@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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @flint/ts
2
2
 
3
+ ## 0.14.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 9b6b884: added browser plugin with alerts rule
8
+ - c8bad31: feat: add JSX plugin with accessKeys rule
9
+
10
+ ## 0.14.2
11
+
12
+ ### Patch Changes
13
+
14
+ - 6415134: feat: implement debuggerStatements rule for TypeScript plugin
15
+ - Updated dependencies [b58d145]
16
+ - @flint.fyi/rule-tester@0.14.1
17
+
3
18
  ## 0.14.1
4
19
 
5
20
  ### Patch Changes
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { getTSNodeRange } from "./getTSNodeRange.js";
2
2
  export * from "./language.js";
3
3
  export { ts } from "./plugin.js";
4
+ export { isGlobalDeclaration } from "./utils/isGlobalDeclaration.js";
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { getTSNodeRange } from "./getTSNodeRange.js";
2
2
  export * from "./language.js";
3
3
  export { ts } from "./plugin.js";
4
+ export { isGlobalDeclaration } from "./utils/isGlobalDeclaration.js";
package/lib/nodes.d.ts CHANGED
@@ -22,6 +22,7 @@ export interface TSNodesByName {
22
22
  ComputedPropertyName: ts.ComputedPropertyName;
23
23
  ConditionalExpression: ts.ConditionalExpression;
24
24
  ConditionalType: ts.ConditionalType;
25
+ Constructor: ts.ConstructorDeclaration;
25
26
  ContinueStatement: ts.ContinueStatement;
26
27
  DebuggerStatement: ts.DebuggerStatement;
27
28
  Decorator: ts.Decorator;
package/lib/plugin.d.ts CHANGED
@@ -1,16 +1,144 @@
1
1
  export declare const ts: import("@flint.fyi/core").Plugin<import("@flint.fyi/core").RuleAbout, string | undefined, [import("@flint.fyi/core").Rule<{
2
- readonly description: "Reports iterating over an array with a for-in loop.";
3
- readonly id: "forInArrays";
2
+ readonly description: "Reports using async functions as Promise executor functions.";
3
+ readonly id: "asyncPromiseExecutors";
4
4
  readonly preset: "logical";
5
- }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "forIn", undefined>, import("@flint.fyi/core").Rule<{
5
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "asyncPromiseExecutor", undefined>, import("@flint.fyi/core").Rule<{
6
+ readonly description: "Reports lexical declarations in case clauses without wrapping them in blocks.";
7
+ readonly id: "caseDeclarations";
8
+ readonly preset: "untyped";
9
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "unexpectedLexicalDeclaration", undefined>, import("@flint.fyi/core").Rule<{
10
+ readonly description: "Reports using chained assignment expressions (e.g., a = b = c).";
11
+ readonly id: "chainedAssignments";
12
+ readonly preset: "stylistic";
13
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "noChainedAssignment", undefined>, import("@flint.fyi/core").Rule<{
14
+ readonly description: "Reports reassigning class declarations.";
15
+ readonly id: "classAssignments";
16
+ readonly preset: "untyped";
17
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "noClassAssign", undefined>, import("@flint.fyi/core").Rule<{
6
18
  readonly description: "Reports unnecessary extra non-null assertions.";
7
19
  readonly id: "consecutiveNonNullAssertions";
8
20
  readonly preset: "logical";
9
21
  }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "consecutiveNonNullAssertion", undefined>, import("@flint.fyi/core").Rule<{
22
+ readonly description: "Reports attempting to reassign variables declared with const.";
23
+ readonly id: "constantAssignments";
24
+ readonly preset: "untyped";
25
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "noConstAssign", undefined>, import("@flint.fyi/core").Rule<{
26
+ readonly description: "Reports returning values from constructor functions.";
27
+ readonly id: "constructorReturns";
28
+ readonly preset: "untyped";
29
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "noConstructorReturn", undefined>, import("@flint.fyi/core").Rule<{
30
+ readonly description: "Reports using debugger statements.";
31
+ readonly id: "debuggerStatements";
32
+ readonly preset: "logical";
33
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "noDebugger", undefined>, import("@flint.fyi/core").Rule<{
34
+ readonly description: "Reports switch statements where the default clause is not last.";
35
+ readonly id: "defaultCaseLast";
36
+ readonly preset: "logical";
37
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "defaultCaseShouldBeLast", undefined>, import("@flint.fyi/core").Rule<{
38
+ readonly description: "Reports functions with duplicate parameter names in their signatures.";
39
+ readonly id: "duplicateArguments";
40
+ readonly preset: "untyped";
41
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "duplicateParam", undefined>, import("@flint.fyi/core").Rule<{
42
+ readonly description: "Reports using empty destructuring patterns that destructure no values.";
43
+ readonly id: "emptyDestructures";
44
+ readonly preset: "logical";
45
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "emptyPattern", undefined>, import("@flint.fyi/core").Rule<{
46
+ readonly description: "Reports empty static initialization blocks within class declarations.";
47
+ readonly id: "emptyStaticBlocks";
48
+ readonly preset: "stylistic";
49
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "emptyStaticBlock", undefined>, import("@flint.fyi/core").Rule<{
50
+ readonly description: "Reports reassigning exception parameters in catch clauses.";
51
+ readonly id: "exceptionAssignments";
52
+ readonly preset: "logical";
53
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "noExAssign", undefined>, import("@flint.fyi/core").Rule<{
54
+ readonly description: "Reports iterating over an array with a for-in loop.";
55
+ readonly id: "forInArrays";
56
+ readonly preset: "logical";
57
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "forIn", undefined>, import("@flint.fyi/core").Rule<{
58
+ readonly description: "Reports reassigning variables declared with function declarations.";
59
+ readonly id: "functionAssignments";
60
+ readonly preset: "untyped";
61
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "noFunctionAssignment", undefined>, import("@flint.fyi/core").Rule<{
62
+ readonly description: "Reports generator functions that do not yield values.";
63
+ readonly id: "generatorFunctionYields";
64
+ readonly preset: "logical";
65
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "missingYield", undefined>, import("@flint.fyi/core").Rule<{
66
+ readonly description: "Reports attempting to assign to read-only global variables such as undefined, NaN, Infinity, Object, etc.";
67
+ readonly id: "globalAssignments";
68
+ readonly preset: "untyped";
69
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "noGlobalAssign", undefined>, import("@flint.fyi/core").Rule<{
70
+ readonly description: "Reports calling global objects like Math, JSON, or Reflect as functions.";
71
+ readonly id: "globalObjectCalls";
72
+ readonly preset: "untyped";
73
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "noGlobalObjectCall", undefined>, import("@flint.fyi/core").Rule<{
10
74
  readonly description: "Reports using legacy `namespace` declarations.";
11
75
  readonly id: "namespaceDeclarations";
12
76
  readonly preset: "logical";
13
77
  }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "preferModules", {
14
78
  readonly allowDeclarations: import("zod").ZodDefault<import("zod").ZodBoolean>;
15
79
  readonly allowDefinitionFiles: import("zod").ZodDefault<import("zod").ZodBoolean>;
16
- }>]>;
80
+ }>, import("@flint.fyi/core").Rule<{
81
+ readonly description: "Reports comparisons with -0 that may not behave as expected.";
82
+ readonly id: "negativeZeroComparisons";
83
+ readonly preset: "logical";
84
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "unexpectedNegativeZeroComparison", undefined>, import("@flint.fyi/core").Rule<{
85
+ readonly description: "Reports standalone new expressions that don't use the constructed object.";
86
+ readonly id: "newExpressions";
87
+ readonly preset: "logical";
88
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "noStandaloneNew", undefined>, import("@flint.fyi/core").Rule<{
89
+ readonly description: "Disallows using `new` with global non-constructor functions like Symbol and BigInt.";
90
+ readonly id: "newNativeNonConstructors";
91
+ readonly preset: "untyped";
92
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "noNewNonConstructor", undefined>, import("@flint.fyi/core").Rule<{
93
+ readonly description: "Reports using the deprecated __proto__ property to access or modify an object's prototype.";
94
+ readonly id: "objectProto";
95
+ readonly preset: "untyped";
96
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "noProto", undefined>, import("@flint.fyi/core").Rule<{
97
+ readonly description: "Reports using octal escape sequences in string literals.";
98
+ readonly id: "octalEscapes";
99
+ readonly preset: "logical";
100
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "noOctalEscape", undefined>, import("@flint.fyi/core").Rule<{
101
+ readonly description: "Reports using legacy octal numeric literals.";
102
+ readonly id: "octalNumbers";
103
+ readonly preset: "untyped";
104
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "noOctalNumber", undefined>, import("@flint.fyi/core").Rule<{
105
+ readonly description: "Reports using assignment expressions in return statements.";
106
+ readonly id: "returnAssignments";
107
+ readonly preset: "stylistic";
108
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "noReturnAssign", undefined>, import("@flint.fyi/core").Rule<{
109
+ readonly description: "Reports array literals with holes (sparse arrays).";
110
+ readonly id: "sparseArrays";
111
+ readonly preset: "logical";
112
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "noSparseArray", undefined>, import("@flint.fyi/core").Rule<{
113
+ readonly description: "Reports Symbol() calls without description arguments.";
114
+ readonly id: "symbolDescriptions";
115
+ readonly preset: "stylistic";
116
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "missingDescription", undefined>, import("@flint.fyi/core").Rule<{
117
+ readonly description: "Reports variables that are declared but never assigned a value.";
118
+ readonly id: "unassignedVariables";
119
+ readonly preset: "untyped";
120
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "noUnassigned", undefined>, import("@flint.fyi/core").Rule<{
121
+ readonly description: "Reports using variables that are not defined.";
122
+ readonly id: "undefinedVariables";
123
+ readonly preset: "untyped";
124
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "undefinedVariable", undefined>, import("@flint.fyi/core").Rule<{
125
+ readonly description: "Reports files with Unicode Byte Order Marks (BOMs).";
126
+ readonly id: "unicodeBOMs";
127
+ readonly preset: "stylistic";
128
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "noBOM", undefined>, import("@flint.fyi/core").Rule<{
129
+ readonly description: "Reports catch clauses that only rethrow the caught error without modification.";
130
+ readonly id: "unnecessaryCatches";
131
+ readonly preset: "logical";
132
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "unnecessaryCatch", undefined>, import("@flint.fyi/core").Rule<{
133
+ readonly description: "Reports negating the left operand of `in` or `instanceof` relations.";
134
+ readonly id: "unsafeNegations";
135
+ readonly preset: "untyped";
136
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "preferNegatingRelation", undefined>, import("@flint.fyi/core").Rule<{
137
+ readonly description: "Reports attempting to delete variables with the delete operator.";
138
+ readonly id: "variableDeletions";
139
+ readonly preset: "untyped";
140
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "noDeleteVar", undefined>, import("@flint.fyi/core").Rule<{
141
+ readonly description: "Reports using the void operator.";
142
+ readonly id: "voidOperator";
143
+ readonly preset: "stylistic";
144
+ }, import("./nodes.js").TSNodesByName, import("./language.js").TypeScriptServices, "noVoid", undefined>]>;
package/lib/plugin.js CHANGED
@@ -1,11 +1,79 @@
1
1
  import { createPlugin } from "@flint.fyi/core";
2
+ import asyncPromiseExecutors from "./rules/asyncPromiseExecutors.js";
3
+ import caseDeclarations from "./rules/caseDeclarations.js";
4
+ import chainedAssignments from "./rules/chainedAssignments.js";
5
+ import classAssignments from "./rules/classAssignments.js";
2
6
  import consecutiveNonNullAssertions from "./rules/consecutiveNonNullAssertions.js";
7
+ import constantAssignments from "./rules/constantAssignments.js";
8
+ import constructorReturns from "./rules/constructorReturns.js";
9
+ import debuggerStatements from "./rules/debuggerStatements.js";
10
+ import defaultCaseLast from "./rules/defaultCaseLast.js";
11
+ import duplicateArguments from "./rules/duplicateArguments.js";
12
+ import emptyDestructures from "./rules/emptyDestructures.js";
13
+ import emptyStaticBlocks from "./rules/emptyStaticBlocks.js";
14
+ import exceptionAssignments from "./rules/exceptionAssignments.js";
3
15
  import forInArrays from "./rules/forInArrays.js";
16
+ import functionAssignments from "./rules/functionAssignments.js";
17
+ import generatorFunctionYields from "./rules/generatorFunctionYields.js";
18
+ import globalAssignments from "./rules/globalAssignments.js";
19
+ import globalObjectCalls from "./rules/globalObjectCalls.js";
4
20
  import namespaceDeclarations from "./rules/namespaceDeclarations.js";
21
+ import negativeZeroComparisons from "./rules/negativeZeroComparisons.js";
22
+ import newExpressions from "./rules/newExpressions.js";
23
+ import newNativeNonConstructors from "./rules/newNativeNonConstructors.js";
24
+ import objectProto from "./rules/objectProto.js";
25
+ import octalEscapes from "./rules/octalEscapes.js";
26
+ import octalNumbers from "./rules/octalNumbers.js";
27
+ import returnAssignments from "./rules/returnAssignments.js";
28
+ import sparseArrays from "./rules/sparseArrays.js";
29
+ import symbolDescriptions from "./rules/symbolDescriptions.js";
30
+ import unassignedVariables from "./rules/unassignedVariables.js";
31
+ import undefinedVariables from "./rules/undefinedVariables.js";
32
+ import unicodeBOMs from "./rules/unicodeBOMs.js";
33
+ import unnecessaryCatches from "./rules/unnecessaryCatches.js";
34
+ import unsafeNegations from "./rules/unsafeNegations.js";
35
+ import variableDeletions from "./rules/variableDeletions.js";
36
+ import voidOperator from "./rules/voidOperator.js";
5
37
  export const ts = createPlugin({
6
38
  files: {
7
39
  all: ["**/*.{cjs,js,jsx,mjs,ts,tsx}"],
8
40
  },
9
41
  name: "ts",
10
- rules: [forInArrays, consecutiveNonNullAssertions, namespaceDeclarations],
42
+ rules: [
43
+ asyncPromiseExecutors,
44
+ caseDeclarations,
45
+ chainedAssignments,
46
+ classAssignments,
47
+ consecutiveNonNullAssertions,
48
+ constantAssignments,
49
+ constructorReturns,
50
+ debuggerStatements,
51
+ defaultCaseLast,
52
+ duplicateArguments,
53
+ emptyDestructures,
54
+ emptyStaticBlocks,
55
+ exceptionAssignments,
56
+ forInArrays,
57
+ functionAssignments,
58
+ generatorFunctionYields,
59
+ globalAssignments,
60
+ globalObjectCalls,
61
+ namespaceDeclarations,
62
+ negativeZeroComparisons,
63
+ newExpressions,
64
+ newNativeNonConstructors,
65
+ objectProto,
66
+ octalEscapes,
67
+ octalNumbers,
68
+ returnAssignments,
69
+ sparseArrays,
70
+ symbolDescriptions,
71
+ unassignedVariables,
72
+ undefinedVariables,
73
+ unicodeBOMs,
74
+ unnecessaryCatches,
75
+ unsafeNegations,
76
+ variableDeletions,
77
+ voidOperator,
78
+ ],
11
79
  });
@@ -0,0 +1,6 @@
1
+ declare const _default: import("@flint.fyi/core").Rule<{
2
+ readonly description: "Reports using async functions as Promise executor functions.";
3
+ readonly id: "asyncPromiseExecutors";
4
+ readonly preset: "logical";
5
+ }, import("../nodes.js").TSNodesByName, import("../language.js").TypeScriptServices, "asyncPromiseExecutor", undefined>;
6
+ export default _default;
@@ -0,0 +1,51 @@
1
+ import * as ts from "typescript";
2
+ import { typescriptLanguage } from "../language.js";
3
+ import { isGlobalDeclaration } from "../utils/isGlobalDeclaration.js";
4
+ export default typescriptLanguage.createRule({
5
+ about: {
6
+ description: "Reports using async functions as Promise executor functions.",
7
+ id: "asyncPromiseExecutors",
8
+ preset: "logical",
9
+ },
10
+ messages: {
11
+ asyncPromiseExecutor: {
12
+ primary: "Async Promise executor functions are not able to properly catch thrown errors and often indicate unnecessarily complex logic.",
13
+ secondary: [
14
+ "The Promise executor function is called synchronously by the Promise constructor.",
15
+ "If an async function is used as a Promise executor, thrown errors will not be caught by the Promise and will instead result in unhandled rejections.",
16
+ "Additionally, if a Promise executor function is using `await`, there's probably no need to use the `new Promise` constructor.",
17
+ ],
18
+ suggestions: [
19
+ "Remove the `async` keyword from the executor function.",
20
+ "If you need to use `await` inside the Promise, consider restructuring your code to avoid the Promise constructor.",
21
+ ],
22
+ },
23
+ },
24
+ setup(context) {
25
+ return {
26
+ visitors: {
27
+ NewExpression: (node) => {
28
+ if (!isGlobalDeclaration(node.expression, context.typeChecker) ||
29
+ !node.arguments?.length) {
30
+ return;
31
+ }
32
+ const executor = node.arguments[0];
33
+ if (!ts.isFunctionLike(executor)) {
34
+ return;
35
+ }
36
+ const asyncModifier = executor.modifiers?.find((mod) => mod.kind === ts.SyntaxKind.AsyncKeyword);
37
+ if (!asyncModifier) {
38
+ return;
39
+ }
40
+ context.report({
41
+ message: "asyncPromiseExecutor",
42
+ range: {
43
+ begin: asyncModifier.getStart(context.sourceFile),
44
+ end: asyncModifier.getEnd(),
45
+ },
46
+ });
47
+ },
48
+ },
49
+ };
50
+ },
51
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,71 @@
1
+ import rule from "./asyncPromiseExecutors.js";
2
+ import { ruleTester } from "./ruleTester.js";
3
+ ruleTester.describe(rule, {
4
+ invalid: [
5
+ {
6
+ code: `
7
+ new Promise(async (resolve, reject) => {
8
+ resolve(42);
9
+ });
10
+ `,
11
+ snapshot: `
12
+ new Promise(async (resolve, reject) => {
13
+ ~~~~~
14
+ Async Promise executor functions are not able to properly catch thrown errors and often indicate unnecessarily complex logic.
15
+ resolve(42);
16
+ });
17
+ `,
18
+ },
19
+ {
20
+ code: `
21
+ new Promise(async function(resolve, reject) {
22
+ resolve(42);
23
+ });
24
+ `,
25
+ snapshot: `
26
+ new Promise(async function(resolve, reject) {
27
+ ~~~~~
28
+ Async Promise executor functions are not able to properly catch thrown errors and often indicate unnecessarily complex logic.
29
+ resolve(42);
30
+ });
31
+ `,
32
+ },
33
+ {
34
+ code: `
35
+ const p = new Promise(async (resolve) => {
36
+ resolve();
37
+ });
38
+ `,
39
+ snapshot: `
40
+ const p = new Promise(async (resolve) => {
41
+ ~~~~~
42
+ Async Promise executor functions are not able to properly catch thrown errors and often indicate unnecessarily complex logic.
43
+ resolve();
44
+ });
45
+ `,
46
+ },
47
+ ],
48
+ valid: [
49
+ `
50
+ new Promise((resolve, reject) => {
51
+ resolve(42);
52
+ });
53
+ `,
54
+ `
55
+ new Promise(function(resolve, reject) {
56
+ resolve(42);
57
+ });
58
+ `,
59
+ `
60
+ const p = new Promise((resolve) => {
61
+ doSomething().then(resolve);
62
+ });
63
+ `,
64
+ `
65
+ // Not a Promise constructor
66
+ new SomethingElse(async (resolve) => {
67
+ resolve();
68
+ });
69
+ `,
70
+ ],
71
+ });
@@ -0,0 +1,6 @@
1
+ declare const _default: import("@flint.fyi/core").Rule<{
2
+ readonly description: "Reports lexical declarations in case clauses without wrapping them in blocks.";
3
+ readonly id: "caseDeclarations";
4
+ readonly preset: "untyped";
5
+ }, import("../nodes.js").TSNodesByName, import("../language.js").TypeScriptServices, "unexpectedLexicalDeclaration", undefined>;
6
+ export default _default;
@@ -0,0 +1,53 @@
1
+ import * as tsutils from "ts-api-utils";
2
+ import * as ts from "typescript";
3
+ import { getTSNodeRange } from "../getTSNodeRange.js";
4
+ import { typescriptLanguage } from "../language.js";
5
+ export default typescriptLanguage.createRule({
6
+ about: {
7
+ description: "Reports lexical declarations in case clauses without wrapping them in blocks.",
8
+ id: "caseDeclarations",
9
+ preset: "untyped",
10
+ },
11
+ messages: {
12
+ unexpectedLexicalDeclaration: {
13
+ primary: "Variables declared in case clauses without braces leak into the surrounding scope.",
14
+ secondary: [
15
+ "Lexical declarations (let, const, function, class) are scoped to the entire switch statement, not just the case clause where they are declared.",
16
+ "This can lead to unexpected behavior when the same variable name is used in multiple case clauses, as they will conflict in the same scope.",
17
+ ],
18
+ suggestions: [
19
+ "Wrap the case clause contents in curly braces {} to create a block scope.",
20
+ ],
21
+ },
22
+ },
23
+ setup(context) {
24
+ function getLexicalDeclaration(statements) {
25
+ for (const statement of statements) {
26
+ if (ts.isVariableStatement(statement) &&
27
+ tsutils.isNodeFlagSet(statement.declarationList, ts.NodeFlags.Let | ts.NodeFlags.Const)) {
28
+ return statement.declarationList.getChildAt(0, context.sourceFile);
29
+ }
30
+ if (ts.isClassDeclaration(statement) ||
31
+ ts.isFunctionDeclaration(statement)) {
32
+ return statement.getChildAt(0, context.sourceFile);
33
+ }
34
+ }
35
+ return undefined;
36
+ }
37
+ function checkClause(node) {
38
+ const declarationNode = getLexicalDeclaration(node.statements);
39
+ if (declarationNode) {
40
+ context.report({
41
+ message: "unexpectedLexicalDeclaration",
42
+ range: getTSNodeRange(declarationNode, context.sourceFile),
43
+ });
44
+ }
45
+ }
46
+ return {
47
+ visitors: {
48
+ CaseClause: checkClause,
49
+ DefaultClause: checkClause,
50
+ },
51
+ };
52
+ },
53
+ });
@@ -0,0 +1 @@
1
+ export {};