@autotelic/plumb 0.3.1 → 0.4.0

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 (268) 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 +104 -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-mutable-environment-capture.d.ts +7 -0
  92. package/dist/rules/no-mutable-environment-capture.js +134 -0
  93. package/dist/rules/no-nondeterministic-core.d.ts +6 -0
  94. package/dist/rules/no-nondeterministic-core.js +63 -0
  95. package/dist/rules/no-object-parameters.d.ts +2 -0
  96. package/dist/rules/no-object-parameters.js +95 -0
  97. package/dist/rules/no-optional-function-parameters.d.ts +7 -0
  98. package/dist/rules/no-optional-function-parameters.js +44 -0
  99. package/dist/rules/no-product-of-state-booleans.d.ts +2 -0
  100. package/dist/rules/no-product-of-state-booleans.js +79 -0
  101. package/dist/rules/no-redundant-derived-field.d.ts +6 -0
  102. package/dist/rules/no-redundant-derived-field.js +194 -0
  103. package/dist/rules/no-reflect-apply.d.ts +2 -0
  104. package/dist/rules/no-reflect-apply.js +29 -0
  105. package/dist/rules/no-reflect-get.d.ts +2 -0
  106. package/dist/rules/no-reflect-get.js +29 -0
  107. package/dist/rules/no-reinterpret-cast.d.ts +2 -0
  108. package/dist/rules/no-reinterpret-cast.js +68 -0
  109. package/dist/rules/no-runtime-typeof.d.ts +2 -0
  110. package/dist/rules/no-runtime-typeof.js +54 -0
  111. package/dist/rules/no-sentinel-comparison-union.d.ts +2 -0
  112. package/dist/rules/no-sentinel-comparison-union.js +139 -0
  113. package/dist/rules/no-shape-in-symbol-names.d.ts +2 -0
  114. package/dist/rules/no-shape-in-symbol-names.js +39 -0
  115. package/dist/rules/no-single-use-private-functions.d.ts +17 -0
  116. package/dist/rules/no-single-use-private-functions.js +419 -0
  117. package/dist/rules/no-stacked-jsdoc-blocks.d.ts +2 -0
  118. package/dist/rules/no-stacked-jsdoc-blocks.js +50 -0
  119. package/dist/rules/no-stray-inline-comments.d.ts +2 -0
  120. package/dist/rules/no-stray-inline-comments.js +74 -0
  121. package/dist/rules/no-swappable-primitive-params.d.ts +2 -0
  122. package/dist/rules/no-swappable-primitive-params.js +96 -0
  123. package/dist/rules/no-tag-ladder-assertions.d.ts +6 -0
  124. package/dist/rules/no-tag-ladder-assertions.js +63 -0
  125. package/dist/rules/no-transposed-field-reads.d.ts +8 -0
  126. package/dist/rules/no-transposed-field-reads.js +101 -0
  127. package/dist/rules/no-unit-return-validators.d.ts +2 -0
  128. package/dist/rules/no-unit-return-validators.js +64 -0
  129. package/dist/rules/no-unknown-parameters.d.ts +2 -0
  130. package/dist/rules/no-unknown-parameters.js +82 -0
  131. package/dist/rules/no-unknown-returns.d.ts +2 -0
  132. package/dist/rules/no-unknown-returns.js +86 -0
  133. package/dist/rules/no-unknown-type-aliases.d.ts +2 -0
  134. package/dist/rules/no-unknown-type-aliases.js +64 -0
  135. package/dist/rules/no-unsafe-dictionary-type.d.ts +2 -0
  136. package/dist/rules/no-unsafe-dictionary-type.js +116 -0
  137. package/dist/rules/no-vague-test-filenames.d.ts +2 -0
  138. package/dist/rules/no-vague-test-filenames.js +61 -0
  139. package/dist/rules/no-widen-then-assert.d.ts +2 -0
  140. package/dist/rules/no-widen-then-assert.js +268 -0
  141. package/dist/rules/prefer-payload-brand.d.ts +2 -0
  142. package/dist/rules/prefer-payload-brand.js +57 -0
  143. package/dist/rules/prefer-property-tests.d.ts +5 -0
  144. package/dist/rules/prefer-property-tests.js +39 -0
  145. package/dist/rules/require-canonical-stringify-for-identity.d.ts +8 -0
  146. package/dist/rules/require-canonical-stringify-for-identity.js +72 -0
  147. package/dist/rules/require-deprecated-tag-for-legacy-comments.d.ts +2 -0
  148. package/dist/rules/require-deprecated-tag-for-legacy-comments.js +34 -0
  149. package/dist/rules/require-exhaustive-tag-switch.d.ts +7 -0
  150. package/dist/rules/require-exhaustive-tag-switch.js +34 -0
  151. package/dist/rules/require-fc-block-predicate.d.ts +2 -0
  152. package/dist/rules/require-fc-block-predicate.js +37 -0
  153. package/dist/rules/require-jsdoc-on-exported.d.ts +2 -0
  154. package/dist/rules/require-jsdoc-on-exported.js +66 -0
  155. package/dist/rules/require-published-order.d.ts +2 -0
  156. package/dist/rules/require-published-order.js +102 -0
  157. package/dist/rules/require-safety-comment-for-type-assertion.d.ts +2 -0
  158. package/dist/rules/require-safety-comment-for-type-assertion.js +53 -0
  159. package/dist/rules/require-sort-comparator.d.ts +7 -0
  160. package/dist/rules/require-sort-comparator.js +34 -0
  161. package/dist/rules/test-utils.d.ts +35 -0
  162. package/dist/rules/test-utils.js +53 -0
  163. package/{src/shared/ancestors.ts → dist/shared/ancestors.d.ts} +1 -4
  164. package/dist/shared/ancestors.js +19 -0
  165. package/dist/shared/child-nodes.d.ts +12 -0
  166. package/dist/shared/child-nodes.js +26 -0
  167. package/dist/shared/dictionary-types.d.ts +55 -0
  168. package/dist/shared/dictionary-types.js +413 -0
  169. package/{src/shared/is-node.ts → dist/shared/is-node.d.ts} +2 -6
  170. package/dist/shared/is-node.js +10 -0
  171. package/dist/shared/lexical-type-parameters.d.ts +12 -0
  172. package/dist/shared/lexical-type-parameters.js +50 -0
  173. package/dist/shared/reflect-method.d.ts +15 -0
  174. package/dist/shared/reflect-method.js +32 -0
  175. package/{src/shared/rule-options.ts → dist/shared/rule-options.d.ts} +2 -7
  176. package/dist/shared/rule-options.js +12 -0
  177. package/{src/shared/structural.ts → dist/shared/structural.d.ts} +17 -44
  178. package/dist/shared/structural.js +40 -0
  179. package/{src/testing/index.ts → dist/testing/index.d.ts} +0 -1
  180. package/dist/testing/index.js +1 -0
  181. package/dist/testing/testable-rule.d.ts +38 -0
  182. package/dist/testing/testable-rule.js +70 -0
  183. package/package.json +7 -6
  184. package/src/effect/index.ts +0 -59
  185. package/src/effect/rules/guarded-op-must-return-effect.ts +0 -236
  186. package/src/effect/rules/guarded-op-must-return-option.ts +0 -97
  187. package/src/effect/rules/no-cascading-layer-provide.ts +0 -80
  188. package/src/effect/rules/no-decode-unknown-option.ts +0 -41
  189. package/src/effect/rules/no-direct-browser-storage.ts +0 -91
  190. package/src/effect/rules/no-direct-fetch.ts +0 -44
  191. package/src/effect/rules/no-manual-field-guards.ts +0 -144
  192. package/src/effect/rules/no-nested-layer-provide.ts +0 -51
  193. package/src/effect/rules/no-schema-class-modeling.ts +0 -59
  194. package/src/effect/rules/no-service-constructor-imports.ts +0 -50
  195. package/src/effect/rules/no-silent-error-swallow.ts +0 -99
  196. package/src/effect/rules/no-static-effect-service-forwarders.ts +0 -227
  197. package/src/effect/rules/no-try-catch.ts +0 -32
  198. package/src/effect/rules/no-unguarded-json-parse.ts +0 -211
  199. package/src/effect/rules/option-core-needs-effect-public.ts +0 -81
  200. package/src/effect/rules/prefer-die-for-precondition-defects.ts +0 -118
  201. package/src/effect/rules/prefer-effect-gen-for-guard-ladders.ts +0 -76
  202. package/src/effect/rules/prefer-effect-match.ts +0 -78
  203. package/src/effect/rules/prefer-effect-predicate-over-boolean-function.ts +0 -79
  204. package/src/effect/rules/prefer-named-guard-predicate.ts +0 -105
  205. package/src/effect/rules/prefer-option-pipeline.ts +0 -95
  206. package/src/effect/rules/prefer-ordering-match.ts +0 -152
  207. package/src/effect/rules/prefer-tagged-enum.ts +0 -68
  208. package/src/effect/rules/require-schema-type-derivation.ts +0 -83
  209. package/src/index.ts +0 -106
  210. package/src/meta/rules/no-disable-directives.ts +0 -38
  211. package/src/meta/rules/no-manual-ancestor-walks.ts +0 -27
  212. package/src/meta/rules/prefer-before-file-scope.ts +0 -57
  213. package/src/meta/rules/require-create-once.ts +0 -51
  214. package/src/meta/rules/require-rule-tester.ts +0 -57
  215. package/src/rules/no-anonymous-wide-tuples.ts +0 -38
  216. package/src/rules/no-barrel-export-star.ts +0 -30
  217. package/src/rules/no-boolean-field-signals.ts +0 -305
  218. package/src/rules/no-builtin-throws.ts +0 -83
  219. package/src/rules/no-chained-type-assertions.ts +0 -65
  220. package/src/rules/no-conditional-empty-object-spread.ts +0 -42
  221. package/src/rules/no-duplicated-literal-union.ts +0 -66
  222. package/src/rules/no-exported-mutable-state.ts +0 -111
  223. package/src/rules/no-generic-export-names.ts +0 -149
  224. package/src/rules/no-impossible-branch-throw.ts +0 -55
  225. package/src/rules/no-known-value-widening.ts +0 -225
  226. package/src/rules/no-module-mocking.ts +0 -95
  227. package/src/rules/no-multiple-function-params.ts +0 -192
  228. package/src/rules/no-nondeterministic-core.ts +0 -73
  229. package/src/rules/no-object-parameters.ts +0 -127
  230. package/src/rules/no-optional-function-parameters.ts +0 -49
  231. package/src/rules/no-product-of-state-booleans.ts +0 -80
  232. package/src/rules/no-redundant-derived-field.ts +0 -192
  233. package/src/rules/no-reflect-apply.ts +0 -32
  234. package/src/rules/no-reflect-get.ts +0 -32
  235. package/src/rules/no-reinterpret-cast.ts +0 -78
  236. package/src/rules/no-runtime-typeof.ts +0 -59
  237. package/src/rules/no-sentinel-comparison-union.ts +0 -148
  238. package/src/rules/no-shape-in-symbol-names.ts +0 -45
  239. package/src/rules/no-single-use-private-functions.ts +0 -329
  240. package/src/rules/no-stacked-jsdoc-blocks.ts +0 -65
  241. package/src/rules/no-stray-inline-comments.ts +0 -79
  242. package/src/rules/no-swappable-primitive-params.ts +0 -109
  243. package/src/rules/no-tag-ladder-assertions.ts +0 -71
  244. package/src/rules/no-transposed-field-reads.ts +0 -135
  245. package/src/rules/no-unit-return-validators.ts +0 -65
  246. package/src/rules/no-unknown-parameters.ts +0 -97
  247. package/src/rules/no-unknown-returns.ts +0 -120
  248. package/src/rules/no-unknown-type-aliases.ts +0 -70
  249. package/src/rules/no-unsafe-dictionary-type.ts +0 -132
  250. package/src/rules/no-vague-test-filenames.ts +0 -67
  251. package/src/rules/no-widen-then-assert.ts +0 -345
  252. package/src/rules/prefer-payload-brand.ts +0 -67
  253. package/src/rules/prefer-property-tests.ts +0 -43
  254. package/src/rules/require-canonical-stringify-for-identity.ts +0 -80
  255. package/src/rules/require-deprecated-tag-for-legacy-comments.ts +0 -45
  256. package/src/rules/require-exhaustive-tag-switch.ts +0 -42
  257. package/src/rules/require-fc-block-predicate.ts +0 -42
  258. package/src/rules/require-jsdoc-on-exported.ts +0 -74
  259. package/src/rules/require-published-order.ts +0 -109
  260. package/src/rules/require-safety-comment-for-type-assertion.ts +0 -61
  261. package/src/rules/require-sort-comparator.ts +0 -41
  262. package/src/rules/test-utils.ts +0 -68
  263. package/src/shared/child-nodes.ts +0 -27
  264. package/src/shared/dictionary-types.ts +0 -524
  265. package/src/shared/lexical-type-parameters.ts +0 -62
  266. package/src/shared/reflect-method.ts +0 -41
  267. package/src/testing/testable-rule.test.ts +0 -68
  268. package/src/testing/testable-rule.ts +0 -86
