@autotelic/plumb 0.6.1 → 0.6.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 (209) hide show
  1. package/package.json +18 -18
  2. package/dist/src/configs/recommended-rules.d.ts +0 -20
  3. package/dist/src/configs/recommended-rules.js +0 -22
  4. package/dist/src/effect/index.d.ts +0 -3
  5. package/dist/src/effect/index.js +0 -60
  6. package/dist/src/effect/rules/guarded-op-must-return-effect.d.ts +0 -6
  7. package/dist/src/effect/rules/guarded-op-must-return-effect.js +0 -235
  8. package/dist/src/effect/rules/guarded-op-must-return-option.d.ts +0 -2
  9. package/dist/src/effect/rules/guarded-op-must-return-option.js +0 -88
  10. package/dist/src/effect/rules/no-cascading-layer-provide.d.ts +0 -6
  11. package/dist/src/effect/rules/no-cascading-layer-provide.js +0 -73
  12. package/dist/src/effect/rules/no-decode-unknown-option.d.ts +0 -7
  13. package/dist/src/effect/rules/no-decode-unknown-option.js +0 -34
  14. package/dist/src/effect/rules/no-direct-browser-storage.d.ts +0 -2
  15. package/dist/src/effect/rules/no-direct-browser-storage.js +0 -88
  16. package/dist/src/effect/rules/no-direct-fetch.d.ts +0 -2
  17. package/dist/src/effect/rules/no-direct-fetch.js +0 -37
  18. package/dist/src/effect/rules/no-manual-field-guards.d.ts +0 -6
  19. package/dist/src/effect/rules/no-manual-field-guards.js +0 -129
  20. package/dist/src/effect/rules/no-nested-layer-provide.d.ts +0 -2
  21. package/dist/src/effect/rules/no-nested-layer-provide.js +0 -50
  22. package/dist/src/effect/rules/no-nullish-default-on-partial-input.d.ts +0 -13
  23. package/dist/src/effect/rules/no-nullish-default-on-partial-input.js +0 -109
  24. package/dist/src/effect/rules/no-raw-error-forwarding.d.ts +0 -12
  25. package/dist/src/effect/rules/no-raw-error-forwarding.js +0 -103
  26. package/dist/src/effect/rules/no-schema-class-modeling.d.ts +0 -2
  27. package/dist/src/effect/rules/no-schema-class-modeling.js +0 -52
  28. package/dist/src/effect/rules/no-service-constructor-imports.d.ts +0 -2
  29. package/dist/src/effect/rules/no-service-constructor-imports.js +0 -42
  30. package/dist/src/effect/rules/no-silent-error-swallow.d.ts +0 -2
  31. package/dist/src/effect/rules/no-silent-error-swallow.js +0 -95
  32. package/dist/src/effect/rules/no-static-effect-service-forwarders.d.ts +0 -6
  33. package/dist/src/effect/rules/no-static-effect-service-forwarders.js +0 -222
  34. package/dist/src/effect/rules/no-try-catch.d.ts +0 -2
  35. package/dist/src/effect/rules/no-try-catch.js +0 -30
  36. package/dist/src/effect/rules/no-unguarded-json-parse.d.ts +0 -5
  37. package/dist/src/effect/rules/no-unguarded-json-parse.js +0 -200
  38. package/dist/src/effect/rules/option-core-needs-effect-public.d.ts +0 -5
  39. package/dist/src/effect/rules/option-core-needs-effect-public.js +0 -76
  40. package/dist/src/effect/rules/prefer-die-for-precondition-defects.d.ts +0 -5
  41. package/dist/src/effect/rules/prefer-die-for-precondition-defects.js +0 -112
  42. package/dist/src/effect/rules/prefer-effect-gen-for-guard-ladders.d.ts +0 -5
  43. package/dist/src/effect/rules/prefer-effect-gen-for-guard-ladders.js +0 -72
  44. package/dist/src/effect/rules/prefer-effect-match.d.ts +0 -2
  45. package/dist/src/effect/rules/prefer-effect-match.js +0 -74
  46. package/dist/src/effect/rules/prefer-effect-predicate-over-boolean-function.d.ts +0 -2
  47. package/dist/src/effect/rules/prefer-effect-predicate-over-boolean-function.js +0 -75
  48. package/dist/src/effect/rules/prefer-named-guard-predicate.d.ts +0 -2
  49. package/dist/src/effect/rules/prefer-named-guard-predicate.js +0 -93
  50. package/dist/src/effect/rules/prefer-option-pipeline.d.ts +0 -2
  51. package/dist/src/effect/rules/prefer-option-pipeline.js +0 -87
  52. package/dist/src/effect/rules/prefer-ordering-match.d.ts +0 -2
  53. package/dist/src/effect/rules/prefer-ordering-match.js +0 -135
  54. package/dist/src/effect/rules/prefer-tagged-enum.d.ts +0 -2
  55. package/dist/src/effect/rules/prefer-tagged-enum.js +0 -66
  56. package/dist/src/effect/rules/require-schema-type-derivation.d.ts +0 -7
  57. package/dist/src/effect/rules/require-schema-type-derivation.js +0 -80
  58. package/dist/src/index.d.ts +0 -3
  59. package/dist/src/index.js +0 -106
  60. package/dist/src/meta/index.d.ts +0 -7
  61. package/dist/src/meta/index.js +0 -22
  62. package/dist/src/meta/rules/no-disable-directives.d.ts +0 -6
  63. package/dist/src/meta/rules/no-disable-directives.js +0 -35
  64. package/dist/src/meta/rules/no-manual-ancestor-walks.d.ts +0 -2
  65. package/dist/src/meta/rules/no-manual-ancestor-walks.js +0 -26
  66. package/dist/src/meta/rules/prefer-before-file-scope.d.ts +0 -2
  67. package/dist/src/meta/rules/prefer-before-file-scope.js +0 -57
  68. package/dist/src/meta/rules/require-create-once.d.ts +0 -2
  69. package/dist/src/meta/rules/require-create-once.js +0 -51
  70. package/dist/src/meta/rules/require-rule-tester.d.ts +0 -2
  71. package/dist/src/meta/rules/require-rule-tester.js +0 -50
  72. package/dist/src/react/index.d.ts +0 -3
  73. package/dist/src/react/index.js +0 -16
  74. package/dist/src/react/role.d.ts +0 -23
  75. package/dist/src/react/role.js +0 -30
  76. package/dist/src/react/rules/require-dot-notation-exports.d.ts +0 -27
  77. package/dist/src/react/rules/require-dot-notation-exports.js +0 -144
  78. package/dist/src/react/rules/require-guarded-context-hook.d.ts +0 -19
  79. package/dist/src/react/rules/require-guarded-context-hook.js +0 -167
  80. package/dist/src/react/rules/require-tripartite-context.d.ts +0 -17
  81. package/dist/src/react/rules/require-tripartite-context.js +0 -160
  82. package/dist/src/react/rules/use-encapsulation.d.ts +0 -22
  83. package/dist/src/react/rules/use-encapsulation.js +0 -97
  84. package/dist/src/rules/no-anonymous-wide-tuples.d.ts +0 -7
  85. package/dist/src/rules/no-anonymous-wide-tuples.js +0 -34
  86. package/dist/src/rules/no-barrel-export-star.d.ts +0 -2
  87. package/dist/src/rules/no-barrel-export-star.js +0 -26
  88. package/dist/src/rules/no-boolean-field-signals.d.ts +0 -2
  89. package/dist/src/rules/no-boolean-field-signals.js +0 -279
  90. package/dist/src/rules/no-builtin-throws.d.ts +0 -6
  91. package/dist/src/rules/no-builtin-throws.js +0 -74
  92. package/dist/src/rules/no-chained-type-assertions.d.ts +0 -2
  93. package/dist/src/rules/no-chained-type-assertions.js +0 -54
  94. package/dist/src/rules/no-conditional-empty-object-spread.d.ts +0 -2
  95. package/dist/src/rules/no-conditional-empty-object-spread.js +0 -36
  96. package/dist/src/rules/no-duplicated-literal-union.d.ts +0 -6
  97. package/dist/src/rules/no-duplicated-literal-union.js +0 -66
  98. package/dist/src/rules/no-exported-mutable-state.d.ts +0 -7
  99. package/dist/src/rules/no-exported-mutable-state.js +0 -104
  100. package/dist/src/rules/no-generic-export-names.d.ts +0 -2
  101. package/dist/src/rules/no-generic-export-names.js +0 -141
  102. package/dist/src/rules/no-impossible-branch-throw.d.ts +0 -2
  103. package/dist/src/rules/no-impossible-branch-throw.js +0 -51
  104. package/dist/src/rules/no-known-value-widening.d.ts +0 -2
  105. package/dist/src/rules/no-known-value-widening.js +0 -176
  106. package/dist/src/rules/no-module-mocking.d.ts +0 -2
  107. package/dist/src/rules/no-module-mocking.js +0 -90
  108. package/dist/src/rules/no-multiple-function-params.d.ts +0 -2
  109. package/dist/src/rules/no-multiple-function-params.js +0 -155
  110. package/dist/src/rules/no-mutable-environment-capture.d.ts +0 -7
  111. package/dist/src/rules/no-mutable-environment-capture.js +0 -134
  112. package/dist/src/rules/no-nondeterministic-core.d.ts +0 -6
  113. package/dist/src/rules/no-nondeterministic-core.js +0 -63
  114. package/dist/src/rules/no-object-parameters.d.ts +0 -2
  115. package/dist/src/rules/no-object-parameters.js +0 -95
  116. package/dist/src/rules/no-optional-function-parameters.d.ts +0 -7
  117. package/dist/src/rules/no-optional-function-parameters.js +0 -44
  118. package/dist/src/rules/no-product-of-state-booleans.d.ts +0 -2
  119. package/dist/src/rules/no-product-of-state-booleans.js +0 -79
  120. package/dist/src/rules/no-redundant-derived-field.d.ts +0 -6
  121. package/dist/src/rules/no-redundant-derived-field.js +0 -194
  122. package/dist/src/rules/no-reflect-apply.d.ts +0 -2
  123. package/dist/src/rules/no-reflect-apply.js +0 -29
  124. package/dist/src/rules/no-reflect-get.d.ts +0 -2
  125. package/dist/src/rules/no-reflect-get.js +0 -29
  126. package/dist/src/rules/no-reinterpret-cast.d.ts +0 -2
  127. package/dist/src/rules/no-reinterpret-cast.js +0 -68
  128. package/dist/src/rules/no-runtime-typeof.d.ts +0 -2
  129. package/dist/src/rules/no-runtime-typeof.js +0 -54
  130. package/dist/src/rules/no-sentinel-comparison-union.d.ts +0 -2
  131. package/dist/src/rules/no-sentinel-comparison-union.js +0 -139
  132. package/dist/src/rules/no-shape-in-symbol-names.d.ts +0 -2
  133. package/dist/src/rules/no-shape-in-symbol-names.js +0 -39
  134. package/dist/src/rules/no-single-use-private-functions.d.ts +0 -17
  135. package/dist/src/rules/no-single-use-private-functions.js +0 -419
  136. package/dist/src/rules/no-sql-string-interpolation.d.ts +0 -7
  137. package/dist/src/rules/no-sql-string-interpolation.js +0 -62
  138. package/dist/src/rules/no-stacked-jsdoc-blocks.d.ts +0 -2
  139. package/dist/src/rules/no-stacked-jsdoc-blocks.js +0 -50
  140. package/dist/src/rules/no-stray-inline-comments.d.ts +0 -2
  141. package/dist/src/rules/no-stray-inline-comments.js +0 -74
  142. package/dist/src/rules/no-swappable-primitive-params.d.ts +0 -2
  143. package/dist/src/rules/no-swappable-primitive-params.js +0 -96
  144. package/dist/src/rules/no-tag-ladder-assertions.d.ts +0 -6
  145. package/dist/src/rules/no-tag-ladder-assertions.js +0 -63
  146. package/dist/src/rules/no-transposed-field-reads.d.ts +0 -8
  147. package/dist/src/rules/no-transposed-field-reads.js +0 -101
  148. package/dist/src/rules/no-unit-return-validators.d.ts +0 -2
  149. package/dist/src/rules/no-unit-return-validators.js +0 -64
  150. package/dist/src/rules/no-unknown-parameters.d.ts +0 -2
  151. package/dist/src/rules/no-unknown-parameters.js +0 -82
  152. package/dist/src/rules/no-unknown-returns.d.ts +0 -2
  153. package/dist/src/rules/no-unknown-returns.js +0 -86
  154. package/dist/src/rules/no-unknown-type-aliases.d.ts +0 -2
  155. package/dist/src/rules/no-unknown-type-aliases.js +0 -64
  156. package/dist/src/rules/no-unsafe-dictionary-type.d.ts +0 -2
  157. package/dist/src/rules/no-unsafe-dictionary-type.js +0 -116
  158. package/dist/src/rules/no-vague-test-filenames.d.ts +0 -2
  159. package/dist/src/rules/no-vague-test-filenames.js +0 -61
  160. package/dist/src/rules/no-widen-then-assert.d.ts +0 -2
  161. package/dist/src/rules/no-widen-then-assert.js +0 -268
  162. package/dist/src/rules/prefer-payload-brand.d.ts +0 -2
  163. package/dist/src/rules/prefer-payload-brand.js +0 -57
  164. package/dist/src/rules/prefer-property-tests.d.ts +0 -5
  165. package/dist/src/rules/prefer-property-tests.js +0 -39
  166. package/dist/src/rules/require-canonical-stringify-for-identity.d.ts +0 -8
  167. package/dist/src/rules/require-canonical-stringify-for-identity.js +0 -72
  168. package/dist/src/rules/require-deprecated-tag-for-legacy-comments.d.ts +0 -2
  169. package/dist/src/rules/require-deprecated-tag-for-legacy-comments.js +0 -34
  170. package/dist/src/rules/require-exhaustive-tag-switch.d.ts +0 -7
  171. package/dist/src/rules/require-exhaustive-tag-switch.js +0 -34
  172. package/dist/src/rules/require-fc-block-predicate.d.ts +0 -2
  173. package/dist/src/rules/require-fc-block-predicate.js +0 -37
  174. package/dist/src/rules/require-jsdoc-on-exported.d.ts +0 -2
  175. package/dist/src/rules/require-jsdoc-on-exported.js +0 -66
  176. package/dist/src/rules/require-published-order.d.ts +0 -2
  177. package/dist/src/rules/require-published-order.js +0 -102
  178. package/dist/src/rules/require-safety-comment-for-type-assertion.d.ts +0 -2
  179. package/dist/src/rules/require-safety-comment-for-type-assertion.js +0 -53
  180. package/dist/src/rules/require-sort-comparator.d.ts +0 -7
  181. package/dist/src/rules/require-sort-comparator.js +0 -34
  182. package/dist/src/rules/test-utils.d.ts +0 -35
  183. package/dist/src/rules/test-utils.js +0 -53
  184. package/dist/src/shared/ancestors.d.ts +0 -18
  185. package/dist/src/shared/ancestors.js +0 -19
  186. package/dist/src/shared/child-nodes.d.ts +0 -12
  187. package/dist/src/shared/child-nodes.js +0 -26
  188. package/dist/src/shared/dictionary-types.d.ts +0 -55
  189. package/dist/src/shared/dictionary-types.js +0 -413
  190. package/dist/src/shared/is-node.d.ts +0 -9
  191. package/dist/src/shared/is-node.js +0 -10
  192. package/dist/src/shared/lexical-type-parameters.d.ts +0 -12
  193. package/dist/src/shared/lexical-type-parameters.js +0 -50
  194. package/dist/src/shared/reflect-method.d.ts +0 -15
  195. package/dist/src/shared/reflect-method.js +0 -32
  196. package/dist/src/shared/rule-options.d.ts +0 -18
  197. package/dist/src/shared/rule-options.js +0 -12
  198. package/dist/src/shared/structural.d.ts +0 -54
  199. package/dist/src/shared/structural.js +0 -40
  200. package/dist/src/testing/index.d.ts +0 -2
  201. package/dist/src/testing/index.js +0 -1
  202. package/dist/src/testing/testable-rule.d.ts +0 -39
  203. package/dist/src/testing/testable-rule.js +0 -84
  204. package/dist/src/ui/index.d.ts +0 -12
  205. package/dist/src/ui/index.js +0 -18
  206. package/dist/src/ui/manifest.d.ts +0 -34
  207. package/dist/src/ui/manifest.js +0 -75
  208. package/dist/src/ui/rules/no-deprecated-parts.d.ts +0 -3
  209. package/dist/src/ui/rules/no-deprecated-parts.js +0 -131
