@paulhfischer/eslint-config-typescript-react 1.42.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -18
- package/index.js +33 -16
- package/package.json +10 -15
- package/rules.js +39 -0
package/README.md
CHANGED
|
@@ -1,39 +1,82 @@
|
|
|
1
1
|
# eslint-config-typescript-react
|
|
2
2
|
|
|
3
|
-
ESLint-config for typed React projects. It
|
|
3
|
+
ESLint-config for typed React projects. It extends
|
|
4
|
+
[`eslint-config-typescript`](https://github.com/paulhfischer/eslint-config-typescript) with
|
|
4
5
|
|
|
5
|
-
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
-
|
|
6
|
+
- the `strict` configs of [`@eslint-react/eslint-plugin`](https://eslint-react.xyz) (including
|
|
7
|
+
the rules of hooks) and
|
|
8
|
+
[`eslint-plugin-jsx-a11y-x`](https://github.com/es-tooling/eslint-plugin-jsx-a11y-x) and
|
|
9
|
+
- the React rules of the [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript),
|
|
10
|
+
mapped to these plugins (see [`rules.js`](rules.js)).
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
### Usage
|
|
11
13
|
|
|
12
|
-
-
|
|
13
|
-
- [`eslint-plugin-jinja2-processor`](https://github.com/paulhfischer/eslint-plugin-jinja2-processor)
|
|
14
|
+
#### pre-commit
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
1. Add the hook to your `.pre-commit-config.yaml`:
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
```yaml
|
|
19
|
+
- repo: https://github.com/paulhfischer/eslint-config-typescript-react
|
|
20
|
+
rev: v2.0.0
|
|
21
|
+
hooks:
|
|
22
|
+
- id: lint
|
|
23
|
+
```
|
|
18
24
|
|
|
19
|
-
|
|
25
|
+
2. Add the config to your `eslint.config.cjs`:
|
|
20
26
|
|
|
27
|
+
```js
|
|
28
|
+
module.exports = require('@paulhfischer/eslint-config-typescript-react');
|
|
21
29
|
```
|
|
22
|
-
|
|
30
|
+
|
|
31
|
+
or, to adjust it:
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
const config = require('@paulhfischer/eslint-config-typescript-react');
|
|
35
|
+
|
|
36
|
+
module.exports = [...config, { rules: { 'jsx-a11y-x/no-autofocus': 'off' } }];
|
|
23
37
|
```
|
|
24
38
|
|
|
25
|
-
_Note: The
|
|
39
|
+
_Note: The config has to be a CommonJS-file using `require()`, as ES modules can't import
|
|
40
|
+
packages from the environment pre-commit installs the hook into._
|
|
26
41
|
|
|
27
|
-
|
|
42
|
+
3. Add the prettier configuration to your `.prettierrc`:
|
|
28
43
|
|
|
29
44
|
```json
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
45
|
+
"@paulhfischer/prettier-config"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
_Note: Type-aware rules use the `tsconfig.json` closest to each file and need the dependencies of
|
|
49
|
+
your project to be installed (otherwise their types can't be resolved)._
|
|
50
|
+
|
|
51
|
+
#### npm
|
|
52
|
+
|
|
53
|
+
1. Install via `npm`:
|
|
54
|
+
|
|
33
55
|
```
|
|
56
|
+
npm install --save-dev @paulhfischer/eslint-config-typescript-react
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
_Note: Have a look at the `.pre-commit-hooks.yaml`-file for a list of all peer-dependencies._
|
|
60
|
+
|
|
61
|
+
2. Add the config to your `eslint.config.js`:
|
|
34
62
|
|
|
35
|
-
|
|
63
|
+
```js
|
|
64
|
+
import config from '@paulhfischer/eslint-config-typescript-react';
|
|
65
|
+
|
|
66
|
+
export default config;
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
3. Add the prettier configuration to your `.prettierrc` (or the `prettier`-key of your
|
|
70
|
+
`package.json`):
|
|
36
71
|
|
|
37
72
|
```json
|
|
38
73
|
"@paulhfischer/prettier-config"
|
|
39
74
|
```
|
|
75
|
+
|
|
76
|
+
### Migrating from version 1
|
|
77
|
+
|
|
78
|
+
- Version 2 requires ESLint 10 and flat configs. Replace your `.eslintrc`-file or the
|
|
79
|
+
`eslintConfig`-key of your `package.json` with an `eslint.config.cjs`-file (see above).
|
|
80
|
+
- Rules were renamed: `import/…` becomes `import-x/…`, `react/…` and `react-hooks/…` become
|
|
81
|
+
`@eslint-react/…` and `jsx-a11y/…` becomes `jsx-a11y-x/…`. The React version is detected
|
|
82
|
+
automatically, so `settings.react.version` is no longer needed.
|
package/index.js
CHANGED
|
@@ -1,19 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import eslintReact from '@eslint-react/eslint-plugin';
|
|
2
|
+
import { base, prettier, tsFiles, typescript } from '@paulhfischer/eslint-config-typescript';
|
|
3
|
+
import jsxA11y from 'eslint-plugin-jsx-a11y-x';
|
|
4
|
+
import { defineConfig } from 'eslint/config';
|
|
5
|
+
|
|
6
|
+
import rules, { typeChecked } from './rules.js';
|
|
7
|
+
|
|
8
|
+
export { base, prettier, tsFiles, typescript };
|
|
9
|
+
|
|
10
|
+
export const jsFiles = ['**/*.js', '**/*.jsx', '**/*.mjs', '**/*.cjs'];
|
|
11
|
+
|
|
12
|
+
export const react = defineConfig(
|
|
13
|
+
{
|
|
14
|
+
name: '@paulhfischer/react/javascript',
|
|
15
|
+
files: jsFiles,
|
|
16
|
+
extends: [eslintReact.configs.strict],
|
|
7
17
|
},
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
es6: true,
|
|
14
|
-
node: true,
|
|
18
|
+
{
|
|
19
|
+
name: '@paulhfischer/react/typescript',
|
|
20
|
+
files: tsFiles,
|
|
21
|
+
extends: [eslintReact.configs['strict-type-checked']],
|
|
22
|
+
rules: typeChecked,
|
|
15
23
|
},
|
|
16
|
-
|
|
17
|
-
|
|
24
|
+
{
|
|
25
|
+
name: '@paulhfischer/react/rules',
|
|
26
|
+
files: [...jsFiles, ...tsFiles],
|
|
27
|
+
extends: [jsxA11y.configs.strict],
|
|
28
|
+
rules,
|
|
18
29
|
},
|
|
19
|
-
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const config = [...base, ...typescript, ...react, ...prettier];
|
|
33
|
+
|
|
34
|
+
export default config;
|
|
35
|
+
// returned by `require()`, so that CommonJS configs can use it directly
|
|
36
|
+
export { config as 'module.exports' };
|
package/package.json
CHANGED
|
@@ -1,36 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paulhfischer/eslint-config-typescript-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "ESLint-config for typed React projects.",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "index.js",
|
|
6
7
|
"author": "Paul Fischer <paul.fischer@mailbox.org>",
|
|
7
8
|
"repository": {
|
|
8
9
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/paulhfischer/eslint-config-typescript-react"
|
|
10
|
+
"url": "git+https://github.com/paulhfischer/eslint-config-typescript-react.git"
|
|
10
11
|
},
|
|
11
12
|
"license": "GPL-3.0",
|
|
12
13
|
"publishConfig": {
|
|
13
14
|
"access": "public"
|
|
14
15
|
},
|
|
15
|
-
"eslintConfig": {
|
|
16
|
-
"extends": [
|
|
17
|
-
"@paulhfischer/eslint-config-javascript"
|
|
18
|
-
]
|
|
19
|
-
},
|
|
20
16
|
"prettier": "@paulhfischer/prettier-config",
|
|
21
17
|
"peerDependencies": {
|
|
22
|
-
"@
|
|
23
|
-
"eslint-config-
|
|
24
|
-
"eslint
|
|
25
|
-
"eslint-
|
|
26
|
-
"eslint-plugin-html": "8.2.1",
|
|
27
|
-
"eslint-plugin-jinja2-processor": "1.2.0",
|
|
28
|
-
"eslint-plugin-prettier": "5.5.6"
|
|
18
|
+
"@eslint-react/eslint-plugin": "5.28.0",
|
|
19
|
+
"@paulhfischer/eslint-config-typescript": "2.0.0",
|
|
20
|
+
"eslint": "10.12.0",
|
|
21
|
+
"eslint-plugin-jsx-a11y-x": "0.2.0"
|
|
29
22
|
},
|
|
30
23
|
"files": [
|
|
31
|
-
"index.js"
|
|
24
|
+
"index.js",
|
|
25
|
+
"rules.js"
|
|
32
26
|
],
|
|
33
27
|
"engines": {
|
|
28
|
+
"node": "^20.19.0 || ^22.13.0 || >=24",
|
|
34
29
|
"npm": ">=7"
|
|
35
30
|
}
|
|
36
31
|
}
|
package/rules.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// React rules of the Airbnb JavaScript Style Guide (https://github.com/airbnb/javascript), mapped to
|
|
2
|
+
// `@eslint-react/eslint-plugin` and `eslint-plugin-jsx-a11y-x`, on top of their `strict` configs.
|
|
3
|
+
|
|
4
|
+
export const react = {
|
|
5
|
+
'@eslint-react/dom-no-missing-button-type': 'error',
|
|
6
|
+
'@eslint-react/dom-no-missing-iframe-sandbox': 'error',
|
|
7
|
+
'@eslint-react/dom-no-unsafe-target-blank': 'error',
|
|
8
|
+
'@eslint-react/jsx-no-useless-fragment': 'error',
|
|
9
|
+
'@eslint-react/no-array-index-key': 'error',
|
|
10
|
+
'@eslint-react/no-unstable-context-value': 'error',
|
|
11
|
+
'@eslint-react/no-unstable-default-props': 'error',
|
|
12
|
+
'@eslint-react/no-unused-state': 'error',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const a11y = {
|
|
16
|
+
'jsx-a11y-x/anchor-is-valid': [
|
|
17
|
+
'error',
|
|
18
|
+
{
|
|
19
|
+
components: ['Link'],
|
|
20
|
+
specialLink: ['to'],
|
|
21
|
+
aspects: ['noHref', 'invalidHref', 'preferButton'],
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
'jsx-a11y-x/lang': 'error',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const typeChecked = {
|
|
28
|
+
'@eslint-react/no-unused-props': 'error',
|
|
29
|
+
// allow async event handlers
|
|
30
|
+
'@typescript-eslint/no-misused-promises': [
|
|
31
|
+
'error',
|
|
32
|
+
{ checksVoidReturn: { attributes: false } },
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default {
|
|
37
|
+
...react,
|
|
38
|
+
...a11y,
|
|
39
|
+
};
|