@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.
Files changed (162) hide show
  1. package/LICENSE +23 -0
  2. package/NOTICE +19 -0
  3. package/README.md +90 -2
  4. package/codelaw-pack.toml +6 -0
  5. package/data/globals/browser.json +1209 -0
  6. package/data/globals/commonjs.json +6 -0
  7. package/data/globals/jest.json +15 -0
  8. package/data/globals/mocha.json +22 -0
  9. package/data/globals/node.json +83 -0
  10. package/data/globals/serviceworker.json +328 -0
  11. package/data/globals/shared-node-browser.json +73 -0
  12. package/data/globals/vitest.json +19 -0
  13. package/data/globals/worker.json +349 -0
  14. package/data/node/deprecated-api.json +83 -0
  15. package/data/react/dom-property-aliases.json +131 -0
  16. package/package.json +14 -4
  17. package/presets/js/conventions.toml +10 -0
  18. package/presets/js/recommended.toml +67 -0
  19. package/presets/node/recommended.toml +13 -0
  20. package/presets/react/recommended.toml +22 -0
  21. package/presets/stencil/recommended.toml +18 -0
  22. package/presets/ts/recommended.toml +27 -0
  23. package/rules/graph/no-unused-exports.md +135 -0
  24. package/rules/js/constructor-super.md +77 -0
  25. package/rules/js/exports-at-end.md +134 -0
  26. package/rules/js/for-direction.md +106 -0
  27. package/rules/js/getter-return.md +74 -0
  28. package/rules/js/import-groups.md +117 -0
  29. package/rules/js/no-async-promise-executor.md +95 -0
  30. package/rules/js/no-case-declarations.md +134 -0
  31. package/rules/js/no-class-assign.md +61 -0
  32. package/rules/js/no-compare-neg-zero.md +105 -0
  33. package/rules/js/no-cond-assign.md +135 -0
  34. package/rules/js/no-const-assign.md +61 -0
  35. package/rules/js/no-constant-binary-expression.md +83 -0
  36. package/rules/js/no-constant-condition.md +150 -0
  37. package/rules/js/no-control-regex.md +84 -0
  38. package/rules/js/no-debugger.md +99 -0
  39. package/rules/js/no-default-export.md +88 -0
  40. package/rules/js/no-delete-var.md +93 -0
  41. package/rules/js/no-dupe-args.md +61 -0
  42. package/rules/js/no-dupe-class-members.md +82 -0
  43. package/rules/js/no-dupe-else-if.md +113 -0
  44. package/rules/js/no-dupe-keys.md +66 -0
  45. package/rules/js/no-duplicate-case.md +137 -0
  46. package/rules/js/no-empty-character-class.md +98 -0
  47. package/rules/js/no-empty-pattern.md +86 -0
  48. package/rules/js/no-empty-static-block.md +99 -0
  49. package/rules/js/no-empty.md +116 -0
  50. package/rules/js/no-ex-assign.md +121 -0
  51. package/rules/js/no-extra-boolean-cast.md +107 -0
  52. package/rules/js/no-fallthrough.md +178 -0
  53. package/rules/js/no-func-assign.md +62 -0
  54. package/rules/js/no-global-assign.md +85 -0
  55. package/rules/js/no-import-assign.md +60 -0
  56. package/rules/js/no-invalid-regexp.md +86 -0
  57. package/rules/js/no-irregular-whitespace.md +87 -0
  58. package/rules/js/no-loss-of-precision.md +82 -0
  59. package/rules/js/no-misleading-character-class.md +83 -0
  60. package/rules/js/no-new-native-nonconstructor.md +55 -0
  61. package/rules/js/no-nonoctal-decimal-escape.md +84 -0
  62. package/rules/js/no-obj-calls.md +61 -0
  63. package/rules/js/no-octal.md +84 -0
  64. package/rules/js/no-prototype-builtins.md +99 -0
  65. package/rules/js/no-redeclare.md +61 -0
  66. package/rules/js/no-regex-spaces.md +75 -0
  67. package/rules/js/no-self-assign.md +91 -0
  68. package/rules/js/no-setter-return.md +69 -0
  69. package/rules/js/no-shadow-restricted-names.md +102 -0
  70. package/rules/js/no-sparse-arrays.md +82 -0
  71. package/rules/js/no-this-before-super.md +74 -0
  72. package/rules/js/no-unassigned-vars.md +102 -0
  73. package/rules/js/no-undef.md +76 -0
  74. package/rules/js/no-unexpected-multiline.md +91 -0
  75. package/rules/js/no-unreachable.md +59 -0
  76. package/rules/js/no-unsafe-finally.md +145 -0
  77. package/rules/js/no-unsafe-negation.md +71 -0
  78. package/rules/js/no-unsafe-optional-chaining.md +83 -0
  79. package/rules/js/no-unused-labels.md +102 -0
  80. package/rules/js/no-unused-private-class-members.md +126 -0
  81. package/rules/js/no-unused-vars.md +69 -0
  82. package/rules/js/no-useless-assignment.md +115 -0
  83. package/rules/js/no-useless-backreference.md +83 -0
  84. package/rules/js/no-useless-catch.md +105 -0
  85. package/rules/js/no-useless-escape.md +81 -0
  86. package/rules/js/no-var.md +76 -0
  87. package/rules/js/no-with.md +60 -0
  88. package/rules/js/prefer-const.md +83 -0
  89. package/rules/js/prefer-rest-params.md +103 -0
  90. package/rules/js/prefer-spread.md +95 -0
  91. package/rules/js/preserve-caught-error.md +122 -0
  92. package/rules/js/require-yield.md +107 -0
  93. package/rules/js/use-isnan.md +105 -0
  94. package/rules/js/valid-typeof.md +111 -0
  95. package/rules/node/hashbang.md +71 -0
  96. package/rules/node/no-deprecated-api.md +91 -0
  97. package/rules/node/no-exports-assign.md +92 -0
  98. package/rules/node/no-extraneous-import.md +118 -0
  99. package/rules/node/no-extraneous-require.md +117 -0
  100. package/rules/node/no-missing-import.md +118 -0
  101. package/rules/node/no-missing-require.md +117 -0
  102. package/rules/node/no-process-exit.md +99 -0
  103. package/rules/node/no-unpublished-import.md +134 -0
  104. package/rules/node/no-unpublished-require.md +133 -0
  105. package/rules/react/display-name.md +91 -0
  106. package/rules/react/exhaustive-deps.md +116 -0
  107. package/rules/react/hook-prefix.md +108 -0
  108. package/rules/react/jsx-key.md +99 -0
  109. package/rules/react/jsx-no-comment-textnodes.md +87 -0
  110. package/rules/react/jsx-no-duplicate-props.md +66 -0
  111. package/rules/react/jsx-no-target-blank.md +78 -0
  112. package/rules/react/jsx-no-undef.md +78 -0
  113. package/rules/react/no-children-prop.md +80 -0
  114. package/rules/react/no-danger-with-children.md +83 -0
  115. package/rules/react/no-deprecated.md +84 -0
  116. package/rules/react/no-direct-mutation-state.md +102 -0
  117. package/rules/react/no-find-dom-node.md +72 -0
  118. package/rules/react/no-is-mounted.md +109 -0
  119. package/rules/react/no-render-return-value.md +75 -0
  120. package/rules/react/no-string-refs.md +72 -0
  121. package/rules/react/no-unescaped-entities.md +69 -0
  122. package/rules/react/no-unknown-property.md +69 -0
  123. package/rules/react/props-type-name.md +43 -0
  124. package/rules/react/require-render-return.md +91 -0
  125. package/rules/react/rules-of-hooks.md +128 -0
  126. package/rules/stencil/ban-default-true.md +70 -0
  127. package/rules/stencil/ban-exported-const-enums.md +60 -0
  128. package/rules/stencil/ban-prefix.md +76 -0
  129. package/rules/stencil/decorators-context.md +61 -0
  130. package/rules/stencil/host-data-deprecated.md +73 -0
  131. package/rules/stencil/methods-must-be-public.md +69 -0
  132. package/rules/stencil/no-unused-watch.md +68 -0
  133. package/rules/stencil/own-methods-must-be-private.md +68 -0
  134. package/rules/stencil/own-props-must-be-private.md +60 -0
  135. package/rules/stencil/prefer-vdom-listener.md +67 -0
  136. package/rules/stencil/prop-readonly.md +63 -0
  137. package/rules/stencil/props-must-be-public.md +68 -0
  138. package/rules/stencil/required-jsdoc.md +66 -0
  139. package/rules/stencil/reserved-member-names.md +70 -0
  140. package/rules/stencil/strict-mutable.md +75 -0
  141. package/rules/stencil/tag-prefix.md +75 -0
  142. package/rules/ts/ban-ts-comment.md +64 -0
  143. package/rules/ts/no-array-constructor.md +58 -0
  144. package/rules/ts/no-duplicate-enum-values.md +65 -0
  145. package/rules/ts/no-empty-object-type.md +65 -0
  146. package/rules/ts/no-explicit-any.md +61 -0
  147. package/rules/ts/no-extra-non-null-assertion.md +50 -0
  148. package/rules/ts/no-misused-new.md +70 -0
  149. package/rules/ts/no-namespace.md +65 -0
  150. package/rules/ts/no-non-null-asserted-optional-chain.md +55 -0
  151. package/rules/ts/no-require-imports.md +54 -0
  152. package/rules/ts/no-this-alias.md +68 -0
  153. package/rules/ts/no-unnecessary-type-constraint.md +64 -0
  154. package/rules/ts/no-unsafe-declaration-merging.md +73 -0
  155. package/rules/ts/no-unsafe-function-type.md +57 -0
  156. package/rules/ts/no-unused-expressions.md +61 -0
  157. package/rules/ts/no-unused-vars.md +68 -0
  158. package/rules/ts/no-wrapper-object-types.md +49 -0
  159. package/rules/ts/prefer-as-const.md +47 -0
  160. package/rules/ts/prefer-namespace-keyword.md +63 -0
  161. package/rules/ts/triple-slash-reference.md +60 -0
  162. package/rules/ts/type-only-imports.md +57 -0
