@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,113 @@
1
+ ---
2
+ id: js/no-dupe-else-if
3
+ title: "No two conditions in an if/else-if chain are the same"
4
+ languages: [javascript, jsx, typescript, tsx]
5
+ fix: manual
6
+ fix_reason: "what the second condition should have been is a decision"
7
+ stability: preview
8
+ ported_from: [eslint/no-dupe-else-if]
9
+ since: 0.1.0
10
+ ---
11
+
12
+ Each condition in an `if … else if …` chain is different from the ones before it.
13
+
14
+ **Why:** A repeated condition's branch can never run, because the earlier one already took it.
15
+
16
+ ```codelaw
17
+ native: js/no-dupe-else-if
18
+ ```
19
+
20
+ ## How to fix
21
+
22
+ 1. Find the repeated condition.
23
+ 2. Correct it to the case it was meant to handle, or remove the dead branch.
24
+
25
+ ## Examples
26
+
27
+ ### JavaScript
28
+
29
+ #### Don't
30
+
31
+ ```js
32
+ if (isAdmin) {
33
+ grant();
34
+ } else if (isAdmin) {
35
+ audit();
36
+ }
37
+ ```
38
+
39
+ #### Do
40
+
41
+ ```js
42
+ if (isAdmin) {
43
+ grant();
44
+ } else if (isAuditor) {
45
+ audit();
46
+ }
47
+ ```
48
+
49
+ ### JSX
50
+
51
+ #### Don't
52
+
53
+ ```jsx
54
+ if (isAdmin) {
55
+ grant();
56
+ } else if (isAdmin) {
57
+ audit();
58
+ }
59
+ ```
60
+
61
+ #### Do
62
+
63
+ ```jsx
64
+ if (isAdmin) {
65
+ grant();
66
+ } else if (isAuditor) {
67
+ audit();
68
+ }
69
+ ```
70
+
71
+ ### TypeScript
72
+
73
+ #### Don't
74
+
75
+ ```ts
76
+ if (isAdmin) {
77
+ grant();
78
+ } else if (isAdmin) {
79
+ audit();
80
+ }
81
+ ```
82
+
83
+ #### Do
84
+
85
+ ```ts
86
+ if (isAdmin) {
87
+ grant();
88
+ } else if (isAuditor) {
89
+ audit();
90
+ }
91
+ ```
92
+
93
+ ### TSX
94
+
95
+ #### Don't
96
+
97
+ ```tsx
98
+ if (isAdmin) {
99
+ grant();
100
+ } else if (isAdmin) {
101
+ audit();
102
+ }
103
+ ```
104
+
105
+ #### Do
106
+
107
+ ```tsx
108
+ if (isAdmin) {
109
+ grant();
110
+ } else if (isAuditor) {
111
+ audit();
112
+ }
113
+ ```
@@ -0,0 +1,66 @@
1
+ ---
2
+ id: js/no-dupe-keys
3
+ title: "No two keys in an object literal are the same"
4
+ languages: [javascript, jsx]
5
+ fix: manual
6
+ fix_reason: "which value should win can't be known from the code"
7
+ stability: preview
8
+ ported_from: [eslint/no-dupe-keys]
9
+ since: 0.1.0
10
+ ---
11
+
12
+ An object literal names each key once; `a`, `'a'` and `["a"]` are the same key, as are `1` and
13
+ `0x1`.
14
+
15
+ **Why:** The later value silently replaces the earlier one.
16
+
17
+ ```codelaw
18
+ native: js/no-dupe-keys
19
+ ```
20
+
21
+ ## How to fix
22
+
23
+ 1. Decide which value the key should have.
24
+ 2. Remove the other entry, or give it its own key.
25
+
26
+ ## Examples
27
+
28
+ ### JavaScript
29
+
30
+ #### Don't
31
+
32
+ ```js
33
+ const user = {
34
+ name: "Ada",
35
+ name: "Grace",
36
+ };
37
+ ```
38
+
39
+ #### Do
40
+
41
+ ```js
42
+ const user = {
43
+ name: "Ada",
44
+ nickname: "Grace",
45
+ };
46
+ ```
47
+
48
+ ### JSX
49
+
50
+ #### Don't
51
+
52
+ ```jsx
53
+ const user = {
54
+ name: "Ada",
55
+ name: "Grace",
56
+ };
57
+ ```
58
+
59
+ #### Do
60
+
61
+ ```jsx
62
+ const user = {
63
+ name: "Ada",
64
+ nickname: "Grace",
65
+ };
66
+ ```
@@ -0,0 +1,137 @@
1
+ ---
2
+ id: js/no-duplicate-case
3
+ title: "No two case labels in a switch are the same"
4
+ languages: [javascript, jsx, typescript, tsx]
5
+ fix: manual
6
+ fix_reason: "which label was meant is a decision"
7
+ stability: preview
8
+ ported_from: [eslint/no-duplicate-case]
9
+ since: 0.1.0
10
+ ---
11
+
12
+ Each `case` in a `switch` tests a different expression.
13
+
14
+ **Why:** A repeated case can never match: the first one always wins.
15
+
16
+ ```codelaw
17
+ native: js/no-duplicate-case
18
+ ```
19
+
20
+ ## How to fix
21
+
22
+ 1. Find the label that was meant to test something else.
23
+ 2. Correct it, or merge the two bodies.
24
+
25
+ ## Examples
26
+
27
+ ### JavaScript
28
+
29
+ #### Don't
30
+
31
+ ```js
32
+ switch (status) {
33
+ case 200:
34
+ ok();
35
+ break;
36
+ case 200:
37
+ retry();
38
+ break;
39
+ }
40
+ ```
41
+
42
+ #### Do
43
+
44
+ ```js
45
+ switch (status) {
46
+ case 200:
47
+ ok();
48
+ break;
49
+ case 503:
50
+ retry();
51
+ break;
52
+ }
53
+ ```
54
+
55
+ ### JSX
56
+
57
+ #### Don't
58
+
59
+ ```jsx
60
+ switch (status) {
61
+ case 200:
62
+ ok();
63
+ break;
64
+ case 200:
65
+ retry();
66
+ break;
67
+ }
68
+ ```
69
+
70
+ #### Do
71
+
72
+ ```jsx
73
+ switch (status) {
74
+ case 200:
75
+ ok();
76
+ break;
77
+ case 503:
78
+ retry();
79
+ break;
80
+ }
81
+ ```
82
+
83
+ ### TypeScript
84
+
85
+ #### Don't
86
+
87
+ ```ts
88
+ switch (status) {
89
+ case 200:
90
+ ok();
91
+ break;
92
+ case 200:
93
+ retry();
94
+ break;
95
+ }
96
+ ```
97
+
98
+ #### Do
99
+
100
+ ```ts
101
+ switch (status) {
102
+ case 200:
103
+ ok();
104
+ break;
105
+ case 503:
106
+ retry();
107
+ break;
108
+ }
109
+ ```
110
+
111
+ ### TSX
112
+
113
+ #### Don't
114
+
115
+ ```tsx
116
+ switch (status) {
117
+ case 200:
118
+ ok();
119
+ break;
120
+ case 200:
121
+ retry();
122
+ break;
123
+ }
124
+ ```
125
+
126
+ #### Do
127
+
128
+ ```tsx
129
+ switch (status) {
130
+ case 200:
131
+ ok();
132
+ break;
133
+ case 503:
134
+ retry();
135
+ break;
136
+ }
137
+ ```
@@ -0,0 +1,98 @@
1
+ ---
2
+ id: js/no-empty-character-class
3
+ title: "No empty character classes in regular expressions"
4
+ languages: [javascript, jsx, typescript, tsx]
5
+ fix: manual
6
+ fix_reason: "which characters the class should hold needs the author"
7
+ stability: preview
8
+ ported_from: [eslint/no-empty-character-class]
9
+ since: 0.1.0
10
+ ---
11
+
12
+ A regular expression contains no empty character class `[]`; `[^]`, which matches any character, is
13
+ fine.
14
+
15
+ **Why:** `[]` matches no character at all, so the whole pattern can never match.
16
+
17
+ ```codelaw
18
+ native: js/no-empty-character-class
19
+ ```
20
+
21
+ ## How to fix
22
+
23
+ 1. Put the characters the class should match inside it.
24
+ 2. If `[]` was meant literally, escape it: `\[\]`.
25
+
26
+ ## Examples
27
+
28
+ ### JavaScript
29
+
30
+ #### Don't
31
+
32
+ ```js
33
+ const re = /^abc[]/;
34
+ ```
35
+
36
+ #### Do
37
+
38
+ ```js
39
+ const re = /^abc[a-z]/;
40
+ ```
41
+
42
+ ```js
43
+ const brackets = /^\s*[{[]/;
44
+ ```
45
+
46
+ ### JSX
47
+
48
+ #### Don't
49
+
50
+ ```jsx
51
+ const re = /^abc[]/;
52
+ ```
53
+
54
+ #### Do
55
+
56
+ ```jsx
57
+ const re = /^abc[a-z]/;
58
+ ```
59
+
60
+ ```jsx
61
+ const brackets = /^\s*[{[]/;
62
+ ```
63
+
64
+ ### TypeScript
65
+
66
+ #### Don't
67
+
68
+ ```ts
69
+ const re = /^abc[]/;
70
+ ```
71
+
72
+ #### Do
73
+
74
+ ```ts
75
+ const re = /^abc[a-z]/;
76
+ ```
77
+
78
+ ```ts
79
+ const brackets = /^\s*[{[]/;
80
+ ```
81
+
82
+ ### TSX
83
+
84
+ #### Don't
85
+
86
+ ```tsx
87
+ const re = /^abc[]/;
88
+ ```
89
+
90
+ #### Do
91
+
92
+ ```tsx
93
+ const re = /^abc[a-z]/;
94
+ ```
95
+
96
+ ```tsx
97
+ const brackets = /^\s*[{[]/;
98
+ ```
@@ -0,0 +1,86 @@
1
+ ---
2
+ id: js/no-empty-pattern
3
+ title: "No empty destructuring patterns"
4
+ languages: [javascript, jsx, typescript, tsx]
5
+ fix: manual
6
+ fix_reason: "what the pattern was meant to bind needs the author"
7
+ stability: preview
8
+ ported_from: [eslint/no-empty-pattern]
9
+ since: 0.1.0
10
+ ---
11
+
12
+ A destructuring pattern names at least one binding.
13
+
14
+ **Why:** `const {} = obj` binds nothing; it's usually a mistyped default such as `{ a = {} }`.
15
+
16
+ ```codelaw
17
+ match:
18
+ any:
19
+ - kind: object_pattern
20
+ regex: ^\{\s*\}$
21
+ - kind: array_pattern
22
+ regex: ^\[\s*\]$
23
+ message: "This destructuring pattern binds nothing"
24
+ ```
25
+
26
+ ## How to fix
27
+
28
+ 1. Name the properties to bind inside the pattern, or remove it.
29
+
30
+ ## Examples
31
+
32
+ ### JavaScript
33
+
34
+ #### Don't
35
+
36
+ ```js
37
+ const { a: {} } = options;
38
+ ```
39
+
40
+ #### Do
41
+
42
+ ```js
43
+ const { a = {} } = options;
44
+ ```
45
+
46
+ ### JSX
47
+
48
+ #### Don't
49
+
50
+ ```jsx
51
+ const { a: {} } = options;
52
+ ```
53
+
54
+ #### Do
55
+
56
+ ```jsx
57
+ const { a = {} } = options;
58
+ ```
59
+
60
+ ### TypeScript
61
+
62
+ #### Don't
63
+
64
+ ```ts
65
+ const { a: {} } = options;
66
+ ```
67
+
68
+ #### Do
69
+
70
+ ```ts
71
+ const { a = {} } = options;
72
+ ```
73
+
74
+ ### TSX
75
+
76
+ #### Don't
77
+
78
+ ```tsx
79
+ const { a: {} } = options;
80
+ ```
81
+
82
+ #### Do
83
+
84
+ ```tsx
85
+ const { a = {} } = options;
86
+ ```
@@ -0,0 +1,99 @@
1
+ ---
2
+ id: js/no-empty-static-block
3
+ title: "No empty static blocks"
4
+ languages: [javascript, jsx, typescript, tsx]
5
+ fix: auto
6
+ stability: preview
7
+ ported_from: [eslint/no-empty-static-block]
8
+ since: 0.1.0
9
+ ---
10
+
11
+ A class has no empty `static { }` block.
12
+
13
+ **Why:** An empty static block does nothing; it is leftover or unfinished code.
14
+
15
+ ```codelaw
16
+ match:
17
+ kind: class_static_block
18
+ regex: ^static\s*\{\s*\}$
19
+ message: "Empty static block"
20
+ fix: [remove]
21
+ ```
22
+
23
+ ## Examples
24
+
25
+ ### JavaScript
26
+
27
+ #### Don't
28
+
29
+ ```js
30
+ class Config {
31
+ static {}
32
+ load() {}
33
+ }
34
+ ```
35
+
36
+ #### Do
37
+
38
+ ```js
39
+ class Config {
40
+ load() {}
41
+ }
42
+ ```
43
+
44
+ ### JSX
45
+
46
+ #### Don't
47
+
48
+ ```jsx
49
+ class Config {
50
+ static {}
51
+ load() {}
52
+ }
53
+ ```
54
+
55
+ #### Do
56
+
57
+ ```jsx
58
+ class Config {
59
+ load() {}
60
+ }
61
+ ```
62
+
63
+ ### TypeScript
64
+
65
+ #### Don't
66
+
67
+ ```ts
68
+ class Config {
69
+ static {}
70
+ load() {}
71
+ }
72
+ ```
73
+
74
+ #### Do
75
+
76
+ ```ts
77
+ class Config {
78
+ load() {}
79
+ }
80
+ ```
81
+
82
+ ### TSX
83
+
84
+ #### Don't
85
+
86
+ ```tsx
87
+ class Config {
88
+ static {}
89
+ load() {}
90
+ }
91
+ ```
92
+
93
+ #### Do
94
+
95
+ ```tsx
96
+ class Config {
97
+ load() {}
98
+ }
99
+ ```
@@ -0,0 +1,116 @@
1
+ ---
2
+ id: js/no-empty
3
+ title: "No empty blocks"
4
+ languages: [javascript, jsx, typescript, tsx]
5
+ fix: manual
6
+ fix_reason: "whether to fill the block, remove it or document it needs the author"
7
+ stability: preview
8
+ ported_from: [eslint/no-empty]
9
+ since: 0.1.0
10
+ ---
11
+
12
+ A block or `switch` has at least one statement, or a comment saying why it is empty. Function bodies
13
+ may be empty.
14
+
15
+ **Why:** An empty block is usually unfinished code, and an empty `catch` hides errors.
16
+
17
+ ```codelaw
18
+ match:
19
+ any:
20
+ - kind: statement_block
21
+ regex: ^\{\s*\}$
22
+ not:
23
+ inside:
24
+ stopBy: neighbor
25
+ any: [{kind: function_declaration}, {kind: function_expression}, {kind: arrow_function}, {kind: method_definition}, {kind: generator_function_declaration}, {kind: generator_function}, { kind: class_static_block }]
26
+ - kind: switch_statement
27
+ has: { field: body, regex: '^\{\s*\}$' }
28
+ message: "Empty block; remove it or say why it's empty"
29
+ ```
30
+
31
+ ## How to fix
32
+
33
+ 1. If the block is unfinished, write its code.
34
+ 2. If it's meant to be empty, put a comment in it saying why.
35
+
36
+ ## Examples
37
+
38
+ ### JavaScript
39
+
40
+ #### Don't
41
+
42
+ ```js
43
+ try {
44
+ load();
45
+ } catch (e) {}
46
+ ```
47
+
48
+ #### Do
49
+
50
+ ```js
51
+ try {
52
+ load();
53
+ } catch (e) {
54
+ // The cache is optional: a failed load is not an error.
55
+ }
56
+ ```
57
+
58
+ ### JSX
59
+
60
+ #### Don't
61
+
62
+ ```jsx
63
+ try {
64
+ load();
65
+ } catch (e) {}
66
+ ```
67
+
68
+ #### Do
69
+
70
+ ```jsx
71
+ try {
72
+ load();
73
+ } catch (e) {
74
+ // The cache is optional: a failed load is not an error.
75
+ }
76
+ ```
77
+
78
+ ### TypeScript
79
+
80
+ #### Don't
81
+
82
+ ```ts
83
+ try {
84
+ load();
85
+ } catch (e) {}
86
+ ```
87
+
88
+ #### Do
89
+
90
+ ```ts
91
+ try {
92
+ load();
93
+ } catch (e) {
94
+ // The cache is optional: a failed load is not an error.
95
+ }
96
+ ```
97
+
98
+ ### TSX
99
+
100
+ #### Don't
101
+
102
+ ```tsx
103
+ try {
104
+ load();
105
+ } catch (e) {}
106
+ ```
107
+
108
+ #### Do
109
+
110
+ ```tsx
111
+ try {
112
+ load();
113
+ } catch (e) {
114
+ // The cache is optional: a failed load is not an error.
115
+ }
116
+ ```