Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only enable eslint in specific files

I really like eslint for es6 projects. Previously I've used it for new projects. Now I want to add it to a legacy project.

Fixing all pre-existing lint issues in one go is too much effort. Can I configure eslint (in .eslintrc.js) to only check files where I've explicitly enabled it with /* eslint-enable */ or similar?

like image 598
worldsayshi Avatar asked Mar 09 '23 13:03

worldsayshi


1 Answers

ESLint has no default-disabled state that can be toggled by a file comment. You might be able to use .eslintignore for this purpose, however. You can ignore everything and then gradually whitelist files as you migrate them by using ! to un-ignore individual files. For example:

.
├── .eslintignore
├── .eslintrc.js
├── package.json
├── node_modules
│   └── ...
├── src
│   ├── index.js
│   └── module
│       └── foo.js
└── yarn.lock

Then your .eslintignore could look something like this:

# Start by ignoring everything by default
src/**/*.js
# Enable linting just for some files
!src/module/foo.js

In this case, src/index.js would be ignored, but it would lint src/module/foo.js.

like image 136
btmills Avatar answered Mar 21 '23 00:03

btmills