@@ -1,66 +0,0 @@
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
- before() {
40
- seen.clear();
41
- duplicates.clear();
42
- },
43
- TSTypeAliasDeclaration(node) {
44
- const key = literalUnionKey(node.typeAnnotation);
45
- if (key === null)
46
- return;
47
- const joined = key.join("\u0000");
48
- const first = seen.get(joined);
49
- if (first === undefined) {
50
- seen.set(joined, node.id.name);
51
- return;
52
- }
53
- duplicates.set(`${joined}\u0000${node.id.name}`, { node, name: node.id.name, first });
54
- },
55
- "Program:exit"() {
56
- for (const duplicate of duplicates.values()) {
57
- context.report({
58
- node: duplicate.node,
59
- messageId: "duplicateUnion",
60
- data: { second: duplicate.name, first: duplicate.first },
61
- });
62
- }
63
- },
64
- };
65
- },
66
- });
@@ -1,7 +0,0 @@
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;
@@ -1,104 +0,0 @@
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
- });
@@ -1,2 +0,0 @@
1
- /** Exported symbols must resolve by grep in one hop; qualification by the module counts. */
2
- export declare const noGenericExportNamesRule: import("@oxlint/plugins").Rule;
@@ -1,141 +0,0 @@
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
- });
@@ -1,2 +0,0 @@
1
- /** Reject "should never happen" throws; encode the case out of the type instead. */
2
- export declare const noImpossibleBranchThrowRule: import("@oxlint/plugins").Rule;
@@ -1,51 +0,0 @@
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
- });
@@ -1,2 +0,0 @@
1
- /** Detect sound syntactic cases where a known value is explicitly widened and loses evidence. */
2
- export declare const noKnownValueWideningRule: import("@oxlint/plugins").Rule;
@@ -1,176 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- import { classifyWideningTarget, createTypeEnvironment, isKnownEvidenceExpression, } from "../shared/dictionary-types.js";
3
- import { ancestorsOf } from "../shared/ancestors.js";
4
- function unwrapExpression(expression) {
5
- let current = expression;
6
- while (current.type === "ParenthesizedExpression" ||
7
- current.type === "TSAsExpression" ||
8
- current.type === "TSSatisfiesExpression" ||
9
- current.type === "TSTypeAssertion" ||
10
- current.type === "TSNonNullExpression") {
11
- current = current.expression;
12
- }
13
- return current;
14
- }
15
- function resolveVariable(sourceCode, identifier) {
16
- let scope = sourceCode.getScope(identifier);
17
- while (scope !== null) {
18
- const variable = scope.set.get(identifier.name);
19
- if (variable !== undefined)
20
- return variable;
21
- scope = scope.upper;
22
- }
23
- return null;
24
- }
25
- function variableDeclarator(variable) {
26
- if (variable.defs.length !== 1)
27
- return null;
28
- const [definition] = variable.defs;
29
- return definition?.type === "Variable" && definition.node.type === "VariableDeclarator"
30
- ? definition.node
31
- : null;
32
- }
33
- function sourceKeyName(sourceCode, key) {
34
- if (key.type === "Identifier" || key.type === "PrivateIdentifier")
35
- return key.name;
36
- if (key.type === "Literal")
37
- return String(key.value);
38
- return sourceCode.getText(key);
39
- }
40
- function functionName(sourceCode, owner) {
41
- if (owner === null)
42
- return "anonymous function";
43
- if (owner.id !== null)
44
- return owner.id.name;
45
- const parent = ancestorsOf(sourceCode, owner).at(-1);
46
- if (parent?.type === "VariableDeclarator" && parent.id.type === "Identifier")
47
- return parent.id.name;
48
- if (parent?.type === "MethodDefinition")
49
- return sourceKeyName(sourceCode, parent.key);
50
- return "anonymous function";
51
- }
52
- function hasParentAssertion(sourceCode, node) {
53
- const parent = ancestorsOf(sourceCode, node).at(-1);
54
- return parent?.type === "TSAsExpression" || parent?.type === "TSTypeAssertion";
55
- }
56
- /** Detect sound syntactic cases where a known value is explicitly widened and loses evidence. */
57
- export const noKnownValueWideningRule = defineRule({
58
- meta: {
59
- type: "problem",
60
- docs: {
61
- description: "Disallow syntactically established values from flowing into explicitly broad or anonymous target types that discard useful evidence.",
62
- },
63
- messages: {
64
- widening: "The explicit {{target}} type on {{subject}} discards known type evidence. Keep inference, validate with `satisfies`, or use a named owner contract.",
65
- },
66
- },
67
- createOnce(context) {
68
- let environment = null;
69
- const reportFlow = (expression, destination, subject) => {
70
- if (destination === null)
71
- return;
72
- const unwrapped = unwrapExpression(expression);
73
- const accumulator = destination.kind === "open dictionary" || destination.kind === "generic container";
74
- if (accumulator &&
75
- unwrapped.type === "ObjectExpression" &&
76
- unwrapped.properties.length === 0) {
77
- return;
78
- }
79
- const visit = (expression, visitedVariables) => {
80
- if (isKnownEvidenceExpression(expression))
81
- return true;
82
- const unwrapped = unwrapExpression(expression);
83
- if (unwrapped.type !== "Identifier")
84
- return false;
85
- const variable = resolveVariable(context.sourceCode, unwrapped);
86
- if (variable === null || visitedVariables.has(variable))
87
- return false;
88
- const declarator = variableDeclarator(variable);
89
- if (declarator === null || declarator.init === null)
90
- return false;
91
- const declaration = ancestorsOf(context.sourceCode, declarator).at(-1);
92
- const stableConst = declaration?.type === "VariableDeclaration" &&
93
- declaration.kind === "const" &&
94
- variable.references.every((reference) => reference.init || !reference.isWrite());
95
- if (!stableConst)
96
- return false;
97
- visitedVariables.add(variable);
98
- return visit(declarator.init, visitedVariables);
99
- };
100
- if (!visit(expression, new Set()))
101
- return;
102
- context.report({
103
- node: expression,
104
- messageId: "widening",
105
- data: { subject, target: destination.kind },
106
- });
107
- };
108
- const targetFromAnnotation = (annotation) => environment === null || annotation === null || annotation === undefined
109
- ? null
110
- : classifyWideningTarget(annotation.typeAnnotation, environment);
111
- return {
112
- Program(node) {
113
- environment = createTypeEnvironment(node);
114
- },
115
- VariableDeclarator(node) {
116
- if (node.init === null || node.id.type !== "Identifier")
117
- return;
118
- reportFlow(node.init, targetFromAnnotation(node.id.typeAnnotation), `binding \`${node.id.name}\``);
119
- },
120
- PropertyDefinition(node) {
121
- if (node.value === null)
122
- return;
123
- reportFlow(node.value, targetFromAnnotation(node.typeAnnotation), `property \`${sourceKeyName(context.sourceCode, node.key)}\``);
124
- },
125
- AccessorProperty(node) {
126
- if (node.value === null)
127
- return;
128
- reportFlow(node.value, targetFromAnnotation(node.typeAnnotation), `property \`${sourceKeyName(context.sourceCode, node.key)}\``);
129
- },
130
- AssignmentExpression(node) {
131
- if (node.operator !== "=" || node.left.type !== "Identifier")
132
- return;
133
- const variable = resolveVariable(context.sourceCode, node.left);
134
- if (variable === null)
135
- return;
136
- const declarator = variableDeclarator(variable);
137
- if (declarator === null || declarator.id.type !== "Identifier")
138
- return;
139
- reportFlow(node.right, targetFromAnnotation(declarator.id.typeAnnotation), `binding \`${declarator.id.name}\``);
140
- },
141
- ReturnStatement(node) {
142
- if (node.argument === null)
143
- return;
144
- let owner = null;
145
- const ancestors = ancestorsOf(context.sourceCode, node);
146
- for (let index = ancestors.length - 1; index >= 0; index--) {
147
- const current = ancestors[index];
148
- if (current.type === "Program")
149
- break;
150
- if (current.type === "ArrowFunctionExpression" ||
151
- current.type === "FunctionDeclaration" ||
152
- current.type === "FunctionExpression") {
153
- owner = current;
154
- break;
155
- }
156
- }
157
- reportFlow(node.argument, targetFromAnnotation(owner?.returnType), `return value of \`${functionName(context.sourceCode, owner)}\``);
158
- },
159
- ArrowFunctionExpression(node) {
160
- if (node.body.type === "BlockStatement")
161
- return;
162
- reportFlow(node.body, targetFromAnnotation(node.returnType), `return value of \`${functionName(context.sourceCode, node)}\``);
163
- },
164
- TSAsExpression(node) {
165
- if (environment === null || hasParentAssertion(context.sourceCode, node))
166
- return;
167
- reportFlow(node.expression, classifyWideningTarget(node.typeAnnotation, environment), "assertion");
168
- },
169
- TSTypeAssertion(node) {
170
- if (environment === null || hasParentAssertion(context.sourceCode, node))
171
- return;
172
- reportFlow(node.expression, classifyWideningTarget(node.typeAnnotation, environment), "assertion");
173
- },
174
- };
175
- },
176
- });
@@ -1,2 +0,0 @@
1
- /** Ban test framework module mocking in favor of real dependency seams. */
2
- export declare const noModuleMockingRule: import("@oxlint/plugins").Rule;
@@ -1,90 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- import { ancestorsOf } from "../shared/ancestors.js";
3
- const moduleMockMethods = new Set(["doMock", "mock", "unstable_mockModule"]);
4
- /**
5
- * Whether a callee invokes a test framework's module mocking API
6
- * (`vi.doMock`, `jest.mock`, `vi.unstable_mockModule`), either through the
7
- * global or through a binding imported from vitest / @jest/globals.
8
- *
9
- * @param {SourceCode} sourceCode - The rule's source-code accessor.
10
- * @param {ESTree.Expression} callee - The visited call expression's callee.
11
- * @returns {boolean} True when the call mocks a module.
12
- */
13
- function moduleMockCall(sourceCode, callee) {
14
- if (callee.type !== "MemberExpression")
15
- return false;
16
- if (callee.object.type !== "Identifier")
17
- return false;
18
- const identifier = callee.object;
19
- let resolved = null;
20
- let scope = sourceCode.getScope(identifier);
21
- while (scope !== null) {
22
- const variable = scope.set.get(identifier.name);
23
- if (variable !== undefined) {
24
- resolved = variable;
25
- break;
26
- }
27
- scope = scope.upper;
28
- }
29
- const isTestFrameworkName = identifier.name === "vi" || identifier.name === "jest";
30
- let boundToFramework;
31
- if (resolved === null || resolved.defs.length === 0) {
32
- boundToFramework =
33
- (isTestFrameworkName && sourceCode.isGlobalReference(identifier)) || isTestFrameworkName;
34
- }
35
- else {
36
- boundToFramework = resolved.defs.some((definition) => {
37
- if (definition.type !== "ImportBinding")
38
- return false;
39
- const importDeclaration = ancestorsOf(sourceCode, definition.node).at(-1);
40
- if (importDeclaration?.type !== "ImportDeclaration")
41
- return false;
42
- const source = importDeclaration.source.value;
43
- const specifier = definition.node;
44
- const importedName = specifier.type === "ImportSpecifier"
45
- ? specifier.imported.type === "Identifier"
46
- ? specifier.imported.name
47
- : specifier.imported.value
48
- : null;
49
- return ((source === "vitest" && importedName === "vi") ||
50
- (source === "@jest/globals" && importedName === "jest"));
51
- });
52
- }
53
- if (!boundToFramework)
54
- return false;
55
- const property = callee.property;
56
- const method = callee.computed
57
- ? property.type === "Literal" &&
58
- (property.value === "doMock" ||
59
- property.value === "mock" ||
60
- property.value === "unstable_mockModule")
61
- ? property.value
62
- : null
63
- : property.type === "Identifier"
64
- ? property.name
65
- : null;
66
- return method !== null && moduleMockMethods.has(method);
67
- }
68
- /** Ban test framework module mocking in favor of real dependency seams. */
69
- export const noModuleMockingRule = defineRule({
70
- meta: {
71
- type: "problem",
72
- docs: {
73
- description: "Disallow Vitest and Jest module mocking; tests must replace dependencies through real interfaces.",
74
- },
75
- messages: {
76
- moduleMock: "Replace module mocking with dependency injection through a real interface, service layer, or faithful test implementation.",
77
- },
78
- },
79
- createOnce(context) {
80
- return {
81
- CallExpression(node) {
82
- if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression")
83
- return;
84
- if (moduleMockCall(context.sourceCode, node.callee)) {
85
- context.report({ node, messageId: "moduleMock" });
86
- }
87
- },
88
- };
89
- },
90
- });
@@ -1,2 +0,0 @@
1
- /** Owned functions taking several positional inputs accept transposed arguments silently; require one payload object. */
2
- export declare const noMultipleFunctionParamsRule: import("@oxlint/plugins").Rule;