@sarj/eslint-plugin 15.26.8 → 15.28.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/_docs-XCw_6XV9.d.cts +88 -0
- package/dist/_docs-XCw_6XV9.d.ts +88 -0
- package/dist/index.cjs +970 -840
- package/dist/index.d.cts +10 -89
- package/dist/index.d.ts +10 -89
- package/dist/index.js +968 -838
- package/dist/rule-examples.cjs +112 -0
- package/dist/rule-examples.d.cts +7 -0
- package/dist/rule-examples.d.ts +7 -0
- package/dist/rule-examples.js +77 -0
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -15710,8 +15710,134 @@ var prefer_multi_value_zod_literal_default = createRule({
|
|
|
15710
15710
|
}
|
|
15711
15711
|
});
|
|
15712
15712
|
|
|
15713
|
+
// src/rules/prefer-nominal-id-types.ts
|
|
15714
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES75, ASTUtils as ASTUtils35 } from "@typescript-eslint/utils";
|
|
15715
|
+
var OPERATIONAL_ROLES = /* @__PURE__ */ new Set([
|
|
15716
|
+
"request",
|
|
15717
|
+
"trace",
|
|
15718
|
+
"span",
|
|
15719
|
+
"correlation",
|
|
15720
|
+
"process",
|
|
15721
|
+
"thread",
|
|
15722
|
+
"timeout",
|
|
15723
|
+
"interval"
|
|
15724
|
+
]);
|
|
15725
|
+
var MAX_ALIAS_DEPTH = 16;
|
|
15726
|
+
var PREFER_NOMINAL_ID_TYPES_DOCUMENTATION = {
|
|
15727
|
+
defaultLevel: "warning",
|
|
15728
|
+
summary: "Distinguish identifier roles sharing primitive types at callable boundaries.",
|
|
15729
|
+
rationale: "Two identifier roles represented by the same primitive accept each other's values, so swapped arguments survive type checking. Transparent aliases do not prevent this.",
|
|
15730
|
+
remediation: "Introduce distinct branded identifier types at a validated domain boundary and use them in the callable contract. Keep wire representations primitive until validation; suppress a required external signature locally with a reason.",
|
|
15731
|
+
category: "correctness",
|
|
15732
|
+
limitations: [
|
|
15733
|
+
"Requires two distinct Id/Ids or _id/_ids parameter roles with the same proven string, number, or homogeneous array carrier. Plural names require array carriers. Scalars and arrays remain distinct; object fields, destructuring, tuples, inferred types and generic aliases are not checked.",
|
|
15734
|
+
"Resolves only scope-correct file-local transparent aliases, up to 16 levels. Intersections, imported types, ambiguous declarations and mixed branded/raw pairs are deliberately skipped.",
|
|
15735
|
+
"Generated files and request, trace, span, correlation, process, thread, timeout and interval identifiers are excluded. Raw wire object schemas are not callable boundaries; required external callable signatures need a local suppression. API and adapter paths are not blanket-excluded."
|
|
15736
|
+
],
|
|
15737
|
+
examples: [
|
|
15738
|
+
{ id: "raw-identifiers", title: "Do not accept interchangeable identifiers", outcome: "match", files: [{ path: "src/store.ts", source: "function load(accountId: string, invoiceId: string): void {}" }], focusPath: "src/store.ts", expectedCount: 1, public: true },
|
|
15739
|
+
{ id: "branded-identifiers", title: "Distinguish domain identifiers", outcome: "no-match", files: [{ path: "src/store.ts", source: "type AccountId = string & { readonly account: unique symbol }; type InvoiceId = string & { readonly invoice: unique symbol }; function load(accountId: AccountId, invoiceId: InvoiceId): void {}" }], focusPath: "src/store.ts", expectedCount: 0, public: true }
|
|
15740
|
+
]
|
|
15741
|
+
};
|
|
15742
|
+
function arrayCarrier(carrier) {
|
|
15743
|
+
if (carrier === "string") return "string[]";
|
|
15744
|
+
if (carrier === "number") return "number[]";
|
|
15745
|
+
return void 0;
|
|
15746
|
+
}
|
|
15747
|
+
function isNullish(node) {
|
|
15748
|
+
return node.type === AST_NODE_TYPES75.TSUndefinedKeyword || node.type === AST_NODE_TYPES75.TSNullKeyword || node.type === AST_NODE_TYPES75.TSLiteralType && node.literal.type === AST_NODE_TYPES75.Literal && node.literal.value === null;
|
|
15749
|
+
}
|
|
15750
|
+
function referenceCarrier(node, context, depth) {
|
|
15751
|
+
if (node.typeName.type !== AST_NODE_TYPES75.Identifier) return void 0;
|
|
15752
|
+
const variable = ASTUtils35.findVariable(context.sourceCode.getScope(node), node.typeName.name);
|
|
15753
|
+
const definitions = variable?.defs ?? [];
|
|
15754
|
+
const args = node.typeArguments?.params;
|
|
15755
|
+
if (definitions.length === 0 && ["Array", "ReadonlyArray"].includes(node.typeName.name) && args?.length === 1) {
|
|
15756
|
+
return arrayCarrier(rawCarrier(args[0], context, depth + 1));
|
|
15757
|
+
}
|
|
15758
|
+
if (args !== void 0 || definitions.length !== 1) return void 0;
|
|
15759
|
+
const declaration = definitions[0]?.node;
|
|
15760
|
+
if (declaration?.type !== AST_NODE_TYPES75.TSTypeAliasDeclaration || declaration.typeParameters !== void 0) return void 0;
|
|
15761
|
+
return rawCarrier(declaration.typeAnnotation, context, depth + 1);
|
|
15762
|
+
}
|
|
15763
|
+
function rawCarrier(node, context, depth = 0) {
|
|
15764
|
+
if (node === void 0 || depth >= MAX_ALIAS_DEPTH) return void 0;
|
|
15765
|
+
switch (node.type) {
|
|
15766
|
+
case AST_NODE_TYPES75.TSStringKeyword:
|
|
15767
|
+
return "string";
|
|
15768
|
+
case AST_NODE_TYPES75.TSNumberKeyword:
|
|
15769
|
+
return "number";
|
|
15770
|
+
case AST_NODE_TYPES75.TSArrayType:
|
|
15771
|
+
return arrayCarrier(rawCarrier(node.elementType, context, depth + 1));
|
|
15772
|
+
case AST_NODE_TYPES75.TSTypeOperator:
|
|
15773
|
+
return node.operator === "readonly" ? rawCarrier(node.typeAnnotation, context, depth + 1) : void 0;
|
|
15774
|
+
case AST_NODE_TYPES75.TSUnionType: {
|
|
15775
|
+
const members = node.types.filter((member) => !isNullish(member));
|
|
15776
|
+
if (members.length !== 1) return void 0;
|
|
15777
|
+
return rawCarrier(members[0], context, depth + 1);
|
|
15778
|
+
}
|
|
15779
|
+
case AST_NODE_TYPES75.TSTypeReference:
|
|
15780
|
+
return referenceCarrier(node, context, depth);
|
|
15781
|
+
default:
|
|
15782
|
+
return void 0;
|
|
15783
|
+
}
|
|
15784
|
+
}
|
|
15785
|
+
function checkBoundary(node, context) {
|
|
15786
|
+
const roles = /* @__PURE__ */ new Map();
|
|
15787
|
+
for (const parameter of node.params) {
|
|
15788
|
+
const identifier = parameterIdentifier(parameter);
|
|
15789
|
+
if (identifier?.typeAnnotation === void 0) continue;
|
|
15790
|
+
const role = identifierRole(identifier.name);
|
|
15791
|
+
if (role === void 0) continue;
|
|
15792
|
+
const carrier = rawCarrier(identifier.typeAnnotation.typeAnnotation, context);
|
|
15793
|
+
if (carrier === void 0 || /(?:Ids|_ids)$/u.test(identifier.name) && !carrier.endsWith("[]")) continue;
|
|
15794
|
+
const previous = roles.get(carrier);
|
|
15795
|
+
if (previous !== void 0 && previous !== role) {
|
|
15796
|
+
context.report({ node: identifier, messageId: "preferNominalIds" });
|
|
15797
|
+
return;
|
|
15798
|
+
}
|
|
15799
|
+
roles.set(carrier, role);
|
|
15800
|
+
}
|
|
15801
|
+
}
|
|
15802
|
+
function identifierRole(name) {
|
|
15803
|
+
const match = /^(.*?)(?:Ids?|_ids?)$/u.exec(name);
|
|
15804
|
+
const stem4 = match?.[1];
|
|
15805
|
+
if (stem4 === void 0 || stem4.length === 0) return void 0;
|
|
15806
|
+
const role = stem4.replaceAll("_", "").toLowerCase();
|
|
15807
|
+
return OPERATIONAL_ROLES.has(role) ? void 0 : role;
|
|
15808
|
+
}
|
|
15809
|
+
function parameterIdentifier(parameter) {
|
|
15810
|
+
if (parameter.type === AST_NODE_TYPES75.Identifier) return parameter;
|
|
15811
|
+
if (parameter.type === AST_NODE_TYPES75.AssignmentPattern && parameter.left.type === AST_NODE_TYPES75.Identifier) return parameter.left;
|
|
15812
|
+
if (parameter.type === AST_NODE_TYPES75.TSParameterProperty) return parameterIdentifier(parameter.parameter);
|
|
15813
|
+
return void 0;
|
|
15814
|
+
}
|
|
15815
|
+
var prefer_nominal_id_types_default = createRule({
|
|
15816
|
+
name: "prefer-nominal-id-types",
|
|
15817
|
+
documentation: PREFER_NOMINAL_ID_TYPES_DOCUMENTATION,
|
|
15818
|
+
meta: {
|
|
15819
|
+
type: "suggestion",
|
|
15820
|
+
docs: { description: "Distinguish identifier roles sharing primitive types at callable boundaries." },
|
|
15821
|
+
schema: [],
|
|
15822
|
+
messages: { preferNominalIds: "Distinct identifier roles share an interchangeable primitive type. Use distinct branded identifier types at this callable boundary." }
|
|
15823
|
+
},
|
|
15824
|
+
defaultOptions: [],
|
|
15825
|
+
create(context) {
|
|
15826
|
+
if (isGeneratedFile(context.filename, context.sourceCode.text)) return {};
|
|
15827
|
+
return {
|
|
15828
|
+
ArrowFunctionExpression: (node) => checkBoundary(node, context),
|
|
15829
|
+
FunctionDeclaration: (node) => checkBoundary(node, context),
|
|
15830
|
+
FunctionExpression: (node) => checkBoundary(node, context),
|
|
15831
|
+
TSDeclareFunction: (node) => checkBoundary(node, context),
|
|
15832
|
+
TSEmptyBodyFunctionExpression: (node) => checkBoundary(node, context),
|
|
15833
|
+
TSFunctionType: (node) => checkBoundary(node, context),
|
|
15834
|
+
TSMethodSignature: (node) => checkBoundary(node, context)
|
|
15835
|
+
};
|
|
15836
|
+
}
|
|
15837
|
+
});
|
|
15838
|
+
|
|
15713
15839
|
// src/rules/prefer-named-callback-domain.ts
|
|
15714
|
-
import { AST_NODE_TYPES as
|
|
15840
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES76 } from "@typescript-eslint/utils";
|
|
15715
15841
|
var PREFER_NAMED_CALLBACK_DOMAIN_DOCUMENTATION = {
|
|
15716
15842
|
summary: "Name literal-union domains used by callbacks in exported contracts.",
|
|
15717
15843
|
rationale: "An inline callback domain hides a reusable vocabulary at the point where callers and implementations must agree.",
|
|
@@ -15724,13 +15850,13 @@ var PREFER_NAMED_CALLBACK_DOMAIN_DOCUMENTATION = {
|
|
|
15724
15850
|
]
|
|
15725
15851
|
};
|
|
15726
15852
|
function isLiteralUnion(node) {
|
|
15727
|
-
return node.type ===
|
|
15853
|
+
return node.type === AST_NODE_TYPES76.TSUnionType && node.types.length >= 2 && node.types.every((part) => part.type === AST_NODE_TYPES76.TSLiteralType);
|
|
15728
15854
|
}
|
|
15729
15855
|
function exportedContract(node) {
|
|
15730
15856
|
let current = node;
|
|
15731
15857
|
while (current !== void 0) {
|
|
15732
|
-
if (current.type ===
|
|
15733
|
-
if (current.type ===
|
|
15858
|
+
if (current.type === AST_NODE_TYPES76.TSTypeAliasDeclaration || current.type === AST_NODE_TYPES76.TSInterfaceDeclaration) return current.parent.type === AST_NODE_TYPES76.ExportNamedDeclaration;
|
|
15859
|
+
if (current.type === AST_NODE_TYPES76.Program) return false;
|
|
15734
15860
|
current = current.parent ?? void 0;
|
|
15735
15861
|
}
|
|
15736
15862
|
return false;
|
|
@@ -15751,7 +15877,7 @@ var prefer_named_callback_domain_default = createRule({
|
|
|
15751
15877
|
TSFunctionType(node) {
|
|
15752
15878
|
if (!exportedContract(node)) return;
|
|
15753
15879
|
for (const parameter of node.params) {
|
|
15754
|
-
if (parameter.type !==
|
|
15880
|
+
if (parameter.type !== AST_NODE_TYPES76.TSParameterProperty && parameter.typeAnnotation !== void 0 && isLiteralUnion(parameter.typeAnnotation.typeAnnotation)) {
|
|
15755
15881
|
context.report({ node: parameter.typeAnnotation.typeAnnotation, messageId: "nameCallbackDomain" });
|
|
15756
15882
|
}
|
|
15757
15883
|
}
|
|
@@ -15761,7 +15887,7 @@ var prefer_named_callback_domain_default = createRule({
|
|
|
15761
15887
|
});
|
|
15762
15888
|
|
|
15763
15889
|
// src/rules/prefer-named-complex-return-type.ts
|
|
15764
|
-
import { AST_NODE_TYPES as
|
|
15890
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES77 } from "@typescript-eslint/utils";
|
|
15765
15891
|
var PREFER_NAMED_COMPLEX_RETURN_TYPE_DOCUMENTATION = {
|
|
15766
15892
|
defaultLevel: "warning",
|
|
15767
15893
|
summary: "Prefer a named contract for structurally complex function return types.",
|
|
@@ -15778,7 +15904,7 @@ var PREFER_NAMED_COMPLEX_RETURN_TYPE_DOCUMENTATION = {
|
|
|
15778
15904
|
]
|
|
15779
15905
|
};
|
|
15780
15906
|
function unwrap5(node) {
|
|
15781
|
-
if (node.type ===
|
|
15907
|
+
if (node.type === AST_NODE_TYPES77.TSTypeReference && node.typeArguments?.params.length === 1) {
|
|
15782
15908
|
const [inner] = node.typeArguments.params;
|
|
15783
15909
|
if (inner !== void 0) return unwrap5(inner);
|
|
15784
15910
|
}
|
|
@@ -15792,9 +15918,9 @@ function report(context, node) {
|
|
|
15792
15918
|
}
|
|
15793
15919
|
function isComplex(node) {
|
|
15794
15920
|
const type = unwrap5(node);
|
|
15795
|
-
if (type.type ===
|
|
15796
|
-
if (type.type !==
|
|
15797
|
-
return type.types.every((member) => unwrap5(member).type ===
|
|
15921
|
+
if (type.type === AST_NODE_TYPES77.TSTypeLiteral) return type.members.length >= 3;
|
|
15922
|
+
if (type.type !== AST_NODE_TYPES77.TSUnionType || type.types.length < 3) return false;
|
|
15923
|
+
return type.types.every((member) => unwrap5(member).type === AST_NODE_TYPES77.TSTypeLiteral);
|
|
15798
15924
|
}
|
|
15799
15925
|
var prefer_named_complex_return_type_default = createRule({
|
|
15800
15926
|
name: "prefer-named-complex-return-type",
|
|
@@ -15821,7 +15947,7 @@ var prefer_named_complex_return_type_default = createRule({
|
|
|
15821
15947
|
});
|
|
15822
15948
|
|
|
15823
15949
|
// src/rules/prefer-native-random-uuid.ts
|
|
15824
|
-
import { AST_NODE_TYPES as
|
|
15950
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES78, ASTUtils as ASTUtils36 } from "@typescript-eslint/utils";
|
|
15825
15951
|
var PREFER_NATIVE_RANDOM_UUID_DOCUMENTATION = {
|
|
15826
15952
|
summary: "Prefer `globalThis.crypto.randomUUID()` over resolved zero-argument UUID v4 bindings from the `uuid` package.",
|
|
15827
15953
|
rationale: "The platform implementation avoids an unnecessary dependency for standard random UUID generation.",
|
|
@@ -15835,7 +15961,7 @@ var PREFER_NATIVE_RANDOM_UUID_DOCUMENTATION = {
|
|
|
15835
15961
|
]
|
|
15836
15962
|
};
|
|
15837
15963
|
function requireUuid(node) {
|
|
15838
|
-
return node?.type ===
|
|
15964
|
+
return node?.type === AST_NODE_TYPES78.CallExpression && node.callee.type === AST_NODE_TYPES78.Identifier && node.callee.name === "require" && node.arguments.length === 1 && node.arguments[0]?.type === AST_NODE_TYPES78.Literal && node.arguments[0].value === "uuid";
|
|
15839
15965
|
}
|
|
15840
15966
|
var prefer_native_random_uuid_default = createRule({
|
|
15841
15967
|
name: "prefer-native-random-uuid",
|
|
@@ -15857,14 +15983,14 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
15857
15983
|
const directBindings = /* @__PURE__ */ new Set();
|
|
15858
15984
|
const namespaceBindings = /* @__PURE__ */ new Set();
|
|
15859
15985
|
function resolve2(identifier) {
|
|
15860
|
-
return
|
|
15986
|
+
return ASTUtils36.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
15861
15987
|
}
|
|
15862
15988
|
function record(identifier, destination) {
|
|
15863
15989
|
const variable = resolve2(identifier);
|
|
15864
15990
|
if (variable !== null) destination.add(variable);
|
|
15865
15991
|
}
|
|
15866
15992
|
function report2(node) {
|
|
15867
|
-
const globalBinding =
|
|
15993
|
+
const globalBinding = ASTUtils36.findVariable(context.sourceCode.getScope(node), "globalThis");
|
|
15868
15994
|
const canSuggest = (globalBinding?.defs.length ?? 0) === 0 && context.sourceCode.getCommentsInside(node).length === 0;
|
|
15869
15995
|
context.report({
|
|
15870
15996
|
node,
|
|
@@ -15881,37 +16007,37 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
15881
16007
|
ImportDeclaration(node) {
|
|
15882
16008
|
if (node.source.value !== "uuid") return;
|
|
15883
16009
|
for (const specifier of node.specifiers) {
|
|
15884
|
-
if (specifier.type ===
|
|
16010
|
+
if (specifier.type === AST_NODE_TYPES78.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES78.Identifier ? specifier.imported.name === "v4" : specifier.imported.value === "v4")) {
|
|
15885
16011
|
record(specifier.local, directBindings);
|
|
15886
|
-
} else if (specifier.type ===
|
|
16012
|
+
} else if (specifier.type === AST_NODE_TYPES78.ImportNamespaceSpecifier) {
|
|
15887
16013
|
record(specifier.local, namespaceBindings);
|
|
15888
16014
|
}
|
|
15889
16015
|
}
|
|
15890
16016
|
},
|
|
15891
16017
|
VariableDeclarator(node) {
|
|
15892
16018
|
if (node.parent.kind !== "const" || !requireUuid(node.init)) return;
|
|
15893
|
-
if (node.init?.type !==
|
|
16019
|
+
if (node.init?.type !== AST_NODE_TYPES78.CallExpression || node.init.callee.type !== AST_NODE_TYPES78.Identifier || (resolve2(node.init.callee)?.defs.length ?? 0) > 0) {
|
|
15894
16020
|
return;
|
|
15895
16021
|
}
|
|
15896
|
-
if (node.id.type ===
|
|
16022
|
+
if (node.id.type === AST_NODE_TYPES78.Identifier) {
|
|
15897
16023
|
record(node.id, namespaceBindings);
|
|
15898
16024
|
return;
|
|
15899
16025
|
}
|
|
15900
|
-
if (node.id.type !==
|
|
16026
|
+
if (node.id.type !== AST_NODE_TYPES78.ObjectPattern) return;
|
|
15901
16027
|
for (const property of node.id.properties) {
|
|
15902
|
-
if (property.type ===
|
|
16028
|
+
if (property.type === AST_NODE_TYPES78.Property && !property.computed && (property.key.type === AST_NODE_TYPES78.Identifier && property.key.name === "v4" || property.key.type === AST_NODE_TYPES78.Literal && property.key.value === "v4") && property.value.type === AST_NODE_TYPES78.Identifier) {
|
|
15903
16029
|
record(property.value, directBindings);
|
|
15904
16030
|
}
|
|
15905
16031
|
}
|
|
15906
16032
|
},
|
|
15907
16033
|
"CallExpression:exit"(node) {
|
|
15908
16034
|
if (node.arguments.length !== 0) return;
|
|
15909
|
-
if (node.callee.type ===
|
|
16035
|
+
if (node.callee.type === AST_NODE_TYPES78.Identifier) {
|
|
15910
16036
|
const variable2 = resolve2(node.callee);
|
|
15911
16037
|
if (variable2 !== null && directBindings.has(variable2)) report2(node);
|
|
15912
16038
|
return;
|
|
15913
16039
|
}
|
|
15914
|
-
if (node.callee.type !==
|
|
16040
|
+
if (node.callee.type !== AST_NODE_TYPES78.MemberExpression || node.callee.computed || node.callee.object.type !== AST_NODE_TYPES78.Identifier || node.callee.property.type !== AST_NODE_TYPES78.Identifier || node.callee.property.name !== "v4") {
|
|
15915
16041
|
return;
|
|
15916
16042
|
}
|
|
15917
16043
|
const variable = resolve2(node.callee.object);
|
|
@@ -15922,7 +16048,7 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
15922
16048
|
});
|
|
15923
16049
|
|
|
15924
16050
|
// src/rules/prefer-node-crypto-hash.ts
|
|
15925
|
-
import { AST_NODE_TYPES as
|
|
16051
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES79, ASTUtils as ASTUtils37 } from "@typescript-eslint/utils";
|
|
15926
16052
|
var PREFER_NODE_CRYPTO_HASH_DOCUMENTATION = {
|
|
15927
16053
|
defaultLevel: "warning",
|
|
15928
16054
|
summary: "Prefer the modern one-shot node:crypto hash API when streaming state is unnecessary.",
|
|
@@ -15941,33 +16067,33 @@ var PREFER_NODE_CRYPTO_HASH_DOCUMENTATION = {
|
|
|
15941
16067
|
]
|
|
15942
16068
|
};
|
|
15943
16069
|
function memberName5(node) {
|
|
15944
|
-
if (!node.computed && node.property.type ===
|
|
15945
|
-
if (node.computed && node.property.type ===
|
|
16070
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES79.Identifier) return node.property.name;
|
|
16071
|
+
if (node.computed && node.property.type === AST_NODE_TYPES79.Literal && typeof node.property.value === "string") {
|
|
15946
16072
|
return node.property.value;
|
|
15947
16073
|
}
|
|
15948
16074
|
return null;
|
|
15949
16075
|
}
|
|
15950
16076
|
function isCryptoLoader(node, resolve2) {
|
|
15951
|
-
if (node.type !==
|
|
16077
|
+
if (node.type !== AST_NODE_TYPES79.CallExpression || node.arguments.length !== 1) return false;
|
|
15952
16078
|
const [argument] = node.arguments;
|
|
15953
|
-
if (argument === void 0 || argument.type ===
|
|
16079
|
+
if (argument === void 0 || argument.type === AST_NODE_TYPES79.SpreadElement || !isCryptoSpecifier(argument)) {
|
|
15954
16080
|
return false;
|
|
15955
16081
|
}
|
|
15956
|
-
if (node.callee.type ===
|
|
16082
|
+
if (node.callee.type === AST_NODE_TYPES79.Identifier) {
|
|
15957
16083
|
return node.callee.name === "require" && isUnshadowedBuiltinIdentifier(node.callee, resolve2);
|
|
15958
16084
|
}
|
|
15959
|
-
return node.callee.type ===
|
|
16085
|
+
return node.callee.type === AST_NODE_TYPES79.MemberExpression && node.callee.object.type === AST_NODE_TYPES79.Identifier && node.callee.object.name === "process" && isUnshadowedBuiltinIdentifier(node.callee.object, resolve2) && memberName5(node.callee) === "getBuiltinModule";
|
|
15960
16086
|
}
|
|
15961
16087
|
function isCryptoSpecifier(node) {
|
|
15962
|
-
return node.type ===
|
|
16088
|
+
return node.type === AST_NODE_TYPES79.Literal && (node.value === "crypto" || node.value === "node:crypto");
|
|
15963
16089
|
}
|
|
15964
16090
|
function isUnshadowedBuiltinIdentifier(identifier, resolve2) {
|
|
15965
16091
|
const variable = resolve2(identifier);
|
|
15966
16092
|
return variable === null || variable.defs.length === 0;
|
|
15967
16093
|
}
|
|
15968
16094
|
function propertyName3(node) {
|
|
15969
|
-
if (!node.computed && node.key.type ===
|
|
15970
|
-
if (node.key.type ===
|
|
16095
|
+
if (!node.computed && node.key.type === AST_NODE_TYPES79.Identifier) return node.key.name;
|
|
16096
|
+
if (node.key.type === AST_NODE_TYPES79.Literal && typeof node.key.value === "string") {
|
|
15971
16097
|
return node.key.value;
|
|
15972
16098
|
}
|
|
15973
16099
|
return null;
|
|
@@ -15981,7 +16107,7 @@ var prefer_node_crypto_hash_default = createRule({
|
|
|
15981
16107
|
const directBindings = /* @__PURE__ */ new Set();
|
|
15982
16108
|
const namespaceBindings = /* @__PURE__ */ new Set();
|
|
15983
16109
|
function resolve2(identifier) {
|
|
15984
|
-
return
|
|
16110
|
+
return ASTUtils37.findVariable(
|
|
15985
16111
|
context.sourceCode.getScope(identifier),
|
|
15986
16112
|
identifier.name
|
|
15987
16113
|
);
|
|
@@ -15994,9 +16120,9 @@ var prefer_node_crypto_hash_default = createRule({
|
|
|
15994
16120
|
ImportDeclaration(node) {
|
|
15995
16121
|
if (node.source.value !== "crypto" && node.source.value !== "node:crypto") return;
|
|
15996
16122
|
for (const specifier of node.specifiers) {
|
|
15997
|
-
if (specifier.type ===
|
|
16123
|
+
if (specifier.type === AST_NODE_TYPES79.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES79.ImportDefaultSpecifier) {
|
|
15998
16124
|
record(specifier.local, namespaceBindings);
|
|
15999
|
-
} else if (specifier.type ===
|
|
16125
|
+
} else if (specifier.type === AST_NODE_TYPES79.ImportSpecifier && importedName6(specifier.imported) === "createHash") {
|
|
16000
16126
|
record(specifier.local, directBindings);
|
|
16001
16127
|
}
|
|
16002
16128
|
}
|
|
@@ -16005,13 +16131,13 @@ var prefer_node_crypto_hash_default = createRule({
|
|
|
16005
16131
|
if (node.parent.kind !== "const" || node.init === null || !isCryptoLoader(node.init, resolve2)) {
|
|
16006
16132
|
return;
|
|
16007
16133
|
}
|
|
16008
|
-
if (node.id.type ===
|
|
16134
|
+
if (node.id.type === AST_NODE_TYPES79.Identifier) {
|
|
16009
16135
|
record(node.id, namespaceBindings);
|
|
16010
16136
|
return;
|
|
16011
16137
|
}
|
|
16012
|
-
if (node.id.type !==
|
|
16138
|
+
if (node.id.type !== AST_NODE_TYPES79.ObjectPattern) return;
|
|
16013
16139
|
for (const property of node.id.properties) {
|
|
16014
|
-
if (property.type ===
|
|
16140
|
+
if (property.type === AST_NODE_TYPES79.Property && propertyName3(property) === "createHash" && property.value.type === AST_NODE_TYPES79.Identifier) {
|
|
16015
16141
|
record(property.value, directBindings);
|
|
16016
16142
|
}
|
|
16017
16143
|
}
|
|
@@ -16019,10 +16145,10 @@ var prefer_node_crypto_hash_default = createRule({
|
|
|
16019
16145
|
CallExpression(node) {
|
|
16020
16146
|
if (!isMemberCall(node, "digest")) return;
|
|
16021
16147
|
const update = node.callee.object;
|
|
16022
|
-
if (update.type !==
|
|
16148
|
+
if (update.type !== AST_NODE_TYPES79.CallExpression || update.arguments.length !== 1 || !isMemberCall(update, "update"))
|
|
16023
16149
|
return;
|
|
16024
16150
|
const create = update.callee.object;
|
|
16025
|
-
if (create.type !==
|
|
16151
|
+
if (create.type !== AST_NODE_TYPES79.CallExpression || create.arguments.length !== 1 || create.arguments[0]?.type !== AST_NODE_TYPES79.Literal || typeof create.arguments[0].value !== "string" || !isCreateHashCall(
|
|
16026
16152
|
create,
|
|
16027
16153
|
directBindings,
|
|
16028
16154
|
namespaceBindings,
|
|
@@ -16035,27 +16161,27 @@ var prefer_node_crypto_hash_default = createRule({
|
|
|
16035
16161
|
}
|
|
16036
16162
|
});
|
|
16037
16163
|
function importedName6(node) {
|
|
16038
|
-
return node.type ===
|
|
16164
|
+
return node.type === AST_NODE_TYPES79.Identifier ? node.name : node.value;
|
|
16039
16165
|
}
|
|
16040
16166
|
function isMemberCall(node, name) {
|
|
16041
|
-
return node.callee.type ===
|
|
16167
|
+
return node.callee.type === AST_NODE_TYPES79.MemberExpression && memberName5(node.callee) === name;
|
|
16042
16168
|
}
|
|
16043
16169
|
function isCreateHashCall(node, directBindings, namespaceBindings, resolve2) {
|
|
16044
|
-
if (node.callee.type ===
|
|
16170
|
+
if (node.callee.type === AST_NODE_TYPES79.Identifier) {
|
|
16045
16171
|
const variable2 = resolve2(node.callee);
|
|
16046
16172
|
return variable2 !== null && directBindings.has(variable2);
|
|
16047
16173
|
}
|
|
16048
|
-
if (node.callee.type !==
|
|
16174
|
+
if (node.callee.type !== AST_NODE_TYPES79.MemberExpression || memberName5(node.callee) !== "createHash") {
|
|
16049
16175
|
return false;
|
|
16050
16176
|
}
|
|
16051
16177
|
if (isCryptoLoader(node.callee.object, resolve2)) return true;
|
|
16052
|
-
if (node.callee.object.type !==
|
|
16178
|
+
if (node.callee.object.type !== AST_NODE_TYPES79.Identifier) return false;
|
|
16053
16179
|
const variable = resolve2(node.callee.object);
|
|
16054
16180
|
return variable !== null && namespaceBindings.has(variable);
|
|
16055
16181
|
}
|
|
16056
16182
|
|
|
16057
16183
|
// src/rules/prefer-node-fs-promises.ts
|
|
16058
|
-
import { AST_NODE_TYPES as
|
|
16184
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES80, ASTUtils as ASTUtils38 } from "@typescript-eslint/utils";
|
|
16059
16185
|
var PREFER_NODE_FS_PROMISES_DOCUMENTATION = {
|
|
16060
16186
|
defaultLevel: "warning",
|
|
16061
16187
|
summary: "Prefer promise-based Node.js filesystem APIs over synchronous calls in production modules.",
|
|
@@ -16074,30 +16200,30 @@ var PREFER_NODE_FS_PROMISES_DOCUMENTATION = {
|
|
|
16074
16200
|
]
|
|
16075
16201
|
};
|
|
16076
16202
|
function memberName6(node) {
|
|
16077
|
-
if (!node.computed && node.property.type ===
|
|
16078
|
-
if (node.computed && node.property.type ===
|
|
16203
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES80.Identifier) return node.property.name;
|
|
16204
|
+
if (node.computed && node.property.type === AST_NODE_TYPES80.Literal && typeof node.property.value === "string") {
|
|
16079
16205
|
return node.property.value;
|
|
16080
16206
|
}
|
|
16081
16207
|
return null;
|
|
16082
16208
|
}
|
|
16083
16209
|
function unwrapAwait2(node) {
|
|
16084
|
-
return node.type ===
|
|
16210
|
+
return node.type === AST_NODE_TYPES80.AwaitExpression ? node.argument : node;
|
|
16085
16211
|
}
|
|
16086
16212
|
function isFsLoader(node, isGlobal) {
|
|
16087
16213
|
const expression = unwrapAwait2(node);
|
|
16088
|
-
if (expression.type ===
|
|
16089
|
-
if (expression.type !==
|
|
16214
|
+
if (expression.type === AST_NODE_TYPES80.ImportExpression) return isFsSpecifier(expression.source);
|
|
16215
|
+
if (expression.type !== AST_NODE_TYPES80.CallExpression || expression.arguments.length !== 1) return false;
|
|
16090
16216
|
const [argument] = expression.arguments;
|
|
16091
|
-
if (argument === void 0 || argument.type ===
|
|
16092
|
-
if (expression.callee.type ===
|
|
16093
|
-
return expression.callee.type ===
|
|
16217
|
+
if (argument === void 0 || argument.type === AST_NODE_TYPES80.SpreadElement || !isFsSpecifier(argument)) return false;
|
|
16218
|
+
if (expression.callee.type === AST_NODE_TYPES80.Identifier) return expression.callee.name === "require" && isGlobal(expression.callee);
|
|
16219
|
+
return expression.callee.type === AST_NODE_TYPES80.MemberExpression && expression.callee.object.type === AST_NODE_TYPES80.Identifier && expression.callee.object.name === "process" && isGlobal(expression.callee.object) && memberName6(expression.callee) === "getBuiltinModule";
|
|
16094
16220
|
}
|
|
16095
16221
|
function isFsSpecifier(node) {
|
|
16096
|
-
return node.type ===
|
|
16222
|
+
return node.type === AST_NODE_TYPES80.Literal && (node.value === "node:fs" || node.value === "fs");
|
|
16097
16223
|
}
|
|
16098
16224
|
function propertyName4(node) {
|
|
16099
|
-
if (!node.computed && node.key.type ===
|
|
16100
|
-
if (node.key.type ===
|
|
16225
|
+
if (!node.computed && node.key.type === AST_NODE_TYPES80.Identifier) return node.key.name;
|
|
16226
|
+
if (node.key.type === AST_NODE_TYPES80.Literal && typeof node.key.value === "string") return node.key.value;
|
|
16101
16227
|
return null;
|
|
16102
16228
|
}
|
|
16103
16229
|
var prefer_node_fs_promises_default = createRule({
|
|
@@ -16117,7 +16243,7 @@ var prefer_node_fs_promises_default = createRule({
|
|
|
16117
16243
|
if (isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text) || normalizedFilename.includes("src/rules/"))
|
|
16118
16244
|
return {};
|
|
16119
16245
|
const namespaces = /* @__PURE__ */ new Set();
|
|
16120
|
-
const bindingOf = (node) =>
|
|
16246
|
+
const bindingOf = (node) => ASTUtils38.findVariable(context.sourceCode.getScope(node), node.name);
|
|
16121
16247
|
const isGlobal = (node) => {
|
|
16122
16248
|
const binding = bindingOf(node);
|
|
16123
16249
|
return binding === null || binding.defs.length === 0;
|
|
@@ -16135,11 +16261,11 @@ var prefer_node_fs_promises_default = createRule({
|
|
|
16135
16261
|
if (node.source.value !== "node:fs" && node.source.value !== "fs") return;
|
|
16136
16262
|
const synchronousImports = [];
|
|
16137
16263
|
for (const specifier of node.specifiers) {
|
|
16138
|
-
if (specifier.type ===
|
|
16264
|
+
if (specifier.type === AST_NODE_TYPES80.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES80.ImportDefaultSpecifier) {
|
|
16139
16265
|
recordNamespace(specifier.local);
|
|
16140
16266
|
continue;
|
|
16141
16267
|
}
|
|
16142
|
-
if (specifier.type ===
|
|
16268
|
+
if (specifier.type === AST_NODE_TYPES80.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES80.Identifier && specifier.imported.name.endsWith("Sync")) synchronousImports.push(specifier.imported.name);
|
|
16143
16269
|
}
|
|
16144
16270
|
if (synchronousImports.length > 0) {
|
|
16145
16271
|
context.report({
|
|
@@ -16150,15 +16276,15 @@ var prefer_node_fs_promises_default = createRule({
|
|
|
16150
16276
|
}
|
|
16151
16277
|
},
|
|
16152
16278
|
VariableDeclarator(node) {
|
|
16153
|
-
if (node.init === null || !isFsLoader(node.init, isGlobal) && (node.init.type !==
|
|
16279
|
+
if (node.init === null || !isFsLoader(node.init, isGlobal) && (node.init.type !== AST_NODE_TYPES80.Identifier || !isNamespace(node.init)))
|
|
16154
16280
|
return;
|
|
16155
|
-
if (node.id.type ===
|
|
16281
|
+
if (node.id.type === AST_NODE_TYPES80.Identifier) {
|
|
16156
16282
|
recordNamespace(node.id);
|
|
16157
16283
|
return;
|
|
16158
16284
|
}
|
|
16159
|
-
if (node.id.type !==
|
|
16285
|
+
if (node.id.type !== AST_NODE_TYPES80.ObjectPattern) return;
|
|
16160
16286
|
const synchronousImports = node.id.properties.flatMap((property) => {
|
|
16161
|
-
if (property.type !==
|
|
16287
|
+
if (property.type !== AST_NODE_TYPES80.Property) return [];
|
|
16162
16288
|
const name = propertyName4(property);
|
|
16163
16289
|
return name?.endsWith("Sync") === true ? [name] : [];
|
|
16164
16290
|
});
|
|
@@ -16174,7 +16300,7 @@ var prefer_node_fs_promises_default = createRule({
|
|
|
16174
16300
|
const name = memberName6(node);
|
|
16175
16301
|
if (name?.endsWith("Sync") !== true) return;
|
|
16176
16302
|
const object = unwrapAwait2(node.object);
|
|
16177
|
-
if (object.type ===
|
|
16303
|
+
if (object.type === AST_NODE_TYPES80.Identifier && isNamespace(object) || isFsLoader(object, isGlobal)) {
|
|
16178
16304
|
context.report({ node, messageId: "preferAsyncFs", data: { name } });
|
|
16179
16305
|
}
|
|
16180
16306
|
}
|
|
@@ -16183,7 +16309,7 @@ var prefer_node_fs_promises_default = createRule({
|
|
|
16183
16309
|
});
|
|
16184
16310
|
|
|
16185
16311
|
// src/rules/prefer-non-nullable-collection.ts
|
|
16186
|
-
import { AST_NODE_TYPES as
|
|
16312
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES81, ASTUtils as ASTUtils39 } from "@typescript-eslint/utils";
|
|
16187
16313
|
var PREFER_NON_NULLABLE_COLLECTION_DOCUMENTATION = {
|
|
16188
16314
|
summary: "Suggest reviewing nullish arrays that use local empty-array defaults or a shared null-or-empty guard.",
|
|
16189
16315
|
rationale: "A redundant nullish collection state spreads defaults and guards through consumers without carrying information.",
|
|
@@ -16199,33 +16325,33 @@ var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
|
16199
16325
|
function propertyName5(node) {
|
|
16200
16326
|
const key = node.key;
|
|
16201
16327
|
if (node.computed) return null;
|
|
16202
|
-
if (key.type ===
|
|
16203
|
-
if (key.type ===
|
|
16328
|
+
if (key.type === AST_NODE_TYPES81.Identifier) return key.name;
|
|
16329
|
+
if (key.type === AST_NODE_TYPES81.Literal && typeof key.value === "string") return key.value;
|
|
16204
16330
|
return null;
|
|
16205
16331
|
}
|
|
16206
16332
|
function isArrayType(node) {
|
|
16207
|
-
if (node.type ===
|
|
16208
|
-
return node.type ===
|
|
16333
|
+
if (node.type === AST_NODE_TYPES81.TSArrayType) return true;
|
|
16334
|
+
return node.type === AST_NODE_TYPES81.TSTypeReference && node.typeName.type === AST_NODE_TYPES81.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
16209
16335
|
}
|
|
16210
16336
|
function nullableProperty(node) {
|
|
16211
16337
|
if (node.optional) return null;
|
|
16212
16338
|
const name = propertyName5(node);
|
|
16213
16339
|
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
16214
|
-
if (name === null || annotation?.type !==
|
|
16340
|
+
if (name === null || annotation?.type !== AST_NODE_TYPES81.TSUnionType) return null;
|
|
16215
16341
|
const concrete = annotation.types.filter(
|
|
16216
|
-
(member) => member.type !==
|
|
16342
|
+
(member) => member.type !== AST_NODE_TYPES81.TSNullKeyword && member.type !== AST_NODE_TYPES81.TSUndefinedKeyword
|
|
16217
16343
|
);
|
|
16218
16344
|
if (concrete.length === 0 || !concrete.every(isArrayType)) return null;
|
|
16219
|
-
const acceptsNull = annotation.types.some((member) => member.type ===
|
|
16345
|
+
const acceptsNull = annotation.types.some((member) => member.type === AST_NODE_TYPES81.TSNullKeyword);
|
|
16220
16346
|
const acceptsUndefined = annotation.types.some(
|
|
16221
|
-
(member) => member.type ===
|
|
16347
|
+
(member) => member.type === AST_NODE_TYPES81.TSUndefinedKeyword
|
|
16222
16348
|
);
|
|
16223
16349
|
if (!acceptsNull && !acceptsUndefined) return null;
|
|
16224
16350
|
return { name, node, acceptsNull, acceptsUndefined };
|
|
16225
16351
|
}
|
|
16226
16352
|
function shapeProperties(members) {
|
|
16227
16353
|
return members.flatMap((member) => {
|
|
16228
|
-
if (member.type !==
|
|
16354
|
+
if (member.type !== AST_NODE_TYPES81.TSPropertySignature) return [];
|
|
16229
16355
|
const property = nullableProperty(member);
|
|
16230
16356
|
return property === null ? [] : [property];
|
|
16231
16357
|
});
|
|
@@ -16233,14 +16359,14 @@ function shapeProperties(members) {
|
|
|
16233
16359
|
function typeIndex(program) {
|
|
16234
16360
|
const index = /* @__PURE__ */ new Map();
|
|
16235
16361
|
for (const statement of program.body) {
|
|
16236
|
-
const exported = statement.type ===
|
|
16362
|
+
const exported = statement.type === AST_NODE_TYPES81.ExportNamedDeclaration;
|
|
16237
16363
|
const declaration = exported ? statement.declaration : statement;
|
|
16238
|
-
if (declaration?.type ===
|
|
16364
|
+
if (declaration?.type === AST_NODE_TYPES81.TSInterfaceDeclaration) {
|
|
16239
16365
|
index.set(declaration.id.name, {
|
|
16240
16366
|
exported,
|
|
16241
16367
|
properties: shapeProperties(declaration.body.body)
|
|
16242
16368
|
});
|
|
16243
|
-
} else if (declaration?.type ===
|
|
16369
|
+
} else if (declaration?.type === AST_NODE_TYPES81.TSTypeAliasDeclaration && declaration.typeAnnotation.type === AST_NODE_TYPES81.TSTypeLiteral) {
|
|
16244
16370
|
index.set(declaration.id.name, {
|
|
16245
16371
|
exported,
|
|
16246
16372
|
properties: shapeProperties(declaration.typeAnnotation.members)
|
|
@@ -16250,45 +16376,45 @@ function typeIndex(program) {
|
|
|
16250
16376
|
return index;
|
|
16251
16377
|
}
|
|
16252
16378
|
function emptyArray(node) {
|
|
16253
|
-
return node.type ===
|
|
16379
|
+
return node.type === AST_NODE_TYPES81.ArrayExpression && node.elements.length === 0;
|
|
16254
16380
|
}
|
|
16255
16381
|
function sameAccess(node, access) {
|
|
16256
16382
|
if (access.kind === "identifier") {
|
|
16257
|
-
return node.type ===
|
|
16383
|
+
return node.type === AST_NODE_TYPES81.Identifier && node.name === access.name;
|
|
16258
16384
|
}
|
|
16259
|
-
return node.type ===
|
|
16385
|
+
return node.type === AST_NODE_TYPES81.MemberExpression && !node.computed && node.object.type === AST_NODE_TYPES81.Identifier && node.object.name === access.object && node.property.type === AST_NODE_TYPES81.Identifier && node.property.name === access.property;
|
|
16260
16386
|
}
|
|
16261
16387
|
function memberLengthOf(node, access) {
|
|
16262
|
-
const target = node.type ===
|
|
16263
|
-
return target.type ===
|
|
16388
|
+
const target = node.type === AST_NODE_TYPES81.ChainExpression ? node.expression : node;
|
|
16389
|
+
return target.type === AST_NODE_TYPES81.MemberExpression && !target.computed && target.property.type === AST_NODE_TYPES81.Identifier && target.property.name === "length" && sameAccess(target.object, access);
|
|
16264
16390
|
}
|
|
16265
16391
|
function optionalMemberLengthOf(node, access) {
|
|
16266
|
-
return node.type ===
|
|
16392
|
+
return node.type === AST_NODE_TYPES81.ChainExpression && node.expression.type === AST_NODE_TYPES81.MemberExpression && node.expression.optional && memberLengthOf(node, access);
|
|
16267
16393
|
}
|
|
16268
16394
|
function hasEquivalentLeadingGuard(fn, access, visitorKeys) {
|
|
16269
|
-
if (fn.body.type !==
|
|
16395
|
+
if (fn.body.type !== AST_NODE_TYPES81.BlockStatement) return false;
|
|
16270
16396
|
const first = fn.body.body[0];
|
|
16271
|
-
if (first?.type !==
|
|
16272
|
-
const terminating = first.consequent.type ===
|
|
16397
|
+
if (first?.type !== AST_NODE_TYPES81.IfStatement) return false;
|
|
16398
|
+
const terminating = first.consequent.type === AST_NODE_TYPES81.ReturnStatement || first.consequent.type === AST_NODE_TYPES81.ThrowStatement || first.consequent.type === AST_NODE_TYPES81.BlockStatement && first.consequent.body.length === 1 && (first.consequent.body[0]?.type === AST_NODE_TYPES81.ReturnStatement || first.consequent.body[0]?.type === AST_NODE_TYPES81.ThrowStatement);
|
|
16273
16399
|
if (!terminating) return false;
|
|
16274
16400
|
if (contains(first.consequent, visitorKeys, (node) => sameAccess(node, access))) return false;
|
|
16275
|
-
if (first.test.type ===
|
|
16276
|
-
return first.test.type ===
|
|
16401
|
+
if (first.test.type === AST_NODE_TYPES81.UnaryExpression && first.test.operator === "!" && optionalMemberLengthOf(first.test.argument, access)) return true;
|
|
16402
|
+
return first.test.type === AST_NODE_TYPES81.LogicalExpression && first.test.operator === "||" && isNullGuard(first.test.left, access) && isEmptyGuard(first.test.right, access);
|
|
16277
16403
|
}
|
|
16278
16404
|
function isNullGuard(node, access) {
|
|
16279
|
-
if (node.type ===
|
|
16280
|
-
if (node.type !==
|
|
16405
|
+
if (node.type === AST_NODE_TYPES81.UnaryExpression && node.operator === "!" && (sameAccess(node.argument, access) || optionalMemberLengthOf(node.argument, access))) return true;
|
|
16406
|
+
if (node.type !== AST_NODE_TYPES81.BinaryExpression || !["==", "==="].includes(node.operator)) {
|
|
16281
16407
|
return false;
|
|
16282
16408
|
}
|
|
16283
|
-
const nullish = (value) => value.type ===
|
|
16409
|
+
const nullish = (value) => value.type === AST_NODE_TYPES81.Literal && value.value === null || value.type === AST_NODE_TYPES81.Identifier && value.name === "undefined";
|
|
16284
16410
|
return sameAccess(node.left, access) && nullish(node.right) || sameAccess(node.right, access) && nullish(node.left);
|
|
16285
16411
|
}
|
|
16286
16412
|
function isEmptyGuard(node, access) {
|
|
16287
|
-
if (node.type ===
|
|
16288
|
-
if (node.type !==
|
|
16413
|
+
if (node.type === AST_NODE_TYPES81.UnaryExpression && node.operator === "!" && memberLengthOf(node.argument, access)) return true;
|
|
16414
|
+
if (node.type !== AST_NODE_TYPES81.BinaryExpression || !["==", "===", "<="].includes(node.operator)) {
|
|
16289
16415
|
return false;
|
|
16290
16416
|
}
|
|
16291
|
-
const zero = (value) => value.type ===
|
|
16417
|
+
const zero = (value) => value.type === AST_NODE_TYPES81.Literal && value.value === 0;
|
|
16292
16418
|
return memberLengthOf(node.left, access) && zero(node.right) || node.operator !== "<=" && memberLengthOf(node.right, access) && zero(node.left);
|
|
16293
16419
|
}
|
|
16294
16420
|
function contains(node, visitorKeys, predicate) {
|
|
@@ -16298,30 +16424,30 @@ function contains(node, visitorKeys, predicate) {
|
|
|
16298
16424
|
function belongsToFunction(node, fn) {
|
|
16299
16425
|
let current = node;
|
|
16300
16426
|
while (current !== void 0 && current !== fn) {
|
|
16301
|
-
if (current !== node && (current.type ===
|
|
16427
|
+
if (current !== node && (current.type === AST_NODE_TYPES81.ArrowFunctionExpression || current.type === AST_NODE_TYPES81.FunctionDeclaration || current.type === AST_NODE_TYPES81.FunctionExpression)) return false;
|
|
16302
16428
|
current = current.parent;
|
|
16303
16429
|
}
|
|
16304
16430
|
return current === fn;
|
|
16305
16431
|
}
|
|
16306
16432
|
function directlyCoalesced(node) {
|
|
16307
16433
|
const parent = node.parent;
|
|
16308
|
-
return parent?.type ===
|
|
16434
|
+
return parent?.type === AST_NODE_TYPES81.LogicalExpression && parent.left === node && (parent.operator === "??" || parent.operator === "||") && emptyArray(parent.right);
|
|
16309
16435
|
}
|
|
16310
16436
|
function identifierIsOnlyCoalesced(context, binding, fn) {
|
|
16311
|
-
const variable =
|
|
16437
|
+
const variable = ASTUtils39.findVariable(context.sourceCode.getScope(binding), binding.name);
|
|
16312
16438
|
if (variable === null || variable.references.length === 0) return false;
|
|
16313
16439
|
return variable.references.every(
|
|
16314
16440
|
(reference) => belongsToFunction(reference.identifier, fn) && directlyCoalesced(reference.identifier)
|
|
16315
16441
|
);
|
|
16316
16442
|
}
|
|
16317
16443
|
function memberIsOnlyCoalesced(context, object, property, fn) {
|
|
16318
|
-
const variable =
|
|
16444
|
+
const variable = ASTUtils39.findVariable(context.sourceCode.getScope(object), object.name);
|
|
16319
16445
|
if (variable === null) return false;
|
|
16320
16446
|
const accesses = variable.references.flatMap((reference) => {
|
|
16321
16447
|
if (!belongsToFunction(reference.identifier, fn)) return [null];
|
|
16322
16448
|
const parent = reference.identifier.parent;
|
|
16323
|
-
if (parent?.type ===
|
|
16324
|
-
return parent?.type ===
|
|
16449
|
+
if (parent?.type === AST_NODE_TYPES81.MemberExpression && !parent.computed && parent.object === reference.identifier && parent.property.type === AST_NODE_TYPES81.Identifier && parent.property.name === property) return [parent];
|
|
16450
|
+
return parent?.type === AST_NODE_TYPES81.MemberExpression && parent.object === reference.identifier ? [] : [null];
|
|
16325
16451
|
});
|
|
16326
16452
|
return accesses.length > 0 && accesses.every((access) => access !== null && directlyCoalesced(access));
|
|
16327
16453
|
}
|
|
@@ -16346,8 +16472,8 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
16346
16472
|
let shapes = /* @__PURE__ */ new Map();
|
|
16347
16473
|
const evidence = /* @__PURE__ */ new Map();
|
|
16348
16474
|
function propertiesFor(annotation) {
|
|
16349
|
-
if (annotation?.type ===
|
|
16350
|
-
if (annotation?.type ===
|
|
16475
|
+
if (annotation?.type === AST_NODE_TYPES81.TSTypeLiteral) return shapeProperties(annotation.members);
|
|
16476
|
+
if (annotation?.type === AST_NODE_TYPES81.TSTypeReference && annotation.typeName.type === AST_NODE_TYPES81.Identifier) {
|
|
16351
16477
|
const shape = shapes.get(annotation.typeName.name);
|
|
16352
16478
|
return shape?.exported === false ? shape.properties : [];
|
|
16353
16479
|
}
|
|
@@ -16360,13 +16486,13 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
16360
16486
|
}
|
|
16361
16487
|
function checkFunction(fn) {
|
|
16362
16488
|
function checkParameter(rawParameter) {
|
|
16363
|
-
const parameter = rawParameter.type ===
|
|
16364
|
-
if (parameter.type ===
|
|
16489
|
+
const parameter = rawParameter.type === AST_NODE_TYPES81.AssignmentPattern ? rawParameter.left : rawParameter;
|
|
16490
|
+
if (parameter.type === AST_NODE_TYPES81.ObjectPattern) {
|
|
16365
16491
|
const properties2 = propertiesFor(parameter.typeAnnotation?.typeAnnotation);
|
|
16366
16492
|
checkDestructuredProperties(parameter, properties2);
|
|
16367
16493
|
return;
|
|
16368
16494
|
}
|
|
16369
|
-
if (parameter.type !==
|
|
16495
|
+
if (parameter.type !== AST_NODE_TYPES81.Identifier) return;
|
|
16370
16496
|
const properties = propertiesFor(parameter.typeAnnotation?.typeAnnotation);
|
|
16371
16497
|
for (const property of properties) {
|
|
16372
16498
|
const access = {
|
|
@@ -16383,16 +16509,16 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
16383
16509
|
function checkDestructuredProperties(parameter, properties) {
|
|
16384
16510
|
for (const property of properties) {
|
|
16385
16511
|
const bindingProperty = parameter.properties.find(
|
|
16386
|
-
(entry) => entry.type ===
|
|
16512
|
+
(entry) => entry.type === AST_NODE_TYPES81.Property && !entry.computed && entry.key.type === AST_NODE_TYPES81.Identifier && entry.key.name === property.name
|
|
16387
16513
|
);
|
|
16388
16514
|
if (bindingProperty === void 0) continue;
|
|
16389
16515
|
const value = bindingProperty.value;
|
|
16390
|
-
const binding = value.type ===
|
|
16391
|
-
if (binding.type !==
|
|
16516
|
+
const binding = value.type === AST_NODE_TYPES81.AssignmentPattern ? value.left : value;
|
|
16517
|
+
if (binding.type !== AST_NODE_TYPES81.Identifier) {
|
|
16392
16518
|
record(property, false);
|
|
16393
16519
|
continue;
|
|
16394
16520
|
}
|
|
16395
|
-
if (value.type ===
|
|
16521
|
+
if (value.type === AST_NODE_TYPES81.AssignmentPattern && emptyArray(value.right) && property.acceptsUndefined && !property.acceptsNull) {
|
|
16396
16522
|
record(property, true);
|
|
16397
16523
|
continue;
|
|
16398
16524
|
}
|
|
@@ -16430,8 +16556,8 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
16430
16556
|
|
|
16431
16557
|
// src/rules/prefer-nullish-filter-predicate.ts
|
|
16432
16558
|
import {
|
|
16433
|
-
AST_NODE_TYPES as
|
|
16434
|
-
ASTUtils as
|
|
16559
|
+
AST_NODE_TYPES as AST_NODE_TYPES82,
|
|
16560
|
+
ASTUtils as ASTUtils40,
|
|
16435
16561
|
ESLintUtils as ESLintUtils11
|
|
16436
16562
|
} from "@typescript-eslint/utils";
|
|
16437
16563
|
import ts9 from "typescript";
|
|
@@ -16477,7 +16603,7 @@ var PREFER_NULLISH_FILTER_PREDICATE_DOCUMENTATION = {
|
|
|
16477
16603
|
]
|
|
16478
16604
|
};
|
|
16479
16605
|
function isUnshadowedBoolean(node, context) {
|
|
16480
|
-
const variable =
|
|
16606
|
+
const variable = ASTUtils40.findVariable(context.sourceCode.getScope(node), node.name);
|
|
16481
16607
|
return variable === null || variable.defs.length === 0;
|
|
16482
16608
|
}
|
|
16483
16609
|
function isBuiltinArrayFilter(node, services) {
|
|
@@ -16536,7 +16662,7 @@ function isProvablyTruthy(type, checker) {
|
|
|
16536
16662
|
}
|
|
16537
16663
|
function availableParameterName(node, context) {
|
|
16538
16664
|
for (const name of ["value", "item", "element", "candidate"]) {
|
|
16539
|
-
if (
|
|
16665
|
+
if (ASTUtils40.findVariable(context.sourceCode.getScope(node), name) === null) return name;
|
|
16540
16666
|
}
|
|
16541
16667
|
return null;
|
|
16542
16668
|
}
|
|
@@ -16567,7 +16693,7 @@ var prefer_nullish_filter_predicate_default = createRule({
|
|
|
16567
16693
|
CallExpression(node) {
|
|
16568
16694
|
const callee = node.callee;
|
|
16569
16695
|
const callback = node.arguments[0];
|
|
16570
|
-
if (node.arguments.length !== 1 || callback?.type !==
|
|
16696
|
+
if (node.arguments.length !== 1 || callback?.type !== AST_NODE_TYPES82.Identifier || callback.name !== "Boolean" || callee.type !== AST_NODE_TYPES82.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES82.Identifier || callee.property.name !== "filter" || !isUnshadowedBoolean(callback, context) || !isBuiltinArrayFilter(callee, services)) return;
|
|
16571
16697
|
const elementType = arrayElementType(callee.object, services);
|
|
16572
16698
|
const checker = services.program.getTypeChecker();
|
|
16573
16699
|
if (elementType === null || !isNullishPlusTruthy(elementType, checker)) return;
|
|
@@ -16590,9 +16716,9 @@ var prefer_nullish_filter_predicate_default = createRule({
|
|
|
16590
16716
|
|
|
16591
16717
|
// src/rules/prefer-await-in-async-return.ts
|
|
16592
16718
|
import {
|
|
16593
|
-
ASTUtils as
|
|
16719
|
+
ASTUtils as ASTUtils41,
|
|
16594
16720
|
ESLintUtils as ESLintUtils12,
|
|
16595
|
-
AST_NODE_TYPES as
|
|
16721
|
+
AST_NODE_TYPES as AST_NODE_TYPES83
|
|
16596
16722
|
} from "@typescript-eslint/utils";
|
|
16597
16723
|
import * as ts10 from "typescript";
|
|
16598
16724
|
var PREFER_AWAIT_IN_ASYNC_RETURN_DOCUMENTATION = {
|
|
@@ -16635,10 +16761,10 @@ var PREFER_AWAIT_IN_ASYNC_RETURN_DOCUMENTATION = {
|
|
|
16635
16761
|
};
|
|
16636
16762
|
function directAsyncReturnOwner(node) {
|
|
16637
16763
|
const parent = node.parent;
|
|
16638
|
-
if (parent.type ===
|
|
16764
|
+
if (parent.type === AST_NODE_TYPES83.ArrowFunctionExpression && parent.body === node) {
|
|
16639
16765
|
return parent.async && !parent.generator ? parent : null;
|
|
16640
16766
|
}
|
|
16641
|
-
if (parent.type !==
|
|
16767
|
+
if (parent.type !== AST_NODE_TYPES83.ReturnStatement || parent.argument !== node) {
|
|
16642
16768
|
return null;
|
|
16643
16769
|
}
|
|
16644
16770
|
let owner = parent.parent;
|
|
@@ -16648,15 +16774,15 @@ function directAsyncReturnOwner(node) {
|
|
|
16648
16774
|
return owner !== void 0 && owner.async && !owner.generator ? owner : null;
|
|
16649
16775
|
}
|
|
16650
16776
|
function isRuntimeFunction(node) {
|
|
16651
|
-
return node.type ===
|
|
16777
|
+
return node.type === AST_NODE_TYPES83.ArrowFunctionExpression || node.type === AST_NODE_TYPES83.FunctionDeclaration || node.type === AST_NODE_TYPES83.FunctionExpression;
|
|
16652
16778
|
}
|
|
16653
16779
|
function promiseThenReceiver(node) {
|
|
16654
16780
|
const callee = node.callee;
|
|
16655
|
-
if (callee.type !==
|
|
16781
|
+
if (callee.type !== AST_NODE_TYPES83.MemberExpression || callee.computed || callee.optional || callee.property.type !== AST_NODE_TYPES83.Identifier || callee.property.name !== "then" || node.optional || node.arguments.length !== 1) {
|
|
16656
16782
|
return null;
|
|
16657
16783
|
}
|
|
16658
16784
|
const callback = node.arguments[0];
|
|
16659
|
-
if (callback === void 0 || callback.type !==
|
|
16785
|
+
if (callback === void 0 || callback.type !== AST_NODE_TYPES83.ArrowFunctionExpression && callback.type !== AST_NODE_TYPES83.FunctionExpression) {
|
|
16660
16786
|
return null;
|
|
16661
16787
|
}
|
|
16662
16788
|
return callee.object;
|
|
@@ -16704,25 +16830,25 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
16704
16830
|
if (services === null) return {};
|
|
16705
16831
|
const frameworkLoaders = /* @__PURE__ */ new Set();
|
|
16706
16832
|
const rememberFrameworkLoader = (identifier) => {
|
|
16707
|
-
const variable =
|
|
16833
|
+
const variable = ASTUtils41.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
16708
16834
|
if (variable !== null) frameworkLoaders.add(variable);
|
|
16709
16835
|
};
|
|
16710
16836
|
const isFrameworkLoaderCallback = (owner) => {
|
|
16711
16837
|
const parent = owner.parent;
|
|
16712
|
-
if (parent.type !==
|
|
16713
|
-
const variable =
|
|
16838
|
+
if (parent.type !== AST_NODE_TYPES83.CallExpression || parent.arguments[0] !== owner || parent.callee.type !== AST_NODE_TYPES83.Identifier) return false;
|
|
16839
|
+
const variable = ASTUtils41.findVariable(context.sourceCode.getScope(parent.callee), parent.callee.name);
|
|
16714
16840
|
return variable !== null && frameworkLoaders.has(variable);
|
|
16715
16841
|
};
|
|
16716
16842
|
return {
|
|
16717
16843
|
ImportDeclaration(node) {
|
|
16718
16844
|
if (node.source.value === "react") {
|
|
16719
16845
|
for (const specifier of node.specifiers) {
|
|
16720
|
-
if (specifier.type ===
|
|
16846
|
+
if (specifier.type === AST_NODE_TYPES83.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES83.Identifier ? specifier.imported.name : specifier.imported.value) === "lazy") rememberFrameworkLoader(specifier.local);
|
|
16721
16847
|
}
|
|
16722
16848
|
}
|
|
16723
16849
|
if (node.source.value === "next/dynamic") {
|
|
16724
16850
|
for (const specifier of node.specifiers) {
|
|
16725
|
-
if (specifier.type ===
|
|
16851
|
+
if (specifier.type === AST_NODE_TYPES83.ImportDefaultSpecifier) rememberFrameworkLoader(specifier.local);
|
|
16726
16852
|
}
|
|
16727
16853
|
}
|
|
16728
16854
|
},
|
|
@@ -16740,7 +16866,7 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
16740
16866
|
});
|
|
16741
16867
|
|
|
16742
16868
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
16743
|
-
import { AST_NODE_TYPES as
|
|
16869
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES84, ASTUtils as ASTUtils42 } from "@typescript-eslint/utils";
|
|
16744
16870
|
var PREFER_SCHEMA_FOR_API_PAYLOAD_DOCUMENTATION = {
|
|
16745
16871
|
summary: "Require Zod (or similar) schema validation on `response.json()` / `JSON.parse()` results before property access.",
|
|
16746
16872
|
rationale: "External JSON is untrusted at runtime even when its expected TypeScript shape is known statically.",
|
|
@@ -16760,9 +16886,9 @@ var PREFER_SCHEMA_FOR_API_PAYLOAD_DOCUMENTATION = {
|
|
|
16760
16886
|
var unwrap6 = (node) => {
|
|
16761
16887
|
let current = node;
|
|
16762
16888
|
while (current !== null && current !== void 0) {
|
|
16763
|
-
if (current.type ===
|
|
16889
|
+
if (current.type === AST_NODE_TYPES84.TSAsExpression || current.type === AST_NODE_TYPES84.TSTypeAssertion || current.type === AST_NODE_TYPES84.TSNonNullExpression || current.type === AST_NODE_TYPES84.TSSatisfiesExpression) {
|
|
16764
16890
|
current = current.expression;
|
|
16765
|
-
} else if (current.type ===
|
|
16891
|
+
} else if (current.type === AST_NODE_TYPES84.ChainExpression) {
|
|
16766
16892
|
current = current.expression;
|
|
16767
16893
|
} else {
|
|
16768
16894
|
break;
|
|
@@ -16777,23 +16903,23 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
16777
16903
|
]);
|
|
16778
16904
|
var isSchemaParseReference = (node) => {
|
|
16779
16905
|
const inner = unwrap6(node);
|
|
16780
|
-
return inner !== null && inner.type ===
|
|
16906
|
+
return inner !== null && inner.type === AST_NODE_TYPES84.MemberExpression && !inner.computed && inner.property.type === AST_NODE_TYPES84.Identifier && (inner.property.name === "parse" || inner.property.name === "safeParse");
|
|
16781
16907
|
};
|
|
16782
16908
|
var isRawPayloadSource = (node, context, isKnownLocalText) => {
|
|
16783
16909
|
let current = unwrap6(node);
|
|
16784
16910
|
if (current === null) return false;
|
|
16785
|
-
if (current.type ===
|
|
16911
|
+
if (current.type === AST_NODE_TYPES84.AwaitExpression) {
|
|
16786
16912
|
current = unwrap6(current.argument);
|
|
16787
16913
|
}
|
|
16788
|
-
if (current === null || current.type !==
|
|
16914
|
+
if (current === null || current.type !== AST_NODE_TYPES84.CallExpression) {
|
|
16789
16915
|
return false;
|
|
16790
16916
|
}
|
|
16791
16917
|
const callee = unwrap6(current.callee);
|
|
16792
|
-
if (callee === null || callee.type !==
|
|
16918
|
+
if (callee === null || callee.type !== AST_NODE_TYPES84.MemberExpression) {
|
|
16793
16919
|
return false;
|
|
16794
16920
|
}
|
|
16795
16921
|
const property = unwrap6(callee.property);
|
|
16796
|
-
if (property === null || property.type !==
|
|
16922
|
+
if (property === null || property.type !== AST_NODE_TYPES84.Identifier) {
|
|
16797
16923
|
return false;
|
|
16798
16924
|
}
|
|
16799
16925
|
if (property.name === "json") {
|
|
@@ -16804,34 +16930,34 @@ var isRawPayloadSource = (node, context, isKnownLocalText) => {
|
|
|
16804
16930
|
}
|
|
16805
16931
|
const object = unwrap6(callee.object);
|
|
16806
16932
|
const input = unwrap6(current.arguments[0]);
|
|
16807
|
-
if (input?.type ===
|
|
16808
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
16933
|
+
if (input?.type === AST_NODE_TYPES84.CallExpression && input.arguments.length === 1 && input.callee.type === AST_NODE_TYPES84.MemberExpression && !input.callee.computed && input.callee.object.type === AST_NODE_TYPES84.Identifier && input.callee.object.name === "JSON" && input.callee.property.type === AST_NODE_TYPES84.Identifier && input.callee.property.name === "stringify" && (ASTUtils42.findVariable(context.sourceCode.getScope(input.callee.object), "JSON")?.defs.length ?? 0) === 0) return false;
|
|
16934
|
+
return property.name === "parse" && object !== null && object.type === AST_NODE_TYPES84.Identifier && object.name === "JSON" && (ASTUtils42.findVariable(context.sourceCode.getScope(object), "JSON")?.defs.length ?? 0) === 0 && !isLocalFileRead(current.arguments[0]) && isKnownLocalText?.(current.arguments[0]) !== true;
|
|
16809
16935
|
};
|
|
16810
16936
|
var isResponseSource = (node, context, seen = /* @__PURE__ */ new Set()) => {
|
|
16811
16937
|
let current = unwrap6(node);
|
|
16812
|
-
if (current?.type ===
|
|
16938
|
+
if (current?.type === AST_NODE_TYPES84.AwaitExpression) current = unwrap6(current.argument);
|
|
16813
16939
|
if (current === null || seen.has(current)) return false;
|
|
16814
16940
|
seen.add(current);
|
|
16815
|
-
const isGlobal = (identifier) => (
|
|
16816
|
-
if (current.type ===
|
|
16817
|
-
if (current.type ===
|
|
16818
|
-
if (current.type !==
|
|
16819
|
-
const binding =
|
|
16941
|
+
const isGlobal = (identifier) => (ASTUtils42.findVariable(context.sourceCode.getScope(identifier), identifier.name)?.defs.length ?? 0) === 0;
|
|
16942
|
+
if (current.type === AST_NODE_TYPES84.CallExpression) return current.callee.type === AST_NODE_TYPES84.Identifier && current.callee.name === "fetch" && isGlobal(current.callee);
|
|
16943
|
+
if (current.type === AST_NODE_TYPES84.NewExpression) return current.callee.type === AST_NODE_TYPES84.Identifier && ["Request", "Response"].includes(current.callee.name) && isGlobal(current.callee);
|
|
16944
|
+
if (current.type !== AST_NODE_TYPES84.Identifier) return false;
|
|
16945
|
+
const binding = ASTUtils42.findVariable(context.sourceCode.getScope(current), current.name);
|
|
16820
16946
|
if (binding?.defs.length !== 1 || binding.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
16821
16947
|
const definition = binding.defs[0];
|
|
16822
|
-
const annotation = definition?.name.type ===
|
|
16823
|
-
if (annotation?.type ===
|
|
16948
|
+
const annotation = definition?.name.type === AST_NODE_TYPES84.Identifier ? definition.name.typeAnnotation?.typeAnnotation : void 0;
|
|
16949
|
+
if (annotation?.type === AST_NODE_TYPES84.TSTypeReference && annotation.typeName.type === AST_NODE_TYPES84.Identifier && ["Request", "Response"].includes(annotation.typeName.name) && isGlobal(annotation.typeName)) return true;
|
|
16824
16950
|
return definition?.type === "Variable" && definition.parent.kind === "const" && definition.node.init !== null && isResponseSource(definition.node.init, context, seen);
|
|
16825
16951
|
};
|
|
16826
16952
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
16827
16953
|
var isDirectLocalFileRead = (node) => {
|
|
16828
16954
|
let current = unwrap6(node);
|
|
16829
|
-
if (current?.type ===
|
|
16955
|
+
if (current?.type === AST_NODE_TYPES84.AwaitExpression) {
|
|
16830
16956
|
current = unwrap6(current.argument);
|
|
16831
16957
|
}
|
|
16832
|
-
if (current?.type !==
|
|
16958
|
+
if (current?.type !== AST_NODE_TYPES84.CallExpression) return false;
|
|
16833
16959
|
const callee = unwrap6(current.callee);
|
|
16834
|
-
const name = callee?.type ===
|
|
16960
|
+
const name = callee?.type === AST_NODE_TYPES84.Identifier ? callee.name : callee?.type === AST_NODE_TYPES84.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES84.Identifier ? callee.property.name : null;
|
|
16835
16961
|
return name !== null && FILE_READ_RE.test(name);
|
|
16836
16962
|
};
|
|
16837
16963
|
var isLocalFileRead = (node) => {
|
|
@@ -16853,15 +16979,15 @@ var isLocalFileRead = (node) => {
|
|
|
16853
16979
|
var ASSERTION_CALLEE_RE = /^(expect|assert|should|invariant)$/;
|
|
16854
16980
|
var isInsideAssertion = (node) => {
|
|
16855
16981
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
16856
|
-
if (current.type !==
|
|
16982
|
+
if (current.type !== AST_NODE_TYPES84.CallExpression) continue;
|
|
16857
16983
|
let callee = current.callee;
|
|
16858
|
-
while (callee.type ===
|
|
16984
|
+
while (callee.type === AST_NODE_TYPES84.MemberExpression) {
|
|
16859
16985
|
callee = callee.object;
|
|
16860
16986
|
}
|
|
16861
|
-
if (callee.type ===
|
|
16987
|
+
if (callee.type === AST_NODE_TYPES84.CallExpression) {
|
|
16862
16988
|
callee = callee.callee;
|
|
16863
16989
|
}
|
|
16864
|
-
if (callee.type ===
|
|
16990
|
+
if (callee.type === AST_NODE_TYPES84.Identifier && ASSERTION_CALLEE_RE.test(callee.name)) {
|
|
16865
16991
|
return true;
|
|
16866
16992
|
}
|
|
16867
16993
|
}
|
|
@@ -16880,22 +17006,22 @@ var GUARD_NAME_RE = /^(?:is|validate|parse|assert|decode|coerce)[A-Z]/;
|
|
|
16880
17006
|
var isValidationRead = (node) => {
|
|
16881
17007
|
let current = node;
|
|
16882
17008
|
let parent = current.parent;
|
|
16883
|
-
while (parent !== null && parent !== void 0 && (parent.type ===
|
|
17009
|
+
while (parent !== null && parent !== void 0 && (parent.type === AST_NODE_TYPES84.TSAsExpression || parent.type === AST_NODE_TYPES84.TSTypeAssertion || parent.type === AST_NODE_TYPES84.TSNonNullExpression || parent.type === AST_NODE_TYPES84.TSSatisfiesExpression || parent.type === AST_NODE_TYPES84.ChainExpression)) {
|
|
16884
17010
|
current = parent;
|
|
16885
17011
|
parent = parent.parent;
|
|
16886
17012
|
}
|
|
16887
17013
|
if (parent === null || parent === void 0) return false;
|
|
16888
|
-
if (parent.type ===
|
|
17014
|
+
if (parent.type === AST_NODE_TYPES84.UnaryExpression && parent.operator === "typeof" && parent.argument === current) {
|
|
16889
17015
|
return true;
|
|
16890
17016
|
}
|
|
16891
|
-
if (parent.type !==
|
|
17017
|
+
if (parent.type !== AST_NODE_TYPES84.CallExpression || !parent.arguments.some((arg) => arg === current)) {
|
|
16892
17018
|
return false;
|
|
16893
17019
|
}
|
|
16894
17020
|
const callee = parent.callee;
|
|
16895
|
-
if (callee.type ===
|
|
17021
|
+
if (callee.type === AST_NODE_TYPES84.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES84.Identifier && callee.object.name === "Array" && callee.property.type === AST_NODE_TYPES84.Identifier && callee.property.name === "isArray") {
|
|
16896
17022
|
return parent.arguments.length === 1;
|
|
16897
17023
|
}
|
|
16898
|
-
return callee.type ===
|
|
17024
|
+
return callee.type === AST_NODE_TYPES84.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
16899
17025
|
};
|
|
16900
17026
|
var PRIMITIVE_TYPEOF_RESULTS = /* @__PURE__ */ new Set([
|
|
16901
17027
|
"bigint",
|
|
@@ -16906,13 +17032,13 @@ var PRIMITIVE_TYPEOF_RESULTS = /* @__PURE__ */ new Set([
|
|
|
16906
17032
|
"undefined"
|
|
16907
17033
|
]);
|
|
16908
17034
|
var bindingValidationPolarity = (test, bindingName) => {
|
|
16909
|
-
if (test.type ===
|
|
17035
|
+
if (test.type === AST_NODE_TYPES84.UnaryExpression && test.operator === "!") {
|
|
16910
17036
|
const inner = bindingValidationPolarity(test.argument, bindingName);
|
|
16911
17037
|
return invertValidationPolarity(inner);
|
|
16912
17038
|
}
|
|
16913
|
-
if (test.type ===
|
|
16914
|
-
const typeofName = (node) => node.type ===
|
|
16915
|
-
const literalType = (node) => node.type ===
|
|
17039
|
+
if (test.type === AST_NODE_TYPES84.BinaryExpression) {
|
|
17040
|
+
const typeofName = (node) => node.type === AST_NODE_TYPES84.UnaryExpression && node.operator === "typeof" && node.argument.type === AST_NODE_TYPES84.Identifier ? node.argument.name : null;
|
|
17041
|
+
const literalType = (node) => node.type === AST_NODE_TYPES84.Literal && typeof node.value === "string" && PRIMITIVE_TYPEOF_RESULTS.has(node.value) ? node.value : null;
|
|
16916
17042
|
const matches = typeofName(test.left) === bindingName && literalType(test.right) !== null || typeofName(test.right) === bindingName && literalType(test.left) !== null;
|
|
16917
17043
|
if (!matches) return null;
|
|
16918
17044
|
if (test.operator === "===" || test.operator === "==") {
|
|
@@ -16920,9 +17046,9 @@ var bindingValidationPolarity = (test, bindingName) => {
|
|
|
16920
17046
|
}
|
|
16921
17047
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
16922
17048
|
}
|
|
16923
|
-
return test.type ===
|
|
17049
|
+
return test.type === AST_NODE_TYPES84.CallExpression && test.arguments.length === 1 && test.arguments[0]?.type === AST_NODE_TYPES84.Identifier && test.arguments[0].name === bindingName && test.callee.type === AST_NODE_TYPES84.MemberExpression && !test.callee.computed && test.callee.object.type === AST_NODE_TYPES84.Identifier && test.callee.object.name === "Array" && test.callee.property.type === AST_NODE_TYPES84.Identifier && test.callee.property.name === "isArray" ? "valid-when-true" : null;
|
|
16924
17050
|
};
|
|
16925
|
-
var plainMemberAccess = (node) => node.type ===
|
|
17051
|
+
var plainMemberAccess = (node) => node.type === AST_NODE_TYPES84.MemberExpression && !node.computed && node.object.type === AST_NODE_TYPES84.Identifier && node.property.type === AST_NODE_TYPES84.Identifier ? { object: node.object.name, property: node.property.name } : null;
|
|
16926
17052
|
var isSamePlainMember = (node, access) => {
|
|
16927
17053
|
const candidate2 = plainMemberAccess(node);
|
|
16928
17054
|
return candidate2 !== null && candidate2.object === access.object && candidate2.property === access.property;
|
|
@@ -16930,19 +17056,19 @@ var isSamePlainMember = (node, access) => {
|
|
|
16930
17056
|
var nodeWithin2 = (node, container) => node.range[0] >= container.range[0] && node.range[1] <= container.range[1];
|
|
16931
17057
|
var isUseWithinValidatedBranch = (node, bindingName) => {
|
|
16932
17058
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
16933
|
-
if (current.type ===
|
|
17059
|
+
if (current.type === AST_NODE_TYPES84.ConditionalExpression) {
|
|
16934
17060
|
const polarity = bindingValidationPolarity(current.test, bindingName);
|
|
16935
17061
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && nodeWithin2(node, current.alternate)) {
|
|
16936
17062
|
return true;
|
|
16937
17063
|
}
|
|
16938
17064
|
}
|
|
16939
|
-
if (current.type ===
|
|
17065
|
+
if (current.type === AST_NODE_TYPES84.IfStatement) {
|
|
16940
17066
|
const polarity = bindingValidationPolarity(current.test, bindingName);
|
|
16941
17067
|
if (validatedBranchContains(node, current, polarity)) {
|
|
16942
17068
|
return true;
|
|
16943
17069
|
}
|
|
16944
17070
|
}
|
|
16945
|
-
if (current.type ===
|
|
17071
|
+
if (current.type === AST_NODE_TYPES84.FunctionDeclaration || current.type === AST_NODE_TYPES84.FunctionExpression || current.type === AST_NODE_TYPES84.ArrowFunctionExpression) {
|
|
16946
17072
|
return false;
|
|
16947
17073
|
}
|
|
16948
17074
|
}
|
|
@@ -16950,32 +17076,32 @@ var isUseWithinValidatedBranch = (node, bindingName) => {
|
|
|
16950
17076
|
};
|
|
16951
17077
|
var isMemberUseWithinValidatedBranch = (node, access) => {
|
|
16952
17078
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
16953
|
-
if (current.type ===
|
|
17079
|
+
if (current.type === AST_NODE_TYPES84.ConditionalExpression) {
|
|
16954
17080
|
const polarity = memberValidationPolarity(current.test, access);
|
|
16955
17081
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && nodeWithin2(node, current.alternate)) {
|
|
16956
17082
|
return true;
|
|
16957
17083
|
}
|
|
16958
17084
|
}
|
|
16959
|
-
if (current.type ===
|
|
17085
|
+
if (current.type === AST_NODE_TYPES84.IfStatement) {
|
|
16960
17086
|
const polarity = memberValidationPolarity(current.test, access);
|
|
16961
17087
|
if (validatedBranchContains(node, current, polarity)) {
|
|
16962
17088
|
return true;
|
|
16963
17089
|
}
|
|
16964
17090
|
}
|
|
16965
|
-
if (current.type ===
|
|
17091
|
+
if (current.type === AST_NODE_TYPES84.FunctionDeclaration || current.type === AST_NODE_TYPES84.FunctionExpression || current.type === AST_NODE_TYPES84.ArrowFunctionExpression) {
|
|
16966
17092
|
return false;
|
|
16967
17093
|
}
|
|
16968
17094
|
}
|
|
16969
17095
|
return false;
|
|
16970
17096
|
};
|
|
16971
17097
|
var memberValidationPolarity = (test, access) => {
|
|
16972
|
-
if (test.type ===
|
|
17098
|
+
if (test.type === AST_NODE_TYPES84.UnaryExpression && test.operator === "!") {
|
|
16973
17099
|
const inner = memberValidationPolarity(test.argument, access);
|
|
16974
17100
|
return invertValidationPolarity(inner);
|
|
16975
17101
|
}
|
|
16976
|
-
if (test.type ===
|
|
16977
|
-
const isMatchingTypeof = (node) => node.type ===
|
|
16978
|
-
const isPrimitiveType = (node) => node.type ===
|
|
17102
|
+
if (test.type === AST_NODE_TYPES84.BinaryExpression) {
|
|
17103
|
+
const isMatchingTypeof = (node) => node.type === AST_NODE_TYPES84.UnaryExpression && node.operator === "typeof" && isSamePlainMember(node.argument, access);
|
|
17104
|
+
const isPrimitiveType = (node) => node.type === AST_NODE_TYPES84.Literal && typeof node.value === "string" && PRIMITIVE_TYPEOF_RESULTS.has(node.value);
|
|
16979
17105
|
if (!(isMatchingTypeof(test.left) && isPrimitiveType(test.right) || isMatchingTypeof(test.right) && isPrimitiveType(test.left))) {
|
|
16980
17106
|
return null;
|
|
16981
17107
|
}
|
|
@@ -16984,15 +17110,15 @@ var memberValidationPolarity = (test, access) => {
|
|
|
16984
17110
|
}
|
|
16985
17111
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
16986
17112
|
}
|
|
16987
|
-
return test.type ===
|
|
17113
|
+
return test.type === AST_NODE_TYPES84.CallExpression && test.arguments.length === 1 && test.arguments[0] !== void 0 && test.arguments[0].type !== AST_NODE_TYPES84.SpreadElement && isSamePlainMember(test.arguments[0], access) && test.callee.type === AST_NODE_TYPES84.MemberExpression && !test.callee.computed && test.callee.object.type === AST_NODE_TYPES84.Identifier && test.callee.object.name === "Array" && test.callee.property.type === AST_NODE_TYPES84.Identifier && test.callee.property.name === "isArray" ? "valid-when-true" : null;
|
|
16988
17114
|
};
|
|
16989
17115
|
var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
16990
17116
|
const isValidationReference = (identifier) => {
|
|
16991
17117
|
for (let current = identifier.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
16992
|
-
if ((current.type ===
|
|
17118
|
+
if ((current.type === AST_NODE_TYPES84.BinaryExpression || current.type === AST_NODE_TYPES84.CallExpression || current.type === AST_NODE_TYPES84.UnaryExpression) && bindingValidationPolarity(current, identifier.name) !== null) {
|
|
16993
17119
|
return true;
|
|
16994
17120
|
}
|
|
16995
|
-
if (current.type !==
|
|
17121
|
+
if (current.type !== AST_NODE_TYPES84.UnaryExpression && current.type !== AST_NODE_TYPES84.MemberExpression && current.type !== AST_NODE_TYPES84.CallExpression) {
|
|
16996
17122
|
return false;
|
|
16997
17123
|
}
|
|
16998
17124
|
}
|
|
@@ -17000,7 +17126,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
17000
17126
|
};
|
|
17001
17127
|
const isGuardedUse = (identifier) => isUseWithinValidatedBranch(identifier, identifier.name);
|
|
17002
17128
|
const declarator = member.parent;
|
|
17003
|
-
if (declarator.type !==
|
|
17129
|
+
if (declarator.type !== AST_NODE_TYPES84.VariableDeclarator || declarator.init !== member || declarator.id.type !== AST_NODE_TYPES84.Identifier || declarator.parent.type !== AST_NODE_TYPES84.VariableDeclaration || declarator.parent.kind !== "const") {
|
|
17004
17130
|
return false;
|
|
17005
17131
|
}
|
|
17006
17132
|
const extracted = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
@@ -17008,7 +17134,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
17008
17134
|
let hasValueUse = false;
|
|
17009
17135
|
for (const reference of extracted.references) {
|
|
17010
17136
|
const identifier = reference.identifier;
|
|
17011
|
-
if (identifier.type !==
|
|
17137
|
+
if (identifier.type !== AST_NODE_TYPES84.Identifier) return false;
|
|
17012
17138
|
if (nodeWithin2(identifier, declarator)) continue;
|
|
17013
17139
|
if (isValidationReference(identifier)) continue;
|
|
17014
17140
|
hasValueUse = true;
|
|
@@ -17021,17 +17147,17 @@ var isGuardTestPosition = (node) => {
|
|
|
17021
17147
|
let parent = current.parent;
|
|
17022
17148
|
while (parent !== void 0 && parent !== null) {
|
|
17023
17149
|
switch (parent.type) {
|
|
17024
|
-
case
|
|
17025
|
-
case
|
|
17026
|
-
case
|
|
17150
|
+
case AST_NODE_TYPES84.UnaryExpression:
|
|
17151
|
+
case AST_NODE_TYPES84.LogicalExpression:
|
|
17152
|
+
case AST_NODE_TYPES84.ChainExpression:
|
|
17027
17153
|
current = parent;
|
|
17028
17154
|
parent = parent.parent;
|
|
17029
17155
|
continue;
|
|
17030
|
-
case
|
|
17031
|
-
case
|
|
17032
|
-
case
|
|
17033
|
-
case
|
|
17034
|
-
case
|
|
17156
|
+
case AST_NODE_TYPES84.IfStatement:
|
|
17157
|
+
case AST_NODE_TYPES84.ConditionalExpression:
|
|
17158
|
+
case AST_NODE_TYPES84.WhileStatement:
|
|
17159
|
+
case AST_NODE_TYPES84.DoWhileStatement:
|
|
17160
|
+
case AST_NODE_TYPES84.ForStatement:
|
|
17035
17161
|
return parent.test === current;
|
|
17036
17162
|
default:
|
|
17037
17163
|
return false;
|
|
@@ -17041,7 +17167,7 @@ var isGuardTestPosition = (node) => {
|
|
|
17041
17167
|
};
|
|
17042
17168
|
var unvalidatedVariableRef = (node, scope, tracked) => {
|
|
17043
17169
|
const unwrapped = unwrap6(node);
|
|
17044
|
-
if (unwrapped === null || unwrapped.type !==
|
|
17170
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES84.Identifier) {
|
|
17045
17171
|
return null;
|
|
17046
17172
|
}
|
|
17047
17173
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -17073,24 +17199,24 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
17073
17199
|
if (context.sourceCode.getScope(use).variableScope !== context.sourceCode.getScope(call).variableScope) return false;
|
|
17074
17200
|
let guard = call;
|
|
17075
17201
|
let positive = true;
|
|
17076
|
-
while (guard.parent.type ===
|
|
17202
|
+
while (guard.parent.type === AST_NODE_TYPES84.UnaryExpression && guard.parent.operator === "!") {
|
|
17077
17203
|
positive = !positive;
|
|
17078
17204
|
guard = guard.parent;
|
|
17079
17205
|
}
|
|
17080
|
-
while (positive && guard.parent.type ===
|
|
17206
|
+
while (positive && guard.parent.type === AST_NODE_TYPES84.LogicalExpression && guard.parent.operator === "&&") guard = guard.parent;
|
|
17081
17207
|
const branch = guard.parent;
|
|
17082
|
-
if (branch.type ===
|
|
17208
|
+
if (branch.type === AST_NODE_TYPES84.IfStatement && branch.test === guard) {
|
|
17083
17209
|
const dominated = ifGuardDominates(use, branch, positive);
|
|
17084
17210
|
if (dominated !== null) return dominated;
|
|
17085
17211
|
}
|
|
17086
|
-
if (branch.type ===
|
|
17087
|
-
if (positive && branch.type ===
|
|
17088
|
-
if (call.parent.type !==
|
|
17212
|
+
if (branch.type === AST_NODE_TYPES84.ConditionalExpression && branch.test === guard) return nodeWithin2(use, positive ? branch.consequent : branch.alternate);
|
|
17213
|
+
if (positive && branch.type === AST_NODE_TYPES84.WhileStatement && branch.test === guard) return nodeWithin2(use, branch.body);
|
|
17214
|
+
if (call.parent.type !== AST_NODE_TYPES84.ExpressionStatement || call.callee.type !== AST_NODE_TYPES84.Identifier || /^(?:is|has)[A-Z]/u.test(call.callee.name)) return false;
|
|
17089
17215
|
return followsInSameContainer(use, call.parent);
|
|
17090
17216
|
};
|
|
17091
17217
|
const localFileTextRef = (node, scope) => {
|
|
17092
17218
|
const unwrapped = unwrap6(node);
|
|
17093
|
-
if (unwrapped?.type !==
|
|
17219
|
+
if (unwrapped?.type !== AST_NODE_TYPES84.Identifier) return null;
|
|
17094
17220
|
const variable = findVariable2(scope, unwrapped.name);
|
|
17095
17221
|
return variable !== null && localFileTextVariables.has(variable) ? variable : null;
|
|
17096
17222
|
};
|
|
@@ -17142,19 +17268,19 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
17142
17268
|
const statement = declarator.parent;
|
|
17143
17269
|
const block = statement.parent;
|
|
17144
17270
|
const followsRejectingGuard = (identifier) => {
|
|
17145
|
-
if (block.type !==
|
|
17271
|
+
if (block.type !== AST_NODE_TYPES84.BlockStatement && block.type !== AST_NODE_TYPES84.Program) return false;
|
|
17146
17272
|
if (context.sourceCode.getScope(identifier).variableScope !== context.sourceCode.getScope(declarator).variableScope) return false;
|
|
17147
17273
|
return block.body.some((candidate2) => {
|
|
17148
|
-
if (candidate2.type !==
|
|
17149
|
-
const terminal = candidate2.consequent.type ===
|
|
17150
|
-
return terminal?.type ===
|
|
17274
|
+
if (candidate2.type !== AST_NODE_TYPES84.IfStatement || candidate2.range[1] >= identifier.range[0] || bindingValidationPolarity(candidate2.test, identifier.name) !== "valid-when-false") return false;
|
|
17275
|
+
const terminal = candidate2.consequent.type === AST_NODE_TYPES84.BlockStatement ? candidate2.consequent.body.at(-1) : candidate2.consequent;
|
|
17276
|
+
return terminal?.type === AST_NODE_TYPES84.ThrowStatement || terminal?.type === AST_NODE_TYPES84.ReturnStatement;
|
|
17151
17277
|
});
|
|
17152
17278
|
};
|
|
17153
17279
|
return declared.length > 0 && declared.every(
|
|
17154
17280
|
(variable) => variable.references.some((reference) => isValidationRead(reference.identifier)) && variable.references.every((reference) => {
|
|
17155
17281
|
const identifier = reference.identifier;
|
|
17156
17282
|
if (reference.init === true) return true;
|
|
17157
|
-
if (reference.isWrite() || identifier.type !==
|
|
17283
|
+
if (reference.isWrite() || identifier.type !== AST_NODE_TYPES84.Identifier) return false;
|
|
17158
17284
|
return isValidationRead(identifier) || isUseWithinValidatedBranch(identifier, identifier.name) || followsRejectingGuard(identifier);
|
|
17159
17285
|
})
|
|
17160
17286
|
);
|
|
@@ -17174,7 +17300,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
17174
17300
|
return {
|
|
17175
17301
|
VariableDeclarator(node) {
|
|
17176
17302
|
const scope = context.sourceCode.getScope(node);
|
|
17177
|
-
if (node.id.type ===
|
|
17303
|
+
if (node.id.type === AST_NODE_TYPES84.Identifier) {
|
|
17178
17304
|
const variable = context.sourceCode.getDeclaredVariables(node)[0];
|
|
17179
17305
|
if (variable !== void 0) {
|
|
17180
17306
|
updateLocalFileText(variable, node.init, scope);
|
|
@@ -17182,7 +17308,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
17182
17308
|
trackInitializer(node, scope);
|
|
17183
17309
|
return;
|
|
17184
17310
|
}
|
|
17185
|
-
if (node.id.type ===
|
|
17311
|
+
if (node.id.type === AST_NODE_TYPES84.ObjectPattern || node.id.type === AST_NODE_TYPES84.ArrayPattern) {
|
|
17186
17312
|
if (isRawPayloadSource(
|
|
17187
17313
|
node.init,
|
|
17188
17314
|
context,
|
|
@@ -17200,7 +17326,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
17200
17326
|
},
|
|
17201
17327
|
AssignmentExpression(node) {
|
|
17202
17328
|
const scope = context.sourceCode.getScope(node);
|
|
17203
|
-
if (node.left.type ===
|
|
17329
|
+
if (node.left.type === AST_NODE_TYPES84.Identifier) {
|
|
17204
17330
|
const variable = findVariable2(scope, node.left.name);
|
|
17205
17331
|
if (variable === null) return;
|
|
17206
17332
|
const isLocalText = (candidate2) => localFileTextRef(candidate2, scope) !== null;
|
|
@@ -17214,7 +17340,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
17214
17340
|
}
|
|
17215
17341
|
return;
|
|
17216
17342
|
}
|
|
17217
|
-
if (node.left.type ===
|
|
17343
|
+
if (node.left.type === AST_NODE_TYPES84.ObjectPattern || node.left.type === AST_NODE_TYPES84.ArrayPattern) {
|
|
17218
17344
|
if (isRawPayloadSource(
|
|
17219
17345
|
node.right,
|
|
17220
17346
|
context,
|
|
@@ -17235,15 +17361,15 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
17235
17361
|
}
|
|
17236
17362
|
},
|
|
17237
17363
|
CallExpression(node) {
|
|
17238
|
-
if (node.callee.type !==
|
|
17364
|
+
if (node.callee.type !== AST_NODE_TYPES84.Identifier) return;
|
|
17239
17365
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
17240
17366
|
return;
|
|
17241
17367
|
}
|
|
17242
17368
|
const scope = context.sourceCode.getScope(node);
|
|
17243
17369
|
for (const arg of node.arguments) {
|
|
17244
|
-
if (arg.type ===
|
|
17370
|
+
if (arg.type === AST_NODE_TYPES84.SpreadElement) continue;
|
|
17245
17371
|
const unwrapped = unwrap6(arg);
|
|
17246
|
-
if (unwrapped === null || unwrapped.type !==
|
|
17372
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES84.Identifier) {
|
|
17247
17373
|
continue;
|
|
17248
17374
|
}
|
|
17249
17375
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -17267,14 +17393,14 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
17267
17393
|
(candidate2) => localFileTextRef(candidate2, scope) !== null
|
|
17268
17394
|
)) {
|
|
17269
17395
|
const parent = node.parent;
|
|
17270
|
-
if (parent.type ===
|
|
17396
|
+
if (parent.type === AST_NODE_TYPES84.CallExpression && parent.callee === node && node.property.type === AST_NODE_TYPES84.Identifier && (node.property.name === "parse" || node.property.name === "safeParse" || PROMISE_CHAIN_METHODS.has(node.property.name))) {
|
|
17271
17397
|
return;
|
|
17272
17398
|
}
|
|
17273
17399
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
17274
17400
|
return;
|
|
17275
17401
|
}
|
|
17276
|
-
const variable = obj?.type ===
|
|
17277
|
-
if (variable !== null && obj?.type ===
|
|
17402
|
+
const variable = obj?.type === AST_NODE_TYPES84.Identifier ? unvalidatedVariableRef(obj, scope, unvalidatedVariables) : null;
|
|
17403
|
+
if (variable !== null && obj?.type === AST_NODE_TYPES84.Identifier) {
|
|
17278
17404
|
if (namedGuards.get(variable)?.some((call) => guardDominates(node, call))) return;
|
|
17279
17405
|
if (isUseWithinValidatedBranch(node, obj.name)) {
|
|
17280
17406
|
return;
|
|
@@ -17302,8 +17428,8 @@ function validatedBranchContains(node, branch, polarity) {
|
|
|
17302
17428
|
}
|
|
17303
17429
|
function followsInSameContainer(use, preceding) {
|
|
17304
17430
|
let statement = use;
|
|
17305
|
-
while (statement.parent !== void 0 && statement.parent !== preceding.parent && statement.parent.type !==
|
|
17306
|
-
if (statement.type ===
|
|
17431
|
+
while (statement.parent !== void 0 && statement.parent !== preceding.parent && statement.parent.type !== AST_NODE_TYPES84.Program) {
|
|
17432
|
+
if (statement.type === AST_NODE_TYPES84.FunctionDeclaration || statement.type === AST_NODE_TYPES84.FunctionExpression || statement.type === AST_NODE_TYPES84.ArrowFunctionExpression) return false;
|
|
17307
17433
|
statement = statement.parent;
|
|
17308
17434
|
}
|
|
17309
17435
|
return statement.parent === preceding.parent && statement.range[0] > preceding.range[1];
|
|
@@ -17311,15 +17437,15 @@ function followsInSameContainer(use, preceding) {
|
|
|
17311
17437
|
function ifGuardDominates(use, branch, positive) {
|
|
17312
17438
|
if (positive && nodeWithin2(use, branch.consequent)) return true;
|
|
17313
17439
|
if (!positive && branch.alternate !== null && nodeWithin2(use, branch.alternate)) return true;
|
|
17314
|
-
const terminal = branch.consequent.type ===
|
|
17315
|
-
if (!positive && (terminal?.type ===
|
|
17440
|
+
const terminal = branch.consequent.type === AST_NODE_TYPES84.BlockStatement ? branch.consequent.body.at(-1) : branch.consequent;
|
|
17441
|
+
if (!positive && (terminal?.type === AST_NODE_TYPES84.ThrowStatement || terminal?.type === AST_NODE_TYPES84.ReturnStatement)) {
|
|
17316
17442
|
return followsInSameContainer(use, branch);
|
|
17317
17443
|
}
|
|
17318
17444
|
return null;
|
|
17319
17445
|
}
|
|
17320
17446
|
|
|
17321
17447
|
// src/rules/prefer-shared-zod-enum.ts
|
|
17322
|
-
import { AST_NODE_TYPES as
|
|
17448
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES85, ASTUtils as ASTUtils43 } from "@typescript-eslint/utils";
|
|
17323
17449
|
var PREFER_SHARED_ZOD_ENUM_DOCUMENTATION = {
|
|
17324
17450
|
defaultLevel: "warning",
|
|
17325
17451
|
summary: "Give repeated literal Zod enum domains one reusable module-level schema.",
|
|
@@ -17335,24 +17461,24 @@ var PREFER_SHARED_ZOD_ENUM_DOCUMENTATION = {
|
|
|
17335
17461
|
function literalDomain(node) {
|
|
17336
17462
|
if (node.arguments.length !== 1) return null;
|
|
17337
17463
|
const [argument] = node.arguments;
|
|
17338
|
-
if (argument?.type !==
|
|
17464
|
+
if (argument?.type !== AST_NODE_TYPES85.ArrayExpression || argument.elements.length < 2) return null;
|
|
17339
17465
|
const values = [];
|
|
17340
17466
|
for (const element of argument.elements) {
|
|
17341
|
-
if (element?.type !==
|
|
17467
|
+
if (element?.type !== AST_NODE_TYPES85.Literal || typeof element.value !== "string") return null;
|
|
17342
17468
|
values.push(element.value);
|
|
17343
17469
|
}
|
|
17344
17470
|
return values;
|
|
17345
17471
|
}
|
|
17346
17472
|
function isModuleLevelNamedSchema(node) {
|
|
17347
17473
|
let current = node;
|
|
17348
|
-
while (current.parent?.type ===
|
|
17474
|
+
while (current.parent?.type === AST_NODE_TYPES85.MemberExpression && current.parent.object === current) {
|
|
17349
17475
|
current = current.parent;
|
|
17350
|
-
if (current.parent?.type ===
|
|
17476
|
+
if (current.parent?.type === AST_NODE_TYPES85.CallExpression && current.parent.callee === current) current = current.parent;
|
|
17351
17477
|
}
|
|
17352
17478
|
const declarator = current.parent;
|
|
17353
|
-
if (declarator?.type !==
|
|
17479
|
+
if (declarator?.type !== AST_NODE_TYPES85.VariableDeclarator || declarator.init !== current || declarator.id.type !== AST_NODE_TYPES85.Identifier || declarator.parent.type !== AST_NODE_TYPES85.VariableDeclaration) return false;
|
|
17354
17480
|
const declarationParent = declarator.parent.parent;
|
|
17355
|
-
return declarationParent.type ===
|
|
17481
|
+
return declarationParent.type === AST_NODE_TYPES85.Program || declarationParent.type === AST_NODE_TYPES85.ExportNamedDeclaration && declarationParent.parent.type === AST_NODE_TYPES85.Program;
|
|
17356
17482
|
}
|
|
17357
17483
|
var prefer_shared_zod_enum_default = createRule({
|
|
17358
17484
|
name: "prefer-shared-zod-enum",
|
|
@@ -17369,20 +17495,20 @@ var prefer_shared_zod_enum_default = createRule({
|
|
|
17369
17495
|
create(context) {
|
|
17370
17496
|
if (isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text)) return {};
|
|
17371
17497
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
17372
|
-
const bindingOf = (node) =>
|
|
17498
|
+
const bindingOf = (node) => ASTUtils43.findVariable(context.sourceCode.getScope(node), node.name);
|
|
17373
17499
|
const candidates = /* @__PURE__ */ new Map();
|
|
17374
17500
|
return {
|
|
17375
17501
|
ImportDeclaration(node) {
|
|
17376
17502
|
if (!isZodModule(node.source.value)) return;
|
|
17377
17503
|
for (const specifier of node.specifiers) {
|
|
17378
|
-
if (specifier.type ===
|
|
17504
|
+
if (specifier.type === AST_NODE_TYPES85.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES85.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES85.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES85.Identifier && specifier.imported.name === "z") {
|
|
17379
17505
|
const binding = bindingOf(specifier.local);
|
|
17380
17506
|
if (binding !== null) zodBindings.add(binding);
|
|
17381
17507
|
}
|
|
17382
17508
|
}
|
|
17383
17509
|
},
|
|
17384
17510
|
CallExpression(node) {
|
|
17385
|
-
if (node.callee.type !==
|
|
17511
|
+
if (node.callee.type !== AST_NODE_TYPES85.MemberExpression || node.callee.computed || node.callee.object.type !== AST_NODE_TYPES85.Identifier || node.callee.property.type !== AST_NODE_TYPES85.Identifier || node.callee.property.name !== "enum") return;
|
|
17386
17512
|
const binding = bindingOf(node.callee.object);
|
|
17387
17513
|
if (binding === null || !zodBindings.has(binding)) return;
|
|
17388
17514
|
const domain = literalDomain(node);
|
|
@@ -17407,7 +17533,7 @@ var prefer_shared_zod_enum_default = createRule({
|
|
|
17407
17533
|
});
|
|
17408
17534
|
|
|
17409
17535
|
// src/rules/prefer-switch-for-repeated-equality.ts
|
|
17410
|
-
import { AST_NODE_TYPES as
|
|
17536
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES86 } from "@typescript-eslint/utils";
|
|
17411
17537
|
var PREFER_SWITCH_FOR_REPEATED_EQUALITY_DOCUMENTATION = {
|
|
17412
17538
|
defaultLevel: "warning",
|
|
17413
17539
|
summary: "Prefer switch over long if/else-if chains that compare one value for strict equality.",
|
|
@@ -17426,18 +17552,18 @@ var PREFER_SWITCH_FOR_REPEATED_EQUALITY_DOCUMENTATION = {
|
|
|
17426
17552
|
]
|
|
17427
17553
|
};
|
|
17428
17554
|
function discriminantText(sourceCode, test) {
|
|
17429
|
-
if (test.type !==
|
|
17555
|
+
if (test.type !== AST_NODE_TYPES86.BinaryExpression || test.operator !== "===") return null;
|
|
17430
17556
|
const leftIsCase = isCaseValue(test.left);
|
|
17431
17557
|
const rightIsCase = isCaseValue(test.right);
|
|
17432
17558
|
if (leftIsCase === rightIsCase) return null;
|
|
17433
17559
|
const discriminant = leftIsCase ? test.right : test.left;
|
|
17434
|
-
return discriminant.type ===
|
|
17560
|
+
return discriminant.type === AST_NODE_TYPES86.Identifier ? sourceCode.getText(discriminant) : null;
|
|
17435
17561
|
}
|
|
17436
17562
|
function isCaseValue(node) {
|
|
17437
|
-
if (node.type ===
|
|
17438
|
-
if (node.type ===
|
|
17439
|
-
if (node.type !==
|
|
17440
|
-
return node.property.type ===
|
|
17563
|
+
if (node.type === AST_NODE_TYPES86.Literal) return true;
|
|
17564
|
+
if (node.type === AST_NODE_TYPES86.Identifier) return /^[A-Z][A-Z0-9_]*$/u.test(node.name);
|
|
17565
|
+
if (node.type !== AST_NODE_TYPES86.MemberExpression || node.computed) return false;
|
|
17566
|
+
return node.property.type === AST_NODE_TYPES86.Identifier && (node.object.type === AST_NODE_TYPES86.Identifier || isCaseValue(node.object));
|
|
17441
17567
|
}
|
|
17442
17568
|
var prefer_switch_for_repeated_equality_default = createRule({
|
|
17443
17569
|
name: "prefer-switch-for-repeated-equality",
|
|
@@ -17454,12 +17580,12 @@ var prefer_switch_for_repeated_equality_default = createRule({
|
|
|
17454
17580
|
create(context) {
|
|
17455
17581
|
return {
|
|
17456
17582
|
IfStatement(node) {
|
|
17457
|
-
if (node.parent.type ===
|
|
17583
|
+
if (node.parent.type === AST_NODE_TYPES86.IfStatement && node.parent.alternate === node) return;
|
|
17458
17584
|
const first = discriminantText(context.sourceCode, node.test);
|
|
17459
17585
|
if (first === null) return;
|
|
17460
17586
|
let count = 1;
|
|
17461
17587
|
let current = node.alternate;
|
|
17462
|
-
while (current?.type ===
|
|
17588
|
+
while (current?.type === AST_NODE_TYPES86.IfStatement) {
|
|
17463
17589
|
if (discriminantText(context.sourceCode, current.test) !== first) return;
|
|
17464
17590
|
count += 1;
|
|
17465
17591
|
current = current.alternate;
|
|
@@ -17473,7 +17599,7 @@ var prefer_switch_for_repeated_equality_default = createRule({
|
|
|
17473
17599
|
});
|
|
17474
17600
|
|
|
17475
17601
|
// src/rules/prefer-semantic-colors.ts
|
|
17476
|
-
import { AST_NODE_TYPES as
|
|
17602
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES87 } from "@typescript-eslint/utils";
|
|
17477
17603
|
import { existsSync as existsSync2, lstatSync as lstatSync2, readdirSync, readFileSync as readFileSync2 } from "fs";
|
|
17478
17604
|
import { dirname as dirname2, join as join2, parse } from "path";
|
|
17479
17605
|
var PREFER_SEMANTIC_COLORS_DOCUMENTATION = {
|
|
@@ -17583,7 +17709,7 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
17583
17709
|
var isInsideSvg = (node) => {
|
|
17584
17710
|
let current = node.parent;
|
|
17585
17711
|
while (current !== void 0 && current !== null) {
|
|
17586
|
-
if (current.type ===
|
|
17712
|
+
if (current.type === AST_NODE_TYPES87.JSXElement) {
|
|
17587
17713
|
const name = jsxElementName(current);
|
|
17588
17714
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
17589
17715
|
}
|
|
@@ -17593,8 +17719,8 @@ var isInsideSvg = (node) => {
|
|
|
17593
17719
|
};
|
|
17594
17720
|
function jsxElementName(node) {
|
|
17595
17721
|
const name = node.openingElement.name;
|
|
17596
|
-
if (name.type ===
|
|
17597
|
-
if (name.type ===
|
|
17722
|
+
if (name.type === AST_NODE_TYPES87.JSXIdentifier) return name.name;
|
|
17723
|
+
if (name.type === AST_NODE_TYPES87.JSXMemberExpression && name.property.type === AST_NODE_TYPES87.JSXIdentifier) {
|
|
17598
17724
|
return name.property.name;
|
|
17599
17725
|
}
|
|
17600
17726
|
return null;
|
|
@@ -17626,7 +17752,7 @@ function isSvgLikeElementName(name) {
|
|
|
17626
17752
|
var isInsideIconFactoryPath = (node) => {
|
|
17627
17753
|
let current = node.parent;
|
|
17628
17754
|
while (current !== void 0 && current !== null) {
|
|
17629
|
-
if (current.type ===
|
|
17755
|
+
if (current.type === AST_NODE_TYPES87.Property && propName(current.key) === "path" && current.parent.type === AST_NODE_TYPES87.ObjectExpression && current.parent.parent.type === AST_NODE_TYPES87.CallExpression && current.parent.parent.callee.type === AST_NODE_TYPES87.Identifier && current.parent.parent.callee.name === "createIcon") {
|
|
17630
17756
|
return true;
|
|
17631
17757
|
}
|
|
17632
17758
|
current = current.parent;
|
|
@@ -17758,12 +17884,12 @@ var expandWorkspaceGlob = (root, glob) => {
|
|
|
17758
17884
|
return readdirSync(parent, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).sort((left, right) => left.name.localeCompare(right.name)).map((entry) => join2(parent, entry.name));
|
|
17759
17885
|
};
|
|
17760
17886
|
var propName = (key) => {
|
|
17761
|
-
if (key.type ===
|
|
17762
|
-
if (key.type ===
|
|
17887
|
+
if (key.type === AST_NODE_TYPES87.Identifier) return key.name;
|
|
17888
|
+
if (key.type === AST_NODE_TYPES87.Literal && typeof key.value === "string") return key.value;
|
|
17763
17889
|
return null;
|
|
17764
17890
|
};
|
|
17765
17891
|
var staticallyImportsExternalRenderer = (program) => program.body.some((statement) => {
|
|
17766
|
-
if (statement.type !==
|
|
17892
|
+
if (statement.type !== AST_NODE_TYPES87.ImportDeclaration && statement.type !== AST_NODE_TYPES87.ExportNamedDeclaration && statement.type !== AST_NODE_TYPES87.ExportAllDeclaration) {
|
|
17767
17893
|
return false;
|
|
17768
17894
|
}
|
|
17769
17895
|
return statement.source !== null && typeof statement.source.value === "string" && EXTERNAL_RENDERER_MODULE_RE.test(statement.source.value);
|
|
@@ -17888,25 +18014,25 @@ var prefer_semantic_colors_default = createRule({
|
|
|
17888
18014
|
const checkClassNode = (node, objectKeys = false) => {
|
|
17889
18015
|
if (node === null) return;
|
|
17890
18016
|
switch (node.type) {
|
|
17891
|
-
case
|
|
18017
|
+
case AST_NODE_TYPES87.Literal:
|
|
17892
18018
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
17893
18019
|
break;
|
|
17894
|
-
case
|
|
18020
|
+
case AST_NODE_TYPES87.TemplateLiteral:
|
|
17895
18021
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
17896
18022
|
break;
|
|
17897
|
-
case
|
|
18023
|
+
case AST_NODE_TYPES87.ArrayExpression:
|
|
17898
18024
|
for (const element of node.elements) {
|
|
17899
|
-
if (element !== null && element.type !==
|
|
18025
|
+
if (element !== null && element.type !== AST_NODE_TYPES87.SpreadElement) checkClassNode(element, objectKeys);
|
|
17900
18026
|
}
|
|
17901
18027
|
break;
|
|
17902
|
-
case
|
|
18028
|
+
case AST_NODE_TYPES87.ObjectExpression:
|
|
17903
18029
|
checkClassProperties(node, objectKeys);
|
|
17904
18030
|
break;
|
|
17905
|
-
case
|
|
18031
|
+
case AST_NODE_TYPES87.ConditionalExpression:
|
|
17906
18032
|
checkClassNode(node.consequent, objectKeys);
|
|
17907
18033
|
checkClassNode(node.alternate, objectKeys);
|
|
17908
18034
|
break;
|
|
17909
|
-
case
|
|
18035
|
+
case AST_NODE_TYPES87.LogicalExpression:
|
|
17910
18036
|
checkClassNode(node.right, objectKeys);
|
|
17911
18037
|
break;
|
|
17912
18038
|
default:
|
|
@@ -17915,10 +18041,10 @@ var prefer_semantic_colors_default = createRule({
|
|
|
17915
18041
|
};
|
|
17916
18042
|
function checkClassProperties(node, objectKeys) {
|
|
17917
18043
|
for (const property of node.properties) {
|
|
17918
|
-
if (property.type !==
|
|
18044
|
+
if (property.type !== AST_NODE_TYPES87.Property) continue;
|
|
17919
18045
|
if (objectKeys) {
|
|
17920
|
-
if (property.value.type ===
|
|
17921
|
-
if (!property.computed && property.key.type ===
|
|
18046
|
+
if (property.value.type === AST_NODE_TYPES87.Literal && !property.value.value && !("regex" in property.value)) continue;
|
|
18047
|
+
if (!property.computed && property.key.type === AST_NODE_TYPES87.Literal) {
|
|
17922
18048
|
checkClassNode(property.key);
|
|
17923
18049
|
}
|
|
17924
18050
|
} else {
|
|
@@ -17927,34 +18053,34 @@ var prefer_semantic_colors_default = createRule({
|
|
|
17927
18053
|
}
|
|
17928
18054
|
}
|
|
17929
18055
|
const checkColorValueNode = (node) => {
|
|
17930
|
-
if (node.type ===
|
|
18056
|
+
if (node.type === AST_NODE_TYPES87.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value.replace(/url\(\s*(?:"[^"]*"|'[^']*'|[^)]*)\s*\)/giu, "")) && !CSS_VAR_REFERENCE_RE.test(node.value)) {
|
|
17931
18057
|
report2(node, "inlineColor", { value: node.value });
|
|
17932
18058
|
}
|
|
17933
18059
|
};
|
|
17934
18060
|
return {
|
|
17935
18061
|
"JSXAttribute[name.name='className']"(node) {
|
|
17936
18062
|
if (node.value === null) return;
|
|
17937
|
-
if (node.value.type ===
|
|
17938
|
-
else if (node.value.type ===
|
|
17939
|
-
if (node.value.expression.type !==
|
|
18063
|
+
if (node.value.type === AST_NODE_TYPES87.Literal) checkClassNode(node.value);
|
|
18064
|
+
else if (node.value.type === AST_NODE_TYPES87.JSXExpressionContainer) {
|
|
18065
|
+
if (node.value.expression.type !== AST_NODE_TYPES87.JSXEmptyExpression) {
|
|
17940
18066
|
checkClassNode(node.value.expression);
|
|
17941
18067
|
}
|
|
17942
18068
|
}
|
|
17943
18069
|
},
|
|
17944
18070
|
CallExpression(node) {
|
|
17945
|
-
if (node.callee.type ===
|
|
18071
|
+
if (node.callee.type === AST_NODE_TYPES87.Identifier && node.callee.name === "require" && node.arguments[0]?.type === AST_NODE_TYPES87.Literal && typeof node.arguments[0].value === "string" && EXTERNAL_RENDERER_MODULE_RE.test(node.arguments[0].value)) {
|
|
17946
18072
|
importsExternalRenderer = true;
|
|
17947
18073
|
}
|
|
17948
|
-
if (node.callee.type ===
|
|
18074
|
+
if (node.callee.type === AST_NODE_TYPES87.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
17949
18075
|
for (const arg of node.arguments) {
|
|
17950
|
-
if (arg.type !==
|
|
18076
|
+
if (arg.type !== AST_NODE_TYPES87.SpreadElement) {
|
|
17951
18077
|
checkClassNode(arg, node.callee.name !== "cva" && node.callee.name !== "tv");
|
|
17952
18078
|
}
|
|
17953
18079
|
}
|
|
17954
18080
|
}
|
|
17955
18081
|
},
|
|
17956
18082
|
VariableDeclarator(node) {
|
|
17957
|
-
if (node.id.type ===
|
|
18083
|
+
if (node.id.type === AST_NODE_TYPES87.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
17958
18084
|
checkClassNode(node.init);
|
|
17959
18085
|
}
|
|
17960
18086
|
},
|
|
@@ -17964,9 +18090,9 @@ var prefer_semantic_colors_default = createRule({
|
|
|
17964
18090
|
},
|
|
17965
18091
|
// SVG artwork colors are exempt; component presentation colors still report.
|
|
17966
18092
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
17967
|
-
if (node.value?.type !==
|
|
18093
|
+
if (node.value?.type !== AST_NODE_TYPES87.Literal) return;
|
|
17968
18094
|
const owner = node.parent.name;
|
|
17969
|
-
if (owner.type ===
|
|
18095
|
+
if (owner.type === AST_NODE_TYPES87.JSXIdentifier && SVG_SHAPE_PRIMITIVES.has(owner.name)) {
|
|
17970
18096
|
return;
|
|
17971
18097
|
}
|
|
17972
18098
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
@@ -17980,7 +18106,7 @@ var prefer_semantic_colors_default = createRule({
|
|
|
17980
18106
|
if (name !== null && STYLE_COLOR_PROPS.has(name)) checkColorValueNode(node.value);
|
|
17981
18107
|
},
|
|
17982
18108
|
ImportExpression(node) {
|
|
17983
|
-
if (node.source.type ===
|
|
18109
|
+
if (node.source.type === AST_NODE_TYPES87.Literal && typeof node.source.value === "string" && EXTERNAL_RENDERER_MODULE_RE.test(node.source.value)) {
|
|
17984
18110
|
importsExternalRenderer = true;
|
|
17985
18111
|
}
|
|
17986
18112
|
},
|
|
@@ -18000,7 +18126,7 @@ function packageWorkspaceGlobs(parsed) {
|
|
|
18000
18126
|
}
|
|
18001
18127
|
|
|
18002
18128
|
// src/rules/prefer-server-actions.ts
|
|
18003
|
-
import { ASTUtils as
|
|
18129
|
+
import { ASTUtils as ASTUtils44 } from "@typescript-eslint/utils";
|
|
18004
18130
|
var PREFER_SERVER_ACTIONS_DOCUMENTATION = {
|
|
18005
18131
|
summary: "Prefer Next.js Server Actions over same-origin API mutations.",
|
|
18006
18132
|
rationale: "Server Actions can remove a hand-written internal API wrapper while retaining typed application calls. Client invocations still cross a network and serialization boundary.",
|
|
@@ -18032,7 +18158,7 @@ function resolvesToGlobalFetch(context, identifier) {
|
|
|
18032
18158
|
function resolveNode(node, context) {
|
|
18033
18159
|
if (!node) return null;
|
|
18034
18160
|
if (node.type !== "Identifier") return node;
|
|
18035
|
-
const variable =
|
|
18161
|
+
const variable = ASTUtils44.findVariable(getScope(context, node), node.name);
|
|
18036
18162
|
const definition = variable?.defs.length === 1 ? variable.defs[0] : void 0;
|
|
18037
18163
|
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init === null || variable?.references.some((reference) => reference.isWrite() && reference.init !== true)) return node;
|
|
18038
18164
|
if (definition.node.init.type === "ObjectExpression" && variable?.references.some((reference) => reference.identifier !== node && reference.init !== true)) return node;
|
|
@@ -18041,7 +18167,7 @@ function resolveNode(node, context) {
|
|
|
18041
18167
|
function isAxiosClient(node, context, seen = /* @__PURE__ */ new Set()) {
|
|
18042
18168
|
if (node.type !== "Identifier" || seen.has(node)) return false;
|
|
18043
18169
|
seen.add(node);
|
|
18044
|
-
const variable =
|
|
18170
|
+
const variable = ASTUtils44.findVariable(getScope(context, node), node.name);
|
|
18045
18171
|
const definition = variable?.defs.length === 1 ? variable.defs[0] : void 0;
|
|
18046
18172
|
if (definition === void 0 || variable?.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
18047
18173
|
if (variable?.references.some((reference) => {
|
|
@@ -18256,7 +18382,7 @@ var prefer_server_actions_default = createRule({
|
|
|
18256
18382
|
});
|
|
18257
18383
|
|
|
18258
18384
|
// src/rules/prefer-whole-object-assertion.ts
|
|
18259
|
-
import { AST_NODE_TYPES as
|
|
18385
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES88, ASTUtils as ASTUtils45 } from "@typescript-eslint/utils";
|
|
18260
18386
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
18261
18387
|
var SYNTHETIC_LITERAL_MATCHERS = /* @__PURE__ */ new Map([
|
|
18262
18388
|
["toBeNull", "null"],
|
|
@@ -18283,11 +18409,11 @@ var PREFER_WHOLE_OBJECT_ASSERTION_DOCUMENTATION = {
|
|
|
18283
18409
|
};
|
|
18284
18410
|
function literalText(node, getText) {
|
|
18285
18411
|
switch (node.type) {
|
|
18286
|
-
case
|
|
18412
|
+
case AST_NODE_TYPES88.Literal:
|
|
18287
18413
|
return "regex" in node ? null : getText(node);
|
|
18288
|
-
case
|
|
18414
|
+
case AST_NODE_TYPES88.TemplateLiteral:
|
|
18289
18415
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
18290
|
-
case
|
|
18416
|
+
case AST_NODE_TYPES88.UnaryExpression:
|
|
18291
18417
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
18292
18418
|
default:
|
|
18293
18419
|
return null;
|
|
@@ -18295,15 +18421,15 @@ function literalText(node, getText) {
|
|
|
18295
18421
|
}
|
|
18296
18422
|
function isPureReceiver(node) {
|
|
18297
18423
|
switch (node.type) {
|
|
18298
|
-
case
|
|
18299
|
-
case
|
|
18424
|
+
case AST_NODE_TYPES88.Identifier:
|
|
18425
|
+
case AST_NODE_TYPES88.ThisExpression:
|
|
18300
18426
|
return true;
|
|
18301
|
-
case
|
|
18427
|
+
case AST_NODE_TYPES88.MemberExpression:
|
|
18302
18428
|
if (node.optional) {
|
|
18303
18429
|
return false;
|
|
18304
18430
|
}
|
|
18305
18431
|
if (node.computed) {
|
|
18306
|
-
return node.property.type ===
|
|
18432
|
+
return node.property.type === AST_NODE_TYPES88.Literal && isPureReceiver(node.object);
|
|
18307
18433
|
}
|
|
18308
18434
|
return isPureReceiver(node.object);
|
|
18309
18435
|
default:
|
|
@@ -18311,7 +18437,7 @@ function isPureReceiver(node) {
|
|
|
18311
18437
|
}
|
|
18312
18438
|
}
|
|
18313
18439
|
function literalIndex(node) {
|
|
18314
|
-
if (node.type !==
|
|
18440
|
+
if (node.type !== AST_NODE_TYPES88.Literal || typeof node.value !== "number") {
|
|
18315
18441
|
return null;
|
|
18316
18442
|
}
|
|
18317
18443
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
@@ -18319,8 +18445,8 @@ function literalIndex(node) {
|
|
|
18319
18445
|
function propertyAccess(node) {
|
|
18320
18446
|
const path = [];
|
|
18321
18447
|
let current = node;
|
|
18322
|
-
while (current.type ===
|
|
18323
|
-
if (current.property.type !==
|
|
18448
|
+
while (current.type === AST_NODE_TYPES88.MemberExpression && !current.computed && !current.optional) {
|
|
18449
|
+
if (current.property.type !== AST_NODE_TYPES88.Identifier || COLLECTION_PROPERTIES.has(current.property.name) || LITERAL_KEY_HAZARDS.has(current.property.name)) return null;
|
|
18324
18450
|
path.unshift(current.property.name);
|
|
18325
18451
|
current = current.object;
|
|
18326
18452
|
}
|
|
@@ -18347,25 +18473,25 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
18347
18473
|
}
|
|
18348
18474
|
const { sourceCode } = context;
|
|
18349
18475
|
function parseAssertion(statement) {
|
|
18350
|
-
if (statement.type !==
|
|
18476
|
+
if (statement.type !== AST_NODE_TYPES88.ExpressionStatement) {
|
|
18351
18477
|
return null;
|
|
18352
18478
|
}
|
|
18353
18479
|
const call = statement.expression;
|
|
18354
|
-
if (call.type !==
|
|
18480
|
+
if (call.type !== AST_NODE_TYPES88.CallExpression) {
|
|
18355
18481
|
return null;
|
|
18356
18482
|
}
|
|
18357
18483
|
const callee = call.callee;
|
|
18358
|
-
if (callee.type !==
|
|
18484
|
+
if (callee.type !== AST_NODE_TYPES88.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES88.Identifier) {
|
|
18359
18485
|
return null;
|
|
18360
18486
|
}
|
|
18361
18487
|
const matcher = callee.property.name;
|
|
18362
18488
|
const expectCall = callee.object;
|
|
18363
|
-
if (expectCall.type !==
|
|
18489
|
+
if (expectCall.type !== AST_NODE_TYPES88.CallExpression || expectCall.callee.type !== AST_NODE_TYPES88.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
18364
18490
|
return null;
|
|
18365
18491
|
}
|
|
18366
18492
|
const actual = expectCall.arguments[0];
|
|
18367
18493
|
if (!isTestExpect(expectCall.callee)) return null;
|
|
18368
|
-
if (actual === void 0 || actual.type !==
|
|
18494
|
+
if (actual === void 0 || actual.type !== AST_NODE_TYPES88.MemberExpression || actual.optional) {
|
|
18369
18495
|
return null;
|
|
18370
18496
|
}
|
|
18371
18497
|
if (!isPureReceiver(actual.object)) {
|
|
@@ -18397,7 +18523,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
18397
18523
|
return null;
|
|
18398
18524
|
}
|
|
18399
18525
|
const expected = call.arguments[0];
|
|
18400
|
-
if (call.arguments.length !== 1 || expected === void 0 || expected.type ===
|
|
18526
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === AST_NODE_TYPES88.SpreadElement) {
|
|
18401
18527
|
return null;
|
|
18402
18528
|
}
|
|
18403
18529
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
@@ -18411,12 +18537,12 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
18411
18537
|
};
|
|
18412
18538
|
}
|
|
18413
18539
|
function isTestExpect(callee) {
|
|
18414
|
-
const variable =
|
|
18540
|
+
const variable = ASTUtils45.findVariable(sourceCode.getScope(callee), callee.name);
|
|
18415
18541
|
if (variable !== null && variable.defs.some((definition) => {
|
|
18416
|
-
if (definition.node.type !==
|
|
18542
|
+
if (definition.node.type !== AST_NODE_TYPES88.ImportSpecifier) return true;
|
|
18417
18543
|
const declaration = definition.node.parent;
|
|
18418
18544
|
const imported = definition.node.imported;
|
|
18419
|
-
return declaration.type !==
|
|
18545
|
+
return declaration.type !== AST_NODE_TYPES88.ImportDeclaration || !["vitest", "@jest/globals", "@playwright/test", "bun:test"].includes(String(declaration.source.value)) || (imported.type === AST_NODE_TYPES88.Identifier ? imported.name : imported.value) !== "expect";
|
|
18420
18546
|
})) return false;
|
|
18421
18547
|
return true;
|
|
18422
18548
|
}
|
|
@@ -18541,7 +18667,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
18541
18667
|
});
|
|
18542
18668
|
|
|
18543
18669
|
// src/rules/repeated-static-call-cases.ts
|
|
18544
|
-
import { AST_NODE_TYPES as
|
|
18670
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES89, ASTUtils as ASTUtils46 } from "@typescript-eslint/utils";
|
|
18545
18671
|
var REPEATED_STATIC_CALL_CASES_DOCUMENTATION = {
|
|
18546
18672
|
summary: "Review three or more consecutive static-input call assertions as potential named cases.",
|
|
18547
18673
|
rationale: "Copy-pasted cases obscure the input table, and a thrown assertion can stop later cases from being reported.",
|
|
@@ -18562,67 +18688,67 @@ var EXPECT_MODIFIERS = /* @__PURE__ */ new Set(["not", "rejects", "resolves"]);
|
|
|
18562
18688
|
var SNAPSHOT_MATCHERS = /snapshot/iu;
|
|
18563
18689
|
var MIN_CASES2 = 3;
|
|
18564
18690
|
function staticMemberName6(node) {
|
|
18565
|
-
if (!node.computed && node.property.type ===
|
|
18566
|
-
if (node.computed && node.property.type ===
|
|
18691
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES89.Identifier) return node.property.name;
|
|
18692
|
+
if (node.computed && node.property.type === AST_NODE_TYPES89.Literal && typeof node.property.value === "string") return node.property.value;
|
|
18567
18693
|
return null;
|
|
18568
18694
|
}
|
|
18569
18695
|
function importedName7(identifier, context, modules) {
|
|
18570
|
-
const variable =
|
|
18696
|
+
const variable = ASTUtils46.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
18571
18697
|
if (variable === null || variable.defs.length === 0) return identifier.name;
|
|
18572
18698
|
for (const definition of variable.defs) {
|
|
18573
|
-
if (definition.node.type !==
|
|
18699
|
+
if (definition.node.type !== AST_NODE_TYPES89.ImportSpecifier) continue;
|
|
18574
18700
|
const declaration = definition.node.parent;
|
|
18575
|
-
if (declaration.type !==
|
|
18701
|
+
if (declaration.type !== AST_NODE_TYPES89.ImportDeclaration || typeof declaration.source.value !== "string" || !modules.has(declaration.source.value)) continue;
|
|
18576
18702
|
const imported = definition.node.imported;
|
|
18577
|
-
return imported.type ===
|
|
18703
|
+
return imported.type === AST_NODE_TYPES89.Identifier ? imported.name : String(imported.value);
|
|
18578
18704
|
}
|
|
18579
18705
|
return null;
|
|
18580
18706
|
}
|
|
18581
18707
|
function isDirectTestCallback2(node, context) {
|
|
18582
|
-
if (node.type !==
|
|
18708
|
+
if (node.type !== AST_NODE_TYPES89.ArrowFunctionExpression && node.type !== AST_NODE_TYPES89.FunctionExpression) return false;
|
|
18583
18709
|
const call = node.parent;
|
|
18584
|
-
if (call?.type !==
|
|
18710
|
+
if (call?.type !== AST_NODE_TYPES89.CallExpression || !call.arguments.includes(node)) return false;
|
|
18585
18711
|
const root = testRoot2(call.callee);
|
|
18586
18712
|
return root !== null && TEST_NAMES2.has(importedName7(root, context, TEST_MODULES4) ?? "");
|
|
18587
18713
|
}
|
|
18588
18714
|
function testRoot2(callee) {
|
|
18589
|
-
if (callee.type ===
|
|
18590
|
-
if (callee.type !==
|
|
18715
|
+
if (callee.type === AST_NODE_TYPES89.Identifier) return callee;
|
|
18716
|
+
if (callee.type !== AST_NODE_TYPES89.MemberExpression) return null;
|
|
18591
18717
|
const modifier = staticMemberName6(callee);
|
|
18592
18718
|
return modifier !== null && TEST_MODIFIERS4.has(modifier) ? testRoot2(callee.object) : null;
|
|
18593
18719
|
}
|
|
18594
18720
|
function isStatic(node) {
|
|
18595
|
-
if (node.type ===
|
|
18721
|
+
if (node.type === AST_NODE_TYPES89.TSAsExpression || node.type === AST_NODE_TYPES89.TSTypeAssertion || node.type === AST_NODE_TYPES89.TSSatisfiesExpression || node.type === AST_NODE_TYPES89.TSNonNullExpression) return isStatic(node.expression);
|
|
18596
18722
|
switch (node.type) {
|
|
18597
|
-
case
|
|
18723
|
+
case AST_NODE_TYPES89.Literal:
|
|
18598
18724
|
return true;
|
|
18599
|
-
case
|
|
18725
|
+
case AST_NODE_TYPES89.TemplateLiteral:
|
|
18600
18726
|
return node.expressions.length === 0;
|
|
18601
|
-
case
|
|
18727
|
+
case AST_NODE_TYPES89.UnaryExpression:
|
|
18602
18728
|
return (node.operator === "+" || node.operator === "-") && isStatic(node.argument);
|
|
18603
|
-
case
|
|
18604
|
-
return node.elements.every((item) => item !== null && item.type !==
|
|
18605
|
-
case
|
|
18606
|
-
return node.properties.every((property) => property.type ===
|
|
18729
|
+
case AST_NODE_TYPES89.ArrayExpression:
|
|
18730
|
+
return node.elements.every((item) => item !== null && item.type !== AST_NODE_TYPES89.SpreadElement && isStatic(item));
|
|
18731
|
+
case AST_NODE_TYPES89.ObjectExpression:
|
|
18732
|
+
return node.properties.every((property) => property.type === AST_NODE_TYPES89.Property && !property.computed && property.kind === "init" && property.value.type !== AST_NODE_TYPES89.AssignmentPattern && isStatic(property.value));
|
|
18607
18733
|
default:
|
|
18608
18734
|
return false;
|
|
18609
18735
|
}
|
|
18610
18736
|
}
|
|
18611
18737
|
function staticShape(node) {
|
|
18612
|
-
if (node.type ===
|
|
18738
|
+
if (node.type === AST_NODE_TYPES89.TSAsExpression || node.type === AST_NODE_TYPES89.TSTypeAssertion || node.type === AST_NODE_TYPES89.TSSatisfiesExpression || node.type === AST_NODE_TYPES89.TSNonNullExpression) return staticShape(node.expression);
|
|
18613
18739
|
switch (node.type) {
|
|
18614
|
-
case
|
|
18740
|
+
case AST_NODE_TYPES89.Literal:
|
|
18615
18741
|
return `literal:${typeof node.value}`;
|
|
18616
|
-
case
|
|
18742
|
+
case AST_NODE_TYPES89.TemplateLiteral:
|
|
18617
18743
|
return "template";
|
|
18618
|
-
case
|
|
18744
|
+
case AST_NODE_TYPES89.UnaryExpression:
|
|
18619
18745
|
return `unary:${node.operator}:${staticShape(node.argument)}`;
|
|
18620
|
-
case
|
|
18621
|
-
return `array(${node.elements.map((item) => item === null || item.type ===
|
|
18622
|
-
case
|
|
18746
|
+
case AST_NODE_TYPES89.ArrayExpression:
|
|
18747
|
+
return `array(${node.elements.map((item) => item === null || item.type === AST_NODE_TYPES89.SpreadElement ? "invalid" : staticShape(item)).join(",")})`;
|
|
18748
|
+
case AST_NODE_TYPES89.ObjectExpression:
|
|
18623
18749
|
return `object(${node.properties.map((property) => {
|
|
18624
|
-
if (property.type !==
|
|
18625
|
-
const key = property.key.type ===
|
|
18750
|
+
if (property.type !== AST_NODE_TYPES89.Property || property.computed || property.value.type === AST_NODE_TYPES89.AssignmentPattern) return "invalid";
|
|
18751
|
+
const key = property.key.type === AST_NODE_TYPES89.Identifier ? property.key.name : String(property.key.value);
|
|
18626
18752
|
return `${key}:${staticShape(property.value)}`;
|
|
18627
18753
|
}).join(",")})`;
|
|
18628
18754
|
default:
|
|
@@ -18630,18 +18756,18 @@ function staticShape(node) {
|
|
|
18630
18756
|
}
|
|
18631
18757
|
}
|
|
18632
18758
|
function assertionShape(statement, context, callback) {
|
|
18633
|
-
if (statement.type !==
|
|
18759
|
+
if (statement.type !== AST_NODE_TYPES89.ExpressionStatement || statement.expression.type !== AST_NODE_TYPES89.CallExpression) return null;
|
|
18634
18760
|
const matcherCall = statement.expression;
|
|
18635
|
-
if (matcherCall.callee.type !==
|
|
18761
|
+
if (matcherCall.callee.type !== AST_NODE_TYPES89.MemberExpression || matcherCall.callee.computed || matcherCall.callee.property.type !== AST_NODE_TYPES89.Identifier || matcherCall.arguments.length !== 1) return null;
|
|
18636
18762
|
const matcher = matcherCall.callee.property.name;
|
|
18637
18763
|
if (SNAPSHOT_MATCHERS.test(matcher)) return null;
|
|
18638
18764
|
const chain = expectCallFromMatcher(matcherCall.callee);
|
|
18639
|
-
if (chain === null || chain.call.callee.type !==
|
|
18765
|
+
if (chain === null || chain.call.callee.type !== AST_NODE_TYPES89.Identifier || importedName7(chain.call.callee, context, ASSERTION_MODULES3) !== "expect" || chain.call.arguments.length !== 1) return null;
|
|
18640
18766
|
const observed = chain.call.arguments[0];
|
|
18641
18767
|
const expected = matcherCall.arguments[0];
|
|
18642
|
-
if (observed?.type !==
|
|
18768
|
+
if (observed?.type !== AST_NODE_TYPES89.CallExpression || observed.callee.type !== AST_NODE_TYPES89.Identifier || observed.arguments.length === 0 || observed.arguments.some((arg) => arg.type === AST_NODE_TYPES89.SpreadElement || !isStatic(arg)) || expected?.type === AST_NODE_TYPES89.SpreadElement || expected === void 0 || !isStatic(expected)) return null;
|
|
18643
18769
|
const skeleton = `${observed.callee.name}/${observed.arguments.map((item) => staticShape(item)).join(",")}/${chain.modifiers.join(".")}/${matcher}/${staticShape(expected)}`;
|
|
18644
|
-
const binding =
|
|
18770
|
+
const binding = ASTUtils46.findVariable(context.sourceCode.getScope(observed.callee), observed.callee.name);
|
|
18645
18771
|
if (binding?.defs.some(
|
|
18646
18772
|
(definition) => definition.node.range[0] >= callback.range[0] && definition.node.range[1] <= callback.range[1]
|
|
18647
18773
|
)) return null;
|
|
@@ -18651,13 +18777,13 @@ function assertionShape(statement, context, callback) {
|
|
|
18651
18777
|
function expectCallFromMatcher(node) {
|
|
18652
18778
|
const modifiers = [];
|
|
18653
18779
|
let receiver = node.object;
|
|
18654
|
-
while (receiver.type ===
|
|
18780
|
+
while (receiver.type === AST_NODE_TYPES89.MemberExpression) {
|
|
18655
18781
|
const modifier = staticMemberName6(receiver);
|
|
18656
18782
|
if (modifier === null || !EXPECT_MODIFIERS.has(modifier)) return null;
|
|
18657
18783
|
modifiers.unshift(modifier);
|
|
18658
18784
|
receiver = receiver.object;
|
|
18659
18785
|
}
|
|
18660
|
-
return receiver.type ===
|
|
18786
|
+
return receiver.type === AST_NODE_TYPES89.CallExpression ? { call: receiver, modifiers } : null;
|
|
18661
18787
|
}
|
|
18662
18788
|
var repeated_static_call_cases_default = createRule({
|
|
18663
18789
|
name: "repeated-static-call-cases",
|
|
@@ -18677,7 +18803,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
18677
18803
|
return {
|
|
18678
18804
|
"CallExpression > ArrowFunctionExpression, CallExpression > FunctionExpression"(node) {
|
|
18679
18805
|
const call = node.parent;
|
|
18680
|
-
if (call?.type ===
|
|
18806
|
+
if (call?.type === AST_NODE_TYPES89.CallExpression) {
|
|
18681
18807
|
const duplicate = duplicateTestBodyCandidate(call, sourceCode);
|
|
18682
18808
|
if (duplicate !== null && duplicate.body === node) {
|
|
18683
18809
|
const groups = duplicateGroups.get(duplicate.container) ?? /* @__PURE__ */ new Map();
|
|
@@ -18687,7 +18813,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
18687
18813
|
duplicateGroups.set(duplicate.container, groups);
|
|
18688
18814
|
}
|
|
18689
18815
|
}
|
|
18690
|
-
if (!isDirectTestCallback2(node, context) || node.body.type !==
|
|
18816
|
+
if (!isDirectTestCallback2(node, context) || node.body.type !== AST_NODE_TYPES89.BlockStatement) return;
|
|
18691
18817
|
let run = [];
|
|
18692
18818
|
const flush = () => {
|
|
18693
18819
|
if (run.length >= MIN_CASES2 && new Set(run.map((item) => item.values)).size > 1) {
|
|
@@ -18728,7 +18854,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
18728
18854
|
});
|
|
18729
18855
|
|
|
18730
18856
|
// src/rules/prefer-zod-infer.ts
|
|
18731
|
-
import { AST_NODE_TYPES as
|
|
18857
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES90 } from "@typescript-eslint/utils";
|
|
18732
18858
|
var PREFER_ZOD_INFER_DOCUMENTATION = {
|
|
18733
18859
|
summary: "Derive a type from its Zod schema with `z.infer` instead of hand-writing a twin declaration beside it.",
|
|
18734
18860
|
rationale: "A derived type stays synchronized when the runtime schema changes.",
|
|
@@ -18792,47 +18918,47 @@ function isPreferZodInferTypeConstraintName(name) {
|
|
|
18792
18918
|
return ZOD_TYPE_CONSTRAINTS.has(name);
|
|
18793
18919
|
}
|
|
18794
18920
|
var LEAF_NODE_TYPES = {
|
|
18795
|
-
string: [
|
|
18796
|
-
email: [
|
|
18797
|
-
url: [
|
|
18798
|
-
uuid: [
|
|
18799
|
-
ulid: [
|
|
18800
|
-
cuid: [
|
|
18801
|
-
cuid2: [
|
|
18802
|
-
nanoid: [
|
|
18803
|
-
iso: [
|
|
18804
|
-
number: [
|
|
18805
|
-
int: [
|
|
18806
|
-
float32: [
|
|
18807
|
-
float64: [
|
|
18808
|
-
boolean: [
|
|
18809
|
-
bigint: [
|
|
18810
|
-
symbol: [
|
|
18811
|
-
any: [
|
|
18812
|
-
unknown: [
|
|
18813
|
-
never: [
|
|
18814
|
-
void: [
|
|
18815
|
-
null: [
|
|
18816
|
-
undefined: [
|
|
18817
|
-
literal: [
|
|
18818
|
-
date: [
|
|
18819
|
-
array: [
|
|
18820
|
-
tuple: [
|
|
18821
|
-
object: [
|
|
18822
|
-
strictObject: [
|
|
18823
|
-
looseObject: [
|
|
18824
|
-
record: [
|
|
18825
|
-
map: [
|
|
18826
|
-
set: [
|
|
18827
|
-
promise: [
|
|
18828
|
-
enum: [
|
|
18829
|
-
nativeEnum: [
|
|
18830
|
-
union: [
|
|
18831
|
-
discriminatedUnion: [
|
|
18832
|
-
intersection: [
|
|
18921
|
+
string: [AST_NODE_TYPES90.TSStringKeyword],
|
|
18922
|
+
email: [AST_NODE_TYPES90.TSStringKeyword],
|
|
18923
|
+
url: [AST_NODE_TYPES90.TSStringKeyword],
|
|
18924
|
+
uuid: [AST_NODE_TYPES90.TSStringKeyword],
|
|
18925
|
+
ulid: [AST_NODE_TYPES90.TSStringKeyword],
|
|
18926
|
+
cuid: [AST_NODE_TYPES90.TSStringKeyword],
|
|
18927
|
+
cuid2: [AST_NODE_TYPES90.TSStringKeyword],
|
|
18928
|
+
nanoid: [AST_NODE_TYPES90.TSStringKeyword],
|
|
18929
|
+
iso: [AST_NODE_TYPES90.TSStringKeyword],
|
|
18930
|
+
number: [AST_NODE_TYPES90.TSNumberKeyword],
|
|
18931
|
+
int: [AST_NODE_TYPES90.TSNumberKeyword],
|
|
18932
|
+
float32: [AST_NODE_TYPES90.TSNumberKeyword],
|
|
18933
|
+
float64: [AST_NODE_TYPES90.TSNumberKeyword],
|
|
18934
|
+
boolean: [AST_NODE_TYPES90.TSBooleanKeyword],
|
|
18935
|
+
bigint: [AST_NODE_TYPES90.TSBigIntKeyword],
|
|
18936
|
+
symbol: [AST_NODE_TYPES90.TSSymbolKeyword],
|
|
18937
|
+
any: [AST_NODE_TYPES90.TSAnyKeyword],
|
|
18938
|
+
unknown: [AST_NODE_TYPES90.TSUnknownKeyword],
|
|
18939
|
+
never: [AST_NODE_TYPES90.TSNeverKeyword],
|
|
18940
|
+
void: [AST_NODE_TYPES90.TSVoidKeyword],
|
|
18941
|
+
null: [AST_NODE_TYPES90.TSNullKeyword],
|
|
18942
|
+
undefined: [AST_NODE_TYPES90.TSUndefinedKeyword],
|
|
18943
|
+
literal: [AST_NODE_TYPES90.TSLiteralType],
|
|
18944
|
+
date: [AST_NODE_TYPES90.TSTypeReference],
|
|
18945
|
+
array: [AST_NODE_TYPES90.TSArrayType, AST_NODE_TYPES90.TSTypeReference],
|
|
18946
|
+
tuple: [AST_NODE_TYPES90.TSTupleType],
|
|
18947
|
+
object: [AST_NODE_TYPES90.TSTypeLiteral, AST_NODE_TYPES90.TSTypeReference],
|
|
18948
|
+
strictObject: [AST_NODE_TYPES90.TSTypeLiteral, AST_NODE_TYPES90.TSTypeReference],
|
|
18949
|
+
looseObject: [AST_NODE_TYPES90.TSTypeLiteral, AST_NODE_TYPES90.TSTypeReference],
|
|
18950
|
+
record: [AST_NODE_TYPES90.TSTypeReference, AST_NODE_TYPES90.TSTypeLiteral],
|
|
18951
|
+
map: [AST_NODE_TYPES90.TSTypeReference],
|
|
18952
|
+
set: [AST_NODE_TYPES90.TSTypeReference],
|
|
18953
|
+
promise: [AST_NODE_TYPES90.TSTypeReference],
|
|
18954
|
+
enum: [AST_NODE_TYPES90.TSUnionType, AST_NODE_TYPES90.TSTypeReference, AST_NODE_TYPES90.TSLiteralType],
|
|
18955
|
+
nativeEnum: [AST_NODE_TYPES90.TSUnionType, AST_NODE_TYPES90.TSTypeReference, AST_NODE_TYPES90.TSLiteralType],
|
|
18956
|
+
union: [AST_NODE_TYPES90.TSUnionType, AST_NODE_TYPES90.TSTypeReference],
|
|
18957
|
+
discriminatedUnion: [AST_NODE_TYPES90.TSUnionType, AST_NODE_TYPES90.TSTypeReference],
|
|
18958
|
+
intersection: [AST_NODE_TYPES90.TSIntersectionType, AST_NODE_TYPES90.TSTypeReference]
|
|
18833
18959
|
};
|
|
18834
18960
|
function primitiveLiteralKey(node) {
|
|
18835
|
-
if (node.type !==
|
|
18961
|
+
if (node.type !== AST_NODE_TYPES90.Literal) {
|
|
18836
18962
|
return null;
|
|
18837
18963
|
}
|
|
18838
18964
|
if (node.value === null) {
|
|
@@ -18864,13 +18990,13 @@ function staticZodDomain(leaf, call) {
|
|
|
18864
18990
|
}
|
|
18865
18991
|
if (leaf === "literal") {
|
|
18866
18992
|
const [argument] = call.arguments;
|
|
18867
|
-
if (argument === void 0 || argument.type ===
|
|
18993
|
+
if (argument === void 0 || argument.type === AST_NODE_TYPES90.SpreadElement) {
|
|
18868
18994
|
return null;
|
|
18869
18995
|
}
|
|
18870
|
-
if (argument.type ===
|
|
18996
|
+
if (argument.type === AST_NODE_TYPES90.ArrayExpression) {
|
|
18871
18997
|
return exactDomain(
|
|
18872
18998
|
argument.elements.map(
|
|
18873
|
-
(element) => element === null || element.type ===
|
|
18999
|
+
(element) => element === null || element.type === AST_NODE_TYPES90.SpreadElement ? null : primitiveLiteralKey(element)
|
|
18874
19000
|
)
|
|
18875
19001
|
);
|
|
18876
19002
|
}
|
|
@@ -18878,13 +19004,13 @@ function staticZodDomain(leaf, call) {
|
|
|
18878
19004
|
}
|
|
18879
19005
|
if (leaf === "enum") {
|
|
18880
19006
|
const [argument] = call.arguments;
|
|
18881
|
-
if (argument === void 0 || argument.type ===
|
|
19007
|
+
if (argument === void 0 || argument.type === AST_NODE_TYPES90.SpreadElement) {
|
|
18882
19008
|
return null;
|
|
18883
19009
|
}
|
|
18884
|
-
if (argument.type ===
|
|
19010
|
+
if (argument.type === AST_NODE_TYPES90.ArrayExpression) {
|
|
18885
19011
|
return exactDomain(
|
|
18886
19012
|
argument.elements.map((element) => {
|
|
18887
|
-
if (element === null || element.type ===
|
|
19013
|
+
if (element === null || element.type === AST_NODE_TYPES90.SpreadElement) {
|
|
18888
19014
|
return null;
|
|
18889
19015
|
}
|
|
18890
19016
|
const key = primitiveLiteralKey(element);
|
|
@@ -18892,10 +19018,10 @@ function staticZodDomain(leaf, call) {
|
|
|
18892
19018
|
})
|
|
18893
19019
|
);
|
|
18894
19020
|
}
|
|
18895
|
-
if (argument.type ===
|
|
19021
|
+
if (argument.type === AST_NODE_TYPES90.ObjectExpression) {
|
|
18896
19022
|
return exactDomain(
|
|
18897
19023
|
argument.properties.map((property) => {
|
|
18898
|
-
if (property.type !==
|
|
19024
|
+
if (property.type !== AST_NODE_TYPES90.Property || property.computed || property.kind !== "init" || property.method || property.shorthand) {
|
|
18899
19025
|
return null;
|
|
18900
19026
|
}
|
|
18901
19027
|
const key = primitiveLiteralKey(property.value);
|
|
@@ -18922,19 +19048,19 @@ function sameDomain(left, right) {
|
|
|
18922
19048
|
return true;
|
|
18923
19049
|
}
|
|
18924
19050
|
function isExportedDeclaration(node) {
|
|
18925
|
-
return node.parent?.type ===
|
|
19051
|
+
return node.parent?.type === AST_NODE_TYPES90.ExportNamedDeclaration;
|
|
18926
19052
|
}
|
|
18927
19053
|
function isModuleLevelDeclaration(node) {
|
|
18928
19054
|
const parent = node.parent;
|
|
18929
|
-
return parent?.type ===
|
|
19055
|
+
return parent?.type === AST_NODE_TYPES90.Program || parent?.type === AST_NODE_TYPES90.ExportNamedDeclaration && parent.parent.type === AST_NODE_TYPES90.Program;
|
|
18930
19056
|
}
|
|
18931
19057
|
function isModuleLevelConst(node) {
|
|
18932
19058
|
const declaration = node.parent;
|
|
18933
|
-
if (declaration.type !==
|
|
19059
|
+
if (declaration.type !== AST_NODE_TYPES90.VariableDeclaration || declaration.kind !== "const") {
|
|
18934
19060
|
return false;
|
|
18935
19061
|
}
|
|
18936
19062
|
const container = declaration.parent;
|
|
18937
|
-
return container.type ===
|
|
19063
|
+
return container.type === AST_NODE_TYPES90.Program || container.type === AST_NODE_TYPES90.ExportNamedDeclaration && container.parent.type === AST_NODE_TYPES90.Program;
|
|
18938
19064
|
}
|
|
18939
19065
|
function normalizeSchemaName(name) {
|
|
18940
19066
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -18943,20 +19069,20 @@ function normalizeTypeName(name) {
|
|
|
18943
19069
|
return name.replace(/Type$/, "").toLowerCase();
|
|
18944
19070
|
}
|
|
18945
19071
|
function unwrapNullish(annotation) {
|
|
18946
|
-
if (annotation.type !==
|
|
19072
|
+
if (annotation.type !== AST_NODE_TYPES90.TSUnionType) {
|
|
18947
19073
|
return {
|
|
18948
19074
|
core: annotation,
|
|
18949
|
-
nullable: annotation.type ===
|
|
19075
|
+
nullable: annotation.type === AST_NODE_TYPES90.TSNullKeyword
|
|
18950
19076
|
};
|
|
18951
19077
|
}
|
|
18952
19078
|
const rest = [];
|
|
18953
19079
|
let nullable = false;
|
|
18954
19080
|
for (const member of annotation.types) {
|
|
18955
|
-
if (member.type ===
|
|
19081
|
+
if (member.type === AST_NODE_TYPES90.TSNullKeyword) {
|
|
18956
19082
|
nullable = true;
|
|
18957
19083
|
continue;
|
|
18958
19084
|
}
|
|
18959
|
-
if (member.type ===
|
|
19085
|
+
if (member.type === AST_NODE_TYPES90.TSUndefinedKeyword) {
|
|
18960
19086
|
continue;
|
|
18961
19087
|
}
|
|
18962
19088
|
rest.push(member);
|
|
@@ -19008,18 +19134,18 @@ function leafAgrees(field, annotation) {
|
|
|
19008
19134
|
return null;
|
|
19009
19135
|
}
|
|
19010
19136
|
if (leaf === "date") {
|
|
19011
|
-
return core.type ===
|
|
19137
|
+
return core.type === AST_NODE_TYPES90.TSTypeReference && core.typeName.type === AST_NODE_TYPES90.Identifier && core.typeName.name === "Date";
|
|
19012
19138
|
}
|
|
19013
19139
|
return expected.includes(core.type);
|
|
19014
19140
|
}
|
|
19015
19141
|
function typeLiteralDomain(annotation) {
|
|
19016
|
-
const members = annotation.type ===
|
|
19142
|
+
const members = annotation.type === AST_NODE_TYPES90.TSUnionType ? annotation.types : [annotation];
|
|
19017
19143
|
const keys = [];
|
|
19018
19144
|
for (const member of members) {
|
|
19019
|
-
if (member.type ===
|
|
19145
|
+
if (member.type === AST_NODE_TYPES90.TSNullKeyword) {
|
|
19020
19146
|
continue;
|
|
19021
19147
|
}
|
|
19022
|
-
if (member.type !==
|
|
19148
|
+
if (member.type !== AST_NODE_TYPES90.TSLiteralType) {
|
|
19023
19149
|
return null;
|
|
19024
19150
|
}
|
|
19025
19151
|
keys.push(primitiveLiteralKey(member.literal));
|
|
@@ -19027,11 +19153,11 @@ function typeLiteralDomain(annotation) {
|
|
|
19027
19153
|
return exactDomain(keys);
|
|
19028
19154
|
}
|
|
19029
19155
|
function staticStringUnionDomain(node) {
|
|
19030
|
-
if (node.type !==
|
|
19156
|
+
if (node.type !== AST_NODE_TYPES90.TSUnionType) {
|
|
19031
19157
|
return null;
|
|
19032
19158
|
}
|
|
19033
19159
|
const keys = node.types.map((member) => {
|
|
19034
|
-
if (member.type !==
|
|
19160
|
+
if (member.type !== AST_NODE_TYPES90.TSLiteralType) {
|
|
19035
19161
|
return null;
|
|
19036
19162
|
}
|
|
19037
19163
|
const key = primitiveLiteralKey(member.literal);
|
|
@@ -19043,13 +19169,13 @@ function staticStringUnionDomain(node) {
|
|
|
19043
19169
|
function twinCallChain(node, zodNamespaces) {
|
|
19044
19170
|
const chain = [];
|
|
19045
19171
|
let current = node;
|
|
19046
|
-
while (current.type ===
|
|
19172
|
+
while (current.type === AST_NODE_TYPES90.CallExpression) {
|
|
19047
19173
|
const callee = current.callee;
|
|
19048
|
-
if (callee.type !==
|
|
19174
|
+
if (callee.type !== AST_NODE_TYPES90.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES90.Identifier) {
|
|
19049
19175
|
return null;
|
|
19050
19176
|
}
|
|
19051
19177
|
chain.push(current);
|
|
19052
|
-
if (callee.object.type ===
|
|
19178
|
+
if (callee.object.type === AST_NODE_TYPES90.Identifier) {
|
|
19053
19179
|
return zodNamespaces.has(callee.object.name) ? chain.reverse() : null;
|
|
19054
19180
|
}
|
|
19055
19181
|
current = callee.object;
|
|
@@ -19058,7 +19184,7 @@ function twinCallChain(node, zodNamespaces) {
|
|
|
19058
19184
|
}
|
|
19059
19185
|
function twinMethodName(call) {
|
|
19060
19186
|
const callee = call.callee;
|
|
19061
|
-
return callee.type ===
|
|
19187
|
+
return callee.type === AST_NODE_TYPES90.MemberExpression && callee.property.type === AST_NODE_TYPES90.Identifier ? callee.property.name : "";
|
|
19062
19188
|
}
|
|
19063
19189
|
function twinSchemaFields(initializer, zodNamespaces) {
|
|
19064
19190
|
const chain = twinCallChain(initializer, zodNamespaces);
|
|
@@ -19069,10 +19195,10 @@ function twinSchemaFields(initializer, zodNamespaces) {
|
|
|
19069
19195
|
if (baseMethod !== "object" && baseMethod !== "strictObject") return null;
|
|
19070
19196
|
if (rest.some((call) => !SHAPE_PRESERVING_METHODS.has(twinMethodName(call)))) return null;
|
|
19071
19197
|
const shape = base.arguments[0];
|
|
19072
|
-
if (shape === void 0 || shape.type !==
|
|
19198
|
+
if (shape === void 0 || shape.type !== AST_NODE_TYPES90.ObjectExpression) return null;
|
|
19073
19199
|
const fields = /* @__PURE__ */ new Map();
|
|
19074
19200
|
for (const property of shape.properties) {
|
|
19075
|
-
if (property.type !==
|
|
19201
|
+
if (property.type !== AST_NODE_TYPES90.Property || property.computed) return null;
|
|
19076
19202
|
const { key } = property;
|
|
19077
19203
|
const name = staticFieldName(key);
|
|
19078
19204
|
if (name === null) return null;
|
|
@@ -19085,13 +19211,13 @@ function twinSchemaField(node, zodNamespaces) {
|
|
|
19085
19211
|
let current = node;
|
|
19086
19212
|
let leaf = null;
|
|
19087
19213
|
let leafCall = null;
|
|
19088
|
-
while (current.type ===
|
|
19214
|
+
while (current.type === AST_NODE_TYPES90.CallExpression) {
|
|
19089
19215
|
const callee = current.callee;
|
|
19090
|
-
if (callee.type !==
|
|
19216
|
+
if (callee.type !== AST_NODE_TYPES90.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES90.Identifier) {
|
|
19091
19217
|
break;
|
|
19092
19218
|
}
|
|
19093
19219
|
const receiver = callee.object;
|
|
19094
|
-
if (receiver.type ===
|
|
19220
|
+
if (receiver.type === AST_NODE_TYPES90.Identifier && zodNamespaces.has(receiver.name)) {
|
|
19095
19221
|
leaf = callee.property.name;
|
|
19096
19222
|
leafCall = current;
|
|
19097
19223
|
break;
|
|
@@ -19109,18 +19235,18 @@ function twinSchemaField(node, zodNamespaces) {
|
|
|
19109
19235
|
}
|
|
19110
19236
|
function twinTypeMembers(declaration) {
|
|
19111
19237
|
let members;
|
|
19112
|
-
if (declaration.type ===
|
|
19238
|
+
if (declaration.type === AST_NODE_TYPES90.TSInterfaceDeclaration) {
|
|
19113
19239
|
if (declaration.typeParameters !== void 0 || (declaration.extends?.length ?? 0) > 0) return null;
|
|
19114
19240
|
members = declaration.body.body;
|
|
19115
19241
|
} else {
|
|
19116
|
-
if (declaration.typeParameters !== void 0 || declaration.typeAnnotation.type !==
|
|
19242
|
+
if (declaration.typeParameters !== void 0 || declaration.typeAnnotation.type !== AST_NODE_TYPES90.TSTypeLiteral) {
|
|
19117
19243
|
return null;
|
|
19118
19244
|
}
|
|
19119
19245
|
members = declaration.typeAnnotation.members;
|
|
19120
19246
|
}
|
|
19121
19247
|
const result = /* @__PURE__ */ new Map();
|
|
19122
19248
|
for (const member of members) {
|
|
19123
|
-
if (member.type !==
|
|
19249
|
+
if (member.type !== AST_NODE_TYPES90.TSPropertySignature || member.computed) return null;
|
|
19124
19250
|
const { key } = member;
|
|
19125
19251
|
const name = staticFieldName(key);
|
|
19126
19252
|
if (name === null) return null;
|
|
@@ -19195,7 +19321,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
19195
19321
|
return;
|
|
19196
19322
|
}
|
|
19197
19323
|
for (const specifier of node.specifiers) {
|
|
19198
|
-
if (specifier.type ===
|
|
19324
|
+
if (specifier.type === AST_NODE_TYPES90.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES90.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES90.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES90.Identifier && specifier.imported.name === "z") {
|
|
19199
19325
|
zodNamespaces.add(specifier.local.name);
|
|
19200
19326
|
}
|
|
19201
19327
|
}
|
|
@@ -19213,20 +19339,20 @@ var prefer_zod_infer_default = createRule({
|
|
|
19213
19339
|
return domain instanceof Set && domain.size >= 2 ? domain : null;
|
|
19214
19340
|
}
|
|
19215
19341
|
function inferredSchemaName(node) {
|
|
19216
|
-
if (node.type !==
|
|
19342
|
+
if (node.type !== AST_NODE_TYPES90.TSTypeReference || node.typeName.type !== AST_NODE_TYPES90.TSQualifiedName || node.typeName.left.type !== AST_NODE_TYPES90.Identifier || !zodNamespaces.has(node.typeName.left.name) || node.typeName.right.name !== "infer") {
|
|
19217
19343
|
return null;
|
|
19218
19344
|
}
|
|
19219
19345
|
const arguments_ = node.typeArguments?.params ?? [];
|
|
19220
19346
|
const [argument] = arguments_;
|
|
19221
|
-
return arguments_.length === 1 && argument?.type ===
|
|
19347
|
+
return arguments_.length === 1 && argument?.type === AST_NODE_TYPES90.TSTypeQuery && argument.exprName.type === AST_NODE_TYPES90.Identifier ? argument.exprName.name : null;
|
|
19222
19348
|
}
|
|
19223
19349
|
function recordLiteralUnions(members, owner, ownerName, exported) {
|
|
19224
19350
|
for (const member of members) {
|
|
19225
|
-
if (member.type !==
|
|
19351
|
+
if (member.type !== AST_NODE_TYPES90.TSPropertySignature || member.computed || member.optional || member.readonly || member.typeAnnotation === void 0) {
|
|
19226
19352
|
continue;
|
|
19227
19353
|
}
|
|
19228
19354
|
const key = member.key;
|
|
19229
|
-
const propertyName7 = key.type ===
|
|
19355
|
+
const propertyName7 = key.type === AST_NODE_TYPES90.Identifier ? key.name : key.type === AST_NODE_TYPES90.Literal && typeof key.value === "string" ? key.value : null;
|
|
19230
19356
|
if (propertyName7 === null) {
|
|
19231
19357
|
continue;
|
|
19232
19358
|
}
|
|
@@ -19236,7 +19362,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
19236
19362
|
}
|
|
19237
19363
|
const annotation = member.typeAnnotation.typeAnnotation;
|
|
19238
19364
|
const domain = staticStringUnionDomain(annotation);
|
|
19239
|
-
if (domain === null || annotation.type !==
|
|
19365
|
+
if (domain === null || annotation.type !== AST_NODE_TYPES90.TSUnionType) {
|
|
19240
19366
|
continue;
|
|
19241
19367
|
}
|
|
19242
19368
|
literalUnionOccurrences.push({
|
|
@@ -19251,8 +19377,8 @@ var prefer_zod_infer_default = createRule({
|
|
|
19251
19377
|
}
|
|
19252
19378
|
}
|
|
19253
19379
|
function collectConstrainedNames2(node) {
|
|
19254
|
-
if (node.type ===
|
|
19255
|
-
if (node.typeName.type ===
|
|
19380
|
+
if (node.type === AST_NODE_TYPES90.TSTypeReference) {
|
|
19381
|
+
if (node.typeName.type === AST_NODE_TYPES90.Identifier) {
|
|
19256
19382
|
constrainedTypeNames.add(node.typeName.name);
|
|
19257
19383
|
}
|
|
19258
19384
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -19260,11 +19386,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
19260
19386
|
}
|
|
19261
19387
|
return;
|
|
19262
19388
|
}
|
|
19263
|
-
if (node.type ===
|
|
19389
|
+
if (node.type === AST_NODE_TYPES90.TSArrayType) {
|
|
19264
19390
|
collectConstrainedNames2(node.elementType);
|
|
19265
19391
|
return;
|
|
19266
19392
|
}
|
|
19267
|
-
if (node.type ===
|
|
19393
|
+
if (node.type === AST_NODE_TYPES90.TSUnionType || node.type === AST_NODE_TYPES90.TSIntersectionType) {
|
|
19268
19394
|
for (const member of node.types) {
|
|
19269
19395
|
collectConstrainedNames2(member);
|
|
19270
19396
|
}
|
|
@@ -19273,7 +19399,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
19273
19399
|
return {
|
|
19274
19400
|
Program(node) {
|
|
19275
19401
|
for (const statement of node.body) {
|
|
19276
|
-
if (statement.type ===
|
|
19402
|
+
if (statement.type === AST_NODE_TYPES90.ImportDeclaration) {
|
|
19277
19403
|
recordZodImport(statement);
|
|
19278
19404
|
}
|
|
19279
19405
|
}
|
|
@@ -19282,7 +19408,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
19282
19408
|
recordZodImport(node);
|
|
19283
19409
|
},
|
|
19284
19410
|
VariableDeclarator(node) {
|
|
19285
|
-
if (node.id.type !==
|
|
19411
|
+
if (node.id.type !== AST_NODE_TYPES90.Identifier || node.init == null || !isModuleLevelConst(node)) {
|
|
19286
19412
|
return;
|
|
19287
19413
|
}
|
|
19288
19414
|
const fields = twinSchemaFields(node.init, zodNamespaces);
|
|
@@ -19299,14 +19425,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
19299
19425
|
},
|
|
19300
19426
|
/** Records `XSchema.transform(...)` and equivalent module-level reshaping. */
|
|
19301
19427
|
"MemberExpression[computed=false]"(node) {
|
|
19302
|
-
if (node.object.type ===
|
|
19428
|
+
if (node.object.type === AST_NODE_TYPES90.Identifier && node.property.type === AST_NODE_TYPES90.Identifier && isPreferZodInferModuleReshaper(node.property.name)) {
|
|
19303
19429
|
reshapedSchemaNames.add(node.object.name);
|
|
19304
19430
|
}
|
|
19305
19431
|
},
|
|
19306
19432
|
/** Records every type argument carried by a Zod constraint. */
|
|
19307
19433
|
TSTypeReference(node) {
|
|
19308
19434
|
const { typeName } = node;
|
|
19309
|
-
const referenced = typeName.type ===
|
|
19435
|
+
const referenced = typeName.type === AST_NODE_TYPES90.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES90.TSQualifiedName && typeName.right.type === AST_NODE_TYPES90.Identifier ? typeName.right.name : null;
|
|
19310
19436
|
if (referenced === null || !isPreferZodInferTypeConstraintName(referenced)) {
|
|
19311
19437
|
return;
|
|
19312
19438
|
}
|
|
@@ -19340,7 +19466,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
19340
19466
|
typeName: node.id.name
|
|
19341
19467
|
});
|
|
19342
19468
|
}
|
|
19343
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
19469
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== AST_NODE_TYPES90.TSTypeLiteral) {
|
|
19344
19470
|
return;
|
|
19345
19471
|
}
|
|
19346
19472
|
const members = twinTypeMembers(node);
|
|
@@ -19452,12 +19578,12 @@ var prefer_zod_infer_default = createRule({
|
|
|
19452
19578
|
}
|
|
19453
19579
|
});
|
|
19454
19580
|
function staticFieldName(key) {
|
|
19455
|
-
return key.type ===
|
|
19581
|
+
return key.type === AST_NODE_TYPES90.Identifier ? key.name : key.type === AST_NODE_TYPES90.Literal && typeof key.value === "string" ? key.value : null;
|
|
19456
19582
|
}
|
|
19457
19583
|
|
|
19458
19584
|
// src/rules/prefer-zod-parse-output-type.ts
|
|
19459
19585
|
import {
|
|
19460
|
-
AST_NODE_TYPES as
|
|
19586
|
+
AST_NODE_TYPES as AST_NODE_TYPES91,
|
|
19461
19587
|
ESLintUtils as ESLintUtils13
|
|
19462
19588
|
} from "@typescript-eslint/utils";
|
|
19463
19589
|
import ts11 from "typescript";
|
|
@@ -19513,20 +19639,20 @@ var PREFER_ZOD_PARSE_OUTPUT_TYPE_DOCUMENTATION = {
|
|
|
19513
19639
|
};
|
|
19514
19640
|
function isModuleLevelConst2(node) {
|
|
19515
19641
|
const declaration = node.parent;
|
|
19516
|
-
if (declaration.type !==
|
|
19642
|
+
if (declaration.type !== AST_NODE_TYPES91.VariableDeclaration || declaration.kind !== "const") {
|
|
19517
19643
|
return false;
|
|
19518
19644
|
}
|
|
19519
19645
|
const container = declaration.parent;
|
|
19520
|
-
return container.type ===
|
|
19646
|
+
return container.type === AST_NODE_TYPES91.Program || container.type === AST_NODE_TYPES91.ExportNamedDeclaration && container.parent.type === AST_NODE_TYPES91.Program;
|
|
19521
19647
|
}
|
|
19522
19648
|
function isLocalZodObjectSchema(node, namespaces) {
|
|
19523
19649
|
let current = node;
|
|
19524
|
-
while (current.type ===
|
|
19650
|
+
while (current.type === AST_NODE_TYPES91.CallExpression) {
|
|
19525
19651
|
const { callee } = current;
|
|
19526
|
-
if (callee.type !==
|
|
19652
|
+
if (callee.type !== AST_NODE_TYPES91.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES91.Identifier) {
|
|
19527
19653
|
return false;
|
|
19528
19654
|
}
|
|
19529
|
-
if (callee.object.type ===
|
|
19655
|
+
if (callee.object.type === AST_NODE_TYPES91.Identifier) {
|
|
19530
19656
|
return namespaces.has(callee.object.name) && (callee.property.name === "object" || callee.property.name === "strictObject");
|
|
19531
19657
|
}
|
|
19532
19658
|
current = callee.object;
|
|
@@ -19535,7 +19661,7 @@ function isLocalZodObjectSchema(node, namespaces) {
|
|
|
19535
19661
|
}
|
|
19536
19662
|
function zodParseCall(node) {
|
|
19537
19663
|
const { callee } = node;
|
|
19538
|
-
if (callee.type !==
|
|
19664
|
+
if (callee.type !== AST_NODE_TYPES91.MemberExpression || callee.computed || callee.object.type !== AST_NODE_TYPES91.Identifier || callee.property.type !== AST_NODE_TYPES91.Identifier || callee.property.name !== "parse" && callee.property.name !== "safeParse") {
|
|
19539
19665
|
return null;
|
|
19540
19666
|
}
|
|
19541
19667
|
return {
|
|
@@ -19550,7 +19676,7 @@ function returnedOutputCandidate(parsed, output) {
|
|
|
19550
19676
|
const annotation = owner?.returnType?.typeAnnotation;
|
|
19551
19677
|
if (annotation === void 0) return null;
|
|
19552
19678
|
const typeReference = returnContractReference(annotation);
|
|
19553
|
-
if (typeReference === null || typeReference.typeName.type !==
|
|
19679
|
+
if (typeReference === null || typeReference.typeName.type !== AST_NODE_TYPES91.Identifier) {
|
|
19554
19680
|
return null;
|
|
19555
19681
|
}
|
|
19556
19682
|
return {
|
|
@@ -19567,7 +19693,7 @@ function directParseReturnCandidate(node) {
|
|
|
19567
19693
|
return parsed?.method === "parse" ? returnedOutputCandidate(parsed, node) : null;
|
|
19568
19694
|
}
|
|
19569
19695
|
function localParseReturnCandidates(node, sourceCode) {
|
|
19570
|
-
if (node.id.type !==
|
|
19696
|
+
if (node.id.type !== AST_NODE_TYPES91.Identifier || node.init?.type !== AST_NODE_TYPES91.CallExpression || node.parent.type !== AST_NODE_TYPES91.VariableDeclaration || node.parent.kind !== "const" || enclosingFunction4(node.init) === null) {
|
|
19571
19697
|
return [];
|
|
19572
19698
|
}
|
|
19573
19699
|
const parsed = zodParseCall(node.init);
|
|
@@ -19578,7 +19704,7 @@ function localParseReturnCandidates(node, sourceCode) {
|
|
|
19578
19704
|
for (const reference of variable.references) {
|
|
19579
19705
|
const identifier = reference.identifier;
|
|
19580
19706
|
const parent = identifier.parent;
|
|
19581
|
-
const output = parsed.method === "parse" ? identifier : parent.type ===
|
|
19707
|
+
const output = parsed.method === "parse" ? identifier : parent.type === AST_NODE_TYPES91.MemberExpression && parent.object === identifier && !parent.computed && parent.property.type === AST_NODE_TYPES91.Identifier && parent.property.name === "data" ? parent : null;
|
|
19582
19708
|
if (output === null) continue;
|
|
19583
19709
|
const candidate2 = returnedOutputCandidate(parsed, output);
|
|
19584
19710
|
if (candidate2 !== null) candidates.push(candidate2);
|
|
@@ -19589,17 +19715,17 @@ function directReturnOwner(node) {
|
|
|
19589
19715
|
let current = node;
|
|
19590
19716
|
while (current.parent !== void 0) {
|
|
19591
19717
|
const parent = current.parent;
|
|
19592
|
-
if (parent.type ===
|
|
19718
|
+
if (parent.type === AST_NODE_TYPES91.ReturnStatement) {
|
|
19593
19719
|
return parent.argument === current ? enclosingFunction4(parent) : null;
|
|
19594
19720
|
}
|
|
19595
|
-
if (parent.type ===
|
|
19721
|
+
if (parent.type === AST_NODE_TYPES91.ArrowFunctionExpression && parent.expression && parent.body === current) {
|
|
19596
19722
|
return parent;
|
|
19597
19723
|
}
|
|
19598
|
-
if (parent.type ===
|
|
19724
|
+
if (parent.type === AST_NODE_TYPES91.AwaitExpression && parent.argument === current) {
|
|
19599
19725
|
current = parent;
|
|
19600
19726
|
continue;
|
|
19601
19727
|
}
|
|
19602
|
-
if (parent.type ===
|
|
19728
|
+
if (parent.type === AST_NODE_TYPES91.ConditionalExpression) {
|
|
19603
19729
|
const parsedWhenTrue = parent.consequent === current && isNullishExpression(parent.alternate);
|
|
19604
19730
|
const parsedWhenFalse = parent.alternate === current && isNullishExpression(parent.consequent);
|
|
19605
19731
|
if (parsedWhenTrue || parsedWhenFalse) {
|
|
@@ -19612,12 +19738,12 @@ function directReturnOwner(node) {
|
|
|
19612
19738
|
return null;
|
|
19613
19739
|
}
|
|
19614
19740
|
function isNullishExpression(node) {
|
|
19615
|
-
return node.type ===
|
|
19741
|
+
return node.type === AST_NODE_TYPES91.Literal && node.value === null || node.type === AST_NODE_TYPES91.Identifier && node.name === "undefined";
|
|
19616
19742
|
}
|
|
19617
19743
|
function enclosingFunction4(node) {
|
|
19618
19744
|
let current = node.parent;
|
|
19619
19745
|
while (current != null) {
|
|
19620
|
-
if (current.type ===
|
|
19746
|
+
if (current.type === AST_NODE_TYPES91.ArrowFunctionExpression || current.type === AST_NODE_TYPES91.FunctionDeclaration || current.type === AST_NODE_TYPES91.FunctionExpression) {
|
|
19621
19747
|
return current;
|
|
19622
19748
|
}
|
|
19623
19749
|
current = current.parent;
|
|
@@ -19625,45 +19751,45 @@ function enclosingFunction4(node) {
|
|
|
19625
19751
|
return null;
|
|
19626
19752
|
}
|
|
19627
19753
|
function returnContractReference(node) {
|
|
19628
|
-
if (node.type ===
|
|
19754
|
+
if (node.type === AST_NODE_TYPES91.TSUnionType) {
|
|
19629
19755
|
const substantive = node.types.filter(
|
|
19630
|
-
(member) => member.type !==
|
|
19756
|
+
(member) => member.type !== AST_NODE_TYPES91.TSNullKeyword && member.type !== AST_NODE_TYPES91.TSUndefinedKeyword
|
|
19631
19757
|
);
|
|
19632
19758
|
const [only] = substantive;
|
|
19633
19759
|
return substantive.length === 1 && only !== void 0 ? returnContractReference(only) : null;
|
|
19634
19760
|
}
|
|
19635
|
-
if (node.type ===
|
|
19761
|
+
if (node.type === AST_NODE_TYPES91.TSTypeReference && node.typeName.type === AST_NODE_TYPES91.Identifier && node.typeName.name === "Promise") {
|
|
19636
19762
|
const parameters = node.typeArguments?.params ?? [];
|
|
19637
19763
|
const [only] = parameters;
|
|
19638
19764
|
return parameters.length === 1 && only !== void 0 ? returnContractReference(only) : null;
|
|
19639
19765
|
}
|
|
19640
|
-
return node.type ===
|
|
19766
|
+
return node.type === AST_NODE_TYPES91.TSTypeReference && node.typeName.type === AST_NODE_TYPES91.Identifier && (node.typeArguments?.params.length ?? 0) === 0 ? node : null;
|
|
19641
19767
|
}
|
|
19642
19768
|
function recordZodNamespaces(node, namespaces) {
|
|
19643
19769
|
for (const statement of node.body) {
|
|
19644
|
-
if (statement.type !==
|
|
19770
|
+
if (statement.type !== AST_NODE_TYPES91.ImportDeclaration || !isZodModule(statement.source.value)) {
|
|
19645
19771
|
continue;
|
|
19646
19772
|
}
|
|
19647
19773
|
for (const specifier of statement.specifiers) {
|
|
19648
|
-
if (specifier.type ===
|
|
19774
|
+
if (specifier.type === AST_NODE_TYPES91.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES91.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES91.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES91.Identifier && specifier.imported.name === "z") {
|
|
19649
19775
|
namespaces.add(specifier.local.name);
|
|
19650
19776
|
}
|
|
19651
19777
|
}
|
|
19652
19778
|
}
|
|
19653
19779
|
}
|
|
19654
19780
|
function collectConstrainedNames(node, names) {
|
|
19655
|
-
if (node.type ===
|
|
19656
|
-
if (node.typeName.type ===
|
|
19781
|
+
if (node.type === AST_NODE_TYPES91.TSTypeReference) {
|
|
19782
|
+
if (node.typeName.type === AST_NODE_TYPES91.Identifier) names.add(node.typeName.name);
|
|
19657
19783
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
19658
19784
|
collectConstrainedNames(argument, names);
|
|
19659
19785
|
}
|
|
19660
19786
|
return;
|
|
19661
19787
|
}
|
|
19662
|
-
if (node.type ===
|
|
19788
|
+
if (node.type === AST_NODE_TYPES91.TSArrayType) {
|
|
19663
19789
|
collectConstrainedNames(node.elementType, names);
|
|
19664
19790
|
return;
|
|
19665
19791
|
}
|
|
19666
|
-
if (node.type ===
|
|
19792
|
+
if (node.type === AST_NODE_TYPES91.TSUnionType || node.type === AST_NODE_TYPES91.TSIntersectionType) {
|
|
19667
19793
|
for (const member of node.types) collectConstrainedNames(member, names);
|
|
19668
19794
|
}
|
|
19669
19795
|
}
|
|
@@ -19697,7 +19823,7 @@ function reportCandidates(context, services, schemas, candidates, zodNamespaces,
|
|
|
19697
19823
|
if (constrained) return;
|
|
19698
19824
|
if (declaration.getSourceFile() === tsSchema.getSourceFile()) {
|
|
19699
19825
|
const estreeDeclaration = services.tsNodeToESTreeNodeMap.get(declaration);
|
|
19700
|
-
if ((estreeDeclaration.type ===
|
|
19826
|
+
if ((estreeDeclaration.type === AST_NODE_TYPES91.TSInterfaceDeclaration || estreeDeclaration.type === AST_NODE_TYPES91.TSTypeAliasDeclaration) && preferZodInferOwnsDefaultTwin({
|
|
19701
19827
|
constrained,
|
|
19702
19828
|
declaration: estreeDeclaration,
|
|
19703
19829
|
initializer: schema.initializer,
|
|
@@ -19802,7 +19928,7 @@ var prefer_zod_parse_output_type_default = createRule({
|
|
|
19802
19928
|
recordZodNamespaces(node, namespaces);
|
|
19803
19929
|
},
|
|
19804
19930
|
VariableDeclarator(node) {
|
|
19805
|
-
if (node.id.type ===
|
|
19931
|
+
if (node.id.type === AST_NODE_TYPES91.Identifier && node.init !== null && isModuleLevelConst2(node) && isLocalZodObjectSchema(node.init, namespaces)) {
|
|
19806
19932
|
schemas.push({ identifier: node.id, initializer: node.init, name: node.id.name });
|
|
19807
19933
|
}
|
|
19808
19934
|
candidates.push(...localParseReturnCandidates(node, context.sourceCode));
|
|
@@ -19812,13 +19938,13 @@ var prefer_zod_parse_output_type_default = createRule({
|
|
|
19812
19938
|
if (candidate2 !== null) candidates.push(candidate2);
|
|
19813
19939
|
},
|
|
19814
19940
|
"MemberExpression[computed=false]"(node) {
|
|
19815
|
-
if (node.object.type ===
|
|
19941
|
+
if (node.object.type === AST_NODE_TYPES91.Identifier && node.property.type === AST_NODE_TYPES91.Identifier && isPreferZodInferModuleReshaper(node.property.name)) {
|
|
19816
19942
|
reshapedSchemas.add(node.object.name);
|
|
19817
19943
|
}
|
|
19818
19944
|
},
|
|
19819
19945
|
TSTypeReference(node) {
|
|
19820
19946
|
const { typeName } = node;
|
|
19821
|
-
const name = typeName.type ===
|
|
19947
|
+
const name = typeName.type === AST_NODE_TYPES91.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES91.TSQualifiedName && typeName.right.type === AST_NODE_TYPES91.Identifier ? typeName.right.name : null;
|
|
19822
19948
|
if (name === null || !isPreferZodInferTypeConstraintName(name)) return;
|
|
19823
19949
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
19824
19950
|
collectConstrainedNames(argument, constrainedTypeNames);
|
|
@@ -19842,7 +19968,7 @@ var prefer_zod_parse_output_type_default = createRule({
|
|
|
19842
19968
|
// src/rules/require-assert-never.ts
|
|
19843
19969
|
import {
|
|
19844
19970
|
ESLintUtils as ESLintUtils14,
|
|
19845
|
-
AST_NODE_TYPES as
|
|
19971
|
+
AST_NODE_TYPES as AST_NODE_TYPES92
|
|
19846
19972
|
} from "@typescript-eslint/utils";
|
|
19847
19973
|
import ts12 from "typescript";
|
|
19848
19974
|
var REQUIRE_ASSERT_NEVER_DOCUMENTATION = {
|
|
@@ -19857,14 +19983,14 @@ var REQUIRE_ASSERT_NEVER_DOCUMENTATION = {
|
|
|
19857
19983
|
]
|
|
19858
19984
|
};
|
|
19859
19985
|
var isRuntimeHandlingStatement = (statement) => {
|
|
19860
|
-
if (statement.type ===
|
|
19861
|
-
if (statement.type ===
|
|
19986
|
+
if (statement.type === AST_NODE_TYPES92.EmptyStatement) return false;
|
|
19987
|
+
if (statement.type === AST_NODE_TYPES92.BreakStatement) {
|
|
19862
19988
|
return statement.label !== null;
|
|
19863
19989
|
}
|
|
19864
|
-
if (statement.type ===
|
|
19990
|
+
if (statement.type === AST_NODE_TYPES92.TSTypeAliasDeclaration || statement.type === AST_NODE_TYPES92.TSInterfaceDeclaration) {
|
|
19865
19991
|
return false;
|
|
19866
19992
|
}
|
|
19867
|
-
if (statement.type ===
|
|
19993
|
+
if (statement.type === AST_NODE_TYPES92.BlockStatement) {
|
|
19868
19994
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
19869
19995
|
}
|
|
19870
19996
|
return true;
|
|
@@ -19880,7 +20006,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
19880
20006
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
19881
20007
|
}
|
|
19882
20008
|
const only = defaultCase.consequent[0];
|
|
19883
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
20009
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === AST_NODE_TYPES92.BlockStatement && !only.body.some(isRuntimeHandlingStatement)) {
|
|
19884
20010
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
19885
20011
|
}
|
|
19886
20012
|
return false;
|
|
@@ -19961,7 +20087,7 @@ var require_assert_never_default = createRule({
|
|
|
19961
20087
|
});
|
|
19962
20088
|
|
|
19963
20089
|
// src/rules/require-fetch-timeout.ts
|
|
19964
|
-
import { AST_NODE_TYPES as
|
|
20090
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES93, ASTUtils as ASTUtils47 } from "@typescript-eslint/utils";
|
|
19965
20091
|
var REQUIRE_FETCH_TIMEOUT_DOCUMENTATION = {
|
|
19966
20092
|
summary: "Require an explicit abort signal on locally analyzable global fetch calls.",
|
|
19967
20093
|
rationale: "An unbounded request can occupy work indefinitely when an upstream stalls.",
|
|
@@ -19988,14 +20114,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
19988
20114
|
return false;
|
|
19989
20115
|
}
|
|
19990
20116
|
function initProvablyLacksSignal(init) {
|
|
19991
|
-
if (init.type !==
|
|
20117
|
+
if (init.type !== AST_NODE_TYPES93.ObjectExpression) {
|
|
19992
20118
|
return false;
|
|
19993
20119
|
}
|
|
19994
20120
|
for (const prop of init.properties) {
|
|
19995
|
-
if (prop.type ===
|
|
20121
|
+
if (prop.type === AST_NODE_TYPES93.SpreadElement) {
|
|
19996
20122
|
return false;
|
|
19997
20123
|
}
|
|
19998
|
-
if (prop.key.type ===
|
|
20124
|
+
if (prop.key.type === AST_NODE_TYPES93.Identifier && prop.key.name === "signal" || prop.key.type === AST_NODE_TYPES93.Literal && prop.key.value === "signal") {
|
|
19999
20125
|
return false;
|
|
20000
20126
|
}
|
|
20001
20127
|
if (prop.computed) {
|
|
@@ -20005,7 +20131,7 @@ function initProvablyLacksSignal(init) {
|
|
|
20005
20131
|
return true;
|
|
20006
20132
|
}
|
|
20007
20133
|
function isInlineUrl(node, resolvesToGlobal) {
|
|
20008
|
-
return node.type ===
|
|
20134
|
+
return node.type === AST_NODE_TYPES93.Literal && typeof node.value === "string" || node.type === AST_NODE_TYPES93.TemplateLiteral || node.type === AST_NODE_TYPES93.NewExpression && node.callee.type === AST_NODE_TYPES93.Identifier && node.callee.name === "URL" && resolvesToGlobal(node.callee);
|
|
20009
20135
|
}
|
|
20010
20136
|
var require_fetch_timeout_default = createRule({
|
|
20011
20137
|
name: "require-fetch-timeout",
|
|
@@ -20043,30 +20169,30 @@ var require_fetch_timeout_default = createRule({
|
|
|
20043
20169
|
}
|
|
20044
20170
|
function resolvesToGlobal(identifier) {
|
|
20045
20171
|
const scope = context.sourceCode.getScope(identifier);
|
|
20046
|
-
const variable =
|
|
20172
|
+
const variable = ASTUtils47.findVariable(scope, identifier.name);
|
|
20047
20173
|
return variable === null || variable.defs.length === 0;
|
|
20048
20174
|
}
|
|
20049
20175
|
function isGlobalFetchCall2(callee) {
|
|
20050
|
-
if (callee.type ===
|
|
20176
|
+
if (callee.type === AST_NODE_TYPES93.Identifier) {
|
|
20051
20177
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
20052
20178
|
}
|
|
20053
|
-
return callee.type ===
|
|
20179
|
+
return callee.type === AST_NODE_TYPES93.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES93.Identifier && callee.property.name === "fetch" && callee.object.type === AST_NODE_TYPES93.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
20054
20180
|
}
|
|
20055
20181
|
function localConstInitProvablyLacksSignal(identifier) {
|
|
20056
|
-
const variable =
|
|
20182
|
+
const variable = ASTUtils47.findVariable(
|
|
20057
20183
|
context.sourceCode.getScope(identifier),
|
|
20058
20184
|
identifier.name
|
|
20059
20185
|
);
|
|
20060
20186
|
if (variable?.defs.length !== 1) return false;
|
|
20061
20187
|
const definition = variable.defs[0];
|
|
20062
|
-
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !==
|
|
20188
|
+
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !== AST_NODE_TYPES93.ObjectExpression || !initProvablyLacksSignal(definition.node.init)) {
|
|
20063
20189
|
return false;
|
|
20064
20190
|
}
|
|
20065
20191
|
for (const reference of variable.references) {
|
|
20066
20192
|
const ref = reference.identifier;
|
|
20067
20193
|
if (ref === identifier || ref === definition.name) continue;
|
|
20068
20194
|
const member = ref.parent;
|
|
20069
|
-
if (member.type !==
|
|
20195
|
+
if (member.type !== AST_NODE_TYPES93.MemberExpression || member.object !== ref || member.computed || member.property.type !== AST_NODE_TYPES93.Identifier || member.property.name === "signal" || member.parent.type !== AST_NODE_TYPES93.AssignmentExpression || member.parent.left !== member) {
|
|
20070
20196
|
return false;
|
|
20071
20197
|
}
|
|
20072
20198
|
}
|
|
@@ -20074,13 +20200,13 @@ var require_fetch_timeout_default = createRule({
|
|
|
20074
20200
|
}
|
|
20075
20201
|
function isForwardedRequest(argument) {
|
|
20076
20202
|
let value = argument;
|
|
20077
|
-
if (value.type ===
|
|
20078
|
-
const binding =
|
|
20203
|
+
if (value.type === AST_NODE_TYPES93.Identifier) {
|
|
20204
|
+
const binding = ASTUtils47.findVariable(context.sourceCode.getScope(value), value.name);
|
|
20079
20205
|
const definition = binding?.defs.length === 1 ? binding.defs[0] : void 0;
|
|
20080
20206
|
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init === null || binding?.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
20081
20207
|
value = definition.node.init;
|
|
20082
20208
|
}
|
|
20083
|
-
return value.type ===
|
|
20209
|
+
return value.type === AST_NODE_TYPES93.NewExpression && value.callee.type === AST_NODE_TYPES93.Identifier && value.callee.name === "Request" && resolvesToGlobal(value.callee);
|
|
20084
20210
|
}
|
|
20085
20211
|
return {
|
|
20086
20212
|
CallExpression(node) {
|
|
@@ -20091,7 +20217,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
20091
20217
|
if (first !== void 0 && (node.arguments.length === 1 && !isInlineUrl(first, resolvesToGlobal) || isForwardedRequest(first))) {
|
|
20092
20218
|
return;
|
|
20093
20219
|
}
|
|
20094
|
-
if (init === void 0 || initProvablyLacksSignal(init) || init.type ===
|
|
20220
|
+
if (init === void 0 || initProvablyLacksSignal(init) || init.type === AST_NODE_TYPES93.Identifier && localConstInitProvablyLacksSignal(init)) {
|
|
20095
20221
|
context.report({ node, messageId: "missingSignal" });
|
|
20096
20222
|
}
|
|
20097
20223
|
}
|
|
@@ -20100,7 +20226,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
20100
20226
|
});
|
|
20101
20227
|
|
|
20102
20228
|
// src/rules/require-interface-for-exported-class.ts
|
|
20103
|
-
import { AST_NODE_TYPES as
|
|
20229
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES94 } from "@typescript-eslint/utils";
|
|
20104
20230
|
var REQUIRE_INTERFACE_FOR_EXPORTED_CLASS_DOCUMENTATION = {
|
|
20105
20231
|
defaultLevel: "warning",
|
|
20106
20232
|
summary: "Require exported concrete classes with public behavior to declare a contract.",
|
|
@@ -20147,23 +20273,23 @@ var REQUIRE_INTERFACE_FOR_EXPORTED_CLASS_DOCUMENTATION = {
|
|
|
20147
20273
|
};
|
|
20148
20274
|
function hasPublicInstanceBehavior(node) {
|
|
20149
20275
|
return node.body.body.some((member) => {
|
|
20150
|
-
if (member.type ===
|
|
20151
|
-
return member.kind !== "constructor" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.key.type !==
|
|
20276
|
+
if (member.type === AST_NODE_TYPES94.MethodDefinition) {
|
|
20277
|
+
return member.kind !== "constructor" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.key.type !== AST_NODE_TYPES94.PrivateIdentifier;
|
|
20152
20278
|
}
|
|
20153
|
-
if (member.type !==
|
|
20279
|
+
if (member.type !== AST_NODE_TYPES94.PropertyDefinition || member.static)
|
|
20154
20280
|
return false;
|
|
20155
|
-
if (member.accessibility === "private" || member.accessibility === "protected" || member.key.type ===
|
|
20156
|
-
return member.value?.type ===
|
|
20281
|
+
if (member.accessibility === "private" || member.accessibility === "protected" || member.key.type === AST_NODE_TYPES94.PrivateIdentifier) return false;
|
|
20282
|
+
return member.value?.type === AST_NODE_TYPES94.ArrowFunctionExpression || member.value?.type === AST_NODE_TYPES94.FunctionExpression || member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES94.TSFunctionType;
|
|
20157
20283
|
});
|
|
20158
20284
|
}
|
|
20159
20285
|
function classBindings(statement) {
|
|
20160
|
-
const declaration = statement.type ===
|
|
20161
|
-
if (declaration?.type ===
|
|
20286
|
+
const declaration = statement.type === AST_NODE_TYPES94.ExportNamedDeclaration ? statement.declaration : statement;
|
|
20287
|
+
if (declaration?.type === AST_NODE_TYPES94.ClassDeclaration) {
|
|
20162
20288
|
return declaration.id === null ? [] : [{ declaration, name: declaration.id.name }];
|
|
20163
20289
|
}
|
|
20164
|
-
if (declaration?.type !==
|
|
20290
|
+
if (declaration?.type !== AST_NODE_TYPES94.VariableDeclaration) return [];
|
|
20165
20291
|
return declaration.declarations.flatMap(
|
|
20166
|
-
(item) => item.id.type ===
|
|
20292
|
+
(item) => item.id.type === AST_NODE_TYPES94.Identifier && item.init?.type === AST_NODE_TYPES94.ClassExpression ? [{ declaration: item.init, name: item.id.name }] : []
|
|
20167
20293
|
);
|
|
20168
20294
|
}
|
|
20169
20295
|
var require_interface_for_exported_class_default = createRule({
|
|
@@ -20197,7 +20323,7 @@ var require_interface_for_exported_class_default = createRule({
|
|
|
20197
20323
|
}
|
|
20198
20324
|
const exported = exportedClasses(program, classes);
|
|
20199
20325
|
for (const [declaration, exportedName] of exported) {
|
|
20200
|
-
const extendsLocalAbstractBase = declaration.superClass?.type ===
|
|
20326
|
+
const extendsLocalAbstractBase = declaration.superClass?.type === AST_NODE_TYPES94.Identifier && abstractBases.has(declaration.superClass.name);
|
|
20201
20327
|
if (declaration.abstract || declaration.implements.length > 0 || extendsLocalAbstractBase || !hasPublicInstanceBehavior(declaration)) continue;
|
|
20202
20328
|
context.report({
|
|
20203
20329
|
node: declaration.id ?? declaration,
|
|
@@ -20212,7 +20338,7 @@ var require_interface_for_exported_class_default = createRule({
|
|
|
20212
20338
|
function exportedClasses(program, classes) {
|
|
20213
20339
|
const exported = /* @__PURE__ */ new Map();
|
|
20214
20340
|
function collectExportedClass(statement) {
|
|
20215
|
-
if (statement.type ===
|
|
20341
|
+
if (statement.type === AST_NODE_TYPES94.ExportNamedDeclaration) {
|
|
20216
20342
|
for (const binding of classBindings(statement)) {
|
|
20217
20343
|
exported.set(binding.declaration, binding.name);
|
|
20218
20344
|
}
|
|
@@ -20220,13 +20346,13 @@ function exportedClasses(program, classes) {
|
|
|
20220
20346
|
collectClassSpecifiers(statement);
|
|
20221
20347
|
return;
|
|
20222
20348
|
}
|
|
20223
|
-
if (statement.type !==
|
|
20224
|
-
if (statement.declaration.type ===
|
|
20349
|
+
if (statement.type !== AST_NODE_TYPES94.ExportDefaultDeclaration) return;
|
|
20350
|
+
if (statement.declaration.type === AST_NODE_TYPES94.ClassDeclaration || statement.declaration.type === AST_NODE_TYPES94.ClassExpression) {
|
|
20225
20351
|
exported.set(
|
|
20226
20352
|
statement.declaration,
|
|
20227
20353
|
statement.declaration.id?.name ?? "default"
|
|
20228
20354
|
);
|
|
20229
|
-
} else if (statement.declaration.type ===
|
|
20355
|
+
} else if (statement.declaration.type === AST_NODE_TYPES94.Identifier) {
|
|
20230
20356
|
const candidate2 = classes.get(statement.declaration.name);
|
|
20231
20357
|
if (candidate2 !== void 0) {
|
|
20232
20358
|
exported.set(candidate2, statement.declaration.name);
|
|
@@ -20238,7 +20364,7 @@ function exportedClasses(program, classes) {
|
|
|
20238
20364
|
if (specifier.exportKind === "type") continue;
|
|
20239
20365
|
const candidate2 = classes.get(specifier.local.name);
|
|
20240
20366
|
if (candidate2 === void 0) continue;
|
|
20241
|
-
const exportedName = specifier.exported.type ===
|
|
20367
|
+
const exportedName = specifier.exported.type === AST_NODE_TYPES94.Identifier ? specifier.exported.name : specifier.exported.value;
|
|
20242
20368
|
exported.set(candidate2, exportedName);
|
|
20243
20369
|
}
|
|
20244
20370
|
}
|
|
@@ -20249,7 +20375,7 @@ function exportedClasses(program, classes) {
|
|
|
20249
20375
|
}
|
|
20250
20376
|
|
|
20251
20377
|
// src/rules/require-port-for-service.ts
|
|
20252
|
-
import { AST_NODE_TYPES as
|
|
20378
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES95 } from "@typescript-eslint/utils";
|
|
20253
20379
|
var REQUIRE_PORT_FOR_SERVICE_DOCUMENTATION = {
|
|
20254
20380
|
summary: "Advise when an exported service with injected collaborators has public methods not covered by its declared ports.",
|
|
20255
20381
|
rationale: "A declared port keeps consumers coupled to the service capability instead of its concrete implementation.",
|
|
@@ -20274,45 +20400,45 @@ var ROUTER_FACTORY_NAME = "Router";
|
|
|
20274
20400
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
20275
20401
|
var STORAGE_ASSIGNMENT_OPERATORS2 = /* @__PURE__ */ new Set(["=", "&&=", "??=", "||="]);
|
|
20276
20402
|
var staticMemberName7 = (member) => {
|
|
20277
|
-
if (member.property.type ===
|
|
20278
|
-
if (!member.computed && member.property.type ===
|
|
20279
|
-
return member.computed && member.property.type ===
|
|
20403
|
+
if (member.property.type === AST_NODE_TYPES95.PrivateIdentifier) return `#${member.property.name}`;
|
|
20404
|
+
if (!member.computed && member.property.type === AST_NODE_TYPES95.Identifier) return member.property.name;
|
|
20405
|
+
return member.computed && member.property.type === AST_NODE_TYPES95.Literal && typeof member.property.value === "string" ? member.property.value : null;
|
|
20280
20406
|
};
|
|
20281
20407
|
var detachedValueExports = (program) => {
|
|
20282
20408
|
const names = /* @__PURE__ */ new Set();
|
|
20283
20409
|
for (const statement of program.body) {
|
|
20284
|
-
if (statement.type ===
|
|
20410
|
+
if (statement.type === AST_NODE_TYPES95.ExportNamedDeclaration && statement.declaration === null && statement.source === null && statement.exportKind !== "type") {
|
|
20285
20411
|
for (const specifier of statement.specifiers) {
|
|
20286
20412
|
if (specifier.exportKind !== "type") names.add(specifier.local.name);
|
|
20287
20413
|
}
|
|
20288
|
-
} else if (statement.type ===
|
|
20414
|
+
} else if (statement.type === AST_NODE_TYPES95.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES95.Identifier) {
|
|
20289
20415
|
names.add(statement.declaration.name);
|
|
20290
|
-
} else if (statement.type ===
|
|
20416
|
+
} else if (statement.type === AST_NODE_TYPES95.TSExportAssignment && statement.expression.type === AST_NODE_TYPES95.Identifier) {
|
|
20291
20417
|
names.add(statement.expression.name);
|
|
20292
20418
|
}
|
|
20293
20419
|
}
|
|
20294
20420
|
return names;
|
|
20295
20421
|
};
|
|
20296
|
-
var isExportedClass2 = (node, detached) => node.parent.type ===
|
|
20422
|
+
var isExportedClass2 = (node, detached) => node.parent.type === AST_NODE_TYPES95.ExportNamedDeclaration || node.parent.type === AST_NODE_TYPES95.ExportDefaultDeclaration || node.id !== null && detached.has(node.id.name);
|
|
20297
20423
|
var readTypeReference = (annotation) => {
|
|
20298
|
-
if (annotation?.type ===
|
|
20424
|
+
if (annotation?.type === AST_NODE_TYPES95.TSUnionType) {
|
|
20299
20425
|
const members = annotation.types.filter(
|
|
20300
|
-
(member) => member.type !==
|
|
20426
|
+
(member) => member.type !== AST_NODE_TYPES95.TSUndefinedKeyword && member.type !== AST_NODE_TYPES95.TSNullKeyword
|
|
20301
20427
|
);
|
|
20302
20428
|
annotation = members.length === 1 ? members[0] : void 0;
|
|
20303
20429
|
}
|
|
20304
|
-
if (annotation === void 0 || annotation.type !==
|
|
20430
|
+
if (annotation === void 0 || annotation.type !== AST_NODE_TYPES95.TSTypeReference) return null;
|
|
20305
20431
|
const { typeName } = annotation;
|
|
20306
|
-
const rightmost = typeName.type ===
|
|
20432
|
+
const rightmost = typeName.type === AST_NODE_TYPES95.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES95.TSQualifiedName ? typeName.right.name : null;
|
|
20307
20433
|
if (rightmost === null) return null;
|
|
20308
20434
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
20309
20435
|
};
|
|
20310
|
-
var qualifiedName = (name) => name.type ===
|
|
20436
|
+
var qualifiedName = (name) => name.type === AST_NODE_TYPES95.Identifier ? name.name : name.type === AST_NODE_TYPES95.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
20311
20437
|
var propertySignatureTypes = (members) => {
|
|
20312
20438
|
const types = /* @__PURE__ */ new Map();
|
|
20313
20439
|
for (const member of members) {
|
|
20314
|
-
if (member.type !==
|
|
20315
|
-
if (member.computed || member.key.type !==
|
|
20440
|
+
if (member.type !== AST_NODE_TYPES95.TSPropertySignature) continue;
|
|
20441
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES95.Identifier) continue;
|
|
20316
20442
|
const reference = readTypeReference(member.typeAnnotation?.typeAnnotation);
|
|
20317
20443
|
if (reference === null) continue;
|
|
20318
20444
|
types.set(member.key.name, reference);
|
|
@@ -20323,18 +20449,18 @@ var fileTypeIndex = (program) => {
|
|
|
20323
20449
|
const objects = /* @__PURE__ */ new Map();
|
|
20324
20450
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
20325
20451
|
function collectDeclaredType(statement) {
|
|
20326
|
-
const declaration = statement.type ===
|
|
20327
|
-
if (declaration?.type ===
|
|
20452
|
+
const declaration = statement.type === AST_NODE_TYPES95.ExportNamedDeclaration ? statement.declaration : statement;
|
|
20453
|
+
if (declaration?.type === AST_NODE_TYPES95.TSInterfaceDeclaration) {
|
|
20328
20454
|
objects.set(declaration.id.name, propertySignatureTypes(declaration.body.body));
|
|
20329
20455
|
return;
|
|
20330
20456
|
}
|
|
20331
|
-
if (declaration?.type !==
|
|
20457
|
+
if (declaration?.type !== AST_NODE_TYPES95.TSTypeAliasDeclaration) return;
|
|
20332
20458
|
const aliased = declaration.typeAnnotation;
|
|
20333
|
-
if (aliased.type ===
|
|
20459
|
+
if (aliased.type === AST_NODE_TYPES95.TSFunctionType || aliased.type === AST_NODE_TYPES95.TSConstructorType) {
|
|
20334
20460
|
functionAliases.add(declaration.id.name);
|
|
20335
20461
|
return;
|
|
20336
20462
|
}
|
|
20337
|
-
const literals = aliased.type ===
|
|
20463
|
+
const literals = aliased.type === AST_NODE_TYPES95.TSTypeLiteral ? [aliased] : aliased.type === AST_NODE_TYPES95.TSIntersectionType ? aliased.types.filter((part) => part.type === AST_NODE_TYPES95.TSTypeLiteral) : [];
|
|
20338
20464
|
if (literals.length === 0) return;
|
|
20339
20465
|
const merged = /* @__PURE__ */ new Map();
|
|
20340
20466
|
for (const literal of literals) {
|
|
@@ -20365,22 +20491,22 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
20365
20491
|
function scanStoredFields(body3) {
|
|
20366
20492
|
const pending = [...body3.body];
|
|
20367
20493
|
function recordStoredField(current) {
|
|
20368
|
-
if (current.type ===
|
|
20369
|
-
const expression = current.type ===
|
|
20370
|
-
const storedField = expression?.type ===
|
|
20371
|
-
if (expression?.type !==
|
|
20494
|
+
if (current.type === AST_NODE_TYPES95.ArrowFunctionExpression || current.type === AST_NODE_TYPES95.FunctionExpression || current.type === AST_NODE_TYPES95.FunctionDeclaration || current.type === AST_NODE_TYPES95.ClassExpression || current.type === AST_NODE_TYPES95.ClassDeclaration) return;
|
|
20495
|
+
const expression = current.type === AST_NODE_TYPES95.ExpressionStatement ? current.expression : null;
|
|
20496
|
+
const storedField = expression?.type === AST_NODE_TYPES95.AssignmentExpression && expression.left.type === AST_NODE_TYPES95.MemberExpression && expression.left.object.type === AST_NODE_TYPES95.ThisExpression ? staticMemberName7(expression.left) : null;
|
|
20497
|
+
if (expression?.type !== AST_NODE_TYPES95.AssignmentExpression || !STORAGE_ASSIGNMENT_OPERATORS2.has(expression.operator) || expression.left.type !== AST_NODE_TYPES95.MemberExpression || expression.left.object.type !== AST_NODE_TYPES95.ThisExpression || storedField === null) {
|
|
20372
20498
|
enqueueChildren(current);
|
|
20373
20499
|
return;
|
|
20374
20500
|
}
|
|
20375
20501
|
let source = expression.right;
|
|
20376
|
-
while (source.type ===
|
|
20377
|
-
if (source.type ===
|
|
20502
|
+
while (source.type === AST_NODE_TYPES95.TSNonNullExpression || source.type === AST_NODE_TYPES95.TSAsExpression || source.type === AST_NODE_TYPES95.TSSatisfiesExpression || source.type === AST_NODE_TYPES95.TSTypeAssertion) source = source.expression;
|
|
20503
|
+
if (source.type === AST_NODE_TYPES95.NewExpression) {
|
|
20378
20504
|
constructedFields += 1;
|
|
20379
|
-
} else if (source.type ===
|
|
20505
|
+
} else if (source.type === AST_NODE_TYPES95.Identifier) {
|
|
20380
20506
|
const fields = storedFieldsFrom.get(source.name) ?? /* @__PURE__ */ new Set();
|
|
20381
20507
|
fields.add(storedField);
|
|
20382
20508
|
storedFieldsFrom.set(source.name, fields);
|
|
20383
|
-
} else if (source.type ===
|
|
20509
|
+
} else if (source.type === AST_NODE_TYPES95.MemberExpression && source.object.type === AST_NODE_TYPES95.Identifier) {
|
|
20384
20510
|
const fields = storedFieldsFrom.get(source.object.name) ?? /* @__PURE__ */ new Set();
|
|
20385
20511
|
fields.add(storedField);
|
|
20386
20512
|
storedFieldsFrom.set(source.object.name, fields);
|
|
@@ -20408,7 +20534,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
20408
20534
|
const collaborators = [];
|
|
20409
20535
|
function collectCollaborators(parameter) {
|
|
20410
20536
|
for (const reference of parameterCollaborators(parameter, declared, storedMemberFieldsFrom)) {
|
|
20411
|
-
const fields = parameter.type ===
|
|
20537
|
+
const fields = parameter.type === AST_NODE_TYPES95.TSParameterProperty ? [reference.name] : reference.fields.length > 0 ? reference.fields : [...storedFieldsFrom.get(reference.name) ?? []];
|
|
20412
20538
|
if (fields.length === 0) continue;
|
|
20413
20539
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
20414
20540
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -20426,8 +20552,8 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
20426
20552
|
};
|
|
20427
20553
|
var parameterCollaborators = (parameter, declared, storedMemberFieldsFrom) => {
|
|
20428
20554
|
let target = parameter;
|
|
20429
|
-
if (target.type ===
|
|
20430
|
-
if (target.type ===
|
|
20555
|
+
if (target.type === AST_NODE_TYPES95.AssignmentPattern) target = target.left;
|
|
20556
|
+
if (target.type === AST_NODE_TYPES95.ObjectPattern) {
|
|
20431
20557
|
return objectPatternCollaborators(target, declared);
|
|
20432
20558
|
}
|
|
20433
20559
|
const named2 = namedParameterCollaborator(parameter);
|
|
@@ -20436,9 +20562,9 @@ var parameterCollaborators = (parameter, declared, storedMemberFieldsFrom) => {
|
|
|
20436
20562
|
};
|
|
20437
20563
|
var namedBagCollaborators = (annotated, declared, storedMemberFieldsFrom) => {
|
|
20438
20564
|
let target = annotated;
|
|
20439
|
-
if (target.type ===
|
|
20440
|
-
if (target.type ===
|
|
20441
|
-
if (target.type !==
|
|
20565
|
+
if (target.type === AST_NODE_TYPES95.TSParameterProperty) target = target.parameter;
|
|
20566
|
+
if (target.type === AST_NODE_TYPES95.AssignmentPattern) target = target.left;
|
|
20567
|
+
if (target.type !== AST_NODE_TYPES95.Identifier) return [];
|
|
20442
20568
|
const members = bagMemberTypes(target.typeAnnotation?.typeAnnotation, declared);
|
|
20443
20569
|
if (members === null) return [];
|
|
20444
20570
|
const storedMembers = storedMemberFieldsFrom.get(target.name);
|
|
@@ -20454,9 +20580,9 @@ var namedBagCollaborators = (annotated, declared, storedMemberFieldsFrom) => {
|
|
|
20454
20580
|
};
|
|
20455
20581
|
var namedParameterCollaborator = (annotated) => {
|
|
20456
20582
|
let target = annotated;
|
|
20457
|
-
if (target.type ===
|
|
20458
|
-
if (target.type ===
|
|
20459
|
-
if (target.type !==
|
|
20583
|
+
if (target.type === AST_NODE_TYPES95.TSParameterProperty) target = target.parameter;
|
|
20584
|
+
if (target.type === AST_NODE_TYPES95.AssignmentPattern) target = target.left;
|
|
20585
|
+
if (target.type !== AST_NODE_TYPES95.Identifier) return null;
|
|
20460
20586
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
20461
20587
|
if (reference === null) return null;
|
|
20462
20588
|
return { name: target.name, ...reference, fields: [] };
|
|
@@ -20468,11 +20594,11 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
20468
20594
|
if (members === null) return [];
|
|
20469
20595
|
const collaborators = [];
|
|
20470
20596
|
for (const property of pattern.properties) {
|
|
20471
|
-
if (property.type !==
|
|
20472
|
-
if (property.key.type !==
|
|
20597
|
+
if (property.type !== AST_NODE_TYPES95.Property || property.computed) continue;
|
|
20598
|
+
if (property.key.type !== AST_NODE_TYPES95.Identifier) continue;
|
|
20473
20599
|
const key = property.key.name;
|
|
20474
|
-
const bound = property.value.type ===
|
|
20475
|
-
if (bound.type !==
|
|
20600
|
+
const bound = property.value.type === AST_NODE_TYPES95.AssignmentPattern ? property.value.left : property.value;
|
|
20601
|
+
if (bound.type !== AST_NODE_TYPES95.Identifier) continue;
|
|
20476
20602
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
20477
20603
|
const reference = members.get(key);
|
|
20478
20604
|
if (reference === void 0) continue;
|
|
@@ -20482,21 +20608,21 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
20482
20608
|
};
|
|
20483
20609
|
var bagMemberTypes = (annotation, declared) => {
|
|
20484
20610
|
if (annotation === void 0) return null;
|
|
20485
|
-
if (annotation.type ===
|
|
20611
|
+
if (annotation.type === AST_NODE_TYPES95.TSTypeLiteral) {
|
|
20486
20612
|
return propertySignatureTypes(annotation.members);
|
|
20487
20613
|
}
|
|
20488
|
-
if (annotation.type !==
|
|
20614
|
+
if (annotation.type !== AST_NODE_TYPES95.TSTypeReference || annotation.typeName.type !== AST_NODE_TYPES95.Identifier) {
|
|
20489
20615
|
return null;
|
|
20490
20616
|
}
|
|
20491
20617
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
20492
20618
|
};
|
|
20493
20619
|
var isFrameworkWiring = (body2) => subtreeHas(body2, (node) => {
|
|
20494
|
-
if (node.type ===
|
|
20620
|
+
if (node.type === AST_NODE_TYPES95.CallExpression) {
|
|
20495
20621
|
const { callee } = node;
|
|
20496
|
-
if (callee.type ===
|
|
20497
|
-
return callee.type ===
|
|
20622
|
+
if (callee.type === AST_NODE_TYPES95.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
20623
|
+
return callee.type === AST_NODE_TYPES95.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES95.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
20498
20624
|
}
|
|
20499
|
-
return node.type ===
|
|
20625
|
+
return node.type === AST_NODE_TYPES95.TSTypeReference && node.typeName.type === AST_NODE_TYPES95.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
20500
20626
|
});
|
|
20501
20627
|
var subtreeHas = (root, found) => {
|
|
20502
20628
|
let hit = false;
|
|
@@ -20518,33 +20644,33 @@ var invokedInstanceField = (call) => {
|
|
|
20518
20644
|
const direct = instanceField(call.callee);
|
|
20519
20645
|
if (direct !== null) return direct;
|
|
20520
20646
|
let callee = call.callee;
|
|
20521
|
-
while (callee.type ===
|
|
20522
|
-
return callee.type ===
|
|
20647
|
+
while (callee.type === AST_NODE_TYPES95.ChainExpression || callee.type === AST_NODE_TYPES95.TSAsExpression || callee.type === AST_NODE_TYPES95.TSNonNullExpression || callee.type === AST_NODE_TYPES95.TSSatisfiesExpression || callee.type === AST_NODE_TYPES95.TSTypeAssertion) callee = callee.expression;
|
|
20648
|
+
return callee.type === AST_NODE_TYPES95.MemberExpression ? instanceField(callee.object) : null;
|
|
20523
20649
|
};
|
|
20524
20650
|
var instanceField = (candidate2) => {
|
|
20525
20651
|
let node = candidate2;
|
|
20526
|
-
while (node.type ===
|
|
20527
|
-
return node.type ===
|
|
20652
|
+
while (node.type === AST_NODE_TYPES95.ChainExpression || node.type === AST_NODE_TYPES95.TSAsExpression || node.type === AST_NODE_TYPES95.TSNonNullExpression || node.type === AST_NODE_TYPES95.TSSatisfiesExpression || node.type === AST_NODE_TYPES95.TSTypeAssertion) node = node.expression;
|
|
20653
|
+
return node.type === AST_NODE_TYPES95.MemberExpression && node.object.type === AST_NODE_TYPES95.ThisExpression ? staticMemberName7(node) : null;
|
|
20528
20654
|
};
|
|
20529
20655
|
var behaviorallyInvokedFields = (body2) => {
|
|
20530
20656
|
const invoked = /* @__PURE__ */ new Set();
|
|
20531
20657
|
const visit = (current) => {
|
|
20532
|
-
if (current.type ===
|
|
20533
|
-
if (current.type ===
|
|
20658
|
+
if (current.type === AST_NODE_TYPES95.ClassDeclaration || current.type === AST_NODE_TYPES95.ClassExpression || current.type === AST_NODE_TYPES95.FunctionDeclaration || current.type === AST_NODE_TYPES95.FunctionExpression) return;
|
|
20659
|
+
if (current.type === AST_NODE_TYPES95.CallExpression) {
|
|
20534
20660
|
const field = invokedInstanceField(current);
|
|
20535
20661
|
if (field !== null) invoked.add(field);
|
|
20536
20662
|
}
|
|
20537
20663
|
forEachOwnAstChild(current, visit);
|
|
20538
20664
|
};
|
|
20539
20665
|
for (const member of body2.body) {
|
|
20540
|
-
if (member.type ===
|
|
20541
|
-
if (member.type ===
|
|
20666
|
+
if (member.type === AST_NODE_TYPES95.StaticBlock || member.static) continue;
|
|
20667
|
+
if (member.type === AST_NODE_TYPES95.MethodDefinition) {
|
|
20542
20668
|
if (member.value.body !== null && member.value.body !== void 0) visit(member.value.body);
|
|
20543
20669
|
continue;
|
|
20544
20670
|
}
|
|
20545
|
-
if (member.type !==
|
|
20671
|
+
if (member.type !== AST_NODE_TYPES95.PropertyDefinition || member.value === null) continue;
|
|
20546
20672
|
visit(
|
|
20547
|
-
member.value.type ===
|
|
20673
|
+
member.value.type === AST_NODE_TYPES95.ArrowFunctionExpression ? member.value.body : member.value
|
|
20548
20674
|
);
|
|
20549
20675
|
}
|
|
20550
20676
|
return invoked;
|
|
@@ -20564,25 +20690,25 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
20564
20690
|
var fileInterfaceNames = (program) => {
|
|
20565
20691
|
const names = [];
|
|
20566
20692
|
for (const statement of program.body) {
|
|
20567
|
-
const declaration = statement.type ===
|
|
20568
|
-
if (declaration?.type ===
|
|
20693
|
+
const declaration = statement.type === AST_NODE_TYPES95.ExportNamedDeclaration ? statement.declaration : statement;
|
|
20694
|
+
if (declaration?.type === AST_NODE_TYPES95.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
20569
20695
|
}
|
|
20570
20696
|
return names;
|
|
20571
20697
|
};
|
|
20572
20698
|
var publicMethodNames = (body2, functionAliases) => {
|
|
20573
20699
|
const names = [];
|
|
20574
20700
|
function collectPublicCallable(member) {
|
|
20575
|
-
if (member.type ===
|
|
20701
|
+
if (member.type === AST_NODE_TYPES95.PropertyDefinition) {
|
|
20576
20702
|
if (member.static || member.accessibility === "private" || member.accessibility === "protected") return;
|
|
20577
|
-
if (member.key.type ===
|
|
20578
|
-
if (member.value?.type !==
|
|
20703
|
+
if (member.key.type === AST_NODE_TYPES95.PrivateIdentifier) return;
|
|
20704
|
+
if (member.value?.type !== AST_NODE_TYPES95.ArrowFunctionExpression && member.value?.type !== AST_NODE_TYPES95.FunctionExpression && member.typeAnnotation?.typeAnnotation.type !== AST_NODE_TYPES95.TSFunctionType && !(member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES95.TSTypeReference && member.typeAnnotation.typeAnnotation.typeName.type === AST_NODE_TYPES95.Identifier && functionAliases.has(member.typeAnnotation.typeAnnotation.typeName.name))) return;
|
|
20579
20705
|
names.push(declaredMemberName(member) ?? "\u2026");
|
|
20580
20706
|
return;
|
|
20581
20707
|
}
|
|
20582
|
-
if (member.type !==
|
|
20708
|
+
if (member.type !== AST_NODE_TYPES95.MethodDefinition) return;
|
|
20583
20709
|
if (member.kind !== "method" || member.static) return;
|
|
20584
20710
|
if (member.accessibility === "private" || member.accessibility === "protected") return;
|
|
20585
|
-
if (member.key.type ===
|
|
20711
|
+
if (member.key.type === AST_NODE_TYPES95.PrivateIdentifier) return;
|
|
20586
20712
|
names.push(declaredMemberName(member) ?? "\u2026");
|
|
20587
20713
|
}
|
|
20588
20714
|
for (const member of body2.body) {
|
|
@@ -20593,13 +20719,13 @@ var publicMethodNames = (body2, functionAliases) => {
|
|
|
20593
20719
|
var isFluentConstructionObject = (node, getText) => {
|
|
20594
20720
|
if (node.id === null) return false;
|
|
20595
20721
|
const methods = node.body.body.filter(
|
|
20596
|
-
(member) => member.type ===
|
|
20722
|
+
(member) => member.type === AST_NODE_TYPES95.MethodDefinition && member.kind === "method" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.value.body !== null
|
|
20597
20723
|
);
|
|
20598
20724
|
if (methods.length === 0) return false;
|
|
20599
20725
|
return methods.every((member) => {
|
|
20600
20726
|
const result = member.value.returnType?.typeAnnotation;
|
|
20601
20727
|
if (result === void 0) return false;
|
|
20602
|
-
const returnsOwnType = result.type ===
|
|
20728
|
+
const returnsOwnType = result.type === AST_NODE_TYPES95.TSTypeReference && result.typeName.type === AST_NODE_TYPES95.Identifier && result.typeName.name === node.id?.name;
|
|
20603
20729
|
return returnsOwnType || FLUENT_BUILDER_NAME_RE.test(node.id?.name ?? "") && FLUENT_RESULT_TYPE_RE.test(getText(result));
|
|
20604
20730
|
});
|
|
20605
20731
|
};
|
|
@@ -20607,10 +20733,10 @@ function localClassAbstractness(program) {
|
|
|
20607
20733
|
const classes = /* @__PURE__ */ new Map();
|
|
20608
20734
|
const parents = /* @__PURE__ */ new Map();
|
|
20609
20735
|
for (const statement of program.body) {
|
|
20610
|
-
const declaration = statement.type ===
|
|
20611
|
-
if (declaration?.type ===
|
|
20736
|
+
const declaration = statement.type === AST_NODE_TYPES95.ExportNamedDeclaration || statement.type === AST_NODE_TYPES95.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
20737
|
+
if (declaration?.type === AST_NODE_TYPES95.ClassDeclaration && declaration.id !== null) {
|
|
20612
20738
|
classes.set(declaration.id.name, declaration.abstract === true);
|
|
20613
|
-
if (declaration.superClass?.type ===
|
|
20739
|
+
if (declaration.superClass?.type === AST_NODE_TYPES95.Identifier) {
|
|
20614
20740
|
parents.set(declaration.id.name, declaration.superClass.name);
|
|
20615
20741
|
}
|
|
20616
20742
|
}
|
|
@@ -20628,8 +20754,8 @@ function localClassAbstractness(program) {
|
|
|
20628
20754
|
return classes;
|
|
20629
20755
|
}
|
|
20630
20756
|
function declaredMemberName(member) {
|
|
20631
|
-
if (!member.computed && member.key.type ===
|
|
20632
|
-
if (member.key.type ===
|
|
20757
|
+
if (!member.computed && member.key.type === AST_NODE_TYPES95.Identifier) return member.key.name;
|
|
20758
|
+
if (member.key.type === AST_NODE_TYPES95.Literal && typeof member.key.value === "string") return member.key.value;
|
|
20633
20759
|
return null;
|
|
20634
20760
|
}
|
|
20635
20761
|
function localInterfaceSurfaces(program) {
|
|
@@ -20637,28 +20763,28 @@ function localInterfaceSurfaces(program) {
|
|
|
20637
20763
|
const parents = /* @__PURE__ */ new Map();
|
|
20638
20764
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
20639
20765
|
for (const statement of program.body) {
|
|
20640
|
-
const declaration = statement.type ===
|
|
20641
|
-
if (declaration?.type ===
|
|
20766
|
+
const declaration = statement.type === AST_NODE_TYPES95.ExportNamedDeclaration ? statement.declaration : statement;
|
|
20767
|
+
if (declaration?.type === AST_NODE_TYPES95.TSTypeAliasDeclaration && (declaration.typeAnnotation.type === AST_NODE_TYPES95.TSFunctionType || declaration.typeAnnotation.type === AST_NODE_TYPES95.TSConstructorType)) functionAliases.add(declaration.id.name);
|
|
20642
20768
|
}
|
|
20643
20769
|
function collectInterfaceSurface(statement) {
|
|
20644
|
-
const declaration = statement.type ===
|
|
20645
|
-
if (declaration?.type ===
|
|
20770
|
+
const declaration = statement.type === AST_NODE_TYPES95.ExportNamedDeclaration ? statement.declaration : statement;
|
|
20771
|
+
if (declaration?.type === AST_NODE_TYPES95.TSTypeAliasDeclaration) {
|
|
20646
20772
|
const callables2 = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
20647
|
-
const parts = declaration.typeAnnotation.type ===
|
|
20773
|
+
const parts = declaration.typeAnnotation.type === AST_NODE_TYPES95.TSIntersectionType ? declaration.typeAnnotation.types : [declaration.typeAnnotation];
|
|
20648
20774
|
const inherited = parents.get(declaration.id.name) ?? [];
|
|
20649
20775
|
for (const part of parts) {
|
|
20650
|
-
if (part.type ===
|
|
20776
|
+
if (part.type === AST_NODE_TYPES95.TSTypeReference && part.typeName.type === AST_NODE_TYPES95.Identifier) {
|
|
20651
20777
|
inherited.push(part.typeName.name);
|
|
20652
20778
|
continue;
|
|
20653
20779
|
}
|
|
20654
|
-
if (part.type !==
|
|
20780
|
+
if (part.type !== AST_NODE_TYPES95.TSTypeLiteral) continue;
|
|
20655
20781
|
addCallableMembers(part.members, callables2);
|
|
20656
20782
|
}
|
|
20657
20783
|
interfaces.set(declaration.id.name, callables2);
|
|
20658
20784
|
parents.set(declaration.id.name, inherited);
|
|
20659
20785
|
return;
|
|
20660
20786
|
}
|
|
20661
|
-
if (declaration?.type !==
|
|
20787
|
+
if (declaration?.type !== AST_NODE_TYPES95.TSInterfaceDeclaration) return;
|
|
20662
20788
|
const callables = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
20663
20789
|
addCallableMembers(declaration.body.body, callables);
|
|
20664
20790
|
interfaces.set(declaration.id.name, callables);
|
|
@@ -20667,7 +20793,7 @@ function localInterfaceSurfaces(program) {
|
|
|
20667
20793
|
[
|
|
20668
20794
|
...parents.get(declaration.id.name) ?? [],
|
|
20669
20795
|
...declaration.extends.flatMap(
|
|
20670
|
-
(heritage) => heritage.expression.type ===
|
|
20796
|
+
(heritage) => heritage.expression.type === AST_NODE_TYPES95.Identifier ? [heritage.expression.name] : ["*"]
|
|
20671
20797
|
)
|
|
20672
20798
|
]
|
|
20673
20799
|
);
|
|
@@ -20677,16 +20803,16 @@ function localInterfaceSurfaces(program) {
|
|
|
20677
20803
|
}
|
|
20678
20804
|
function addCallableMembers(members, callables) {
|
|
20679
20805
|
for (const member of members) {
|
|
20680
|
-
if (member.type !==
|
|
20806
|
+
if (member.type !== AST_NODE_TYPES95.TSMethodSignature && member.type !== AST_NODE_TYPES95.TSPropertySignature) continue;
|
|
20681
20807
|
const name = declaredMemberName(member);
|
|
20682
20808
|
if (name === null) continue;
|
|
20683
|
-
if (member.type ===
|
|
20809
|
+
if (member.type === AST_NODE_TYPES95.TSMethodSignature) {
|
|
20684
20810
|
callables.add(name);
|
|
20685
20811
|
continue;
|
|
20686
20812
|
}
|
|
20687
|
-
if (member.type !==
|
|
20813
|
+
if (member.type !== AST_NODE_TYPES95.TSPropertySignature) continue;
|
|
20688
20814
|
const annotation = member.typeAnnotation?.typeAnnotation;
|
|
20689
|
-
if (annotation?.type ===
|
|
20815
|
+
if (annotation?.type === AST_NODE_TYPES95.TSFunctionType || annotation?.type === AST_NODE_TYPES95.TSTypeReference && annotation.typeName.type === AST_NODE_TYPES95.Identifier && functionAliases.has(annotation.typeName.name)) callables.add(name);
|
|
20690
20816
|
}
|
|
20691
20817
|
}
|
|
20692
20818
|
function expandInheritedSurfaces() {
|
|
@@ -20715,7 +20841,7 @@ function localInterfaceSurfaces(program) {
|
|
|
20715
20841
|
}
|
|
20716
20842
|
function hasServicePort(node, methods, classes, interfaces) {
|
|
20717
20843
|
if (node.superClass !== null) {
|
|
20718
|
-
if (node.superClass.type !==
|
|
20844
|
+
if (node.superClass.type !== AST_NODE_TYPES95.Identifier) return true;
|
|
20719
20845
|
const localAbstract = classes.get(node.superClass.name);
|
|
20720
20846
|
if (localAbstract === void 0 || localAbstract) return true;
|
|
20721
20847
|
}
|
|
@@ -20756,7 +20882,7 @@ var require_port_for_service_default = createRule({
|
|
|
20756
20882
|
if (node.abstract === true) return;
|
|
20757
20883
|
if (node.decorators.length > 0) return;
|
|
20758
20884
|
const ctor = node.body.body.find(
|
|
20759
|
-
(member) => member.type ===
|
|
20885
|
+
(member) => member.type === AST_NODE_TYPES95.MethodDefinition && member.kind === "constructor" && member.value.body !== null && member.value.body !== void 0
|
|
20760
20886
|
);
|
|
20761
20887
|
if (ctor === void 0) return;
|
|
20762
20888
|
const constructorFacts = readConstructor(
|
|
@@ -20798,7 +20924,7 @@ function hasStructuralPort(name, methods, interfaces) {
|
|
|
20798
20924
|
function implementedSurfaceCovers(node, methods, classes, interfaces) {
|
|
20799
20925
|
const combined = /* @__PURE__ */ new Set();
|
|
20800
20926
|
for (const implementation of node.implements) {
|
|
20801
|
-
if (implementation.expression.type !==
|
|
20927
|
+
if (implementation.expression.type !== AST_NODE_TYPES95.Identifier) return true;
|
|
20802
20928
|
const name = implementation.expression.name;
|
|
20803
20929
|
const localAbstract = classes.get(name);
|
|
20804
20930
|
if (localAbstract === true) return true;
|
|
@@ -20812,7 +20938,7 @@ function implementedSurfaceCovers(node, methods, classes, interfaces) {
|
|
|
20812
20938
|
}
|
|
20813
20939
|
|
|
20814
20940
|
// src/rules/require-sql-access-class.ts
|
|
20815
|
-
import { AST_NODE_TYPES as
|
|
20941
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES96, ASTUtils as ASTUtils48 } from "@typescript-eslint/utils";
|
|
20816
20942
|
var DIRECT_EXECUTION_METHODS = /* @__PURE__ */ new Set([
|
|
20817
20943
|
"all",
|
|
20818
20944
|
"batch",
|
|
@@ -20908,9 +21034,9 @@ var REQUIRE_SQL_ACCESS_CLASS_DOCUMENTATION = {
|
|
|
20908
21034
|
]
|
|
20909
21035
|
};
|
|
20910
21036
|
function memberName7(node) {
|
|
20911
|
-
if (!node.computed && node.property.type ===
|
|
21037
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES96.Identifier)
|
|
20912
21038
|
return node.property.name;
|
|
20913
|
-
if (node.computed && node.property.type ===
|
|
21039
|
+
if (node.computed && node.property.type === AST_NODE_TYPES96.Literal && typeof node.property.value === "string")
|
|
20914
21040
|
return node.property.value;
|
|
20915
21041
|
return null;
|
|
20916
21042
|
}
|
|
@@ -20922,89 +21048,89 @@ function isDatabaseOperation(method, receiver) {
|
|
|
20922
21048
|
return BUILDER_SHORT_TERMINALS.has(method) && expressionCallsBuilder(receiver);
|
|
20923
21049
|
}
|
|
20924
21050
|
function databaseReceiver(node) {
|
|
20925
|
-
if (node.type ===
|
|
21051
|
+
if (node.type === AST_NODE_TYPES96.Identifier)
|
|
20926
21052
|
return DATABASE_NAMES.test(node.name);
|
|
20927
|
-
if (node.type !==
|
|
21053
|
+
if (node.type !== AST_NODE_TYPES96.MemberExpression) return false;
|
|
20928
21054
|
const name = memberName7(node);
|
|
20929
21055
|
return name === "DB" || name !== null && DATABASE_NAMES.test(name);
|
|
20930
21056
|
}
|
|
20931
21057
|
function databaseRootMember(node) {
|
|
20932
21058
|
let current = node;
|
|
20933
21059
|
for (; ; ) {
|
|
20934
|
-
if (current.type ===
|
|
21060
|
+
if (current.type === AST_NODE_TYPES96.ChainExpression) {
|
|
20935
21061
|
current = current.expression;
|
|
20936
21062
|
continue;
|
|
20937
21063
|
}
|
|
20938
|
-
if (current.type ===
|
|
21064
|
+
if (current.type === AST_NODE_TYPES96.TSAsExpression || current.type === AST_NODE_TYPES96.TSNonNullExpression || current.type === AST_NODE_TYPES96.TSTypeAssertion) {
|
|
20939
21065
|
current = current.expression;
|
|
20940
21066
|
continue;
|
|
20941
21067
|
}
|
|
20942
|
-
if (current.type ===
|
|
20943
|
-
if (current.callee.type !==
|
|
21068
|
+
if (current.type === AST_NODE_TYPES96.CallExpression) {
|
|
21069
|
+
if (current.callee.type !== AST_NODE_TYPES96.MemberExpression) return null;
|
|
20944
21070
|
current = current.callee.object;
|
|
20945
21071
|
continue;
|
|
20946
21072
|
}
|
|
20947
|
-
if (current.type ===
|
|
20948
|
-
if (current.object.type ===
|
|
21073
|
+
if (current.type === AST_NODE_TYPES96.MemberExpression) {
|
|
21074
|
+
if (current.object.type === AST_NODE_TYPES96.ThisExpression)
|
|
20949
21075
|
return memberName7(current);
|
|
20950
21076
|
current = current.object;
|
|
20951
21077
|
continue;
|
|
20952
21078
|
}
|
|
20953
|
-
return current.type ===
|
|
21079
|
+
return current.type === AST_NODE_TYPES96.Identifier ? current.name : null;
|
|
20954
21080
|
}
|
|
20955
21081
|
}
|
|
20956
21082
|
function expressionHasDatabaseMarker(node) {
|
|
20957
21083
|
let current = node;
|
|
20958
21084
|
for (; ; ) {
|
|
20959
|
-
if (current.type ===
|
|
21085
|
+
if (current.type === AST_NODE_TYPES96.ChainExpression) {
|
|
20960
21086
|
current = current.expression;
|
|
20961
21087
|
continue;
|
|
20962
21088
|
}
|
|
20963
|
-
if (current.type ===
|
|
21089
|
+
if (current.type === AST_NODE_TYPES96.TSAsExpression || current.type === AST_NODE_TYPES96.TSNonNullExpression || current.type === AST_NODE_TYPES96.TSTypeAssertion) {
|
|
20964
21090
|
current = current.expression;
|
|
20965
21091
|
continue;
|
|
20966
21092
|
}
|
|
20967
|
-
if (current.type ===
|
|
20968
|
-
if (current.callee.type !==
|
|
21093
|
+
if (current.type === AST_NODE_TYPES96.CallExpression) {
|
|
21094
|
+
if (current.callee.type !== AST_NODE_TYPES96.MemberExpression) return false;
|
|
20969
21095
|
current = current.callee.object;
|
|
20970
21096
|
continue;
|
|
20971
21097
|
}
|
|
20972
|
-
if (current.type ===
|
|
21098
|
+
if (current.type === AST_NODE_TYPES96.MemberExpression) {
|
|
20973
21099
|
const name = memberName7(current);
|
|
20974
21100
|
if (name === "DB" || name !== null && DATABASE_NAMES.test(name))
|
|
20975
21101
|
return true;
|
|
20976
21102
|
current = current.object;
|
|
20977
21103
|
continue;
|
|
20978
21104
|
}
|
|
20979
|
-
return current.type ===
|
|
21105
|
+
return current.type === AST_NODE_TYPES96.Identifier && DATABASE_NAMES.test(current.name);
|
|
20980
21106
|
}
|
|
20981
21107
|
}
|
|
20982
21108
|
function expressionCallsBuilder(node) {
|
|
20983
21109
|
let current = node;
|
|
20984
21110
|
for (; ; ) {
|
|
20985
|
-
if (current.type ===
|
|
21111
|
+
if (current.type === AST_NODE_TYPES96.ChainExpression) {
|
|
20986
21112
|
current = current.expression;
|
|
20987
21113
|
continue;
|
|
20988
21114
|
}
|
|
20989
|
-
if (current.type ===
|
|
21115
|
+
if (current.type === AST_NODE_TYPES96.TSAsExpression || current.type === AST_NODE_TYPES96.TSNonNullExpression || current.type === AST_NODE_TYPES96.TSTypeAssertion) {
|
|
20990
21116
|
current = current.expression;
|
|
20991
21117
|
continue;
|
|
20992
21118
|
}
|
|
20993
|
-
if (current.type ===
|
|
20994
|
-
if (current.callee.type !==
|
|
21119
|
+
if (current.type === AST_NODE_TYPES96.CallExpression) {
|
|
21120
|
+
if (current.callee.type !== AST_NODE_TYPES96.MemberExpression) return false;
|
|
20995
21121
|
const name = memberName7(current.callee);
|
|
20996
21122
|
if (name !== null && BUILDER_METHODS.has(name)) return true;
|
|
20997
21123
|
current = current.callee.object;
|
|
20998
21124
|
continue;
|
|
20999
21125
|
}
|
|
21000
|
-
if (current.type !==
|
|
21126
|
+
if (current.type !== AST_NODE_TYPES96.MemberExpression) return false;
|
|
21001
21127
|
current = current.object;
|
|
21002
21128
|
}
|
|
21003
21129
|
}
|
|
21004
21130
|
function owningClass2(node) {
|
|
21005
21131
|
let current = node.parent;
|
|
21006
21132
|
while (current != null) {
|
|
21007
|
-
if (current.type ===
|
|
21133
|
+
if (current.type === AST_NODE_TYPES96.ClassDeclaration || current.type === AST_NODE_TYPES96.ClassExpression)
|
|
21008
21134
|
return current;
|
|
21009
21135
|
current = current.parent;
|
|
21010
21136
|
}
|
|
@@ -21013,25 +21139,25 @@ function owningClass2(node) {
|
|
|
21013
21139
|
function injectedMembers(owner) {
|
|
21014
21140
|
const injected = /* @__PURE__ */ new Set();
|
|
21015
21141
|
const constructor = owner.body.body.find(
|
|
21016
|
-
(member) => member.type ===
|
|
21142
|
+
(member) => member.type === AST_NODE_TYPES96.MethodDefinition && member.kind === "constructor"
|
|
21017
21143
|
);
|
|
21018
21144
|
if (constructor === void 0) return injected;
|
|
21019
21145
|
const parameters = /* @__PURE__ */ new Set();
|
|
21020
21146
|
for (const parameter of constructor.value.params) {
|
|
21021
21147
|
for (const name of parameterNames(parameter)) parameters.add(name);
|
|
21022
|
-
if (parameter.type !==
|
|
21023
|
-
const value = parameter.parameter.type ===
|
|
21024
|
-
if (value.type ===
|
|
21148
|
+
if (parameter.type !== AST_NODE_TYPES96.TSParameterProperty) continue;
|
|
21149
|
+
const value = parameter.parameter.type === AST_NODE_TYPES96.AssignmentPattern ? parameter.parameter.left : parameter.parameter;
|
|
21150
|
+
if (value.type === AST_NODE_TYPES96.Identifier) injected.add(value.name);
|
|
21025
21151
|
}
|
|
21026
21152
|
const body2 = constructor.value.body;
|
|
21027
21153
|
if (body2 === null) return injected;
|
|
21028
21154
|
function collectInjectedMember(statement) {
|
|
21029
|
-
if (statement.type !==
|
|
21155
|
+
if (statement.type !== AST_NODE_TYPES96.ExpressionStatement || statement.expression.type !== AST_NODE_TYPES96.AssignmentExpression || statement.expression.operator !== "=") return;
|
|
21030
21156
|
const { left, right } = statement.expression;
|
|
21031
|
-
if (left.type !==
|
|
21157
|
+
if (left.type !== AST_NODE_TYPES96.MemberExpression) return;
|
|
21032
21158
|
const target = thisRootMember(left);
|
|
21033
21159
|
if (target === null) return;
|
|
21034
|
-
const source = right.type ===
|
|
21160
|
+
const source = right.type === AST_NODE_TYPES96.Identifier ? right.name : right.type === AST_NODE_TYPES96.MemberExpression && right.object.type === AST_NODE_TYPES96.Identifier ? right.object.name : null;
|
|
21035
21161
|
if (source !== null && parameters.has(source)) injected.add(target);
|
|
21036
21162
|
}
|
|
21037
21163
|
for (const statement of body2.body) {
|
|
@@ -21042,26 +21168,26 @@ function injectedMembers(owner) {
|
|
|
21042
21168
|
function thisRootMember(node) {
|
|
21043
21169
|
let current = node;
|
|
21044
21170
|
let root = null;
|
|
21045
|
-
while (current.type ===
|
|
21171
|
+
while (current.type === AST_NODE_TYPES96.MemberExpression) {
|
|
21046
21172
|
const name = memberName7(current);
|
|
21047
21173
|
if (name === null) return null;
|
|
21048
21174
|
root = name;
|
|
21049
21175
|
current = current.object;
|
|
21050
21176
|
}
|
|
21051
|
-
return current.type ===
|
|
21177
|
+
return current.type === AST_NODE_TYPES96.ThisExpression ? root : null;
|
|
21052
21178
|
}
|
|
21053
21179
|
function parameterNames(parameter) {
|
|
21054
21180
|
let value = parameter;
|
|
21055
|
-
if (value.type ===
|
|
21056
|
-
if (value.type ===
|
|
21057
|
-
if (value.type ===
|
|
21058
|
-
if (value.type !==
|
|
21181
|
+
if (value.type === AST_NODE_TYPES96.TSParameterProperty) value = value.parameter;
|
|
21182
|
+
if (value.type === AST_NODE_TYPES96.AssignmentPattern) value = value.left;
|
|
21183
|
+
if (value.type === AST_NODE_TYPES96.Identifier) return /* @__PURE__ */ new Set([value.name]);
|
|
21184
|
+
if (value.type !== AST_NODE_TYPES96.ObjectPattern) return /* @__PURE__ */ new Set();
|
|
21059
21185
|
return new Set(
|
|
21060
21186
|
value.properties.flatMap((property) => {
|
|
21061
|
-
if (property.type ===
|
|
21062
|
-
return property.argument.type ===
|
|
21063
|
-
const target = property.value.type ===
|
|
21064
|
-
return target.type ===
|
|
21187
|
+
if (property.type === AST_NODE_TYPES96.RestElement)
|
|
21188
|
+
return property.argument.type === AST_NODE_TYPES96.Identifier ? [property.argument.name] : [];
|
|
21189
|
+
const target = property.value.type === AST_NODE_TYPES96.AssignmentPattern ? property.value.left : property.value;
|
|
21190
|
+
return target.type === AST_NODE_TYPES96.Identifier ? [target.name] : [];
|
|
21065
21191
|
})
|
|
21066
21192
|
);
|
|
21067
21193
|
}
|
|
@@ -21085,17 +21211,17 @@ var require_sql_access_class_default = createRule({
|
|
|
21085
21211
|
function knownNonDatabase(node, seen = /* @__PURE__ */ new Set()) {
|
|
21086
21212
|
if (seen.has(node)) return false;
|
|
21087
21213
|
seen.add(node);
|
|
21088
|
-
if (node.type ===
|
|
21089
|
-
const binding =
|
|
21214
|
+
if (node.type === AST_NODE_TYPES96.Identifier) {
|
|
21215
|
+
const binding = ASTUtils48.findVariable(context.sourceCode.getScope(node), node.name);
|
|
21090
21216
|
if (binding?.defs.length !== 1 || binding.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
21091
21217
|
const definition = binding.defs[0];
|
|
21092
21218
|
return definition?.type === "Variable" && definition.node.init !== null && knownNonDatabase(definition.node.init, seen);
|
|
21093
21219
|
}
|
|
21094
|
-
return node.type ===
|
|
21220
|
+
return node.type === AST_NODE_TYPES96.NewExpression && node.callee.type === AST_NODE_TYPES96.Identifier && ["Map", "WeakMap", "URLSearchParams"].includes(node.callee.name) && (ASTUtils48.findVariable(context.sourceCode.getScope(node.callee), node.callee.name)?.defs.length ?? 0) === 0;
|
|
21095
21221
|
}
|
|
21096
21222
|
return {
|
|
21097
21223
|
CallExpression(node) {
|
|
21098
|
-
if (node.callee.type !==
|
|
21224
|
+
if (node.callee.type !== AST_NODE_TYPES96.MemberExpression)
|
|
21099
21225
|
return;
|
|
21100
21226
|
const method = memberName7(node.callee);
|
|
21101
21227
|
if (knownNonDatabase(node.callee.object)) return;
|
|
@@ -21113,7 +21239,7 @@ var require_sql_access_class_default = createRule({
|
|
|
21113
21239
|
});
|
|
21114
21240
|
|
|
21115
21241
|
// src/rules/require-static-next-matcher.ts
|
|
21116
|
-
import { AST_NODE_TYPES as
|
|
21242
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES97 } from "@typescript-eslint/utils";
|
|
21117
21243
|
var REQUIRE_STATIC_NEXT_MATCHER_DOCUMENTATION = {
|
|
21118
21244
|
summary: "Require Next.js middleware and proxy matcher configuration to contain only build-time literals.",
|
|
21119
21245
|
rationale: "Next.js must statically analyze matcher values at build time; computed values are ignored.",
|
|
@@ -21128,34 +21254,34 @@ var REQUIRE_STATIC_NEXT_MATCHER_DOCUMENTATION = {
|
|
|
21128
21254
|
};
|
|
21129
21255
|
var NEXT_ENTRY_FILE = /(?:^|[/\\])(?:middleware|proxy)\.[cm]?[jt]sx?$/u;
|
|
21130
21256
|
function unwrapExpression5(node) {
|
|
21131
|
-
if (node.type ===
|
|
21257
|
+
if (node.type === AST_NODE_TYPES97.TSAsExpression || node.type === AST_NODE_TYPES97.TSSatisfiesExpression || node.type === AST_NODE_TYPES97.TSNonNullExpression || node.type === AST_NODE_TYPES97.TSTypeAssertion) {
|
|
21132
21258
|
return unwrapExpression5(node.expression);
|
|
21133
21259
|
}
|
|
21134
21260
|
return node;
|
|
21135
21261
|
}
|
|
21136
21262
|
function isStaticValue(node) {
|
|
21137
21263
|
const value = unwrapExpression5(node);
|
|
21138
|
-
if (value.type ===
|
|
21264
|
+
if (value.type === AST_NODE_TYPES97.Literal) {
|
|
21139
21265
|
return true;
|
|
21140
21266
|
}
|
|
21141
|
-
if (value.type ===
|
|
21267
|
+
if (value.type === AST_NODE_TYPES97.TemplateLiteral) {
|
|
21142
21268
|
return value.expressions.length === 0;
|
|
21143
21269
|
}
|
|
21144
|
-
if (value.type ===
|
|
21270
|
+
if (value.type === AST_NODE_TYPES97.ArrayExpression) {
|
|
21145
21271
|
return value.elements.every(
|
|
21146
|
-
(element) => element !== null && element.type !==
|
|
21272
|
+
(element) => element !== null && element.type !== AST_NODE_TYPES97.SpreadElement && isStaticValue(element)
|
|
21147
21273
|
);
|
|
21148
21274
|
}
|
|
21149
|
-
if (value.type ===
|
|
21275
|
+
if (value.type === AST_NODE_TYPES97.ObjectExpression) {
|
|
21150
21276
|
return value.properties.every(
|
|
21151
|
-
(property) => property.type ===
|
|
21277
|
+
(property) => property.type === AST_NODE_TYPES97.Property && property.kind === "init" && !property.computed && property.value.type !== AST_NODE_TYPES97.AssignmentPattern && isStaticValue(property.value)
|
|
21152
21278
|
);
|
|
21153
21279
|
}
|
|
21154
21280
|
return false;
|
|
21155
21281
|
}
|
|
21156
21282
|
function propertyName6(property) {
|
|
21157
|
-
if (!property.computed && property.key.type ===
|
|
21158
|
-
return property.key.type ===
|
|
21283
|
+
if (!property.computed && property.key.type === AST_NODE_TYPES97.Identifier) return property.key.name;
|
|
21284
|
+
return property.key.type === AST_NODE_TYPES97.Literal && typeof property.key.value === "string" ? property.key.value : null;
|
|
21159
21285
|
}
|
|
21160
21286
|
var require_static_next_matcher_default = createRule({
|
|
21161
21287
|
name: "require-static-next-matcher",
|
|
@@ -21177,19 +21303,19 @@ var require_static_next_matcher_default = createRule({
|
|
|
21177
21303
|
}
|
|
21178
21304
|
return {
|
|
21179
21305
|
ExportNamedDeclaration(node) {
|
|
21180
|
-
if (node.declaration?.type !==
|
|
21306
|
+
if (node.declaration?.type !== AST_NODE_TYPES97.VariableDeclaration) {
|
|
21181
21307
|
return;
|
|
21182
21308
|
}
|
|
21183
21309
|
for (const declaration of node.declaration.declarations) {
|
|
21184
|
-
if (declaration.id.type !==
|
|
21310
|
+
if (declaration.id.type !== AST_NODE_TYPES97.Identifier || declaration.id.name !== "config" || declaration.init === null) {
|
|
21185
21311
|
continue;
|
|
21186
21312
|
}
|
|
21187
21313
|
const config = unwrapExpression5(declaration.init);
|
|
21188
|
-
if (config.type !==
|
|
21314
|
+
if (config.type !== AST_NODE_TYPES97.ObjectExpression) {
|
|
21189
21315
|
continue;
|
|
21190
21316
|
}
|
|
21191
21317
|
for (const property of config.properties) {
|
|
21192
|
-
if (property.type !==
|
|
21318
|
+
if (property.type !== AST_NODE_TYPES97.Property || propertyName6(property) !== "matcher" || property.value.type === AST_NODE_TYPES97.AssignmentPattern) {
|
|
21193
21319
|
continue;
|
|
21194
21320
|
}
|
|
21195
21321
|
if (!isStaticValue(property.value)) {
|
|
@@ -21203,7 +21329,7 @@ var require_static_next_matcher_default = createRule({
|
|
|
21203
21329
|
});
|
|
21204
21330
|
|
|
21205
21331
|
// src/rules/require-use-form-default-values.ts
|
|
21206
|
-
import { AST_NODE_TYPES as
|
|
21332
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES98, ASTUtils as ASTUtils49 } from "@typescript-eslint/utils";
|
|
21207
21333
|
var REQUIRE_USE_FORM_DEFAULT_VALUES_DOCUMENTATION = {
|
|
21208
21334
|
summary: "Require explicit form-level initialization or a field default for directly bound Controller fields.",
|
|
21209
21335
|
rationale: "React Hook Form exposes form-level defaultValues/values and field-level defaultValue as its explicit initialization mechanisms. A directly bound controlled field should not omit both mechanisms.",
|
|
@@ -21236,12 +21362,12 @@ var REQUIRE_USE_FORM_DEFAULT_VALUES_DOCUMENTATION = {
|
|
|
21236
21362
|
};
|
|
21237
21363
|
function staticPropertyName(property) {
|
|
21238
21364
|
if (property.computed) return null;
|
|
21239
|
-
if (property.key.type ===
|
|
21240
|
-
if (property.key.type ===
|
|
21365
|
+
if (property.key.type === AST_NODE_TYPES98.Identifier) return property.key.name;
|
|
21366
|
+
if (property.key.type === AST_NODE_TYPES98.Literal && typeof property.key.value === "string") return property.key.value;
|
|
21241
21367
|
return null;
|
|
21242
21368
|
}
|
|
21243
21369
|
function unwrapExpression6(node) {
|
|
21244
|
-
if (node.type ===
|
|
21370
|
+
if (node.type === AST_NODE_TYPES98.TSAsExpression || node.type === AST_NODE_TYPES98.TSSatisfiesExpression || node.type === AST_NODE_TYPES98.TSNonNullExpression || node.type === AST_NODE_TYPES98.TSTypeAssertion) return unwrapExpression6(node.expression);
|
|
21245
21371
|
return node;
|
|
21246
21372
|
}
|
|
21247
21373
|
var require_use_form_default_values_default = createRule({
|
|
@@ -21258,7 +21384,7 @@ var require_use_form_default_values_default = createRule({
|
|
|
21258
21384
|
const imported = /* @__PURE__ */ new Map();
|
|
21259
21385
|
const uninitializedForms = /* @__PURE__ */ new Set();
|
|
21260
21386
|
const uninitializedControls = /* @__PURE__ */ new Set();
|
|
21261
|
-
const bindingNamed = (node, name) =>
|
|
21387
|
+
const bindingNamed = (node, name) => ASTUtils49.findVariable(context.sourceCode.getScope(node), name);
|
|
21262
21388
|
const bindingOf = (node) => bindingNamed(node, node.name);
|
|
21263
21389
|
const stable = (variable) => !variable.references.some((reference) => reference.isWrite() && reference.init !== true);
|
|
21264
21390
|
const importedKind = (node) => {
|
|
@@ -21271,44 +21397,44 @@ var require_use_form_default_values_default = createRule({
|
|
|
21271
21397
|
};
|
|
21272
21398
|
const isDefinitelyUndefined = (node) => {
|
|
21273
21399
|
const value = unwrapExpression6(node);
|
|
21274
|
-
return value.type ===
|
|
21400
|
+
return value.type === AST_NODE_TYPES98.UnaryExpression && value.operator === "void" || value.type === AST_NODE_TYPES98.Identifier && value.name === "undefined" && (bindingOf(value)?.defs.length ?? 0) === 0;
|
|
21275
21401
|
};
|
|
21276
21402
|
const initializationState = (node) => {
|
|
21277
21403
|
if (node === void 0) return "uninitialized";
|
|
21278
|
-
if (node.type !==
|
|
21404
|
+
if (node.type !== AST_NODE_TYPES98.ObjectExpression) return "unknown";
|
|
21279
21405
|
const initialization = /* @__PURE__ */ new Map();
|
|
21280
21406
|
for (const property of node.properties) {
|
|
21281
|
-
if (property.type ===
|
|
21282
|
-
if (property.type !==
|
|
21407
|
+
if (property.type === AST_NODE_TYPES98.SpreadElement || property.computed) return "unknown";
|
|
21408
|
+
if (property.type !== AST_NODE_TYPES98.Property) continue;
|
|
21283
21409
|
const name = staticPropertyName(property);
|
|
21284
21410
|
if (name === "defaultValues" || name === "values") initialization.set(name, !isDefinitelyUndefined(property.value));
|
|
21285
21411
|
}
|
|
21286
21412
|
return [...initialization.values()].some(Boolean) ? "initialized" : "uninitialized";
|
|
21287
21413
|
};
|
|
21288
21414
|
const uninitializedUseFormCall = (node) => {
|
|
21289
|
-
if (node.type !==
|
|
21415
|
+
if (node.type !== AST_NODE_TYPES98.CallExpression || node.callee.type !== AST_NODE_TYPES98.Identifier || importedKind(node.callee) !== "useForm") return false;
|
|
21290
21416
|
const options = node.arguments[0];
|
|
21291
|
-
return options?.type !==
|
|
21417
|
+
return options?.type !== AST_NODE_TYPES98.SpreadElement && initializationState(options) === "uninitialized";
|
|
21292
21418
|
};
|
|
21293
21419
|
const isUninitializedForm = (node) => {
|
|
21294
|
-
if (node.type !==
|
|
21420
|
+
if (node.type !== AST_NODE_TYPES98.Identifier) return false;
|
|
21295
21421
|
const variable = bindingOf(node);
|
|
21296
21422
|
return variable !== null && stable(variable) && uninitializedForms.has(variable);
|
|
21297
21423
|
};
|
|
21298
21424
|
const isUninitializedControl = (node) => {
|
|
21299
|
-
if (node.type ===
|
|
21425
|
+
if (node.type === AST_NODE_TYPES98.Identifier) {
|
|
21300
21426
|
const variable = bindingOf(node);
|
|
21301
21427
|
return variable !== null && stable(variable) && uninitializedControls.has(variable);
|
|
21302
21428
|
}
|
|
21303
|
-
return node.type ===
|
|
21429
|
+
return node.type === AST_NODE_TYPES98.MemberExpression && !node.computed && node.property.type === AST_NODE_TYPES98.Identifier && node.property.name === "control" && isUninitializedForm(node.object);
|
|
21304
21430
|
};
|
|
21305
21431
|
const fieldOptionsNeedDefault = (node) => {
|
|
21306
|
-
if (node?.type !==
|
|
21432
|
+
if (node?.type !== AST_NODE_TYPES98.ObjectExpression) return false;
|
|
21307
21433
|
let control = null;
|
|
21308
21434
|
let hasDefault = false;
|
|
21309
21435
|
for (const property of node.properties) {
|
|
21310
|
-
if (property.type ===
|
|
21311
|
-
if (property.type !==
|
|
21436
|
+
if (property.type === AST_NODE_TYPES98.SpreadElement || property.computed) return false;
|
|
21437
|
+
if (property.type !== AST_NODE_TYPES98.Property) continue;
|
|
21312
21438
|
const name = staticPropertyName(property);
|
|
21313
21439
|
if (name === "control") control = property.value;
|
|
21314
21440
|
if (name === "defaultValue") hasDefault = !isDefinitelyUndefined(property.value);
|
|
@@ -21318,14 +21444,14 @@ var require_use_form_default_values_default = createRule({
|
|
|
21318
21444
|
const jsxAttribute = (node, name) => {
|
|
21319
21445
|
let result = null;
|
|
21320
21446
|
for (const attribute of node.attributes) {
|
|
21321
|
-
if (attribute.type ===
|
|
21322
|
-
if (attribute.name.type ===
|
|
21447
|
+
if (attribute.type === AST_NODE_TYPES98.JSXSpreadAttribute) return null;
|
|
21448
|
+
if (attribute.name.type === AST_NODE_TYPES98.JSXIdentifier && attribute.name.name === name) result = attribute;
|
|
21323
21449
|
}
|
|
21324
21450
|
return result;
|
|
21325
21451
|
};
|
|
21326
21452
|
const trackDestructuredControl = (pattern) => {
|
|
21327
21453
|
for (const property of pattern.properties) {
|
|
21328
|
-
if (property.type !==
|
|
21454
|
+
if (property.type !== AST_NODE_TYPES98.Property || staticPropertyName(property) !== "control" || property.value.type !== AST_NODE_TYPES98.Identifier) continue;
|
|
21329
21455
|
const variable = bindingOf(property.value);
|
|
21330
21456
|
if (variable !== null) uninitializedControls.add(variable);
|
|
21331
21457
|
}
|
|
@@ -21334,8 +21460,8 @@ var require_use_form_default_values_default = createRule({
|
|
|
21334
21460
|
ImportDeclaration(node) {
|
|
21335
21461
|
if (node.source.value !== "react-hook-form") return;
|
|
21336
21462
|
for (const specifier of node.specifiers) {
|
|
21337
|
-
if (specifier.type !==
|
|
21338
|
-
const name = specifier.imported.type ===
|
|
21463
|
+
if (specifier.type !== AST_NODE_TYPES98.ImportSpecifier) continue;
|
|
21464
|
+
const name = specifier.imported.type === AST_NODE_TYPES98.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
21339
21465
|
if (name !== "Controller" && name !== "useController" && name !== "useForm") continue;
|
|
21340
21466
|
const variable = bindingOf(specifier.local);
|
|
21341
21467
|
if (variable !== null) imported.set(variable, name);
|
|
@@ -21344,34 +21470,34 @@ var require_use_form_default_values_default = createRule({
|
|
|
21344
21470
|
VariableDeclarator(node) {
|
|
21345
21471
|
if (node.init === null) return;
|
|
21346
21472
|
if (uninitializedUseFormCall(node.init)) {
|
|
21347
|
-
if (node.id.type ===
|
|
21473
|
+
if (node.id.type === AST_NODE_TYPES98.Identifier) {
|
|
21348
21474
|
const variable = bindingOf(node.id);
|
|
21349
21475
|
if (variable !== null) uninitializedForms.add(variable);
|
|
21350
|
-
} else if (node.id.type ===
|
|
21476
|
+
} else if (node.id.type === AST_NODE_TYPES98.ObjectPattern) {
|
|
21351
21477
|
trackDestructuredControl(node.id);
|
|
21352
21478
|
}
|
|
21353
21479
|
return;
|
|
21354
21480
|
}
|
|
21355
|
-
if (node.id.type ===
|
|
21481
|
+
if (node.id.type === AST_NODE_TYPES98.ObjectPattern && isUninitializedForm(node.init)) {
|
|
21356
21482
|
trackDestructuredControl(node.id);
|
|
21357
21483
|
return;
|
|
21358
21484
|
}
|
|
21359
|
-
if (node.id.type ===
|
|
21485
|
+
if (node.id.type === AST_NODE_TYPES98.Identifier && node.init.type === AST_NODE_TYPES98.MemberExpression && !node.init.computed && node.init.property.type === AST_NODE_TYPES98.Identifier && node.init.property.name === "control" && isUninitializedForm(node.init.object)) {
|
|
21360
21486
|
const variable = bindingOf(node.id);
|
|
21361
21487
|
if (variable !== null) uninitializedControls.add(variable);
|
|
21362
21488
|
}
|
|
21363
21489
|
},
|
|
21364
21490
|
CallExpression(node) {
|
|
21365
|
-
if (node.callee.type !==
|
|
21491
|
+
if (node.callee.type !== AST_NODE_TYPES98.Identifier || importedKind(node.callee) !== "useController" || !fieldOptionsNeedDefault(node.arguments[0]?.type === AST_NODE_TYPES98.SpreadElement ? void 0 : node.arguments[0])) return;
|
|
21366
21492
|
context.report({ node, messageId: "requireUseFormDefaultValues" });
|
|
21367
21493
|
},
|
|
21368
21494
|
JSXOpeningElement(node) {
|
|
21369
|
-
if (node.name.type !==
|
|
21370
|
-
if (node.attributes.some((attribute) => attribute.type ===
|
|
21495
|
+
if (node.name.type !== AST_NODE_TYPES98.JSXIdentifier || importedJsxKind(node.name) !== "Controller") return;
|
|
21496
|
+
if (node.attributes.some((attribute) => attribute.type === AST_NODE_TYPES98.JSXSpreadAttribute)) return;
|
|
21371
21497
|
const control = jsxAttribute(node, "control");
|
|
21372
|
-
if (control?.value?.type !==
|
|
21498
|
+
if (control?.value?.type !== AST_NODE_TYPES98.JSXExpressionContainer || control.value.expression.type === AST_NODE_TYPES98.JSXEmptyExpression || !isUninitializedControl(control.value.expression)) return;
|
|
21373
21499
|
const defaultValue = jsxAttribute(node, "defaultValue");
|
|
21374
|
-
if (defaultValue !== null && (defaultValue.value === null || defaultValue.value.type !==
|
|
21500
|
+
if (defaultValue !== null && (defaultValue.value === null || defaultValue.value.type !== AST_NODE_TYPES98.JSXExpressionContainer || defaultValue.value.expression.type !== AST_NODE_TYPES98.JSXEmptyExpression && !isDefinitelyUndefined(defaultValue.value.expression))) return;
|
|
21375
21501
|
context.report({ node, messageId: "requireUseFormDefaultValues" });
|
|
21376
21502
|
}
|
|
21377
21503
|
};
|
|
@@ -21447,8 +21573,8 @@ var require_use_server_in_actions_file_default = createRule({
|
|
|
21447
21573
|
|
|
21448
21574
|
// src/rules/require-zod-form-validation.ts
|
|
21449
21575
|
import {
|
|
21450
|
-
AST_NODE_TYPES as
|
|
21451
|
-
ASTUtils as
|
|
21576
|
+
AST_NODE_TYPES as AST_NODE_TYPES99,
|
|
21577
|
+
ASTUtils as ASTUtils50
|
|
21452
21578
|
} from "@typescript-eslint/utils";
|
|
21453
21579
|
var REQUIRE_ZOD_FORM_VALIDATION_DOCUMENTATION = {
|
|
21454
21580
|
summary: "Require Zod validation (`Schema.parse(...)` / `Schema.safeParse(...)`) when reading values out of a `FormData` object.",
|
|
@@ -21475,14 +21601,14 @@ var FORM_VALUE_METHODS = /* @__PURE__ */ new Set(["get", "getAll"]);
|
|
|
21475
21601
|
var zodReceiverRoot = (node) => {
|
|
21476
21602
|
let current = node;
|
|
21477
21603
|
while (true) {
|
|
21478
|
-
if (current.type ===
|
|
21604
|
+
if (current.type === AST_NODE_TYPES99.Identifier) {
|
|
21479
21605
|
return current;
|
|
21480
21606
|
}
|
|
21481
|
-
if (current.type ===
|
|
21607
|
+
if (current.type === AST_NODE_TYPES99.CallExpression) {
|
|
21482
21608
|
current = current.callee;
|
|
21483
21609
|
continue;
|
|
21484
21610
|
}
|
|
21485
|
-
if (current.type ===
|
|
21611
|
+
if (current.type === AST_NODE_TYPES99.MemberExpression) {
|
|
21486
21612
|
current = current.object;
|
|
21487
21613
|
continue;
|
|
21488
21614
|
}
|
|
@@ -21491,12 +21617,12 @@ var zodReceiverRoot = (node) => {
|
|
|
21491
21617
|
};
|
|
21492
21618
|
var isFormDataMethodCall = (node) => {
|
|
21493
21619
|
let current = node;
|
|
21494
|
-
if (current.type ===
|
|
21620
|
+
if (current.type === AST_NODE_TYPES99.AwaitExpression) {
|
|
21495
21621
|
current = current.argument;
|
|
21496
21622
|
}
|
|
21497
|
-
if (current.type !==
|
|
21623
|
+
if (current.type !== AST_NODE_TYPES99.CallExpression) return false;
|
|
21498
21624
|
const callee = current.callee;
|
|
21499
|
-
return callee.type ===
|
|
21625
|
+
return callee.type === AST_NODE_TYPES99.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES99.Identifier && callee.property.name === "formData";
|
|
21500
21626
|
};
|
|
21501
21627
|
var require_zod_form_validation_default = createRule({
|
|
21502
21628
|
name: "require-zod-form-validation",
|
|
@@ -21517,7 +21643,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
21517
21643
|
return {};
|
|
21518
21644
|
}
|
|
21519
21645
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
21520
|
-
const resolvedBinding = (identifier) =>
|
|
21646
|
+
const resolvedBinding = (identifier) => ASTUtils50.findVariable(
|
|
21521
21647
|
context.sourceCode.getScope(identifier),
|
|
21522
21648
|
identifier.name
|
|
21523
21649
|
);
|
|
@@ -21527,16 +21653,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
21527
21653
|
return false;
|
|
21528
21654
|
}
|
|
21529
21655
|
const definition = binding.defs[0];
|
|
21530
|
-
if (definition?.type !== "Variable" || definition.node.type !==
|
|
21656
|
+
if (definition?.type !== "Variable" || definition.node.type !== AST_NODE_TYPES99.VariableDeclarator) {
|
|
21531
21657
|
return false;
|
|
21532
21658
|
}
|
|
21533
21659
|
const init = definition.node.init;
|
|
21534
|
-
return init?.type ===
|
|
21660
|
+
return init?.type === AST_NODE_TYPES99.ObjectExpression || init?.type === AST_NODE_TYPES99.ArrayExpression || init?.type === AST_NODE_TYPES99.Literal || init?.type === AST_NODE_TYPES99.ArrowFunctionExpression || init?.type === AST_NODE_TYPES99.FunctionExpression;
|
|
21535
21661
|
};
|
|
21536
21662
|
const isZodParseCall = (node) => {
|
|
21537
|
-
if (node.type !==
|
|
21663
|
+
if (node.type !== AST_NODE_TYPES99.CallExpression) return false;
|
|
21538
21664
|
const callee = node.callee;
|
|
21539
|
-
if (callee.type !==
|
|
21665
|
+
if (callee.type !== AST_NODE_TYPES99.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES99.Identifier || !ZOD_PARSE_METHODS.has(callee.property.name)) {
|
|
21540
21666
|
return false;
|
|
21541
21667
|
}
|
|
21542
21668
|
const root = zodReceiverRoot(callee.object);
|
|
@@ -21545,14 +21671,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
21545
21671
|
return binding !== null && zodBindings.has(binding) || (root.name === "z" || ZOD_SCHEMA_NAME_RE.test(root.name)) && !isProvablyNonZodLocal(root);
|
|
21546
21672
|
};
|
|
21547
21673
|
const isFormSourceIdentifier = (node) => {
|
|
21548
|
-
if (node.type !==
|
|
21674
|
+
if (node.type !== AST_NODE_TYPES99.Identifier) return false;
|
|
21549
21675
|
const conventionalName = /formdata/i.test(node.name);
|
|
21550
21676
|
let scope = context.sourceCode.getScope(node);
|
|
21551
21677
|
while (scope !== null) {
|
|
21552
21678
|
const variable = scope.set.get(node.name);
|
|
21553
21679
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
21554
21680
|
const def = variable.defs[0];
|
|
21555
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
21681
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === AST_NODE_TYPES99.VariableDeclarator && def.node.init !== null) {
|
|
21556
21682
|
return isFormDataMethodCall(def.node.init);
|
|
21557
21683
|
}
|
|
21558
21684
|
return def?.type === "Parameter" && conventionalName;
|
|
@@ -21563,8 +21689,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
21563
21689
|
};
|
|
21564
21690
|
const isFormDataGetCall = (node) => {
|
|
21565
21691
|
const callee = node.callee;
|
|
21566
|
-
if (callee.type !==
|
|
21567
|
-
if (callee.property.type !==
|
|
21692
|
+
if (callee.type !== AST_NODE_TYPES99.MemberExpression) return false;
|
|
21693
|
+
if (callee.property.type !== AST_NODE_TYPES99.Identifier || !FORM_VALUE_METHODS.has(callee.property.name)) {
|
|
21568
21694
|
return false;
|
|
21569
21695
|
}
|
|
21570
21696
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -21573,15 +21699,15 @@ var require_zod_form_validation_default = createRule({
|
|
|
21573
21699
|
let parent = node.parent;
|
|
21574
21700
|
while (parent !== null && parent !== void 0) {
|
|
21575
21701
|
if (isZodParseCall(parent)) return parent;
|
|
21576
|
-
if (parent.type ===
|
|
21702
|
+
if (parent.type === AST_NODE_TYPES99.CallExpression && parent.callee.type === AST_NODE_TYPES99.Identifier && ["Number", "String", "Boolean"].includes(parent.callee.name) && parent.arguments.length === 1 && (resolvedBinding(parent.callee)?.defs.length ?? 0) === 0) {
|
|
21577
21703
|
parent = parent.parent;
|
|
21578
21704
|
continue;
|
|
21579
21705
|
}
|
|
21580
|
-
if (parent.type ===
|
|
21706
|
+
if (parent.type === AST_NODE_TYPES99.CallExpression && parent.callee.type === AST_NODE_TYPES99.MemberExpression && !parent.callee.computed && parent.callee.object.type === AST_NODE_TYPES99.Identifier && parent.callee.object.name === "Object" && parent.callee.property.type === AST_NODE_TYPES99.Identifier && parent.callee.property.name === "fromEntries" && (resolvedBinding(parent.callee.object)?.defs.length ?? 0) === 0) {
|
|
21581
21707
|
parent = parent.parent;
|
|
21582
21708
|
continue;
|
|
21583
21709
|
}
|
|
21584
|
-
if (parent.type ===
|
|
21710
|
+
if (parent.type === AST_NODE_TYPES99.CallExpression || parent.type === AST_NODE_TYPES99.NewExpression || parent.type === AST_NODE_TYPES99.TaggedTemplateExpression || parent.type === AST_NODE_TYPES99.ArrowFunctionExpression || parent.type === AST_NODE_TYPES99.FunctionExpression || parent.type === AST_NODE_TYPES99.FunctionDeclaration) return null;
|
|
21585
21711
|
parent = parent.parent;
|
|
21586
21712
|
}
|
|
21587
21713
|
return null;
|
|
@@ -21589,16 +21715,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
21589
21715
|
const hasZodParseAncestor = (node) => zodParseAncestor(node) !== null;
|
|
21590
21716
|
const isInstanceofNarrowing = (node) => {
|
|
21591
21717
|
const parent = node.parent;
|
|
21592
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
21718
|
+
return parent !== null && parent !== void 0 && parent.type === AST_NODE_TYPES99.BinaryExpression && parent.operator === "instanceof" && parent.left === node && parent.right.type === AST_NODE_TYPES99.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
21593
21719
|
};
|
|
21594
21720
|
const boundDeclarator = (node) => {
|
|
21595
21721
|
let current = node;
|
|
21596
21722
|
let parent = current.parent;
|
|
21597
|
-
while ((parent.type ===
|
|
21723
|
+
while ((parent.type === AST_NODE_TYPES99.TSAsExpression || parent.type === AST_NODE_TYPES99.TSSatisfiesExpression || parent.type === AST_NODE_TYPES99.TSNonNullExpression || parent.type === AST_NODE_TYPES99.ChainExpression) && parent.expression === current) {
|
|
21598
21724
|
current = parent;
|
|
21599
21725
|
parent = current.parent;
|
|
21600
21726
|
}
|
|
21601
|
-
if (parent.type ===
|
|
21727
|
+
if (parent.type === AST_NODE_TYPES99.VariableDeclarator && parent.init === current && parent.id.type === AST_NODE_TYPES99.Identifier) {
|
|
21602
21728
|
return parent;
|
|
21603
21729
|
}
|
|
21604
21730
|
return null;
|
|
@@ -21607,7 +21733,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
21607
21733
|
let current = node;
|
|
21608
21734
|
while (current.parent !== void 0) {
|
|
21609
21735
|
const parent = current.parent;
|
|
21610
|
-
if (parent.type ===
|
|
21736
|
+
if (parent.type === AST_NODE_TYPES99.BlockStatement || parent.type === AST_NODE_TYPES99.Program) {
|
|
21611
21737
|
return current;
|
|
21612
21738
|
}
|
|
21613
21739
|
current = parent;
|
|
@@ -21616,12 +21742,12 @@ var require_zod_form_validation_default = createRule({
|
|
|
21616
21742
|
};
|
|
21617
21743
|
const zodParseMethod = (call) => {
|
|
21618
21744
|
const callee = call.callee;
|
|
21619
|
-
return callee.type ===
|
|
21745
|
+
return callee.type === AST_NODE_TYPES99.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES99.Identifier ? callee.property.name : null;
|
|
21620
21746
|
};
|
|
21621
21747
|
const hasConditionalAncestorBeforeStatement = (node, statement) => {
|
|
21622
21748
|
let current = node.parent;
|
|
21623
21749
|
while (current !== void 0 && current !== statement) {
|
|
21624
|
-
if (current.type ===
|
|
21750
|
+
if (current.type === AST_NODE_TYPES99.LogicalExpression || current.type === AST_NODE_TYPES99.ConditionalExpression) {
|
|
21625
21751
|
return true;
|
|
21626
21752
|
}
|
|
21627
21753
|
current = current.parent;
|
|
@@ -21631,7 +21757,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
21631
21757
|
const isAwaitedBeforeStatement = (node, statement) => {
|
|
21632
21758
|
let current = node.parent;
|
|
21633
21759
|
while (current !== void 0 && current !== statement) {
|
|
21634
|
-
if (current.type ===
|
|
21760
|
+
if (current.type === AST_NODE_TYPES99.AwaitExpression) return true;
|
|
21635
21761
|
current = current.parent;
|
|
21636
21762
|
}
|
|
21637
21763
|
return false;
|
|
@@ -21644,7 +21770,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
21644
21770
|
if (declarationStatement === null || validationStatement === null || declarationStatement.parent !== validationStatement.parent || validationStatement.range[0] <= declarationStatement.range[1] || hasConditionalAncestorBeforeStatement(parse2, validationStatement)) {
|
|
21645
21771
|
return null;
|
|
21646
21772
|
}
|
|
21647
|
-
if (validationStatement.type !==
|
|
21773
|
+
if (validationStatement.type !== AST_NODE_TYPES99.VariableDeclaration && validationStatement.type !== AST_NODE_TYPES99.ExpressionStatement) {
|
|
21648
21774
|
return null;
|
|
21649
21775
|
}
|
|
21650
21776
|
const method = zodParseMethod(parse2);
|
|
@@ -21656,16 +21782,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
21656
21782
|
};
|
|
21657
21783
|
const isSafePrevalidationInspection = (identifier) => {
|
|
21658
21784
|
const parent = identifier.parent;
|
|
21659
|
-
if (parent.type ===
|
|
21785
|
+
if (parent.type === AST_NODE_TYPES99.UnaryExpression && parent.operator === "typeof") {
|
|
21660
21786
|
return true;
|
|
21661
21787
|
}
|
|
21662
|
-
if (parent.type !==
|
|
21788
|
+
if (parent.type !== AST_NODE_TYPES99.BinaryExpression || parent.left !== identifier) {
|
|
21663
21789
|
return false;
|
|
21664
21790
|
}
|
|
21665
21791
|
if (parent.operator === "instanceof") {
|
|
21666
|
-
return parent.right.type ===
|
|
21792
|
+
return parent.right.type === AST_NODE_TYPES99.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
21667
21793
|
}
|
|
21668
|
-
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type ===
|
|
21794
|
+
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type === AST_NODE_TYPES99.Literal && parent.right.value === null || parent.right.type === AST_NODE_TYPES99.Identifier && parent.right.name === "undefined");
|
|
21669
21795
|
};
|
|
21670
21796
|
const isDescendantOf = (node, ancestor) => {
|
|
21671
21797
|
let current = node;
|
|
@@ -21676,23 +21802,23 @@ var require_zod_form_validation_default = createRule({
|
|
|
21676
21802
|
return false;
|
|
21677
21803
|
};
|
|
21678
21804
|
const blockTerminates = (node) => {
|
|
21679
|
-
if (node.type ===
|
|
21805
|
+
if (node.type === AST_NODE_TYPES99.ReturnStatement || node.type === AST_NODE_TYPES99.ThrowStatement) {
|
|
21680
21806
|
return true;
|
|
21681
21807
|
}
|
|
21682
|
-
if (node.type !==
|
|
21808
|
+
if (node.type !== AST_NODE_TYPES99.BlockStatement || node.body.length === 0) return false;
|
|
21683
21809
|
const last = node.body.at(-1);
|
|
21684
21810
|
return last !== void 0 && blockTerminates(last);
|
|
21685
21811
|
};
|
|
21686
21812
|
const narrowingIf = (identifier) => {
|
|
21687
21813
|
const comparison = identifier.parent;
|
|
21688
|
-
if (comparison?.type !==
|
|
21814
|
+
if (comparison?.type !== AST_NODE_TYPES99.BinaryExpression || comparison.operator !== "instanceof" || comparison.left !== identifier || comparison.right.type !== AST_NODE_TYPES99.Identifier || comparison.right.name !== "File" && comparison.right.name !== "Blob") {
|
|
21689
21815
|
return null;
|
|
21690
21816
|
}
|
|
21691
21817
|
const maybeNegation = comparison.parent;
|
|
21692
|
-
const negated = maybeNegation?.type ===
|
|
21818
|
+
const negated = maybeNegation?.type === AST_NODE_TYPES99.UnaryExpression && maybeNegation.operator === "!";
|
|
21693
21819
|
const test = negated ? maybeNegation : comparison;
|
|
21694
21820
|
const branch = test.parent;
|
|
21695
|
-
return branch?.type ===
|
|
21821
|
+
return branch?.type === AST_NODE_TYPES99.IfStatement && branch.test === test ? { branch, positive: !negated } : null;
|
|
21696
21822
|
};
|
|
21697
21823
|
const useDominatedByNarrowing = (use, narrowings) => narrowings.some(({ branch, positive }) => {
|
|
21698
21824
|
if (positive) return isDescendantOf(use, branch.consequent);
|
|
@@ -21712,7 +21838,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
21712
21838
|
const variable = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
21713
21839
|
if (variable === void 0) return false;
|
|
21714
21840
|
const references = variable.references.filter((reference) => !reference.isWriteOnly()).map((reference) => reference.identifier).filter(
|
|
21715
|
-
(identifier) => identifier.type ===
|
|
21841
|
+
(identifier) => identifier.type === AST_NODE_TYPES99.Identifier
|
|
21716
21842
|
);
|
|
21717
21843
|
if (references.length === 0) return false;
|
|
21718
21844
|
const narrowings = references.map(narrowingIf).filter(
|
|
@@ -21738,7 +21864,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
21738
21864
|
ImportDeclaration(node) {
|
|
21739
21865
|
if (!isZodModule(node.source.value)) return;
|
|
21740
21866
|
for (const specifier of node.specifiers) {
|
|
21741
|
-
if (specifier.type ===
|
|
21867
|
+
if (specifier.type === AST_NODE_TYPES99.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES99.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES99.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES99.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
21742
21868
|
const binding = resolvedBinding(specifier.local);
|
|
21743
21869
|
if (binding !== null) zodBindings.add(binding);
|
|
21744
21870
|
}
|
|
@@ -21827,7 +21953,7 @@ function expressionCallableName(current) {
|
|
|
21827
21953
|
}
|
|
21828
21954
|
|
|
21829
21955
|
// src/rules/stepdown.ts
|
|
21830
|
-
import { AST_NODE_TYPES as
|
|
21956
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES100, ASTUtils as ASTUtils51 } from "@typescript-eslint/utils";
|
|
21831
21957
|
var STEPDOWN_DOCUMENTATION = {
|
|
21832
21958
|
summary: "Place a private helper below its sole direct same-scope caller.",
|
|
21833
21959
|
rationale: "Caller-first ordering lets a reader follow the main flow before descending into implementation details.",
|
|
@@ -21845,7 +21971,7 @@ var STEPDOWN_DOCUMENTATION = {
|
|
|
21845
21971
|
]
|
|
21846
21972
|
};
|
|
21847
21973
|
function isFunction(node) {
|
|
21848
|
-
return node.type ===
|
|
21974
|
+
return node.type === AST_NODE_TYPES100.ArrowFunctionExpression || node.type === AST_NODE_TYPES100.FunctionDeclaration || node.type === AST_NODE_TYPES100.FunctionExpression;
|
|
21849
21975
|
}
|
|
21850
21976
|
function reportMisordered(context, candidates, scopeDefinitions, calls, pinned, canMove = () => true) {
|
|
21851
21977
|
const byName = new Map(scopeDefinitions.map((definition) => [definition.name, definition]));
|
|
@@ -21946,8 +22072,8 @@ function moduleScope(context, program) {
|
|
|
21946
22072
|
for (const node of declarations) counts.set(node.name, (counts.get(node.name) ?? 0) + 1);
|
|
21947
22073
|
const overloadNames = new Set(
|
|
21948
22074
|
program.body.flatMap((statement) => {
|
|
21949
|
-
const node = statement.type ===
|
|
21950
|
-
return node?.type ===
|
|
22075
|
+
const node = statement.type === AST_NODE_TYPES100.ExportNamedDeclaration ? statement.declaration : statement;
|
|
22076
|
+
return node?.type === AST_NODE_TYPES100.TSDeclareFunction && node.id !== null ? [node.id.name] : [];
|
|
21951
22077
|
})
|
|
21952
22078
|
);
|
|
21953
22079
|
const exported = exportedNames(program);
|
|
@@ -21971,7 +22097,7 @@ function moduleScope(context, program) {
|
|
|
21971
22097
|
const nearestFunction2 = [...ancestors].reverse().find(isFunction);
|
|
21972
22098
|
const parent = identifier.parent;
|
|
21973
22099
|
const callerDefinition = nearestFunction2 === void 0 ? void 0 : byFunction.get(nearestFunction2);
|
|
21974
|
-
if (callerDefinition === void 0 || parent.type !==
|
|
22100
|
+
if (callerDefinition === void 0 || parent.type !== AST_NODE_TYPES100.CallExpression || parent.callee !== identifier) {
|
|
21975
22101
|
pinned.add(definition.name);
|
|
21976
22102
|
continue;
|
|
21977
22103
|
}
|
|
@@ -21986,17 +22112,17 @@ function moduleScope(context, program) {
|
|
|
21986
22112
|
function exportedNames(program) {
|
|
21987
22113
|
const names = /* @__PURE__ */ new Set();
|
|
21988
22114
|
function collectNamedExports(statement) {
|
|
21989
|
-
if (statement.type !==
|
|
21990
|
-
if (statement.declaration?.type ===
|
|
22115
|
+
if (statement.type !== AST_NODE_TYPES100.ExportNamedDeclaration || statement.exportKind === "type" || statement.source !== null) return;
|
|
22116
|
+
if (statement.declaration?.type === AST_NODE_TYPES100.FunctionDeclaration && statement.declaration.id !== null) {
|
|
21991
22117
|
names.add(statement.declaration.id.name);
|
|
21992
22118
|
}
|
|
21993
|
-
if (statement.declaration?.type ===
|
|
22119
|
+
if (statement.declaration?.type === AST_NODE_TYPES100.VariableDeclaration) {
|
|
21994
22120
|
for (const declarator of statement.declaration.declarations) {
|
|
21995
|
-
if (declarator.id.type ===
|
|
22121
|
+
if (declarator.id.type === AST_NODE_TYPES100.Identifier) names.add(declarator.id.name);
|
|
21996
22122
|
}
|
|
21997
22123
|
}
|
|
21998
22124
|
for (const specifier of statement.specifiers) {
|
|
21999
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
22125
|
+
if (specifier.exportKind !== "type" && specifier.local.type === AST_NODE_TYPES100.Identifier) {
|
|
22000
22126
|
names.add(specifier.local.name);
|
|
22001
22127
|
}
|
|
22002
22128
|
}
|
|
@@ -22005,22 +22131,22 @@ function exportedNames(program) {
|
|
|
22005
22131
|
collectNamedExports(statement);
|
|
22006
22132
|
}
|
|
22007
22133
|
for (const statement of program.body) {
|
|
22008
|
-
if (statement.type ===
|
|
22009
|
-
if (statement.type ===
|
|
22134
|
+
if (statement.type === AST_NODE_TYPES100.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES100.Identifier) names.add(statement.declaration.name);
|
|
22135
|
+
if (statement.type === AST_NODE_TYPES100.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES100.FunctionDeclaration && statement.declaration.id !== null) names.add(statement.declaration.id.name);
|
|
22010
22136
|
}
|
|
22011
22137
|
return names;
|
|
22012
22138
|
}
|
|
22013
22139
|
function moduleDefinitions(program) {
|
|
22014
22140
|
const definitions = [];
|
|
22015
22141
|
for (const statement of program.body) {
|
|
22016
|
-
const node = statement.type ===
|
|
22017
|
-
if (node?.type ===
|
|
22142
|
+
const node = statement.type === AST_NODE_TYPES100.ExportNamedDeclaration || statement.type === AST_NODE_TYPES100.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
22143
|
+
if (node?.type === AST_NODE_TYPES100.FunctionDeclaration && node.id !== null && node.body !== null) {
|
|
22018
22144
|
definitions.push({ name: node.id.name, node, functionNode: node, bindingNode: node });
|
|
22019
22145
|
continue;
|
|
22020
22146
|
}
|
|
22021
|
-
if (node?.type !==
|
|
22147
|
+
if (node?.type !== AST_NODE_TYPES100.VariableDeclaration || node.kind !== "const") continue;
|
|
22022
22148
|
for (const declarator of node.declarations) {
|
|
22023
|
-
if (declarator.id.type ===
|
|
22149
|
+
if (declarator.id.type === AST_NODE_TYPES100.Identifier && declarator.init !== null && isFunction(declarator.init)) {
|
|
22024
22150
|
definitions.push({
|
|
22025
22151
|
name: declarator.id.name,
|
|
22026
22152
|
node: declarator,
|
|
@@ -22033,21 +22159,21 @@ function moduleDefinitions(program) {
|
|
|
22033
22159
|
return definitions;
|
|
22034
22160
|
}
|
|
22035
22161
|
function methodName2(node) {
|
|
22036
|
-
if (node.key.type ===
|
|
22037
|
-
return !node.computed && node.key.type ===
|
|
22162
|
+
if (node.key.type === AST_NODE_TYPES100.PrivateIdentifier) return `#${node.key.name}`;
|
|
22163
|
+
return !node.computed && node.key.type === AST_NODE_TYPES100.Identifier ? node.key.name : null;
|
|
22038
22164
|
}
|
|
22039
22165
|
function referencedMethod(context, node, classVariables) {
|
|
22040
|
-
const objectVariable = node.object.type ===
|
|
22166
|
+
const objectVariable = node.object.type === AST_NODE_TYPES100.Identifier ? ASTUtils51.findVariable(context.sourceCode.getScope(node.object), node.object.name) : null;
|
|
22041
22167
|
const isClassReference = objectVariable !== null && classVariables.has(objectVariable);
|
|
22042
|
-
if (node.object.type !==
|
|
22043
|
-
if (node.property.type ===
|
|
22044
|
-
if (!node.computed && node.property.type ===
|
|
22045
|
-
return node.computed && node.property.type ===
|
|
22168
|
+
if (node.object.type !== AST_NODE_TYPES100.ThisExpression && !isClassReference) return null;
|
|
22169
|
+
if (node.property.type === AST_NODE_TYPES100.PrivateIdentifier) return `#${node.property.name}`;
|
|
22170
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES100.Identifier) return node.property.name;
|
|
22171
|
+
return node.computed && node.property.type === AST_NODE_TYPES100.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
22046
22172
|
}
|
|
22047
22173
|
function referencedPropertyName(node) {
|
|
22048
|
-
if (node.property.type ===
|
|
22049
|
-
if (!node.computed && node.property.type ===
|
|
22050
|
-
return node.computed && node.property.type ===
|
|
22174
|
+
if (node.property.type === AST_NODE_TYPES100.PrivateIdentifier) return `#${node.property.name}`;
|
|
22175
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES100.Identifier) return node.property.name;
|
|
22176
|
+
return node.computed && node.property.type === AST_NODE_TYPES100.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
22051
22177
|
}
|
|
22052
22178
|
function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
22053
22179
|
visit(node, nestedFunction);
|
|
@@ -22056,7 +22182,7 @@ function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
|
22056
22182
|
}
|
|
22057
22183
|
function classScope(context, node, computedReferenceNames) {
|
|
22058
22184
|
const methods = node.body.body.filter(
|
|
22059
|
-
(member) => member.type ===
|
|
22185
|
+
(member) => member.type === AST_NODE_TYPES100.MethodDefinition
|
|
22060
22186
|
);
|
|
22061
22187
|
const counts = classMethodCounts(node.body, methods);
|
|
22062
22188
|
const scopeDefinitions = methods.flatMap((method) => {
|
|
@@ -22065,7 +22191,7 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
22065
22191
|
});
|
|
22066
22192
|
const definitions = methods.flatMap((method) => {
|
|
22067
22193
|
const name = methodName2(method);
|
|
22068
|
-
const isPrivate = method.accessibility === "private" || method.key.type ===
|
|
22194
|
+
const isPrivate = method.accessibility === "private" || method.key.type === AST_NODE_TYPES100.PrivateIdentifier;
|
|
22069
22195
|
return name !== null && isPrivate && counts.get(name) === 1 && method.decorators.length === 0 ? [{ name, node: method }] : [];
|
|
22070
22196
|
});
|
|
22071
22197
|
if (definitions.length === 0) return;
|
|
@@ -22074,11 +22200,11 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
22074
22200
|
const pinned = /* @__PURE__ */ new Set();
|
|
22075
22201
|
const classVariables = /* @__PURE__ */ new Set();
|
|
22076
22202
|
if (node.id !== null) {
|
|
22077
|
-
const internal =
|
|
22203
|
+
const internal = ASTUtils51.findVariable(context.sourceCode.getScope(node), node.id.name);
|
|
22078
22204
|
if (internal !== null) classVariables.add(internal);
|
|
22079
22205
|
}
|
|
22080
|
-
if (node.type ===
|
|
22081
|
-
const outer =
|
|
22206
|
+
if (node.type === AST_NODE_TYPES100.ClassExpression && node.parent.type === AST_NODE_TYPES100.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES100.Identifier) {
|
|
22207
|
+
const outer = ASTUtils51.findVariable(context.sourceCode.getScope(node.parent), node.parent.id.name);
|
|
22082
22208
|
if (outer !== null) classVariables.add(outer);
|
|
22083
22209
|
}
|
|
22084
22210
|
function collectMethodCalls(method) {
|
|
@@ -22094,21 +22220,21 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
22094
22220
|
}
|
|
22095
22221
|
const thisValue = (value) => {
|
|
22096
22222
|
let current = value;
|
|
22097
|
-
while (current?.type ===
|
|
22098
|
-
return current?.type ===
|
|
22223
|
+
while (current?.type === AST_NODE_TYPES100.TSAsExpression || current?.type === AST_NODE_TYPES100.TSSatisfiesExpression || current?.type === AST_NODE_TYPES100.TSNonNullExpression) current = current.expression;
|
|
22224
|
+
return current?.type === AST_NODE_TYPES100.ThisExpression;
|
|
22099
22225
|
};
|
|
22100
22226
|
const collectAlias = (current, nestedFunction) => {
|
|
22101
|
-
if (nestedFunction || current.type !==
|
|
22102
|
-
if (current.type ===
|
|
22103
|
-
const binding = current.type ===
|
|
22104
|
-
const value = current.type ===
|
|
22227
|
+
if (nestedFunction || current.type !== AST_NODE_TYPES100.VariableDeclarator && current.type !== AST_NODE_TYPES100.AssignmentPattern) return;
|
|
22228
|
+
if (current.type === AST_NODE_TYPES100.VariableDeclarator && (current.parent.type !== AST_NODE_TYPES100.VariableDeclaration || current.parent.kind !== "const")) return;
|
|
22229
|
+
const binding = current.type === AST_NODE_TYPES100.VariableDeclarator ? current.id : current.left;
|
|
22230
|
+
const value = current.type === AST_NODE_TYPES100.VariableDeclarator ? current.init : current.right;
|
|
22105
22231
|
if (!thisValue(value)) return;
|
|
22106
|
-
if (binding.type ===
|
|
22232
|
+
if (binding.type === AST_NODE_TYPES100.ObjectPattern) {
|
|
22107
22233
|
pinDestructuredMembers(binding);
|
|
22108
22234
|
return;
|
|
22109
22235
|
}
|
|
22110
|
-
if (binding.type !==
|
|
22111
|
-
const variable =
|
|
22236
|
+
if (binding.type !== AST_NODE_TYPES100.Identifier) return;
|
|
22237
|
+
const variable = ASTUtils51.findVariable(context.sourceCode.getScope(binding), binding.name);
|
|
22112
22238
|
if (variable !== null) {
|
|
22113
22239
|
methodClassVariables.add(variable);
|
|
22114
22240
|
methodAliases.add(variable);
|
|
@@ -22122,18 +22248,18 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
22122
22248
|
}
|
|
22123
22249
|
function pinDestructuredMembers(binding) {
|
|
22124
22250
|
for (const property of binding.properties) {
|
|
22125
|
-
if (property.type ===
|
|
22251
|
+
if (property.type === AST_NODE_TYPES100.RestElement) {
|
|
22126
22252
|
for (const name of privateNames) pinned.add(name);
|
|
22127
|
-
} else if (property.key.type ===
|
|
22253
|
+
} else if (property.key.type === AST_NODE_TYPES100.Identifier && privateNames.has(property.key.name)) {
|
|
22128
22254
|
pinned.add(property.key.name);
|
|
22129
22255
|
}
|
|
22130
22256
|
}
|
|
22131
22257
|
}
|
|
22132
22258
|
const visitCall = (current, nestedFunction) => {
|
|
22133
|
-
if (current.type ===
|
|
22259
|
+
if (current.type === AST_NODE_TYPES100.VariableDeclarator && current.id.type === AST_NODE_TYPES100.ObjectPattern && thisValue(current.init)) {
|
|
22134
22260
|
pinDestructuredMembers(current.id);
|
|
22135
22261
|
}
|
|
22136
|
-
if (current.type !==
|
|
22262
|
+
if (current.type !== AST_NODE_TYPES100.MemberExpression) return;
|
|
22137
22263
|
const target = referencedMethod(context, current, methodClassVariables);
|
|
22138
22264
|
if (target === null) {
|
|
22139
22265
|
const possibleTarget = referencedPropertyName(current);
|
|
@@ -22141,12 +22267,12 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
22141
22267
|
return;
|
|
22142
22268
|
}
|
|
22143
22269
|
if (!privateNames.has(target)) return;
|
|
22144
|
-
const objectVariable = current.object.type ===
|
|
22270
|
+
const objectVariable = current.object.type === AST_NODE_TYPES100.Identifier ? ASTUtils51.findVariable(context.sourceCode.getScope(current.object), current.object.name) : null;
|
|
22145
22271
|
if (objectVariable !== null && methodAliases.has(objectVariable)) {
|
|
22146
22272
|
pinned.add(target);
|
|
22147
22273
|
return;
|
|
22148
22274
|
}
|
|
22149
|
-
if (current.computed || nestedFunction || parameterDecoratorNodes.has(current) || current.parent.type !==
|
|
22275
|
+
if (current.computed || nestedFunction || parameterDecoratorNodes.has(current) || current.parent.type !== AST_NODE_TYPES100.CallExpression || current.parent.callee !== current) {
|
|
22150
22276
|
pinned.add(target);
|
|
22151
22277
|
return;
|
|
22152
22278
|
}
|
|
@@ -22167,9 +22293,9 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
22167
22293
|
}
|
|
22168
22294
|
for (const method of methods) collectMethodCalls(method);
|
|
22169
22295
|
for (const member of node.body.body) {
|
|
22170
|
-
if (member.type ===
|
|
22296
|
+
if (member.type === AST_NODE_TYPES100.MethodDefinition || member.type === AST_NODE_TYPES100.TSAbstractMethodDefinition) continue;
|
|
22171
22297
|
walk(member, context.sourceCode.visitorKeys, (current) => {
|
|
22172
|
-
if (current.type !==
|
|
22298
|
+
if (current.type !== AST_NODE_TYPES100.MemberExpression) return;
|
|
22173
22299
|
const target = referencedMethod(context, current, classVariables);
|
|
22174
22300
|
const possibleTarget = target ?? referencedPropertyName(current);
|
|
22175
22301
|
if (possibleTarget !== null && privateNames.has(possibleTarget)) pinned.add(possibleTarget);
|
|
@@ -22191,12 +22317,12 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
22191
22317
|
}
|
|
22192
22318
|
function isClassRuntimeBarrier(member) {
|
|
22193
22319
|
switch (member.type) {
|
|
22194
|
-
case
|
|
22320
|
+
case AST_NODE_TYPES100.StaticBlock:
|
|
22195
22321
|
return true;
|
|
22196
|
-
case
|
|
22197
|
-
case
|
|
22322
|
+
case AST_NODE_TYPES100.PropertyDefinition:
|
|
22323
|
+
case AST_NODE_TYPES100.AccessorProperty:
|
|
22198
22324
|
return member.static || member.computed || member.decorators.length > 0 || member.value !== null;
|
|
22199
|
-
case
|
|
22325
|
+
case AST_NODE_TYPES100.MethodDefinition:
|
|
22200
22326
|
return member.computed || member.decorators.length > 0;
|
|
22201
22327
|
default:
|
|
22202
22328
|
return false;
|
|
@@ -22228,7 +22354,7 @@ var stepdown_default = createRule({
|
|
|
22228
22354
|
moduleScope(context, program);
|
|
22229
22355
|
const computedReferenceNames = /* @__PURE__ */ new Set();
|
|
22230
22356
|
walk(program, context.sourceCode.visitorKeys, (node) => {
|
|
22231
|
-
if (node.type ===
|
|
22357
|
+
if (node.type === AST_NODE_TYPES100.MemberExpression && node.computed && node.property.type === AST_NODE_TYPES100.Literal && typeof node.property.value === "string") computedReferenceNames.add(node.property.value);
|
|
22232
22358
|
});
|
|
22233
22359
|
for (const node of classes) classScope(context, node, computedReferenceNames);
|
|
22234
22360
|
}
|
|
@@ -22242,15 +22368,15 @@ function classMethodCounts(body2, methods) {
|
|
|
22242
22368
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
22243
22369
|
}
|
|
22244
22370
|
for (const member of body2.body) {
|
|
22245
|
-
if (member.type !==
|
|
22246
|
-
const name = !member.computed && member.key.type ===
|
|
22371
|
+
if (member.type !== AST_NODE_TYPES100.TSAbstractMethodDefinition) continue;
|
|
22372
|
+
const name = !member.computed && member.key.type === AST_NODE_TYPES100.Identifier ? member.key.name : null;
|
|
22247
22373
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
22248
22374
|
}
|
|
22249
22375
|
return counts;
|
|
22250
22376
|
}
|
|
22251
22377
|
|
|
22252
22378
|
// src/rules/source-coupled-test.ts
|
|
22253
|
-
import { AST_NODE_TYPES as
|
|
22379
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES101, ASTUtils as ASTUtils52 } from "@typescript-eslint/utils";
|
|
22254
22380
|
var GENERAL_SOURCE_SUFFIX_RE = /\.(?:bash|sh|ya?ml|jsonc?|toml|py|[cm]?[jt]s)$/iu;
|
|
22255
22381
|
var FS_MODULES = /* @__PURE__ */ new Set(["fs", "node:fs", "fs/promises", "node:fs/promises"]);
|
|
22256
22382
|
var FS_READERS = /* @__PURE__ */ new Set(["readFile", "readFileSync"]);
|
|
@@ -22322,21 +22448,21 @@ var SOURCE_COUPLED_TEST_DOCUMENTATION = {
|
|
|
22322
22448
|
]
|
|
22323
22449
|
};
|
|
22324
22450
|
function staticMemberName8(node) {
|
|
22325
|
-
if (!node.computed && node.property.type ===
|
|
22326
|
-
if (node.computed && node.property.type ===
|
|
22451
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES101.Identifier) return node.property.name;
|
|
22452
|
+
if (node.computed && node.property.type === AST_NODE_TYPES101.Literal && typeof node.property.value === "string") return node.property.value;
|
|
22327
22453
|
return null;
|
|
22328
22454
|
}
|
|
22329
22455
|
function unwrap7(node) {
|
|
22330
|
-
if (node.type ===
|
|
22331
|
-
if (node.type ===
|
|
22332
|
-
if (node.type ===
|
|
22456
|
+
if (node.type === AST_NODE_TYPES101.AwaitExpression) return unwrap7(node.argument);
|
|
22457
|
+
if (node.type === AST_NODE_TYPES101.ChainExpression) return unwrap7(node.expression);
|
|
22458
|
+
if (node.type === AST_NODE_TYPES101.TSAsExpression || node.type === AST_NODE_TYPES101.TSNonNullExpression || node.type === AST_NODE_TYPES101.TSTypeAssertion) return unwrap7(node.expression);
|
|
22333
22459
|
return node;
|
|
22334
22460
|
}
|
|
22335
22461
|
function stringValue(node) {
|
|
22336
22462
|
const current = unwrap7(node);
|
|
22337
|
-
if (current.type ===
|
|
22338
|
-
if (current.type ===
|
|
22339
|
-
if (current.type ===
|
|
22463
|
+
if (current.type === AST_NODE_TYPES101.Literal && typeof current.value === "string") return current.value;
|
|
22464
|
+
if (current.type === AST_NODE_TYPES101.TemplateLiteral && current.expressions.length === 0) return current.quasis[0]?.value.cooked ?? null;
|
|
22465
|
+
if (current.type === AST_NODE_TYPES101.BinaryExpression && current.operator === "+") {
|
|
22340
22466
|
const left = stringValue(current.left);
|
|
22341
22467
|
const right = stringValue(current.right);
|
|
22342
22468
|
return left === null || right === null ? null : left + right;
|
|
@@ -22348,7 +22474,7 @@ function importSource(node) {
|
|
|
22348
22474
|
}
|
|
22349
22475
|
function requireSource(node) {
|
|
22350
22476
|
const current = unwrap7(node);
|
|
22351
|
-
if (current.type !==
|
|
22477
|
+
if (current.type !== AST_NODE_TYPES101.CallExpression || current.callee.type !== AST_NODE_TYPES101.Identifier || current.callee.name !== "require" || current.arguments.length !== 1 || current.arguments[0]?.type === AST_NODE_TYPES101.SpreadElement) return null;
|
|
22352
22478
|
return stringValue(current.arguments[0]);
|
|
22353
22479
|
}
|
|
22354
22480
|
function newScope() {
|
|
@@ -22370,7 +22496,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
22370
22496
|
const scopes = [newScope()];
|
|
22371
22497
|
const reportedOrigins = /* @__PURE__ */ new Set();
|
|
22372
22498
|
const currentScope = () => scopes.at(-1) ?? scopes[0];
|
|
22373
|
-
const bindingOf = (node) =>
|
|
22499
|
+
const bindingOf = (node) => ASTUtils52.findVariable(context.sourceCode.getScope(node), node.name);
|
|
22374
22500
|
const assertionKind = (node) => {
|
|
22375
22501
|
const binding = bindingOf(node);
|
|
22376
22502
|
if (binding === null || binding.defs.length === 0) {
|
|
@@ -22404,37 +22530,37 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
22404
22530
|
const current = unwrap7(node);
|
|
22405
22531
|
const value = stringValue(current);
|
|
22406
22532
|
if (value !== null) return sourceSuffixRe.test(value);
|
|
22407
|
-
if (current.type ===
|
|
22408
|
-
if (current.type ===
|
|
22533
|
+
if (current.type === AST_NODE_TYPES101.Identifier) return visible("paths", current);
|
|
22534
|
+
if (current.type === AST_NODE_TYPES101.CallExpression || current.type === AST_NODE_TYPES101.NewExpression) {
|
|
22409
22535
|
const callee = current.callee;
|
|
22410
22536
|
const first = current.arguments[0];
|
|
22411
|
-
if (first === void 0 || first.type ===
|
|
22412
|
-
if (current.type ===
|
|
22413
|
-
if (callee.type ===
|
|
22537
|
+
if (first === void 0 || first.type === AST_NODE_TYPES101.SpreadElement) return false;
|
|
22538
|
+
if (current.type === AST_NODE_TYPES101.NewExpression && callee.type === AST_NODE_TYPES101.Identifier && callee.name === "URL" && (bindingOf(callee)?.defs.length ?? 0) === 0) return sourcePath(first);
|
|
22539
|
+
if (callee.type === AST_NODE_TYPES101.Identifier && bindingOf(callee)?.defs.some((definition) => definition.node.type === AST_NODE_TYPES101.ImportSpecifier && definition.node.imported.type === AST_NODE_TYPES101.Identifier && definition.node.imported.name === "fileURLToPath" && definition.node.parent.type === AST_NODE_TYPES101.ImportDeclaration && ["node:url", "url"].includes(String(definition.node.parent.source.value)))) return sourcePath(first);
|
|
22414
22540
|
}
|
|
22415
22541
|
return false;
|
|
22416
22542
|
};
|
|
22417
22543
|
const rawRead = (node) => {
|
|
22418
22544
|
const current = unwrap7(node);
|
|
22419
|
-
if (current.type !==
|
|
22545
|
+
if (current.type !== AST_NODE_TYPES101.CallExpression || current.arguments.length === 0) return false;
|
|
22420
22546
|
const callee = unwrap7(current.callee);
|
|
22421
|
-
if (callee.type ===
|
|
22547
|
+
if (callee.type === AST_NODE_TYPES101.Identifier) {
|
|
22422
22548
|
return visible("fsReaders", callee) && sourcePath(current.arguments[0]);
|
|
22423
22549
|
}
|
|
22424
|
-
if (callee.type !==
|
|
22550
|
+
if (callee.type !== AST_NODE_TYPES101.MemberExpression) return false;
|
|
22425
22551
|
const name2 = staticMemberName8(callee);
|
|
22426
22552
|
const object = unwrap7(callee.object);
|
|
22427
|
-
return name2 !== null && FS_READERS.has(name2) && object.type ===
|
|
22553
|
+
return name2 !== null && FS_READERS.has(name2) && object.type === AST_NODE_TYPES101.Identifier && visible("fsObjects", object) && sourcePath(current.arguments[0]);
|
|
22428
22554
|
};
|
|
22429
22555
|
const rawOrigins = (node) => {
|
|
22430
22556
|
const current = unwrap7(node);
|
|
22431
|
-
if (current.type ===
|
|
22557
|
+
if (current.type === AST_NODE_TYPES101.Identifier) return visibleRawOrigins(current);
|
|
22432
22558
|
if (rawRead(current)) return /* @__PURE__ */ new Set([`${current.range[0]}:${current.range[1]}`]);
|
|
22433
|
-
if (current.type ===
|
|
22434
|
-
if (current.type ===
|
|
22435
|
-
if (current.type !==
|
|
22559
|
+
if (current.type === AST_NODE_TYPES101.BinaryExpression && current.operator === "+") return /* @__PURE__ */ new Set([...rawOrigins(current.left), ...rawOrigins(current.right)]);
|
|
22560
|
+
if (current.type === AST_NODE_TYPES101.MemberExpression && staticMemberName8(current) === "length") return rawOrigins(current.object);
|
|
22561
|
+
if (current.type !== AST_NODE_TYPES101.CallExpression) return /* @__PURE__ */ new Set();
|
|
22436
22562
|
const callee = unwrap7(current.callee);
|
|
22437
|
-
if (callee.type !==
|
|
22563
|
+
if (callee.type !== AST_NODE_TYPES101.MemberExpression) return /* @__PURE__ */ new Set();
|
|
22438
22564
|
const name2 = staticMemberName8(callee);
|
|
22439
22565
|
return name2 !== null && TEXT_TRANSFORMS.has(name2) ? rawOrigins(callee.object) : /* @__PURE__ */ new Set();
|
|
22440
22566
|
};
|
|
@@ -22442,32 +22568,32 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
22442
22568
|
const current = unwrap7(node);
|
|
22443
22569
|
const direct = rawOrigins(current);
|
|
22444
22570
|
if (direct.size > 0) return direct;
|
|
22445
|
-
if (current.type ===
|
|
22446
|
-
if (current.type ===
|
|
22447
|
-
if (current.type !==
|
|
22571
|
+
if (current.type === AST_NODE_TYPES101.BinaryExpression || current.type === AST_NODE_TYPES101.LogicalExpression) return /* @__PURE__ */ new Set([...evidenceOrigins(current.left), ...evidenceOrigins(current.right)]);
|
|
22572
|
+
if (current.type === AST_NODE_TYPES101.UnaryExpression) return evidenceOrigins(current.argument);
|
|
22573
|
+
if (current.type !== AST_NODE_TYPES101.CallExpression) return /* @__PURE__ */ new Set();
|
|
22448
22574
|
const callee = unwrap7(current.callee);
|
|
22449
|
-
if (callee.type !==
|
|
22575
|
+
if (callee.type !== AST_NODE_TYPES101.MemberExpression) return /* @__PURE__ */ new Set();
|
|
22450
22576
|
const name2 = staticMemberName8(callee);
|
|
22451
22577
|
if (name2 !== null && TEXT_PREDICATES.has(name2)) return rawOrigins(callee.object);
|
|
22452
|
-
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type ===
|
|
22578
|
+
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES101.SpreadElement ? [] : [...rawOrigins(argument)]));
|
|
22453
22579
|
return /* @__PURE__ */ new Set();
|
|
22454
22580
|
};
|
|
22455
22581
|
const rawAssertionOrigins = (node) => {
|
|
22456
22582
|
const callee = unwrap7(node.callee);
|
|
22457
|
-
if (callee.type ===
|
|
22458
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
22583
|
+
if (callee.type === AST_NODE_TYPES101.Identifier && assertionKind(callee) === "assert") {
|
|
22584
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES101.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
22459
22585
|
}
|
|
22460
|
-
if (callee.type !==
|
|
22586
|
+
if (callee.type !== AST_NODE_TYPES101.MemberExpression) return /* @__PURE__ */ new Set();
|
|
22461
22587
|
const matcher = staticMemberName8(callee);
|
|
22462
22588
|
if (matcher === null) return /* @__PURE__ */ new Set();
|
|
22463
22589
|
let receiver = unwrap7(callee.object);
|
|
22464
|
-
while (receiver.type ===
|
|
22465
|
-
if (receiver.type ===
|
|
22590
|
+
while (receiver.type === AST_NODE_TYPES101.MemberExpression && EXPECT_MODIFIERS2.has(staticMemberName8(receiver) ?? "")) receiver = unwrap7(receiver.object);
|
|
22591
|
+
if (receiver.type === AST_NODE_TYPES101.CallExpression && receiver.callee.type === AST_NODE_TYPES101.Identifier && assertionKind(receiver.callee) === "expect") {
|
|
22466
22592
|
if (!EXPECT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
22467
|
-
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type ===
|
|
22593
|
+
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type === AST_NODE_TYPES101.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
22468
22594
|
}
|
|
22469
|
-
if (receiver.type !==
|
|
22470
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
22595
|
+
if (receiver.type !== AST_NODE_TYPES101.Identifier || assertionKind(receiver) !== "assert" || !ASSERT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
22596
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES101.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
22471
22597
|
};
|
|
22472
22598
|
const declare = (node, state) => {
|
|
22473
22599
|
const name2 = bindingOf(node);
|
|
@@ -22489,7 +22615,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
22489
22615
|
};
|
|
22490
22616
|
const sourceCollection = (node) => {
|
|
22491
22617
|
const current = unwrap7(node);
|
|
22492
|
-
return current.type ===
|
|
22618
|
+
return current.type === AST_NODE_TYPES101.ArrayExpression && current.elements.length > 0 && current.elements.every((element) => element !== null && element.type !== AST_NODE_TYPES101.SpreadElement && sourcePath(element));
|
|
22493
22619
|
};
|
|
22494
22620
|
const enterFunction = () => {
|
|
22495
22621
|
scopes.push(newScope());
|
|
@@ -22499,8 +22625,8 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
22499
22625
|
};
|
|
22500
22626
|
function declareFsReaders(pattern) {
|
|
22501
22627
|
for (const property of pattern.properties) {
|
|
22502
|
-
if (property.type !==
|
|
22503
|
-
const key = property.key.type ===
|
|
22628
|
+
if (property.type !== AST_NODE_TYPES101.Property || property.value.type !== AST_NODE_TYPES101.Identifier) continue;
|
|
22629
|
+
const key = property.key.type === AST_NODE_TYPES101.Identifier ? property.key.name : property.key.type === AST_NODE_TYPES101.Literal ? String(property.key.value) : "";
|
|
22504
22630
|
if (FS_READERS.has(key)) declare(property.value, { fsReader: true });
|
|
22505
22631
|
}
|
|
22506
22632
|
}
|
|
@@ -22509,8 +22635,8 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
22509
22635
|
const source = importSource(node);
|
|
22510
22636
|
if (source === null || !FS_MODULES.has(source)) return;
|
|
22511
22637
|
for (const specifier of node.specifiers) {
|
|
22512
|
-
if (specifier.type ===
|
|
22513
|
-
const imported = specifier.imported.type ===
|
|
22638
|
+
if (specifier.type === AST_NODE_TYPES101.ImportSpecifier) {
|
|
22639
|
+
const imported = specifier.imported.type === AST_NODE_TYPES101.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
22514
22640
|
if (FS_READERS.has(imported)) declare(specifier.local, { fsReader: true });
|
|
22515
22641
|
} else {
|
|
22516
22642
|
declare(specifier.local, { fsObject: true });
|
|
@@ -22523,26 +22649,26 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
22523
22649
|
if (node.init === null) return;
|
|
22524
22650
|
const required = requireSource(node.init);
|
|
22525
22651
|
const initializer = unwrap7(node.init);
|
|
22526
|
-
if (required !== null && initializer.type ===
|
|
22527
|
-
if (required !== null && FS_MODULES.has(required) && node.id.type ===
|
|
22652
|
+
if (required !== null && initializer.type === AST_NODE_TYPES101.CallExpression && initializer.callee.type === AST_NODE_TYPES101.Identifier && (bindingOf(initializer.callee)?.defs.length ?? 0) > 0) return;
|
|
22653
|
+
if (required !== null && FS_MODULES.has(required) && node.id.type === AST_NODE_TYPES101.Identifier) {
|
|
22528
22654
|
declare(node.id, { fsObject: true });
|
|
22529
22655
|
return;
|
|
22530
22656
|
}
|
|
22531
|
-
if (node.id.type ===
|
|
22657
|
+
if (node.id.type === AST_NODE_TYPES101.ObjectPattern && required !== null && FS_MODULES.has(required)) {
|
|
22532
22658
|
declareFsReaders(node.id);
|
|
22533
22659
|
return;
|
|
22534
22660
|
}
|
|
22535
|
-
if (node.id.type !==
|
|
22661
|
+
if (node.id.type !== AST_NODE_TYPES101.Identifier) return;
|
|
22536
22662
|
declare(node.id, { collection: sourceCollection(node.init), path: sourcePath(node.init), rawOrigins: rawOrigins(node.init) });
|
|
22537
22663
|
},
|
|
22538
22664
|
AssignmentExpression(node) {
|
|
22539
|
-
if (node.left.type ===
|
|
22665
|
+
if (node.left.type === AST_NODE_TYPES101.Identifier) declare(node.left, {});
|
|
22540
22666
|
},
|
|
22541
22667
|
ForOfStatement(node) {
|
|
22542
22668
|
const right = unwrap7(node.right);
|
|
22543
|
-
const collection = right.type ===
|
|
22544
|
-
const left = node.left.type ===
|
|
22545
|
-
if (collection && left?.type ===
|
|
22669
|
+
const collection = right.type === AST_NODE_TYPES101.Identifier && visible("collections", right);
|
|
22670
|
+
const left = node.left.type === AST_NODE_TYPES101.VariableDeclaration ? node.left.declarations[0]?.id : node.left;
|
|
22671
|
+
if (collection && left?.type === AST_NODE_TYPES101.Identifier) declare(left, { path: true });
|
|
22546
22672
|
},
|
|
22547
22673
|
CallExpression(node) {
|
|
22548
22674
|
const origins = rawAssertionOrigins(node);
|
|
@@ -22560,22 +22686,22 @@ var source_coupled_test_default = createSourceCoupledRule(
|
|
|
22560
22686
|
GENERAL_SOURCE_SUFFIX_RE
|
|
22561
22687
|
);
|
|
22562
22688
|
function importedAssertionKind(specifier) {
|
|
22563
|
-
if (specifier.type !==
|
|
22689
|
+
if (specifier.type !== AST_NODE_TYPES101.ImportSpecifier && specifier.type !== AST_NODE_TYPES101.ImportDefaultSpecifier && specifier.type !== AST_NODE_TYPES101.ImportNamespaceSpecifier || specifier.parent.type !== AST_NODE_TYPES101.ImportDeclaration) return null;
|
|
22564
22690
|
const source = importSource(specifier.parent);
|
|
22565
22691
|
if (source !== null && ASSERT_MODULES.has(source)) {
|
|
22566
|
-
if (specifier.type !==
|
|
22567
|
-
const imported2 = specifier.imported.type ===
|
|
22692
|
+
if (specifier.type !== AST_NODE_TYPES101.ImportSpecifier) return "assert";
|
|
22693
|
+
const imported2 = specifier.imported.type === AST_NODE_TYPES101.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
22568
22694
|
if (imported2 === "strict" || ASSERT_MATCHERS.has(imported2)) return "assert";
|
|
22569
22695
|
return null;
|
|
22570
22696
|
}
|
|
22571
|
-
if (source === null || !EXPECT_MODULES.has(source) || specifier.type !==
|
|
22572
|
-
const imported = specifier.imported.type ===
|
|
22697
|
+
if (source === null || !EXPECT_MODULES.has(source) || specifier.type !== AST_NODE_TYPES101.ImportSpecifier) return null;
|
|
22698
|
+
const imported = specifier.imported.type === AST_NODE_TYPES101.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
22573
22699
|
if (imported === "assert" || imported === "expect") return imported;
|
|
22574
22700
|
return null;
|
|
22575
22701
|
}
|
|
22576
22702
|
|
|
22577
22703
|
// src/rules/sole-export-matches-filename.ts
|
|
22578
|
-
import { AST_NODE_TYPES as
|
|
22704
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES102 } from "@typescript-eslint/utils";
|
|
22579
22705
|
var SOLE_EXPORT_MATCHES_FILENAME_DOCUMENTATION = {
|
|
22580
22706
|
defaultLevel: "warning",
|
|
22581
22707
|
summary: "Make a module filename reflect its sole named public runtime export.",
|
|
@@ -22656,10 +22782,10 @@ function reflectsExportName(fileStem, exportedStem) {
|
|
|
22656
22782
|
function declarationExport(statement) {
|
|
22657
22783
|
const declaration = statement.declaration;
|
|
22658
22784
|
if (declaration === null || declaration.declare === true) return [];
|
|
22659
|
-
if (declaration.type ===
|
|
22660
|
-
if (declaration.type !==
|
|
22785
|
+
if (declaration.type === AST_NODE_TYPES102.ClassDeclaration || declaration.type === AST_NODE_TYPES102.FunctionDeclaration || declaration.type === AST_NODE_TYPES102.TSEnumDeclaration) return declaration.id === null ? [] : [{ name: declaration.id.name, node: declaration }];
|
|
22786
|
+
if (declaration.type !== AST_NODE_TYPES102.VariableDeclaration) return [];
|
|
22661
22787
|
return declaration.declarations.flatMap(
|
|
22662
|
-
(item) => item.id.type ===
|
|
22788
|
+
(item) => item.id.type === AST_NODE_TYPES102.Identifier ? [{ name: item.id.name, node: item }] : []
|
|
22663
22789
|
);
|
|
22664
22790
|
}
|
|
22665
22791
|
var sole_export_matches_filename_default = createRule({
|
|
@@ -22683,29 +22809,29 @@ var sole_export_matches_filename_default = createRule({
|
|
|
22683
22809
|
const exports = [];
|
|
22684
22810
|
const publicExports = /* @__PURE__ */ new Set();
|
|
22685
22811
|
function collectPublicExport(statement) {
|
|
22686
|
-
if (statement.type ===
|
|
22687
|
-
if (statement.type ===
|
|
22812
|
+
if (statement.type === AST_NODE_TYPES102.ExportAllDeclaration || statement.type === AST_NODE_TYPES102.ExportNamedDeclaration && statement.source !== null) return false;
|
|
22813
|
+
if (statement.type === AST_NODE_TYPES102.ExportDefaultDeclaration) {
|
|
22688
22814
|
publicExports.add("default");
|
|
22689
22815
|
const declaration = statement.declaration;
|
|
22690
|
-
if ((declaration.type ===
|
|
22816
|
+
if ((declaration.type === AST_NODE_TYPES102.ClassDeclaration || declaration.type === AST_NODE_TYPES102.FunctionDeclaration) && declaration.id !== null) exports.push({ name: declaration.id.name, node: declaration });
|
|
22691
22817
|
else return false;
|
|
22692
22818
|
}
|
|
22693
|
-
if (statement.type !==
|
|
22819
|
+
if (statement.type !== AST_NODE_TYPES102.ExportNamedDeclaration) return true;
|
|
22694
22820
|
return collectNamedExport(statement);
|
|
22695
22821
|
}
|
|
22696
22822
|
function collectNamedExport(statement) {
|
|
22697
22823
|
const declaration = statement.declaration;
|
|
22698
|
-
if (declaration !== null && "id" in declaration && declaration.id?.type ===
|
|
22824
|
+
if (declaration !== null && "id" in declaration && declaration.id?.type === AST_NODE_TYPES102.Identifier) {
|
|
22699
22825
|
publicExports.add(declaration.id.name);
|
|
22700
22826
|
}
|
|
22701
|
-
if (declaration?.type ===
|
|
22702
|
-
if (declaration.declarations.some((item) => item.id.type !==
|
|
22827
|
+
if (declaration?.type === AST_NODE_TYPES102.VariableDeclaration) {
|
|
22828
|
+
if (declaration.declarations.some((item) => item.id.type !== AST_NODE_TYPES102.Identifier)) return false;
|
|
22703
22829
|
for (const item of declaration.declarations) {
|
|
22704
|
-
if (item.id.type ===
|
|
22830
|
+
if (item.id.type === AST_NODE_TYPES102.Identifier) publicExports.add(item.id.name);
|
|
22705
22831
|
}
|
|
22706
22832
|
}
|
|
22707
22833
|
for (const specifier of statement.specifiers) {
|
|
22708
|
-
const exported = specifier.exported.type ===
|
|
22834
|
+
const exported = specifier.exported.type === AST_NODE_TYPES102.Identifier ? specifier.exported.name : specifier.exported.value;
|
|
22709
22835
|
publicExports.add(String(exported));
|
|
22710
22836
|
}
|
|
22711
22837
|
if (statement.exportKind === "type") return true;
|
|
@@ -22715,7 +22841,7 @@ var sole_export_matches_filename_default = createRule({
|
|
|
22715
22841
|
}
|
|
22716
22842
|
function collectRuntimeSpecifiers(statement) {
|
|
22717
22843
|
for (const specifier of statement.specifiers) {
|
|
22718
|
-
const exported = specifier.exported.type ===
|
|
22844
|
+
const exported = specifier.exported.type === AST_NODE_TYPES102.Identifier ? specifier.exported.name : specifier.exported.value;
|
|
22719
22845
|
publicExports.add(String(exported));
|
|
22720
22846
|
if (specifier.exportKind === "type") continue;
|
|
22721
22847
|
if (exported === "default") exports.push({ name: specifier.local.name, node: specifier });
|
|
@@ -22730,7 +22856,7 @@ var sole_export_matches_filename_default = createRule({
|
|
|
22730
22856
|
const only = [...unique.values()][0];
|
|
22731
22857
|
if (only === void 0) return;
|
|
22732
22858
|
if (only.name === "onRouterTransitionStart" && /(?:^|\/)instrumentation-client\.[jt]s$/u.test(normalizedFilename)) return;
|
|
22733
|
-
if (only.name === "collections" && /(?:^|\/)src\/content\.config\.(?:ts|js|mjs)$/u.test(normalizedFilename) && program.body.some((statement) => statement.type ===
|
|
22859
|
+
if (only.name === "collections" && /(?:^|\/)src\/content\.config\.(?:ts|js|mjs)$/u.test(normalizedFilename) && program.body.some((statement) => statement.type === AST_NODE_TYPES102.ImportDeclaration && statement.source.value === "astro:content")) return;
|
|
22734
22860
|
const exportedStem = kebabCase(only.name);
|
|
22735
22861
|
if (exportedStem === "") return;
|
|
22736
22862
|
const expected = `${fileStem.startsWith("_") ? "_" : ""}${exportedStem}`;
|
|
@@ -22781,8 +22907,8 @@ var iac_source_coupled_test_default = createSourceCoupledRule(
|
|
|
22781
22907
|
|
|
22782
22908
|
// src/rules/require-pascal-case-zod-schema-name.ts
|
|
22783
22909
|
import {
|
|
22784
|
-
AST_NODE_TYPES as
|
|
22785
|
-
ASTUtils as
|
|
22910
|
+
AST_NODE_TYPES as AST_NODE_TYPES103,
|
|
22911
|
+
ASTUtils as ASTUtils53
|
|
22786
22912
|
} from "@typescript-eslint/utils";
|
|
22787
22913
|
var REQUIRE_PASCAL_CASE_ZOD_SCHEMA_NAME_DOCUMENTATION = {
|
|
22788
22914
|
summary: "Require confirmed module-level Zod schema contracts to use PascalCase with a `Schema` suffix.",
|
|
@@ -22915,18 +23041,18 @@ var SCHEMA_RETURNING_METHODS = /* @__PURE__ */ new Set([
|
|
|
22915
23041
|
"superRefine",
|
|
22916
23042
|
"transform"
|
|
22917
23043
|
]);
|
|
22918
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
23044
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === AST_NODE_TYPES103.Identifier ? callee.property.name : null;
|
|
22919
23045
|
var calleeChainRoot2 = (node) => {
|
|
22920
23046
|
let current = node;
|
|
22921
23047
|
for (; ; ) {
|
|
22922
|
-
if (current.type ===
|
|
23048
|
+
if (current.type === AST_NODE_TYPES103.Identifier) {
|
|
22923
23049
|
return current;
|
|
22924
23050
|
}
|
|
22925
|
-
if (current.type ===
|
|
23051
|
+
if (current.type === AST_NODE_TYPES103.MemberExpression) {
|
|
22926
23052
|
current = current.object;
|
|
22927
23053
|
continue;
|
|
22928
23054
|
}
|
|
22929
|
-
if (current.type ===
|
|
23055
|
+
if (current.type === AST_NODE_TYPES103.CallExpression) {
|
|
22930
23056
|
current = current.callee;
|
|
22931
23057
|
continue;
|
|
22932
23058
|
}
|
|
@@ -22937,13 +23063,13 @@ var chainMemberNames2 = (node) => {
|
|
|
22937
23063
|
const names = [];
|
|
22938
23064
|
let current = node;
|
|
22939
23065
|
for (; ; ) {
|
|
22940
|
-
if (current.type ===
|
|
22941
|
-
if (current.computed || current.property.type !==
|
|
23066
|
+
if (current.type === AST_NODE_TYPES103.MemberExpression) {
|
|
23067
|
+
if (current.computed || current.property.type !== AST_NODE_TYPES103.Identifier) return [];
|
|
22942
23068
|
names.push(current.property.name);
|
|
22943
23069
|
current = current.object;
|
|
22944
23070
|
continue;
|
|
22945
23071
|
}
|
|
22946
|
-
if (current.type ===
|
|
23072
|
+
if (current.type === AST_NODE_TYPES103.CallExpression) {
|
|
22947
23073
|
current = current.callee;
|
|
22948
23074
|
continue;
|
|
22949
23075
|
}
|
|
@@ -22954,16 +23080,16 @@ var chainMemberNames2 = (node) => {
|
|
|
22954
23080
|
};
|
|
22955
23081
|
var unwrapExpression7 = (node) => {
|
|
22956
23082
|
let current = node;
|
|
22957
|
-
while (current.type ===
|
|
23083
|
+
while (current.type === AST_NODE_TYPES103.TSAsExpression || current.type === AST_NODE_TYPES103.TSSatisfiesExpression || current.type === AST_NODE_TYPES103.TSNonNullExpression || current.type === AST_NODE_TYPES103.TSTypeAssertion) {
|
|
22958
23084
|
current = current.expression;
|
|
22959
23085
|
}
|
|
22960
23086
|
return current;
|
|
22961
23087
|
};
|
|
22962
23088
|
var isModuleDeclarator = (node) => {
|
|
22963
23089
|
const declaration = node.parent;
|
|
22964
|
-
if (declaration.type !==
|
|
23090
|
+
if (declaration.type !== AST_NODE_TYPES103.VariableDeclaration) return false;
|
|
22965
23091
|
const owner = declaration.parent;
|
|
22966
|
-
return owner.type ===
|
|
23092
|
+
return owner.type === AST_NODE_TYPES103.Program || owner.type === AST_NODE_TYPES103.ExportNamedDeclaration && owner.parent.type === AST_NODE_TYPES103.Program;
|
|
22967
23093
|
};
|
|
22968
23094
|
var require_pascal_case_zod_schema_name_default = createRule({
|
|
22969
23095
|
name: "require-pascal-case-zod-schema-name",
|
|
@@ -22983,7 +23109,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
22983
23109
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
22984
23110
|
const schemaBindings = /* @__PURE__ */ new Set();
|
|
22985
23111
|
function resolvedBinding(identifier) {
|
|
22986
|
-
return
|
|
23112
|
+
return ASTUtils53.findVariable(
|
|
22987
23113
|
context.sourceCode.getScope(identifier),
|
|
22988
23114
|
identifier.name
|
|
22989
23115
|
);
|
|
@@ -23004,8 +23130,8 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
23004
23130
|
}
|
|
23005
23131
|
function isConfirmedSchema(expression) {
|
|
23006
23132
|
const init = unwrapExpression7(expression);
|
|
23007
|
-
if (init.type ===
|
|
23008
|
-
if (init.type !==
|
|
23133
|
+
if (init.type === AST_NODE_TYPES103.Identifier) return isSchemaBinding(init);
|
|
23134
|
+
if (init.type !== AST_NODE_TYPES103.CallExpression || init.callee.type !== AST_NODE_TYPES103.MemberExpression) {
|
|
23009
23135
|
return false;
|
|
23010
23136
|
}
|
|
23011
23137
|
const terminal = terminalMethodName(init.callee);
|
|
@@ -23025,7 +23151,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
23025
23151
|
ImportDeclaration(node) {
|
|
23026
23152
|
if (!isZodModule(node.source.value)) return;
|
|
23027
23153
|
for (const specifier of node.specifiers) {
|
|
23028
|
-
if (specifier.type ===
|
|
23154
|
+
if (specifier.type === AST_NODE_TYPES103.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES103.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES103.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES103.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
23029
23155
|
recordZodBinding(specifier.local);
|
|
23030
23156
|
}
|
|
23031
23157
|
}
|
|
@@ -23034,7 +23160,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
23034
23160
|
if (!isModuleDeclarator(node)) return;
|
|
23035
23161
|
const init = node.init;
|
|
23036
23162
|
if (init === null || init === void 0) return;
|
|
23037
|
-
if (node.id.type !==
|
|
23163
|
+
if (node.id.type !== AST_NODE_TYPES103.Identifier) return;
|
|
23038
23164
|
if (!isConfirmedSchema(init)) return;
|
|
23039
23165
|
const binding = resolvedBinding(node.id);
|
|
23040
23166
|
if (binding !== null) schemaBindings.add(binding);
|
|
@@ -23217,6 +23343,7 @@ var RULES = {
|
|
|
23217
23343
|
"prefer-module-level-refined-schema": prefer_module_level_refined_schema_default,
|
|
23218
23344
|
"prefer-multi-value-zod-literal": prefer_multi_value_zod_literal_default,
|
|
23219
23345
|
"prefer-named-callback-domain": prefer_named_callback_domain_default,
|
|
23346
|
+
"prefer-nominal-id-types": prefer_nominal_id_types_default,
|
|
23220
23347
|
"prefer-named-complex-return-type": prefer_named_complex_return_type_default,
|
|
23221
23348
|
"prefer-native-random-uuid": prefer_native_random_uuid_default,
|
|
23222
23349
|
"prefer-node-crypto-hash": prefer_node_crypto_hash_default,
|
|
@@ -23248,7 +23375,7 @@ var RULES = {
|
|
|
23248
23375
|
};
|
|
23249
23376
|
var meta = {
|
|
23250
23377
|
name: "@sarj/eslint-plugin",
|
|
23251
|
-
version: "15.
|
|
23378
|
+
version: "15.28.0"
|
|
23252
23379
|
};
|
|
23253
23380
|
var APPLICATION_ONLY_RULES = [];
|
|
23254
23381
|
var LIBRARY_IMPORT_POLICY = ["error", {
|
|
@@ -23267,6 +23394,7 @@ var ADVISORY_RULES = [
|
|
|
23267
23394
|
"@sarj/prefer-named-complex-return-type",
|
|
23268
23395
|
"@sarj/prefer-node-crypto-hash",
|
|
23269
23396
|
"@sarj/prefer-node-fs-promises",
|
|
23397
|
+
"@sarj/prefer-nominal-id-types",
|
|
23270
23398
|
"@sarj/prefer-shared-zod-enum",
|
|
23271
23399
|
"@sarj/prefer-switch-for-repeated-equality",
|
|
23272
23400
|
"@sarj/prefer-whole-object-assertion",
|
|
@@ -23357,6 +23485,7 @@ var RECOMMENDED_RULES = {
|
|
|
23357
23485
|
"@sarj/prefer-module-level-refined-schema": "warn",
|
|
23358
23486
|
"@sarj/prefer-multi-value-zod-literal": ["warn", { zodMajorVersion: 4 }],
|
|
23359
23487
|
"@sarj/prefer-named-callback-domain": "error",
|
|
23488
|
+
"@sarj/prefer-nominal-id-types": "warn",
|
|
23360
23489
|
"@sarj/prefer-named-complex-return-type": "warn",
|
|
23361
23490
|
"@sarj/prefer-node-crypto-hash": "warn",
|
|
23362
23491
|
"@sarj/prefer-node-fs-promises": "warn",
|
|
@@ -23474,6 +23603,7 @@ var STRICT_RULES = {
|
|
|
23474
23603
|
"@sarj/prefer-module-level-refined-schema": "warn",
|
|
23475
23604
|
"@sarj/prefer-multi-value-zod-literal": ["warn", { zodMajorVersion: 4 }],
|
|
23476
23605
|
"@sarj/prefer-named-callback-domain": "error",
|
|
23606
|
+
"@sarj/prefer-nominal-id-types": "warn",
|
|
23477
23607
|
"@sarj/prefer-named-complex-return-type": "warn",
|
|
23478
23608
|
"@sarj/prefer-node-crypto-hash": "warn",
|
|
23479
23609
|
"@sarj/prefer-node-fs-promises": "warn",
|