简体   繁体   English

Eslint 不忽略 node_modules 文件夹

[英]Eslint not ignoring node_modules folder

Somehow after updating Babel from 6 to 7 my eslint started giving such a warning in node_modules :不知何故,在将Babel6更新到7之后,我的eslint开始在node_modules中发出这样的警告:

在此处输入图像描述

So, from my understanding node_modules folder is not ignored and that is why the issue popped up.因此,根据我的理解, node_modules文件夹不会被忽略,这就是问题出现的原因。 So, reading through eslint docs:因此,阅读eslint文档:

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

I tried adding "ignorePatterns": ["node_modules/"], to the .eslintrc file but got an error:我尝试将"ignorePatterns": ["node_modules/"],添加到.eslintrc文件但出现错误:

Module build failed: Error: ESLint configuration in /Users/vlasenkona/Desktop/gris-seqr2/ui/.eslintrc is invalid: - Unexpected top-level property "ignorePatterns".模块构建失败:错误:/Users/vlasenkona/Desktop/gris-seqr2/ui/.eslintrc 中的 ESLint 配置无效:- 意外的顶级属性“ignorePatterns”。

So, I tried creating .eslintignore file and added there just node_modules/ but the warning stayed the same.因此,我尝试创建.eslintignore文件并在其中添加node_modules/但警告保持不变。 How could I ignore the node_modules folder?我怎么能忽略node_modules文件夹? 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: .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
  }
}

Update更新

I tried adding the following to newly created .eslintignore :我尝试将以下内容添加到新创建的.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?..有趣的是,如果我打开./node_modules/draftjs-md-converter/dist/index.js并在文件的开头和结尾放置/*eslint-disable */警告仍然存在,所以也许它不是eslint问题:只是完全误导性的警告?..

In my case, ESLint (v7.8.1) was ignoring node_modules directories properly, but not my dist directory.在我的例子中,ESLint (v7.8.1) 正确地忽略node_modules目录,但不是我的dist目录。 I added this to .eslintignore :我将此添加到.eslintignore

client/dist/

and that resolved the issue.这解决了这个问题。

Edit: I shouldn't have had a second node_modules folder in the first place, it works with using only the main folder now编辑:我一开始就不应该有第二个 node_modules 文件夹,它现在只使用主文件夹


Ignoring node_modules/ in the.eslintignore file in the root folder worked for me.忽略根文件夹中 .eslintignore 文件中的node_modules/对我有用。

node_modules/* did not, it caused "An unhandled exception occurred: Failed to load config "airbnb" to extend from." node_modules/*没有,它导致“发生未处理的异常:无法加载要扩展的配置“airbnb”。” or similar errors when linting the sub-project.或对子项目进行 linting 时出现类似错误。

Our project structure looks like this:我们的项目结构如下所示:

root-project根项目

  • node_modules节点模块
  • projects项目
    • sub-project子项目
      • node_modules节点模块
      • package.json package.json
      • .eslintrc.json .eslintrc.json
      • ... ...
  • src来源
  • .eslintignore .eslintignore
  • .eslintrc.json .eslintrc.json
  • ... ...

I've got the same problem.我有同样的问题。 Solution: Make sure your file ".eslintrc" is in the root directory of your project.解决方案:确保您的文件“.eslintrc”位于项目的根目录中。 Where is package.json, node_modules and other things. package.json、node_modules 和其他东西在哪里。 Good luck.祝你好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM