@autotelic/plumb 0.6.0 → 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 (279) 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/rules/guarded-op-must-return-effect.js +1 -1
  5. package/dist/effect/rules/no-cascading-layer-provide.js +1 -1
  6. package/dist/effect/rules/no-decode-unknown-option.js +1 -1
  7. package/dist/effect/rules/no-direct-browser-storage.js +3 -3
  8. package/dist/effect/rules/no-direct-fetch.js +1 -1
  9. package/dist/effect/rules/no-manual-field-guards.js +1 -1
  10. package/dist/effect/rules/no-nested-layer-provide.js +1 -1
  11. package/dist/effect/rules/no-nullish-default-on-partial-input.js +2 -2
  12. package/dist/effect/rules/no-raw-error-forwarding.d.ts +4 -0
  13. package/dist/effect/rules/no-raw-error-forwarding.js +7 -2
  14. package/dist/effect/rules/no-silent-error-swallow.js +1 -1
  15. package/dist/effect/rules/no-static-effect-service-forwarders.js +5 -4
  16. package/dist/effect/rules/no-try-catch.js +1 -1
  17. package/dist/effect/rules/no-unguarded-json-parse.js +1 -1
  18. package/dist/effect/rules/option-core-needs-effect-public.js +1 -1
  19. package/dist/effect/rules/prefer-die-for-precondition-defects.js +1 -1
  20. package/dist/effect/rules/prefer-effect-gen-for-guard-ladders.js +1 -1
  21. package/dist/effect/rules/prefer-effect-match.js +2 -2
  22. package/dist/effect/rules/prefer-effect-predicate-over-boolean-function.js +1 -1
  23. package/dist/effect/rules/prefer-named-guard-predicate.js +1 -1
  24. package/dist/effect/rules/prefer-option-pipeline.js +13 -12
  25. package/dist/effect/rules/prefer-ordering-match.js +1 -1
  26. package/dist/effect/rules/prefer-tagged-enum.js +1 -1
  27. package/dist/effect/rules/require-schema-type-derivation.d.ts +8 -2
  28. package/dist/effect/rules/require-schema-type-derivation.js +14 -4
  29. package/dist/index.js +8 -0
  30. package/dist/react/rules/require-dot-notation-exports.js +1 -1
  31. package/dist/react/rules/require-guarded-context-hook.js +1 -1
  32. package/dist/react/rules/require-tripartite-context.js +1 -1
  33. package/dist/react/rules/use-encapsulation.js +1 -1
  34. package/dist/rules/no-adapter-in-values.d.ts +12 -0
  35. package/dist/rules/no-adapter-in-values.js +110 -0
  36. package/dist/rules/no-builtin-throws.js +1 -1
  37. package/dist/rules/no-duplicated-literal-union.d.ts +7 -0
  38. package/dist/rules/no-duplicated-literal-union.js +5 -1
  39. package/dist/rules/no-generic-export-names.js +1 -1
  40. package/dist/rules/no-multiple-function-params.js +26 -12
  41. package/dist/rules/no-mutable-environment-capture.js +2 -2
  42. package/dist/rules/no-nondeterministic-core.js +1 -1
  43. package/dist/rules/no-nullable-value-field.d.ts +16 -0
  44. package/dist/rules/no-nullable-value-field.js +117 -0
  45. package/dist/rules/no-optional-function-parameters.js +1 -1
  46. package/dist/rules/no-row-coercion.d.ts +13 -0
  47. package/dist/rules/no-row-coercion.js +135 -0
  48. package/dist/rules/no-single-use-private-functions.js +1 -1
  49. package/dist/rules/no-sql-string-interpolation.js +2 -2
  50. package/dist/rules/no-stray-inline-comments.js +1 -1
  51. package/dist/rules/no-string-instant.d.ts +15 -0
  52. package/dist/rules/no-string-instant.js +108 -0
  53. package/dist/rules/no-swappable-primitive-params.js +1 -1
  54. package/dist/rules/no-tag-ladder-assertions.js +1 -1
  55. package/dist/rules/no-vague-test-filenames.js +1 -1
  56. package/dist/rules/prefer-property-tests.d.ts +5 -0
  57. package/dist/rules/prefer-property-tests.js +7 -0
  58. package/dist/rules/require-jsdoc-on-exported.js +1 -1
  59. package/dist/shared/ancestors.d.ts +1 -1
  60. package/dist/shared/ancestors.js +1 -1
  61. package/dist/shared/values-path.d.ts +12 -0
  62. package/dist/shared/values-path.js +56 -0
  63. package/dist/src/configs/recommended-rules.d.ts +20 -0
  64. package/dist/src/configs/recommended-rules.js +22 -0
  65. package/dist/src/effect/index.d.ts +3 -0
  66. package/dist/src/effect/index.js +60 -0
  67. package/dist/src/effect/rules/guarded-op-must-return-effect.d.ts +6 -0
  68. package/dist/src/effect/rules/guarded-op-must-return-effect.js +235 -0
  69. package/dist/src/effect/rules/guarded-op-must-return-option.d.ts +2 -0
  70. package/dist/src/effect/rules/guarded-op-must-return-option.js +88 -0
  71. package/dist/src/effect/rules/no-cascading-layer-provide.d.ts +6 -0
  72. package/dist/src/effect/rules/no-cascading-layer-provide.js +73 -0
  73. package/dist/src/effect/rules/no-decode-unknown-option.d.ts +7 -0
  74. package/dist/src/effect/rules/no-decode-unknown-option.js +34 -0
  75. package/dist/src/effect/rules/no-direct-browser-storage.d.ts +2 -0
  76. package/dist/src/effect/rules/no-direct-browser-storage.js +88 -0
  77. package/dist/src/effect/rules/no-direct-fetch.d.ts +2 -0
  78. package/dist/src/effect/rules/no-direct-fetch.js +37 -0
  79. package/dist/src/effect/rules/no-manual-field-guards.d.ts +6 -0
  80. package/dist/src/effect/rules/no-manual-field-guards.js +129 -0
  81. package/dist/src/effect/rules/no-nested-layer-provide.d.ts +2 -0
  82. package/dist/src/effect/rules/no-nested-layer-provide.js +50 -0
  83. package/dist/src/effect/rules/no-nullish-default-on-partial-input.d.ts +13 -0
  84. package/dist/src/effect/rules/no-nullish-default-on-partial-input.js +109 -0
  85. package/dist/src/effect/rules/no-raw-error-forwarding.d.ts +12 -0
  86. package/dist/src/effect/rules/no-raw-error-forwarding.js +103 -0
  87. package/dist/src/effect/rules/no-schema-class-modeling.d.ts +2 -0
  88. package/dist/src/effect/rules/no-schema-class-modeling.js +52 -0
  89. package/dist/src/effect/rules/no-service-constructor-imports.d.ts +2 -0
  90. package/dist/src/effect/rules/no-service-constructor-imports.js +42 -0
  91. package/dist/src/effect/rules/no-silent-error-swallow.d.ts +2 -0
  92. package/dist/src/effect/rules/no-silent-error-swallow.js +95 -0
  93. package/dist/src/effect/rules/no-static-effect-service-forwarders.d.ts +6 -0
  94. package/dist/src/effect/rules/no-static-effect-service-forwarders.js +222 -0
  95. package/dist/src/effect/rules/no-try-catch.d.ts +2 -0
  96. package/dist/src/effect/rules/no-try-catch.js +30 -0
  97. package/dist/src/effect/rules/no-unguarded-json-parse.d.ts +5 -0
  98. package/dist/src/effect/rules/no-unguarded-json-parse.js +200 -0
  99. package/dist/src/effect/rules/option-core-needs-effect-public.d.ts +5 -0
  100. package/dist/src/effect/rules/option-core-needs-effect-public.js +76 -0
  101. package/dist/src/effect/rules/prefer-die-for-precondition-defects.d.ts +5 -0
  102. package/dist/src/effect/rules/prefer-die-for-precondition-defects.js +112 -0
  103. package/dist/src/effect/rules/prefer-effect-gen-for-guard-ladders.d.ts +5 -0
  104. package/dist/src/effect/rules/prefer-effect-gen-for-guard-ladders.js +72 -0
  105. package/dist/src/effect/rules/prefer-effect-match.d.ts +2 -0
  106. package/dist/src/effect/rules/prefer-effect-match.js +74 -0
  107. package/dist/src/effect/rules/prefer-effect-predicate-over-boolean-function.d.ts +2 -0
  108. package/dist/src/effect/rules/prefer-effect-predicate-over-boolean-function.js +75 -0
  109. package/dist/src/effect/rules/prefer-named-guard-predicate.d.ts +2 -0
  110. package/dist/src/effect/rules/prefer-named-guard-predicate.js +93 -0
  111. package/dist/src/effect/rules/prefer-option-pipeline.d.ts +2 -0
  112. package/dist/src/effect/rules/prefer-option-pipeline.js +87 -0
  113. package/dist/src/effect/rules/prefer-ordering-match.d.ts +2 -0
  114. package/dist/src/effect/rules/prefer-ordering-match.js +135 -0
  115. package/dist/src/effect/rules/prefer-tagged-enum.d.ts +2 -0
  116. package/dist/src/effect/rules/prefer-tagged-enum.js +66 -0
  117. package/dist/src/effect/rules/require-schema-type-derivation.d.ts +7 -0
  118. package/dist/src/effect/rules/require-schema-type-derivation.js +80 -0
  119. package/dist/src/index.d.ts +3 -0
  120. package/dist/src/index.js +106 -0
  121. package/dist/src/meta/index.d.ts +7 -0
  122. package/dist/src/meta/index.js +22 -0
  123. package/dist/src/meta/rules/no-disable-directives.d.ts +6 -0
  124. package/dist/src/meta/rules/no-disable-directives.js +35 -0
  125. package/dist/src/meta/rules/no-manual-ancestor-walks.d.ts +2 -0
  126. package/dist/src/meta/rules/no-manual-ancestor-walks.js +26 -0
  127. package/dist/src/meta/rules/prefer-before-file-scope.d.ts +2 -0
  128. package/dist/src/meta/rules/prefer-before-file-scope.js +57 -0
  129. package/dist/src/meta/rules/require-create-once.d.ts +2 -0
  130. package/dist/src/meta/rules/require-create-once.js +51 -0
  131. package/dist/src/meta/rules/require-rule-tester.d.ts +2 -0
  132. package/dist/src/meta/rules/require-rule-tester.js +50 -0
  133. package/dist/src/react/index.d.ts +3 -0
  134. package/dist/src/react/index.js +16 -0
  135. package/dist/src/react/role.d.ts +23 -0
  136. package/dist/src/react/role.js +30 -0
  137. package/dist/src/react/rules/require-dot-notation-exports.d.ts +27 -0
  138. package/dist/src/react/rules/require-dot-notation-exports.js +144 -0
  139. package/dist/src/react/rules/require-guarded-context-hook.d.ts +19 -0
  140. package/dist/src/react/rules/require-guarded-context-hook.js +167 -0
  141. package/dist/src/react/rules/require-tripartite-context.d.ts +17 -0
  142. package/dist/src/react/rules/require-tripartite-context.js +160 -0
  143. package/dist/src/react/rules/use-encapsulation.d.ts +22 -0
  144. package/dist/src/react/rules/use-encapsulation.js +97 -0
  145. package/dist/src/rules/no-anonymous-wide-tuples.d.ts +7 -0
  146. package/dist/src/rules/no-anonymous-wide-tuples.js +34 -0
  147. package/dist/src/rules/no-barrel-export-star.d.ts +2 -0
  148. package/dist/src/rules/no-barrel-export-star.js +26 -0
  149. package/dist/src/rules/no-boolean-field-signals.d.ts +2 -0
  150. package/dist/src/rules/no-boolean-field-signals.js +279 -0
  151. package/dist/src/rules/no-builtin-throws.d.ts +6 -0
  152. package/dist/src/rules/no-builtin-throws.js +74 -0
  153. package/dist/src/rules/no-chained-type-assertions.d.ts +2 -0
  154. package/dist/src/rules/no-chained-type-assertions.js +54 -0
  155. package/dist/src/rules/no-conditional-empty-object-spread.d.ts +2 -0
  156. package/dist/src/rules/no-conditional-empty-object-spread.js +36 -0
  157. package/dist/src/rules/no-duplicated-literal-union.d.ts +6 -0
  158. package/dist/src/rules/no-duplicated-literal-union.js +66 -0
  159. package/dist/src/rules/no-exported-mutable-state.d.ts +7 -0
  160. package/dist/src/rules/no-exported-mutable-state.js +104 -0
  161. package/dist/src/rules/no-generic-export-names.d.ts +2 -0
  162. package/dist/src/rules/no-generic-export-names.js +141 -0
  163. package/dist/src/rules/no-impossible-branch-throw.d.ts +2 -0
  164. package/dist/src/rules/no-impossible-branch-throw.js +51 -0
  165. package/dist/src/rules/no-known-value-widening.d.ts +2 -0
  166. package/dist/src/rules/no-known-value-widening.js +176 -0
  167. package/dist/src/rules/no-module-mocking.d.ts +2 -0
  168. package/dist/src/rules/no-module-mocking.js +90 -0
  169. package/dist/src/rules/no-multiple-function-params.d.ts +2 -0
  170. package/dist/src/rules/no-multiple-function-params.js +155 -0
  171. package/dist/src/rules/no-mutable-environment-capture.d.ts +7 -0
  172. package/dist/src/rules/no-mutable-environment-capture.js +134 -0
  173. package/dist/src/rules/no-nondeterministic-core.d.ts +6 -0
  174. package/dist/src/rules/no-nondeterministic-core.js +63 -0
  175. package/dist/src/rules/no-object-parameters.d.ts +2 -0
  176. package/dist/src/rules/no-object-parameters.js +95 -0
  177. package/dist/src/rules/no-optional-function-parameters.d.ts +7 -0
  178. package/dist/src/rules/no-optional-function-parameters.js +44 -0
  179. package/dist/src/rules/no-product-of-state-booleans.d.ts +2 -0
  180. package/dist/src/rules/no-product-of-state-booleans.js +79 -0
  181. package/dist/src/rules/no-redundant-derived-field.d.ts +6 -0
  182. package/dist/src/rules/no-redundant-derived-field.js +194 -0
  183. package/dist/src/rules/no-reflect-apply.d.ts +2 -0
  184. package/dist/src/rules/no-reflect-apply.js +29 -0
  185. package/dist/src/rules/no-reflect-get.d.ts +2 -0
  186. package/dist/src/rules/no-reflect-get.js +29 -0
  187. package/dist/src/rules/no-reinterpret-cast.d.ts +2 -0
  188. package/dist/src/rules/no-reinterpret-cast.js +68 -0
  189. package/dist/src/rules/no-runtime-typeof.d.ts +2 -0
  190. package/dist/src/rules/no-runtime-typeof.js +54 -0
  191. package/dist/src/rules/no-sentinel-comparison-union.d.ts +2 -0
  192. package/dist/src/rules/no-sentinel-comparison-union.js +139 -0
  193. package/dist/src/rules/no-shape-in-symbol-names.d.ts +2 -0
  194. package/dist/src/rules/no-shape-in-symbol-names.js +39 -0
  195. package/dist/src/rules/no-single-use-private-functions.d.ts +17 -0
  196. package/dist/src/rules/no-single-use-private-functions.js +419 -0
  197. package/dist/src/rules/no-sql-string-interpolation.d.ts +7 -0
  198. package/dist/src/rules/no-sql-string-interpolation.js +62 -0
  199. package/dist/src/rules/no-stacked-jsdoc-blocks.d.ts +2 -0
  200. package/dist/src/rules/no-stacked-jsdoc-blocks.js +50 -0
  201. package/dist/src/rules/no-stray-inline-comments.d.ts +2 -0
  202. package/dist/src/rules/no-stray-inline-comments.js +74 -0
  203. package/dist/src/rules/no-swappable-primitive-params.d.ts +2 -0
  204. package/dist/src/rules/no-swappable-primitive-params.js +96 -0
  205. package/dist/src/rules/no-tag-ladder-assertions.d.ts +6 -0
  206. package/dist/src/rules/no-tag-ladder-assertions.js +63 -0
  207. package/dist/src/rules/no-transposed-field-reads.d.ts +8 -0
  208. package/dist/src/rules/no-transposed-field-reads.js +101 -0
  209. package/dist/src/rules/no-unit-return-validators.d.ts +2 -0
  210. package/dist/src/rules/no-unit-return-validators.js +64 -0
  211. package/dist/src/rules/no-unknown-parameters.d.ts +2 -0
  212. package/dist/src/rules/no-unknown-parameters.js +82 -0
  213. package/dist/src/rules/no-unknown-returns.d.ts +2 -0
  214. package/dist/src/rules/no-unknown-returns.js +86 -0
  215. package/dist/src/rules/no-unknown-type-aliases.d.ts +2 -0
  216. package/dist/src/rules/no-unknown-type-aliases.js +64 -0
  217. package/dist/src/rules/no-unsafe-dictionary-type.d.ts +2 -0
  218. package/dist/src/rules/no-unsafe-dictionary-type.js +116 -0
  219. package/dist/src/rules/no-vague-test-filenames.d.ts +2 -0
  220. package/dist/src/rules/no-vague-test-filenames.js +61 -0
  221. package/dist/src/rules/no-widen-then-assert.d.ts +2 -0
  222. package/dist/src/rules/no-widen-then-assert.js +268 -0
  223. package/dist/src/rules/prefer-payload-brand.d.ts +2 -0
  224. package/dist/src/rules/prefer-payload-brand.js +57 -0
  225. package/dist/src/rules/prefer-property-tests.d.ts +5 -0
  226. package/dist/src/rules/prefer-property-tests.js +39 -0
  227. package/dist/src/rules/require-canonical-stringify-for-identity.d.ts +8 -0
  228. package/dist/src/rules/require-canonical-stringify-for-identity.js +72 -0
  229. package/dist/src/rules/require-deprecated-tag-for-legacy-comments.d.ts +2 -0
  230. package/dist/src/rules/require-deprecated-tag-for-legacy-comments.js +34 -0
  231. package/dist/src/rules/require-exhaustive-tag-switch.d.ts +7 -0
  232. package/dist/src/rules/require-exhaustive-tag-switch.js +34 -0
  233. package/dist/src/rules/require-fc-block-predicate.d.ts +2 -0
  234. package/dist/src/rules/require-fc-block-predicate.js +37 -0
  235. package/dist/src/rules/require-jsdoc-on-exported.d.ts +2 -0
  236. package/dist/src/rules/require-jsdoc-on-exported.js +66 -0
  237. package/dist/src/rules/require-published-order.d.ts +2 -0
  238. package/dist/src/rules/require-published-order.js +102 -0
  239. package/dist/src/rules/require-safety-comment-for-type-assertion.d.ts +2 -0
  240. package/dist/src/rules/require-safety-comment-for-type-assertion.js +53 -0
  241. package/dist/src/rules/require-sort-comparator.d.ts +7 -0
  242. package/dist/src/rules/require-sort-comparator.js +34 -0
  243. package/dist/src/rules/test-utils.d.ts +35 -0
  244. package/dist/src/rules/test-utils.js +53 -0
  245. package/dist/src/shared/ancestors.d.ts +18 -0
  246. package/dist/src/shared/ancestors.js +19 -0
  247. package/dist/src/shared/child-nodes.d.ts +12 -0
  248. package/dist/src/shared/child-nodes.js +26 -0
  249. package/dist/src/shared/dictionary-types.d.ts +55 -0
  250. package/dist/src/shared/dictionary-types.js +413 -0
  251. package/dist/src/shared/is-node.d.ts +9 -0
  252. package/dist/src/shared/is-node.js +10 -0
  253. package/dist/src/shared/lexical-type-parameters.d.ts +12 -0
  254. package/dist/src/shared/lexical-type-parameters.js +50 -0
  255. package/dist/src/shared/reflect-method.d.ts +15 -0
  256. package/dist/src/shared/reflect-method.js +32 -0
  257. package/dist/src/shared/rule-options.d.ts +18 -0
  258. package/dist/src/shared/rule-options.js +12 -0
  259. package/dist/src/shared/structural.d.ts +54 -0
  260. package/dist/src/shared/structural.js +40 -0
  261. package/dist/src/testing/index.d.ts +2 -0
  262. package/dist/src/testing/index.js +1 -0
  263. package/dist/src/testing/testable-rule.d.ts +39 -0
  264. package/dist/src/testing/testable-rule.js +84 -0
  265. package/dist/src/ui/index.d.ts +12 -0
  266. package/dist/src/ui/index.js +18 -0
  267. package/dist/src/ui/manifest.d.ts +34 -0
  268. package/dist/src/ui/manifest.js +75 -0
  269. package/dist/src/ui/rules/no-deprecated-parts.d.ts +3 -0
  270. package/dist/src/ui/rules/no-deprecated-parts.js +131 -0
  271. package/dist/testing/testable-rule.d.ts +6 -5
  272. package/dist/testing/testable-rule.js +20 -6
  273. package/dist/ui/index.d.ts +12 -0
  274. package/dist/ui/index.js +18 -0
  275. package/dist/ui/manifest.d.ts +49 -0
  276. package/dist/ui/manifest.js +90 -0
  277. package/dist/ui/rules/no-deprecated-parts.d.ts +3 -0
  278. package/dist/ui/rules/no-deprecated-parts.js +172 -0
  279. package/package.json +20 -11
