@autotelic/plumb 0.5.2 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (282) hide show
  1. package/README.md +81 -8
  2. package/dist/configs/recommended-rules.d.ts +36 -0
  3. package/dist/configs/recommended-rules.js +57 -0
  4. package/dist/effect/index.js +4 -0
  5. package/dist/effect/rules/guarded-op-must-return-effect.js +1 -1
  6. package/dist/effect/rules/no-cascading-layer-provide.js +1 -1
  7. package/dist/effect/rules/no-decode-unknown-option.js +1 -1
  8. package/dist/effect/rules/no-direct-browser-storage.js +3 -3
  9. package/dist/effect/rules/no-direct-fetch.js +1 -1
  10. package/dist/effect/rules/no-manual-field-guards.js +1 -1
  11. package/dist/effect/rules/no-nested-layer-provide.js +1 -1
  12. package/dist/effect/rules/no-nullish-default-on-partial-input.d.ts +13 -0
  13. package/dist/effect/rules/no-nullish-default-on-partial-input.js +109 -0
  14. package/dist/effect/rules/no-raw-error-forwarding.d.ts +16 -0
  15. package/dist/effect/rules/no-raw-error-forwarding.js +108 -0
  16. package/dist/effect/rules/no-silent-error-swallow.js +1 -1
  17. package/dist/effect/rules/no-static-effect-service-forwarders.js +5 -4
  18. package/dist/effect/rules/no-try-catch.js +1 -1
  19. package/dist/effect/rules/no-unguarded-json-parse.js +1 -1
  20. package/dist/effect/rules/option-core-needs-effect-public.js +1 -1
  21. package/dist/effect/rules/prefer-die-for-precondition-defects.js +1 -1
  22. package/dist/effect/rules/prefer-effect-gen-for-guard-ladders.js +1 -1
  23. package/dist/effect/rules/prefer-effect-match.js +2 -2
  24. package/dist/effect/rules/prefer-effect-predicate-over-boolean-function.js +1 -1
  25. package/dist/effect/rules/prefer-named-guard-predicate.js +1 -1
  26. package/dist/effect/rules/prefer-option-pipeline.js +13 -12
  27. package/dist/effect/rules/prefer-ordering-match.js +1 -1
  28. package/dist/effect/rules/prefer-tagged-enum.js +1 -1
  29. package/dist/effect/rules/require-schema-type-derivation.d.ts +8 -2
  30. package/dist/effect/rules/require-schema-type-derivation.js +14 -4
  31. package/dist/index.js +10 -0
  32. package/dist/react/rules/require-dot-notation-exports.js +1 -1
  33. package/dist/react/rules/require-guarded-context-hook.js +1 -1
  34. package/dist/react/rules/require-tripartite-context.js +1 -1
  35. package/dist/react/rules/use-encapsulation.js +1 -1
  36. package/dist/rules/no-adapter-in-values.d.ts +12 -0
  37. package/dist/rules/no-adapter-in-values.js +110 -0
  38. package/dist/rules/no-builtin-throws.js +1 -1
  39. package/dist/rules/no-duplicated-literal-union.d.ts +7 -0
  40. package/dist/rules/no-duplicated-literal-union.js +5 -1
  41. package/dist/rules/no-generic-export-names.js +1 -1
  42. package/dist/rules/no-multiple-function-params.js +26 -12
  43. package/dist/rules/no-mutable-environment-capture.js +2 -2
  44. package/dist/rules/no-nondeterministic-core.js +1 -1
  45. package/dist/rules/no-nullable-value-field.d.ts +16 -0
  46. package/dist/rules/no-nullable-value-field.js +117 -0
  47. package/dist/rules/no-optional-function-parameters.js +1 -1
  48. package/dist/rules/no-row-coercion.d.ts +13 -0
  49. package/dist/rules/no-row-coercion.js +135 -0
  50. package/dist/rules/no-single-use-private-functions.js +1 -1
  51. package/dist/rules/no-sql-string-interpolation.d.ts +7 -0
  52. package/dist/rules/no-sql-string-interpolation.js +62 -0
  53. package/dist/rules/no-stray-inline-comments.js +1 -1
  54. package/dist/rules/no-string-instant.d.ts +15 -0
  55. package/dist/rules/no-string-instant.js +108 -0
  56. package/dist/rules/no-swappable-primitive-params.js +1 -1
  57. package/dist/rules/no-tag-ladder-assertions.js +1 -1
  58. package/dist/rules/no-vague-test-filenames.js +1 -1
  59. package/dist/rules/prefer-property-tests.d.ts +5 -0
  60. package/dist/rules/prefer-property-tests.js +7 -0
  61. package/dist/rules/require-jsdoc-on-exported.js +1 -1
  62. package/dist/shared/ancestors.d.ts +1 -1
  63. package/dist/shared/ancestors.js +1 -1
  64. package/dist/shared/values-path.d.ts +12 -0
  65. package/dist/shared/values-path.js +56 -0
  66. package/dist/src/configs/recommended-rules.d.ts +20 -0
  67. package/dist/src/configs/recommended-rules.js +22 -0
  68. package/dist/src/effect/index.d.ts +3 -0
  69. package/dist/src/effect/index.js +60 -0
  70. package/dist/src/effect/rules/guarded-op-must-return-effect.d.ts +6 -0
  71. package/dist/src/effect/rules/guarded-op-must-return-effect.js +235 -0
  72. package/dist/src/effect/rules/guarded-op-must-return-option.d.ts +2 -0
  73. package/dist/src/effect/rules/guarded-op-must-return-option.js +88 -0
  74. package/dist/src/effect/rules/no-cascading-layer-provide.d.ts +6 -0
  75. package/dist/src/effect/rules/no-cascading-layer-provide.js +73 -0
  76. package/dist/src/effect/rules/no-decode-unknown-option.d.ts +7 -0
  77. package/dist/src/effect/rules/no-decode-unknown-option.js +34 -0
  78. package/dist/src/effect/rules/no-direct-browser-storage.d.ts +2 -0
  79. package/dist/src/effect/rules/no-direct-browser-storage.js +88 -0
  80. package/dist/src/effect/rules/no-direct-fetch.d.ts +2 -0
  81. package/dist/src/effect/rules/no-direct-fetch.js +37 -0
  82. package/dist/src/effect/rules/no-manual-field-guards.d.ts +6 -0
  83. package/dist/src/effect/rules/no-manual-field-guards.js +129 -0
  84. package/dist/src/effect/rules/no-nested-layer-provide.d.ts +2 -0
  85. package/dist/src/effect/rules/no-nested-layer-provide.js +50 -0
  86. package/dist/src/effect/rules/no-nullish-default-on-partial-input.d.ts +13 -0
  87. package/dist/src/effect/rules/no-nullish-default-on-partial-input.js +109 -0
  88. package/dist/src/effect/rules/no-raw-error-forwarding.d.ts +12 -0
  89. package/dist/src/effect/rules/no-raw-error-forwarding.js +103 -0
  90. package/dist/src/effect/rules/no-schema-class-modeling.d.ts +2 -0
  91. package/dist/src/effect/rules/no-schema-class-modeling.js +52 -0
  92. package/dist/src/effect/rules/no-service-constructor-imports.d.ts +2 -0
  93. package/dist/src/effect/rules/no-service-constructor-imports.js +42 -0
  94. package/dist/src/effect/rules/no-silent-error-swallow.d.ts +2 -0
  95. package/dist/src/effect/rules/no-silent-error-swallow.js +95 -0
  96. package/dist/src/effect/rules/no-static-effect-service-forwarders.d.ts +6 -0
  97. package/dist/src/effect/rules/no-static-effect-service-forwarders.js +222 -0
  98. package/dist/src/effect/rules/no-try-catch.d.ts +2 -0
  99. package/dist/src/effect/rules/no-try-catch.js +30 -0
  100. package/dist/src/effect/rules/no-unguarded-json-parse.d.ts +5 -0
  101. package/dist/src/effect/rules/no-unguarded-json-parse.js +200 -0
  102. package/dist/src/effect/rules/option-core-needs-effect-public.d.ts +5 -0
  103. package/dist/src/effect/rules/option-core-needs-effect-public.js +76 -0
  104. package/dist/src/effect/rules/prefer-die-for-precondition-defects.d.ts +5 -0
  105. package/dist/src/effect/rules/prefer-die-for-precondition-defects.js +112 -0
  106. package/dist/src/effect/rules/prefer-effect-gen-for-guard-ladders.d.ts +5 -0
  107. package/dist/src/effect/rules/prefer-effect-gen-for-guard-ladders.js +72 -0
  108. package/dist/src/effect/rules/prefer-effect-match.d.ts +2 -0
  109. package/dist/src/effect/rules/prefer-effect-match.js +74 -0
  110. package/dist/src/effect/rules/prefer-effect-predicate-over-boolean-function.d.ts +2 -0
  111. package/dist/src/effect/rules/prefer-effect-predicate-over-boolean-function.js +75 -0
  112. package/dist/src/effect/rules/prefer-named-guard-predicate.d.ts +2 -0
  113. package/dist/src/effect/rules/prefer-named-guard-predicate.js +93 -0
  114. package/dist/src/effect/rules/prefer-option-pipeline.d.ts +2 -0
  115. package/dist/src/effect/rules/prefer-option-pipeline.js +87 -0
  116. package/dist/src/effect/rules/prefer-ordering-match.d.ts +2 -0
  117. package/dist/src/effect/rules/prefer-ordering-match.js +135 -0
  118. package/dist/src/effect/rules/prefer-tagged-enum.d.ts +2 -0
  119. package/dist/src/effect/rules/prefer-tagged-enum.js +66 -0
  120. package/dist/src/effect/rules/require-schema-type-derivation.d.ts +7 -0
  121. package/dist/src/effect/rules/require-schema-type-derivation.js +80 -0
  122. package/dist/src/index.d.ts +3 -0
  123. package/dist/src/index.js +106 -0
  124. package/dist/src/meta/index.d.ts +7 -0
  125. package/dist/src/meta/index.js +22 -0
  126. package/dist/src/meta/rules/no-disable-directives.d.ts +6 -0
  127. package/dist/src/meta/rules/no-disable-directives.js +35 -0
  128. package/dist/src/meta/rules/no-manual-ancestor-walks.d.ts +2 -0
  129. package/dist/src/meta/rules/no-manual-ancestor-walks.js +26 -0
  130. package/dist/src/meta/rules/prefer-before-file-scope.d.ts +2 -0
  131. package/dist/src/meta/rules/prefer-before-file-scope.js +57 -0
  132. package/dist/src/meta/rules/require-create-once.d.ts +2 -0
  133. package/dist/src/meta/rules/require-create-once.js +51 -0
  134. package/dist/src/meta/rules/require-rule-tester.d.ts +2 -0
  135. package/dist/src/meta/rules/require-rule-tester.js +50 -0
  136. package/dist/src/react/index.d.ts +3 -0
  137. package/dist/src/react/index.js +16 -0
  138. package/dist/src/react/role.d.ts +23 -0
  139. package/dist/src/react/role.js +30 -0
  140. package/dist/src/react/rules/require-dot-notation-exports.d.ts +27 -0
  141. package/dist/src/react/rules/require-dot-notation-exports.js +144 -0
  142. package/dist/src/react/rules/require-guarded-context-hook.d.ts +19 -0
  143. package/dist/src/react/rules/require-guarded-context-hook.js +167 -0
  144. package/dist/src/react/rules/require-tripartite-context.d.ts +17 -0
  145. package/dist/src/react/rules/require-tripartite-context.js +160 -0
  146. package/dist/src/react/rules/use-encapsulation.d.ts +22 -0
  147. package/dist/src/react/rules/use-encapsulation.js +97 -0
  148. package/dist/src/rules/no-anonymous-wide-tuples.d.ts +7 -0
  149. package/dist/src/rules/no-anonymous-wide-tuples.js +34 -0
  150. package/dist/src/rules/no-barrel-export-star.d.ts +2 -0
  151. package/dist/src/rules/no-barrel-export-star.js +26 -0
  152. package/dist/src/rules/no-boolean-field-signals.d.ts +2 -0
  153. package/dist/src/rules/no-boolean-field-signals.js +279 -0
  154. package/dist/src/rules/no-builtin-throws.d.ts +6 -0
  155. package/dist/src/rules/no-builtin-throws.js +74 -0
  156. package/dist/src/rules/no-chained-type-assertions.d.ts +2 -0
  157. package/dist/src/rules/no-chained-type-assertions.js +54 -0
  158. package/dist/src/rules/no-conditional-empty-object-spread.d.ts +2 -0
  159. package/dist/src/rules/no-conditional-empty-object-spread.js +36 -0
  160. package/dist/src/rules/no-duplicated-literal-union.d.ts +6 -0
  161. package/dist/src/rules/no-duplicated-literal-union.js +66 -0
  162. package/dist/src/rules/no-exported-mutable-state.d.ts +7 -0
  163. package/dist/src/rules/no-exported-mutable-state.js +104 -0
  164. package/dist/src/rules/no-generic-export-names.d.ts +2 -0
  165. package/dist/src/rules/no-generic-export-names.js +141 -0
  166. package/dist/src/rules/no-impossible-branch-throw.d.ts +2 -0
  167. package/dist/src/rules/no-impossible-branch-throw.js +51 -0
  168. package/dist/src/rules/no-known-value-widening.d.ts +2 -0
  169. package/dist/src/rules/no-known-value-widening.js +176 -0
  170. package/dist/src/rules/no-module-mocking.d.ts +2 -0
  171. package/dist/src/rules/no-module-mocking.js +90 -0
  172. package/dist/src/rules/no-multiple-function-params.d.ts +2 -0
  173. package/dist/src/rules/no-multiple-function-params.js +155 -0
  174. package/dist/src/rules/no-mutable-environment-capture.d.ts +7 -0
  175. package/dist/src/rules/no-mutable-environment-capture.js +134 -0
  176. package/dist/src/rules/no-nondeterministic-core.d.ts +6 -0
  177. package/dist/src/rules/no-nondeterministic-core.js +63 -0
  178. package/dist/src/rules/no-object-parameters.d.ts +2 -0
  179. package/dist/src/rules/no-object-parameters.js +95 -0
  180. package/dist/src/rules/no-optional-function-parameters.d.ts +7 -0
  181. package/dist/src/rules/no-optional-function-parameters.js +44 -0
  182. package/dist/src/rules/no-product-of-state-booleans.d.ts +2 -0
  183. package/dist/src/rules/no-product-of-state-booleans.js +79 -0
  184. package/dist/src/rules/no-redundant-derived-field.d.ts +6 -0
  185. package/dist/src/rules/no-redundant-derived-field.js +194 -0
  186. package/dist/src/rules/no-reflect-apply.d.ts +2 -0
  187. package/dist/src/rules/no-reflect-apply.js +29 -0
  188. package/dist/src/rules/no-reflect-get.d.ts +2 -0
  189. package/dist/src/rules/no-reflect-get.js +29 -0
  190. package/dist/src/rules/no-reinterpret-cast.d.ts +2 -0
  191. package/dist/src/rules/no-reinterpret-cast.js +68 -0
  192. package/dist/src/rules/no-runtime-typeof.d.ts +2 -0
  193. package/dist/src/rules/no-runtime-typeof.js +54 -0
  194. package/dist/src/rules/no-sentinel-comparison-union.d.ts +2 -0
  195. package/dist/src/rules/no-sentinel-comparison-union.js +139 -0
  196. package/dist/src/rules/no-shape-in-symbol-names.d.ts +2 -0
  197. package/dist/src/rules/no-shape-in-symbol-names.js +39 -0
  198. package/dist/src/rules/no-single-use-private-functions.d.ts +17 -0
  199. package/dist/src/rules/no-single-use-private-functions.js +419 -0
  200. package/dist/src/rules/no-sql-string-interpolation.d.ts +7 -0
  201. package/dist/src/rules/no-sql-string-interpolation.js +62 -0
  202. package/dist/src/rules/no-stacked-jsdoc-blocks.d.ts +2 -0
  203. package/dist/src/rules/no-stacked-jsdoc-blocks.js +50 -0
  204. package/dist/src/rules/no-stray-inline-comments.d.ts +2 -0
  205. package/dist/src/rules/no-stray-inline-comments.js +74 -0
  206. package/dist/src/rules/no-swappable-primitive-params.d.ts +2 -0
  207. package/dist/src/rules/no-swappable-primitive-params.js +96 -0
  208. package/dist/src/rules/no-tag-ladder-assertions.d.ts +6 -0
  209. package/dist/src/rules/no-tag-ladder-assertions.js +63 -0
  210. package/dist/src/rules/no-transposed-field-reads.d.ts +8 -0
  211. package/dist/src/rules/no-transposed-field-reads.js +101 -0
  212. package/dist/src/rules/no-unit-return-validators.d.ts +2 -0
  213. package/dist/src/rules/no-unit-return-validators.js +64 -0
  214. package/dist/src/rules/no-unknown-parameters.d.ts +2 -0
  215. package/dist/src/rules/no-unknown-parameters.js +82 -0
  216. package/dist/src/rules/no-unknown-returns.d.ts +2 -0
  217. package/dist/src/rules/no-unknown-returns.js +86 -0
  218. package/dist/src/rules/no-unknown-type-aliases.d.ts +2 -0
  219. package/dist/src/rules/no-unknown-type-aliases.js +64 -0
  220. package/dist/src/rules/no-unsafe-dictionary-type.d.ts +2 -0
  221. package/dist/src/rules/no-unsafe-dictionary-type.js +116 -0
  222. package/dist/src/rules/no-vague-test-filenames.d.ts +2 -0
  223. package/dist/src/rules/no-vague-test-filenames.js +61 -0
  224. package/dist/src/rules/no-widen-then-assert.d.ts +2 -0
  225. package/dist/src/rules/no-widen-then-assert.js +268 -0
  226. package/dist/src/rules/prefer-payload-brand.d.ts +2 -0
  227. package/dist/src/rules/prefer-payload-brand.js +57 -0
  228. package/dist/src/rules/prefer-property-tests.d.ts +5 -0
  229. package/dist/src/rules/prefer-property-tests.js +39 -0
  230. package/dist/src/rules/require-canonical-stringify-for-identity.d.ts +8 -0
  231. package/dist/src/rules/require-canonical-stringify-for-identity.js +72 -0
  232. package/dist/src/rules/require-deprecated-tag-for-legacy-comments.d.ts +2 -0
  233. package/dist/src/rules/require-deprecated-tag-for-legacy-comments.js +34 -0
  234. package/dist/src/rules/require-exhaustive-tag-switch.d.ts +7 -0
  235. package/dist/src/rules/require-exhaustive-tag-switch.js +34 -0
  236. package/dist/src/rules/require-fc-block-predicate.d.ts +2 -0
  237. package/dist/src/rules/require-fc-block-predicate.js +37 -0
  238. package/dist/src/rules/require-jsdoc-on-exported.d.ts +2 -0
  239. package/dist/src/rules/require-jsdoc-on-exported.js +66 -0
  240. package/dist/src/rules/require-published-order.d.ts +2 -0
  241. package/dist/src/rules/require-published-order.js +102 -0
  242. package/dist/src/rules/require-safety-comment-for-type-assertion.d.ts +2 -0
  243. package/dist/src/rules/require-safety-comment-for-type-assertion.js +53 -0
  244. package/dist/src/rules/require-sort-comparator.d.ts +7 -0
  245. package/dist/src/rules/require-sort-comparator.js +34 -0
  246. package/dist/src/rules/test-utils.d.ts +35 -0
  247. package/dist/src/rules/test-utils.js +53 -0
  248. package/dist/src/shared/ancestors.d.ts +18 -0
  249. package/dist/src/shared/ancestors.js +19 -0
  250. package/dist/src/shared/child-nodes.d.ts +12 -0
  251. package/dist/src/shared/child-nodes.js +26 -0
  252. package/dist/src/shared/dictionary-types.d.ts +55 -0
  253. package/dist/src/shared/dictionary-types.js +413 -0
  254. package/dist/src/shared/is-node.d.ts +9 -0
  255. package/dist/src/shared/is-node.js +10 -0
  256. package/dist/src/shared/lexical-type-parameters.d.ts +12 -0
  257. package/dist/src/shared/lexical-type-parameters.js +50 -0
  258. package/dist/src/shared/reflect-method.d.ts +15 -0
  259. package/dist/src/shared/reflect-method.js +32 -0
  260. package/dist/src/shared/rule-options.d.ts +18 -0
  261. package/dist/src/shared/rule-options.js +12 -0
  262. package/dist/src/shared/structural.d.ts +54 -0
  263. package/dist/src/shared/structural.js +40 -0
  264. package/dist/src/testing/index.d.ts +2 -0
  265. package/dist/src/testing/index.js +1 -0
  266. package/dist/src/testing/testable-rule.d.ts +39 -0
  267. package/dist/src/testing/testable-rule.js +84 -0
  268. package/dist/src/ui/index.d.ts +12 -0
  269. package/dist/src/ui/index.js +18 -0
  270. package/dist/src/ui/manifest.d.ts +34 -0
  271. package/dist/src/ui/manifest.js +75 -0
  272. package/dist/src/ui/rules/no-deprecated-parts.d.ts +3 -0
  273. package/dist/src/ui/rules/no-deprecated-parts.js +131 -0
  274. package/dist/testing/testable-rule.d.ts +6 -5
  275. package/dist/testing/testable-rule.js +20 -6
  276. package/dist/ui/index.d.ts +12 -0
  277. package/dist/ui/index.js +18 -0
  278. package/dist/ui/manifest.d.ts +49 -0
  279. package/dist/ui/manifest.js +90 -0
  280. package/dist/ui/rules/no-deprecated-parts.d.ts +3 -0
  281. package/dist/ui/rules/no-deprecated-parts.js +172 -0
  282. package/package.json +20 -11
