Only enable eslint in specific files

落爺英雄遲暮 提交于 2020-01-14 19:06:09

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/42909553/only-enable-eslint-in-specific-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!