@autotelic/plumb 0.3.1 → 0.3.2

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 (266) hide show
  1. package/dist/effect/index.d.ts +3 -0
  2. package/dist/effect/index.js +56 -0
  3. package/dist/effect/rules/guarded-op-must-return-effect.d.ts +6 -0
  4. package/dist/effect/rules/guarded-op-must-return-effect.js +235 -0
  5. package/dist/effect/rules/guarded-op-must-return-option.d.ts +2 -0
  6. package/dist/effect/rules/guarded-op-must-return-option.js +88 -0
  7. package/dist/effect/rules/no-cascading-layer-provide.d.ts +6 -0
  8. package/dist/effect/rules/no-cascading-layer-provide.js +73 -0
  9. package/dist/effect/rules/no-decode-unknown-option.d.ts +7 -0
  10. package/dist/effect/rules/no-decode-unknown-option.js +34 -0
  11. package/dist/effect/rules/no-direct-browser-storage.d.ts +2 -0
  12. package/dist/effect/rules/no-direct-browser-storage.js +88 -0
  13. package/dist/effect/rules/no-direct-fetch.d.ts +2 -0
  14. package/dist/effect/rules/no-direct-fetch.js +37 -0
  15. package/dist/effect/rules/no-manual-field-guards.d.ts +6 -0
  16. package/dist/effect/rules/no-manual-field-guards.js +129 -0
  17. package/dist/effect/rules/no-nested-layer-provide.d.ts +2 -0
  18. package/dist/effect/rules/no-nested-layer-provide.js +50 -0
  19. package/dist/effect/rules/no-schema-class-modeling.d.ts +2 -0
  20. package/dist/effect/rules/no-schema-class-modeling.js +52 -0
  21. package/dist/effect/rules/no-service-constructor-imports.d.ts +2 -0
  22. package/dist/effect/rules/no-service-constructor-imports.js +42 -0
  23. package/dist/effect/rules/no-silent-error-swallow.d.ts +2 -0
  24. package/dist/effect/rules/no-silent-error-swallow.js +95 -0
  25. package/dist/effect/rules/no-static-effect-service-forwarders.d.ts +6 -0
  26. package/dist/effect/rules/no-static-effect-service-forwarders.js +222 -0
  27. package/dist/effect/rules/no-try-catch.d.ts +2 -0
  28. package/dist/effect/rules/no-try-catch.js +30 -0
  29. package/dist/effect/rules/no-unguarded-json-parse.d.ts +5 -0
  30. package/dist/effect/rules/no-unguarded-json-parse.js +200 -0
  31. package/dist/effect/rules/option-core-needs-effect-public.d.ts +5 -0
  32. package/dist/effect/rules/option-core-needs-effect-public.js +76 -0
  33. package/dist/effect/rules/prefer-die-for-precondition-defects.d.ts +5 -0
  34. package/dist/effect/rules/prefer-die-for-precondition-defects.js +112 -0
  35. package/dist/effect/rules/prefer-effect-gen-for-guard-ladders.d.ts +5 -0
  36. package/dist/effect/rules/prefer-effect-gen-for-guard-ladders.js +72 -0
  37. package/dist/effect/rules/prefer-effect-match.d.ts +2 -0
  38. package/dist/effect/rules/prefer-effect-match.js +74 -0
  39. package/dist/effect/rules/prefer-effect-predicate-over-boolean-function.d.ts +2 -0
  40. package/dist/effect/rules/prefer-effect-predicate-over-boolean-function.js +75 -0
  41. package/dist/effect/rules/prefer-named-guard-predicate.d.ts +2 -0
  42. package/dist/effect/rules/prefer-named-guard-predicate.js +93 -0
  43. package/dist/effect/rules/prefer-option-pipeline.d.ts +2 -0
  44. package/dist/effect/rules/prefer-option-pipeline.js +87 -0
  45. package/dist/effect/rules/prefer-ordering-match.d.ts +2 -0
  46. package/dist/effect/rules/prefer-ordering-match.js +135 -0
  47. package/dist/effect/rules/prefer-tagged-enum.d.ts +2 -0
  48. package/dist/effect/rules/prefer-tagged-enum.js +66 -0
  49. package/dist/effect/rules/require-schema-type-derivation.d.ts +7 -0
  50. package/dist/effect/rules/require-schema-type-derivation.js +80 -0
  51. package/dist/index.d.ts +3 -0
  52. package/dist/index.js +102 -0
  53. package/dist/meta/index.d.ts +7 -0
  54. package/{src/meta/index.ts → dist/meta/index.js} +13 -16
  55. package/dist/meta/rules/no-disable-directives.d.ts +6 -0
  56. package/dist/meta/rules/no-disable-directives.js +35 -0
  57. package/dist/meta/rules/no-manual-ancestor-walks.d.ts +2 -0
  58. package/dist/meta/rules/no-manual-ancestor-walks.js +26 -0
  59. package/dist/meta/rules/prefer-before-file-scope.d.ts +2 -0
  60. package/dist/meta/rules/prefer-before-file-scope.js +57 -0
  61. package/dist/meta/rules/require-create-once.d.ts +2 -0
  62. package/dist/meta/rules/require-create-once.js +51 -0
  63. package/dist/meta/rules/require-rule-tester.d.ts +2 -0
  64. package/dist/meta/rules/require-rule-tester.js +50 -0
  65. package/dist/rules/no-anonymous-wide-tuples.d.ts +7 -0
  66. package/dist/rules/no-anonymous-wide-tuples.js +34 -0
  67. package/dist/rules/no-barrel-export-star.d.ts +2 -0
  68. package/dist/rules/no-barrel-export-star.js +26 -0
  69. package/dist/rules/no-boolean-field-signals.d.ts +2 -0
  70. package/dist/rules/no-boolean-field-signals.js +279 -0
  71. package/dist/rules/no-builtin-throws.d.ts +6 -0
  72. package/dist/rules/no-builtin-throws.js +74 -0
  73. package/dist/rules/no-chained-type-assertions.d.ts +2 -0
  74. package/dist/rules/no-chained-type-assertions.js +54 -0
  75. package/dist/rules/no-conditional-empty-object-spread.d.ts +2 -0
  76. package/dist/rules/no-conditional-empty-object-spread.js +36 -0
  77. package/dist/rules/no-duplicated-literal-union.d.ts +6 -0
  78. package/dist/rules/no-duplicated-literal-union.js +62 -0
  79. package/dist/rules/no-exported-mutable-state.d.ts +7 -0
  80. package/dist/rules/no-exported-mutable-state.js +104 -0
  81. package/dist/rules/no-generic-export-names.d.ts +2 -0
  82. package/dist/rules/no-generic-export-names.js +141 -0
  83. package/dist/rules/no-impossible-branch-throw.d.ts +2 -0
  84. package/dist/rules/no-impossible-branch-throw.js +51 -0
  85. package/dist/rules/no-known-value-widening.d.ts +2 -0
  86. package/dist/rules/no-known-value-widening.js +176 -0
  87. package/dist/rules/no-module-mocking.d.ts +2 -0
  88. package/dist/rules/no-module-mocking.js +90 -0
  89. package/dist/rules/no-multiple-function-params.d.ts +2 -0
  90. package/dist/rules/no-multiple-function-params.js +155 -0
  91. package/dist/rules/no-nondeterministic-core.d.ts +6 -0
  92. package/dist/rules/no-nondeterministic-core.js +63 -0
  93. package/dist/rules/no-object-parameters.d.ts +2 -0
  94. package/dist/rules/no-object-parameters.js +95 -0
  95. package/dist/rules/no-optional-function-parameters.d.ts +7 -0
  96. package/dist/rules/no-optional-function-parameters.js +44 -0
  97. package/dist/rules/no-product-of-state-booleans.d.ts +2 -0
  98. package/dist/rules/no-product-of-state-booleans.js +79 -0
  99. package/dist/rules/no-redundant-derived-field.d.ts +6 -0
  100. package/dist/rules/no-redundant-derived-field.js +194 -0
  101. package/dist/rules/no-reflect-apply.d.ts +2 -0
  102. package/dist/rules/no-reflect-apply.js +29 -0
  103. package/dist/rules/no-reflect-get.d.ts +2 -0
  104. package/dist/rules/no-reflect-get.js +29 -0
  105. package/dist/rules/no-reinterpret-cast.d.ts +2 -0
  106. package/dist/rules/no-reinterpret-cast.js +68 -0
  107. package/dist/rules/no-runtime-typeof.d.ts +2 -0
  108. package/dist/rules/no-runtime-typeof.js +54 -0
  109. package/dist/rules/no-sentinel-comparison-union.d.ts +2 -0
  110. package/dist/rules/no-sentinel-comparison-union.js +139 -0
  111. package/dist/rules/no-shape-in-symbol-names.d.ts +2 -0
  112. package/dist/rules/no-shape-in-symbol-names.js +39 -0
  113. package/dist/rules/no-single-use-private-functions.d.ts +6 -0
  114. package/dist/rules/no-single-use-private-functions.js +295 -0
  115. package/dist/rules/no-stacked-jsdoc-blocks.d.ts +2 -0
  116. package/dist/rules/no-stacked-jsdoc-blocks.js +50 -0
  117. package/dist/rules/no-stray-inline-comments.d.ts +2 -0
  118. package/dist/rules/no-stray-inline-comments.js +74 -0
  119. package/dist/rules/no-swappable-primitive-params.d.ts +2 -0
  120. package/dist/rules/no-swappable-primitive-params.js +96 -0
  121. package/dist/rules/no-tag-ladder-assertions.d.ts +6 -0
  122. package/dist/rules/no-tag-ladder-assertions.js +63 -0
  123. package/dist/rules/no-transposed-field-reads.d.ts +8 -0
  124. package/dist/rules/no-transposed-field-reads.js +101 -0
  125. package/dist/rules/no-unit-return-validators.d.ts +2 -0
  126. package/dist/rules/no-unit-return-validators.js +64 -0
  127. package/dist/rules/no-unknown-parameters.d.ts +2 -0
  128. package/dist/rules/no-unknown-parameters.js +82 -0
  129. package/dist/rules/no-unknown-returns.d.ts +2 -0
  130. package/dist/rules/no-unknown-returns.js +86 -0
  131. package/dist/rules/no-unknown-type-aliases.d.ts +2 -0
  132. package/dist/rules/no-unknown-type-aliases.js +64 -0
  133. package/dist/rules/no-unsafe-dictionary-type.d.ts +2 -0
  134. package/dist/rules/no-unsafe-dictionary-type.js +116 -0
  135. package/dist/rules/no-vague-test-filenames.d.ts +2 -0
  136. package/dist/rules/no-vague-test-filenames.js +61 -0
  137. package/dist/rules/no-widen-then-assert.d.ts +2 -0
  138. package/dist/rules/no-widen-then-assert.js +268 -0
  139. package/dist/rules/prefer-payload-brand.d.ts +2 -0
  140. package/dist/rules/prefer-payload-brand.js +57 -0
  141. package/dist/rules/prefer-property-tests.d.ts +5 -0
  142. package/dist/rules/prefer-property-tests.js +39 -0
  143. package/dist/rules/require-canonical-stringify-for-identity.d.ts +8 -0
  144. package/dist/rules/require-canonical-stringify-for-identity.js +72 -0
  145. package/dist/rules/require-deprecated-tag-for-legacy-comments.d.ts +2 -0
  146. package/dist/rules/require-deprecated-tag-for-legacy-comments.js +34 -0
  147. package/dist/rules/require-exhaustive-tag-switch.d.ts +7 -0
  148. package/dist/rules/require-exhaustive-tag-switch.js +34 -0
  149. package/dist/rules/require-fc-block-predicate.d.ts +2 -0
  150. package/dist/rules/require-fc-block-predicate.js +37 -0
  151. package/dist/rules/require-jsdoc-on-exported.d.ts +2 -0
  152. package/dist/rules/require-jsdoc-on-exported.js +66 -0
  153. package/dist/rules/require-published-order.d.ts +2 -0
  154. package/dist/rules/require-published-order.js +102 -0
  155. package/dist/rules/require-safety-comment-for-type-assertion.d.ts +2 -0
  156. package/dist/rules/require-safety-comment-for-type-assertion.js +53 -0
  157. package/dist/rules/require-sort-comparator.d.ts +7 -0
  158. package/dist/rules/require-sort-comparator.js +34 -0
  159. package/dist/rules/test-utils.d.ts +35 -0
  160. package/dist/rules/test-utils.js +53 -0
  161. package/{src/shared/ancestors.ts → dist/shared/ancestors.d.ts} +1 -4
  162. package/dist/shared/ancestors.js +19 -0
  163. package/dist/shared/child-nodes.d.ts +12 -0
  164. package/dist/shared/child-nodes.js +26 -0
  165. package/dist/shared/dictionary-types.d.ts +55 -0
  166. package/dist/shared/dictionary-types.js +413 -0
  167. package/{src/shared/is-node.ts → dist/shared/is-node.d.ts} +2 -6
  168. package/dist/shared/is-node.js +10 -0
  169. package/dist/shared/lexical-type-parameters.d.ts +12 -0
  170. package/dist/shared/lexical-type-parameters.js +50 -0
  171. package/dist/shared/reflect-method.d.ts +15 -0
  172. package/dist/shared/reflect-method.js +32 -0
  173. package/{src/shared/rule-options.ts → dist/shared/rule-options.d.ts} +2 -7
  174. package/dist/shared/rule-options.js +12 -0
  175. package/{src/shared/structural.ts → dist/shared/structural.d.ts} +17 -44
  176. package/dist/shared/structural.js +40 -0
  177. package/{src/testing/index.ts → dist/testing/index.d.ts} +0 -1
  178. package/dist/testing/index.js +1 -0
  179. package/dist/testing/testable-rule.d.ts +38 -0
  180. package/dist/testing/testable-rule.js +70 -0
  181. package/package.json +7 -6
  182. package/src/effect/index.ts +0 -59
  183. package/src/effect/rules/guarded-op-must-return-effect.ts +0 -236
  184. package/src/effect/rules/guarded-op-must-return-option.ts +0 -97
  185. package/src/effect/rules/no-cascading-layer-provide.ts +0 -80
  186. package/src/effect/rules/no-decode-unknown-option.ts +0 -41
  187. package/src/effect/rules/no-direct-browser-storage.ts +0 -91
  188. package/src/effect/rules/no-direct-fetch.ts +0 -44
  189. package/src/effect/rules/no-manual-field-guards.ts +0 -144
  190. package/src/effect/rules/no-nested-layer-provide.ts +0 -51
  191. package/src/effect/rules/no-schema-class-modeling.ts +0 -59
  192. package/src/effect/rules/no-service-constructor-imports.ts +0 -50
  193. package/src/effect/rules/no-silent-error-swallow.ts +0 -99
  194. package/src/effect/rules/no-static-effect-service-forwarders.ts +0 -227
  195. package/src/effect/rules/no-try-catch.ts +0 -32
  196. package/src/effect/rules/no-unguarded-json-parse.ts +0 -211
  197. package/src/effect/rules/option-core-needs-effect-public.ts +0 -81
  198. package/src/effect/rules/prefer-die-for-precondition-defects.ts +0 -118
  199. package/src/effect/rules/prefer-effect-gen-for-guard-ladders.ts +0 -76
  200. package/src/effect/rules/prefer-effect-match.ts +0 -78
  201. package/src/effect/rules/prefer-effect-predicate-over-boolean-function.ts +0 -79
  202. package/src/effect/rules/prefer-named-guard-predicate.ts +0 -105
  203. package/src/effect/rules/prefer-option-pipeline.ts +0 -95
  204. package/src/effect/rules/prefer-ordering-match.ts +0 -152
  205. package/src/effect/rules/prefer-tagged-enum.ts +0 -68
  206. package/src/effect/rules/require-schema-type-derivation.ts +0 -83
  207. package/src/index.ts +0 -106
  208. package/src/meta/rules/no-disable-directives.ts +0 -38
  209. package/src/meta/rules/no-manual-ancestor-walks.ts +0 -27
  210. package/src/meta/rules/prefer-before-file-scope.ts +0 -57
  211. package/src/meta/rules/require-create-once.ts +0 -51
  212. package/src/meta/rules/require-rule-tester.ts +0 -57
  213. package/src/rules/no-anonymous-wide-tuples.ts +0 -38
  214. package/src/rules/no-barrel-export-star.ts +0 -30
  215. package/src/rules/no-boolean-field-signals.ts +0 -305
  216. package/src/rules/no-builtin-throws.ts +0 -83
  217. package/src/rules/no-chained-type-assertions.ts +0 -65
  218. package/src/rules/no-conditional-empty-object-spread.ts +0 -42
  219. package/src/rules/no-duplicated-literal-union.ts +0 -66
  220. package/src/rules/no-exported-mutable-state.ts +0 -111
  221. package/src/rules/no-generic-export-names.ts +0 -149
  222. package/src/rules/no-impossible-branch-throw.ts +0 -55
  223. package/src/rules/no-known-value-widening.ts +0 -225
  224. package/src/rules/no-module-mocking.ts +0 -95
  225. package/src/rules/no-multiple-function-params.ts +0 -192
  226. package/src/rules/no-nondeterministic-core.ts +0 -73
  227. package/src/rules/no-object-parameters.ts +0 -127
  228. package/src/rules/no-optional-function-parameters.ts +0 -49
  229. package/src/rules/no-product-of-state-booleans.ts +0 -80
  230. package/src/rules/no-redundant-derived-field.ts +0 -192
  231. package/src/rules/no-reflect-apply.ts +0 -32
  232. package/src/rules/no-reflect-get.ts +0 -32
  233. package/src/rules/no-reinterpret-cast.ts +0 -78
  234. package/src/rules/no-runtime-typeof.ts +0 -59
  235. package/src/rules/no-sentinel-comparison-union.ts +0 -148
  236. package/src/rules/no-shape-in-symbol-names.ts +0 -45
  237. package/src/rules/no-single-use-private-functions.ts +0 -329
  238. package/src/rules/no-stacked-jsdoc-blocks.ts +0 -65
  239. package/src/rules/no-stray-inline-comments.ts +0 -79
  240. package/src/rules/no-swappable-primitive-params.ts +0 -109
  241. package/src/rules/no-tag-ladder-assertions.ts +0 -71
  242. package/src/rules/no-transposed-field-reads.ts +0 -135
  243. package/src/rules/no-unit-return-validators.ts +0 -65
  244. package/src/rules/no-unknown-parameters.ts +0 -97
  245. package/src/rules/no-unknown-returns.ts +0 -120
  246. package/src/rules/no-unknown-type-aliases.ts +0 -70
  247. package/src/rules/no-unsafe-dictionary-type.ts +0 -132
  248. package/src/rules/no-vague-test-filenames.ts +0 -67
  249. package/src/rules/no-widen-then-assert.ts +0 -345
  250. package/src/rules/prefer-payload-brand.ts +0 -67
  251. package/src/rules/prefer-property-tests.ts +0 -43
  252. package/src/rules/require-canonical-stringify-for-identity.ts +0 -80
  253. package/src/rules/require-deprecated-tag-for-legacy-comments.ts +0 -45
  254. package/src/rules/require-exhaustive-tag-switch.ts +0 -42
  255. package/src/rules/require-fc-block-predicate.ts +0 -42
  256. package/src/rules/require-jsdoc-on-exported.ts +0 -74
  257. package/src/rules/require-published-order.ts +0 -109
  258. package/src/rules/require-safety-comment-for-type-assertion.ts +0 -61
  259. package/src/rules/require-sort-comparator.ts +0 -41
  260. package/src/rules/test-utils.ts +0 -68
  261. package/src/shared/child-nodes.ts +0 -27
  262. package/src/shared/dictionary-types.ts +0 -524
  263. package/src/shared/lexical-type-parameters.ts +0 -62
  264. package/src/shared/reflect-method.ts +0 -41
  265. package/src/testing/testable-rule.test.ts +0 -68
  266. package/src/testing/testable-rule.ts +0 -86