@@ -1,329 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import type { ESTree, SourceCode } from "@oxlint/plugins";
4
-
5
- import { ancestorsOf } from "../shared/ancestors.ts";
6
-
7
- import { isString } from "../shared/structural.ts";
8
-
9
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
10
-
11
- type DeclaredVariable = ReturnType<SourceCode["getDeclaredVariables"]>[number];
12
-
13
- type CandidateKind = "effect-function" | "effect-program" | "function" | "type";
14
-
15
- interface Candidate {
16
- kind: CandidateKind;
17
- name: string;
18
- node: ESTree.Node;
19
- variable: DeclaredVariable;
20
- }
21
-
22
- const MESSAGE_BY_KIND = {
23
- "effect-function": "singleUseEffectFunction",
24
- "effect-program": "singleUseEffectProgram",
25
- function: "singleUseFunction",
26
- type: "singleUseType",
27
- } satisfies Readonly<Record<CandidateKind, string>>;
28
-
29
- function isPascalCase(name: string): boolean {
30
- return /^[A-Z]/u.test(name);
31
- }
32
-
33
- /** Computed or plain property name on a member expression.
34
- *
35
- * @param {ESTree.Node} member - The member expression node.
36
- * @returns {string | null} The property name, or null when unavailable.
37
- */
38
- function memberName(member: ESTree.Node): string | null {
39
- if (member.type !== "MemberExpression") return null;
40
- if (!member.computed) {
41
- return member.property.type === "Identifier" ? member.property.name : null;
42
- }
43
- if (member.property.type === "Literal" && isString(member.property.value)) {
44
- return member.property.value;
45
- }
46
- return null;
47
- }
48
-
49
- /** Whether the call resolves to `Effect.<method>` (one invocation wrapper allowed for `Effect.fn("N")(...)`).
50
- *
51
- * @param {{ call: ESTree.Node; method: string }} payload - The candidate call and Effect method name.
52
- * @returns {boolean} True when the call targets `Effect.<method>`.
53
- */
54
- function isEffectMethodCall(payload: { call: ESTree.Node; method: string }): boolean {
55
- let callee: ESTree.Node = payload.call;
56
- if (callee.type === "CallExpression") callee = callee.callee;
57
- if (callee.type !== "MemberExpression") return false;
58
- if (callee.object.type !== "Identifier") return false;
59
- return callee.object.name === "Effect" && memberName(callee) === payload.method;
60
- }
61
-
62
- /**
63
- * Classify an initializer expression by the kind of private candidate it
64
- * declares: plain function values, Effect.fn-style services, or Effect.gen
65
- * programs.
66
- *
67
- * @param {ESTree.Node} init - The initializer expression of a top-level declarator.
68
- * @returns {CandidateKind | null} The candidate kind, or null when not a candidate.
69
- */
70
- function effectInitializerKind(init: ESTree.Node): CandidateKind | null {
71
- const kind = init.type;
72
- if (kind === "ArrowFunctionExpression" || kind === "FunctionExpression") {
73
- return "function";
74
- }
75
- if (kind !== "CallExpression") return null;
76
- if (
77
- isEffectMethodCall({ call: init, method: "fn" }) ||
78
- isEffectMethodCall({ call: init, method: "fnUntraced" })
79
- ) {
80
- return "effect-function";
81
- }
82
- if (isEffectMethodCall({ call: init, method: "gen" })) return "effect-program";
83
- return null;
84
- }
85
-
86
- function addDeclaredName(declaration: ESTree.Node | null, names: Set<string>): void {
87
- if (declaration === null) return;
88
- if (
89
- declaration.type === "FunctionDeclaration" ||
90
- declaration.type === "TSTypeAliasDeclaration" ||
91
- declaration.type === "TSInterfaceDeclaration"
92
- ) {
93
- if (declaration.id != null) names.add(declaration.id.name);
94
- return;
95
- }
96
- if (declaration.type === "VariableDeclaration") {
97
- for (const declarator of declaration.declarations) {
98
- if (declarator.id.type === "Identifier") names.add(declarator.id.name);
99
- }
100
- }
101
- }
102
-
103
- /** Re-exported or default-exported names are public regardless of local privacy.
104
- *
105
- * @param {ESTree.Program} program - Root AST node of the file under lint.
106
- * @returns {Set<string>} Names treated as public exports.
107
- */
108
- function exportedNames(program: ESTree.Program): Set<string> {
109
- const names = new Set<string>();
110
- for (const statement of program.body) {
111
- if (statement.type === "ExportDefaultDeclaration") {
112
- addDeclaredName(statement.declaration ?? null, names);
113
- }
114
- if (statement.type === "ExportNamedDeclaration") {
115
- addDeclaredName(statement.declaration ?? null, names);
116
- if (statement.source === null || statement.source === undefined) {
117
- for (const specifier of statement.specifiers) {
118
- if (specifier.local !== undefined && specifier.local.type === "Identifier") {
119
- names.add(specifier.local.name);
120
- }
121
- }
122
- }
123
- }
124
- if (statement.type === "TSExportAssignment") {
125
- if (statement.expression.type === "Identifier") {
126
- names.add(statement.expression.name);
127
- }
128
- }
129
- }
130
- return names;
131
- }
132
-
133
- /** Reads inside type positions (`: T`, `as T`, generics) are not runtime reads.
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 a type position.
138
- */
139
- function hasTypeAncestor(sourceCode: SourceCode, identifier: ESTree.Node): boolean {
140
- for (const current of ancestorsOf(sourceCode, identifier)) {
141
- const kind = current.type;
142
- if (kind.startsWith("TS")) return true;
143
- if (
144
- kind === "Program" ||
145
- kind === "BlockStatement" ||
146
- kind === "ExpressionStatement"
147
- ) {
148
- return false;
149
- }
150
- }
151
- return false;
152
- }
153
-
154
- /** Reads inside re-export positions do not count toward private usage.
155
- *
156
- * @param {SourceCode} sourceCode - The rule's source-code accessor.
157
- * @param {ESTree.Node} identifier - The identifier reference being counted.
158
- * @returns {boolean} True when the read sits in an export position.
159
- */
160
- function hasExportAncestor(sourceCode: SourceCode, identifier: ESTree.Node): boolean {
161
- for (const current of ancestorsOf(sourceCode, identifier)) {
162
- const kind = current.type;
163
- if (
164
- kind === "ExportDefaultDeclaration" ||
165
- kind === "ExportSpecifier" ||
166
- kind === "TSExportAssignment"
167
- ) {
168
- return true;
169
- }
170
- if (kind === "Program" || kind === "BlockStatement") return false;
171
- }
172
- return false;
173
- }
174
-
175
- /**
176
- * Runtime reads of a private top-level binding: reads outside type positions
177
- * and re-export positions.
178
- *
179
- * @param {{ sourceCode: SourceCode; variable: DeclaredVariable }} payload - The declared variable to count.
180
- * @returns {number} Number of qualifying reads.
181
- */
182
- function runtimeReadCount(payload: { sourceCode: SourceCode; variable: DeclaredVariable }): number {
183
- return payload.variable.references.filter(
184
- (reference) =>
185
- reference.isRead() &&
186
- !hasTypeAncestor(payload.sourceCode, reference.identifier) &&
187
- !hasExportAncestor(payload.sourceCode, reference.identifier),
188
- ).length;
189
- }
190
-
191
- /**
192
- * Type-position reads of a private top-level type alias or interface.
193
- *
194
- * @param {{ sourceCode: SourceCode; variable: DeclaredVariable }} payload - The declared type to count.
195
- * @returns {number} Number of qualifying reads.
196
- */
197
- function typeReadCount(payload: { sourceCode: SourceCode; variable: DeclaredVariable }): number {
198
- return payload.variable.references.filter(
199
- (reference) =>
200
- reference.isRead() &&
201
- hasTypeAncestor(payload.sourceCode, reference.identifier) &&
202
- !hasExportAncestor(payload.sourceCode, reference.identifier),
203
- ).length;
204
- }
205
-
206
- /**
207
- * Usage count for a candidate, using the read model appropriate to its kind.
208
- *
209
- * @param {{ sourceCode: SourceCode; candidate: Candidate }} payload - The candidate to count.
210
- * @returns {number} The usage count.
211
- */
212
- function useCount(payload: { sourceCode: SourceCode; candidate: Candidate }): number {
213
- return payload.candidate.kind === "type"
214
- ? typeReadCount({ sourceCode: payload.sourceCode, variable: payload.candidate.variable })
215
- : runtimeReadCount({ sourceCode: payload.sourceCode, variable: payload.candidate.variable });
216
- }
217
-
218
- /**
219
- * The declared-variable record matching a name among a node's declarations.
220
- *
221
- * @param {{ sourceCode: SourceCode; node: ESTree.Node; name: string }} payload - Lookup inputs.
222
- * @returns {DeclaredVariable | undefined} The matching record, if any.
223
- */
224
- function declaredVariablesOf(payload: {
225
- sourceCode: SourceCode;
226
- node: ESTree.Node;
227
- name: string;
228
- }): DeclaredVariable | undefined {
229
- return payload.sourceCode.getDeclaredVariables(payload.node).find((variable) => variable.name === payload.name);
230
- }
231
-
232
- /** Top-level privates referenced exactly once are dead indirection; inline them at their single site.
233
- *
234
- * A leading JSDoc block marks the name as deliberately documented composition,
235
- * so such statements are exempt from the check.
236
- */
237
- export const noSingleUsePrivateFunctionsRule = defineRule({
238
- meta: {
239
- type: "suggestion",
240
- docs: {
241
- description:
242
- "Inline private top-level functions, Effect values, and types that are referenced exactly once; single-use indirection hides shape without earning a name.",
243
- },
244
- messages: {
245
- singleUseFunction:
246
- "Private function `{{name}}` is read exactly once. Inline it at that use site instead of naming an indirection.",
247
- singleUseEffectFunction:
248
- "Private Effect function `{{name}}` is run exactly once. Inline the handler at its single use site.",
249
- singleUseEffectProgram:
250
- "Private Effect program `{{name}}` is composed into exactly one pipeline. Inline it there instead of naming an indirection.",
251
- singleUseType:
252
- "Private type `{{name}}` is referenced exactly once. Inline the annotation at that use site instead of naming it.",
253
- },
254
- },
255
- createOnce(context) {
256
- return {
257
- before() {
258
- if (TEST_FILE.test(context.filename.replaceAll("\\", "/"))) return false;
259
- },
260
- Program(node) {
261
- const sourceCode = context.sourceCode;
262
- const exported = exportedNames(node);
263
- const documented = new Set<ESTree.Node>();
264
- for (const statement of node.body) {
265
- const comments = context.sourceCode.getCommentsBefore(statement);
266
- const last = comments[comments.length - 1];
267
- if (last !== undefined && last.type === "Block" && last.value.startsWith("*")) {
268
- documented.add(statement);
269
- }
270
- }
271
- const candidates: Array<Candidate> = [];
272
- for (const statement of node.body) {
273
- if (documented.has(statement)) continue;
274
- if (statement.type === "FunctionDeclaration") {
275
- const name = statement.id?.name;
276
- if (name === undefined || exported.has(name) || isPascalCase(name)) continue;
277
- const variable = declaredVariablesOf({ sourceCode, node: statement, name });
278
- if (variable !== undefined) {
279
- candidates.push({ kind: "function", name, node: statement, variable });
280
- }
281
- continue;
282
- }
283
- if (statement.type === "TSTypeAliasDeclaration" || statement.type === "TSInterfaceDeclaration") {
284
- const name = statement.id.name;
285
- if (exported.has(name)) continue;
286
- const variable = declaredVariablesOf({ sourceCode, node: statement, name });
287
- if (variable !== undefined) {
288
- candidates.push({ kind: "type", name, node: statement, variable });
289
- }
290
- continue;
291
- }
292
- if (statement.type !== "VariableDeclaration") continue;
293
- for (const declarator of statement.declarations) {
294
- if (declarator.id.type !== "Identifier") continue;
295
- const { name } = declarator.id;
296
- const init = declarator.init;
297
- if (init === null || init === undefined) continue;
298
- const candidateKind = effectInitializerKind(init);
299
- if (candidateKind === null) continue;
300
- const chain = ancestorsOf(sourceCode, declarator);
301
- const parent = chain[0];
302
- const grandparent = chain[1];
303
- if (
304
- parent === undefined ||
305
- grandparent === undefined ||
306
- parent.type !== "VariableDeclaration" ||
307
- grandparent.type !== "Program"
308
- ) {
309
- continue;
310
- }
311
- if (exported.has(name) || isPascalCase(name)) continue;
312
- const variable = declaredVariablesOf({ sourceCode, node: declarator, name });
313
- if (variable !== undefined) {
314
- candidates.push({ kind: candidateKind, name, node: declarator, variable });
315
- }
316
- }
317
- }
318
- for (const candidate of candidates) {
319
- if (useCount({ sourceCode, candidate }) !== 1) continue;
320
- context.report({
321
- node: candidate.node,
322
- messageId: MESSAGE_BY_KIND[candidate.kind],
323
- data: { name: candidate.name },
324
- });
325
- }
326
- },
327
- };
328
- },
329
- });
@@ -1,65 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- /** A JSDoc comment with its source span. */
4
- type JSDocComment = { start: number; end: number; line: number };
5
-
6
- interface CommentLike {
7
- type: string;
8
- value: string;
9
- range?: [number, number];
10
- loc?: { start: { line: number } };
11
- }
12
-
13
- /**
14
- * Collect JSDoc-style block comments with their source offsets.
15
- *
16
- * @param {{ getAllComments: () => CommentLike[]; text: string }} sourceCode - The rule's source-code accessor.
17
- * @returns {JSDocComment[]} Block comments paired with their source positions.
18
- */
19
- function collectJSDoc(sourceCode: {
20
- getAllComments: () => CommentLike[];
21
- text: string;
22
- }): JSDocComment[] {
23
- const comments: JSDocComment[] = [];
24
- for (const comment of sourceCode.getAllComments()) {
25
- if (comment.type !== "Block" || !comment.value.startsWith("*")) continue;
26
- comments.push({
27
- start: comment.range?.[0] ?? 0,
28
- end: comment.range?.[1] ?? 0,
29
- line: comment.loc?.start.line ?? 1,
30
- });
31
- }
32
- return comments;
33
- }
34
-
35
- /** Consecutive JSDoc blocks mean the outer one documents nothing. */
36
- export const noStackedJsdocBlocksRule = defineRule({
37
- meta: {
38
- type: "problem",
39
- docs: {
40
- description:
41
- "Disallow stacked JSDoc blocks; tools attach only the last block to the following declaration, so any earlier block silently documents nothing.",
42
- },
43
- messages: {
44
- stackedJsdoc:
45
- "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.",
46
- },
47
- },
48
- createOnce(context) {
49
- return {
50
- Program() {
51
- const comments = collectJSDoc(context.sourceCode);
52
- for (let index = 1; index < comments.length; index += 1) {
53
- const previous = comments[index - 1]!;
54
- const current = comments[index]!;
55
- const between = context.sourceCode.text.slice(previous.end, current.start);
56
- if (between.trim() !== "") continue;
57
- context.report({
58
- loc: { start: { line: previous.line, column: 0 } },
59
- messageId: "stackedJsdoc",
60
- });
61
- }
62
- },
63
- };
64
- },
65
- });
@@ -1,79 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import type { ESTree } from "@oxlint/plugins";
4
-
5
- import { type CommentLike, getAllComments } from "../shared/structural.ts";
6
-
7
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
8
-
9
- /** Directive and safety comments are tooling contracts, not prose. */
10
- const EXEMPT = /^(?:SAFETY:|eslint|oxlint|@ts-|ts-check|jscpd)/iu;
11
-
12
- /** Stray inline notes inside a function body belong in its JSDoc, not the code. */
13
- export const noStrayInlineCommentsRule = defineRule({
14
- meta: {
15
- type: "problem",
16
- docs: {
17
- description:
18
- "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.",
19
- },
20
- messages: {
21
- strayInlineComment:
22
- "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.",
23
- },
24
- },
25
- createOnce(context) {
26
- const bodyRanges: Array<readonly [number, number]> = [];
27
- const recordBody = (body: { range?: readonly [number, number] } | null | undefined): void => {
28
- if (body?.range !== undefined && body.range !== null) bodyRanges.push(body.range);
29
- };
30
- return {
31
- before() {
32
- if (TEST_FILE.test(context.filename.replaceAll("\\", "/"))) return false;
33
- bodyRanges.length = 0;
34
- },
35
- FunctionDeclaration(node) {
36
- recordBody(node.body);
37
- },
38
- FunctionExpression(node) {
39
- recordBody(node.body);
40
- },
41
- ArrowFunctionExpression(node) {
42
- recordBody(node.body);
43
- },
44
- "Program:exit"() {
45
- const lineComments = (
46
- getAllComments(context.sourceCode)
47
- ).filter((comment) => comment.type === "Line");
48
- const exempt = new Set<CommentLike>();
49
- lineComments.forEach((comment, index) => {
50
- if (!EXEMPT.test(comment.value.trim())) return;
51
- exempt.add(comment);
52
- let previousEnd = comment.loc?.end?.line;
53
- let cursor = index + 1;
54
- while (
55
- previousEnd !== undefined &&
56
- cursor < lineComments.length
57
- ) {
58
- const next = lineComments[cursor]!;
59
- const nextStart = next.loc?.start?.line;
60
- if (nextStart === undefined || nextStart !== previousEnd + 1) break;
61
- exempt.add(next);
62
- previousEnd = next.loc?.end?.line;
63
- cursor += 1;
64
- }
65
- });
66
- for (const comment of lineComments) {
67
- if (exempt.has(comment)) continue;
68
- const start = comment.range?.[0];
69
- if (start === undefined) continue;
70
- if (!bodyRanges.some(([from, to]) => start > from && start < to)) continue;
71
- context.report({
72
- loc: { start: { line: comment.loc?.start?.line ?? 1, column: 0 } },
73
- messageId: "strayInlineComment",
74
- });
75
- }
76
- },
77
- };
78
- },
79
- });
@@ -1,109 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import type { ESTree } from "@oxlint/plugins";
4
-
5
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
6
-
7
- /** Keyword node type -> spelled-out primitive for messages. */
8
- const PRIMITIVE_KEYWORDS = new Map<string, string>([
9
- ["TSStringKeyword", "string"],
10
- ["TSNumberKeyword", "number"],
11
- ["TSBooleanKeyword", "boolean"],
12
- ["TSBigIntKeyword", "bigint"],
13
- ]);
14
-
15
- const PRIMITIVES: ReadonlySet<string> = new Set(PRIMITIVE_KEYWORDS.values());
16
-
17
- /** Bare primitive annotation on a positional parameter, e.g. `userId: string`.
18
- *
19
- * @param {ESTree.BindingPattern | ESTree.ParamPattern} param - The parameter pattern to inspect.
20
- * @returns {string | null} The primitive keyword's text, or null when not a bare primitive.
21
- */
22
- function barePrimitive(param: ESTree.BindingPattern | ESTree.ParamPattern): string | null {
23
- if (param.type !== "Identifier") return null;
24
- const annotation = param.typeAnnotation?.typeAnnotation;
25
- if (annotation === undefined || annotation === null) return null;
26
- return PRIMITIVE_KEYWORDS.get(annotation.type) ?? null;
27
- }
28
-
29
- interface FnLike {
30
- params: ReadonlyArray<ESTree.BindingPattern | ESTree.ParamPattern>;
31
- }
32
-
33
- /** Adjacent same-primitive parameters compile despite swaps; require distinct brands. */
34
- export const noSwappablePrimitiveParamsRule = defineRule({
35
- meta: {
36
- type: "problem",
37
- docs: {
38
- description:
39
- "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.",
40
- },
41
- messages: {
42
- swappablePrimitiveParams:
43
- "`{{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.",
44
- },
45
- },
46
- createOnce(context) {
47
- const reportFn = (
48
- name: string,
49
- id: ESTree.BindingIdentifier | null,
50
- fn: FnLike,
51
- fnNode: ESTree.Node,
52
- ): void => {
53
- const found: Array<{ primitive: string; count: number }> = [];
54
- let runPrimitive: string | null = null;
55
- let runLength = 0;
56
- for (const param of fn.params) {
57
- const primitive = barePrimitive(param);
58
- if (primitive !== null && primitive === runPrimitive) {
59
- runLength += 1;
60
- } else {
61
- if (runPrimitive !== null && runLength >= 2)
62
- found.push({ primitive: runPrimitive, count: runLength });
63
- runPrimitive = primitive;
64
- runLength = 1;
65
- }
66
- }
67
- if (runPrimitive !== null && runLength >= 2)
68
- found.push({ primitive: runPrimitive, count: runLength });
69
- if (found.length === 0) return;
70
- const firstRun = found[0];
71
- if (firstRun === undefined) return;
72
- context.report({
73
- node: id ?? fnNode,
74
- messageId: "swappablePrimitiveParams",
75
- data: { name, primitive: firstRun.primitive, count: String(firstRun.count) },
76
- });
77
- };
78
- return {
79
- before() {
80
- if (TEST_FILE.test(context.filename.replaceAll("\\", "/"))) return false;
81
- },
82
- Program(node) {
83
- for (const statement of node.body) {
84
- const declaration =
85
- statement.type === "ExportNamedDeclaration" ||
86
- statement.type === "ExportDefaultDeclaration"
87
- ? (statement.declaration ?? null)
88
- : statement;
89
- if (declaration === null) continue;
90
- if (declaration.type === "FunctionDeclaration" && declaration.id !== null) {
91
- reportFn(declaration.id.name, declaration.id, declaration, declaration);
92
- }
93
- if (declaration.type === "VariableDeclaration") {
94
- for (const declarator of declaration.declarations) {
95
- if (declarator.id.type !== "Identifier") continue;
96
- const init = declarator.init;
97
- if (
98
- init?.type === "ArrowFunctionExpression" ||
99
- init?.type === "FunctionExpression"
100
- ) {
101
- reportFn(declarator.id.name, declarator.id, init, init);
102
- }
103
- }
104
- }
105
- }
106
- },
107
- };
108
- },
109
- });
@@ -1,71 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import type { ESTree } from "@oxlint/plugins";
4
- import { isRecordObject, isString } from "../shared/structural.ts";
5
-
6
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$|\/test\//u;
7
-
8
- /** Whether the if-consequent (or alternate) is a bare `throw new Error(...)` assertion.
9
- *
10
- * @param {ESTree.Statement | null | undefined} statement - The branch body to inspect.
11
- * @returns {boolean} True when the branch throws a built-in Error constructor.
12
- */
13
- function isBuiltinThrowBranch(statement: ESTree.Statement | null | undefined): boolean {
14
- if (statement === undefined || statement === null) return false;
15
- const body = statement.type === "BlockStatement" ? statement.body : [statement];
16
- return body.some(
17
- (child) =>
18
- child.type === "ThrowStatement" &&
19
- child.argument.type === "NewExpression" &&
20
- child.argument.callee.type === "Identifier" &&
21
- child.argument.callee.name === "Error",
22
- );
23
- }
24
-
25
- /** Whether the binary expression compares a `._tag` member against a string literal.
26
- *
27
- * @param {ESTree.Expression} expression - The expression to inspect.
28
- * @returns {boolean} True when the comparison is a tag equality check.
29
- */
30
- function isTagComparison(expression: ESTree.Expression): boolean {
31
- if (expression.type !== "BinaryExpression") return false;
32
- if (expression.operator !== "!==" && expression.operator !== "===") return false;
33
- const sides = [expression.left, expression.right];
34
- const hasTagMember = sides.some(
35
- (side) => side.type === "MemberExpression" && side.property.type === "Identifier" && side.property.name === "_tag",
36
- );
37
- const hasStringLiteral = sides.some((side) => side.type === "Literal" && isString(side.value));
38
- return hasTagMember && hasStringLiteral;
39
- }
40
-
41
- /**
42
- * Hand-rolled `if (x._tag !== "...") throw new Error(...)` ladders re-implement
43
- * narrowing assertions per spec; a shared assertTag helper does it once, with
44
- * type-level narrowing.
45
- */
46
- export const noTagLadderAssertionsRule = defineRule({
47
- meta: {
48
- type: "suggestion",
49
- docs: {
50
- description:
51
- "In specs, replace hand-rolled _tag comparison + throw ladders with the shared assertTag narrowing helper from test helpers.",
52
- },
53
- messages: {
54
- ladder:
55
- "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.",
56
- },
57
- },
58
- createOnce(context) {
59
- return {
60
- before() {
61
- if (TEST_FILE.test(context.filename.replaceAll("\\", "/"))) return false;
62
- },
63
- IfStatement(node) {
64
- if (!isTagComparison(node.test)) return;
65
- if (isBuiltinThrowBranch(node.consequent) || isBuiltinThrowBranch(node.alternate)) {
66
- context.report({ node, messageId: "ladder" });
67
- }
68
- },
69
- };
70
- },
71
- });