@flint.fyi/ts 0.14.1 → 0.14.3

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 (221) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/lib/index.d.ts +1 -0
  3. package/lib/index.js +1 -0
  4. package/lib/nodes.d.ts +1 -0
  5. package/lib/plugin.d.ts +132 -4
  6. package/lib/plugin.js +69 -1
  7. package/lib/rules/asyncPromiseExecutors.d.ts +6 -0
  8. package/lib/rules/asyncPromiseExecutors.js +51 -0
  9. package/lib/rules/asyncPromiseExecutors.test.d.ts +1 -0
  10. package/lib/rules/asyncPromiseExecutors.test.js +71 -0
  11. package/lib/rules/caseDeclarations.d.ts +6 -0
  12. package/lib/rules/caseDeclarations.js +53 -0
  13. package/lib/rules/caseDeclarations.test.d.ts +1 -0
  14. package/lib/rules/caseDeclarations.test.js +227 -0
  15. package/lib/rules/chainedAssignments.d.ts +6 -0
  16. package/lib/rules/chainedAssignments.js +48 -0
  17. package/lib/rules/chainedAssignments.test.d.ts +1 -0
  18. package/lib/rules/chainedAssignments.test.js +238 -0
  19. package/lib/rules/classAssignments.d.ts +6 -0
  20. package/lib/rules/classAssignments.js +42 -0
  21. package/lib/rules/classAssignments.test.d.ts +1 -0
  22. package/lib/rules/classAssignments.test.js +156 -0
  23. package/lib/rules/constantAssignments.d.ts +6 -0
  24. package/lib/rules/constantAssignments.js +61 -0
  25. package/lib/rules/constantAssignments.test.d.ts +1 -0
  26. package/lib/rules/constantAssignments.test.js +221 -0
  27. package/lib/rules/constructorReturns.d.ts +6 -0
  28. package/lib/rules/constructorReturns.js +52 -0
  29. package/lib/rules/constructorReturns.test.d.ts +1 -0
  30. package/lib/rules/constructorReturns.test.js +96 -0
  31. package/lib/rules/debuggerStatements.d.ts +6 -0
  32. package/lib/rules/debuggerStatements.js +43 -0
  33. package/lib/rules/debuggerStatements.test.d.ts +1 -0
  34. package/lib/rules/debuggerStatements.test.js +80 -0
  35. package/lib/rules/defaultCaseLast.d.ts +6 -0
  36. package/lib/rules/defaultCaseLast.js +43 -0
  37. package/lib/rules/defaultCaseLast.test.d.ts +1 -0
  38. package/lib/rules/defaultCaseLast.test.js +195 -0
  39. package/lib/rules/duplicateArguments.d.ts +6 -0
  40. package/lib/rules/duplicateArguments.js +51 -0
  41. package/lib/rules/duplicateArguments.test.d.ts +1 -0
  42. package/lib/rules/duplicateArguments.test.js +139 -0
  43. package/lib/rules/emptyDestructures.d.ts +6 -0
  44. package/lib/rules/emptyDestructures.js +40 -0
  45. package/lib/rules/emptyDestructures.test.d.ts +1 -0
  46. package/lib/rules/emptyDestructures.test.js +186 -0
  47. package/lib/rules/emptyStaticBlocks.d.ts +6 -0
  48. package/lib/rules/emptyStaticBlocks.js +54 -0
  49. package/lib/rules/emptyStaticBlocks.test.d.ts +1 -0
  50. package/lib/rules/emptyStaticBlocks.test.js +167 -0
  51. package/lib/rules/exceptionAssignments.d.ts +6 -0
  52. package/lib/rules/exceptionAssignments.js +61 -0
  53. package/lib/rules/exceptionAssignments.test.d.ts +1 -0
  54. package/lib/rules/exceptionAssignments.test.js +264 -0
  55. package/lib/rules/functionAssignments.d.ts +6 -0
  56. package/lib/rules/functionAssignments.js +42 -0
  57. package/lib/rules/functionAssignments.test.d.ts +1 -0
  58. package/lib/rules/functionAssignments.test.js +209 -0
  59. package/lib/rules/generatorFunctionYields.d.ts +6 -0
  60. package/lib/rules/generatorFunctionYields.js +57 -0
  61. package/lib/rules/generatorFunctionYields.test.d.ts +1 -0
  62. package/lib/rules/generatorFunctionYields.test.js +151 -0
  63. package/lib/rules/globalAssignments.d.ts +6 -0
  64. package/lib/rules/globalAssignments.js +59 -0
  65. package/lib/rules/globalAssignments.test.d.ts +1 -0
  66. package/lib/rules/globalAssignments.test.js +215 -0
  67. package/lib/rules/globalObjectCalls.d.ts +6 -0
  68. package/lib/rules/globalObjectCalls.js +43 -0
  69. package/lib/rules/globalObjectCalls.test.d.ts +1 -0
  70. package/lib/rules/globalObjectCalls.test.js +93 -0
  71. package/lib/rules/negativeZeroComparisons.d.ts +6 -0
  72. package/lib/rules/negativeZeroComparisons.js +83 -0
  73. package/lib/rules/negativeZeroComparisons.test.d.ts +1 -0
  74. package/lib/rules/negativeZeroComparisons.test.js +209 -0
  75. package/lib/rules/newExpressions.d.ts +6 -0
  76. package/lib/rules/newExpressions.js +54 -0
  77. package/lib/rules/newExpressions.test.d.ts +1 -0
  78. package/lib/rules/newExpressions.test.js +79 -0
  79. package/lib/rules/newNativeNonConstructors.d.ts +6 -0
  80. package/lib/rules/newNativeNonConstructors.js +49 -0
  81. package/lib/rules/newNativeNonConstructors.test.d.ts +1 -0
  82. package/lib/rules/newNativeNonConstructors.test.js +94 -0
  83. package/lib/rules/objectProto.d.ts +6 -0
  84. package/lib/rules/objectProto.js +54 -0
  85. package/lib/rules/objectProto.test.d.ts +1 -0
  86. package/lib/rules/objectProto.test.js +96 -0
  87. package/lib/rules/octalEscapes.d.ts +6 -0
  88. package/lib/rules/octalEscapes.js +71 -0
  89. package/lib/rules/octalEscapes.test.d.ts +1 -0
  90. package/lib/rules/octalEscapes.test.js +213 -0
  91. package/lib/rules/octalNumbers.d.ts +6 -0
  92. package/lib/rules/octalNumbers.js +68 -0
  93. package/lib/rules/octalNumbers.test.d.ts +1 -0
  94. package/lib/rules/octalNumbers.test.js +245 -0
  95. package/lib/rules/returnAssignments.d.ts +6 -0
  96. package/lib/rules/returnAssignments.js +50 -0
  97. package/lib/rules/returnAssignments.test.d.ts +1 -0
  98. package/lib/rules/returnAssignments.test.js +185 -0
  99. package/lib/rules/sparseArrays.d.ts +6 -0
  100. package/lib/rules/sparseArrays.js +54 -0
  101. package/lib/rules/sparseArrays.test.d.ts +1 -0
  102. package/lib/rules/sparseArrays.test.js +110 -0
  103. package/lib/rules/symbolDescriptions.d.ts +6 -0
  104. package/lib/rules/symbolDescriptions.js +41 -0
  105. package/lib/rules/symbolDescriptions.test.d.ts +1 -0
  106. package/lib/rules/symbolDescriptions.test.js +89 -0
  107. package/lib/rules/unassignedVariables.d.ts +6 -0
  108. package/lib/rules/unassignedVariables.js +55 -0
  109. package/lib/rules/unassignedVariables.test.d.ts +1 -0
  110. package/lib/rules/unassignedVariables.test.js +72 -0
  111. package/lib/rules/undefinedVariables.d.ts +6 -0
  112. package/lib/rules/undefinedVariables.js +76 -0
  113. package/lib/rules/undefinedVariables.test.d.ts +1 -0
  114. package/lib/rules/undefinedVariables.test.js +80 -0
  115. package/lib/rules/unicodeBOMs.d.ts +6 -0
  116. package/lib/rules/unicodeBOMs.js +41 -0
  117. package/lib/rules/unicodeBOMs.test.d.ts +1 -0
  118. package/lib/rules/unicodeBOMs.test.js +65 -0
  119. package/lib/rules/unnecessaryCatches.d.ts +6 -0
  120. package/lib/rules/unnecessaryCatches.js +68 -0
  121. package/lib/rules/unnecessaryCatches.test.d.ts +1 -0
  122. package/lib/rules/unnecessaryCatches.test.js +210 -0
  123. package/lib/rules/unsafeNegations.d.ts +6 -0
  124. package/lib/rules/unsafeNegations.js +50 -0
  125. package/lib/rules/unsafeNegations.test.d.ts +1 -0
  126. package/lib/rules/unsafeNegations.test.js +63 -0
  127. package/lib/rules/variableDeletions.d.ts +6 -0
  128. package/lib/rules/variableDeletions.js +39 -0
  129. package/lib/rules/variableDeletions.test.d.ts +1 -0
  130. package/lib/rules/variableDeletions.test.js +75 -0
  131. package/lib/rules/voidOperator.d.ts +6 -0
  132. package/lib/rules/voidOperator.js +36 -0
  133. package/lib/rules/voidOperator.test.d.ts +1 -0
  134. package/lib/rules/voidOperator.test.js +98 -0
  135. package/lib/utils/declarationsIncludeGlobal.d.ts +2 -0
  136. package/lib/utils/declarationsIncludeGlobal.js +7 -0
  137. package/lib/utils/getModifyingReferences.d.ts +8 -0
  138. package/lib/utils/getModifyingReferences.js +42 -0
  139. package/lib/utils/isGlobalDeclaration.d.ts +2 -0
  140. package/lib/utils/isGlobalDeclaration.js +5 -0
  141. package/lib/utils/isGlobalVariable.d.ts +8 -0
  142. package/lib/utils/isGlobalVariable.js +21 -0
  143. package/lib/utils/unwrapParentParenthesizedExpressions.d.ts +2 -0
  144. package/lib/utils/unwrapParentParenthesizedExpressions.js +6 -0
  145. package/lib/utils/unwrapParenthesizedExpression.d.ts +2 -0
  146. package/lib/utils/unwrapParenthesizedExpression.js +6 -0
  147. package/package.json +1 -1
  148. package/src/index.ts +1 -0
  149. package/src/nodes.ts +1 -0
  150. package/src/plugin.ts +69 -1
  151. package/src/rules/asyncPromiseExecutors.test.ts +72 -0
  152. package/src/rules/asyncPromiseExecutors.ts +61 -0
  153. package/src/rules/caseDeclarations.test.ts +228 -0
  154. package/src/rules/caseDeclarations.ts +70 -0
  155. package/src/rules/chainedAssignments.test.ts +239 -0
  156. package/src/rules/chainedAssignments.ts +55 -0
  157. package/src/rules/classAssignments.test.ts +157 -0
  158. package/src/rules/classAssignments.ts +50 -0
  159. package/src/rules/constantAssignments.test.ts +222 -0
  160. package/src/rules/constantAssignments.ts +78 -0
  161. package/src/rules/constructorReturns.test.ts +97 -0
  162. package/src/rules/constructorReturns.ts +59 -0
  163. package/src/rules/debuggerStatements.test.ts +81 -0
  164. package/src/rules/debuggerStatements.ts +45 -0
  165. package/src/rules/defaultCaseLast.test.ts +196 -0
  166. package/src/rules/defaultCaseLast.ts +54 -0
  167. package/src/rules/duplicateArguments.test.ts +140 -0
  168. package/src/rules/duplicateArguments.ts +58 -0
  169. package/src/rules/emptyDestructures.test.ts +187 -0
  170. package/src/rules/emptyDestructures.ts +48 -0
  171. package/src/rules/emptyStaticBlocks.test.ts +168 -0
  172. package/src/rules/emptyStaticBlocks.ts +60 -0
  173. package/src/rules/exceptionAssignments.test.ts +265 -0
  174. package/src/rules/exceptionAssignments.ts +77 -0
  175. package/src/rules/functionAssignments.test.ts +210 -0
  176. package/src/rules/functionAssignments.ts +51 -0
  177. package/src/rules/generatorFunctionYields.test.ts +152 -0
  178. package/src/rules/generatorFunctionYields.ts +71 -0
  179. package/src/rules/globalAssignments.test.ts +216 -0
  180. package/src/rules/globalAssignments.ts +67 -0
  181. package/src/rules/globalObjectCalls.test.ts +94 -0
  182. package/src/rules/globalObjectCalls.ts +52 -0
  183. package/src/rules/negativeZeroComparisons.test.ts +210 -0
  184. package/src/rules/negativeZeroComparisons.ts +106 -0
  185. package/src/rules/newExpressions.test.ts +80 -0
  186. package/src/rules/newExpressions.ts +67 -0
  187. package/src/rules/newNativeNonConstructors.test.ts +95 -0
  188. package/src/rules/newNativeNonConstructors.ts +59 -0
  189. package/src/rules/objectProto.test.ts +97 -0
  190. package/src/rules/objectProto.ts +62 -0
  191. package/src/rules/octalEscapes.test.ts +214 -0
  192. package/src/rules/octalEscapes.ts +85 -0
  193. package/src/rules/octalNumbers.test.ts +246 -0
  194. package/src/rules/octalNumbers.ts +75 -0
  195. package/src/rules/returnAssignments.test.ts +186 -0
  196. package/src/rules/returnAssignments.ts +57 -0
  197. package/src/rules/sparseArrays.test.ts +111 -0
  198. package/src/rules/sparseArrays.ts +61 -0
  199. package/src/rules/symbolDescriptions.test.ts +90 -0
  200. package/src/rules/symbolDescriptions.ts +47 -0
  201. package/src/rules/unassignedVariables.test.ts +73 -0
  202. package/src/rules/unassignedVariables.ts +69 -0
  203. package/src/rules/undefinedVariables.test.ts +81 -0
  204. package/src/rules/undefinedVariables.ts +97 -0
  205. package/src/rules/unicodeBOMs.test.ts +66 -0
  206. package/src/rules/unicodeBOMs.ts +44 -0
  207. package/src/rules/unnecessaryCatches.test.ts +211 -0
  208. package/src/rules/unnecessaryCatches.ts +84 -0
  209. package/src/rules/unsafeNegations.test.ts +64 -0
  210. package/src/rules/unsafeNegations.ts +59 -0
  211. package/src/rules/variableDeletions.test.ts +76 -0
  212. package/src/rules/variableDeletions.ts +43 -0
  213. package/src/rules/voidOperator.test.ts +99 -0
  214. package/src/rules/voidOperator.ts +38 -0
  215. package/src/utils/declarationsIncludeGlobal.ts +11 -0
  216. package/src/utils/getModifyingReferences.ts +58 -0
  217. package/src/utils/isGlobalDeclaration.ts +12 -0
  218. package/src/utils/isGlobalVariable.ts +30 -0
  219. package/src/utils/unwrapParentParenthesizedExpressions.ts +7 -0
  220. package/src/utils/unwrapParenthesizedExpression.ts +9 -0
  221. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,80 @@
