Eslint不忽略node_modules文件夹

时间:2020-02-12 15:46:59

标签: node.js eslint babel-eslint

Arraystd::optional<std::string> safe_access(std::string Array[][72], int Pos1, int Pos2) { if (Pos1 < 0 || Pos1 >= 71) return {}; if (Pos2 < 0 || Pos1 >= 21) return {}; return Array[Pos1][Pos2]; } 更新为safe_access(Array, -1, -1) == "X"后,我的Array开始在Babel中发出这样的警告:

enter image description here

因此,据我了解,6文件夹不会被忽略,这就是为什么弹出此问题的原因。因此,请仔细阅读7文档:

https://eslint.org/docs/user-guide/configuring

我尝试将eslint添加到node_modules文件中,但出现错误:

模块构建失败:错误:/Users/vlasenkona/Desktop/gris-seqr2/ui/.eslintrc中的ESLint配置无效: -意外的顶级属性“ ignorePatterns”。

因此,我尝试创建node_modules文件并仅在其中添加eslint,但是警告保持不变。如何忽略"ignorePatterns": ["node_modules/"],文件夹?我正在使用的软件包的版本:

.eslintrc

.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的问题:仅仅是完全误导性的警告? ..

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。 解: 确保文件“ .eslintrc”位于项目的根目录中。 package.json,node_modules和其他东西在哪里。祝你好运。

答案 1 :(得分:1)

就我而言,ESLint(v7.8.1)正确地忽略了node_modules目录,而不是我的dist目录。我将此添加到了.eslintignore

client/dist/

这解决了问题。