Skip to content

Commit d155b53

Browse files
committed
Add accessibility rules to React config
1 parent c9bf102 commit d155b53

File tree

9 files changed

+247
-77
lines changed

9 files changed

+247
-77
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ All peer dependencies used by `@code-pushup/eslint-config` are listed below, alo
8585
| ![cypress](./docs/icons/material/cypress.png) | [eslint-plugin-cypress](https://www.npmjs.com/package/eslint-plugin-cypress) | `>=3.3.0` | |
8686
| ![jest](./docs/icons/material/jest.png) | [eslint-plugin-jest](https://www.npmjs.com/package/eslint-plugin-jest) | `^28.8.0` | |
8787
| ![test](./docs/icons/icons8/test.png) | [eslint-plugin-jest-formatting](https://www.npmjs.com/package/eslint-plugin-jest-formatting) | `^3.0.0` | |
88+
| ![accessibility](./docs/icons/icons8/accessibility.png) | [eslint-plugin-jsx-a11y](https://www.npmjs.com/package/eslint-plugin-jsx-a11y) | `^6.10.0` | |
8889
| ![nodejs](./docs/icons/material/nodejs.png) | [eslint-plugin-n](https://www.npmjs.com/package/eslint-plugin-n) | `>=17.0.0` | |
8990
| ![playwright](./docs/icons/material/playwright.png) | [eslint-plugin-playwright](https://www.npmjs.com/package/eslint-plugin-playwright) | `^2.1.0` | |
9091
| ![react](./docs/icons/material/react.png) | [eslint-plugin-react](https://www.npmjs.com/package/eslint-plugin-react) | `^7.36.0` | |

docs/icons/icons8/accessibility.png

610 Bytes
Loading

docs/react.md

Lines changed: 109 additions & 77 deletions
Large diffs are not rendered by default.

package-lock.json

Lines changed: 119 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"eslint-plugin-import": "^2.31.0",
5050
"eslint-plugin-jest": "^28.8.0",
5151
"eslint-plugin-jest-formatting": "^3.0.0",
52+
"eslint-plugin-jsx-a11y": "^6.10.0",
5253
"eslint-plugin-n": ">=17.0.0",
5354
"eslint-plugin-playwright": "^2.1.0",
5455
"eslint-plugin-promise": ">=6.4.0",
@@ -85,6 +86,9 @@
8586
"eslint-plugin-jest-formatting": {
8687
"optional": true
8788
},
89+
"eslint-plugin-jsx-a11y": {
90+
"optional": true
91+
},
8892
"eslint-plugin-n": {
8993
"optional": true
9094
},
@@ -126,6 +130,7 @@
126130
"eslint-plugin-import": "^2.31.0",
127131
"eslint-plugin-jest": "^28.8.0",
128132
"eslint-plugin-jest-formatting": "^3.1.0",
133+
"eslint-plugin-jsx-a11y": "^6.10.2",
129134
"eslint-plugin-n": "^17.0.0",
130135
"eslint-plugin-playwright": "^2.1.0",
131136
"eslint-plugin-promise": "^6.4.0",

scripts/helpers/plugins.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const pluginIcons = {
1414
import: 'icons8/import',
1515
jest: 'material/jest',
1616
'jest-formatting': 'icons8/test',
17+
'jsx-a11y': 'icons8/accessibility',
1718
n: 'material/nodejs',
1819
'no-secrets': 'icons8/secure',
1920
playwright: 'material/playwright',
@@ -47,6 +48,7 @@ const pluginDocsUrls = {
4748
jest: 'https://github.com/jest-community/eslint-plugin-jest#readme',
4849
'jest-formatting':
4950
'https://github.com/dangreenisrael/eslint-plugin-jest-formatting#readme',
51+
'jsx-a11y': 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y#readme',
5052
n: 'https://github.com/eslint-community/eslint-plugin-n#readme',
5153
'no-secrets': 'https://github.com/nickdeis/eslint-plugin-no-secrets#readme',
5254
playwright:

scripts/helpers/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export type PeerDep = {
3030

3131
// corresponds to PNG file names in docs/icons
3232
export type Icon =
33+
| 'icons8/accessibility'
3334
| 'icons8/expired'
3435
| 'icons8/global'
3536
| 'icons8/import'

src/configs/react.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @ts-check
22

3+
import jsxA11y from 'eslint-plugin-jsx-a11y';
34
import react from 'eslint-plugin-react';
45
import reactHooks from 'eslint-plugin-react-hooks';
56
import globals from 'globals';
@@ -14,6 +15,7 @@ export default tseslint.config({
1415
extends: [
1516
// @ts-expect-error types inferred as possibly undefined
1617
react.configs.flat.recommended,
18+
jsxA11y.flatConfigs.recommended,
1719
{
1820
name: 'code-pushup/react/react-hooks',
1921
plugins: {
@@ -29,6 +31,8 @@ export default tseslint.config({
2931
name: 'code-pushup/react/customized',
3032
rules: {
3133
'react/display-name': 'warn',
34+
'jsx-a11y/no-autofocus': 'warn',
35+
'jsx-a11y/no-redundant-roles': 'warn',
3236
},
3337
},
3438
{
@@ -88,6 +92,7 @@ export default tseslint.config({
8892
'react/static-property-placement': 'warn',
8993
'react/style-prop-object': 'warn',
9094
'react/void-dom-elements-no-children': 'error',
95+
'jsx-a11y/prefer-tag-over-role': 'warn',
9196
},
9297
},
9398
],

tests/configs/react.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@ describe('react config', () => {
3434
const config = await loadConfig();
3535
expect(Object.keys(config.rules ?? {}).join(',')).toContain('react-hooks/');
3636
});
37+
38+
it('should have rule from extended recommended jsx-a11y config', async () => {
39+
const config = await loadConfig();
40+
expect(config.rules).toHaveProperty('jsx-a11y/alt-text');
41+
});
3742
});

0 commit comments

Comments
 (0)