【问题标题】:Warning jsx-a11y/img-has-alt警告 jsx-a11y/img-has-alt
【发布时间】:2023-03-24 21:33:01
【问题描述】:

我有 CRA,我想安装自定义 eslint (airbnb),但安装后会触发错误

没有找到规则“jsx-a11y/img-has-alt”的警告定义 jsx-a11y/img-has-alt

package.json

...
"eslint-config-airbnb": "^15.0.1",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^5.0.1",
"eslint-plugin-react": "^7.0.1",

create-app-react - 3.10.10

.eslintrc

"extends": [
    "airbnb"
],
"plugins": [
    "import",
    "react",
    "jsx-a11y"
],
"env": {
    "browser": true,
    "node": true,
    "jest": true
},
"rules": {
    "comma-dangle": ["error", "never"],
    "jsx-a11y/img-has-alt": [0],
    "jsx-quotes": ["error", "prefer-single"],
    "no-confusing-arrow": [0],
    "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
    "react/jsx-no-bind": [0],
    "react/prop-types": [1],
    "react/require-default-props": [0]
}

编辑:npm 说 eslint-config-airbnb 需要 jsx-a11y v5.0.1

【问题讨论】:

标签: reactjs eslint create-react-app eslint-config-airbnb


【解决方案1】:

我使用 CRA eslint 插件,当我安装 jsx-a11y 插件 5.0.3 时,我收到控制台警告:

“eslint-config-react-app@0.6.2”具有不正确的对等依赖关系“eslint-plugin-jsx-a11y@^2.0.0 || ^3.0.0 || ^4.0.0”。

也会收到同样的警告。

我认为您需要降级到版本 4.0.0。这仍然是“想要”的版本

【讨论】:

【解决方案2】:

您显然需要更新您的节点版本才能解决问题。

【讨论】:

    【解决方案3】:

    如果您将规则声明从 "jsx-a11y/img-has-alt": [0], 更改为 "jsx-a11y/alt-text": [0], 它会起作用的。

    https://cnpmjs.org/package/eslint-plugin-jsx-a11y

    【讨论】:

      猜你喜欢
      • 2017-10-10
      • 2019-12-25
      • 1970-01-01
      • 1970-01-01
      • 2021-12-22
      • 1970-01-01
      • 2021-10-12
      • 1970-01-01
      • 2019-07-25
      相关资源
      最近更新 更多