|
| 1 | +--- |
| 2 | +description: Modern alternatives to eslint-plugin-jsx-a11y for accessibility linting of JSX |
| 3 | +--- |
| 4 | + |
| 5 | +# Replacements for `eslint-plugin-jsx-a11y` |
| 6 | + |
| 7 | +**Motivation:** `eslint-plugin-jsx-a11y` still supports very old ESLint and Node versions, which pulls in far more dependencies than it needs. |
| 8 | + |
| 9 | +## `eslint-plugin-jsx-a11y-x` |
| 10 | + |
| 11 | +[`eslint-plugin-jsx-a11y-x`](https://github.com/eslint-community/eslint-plugin-jsx-a11y-x) is a fork of [`eslint-plugin-jsx-a11y`](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y) with far fewer dependencies and full support for flat config and ESLint v10. |
| 12 | + |
| 13 | +> [!NOTE] |
| 14 | +> `eslint-plugin-jsx-a11y-x` is still being modernised, so treat it as experimental for now. |
| 15 | +
|
| 16 | +Rename the import, use `configs` instead of `flatConfigs`, and change the rule prefix from `jsx-a11y/` to `jsx-a11y-x/`: |
| 17 | + |
| 18 | +<!-- prettier-ignore --> |
| 19 | +```ts |
| 20 | +import jsxA11y from 'eslint-plugin-jsx-a11y' // [!code --] |
| 21 | +import jsxA11yX from 'eslint-plugin-jsx-a11y-x' // [!code ++] |
| 22 | +
|
| 23 | +export default [ |
| 24 | + { |
| 25 | + files: ['**/*.{jsx,tsx}'], |
| 26 | + ...jsxA11y.flatConfigs.recommended, // [!code --] |
| 27 | + ...jsxA11yX.configs.recommended, // [!code ++] |
| 28 | + rules: { |
| 29 | + ...jsxA11y.flatConfigs.recommended.rules, // [!code --] |
| 30 | + ...jsxA11yX.configs.recommended.rules, // [!code ++] |
| 31 | + 'jsx-a11y/no-autofocus': 'off', // [!code --] |
| 32 | + 'jsx-a11y-x/no-autofocus': 'off' // [!code ++] |
| 33 | + }, |
| 34 | + settings: { |
| 35 | + 'jsx-a11y': { components: { Image: 'img' } }, // [!code --] |
| 36 | + 'jsx-a11y-x': { components: { Image: 'img' } } // [!code ++] |
| 37 | + } |
| 38 | + } |
| 39 | +] |
| 40 | +``` |
| 41 | + |
| 42 | +> [!NOTE] |
| 43 | +> Settings under the old `jsx-a11y` key are ignored without a warning, so make sure to rename that key too. The deprecated `accessible-emoji`, `label-has-for` and `no-onchange` rules no longer exist and should be removed. See [the migration notes](https://github.com/eslint-community/eslint-plugin-jsx-a11y-x#migrating-from-eslint-plugin-jsx-a11y) for the full list. |
| 44 | +
|
| 45 | +## Oxlint |
| 46 | + |
| 47 | +[Oxlint](https://oxc.rs/docs/guide/usage/linter.html) is a high-performance linter for JavaScript and TypeScript, built on the Rust-based `Oxc` compiler stack. It has ported [all of the non-deprecated `eslint-plugin-jsx-a11y` rules](https://github.com/oxc-project/oxc/issues/1141). |
| 48 | + |
| 49 | +The migration process from ESLint is covered in [the Oxlint documentation](https://oxc.rs/docs/guide/usage/linter/migrate-from-eslint.html), and can be done automatically from an ESLint flat config using [`npx @oxlint/migrate`](https://github.com/oxc-project/oxlint-migrate). |
0 commit comments