@autotelic/plumb 0.3.1 → 0.3.2

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 (266) 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 +102 -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-nondeterministic-core.d.ts +6 -0
  92. package/dist/rules/no-nondeterministic-core.js +63 -0
  93. package/dist/rules/no-object-parameters.d.ts +2 -0
  94. package/dist/rules/no-object-parameters.js +95 -0
  95. package/dist/rules/no-optional-function-parameters.d.ts +7 -0
  96. package/dist/rules/no-optional-function-parameters.js +44 -0
  97. package/dist/rules/no-product-of-state-booleans.d.ts +2 -0
  98. package/dist/rules/no-product-of-state-booleans.js +79 -0
  99. package/dist/rules/no-redundant-derived-field.d.ts +6 -0
  100. package/dist/rules/no-redundant-derived-field.js +194 -0
  101. package/dist/rules/no-reflect-apply.d.ts +2 -0
  102. package/dist/rules/no-reflect-apply.js +29 -0
  103. package/dist/rules/no-reflect-get.d.ts +2 -0
  104. package/dist/rules/no-reflect-get.js +29 -0
  105. package/dist/rules/no-reinterpret-cast.d.ts +2 -0
  106. package/dist/rules/no-reinterpret-cast.js +68 -0
  107. package/dist/rules/no-runtime-typeof.d.ts +2 -0
  108. package/dist/rules/no-runtime-typeof.js +54 -0
  109. package/dist/rules/no-sentinel-comparison-union.d.ts +2 -0
  110. package/dist/rules/no-sentinel-comparison-union.js +139 -0
  111. package/dist/rules/no-shape-in-symbol-names.d.ts +2 -0
  112. package/dist/rules/no-shape-in-symbol-names.js +39 -0
  113. package/dist/rules/no-single-use-private-functions.d.ts +6 -0
  114. package/dist/rules/no-single-use-private-functions.js +295 -0
  115. package/dist/rules/no-stacked-jsdoc-blocks.d.ts +2 -0
  116. package/dist/rules/no-stacked-jsdoc-blocks.js +50 -0
  117. package/dist/rules/no-stray-inline-comments.d.ts +2 -0
  118. package/dist/rules/no-stray-inline-comments.js +74 -0
  119. package/dist/rules/no-swappable-primitive-params.d.ts +2 -0
  120. package/dist/rules/no-swappable-primitive-params.js +96 -0
  121. package/dist/rules/no-tag-ladder-assertions.d.ts +6 -0
  122. package/dist/rules/no-tag-ladder-assertions.js +63 -0
  123. package/dist/rules/no-transposed-field-reads.d.ts +8 -0
  124. package/dist/rules/no-transposed-field-reads.js +101 -0
  125. package/dist/rules/no-unit-return-validators.d.ts +2 -0
  126. package/dist/rules/no-unit-return-validators.js +64 -0
  127. package/dist/rules/no-unknown-parameters.d.ts +2 -0
  128. package/dist/rules/no-unknown-parameters.js +82 -0
  129. package/dist/rules/no-unknown-returns.d.ts +2 -0
  130. package/dist/rules/no-unknown-returns.js +86 -0
  131. package/dist/rules/no-unknown-type-aliases.d.ts +2 -0
  132. package/dist/rules/no-unknown-type-aliases.js +64 -0
  133. package/dist/rules/no-unsafe-dictionary-type.d.ts +2 -0
  134. package/dist/rules/no-unsafe-dictionary-type.js +116 -0
  135. package/dist/rules/no-vague-test-filenames.d.ts +2 -0
  136. package/dist/rules/no-vague-test-filenames.js +61 -0
  137. package/dist/rules/no-widen-then-assert.d.ts +2 -0
  138. package/dist/rules/no-widen-then-assert.js +268 -0
  139. package/dist/rules/prefer-payload-brand.d.ts +2 -0
  140. package/dist/rules/prefer-payload-brand.js +57 -0
  141. package/dist/rules/prefer-property-tests.d.ts +5 -0
  142. package/dist/rules/prefer-property-tests.js +39 -0
  143. package/dist/rules/require-canonical-stringify-for-identity.d.ts +8 -0
  144. package/dist/rules/require-canonical-stringify-for-identity.js +72 -0
  145. package/dist/rules/require-deprecated-tag-for-legacy-comments.d.ts +2 -0
  146. package/dist/rules/require-deprecated-tag-for-legacy-comments.js +34 -0
  147. package/dist/rules/require-exhaustive-tag-switch.d.ts +7 -0
  148. package/dist/rules/require-exhaustive-tag-switch.js +34 -0
  149. package/dist/rules/require-fc-block-predicate.d.ts +2 -0
  150. package/dist/rules/require-fc-block-predicate.js +37 -0
  151. package/dist/rules/require-jsdoc-on-exported.d.ts +2 -0
  152. package/dist/rules/require-jsdoc-on-exported.js +66 -0
  153. package/dist/rules/require-published-order.d.ts +2 -0
  154. package/dist/rules/require-published-order.js +102 -0
  155. package/dist/rules/require-safety-comment-for-type-assertion.d.ts +2 -0
  156. package/dist/rules/require-safety-comment-for-type-assertion.js +53 -0
  157. package/dist/rules/require-sort-comparator.d.ts +7 -0
  158. package/dist/rules/require-sort-comparator.js +34 -0
  159. package/dist/rules/test-utils.d.ts +35 -0
  160. package/dist/rules/test-utils.js +53 -0
  161. package/{src/shared/ancestors.ts → dist/shared/ancestors.d.ts} +1 -4
  162. package/dist/shared/ancestors.js +19 -0
  163. package/dist/shared/child-nodes.d.ts +12 -0
  164. package/dist/shared/child-nodes.js +26 -0
  165. package/dist/shared/dictionary-types.d.ts +55 -0
  166. package/dist/shared/dictionary-types.js +413 -0
  167. package/{src/shared/is-node.ts → dist/shared/is-node.d.ts} +2 -6
  168. package/dist/shared/is-node.js +10 -0
  169. package/dist/shared/lexical-type-parameters.d.ts +12 -0
  170. package/dist/shared/lexical-type-parameters.js +50 -0
  171. package/dist/shared/reflect-method.d.ts +15 -0
  172. package/dist/shared/reflect-method.js +32 -0
  173. package/{src/shared/rule-options.ts → dist/shared/rule-options.d.ts} +2 -7
  174. package/dist/shared/rule-options.js +12 -0
  175. package/{src/shared/structural.ts → dist/shared/structural.d.ts} +17 -44
  176. package/dist/shared/structural.js +40 -0
  177. package/{src/testing/index.ts → dist/testing/index.d.ts} +0 -1
  178. package/dist/testing/index.js +1 -0
  179. package/dist/testing/testable-rule.d.ts +38 -0
  180. package/dist/testing/testable-rule.js +70 -0
  181. package/package.json +7 -6
  182. package/src/effect/index.ts +0 -59
  183. package/src/effect/rules/guarded-op-must-return-effect.ts +0 -236
  184. package/src/effect/rules/guarded-op-must-return-option.ts +0 -97
  185. package/src/effect/rules/no-cascading-layer-provide.ts +0 -80
  186. package/src/effect/rules/no-decode-unknown-option.ts +0 -41
  187. package/src/effect/rules/no-direct-browser-storage.ts +0 -91
  188. package/src/effect/rules/no-direct-fetch.ts +0 -44
  189. package/src/effect/rules/no-manual-field-guards.ts +0 -144
  190. package/src/effect/rules/no-nested-layer-provide.ts +0 -51
  191. package/src/effect/rules/no-schema-class-modeling.ts +0 -59
  192. package/src/effect/rules/no-service-constructor-imports.ts +0 -50
  193. package/src/effect/rules/no-silent-error-swallow.ts +0 -99
  194. package/src/effect/rules/no-static-effect-service-forwarders.ts +0 -227
  195. package/src/effect/rules/no-try-catch.ts +0 -32
  196. package/src/effect/rules/no-unguarded-json-parse.ts +0 -211
  197. package/src/effect/rules/option-core-needs-effect-public.ts +0 -81
  198. package/src/effect/rules/prefer-die-for-precondition-defects.ts +0 -118
  199. package/src/effect/rules/prefer-effect-gen-for-guard-ladders.ts +0 -76
  200. package/src/effect/rules/prefer-effect-match.ts +0 -78
  201. package/src/effect/rules/prefer-effect-predicate-over-boolean-function.ts +0 -79
  202. package/src/effect/rules/prefer-named-guard-predicate.ts +0 -105
  203. package/src/effect/rules/prefer-option-pipeline.ts +0 -95
  204. package/src/effect/rules/prefer-ordering-match.ts +0 -152
  205. package/src/effect/rules/prefer-tagged-enum.ts +0 -68
  206. package/src/effect/rules/require-schema-type-derivation.ts +0 -83
  207. package/src/index.ts +0 -106
  208. package/src/meta/rules/no-disable-directives.ts +0 -38
  209. package/src/meta/rules/no-manual-ancestor-walks.ts +0 -27
  210. package/src/meta/rules/prefer-before-file-scope.ts +0 -57
  211. package/src/meta/rules/require-create-once.ts +0 -51
  212. package/src/meta/rules/require-rule-tester.ts +0 -57
  213. package/src/rules/no-anonymous-wide-tuples.ts +0 -38
  214. package/src/rules/no-barrel-export-star.ts +0 -30
  215. package/src/rules/no-boolean-field-signals.ts +0 -305
  216. package/src/rules/no-builtin-throws.ts +0 -83
  217. package/src/rules/no-chained-type-assertions.ts +0 -65
  218. package/src/rules/no-conditional-empty-object-spread.ts +0 -42
  219. package/src/rules/no-duplicated-literal-union.ts +0 -66
  220. package/src/rules/no-exported-mutable-state.ts +0 -111
  221. package/src/rules/no-generic-export-names.ts +0 -149
  222. package/src/rules/no-impossible-branch-throw.ts +0 -55
  223. package/src/rules/no-known-value-widening.ts +0 -225
  224. package/src/rules/no-module-mocking.ts +0 -95
  225. package/src/rules/no-multiple-function-params.ts +0 -192
  226. package/src/rules/no-nondeterministic-core.ts +0 -73
  227. package/src/rules/no-object-parameters.ts +0 -127
  228. package/src/rules/no-optional-function-parameters.ts +0 -49
  229. package/src/rules/no-product-of-state-booleans.ts +0 -80
  230. package/src/rules/no-redundant-derived-field.ts +0 -192
  231. package/src/rules/no-reflect-apply.ts +0 -32
  232. package/src/rules/no-reflect-get.ts +0 -32
  233. package/src/rules/no-reinterpret-cast.ts +0 -78
  234. package/src/rules/no-runtime-typeof.ts +0 -59
  235. package/src/rules/no-sentinel-comparison-union.ts +0 -148
  236. package/src/rules/no-shape-in-symbol-names.ts +0 -45
  237. package/src/rules/no-single-use-private-functions.ts +0 -329
  238. package/src/rules/no-stacked-jsdoc-blocks.ts +0 -65
  239. package/src/rules/no-stray-inline-comments.ts +0 -79
  240. package/src/rules/no-swappable-primitive-params.ts +0 -109
  241. package/src/rules/no-tag-ladder-assertions.ts +0 -71
  242. package/src/rules/no-transposed-field-reads.ts +0 -135
  243. package/src/rules/no-unit-return-validators.ts +0 -65
  244. package/src/rules/no-unknown-parameters.ts +0 -97
  245. package/src/rules/no-unknown-returns.ts +0 -120
  246. package/src/rules/no-unknown-type-aliases.ts +0 -70
  247. package/src/rules/no-unsafe-dictionary-type.ts +0 -132
  248. package/src/rules/no-vague-test-filenames.ts +0 -67
  249. package/src/rules/no-widen-then-assert.ts +0 -345
  250. package/src/rules/prefer-payload-brand.ts +0 -67
  251. package/src/rules/prefer-property-tests.ts +0 -43
  252. package/src/rules/require-canonical-stringify-for-identity.ts +0 -80
  253. package/src/rules/require-deprecated-tag-for-legacy-comments.ts +0 -45
  254. package/src/rules/require-exhaustive-tag-switch.ts +0 -42
  255. package/src/rules/require-fc-block-predicate.ts +0 -42
  256. package/src/rules/require-jsdoc-on-exported.ts +0 -74
  257. package/src/rules/require-published-order.ts +0 -109
  258. package/src/rules/require-safety-comment-for-type-assertion.ts +0 -61
  259. package/src/rules/require-sort-comparator.ts +0 -41
  260. package/src/rules/test-utils.ts +0 -68
  261. package/src/shared/child-nodes.ts +0 -27
  262. package/src/shared/dictionary-types.ts +0 -524
  263. package/src/shared/lexical-type-parameters.ts +0 -62
  264. package/src/shared/reflect-method.ts +0 -41
  265. package/src/testing/testable-rule.test.ts +0 -68
  266. package/src/testing/testable-rule.ts +0 -86
