@autotelic/plumb 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. package/dist/effect/index.d.ts +3 -0
  2. package/dist/effect/index.js +56 -0
  3. package/dist/effect/rules/guarded-op-must-return-effect.d.ts +6 -0
  4. package/dist/effect/rules/guarded-op-must-return-effect.js +235 -0
  5. package/dist/effect/rules/guarded-op-must-return-option.d.ts +2 -0
  6. package/dist/effect/rules/guarded-op-must-return-option.js +88 -0
  7. package/dist/effect/rules/no-cascading-layer-provide.d.ts +6 -0
  8. package/dist/effect/rules/no-cascading-layer-provide.js +73 -0
  9. package/dist/effect/rules/no-decode-unknown-option.d.ts +7 -0
  10. package/dist/effect/rules/no-decode-unknown-option.js +34 -0
  11. package/dist/effect/rules/no-direct-browser-storage.d.ts +2 -0
  12. package/dist/effect/rules/no-direct-browser-storage.js +88 -0
  13. package/dist/effect/rules/no-direct-fetch.d.ts +2 -0
  14. package/dist/effect/rules/no-direct-fetch.js +37 -0
  15. package/dist/effect/rules/no-manual-field-guards.d.ts +6 -0
  16. package/dist/effect/rules/no-manual-field-guards.js +129 -0
  17. package/dist/effect/rules/no-nested-layer-provide.d.ts +2 -0
  18. package/dist/effect/rules/no-nested-layer-provide.js +50 -0
  19. package/dist/effect/rules/no-schema-class-modeling.d.ts +2 -0
  20. package/dist/effect/rules/no-schema-class-modeling.js +52 -0
  21. package/dist/effect/rules/no-service-constructor-imports.d.ts +2 -0
  22. package/dist/effect/rules/no-service-constructor-imports.js +42 -0
  23. package/dist/effect/rules/no-silent-error-swallow.d.ts +2 -0
  24. package/dist/effect/rules/no-silent-error-swallow.js +95 -0
  25. package/dist/effect/rules/no-static-effect-service-forwarders.d.ts +6 -0
  26. package/dist/effect/rules/no-static-effect-service-forwarders.js +222 -0
  27. package/dist/effect/rules/no-try-catch.d.ts +2 -0
  28. package/dist/effect/rules/no-try-catch.js +30 -0
  29. package/dist/effect/rules/no-unguarded-json-parse.d.ts +5 -0
  30. package/dist/effect/rules/no-unguarded-json-parse.js +200 -0
  31. package/dist/effect/rules/option-core-needs-effect-public.d.ts +5 -0
  32. package/dist/effect/rules/option-core-needs-effect-public.js +76 -0
  33. package/dist/effect/rules/prefer-die-for-precondition-defects.d.ts +5 -0
  34. package/dist/effect/rules/prefer-die-for-precondition-defects.js +112 -0
  35. package/dist/effect/rules/prefer-effect-gen-for-guard-ladders.d.ts +5 -0
  36. package/dist/effect/rules/prefer-effect-gen-for-guard-ladders.js +72 -0
  37. package/dist/effect/rules/prefer-effect-match.d.ts +2 -0
  38. package/dist/effect/rules/prefer-effect-match.js +74 -0
  39. package/dist/effect/rules/prefer-effect-predicate-over-boolean-function.d.ts +2 -0
  40. package/dist/effect/rules/prefer-effect-predicate-over-boolean-function.js +75 -0
  41. package/dist/effect/rules/prefer-named-guard-predicate.d.ts +2 -0
  42. package/dist/effect/rules/prefer-named-guard-predicate.js +93 -0
  43. package/dist/effect/rules/prefer-option-pipeline.d.ts +2 -0
  44. package/dist/effect/rules/prefer-option-pipeline.js +87 -0
  45. package/dist/effect/rules/prefer-ordering-match.d.ts +2 -0
  46. package/dist/effect/rules/prefer-ordering-match.js +135 -0
  47. package/dist/effect/rules/prefer-tagged-enum.d.ts +2 -0
  48. package/dist/effect/rules/prefer-tagged-enum.js +66 -0
  49. package/dist/effect/rules/require-schema-type-derivation.d.ts +7 -0
  50. package/dist/effect/rules/require-schema-type-derivation.js +80 -0
  51. package/dist/index.d.ts +3 -0
  52. package/dist/index.js +102 -0
  53. package/dist/meta/index.d.ts +7 -0
  54. package/{src/meta/index.ts → dist/meta/index.js} +13 -16
  55. package/dist/meta/rules/no-disable-directives.d.ts +6 -0
  56. package/dist/meta/rules/no-disable-directives.js +35 -0
  57. package/dist/meta/rules/no-manual-ancestor-walks.d.ts +2 -0
  58. package/dist/meta/rules/no-manual-ancestor-walks.js +26 -0
  59. package/dist/meta/rules/prefer-before-file-scope.d.ts +2 -0
  60. package/dist/meta/rules/prefer-before-file-scope.js +57 -0
  61. package/dist/meta/rules/require-create-once.d.ts +2 -0
  62. package/dist/meta/rules/require-create-once.js +51 -0
  63. package/dist/meta/rules/require-rule-tester.d.ts +2 -0
  64. package/dist/meta/rules/require-rule-tester.js +50 -0
  65. package/dist/rules/no-anonymous-wide-tuples.d.ts +7 -0
  66. package/dist/rules/no-anonymous-wide-tuples.js +34 -0
  67. package/dist/rules/no-barrel-export-star.d.ts +2 -0
  68. package/dist/rules/no-barrel-export-star.js +26 -0
  69. package/dist/rules/no-boolean-field-signals.d.ts +2 -0
  70. package/dist/rules/no-boolean-field-signals.js +279 -0
  71. package/dist/rules/no-builtin-throws.d.ts +6 -0
  72. package/dist/rules/no-builtin-throws.js +74 -0
  73. package/dist/rules/no-chained-type-assertions.d.ts +2 -0
  74. package/dist/rules/no-chained-type-assertions.js +54 -0
  75. package/dist/rules/no-conditional-empty-object-spread.d.ts +2 -0
  76. package/dist/rules/no-conditional-empty-object-spread.js +36 -0
  77. package/dist/rules/no-duplicated-literal-union.d.ts +6 -0
  78. package/dist/rules/no-duplicated-literal-union.js +62 -0
  79. package/dist/rules/no-exported-mutable-state.d.ts +7 -0
  80. package/dist/rules/no-exported-mutable-state.js +104 -0
  81. package/dist/rules/no-generic-export-names.d.ts +2 -0
  82. package/dist/rules/no-generic-export-names.js +141 -0
  83. package/dist/rules/no-impossible-branch-throw.d.ts +2 -0
  84. package/dist/rules/no-impossible-branch-throw.js +51 -0
  85. package/dist/rules/no-known-value-widening.d.ts +2 -0
  86. package/dist/rules/no-known-value-widening.js +176 -0
  87. package/dist/rules/no-module-mocking.d.ts +2 -0
  88. package/dist/rules/no-module-mocking.js +90 -0
  89. package/dist/rules/no-multiple-function-params.d.ts +2 -0
  90. package/dist/rules/no-multiple-function-params.js +155 -0
  91. package/dist/rules/no-nondeterministic-core.d.ts +6 -0
  92. package/dist/rules/no-nondeterministic-core.js +63 -0
  93. package/dist/rules/no-object-parameters.d.ts +2 -0
  94. package/dist/rules/no-object-parameters.js +95 -0
  95. package/dist/rules/no-optional-function-parameters.d.ts +7 -0
  96. package/dist/rules/no-optional-function-parameters.js +44 -0
  97. package/dist/rules/no-product-of-state-booleans.d.ts +2 -0
  98. package/dist/rules/no-product-of-state-booleans.js +79 -0
  99. package/dist/rules/no-redundant-derived-field.d.ts +6 -0
  100. package/dist/rules/no-redundant-derived-field.js +194 -0
  101. package/dist/rules/no-reflect-apply.d.ts +2 -0
  102. package/dist/rules/no-reflect-apply.js +29 -0
  103. package/dist/rules/no-reflect-get.d.ts +2 -0
  104. package/dist/rules/no-reflect-get.js +29 -0
  105. package/dist/rules/no-reinterpret-cast.d.ts +2 -0
  106. package/dist/rules/no-reinterpret-cast.js +68 -0
  107. package/dist/rules/no-runtime-typeof.d.ts +2 -0
  108. package/dist/rules/no-runtime-typeof.js +54 -0
  109. package/dist/rules/no-sentinel-comparison-union.d.ts +2 -0
  110. package/dist/rules/no-sentinel-comparison-union.js +139 -0
  111. package/dist/rules/no-shape-in-symbol-names.d.ts +2 -0
  112. package/dist/rules/no-shape-in-symbol-names.js +39 -0
  113. package/dist/rules/no-single-use-private-functions.d.ts +6 -0
  114. package/dist/rules/no-single-use-private-functions.js +295 -0
  115. package/dist/rules/no-stacked-jsdoc-blocks.d.ts +2 -0
  116. package/dist/rules/no-stacked-jsdoc-blocks.js +50 -0
  117. package/dist/rules/no-stray-inline-comments.d.ts +2 -0
  118. package/dist/rules/no-stray-inline-comments.js +74 -0
  119. package/dist/rules/no-swappable-primitive-params.d.ts +2 -0
  120. package/dist/rules/no-swappable-primitive-params.js +96 -0
  121. package/dist/rules/no-tag-ladder-assertions.d.ts +6 -0
  122. package/dist/rules/no-tag-ladder-assertions.js +63 -0
  123. package/dist/rules/no-transposed-field-reads.d.ts +8 -0
  124. package/dist/rules/no-transposed-field-reads.js +101 -0
  125. package/dist/rules/no-unit-return-validators.d.ts +2 -0
  126. package/dist/rules/no-unit-return-validators.js +64 -0
  127. package/dist/rules/no-unknown-parameters.d.ts +2 -0
  128. package/dist/rules/no-unknown-parameters.js +82 -0
  129. package/dist/rules/no-unknown-returns.d.ts +2 -0
  130. package/dist/rules/no-unknown-returns.js +86 -0
  131. package/dist/rules/no-unknown-type-aliases.d.ts +2 -0
  132. package/dist/rules/no-unknown-type-aliases.js +64 -0
  133. package/dist/rules/no-unsafe-dictionary-type.d.ts +2 -0
  134. package/dist/rules/no-unsafe-dictionary-type.js +116 -0
  135. package/dist/rules/no-vague-test-filenames.d.ts +2 -0
  136. package/dist/rules/no-vague-test-filenames.js +61 -0
  137. package/dist/rules/no-widen-then-assert.d.ts +2 -0
  138. package/dist/rules/no-widen-then-assert.js +268 -0
  139. package/dist/rules/prefer-payload-brand.d.ts +2 -0
  140. package/dist/rules/prefer-payload-brand.js +57 -0
  141. package/dist/rules/prefer-property-tests.d.ts +5 -0
  142. package/dist/rules/prefer-property-tests.js +39 -0
  143. package/dist/rules/require-canonical-stringify-for-identity.d.ts +8 -0
  144. package/dist/rules/require-canonical-stringify-for-identity.js +72 -0
  145. package/dist/rules/require-deprecated-tag-for-legacy-comments.d.ts +2 -0
  146. package/dist/rules/require-deprecated-tag-for-legacy-comments.js +34 -0
  147. package/dist/rules/require-exhaustive-tag-switch.d.ts +7 -0
  148. package/dist/rules/require-exhaustive-tag-switch.js +34 -0
  149. package/dist/rules/require-fc-block-predicate.d.ts +2 -0
  150. package/dist/rules/require-fc-block-predicate.js +37 -0
  151. package/dist/rules/require-jsdoc-on-exported.d.ts +2 -0
  152. package/dist/rules/require-jsdoc-on-exported.js +66 -0
  153. package/dist/rules/require-published-order.d.ts +2 -0
  154. package/dist/rules/require-published-order.js +102 -0
  155. package/dist/rules/require-safety-comment-for-type-assertion.d.ts +2 -0
  156. package/dist/rules/require-safety-comment-for-type-assertion.js +53 -0
  157. package/dist/rules/require-sort-comparator.d.ts +7 -0
  158. package/dist/rules/require-sort-comparator.js +34 -0
  159. package/dist/rules/test-utils.d.ts +35 -0
  160. package/dist/rules/test-utils.js +53 -0
  161. package/{src/shared/ancestors.ts → dist/shared/ancestors.d.ts} +1 -4
  162. package/dist/shared/ancestors.js +19 -0
  163. package/dist/shared/child-nodes.d.ts +12 -0
  164. package/dist/shared/child-nodes.js +26 -0
  165. package/dist/shared/dictionary-types.d.ts +55 -0
  166. package/dist/shared/dictionary-types.js +413 -0
  167. package/{src/shared/is-node.ts → dist/shared/is-node.d.ts} +2 -6
  168. package/dist/shared/is-node.js +10 -0
  169. package/dist/shared/lexical-type-parameters.d.ts +12 -0
  170. package/dist/shared/lexical-type-parameters.js +50 -0
  171. package/dist/shared/reflect-method.d.ts +15 -0
  172. package/dist/shared/reflect-method.js +32 -0
  173. package/{src/shared/rule-options.ts → dist/shared/rule-options.d.ts} +2 -7
  174. package/dist/shared/rule-options.js +12 -0
  175. package/{src/shared/structural.ts → dist/shared/structural.d.ts} +17 -44
  176. package/dist/shared/structural.js +40 -0
  177. package/{src/testing/index.ts → dist/testing/index.d.ts} +0 -1
  178. package/dist/testing/index.js +1 -0
  179. package/dist/testing/testable-rule.d.ts +38 -0
  180. package/dist/testing/testable-rule.js +70 -0
  181. package/package.json +7 -6
  182. package/src/effect/index.ts +0 -59
  183. package/src/effect/rules/guarded-op-must-return-effect.ts +0 -236
  184. package/src/effect/rules/guarded-op-must-return-option.ts +0 -97
  185. package/src/effect/rules/no-cascading-layer-provide.ts +0 -80
  186. package/src/effect/rules/no-decode-unknown-option.ts +0 -41
  187. package/src/effect/rules/no-direct-browser-storage.ts +0 -91
  188. package/src/effect/rules/no-direct-fetch.ts +0 -44
  189. package/src/effect/rules/no-manual-field-guards.ts +0 -144
  190. package/src/effect/rules/no-nested-layer-provide.ts +0 -51
  191. package/src/effect/rules/no-schema-class-modeling.ts +0 -59
  192. package/src/effect/rules/no-service-constructor-imports.ts +0 -50
  193. package/src/effect/rules/no-silent-error-swallow.ts +0 -99
  194. package/src/effect/rules/no-static-effect-service-forwarders.ts +0 -227
  195. package/src/effect/rules/no-try-catch.ts +0 -32
  196. package/src/effect/rules/no-unguarded-json-parse.ts +0 -211
  197. package/src/effect/rules/option-core-needs-effect-public.ts +0 -81
  198. package/src/effect/rules/prefer-die-for-precondition-defects.ts +0 -118
  199. package/src/effect/rules/prefer-effect-gen-for-guard-ladders.ts +0 -76
  200. package/src/effect/rules/prefer-effect-match.ts +0 -78
  201. package/src/effect/rules/prefer-effect-predicate-over-boolean-function.ts +0 -79
  202. package/src/effect/rules/prefer-named-guard-predicate.ts +0 -105
  203. package/src/effect/rules/prefer-option-pipeline.ts +0 -95
  204. package/src/effect/rules/prefer-ordering-match.ts +0 -152
  205. package/src/effect/rules/prefer-tagged-enum.ts +0 -68
  206. package/src/effect/rules/require-schema-type-derivation.ts +0 -83
  207. package/src/index.ts +0 -106
  208. package/src/meta/rules/no-disable-directives.ts +0 -38
  209. package/src/meta/rules/no-manual-ancestor-walks.ts +0 -27
  210. package/src/meta/rules/prefer-before-file-scope.ts +0 -57
  211. package/src/meta/rules/require-create-once.ts +0 -51
  212. package/src/meta/rules/require-rule-tester.ts +0 -57
  213. package/src/rules/no-anonymous-wide-tuples.ts +0 -38
  214. package/src/rules/no-barrel-export-star.ts +0 -30
  215. package/src/rules/no-boolean-field-signals.ts +0 -305
  216. package/src/rules/no-builtin-throws.ts +0 -83
  217. package/src/rules/no-chained-type-assertions.ts +0 -65
  218. package/src/rules/no-conditional-empty-object-spread.ts +0 -42
  219. package/src/rules/no-duplicated-literal-union.ts +0 -66
  220. package/src/rules/no-exported-mutable-state.ts +0 -111
  221. package/src/rules/no-generic-export-names.ts +0 -149
  222. package/src/rules/no-impossible-branch-throw.ts +0 -55
  223. package/src/rules/no-known-value-widening.ts +0 -225
  224. package/src/rules/no-module-mocking.ts +0 -95
  225. package/src/rules/no-multiple-function-params.ts +0 -192
  226. package/src/rules/no-nondeterministic-core.ts +0 -73
  227. package/src/rules/no-object-parameters.ts +0 -127
  228. package/src/rules/no-optional-function-parameters.ts +0 -49
  229. package/src/rules/no-product-of-state-booleans.ts +0 -80
  230. package/src/rules/no-redundant-derived-field.ts +0 -192
  231. package/src/rules/no-reflect-apply.ts +0 -32
  232. package/src/rules/no-reflect-get.ts +0 -32
  233. package/src/rules/no-reinterpret-cast.ts +0 -78
  234. package/src/rules/no-runtime-typeof.ts +0 -59
  235. package/src/rules/no-sentinel-comparison-union.ts +0 -148
  236. package/src/rules/no-shape-in-symbol-names.ts +0 -45
  237. package/src/rules/no-single-use-private-functions.ts +0 -329
  238. package/src/rules/no-stacked-jsdoc-blocks.ts +0 -65
  239. package/src/rules/no-stray-inline-comments.ts +0 -79
  240. package/src/rules/no-swappable-primitive-params.ts +0 -109
  241. package/src/rules/no-tag-ladder-assertions.ts +0 -71
  242. package/src/rules/no-transposed-field-reads.ts +0 -135
  243. package/src/rules/no-unit-return-validators.ts +0 -65
  244. package/src/rules/no-unknown-parameters.ts +0 -97
  245. package/src/rules/no-unknown-returns.ts +0 -120
  246. package/src/rules/no-unknown-type-aliases.ts +0 -70
  247. package/src/rules/no-unsafe-dictionary-type.ts +0 -132
  248. package/src/rules/no-vague-test-filenames.ts +0 -67
  249. package/src/rules/no-widen-then-assert.ts +0 -345
  250. package/src/rules/prefer-payload-brand.ts +0 -67
  251. package/src/rules/prefer-property-tests.ts +0 -43
  252. package/src/rules/require-canonical-stringify-for-identity.ts +0 -80
  253. package/src/rules/require-deprecated-tag-for-legacy-comments.ts +0 -45
  254. package/src/rules/require-exhaustive-tag-switch.ts +0 -42
  255. package/src/rules/require-fc-block-predicate.ts +0 -42
  256. package/src/rules/require-jsdoc-on-exported.ts +0 -74
  257. package/src/rules/require-published-order.ts +0 -109
  258. package/src/rules/require-safety-comment-for-type-assertion.ts +0 -61
  259. package/src/rules/require-sort-comparator.ts +0 -41
  260. package/src/rules/test-utils.ts +0 -68
  261. package/src/shared/child-nodes.ts +0 -27
  262. package/src/shared/dictionary-types.ts +0 -524
  263. package/src/shared/lexical-type-parameters.ts +0 -62
  264. package/src/shared/reflect-method.ts +0 -41
  265. package/src/testing/testable-rule.test.ts +0 -68
  266. package/src/testing/testable-rule.ts +0 -86
