Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
310 views
in Technique[技术] by (71.8m points)

Make ESLint apply rules to only certain file name patterns

Is it possible to configure ESLint in a way that it only applies rules to files that names are matching certain pattern? I know it's possible to have separate rule sheets in directories, but in case the structure is following:

app
|
|- module1
|     |- module1.js
|     |- module1.spec.js
|
|- module2
|     |- module2.js
|     |- module2.spec.js

And I want a project-wide rules that would only apply to the *.spec.js files. I'd expect to have a setting like

"include-pattern": "*.spec.js"

in the .eslintrc or any other, simlilar way to specify which filenames should be considered for specific rules.

question from:https://stackoverflow.com/questions/32520674/make-eslint-apply-rules-to-only-certain-file-name-patterns

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Updated answer:

Yes, now it's possible. In your example it could look like

{
  "rules": {
    "quotes": [ 2, "double" ]
  },

  "overrides": [
    {
      "files": [ "app/module1/*.js" ],
      "excludedFiles": "*.spec.js",
      "rules": {
        "quotes": [ 2, "single" ]
      }
    }
  ]
}

You can read more at eslint doc page.

Old answer:

Currently this is not supported. But for 2.0.0 version we are actively working on this feature.

To track progress: https://github.com/eslint/eslint/issues/3611


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...