用于打字稿的 eslint-plugin-jsx-a11y

jro*_*004 5 accessibility typescript reactjs eslint

我正在尝试为我的打字稿反应项目设置,当我工作时,如果我正在做一些无法访问的事情,它会给我警告/错误。我的编辑器已经给我列出错误,但我尝试设置 eslint-plugin-jsx-a11y,但我无法让它工作。

这是我的 package.json 中的 eslint 部分

  "eslintConfig": {
    parser: '@typescript-eslint/parser',
    "extends": [
      "react-app",
      "react-app/jest",
      "shared-config",
      "plugin:jsx-a11y/recommended"
    ],
    "rules": {
      "additional-rule": "warn"
    },
    "overrides": [
      {
        "files": [
          "**/*.ts?(x)"
        ],
        "rules": {
          "additional-typescript-only-rule": "warn"
        }
      }
    ]
  },
Run Code Online (Sandbox Code Playgroud)

不知道我错过了什么。谢谢

Nic*_*yme 3

您的意思是无法让它发挥作用

从它的外观来看,我猜您缺少使用 eslint文档plugins中任何给定插件所需的密钥。

文档eslint-plugin-jsx-a11y甚至在使用部分提到了这一点。

密钥extends仅应用规则集,而密钥使某些规则可用,请参阅此处的plugins详细说明。

{
  "eslintConfig": {
    "parser": '@typescript-eslint/parser',
    "extends": [
      "react-app",
      "react-app/jest",
      "shared-config",
      "plugin:jsx-a11y/recommended"
    ],
    "plugins": [
      "jsx-a11y"
    ],
    "rules": {
      "additional-rule": "warn"
    },
    "overrides": [
      {
        "files": [
          "**/*.ts?(x)"
        ],
        "rules": {
          "additional-typescript-only-rule": "warn"
        }
      }
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

如果这不起作用,请详细说明什么不起作用或出现什么错误。