@riligar/eslint-config 1.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 +34 -0
- package/dashboard.js +91 -0
- package/package.json +31 -0
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @riligar/eslint-config
|
|
2
|
+
|
|
3
|
+
A config de ESLint dos painéis React da RiLiGar.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
bun add -d @riligar/eslint-config eslint
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
// eslint.config.js
|
|
11
|
+
import dashboard from '@riligar/eslint-config/dashboard'
|
|
12
|
+
|
|
13
|
+
export default dashboard
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Uma regra específica do seu projeto entra espalhando a base primeiro:
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
export default [...dashboard, { files: ['src/x.jsx'], rules: { /* ... */ } }]
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## O que ela carrega
|
|
23
|
+
|
|
24
|
+
Além de `js.configs.recommended`, `react-hooks` e `react-refresh`, três
|
|
25
|
+
exceções — cada uma escrita depois de um falso positivo que travou um deploy.
|
|
26
|
+
O porquê de cada uma está em comentário no próprio [`dashboard.js`](dashboard.js):
|
|
27
|
+
|
|
28
|
+
- **`no-unused-vars` com `argsIgnorePattern: '^[A-Z_]'`** — sem o plugin react,
|
|
29
|
+
o linter não enxerga `<Icon />` no JSX e acusa todo componente que recebe um
|
|
30
|
+
ícone por prop no padrão `{ icon: Icon }`.
|
|
31
|
+
- **`react-hooks/set-state-in-effect` como aviso** — a regra não distingue uma
|
|
32
|
+
carga inicial no mount de uma cascata de renders.
|
|
33
|
+
- **`react-hooks/preserve-manual-memoization` como aviso** — é o React Compiler
|
|
34
|
+
relatando uma otimização que não pôde manter, não um defeito.
|
package/dashboard.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config de ESLint dos sete painéis.
|
|
3
|
+
*
|
|
4
|
+
* Antes do monorepo isto era SETE arquivos `eslint.config.js`, um por
|
|
5
|
+
* dashboard, com cinco conteúdos diferentes entre eles — a divergência era
|
|
6
|
+
* só de comentário e de uma exceção a mais num deles, mas nada garantia
|
|
7
|
+
* que continuasse assim. Agora é um arquivo, e cada painel o estende.
|
|
8
|
+
*
|
|
9
|
+
* Uso, em `apps/<produto>/dashboard/eslint.config.js`:
|
|
10
|
+
*
|
|
11
|
+
* import dashboard from '@riligar/eslint-config/dashboard'
|
|
12
|
+
* export default dashboard
|
|
13
|
+
*
|
|
14
|
+
* Uma regra específica de um painel se acrescenta assim:
|
|
15
|
+
*
|
|
16
|
+
* export default [...dashboard, { files: ['src/x.jsx'], rules: {...} }]
|
|
17
|
+
*/
|
|
18
|
+
import js from '@eslint/js'
|
|
19
|
+
import globals from 'globals'
|
|
20
|
+
import reactHooks from 'eslint-plugin-react-hooks'
|
|
21
|
+
import reactRefresh from 'eslint-plugin-react-refresh'
|
|
22
|
+
import { defineConfig, globalIgnores } from 'eslint/config'
|
|
23
|
+
|
|
24
|
+
export default defineConfig([
|
|
25
|
+
globalIgnores(['dist']),
|
|
26
|
+
{
|
|
27
|
+
files: ['**/*.{js,jsx}'],
|
|
28
|
+
extends: [
|
|
29
|
+
js.configs.recommended,
|
|
30
|
+
reactHooks.configs.flat.recommended,
|
|
31
|
+
reactRefresh.configs.vite,
|
|
32
|
+
],
|
|
33
|
+
languageOptions: {
|
|
34
|
+
ecmaVersion: 2020,
|
|
35
|
+
globals: globals.browser,
|
|
36
|
+
parserOptions: {
|
|
37
|
+
ecmaVersion: 'latest',
|
|
38
|
+
ecmaFeatures: { jsx: true },
|
|
39
|
+
sourceType: 'module',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
rules: {
|
|
43
|
+
/*
|
|
44
|
+
* `varsIgnorePattern` cobre variáveis; `argsIgnorePattern` cobre
|
|
45
|
+
* parâmetros — e é aí que caem os aliases de componente do padrão
|
|
46
|
+
* `{ icon: Icon }`, usados só dentro do JSX. Sem o plugin react (que
|
|
47
|
+
* lê JSX), o linter não enxerga `<Icon />` e acusa falso positivo em
|
|
48
|
+
* todo componente que recebe um ícone por prop.
|
|
49
|
+
*
|
|
50
|
+
* A inicial maiúscula é o que distingue componente de valor comum, e é
|
|
51
|
+
* exatamente o mesmo critério que já valia para as variáveis.
|
|
52
|
+
*/
|
|
53
|
+
'no-unused-vars': [
|
|
54
|
+
'error',
|
|
55
|
+
{ varsIgnorePattern: '^[A-Z_]', argsIgnorePattern: '^[A-Z_]' },
|
|
56
|
+
],
|
|
57
|
+
|
|
58
|
+
/*
|
|
59
|
+
* `set-state-in-effect` as a WARNING, not an error.
|
|
60
|
+
*
|
|
61
|
+
* The occurrences across this stack are initial data loads on mount or
|
|
62
|
+
* syncing a prop into local state — the correct React pattern. The rule
|
|
63
|
+
* does not tell that apart from a render cascade: it sees a synchronous
|
|
64
|
+
* `setState` and flags it.
|
|
65
|
+
*
|
|
66
|
+
* It stays a warning so it keeps showing up in new code, where it may be
|
|
67
|
+
* a real defect, without blocking the deploy over a false positive.
|
|
68
|
+
*/
|
|
69
|
+
'react-hooks/set-state-in-effect': 'warn',
|
|
70
|
+
|
|
71
|
+
/*
|
|
72
|
+
* `preserve-manual-memoization` as a WARNING.
|
|
73
|
+
*
|
|
74
|
+
* This is the React Compiler reporting that it could not keep an existing
|
|
75
|
+
* `useCallback`/`useMemo` while compiling — a missed optimisation, not a
|
|
76
|
+
* defect: the code behaves exactly as written either way.
|
|
77
|
+
*/
|
|
78
|
+
'react-hooks/preserve-manual-memoization': 'warn',
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
/*
|
|
83
|
+
* The entrypoint mounts the tree and is reused by nobody: Fast Refresh does
|
|
84
|
+
* not apply to it, and forcing the component out of here would create a file
|
|
85
|
+
* just to satisfy a rule that protects nothing in this case. The rule still
|
|
86
|
+
* holds everywhere else.
|
|
87
|
+
*/
|
|
88
|
+
files: ['src/main.jsx'],
|
|
89
|
+
rules: { 'react-refresh/only-export-components': 'off' },
|
|
90
|
+
},
|
|
91
|
+
])
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@riligar/eslint-config",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "A config de ESLint dos painéis React da RiLiGar: as três exceções que o linter precisa para não acusar falso positivo em código correto.",
|
|
7
|
+
"exports": {
|
|
8
|
+
"./dashboard": "./dashboard.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dashboard.js",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@eslint/js": "^9.39.4",
|
|
16
|
+
"eslint-plugin-react-hooks": "7.1.1",
|
|
17
|
+
"eslint-plugin-react-refresh": "^0.4.26",
|
|
18
|
+
"globals": "^16.5.0"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"eslint": "^9.39.4"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/riligar/packages.git",
|
|
29
|
+
"directory": "eslint-config"
|
|
30
|
+
}
|
|
31
|
+
}
|