简体   繁体   中英

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.

I want eslint to only look at .js and .jsx files.

I don't see any way to do that.

I did find eslintignore which is not the best way to do things.

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:

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

Docs: 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

If you are running it through gulp, first pipe the src like

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:

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

Then invoke it with npm run eslint

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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