@autotelic/plumb 0.5.2 → 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 (282) 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/index.js +4 -0
  5. package/dist/effect/rules/guarded-op-must-return-effect.js +1 -1
  6. package/dist/effect/rules/no-cascading-layer-provide.js +1 -1
  7. package/dist/effect/rules/no-decode-unknown-option.js +1 -1
  8. package/dist/effect/rules/no-direct-browser-storage.js +3 -3
  9. package/dist/effect/rules/no-direct-fetch.js +1 -1
  10. package/dist/effect/rules/no-manual-field-guards.js +1 -1
  11. package/dist/effect/rules/no-nested-layer-provide.js +1 -1
  12. package/dist/effect/rules/no-nullish-default-on-partial-input.d.ts +13 -0
  13. package/dist/effect/rules/no-nullish-default-on-partial-input.js +109 -0
  14. package/dist/effect/rules/no-raw-error-forwarding.d.ts +16 -0
  15. package/dist/effect/rules/no-raw-error-forwarding.js +108 -0
  16. package/dist/effect/rules/no-silent-error-swallow.js +1 -1
  17. package/dist/effect/rules/no-static-effect-service-forwarders.js +5 -4
  18. package/dist/effect/rules/no-try-catch.js +1 -1
  19. package/dist/effect/rules/no-unguarded-json-parse.js +1 -1
  20. package/dist/effect/rules/option-core-needs-effect-public.js +1 -1
  21. package/dist/effect/rules/prefer-die-for-precondition-defects.js +1 -1
  22. package/dist/effect/rules/prefer-effect-gen-for-guard-ladders.js +1 -1
  23. package/dist/effect/rules/prefer-effect-match.js +2 -2
  24. package/dist/effect/rules/prefer-effect-predicate-over-boolean-function.js +1 -1
  25. package/dist/effect/rules/prefer-named-guard-predicate.js +1 -1
  26. package/dist/effect/rules/prefer-option-pipeline.js +13 -12
  27. package/dist/effect/rules/prefer-ordering-match.js +1 -1
  28. package/dist/effect/rules/prefer-tagged-enum.js +1 -1
  29. package/dist/effect/rules/require-schema-type-derivation.d.ts +8 -2
  30. package/dist/effect/rules/require-schema-type-derivation.js +14 -4
  31. package/dist/index.js +10 -0
  32. package/dist/react/rules/require-dot-notation-exports.js +1 -1
  33. package/dist/react/rules/require-guarded-context-hook.js +1 -1
  34. package/dist/react/rules/require-tripartite-context.js +1 -1
  35. package/dist/react/rules/use-encapsulation.js +1 -1
  36. package/dist/rules/no-adapter-in-values.d.ts +12 -0
  37. package/dist/rules/no-adapter-in-values.js +110 -0
  38. package/dist/rules/no-builtin-throws.js +1 -1
  39. package/dist/rules/no-duplicated-literal-union.d.ts +7 -0
  40. package/dist/rules/no-duplicated-literal-union.js +5 -1
  41. package/dist/rules/no-generic-export-names.js +1 -1
  42. package/dist/rules/no-multiple-function-params.js +26 -12
  43. package/dist/rules/no-mutable-environment-capture.js +2 -2
  44. package/dist/rules/no-nondeterministic-core.js +1 -1
  45. package/dist/rules/no-nullable-value-field.d.ts +16 -0
  46. package/dist/rules/no-nullable-value-field.js +117 -0
  47. package/dist/rules/no-optional-function-parameters.js +1 -1
  48. package/dist/rules/no-row-coercion.d.ts +13 -0
  49. package/dist/rules/no-row-coercion.js +135 -0
  50. package/dist/rules/no-single-use-private-functions.js +1 -1
  51. package/dist/rules/no-sql-string-interpolation.d.ts +7 -0
  52. package/dist/rules/no-sql-string-interpolation.js +62 -0
  53. package/dist/rules/no-stray-inline-comments.js +1 -1
  54. package/dist/rules/no-string-instant.d.ts +15 -0
  55. package/dist/rules/no-string-instant.js +108 -0
  56. package/dist/rules/no-swappable-primitive-params.js +1 -1
  57. package/dist/rules/no-tag-ladder-assertions.js +1 -1
  58. package/dist/rules/no-vague-test-filenames.js +1 -1
  59. package/dist/rules/prefer-property-tests.d.ts +5 -0
  60. package/dist/rules/prefer-property-tests.js +7 -0
  61. package/dist/rules/require-jsdoc-on-exported.js +1 -1
  62. package/dist/shared/ancestors.d.ts +1 -1
  63. package/dist/shared/ancestors.js +1 -1
  64. package/dist/shared/values-path.d.ts +12 -0
  65. package/dist/shared/values-path.js +56 -0
  66. package/dist/src/configs/recommended-rules.d.ts +20 -0
  67. package/dist/src/configs/recommended-rules.js +22 -0
  68. package/dist/src/effect/index.d.ts +3 -0
  69. package/dist/src/effect/index.js +60 -0
  70. package/dist/src/effect/rules/guarded-op-must-return-effect.d.ts +6 -0
  71. package/dist/src/effect/rules/guarded-op-must-return-effect.js +235 -0
  72. package/dist/src/effect/rules/guarded-op-must-return-option.d.ts +2 -0
  73. package/dist/src/effect/rules/guarded-op-must-return-option.js +88 -0
  74. package/dist/src/effect/rules/no-cascading-layer-provide.d.ts +6 -0
  75. package/dist/src/effect/rules/no-cascading-layer-provide.js +73 -0
  76. package/dist/src/effect/rules/no-decode-unknown-option.d.ts +7 -0
  77. package/dist/src/effect/rules/no-decode-unknown-option.js +34 -0
  78. package/dist/src/effect/rules/no-direct-browser-storage.d.ts +2 -0
  79. package/dist/src/effect/rules/no-direct-browser-storage.js +88 -0
  80. package/dist/src/effect/rules/no-direct-fetch.d.ts +2 -0
  81. package/dist/src/effect/rules/no-direct-fetch.js +37 -0
  82. package/dist/src/effect/rules/no-manual-field-guards.d.ts +6 -0
  83. package/dist/src/effect/rules/no-manual-field-guards.js +129 -0
  84. package/dist/src/effect/rules/no-nested-layer-provide.d.ts +2 -0
  85. package/dist/src/effect/rules/no-nested-layer-provide.js +50 -0
  86. package/dist/src/effect/rules/no-nullish-default-on-partial-input.d.ts +13 -0
  87. package/dist/src/effect/rules/no-nullish-default-on-partial-input.js +109 -0
  88. package/dist/src/effect/rules/no-raw-error-forwarding.d.ts +12 -0
  89. package/dist/src/effect/rules/no-raw-error-forwarding.js +103 -0
  90. package/dist/src/effect/rules/no-schema-class-modeling.d.ts +2 -0
  91. package/dist/src/effect/rules/no-schema-class-modeling.js +52 -0
  92. package/dist/src/effect/rules/no-service-constructor-imports.d.ts +2 -0
  93. package/dist/src/effect/rules/no-service-constructor-imports.js +42 -0
  94. package/dist/src/effect/rules/no-silent-error-swallow.d.ts +2 -0
  95. package/dist/src/effect/rules/no-silent-error-swallow.js +95 -0
  96. package/dist/src/effect/rules/no-static-effect-service-forwarders.d.ts +6 -0
  97. package/dist/src/effect/rules/no-static-effect-service-forwarders.js +222 -0
  98. package/dist/src/effect/rules/no-try-catch.d.ts +2 -0
  99. package/dist/src/effect/rules/no-try-catch.js +30 -0
  100. package/dist/src/effect/rules/no-unguarded-json-parse.d.ts +5 -0
  101. package/dist/src/effect/rules/no-unguarded-json-parse.js +200 -0
  102. package/dist/src/effect/rules/option-core-needs-effect-public.d.ts +5 -0
  103. package/dist/src/effect/rules/option-core-needs-effect-public.js +76 -0
  104. package/dist/src/effect/rules/prefer-die-for-precondition-defects.d.ts +5 -0
  105. package/dist/src/effect/rules/prefer-die-for-precondition-defects.js +112 -0
  106. package/dist/src/effect/rules/prefer-effect-gen-for-guard-ladders.d.ts +5 -0
  107. package/dist/src/effect/rules/prefer-effect-gen-for-guard-ladders.js +72 -0
  108. package/dist/src/effect/rules/prefer-effect-match.d.ts +2 -0
  109. package/dist/src/effect/rules/prefer-effect-match.js +74 -0
  110. package/dist/src/effect/rules/prefer-effect-predicate-over-boolean-function.d.ts +2 -0
  111. package/dist/src/effect/rules/prefer-effect-predicate-over-boolean-function.js +75 -0
  112. package/dist/src/effect/rules/prefer-named-guard-predicate.d.ts +2 -0
  113. package/dist/src/effect/rules/prefer-named-guard-predicate.js +93 -0
  114. package/dist/src/effect/rules/prefer-option-pipeline.d.ts +2 -0
  115. package/dist/src/effect/rules/prefer-option-pipeline.js +87 -0
  116. package/dist/src/effect/rules/prefer-ordering-match.d.ts +2 -0
  117. package/dist/src/effect/rules/prefer-ordering-match.js +135 -0
  118. package/dist/src/effect/rules/prefer-tagged-enum.d.ts +2 -0
  119. package/dist/src/effect/rules/prefer-tagged-enum.js +66 -0
  120. package/dist/src/effect/rules/require-schema-type-derivation.d.ts +7 -0
  121. package/dist/src/effect/rules/require-schema-type-derivation.js +80 -0
  122. package/dist/src/index.d.ts +3 -0
  123. package/dist/src/index.js +106 -0
  124. package/dist/src/meta/index.d.ts +7 -0
  125. package/dist/src/meta/index.js +22 -0
  126. package/dist/src/meta/rules/no-disable-directives.d.ts +6 -0
  127. package/dist/src/meta/rules/no-disable-directives.js +35 -0
  128. package/dist/src/meta/rules/no-manual-ancestor-walks.d.ts +2 -0
  129. package/dist/src/meta/rules/no-manual-ancestor-walks.js +26 -0
  130. package/dist/src/meta/rules/prefer-before-file-scope.d.ts +2 -0
  131. package/dist/src/meta/rules/prefer-before-file-scope.js +57 -0
  132. package/dist/src/meta/rules/require-create-once.d.ts +2 -0
  133. package/dist/src/meta/rules/require-create-once.js +51 -0
  134. package/dist/src/meta/rules/require-rule-tester.d.ts +2 -0
  135. package/dist/src/meta/rules/require-rule-tester.js +50 -0
  136. package/dist/src/react/index.d.ts +3 -0
  137. package/dist/src/react/index.js +16 -0
  138. package/dist/src/react/role.d.ts +23 -0
  139. package/dist/src/react/role.js +30 -0
  140. package/dist/src/react/rules/require-dot-notation-exports.d.ts +27 -0
  141. package/dist/src/react/rules/require-dot-notation-exports.js +144 -0
  142. package/dist/src/react/rules/require-guarded-context-hook.d.ts +19 -0
  143. package/dist/src/react/rules/require-guarded-context-hook.js +167 -0
  144. package/dist/src/react/rules/require-tripartite-context.d.ts +17 -0
  145. package/dist/src/react/rules/require-tripartite-context.js +160 -0
  146. package/dist/src/react/rules/use-encapsulation.d.ts +22 -0
  147. package/dist/src/react/rules/use-encapsulation.js +97 -0
  148. package/dist/src/rules/no-anonymous-wide-tuples.d.ts +7 -0
  149. package/dist/src/rules/no-anonymous-wide-tuples.js +34 -0
  150. package/dist/src/rules/no-barrel-export-star.d.ts +2 -0
  151. package/dist/src/rules/no-barrel-export-star.js +26 -0
  152. package/dist/src/rules/no-boolean-field-signals.d.ts +2 -0
  153. package/dist/src/rules/no-boolean-field-signals.js +279 -0
  154. package/dist/src/rules/no-builtin-throws.d.ts +6 -0
  155. package/dist/src/rules/no-builtin-throws.js +74 -0
  156. package/dist/src/rules/no-chained-type-assertions.d.ts +2 -0
  157. package/dist/src/rules/no-chained-type-assertions.js +54 -0
  158. package/dist/src/rules/no-conditional-empty-object-spread.d.ts +2 -0
  159. package/dist/src/rules/no-conditional-empty-object-spread.js +36 -0
  160. package/dist/src/rules/no-duplicated-literal-union.d.ts +6 -0
  161. package/dist/src/rules/no-duplicated-literal-union.js +66 -0
  162. package/dist/src/rules/no-exported-mutable-state.d.ts +7 -0
  163. package/dist/src/rules/no-exported-mutable-state.js +104 -0
  164. package/dist/src/rules/no-generic-export-names.d.ts +2 -0
  165. package/dist/src/rules/no-generic-export-names.js +141 -0
  166. package/dist/src/rules/no-impossible-branch-throw.d.ts +2 -0
  167. package/dist/src/rules/no-impossible-branch-throw.js +51 -0
  168. package/dist/src/rules/no-known-value-widening.d.ts +2 -0
  169. package/dist/src/rules/no-known-value-widening.js +176 -0
  170. package/dist/src/rules/no-module-mocking.d.ts +2 -0
  171. package/dist/src/rules/no-module-mocking.js +90 -0
  172. package/dist/src/rules/no-multiple-function-params.d.ts +2 -0
  173. package/dist/src/rules/no-multiple-function-params.js +155 -0
  174. package/dist/src/rules/no-mutable-environment-capture.d.ts +7 -0
  175. package/dist/src/rules/no-mutable-environment-capture.js +134 -0
  176. package/dist/src/rules/no-nondeterministic-core.d.ts +6 -0
  177. package/dist/src/rules/no-nondeterministic-core.js +63 -0
  178. package/dist/src/rules/no-object-parameters.d.ts +2 -0
  179. package/dist/src/rules/no-object-parameters.js +95 -0
  180. package/dist/src/rules/no-optional-function-parameters.d.ts +7 -0
  181. package/dist/src/rules/no-optional-function-parameters.js +44 -0
  182. package/dist/src/rules/no-product-of-state-booleans.d.ts +2 -0
  183. package/dist/src/rules/no-product-of-state-booleans.js +79 -0
  184. package/dist/src/rules/no-redundant-derived-field.d.ts +6 -0
  185. package/dist/src/rules/no-redundant-derived-field.js +194 -0
  186. package/dist/src/rules/no-reflect-apply.d.ts +2 -0
  187. package/dist/src/rules/no-reflect-apply.js +29 -0
  188. package/dist/src/rules/no-reflect-get.d.ts +2 -0
  189. package/dist/src/rules/no-reflect-get.js +29 -0
  190. package/dist/src/rules/no-reinterpret-cast.d.ts +2 -0
  191. package/dist/src/rules/no-reinterpret-cast.js +68 -0
  192. package/dist/src/rules/no-runtime-typeof.d.ts +2 -0
  193. package/dist/src/rules/no-runtime-typeof.js +54 -0
  194. package/dist/src/rules/no-sentinel-comparison-union.d.ts +2 -0
  195. package/dist/src/rules/no-sentinel-comparison-union.js +139 -0
  196. package/dist/src/rules/no-shape-in-symbol-names.d.ts +2 -0
  197. package/dist/src/rules/no-shape-in-symbol-names.js +39 -0
  198. package/dist/src/rules/no-single-use-private-functions.d.ts +17 -0
  199. package/dist/src/rules/no-single-use-private-functions.js +419 -0
  200. package/dist/src/rules/no-sql-string-interpolation.d.ts +7 -0
  201. package/dist/src/rules/no-sql-string-interpolation.js +62 -0
  202. package/dist/src/rules/no-stacked-jsdoc-blocks.d.ts +2 -0
  203. package/dist/src/rules/no-stacked-jsdoc-blocks.js +50 -0
  204. package/dist/src/rules/no-stray-inline-comments.d.ts +2 -0
  205. package/dist/src/rules/no-stray-inline-comments.js +74 -0
  206. package/dist/src/rules/no-swappable-primitive-params.d.ts +2 -0
  207. package/dist/src/rules/no-swappable-primitive-params.js +96 -0
  208. package/dist/src/rules/no-tag-ladder-assertions.d.ts +6 -0
  209. package/dist/src/rules/no-tag-ladder-assertions.js +63 -0
  210. package/dist/src/rules/no-transposed-field-reads.d.ts +8 -0
  211. package/dist/src/rules/no-transposed-field-reads.js +101 -0
  212. package/dist/src/rules/no-unit-return-validators.d.ts +2 -0
  213. package/dist/src/rules/no-unit-return-validators.js +64 -0
  214. package/dist/src/rules/no-unknown-parameters.d.ts +2 -0
  215. package/dist/src/rules/no-unknown-parameters.js +82 -0
  216. package/dist/src/rules/no-unknown-returns.d.ts +2 -0
  217. package/dist/src/rules/no-unknown-returns.js +86 -0
  218. package/dist/src/rules/no-unknown-type-aliases.d.ts +2 -0
  219. package/dist/src/rules/no-unknown-type-aliases.js +64 -0
  220. package/dist/src/rules/no-unsafe-dictionary-type.d.ts +2 -0
  221. package/dist/src/rules/no-unsafe-dictionary-type.js +116 -0
  222. package/dist/src/rules/no-vague-test-filenames.d.ts +2 -0
  223. package/dist/src/rules/no-vague-test-filenames.js +61 -0
  224. package/dist/src/rules/no-widen-then-assert.d.ts +2 -0
  225. package/dist/src/rules/no-widen-then-assert.js +268 -0
  226. package/dist/src/rules/prefer-payload-brand.d.ts +2 -0
  227. package/dist/src/rules/prefer-payload-brand.js +57 -0
  228. package/dist/src/rules/prefer-property-tests.d.ts +5 -0
  229. package/dist/src/rules/prefer-property-tests.js +39 -0
  230. package/dist/src/rules/require-canonical-stringify-for-identity.d.ts +8 -0
  231. package/dist/src/rules/require-canonical-stringify-for-identity.js +72 -0
  232. package/dist/src/rules/require-deprecated-tag-for-legacy-comments.d.ts +2 -0
  233. package/dist/src/rules/require-deprecated-tag-for-legacy-comments.js +34 -0
  234. package/dist/src/rules/require-exhaustive-tag-switch.d.ts +7 -0
  235. package/dist/src/rules/require-exhaustive-tag-switch.js +34 -0
  236. package/dist/src/rules/require-fc-block-predicate.d.ts +2 -0
  237. package/dist/src/rules/require-fc-block-predicate.js +37 -0
  238. package/dist/src/rules/require-jsdoc-on-exported.d.ts +2 -0
  239. package/dist/src/rules/require-jsdoc-on-exported.js +66 -0
  240. package/dist/src/rules/require-published-order.d.ts +2 -0
  241. package/dist/src/rules/require-published-order.js +102 -0
  242. package/dist/src/rules/require-safety-comment-for-type-assertion.d.ts +2 -0
  243. package/dist/src/rules/require-safety-comment-for-type-assertion.js +53 -0
  244. package/dist/src/rules/require-sort-comparator.d.ts +7 -0
  245. package/dist/src/rules/require-sort-comparator.js +34 -0
  246. package/dist/src/rules/test-utils.d.ts +35 -0
  247. package/dist/src/rules/test-utils.js +53 -0
  248. package/dist/src/shared/ancestors.d.ts +18 -0
  249. package/dist/src/shared/ancestors.js +19 -0
  250. package/dist/src/shared/child-nodes.d.ts +12 -0
  251. package/dist/src/shared/child-nodes.js +26 -0
  252. package/dist/src/shared/dictionary-types.d.ts +55 -0
  253. package/dist/src/shared/dictionary-types.js +413 -0
  254. package/dist/src/shared/is-node.d.ts +9 -0
  255. package/dist/src/shared/is-node.js +10 -0
  256. package/dist/src/shared/lexical-type-parameters.d.ts +12 -0
  257. package/dist/src/shared/lexical-type-parameters.js +50 -0
  258. package/dist/src/shared/reflect-method.d.ts +15 -0
  259. package/dist/src/shared/reflect-method.js +32 -0
  260. package/dist/src/shared/rule-options.d.ts +18 -0
  261. package/dist/src/shared/rule-options.js +12 -0
  262. package/dist/src/shared/structural.d.ts +54 -0
  263. package/dist/src/shared/structural.js +40 -0
  264. package/dist/src/testing/index.d.ts +2 -0
  265. package/dist/src/testing/index.js +1 -0
  266. package/dist/src/testing/testable-rule.d.ts +39 -0
  267. package/dist/src/testing/testable-rule.js +84 -0
  268. package/dist/src/ui/index.d.ts +12 -0
  269. package/dist/src/ui/index.js +18 -0
  270. package/dist/src/ui/manifest.d.ts +34 -0
  271. package/dist/src/ui/manifest.js +75 -0
  272. package/dist/src/ui/rules/no-deprecated-parts.d.ts +3 -0
  273. package/dist/src/ui/rules/no-deprecated-parts.js +131 -0
  274. package/dist/testing/testable-rule.d.ts +6 -5
  275. package/dist/testing/testable-rule.js +20 -6
  276. package/dist/ui/index.d.ts +12 -0
  277. package/dist/ui/index.js +18 -0
  278. package/dist/ui/manifest.d.ts +49 -0
  279. package/dist/ui/manifest.js +90 -0
  280. package/dist/ui/rules/no-deprecated-parts.d.ts +3 -0
  281. package/dist/ui/rules/no-deprecated-parts.js +172 -0
  282. package/package.json +20 -11
