reactjs ESLint断裂:带有建议的规则必须将" meta. hasSugggestions“属性设置为”true

yi0zb3m4  于 2022-12-18  发布在  React
关注(0)|答案(3)|浏览(110)

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

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:

meta: {
    hasSuggestions: true
},

得到了以下错误:

UnhandledPromiseRejectionWarning: Error: ESLint configuration in .eslintrc.js is invalid:
    - Unexpected top-level property "meta".


任何帮助都将不胜感激。
下面是我的.eslintrc.js:

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'
    },
};

这是我的包裹

{
  "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"
  }
}
hjqgdpho

hjqgdpho1#

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版本,直到下一个稳定的版本出来。
kcrjzv8t

kcrjzv8t2#

我不得不删除规则"react/require-default-props": "off",来摆脱这个问题。不是一个完整的修复,但它现在在react v18中工作

xoshrz7s

xoshrz7s3#

在将react-scripts从4.x升级到5.0.1后也出现了同样的错误。因为我们的package.json中也有“eslint-config-react-app”,所以在我们的情况下,修复方法是将其升级到当前的.7.0.1。希望这对您遇到同样的问题有所帮助。

相关问题