@@ -0,0 +1,74 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { firstOptionRecord } from "../shared/rule-options.js";
3
+ import { isRecordObject, isString } from "../shared/structural.js";
4
+ const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
5
+ /** Generic built-in errors: untyped, prose-only, and invisible to tag-based handling. */
6
+ const BUILTIN_ERRORS = new Set([
7
+ "Error",
8
+ "EvalError",
9
+ "RangeError",
10
+ "ReferenceError",
11
+ "SyntaxError",
12
+ "TypeError",
13
+ "URIError",
14
+ "AggregateError",
15
+ ]);
16
+ /**
17
+ * Unwrap parenthesized expressions to the underlying expression.
18
+ *
19
+ * @param {ESTree.Expression} expression - The expression to unwrap.
20
+ * @returns {ESTree.Expression} The first non-parenthesized inner expression.
21
+ */
22
+ function unwrapParentheses(expression) {
23
+ let current = expression;
24
+ while (current.type === "ParenthesizedExpression")
25
+ current = current.expression;
26
+ return current;
27
+ }
28
+ /**
29
+ * Flag throwing generic built-in errors at call sites that should instead throw
30
+ * a project-defined tagged error carrying its evidence structurally (e.g.
31
+ * Data.TaggedError with operation/value/domain fields plus a rendered message).
32
+ */
33
+ export const noBuiltinThrowsRule = defineRule({
34
+ meta: {
35
+ type: "problem",
36
+ docs: {
37
+ description: "Disallow throwing built-in Error constructors; require project-defined tagged error classes so defects carry structured evidence and can be matched by tag.",
38
+ },
39
+ messages: {
40
+ noBuiltinThrows: "Throwing the built-in `{{builtin}}` loses structure: consumers get prose only. Throw a project-defined tagged error (e.g. Data.TaggedError) whose fields carry the operation, offending value, and domain, and render this context as its message.",
41
+ },
42
+ schema: [
43
+ {
44
+ type: "object",
45
+ properties: {
46
+ allow: { type: "array", items: { type: "string" } },
47
+ },
48
+ additionalProperties: false,
49
+ },
50
+ ],
51
+ defaultOptions: [{ allow: [] }],
52
+ },
53
+ createOnce(context) {
54
+ const option = firstOptionRecord(context.options);
55
+ const allowed = new Set(Array.isArray(option.allow) ? option.allow.filter(isString) : []);
56
+ return {
57
+ before() {
58
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
59
+ return false;
60
+ },
61
+ ThrowStatement(node) {
62
+ const argument = node.argument === null || node.argument === undefined ? undefined : unwrapParentheses(node.argument);
63
+ if (argument?.type !== "NewExpression")
64
+ return;
65
+ if (argument.callee.type !== "Identifier")
66
+ return;
67
+ const builtin = argument.callee.name;
68
+ if (!BUILTIN_ERRORS.has(builtin) || allowed.has(builtin))
69
+ return;
70
+ context.report({ node, messageId: "noBuiltinThrows", data: { builtin } });
71
+ },
72
+ };
73
+ },
74
+ });
@@ -0,0 +1,2 @@
1
+ /** Disallow nested TypeScript type assertions, while permitting chains made only of const assertions. */
2
+ export declare const noChainedTypeAssertionsRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,54 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { ancestorsOf } from "../shared/ancestors.js";
3
+ /** Disallow nested TypeScript type assertions, while permitting chains made only of const assertions. */
4
+ export const noChainedTypeAssertionsRule = defineRule({
5
+ meta: {
6
+ type: "problem",
7
+ docs: {
8
+ description: "Disallow chained TypeScript as and angle-bracket assertions, including parenthesized chains.",
9
+ },
10
+ messages: {
11
+ chained: "This assertion chain discards type evidence. Keep the original precise type, or parse untrusted input at its boundary before narrowing it.",
12
+ },
13
+ },
14
+ createOnce(context) {
15
+ const checkTypeAssertion = (node) => {
16
+ const ancestors = ancestorsOf(context.sourceCode, node);
17
+ let current = node;
18
+ let index = ancestors.length - 1;
19
+ while (index >= 0) {
20
+ const parent = ancestors[index];
21
+ if (parent.type !== "ParenthesizedExpression" || parent.expression !== current)
22
+ break;
23
+ current = parent;
24
+ index -= 1;
25
+ }
26
+ const outermost = ancestors[index];
27
+ if (outermost !== undefined &&
28
+ (outermost.type === "TSAsExpression" || outermost.type === "TSTypeAssertion") &&
29
+ outermost.expression === current)
30
+ return;
31
+ let assertionCount = 0;
32
+ let hasNonConstAssertion = false;
33
+ current = node;
34
+ while (current.type === "TSAsExpression" || current.type === "TSTypeAssertion") {
35
+ assertionCount += 1;
36
+ const { typeAnnotation } = current;
37
+ hasNonConstAssertion ||= !(typeAnnotation.type === "TSTypeReference" &&
38
+ typeAnnotation.typeName.type === "Identifier" &&
39
+ typeAnnotation.typeName.name === "const");
40
+ let next = current.expression;
41
+ while (next.type === "ParenthesizedExpression")
42
+ next = next.expression;
43
+ current = next;
44
+ }
45
+ if (assertionCount > 1 && hasNonConstAssertion) {
46
+ context.report({ node, messageId: "chained" });
47
+ }
48
+ };
49
+ return {
50
+ TSAsExpression: checkTypeAssertion,
51
+ TSTypeAssertion: checkTypeAssertion,
52
+ };
53
+ },
54
+ });
@@ -0,0 +1,2 @@
1
+ /** Ban conditional empty-object spreads without changing their omission semantics. */
2
+ export declare const noConditionalEmptyObjectSpreadRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,36 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { ancestorsOf } from "../shared/ancestors.js";
3
+ function isEmptyObjectExpression(node) {
4
+ return node.type === "ObjectExpression" && node.properties.length === 0;
5
+ }
6
+ /** Ban conditional empty-object spreads without changing their omission semantics. */
7
+ export const noConditionalEmptyObjectSpreadRule = defineRule({
8
+ meta: {
9
+ type: "suggestion",
10
+ docs: {
11
+ description: "Disallow object spreads that conditionally spread an empty object to omit fields.",
12
+ },
13
+ messages: {
14
+ avoid: "This conditional spread hides property omission behind an empty object. Build the object in separate statements and add the property only when present.",
15
+ },
16
+ },
17
+ createOnce(context) {
18
+ return {
19
+ SpreadElement(node) {
20
+ const parent = ancestorsOf(context.sourceCode, node).at(-1);
21
+ if (parent?.type !== "ObjectExpression")
22
+ return;
23
+ let conditional = node.argument;
24
+ while (conditional.type === "ParenthesizedExpression") {
25
+ conditional = conditional.expression;
26
+ }
27
+ const emptyObjectOmission = conditional.type === "ConditionalExpression" &&
28
+ (isEmptyObjectExpression(conditional.consequent) ||
29
+ isEmptyObjectExpression(conditional.alternate));
30
+ if (emptyObjectOmission) {
31
+ context.report({ node, messageId: "avoid" });
32
+ }
33
+ },
34
+ };
35
+ },
36
+ });
@@ -0,0 +1,6 @@
1
+ /**
2
+ * One fact, one place: a set of variants declared twice drifts the moment
3
+ * someone adds a member to one copy. Declare each variant set once and
4
+ * derive every use from it.
5
+ */
6
+ export declare const noDuplicatedLiteralUnionRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,62 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { isRecordObject, isString } from "../shared/structural.js";
3
+ /** Sorted string-literal members of a union annotation, or null if it isn't one.
4
+ *
5
+ * @param {ESTree.TSType} annotation - The annotation to inspect.
6
+ * @returns {string[] | null} Sorted literal members, or null when not a literal union.
7
+ */
8
+ function literalUnionKey(annotation) {
9
+ const types = annotation.type === "TSUnionType" ? annotation.types : [annotation];
10
+ const literals = [];
11
+ for (const member of types) {
12
+ if (member.type !== "TSLiteralType" || member.literal.type !== "Literal")
13
+ return null;
14
+ if (!isString(member.literal.value))
15
+ return null;
16
+ literals.push(member.literal.value);
17
+ }
18
+ return [...literals].sort((a, b) => a.localeCompare(b));
19
+ }
20
+ /**
21
+ * One fact, one place: a set of variants declared twice drifts the moment
22
+ * someone adds a member to one copy. Declare each variant set once and
23
+ * derive every use from it.
24
+ */
25
+ export const noDuplicatedLiteralUnionRule = defineRule({
26
+ meta: {
27
+ type: "problem",
28
+ docs: {
29
+ description: "Disallow string-literal unions whose exact member set is declared by more than one alias in a file; declare the variant set once.",
30
+ },
31
+ messages: {
32
+ duplicateUnion: "`{{second}}` declares exactly the variant set of `{{first}}`: two sources of truth that will drift when a member is added to one. Export `{{first}}` and reuse it (or rename if coincidental).",
33
+ },
34
+ },
35
+ createOnce(context) {
36
+ const seen = new Map();
37
+ const duplicates = new Map();
38
+ return {
39
+ TSTypeAliasDeclaration(node) {
40
+ const key = literalUnionKey(node.typeAnnotation);
41
+ if (key === null)
42
+ return;
43
+ const joined = key.join("\u0000");
44
+ const first = seen.get(joined);
45
+ if (first === undefined) {
46
+ seen.set(joined, node.id.name);
47
+ return;
48
+ }
49
+ duplicates.set(`${joined}\u0000${node.id.name}`, { node, name: node.id.name, first });
50
+ },
51
+ "Program:exit"() {
52
+ for (const duplicate of duplicates.values()) {
53
+ context.report({
54
+ node: duplicate.node,
55
+ messageId: "duplicateUnion",
56
+ data: { second: duplicate.name, first: duplicate.first },
57
+ });
58
+ }
59
+ },
60
+ };
61
+ },
62
+ });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * No blessed surface area: a value that escapes module scope mutably lets
3
+ * every invariant its constructor established be broken from outside. Module
4
+ * state must be immutable bindings over immutable structures; anything that
5
+ * varies belongs in parameters, state objects or Effect services.
6
+ */
7
+ export declare const noExportedMutableStateRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,104 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ const MUTATING_METHODS = new Set([
3
+ "add",
4
+ "clear",
5
+ "copyWithin",
6
+ "defineProperty",
7
+ "delete",
8
+ "fill",
9
+ "pop",
10
+ "push",
11
+ "reverse",
12
+ "set",
13
+ "shift",
14
+ "sort",
15
+ "splice",
16
+ "unshift",
17
+ ]);
18
+ /** Root identifier of an assignment target / call receiver, if statically simple.
19
+ *
20
+ * @param {ESTree.Node} node - The target or receiver expression.
21
+ * @returns {string | null} The leftmost identifier's name, or null when dynamic.
22
+ */
23
+ function rootIdentifier(node) {
24
+ if (node.type === "Identifier")
25
+ return node.name;
26
+ if (node.type === "MemberExpression" && !node.computed)
27
+ return rootIdentifier(node.object);
28
+ if (node.type === "ParenthesizedExpression")
29
+ return rootIdentifier(node.expression);
30
+ return null;
31
+ }
32
+ /**
33
+ * No blessed surface area: a value that escapes module scope mutably lets
34
+ * every invariant its constructor established be broken from outside. Module
35
+ * state must be immutable bindings over immutable structures; anything that
36
+ * varies belongs in parameters, state objects or Effect services.
37
+ */
38
+ export const noExportedMutableStateRule = defineRule({
39
+ meta: {
40
+ type: "problem",
41
+ docs: {
42
+ description: "Disallow exported let/var bindings and mutation of module-scope values; keep module state immutable so construction-time invariants can't be broken.",
43
+ },
44
+ messages: {
45
+ exportedBinding: "`{{name}}` is exported as a mutable binding, so importers can change it under every other consumer and break whatever invariants it carried. Export a `const`.",
46
+ moduleMutation: "`{{name}}` lives at module scope, so this mutation is invisible shared state across every caller: the blessed-surface-area problem. Make it local, or hold it in explicit state/service passed by parameter.",
47
+ },
48
+ },
49
+ createOnce(context) {
50
+ let topLevelNames = new Set();
51
+ function checkTarget(node) {
52
+ const name = rootIdentifier(node);
53
+ if (name === null || !topLevelNames.has(name))
54
+ return;
55
+ context.report({ node, messageId: "moduleMutation", data: { name } });
56
+ }
57
+ function isMutatingCall(node) {
58
+ if (node.type !== "CallExpression" || node.callee.type !== "MemberExpression")
59
+ return false;
60
+ const property = node.callee.property;
61
+ return property.type === "Identifier" && MUTATING_METHODS.has(property.name);
62
+ }
63
+ return {
64
+ Program(node) {
65
+ topLevelNames = new Set(node.body.flatMap((statement) => statement.type === "VariableDeclaration"
66
+ ? statement.declarations.flatMap((declarator) => declarator.id.type === "Identifier" ? [declarator.id.name] : [])
67
+ : (statement.type === "FunctionDeclaration" ||
68
+ statement.type === "ClassDeclaration") &&
69
+ statement.id !== null
70
+ ? [statement.id.name]
71
+ : []));
72
+ },
73
+ ExportNamedDeclaration(node) {
74
+ const declaration = node.declaration;
75
+ if (declaration === null || declaration.type !== "VariableDeclaration")
76
+ return;
77
+ if (declaration.kind === "const")
78
+ return;
79
+ for (const declarator of declaration.declarations) {
80
+ if (declarator.id.type !== "Identifier")
81
+ continue;
82
+ context.report({
83
+ node,
84
+ messageId: "exportedBinding",
85
+ data: { name: declarator.id.name },
86
+ });
87
+ }
88
+ },
89
+ AssignmentExpression(node) {
90
+ checkTarget(node.left);
91
+ },
92
+ UpdateExpression(node) {
93
+ checkTarget(node.argument);
94
+ },
95
+ CallExpression(node) {
96
+ if (!isMutatingCall(node))
97
+ return;
98
+ if (node.callee.type !== "MemberExpression")
99
+ return;
100
+ checkTarget(node.callee.object);
101
+ },
102
+ };
103
+ },
104
+ });
@@ -0,0 +1,2 @@
1
+ /** Exported symbols must resolve by grep in one hop; qualification by the module counts. */
2
+ export declare const noGenericExportNamesRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,141 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ /** Single words whose bare grep hits span unrelated subsystems (the `create` problem). */
3
+ const GENERIC_TERMS = new Set([
4
+ "create",
5
+ "init",
6
+ "initialize",
7
+ "get",
8
+ "set",
9
+ "validate",
10
+ "process",
11
+ "handle",
12
+ "run",
13
+ "make",
14
+ "build",
15
+ "execute",
16
+ "update",
17
+ "parse",
18
+ "format",
19
+ "convert",
20
+ "transform",
21
+ "start",
22
+ "stop",
23
+ "load",
24
+ "save",
25
+ "check",
26
+ "do",
27
+ "main",
28
+ "util",
29
+ "utils",
30
+ "helper",
31
+ "helpers",
32
+ "misc",
33
+ "common",
34
+ "data",
35
+ "manager",
36
+ "service",
37
+ "wrapper",
38
+ "temp",
39
+ "tmp",
40
+ ]);
41
+ const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
42
+ /** Split an identifier into its words across camelCase and separators.
43
+ *
44
+ * @param {string} name - Identifier or filename stem to split.
45
+ * @returns {Array<string>} Non-empty words of the name.
46
+ */
47
+ function splitWords(name) {
48
+ return name
49
+ .replace(/([a-z0-9])([A-Z])/gu, "$1 $2")
50
+ .split(/[^A-Za-z0-9]+/u)
51
+ .filter((word) => word.length > 0);
52
+ }
53
+ /** Module segment acting as the qualification prefix at qualified call sites.
54
+ *
55
+ * @param {string} filename - Lint-context filename of the module.
56
+ * @returns {Array<string>} Words of the module's qualifying segment.
57
+ */
58
+ function qualifierWords(filename) {
59
+ const segments = filename.replaceAll("\\", "/").split("/");
60
+ const base = segments[segments.length - 1] ?? "";
61
+ let stem = base.replace(/\.[cm]?[jt]sx?$/u, "");
62
+ if (stem === "index" || stem === "mod") {
63
+ stem = segments[segments.length - 2] ?? stem;
64
+ }
65
+ return splitWords(stem);
66
+ }
67
+ /** True when every word of the name is generic, so qualification adds nothing either.
68
+ *
69
+ * @param {Array<string>} words - Words of the exported symbol's name.
70
+ * @returns {boolean} True when no word carries domain meaning.
71
+ */
72
+ function isAllGeneric(words) {
73
+ return (words.length > 0 &&
74
+ words.every((word) => GENERIC_TERMS.has(word.toLowerCase())));
75
+ }
76
+ /** Exported symbols must resolve by grep in one hop; qualification by the module counts. */
77
+ export const noGenericExportNamesRule = defineRule({
78
+ meta: {
79
+ type: "problem",
80
+ docs: {
81
+ description: "Disallow exported symbol names that stay generic even after module qualification (e.g. utils.ts exporting `create`); a distinctive qualified token such as `Currency.make` greps to exactly the right definition and call sites.",
82
+ },
83
+ messages: {
84
+ genericExportName: "Exported symbol `{{qualified}}` stays generic, so searching it lands on hundreds of unrelated hits. Add a domain word to the name (e.g. `create` -> `createStripeClient`) or move it into a domain-named module so callers read `{{domain}}.{{name}}`.",
85
+ },
86
+ },
87
+ createOnce(context) {
88
+ let moduleWords = [];
89
+ let moduleSuppliesDomain = false;
90
+ return {
91
+ before() {
92
+ const filePath = context.filename.replaceAll("\\", "/");
93
+ if (TEST_FILE.test(filePath))
94
+ return false;
95
+ moduleWords = qualifierWords(filePath);
96
+ moduleSuppliesDomain = moduleWords.some((word) => !GENERIC_TERMS.has(word.toLowerCase()));
97
+ },
98
+ Program(node) {
99
+ for (const statement of node.body) {
100
+ const declaration = statement.type === "ExportNamedDeclaration" ||
101
+ statement.type === "ExportDefaultDeclaration"
102
+ ? (statement.declaration ?? null)
103
+ : statement;
104
+ if (declaration === null)
105
+ continue;
106
+ const identifiers = [];
107
+ if (declaration.type === "FunctionDeclaration" ||
108
+ declaration.type === "ClassDeclaration" ||
109
+ declaration.type === "TSInterfaceDeclaration" ||
110
+ declaration.type === "TSTypeAliasDeclaration" ||
111
+ declaration.type === "TSEnumDeclaration") {
112
+ if (declaration.id !== null)
113
+ identifiers.push(declaration.id);
114
+ }
115
+ else if (declaration.type === "VariableDeclaration") {
116
+ for (const declarator of declaration.declarations) {
117
+ if (declarator.id.type === "Identifier")
118
+ identifiers.push(declarator.id);
119
+ }
120
+ }
121
+ for (const id of identifiers) {
122
+ const nameWords = splitWords(id.name);
123
+ if (!isAllGeneric(nameWords))
124
+ continue;
125
+ if (moduleSuppliesDomain)
126
+ continue;
127
+ context.report({
128
+ node: id,
129
+ messageId: "genericExportName",
130
+ data: {
131
+ name: id.name,
132
+ qualified: moduleWords.concat(nameWords).join("."),
133
+ domain: moduleWords.join(""),
134
+ },
135
+ });
136
+ }
137
+ }
138
+ },
139
+ };
140
+ },
141
+ });
@@ -0,0 +1,2 @@
1
+ /** Reject "should never happen" throws; encode the case out of the type instead. */
2
+ export declare const noImpossibleBranchThrowRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,51 @@
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
+ const IMPOSSIBLE_MESSAGE = /(?:never\s+happen|impossible|unreachable|invariant|cannot\s+happen|can'?t\s+happen|unexpected\s+state|not\s+possible)/iu;
5
+ /** Extract the prose message of a thrown error literal or constructor.
6
+ *
7
+ * @param {ESTree.ThrowStatement} node - The throw statement to inspect.
8
+ * @returns {string | null} The thrown message, or null when not a string literal.
9
+ */
10
+ function throwMessage(node) {
11
+ const argument = node.argument;
12
+ if (argument === null || argument === undefined)
13
+ return null;
14
+ if (argument.type === "Literal" && isString(argument.value))
15
+ return argument.value;
16
+ if (argument.type === "NewExpression") {
17
+ const first = argument.arguments[0];
18
+ if (first !== undefined && first.type === "Literal" && isString(first.value)) {
19
+ return first.value;
20
+ }
21
+ }
22
+ return null;
23
+ }
24
+ /** Reject "should never happen" throws; encode the case out of the type instead. */
25
+ export const noImpossibleBranchThrowRule = defineRule({
26
+ meta: {
27
+ type: "problem",
28
+ docs: {
29
+ description: "Disallow hand-asserted impossible branches (throws about never-happens/invariants); encode the case out of the type so the compiler rejects it.",
30
+ },
31
+ messages: {
32
+ impossibleThrow: "This branch is asserted impossible by hand (\"{{message}}\"). If it truly cannot occur, parse/encode it out of the type (Option, parsed/refined type) so the compiler rejects it; otherwise return a structured failure.",
33
+ },
34
+ },
35
+ createOnce(context) {
36
+ return {
37
+ before() {
38
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
39
+ return false;
40
+ },
41
+ ThrowStatement(node) {
42
+ const message = throwMessage(node);
43
+ if (message === null)
44
+ return;
45
+ if (!IMPOSSIBLE_MESSAGE.test(message))
46
+ return;
47
+ context.report({ node, messageId: "impossibleThrow", data: { message } });
48
+ },
49
+ };
50
+ },
51
+ });
@@ -0,0 +1,2 @@
1
+ /** Detect sound syntactic cases where a known value is explicitly widened and loses evidence. */
2
+ export declare const noKnownValueWideningRule: import("@oxlint/plugins").Rule;