42

Somehow after updating Babel from 6 to 7 my eslint started giving such a warning in node_modules:

enter image description here

So, from my understanding node_modules folder is not ignored and that is why the issue popped up. So, reading through eslint docs:

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

I tried adding "ignorePatterns": ["node_modules/"], to the .eslintrc file but got an error:

Module build failed: Error: ESLint configuration in /Users/vlasenkona/Desktop/gris-seqr2/ui/.eslintrc is invalid: - Unexpected top-level property "ignorePatterns".

So, I tried creating .eslintignore file and added there just node_modules/ but the warning stayed the same. How could I ignore the node_modules folder? The versions of the packages I am using:

"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",

The .eslintrc looks like that:

{
  "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
  }
}

Update

I tried adding the following to newly created .eslintignore:

node_modules/*
./node_modules/**
**/node_modules/**

But neither works. Interestingly enough, if I open ./node_modules/draftjs-md-converter/dist/index.js and put at the very beginning and end of the file /*eslint-disable */ the warning still remains, so maybe it is not an eslint problem: just totally misleading warning?..

4

3 回答 3

4

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

client/dist/

这解决了这个问题。

于 2020-09-12T00:24:31.120 回答
2

忽略node_modules/根文件夹中的 .eslintignore 文件对我有用。

node_modules/*没有,它导致“发生未处理的异常:无法加载配置“airbnb”以扩展。” linting 子项目时出现类似错误。

我们的项目结构如下所示:

根项目

  • 节点模块
  • 项目
    • 子项目
      • 节点模块
      • 包.json
      • .eslintrc.json
      • ...
  • 源代码
  • .eslintignore
  • .eslintrc.json
  • ...
于 2021-08-17T09:06:18.610 回答
1

我有同样的问题。解决方案:确保您的文件“.eslintrc”位于项目的根目录中。package.json、node_modules 和其他东西在哪里。祝你好运。

于 2020-02-28T22:19:53.403 回答