@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,149 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import type { ESTree } from "@oxlint/plugins";
4
-
5
- /** Single words whose bare grep hits span unrelated subsystems (the `create` problem). */
6
- const GENERIC_TERMS: ReadonlySet<string> = new Set([
7
- "create",
8
- "init",
9
- "initialize",
10
- "get",
11
- "set",
12
- "validate",
13
- "process",
14
- "handle",
15
- "run",
16
- "make",
17
- "build",
18
- "execute",
19
- "update",
20
- "parse",
21
- "format",
22
- "convert",
23
- "transform",
24
- "start",
25
- "stop",
26
- "load",
27
- "save",
28
- "check",
29
- "do",
30
- "main",
31
- "util",
32
- "utils",
33
- "helper",
34
- "helpers",
35
- "misc",
36
- "common",
37
- "data",
38
- "manager",
39
- "service",
40
- "wrapper",
41
- "temp",
42
- "tmp",
43
- ]);
44
-
45
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
46
-
47
- /** Split an identifier into its words across camelCase and separators.
48
- *
49
- * @param {string} name - Identifier or filename stem to split.
50
- * @returns {Array<string>} Non-empty words of the name.
51
- */
52
- function splitWords(name: string): Array<string> {
53
- return name
54
- .replace(/([a-z0-9])([A-Z])/gu, "$1 $2")
55
- .split(/[^A-Za-z0-9]+/u)
56
- .filter((word) => word.length > 0);
57
- }
58
-
59
- /** Module segment acting as the qualification prefix at qualified call sites.
60
- *
61
- * @param {string} filename - Lint-context filename of the module.
62
- * @returns {Array<string>} Words of the module's qualifying segment.
63
- */
64
- function qualifierWords(filename: string): Array<string> {
65
- const segments = filename.replaceAll("\\", "/").split("/");
66
- const base = segments[segments.length - 1] ?? "";
67
- let stem = base.replace(/\.[cm]?[jt]sx?$/u, "");
68
- if (stem === "index" || stem === "mod") {
69
- stem = segments[segments.length - 2] ?? stem;
70
- }
71
- return splitWords(stem);
72
- }
73
-
74
- /** True when every word of the name is generic, so qualification adds nothing either.
75
- *
76
- * @param {Array<string>} words - Words of the exported symbol's name.
77
- * @returns {boolean} True when no word carries domain meaning.
78
- */
79
- function isAllGeneric(words: Array<string>): boolean {
80
- return (
81
- words.length > 0 &&
82
- words.every((word) => GENERIC_TERMS.has(word.toLowerCase()))
83
- );
84
- }
85
-
86
- /** Exported symbols must resolve by grep in one hop; qualification by the module counts. */
87
- export const noGenericExportNamesRule = defineRule({
88
- meta: {
89
- type: "problem",
90
- docs: {
91
- description:
92
- "Disallow exported symbol names that stay generic even after module qualification (e.g. utils.ts exporting `create`); a distinctive qualified token such as `Currency.make` greps to exactly the right definition and call sites.",
93
- },
94
- messages: {
95
- genericExportName:
96
- "Exported symbol `{{qualified}}` stays generic, so searching it lands on hundreds of unrelated hits. Add a domain word to the name (e.g. `create` -> `createStripeClient`) or move it into a domain-named module so callers read `{{domain}}.{{name}}`.",
97
- },
98
- },
99
- createOnce(context) {
100
- let moduleWords: Array<string> = [];
101
- let moduleSuppliesDomain = false;
102
- return {
103
- before() {
104
- const filePath = context.filename.replaceAll("\\", "/");
105
- if (TEST_FILE.test(filePath)) return false;
106
- moduleWords = qualifierWords(filePath);
107
- moduleSuppliesDomain = moduleWords.some((word) => !GENERIC_TERMS.has(word.toLowerCase()));
108
- },
109
- Program(node) {
110
- for (const statement of node.body) {
111
- const declaration =
112
- statement.type === "ExportNamedDeclaration" ||
113
- statement.type === "ExportDefaultDeclaration"
114
- ? (statement.declaration ?? null)
115
- : statement;
116
- if (declaration === null) continue;
117
- const identifiers: Array<ESTree.BindingIdentifier> = [];
118
- if (
119
- declaration.type === "FunctionDeclaration" ||
120
- declaration.type === "ClassDeclaration" ||
121
- declaration.type === "TSInterfaceDeclaration" ||
122
- declaration.type === "TSTypeAliasDeclaration" ||
123
- declaration.type === "TSEnumDeclaration"
124
- ) {
125
- if (declaration.id !== null) identifiers.push(declaration.id);
126
- } else if (declaration.type === "VariableDeclaration") {
127
- for (const declarator of declaration.declarations) {
128
- if (declarator.id.type === "Identifier") identifiers.push(declarator.id);
129
- }
130
- }
131
- for (const id of identifiers) {
132
- const nameWords = splitWords(id.name);
133
- if (!isAllGeneric(nameWords)) continue;
134
- if (moduleSuppliesDomain) continue;
135
- context.report({
136
- node: id,
137
- messageId: "genericExportName",
138
- data: {
139
- name: id.name,
140
- qualified: moduleWords.concat(nameWords).join("."),
141
- domain: moduleWords.join(""),
142
- },
143
- });
144
- }
145
- }
146
- },
147
- };
148
- },
149
- });
@@ -1,55 +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?$/u;
7
- const IMPOSSIBLE_MESSAGE =
8
- /(?:never\s+happen|impossible|unreachable|invariant|cannot\s+happen|can'?t\s+happen|unexpected\s+state|not\s+possible)/iu;
9
-
10
- /** Extract the prose message of a thrown error literal or constructor.
11
- *
12
- * @param {ESTree.ThrowStatement} node - The throw statement to inspect.
13
- * @returns {string | null} The thrown message, or null when not a string literal.
14
- */
15
- function throwMessage(node: ESTree.ThrowStatement): string | null {
16
- const argument = node.argument;
17
- if (argument === null || argument === undefined) return null;
18
- if (argument.type === "Literal" && isString(argument.value)) return argument.value;
19
- if (argument.type === "NewExpression") {
20
- const first = argument.arguments[0];
21
- if (first !== undefined && first.type === "Literal" && isString(first.value)) {
22
- return first.value;
23
- }
24
- }
25
- return null;
26
- }
27
-
28
- /** Reject "should never happen" throws; encode the case out of the type instead. */
29
- export const noImpossibleBranchThrowRule = defineRule({
30
- meta: {
31
- type: "problem",
32
- docs: {
33
- description:
34
- "Disallow hand-asserted impossible branches (throws about never-happens/invariants); encode the case out of the type so the compiler rejects it.",
35
- },
36
- messages: {
37
- impossibleThrow:
38
- "This branch is asserted impossible by hand (\"{{message}}\"). If it truly cannot occur, parse/encode it out of the type (Option, parsed/refined type) so the compiler rejects it; otherwise return a structured failure.",
39
- },
40
- },
41
- createOnce(context) {
42
-
43
- return {
44
- before() {
45
- if (TEST_FILE.test(context.filename.replaceAll("\\", "/"))) return false;
46
- },
47
- ThrowStatement(node) {
48
- const message = throwMessage(node);
49
- if (message === null) return;
50
- if (!IMPOSSIBLE_MESSAGE.test(message)) return;
51
- context.report({ node, messageId: "impossibleThrow", data: { message } });
52
- },
53
- };
54
- },
55
- });
@@ -1,225 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import {
4
- classifyWideningTarget,
5
- createTypeEnvironment,
6
- isKnownEvidenceExpression,
7
- type TypeEnvironment,
8
- type WideningTarget,
9
- } from "../shared/dictionary-types.ts";
10
-
11
- import type { ESTree, Scope, SourceCode, Variable } from "@oxlint/plugins";
12
-
13
- import { ancestorsOf } from "../shared/ancestors.ts";
14
-
15
- type FunctionExpression = ESTree.ArrowFunctionExpression | ESTree.Function;
16
-
17
- function unwrapExpression(expression: ESTree.Expression): ESTree.Expression {
18
- let current = expression;
19
- while (
20
- current.type === "ParenthesizedExpression" ||
21
- current.type === "TSAsExpression" ||
22
- current.type === "TSSatisfiesExpression" ||
23
- current.type === "TSTypeAssertion" ||
24
- current.type === "TSNonNullExpression"
25
- ) {
26
- current = current.expression;
27
- }
28
- return current;
29
- }
30
-
31
- function resolveVariable(
32
- sourceCode: SourceCode,
33
- identifier: ESTree.IdentifierReference,
34
- ): Variable | null {
35
- let scope: Scope | null = sourceCode.getScope(identifier);
36
- while (scope !== null) {
37
- const variable = scope.set.get(identifier.name);
38
- if (variable !== undefined) return variable;
39
- scope = scope.upper;
40
- }
41
- return null;
42
- }
43
-
44
- function variableDeclarator(variable: Variable): ESTree.VariableDeclarator | null {
45
- if (variable.defs.length !== 1) return null;
46
- const [definition] = variable.defs;
47
- return definition?.type === "Variable" && definition.node.type === "VariableDeclarator"
48
- ? definition.node
49
- : null;
50
- }
51
-
52
- function sourceKeyName(sourceCode: SourceCode, key: ESTree.PropertyKey): string {
53
- if (key.type === "Identifier" || key.type === "PrivateIdentifier") return key.name;
54
- if (key.type === "Literal") return String(key.value);
55
- return sourceCode.getText(key);
56
- }
57
-
58
- function functionName(sourceCode: SourceCode, owner: FunctionExpression | null): string {
59
- if (owner === null) return "anonymous function";
60
- if (owner.id !== null) return owner.id.name;
61
- const parent = ancestorsOf(sourceCode, owner).at(-1);
62
- if (parent?.type === "VariableDeclarator" && parent.id.type === "Identifier")
63
- return parent.id.name;
64
- if (parent?.type === "MethodDefinition") return sourceKeyName(sourceCode, parent.key);
65
- return "anonymous function";
66
- }
67
-
68
- function hasParentAssertion(sourceCode: SourceCode, node: ESTree.Node): boolean {
69
- const parent = ancestorsOf(sourceCode, node).at(-1);
70
- return parent?.type === "TSAsExpression" || parent?.type === "TSTypeAssertion";
71
- }
72
-
73
- /** Detect sound syntactic cases where a known value is explicitly widened and loses evidence. */
74
- export const noKnownValueWideningRule = defineRule({
75
- meta: {
76
- type: "problem",
77
- docs: {
78
- description:
79
- "Disallow syntactically established values from flowing into explicitly broad or anonymous target types that discard useful evidence.",
80
- },
81
- messages: {
82
- widening:
83
- "The explicit {{target}} type on {{subject}} discards known type evidence. Keep inference, validate with `satisfies`, or use a named owner contract.",
84
- },
85
- },
86
- createOnce(context) {
87
- let environment: TypeEnvironment | null = null;
88
-
89
- const reportFlow = (
90
- expression: ESTree.Expression,
91
- destination: WideningTarget | null,
92
- subject: string,
93
- ) => {
94
- if (destination === null) return;
95
- const unwrapped = unwrapExpression(expression);
96
- const accumulator =
97
- destination.kind === "open dictionary" || destination.kind === "generic container";
98
- if (
99
- accumulator &&
100
- unwrapped.type === "ObjectExpression" &&
101
- unwrapped.properties.length === 0
102
- ) {
103
- return;
104
- }
105
- const visit = (expression: ESTree.Expression, visitedVariables: Set<Variable>): boolean => {
106
- if (isKnownEvidenceExpression(expression)) return true;
107
- const unwrapped = unwrapExpression(expression);
108
- if (unwrapped.type !== "Identifier") return false;
109
- const variable = resolveVariable(context.sourceCode, unwrapped);
110
- if (variable === null || visitedVariables.has(variable)) return false;
111
- const declarator = variableDeclarator(variable);
112
- if (declarator === null || declarator.init === null) return false;
113
- const declaration = ancestorsOf(context.sourceCode, declarator).at(-1);
114
- const stableConst =
115
- declaration?.type === "VariableDeclaration" &&
116
- declaration.kind === "const" &&
117
- variable.references.every((reference) => reference.init || !reference.isWrite());
118
- if (!stableConst) return false;
119
- visitedVariables.add(variable);
120
- return visit(declarator.init, visitedVariables);
121
- };
122
- if (!visit(expression, new Set<Variable>())) return;
123
- context.report({
124
- node: expression,
125
- messageId: "widening",
126
- data: { subject, target: destination.kind },
127
- });
128
- };
129
-
130
- const targetFromAnnotation = (
131
- annotation: ESTree.TSTypeAnnotation | null | undefined,
132
- ): WideningTarget | null =>
133
- environment === null || annotation === null || annotation === undefined
134
- ? null
135
- : classifyWideningTarget(annotation.typeAnnotation, environment);
136
-
137
- return {
138
- Program(node) {
139
- environment = createTypeEnvironment(node);
140
- },
141
- VariableDeclarator(node) {
142
- if (node.init === null || node.id.type !== "Identifier") return;
143
- reportFlow(
144
- node.init,
145
- targetFromAnnotation(node.id.typeAnnotation),
146
- `binding \`${node.id.name}\``,
147
- );
148
- },
149
- PropertyDefinition(node) {
150
- if (node.value === null) return;
151
- reportFlow(
152
- node.value,
153
- targetFromAnnotation(node.typeAnnotation),
154
- `property \`${sourceKeyName(context.sourceCode, node.key)}\``,
155
- );
156
- },
157
- AccessorProperty(node) {
158
- if (node.value === null) return;
159
- reportFlow(
160
- node.value,
161
- targetFromAnnotation(node.typeAnnotation),
162
- `property \`${sourceKeyName(context.sourceCode, node.key)}\``,
163
- );
164
- },
165
- AssignmentExpression(node) {
166
- if (node.operator !== "=" || node.left.type !== "Identifier") return;
167
- const variable = resolveVariable(context.sourceCode, node.left);
168
- if (variable === null) return;
169
- const declarator = variableDeclarator(variable);
170
- if (declarator === null || declarator.id.type !== "Identifier") return;
171
- reportFlow(
172
- node.right,
173
- targetFromAnnotation(declarator.id.typeAnnotation),
174
- `binding \`${declarator.id.name}\``,
175
- );
176
- },
177
- ReturnStatement(node) {
178
- if (node.argument === null) return;
179
- let owner: FunctionExpression | null = null;
180
- const ancestors = ancestorsOf(context.sourceCode, node);
181
- for (let index = ancestors.length - 1; index >= 0; index--) {
182
- const current = ancestors[index]!;
183
- if (current.type === "Program") break;
184
- if (
185
- current.type === "ArrowFunctionExpression" ||
186
- current.type === "FunctionDeclaration" ||
187
- current.type === "FunctionExpression"
188
- ) {
189
- owner = current;
190
- break;
191
- }
192
- }
193
- reportFlow(
194
- node.argument,
195
- targetFromAnnotation(owner?.returnType),
196
- `return value of \`${functionName(context.sourceCode, owner)}\``,
197
- );
198
- },
199
- ArrowFunctionExpression(node) {
200
- if (node.body.type === "BlockStatement") return;
201
- reportFlow(
202
- node.body,
203
- targetFromAnnotation(node.returnType),
204
- `return value of \`${functionName(context.sourceCode, node)}\``,
205
- );
206
- },
207
- TSAsExpression(node) {
208
- if (environment === null || hasParentAssertion(context.sourceCode, node)) return;
209
- reportFlow(
210
- node.expression,
211
- classifyWideningTarget(node.typeAnnotation, environment),
212
- "assertion",
213
- );
214
- },
215
- TSTypeAssertion(node) {
216
- if (environment === null || hasParentAssertion(context.sourceCode, node)) return;
217
- reportFlow(
218
- node.expression,
219
- classifyWideningTarget(node.typeAnnotation, environment),
220
- "assertion",
221
- );
222
- },
223
- };
224
- },
225
- });
@@ -1,95 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import type { ESTree, Scope, SourceCode, Variable } from "@oxlint/plugins";
4
- import { ancestorsOf } from "../shared/ancestors.ts";
5
-
6
- const moduleMockMethods = new Set(["doMock", "mock", "unstable_mockModule"]);
7
-
8
- /**
9
- * Whether a callee invokes a test framework's module mocking API
10
- * (`vi.doMock`, `jest.mock`, `vi.unstable_mockModule`), either through the
11
- * global or through a binding imported from vitest / @jest/globals.
12
- *
13
- * @param {SourceCode} sourceCode - The rule's source-code accessor.
14
- * @param {ESTree.Expression} callee - The visited call expression's callee.
15
- * @returns {boolean} True when the call mocks a module.
16
- */
17
- function moduleMockCall(sourceCode: SourceCode, callee: ESTree.Expression): boolean {
18
- if (callee.type !== "MemberExpression") return false;
19
- if (callee.object.type !== "Identifier") return false;
20
- const identifier = callee.object;
21
-
22
- let resolved: Variable | null = null;
23
- let scope: Scope | null = sourceCode.getScope(identifier);
24
- while (scope !== null) {
25
- const variable = scope.set.get(identifier.name);
26
- if (variable !== undefined) {
27
- resolved = variable;
28
- break;
29
- }
30
- scope = scope.upper;
31
- }
32
- const isTestFrameworkName = identifier.name === "vi" || identifier.name === "jest";
33
- let boundToFramework: boolean;
34
- if (resolved === null || resolved.defs.length === 0) {
35
- boundToFramework =
36
- (isTestFrameworkName && sourceCode.isGlobalReference(identifier)) || isTestFrameworkName;
37
- } else {
38
- boundToFramework = resolved.defs.some((definition: Variable["defs"][number]) => {
39
- if (definition.type !== "ImportBinding") return false;
40
- const importDeclaration = ancestorsOf(sourceCode, definition.node).at(-1);
41
- if (importDeclaration?.type !== "ImportDeclaration") return false;
42
- const source = importDeclaration.source.value;
43
- const specifier = definition.node;
44
- const importedName =
45
- specifier.type === "ImportSpecifier"
46
- ? specifier.imported.type === "Identifier"
47
- ? specifier.imported.name
48
- : specifier.imported.value
49
- : null;
50
- return (
51
- (source === "vitest" && importedName === "vi") ||
52
- (source === "@jest/globals" && importedName === "jest")
53
- );
54
- });
55
- }
56
- if (!boundToFramework) return false;
57
-
58
- const property = callee.property;
59
- const method = callee.computed
60
- ? property.type === "Literal" &&
61
- (property.value === "doMock" ||
62
- property.value === "mock" ||
63
- property.value === "unstable_mockModule")
64
- ? property.value
65
- : null
66
- : property.type === "Identifier"
67
- ? property.name
68
- : null;
69
- return method !== null && moduleMockMethods.has(method);
70
- }
71
-
72
- /** Ban test framework module mocking in favor of real dependency seams. */
73
- export const noModuleMockingRule = defineRule({
74
- meta: {
75
- type: "problem",
76
- docs: {
77
- description:
78
- "Disallow Vitest and Jest module mocking; tests must replace dependencies through real interfaces.",
79
- },
80
- messages: {
81
- moduleMock:
82
- "Replace module mocking with dependency injection through a real interface, service layer, or faithful test implementation.",
83
- },
84
- },
85
- createOnce(context) {
86
- return {
87
- CallExpression(node) {
88
- if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression") return;
89
- if (moduleMockCall(context.sourceCode, node.callee)) {
90
- context.report({ node, messageId: "moduleMock" });
91
- }
92
- },
93
- };
94
- },
95
- });