@autotelic/plumb 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) hide show
  1. package/README.md +81 -8
  2. package/dist/configs/recommended-rules.d.ts +36 -0
  3. package/dist/configs/recommended-rules.js +57 -0
  4. package/dist/effect/rules/guarded-op-must-return-effect.js +1 -1
  5. package/dist/effect/rules/no-cascading-layer-provide.js +1 -1
  6. package/dist/effect/rules/no-decode-unknown-option.js +1 -1
  7. package/dist/effect/rules/no-direct-browser-storage.js +3 -3
  8. package/dist/effect/rules/no-direct-fetch.js +1 -1
  9. package/dist/effect/rules/no-manual-field-guards.js +1 -1
  10. package/dist/effect/rules/no-nested-layer-provide.js +1 -1
  11. package/dist/effect/rules/no-nullish-default-on-partial-input.js +2 -2
  12. package/dist/effect/rules/no-raw-error-forwarding.d.ts +4 -0
  13. package/dist/effect/rules/no-raw-error-forwarding.js +7 -2
  14. package/dist/effect/rules/no-silent-error-swallow.js +1 -1
  15. package/dist/effect/rules/no-static-effect-service-forwarders.js +5 -4
  16. package/dist/effect/rules/no-try-catch.js +1 -1
  17. package/dist/effect/rules/no-unguarded-json-parse.js +1 -1
  18. package/dist/effect/rules/option-core-needs-effect-public.js +1 -1
  19. package/dist/effect/rules/prefer-die-for-precondition-defects.js +1 -1
  20. package/dist/effect/rules/prefer-effect-gen-for-guard-ladders.js +1 -1
  21. package/dist/effect/rules/prefer-effect-match.js +2 -2
  22. package/dist/effect/rules/prefer-effect-predicate-over-boolean-function.js +1 -1
  23. package/dist/effect/rules/prefer-named-guard-predicate.js +1 -1
  24. package/dist/effect/rules/prefer-option-pipeline.js +13 -12
  25. package/dist/effect/rules/prefer-ordering-match.js +1 -1
  26. package/dist/effect/rules/prefer-tagged-enum.js +1 -1
  27. package/dist/effect/rules/require-schema-type-derivation.d.ts +8 -2
  28. package/dist/effect/rules/require-schema-type-derivation.js +14 -4
  29. package/dist/index.js +8 -0
  30. package/dist/react/rules/require-dot-notation-exports.js +1 -1
  31. package/dist/react/rules/require-guarded-context-hook.js +1 -1
  32. package/dist/react/rules/require-tripartite-context.js +1 -1
  33. package/dist/react/rules/use-encapsulation.js +1 -1
  34. package/dist/rules/no-adapter-in-values.d.ts +12 -0
  35. package/dist/rules/no-adapter-in-values.js +110 -0
  36. package/dist/rules/no-builtin-throws.js +1 -1
  37. package/dist/rules/no-duplicated-literal-union.d.ts +7 -0
  38. package/dist/rules/no-duplicated-literal-union.js +5 -1
  39. package/dist/rules/no-generic-export-names.js +1 -1
  40. package/dist/rules/no-multiple-function-params.js +26 -12
  41. package/dist/rules/no-mutable-environment-capture.js +2 -2
  42. package/dist/rules/no-nondeterministic-core.js +1 -1
  43. package/dist/rules/no-nullable-value-field.d.ts +16 -0
  44. package/dist/rules/no-nullable-value-field.js +117 -0
  45. package/dist/rules/no-optional-function-parameters.js +1 -1
  46. package/dist/rules/no-row-coercion.d.ts +13 -0
  47. package/dist/rules/no-row-coercion.js +135 -0
  48. package/dist/rules/no-single-use-private-functions.js +1 -1
  49. package/dist/rules/no-sql-string-interpolation.js +2 -2
  50. package/dist/rules/no-stray-inline-comments.js +1 -1
  51. package/dist/rules/no-string-instant.d.ts +15 -0
  52. package/dist/rules/no-string-instant.js +108 -0
  53. package/dist/rules/no-swappable-primitive-params.js +1 -1
  54. package/dist/rules/no-tag-ladder-assertions.js +1 -1
  55. package/dist/rules/no-vague-test-filenames.js +1 -1
  56. package/dist/rules/prefer-property-tests.d.ts +5 -0
  57. package/dist/rules/prefer-property-tests.js +7 -0
  58. package/dist/rules/require-jsdoc-on-exported.js +1 -1
  59. package/dist/shared/ancestors.d.ts +1 -1
  60. package/dist/shared/ancestors.js +1 -1
  61. package/dist/shared/values-path.d.ts +12 -0
  62. package/dist/shared/values-path.js +56 -0
  63. package/dist/src/configs/recommended-rules.d.ts +20 -0
  64. package/dist/src/configs/recommended-rules.js +22 -0
  65. package/dist/src/effect/index.d.ts +3 -0
  66. package/dist/src/effect/index.js +60 -0
  67. package/dist/src/effect/rules/guarded-op-must-return-effect.d.ts +6 -0
  68. package/dist/src/effect/rules/guarded-op-must-return-effect.js +235 -0
  69. package/dist/src/effect/rules/guarded-op-must-return-option.d.ts +2 -0
  70. package/dist/src/effect/rules/guarded-op-must-return-option.js +88 -0
  71. package/dist/src/effect/rules/no-cascading-layer-provide.d.ts +6 -0
  72. package/dist/src/effect/rules/no-cascading-layer-provide.js +73 -0
  73. package/dist/src/effect/rules/no-decode-unknown-option.d.ts +7 -0
  74. package/dist/src/effect/rules/no-decode-unknown-option.js +34 -0
  75. package/dist/src/effect/rules/no-direct-browser-storage.d.ts +2 -0
  76. package/dist/src/effect/rules/no-direct-browser-storage.js +88 -0
  77. package/dist/src/effect/rules/no-direct-fetch.d.ts +2 -0
  78. package/dist/src/effect/rules/no-direct-fetch.js +37 -0
  79. package/dist/src/effect/rules/no-manual-field-guards.d.ts +6 -0
  80. package/dist/src/effect/rules/no-manual-field-guards.js +129 -0
  81. package/dist/src/effect/rules/no-nested-layer-provide.d.ts +2 -0
  82. package/dist/src/effect/rules/no-nested-layer-provide.js +50 -0
  83. package/dist/src/effect/rules/no-nullish-default-on-partial-input.d.ts +13 -0
  84. package/dist/src/effect/rules/no-nullish-default-on-partial-input.js +109 -0
  85. package/dist/src/effect/rules/no-raw-error-forwarding.d.ts +12 -0
  86. package/dist/src/effect/rules/no-raw-error-forwarding.js +103 -0
  87. package/dist/src/effect/rules/no-schema-class-modeling.d.ts +2 -0
  88. package/dist/src/effect/rules/no-schema-class-modeling.js +52 -0
  89. package/dist/src/effect/rules/no-service-constructor-imports.d.ts +2 -0
  90. package/dist/src/effect/rules/no-service-constructor-imports.js +42 -0
  91. package/dist/src/effect/rules/no-silent-error-swallow.d.ts +2 -0
  92. package/dist/src/effect/rules/no-silent-error-swallow.js +95 -0
  93. package/dist/src/effect/rules/no-static-effect-service-forwarders.d.ts +6 -0
  94. package/dist/src/effect/rules/no-static-effect-service-forwarders.js +222 -0
  95. package/dist/src/effect/rules/no-try-catch.d.ts +2 -0
  96. package/dist/src/effect/rules/no-try-catch.js +30 -0
  97. package/dist/src/effect/rules/no-unguarded-json-parse.d.ts +5 -0
  98. package/dist/src/effect/rules/no-unguarded-json-parse.js +200 -0
  99. package/dist/src/effect/rules/option-core-needs-effect-public.d.ts +5 -0
  100. package/dist/src/effect/rules/option-core-needs-effect-public.js +76 -0
  101. package/dist/src/effect/rules/prefer-die-for-precondition-defects.d.ts +5 -0
  102. package/dist/src/effect/rules/prefer-die-for-precondition-defects.js +112 -0
  103. package/dist/src/effect/rules/prefer-effect-gen-for-guard-ladders.d.ts +5 -0
  104. package/dist/src/effect/rules/prefer-effect-gen-for-guard-ladders.js +72 -0
  105. package/dist/src/effect/rules/prefer-effect-match.d.ts +2 -0
  106. package/dist/src/effect/rules/prefer-effect-match.js +74 -0
  107. package/dist/src/effect/rules/prefer-effect-predicate-over-boolean-function.d.ts +2 -0
  108. package/dist/src/effect/rules/prefer-effect-predicate-over-boolean-function.js +75 -0
  109. package/dist/src/effect/rules/prefer-named-guard-predicate.d.ts +2 -0
  110. package/dist/src/effect/rules/prefer-named-guard-predicate.js +93 -0
  111. package/dist/src/effect/rules/prefer-option-pipeline.d.ts +2 -0
  112. package/dist/src/effect/rules/prefer-option-pipeline.js +87 -0
  113. package/dist/src/effect/rules/prefer-ordering-match.d.ts +2 -0
  114. package/dist/src/effect/rules/prefer-ordering-match.js +135 -0
  115. package/dist/src/effect/rules/prefer-tagged-enum.d.ts +2 -0
  116. package/dist/src/effect/rules/prefer-tagged-enum.js +66 -0
  117. package/dist/src/effect/rules/require-schema-type-derivation.d.ts +7 -0
  118. package/dist/src/effect/rules/require-schema-type-derivation.js +80 -0
  119. package/dist/src/index.d.ts +3 -0
  120. package/dist/src/index.js +106 -0
  121. package/dist/src/meta/index.d.ts +7 -0
  122. package/dist/src/meta/index.js +22 -0
  123. package/dist/src/meta/rules/no-disable-directives.d.ts +6 -0
  124. package/dist/src/meta/rules/no-disable-directives.js +35 -0
  125. package/dist/src/meta/rules/no-manual-ancestor-walks.d.ts +2 -0
  126. package/dist/src/meta/rules/no-manual-ancestor-walks.js +26 -0
  127. package/dist/src/meta/rules/prefer-before-file-scope.d.ts +2 -0
  128. package/dist/src/meta/rules/prefer-before-file-scope.js +57 -0
  129. package/dist/src/meta/rules/require-create-once.d.ts +2 -0
  130. package/dist/src/meta/rules/require-create-once.js +51 -0
  131. package/dist/src/meta/rules/require-rule-tester.d.ts +2 -0
  132. package/dist/src/meta/rules/require-rule-tester.js +50 -0
  133. package/dist/src/react/index.d.ts +3 -0
  134. package/dist/src/react/index.js +16 -0
  135. package/dist/src/react/role.d.ts +23 -0
  136. package/dist/src/react/role.js +30 -0
  137. package/dist/src/react/rules/require-dot-notation-exports.d.ts +27 -0
  138. package/dist/src/react/rules/require-dot-notation-exports.js +144 -0
  139. package/dist/src/react/rules/require-guarded-context-hook.d.ts +19 -0
  140. package/dist/src/react/rules/require-guarded-context-hook.js +167 -0
  141. package/dist/src/react/rules/require-tripartite-context.d.ts +17 -0
  142. package/dist/src/react/rules/require-tripartite-context.js +160 -0
  143. package/dist/src/react/rules/use-encapsulation.d.ts +22 -0
  144. package/dist/src/react/rules/use-encapsulation.js +97 -0
  145. package/dist/src/rules/no-anonymous-wide-tuples.d.ts +7 -0
  146. package/dist/src/rules/no-anonymous-wide-tuples.js +34 -0
  147. package/dist/src/rules/no-barrel-export-star.d.ts +2 -0
  148. package/dist/src/rules/no-barrel-export-star.js +26 -0
  149. package/dist/src/rules/no-boolean-field-signals.d.ts +2 -0
  150. package/dist/src/rules/no-boolean-field-signals.js +279 -0
  151. package/dist/src/rules/no-builtin-throws.d.ts +6 -0
  152. package/dist/src/rules/no-builtin-throws.js +74 -0
  153. package/dist/src/rules/no-chained-type-assertions.d.ts +2 -0
  154. package/dist/src/rules/no-chained-type-assertions.js +54 -0
  155. package/dist/src/rules/no-conditional-empty-object-spread.d.ts +2 -0
  156. package/dist/src/rules/no-conditional-empty-object-spread.js +36 -0
  157. package/dist/src/rules/no-duplicated-literal-union.d.ts +6 -0
  158. package/dist/src/rules/no-duplicated-literal-union.js +66 -0
  159. package/dist/src/rules/no-exported-mutable-state.d.ts +7 -0
  160. package/dist/src/rules/no-exported-mutable-state.js +104 -0
  161. package/dist/src/rules/no-generic-export-names.d.ts +2 -0
  162. package/dist/src/rules/no-generic-export-names.js +141 -0
  163. package/dist/src/rules/no-impossible-branch-throw.d.ts +2 -0
  164. package/dist/src/rules/no-impossible-branch-throw.js +51 -0
  165. package/dist/src/rules/no-known-value-widening.d.ts +2 -0
  166. package/dist/src/rules/no-known-value-widening.js +176 -0
  167. package/dist/src/rules/no-module-mocking.d.ts +2 -0
  168. package/dist/src/rules/no-module-mocking.js +90 -0
  169. package/dist/src/rules/no-multiple-function-params.d.ts +2 -0
  170. package/dist/src/rules/no-multiple-function-params.js +155 -0
  171. package/dist/src/rules/no-mutable-environment-capture.d.ts +7 -0
  172. package/dist/src/rules/no-mutable-environment-capture.js +134 -0
  173. package/dist/src/rules/no-nondeterministic-core.d.ts +6 -0
  174. package/dist/src/rules/no-nondeterministic-core.js +63 -0
  175. package/dist/src/rules/no-object-parameters.d.ts +2 -0
  176. package/dist/src/rules/no-object-parameters.js +95 -0
  177. package/dist/src/rules/no-optional-function-parameters.d.ts +7 -0
  178. package/dist/src/rules/no-optional-function-parameters.js +44 -0
  179. package/dist/src/rules/no-product-of-state-booleans.d.ts +2 -0
  180. package/dist/src/rules/no-product-of-state-booleans.js +79 -0
  181. package/dist/src/rules/no-redundant-derived-field.d.ts +6 -0
  182. package/dist/src/rules/no-redundant-derived-field.js +194 -0
  183. package/dist/src/rules/no-reflect-apply.d.ts +2 -0
  184. package/dist/src/rules/no-reflect-apply.js +29 -0
  185. package/dist/src/rules/no-reflect-get.d.ts +2 -0
  186. package/dist/src/rules/no-reflect-get.js +29 -0
  187. package/dist/src/rules/no-reinterpret-cast.d.ts +2 -0
  188. package/dist/src/rules/no-reinterpret-cast.js +68 -0
  189. package/dist/src/rules/no-runtime-typeof.d.ts +2 -0
  190. package/dist/src/rules/no-runtime-typeof.js +54 -0
  191. package/dist/src/rules/no-sentinel-comparison-union.d.ts +2 -0
  192. package/dist/src/rules/no-sentinel-comparison-union.js +139 -0
  193. package/dist/src/rules/no-shape-in-symbol-names.d.ts +2 -0
  194. package/dist/src/rules/no-shape-in-symbol-names.js +39 -0
  195. package/dist/src/rules/no-single-use-private-functions.d.ts +17 -0
  196. package/dist/src/rules/no-single-use-private-functions.js +419 -0
  197. package/dist/src/rules/no-sql-string-interpolation.d.ts +7 -0
  198. package/dist/src/rules/no-sql-string-interpolation.js +62 -0
  199. package/dist/src/rules/no-stacked-jsdoc-blocks.d.ts +2 -0
  200. package/dist/src/rules/no-stacked-jsdoc-blocks.js +50 -0
  201. package/dist/src/rules/no-stray-inline-comments.d.ts +2 -0
  202. package/dist/src/rules/no-stray-inline-comments.js +74 -0
  203. package/dist/src/rules/no-swappable-primitive-params.d.ts +2 -0
  204. package/dist/src/rules/no-swappable-primitive-params.js +96 -0
  205. package/dist/src/rules/no-tag-ladder-assertions.d.ts +6 -0
  206. package/dist/src/rules/no-tag-ladder-assertions.js +63 -0
  207. package/dist/src/rules/no-transposed-field-reads.d.ts +8 -0
  208. package/dist/src/rules/no-transposed-field-reads.js +101 -0
  209. package/dist/src/rules/no-unit-return-validators.d.ts +2 -0
  210. package/dist/src/rules/no-unit-return-validators.js +64 -0
  211. package/dist/src/rules/no-unknown-parameters.d.ts +2 -0
  212. package/dist/src/rules/no-unknown-parameters.js +82 -0
  213. package/dist/src/rules/no-unknown-returns.d.ts +2 -0
  214. package/dist/src/rules/no-unknown-returns.js +86 -0
  215. package/dist/src/rules/no-unknown-type-aliases.d.ts +2 -0
  216. package/dist/src/rules/no-unknown-type-aliases.js +64 -0
  217. package/dist/src/rules/no-unsafe-dictionary-type.d.ts +2 -0
  218. package/dist/src/rules/no-unsafe-dictionary-type.js +116 -0
  219. package/dist/src/rules/no-vague-test-filenames.d.ts +2 -0
  220. package/dist/src/rules/no-vague-test-filenames.js +61 -0
  221. package/dist/src/rules/no-widen-then-assert.d.ts +2 -0
  222. package/dist/src/rules/no-widen-then-assert.js +268 -0
  223. package/dist/src/rules/prefer-payload-brand.d.ts +2 -0
  224. package/dist/src/rules/prefer-payload-brand.js +57 -0
  225. package/dist/src/rules/prefer-property-tests.d.ts +5 -0
  226. package/dist/src/rules/prefer-property-tests.js +39 -0
  227. package/dist/src/rules/require-canonical-stringify-for-identity.d.ts +8 -0
  228. package/dist/src/rules/require-canonical-stringify-for-identity.js +72 -0
  229. package/dist/src/rules/require-deprecated-tag-for-legacy-comments.d.ts +2 -0
  230. package/dist/src/rules/require-deprecated-tag-for-legacy-comments.js +34 -0
  231. package/dist/src/rules/require-exhaustive-tag-switch.d.ts +7 -0
  232. package/dist/src/rules/require-exhaustive-tag-switch.js +34 -0
  233. package/dist/src/rules/require-fc-block-predicate.d.ts +2 -0
  234. package/dist/src/rules/require-fc-block-predicate.js +37 -0
  235. package/dist/src/rules/require-jsdoc-on-exported.d.ts +2 -0
  236. package/dist/src/rules/require-jsdoc-on-exported.js +66 -0
  237. package/dist/src/rules/require-published-order.d.ts +2 -0
  238. package/dist/src/rules/require-published-order.js +102 -0
  239. package/dist/src/rules/require-safety-comment-for-type-assertion.d.ts +2 -0
  240. package/dist/src/rules/require-safety-comment-for-type-assertion.js +53 -0
  241. package/dist/src/rules/require-sort-comparator.d.ts +7 -0
  242. package/dist/src/rules/require-sort-comparator.js +34 -0
  243. package/dist/src/rules/test-utils.d.ts +35 -0
  244. package/dist/src/rules/test-utils.js +53 -0
  245. package/dist/src/shared/ancestors.d.ts +18 -0
  246. package/dist/src/shared/ancestors.js +19 -0
  247. package/dist/src/shared/child-nodes.d.ts +12 -0
  248. package/dist/src/shared/child-nodes.js +26 -0
  249. package/dist/src/shared/dictionary-types.d.ts +55 -0
  250. package/dist/src/shared/dictionary-types.js +413 -0
  251. package/dist/src/shared/is-node.d.ts +9 -0
  252. package/dist/src/shared/is-node.js +10 -0
  253. package/dist/src/shared/lexical-type-parameters.d.ts +12 -0
  254. package/dist/src/shared/lexical-type-parameters.js +50 -0
  255. package/dist/src/shared/reflect-method.d.ts +15 -0
  256. package/dist/src/shared/reflect-method.js +32 -0
  257. package/dist/src/shared/rule-options.d.ts +18 -0
  258. package/dist/src/shared/rule-options.js +12 -0
  259. package/dist/src/shared/structural.d.ts +54 -0
  260. package/dist/src/shared/structural.js +40 -0
  261. package/dist/src/testing/index.d.ts +2 -0
  262. package/dist/src/testing/index.js +1 -0
  263. package/dist/src/testing/testable-rule.d.ts +39 -0
  264. package/dist/src/testing/testable-rule.js +84 -0
  265. package/dist/src/ui/index.d.ts +12 -0
  266. package/dist/src/ui/index.js +18 -0
  267. package/dist/src/ui/manifest.d.ts +34 -0
  268. package/dist/src/ui/manifest.js +75 -0
  269. package/dist/src/ui/rules/no-deprecated-parts.d.ts +3 -0
  270. package/dist/src/ui/rules/no-deprecated-parts.js +131 -0
  271. package/dist/testing/testable-rule.d.ts +6 -5
  272. package/dist/testing/testable-rule.js +20 -6
  273. package/dist/ui/index.d.ts +12 -0
  274. package/dist/ui/index.js +18 -0
  275. package/dist/ui/manifest.d.ts +49 -0
  276. package/dist/ui/manifest.js +90 -0
  277. package/dist/ui/rules/no-deprecated-parts.d.ts +3 -0
  278. package/dist/ui/rules/no-deprecated-parts.js +172 -0
  279. package/package.json +20 -11
