首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ESLint破坏:带有建议的规则必须将`meta.hasSuggestions`属性设置为“`true`”

ESLint破坏:带有建议的规则必须将`meta.hasSuggestions`属性设置为“`true`”
EN

Stack Overflow用户
提问于 2021-10-15 00:23:14
回答 3查看 19.2K关注 0票数 37

我使用的是VSCode,当我将行'react-hooks/exhaustive-deps': 'warn'添加到我的.eslintrc.js中时,会在ESLint输出中得到以下内容:

代码语言:javascript
运行
复制
Rules with suggestions must set the `meta.hasSuggestions` property to `true`. Occurred while linting
C:\Users\filepath.jsx:72 Rule: "react-hooks/exhaustive-deps"

这就破坏了所有其他的皮毛。我尝试在我的.eslintrc.js中添加以下内容:

代码语言:javascript
运行
复制
meta: {
    hasSuggestions: true
},

这给了我以下错误:

代码语言:javascript
运行
复制
UnhandledPromiseRejectionWarning: Error: ESLint configuration in .eslintrc.js is invalid:
    - Unexpected top-level property "meta".

任何帮助都将不胜感激。

这是我的.eslintrc.js:

代码语言:javascript
运行
复制
module.exports = {
    env: {
        browser: true,
        es2021: true,
    },
    extends: ['eslint:recommended', 'plugin:react/recommended', 'plugin:react-hooks/recommended'],
    settings: {
        'react': {
            'version': 'detect'
        }
    },
    parserOptions: {
        ecmaFeatures: {
            jsx: true,
        },
        ecmaVersion: 13,
        sourceType: 'module',
    },
    plugins: ['react-hooks', 'react'],
    rules: {
        'react/prop-types': [0],
        quotes: ['error', 'single'],
        semi: [1],
        'react/jsx-indent': [1],
        'no-multi-spaces': [1],
        'indent': [2],
        'react/jsx-newline': [2, { prevent: true }],
        'no-trailing-spaces': [1],
        'no-multiple-empty-lines': [1, { max: 1 }],
        'space-infix-ops': [1],
        'object-curly-spacing': [1, 'always'],
        'comma-spacing': [1],
        'react-hooks/rules-of-hooks': 'error',
        'react/self-closing-comp': 1,
        'react/jsx-closing-tag-location': 1,
        'no-unreachable': 1,
        'react-hooks/exhaustive-deps': 'warn'
    },
};

这是我的package.json:

代码语言:javascript
运行
复制
{
  "name": "app",
  "private": true,
  "dependencies": {
    "@babel/preset-react": "^7.14.5",
    "@emotion/react": "^11.4.1",
    "@emotion/styled": "^11.3.0",
    "@mui/icons-material": "^5.0.4",
    "@mui/material": "^5.0.3",
    "@mui/styles": "^5.0.1",
    "@rails/actioncable": "^6.1.4-1",
    "@rails/activestorage": "^6.1.4-1",
    "@rails/ujs": "^6.1.4-1",
    "@rails/webpacker": "^6.0.0-rc.5",
    "babel-plugin-macros": "^3.1.0",
    "prop-types": "^15.7.2",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-on-rails": "12.3.0",
    "react-player": "^2.9.0",
    "turbolinks": "^5.2.0",
    "webpack": "^5.53.0",
    "webpack-cli": "^4.8.0"
  },
  "version": "0.1.0",
  "babel": {
    "presets": [
      "./node_modules/@rails/webpacker/package/babel/preset.js"
    ]
  },
  "browserslist": [
    "defaults"
  ],
  "devDependencies": {
    "@webpack-cli/serve": "^1.6.0",
    "eslint": "^8.0.0",
    "eslint-plugin-react": "^7.26.1",
    "eslint-plugin-react-hooks": "^4.2.0",
    "webpack-dev-server": "^4.3.1"
  }
}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2021-10-15 00:55:41

ESLint 8.0.0附带了一个打破提供建议的规则的变化。如果您使用了在此更改后尚未更新的规则,则无法将其放入.eslintrc.js中以使其工作。

你能做的是:

  • 使用ESLint 7,直到插件被更新以使用ESLint 8。
  • eslint-plugin-react-hooks的情况下,违规规则已经被更新(检查GitHub上的这一行),只是从那以后还没有一个稳定的包发布。然而,每天都有alpha版本,在编写本报告时,最新版本是4.2.1-alpha-c3a19e5af-20211014。如果您确实需要ESLint 8和这个插件,您可以使用alpha版本,直到下一个稳定版本出现为止。
票数 51
EN

Stack Overflow用户

发布于 2022-04-13 18:56:24

为了解决这个问题,我不得不删除"react/require-default-props": "off",规则。不是一个完整的修复程序,但现在它与react v18一起工作。

票数 2
EN

Stack Overflow用户

发布于 2022-09-12 07:21:59

在将react脚本从4.x跳到5.0.1之后,也有相同的错误。因为我们的package.json中也有“eslint react”,所以解决方法也是把它撞到当前。7.0.1在我们的案件中。希望这能帮到你遇到同样的问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69578685

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档