@@ -0,0 +1,69 @@
1
+ ---
2
+ id: js/no-unused-vars
3
+ title: "Every declared name is used"
4
+ languages: [javascript, jsx]
5
+ fix: manual
6
+ fix_reason: "removing a declaration can drop the side effects of its initialiser"
7
+ stability: preview
8
+ options:
9
+ vars: { type: string, default: all, description: "all, or local to skip module-level names" }
10
+ args: { type: string, default: after-used, description: "after-used, all or none" }
11
+ caughtErrors: { type: string, default: all, description: "all or none" }
12
+ ignoreRestSiblings: { type: boolean, default: false }
13
+ varsIgnorePattern: { type: string, description: "a regular expression of names to skip" }
14
+ argsIgnorePattern: { type: string }
15
+ caughtErrorsIgnorePattern: { type: string }
16
+ destructuredArrayIgnorePattern: { type: string }
17
+ ported_from: [eslint/no-unused-vars]
18
+ since: 0.1.0
19
+ ---
20
+
21
+ Every variable, function, class, import, parameter and caught error is read somewhere. Parameters
22
+ before the last used one are allowed (`args: after-used`).
23
+
24
+ **Why:** An unused declaration is either dead code or a sign the code doesn't do what it was meant
25
+ to.
26
+
27
+ ```codelaw
28
+ native: js/no-unused-vars
29
+ ```
30
+
31
+ ## How to fix
32
+
33
+ 1. Check the initialiser has no side effect that matters.
34
+ 2. Remove the declaration, or use it where it was meant to be used.
35
+ 3. For a parameter that must stay for its position, prefix it with `_` and set `argsIgnorePattern: "^_"`.
36
+
37
+ ## Examples
38
+
39
+ ### JavaScript
40
+
41
+ #### Don't
42
+
43
+ ```js
44
+ import { readFile, writeFile } from "node:fs";
45
+ export const load = (path) => readFile(path);
46
+ ```
47
+
48
+ #### Do
49
+
50
+ ```js
51
+ import { readFile } from "node:fs";
52
+ export const load = (path) => readFile(path);
53
+ ```
54
+
55
+ ### JSX
56
+
57
+ #### Don't
58
+
59
+ ```jsx
60
+ import { readFile, writeFile } from "node:fs";
61
+ export const load = (path) => readFile(path);
62
+ ```
63
+
64
+ #### Do
65
+
66
+ ```jsx
67
+ import { readFile } from "node:fs";
68
+ export const load = (path) => readFile(path);
69
+ ```
@@ -0,0 +1,115 @@
1
+ ---
2
+ id: js/no-useless-assignment
3
+ title: "No value is stored that nothing reads"
4
+ languages: [javascript, jsx, typescript, tsx]
5
+ fix: manual
6
+ fix_reason: "whether the store is dead or the read is missing needs the author"
7
+ stability: preview
8
+ ported_from: [eslint/no-useless-assignment]
9
+ since: 0.1.0
10
+ ---
11
+
12
+ A variable is not assigned a value that is overwritten before anything reads it, or that nothing
13
+ reads after the assignment.
14
+
15
+ **Why:** A dead store is wasted work and usually means the code reads the wrong variable.
16
+
17
+ ```codelaw
18
+ native: js/no-useless-assignment
19
+ ```
20
+
21
+ ## How to fix
22
+
23
+ 1. If the value is not needed, remove the assignment.
24
+ 2. If it should be read, read it where it was meant to be used.
25
+
26
+ ## Examples
27
+
28
+ ### JavaScript
29
+
30
+ #### Don't
31
+
32
+ ```js
33
+ function total(items) {
34
+ let sum = 0;
35
+ sum = items.length;
36
+ return sum;
37
+ }
38
+ ```
39
+
40
+ #### Do
41
+
42
+ ```js
43
+ function total(items) {
44
+ const sum = items.length;
45
+ return sum;
46
+ }
47
+ ```
48
+
49
+ ### JSX
50
+
51
+ #### Don't
52
+
53
+ ```jsx
54
+ function total(items) {
55
+ let sum = 0;
56
+ sum = items.length;
57
+ return sum;
58
+ }
59
+ ```
60
+
61
+ #### Do
62
+
63
+ ```jsx
64
+ function total(items) {
65
+ const sum = items.length;
66
+ return sum;
67
+ }
68
+ ```
69
+
70
+ ### TypeScript
71
+
72
+ #### Don't
73
+
74
+ ```ts
75
+ function total(items) {
76
+ let sum = 0;
77
+ sum = items.length;
78
+ return sum;
79
+ }
80
+ ```
81
+
82
+ #### Do
83
+
84
+ ```ts
85
+ function total(items) {
86
+ const sum = items.length;
87
+ return sum;
88
+ }
89
+ ```
90
+
91
+ ### TSX
92
+
93
+ #### Don't
94
+
95
+ ```tsx
96
+ function total(items) {
97
+ let sum = 0;
98
+ sum = items.length;
99
+ return sum;
100
+ }
101
+ ```
102
+
103
+ #### Do
104
+
105
+ ```tsx
106
+ function total(items) {
107
+ const sum = items.length;
108
+ return sum;
109
+ }
110
+ ```
111
+
112
+ ## Differences from the source
113
+
114
+ Only stores a straight-line reading proves dead are reported: an overwrite in the same block, or a
115
+ last assignment outside any loop. A variable a nested function touches is skipped.
@@ -0,0 +1,83 @@
1
+ ---
2
+ id: js/no-useless-backreference
3
+ title: "No backreference that can only match the empty string"
4
+ languages: [javascript, jsx, typescript, tsx]
5
+ fix: manual
6
+ fix_reason: "what the reference was meant to repeat needs the author"
7
+ stability: preview
8
+ ported_from: [eslint/no-useless-backreference]
9
+ since: 0.1.0
10
+ ---
11
+
12
+ A backreference such as `\1` or `\k<name>` appears after its group closes, in the same alternative,
13
+ and not into a negative lookaround.
14
+
15
+ **Why:** A backreference that comes first, sits inside its own group or in another alternative
16
+ always matches the empty string.
17
+
18
+ ```codelaw
19
+ native: js/no-useless-backreference
20
+ ```
21
+
22
+ ## How to fix
23
+
24
+ 1. Move the backreference after the group it refers to.
25
+ 2. Or remove it if it was meant to be literal text.
26
+
27
+ ## Examples
28
+
29
+ ### JavaScript
30
+
31
+ #### Don't
32
+
33
+ ```js
34
+ const re = /\1(a)/;
35
+ ```
36
+
37
+ #### Do
38
+
39
+ ```js
40
+ const re = /(a)\1/;
41
+ ```
42
+
43
+ ### JSX
44
+
45
+ #### Don't
46
+
47
+ ```jsx
48
+ const re = /\1(a)/;
49
+ ```
50
+
51
+ #### Do
52
+
53
+ ```jsx
54
+ const re = /(a)\1/;
55
+ ```
56
+
57
+ ### TypeScript
58
+
59
+ #### Don't
60
+
61
+ ```ts
62
+ const re = /\1(a)/;
63
+ ```
64
+
65
+ #### Do
66
+
67
+ ```ts
68
+ const re = /(a)\1/;
69
+ ```
70
+
71
+ ### TSX
72
+
73
+ #### Don't
74
+
75
+ ```tsx
76
+ const re = /\1(a)/;
77
+ ```
78
+
79
+ #### Do
80
+
81
+ ```tsx
82
+ const re = /(a)\1/;
83
+ ```
@@ -0,0 +1,105 @@
1
+ ---
2
+ id: js/no-useless-catch
3
+ title: "No catch that only rethrows"
4
+ languages: [javascript, jsx, typescript, tsx]
5
+ fix: manual
6
+ fix_reason: "removing the try block changes the scope of declarations inside it"
7
+ stability: preview
8
+ ported_from: [eslint/no-useless-catch]
9
+ since: 0.1.0
10
+ ---
11
+
12
+ A `catch` clause does more than rethrow the error it caught.
13
+
14
+ **Why:** `catch (e) { throw e; }` does nothing but add noise and a level of nesting.
15
+
16
+ ```codelaw
17
+ match:
18
+ kind: catch_clause
19
+ all:
20
+ - has: { field: parameter, pattern: $E }
21
+ - has:
22
+ field: body
23
+ regex: ^\{\s*throw\s+[A-Za-z_$][A-Za-z0-9_$]*\s*;?\s*\}$
24
+ has: { kind: throw_statement, has: { pattern: $E }, stopBy: end }
25
+ message: "This catch only rethrows `$E`; remove it"
26
+ ```
27
+
28
+ ## How to fix
29
+
30
+ 1. If there is no `finally`, replace the `try` statement with the statements of its block.
31
+ 2. If there is a `finally`, remove only the `catch` clause.
32
+
33
+ ## Examples
34
+
35
+ ### JavaScript
36
+
37
+ #### Don't
38
+
39
+ ```js
40
+ try {
41
+ load();
42
+ } catch (e) {
43
+ throw e;
44
+ }
45
+ ```
46
+
47
+ #### Do
48
+
49
+ ```js
50
+ load();
51
+ ```
52
+
53
+ ### JSX
54
+
55
+ #### Don't
56
+
57
+ ```jsx
58
+ try {
59
+ load();
60
+ } catch (e) {
61
+ throw e;
62
+ }
63
+ ```
64
+
65
+ #### Do
66
+
67
+ ```jsx
68
+ load();
69
+ ```
70
+
71
+ ### TypeScript
72
+
73
+ #### Don't
74
+
75
+ ```ts
76
+ try {
77
+ load();
78
+ } catch (e) {
79
+ throw e;
80
+ }
81
+ ```
82
+
83
+ #### Do
84
+
85
+ ```ts
86
+ load();
87
+ ```
88
+
89
+ ### TSX
90
+
91
+ #### Don't
92
+
93
+ ```tsx
94
+ try {
95
+ load();
96
+ } catch (e) {
97
+ throw e;
98
+ }
99
+ ```
100
+
101
+ #### Do
102
+
103
+ ```tsx
104
+ load();
105
+ ```
@@ -0,0 +1,81 @@
1
+ ---
2
+ id: js/no-useless-escape
3
+ title: "No backslash that changes nothing"
4
+ languages: [javascript, jsx, typescript, tsx]
5
+ fix: auto
6
+ stability: preview
7
+ ported_from: [eslint/no-useless-escape]
8
+ since: 0.1.0
9
+ ---
10
+
11
+ A string or template literal escapes only characters that need it: quotes that match the delimiter,
12
+ `\\`, line breaks and the escape letters.
13
+
14
+ **Why:** A useless escape suggests the author meant something else, and makes the string harder to
15
+ read.
16
+
17
+ ```codelaw
18
+ native: js/no-useless-escape
19
+ ```
20
+
21
+ ## Examples
22
+
23
+ ### JavaScript
24
+
25
+ #### Don't
26
+
27
+ ```js
28
+ const path = "a\.b";
29
+ ```
30
+
31
+ #### Do
32
+
33
+ ```js
34
+ const path = "a.b";
35
+ ```
36
+
37
+ ### JSX
38
+
39
+ #### Don't
40
+
41
+ ```jsx
42
+ const path = "a\.b";
43
+ ```
44
+
45
+ #### Do
46
+
47
+ ```jsx
48
+ const path = "a.b";
49
+ ```
50
+
51
+ ### TypeScript
52
+
53
+ #### Don't
54
+
55
+ ```ts
56
+ const path = "a\.b";
57
+ ```
58
+
59
+ #### Do
60
+
61
+ ```ts
62
+ const path = "a.b";
63
+ ```
64
+
65
+ ### TSX
66
+
67
+ #### Don't
68
+
69
+ ```tsx
70
+ const path = "a\.b";
71
+ ```
72
+
73
+ #### Do
74
+
75
+ ```tsx
76
+ const path = "a.b";
77
+ ```
78
+
79
+ ## Differences from the source
80
+
81
+ Escapes inside regular expressions are not checked yet. A tagged template (`String.raw`, `html`) is not checked: its tag sees the raw text, backslashes included, as in ESLint.
@@ -0,0 +1,76 @@
1
+ ---
2
+ id: js/no-var
3
+ title: "let or const instead of var"
4
+ languages: [javascript, jsx, typescript, tsx]
5
+ fix: suggest
6
+ fix_reason: "`let` is block-scoped, so a `var` used outside its block or before its declaration changes meaning"
7
+ stability: preview
8
+ ported_from: [eslint/no-var]
9
+ since: 0.1.0
10
+ ---
11
+
12
+ Variables are declared with `let` or `const`, never `var`.
13
+
14
+ **Why:** `var` is function-scoped and hoisted, which causes bugs `let` and `const` rule out.
15
+
16
+ ```codelaw
17
+ native: js/no-var
18
+ ```
19
+
20
+ ## Examples
21
+
22
+ ### JavaScript
23
+
24
+ #### Don't
25
+
26
+ ```js
27
+ var total = 0;
28
+ ```
29
+
30
+ #### Do
31
+
32
+ ```js
33
+ let total = 0;
34
+ ```
35
+
36
+ ### JSX
37
+
38
+ #### Don't
39
+
40
+ ```jsx
41
+ var total = 0;
42
+ ```
43
+
44
+ #### Do
45
+
46
+ ```jsx
47
+ let total = 0;
48
+ ```
49
+
50
+ ### TypeScript
51
+
52
+ #### Don't
53
+
54
+ ```ts
55
+ var total = 0;
56
+ ```
57
+
58
+ #### Do
59
+
60
+ ```ts
61
+ let total = 0;
62
+ ```
63
+
64
+ ### TSX
65
+
66
+ #### Don't
67
+
68
+ ```tsx
69
+ var total = 0;
70
+ ```
71
+
72
+ #### Do
73
+
74
+ ```tsx
75
+ let total = 0;
76
+ ```
@@ -0,0 +1,60 @@
1
+ ---
2
+ id: js/no-with
3
+ title: "No with statements"
4
+ languages: [javascript, jsx]
5
+ fix: manual
6
+ fix_reason: "each name inside needs to be qualified by hand"
7
+ stability: preview
8
+ ported_from: [eslint/no-with]
9
+ since: 0.1.0
10
+ ---
11
+
12
+ Code doesn't use `with`.
13
+
14
+ **Why:** `with` makes it impossible to tell which names are properties and which are variables, and
15
+ is an error in strict code.
16
+
17
+ ```codelaw
18
+ match:
19
+ kind: with_statement
20
+ message: "`with` makes every name inside it ambiguous"
21
+ ```
22
+
23
+ ## How to fix
24
+
25
+ 1. Replace each property used inside `with` by `object.property`.
26
+ 2. Remove the `with`.
27
+
28
+ ## Examples
29
+
30
+ ### JavaScript
31
+
32
+ #### Don't
33
+
34
+ ```js
35
+ with (Math) {
36
+ area = PI * r * r;
37
+ }
38
+ ```
39
+
40
+ #### Do
41
+
42
+ ```js
43
+ area = Math.PI * r * r;
44
+ ```
45
+
46
+ ### JSX
47
+
48
+ #### Don't
49
+
50
+ ```jsx
51
+ with (Math) {
52
+ area = PI * r * r;
53
+ }
54
+ ```
55
+
56
+ #### Do
57
+
58
+ ```jsx
59
+ area = Math.PI * r * r;
60
+ ```
@@ -0,0 +1,83 @@
1
+ ---
2
+ id: js/prefer-const
3
+ title: "const for variables that are never reassigned"
4
+ languages: [javascript, jsx, typescript, tsx]
5
+ fix: auto
6
+ stability: preview
7
+ ported_from: [eslint/prefer-const]
8
+ since: 0.1.0
9
+ ---
10
+
11
+ A `let` whose names all get their value in the declaration and are never reassigned is a `const`.
12
+
13
+ **Why:** `const` tells the reader the binding won't change, and the engine enforces it.
14
+
15
+ ```codelaw
16
+ native: js/prefer-const
17
+ ```
18
+
19
+ ## Examples
20
+
21
+ ### JavaScript
22
+
23
+ #### Don't
24
+
25
+ ```js
26
+ let limit = 10;
27
+ use(limit);
28
+ ```
29
+
30
+ #### Do
31
+
32
+ ```js
33
+ const limit = 10;
34
+ use(limit);
35
+ ```
36
+
37
+ ### JSX
38
+
39
+ #### Don't
40
+
41
+ ```jsx
42
+ let limit = 10;
43
+ use(limit);
44
+ ```
45
+
46
+ #### Do
47
+
48
+ ```jsx
49
+ const limit = 10;
50
+ use(limit);
51
+ ```
52
+
53
+ ### TypeScript
54
+
55
+ #### Don't
56
+
57
+ ```ts
58
+ let limit = 10;
59
+ use(limit);
60
+ ```
61
+
62
+ #### Do
63
+
64
+ ```ts
65
+ const limit = 10;
66
+ use(limit);
67
+ ```
68
+
69
+ ### TSX
70
+
71
+ #### Don't
72
+
73
+ ```tsx
74
+ let limit = 10;
75
+ use(limit);
76
+ ```
77
+
78
+ #### Do
79
+
80
+ ```tsx
81
+ const limit = 10;
82
+ use(limit);
83
+ ```