@autotelic/plumb 0.3.1 → 0.4.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 (268) hide show
  1. package/dist/effect/index.d.ts +3 -0
  2. package/dist/effect/index.js +56 -0
  3. package/dist/effect/rules/guarded-op-must-return-effect.d.ts +6 -0
  4. package/dist/effect/rules/guarded-op-must-return-effect.js +235 -0
  5. package/dist/effect/rules/guarded-op-must-return-option.d.ts +2 -0
  6. package/dist/effect/rules/guarded-op-must-return-option.js +88 -0
  7. package/dist/effect/rules/no-cascading-layer-provide.d.ts +6 -0
  8. package/dist/effect/rules/no-cascading-layer-provide.js +73 -0
  9. package/dist/effect/rules/no-decode-unknown-option.d.ts +7 -0
  10. package/dist/effect/rules/no-decode-unknown-option.js +34 -0
  11. package/dist/effect/rules/no-direct-browser-storage.d.ts +2 -0
  12. package/dist/effect/rules/no-direct-browser-storage.js +88 -0
  13. package/dist/effect/rules/no-direct-fetch.d.ts +2 -0
  14. package/dist/effect/rules/no-direct-fetch.js +37 -0
  15. package/dist/effect/rules/no-manual-field-guards.d.ts +6 -0
  16. package/dist/effect/rules/no-manual-field-guards.js +129 -0
  17. package/dist/effect/rules/no-nested-layer-provide.d.ts +2 -0
  18. package/dist/effect/rules/no-nested-layer-provide.js +50 -0
  19. package/dist/effect/rules/no-schema-class-modeling.d.ts +2 -0
  20. package/dist/effect/rules/no-schema-class-modeling.js +52 -0
  21. package/dist/effect/rules/no-service-constructor-imports.d.ts +2 -0
  22. package/dist/effect/rules/no-service-constructor-imports.js +42 -0
  23. package/dist/effect/rules/no-silent-error-swallow.d.ts +2 -0
  24. package/dist/effect/rules/no-silent-error-swallow.js +95 -0
  25. package/dist/effect/rules/no-static-effect-service-forwarders.d.ts +6 -0
  26. package/dist/effect/rules/no-static-effect-service-forwarders.js +222 -0
  27. package/dist/effect/rules/no-try-catch.d.ts +2 -0
  28. package/dist/effect/rules/no-try-catch.js +30 -0
  29. package/dist/effect/rules/no-unguarded-json-parse.d.ts +5 -0
  30. package/dist/effect/rules/no-unguarded-json-parse.js +200 -0
  31. package/dist/effect/rules/option-core-needs-effect-public.d.ts +5 -0
  32. package/dist/effect/rules/option-core-needs-effect-public.js +76 -0
  33. package/dist/effect/rules/prefer-die-for-precondition-defects.d.ts +5 -0
  34. package/dist/effect/rules/prefer-die-for-precondition-defects.js +112 -0
  35. package/dist/effect/rules/prefer-effect-gen-for-guard-ladders.d.ts +5 -0
  36. package/dist/effect/rules/prefer-effect-gen-for-guard-ladders.js +72 -0
  37. package/dist/effect/rules/prefer-effect-match.d.ts +2 -0
  38. package/dist/effect/rules/prefer-effect-match.js +74 -0
  39. package/dist/effect/rules/prefer-effect-predicate-over-boolean-function.d.ts +2 -0
  40. package/dist/effect/rules/prefer-effect-predicate-over-boolean-function.js +75 -0
  41. package/dist/effect/rules/prefer-named-guard-predicate.d.ts +2 -0
  42. package/dist/effect/rules/prefer-named-guard-predicate.js +93 -0
  43. package/dist/effect/rules/prefer-option-pipeline.d.ts +2 -0
  44. package/dist/effect/rules/prefer-option-pipeline.js +87 -0
  45. package/dist/effect/rules/prefer-ordering-match.d.ts +2 -0
  46. package/dist/effect/rules/prefer-ordering-match.js +135 -0
  47. package/dist/effect/rules/prefer-tagged-enum.d.ts +2 -0
  48. package/dist/effect/rules/prefer-tagged-enum.js +66 -0
  49. package/dist/effect/rules/require-schema-type-derivation.d.ts +7 -0
  50. package/dist/effect/rules/require-schema-type-derivation.js +80 -0
  51. package/dist/index.d.ts +3 -0
  52. package/dist/index.js +104 -0
  53. package/dist/meta/index.d.ts +7 -0
  54. package/{src/meta/index.ts → dist/meta/index.js} +13 -16
  55. package/dist/meta/rules/no-disable-directives.d.ts +6 -0
  56. package/dist/meta/rules/no-disable-directives.js +35 -0
  57. package/dist/meta/rules/no-manual-ancestor-walks.d.ts +2 -0
  58. package/dist/meta/rules/no-manual-ancestor-walks.js +26 -0
  59. package/dist/meta/rules/prefer-before-file-scope.d.ts +2 -0
  60. package/dist/meta/rules/prefer-before-file-scope.js +57 -0
  61. package/dist/meta/rules/require-create-once.d.ts +2 -0
  62. package/dist/meta/rules/require-create-once.js +51 -0
  63. package/dist/meta/rules/require-rule-tester.d.ts +2 -0
  64. package/dist/meta/rules/require-rule-tester.js +50 -0
  65. package/dist/rules/no-anonymous-wide-tuples.d.ts +7 -0
  66. package/dist/rules/no-anonymous-wide-tuples.js +34 -0
  67. package/dist/rules/no-barrel-export-star.d.ts +2 -0
  68. package/dist/rules/no-barrel-export-star.js +26 -0
  69. package/dist/rules/no-boolean-field-signals.d.ts +2 -0
  70. package/dist/rules/no-boolean-field-signals.js +279 -0
  71. package/dist/rules/no-builtin-throws.d.ts +6 -0
  72. package/dist/rules/no-builtin-throws.js +74 -0
  73. package/dist/rules/no-chained-type-assertions.d.ts +2 -0
  74. package/dist/rules/no-chained-type-assertions.js +54 -0
  75. package/dist/rules/no-conditional-empty-object-spread.d.ts +2 -0
  76. package/dist/rules/no-conditional-empty-object-spread.js +36 -0
  77. package/dist/rules/no-duplicated-literal-union.d.ts +6 -0
  78. package/dist/rules/no-duplicated-literal-union.js +62 -0
  79. package/dist/rules/no-exported-mutable-state.d.ts +7 -0
  80. package/dist/rules/no-exported-mutable-state.js +104 -0
  81. package/dist/rules/no-generic-export-names.d.ts +2 -0
  82. package/dist/rules/no-generic-export-names.js +141 -0
  83. package/dist/rules/no-impossible-branch-throw.d.ts +2 -0
  84. package/dist/rules/no-impossible-branch-throw.js +51 -0
  85. package/dist/rules/no-known-value-widening.d.ts +2 -0
  86. package/dist/rules/no-known-value-widening.js +176 -0
  87. package/dist/rules/no-module-mocking.d.ts +2 -0
  88. package/dist/rules/no-module-mocking.js +90 -0
  89. package/dist/rules/no-multiple-function-params.d.ts +2 -0
  90. package/dist/rules/no-multiple-function-params.js +155 -0
  91. package/dist/rules/no-mutable-environment-capture.d.ts +7 -0
  92. package/dist/rules/no-mutable-environment-capture.js +134 -0
  93. package/dist/rules/no-nondeterministic-core.d.ts +6 -0
  94. package/dist/rules/no-nondeterministic-core.js +63 -0
  95. package/dist/rules/no-object-parameters.d.ts +2 -0
  96. package/dist/rules/no-object-parameters.js +95 -0
  97. package/dist/rules/no-optional-function-parameters.d.ts +7 -0
  98. package/dist/rules/no-optional-function-parameters.js +44 -0
  99. package/dist/rules/no-product-of-state-booleans.d.ts +2 -0
  100. package/dist/rules/no-product-of-state-booleans.js +79 -0
  101. package/dist/rules/no-redundant-derived-field.d.ts +6 -0
  102. package/dist/rules/no-redundant-derived-field.js +194 -0
  103. package/dist/rules/no-reflect-apply.d.ts +2 -0
  104. package/dist/rules/no-reflect-apply.js +29 -0
  105. package/dist/rules/no-reflect-get.d.ts +2 -0
  106. package/dist/rules/no-reflect-get.js +29 -0
  107. package/dist/rules/no-reinterpret-cast.d.ts +2 -0
  108. package/dist/rules/no-reinterpret-cast.js +68 -0
  109. package/dist/rules/no-runtime-typeof.d.ts +2 -0
  110. package/dist/rules/no-runtime-typeof.js +54 -0
  111. package/dist/rules/no-sentinel-comparison-union.d.ts +2 -0
  112. package/dist/rules/no-sentinel-comparison-union.js +139 -0
  113. package/dist/rules/no-shape-in-symbol-names.d.ts +2 -0
  114. package/dist/rules/no-shape-in-symbol-names.js +39 -0
  115. package/dist/rules/no-single-use-private-functions.d.ts +17 -0
  116. package/dist/rules/no-single-use-private-functions.js +419 -0
  117. package/dist/rules/no-stacked-jsdoc-blocks.d.ts +2 -0
  118. package/dist/rules/no-stacked-jsdoc-blocks.js +50 -0
  119. package/dist/rules/no-stray-inline-comments.d.ts +2 -0
  120. package/dist/rules/no-stray-inline-comments.js +74 -0
  121. package/dist/rules/no-swappable-primitive-params.d.ts +2 -0
  122. package/dist/rules/no-swappable-primitive-params.js +96 -0
  123. package/dist/rules/no-tag-ladder-assertions.d.ts +6 -0
  124. package/dist/rules/no-tag-ladder-assertions.js +63 -0
  125. package/dist/rules/no-transposed-field-reads.d.ts +8 -0
  126. package/dist/rules/no-transposed-field-reads.js +101 -0
  127. package/dist/rules/no-unit-return-validators.d.ts +2 -0
  128. package/dist/rules/no-unit-return-validators.js +64 -0
  129. package/dist/rules/no-unknown-parameters.d.ts +2 -0
  130. package/dist/rules/no-unknown-parameters.js +82 -0
  131. package/dist/rules/no-unknown-returns.d.ts +2 -0
  132. package/dist/rules/no-unknown-returns.js +86 -0
  133. package/dist/rules/no-unknown-type-aliases.d.ts +2 -0
  134. package/dist/rules/no-unknown-type-aliases.js +64 -0
  135. package/dist/rules/no-unsafe-dictionary-type.d.ts +2 -0
  136. package/dist/rules/no-unsafe-dictionary-type.js +116 -0
  137. package/dist/rules/no-vague-test-filenames.d.ts +2 -0
  138. package/dist/rules/no-vague-test-filenames.js +61 -0
  139. package/dist/rules/no-widen-then-assert.d.ts +2 -0
  140. package/dist/rules/no-widen-then-assert.js +268 -0
  141. package/dist/rules/prefer-payload-brand.d.ts +2 -0
  142. package/dist/rules/prefer-payload-brand.js +57 -0
  143. package/dist/rules/prefer-property-tests.d.ts +5 -0
  144. package/dist/rules/prefer-property-tests.js +39 -0
  145. package/dist/rules/require-canonical-stringify-for-identity.d.ts +8 -0
  146. package/dist/rules/require-canonical-stringify-for-identity.js +72 -0
  147. package/dist/rules/require-deprecated-tag-for-legacy-comments.d.ts +2 -0
  148. package/dist/rules/require-deprecated-tag-for-legacy-comments.js +34 -0
  149. package/dist/rules/require-exhaustive-tag-switch.d.ts +7 -0
  150. package/dist/rules/require-exhaustive-tag-switch.js +34 -0
  151. package/dist/rules/require-fc-block-predicate.d.ts +2 -0
  152. package/dist/rules/require-fc-block-predicate.js +37 -0
  153. package/dist/rules/require-jsdoc-on-exported.d.ts +2 -0
  154. package/dist/rules/require-jsdoc-on-exported.js +66 -0
  155. package/dist/rules/require-published-order.d.ts +2 -0
  156. package/dist/rules/require-published-order.js +102 -0
  157. package/dist/rules/require-safety-comment-for-type-assertion.d.ts +2 -0
  158. package/dist/rules/require-safety-comment-for-type-assertion.js +53 -0
  159. package/dist/rules/require-sort-comparator.d.ts +7 -0
  160. package/dist/rules/require-sort-comparator.js +34 -0
  161. package/dist/rules/test-utils.d.ts +35 -0
  162. package/dist/rules/test-utils.js +53 -0
  163. package/{src/shared/ancestors.ts → dist/shared/ancestors.d.ts} +1 -4
  164. package/dist/shared/ancestors.js +19 -0
  165. package/dist/shared/child-nodes.d.ts +12 -0
  166. package/dist/shared/child-nodes.js +26 -0
  167. package/dist/shared/dictionary-types.d.ts +55 -0
  168. package/dist/shared/dictionary-types.js +413 -0
  169. package/{src/shared/is-node.ts → dist/shared/is-node.d.ts} +2 -6
  170. package/dist/shared/is-node.js +10 -0
  171. package/dist/shared/lexical-type-parameters.d.ts +12 -0
  172. package/dist/shared/lexical-type-parameters.js +50 -0
  173. package/dist/shared/reflect-method.d.ts +15 -0
  174. package/dist/shared/reflect-method.js +32 -0
  175. package/{src/shared/rule-options.ts → dist/shared/rule-options.d.ts} +2 -7
  176. package/dist/shared/rule-options.js +12 -0
  177. package/{src/shared/structural.ts → dist/shared/structural.d.ts} +17 -44
  178. package/dist/shared/structural.js +40 -0
  179. package/{src/testing/index.ts → dist/testing/index.d.ts} +0 -1
  180. package/dist/testing/index.js +1 -0
  181. package/dist/testing/testable-rule.d.ts +38 -0
  182. package/dist/testing/testable-rule.js +70 -0
  183. package/package.json +7 -6
  184. package/src/effect/index.ts +0 -59
  185. package/src/effect/rules/guarded-op-must-return-effect.ts +0 -236
  186. package/src/effect/rules/guarded-op-must-return-option.ts +0 -97
  187. package/src/effect/rules/no-cascading-layer-provide.ts +0 -80
  188. package/src/effect/rules/no-decode-unknown-option.ts +0 -41
  189. package/src/effect/rules/no-direct-browser-storage.ts +0 -91
  190. package/src/effect/rules/no-direct-fetch.ts +0 -44
  191. package/src/effect/rules/no-manual-field-guards.ts +0 -144
  192. package/src/effect/rules/no-nested-layer-provide.ts +0 -51
  193. package/src/effect/rules/no-schema-class-modeling.ts +0 -59
  194. package/src/effect/rules/no-service-constructor-imports.ts +0 -50
  195. package/src/effect/rules/no-silent-error-swallow.ts +0 -99
  196. package/src/effect/rules/no-static-effect-service-forwarders.ts +0 -227
  197. package/src/effect/rules/no-try-catch.ts +0 -32
  198. package/src/effect/rules/no-unguarded-json-parse.ts +0 -211
  199. package/src/effect/rules/option-core-needs-effect-public.ts +0 -81
  200. package/src/effect/rules/prefer-die-for-precondition-defects.ts +0 -118
  201. package/src/effect/rules/prefer-effect-gen-for-guard-ladders.ts +0 -76
  202. package/src/effect/rules/prefer-effect-match.ts +0 -78
  203. package/src/effect/rules/prefer-effect-predicate-over-boolean-function.ts +0 -79
  204. package/src/effect/rules/prefer-named-guard-predicate.ts +0 -105
  205. package/src/effect/rules/prefer-option-pipeline.ts +0 -95
  206. package/src/effect/rules/prefer-ordering-match.ts +0 -152
  207. package/src/effect/rules/prefer-tagged-enum.ts +0 -68
  208. package/src/effect/rules/require-schema-type-derivation.ts +0 -83
  209. package/src/index.ts +0 -106
  210. package/src/meta/rules/no-disable-directives.ts +0 -38
  211. package/src/meta/rules/no-manual-ancestor-walks.ts +0 -27
  212. package/src/meta/rules/prefer-before-file-scope.ts +0 -57
  213. package/src/meta/rules/require-create-once.ts +0 -51
  214. package/src/meta/rules/require-rule-tester.ts +0 -57
  215. package/src/rules/no-anonymous-wide-tuples.ts +0 -38
  216. package/src/rules/no-barrel-export-star.ts +0 -30
  217. package/src/rules/no-boolean-field-signals.ts +0 -305
  218. package/src/rules/no-builtin-throws.ts +0 -83
  219. package/src/rules/no-chained-type-assertions.ts +0 -65
  220. package/src/rules/no-conditional-empty-object-spread.ts +0 -42
  221. package/src/rules/no-duplicated-literal-union.ts +0 -66
  222. package/src/rules/no-exported-mutable-state.ts +0 -111
  223. package/src/rules/no-generic-export-names.ts +0 -149
  224. package/src/rules/no-impossible-branch-throw.ts +0 -55
  225. package/src/rules/no-known-value-widening.ts +0 -225
  226. package/src/rules/no-module-mocking.ts +0 -95
  227. package/src/rules/no-multiple-function-params.ts +0 -192
  228. package/src/rules/no-nondeterministic-core.ts +0 -73
  229. package/src/rules/no-object-parameters.ts +0 -127
  230. package/src/rules/no-optional-function-parameters.ts +0 -49
  231. package/src/rules/no-product-of-state-booleans.ts +0 -80
  232. package/src/rules/no-redundant-derived-field.ts +0 -192
  233. package/src/rules/no-reflect-apply.ts +0 -32
  234. package/src/rules/no-reflect-get.ts +0 -32
  235. package/src/rules/no-reinterpret-cast.ts +0 -78
  236. package/src/rules/no-runtime-typeof.ts +0 -59
  237. package/src/rules/no-sentinel-comparison-union.ts +0 -148
  238. package/src/rules/no-shape-in-symbol-names.ts +0 -45
  239. package/src/rules/no-single-use-private-functions.ts +0 -329
  240. package/src/rules/no-stacked-jsdoc-blocks.ts +0 -65
  241. package/src/rules/no-stray-inline-comments.ts +0 -79
  242. package/src/rules/no-swappable-primitive-params.ts +0 -109
  243. package/src/rules/no-tag-ladder-assertions.ts +0 -71
  244. package/src/rules/no-transposed-field-reads.ts +0 -135
  245. package/src/rules/no-unit-return-validators.ts +0 -65
  246. package/src/rules/no-unknown-parameters.ts +0 -97
  247. package/src/rules/no-unknown-returns.ts +0 -120
  248. package/src/rules/no-unknown-type-aliases.ts +0 -70
  249. package/src/rules/no-unsafe-dictionary-type.ts +0 -132
  250. package/src/rules/no-vague-test-filenames.ts +0 -67
  251. package/src/rules/no-widen-then-assert.ts +0 -345
  252. package/src/rules/prefer-payload-brand.ts +0 -67
  253. package/src/rules/prefer-property-tests.ts +0 -43
  254. package/src/rules/require-canonical-stringify-for-identity.ts +0 -80
  255. package/src/rules/require-deprecated-tag-for-legacy-comments.ts +0 -45
  256. package/src/rules/require-exhaustive-tag-switch.ts +0 -42
  257. package/src/rules/require-fc-block-predicate.ts +0 -42
  258. package/src/rules/require-jsdoc-on-exported.ts +0 -74
  259. package/src/rules/require-published-order.ts +0 -109
  260. package/src/rules/require-safety-comment-for-type-assertion.ts +0 -61
  261. package/src/rules/require-sort-comparator.ts +0 -41
  262. package/src/rules/test-utils.ts +0 -68
  263. package/src/shared/child-nodes.ts +0 -27
  264. package/src/shared/dictionary-types.ts +0 -524
  265. package/src/shared/lexical-type-parameters.ts +0 -62
  266. package/src/shared/reflect-method.ts +0 -41
  267. package/src/testing/testable-rule.test.ts +0 -68
  268. package/src/testing/testable-rule.ts +0 -86
