@autotelic/plumb 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (268) hide show
  1. package/dist/effect/index.d.ts +3 -0
  2. package/dist/effect/index.js +56 -0
  3. package/dist/effect/rules/guarded-op-must-return-effect.d.ts +6 -0
  4. package/dist/effect/rules/guarded-op-must-return-effect.js +235 -0
  5. package/dist/effect/rules/guarded-op-must-return-option.d.ts +2 -0
  6. package/dist/effect/rules/guarded-op-must-return-option.js +88 -0
  7. package/dist/effect/rules/no-cascading-layer-provide.d.ts +6 -0
  8. package/dist/effect/rules/no-cascading-layer-provide.js +73 -0
  9. package/dist/effect/rules/no-decode-unknown-option.d.ts +7 -0
  10. package/dist/effect/rules/no-decode-unknown-option.js +34 -0
  11. package/dist/effect/rules/no-direct-browser-storage.d.ts +2 -0
  12. package/dist/effect/rules/no-direct-browser-storage.js +88 -0
  13. package/dist/effect/rules/no-direct-fetch.d.ts +2 -0
  14. package/dist/effect/rules/no-direct-fetch.js +37 -0
  15. package/dist/effect/rules/no-manual-field-guards.d.ts +6 -0
  16. package/dist/effect/rules/no-manual-field-guards.js +129 -0
  17. package/dist/effect/rules/no-nested-layer-provide.d.ts +2 -0
  18. package/dist/effect/rules/no-nested-layer-provide.js +50 -0
  19. package/dist/effect/rules/no-schema-class-modeling.d.ts +2 -0
  20. package/dist/effect/rules/no-schema-class-modeling.js +52 -0
  21. package/dist/effect/rules/no-service-constructor-imports.d.ts +2 -0
  22. package/dist/effect/rules/no-service-constructor-imports.js +42 -0
  23. package/dist/effect/rules/no-silent-error-swallow.d.ts +2 -0
  24. package/dist/effect/rules/no-silent-error-swallow.js +95 -0
  25. package/dist/effect/rules/no-static-effect-service-forwarders.d.ts +6 -0
  26. package/dist/effect/rules/no-static-effect-service-forwarders.js +222 -0
  27. package/dist/effect/rules/no-try-catch.d.ts +2 -0
  28. package/dist/effect/rules/no-try-catch.js +30 -0
  29. package/dist/effect/rules/no-unguarded-json-parse.d.ts +5 -0
  30. package/dist/effect/rules/no-unguarded-json-parse.js +200 -0
  31. package/dist/effect/rules/option-core-needs-effect-public.d.ts +5 -0
  32. package/dist/effect/rules/option-core-needs-effect-public.js +76 -0
  33. package/dist/effect/rules/prefer-die-for-precondition-defects.d.ts +5 -0
  34. package/dist/effect/rules/prefer-die-for-precondition-defects.js +112 -0
  35. package/dist/effect/rules/prefer-effect-gen-for-guard-ladders.d.ts +5 -0
  36. package/dist/effect/rules/prefer-effect-gen-for-guard-ladders.js +72 -0
  37. package/dist/effect/rules/prefer-effect-match.d.ts +2 -0
  38. package/dist/effect/rules/prefer-effect-match.js +74 -0
  39. package/dist/effect/rules/prefer-effect-predicate-over-boolean-function.d.ts +2 -0
  40. package/dist/effect/rules/prefer-effect-predicate-over-boolean-function.js +75 -0
  41. package/dist/effect/rules/prefer-named-guard-predicate.d.ts +2 -0
  42. package/dist/effect/rules/prefer-named-guard-predicate.js +93 -0
  43. package/dist/effect/rules/prefer-option-pipeline.d.ts +2 -0
  44. package/dist/effect/rules/prefer-option-pipeline.js +87 -0
  45. package/dist/effect/rules/prefer-ordering-match.d.ts +2 -0
  46. package/dist/effect/rules/prefer-ordering-match.js +135 -0
  47. package/dist/effect/rules/prefer-tagged-enum.d.ts +2 -0
  48. package/dist/effect/rules/prefer-tagged-enum.js +66 -0
  49. package/dist/effect/rules/require-schema-type-derivation.d.ts +7 -0
  50. package/dist/effect/rules/require-schema-type-derivation.js +80 -0
  51. package/dist/index.d.ts +3 -0
  52. package/dist/index.js +104 -0
  53. package/dist/meta/index.d.ts +7 -0
  54. package/{src/meta/index.ts → dist/meta/index.js} +13 -16
  55. package/dist/meta/rules/no-disable-directives.d.ts +6 -0
  56. package/dist/meta/rules/no-disable-directives.js +35 -0
  57. package/dist/meta/rules/no-manual-ancestor-walks.d.ts +2 -0
  58. package/dist/meta/rules/no-manual-ancestor-walks.js +26 -0
  59. package/dist/meta/rules/prefer-before-file-scope.d.ts +2 -0
  60. package/dist/meta/rules/prefer-before-file-scope.js +57 -0
  61. package/dist/meta/rules/require-create-once.d.ts +2 -0
  62. package/dist/meta/rules/require-create-once.js +51 -0
  63. package/dist/meta/rules/require-rule-tester.d.ts +2 -0
  64. package/dist/meta/rules/require-rule-tester.js +50 -0
  65. package/dist/rules/no-anonymous-wide-tuples.d.ts +7 -0
  66. package/dist/rules/no-anonymous-wide-tuples.js +34 -0
  67. package/dist/rules/no-barrel-export-star.d.ts +2 -0
  68. package/dist/rules/no-barrel-export-star.js +26 -0
  69. package/dist/rules/no-boolean-field-signals.d.ts +2 -0
  70. package/dist/rules/no-boolean-field-signals.js +279 -0
  71. package/dist/rules/no-builtin-throws.d.ts +6 -0
  72. package/dist/rules/no-builtin-throws.js +74 -0
  73. package/dist/rules/no-chained-type-assertions.d.ts +2 -0
  74. package/dist/rules/no-chained-type-assertions.js +54 -0
  75. package/dist/rules/no-conditional-empty-object-spread.d.ts +2 -0
  76. package/dist/rules/no-conditional-empty-object-spread.js +36 -0
  77. package/dist/rules/no-duplicated-literal-union.d.ts +6 -0
  78. package/dist/rules/no-duplicated-literal-union.js +62 -0
  79. package/dist/rules/no-exported-mutable-state.d.ts +7 -0
  80. package/dist/rules/no-exported-mutable-state.js +104 -0
  81. package/dist/rules/no-generic-export-names.d.ts +2 -0
  82. package/dist/rules/no-generic-export-names.js +141 -0
  83. package/dist/rules/no-impossible-branch-throw.d.ts +2 -0
  84. package/dist/rules/no-impossible-branch-throw.js +51 -0
  85. package/dist/rules/no-known-value-widening.d.ts +2 -0
  86. package/dist/rules/no-known-value-widening.js +176 -0
  87. package/dist/rules/no-module-mocking.d.ts +2 -0
  88. package/dist/rules/no-module-mocking.js +90 -0
  89. package/dist/rules/no-multiple-function-params.d.ts +2 -0
  90. package/dist/rules/no-multiple-function-params.js +155 -0
  91. package/dist/rules/no-mutable-environment-capture.d.ts +7 -0
  92. package/dist/rules/no-mutable-environment-capture.js +134 -0
  93. package/dist/rules/no-nondeterministic-core.d.ts +6 -0
  94. package/dist/rules/no-nondeterministic-core.js +63 -0
  95. package/dist/rules/no-object-parameters.d.ts +2 -0
  96. package/dist/rules/no-object-parameters.js +95 -0
  97. package/dist/rules/no-optional-function-parameters.d.ts +7 -0
  98. package/dist/rules/no-optional-function-parameters.js +44 -0
  99. package/dist/rules/no-product-of-state-booleans.d.ts +2 -0
  100. package/dist/rules/no-product-of-state-booleans.js +79 -0
  101. package/dist/rules/no-redundant-derived-field.d.ts +6 -0
  102. package/dist/rules/no-redundant-derived-field.js +194 -0
  103. package/dist/rules/no-reflect-apply.d.ts +2 -0
  104. package/dist/rules/no-reflect-apply.js +29 -0
  105. package/dist/rules/no-reflect-get.d.ts +2 -0
  106. package/dist/rules/no-reflect-get.js +29 -0
  107. package/dist/rules/no-reinterpret-cast.d.ts +2 -0
  108. package/dist/rules/no-reinterpret-cast.js +68 -0
  109. package/dist/rules/no-runtime-typeof.d.ts +2 -0
  110. package/dist/rules/no-runtime-typeof.js +54 -0
  111. package/dist/rules/no-sentinel-comparison-union.d.ts +2 -0
  112. package/dist/rules/no-sentinel-comparison-union.js +139 -0
  113. package/dist/rules/no-shape-in-symbol-names.d.ts +2 -0
  114. package/dist/rules/no-shape-in-symbol-names.js +39 -0
  115. package/dist/rules/no-single-use-private-functions.d.ts +17 -0
  116. package/dist/rules/no-single-use-private-functions.js +419 -0
  117. package/dist/rules/no-stacked-jsdoc-blocks.d.ts +2 -0
  118. package/dist/rules/no-stacked-jsdoc-blocks.js +50 -0
  119. package/dist/rules/no-stray-inline-comments.d.ts +2 -0
  120. package/dist/rules/no-stray-inline-comments.js +74 -0
  121. package/dist/rules/no-swappable-primitive-params.d.ts +2 -0
  122. package/dist/rules/no-swappable-primitive-params.js +96 -0
  123. package/dist/rules/no-tag-ladder-assertions.d.ts +6 -0
  124. package/dist/rules/no-tag-ladder-assertions.js +63 -0
  125. package/dist/rules/no-transposed-field-reads.d.ts +8 -0
  126. package/dist/rules/no-transposed-field-reads.js +101 -0
  127. package/dist/rules/no-unit-return-validators.d.ts +2 -0
  128. package/dist/rules/no-unit-return-validators.js +64 -0
  129. package/dist/rules/no-unknown-parameters.d.ts +2 -0
  130. package/dist/rules/no-unknown-parameters.js +82 -0
  131. package/dist/rules/no-unknown-returns.d.ts +2 -0
  132. package/dist/rules/no-unknown-returns.js +86 -0
  133. package/dist/rules/no-unknown-type-aliases.d.ts +2 -0
  134. package/dist/rules/no-unknown-type-aliases.js +64 -0
  135. package/dist/rules/no-unsafe-dictionary-type.d.ts +2 -0
  136. package/dist/rules/no-unsafe-dictionary-type.js +116 -0
  137. package/dist/rules/no-vague-test-filenames.d.ts +2 -0
  138. package/dist/rules/no-vague-test-filenames.js +61 -0
  139. package/dist/rules/no-widen-then-assert.d.ts +2 -0
  140. package/dist/rules/no-widen-then-assert.js +268 -0
  141. package/dist/rules/prefer-payload-brand.d.ts +2 -0
  142. package/dist/rules/prefer-payload-brand.js +57 -0
  143. package/dist/rules/prefer-property-tests.d.ts +5 -0
  144. package/dist/rules/prefer-property-tests.js +39 -0
  145. package/dist/rules/require-canonical-stringify-for-identity.d.ts +8 -0
  146. package/dist/rules/require-canonical-stringify-for-identity.js +72 -0
  147. package/dist/rules/require-deprecated-tag-for-legacy-comments.d.ts +2 -0
  148. package/dist/rules/require-deprecated-tag-for-legacy-comments.js +34 -0
  149. package/dist/rules/require-exhaustive-tag-switch.d.ts +7 -0
  150. package/dist/rules/require-exhaustive-tag-switch.js +34 -0
  151. package/dist/rules/require-fc-block-predicate.d.ts +2 -0
  152. package/dist/rules/require-fc-block-predicate.js +37 -0
  153. package/dist/rules/require-jsdoc-on-exported.d.ts +2 -0
  154. package/dist/rules/require-jsdoc-on-exported.js +66 -0
  155. package/dist/rules/require-published-order.d.ts +2 -0
  156. package/dist/rules/require-published-order.js +102 -0
  157. package/dist/rules/require-safety-comment-for-type-assertion.d.ts +2 -0
  158. package/dist/rules/require-safety-comment-for-type-assertion.js +53 -0
  159. package/dist/rules/require-sort-comparator.d.ts +7 -0
  160. package/dist/rules/require-sort-comparator.js +34 -0
  161. package/dist/rules/test-utils.d.ts +35 -0
  162. package/dist/rules/test-utils.js +53 -0
  163. package/{src/shared/ancestors.ts → dist/shared/ancestors.d.ts} +1 -4
  164. package/dist/shared/ancestors.js +19 -0
  165. package/dist/shared/child-nodes.d.ts +12 -0
  166. package/dist/shared/child-nodes.js +26 -0
  167. package/dist/shared/dictionary-types.d.ts +55 -0
  168. package/dist/shared/dictionary-types.js +413 -0
  169. package/{src/shared/is-node.ts → dist/shared/is-node.d.ts} +2 -6
  170. package/dist/shared/is-node.js +10 -0
  171. package/dist/shared/lexical-type-parameters.d.ts +12 -0
  172. package/dist/shared/lexical-type-parameters.js +50 -0
  173. package/dist/shared/reflect-method.d.ts +15 -0
  174. package/dist/shared/reflect-method.js +32 -0
  175. package/{src/shared/rule-options.ts → dist/shared/rule-options.d.ts} +2 -7
  176. package/dist/shared/rule-options.js +12 -0
  177. package/{src/shared/structural.ts → dist/shared/structural.d.ts} +17 -44
  178. package/dist/shared/structural.js +40 -0
  179. package/{src/testing/index.ts → dist/testing/index.d.ts} +0 -1
  180. package/dist/testing/index.js +1 -0
  181. package/dist/testing/testable-rule.d.ts +38 -0
  182. package/dist/testing/testable-rule.js +70 -0
  183. package/package.json +7 -6
  184. package/src/effect/index.ts +0 -59
  185. package/src/effect/rules/guarded-op-must-return-effect.ts +0 -236
  186. package/src/effect/rules/guarded-op-must-return-option.ts +0 -97
  187. package/src/effect/rules/no-cascading-layer-provide.ts +0 -80
  188. package/src/effect/rules/no-decode-unknown-option.ts +0 -41
  189. package/src/effect/rules/no-direct-browser-storage.ts +0 -91
  190. package/src/effect/rules/no-direct-fetch.ts +0 -44
  191. package/src/effect/rules/no-manual-field-guards.ts +0 -144
  192. package/src/effect/rules/no-nested-layer-provide.ts +0 -51
  193. package/src/effect/rules/no-schema-class-modeling.ts +0 -59
  194. package/src/effect/rules/no-service-constructor-imports.ts +0 -50
  195. package/src/effect/rules/no-silent-error-swallow.ts +0 -99
  196. package/src/effect/rules/no-static-effect-service-forwarders.ts +0 -227
  197. package/src/effect/rules/no-try-catch.ts +0 -32
  198. package/src/effect/rules/no-unguarded-json-parse.ts +0 -211
  199. package/src/effect/rules/option-core-needs-effect-public.ts +0 -81
  200. package/src/effect/rules/prefer-die-for-precondition-defects.ts +0 -118
  201. package/src/effect/rules/prefer-effect-gen-for-guard-ladders.ts +0 -76
  202. package/src/effect/rules/prefer-effect-match.ts +0 -78
  203. package/src/effect/rules/prefer-effect-predicate-over-boolean-function.ts +0 -79
  204. package/src/effect/rules/prefer-named-guard-predicate.ts +0 -105
  205. package/src/effect/rules/prefer-option-pipeline.ts +0 -95
  206. package/src/effect/rules/prefer-ordering-match.ts +0 -152
  207. package/src/effect/rules/prefer-tagged-enum.ts +0 -68
  208. package/src/effect/rules/require-schema-type-derivation.ts +0 -83
  209. package/src/index.ts +0 -106
  210. package/src/meta/rules/no-disable-directives.ts +0 -38
  211. package/src/meta/rules/no-manual-ancestor-walks.ts +0 -27
  212. package/src/meta/rules/prefer-before-file-scope.ts +0 -57
  213. package/src/meta/rules/require-create-once.ts +0 -51
  214. package/src/meta/rules/require-rule-tester.ts +0 -57
  215. package/src/rules/no-anonymous-wide-tuples.ts +0 -38
  216. package/src/rules/no-barrel-export-star.ts +0 -30
  217. package/src/rules/no-boolean-field-signals.ts +0 -305
  218. package/src/rules/no-builtin-throws.ts +0 -83
  219. package/src/rules/no-chained-type-assertions.ts +0 -65
  220. package/src/rules/no-conditional-empty-object-spread.ts +0 -42
  221. package/src/rules/no-duplicated-literal-union.ts +0 -66
  222. package/src/rules/no-exported-mutable-state.ts +0 -111
  223. package/src/rules/no-generic-export-names.ts +0 -149
  224. package/src/rules/no-impossible-branch-throw.ts +0 -55
  225. package/src/rules/no-known-value-widening.ts +0 -225
  226. package/src/rules/no-module-mocking.ts +0 -95
  227. package/src/rules/no-multiple-function-params.ts +0 -192
  228. package/src/rules/no-nondeterministic-core.ts +0 -73
  229. package/src/rules/no-object-parameters.ts +0 -127
  230. package/src/rules/no-optional-function-parameters.ts +0 -49
  231. package/src/rules/no-product-of-state-booleans.ts +0 -80
  232. package/src/rules/no-redundant-derived-field.ts +0 -192
  233. package/src/rules/no-reflect-apply.ts +0 -32
  234. package/src/rules/no-reflect-get.ts +0 -32
  235. package/src/rules/no-reinterpret-cast.ts +0 -78
  236. package/src/rules/no-runtime-typeof.ts +0 -59
  237. package/src/rules/no-sentinel-comparison-union.ts +0 -148
  238. package/src/rules/no-shape-in-symbol-names.ts +0 -45
  239. package/src/rules/no-single-use-private-functions.ts +0 -329
  240. package/src/rules/no-stacked-jsdoc-blocks.ts +0 -65
  241. package/src/rules/no-stray-inline-comments.ts +0 -79
  242. package/src/rules/no-swappable-primitive-params.ts +0 -109
  243. package/src/rules/no-tag-ladder-assertions.ts +0 -71
  244. package/src/rules/no-transposed-field-reads.ts +0 -135
  245. package/src/rules/no-unit-return-validators.ts +0 -65
  246. package/src/rules/no-unknown-parameters.ts +0 -97
  247. package/src/rules/no-unknown-returns.ts +0 -120
  248. package/src/rules/no-unknown-type-aliases.ts +0 -70
  249. package/src/rules/no-unsafe-dictionary-type.ts +0 -132
  250. package/src/rules/no-vague-test-filenames.ts +0 -67
  251. package/src/rules/no-widen-then-assert.ts +0 -345
  252. package/src/rules/prefer-payload-brand.ts +0 -67
  253. package/src/rules/prefer-property-tests.ts +0 -43
  254. package/src/rules/require-canonical-stringify-for-identity.ts +0 -80
  255. package/src/rules/require-deprecated-tag-for-legacy-comments.ts +0 -45
  256. package/src/rules/require-exhaustive-tag-switch.ts +0 -42
  257. package/src/rules/require-fc-block-predicate.ts +0 -42
  258. package/src/rules/require-jsdoc-on-exported.ts +0 -74
  259. package/src/rules/require-published-order.ts +0 -109
  260. package/src/rules/require-safety-comment-for-type-assertion.ts +0 -61
  261. package/src/rules/require-sort-comparator.ts +0 -41
  262. package/src/rules/test-utils.ts +0 -68
  263. package/src/shared/child-nodes.ts +0 -27
  264. package/src/shared/dictionary-types.ts +0 -524
  265. package/src/shared/lexical-type-parameters.ts +0 -62
  266. package/src/shared/reflect-method.ts +0 -41
  267. package/src/testing/testable-rule.test.ts +0 -68
  268. package/src/testing/testable-rule.ts +0 -86
