@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,101 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { isString } from "../shared/structural.js";
3
+ import { firstOptionRecord } from "../shared/rule-options.js";
4
+ /** The `base.field` pluck of a direct member read, or null for anything more elaborate.
5
+ * @param {ESTree.Expression | null | undefined} expression - Argument or spread expression to inspect.
6
+ * @param {(node: ESTree.Node) => string} getText - Source text accessor from the lint context.
7
+ * @returns {{ baseText: string; field: string }} Base text and field name, or null when not a simple pluck. */
8
+ function directPluck(expression, getText) {
9
+ if (expression === undefined || expression === null)
10
+ return null;
11
+ let member = expression;
12
+ while (member.type === "ParenthesizedExpression")
13
+ member = member.expression;
14
+ if (member.type !== "MemberExpression" || member.computed || member.property.type !== "Identifier") {
15
+ return null;
16
+ }
17
+ return { baseText: getText(member.object), field: member.property.name };
18
+ }
19
+ /**
20
+ * Flag argument lists and object literals that pluck two or more role fields
21
+ * off the same base expression in reversed canonical order: the syntactic
22
+ * fingerprint of inline structural surgery on a domain value (e.g. a
23
+ * hand-rolled reciprocal). Such shuffles belong behind a named operation
24
+ * that owns the invariant.
25
+ */
26
+ export const noTransposedFieldReadsRule = defineRule({
27
+ meta: {
28
+ type: "problem",
29
+ docs: {
30
+ description: 'Disallow directly reading two or more configured role fields from the same expression in reversed order inside call arguments or object literals; require a named domain operation instead. Configure `groups` with your domain\'s canonical field pairings (e.g. groups: [["startDate", "endDate"]]).',
31
+ },
32
+ messages: {
33
+ transposedFieldReads: "`{{base}}.{{first}}` is read after `{{base}}.{{second}}`, reversing the canonical order {{group}}; this looks like inline structural surgery on a domain value. Use a named operation instead of shuffling its fields by hand.",
34
+ },
35
+ schema: [
36
+ {
37
+ type: "object",
38
+ properties: {
39
+ groups: {
40
+ type: "array",
41
+ items: { type: "array", items: { type: "string" }, minItems: 2 },
42
+ },
43
+ },
44
+ additionalProperties: false,
45
+ },
46
+ ],
47
+ // Inert until configured: which field pairs have a canonical order is
48
+ // consumer-domain knowledge (e.g. numerator/denominator, startDate/endDate),
49
+ // so no universal default exists.
50
+ defaultOptions: [{ groups: [] }],
51
+ },
52
+ createOnce(context) {
53
+ const option = firstOptionRecord(context.options);
54
+ const groups = (Array.isArray(option.groups) ? option.groups : [])
55
+ .filter((group) => Array.isArray(group) && group.every((field) => isString(field)))
56
+ .map((fields) => ({
57
+ order: new Map(fields.map((field, index) => [field, index])),
58
+ label: fields.join(" → "),
59
+ }));
60
+ const checkSequence = (node, parts) => {
61
+ const getText = (target) => context.sourceCode.getText(target);
62
+ const plucks = [];
63
+ for (const [position, part] of parts.entries()) {
64
+ const direct = directPluck(part.expression, getText);
65
+ if (direct === null)
66
+ continue;
67
+ plucks.push({ ...direct, position });
68
+ }
69
+ for (const group of groups) {
70
+ const inGroup = plucks.filter((pluck) => group.order.has(pluck.field));
71
+ for (const later of inGroup) {
72
+ for (const earlier of inGroup) {
73
+ if (earlier.baseText !== later.baseText || earlier.position >= later.position)
74
+ continue;
75
+ if ((group.order.get(earlier.field) ?? 0) > (group.order.get(later.field) ?? 0)) {
76
+ context.report({
77
+ node,
78
+ messageId: "transposedFieldReads",
79
+ data: {
80
+ base: earlier.baseText,
81
+ first: later.field,
82
+ second: earlier.field,
83
+ group: group.label,
84
+ },
85
+ });
86
+ break;
87
+ }
88
+ }
89
+ }
90
+ }
91
+ };
92
+ return {
93
+ CallExpression(node) {
94
+ checkSequence(node, node.arguments.map((argument) => ({ expression: argument })));
95
+ },
96
+ ObjectExpression(node) {
97
+ checkSequence(node, node.properties.map((property) => property.type === "Property" ? { expression: property.value } : { expression: undefined }));
98
+ },
99
+ };
100
+ },
101
+ });
@@ -0,0 +1,2 @@
1
+ /** Validators that return nothing throw away what they just learned. */
2
+ export declare const noUnitReturnValidatorsRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,64 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ const VALIDATOR_NAME = /^(?:validate|check|ensure)/u;
3
+ /**
4
+ * Whether a validator function declares void/undefined as its return type.
5
+ *
6
+ * @param {ValidatorFunction} node - The function-like node to inspect.
7
+ * @returns {boolean} True when the return annotation is void or undefined.
8
+ */
9
+ function returnsVoid(node) {
10
+ const annotation = node.returnType;
11
+ if (annotation === null || annotation === undefined)
12
+ return false;
13
+ const type = annotation.typeAnnotation;
14
+ if (type.type === "TSVoidKeyword" || type.type === "TSUndefinedKeyword")
15
+ return true;
16
+ if (type.type === "TSParenthesizedType") {
17
+ const inner = type.typeAnnotation;
18
+ return inner.type === "TSVoidKeyword" || inner.type === "TSUndefinedKeyword";
19
+ }
20
+ return false;
21
+ }
22
+ /** Validators that return nothing throw away what they just learned. */
23
+ export const noUnitReturnValidatorsRule = defineRule({
24
+ meta: {
25
+ type: "problem",
26
+ docs: {
27
+ description: "Disallow validators that return nothing (void/undefined); a check should preserve what it learned by returning the refined value.",
28
+ },
29
+ messages: {
30
+ unitValidator: "`{{name}}` validates and returns nothing (void). Return the refined value (Option/parsed type) so the knowledge survives: parse, don't validate.",
31
+ },
32
+ },
33
+ createOnce(context) {
34
+ const report = (name, node, validator) => {
35
+ if (!VALIDATOR_NAME.test(name))
36
+ return;
37
+ if (!returnsVoid(validator))
38
+ return;
39
+ context.report({ node, messageId: "unitValidator", data: { name } });
40
+ };
41
+ return {
42
+ ExportNamedDeclaration(node) {
43
+ const declaration = node.declaration;
44
+ if (declaration === null)
45
+ return;
46
+ if (declaration.type === "FunctionDeclaration") {
47
+ if (declaration.id !== null)
48
+ report(declaration.id.name, declaration, declaration);
49
+ return;
50
+ }
51
+ if (declaration.type !== "VariableDeclaration")
52
+ return;
53
+ for (const declarator of declaration.declarations) {
54
+ const init = declarator.init;
55
+ if (init === null || init === undefined || init.type !== "ArrowFunctionExpression")
56
+ continue;
57
+ if (declarator.id.type !== "Identifier")
58
+ continue;
59
+ report(declarator.id.name, declarator, init);
60
+ }
61
+ },
62
+ };
63
+ },
64
+ });
@@ -0,0 +1,2 @@
1
+ /** Disallow unknown inputs except explicitly named error-cause enrichment. */
2
+ export declare const noUnknownParametersRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,82 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ /** Unwrap parameter-property/rest/default wrappers to the declared annotation.
3
+ *
4
+ * @param {Parameter} parameter - The parameter pattern to inspect.
5
+ * @returns {ESTree.TSTypeAnnotation | null | undefined} The declared type annotation, if any.
6
+ */
7
+ function parameterAnnotation(parameter) {
8
+ if (parameter.type === "TSParameterProperty") {
9
+ return parameterAnnotation(parameter.parameter);
10
+ }
11
+ if (parameter.type === "RestElement") {
12
+ return parameter.typeAnnotation ?? parameterAnnotation(parameter.argument);
13
+ }
14
+ if (parameter.type === "AssignmentPattern") {
15
+ return parameter.typeAnnotation ?? parameter.left.typeAnnotation;
16
+ }
17
+ return parameter.typeAnnotation;
18
+ }
19
+ /** Render a parameter's source name for reporting.
20
+ *
21
+ * @param {{ parameter: Parameter; sourceText: string }} payload - The pattern and its source text.
22
+ * @returns {string} The bound identifier's name, or the raw unknown-annotated text.
23
+ */
24
+ function parameterName(payload) {
25
+ const { parameter, sourceText } = payload;
26
+ if (parameter.type === "TSParameterProperty") {
27
+ return parameterName({ parameter: parameter.parameter, sourceText });
28
+ }
29
+ if (parameter.type === "AssignmentPattern") {
30
+ return parameterName({ parameter: parameter.left, sourceText });
31
+ }
32
+ if (parameter.type === "RestElement") {
33
+ return parameterName({ parameter: parameter.argument, sourceText });
34
+ }
35
+ return parameter.type === "Identifier"
36
+ ? parameter.name
37
+ : sourceText.replace(/\s*:\s*unknown\s*$/u, "");
38
+ }
39
+ /** Disallow unknown inputs except explicitly named error-cause enrichment. */
40
+ export const noUnknownParametersRule = defineRule({
41
+ meta: {
42
+ type: "problem",
43
+ docs: {
44
+ description: "Disallow explicitly unknown function parameters except `cause`; decode unknown input at its I/O boundary instead.",
45
+ },
46
+ messages: {
47
+ unknownParameter: "Parameter `{{parameter}}` leaves input unparsed. Accept a named domain type; run the expected schema or parser at the I/O boundary before calling this function.",
48
+ },
49
+ },
50
+ createOnce(context) {
51
+ const checkParameters = (node) => {
52
+ for (const parameter of node.params) {
53
+ const annotation = parameterAnnotation(parameter);
54
+ if (annotation?.typeAnnotation.type !== "TSUnknownKeyword")
55
+ continue;
56
+ const name = parameterName({
57
+ parameter,
58
+ sourceText: context.sourceCode.getText(parameter),
59
+ });
60
+ if (name === "cause")
61
+ continue;
62
+ context.report({
63
+ node: annotation.typeAnnotation,
64
+ messageId: "unknownParameter",
65
+ data: { parameter: name },
66
+ });
67
+ }
68
+ };
69
+ return {
70
+ ArrowFunctionExpression: checkParameters,
71
+ FunctionDeclaration: checkParameters,
72
+ FunctionExpression: checkParameters,
73
+ TSCallSignatureDeclaration: checkParameters,
74
+ TSConstructSignatureDeclaration: checkParameters,
75
+ TSConstructorType: checkParameters,
76
+ TSDeclareFunction: checkParameters,
77
+ TSEmptyBodyFunctionExpression: checkParameters,
78
+ TSFunctionType: checkParameters,
79
+ TSMethodSignature: checkParameters,
80
+ };
81
+ },
82
+ });
@@ -0,0 +1,2 @@
1
+ /** Ban function contracts that return unknown instead of a parsed domain type. */
2
+ export declare const noUnknownReturnsRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,86 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { ancestorsOf } from "../shared/ancestors.js";
3
+ import { lexicalTypeParameterNames } from "../shared/lexical-type-parameters.js";
4
+ function referencedAliasName(type) {
5
+ if (type.type === "TSParenthesizedType")
6
+ return referencedAliasName(type.typeAnnotation);
7
+ if (type.type !== "TSTypeReference" || type.typeName.type !== "Identifier")
8
+ return null;
9
+ return type.typeArguments === null ||
10
+ type.typeArguments === undefined ||
11
+ type.typeArguments.params.length === 0
12
+ ? type.typeName.name
13
+ : null;
14
+ }
15
+ /** Ban function contracts that return unknown instead of a parsed domain type. */
16
+ export const noUnknownReturnsRule = defineRule({
17
+ meta: {
18
+ type: "problem",
19
+ docs: {
20
+ description: "Disallow functions whose explicit return contract is unknown or Promise<unknown>.",
21
+ },
22
+ messages: {
23
+ unknownReturn: "This function exposes `unknown` to its caller. Parse the value at its boundary and return a named domain type.",
24
+ },
25
+ },
26
+ createOnce(context) {
27
+ const aliases = new Map();
28
+ const resolvesToUnknown = (type, shadowedAliases, visited = new Set()) => {
29
+ if (type.type === "TSUnknownKeyword")
30
+ return true;
31
+ if (type.type === "TSParenthesizedType") {
32
+ return resolvesToUnknown(type.typeAnnotation, shadowedAliases, visited);
33
+ }
34
+ if (type.type === "TSUnionType") {
35
+ return type.types.some((member) => resolvesToUnknown(member, shadowedAliases, visited));
36
+ }
37
+ if (type.type === "TSTypeReference" &&
38
+ type.typeName.type === "Identifier" &&
39
+ (type.typeName.name === "Promise" || type.typeName.name === "PromiseLike")) {
40
+ const value = type.typeArguments?.params[0];
41
+ return value !== undefined && resolvesToUnknown(value, shadowedAliases, visited);
42
+ }
43
+ const name = referencedAliasName(type);
44
+ if (name === null || visited.has(name) || shadowedAliases.has(name))
45
+ return false;
46
+ const alias = aliases.get(name);
47
+ if (alias === undefined ||
48
+ (alias.typeParameters !== null && alias.typeParameters !== undefined)) {
49
+ return false;
50
+ }
51
+ const nextVisited = new Set(visited);
52
+ nextVisited.add(name);
53
+ return resolvesToUnknown(alias.typeAnnotation, shadowedAliases, nextVisited);
54
+ };
55
+ const checkReturnType = (node) => {
56
+ const annotation = node.returnType;
57
+ if (annotation === null || annotation === undefined)
58
+ return;
59
+ if (!resolvesToUnknown(annotation.typeAnnotation, lexicalTypeParameterNames(node, ancestorsOf(context.sourceCode, node), context.sourceCode.visitorKeys))) {
60
+ return;
61
+ }
62
+ context.report({ node: annotation.typeAnnotation, messageId: "unknownReturn" });
63
+ };
64
+ return {
65
+ Program(node) {
66
+ aliases.clear();
67
+ for (const statement of node.body) {
68
+ const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
69
+ if (declaration?.type === "TSTypeAliasDeclaration") {
70
+ aliases.set(declaration.id.name, declaration);
71
+ }
72
+ }
73
+ },
74
+ ArrowFunctionExpression: checkReturnType,
75
+ FunctionDeclaration: checkReturnType,
76
+ FunctionExpression: checkReturnType,
77
+ TSCallSignatureDeclaration: checkReturnType,
78
+ TSConstructSignatureDeclaration: checkReturnType,
79
+ TSConstructorType: checkReturnType,
80
+ TSDeclareFunction: checkReturnType,
81
+ TSEmptyBodyFunctionExpression: checkReturnType,
82
+ TSFunctionType: checkReturnType,
83
+ TSMethodSignature: checkReturnType,
84
+ };
85
+ },
86
+ });
@@ -0,0 +1,2 @@
1
+ /** Ban named aliases that merely conceal TypeScript's unknown top type. */
2
+ export declare const noUnknownTypeAliasesRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,64 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ function referencedAliasName(type) {
3
+ if (type.type === "TSParenthesizedType")
4
+ return referencedAliasName(type.typeAnnotation);
5
+ if (type.type !== "TSTypeReference" || type.typeName.type !== "Identifier")
6
+ return null;
7
+ return type.typeArguments === null ||
8
+ type.typeArguments === undefined ||
9
+ type.typeArguments.params.length === 0
10
+ ? type.typeName.name
11
+ : null;
12
+ }
13
+ /** Ban named aliases that merely conceal TypeScript's unknown top type. */
14
+ export const noUnknownTypeAliasesRule = defineRule({
15
+ meta: {
16
+ type: "problem",
17
+ docs: {
18
+ description: "Disallow type aliases whose resolved type is unknown; unknown must remain visible at an allowed boundary.",
19
+ },
20
+ messages: {
21
+ unknownAlias: "Type alias `{{alias}}` hides `unknown`. Keep `unknown` explicit at the parsing boundary or on an allowed `cause` field; otherwise use the parsed owner type.",
22
+ },
23
+ },
24
+ createOnce(context) {
25
+ const aliases = new Map();
26
+ const resolvesToUnknown = (type, visited = new Set()) => {
27
+ if (type.type === "TSUnknownKeyword")
28
+ return true;
29
+ if (type.type === "TSParenthesizedType")
30
+ return resolvesToUnknown(type.typeAnnotation, visited);
31
+ const name = referencedAliasName(type);
32
+ if (name === null || visited.has(name))
33
+ return false;
34
+ const alias = aliases.get(name);
35
+ if (alias === undefined ||
36
+ (alias.typeParameters !== null && alias.typeParameters !== undefined)) {
37
+ return false;
38
+ }
39
+ const nextVisited = new Set(visited);
40
+ nextVisited.add(name);
41
+ return resolvesToUnknown(alias.typeAnnotation, nextVisited);
42
+ };
43
+ return {
44
+ Program(node) {
45
+ aliases.clear();
46
+ for (const statement of node.body) {
47
+ const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
48
+ if (declaration?.type === "TSTypeAliasDeclaration") {
49
+ aliases.set(declaration.id.name, declaration);
50
+ }
51
+ }
52
+ for (const alias of aliases.values()) {
53
+ if (!resolvesToUnknown(alias.typeAnnotation, new Set([alias.id.name])))
54
+ continue;
55
+ context.report({
56
+ node: alias.id,
57
+ messageId: "unknownAlias",
58
+ data: { alias: alias.id.name },
59
+ });
60
+ }
61
+ },
62
+ };
63
+ },
64
+ });
@@ -0,0 +1,2 @@
1
+ /** Disallow object-dictionary contracts whose direct value type is an unsafe escape hatch. */
2
+ export declare const noUnsafeDictionaryTypeRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,116 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { classifyUnsafeDictionary, classifyUnsafeDictionaryValue, createTypeEnvironment, } from "../shared/dictionary-types.js";
3
+ import { ancestorsOf } from "../shared/ancestors.js";
4
+ const typeNodeKinds = new Set([
5
+ "JSDocNonNullableType",
6
+ "JSDocNullableType",
7
+ "JSDocUnknownType",
8
+ "TSAnyKeyword",
9
+ "TSArrayType",
10
+ "TSBigIntKeyword",
11
+ "TSBooleanKeyword",
12
+ "TSConditionalType",
13
+ "TSConstructorType",
14
+ "TSFunctionType",
15
+ "TSImportType",
16
+ "TSIndexedAccessType",
17
+ "TSInferType",
18
+ "TSIntersectionType",
19
+ "TSIntrinsicKeyword",
20
+ "TSLiteralType",
21
+ "TSMappedType",
22
+ "TSNamedTupleMember",
23
+ "TSNeverKeyword",
24
+ "TSNullKeyword",
25
+ "TSNumberKeyword",
26
+ "TSObjectKeyword",
27
+ "TSParenthesizedType",
28
+ "TSStringKeyword",
29
+ "TSSymbolKeyword",
30
+ "TSTemplateLiteralType",
31
+ "TSThisType",
32
+ "TSTupleType",
33
+ "TSTypeLiteral",
34
+ "TSTypeOperator",
35
+ "TSTypePredicate",
36
+ "TSTypeQuery",
37
+ "TSTypeReference",
38
+ "TSUndefinedKeyword",
39
+ "TSUnionType",
40
+ "TSUnknownKeyword",
41
+ "TSVoidKeyword",
42
+ ]);
43
+ /**
44
+ * Whether a node is one of the grammar's type-node kinds.
45
+ *
46
+ * @param {ESTree.Node} node - The ancestor node to test.
47
+ * @returns {boolean} True when the node is a type node.
48
+ */
49
+ function isTypeNode(node) {
50
+ return typeNodeKinds.has(node.type);
51
+ }
52
+ /** Disallow object-dictionary contracts whose direct value type is an unsafe escape hatch. */
53
+ export const noUnsafeDictionaryTypeRule = defineRule({
54
+ meta: {
55
+ type: "problem",
56
+ docs: {
57
+ description: "Disallow object-dictionary contracts whose direct value type is unknown, any, object, {}, or a union/alias containing one of those escape hatches.",
58
+ },
59
+ messages: {
60
+ unsafeDictionary: "This dictionary's {{value}} value type gives callers no concrete value contract. Use an owner/schema-derived value type; parse external payloads before insertion.",
61
+ },
62
+ },
63
+ createOnce(context) {
64
+ let environment = null;
65
+ const report = (node, value) => {
66
+ context.report({ node, messageId: "unsafeDictionary", data: { value } });
67
+ };
68
+ const reportIfUnsafe = (node) => {
69
+ if (environment === null)
70
+ return;
71
+ if (node.type === "TSTypeReference" && !node.typeArguments?.params.length) {
72
+ const aliasName = node.typeName.type === "Identifier" ? node.typeName.name : null;
73
+ if (aliasName !== null && environment.aliases.has(aliasName)) {
74
+ let insideAliasDeclaration = false;
75
+ for (const current of ancestorsOf(context.sourceCode, node)) {
76
+ if (current.type === "Program")
77
+ break;
78
+ if (current.type === "TSTypeAliasDeclaration") {
79
+ insideAliasDeclaration = true;
80
+ break;
81
+ }
82
+ }
83
+ if (!insideAliasDeclaration)
84
+ return;
85
+ }
86
+ }
87
+ const unsafe = classifyUnsafeDictionary(node, environment);
88
+ if (unsafe === null)
89
+ return;
90
+ for (const current of ancestorsOf(context.sourceCode, node)) {
91
+ if (current.type === "Program")
92
+ break;
93
+ if (isTypeNode(current) && classifyUnsafeDictionary(current, environment) !== null)
94
+ return;
95
+ }
96
+ report(node, unsafe.unsafeValue);
97
+ };
98
+ return {
99
+ Program(node) {
100
+ environment = createTypeEnvironment(node);
101
+ },
102
+ TSTypeReference: reportIfUnsafe,
103
+ TSTypeLiteral: reportIfUnsafe,
104
+ TSMappedType: reportIfUnsafe,
105
+ TSIndexSignature(node) {
106
+ if (environment === null ||
107
+ node.typeAnnotation === null ||
108
+ ancestorsOf(context.sourceCode, node).at(-1)?.type === "TSTypeLiteral")
109
+ return;
110
+ const unsafe = classifyUnsafeDictionaryValue(node.typeAnnotation.typeAnnotation, environment);
111
+ if (unsafe !== null)
112
+ report(node, unsafe.unsafeValue);
113
+ },
114
+ };
115
+ },
116
+ });
@@ -0,0 +1,2 @@
1
+ /** Name test files after the source they cover so agents can navigate both directions. */
2
+ export declare const noVagueTestFilenamesRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,61 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
3
+ /** Stems that name nothing; a test file must point back at the module it covers. */
4
+ const VAGUE_STEMS = new Set([
5
+ "index",
6
+ "test",
7
+ "tests",
8
+ "spec",
9
+ "util",
10
+ "utils",
11
+ "helper",
12
+ "helpers",
13
+ "misc",
14
+ "common",
15
+ "shared",
16
+ "core",
17
+ "base",
18
+ "main",
19
+ "lib",
20
+ ]);
21
+ /** Strip the directory and extension from a test filename.
22
+ *
23
+ * @param {string} filename - The raw filename to process.
24
+ * @returns {string} The bare stem without path or extension. */
25
+ function testFileStem(filename) {
26
+ const segments = filename.replaceAll("\\", "/").split("/");
27
+ const base = segments[segments.length - 1] ?? "";
28
+ return base.replace(/\.[cm]?[jt]sx?$/u, "").replace(/\.(?:test|spec)$/u, "");
29
+ }
30
+ /** Name test files after the source they cover so agents can navigate both directions. */
31
+ export const noVagueTestFilenamesRule = defineRule({
32
+ meta: {
33
+ type: "problem",
34
+ docs: {
35
+ description: "Disallow vague test file names (index.test.ts, utils.test.ts, ...) because tests are found by searching for the source module's name; a test file that does not name the code it covers costs extra agent turns to locate.",
36
+ },
37
+ messages: {
38
+ vagueTestFilename: "Test file `{{stem}}.test.ts` does not name the source it covers. Rename it after the module under test (e.g. `stripe.ts` -> `stripe.test.ts`) so searches for the source name land on its tests too.",
39
+ },
40
+ },
41
+ createOnce(context) {
42
+ let filePath = "";
43
+ return {
44
+ before() {
45
+ filePath = context.filename.replaceAll("\\", "/");
46
+ },
47
+ Program(node) {
48
+ if (!TEST_FILE.test(filePath))
49
+ return;
50
+ const stem = testFileStem(filePath);
51
+ if (!VAGUE_STEMS.has(stem.toLowerCase()))
52
+ return;
53
+ context.report({
54
+ node,
55
+ messageId: "vagueTestFilename",
56
+ data: { stem },
57
+ });
58
+ },
59
+ };
60
+ },
61
+ });
@@ -0,0 +1,2 @@
1
+ /** Detect immutable local bindings that erase a known type and are later asserted back to a narrower type. */
2
+ export declare const noWidenThenAssertRule: import("@oxlint/plugins").Rule;