@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,419 @@
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?$/u;
5
+ const MESSAGE_BY_KIND = {
6
+ "effect-function": "singleUseEffectFunction",
7
+ "effect-program": "singleUseEffectProgram",
8
+ function: "singleUseFunction",
9
+ type: "singleUseType",
10
+ };
11
+ function isPascalCase(name) {
12
+ return /^[A-Z]/u.test(name);
13
+ }
14
+ /** Computed or plain property name on a member expression.
15
+ *
16
+ * @param {ESTree.Node} member - The member expression node.
17
+ * @returns {string | null} The property name, or null when unavailable.
18
+ */
19
+ function memberName(member) {
20
+ if (member.type !== "MemberExpression")
21
+ return null;
22
+ if (!member.computed) {
23
+ return member.property.type === "Identifier" ? member.property.name : null;
24
+ }
25
+ if (member.property.type === "Literal" && isString(member.property.value)) {
26
+ return member.property.value;
27
+ }
28
+ return null;
29
+ }
30
+ /** Whether the call resolves to Effect.<method> (one invocation wrapper allowed for Effect.fn("N")(...)).
31
+ *
32
+ * @param {{ call: ESTree.Node; method: string }} payload - The candidate call and Effect method name.
33
+ * @returns {boolean} True when the call targets Effect.<method>.
34
+ */
35
+ function isEffectMethodCall(payload) {
36
+ let callee = payload.call;
37
+ if (callee.type === "CallExpression")
38
+ callee = callee.callee;
39
+ if (callee.type !== "MemberExpression")
40
+ return false;
41
+ if (callee.object.type !== "Identifier")
42
+ return false;
43
+ return callee.object.name === "Effect" && memberName(callee) === payload.method;
44
+ }
45
+ /**
46
+ * Classify an initializer expression by the kind of private candidate it
47
+ * declares: plain function values, Effect.fn-style services, or Effect.gen
48
+ * programs.
49
+ *
50
+ * @param {ESTree.Node} init - The initializer expression of a top-level declarator.
51
+ * @returns {CandidateKind | null} The candidate kind, or null when not a candidate.
52
+ */
53
+ function effectInitializerKind(init) {
54
+ const kind = init.type;
55
+ if (kind === "ArrowFunctionExpression" || kind === "FunctionExpression") {
56
+ return "function";
57
+ }
58
+ if (kind !== "CallExpression")
59
+ return null;
60
+ if (isEffectMethodCall({ call: init, method: "fn" }) ||
61
+ isEffectMethodCall({ call: init, method: "fnUntraced" })) {
62
+ return "effect-function";
63
+ }
64
+ if (isEffectMethodCall({ call: init, method: "gen" }))
65
+ return "effect-program";
66
+ return null;
67
+ }
68
+ function addDeclaredName(declaration, names) {
69
+ if (declaration === null)
70
+ return;
71
+ if (declaration.type === "FunctionDeclaration" ||
72
+ declaration.type === "TSTypeAliasDeclaration" ||
73
+ declaration.type === "TSInterfaceDeclaration") {
74
+ if (declaration.id != null)
75
+ names.add(declaration.id.name);
76
+ return;
77
+ }
78
+ if (declaration.type === "VariableDeclaration") {
79
+ for (const declarator of declaration.declarations) {
80
+ if (declarator.id.type === "Identifier")
81
+ names.add(declarator.id.name);
82
+ }
83
+ }
84
+ }
85
+ /** Re-exported or default-exported names are public regardless of local privacy.
86
+ *
87
+ * @param {ESTree.Program} program - Root AST node of the file under lint.
88
+ * @returns {Set<string>} Names treated as public exports.
89
+ */
90
+ function exportedNames(program) {
91
+ const names = new Set();
92
+ for (const statement of program.body) {
93
+ if (statement.type === "ExportDefaultDeclaration") {
94
+ addDeclaredName(statement.declaration ?? null, names);
95
+ }
96
+ if (statement.type === "ExportNamedDeclaration") {
97
+ addDeclaredName(statement.declaration ?? null, names);
98
+ if (statement.source === null || statement.source === undefined) {
99
+ for (const specifier of statement.specifiers) {
100
+ if (specifier.local !== undefined && specifier.local.type === "Identifier") {
101
+ names.add(specifier.local.name);
102
+ }
103
+ }
104
+ }
105
+ }
106
+ if (statement.type === "TSExportAssignment") {
107
+ if (statement.expression.type === "Identifier") {
108
+ names.add(statement.expression.name);
109
+ }
110
+ }
111
+ }
112
+ return names;
113
+ }
114
+ /** Reads inside type positions (: T, as T, generics) are not runtime reads.
115
+ *
116
+ * @param {SourceCode} sourceCode - The rule's source-code accessor.
117
+ * @param {ESTree.Node} identifier - The identifier reference being counted.
118
+ * @returns {boolean} True when the read sits in a type position.
119
+ */
120
+ function hasTypeAncestor(sourceCode, identifier) {
121
+ for (const current of ancestorsOf(sourceCode, identifier)) {
122
+ const kind = current.type;
123
+ if (kind.startsWith("TS"))
124
+ return true;
125
+ if (kind === "Program" ||
126
+ kind === "BlockStatement" ||
127
+ kind === "ExpressionStatement") {
128
+ return false;
129
+ }
130
+ }
131
+ return false;
132
+ }
133
+ /** Reads inside re-export positions do not count toward private usage.
134
+ *
135
+ * @param {SourceCode} sourceCode - The rule's source-code accessor.
136
+ * @param {ESTree.Node} identifier - The identifier reference being counted.
137
+ * @returns {boolean} True when the read sits in an export position.
138
+ */
139
+ function hasExportAncestor(sourceCode, identifier) {
140
+ for (const current of ancestorsOf(sourceCode, identifier)) {
141
+ const kind = current.type;
142
+ if (kind === "ExportDefaultDeclaration" ||
143
+ kind === "ExportSpecifier" ||
144
+ kind === "TSExportAssignment") {
145
+ return true;
146
+ }
147
+ if (kind === "Program" || kind === "BlockStatement")
148
+ return false;
149
+ }
150
+ return false;
151
+ }
152
+ /**
153
+ * Runtime reads of a private top-level binding: reads outside type positions
154
+ * and re-export positions.
155
+ *
156
+ * @param {{ sourceCode: SourceCode; variable: DeclaredVariable }} payload - The declared variable to count.
157
+ * @returns {number} Number of qualifying reads.
158
+ */
159
+ function runtimeReadCount(payload) {
160
+ return payload.variable.references.filter((reference) => reference.isRead() &&
161
+ !hasTypeAncestor(payload.sourceCode, reference.identifier) &&
162
+ !hasExportAncestor(payload.sourceCode, reference.identifier)).length;
163
+ }
164
+ /**
165
+ * Type-position reads of a private top-level type alias or interface.
166
+ *
167
+ * @param {{ sourceCode: SourceCode; variable: DeclaredVariable }} payload - The declared type to count.
168
+ * @returns {number} Number of qualifying reads.
169
+ */
170
+ function typeReadCount(payload) {
171
+ return payload.variable.references.filter((reference) => reference.isRead() &&
172
+ hasTypeAncestor(payload.sourceCode, reference.identifier) &&
173
+ !hasExportAncestor(payload.sourceCode, reference.identifier)).length;
174
+ }
175
+ /**
176
+ * Usage count for a candidate, using the read model appropriate to its kind.
177
+ *
178
+ * @param {{ sourceCode: SourceCode; candidate: Candidate }} payload - The candidate to count.
179
+ * @returns {number} The usage count.
180
+ */
181
+ function useCount(payload) {
182
+ return payload.candidate.kind === "type"
183
+ ? typeReadCount({ sourceCode: payload.sourceCode, variable: payload.candidate.variable })
184
+ : runtimeReadCount({ sourceCode: payload.sourceCode, variable: payload.candidate.variable });
185
+ }
186
+ /**
187
+ * The declared-variable record matching a name among a node's declarations.
188
+ *
189
+ * @param {{ sourceCode: SourceCode; node: ESTree.Node; name: string }} payload - Lookup inputs.
190
+ * @returns {DeclaredVariable | undefined} The matching record, if any.
191
+ * For a VariableDeclarator the binding lives on its parent VariableDeclaration, so the declarator is unwrapped first.
192
+ */
193
+ function declaredVariablesOf(payload) {
194
+ const node = payload.node.type === "VariableDeclarator"
195
+ ? (ancestorsOf(payload.sourceCode, payload.node).find((ancestor) => ancestor.type === "VariableDeclaration") ?? payload.node)
196
+ : payload.node;
197
+ return payload.sourceCode.getDeclaredVariables(node).find((variable) => variable.name === payload.name);
198
+ }
199
+ /** Extract the handler function nested inside an Effect initializer (Effect.fn / Effect.gen).
200
+ *
201
+ * @param {ESTree.Node | null | undefined} init - The candidate's initializer expression.
202
+ * @returns {ESTree.Node | null} The handler function node, or null when absent.
203
+ */
204
+ function effectHandler(init) {
205
+ if (init === null || init === undefined || init.type !== "CallExpression")
206
+ return null;
207
+ let handler = null;
208
+ for (const arg of init.arguments) {
209
+ if (arg.type === "FunctionExpression" ||
210
+ arg.type === "ArrowFunctionExpression" ||
211
+ arg.type === "FunctionDeclaration") {
212
+ handler = arg;
213
+ }
214
+ }
215
+ return handler;
216
+ }
217
+ /** Simple identifier parameter names, or null when any parameter is a pattern.
218
+ *
219
+ * @param {ESTree.Node} fn - The function-like node to inspect.
220
+ * @returns {Set<string> | null} The parameter names, or null for non-functions/patterns.
221
+ */
222
+ function paramNames(fn) {
223
+ if (fn.type !== "FunctionDeclaration" &&
224
+ fn.type !== "FunctionExpression" &&
225
+ fn.type !== "ArrowFunctionExpression") {
226
+ return null;
227
+ }
228
+ const names = new Set();
229
+ for (const param of fn.params) {
230
+ if (param.type !== "Identifier")
231
+ return null;
232
+ names.add(param.name);
233
+ }
234
+ return names;
235
+ }
236
+ /**
237
+ * Whether a function is a pure alias: it returns a single call that forwards
238
+ * each of its parameters verbatim (a generator may delegate-yield such a call).
239
+ * Anything else raises the level of abstraction and earns its name.
240
+ *
241
+ * @param {ESTree.Node} fn - The function-like node to inspect.
242
+ * @returns {boolean} True when the function is dead indirection.
243
+ */
244
+ export function isTrivialForwarder(fn) {
245
+ if (fn.type !== "FunctionDeclaration" &&
246
+ fn.type !== "FunctionExpression" &&
247
+ fn.type !== "ArrowFunctionExpression") {
248
+ return false;
249
+ }
250
+ const names = paramNames(fn);
251
+ if (names === null || names.size === 0)
252
+ return false;
253
+ let call = null;
254
+ if (fn.body !== null && fn.body.type === "BlockStatement") {
255
+ const statements = fn.body.body;
256
+ const statement = statements[0];
257
+ if (statement !== undefined && statement.type === "ReturnStatement") {
258
+ const argument = statement.argument;
259
+ if (argument !== null && argument !== undefined && argument.type === "CallExpression") {
260
+ call = argument;
261
+ }
262
+ else if (argument !== null &&
263
+ argument !== undefined &&
264
+ argument.type === "YieldExpression" &&
265
+ argument.delegate === true &&
266
+ argument.argument !== null &&
267
+ argument.argument !== undefined &&
268
+ argument.argument.type === "CallExpression") {
269
+ call = argument.argument;
270
+ }
271
+ }
272
+ }
273
+ else if (fn.type === "ArrowFunctionExpression" && fn.body !== null && fn.body.type === "CallExpression") {
274
+ call = fn.body;
275
+ }
276
+ if (call === null)
277
+ return false;
278
+ const seen = new Set();
279
+ for (const arg of call.arguments) {
280
+ if (arg.type !== "Identifier")
281
+ return false;
282
+ if (!names.has(arg.name) || seen.has(arg.name))
283
+ return false;
284
+ seen.add(arg.name);
285
+ }
286
+ return seen.size === names.size;
287
+ }
288
+ /**
289
+ * Whether a single-use candidate is dead indirection worth inlining: a pure
290
+ * alias that forwards its inputs verbatim. Substantial single-use helpers that
291
+ * raise the level of abstraction are kept (the document's "factor at n=1").
292
+ *
293
+ * @param {SourceCode} sourceCode - The rule's source-code accessor.
294
+ * @param {Candidate} candidate - The candidate to grade.
295
+ * @returns {boolean} True when the candidate is a pure alias.
296
+ */
297
+ function isDeadIndirection(sourceCode, candidate) {
298
+ if (candidate.kind === "type")
299
+ return false;
300
+ let fn = null;
301
+ if (candidate.kind === "function") {
302
+ const node = candidate.node;
303
+ if (node.type === "FunctionDeclaration") {
304
+ fn = node;
305
+ }
306
+ else if (node.type === "VariableDeclarator") {
307
+ fn = node.init ?? null;
308
+ }
309
+ }
310
+ else {
311
+ const node = candidate.node;
312
+ fn = node.type === "VariableDeclarator" ? effectHandler(node.init) : null;
313
+ }
314
+ if (fn === null)
315
+ return false;
316
+ return isTrivialForwarder(fn);
317
+ }
318
+ /**
319
+ * Top-level privates referenced exactly once are only worth inlining when they
320
+ * are pure aliases (they forward their inputs verbatim to another call). A
321
+ * single-use helper that earns its name by raising the level of abstraction is
322
+ * kept: the document argues for factoring proactively, even at n=1.
323
+ */
324
+ export const noSingleUsePrivateFunctionsRule = defineRule({
325
+ meta: {
326
+ type: "suggestion",
327
+ docs: {
328
+ description: "Inline private top-level functions and Effect values that are referenced exactly once as a pure alias (they forward their inputs verbatim to another call); single-use indirection that adds no abstraction hides shape. Single-use helpers that raise the level of abstraction earn their name and are kept.",
329
+ },
330
+ messages: {
331
+ singleUseFunction: "Private function {{name}} is a single-use pure alias: it forwards its inputs verbatim to another call. Inline the forwarded call at its use site instead of naming zero-abstraction indirection.",
332
+ singleUseEffectFunction: "Private Effect function {{name}} is run exactly once as a pure alias. Inline the forwarded handler at its single use site instead of naming zero-abstraction indirection.",
333
+ singleUseEffectProgram: "Private Effect program {{name}} is composed into exactly one pipeline as a pure alias. Inline it there instead of naming zero-abstraction indirection.",
334
+ singleUseType: "Private type {{name}} is referenced exactly once. Inline the annotation at that use site instead of naming it.",
335
+ },
336
+ },
337
+ createOnce(context) {
338
+ return {
339
+ before() {
340
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
341
+ return false;
342
+ },
343
+ Program(node) {
344
+ const sourceCode = context.sourceCode;
345
+ const exported = exportedNames(node);
346
+ const documented = new Set();
347
+ for (const statement of node.body) {
348
+ const comments = context.sourceCode.getCommentsBefore(statement);
349
+ const last = comments[comments.length - 1];
350
+ if (last !== undefined && last.type === "Block" && last.value.startsWith("*")) {
351
+ documented.add(statement);
352
+ }
353
+ }
354
+ const candidates = [];
355
+ for (const statement of node.body) {
356
+ if (documented.has(statement))
357
+ continue;
358
+ if (statement.type === "FunctionDeclaration") {
359
+ const name = statement.id?.name;
360
+ if (name === undefined || exported.has(name) || isPascalCase(name))
361
+ continue;
362
+ const variable = declaredVariablesOf({ sourceCode, node: statement, name });
363
+ if (variable !== undefined) {
364
+ candidates.push({ kind: "function", name, node: statement, variable });
365
+ }
366
+ continue;
367
+ }
368
+ if (statement.type === "TSTypeAliasDeclaration" || statement.type === "TSInterfaceDeclaration") {
369
+ const name = statement.id.name;
370
+ if (exported.has(name))
371
+ continue;
372
+ const variable = declaredVariablesOf({ sourceCode, node: statement, name });
373
+ if (variable !== undefined) {
374
+ candidates.push({ kind: "type", name, node: statement, variable });
375
+ }
376
+ continue;
377
+ }
378
+ if (statement.type !== "VariableDeclaration")
379
+ continue;
380
+ for (const declarator of statement.declarations) {
381
+ if (declarator.id.type !== "Identifier")
382
+ continue;
383
+ const { name } = declarator.id;
384
+ const init = declarator.init;
385
+ if (init === null || init === undefined)
386
+ continue;
387
+ const candidateKind = effectInitializerKind(init);
388
+ if (candidateKind === null)
389
+ continue;
390
+ const chain = ancestorsOf(sourceCode, declarator);
391
+ const parentIndex = chain.findIndex((ancestor) => ancestor.type === "VariableDeclaration");
392
+ const parent = parentIndex >= 0 ? chain[parentIndex] : undefined;
393
+ const grandparent = parentIndex > 0 ? chain[parentIndex - 1] : chain[parentIndex + 1];
394
+ if (parent === undefined || grandparent === undefined || grandparent.type !== "Program") {
395
+ continue;
396
+ }
397
+ if (exported.has(name) || isPascalCase(name))
398
+ continue;
399
+ const variable = declaredVariablesOf({ sourceCode, node: declarator, name });
400
+ if (variable !== undefined) {
401
+ candidates.push({ kind: candidateKind, name, node: declarator, variable });
402
+ }
403
+ }
404
+ }
405
+ for (const candidate of candidates) {
406
+ if (useCount({ sourceCode, candidate }) !== 1)
407
+ continue;
408
+ if (!isDeadIndirection(sourceCode, candidate))
409
+ continue;
410
+ context.report({
411
+ node: candidate.node,
412
+ messageId: MESSAGE_BY_KIND[candidate.kind],
413
+ data: { name: candidate.name },
414
+ });
415
+ }
416
+ },
417
+ };
418
+ },
419
+ });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Disallow SQL queries built from template literal interpolation. String
3
+ * interpolation in SQL is an injection vector: attacker-controlled values
4
+ * become query structure. Use parameterized queries or a query builder
5
+ * instead so values never become syntax.
6
+ */
7
+ export declare const noSqlStringInterpolationRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,62 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
3
+ /**
4
+ * SQL keywords that suggest a string is a query. Case-insensitive match
5
+ * against the raw template string portions.
6
+ */
7
+ const SQL_KEYWORDS = [
8
+ "SELECT",
9
+ "INSERT",
10
+ "UPDATE",
11
+ "DELETE",
12
+ "FROM",
13
+ "WHERE",
14
+ "JOIN",
15
+ "CREATE\\s+TABLE",
16
+ "DROP\\s+TABLE",
17
+ "ALTER\\s+TABLE",
18
+ ];
19
+ const SQL_PATTERN = new RegExp("\\b(?:" + SQL_KEYWORDS.join("|") + ")\\b", "iu");
20
+ /**
21
+ * Whether a template literal's raw text contains a SQL keyword.
22
+ * @param {ESTree.TemplateElement} quasi - The template element to test.
23
+ * @returns {boolean} True when the raw text contains a SQL keyword.
24
+ */
25
+ function hasSqlKeyword(quasi) {
26
+ return SQL_PATTERN.test(quasi.value.raw);
27
+ }
28
+ /**
29
+ * Disallow SQL queries built from template literal interpolation. String
30
+ * interpolation in SQL is an injection vector: attacker-controlled values
31
+ * become query structure. Use parameterized queries or a query builder
32
+ * instead so values never become syntax.
33
+ */
34
+ export const noSqlStringInterpolationRule = defineRule({
35
+ meta: {
36
+ type: "problem",
37
+ docs: {
38
+ description: "Disallow SQL queries built via template literal interpolation; use parameterized queries or a query builder to prevent SQL injection.",
39
+ },
40
+ messages: {
41
+ sqlInterpolation: "SQL via template literal interpolation is an injection vector. Use parameterized queries or a query builder so values never become syntax.",
42
+ },
43
+ },
44
+ createOnce(context) {
45
+ return {
46
+ before() {
47
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
48
+ return false;
49
+ },
50
+ TemplateLiteral(node) {
51
+ if (node.expressions.length === 0)
52
+ return;
53
+ for (const quasi of node.quasis) {
54
+ if (hasSqlKeyword(quasi)) {
55
+ context.report({ node, messageId: "sqlInterpolation" });
56
+ return;
57
+ }
58
+ }
59
+ },
60
+ };
61
+ },
62
+ });
@@ -0,0 +1,2 @@
1
+ /** Consecutive JSDoc blocks mean the outer one documents nothing. */
2
+ export declare const noStackedJsdocBlocksRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,50 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ /**
3
+ * Collect JSDoc-style block comments with their source offsets.
4
+ *
5
+ * @param {{ getAllComments: () => CommentLike[]; text: string }} sourceCode - The rule's source-code accessor.
6
+ * @returns {JSDocComment[]} Block comments paired with their source positions.
7
+ */
8
+ function collectJSDoc(sourceCode) {
9
+ const comments = [];
10
+ for (const comment of sourceCode.getAllComments()) {
11
+ if (comment.type !== "Block" || !comment.value.startsWith("*"))
12
+ continue;
13
+ comments.push({
14
+ start: comment.range?.[0] ?? 0,
15
+ end: comment.range?.[1] ?? 0,
16
+ line: comment.loc?.start.line ?? 1,
17
+ });
18
+ }
19
+ return comments;
20
+ }
21
+ /** Consecutive JSDoc blocks mean the outer one documents nothing. */
22
+ export const noStackedJsdocBlocksRule = defineRule({
23
+ meta: {
24
+ type: "problem",
25
+ docs: {
26
+ description: "Disallow stacked JSDoc blocks; tools attach only the last block to the following declaration, so any earlier block silently documents nothing.",
27
+ },
28
+ messages: {
29
+ stackedJsdoc: "This JSDoc block is immediately followed by another; only the last one attaches to the declaration, so this block documents nothing. Merge the content into one block or delete the orphan.",
30
+ },
31
+ },
32
+ createOnce(context) {
33
+ return {
34
+ Program() {
35
+ const comments = collectJSDoc(context.sourceCode);
36
+ for (let index = 1; index < comments.length; index += 1) {
37
+ const previous = comments[index - 1];
38
+ const current = comments[index];
39
+ const between = context.sourceCode.text.slice(previous.end, current.start);
40
+ if (between.trim() !== "")
41
+ continue;
42
+ context.report({
43
+ loc: { start: { line: previous.line, column: 0 } },
44
+ messageId: "stackedJsdoc",
45
+ });
46
+ }
47
+ },
48
+ };
49
+ },
50
+ });
@@ -0,0 +1,2 @@
1
+ /** Stray inline notes inside a function body belong in its JSDoc, not the code. */
2
+ export declare const noStrayInlineCommentsRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,74 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { getAllComments } from "../shared/structural.js";
3
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
4
+ /** Directive and safety comments are tooling contracts, not prose. */
5
+ const EXEMPT = /^(?:SAFETY:|eslint|oxlint|@ts-|ts-check|jscpd)/iu;
6
+ /** Stray inline notes inside a function body belong in its JSDoc, not the code. */
7
+ export const noStrayInlineCommentsRule = defineRule({
8
+ meta: {
9
+ type: "problem",
10
+ docs: {
11
+ description: "Disallow // line comments inside function bodies: notes about a function's behaviour belong in that function's JSDoc (description or annotated tags), keeping the body purely executable.",
12
+ },
13
+ messages: {
14
+ strayInlineComment: "Stray inline comment inside a function body. Move the note into the enclosing declaration's JSDoc (as description prose or an annotated note) or delete it.",
15
+ },
16
+ },
17
+ createOnce(context) {
18
+ const bodyRanges = [];
19
+ const recordBody = (body) => {
20
+ if (body?.range !== undefined && body.range !== null)
21
+ bodyRanges.push(body.range);
22
+ };
23
+ return {
24
+ before() {
25
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
26
+ return false;
27
+ bodyRanges.length = 0;
28
+ },
29
+ FunctionDeclaration(node) {
30
+ recordBody(node.body);
31
+ },
32
+ FunctionExpression(node) {
33
+ recordBody(node.body);
34
+ },
35
+ ArrowFunctionExpression(node) {
36
+ recordBody(node.body);
37
+ },
38
+ "Program:exit"() {
39
+ const lineComments = (getAllComments(context.sourceCode)).filter((comment) => comment.type === "Line");
40
+ const exempt = new Set();
41
+ lineComments.forEach((comment, index) => {
42
+ if (!EXEMPT.test(comment.value.trim()))
43
+ return;
44
+ exempt.add(comment);
45
+ let previousEnd = comment.loc?.end?.line;
46
+ let cursor = index + 1;
47
+ while (previousEnd !== undefined &&
48
+ cursor < lineComments.length) {
49
+ const next = lineComments[cursor];
50
+ const nextStart = next.loc?.start?.line;
51
+ if (nextStart === undefined || nextStart !== previousEnd + 1)
52
+ break;
53
+ exempt.add(next);
54
+ previousEnd = next.loc?.end?.line;
55
+ cursor += 1;
56
+ }
57
+ });
58
+ for (const comment of lineComments) {
59
+ if (exempt.has(comment))
60
+ continue;
61
+ const start = comment.range?.[0];
62
+ if (start === undefined)
63
+ continue;
64
+ if (!bodyRanges.some(([from, to]) => start > from && start < to))
65
+ continue;
66
+ context.report({
67
+ loc: { start: { line: comment.loc?.start?.line ?? 1, column: 0 } },
68
+ messageId: "strayInlineComment",
69
+ });
70
+ }
71
+ },
72
+ };
73
+ },
74
+ });
@@ -0,0 +1,2 @@
1
+ /** Adjacent same-primitive parameters compile despite swaps; require distinct brands. */
2
+ export declare const noSwappablePrimitiveParamsRule: import("@oxlint/plugins").Rule;