[英]Why eslint can't detect all files in the directory, but can detect single file?
This is my directory structure. 这是我的目录结构。
I want to config some eslint rule to detect my code. 我想配置一些eslint规则来检测我的代码。
In .eslintrc
, I write these configuration items. 在
.eslintrc
,我编写了这些配置项。
{
"extends": "airbnb",
"rules": {
"valid-jsdoc": 2,
// Disable until Flow supports let and const
"no-var": 0,
"react/jsx-uses-react": 1,
"react/jsx-no-undef": 2,
"react/wrap-multilines": 2,
"func-names": 0,
"new-cap": 0,
"no-undef": 0,
},
"plugins": [
"react"
]
}
I have used npm script to run eslint. 我用npm脚本来运行eslint。
"scripts": {
"lint": "eslint src"
},
Normally, when I run npm run lint
, it will detect all the files in src
directory. 通常,当我运行
npm run lint
,它会检测src
目录中的所有文件。
But, unfortunately, nothing output. 但是,遗憾的是,没有任何输出。
I don't know why. 我不知道为什么。 I guess maybe I have writed wrong configuration items.
我想也许我写了错误的配置项。 But after I write npm scripts
"lint": "eslint src/component/App.jsx"
, eslint works. 但是在我写了npm脚本
"lint": "eslint src/component/App.jsx"
,eslint起作用了。
So where is the problems? 那问题出在哪里? Eslint can detect single file well, but it can't detect all the files in some directory.
Eslint可以很好地检测单个文件,但它无法检测某些目录中的所有文件。
when you run eslint src
, by default its looking for all the files with .js
extension. 当你运行
eslint src
,默认它会查找扩展名为.js
所有文件。 I think in your case you want to change command to eslint src --ext .js,.jsx
. 我认为在你的情况下你想要将命令改为
eslint src --ext .js,.jsx
。 This will look for all the files inside src
with .js
and/or .jsx
extensions. 这将查找带有
.js
和/或.jsx
扩展名的src
内的所有文件。 (personally recommend) (个人推荐)
If you want to use glob to solve this issue then you can change your cmd to eslint src/**/*.jsx
如果你想使用glob来解决这个问题,你可以将你的cmd更改为
eslint src/**/*.jsx
CLI docs: http://eslint.org/docs/user-guide/command-line-interface CLI文档: http : //eslint.org/docs/user-guide/command-line-interface
Glob patterns help: http://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories 全局模式有助于: http : //eslint.org/docs/user-guide/configuring#ignoring-files-and-directories
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.