eslint-plugin-th-rules 1.19.0 → 1.19.2
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/CHANGELOG.md +14 -0
- package/package.json +1 -1
- package/src/index.js +1 -8
- package/src/rules/no-destructuring.js +80 -58
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [1.19.2](https://github.com/tomerh2001/eslint-plugin-th-rules/compare/v1.19.1...v1.19.2) (2026-01-05)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* clean up JSDoc comments and improve code readability in no-destructuring rule ([f7c2547](https://github.com/tomerh2001/eslint-plugin-th-rules/commit/f7c2547e71d41d19c874b1713c62bed25018803c))
|
|
7
|
+
|
|
8
|
+
## [1.19.1](https://github.com/tomerh2001/eslint-plugin-th-rules/compare/v1.19.0...v1.19.1) (2026-01-05)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* remove jsdoc plugin from recommended configs and clean up extends ([de220ac](https://github.com/tomerh2001/eslint-plugin-th-rules/commit/de220acd3d0c80340c7ee9b5bc2bfe2967c1c4c5))
|
|
14
|
+
|
|
1
15
|
# [1.19.0](https://github.com/tomerh2001/eslint-plugin-th-rules/compare/v1.18.0...v1.19.0) (2026-01-05)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -9,12 +9,10 @@ const configs = {
|
|
|
9
9
|
plugins: [
|
|
10
10
|
'th-rules',
|
|
11
11
|
'sonarjs',
|
|
12
|
-
'jsdoc',
|
|
13
12
|
],
|
|
14
13
|
extends: [
|
|
15
14
|
'plugin:sonarjs/recommended-legacy',
|
|
16
15
|
'plugin:security/recommended-legacy',
|
|
17
|
-
'plugin:jsdoc/recommended',
|
|
18
16
|
],
|
|
19
17
|
rules: {
|
|
20
18
|
'th-rules/no-destructuring': 'error',
|
|
@@ -24,7 +22,6 @@ const configs = {
|
|
|
24
22
|
'th-rules/styles-in-styles-file': 'error',
|
|
25
23
|
'th-rules/schemas-in-schemas-file': 'error',
|
|
26
24
|
'th-rules/types-in-dts': 'error',
|
|
27
|
-
|
|
28
25
|
'unicorn/prefer-module': 'warn',
|
|
29
26
|
'unicorn/filename-case': 'off',
|
|
30
27
|
'unicorn/no-array-callback-reference': 'off',
|
|
@@ -56,10 +53,7 @@ for (const configName of Object.keys(configs)) {
|
|
|
56
53
|
extends: [
|
|
57
54
|
'plugin:@typescript-eslint/strict-type-checked',
|
|
58
55
|
'plugin:@typescript-eslint/stylistic-type-checked',
|
|
59
|
-
|
|
60
|
-
...configs[configName].extends
|
|
61
|
-
.filter(x => x !== 'plugin:jsdoc/recommended'),
|
|
62
|
-
'plugin:jsdoc/recommended-typescript',
|
|
56
|
+
...configs[configName].extends,
|
|
63
57
|
],
|
|
64
58
|
rules: {
|
|
65
59
|
...configs[configName].rules,
|
|
@@ -75,7 +69,6 @@ for (const configName of Object.keys(configs)) {
|
|
|
75
69
|
'@typescript-eslint/no-unsafe-argument': 'off',
|
|
76
70
|
},
|
|
77
71
|
};
|
|
78
|
-
|
|
79
72
|
configs[`${configName}-react`] = {
|
|
80
73
|
...configs[configName],
|
|
81
74
|
extends: [
|
|
@@ -1,19 +1,5 @@
|
|
|
1
1
|
const MAX_TAB_COUNT = 3;
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Represents the metadata for the "no-destructuring" ESLint rule.
|
|
5
|
-
*
|
|
6
|
-
* @type {Object}
|
|
7
|
-
* @property {string} type - The type of the rule.
|
|
8
|
-
* @property {Object} docs - The documentation for the rule.
|
|
9
|
-
* @property {string} docs.description - The description of the rule.
|
|
10
|
-
* @property {string} docs.category - The category of the rule.
|
|
11
|
-
* @property {boolean} docs.recommended - Indicates if the rule is recommended.
|
|
12
|
-
* @property {Object[]} schema - The schema for the rule options.
|
|
13
|
-
* @property {Object} schema[].properties - The properties of the rule options.
|
|
14
|
-
* @property {number} schema[].properties.maximumDestructuredVariables - The maximum number of destructured variables allowed.
|
|
15
|
-
* @property {number} schema[].properties.maximumLineLength - The maximum line length allowed.
|
|
16
|
-
*/
|
|
17
3
|
const meta = {
|
|
18
4
|
type: 'problem',
|
|
19
5
|
docs: {
|
|
@@ -26,67 +12,103 @@ const meta = {
|
|
|
26
12
|
{
|
|
27
13
|
type: 'object',
|
|
28
14
|
properties: {
|
|
29
|
-
maximumDestructuredVariables: {
|
|
30
|
-
|
|
31
|
-
minimum: 0,
|
|
32
|
-
},
|
|
33
|
-
maximumLineLength: {
|
|
34
|
-
type: 'integer',
|
|
35
|
-
minimum: 0,
|
|
36
|
-
},
|
|
15
|
+
maximumDestructuredVariables: {type: 'integer', minimum: 0},
|
|
16
|
+
maximumLineLength: {type: 'integer', minimum: 0},
|
|
37
17
|
},
|
|
38
18
|
additionalProperties: false,
|
|
39
19
|
},
|
|
40
20
|
],
|
|
41
21
|
};
|
|
42
22
|
|
|
43
|
-
/**
|
|
44
|
-
* Creates an ESLint rule that checks for excessive destructuring in variable declarations.
|
|
45
|
-
* @param {Object} context - The ESLint rule context.
|
|
46
|
-
* @returns {Object} - The ESLint rule object.
|
|
47
|
-
*/
|
|
48
23
|
function create(context) {
|
|
49
|
-
const MAX_VARIABLES = context?.options[0]?.maximumDestructuredVariables
|
|
50
|
-
const MAX_LINE_LENGTH = context?.options[0]?.maximumLineLength
|
|
24
|
+
const MAX_VARIABLES = context?.options?.[0]?.maximumDestructuredVariables ?? 2;
|
|
25
|
+
const MAX_LINE_LENGTH = context?.options?.[0]?.maximumLineLength ?? 100;
|
|
51
26
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
27
|
+
const sourceCode = context.getSourceCode();
|
|
28
|
+
|
|
29
|
+
function reportIfNeeded(patternNode, reportNode = patternNode) {
|
|
30
|
+
if (!patternNode || patternNode.type !== 'ObjectPattern' || !patternNode.loc) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
58
33
|
|
|
59
|
-
|
|
60
|
-
|
|
34
|
+
const lineText = sourceCode.lines[patternNode.loc.start.line - 1] ?? '';
|
|
35
|
+
const indentCount = lineText.search(/\S|$/);
|
|
36
|
+
|
|
37
|
+
const propertyCount = patternNode.properties?.length ?? 0;
|
|
38
|
+
|
|
39
|
+
const startLine = patternNode.loc.start.line;
|
|
40
|
+
const endLine = patternNode.loc.end.line;
|
|
41
|
+
let maxSpannedLineLength = 0;
|
|
42
|
+
for (let i = startLine; i <= endLine; i++) {
|
|
43
|
+
const t = sourceCode.lines[i - 1] ?? '';
|
|
44
|
+
if (t.length > maxSpannedLineLength) {
|
|
45
|
+
maxSpannedLineLength = t.length;
|
|
61
46
|
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (indentCount > MAX_TAB_COUNT) {
|
|
50
|
+
context.report({
|
|
51
|
+
node: reportNode,
|
|
52
|
+
message: `destructuring at a nesting level above ${MAX_TAB_COUNT} is not allowed, instead saw ${indentCount} levels of nesting`,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
62
55
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
56
|
+
if (propertyCount > MAX_VARIABLES) {
|
|
57
|
+
context.report({
|
|
58
|
+
node: reportNode,
|
|
59
|
+
message: `destructuring of more than ${MAX_VARIABLES} variables is not allowed`,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (maxSpannedLineLength > MAX_LINE_LENGTH) {
|
|
64
|
+
context.report({
|
|
65
|
+
node: reportNode,
|
|
66
|
+
message: `destructuring on a line exceeding ${MAX_LINE_LENGTH} characters is not allowed`,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function checkParameters(parameters) {
|
|
72
|
+
for (const p of parameters || []) {
|
|
73
|
+
if (!p) {
|
|
74
|
+
continue;
|
|
68
75
|
}
|
|
69
76
|
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
message: `destructuring of more than ${MAX_VARIABLES} variables is not allowed`,
|
|
74
|
-
});
|
|
77
|
+
if (p.type === 'AssignmentPattern') {
|
|
78
|
+
reportIfNeeded(p.left, p);
|
|
79
|
+
continue;
|
|
75
80
|
}
|
|
76
81
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
reportIfNeeded(p, p);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
|
|
88
|
+
VariableDeclarator(node) {
|
|
89
|
+
reportIfNeeded(node?.id, node);
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
FunctionDeclaration(node) {
|
|
93
|
+
checkParameters(node.params);
|
|
94
|
+
},
|
|
95
|
+
FunctionExpression(node) {
|
|
96
|
+
checkParameters(node.params);
|
|
97
|
+
},
|
|
98
|
+
ArrowFunctionExpression(node) {
|
|
99
|
+
checkParameters(node.params);
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
MethodDefinition(node) {
|
|
103
|
+
if (node?.value?.params) {
|
|
104
|
+
checkParameters(node.value.params);
|
|
82
105
|
}
|
|
83
106
|
},
|
|
107
|
+
|
|
108
|
+
TSDeclareFunction(node) {
|
|
109
|
+
checkParameters(node.params);
|
|
110
|
+
},
|
|
84
111
|
};
|
|
85
112
|
}
|
|
86
113
|
|
|
87
|
-
|
|
88
|
-
meta,
|
|
89
|
-
create,
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
module.exports = rule;
|
|
114
|
+
module.exports = {meta, create};
|