@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,20 @@
1
+ import type { Plugin } from "@oxlint/plugins";
2
+ /** The parts of a plugin a shared rule set is derived from. */
3
+ type RuleSetSource = Pick<Plugin, "meta" | "rules">;
4
+ /** Every rule a plugin ships, enabled at `error` under the plugin's own name.
5
+ *
6
+ * The keys assume the plugin is registered under `meta.name` (`plumb`,
7
+ * `plumb-effect`, `plumb-react`), in `jsPlugins` for Oxlint or `plugins` for
8
+ * ESLint. The result drops straight into either linter's `rules` object.
9
+ *
10
+ * @param {RuleSetSource} plugin - The plugin whose rules to enable.
11
+ * @returns {Readonly<Record<string, "error">>} Namespaced rule ids mapped to `error`.
12
+ */
13
+ export declare function recommendedRulesFor(plugin: RuleSetSource): Readonly<Record<string, "error">>;
14
+ /** Every `plumb` rule at `error`. */
15
+ export declare const plumbRecommendedRules: Readonly<Record<string, "error">>;
16
+ /** Every `plumb-effect` rule at `error`; enable only in repos that depend on `effect`. */
17
+ export declare const plumbEffectRecommendedRules: Readonly<Record<string, "error">>;
18
+ /** Every `plumb-react` rule at `error`; enable only in React repos. */
19
+ export declare const plumbReactRecommendedRules: Readonly<Record<string, "error">>;
20
+ export {};
@@ -0,0 +1,22 @@
1
+ import plumbPlugin from "../index.js";
2
+ import plumbEffectPlugin from "../effect/index.js";
3
+ import plumbReactPlugin from "../react/index.js";
4
+ /** Every rule a plugin ships, enabled at `error` under the plugin's own name.
5
+ *
6
+ * The keys assume the plugin is registered under `meta.name` (`plumb`,
7
+ * `plumb-effect`, `plumb-react`), in `jsPlugins` for Oxlint or `plugins` for
8
+ * ESLint. The result drops straight into either linter's `rules` object.
9
+ *
10
+ * @param {RuleSetSource} plugin - The plugin whose rules to enable.
11
+ * @returns {Readonly<Record<string, "error">>} Namespaced rule ids mapped to `error`.
12
+ */
13
+ export function recommendedRulesFor(plugin) {
14
+ const name = plugin.meta?.name ?? "";
15
+ return Object.fromEntries(Object.keys(plugin.rules).map((rule) => [`${name}/${rule}`, "error"]));
16
+ }
17
+ /** Every `plumb` rule at `error`. */
18
+ export const plumbRecommendedRules = recommendedRulesFor(plumbPlugin);
19
+ /** Every `plumb-effect` rule at `error`; enable only in repos that depend on `effect`. */
20
+ export const plumbEffectRecommendedRules = recommendedRulesFor(plumbEffectPlugin);
21
+ /** Every `plumb-react` rule at `error`; enable only in React repos. */
22
+ export const plumbReactRecommendedRules = recommendedRulesFor(plumbReactPlugin);
@@ -0,0 +1,3 @@
1
+ /** Opt-in Oxlint rules for Effect service and Layer architecture. */
2
+ declare const plumbEffectPlugin: import("@oxlint/plugins").Plugin;
3
+ export default plumbEffectPlugin;
@@ -0,0 +1,60 @@
1
+ import { eslintCompatPlugin } from "@oxlint/plugins";
2
+ import { guardedOpMustReturnEffectRule } from "./rules/guarded-op-must-return-effect.js";
3
+ import { guardedOpMustReturnOptionRule } from "./rules/guarded-op-must-return-option.js";
4
+ import { noDecodeUnknownOptionRule } from "./rules/no-decode-unknown-option.js";
5
+ import { noManualFieldGuardsRule } from "./rules/no-manual-field-guards.js";
6
+ import { noUnguardedJsonParseRule } from "./rules/no-unguarded-json-parse.js";
7
+ import { noSchemaClassModelingRule } from "./rules/no-schema-class-modeling.js";
8
+ import { noServiceConstructorImportsRule } from "./rules/no-service-constructor-imports.js";
9
+ import { optionCoreNeedsEffectPublicRule } from "./rules/option-core-needs-effect-public.js";
10
+ import { preferDieForPreconditionDefectsRule } from "./rules/prefer-die-for-precondition-defects.js";
11
+ import { preferEffectGenForGuardLaddersRule } from "./rules/prefer-effect-gen-for-guard-ladders.js";
12
+ import { preferEffectPredicateOverBooleanFunctionRule } from "./rules/prefer-effect-predicate-over-boolean-function.js";
13
+ import { preferNamedGuardPredicateRule } from "./rules/prefer-named-guard-predicate.js";
14
+ import { preferOrderingMatchRule } from "./rules/prefer-ordering-match.js";
15
+ import { preferOptionPipelineRule } from "./rules/prefer-option-pipeline.js";
16
+ import { preferTaggedEnumRule } from "./rules/prefer-tagged-enum.js";
17
+ import { requireSchemaTypeDerivationRule } from "./rules/require-schema-type-derivation.js";
18
+ import { noDirectFetchRule } from "./rules/no-direct-fetch.js";
19
+ import { noDirectBrowserStorageRule } from "./rules/no-direct-browser-storage.js";
20
+ import { noTryCatchRule } from "./rules/no-try-catch.js";
21
+ import { noSilentErrorSwallowRule } from "./rules/no-silent-error-swallow.js";
22
+ import { preferEffectMatchRule } from "./rules/prefer-effect-match.js";
23
+ import { noNestedLayerProvideRule } from "./rules/no-nested-layer-provide.js";
24
+ import { noCascadingLayerProvideRule } from "./rules/no-cascading-layer-provide.js";
25
+ import { noStaticEffectServiceForwardersRule } from "./rules/no-static-effect-service-forwarders.js";
26
+ import { noRawErrorForwardingRule } from "./rules/no-raw-error-forwarding.js";
27
+ import { noNullishDefaultOnPartialInputRule } from "./rules/no-nullish-default-on-partial-input.js";
28
+ /** Opt-in Oxlint rules for Effect service and Layer architecture. */
29
+ const plumbEffectPlugin = eslintCompatPlugin({
30
+ meta: { name: "plumb-effect" },
31
+ rules: {
32
+ "guarded-op-must-return-effect": guardedOpMustReturnEffectRule,
33
+ "guarded-op-must-return-option": guardedOpMustReturnOptionRule,
34
+ "no-decode-unknown-option": noDecodeUnknownOptionRule,
35
+ "no-manual-field-guards": noManualFieldGuardsRule,
36
+ "no-unguarded-json-parse": noUnguardedJsonParseRule,
37
+ "option-core-needs-effect-public": optionCoreNeedsEffectPublicRule,
38
+ "no-schema-class-modeling": noSchemaClassModelingRule,
39
+ "no-service-constructor-imports": noServiceConstructorImportsRule,
40
+ "prefer-die-for-precondition-defects": preferDieForPreconditionDefectsRule,
41
+ "prefer-effect-gen-for-guard-ladders": preferEffectGenForGuardLaddersRule,
42
+ "prefer-effect-predicate-over-boolean-function": preferEffectPredicateOverBooleanFunctionRule,
43
+ "prefer-named-guard-predicate": preferNamedGuardPredicateRule,
44
+ "prefer-option-pipeline": preferOptionPipelineRule,
45
+ "prefer-ordering-match": preferOrderingMatchRule,
46
+ "prefer-tagged-enum": preferTaggedEnumRule,
47
+ "require-schema-type-derivation": requireSchemaTypeDerivationRule,
48
+ "no-direct-fetch": noDirectFetchRule,
49
+ "no-direct-browser-storage": noDirectBrowserStorageRule,
50
+ "no-try-catch": noTryCatchRule,
51
+ "no-silent-error-swallow": noSilentErrorSwallowRule,
52
+ "prefer-effect-match": preferEffectMatchRule,
53
+ "no-nested-layer-provide": noNestedLayerProvideRule,
54
+ "no-cascading-layer-provide": noCascadingLayerProvideRule,
55
+ "no-static-effect-service-forwarders": noStaticEffectServiceForwardersRule,
56
+ "no-raw-error-forwarding": noRawErrorForwardingRule,
57
+ "no-nullish-default-on-partial-input": noNullishDefaultOnPartialInputRule,
58
+ },
59
+ });
60
+ export default plumbEffectPlugin;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Guarded operations must surface failure reasons as tagged MoneyError values
3
+ * through the Effect error channel, not as bare Option.None which conflates
4
+ * every possible why into one silent absence.
5
+ */
6
+ export declare const guardedOpMustReturnEffectRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,235 @@
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
+ /** Whether the member chain ends in the Option namespace, e.g. `Option` or `O`.
5
+ *
6
+ * @param {ESTree.Expression | ESTree.Super} node - The callee object to inspect.
7
+ * @returns {boolean} True when the object resolves to the Option namespace.
8
+ */
9
+ function isOptionObject(node) {
10
+ if (node.type === "Identifier")
11
+ return node.name === "Option";
12
+ if (node.type === "MemberExpression" && !node.computed && node.property.type === "Identifier") {
13
+ return node.property.name === "Option";
14
+ }
15
+ return false;
16
+ }
17
+ /** The name of the function whose body contains this node, if determinable.
18
+ *
19
+ * @param {SourceCode} sourceCode - The rule's source-code accessor.
20
+ * @param {ESTree.Node} node - The node whose enclosing function is sought.
21
+ * @returns {string | null} The enclosing function's name, or null.
22
+ */
23
+ function enclosingFunctionName(sourceCode, node) {
24
+ const chain = ancestorsOf(sourceCode, node);
25
+ for (let index = chain.length - 1; index >= 0; index--) {
26
+ const current = chain[index];
27
+ if (current.type === "FunctionDeclaration" && current.id !== null)
28
+ return current.id.name;
29
+ if ((current.type === "FunctionExpression" || current.type === "ArrowFunctionExpression") &&
30
+ node !== current) {
31
+ const name = current.type === "FunctionExpression" && current.id !== null
32
+ ? current.id.name
33
+ : variableDeclaratorName(sourceCode, current);
34
+ if (name !== null)
35
+ return name;
36
+ }
37
+ }
38
+ return null;
39
+ }
40
+ /** The declared name of the variable a function expression initialises, if any.
41
+ *
42
+ * @param {SourceCode} sourceCode - The rule's source-code accessor.
43
+ * @param {ESTree.Node} node - The function expression node.
44
+ * @returns {string | null} The initialising declarator's name, or null.
45
+ */
46
+ function variableDeclaratorName(sourceCode, node) {
47
+ const chain = ancestorsOf(sourceCode, node);
48
+ for (let index = chain.length - 1; index >= 0; index--) {
49
+ const current = chain[index];
50
+ if (current.type === "Program")
51
+ break;
52
+ if (current.type === "VariableDeclarator" && current.id.type === "Identifier")
53
+ return current.id.name;
54
+ }
55
+ return null;
56
+ }
57
+ /** The doctrine binds public APIs: walk up to see if this node is exported.
58
+ *
59
+ * @param {SourceCode} sourceCode - The rule's source-code accessor.
60
+ * @param {ESTree.Node} node - The node to test for export ancestry.
61
+ * @returns {boolean} True when an export declaration encloses the node.
62
+ */
63
+ function hasExportAncestor(sourceCode, node) {
64
+ const chain = ancestorsOf(sourceCode, node);
65
+ for (let index = chain.length - 1; index >= 0; index--) {
66
+ const current = chain[index];
67
+ if (current.type === "ExportNamedDeclaration" || current.type === "ExportDefaultDeclaration")
68
+ return true;
69
+ if (current.type === "Program")
70
+ return false;
71
+ }
72
+ return false;
73
+ }
74
+ /** A return-type annotation naming Option<T>, e.g. `Option.Option<Account>`.
75
+ *
76
+ * @param {ESTree.TSType} type - The type node to inspect.
77
+ * @returns {string | null} The Option spelling used, or null when not an Option reference.
78
+ */
79
+ function optionTypeReference(type) {
80
+ if (type.type !== "TSTypeReference")
81
+ return null;
82
+ const name = type.typeName;
83
+ if (name.type === "Identifier" && name.name === "Option")
84
+ return "Option";
85
+ if (name.type === "TSQualifiedName" &&
86
+ name.right.type === "Identifier" &&
87
+ name.right.name === "Option") {
88
+ return "Option.Option";
89
+ }
90
+ return null;
91
+ }
92
+ /**
93
+ * Guarded operations must surface failure reasons as tagged MoneyError values
94
+ * through the Effect error channel, not as bare Option.None which conflates
95
+ * every possible why into one silent absence.
96
+ */
97
+ export const guardedOpMustReturnEffectRule = defineRule({
98
+ meta: {
99
+ type: "problem",
100
+ docs: {
101
+ description: "Require guarded operations to fail with typed MoneyError reasons via Effect/Either instead of returning bare Option values.",
102
+ },
103
+ messages: {
104
+ optionReturn: "`{{found}}` hides why the operation failed. Return `Effect.Effect<T, MoneyError>` (or `Either<T, MoneyError>` in sync cores) with Schema.TaggedError reasons so callers can match Overflow vs InvalidInput vs ZeroDivisor. Options buried in tuples, records or arrays hide it just as well.",
105
+ bareNone: "`Option.none()` here discards the reason for failure. Fail with a tagged MoneyError reason instead, or keep the Option strictly internal while a converted public API owns the error channel.",
106
+ },
107
+ },
108
+ createOnce(context) {
109
+ return {
110
+ before() {
111
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
112
+ return false;
113
+ },
114
+ ReturnStatement(node) {
115
+ if (!hasExportAncestor(context.sourceCode, node))
116
+ return;
117
+ if (enclosingFunctionName(context.sourceCode, node)?.endsWith("Option"))
118
+ return;
119
+ const argument = node.argument;
120
+ if (argument === null || argument === undefined)
121
+ return;
122
+ let call = argument;
123
+ while (call.type === "ParenthesizedExpression")
124
+ call = call.expression;
125
+ if (call.type !== "CallExpression")
126
+ return;
127
+ if (call.callee.type === "MemberExpression" &&
128
+ call.callee.property.type === "Identifier" &&
129
+ call.callee.property.name === "none" &&
130
+ isOptionObject(call.callee.object)) {
131
+ context.report({ node, messageId: "bareNone" });
132
+ }
133
+ },
134
+ ArrowFunctionExpression(node) {
135
+ if (!hasExportAncestor(context.sourceCode, node))
136
+ return;
137
+ const parentId = variableDeclaratorName(context.sourceCode, node);
138
+ if (parentId !== null && parentId.endsWith("Option"))
139
+ return;
140
+ const annotation = node.returnType?.typeAnnotation;
141
+ if (annotation === undefined)
142
+ return;
143
+ const found = optionInReturnType(annotation);
144
+ if (found !== null) {
145
+ context.report({ node: node.returnType ?? node, messageId: "optionReturn", data: { found } });
146
+ }
147
+ },
148
+ FunctionDeclaration(node) {
149
+ if (!hasExportAncestor(context.sourceCode, node))
150
+ return;
151
+ checkFunctionReturn(context, node, node.id?.name ?? null);
152
+ },
153
+ FunctionExpression(node) {
154
+ if (!hasExportAncestor(context.sourceCode, node))
155
+ return;
156
+ checkFunctionReturn(context, node, node.id?.name ?? variableDeclaratorName(context.sourceCode, node));
157
+ },
158
+ };
159
+ },
160
+ });
161
+ function checkFunctionReturn(context, node, idName) {
162
+ if (idName !== null && idName.endsWith("Option"))
163
+ return;
164
+ const annotation = node.returnType?.typeAnnotation;
165
+ if (annotation === undefined)
166
+ return;
167
+ const found = optionInReturnType(annotation);
168
+ if (found !== null) {
169
+ context.report({ node: node.returnType ?? node, messageId: "optionReturn", data: { found } });
170
+ }
171
+ }
172
+ /** Search a type node for an embedded Option reference (tuples, arrays, members).
173
+ *
174
+ * @param {ESTree.TSType} type - The type node to search.
175
+ * @returns {string | null} The first embedded Option spelling, or null when none.
176
+ */
177
+ function findOptionType(type) {
178
+ const direct = optionTypeReference(type);
179
+ if (direct !== null)
180
+ return direct;
181
+ switch (type.type) {
182
+ case "TSTupleType": {
183
+ const render = (element) => {
184
+ if ("elementType" in element)
185
+ return render(element.elementType);
186
+ if (element.type === "TSOptionalType" || element.type === "TSRestType") {
187
+ return findOptionType(element.typeAnnotation);
188
+ }
189
+ return findOptionType(element);
190
+ };
191
+ for (const element of type.elementTypes) {
192
+ const found = render(element);
193
+ if (found !== null)
194
+ return found;
195
+ }
196
+ return null;
197
+ }
198
+ case "TSTypeOperator":
199
+ return findOptionType(type.typeAnnotation);
200
+ case "TSArrayType":
201
+ return findOptionType(type.elementType);
202
+ case "TSTypeLiteral":
203
+ for (const member of type.members) {
204
+ if (member.type !== "TSPropertySignature")
205
+ continue;
206
+ const annotation = member.typeAnnotation?.typeAnnotation;
207
+ if (annotation === undefined || annotation === null)
208
+ continue;
209
+ const found = findOptionType(annotation);
210
+ if (found !== null)
211
+ return found;
212
+ }
213
+ return null;
214
+ default:
215
+ return null;
216
+ }
217
+ }
218
+ /** A return-type annotation hiding an Option anywhere: unions, tuples, arrays, members.
219
+ *
220
+ * @param {ESTree.TSType} annotation - The return-type annotation to search.
221
+ * @returns {string | null} The Option spelling found, or null when none.
222
+ */
223
+ function optionInReturnType(annotation) {
224
+ let current = annotation;
225
+ while (current.type === "TSParenthesizedType")
226
+ current = current.typeAnnotation;
227
+ if (current.type === "TSUnionType") {
228
+ for (const member of current.types) {
229
+ const found = optionTypeReference(member);
230
+ if (found !== null)
231
+ return found;
232
+ }
233
+ }
234
+ return findOptionType(current);
235
+ }
@@ -0,0 +1,2 @@
1
+ /** Guarded operations must surface absence as Option, not null/undefined unions or crashes. */
2
+ export declare const guardedOpMustReturnOptionRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,88 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { ancestorsOf } from "../../shared/ancestors.js";
3
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
4
+ function isNullableKeyword(type) {
5
+ return type.type === "TSNullKeyword" || type.type === "TSUndefinedKeyword";
6
+ }
7
+ /**
8
+ * Returns whether a union pairs a nullable member with at least one real
9
+ * value type (T | null/undefined, not void | undefined).
10
+ *
11
+ * @param {ESTree.TSUnionType} union - The union annotation to inspect.
12
+ * @returns {boolean} True when the union mixes null/undefined with value types.
13
+ */
14
+ function nullableWithValue(union) {
15
+ let nullable = false;
16
+ let value = false;
17
+ for (const member of union.types) {
18
+ if (isNullableKeyword(member)) {
19
+ nullable = true;
20
+ }
21
+ else if (member.type !== "TSVoidKeyword" && member.type !== "TSNeverKeyword") {
22
+ value = true;
23
+ }
24
+ }
25
+ return nullable && value;
26
+ }
27
+ function asUnion(type) {
28
+ if (type.type === "TSParenthesizedType")
29
+ return asUnion(type.typeAnnotation);
30
+ return type.type === "TSUnionType" ? type : null;
31
+ }
32
+ /** Guarded operations must surface absence as Option, not null/undefined unions or crashes. */
33
+ export const guardedOpMustReturnOptionRule = defineRule({
34
+ meta: {
35
+ type: "problem",
36
+ docs: {
37
+ description: "Disallow returning T | null/undefined from guarded operations and getOrThrow escapes; express absence as Option<T> so callers compose with Option.zip/flatMap/filter.",
38
+ },
39
+ messages: {
40
+ nullableReturn: "This function returns `{{type}}`, conflating absence with a value. Return Option<{{value}}> and express absence as Option.none().",
41
+ optionEscape: "`getOrThrow` turns absence into a runtime crash. Keep the Option in the type and handle None, or parse to a refined value so the empty branch can't exist.",
42
+ },
43
+ },
44
+ createOnce(context) {
45
+ const checkReturnType = (node) => {
46
+ const annotation = node.returnType;
47
+ if (annotation === null || annotation === undefined)
48
+ return;
49
+ const type = annotation.typeAnnotation;
50
+ const union = asUnion(type);
51
+ if (union === null || !nullableWithValue(union))
52
+ return;
53
+ const value = union.types
54
+ .filter((member) => !isNullableKeyword(member) && member.type !== "TSVoidKeyword")
55
+ .map((member) => context.sourceCode.getText(member))
56
+ .join(" | ");
57
+ context.report({
58
+ node: type,
59
+ messageId: "nullableReturn",
60
+ data: { type: context.sourceCode.getText(type), value },
61
+ });
62
+ };
63
+ return {
64
+ before() {
65
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
66
+ return false;
67
+ },
68
+ ArrowFunctionExpression: checkReturnType,
69
+ FunctionDeclaration: checkReturnType,
70
+ FunctionExpression: checkReturnType,
71
+ MemberExpression(node) {
72
+ if (!node.computed &&
73
+ node.property.type === "Identifier" &&
74
+ node.property.name === "getOrThrow") {
75
+ context.report({ node, messageId: "optionEscape" });
76
+ }
77
+ },
78
+ Identifier(node) {
79
+ if (node.name !== "getOrThrow")
80
+ return;
81
+ const parent = (ancestorsOf(context.sourceCode, node)).at(-1);
82
+ if (parent?.type === "MemberExpression" && parent.property === node)
83
+ return;
84
+ context.report({ node, messageId: "optionEscape" });
85
+ },
86
+ };
87
+ },
88
+ });
@@ -0,0 +1,6 @@
1
+ /** Multiple provision stages in one pipe entangle dependency tiers; combine independent layers or name each stage.
2
+ *
3
+ * Import tracking covers local names bound to the `Layer` export of
4
+ * "effect"; re-exports are not tracked.
5
+ */
6
+ export declare const noCascadingLayerProvideRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,73 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { isString } from "../../shared/structural.js";
3
+ const PROVISION_METHODS = new Set(["provide", "provideMerge"]);
4
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$|\/test\//u;
5
+ /** Multiple provision stages in one pipe entangle dependency tiers; combine independent layers or name each stage.
6
+ *
7
+ * Import tracking covers local names bound to the `Layer` export of
8
+ * "effect"; re-exports are not tracked.
9
+ */
10
+ export const noCascadingLayerProvideRule = defineRule({
11
+ meta: {
12
+ type: "problem",
13
+ docs: {
14
+ description: "Disallow multiple Layer.provide/provideMerge stages in one pipe; combine independent dependencies in one Layer.provide([...]) and extract intentional dependency stages as named layers.",
15
+ },
16
+ messages: {
17
+ cascadingProvide: "Multiple `Layer.provide` stages run in this pipe, entangling dependency tiers. Combine independent dependencies into one `Layer.provide([a, b])`; when a layer depends on another layer, extract that configured layer into a named value before providing it.",
18
+ },
19
+ },
20
+ createOnce(context) {
21
+ const layerNames = new Set();
22
+ return {
23
+ before() {
24
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
25
+ return false;
26
+ },
27
+ ImportDeclaration(node) {
28
+ if (node.source.value !== "effect")
29
+ return;
30
+ for (const specifier of node.specifiers) {
31
+ if (specifier.type === "ImportNamespaceSpecifier" || specifier.type === "ImportDefaultSpecifier") {
32
+ if (specifier.local.name === "Layer")
33
+ layerNames.add("Layer");
34
+ continue;
35
+ }
36
+ if (specifier.type !== "ImportSpecifier")
37
+ continue;
38
+ const importedName = specifier.imported.type === "Identifier"
39
+ ? specifier.imported.name
40
+ : isString(specifier.imported.value)
41
+ ? specifier.imported.value
42
+ : undefined;
43
+ if (importedName !== "Layer")
44
+ continue;
45
+ layerNames.add(specifier.local.name);
46
+ }
47
+ },
48
+ CallExpression(node) {
49
+ const callee = node.callee;
50
+ if (callee.type !== "MemberExpression" ||
51
+ callee.computed ||
52
+ callee.property.type !== "Identifier" ||
53
+ callee.property.name !== "pipe") {
54
+ return;
55
+ }
56
+ let stages = 0;
57
+ for (const argument of node.arguments) {
58
+ if (argument.type === "CallExpression" &&
59
+ argument.callee.type === "MemberExpression" &&
60
+ !argument.callee.computed &&
61
+ argument.callee.object.type === "Identifier" &&
62
+ layerNames.has(argument.callee.object.name) &&
63
+ argument.callee.property.type === "Identifier" &&
64
+ PROVISION_METHODS.has(argument.callee.property.name))
65
+ stages += 1;
66
+ }
67
+ if (stages < 2)
68
+ return;
69
+ context.report({ node, messageId: "cascadingProvide" });
70
+ },
71
+ };
72
+ },
73
+ });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * decodeUnknownOption collapses every schema mismatch into None, discarding
3
+ * the issue tree that explains why decoding failed. Prefer adapters that keep
4
+ * the issues: SchemaParser.decodeUnknownResult for sync cores,
5
+ * decodeUnknownEffect on the Effect channel.
6
+ */
7
+ export declare const noDecodeUnknownOptionRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,34 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
3
+ /**
4
+ * decodeUnknownOption collapses every schema mismatch into None, discarding
5
+ * the issue tree that explains why decoding failed. Prefer adapters that keep
6
+ * the issues: SchemaParser.decodeUnknownResult for sync cores,
7
+ * decodeUnknownEffect on the Effect channel.
8
+ */
9
+ export const noDecodeUnknownOptionRule = defineRule({
10
+ meta: {
11
+ type: "problem",
12
+ docs: {
13
+ description: "Disallow Schema.decodeUnknownOption outside tests: it discards mismatch details. Return the schema issues as typed failure evidence instead.",
14
+ },
15
+ messages: {
16
+ noDecodeUnknownOption: "`decodeUnknownOption` intentionally discards mismatch details, so callers cannot learn why decoding failed. Use `SchemaParser.decodeUnknownResult(schema)` (sync cores) or `SchemaParser.decodeUnknownEffect(schema)` (Effect channel) and fold the issue into your tagged error's evidence.",
17
+ },
18
+ },
19
+ createOnce(context) {
20
+ return {
21
+ before() {
22
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
23
+ return false;
24
+ },
25
+ MemberExpression(node) {
26
+ if (!node.computed &&
27
+ node.property.type === "Identifier" &&
28
+ node.property.name === "decodeUnknownOption") {
29
+ context.report({ node, messageId: "noDecodeUnknownOption" });
30
+ }
31
+ },
32
+ };
33
+ },
34
+ });
@@ -0,0 +1,2 @@
1
+ /** Browser storage globals hide I/O from the Effect runtime; persist through KeyValueStore or an injected store. */
2
+ export declare const noDirectBrowserStorageRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,88 @@
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
+ const BANNED_STORAGE = new Set(["indexedDB", "localStorage", "sessionStorage"]);
6
+ /**
7
+ * The banned-storage global named by an identifier, if any.
8
+ *
9
+ * @param {ESTree.Node} node - The identifier node to test.
10
+ * @returns {string | null} The banned storage name, or null.
11
+ */
12
+ function storageName(node) {
13
+ if (node.type !== "Identifier")
14
+ return null;
15
+ return BANNED_STORAGE.has(node.name) ? node.name : null;
16
+ }
17
+ /** Browser storage globals hide I/O from the Effect runtime; persist through KeyValueStore or an injected store. */
18
+ export const noDirectBrowserStorageRule = defineRule({
19
+ meta: {
20
+ type: "problem",
21
+ docs: {
22
+ description: "Disallow direct browser storage globals (indexedDB, localStorage, sessionStorage); persist through Effect's KeyValueStore/IndexedDb modules or an injected storage service.",
23
+ },
24
+ messages: {
25
+ directStorage: "`{{name}}` is reached directly, hiding I/O from the Effect runtime. Persist through Effect's KeyValueStore/IndexedDb layer or an injected storage service so access stays testable and swappable.",
26
+ },
27
+ },
28
+ createOnce(context) {
29
+ const reportStorage = (node, name) => {
30
+ context.report({ node, messageId: "directStorage", data: { name } });
31
+ };
32
+ return {
33
+ before() {
34
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
35
+ return false;
36
+ },
37
+ Identifier(node) {
38
+ const name = storageName(node);
39
+ if (name === null)
40
+ return;
41
+ const chain = ancestorsOf(context.sourceCode, node);
42
+ const parent = chain[0];
43
+ const grandparent = chain[1];
44
+ if (parent === undefined)
45
+ return;
46
+ if (parent.type === "MemberExpression") {
47
+ return;
48
+ }
49
+ if (parent.type === "Property") {
50
+ const containerType = grandparent === undefined ? "" : grandparent.type;
51
+ if (parent.key === node && parent.value !== node && containerType !== "ObjectPattern") {
52
+ return;
53
+ }
54
+ }
55
+ if (parent.type === "ImportSpecifier") {
56
+ if (parent.imported === node && parent.local !== node) {
57
+ return;
58
+ }
59
+ }
60
+ reportStorage(node, name);
61
+ },
62
+ MemberExpression(node) {
63
+ const direct = storageName(node.object);
64
+ if (direct !== null) {
65
+ reportStorage(node, direct);
66
+ return;
67
+ }
68
+ if (node.object.type !== "Identifier")
69
+ return;
70
+ const objectName = node.object.name;
71
+ if (objectName !== "globalThis" && objectName !== "window")
72
+ return;
73
+ let propertyName;
74
+ if (node.computed) {
75
+ if (node.property.type === "Literal" && isString(node.property.value)) {
76
+ propertyName = node.property.value;
77
+ }
78
+ }
79
+ else if (node.property.type === "Identifier") {
80
+ propertyName = node.property.name;
81
+ }
82
+ if (propertyName !== undefined && BANNED_STORAGE.has(propertyName)) {
83
+ reportStorage(node, propertyName);
84
+ }
85
+ },
86
+ };
87
+ },
88
+ });