Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make ESLint apply rules to only certain file name patterns

Tags:

eslint

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.

like image 877
wap300 Avatar asked Sep 11 '15 09:09

wap300


People also ask

How do I get ESLint to ignore a line?

The // eslint-disable-line comment disables the no-eval rule for just that line. You can also disable the no-eval rule for an entire function block by using /* eslint-disable */ .


1 Answers

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

like image 90
Gyandeep Avatar answered Oct 24 '22 17:10

Gyandeep