问题
I need to exclude css files from the eslint parser.
Currently when I run eslint src/** this is checking all the files including css files. .
Please find below my eslintrc file contents.
module.exports = {
"parser": "babel-eslint",
"extends": "airbnb",
"plugins": [
"react",
"jsx-a11y",
"import"
],
"env" : {
"browser": true
}
"rules": {
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
},
};
回答1:
.eslintignore file to ignore styles would work nicely. Inside, do something like this: *.css
Here's a good starting point with these techs, which I actually found while reading another, similar SO post
回答2:
Use eslint --ext js,jsx src instead. This allows ESLint to do its own traversal of the src directory, including files with .js or .jsx extensions.
Using eslint src/** and ignoring src/**/*.css will correctly exclude .css files, but it will miss any .jsx files in subdirectories inside of src.
Why?
Given this as an example
src
├── a.css
├── b.js
└── c
├── d.css
├── e.js
└── f.jsx
eslint src/**expands toeslint src/a.css src/b.js src/c. ESLint checkssrc/a.cssandsrc/b.jsbecause they were explicitly passed, then does its own traversal ofsrc/cand lintssrc/c/e.js. This includes even non-js files directly withinsrcand completely misses.jsxfiles in subdirectories ofsrc.eslint srctells ESLint to do its own traversal ofsrcwith the default.jsextension, so it lintssrc/b.jsandsrc/c/e.jsbut missessrc/c/f.jsx.eslint --ext js,jsx srctells ESLint to do its own traversal ofsrc, including.jsand.jsxfiles, so it lintssrc/b.js,src/c/e.js, andsrc/c/f.jsx.
来源:https://stackoverflow.com/questions/43626296/how-to-exclude-css-files-from-eslint-parser-in-react