繁体   English   中英

为什么eslint无法检测目录中的所有文件,但可以检测单个文件?

[英]Why eslint can't detect all files in the directory, but can detect single file?

这是我的目录结构。

在此输入图像描述

我想配置一些eslint规则来检测我的代码。

.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"
  ]
}

我用npm脚本来运行eslint。

  "scripts": {
    "lint": "eslint src"
  },

通常,当我运行npm run lint ,它会检测src目录中的所有文件。

但是,遗憾的是,没有任何输出。

在此输入图像描述

我不知道为什么。 我想也许我写了错误的配置项。 但是在我写了npm脚本"lint": "eslint src/component/App.jsx" ,eslint起作用了。

那问题出在哪里? Eslint可以很好地检测单个文件,但它无法检测某些目录中的所有文件。

在此输入图像描述

当你运行eslint src ,默认它会查找扩展名为.js所有文件。 我认为在你的情况下你想要将命令改为eslint src --ext .js,.jsx 这将查找带有.js和/或.jsx扩展名的src内的所有文件。 (个人推荐)

如果你想使用glob来解决这个问题,你可以将你的cmd更改为eslint src/**/*.jsx

CLI文档: http//eslint.org/docs/user-guide/command-line-interface

全局模式有助于: http//eslint.org/docs/user-guide/configuring#ignoring-files-and-directories

暂无
暂无

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

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