eslint-plugin-etc-misc 1.1.6 → 1.1.8
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 +135 -135
- package/dist/_internal/casing.js +2 -2
- package/dist/_internal/casing.js.map +1 -1
- package/dist/_internal/get-core-rule.d.ts.map +1 -1
- package/dist/_internal/get-core-rule.js +1 -2
- package/dist/_internal/get-core-rule.js.map +1 -1
- package/dist/_internal/import-patterns.js +3 -3
- package/dist/_internal/import-patterns.js.map +1 -1
- package/dist/_internal/rule-catalog.js +4 -4
- package/dist/_internal/rule-catalog.js.map +1 -1
- package/dist/_internal/rule-deprecation.d.ts +2 -2
- package/dist/_internal/rule-deprecation.d.ts.map +1 -1
- package/dist/_internal/rule-deprecation.js +10 -12
- package/dist/_internal/rule-deprecation.js.map +1 -1
- package/dist/_internal/symbol-usage.d.ts +1 -1
- package/dist/_internal/symbol-usage.d.ts.map +1 -1
- package/dist/_internal/symbol-usage.js +1 -1
- package/dist/_internal/symbol-usage.js.map +1 -1
- package/dist/plugin.cjs +78 -101
- package/dist/plugin.cjs.map +3 -3
- package/dist/rules/match-filename.js +2 -2
- package/dist/rules/match-filename.js.map +1 -1
- package/dist/rules/no-assign-mutated-array.js +3 -3
- package/dist/rules/no-assign-mutated-array.js.map +1 -1
- package/dist/rules/no-const-enum.js +17 -17
- package/dist/rules/no-const-enum.js.map +1 -1
- package/dist/rules/no-deprecated.js +3 -3
- package/dist/rules/no-deprecated.js.map +1 -1
- package/dist/rules/no-foreach.js +2 -2
- package/dist/rules/no-foreach.js.map +1 -1
- package/dist/rules/no-implicit-any-catch.d.ts.map +1 -1
- package/dist/rules/no-implicit-any-catch.js.map +1 -1
- package/dist/rules/no-internal.js +3 -3
- package/dist/rules/no-internal.js.map +1 -1
- package/dist/rules/no-misused-generics.d.ts.map +1 -1
- package/dist/rules/no-misused-generics.js +11 -11
- package/dist/rules/no-misused-generics.js.map +1 -1
- package/dist/rules/no-single-line-comment.d.ts.map +1 -1
- package/dist/rules/no-single-line-comment.js +11 -15
- package/dist/rules/no-single-line-comment.js.map +1 -1
- package/dist/rules/no-use-extend-native.d.ts.map +1 -1
- package/dist/rules/no-use-extend-native.js +4 -3
- package/dist/rules/no-use-extend-native.js.map +1 -1
- package/dist/rules/object-format.js +2 -2
- package/dist/rules/object-format.js.map +1 -1
- package/dist/rules/sort-array.js +2 -2
- package/dist/rules/sort-array.js.map +1 -1
- package/dist/rules/sort-class-members.d.ts.map +1 -1
- package/dist/rules/sort-class-members.js.map +1 -1
- package/dist/rules/sort-export-specifiers.js +2 -2
- package/dist/rules/sort-export-specifiers.js.map +1 -1
- package/dist/rules/switch-case-spacing.d.ts.map +1 -1
- package/dist/rules/switch-case-spacing.js +5 -4
- package/dist/rules/switch-case-spacing.js.map +1 -1
- package/dist/rules/throw-error.d.ts.map +1 -1
- package/dist/rules/throw-error.js +12 -14
- package/dist/rules/throw-error.js.map +1 -1
- package/dist/rules/typescript-array-callback-return-type.d.ts.map +1 -1
- package/dist/rules/typescript-array-callback-return-type.js.map +1 -1
- package/dist/rules/typescript-class-methods-use-this.d.ts.map +1 -1
- package/dist/rules/typescript-class-methods-use-this.js +3 -3
- package/dist/rules/typescript-class-methods-use-this.js.map +1 -1
- package/dist/rules/typescript-no-redundant-undefined-const.d.ts.map +1 -1
- package/dist/rules/typescript-no-redundant-undefined-const.js +1 -4
- package/dist/rules/typescript-no-redundant-undefined-const.js.map +1 -1
- package/dist/rules/typescript-no-redundant-undefined-default-parameter.d.ts.map +1 -1
- package/dist/rules/typescript-no-redundant-undefined-default-parameter.js +1 -4
- package/dist/rules/typescript-no-redundant-undefined-default-parameter.js.map +1 -1
- package/dist/rules/typescript-no-redundant-undefined-let.d.ts.map +1 -1
- package/dist/rules/typescript-no-redundant-undefined-let.js +2 -5
- package/dist/rules/typescript-no-redundant-undefined-let.js.map +1 -1
- package/dist/rules/typescript-no-redundant-undefined-promise-return-type.d.ts.map +1 -1
- package/dist/rules/typescript-no-redundant-undefined-promise-return-type.js +1 -4
- package/dist/rules/typescript-no-redundant-undefined-promise-return-type.js.map +1 -1
- package/dist/rules/typescript-no-redundant-undefined-readonly-property.d.ts.map +1 -1
- package/dist/rules/typescript-no-redundant-undefined-readonly-property.js +1 -4
- package/dist/rules/typescript-no-redundant-undefined-readonly-property.js.map +1 -1
- package/dist/rules/typescript-no-redundant-undefined-return-type.d.ts.map +1 -1
- package/dist/rules/typescript-no-redundant-undefined-return-type.js +1 -4
- package/dist/rules/typescript-no-redundant-undefined-return-type.js.map +1 -1
- package/dist/rules/typescript-no-redundant-undefined-var.d.ts.map +1 -1
- package/dist/rules/typescript-no-redundant-undefined-var.js +2 -5
- package/dist/rules/typescript-no-redundant-undefined-var.js.map +1 -1
- package/dist/rules/typescript-prefer-enum.d.ts.map +1 -1
- package/dist/rules/typescript-prefer-enum.js.map +1 -1
- package/dist/rules/typescript-prefer-named-tuple-members.d.ts.map +1 -1
- package/dist/rules/typescript-prefer-named-tuple-members.js +2 -5
- package/dist/rules/typescript-prefer-named-tuple-members.js.map +1 -1
- package/dist/rules/typescript-prefer-readonly-property.d.ts.map +1 -1
- package/dist/rules/typescript-prefer-readonly-property.js +9 -11
- package/dist/rules/typescript-prefer-readonly-property.js.map +1 -1
- package/dist/rules/typescript-require-prop-type-annotation.d.ts.map +1 -1
- package/dist/rules/typescript-require-prop-type-annotation.js +9 -11
- package/dist/rules/typescript-require-prop-type-annotation.js.map +1 -1
- package/dist/rules/typescript-require-this-void.d.ts.map +1 -1
- package/dist/rules/typescript-require-this-void.js +9 -11
- package/dist/rules/typescript-require-this-void.js.map +1 -1
- package/docs/AGENTS.md +20 -18
- package/docs/docusaurus/blog/authors.yml +11 -11
- package/docs/docusaurus/docusaurus.config.ts +23 -25
- package/docs/docusaurus/package.json +2 -1
- package/docs/docusaurus/sidebars.rules.ts +40 -42
- package/docs/docusaurus/sidebars.ts +20 -20
- package/docs/docusaurus/src/components/GitHubStats.jsx +4 -4
- package/docs/docusaurus/src/components/GitHubStats.module.css +18 -3
- package/docs/docusaurus/src/js/modernEnhancements.ts +55 -55
- package/docs/docusaurus/src/pages/index.jsx +12 -12
- package/docs/docusaurus/typedoc-plugins/hashToBangLinksCore.d.mts +4 -2
- package/docs/docusaurus/typedoc.config.json +7 -586
- package/docs/rules/consistent-enum-members.md +3 -3
- package/docs/rules/consistent-filename.md +1 -1
- package/docs/rules/getting-started.md +19 -21
- package/docs/rules/no-assign-mutated-array.md +5 -25
- package/docs/rules/no-expression-empty-lines.md +2 -4
- package/docs/rules/no-foreach.md +1 -5
- package/docs/rules/no-function-declare-after-return.md +72 -66
- package/docs/rules/no-use-extend-native.md +29 -31
- package/docs/rules/no-vulnerable.md +32 -34
- package/docs/rules/prefer-includes.md +2 -11
- package/docs/rules/presets/all.md +1 -1
- package/docs/rules/presets/recommended.md +1 -1
- package/docs/rules/require-jsdoc.md +1 -7
- package/docs/rules/sort-array.md +2 -10
- package/docs/rules/typescript-array-callback-return-type.md +5 -17
- package/package.json +17 -9
|
@@ -9,18 +9,18 @@ This rule analyzes TypeScript `TSEnumMember` nodes and validates naming for:
|
|
|
9
9
|
- enum member identifiers (for example `ACTIVE_USER`), and
|
|
10
10
|
- string literal member values when provided.
|
|
11
11
|
|
|
12
|
-
It enforces
|
|
12
|
+
It enforces SCREAMING_SNAKE_CASE in both places.
|
|
13
13
|
|
|
14
14
|
## What this rule reports
|
|
15
15
|
|
|
16
16
|
This rule reports enum members when **neither** of these matches
|
|
17
|
-
|
|
17
|
+
SCREAMING_SNAKE_CASE:
|
|
18
18
|
|
|
19
19
|
- the member identifier name, or
|
|
20
20
|
- the string literal initializer value.
|
|
21
21
|
|
|
22
22
|
In other words, the current implementation accepts a member if either side is
|
|
23
|
-
already
|
|
23
|
+
already SCREAMING_SNAKE_CASE.
|
|
24
24
|
|
|
25
25
|
## Why this rule exists
|
|
26
26
|
|
|
@@ -4,7 +4,7 @@ Enforce filename casing consistency.
|
|
|
4
4
|
|
|
5
5
|
## Targeted pattern scope
|
|
6
6
|
|
|
7
|
-
This rule validates the current file
|
|
7
|
+
This rule validates the current file's stem (filename without extension) against
|
|
8
8
|
one configured casing format.
|
|
9
9
|
|
|
10
10
|
## What this rule reports
|
|
@@ -16,9 +16,7 @@ Enable one preset in your Flat Config:
|
|
|
16
16
|
```ts
|
|
17
17
|
import etcMisc from "eslint-plugin-etc-misc";
|
|
18
18
|
|
|
19
|
-
export default [
|
|
20
|
-
etcMisc.configs.recommended,
|
|
21
|
-
];
|
|
19
|
+
export default [etcMisc.configs.recommended];
|
|
22
20
|
```
|
|
23
21
|
|
|
24
22
|
Use `minimal` or `recommended` first, then move through stricter presets as
|
|
@@ -33,24 +31,24 @@ import tsParser from "@typescript-eslint/parser";
|
|
|
33
31
|
import etcMisc from "eslint-plugin-etc-misc";
|
|
34
32
|
|
|
35
33
|
export default [
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
34
|
+
{
|
|
35
|
+
files: ["**/*.{ts,tsx,mts,cts}"],
|
|
36
|
+
languageOptions: {
|
|
37
|
+
parser: tsParser,
|
|
38
|
+
parserOptions: {
|
|
39
|
+
ecmaVersion: "latest",
|
|
40
|
+
// Enable only when using a type-aware preset.
|
|
41
|
+
// projectService: true,
|
|
42
|
+
sourceType: "module",
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
plugins: {
|
|
46
|
+
"etc-misc": etcMisc,
|
|
47
|
+
},
|
|
48
|
+
rules: {
|
|
49
|
+
...etcMisc.configs.recommended.rules,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
54
52
|
];
|
|
55
53
|
```
|
|
56
54
|
|
|
@@ -26,20 +26,12 @@ mutating shared state, which causes subtle bugs.
|
|
|
26
26
|
## ❌ Incorrect
|
|
27
27
|
|
|
28
28
|
```ts
|
|
29
|
-
const names = [
|
|
30
|
-
"c",
|
|
31
|
-
"a",
|
|
32
|
-
"b",
|
|
33
|
-
];
|
|
29
|
+
const names = ["c", "a", "b"];
|
|
34
30
|
const sorted = names.sort();
|
|
35
31
|
```
|
|
36
32
|
|
|
37
33
|
```ts
|
|
38
|
-
const names = [
|
|
39
|
-
"c",
|
|
40
|
-
"a",
|
|
41
|
-
"b",
|
|
42
|
-
];
|
|
34
|
+
const names = ["c", "a", "b"];
|
|
43
35
|
print(names.reverse());
|
|
44
36
|
```
|
|
45
37
|
|
|
@@ -51,29 +43,17 @@ return sorted;
|
|
|
51
43
|
## ✅ Correct
|
|
52
44
|
|
|
53
45
|
```ts
|
|
54
|
-
const names = [
|
|
55
|
-
"c",
|
|
56
|
-
"a",
|
|
57
|
-
"b",
|
|
58
|
-
];
|
|
46
|
+
const names = ["c", "a", "b"];
|
|
59
47
|
names.sort();
|
|
60
48
|
```
|
|
61
49
|
|
|
62
50
|
```ts
|
|
63
|
-
const names = [
|
|
64
|
-
"c",
|
|
65
|
-
"a",
|
|
66
|
-
"b",
|
|
67
|
-
];
|
|
51
|
+
const names = ["c", "a", "b"];
|
|
68
52
|
const sorted = names.slice().sort();
|
|
69
53
|
```
|
|
70
54
|
|
|
71
55
|
```ts
|
|
72
|
-
const names = [
|
|
73
|
-
"c",
|
|
74
|
-
"a",
|
|
75
|
-
"b",
|
|
76
|
-
];
|
|
56
|
+
const names = ["c", "a", "b"];
|
|
77
57
|
const sorted = names.map((name) => name).reverse();
|
|
78
58
|
```
|
|
79
59
|
|
|
@@ -4,7 +4,7 @@ Disallow blank lines inside expression statements.
|
|
|
4
4
|
|
|
5
5
|
## Targeted pattern scope
|
|
6
6
|
|
|
7
|
-
This rule inspects `ExpressionStatement` nodes and checks the expression
|
|
7
|
+
This rule inspects `ExpressionStatement` nodes and checks the expression's raw
|
|
8
8
|
source text for blank lines.
|
|
9
9
|
|
|
10
10
|
It only applies to expression statements and does not inspect declarations,
|
|
@@ -23,9 +23,7 @@ formatting noise.
|
|
|
23
23
|
## ❌ Incorrect
|
|
24
24
|
|
|
25
25
|
```ts
|
|
26
|
-
someCall(
|
|
27
|
-
|
|
28
|
-
1);
|
|
26
|
+
someCall(1);
|
|
29
27
|
```
|
|
30
28
|
|
|
31
29
|
## ✅ Correct
|
package/docs/rules/no-foreach.md
CHANGED
|
@@ -61,11 +61,7 @@ Use this option to control which type names are checked.
|
|
|
61
61
|
## Additional examples
|
|
62
62
|
|
|
63
63
|
```ts
|
|
64
|
-
const set = new Set([
|
|
65
|
-
1,
|
|
66
|
-
2,
|
|
67
|
-
3,
|
|
68
|
-
]);
|
|
64
|
+
const set = new Set([1, 2, 3]);
|
|
69
65
|
set.forEach((value) => console.log(value));
|
|
70
66
|
// ❌ reported with default options
|
|
71
67
|
|
|
@@ -2,30 +2,42 @@
|
|
|
2
2
|
|
|
3
3
|
Disallow function declarations that appear after a `return` statement in the same block scope.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Targeted pattern scope
|
|
6
6
|
|
|
7
|
-
This rule
|
|
7
|
+
This rule reports `FunctionDeclaration` nodes that appear after a `ReturnStatement` in the same direct statement list (`BlockStatement` or `Program`).
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
- `return` inside `switch` cases is out of scope for this rule.
|
|
10
|
+
- Function declarations nested inside later `if`/`try`/`for` blocks are not directly targeted by this rule.
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
> **Note:** This rule targets only `FunctionDeclaration` nodes. Arrow functions,
|
|
13
|
+
> function expressions, generator functions, and async function expressions
|
|
14
|
+
> assigned to variables are **not** flagged — those are expression statements and
|
|
15
|
+
> are genuinely unreachable. Use `no-unreachable` for those cases.
|
|
16
|
+
|
|
17
|
+
## What this rule reports
|
|
12
18
|
|
|
13
19
|
JavaScript hoists `function` declarations to the top of their enclosing scope,
|
|
14
20
|
which means the following code is syntactically valid and runs without errors:
|
|
15
21
|
|
|
16
22
|
```ts
|
|
17
23
|
function publicMethods(obj) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
if (obj instanceof CustomClass) {
|
|
25
|
+
return {
|
|
26
|
+
get: methodGetter(obj), // ← called before its declaration ❌
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function methodGetter(obj) {
|
|
30
|
+
// ← declared after the return
|
|
31
|
+
// …
|
|
32
|
+
}
|
|
26
33
|
}
|
|
27
34
|
```
|
|
28
35
|
|
|
36
|
+
This rule reports function declarations that rely on that hoisting by appearing
|
|
37
|
+
after an earlier `return` in the same block.
|
|
38
|
+
|
|
39
|
+
## Why this rule exists
|
|
40
|
+
|
|
29
41
|
Even though this works at runtime, it is a readability trap:
|
|
30
42
|
|
|
31
43
|
- A reader scanning the function top-to-bottom will encounter the call to
|
|
@@ -39,39 +51,29 @@ This rule enforces that every `FunctionDeclaration` is placed **before** any
|
|
|
39
51
|
`ReturnStatement` in the same block scope, making hoisting irrelevant from a
|
|
40
52
|
readability perspective.
|
|
41
53
|
|
|
42
|
-
### Scope boundaries
|
|
43
|
-
|
|
44
|
-
This rule reports only when the function declaration is a **direct sibling** of
|
|
45
|
-
the `return` statement in the same statement list (`BlockStatement` or
|
|
46
|
-
`Program`).
|
|
47
|
-
|
|
48
|
-
- `return` inside `switch` cases is out of scope for this rule.
|
|
49
|
-
- Function declarations nested inside later `if`/`try`/`for` blocks are not directly targeted by this rule.
|
|
50
|
-
|
|
51
|
-
> **Note:** This rule targets only `FunctionDeclaration` nodes. Arrow functions,
|
|
52
|
-
> function expressions, generator functions, and async function expressions
|
|
53
|
-
> assigned to variables are **not** flagged — those are expression statements and
|
|
54
|
-
> are genuinely unreachable. Use `no-unreachable` for those cases.
|
|
55
|
-
|
|
56
54
|
## ❌ Incorrect
|
|
57
55
|
|
|
58
56
|
```ts
|
|
59
57
|
function outer() {
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
return 42;
|
|
59
|
+
function helper() {} // ← 'helper' should be moved before the return
|
|
62
60
|
}
|
|
63
61
|
```
|
|
64
62
|
|
|
65
63
|
```ts
|
|
66
64
|
function publicMethods(obj) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
65
|
+
if (obj) {
|
|
66
|
+
return {
|
|
67
|
+
set: methodSetter(obj),
|
|
68
|
+
get: methodGetter(obj),
|
|
69
|
+
};
|
|
70
|
+
function methodSetter(obj) {
|
|
71
|
+
/* … */
|
|
72
|
+
} // ← should be before return
|
|
73
|
+
function methodGetter(obj) {
|
|
74
|
+
/* … */
|
|
75
|
+
} // ← should be before return
|
|
76
|
+
}
|
|
75
77
|
}
|
|
76
78
|
```
|
|
77
79
|
|
|
@@ -79,21 +81,25 @@ function publicMethods(obj) {
|
|
|
79
81
|
|
|
80
82
|
```ts
|
|
81
83
|
function outer() {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
function helper() {} // ← declared before the return
|
|
85
|
+
return helper();
|
|
84
86
|
}
|
|
85
87
|
```
|
|
86
88
|
|
|
87
89
|
```ts
|
|
88
90
|
function publicMethods(obj) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
91
|
+
function methodSetter(obj) {
|
|
92
|
+
/* … */
|
|
93
|
+
} // ← before the return
|
|
94
|
+
function methodGetter(obj) {
|
|
95
|
+
/* … */
|
|
96
|
+
} // ← before the return
|
|
97
|
+
if (obj) {
|
|
98
|
+
return {
|
|
99
|
+
set: methodSetter(obj),
|
|
100
|
+
get: methodGetter(obj),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
97
103
|
}
|
|
98
104
|
```
|
|
99
105
|
|
|
@@ -101,12 +107,12 @@ function publicMethods(obj) {
|
|
|
101
107
|
// Arrow functions and function expressions after return are NOT flagged —
|
|
102
108
|
// use no-unreachable for those.
|
|
103
109
|
function outer() {
|
|
104
|
-
|
|
105
|
-
|
|
110
|
+
return 1;
|
|
111
|
+
const arrow = () => {}; // not a FunctionDeclaration — not flagged here
|
|
106
112
|
}
|
|
107
113
|
```
|
|
108
114
|
|
|
109
|
-
##
|
|
115
|
+
## Behavior and migration notes
|
|
110
116
|
|
|
111
117
|
This rule provides an **autofix**. When triggered, it moves the offending
|
|
112
118
|
`FunctionDeclaration` to immediately before the `ReturnStatement`, preserving
|
|
@@ -115,10 +121,25 @@ the correct indentation level.
|
|
|
115
121
|
When a function declaration has leading comments (including JSDoc), the fixer
|
|
116
122
|
moves those comments together with the declaration.
|
|
117
123
|
|
|
118
|
-
## Options
|
|
119
|
-
|
|
120
124
|
This rule has no options.
|
|
121
125
|
|
|
126
|
+
Original plugin source: [`eslint-plugin-no-function-declare-after-return`](https://github.com/bhumijgupta/eslint-plugin-no-function-declare-after-return).
|
|
127
|
+
|
|
128
|
+
## ESLint flat config example
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
import etcMisc from "eslint-plugin-etc-misc";
|
|
132
|
+
|
|
133
|
+
export default [
|
|
134
|
+
{
|
|
135
|
+
plugins: { "etc-misc": etcMisc },
|
|
136
|
+
rules: {
|
|
137
|
+
"etc-misc/no-function-declare-after-return": "warn",
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
];
|
|
141
|
+
```
|
|
142
|
+
|
|
122
143
|
## When not to use it
|
|
123
144
|
|
|
124
145
|
- If your team relies on intentional hoisting patterns with thorough documentation,
|
|
@@ -132,18 +153,3 @@ This rule has no options.
|
|
|
132
153
|
|
|
133
154
|
- [MDN: Function declarations — Hoisting](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function#hoisting)
|
|
134
155
|
- [ESLint built-in: `no-unreachable`](https://eslint.org/docs/rules/no-unreachable)
|
|
135
|
-
|
|
136
|
-
## ESLint flat config example
|
|
137
|
-
|
|
138
|
-
```ts
|
|
139
|
-
import etcMisc from "eslint-plugin-etc-misc";
|
|
140
|
-
|
|
141
|
-
export default [
|
|
142
|
-
{
|
|
143
|
-
plugins: { "etc-misc": etcMisc },
|
|
144
|
-
rules: {
|
|
145
|
-
"etc-misc/no-function-declare-after-return": "warn",
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
];
|
|
149
|
-
```
|
|
@@ -2,20 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Disallow usage of non-native members on built-in JavaScript objects.
|
|
4
4
|
|
|
5
|
-
## Why this rule is included here
|
|
6
|
-
|
|
7
|
-
This rule was integrated into `eslint-plugin-etc-misc` to avoid requiring a separate single-rule plugin dependency.
|
|
8
|
-
|
|
9
|
-
Original plugin source: [`eslint-plugin-no-use-extend-native`](https://github.com/dustinspecker/eslint-plugin-no-use-extend-native).
|
|
10
|
-
|
|
11
|
-
## Rule details
|
|
12
|
-
|
|
13
|
-
This rule helps prevent implicit reliance on monkey-patched native prototypes (for example from legacy libraries that add methods like `String.prototype.green`).
|
|
14
|
-
|
|
15
|
-
Relying on extended native objects can make code unpredictable across runtimes, bundling targets, and dependency versions.
|
|
16
|
-
|
|
17
|
-
This rule reports member usage on obvious built-in values when the accessed member is not part of the native API.
|
|
18
|
-
|
|
19
5
|
## Targeted pattern scope
|
|
20
6
|
|
|
21
7
|
This rule is intentionally conservative and focuses on obvious built-in object shapes such as:
|
|
@@ -27,6 +13,16 @@ This rule is intentionally conservative and focuses on obvious built-in object s
|
|
|
27
13
|
|
|
28
14
|
It does **not** attempt full-flow inference for arbitrary identifiers.
|
|
29
15
|
|
|
16
|
+
## What this rule reports
|
|
17
|
+
|
|
18
|
+
This rule helps prevent implicit reliance on monkey-patched native prototypes (for example from legacy libraries that add methods like `String.prototype.green`).
|
|
19
|
+
|
|
20
|
+
This rule reports member usage on obvious built-in values when the accessed member is not part of the native API.
|
|
21
|
+
|
|
22
|
+
## Why this rule exists
|
|
23
|
+
|
|
24
|
+
Relying on extended native objects can make code unpredictable across runtimes, bundling targets, and dependency versions.
|
|
25
|
+
|
|
30
26
|
## ❌ Incorrect
|
|
31
27
|
|
|
32
28
|
```ts
|
|
@@ -55,11 +51,11 @@ const value = [].map((entry) => entry);
|
|
|
55
51
|
const value = String.prototype.toLowerCase.call("ABC");
|
|
56
52
|
```
|
|
57
53
|
|
|
58
|
-
##
|
|
54
|
+
## Behavior and migration notes
|
|
59
55
|
|
|
60
56
|
This rule has no options.
|
|
61
57
|
|
|
62
|
-
|
|
58
|
+
### Relationship to ESLint `no-extend-native`
|
|
63
59
|
|
|
64
60
|
- ESLint core [`no-extend-native`](https://eslint.org/docs/latest/rules/no-extend-native) prevents adding properties to native prototypes.
|
|
65
61
|
- This rule prevents consuming non-native members when they appear in code.
|
|
@@ -69,15 +65,7 @@ Using both rules together gives better protection:
|
|
|
69
65
|
1. Prevent introducing prototype extension.
|
|
70
66
|
2. Prevent relying on prototype extension from third-party code.
|
|
71
67
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
- If your project intentionally and explicitly relies on controlled prototype extension.
|
|
75
|
-
- If your runtime environment guarantees specific prototype patches and that dependency is accepted in your architecture.
|
|
76
|
-
|
|
77
|
-
## Further reading
|
|
78
|
-
|
|
79
|
-
- [ESLint `no-extend-native`](https://eslint.org/docs/latest/rules/no-extend-native)
|
|
80
|
-
- [MDN: Inheritance and the prototype chain](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain)
|
|
68
|
+
Original plugin source: [`eslint-plugin-no-use-extend-native`](https://github.com/dustinspecker/eslint-plugin-no-use-extend-native).
|
|
81
69
|
|
|
82
70
|
## ESLint flat config example
|
|
83
71
|
|
|
@@ -85,11 +73,21 @@ Using both rules together gives better protection:
|
|
|
85
73
|
import etcMisc from "eslint-plugin-etc-misc";
|
|
86
74
|
|
|
87
75
|
export default [
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
76
|
+
{
|
|
77
|
+
plugins: { "etc-misc": etcMisc },
|
|
78
|
+
rules: {
|
|
79
|
+
"etc-misc/no-use-extend-native": "error",
|
|
80
|
+
},
|
|
81
|
+
},
|
|
94
82
|
];
|
|
95
83
|
```
|
|
84
|
+
|
|
85
|
+
## When not to use it
|
|
86
|
+
|
|
87
|
+
- If your project intentionally and explicitly relies on controlled prototype extension.
|
|
88
|
+
- If your runtime environment guarantees specific prototype patches and that dependency is accepted in your architecture.
|
|
89
|
+
|
|
90
|
+
## Further reading
|
|
91
|
+
|
|
92
|
+
- [ESLint `no-extend-native`](https://eslint.org/docs/latest/rules/no-extend-native)
|
|
93
|
+
- [MDN: Inheritance and the prototype chain](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain)
|
|
@@ -2,28 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
Disallow regular expressions that are potentially vulnerable to ReDoS (Regular Expression Denial of Service).
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Targeted pattern scope
|
|
6
6
|
|
|
7
|
-
This rule
|
|
7
|
+
This rule checks:
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
- `/(...)/flags` literals.
|
|
10
|
+
- `RegExp("...")` and `new RegExp("...", "flags")` when both arguments are statically-known strings.
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
This rule intentionally skips dynamic patterns/flags it cannot resolve safely at lint time.
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
## What this rule reports
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
This rule analyzes regular expression literals and statically-resolvable `RegExp(...)` constructor calls using [`recheck`](https://www.npmjs.com/package/recheck).
|
|
16
17
|
|
|
17
18
|
This rule reports patterns that `recheck` identifies as vulnerable with polynomial or exponential complexity.
|
|
18
19
|
|
|
19
|
-
##
|
|
20
|
-
|
|
21
|
-
This rule checks:
|
|
20
|
+
## Why this rule exists
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
- `RegExp("...")` and `new RegExp("...", "flags")` when both arguments are statically-known strings.
|
|
25
|
-
|
|
26
|
-
This rule intentionally skips dynamic patterns/flags it cannot resolve safely at lint time.
|
|
22
|
+
Catastrophic backtracking can make an application spend excessive CPU time on crafted inputs. In server contexts, that can become an availability issue.
|
|
27
23
|
|
|
28
24
|
## ❌ Incorrect
|
|
29
25
|
|
|
@@ -50,15 +46,15 @@ const source = getPatternFromConfig();
|
|
|
50
46
|
const maybeUnsafe = RegExp(source); // Dynamic value: intentionally not analyzed.
|
|
51
47
|
```
|
|
52
48
|
|
|
53
|
-
##
|
|
49
|
+
## Behavior and migration notes
|
|
54
50
|
|
|
55
51
|
```ts
|
|
56
52
|
type Options = [
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
{
|
|
54
|
+
ignoreErrors?: boolean;
|
|
55
|
+
permittableComplexities?: Array<"polynomial" | "exponential">;
|
|
56
|
+
timeout?: number | null;
|
|
57
|
+
}?,
|
|
62
58
|
];
|
|
63
59
|
```
|
|
64
60
|
|
|
@@ -94,6 +90,23 @@ For example, to allow polynomial but still report exponential:
|
|
|
94
90
|
}
|
|
95
91
|
```
|
|
96
92
|
|
|
93
|
+
Original plugin source: [`eslint-plugin-redos-detector`](https://github.com/tjenkinson/eslint-plugin-redos-detector).
|
|
94
|
+
|
|
95
|
+
## ESLint flat config example
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import etcMisc from "eslint-plugin-etc-misc";
|
|
99
|
+
|
|
100
|
+
export default [
|
|
101
|
+
{
|
|
102
|
+
plugins: { "etc-misc": etcMisc },
|
|
103
|
+
rules: {
|
|
104
|
+
"etc-misc/no-vulnerable": "error",
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
];
|
|
108
|
+
```
|
|
109
|
+
|
|
97
110
|
## When not to use it
|
|
98
111
|
|
|
99
112
|
- If your codebase never handles untrusted input with regexes.
|
|
@@ -105,18 +118,3 @@ For example, to allow polynomial but still report exponential:
|
|
|
105
118
|
- [OWASP: Regular expression Denial of Service (ReDoS)](https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS)
|
|
106
119
|
- [`recheck` package](https://www.npmjs.com/package/recheck)
|
|
107
120
|
- [MDN: Regular expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions)
|
|
108
|
-
|
|
109
|
-
## ESLint flat config example
|
|
110
|
-
|
|
111
|
-
```ts
|
|
112
|
-
import etcMisc from "eslint-plugin-etc-misc";
|
|
113
|
-
|
|
114
|
-
export default [
|
|
115
|
-
{
|
|
116
|
-
plugins: { "etc-misc": etcMisc },
|
|
117
|
-
rules: {
|
|
118
|
-
"etc-misc/no-vulnerable": "error",
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
];
|
|
122
|
-
```
|
|
@@ -19,22 +19,13 @@ comparisons.
|
|
|
19
19
|
## ❌ Incorrect
|
|
20
20
|
|
|
21
21
|
```ts
|
|
22
|
-
const hasValue =
|
|
23
|
-
[
|
|
24
|
-
1,
|
|
25
|
-
2,
|
|
26
|
-
3,
|
|
27
|
-
].indexOf(2) !== -1;
|
|
22
|
+
const hasValue = [1, 2, 3].indexOf(2) !== -1;
|
|
28
23
|
```
|
|
29
24
|
|
|
30
25
|
## ✅ Correct
|
|
31
26
|
|
|
32
27
|
```ts
|
|
33
|
-
const hasValue = [
|
|
34
|
-
1,
|
|
35
|
-
2,
|
|
36
|
-
3,
|
|
37
|
-
].includes(2);
|
|
28
|
+
const hasValue = [1, 2, 3].includes(2);
|
|
38
29
|
```
|
|
39
30
|
|
|
40
31
|
## Behavior and migration notes
|
|
@@ -46,7 +46,7 @@ export default [etcMisc.configs.recommended];
|
|
|
46
46
|
|
|
47
47
|
## Adoption guidance
|
|
48
48
|
|
|
49
|
-
If you don
|
|
49
|
+
If you don't want readonly preference rules yet, start with minimal. Otherwise, start here for a balanced baseline of correctness and maintainability rules. This preset is designed to be a long-term baseline, so it includes some rules that may be initially noisy but are worth fixing early for long-term benefits.
|
|
50
50
|
|
|
51
51
|
This preset now enables a wider "safe baseline" mix:
|
|
52
52
|
|
package/docs/rules/sort-array.md
CHANGED
|
@@ -25,21 +25,13 @@ faster during code review.
|
|
|
25
25
|
## ❌ Incorrect
|
|
26
26
|
|
|
27
27
|
```ts
|
|
28
|
-
const statuses = [
|
|
29
|
-
"pending",
|
|
30
|
-
"active",
|
|
31
|
-
"archived",
|
|
32
|
-
];
|
|
28
|
+
const statuses = ["pending", "active", "archived"];
|
|
33
29
|
```
|
|
34
30
|
|
|
35
31
|
## ✅ Correct
|
|
36
32
|
|
|
37
33
|
```ts
|
|
38
|
-
const statuses = [
|
|
39
|
-
"active",
|
|
40
|
-
"archived",
|
|
41
|
-
"pending",
|
|
42
|
-
];
|
|
34
|
+
const statuses = ["active", "archived", "pending"];
|
|
43
35
|
```
|
|
44
36
|
|
|
45
37
|
## Behavior and migration notes
|