@autotelic/plumb 0.5.2 → 0.6.1

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 (282) hide show
  1. package/README.md +81 -8
  2. package/dist/configs/recommended-rules.d.ts +36 -0
  3. package/dist/configs/recommended-rules.js +57 -0
  4. package/dist/effect/index.js +4 -0
  5. package/dist/effect/rules/guarded-op-must-return-effect.js +1 -1
  6. package/dist/effect/rules/no-cascading-layer-provide.js +1 -1
  7. package/dist/effect/rules/no-decode-unknown-option.js +1 -1
  8. package/dist/effect/rules/no-direct-browser-storage.js +3 -3
  9. package/dist/effect/rules/no-direct-fetch.js +1 -1
  10. package/dist/effect/rules/no-manual-field-guards.js +1 -1
  11. package/dist/effect/rules/no-nested-layer-provide.js +1 -1
  12. package/dist/effect/rules/no-nullish-default-on-partial-input.d.ts +13 -0
  13. package/dist/effect/rules/no-nullish-default-on-partial-input.js +109 -0
  14. package/dist/effect/rules/no-raw-error-forwarding.d.ts +16 -0
  15. package/dist/effect/rules/no-raw-error-forwarding.js +108 -0
  16. package/dist/effect/rules/no-silent-error-swallow.js +1 -1
  17. package/dist/effect/rules/no-static-effect-service-forwarders.js +5 -4
  18. package/dist/effect/rules/no-try-catch.js +1 -1
  19. package/dist/effect/rules/no-unguarded-json-parse.js +1 -1
  20. package/dist/effect/rules/option-core-needs-effect-public.js +1 -1
  21. package/dist/effect/rules/prefer-die-for-precondition-defects.js +1 -1
  22. package/dist/effect/rules/prefer-effect-gen-for-guard-ladders.js +1 -1
  23. package/dist/effect/rules/prefer-effect-match.js +2 -2
  24. package/dist/effect/rules/prefer-effect-predicate-over-boolean-function.js +1 -1
  25. package/dist/effect/rules/prefer-named-guard-predicate.js +1 -1
  26. package/dist/effect/rules/prefer-option-pipeline.js +13 -12
  27. package/dist/effect/rules/prefer-ordering-match.js +1 -1
  28. package/dist/effect/rules/prefer-tagged-enum.js +1 -1
  29. package/dist/effect/rules/require-schema-type-derivation.d.ts +8 -2
  30. package/dist/effect/rules/require-schema-type-derivation.js +14 -4
  31. package/dist/index.js +10 -0
  32. package/dist/react/rules/require-dot-notation-exports.js +1 -1
  33. package/dist/react/rules/require-guarded-context-hook.js +1 -1
  34. package/dist/react/rules/require-tripartite-context.js +1 -1
  35. package/dist/react/rules/use-encapsulation.js +1 -1
  36. package/dist/rules/no-adapter-in-values.d.ts +12 -0
  37. package/dist/rules/no-adapter-in-values.js +110 -0
  38. package/dist/rules/no-builtin-throws.js +1 -1
  39. package/dist/rules/no-duplicated-literal-union.d.ts +7 -0
  40. package/dist/rules/no-duplicated-literal-union.js +5 -1
  41. package/dist/rules/no-generic-export-names.js +1 -1
  42. package/dist/rules/no-multiple-function-params.js +26 -12
  43. package/dist/rules/no-mutable-environment-capture.js +2 -2
  44. package/dist/rules/no-nondeterministic-core.js +1 -1
  45. package/dist/rules/no-nullable-value-field.d.ts +16 -0
  46. package/dist/rules/no-nullable-value-field.js +117 -0
  47. package/dist/rules/no-optional-function-parameters.js +1 -1
  48. package/dist/rules/no-row-coercion.d.ts +13 -0
  49. package/dist/rules/no-row-coercion.js +135 -0
  50. package/dist/rules/no-single-use-private-functions.js +1 -1
  51. package/dist/rules/no-sql-string-interpolation.d.ts +7 -0
  52. package/dist/rules/no-sql-string-interpolation.js +62 -0
  53. package/dist/rules/no-stray-inline-comments.js +1 -1
  54. package/dist/rules/no-string-instant.d.ts +15 -0
  55. package/dist/rules/no-string-instant.js +108 -0
  56. package/dist/rules/no-swappable-primitive-params.js +1 -1
  57. package/dist/rules/no-tag-ladder-assertions.js +1 -1
  58. package/dist/rules/no-vague-test-filenames.js +1 -1
  59. package/dist/rules/prefer-property-tests.d.ts +5 -0
  60. package/dist/rules/prefer-property-tests.js +7 -0
  61. package/dist/rules/require-jsdoc-on-exported.js +1 -1
  62. package/dist/shared/ancestors.d.ts +1 -1
  63. package/dist/shared/ancestors.js +1 -1
  64. package/dist/shared/values-path.d.ts +12 -0
  65. package/dist/shared/values-path.js +56 -0
  66. package/dist/src/configs/recommended-rules.d.ts +20 -0
  67. package/dist/src/configs/recommended-rules.js +22 -0
  68. package/dist/src/effect/index.d.ts +3 -0
  69. package/dist/src/effect/index.js +60 -0
  70. package/dist/src/effect/rules/guarded-op-must-return-effect.d.ts +6 -0
  71. package/dist/src/effect/rules/guarded-op-must-return-effect.js +235 -0
  72. package/dist/src/effect/rules/guarded-op-must-return-option.d.ts +2 -0
  73. package/dist/src/effect/rules/guarded-op-must-return-option.js +88 -0
  74. package/dist/src/effect/rules/no-cascading-layer-provide.d.ts +6 -0
  75. package/dist/src/effect/rules/no-cascading-layer-provide.js +73 -0
  76. package/dist/src/effect/rules/no-decode-unknown-option.d.ts +7 -0
  77. package/dist/src/effect/rules/no-decode-unknown-option.js +34 -0
  78. package/dist/src/effect/rules/no-direct-browser-storage.d.ts +2 -0
  79. package/dist/src/effect/rules/no-direct-browser-storage.js +88 -0
  80. package/dist/src/effect/rules/no-direct-fetch.d.ts +2 -0
  81. package/dist/src/effect/rules/no-direct-fetch.js +37 -0
  82. package/dist/src/effect/rules/no-manual-field-guards.d.ts +6 -0
  83. package/dist/src/effect/rules/no-manual-field-guards.js +129 -0
  84. package/dist/src/effect/rules/no-nested-layer-provide.d.ts +2 -0
  85. package/dist/src/effect/rules/no-nested-layer-provide.js +50 -0
  86. package/dist/src/effect/rules/no-nullish-default-on-partial-input.d.ts +13 -0
  87. package/dist/src/effect/rules/no-nullish-default-on-partial-input.js +109 -0
  88. package/dist/src/effect/rules/no-raw-error-forwarding.d.ts +12 -0
  89. package/dist/src/effect/rules/no-raw-error-forwarding.js +103 -0
  90. package/dist/src/effect/rules/no-schema-class-modeling.d.ts +2 -0
  91. package/dist/src/effect/rules/no-schema-class-modeling.js +52 -0
  92. package/dist/src/effect/rules/no-service-constructor-imports.d.ts +2 -0
  93. package/dist/src/effect/rules/no-service-constructor-imports.js +42 -0
  94. package/dist/src/effect/rules/no-silent-error-swallow.d.ts +2 -0
  95. package/dist/src/effect/rules/no-silent-error-swallow.js +95 -0
  96. package/dist/src/effect/rules/no-static-effect-service-forwarders.d.ts +6 -0
  97. package/dist/src/effect/rules/no-static-effect-service-forwarders.js +222 -0
  98. package/dist/src/effect/rules/no-try-catch.d.ts +2 -0
  99. package/dist/src/effect/rules/no-try-catch.js +30 -0
  100. package/dist/src/effect/rules/no-unguarded-json-parse.d.ts +5 -0
  101. package/dist/src/effect/rules/no-unguarded-json-parse.js +200 -0
  102. package/dist/src/effect/rules/option-core-needs-effect-public.d.ts +5 -0
  103. package/dist/src/effect/rules/option-core-needs-effect-public.js +76 -0
  104. package/dist/src/effect/rules/prefer-die-for-precondition-defects.d.ts +5 -0
  105. package/dist/src/effect/rules/prefer-die-for-precondition-defects.js +112 -0
  106. package/dist/src/effect/rules/prefer-effect-gen-for-guard-ladders.d.ts +5 -0
  107. package/dist/src/effect/rules/prefer-effect-gen-for-guard-ladders.js +72 -0
  108. package/dist/src/effect/rules/prefer-effect-match.d.ts +2 -0
  109. package/dist/src/effect/rules/prefer-effect-match.js +74 -0
  110. package/dist/src/effect/rules/prefer-effect-predicate-over-boolean-function.d.ts +2 -0
  111. package/dist/src/effect/rules/prefer-effect-predicate-over-boolean-function.js +75 -0
  112. package/dist/src/effect/rules/prefer-named-guard-predicate.d.ts +2 -0
  113. package/dist/src/effect/rules/prefer-named-guard-predicate.js +93 -0
  114. package/dist/src/effect/rules/prefer-option-pipeline.d.ts +2 -0
  115. package/dist/src/effect/rules/prefer-option-pipeline.js +87 -0
  116. package/dist/src/effect/rules/prefer-ordering-match.d.ts +2 -0
  117. package/dist/src/effect/rules/prefer-ordering-match.js +135 -0
  118. package/dist/src/effect/rules/prefer-tagged-enum.d.ts +2 -0
  119. package/dist/src/effect/rules/prefer-tagged-enum.js +66 -0
  120. package/dist/src/effect/rules/require-schema-type-derivation.d.ts +7 -0
  121. package/dist/src/effect/rules/require-schema-type-derivation.js +80 -0
  122. package/dist/src/index.d.ts +3 -0
  123. package/dist/src/index.js +106 -0
  124. package/dist/src/meta/index.d.ts +7 -0
  125. package/dist/src/meta/index.js +22 -0
  126. package/dist/src/meta/rules/no-disable-directives.d.ts +6 -0
  127. package/dist/src/meta/rules/no-disable-directives.js +35 -0
  128. package/dist/src/meta/rules/no-manual-ancestor-walks.d.ts +2 -0
  129. package/dist/src/meta/rules/no-manual-ancestor-walks.js +26 -0
  130. package/dist/src/meta/rules/prefer-before-file-scope.d.ts +2 -0
  131. package/dist/src/meta/rules/prefer-before-file-scope.js +57 -0
  132. package/dist/src/meta/rules/require-create-once.d.ts +2 -0
  133. package/dist/src/meta/rules/require-create-once.js +51 -0
  134. package/dist/src/meta/rules/require-rule-tester.d.ts +2 -0
  135. package/dist/src/meta/rules/require-rule-tester.js +50 -0
  136. package/dist/src/react/index.d.ts +3 -0
  137. package/dist/src/react/index.js +16 -0
  138. package/dist/src/react/role.d.ts +23 -0
  139. package/dist/src/react/role.js +30 -0
  140. package/dist/src/react/rules/require-dot-notation-exports.d.ts +27 -0
  141. package/dist/src/react/rules/require-dot-notation-exports.js +144 -0
  142. package/dist/src/react/rules/require-guarded-context-hook.d.ts +19 -0
  143. package/dist/src/react/rules/require-guarded-context-hook.js +167 -0
  144. package/dist/src/react/rules/require-tripartite-context.d.ts +17 -0
  145. package/dist/src/react/rules/require-tripartite-context.js +160 -0
  146. package/dist/src/react/rules/use-encapsulation.d.ts +22 -0
  147. package/dist/src/react/rules/use-encapsulation.js +97 -0
  148. package/dist/src/rules/no-anonymous-wide-tuples.d.ts +7 -0
  149. package/dist/src/rules/no-anonymous-wide-tuples.js +34 -0
  150. package/dist/src/rules/no-barrel-export-star.d.ts +2 -0
  151. package/dist/src/rules/no-barrel-export-star.js +26 -0
  152. package/dist/src/rules/no-boolean-field-signals.d.ts +2 -0
  153. package/dist/src/rules/no-boolean-field-signals.js +279 -0
  154. package/dist/src/rules/no-builtin-throws.d.ts +6 -0
  155. package/dist/src/rules/no-builtin-throws.js +74 -0
  156. package/dist/src/rules/no-chained-type-assertions.d.ts +2 -0
  157. package/dist/src/rules/no-chained-type-assertions.js +54 -0
  158. package/dist/src/rules/no-conditional-empty-object-spread.d.ts +2 -0
  159. package/dist/src/rules/no-conditional-empty-object-spread.js +36 -0
  160. package/dist/src/rules/no-duplicated-literal-union.d.ts +6 -0
  161. package/dist/src/rules/no-duplicated-literal-union.js +66 -0
  162. package/dist/src/rules/no-exported-mutable-state.d.ts +7 -0
  163. package/dist/src/rules/no-exported-mutable-state.js +104 -0
  164. package/dist/src/rules/no-generic-export-names.d.ts +2 -0
  165. package/dist/src/rules/no-generic-export-names.js +141 -0
  166. package/dist/src/rules/no-impossible-branch-throw.d.ts +2 -0
  167. package/dist/src/rules/no-impossible-branch-throw.js +51 -0
  168. package/dist/src/rules/no-known-value-widening.d.ts +2 -0
  169. package/dist/src/rules/no-known-value-widening.js +176 -0
  170. package/dist/src/rules/no-module-mocking.d.ts +2 -0
  171. package/dist/src/rules/no-module-mocking.js +90 -0
  172. package/dist/src/rules/no-multiple-function-params.d.ts +2 -0
  173. package/dist/src/rules/no-multiple-function-params.js +155 -0
  174. package/dist/src/rules/no-mutable-environment-capture.d.ts +7 -0
  175. package/dist/src/rules/no-mutable-environment-capture.js +134 -0
  176. package/dist/src/rules/no-nondeterministic-core.d.ts +6 -0
  177. package/dist/src/rules/no-nondeterministic-core.js +63 -0
  178. package/dist/src/rules/no-object-parameters.d.ts +2 -0
  179. package/dist/src/rules/no-object-parameters.js +95 -0
  180. package/dist/src/rules/no-optional-function-parameters.d.ts +7 -0
  181. package/dist/src/rules/no-optional-function-parameters.js +44 -0
  182. package/dist/src/rules/no-product-of-state-booleans.d.ts +2 -0
  183. package/dist/src/rules/no-product-of-state-booleans.js +79 -0
  184. package/dist/src/rules/no-redundant-derived-field.d.ts +6 -0
  185. package/dist/src/rules/no-redundant-derived-field.js +194 -0
  186. package/dist/src/rules/no-reflect-apply.d.ts +2 -0
  187. package/dist/src/rules/no-reflect-apply.js +29 -0
  188. package/dist/src/rules/no-reflect-get.d.ts +2 -0
  189. package/dist/src/rules/no-reflect-get.js +29 -0
  190. package/dist/src/rules/no-reinterpret-cast.d.ts +2 -0
  191. package/dist/src/rules/no-reinterpret-cast.js +68 -0
  192. package/dist/src/rules/no-runtime-typeof.d.ts +2 -0
  193. package/dist/src/rules/no-runtime-typeof.js +54 -0
  194. package/dist/src/rules/no-sentinel-comparison-union.d.ts +2 -0
  195. package/dist/src/rules/no-sentinel-comparison-union.js +139 -0
  196. package/dist/src/rules/no-shape-in-symbol-names.d.ts +2 -0
  197. package/dist/src/rules/no-shape-in-symbol-names.js +39 -0
  198. package/dist/src/rules/no-single-use-private-functions.d.ts +17 -0
  199. package/dist/src/rules/no-single-use-private-functions.js +419 -0
  200. package/dist/src/rules/no-sql-string-interpolation.d.ts +7 -0
  201. package/dist/src/rules/no-sql-string-interpolation.js +62 -0
  202. package/dist/src/rules/no-stacked-jsdoc-blocks.d.ts +2 -0
  203. package/dist/src/rules/no-stacked-jsdoc-blocks.js +50 -0
  204. package/dist/src/rules/no-stray-inline-comments.d.ts +2 -0
  205. package/dist/src/rules/no-stray-inline-comments.js +74 -0
  206. package/dist/src/rules/no-swappable-primitive-params.d.ts +2 -0
  207. package/dist/src/rules/no-swappable-primitive-params.js +96 -0
  208. package/dist/src/rules/no-tag-ladder-assertions.d.ts +6 -0
  209. package/dist/src/rules/no-tag-ladder-assertions.js +63 -0
  210. package/dist/src/rules/no-transposed-field-reads.d.ts +8 -0
  211. package/dist/src/rules/no-transposed-field-reads.js +101 -0
  212. package/dist/src/rules/no-unit-return-validators.d.ts +2 -0
  213. package/dist/src/rules/no-unit-return-validators.js +64 -0
  214. package/dist/src/rules/no-unknown-parameters.d.ts +2 -0
  215. package/dist/src/rules/no-unknown-parameters.js +82 -0
  216. package/dist/src/rules/no-unknown-returns.d.ts +2 -0
  217. package/dist/src/rules/no-unknown-returns.js +86 -0
  218. package/dist/src/rules/no-unknown-type-aliases.d.ts +2 -0
  219. package/dist/src/rules/no-unknown-type-aliases.js +64 -0
  220. package/dist/src/rules/no-unsafe-dictionary-type.d.ts +2 -0
  221. package/dist/src/rules/no-unsafe-dictionary-type.js +116 -0
  222. package/dist/src/rules/no-vague-test-filenames.d.ts +2 -0
  223. package/dist/src/rules/no-vague-test-filenames.js +61 -0
  224. package/dist/src/rules/no-widen-then-assert.d.ts +2 -0
  225. package/dist/src/rules/no-widen-then-assert.js +268 -0
  226. package/dist/src/rules/prefer-payload-brand.d.ts +2 -0
  227. package/dist/src/rules/prefer-payload-brand.js +57 -0
  228. package/dist/src/rules/prefer-property-tests.d.ts +5 -0
  229. package/dist/src/rules/prefer-property-tests.js +39 -0
  230. package/dist/src/rules/require-canonical-stringify-for-identity.d.ts +8 -0
  231. package/dist/src/rules/require-canonical-stringify-for-identity.js +72 -0
  232. package/dist/src/rules/require-deprecated-tag-for-legacy-comments.d.ts +2 -0
  233. package/dist/src/rules/require-deprecated-tag-for-legacy-comments.js +34 -0
  234. package/dist/src/rules/require-exhaustive-tag-switch.d.ts +7 -0
  235. package/dist/src/rules/require-exhaustive-tag-switch.js +34 -0
  236. package/dist/src/rules/require-fc-block-predicate.d.ts +2 -0
  237. package/dist/src/rules/require-fc-block-predicate.js +37 -0
  238. package/dist/src/rules/require-jsdoc-on-exported.d.ts +2 -0
  239. package/dist/src/rules/require-jsdoc-on-exported.js +66 -0
  240. package/dist/src/rules/require-published-order.d.ts +2 -0
  241. package/dist/src/rules/require-published-order.js +102 -0
  242. package/dist/src/rules/require-safety-comment-for-type-assertion.d.ts +2 -0
  243. package/dist/src/rules/require-safety-comment-for-type-assertion.js +53 -0
  244. package/dist/src/rules/require-sort-comparator.d.ts +7 -0
  245. package/dist/src/rules/require-sort-comparator.js +34 -0
  246. package/dist/src/rules/test-utils.d.ts +35 -0
  247. package/dist/src/rules/test-utils.js +53 -0
  248. package/dist/src/shared/ancestors.d.ts +18 -0
  249. package/dist/src/shared/ancestors.js +19 -0
  250. package/dist/src/shared/child-nodes.d.ts +12 -0
  251. package/dist/src/shared/child-nodes.js +26 -0
  252. package/dist/src/shared/dictionary-types.d.ts +55 -0
  253. package/dist/src/shared/dictionary-types.js +413 -0
  254. package/dist/src/shared/is-node.d.ts +9 -0
  255. package/dist/src/shared/is-node.js +10 -0
  256. package/dist/src/shared/lexical-type-parameters.d.ts +12 -0
  257. package/dist/src/shared/lexical-type-parameters.js +50 -0
  258. package/dist/src/shared/reflect-method.d.ts +15 -0
  259. package/dist/src/shared/reflect-method.js +32 -0
  260. package/dist/src/shared/rule-options.d.ts +18 -0
  261. package/dist/src/shared/rule-options.js +12 -0
  262. package/dist/src/shared/structural.d.ts +54 -0
  263. package/dist/src/shared/structural.js +40 -0
  264. package/dist/src/testing/index.d.ts +2 -0
  265. package/dist/src/testing/index.js +1 -0
  266. package/dist/src/testing/testable-rule.d.ts +39 -0
  267. package/dist/src/testing/testable-rule.js +84 -0
  268. package/dist/src/ui/index.d.ts +12 -0
  269. package/dist/src/ui/index.js +18 -0
  270. package/dist/src/ui/manifest.d.ts +34 -0
  271. package/dist/src/ui/manifest.js +75 -0
  272. package/dist/src/ui/rules/no-deprecated-parts.d.ts +3 -0
  273. package/dist/src/ui/rules/no-deprecated-parts.js +131 -0
  274. package/dist/testing/testable-rule.d.ts +6 -5
  275. package/dist/testing/testable-rule.js +20 -6
  276. package/dist/ui/index.d.ts +12 -0
  277. package/dist/ui/index.js +18 -0
  278. package/dist/ui/manifest.d.ts +49 -0
  279. package/dist/ui/manifest.js +90 -0
  280. package/dist/ui/rules/no-deprecated-parts.d.ts +3 -0
  281. package/dist/ui/rules/no-deprecated-parts.js +172 -0
  282. package/package.json +20 -11
