@innovixx/eslint-config 3.0.13 → 4.0.0-alpha.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 +370 -20
- package/config/configs/base/index.mjs +40 -40
- package/config/configs/base/rules/best-practices.mjs +331 -333
- package/config/configs/base/rules/errors.mjs +115 -115
- package/config/configs/base/rules/es6.mjs +176 -176
- package/config/configs/base/rules/imports.mjs +238 -238
- package/config/configs/base/rules/variables.mjs +31 -31
- package/config/configs/jest/index.mjs +19 -19
- package/config/configs/jest/rules/jest-dom.mjs +8 -8
- package/config/configs/jest/rules/jest.mjs +33 -33
- package/config/configs/react/index.mjs +31 -42
- package/config/configs/react/rules/custom-rules.mjs +332 -0
- package/config/configs/react/rules/react-a11y.mjs +227 -227
- package/config/configs/react/rules/react-hooks.mjs +6 -6
- package/config/configs/react/rules/react.mjs +49 -452
- package/config/configs/typescript/index.mjs +24 -24
- package/config/configs/typescript/rules/all.mjs +14 -14
- package/config/configs/typescript/settings/typescript.mjs +8 -11
- package/config/deepMerge.mjs +47 -47
- package/config/index.mjs +117 -117
- package/demo/components/ComponentTest/index.tsx +1 -1
- package/demo/components/ComponentTestWithProps/index.tsx +2 -2
- package/package.json +19 -20
- package/tsconfig.json +1 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/** @type {import ('eslint').Linter.Config} */
|
|
2
2
|
|
|
3
3
|
const jestDomRules = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
rules: {
|
|
5
|
+
'jest-dom/prefer-checked': 'error',
|
|
6
|
+
'jest-dom/prefer-enabled-disabled': 'error',
|
|
7
|
+
'jest-dom/prefer-focus': 'error',
|
|
8
|
+
'jest-dom/prefer-required': 'error',
|
|
9
|
+
'jest-dom/prefer-to-have-attribute': 'error',
|
|
10
|
+
},
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export default jestDomRules;
|
|
13
|
+
export default jestDomRules;
|
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
/** @type {import ('eslint').Linter.Config} */
|
|
2
2
|
|
|
3
3
|
const jestRules = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
4
|
+
rules: {
|
|
5
|
+
'jest/consistent-test-it': ['error', { fn: 'it' }],
|
|
6
|
+
'jest/expect-expect': 'error',
|
|
7
|
+
'jest/no-alias-methods': 'error',
|
|
8
|
+
'jest/no-commented-out-tests': 'off',
|
|
9
|
+
'jest/no-disabled-tests': 'off',
|
|
10
|
+
'jest/no-duplicate-hooks': 'error',
|
|
11
|
+
'jest/no-export': 'error',
|
|
12
|
+
'jest/no-focused-tests': 'error',
|
|
13
|
+
'jest/no-hooks': 'off',
|
|
14
|
+
'jest/no-identical-title': 'error',
|
|
15
|
+
'jest/no-jasmine-globals': 'error',
|
|
16
|
+
'jest/no-large-snapshots': 'error',
|
|
17
|
+
'jest/no-mocks-import': 'error',
|
|
18
|
+
'jest/no-standalone-expect': 'error',
|
|
19
|
+
'jest/no-done-callback': 'error',
|
|
20
|
+
'jest/no-test-prefixes': 'error',
|
|
21
|
+
'jest/no-test-return-statement': 'error',
|
|
22
|
+
'jest/prefer-called-with': 'error',
|
|
23
|
+
'jest/prefer-expect-assertions': 'off',
|
|
24
|
+
'jest/prefer-hooks-on-top': 'error',
|
|
25
|
+
'jest/prefer-spy-on': 'error',
|
|
26
|
+
'jest/prefer-strict-equal': 'error',
|
|
27
|
+
'jest/prefer-to-contain': 'error',
|
|
28
|
+
'jest/prefer-to-have-length': 'error',
|
|
29
|
+
'jest/prefer-todo': 'error',
|
|
30
|
+
'jest/require-top-level-describe': 'error',
|
|
31
|
+
'jest/require-to-throw-message': 'error',
|
|
32
|
+
'jest/valid-expect-in-promise': 'error',
|
|
33
|
+
'jest/valid-expect': 'error',
|
|
34
|
+
'jest/valid-title': 'error',
|
|
35
|
+
},
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
export default jestRules;
|
|
38
|
+
export default jestRules;
|
|
@@ -1,52 +1,41 @@
|
|
|
1
|
-
import
|
|
1
|
+
import eslintReact from '@eslint-react/eslint-plugin';
|
|
2
|
+
import stylistic from '@stylistic/eslint-plugin';
|
|
2
3
|
import jsxA11y from 'eslint-plugin-jsx-a11y';
|
|
3
4
|
import reactHooks from 'eslint-plugin-react-hooks';
|
|
4
5
|
import globals from 'globals';
|
|
5
6
|
import reactRules from './rules/react.mjs';
|
|
6
7
|
import reactA11yRules from './rules/react-a11y.mjs';
|
|
7
|
-
import { deepMerge } from '../../deepMerge.mjs';
|
|
8
8
|
import reactHooksRules from './rules/react-hooks.mjs';
|
|
9
|
+
import { customReactConfig } from './rules/custom-rules.mjs';
|
|
9
10
|
|
|
10
|
-
/** @type {import
|
|
11
|
+
/** @type {import('eslint').Linter.Config} */
|
|
12
|
+
export const index = {
|
|
13
|
+
languageOptions: {
|
|
14
|
+
globals: {
|
|
15
|
+
...globals.browser,
|
|
16
|
+
},
|
|
17
|
+
parserOptions: {
|
|
18
|
+
ecmaFeatures: {
|
|
19
|
+
jsx: true,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
11
23
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
{
|
|
29
|
-
languageOptions: {
|
|
30
|
-
globals: {
|
|
31
|
-
...globals.browser,
|
|
32
|
-
},
|
|
33
|
-
parserOptions: {
|
|
34
|
-
ecmaFeatures: {
|
|
35
|
-
jsx: true,
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
plugins: {
|
|
40
|
-
react,
|
|
41
|
-
'jsx-a11y': jsxA11y,
|
|
42
|
-
'react-hooks': reactHooks,
|
|
43
|
-
},
|
|
44
|
-
settings: {
|
|
45
|
-
react: {
|
|
46
|
-
version: 'detect',
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
);
|
|
24
|
+
plugins: {
|
|
25
|
+
'@eslint-react': eslintReact,
|
|
26
|
+
'@stylistic': stylistic,
|
|
27
|
+
'jsx-a11y': jsxA11y,
|
|
28
|
+
'react-hooks': reactHooks,
|
|
29
|
+
...customReactConfig.plugins,
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
rules: {
|
|
33
|
+
...reactRules.rules,
|
|
34
|
+
...reactA11yRules.rules,
|
|
35
|
+
...reactHooks.configs.recommended.rules,
|
|
36
|
+
...reactHooksRules,
|
|
37
|
+
...customReactConfig.rules,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
51
40
|
|
|
52
41
|
export default index;
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
/* eslint-disable no-continue */
|
|
2
|
+
/* eslint-disable no-restricted-syntax */
|
|
3
|
+
import { extname } from 'node:path';
|
|
4
|
+
import eslintReactKit, { merge } from '@eslint-react/kit';
|
|
5
|
+
|
|
6
|
+
/** @returns {import('@eslint-react/kit').RuleFunction} */
|
|
7
|
+
function jsxBooleanValue() {
|
|
8
|
+
return (context, { ast }) => ({
|
|
9
|
+
JSXAttribute(node) {
|
|
10
|
+
if (node.value?.type !== 'JSXExpressionContainer') {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const expression = ast.unwrap(node.value.expression);
|
|
15
|
+
|
|
16
|
+
if (expression.type !== 'Literal' || expression.value !== true) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
context.report({
|
|
21
|
+
node,
|
|
22
|
+
message: 'Use shorthand for boolean attributes.',
|
|
23
|
+
fix(fixer) {
|
|
24
|
+
return fixer.removeRange([
|
|
25
|
+
node.name.range[1],
|
|
26
|
+
node.value.range[1],
|
|
27
|
+
]);
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** @returns {import('@eslint-react/kit').RuleFunction} */
|
|
35
|
+
function jsxNoBind() {
|
|
36
|
+
return (context, { ast }) => ({
|
|
37
|
+
JSXAttribute(node) {
|
|
38
|
+
if (
|
|
39
|
+
node.name.type === 'JSXIdentifier'
|
|
40
|
+
&& node.name.name === 'ref'
|
|
41
|
+
) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const elementName = node.parent.name;
|
|
46
|
+
|
|
47
|
+
if (
|
|
48
|
+
elementName.type === 'JSXIdentifier'
|
|
49
|
+
&& /^[a-z]/u.test(elementName.name)
|
|
50
|
+
) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (node.value?.type !== 'JSXExpressionContainer') {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const expression = ast.unwrap(node.value.expression);
|
|
59
|
+
|
|
60
|
+
if (expression.type === 'FunctionExpression') {
|
|
61
|
+
context.report({
|
|
62
|
+
node: expression,
|
|
63
|
+
message: 'Do not pass inline function expressions as props.',
|
|
64
|
+
});
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (expression.type !== 'CallExpression') {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const callee = ast.unwrap(expression.callee);
|
|
73
|
+
|
|
74
|
+
if (callee.type !== 'MemberExpression') {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const isBind = callee.computed
|
|
79
|
+
? callee.property.type === 'Literal'
|
|
80
|
+
&& callee.property.value === 'bind'
|
|
81
|
+
: callee.property.type === 'Identifier'
|
|
82
|
+
&& callee.property.name === 'bind';
|
|
83
|
+
|
|
84
|
+
if (!isBind) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
context.report({
|
|
89
|
+
node: expression,
|
|
90
|
+
message: 'Do not call .bind() directly in JSX props.',
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** @returns {import('@eslint-react/kit').RuleFunction} */
|
|
97
|
+
function jsxNoDuplicateProps() {
|
|
98
|
+
return (context) => ({
|
|
99
|
+
JSXOpeningElement(node) {
|
|
100
|
+
const seen = new Set();
|
|
101
|
+
|
|
102
|
+
for (const attribute of node.attributes) {
|
|
103
|
+
if (attribute.type !== 'JSXAttribute') {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const name = attribute.name.type === 'JSXIdentifier'
|
|
108
|
+
? attribute.name.name
|
|
109
|
+
: `${attribute.name.namespace.name}:${attribute.name.name.name}`;
|
|
110
|
+
|
|
111
|
+
const normalizedName = name.toLowerCase();
|
|
112
|
+
|
|
113
|
+
if (seen.has(normalizedName)) {
|
|
114
|
+
context.report({
|
|
115
|
+
node: attribute,
|
|
116
|
+
message: `Duplicate JSX prop "${name}".`,
|
|
117
|
+
});
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
seen.add(normalizedName);
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** @returns {import('@eslint-react/kit').RuleFunction} */
|
|
128
|
+
function jsxFilenameExtension() {
|
|
129
|
+
return (context) => {
|
|
130
|
+
const allowedExtensions = new Set(['.js', '.jsx', '.ts', '.tsx']);
|
|
131
|
+
const filename = context.physicalFilename;
|
|
132
|
+
let reported = false;
|
|
133
|
+
|
|
134
|
+
if (allowedExtensions.has(extname(filename))) {
|
|
135
|
+
return {};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function checkFilename(node) {
|
|
139
|
+
if (reported) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
reported = true;
|
|
144
|
+
|
|
145
|
+
context.report({
|
|
146
|
+
node,
|
|
147
|
+
message: 'JSX is only allowed in .js, .jsx, .ts, or .tsx files.',
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
JSXElement: checkFilename,
|
|
153
|
+
JSXFragment: checkFilename,
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** @returns {import('@eslint-react/kit').RuleFunction} */
|
|
159
|
+
function noUnescapedEntities() {
|
|
160
|
+
return (context) => ({
|
|
161
|
+
JSXText(node) {
|
|
162
|
+
const rawText = context.sourceCode.getText(node);
|
|
163
|
+
|
|
164
|
+
for (const match of rawText.matchAll(/[>"'}]/gu)) {
|
|
165
|
+
const start = node.range[0] + match.index;
|
|
166
|
+
|
|
167
|
+
context.report({
|
|
168
|
+
node,
|
|
169
|
+
loc: {
|
|
170
|
+
start: context.sourceCode.getLocFromIndex(start),
|
|
171
|
+
end: context.sourceCode.getLocFromIndex(start + 1),
|
|
172
|
+
},
|
|
173
|
+
message: `Escape "${match[0]}" with an HTML entity or a JSX expression.`,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** @returns {import('@eslint-react/kit').RuleFunction} */
|
|
181
|
+
function jsxFragments() {
|
|
182
|
+
return (context) => ({
|
|
183
|
+
JSXFragment(node) {
|
|
184
|
+
context.report({
|
|
185
|
+
node,
|
|
186
|
+
message: 'Use an explicit Fragment element instead of <>...</>.',
|
|
187
|
+
fix(fixer) {
|
|
188
|
+
return [
|
|
189
|
+
fixer.replaceText(node.openingFragment, '<React.Fragment>'),
|
|
190
|
+
fixer.replaceText(node.closingFragment, '</React.Fragment>'),
|
|
191
|
+
];
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** @returns {import('@eslint-react/kit').RuleFunction} */
|
|
199
|
+
function noStringRefs() {
|
|
200
|
+
return (context, { ast }) => ({
|
|
201
|
+
JSXAttribute(node) {
|
|
202
|
+
if (
|
|
203
|
+
node.name.type !== 'JSXIdentifier'
|
|
204
|
+
|| node.name.name !== 'ref'
|
|
205
|
+
|| node.value == null
|
|
206
|
+
) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const value = node.value.type === 'JSXExpressionContainer'
|
|
211
|
+
? ast.unwrap(node.value.expression)
|
|
212
|
+
: node.value;
|
|
213
|
+
|
|
214
|
+
const isStringLiteral = value.type === 'Literal'
|
|
215
|
+
&& typeof value.value === 'string';
|
|
216
|
+
|
|
217
|
+
const isStaticTemplate = value.type === 'TemplateLiteral'
|
|
218
|
+
&& value.expressions.length === 0;
|
|
219
|
+
|
|
220
|
+
if (!isStringLiteral && !isStaticTemplate) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
context.report({
|
|
225
|
+
node,
|
|
226
|
+
message: 'String refs are not supported. Use an object or callback ref.',
|
|
227
|
+
});
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** @returns {import('@eslint-react/kit').RuleFunction} */
|
|
233
|
+
function destructuringAssignment() {
|
|
234
|
+
return (context, { collect }) => {
|
|
235
|
+
const { query, visitor } = collect.components(context);
|
|
236
|
+
|
|
237
|
+
return merge(visitor, {
|
|
238
|
+
'Program:exit': function (program) {
|
|
239
|
+
for (const component of query.all(program)) {
|
|
240
|
+
const parameter = component.node.params[0];
|
|
241
|
+
|
|
242
|
+
if (parameter?.type !== 'Identifier') {
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const scope = context.sourceCode.getScope(component.node);
|
|
247
|
+
const variable = scope.variables.find(
|
|
248
|
+
(candidate) => candidate.name === parameter.name,
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
if (variable == null) {
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
for (const reference of variable.references) {
|
|
256
|
+
const { identifier } = reference;
|
|
257
|
+
const { parent } = identifier;
|
|
258
|
+
|
|
259
|
+
if (
|
|
260
|
+
parent.type !== 'MemberExpression'
|
|
261
|
+
|| parent.object !== identifier
|
|
262
|
+
) {
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
context.report({
|
|
267
|
+
node: parent,
|
|
268
|
+
message: 'Destructure component props instead of accessing props members.',
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
});
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** @returns {import('@eslint-react/kit').RuleFunction} */
|
|
278
|
+
function noThisInSfc() {
|
|
279
|
+
return (context, { collect }) => {
|
|
280
|
+
const { query, visitor } = collect.components(context);
|
|
281
|
+
const thisExpressions = [];
|
|
282
|
+
|
|
283
|
+
return merge(visitor, {
|
|
284
|
+
ThisExpression(node) {
|
|
285
|
+
thisExpressions.push(node);
|
|
286
|
+
},
|
|
287
|
+
|
|
288
|
+
'Program:exit': function (program) {
|
|
289
|
+
const components = new Set(
|
|
290
|
+
query.all(program).map((component) => component.node),
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
for (const expression of thisExpressions) {
|
|
294
|
+
const ancestors = context.sourceCode.getAncestors(expression);
|
|
295
|
+
|
|
296
|
+
for (let index = ancestors.length - 1; index >= 0; index -= 1) {
|
|
297
|
+
const ancestor = ancestors[index];
|
|
298
|
+
|
|
299
|
+
if (components.has(ancestor)) {
|
|
300
|
+
context.report({
|
|
301
|
+
node: expression,
|
|
302
|
+
message: 'Do not use this inside a function component.',
|
|
303
|
+
});
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// Ordinary functions and classes introduce a different this context.
|
|
308
|
+
if (
|
|
309
|
+
ancestor.type === 'FunctionDeclaration'
|
|
310
|
+
|| ancestor.type === 'FunctionExpression'
|
|
311
|
+
|| ancestor.type === 'ClassBody'
|
|
312
|
+
) {
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
});
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export const customReactConfig = eslintReactKit()
|
|
323
|
+
.use(jsxBooleanValue)
|
|
324
|
+
.use(jsxNoBind)
|
|
325
|
+
.use(jsxNoDuplicateProps)
|
|
326
|
+
.use(jsxFilenameExtension)
|
|
327
|
+
.use(noUnescapedEntities)
|
|
328
|
+
.use(jsxFragments)
|
|
329
|
+
.use(noStringRefs)
|
|
330
|
+
.use(destructuringAssignment)
|
|
331
|
+
.use(noThisInSfc)
|
|
332
|
+
.getConfig();
|