Eslint不忽略node_modules文件夹

rjjhvcjd  于 5个月前  发布在  Node.js
关注(0)|答案(5)|浏览(97)

在将Babel6更新为7之后,我的eslint开始在node_modules中发出这样的警告:
x1c 0d1x的数据
所以,从我的理解node_modules文件夹是不会被忽略的,这就是为什么问题弹出.所以,阅读通过eslint文档:
https://eslint.org/docs/user-guide/configuring
我尝试将"ignorePatterns": ["node_modules/"],添加到.eslintrc文件中,但出现错误:
模块构建失败:错误:/Users/vlasenkona/Desktop/gris-seqr 2/ui/.eslintrc中的ESLint配置无效:-意外的顶级属性“BullrePatterns”。
所以,我尝试创建.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的问题:只是完全误导性的警告?..

7hiiyaii

7hiiyaii1#

在我的例子中,ESLint(v7.8.1)正确地忽略了node_modules目录,但没有忽略我的dist目录。我将此添加到.eslintignore

client/dist/

字符串
这就解决了问题

1dkrff03

1dkrff032#

**编辑:**我不应该有第二个node_modules文件夹摆在首位,它现在只使用主文件夹

忽略根文件夹中的.eslintignore文件中的node_modules/对我很有效。
node_modules/*没有,它导致了“An unhandled exception occurred:Failed to load config“airbnb”to extend from.”或类似的错误。
我们的项目结构看起来像这样:

根项目

  • node_modules
  • 项目
  • 子项目
  • node_modules
  • package.json
  • .eslintrc.json
  • ...
  • src
  • .椭圆形
  • .eslintrc.json
  • ...
3mpgtkmj

3mpgtkmj3#

对我来说,这是我的节点版本。我运行14和eslint服务器运行16。这导致eslint lint我所有的节点模块。
如果您使用的是nvm,请切换到更新的节点:

nvm use 18

字符串
您可以使用ESLint: Show Output Channel命令在IDE中查看ESLint节点服务器版本。

8yoxcaq7

8yoxcaq74#

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

bis0qfac

bis0qfac5#

我在package.json中有以下脚本:

"scripts": {
    "lint": "eslint **/*.ts",
  }

字符串
原来我的shell正在扩展glob,所以它将所有.ts文件作为参数传递给eslint(包括node_modules中的文件),导致eslint的忽略规则不适用。
我通过修改脚本将glob传递给eslint而不是扩展它来修复它:

"scripts": {
    "lint": "eslint '**/*.ts'",
  }

相关问题