简体   繁体   English

为除 js 文件之外的所有文件禁用 eslint?

[英]Disable eslint for all files but js files?

Right now it's giving error that .png and .less files aren't valid, everything is invalid.现在它给出的错误是 .png 和 .less 文件无效,一切都无效。

I want eslint to only look at .js and .jsx files.我希望 eslint 只查看 .js 和 .jsx 文件。

I don't see any way to do that.我看不出有什么办法可以做到这一点。

I did find eslintignore which is not the best way to do things.我确实发现 eslintignore 这不是最好的做事方式。

I don't want to maintain a list of files to ignore.我不想维护要忽略的文件列表。

Whitelist approach please.请使用白名单方法。

You could make use of the property "overrides" on your .eslintrc file to include only the files/file types you want:您可以使用 .eslintrc 文件上的“覆盖”属性来仅包含您想要的文件/文件类型:

{
    "overrides": [
        {
            "files": [ "src/**/*.js", "src/**/*.jsx" ]
        }
    ]
}

Docs: https://eslint.org/docs/user-guide/configuring#example-configuration文档: https : //eslint.org/docs/user-guide/configuring#example-configuration

I believe there is no way to configure it other than the arguments for the CLI我相信除了 CLI 的参数之外没有其他方法可以配置它

If you are running it through gulp, first pipe the src like如果您通过 gulp 运行它,请首先通过管道将 src 像

src(['**/*.js', '**/*.jsx'])
        .pipe(eslint())
...

If you would rather do it via npm command, you can create a script in your package.json like so:如果您更愿意通过 npm 命令执行此操作,您可以在 package.json 中创建一个脚本,如下所示:

"scripts": {
  ...
  "eslint": "eslint **/*.js **/*.jsx",

Then invoke it with npm run eslint然后用npm run eslint调用它

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

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