@@ -1,305 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import type { ESTree } from "@oxlint/plugins";
4
-
5
- const COMPARISON_OPERATORS = new Set(["===", "!==", "==", "!=", "<", ">", "<=", ">="]);
6
- const CONSTRUCTOR_NAME = /^(?:make[A-Z]|make$|fromRaw|unsafeMake)/u;
7
-
8
- type PredicateFunction = ESTree.ArrowFunctionExpression | ESTree.Function;
9
-
10
- type PredicateCandidate = {
11
- readonly node: PredicateFunction;
12
- readonly typeName: string;
13
- };
14
-
15
- function parameterAnnotation(
16
- parameter: ESTree.ParamPattern,
17
- ): ESTree.TSTypeAnnotation | null | undefined {
18
- if (parameter.type === "TSParameterProperty") {
19
- return parameterAnnotation(parameter.parameter);
20
- }
21
- if (parameter.type === "RestElement") {
22
- return parameter.typeAnnotation ?? parameterAnnotation(parameter.argument);
23
- }
24
- if (parameter.type === "AssignmentPattern") {
25
- return parameter.typeAnnotation ?? parameter.left.typeAnnotation;
26
- }
27
- return parameter.typeAnnotation;
28
- }
29
-
30
- function referencedTypeName(type: ESTree.TSType): string | null {
31
- if (type.type === "TSParenthesizedType") return referencedTypeName(type.typeAnnotation);
32
- if (type.type !== "TSTypeReference" || type.typeName.type !== "Identifier") return null;
33
- return type.typeName.name;
34
- }
35
-
36
- function isLiteralExpression(expression: ESTree.Expression | ESTree.PrivateIdentifier): boolean {
37
- if (expression.type === "Literal") return true;
38
- return (
39
- expression.type === "UnaryExpression" &&
40
- expression.operator === "-" &&
41
- expression.argument.type === "Literal"
42
- );
43
- }
44
-
45
- function isParamField(payload: {
46
- expression: ESTree.Expression | ESTree.PrivateIdentifier;
47
- paramName: string;
48
- }): boolean {
49
- const { expression, paramName } = payload;
50
- if (expression.type === "PrivateIdentifier") return false;
51
- if (expression.type !== "MemberExpression" || expression.object.type !== "Identifier") {
52
- return false;
53
- }
54
- if (expression.object.name !== paramName) return false;
55
- if (expression.computed) return expression.property.type === "Literal";
56
- return expression.property.type === "Identifier" || expression.property.type === "PrivateIdentifier";
57
- }
58
-
59
- function isFieldSignalBody(payload: { expression: ESTree.Expression; paramName: string }): boolean {
60
- const { expression, paramName } = payload;
61
- if (expression.type === "LogicalExpression") {
62
- return (
63
- isFieldSignalBody({ expression: expression.left, paramName }) &&
64
- isFieldSignalBody({ expression: expression.right, paramName })
65
- );
66
- }
67
- if (expression.type === "UnaryExpression" && expression.operator === "!") {
68
- return isFieldSignalBody({ expression: expression.argument, paramName });
69
- }
70
- if (expression.type === "ParenthesizedExpression") {
71
- return isFieldSignalBody({ expression: expression.expression, paramName });
72
- }
73
- if (expression.type === "BinaryExpression" && COMPARISON_OPERATORS.has(expression.operator)) {
74
- const fieldOnLeft = isParamField({ expression: expression.left, paramName });
75
- const literalOnRight = isLiteralExpression(expression.right);
76
- const fieldOnRight = isParamField({ expression: expression.right, paramName });
77
- const literalOnLeft = isLiteralExpression(expression.left);
78
- return (fieldOnLeft && literalOnRight) || (fieldOnRight && literalOnLeft);
79
- }
80
- return false;
81
- }
82
-
83
- /**
84
- * Build a predicate-analysis candidate when the function reads as a boolean
85
- * classification derived solely from comparing one typed parameter's fields.
86
- *
87
- * @param {PredicateFunction} node - The exported function node under analysis.
88
- * @returns {PredicateCandidate | null} The candidate, or null when not a field-signal predicate.
89
- */
90
- function candidateFrom(
91
- node: PredicateFunction,
92
- ): PredicateCandidate | null {
93
- if (node.returnType === null || node.returnType === undefined) return null;
94
- const returnType = node.returnType.typeAnnotation;
95
- if (returnType.type !== "TSBooleanKeyword") return null;
96
- if (node.params.length !== 1) return null;
97
- const firstParam = node.params[0];
98
- if (firstParam === undefined) return null;
99
- const annotation = parameterAnnotation(firstParam);
100
- if (annotation === null || annotation === undefined) return null;
101
- const typeName = referencedTypeName(annotation.typeAnnotation);
102
- if (typeName === null) return null;
103
- let body: ESTree.Expression | null = null;
104
- if (node.body !== null && node.body !== undefined) {
105
- if (node.body.type === "BlockStatement") {
106
- const only = node.body.body.length === 1 ? node.body.body[0] : undefined;
107
- if (only !== undefined && only.type === "ReturnStatement" && only.argument !== null) {
108
- body = only.argument;
109
- }
110
- } else {
111
- body = node.body;
112
- }
113
- }
114
- if (body === null) return null;
115
- if (
116
- !isFieldSignalBody({
117
- expression: body,
118
- paramName: firstParam.type === "Identifier" ? firstParam.name : "",
119
- })
120
- ) {
121
- return null;
122
- }
123
- return { node, typeName };
124
- }
125
-
126
- const AUXILIARIES = new Set(["is", "has", "can", "should", "was", "will", "did", "be", "the"]);
127
-
128
- /** Split a camelCase/separator name into lowercase tokens, dropping auxiliary prefixes like `is`/`has`.
129
- *
130
- * @param {string} name - The name to tokenise.
131
- * @returns {string[]} Content-bearing lowercase tokens.
132
- */
133
- function contentTokens(name: string): string[] {
134
- return name
135
- .replaceAll(/([a-z0-9])([A-Z])/gu, "$1 $2")
136
- .split(/[^a-zA-Z0-9]+/u)
137
- .map((token) => token.toLowerCase())
138
- .filter((token) => token.length > 0 && !AUXILIARIES.has(token));
139
- }
140
-
141
- /** Accept both `{ members }` and flattened `{ body }` shapes for an interface/type-literal body.
142
- *
143
- * @param {ESTree.TSInterfaceBody | ESTree.TSTypeLiteral} bodyNode - The declared body node.
144
- * @returns {ESTree.TSSignature[]} The signature list.
145
- */
146
- function memberList(bodyNode: ESTree.TSInterfaceBody | ESTree.TSTypeLiteral): ESTree.TSSignature[] {
147
- const members = "body" in bodyNode ? bodyNode.body : bodyNode.members;
148
- return [...members];
149
- }
150
-
151
- /** Ban predicate families that re-derive classification, and un-guarded construction. */
152
- export const noBooleanFieldSignalsRule = defineRule({
153
- meta: {
154
- type: "problem",
155
- docs: {
156
- description:
157
- "Disallow families of exported predicates over one type that re-test the same fields, constructors that produce un-guarded values, and boolean state products on declared types; classify (parse) once.",
158
- },
159
- messages: {
160
- reportPredicate:
161
- "Predicates over `{{type}}` each re-derive classification from the same field comparisons. Classify the value once into a named union (or comparable structure) and derive the predicates from it.",
162
- booleanFieldSignals:
163
- "Predicates over `{{type}}` each re-derive classification from the same field comparisons. Classify the value once into a named union (or comparable structure) and derive the predicates from it.",
164
- unguardedConstructor:
165
- "`{{type}}` is constructed directly by `make` yet inspected by a predicate family. Make the constructor a parser (normalise or return Option) so invalid states can't be produced.",
166
- booleanStateProduct:
167
- "`{{name}}` carries {{count}} boolean {{kind}} admitting invalid combinations. Classify once into a named union over that state so impossible combinations can't be represented, and derive any predicates from it.",
168
- },
169
- },
170
- createOnce(context) {
171
- const pending = new Map<string, PredicateCandidate>();
172
- const reported = new Set<string>();
173
- const constructors = new Map<string, ESTree.Function[]>();
174
-
175
- const reportPredicate = (candidate: PredicateCandidate) => {
176
- context.report({
177
- node: candidate.node,
178
- messageId: "booleanFieldSignals",
179
- data: { type: candidate.typeName },
180
- });
181
- };
182
-
183
- const flushConstructors = (typeName: string) => {
184
- const list = constructors.get(typeName);
185
- if (list === undefined) return;
186
- for (const node of list) {
187
- context.report({ node, messageId: "unguardedConstructor", data: { type: typeName } });
188
- }
189
- constructors.delete(typeName);
190
- };
191
-
192
- const recordPredicate = (candidate: PredicateCandidate | null) => {
193
- if (candidate === null) return;
194
- if (reported.has(candidate.typeName)) {
195
- reportPredicate(candidate);
196
- return;
197
- }
198
- const first = pending.get(candidate.typeName);
199
- if (first !== undefined) {
200
- reportPredicate(first);
201
- reportPredicate(candidate);
202
- reported.add(candidate.typeName);
203
- pending.delete(candidate.typeName);
204
- flushConstructors(candidate.typeName);
205
- return;
206
- }
207
- pending.set(candidate.typeName, candidate);
208
- };
209
-
210
- const recordConstructor = (typeName: string | null, node: ESTree.Function) => {
211
- if (typeName === null) return;
212
- if (reported.has(typeName)) {
213
- context.report({ node, messageId: "unguardedConstructor", data: { type: typeName } });
214
- return;
215
- }
216
- const list = constructors.get(typeName) ?? [];
217
- list.push(node);
218
- constructors.set(typeName, list);
219
- };
220
-
221
- const checkDeclaredBody = (reportNode: ESTree.Node, members: ESTree.TSSignature[], typeName: string): void => {
222
- const booleanNames = members.flatMap((member) => {
223
- if (member.type !== "TSPropertySignature") return [];
224
- if (member.typeAnnotation?.typeAnnotation.type !== "TSBooleanKeyword") return [];
225
- return member.key.type === "Identifier" ? [member.key.name] : [];
226
- });
227
- if (booleanNames.length >= 3) {
228
- context.report({
229
- node: reportNode,
230
- messageId: "booleanStateProduct",
231
- data: { name: typeName, count: String(booleanNames.length), kind: "flags" },
232
- });
233
- return;
234
- }
235
- for (let i = 0; i < booleanNames.length; i += 1) {
236
- for (let j = i + 1; j < booleanNames.length; j += 1) {
237
- const first = contentTokens(booleanNames[i] ?? "");
238
- const second = contentTokens(booleanNames[j] ?? "");
239
- const shared = first.find((token) => second.includes(token));
240
- if (shared === undefined) continue;
241
- context.report({
242
- node: reportNode,
243
- messageId: "booleanStateProduct",
244
- data: { name: `${booleanNames[i]}/${booleanNames[j]}`, count: "2", kind: `flags over \`${shared}\`` },
245
- });
246
- return;
247
- }
248
- }
249
- };
250
-
251
- const handle = (name: string, fn: PredicateFunction, rawNode: ESTree.Node) => {
252
- const firstParameter = fn.params[0];
253
- const boundParameter =
254
- firstParameter === undefined
255
- ? null
256
- : firstParameter.type === "Identifier"
257
- ? firstParameter.name
258
- : firstParameter.type === "AssignmentPattern" && firstParameter.left.type === "Identifier"
259
- ? firstParameter.left.name
260
- : null;
261
- if (boundParameter !== null) recordPredicate(candidateFrom(fn));
262
- const declaredReturn =
263
- fn.returnType === null || fn.returnType === undefined
264
- ? null
265
- : referencedTypeName(fn.returnType.typeAnnotation);
266
- const ctorReturn = CONSTRUCTOR_NAME.test(name) ? declaredReturn : null;
267
- if (
268
- ctorReturn !== null &&
269
- (fn.type === "FunctionDeclaration" || fn.type === "FunctionExpression") &&
270
- fn.id !== null
271
- ) {
272
- recordConstructor(ctorReturn, fn);
273
- }
274
- };
275
-
276
- return {
277
- ExportNamedDeclaration(node) {
278
- const declaration = node.declaration;
279
- if (declaration === null) return;
280
- if (declaration.type === "FunctionDeclaration") {
281
- if (declaration.id !== null) handle(declaration.id.name, declaration, declaration);
282
- return;
283
- }
284
- if (declaration.type !== "VariableDeclaration") return;
285
- for (const declarator of declaration.declarations) {
286
- const init = declarator.init;
287
- if (init === null || init === undefined || init.type !== "ArrowFunctionExpression") continue;
288
- if (declarator.id.type !== "Identifier") continue;
289
- handle(declarator.id.name, init, declarator);
290
- }
291
- },
292
- TSInterfaceDeclaration(node) {
293
- checkDeclaredBody(
294
- node,
295
- memberList(node.body),
296
- node.id.type === "Identifier" ? node.id.name : "anonymous interface",
297
- );
298
- },
299
- TSTypeAliasDeclaration(node) {
300
- if (node.typeAnnotation.type !== "TSTypeLiteral") return;
301
- checkDeclaredBody(node, node.typeAnnotation.members, node.id.name);
302
- },
303
- };
304
- },
305
- });
@@ -1,83 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import type { ESTree } from "@oxlint/plugins";
4
- import { firstOptionRecord } from "../shared/rule-options.ts";
5
- import { isRecordObject, isString } from "../shared/structural.ts";
6
-
7
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
8
-
9
- /** Generic built-in errors: untyped, prose-only, and invisible to tag-based handling. */
10
- const BUILTIN_ERRORS: ReadonlySet<string> = new Set([
11
- "Error",
12
- "EvalError",
13
- "RangeError",
14
- "ReferenceError",
15
- "SyntaxError",
16
- "TypeError",
17
- "URIError",
18
- "AggregateError",
19
- ]);
20
-
21
- interface Options {
22
- readonly allow?: ReadonlyArray<string>;
23
- }
24
-
25
- /**
26
- * Unwrap parenthesized expressions to the underlying expression.
27
- *
28
- * @param {ESTree.Expression} expression - The expression to unwrap.
29
- * @returns {ESTree.Expression} The first non-parenthesized inner expression.
30
- */
31
- function unwrapParentheses(expression: ESTree.Expression): ESTree.Expression {
32
- let current = expression;
33
- while (current.type === "ParenthesizedExpression") current = current.expression;
34
- return current;
35
- }
36
-
37
- /**
38
- * Flag throwing generic built-in errors at call sites that should instead throw
39
- * a project-defined tagged error carrying its evidence structurally (e.g.
40
- * Data.TaggedError with operation/value/domain fields plus a rendered message).
41
- */
42
- export const noBuiltinThrowsRule = defineRule({
43
- meta: {
44
- type: "problem",
45
- docs: {
46
- description:
47
- "Disallow throwing built-in Error constructors; require project-defined tagged error classes so defects carry structured evidence and can be matched by tag.",
48
- },
49
- messages: {
50
- noBuiltinThrows:
51
- "Throwing the built-in `{{builtin}}` loses structure: consumers get prose only. Throw a project-defined tagged error (e.g. Data.TaggedError) whose fields carry the operation, offending value, and domain, and render this context as its message.",
52
- },
53
- schema: [
54
- {
55
- type: "object",
56
- properties: {
57
- allow: { type: "array", items: { type: "string" } },
58
- },
59
- additionalProperties: false,
60
- },
61
- ],
62
- defaultOptions: [{ allow: [] }],
63
- },
64
- createOnce(context) {
65
- const option = firstOptionRecord(context.options);
66
- const allowed: ReadonlySet<string> = new Set(
67
- Array.isArray(option.allow) ? option.allow.filter(isString) : [],
68
- );
69
- return {
70
- before() {
71
- if (TEST_FILE.test(context.filename.replaceAll("\\", "/"))) return false;
72
- },
73
- ThrowStatement(node) {
74
- const argument = node.argument === null || node.argument === undefined ? undefined : unwrapParentheses(node.argument);
75
- if (argument?.type !== "NewExpression") return;
76
- if (argument.callee.type !== "Identifier") return;
77
- const builtin = argument.callee.name;
78
- if (!BUILTIN_ERRORS.has(builtin) || allowed.has(builtin)) return;
79
- context.report({ node, messageId: "noBuiltinThrows", data: { builtin } });
80
- },
81
- };
82
- },
83
- });
@@ -1,65 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- import type { ESTree } from "@oxlint/plugins";
3
- import { ancestorsOf } from "../shared/ancestors.ts";
4
-
5
- type TypeAssertionExpression = ESTree.TSAsExpression | ESTree.TSTypeAssertion;
6
-
7
- /** Disallow nested TypeScript type assertions, while permitting chains made only of const assertions. */
8
- export const noChainedTypeAssertionsRule = defineRule({
9
- meta: {
10
- type: "problem",
11
- docs: {
12
- description:
13
- "Disallow chained TypeScript as and angle-bracket assertions, including parenthesized chains.",
14
- },
15
- messages: {
16
- chained:
17
- "This assertion chain discards type evidence. Keep the original precise type, or parse untrusted input at its boundary before narrowing it.",
18
- },
19
- },
20
- createOnce(context) {
21
- const checkTypeAssertion = (node: TypeAssertionExpression) => {
22
- const ancestors = ancestorsOf(context.sourceCode, node);
23
-
24
- let current: ESTree.Expression = node;
25
- let index = ancestors.length - 1;
26
- while (index >= 0) {
27
- const parent = ancestors[index]!;
28
- if (parent.type !== "ParenthesizedExpression" || parent.expression !== current) break;
29
- current = parent;
30
- index -= 1;
31
- }
32
- const outermost = ancestors[index];
33
- if (
34
- outermost !== undefined &&
35
- (outermost.type === "TSAsExpression" || outermost.type === "TSTypeAssertion") &&
36
- outermost.expression === current
37
- )
38
- return;
39
-
40
- let assertionCount = 0;
41
- let hasNonConstAssertion = false;
42
- current = node;
43
- while (current.type === "TSAsExpression" || current.type === "TSTypeAssertion") {
44
- assertionCount += 1;
45
- const { typeAnnotation } = current;
46
- hasNonConstAssertion ||= !(
47
- typeAnnotation.type === "TSTypeReference" &&
48
- typeAnnotation.typeName.type === "Identifier" &&
49
- typeAnnotation.typeName.name === "const"
50
- );
51
- let next: ESTree.Expression = current.expression;
52
- while (next.type === "ParenthesizedExpression") next = next.expression;
53
- current = next;
54
- }
55
- if (assertionCount > 1 && hasNonConstAssertion) {
56
- context.report({ node, messageId: "chained" });
57
- }
58
- };
59
-
60
- return {
61
- TSAsExpression: checkTypeAssertion,
62
- TSTypeAssertion: checkTypeAssertion,
63
- };
64
- },
65
- });
@@ -1,42 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- import type { ESTree } from "@oxlint/plugins";
3
- import { ancestorsOf } from "../shared/ancestors.ts";
4
-
5
- function isEmptyObjectExpression(node: ESTree.Expression): boolean {
6
- return node.type === "ObjectExpression" && node.properties.length === 0;
7
- }
8
-
9
- /** Ban conditional empty-object spreads without changing their omission semantics. */
10
- export const noConditionalEmptyObjectSpreadRule = defineRule({
11
- meta: {
12
- type: "suggestion",
13
- docs: {
14
- description:
15
- "Disallow object spreads that conditionally spread an empty object to omit fields.",
16
- },
17
- messages: {
18
- avoid:
19
- "This conditional spread hides property omission behind an empty object. Build the object in separate statements and add the property only when present.",
20
- },
21
- },
22
- createOnce(context) {
23
- return {
24
- SpreadElement(node) {
25
- const parent = ancestorsOf(context.sourceCode, node).at(-1);
26
- if (parent?.type !== "ObjectExpression") return;
27
-
28
- let conditional = node.argument;
29
- while (conditional.type === "ParenthesizedExpression") {
30
- conditional = conditional.expression;
31
- }
32
- const emptyObjectOmission =
33
- conditional.type === "ConditionalExpression" &&
34
- (isEmptyObjectExpression(conditional.consequent) ||
35
- isEmptyObjectExpression(conditional.alternate));
36
- if (emptyObjectOmission) {
37
- context.report({ node, messageId: "avoid" });
38
- }
39
- },
40
- };
41
- },
42
- });
@@ -1,66 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import type { ESTree } from "@oxlint/plugins";
4
- import { isRecordObject, isString } from "../shared/structural.ts";
5
-
6
- /** Sorted string-literal members of a union annotation, or null if it isn't one.
7
- *
8
- * @param {ESTree.TSType} annotation - The annotation to inspect.
9
- * @returns {string[] | null} Sorted literal members, or null when not a literal union.
10
- */
11
- function literalUnionKey(annotation: ESTree.TSType): string[] | null {
12
- const types = annotation.type === "TSUnionType" ? annotation.types : [annotation];
13
- const literals: string[] = [];
14
- for (const member of types) {
15
- if (member.type !== "TSLiteralType" || member.literal.type !== "Literal") return null;
16
- if (!isString(member.literal.value)) return null;
17
- literals.push(member.literal.value);
18
- }
19
- return [...literals].sort((a, b) => a.localeCompare(b));
20
- }
21
-
22
- /**
23
- * One fact, one place: a set of variants declared twice drifts the moment
24
- * someone adds a member to one copy. Declare each variant set once and
25
- * derive every use from it.
26
- */
27
- export const noDuplicatedLiteralUnionRule = defineRule({
28
- meta: {
29
- type: "problem",
30
- docs: {
31
- description:
32
- "Disallow string-literal unions whose exact member set is declared by more than one alias in a file; declare the variant set once.",
33
- },
34
- messages: {
35
- duplicateUnion:
36
- "`{{second}}` declares exactly the variant set of `{{first}}`: two sources of truth that will drift when a member is added to one. Export `{{first}}` and reuse it (or rename if coincidental).",
37
- },
38
- },
39
- createOnce(context) {
40
- const seen = new Map<string, string>();
41
- const duplicates = new Map<string, { node: ESTree.Node; name: string; first: string }>();
42
-
43
- return {
44
- TSTypeAliasDeclaration(node) {
45
- const key = literalUnionKey(node.typeAnnotation);
46
- if (key === null) return;
47
- const joined = key.join("\u0000");
48
- const first = seen.get(joined);
49
- if (first === undefined) {
50
- seen.set(joined, node.id.name);
51
- return;
52
- }
53
- duplicates.set(`${joined}\u0000${node.id.name}`, { node, name: node.id.name, first });
54
- },
55
- "Program:exit"() {
56
- for (const duplicate of duplicates.values()) {
57
- context.report({
58
- node: duplicate.node,
59
- messageId: "duplicateUnion",
60
- data: { second: duplicate.name, first: duplicate.first },
61
- });
62
- }
63
- },
64
- };
65
- },
66
- });
@@ -1,111 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import type { ESTree } from "@oxlint/plugins";
4
-
5
- const MUTATING_METHODS = new Set([
6
- "add",
7
- "clear",
8
- "copyWithin",
9
- "defineProperty",
10
- "delete",
11
- "fill",
12
- "pop",
13
- "push",
14
- "reverse",
15
- "set",
16
- "shift",
17
- "sort",
18
- "splice",
19
- "unshift",
20
- ]);
21
-
22
- /** Root identifier of an assignment target / call receiver, if statically simple.
23
- *
24
- * @param {ESTree.Node} node - The target or receiver expression.
25
- * @returns {string | null} The leftmost identifier's name, or null when dynamic.
26
- */
27
- function rootIdentifier(node: ESTree.Node): string | null {
28
- if (node.type === "Identifier") return node.name;
29
- if (node.type === "MemberExpression" && !node.computed) return rootIdentifier(node.object);
30
- if (node.type === "ParenthesizedExpression") return rootIdentifier(node.expression);
31
- return null;
32
- }
33
-
34
- /**
35
- * No blessed surface area: a value that escapes module scope mutably lets
36
- * every invariant its constructor established be broken from outside. Module
37
- * state must be immutable bindings over immutable structures; anything that
38
- * varies belongs in parameters, state objects or Effect services.
39
- */
40
- export const noExportedMutableStateRule = defineRule({
41
- meta: {
42
- type: "problem",
43
- docs: {
44
- description:
45
- "Disallow exported let/var bindings and mutation of module-scope values; keep module state immutable so construction-time invariants can't be broken.",
46
- },
47
- messages: {
48
- exportedBinding:
49
- "`{{name}}` is exported as a mutable binding, so importers can change it under every other consumer and break whatever invariants it carried. Export a `const`.",
50
- moduleMutation:
51
- "`{{name}}` lives at module scope, so this mutation is invisible shared state across every caller: the blessed-surface-area problem. Make it local, or hold it in explicit state/service passed by parameter.",
52
- },
53
- },
54
- createOnce(context) {
55
- let topLevelNames = new Set<string>();
56
-
57
- function checkTarget(node: ESTree.Node): void {
58
- const name = rootIdentifier(node);
59
- if (name === null || !topLevelNames.has(name)) return;
60
- context.report({ node, messageId: "moduleMutation", data: { name } });
61
- }
62
-
63
- function isMutatingCall(node: ESTree.Expression): boolean {
64
- if (node.type !== "CallExpression" || node.callee.type !== "MemberExpression") return false;
65
- const property = node.callee.property;
66
- return property.type === "Identifier" && MUTATING_METHODS.has(property.name);
67
- }
68
-
69
- return {
70
- Program(node) {
71
- topLevelNames = new Set(
72
- node.body.flatMap((statement) =>
73
- statement.type === "VariableDeclaration"
74
- ? statement.declarations.flatMap((declarator) =>
75
- declarator.id.type === "Identifier" ? [declarator.id.name] : [],
76
- )
77
- : (statement.type === "FunctionDeclaration" ||
78
- statement.type === "ClassDeclaration") &&
79
- statement.id !== null
80
- ? [statement.id.name]
81
- : [],
82
- ),
83
- );
84
- },
85
- ExportNamedDeclaration(node) {
86
- const declaration = node.declaration;
87
- if (declaration === null || declaration.type !== "VariableDeclaration") return;
88
- if (declaration.kind === "const") return;
89
- for (const declarator of declaration.declarations) {
90
- if (declarator.id.type !== "Identifier") continue;
91
- context.report({
92
- node,
93
- messageId: "exportedBinding",
94
- data: { name: declarator.id.name },
95
- });
96
- }
97
- },
98
- AssignmentExpression(node) {
99
- checkTarget(node.left);
100
- },
101
- UpdateExpression(node) {
102
- checkTarget(node.argument);
103
- },
104
- CallExpression(node) {
105
- if (!isMutatingCall(node)) return;
106
- if (node.callee.type !== "MemberExpression") return;
107
- checkTarget(node.callee.object);
108
- },
109
- };
110
- },
111
- });