@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,192 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import type { ESTree, SourceCode } from "@oxlint/plugins";
4
-
5
- import { readField } from "../shared/structural.ts";
6
-
7
- import { ancestorsOf } from "../shared/ancestors.ts";
8
-
9
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
10
-
11
- const DEFAULT_MAX_PARAMS = 1;
12
-
13
- /** Conventional HTTP method handler names, exempt inside framework route files. */
14
- const HTTP_METHOD_NAMES = new Set([
15
- "DELETE",
16
- "GET",
17
- "HEAD",
18
- "OPTIONS",
19
- "PATCH",
20
- "POST",
21
- "PUT",
22
- ]);
23
-
24
- const DEFAULT_ROUTE_BASENAMES = new Set(["route.ts", "route.tsx"]);
25
-
26
- interface Options {
27
- readonly exemptFunctionNames?: ReadonlyArray<string>;
28
- readonly exemptRouteBasenames?: ReadonlyArray<string>;
29
- }
30
-
31
- /** Structural view of a function-like visitor node. */
32
- interface FunctionLike {
33
- readonly params: ReadonlyArray<ESTree.ParamPattern>;
34
- }
35
-
36
- function parentOf(sourceCode: SourceCode, node: ESTree.Node): ESTree.Node | null {
37
- return ancestorsOf(sourceCode, node)[0] ?? null;
38
- }
39
-
40
- /**
41
- * Functions the module owns: declarations and named bindings, not callbacks.
42
- *
43
- * @param {SourceCode} sourceCode - The rule's source-code accessor.
44
- * @param {ESTree.Node} node - The visited function-like node.
45
- * @returns {boolean} True when the module owns the function's arity.
46
- */
47
- function isOwnedFunction(sourceCode: SourceCode, node: ESTree.Node): boolean {
48
- if (node.type === "FunctionDeclaration") return true;
49
- const parent = parentOf(sourceCode, node);
50
- if (parent === null) return false;
51
- const parentType = parent.type;
52
- if (
53
- parentType === "CallExpression" ||
54
- parentType === "NewExpression" ||
55
- parentType === "JSXExpressionContainer"
56
- ) {
57
- return false;
58
- }
59
- return (
60
- parentType === "VariableDeclarator" ||
61
- parentType === "AssignmentExpression" ||
62
- parentType === "ExportDefaultDeclaration"
63
- );
64
- }
65
-
66
- interface ResolvedOptions {
67
- methodNames: ReadonlySet<string>;
68
- routeBasenames: ReadonlySet<string>;
69
- }
70
-
71
- /**
72
- * Exported HTTP-method-named handlers in framework route files own their arity.
73
- *
74
- * @param {{ options: ResolvedOptions; baseName: string; sourceCode: SourceCode; node: ESTree.Node }} payload - Exemption inputs.
75
- * @returns {boolean} True when the handler is an exempt route handler.
76
- */
77
- function isExemptRouteHandler(payload: {
78
- options: ResolvedOptions;
79
- baseName: string;
80
- sourceCode: SourceCode;
81
- node: ESTree.Node;
82
- }): boolean {
83
- if (payload.node.type !== "FunctionDeclaration") return false;
84
- const name = payload.node.id?.name;
85
- if (name === undefined || !payload.options.methodNames.has(name)) return false;
86
- if (!payload.options.routeBasenames.has(payload.baseName)) return false;
87
- const parent = parentOf(payload.sourceCode, payload.node);
88
- return parent !== null && parent.type === "ExportNamedDeclaration";
89
- }
90
-
91
- /** Primitive annotations transpose silently; structural ones fail the compiler. */
92
- const PRIMITIVE_TYPE_TEXT = /^(?:string|number|bigint|boolean|unknown|any|null|undefined|void)$/u;
93
-
94
- /**
95
- * Whether every positional parameter carries a distinct non-primitive type:
96
- * transposing such arguments is a compile error, so ordering needs no guard.
97
- *
98
- * @param {SourceCode} sourceCode - The rule's source-code accessor.
99
- * @param {ReadonlyArray<ESTree.ParamPattern>} params - The parameter list to inspect.
100
- * @returns {boolean} True when transposing any pair fails the compiler.
101
- */
102
- function transpositionSafe(
103
- sourceCode: SourceCode,
104
- params: ReadonlyArray<ESTree.ParamPattern>,
105
- ): boolean {
106
- const texts: Array<string> = [];
107
- for (const param of params) {
108
- if (param.type !== "Identifier") return false;
109
- const annotation = param.typeAnnotation;
110
- if (annotation === null || annotation === undefined) return false;
111
- const text = sourceCode.getText(annotation.typeAnnotation).replaceAll(" ", "");
112
- if (text === "" || PRIMITIVE_TYPE_TEXT.test(text)) return false;
113
- texts.push(text);
114
- }
115
- return new Set(texts).size === texts.length;
116
- }
117
-
118
- /** Owned functions taking several positional inputs accept transposed arguments silently; require one payload object. */
119
- export const noMultipleFunctionParamsRule = defineRule({
120
- meta: {
121
- type: "problem",
122
- docs: {
123
- description:
124
- "Disallow owned functions with more than one positional parameter; collapse multiple inputs into a single named payload object so transposed arguments fail the compiler.",
125
- },
126
- messages: {
127
- multipleParams:
128
- "`{{name}}` takes {{count}} positional parameters. Accept a single named payload object instead; transposed primitive arguments compile silently.",
129
- },
130
- },
131
- createOnce(context) {
132
- const rawOptions = readField<ReadonlyArray<Options>>(context, "options");
133
- const options: ResolvedOptions = {
134
- methodNames: new Set(rawOptions?.[0]?.exemptFunctionNames ?? HTTP_METHOD_NAMES),
135
- routeBasenames: new Set(
136
- rawOptions?.[0]?.exemptRouteBasenames ?? DEFAULT_ROUTE_BASENAMES,
137
- ),
138
- };
139
- let fileBase = "";
140
- const check = (node: ESTree.Node): void => {
141
- if (
142
- node.type !== "FunctionDeclaration" &&
143
- node.type !== "FunctionExpression" &&
144
- node.type !== "ArrowFunctionExpression"
145
- )
146
- return;
147
- const fn = node;
148
- if (fn.params.length <= DEFAULT_MAX_PARAMS) return;
149
- if (!isOwnedFunction(context.sourceCode, node)) return;
150
- if (transpositionSafe(context.sourceCode, fn.params)) return;
151
- if (
152
- isExemptRouteHandler({
153
- options,
154
- baseName: fileBase,
155
- sourceCode: context.sourceCode,
156
- node,
157
- })
158
- )
159
- return;
160
- let name = "(anonymous)";
161
- if (node.id !== null && node.id !== undefined) {
162
- name = node.id.name;
163
- } else {
164
- const parent = parentOf(context.sourceCode, node);
165
- if (parent?.type === "VariableDeclarator" && parent.id.type === "Identifier") {
166
- name = parent.id.name;
167
- } else if (
168
- parent?.type === "AssignmentExpression" &&
169
- parent.left.type === "Identifier"
170
- ) {
171
- name = parent.left.name;
172
- }
173
- }
174
- context.report({
175
- node,
176
- messageId: "multipleParams",
177
- data: { name, count: String(fn.params.length) },
178
- });
179
- };
180
- return {
181
- before() {
182
- const normalized = context.filename.replaceAll("\\", "/");
183
- const segments = normalized.split("/");
184
- fileBase = segments[segments.length - 1] ?? normalized;
185
- if (TEST_FILE.test(normalized)) return false;
186
- },
187
- FunctionDeclaration: check,
188
- FunctionExpression: check,
189
- ArrowFunctionExpression: check,
190
- };
191
- },
192
- });
@@ -1,73 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import type { ESTree } from "@oxlint/plugins";
4
-
5
- const NONDETERMINISTIC_MEMBERS = new Set(["getRandomValues", "random", "randomUUID", "now"]);
6
-
7
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$|\/test\//u;
8
-
9
- function memberChain(node: ESTree.Node): string[] {
10
- if (node.type === "MemberExpression" && !node.computed) {
11
- return [...memberChain(node.object), node.property.type === "Identifier" ? node.property.name : ""];
12
- }
13
- return [node.type === "Identifier" ? node.name : "?"];
14
- }
15
-
16
- /**
17
- * Canonical form: identical inputs must produce identical outputs. Time and
18
- * randomness are boundary inputs: capture them once at the edge and pass
19
- * them in, so cores stay reproducible and their serialisations stable.
20
- */
21
- export const noNondeterministicCoreRule = defineRule({
22
- meta: {
23
- type: "problem",
24
- docs: {
25
- description:
26
- "Disallow nondeterministic sources (Math.random, Date.now, new Date(), crypto randomness) outside tests; inject them as boundary inputs so cores stay canonical.",
27
- },
28
- messages: {
29
- nondeterministicSource:
30
- "`{{source}}` makes this code's output depend on when/where it runs, breaking canonical form (identical inputs, identical outputs). Capture it at the boundary and pass it in as a parameter.",
31
- unseededDate:
32
- "`new Date()` captures wall-clock time here, making output non-reproducible. Take the instant as a parameter (or use a fixed epoch for pure conversions).",
33
- },
34
- },
35
- createOnce(context) {
36
- return {
37
- before() {
38
- if (TEST_FILE.test(context.filename.replaceAll("\\", "/"))) return false;
39
- },
40
- MemberExpression(node) {
41
- const property = node.property;
42
- if (node.computed || property.type !== "Identifier" || !NONDETERMINISTIC_MEMBERS.has(property.name)) {
43
- return;
44
- }
45
- const chain = memberChain(node.object);
46
- const root = chain[0] ?? "";
47
- if ((root === "Math" && property.name === "random") || (root === "crypto" && property.name !== "now")) {
48
- context.report({
49
- node,
50
- messageId: "nondeterministicSource",
51
- data: { source: `${root}.${property.name}` },
52
- });
53
- return;
54
- }
55
- if (
56
- property.name === "now" &&
57
- ((root === "Date" && chain.length === 1) || (root === "performance" && chain.length === 1))
58
- ) {
59
- context.report({
60
- node,
61
- messageId: "nondeterministicSource",
62
- data: { source: `${root}.now` },
63
- });
64
- }
65
- },
66
- NewExpression(node) {
67
- if (node.callee.type === "Identifier" && node.callee.name === "Date" && node.arguments.length === 0) {
68
- context.report({ node, messageId: "unseededDate" });
69
- }
70
- },
71
- };
72
- },
73
- });
@@ -1,127 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import type { ESTree, SourceCode } from "@oxlint/plugins";
4
- import { ancestorsOf } from "../shared/ancestors.ts";
5
-
6
- import { lexicalTypeParameterNames } from "../shared/lexical-type-parameters.ts";
7
-
8
- type Parameter = ESTree.ParamPattern;
9
- type ParameterOwner =
10
- | ESTree.ArrowFunctionExpression
11
- | ESTree.Function
12
- | ESTree.TSCallSignatureDeclaration
13
- | ESTree.TSConstructSignatureDeclaration
14
- | ESTree.TSConstructorType
15
- | ESTree.TSFunctionType
16
- | ESTree.TSMethodSignature;
17
-
18
- function parameterAnnotation(parameter: Parameter): ESTree.TSTypeAnnotation | null | undefined {
19
- if (parameter.type === "TSParameterProperty") {
20
- return parameterAnnotation(parameter.parameter);
21
- }
22
- if (parameter.type === "RestElement") {
23
- return parameter.typeAnnotation ?? parameterAnnotation(parameter.argument);
24
- }
25
- if (parameter.type === "AssignmentPattern") {
26
- return parameter.typeAnnotation ?? parameter.left.typeAnnotation;
27
- }
28
- return parameter.typeAnnotation;
29
- }
30
-
31
- /** Ban the broad object type on function inputs, including local aliases to object. */
32
- export const noObjectParametersRule = defineRule({
33
- meta: {
34
- type: "problem",
35
- docs: {
36
- description:
37
- "Disallow object function parameters; inputs must use an owner-provided type and be parsed at their boundary.",
38
- },
39
- messages: {
40
- objectParameter:
41
- "Parameter `{{parameter}}` uses the broad `object` type. Accept a named owner type; parse external input at its boundary before calling this function.",
42
- },
43
- },
44
- createOnce(context) {
45
- const aliases = new Map<string, ESTree.TSType>();
46
-
47
- const resolvesToObject = (
48
- type: ESTree.TSType,
49
- shadowedAliases: ReadonlySet<string>,
50
- visited = new Set<string>(),
51
- ): boolean => {
52
- if (type.type === "TSObjectKeyword") return true;
53
- if (type.type === "TSParenthesizedType")
54
- return resolvesToObject(type.typeAnnotation, shadowedAliases, visited);
55
- if (type.type === "TSUnionType") {
56
- return type.types.some((member) =>
57
- resolvesToObject(member, shadowedAliases, visited),
58
- );
59
- }
60
- if (
61
- type.type !== "TSTypeReference" ||
62
- type.typeName.type !== "Identifier" ||
63
- (type.typeArguments !== null &&
64
- type.typeArguments !== undefined &&
65
- type.typeArguments.params.length > 0) ||
66
- visited.has(type.typeName.name) ||
67
- shadowedAliases.has(type.typeName.name)
68
- ) {
69
- return false;
70
- }
71
- const alias = aliases.get(type.typeName.name);
72
- if (alias === undefined) return false;
73
- const nextVisited = new Set(visited);
74
- nextVisited.add(type.typeName.name);
75
- return resolvesToObject(alias, shadowedAliases, nextVisited);
76
- };
77
-
78
- const checkParameters = (node: ParameterOwner) => {
79
- const shadowedAliases = lexicalTypeParameterNames(
80
- node,
81
- ancestorsOf(context.sourceCode, node),
82
- context.sourceCode.visitorKeys,
83
- );
84
- for (const parameter of node.params) {
85
- const annotation = parameterAnnotation(parameter);
86
- if (annotation === null || annotation === undefined) continue;
87
- if (!resolvesToObject(annotation.typeAnnotation, shadowedAliases)) continue;
88
- context.report({
89
- node: annotation.typeAnnotation,
90
- messageId: "objectParameter",
91
- data: {
92
- parameter:
93
- parameter.type === "Identifier"
94
- ? parameter.name
95
- : context.sourceCode.getText(parameter).replace(/\s*:\s*object\s*$/u, ""),
96
- },
97
- });
98
- }
99
- };
100
-
101
- return {
102
- Program(node) {
103
- aliases.clear();
104
- for (const statement of node.body) {
105
- const declaration =
106
- statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
107
- if (
108
- declaration?.type === "TSTypeAliasDeclaration" &&
109
- (declaration.typeParameters === null || declaration.typeParameters === undefined)
110
- ) {
111
- aliases.set(declaration.id.name, declaration.typeAnnotation);
112
- }
113
- }
114
- },
115
- ArrowFunctionExpression: checkParameters,
116
- FunctionDeclaration: checkParameters,
117
- FunctionExpression: checkParameters,
118
- TSCallSignatureDeclaration: checkParameters,
119
- TSConstructSignatureDeclaration: checkParameters,
120
- TSConstructorType: checkParameters,
121
- TSDeclareFunction: checkParameters,
122
- TSEmptyBodyFunctionExpression: checkParameters,
123
- TSFunctionType: checkParameters,
124
- TSMethodSignature: checkParameters,
125
- };
126
- },
127
- });
@@ -1,49 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import type { ESTree } from "@oxlint/plugins";
4
-
5
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
6
-
7
- /**
8
- * Optional parameters hide undefined from the signature; require the union spelled out.
9
- *
10
- * Optionality is a grammar-level flag present on every concrete ParamPattern
11
- * shape, read after unwrapping TypeScript parameter-property wrappers.
12
- */
13
- export const noOptionalFunctionParametersRule = defineRule({
14
- meta: {
15
- type: "problem",
16
- docs: {
17
- description:
18
- "Disallow optional function parameters (`param?:`); require an explicit union with undefined so callers see the possibility in the type.",
19
- },
20
- messages: {
21
- optionalParameter:
22
- "Optional parameters hide `undefined` from callers. Annotate the parameter as `T | undefined` so the possibility is spelled out in the type.",
23
- },
24
- },
25
- createOnce(context) {
26
- const check = (node: ESTree.Node): void => {
27
- if (
28
- node.type !== "FunctionDeclaration" &&
29
- node.type !== "FunctionExpression" &&
30
- node.type !== "ArrowFunctionExpression"
31
- )
32
- return;
33
- for (const parameter of node.params) {
34
- let pattern = parameter;
35
- if (pattern.type === "TSParameterProperty") pattern = pattern.parameter;
36
- if (pattern.optional !== true) continue;
37
- context.report({ node: parameter, messageId: "optionalParameter" });
38
- }
39
- };
40
- return {
41
- before() {
42
- if (TEST_FILE.test(context.filename.replaceAll("\\", "/"))) return false;
43
- },
44
- FunctionDeclaration: check,
45
- FunctionExpression: check,
46
- ArrowFunctionExpression: check,
47
- };
48
- },
49
- });
@@ -1,80 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import type { ESTree } from "@oxlint/plugins";
4
- import { readField } from "../shared/structural.ts";
5
- import { ancestorsOf } from "../shared/ancestors.ts";
6
-
7
- function lastTypeNameSegment(typeName: ESTree.Node): string | null {
8
- if (typeName.type === "Identifier") return typeName.name;
9
- if (typeName.type === "TSQualifiedName") return lastTypeNameSegment(typeName.right);
10
- return null;
11
- }
12
-
13
- /**
14
- * Returns the enclosing TSPropertySignature when the literal is a variant
15
- * payload of a Data.TaggedEnum (i.e. `{ Variant: Payload }` inside the enum's
16
- * type argument), otherwise null.
17
- *
18
- * @param {ESTree.TSTypeLiteral} node - The visited type literal (candidate payload).
19
- * @param {ReadonlyArray<ESTree.Node>} ancestors - Nearest-first ancestor chain of `node`.
20
- * @returns {ESTree.TSPropertySignature | null} The variant property signature, or null.
21
- */
22
- function variantPayloadSignature(
23
- node: ESTree.TSTypeLiteral,
24
- ancestors: ReadonlyArray<ESTree.Node>,
25
- ): ESTree.TSPropertySignature | null {
26
- const at = (depth: number): ESTree.Node | undefined => ancestors[ancestors.length - 1 - depth];
27
- const annotation = at(0);
28
- if (annotation?.type !== "TSTypeAnnotation") return null;
29
- const signature = at(1);
30
- if (signature?.type !== "TSPropertySignature") return null;
31
- const outer = at(2);
32
- if (outer?.type !== "TSTypeLiteral") return null;
33
- const args = at(3);
34
- if (args === undefined) return null;
35
- const reference = at(4);
36
- if (reference?.type !== "TSTypeReference") return null;
37
- const name = lastTypeNameSegment(reference.typeName);
38
- return name !== null && /TaggedEnum$/u.test(name) ? signature : null;
39
- }
40
-
41
- /** A product of booleans inside a variant tends to admit an illegal combination. */
42
- export const noProductOfStateBooleansRule = defineRule({
43
- meta: {
44
- type: "problem",
45
- docs: {
46
- description:
47
- "Disallow tagged-enum variant payloads with two or more boolean state flags; replace them with a nested tag union so impossible combinations can't be represented.",
48
- },
49
- messages: {
50
- productOfStateBooleans:
51
- "Variant payload `{{name}}` carries {{count}} boolean state flags. Replace them with a nested tag union (e.g. Sign) so combinations like {zero, negative} can't be represented.",
52
- },
53
- },
54
- createOnce(context) {
55
- return {
56
- TSTypeLiteral(node) {
57
- const signature = variantPayloadSignature(
58
- node,
59
- ancestorsOf(context.sourceCode, node),
60
- );
61
- if (signature === null) return;
62
- let count = 0;
63
- for (const member of node.members) {
64
- if (member.type !== "TSPropertySignature") continue;
65
- const annotation = member.typeAnnotation;
66
- if (annotation === null || annotation === undefined) continue;
67
- if (annotation.typeAnnotation.type === "TSBooleanKeyword") count += 1;
68
- }
69
- if (count < 2) return;
70
- const key = signature.key;
71
- const name = key.type === "Identifier" ? key.name : "variant";
72
- context.report({
73
- node,
74
- messageId: "productOfStateBooleans",
75
- data: { name, count: String(count) },
76
- });
77
- },
78
- };
79
- },
80
- });