You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This change adds support for ESLint's new Flat config system.
It maintains backwards compatibility with eslintrc style configs as well.
To achieve this, we're now dynamically creating four configs: two are the original `recommended` and `strict`, and the other two are the new `flat/recommended` and `flat/strict`.
The two `flat` ones are setup with the new config format, while the original two have the same options as before.
Usage
Legacy
```json
{
"extends": ["plugin:jsx-a11y/recommended"]
}
```
Flat
```js
import globals from 'globals';
import js from '@eslint/js';
import jsxA11y from 'eslint-plugin-jsx-a11y';
export default [
js.configs.recommended,
jsxA11y.flatConfigs.recommended,
{
files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
globals: globals.browser,
},
ignores: ['dist', 'eslint.config.js'],
rules: {
'no-unused-vars': 'warn',
'jsx-a11y/anchor-ambiguous-text': 'warn',
'jsx-a11y/anchor-is-valid': 'warn',
},
},
];
```
**Note:** If you installed ESLint globally (using the `-g` flag in npm, or the `global` prefix in yarn) then you must also install `eslint-plugin-jsx-a11y` globally.
62
62
63
-
## Usage
63
+
<aid="usage"></a>
64
+
## Usage - Legacy Config (`.eslintrc`)
64
65
65
66
Add `jsx-a11y` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
66
67
@@ -109,6 +110,94 @@ Add `plugin:jsx-a11y/recommended` or `plugin:jsx-a11y/strict` in `extends`:
109
110
}
110
111
```
111
112
113
+
## Usage - Flat Config (`eslint.config.js`)
114
+
115
+
The default export of `eslint-plugin-jsx-a11y` is a plugin object.
There are two shareable configs, provided by the plugin.
147
+
148
+
-`flatConfigs.recommended`
149
+
-`flatConfigs.strict`
150
+
151
+
#### CJS
152
+
153
+
```js
154
+
constjsxA11y=require('eslint-plugin-jsx-a11y');
155
+
156
+
exportdefault [
157
+
jsxA11y.flatConfigs.recommended,
158
+
{
159
+
// Your additional configs and overrides
160
+
},
161
+
];
162
+
```
163
+
164
+
#### ESM
165
+
166
+
```js
167
+
importjsxA11yfrom'eslint-plugin-jsx-a11y';
168
+
169
+
exportdefault [
170
+
jsxA11y.flatConfigs.recommended,
171
+
{
172
+
// Your additional configs and overrides
173
+
},
174
+
];
175
+
```
176
+
177
+
**Note**: Our shareable config do configure `files` or [`languageOptions.globals`](https://eslint.org/docs/latest/user-guide/configuring/configuration-files-new#configuration-objects).
178
+
For most of the cases, you probably want to configure some of these properties yourself.
To enable your custom components to be checked as DOM elements, you can set global settings in your configuration file by mapping each custom component name to a DOM element type.
@@ -124,7 +213,7 @@ For example, if you set the `polymorphicPropName` setting to `as` then this elem
124
213
125
214
will be evaluated as an `h3`. If no `polymorphicPropName` is set, then the component will be evaluated as `Box`.
126
215
127
-
⚠️ Polymorphic components can make code harder to maintain; please use this feature with caution.
216
+
⚠️ Polymorphic components can make code harder to maintain; please use this feature with caution.
0 commit comments