Skip to content

Commit 28c61d2

Browse files
authored
Create accessibility config (#30)
* feat: create a11y config * chore: remove unnecessary rules (rule is the default) * chore: add type checking for test config * feat: add a counter-example of a11y rules in example app
1 parent 2e8c7a8 commit 28c61d2

File tree

10 files changed

+1530
-1483
lines changed

10 files changed

+1530
-1483
lines changed

example-app/.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"root": true,
3-
"extends": "plugin:@bam.tech/recommended",
3+
"extends": ["plugin:@bam.tech/recommended", "plugin:@bam.tech/a11y"],
44
"overrides": [
55
{
66
"files": ["*.test.tsx"],

example-app/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
18
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Save without formatting: [⌘ + K] > [S]
2+
3+
// This should trigger one error breaking eslint-plugin-react-native:
4+
// react-native-a11y/has-valid-accessibility-descriptors
5+
6+
import { Pressable, Text } from "react-native";
7+
8+
export const MyCustomButton = () => {
9+
return (
10+
<Pressable>
11+
<Text>Click here!</Text>
12+
<Text>Here is a short summary</Text>
13+
</Pressable>
14+
);
15+
};

example-app/package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,31 @@
66
"scripts": {
77
"start": "node .",
88
"lint": "eslint .",
9-
"types":"tsc --noEmit"
9+
"types": "tsc --noEmit"
1010
},
1111
"devDependencies": {
12+
"@bam.tech/eslint-plugin": "*",
13+
"@bam.tech/typescript-config": "*",
1214
"@types/jest": "^29.5.2",
1315
"@types/react": "^18.2.14",
14-
"@bam.tech/typescript-config": "*",
15-
"@typescript-eslint/eslint-plugin": "^5.49.0",
16-
"eslint": "^8.32.0",
16+
"@typescript-eslint/eslint-plugin": "^5.61.0",
17+
"eslint": "^8.44.0",
1718
"eslint-plugin-jest": "^27.2.2",
1819
"eslint-plugin-jest-formatting": "^3.1.0",
1920
"eslint-plugin-prettier": "^4.2.1",
20-
"eslint-plugin-react": "^7.32.1",
21+
"eslint-plugin-react": "^7.31.11",
2122
"eslint-plugin-react-hooks": "^4.6.0",
2223
"eslint-plugin-react-native": "^4.0.0",
24+
"eslint-plugin-react-native-a11y": "^3.3.0",
2325
"eslint-plugin-testing-library": "^5.11.0",
2426
"jest": "^29.5.0",
2527
"prettier": "^2.8.8",
2628
"typescript": "^4.9.4"
2729
},
2830
"private": "true",
2931
"dependencies": {
32+
"expo": "^47.0.13",
3033
"react": "^18.2.0",
31-
"react-native": "^0.72.0",
32-
"expo": "^47.0.13"
34+
"react-native": "^0.72.0"
3335
}
3436
}

packages/eslint-plugin/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ This project is an ESLint plugin that gathers all the rules, plugins and parsers
77
Install the plugin and its peer dependencies:
88

99
```bash
10-
yarn add --dev @bam.tech/eslint-plugin
11-
npx install-peerdeps --dev @bam.tech/eslint-plugin
10+
yarn add @bam.tech/eslint-plugin --dev
11+
npx install-peerdeps @bam.tech/eslint-plugin --dev --yarn
1212
```
1313

1414
Then update your `.eslintrc` config file:
@@ -30,10 +30,11 @@ Then update your `.eslintrc` config file:
3030

3131
This plugin exports multiple configurations that can be used in your `.eslintrc` config file:
3232

33-
| Name | Description |
34-
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
35-
| `@bam.tech/recommended` | The recommended config for all projects |
36-
| `@bam.tech/tests` | The recommended config for test files. By default this applies to every file: put it in an `overrides` to filter on your test files. |
33+
| Name | Description |
34+
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
35+
| `@bam.tech/recommended` | The recommended config for all projects |
36+
| `@bam.tech/tests` | The recommended config for test files. By default this applies to every file: put it in an `overrides` to filter on your test files. |
37+
| `@bam.tech/a11y` | [beta] Eslint config to check for accessibility. Still in beta to not break existing projects, but will be merged into the recommended config in the future. |
3738

3839
These configs need some peer dependencies. You can list them with:
3940

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @ts-check
2+
"use strict";
3+
4+
const { defineConfig } = require("eslint-define-config");
5+
6+
module.exports = defineConfig({
7+
extends: ["plugin:react-native-a11y/all"],
8+
rules: {
9+
"react-native-a11y/has-accessibility-hint": "off",
10+
},
11+
});

packages/eslint-plugin/lib/configs/recommended.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ module.exports = defineConfig({
3333
"@typescript-eslint/no-unused-vars": "error",
3434
"no-console": ["error", { allow: ["warn", "error"] }],
3535
"no-return-await": "error",
36-
"prettier/prettier": ["error", { printWidth: 80 }],
3736
"react-hooks/exhaustive-deps": "error",
3837
"react-native/no-color-literals": "off",
3938
"react-native/no-raw-text": ["error", { skip: ["Trans"] }],

packages/eslint-plugin/lib/configs/tests.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// @ts-check
2+
"use strict";
3+
14
const { defineConfig } = require("eslint-define-config");
25

36
module.exports = defineConfig({

packages/eslint-plugin/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"eslint-plugin-react": "^7.31.11",
3333
"eslint-plugin-react-hooks": "^4.6.0",
3434
"eslint-plugin-react-native": "^4.0.0",
35+
"eslint-plugin-react-native-a11y": "^3.3.0",
3536
"eslint-plugin-testing-library": "^5.11.0",
3637
"prettier": "^2.8.8"
3738
},

0 commit comments

Comments
 (0)