@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,96 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
3
- /** Keyword node type -> spelled-out primitive for messages. */
4
- const PRIMITIVE_KEYWORDS = new Map([
5
- ["TSStringKeyword", "string"],
6
- ["TSNumberKeyword", "number"],
7
- ["TSBooleanKeyword", "boolean"],
8
- ["TSBigIntKeyword", "bigint"],
9
- ]);
10
- const PRIMITIVES = new Set(PRIMITIVE_KEYWORDS.values());
11
- /** Bare primitive annotation on a positional parameter, e.g. `userId: string`.
12
- *
13
- * @param {ESTree.BindingPattern | ESTree.ParamPattern} param - The parameter pattern to inspect.
14
- * @returns {string | null} The primitive keyword's text, or null when not a bare primitive.
15
- */
16
- function barePrimitive(param) {
17
- if (param.type !== "Identifier")
18
- return null;
19
- const annotation = param.typeAnnotation?.typeAnnotation;
20
- if (annotation === undefined || annotation === null)
21
- return null;
22
- return PRIMITIVE_KEYWORDS.get(annotation.type) ?? null;
23
- }
24
- /** Adjacent same-primitive parameters compile despite swaps; require distinct brands. */
25
- export const noSwappablePrimitiveParamsRule = defineRule({
26
- meta: {
27
- type: "problem",
28
- docs: {
29
- description: "Disallow exported functions with two or more adjacent parameters annotated as the same bare primitive (string, number, boolean, bigint); accidental argument swaps compile silently. Require distinct branded types instead.",
30
- },
31
- messages: {
32
- swappablePrimitiveParams: "`{{name}}` takes {{count}} adjacent `{{primitive}}` parameters, so a swapped call compiles. Brand each one (e.g. `type UserId = string & Brand.Brand<\"UserId\">`) so the compiler rejects transposed arguments.",
33
- },
34
- },
35
- createOnce(context) {
36
- const reportFn = (name, id, fn, fnNode) => {
37
- const found = [];
38
- let runPrimitive = null;
39
- let runLength = 0;
40
- for (const param of fn.params) {
41
- const primitive = barePrimitive(param);
42
- if (primitive !== null && primitive === runPrimitive) {
43
- runLength += 1;
44
- }
45
- else {
46
- if (runPrimitive !== null && runLength >= 2)
47
- found.push({ primitive: runPrimitive, count: runLength });
48
- runPrimitive = primitive;
49
- runLength = 1;
50
- }
51
- }
52
- if (runPrimitive !== null && runLength >= 2)
53
- found.push({ primitive: runPrimitive, count: runLength });
54
- if (found.length === 0)
55
- return;
56
- const firstRun = found[0];
57
- if (firstRun === undefined)
58
- return;
59
- context.report({
60
- node: id ?? fnNode,
61
- messageId: "swappablePrimitiveParams",
62
- data: { name, primitive: firstRun.primitive, count: String(firstRun.count) },
63
- });
64
- };
65
- return {
66
- before() {
67
- if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
68
- return false;
69
- },
70
- Program(node) {
71
- for (const statement of node.body) {
72
- const declaration = statement.type === "ExportNamedDeclaration" ||
73
- statement.type === "ExportDefaultDeclaration"
74
- ? (statement.declaration ?? null)
75
- : statement;
76
- if (declaration === null)
77
- continue;
78
- if (declaration.type === "FunctionDeclaration" && declaration.id !== null) {
79
- reportFn(declaration.id.name, declaration.id, declaration, declaration);
80
- }
81
- if (declaration.type === "VariableDeclaration") {
82
- for (const declarator of declaration.declarations) {
83
- if (declarator.id.type !== "Identifier")
84
- continue;
85
- const init = declarator.init;
86
- if (init?.type === "ArrowFunctionExpression" ||
87
- init?.type === "FunctionExpression") {
88
- reportFn(declarator.id.name, declarator.id, init, init);
89
- }
90
- }
91
- }
92
- }
93
- },
94
- };
95
- },
96
- });
@@ -1,6 +0,0 @@
1
- /**
2
- * Hand-rolled `if (x._tag !== "...") throw new Error(...)` ladders re-implement
3
- * narrowing assertions per spec; a shared assertTag helper does it once, with
4
- * type-level narrowing.
5
- */
6
- export declare const noTagLadderAssertionsRule: import("@oxlint/plugins").Rule;
@@ -1,63 +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?$|\/test\//u;
4
- /** Whether the if-consequent (or alternate) is a bare `throw new Error(...)` assertion.
5
- *
6
- * @param {ESTree.Statement | null | undefined} statement - The branch body to inspect.
7
- * @returns {boolean} True when the branch throws a built-in Error constructor.
8
- */
9
- function isBuiltinThrowBranch(statement) {
10
- if (statement === undefined || statement === null)
11
- return false;
12
- const body = statement.type === "BlockStatement" ? statement.body : [statement];
13
- return body.some((child) => child.type === "ThrowStatement" &&
14
- child.argument.type === "NewExpression" &&
15
- child.argument.callee.type === "Identifier" &&
16
- child.argument.callee.name === "Error");
17
- }
18
- /** Whether the binary expression compares a `._tag` member against a string literal.
19
- *
20
- * @param {ESTree.Expression} expression - The expression to inspect.
21
- * @returns {boolean} True when the comparison is a tag equality check.
22
- */
23
- function isTagComparison(expression) {
24
- if (expression.type !== "BinaryExpression")
25
- return false;
26
- if (expression.operator !== "!==" && expression.operator !== "===")
27
- return false;
28
- const sides = [expression.left, expression.right];
29
- const hasTagMember = sides.some((side) => side.type === "MemberExpression" && side.property.type === "Identifier" && side.property.name === "_tag");
30
- const hasStringLiteral = sides.some((side) => side.type === "Literal" && isString(side.value));
31
- return hasTagMember && hasStringLiteral;
32
- }
33
- /**
34
- * Hand-rolled `if (x._tag !== "...") throw new Error(...)` ladders re-implement
35
- * narrowing assertions per spec; a shared assertTag helper does it once, with
36
- * type-level narrowing.
37
- */
38
- export const noTagLadderAssertionsRule = defineRule({
39
- meta: {
40
- type: "suggestion",
41
- docs: {
42
- description: "In specs, replace hand-rolled _tag comparison + throw ladders with the shared assertTag narrowing helper from test helpers.",
43
- },
44
- messages: {
45
- ladder: "This _tag ladder re-implements variant assertion by hand. Use the shared `assertTag(value, tag)` helper so the branch narrows types and fails with a uniform message.",
46
- },
47
- },
48
- createOnce(context) {
49
- return {
50
- before() {
51
- if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
52
- return false;
53
- },
54
- IfStatement(node) {
55
- if (!isTagComparison(node.test))
56
- return;
57
- if (isBuiltinThrowBranch(node.consequent) || isBuiltinThrowBranch(node.alternate)) {
58
- context.report({ node, messageId: "ladder" });
59
- }
60
- },
61
- };
62
- },
63
- });
@@ -1,8 +0,0 @@
1
- /**
2
- * Flag argument lists and object literals that pluck two or more role fields
3
- * off the same base expression in reversed canonical order: the syntactic
4
- * fingerprint of inline structural surgery on a domain value (e.g. a
5
- * hand-rolled reciprocal). Such shuffles belong behind a named operation
6
- * that owns the invariant.
7
- */
8
- export declare const noTransposedFieldReadsRule: import("@oxlint/plugins").Rule;
@@ -1,101 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- import { isString } from "../shared/structural.js";
3
- import { firstOptionRecord } from "../shared/rule-options.js";
4
- /** The `base.field` pluck of a direct member read, or null for anything more elaborate.
5
- * @param {ESTree.Expression | null | undefined} expression - Argument or spread expression to inspect.
6
- * @param {(node: ESTree.Node) => string} getText - Source text accessor from the lint context.
7
- * @returns {{ baseText: string; field: string }} Base text and field name, or null when not a simple pluck. */
8
- function directPluck(expression, getText) {
9
- if (expression === undefined || expression === null)
10
- return null;
11
- let member = expression;
12
- while (member.type === "ParenthesizedExpression")
13
- member = member.expression;
14
- if (member.type !== "MemberExpression" || member.computed || member.property.type !== "Identifier") {
15
- return null;
16
- }
17
- return { baseText: getText(member.object), field: member.property.name };
18
- }
19
- /**
20
- * Flag argument lists and object literals that pluck two or more role fields
21
- * off the same base expression in reversed canonical order: the syntactic
22
- * fingerprint of inline structural surgery on a domain value (e.g. a
23
- * hand-rolled reciprocal). Such shuffles belong behind a named operation
24
- * that owns the invariant.
25
- */
26
- export const noTransposedFieldReadsRule = defineRule({
27
- meta: {
28
- type: "problem",
29
- docs: {
30
- description: 'Disallow directly reading two or more configured role fields from the same expression in reversed order inside call arguments or object literals; require a named domain operation instead. Configure `groups` with your domain\'s canonical field pairings (e.g. groups: [["startDate", "endDate"]]).',
31
- },
32
- messages: {
33
- transposedFieldReads: "`{{base}}.{{first}}` is read after `{{base}}.{{second}}`, reversing the canonical order {{group}}; this looks like inline structural surgery on a domain value. Use a named operation instead of shuffling its fields by hand.",
34
- },
35
- schema: [
36
- {
37
- type: "object",
38
- properties: {
39
- groups: {
40
- type: "array",
41
- items: { type: "array", items: { type: "string" }, minItems: 2 },
42
- },
43
- },
44
- additionalProperties: false,
45
- },
46
- ],
47
- // Inert until configured: which field pairs have a canonical order is
48
- // consumer-domain knowledge (e.g. numerator/denominator, startDate/endDate),
49
- // so no universal default exists.
50
- defaultOptions: [{ groups: [] }],
51
- },
52
- createOnce(context) {
53
- const option = firstOptionRecord(context.options);
54
- const groups = (Array.isArray(option.groups) ? option.groups : [])
55
- .filter((group) => Array.isArray(group) && group.every((field) => isString(field)))
56
- .map((fields) => ({
57
- order: new Map(fields.map((field, index) => [field, index])),
58
- label: fields.join(" → "),
59
- }));
60
- const checkSequence = (node, parts) => {
61
- const getText = (target) => context.sourceCode.getText(target);
62
- const plucks = [];
63
- for (const [position, part] of parts.entries()) {
64
- const direct = directPluck(part.expression, getText);
65
- if (direct === null)
66
- continue;
67
- plucks.push({ ...direct, position });
68
- }
69
- for (const group of groups) {
70
- const inGroup = plucks.filter((pluck) => group.order.has(pluck.field));
71
- for (const later of inGroup) {
72
- for (const earlier of inGroup) {
73
- if (earlier.baseText !== later.baseText || earlier.position >= later.position)
74
- continue;
75
- if ((group.order.get(earlier.field) ?? 0) > (group.order.get(later.field) ?? 0)) {
76
- context.report({
77
- node,
78
- messageId: "transposedFieldReads",
79
- data: {
80
- base: earlier.baseText,
81
- first: later.field,
82
- second: earlier.field,
83
- group: group.label,
84
- },
85
- });
86
- break;
87
- }
88
- }
89
- }
90
- }
91
- };
92
- return {
93
- CallExpression(node) {
94
- checkSequence(node, node.arguments.map((argument) => ({ expression: argument })));
95
- },
96
- ObjectExpression(node) {
97
- checkSequence(node, node.properties.map((property) => property.type === "Property" ? { expression: property.value } : { expression: undefined }));
98
- },
99
- };
100
- },
101
- });
@@ -1,2 +0,0 @@
1
- /** Validators that return nothing throw away what they just learned. */
2
- export declare const noUnitReturnValidatorsRule: import("@oxlint/plugins").Rule;
@@ -1,64 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- const VALIDATOR_NAME = /^(?:validate|check|ensure)/u;
3
- /**
4
- * Whether a validator function declares void/undefined as its return type.
5
- *
6
- * @param {ValidatorFunction} node - The function-like node to inspect.
7
- * @returns {boolean} True when the return annotation is void or undefined.
8
- */
9
- function returnsVoid(node) {
10
- const annotation = node.returnType;
11
- if (annotation === null || annotation === undefined)
12
- return false;
13
- const type = annotation.typeAnnotation;
14
- if (type.type === "TSVoidKeyword" || type.type === "TSUndefinedKeyword")
15
- return true;
16
- if (type.type === "TSParenthesizedType") {
17
- const inner = type.typeAnnotation;
18
- return inner.type === "TSVoidKeyword" || inner.type === "TSUndefinedKeyword";
19
- }
20
- return false;
21
- }
22
- /** Validators that return nothing throw away what they just learned. */
23
- export const noUnitReturnValidatorsRule = defineRule({
24
- meta: {
25
- type: "problem",
26
- docs: {
27
- description: "Disallow validators that return nothing (void/undefined); a check should preserve what it learned by returning the refined value.",
28
- },
29
- messages: {
30
- unitValidator: "`{{name}}` validates and returns nothing (void). Return the refined value (Option/parsed type) so the knowledge survives: parse, don't validate.",
31
- },
32
- },
33
- createOnce(context) {
34
- const report = (name, node, validator) => {
35
- if (!VALIDATOR_NAME.test(name))
36
- return;
37
- if (!returnsVoid(validator))
38
- return;
39
- context.report({ node, messageId: "unitValidator", data: { name } });
40
- };
41
- return {
42
- ExportNamedDeclaration(node) {
43
- const declaration = node.declaration;
44
- if (declaration === null)
45
- return;
46
- if (declaration.type === "FunctionDeclaration") {
47
- if (declaration.id !== null)
48
- report(declaration.id.name, declaration, declaration);
49
- return;
50
- }
51
- if (declaration.type !== "VariableDeclaration")
52
- return;
53
- for (const declarator of declaration.declarations) {
54
- const init = declarator.init;
55
- if (init === null || init === undefined || init.type !== "ArrowFunctionExpression")
56
- continue;
57
- if (declarator.id.type !== "Identifier")
58
- continue;
59
- report(declarator.id.name, declarator, init);
60
- }
61
- },
62
- };
63
- },
64
- });
@@ -1,2 +0,0 @@
1
- /** Disallow unknown inputs except explicitly named error-cause enrichment. */
2
- export declare const noUnknownParametersRule: import("@oxlint/plugins").Rule;
@@ -1,82 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- /** Unwrap parameter-property/rest/default wrappers to the declared annotation.
3
- *
4
- * @param {Parameter} parameter - The parameter pattern to inspect.
5
- * @returns {ESTree.TSTypeAnnotation | null | undefined} The declared type annotation, if any.
6
- */
7
- function parameterAnnotation(parameter) {
8
- if (parameter.type === "TSParameterProperty") {
9
- return parameterAnnotation(parameter.parameter);
10
- }
11
- if (parameter.type === "RestElement") {
12
- return parameter.typeAnnotation ?? parameterAnnotation(parameter.argument);
13
- }
14
- if (parameter.type === "AssignmentPattern") {
15
- return parameter.typeAnnotation ?? parameter.left.typeAnnotation;
16
- }
17
- return parameter.typeAnnotation;
18
- }
19
- /** Render a parameter's source name for reporting.
20
- *
21
- * @param {{ parameter: Parameter; sourceText: string }} payload - The pattern and its source text.
22
- * @returns {string} The bound identifier's name, or the raw unknown-annotated text.
23
- */
24
- function parameterName(payload) {
25
- const { parameter, sourceText } = payload;
26
- if (parameter.type === "TSParameterProperty") {
27
- return parameterName({ parameter: parameter.parameter, sourceText });
28
- }
29
- if (parameter.type === "AssignmentPattern") {
30
- return parameterName({ parameter: parameter.left, sourceText });
31
- }
32
- if (parameter.type === "RestElement") {
33
- return parameterName({ parameter: parameter.argument, sourceText });
34
- }
35
- return parameter.type === "Identifier"
36
- ? parameter.name
37
- : sourceText.replace(/\s*:\s*unknown\s*$/u, "");
38
- }
39
- /** Disallow unknown inputs except explicitly named error-cause enrichment. */
40
- export const noUnknownParametersRule = defineRule({
41
- meta: {
42
- type: "problem",
43
- docs: {
44
- description: "Disallow explicitly unknown function parameters except `cause`; decode unknown input at its I/O boundary instead.",
45
- },
46
- messages: {
47
- unknownParameter: "Parameter `{{parameter}}` leaves input unparsed. Accept a named domain type; run the expected schema or parser at the I/O boundary before calling this function.",
48
- },
49
- },
50
- createOnce(context) {
51
- const checkParameters = (node) => {
52
- for (const parameter of node.params) {
53
- const annotation = parameterAnnotation(parameter);
54
- if (annotation?.typeAnnotation.type !== "TSUnknownKeyword")
55
- continue;
56
- const name = parameterName({
57
- parameter,
58
- sourceText: context.sourceCode.getText(parameter),
59
- });
60
- if (name === "cause")
61
- continue;
62
- context.report({
63
- node: annotation.typeAnnotation,
64
- messageId: "unknownParameter",
65
- data: { parameter: name },
66
- });
67
- }
68
- };
69
- return {
70
- ArrowFunctionExpression: checkParameters,
71
- FunctionDeclaration: checkParameters,
72
- FunctionExpression: checkParameters,
73
- TSCallSignatureDeclaration: checkParameters,
74
- TSConstructSignatureDeclaration: checkParameters,
75
- TSConstructorType: checkParameters,
76
- TSDeclareFunction: checkParameters,
77
- TSEmptyBodyFunctionExpression: checkParameters,
78
- TSFunctionType: checkParameters,
79
- TSMethodSignature: checkParameters,
80
- };
81
- },
82
- });
@@ -1,2 +0,0 @@
1
- /** Ban function contracts that return unknown instead of a parsed domain type. */
2
- export declare const noUnknownReturnsRule: import("@oxlint/plugins").Rule;
@@ -1,86 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- import { ancestorsOf } from "../shared/ancestors.js";
3
- import { lexicalTypeParameterNames } from "../shared/lexical-type-parameters.js";
4
- function referencedAliasName(type) {
5
- if (type.type === "TSParenthesizedType")
6
- return referencedAliasName(type.typeAnnotation);
7
- if (type.type !== "TSTypeReference" || type.typeName.type !== "Identifier")
8
- return null;
9
- return type.typeArguments === null ||
10
- type.typeArguments === undefined ||
11
- type.typeArguments.params.length === 0
12
- ? type.typeName.name
13
- : null;
14
- }
15
- /** Ban function contracts that return unknown instead of a parsed domain type. */
16
- export const noUnknownReturnsRule = defineRule({
17
- meta: {
18
- type: "problem",
19
- docs: {
20
- description: "Disallow functions whose explicit return contract is unknown or Promise<unknown>.",
21
- },
22
- messages: {
23
- unknownReturn: "This function exposes `unknown` to its caller. Parse the value at its boundary and return a named domain type.",
24
- },
25
- },
26
- createOnce(context) {
27
- const aliases = new Map();
28
- const resolvesToUnknown = (type, shadowedAliases, visited = new Set()) => {
29
- if (type.type === "TSUnknownKeyword")
30
- return true;
31
- if (type.type === "TSParenthesizedType") {
32
- return resolvesToUnknown(type.typeAnnotation, shadowedAliases, visited);
33
- }
34
- if (type.type === "TSUnionType") {
35
- return type.types.some((member) => resolvesToUnknown(member, shadowedAliases, visited));
36
- }
37
- if (type.type === "TSTypeReference" &&
38
- type.typeName.type === "Identifier" &&
39
- (type.typeName.name === "Promise" || type.typeName.name === "PromiseLike")) {
40
- const value = type.typeArguments?.params[0];
41
- return value !== undefined && resolvesToUnknown(value, shadowedAliases, visited);
42
- }
43
- const name = referencedAliasName(type);
44
- if (name === null || visited.has(name) || shadowedAliases.has(name))
45
- return false;
46
- const alias = aliases.get(name);
47
- if (alias === undefined ||
48
- (alias.typeParameters !== null && alias.typeParameters !== undefined)) {
49
- return false;
50
- }
51
- const nextVisited = new Set(visited);
52
- nextVisited.add(name);
53
- return resolvesToUnknown(alias.typeAnnotation, shadowedAliases, nextVisited);
54
- };
55
- const checkReturnType = (node) => {
56
- const annotation = node.returnType;
57
- if (annotation === null || annotation === undefined)
58
- return;
59
- if (!resolvesToUnknown(annotation.typeAnnotation, lexicalTypeParameterNames(node, ancestorsOf(context.sourceCode, node), context.sourceCode.visitorKeys))) {
60
- return;
61
- }
62
- context.report({ node: annotation.typeAnnotation, messageId: "unknownReturn" });
63
- };
64
- return {
65
- Program(node) {
66
- aliases.clear();
67
- for (const statement of node.body) {
68
- const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
69
- if (declaration?.type === "TSTypeAliasDeclaration") {
70
- aliases.set(declaration.id.name, declaration);
71
- }
72
- }
73
- },
74
- ArrowFunctionExpression: checkReturnType,
75
- FunctionDeclaration: checkReturnType,
76
- FunctionExpression: checkReturnType,
77
- TSCallSignatureDeclaration: checkReturnType,
78
- TSConstructSignatureDeclaration: checkReturnType,
79
- TSConstructorType: checkReturnType,
80
- TSDeclareFunction: checkReturnType,
81
- TSEmptyBodyFunctionExpression: checkReturnType,
82
- TSFunctionType: checkReturnType,
83
- TSMethodSignature: checkReturnType,
84
- };
85
- },
86
- });
@@ -1,2 +0,0 @@
1
- /** Ban named aliases that merely conceal TypeScript's unknown top type. */
2
- export declare const noUnknownTypeAliasesRule: import("@oxlint/plugins").Rule;
@@ -1,64 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- function referencedAliasName(type) {
3
- if (type.type === "TSParenthesizedType")
4
- return referencedAliasName(type.typeAnnotation);
5
- if (type.type !== "TSTypeReference" || type.typeName.type !== "Identifier")
6
- return null;
7
- return type.typeArguments === null ||
8
- type.typeArguments === undefined ||
9
- type.typeArguments.params.length === 0
10
- ? type.typeName.name
11
- : null;
12
- }
13
- /** Ban named aliases that merely conceal TypeScript's unknown top type. */
14
- export const noUnknownTypeAliasesRule = defineRule({
15
- meta: {
16
- type: "problem",
17
- docs: {
18
- description: "Disallow type aliases whose resolved type is unknown; unknown must remain visible at an allowed boundary.",
19
- },
20
- messages: {
21
- unknownAlias: "Type alias `{{alias}}` hides `unknown`. Keep `unknown` explicit at the parsing boundary or on an allowed `cause` field; otherwise use the parsed owner type.",
22
- },
23
- },
24
- createOnce(context) {
25
- const aliases = new Map();
26
- const resolvesToUnknown = (type, visited = new Set()) => {
27
- if (type.type === "TSUnknownKeyword")
28
- return true;
29
- if (type.type === "TSParenthesizedType")
30
- return resolvesToUnknown(type.typeAnnotation, visited);
31
- const name = referencedAliasName(type);
32
- if (name === null || visited.has(name))
33
- return false;
34
- const alias = aliases.get(name);
35
- if (alias === undefined ||
36
- (alias.typeParameters !== null && alias.typeParameters !== undefined)) {
37
- return false;
38
- }
39
- const nextVisited = new Set(visited);
40
- nextVisited.add(name);
41
- return resolvesToUnknown(alias.typeAnnotation, nextVisited);
42
- };
43
- return {
44
- Program(node) {
45
- aliases.clear();
46
- for (const statement of node.body) {
47
- const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
48
- if (declaration?.type === "TSTypeAliasDeclaration") {
49
- aliases.set(declaration.id.name, declaration);
50
- }
51
- }
52
- for (const alias of aliases.values()) {
53
- if (!resolvesToUnknown(alias.typeAnnotation, new Set([alias.id.name])))
54
- continue;
55
- context.report({
56
- node: alias.id,
57
- messageId: "unknownAlias",
58
- data: { alias: alias.id.name },
59
- });
60
- }
61
- },
62
- };
63
- },
64
- });
@@ -1,2 +0,0 @@
1
- /** Disallow object-dictionary contracts whose direct value type is an unsafe escape hatch. */
2
- export declare const noUnsafeDictionaryTypeRule: import("@oxlint/plugins").Rule;