1
+ import rule from "./debuggerStatements.js";
2
+ import { ruleTester } from "./ruleTester.js";
3
+ ruleTester.describe(rule, {
4
+ invalid: [
5
+ {
6
+ code: `
7
+ debugger;
8
+ `,
9
+ snapshot: `
10
+ debugger;
11
+ ~~~~~~~~~
12
+ Debugger statements should not be used in production code.
13
+ `,
14
+ suggestions: [
15
+ {
16
+ id: "removeDebugger",
17
+ updated: `
18
+
19
+ `,
20
+ },
21
+ ],
22
+ },
23
+ {
24
+ code: `
25
+ function test() {
26
+ debugger;
27
+ }
28
+ `,
29
+ snapshot: `
30
+ function test() {
31
+ debugger;
32
+ ~~~~~~~~~
33
+ Debugger statements should not be used in production code.
34
+ }
35
+ `,
36
+ suggestions: [
37
+ {
38
+ id: "removeDebugger",
39
+ updated: `
40
+ function test() {
41
+
42
+ }
43
+ `,
44
+ },
45
+ ],
46
+ },
47
+ {
48
+ code: `
49
+ if (condition) {
50
+ debugger;
51
+ }
52
+ `,
53
+ snapshot: `
54
+ if (condition) {
55
+ debugger;
56
+ ~~~~~~~~~
57
+ Debugger statements should not be used in production code.
58
+ }
59
+ `,
60
+ suggestions: [
61
+ {
62
+ id: "removeDebugger",
63
+ updated: `
64
+ if (condition) {
65
+
66
+ }
67
+ `,
68
+ },
69
+ ],
70
+ },
71
+ ],
72
+ valid: [
73
+ `console.log("debugging");`,
74
+ `function test() { console.log("test"); }`,
75
+ `for (let i = 0; i < 10; i++) { break; }`,
76
+ `for (let i = 0; i < 10; i++) { continue; }`,
77
+ `function test() { return; }`,
78
+ `throw new Error("test");`,
79
+ ],
80
+ });
@@ -0,0 +1,6 @@
1
+ declare const _default: import("@flint.fyi/core").Rule<{
2
+ readonly description: "Reports switch statements where the default clause is not last.";
3
+ readonly id: "defaultCaseLast";
4
+ readonly preset: "logical";
5
+ }, import("../nodes.js").TSNodesByName, import("../language.js").TypeScriptServices, "defaultCaseShouldBeLast", undefined>;
6
+ export default _default;
@@ -0,0 +1,43 @@
1
+ import * as ts from "typescript";
2
+ import { typescriptLanguage } from "../language.js";
3
+ export default typescriptLanguage.createRule({
4
+ about: {
5
+ description: "Reports switch statements where the default clause is not last.",
6
+ id: "defaultCaseLast",
7
+ preset: "logical",
8
+ },
9
+ messages: {
10
+ defaultCaseShouldBeLast: {
11
+ primary: "Default clauses in switch statements should be last.",
12
+ secondary: [
13
+ "Placing the default clause in a position other than last can lead to confusion and unexpected behavior.",
14
+ "While the default clause is executed when no case matches, having it in the middle of other cases makes the control flow harder to follow.",
15
+ ],
16
+ suggestions: [
17
+ "Move the default clause to the end of the switch statement to improve code clarity.",
18
+ ],
19
+ },
20
+ },
21
+ setup(context) {
22
+ return {
23
+ visitors: {
24
+ SwitchStatement: (node) => {
25
+ const clauses = node.caseBlock.clauses;
26
+ const defaultClauseIndex = clauses.findIndex((clause) => clause.kind === ts.SyntaxKind.DefaultClause);
27
+ if (defaultClauseIndex === -1 ||
28
+ defaultClauseIndex === clauses.length - 1) {
29
+ return;
30
+ }
31
+ const defaultClause = clauses[defaultClauseIndex];
32
+ context.report({
33
+ message: "defaultCaseShouldBeLast",
34
+ range: {
35
+ begin: defaultClause.getStart(context.sourceFile),
36
+ end: defaultClause.getStart(context.sourceFile) + "default".length,
37
+ },
38
+ });
39
+ },
40
+ },
41
+ };
42
+ },
43
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,195 @@
1
+ import rule from "./defaultCaseLast.js";
2
+ import { ruleTester } from "./ruleTester.js";
3
+ ruleTester.describe(rule, {
4
+ invalid: [
5
+ {
6
+ code: `
7
+ switch (value) {
8
+ default:
9
+ break;
10
+ case 1:
11
+ break;
12
+ }
13
+ `,
14
+ snapshot: `
15
+ switch (value) {
16
+ default:
17
+ ~~~~~~~
18
+ Default clauses in switch statements should be last.
19
+ break;
20
+ case 1:
21
+ break;
22
+ }
23
+ `,
24
+ },
25
+ {
26
+ code: `
27
+ switch (value) {
28
+ case 1:
29
+ break;
30
+ default:
31
+ break;
32
+ case 2:
33
+ break;
34
+ }
35
+ `,
36
+ snapshot: `
37
+ switch (value) {
38
+ case 1:
39
+ break;
40
+ default:
41
+ ~~~~~~~
42
+ Default clauses in switch statements should be last.
43
+ break;
44
+ case 2:
45
+ break;
46
+ }
47
+ `,
48
+ },
49
+ {
50
+ code: `
51
+ switch (value) {
52
+ case 1:
53
+ case 2:
54
+ break;
55
+ default:
56
+ break;
57
+ case 3:
58
+ break;
59
+ }
60
+ `,
61
+ snapshot: `
62
+ switch (value) {
63
+ case 1:
64
+ case 2:
65
+ break;
66
+ default:
67
+ ~~~~~~~
68
+ Default clauses in switch statements should be last.
69
+ break;
70
+ case 3:
71
+ break;
72
+ }
73
+ `,
74
+ },
75
+ {
76
+ code: `
77
+ switch (value) {
78
+ default:
79
+ console.log("default");
80
+ break;
81
+ case 1:
82
+ console.log("one");
83
+ break;
84
+ }
85
+ `,
86
+ snapshot: `
87
+ switch (value) {
88
+ default:
89
+ ~~~~~~~
90
+ Default clauses in switch statements should be last.
91
+ console.log("default");
92
+ break;
93
+ case 1:
94
+ console.log("one");
95
+ break;
96
+ }
97
+ `,
98
+ },
99
+ {
100
+ code: `
101
+ const result = (value: number) => {
102
+ switch (value) {
103
+ case 1:
104
+ return "one";
105
+ default:
106
+ return "default";
107
+ case 2:
108
+ return "two";
109
+ }
110
+ };
111
+ `,
112
+ snapshot: `
113
+ const result = (value: number) => {
114
+ switch (value) {
115
+ case 1:
116
+ return "one";
117
+ default:
118
+ ~~~~~~~
119
+ Default clauses in switch statements should be last.
120
+ return "default";
121
+ case 2:
122
+ return "two";
123
+ }
124
+ };
125
+ `,
126
+ },
127
+ {
128
+ code: `
129
+ switch (value) {
130
+ default:
131
+ case 1:
132
+ break;
133
+ }
134
+ `,
135
+ snapshot: `
136
+ switch (value) {
137
+ default:
138
+ ~~~~~~~
139
+ Default clauses in switch statements should be last.
140
+ case 1:
141
+ break;
142
+ }
143
+ `,
144
+ },
145
+ ],
146
+ valid: [
147
+ `switch (value) { case 1: break; default: break; }`,
148
+ `switch (value) { case 1: break; case 2: break; default: break; }`,
149
+ `switch (value) { case 1: break; case 2: break; }`,
150
+ `switch (value) { default: break; }`,
151
+ `switch (value) { case 1: case 2: break; default: break; }`,
152
+ `
153
+ switch (value) {
154
+ case 1:
155
+ break;
156
+ default:
157
+ break;
158
+ }
159
+ `,
160
+ `
161
+ switch (value) {
162
+ case 1:
163
+ console.log("one");
164
+ break;
165
+ case 2:
166
+ console.log("two");
167
+ break;
168
+ default:
169
+ console.log("default");
170
+ break;
171
+ }
172
+ `,
173
+ `
174
+ const result = (value: number) => {
175
+ switch (value) {
176
+ case 1:
177
+ return "one";
178
+ case 2:
179
+ return "two";
180
+ default:
181
+ return "default";
182
+ }
183
+ };
184
+ `,
185
+ `
186
+ switch (value) {
187
+ case 1:
188
+ case 2:
189
+ break;
190
+ default:
191
+ break;
192
+ }
193
+ `,
194
+ ],
195
+ });
@@ -0,0 +1,6 @@
1
+ declare const _default: import("@flint.fyi/core").Rule<{
2
+ readonly description: "Reports functions with duplicate parameter names in their signatures.";
3
+ readonly id: "duplicateArguments";
4
+ readonly preset: "untyped";
5
+ }, import("../nodes.js").TSNodesByName, import("../language.js").TypeScriptServices, "duplicateParam", undefined>;
6
+ export default _default;
@@ -0,0 +1,51 @@
1
+ import * as ts from "typescript";
2
+ import { getTSNodeRange } from "../getTSNodeRange.js";
3
+ import { typescriptLanguage } from "../language.js";
4
+ export default typescriptLanguage.createRule({
5
+ about: {
6
+ description: "Reports functions with duplicate parameter names in their signatures.",
7
+ id: "duplicateArguments",
8
+ preset: "untyped",
9
+ },
10
+ messages: {
11
+ duplicateParam: {
12
+ primary: "This parameter overrides the previous parameter of the same name.",
13
+ secondary: [
14
+ "Duplicate parameter names in functions can lead to unexpected behavior and make code harder to understand.",
15
+ "In strict mode, duplicate parameter names are a syntax error.",
16
+ "Even in non-strict mode, only the last parameter with a given name is accessible.",
17
+ ],
18
+ suggestions: ["Rename one of the duplicate parameters to a unique name."],
19
+ },
20
+ },
21
+ setup(context) {
22
+ function checkNode({ parameters }) {
23
+ const seenNames = new Set();
24
+ for (const parameter of parameters) {
25
+ if (!ts.isIdentifier(parameter.name)) {
26
+ continue;
27
+ }
28
+ const parameterName = parameter.name.text;
29
+ const existingParameter = seenNames.has(parameterName);
30
+ if (existingParameter) {
31
+ context.report({
32
+ message: "duplicateParam",
33
+ range: getTSNodeRange(parameter.name, context.sourceFile),
34
+ });
35
+ }
36
+ else {
37
+ seenNames.add(parameterName);
38
+ }
39
+ }
40
+ }
41
+ return {
42
+ visitors: {
43
+ ArrowFunction: checkNode,
44
+ Constructor: checkNode,
45
+ FunctionDeclaration: checkNode,
46
+ FunctionExpression: checkNode,
47
+ MethodDeclaration: checkNode,
48
+ },
49
+ };
50
+ },
51
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,139 @@
1
+ import rule from "./duplicateArguments.js";
2
+ import { ruleTester } from "./ruleTester.js";
3
+ ruleTester.describe(rule, {
4
+ invalid: [
5
+ {
6
+ code: `
7
+ function test(value, value) {
8
+ return value;
9
+ }
10
+ `,
11
+ snapshot: `
12
+ function test(value, value) {
13
+ ~~~~~
14
+ This parameter overrides the previous parameter of the same name.
15
+ return value;
16
+ }
17
+ `,
18
+ },
19
+ {
20
+ code: `
21
+ function test(first, second, first) {
22
+ return first + second;
23
+ }
24
+ `,
25
+ snapshot: `
26
+ function test(first, second, first) {
27
+ ~~~~~
28
+ This parameter overrides the previous parameter of the same name.
29
+ return first + second;
30
+ }
31
+ `,
32
+ },
33
+ {
34
+ code: `
35
+ const arrow = (value, value) => value;
36
+ `,
37
+ snapshot: `
38
+ const arrow = (value, value) => value;
39
+ ~~~~~
40
+ This parameter overrides the previous parameter of the same name.
41
+ `,
42
+ },
43
+ {
44
+ code: `
45
+ const func = function (value, value) {
46
+ return value;
47
+ };
48
+ `,
49
+ snapshot: `
50
+ const func = function (value, value) {
51
+ ~~~~~
52
+ This parameter overrides the previous parameter of the same name.
53
+ return value;
54
+ };
55
+ `,
56
+ },
57
+ {
58
+ code: `
59
+ class Example {
60
+ method(value, value) {
61
+ return value;
62
+ }
63
+ }
64
+ `,
65
+ snapshot: `
66
+ class Example {
67
+ method(value, value) {
68
+ ~~~~~
69
+ This parameter overrides the previous parameter of the same name.
70
+ return value;
71
+ }
72
+ }
73
+ `,
74
+ },
75
+ {
76
+ code: `
77
+ class Example {
78
+ constructor(value, value) {
79
+ this.value = value;
80
+ }
81
+ }
82
+ `,
83
+ snapshot: `
84
+ class Example {
85
+ constructor(value, value) {
86
+ ~~~~~
87
+ This parameter overrides the previous parameter of the same name.
88
+ this.value = value;
89
+ }
90
+ }
91
+ `,
92
+ },
93
+ {
94
+ code: `
95
+ function test(first, second, third, second) {
96
+ return first + second + third;
97
+ }
98
+ `,
99
+ snapshot: `
100
+ function test(first, second, third, second) {
101
+ ~~~~~~
102
+ This parameter overrides the previous parameter of the same name.
103
+ return first + second + third;
104
+ }
105
+ `,
106
+ },
107
+ {
108
+ code: `
109
+ function test(value, value, value) {
110
+ return value;
111
+ }
112
+ `,
113
+ snapshot: `
114
+ function test(value, value, value) {
115
+ ~~~~~
116
+ This parameter overrides the previous parameter of the same name.
117
+ ~~~~~
118
+ This parameter overrides the previous parameter of the same name.
119
+ return value;
120
+ }
121
+ `,
122
+ },
123
+ ],
124
+ valid: [
125
+ `function test(value) { return value; }`,
126
+ `function test(first, second) { return first + second; }`,
127
+ `const arrow = (value) => value;`,
128
+ `const arrow = (first, second) => first + second;`,
129
+ `const func = function (value) { return value; };`,
130
+ `const func = function (first, second) { return first + second; };`,
131
+ `class Example { method(value) { return value; } }`,
132
+ `class Example { method(first, second) { return first + second; } }`,
133
+ `class Example { constructor(value) { this.value = value; } }`,
134
+ `class Example { constructor(first, second) { this.first = first; this.second = second; } }`,
135
+ `function test({ value }) { return value; }`,
136
+ `function test({ first, second }) { return first + second; }`,
137
+ `function test([first, second]) { return first + second; }`,
138
+ ],
139
+ });
@@ -0,0 +1,6 @@
1
+ declare const _default: import("@flint.fyi/core").Rule<{
2
+ readonly description: "Reports using empty destructuring patterns that destructure no values.";
3
+ readonly id: "emptyDestructures";
4
+ readonly preset: "logical";
5
+ }, import("../nodes.js").TSNodesByName, import("../language.js").TypeScriptServices, "emptyPattern", undefined>;
6
+ export default _default;
@@ -0,0 +1,40 @@
1
+ import { typescriptLanguage } from "../language.js";
2
+ export default typescriptLanguage.createRule({
3
+ about: {
4
+ description: "Reports using empty destructuring patterns that destructure no values.",
5
+ id: "emptyDestructures",
6
+ preset: "logical",
7
+ },
8
+ messages: {
9
+ emptyPattern: {
10
+ primary: "Destructuring patterns that don't extract at least one value are unnecessary.",
11
+ secondary: [
12
+ "Empty destructuring patterns like `{}` or `[]` don't extract any values and serve no practical purpose.",
13
+ "These patterns are likely mistakes or leftover code from refactoring.",
14
+ ],
15
+ suggestions: [
16
+ "Remove the empty destructuring pattern if it's not needed.",
17
+ "Add bindings to extract values if you intended to destructure specific properties.",
18
+ ],
19
+ },
20
+ },
21
+ setup(context) {
22
+ function checkBindingPattern(node) {
23
+ if (node.elements.length === 0) {
24
+ context.report({
25
+ message: "emptyPattern",
26
+ range: {
27
+ begin: node.getStart(context.sourceFile),
28
+ end: node.getEnd(),
29
+ },
30
+ });
31
+ }
32
+ }
33
+ return {
34
+ visitors: {
35
+ ArrayBindingPattern: checkBindingPattern,
36
+ ObjectBindingPattern: checkBindingPattern,
37
+ },
38
+ };
39
+ },
40
+ });
@@ -0,0 +1 @@
1
+ export {};