@@ -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;
@@ -0,0 +1,112 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { readField } from "../../shared/structural.js";
3
+ import { ancestorsOf } from "../../shared/ancestors.js";
4
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$|\/test\//u;
5
+ /** Unwrap a tuple element to the type node it contributes to the annotation walk.
6
+ *
7
+ * @param {ESTree.TSTupleElement} element - Tuple element node.
8
+ * @returns {ESTree.TSType} The underlying type node.
9
+ */
10
+ function tupleElementType(element) {
11
+ if (element.type === "TSOptionalType" || element.type === "TSRestType") {
12
+ return element.typeAnnotation;
13
+ }
14
+ if ("elementType" in element)
15
+ return tupleElementType(element.elementType);
16
+ return element;
17
+ }
18
+ /** Whether the annotation references the Effect or Either channel (defect-capable).
19
+ *
20
+ * @param {ESTree.Node} node - A function-like node whose return annotation is inspected.
21
+ * @returns {boolean} True when the return annotation mentions Effect or Either.
22
+ */
23
+ function returnsEffectOrFailChannel(node) {
24
+ if (node.type !== "FunctionDeclaration" &&
25
+ node.type !== "FunctionExpression" &&
26
+ node.type !== "ArrowFunctionExpression") {
27
+ return false;
28
+ }
29
+ const annotation = node.returnType?.typeAnnotation;
30
+ if (annotation === undefined)
31
+ return false;
32
+ const seen = [annotation];
33
+ while (seen.length > 0) {
34
+ const type = seen.pop();
35
+ if (type === undefined)
36
+ continue;
37
+ switch (type.type) {
38
+ case "TSTypeReference": {
39
+ const name = type.typeName;
40
+ const head = name.type === "Identifier"
41
+ ? name.name
42
+ : name.type === "TSQualifiedName"
43
+ ? name.left.type === "Identifier"
44
+ ? name.left.name
45
+ : null
46
+ : null;
47
+ if (head === "Effect" || head === "Either") {
48
+ return true;
49
+ }
50
+ const args = readField(type, "typeArguments");
51
+ if (args?.params !== undefined)
52
+ seen.push(...args.params);
53
+ break;
54
+ }
55
+ case "TSUnionType":
56
+ case "TSIntersectionType":
57
+ seen.push(...type.types);
58
+ break;
59
+ case "TSTupleType":
60
+ for (const element of type.elementTypes) {
61
+ seen.push(tupleElementType(element));
62
+ }
63
+ break;
64
+ case "TSTypeOperator":
65
+ seen.push(type.typeAnnotation);
66
+ break;
67
+ case "TSArrayType":
68
+ seen.push(type.elementType);
69
+ break;
70
+ default:
71
+ break;
72
+ }
73
+ }
74
+ return false;
75
+ }
76
+ /**
77
+ * Precondition violations are defects by doctrine: thrown directly they escape
78
+ * the Cause, invisible to telemetry and supervisors.
79
+ */
80
+ export const preferDieForPreconditionDefectsRule = defineRule({
81
+ meta: {
82
+ type: "problem",
83
+ docs: {
84
+ description: "In Effect/Either-returning functions, raise precondition defects with Effect.die instead of a bare throw so they travel inside the Cause.",
85
+ },
86
+ messages: {
87
+ bareThrow: "This bare throw escapes the Effect `Cause`. Raise the tagged defect with `Effect.die(new ...)` (or reclassify the case as a typed failure on the error channel) so supervisors and telemetry observe it.",
88
+ },
89
+ },
90
+ createOnce(context) {
91
+ const check = (node) => {
92
+ const ancestors = ancestorsOf(context.sourceCode, node);
93
+ for (let index = ancestors.length - 1; index >= 0; index--) {
94
+ const current = ancestors[index];
95
+ if (current.type === "Program")
96
+ break;
97
+ if (current.type === "FunctionDeclaration" ||
98
+ current.type === "FunctionExpression" ||
99
+ current.type === "ArrowFunctionExpression") {
100
+ if (returnsEffectOrFailChannel(current))
101
+ context.report({ node, messageId: "bareThrow" });
102
+ return;
103
+ }
104
+ }
105
+ };
106
+ return { before() {
107
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
108
+ return false;
109
+ },
110
+ ThrowStatement: check };
111
+ },
112
+ });
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Long Effect.flatMap ladders read as callback pyramids; Effect.gen renders the
3
+ * same program as straight-line validation.
4
+ */
5
+ export declare const preferEffectGenForGuardLaddersRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,72 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { ancestorsOf } from "../../shared/ancestors.js";
3
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$|\/test\//u;
4
+ const LADDER_THRESHOLD = 3;
5
+ /** Whether this call is an Effect combinator chained in the flatMap/map ladder family.
6
+ *
7
+ * @param {ESTree.CallExpression} node - The candidate call expression.
8
+ * @returns {boolean} True when the callee is an Effect flatMap/map-family combinator.
9
+ */
10
+ function isEffectLadderCombinator(node) {
11
+ const callee = node.callee;
12
+ if (callee.type !== "MemberExpression" || callee.computed)
13
+ return false;
14
+ if (callee.object.type !== "Identifier" || callee.object.name !== "Effect")
15
+ return false;
16
+ const name = callee.property.type === "Identifier" ? callee.property.name : "";
17
+ return name === "flatMap" || name === "andThen" || name === "tap";
18
+ }
19
+ /**
20
+ * Long Effect.flatMap ladders read as callback pyramids; Effect.gen renders the
21
+ * same program as straight-line validation.
22
+ */
23
+ export const preferEffectGenForGuardLaddersRule = defineRule({
24
+ meta: {
25
+ type: "suggestion",
26
+ docs: {
27
+ description: "Suggest Effect.gen when a function chains several Effect.flatMap/andThen/tap combinators instead of reading as straight-line code.",
28
+ },
29
+ messages: {
30
+ ladder: "This function chains {{count}} Effect ladder combinators. Rewrite with `Effect.gen` + `yield*` so the guard sequence reads top-to-bottom.",
31
+ },
32
+ },
33
+ createOnce(context) {
34
+ const counts = new Map();
35
+ const reported = new Set();
36
+ const enclosingFunction = (node) => {
37
+ const ancestors = ancestorsOf(context.sourceCode, node);
38
+ for (let index = ancestors.length - 1; index >= 0; index--) {
39
+ const current = ancestors[index];
40
+ if (current.type === "Program")
41
+ break;
42
+ if (current.type === "FunctionDeclaration" ||
43
+ current.type === "FunctionExpression" ||
44
+ current.type === "ArrowFunctionExpression") {
45
+ return current;
46
+ }
47
+ }
48
+ return undefined;
49
+ };
50
+ return {
51
+ before() {
52
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
53
+ return false;
54
+ counts.clear();
55
+ reported.clear();
56
+ },
57
+ CallExpression(node) {
58
+ if (!isEffectLadderCombinator(node))
59
+ return;
60
+ const owner = enclosingFunction(node);
61
+ if (owner === undefined)
62
+ return;
63
+ const next = (counts.get(owner) ?? 0) + 1;
64
+ counts.set(owner, next);
65
+ if (next >= LADDER_THRESHOLD && !reported.has(owner)) {
66
+ reported.add(owner);
67
+ context.report({ node: owner, messageId: "ladder", data: { count: String(next) } });
68
+ }
69
+ },
70
+ };
71
+ },
72
+ });
@@ -0,0 +1,2 @@
1
+ /** Chained literal ternaries over one value re-implement `Match` without exhaustiveness checking. */
2
+ export declare const preferEffectMatchRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,74 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { ancestorsOf } from "../../shared/ancestors.js";
3
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$|\/test\//u;
4
+ const EQUALITY_OPERATORS = new Set(["==", "===", "!=", "!=="]);
5
+ /**
6
+ * Whether the expression is a literal operand (literal or brace-less template).
7
+ *
8
+ * @param {ESTree.Node} node - The candidate expression node.
9
+ * @returns {boolean} True when the node is literal-valued.
10
+ */
11
+ function isLiteral(node) {
12
+ if (node.type === "Literal")
13
+ return true;
14
+ return node.type === "TemplateLiteral" && node.expressions.length === 0;
15
+ }
16
+ /**
17
+ * The compared operand of a literal equality test, rendered to source text.
18
+ *
19
+ * @param {import("@oxlint/plugins").SourceCode} sourceCode - The rule's source-code accessor.
20
+ * @param {ESTree.Expression} test - The conditional's test expression.
21
+ * @returns {string | undefined} Source text of the non-literal side, or undefined.
22
+ */
23
+ function comparedValue(sourceCode, test) {
24
+ if (test.type !== "BinaryExpression")
25
+ return undefined;
26
+ if (!EQUALITY_OPERATORS.has(test.operator))
27
+ return undefined;
28
+ if (isLiteral(test.left))
29
+ return sourceCode.getText(test.right);
30
+ if (isLiteral(test.right))
31
+ return sourceCode.getText(test.left);
32
+ return undefined;
33
+ }
34
+ /** Chained literal ternaries over one value re-implement `Match` without exhaustiveness checking. */
35
+ export const preferEffectMatchRule = defineRule({
36
+ meta: {
37
+ type: "problem",
38
+ docs: {
39
+ description: "Prefer Match from effect for chained literal ternaries over the same value; the compiler then checks exhaustiveness instead of falling through silently.",
40
+ },
41
+ messages: {
42
+ preferMatch: "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.",
43
+ },
44
+ },
45
+ createOnce(context) {
46
+ return {
47
+ before() {
48
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
49
+ return false;
50
+ },
51
+ ConditionalExpression(node) {
52
+ const parent = ancestorsOf(context.sourceCode, node)[0];
53
+ if (parent?.type === "ConditionalExpression") {
54
+ return;
55
+ }
56
+ const compared = comparedValue(context.sourceCode, node.test);
57
+ if (compared === undefined)
58
+ return;
59
+ let alternate = node.alternate;
60
+ let literalChecks = 1;
61
+ while (alternate.type === "ConditionalExpression") {
62
+ const alternateCompared = comparedValue(context.sourceCode, alternate.test);
63
+ if (alternateCompared !== compared)
64
+ return;
65
+ literalChecks += 1;
66
+ alternate = alternate.alternate;
67
+ }
68
+ if (literalChecks > 1) {
69
+ context.report({ node, messageId: "preferMatch" });
70
+ }
71
+ },
72
+ };
73
+ },
74
+ });
@@ -0,0 +1,2 @@
1
+ /** Exported predicates should be typed P.Predicate<T> so they compose. */
2
+ export declare const preferEffectPredicateOverBooleanFunctionRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,75 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
3
+ function parameterAnnotation(parameter) {
4
+ if (parameter.type === "TSParameterProperty") {
5
+ return parameterAnnotation(parameter.parameter);
6
+ }
7
+ if (parameter.type === "RestElement") {
8
+ return parameter.typeAnnotation ?? parameterAnnotation(parameter.argument);
9
+ }
10
+ if (parameter.type === "AssignmentPattern") {
11
+ return parameter.typeAnnotation ?? parameter.left.typeAnnotation;
12
+ }
13
+ return parameter.typeAnnotation;
14
+ }
15
+ /** Exported predicates should be typed P.Predicate<T> so they compose. */
16
+ export const preferEffectPredicateOverBooleanFunctionRule = defineRule({
17
+ meta: {
18
+ type: "problem",
19
+ docs: {
20
+ description: "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.",
21
+ },
22
+ messages: {
23
+ booleanPredicateReturn: "Export this predicate as P.Predicate<{{type}}> so it composes with P.and/or/mapInput, Array.filter, and Option refinement.",
24
+ },
25
+ },
26
+ createOnce(context) {
27
+ const checkPredicate = (node) => {
28
+ if (node.returnType === null || node.returnType === undefined)
29
+ return;
30
+ const returnType = node.returnType.typeAnnotation;
31
+ if (returnType.type !== "TSBooleanKeyword")
32
+ return;
33
+ if (node.params.length !== 1)
34
+ return;
35
+ const firstParam = node.params[0];
36
+ if (firstParam === undefined)
37
+ return;
38
+ const annotation = parameterAnnotation(firstParam);
39
+ if (annotation === null || annotation === undefined)
40
+ return;
41
+ const type = annotation.typeAnnotation;
42
+ if (type.type === "TSUnknownKeyword")
43
+ return;
44
+ context.report({
45
+ node: returnType,
46
+ messageId: "booleanPredicateReturn",
47
+ data: { type: context.sourceCode.getText(type) },
48
+ });
49
+ };
50
+ return {
51
+ before() {
52
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
53
+ return false;
54
+ },
55
+ ExportNamedDeclaration(node) {
56
+ const declaration = node.declaration;
57
+ if (declaration === null)
58
+ return;
59
+ if (declaration.type === "FunctionDeclaration") {
60
+ checkPredicate(declaration);
61
+ return;
62
+ }
63
+ if (declaration.type !== "VariableDeclaration")
64
+ return;
65
+ for (const declarator of declaration.declarations) {
66
+ const init = declarator.init;
67
+ if (init === null || init === undefined || init.type !== "ArrowFunctionExpression") {
68
+ continue;
69
+ }
70
+ checkPredicate(init);
71
+ }
72
+ },
73
+ };
74
+ },
75
+ });
@@ -0,0 +1,2 @@
1
+ /** Inline chains of domain predicates guarding Options should be named Predicates. */
2
+ export declare const preferNamedGuardPredicateRule: import("@oxlint/plugins").Rule;