@@ -1,76 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import type { ESTree } from "@oxlint/plugins";
4
- import { ancestorsOf } from "../../shared/ancestors.ts";
5
-
6
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$|\/test\//u;
7
-
8
- const LADDER_THRESHOLD = 3;
9
-
10
- /** Whether this call is an Effect combinator chained in the flatMap/map ladder family.
11
- *
12
- * @param {ESTree.CallExpression} node - The candidate call expression.
13
- * @returns {boolean} True when the callee is an Effect flatMap/map-family combinator.
14
- */
15
- function isEffectLadderCombinator(node: ESTree.CallExpression): boolean {
16
- const callee = node.callee;
17
- if (callee.type !== "MemberExpression" || callee.computed) return false;
18
- if (callee.object.type !== "Identifier" || callee.object.name !== "Effect") return false;
19
- const name = callee.property.type === "Identifier" ? callee.property.name : "";
20
- return name === "flatMap" || name === "andThen" || name === "tap";
21
- }
22
-
23
- /**
24
- * Long Effect.flatMap ladders read as callback pyramids; Effect.gen renders the
25
- * same program as straight-line validation.
26
- */
27
- export const preferEffectGenForGuardLaddersRule = defineRule({
28
- meta: {
29
- type: "suggestion",
30
- docs: {
31
- description:
32
- "Suggest Effect.gen when a function chains several Effect.flatMap/andThen/tap combinators instead of reading as straight-line code.",
33
- },
34
- messages: {
35
- ladder:
36
- "This function chains {{count}} Effect ladder combinators. Rewrite with `Effect.gen` + `yield*` so the guard sequence reads top-to-bottom.",
37
- },
38
- },
39
- createOnce(context) {
40
- const counts = new Map<ESTree.Node, number>();
41
- const reported = new Set<ESTree.Node>();
42
- const enclosingFunction = (node: ESTree.Node): ESTree.Node | undefined => {
43
- const ancestors = ancestorsOf(context.sourceCode, node);
44
- for (let index = ancestors.length - 1; index >= 0; index--) {
45
- const current = ancestors[index]!;
46
- if (current.type === "Program") break;
47
- if (
48
- current.type === "FunctionDeclaration" ||
49
- current.type === "FunctionExpression" ||
50
- current.type === "ArrowFunctionExpression"
51
- ) {
52
- return current;
53
- }
54
- }
55
- return undefined;
56
- };
57
- return {
58
- before() {
59
- if (TEST_FILE.test(context.filename.replaceAll("\\", "/"))) return false;
60
- counts.clear();
61
- reported.clear();
62
- },
63
- CallExpression(node) {
64
- if (!isEffectLadderCombinator(node)) return;
65
- const owner = enclosingFunction(node);
66
- if (owner === undefined) return;
67
- const next = (counts.get(owner) ?? 0) + 1;
68
- counts.set(owner, next);
69
- if (next >= LADDER_THRESHOLD && !reported.has(owner)) {
70
- reported.add(owner);
71
- context.report({ node: owner, messageId: "ladder", data: { count: String(next) } });
72
- }
73
- },
74
- };
75
- },
76
- });
@@ -1,78 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import type { ESTree } from "@oxlint/plugins";
4
-
5
- import { ancestorsOf } from "../../shared/ancestors.ts";
6
-
7
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$|\/test\//u;
8
-
9
- const EQUALITY_OPERATORS = new Set(["==", "===", "!=", "!=="]);
10
-
11
- /**
12
- * Whether the expression is a literal operand (literal or brace-less template).
13
- *
14
- * @param {ESTree.Node} node - The candidate expression node.
15
- * @returns {boolean} True when the node is literal-valued.
16
- */
17
- function isLiteral(node: ESTree.Node): boolean {
18
- if (node.type === "Literal") return true;
19
- return node.type === "TemplateLiteral" && node.expressions.length === 0;
20
- }
21
-
22
- /**
23
- * The compared operand of a literal equality test, rendered to source text.
24
- *
25
- * @param {import("@oxlint/plugins").SourceCode} sourceCode - The rule's source-code accessor.
26
- * @param {ESTree.Expression} test - The conditional's test expression.
27
- * @returns {string | undefined} Source text of the non-literal side, or undefined.
28
- */
29
- function comparedValue(
30
- sourceCode: import("@oxlint/plugins").SourceCode,
31
- test: ESTree.Expression,
32
- ): string | undefined {
33
- if (test.type !== "BinaryExpression") return undefined;
34
- if (!EQUALITY_OPERATORS.has(test.operator)) return undefined;
35
- if (isLiteral(test.left)) return sourceCode.getText(test.right);
36
- if (isLiteral(test.right)) return sourceCode.getText(test.left);
37
- return undefined;
38
- }
39
- /** Chained literal ternaries over one value re-implement `Match` without exhaustiveness checking. */
40
- export const preferEffectMatchRule = defineRule({
41
- meta: {
42
- type: "problem",
43
- docs: {
44
- description:
45
- "Prefer Match from effect for chained literal ternaries over the same value; the compiler then checks exhaustiveness instead of falling through silently.",
46
- },
47
- messages: {
48
- preferMatch:
49
- "This ternary chain re-implements pattern matching over literal comparisons. Use `Match.value` (or `Match.discriminate`) from `effect/Match` so exhaustiveness is checked by the compiler.",
50
- },
51
- },
52
- createOnce(context) {
53
- return {
54
- before() {
55
- if (TEST_FILE.test(context.filename.replaceAll("\\", "/"))) return false;
56
- },
57
- ConditionalExpression(node) {
58
- const parent = ancestorsOf(context.sourceCode, node)[0];
59
- if (parent?.type === "ConditionalExpression") {
60
- return;
61
- }
62
- const compared = comparedValue(context.sourceCode, node.test);
63
- if (compared === undefined) return;
64
- let alternate = node.alternate;
65
- let literalChecks = 1;
66
- while (alternate.type === "ConditionalExpression") {
67
- const alternateCompared = comparedValue(context.sourceCode, alternate.test);
68
- if (alternateCompared !== compared) return;
69
- literalChecks += 1;
70
- alternate = alternate.alternate;
71
- }
72
- if (literalChecks > 1) {
73
- context.report({ node, messageId: "preferMatch" });
74
- }
75
- },
76
- };
77
- },
78
- });
@@ -1,79 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import type { ESTree } from "@oxlint/plugins";
4
-
5
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
6
-
7
- type PredicateFunction = ESTree.ArrowFunctionExpression | ESTree.Function;
8
-
9
- function parameterAnnotation(
10
- parameter: ESTree.ParamPattern,
11
- ): ESTree.TSTypeAnnotation | null | undefined {
12
- if (parameter.type === "TSParameterProperty") {
13
- return parameterAnnotation(parameter.parameter);
14
- }
15
- if (parameter.type === "RestElement") {
16
- return parameter.typeAnnotation ?? parameterAnnotation(parameter.argument);
17
- }
18
- if (parameter.type === "AssignmentPattern") {
19
- return parameter.typeAnnotation ?? parameter.left.typeAnnotation;
20
- }
21
- return parameter.typeAnnotation;
22
- }
23
-
24
- /** Exported predicates should be typed P.Predicate<T> so they compose. */
25
- export const preferEffectPredicateOverBooleanFunctionRule = defineRule({
26
- meta: {
27
- type: "problem",
28
- docs: {
29
- description:
30
- "Prefer P.Predicate<T> over plain (value: T) => boolean for exported predicates so they compose with P.and/or/mapInput, Array.filter, and Option refinement.",
31
- },
32
- messages: {
33
- booleanPredicateReturn:
34
- "Export this predicate as P.Predicate<{{type}}> so it composes with P.and/or/mapInput, Array.filter, and Option refinement.",
35
- },
36
- },
37
- createOnce(context) {
38
-
39
- const checkPredicate = (node: PredicateFunction) => {
40
- if (node.returnType === null || node.returnType === undefined) return;
41
- const returnType = node.returnType.typeAnnotation;
42
- if (returnType.type !== "TSBooleanKeyword") return;
43
- if (node.params.length !== 1) return;
44
- const firstParam = node.params[0];
45
- if (firstParam === undefined) return;
46
- const annotation = parameterAnnotation(firstParam);
47
- if (annotation === null || annotation === undefined) return;
48
- const type = annotation.typeAnnotation;
49
- if (type.type === "TSUnknownKeyword") return;
50
- context.report({
51
- node: returnType,
52
- messageId: "booleanPredicateReturn",
53
- data: { type: context.sourceCode.getText(type) },
54
- });
55
- };
56
-
57
- return {
58
- before() {
59
- if (TEST_FILE.test(context.filename.replaceAll("\\", "/"))) return false;
60
- },
61
- ExportNamedDeclaration(node) {
62
- const declaration = node.declaration;
63
- if (declaration === null) return;
64
- if (declaration.type === "FunctionDeclaration") {
65
- checkPredicate(declaration);
66
- return;
67
- }
68
- if (declaration.type !== "VariableDeclaration") return;
69
- for (const declarator of declaration.declarations) {
70
- const init = declarator.init;
71
- if (init === null || init === undefined || init.type !== "ArrowFunctionExpression") {
72
- continue;
73
- }
74
- checkPredicate(init);
75
- }
76
- },
77
- };
78
- },
79
- });
@@ -1,105 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import type { ESTree } from "@oxlint/plugins";
4
- import { childNodes } from "../../shared/child-nodes.ts";
5
- import { readField } from "../../shared/structural.ts";
6
-
7
- const PREDICATE_NAME = /^is[A-Z]/u;
8
-
9
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
10
-
11
- /** True for a logical chain (>= 2 operands) whose every leaf is a domain-predicate call.
12
- *
13
- * @param {ESTree.Expression} expression - The guard test expression.
14
- * @returns {boolean} True when the chain is composed of domain predicates only.
15
- */
16
- function isPredicateChain(expression: ESTree.Expression): boolean {
17
- if (expression.type !== "LogicalExpression") return false;
18
- return chainLeaf(expression.left) && chainLeaf(expression.right);
19
- }
20
-
21
- /**
22
- * Whether a leaf expression is a domain predicate call, not an Option combinator.
23
- *
24
- * @param {ESTree.Expression} expression - The leaf expression to test.
25
- * @returns {boolean} True when the callee matches the domain predicate naming scheme.
26
- */
27
- function chainLeaf(expression: ESTree.Expression): boolean {
28
- if (expression.type === "LogicalExpression") {
29
- return chainLeaf(expression.left) && chainLeaf(expression.right);
30
- }
31
- if (expression.type === "ParenthesizedExpression") {
32
- return chainLeaf(expression.expression);
33
- }
34
- if (expression.type !== "CallExpression") return false;
35
- const callee = expression.callee;
36
- if (
37
- callee.type === "MemberExpression" &&
38
- callee.object.type === "Identifier" &&
39
- callee.object.name === "Option"
40
- ) {
41
- return false;
42
- }
43
- if (callee.type === "Identifier") return PREDICATE_NAME.test(callee.name);
44
- return (
45
- callee.type === "MemberExpression" &&
46
- callee.property.type === "Identifier" &&
47
- PREDICATE_NAME.test(callee.property.name)
48
- );
49
- }
50
-
51
- /** True when the subtree produces an Option.none()/Option.some(...) result.
52
- *
53
- * @param {ESTree.Node | null | undefined} node - The subtree root to scan.
54
- * @returns {boolean} True when an Option constructor call appears in the subtree.
55
- */
56
- function containsOptionResult(node: ESTree.Node | null | undefined): boolean {
57
- if (node === null || node === undefined) return false;
58
- if (
59
- node.type === "CallExpression" &&
60
- node.callee.type === "MemberExpression" &&
61
- node.callee.object.type === "Identifier" &&
62
- node.callee.object.name === "Option" &&
63
- node.callee.property.type === "Identifier" &&
64
- (node.callee.property.name === "none" || node.callee.property.name === "some")
65
- ) {
66
- return true;
67
- }
68
- return childNodes(node).some(containsOptionResult);
69
- }
70
-
71
- /** Inline chains of domain predicates guarding Options should be named Predicates. */
72
- export const preferNamedGuardPredicateRule = defineRule({
73
- meta: {
74
- type: "problem",
75
- docs: {
76
- description:
77
- "Require guards built from chained domain predicates to be extracted into a named P.Predicate and lifted through Option.liftPredicate so the guard composes and carries a name.",
78
- },
79
- messages: {
80
- namedGuardPredicate:
81
- "This guard anonymously chains domain predicates. Extract a named `P.Predicate` (composed via P.and/P.or/P.not) and lift the value with `Option.liftPredicate` so the guard is reusable, testable and self-describing.",
82
- },
83
- },
84
- createOnce(context) {
85
- const checkGuard = (
86
- test: ESTree.Expression,
87
- branches: Array<ESTree.Node | null | undefined>,
88
- ): void => {
89
- if (!isPredicateChain(test)) return;
90
- if (!branches.some((branch) => containsOptionResult(branch))) return;
91
- context.report({ node: test, messageId: "namedGuardPredicate" });
92
- };
93
- return {
94
- before() {
95
- if (TEST_FILE.test(context.filename.replaceAll("\\", "/"))) return false;
96
- },
97
- ConditionalExpression(node) {
98
- checkGuard(node.test, [node.consequent, node.alternate]);
99
- },
100
- IfStatement(node) {
101
- checkGuard(node.test, [node.consequent, node.alternate]);
102
- },
103
- };
104
- },
105
- });
@@ -1,95 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import type { ESTree } from "@oxlint/plugins";
4
- import { childNodes } from "../../shared/child-nodes.ts";
5
- import { readField } from "../../shared/structural.ts";
6
-
7
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
8
-
9
- type FunctionLike = ESTree.ArrowFunctionExpression | ESTree.Function;
10
-
11
- /**
12
- * Count Option.none() returns in this function's own body. Nested scopes belong to
13
- * themselves, and loop bodies hold algorithmic exits rather than guard scatters.
14
- *
15
- * @param {ESTree.Node} body - The function body to walk.
16
- * @returns {number} Number of direct `Option.none()` return exits.
17
- */
18
- function countDirectNoneReturns(body: ESTree.Node): number {
19
- let count = 0;
20
- const visit = (node: ESTree.Node): void => {
21
- if (
22
- node.type === "ArrowFunctionExpression" ||
23
- node.type === "FunctionExpression" ||
24
- node.type === "FunctionDeclaration"
25
- )
26
- return;
27
- if (
28
- node.type === "ForStatement" ||
29
- node.type === "ForInStatement" ||
30
- node.type === "ForOfStatement" ||
31
- node.type === "WhileStatement" ||
32
- node.type === "DoWhileStatement"
33
- ) {
34
- return;
35
- }
36
- if (node.type !== "ReturnStatement") return void 0;
37
- const argument = node.argument;
38
- if (
39
- argument?.type === "CallExpression" &&
40
- argument.callee.type === "MemberExpression" &&
41
- argument.callee.object.type === "Identifier" &&
42
- argument.callee.object.name === "Option" &&
43
- argument.callee.property.type === "Identifier" &&
44
- argument.callee.property.name === "none"
45
- )
46
- count += 1;
47
- for (const child of childNodes(node)) visit(child);
48
- };
49
- visit(body);
50
- return count;
51
- }
52
-
53
- /** Guard-gauntlets over Option should compose into liftPredicate/filter pipelines. */
54
- export const preferOptionPipelineRule = defineRule({
55
- meta: {
56
- type: "problem",
57
- docs: {
58
- description:
59
- "Require Option-returning functions to reject through composed pipelines (named Predicates lifted via Option.liftPredicate / narrowed via Option.filter) instead of scattering multiple `return Option.none()` guard exits through the body.",
60
- },
61
- messages: {
62
- preferPipeline:
63
- "This Option-returning function rejects through {{count}} scattered `Option.none()` guards. Extract named Predicates and compose them via pipe + Option.liftPredicate / Option.filter so the happy path reads as one pipeline.",
64
- },
65
- },
66
- createOnce(context) {
67
- const check = (node: FunctionLike): void => {
68
- const returnType = node.returnType?.typeAnnotation;
69
- if (returnType === null || returnType === undefined) return;
70
- if (returnType.type !== "TSTypeReference") return;
71
- const typeName = returnType.typeName;
72
- const declaresOption =
73
- typeName.type === "Identifier"
74
- ? typeName.name === "Option"
75
- : typeName.type === "TSQualifiedName" &&
76
- typeName.left.type === "Identifier" &&
77
- typeName.left.name === "Option" &&
78
- typeName.right.type === "Identifier" &&
79
- typeName.right.name === "Option";
80
- if (!declaresOption) return;
81
- if (node.body === null || node.body === undefined) return;
82
- const count = countDirectNoneReturns(node.body);
83
- if (count < 2) return;
84
- context.report({ node, messageId: "preferPipeline", data: { count: String(count) } });
85
- };
86
- return {
87
- before() {
88
- if (TEST_FILE.test(context.filename.replaceAll("\\", "/"))) return false;
89
- },
90
- ArrowFunctionExpression: check,
91
- FunctionExpression: check,
92
- FunctionDeclaration: check,
93
- };
94
- },
95
- });
@@ -1,152 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import type { ESTree } from "@oxlint/plugins";
4
-
5
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
6
-
7
- const ORDERING_OPERATORS = new Set(["<", ">", "<=", ">=", "===", "=="]);
8
-
9
- function isZeroLiteral(
10
- expression: ESTree.Expression | ESTree.PrivateIdentifier | null | undefined,
11
- ): boolean {
12
- return (
13
- expression !== null &&
14
- expression !== undefined &&
15
- expression.type === "Literal" &&
16
- expression.value === 0
17
- );
18
- }
19
-
20
- /** Source text of the operand compared against zero, or null when this is not one.
21
- *
22
- * @param {{ test: ESTree.Expression; sourceText: string }} payload - The compared test and its source text.
23
- * @returns {string | null} Source text of the non-zero side, or null.
24
- */
25
- function orderingZeroSubject(payload: {
26
- test: ESTree.Expression;
27
- sourceText: string;
28
- }): string | null {
29
- const { test, sourceText } = payload;
30
- let binary = test;
31
- while (binary.type === "ParenthesizedExpression") {
32
- binary = binary.expression;
33
- }
34
- if (binary.type !== "BinaryExpression" || !ORDERING_OPERATORS.has(binary.operator)) {
35
- return null;
36
- }
37
- const slice = (expression: ESTree.Expression | ESTree.PrivateIdentifier): string =>
38
- sourceText.slice(expression.range?.[0] ?? 0, expression.range?.[1] ?? 0).trim();
39
- if (isZeroLiteral(binary.right)) return slice(binary.left);
40
- if (isZeroLiteral(binary.left)) return slice(binary.right);
41
- return null;
42
- }
43
-
44
- function isSentinelValue(expression: ESTree.Node | null | undefined): boolean {
45
- if (expression === null || expression === undefined) return false;
46
- if (expression.type === "ParenthesizedExpression") {
47
- return isSentinelValue(expression.expression);
48
- }
49
- if (expression.type === "UnaryExpression") {
50
- return (
51
- expression.operator === "-" &&
52
- expression.argument.type === "Literal" &&
53
- expression.argument.value === 1
54
- );
55
- }
56
- return expression.type === "Literal" && (expression.value === 0 || expression.value === 1);
57
- }
58
-
59
- function lastReturnedValue(block: ESTree.BlockStatement): ESTree.Node | null | undefined {
60
- const statement = block.body[block.body.length - 1];
61
- return statement !== undefined && statement.type === "ReturnStatement"
62
- ? statement.argument
63
- : undefined;
64
- }
65
-
66
- /** Hand-mapping an ordering comparison to domain values duplicates Ordering.match. */
67
- export const preferOrderingMatchRule = defineRule({
68
- meta: {
69
- type: "problem",
70
- docs: {
71
- description:
72
- "Require ladders of conditional branches re-testing the same ordering comparison against zero to be expressed as one Ordering.match table.",
73
- },
74
- messages: {
75
- preferOrderingMatch:
76
- "This ladder re-tests `{{subject}}` against zero {{links}} times to pick domain values. Replace it with a single Ordering.match({ onLessThan, onEqual, onGreaterThan }) over the comparison result so the direction mapping lives in one exhaustive table.",
77
- },
78
- },
79
- createOnce(context) {
80
- const checkChain = (
81
- tests: Array<{ subject: string | null; node: ESTree.Expression }>,
82
- leaves: Array<ESTree.Node | null | undefined>,
83
- ): void => {
84
- if (tests.length < 2) return;
85
- if (tests.some((test) => test.subject === null)) return;
86
- const subject = tests[0]!.subject!;
87
- if (tests.some((test) => test.subject !== subject)) return;
88
- if (leaves.every((leaf) => isSentinelValue(leaf))) return;
89
- context.report({
90
- node: tests[0]!.node,
91
- messageId: "preferOrderingMatch",
92
- data: { subject, links: String(tests.length) },
93
- });
94
- };
95
- return {
96
- before() {
97
- if (TEST_FILE.test(context.filename.replaceAll("\\", "/"))) return false;
98
- },
99
- ConditionalExpression(node) {
100
- const tests: Array<{ subject: string | null; node: ESTree.Expression }> = [];
101
- const leaves: Array<ESTree.Node | null | undefined> = [];
102
- let current: ESTree.ConditionalExpression | null = node;
103
- while (current !== null && current.type === "ConditionalExpression") {
104
- tests.push({
105
- subject: orderingZeroSubject({ test: current.test, sourceText: context.sourceCode.text }),
106
- node: current.test,
107
- });
108
- leaves.push(current.consequent);
109
- const alternate: ESTree.Expression | null = current.alternate;
110
- if (alternate.type === "ConditionalExpression") {
111
- current = alternate;
112
- } else {
113
- leaves.push(alternate);
114
- current = null;
115
- }
116
- }
117
- checkChain(tests, leaves);
118
- },
119
- IfStatement(node) {
120
- const tests: Array<{ subject: string | null; node: ESTree.Expression }> = [];
121
- const leaves: Array<ESTree.Node | null | undefined> = [];
122
- let current: ESTree.IfStatement | null = node;
123
- while (current !== null && current.type === "IfStatement") {
124
- tests.push({
125
- subject: orderingZeroSubject({ test: current.test, sourceText: context.sourceCode.text }),
126
- node: current.test,
127
- });
128
- const consequent = current.consequent;
129
- leaves.push(
130
- consequent.type === "BlockStatement"
131
- ? lastReturnedValue(consequent)
132
- : consequent,
133
- );
134
- const alternate: ESTree.Statement | null = current.alternate;
135
- if (alternate === null) {
136
- current = null;
137
- } else if (alternate.type === "IfStatement") {
138
- current = alternate;
139
- } else {
140
- leaves.push(
141
- alternate.type === "BlockStatement"
142
- ? lastReturnedValue(alternate)
143
- : alternate,
144
- );
145
- current = null;
146
- }
147
- }
148
- checkChain(tests, leaves);
149
- },
150
- };
151
- },
152
- });
@@ -1,68 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import type { ESTree } from "@oxlint/plugins";
4
- import { isRecordObject, isString } from "../../shared/structural.ts";
5
-
6
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
7
-
8
- /** Whether a type-literal member declares a literal-typed `_tag` property.
9
- *
10
- * @param {ESTree.Node} member - A member of a type literal.
11
- * @returns {boolean} True when the member is `_tag` with a string literal type.
12
- */
13
- function hasLiteralTagProperty(member: ESTree.Node): boolean {
14
- if (member.type !== "TSPropertySignature") return false;
15
- const key = member.key;
16
- const isTagKey =
17
- (key.type === "Identifier" && key.name === "_tag") ||
18
- (key.type === "Literal" && key.value === "_tag");
19
- if (!isTagKey) return false;
20
- const annotation = member.typeAnnotation?.typeAnnotation;
21
- if (annotation === undefined || annotation === null || annotation.type !== "TSLiteralType") {
22
- return false;
23
- }
24
- return annotation.literal.type === "Literal" && isString(annotation.literal.value);
25
- }
26
-
27
- /** Whether every union constituent is a type literal carrying a `_tag` property.
28
- *
29
- * @param {ESTree.TSType} member - One constituent of a union annotation.
30
- * @returns {boolean} True when the member is a type literal with a `_tag`.
31
- */
32
- function isTaggedLiteralMember(member: ESTree.TSType): boolean {
33
- if (member.type !== "TSTypeLiteral") return false;
34
- return member.members.some(hasLiteralTagProperty);
35
- }
36
-
37
- /** Hand-rolled _tag unions duplicate what Data.TaggedEnum gives for free. */
38
- export const preferTaggedEnumRule = defineRule({
39
- meta: {
40
- type: "problem",
41
- docs: {
42
- description:
43
- "Require internal tagged unions to be declared with Data.TaggedEnum (constructors, $is guards and exhaustive $match) instead of hand-rolled _tag object-literal unions with manual type guards.",
44
- },
45
- messages: {
46
- preferTaggedEnum:
47
- "This union hand-rolls `_tag` discrimination. Declare it as `type {{name}} = Data.TaggedEnum<{...}>` and derive constructors, `$is` guards and exhaustive `$match` via `Data.taggedEnum<{{name}}>()`, matching the rational.ts idiom.",
48
- },
49
- },
50
- createOnce(context) {
51
- return {
52
- before() {
53
- if (TEST_FILE.test(context.filename.replaceAll("\\", "/"))) return false;
54
- },
55
- TSTypeAliasDeclaration(node) {
56
- const annotation = node.typeAnnotation;
57
- if (annotation.type !== "TSUnionType") return;
58
- if (annotation.types.length < 2) return;
59
- if (!annotation.types.every((member) => isTaggedLiteralMember(member))) return;
60
- context.report({
61
- node: node.id,
62
- messageId: "preferTaggedEnum",
63
- data: { name: node.id.name },
64
- });
65
- },
66
- };
67
- },
68
- });