@@ -0,0 +1,135 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
3
+ const ORDERING_OPERATORS = new Set(["<", ">", "<=", ">=", "===", "=="]);
4
+ function isZeroLiteral(expression) {
5
+ return (expression !== null &&
6
+ expression !== undefined &&
7
+ expression.type === "Literal" &&
8
+ expression.value === 0);
9
+ }
10
+ /** Source text of the operand compared against zero, or null when this is not one.
11
+ *
12
+ * @param {{ test: ESTree.Expression; sourceText: string }} payload - The compared test and its source text.
13
+ * @returns {string | null} Source text of the non-zero side, or null.
14
+ */
15
+ function orderingZeroSubject(payload) {
16
+ const { test, sourceText } = payload;
17
+ let binary = test;
18
+ while (binary.type === "ParenthesizedExpression") {
19
+ binary = binary.expression;
20
+ }
21
+ if (binary.type !== "BinaryExpression" || !ORDERING_OPERATORS.has(binary.operator)) {
22
+ return null;
23
+ }
24
+ const slice = (expression) => sourceText.slice(expression.range?.[0] ?? 0, expression.range?.[1] ?? 0).trim();
25
+ if (isZeroLiteral(binary.right))
26
+ return slice(binary.left);
27
+ if (isZeroLiteral(binary.left))
28
+ return slice(binary.right);
29
+ return null;
30
+ }
31
+ function isSentinelValue(expression) {
32
+ if (expression === null || expression === undefined)
33
+ return false;
34
+ if (expression.type === "ParenthesizedExpression") {
35
+ return isSentinelValue(expression.expression);
36
+ }
37
+ if (expression.type === "UnaryExpression") {
38
+ return (expression.operator === "-" &&
39
+ expression.argument.type === "Literal" &&
40
+ expression.argument.value === 1);
41
+ }
42
+ return expression.type === "Literal" && (expression.value === 0 || expression.value === 1);
43
+ }
44
+ function lastReturnedValue(block) {
45
+ const statement = block.body[block.body.length - 1];
46
+ return statement !== undefined && statement.type === "ReturnStatement"
47
+ ? statement.argument
48
+ : undefined;
49
+ }
50
+ /** Hand-mapping an ordering comparison to domain values duplicates Ordering.match. */
51
+ export const preferOrderingMatchRule = defineRule({
52
+ meta: {
53
+ type: "problem",
54
+ docs: {
55
+ description: "Require ladders of conditional branches re-testing the same ordering comparison against zero to be expressed as one Ordering.match table.",
56
+ },
57
+ messages: {
58
+ preferOrderingMatch: "This ladder re-tests `{{subject}}` against zero {{links}} times to pick domain values. Replace it with a single Ordering.match({ onLessThan, onEqual, onGreaterThan }) over the comparison result so the direction mapping lives in one exhaustive table.",
59
+ },
60
+ },
61
+ createOnce(context) {
62
+ const checkChain = (tests, leaves) => {
63
+ if (tests.length < 2)
64
+ return;
65
+ if (tests.some((test) => test.subject === null))
66
+ return;
67
+ const subject = tests[0].subject;
68
+ if (tests.some((test) => test.subject !== subject))
69
+ return;
70
+ if (leaves.every((leaf) => isSentinelValue(leaf)))
71
+ return;
72
+ context.report({
73
+ node: tests[0].node,
74
+ messageId: "preferOrderingMatch",
75
+ data: { subject, links: String(tests.length) },
76
+ });
77
+ };
78
+ return {
79
+ before() {
80
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
81
+ return false;
82
+ },
83
+ ConditionalExpression(node) {
84
+ const tests = [];
85
+ const leaves = [];
86
+ let current = node;
87
+ while (current !== null && current.type === "ConditionalExpression") {
88
+ tests.push({
89
+ subject: orderingZeroSubject({ test: current.test, sourceText: context.sourceCode.text }),
90
+ node: current.test,
91
+ });
92
+ leaves.push(current.consequent);
93
+ const alternate = current.alternate;
94
+ if (alternate.type === "ConditionalExpression") {
95
+ current = alternate;
96
+ }
97
+ else {
98
+ leaves.push(alternate);
99
+ current = null;
100
+ }
101
+ }
102
+ checkChain(tests, leaves);
103
+ },
104
+ IfStatement(node) {
105
+ const tests = [];
106
+ const leaves = [];
107
+ let current = node;
108
+ while (current !== null && current.type === "IfStatement") {
109
+ tests.push({
110
+ subject: orderingZeroSubject({ test: current.test, sourceText: context.sourceCode.text }),
111
+ node: current.test,
112
+ });
113
+ const consequent = current.consequent;
114
+ leaves.push(consequent.type === "BlockStatement"
115
+ ? lastReturnedValue(consequent)
116
+ : consequent);
117
+ const alternate = current.alternate;
118
+ if (alternate === null) {
119
+ current = null;
120
+ }
121
+ else if (alternate.type === "IfStatement") {
122
+ current = alternate;
123
+ }
124
+ else {
125
+ leaves.push(alternate.type === "BlockStatement"
126
+ ? lastReturnedValue(alternate)
127
+ : alternate);
128
+ current = null;
129
+ }
130
+ }
131
+ checkChain(tests, leaves);
132
+ },
133
+ };
134
+ },
135
+ });
@@ -0,0 +1,2 @@
1
+ /** Hand-rolled _tag unions duplicate what Data.TaggedEnum gives for free. */
2
+ export declare const preferTaggedEnumRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,66 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { isRecordObject, isString } from "../../shared/structural.js";
3
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
4
+ /** Whether a type-literal member declares a literal-typed `_tag` property.
5
+ *
6
+ * @param {ESTree.Node} member - A member of a type literal.
7
+ * @returns {boolean} True when the member is `_tag` with a string literal type.
8
+ */
9
+ function hasLiteralTagProperty(member) {
10
+ if (member.type !== "TSPropertySignature")
11
+ return false;
12
+ const key = member.key;
13
+ const isTagKey = (key.type === "Identifier" && key.name === "_tag") ||
14
+ (key.type === "Literal" && key.value === "_tag");
15
+ if (!isTagKey)
16
+ return false;
17
+ const annotation = member.typeAnnotation?.typeAnnotation;
18
+ if (annotation === undefined || annotation === null || annotation.type !== "TSLiteralType") {
19
+ return false;
20
+ }
21
+ return annotation.literal.type === "Literal" && isString(annotation.literal.value);
22
+ }
23
+ /** Whether every union constituent is a type literal carrying a `_tag` property.
24
+ *
25
+ * @param {ESTree.TSType} member - One constituent of a union annotation.
26
+ * @returns {boolean} True when the member is a type literal with a `_tag`.
27
+ */
28
+ function isTaggedLiteralMember(member) {
29
+ if (member.type !== "TSTypeLiteral")
30
+ return false;
31
+ return member.members.some(hasLiteralTagProperty);
32
+ }
33
+ /** Hand-rolled _tag unions duplicate what Data.TaggedEnum gives for free. */
34
+ export const preferTaggedEnumRule = defineRule({
35
+ meta: {
36
+ type: "problem",
37
+ docs: {
38
+ description: "Require internal tagged unions to be declared with Data.TaggedEnum (constructors, $is guards and exhaustive $match) instead of hand-rolled _tag object-literal unions with manual type guards.",
39
+ },
40
+ messages: {
41
+ preferTaggedEnum: "This union hand-rolls `_tag` discrimination. Declare it as `type {{name}} = Data.TaggedEnum<{...}>` and derive constructors, `$is` guards and exhaustive `$match` via `Data.taggedEnum<{{name}}>()`, matching the rational.ts idiom.",
42
+ },
43
+ },
44
+ createOnce(context) {
45
+ return {
46
+ before() {
47
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
48
+ return false;
49
+ },
50
+ TSTypeAliasDeclaration(node) {
51
+ const annotation = node.typeAnnotation;
52
+ if (annotation.type !== "TSUnionType")
53
+ return;
54
+ if (annotation.types.length < 2)
55
+ return;
56
+ if (!annotation.types.every((member) => isTaggedLiteralMember(member)))
57
+ return;
58
+ context.report({
59
+ node: node.id,
60
+ messageId: "preferTaggedEnum",
61
+ data: { name: node.id.name },
62
+ });
63
+ },
64
+ };
65
+ },
66
+ });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Single source of truth: once a Schema exists, it is the canonical shape.
3
+ * A hand-written twin type drifts from it silently: derive the static side
4
+ * with `Schema.Type<typeof x>` so identical data can only have one declared
5
+ * form.
6
+ */
7
+ export declare const requireSchemaTypeDerivationRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,80 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ const STRUCT_PROPERTIES = new Set(["Struct", "TaggedStruct"]);
3
+ /**
4
+ * Whether an expression calls `Schema.struct`/`Schema.fields` on a schema-ish object.
5
+ *
6
+ * @param {ESTree.Expression | ESTree.SpreadElement | null} expression - The candidate call expression.
7
+ * @returns {boolean} True when the expression is a schema struct-style call.
8
+ */
9
+ function isSchemaStructCall(expression) {
10
+ if (expression === null || expression.type !== "CallExpression")
11
+ return false;
12
+ const callee = expression.callee;
13
+ if (callee.type !== "MemberExpression" || callee.computed)
14
+ return false;
15
+ if (callee.property.type !== "Identifier" || !STRUCT_PROPERTIES.has(callee.property.name))
16
+ return false;
17
+ const object = callee.object;
18
+ return (object.type === "Identifier" && /schema$/iu.test(object.name));
19
+ }
20
+ /** Fold a declared name to its stem so `RationalSchema`/`rational` and `rationalSchema` collide.
21
+ *
22
+ * @param {string} name - The declared name to fold.
23
+ * @returns {string} The case-insensitive comparison stem.
24
+ */
25
+ function normaliseName(name) {
26
+ const folded = name.replaceAll(/[^a-zA-Z0-9]/gu, "").toLowerCase();
27
+ return folded.endsWith("schema") ? folded.slice(0, -6) : folded;
28
+ }
29
+ /**
30
+ * Single source of truth: once a Schema exists, it is the canonical shape.
31
+ * A hand-written twin type drifts from it silently: derive the static side
32
+ * with `Schema.Type<typeof x>` so identical data can only have one declared
33
+ * form.
34
+ */
35
+ export const requireSchemaTypeDerivationRule = defineRule({
36
+ meta: {
37
+ type: "problem",
38
+ docs: {
39
+ description: "Require static types paired with an Effect Schema to be derived via Schema.Type<typeof schema> instead of re-declaring the shape by hand.",
40
+ },
41
+ messages: {
42
+ handWrittenTwin: "`{{name}}` re-declares the shape of `{{schema}}` by hand, giving the data two sources of truth that drift. Derive it as `Schema.Type<typeof {{schema}}>` (or rename if unrelated).",
43
+ },
44
+ },
45
+ createOnce(context) {
46
+ const schemas = new Map();
47
+ const typeAliases = new Map();
48
+ return {
49
+ VariableDeclarator(node) {
50
+ if (node.id.type !== "Identifier" || node.init === null || node.init === undefined)
51
+ return;
52
+ if (!isSchemaStructCall(node.init))
53
+ return;
54
+ schemas.set(normaliseName(node.id.name), node.id.name);
55
+ },
56
+ TSTypeAliasDeclaration(node) {
57
+ if (node.typeAnnotation.type !== "TSTypeLiteral")
58
+ return;
59
+ typeAliases.set(normaliseName(node.id.name), { node, name: node.id.name });
60
+ },
61
+ TSInterfaceDeclaration(node) {
62
+ if (node.id.type !== "Identifier")
63
+ return;
64
+ typeAliases.set(normaliseName(node.id.name), { node, name: node.id.name });
65
+ },
66
+ "Program:exit"() {
67
+ for (const [stem, alias] of typeAliases) {
68
+ const schema = schemas.get(stem);
69
+ if (schema === undefined)
70
+ continue;
71
+ context.report({
72
+ node: alias.node,
73
+ messageId: "handWrittenTwin",
74
+ data: { name: alias.name, schema },
75
+ });
76
+ }
77
+ },
78
+ };
79
+ },
80
+ });
@@ -0,0 +1,3 @@
1
+ /** Generic Oxlint rules that reject low-evidence and low-signal implementation patterns. */
2
+ declare const plumbPlugin: import("@oxlint/plugins").Plugin;
3
+ export default plumbPlugin;
@@ -0,0 +1,106 @@
1
+ import { eslintCompatPlugin } from "@oxlint/plugins";
2
+ import { preferPropertyTestsRule } from "./rules/prefer-property-tests.js";
3
+ import { noChainedTypeAssertionsRule } from "./rules/no-chained-type-assertions.js";
4
+ import { noConditionalEmptyObjectSpreadRule } from "./rules/no-conditional-empty-object-spread.js";
5
+ import { noBooleanFieldSignalsRule } from "./rules/no-boolean-field-signals.js";
6
+ import { noImpossibleBranchThrowRule } from "./rules/no-impossible-branch-throw.js";
7
+ import { noKnownValueWideningRule } from "./rules/no-known-value-widening.js";
8
+ import { noModuleMockingRule } from "./rules/no-module-mocking.js";
9
+ import { noObjectParametersRule } from "./rules/no-object-parameters.js";
10
+ import { noReinterpretCastRule } from "./rules/no-reinterpret-cast.js";
11
+ import { preferPayloadBrandRule } from "./rules/prefer-payload-brand.js";
12
+ import { noProductOfStateBooleansRule } from "./rules/no-product-of-state-booleans.js";
13
+ import { noReflectApplyRule } from "./rules/no-reflect-apply.js";
14
+ import { requireFcBlockPredicateRule } from "./rules/require-fc-block-predicate.js";
15
+ import { requireJsdocOnExportedRule } from "./rules/require-jsdoc-on-exported.js";
16
+ import { requirePublishedOrderRule } from "./rules/require-published-order.js";
17
+ import { noReflectGetRule } from "./rules/no-reflect-get.js";
18
+ import { noRuntimeTypeofRule } from "./rules/no-runtime-typeof.js";
19
+ import { noSentinelComparisonUnionRule } from "./rules/no-sentinel-comparison-union.js";
20
+ import { noStackedJsdocBlocksRule } from "./rules/no-stacked-jsdoc-blocks.js";
21
+ import { noForbiddenTermInSymbolNamesRule } from "./rules/no-shape-in-symbol-names.js";
22
+ import { noUnitReturnValidatorsRule } from "./rules/no-unit-return-validators.js";
23
+ import { noUnknownParametersRule } from "./rules/no-unknown-parameters.js";
24
+ import { noUnknownReturnsRule } from "./rules/no-unknown-returns.js";
25
+ import { noUnknownTypeAliasesRule } from "./rules/no-unknown-type-aliases.js";
26
+ import { noUnsafeDictionaryTypeRule } from "./rules/no-unsafe-dictionary-type.js";
27
+ import { noStrayInlineCommentsRule } from "./rules/no-stray-inline-comments.js";
28
+ import { noWidenThenAssertRule } from "./rules/no-widen-then-assert.js";
29
+ import { requireSafetyCommentForTypeAssertionRule } from "./rules/require-safety-comment-for-type-assertion.js";
30
+ import { requireSortComparatorRule } from "./rules/require-sort-comparator.js";
31
+ import { noGenericExportNamesRule } from "./rules/no-generic-export-names.js";
32
+ import { noBarrelExportStarRule } from "./rules/no-barrel-export-star.js";
33
+ import { requireDeprecatedTagForLegacyCommentsRule } from "./rules/require-deprecated-tag-for-legacy-comments.js";
34
+ import { noVagueTestFilenamesRule } from "./rules/no-vague-test-filenames.js";
35
+ import { noSwappablePrimitiveParamsRule } from "./rules/no-swappable-primitive-params.js";
36
+ import { noTransposedFieldReadsRule } from "./rules/no-transposed-field-reads.js";
37
+ import { noBuiltinThrowsRule } from "./rules/no-builtin-throws.js";
38
+ import { noNondeterministicCoreRule } from "./rules/no-nondeterministic-core.js";
39
+ import { noExportedMutableStateRule } from "./rules/no-exported-mutable-state.js";
40
+ import { noDuplicatedLiteralUnionRule } from "./rules/no-duplicated-literal-union.js";
41
+ import { requireCanonicalStringifyForIdentityRule } from "./rules/require-canonical-stringify-for-identity.js";
42
+ import { noAnonymousWideTuplesRule } from "./rules/no-anonymous-wide-tuples.js";
43
+ import { noTagLadderAssertionsRule } from "./rules/no-tag-ladder-assertions.js";
44
+ import { noRedundantDerivedFieldRule } from "./rules/no-redundant-derived-field.js";
45
+ import { requireExhaustiveTagSwitchRule } from "./rules/require-exhaustive-tag-switch.js";
46
+ import { noMultipleFunctionParamsRule } from "./rules/no-multiple-function-params.js";
47
+ import { noOptionalFunctionParametersRule } from "./rules/no-optional-function-parameters.js";
48
+ import { noSingleUsePrivateFunctionsRule } from "./rules/no-single-use-private-functions.js";
49
+ import { noMutableEnvironmentCaptureRule } from "./rules/no-mutable-environment-capture.js";
50
+ import { noSqlStringInterpolationRule } from "./rules/no-sql-string-interpolation.js";
51
+ /** Generic Oxlint rules that reject low-evidence and low-signal implementation patterns. */
52
+ const plumbPlugin = eslintCompatPlugin({
53
+ meta: { name: "plumb" },
54
+ rules: {
55
+ "no-chained-type-assertions": noChainedTypeAssertionsRule,
56
+ "no-boolean-field-signals": noBooleanFieldSignalsRule,
57
+ "no-conditional-empty-object-spread": noConditionalEmptyObjectSpreadRule,
58
+ "no-impossible-branch-throw": noImpossibleBranchThrowRule,
59
+ "no-known-value-widening": noKnownValueWideningRule,
60
+ "no-module-mocking": noModuleMockingRule,
61
+ "no-object-parameters": noObjectParametersRule,
62
+ "no-reinterpret-cast": noReinterpretCastRule,
63
+ "prefer-payload-brand": preferPayloadBrandRule,
64
+ "no-product-of-state-booleans": noProductOfStateBooleansRule,
65
+ "no-reflect-apply": noReflectApplyRule,
66
+ "require-published-order": requirePublishedOrderRule,
67
+ "no-reflect-get": noReflectGetRule,
68
+ "no-runtime-typeof": noRuntimeTypeofRule,
69
+ "no-sentinel-comparison-union": noSentinelComparisonUnionRule,
70
+ "no-stacked-jsdoc-blocks": noStackedJsdocBlocksRule,
71
+ "no-stray-inline-comments": noStrayInlineCommentsRule,
72
+ "no-unit-return-validators": noUnitReturnValidatorsRule,
73
+ "no-unsafe-dictionary-type": noUnsafeDictionaryTypeRule,
74
+ "no-shape-in-symbol-names": noForbiddenTermInSymbolNamesRule,
75
+ "no-unknown-parameters": noUnknownParametersRule,
76
+ "no-unknown-returns": noUnknownReturnsRule,
77
+ "no-unknown-type-aliases": noUnknownTypeAliasesRule,
78
+ "no-widen-then-assert": noWidenThenAssertRule,
79
+ "require-fc-block-predicate": requireFcBlockPredicateRule,
80
+ "require-jsdoc-on-exported": requireJsdocOnExportedRule,
81
+ "require-safety-comment-for-type-assertion": requireSafetyCommentForTypeAssertionRule,
82
+ "require-sort-comparator": requireSortComparatorRule,
83
+ "no-generic-export-names": noGenericExportNamesRule,
84
+ "no-barrel-export-star": noBarrelExportStarRule,
85
+ "require-deprecated-tag-for-legacy-comments": requireDeprecatedTagForLegacyCommentsRule,
86
+ "no-vague-test-filenames": noVagueTestFilenamesRule,
87
+ "no-swappable-primitive-params": noSwappablePrimitiveParamsRule,
88
+ "no-transposed-field-reads": noTransposedFieldReadsRule,
89
+ "no-builtin-throws": noBuiltinThrowsRule,
90
+ "no-nondeterministic-core": noNondeterministicCoreRule,
91
+ "no-exported-mutable-state": noExportedMutableStateRule,
92
+ "no-tag-ladder-assertions": noTagLadderAssertionsRule,
93
+ "no-anonymous-wide-tuples": noAnonymousWideTuplesRule,
94
+ "no-duplicated-literal-union": noDuplicatedLiteralUnionRule,
95
+ "require-canonical-stringify-for-identity": requireCanonicalStringifyForIdentityRule,
96
+ "no-redundant-derived-field": noRedundantDerivedFieldRule,
97
+ "require-exhaustive-tag-switch": requireExhaustiveTagSwitchRule,
98
+ "prefer-property-tests": preferPropertyTestsRule,
99
+ "no-multiple-function-params": noMultipleFunctionParamsRule,
100
+ "no-optional-function-parameters": noOptionalFunctionParametersRule,
101
+ "no-single-use-private-functions": noSingleUsePrivateFunctionsRule,
102
+ "no-mutable-environment-capture": noMutableEnvironmentCaptureRule,
103
+ "no-sql-string-interpolation": noSqlStringInterpolationRule,
104
+ },
105
+ });
106
+ export default plumbPlugin;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Meta-rules that keep rule authorship itself idiomatic (createOnce API, engine-native
3
+ * traversal, RuleTester suites, property-based coverage). Opt-in: only meaningful in
4
+ * lint-plugin codebases, so consumers enable `plumb-meta` deliberately.
5
+ */
6
+ declare const plumbMetaPlugin: import("@oxlint/plugins").Plugin;
7
+ export default plumbMetaPlugin;
@@ -0,0 +1,22 @@
1
+ import { eslintCompatPlugin } from "@oxlint/plugins";
2
+ import { noDisableDirectivesRule } from "./rules/no-disable-directives.js";
3
+ import { noManualAncestorWalksRule } from "./rules/no-manual-ancestor-walks.js";
4
+ import { preferBeforeFileScopeRule } from "./rules/prefer-before-file-scope.js";
5
+ import { requireCreateOnceRule } from "./rules/require-create-once.js";
6
+ import { requireRuleTesterRule } from "./rules/require-rule-tester.js";
7
+ /**
8
+ * Meta-rules that keep rule authorship itself idiomatic (createOnce API, engine-native
9
+ * traversal, RuleTester suites, property-based coverage). Opt-in: only meaningful in
10
+ * lint-plugin codebases, so consumers enable `plumb-meta` deliberately.
11
+ */
12
+ const plumbMetaPlugin = eslintCompatPlugin({
13
+ meta: { name: "plumb-meta" },
14
+ rules: {
15
+ "no-disable-directives": noDisableDirectivesRule,
16
+ "no-manual-ancestor-walks": noManualAncestorWalksRule,
17
+ "prefer-before-file-scope": preferBeforeFileScopeRule,
18
+ "require-create-once": requireCreateOnceRule,
19
+ "require-rule-tester": requireRuleTesterRule,
20
+ },
21
+ });
22
+ export default plumbMetaPlugin;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Inline suppression comments hide lint failures from the exact files where
3
+ * enforcement matters most. Fix the code or scope a justified override in the
4
+ * config; do not silence rules line-by-line.
5
+ */
6
+ export declare const noDisableDirectivesRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,35 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ /**
3
+ * Inline suppression comments hide lint failures from the exact files where
4
+ * enforcement matters most. Fix the code or scope a justified override in the
5
+ * config; do not silence rules line-by-line.
6
+ */
7
+ export const noDisableDirectivesRule = defineRule({
8
+ meta: {
9
+ type: "problem",
10
+ docs: {
11
+ description: "Disallow `// oxlint-disable` suppression comments; fix the finding or add a justified file-scoped config override instead.",
12
+ },
13
+ messages: {
14
+ suppressionDirective: "Inline suppression comments make findings invisible without making them gone. Prefer fixing the code; if an exception is truly warranted, use a scoped override entry in oxlint.config.ts with a written reason.",
15
+ },
16
+ },
17
+ createOnce(context) {
18
+ let program = null;
19
+ return {
20
+ Program(node) {
21
+ program = node;
22
+ },
23
+ "Program:exit"() {
24
+ if (program === null)
25
+ return;
26
+ for (const comment of context.sourceCode.getAllComments()) {
27
+ if (!/^\s*oxlint-disable\b/u.test(comment.value))
28
+ continue;
29
+ context.report({ node: program, messageId: "suppressionDirective" });
30
+ return;
31
+ }
32
+ },
33
+ };
34
+ },
35
+ });
@@ -0,0 +1,2 @@
1
+ /** Hand-rolled `.parent` loops duplicate sourceCode.getAncestors and hide traversal intent. */
2
+ export declare const noManualAncestorWalksRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,26 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ /** Hand-rolled `.parent` loops duplicate sourceCode.getAncestors and hide traversal intent. */
3
+ export const noManualAncestorWalksRule = defineRule({
4
+ meta: {
5
+ type: "suggestion",
6
+ docs: {
7
+ description: "Disallow manual `.parent` walks; use `context.sourceCode.getAncestors(node)`.",
8
+ },
9
+ messages: {
10
+ useGetAncestors: "Hand-rolled ancestor walking via `.parent` obscures traversal intent. Use `context.sourceCode.getAncestors(node)` (root-first array) and express the search declaratively.",
11
+ },
12
+ },
13
+ createOnce(context) {
14
+ return {
15
+ MemberExpression(node) {
16
+ if (node.computed)
17
+ return;
18
+ if (node.property.type !== "Identifier")
19
+ return;
20
+ if (node.property.name !== "parent")
21
+ return;
22
+ context.report({ node, messageId: "useGetAncestors" });
23
+ },
24
+ };
25
+ },
26
+ });
@@ -0,0 +1,2 @@
1
+ /** File-scoping logic belongs in the `before` hook, not scattered through visitors or `create`. */
2
+ export declare const preferBeforeFileScopeRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,57 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { isString, readField } from "../../shared/structural.js";
3
+ /**
4
+ * Property-name reader for visitor properties. The `Property` selector receives
5
+ * Object/Binding/AssignmentTarget properties; all share this structural shape.
6
+ *
7
+ * @param {{ readonly computed: boolean; readonly key: ESTree.Expression | ESTree.PrivateIdentifier }} node - A visited property node.
8
+ * @returns {string | null} The non-computed property's identifier or literal string name.
9
+ */
10
+ function propertyName(node) {
11
+ if (node.computed)
12
+ return null;
13
+ const key = node.key;
14
+ const name = readField(key, "name");
15
+ if (readField(key, "type") === "Identifier" && isString(name))
16
+ return name;
17
+ const value = readField(key, "value");
18
+ if (readField(key, "type") === "Literal" && isString(value))
19
+ return value;
20
+ return null;
21
+ }
22
+ /** File-scoping logic belongs in the `before` hook, not scattered through visitors or `create`. */
23
+ export const preferBeforeFileScopeRule = defineRule({
24
+ meta: {
25
+ type: "suggestion",
26
+ docs: {
27
+ description: "Read `context.filename` only inside a `before` hook; skip the file by returning `false` there.",
28
+ },
29
+ messages: {
30
+ moveToBefore: "File-scoping read of `context.filename` outside `before()`. Do file selection in `before()` and return `false` to skip the file, keeping visitors free of filename checks.",
31
+ },
32
+ },
33
+ createOnce(context) {
34
+ let insideBeforeHook = false;
35
+ return {
36
+ Property(node) {
37
+ if (!insideBeforeHook && propertyName(node) === "before")
38
+ insideBeforeHook = true;
39
+ },
40
+ "Property:exit"(node) {
41
+ if (insideBeforeHook && propertyName(node) === "before")
42
+ insideBeforeHook = false;
43
+ },
44
+ MemberExpression(node) {
45
+ if (insideBeforeHook)
46
+ return;
47
+ if (node.computed)
48
+ return;
49
+ if (node.object.type !== "Identifier" || node.object.name !== "context")
50
+ return;
51
+ if (node.property.type !== "Identifier" || node.property.name !== "filename")
52
+ return;
53
+ context.report({ node, messageId: "moveToBefore" });
54
+ },
55
+ };
56
+ },
57
+ });
@@ -0,0 +1,2 @@
1
+ /** Rule objects should opt into Oxlint's performant createOnce API, not ESLint's per-file create. */
2
+ export declare const requireCreateOnceRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,51 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { isString } from "../../shared/structural.js";
3
+ /**
4
+ * Static property name of an object property node.
5
+ *
6
+ * @param {ESTree.ObjectProperty} key - The property node to inspect.
7
+ * @returns {string | null} The identifier or literal string name, or null when computed.
8
+ */
9
+ function propertyName(key) {
10
+ if (key.computed)
11
+ return null;
12
+ if (key.key.type === "Identifier")
13
+ return key.key.name;
14
+ if (key.key.type === "Literal" && isString(key.key.value))
15
+ return key.key.value;
16
+ return null;
17
+ }
18
+ /** Rule objects should opt into Oxlint's performant createOnce API, not ESLint's per-file create. */
19
+ export const requireCreateOnceRule = defineRule({
20
+ meta: {
21
+ type: "suggestion",
22
+ docs: {
23
+ description: "Require `createOnce` instead of `create` when authoring Oxlint rules.",
24
+ },
25
+ messages: {
26
+ useCreateOnce: "`create` re-runs per file and blocks Oxlint's Rust-side traversal optimizations. Use `createOnce` (per-file setup belongs in the `before` hook).",
27
+ },
28
+ },
29
+ createOnce(context) {
30
+ const visitObject = (node) => {
31
+ const keys = new Set();
32
+ let createProperty = null;
33
+ for (const property of node.properties) {
34
+ if (property.type !== "Property")
35
+ continue;
36
+ const name = propertyName(property);
37
+ if (name === null)
38
+ continue;
39
+ keys.add(name);
40
+ if (name === "create")
41
+ createProperty = property;
42
+ }
43
+ if (createProperty !== null && keys.has("meta")) {
44
+ context.report({ node: createProperty, messageId: "useCreateOnce" });
45
+ }
46
+ };
47
+ return {
48
+ ObjectExpression: visitObject,
49
+ };
50
+ },
51
+ });
@@ -0,0 +1,2 @@
1
+ /** Tests for lint rules belong in Oxlint's RuleTester: valid/invalid cases with message and span assertions. */
2
+ export declare const requireRuleTesterRule: import("@oxlint/plugins").Rule;