@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,167 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { ancestorsOf } from "../../shared/ancestors.js";
3
+ import { isHookName } from "../role.js";
4
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
5
+ /**
6
+ * Whether a custom context hook that reads context must be reported for
7
+ * lacking a guard against a missing Provider.
8
+ *
9
+ * @param {{ isHook: boolean; callsUseContext: boolean; guarded: boolean }} input - The hook's shape facts.
10
+ * @returns {boolean} True when the hook needs a guard but has none.
11
+ */
12
+ export function requiresContextGuard(input) {
13
+ return input.isHook && input.callsUseContext && !input.guarded;
14
+ }
15
+ /**
16
+ * The variable name an `if` test guards against a nullish value.
17
+ *
18
+ * @param {ESTree.Node} test - The if-statement test expression.
19
+ * @returns {string | null} The guarded variable name, or null when not a nullish guard.
20
+ */
21
+ function checkedVar(test) {
22
+ if (test.type === "UnaryExpression" && test.operator === "!" && test.argument.type === "Identifier") {
23
+ return test.argument.name;
24
+ }
25
+ if (test.type === "BinaryExpression") {
26
+ const nullish = (operand) => (operand.type === "Identifier" && (operand.name === "undefined" || operand.name === "null")) ||
27
+ (operand.type === "Literal" && (operand.value === null || operand.value === undefined));
28
+ if (test.operator === "===" || test.operator === "!==" || test.operator === "==" || test.operator === "!=") {
29
+ if (test.left.type === "Identifier" && nullish(test.right))
30
+ return test.left.name;
31
+ if (test.right.type === "Identifier" && nullish(test.left))
32
+ return test.right.name;
33
+ }
34
+ }
35
+ return null;
36
+ }
37
+ /**
38
+ * Whether a statement (or its block body) throws.
39
+ *
40
+ * @param {ESTree.Node} node - The statement node to inspect.
41
+ * @returns {boolean} True when the statement throws.
42
+ */
43
+ function containsThrow(node) {
44
+ if (node.type === "ThrowStatement")
45
+ return true;
46
+ if (node.type === "BlockStatement")
47
+ return node.body.some((s) => s.type === "ThrowStatement");
48
+ return false;
49
+ }
50
+ /**
51
+ * Whether the callee references `useContext`.
52
+ *
53
+ * @param {ESTree.Node} callee - The callee expression of a call.
54
+ * @returns {boolean} True when the callee is `useContext`.
55
+ */
56
+ function isUseContext(callee) {
57
+ if (callee.type === "Identifier")
58
+ return callee.name === "useContext";
59
+ if (callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier")
60
+ return callee.property.name === "useContext";
61
+ return false;
62
+ }
63
+ /**
64
+ * A custom hook that reads context with `useContext` must throw when the
65
+ * Provider is missing, rather than returning `undefined` and pushing a
66
+ * null-check onto every consumer. Returning a possibly-undefined context is the
67
+ * same hidden-nullable defect the rest of the library forbids.
68
+ */
69
+ export const requireGuardedContextHookRule = defineRule({
70
+ meta: {
71
+ type: "problem",
72
+ docs: {
73
+ description: "Require custom context hooks (useXxx calling useContext) to throw when the Provider is missing, instead of returning a possibly-undefined context.",
74
+ },
75
+ messages: {
76
+ unguardedContext: "`{{name}}` reads context with useContext but never guards against a missing Provider (no `if (!context) throw`). A context read outside the Provider returns undefined; throw when it is absent so consumers get a clear error instead of a nullable value.",
77
+ },
78
+ },
79
+ createOnce(context) {
80
+ const frames = [];
81
+ const push = (entry) => {
82
+ frames.push({ name: entry.name, node: entry.node, useContextVars: new Set(), guardedVars: new Set() });
83
+ };
84
+ const current = () => frames[frames.length - 1];
85
+ /**
86
+ * Nearest enclosing function name for a node (declaration or variable binding).
87
+ *
88
+ * @param {ESTree.Node} node - The reference node.
89
+ * @returns {string | null} The nearest function name, or null when anonymous.
90
+ */
91
+ function nearestFunctionName(node) {
92
+ const ancestors = ancestorsOf(context.sourceCode, node);
93
+ for (let i = ancestors.length - 1; i >= 0; i--) {
94
+ const a = ancestors[i];
95
+ if (a === undefined)
96
+ continue;
97
+ if (a.type === "FunctionDeclaration" && a.id !== null && a.id !== undefined)
98
+ return a.id.name;
99
+ if (a.type === "FunctionExpression" && a.id !== null && a.id !== undefined)
100
+ return a.id.name;
101
+ if (a.type === "VariableDeclarator" && a.id.type === "Identifier") {
102
+ const init = a.init;
103
+ if (init !== null &&
104
+ init !== undefined &&
105
+ (init.type === "ArrowFunctionExpression" || init.type === "FunctionExpression"))
106
+ return a.id.name;
107
+ }
108
+ }
109
+ return null;
110
+ }
111
+ return {
112
+ before() {
113
+ frames.length = 0;
114
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
115
+ return false;
116
+ },
117
+ FunctionDeclaration(node) {
118
+ push({ name: node.id?.name ?? null, node });
119
+ },
120
+ "FunctionDeclaration:exit"() {
121
+ const frame = frames.pop();
122
+ if (frame !== undefined)
123
+ report(frame);
124
+ },
125
+ FunctionExpression(node) {
126
+ push({ name: node.id?.name ?? null, node });
127
+ },
128
+ "FunctionExpression:exit"() {
129
+ const frame = frames.pop();
130
+ if (frame !== undefined)
131
+ report(frame);
132
+ },
133
+ ArrowFunctionExpression(node) {
134
+ push({ name: nearestFunctionName(node), node });
135
+ },
136
+ "ArrowFunctionExpression:exit"() {
137
+ const frame = frames.pop();
138
+ if (frame !== undefined)
139
+ report(frame);
140
+ },
141
+ CallExpression(node) {
142
+ if (!isUseContext(node.callee))
143
+ return;
144
+ const parent = ancestorsOf(context.sourceCode, node).at(-1);
145
+ if (parent?.type === "VariableDeclarator" && parent.id.type === "Identifier") {
146
+ current()?.useContextVars.add(parent.id.name);
147
+ }
148
+ },
149
+ IfStatement(node) {
150
+ const variable = checkedVar(node.test);
151
+ if (variable === null)
152
+ return;
153
+ if (containsThrow(node.consequent) || (node.alternate !== null && containsThrow(node.alternate))) {
154
+ current()?.guardedVars.add(variable);
155
+ }
156
+ },
157
+ };
158
+ function report(frame) {
159
+ if (!isHookName(frame.name))
160
+ return;
161
+ const unguarded = [...frame.useContextVars].filter((v) => !frame.guardedVars.has(v));
162
+ if (unguarded.length === 0)
163
+ return;
164
+ context.report({ node: frame.node, messageId: "unguardedContext", data: { name: frame.name } });
165
+ }
166
+ },
167
+ });
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Whether a context value type's member keys form the tripartite
3
+ * state/actions/meta contract.
4
+ *
5
+ * @param {ReadonlyArray<string>} members - The declared member key names.
6
+ * @returns {boolean} True when `state`, `actions`, and `meta` are all present.
7
+ */
8
+ export declare function isTripartiteContextValue(members: ReadonlyArray<string>): boolean;
9
+ /**
10
+ * A React context's value must be shaped as `{ state, actions, meta }`: state is
11
+ * the data, actions are the functions that change it, and meta holds
12
+ * non-reactive configuration. This is the explicit I/O boundary of the
13
+ * component family - the same "perfect function" contract as the composition
14
+ * pattern. A context that omits one of the three leaks an implicit, unnamed
15
+ * channel that consumers cannot reason about.
16
+ */
17
+ export declare const requireTripartiteContextRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,160 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { isString } from "../../shared/structural.js";
3
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
4
+ /** The three required keys of a context value type. */
5
+ const REQUIRED_KEYS = ["state", "actions", "meta"];
6
+ /**
7
+ * Whether a context value type's member keys form the tripartite
8
+ * state/actions/meta contract.
9
+ *
10
+ * @param {ReadonlyArray<string>} members - The declared member key names.
11
+ * @returns {boolean} True when `state`, `actions`, and `meta` are all present.
12
+ */
13
+ export function isTripartiteContextValue(members) {
14
+ const present = new Set(members);
15
+ return REQUIRED_KEYS.every((key) => present.has(key));
16
+ }
17
+ /**
18
+ * Member key names of a TS object type (interface body or inline literal).
19
+ *
20
+ * @param {ESTree.Node} node - The interface or type-literal node.
21
+ * @returns {ReadonlyArray<string>} The declared member key names.
22
+ */
23
+ function memberKeys(node) {
24
+ const keys = [];
25
+ const addKey = (key) => {
26
+ if (key.type === "Identifier")
27
+ keys.push(key.name);
28
+ else if (key.type === "Literal" && isString(key.value))
29
+ keys.push(key.value);
30
+ };
31
+ if (node.type === "TSInterfaceDeclaration") {
32
+ for (const member of node.body.body) {
33
+ if (member.type === "TSPropertySignature" || member.type === "TSMethodSignature")
34
+ addKey(member.key);
35
+ }
36
+ }
37
+ else if (node.type === "TSTypeLiteral") {
38
+ for (const member of node.members) {
39
+ if (member.type === "TSPropertySignature" || member.type === "TSMethodSignature")
40
+ addKey(member.key);
41
+ }
42
+ }
43
+ return keys;
44
+ }
45
+ /**
46
+ * Final segment of a type reference name.
47
+ *
48
+ * @param {ESTree.TSTypeReference} node - The type reference node.
49
+ * @returns {string | null} The unqualified type name, or null when unavailable.
50
+ */
51
+ function typeName(node) {
52
+ const tn = node.typeName;
53
+ if (tn.type === "Identifier")
54
+ return tn.name;
55
+ if (tn.type === "TSQualifiedName")
56
+ return tn.right.name;
57
+ return null;
58
+ }
59
+ /**
60
+ * Whether the callee references `createContext`.
61
+ *
62
+ * @param {ESTree.Node} callee - The callee expression of a call.
63
+ * @returns {boolean} True when the callee is `createContext`.
64
+ */
65
+ function isCreateContext(callee) {
66
+ if (callee.type === "Identifier")
67
+ return callee.name === "createContext";
68
+ if (callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier")
69
+ return callee.property.name === "createContext";
70
+ return false;
71
+ }
72
+ /**
73
+ * A React context's value must be shaped as `{ state, actions, meta }`: state is
74
+ * the data, actions are the functions that change it, and meta holds
75
+ * non-reactive configuration. This is the explicit I/O boundary of the
76
+ * component family - the same "perfect function" contract as the composition
77
+ * pattern. A context that omits one of the three leaks an implicit, unnamed
78
+ * channel that consumers cannot reason about.
79
+ */
80
+ export const requireTripartiteContextRule = defineRule({
81
+ meta: {
82
+ type: "problem",
83
+ docs: {
84
+ description: "Require React context value types to be the tripartite { state, actions, meta } shape; missing keys leak an implicit, unnamed I/O channel.",
85
+ },
86
+ messages: {
87
+ tripartiteContext: "Context value type is missing required key(s): {{missing}}. A context value must be { state, actions, meta } so its I/O boundary is explicit.",
88
+ },
89
+ },
90
+ createOnce(context) {
91
+ const localTypes = new Map();
92
+ const calls = [];
93
+ /**
94
+ * Resolve a context type argument to declared member keys, if local.
95
+ *
96
+ * @param {ESTree.Node} typeArg - The type argument node passed to createContext.
97
+ * @returns {ReadonlyArray<string> | null} The member keys, or null when unresolved.
98
+ */
99
+ function resolveKeys(typeArg) {
100
+ if (typeArg.type === "TSTypeLiteral")
101
+ return memberKeys(typeArg);
102
+ if (typeArg.type === "TSTypeReference") {
103
+ const name = typeName(typeArg);
104
+ return name === null ? null : localTypes.get(name) ?? null;
105
+ }
106
+ if (typeArg.type === "TSUnionType") {
107
+ for (const member of typeArg.types) {
108
+ if (member.type === "TSUndefinedKeyword" || member.type === "TSNullKeyword")
109
+ continue;
110
+ const resolved = resolveKeys(member);
111
+ if (resolved !== null)
112
+ return resolved;
113
+ }
114
+ }
115
+ return null;
116
+ }
117
+ return {
118
+ before() {
119
+ localTypes.clear();
120
+ calls.length = 0;
121
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
122
+ return false;
123
+ },
124
+ TSInterfaceDeclaration(node) {
125
+ localTypes.set(node.id.name, memberKeys(node));
126
+ },
127
+ TSTypeAliasDeclaration(node) {
128
+ if (node.typeAnnotation.type === "TSTypeLiteral") {
129
+ localTypes.set(node.id.name, memberKeys(node.typeAnnotation));
130
+ }
131
+ },
132
+ CallExpression(node) {
133
+ if (isCreateContext(node.callee))
134
+ calls.push(node);
135
+ },
136
+ "Program:exit"() {
137
+ for (const call of calls) {
138
+ const params = call.typeArguments?.params;
139
+ if (params === undefined || params.length === 0)
140
+ continue;
141
+ const first = params[0];
142
+ if (first === undefined)
143
+ continue;
144
+ const keys = resolveKeys(first);
145
+ if (keys === null)
146
+ continue;
147
+ if (isTripartiteContextValue(keys))
148
+ continue;
149
+ const present = new Set(keys);
150
+ const missing = REQUIRED_KEYS.filter((key) => !present.has(key));
151
+ context.report({
152
+ node: call,
153
+ messageId: "tripartiteContext",
154
+ data: { missing: missing.join(", ") },
155
+ });
156
+ }
157
+ },
158
+ };
159
+ },
160
+ });
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Whether a React hook used at `hookName` inside a function named `parentName`
3
+ * violates the encapsulation rule. Provider components (XProvider) are the
4
+ * stateful root of a context family and legitimately use hooks inline, so they
5
+ * are exempt.
6
+ *
7
+ * @param {{ hookName: string; parentName: string }} input - The usage facts.
8
+ * @returns {boolean} True when the usage should be reported.
9
+ */
10
+ export declare function isEncapsulationViolation(input: {
11
+ hookName: string;
12
+ parentName: string;
13
+ }): boolean;
14
+ /**
15
+ * Do not call React's hooks directly inside a component. Abstract the
16
+ * functionality into a custom hook (`useXxx`) and call that instead - the
17
+ * "useEncapsulation" pattern. A component that reaches for `useState`/`useEffect`
18
+ * inline hides its state and effects; a custom hook names them and can be tested
19
+ * and composed in isolation. Provider components (XProvider) are exempt: they are
20
+ * the stateful root of a context family and must use hooks inline.
21
+ */
22
+ export declare const useEncapsulationRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,97 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { ancestorsOf } from "../../shared/ancestors.js";
3
+ import { readField } from "../../shared/structural.js";
4
+ import { isProviderName } from "../role.js";
5
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
6
+ /** Pattern identifying custom hooks (names starting with `use`). */
7
+ const HOOK_PATTERN = /^use/u;
8
+ /** React's built-in hooks that must not be used directly inside components. */
9
+ const REACT_HOOKS = new Set([
10
+ "useCallback",
11
+ "useContext",
12
+ "useDebugValue",
13
+ "useDeferredValue",
14
+ "useEffect",
15
+ "useId",
16
+ "useImperativeHandle",
17
+ "useInsertionEffect",
18
+ "useLayoutEffect",
19
+ "useMemo",
20
+ "useReducer",
21
+ "useRef",
22
+ "useState",
23
+ "useSyncExternalStore",
24
+ "useTransition",
25
+ ]);
26
+ /**
27
+ * Whether a React hook used at `hookName` inside a function named `parentName`
28
+ * violates the encapsulation rule. Provider components (XProvider) are the
29
+ * stateful root of a context family and legitimately use hooks inline, so they
30
+ * are exempt.
31
+ *
32
+ * @param {{ hookName: string; parentName: string }} input - The usage facts.
33
+ * @returns {boolean} True when the usage should be reported.
34
+ */
35
+ export function isEncapsulationViolation(input) {
36
+ return REACT_HOOKS.has(input.hookName) && !HOOK_PATTERN.test(input.parentName) && !isProviderName(input.parentName);
37
+ }
38
+ /**
39
+ * Do not call React's hooks directly inside a component. Abstract the
40
+ * functionality into a custom hook (`useXxx`) and call that instead - the
41
+ * "useEncapsulation" pattern. A component that reaches for `useState`/`useEffect`
42
+ * inline hides its state and effects; a custom hook names them and can be tested
43
+ * and composed in isolation. Provider components (XProvider) are exempt: they are
44
+ * the stateful root of a context family and must use hooks inline.
45
+ */
46
+ export const useEncapsulationRule = defineRule({
47
+ meta: {
48
+ type: "problem",
49
+ docs: {
50
+ description: "Disallow using React's hooks directly inside a component; abstract them into a custom hook (useXxx) and call that instead (useEncapsulation).",
51
+ },
52
+ messages: {
53
+ noDirectHooks: "Do not use React hook `{{hook}}` directly inside component `{{parent}}`. Abstract the functionality into a custom hook (useXxx) and call that instead.",
54
+ },
55
+ },
56
+ createOnce(context) {
57
+ const raw = readField(context, "options");
58
+ const options = raw?.[0] ?? {};
59
+ const allowed = new Set(options.allow ?? []);
60
+ const blocked = new Set(options.block ?? []);
61
+ const hooksToCheck = new Set([...REACT_HOOKS, ...blocked].filter((h) => !allowed.has(h)));
62
+ function nearestFunctionName(node) {
63
+ const ancestors = ancestorsOf(context.sourceCode, node);
64
+ for (let i = ancestors.length - 1; i >= 0; i--) {
65
+ const a = ancestors[i];
66
+ if (a === undefined)
67
+ continue;
68
+ if (a.type === "FunctionDeclaration" && a.id !== null && a.id !== undefined)
69
+ return a.id.name;
70
+ if (a.type === "FunctionExpression" && a.id !== null && a.id !== undefined)
71
+ return a.id.name;
72
+ if (a.type === "VariableDeclarator" && a.id.type === "Identifier") {
73
+ const init = a.init;
74
+ if (init !== null &&
75
+ init !== undefined &&
76
+ (init.type === "ArrowFunctionExpression" || init.type === "FunctionExpression"))
77
+ return a.id.name;
78
+ }
79
+ }
80
+ return null;
81
+ }
82
+ return {
83
+ before() {
84
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
85
+ return false;
86
+ },
87
+ Identifier(node) {
88
+ if (!hooksToCheck.has(node.name))
89
+ return;
90
+ const parent = nearestFunctionName(node);
91
+ if (parent !== null && !HOOK_PATTERN.test(parent) && !isProviderName(parent)) {
92
+ context.report({ node, messageId: "noDirectHooks", data: { hook: node.name, parent } });
93
+ }
94
+ },
95
+ };
96
+ },
97
+ });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Dense representations are sliceable on any axis because their parts are
3
+ * named. Past two elements, positional tuples hide which position carries
4
+ * which fact: swap-prone, unreadable at call sites, and impossible to
5
+ * slice meaningfully. Give wide tuples a named shape.
6
+ */
7
+ export declare const noAnonymousWideTuplesRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,34 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { readField } from "../shared/structural.js";
3
+ /**
4
+ * Dense representations are sliceable on any axis because their parts are
5
+ * named. Past two elements, positional tuples hide which position carries
6
+ * which fact: swap-prone, unreadable at call sites, and impossible to
7
+ * slice meaningfully. Give wide tuples a named shape.
8
+ */
9
+ export const noAnonymousWideTuplesRule = defineRule({
10
+ meta: {
11
+ type: "suggestion",
12
+ docs: {
13
+ description: "Disallow anonymous tuple types of three or more elements; use a named object so every field's role is explicit.",
14
+ },
15
+ messages: {
16
+ wideTuple: "This {{count}}-element tuple leaves {{count}} unnamed positions whose meaning lives only in the reader's head. Declare a named object (or tagged union) instead so fields are self-describing.",
17
+ },
18
+ },
19
+ createOnce(context) {
20
+ return {
21
+ TSTupleType(node) {
22
+ const elements = readField(node, "elementTypes") ?? [];
23
+ const count = elements.length;
24
+ if (count < 3)
25
+ return;
26
+ context.report({
27
+ node,
28
+ messageId: "wideTuple",
29
+ data: { count: String(count) },
30
+ });
31
+ },
32
+ };
33
+ },
34
+ });
@@ -0,0 +1,2 @@
1
+ /** Barrel `export *` erases the names it forwards, forcing search-driven readers back inside the package. */
2
+ export declare const noBarrelExportStarRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,26 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ /** Barrel `export *` erases the names it forwards, forcing search-driven readers back inside the package. */
3
+ export const noBarrelExportStarRule = defineRule({
4
+ meta: {
5
+ type: "problem",
6
+ docs: {
7
+ description: "Disallow `export * from ...` re-exports because the star erases forwarded names; an agent navigating by text search cannot resolve which module owns a symbol and must re-grep inside the package.",
8
+ },
9
+ messages: {
10
+ erasesForwardedNames: "`export * from '{{source}}'` erases the names it forwards; readers resolving a symbol through this barrel must grep inside the package instead. Re-export the explicit names.",
11
+ },
12
+ },
13
+ createOnce(context) {
14
+ return {
15
+ ExportAllDeclaration(node) {
16
+ if (node.exported !== null && node.exported !== undefined)
17
+ return;
18
+ context.report({
19
+ node,
20
+ messageId: "erasesForwardedNames",
21
+ data: { source: String(node.source.value) },
22
+ });
23
+ },
24
+ };
25
+ },
26
+ });
@@ -0,0 +1,2 @@
1
+ /** Ban predicate families that re-derive classification, and un-guarded construction. */
2
+ export declare const noBooleanFieldSignalsRule: import("@oxlint/plugins").Rule;