eslint-config-vylda-vanilla-react 4.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/.editorconfig +12 -0
- package/.gitlab-ci.yml +13 -0
- package/.husky/pre-commit +1 -0
- package/.husky/pre-push +1 -0
- package/.vscode/extensions.json +8 -0
- package/.vscode/settings.json +6 -0
- package/Changelog.md +112 -0
- package/LICENSE +24 -0
- package/README.md +294 -0
- package/eslint.config.mjs +55 -0
- package/index.js +150 -0
- package/package.json +43 -0
- package/rules/a11y.mjs +333 -0
- package/rules/best-practices.mjs +57 -0
- package/rules/constants.mjs +20 -0
- package/rules/hooks.mjs +129 -0
- package/rules/imports.mjs +12 -0
- package/rules/index.mjs +37 -0
- package/rules/perfectionist.mjs +33 -0
- package/rules/react.mjs +610 -0
- package/rules/refresh.mjs +10 -0
- package/rules/stylistic.mjs +154 -0
package/rules/hooks.mjs
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
const config = [{
|
|
2
|
+
name: 'react-hooks/hooks',
|
|
3
|
+
rules: {
|
|
4
|
+
// Verifies that automatic effect dependencies are compiled if opted-in.
|
|
5
|
+
// URL is missing in the official documentation.
|
|
6
|
+
'react-hooks/automatic-effect-dependencies': 'off',
|
|
7
|
+
|
|
8
|
+
// Validates against calling capitalized functions/methods instead of using JSX.
|
|
9
|
+
// URL is missing in the official documentation.
|
|
10
|
+
'react-hooks/capitalized-calls': 'off',
|
|
11
|
+
|
|
12
|
+
// Validates against higher order functions defining nested components or hooks.
|
|
13
|
+
// https://react.dev/reference/eslint-plugin-react-hooks/lints/component-hook-factories
|
|
14
|
+
'react-hooks/component-hook-factories': 'warn',
|
|
15
|
+
|
|
16
|
+
// Validates the compiler configuration options.
|
|
17
|
+
// https://react.dev/reference/eslint-plugin-react-hooks/lints/config
|
|
18
|
+
'react-hooks/config': 'off',
|
|
19
|
+
|
|
20
|
+
// Validates usage of Error Boundaries instead of try/catch for errors in child components.
|
|
21
|
+
// https://react.dev/reference/eslint-plugin-react-hooks/lints/error-boundaries
|
|
22
|
+
'react-hooks/error-boundaries': 'error',
|
|
23
|
+
|
|
24
|
+
// Verify the list of the dependencies for Hooks like useEffect and similar.
|
|
25
|
+
// https://react.dev/reference/eslint-plugin-react-hooks/lints/exhaustive-deps
|
|
26
|
+
'react-hooks/exhaustive-deps': 'warn',
|
|
27
|
+
|
|
28
|
+
// Validates usage of fbt.
|
|
29
|
+
// Missing URL in the official documentation.
|
|
30
|
+
'react-hooks/fbt': 'off',
|
|
31
|
+
|
|
32
|
+
// Validates usage of `fire`.
|
|
33
|
+
// Missing URL in the official documentation.
|
|
34
|
+
'react-hooks/fire': 'off',
|
|
35
|
+
|
|
36
|
+
// Validates configuration of gating mode.
|
|
37
|
+
// https://react.dev/reference/eslint-plugin-react-hooks/lints/gating
|
|
38
|
+
'react-hooks/gating': 'off',
|
|
39
|
+
|
|
40
|
+
// Validates against assignment/mutation of globals during render,
|
|
41
|
+
// part of ensuring that side effects must run outside of render.
|
|
42
|
+
// https://react.dev/reference/eslint-plugin-react-hooks/lints/globals
|
|
43
|
+
'react-hooks/globals': 'error',
|
|
44
|
+
|
|
45
|
+
// Validates the rules of hooks.
|
|
46
|
+
// Missing URL in the official documentation.
|
|
47
|
+
'react-hooks/hooks': 'off',
|
|
48
|
+
|
|
49
|
+
// Validates against mutating props, state, and other values that are immutable.
|
|
50
|
+
// https://react.dev/reference/eslint-plugin-react-hooks/lints/immutability
|
|
51
|
+
'react-hooks/immutability': 'error',
|
|
52
|
+
|
|
53
|
+
// Validates against usage of libraries which are incompatible
|
|
54
|
+
// with memoization (manual or automatic).
|
|
55
|
+
// https://react.dev/reference/eslint-plugin-react-hooks/lints/incompatible-library
|
|
56
|
+
'react-hooks/incompatible-library': 'error',
|
|
57
|
+
|
|
58
|
+
// Internal invariants.
|
|
59
|
+
// Missing URL in the official documentation.
|
|
60
|
+
'react-hooks/invariant': 'off',
|
|
61
|
+
|
|
62
|
+
// Validates that effect dependencies are memoized.
|
|
63
|
+
// Missing URL in the official documentation.
|
|
64
|
+
'react-hooks/memoized-effect-dependencies': 'off',
|
|
65
|
+
|
|
66
|
+
// Validates against deriving values from state in an effect.
|
|
67
|
+
// Missing URL in the official documentation.
|
|
68
|
+
'react-hooks/no-deriving-state-in-effects': 'off',
|
|
69
|
+
|
|
70
|
+
// Validates that existing manual memoization is preserved by the compiler.
|
|
71
|
+
// https://react.dev/reference/eslint-plugin-react-hooks/lints/preserve-manual-memoization
|
|
72
|
+
'react-hooks/preserve-manual-memoization': 'warn',
|
|
73
|
+
|
|
74
|
+
// Validates that components/hooks are pure by checking that they
|
|
75
|
+
// do not call known-impure functions.
|
|
76
|
+
// https://react.dev/reference/eslint-plugin-react-hooks/lints/purity
|
|
77
|
+
'react-hooks/purity': 'error',
|
|
78
|
+
|
|
79
|
+
// Validates correct usage of refs, not reading/writing during render.
|
|
80
|
+
// https://react.dev/reference/eslint-plugin-react-hooks/lints/refs
|
|
81
|
+
'react-hooks/refs': 'error',
|
|
82
|
+
|
|
83
|
+
// Validates against suppression of other rules.
|
|
84
|
+
// Missing URL in the official documentation.
|
|
85
|
+
'react-hooks/rule-suppression': 'off',
|
|
86
|
+
|
|
87
|
+
// Enforce Rules of Hooks.
|
|
88
|
+
// https://react.dev/reference/eslint-plugin-react-hooks/lints/rules-of-hooks
|
|
89
|
+
'react-hooks/rules-of-hooks': 'error',
|
|
90
|
+
|
|
91
|
+
// Validates against calling setState synchronously in an effect,
|
|
92
|
+
// which can lead to re-renders that degrade performance.
|
|
93
|
+
// https://react.dev/reference/eslint-plugin-react-hooks/lints/set-state-in-effect
|
|
94
|
+
'react-hooks/set-state-in-effect': 'error',
|
|
95
|
+
|
|
96
|
+
// Validates against unconditionally setting state during render,
|
|
97
|
+
// which can trigger additional renders and potential infinite render loops.
|
|
98
|
+
// https://react.dev/reference/eslint-plugin-react-hooks/lints/set-state-in-render
|
|
99
|
+
'react-hooks/set-state-in-render': 'error',
|
|
100
|
+
|
|
101
|
+
// Validates that components are static, not recreated every render.
|
|
102
|
+
// https://react.dev/reference/eslint-plugin-react-hooks/lints/static-components
|
|
103
|
+
'react-hooks/static-components': 'error',
|
|
104
|
+
|
|
105
|
+
// Validates against invalid syntax.
|
|
106
|
+
// Missing URL in the official documentation.
|
|
107
|
+
'react-hooks/syntax': 'off',
|
|
108
|
+
|
|
109
|
+
// Unimplemented features.
|
|
110
|
+
// Missing URL in the official documentation.
|
|
111
|
+
'react-hooks/todo': 'off',
|
|
112
|
+
|
|
113
|
+
// Validates against syntax that React Compiler does not support.
|
|
114
|
+
// https://react.dev/reference/eslint-plugin-react-hooks/lints/unsupported-syntax
|
|
115
|
+
'react-hooks/unsupported-syntax': 'error',
|
|
116
|
+
|
|
117
|
+
// Validates that the useMemo hook is used with a return value.
|
|
118
|
+
// https://react.dev/reference/eslint-plugin-react-hooks/lints/use-memo
|
|
119
|
+
'react-hooks/use-memo': 'error',
|
|
120
|
+
|
|
121
|
+
// Validates that useMemos always return a value and that the result of the useMemo is used
|
|
122
|
+
// by the component/hook. See [`useMemo()` docs](https://react.dev/reference/react/useMemo)
|
|
123
|
+
// for more information..
|
|
124
|
+
// Missing URL in the official documentation.
|
|
125
|
+
'react-hooks/void-use-memo': 'off',
|
|
126
|
+
},
|
|
127
|
+
}];
|
|
128
|
+
|
|
129
|
+
export default config;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defaultImportExtensionsRuleGranularOption as diergov,
|
|
3
|
+
defaultImportNoExtraneousDependenciesDevDependencies as dinedddv,
|
|
4
|
+
} from 'eslint-config-vylda-vanilla';
|
|
5
|
+
|
|
6
|
+
export const defaultImportExtensions = ['.js', '.jsx', '.mjs'];
|
|
7
|
+
export const defaultImportExtensionsRuleGranularOption = {
|
|
8
|
+
...diergov,
|
|
9
|
+
jsx: 'never',
|
|
10
|
+
};
|
|
11
|
+
export const defaultImportNoExtraneousDependenciesDevDependencies = dinedddv;
|
|
12
|
+
export const defaultImportResolverNodeExtensions = ['.js', '.jsx', '.json', '.mjs'];
|
package/rules/index.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
customs, errors, es6, getImportConfig, node, plus, strict, stylistic, variables,
|
|
3
|
+
} from 'eslint-config-vylda-vanilla';
|
|
4
|
+
import a11y from './a11y.mjs';
|
|
5
|
+
import bestPractices from './best-practices.mjs';
|
|
6
|
+
import hooks from './hooks.mjs';
|
|
7
|
+
import perfectionist from './perfectionist.mjs';
|
|
8
|
+
import react from './react.mjs';
|
|
9
|
+
import refresh from './refresh.mjs';
|
|
10
|
+
import reactStylistic from './stylistic.mjs';
|
|
11
|
+
|
|
12
|
+
const imports = getImportConfig();
|
|
13
|
+
|
|
14
|
+
const defaults = [
|
|
15
|
+
...imports,
|
|
16
|
+
...es6,
|
|
17
|
+
...strict,
|
|
18
|
+
...stylistic,
|
|
19
|
+
...bestPractices,
|
|
20
|
+
...errors,
|
|
21
|
+
...node,
|
|
22
|
+
...variables,
|
|
23
|
+
...customs,
|
|
24
|
+
...perfectionist,
|
|
25
|
+
...plus,
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
export {
|
|
29
|
+
a11y,
|
|
30
|
+
hooks,
|
|
31
|
+
perfectionist,
|
|
32
|
+
react,
|
|
33
|
+
reactStylistic,
|
|
34
|
+
refresh,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default defaults;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { perfectionist } from 'eslint-config-vylda-vanilla';
|
|
2
|
+
|
|
3
|
+
// off due there is problem with better @stylistic/jsx-sort-props rule
|
|
4
|
+
const updatePerfectionistSortJsxPropsRule = (rules) => {
|
|
5
|
+
const sortJsxPropsRule = rules['perfectionist/sort-jsx-props'];
|
|
6
|
+
|
|
7
|
+
if (!sortJsxPropsRule) {
|
|
8
|
+
return rules;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
...rules,
|
|
13
|
+
'perfectionist/sort-jsx-props': 'off',
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const updateConfig = (configs) => configs.map((config) => {
|
|
18
|
+
if (!('rules' in config)) {
|
|
19
|
+
return config;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const updatedSJPRules = updatePerfectionistSortJsxPropsRule(config.rules);
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
...config,
|
|
26
|
+
name: `vanilla-react/perfectionist extends ${config.name || 'old config'}`,
|
|
27
|
+
rules: updatedSJPRules,
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const config = updateConfig(perfectionist);
|
|
32
|
+
|
|
33
|
+
export default config;
|