问题
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.css
andsrc/b.js
because they were explicitly passed, then does its own traversal ofsrc/c
and lintssrc/c/e.js
. This includes even non-js files directly withinsrc
and completely misses.jsx
files in subdirectories ofsrc
.eslint src
tells ESLint to do its own traversal ofsrc
with the default.js
extension, so it lintssrc/b.js
andsrc/c/e.js
but missessrc/c/f.jsx
.eslint --ext js,jsx src
tells ESLint to do its own traversal ofsrc
, including.js
and.jsx
files, 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