@codelaw/rules-js 0.0.0-stage → 0.1.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/LICENSE +23 -0
- package/NOTICE +19 -0
- package/README.md +90 -2
- package/codelaw-pack.toml +6 -0
- package/data/globals/browser.json +1209 -0
- package/data/globals/commonjs.json +6 -0
- package/data/globals/jest.json +15 -0
- package/data/globals/mocha.json +22 -0
- package/data/globals/node.json +83 -0
- package/data/globals/serviceworker.json +328 -0
- package/data/globals/shared-node-browser.json +73 -0
- package/data/globals/vitest.json +19 -0
- package/data/globals/worker.json +349 -0
- package/data/node/deprecated-api.json +83 -0
- package/data/react/dom-property-aliases.json +131 -0
- package/package.json +14 -4
- package/presets/js/conventions.toml +10 -0
- package/presets/js/recommended.toml +67 -0
- package/presets/node/recommended.toml +13 -0
- package/presets/react/recommended.toml +22 -0
- package/presets/stencil/recommended.toml +18 -0
- package/presets/ts/recommended.toml +27 -0
- package/rules/graph/no-unused-exports.md +135 -0
- package/rules/js/constructor-super.md +77 -0
- package/rules/js/exports-at-end.md +134 -0
- package/rules/js/for-direction.md +106 -0
- package/rules/js/getter-return.md +74 -0
- package/rules/js/import-groups.md +117 -0
- package/rules/js/no-async-promise-executor.md +95 -0
- package/rules/js/no-case-declarations.md +134 -0
- package/rules/js/no-class-assign.md +61 -0
- package/rules/js/no-compare-neg-zero.md +105 -0
- package/rules/js/no-cond-assign.md +135 -0
- package/rules/js/no-const-assign.md +61 -0
- package/rules/js/no-constant-binary-expression.md +83 -0
- package/rules/js/no-constant-condition.md +150 -0
- package/rules/js/no-control-regex.md +84 -0
- package/rules/js/no-debugger.md +99 -0
- package/rules/js/no-default-export.md +88 -0
- package/rules/js/no-delete-var.md +93 -0
- package/rules/js/no-dupe-args.md +61 -0
- package/rules/js/no-dupe-class-members.md +82 -0
- package/rules/js/no-dupe-else-if.md +113 -0
- package/rules/js/no-dupe-keys.md +66 -0
- package/rules/js/no-duplicate-case.md +137 -0
- package/rules/js/no-empty-character-class.md +98 -0
- package/rules/js/no-empty-pattern.md +86 -0
- package/rules/js/no-empty-static-block.md +99 -0
- package/rules/js/no-empty.md +116 -0
- package/rules/js/no-ex-assign.md +121 -0
- package/rules/js/no-extra-boolean-cast.md +107 -0
- package/rules/js/no-fallthrough.md +178 -0
- package/rules/js/no-func-assign.md +62 -0
- package/rules/js/no-global-assign.md +85 -0
- package/rules/js/no-import-assign.md +60 -0
- package/rules/js/no-invalid-regexp.md +86 -0
- package/rules/js/no-irregular-whitespace.md +87 -0
- package/rules/js/no-loss-of-precision.md +82 -0
- package/rules/js/no-misleading-character-class.md +83 -0
- package/rules/js/no-new-native-nonconstructor.md +55 -0
- package/rules/js/no-nonoctal-decimal-escape.md +84 -0
- package/rules/js/no-obj-calls.md +61 -0
- package/rules/js/no-octal.md +84 -0
- package/rules/js/no-prototype-builtins.md +99 -0
- package/rules/js/no-redeclare.md +61 -0
- package/rules/js/no-regex-spaces.md +75 -0
- package/rules/js/no-self-assign.md +91 -0
- package/rules/js/no-setter-return.md +69 -0
- package/rules/js/no-shadow-restricted-names.md +102 -0
- package/rules/js/no-sparse-arrays.md +82 -0
- package/rules/js/no-this-before-super.md +74 -0
- package/rules/js/no-unassigned-vars.md +102 -0
- package/rules/js/no-undef.md +76 -0
- package/rules/js/no-unexpected-multiline.md +91 -0
- package/rules/js/no-unreachable.md +59 -0
- package/rules/js/no-unsafe-finally.md +145 -0
- package/rules/js/no-unsafe-negation.md +71 -0
- package/rules/js/no-unsafe-optional-chaining.md +83 -0
- package/rules/js/no-unused-labels.md +102 -0
- package/rules/js/no-unused-private-class-members.md +126 -0
- package/rules/js/no-unused-vars.md +69 -0
- package/rules/js/no-useless-assignment.md +115 -0
- package/rules/js/no-useless-backreference.md +83 -0
- package/rules/js/no-useless-catch.md +105 -0
- package/rules/js/no-useless-escape.md +81 -0
- package/rules/js/no-var.md +76 -0
- package/rules/js/no-with.md +60 -0
- package/rules/js/prefer-const.md +83 -0
- package/rules/js/prefer-rest-params.md +103 -0
- package/rules/js/prefer-spread.md +95 -0
- package/rules/js/preserve-caught-error.md +122 -0
- package/rules/js/require-yield.md +107 -0
- package/rules/js/use-isnan.md +105 -0
- package/rules/js/valid-typeof.md +111 -0
- package/rules/node/hashbang.md +71 -0
- package/rules/node/no-deprecated-api.md +91 -0
- package/rules/node/no-exports-assign.md +92 -0
- package/rules/node/no-extraneous-import.md +118 -0
- package/rules/node/no-extraneous-require.md +117 -0
- package/rules/node/no-missing-import.md +118 -0
- package/rules/node/no-missing-require.md +117 -0
- package/rules/node/no-process-exit.md +99 -0
- package/rules/node/no-unpublished-import.md +134 -0
- package/rules/node/no-unpublished-require.md +133 -0
- package/rules/react/display-name.md +91 -0
- package/rules/react/exhaustive-deps.md +116 -0
- package/rules/react/hook-prefix.md +108 -0
- package/rules/react/jsx-key.md +99 -0
- package/rules/react/jsx-no-comment-textnodes.md +87 -0
- package/rules/react/jsx-no-duplicate-props.md +66 -0
- package/rules/react/jsx-no-target-blank.md +78 -0
- package/rules/react/jsx-no-undef.md +78 -0
- package/rules/react/no-children-prop.md +80 -0
- package/rules/react/no-danger-with-children.md +83 -0
- package/rules/react/no-deprecated.md +84 -0
- package/rules/react/no-direct-mutation-state.md +102 -0
- package/rules/react/no-find-dom-node.md +72 -0
- package/rules/react/no-is-mounted.md +109 -0
- package/rules/react/no-render-return-value.md +75 -0
- package/rules/react/no-string-refs.md +72 -0
- package/rules/react/no-unescaped-entities.md +69 -0
- package/rules/react/no-unknown-property.md +69 -0
- package/rules/react/props-type-name.md +43 -0
- package/rules/react/require-render-return.md +91 -0
- package/rules/react/rules-of-hooks.md +128 -0
- package/rules/stencil/ban-default-true.md +70 -0
- package/rules/stencil/ban-exported-const-enums.md +60 -0
- package/rules/stencil/ban-prefix.md +76 -0
- package/rules/stencil/decorators-context.md +61 -0
- package/rules/stencil/host-data-deprecated.md +73 -0
- package/rules/stencil/methods-must-be-public.md +69 -0
- package/rules/stencil/no-unused-watch.md +68 -0
- package/rules/stencil/own-methods-must-be-private.md +68 -0
- package/rules/stencil/own-props-must-be-private.md +60 -0
- package/rules/stencil/prefer-vdom-listener.md +67 -0
- package/rules/stencil/prop-readonly.md +63 -0
- package/rules/stencil/props-must-be-public.md +68 -0
- package/rules/stencil/required-jsdoc.md +66 -0
- package/rules/stencil/reserved-member-names.md +70 -0
- package/rules/stencil/strict-mutable.md +75 -0
- package/rules/stencil/tag-prefix.md +75 -0
- package/rules/ts/ban-ts-comment.md +64 -0
- package/rules/ts/no-array-constructor.md +58 -0
- package/rules/ts/no-duplicate-enum-values.md +65 -0
- package/rules/ts/no-empty-object-type.md +65 -0
- package/rules/ts/no-explicit-any.md +61 -0
- package/rules/ts/no-extra-non-null-assertion.md +50 -0
- package/rules/ts/no-misused-new.md +70 -0
- package/rules/ts/no-namespace.md +65 -0
- package/rules/ts/no-non-null-asserted-optional-chain.md +55 -0
- package/rules/ts/no-require-imports.md +54 -0
- package/rules/ts/no-this-alias.md +68 -0
- package/rules/ts/no-unnecessary-type-constraint.md +64 -0
- package/rules/ts/no-unsafe-declaration-merging.md +73 -0
- package/rules/ts/no-unsafe-function-type.md +57 -0
- package/rules/ts/no-unused-expressions.md +61 -0
- package/rules/ts/no-unused-vars.md +68 -0
- package/rules/ts/no-wrapper-object-types.md +49 -0
- package/rules/ts/prefer-as-const.md +47 -0
- package/rules/ts/prefer-namespace-keyword.md +63 -0
- package/rules/ts/triple-slash-reference.md +60 -0
- package/rules/ts/type-only-imports.md +57 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: js/no-constant-condition
|
|
3
|
+
title: "No conditions that are always true or always false"
|
|
4
|
+
languages: [javascript, jsx, typescript, tsx]
|
|
5
|
+
fix: manual
|
|
6
|
+
fix_reason: "whether to remove the branch or fix the condition needs the author"
|
|
7
|
+
stability: preview
|
|
8
|
+
ported_from: [eslint/no-constant-condition]
|
|
9
|
+
since: 0.1.0
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
The condition of an `if`, `while` or `do … while` is not a literal or another value that is always
|
|
13
|
+
truthy or always falsy; `while (true)` is allowed.
|
|
14
|
+
|
|
15
|
+
**Why:** A constant condition is usually leftover debugging or a typo, and hides dead code.
|
|
16
|
+
|
|
17
|
+
```codelaw
|
|
18
|
+
match:
|
|
19
|
+
kind: parenthesized_expression
|
|
20
|
+
inside:
|
|
21
|
+
stopBy: neighbor
|
|
22
|
+
any: [{ kind: if_statement }, { kind: while_statement }, { kind: do_statement }]
|
|
23
|
+
field: condition
|
|
24
|
+
has:
|
|
25
|
+
stopBy: neighbor
|
|
26
|
+
any:
|
|
27
|
+
- kind: number
|
|
28
|
+
- kind: string
|
|
29
|
+
- kind: "true"
|
|
30
|
+
- kind: "false"
|
|
31
|
+
- kind: "null"
|
|
32
|
+
- kind: undefined
|
|
33
|
+
- kind: array
|
|
34
|
+
- kind: object
|
|
35
|
+
- kind: arrow_function
|
|
36
|
+
- kind: function_expression
|
|
37
|
+
- kind: regex
|
|
38
|
+
not:
|
|
39
|
+
all:
|
|
40
|
+
- inside: { stopBy: neighbor, kind: while_statement }
|
|
41
|
+
- has: { stopBy: neighbor, kind: "true" }
|
|
42
|
+
message: "This condition is a constant, so the branch always or never runs"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## How to fix
|
|
46
|
+
|
|
47
|
+
1. If the branch is dead, remove it.
|
|
48
|
+
2. Otherwise replace the constant with the condition that was meant.
|
|
49
|
+
|
|
50
|
+
## Examples
|
|
51
|
+
|
|
52
|
+
### JavaScript
|
|
53
|
+
|
|
54
|
+
#### Don't
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
if (0) {
|
|
58
|
+
debugPanel();
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
#### Do
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
if (debug) {
|
|
66
|
+
debugPanel();
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
while (true) {
|
|
72
|
+
step();
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### JSX
|
|
77
|
+
|
|
78
|
+
#### Don't
|
|
79
|
+
|
|
80
|
+
```jsx
|
|
81
|
+
if (0) {
|
|
82
|
+
debugPanel();
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
#### Do
|
|
87
|
+
|
|
88
|
+
```jsx
|
|
89
|
+
if (debug) {
|
|
90
|
+
debugPanel();
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
```jsx
|
|
95
|
+
while (true) {
|
|
96
|
+
step();
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### TypeScript
|
|
101
|
+
|
|
102
|
+
#### Don't
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
if (0) {
|
|
106
|
+
debugPanel();
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
#### Do
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
if (debug) {
|
|
114
|
+
debugPanel();
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
while (true) {
|
|
120
|
+
step();
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### TSX
|
|
125
|
+
|
|
126
|
+
#### Don't
|
|
127
|
+
|
|
128
|
+
```tsx
|
|
129
|
+
if (0) {
|
|
130
|
+
debugPanel();
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
#### Do
|
|
135
|
+
|
|
136
|
+
```tsx
|
|
137
|
+
if (debug) {
|
|
138
|
+
debugPanel();
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
```tsx
|
|
143
|
+
while (true) {
|
|
144
|
+
step();
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Differences from the source
|
|
149
|
+
|
|
150
|
+
Only literal conditions are checked; ESLint also folds some expressions such as `typeof x` and `!1`.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: js/no-control-regex
|
|
3
|
+
title: "No control characters in regular expressions"
|
|
4
|
+
languages: [javascript, jsx, typescript, tsx]
|
|
5
|
+
fix: manual
|
|
6
|
+
fix_reason: "which character was meant needs the author"
|
|
7
|
+
stability: preview
|
|
8
|
+
ported_from: [eslint/no-control-regex]
|
|
9
|
+
since: 0.1.0
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
A regular expression literal doesn't match ASCII control characters (`\x00`–`\x1F`).
|
|
13
|
+
|
|
14
|
+
**Why:** Control characters rarely appear in text, so matching them is usually an escaping mistake.
|
|
15
|
+
|
|
16
|
+
```codelaw
|
|
17
|
+
match:
|
|
18
|
+
kind: regex_pattern
|
|
19
|
+
regex: \\x[01][0-9a-fA-F]|\\u00[01][0-9a-fA-F]|[\x00-\x1f]
|
|
20
|
+
message: "Control characters in a regular expression are almost always a mistake"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## How to fix
|
|
24
|
+
|
|
25
|
+
1. Use the named escape (`\t`, `\n`, `\f`) if one was meant.
|
|
26
|
+
2. Otherwise remove the control character from the pattern.
|
|
27
|
+
|
|
28
|
+
## Examples
|
|
29
|
+
|
|
30
|
+
### JavaScript
|
|
31
|
+
|
|
32
|
+
#### Don't
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
const re = /\x0C/;
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
#### Do
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
const re = /\f/;
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### JSX
|
|
45
|
+
|
|
46
|
+
#### Don't
|
|
47
|
+
|
|
48
|
+
```jsx
|
|
49
|
+
const re = /\x0C/;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
#### Do
|
|
53
|
+
|
|
54
|
+
```jsx
|
|
55
|
+
const re = /\f/;
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### TypeScript
|
|
59
|
+
|
|
60
|
+
#### Don't
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
const re = /\x0C/;
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### Do
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
const re = /\f/;
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### TSX
|
|
73
|
+
|
|
74
|
+
#### Don't
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
const re = /\x0C/;
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
#### Do
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
const re = /\f/;
|
|
84
|
+
```
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: js/no-debugger
|
|
3
|
+
title: "No debugger statements"
|
|
4
|
+
languages: [javascript, jsx, typescript, tsx]
|
|
5
|
+
fix: auto
|
|
6
|
+
stability: preview
|
|
7
|
+
ported_from: [eslint/no-debugger]
|
|
8
|
+
since: 0.1.0
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
Code contains no `debugger` statements.
|
|
12
|
+
|
|
13
|
+
**Why:** `debugger` pauses execution wherever developer tools are open, which nobody wants in
|
|
14
|
+
shipped code.
|
|
15
|
+
|
|
16
|
+
```codelaw
|
|
17
|
+
match:
|
|
18
|
+
kind: debugger_statement
|
|
19
|
+
message: "Remove `debugger` before committing"
|
|
20
|
+
fix: [remove]
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Examples
|
|
24
|
+
|
|
25
|
+
### JavaScript
|
|
26
|
+
|
|
27
|
+
#### Don't
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
function load() {
|
|
31
|
+
debugger;
|
|
32
|
+
return fetchAll();
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
#### Do
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
function load() {
|
|
40
|
+
return fetchAll();
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### JSX
|
|
45
|
+
|
|
46
|
+
#### Don't
|
|
47
|
+
|
|
48
|
+
```jsx
|
|
49
|
+
function load() {
|
|
50
|
+
debugger;
|
|
51
|
+
return fetchAll();
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
#### Do
|
|
56
|
+
|
|
57
|
+
```jsx
|
|
58
|
+
function load() {
|
|
59
|
+
return fetchAll();
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### TypeScript
|
|
64
|
+
|
|
65
|
+
#### Don't
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
function load() {
|
|
69
|
+
debugger;
|
|
70
|
+
return fetchAll();
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
#### Do
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
function load() {
|
|
78
|
+
return fetchAll();
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### TSX
|
|
83
|
+
|
|
84
|
+
#### Don't
|
|
85
|
+
|
|
86
|
+
```tsx
|
|
87
|
+
function load() {
|
|
88
|
+
debugger;
|
|
89
|
+
return fetchAll();
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
#### Do
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
function load() {
|
|
97
|
+
return fetchAll();
|
|
98
|
+
}
|
|
99
|
+
```
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: js/no-default-export
|
|
3
|
+
title: "No default exports"
|
|
4
|
+
languages: [javascript, jsx, typescript, tsx]
|
|
5
|
+
fix: manual
|
|
6
|
+
fix_reason: "every importer of the default export must change"
|
|
7
|
+
stability: preview
|
|
8
|
+
since: 0.1.0
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
Modules export by name; `export default` is not used.
|
|
12
|
+
|
|
13
|
+
**Why:** A named export has one name everywhere, so it can be found, renamed and auto-imported
|
|
14
|
+
reliably.
|
|
15
|
+
|
|
16
|
+
```codelaw
|
|
17
|
+
match:
|
|
18
|
+
kind: export_statement
|
|
19
|
+
has: { regex: ^default$ }
|
|
20
|
+
message: "Export this by name instead of as the default"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## How to fix
|
|
24
|
+
|
|
25
|
+
1. Give the exported value a name and export it with `export { name }`.
|
|
26
|
+
2. Change every `import x from` of this module to `import { name } from`.
|
|
27
|
+
|
|
28
|
+
## Examples
|
|
29
|
+
|
|
30
|
+
### JavaScript
|
|
31
|
+
|
|
32
|
+
#### Don't
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
export default function load() {}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
#### Do
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
function load() {}
|
|
42
|
+
export { load };
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### JSX
|
|
46
|
+
|
|
47
|
+
#### Don't
|
|
48
|
+
|
|
49
|
+
```jsx
|
|
50
|
+
export default function load() {}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
#### Do
|
|
54
|
+
|
|
55
|
+
```jsx
|
|
56
|
+
function load() {}
|
|
57
|
+
export { load };
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### TypeScript
|
|
61
|
+
|
|
62
|
+
#### Don't
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
export default function load() {}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### Do
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
function load() {}
|
|
72
|
+
export { load };
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### TSX
|
|
76
|
+
|
|
77
|
+
#### Don't
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
export default function load() {}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
#### Do
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
function load() {}
|
|
87
|
+
export { load };
|
|
88
|
+
```
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: js/no-delete-var
|
|
3
|
+
title: "No delete on a variable"
|
|
4
|
+
languages: [javascript, jsx, typescript, tsx]
|
|
5
|
+
fix: manual
|
|
6
|
+
fix_reason: "what the code meant to clear is a decision"
|
|
7
|
+
stability: preview
|
|
8
|
+
ported_from: [eslint/no-delete-var]
|
|
9
|
+
since: 0.1.0
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
`delete` is applied to object properties, never to a variable.
|
|
13
|
+
|
|
14
|
+
**Why:** Deleting a variable does nothing in sloppy mode and is a syntax error in strict mode.
|
|
15
|
+
|
|
16
|
+
```codelaw
|
|
17
|
+
match:
|
|
18
|
+
pattern: delete $X
|
|
19
|
+
constraints:
|
|
20
|
+
X: { kind: identifier }
|
|
21
|
+
message: "`delete` works on properties, not on the variable `$X`"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## How to fix
|
|
25
|
+
|
|
26
|
+
1. To clear the value, assign `undefined` or a fresh value.
|
|
27
|
+
2. To remove a property, `delete obj.key`.
|
|
28
|
+
|
|
29
|
+
## Examples
|
|
30
|
+
|
|
31
|
+
### JavaScript
|
|
32
|
+
|
|
33
|
+
#### Don't
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
let cache = {};
|
|
37
|
+
delete cache;
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
#### Do
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
let cache = {};
|
|
44
|
+
cache = {};
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### JSX
|
|
48
|
+
|
|
49
|
+
#### Don't
|
|
50
|
+
|
|
51
|
+
```jsx
|
|
52
|
+
let cache = {};
|
|
53
|
+
delete cache;
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
#### Do
|
|
57
|
+
|
|
58
|
+
```jsx
|
|
59
|
+
let cache = {};
|
|
60
|
+
cache = {};
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### TypeScript
|
|
64
|
+
|
|
65
|
+
#### Don't
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
let cache = {};
|
|
69
|
+
delete cache;
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
#### Do
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
let cache = {};
|
|
76
|
+
cache = {};
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### TSX
|
|
80
|
+
|
|
81
|
+
#### Don't
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
let cache = {};
|
|
85
|
+
delete cache;
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
#### Do
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
let cache = {};
|
|
92
|
+
cache = {};
|
|
93
|
+
```
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: js/no-dupe-args
|
|
3
|
+
title: "No two parameters share a name"
|
|
4
|
+
languages: [javascript, jsx]
|
|
5
|
+
fix: manual
|
|
6
|
+
fix_reason: "which parameter was meant can't be known from the code"
|
|
7
|
+
stability: preview
|
|
8
|
+
ported_from: [eslint/no-dupe-args]
|
|
9
|
+
since: 0.1.0
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
A function's parameters, destructured ones included, all have different names.
|
|
13
|
+
|
|
14
|
+
**Why:** The later parameter silently hides the earlier one, so one argument can never be read.
|
|
15
|
+
|
|
16
|
+
```codelaw
|
|
17
|
+
native: js/no-dupe-args
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## How to fix
|
|
21
|
+
|
|
22
|
+
1. Rename the duplicate parameter.
|
|
23
|
+
2. Update the body to read the parameter it meant.
|
|
24
|
+
|
|
25
|
+
## Examples
|
|
26
|
+
|
|
27
|
+
### JavaScript
|
|
28
|
+
|
|
29
|
+
#### Don't
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
function add(a, b, a) {
|
|
33
|
+
return a + b;
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
#### Do
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
function add(a, b, c) {
|
|
41
|
+
return a + b + c;
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### JSX
|
|
46
|
+
|
|
47
|
+
#### Don't
|
|
48
|
+
|
|
49
|
+
```jsx
|
|
50
|
+
function add(a, b, a) {
|
|
51
|
+
return a + b;
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
#### Do
|
|
56
|
+
|
|
57
|
+
```jsx
|
|
58
|
+
function add(a, b, c) {
|
|
59
|
+
return a + b + c;
|
|
60
|
+
}
|
|
61
|
+
```
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: js/no-dupe-class-members
|
|
3
|
+
title: "No two class members share a name"
|
|
4
|
+
languages: [javascript, jsx]
|
|
5
|
+
fix: manual
|
|
6
|
+
fix_reason: "which of the two members to keep is a decision"
|
|
7
|
+
stability: preview
|
|
8
|
+
ported_from: [eslint/no-dupe-class-members]
|
|
9
|
+
since: 0.1.0
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
A class declares each method and field name once, separately for static and instance members; a
|
|
13
|
+
getter and a setter may share a name.
|
|
14
|
+
|
|
15
|
+
**Why:** The later declaration replaces the earlier one, so one of them is dead code.
|
|
16
|
+
|
|
17
|
+
```codelaw
|
|
18
|
+
native: js/no-dupe-class-members
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## How to fix
|
|
22
|
+
|
|
23
|
+
1. Decide which declaration is right.
|
|
24
|
+
2. Remove or rename the other.
|
|
25
|
+
|
|
26
|
+
## Examples
|
|
27
|
+
|
|
28
|
+
### JavaScript
|
|
29
|
+
|
|
30
|
+
#### Don't
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
class Cart {
|
|
34
|
+
total() {
|
|
35
|
+
return 1;
|
|
36
|
+
}
|
|
37
|
+
total() {
|
|
38
|
+
return 2;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
#### Do
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
class Cart {
|
|
47
|
+
total() {
|
|
48
|
+
return 1;
|
|
49
|
+
}
|
|
50
|
+
subtotal() {
|
|
51
|
+
return 2;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### JSX
|
|
57
|
+
|
|
58
|
+
#### Don't
|
|
59
|
+
|
|
60
|
+
```jsx
|
|
61
|
+
class Cart {
|
|
62
|
+
total() {
|
|
63
|
+
return 1;
|
|
64
|
+
}
|
|
65
|
+
total() {
|
|
66
|
+
return 2;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
#### Do
|
|
72
|
+
|
|
73
|
+
```jsx
|
|
74
|
+
class Cart {
|
|
75
|
+
total() {
|
|
76
|
+
return 1;
|
|
77
|
+
}
|
|
78
|
+
subtotal() {
|
|
79
|
+
return 2;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|