![](/img/trans.png)
[英]eslint not ignoring node_modules and getting error when try to lint
[英]Eslint not ignoring node_modules folder
不知何故,在将Babel
从6
更新到7
之后,我的eslint
开始在node_modules
中发出这样的警告:
因此,根据我的理解, node_modules
文件夹不会被忽略,这就是问题出现的原因。 因此,阅读eslint
文档:
https://eslint.org/docs/user-guide/configuring
我尝试将"ignorePatterns": ["node_modules/"],
添加到.eslintrc
文件但出现错误:
模块构建失败:错误:/Users/vlasenkona/Desktop/gris-seqr2/ui/.eslintrc 中的 ESLint 配置无效:- 意外的顶级属性“ignorePatterns”。
因此,我尝试创建.eslintignore
文件并在其中添加node_modules/
但警告保持不变。 我怎么能忽略node_modules
文件夹? 我正在使用的软件包版本:
"eslint": "^5.16.0",
"babel-eslint": "^9.0.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-import-resolver-babel-module": "^5.1.2",
"eslint-loader": "1.9.0",
"eslint-plugin-flowtype": "2.39.1",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-jsx-a11y": "^6.1.0",
"eslint-plugin-react": "^7.10.0",
"eslint-plugin-react-perf": "^2.0.8",
.eslintrc
看起来像这样:
{
"extends": [
"airbnb",
"plugin:react-perf/recommended"
],
"parser": "babel-eslint",
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
},
"env": {
"mocha": true,
"es6": true,
"browser": true,
"node": true,
"jest": true
},
"settings": {
"import/resolver": {
"babel-module": {}
}
},
"rules": {
"semi": [2, "never"],
"no-shadow": ["error", { "allow": ["error"] }],
"arrow-body-style": 0,
"func-names": 0,
"function-paren-newline": 0,
"max-len": 0, //["warn", 80, 2],
"no-console": 0,
"no-multi-str": 0,
"no-param-reassign": 0,
"no-plusplus": 0,
"brace-style": 0,
"object-curly-newline": 0,
"padded-blocks": 0,
"react/jsx-first-prop-new-line": 0,
"react/jsx-wrap-multilines": 0,
"react/prefer-stateless-function": 0,
"react/sort-comp": 0, // more freedom in arranging class functions
"import/prefer-default-export": 0,
"react/forbid-prop-types": 0,
"no-class-assign": 0,
"react/jsx-filename-extension": [ 1, { "extensions": [".js", ".jsx"]} ],
"react/require-default-props": 0,
"react/require-optimization": 2,
"react/jsx-max-props-per-line": 0,
"react/jsx-no-target-blank": 0,
"spaced-comment": 0,
"jsx-a11y/iframe-has-title": 0,
"jsx-a11y/tabindex-no-positive": 0,
"jsx-a11y/click-events-have-key-events": 0,
"jsx-a11y/anchor-is-valid": 0
}
}
更新
我尝试将以下内容添加到新创建的.eslintignore
:
node_modules/*
./node_modules/**
**/node_modules/**
但两者都不起作用。 有趣的是,如果我打开./node_modules/draftjs-md-converter/dist/index.js
并在文件的开头和结尾放置/*eslint-disable */
警告仍然存在,所以也许它不是eslint
问题:只是完全误导性的警告?..
在我的例子中,ESLint (v7.8.1) 正确地忽略node_modules
目录,但不是我的dist
目录。 我将此添加到.eslintignore
:
client/dist/
这解决了这个问题。
编辑:我一开始就不应该有第二个 node_modules 文件夹,它现在只使用主文件夹
忽略根文件夹中 .eslintignore 文件中的node_modules/
对我有用。
node_modules/*
没有,它导致“发生未处理的异常:无法加载要扩展的配置“airbnb”。” 或对子项目进行 linting 时出现类似错误。
我们的项目结构如下所示:
我有同样的问题。 解决方案:确保您的文件“.eslintrc”位于项目的根目录中。 package.json、node_modules 和其他东西在哪里。 祝你好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.