@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
@@ -1,524 +0,0 @@
1
- import type { ESTree } from "@oxlint/plugins";
2
-
3
- const BUILT_INS = new Set([
4
- "Record",
5
- "Readonly",
6
- "Partial",
7
- "Required",
8
- "Pick",
9
- "Omit",
10
- "PropertyKey",
11
- "NonNullable",
12
- ]);
13
- const TRANSPARENT_WRAPPERS = new Set(["Readonly", "Partial", "Required", "NonNullable"]);
14
-
15
- type TypeAliasEnvironment = ReadonlyMap<string, ESTree.TSType>;
16
-
17
- type ResolvedType = {
18
- readonly type: ESTree.TSType;
19
- readonly substitutions: TypeAliasEnvironment;
20
- };
21
-
22
- export type UnsafeDictionary = {
23
- readonly kind: "unsafe-dictionary";
24
- readonly unsafeValue: "any" | "empty-object" | "object" | "union" | "unknown";
25
- };
26
-
27
- export type WideningTargetKind =
28
- | "anonymous object"
29
- | "generic container"
30
- | "object"
31
- | "open dictionary"
32
- | "unknown";
33
-
34
- export type WideningTarget = {
35
- readonly kind: WideningTargetKind;
36
- };
37
-
38
- export type TypeEnvironment = {
39
- readonly aliases: ReadonlyMap<string, ESTree.TSTypeAliasDeclaration>;
40
- readonly interfaces: ReadonlyMap<string, readonly ESTree.TSInterfaceDeclaration[]>;
41
- readonly shadowedBuiltIns: ReadonlySet<string>;
42
- };
43
-
44
- /**
45
- * Build the alias/interface maps for a program so type references can be
46
- * resolved to their declarations during dictionary classification.
47
- * @param {ESTree.Program} program - Root AST node of the file under lint.
48
- * @returns {TypeEnvironment} Environment mapping declared names to their declaration nodes.
49
- */
50
- export function createTypeEnvironment(program: ESTree.Program): TypeEnvironment {
51
- const aliases = new Map<string, ESTree.TSTypeAliasDeclaration>();
52
- const interfaces = new Map<string, ESTree.TSInterfaceDeclaration[]>();
53
- const shadowedBuiltIns = new Set<string>();
54
-
55
- for (const statement of program.body) {
56
- const declaration =
57
- statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration"
58
- ? statement.declaration ?? null
59
- : statement;
60
- if (declaration?.type === "ImportDeclaration") {
61
- for (const specifier of declaration.specifiers) {
62
- if (BUILT_INS.has(specifier.local.name)) shadowedBuiltIns.add(specifier.local.name);
63
- }
64
- continue;
65
- }
66
-
67
- if (declaration?.type === "TSTypeAliasDeclaration") {
68
- const existing = aliases.get(declaration.id.name);
69
- if (existing === undefined) aliases.set(declaration.id.name, declaration);
70
- else shadowedBuiltIns.add(declaration.id.name);
71
- if (BUILT_INS.has(declaration.id.name)) shadowedBuiltIns.add(declaration.id.name);
72
- continue;
73
- }
74
-
75
- if (declaration?.type === "TSInterfaceDeclaration") {
76
- const declarations = interfaces.get(declaration.id.name) ?? [];
77
- declarations.push(declaration);
78
- interfaces.set(declaration.id.name, declarations);
79
- if (BUILT_INS.has(declaration.id.name)) shadowedBuiltIns.add(declaration.id.name);
80
- continue;
81
- }
82
-
83
- if (declaration?.type === "TSEnumDeclaration") {
84
- if (BUILT_INS.has(declaration.id.name)) shadowedBuiltIns.add(declaration.id.name);
85
- continue;
86
- }
87
-
88
- if (
89
- (declaration?.type === "ClassDeclaration" ||
90
- declaration?.type === "FunctionDeclaration") &&
91
- declaration.id !== null
92
- ) {
93
- if (BUILT_INS.has(declaration.id.name)) shadowedBuiltIns.add(declaration.id.name);
94
- }
95
- }
96
-
97
- return { aliases, interfaces, shadowedBuiltIns };
98
- }
99
-
100
- function typeReferenceName(type: ESTree.TSTypeReference): string | null {
101
- return type.typeName.type === "Identifier" ? type.typeName.name : null;
102
- }
103
-
104
- function isBuiltIn(payload: { name: string; environment: TypeEnvironment }): boolean {
105
- return BUILT_INS.has(payload.name) && !payload.environment.shadowedBuiltIns.has(payload.name);
106
- }
107
-
108
- function isUnappliedReferenceTo(payload: { type: ESTree.TSType; name: string }): boolean {
109
- const unwrapped = unwrapTransparentType(payload.type);
110
- return (
111
- unwrapped.type === "TSTypeReference" &&
112
- typeReferenceName(unwrapped) === payload.name &&
113
- (unwrapped.typeArguments === null ||
114
- unwrapped.typeArguments === undefined ||
115
- unwrapped.typeArguments.params.length === 0)
116
- );
117
- }
118
-
119
- function unwrapTransparentType(type: ESTree.TSType): ESTree.TSType {
120
- let current = type;
121
- while (
122
- current.type === "TSParenthesizedType" ||
123
- (current.type === "TSTypeOperator" && current.operator === "readonly")
124
- ) {
125
- current = current.typeAnnotation;
126
- }
127
- return current;
128
- }
129
-
130
- function isEffectivelyEmptyMember(member: ESTree.TSSignature): boolean {
131
- return (
132
- member.type === "TSPropertySignature" &&
133
- member.optional === true &&
134
- member.typeAnnotation !== null &&
135
- member.typeAnnotation !== undefined &&
136
- unwrapTransparentType(member.typeAnnotation.typeAnnotation).type === "TSNeverKeyword"
137
- );
138
- }
139
-
140
- function resolvedSubstitutionArgument(payload: {
141
- type: ESTree.TSType;
142
- base: TypeAliasEnvironment;
143
- resolving?: ReadonlySet<string>;
144
- }): ESTree.TSType {
145
- const { type, base } = payload;
146
- const resolving = payload.resolving ?? new Set<string>();
147
- const unwrapped = unwrapTransparentType(type);
148
- if (unwrapped.type !== "TSTypeReference") return type;
149
- const name = typeReferenceName(unwrapped);
150
- if (name === null || resolving.has(name)) return type;
151
- const substitution = base.get(name);
152
- if (substitution === undefined) return type;
153
- const nextResolving = new Set(resolving);
154
- nextResolving.add(name);
155
- return resolvedSubstitutionArgument({ type: substitution, base, resolving: nextResolving });
156
- }
157
-
158
- function aliasSubstitution(
159
- alias: ESTree.TSTypeAliasDeclaration,
160
- type: ESTree.TSTypeReference,
161
- base: TypeAliasEnvironment,
162
- ): TypeAliasEnvironment | null {
163
- const parameters = alias.typeParameters?.params ?? [];
164
- const arguments_ = type.typeArguments?.params ?? [];
165
- const next = new Map(base);
166
- for (const [index, parameter] of parameters.entries()) {
167
- const argument = arguments_[index] ?? parameter.default;
168
- if (argument === null || argument === undefined) return null;
169
- next.set(parameter.name.name, resolvedSubstitutionArgument({ type: argument, base }));
170
- }
171
- return next;
172
- }
173
-
174
- function unsafeDirectValue(
175
- type: ESTree.TSType,
176
- environment: TypeEnvironment,
177
- substitutions: TypeAliasEnvironment,
178
- resolvingAliases: ReadonlySet<string>,
179
- ): UnsafeDictionary["unsafeValue"] | null {
180
- const unwrapped = unwrapTransparentType(type);
181
- if (unwrapped.type === "TSUnknownKeyword") return "unknown";
182
- if (unwrapped.type === "TSAnyKeyword") return "any";
183
- if (unwrapped.type === "TSObjectKeyword") return "object";
184
- if (
185
- unwrapped.type === "TSTypeLiteral" &&
186
- (unwrapped.members.length === 0 || unwrapped.members.every(isEffectivelyEmptyMember))
187
- )
188
- return "empty-object";
189
- if (unwrapped.type === "TSUnionType") {
190
- return unwrapped.types.some(
191
- (member) => unsafeDirectValue(member, environment, substitutions, resolvingAliases) !== null,
192
- )
193
- ? "union"
194
- : null;
195
- }
196
- if (unwrapped.type === "TSIntersectionType") {
197
- const unsafeMembers = unwrapped.types.map((member) =>
198
- unsafeDirectValue(member, environment, substitutions, resolvingAliases),
199
- );
200
- if (unsafeMembers.includes("any")) return "any";
201
- const [firstUnsafeMember] = unsafeMembers;
202
- return unsafeMembers.length > 0 &&
203
- firstUnsafeMember !== undefined &&
204
- unsafeMembers.every((member) => member !== null)
205
- ? firstUnsafeMember
206
- : null;
207
- }
208
- if (unwrapped.type !== "TSTypeReference") return null;
209
- const name = typeReferenceName(unwrapped);
210
- if (name === null) return null;
211
- if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn({ name, environment })) {
212
- const wrapped = unwrapped.typeArguments?.params[0];
213
- return wrapped === undefined
214
- ? null
215
- : unsafeDirectValue(wrapped, environment, substitutions, resolvingAliases);
216
- }
217
- const substitution = substitutions.get(name);
218
- if (substitution !== undefined) {
219
- return isUnappliedReferenceTo({ type: substitution, name })
220
- ? null
221
- : unsafeDirectValue(substitution, environment, substitutions, resolvingAliases);
222
- }
223
- const interfaceDeclarations = environment.interfaces.get(name);
224
- if (interfaceDeclarations !== undefined) {
225
- const [declaration] = interfaceDeclarations;
226
- const effectivelyEmpty =
227
- interfaceDeclarations.length === 1 &&
228
- declaration !== undefined &&
229
- declaration.extends.length === 0 &&
230
- (declaration.body.body.length === 0 ||
231
- declaration.body.body.every(isEffectivelyEmptyMember));
232
- return effectivelyEmpty ? "empty-object" : null;
233
- }
234
- const alias = environment.aliases.get(name);
235
- if (alias === undefined || resolvingAliases.has(name)) return null;
236
- const nextSubstitutions = aliasSubstitution(alias, unwrapped, substitutions);
237
- if (nextSubstitutions === null) return null;
238
- const nextResolving = new Set(resolvingAliases);
239
- nextResolving.add(name);
240
- return unsafeDirectValue(alias.typeAnnotation, environment, nextSubstitutions, nextResolving);
241
- }
242
-
243
- function dictionaryValueTypes(
244
- type: ESTree.TSType,
245
- environment: TypeEnvironment,
246
- substitutions: TypeAliasEnvironment,
247
- resolvingAliases: ReadonlySet<string>,
248
- ): readonly ResolvedType[] {
249
- const unwrapped = unwrapTransparentType(type);
250
-
251
- if (unwrapped.type === "TSTypeLiteral") {
252
- return unwrapped.members.flatMap((member): readonly ResolvedType[] =>
253
- member.type === "TSIndexSignature" && member.typeAnnotation !== null
254
- ? [{ type: member.typeAnnotation.typeAnnotation, substitutions }]
255
- : [],
256
- );
257
- }
258
-
259
- if (unwrapped.type === "TSMappedType") {
260
- return unwrapped.typeAnnotation === null
261
- ? []
262
- : [{ type: unwrapped.typeAnnotation, substitutions }];
263
- }
264
-
265
- if (unwrapped.type !== "TSTypeReference") return [];
266
- const name = typeReferenceName(unwrapped);
267
- if (name === null) return [];
268
-
269
- const substitution = substitutions.get(name);
270
- if (substitution !== undefined) {
271
- return isUnappliedReferenceTo({ type: substitution, name })
272
- ? []
273
- : dictionaryValueTypes(substitution, environment, substitutions, resolvingAliases);
274
- }
275
-
276
- if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn({ name, environment })) {
277
- const wrapped = unwrapped.typeArguments?.params[0];
278
- return wrapped === undefined
279
- ? []
280
- : dictionaryValueTypes(wrapped, environment, substitutions, resolvingAliases);
281
- }
282
-
283
- if (name === "Record" && isBuiltIn({ name, environment })) {
284
- const value = unwrapped.typeArguments?.params[1] ?? null;
285
- return value === null ? [] : [{ type: value, substitutions }];
286
- }
287
-
288
- if ((name === "Pick" || name === "Omit") && isBuiltIn({ name, environment })) {
289
- const source = unwrapped.typeArguments?.params[0];
290
- return source === undefined
291
- ? []
292
- : dictionaryValueTypes(source, environment, substitutions, resolvingAliases);
293
- }
294
-
295
- const alias = environment.aliases.get(name);
296
- if (alias === undefined || resolvingAliases.has(name)) return [];
297
- const nextSubstitutions = aliasSubstitution(alias, unwrapped, substitutions);
298
- if (nextSubstitutions === null) return [];
299
- const nextResolving = new Set(resolvingAliases);
300
- nextResolving.add(name);
301
- return dictionaryValueTypes(alias.typeAnnotation, environment, nextSubstitutions, nextResolving);
302
- }
303
-
304
- /**
305
- * Classify a single type as an unsafe dictionary value, if it is one.
306
- * @param {ESTree.TSType} valueType - Type annotation of the dictionary value slot.
307
- * @param {TypeEnvironment} environment - Declared-alias environment from createTypeEnvironment.
308
- * @returns {UnsafeDictionary | null} The unsafe kind ("any", "unknown", "object", "empty-object") or null.
309
- */
310
- export function classifyUnsafeDictionaryValue(
311
- valueType: ESTree.TSType,
312
- environment: TypeEnvironment,
313
- ): UnsafeDictionary | null {
314
- const unsafeValue = unsafeDirectValue(valueType, environment, new Map(), new Set());
315
- return unsafeValue === null ? null : { kind: "unsafe-dictionary", unsafeValue };
316
- }
317
-
318
- /**
319
- * Classify the value side of an index-signature or Record dictionary.
320
- * @param {ESTree.TSType} type - The dictionary type node being inspected.
321
- * @param {TypeEnvironment} environment - Declared-alias environment from createTypeEnvironment.
322
- * @returns {UnsafeDictionary | null} Classification with kind and location, or null when safe.
323
- */
324
- export function classifyUnsafeDictionary(
325
- type: ESTree.TSType,
326
- environment: TypeEnvironment,
327
- ): UnsafeDictionary | null {
328
- for (const valueType of dictionaryValueTypes(type, environment, new Map(), new Set())) {
329
- const unsafeValue = unsafeDirectValue(
330
- valueType.type,
331
- environment,
332
- valueType.substitutions,
333
- new Set(),
334
- );
335
- if (unsafeValue !== null) return { kind: "unsafe-dictionary", unsafeValue };
336
- }
337
- return null;
338
- }
339
-
340
- /**
341
- * Describe what a widening assignment erases, for report messaging.
342
- * @param {ESTree.TSType} type - The assigned (widened) type.
343
- * @param {TypeEnvironment} environment - Declared-alias environment from createTypeEnvironment.
344
- * @returns {WideningTarget | null} Human-readable target description, or null when not a widening.
345
- */
346
- export function classifyWideningTarget(
347
- type: ESTree.TSType,
348
- environment: TypeEnvironment,
349
- ): WideningTarget | null {
350
- const unwrapped = unwrapTransparentType(type);
351
- if (unwrapped.type === "TSUnknownKeyword") return { kind: "unknown" };
352
- if (unwrapped.type === "TSObjectKeyword") return { kind: "object" };
353
- if (unwrapped.type === "TSTypeLiteral") {
354
- return unwrapped.members.some((member) => member.type === "TSIndexSignature")
355
- ? { kind: "open dictionary" }
356
- : unwrapped.members.length > 0
357
- ? { kind: "anonymous object" }
358
- : null;
359
- }
360
- if (unwrapped.type === "TSMappedType") return { kind: "open dictionary" };
361
- if (unwrapped.type !== "TSTypeReference") return null;
362
- const name = typeReferenceName(unwrapped);
363
- if (name === null) return null;
364
- if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn({ name, environment })) {
365
- const wrapped = unwrapped.typeArguments?.params[0];
366
- return wrapped === undefined ? null : classifyWideningTarget(wrapped, environment);
367
- }
368
- if (name === "Record" && isBuiltIn({ name, environment })) return { kind: "open dictionary" };
369
- const alias = environment.aliases.get(name);
370
- if (alias === undefined) return null;
371
- if ((alias.typeParameters?.params.length ?? 0) > 0) {
372
- const substitutions = aliasSubstitution(alias, unwrapped, new Map());
373
- const resolves =
374
- substitutions !== null &&
375
- dictionaryValueTypes(
376
- alias.typeAnnotation,
377
- environment,
378
- substitutions,
379
- new Set([name]),
380
- ).length > 0;
381
- return resolves ? { kind: "generic container" } : null;
382
- }
383
- const substitutions = aliasSubstitution(alias, unwrapped, new Map());
384
- if (substitutions === null) return null;
385
- const resolved = classifyAliasBroadTarget(
386
- alias.typeAnnotation,
387
- environment,
388
- substitutions,
389
- new Set([name]),
390
- );
391
- return resolved;
392
- }
393
-
394
- function isBroadMappedKey(
395
- type: ESTree.TSType,
396
- environment: TypeEnvironment,
397
- substitutions: TypeAliasEnvironment,
398
- ): boolean {
399
- const unwrapped = unwrapTransparentType(type);
400
- if (
401
- unwrapped.type === "TSStringKeyword" ||
402
- unwrapped.type === "TSNumberKeyword" ||
403
- unwrapped.type === "TSSymbolKeyword"
404
- ) {
405
- return true;
406
- }
407
- if (unwrapped.type === "TSUnionType") {
408
- return unwrapped.types.every((member) =>
409
- isBroadMappedKey(member, environment, substitutions),
410
- );
411
- }
412
- if (unwrapped.type !== "TSTypeReference") return false;
413
- const name = typeReferenceName(unwrapped);
414
- if (name === null) return false;
415
- const substitution = substitutions.get(name);
416
- if (substitution !== undefined && !isUnappliedReferenceTo({ type: substitution, name })) {
417
- return isBroadMappedKey(substitution, environment, substitutions);
418
- }
419
- return name === "PropertyKey" && isBuiltIn({ name, environment });
420
- }
421
-
422
- function classifyAliasBroadTarget(
423
- type: ESTree.TSType,
424
- environment: TypeEnvironment,
425
- substitutions: TypeAliasEnvironment,
426
- resolvingAliases: ReadonlySet<string>,
427
- ): WideningTarget | null {
428
- const unwrapped = unwrapTransparentType(type);
429
- if (unwrapped.type === "TSUnknownKeyword") return { kind: "unknown" };
430
- if (unwrapped.type === "TSObjectKeyword") return { kind: "object" };
431
- if (unwrapped.type === "TSTypeLiteral") {
432
- return unwrapped.members.some((member) => member.type === "TSIndexSignature")
433
- ? { kind: "open dictionary" }
434
- : null;
435
- }
436
- if (unwrapped.type === "TSMappedType") {
437
- return isBroadMappedKey(unwrapped.constraint, environment, substitutions)
438
- ? { kind: "open dictionary" }
439
- : null;
440
- }
441
- if (unwrapped.type !== "TSTypeReference") return null;
442
- const name = typeReferenceName(unwrapped);
443
- if (name === null) return null;
444
- const substitution = substitutions.get(name);
445
- if (substitution !== undefined) {
446
- return isUnappliedReferenceTo({ type: substitution, name })
447
- ? null
448
- : classifyAliasBroadTarget(
449
- substitution,
450
- environment,
451
- substitutions,
452
- resolvingAliases,
453
- );
454
- }
455
- if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn({ name, environment })) {
456
- const wrapped = unwrapped.typeArguments?.params[0];
457
- return wrapped === undefined
458
- ? null
459
- : classifyAliasBroadTarget(wrapped, environment, substitutions, resolvingAliases);
460
- }
461
- if (name === "Record" && isBuiltIn({ name, environment })) {
462
- return { kind: "open dictionary" };
463
- }
464
- const alias = environment.aliases.get(name);
465
- if (alias === undefined || resolvingAliases.has(name)) return null;
466
- const nextSubstitutions = aliasSubstitution(alias, unwrapped, substitutions);
467
- if (nextSubstitutions === null) return null;
468
- const nextResolving = new Set(resolvingAliases);
469
- nextResolving.add(name);
470
- return classifyAliasBroadTarget(
471
- alias.typeAnnotation,
472
- environment,
473
- nextSubstitutions,
474
- nextResolving,
475
- );
476
- }
477
-
478
- /**
479
- * Whether an expression is an object literal carrying at least one property.
480
- * @param {ESTree.Expression} expression - Candidate expression node.
481
- * @returns {boolean} True only for ObjectExpression nodes with members.
482
- */
483
- export function isPopulatedObjectExpression(expression: ESTree.Expression): boolean {
484
- let current = expression;
485
- while (
486
- current.type === "ParenthesizedExpression" ||
487
- current.type === "TSAsExpression" ||
488
- current.type === "TSTypeAssertion" ||
489
- current.type === "TSNonNullExpression"
490
- ) {
491
- current = current.expression;
492
- }
493
- return current.type === "ObjectExpression" && current.properties.length > 0;
494
- }
495
-
496
- /**
497
- * Whether an expression carries first-hand type evidence (schema parse,
498
- * literal, typed constructor) and therefore needs no further guarding.
499
- * @param {ESTree.Expression} expression - Candidate expression node.
500
- * @returns {boolean} True when the expression is self-evidencing.
501
- */
502
- export function isKnownEvidenceExpression(expression: ESTree.Expression): boolean {
503
- let current = expression;
504
- while (
505
- current.type === "ParenthesizedExpression" ||
506
- current.type === "TSAsExpression" ||
507
- current.type === "TSTypeAssertion" ||
508
- current.type === "TSNonNullExpression" ||
509
- current.type === "TSSatisfiesExpression"
510
- ) {
511
- current = current.expression;
512
- }
513
- if (current.type === "ObjectExpression") return true;
514
- return (
515
- current.type === "ArrayExpression" ||
516
- current.type === "ArrowFunctionExpression" ||
517
- current.type === "ClassExpression" ||
518
- current.type === "FunctionExpression" ||
519
- current.type === "NewExpression" ||
520
- current.type === "Literal" ||
521
- current.type === "TemplateLiteral" ||
522
- current.type === "UnaryExpression"
523
- );
524
- }
@@ -1,62 +0,0 @@
1
- import type { ESTree } from "@oxlint/plugins";
2
- import { isNode } from "./is-node.ts";
3
- import type { NodeFieldValue } from "../shared/structural.ts";
4
- import { readField } from "../shared/structural.ts";
5
-
6
- type VisitorKeys = Readonly<Record<string, readonly string[]>>;
7
-
8
- function collectInferTypeParameterNames(
9
- node: ESTree.Node,
10
- visitorKeys: VisitorKeys,
11
- names: Set<string>,
12
- ): void {
13
- if (node.type === "TSInferType") names.add(node.typeParameter.name.name);
14
- for (const key of visitorKeys[node.type] ?? []) {
15
- const value = readField(node, key);
16
- if (isNode(value)) {
17
- collectInferTypeParameterNames(value, visitorKeys, names);
18
- continue;
19
- }
20
- if (!Array.isArray(value)) continue;
21
- for (const child of value) {
22
- if (isNode(child)) collectInferTypeParameterNames(child, visitorKeys, names);
23
- }
24
- }
25
- }
26
-
27
- /**
28
- * Collect type binders that are in scope at a node and can shadow module aliases.
29
- *
30
- * @param {ESTree.Node} node - The node whose lexical scope is being resolved.
31
- * @param {ReadonlyArray<ESTree.Node>} ancestors - Nearest-first ancestor chain of `node`.
32
- * @param {VisitorKeys} visitorKeys - Grammar keys used to descend conditional types.
33
- * @returns {ReadonlySet<string>} Names of in-scope type binders.
34
- */
35
- export function lexicalTypeParameterNames(
36
- node: ESTree.Node,
37
- ancestors: ReadonlyArray<ESTree.Node>,
38
- visitorKeys: VisitorKeys,
39
- ): ReadonlySet<string> {
40
- const names = new Set<string>();
41
- const chain: Array<ESTree.Node> = [node, ...[...ancestors].reverse()];
42
- for (let index = 1; index < chain.length; index += 1) {
43
- const current = chain[index]!;
44
- if (current.type === "Program") break;
45
- const descendant = chain[index - 1]!;
46
- if ("typeParameters" in current) {
47
- for (const parameter of current.typeParameters?.params ?? []) {
48
- names.add(parameter.name.name);
49
- }
50
- }
51
- if (
52
- current.type === "TSMappedType" &&
53
- (descendant === current.nameType || descendant === current.typeAnnotation)
54
- ) {
55
- names.add(current.key.name);
56
- }
57
- if (current.type === "TSConditionalType" && descendant === current.trueType) {
58
- collectInferTypeParameterNames(current.extendsType, visitorKeys, names);
59
- }
60
- }
61
- return names;
62
- }
@@ -1,41 +0,0 @@
1
- import type { ESTree, Scope, SourceCode, Variable } from "@oxlint/plugins";
2
-
3
- interface ReflectMethodCallInput {
4
- sourceCode: SourceCode;
5
- callee: ESTree.Expression;
6
- methodName: string;
7
- }
8
-
9
- /** Reports whether a call target names one method on the global Reflect object.
10
- *
11
- * @param {SourceCode} sourceCode - The rule's source-code accessor.
12
- * @param {ESTree.Expression} callee - The callee expression of the call.
13
- * @param {string} methodName - The Reflect method name to match.
14
- * @returns {boolean} True when the call targets the global `Reflect`.
15
- */
16
- export function isGlobalReflectMethodCall({
17
- sourceCode,
18
- callee,
19
- methodName,
20
- }: ReflectMethodCallInput): boolean {
21
- if (!("property" in callee) || !("object" in callee) || !("computed" in callee)) return false;
22
- const object = callee.object;
23
- if (object.type !== "Identifier" || object.name !== "Reflect") return false;
24
- if (!sourceCode.isGlobalReference(object)) {
25
- let resolved: Variable | null = null;
26
- let scope: Scope | null = sourceCode.getScope(object);
27
- while (scope !== null) {
28
- const variable = scope.set.get(object.name);
29
- if (variable !== undefined) {
30
- resolved = variable;
31
- break;
32
- }
33
- scope = scope.upper;
34
- }
35
- if (resolved !== null && resolved.defs.length > 0) return false;
36
- }
37
- const property = callee.property;
38
- return callee.computed
39
- ? property.type === "Literal" && property.value === methodName
40
- : property.type === "Identifier" && property.name === methodName;
41
- }
@@ -1,68 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- import { RuleTester } from "oxlint/plugins-dev";
3
- import { describe, expect, it } from "vitest";
4
-
5
- import { testableRule } from "./testable-rule.ts";
6
-
7
- const tinyRule = defineRule({
8
- meta: {
9
- messages: { hit: "hit" },
10
- },
11
- createOnce(context) {
12
- return {
13
- before() {
14
- if (context.filename.includes("skipped")) return false;
15
- },
16
- CallExpression(node) {
17
- context.report({ node, messageId: "hit" });
18
- },
19
- };
20
- },
21
- });
22
-
23
- const tester = new RuleTester();
24
-
25
- tester.run(
26
- "testableRule end-to-end",
27
- // SAFETY: bridging across the two Rule declarations (plugins vs plugins-dev)
28
- // is the adapter's documented purpose.
29
- testableRule(tinyRule) as never,
30
- {
31
- valid: [{ code: `foo();`, filename: "skipped/mine.ts" }],
32
- invalid: [{ code: `foo();`, errors: [{ messageId: "hit" }] }],
33
- },
34
- );
35
-
36
- describe("testableRule", () => {
37
- it("passes plain ESLint-style rules through untouched", () => {
38
- const plain = { meta: {}, create: () => ({}) };
39
- expect(testableRule(plain as never)).toBe(plain);
40
- });
41
-
42
- it("chains the rule's own Program:exit with the after hook, in order", () => {
43
- const calls: string[] = [];
44
- const rule = defineRule({
45
- meta: { messages: {} },
46
- createOnce() {
47
- return {
48
- after() {
49
- calls.push("after");
50
- },
51
- "Program:exit"() {
52
- calls.push("rule-exit");
53
- },
54
- };
55
- },
56
- });
57
- // SAFETY: structural view of the adapted rule for direct invocation.
58
- const adapted = testableRule(rule) as unknown as {
59
- create(context: never): Record<string, (() => void) | undefined>;
60
- };
61
- const context = null as never;
62
- const visitor = adapted.create(context);
63
- const programExit = visitor["Program:exit"];
64
- if (programExit === undefined) throw new Error("missing Program:exit hook");
65
- programExit();
66
- expect(calls).toEqual(["rule-exit", "after"]);
67
- });
68
- });