简体   繁体   English

eslint / eslint-plugin-react:找不到.jsx文件

[英]eslint/eslint-plugin-react:not finding .jsx files

I'm using eslint on a react app for the first time, and while it's checking .js files perfectly well, it's not finding any .jsx files. 我第一次在react应用程序上使用eslint ,虽然它可以很好地检查.js文件,但找不到任何.jsx文件。 Admittedly my understanding is hazy, but I thought eslint-plugin-react automatically scanned .jsx files as well with parserOptions.ecmaFeatures.jsx set to true? 诚然,我的理解很模糊,但是我认为eslint-plugin-react自动将.jsx文件扫描并将parserOptions.ecmaFeatures.jsx设置为true?

If I run npm run:lint -- --ext .jsx then jsx files are scanned correctly, but not with a default npm run:lint command 如果我运行npm run:lint -- --ext .jsx则将正确扫描jsx文件,但不会使用默认的npm run:lint命令

My .eslintrc here: 我的.eslintrc在这里:

{
  "plugins": [
    "react"
  ],
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    }
  },
  "env": {
    "es6":     true,
    "browser": true,
    "node":    true,
    "mocha":   true,
    "jest": true
  },
  "extends": [
    "eslint:recommended",
  "plugin:react/recommended"
  ],
  "rules": {
  }
}

It looks like using the --ext CLI flag is the only way to specify file extensions. 看起来使用--ext CLI标志是指定文件扩展名的唯一方法。 See the documentation below. 请参阅下面的文档。

https://eslint.org/docs/2.0.0/user-guide/configuring#specifying-file-extensions-to-lint https://eslint.org/docs/2.0.0/user-guide/configuring#specifying-file-extensions-to-lint

One thing you could do is to include the flag as part of your npm command. 您可以做的一件事是将标志包含在npm命令中。 For example, npm run lint could run eslint --ext .jsx so that you don't have to type it manually. 例如, npm run lint可以运行eslint --ext .jsx因此您不必手动键入它。

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

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