@@ -0,0 +1,95 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$|\/test\//u;
3
+ const CATCH_METHODS = new Set([
4
+ "catch",
5
+ "catchTag",
6
+ "catchTags",
7
+ "catchReason",
8
+ "catchReasons",
9
+ ]);
10
+ const VOID_OR_UNIT_METHODS = new Set(["void", "unit"]);
11
+ /**
12
+ * Whether the expression is the bare `Effect.void` / `Effect.unit` member.
13
+ *
14
+ * @param {ESTree.Node | null | undefined} node - The candidate member expression.
15
+ * @returns {boolean} True when the expression reads Effect.void or Effect.unit.
16
+ */
17
+ function isEffectVoidOrUnit(node) {
18
+ if (node === null || node === undefined || node.type !== "MemberExpression")
19
+ return false;
20
+ if (node.object.type !== "Identifier" || node.object.name !== "Effect")
21
+ return false;
22
+ return node.property.type === "Identifier" && VOID_OR_UNIT_METHODS.has(node.property.name);
23
+ }
24
+ /**
25
+ * A recovery callback that reduces every failure to Effect.void/unit swallows it silently.
26
+ *
27
+ * @param {ESTree.Node} handler - The catch handler argument to inspect.
28
+ * @returns {boolean} True when the handler can only produce Effect.void/unit.
29
+ */
30
+ function returnsOnlyVoid(handler) {
31
+ if (handler.type !== "ArrowFunctionExpression" &&
32
+ handler.type !== "FunctionExpression") {
33
+ return false;
34
+ }
35
+ const body = handler.body;
36
+ if (body === null || body === undefined)
37
+ return false;
38
+ if (isEffectVoidOrUnit(body))
39
+ return true;
40
+ if (body.type !== "BlockStatement")
41
+ return false;
42
+ if (body.body.length !== 1)
43
+ return false;
44
+ const statement = body.body[0];
45
+ if (statement.type !== "ReturnStatement")
46
+ return false;
47
+ return isEffectVoidOrUnit(statement.argument);
48
+ }
49
+ /** Recovering into Effect.void/Effect.unit erases the failure; recover meaningfully or propagate. */
50
+ export const noSilentErrorSwallowRule = defineRule({
51
+ meta: {
52
+ type: "problem",
53
+ docs: {
54
+ description: "Disallow Effect catch handlers that reduce failures to Effect.void or Effect.unit; recover meaningfully, transform the error, or let it propagate.",
55
+ },
56
+ messages: {
57
+ silentSwallow: "This catch handler reduces every failure to `Effect.void`/`Effect.unit`, erasing the error. Recover meaningfully, transform it into a tagged failure, or remove the handler and let the error propagate.",
58
+ },
59
+ },
60
+ createOnce(context) {
61
+ return {
62
+ before() {
63
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
64
+ return false;
65
+ },
66
+ CallExpression(node) {
67
+ const callee = node.callee;
68
+ if (callee.type !== "MemberExpression" ||
69
+ callee.computed ||
70
+ callee.object.type !== "Identifier" ||
71
+ callee.object.name !== "Effect" ||
72
+ callee.property.type !== "Identifier" ||
73
+ !CATCH_METHODS.has(callee.property.name)) {
74
+ return;
75
+ }
76
+ for (const argument of node.arguments) {
77
+ if (returnsOnlyVoid(argument)) {
78
+ context.report({ node, messageId: "silentSwallow" });
79
+ return;
80
+ }
81
+ if (argument.type !== "ObjectExpression")
82
+ continue;
83
+ for (const property of argument.properties) {
84
+ if (property.type !== "Property")
85
+ continue;
86
+ if (returnsOnlyVoid(property.value)) {
87
+ context.report({ node, messageId: "silentSwallow" });
88
+ return;
89
+ }
90
+ }
91
+ }
92
+ },
93
+ };
94
+ },
95
+ });
@@ -0,0 +1,6 @@
1
+ /** Static forwarders alias a service method at module scope; acquire the service where its method is used instead.
2
+ *
3
+ * Import tracking covers local names bound by imports of "effect" and
4
+ * "effect/Effect"; re-exports are not tracked.
5
+ */
6
+ export declare const noStaticEffectServiceForwardersRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,222 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { ancestorsOf } from "../../shared/ancestors.js";
3
+ import { isString } from "../../shared/structural.js";
4
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$|\/test\//u;
5
+ /** Computed or plain property name on a member expression.
6
+ *
7
+ * @param {ESTree.MemberExpression} member - The member expression node.
8
+ * @returns {string | null} The property name, or null when unavailable.
9
+ */
10
+ function memberName(member) {
11
+ if (!member.computed) {
12
+ return member.property.type === "Identifier" ? member.property.name : null;
13
+ }
14
+ if (member.property.type === "Literal" && isString(member.property.value)) {
15
+ return member.property.value;
16
+ }
17
+ return null;
18
+ }
19
+ /** Imported name behind an import specifier, for both plain and string-literal spellings.
20
+ *
21
+ * @param {ESTree.Node} specifier - The import specifier node.
22
+ * @returns {string | undefined} The imported name, if any.
23
+ */
24
+ function importedNameOf(specifier) {
25
+ if (specifier.type !== "ImportSpecifier")
26
+ return undefined;
27
+ return specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
28
+ }
29
+ /** Local binding name of an import specifier.
30
+ *
31
+ * @param {ESTree.Node} specifier - The import specifier node.
32
+ * @returns {string | undefined} The local bound name, if any.
33
+ */
34
+ function localNameOf(specifier) {
35
+ return specifier.type === "ImportSpecifier" || specifier.type === "ImportNamespaceSpecifier"
36
+ ? specifier.local.name
37
+ : undefined;
38
+ }
39
+ /** Whether the call site sits inside a `static` class property initializer.
40
+ *
41
+ * @param {SourceCode} sourceCode - The rule's source-code accessor.
42
+ * @param {ESTree.Node} node - The call expression being visited.
43
+ * @returns {boolean} True when enclosed by a static property definition.
44
+ */
45
+ function inStaticClassField(sourceCode, node) {
46
+ for (const current of ancestorsOf(sourceCode, node)) {
47
+ if (current.type === "PropertyDefinition")
48
+ return current.static === true;
49
+ if (current.type === "Program")
50
+ return false;
51
+ }
52
+ return false;
53
+ }
54
+ /**
55
+ * Single-parameter handler whose body is one expression or one return statement.
56
+ *
57
+ * @param {ESTree.Node} node - The candidate callback function node.
58
+ * @returns {CallbackExpression | undefined} The extracted expression and parameter, if matching.
59
+ */
60
+ function callbackExpression(node) {
61
+ if (node.type !== "ArrowFunctionExpression" && node.type !== "FunctionExpression")
62
+ return undefined;
63
+ if (node.params.length !== 1)
64
+ return undefined;
65
+ const parameter = node.params[0];
66
+ if (parameter.type !== "Identifier")
67
+ return undefined;
68
+ const parameterName = parameter.name;
69
+ if (node.body === null)
70
+ return undefined;
71
+ let body = node.body;
72
+ if (body.type === "BlockStatement") {
73
+ if (body.body.length !== 1)
74
+ return undefined;
75
+ const statement = body.body[0];
76
+ if (statement.type !== "ReturnStatement")
77
+ return undefined;
78
+ if (statement.argument === null || statement.argument === undefined)
79
+ return undefined;
80
+ body = statement.argument;
81
+ }
82
+ return { expression: body, parameterName };
83
+ }
84
+ /** `svc.member(...)` or bare `svc.member`, where `svc` is exactly the acquired service.
85
+ *
86
+ * @param {ESTree.Expression} expression - The forwarded callback expression.
87
+ * @param {string | undefined} parameterName - The acquired service parameter name.
88
+ * @returns {boolean} True when the expression only reads that service's member.
89
+ */
90
+ function isDirectParameterMember(expression, parameterName) {
91
+ if (parameterName === undefined)
92
+ return false;
93
+ const member = expression.type === "CallExpression" ? expression.callee : expression;
94
+ if (member.type !== "MemberExpression")
95
+ return false;
96
+ return member.object.type === "Identifier" && member.object.name === parameterName;
97
+ }
98
+ /** Static forwarders alias a service method at module scope; acquire the service where its method is used instead.
99
+ *
100
+ * Import tracking covers local names bound by imports of "effect" and
101
+ * "effect/Effect"; re-exports are not tracked.
102
+ */
103
+ export const noStaticEffectServiceForwardersRule = defineRule({
104
+ meta: {
105
+ type: "problem",
106
+ docs: {
107
+ description: "Disallow static class-field forwarders around Effect services; yield the service at the usage site and call the method directly so dependencies stay explicit.",
108
+ },
109
+ messages: {
110
+ staticForwarder: "This static field forwards an Effect service method. Acquire the service where the method is used (`Effect.flatMap(Service, (svc) => ...)`) so the dependency stays explicit and testable.",
111
+ },
112
+ },
113
+ createOnce(context) {
114
+ const effectNamespaceNames = new Set();
115
+ const flatMapNames = new Set();
116
+ const serviceNames = new Set();
117
+ const pipeNames = new Set();
118
+ const isEffectCall = (node, method, directNames) => {
119
+ if (node.type !== "CallExpression")
120
+ return false;
121
+ const callee = node.callee;
122
+ if (callee.type === "Identifier") {
123
+ return directNames.has(callee.name);
124
+ }
125
+ if (callee.type !== "MemberExpression")
126
+ return false;
127
+ return (callee.object.type === "Identifier" &&
128
+ effectNamespaceNames.has(callee.object.name) &&
129
+ memberName(callee) === method);
130
+ };
131
+ const isServiceAcquisition = (node) => {
132
+ if (!isEffectCall(node, "service", serviceNames))
133
+ return false;
134
+ return node.arguments.length === 1 && node.arguments[0].type === "ThisExpression";
135
+ };
136
+ const isForwardingFlatMap = (node) => {
137
+ if (!isEffectCall(node, "flatMap", flatMapNames))
138
+ return false;
139
+ const last = node.arguments[node.arguments.length - 1];
140
+ if (last === undefined)
141
+ return false;
142
+ const callback = callbackExpression(last);
143
+ if (callback === undefined)
144
+ return false;
145
+ return isDirectParameterMember(callback.expression, callback.parameterName);
146
+ };
147
+ return {
148
+ before() {
149
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
150
+ return false;
151
+ },
152
+ ImportDeclaration(node) {
153
+ if (node.source.value === "effect") {
154
+ for (const specifier of node.specifiers) {
155
+ const local = localNameOf(specifier);
156
+ if (local === undefined)
157
+ continue;
158
+ if (specifier.type === "ImportNamespaceSpecifier")
159
+ effectNamespaceNames.add(local);
160
+ const imported = importedNameOf(specifier);
161
+ if (specifier.type === "ImportSpecifier" && imported === "Effect") {
162
+ effectNamespaceNames.add(local);
163
+ }
164
+ if (specifier.type === "ImportSpecifier" && imported === "pipe")
165
+ pipeNames.add(local);
166
+ }
167
+ return;
168
+ }
169
+ if (node.source.value !== "effect/Effect")
170
+ return;
171
+ for (const specifier of node.specifiers) {
172
+ const local = localNameOf(specifier);
173
+ if (local === undefined)
174
+ continue;
175
+ if (specifier.type === "ImportNamespaceSpecifier" ||
176
+ specifier.type === "ImportDefaultSpecifier") {
177
+ effectNamespaceNames.add(local);
178
+ continue;
179
+ }
180
+ const imported = importedNameOf(specifier);
181
+ if (imported === "flatMap")
182
+ flatMapNames.add(local);
183
+ else if (imported === "service")
184
+ serviceNames.add(local);
185
+ }
186
+ },
187
+ CallExpression(node) {
188
+ if (!inStaticClassField(context.sourceCode, node))
189
+ return;
190
+ const args = node.arguments;
191
+ if (isEffectCall(node, "flatMap", flatMapNames) && args.length >= 2) {
192
+ const first = args[0];
193
+ if (first !== undefined && isServiceAcquisition(first) && isForwardingFlatMap(node)) {
194
+ context.report({ node, messageId: "staticForwarder" });
195
+ return;
196
+ }
197
+ }
198
+ const callee = node.callee;
199
+ let subject;
200
+ let operators;
201
+ if (callee.type === "Identifier") {
202
+ if (!pipeNames.has(callee.name))
203
+ return;
204
+ subject = args[0];
205
+ operators = args.slice(1);
206
+ }
207
+ else {
208
+ if (callee.type !== "MemberExpression" || memberName(callee) !== "pipe") {
209
+ return;
210
+ }
211
+ subject = callee.object;
212
+ operators = args;
213
+ }
214
+ if (subject !== undefined &&
215
+ isServiceAcquisition(subject) &&
216
+ operators.some((operator) => isForwardingFlatMap(operator))) {
217
+ context.report({ node, messageId: "staticForwarder" });
218
+ }
219
+ },
220
+ };
221
+ },
222
+ });
@@ -0,0 +1,2 @@
1
+ /** Raw `try`/`catch` detours failures around the typed error channel; route them through `Effect.try` instead. */
2
+ export declare const noTryCatchRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,30 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$|\/test\//u;
3
+ /** Raw `try`/`catch` detours failures around the typed error channel; route them through `Effect.try` instead. */
4
+ export const noTryCatchRule = defineRule({
5
+ meta: {
6
+ type: "problem",
7
+ docs: {
8
+ description: "Disallow raw try/catch; move fallible work behind Effect.try (with a tagged failure reason) or let errors propagate through the typed channel. Unavoidable boundaries justify themselves with a SAFETY comment.",
9
+ },
10
+ messages: {
11
+ tryCatch: "Raw `try`/`catch` detours this failure around the typed error channel. Use `Effect.try` (or `Effect.tryPromise`) failing a tagged reason, or let the error propagate. An integration boundary that must consume throwing APIs justifies itself with a `SAFETY:` comment.",
12
+ },
13
+ },
14
+ createOnce(context) {
15
+ return {
16
+ before() {
17
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
18
+ return false;
19
+ },
20
+ TryStatement(node) {
21
+ const justified = context.sourceCode
22
+ .getCommentsBefore(node)
23
+ .some((comment) => /\bSAFETY\s*:/u.test(comment.value));
24
+ if (justified)
25
+ return;
26
+ context.report({ node, messageId: "tryCatch" });
27
+ },
28
+ };
29
+ },
30
+ });
@@ -0,0 +1,5 @@
1
+ /**
2
+ * JSON.parse throws a raw SyntaxError defect. Inside an Effect/Either/Option
3
+ * channel that bypasses the typed failure path unless explicitly guarded.
4
+ */
5
+ export declare const noUnguardedJsonParseRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,200 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { ancestorsOf } from "../../shared/ancestors.js";
3
+ import { readField } from "../../shared/structural.js";
4
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$|\/test\//u;
5
+ const commentOwnerKinds = new Set([
6
+ "ExpressionStatement",
7
+ "ReturnStatement",
8
+ "ThrowStatement",
9
+ "VariableDeclaration",
10
+ ]);
11
+ /** Whether the nearest annotated function returns through the Effect/Either/Option channel.
12
+ *
13
+ * @param {SourceCode} sourceCode - The rule's source-code accessor.
14
+ * @param {ESTree.Node} node - The JSON.parse call expression.
15
+ * @returns {boolean} True when an enclosing function declares a channel return type.
16
+ */
17
+ function insideChannelReturningFunction(sourceCode, node) {
18
+ const chain = ancestorsOf(sourceCode, node);
19
+ for (let index = chain.length - 1; index >= 0; index--) {
20
+ const current = chain[index];
21
+ if (current.type === "Program")
22
+ break;
23
+ if (current.type !== "FunctionDeclaration" &&
24
+ current.type !== "FunctionExpression" &&
25
+ current.type !== "ArrowFunctionExpression") {
26
+ continue;
27
+ }
28
+ const returnType = current.returnType?.typeAnnotation;
29
+ if (returnType == null)
30
+ continue;
31
+ const text = annotationText(returnType);
32
+ if (/\b(?:Effect|Either|Option)(?:\.|\b)/u.test(text))
33
+ return true;
34
+ }
35
+ return false;
36
+ }
37
+ /** Render an annotation to text so qualified names like Effect.Effect match.
38
+ *
39
+ * @param {ESTree.TSType} type - The type node to render.
40
+ * @returns {string} A space-joined textual sketch of the annotation.
41
+ */
42
+ function annotationText(type) {
43
+ switch (type.type) {
44
+ case "TSTypeReference": {
45
+ const name = type.typeName;
46
+ const head = name.type === "Identifier"
47
+ ? name.name
48
+ : name.type === "TSQualifiedName"
49
+ ? name.right.name
50
+ : "";
51
+ const args = readField(type, "typeArguments");
52
+ const renderedArgs = args?.params?.map(annotationText).join(" ") ?? "";
53
+ return `${head} ${renderedArgs}`;
54
+ }
55
+ case "TSUnionType":
56
+ case "TSIntersectionType":
57
+ return type.types.map(annotationText).join(" ");
58
+ case "TSTupleType": {
59
+ const render = (element) => {
60
+ if ("elementType" in element)
61
+ return render(element.elementType);
62
+ if (element.type === "TSOptionalType" || element.type === "TSRestType") {
63
+ return annotationText(element.typeAnnotation);
64
+ }
65
+ return annotationText(element);
66
+ };
67
+ return type.elementTypes.map(render).join(" ");
68
+ }
69
+ case "TSTypeOperator":
70
+ return annotationText(type.typeAnnotation);
71
+ case "TSArrayType":
72
+ return annotationText(type.elementType);
73
+ default:
74
+ return "";
75
+ }
76
+ }
77
+ /**
78
+ * Whether a call targets Effect.try or Effect.trySync.
79
+ *
80
+ * @param {ESTree.Node} node - The candidate call expression.
81
+ * @returns {boolean} True when the call is an Effect.try family invocation.
82
+ */
83
+ function isEffectTryCall(node) {
84
+ if (node.type !== "CallExpression")
85
+ return false;
86
+ const callee = node.callee;
87
+ return (callee.type === "MemberExpression" &&
88
+ !callee.computed &&
89
+ callee.object.type === "Identifier" &&
90
+ callee.object.name === "Effect" &&
91
+ callee.property.type === "Identifier" &&
92
+ (callee.property.name === "try" || callee.property.name === "trySync"));
93
+ }
94
+ /**
95
+ * Guard recognition for a JSON.parse site.
96
+ *
97
+ * A thunk handed straight to Effect.try through an object literal
98
+ * ({ try: () => ..., catch: ... }) counts as guarded: climb past pure
99
+ * containers (Property, ObjectExpression, ArrayExpression) and resume the
100
+ * walk at the container exit, re-processing it.
101
+ *
102
+ * @param {SourceCode} sourceCode - The rule's source-code accessor.
103
+ * @param {ESTree.Node} node - The JSON.parse call expression.
104
+ * @returns {boolean} True when the parse site is guarded.
105
+ */
106
+ function isGuardedParse(sourceCode, node) {
107
+ const chain = [...ancestorsOf(sourceCode, node)].reverse();
108
+ let index = 0;
109
+ while (index < chain.length) {
110
+ const current = chain[index];
111
+ if (current.type === "Program")
112
+ return false;
113
+ if (current.type === "TryStatement")
114
+ return true;
115
+ if (isEffectTryCall(current))
116
+ return true;
117
+ if (current.type === "FunctionDeclaration" ||
118
+ current.type === "FunctionExpression" ||
119
+ current.type === "ArrowFunctionExpression") {
120
+ let probeIndex = index + 1;
121
+ while (probeIndex < chain.length &&
122
+ (chain[probeIndex].type === "Property" ||
123
+ chain[probeIndex].type === "ObjectExpression" ||
124
+ chain[probeIndex].type === "ArrayExpression")) {
125
+ probeIndex += 1;
126
+ }
127
+ if (probeIndex < chain.length && isEffectTryCall(chain[probeIndex])) {
128
+ index = probeIndex;
129
+ continue;
130
+ }
131
+ return false;
132
+ }
133
+ index += 1;
134
+ }
135
+ return false;
136
+ }
137
+ /**
138
+ * Whether a SAFETY comment covers this parse site or one of its statement owners.
139
+ *
140
+ * @param {SourceCode} sourceCode - The rule's source-code accessor.
141
+ * @param {ESTree.Node} node - The JSON.parse call expression.
142
+ * @returns {boolean} True when an applicable SAFETY justification exists.
143
+ */
144
+ function hasSafetyComment(sourceCode, node) {
145
+ const chain = [node, ...[...ancestorsOf(sourceCode, node)].reverse()];
146
+ for (let index = 0; index < chain.length; index += 1) {
147
+ const current = chain[index];
148
+ if (sourceCode
149
+ .getCommentsBefore(current)
150
+ .some((comment) => comment.end <= node.start && /\bSAFETY\s*:/u.test(comment.value))) {
151
+ return true;
152
+ }
153
+ if (commentOwnerKinds.has(current.type))
154
+ return false;
155
+ const parent = chain[index + 1];
156
+ if (parent === undefined || parent.type === "Program")
157
+ return false;
158
+ }
159
+ return false;
160
+ }
161
+ /**
162
+ * JSON.parse throws a raw SyntaxError defect. Inside an Effect/Either/Option
163
+ * channel that bypasses the typed failure path unless explicitly guarded.
164
+ */
165
+ export const noUnguardedJsonParseRule = defineRule({
166
+ meta: {
167
+ type: "problem",
168
+ docs: {
169
+ description: "Require JSON.parse inside Effect/Either/Option-returning functions to be channelled through Effect.try (or a try/catch), or justified with a SAFETY comment for provably-total parses.",
170
+ },
171
+ messages: {
172
+ unguardedParse: "`JSON.parse` here throws a raw SyntaxError defect past the typed error channel. Channel it with `Effect.try({ try: ..., catch: ... })` failing a tagged reason (e.g. MalformedRenderError), or justify totality with a `SAFETY:` comment.",
173
+ },
174
+ },
175
+ createOnce(context) {
176
+ return {
177
+ before() {
178
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
179
+ return false;
180
+ },
181
+ CallExpression(node) {
182
+ const callee = node.callee;
183
+ if (callee.type !== "MemberExpression" ||
184
+ callee.computed ||
185
+ callee.object.type !== "Identifier" ||
186
+ callee.object.name !== "JSON" ||
187
+ callee.property.type !== "Identifier" ||
188
+ callee.property.name !== "parse")
189
+ return;
190
+ if (!insideChannelReturningFunction(context.sourceCode, node))
191
+ return;
192
+ if (isGuardedParse(context.sourceCode, node))
193
+ return;
194
+ if (hasSafetyComment(context.sourceCode, node))
195
+ return;
196
+ context.report({ node, messageId: "unguardedParse" });
197
+ },
198
+ };
199
+ },
200
+ });
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Every exported `*Option` guarded core must have a converted public twin in the
3
+ * same module, so Option-shaped internals cannot silently become the public API.
4
+ */
5
+ export declare const optionCoreNeedsEffectPublicRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,76 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$|\/test\//u;
3
+ /** The exported name declared by this statement, if any.
4
+ *
5
+ * @param {ESTree.Node} node - The export or declaration statement.
6
+ * @returns {string | null} The declared binding name, or null when anonymous.
7
+ */
8
+ function exportedName(node) {
9
+ if (node.type === "ExportNamedDeclaration") {
10
+ const declaration = node.declaration;
11
+ if (declaration === null || declaration === undefined)
12
+ return null;
13
+ if (declaration.type === "FunctionDeclaration" && declaration.id !== null) {
14
+ return declaration.id.name;
15
+ }
16
+ if (declaration.type === "VariableDeclaration") {
17
+ for (const declarator of declaration.declarations) {
18
+ if (declarator.id.type === "Identifier")
19
+ return declarator.id.name;
20
+ }
21
+ }
22
+ }
23
+ return null;
24
+ }
25
+ /**
26
+ * Every exported `*Option` guarded core must have a converted public twin in the
27
+ * same module, so Option-shaped internals cannot silently become the public API.
28
+ */
29
+ export const optionCoreNeedsEffectPublicRule = defineRule({
30
+ meta: {
31
+ type: "problem",
32
+ docs: {
33
+ description: "Require every exported *Option guarded core to be paired with a converted public API that owns the typed error channel.",
34
+ },
35
+ messages: {
36
+ missingTwin: "`{{name}}` collapses failures to `Option.none()` with no converted public twin. Export `{{base}}` returning `Effect.Effect<T, MoneyError>` (or mark the core `@deprecated` if retired), so callers can match Overflow vs InvalidInput vs ZeroDivisor.",
37
+ },
38
+ },
39
+ createOnce(context) {
40
+ const cores = [];
41
+ const exported = new Set();
42
+ return {
43
+ before() {
44
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
45
+ return false;
46
+ cores.length = 0;
47
+ exported.clear();
48
+ },
49
+ "ExportNamedDeclaration > VariableDeclaration > VariableDeclarator, ExportNamedDeclaration > FunctionDeclaration": (node) => {
50
+ const declaratorId = node.type === "VariableDeclarator" ? node.id : null;
51
+ const name = node.type === "FunctionDeclaration"
52
+ ? (node.id?.name ?? null)
53
+ : declaratorId?.type === "Identifier"
54
+ ? declaratorId.name
55
+ : null;
56
+ if (name === null)
57
+ return;
58
+ exported.add(name);
59
+ if (name.endsWith("Option")) {
60
+ cores.push({ node, name, base: name.slice(0, -"Option".length) });
61
+ }
62
+ },
63
+ "Program:exit"() {
64
+ for (const core of cores) {
65
+ if (!exported.has(core.base)) {
66
+ context.report({
67
+ node: core.node,
68
+ messageId: "missingTwin",
69
+ data: { name: core.name, base: core.base },
70
+ });
71
+ }
72
+ }
73
+ },
74
+ };
75
+ },
76
+ });
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Precondition violations are defects by doctrine: thrown directly they escape
3
+ * the Cause, invisible to telemetry and supervisors.
4
+ */
5
+ export declare const preferDieForPreconditionDefectsRule: import("@oxlint/plugins").Rule;