@@ -0,0 +1,6 @@
1
+ /** Top-level privates referenced exactly once are dead indirection; inline them at their single site.
2
+ *
3
+ * A leading JSDoc block marks the name as deliberately documented composition,
4
+ * so such statements are exempt from the check.
5
+ */
6
+ export declare const noSingleUsePrivateFunctionsRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,295 @@
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
+ */
192
+ function declaredVariablesOf(payload) {
193
+ return payload.sourceCode.getDeclaredVariables(payload.node).find((variable) => variable.name === payload.name);
194
+ }
195
+ /** Top-level privates referenced exactly once are dead indirection; inline them at their single site.
196
+ *
197
+ * A leading JSDoc block marks the name as deliberately documented composition,
198
+ * so such statements are exempt from the check.
199
+ */
200
+ export const noSingleUsePrivateFunctionsRule = defineRule({
201
+ meta: {
202
+ type: "suggestion",
203
+ docs: {
204
+ description: "Inline private top-level functions, Effect values, and types that are referenced exactly once; single-use indirection hides shape without earning a name.",
205
+ },
206
+ messages: {
207
+ singleUseFunction: "Private function `{{name}}` is read exactly once. Inline it at that use site instead of naming an indirection.",
208
+ singleUseEffectFunction: "Private Effect function `{{name}}` is run exactly once. Inline the handler at its single use site.",
209
+ singleUseEffectProgram: "Private Effect program `{{name}}` is composed into exactly one pipeline. Inline it there instead of naming an indirection.",
210
+ singleUseType: "Private type `{{name}}` is referenced exactly once. Inline the annotation at that use site instead of naming it.",
211
+ },
212
+ },
213
+ createOnce(context) {
214
+ return {
215
+ before() {
216
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
217
+ return false;
218
+ },
219
+ Program(node) {
220
+ const sourceCode = context.sourceCode;
221
+ const exported = exportedNames(node);
222
+ const documented = new Set();
223
+ for (const statement of node.body) {
224
+ const comments = context.sourceCode.getCommentsBefore(statement);
225
+ const last = comments[comments.length - 1];
226
+ if (last !== undefined && last.type === "Block" && last.value.startsWith("*")) {
227
+ documented.add(statement);
228
+ }
229
+ }
230
+ const candidates = [];
231
+ for (const statement of node.body) {
232
+ if (documented.has(statement))
233
+ continue;
234
+ if (statement.type === "FunctionDeclaration") {
235
+ const name = statement.id?.name;
236
+ if (name === undefined || exported.has(name) || isPascalCase(name))
237
+ continue;
238
+ const variable = declaredVariablesOf({ sourceCode, node: statement, name });
239
+ if (variable !== undefined) {
240
+ candidates.push({ kind: "function", name, node: statement, variable });
241
+ }
242
+ continue;
243
+ }
244
+ if (statement.type === "TSTypeAliasDeclaration" || statement.type === "TSInterfaceDeclaration") {
245
+ const name = statement.id.name;
246
+ if (exported.has(name))
247
+ continue;
248
+ const variable = declaredVariablesOf({ sourceCode, node: statement, name });
249
+ if (variable !== undefined) {
250
+ candidates.push({ kind: "type", name, node: statement, variable });
251
+ }
252
+ continue;
253
+ }
254
+ if (statement.type !== "VariableDeclaration")
255
+ continue;
256
+ for (const declarator of statement.declarations) {
257
+ if (declarator.id.type !== "Identifier")
258
+ continue;
259
+ const { name } = declarator.id;
260
+ const init = declarator.init;
261
+ if (init === null || init === undefined)
262
+ continue;
263
+ const candidateKind = effectInitializerKind(init);
264
+ if (candidateKind === null)
265
+ continue;
266
+ const chain = ancestorsOf(sourceCode, declarator);
267
+ const parent = chain[0];
268
+ const grandparent = chain[1];
269
+ if (parent === undefined ||
270
+ grandparent === undefined ||
271
+ parent.type !== "VariableDeclaration" ||
272
+ grandparent.type !== "Program") {
273
+ continue;
274
+ }
275
+ if (exported.has(name) || isPascalCase(name))
276
+ continue;
277
+ const variable = declaredVariablesOf({ sourceCode, node: declarator, name });
278
+ if (variable !== undefined) {
279
+ candidates.push({ kind: candidateKind, name, node: declarator, variable });
280
+ }
281
+ }
282
+ }
283
+ for (const candidate of candidates) {
284
+ if (useCount({ sourceCode, candidate }) !== 1)
285
+ continue;
286
+ context.report({
287
+ node: candidate.node,
288
+ messageId: MESSAGE_BY_KIND[candidate.kind],
289
+ data: { name: candidate.name },
290
+ });
291
+ }
292
+ },
293
+ };
294
+ },
295
+ });
@@ -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;
@@ -0,0 +1,96 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
3
+ /** Keyword node type -> spelled-out primitive for messages. */
4
+ const PRIMITIVE_KEYWORDS = new Map([
5
+ ["TSStringKeyword", "string"],
6
+ ["TSNumberKeyword", "number"],
7
+ ["TSBooleanKeyword", "boolean"],
8
+ ["TSBigIntKeyword", "bigint"],
9
+ ]);
10
+ const PRIMITIVES = new Set(PRIMITIVE_KEYWORDS.values());
11
+ /** Bare primitive annotation on a positional parameter, e.g. `userId: string`.
12
+ *
13
+ * @param {ESTree.BindingPattern | ESTree.ParamPattern} param - The parameter pattern to inspect.
14
+ * @returns {string | null} The primitive keyword's text, or null when not a bare primitive.
15
+ */
16
+ function barePrimitive(param) {
17
+ if (param.type !== "Identifier")
18
+ return null;
19
+ const annotation = param.typeAnnotation?.typeAnnotation;
20
+ if (annotation === undefined || annotation === null)
21
+ return null;
22
+ return PRIMITIVE_KEYWORDS.get(annotation.type) ?? null;
23
+ }
24
+ /** Adjacent same-primitive parameters compile despite swaps; require distinct brands. */
25
+ export const noSwappablePrimitiveParamsRule = defineRule({
26
+ meta: {
27
+ type: "problem",
28
+ docs: {
29
+ description: "Disallow exported functions with two or more adjacent parameters annotated as the same bare primitive (string, number, boolean, bigint); accidental argument swaps compile silently. Require distinct branded types instead.",
30
+ },
31
+ messages: {
32
+ swappablePrimitiveParams: "`{{name}}` takes {{count}} adjacent `{{primitive}}` parameters, so a swapped call compiles. Brand each one (e.g. `type UserId = string & Brand.Brand<\"UserId\">`) so the compiler rejects transposed arguments.",
33
+ },
34
+ },
35
+ createOnce(context) {
36
+ const reportFn = (name, id, fn, fnNode) => {
37
+ const found = [];
38
+ let runPrimitive = null;
39
+ let runLength = 0;
40
+ for (const param of fn.params) {
41
+ const primitive = barePrimitive(param);
42
+ if (primitive !== null && primitive === runPrimitive) {
43
+ runLength += 1;
44
+ }
45
+ else {
46
+ if (runPrimitive !== null && runLength >= 2)
47
+ found.push({ primitive: runPrimitive, count: runLength });
48
+ runPrimitive = primitive;
49
+ runLength = 1;
50
+ }
51
+ }
52
+ if (runPrimitive !== null && runLength >= 2)
53
+ found.push({ primitive: runPrimitive, count: runLength });
54
+ if (found.length === 0)
55
+ return;
56
+ const firstRun = found[0];
57
+ if (firstRun === undefined)
58
+ return;
59
+ context.report({
60
+ node: id ?? fnNode,
61
+ messageId: "swappablePrimitiveParams",
62
+ data: { name, primitive: firstRun.primitive, count: String(firstRun.count) },
63
+ });
64
+ };
65
+ return {
66
+ before() {
67
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
68
+ return false;
69
+ },
70
+ Program(node) {
71
+ for (const statement of node.body) {
72
+ const declaration = statement.type === "ExportNamedDeclaration" ||
73
+ statement.type === "ExportDefaultDeclaration"
74
+ ? (statement.declaration ?? null)
75
+ : statement;
76
+ if (declaration === null)
77
+ continue;
78
+ if (declaration.type === "FunctionDeclaration" && declaration.id !== null) {
79
+ reportFn(declaration.id.name, declaration.id, declaration, declaration);
80
+ }
81
+ if (declaration.type === "VariableDeclaration") {
82
+ for (const declarator of declaration.declarations) {
83
+ if (declarator.id.type !== "Identifier")
84
+ continue;
85
+ const init = declarator.init;
86
+ if (init?.type === "ArrowFunctionExpression" ||
87
+ init?.type === "FunctionExpression") {
88
+ reportFn(declarator.id.name, declarator.id, init, init);
89
+ }
90
+ }
91
+ }
92
+ }
93
+ },
94
+ };
95
+ },
96
+ });
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Hand-rolled `if (x._tag !== "...") throw new Error(...)` ladders re-implement
3
+ * narrowing assertions per spec; a shared assertTag helper does it once, with
4
+ * type-level narrowing.
5
+ */
6
+ export declare const noTagLadderAssertionsRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,63 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { isRecordObject, isString } from "../shared/structural.js";
3
+ const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$|\/test\//u;
4
+ /** Whether the if-consequent (or alternate) is a bare `throw new Error(...)` assertion.
5
+ *
6
+ * @param {ESTree.Statement | null | undefined} statement - The branch body to inspect.
7
+ * @returns {boolean} True when the branch throws a built-in Error constructor.
8
+ */
9
+ function isBuiltinThrowBranch(statement) {
10
+ if (statement === undefined || statement === null)
11
+ return false;
12
+ const body = statement.type === "BlockStatement" ? statement.body : [statement];
13
+ return body.some((child) => child.type === "ThrowStatement" &&
14
+ child.argument.type === "NewExpression" &&
15
+ child.argument.callee.type === "Identifier" &&
16
+ child.argument.callee.name === "Error");
17
+ }
18
+ /** Whether the binary expression compares a `._tag` member against a string literal.
19
+ *
20
+ * @param {ESTree.Expression} expression - The expression to inspect.
21
+ * @returns {boolean} True when the comparison is a tag equality check.
22
+ */
23
+ function isTagComparison(expression) {
24
+ if (expression.type !== "BinaryExpression")
25
+ return false;
26
+ if (expression.operator !== "!==" && expression.operator !== "===")
27
+ return false;
28
+ const sides = [expression.left, expression.right];
29
+ const hasTagMember = sides.some((side) => side.type === "MemberExpression" && side.property.type === "Identifier" && side.property.name === "_tag");
30
+ const hasStringLiteral = sides.some((side) => side.type === "Literal" && isString(side.value));
31
+ return hasTagMember && hasStringLiteral;
32
+ }
33
+ /**
34
+ * Hand-rolled `if (x._tag !== "...") throw new Error(...)` ladders re-implement
35
+ * narrowing assertions per spec; a shared assertTag helper does it once, with
36
+ * type-level narrowing.
37
+ */
38
+ export const noTagLadderAssertionsRule = defineRule({
39
+ meta: {
40
+ type: "suggestion",
41
+ docs: {
42
+ description: "In specs, replace hand-rolled _tag comparison + throw ladders with the shared assertTag narrowing helper from test helpers.",
43
+ },
44
+ messages: {
45
+ ladder: "This _tag ladder re-implements variant assertion by hand. Use the shared `assertTag(value, tag)` helper so the branch narrows types and fails with a uniform message.",
46
+ },
47
+ },
48
+ createOnce(context) {
49
+ return {
50
+ before() {
51
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
52
+ return false;
53
+ },
54
+ IfStatement(node) {
55
+ if (!isTagComparison(node.test))
56
+ return;
57
+ if (isBuiltinThrowBranch(node.consequent) || isBuiltinThrowBranch(node.alternate)) {
58
+ context.report({ node, messageId: "ladder" });
59
+ }
60
+ },
61
+ };
62
+ },
63
+ });
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Flag argument lists and object literals that pluck two or more role fields
3
+ * off the same base expression in reversed canonical order: the syntactic
4
+ * fingerprint of inline structural surgery on a domain value (e.g. a
5
+ * hand-rolled reciprocal). Such shuffles belong behind a named operation
6
+ * that owns the invariant.
7
+ */
8
+ export declare const noTransposedFieldReadsRule: import("@oxlint/plugins").Rule;