@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.
- package/package.json +18 -18
- package/dist/src/configs/recommended-rules.d.ts +0 -20
- package/dist/src/configs/recommended-rules.js +0 -22
- package/dist/src/effect/index.d.ts +0 -3
- package/dist/src/effect/index.js +0 -60
- package/dist/src/effect/rules/guarded-op-must-return-effect.d.ts +0 -6
- package/dist/src/effect/rules/guarded-op-must-return-effect.js +0 -235
- package/dist/src/effect/rules/guarded-op-must-return-option.d.ts +0 -2
- package/dist/src/effect/rules/guarded-op-must-return-option.js +0 -88
- package/dist/src/effect/rules/no-cascading-layer-provide.d.ts +0 -6
- package/dist/src/effect/rules/no-cascading-layer-provide.js +0 -73
- package/dist/src/effect/rules/no-decode-unknown-option.d.ts +0 -7
- package/dist/src/effect/rules/no-decode-unknown-option.js +0 -34
- package/dist/src/effect/rules/no-direct-browser-storage.d.ts +0 -2
- package/dist/src/effect/rules/no-direct-browser-storage.js +0 -88
- package/dist/src/effect/rules/no-direct-fetch.d.ts +0 -2
- package/dist/src/effect/rules/no-direct-fetch.js +0 -37
- package/dist/src/effect/rules/no-manual-field-guards.d.ts +0 -6
- package/dist/src/effect/rules/no-manual-field-guards.js +0 -129
- package/dist/src/effect/rules/no-nested-layer-provide.d.ts +0 -2
- package/dist/src/effect/rules/no-nested-layer-provide.js +0 -50
- package/dist/src/effect/rules/no-nullish-default-on-partial-input.d.ts +0 -13
- package/dist/src/effect/rules/no-nullish-default-on-partial-input.js +0 -109
- package/dist/src/effect/rules/no-raw-error-forwarding.d.ts +0 -12
- package/dist/src/effect/rules/no-raw-error-forwarding.js +0 -103
- package/dist/src/effect/rules/no-schema-class-modeling.d.ts +0 -2
- package/dist/src/effect/rules/no-schema-class-modeling.js +0 -52
- package/dist/src/effect/rules/no-service-constructor-imports.d.ts +0 -2
- package/dist/src/effect/rules/no-service-constructor-imports.js +0 -42
- package/dist/src/effect/rules/no-silent-error-swallow.d.ts +0 -2
- package/dist/src/effect/rules/no-silent-error-swallow.js +0 -95
- package/dist/src/effect/rules/no-static-effect-service-forwarders.d.ts +0 -6
- package/dist/src/effect/rules/no-static-effect-service-forwarders.js +0 -222
- package/dist/src/effect/rules/no-try-catch.d.ts +0 -2
- package/dist/src/effect/rules/no-try-catch.js +0 -30
- package/dist/src/effect/rules/no-unguarded-json-parse.d.ts +0 -5
- package/dist/src/effect/rules/no-unguarded-json-parse.js +0 -200
- package/dist/src/effect/rules/option-core-needs-effect-public.d.ts +0 -5
- package/dist/src/effect/rules/option-core-needs-effect-public.js +0 -76
- package/dist/src/effect/rules/prefer-die-for-precondition-defects.d.ts +0 -5
- package/dist/src/effect/rules/prefer-die-for-precondition-defects.js +0 -112
- package/dist/src/effect/rules/prefer-effect-gen-for-guard-ladders.d.ts +0 -5
- package/dist/src/effect/rules/prefer-effect-gen-for-guard-ladders.js +0 -72
- package/dist/src/effect/rules/prefer-effect-match.d.ts +0 -2
- package/dist/src/effect/rules/prefer-effect-match.js +0 -74
- package/dist/src/effect/rules/prefer-effect-predicate-over-boolean-function.d.ts +0 -2
- package/dist/src/effect/rules/prefer-effect-predicate-over-boolean-function.js +0 -75
- package/dist/src/effect/rules/prefer-named-guard-predicate.d.ts +0 -2
- package/dist/src/effect/rules/prefer-named-guard-predicate.js +0 -93
- package/dist/src/effect/rules/prefer-option-pipeline.d.ts +0 -2
- package/dist/src/effect/rules/prefer-option-pipeline.js +0 -87
- package/dist/src/effect/rules/prefer-ordering-match.d.ts +0 -2
- package/dist/src/effect/rules/prefer-ordering-match.js +0 -135
- package/dist/src/effect/rules/prefer-tagged-enum.d.ts +0 -2
- package/dist/src/effect/rules/prefer-tagged-enum.js +0 -66
- package/dist/src/effect/rules/require-schema-type-derivation.d.ts +0 -7
- package/dist/src/effect/rules/require-schema-type-derivation.js +0 -80
- package/dist/src/index.d.ts +0 -3
- package/dist/src/index.js +0 -106
- package/dist/src/meta/index.d.ts +0 -7
- package/dist/src/meta/index.js +0 -22
- package/dist/src/meta/rules/no-disable-directives.d.ts +0 -6
- package/dist/src/meta/rules/no-disable-directives.js +0 -35
- package/dist/src/meta/rules/no-manual-ancestor-walks.d.ts +0 -2
- package/dist/src/meta/rules/no-manual-ancestor-walks.js +0 -26
- package/dist/src/meta/rules/prefer-before-file-scope.d.ts +0 -2
- package/dist/src/meta/rules/prefer-before-file-scope.js +0 -57
- package/dist/src/meta/rules/require-create-once.d.ts +0 -2
- package/dist/src/meta/rules/require-create-once.js +0 -51
- package/dist/src/meta/rules/require-rule-tester.d.ts +0 -2
- package/dist/src/meta/rules/require-rule-tester.js +0 -50
- package/dist/src/react/index.d.ts +0 -3
- package/dist/src/react/index.js +0 -16
- package/dist/src/react/role.d.ts +0 -23
- package/dist/src/react/role.js +0 -30
- package/dist/src/react/rules/require-dot-notation-exports.d.ts +0 -27
- package/dist/src/react/rules/require-dot-notation-exports.js +0 -144
- package/dist/src/react/rules/require-guarded-context-hook.d.ts +0 -19
- package/dist/src/react/rules/require-guarded-context-hook.js +0 -167
- package/dist/src/react/rules/require-tripartite-context.d.ts +0 -17
- package/dist/src/react/rules/require-tripartite-context.js +0 -160
- package/dist/src/react/rules/use-encapsulation.d.ts +0 -22
- package/dist/src/react/rules/use-encapsulation.js +0 -97
- package/dist/src/rules/no-anonymous-wide-tuples.d.ts +0 -7
- package/dist/src/rules/no-anonymous-wide-tuples.js +0 -34
- package/dist/src/rules/no-barrel-export-star.d.ts +0 -2
- package/dist/src/rules/no-barrel-export-star.js +0 -26
- package/dist/src/rules/no-boolean-field-signals.d.ts +0 -2
- package/dist/src/rules/no-boolean-field-signals.js +0 -279
- package/dist/src/rules/no-builtin-throws.d.ts +0 -6
- package/dist/src/rules/no-builtin-throws.js +0 -74
- package/dist/src/rules/no-chained-type-assertions.d.ts +0 -2
- package/dist/src/rules/no-chained-type-assertions.js +0 -54
- package/dist/src/rules/no-conditional-empty-object-spread.d.ts +0 -2
- package/dist/src/rules/no-conditional-empty-object-spread.js +0 -36
- package/dist/src/rules/no-duplicated-literal-union.d.ts +0 -6
- package/dist/src/rules/no-duplicated-literal-union.js +0 -66
- package/dist/src/rules/no-exported-mutable-state.d.ts +0 -7
- package/dist/src/rules/no-exported-mutable-state.js +0 -104
- package/dist/src/rules/no-generic-export-names.d.ts +0 -2
- package/dist/src/rules/no-generic-export-names.js +0 -141
- package/dist/src/rules/no-impossible-branch-throw.d.ts +0 -2
- package/dist/src/rules/no-impossible-branch-throw.js +0 -51
- package/dist/src/rules/no-known-value-widening.d.ts +0 -2
- package/dist/src/rules/no-known-value-widening.js +0 -176
- package/dist/src/rules/no-module-mocking.d.ts +0 -2
- package/dist/src/rules/no-module-mocking.js +0 -90
- package/dist/src/rules/no-multiple-function-params.d.ts +0 -2
- package/dist/src/rules/no-multiple-function-params.js +0 -155
- package/dist/src/rules/no-mutable-environment-capture.d.ts +0 -7
- package/dist/src/rules/no-mutable-environment-capture.js +0 -134
- package/dist/src/rules/no-nondeterministic-core.d.ts +0 -6
- package/dist/src/rules/no-nondeterministic-core.js +0 -63
- package/dist/src/rules/no-object-parameters.d.ts +0 -2
- package/dist/src/rules/no-object-parameters.js +0 -95
- package/dist/src/rules/no-optional-function-parameters.d.ts +0 -7
- package/dist/src/rules/no-optional-function-parameters.js +0 -44
- package/dist/src/rules/no-product-of-state-booleans.d.ts +0 -2
- package/dist/src/rules/no-product-of-state-booleans.js +0 -79
- package/dist/src/rules/no-redundant-derived-field.d.ts +0 -6
- package/dist/src/rules/no-redundant-derived-field.js +0 -194
- package/dist/src/rules/no-reflect-apply.d.ts +0 -2
- package/dist/src/rules/no-reflect-apply.js +0 -29
- package/dist/src/rules/no-reflect-get.d.ts +0 -2
- package/dist/src/rules/no-reflect-get.js +0 -29
- package/dist/src/rules/no-reinterpret-cast.d.ts +0 -2
- package/dist/src/rules/no-reinterpret-cast.js +0 -68
- package/dist/src/rules/no-runtime-typeof.d.ts +0 -2
- package/dist/src/rules/no-runtime-typeof.js +0 -54
- package/dist/src/rules/no-sentinel-comparison-union.d.ts +0 -2
- package/dist/src/rules/no-sentinel-comparison-union.js +0 -139
- package/dist/src/rules/no-shape-in-symbol-names.d.ts +0 -2
- package/dist/src/rules/no-shape-in-symbol-names.js +0 -39
- package/dist/src/rules/no-single-use-private-functions.d.ts +0 -17
- package/dist/src/rules/no-single-use-private-functions.js +0 -419
- package/dist/src/rules/no-sql-string-interpolation.d.ts +0 -7
- package/dist/src/rules/no-sql-string-interpolation.js +0 -62
- package/dist/src/rules/no-stacked-jsdoc-blocks.d.ts +0 -2
- package/dist/src/rules/no-stacked-jsdoc-blocks.js +0 -50
- package/dist/src/rules/no-stray-inline-comments.d.ts +0 -2
- package/dist/src/rules/no-stray-inline-comments.js +0 -74
- package/dist/src/rules/no-swappable-primitive-params.d.ts +0 -2
- package/dist/src/rules/no-swappable-primitive-params.js +0 -96
- package/dist/src/rules/no-tag-ladder-assertions.d.ts +0 -6
- package/dist/src/rules/no-tag-ladder-assertions.js +0 -63
- package/dist/src/rules/no-transposed-field-reads.d.ts +0 -8
- package/dist/src/rules/no-transposed-field-reads.js +0 -101
- package/dist/src/rules/no-unit-return-validators.d.ts +0 -2
- package/dist/src/rules/no-unit-return-validators.js +0 -64
- package/dist/src/rules/no-unknown-parameters.d.ts +0 -2
- package/dist/src/rules/no-unknown-parameters.js +0 -82
- package/dist/src/rules/no-unknown-returns.d.ts +0 -2
- package/dist/src/rules/no-unknown-returns.js +0 -86
- package/dist/src/rules/no-unknown-type-aliases.d.ts +0 -2
- package/dist/src/rules/no-unknown-type-aliases.js +0 -64
- package/dist/src/rules/no-unsafe-dictionary-type.d.ts +0 -2
- package/dist/src/rules/no-unsafe-dictionary-type.js +0 -116
- package/dist/src/rules/no-vague-test-filenames.d.ts +0 -2
- package/dist/src/rules/no-vague-test-filenames.js +0 -61
- package/dist/src/rules/no-widen-then-assert.d.ts +0 -2
- package/dist/src/rules/no-widen-then-assert.js +0 -268
- package/dist/src/rules/prefer-payload-brand.d.ts +0 -2
- package/dist/src/rules/prefer-payload-brand.js +0 -57
- package/dist/src/rules/prefer-property-tests.d.ts +0 -5
- package/dist/src/rules/prefer-property-tests.js +0 -39
- package/dist/src/rules/require-canonical-stringify-for-identity.d.ts +0 -8
- package/dist/src/rules/require-canonical-stringify-for-identity.js +0 -72
- package/dist/src/rules/require-deprecated-tag-for-legacy-comments.d.ts +0 -2
- package/dist/src/rules/require-deprecated-tag-for-legacy-comments.js +0 -34
- package/dist/src/rules/require-exhaustive-tag-switch.d.ts +0 -7
- package/dist/src/rules/require-exhaustive-tag-switch.js +0 -34
- package/dist/src/rules/require-fc-block-predicate.d.ts +0 -2
- package/dist/src/rules/require-fc-block-predicate.js +0 -37
- package/dist/src/rules/require-jsdoc-on-exported.d.ts +0 -2
- package/dist/src/rules/require-jsdoc-on-exported.js +0 -66
- package/dist/src/rules/require-published-order.d.ts +0 -2
- package/dist/src/rules/require-published-order.js +0 -102
- package/dist/src/rules/require-safety-comment-for-type-assertion.d.ts +0 -2
- package/dist/src/rules/require-safety-comment-for-type-assertion.js +0 -53
- package/dist/src/rules/require-sort-comparator.d.ts +0 -7
- package/dist/src/rules/require-sort-comparator.js +0 -34
- package/dist/src/rules/test-utils.d.ts +0 -35
- package/dist/src/rules/test-utils.js +0 -53
- package/dist/src/shared/ancestors.d.ts +0 -18
- package/dist/src/shared/ancestors.js +0 -19
- package/dist/src/shared/child-nodes.d.ts +0 -12
- package/dist/src/shared/child-nodes.js +0 -26
- package/dist/src/shared/dictionary-types.d.ts +0 -55
- package/dist/src/shared/dictionary-types.js +0 -413
- package/dist/src/shared/is-node.d.ts +0 -9
- package/dist/src/shared/is-node.js +0 -10
- package/dist/src/shared/lexical-type-parameters.d.ts +0 -12
- package/dist/src/shared/lexical-type-parameters.js +0 -50
- package/dist/src/shared/reflect-method.d.ts +0 -15
- package/dist/src/shared/reflect-method.js +0 -32
- package/dist/src/shared/rule-options.d.ts +0 -18
- package/dist/src/shared/rule-options.js +0 -12
- package/dist/src/shared/structural.d.ts +0 -54
- package/dist/src/shared/structural.js +0 -40
- package/dist/src/testing/index.d.ts +0 -2
- package/dist/src/testing/index.js +0 -1
- package/dist/src/testing/testable-rule.d.ts +0 -39
- package/dist/src/testing/testable-rule.js +0 -84
- package/dist/src/ui/index.d.ts +0 -12
- package/dist/src/ui/index.js +0 -18
- package/dist/src/ui/manifest.d.ts +0 -34
- package/dist/src/ui/manifest.js +0 -75
- package/dist/src/ui/rules/no-deprecated-parts.d.ts +0 -3
- package/dist/src/ui/rules/no-deprecated-parts.js +0 -131
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
import { readField } from "../../shared/structural.js";
|
|
3
|
-
import { ancestorsOf } from "../../shared/ancestors.js";
|
|
4
|
-
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$|\/test\//u;
|
|
5
|
-
/** Unwrap a tuple element to the type node it contributes to the annotation walk.
|
|
6
|
-
*
|
|
7
|
-
* @param {ESTree.TSTupleElement} element - Tuple element node.
|
|
8
|
-
* @returns {ESTree.TSType} The underlying type node.
|
|
9
|
-
*/
|
|
10
|
-
function tupleElementType(element) {
|
|
11
|
-
if (element.type === "TSOptionalType" || element.type === "TSRestType") {
|
|
12
|
-
return element.typeAnnotation;
|
|
13
|
-
}
|
|
14
|
-
if ("elementType" in element)
|
|
15
|
-
return tupleElementType(element.elementType);
|
|
16
|
-
return element;
|
|
17
|
-
}
|
|
18
|
-
/** Whether the annotation references the Effect or Either channel (defect-capable).
|
|
19
|
-
*
|
|
20
|
-
* @param {ESTree.Node} node - A function-like node whose return annotation is inspected.
|
|
21
|
-
* @returns {boolean} True when the return annotation mentions Effect or Either.
|
|
22
|
-
*/
|
|
23
|
-
function returnsEffectOrFailChannel(node) {
|
|
24
|
-
if (node.type !== "FunctionDeclaration" &&
|
|
25
|
-
node.type !== "FunctionExpression" &&
|
|
26
|
-
node.type !== "ArrowFunctionExpression") {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
const annotation = node.returnType?.typeAnnotation;
|
|
30
|
-
if (annotation === undefined)
|
|
31
|
-
return false;
|
|
32
|
-
const seen = [annotation];
|
|
33
|
-
while (seen.length > 0) {
|
|
34
|
-
const type = seen.pop();
|
|
35
|
-
if (type === undefined)
|
|
36
|
-
continue;
|
|
37
|
-
switch (type.type) {
|
|
38
|
-
case "TSTypeReference": {
|
|
39
|
-
const name = type.typeName;
|
|
40
|
-
const head = name.type === "Identifier"
|
|
41
|
-
? name.name
|
|
42
|
-
: name.type === "TSQualifiedName"
|
|
43
|
-
? name.left.type === "Identifier"
|
|
44
|
-
? name.left.name
|
|
45
|
-
: null
|
|
46
|
-
: null;
|
|
47
|
-
if (head === "Effect" || head === "Either") {
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
const args = readField(type, "typeArguments");
|
|
51
|
-
if (args?.params !== undefined)
|
|
52
|
-
seen.push(...args.params);
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
case "TSUnionType":
|
|
56
|
-
case "TSIntersectionType":
|
|
57
|
-
seen.push(...type.types);
|
|
58
|
-
break;
|
|
59
|
-
case "TSTupleType":
|
|
60
|
-
for (const element of type.elementTypes) {
|
|
61
|
-
seen.push(tupleElementType(element));
|
|
62
|
-
}
|
|
63
|
-
break;
|
|
64
|
-
case "TSTypeOperator":
|
|
65
|
-
seen.push(type.typeAnnotation);
|
|
66
|
-
break;
|
|
67
|
-
case "TSArrayType":
|
|
68
|
-
seen.push(type.elementType);
|
|
69
|
-
break;
|
|
70
|
-
default:
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Precondition violations are defects by doctrine: thrown directly they escape
|
|
78
|
-
* the Cause, invisible to telemetry and supervisors.
|
|
79
|
-
*/
|
|
80
|
-
export const preferDieForPreconditionDefectsRule = defineRule({
|
|
81
|
-
meta: {
|
|
82
|
-
type: "problem",
|
|
83
|
-
docs: {
|
|
84
|
-
description: "In Effect/Either-returning functions, raise precondition defects with Effect.die instead of a bare throw so they travel inside the Cause.",
|
|
85
|
-
},
|
|
86
|
-
messages: {
|
|
87
|
-
bareThrow: "This bare throw escapes the Effect `Cause`. Raise the tagged defect with `Effect.die(new ...)` (or reclassify the case as a typed failure on the error channel) so supervisors and telemetry observe it.",
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
createOnce(context) {
|
|
91
|
-
const check = (node) => {
|
|
92
|
-
const ancestors = ancestorsOf(context.sourceCode, node);
|
|
93
|
-
for (let index = ancestors.length - 1; index >= 0; index--) {
|
|
94
|
-
const current = ancestors[index];
|
|
95
|
-
if (current.type === "Program")
|
|
96
|
-
break;
|
|
97
|
-
if (current.type === "FunctionDeclaration" ||
|
|
98
|
-
current.type === "FunctionExpression" ||
|
|
99
|
-
current.type === "ArrowFunctionExpression") {
|
|
100
|
-
if (returnsEffectOrFailChannel(current))
|
|
101
|
-
context.report({ node, messageId: "bareThrow" });
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
return { before() {
|
|
107
|
-
if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
|
|
108
|
-
return false;
|
|
109
|
-
},
|
|
110
|
-
ThrowStatement: check };
|
|
111
|
-
},
|
|
112
|
-
});
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
import { ancestorsOf } from "../../shared/ancestors.js";
|
|
3
|
-
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$|\/test\//u;
|
|
4
|
-
const LADDER_THRESHOLD = 3;
|
|
5
|
-
/** Whether this call is an Effect combinator chained in the flatMap/map ladder family.
|
|
6
|
-
*
|
|
7
|
-
* @param {ESTree.CallExpression} node - The candidate call expression.
|
|
8
|
-
* @returns {boolean} True when the callee is an Effect flatMap/map-family combinator.
|
|
9
|
-
*/
|
|
10
|
-
function isEffectLadderCombinator(node) {
|
|
11
|
-
const callee = node.callee;
|
|
12
|
-
if (callee.type !== "MemberExpression" || callee.computed)
|
|
13
|
-
return false;
|
|
14
|
-
if (callee.object.type !== "Identifier" || callee.object.name !== "Effect")
|
|
15
|
-
return false;
|
|
16
|
-
const name = callee.property.type === "Identifier" ? callee.property.name : "";
|
|
17
|
-
return name === "flatMap" || name === "andThen" || name === "tap";
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Long Effect.flatMap ladders read as callback pyramids; Effect.gen renders the
|
|
21
|
-
* same program as straight-line validation.
|
|
22
|
-
*/
|
|
23
|
-
export const preferEffectGenForGuardLaddersRule = defineRule({
|
|
24
|
-
meta: {
|
|
25
|
-
type: "suggestion",
|
|
26
|
-
docs: {
|
|
27
|
-
description: "Suggest Effect.gen when a function chains several Effect.flatMap/andThen/tap combinators instead of reading as straight-line code.",
|
|
28
|
-
},
|
|
29
|
-
messages: {
|
|
30
|
-
ladder: "This function chains {{count}} Effect ladder combinators. Rewrite with `Effect.gen` + `yield*` so the guard sequence reads top-to-bottom.",
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
createOnce(context) {
|
|
34
|
-
const counts = new Map();
|
|
35
|
-
const reported = new Set();
|
|
36
|
-
const enclosingFunction = (node) => {
|
|
37
|
-
const ancestors = ancestorsOf(context.sourceCode, node);
|
|
38
|
-
for (let index = ancestors.length - 1; index >= 0; index--) {
|
|
39
|
-
const current = ancestors[index];
|
|
40
|
-
if (current.type === "Program")
|
|
41
|
-
break;
|
|
42
|
-
if (current.type === "FunctionDeclaration" ||
|
|
43
|
-
current.type === "FunctionExpression" ||
|
|
44
|
-
current.type === "ArrowFunctionExpression") {
|
|
45
|
-
return current;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return undefined;
|
|
49
|
-
};
|
|
50
|
-
return {
|
|
51
|
-
before() {
|
|
52
|
-
if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
|
|
53
|
-
return false;
|
|
54
|
-
counts.clear();
|
|
55
|
-
reported.clear();
|
|
56
|
-
},
|
|
57
|
-
CallExpression(node) {
|
|
58
|
-
if (!isEffectLadderCombinator(node))
|
|
59
|
-
return;
|
|
60
|
-
const owner = enclosingFunction(node);
|
|
61
|
-
if (owner === undefined)
|
|
62
|
-
return;
|
|
63
|
-
const next = (counts.get(owner) ?? 0) + 1;
|
|
64
|
-
counts.set(owner, next);
|
|
65
|
-
if (next >= LADDER_THRESHOLD && !reported.has(owner)) {
|
|
66
|
-
reported.add(owner);
|
|
67
|
-
context.report({ node: owner, messageId: "ladder", data: { count: String(next) } });
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
},
|
|
72
|
-
});
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
import { ancestorsOf } from "../../shared/ancestors.js";
|
|
3
|
-
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$|\/test\//u;
|
|
4
|
-
const EQUALITY_OPERATORS = new Set(["==", "===", "!=", "!=="]);
|
|
5
|
-
/**
|
|
6
|
-
* Whether the expression is a literal operand (literal or brace-less template).
|
|
7
|
-
*
|
|
8
|
-
* @param {ESTree.Node} node - The candidate expression node.
|
|
9
|
-
* @returns {boolean} True when the node is literal-valued.
|
|
10
|
-
*/
|
|
11
|
-
function isLiteral(node) {
|
|
12
|
-
if (node.type === "Literal")
|
|
13
|
-
return true;
|
|
14
|
-
return node.type === "TemplateLiteral" && node.expressions.length === 0;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* The compared operand of a literal equality test, rendered to source text.
|
|
18
|
-
*
|
|
19
|
-
* @param {import("@oxlint/plugins").SourceCode} sourceCode - The rule's source-code accessor.
|
|
20
|
-
* @param {ESTree.Expression} test - The conditional's test expression.
|
|
21
|
-
* @returns {string | undefined} Source text of the non-literal side, or undefined.
|
|
22
|
-
*/
|
|
23
|
-
function comparedValue(sourceCode, test) {
|
|
24
|
-
if (test.type !== "BinaryExpression")
|
|
25
|
-
return undefined;
|
|
26
|
-
if (!EQUALITY_OPERATORS.has(test.operator))
|
|
27
|
-
return undefined;
|
|
28
|
-
if (isLiteral(test.left))
|
|
29
|
-
return sourceCode.getText(test.right);
|
|
30
|
-
if (isLiteral(test.right))
|
|
31
|
-
return sourceCode.getText(test.left);
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
/** Chained literal ternaries over one value re-implement `Match` without exhaustiveness checking. */
|
|
35
|
-
export const preferEffectMatchRule = defineRule({
|
|
36
|
-
meta: {
|
|
37
|
-
type: "problem",
|
|
38
|
-
docs: {
|
|
39
|
-
description: "Prefer Match from effect for chained literal ternaries over the same value; the compiler then checks exhaustiveness instead of falling through silently.",
|
|
40
|
-
},
|
|
41
|
-
messages: {
|
|
42
|
-
preferMatch: "This ternary chain re-implements pattern matching over literal comparisons. Use `Match.value` (or `Match.discriminate`) from `effect/Match` so exhaustiveness is checked by the compiler.",
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
createOnce(context) {
|
|
46
|
-
return {
|
|
47
|
-
before() {
|
|
48
|
-
if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
|
|
49
|
-
return false;
|
|
50
|
-
},
|
|
51
|
-
ConditionalExpression(node) {
|
|
52
|
-
const parent = ancestorsOf(context.sourceCode, node)[0];
|
|
53
|
-
if (parent?.type === "ConditionalExpression") {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const compared = comparedValue(context.sourceCode, node.test);
|
|
57
|
-
if (compared === undefined)
|
|
58
|
-
return;
|
|
59
|
-
let alternate = node.alternate;
|
|
60
|
-
let literalChecks = 1;
|
|
61
|
-
while (alternate.type === "ConditionalExpression") {
|
|
62
|
-
const alternateCompared = comparedValue(context.sourceCode, alternate.test);
|
|
63
|
-
if (alternateCompared !== compared)
|
|
64
|
-
return;
|
|
65
|
-
literalChecks += 1;
|
|
66
|
-
alternate = alternate.alternate;
|
|
67
|
-
}
|
|
68
|
-
if (literalChecks > 1) {
|
|
69
|
-
context.report({ node, messageId: "preferMatch" });
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
},
|
|
74
|
-
});
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
3
|
-
function parameterAnnotation(parameter) {
|
|
4
|
-
if (parameter.type === "TSParameterProperty") {
|
|
5
|
-
return parameterAnnotation(parameter.parameter);
|
|
6
|
-
}
|
|
7
|
-
if (parameter.type === "RestElement") {
|
|
8
|
-
return parameter.typeAnnotation ?? parameterAnnotation(parameter.argument);
|
|
9
|
-
}
|
|
10
|
-
if (parameter.type === "AssignmentPattern") {
|
|
11
|
-
return parameter.typeAnnotation ?? parameter.left.typeAnnotation;
|
|
12
|
-
}
|
|
13
|
-
return parameter.typeAnnotation;
|
|
14
|
-
}
|
|
15
|
-
/** Exported predicates should be typed P.Predicate<T> so they compose. */
|
|
16
|
-
export const preferEffectPredicateOverBooleanFunctionRule = defineRule({
|
|
17
|
-
meta: {
|
|
18
|
-
type: "problem",
|
|
19
|
-
docs: {
|
|
20
|
-
description: "Prefer P.Predicate<T> over plain (value: T) => boolean for exported predicates so they compose with P.and/or/mapInput, Array.filter, and Option refinement.",
|
|
21
|
-
},
|
|
22
|
-
messages: {
|
|
23
|
-
booleanPredicateReturn: "Export this predicate as P.Predicate<{{type}}> so it composes with P.and/or/mapInput, Array.filter, and Option refinement.",
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
createOnce(context) {
|
|
27
|
-
const checkPredicate = (node) => {
|
|
28
|
-
if (node.returnType === null || node.returnType === undefined)
|
|
29
|
-
return;
|
|
30
|
-
const returnType = node.returnType.typeAnnotation;
|
|
31
|
-
if (returnType.type !== "TSBooleanKeyword")
|
|
32
|
-
return;
|
|
33
|
-
if (node.params.length !== 1)
|
|
34
|
-
return;
|
|
35
|
-
const firstParam = node.params[0];
|
|
36
|
-
if (firstParam === undefined)
|
|
37
|
-
return;
|
|
38
|
-
const annotation = parameterAnnotation(firstParam);
|
|
39
|
-
if (annotation === null || annotation === undefined)
|
|
40
|
-
return;
|
|
41
|
-
const type = annotation.typeAnnotation;
|
|
42
|
-
if (type.type === "TSUnknownKeyword")
|
|
43
|
-
return;
|
|
44
|
-
context.report({
|
|
45
|
-
node: returnType,
|
|
46
|
-
messageId: "booleanPredicateReturn",
|
|
47
|
-
data: { type: context.sourceCode.getText(type) },
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
return {
|
|
51
|
-
before() {
|
|
52
|
-
if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
|
|
53
|
-
return false;
|
|
54
|
-
},
|
|
55
|
-
ExportNamedDeclaration(node) {
|
|
56
|
-
const declaration = node.declaration;
|
|
57
|
-
if (declaration === null)
|
|
58
|
-
return;
|
|
59
|
-
if (declaration.type === "FunctionDeclaration") {
|
|
60
|
-
checkPredicate(declaration);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (declaration.type !== "VariableDeclaration")
|
|
64
|
-
return;
|
|
65
|
-
for (const declarator of declaration.declarations) {
|
|
66
|
-
const init = declarator.init;
|
|
67
|
-
if (init === null || init === undefined || init.type !== "ArrowFunctionExpression") {
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
checkPredicate(init);
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
},
|
|
75
|
-
});
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
import { childNodes } from "../../shared/child-nodes.js";
|
|
3
|
-
import { readField } from "../../shared/structural.js";
|
|
4
|
-
const PREDICATE_NAME = /^is[A-Z]/u;
|
|
5
|
-
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
6
|
-
/** True for a logical chain (>= 2 operands) whose every leaf is a domain-predicate call.
|
|
7
|
-
*
|
|
8
|
-
* @param {ESTree.Expression} expression - The guard test expression.
|
|
9
|
-
* @returns {boolean} True when the chain is composed of domain predicates only.
|
|
10
|
-
*/
|
|
11
|
-
function isPredicateChain(expression) {
|
|
12
|
-
if (expression.type !== "LogicalExpression")
|
|
13
|
-
return false;
|
|
14
|
-
return chainLeaf(expression.left) && chainLeaf(expression.right);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Whether a leaf expression is a domain predicate call, not an Option combinator.
|
|
18
|
-
*
|
|
19
|
-
* @param {ESTree.Expression} expression - The leaf expression to test.
|
|
20
|
-
* @returns {boolean} True when the callee matches the domain predicate naming scheme.
|
|
21
|
-
*/
|
|
22
|
-
function chainLeaf(expression) {
|
|
23
|
-
if (expression.type === "LogicalExpression") {
|
|
24
|
-
return chainLeaf(expression.left) && chainLeaf(expression.right);
|
|
25
|
-
}
|
|
26
|
-
if (expression.type === "ParenthesizedExpression") {
|
|
27
|
-
return chainLeaf(expression.expression);
|
|
28
|
-
}
|
|
29
|
-
if (expression.type !== "CallExpression")
|
|
30
|
-
return false;
|
|
31
|
-
const callee = expression.callee;
|
|
32
|
-
if (callee.type === "MemberExpression" &&
|
|
33
|
-
callee.object.type === "Identifier" &&
|
|
34
|
-
callee.object.name === "Option") {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
if (callee.type === "Identifier")
|
|
38
|
-
return PREDICATE_NAME.test(callee.name);
|
|
39
|
-
return (callee.type === "MemberExpression" &&
|
|
40
|
-
callee.property.type === "Identifier" &&
|
|
41
|
-
PREDICATE_NAME.test(callee.property.name));
|
|
42
|
-
}
|
|
43
|
-
/** True when the subtree produces an Option.none()/Option.some(...) result.
|
|
44
|
-
*
|
|
45
|
-
* @param {ESTree.Node | null | undefined} node - The subtree root to scan.
|
|
46
|
-
* @returns {boolean} True when an Option constructor call appears in the subtree.
|
|
47
|
-
*/
|
|
48
|
-
function containsOptionResult(node) {
|
|
49
|
-
if (node === null || node === undefined)
|
|
50
|
-
return false;
|
|
51
|
-
if (node.type === "CallExpression" &&
|
|
52
|
-
node.callee.type === "MemberExpression" &&
|
|
53
|
-
node.callee.object.type === "Identifier" &&
|
|
54
|
-
node.callee.object.name === "Option" &&
|
|
55
|
-
node.callee.property.type === "Identifier" &&
|
|
56
|
-
(node.callee.property.name === "none" || node.callee.property.name === "some")) {
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
return childNodes(node).some(containsOptionResult);
|
|
60
|
-
}
|
|
61
|
-
/** Inline chains of domain predicates guarding Options should be named Predicates. */
|
|
62
|
-
export const preferNamedGuardPredicateRule = defineRule({
|
|
63
|
-
meta: {
|
|
64
|
-
type: "problem",
|
|
65
|
-
docs: {
|
|
66
|
-
description: "Require guards built from chained domain predicates to be extracted into a named P.Predicate and lifted through Option.liftPredicate so the guard composes and carries a name.",
|
|
67
|
-
},
|
|
68
|
-
messages: {
|
|
69
|
-
namedGuardPredicate: "This guard anonymously chains domain predicates. Extract a named `P.Predicate` (composed via P.and/P.or/P.not) and lift the value with `Option.liftPredicate` so the guard is reusable, testable and self-describing.",
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
createOnce(context) {
|
|
73
|
-
const checkGuard = (test, branches) => {
|
|
74
|
-
if (!isPredicateChain(test))
|
|
75
|
-
return;
|
|
76
|
-
if (!branches.some((branch) => containsOptionResult(branch)))
|
|
77
|
-
return;
|
|
78
|
-
context.report({ node: test, messageId: "namedGuardPredicate" });
|
|
79
|
-
};
|
|
80
|
-
return {
|
|
81
|
-
before() {
|
|
82
|
-
if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
|
|
83
|
-
return false;
|
|
84
|
-
},
|
|
85
|
-
ConditionalExpression(node) {
|
|
86
|
-
checkGuard(node.test, [node.consequent, node.alternate]);
|
|
87
|
-
},
|
|
88
|
-
IfStatement(node) {
|
|
89
|
-
checkGuard(node.test, [node.consequent, node.alternate]);
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
},
|
|
93
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
import { childNodes } from "../../shared/child-nodes.js";
|
|
3
|
-
import { readField } from "../../shared/structural.js";
|
|
4
|
-
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
5
|
-
/**
|
|
6
|
-
* Count Option.none() returns in this function's own body. Nested scopes belong to
|
|
7
|
-
* themselves, and loop bodies hold algorithmic exits rather than guard scatters.
|
|
8
|
-
*
|
|
9
|
-
* @param {ESTree.Node} body - The function body to walk.
|
|
10
|
-
* @returns {number} Number of direct `Option.none()` return exits.
|
|
11
|
-
*/
|
|
12
|
-
function countDirectNoneReturns(body) {
|
|
13
|
-
let count = 0;
|
|
14
|
-
const visit = (node) => {
|
|
15
|
-
if (node.type === "ArrowFunctionExpression" ||
|
|
16
|
-
node.type === "FunctionExpression" ||
|
|
17
|
-
node.type === "FunctionDeclaration")
|
|
18
|
-
return;
|
|
19
|
-
if (node.type === "ForStatement" ||
|
|
20
|
-
node.type === "ForInStatement" ||
|
|
21
|
-
node.type === "ForOfStatement" ||
|
|
22
|
-
node.type === "WhileStatement" ||
|
|
23
|
-
node.type === "DoWhileStatement") {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
if (node.type !== "ReturnStatement")
|
|
27
|
-
return void 0;
|
|
28
|
-
const argument = node.argument;
|
|
29
|
-
if (argument?.type === "CallExpression" &&
|
|
30
|
-
argument.callee.type === "MemberExpression" &&
|
|
31
|
-
argument.callee.object.type === "Identifier" &&
|
|
32
|
-
argument.callee.object.name === "Option" &&
|
|
33
|
-
argument.callee.property.type === "Identifier" &&
|
|
34
|
-
argument.callee.property.name === "none")
|
|
35
|
-
count += 1;
|
|
36
|
-
for (const child of childNodes(node))
|
|
37
|
-
visit(child);
|
|
38
|
-
};
|
|
39
|
-
visit(body);
|
|
40
|
-
return count;
|
|
41
|
-
}
|
|
42
|
-
/** Guard-gauntlets over Option should compose into liftPredicate/filter pipelines. */
|
|
43
|
-
export const preferOptionPipelineRule = defineRule({
|
|
44
|
-
meta: {
|
|
45
|
-
type: "problem",
|
|
46
|
-
docs: {
|
|
47
|
-
description: "Require Option-returning functions to reject through composed pipelines (named Predicates lifted via Option.liftPredicate / narrowed via Option.filter) instead of scattering multiple `return Option.none()` guard exits through the body.",
|
|
48
|
-
},
|
|
49
|
-
messages: {
|
|
50
|
-
preferPipeline: "This Option-returning function rejects through {{count}} scattered `Option.none()` guards. Extract named Predicates and compose them via pipe + Option.liftPredicate / Option.filter so the happy path reads as one pipeline.",
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
createOnce(context) {
|
|
54
|
-
const check = (node) => {
|
|
55
|
-
const returnType = node.returnType?.typeAnnotation;
|
|
56
|
-
if (returnType === null || returnType === undefined)
|
|
57
|
-
return;
|
|
58
|
-
if (returnType.type !== "TSTypeReference")
|
|
59
|
-
return;
|
|
60
|
-
const typeName = returnType.typeName;
|
|
61
|
-
const declaresOption = typeName.type === "Identifier"
|
|
62
|
-
? typeName.name === "Option"
|
|
63
|
-
: typeName.type === "TSQualifiedName" &&
|
|
64
|
-
typeName.left.type === "Identifier" &&
|
|
65
|
-
typeName.left.name === "Option" &&
|
|
66
|
-
typeName.right.type === "Identifier" &&
|
|
67
|
-
typeName.right.name === "Option";
|
|
68
|
-
if (!declaresOption)
|
|
69
|
-
return;
|
|
70
|
-
if (node.body === null || node.body === undefined)
|
|
71
|
-
return;
|
|
72
|
-
const count = countDirectNoneReturns(node.body);
|
|
73
|
-
if (count < 2)
|
|
74
|
-
return;
|
|
75
|
-
context.report({ node, messageId: "preferPipeline", data: { count: String(count) } });
|
|
76
|
-
};
|
|
77
|
-
return {
|
|
78
|
-
before() {
|
|
79
|
-
if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
|
|
80
|
-
return false;
|
|
81
|
-
},
|
|
82
|
-
ArrowFunctionExpression: check,
|
|
83
|
-
FunctionExpression: check,
|
|
84
|
-
FunctionDeclaration: check,
|
|
85
|
-
};
|
|
86
|
-
},
|
|
87
|
-
});
|