how to exclude css files from eslint parser in React

孤人 提交于 2020-04-10 08:35:11

问题


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


来源:https://stackoverflow.com/questions/43626296/how-to-exclude-css-files-from-eslint-parser-in-react

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