@@ -0,0 +1,176 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { classifyWideningTarget, createTypeEnvironment, isKnownEvidenceExpression, } from "../shared/dictionary-types.js";
3
+ import { ancestorsOf } from "../shared/ancestors.js";
4
+ function unwrapExpression(expression) {
5
+ let current = expression;
6
+ while (current.type === "ParenthesizedExpression" ||
7
+ current.type === "TSAsExpression" ||
8
+ current.type === "TSSatisfiesExpression" ||
9
+ current.type === "TSTypeAssertion" ||
10
+ current.type === "TSNonNullExpression") {
11
+ current = current.expression;
12
+ }
13
+ return current;
14
+ }
15
+ function resolveVariable(sourceCode, identifier) {
16
+ let scope = sourceCode.getScope(identifier);
17
+ while (scope !== null) {
18
+ const variable = scope.set.get(identifier.name);
19
+ if (variable !== undefined)
20
+ return variable;
21
+ scope = scope.upper;
22
+ }
23
+ return null;
24
+ }
25
+ function variableDeclarator(variable) {
26
+ if (variable.defs.length !== 1)
27
+ return null;
28
+ const [definition] = variable.defs;
29
+ return definition?.type === "Variable" && definition.node.type === "VariableDeclarator"
30
+ ? definition.node
31
+ : null;
32
+ }
33
+ function sourceKeyName(sourceCode, key) {
34
+ if (key.type === "Identifier" || key.type === "PrivateIdentifier")
35
+ return key.name;
36
+ if (key.type === "Literal")
37
+ return String(key.value);
38
+ return sourceCode.getText(key);
39
+ }
40
+ function functionName(sourceCode, owner) {
41
+ if (owner === null)
42
+ return "anonymous function";
43
+ if (owner.id !== null)
44
+ return owner.id.name;
45
+ const parent = ancestorsOf(sourceCode, owner).at(-1);
46
+ if (parent?.type === "VariableDeclarator" && parent.id.type === "Identifier")
47
+ return parent.id.name;
48
+ if (parent?.type === "MethodDefinition")
49
+ return sourceKeyName(sourceCode, parent.key);
50
+ return "anonymous function";
51
+ }
52
+ function hasParentAssertion(sourceCode, node) {
53
+ const parent = ancestorsOf(sourceCode, node).at(-1);
54
+ return parent?.type === "TSAsExpression" || parent?.type === "TSTypeAssertion";
55
+ }
56
+ /** Detect sound syntactic cases where a known value is explicitly widened and loses evidence. */
57
+ export const noKnownValueWideningRule = defineRule({
58
+ meta: {
59
+ type: "problem",
60
+ docs: {
61
+ description: "Disallow syntactically established values from flowing into explicitly broad or anonymous target types that discard useful evidence.",
62
+ },
63
+ messages: {
64
+ widening: "The explicit {{target}} type on {{subject}} discards known type evidence. Keep inference, validate with `satisfies`, or use a named owner contract.",
65
+ },
66
+ },
67
+ createOnce(context) {
68
+ let environment = null;
69
+ const reportFlow = (expression, destination, subject) => {
70
+ if (destination === null)
71
+ return;
72
+ const unwrapped = unwrapExpression(expression);
73
+ const accumulator = destination.kind === "open dictionary" || destination.kind === "generic container";
74
+ if (accumulator &&
75
+ unwrapped.type === "ObjectExpression" &&
76
+ unwrapped.properties.length === 0) {
77
+ return;
78
+ }
79
+ const visit = (expression, visitedVariables) => {
80
+ if (isKnownEvidenceExpression(expression))
81
+ return true;
82
+ const unwrapped = unwrapExpression(expression);
83
+ if (unwrapped.type !== "Identifier")
84
+ return false;
85
+ const variable = resolveVariable(context.sourceCode, unwrapped);
86
+ if (variable === null || visitedVariables.has(variable))
87
+ return false;
88
+ const declarator = variableDeclarator(variable);
89
+ if (declarator === null || declarator.init === null)
90
+ return false;
91
+ const declaration = ancestorsOf(context.sourceCode, declarator).at(-1);
92
+ const stableConst = declaration?.type === "VariableDeclaration" &&
93
+ declaration.kind === "const" &&
94
+ variable.references.every((reference) => reference.init || !reference.isWrite());
95
+ if (!stableConst)
96
+ return false;
97
+ visitedVariables.add(variable);
98
+ return visit(declarator.init, visitedVariables);
99
+ };
100
+ if (!visit(expression, new Set()))
101
+ return;
102
+ context.report({
103
+ node: expression,
104
+ messageId: "widening",
105
+ data: { subject, target: destination.kind },
106
+ });
107
+ };
108
+ const targetFromAnnotation = (annotation) => environment === null || annotation === null || annotation === undefined
109
+ ? null
110
+ : classifyWideningTarget(annotation.typeAnnotation, environment);
111
+ return {
112
+ Program(node) {
113
+ environment = createTypeEnvironment(node);
114
+ },
115
+ VariableDeclarator(node) {
116
+ if (node.init === null || node.id.type !== "Identifier")
117
+ return;
118
+ reportFlow(node.init, targetFromAnnotation(node.id.typeAnnotation), `binding \`${node.id.name}\``);
119
+ },
120
+ PropertyDefinition(node) {
121
+ if (node.value === null)
122
+ return;
123
+ reportFlow(node.value, targetFromAnnotation(node.typeAnnotation), `property \`${sourceKeyName(context.sourceCode, node.key)}\``);
124
+ },
125
+ AccessorProperty(node) {
126
+ if (node.value === null)
127
+ return;
128
+ reportFlow(node.value, targetFromAnnotation(node.typeAnnotation), `property \`${sourceKeyName(context.sourceCode, node.key)}\``);
129
+ },
130
+ AssignmentExpression(node) {
131
+ if (node.operator !== "=" || node.left.type !== "Identifier")
132
+ return;
133
+ const variable = resolveVariable(context.sourceCode, node.left);
134
+ if (variable === null)
135
+ return;
136
+ const declarator = variableDeclarator(variable);
137
+ if (declarator === null || declarator.id.type !== "Identifier")
138
+ return;
139
+ reportFlow(node.right, targetFromAnnotation(declarator.id.typeAnnotation), `binding \`${declarator.id.name}\``);
140
+ },
141
+ ReturnStatement(node) {
142
+ if (node.argument === null)
143
+ return;
144
+ let owner = null;
145
+ const ancestors = ancestorsOf(context.sourceCode, node);
146
+ for (let index = ancestors.length - 1; index >= 0; index--) {
147
+ const current = ancestors[index];
148
+ if (current.type === "Program")
149
+ break;
150
+ if (current.type === "ArrowFunctionExpression" ||
151
+ current.type === "FunctionDeclaration" ||
152
+ current.type === "FunctionExpression") {
153
+ owner = current;
154
+ break;
155
+ }
156
+ }
157
+ reportFlow(node.argument, targetFromAnnotation(owner?.returnType), `return value of \`${functionName(context.sourceCode, owner)}\``);
158
+ },
159
+ ArrowFunctionExpression(node) {
160
+ if (node.body.type === "BlockStatement")
161
+ return;
162
+ reportFlow(node.body, targetFromAnnotation(node.returnType), `return value of \`${functionName(context.sourceCode, node)}\``);
163
+ },
164
+ TSAsExpression(node) {
165
+ if (environment === null || hasParentAssertion(context.sourceCode, node))
166
+ return;
167
+ reportFlow(node.expression, classifyWideningTarget(node.typeAnnotation, environment), "assertion");
168
+ },
169
+ TSTypeAssertion(node) {
170
+ if (environment === null || hasParentAssertion(context.sourceCode, node))
171
+ return;
172
+ reportFlow(node.expression, classifyWideningTarget(node.typeAnnotation, environment), "assertion");
173
+ },
174
+ };
175
+ },
176
+ });
@@ -0,0 +1,2 @@
1
+ /** Ban test framework module mocking in favor of real dependency seams. */
2
+ export declare const noModuleMockingRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,90 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { ancestorsOf } from "../shared/ancestors.js";
3
+ const moduleMockMethods = new Set(["doMock", "mock", "unstable_mockModule"]);
4
+ /**
5
+ * Whether a callee invokes a test framework's module mocking API
6
+ * (`vi.doMock`, `jest.mock`, `vi.unstable_mockModule`), either through the
7
+ * global or through a binding imported from vitest / @jest/globals.
8
+ *
9
+ * @param {SourceCode} sourceCode - The rule's source-code accessor.
10
+ * @param {ESTree.Expression} callee - The visited call expression's callee.
11
+ * @returns {boolean} True when the call mocks a module.
12
+ */
13
+ function moduleMockCall(sourceCode, callee) {
14
+ if (callee.type !== "MemberExpression")
15
+ return false;
16
+ if (callee.object.type !== "Identifier")
17
+ return false;
18
+ const identifier = callee.object;
19
+ let resolved = null;
20
+ let scope = sourceCode.getScope(identifier);
21
+ while (scope !== null) {
22
+ const variable = scope.set.get(identifier.name);
23
+ if (variable !== undefined) {
24
+ resolved = variable;
25
+ break;
26
+ }
27
+ scope = scope.upper;
28
+ }
29
+ const isTestFrameworkName = identifier.name === "vi" || identifier.name === "jest";
30
+ let boundToFramework;
31
+ if (resolved === null || resolved.defs.length === 0) {
32
+ boundToFramework =
33
+ (isTestFrameworkName && sourceCode.isGlobalReference(identifier)) || isTestFrameworkName;
34
+ }
35
+ else {
36
+ boundToFramework = resolved.defs.some((definition) => {
37
+ if (definition.type !== "ImportBinding")
38
+ return false;
39
+ const importDeclaration = ancestorsOf(sourceCode, definition.node).at(-1);
40
+ if (importDeclaration?.type !== "ImportDeclaration")
41
+ return false;
42
+ const source = importDeclaration.source.value;
43
+ const specifier = definition.node;
44
+ const importedName = specifier.type === "ImportSpecifier"
45
+ ? specifier.imported.type === "Identifier"
46
+ ? specifier.imported.name
47
+ : specifier.imported.value
48
+ : null;
49
+ return ((source === "vitest" && importedName === "vi") ||
50
+ (source === "@jest/globals" && importedName === "jest"));
51
+ });
52
+ }
53
+ if (!boundToFramework)
54
+ return false;
55
+ const property = callee.property;
56
+ const method = callee.computed
57
+ ? property.type === "Literal" &&
58
+ (property.value === "doMock" ||
59
+ property.value === "mock" ||
60
+ property.value === "unstable_mockModule")
61
+ ? property.value
62
+ : null
63
+ : property.type === "Identifier"
64
+ ? property.name
65
+ : null;
66
+ return method !== null && moduleMockMethods.has(method);
67
+ }
68
+ /** Ban test framework module mocking in favor of real dependency seams. */
69
+ export const noModuleMockingRule = defineRule({
70
+ meta: {
71
+ type: "problem",
72
+ docs: {
73
+ description: "Disallow Vitest and Jest module mocking; tests must replace dependencies through real interfaces.",
74
+ },
75
+ messages: {
76
+ moduleMock: "Replace module mocking with dependency injection through a real interface, service layer, or faithful test implementation.",
77
+ },
78
+ },
79
+ createOnce(context) {
80
+ return {
81
+ CallExpression(node) {
82
+ if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression")
83
+ return;
84
+ if (moduleMockCall(context.sourceCode, node.callee)) {
85
+ context.report({ node, messageId: "moduleMock" });
86
+ }
87
+ },
88
+ };
89
+ },
90
+ });
@@ -0,0 +1,2 @@
1
+ /** Owned functions taking several positional inputs accept transposed arguments silently; require one payload object. */
2
+ export declare const noMultipleFunctionParamsRule: import("@oxlint/plugins").Rule;
@@ -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,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;