@@ -0,0 +1,413 @@
1
+ const BUILT_INS = new Set([
2
+ "Record",
3
+ "Readonly",
4
+ "Partial",
5
+ "Required",
6
+ "Pick",
7
+ "Omit",
8
+ "PropertyKey",
9
+ "NonNullable",
10
+ ]);
11
+ const TRANSPARENT_WRAPPERS = new Set(["Readonly", "Partial", "Required", "NonNullable"]);
12
+ /**
13
+ * Build the alias/interface maps for a program so type references can be
14
+ * resolved to their declarations during dictionary classification.
15
+ * @param {ESTree.Program} program - Root AST node of the file under lint.
16
+ * @returns {TypeEnvironment} Environment mapping declared names to their declaration nodes.
17
+ */
18
+ export function createTypeEnvironment(program) {
19
+ const aliases = new Map();
20
+ const interfaces = new Map();
21
+ const shadowedBuiltIns = new Set();
22
+ for (const statement of program.body) {
23
+ const declaration = statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration"
24
+ ? statement.declaration ?? null
25
+ : statement;
26
+ if (declaration?.type === "ImportDeclaration") {
27
+ for (const specifier of declaration.specifiers) {
28
+ if (BUILT_INS.has(specifier.local.name))
29
+ shadowedBuiltIns.add(specifier.local.name);
30
+ }
31
+ continue;
32
+ }
33
+ if (declaration?.type === "TSTypeAliasDeclaration") {
34
+ const existing = aliases.get(declaration.id.name);
35
+ if (existing === undefined)
36
+ aliases.set(declaration.id.name, declaration);
37
+ else
38
+ shadowedBuiltIns.add(declaration.id.name);
39
+ if (BUILT_INS.has(declaration.id.name))
40
+ shadowedBuiltIns.add(declaration.id.name);
41
+ continue;
42
+ }
43
+ if (declaration?.type === "TSInterfaceDeclaration") {
44
+ const declarations = interfaces.get(declaration.id.name) ?? [];
45
+ declarations.push(declaration);
46
+ interfaces.set(declaration.id.name, declarations);
47
+ if (BUILT_INS.has(declaration.id.name))
48
+ shadowedBuiltIns.add(declaration.id.name);
49
+ continue;
50
+ }
51
+ if (declaration?.type === "TSEnumDeclaration") {
52
+ if (BUILT_INS.has(declaration.id.name))
53
+ shadowedBuiltIns.add(declaration.id.name);
54
+ continue;
55
+ }
56
+ if ((declaration?.type === "ClassDeclaration" ||
57
+ declaration?.type === "FunctionDeclaration") &&
58
+ declaration.id !== null) {
59
+ if (BUILT_INS.has(declaration.id.name))
60
+ shadowedBuiltIns.add(declaration.id.name);
61
+ }
62
+ }
63
+ return { aliases, interfaces, shadowedBuiltIns };
64
+ }
65
+ function typeReferenceName(type) {
66
+ return type.typeName.type === "Identifier" ? type.typeName.name : null;
67
+ }
68
+ function isBuiltIn(payload) {
69
+ return BUILT_INS.has(payload.name) && !payload.environment.shadowedBuiltIns.has(payload.name);
70
+ }
71
+ function isUnappliedReferenceTo(payload) {
72
+ const unwrapped = unwrapTransparentType(payload.type);
73
+ return (unwrapped.type === "TSTypeReference" &&
74
+ typeReferenceName(unwrapped) === payload.name &&
75
+ (unwrapped.typeArguments === null ||
76
+ unwrapped.typeArguments === undefined ||
77
+ unwrapped.typeArguments.params.length === 0));
78
+ }
79
+ function unwrapTransparentType(type) {
80
+ let current = type;
81
+ while (current.type === "TSParenthesizedType" ||
82
+ (current.type === "TSTypeOperator" && current.operator === "readonly")) {
83
+ current = current.typeAnnotation;
84
+ }
85
+ return current;
86
+ }
87
+ function isEffectivelyEmptyMember(member) {
88
+ return (member.type === "TSPropertySignature" &&
89
+ member.optional === true &&
90
+ member.typeAnnotation !== null &&
91
+ member.typeAnnotation !== undefined &&
92
+ unwrapTransparentType(member.typeAnnotation.typeAnnotation).type === "TSNeverKeyword");
93
+ }
94
+ function resolvedSubstitutionArgument(payload) {
95
+ const { type, base } = payload;
96
+ const resolving = payload.resolving ?? new Set();
97
+ const unwrapped = unwrapTransparentType(type);
98
+ if (unwrapped.type !== "TSTypeReference")
99
+ return type;
100
+ const name = typeReferenceName(unwrapped);
101
+ if (name === null || resolving.has(name))
102
+ return type;
103
+ const substitution = base.get(name);
104
+ if (substitution === undefined)
105
+ return type;
106
+ const nextResolving = new Set(resolving);
107
+ nextResolving.add(name);
108
+ return resolvedSubstitutionArgument({ type: substitution, base, resolving: nextResolving });
109
+ }
110
+ function aliasSubstitution(alias, type, base) {
111
+ const parameters = alias.typeParameters?.params ?? [];
112
+ const arguments_ = type.typeArguments?.params ?? [];
113
+ const next = new Map(base);
114
+ for (const [index, parameter] of parameters.entries()) {
115
+ const argument = arguments_[index] ?? parameter.default;
116
+ if (argument === null || argument === undefined)
117
+ return null;
118
+ next.set(parameter.name.name, resolvedSubstitutionArgument({ type: argument, base }));
119
+ }
120
+ return next;
121
+ }
122
+ function unsafeDirectValue(type, environment, substitutions, resolvingAliases) {
123
+ const unwrapped = unwrapTransparentType(type);
124
+ if (unwrapped.type === "TSUnknownKeyword")
125
+ return "unknown";
126
+ if (unwrapped.type === "TSAnyKeyword")
127
+ return "any";
128
+ if (unwrapped.type === "TSObjectKeyword")
129
+ return "object";
130
+ if (unwrapped.type === "TSTypeLiteral" &&
131
+ (unwrapped.members.length === 0 || unwrapped.members.every(isEffectivelyEmptyMember)))
132
+ return "empty-object";
133
+ if (unwrapped.type === "TSUnionType") {
134
+ return unwrapped.types.some((member) => unsafeDirectValue(member, environment, substitutions, resolvingAliases) !== null)
135
+ ? "union"
136
+ : null;
137
+ }
138
+ if (unwrapped.type === "TSIntersectionType") {
139
+ const unsafeMembers = unwrapped.types.map((member) => unsafeDirectValue(member, environment, substitutions, resolvingAliases));
140
+ if (unsafeMembers.includes("any"))
141
+ return "any";
142
+ const [firstUnsafeMember] = unsafeMembers;
143
+ return unsafeMembers.length > 0 &&
144
+ firstUnsafeMember !== undefined &&
145
+ unsafeMembers.every((member) => member !== null)
146
+ ? firstUnsafeMember
147
+ : null;
148
+ }
149
+ if (unwrapped.type !== "TSTypeReference")
150
+ return null;
151
+ const name = typeReferenceName(unwrapped);
152
+ if (name === null)
153
+ return null;
154
+ if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn({ name, environment })) {
155
+ const wrapped = unwrapped.typeArguments?.params[0];
156
+ return wrapped === undefined
157
+ ? null
158
+ : unsafeDirectValue(wrapped, environment, substitutions, resolvingAliases);
159
+ }
160
+ const substitution = substitutions.get(name);
161
+ if (substitution !== undefined) {
162
+ return isUnappliedReferenceTo({ type: substitution, name })
163
+ ? null
164
+ : unsafeDirectValue(substitution, environment, substitutions, resolvingAliases);
165
+ }
166
+ const interfaceDeclarations = environment.interfaces.get(name);
167
+ if (interfaceDeclarations !== undefined) {
168
+ const [declaration] = interfaceDeclarations;
169
+ const effectivelyEmpty = interfaceDeclarations.length === 1 &&
170
+ declaration !== undefined &&
171
+ declaration.extends.length === 0 &&
172
+ (declaration.body.body.length === 0 ||
173
+ declaration.body.body.every(isEffectivelyEmptyMember));
174
+ return effectivelyEmpty ? "empty-object" : null;
175
+ }
176
+ const alias = environment.aliases.get(name);
177
+ if (alias === undefined || resolvingAliases.has(name))
178
+ return null;
179
+ const nextSubstitutions = aliasSubstitution(alias, unwrapped, substitutions);
180
+ if (nextSubstitutions === null)
181
+ return null;
182
+ const nextResolving = new Set(resolvingAliases);
183
+ nextResolving.add(name);
184
+ return unsafeDirectValue(alias.typeAnnotation, environment, nextSubstitutions, nextResolving);
185
+ }
186
+ function dictionaryValueTypes(type, environment, substitutions, resolvingAliases) {
187
+ const unwrapped = unwrapTransparentType(type);
188
+ if (unwrapped.type === "TSTypeLiteral") {
189
+ return unwrapped.members.flatMap((member) => member.type === "TSIndexSignature" && member.typeAnnotation !== null
190
+ ? [{ type: member.typeAnnotation.typeAnnotation, substitutions }]
191
+ : []);
192
+ }
193
+ if (unwrapped.type === "TSMappedType") {
194
+ return unwrapped.typeAnnotation === null
195
+ ? []
196
+ : [{ type: unwrapped.typeAnnotation, substitutions }];
197
+ }
198
+ if (unwrapped.type !== "TSTypeReference")
199
+ return [];
200
+ const name = typeReferenceName(unwrapped);
201
+ if (name === null)
202
+ return [];
203
+ const substitution = substitutions.get(name);
204
+ if (substitution !== undefined) {
205
+ return isUnappliedReferenceTo({ type: substitution, name })
206
+ ? []
207
+ : dictionaryValueTypes(substitution, environment, substitutions, resolvingAliases);
208
+ }
209
+ if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn({ name, environment })) {
210
+ const wrapped = unwrapped.typeArguments?.params[0];
211
+ return wrapped === undefined
212
+ ? []
213
+ : dictionaryValueTypes(wrapped, environment, substitutions, resolvingAliases);
214
+ }
215
+ if (name === "Record" && isBuiltIn({ name, environment })) {
216
+ const value = unwrapped.typeArguments?.params[1] ?? null;
217
+ return value === null ? [] : [{ type: value, substitutions }];
218
+ }
219
+ if ((name === "Pick" || name === "Omit") && isBuiltIn({ name, environment })) {
220
+ const source = unwrapped.typeArguments?.params[0];
221
+ return source === undefined
222
+ ? []
223
+ : dictionaryValueTypes(source, environment, substitutions, resolvingAliases);
224
+ }
225
+ const alias = environment.aliases.get(name);
226
+ if (alias === undefined || resolvingAliases.has(name))
227
+ return [];
228
+ const nextSubstitutions = aliasSubstitution(alias, unwrapped, substitutions);
229
+ if (nextSubstitutions === null)
230
+ return [];
231
+ const nextResolving = new Set(resolvingAliases);
232
+ nextResolving.add(name);
233
+ return dictionaryValueTypes(alias.typeAnnotation, environment, nextSubstitutions, nextResolving);
234
+ }
235
+ /**
236
+ * Classify a single type as an unsafe dictionary value, if it is one.
237
+ * @param {ESTree.TSType} valueType - Type annotation of the dictionary value slot.
238
+ * @param {TypeEnvironment} environment - Declared-alias environment from createTypeEnvironment.
239
+ * @returns {UnsafeDictionary | null} The unsafe kind ("any", "unknown", "object", "empty-object") or null.
240
+ */
241
+ export function classifyUnsafeDictionaryValue(valueType, environment) {
242
+ const unsafeValue = unsafeDirectValue(valueType, environment, new Map(), new Set());
243
+ return unsafeValue === null ? null : { kind: "unsafe-dictionary", unsafeValue };
244
+ }
245
+ /**
246
+ * Classify the value side of an index-signature or Record dictionary.
247
+ * @param {ESTree.TSType} type - The dictionary type node being inspected.
248
+ * @param {TypeEnvironment} environment - Declared-alias environment from createTypeEnvironment.
249
+ * @returns {UnsafeDictionary | null} Classification with kind and location, or null when safe.
250
+ */
251
+ export function classifyUnsafeDictionary(type, environment) {
252
+ for (const valueType of dictionaryValueTypes(type, environment, new Map(), new Set())) {
253
+ const unsafeValue = unsafeDirectValue(valueType.type, environment, valueType.substitutions, new Set());
254
+ if (unsafeValue !== null)
255
+ return { kind: "unsafe-dictionary", unsafeValue };
256
+ }
257
+ return null;
258
+ }
259
+ /**
260
+ * Describe what a widening assignment erases, for report messaging.
261
+ * @param {ESTree.TSType} type - The assigned (widened) type.
262
+ * @param {TypeEnvironment} environment - Declared-alias environment from createTypeEnvironment.
263
+ * @returns {WideningTarget | null} Human-readable target description, or null when not a widening.
264
+ */
265
+ export function classifyWideningTarget(type, environment) {
266
+ const unwrapped = unwrapTransparentType(type);
267
+ if (unwrapped.type === "TSUnknownKeyword")
268
+ return { kind: "unknown" };
269
+ if (unwrapped.type === "TSObjectKeyword")
270
+ return { kind: "object" };
271
+ if (unwrapped.type === "TSTypeLiteral") {
272
+ return unwrapped.members.some((member) => member.type === "TSIndexSignature")
273
+ ? { kind: "open dictionary" }
274
+ : unwrapped.members.length > 0
275
+ ? { kind: "anonymous object" }
276
+ : null;
277
+ }
278
+ if (unwrapped.type === "TSMappedType")
279
+ return { kind: "open dictionary" };
280
+ if (unwrapped.type !== "TSTypeReference")
281
+ return null;
282
+ const name = typeReferenceName(unwrapped);
283
+ if (name === null)
284
+ return null;
285
+ if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn({ name, environment })) {
286
+ const wrapped = unwrapped.typeArguments?.params[0];
287
+ return wrapped === undefined ? null : classifyWideningTarget(wrapped, environment);
288
+ }
289
+ if (name === "Record" && isBuiltIn({ name, environment }))
290
+ return { kind: "open dictionary" };
291
+ const alias = environment.aliases.get(name);
292
+ if (alias === undefined)
293
+ return null;
294
+ if ((alias.typeParameters?.params.length ?? 0) > 0) {
295
+ const substitutions = aliasSubstitution(alias, unwrapped, new Map());
296
+ const resolves = substitutions !== null &&
297
+ dictionaryValueTypes(alias.typeAnnotation, environment, substitutions, new Set([name])).length > 0;
298
+ return resolves ? { kind: "generic container" } : null;
299
+ }
300
+ const substitutions = aliasSubstitution(alias, unwrapped, new Map());
301
+ if (substitutions === null)
302
+ return null;
303
+ const resolved = classifyAliasBroadTarget(alias.typeAnnotation, environment, substitutions, new Set([name]));
304
+ return resolved;
305
+ }
306
+ function isBroadMappedKey(type, environment, substitutions) {
307
+ const unwrapped = unwrapTransparentType(type);
308
+ if (unwrapped.type === "TSStringKeyword" ||
309
+ unwrapped.type === "TSNumberKeyword" ||
310
+ unwrapped.type === "TSSymbolKeyword") {
311
+ return true;
312
+ }
313
+ if (unwrapped.type === "TSUnionType") {
314
+ return unwrapped.types.every((member) => isBroadMappedKey(member, environment, substitutions));
315
+ }
316
+ if (unwrapped.type !== "TSTypeReference")
317
+ return false;
318
+ const name = typeReferenceName(unwrapped);
319
+ if (name === null)
320
+ return false;
321
+ const substitution = substitutions.get(name);
322
+ if (substitution !== undefined && !isUnappliedReferenceTo({ type: substitution, name })) {
323
+ return isBroadMappedKey(substitution, environment, substitutions);
324
+ }
325
+ return name === "PropertyKey" && isBuiltIn({ name, environment });
326
+ }
327
+ function classifyAliasBroadTarget(type, environment, substitutions, resolvingAliases) {
328
+ const unwrapped = unwrapTransparentType(type);
329
+ if (unwrapped.type === "TSUnknownKeyword")
330
+ return { kind: "unknown" };
331
+ if (unwrapped.type === "TSObjectKeyword")
332
+ return { kind: "object" };
333
+ if (unwrapped.type === "TSTypeLiteral") {
334
+ return unwrapped.members.some((member) => member.type === "TSIndexSignature")
335
+ ? { kind: "open dictionary" }
336
+ : null;
337
+ }
338
+ if (unwrapped.type === "TSMappedType") {
339
+ return isBroadMappedKey(unwrapped.constraint, environment, substitutions)
340
+ ? { kind: "open dictionary" }
341
+ : null;
342
+ }
343
+ if (unwrapped.type !== "TSTypeReference")
344
+ return null;
345
+ const name = typeReferenceName(unwrapped);
346
+ if (name === null)
347
+ return null;
348
+ const substitution = substitutions.get(name);
349
+ if (substitution !== undefined) {
350
+ return isUnappliedReferenceTo({ type: substitution, name })
351
+ ? null
352
+ : classifyAliasBroadTarget(substitution, environment, substitutions, resolvingAliases);
353
+ }
354
+ if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn({ name, environment })) {
355
+ const wrapped = unwrapped.typeArguments?.params[0];
356
+ return wrapped === undefined
357
+ ? null
358
+ : classifyAliasBroadTarget(wrapped, environment, substitutions, resolvingAliases);
359
+ }
360
+ if (name === "Record" && isBuiltIn({ name, environment })) {
361
+ return { kind: "open dictionary" };
362
+ }
363
+ const alias = environment.aliases.get(name);
364
+ if (alias === undefined || resolvingAliases.has(name))
365
+ return null;
366
+ const nextSubstitutions = aliasSubstitution(alias, unwrapped, substitutions);
367
+ if (nextSubstitutions === null)
368
+ return null;
369
+ const nextResolving = new Set(resolvingAliases);
370
+ nextResolving.add(name);
371
+ return classifyAliasBroadTarget(alias.typeAnnotation, environment, nextSubstitutions, nextResolving);
372
+ }
373
+ /**
374
+ * Whether an expression is an object literal carrying at least one property.
375
+ * @param {ESTree.Expression} expression - Candidate expression node.
376
+ * @returns {boolean} True only for ObjectExpression nodes with members.
377
+ */
378
+ export function isPopulatedObjectExpression(expression) {
379
+ let current = expression;
380
+ while (current.type === "ParenthesizedExpression" ||
381
+ current.type === "TSAsExpression" ||
382
+ current.type === "TSTypeAssertion" ||
383
+ current.type === "TSNonNullExpression") {
384
+ current = current.expression;
385
+ }
386
+ return current.type === "ObjectExpression" && current.properties.length > 0;
387
+ }
388
+ /**
389
+ * Whether an expression carries first-hand type evidence (schema parse,
390
+ * literal, typed constructor) and therefore needs no further guarding.
391
+ * @param {ESTree.Expression} expression - Candidate expression node.
392
+ * @returns {boolean} True when the expression is self-evidencing.
393
+ */
394
+ export function isKnownEvidenceExpression(expression) {
395
+ let current = expression;
396
+ while (current.type === "ParenthesizedExpression" ||
397
+ current.type === "TSAsExpression" ||
398
+ current.type === "TSTypeAssertion" ||
399
+ current.type === "TSNonNullExpression" ||
400
+ current.type === "TSSatisfiesExpression") {
401
+ current = current.expression;
402
+ }
403
+ if (current.type === "ObjectExpression")
404
+ return true;
405
+ return (current.type === "ArrayExpression" ||
406
+ current.type === "ArrowFunctionExpression" ||
407
+ current.type === "ClassExpression" ||
408
+ current.type === "FunctionExpression" ||
409
+ current.type === "NewExpression" ||
410
+ current.type === "Literal" ||
411
+ current.type === "TemplateLiteral" ||
412
+ current.type === "UnaryExpression");
413
+ }
@@ -0,0 +1,9 @@
1
+ import type { ESTree } from "@oxlint/plugins";
2
+ import { type NodeFieldValue } from "./structural.ts";
3
+ /**
4
+ * Whether a reflected node-field value is an AST node (as opposed to a child
5
+ * array, literal, or absent).
6
+ * @param {NodeFieldValue} value - Value obtained from reading an ESTree node field.
7
+ * @returns {boolean} True when the value is a single AST node.
8
+ */
9
+ export declare function isNode(value: NodeFieldValue): value is ESTree.Node;
@@ -0,0 +1,10 @@
1
+ import { isRecordObject, readField, isString } from "./structural.js";
2
+ /**
3
+ * Whether a reflected node-field value is an AST node (as opposed to a child
4
+ * array, literal, or absent).
5
+ * @param {NodeFieldValue} value - Value obtained from reading an ESTree node field.
6
+ * @returns {boolean} True when the value is a single AST node.
7
+ */
8
+ export function isNode(value) {
9
+ return isRecordObject(value) && isString(readField(value, "type"));
10
+ }
@@ -0,0 +1,12 @@
1
+ import type { ESTree } from "@oxlint/plugins";
2
+ type VisitorKeys = Readonly<Record<string, readonly string[]>>;
3
+ /**
4
+ * Collect type binders that are in scope at a node and can shadow module aliases.
5
+ *
6
+ * @param {ESTree.Node} node - The node whose lexical scope is being resolved.
7
+ * @param {ReadonlyArray<ESTree.Node>} ancestors - Nearest-first ancestor chain of `node`.
8
+ * @param {VisitorKeys} visitorKeys - Grammar keys used to descend conditional types.
9
+ * @returns {ReadonlySet<string>} Names of in-scope type binders.
10
+ */
11
+ export declare function lexicalTypeParameterNames(node: ESTree.Node, ancestors: ReadonlyArray<ESTree.Node>, visitorKeys: VisitorKeys): ReadonlySet<string>;
12
+ export {};
@@ -0,0 +1,50 @@
1
+ import { isNode } from "./is-node.js";
2
+ import { readField } from "../shared/structural.js";
3
+ function collectInferTypeParameterNames(node, visitorKeys, names) {
4
+ if (node.type === "TSInferType")
5
+ names.add(node.typeParameter.name.name);
6
+ for (const key of visitorKeys[node.type] ?? []) {
7
+ const value = readField(node, key);
8
+ if (isNode(value)) {
9
+ collectInferTypeParameterNames(value, visitorKeys, names);
10
+ continue;
11
+ }
12
+ if (!Array.isArray(value))
13
+ continue;
14
+ for (const child of value) {
15
+ if (isNode(child))
16
+ collectInferTypeParameterNames(child, visitorKeys, names);
17
+ }
18
+ }
19
+ }
20
+ /**
21
+ * Collect type binders that are in scope at a node and can shadow module aliases.
22
+ *
23
+ * @param {ESTree.Node} node - The node whose lexical scope is being resolved.
24
+ * @param {ReadonlyArray<ESTree.Node>} ancestors - Nearest-first ancestor chain of `node`.
25
+ * @param {VisitorKeys} visitorKeys - Grammar keys used to descend conditional types.
26
+ * @returns {ReadonlySet<string>} Names of in-scope type binders.
27
+ */
28
+ export function lexicalTypeParameterNames(node, ancestors, visitorKeys) {
29
+ const names = new Set();
30
+ const chain = [node, ...[...ancestors].reverse()];
31
+ for (let index = 1; index < chain.length; index += 1) {
32
+ const current = chain[index];
33
+ if (current.type === "Program")
34
+ break;
35
+ const descendant = chain[index - 1];
36
+ if ("typeParameters" in current) {
37
+ for (const parameter of current.typeParameters?.params ?? []) {
38
+ names.add(parameter.name.name);
39
+ }
40
+ }
41
+ if (current.type === "TSMappedType" &&
42
+ (descendant === current.nameType || descendant === current.typeAnnotation)) {
43
+ names.add(current.key.name);
44
+ }
45
+ if (current.type === "TSConditionalType" && descendant === current.trueType) {
46
+ collectInferTypeParameterNames(current.extendsType, visitorKeys, names);
47
+ }
48
+ }
49
+ return names;
50
+ }
@@ -0,0 +1,15 @@
1
+ import type { ESTree, SourceCode } from "@oxlint/plugins";
2
+ interface ReflectMethodCallInput {
3
+ sourceCode: SourceCode;
4
+ callee: ESTree.Expression;
5
+ methodName: string;
6
+ }
7
+ /** Reports whether a call target names one method on the global Reflect object.
8
+ *
9
+ * @param {SourceCode} sourceCode - The rule's source-code accessor.
10
+ * @param {ESTree.Expression} callee - The callee expression of the call.
11
+ * @param {string} methodName - The Reflect method name to match.
12
+ * @returns {boolean} True when the call targets the global `Reflect`.
13
+ */
14
+ export declare function isGlobalReflectMethodCall({ sourceCode, callee, methodName, }: ReflectMethodCallInput): boolean;
15
+ export {};
@@ -0,0 +1,32 @@
1
+ /** Reports whether a call target names one method on the global Reflect object.
2
+ *
3
+ * @param {SourceCode} sourceCode - The rule's source-code accessor.
4
+ * @param {ESTree.Expression} callee - The callee expression of the call.
5
+ * @param {string} methodName - The Reflect method name to match.
6
+ * @returns {boolean} True when the call targets the global `Reflect`.
7
+ */
8
+ export function isGlobalReflectMethodCall({ sourceCode, callee, methodName, }) {
9
+ if (!("property" in callee) || !("object" in callee) || !("computed" in callee))
10
+ return false;
11
+ const object = callee.object;
12
+ if (object.type !== "Identifier" || object.name !== "Reflect")
13
+ return false;
14
+ if (!sourceCode.isGlobalReference(object)) {
15
+ let resolved = null;
16
+ let scope = sourceCode.getScope(object);
17
+ while (scope !== null) {
18
+ const variable = scope.set.get(object.name);
19
+ if (variable !== undefined) {
20
+ resolved = variable;
21
+ break;
22
+ }
23
+ scope = scope.upper;
24
+ }
25
+ if (resolved !== null && resolved.defs.length > 0)
26
+ return false;
27
+ }
28
+ const property = callee.property;
29
+ return callee.computed
30
+ ? property.type === "Literal" && property.value === methodName
31
+ : property.type === "Identifier" && property.name === methodName;
32
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * THE decode boundary for rule options.
3
+ *
4
+ * Rule configuration arrives from the lint config file as untyped JSON; the
5
+ * `typeof` discrimination in this module is that boundary decode, sanctioned
6
+ * by this module's single purpose. No other rule file should inspect option
7
+ * representations directly.
8
+ */
9
+ export interface OptionRecord {
10
+ readonly [key: string]: unknown;
11
+ }
12
+ /**
13
+ * Read the first options entry as an object record.
14
+ *
15
+ * @param {readonly unknown[] | undefined} options - The raw `context.options` array.
16
+ * @returns {OptionRecord} The first entry as a record, or an empty record when absent.
17
+ */
18
+ export declare function firstOptionRecord(options: readonly unknown[] | undefined): OptionRecord;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Read the first options entry as an object record.
3
+ *
4
+ * @param {readonly unknown[] | undefined} options - The raw `context.options` array.
5
+ * @returns {OptionRecord} The first entry as a record, or an empty record when absent.
6
+ */
7
+ export function firstOptionRecord(options) {
8
+ const first = options?.[0];
9
+ if (first === null || typeof first !== "object" || Array.isArray(first))
10
+ return {};
11
+ return first;
12
+ }
@@ -0,0 +1,54 @@
1
+ import type { ESTree, SourceCode } from "@oxlint/plugins";
2
+ /**
3
+ * The closed domain of values reachable from ESTree node fields.
4
+ *
5
+ * Nothing crossing rule logic is `unknown`: reflection over node fields
6
+ * yields exactly this union, so guards accept it instead of re-widening
7
+ * caller evidence to unknown.
8
+ */
9
+ export type NodeFieldValue = ESTree.Node | readonly ESTree.Node[] | string | number | bigint | boolean | RegExp | null | undefined;
10
+ /**
11
+ * Read a field from an ESTree node without chained assertions.
12
+ *
13
+ * SAFETY: callers invoke this after a discriminant (or containment) check that
14
+ * establishes the key exists on the node's runtime shape; the value's domain is
15
+ * owned by the AST grammar (see NodeFieldValue), not by untrusted input.
16
+ *
17
+ * @param {object | null | undefined} node - The node whose field is read.
18
+ * @param {string} key - The field name.
19
+ * @returns {T | undefined} The field value, or undefined when absent.
20
+ */
21
+ export declare function readField<T = NodeFieldValue>(node: object | null | undefined, key: string): T | undefined;
22
+ /** Discriminate string-valued fields or expressions of an AST node.
23
+ *
24
+ * @param {NodeFieldValue | ESTree.Expression} value - The value to test.
25
+ * @returns {boolean} True when the value is a string.
26
+ */
27
+ export declare function isString(value: NodeFieldValue | ESTree.Expression): value is string;
28
+ /** Engine comment shape, normalized for rule consumption. */
29
+ export interface CommentLike {
30
+ type: string;
31
+ value: string;
32
+ end?: number;
33
+ range?: readonly [number, number];
34
+ loc?: {
35
+ start?: {
36
+ line?: number;
37
+ };
38
+ end?: {
39
+ line?: number;
40
+ };
41
+ };
42
+ }
43
+ /** All comments in the file, typed for rule consumption.
44
+ *
45
+ * @param {SourceCode} sourceCode - The rule's source-code accessor.
46
+ * @returns {CommentLike[]} The file's comments.
47
+ */
48
+ export declare function getAllComments(sourceCode: SourceCode): CommentLike[];
49
+ /** Discriminate object-valued fields of an AST node (child containers).
50
+ *
51
+ * @param {NodeFieldValue | Record<string, NodeFieldValue>} value - The field value to test.
52
+ * @returns {boolean} True when the value is a non-array object record.
53
+ */
54
+ export declare function isRecordObject(value: NodeFieldValue | Record<string, NodeFieldValue>): value is Record<string, NodeFieldValue>;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Read a field from an ESTree node without chained assertions.
3
+ *
4
+ * SAFETY: callers invoke this after a discriminant (or containment) check that
5
+ * establishes the key exists on the node's runtime shape; the value's domain is
6
+ * owned by the AST grammar (see NodeFieldValue), not by untrusted input.
7
+ *
8
+ * @param {object | null | undefined} node - The node whose field is read.
9
+ * @param {string} key - The field name.
10
+ * @returns {T | undefined} The field value, or undefined when absent.
11
+ */
12
+ export function readField(node, key) {
13
+ if (node === null || node === undefined)
14
+ return undefined;
15
+ return node[key];
16
+ }
17
+ /** Discriminate string-valued fields or expressions of an AST node.
18
+ *
19
+ * @param {NodeFieldValue | ESTree.Expression} value - The value to test.
20
+ * @returns {boolean} True when the value is a string.
21
+ */
22
+ export function isString(value) {
23
+ return typeof value === "string";
24
+ }
25
+ /** All comments in the file, typed for rule consumption.
26
+ *
27
+ * @param {SourceCode} sourceCode - The rule's source-code accessor.
28
+ * @returns {CommentLike[]} The file's comments.
29
+ */
30
+ export function getAllComments(sourceCode) {
31
+ return sourceCode.getAllComments();
32
+ }
33
+ /** Discriminate object-valued fields of an AST node (child containers).
34
+ *
35
+ * @param {NodeFieldValue | Record<string, NodeFieldValue>} value - The field value to test.
36
+ * @returns {boolean} True when the value is a non-array object record.
37
+ */
38
+ export function isRecordObject(value) {
39
+ return typeof value === "object" && value !== null && !Array.isArray(value);
40
+ }