簡體   English   中英

Eslint 不忽略 node_modules 文件夾

[英]Eslint not ignoring node_modules folder

不知何故,在將Babel6更新到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 時出現類似錯誤。

我們的項目結構如下所示:

根項目

  • 節點模塊
  • 項目
    • 子項目
      • 節點模塊
      • package.json
      • .eslintrc.json
      • ...
  • 來源
  • .eslintignore
  • .eslintrc.json
  • ...

我有同樣的問題。 解決方案:確保您的文件“.eslintrc”位於項目的根目錄中。 package.json、node_modules 和其他東西在哪里。 祝你好運。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM