@panates/eslint-config-react 0.0.0-stage → 2.3.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/LICENSE +21 -0
- package/README.md +53 -2
- package/configs/next.d.ts +5 -0
- package/configs/next.js +17 -0
- package/configs/react-patch.d.ts +5 -0
- package/configs/react-patch.js +57 -0
- package/configs/react.d.ts +5 -0
- package/configs/react.js +11 -0
- package/configs/vite.d.ts +5 -0
- package/configs/vite.js +18 -0
- package/index.d.ts +11 -0
- package/index.js +15 -0
- package/package.json +77 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Panates
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,54 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @panates/eslint-config-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React rules for Panates' ESLint config, on top of
|
|
4
|
+
[`@panates/eslint-config-ts`](https://github.com/panates/javascript/tree/main/packages/eslint-config-ts).
|
|
5
|
+
For TypeScript React projects, ESLint 10 and flat config.
|
|
6
|
+
|
|
7
|
+
| Config | For | Brings |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `configs.react` | any React project in a browser | [`@eslint-react`](https://eslint-react.xyz) for components and JSX, React's own [`react-hooks`](https://react.dev/reference/eslint-plugin-react-hooks) for hooks and the React Compiler |
|
|
10
|
+
| `@panates/eslint-config-react/next` | Next.js | the above, plus [`@next/eslint-plugin-next`](https://nextjs.org/docs/app/api-reference/config/eslint) at `core-web-vitals` |
|
|
11
|
+
| `@panates/eslint-config-react/vite` | Vite | the above, plus [`react-refresh`](https://github.com/ArnaudBarre/eslint-plugin-react-refresh) for hot reload |
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm i -D eslint @panates/eslint-config-react @eslint-react/eslint-plugin eslint-plugin-react-hooks
|
|
17
|
+
# Next.js
|
|
18
|
+
npm i -D @next/eslint-plugin-next
|
|
19
|
+
# Vite
|
|
20
|
+
npm i -D eslint-plugin-react-refresh
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Use
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
// eslint.config.mjs
|
|
27
|
+
import panatesReact from '@panates/eslint-config-react';
|
|
28
|
+
|
|
29
|
+
export default [...panatesReact.configs.react];
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
// eslint.config.mjs - Next.js
|
|
34
|
+
import next from '@panates/eslint-config-react/next';
|
|
35
|
+
|
|
36
|
+
export default [{ ignores: ['.next/**'] }, ...next];
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
// eslint.config.mjs - Vite
|
|
41
|
+
import vite from '@panates/eslint-config-react/vite';
|
|
42
|
+
|
|
43
|
+
export default [{ ignores: ['dist/**'] }, ...vite];
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`configPatches.react` is the React layer alone, to add on top of a config of your own.
|
|
47
|
+
|
|
48
|
+
## Notes
|
|
49
|
+
|
|
50
|
+
- **`@eslint-react`, not `eslint-plugin-react`**: the latter, and `eslint-plugin-jsx-a11y`, support
|
|
51
|
+
ESLint 9 at most. Accessibility rules will come as a patch once a plugin supports ESLint 10.
|
|
52
|
+
- **Hooks are checked once.** Rules both plugins have (`rules-of-hooks`, `exhaustive-deps`, the
|
|
53
|
+
React Compiler ones) are left to `react-hooks`.
|
|
54
|
+
- **Relative imports need no extension** (`import-x/extensions` is off) - a bundler resolves them.
|
package/configs/next.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import nextPlugin from '@next/eslint-plugin-next';
|
|
2
|
+
import reactConfig from './react.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A Next.js application: the React config plus Next's own rules, at the stricter
|
|
6
|
+
* `core-web-vitals` level `create-next-app` sets up (it includes `recommended`).
|
|
7
|
+
*
|
|
8
|
+
* Its own entry point (`@panates/eslint-config-react/next`), so a project that is not on Next does
|
|
9
|
+
* not need `@next/eslint-plugin-next` installed.
|
|
10
|
+
*/
|
|
11
|
+
export default [
|
|
12
|
+
...reactConfig,
|
|
13
|
+
{
|
|
14
|
+
...nextPlugin.configs['core-web-vitals'],
|
|
15
|
+
name: 'panates/next',
|
|
16
|
+
},
|
|
17
|
+
];
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import eslintReact from '@eslint-react/eslint-plugin';
|
|
2
|
+
import reactHooks from 'eslint-plugin-react-hooks';
|
|
3
|
+
|
|
4
|
+
/** Every file a component or a hook can live in - a hook in a plain `.ts` included. */
|
|
5
|
+
const FILES = ['**/*.{ts,tsx,mts,cts,jsx}'];
|
|
6
|
+
|
|
7
|
+
const eslintReactRecommended = eslintReact.configs['recommended-typescript'];
|
|
8
|
+
const reactHooksRecommended = reactHooks.configs.flat.recommended;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The rules both plugins ship under the same name - `rules-of-hooks`, `exhaustive-deps` and the
|
|
12
|
+
* React Compiler ones - turned off on the `@eslint-react` side. Derived from the two configs rather
|
|
13
|
+
* than listed, because the overlap moves as either plugin adds rules: a list written by hand missed
|
|
14
|
+
* `exhaustive-deps`, which reported every missing dependency twice.
|
|
15
|
+
*/
|
|
16
|
+
const duplicatesOff = Object.fromEntries(
|
|
17
|
+
Object.keys(eslintReactRecommended.rules)
|
|
18
|
+
.filter((rule) => `react-hooks/${rule.replace('@eslint-react/', '')}` in reactHooksRecommended.rules)
|
|
19
|
+
.map((rule) => [rule, 'off']),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* React on top of a TypeScript config: `@eslint-react`'s rules for components and JSX, and React's
|
|
24
|
+
* own `react-hooks` for hooks and the React Compiler.
|
|
25
|
+
*
|
|
26
|
+
* `@eslint-react` rather than `eslint-plugin-react`, because the base config needs ESLint 10 and
|
|
27
|
+
* `eslint-plugin-react` (7.37) and `eslint-plugin-jsx-a11y` (6.10) declare support up to 9 only.
|
|
28
|
+
* Its `recommended-typescript` set needs no type information, so it works without a `projectService`.
|
|
29
|
+
*
|
|
30
|
+
* Hooks come from `react-hooks`, not `@eslint-react`: it is React's own plugin, it carries the React
|
|
31
|
+
* Compiler rules. The rules both plugins have are turned off on the `@eslint-react` side
|
|
32
|
+
* (`duplicatesOff`), so one mistake is reported once.
|
|
33
|
+
*
|
|
34
|
+
* `import-x/extensions` is off: the base config asks for `.js` on a relative import, which is Node's
|
|
35
|
+
* ESM rule, while a React project is built by a bundler (Next, Vite) and imports without one.
|
|
36
|
+
* Measured on `abisena-tr`: 272 reports, every one an ordinary `./component` import.
|
|
37
|
+
*/
|
|
38
|
+
export default [
|
|
39
|
+
{
|
|
40
|
+
...eslintReactRecommended,
|
|
41
|
+
name: 'panates/react-patch/eslint-react',
|
|
42
|
+
files: FILES,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
...reactHooksRecommended,
|
|
46
|
+
name: 'panates/react-patch/react-hooks',
|
|
47
|
+
files: FILES,
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'panates/react-patch',
|
|
51
|
+
files: FILES,
|
|
52
|
+
rules: {
|
|
53
|
+
...duplicatesOff,
|
|
54
|
+
'import-x/extensions': 'off',
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
];
|
package/configs/react.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import panatesTs from '@panates/eslint-config-ts';
|
|
2
|
+
import reactPatchConfig from './react-patch.js';
|
|
3
|
+
|
|
4
|
+
/** A React application or library in TypeScript, running in a browser. */
|
|
5
|
+
export default [
|
|
6
|
+
...panatesTs.configs.browser,
|
|
7
|
+
...reactPatchConfig,
|
|
8
|
+
{
|
|
9
|
+
name: 'panates/react',
|
|
10
|
+
},
|
|
11
|
+
];
|
package/configs/vite.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import reactRefreshPlugin from 'eslint-plugin-react-refresh';
|
|
2
|
+
import reactConfig from './react.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A React application built with Vite: the React config plus `react-refresh/only-export-components`,
|
|
6
|
+
* which flags a module whose exports would make Vite's hot reload fall back to a full page reload.
|
|
7
|
+
*
|
|
8
|
+
* Its own entry point (`@panates/eslint-config-react/vite`), so a project that is not on Vite does
|
|
9
|
+
* not need `eslint-plugin-react-refresh` installed.
|
|
10
|
+
*/
|
|
11
|
+
export default [
|
|
12
|
+
...reactConfig,
|
|
13
|
+
{
|
|
14
|
+
...reactRefreshPlugin.configs.vite,
|
|
15
|
+
name: 'panates/vite',
|
|
16
|
+
files: ['**/*.{tsx,jsx}'],
|
|
17
|
+
},
|
|
18
|
+
];
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import reactConfig from './configs/react.js';
|
|
2
|
+
import reactPatchConfig from './configs/react-patch.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Next.js and Vite are not here: each needs a plugin a project on the other does not have, so they
|
|
6
|
+
* are their own entry points - `@panates/eslint-config-react/next` and `.../vite`.
|
|
7
|
+
*/
|
|
8
|
+
export default {
|
|
9
|
+
configs: {
|
|
10
|
+
react: reactConfig,
|
|
11
|
+
},
|
|
12
|
+
configPatches: {
|
|
13
|
+
react: reactPatchConfig,
|
|
14
|
+
},
|
|
15
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,79 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panates/eslint-config-react",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.3.0",
|
|
4
|
+
"description": "React rules for Panates ESLint config, following our styleguide",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"module": "./index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./index.js",
|
|
9
|
+
"./next": "./configs/next.js",
|
|
10
|
+
"./vite": "./configs/vite.js",
|
|
11
|
+
"./package.json": "./package.json"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@panates/eslint-config-ts": "^2.3.0"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"@eslint-react/eslint-plugin": ">=5",
|
|
18
|
+
"@next/eslint-plugin-next": ">=15",
|
|
19
|
+
"eslint-plugin-react-hooks": ">=7",
|
|
20
|
+
"eslint-plugin-react-refresh": ">=0.5"
|
|
21
|
+
},
|
|
22
|
+
"peerDependenciesMeta": {
|
|
23
|
+
"@next/eslint-plugin-next": {
|
|
24
|
+
"optional": true
|
|
25
|
+
},
|
|
26
|
+
"eslint-plugin-react-refresh": {
|
|
27
|
+
"optional": true
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"format": "prettier . --write --log-level=warn",
|
|
32
|
+
"lint": "eslint . --max-warnings=0 --fix",
|
|
33
|
+
"prepublish": "npm run format && npm run lint"
|
|
34
|
+
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=18.0.0"
|
|
37
|
+
},
|
|
38
|
+
"author": "Panates",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"homepage": "https://github.com/panates/javascript.git",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/panates/javascript.git",
|
|
44
|
+
"directory": "./packages/eslint-config-react"
|
|
45
|
+
},
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/panates/javascript/issues"
|
|
48
|
+
},
|
|
49
|
+
"keywords": [
|
|
50
|
+
"eslint",
|
|
51
|
+
"eslintconfig",
|
|
52
|
+
"config",
|
|
53
|
+
"panates",
|
|
54
|
+
"react",
|
|
55
|
+
"nextjs",
|
|
56
|
+
"vite",
|
|
57
|
+
"typescript",
|
|
58
|
+
"styleguide"
|
|
59
|
+
],
|
|
60
|
+
"contributors": [
|
|
61
|
+
"Eray Hanoglu <e.hanoglu@panates.com>",
|
|
62
|
+
"Ilker Gurelli <i.gurelli@panates.com>",
|
|
63
|
+
"Onur Tokel <o.tokel@panates.com>",
|
|
64
|
+
"Bircan Yuruk <b.yuruk@panates.com>"
|
|
65
|
+
],
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@eslint-react/eslint-plugin": "^5.24.10",
|
|
68
|
+
"@next/eslint-plugin-next": "^16.4.0",
|
|
69
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
70
|
+
"eslint-plugin-react-refresh": "^0.5.7"
|
|
71
|
+
},
|
|
72
|
+
"files": [
|
|
73
|
+
"index.js",
|
|
74
|
+
"index.d.ts",
|
|
75
|
+
"configs",
|
|
76
|
+
"README.md",
|
|
77
|
+
"LICENSE"
|
|
78
|
+
]
|
|
79
|
+
}
|