@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,87 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: js/no-irregular-whitespace
|
|
3
|
+
title: "No irregular whitespace in templates, regular expressions, JSX text or comments"
|
|
4
|
+
languages: [javascript, jsx, typescript, tsx]
|
|
5
|
+
fix: suggest
|
|
6
|
+
fix_reason: "the escape keeps a template's cooked value but changes the raw string a tagged template such as `String.raw` sees"
|
|
7
|
+
stability: preview
|
|
8
|
+
ported_from: [eslint/no-irregular-whitespace]
|
|
9
|
+
since: 0.1.0
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
Templates, regular expressions and JSX text spell a no-break space, zero-width space or other
|
|
13
|
+
irregular whitespace as an escape (`\u00A0`, ` `), and comments use ordinary spaces.
|
|
14
|
+
|
|
15
|
+
**Why:** Irregular whitespace is invisible in most editors. In a template, regular expression or JSX
|
|
16
|
+
text it silently becomes part of the value, so the text looks right and compares wrong.
|
|
17
|
+
|
|
18
|
+
```codelaw
|
|
19
|
+
native: js/no-irregular-whitespace
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Examples
|
|
23
|
+
|
|
24
|
+
### JavaScript
|
|
25
|
+
|
|
26
|
+
#### Don't
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
const label = `Total: 1`;
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
#### Do
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
const label = `Total:\u00A01`;
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### JSX
|
|
39
|
+
|
|
40
|
+
#### Don't
|
|
41
|
+
|
|
42
|
+
```jsx
|
|
43
|
+
const label = <p>Total: 1</p>;
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
#### Do
|
|
47
|
+
|
|
48
|
+
```jsx
|
|
49
|
+
const label = <p>Total: 1</p>;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### TypeScript
|
|
53
|
+
|
|
54
|
+
#### Don't
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
const label = `Total: 1`;
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
#### Do
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
const label = `Total:\u00A01`;
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### TSX
|
|
67
|
+
|
|
68
|
+
#### Don't
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
const label = <p>Total: 1</p>;
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
#### Do
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
const label = <p>Total: 1</p>;
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Differences from the source
|
|
81
|
+
|
|
82
|
+
- **Between tokens the formatter owns it.** ESLint also reports irregular whitespace between tokens;
|
|
83
|
+
here that is layout, and `codelaw format` replaces it with a space (SR-FORMATTER decision 3), so
|
|
84
|
+
this rule does not report it.
|
|
85
|
+
- **Strings are skipped**, as ESLint's `skipStrings` default does.
|
|
86
|
+
- **The fix escapes, it doesn't delete:** `\uXXXX` in a template or regular expression, `&#xXXXX;`
|
|
87
|
+
in JSX text, so the value is unchanged; a comment gets an ordinary space.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: js/no-loss-of-precision
|
|
3
|
+
title: "Number literals keep their value"
|
|
4
|
+
languages: [javascript, jsx, typescript, tsx]
|
|
5
|
+
fix: manual
|
|
6
|
+
fix_reason: "whether to use a BigInt, a string or a rounder value depends on how the number is used"
|
|
7
|
+
stability: preview
|
|
8
|
+
ported_from: [eslint/no-loss-of-precision]
|
|
9
|
+
since: 0.1.0
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
A number literal can be represented exactly as a JavaScript number.
|
|
13
|
+
|
|
14
|
+
**Why:** A literal with more precision than a double holds is silently rounded, so the code doesn't
|
|
15
|
+
mean what it says.
|
|
16
|
+
|
|
17
|
+
```codelaw
|
|
18
|
+
native: js/no-loss-of-precision
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## How to fix
|
|
22
|
+
|
|
23
|
+
1. Use a BigInt (`123n`) for an exact large integer.
|
|
24
|
+
2. Or keep the value as a string, or write the value the code really gets.
|
|
25
|
+
|
|
26
|
+
## Examples
|
|
27
|
+
|
|
28
|
+
### JavaScript
|
|
29
|
+
|
|
30
|
+
#### Don't
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
const id = 9007199254740993;
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
#### Do
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
const id = 9007199254740993n;
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### JSX
|
|
43
|
+
|
|
44
|
+
#### Don't
|
|
45
|
+
|
|
46
|
+
```jsx
|
|
47
|
+
const id = 9007199254740993;
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### Do
|
|
51
|
+
|
|
52
|
+
```jsx
|
|
53
|
+
const id = 9007199254740993n;
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### TypeScript
|
|
57
|
+
|
|
58
|
+
#### Don't
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
const id = 9007199254740993;
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
#### Do
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
const id = 9007199254740993n;
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### TSX
|
|
71
|
+
|
|
72
|
+
#### Don't
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
const id = 9007199254740993;
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
#### Do
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
const id = 9007199254740993n;
|
|
82
|
+
```
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: js/no-misleading-character-class
|
|
3
|
+
title: "No character class holding a character made of several code points"
|
|
4
|
+
languages: [javascript, jsx, typescript, tsx]
|
|
5
|
+
fix: manual
|
|
6
|
+
fix_reason: "whether an alternation or a different class was meant needs the author"
|
|
7
|
+
stability: preview
|
|
8
|
+
ported_from: [eslint/no-misleading-character-class]
|
|
9
|
+
since: 0.1.0
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
A character class contains no character built from several code points — an emoji with a skin-tone
|
|
13
|
+
modifier, a flag, a letter with a combining mark — and no astral character without the `u` flag.
|
|
14
|
+
|
|
15
|
+
**Why:** A class matches one code point at a time, so `[👍🏻]` matches the thumb or the tone, never
|
|
16
|
+
the pair.
|
|
17
|
+
|
|
18
|
+
```codelaw
|
|
19
|
+
native: js/no-misleading-character-class
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## How to fix
|
|
23
|
+
|
|
24
|
+
1. Use an alternation such as `(?:👍🏻|👍)` for multi-code-point characters.
|
|
25
|
+
2. Add the `u` flag for astral characters.
|
|
26
|
+
|
|
27
|
+
## Examples
|
|
28
|
+
|
|
29
|
+
### JavaScript
|
|
30
|
+
|
|
31
|
+
#### Don't
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
const re = /^[❤️]$/u;
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
#### Do
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
const re = /^(?:❤️)$/u;
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### JSX
|
|
44
|
+
|
|
45
|
+
#### Don't
|
|
46
|
+
|
|
47
|
+
```jsx
|
|
48
|
+
const re = /^[❤️]$/u;
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
#### Do
|
|
52
|
+
|
|
53
|
+
```jsx
|
|
54
|
+
const re = /^(?:❤️)$/u;
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### TypeScript
|
|
58
|
+
|
|
59
|
+
#### Don't
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
const re = /^[❤️]$/u;
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### Do
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
const re = /^(?:❤️)$/u;
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### TSX
|
|
72
|
+
|
|
73
|
+
#### Don't
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
const re = /^[❤️]$/u;
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
#### Do
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
const re = /^(?:❤️)$/u;
|
|
83
|
+
```
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: js/no-new-native-nonconstructor
|
|
3
|
+
title: "No new on Symbol or BigInt"
|
|
4
|
+
languages: [javascript, jsx]
|
|
5
|
+
fix: suggest
|
|
6
|
+
fix_reason: "the call throws today, so removing `new` changes what the code does"
|
|
7
|
+
stability: preview
|
|
8
|
+
ported_from: [eslint/no-new-native-nonconstructor]
|
|
9
|
+
since: 0.1.0
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
`Symbol` and `BigInt` are called as functions, never with `new`.
|
|
13
|
+
|
|
14
|
+
**Why:** `new Symbol()` and `new BigInt()` throw a TypeError.
|
|
15
|
+
|
|
16
|
+
```codelaw
|
|
17
|
+
match:
|
|
18
|
+
pattern: new $C($$$ARGS)
|
|
19
|
+
constraints:
|
|
20
|
+
C: { regex: ^(Symbol|BigInt)$ }
|
|
21
|
+
where:
|
|
22
|
+
$C: builtin
|
|
23
|
+
message: "`$C` is not a constructor; call it without `new`"
|
|
24
|
+
fix: "$C($$$ARGS)"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Examples
|
|
28
|
+
|
|
29
|
+
### JavaScript
|
|
30
|
+
|
|
31
|
+
#### Don't
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
const id = new Symbol("id");
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
#### Do
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
const id = Symbol("id");
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### JSX
|
|
44
|
+
|
|
45
|
+
#### Don't
|
|
46
|
+
|
|
47
|
+
```jsx
|
|
48
|
+
const id = new Symbol("id");
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
#### Do
|
|
52
|
+
|
|
53
|
+
```jsx
|
|
54
|
+
const id = Symbol("id");
|
|
55
|
+
```
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: js/no-nonoctal-decimal-escape
|
|
3
|
+
title: "No \\8 or \\9 escapes in strings"
|
|
4
|
+
languages: [javascript, jsx, typescript, tsx]
|
|
5
|
+
fix: manual
|
|
6
|
+
fix_reason: "whether the digit or a literal backslash was meant needs the author"
|
|
7
|
+
stability: preview
|
|
8
|
+
ported_from: [eslint/no-nonoctal-decimal-escape]
|
|
9
|
+
since: 0.1.0
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
A string contains no `\8` or `\9` escape.
|
|
13
|
+
|
|
14
|
+
**Why:** `\8` and `\9` are legacy escapes that just mean the digits, and are errors in template
|
|
15
|
+
literals and strict code.
|
|
16
|
+
|
|
17
|
+
```codelaw
|
|
18
|
+
match:
|
|
19
|
+
kind: escape_sequence
|
|
20
|
+
regex: ^\\[89]$
|
|
21
|
+
message: "`$$MATCH` is not an escape; it's the digit itself"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## How to fix
|
|
25
|
+
|
|
26
|
+
1. Write the digit without the backslash, or `\\8` for a backslash and a digit.
|
|
27
|
+
|
|
28
|
+
## Examples
|
|
29
|
+
|
|
30
|
+
### JavaScript
|
|
31
|
+
|
|
32
|
+
#### Don't
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
const msg = "version \8";
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
#### Do
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
const msg = "version 8";
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### JSX
|
|
45
|
+
|
|
46
|
+
#### Don't
|
|
47
|
+
|
|
48
|
+
```jsx
|
|
49
|
+
const msg = "version \8";
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
#### Do
|
|
53
|
+
|
|
54
|
+
```jsx
|
|
55
|
+
const msg = "version 8";
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### TypeScript
|
|
59
|
+
|
|
60
|
+
#### Don't
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
const msg = "version \8";
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### Do
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
const msg = "version 8";
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### TSX
|
|
73
|
+
|
|
74
|
+
#### Don't
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
const msg = "version \8";
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
#### Do
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
const msg = "version 8";
|
|
84
|
+
```
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: js/no-obj-calls
|
|
3
|
+
title: "No calling Math, JSON, Reflect, Atomics or Intl as functions"
|
|
4
|
+
languages: [javascript, jsx]
|
|
5
|
+
fix: manual
|
|
6
|
+
fix_reason: "which method was meant needs the author"
|
|
7
|
+
stability: preview
|
|
8
|
+
ported_from: [eslint/no-obj-calls]
|
|
9
|
+
since: 0.1.0
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
The built-in namespace objects `Math`, `JSON`, `Reflect`, `Atomics` and `Intl` are not called or
|
|
13
|
+
constructed.
|
|
14
|
+
|
|
15
|
+
**Why:** They are plain objects; calling one throws a TypeError.
|
|
16
|
+
|
|
17
|
+
```codelaw
|
|
18
|
+
match:
|
|
19
|
+
any:
|
|
20
|
+
- pattern: $C($$$ARGS)
|
|
21
|
+
- pattern: new $C($$$ARGS)
|
|
22
|
+
constraints:
|
|
23
|
+
C: { regex: ^(Math|JSON|Reflect|Atomics|Intl)$ }
|
|
24
|
+
where:
|
|
25
|
+
$C: builtin
|
|
26
|
+
message: "`$C` is a namespace object, not a function"
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## How to fix
|
|
30
|
+
|
|
31
|
+
1. Call the method of the namespace that was meant, e.g. `Math.round(x)`.
|
|
32
|
+
|
|
33
|
+
## Examples
|
|
34
|
+
|
|
35
|
+
### JavaScript
|
|
36
|
+
|
|
37
|
+
#### Don't
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
const n = Math(2.5);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
#### Do
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
const n = Math.round(2.5);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### JSX
|
|
50
|
+
|
|
51
|
+
#### Don't
|
|
52
|
+
|
|
53
|
+
```jsx
|
|
54
|
+
const n = Math(2.5);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
#### Do
|
|
58
|
+
|
|
59
|
+
```jsx
|
|
60
|
+
const n = Math.round(2.5);
|
|
61
|
+
```
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: js/no-octal
|
|
3
|
+
title: "No legacy octal literals"
|
|
4
|
+
languages: [javascript, jsx, typescript, tsx]
|
|
5
|
+
fix: manual
|
|
6
|
+
fix_reason: "whether octal or decimal was meant needs the author"
|
|
7
|
+
stability: preview
|
|
8
|
+
ported_from: [eslint/no-octal]
|
|
9
|
+
since: 0.1.0
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
Number literals don't start with `0` followed by a digit.
|
|
13
|
+
|
|
14
|
+
**Why:** `071` is octal (57) in sloppy code and an error in strict code; `0o71` says what it means.
|
|
15
|
+
|
|
16
|
+
```codelaw
|
|
17
|
+
match:
|
|
18
|
+
kind: number
|
|
19
|
+
regex: ^0[0-9]
|
|
20
|
+
message: "`$$MATCH` is a legacy octal literal; write 0o… for octal or drop the leading 0"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## How to fix
|
|
24
|
+
|
|
25
|
+
1. For an octal number, write `0o` and the digits.
|
|
26
|
+
2. For a decimal number, drop the leading zero.
|
|
27
|
+
|
|
28
|
+
## Examples
|
|
29
|
+
|
|
30
|
+
### JavaScript
|
|
31
|
+
|
|
32
|
+
#### Don't
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
const mode = 0755;
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
#### Do
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
const mode = 0o755;
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### JSX
|
|
45
|
+
|
|
46
|
+
#### Don't
|
|
47
|
+
|
|
48
|
+
```jsx
|
|
49
|
+
const mode = 0755;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
#### Do
|
|
53
|
+
|
|
54
|
+
```jsx
|
|
55
|
+
const mode = 0o755;
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### TypeScript
|
|
59
|
+
|
|
60
|
+
#### Don't
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
const mode = 0755;
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### Do
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
const mode = 0o755;
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### TSX
|
|
73
|
+
|
|
74
|
+
#### Don't
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
const mode = 0755;
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
#### Do
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
const mode = 0o755;
|
|
84
|
+
```
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: js/no-prototype-builtins
|
|
3
|
+
title: "No calling Object.prototype methods on the object itself"
|
|
4
|
+
languages: [javascript, jsx, typescript, tsx]
|
|
5
|
+
fix: suggest
|
|
6
|
+
fix_reason: "an object whose own method is meant would change behaviour"
|
|
7
|
+
stability: preview
|
|
8
|
+
ported_from: [eslint/no-prototype-builtins]
|
|
9
|
+
since: 0.1.0
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
`hasOwnProperty`, `isPrototypeOf` and `propertyIsEnumerable` are called through `Object.prototype`,
|
|
13
|
+
not on the object being tested.
|
|
14
|
+
|
|
15
|
+
**Why:** An object can shadow these methods, or have no prototype at all, and then the call breaks
|
|
16
|
+
or lies.
|
|
17
|
+
|
|
18
|
+
```codelaw
|
|
19
|
+
match:
|
|
20
|
+
pattern: $O.$M($$$ARGS)
|
|
21
|
+
constraints:
|
|
22
|
+
M: { regex: ^(hasOwnProperty|isPrototypeOf|propertyIsEnumerable)$ }
|
|
23
|
+
message: "Call `Object.prototype.$M` through `.call`, or use `Object.hasOwn`"
|
|
24
|
+
fix: "Object.prototype.$M.call($O, $$$ARGS)"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Examples
|
|
28
|
+
|
|
29
|
+
### JavaScript
|
|
30
|
+
|
|
31
|
+
#### Don't
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
if (options.hasOwnProperty("debug")) {
|
|
35
|
+
enable();
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
#### Do
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
if (Object.prototype.hasOwnProperty.call(options, "debug")) {
|
|
43
|
+
enable();
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### JSX
|
|
48
|
+
|
|
49
|
+
#### Don't
|
|
50
|
+
|
|
51
|
+
```jsx
|
|
52
|
+
if (options.hasOwnProperty("debug")) {
|
|
53
|
+
enable();
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
#### Do
|
|
58
|
+
|
|
59
|
+
```jsx
|
|
60
|
+
if (Object.prototype.hasOwnProperty.call(options, "debug")) {
|
|
61
|
+
enable();
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### TypeScript
|
|
66
|
+
|
|
67
|
+
#### Don't
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
if (options.hasOwnProperty("debug")) {
|
|
71
|
+
enable();
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
#### Do
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
if (Object.prototype.hasOwnProperty.call(options, "debug")) {
|
|
79
|
+
enable();
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### TSX
|
|
84
|
+
|
|
85
|
+
#### Don't
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
if (options.hasOwnProperty("debug")) {
|
|
89
|
+
enable();
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
#### Do
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
if (Object.prototype.hasOwnProperty.call(options, "debug")) {
|
|
97
|
+
enable();
|
|
98
|
+
}
|
|
99
|
+
```
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: js/no-redeclare
|
|
3
|
+
title: "No variable is declared twice"
|
|
4
|
+
languages: [javascript, jsx]
|
|
5
|
+
fix: manual
|
|
6
|
+
fix_reason: "whether to rename or to assign needs the author"
|
|
7
|
+
stability: preview
|
|
8
|
+
ported_from: [eslint/no-redeclare]
|
|
9
|
+
since: 0.1.0
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
A name is declared once per scope: a second `var` or `function` with the same name is not allowed.
|
|
13
|
+
|
|
14
|
+
**Why:** Redeclaring silently merges two declarations, so one of them is usually a mistake.
|
|
15
|
+
|
|
16
|
+
```codelaw
|
|
17
|
+
match:
|
|
18
|
+
kind: identifier
|
|
19
|
+
where:
|
|
20
|
+
$$MATCH: [declaration, redeclared]
|
|
21
|
+
message: "`$$MATCH` is already declared in this scope"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## How to fix
|
|
25
|
+
|
|
26
|
+
1. If it's the same variable, drop the second `var` and assign.
|
|
27
|
+
2. If it's a different one, rename it.
|
|
28
|
+
|
|
29
|
+
## Examples
|
|
30
|
+
|
|
31
|
+
### JavaScript
|
|
32
|
+
|
|
33
|
+
#### Don't
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
var count = 1;
|
|
37
|
+
var count = 2;
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
#### Do
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
var count = 1;
|
|
44
|
+
count = 2;
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### JSX
|
|
48
|
+
|
|
49
|
+
#### Don't
|
|
50
|
+
|
|
51
|
+
```jsx
|
|
52
|
+
var count = 1;
|
|
53
|
+
var count = 2;
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
#### Do
|
|
57
|
+
|
|
58
|
+
```jsx
|
|
59
|
+
var count = 1;
|
|
60
|
+
count = 2;
|
|
61
|
+
```
|