@@ -0,0 +1,155 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { readField } from "../shared/structural.js";
3
+ import { ancestorsOf } from "../shared/ancestors.js";
4
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
5
+ const DEFAULT_MAX_PARAMS = 1;
6
+ /** Conventional HTTP method handler names, exempt inside framework route files. */
7
+ const HTTP_METHOD_NAMES = new Set([
8
+ "DELETE",
9
+ "GET",
10
+ "HEAD",
11
+ "OPTIONS",
12
+ "PATCH",
13
+ "POST",
14
+ "PUT",
15
+ ]);
16
+ const DEFAULT_ROUTE_BASENAMES = new Set(["route.ts", "route.tsx"]);
17
+ function parentOf(sourceCode, node) {
18
+ return ancestorsOf(sourceCode, node)[0] ?? null;
19
+ }
20
+ /**
21
+ * Functions the module owns: declarations and named bindings, not callbacks.
22
+ *
23
+ * @param {SourceCode} sourceCode - The rule's source-code accessor.
24
+ * @param {ESTree.Node} node - The visited function-like node.
25
+ * @returns {boolean} True when the module owns the function's arity.
26
+ */
27
+ function isOwnedFunction(sourceCode, node) {
28
+ if (node.type === "FunctionDeclaration")
29
+ return true;
30
+ const parent = parentOf(sourceCode, node);
31
+ if (parent === null)
32
+ return false;
33
+ const parentType = parent.type;
34
+ if (parentType === "CallExpression" ||
35
+ parentType === "NewExpression" ||
36
+ parentType === "JSXExpressionContainer") {
37
+ return false;
38
+ }
39
+ return (parentType === "VariableDeclarator" ||
40
+ parentType === "AssignmentExpression" ||
41
+ parentType === "ExportDefaultDeclaration");
42
+ }
43
+ /**
44
+ * Exported HTTP-method-named handlers in framework route files own their arity.
45
+ *
46
+ * @param {{ options: ResolvedOptions; baseName: string; sourceCode: SourceCode; node: ESTree.Node }} payload - Exemption inputs.
47
+ * @returns {boolean} True when the handler is an exempt route handler.
48
+ */
49
+ function isExemptRouteHandler(payload) {
50
+ if (payload.node.type !== "FunctionDeclaration")
51
+ return false;
52
+ const name = payload.node.id?.name;
53
+ if (name === undefined || !payload.options.methodNames.has(name))
54
+ return false;
55
+ if (!payload.options.routeBasenames.has(payload.baseName))
56
+ return false;
57
+ const parent = parentOf(payload.sourceCode, payload.node);
58
+ return parent !== null && parent.type === "ExportNamedDeclaration";
59
+ }
60
+ /** Primitive annotations transpose silently; structural ones fail the compiler. */
61
+ const PRIMITIVE_TYPE_TEXT = /^(?:string|number|bigint|boolean|unknown|any|null|undefined|void)$/u;
62
+ /**
63
+ * Whether every positional parameter carries a distinct non-primitive type:
64
+ * transposing such arguments is a compile error, so ordering needs no guard.
65
+ *
66
+ * @param {SourceCode} sourceCode - The rule's source-code accessor.
67
+ * @param {ReadonlyArray<ESTree.ParamPattern>} params - The parameter list to inspect.
68
+ * @returns {boolean} True when transposing any pair fails the compiler.
69
+ */
70
+ function transpositionSafe(sourceCode, params) {
71
+ const texts = [];
72
+ for (const param of params) {
73
+ if (param.type !== "Identifier")
74
+ return false;
75
+ const annotation = param.typeAnnotation;
76
+ if (annotation === null || annotation === undefined)
77
+ return false;
78
+ const text = sourceCode.getText(annotation.typeAnnotation).replaceAll(" ", "");
79
+ if (text === "" || PRIMITIVE_TYPE_TEXT.test(text))
80
+ return false;
81
+ texts.push(text);
82
+ }
83
+ return new Set(texts).size === texts.length;
84
+ }
85
+ /** Owned functions taking several positional inputs accept transposed arguments silently; require one payload object. */
86
+ export const noMultipleFunctionParamsRule = defineRule({
87
+ meta: {
88
+ type: "problem",
89
+ docs: {
90
+ description: "Disallow owned functions with more than one positional parameter; collapse multiple inputs into a single named payload object so transposed arguments fail the compiler.",
91
+ },
92
+ messages: {
93
+ multipleParams: "`{{name}}` takes {{count}} positional parameters. Accept a single named payload object instead; transposed primitive arguments compile silently.",
94
+ },
95
+ },
96
+ createOnce(context) {
97
+ const rawOptions = readField(context, "options");
98
+ const options = {
99
+ methodNames: new Set(rawOptions?.[0]?.exemptFunctionNames ?? HTTP_METHOD_NAMES),
100
+ routeBasenames: new Set(rawOptions?.[0]?.exemptRouteBasenames ?? DEFAULT_ROUTE_BASENAMES),
101
+ };
102
+ let fileBase = "";
103
+ const check = (node) => {
104
+ if (node.type !== "FunctionDeclaration" &&
105
+ node.type !== "FunctionExpression" &&
106
+ node.type !== "ArrowFunctionExpression")
107
+ return;
108
+ const fn = node;
109
+ if (fn.params.length <= DEFAULT_MAX_PARAMS)
110
+ return;
111
+ if (!isOwnedFunction(context.sourceCode, node))
112
+ return;
113
+ if (transpositionSafe(context.sourceCode, fn.params))
114
+ return;
115
+ if (isExemptRouteHandler({
116
+ options,
117
+ baseName: fileBase,
118
+ sourceCode: context.sourceCode,
119
+ node,
120
+ }))
121
+ return;
122
+ let name = "(anonymous)";
123
+ if (node.id !== null && node.id !== undefined) {
124
+ name = node.id.name;
125
+ }
126
+ else {
127
+ const parent = parentOf(context.sourceCode, node);
128
+ if (parent?.type === "VariableDeclarator" && parent.id.type === "Identifier") {
129
+ name = parent.id.name;
130
+ }
131
+ else if (parent?.type === "AssignmentExpression" &&
132
+ parent.left.type === "Identifier") {
133
+ name = parent.left.name;
134
+ }
135
+ }
136
+ context.report({
137
+ node,
138
+ messageId: "multipleParams",
139
+ data: { name, count: String(fn.params.length) },
140
+ });
141
+ };
142
+ return {
143
+ before() {
144
+ const normalized = context.filename.replaceAll("\\", "/");
145
+ const segments = normalized.split("/");
146
+ fileBase = segments[segments.length - 1] ?? normalized;
147
+ if (TEST_FILE.test(normalized))
148
+ return false;
149
+ },
150
+ FunctionDeclaration: check,
151
+ FunctionExpression: check,
152
+ ArrowFunctionExpression: check,
153
+ };
154
+ },
155
+ });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A function that reads or writes module state instead of taking it as a
3
+ * parameter is dishonest: its result depends on outside context, so it is not
4
+ * locally testable. Inject the value at the call site (the document's seed-the
5
+ * PRNG-once, pass-it-in pattern) so the dependency is explicit in the signature.
6
+ */
7
+ export declare const noMutableEnvironmentCaptureRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,134 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { ancestorsOf } from "../shared/ancestors.js";
3
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
4
+ /**
5
+ * Whether the identifier sits inside a type annotation rather than a value position.
6
+ *
7
+ * @param {SourceCode} sourceCode - The rule's source-code accessor.
8
+ * @param {ESTree.Node} identifier - The reference identifier to test.
9
+ * @returns {boolean} True when an ancestor is a TypeScript type node.
10
+ */
11
+ function isTypePosition(sourceCode, identifier) {
12
+ for (const ancestor of ancestorsOf(sourceCode, identifier)) {
13
+ if (ancestor.type.startsWith("TS"))
14
+ return true;
15
+ }
16
+ return false;
17
+ }
18
+ /**
19
+ * The name a function is called by at its definition site.
20
+ *
21
+ * @param {ESTree.Node} node - The function-like node.
22
+ * @param {SourceCode} sourceCode - The rule's source-code accessor.
23
+ * @returns {string} The function's name, or "(anonymous)".
24
+ */
25
+ function functionName(node, sourceCode) {
26
+ if (node.type === "FunctionDeclaration" && node.id !== null)
27
+ return node.id.name;
28
+ const parent = ancestorsOf(sourceCode, node)[0];
29
+ if (parent !== undefined) {
30
+ if (parent.type === "VariableDeclarator" && parent.id.type === "Identifier")
31
+ return parent.id.name;
32
+ if (parent.type === "AssignmentExpression" && parent.left.type === "Identifier")
33
+ return parent.left.name;
34
+ if (parent.type === "MethodDefinition" && parent.key.type === "Identifier")
35
+ return parent.key.name;
36
+ if (parent.type === "Property" && parent.key.type === "Identifier")
37
+ return parent.key.name;
38
+ if (parent.type === "ExportDefaultDeclaration")
39
+ return "default";
40
+ }
41
+ return "(anonymous)";
42
+ }
43
+ /**
44
+ * Collect module-scope let/var bindings, separating real state from
45
+ * function-valued helpers (which are legitimate module-private utilities).
46
+ *
47
+ * @param {ESTree.Program} program - The file's root node.
48
+ * @returns {ModuleState} Mutable state names and helper names.
49
+ */
50
+ function collectModuleState(program) {
51
+ const state = new Set();
52
+ const helpers = new Set();
53
+ for (const statement of program.body) {
54
+ const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
55
+ if (declaration === null || declaration === undefined)
56
+ continue;
57
+ if (declaration.type !== "VariableDeclaration")
58
+ continue;
59
+ if (declaration.kind !== "let" && declaration.kind !== "var")
60
+ continue;
61
+ for (const declarator of declaration.declarations) {
62
+ if (declarator.id.type !== "Identifier")
63
+ continue;
64
+ const init = declarator.init;
65
+ const isHelper = init !== null &&
66
+ init !== undefined &&
67
+ (init.type === "ArrowFunctionExpression" || init.type === "FunctionExpression");
68
+ (isHelper ? helpers : state).add(declarator.id.name);
69
+ }
70
+ }
71
+ return { state, helpers };
72
+ }
73
+ /**
74
+ * A function that reads or writes module state instead of taking it as a
75
+ * parameter is dishonest: its result depends on outside context, so it is not
76
+ * locally testable. Inject the value at the call site (the document's seed-the
77
+ * PRNG-once, pass-it-in pattern) so the dependency is explicit in the signature.
78
+ */
79
+ export const noMutableEnvironmentCaptureRule = defineRule({
80
+ meta: {
81
+ type: "problem",
82
+ docs: {
83
+ description: "Disallow functions that read or write module-scope mutable state (let/var) instead of receiving it as a parameter; hidden module state makes a function dishonest and not locally testable.",
84
+ },
85
+ messages: {
86
+ mutableModuleState: "Function `{{name}}` {{kind}} module-scope mutable state `{{binding}}` rather than receiving it as a parameter. Hidden module state makes the function dishonest: its result depends on outside context, so it is not locally testable. Inject `{{binding}}` at the call site or thread it through the signature so the dependency is explicit.",
87
+ },
88
+ },
89
+ createOnce(context) {
90
+ let moduleState = { state: new Set(), helpers: new Set() };
91
+ const check = (node) => {
92
+ if (node.type !== "FunctionDeclaration" &&
93
+ node.type !== "FunctionExpression" &&
94
+ node.type !== "ArrowFunctionExpression") {
95
+ return;
96
+ }
97
+ const scope = context.sourceCode.getScope(node);
98
+ const { state, helpers } = moduleState;
99
+ for (const reference of scope.references) {
100
+ const resolved = reference.resolved;
101
+ if (resolved === null || resolved === undefined)
102
+ continue;
103
+ const name = resolved.name;
104
+ if (helpers.has(name))
105
+ continue;
106
+ if (!state.has(name))
107
+ continue;
108
+ if (isTypePosition(context.sourceCode, reference.identifier))
109
+ continue;
110
+ context.report({
111
+ node: reference.identifier,
112
+ messageId: "mutableModuleState",
113
+ data: {
114
+ name: functionName(node, context.sourceCode),
115
+ kind: reference.isWrite() ? "writes" : "reads",
116
+ binding: name,
117
+ },
118
+ });
119
+ }
120
+ };
121
+ return {
122
+ before() {
123
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
124
+ return false;
125
+ },
126
+ Program(node) {
127
+ moduleState = collectModuleState(node);
128
+ },
129
+ FunctionDeclaration: check,
130
+ FunctionExpression: check,
131
+ ArrowFunctionExpression: check,
132
+ };
133
+ },
134
+ });
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Canonical form: identical inputs must produce identical outputs. Time and
3
+ * randomness are boundary inputs: capture them once at the edge and pass
4
+ * them in, so cores stay reproducible and their serialisations stable.
5
+ */
6
+ export declare const noNondeterministicCoreRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,63 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ const NONDETERMINISTIC_MEMBERS = new Set(["getRandomValues", "random", "randomUUID", "now"]);
3
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$|\/test\//u;
4
+ function memberChain(node) {
5
+ if (node.type === "MemberExpression" && !node.computed) {
6
+ return [...memberChain(node.object), node.property.type === "Identifier" ? node.property.name : ""];
7
+ }
8
+ return [node.type === "Identifier" ? node.name : "?"];
9
+ }
10
+ /**
11
+ * Canonical form: identical inputs must produce identical outputs. Time and
12
+ * randomness are boundary inputs: capture them once at the edge and pass
13
+ * them in, so cores stay reproducible and their serialisations stable.
14
+ */
15
+ export const noNondeterministicCoreRule = defineRule({
16
+ meta: {
17
+ type: "problem",
18
+ docs: {
19
+ description: "Disallow nondeterministic sources (Math.random, Date.now, new Date(), crypto randomness) outside tests; inject them as boundary inputs so cores stay canonical.",
20
+ },
21
+ messages: {
22
+ nondeterministicSource: "`{{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.",
23
+ unseededDate: "`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).",
24
+ },
25
+ },
26
+ createOnce(context) {
27
+ return {
28
+ before() {
29
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
30
+ return false;
31
+ },
32
+ MemberExpression(node) {
33
+ const property = node.property;
34
+ if (node.computed || property.type !== "Identifier" || !NONDETERMINISTIC_MEMBERS.has(property.name)) {
35
+ return;
36
+ }
37
+ const chain = memberChain(node.object);
38
+ const root = chain[0] ?? "";
39
+ if ((root === "Math" && property.name === "random") || (root === "crypto" && property.name !== "now")) {
40
+ context.report({
41
+ node,
42
+ messageId: "nondeterministicSource",
43
+ data: { source: `${root}.${property.name}` },
44
+ });
45
+ return;
46
+ }
47
+ if (property.name === "now" &&
48
+ ((root === "Date" && chain.length === 1) || (root === "performance" && chain.length === 1))) {
49
+ context.report({
50
+ node,
51
+ messageId: "nondeterministicSource",
52
+ data: { source: `${root}.now` },
53
+ });
54
+ }
55
+ },
56
+ NewExpression(node) {
57
+ if (node.callee.type === "Identifier" && node.callee.name === "Date" && node.arguments.length === 0) {
58
+ context.report({ node, messageId: "unseededDate" });
59
+ }
60
+ },
61
+ };
62
+ },
63
+ });
@@ -0,0 +1,2 @@
1
+ /** Ban the broad object type on function inputs, including local aliases to object. */
2
+ export declare const noObjectParametersRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,95 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { ancestorsOf } from "../shared/ancestors.js";
3
+ import { lexicalTypeParameterNames } from "../shared/lexical-type-parameters.js";
4
+ function parameterAnnotation(parameter) {
5
+ if (parameter.type === "TSParameterProperty") {
6
+ return parameterAnnotation(parameter.parameter);
7
+ }
8
+ if (parameter.type === "RestElement") {
9
+ return parameter.typeAnnotation ?? parameterAnnotation(parameter.argument);
10
+ }
11
+ if (parameter.type === "AssignmentPattern") {
12
+ return parameter.typeAnnotation ?? parameter.left.typeAnnotation;
13
+ }
14
+ return parameter.typeAnnotation;
15
+ }
16
+ /** Ban the broad object type on function inputs, including local aliases to object. */
17
+ export const noObjectParametersRule = defineRule({
18
+ meta: {
19
+ type: "problem",
20
+ docs: {
21
+ description: "Disallow object function parameters; inputs must use an owner-provided type and be parsed at their boundary.",
22
+ },
23
+ messages: {
24
+ objectParameter: "Parameter `{{parameter}}` uses the broad `object` type. Accept a named owner type; parse external input at its boundary before calling this function.",
25
+ },
26
+ },
27
+ createOnce(context) {
28
+ const aliases = new Map();
29
+ const resolvesToObject = (type, shadowedAliases, visited = new Set()) => {
30
+ if (type.type === "TSObjectKeyword")
31
+ return true;
32
+ if (type.type === "TSParenthesizedType")
33
+ return resolvesToObject(type.typeAnnotation, shadowedAliases, visited);
34
+ if (type.type === "TSUnionType") {
35
+ return type.types.some((member) => resolvesToObject(member, shadowedAliases, visited));
36
+ }
37
+ if (type.type !== "TSTypeReference" ||
38
+ type.typeName.type !== "Identifier" ||
39
+ (type.typeArguments !== null &&
40
+ type.typeArguments !== undefined &&
41
+ type.typeArguments.params.length > 0) ||
42
+ visited.has(type.typeName.name) ||
43
+ shadowedAliases.has(type.typeName.name)) {
44
+ return false;
45
+ }
46
+ const alias = aliases.get(type.typeName.name);
47
+ if (alias === undefined)
48
+ return false;
49
+ const nextVisited = new Set(visited);
50
+ nextVisited.add(type.typeName.name);
51
+ return resolvesToObject(alias, shadowedAliases, nextVisited);
52
+ };
53
+ const checkParameters = (node) => {
54
+ const shadowedAliases = lexicalTypeParameterNames(node, ancestorsOf(context.sourceCode, node), context.sourceCode.visitorKeys);
55
+ for (const parameter of node.params) {
56
+ const annotation = parameterAnnotation(parameter);
57
+ if (annotation === null || annotation === undefined)
58
+ continue;
59
+ if (!resolvesToObject(annotation.typeAnnotation, shadowedAliases))
60
+ continue;
61
+ context.report({
62
+ node: annotation.typeAnnotation,
63
+ messageId: "objectParameter",
64
+ data: {
65
+ parameter: parameter.type === "Identifier"
66
+ ? parameter.name
67
+ : context.sourceCode.getText(parameter).replace(/\s*:\s*object\s*$/u, ""),
68
+ },
69
+ });
70
+ }
71
+ };
72
+ return {
73
+ Program(node) {
74
+ aliases.clear();
75
+ for (const statement of node.body) {
76
+ const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
77
+ if (declaration?.type === "TSTypeAliasDeclaration" &&
78
+ (declaration.typeParameters === null || declaration.typeParameters === undefined)) {
79
+ aliases.set(declaration.id.name, declaration.typeAnnotation);
80
+ }
81
+ }
82
+ },
83
+ ArrowFunctionExpression: checkParameters,
84
+ FunctionDeclaration: checkParameters,
85
+ FunctionExpression: checkParameters,
86
+ TSCallSignatureDeclaration: checkParameters,
87
+ TSConstructSignatureDeclaration: checkParameters,
88
+ TSConstructorType: checkParameters,
89
+ TSDeclareFunction: checkParameters,
90
+ TSEmptyBodyFunctionExpression: checkParameters,
91
+ TSFunctionType: checkParameters,
92
+ TSMethodSignature: checkParameters,
93
+ };
94
+ },
95
+ });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Optional parameters hide undefined from the signature; require the union spelled out.
3
+ *
4
+ * Optionality is a grammar-level flag present on every concrete ParamPattern
5
+ * shape, read after unwrapping TypeScript parameter-property wrappers.
6
+ */
7
+ export declare const noOptionalFunctionParametersRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,44 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
3
+ /**
4
+ * Optional parameters hide undefined from the signature; require the union spelled out.
5
+ *
6
+ * Optionality is a grammar-level flag present on every concrete ParamPattern
7
+ * shape, read after unwrapping TypeScript parameter-property wrappers.
8
+ */
9
+ export const noOptionalFunctionParametersRule = defineRule({
10
+ meta: {
11
+ type: "problem",
12
+ docs: {
13
+ description: "Disallow optional function parameters (`param?:`); require an explicit union with undefined so callers see the possibility in the type.",
14
+ },
15
+ messages: {
16
+ optionalParameter: "Optional parameters hide `undefined` from callers. Annotate the parameter as `T | undefined` so the possibility is spelled out in the type.",
17
+ },
18
+ },
19
+ createOnce(context) {
20
+ const check = (node) => {
21
+ if (node.type !== "FunctionDeclaration" &&
22
+ node.type !== "FunctionExpression" &&
23
+ node.type !== "ArrowFunctionExpression")
24
+ return;
25
+ for (const parameter of node.params) {
26
+ let pattern = parameter;
27
+ if (pattern.type === "TSParameterProperty")
28
+ pattern = pattern.parameter;
29
+ if (pattern.optional !== true)
30
+ continue;
31
+ context.report({ node: parameter, messageId: "optionalParameter" });
32
+ }
33
+ };
34
+ return {
35
+ before() {
36
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
37
+ return false;
38
+ },
39
+ FunctionDeclaration: check,
40
+ FunctionExpression: check,
41
+ ArrowFunctionExpression: check,
42
+ };
43
+ },
44
+ });
@@ -0,0 +1,2 @@
1
+ /** A product of booleans inside a variant tends to admit an illegal combination. */
2
+ export declare const noProductOfStateBooleansRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,79 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { readField } from "../shared/structural.js";
3
+ import { ancestorsOf } from "../shared/ancestors.js";
4
+ function lastTypeNameSegment(typeName) {
5
+ if (typeName.type === "Identifier")
6
+ return typeName.name;
7
+ if (typeName.type === "TSQualifiedName")
8
+ return lastTypeNameSegment(typeName.right);
9
+ return null;
10
+ }
11
+ /**
12
+ * Returns the enclosing TSPropertySignature when the literal is a variant
13
+ * payload of a Data.TaggedEnum (i.e. `{ Variant: Payload }` inside the enum's
14
+ * type argument), otherwise null.
15
+ *
16
+ * @param {ESTree.TSTypeLiteral} node - The visited type literal (candidate payload).
17
+ * @param {ReadonlyArray<ESTree.Node>} ancestors - Nearest-first ancestor chain of `node`.
18
+ * @returns {ESTree.TSPropertySignature | null} The variant property signature, or null.
19
+ */
20
+ function variantPayloadSignature(node, ancestors) {
21
+ const at = (depth) => ancestors[ancestors.length - 1 - depth];
22
+ const annotation = at(0);
23
+ if (annotation?.type !== "TSTypeAnnotation")
24
+ return null;
25
+ const signature = at(1);
26
+ if (signature?.type !== "TSPropertySignature")
27
+ return null;
28
+ const outer = at(2);
29
+ if (outer?.type !== "TSTypeLiteral")
30
+ return null;
31
+ const args = at(3);
32
+ if (args === undefined)
33
+ return null;
34
+ const reference = at(4);
35
+ if (reference?.type !== "TSTypeReference")
36
+ return null;
37
+ const name = lastTypeNameSegment(reference.typeName);
38
+ return name !== null && /TaggedEnum$/u.test(name) ? signature : null;
39
+ }
40
+ /** A product of booleans inside a variant tends to admit an illegal combination. */
41
+ export const noProductOfStateBooleansRule = defineRule({
42
+ meta: {
43
+ type: "problem",
44
+ docs: {
45
+ description: "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.",
46
+ },
47
+ messages: {
48
+ productOfStateBooleans: "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.",
49
+ },
50
+ },
51
+ createOnce(context) {
52
+ return {
53
+ TSTypeLiteral(node) {
54
+ const signature = variantPayloadSignature(node, ancestorsOf(context.sourceCode, node));
55
+ if (signature === null)
56
+ return;
57
+ let count = 0;
58
+ for (const member of node.members) {
59
+ if (member.type !== "TSPropertySignature")
60
+ continue;
61
+ const annotation = member.typeAnnotation;
62
+ if (annotation === null || annotation === undefined)
63
+ continue;
64
+ if (annotation.typeAnnotation.type === "TSBooleanKeyword")
65
+ count += 1;
66
+ }
67
+ if (count < 2)
68
+ return;
69
+ const key = signature.key;
70
+ const name = key.type === "Identifier" ? key.name : "variant";
71
+ context.report({
72
+ node,
73
+ messageId: "productOfStateBooleans",
74
+ data: { name, count: String(count) },
75
+ });
76
+ },
77
+ };
78
+ },
79
+ });
@@ -0,0 +1,6 @@
1
+ /**
2
+ * One fact, one place: a type that stores data *and* a field derivable from
3
+ * that data keeps two sources of truth that drift apart independently. Counts
4
+ * belong to read sites; ordering belongs in the structure itself.
5
+ */
6
+ export declare const noRedundantDerivedFieldRule: import("@oxlint/plugins").Rule;