【问题标题】:eslint ignore pattern not workseslint 忽略模式不起作用
【发布时间】:2021-10-20 19:23:17
【问题描述】:

我想在没有 node_modules 的情况下运行 lint 检查所有文件 *.js

这是我的命令:"lint": "eslint **/*.js",,我的文件夹结构看起来像:app > module_name > module.js,但在 app 文件夹中仍然有一些常见的文件,如 helpers.jsserver.js,我也想检查它们。

在 .eslint 配置中,我添加了 "ignorePatterns": "node_modules" 并尝试添加文件 .eslintignore 并添加 node_modules 但它不起作用。

当我运行npm run lint 时,它总是抛出错误:


Oops! Something went wrong! :(

ESLint: 7.32.0

You are linting "node_modules/bignumber.js", but all of the files matching the glob pattern "node_modules/bignumber.js" are ignored.

If you don't want to lint these files, remove the pattern "node_modules/bignumber.js" from the list of arguments passed to ESLint.

If you do want to lint these files, try the following solutions:

* Check your .eslintignore file, or the eslintIgnore property in package.json, to ensure that the files are not configured to be ignored.
* Explicitly list the files from this glob that you'd like to lint on the command-line, rather than providing a glob as an argument.

【问题讨论】:

标签: node.js eslint lint


【解决方案1】:

您可以在 .eslintignore 文件中添加 node_modules/,并在运行 npm run lint 之前使用脚本更新 package.json 文件:"lint": "eslint --ext .js app/",

【讨论】:

  • 如果我只更改脚本,它可以工作。但如果我只更改 .eslintignore,它就不起作用。因为如果脚本是正确的,eslint 只检查 /app 文件夹,而 node_modules 不在 /app 文件夹中,不需要将 node_modules 添加到 .eslintignore。如果我的脚本不正确,它会检查根文件夹中的所有过滤器,并将 node_modules 添加到 .eslint 忽略,为什么它不起作用?
猜你喜欢
  • 1970-01-01
  • 2016-06-04
  • 2022-12-07
  • 2012-10-10
  • 1970-01-01
  • 2020-01-16
  • 2018-08-31
  • 2020-05-28
  • 2019-11-28
相关资源
最近更新 更多