Eslint 错误:值 [{"disallowRedundantWrapping":true}] 不应包含超过 0 个项目

Lei*_*nil 10 eslint linter prettier

我正在编写一个小型个人项目来发展我的 React 技能,并且我在 eslint 和 prettier 方面遇到了很多问题,以至于我在该项目上的一半时间都在研究 eslint 的东西,因为它停止了自动格式化我的代码。通常我都能解决问题,但这次我没有。我得到这个:Value [{"disallowRedundantWrapping":true}] should NOT have more than 0 items。我不太清楚为什么,我的 eslint 配置文件中甚至没有这条规则。

\n

我从 VS Code 得到的完整错误是这样的

\n
[Error - 6:30:09 PM] Request textDocument/formatting failed.\n  Message: Request textDocument/formatting failed with message: .eslintrc.json \xc2\xbb eslint-config-airbnb \xc2\xbb /media/{my_path_here}/node_modules/eslint-config-airbnb-base/index.js \xc2\xbb /media/{my_path}/node_modules/eslint-config-airbnb-base/rules/best-practices.js:\n    Configuration for rule "prefer-regex-literals" is invalid:\n    Value [{"disallowRedundantWrapping":true}] should NOT have more than 0 items.\n\n  Code: -32603 \n
Run Code Online (Sandbox Code Playgroud)\n

我的 eslint 文件:

\n
  "env": {\n    "browser": true,\n    "es2020": true\n  },\n  "extends": ["plugin:react/recommended", "airbnb"],\n  "parserOptions": {\n    "ecmaFeatures": {\n      "jsx": true\n    },\n    "sourceType": "module"\n  },\n  "plugins": ["react", "react-hooks"],\n  "rules": {\n    "indent": ["error", 2],\n    "linebreak-style": 0,\n    "quotes": ["error", "single"],\n    "semi": ["error", "always"],\n    "complexity": ["off", 11],\n    "jsx-a11y/label-has-associated-control": "off",\n    "jsx-a11y/label-has-for": "off",\n    "no-magic-numbers": [\n      "error",\n      {\n        "ignore": [0, 1],\n        "ignoreArrayIndexes": true,\n        "enforceConst": true,\n        "detectObjects": false\n      }\n    ],\n    "react/jsx-curly-spacing": [\n      2,\n      { "when": "always", "allowMultiline": false }\n    ],\n    "arrow-parens": [2, "always"],\n    "class-methods-use-this": ["off"],\n    "react/button-has-type": [\n      "error",\n      {\n        "button": true,\n        "submit": true,\n        "reset": true\n      }\n    ],\n    "no-console": ["off"],\n    "no-underscore-dangle": ["off"],\n    "no-param-reassign": ["off"],\n    "consistent-return": ["off"],\n    "no-undef": ["off"],\n    "max-len": [\n      "error",\n      {\n        "code": 90,\n        "ignoreComments": true,\n        "ignoreUrls": true\n      }\n    ],\n    "object-curly-newline": ["off"],\n    "import/no-extraneous-dependencies": ["off"],\n    "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],\n    "react/default-props-match-prop-types": [\n      "error",\n      { "allowRequiredDefaults": false }\n    ],\n    "react/no-array-index-key": ["off"],\n    "react/destructuring-assignment": ["error", "always"],\n    "react/forbid-component-props": ["error"],\n    "react/forbid-prop-types": ["error"],\n    "react/no-did-mount-set-state": ["error"],\n    "react/no-did-update-set-state": ["error"],\n    "react/jsx-props-no-spreading": ["off"],\n    "react/no-multi-comp": ["error", { "ignoreStateless": false }],\n    "react/prefer-stateless-function": ["off"],\n    "react/no-access-state-in-setstate": ["error"],\n    "react/no-redundant-should-component-update": ["error"],\n    "react/no-this-in-sfc": ["error"],\n    "react/no-typos": ["error"],\n    "react/no-unsafe": ["error"],\n    "react/no-unused-state": ["error"],\n    "react/no-will-update-set-state": ["error"],\n    "react/prefer-es6-class": ["error", "always"],\n    "react/self-closing-comp": ["error"],\n    "react/state-in-constructor": ["error", "always"],\n    "react/void-dom-elements-no-children": ["error"],\n    "react/jsx-closing-bracket-location": ["error"],\n    "react/jsx-closing-tag-location": ["error"],\n    "react/jsx-curly-newline": ["error"],\n    "react/jsx-fragments": ["error"],\n    "react/jsx-max-depth": ["error", { "max": 8 }],\n    "react/jsx-no-useless-fragment": ["error"],\n    "react/jsx-equals-spacing": ["error", "never"],\n    "react/jsx-first-prop-new-line": ["error", "multiline"],\n    "react/jsx-indent": [\n      "error",\n      2,\n      { "checkAttributes": true, "indentLogicalExpressions": true }\n    ],\n    "react/jsx-indent-props": ["error", 2],\n    "react/jsx-key": ["error"],\n    "react/jsx-max-props-per-line": [\n      "error",\n      { "maximum": 1, "when": "multiline" }\n    ],\n    "react/jsx-tag-spacing": [\n      "error",\n      {\n        "closingSlash": "never",\n        "beforeSelfClosing": "always",\n        "afterOpening": "never",\n        "beforeClosing": "never"\n      }\n    ],\n    "react/jsx-wrap-multilines": [\n      "error",\n      {\n        "declaration": "parens",\n        "assignment": "parens",\n        "return": "parens",\n        "arrow": "parens",\n        "condition": "ignore",\n        "logical": "ignore",\n        "prop": "ignore"\n      }\n    ],\n    "react-hooks/rules-of-hooks": "error",\n    "react-hooks/exhaustive-deps": 0,\n    "react/function-component-definition": [\n      2,\n      {\n        "namedComponents": "arrow-function",\n        "unnamedComponents": "arrow-function"\n      }\n    ],\n    "prefer-regex-literals": ["error", { "disallowRedundantWrapping": false }]\n  }\n}```\n\nI've tried to turn this rule off as shown on the last line above, but it didn't work. Can you help me?\n\nedit: remove out of context sentence\n
Run Code Online (Sandbox Code Playgroud)\n

Wal*_*ski 4

Airbnb 存储库中的 GitHub 问题表明,此错误可能是由于全局安装了旧版本的 ESLint 造成的。你也可能是这样吗?

https://github.com/airbnb/javascript/issues/2521

由于我找到了 gulp-eslint 包,我也看到了这个问题。