@autotelic/plumb 0.3.1 → 0.4.0
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/dist/effect/index.d.ts +3 -0
- package/dist/effect/index.js +56 -0
- package/dist/effect/rules/guarded-op-must-return-effect.d.ts +6 -0
- package/dist/effect/rules/guarded-op-must-return-effect.js +235 -0
- package/dist/effect/rules/guarded-op-must-return-option.d.ts +2 -0
- package/dist/effect/rules/guarded-op-must-return-option.js +88 -0
- package/dist/effect/rules/no-cascading-layer-provide.d.ts +6 -0
- package/dist/effect/rules/no-cascading-layer-provide.js +73 -0
- package/dist/effect/rules/no-decode-unknown-option.d.ts +7 -0
- package/dist/effect/rules/no-decode-unknown-option.js +34 -0
- package/dist/effect/rules/no-direct-browser-storage.d.ts +2 -0
- package/dist/effect/rules/no-direct-browser-storage.js +88 -0
- package/dist/effect/rules/no-direct-fetch.d.ts +2 -0
- package/dist/effect/rules/no-direct-fetch.js +37 -0
- package/dist/effect/rules/no-manual-field-guards.d.ts +6 -0
- package/dist/effect/rules/no-manual-field-guards.js +129 -0
- package/dist/effect/rules/no-nested-layer-provide.d.ts +2 -0
- package/dist/effect/rules/no-nested-layer-provide.js +50 -0
- package/dist/effect/rules/no-schema-class-modeling.d.ts +2 -0
- package/dist/effect/rules/no-schema-class-modeling.js +52 -0
- package/dist/effect/rules/no-service-constructor-imports.d.ts +2 -0
- package/dist/effect/rules/no-service-constructor-imports.js +42 -0
- package/dist/effect/rules/no-silent-error-swallow.d.ts +2 -0
- package/dist/effect/rules/no-silent-error-swallow.js +95 -0
- package/dist/effect/rules/no-static-effect-service-forwarders.d.ts +6 -0
- package/dist/effect/rules/no-static-effect-service-forwarders.js +222 -0
- package/dist/effect/rules/no-try-catch.d.ts +2 -0
- package/dist/effect/rules/no-try-catch.js +30 -0
- package/dist/effect/rules/no-unguarded-json-parse.d.ts +5 -0
- package/dist/effect/rules/no-unguarded-json-parse.js +200 -0
- package/dist/effect/rules/option-core-needs-effect-public.d.ts +5 -0
- package/dist/effect/rules/option-core-needs-effect-public.js +76 -0
- package/dist/effect/rules/prefer-die-for-precondition-defects.d.ts +5 -0
- package/dist/effect/rules/prefer-die-for-precondition-defects.js +112 -0
- package/dist/effect/rules/prefer-effect-gen-for-guard-ladders.d.ts +5 -0
- package/dist/effect/rules/prefer-effect-gen-for-guard-ladders.js +72 -0
- package/dist/effect/rules/prefer-effect-match.d.ts +2 -0
- package/dist/effect/rules/prefer-effect-match.js +74 -0
- package/dist/effect/rules/prefer-effect-predicate-over-boolean-function.d.ts +2 -0
- package/dist/effect/rules/prefer-effect-predicate-over-boolean-function.js +75 -0
- package/dist/effect/rules/prefer-named-guard-predicate.d.ts +2 -0
- package/dist/effect/rules/prefer-named-guard-predicate.js +93 -0
- package/dist/effect/rules/prefer-option-pipeline.d.ts +2 -0
- package/dist/effect/rules/prefer-option-pipeline.js +87 -0
- package/dist/effect/rules/prefer-ordering-match.d.ts +2 -0
- package/dist/effect/rules/prefer-ordering-match.js +135 -0
- package/dist/effect/rules/prefer-tagged-enum.d.ts +2 -0
- package/dist/effect/rules/prefer-tagged-enum.js +66 -0
- package/dist/effect/rules/require-schema-type-derivation.d.ts +7 -0
- package/dist/effect/rules/require-schema-type-derivation.js +80 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +104 -0
- package/dist/meta/index.d.ts +7 -0
- package/{src/meta/index.ts → dist/meta/index.js} +13 -16
- package/dist/meta/rules/no-disable-directives.d.ts +6 -0
- package/dist/meta/rules/no-disable-directives.js +35 -0
- package/dist/meta/rules/no-manual-ancestor-walks.d.ts +2 -0
- package/dist/meta/rules/no-manual-ancestor-walks.js +26 -0
- package/dist/meta/rules/prefer-before-file-scope.d.ts +2 -0
- package/dist/meta/rules/prefer-before-file-scope.js +57 -0
- package/dist/meta/rules/require-create-once.d.ts +2 -0
- package/dist/meta/rules/require-create-once.js +51 -0
- package/dist/meta/rules/require-rule-tester.d.ts +2 -0
- package/dist/meta/rules/require-rule-tester.js +50 -0
- package/dist/rules/no-anonymous-wide-tuples.d.ts +7 -0
- package/dist/rules/no-anonymous-wide-tuples.js +34 -0
- package/dist/rules/no-barrel-export-star.d.ts +2 -0
- package/dist/rules/no-barrel-export-star.js +26 -0
- package/dist/rules/no-boolean-field-signals.d.ts +2 -0
- package/dist/rules/no-boolean-field-signals.js +279 -0
- package/dist/rules/no-builtin-throws.d.ts +6 -0
- package/dist/rules/no-builtin-throws.js +74 -0
- package/dist/rules/no-chained-type-assertions.d.ts +2 -0
- package/dist/rules/no-chained-type-assertions.js +54 -0
- package/dist/rules/no-conditional-empty-object-spread.d.ts +2 -0
- package/dist/rules/no-conditional-empty-object-spread.js +36 -0
- package/dist/rules/no-duplicated-literal-union.d.ts +6 -0
- package/dist/rules/no-duplicated-literal-union.js +62 -0
- package/dist/rules/no-exported-mutable-state.d.ts +7 -0
- package/dist/rules/no-exported-mutable-state.js +104 -0
- package/dist/rules/no-generic-export-names.d.ts +2 -0
- package/dist/rules/no-generic-export-names.js +141 -0
- package/dist/rules/no-impossible-branch-throw.d.ts +2 -0
- package/dist/rules/no-impossible-branch-throw.js +51 -0
- package/dist/rules/no-known-value-widening.d.ts +2 -0
- package/dist/rules/no-known-value-widening.js +176 -0
- package/dist/rules/no-module-mocking.d.ts +2 -0
- package/dist/rules/no-module-mocking.js +90 -0
- package/dist/rules/no-multiple-function-params.d.ts +2 -0
- package/dist/rules/no-multiple-function-params.js +155 -0
- package/dist/rules/no-mutable-environment-capture.d.ts +7 -0
- package/dist/rules/no-mutable-environment-capture.js +134 -0
- package/dist/rules/no-nondeterministic-core.d.ts +6 -0
- package/dist/rules/no-nondeterministic-core.js +63 -0
- package/dist/rules/no-object-parameters.d.ts +2 -0
- package/dist/rules/no-object-parameters.js +95 -0
- package/dist/rules/no-optional-function-parameters.d.ts +7 -0
- package/dist/rules/no-optional-function-parameters.js +44 -0
- package/dist/rules/no-product-of-state-booleans.d.ts +2 -0
- package/dist/rules/no-product-of-state-booleans.js +79 -0
- package/dist/rules/no-redundant-derived-field.d.ts +6 -0
- package/dist/rules/no-redundant-derived-field.js +194 -0
- package/dist/rules/no-reflect-apply.d.ts +2 -0
- package/dist/rules/no-reflect-apply.js +29 -0
- package/dist/rules/no-reflect-get.d.ts +2 -0
- package/dist/rules/no-reflect-get.js +29 -0
- package/dist/rules/no-reinterpret-cast.d.ts +2 -0
- package/dist/rules/no-reinterpret-cast.js +68 -0
- package/dist/rules/no-runtime-typeof.d.ts +2 -0
- package/dist/rules/no-runtime-typeof.js +54 -0
- package/dist/rules/no-sentinel-comparison-union.d.ts +2 -0
- package/dist/rules/no-sentinel-comparison-union.js +139 -0
- package/dist/rules/no-shape-in-symbol-names.d.ts +2 -0
- package/dist/rules/no-shape-in-symbol-names.js +39 -0
- package/dist/rules/no-single-use-private-functions.d.ts +17 -0
- package/dist/rules/no-single-use-private-functions.js +419 -0
- package/dist/rules/no-stacked-jsdoc-blocks.d.ts +2 -0
- package/dist/rules/no-stacked-jsdoc-blocks.js +50 -0
- package/dist/rules/no-stray-inline-comments.d.ts +2 -0
- package/dist/rules/no-stray-inline-comments.js +74 -0
- package/dist/rules/no-swappable-primitive-params.d.ts +2 -0
- package/dist/rules/no-swappable-primitive-params.js +96 -0
- package/dist/rules/no-tag-ladder-assertions.d.ts +6 -0
- package/dist/rules/no-tag-ladder-assertions.js +63 -0
- package/dist/rules/no-transposed-field-reads.d.ts +8 -0
- package/dist/rules/no-transposed-field-reads.js +101 -0
- package/dist/rules/no-unit-return-validators.d.ts +2 -0
- package/dist/rules/no-unit-return-validators.js +64 -0
- package/dist/rules/no-unknown-parameters.d.ts +2 -0
- package/dist/rules/no-unknown-parameters.js +82 -0
- package/dist/rules/no-unknown-returns.d.ts +2 -0
- package/dist/rules/no-unknown-returns.js +86 -0
- package/dist/rules/no-unknown-type-aliases.d.ts +2 -0
- package/dist/rules/no-unknown-type-aliases.js +64 -0
- package/dist/rules/no-unsafe-dictionary-type.d.ts +2 -0
- package/dist/rules/no-unsafe-dictionary-type.js +116 -0
- package/dist/rules/no-vague-test-filenames.d.ts +2 -0
- package/dist/rules/no-vague-test-filenames.js +61 -0
- package/dist/rules/no-widen-then-assert.d.ts +2 -0
- package/dist/rules/no-widen-then-assert.js +268 -0
- package/dist/rules/prefer-payload-brand.d.ts +2 -0
- package/dist/rules/prefer-payload-brand.js +57 -0
- package/dist/rules/prefer-property-tests.d.ts +5 -0
- package/dist/rules/prefer-property-tests.js +39 -0
- package/dist/rules/require-canonical-stringify-for-identity.d.ts +8 -0
- package/dist/rules/require-canonical-stringify-for-identity.js +72 -0
- package/dist/rules/require-deprecated-tag-for-legacy-comments.d.ts +2 -0
- package/dist/rules/require-deprecated-tag-for-legacy-comments.js +34 -0
- package/dist/rules/require-exhaustive-tag-switch.d.ts +7 -0
- package/dist/rules/require-exhaustive-tag-switch.js +34 -0
- package/dist/rules/require-fc-block-predicate.d.ts +2 -0
- package/dist/rules/require-fc-block-predicate.js +37 -0
- package/dist/rules/require-jsdoc-on-exported.d.ts +2 -0
- package/dist/rules/require-jsdoc-on-exported.js +66 -0
- package/dist/rules/require-published-order.d.ts +2 -0
- package/dist/rules/require-published-order.js +102 -0
- package/dist/rules/require-safety-comment-for-type-assertion.d.ts +2 -0
- package/dist/rules/require-safety-comment-for-type-assertion.js +53 -0
- package/dist/rules/require-sort-comparator.d.ts +7 -0
- package/dist/rules/require-sort-comparator.js +34 -0
- package/dist/rules/test-utils.d.ts +35 -0
- package/dist/rules/test-utils.js +53 -0
- package/{src/shared/ancestors.ts → dist/shared/ancestors.d.ts} +1 -4
- package/dist/shared/ancestors.js +19 -0
- package/dist/shared/child-nodes.d.ts +12 -0
- package/dist/shared/child-nodes.js +26 -0
- package/dist/shared/dictionary-types.d.ts +55 -0
- package/dist/shared/dictionary-types.js +413 -0
- package/{src/shared/is-node.ts → dist/shared/is-node.d.ts} +2 -6
- package/dist/shared/is-node.js +10 -0
- package/dist/shared/lexical-type-parameters.d.ts +12 -0
- package/dist/shared/lexical-type-parameters.js +50 -0
- package/dist/shared/reflect-method.d.ts +15 -0
- package/dist/shared/reflect-method.js +32 -0
- package/{src/shared/rule-options.ts → dist/shared/rule-options.d.ts} +2 -7
- package/dist/shared/rule-options.js +12 -0
- package/{src/shared/structural.ts → dist/shared/structural.d.ts} +17 -44
- package/dist/shared/structural.js +40 -0
- package/{src/testing/index.ts → dist/testing/index.d.ts} +0 -1
- package/dist/testing/index.js +1 -0
- package/dist/testing/testable-rule.d.ts +38 -0
- package/dist/testing/testable-rule.js +70 -0
- package/package.json +7 -6
- package/src/effect/index.ts +0 -59
- package/src/effect/rules/guarded-op-must-return-effect.ts +0 -236
- package/src/effect/rules/guarded-op-must-return-option.ts +0 -97
- package/src/effect/rules/no-cascading-layer-provide.ts +0 -80
- package/src/effect/rules/no-decode-unknown-option.ts +0 -41
- package/src/effect/rules/no-direct-browser-storage.ts +0 -91
- package/src/effect/rules/no-direct-fetch.ts +0 -44
- package/src/effect/rules/no-manual-field-guards.ts +0 -144
- package/src/effect/rules/no-nested-layer-provide.ts +0 -51
- package/src/effect/rules/no-schema-class-modeling.ts +0 -59
- package/src/effect/rules/no-service-constructor-imports.ts +0 -50
- package/src/effect/rules/no-silent-error-swallow.ts +0 -99
- package/src/effect/rules/no-static-effect-service-forwarders.ts +0 -227
- package/src/effect/rules/no-try-catch.ts +0 -32
- package/src/effect/rules/no-unguarded-json-parse.ts +0 -211
- package/src/effect/rules/option-core-needs-effect-public.ts +0 -81
- package/src/effect/rules/prefer-die-for-precondition-defects.ts +0 -118
- package/src/effect/rules/prefer-effect-gen-for-guard-ladders.ts +0 -76
- package/src/effect/rules/prefer-effect-match.ts +0 -78
- package/src/effect/rules/prefer-effect-predicate-over-boolean-function.ts +0 -79
- package/src/effect/rules/prefer-named-guard-predicate.ts +0 -105
- package/src/effect/rules/prefer-option-pipeline.ts +0 -95
- package/src/effect/rules/prefer-ordering-match.ts +0 -152
- package/src/effect/rules/prefer-tagged-enum.ts +0 -68
- package/src/effect/rules/require-schema-type-derivation.ts +0 -83
- package/src/index.ts +0 -106
- package/src/meta/rules/no-disable-directives.ts +0 -38
- package/src/meta/rules/no-manual-ancestor-walks.ts +0 -27
- package/src/meta/rules/prefer-before-file-scope.ts +0 -57
- package/src/meta/rules/require-create-once.ts +0 -51
- package/src/meta/rules/require-rule-tester.ts +0 -57
- package/src/rules/no-anonymous-wide-tuples.ts +0 -38
- package/src/rules/no-barrel-export-star.ts +0 -30
- package/src/rules/no-boolean-field-signals.ts +0 -305
- package/src/rules/no-builtin-throws.ts +0 -83
- package/src/rules/no-chained-type-assertions.ts +0 -65
- package/src/rules/no-conditional-empty-object-spread.ts +0 -42
- package/src/rules/no-duplicated-literal-union.ts +0 -66
- package/src/rules/no-exported-mutable-state.ts +0 -111
- package/src/rules/no-generic-export-names.ts +0 -149
- package/src/rules/no-impossible-branch-throw.ts +0 -55
- package/src/rules/no-known-value-widening.ts +0 -225
- package/src/rules/no-module-mocking.ts +0 -95
- package/src/rules/no-multiple-function-params.ts +0 -192
- package/src/rules/no-nondeterministic-core.ts +0 -73
- package/src/rules/no-object-parameters.ts +0 -127
- package/src/rules/no-optional-function-parameters.ts +0 -49
- package/src/rules/no-product-of-state-booleans.ts +0 -80
- package/src/rules/no-redundant-derived-field.ts +0 -192
- package/src/rules/no-reflect-apply.ts +0 -32
- package/src/rules/no-reflect-get.ts +0 -32
- package/src/rules/no-reinterpret-cast.ts +0 -78
- package/src/rules/no-runtime-typeof.ts +0 -59
- package/src/rules/no-sentinel-comparison-union.ts +0 -148
- package/src/rules/no-shape-in-symbol-names.ts +0 -45
- package/src/rules/no-single-use-private-functions.ts +0 -329
- package/src/rules/no-stacked-jsdoc-blocks.ts +0 -65
- package/src/rules/no-stray-inline-comments.ts +0 -79
- package/src/rules/no-swappable-primitive-params.ts +0 -109
- package/src/rules/no-tag-ladder-assertions.ts +0 -71
- package/src/rules/no-transposed-field-reads.ts +0 -135
- package/src/rules/no-unit-return-validators.ts +0 -65
- package/src/rules/no-unknown-parameters.ts +0 -97
- package/src/rules/no-unknown-returns.ts +0 -120
- package/src/rules/no-unknown-type-aliases.ts +0 -70
- package/src/rules/no-unsafe-dictionary-type.ts +0 -132
- package/src/rules/no-vague-test-filenames.ts +0 -67
- package/src/rules/no-widen-then-assert.ts +0 -345
- package/src/rules/prefer-payload-brand.ts +0 -67
- package/src/rules/prefer-property-tests.ts +0 -43
- package/src/rules/require-canonical-stringify-for-identity.ts +0 -80
- package/src/rules/require-deprecated-tag-for-legacy-comments.ts +0 -45
- package/src/rules/require-exhaustive-tag-switch.ts +0 -42
- package/src/rules/require-fc-block-predicate.ts +0 -42
- package/src/rules/require-jsdoc-on-exported.ts +0 -74
- package/src/rules/require-published-order.ts +0 -109
- package/src/rules/require-safety-comment-for-type-assertion.ts +0 -61
- package/src/rules/require-sort-comparator.ts +0 -41
- package/src/rules/test-utils.ts +0 -68
- package/src/shared/child-nodes.ts +0 -27
- package/src/shared/dictionary-types.ts +0 -524
- package/src/shared/lexical-type-parameters.ts +0 -62
- package/src/shared/reflect-method.ts +0 -41
- package/src/testing/testable-rule.test.ts +0 -68
- package/src/testing/testable-rule.ts +0 -86
|
@@ -1,345 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
import type { ESTree, SourceCode, Variable } from "@oxlint/plugins";
|
|
3
|
-
|
|
4
|
-
import { ancestorsOf } from "../shared/ancestors.ts";
|
|
5
|
-
|
|
6
|
-
type BroadTypeKind = "top" | "object" | "record";
|
|
7
|
-
|
|
8
|
-
type KnownValueEvidence = {
|
|
9
|
-
readonly type: ESTree.TSType | null;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const functionBoundaryTypes = new Set([
|
|
13
|
-
"ArrowFunctionExpression",
|
|
14
|
-
"FunctionDeclaration",
|
|
15
|
-
"FunctionExpression",
|
|
16
|
-
"TSDeclareFunction",
|
|
17
|
-
"TSEmptyBodyFunctionExpression",
|
|
18
|
-
]);
|
|
19
|
-
|
|
20
|
-
function unwrapExpressionParentheses(expression: ESTree.Expression): ESTree.Expression {
|
|
21
|
-
let current = expression;
|
|
22
|
-
while (current.type === "ParenthesizedExpression") current = current.expression;
|
|
23
|
-
return current;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function unwrapTypeParentheses(type: ESTree.TSType): ESTree.TSType {
|
|
27
|
-
let current = type;
|
|
28
|
-
while (current.type === "TSParenthesizedType") current = current.typeAnnotation;
|
|
29
|
-
return current;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function typeReferenceName(type: ESTree.TSTypeReference): string | null {
|
|
33
|
-
return type.typeName.type === "Identifier" ? type.typeName.name : null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function isUnknownOrAnyType(type: ESTree.TSType): boolean {
|
|
37
|
-
const unwrapped = unwrapTypeParentheses(type);
|
|
38
|
-
return unwrapped.type === "TSUnknownKeyword" || unwrapped.type === "TSAnyKeyword";
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function isBroadRecordKeyType(type: ESTree.TSType): boolean {
|
|
42
|
-
const unwrapped = unwrapTypeParentheses(type);
|
|
43
|
-
if (
|
|
44
|
-
unwrapped.type === "TSStringKeyword" ||
|
|
45
|
-
unwrapped.type === "TSNumberKeyword" ||
|
|
46
|
-
unwrapped.type === "TSSymbolKeyword"
|
|
47
|
-
) {
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
if (unwrapped.type === "TSUnionType") return unwrapped.types.every(isBroadRecordKeyType);
|
|
51
|
-
return unwrapped.type === "TSTypeReference" && typeReferenceName(unwrapped) === "PropertyKey";
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function isBroadRecordType(type: ESTree.TSType): boolean {
|
|
55
|
-
const unwrapped = unwrapTypeParentheses(type);
|
|
56
|
-
|
|
57
|
-
if (unwrapped.type === "TSTypeReference") {
|
|
58
|
-
if (typeReferenceName(unwrapped) === "Readonly") {
|
|
59
|
-
const [inner] = unwrapped.typeArguments?.params ?? [];
|
|
60
|
-
return inner !== undefined && isBroadRecordType(inner);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (typeReferenceName(unwrapped) !== "Record") return false;
|
|
64
|
-
const parameters = unwrapped.typeArguments?.params ?? [];
|
|
65
|
-
return (
|
|
66
|
-
parameters.length === 2 &&
|
|
67
|
-
parameters[0] !== undefined &&
|
|
68
|
-
parameters[1] !== undefined &&
|
|
69
|
-
isBroadRecordKeyType(parameters[0]) &&
|
|
70
|
-
isUnknownOrAnyType(parameters[1])
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (unwrapped.type !== "TSTypeLiteral" || unwrapped.members.length !== 1) return false;
|
|
75
|
-
const [member] = unwrapped.members;
|
|
76
|
-
const [parameter] = member?.type === "TSIndexSignature" ? member.parameters : [];
|
|
77
|
-
return (
|
|
78
|
-
member?.type === "TSIndexSignature" &&
|
|
79
|
-
member.parameters.length === 1 &&
|
|
80
|
-
parameter !== undefined &&
|
|
81
|
-
isBroadRecordKeyType(parameter.typeAnnotation.typeAnnotation) &&
|
|
82
|
-
isUnknownOrAnyType(member.typeAnnotation.typeAnnotation)
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function broadTypeKind(type: ESTree.TSType): BroadTypeKind | null {
|
|
87
|
-
const unwrapped = unwrapTypeParentheses(type);
|
|
88
|
-
if (unwrapped.type === "TSUnknownKeyword" || unwrapped.type === "TSAnyKeyword") return "top";
|
|
89
|
-
if (unwrapped.type === "TSObjectKeyword") return "object";
|
|
90
|
-
return isBroadRecordType(unwrapped) ? "record" : null;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function assertedExpression(
|
|
94
|
-
node: ESTree.TSAsExpression | ESTree.TSTypeAssertion,
|
|
95
|
-
): ESTree.Expression {
|
|
96
|
-
return unwrapExpressionParentheses(node.expression);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function isDefinitelyObjectType(type: ESTree.TSType): boolean {
|
|
100
|
-
const unwrapped = unwrapTypeParentheses(type);
|
|
101
|
-
switch (unwrapped.type) {
|
|
102
|
-
case "TSArrayType":
|
|
103
|
-
case "TSConstructorType":
|
|
104
|
-
case "TSFunctionType":
|
|
105
|
-
case "TSMappedType":
|
|
106
|
-
case "TSObjectKeyword":
|
|
107
|
-
case "TSTupleType":
|
|
108
|
-
return true;
|
|
109
|
-
case "TSTypeLiteral":
|
|
110
|
-
return unwrapped.members.length > 0;
|
|
111
|
-
case "TSIntersectionType":
|
|
112
|
-
return unwrapped.types.every(isDefinitelyObjectType);
|
|
113
|
-
case "TSTypeOperator":
|
|
114
|
-
return unwrapped.operator === "readonly" && isDefinitelyObjectType(unwrapped.typeAnnotation);
|
|
115
|
-
default:
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function isDefinitelyNarrowerRecordType(type: ESTree.TSType): boolean {
|
|
121
|
-
const unwrapped = unwrapTypeParentheses(type);
|
|
122
|
-
if (unwrapped.type === "TSTypeLiteral") {
|
|
123
|
-
return unwrapped.members.some((member) => member.type !== "TSIndexSignature");
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (unwrapped.type !== "TSTypeReference") return false;
|
|
127
|
-
if (typeReferenceName(unwrapped) === "Readonly") {
|
|
128
|
-
const [inner] = unwrapped.typeArguments?.params ?? [];
|
|
129
|
-
return inner !== undefined && isDefinitelyNarrowerRecordType(inner);
|
|
130
|
-
}
|
|
131
|
-
if (typeReferenceName(unwrapped) !== "Record") return false;
|
|
132
|
-
|
|
133
|
-
const parameters = unwrapped.typeArguments?.params ?? [];
|
|
134
|
-
return (
|
|
135
|
-
parameters.length === 2 && parameters[1] !== undefined && !isUnknownOrAnyType(parameters[1])
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function functionBoundary(sourceCode: SourceCode, node: ESTree.Node): ESTree.Node | null {
|
|
140
|
-
const ancestors = ancestorsOf(sourceCode, node);
|
|
141
|
-
for (let index = ancestors.length - 1; index >= 0; index--) {
|
|
142
|
-
const current = ancestors[index]!;
|
|
143
|
-
if (current.type === "Program") break;
|
|
144
|
-
if (functionBoundaryTypes.has(current.type)) return current;
|
|
145
|
-
}
|
|
146
|
-
return null;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function resolvedVariableForIdentifier(
|
|
150
|
-
scopes: readonly {
|
|
151
|
-
readonly references: readonly {
|
|
152
|
-
readonly identifier: ESTree.Node;
|
|
153
|
-
readonly resolved: Variable | null;
|
|
154
|
-
}[];
|
|
155
|
-
}[],
|
|
156
|
-
identifier: ESTree.IdentifierReference,
|
|
157
|
-
): Variable | null {
|
|
158
|
-
for (const scope of scopes) {
|
|
159
|
-
const reference = scope.references.find(
|
|
160
|
-
(candidate) =>
|
|
161
|
-
candidate.identifier.start === identifier.start &&
|
|
162
|
-
candidate.identifier.end === identifier.end,
|
|
163
|
-
);
|
|
164
|
-
if (reference !== undefined) return reference.resolved;
|
|
165
|
-
}
|
|
166
|
-
return null;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function variableDeclarator(variable: Variable): ESTree.VariableDeclarator | null {
|
|
170
|
-
for (const definition of variable.defs) {
|
|
171
|
-
if (definition.type === "Variable" && definition.node.type === "VariableDeclarator") {
|
|
172
|
-
return definition.node;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return null;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function knownValueEvidence(
|
|
179
|
-
sourceCode: SourceCode,
|
|
180
|
-
expression: ESTree.Expression,
|
|
181
|
-
scopes: Parameters<typeof resolvedVariableForIdentifier>[0],
|
|
182
|
-
boundary: ESTree.Node | null,
|
|
183
|
-
visitedVariables: ReadonlySet<Variable>,
|
|
184
|
-
): KnownValueEvidence | null {
|
|
185
|
-
const unwrapped = unwrapExpressionParentheses(expression);
|
|
186
|
-
|
|
187
|
-
if (unwrapped.type === "TSAsExpression" || unwrapped.type === "TSTypeAssertion") {
|
|
188
|
-
if (broadTypeKind(unwrapped.typeAnnotation) !== null) return null;
|
|
189
|
-
return { type: unwrapped.typeAnnotation };
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (unwrapped.type === "Literal" || unwrapped.type === "TemplateLiteral") {
|
|
193
|
-
return { type: null };
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (
|
|
197
|
-
unwrapped.type === "ArrayExpression" ||
|
|
198
|
-
unwrapped.type === "ArrowFunctionExpression" ||
|
|
199
|
-
unwrapped.type === "ClassExpression" ||
|
|
200
|
-
unwrapped.type === "FunctionExpression" ||
|
|
201
|
-
unwrapped.type === "NewExpression" ||
|
|
202
|
-
unwrapped.type === "ObjectExpression"
|
|
203
|
-
) {
|
|
204
|
-
return { type: null };
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (unwrapped.type !== "Identifier") return null;
|
|
208
|
-
const variable = resolvedVariableForIdentifier(scopes, unwrapped);
|
|
209
|
-
if (variable === null || visitedVariables.has(variable)) return null;
|
|
210
|
-
|
|
211
|
-
const annotatedIdentifier = variable.identifiers.find(
|
|
212
|
-
(identifier) => identifier.typeAnnotation !== null && identifier.typeAnnotation !== undefined,
|
|
213
|
-
);
|
|
214
|
-
const annotation = annotatedIdentifier?.typeAnnotation?.typeAnnotation;
|
|
215
|
-
if (annotation !== undefined && annotatedIdentifier !== undefined) {
|
|
216
|
-
if (functionBoundary(sourceCode, annotatedIdentifier) !== boundary || broadTypeKind(annotation) !== null) {
|
|
217
|
-
return null;
|
|
218
|
-
}
|
|
219
|
-
return { type: annotation };
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
const declarator = variableDeclarator(variable);
|
|
223
|
-
const declaration = declarator === null ? null : ancestorsOf(sourceCode, declarator).at(-1);
|
|
224
|
-
if (
|
|
225
|
-
declarator === null ||
|
|
226
|
-
declaration === null ||
|
|
227
|
-
declaration?.type !== "VariableDeclaration" ||
|
|
228
|
-
declaration?.kind !== "const" ||
|
|
229
|
-
declarator.init === null ||
|
|
230
|
-
variable.references.some((reference) => reference.isWrite() && !reference.init) ||
|
|
231
|
-
functionBoundary(sourceCode, declarator) !== boundary
|
|
232
|
-
) {
|
|
233
|
-
return null;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
return knownValueEvidence(
|
|
237
|
-
sourceCode,
|
|
238
|
-
declarator.init,
|
|
239
|
-
scopes,
|
|
240
|
-
boundary,
|
|
241
|
-
new Set([...visitedVariables, variable]),
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/** Detect immutable local bindings that erase a known type and are later asserted back to a narrower type. */
|
|
246
|
-
export const noWidenThenAssertRule = defineRule({
|
|
247
|
-
meta: {
|
|
248
|
-
type: "problem",
|
|
249
|
-
docs: {
|
|
250
|
-
description:
|
|
251
|
-
"Disallow local const flows that explicitly widen a known value before asserting the widened binding to a narrower type.",
|
|
252
|
-
},
|
|
253
|
-
messages: {
|
|
254
|
-
widenThenAssert:
|
|
255
|
-
'Binding "{{name}}" discards type evidence and later recreates it with an assertion. Keep the precise type from initialization through use; parse boundary input once.',
|
|
256
|
-
},
|
|
257
|
-
},
|
|
258
|
-
createOnce(context) {
|
|
259
|
-
let scopes: Parameters<typeof resolvedVariableForIdentifier>[0] = [];
|
|
260
|
-
|
|
261
|
-
const checkAssertion = (node: ESTree.TSAsExpression | ESTree.TSTypeAssertion) => {
|
|
262
|
-
const expression = assertedExpression(node);
|
|
263
|
-
if (expression.type !== "Identifier") return;
|
|
264
|
-
|
|
265
|
-
const variable = resolvedVariableForIdentifier(scopes, expression);
|
|
266
|
-
if (variable === null) return;
|
|
267
|
-
|
|
268
|
-
const declarator = variableDeclarator(variable);
|
|
269
|
-
const declaration = declarator === null ? null : ancestorsOf(context.sourceCode, declarator).at(-1);
|
|
270
|
-
if (
|
|
271
|
-
declarator === null ||
|
|
272
|
-
declaration === null ||
|
|
273
|
-
declaration?.type !== "VariableDeclaration" ||
|
|
274
|
-
declaration?.kind !== "const" ||
|
|
275
|
-
declarator.id.type !== "Identifier" ||
|
|
276
|
-
declarator.init === null ||
|
|
277
|
-
variable.references.some((reference) => reference.isWrite() && !reference.init)
|
|
278
|
-
) {
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
const boundary = functionBoundary(context.sourceCode, declarator);
|
|
283
|
-
const declaredType = declarator.id.typeAnnotation?.typeAnnotation;
|
|
284
|
-
const initializerUnwrapped = unwrapExpressionParentheses(declarator.init);
|
|
285
|
-
const initializerAssertion =
|
|
286
|
-
initializerUnwrapped.type === "TSAsExpression" || initializerUnwrapped.type === "TSTypeAssertion"
|
|
287
|
-
? initializerUnwrapped
|
|
288
|
-
: null;
|
|
289
|
-
const initializerBroadKind =
|
|
290
|
-
initializerAssertion === null ? null : broadTypeKind(initializerAssertion.typeAnnotation);
|
|
291
|
-
const declaredBroadKind = declaredType === undefined ? null : broadTypeKind(declaredType);
|
|
292
|
-
const broadKind = declaredBroadKind ?? initializerBroadKind;
|
|
293
|
-
if (broadKind === null) return;
|
|
294
|
-
|
|
295
|
-
const originalExpression =
|
|
296
|
-
initializerAssertion !== null && initializerBroadKind !== null
|
|
297
|
-
? assertedExpression(initializerAssertion)
|
|
298
|
-
: declarator.init;
|
|
299
|
-
const evidence = knownValueEvidence(
|
|
300
|
-
context.sourceCode,
|
|
301
|
-
originalExpression,
|
|
302
|
-
scopes,
|
|
303
|
-
boundary,
|
|
304
|
-
new Set([variable]),
|
|
305
|
-
);
|
|
306
|
-
if (evidence === null) return;
|
|
307
|
-
|
|
308
|
-
if (node.start <= declarator.end || functionBoundary(context.sourceCode, node) !== boundary) {
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
const assertedType = node.typeAnnotation;
|
|
313
|
-
if (broadTypeKind(assertedType) !== null) return;
|
|
314
|
-
if (broadKind !== "top") {
|
|
315
|
-
const normalized = (type: ESTree.TSType): string =>
|
|
316
|
-
context.sourceCode.text.slice(type.start, type.end).replaceAll(/\s+/gu, "");
|
|
317
|
-
const sameSyntax =
|
|
318
|
-
evidence.type !== null &&
|
|
319
|
-
normalized(unwrapTypeParentheses(evidence.type)) ===
|
|
320
|
-
normalized(unwrapTypeParentheses(assertedType));
|
|
321
|
-
if (!sameSyntax) {
|
|
322
|
-
if (broadKind === "object") {
|
|
323
|
-
if (!isDefinitelyObjectType(assertedType)) return;
|
|
324
|
-
} else if (!isDefinitelyNarrowerRecordType(assertedType)) {
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
context.report({
|
|
331
|
-
node,
|
|
332
|
-
messageId: "widenThenAssert",
|
|
333
|
-
data: { name: expression.name },
|
|
334
|
-
});
|
|
335
|
-
};
|
|
336
|
-
|
|
337
|
-
return {
|
|
338
|
-
Program() {
|
|
339
|
-
scopes = context.sourceCode.scopeManager.scopes;
|
|
340
|
-
},
|
|
341
|
-
TSAsExpression: checkAssertion,
|
|
342
|
-
TSTypeAssertion: checkAssertion,
|
|
343
|
-
};
|
|
344
|
-
},
|
|
345
|
-
});
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
|
|
3
|
-
import type { ESTree } from "@oxlint/plugins";
|
|
4
|
-
|
|
5
|
-
/** True for a heritage clause referencing Brand.Brand (any ESTree spelling).
|
|
6
|
-
*
|
|
7
|
-
* @param {ESTree.TSTypeName | ESTree.Expression | ESTree.PrivateIdentifier} expression - Heritage clause expression.
|
|
8
|
-
* @returns {boolean} True when the expression is the Brand.Brand reference.
|
|
9
|
-
*/
|
|
10
|
-
function isBrandBrandReference(
|
|
11
|
-
expression: ESTree.TSTypeName | ESTree.Expression | ESTree.PrivateIdentifier,
|
|
12
|
-
): boolean {
|
|
13
|
-
if (expression.type === "TSQualifiedName") {
|
|
14
|
-
return (
|
|
15
|
-
expression.left.type === "Identifier" &&
|
|
16
|
-
expression.left.name === "Brand" &&
|
|
17
|
-
expression.right.type === "Identifier" &&
|
|
18
|
-
expression.right.name === "Brand"
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
if (expression.type === "MemberExpression") {
|
|
22
|
-
return (
|
|
23
|
-
expression.object.type === "Identifier" &&
|
|
24
|
-
expression.object.name === "Brand" &&
|
|
25
|
-
expression.property.type === "Identifier" &&
|
|
26
|
-
expression.property.name === "Brand"
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** Opaque brand interfaces hide their payload behind casts; carry the payload in the brand. */
|
|
33
|
-
export const preferPayloadBrandRule = defineRule({
|
|
34
|
-
meta: {
|
|
35
|
-
type: "problem",
|
|
36
|
-
docs: {
|
|
37
|
-
description:
|
|
38
|
-
"Prefer payload-carrying brands (type X = Base & Brand.Brand<\"X\">) over opaque brand interfaces so the payload stays recoverable without type assertions.",
|
|
39
|
-
},
|
|
40
|
-
messages: {
|
|
41
|
-
opaqueBrand:
|
|
42
|
-
"Opaque brand interface `{{name}}` hides its payload behind casts. Carry the payload in the brand instead: `type {{name}} = Base & Brand.Brand<\"{{name}}\">` with a cast-free `un{{name}}` accessor.",
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
createOnce(context) {
|
|
46
|
-
return {
|
|
47
|
-
Program(node) {
|
|
48
|
-
for (const statement of node.body) {
|
|
49
|
-
const declaration =
|
|
50
|
-
statement.type === "ExportNamedDeclaration" ||
|
|
51
|
-
statement.type === "ExportDefaultDeclaration"
|
|
52
|
-
? (statement.declaration ?? null)
|
|
53
|
-
: statement;
|
|
54
|
-
if (declaration?.type !== "TSInterfaceDeclaration") continue;
|
|
55
|
-
const heritages = declaration.extends ?? [];
|
|
56
|
-
if (heritages.length !== 1) continue;
|
|
57
|
-
if (!isBrandBrandReference(heritages[0]!.expression)) continue;
|
|
58
|
-
context.report({
|
|
59
|
-
node: declaration.id,
|
|
60
|
-
messageId: "opaqueBrand",
|
|
61
|
-
data: { name: declaration.id.name },
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
},
|
|
67
|
-
});
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
|
|
3
|
-
import type { ESTree } from "@oxlint/plugins";
|
|
4
|
-
|
|
5
|
-
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* We default to property-based testing: a test suite without fast-check only
|
|
9
|
-
* pins examples. Escape hatch is an explicit inline disable with a reason.
|
|
10
|
-
*/
|
|
11
|
-
export const preferPropertyTestsRule = defineRule({
|
|
12
|
-
meta: {
|
|
13
|
-
type: "suggestion",
|
|
14
|
-
docs: {
|
|
15
|
-
description:
|
|
16
|
-
"Require `fast-check` in every test file; suites that genuinely cannot use properties must disable this rule inline with a justification.",
|
|
17
|
-
},
|
|
18
|
-
messages: {
|
|
19
|
-
useFastCheck:
|
|
20
|
-
"No `fast-check` import: this suite only exercises hand-picked examples. Add property-based coverage (generate inputs, assert invariants), or disable this rule inline with a reason if the behavior is truly non-property-testable.",
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
createOnce(context) {
|
|
24
|
-
let program: ESTree.Program | null = null;
|
|
25
|
-
let sawFastCheck = false;
|
|
26
|
-
return {
|
|
27
|
-
before() {
|
|
28
|
-
if (!TEST_FILE.test(context.filename.replaceAll("\\", "/"))) return false;
|
|
29
|
-
},
|
|
30
|
-
Program(node) {
|
|
31
|
-
program = node;
|
|
32
|
-
},
|
|
33
|
-
ImportDeclaration(node) {
|
|
34
|
-
if (node.source.value === "fast-check") sawFastCheck = true;
|
|
35
|
-
},
|
|
36
|
-
"Program:exit"() {
|
|
37
|
-
if (!sawFastCheck && program !== null) {
|
|
38
|
-
context.report({ node: program, messageId: "useFastCheck" });
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
},
|
|
43
|
-
});
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
|
|
3
|
-
import type { ESTree } from "@oxlint/plugins";
|
|
4
|
-
import { ancestorsOf } from "../shared/ancestors.ts";
|
|
5
|
-
|
|
6
|
-
const COMPARISON_OPERATORS = new Set(["===", "!==", "==", "!="]);
|
|
7
|
-
const MAP_KEY_METHODS = new Set(["get", "has", "delete"]);
|
|
8
|
-
const SET_KEY_METHODS = new Set(["add", "has", "delete"]);
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Canonical form: JSON.stringify walks insertion order, so structurally
|
|
12
|
-
* equal data can serialise to different strings depending on construction
|
|
13
|
-
* history. As an identity function (comparison, Map/Set key, hash input),
|
|
14
|
-
* that is a false-negative machine. Only a canonical (key-sorted)
|
|
15
|
-
* serializer may stand in for structural equality there.
|
|
16
|
-
*/
|
|
17
|
-
export const requireCanonicalStringifyForIdentityRule = defineRule({
|
|
18
|
-
meta: {
|
|
19
|
-
type: "problem",
|
|
20
|
-
docs: {
|
|
21
|
-
description:
|
|
22
|
-
"Disallow JSON.stringify as an identity function (equality comparison, Map/Set key, hash input); use a canonical key-sorted serializer instead.",
|
|
23
|
-
},
|
|
24
|
-
messages: {
|
|
25
|
-
nonCanonicalIdentity:
|
|
26
|
-
"`JSON.stringify` here follows property insertion order, so equal data can produce different strings and identical-looking data can hide inequality. Use a canonical serializer (recursively key-sorted) before using the result for {{use}}.",
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
createOnce(context) {
|
|
30
|
-
function report(payload: { node: ESTree.CallExpression; use: string }): void {
|
|
31
|
-
context.report({
|
|
32
|
-
node: payload.node,
|
|
33
|
-
messageId: "nonCanonicalIdentity",
|
|
34
|
-
data: { use: payload.use },
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
CallExpression(node) {
|
|
40
|
-
const callee = node.callee;
|
|
41
|
-
if (
|
|
42
|
-
node.type !== "CallExpression" ||
|
|
43
|
-
callee.type !== "MemberExpression" ||
|
|
44
|
-
callee.computed ||
|
|
45
|
-
callee.object.type !== "Identifier" ||
|
|
46
|
-
callee.object.name !== "JSON" ||
|
|
47
|
-
callee.property.type !== "Identifier" ||
|
|
48
|
-
callee.property.name !== "stringify"
|
|
49
|
-
)
|
|
50
|
-
return;
|
|
51
|
-
const parent = (ancestorsOf(context.sourceCode, node)).at(-1);
|
|
52
|
-
if (parent === null || parent === undefined) return;
|
|
53
|
-
|
|
54
|
-
if (parent.type === "BinaryExpression" && COMPARISON_OPERATORS.has(parent.operator)) {
|
|
55
|
-
report({ node, use: "equality comparison" });
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
if (parent.type === "MemberExpression" && parent.computed) {
|
|
59
|
-
report({ node, use: "property lookup" });
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
if (parent.type === "CallExpression" && parent.callee.type === "MemberExpression" && !parent.callee.computed) {
|
|
63
|
-
const method = parent.callee.property;
|
|
64
|
-
if (method.type !== "Identifier") return;
|
|
65
|
-
if (MAP_KEY_METHODS.has(method.name) && parent.arguments[0] === node) {
|
|
66
|
-
report({ node, use: `${method.name}() on a map` });
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if (SET_KEY_METHODS.has(method.name) && parent.arguments[0] === node) {
|
|
70
|
-
report({ node, use: `${method.name}() on a set` });
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
if (method.name === "set" && parent.arguments[0] === node) {
|
|
74
|
-
report({ node, use: "a map key" });
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
},
|
|
80
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
|
|
3
|
-
import type { ESTree } from "@oxlint/plugins";
|
|
4
|
-
|
|
5
|
-
import { getAllComments } from "../shared/structural.ts";
|
|
6
|
-
|
|
7
|
-
interface CommentLike {
|
|
8
|
-
type: string;
|
|
9
|
-
value: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const LEGACY_PROSE =
|
|
13
|
-
/\b(?:deprecat\w*|legacy|obsolete|superseded|do not use|don't use|no longer (?:used?|supported|maintained))\b/iu;
|
|
14
|
-
|
|
15
|
-
const DEPRECATED_TAG = /@deprecated\b/iu;
|
|
16
|
-
|
|
17
|
-
/** Prose-only retirement notes are invisible to tooling; require the machine-readable tag. */
|
|
18
|
-
export const requireDeprecatedTagForLegacyCommentsRule = defineRule({
|
|
19
|
-
meta: {
|
|
20
|
-
type: "problem",
|
|
21
|
-
docs: {
|
|
22
|
-
description:
|
|
23
|
-
"Require an @deprecated tag whenever a comment describes code as deprecated/legacy/obsolete/do-not-use; prose-only warnings are invisible to editors and agents, who will otherwise discover and use paths you want retired.",
|
|
24
|
-
},
|
|
25
|
-
messages: {
|
|
26
|
-
missingDeprecatedTag:
|
|
27
|
-
"Comment says this code is deprecated/legacy but carries no @deprecated tag; prose warnings are invisible to tooling. Add `@deprecated` (with a pointer to the replacement) so agents and editors see it.",
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
createOnce(context) {
|
|
31
|
-
return {
|
|
32
|
-
Program(node) {
|
|
33
|
-
for (const comment of getAllComments(context.sourceCode)) {
|
|
34
|
-
if (comment.type !== "Block") continue;
|
|
35
|
-
if (!LEGACY_PROSE.test(comment.value)) continue;
|
|
36
|
-
if (DEPRECATED_TAG.test(comment.value)) continue;
|
|
37
|
-
context.report({
|
|
38
|
-
node,
|
|
39
|
-
messageId: "missingDeprecatedTag",
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
},
|
|
45
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
|
|
3
|
-
import type { ESTree } from "@oxlint/plugins";
|
|
4
|
-
|
|
5
|
-
const DISCRIMINANTS = new Set(["_tag", "tag"]);
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Bounded touch points: adding a variant should be caught by the compiler at
|
|
9
|
-
* every place that must change. A `default` arm on a tag switch, even a
|
|
10
|
-
* throwing one, silences that check, so unhandled variants slip through
|
|
11
|
-
* silently or via hand-rolled fallbacks instead of failing type-check.
|
|
12
|
-
*/
|
|
13
|
-
export const requireExhaustiveTagSwitchRule = defineRule({
|
|
14
|
-
meta: {
|
|
15
|
-
type: "suggestion",
|
|
16
|
-
docs: {
|
|
17
|
-
description:
|
|
18
|
-
"Require `default`-free switches over a `_tag` discriminant so exhaustiveness checking flags every site a new variant must touch.",
|
|
19
|
-
},
|
|
20
|
-
messages: {
|
|
21
|
-
noDefault:
|
|
22
|
-
"This switch matches on `_tag` but has a `default` arm, which hides unhandled variants from exhaustiveness checking. Remove it and list every variant explicitly so adding one fails type-check here.",
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
createOnce(context) {
|
|
26
|
-
return {
|
|
27
|
-
SwitchStatement(node) {
|
|
28
|
-
const discriminant = node.discriminant;
|
|
29
|
-
if (
|
|
30
|
-
discriminant.type !== "MemberExpression" ||
|
|
31
|
-
discriminant.computed ||
|
|
32
|
-
discriminant.property.type !== "Identifier" ||
|
|
33
|
-
!DISCRIMINANTS.has(discriminant.property.name)
|
|
34
|
-
)
|
|
35
|
-
return;
|
|
36
|
-
if (node.cases.some((clause) => clause.test === null)) {
|
|
37
|
-
context.report({ node, messageId: "noDefault" });
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
},
|
|
42
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
|
|
3
|
-
import type { ESTree } from "@oxlint/plugins";
|
|
4
|
-
|
|
5
|
-
/** Whether the callee accesses `.property` or `.asyncProperty`.
|
|
6
|
-
* @param {ESTree.CallExpression["callee"]} callee - The callee expression of a call being inspected.
|
|
7
|
-
* @returns {boolean} True when the callee is a property access matching fastcheck patterns. */
|
|
8
|
-
function isPropertyCall(callee: ESTree.CallExpression["callee"]): boolean {
|
|
9
|
-
return (
|
|
10
|
-
callee.type === "MemberExpression" &&
|
|
11
|
-
callee.property.type === "Identifier" &&
|
|
12
|
-
(callee.property.name === "property" || callee.property.name === "asyncProperty")
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** fast-check scores a predicate's implicit return; expression-bodied arrows return matchers. */
|
|
17
|
-
export const requireFcBlockPredicateRule = defineRule({
|
|
18
|
-
meta: {
|
|
19
|
-
type: "problem",
|
|
20
|
-
docs: {
|
|
21
|
-
description:
|
|
22
|
-
"Require fast-check property predicates to use block bodies: an expression-bodied arrow returns its last expression (often a vitest matcher object), which fast-check scores as a falsy result and fails the property.",
|
|
23
|
-
},
|
|
24
|
-
messages: {
|
|
25
|
-
blockBody:
|
|
26
|
-
"This property predicate returns its expression value, which fast-check may score as `false`. Use a block body (`=> { ...; }`) so the predicate returns void.",
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
createOnce(context) {
|
|
30
|
-
const checkArguments = (node: ESTree.CallExpression): void => {
|
|
31
|
-
if (!isPropertyCall(node.callee)) return;
|
|
32
|
-
for (const argument of node.arguments) {
|
|
33
|
-
if (argument.type !== "ArrowFunctionExpression") continue;
|
|
34
|
-
if (argument.body.type === "BlockStatement") continue;
|
|
35
|
-
context.report({ node: argument, messageId: "blockBody" });
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
return {
|
|
39
|
-
CallExpression: checkArguments,
|
|
40
|
-
};
|
|
41
|
-
},
|
|
42
|
-
});
|