简体   繁体   English

ESlint:通过 glob 模式验证文件

[英]ESlint: validate files by glob pattern

Can I split the ESLint rules by glob pattern?我可以通过 glob 模式拆分 ESLint 规则吗?

I mean case like this:我的意思是这样的情况:

{ 
  "*.server.js": { /* rules set for the server JS */ },
  "*.client.js": { /* rules set for the client JS */ },
  "*.special.js": { /* some very special JS */ },
  "*.js": { /* all other JS with its own rules not intersecting with others */ }
}

There is the jshint-groups wrapper for JSHint. JSHint 有 jshint-groups 包装器。 Is there something like this for ESLint? ESLint 有这样的东西吗?

Not yet.还没有。 It's one of the items on the road map for version 2.0.0.它是 2.0.0 版路线图上的项目之一。 For now if you are using grunt/gulp, you can just create multiple tasks with multiple .eslintrc files.现在如果你使用 grunt/gulp,你可以用多个 .eslintrc 文件创建多个任务。

This is now possible using an overrides section:现在可以使用 overrides 部分:

{
  "rules": {...},
  "overrides": [
    {
      "files": ["*-test.js","*.spec.js"],
      "rules": {
        "no-unused-expressions": "off"
      }
    }
  ]
}

https://eslint.org/docs/user-guide/configuring/rules#using-configuration-files-1 https://eslint.org/docs/user-guide/configuring/rules#using-configuration-files-1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM