@sarj/eslint-plugin 16.4.8 → 16.5.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/index.cjs +459 -351
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +458 -350
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// package.json
|
|
2
2
|
var package_default = {
|
|
3
3
|
name: "@sarj/eslint-plugin",
|
|
4
|
-
version: "16.
|
|
4
|
+
version: "16.5.0",
|
|
5
5
|
packageManager: "npm@12.1.0",
|
|
6
6
|
description: "Custom ESLint rules for hypermodern TypeScript / React / Next.js projects",
|
|
7
7
|
type: "module",
|
|
@@ -21371,10 +21371,114 @@ function staticFieldName(key) {
|
|
|
21371
21371
|
return key.type === AST_NODE_TYPES99.Identifier ? key.name : key.type === AST_NODE_TYPES99.Literal && typeof key.value === "string" ? key.value : null;
|
|
21372
21372
|
}
|
|
21373
21373
|
|
|
21374
|
+
// src/rules/named-child-schema-type.ts
|
|
21375
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES100, ASTUtils as ASTUtils61 } from "@typescript-eslint/utils";
|
|
21376
|
+
var UNRESOLVED_TYPE_NODES = /* @__PURE__ */ new Set([
|
|
21377
|
+
AST_NODE_TYPES100.TSTypeQuery,
|
|
21378
|
+
AST_NODE_TYPES100.TSImportType,
|
|
21379
|
+
AST_NODE_TYPES100.TSTypeParameter,
|
|
21380
|
+
AST_NODE_TYPES100.TSAnyKeyword,
|
|
21381
|
+
AST_NODE_TYPES100.TSUnknownKeyword
|
|
21382
|
+
]);
|
|
21383
|
+
var NAMED_CHILD_SCHEMA_TYPE_DOCUMENTATION = {
|
|
21384
|
+
defaultLevel: "warning",
|
|
21385
|
+
summary: "Reference a named Zod record child's complete schema type instead of repeating its explicit annotation.",
|
|
21386
|
+
rationale: "Repeating a child schema's generic contract creates a second maintained declaration even though the record already uses that child at runtime.",
|
|
21387
|
+
remediation: "Replace only the matching record type argument with `typeof ChildSchema`; retain the outer annotation required by isolatedDeclarations and every runtime schema operation.",
|
|
21388
|
+
category: "maintainability",
|
|
21389
|
+
autofix: "none",
|
|
21390
|
+
limitations: [
|
|
21391
|
+
"Only direct module-level const z.record calls with two arguments, a ZodRecord annotation, and an earlier local const child with a complete explicit Zod type are inspected.",
|
|
21392
|
+
"The entire generic child annotation must match token for token; input/output, defaults, transforms, readonly modifiers and brands are never compared by output shape alone.",
|
|
21393
|
+
"Bare leaf types, broad ZodType constraints, type queries, imported or unqualified type references, annotation cycles, comments on the repeated argument, mutable bindings and generated files are excluded.",
|
|
21394
|
+
"Import aliases and namespace imports resolve through scope bindings. Independent public contract pins require review; this warning does not remove annotations or change runtime validation."
|
|
21395
|
+
],
|
|
21396
|
+
examples: [
|
|
21397
|
+
{ id: "named-child", title: "Reference the named child contract", outcome: "no-match", files: [{ path: "src/record.ts", source: 'import { z } from "zod"; const KeySchema: z.ZodEnum<{ a: "a"; b: "b" }> = z.enum(["a", "b"]); export const RecordSchema: z.ZodRecord<typeof KeySchema, z.ZodString> = z.record(KeySchema, z.string());' }], focusPath: "src/record.ts", expectedCount: 0, public: true },
|
|
21398
|
+
{ id: "copied-child", title: "Do not repeat the complete child annotation", outcome: "match", files: [{ path: "src/record.ts", source: 'import { z } from "zod"; const KeySchema: z.ZodEnum<{ a: "a"; b: "b" }> = z.enum(["a", "b"]); export const RecordSchema: z.ZodRecord<z.ZodEnum<{ a: "a"; b: "b" }>, z.ZodString> = z.record(KeySchema, z.string());' }], focusPath: "src/record.ts", expectedCount: 1, public: true }
|
|
21399
|
+
]
|
|
21400
|
+
};
|
|
21401
|
+
function isModuleConst(node) {
|
|
21402
|
+
if (node.parent.kind !== "const" || node.id.type !== AST_NODE_TYPES100.Identifier) return false;
|
|
21403
|
+
const parent = node.parent.parent;
|
|
21404
|
+
return parent.type === AST_NODE_TYPES100.Program || parent.type === AST_NODE_TYPES100.ExportNamedDeclaration && parent.parent.type === AST_NODE_TYPES100.Program;
|
|
21405
|
+
}
|
|
21406
|
+
var named_child_schema_type_default = createRule({
|
|
21407
|
+
name: "named-child-schema-type",
|
|
21408
|
+
documentation: NAMED_CHILD_SCHEMA_TYPE_DOCUMENTATION,
|
|
21409
|
+
meta: {
|
|
21410
|
+
type: "suggestion",
|
|
21411
|
+
docs: { description: NAMED_CHILD_SCHEMA_TYPE_DOCUMENTATION.summary },
|
|
21412
|
+
schema: [],
|
|
21413
|
+
messages: { namedChildType: "Use `typeof {{name}}` for this exact child contract; keep the outer schema annotation and runtime operations." }
|
|
21414
|
+
},
|
|
21415
|
+
defaultOptions: [],
|
|
21416
|
+
create(context) {
|
|
21417
|
+
const source = context.sourceCode;
|
|
21418
|
+
if (isGeneratedFile(context.filename, source.text)) return {};
|
|
21419
|
+
const namespaces = /* @__PURE__ */ new Set();
|
|
21420
|
+
const bindingOf = (node) => ASTUtils61.findVariable(source.getScope(node), node.name);
|
|
21421
|
+
function namespaceOf(type) {
|
|
21422
|
+
if (type.typeName.type !== AST_NODE_TYPES100.TSQualifiedName || type.typeName.left.type !== AST_NODE_TYPES100.Identifier) return null;
|
|
21423
|
+
const binding = bindingOf(type.typeName.left);
|
|
21424
|
+
return binding !== null && namespaces.has(binding) ? binding : null;
|
|
21425
|
+
}
|
|
21426
|
+
function closedType(node, namespace) {
|
|
21427
|
+
if (UNRESOLVED_TYPE_NODES.has(node.type)) return false;
|
|
21428
|
+
if (node.type === AST_NODE_TYPES100.TSTypeReference && namespaceOf(node) !== namespace) return false;
|
|
21429
|
+
return !forEachOwnAstChild(node, (child) => !closedType(child, namespace));
|
|
21430
|
+
}
|
|
21431
|
+
function inspectChild(argument, repeated, namespace, parent) {
|
|
21432
|
+
if (argument.type !== AST_NODE_TYPES100.Identifier || repeated.type !== AST_NODE_TYPES100.TSTypeReference || repeated.typeArguments === void 0) return;
|
|
21433
|
+
if (repeated.typeName.type !== AST_NODE_TYPES100.TSQualifiedName || /^(?:ZodType|ZodSchema|ZodTypeAny)$/u.test(repeated.typeName.right.name)) return;
|
|
21434
|
+
const variable = bindingOf(argument);
|
|
21435
|
+
const definition = variable?.defs.length === 1 ? variable.defs[0] : void 0;
|
|
21436
|
+
if (definition?.type !== "Variable" || !isModuleConst(definition.node)) return;
|
|
21437
|
+
const child = definition.node;
|
|
21438
|
+
if (child.id.type !== AST_NODE_TYPES100.Identifier || child.init === null || child.range[0] >= parent.range[0]) return;
|
|
21439
|
+
const annotation = child.id.typeAnnotation?.typeAnnotation;
|
|
21440
|
+
if (annotation === void 0 || factoryNamespace(child.init) !== namespace || !closedType(annotation, namespace)) return;
|
|
21441
|
+
if (source.getCommentsInside(repeated).length > 0 || source.getCommentsBefore(repeated).length > 0) return;
|
|
21442
|
+
const expected = source.getTokens(annotation);
|
|
21443
|
+
const actual = source.getTokens(repeated);
|
|
21444
|
+
if (expected.length !== actual.length || expected.some((token, index) => token.type !== actual[index]?.type || token.value !== actual[index]?.value)) return;
|
|
21445
|
+
context.report({ node: repeated, messageId: "namedChildType", data: { name: argument.name } });
|
|
21446
|
+
}
|
|
21447
|
+
function factoryNamespace(expression) {
|
|
21448
|
+
if (expression.type !== AST_NODE_TYPES100.CallExpression || expression.callee.type !== AST_NODE_TYPES100.MemberExpression) return null;
|
|
21449
|
+
const object = expression.callee.object;
|
|
21450
|
+
return object.type === AST_NODE_TYPES100.Identifier ? bindingOf(object) : factoryNamespace(object);
|
|
21451
|
+
}
|
|
21452
|
+
return {
|
|
21453
|
+
ImportDeclaration(node) {
|
|
21454
|
+
if (node.importKind === "type" || !isZodModule(node.source.value)) return;
|
|
21455
|
+
for (const specifier of node.specifiers) {
|
|
21456
|
+
if (specifier.type !== AST_NODE_TYPES100.ImportNamespaceSpecifier && (specifier.type !== AST_NODE_TYPES100.ImportSpecifier || specifier.importKind === "type" || importSpecifierName(specifier) !== "z")) continue;
|
|
21457
|
+
const binding = bindingOf(specifier.local);
|
|
21458
|
+
if (binding !== null) namespaces.add(binding);
|
|
21459
|
+
}
|
|
21460
|
+
},
|
|
21461
|
+
VariableDeclarator(node) {
|
|
21462
|
+
if (!isModuleConst(node) || node.id.type !== AST_NODE_TYPES100.Identifier || node.init?.type !== AST_NODE_TYPES100.CallExpression) return;
|
|
21463
|
+
const call = node.init;
|
|
21464
|
+
if (call.arguments.length !== 2 || call.callee.type !== AST_NODE_TYPES100.MemberExpression || call.callee.object.type !== AST_NODE_TYPES100.Identifier || ASTUtils61.getPropertyName(call.callee) !== "record") return;
|
|
21465
|
+
const annotation = node.id.typeAnnotation?.typeAnnotation;
|
|
21466
|
+
if (annotation?.type !== AST_NODE_TYPES100.TSTypeReference || annotation.typeName.type !== AST_NODE_TYPES100.TSQualifiedName || annotation.typeName.right.name !== "ZodRecord") return;
|
|
21467
|
+
const namespace = namespaceOf(annotation);
|
|
21468
|
+
if (namespace === null || bindingOf(call.callee.object) !== namespace || annotation.typeArguments?.params.length !== 2) return;
|
|
21469
|
+
for (const [index, argument] of call.arguments.entries()) {
|
|
21470
|
+
const repeated = annotation.typeArguments.params[index];
|
|
21471
|
+
if (repeated !== void 0) inspectChild(argument, repeated, namespace, node);
|
|
21472
|
+
}
|
|
21473
|
+
}
|
|
21474
|
+
};
|
|
21475
|
+
}
|
|
21476
|
+
});
|
|
21477
|
+
|
|
21374
21478
|
// src/rules/prefer-zod-parse-output-type.ts
|
|
21375
21479
|
import {
|
|
21376
|
-
ASTUtils as
|
|
21377
|
-
AST_NODE_TYPES as
|
|
21480
|
+
ASTUtils as ASTUtils62,
|
|
21481
|
+
AST_NODE_TYPES as AST_NODE_TYPES101,
|
|
21378
21482
|
ESLintUtils as ESLintUtils14
|
|
21379
21483
|
} from "@typescript-eslint/utils";
|
|
21380
21484
|
import ts12 from "typescript";
|
|
@@ -21432,22 +21536,22 @@ var PREFER_ZOD_PARSE_OUTPUT_TYPE_DOCUMENTATION = {
|
|
|
21432
21536
|
};
|
|
21433
21537
|
function isModuleLevelConst2(node) {
|
|
21434
21538
|
const declaration = node.parent;
|
|
21435
|
-
if (declaration.type !==
|
|
21539
|
+
if (declaration.type !== AST_NODE_TYPES101.VariableDeclaration || declaration.kind !== "const") {
|
|
21436
21540
|
return false;
|
|
21437
21541
|
}
|
|
21438
21542
|
const container = declaration.parent;
|
|
21439
|
-
return container.type ===
|
|
21543
|
+
return container.type === AST_NODE_TYPES101.Program || container.type === AST_NODE_TYPES101.ExportNamedDeclaration && container.parent.type === AST_NODE_TYPES101.Program;
|
|
21440
21544
|
}
|
|
21441
21545
|
function isLocalZodObjectSchema(node, namespaces) {
|
|
21442
21546
|
let current = node;
|
|
21443
|
-
while (current.type ===
|
|
21547
|
+
while (current.type === AST_NODE_TYPES101.CallExpression) {
|
|
21444
21548
|
const callee = unwrapExpression(current.callee);
|
|
21445
|
-
const calleeReceiver = callee.type ===
|
|
21446
|
-
if (callee.type !==
|
|
21549
|
+
const calleeReceiver = callee.type === AST_NODE_TYPES101.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
21550
|
+
if (callee.type !== AST_NODE_TYPES101.MemberExpression || ASTUtils62.getPropertyName(callee) === null) {
|
|
21447
21551
|
return false;
|
|
21448
21552
|
}
|
|
21449
|
-
if (calleeReceiver.type ===
|
|
21450
|
-
return namespaces.has(calleeReceiver.name) && ((
|
|
21553
|
+
if (calleeReceiver.type === AST_NODE_TYPES101.Identifier) {
|
|
21554
|
+
return namespaces.has(calleeReceiver.name) && ((ASTUtils62.getPropertyName(callee) ?? "") === "object" || (ASTUtils62.getPropertyName(callee) ?? "") === "strictObject");
|
|
21451
21555
|
}
|
|
21452
21556
|
current = calleeReceiver;
|
|
21453
21557
|
}
|
|
@@ -21455,11 +21559,11 @@ function isLocalZodObjectSchema(node, namespaces) {
|
|
|
21455
21559
|
}
|
|
21456
21560
|
function zodParseCall(node) {
|
|
21457
21561
|
const callee = unwrapExpression(node.callee);
|
|
21458
|
-
const calleeReceiver = callee.type ===
|
|
21459
|
-
if (callee.type !==
|
|
21562
|
+
const calleeReceiver = callee.type === AST_NODE_TYPES101.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
21563
|
+
if (callee.type !== AST_NODE_TYPES101.MemberExpression || calleeReceiver.type !== AST_NODE_TYPES101.Identifier || ASTUtils62.getPropertyName(callee) === null) {
|
|
21460
21564
|
return null;
|
|
21461
21565
|
}
|
|
21462
|
-
const method =
|
|
21566
|
+
const method = ASTUtils62.getPropertyName(callee);
|
|
21463
21567
|
if (method !== "parse" && method !== "safeParse") return null;
|
|
21464
21568
|
return {
|
|
21465
21569
|
call: node,
|
|
@@ -21473,7 +21577,7 @@ function returnedOutputCandidate(parsed, output) {
|
|
|
21473
21577
|
const annotation = owner?.returnType?.typeAnnotation;
|
|
21474
21578
|
if (annotation === void 0) return null;
|
|
21475
21579
|
const typeReference = returnContractReference(annotation);
|
|
21476
|
-
if (typeReference === null || typeReference.typeName.type !==
|
|
21580
|
+
if (typeReference === null || typeReference.typeName.type !== AST_NODE_TYPES101.Identifier) {
|
|
21477
21581
|
return null;
|
|
21478
21582
|
}
|
|
21479
21583
|
return {
|
|
@@ -21490,7 +21594,7 @@ function directParseReturnCandidate(node) {
|
|
|
21490
21594
|
return parsed?.method === "parse" ? returnedOutputCandidate(parsed, node) : null;
|
|
21491
21595
|
}
|
|
21492
21596
|
function localParseReturnCandidates(node, sourceCode) {
|
|
21493
|
-
if (node.id.type !==
|
|
21597
|
+
if (node.id.type !== AST_NODE_TYPES101.Identifier || node.init?.type !== AST_NODE_TYPES101.CallExpression || node.parent.type !== AST_NODE_TYPES101.VariableDeclaration || node.parent.kind !== "const" || enclosingFunction4(node.init) === null) {
|
|
21494
21598
|
return [];
|
|
21495
21599
|
}
|
|
21496
21600
|
const parsed = zodParseCall(node.init);
|
|
@@ -21501,7 +21605,7 @@ function localParseReturnCandidates(node, sourceCode) {
|
|
|
21501
21605
|
for (const reference of variable.references) {
|
|
21502
21606
|
const identifier = reference.identifier;
|
|
21503
21607
|
const parent = identifier.parent;
|
|
21504
|
-
const output = parsed.method === "parse" ? identifier : parent.type ===
|
|
21608
|
+
const output = parsed.method === "parse" ? identifier : parent.type === AST_NODE_TYPES101.MemberExpression && parent.object === identifier && ASTUtils62.getPropertyName(parent) !== null && (ASTUtils62.getPropertyName(parent) ?? "") === "data" ? parent : null;
|
|
21505
21609
|
if (output === null) continue;
|
|
21506
21610
|
const candidate2 = returnedOutputCandidate(parsed, output);
|
|
21507
21611
|
if (candidate2 !== null) candidates.push(candidate2);
|
|
@@ -21512,17 +21616,17 @@ function directReturnOwner(node) {
|
|
|
21512
21616
|
let current = node;
|
|
21513
21617
|
while (current.parent !== void 0) {
|
|
21514
21618
|
const parent = current.parent;
|
|
21515
|
-
if (parent.type ===
|
|
21619
|
+
if (parent.type === AST_NODE_TYPES101.ReturnStatement) {
|
|
21516
21620
|
return parent.argument === current ? enclosingFunction4(parent) : null;
|
|
21517
21621
|
}
|
|
21518
|
-
if (parent.type ===
|
|
21622
|
+
if (parent.type === AST_NODE_TYPES101.ArrowFunctionExpression && parent.expression && parent.body === current) {
|
|
21519
21623
|
return parent;
|
|
21520
21624
|
}
|
|
21521
|
-
if (parent.type ===
|
|
21625
|
+
if (parent.type === AST_NODE_TYPES101.AwaitExpression && parent.argument === current) {
|
|
21522
21626
|
current = parent;
|
|
21523
21627
|
continue;
|
|
21524
21628
|
}
|
|
21525
|
-
if (parent.type ===
|
|
21629
|
+
if (parent.type === AST_NODE_TYPES101.ConditionalExpression) {
|
|
21526
21630
|
const parsedWhenTrue = parent.consequent === current && isNullishExpression(parent.alternate);
|
|
21527
21631
|
const parsedWhenFalse = parent.alternate === current && isNullishExpression(parent.consequent);
|
|
21528
21632
|
if (parsedWhenTrue || parsedWhenFalse) {
|
|
@@ -21535,12 +21639,12 @@ function directReturnOwner(node) {
|
|
|
21535
21639
|
return null;
|
|
21536
21640
|
}
|
|
21537
21641
|
function isNullishExpression(node) {
|
|
21538
|
-
return node.type ===
|
|
21642
|
+
return node.type === AST_NODE_TYPES101.Literal && node.value === null || node.type === AST_NODE_TYPES101.Identifier && node.name === "undefined";
|
|
21539
21643
|
}
|
|
21540
21644
|
function enclosingFunction4(node) {
|
|
21541
21645
|
let current = node.parent;
|
|
21542
21646
|
while (current != null) {
|
|
21543
|
-
if (current.type ===
|
|
21647
|
+
if (current.type === AST_NODE_TYPES101.ArrowFunctionExpression || current.type === AST_NODE_TYPES101.FunctionDeclaration || current.type === AST_NODE_TYPES101.FunctionExpression) {
|
|
21544
21648
|
return current;
|
|
21545
21649
|
}
|
|
21546
21650
|
current = current.parent;
|
|
@@ -21548,45 +21652,45 @@ function enclosingFunction4(node) {
|
|
|
21548
21652
|
return null;
|
|
21549
21653
|
}
|
|
21550
21654
|
function returnContractReference(node) {
|
|
21551
|
-
if (node.type ===
|
|
21655
|
+
if (node.type === AST_NODE_TYPES101.TSUnionType) {
|
|
21552
21656
|
const substantive = node.types.filter(
|
|
21553
|
-
(member) => member.type !==
|
|
21657
|
+
(member) => member.type !== AST_NODE_TYPES101.TSNullKeyword && member.type !== AST_NODE_TYPES101.TSUndefinedKeyword
|
|
21554
21658
|
);
|
|
21555
21659
|
const [only] = substantive;
|
|
21556
21660
|
return substantive.length === 1 && only !== void 0 ? returnContractReference(only) : null;
|
|
21557
21661
|
}
|
|
21558
|
-
if (node.type ===
|
|
21662
|
+
if (node.type === AST_NODE_TYPES101.TSTypeReference && node.typeName.type === AST_NODE_TYPES101.Identifier && node.typeName.name === "Promise") {
|
|
21559
21663
|
const parameters = node.typeArguments?.params ?? [];
|
|
21560
21664
|
const [only] = parameters;
|
|
21561
21665
|
return parameters.length === 1 && only !== void 0 ? returnContractReference(only) : null;
|
|
21562
21666
|
}
|
|
21563
|
-
return node.type ===
|
|
21667
|
+
return node.type === AST_NODE_TYPES101.TSTypeReference && node.typeName.type === AST_NODE_TYPES101.Identifier && (node.typeArguments?.params.length ?? 0) === 0 ? node : null;
|
|
21564
21668
|
}
|
|
21565
21669
|
function recordZodNamespaces(node, namespaces) {
|
|
21566
21670
|
for (const statement of node.body) {
|
|
21567
|
-
if (statement.type !==
|
|
21671
|
+
if (statement.type !== AST_NODE_TYPES101.ImportDeclaration || !isZodModule(statement.source.value)) {
|
|
21568
21672
|
continue;
|
|
21569
21673
|
}
|
|
21570
21674
|
for (const specifier of statement.specifiers) {
|
|
21571
|
-
if (specifier.type ===
|
|
21675
|
+
if (specifier.type === AST_NODE_TYPES101.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES101.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES101.ImportSpecifier && importSpecifierName(specifier) === "z") {
|
|
21572
21676
|
namespaces.add(specifier.local.name);
|
|
21573
21677
|
}
|
|
21574
21678
|
}
|
|
21575
21679
|
}
|
|
21576
21680
|
}
|
|
21577
21681
|
function collectConstrainedNames(node, names) {
|
|
21578
|
-
if (node.type ===
|
|
21579
|
-
if (node.typeName.type ===
|
|
21682
|
+
if (node.type === AST_NODE_TYPES101.TSTypeReference) {
|
|
21683
|
+
if (node.typeName.type === AST_NODE_TYPES101.Identifier) names.add(node.typeName.name);
|
|
21580
21684
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
21581
21685
|
collectConstrainedNames(argument, names);
|
|
21582
21686
|
}
|
|
21583
21687
|
return;
|
|
21584
21688
|
}
|
|
21585
|
-
if (node.type ===
|
|
21689
|
+
if (node.type === AST_NODE_TYPES101.TSArrayType) {
|
|
21586
21690
|
collectConstrainedNames(node.elementType, names);
|
|
21587
21691
|
return;
|
|
21588
21692
|
}
|
|
21589
|
-
if (node.type ===
|
|
21693
|
+
if (node.type === AST_NODE_TYPES101.TSUnionType || node.type === AST_NODE_TYPES101.TSIntersectionType) {
|
|
21590
21694
|
for (const member of node.types) collectConstrainedNames(member, names);
|
|
21591
21695
|
}
|
|
21592
21696
|
}
|
|
@@ -21620,7 +21724,7 @@ function reportCandidates(context, services, schemas, candidates, zodNamespaces,
|
|
|
21620
21724
|
if (constrained) return;
|
|
21621
21725
|
if (declaration.getSourceFile() === tsSchema.getSourceFile()) {
|
|
21622
21726
|
const estreeDeclaration = services.tsNodeToESTreeNodeMap.get(declaration);
|
|
21623
|
-
if ((estreeDeclaration.type ===
|
|
21727
|
+
if ((estreeDeclaration.type === AST_NODE_TYPES101.TSInterfaceDeclaration || estreeDeclaration.type === AST_NODE_TYPES101.TSTypeAliasDeclaration) && preferZodInferOwnsDefaultTwin({
|
|
21624
21728
|
constrained,
|
|
21625
21729
|
declaration: estreeDeclaration,
|
|
21626
21730
|
initializer: schema.initializer,
|
|
@@ -21725,7 +21829,7 @@ var prefer_zod_parse_output_type_default = createRule({
|
|
|
21725
21829
|
recordZodNamespaces(node, namespaces);
|
|
21726
21830
|
},
|
|
21727
21831
|
VariableDeclarator(node) {
|
|
21728
|
-
if (node.id.type ===
|
|
21832
|
+
if (node.id.type === AST_NODE_TYPES101.Identifier && node.init !== null && isModuleLevelConst2(node) && isLocalZodObjectSchema(node.init, namespaces)) {
|
|
21729
21833
|
schemas.push({ identifier: node.id, initializer: node.init, name: node.id.name });
|
|
21730
21834
|
}
|
|
21731
21835
|
candidates.push(...localParseReturnCandidates(node, context.sourceCode));
|
|
@@ -21735,13 +21839,13 @@ var prefer_zod_parse_output_type_default = createRule({
|
|
|
21735
21839
|
if (candidate2 !== null) candidates.push(candidate2);
|
|
21736
21840
|
},
|
|
21737
21841
|
"MemberExpression"(node) {
|
|
21738
|
-
if (node.object.type ===
|
|
21842
|
+
if (node.object.type === AST_NODE_TYPES101.Identifier && node.property.type === AST_NODE_TYPES101.Identifier && isPreferZodInferModuleReshaper(node.property.name)) {
|
|
21739
21843
|
reshapedSchemas.add(node.object.name);
|
|
21740
21844
|
}
|
|
21741
21845
|
},
|
|
21742
21846
|
TSTypeReference(node) {
|
|
21743
21847
|
const { typeName } = node;
|
|
21744
|
-
const name = typeName.type ===
|
|
21848
|
+
const name = typeName.type === AST_NODE_TYPES101.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES101.TSQualifiedName && typeName.right.type === AST_NODE_TYPES101.Identifier ? typeName.right.name : null;
|
|
21745
21849
|
if (name === null || !isPreferZodInferTypeConstraintName(name)) return;
|
|
21746
21850
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
21747
21851
|
collectConstrainedNames(argument, constrainedTypeNames);
|
|
@@ -21765,7 +21869,7 @@ var prefer_zod_parse_output_type_default = createRule({
|
|
|
21765
21869
|
// src/rules/require-assert-never.ts
|
|
21766
21870
|
import {
|
|
21767
21871
|
ESLintUtils as ESLintUtils15,
|
|
21768
|
-
AST_NODE_TYPES as
|
|
21872
|
+
AST_NODE_TYPES as AST_NODE_TYPES102
|
|
21769
21873
|
} from "@typescript-eslint/utils";
|
|
21770
21874
|
import ts13 from "typescript";
|
|
21771
21875
|
var REQUIRE_ASSERT_NEVER_DOCUMENTATION = {
|
|
@@ -21780,14 +21884,14 @@ var REQUIRE_ASSERT_NEVER_DOCUMENTATION = {
|
|
|
21780
21884
|
]
|
|
21781
21885
|
};
|
|
21782
21886
|
var isRuntimeHandlingStatement = (statement) => {
|
|
21783
|
-
if (statement.type ===
|
|
21784
|
-
if (statement.type ===
|
|
21887
|
+
if (statement.type === AST_NODE_TYPES102.EmptyStatement) return false;
|
|
21888
|
+
if (statement.type === AST_NODE_TYPES102.BreakStatement) {
|
|
21785
21889
|
return statement.label !== null;
|
|
21786
21890
|
}
|
|
21787
|
-
if (statement.type ===
|
|
21891
|
+
if (statement.type === AST_NODE_TYPES102.TSTypeAliasDeclaration || statement.type === AST_NODE_TYPES102.TSInterfaceDeclaration) {
|
|
21788
21892
|
return false;
|
|
21789
21893
|
}
|
|
21790
|
-
if (statement.type ===
|
|
21894
|
+
if (statement.type === AST_NODE_TYPES102.BlockStatement) {
|
|
21791
21895
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
21792
21896
|
}
|
|
21793
21897
|
return true;
|
|
@@ -21803,7 +21907,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
21803
21907
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
21804
21908
|
}
|
|
21805
21909
|
const only = defaultCase.consequent[0];
|
|
21806
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
21910
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === AST_NODE_TYPES102.BlockStatement && !only.body.some(isRuntimeHandlingStatement)) {
|
|
21807
21911
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
21808
21912
|
}
|
|
21809
21913
|
return false;
|
|
@@ -21884,7 +21988,7 @@ var require_assert_never_default = createRule({
|
|
|
21884
21988
|
});
|
|
21885
21989
|
|
|
21886
21990
|
// src/rules/require-fetch-timeout.ts
|
|
21887
|
-
import { AST_NODE_TYPES as
|
|
21991
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES103, ASTUtils as ASTUtils63 } from "@typescript-eslint/utils";
|
|
21888
21992
|
var REQUIRE_FETCH_TIMEOUT_DOCUMENTATION = {
|
|
21889
21993
|
summary: "Require an explicit abort signal on locally analyzable global fetch calls.",
|
|
21890
21994
|
rationale: "An unbounded request can occupy work indefinitely when an upstream stalls.",
|
|
@@ -21911,18 +22015,18 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
21911
22015
|
return false;
|
|
21912
22016
|
}
|
|
21913
22017
|
function initProvablyLacksSignal(init, resolvesToGlobal) {
|
|
21914
|
-
if (init.type !==
|
|
22018
|
+
if (init.type !== AST_NODE_TYPES103.ObjectExpression) return false;
|
|
21915
22019
|
let lacksSignal = true;
|
|
21916
22020
|
for (const prop of init.properties) {
|
|
21917
|
-
if (prop.type ===
|
|
22021
|
+
if (prop.type === AST_NODE_TYPES103.SpreadElement) {
|
|
21918
22022
|
lacksSignal = false;
|
|
21919
22023
|
continue;
|
|
21920
22024
|
}
|
|
21921
|
-
const isSignal = !prop.computed && prop.key.type ===
|
|
22025
|
+
const isSignal = !prop.computed && prop.key.type === AST_NODE_TYPES103.Identifier && prop.key.name === "signal" || prop.key.type === AST_NODE_TYPES103.Literal && prop.key.value === "signal";
|
|
21922
22026
|
if (isSignal) {
|
|
21923
22027
|
const value = prop.value;
|
|
21924
|
-
lacksSignal = prop.kind === "init" && !prop.method && (value.type ===
|
|
21925
|
-
} else if (prop.computed && prop.key.type !==
|
|
22028
|
+
lacksSignal = prop.kind === "init" && !prop.method && (value.type === AST_NODE_TYPES103.Literal && value.value === null || value.type === AST_NODE_TYPES103.Identifier && value.name === "undefined" && resolvesToGlobal(value) || value.type === AST_NODE_TYPES103.UnaryExpression && value.operator === "void" && value.argument.type === AST_NODE_TYPES103.Literal && value.argument.value === 0);
|
|
22029
|
+
} else if (prop.computed && prop.key.type !== AST_NODE_TYPES103.Literal) {
|
|
21926
22030
|
lacksSignal = false;
|
|
21927
22031
|
}
|
|
21928
22032
|
}
|
|
@@ -21930,7 +22034,7 @@ function initProvablyLacksSignal(init, resolvesToGlobal) {
|
|
|
21930
22034
|
}
|
|
21931
22035
|
function isInlineUrl(node, resolvesToGlobal) {
|
|
21932
22036
|
node = unwrapExpression(node);
|
|
21933
|
-
return node.type ===
|
|
22037
|
+
return node.type === AST_NODE_TYPES103.Literal && typeof node.value === "string" || node.type === AST_NODE_TYPES103.TemplateLiteral || node.type === AST_NODE_TYPES103.NewExpression && node.callee.type === AST_NODE_TYPES103.Identifier && node.callee.name === "URL" && resolvesToGlobal(node.callee);
|
|
21934
22038
|
}
|
|
21935
22039
|
var require_fetch_timeout_default = createRule({
|
|
21936
22040
|
name: "require-fetch-timeout",
|
|
@@ -21968,30 +22072,30 @@ var require_fetch_timeout_default = createRule({
|
|
|
21968
22072
|
}
|
|
21969
22073
|
function resolvesToGlobal(identifier) {
|
|
21970
22074
|
const scope = context.sourceCode.getScope(identifier);
|
|
21971
|
-
const variable =
|
|
22075
|
+
const variable = ASTUtils63.findVariable(scope, identifier.name);
|
|
21972
22076
|
return variable === null || variable.defs.length === 0;
|
|
21973
22077
|
}
|
|
21974
22078
|
function isGlobalFetchCall2(callee) {
|
|
21975
|
-
if (callee.type ===
|
|
22079
|
+
if (callee.type === AST_NODE_TYPES103.Identifier) {
|
|
21976
22080
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
21977
22081
|
}
|
|
21978
|
-
return callee.type ===
|
|
22082
|
+
return callee.type === AST_NODE_TYPES103.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES103.Identifier && callee.property.name === "fetch" && callee.object.type === AST_NODE_TYPES103.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
21979
22083
|
}
|
|
21980
22084
|
function localConstInitProvablyLacksSignal(identifier) {
|
|
21981
|
-
const variable =
|
|
22085
|
+
const variable = ASTUtils63.findVariable(
|
|
21982
22086
|
context.sourceCode.getScope(identifier),
|
|
21983
22087
|
identifier.name
|
|
21984
22088
|
);
|
|
21985
22089
|
if (variable?.defs.length !== 1) return false;
|
|
21986
22090
|
const definition = variable.defs[0];
|
|
21987
|
-
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !==
|
|
22091
|
+
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !== AST_NODE_TYPES103.ObjectExpression || !initProvablyLacksSignal(definition.node.init, resolvesToGlobal)) {
|
|
21988
22092
|
return false;
|
|
21989
22093
|
}
|
|
21990
22094
|
for (const reference of variable.references) {
|
|
21991
22095
|
const ref = reference.identifier;
|
|
21992
22096
|
if (ref === identifier || ref === definition.name) continue;
|
|
21993
22097
|
const member = ref.parent;
|
|
21994
|
-
if (member.type !==
|
|
22098
|
+
if (member.type !== AST_NODE_TYPES103.MemberExpression || member.object !== ref || member.computed || member.property.type !== AST_NODE_TYPES103.Identifier || member.property.name === "signal" || member.parent.type !== AST_NODE_TYPES103.AssignmentExpression || member.parent.left !== member) {
|
|
21995
22099
|
return false;
|
|
21996
22100
|
}
|
|
21997
22101
|
}
|
|
@@ -21999,13 +22103,13 @@ var require_fetch_timeout_default = createRule({
|
|
|
21999
22103
|
}
|
|
22000
22104
|
function isForwardedRequest(argument) {
|
|
22001
22105
|
let value = argument;
|
|
22002
|
-
if (value.type ===
|
|
22003
|
-
const binding =
|
|
22106
|
+
if (value.type === AST_NODE_TYPES103.Identifier) {
|
|
22107
|
+
const binding = ASTUtils63.findVariable(context.sourceCode.getScope(value), value.name);
|
|
22004
22108
|
const definition = binding?.defs.length === 1 ? binding.defs[0] : void 0;
|
|
22005
22109
|
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init === null || binding?.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
22006
22110
|
value = definition.node.init;
|
|
22007
22111
|
}
|
|
22008
|
-
return value.type ===
|
|
22112
|
+
return value.type === AST_NODE_TYPES103.NewExpression && value.callee.type === AST_NODE_TYPES103.Identifier && value.callee.name === "Request" && resolvesToGlobal(value.callee);
|
|
22009
22113
|
}
|
|
22010
22114
|
return {
|
|
22011
22115
|
CallExpression(node) {
|
|
@@ -22017,7 +22121,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
22017
22121
|
if (first !== void 0 && (node.arguments.length === 1 && !isInlineUrl(first, resolvesToGlobal) || isForwardedRequest(first))) {
|
|
22018
22122
|
return;
|
|
22019
22123
|
}
|
|
22020
|
-
if (init === void 0 || initProvablyLacksSignal(init, resolvesToGlobal) || init.type ===
|
|
22124
|
+
if (init === void 0 || initProvablyLacksSignal(init, resolvesToGlobal) || init.type === AST_NODE_TYPES103.Identifier && localConstInitProvablyLacksSignal(init)) {
|
|
22021
22125
|
context.report({ node, messageId: "missingSignal" });
|
|
22022
22126
|
}
|
|
22023
22127
|
}
|
|
@@ -22026,7 +22130,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
22026
22130
|
});
|
|
22027
22131
|
|
|
22028
22132
|
// src/rules/require-interface-for-exported-class.ts
|
|
22029
|
-
import { AST_NODE_TYPES as
|
|
22133
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES104 } from "@typescript-eslint/utils";
|
|
22030
22134
|
var REQUIRE_INTERFACE_FOR_EXPORTED_CLASS_DOCUMENTATION = {
|
|
22031
22135
|
defaultLevel: "warning",
|
|
22032
22136
|
summary: "Require exported concrete classes with public behavior to declare a contract.",
|
|
@@ -22073,23 +22177,23 @@ var REQUIRE_INTERFACE_FOR_EXPORTED_CLASS_DOCUMENTATION = {
|
|
|
22073
22177
|
};
|
|
22074
22178
|
function hasPublicInstanceBehavior(node) {
|
|
22075
22179
|
return node.body.body.some((member) => {
|
|
22076
|
-
if (member.type ===
|
|
22077
|
-
return member.kind !== "constructor" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.key.type !==
|
|
22180
|
+
if (member.type === AST_NODE_TYPES104.MethodDefinition) {
|
|
22181
|
+
return member.kind !== "constructor" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.key.type !== AST_NODE_TYPES104.PrivateIdentifier;
|
|
22078
22182
|
}
|
|
22079
|
-
if (member.type !==
|
|
22183
|
+
if (member.type !== AST_NODE_TYPES104.PropertyDefinition || member.static)
|
|
22080
22184
|
return false;
|
|
22081
|
-
if (member.accessibility === "private" || member.accessibility === "protected" || member.key.type ===
|
|
22082
|
-
return member.value?.type ===
|
|
22185
|
+
if (member.accessibility === "private" || member.accessibility === "protected" || member.key.type === AST_NODE_TYPES104.PrivateIdentifier) return false;
|
|
22186
|
+
return member.value?.type === AST_NODE_TYPES104.ArrowFunctionExpression || member.value?.type === AST_NODE_TYPES104.FunctionExpression || member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES104.TSFunctionType;
|
|
22083
22187
|
});
|
|
22084
22188
|
}
|
|
22085
22189
|
function classBindings(statement) {
|
|
22086
|
-
const declaration = statement.type ===
|
|
22087
|
-
if (declaration?.type ===
|
|
22190
|
+
const declaration = statement.type === AST_NODE_TYPES104.ExportNamedDeclaration ? statement.declaration : statement;
|
|
22191
|
+
if (declaration?.type === AST_NODE_TYPES104.ClassDeclaration) {
|
|
22088
22192
|
return declaration.id === null ? [] : [{ declaration, name: declaration.id.name }];
|
|
22089
22193
|
}
|
|
22090
|
-
if (declaration?.type !==
|
|
22194
|
+
if (declaration?.type !== AST_NODE_TYPES104.VariableDeclaration) return [];
|
|
22091
22195
|
return declaration.declarations.flatMap(
|
|
22092
|
-
(item) => item.id.type ===
|
|
22196
|
+
(item) => item.id.type === AST_NODE_TYPES104.Identifier && item.init?.type === AST_NODE_TYPES104.ClassExpression ? [{ declaration: item.init, name: item.id.name }] : []
|
|
22093
22197
|
);
|
|
22094
22198
|
}
|
|
22095
22199
|
var require_interface_for_exported_class_default = createRule({
|
|
@@ -22123,7 +22227,7 @@ var require_interface_for_exported_class_default = createRule({
|
|
|
22123
22227
|
}
|
|
22124
22228
|
const exported = exportedClasses(program, classes);
|
|
22125
22229
|
for (const [declaration, exportedName] of exported) {
|
|
22126
|
-
const extendsLocalAbstractBase = declaration.superClass?.type ===
|
|
22230
|
+
const extendsLocalAbstractBase = declaration.superClass?.type === AST_NODE_TYPES104.Identifier && abstractBases.has(declaration.superClass.name);
|
|
22127
22231
|
if (declaration.abstract || declaration.implements.length > 0 || extendsLocalAbstractBase || !hasPublicInstanceBehavior(declaration)) continue;
|
|
22128
22232
|
context.report({
|
|
22129
22233
|
node: declaration.id ?? declaration,
|
|
@@ -22138,7 +22242,7 @@ var require_interface_for_exported_class_default = createRule({
|
|
|
22138
22242
|
function exportedClasses(program, classes) {
|
|
22139
22243
|
const exported = /* @__PURE__ */ new Map();
|
|
22140
22244
|
function collectExportedClass(statement) {
|
|
22141
|
-
if (statement.type ===
|
|
22245
|
+
if (statement.type === AST_NODE_TYPES104.ExportNamedDeclaration) {
|
|
22142
22246
|
for (const binding of classBindings(statement)) {
|
|
22143
22247
|
exported.set(binding.declaration, binding.name);
|
|
22144
22248
|
}
|
|
@@ -22146,13 +22250,13 @@ function exportedClasses(program, classes) {
|
|
|
22146
22250
|
collectClassSpecifiers(statement);
|
|
22147
22251
|
return;
|
|
22148
22252
|
}
|
|
22149
|
-
if (statement.type !==
|
|
22150
|
-
if (statement.declaration.type ===
|
|
22253
|
+
if (statement.type !== AST_NODE_TYPES104.ExportDefaultDeclaration) return;
|
|
22254
|
+
if (statement.declaration.type === AST_NODE_TYPES104.ClassDeclaration || statement.declaration.type === AST_NODE_TYPES104.ClassExpression) {
|
|
22151
22255
|
exported.set(
|
|
22152
22256
|
statement.declaration,
|
|
22153
22257
|
statement.declaration.id?.name ?? "default"
|
|
22154
22258
|
);
|
|
22155
|
-
} else if (statement.declaration.type ===
|
|
22259
|
+
} else if (statement.declaration.type === AST_NODE_TYPES104.Identifier) {
|
|
22156
22260
|
const candidate2 = classes.get(statement.declaration.name);
|
|
22157
22261
|
if (candidate2 !== void 0) {
|
|
22158
22262
|
exported.set(candidate2, statement.declaration.name);
|
|
@@ -22164,7 +22268,7 @@ function exportedClasses(program, classes) {
|
|
|
22164
22268
|
if (specifier.exportKind === "type") continue;
|
|
22165
22269
|
const candidate2 = classes.get(specifier.local.name);
|
|
22166
22270
|
if (candidate2 === void 0) continue;
|
|
22167
|
-
const exportedName = specifier.exported.type ===
|
|
22271
|
+
const exportedName = specifier.exported.type === AST_NODE_TYPES104.Identifier ? specifier.exported.name : specifier.exported.value;
|
|
22168
22272
|
exported.set(candidate2, exportedName);
|
|
22169
22273
|
}
|
|
22170
22274
|
}
|
|
@@ -22175,7 +22279,7 @@ function exportedClasses(program, classes) {
|
|
|
22175
22279
|
}
|
|
22176
22280
|
|
|
22177
22281
|
// src/rules/require-sql-access-class.ts
|
|
22178
|
-
import { AST_NODE_TYPES as
|
|
22282
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES105, ASTUtils as ASTUtils64 } from "@typescript-eslint/utils";
|
|
22179
22283
|
var DIRECT_EXECUTION_METHODS = /* @__PURE__ */ new Set([
|
|
22180
22284
|
"all",
|
|
22181
22285
|
"batch",
|
|
@@ -22279,80 +22383,80 @@ function isDatabaseOperation(method, receiver) {
|
|
|
22279
22383
|
}
|
|
22280
22384
|
function databaseReceiver(node) {
|
|
22281
22385
|
node = unwrapExpression(node);
|
|
22282
|
-
if (node.type ===
|
|
22386
|
+
if (node.type === AST_NODE_TYPES105.Identifier)
|
|
22283
22387
|
return DATABASE_NAMES.test(node.name);
|
|
22284
|
-
if (node.type !==
|
|
22285
|
-
const name =
|
|
22388
|
+
if (node.type !== AST_NODE_TYPES105.MemberExpression) return false;
|
|
22389
|
+
const name = ASTUtils64.getPropertyName(node);
|
|
22286
22390
|
return name === "DB" || name !== null && DATABASE_NAMES.test(name);
|
|
22287
22391
|
}
|
|
22288
22392
|
function databaseRootMember(node) {
|
|
22289
22393
|
let current = node;
|
|
22290
22394
|
for (; ; ) {
|
|
22291
22395
|
current = unwrapExpression(current);
|
|
22292
|
-
if (current.type ===
|
|
22396
|
+
if (current.type === AST_NODE_TYPES105.ChainExpression) {
|
|
22293
22397
|
current = current.expression;
|
|
22294
22398
|
continue;
|
|
22295
22399
|
}
|
|
22296
|
-
if (current.type ===
|
|
22297
|
-
if (current.callee.type !==
|
|
22400
|
+
if (current.type === AST_NODE_TYPES105.CallExpression) {
|
|
22401
|
+
if (current.callee.type !== AST_NODE_TYPES105.MemberExpression) return null;
|
|
22298
22402
|
current = current.callee.object;
|
|
22299
22403
|
continue;
|
|
22300
22404
|
}
|
|
22301
|
-
if (current.type ===
|
|
22302
|
-
if (current.object.type ===
|
|
22303
|
-
return
|
|
22405
|
+
if (current.type === AST_NODE_TYPES105.MemberExpression) {
|
|
22406
|
+
if (current.object.type === AST_NODE_TYPES105.ThisExpression)
|
|
22407
|
+
return ASTUtils64.getPropertyName(current);
|
|
22304
22408
|
current = current.object;
|
|
22305
22409
|
continue;
|
|
22306
22410
|
}
|
|
22307
|
-
return current.type ===
|
|
22411
|
+
return current.type === AST_NODE_TYPES105.Identifier ? current.name : null;
|
|
22308
22412
|
}
|
|
22309
22413
|
}
|
|
22310
22414
|
function expressionHasDatabaseMarker(node) {
|
|
22311
22415
|
let current = node;
|
|
22312
22416
|
for (; ; ) {
|
|
22313
22417
|
current = unwrapExpression(current);
|
|
22314
|
-
if (current.type ===
|
|
22418
|
+
if (current.type === AST_NODE_TYPES105.ChainExpression) {
|
|
22315
22419
|
current = current.expression;
|
|
22316
22420
|
continue;
|
|
22317
22421
|
}
|
|
22318
|
-
if (current.type ===
|
|
22319
|
-
if (current.callee.type !==
|
|
22422
|
+
if (current.type === AST_NODE_TYPES105.CallExpression) {
|
|
22423
|
+
if (current.callee.type !== AST_NODE_TYPES105.MemberExpression) return false;
|
|
22320
22424
|
current = current.callee.object;
|
|
22321
22425
|
continue;
|
|
22322
22426
|
}
|
|
22323
|
-
if (current.type ===
|
|
22324
|
-
const name =
|
|
22427
|
+
if (current.type === AST_NODE_TYPES105.MemberExpression) {
|
|
22428
|
+
const name = ASTUtils64.getPropertyName(current);
|
|
22325
22429
|
if (name === "DB" || name !== null && DATABASE_NAMES.test(name))
|
|
22326
22430
|
return true;
|
|
22327
22431
|
current = current.object;
|
|
22328
22432
|
continue;
|
|
22329
22433
|
}
|
|
22330
|
-
return current.type ===
|
|
22434
|
+
return current.type === AST_NODE_TYPES105.Identifier && DATABASE_NAMES.test(current.name);
|
|
22331
22435
|
}
|
|
22332
22436
|
}
|
|
22333
22437
|
function expressionCallsBuilder(node) {
|
|
22334
22438
|
let current = node;
|
|
22335
22439
|
for (; ; ) {
|
|
22336
22440
|
current = unwrapExpression(current);
|
|
22337
|
-
if (current.type ===
|
|
22441
|
+
if (current.type === AST_NODE_TYPES105.ChainExpression) {
|
|
22338
22442
|
current = current.expression;
|
|
22339
22443
|
continue;
|
|
22340
22444
|
}
|
|
22341
|
-
if (current.type ===
|
|
22342
|
-
if (current.callee.type !==
|
|
22343
|
-
const name =
|
|
22445
|
+
if (current.type === AST_NODE_TYPES105.CallExpression) {
|
|
22446
|
+
if (current.callee.type !== AST_NODE_TYPES105.MemberExpression) return false;
|
|
22447
|
+
const name = ASTUtils64.getPropertyName(current.callee);
|
|
22344
22448
|
if (name !== null && BUILDER_METHODS.has(name)) return true;
|
|
22345
22449
|
current = current.callee.object;
|
|
22346
22450
|
continue;
|
|
22347
22451
|
}
|
|
22348
|
-
if (current.type !==
|
|
22452
|
+
if (current.type !== AST_NODE_TYPES105.MemberExpression) return false;
|
|
22349
22453
|
current = current.object;
|
|
22350
22454
|
}
|
|
22351
22455
|
}
|
|
22352
22456
|
function owningClass2(node) {
|
|
22353
22457
|
let current = node.parent;
|
|
22354
22458
|
while (current != null) {
|
|
22355
|
-
if (current.type ===
|
|
22459
|
+
if (current.type === AST_NODE_TYPES105.ClassDeclaration || current.type === AST_NODE_TYPES105.ClassExpression)
|
|
22356
22460
|
return current;
|
|
22357
22461
|
current = current.parent;
|
|
22358
22462
|
}
|
|
@@ -22361,25 +22465,25 @@ function owningClass2(node) {
|
|
|
22361
22465
|
function injectedMembers(owner) {
|
|
22362
22466
|
const injected = /* @__PURE__ */ new Set();
|
|
22363
22467
|
const constructor = owner.body.body.find(
|
|
22364
|
-
(member) => member.type ===
|
|
22468
|
+
(member) => member.type === AST_NODE_TYPES105.MethodDefinition && member.kind === "constructor"
|
|
22365
22469
|
);
|
|
22366
22470
|
if (constructor === void 0) return injected;
|
|
22367
22471
|
const parameters = /* @__PURE__ */ new Set();
|
|
22368
22472
|
for (const parameter of constructor.value.params) {
|
|
22369
22473
|
for (const name of parameterNames(parameter)) parameters.add(name);
|
|
22370
|
-
if (parameter.type !==
|
|
22371
|
-
const value = parameter.parameter.type ===
|
|
22372
|
-
if (value.type ===
|
|
22474
|
+
if (parameter.type !== AST_NODE_TYPES105.TSParameterProperty) continue;
|
|
22475
|
+
const value = parameter.parameter.type === AST_NODE_TYPES105.AssignmentPattern ? parameter.parameter.left : parameter.parameter;
|
|
22476
|
+
if (value.type === AST_NODE_TYPES105.Identifier) injected.add(value.name);
|
|
22373
22477
|
}
|
|
22374
22478
|
const body2 = constructor.value.body;
|
|
22375
22479
|
if (body2 === null) return injected;
|
|
22376
22480
|
function collectInjectedMember(statement) {
|
|
22377
|
-
if (statement.type !==
|
|
22481
|
+
if (statement.type !== AST_NODE_TYPES105.ExpressionStatement || statement.expression.type !== AST_NODE_TYPES105.AssignmentExpression || statement.expression.operator !== "=") return;
|
|
22378
22482
|
const { left, right } = statement.expression;
|
|
22379
|
-
if (left.type !==
|
|
22483
|
+
if (left.type !== AST_NODE_TYPES105.MemberExpression) return;
|
|
22380
22484
|
const target = thisRootMember(left);
|
|
22381
22485
|
if (target === null) return;
|
|
22382
|
-
const source = right.type ===
|
|
22486
|
+
const source = right.type === AST_NODE_TYPES105.Identifier ? right.name : right.type === AST_NODE_TYPES105.MemberExpression && right.object.type === AST_NODE_TYPES105.Identifier ? right.object.name : null;
|
|
22383
22487
|
if (source !== null && parameters.has(source)) injected.add(target);
|
|
22384
22488
|
}
|
|
22385
22489
|
for (const statement of body2.body) {
|
|
@@ -22390,26 +22494,26 @@ function injectedMembers(owner) {
|
|
|
22390
22494
|
function thisRootMember(node) {
|
|
22391
22495
|
let current = node;
|
|
22392
22496
|
let root = null;
|
|
22393
|
-
while (current.type ===
|
|
22394
|
-
const name =
|
|
22497
|
+
while (current.type === AST_NODE_TYPES105.MemberExpression) {
|
|
22498
|
+
const name = ASTUtils64.getPropertyName(current);
|
|
22395
22499
|
if (name === null) return null;
|
|
22396
22500
|
root = name;
|
|
22397
22501
|
current = current.object;
|
|
22398
22502
|
}
|
|
22399
|
-
return current.type ===
|
|
22503
|
+
return current.type === AST_NODE_TYPES105.ThisExpression ? root : null;
|
|
22400
22504
|
}
|
|
22401
22505
|
function parameterNames(parameter) {
|
|
22402
22506
|
let value = parameter;
|
|
22403
|
-
if (value.type ===
|
|
22404
|
-
if (value.type ===
|
|
22405
|
-
if (value.type ===
|
|
22406
|
-
if (value.type !==
|
|
22507
|
+
if (value.type === AST_NODE_TYPES105.TSParameterProperty) value = value.parameter;
|
|
22508
|
+
if (value.type === AST_NODE_TYPES105.AssignmentPattern) value = value.left;
|
|
22509
|
+
if (value.type === AST_NODE_TYPES105.Identifier) return /* @__PURE__ */ new Set([value.name]);
|
|
22510
|
+
if (value.type !== AST_NODE_TYPES105.ObjectPattern) return /* @__PURE__ */ new Set();
|
|
22407
22511
|
return new Set(
|
|
22408
22512
|
value.properties.flatMap((property) => {
|
|
22409
|
-
if (property.type ===
|
|
22410
|
-
return property.argument.type ===
|
|
22411
|
-
const target = property.value.type ===
|
|
22412
|
-
return target.type ===
|
|
22513
|
+
if (property.type === AST_NODE_TYPES105.RestElement)
|
|
22514
|
+
return property.argument.type === AST_NODE_TYPES105.Identifier ? [property.argument.name] : [];
|
|
22515
|
+
const target = property.value.type === AST_NODE_TYPES105.AssignmentPattern ? property.value.left : property.value;
|
|
22516
|
+
return target.type === AST_NODE_TYPES105.Identifier ? [target.name] : [];
|
|
22413
22517
|
})
|
|
22414
22518
|
);
|
|
22415
22519
|
}
|
|
@@ -22434,20 +22538,20 @@ var require_sql_access_class_default = createRule({
|
|
|
22434
22538
|
const unwrappedNodeCallee = node.type === "CallExpression" || node.type === "NewExpression" ? unwrapExpression(node.callee) : null;
|
|
22435
22539
|
if (seen.has(node)) return false;
|
|
22436
22540
|
seen.add(node);
|
|
22437
|
-
if (node.type ===
|
|
22438
|
-
const binding =
|
|
22541
|
+
if (node.type === AST_NODE_TYPES105.Identifier) {
|
|
22542
|
+
const binding = ASTUtils64.findVariable(context.sourceCode.getScope(node), node.name);
|
|
22439
22543
|
if (binding?.defs.length !== 1 || binding.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
22440
22544
|
const definition = binding.defs[0];
|
|
22441
22545
|
return definition?.type === "Variable" && definition.node.init !== null && knownNonDatabase(definition.node.init, seen);
|
|
22442
22546
|
}
|
|
22443
|
-
return node.type ===
|
|
22547
|
+
return node.type === AST_NODE_TYPES105.NewExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES105.Identifier && ["Map", "WeakMap", "URLSearchParams"].includes(unwrappedNodeCallee.name) && (ASTUtils64.findVariable(context.sourceCode.getScope(unwrappedNodeCallee), unwrappedNodeCallee.name)?.defs.length ?? 0) === 0;
|
|
22444
22548
|
}
|
|
22445
22549
|
return {
|
|
22446
22550
|
CallExpression(node) {
|
|
22447
22551
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
22448
|
-
if (unwrappedNodeCallee.type !==
|
|
22552
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES105.MemberExpression)
|
|
22449
22553
|
return;
|
|
22450
|
-
const method =
|
|
22554
|
+
const method = ASTUtils64.getPropertyName(unwrappedNodeCallee);
|
|
22451
22555
|
if (knownNonDatabase(unwrappedNodeCallee.object)) return;
|
|
22452
22556
|
if (method === null || !isDatabaseOperation(method, unwrappedNodeCallee.object))
|
|
22453
22557
|
return;
|
|
@@ -22463,7 +22567,7 @@ var require_sql_access_class_default = createRule({
|
|
|
22463
22567
|
});
|
|
22464
22568
|
|
|
22465
22569
|
// src/rules/require-static-next-matcher.ts
|
|
22466
|
-
import { AST_NODE_TYPES as
|
|
22570
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES106 } from "@typescript-eslint/utils";
|
|
22467
22571
|
var REQUIRE_STATIC_NEXT_MATCHER_DOCUMENTATION = {
|
|
22468
22572
|
summary: "Require Next.js middleware and proxy matcher configuration to contain only build-time literals.",
|
|
22469
22573
|
rationale: "Next.js must statically analyze matcher values at build time; computed values are ignored.",
|
|
@@ -22479,27 +22583,27 @@ var REQUIRE_STATIC_NEXT_MATCHER_DOCUMENTATION = {
|
|
|
22479
22583
|
var NEXT_ENTRY_FILE = /(?:^|[/\\])(?:middleware|proxy)\.[cm]?[jt]sx?$/u;
|
|
22480
22584
|
function isStaticValue(node) {
|
|
22481
22585
|
const value = unwrapExpression(node);
|
|
22482
|
-
if (value.type ===
|
|
22586
|
+
if (value.type === AST_NODE_TYPES106.Literal) {
|
|
22483
22587
|
return true;
|
|
22484
22588
|
}
|
|
22485
|
-
if (value.type ===
|
|
22589
|
+
if (value.type === AST_NODE_TYPES106.TemplateLiteral) {
|
|
22486
22590
|
return value.expressions.length === 0;
|
|
22487
22591
|
}
|
|
22488
|
-
if (value.type ===
|
|
22592
|
+
if (value.type === AST_NODE_TYPES106.ArrayExpression) {
|
|
22489
22593
|
return value.elements.every(
|
|
22490
|
-
(element) => element !== null && element.type !==
|
|
22594
|
+
(element) => element !== null && element.type !== AST_NODE_TYPES106.SpreadElement && isStaticValue(element)
|
|
22491
22595
|
);
|
|
22492
22596
|
}
|
|
22493
|
-
if (value.type ===
|
|
22597
|
+
if (value.type === AST_NODE_TYPES106.ObjectExpression) {
|
|
22494
22598
|
return value.properties.every(
|
|
22495
|
-
(property) => property.type ===
|
|
22599
|
+
(property) => property.type === AST_NODE_TYPES106.Property && property.kind === "init" && !property.computed && property.value.type !== AST_NODE_TYPES106.AssignmentPattern && isStaticValue(property.value)
|
|
22496
22600
|
);
|
|
22497
22601
|
}
|
|
22498
22602
|
return false;
|
|
22499
22603
|
}
|
|
22500
22604
|
function propertyName5(property) {
|
|
22501
|
-
if (!property.computed && property.key.type ===
|
|
22502
|
-
return property.key.type ===
|
|
22605
|
+
if (!property.computed && property.key.type === AST_NODE_TYPES106.Identifier) return property.key.name;
|
|
22606
|
+
return property.key.type === AST_NODE_TYPES106.Literal && typeof property.key.value === "string" ? property.key.value : null;
|
|
22503
22607
|
}
|
|
22504
22608
|
var require_static_next_matcher_default = createRule({
|
|
22505
22609
|
name: "require-static-next-matcher",
|
|
@@ -22521,19 +22625,19 @@ var require_static_next_matcher_default = createRule({
|
|
|
22521
22625
|
}
|
|
22522
22626
|
return {
|
|
22523
22627
|
ExportNamedDeclaration(node) {
|
|
22524
|
-
if (node.declaration?.type !==
|
|
22628
|
+
if (node.declaration?.type !== AST_NODE_TYPES106.VariableDeclaration) {
|
|
22525
22629
|
return;
|
|
22526
22630
|
}
|
|
22527
22631
|
for (const declaration of node.declaration.declarations) {
|
|
22528
|
-
if (declaration.id.type !==
|
|
22632
|
+
if (declaration.id.type !== AST_NODE_TYPES106.Identifier || declaration.id.name !== "config" || declaration.init === null) {
|
|
22529
22633
|
continue;
|
|
22530
22634
|
}
|
|
22531
22635
|
const config = unwrapExpression(declaration.init);
|
|
22532
|
-
if (config.type !==
|
|
22636
|
+
if (config.type !== AST_NODE_TYPES106.ObjectExpression) {
|
|
22533
22637
|
continue;
|
|
22534
22638
|
}
|
|
22535
22639
|
for (const property of config.properties) {
|
|
22536
|
-
if (property.type !==
|
|
22640
|
+
if (property.type !== AST_NODE_TYPES106.Property || propertyName5(property) !== "matcher" || property.value.type === AST_NODE_TYPES106.AssignmentPattern) {
|
|
22537
22641
|
continue;
|
|
22538
22642
|
}
|
|
22539
22643
|
if (!isStaticValue(property.value)) {
|
|
@@ -22547,7 +22651,7 @@ var require_static_next_matcher_default = createRule({
|
|
|
22547
22651
|
});
|
|
22548
22652
|
|
|
22549
22653
|
// src/rules/require-use-form-default-values.ts
|
|
22550
|
-
import { AST_NODE_TYPES as
|
|
22654
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES107, ASTUtils as ASTUtils65 } from "@typescript-eslint/utils";
|
|
22551
22655
|
var REQUIRE_USE_FORM_DEFAULT_VALUES_DOCUMENTATION = {
|
|
22552
22656
|
summary: "Require explicit form-level initialization or a field default for directly bound Controller fields.",
|
|
22553
22657
|
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.",
|
|
@@ -22580,8 +22684,8 @@ var REQUIRE_USE_FORM_DEFAULT_VALUES_DOCUMENTATION = {
|
|
|
22580
22684
|
};
|
|
22581
22685
|
function staticPropertyName2(property) {
|
|
22582
22686
|
if (property.computed) return null;
|
|
22583
|
-
if (property.key.type ===
|
|
22584
|
-
if (property.key.type ===
|
|
22687
|
+
if (property.key.type === AST_NODE_TYPES107.Identifier) return property.key.name;
|
|
22688
|
+
if (property.key.type === AST_NODE_TYPES107.Literal && typeof property.key.value === "string") return property.key.value;
|
|
22585
22689
|
return null;
|
|
22586
22690
|
}
|
|
22587
22691
|
var require_use_form_default_values_default = createRule({
|
|
@@ -22598,7 +22702,7 @@ var require_use_form_default_values_default = createRule({
|
|
|
22598
22702
|
const imported = /* @__PURE__ */ new Map();
|
|
22599
22703
|
const uninitializedForms = /* @__PURE__ */ new Set();
|
|
22600
22704
|
const uninitializedControls = /* @__PURE__ */ new Set();
|
|
22601
|
-
const bindingNamed = (node, name) =>
|
|
22705
|
+
const bindingNamed = (node, name) => ASTUtils65.findVariable(context.sourceCode.getScope(node), name);
|
|
22602
22706
|
const bindingOf = (node) => bindingNamed(node, node.name);
|
|
22603
22707
|
const stable = (variable) => !variable.references.some((reference) => reference.isWrite() && reference.init !== true);
|
|
22604
22708
|
const importedKind = (node) => {
|
|
@@ -22611,22 +22715,22 @@ var require_use_form_default_values_default = createRule({
|
|
|
22611
22715
|
};
|
|
22612
22716
|
const isDefinitelyUndefined = (node) => {
|
|
22613
22717
|
const value = unwrapExpression(node);
|
|
22614
|
-
return value.type ===
|
|
22718
|
+
return value.type === AST_NODE_TYPES107.UnaryExpression && value.operator === "void" || value.type === AST_NODE_TYPES107.Identifier && value.name === "undefined" && (bindingOf(value)?.defs.length ?? 0) === 0;
|
|
22615
22719
|
};
|
|
22616
22720
|
const uninitializedUseFormCall = (node) => {
|
|
22617
22721
|
node = unwrapExpression(node);
|
|
22618
22722
|
const unwrappedNodeCallee = node.type === "CallExpression" || node.type === "NewExpression" ? unwrapExpression(node.callee) : null;
|
|
22619
|
-
if (node.type !==
|
|
22723
|
+
if (node.type !== AST_NODE_TYPES107.CallExpression || unwrappedNodeCallee?.type !== AST_NODE_TYPES107.Identifier || importedKind(unwrappedNodeCallee) !== "useForm") return false;
|
|
22620
22724
|
const options = node.arguments[0];
|
|
22621
|
-
return options?.type !==
|
|
22725
|
+
return options?.type !== AST_NODE_TYPES107.SpreadElement && initializationState(options) === "uninitialized";
|
|
22622
22726
|
};
|
|
22623
22727
|
const initializationState = (node) => {
|
|
22624
22728
|
if (node === void 0) return "uninitialized";
|
|
22625
|
-
if (node.type !==
|
|
22729
|
+
if (node.type !== AST_NODE_TYPES107.ObjectExpression) return "unknown";
|
|
22626
22730
|
const initialization = /* @__PURE__ */ new Map();
|
|
22627
22731
|
for (const property of node.properties) {
|
|
22628
|
-
if (property.type ===
|
|
22629
|
-
if (property.type !==
|
|
22732
|
+
if (property.type === AST_NODE_TYPES107.SpreadElement || property.computed) return "unknown";
|
|
22733
|
+
if (property.type !== AST_NODE_TYPES107.Property) continue;
|
|
22630
22734
|
const name = staticPropertyName2(property);
|
|
22631
22735
|
if (name === "defaultValues" || name === "values") initialization.set(name, !isDefinitelyUndefined(property.value));
|
|
22632
22736
|
}
|
|
@@ -22634,25 +22738,25 @@ var require_use_form_default_values_default = createRule({
|
|
|
22634
22738
|
};
|
|
22635
22739
|
const isUninitializedForm = (node) => {
|
|
22636
22740
|
node = unwrapExpression(node);
|
|
22637
|
-
if (node.type !==
|
|
22741
|
+
if (node.type !== AST_NODE_TYPES107.Identifier) return false;
|
|
22638
22742
|
const variable = bindingOf(node);
|
|
22639
22743
|
return variable !== null && stable(variable) && uninitializedForms.has(variable);
|
|
22640
22744
|
};
|
|
22641
22745
|
const isUninitializedControl = (node) => {
|
|
22642
22746
|
node = unwrapExpression(node);
|
|
22643
|
-
if (node.type ===
|
|
22747
|
+
if (node.type === AST_NODE_TYPES107.Identifier) {
|
|
22644
22748
|
const variable = bindingOf(node);
|
|
22645
22749
|
return variable !== null && stable(variable) && uninitializedControls.has(variable);
|
|
22646
22750
|
}
|
|
22647
|
-
return node.type ===
|
|
22751
|
+
return node.type === AST_NODE_TYPES107.MemberExpression && ASTUtils65.getPropertyName(node) !== null && (ASTUtils65.getPropertyName(node) ?? "") === "control" && isUninitializedForm(node.object);
|
|
22648
22752
|
};
|
|
22649
22753
|
const fieldOptionsNeedDefault = (node) => {
|
|
22650
|
-
if (node?.type !==
|
|
22754
|
+
if (node?.type !== AST_NODE_TYPES107.ObjectExpression) return false;
|
|
22651
22755
|
let control = null;
|
|
22652
22756
|
let hasDefault = false;
|
|
22653
22757
|
for (const property of node.properties) {
|
|
22654
|
-
if (property.type ===
|
|
22655
|
-
if (property.type !==
|
|
22758
|
+
if (property.type === AST_NODE_TYPES107.SpreadElement || property.computed) return false;
|
|
22759
|
+
if (property.type !== AST_NODE_TYPES107.Property) continue;
|
|
22656
22760
|
const name = staticPropertyName2(property);
|
|
22657
22761
|
if (name === "control") control = property.value;
|
|
22658
22762
|
if (name === "defaultValue") hasDefault = !isDefinitelyUndefined(property.value);
|
|
@@ -22662,14 +22766,14 @@ var require_use_form_default_values_default = createRule({
|
|
|
22662
22766
|
const jsxAttribute = (node, name) => {
|
|
22663
22767
|
let result = null;
|
|
22664
22768
|
for (const attribute of node.attributes) {
|
|
22665
|
-
if (attribute.type ===
|
|
22666
|
-
if (attribute.name.type ===
|
|
22769
|
+
if (attribute.type === AST_NODE_TYPES107.JSXSpreadAttribute) return null;
|
|
22770
|
+
if (attribute.name.type === AST_NODE_TYPES107.JSXIdentifier && attribute.name.name === name) result = attribute;
|
|
22667
22771
|
}
|
|
22668
22772
|
return result;
|
|
22669
22773
|
};
|
|
22670
22774
|
const trackDestructuredControl = (pattern) => {
|
|
22671
22775
|
for (const property of pattern.properties) {
|
|
22672
|
-
if (property.type !==
|
|
22776
|
+
if (property.type !== AST_NODE_TYPES107.Property || staticPropertyName2(property) !== "control" || property.value.type !== AST_NODE_TYPES107.Identifier) continue;
|
|
22673
22777
|
const variable = bindingOf(property.value);
|
|
22674
22778
|
if (variable !== null) uninitializedControls.add(variable);
|
|
22675
22779
|
}
|
|
@@ -22678,8 +22782,8 @@ var require_use_form_default_values_default = createRule({
|
|
|
22678
22782
|
ImportDeclaration(node) {
|
|
22679
22783
|
if (node.source.value !== "react-hook-form") return;
|
|
22680
22784
|
for (const specifier of node.specifiers) {
|
|
22681
|
-
if (specifier.type !==
|
|
22682
|
-
const name = specifier.imported.type ===
|
|
22785
|
+
if (specifier.type !== AST_NODE_TYPES107.ImportSpecifier) continue;
|
|
22786
|
+
const name = specifier.imported.type === AST_NODE_TYPES107.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
22683
22787
|
if (name !== "Controller" && name !== "useController" && name !== "useForm") continue;
|
|
22684
22788
|
const variable = bindingOf(specifier.local);
|
|
22685
22789
|
if (variable !== null) imported.set(variable, name);
|
|
@@ -22688,35 +22792,35 @@ var require_use_form_default_values_default = createRule({
|
|
|
22688
22792
|
VariableDeclarator(node) {
|
|
22689
22793
|
if (node.init === null) return;
|
|
22690
22794
|
if (uninitializedUseFormCall(node.init)) {
|
|
22691
|
-
if (node.id.type ===
|
|
22795
|
+
if (node.id.type === AST_NODE_TYPES107.Identifier) {
|
|
22692
22796
|
const variable = bindingOf(node.id);
|
|
22693
22797
|
if (variable !== null) uninitializedForms.add(variable);
|
|
22694
|
-
} else if (node.id.type ===
|
|
22798
|
+
} else if (node.id.type === AST_NODE_TYPES107.ObjectPattern) {
|
|
22695
22799
|
trackDestructuredControl(node.id);
|
|
22696
22800
|
}
|
|
22697
22801
|
return;
|
|
22698
22802
|
}
|
|
22699
|
-
if (node.id.type ===
|
|
22803
|
+
if (node.id.type === AST_NODE_TYPES107.ObjectPattern && isUninitializedForm(node.init)) {
|
|
22700
22804
|
trackDestructuredControl(node.id);
|
|
22701
22805
|
return;
|
|
22702
22806
|
}
|
|
22703
|
-
if (node.id.type ===
|
|
22807
|
+
if (node.id.type === AST_NODE_TYPES107.Identifier && node.init.type === AST_NODE_TYPES107.MemberExpression && ASTUtils65.getPropertyName(node.init) !== null && (ASTUtils65.getPropertyName(node.init) ?? "") === "control" && isUninitializedForm(node.init.object)) {
|
|
22704
22808
|
const variable = bindingOf(node.id);
|
|
22705
22809
|
if (variable !== null) uninitializedControls.add(variable);
|
|
22706
22810
|
}
|
|
22707
22811
|
},
|
|
22708
22812
|
CallExpression(node) {
|
|
22709
22813
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
22710
|
-
if (unwrappedNodeCallee.type !==
|
|
22814
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES107.Identifier || importedKind(unwrappedNodeCallee) !== "useController" || !fieldOptionsNeedDefault(node.arguments[0]?.type === AST_NODE_TYPES107.SpreadElement ? void 0 : node.arguments[0])) return;
|
|
22711
22815
|
context.report({ node, messageId: "requireUseFormDefaultValues" });
|
|
22712
22816
|
},
|
|
22713
22817
|
JSXOpeningElement(node) {
|
|
22714
|
-
if (node.name.type !==
|
|
22715
|
-
if (node.attributes.some((attribute) => attribute.type ===
|
|
22818
|
+
if (node.name.type !== AST_NODE_TYPES107.JSXIdentifier || importedJsxKind(node.name) !== "Controller") return;
|
|
22819
|
+
if (node.attributes.some((attribute) => attribute.type === AST_NODE_TYPES107.JSXSpreadAttribute)) return;
|
|
22716
22820
|
const control = jsxAttribute(node, "control");
|
|
22717
|
-
if (control?.value?.type !==
|
|
22821
|
+
if (control?.value?.type !== AST_NODE_TYPES107.JSXExpressionContainer || control.value.expression.type === AST_NODE_TYPES107.JSXEmptyExpression || !isUninitializedControl(control.value.expression)) return;
|
|
22718
22822
|
const defaultValue = jsxAttribute(node, "defaultValue");
|
|
22719
|
-
if (defaultValue !== null && (defaultValue.value === null || defaultValue.value.type !==
|
|
22823
|
+
if (defaultValue !== null && (defaultValue.value === null || defaultValue.value.type !== AST_NODE_TYPES107.JSXExpressionContainer || defaultValue.value.expression.type !== AST_NODE_TYPES107.JSXEmptyExpression && !isDefinitelyUndefined(defaultValue.value.expression))) return;
|
|
22720
22824
|
context.report({ node, messageId: "requireUseFormDefaultValues" });
|
|
22721
22825
|
}
|
|
22722
22826
|
};
|
|
@@ -22792,8 +22896,8 @@ var require_use_server_in_actions_file_default = createRule({
|
|
|
22792
22896
|
|
|
22793
22897
|
// src/rules/require-zod-form-validation.ts
|
|
22794
22898
|
import {
|
|
22795
|
-
AST_NODE_TYPES as
|
|
22796
|
-
ASTUtils as
|
|
22899
|
+
AST_NODE_TYPES as AST_NODE_TYPES108,
|
|
22900
|
+
ASTUtils as ASTUtils66
|
|
22797
22901
|
} from "@typescript-eslint/utils";
|
|
22798
22902
|
var REQUIRE_ZOD_FORM_VALIDATION_DOCUMENTATION = {
|
|
22799
22903
|
summary: "Require Zod validation (`Schema.parse(...)` / `Schema.safeParse(...)`) when reading values out of a `FormData` object.",
|
|
@@ -22820,14 +22924,14 @@ var FORM_VALUE_METHODS = /* @__PURE__ */ new Set(["get", "getAll"]);
|
|
|
22820
22924
|
var zodReceiverRoot = (node) => {
|
|
22821
22925
|
let current = node;
|
|
22822
22926
|
while (true) {
|
|
22823
|
-
if (current.type ===
|
|
22927
|
+
if (current.type === AST_NODE_TYPES108.Identifier) {
|
|
22824
22928
|
return current;
|
|
22825
22929
|
}
|
|
22826
|
-
if (current.type ===
|
|
22930
|
+
if (current.type === AST_NODE_TYPES108.CallExpression) {
|
|
22827
22931
|
current = current.callee;
|
|
22828
22932
|
continue;
|
|
22829
22933
|
}
|
|
22830
|
-
if (current.type ===
|
|
22934
|
+
if (current.type === AST_NODE_TYPES108.MemberExpression) {
|
|
22831
22935
|
current = current.object;
|
|
22832
22936
|
continue;
|
|
22833
22937
|
}
|
|
@@ -22836,12 +22940,12 @@ var zodReceiverRoot = (node) => {
|
|
|
22836
22940
|
};
|
|
22837
22941
|
var isFormDataMethodCall = (node) => {
|
|
22838
22942
|
let current = node;
|
|
22839
|
-
if (current.type ===
|
|
22943
|
+
if (current.type === AST_NODE_TYPES108.AwaitExpression) {
|
|
22840
22944
|
current = current.argument;
|
|
22841
22945
|
}
|
|
22842
|
-
if (current.type !==
|
|
22946
|
+
if (current.type !== AST_NODE_TYPES108.CallExpression) return false;
|
|
22843
22947
|
const callee = unwrapExpression(current.callee);
|
|
22844
|
-
return callee.type ===
|
|
22948
|
+
return callee.type === AST_NODE_TYPES108.MemberExpression && ASTUtils66.getPropertyName(callee) === "formData";
|
|
22845
22949
|
};
|
|
22846
22950
|
var require_zod_form_validation_default = createRule({
|
|
22847
22951
|
name: "require-zod-form-validation",
|
|
@@ -22862,29 +22966,29 @@ var require_zod_form_validation_default = createRule({
|
|
|
22862
22966
|
return {};
|
|
22863
22967
|
}
|
|
22864
22968
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
22865
|
-
const resolvedBinding = (identifier) =>
|
|
22969
|
+
const resolvedBinding = (identifier) => ASTUtils66.findVariable(
|
|
22866
22970
|
context.sourceCode.getScope(identifier),
|
|
22867
22971
|
identifier.name
|
|
22868
22972
|
);
|
|
22869
22973
|
const isFormDataGetCall = (node) => {
|
|
22870
22974
|
const callee = unwrapExpression(node.callee);
|
|
22871
|
-
const calleeReceiver = callee.type ===
|
|
22872
|
-
if (callee.type !==
|
|
22873
|
-
if (
|
|
22975
|
+
const calleeReceiver = callee.type === AST_NODE_TYPES108.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
22976
|
+
if (callee.type !== AST_NODE_TYPES108.MemberExpression) return false;
|
|
22977
|
+
if (ASTUtils66.getPropertyName(callee) === null || !FORM_VALUE_METHODS.has(ASTUtils66.getPropertyName(callee) ?? "")) {
|
|
22874
22978
|
return false;
|
|
22875
22979
|
}
|
|
22876
22980
|
return isFormSourceIdentifier(calleeReceiver);
|
|
22877
22981
|
};
|
|
22878
22982
|
const isFormSourceIdentifier = (node) => {
|
|
22879
22983
|
node = unwrapExpression(node);
|
|
22880
|
-
if (node.type !==
|
|
22984
|
+
if (node.type !== AST_NODE_TYPES108.Identifier) return false;
|
|
22881
22985
|
const conventionalName = /formdata/i.test(node.name);
|
|
22882
22986
|
let scope = context.sourceCode.getScope(node);
|
|
22883
22987
|
while (scope !== null) {
|
|
22884
22988
|
const variable = scope.set.get(node.name);
|
|
22885
22989
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
22886
22990
|
const def = variable.defs[0];
|
|
22887
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
22991
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === AST_NODE_TYPES108.VariableDeclarator && def.node.init !== null) {
|
|
22888
22992
|
return isFormDataMethodCall(def.node.init);
|
|
22889
22993
|
}
|
|
22890
22994
|
return def?.type === "Parameter" && conventionalName;
|
|
@@ -22897,24 +23001,24 @@ var require_zod_form_validation_default = createRule({
|
|
|
22897
23001
|
let parent = node.parent;
|
|
22898
23002
|
while (parent !== null && parent !== void 0) {
|
|
22899
23003
|
if (isZodParseCall(parent)) return parent;
|
|
22900
|
-
if (parent.type ===
|
|
23004
|
+
if (parent.type === AST_NODE_TYPES108.CallExpression && parent.callee.type === AST_NODE_TYPES108.Identifier && ["Number", "String", "Boolean"].includes(parent.callee.name) && parent.arguments.length === 1 && (resolvedBinding(parent.callee)?.defs.length ?? 0) === 0) {
|
|
22901
23005
|
parent = parent.parent;
|
|
22902
23006
|
continue;
|
|
22903
23007
|
}
|
|
22904
|
-
if (parent.type ===
|
|
23008
|
+
if (parent.type === AST_NODE_TYPES108.CallExpression && parent.callee.type === AST_NODE_TYPES108.MemberExpression && parent.callee.object.type === AST_NODE_TYPES108.Identifier && parent.callee.object.name === "Object" && ASTUtils66.getPropertyName(parent.callee) === "fromEntries" && (resolvedBinding(parent.callee.object)?.defs.length ?? 0) === 0) {
|
|
22905
23009
|
parent = parent.parent;
|
|
22906
23010
|
continue;
|
|
22907
23011
|
}
|
|
22908
|
-
if (parent.type ===
|
|
23012
|
+
if (parent.type === AST_NODE_TYPES108.CallExpression || parent.type === AST_NODE_TYPES108.NewExpression || parent.type === AST_NODE_TYPES108.TaggedTemplateExpression || parent.type === AST_NODE_TYPES108.ArrowFunctionExpression || parent.type === AST_NODE_TYPES108.FunctionExpression || parent.type === AST_NODE_TYPES108.FunctionDeclaration) return null;
|
|
22909
23013
|
parent = parent.parent;
|
|
22910
23014
|
}
|
|
22911
23015
|
return null;
|
|
22912
23016
|
};
|
|
22913
23017
|
const isZodParseCall = (node) => {
|
|
22914
|
-
if (node.type !==
|
|
23018
|
+
if (node.type !== AST_NODE_TYPES108.CallExpression) return false;
|
|
22915
23019
|
const callee = unwrapExpression(node.callee);
|
|
22916
|
-
const calleeReceiver = callee.type ===
|
|
22917
|
-
if (callee.type !==
|
|
23020
|
+
const calleeReceiver = callee.type === AST_NODE_TYPES108.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
23021
|
+
if (callee.type !== AST_NODE_TYPES108.MemberExpression || ASTUtils66.getPropertyName(callee) === null || !ZOD_PARSE_METHODS.has(ASTUtils66.getPropertyName(callee) ?? "")) {
|
|
22918
23022
|
return false;
|
|
22919
23023
|
}
|
|
22920
23024
|
const root = zodReceiverRoot(calleeReceiver);
|
|
@@ -22928,25 +23032,25 @@ var require_zod_form_validation_default = createRule({
|
|
|
22928
23032
|
return false;
|
|
22929
23033
|
}
|
|
22930
23034
|
const definition = binding.defs[0];
|
|
22931
|
-
if (definition?.type !== "Variable" || definition.node.type !==
|
|
23035
|
+
if (definition?.type !== "Variable" || definition.node.type !== AST_NODE_TYPES108.VariableDeclarator) {
|
|
22932
23036
|
return false;
|
|
22933
23037
|
}
|
|
22934
23038
|
const init = definition.node.init;
|
|
22935
|
-
return init?.type ===
|
|
23039
|
+
return init?.type === AST_NODE_TYPES108.ObjectExpression || init?.type === AST_NODE_TYPES108.ArrayExpression || init?.type === AST_NODE_TYPES108.Literal || init?.type === AST_NODE_TYPES108.ArrowFunctionExpression || init?.type === AST_NODE_TYPES108.FunctionExpression;
|
|
22936
23040
|
};
|
|
22937
23041
|
const hasZodParseAncestor = (node) => zodParseAncestor(node) !== null;
|
|
22938
23042
|
const isInstanceofNarrowing = (node) => {
|
|
22939
23043
|
const parent = node.parent;
|
|
22940
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
23044
|
+
return parent !== null && parent !== void 0 && parent.type === AST_NODE_TYPES108.BinaryExpression && parent.operator === "instanceof" && parent.left === node && parent.right.type === AST_NODE_TYPES108.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
22941
23045
|
};
|
|
22942
23046
|
const boundDeclarator = (node) => {
|
|
22943
23047
|
let current = node;
|
|
22944
23048
|
let parent = current.parent;
|
|
22945
|
-
while ((parent.type ===
|
|
23049
|
+
while ((parent.type === AST_NODE_TYPES108.TSAsExpression || parent.type === AST_NODE_TYPES108.TSSatisfiesExpression || parent.type === AST_NODE_TYPES108.TSNonNullExpression || parent.type === AST_NODE_TYPES108.ChainExpression) && parent.expression === current) {
|
|
22946
23050
|
current = parent;
|
|
22947
23051
|
parent = current.parent;
|
|
22948
23052
|
}
|
|
22949
|
-
if (parent.type ===
|
|
23053
|
+
if (parent.type === AST_NODE_TYPES108.VariableDeclarator && parent.init === current && parent.id.type === AST_NODE_TYPES108.Identifier) {
|
|
22950
23054
|
return parent;
|
|
22951
23055
|
}
|
|
22952
23056
|
return null;
|
|
@@ -22955,7 +23059,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
22955
23059
|
let current = node;
|
|
22956
23060
|
while (current.parent !== void 0) {
|
|
22957
23061
|
const parent = current.parent;
|
|
22958
|
-
if (parent.type ===
|
|
23062
|
+
if (parent.type === AST_NODE_TYPES108.BlockStatement || parent.type === AST_NODE_TYPES108.Program) {
|
|
22959
23063
|
return current;
|
|
22960
23064
|
}
|
|
22961
23065
|
current = parent;
|
|
@@ -22970,7 +23074,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
22970
23074
|
if (declarationStatement === null || validationStatement === null || declarationStatement.parent !== validationStatement.parent || validationStatement.range[0] <= declarationStatement.range[1] || hasConditionalAncestorBeforeStatement(parse2, validationStatement)) {
|
|
22971
23075
|
return null;
|
|
22972
23076
|
}
|
|
22973
|
-
if (validationStatement.type !==
|
|
23077
|
+
if (validationStatement.type !== AST_NODE_TYPES108.VariableDeclaration && validationStatement.type !== AST_NODE_TYPES108.ExpressionStatement) {
|
|
22974
23078
|
return null;
|
|
22975
23079
|
}
|
|
22976
23080
|
const method = zodParseMethod(parse2);
|
|
@@ -22983,7 +23087,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
22983
23087
|
const isAwaitedBeforeStatement = (node, statement) => {
|
|
22984
23088
|
let current = node.parent;
|
|
22985
23089
|
while (current !== void 0 && current !== statement) {
|
|
22986
|
-
if (current.type ===
|
|
23090
|
+
if (current.type === AST_NODE_TYPES108.AwaitExpression) return true;
|
|
22987
23091
|
current = current.parent;
|
|
22988
23092
|
}
|
|
22989
23093
|
return false;
|
|
@@ -22991,7 +23095,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
22991
23095
|
const hasConditionalAncestorBeforeStatement = (node, statement) => {
|
|
22992
23096
|
let current = node.parent;
|
|
22993
23097
|
while (current !== void 0 && current !== statement) {
|
|
22994
|
-
if (current.type ===
|
|
23098
|
+
if (current.type === AST_NODE_TYPES108.LogicalExpression || current.type === AST_NODE_TYPES108.ConditionalExpression) {
|
|
22995
23099
|
return true;
|
|
22996
23100
|
}
|
|
22997
23101
|
current = current.parent;
|
|
@@ -23000,20 +23104,20 @@ var require_zod_form_validation_default = createRule({
|
|
|
23000
23104
|
};
|
|
23001
23105
|
const zodParseMethod = (call) => {
|
|
23002
23106
|
const callee = unwrapExpression(call.callee);
|
|
23003
|
-
return callee.type ===
|
|
23107
|
+
return callee.type === AST_NODE_TYPES108.MemberExpression && ASTUtils66.getPropertyName(callee) !== null ? ASTUtils66.getPropertyName(callee) ?? "" : null;
|
|
23004
23108
|
};
|
|
23005
23109
|
const isSafePrevalidationInspection = (identifier) => {
|
|
23006
23110
|
const parent = identifier.parent;
|
|
23007
|
-
if (parent.type ===
|
|
23111
|
+
if (parent.type === AST_NODE_TYPES108.UnaryExpression && parent.operator === "typeof") {
|
|
23008
23112
|
return true;
|
|
23009
23113
|
}
|
|
23010
|
-
if (parent.type !==
|
|
23114
|
+
if (parent.type !== AST_NODE_TYPES108.BinaryExpression || parent.left !== identifier) {
|
|
23011
23115
|
return false;
|
|
23012
23116
|
}
|
|
23013
23117
|
if (parent.operator === "instanceof") {
|
|
23014
|
-
return parent.right.type ===
|
|
23118
|
+
return parent.right.type === AST_NODE_TYPES108.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
23015
23119
|
}
|
|
23016
|
-
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type ===
|
|
23120
|
+
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type === AST_NODE_TYPES108.Literal && parent.right.value === null || parent.right.type === AST_NODE_TYPES108.Identifier && parent.right.name === "undefined");
|
|
23017
23121
|
};
|
|
23018
23122
|
const isDescendantOf = (node, ancestor) => {
|
|
23019
23123
|
let current = node;
|
|
@@ -23024,23 +23128,23 @@ var require_zod_form_validation_default = createRule({
|
|
|
23024
23128
|
return false;
|
|
23025
23129
|
};
|
|
23026
23130
|
const blockTerminates = (node) => {
|
|
23027
|
-
if (node.type ===
|
|
23131
|
+
if (node.type === AST_NODE_TYPES108.ReturnStatement || node.type === AST_NODE_TYPES108.ThrowStatement) {
|
|
23028
23132
|
return true;
|
|
23029
23133
|
}
|
|
23030
|
-
if (node.type !==
|
|
23134
|
+
if (node.type !== AST_NODE_TYPES108.BlockStatement || node.body.length === 0) return false;
|
|
23031
23135
|
const last = node.body.at(-1);
|
|
23032
23136
|
return last !== void 0 && blockTerminates(last);
|
|
23033
23137
|
};
|
|
23034
23138
|
const narrowingIf = (identifier) => {
|
|
23035
23139
|
const comparison = identifier.parent;
|
|
23036
|
-
if (comparison?.type !==
|
|
23140
|
+
if (comparison?.type !== AST_NODE_TYPES108.BinaryExpression || comparison.operator !== "instanceof" || comparison.left !== identifier || comparison.right.type !== AST_NODE_TYPES108.Identifier || comparison.right.name !== "File" && comparison.right.name !== "Blob") {
|
|
23037
23141
|
return null;
|
|
23038
23142
|
}
|
|
23039
23143
|
const maybeNegation = comparison.parent;
|
|
23040
|
-
const negated = maybeNegation?.type ===
|
|
23144
|
+
const negated = maybeNegation?.type === AST_NODE_TYPES108.UnaryExpression && maybeNegation.operator === "!";
|
|
23041
23145
|
const test = negated ? maybeNegation : comparison;
|
|
23042
23146
|
const branch = test.parent;
|
|
23043
|
-
return branch?.type ===
|
|
23147
|
+
return branch?.type === AST_NODE_TYPES108.IfStatement && branch.test === test ? { branch, positive: !negated } : null;
|
|
23044
23148
|
};
|
|
23045
23149
|
const useDominatedByNarrowing = (use, narrowings) => narrowings.some(({ branch, positive }) => {
|
|
23046
23150
|
if (positive) return isDescendantOf(use, branch.consequent);
|
|
@@ -23060,7 +23164,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
23060
23164
|
const variable = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
23061
23165
|
if (variable === void 0) return false;
|
|
23062
23166
|
const references = variable.references.filter((reference) => !reference.isWriteOnly()).map((reference) => reference.identifier).filter(
|
|
23063
|
-
(identifier) => identifier.type ===
|
|
23167
|
+
(identifier) => identifier.type === AST_NODE_TYPES108.Identifier
|
|
23064
23168
|
);
|
|
23065
23169
|
if (references.length === 0) return false;
|
|
23066
23170
|
const narrowings = references.map(narrowingIf).filter(
|
|
@@ -23086,7 +23190,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
23086
23190
|
ImportDeclaration(node) {
|
|
23087
23191
|
if (!isZodModule(node.source.value)) return;
|
|
23088
23192
|
for (const specifier of node.specifiers) {
|
|
23089
|
-
if (specifier.type ===
|
|
23193
|
+
if (specifier.type === AST_NODE_TYPES108.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES108.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES108.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES108.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
23090
23194
|
const binding = resolvedBinding(specifier.local);
|
|
23091
23195
|
if (binding !== null) zodBindings.add(binding);
|
|
23092
23196
|
}
|
|
@@ -23176,7 +23280,7 @@ function expressionCallableName(current) {
|
|
|
23176
23280
|
}
|
|
23177
23281
|
|
|
23178
23282
|
// src/rules/stepdown.ts
|
|
23179
|
-
import { AST_NODE_TYPES as
|
|
23283
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES109, ASTUtils as ASTUtils67 } from "@typescript-eslint/utils";
|
|
23180
23284
|
var STEPDOWN_DOCUMENTATION = {
|
|
23181
23285
|
summary: "Place a private helper below its sole direct same-scope caller.",
|
|
23182
23286
|
rationale: "Caller-first ordering lets a reader follow the main flow before descending into implementation details.",
|
|
@@ -23194,7 +23298,7 @@ var STEPDOWN_DOCUMENTATION = {
|
|
|
23194
23298
|
]
|
|
23195
23299
|
};
|
|
23196
23300
|
function isFunction(node) {
|
|
23197
|
-
return node.type ===
|
|
23301
|
+
return node.type === AST_NODE_TYPES109.ArrowFunctionExpression || node.type === AST_NODE_TYPES109.FunctionDeclaration || node.type === AST_NODE_TYPES109.FunctionExpression;
|
|
23198
23302
|
}
|
|
23199
23303
|
function reportMisordered(context, candidates, scopeDefinitions, calls, pinned, canMove = () => true) {
|
|
23200
23304
|
const byName = new Map(scopeDefinitions.map((definition) => [definition.key, definition]));
|
|
@@ -23290,7 +23394,7 @@ function cycleComponents(graph) {
|
|
|
23290
23394
|
return components;
|
|
23291
23395
|
}
|
|
23292
23396
|
function isErasedExpression2(node) {
|
|
23293
|
-
return node.type ===
|
|
23397
|
+
return node.type === AST_NODE_TYPES109.TSAsExpression || node.type === AST_NODE_TYPES109.TSTypeAssertion || node.type === AST_NODE_TYPES109.TSSatisfiesExpression || node.type === AST_NODE_TYPES109.TSNonNullExpression || node.type === AST_NODE_TYPES109.TSInstantiationExpression;
|
|
23294
23398
|
}
|
|
23295
23399
|
function unwrapExpression4(node) {
|
|
23296
23400
|
let current = node;
|
|
@@ -23314,11 +23418,11 @@ function localCallCount(context, node, owner) {
|
|
|
23314
23418
|
if (current === void 0 || enclosingFunction5(context, current) !== owner) return null;
|
|
23315
23419
|
const expression = wrappedExpression(current);
|
|
23316
23420
|
const parent = expression.parent;
|
|
23317
|
-
if (parent?.type ===
|
|
23421
|
+
if (parent?.type === AST_NODE_TYPES109.CallExpression && parent.callee === expression) {
|
|
23318
23422
|
count += 1;
|
|
23319
23423
|
continue;
|
|
23320
23424
|
}
|
|
23321
|
-
if (parent?.type !==
|
|
23425
|
+
if (parent?.type !== AST_NODE_TYPES109.VariableDeclarator || parent.init !== expression || parent.id.type !== AST_NODE_TYPES109.Identifier || parent.parent.type !== AST_NODE_TYPES109.VariableDeclaration || parent.parent.kind !== "const") return null;
|
|
23322
23426
|
const variable = context.sourceCode.getDeclaredVariables(parent)[0];
|
|
23323
23427
|
if (variable === void 0 || seen.has(variable) || !stableVariable(variable)) return null;
|
|
23324
23428
|
seen.add(variable);
|
|
@@ -23333,11 +23437,11 @@ function declarationScope(context, program) {
|
|
|
23333
23437
|
for (const node of declarations) counts.set(node.name, (counts.get(node.name) ?? 0) + 1);
|
|
23334
23438
|
const overloadNames = new Set(
|
|
23335
23439
|
program.body.flatMap((statement) => {
|
|
23336
|
-
const node = statement.type ===
|
|
23337
|
-
return node?.type ===
|
|
23440
|
+
const node = statement.type === AST_NODE_TYPES109.ExportNamedDeclaration ? statement.declaration : statement;
|
|
23441
|
+
return node?.type === AST_NODE_TYPES109.TSDeclareFunction && node.id !== null ? [node.id.name] : [];
|
|
23338
23442
|
})
|
|
23339
23443
|
);
|
|
23340
|
-
const exported = program.type ===
|
|
23444
|
+
const exported = program.type === AST_NODE_TYPES109.Program ? exportedNames(program) : /* @__PURE__ */ new Set();
|
|
23341
23445
|
const scopeDefinitions = declarations.filter((node) => counts.get(node.name) === 1);
|
|
23342
23446
|
const definitions = scopeDefinitions.filter(
|
|
23343
23447
|
(definition) => !exported.has(definition.name) && !overloadNames.has(definition.name)
|
|
@@ -23349,7 +23453,7 @@ function declarationScope(context, program) {
|
|
|
23349
23453
|
runtimeBarrierPrefix.push((runtimeBarrierPrefix.at(-1) ?? 0) + (isDeferredModuleStatement(statement) ? 0 : 1));
|
|
23350
23454
|
}
|
|
23351
23455
|
const canMove = (helper, caller) => {
|
|
23352
|
-
if (helper.node.type ===
|
|
23456
|
+
if (helper.node.type === AST_NODE_TYPES109.FunctionDeclaration) return true;
|
|
23353
23457
|
const helperIndex = statementIndex(helper);
|
|
23354
23458
|
const callerIndex = statementIndex(caller);
|
|
23355
23459
|
return helperIndex !== void 0 && callerIndex !== void 0 && runtimeBarrierPrefix[callerIndex + 1] === runtimeBarrierPrefix[helperIndex + 1];
|
|
@@ -23391,26 +23495,26 @@ function moduleCallGraph(context, scopeDefinitions) {
|
|
|
23391
23495
|
return { calls, pinned };
|
|
23392
23496
|
}
|
|
23393
23497
|
function isDeferredModuleStatement(statement) {
|
|
23394
|
-
const node = statement.type ===
|
|
23395
|
-
if (node === null || node.type ===
|
|
23396
|
-
return node.type ===
|
|
23397
|
-
(declaration) => declaration.id.type ===
|
|
23498
|
+
const node = statement.type === AST_NODE_TYPES109.ExportNamedDeclaration || statement.type === AST_NODE_TYPES109.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
23499
|
+
if (node === null || node.type === AST_NODE_TYPES109.FunctionDeclaration || node.type === AST_NODE_TYPES109.TSDeclareFunction || node.type === AST_NODE_TYPES109.TSInterfaceDeclaration || node.type === AST_NODE_TYPES109.TSTypeAliasDeclaration || node.type === AST_NODE_TYPES109.ImportDeclaration || node.type === AST_NODE_TYPES109.ExportAllDeclaration || node.type === AST_NODE_TYPES109.EmptyStatement) return true;
|
|
23500
|
+
return node.type === AST_NODE_TYPES109.VariableDeclaration && node.declarations.every(
|
|
23501
|
+
(declaration) => declaration.id.type === AST_NODE_TYPES109.Identifier && declaration.init !== null && isFunction(unwrapExpression4(declaration.init))
|
|
23398
23502
|
);
|
|
23399
23503
|
}
|
|
23400
23504
|
function exportedNames(program) {
|
|
23401
23505
|
const names = /* @__PURE__ */ new Set();
|
|
23402
23506
|
function collectNamedExports(statement) {
|
|
23403
|
-
if (statement.type !==
|
|
23404
|
-
if (statement.declaration?.type ===
|
|
23507
|
+
if (statement.type !== AST_NODE_TYPES109.ExportNamedDeclaration || statement.exportKind === "type" || statement.source !== null) return;
|
|
23508
|
+
if (statement.declaration?.type === AST_NODE_TYPES109.FunctionDeclaration && statement.declaration.id !== null) {
|
|
23405
23509
|
names.add(statement.declaration.id.name);
|
|
23406
23510
|
}
|
|
23407
|
-
if (statement.declaration?.type ===
|
|
23511
|
+
if (statement.declaration?.type === AST_NODE_TYPES109.VariableDeclaration) {
|
|
23408
23512
|
for (const declarator of statement.declaration.declarations) {
|
|
23409
|
-
if (declarator.id.type ===
|
|
23513
|
+
if (declarator.id.type === AST_NODE_TYPES109.Identifier) names.add(declarator.id.name);
|
|
23410
23514
|
}
|
|
23411
23515
|
}
|
|
23412
23516
|
for (const specifier of statement.specifiers) {
|
|
23413
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
23517
|
+
if (specifier.exportKind !== "type" && specifier.local.type === AST_NODE_TYPES109.Identifier) {
|
|
23414
23518
|
names.add(specifier.local.name);
|
|
23415
23519
|
}
|
|
23416
23520
|
}
|
|
@@ -23419,23 +23523,23 @@ function exportedNames(program) {
|
|
|
23419
23523
|
collectNamedExports(statement);
|
|
23420
23524
|
}
|
|
23421
23525
|
for (const statement of program.body) {
|
|
23422
|
-
if (statement.type ===
|
|
23423
|
-
if (statement.type ===
|
|
23526
|
+
if (statement.type === AST_NODE_TYPES109.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES109.Identifier) names.add(statement.declaration.name);
|
|
23527
|
+
if (statement.type === AST_NODE_TYPES109.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES109.FunctionDeclaration && statement.declaration.id !== null) names.add(statement.declaration.id.name);
|
|
23424
23528
|
}
|
|
23425
23529
|
return names;
|
|
23426
23530
|
}
|
|
23427
23531
|
function moduleDefinitions(program) {
|
|
23428
23532
|
const definitions = [];
|
|
23429
23533
|
for (const statement of program.body) {
|
|
23430
|
-
const node = statement.type ===
|
|
23431
|
-
if (node?.type ===
|
|
23534
|
+
const node = statement.type === AST_NODE_TYPES109.ExportNamedDeclaration || statement.type === AST_NODE_TYPES109.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
23535
|
+
if (node?.type === AST_NODE_TYPES109.FunctionDeclaration && node.id !== null && node.body !== null) {
|
|
23432
23536
|
definitions.push({ key: node.id.name, name: node.id.name, node, functionNode: node, bindingNode: node });
|
|
23433
23537
|
continue;
|
|
23434
23538
|
}
|
|
23435
|
-
if (node?.type !==
|
|
23539
|
+
if (node?.type !== AST_NODE_TYPES109.VariableDeclaration || node.kind !== "const" || node.declarations.length !== 1) continue;
|
|
23436
23540
|
for (const declarator of node.declarations) {
|
|
23437
23541
|
const initializer = declarator.init === null ? null : unwrapExpression4(declarator.init);
|
|
23438
|
-
if (declarator.id.type ===
|
|
23542
|
+
if (declarator.id.type === AST_NODE_TYPES109.Identifier && initializer !== null && isFunction(initializer)) {
|
|
23439
23543
|
definitions.push({
|
|
23440
23544
|
key: declarator.id.name,
|
|
23441
23545
|
name: declarator.id.name,
|
|
@@ -23449,25 +23553,25 @@ function moduleDefinitions(program) {
|
|
|
23449
23553
|
return definitions;
|
|
23450
23554
|
}
|
|
23451
23555
|
function methodName(node) {
|
|
23452
|
-
if (node.key.type ===
|
|
23453
|
-
if (!node.computed && node.key.type ===
|
|
23454
|
-
return node.key.type ===
|
|
23556
|
+
if (node.key.type === AST_NODE_TYPES109.PrivateIdentifier) return `#${node.key.name}`;
|
|
23557
|
+
if (!node.computed && node.key.type === AST_NODE_TYPES109.Identifier) return node.key.name;
|
|
23558
|
+
return node.key.type === AST_NODE_TYPES109.Literal && typeof node.key.value === "string" ? node.key.value : null;
|
|
23455
23559
|
}
|
|
23456
23560
|
function methodKey(name, isStatic2) {
|
|
23457
23561
|
return `${isStatic2 ? "static" : "instance"}:${name}`;
|
|
23458
23562
|
}
|
|
23459
23563
|
function receiverDomain(context, object, receivers, thisIsStatic) {
|
|
23460
23564
|
const unwrapped = unwrapExpression4(object);
|
|
23461
|
-
if (unwrapped.type ===
|
|
23565
|
+
if (unwrapped.type === AST_NODE_TYPES109.ThisExpression) return thisIsStatic;
|
|
23462
23566
|
return externalReceiverDomain(context, unwrapped, receivers);
|
|
23463
23567
|
}
|
|
23464
23568
|
function externalReceiverDomain(context, object, receivers) {
|
|
23465
23569
|
const origin = receiverOrigin(context, object, receivers);
|
|
23466
23570
|
if (origin === null || typeof origin === "boolean") return origin;
|
|
23467
|
-
if (origin.type ===
|
|
23571
|
+
if (origin.type === AST_NODE_TYPES109.NewExpression) {
|
|
23468
23572
|
return receiverOrigin(context, origin.callee, receivers) === true ? false : null;
|
|
23469
23573
|
}
|
|
23470
|
-
if (origin.type ===
|
|
23574
|
+
if (origin.type === AST_NODE_TYPES109.ObjectExpression || origin.type === AST_NODE_TYPES109.ArrayExpression || origin.type === AST_NODE_TYPES109.Literal || origin.type === AST_NODE_TYPES109.ArrowFunctionExpression || origin.type === AST_NODE_TYPES109.FunctionExpression) return "unrelated";
|
|
23471
23575
|
return null;
|
|
23472
23576
|
}
|
|
23473
23577
|
function receiverOrigin(context, object, receivers) {
|
|
@@ -23475,8 +23579,8 @@ function receiverOrigin(context, object, receivers) {
|
|
|
23475
23579
|
const seen = /* @__PURE__ */ new Set();
|
|
23476
23580
|
while (true) {
|
|
23477
23581
|
const unwrapped = unwrapExpression4(current);
|
|
23478
|
-
if (unwrapped.type !==
|
|
23479
|
-
const variable =
|
|
23582
|
+
if (unwrapped.type !== AST_NODE_TYPES109.Identifier) return unwrapped;
|
|
23583
|
+
const variable = ASTUtils67.findVariable(context.sourceCode.getScope(unwrapped), unwrapped.name);
|
|
23480
23584
|
if (variable === null) return null;
|
|
23481
23585
|
const known = receivers.get(variable);
|
|
23482
23586
|
if (known !== void 0) return known;
|
|
@@ -23489,25 +23593,25 @@ function immutableInitializer(variable, seen) {
|
|
|
23489
23593
|
if (seen.has(variable) || !stableVariable(variable) || variable.defs.length !== 1) return null;
|
|
23490
23594
|
seen.add(variable);
|
|
23491
23595
|
const definition = variable.defs[0];
|
|
23492
|
-
if (definition?.node.type !==
|
|
23596
|
+
if (definition?.node.type !== AST_NODE_TYPES109.VariableDeclarator || definition.node.parent.type !== AST_NODE_TYPES109.VariableDeclaration || definition.node.parent.kind !== "const") return null;
|
|
23493
23597
|
return definition.node.init;
|
|
23494
23598
|
}
|
|
23495
23599
|
function stableVariable(variable) {
|
|
23496
23600
|
return !variable.references.some((reference) => reference.isWrite() && reference.init !== true);
|
|
23497
23601
|
}
|
|
23498
23602
|
function referencedPropertyName(node) {
|
|
23499
|
-
if (node.property.type ===
|
|
23500
|
-
if (!node.computed && node.property.type ===
|
|
23501
|
-
return node.computed && node.property.type ===
|
|
23603
|
+
if (node.property.type === AST_NODE_TYPES109.PrivateIdentifier) return `#${node.property.name}`;
|
|
23604
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES109.Identifier) return node.property.name;
|
|
23605
|
+
return node.computed && node.property.type === AST_NODE_TYPES109.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
23502
23606
|
}
|
|
23503
23607
|
function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
23504
23608
|
visit(node, nestedFunction);
|
|
23505
|
-
const nested = nestedFunction || isFunction(node) || node.type ===
|
|
23609
|
+
const nested = nestedFunction || isFunction(node) || node.type === AST_NODE_TYPES109.ClassDeclaration || node.type === AST_NODE_TYPES109.ClassExpression;
|
|
23506
23610
|
forEachAstChild(node, visitorKeys, (child) => walk(child, visitorKeys, visit, nested));
|
|
23507
23611
|
}
|
|
23508
23612
|
function classScope(context, node, computedReferences) {
|
|
23509
23613
|
const methods = node.body.body.filter(
|
|
23510
|
-
(member) => member.type ===
|
|
23614
|
+
(member) => member.type === AST_NODE_TYPES109.MethodDefinition
|
|
23511
23615
|
);
|
|
23512
23616
|
const counts = classMethodCounts(node.body, methods);
|
|
23513
23617
|
const implementations = methods.filter((method) => isFunction(method.value));
|
|
@@ -23518,7 +23622,7 @@ function classScope(context, node, computedReferences) {
|
|
|
23518
23622
|
return name !== null && key !== null && implementationCounts.get(key) === 1 ? [{ key, name, node: method }] : [];
|
|
23519
23623
|
});
|
|
23520
23624
|
const definitions = scopeDefinitions.filter(
|
|
23521
|
-
({ key, node: method }) => (method.accessibility === "private" || method.key.type ===
|
|
23625
|
+
({ key, node: method }) => (method.accessibility === "private" || method.key.type === AST_NODE_TYPES109.PrivateIdentifier) && counts.get(key) === 1 && method.decorators.length === 0 && !method.computed && method.kind === "method"
|
|
23522
23626
|
);
|
|
23523
23627
|
if (definitions.length === 0) return;
|
|
23524
23628
|
const methodKeys = new Set(scopeDefinitions.map((definition) => definition.key));
|
|
@@ -23534,11 +23638,11 @@ function classScope(context, node, computedReferences) {
|
|
|
23534
23638
|
};
|
|
23535
23639
|
function pinDestructuredMembers(binding, domain) {
|
|
23536
23640
|
for (const property of binding.properties) {
|
|
23537
|
-
if (property.type ===
|
|
23641
|
+
if (property.type === AST_NODE_TYPES109.RestElement || property.computed) {
|
|
23538
23642
|
pinNames(null, domain);
|
|
23539
|
-
} else if (property.key.type ===
|
|
23643
|
+
} else if (property.key.type === AST_NODE_TYPES109.Identifier) {
|
|
23540
23644
|
pinNames(property.key.name, domain);
|
|
23541
|
-
} else if (property.key.type ===
|
|
23645
|
+
} else if (property.key.type === AST_NODE_TYPES109.Literal && typeof property.key.value === "string") {
|
|
23542
23646
|
pinNames(property.key.value, domain);
|
|
23543
23647
|
}
|
|
23544
23648
|
}
|
|
@@ -23560,15 +23664,15 @@ function classScope(context, node, computedReferences) {
|
|
|
23560
23664
|
}
|
|
23561
23665
|
}
|
|
23562
23666
|
const collectAlias = (current, nestedFunction) => {
|
|
23563
|
-
if (nestedFunction || current.type !==
|
|
23667
|
+
if (nestedFunction || current.type !== AST_NODE_TYPES109.VariableDeclarator || current.init === null) return;
|
|
23564
23668
|
const domain = receiverDomain(context, current.init, receivers, method.static);
|
|
23565
23669
|
if (domain === null || domain === "unrelated") return;
|
|
23566
|
-
if (current.id.type ===
|
|
23670
|
+
if (current.id.type === AST_NODE_TYPES109.ObjectPattern) {
|
|
23567
23671
|
pinDestructuredMembers(current.id, domain);
|
|
23568
23672
|
return;
|
|
23569
23673
|
}
|
|
23570
|
-
if (current.id.type !==
|
|
23571
|
-
if (current.parent.type !==
|
|
23674
|
+
if (current.id.type !== AST_NODE_TYPES109.Identifier) return;
|
|
23675
|
+
if (current.parent.type !== AST_NODE_TYPES109.VariableDeclaration || current.parent.kind !== "const") {
|
|
23572
23676
|
pinNames(null, domain);
|
|
23573
23677
|
return;
|
|
23574
23678
|
}
|
|
@@ -23577,7 +23681,7 @@ function classScope(context, node, computedReferences) {
|
|
|
23577
23681
|
const local = variable.references.every((reference) => {
|
|
23578
23682
|
if (!reference.isRead()) return true;
|
|
23579
23683
|
const expression = wrappedExpression(reference.identifier);
|
|
23580
|
-
return enclosingFunction5(context, reference.identifier) === methodFunction && expression.parent?.type ===
|
|
23684
|
+
return enclosingFunction5(context, reference.identifier) === methodFunction && expression.parent?.type === AST_NODE_TYPES109.MemberExpression && expression.parent.object === expression;
|
|
23581
23685
|
});
|
|
23582
23686
|
if (local) receivers.set(variable, domain);
|
|
23583
23687
|
else pinNames(null, domain);
|
|
@@ -23589,7 +23693,7 @@ function classScope(context, node, computedReferences) {
|
|
|
23589
23693
|
const domain2 = receiverDomain(context, destructuring.value, receivers, method.static);
|
|
23590
23694
|
if (domain2 !== "unrelated") pinDestructuredMembers(destructuring.binding, domain2);
|
|
23591
23695
|
}
|
|
23592
|
-
if (current.type !==
|
|
23696
|
+
if (current.type !== AST_NODE_TYPES109.MemberExpression) return;
|
|
23593
23697
|
const domain = receiverDomain(context, current.object, receivers, method.static);
|
|
23594
23698
|
const targetName = referencedPropertyName(current);
|
|
23595
23699
|
if (domain === "unrelated") return;
|
|
@@ -23623,9 +23727,9 @@ function classScope(context, node, computedReferences) {
|
|
|
23623
23727
|
}
|
|
23624
23728
|
for (const method of methods) collectMethodCalls(method);
|
|
23625
23729
|
for (const member of node.body.body) {
|
|
23626
|
-
if (member.type ===
|
|
23730
|
+
if (member.type === AST_NODE_TYPES109.MethodDefinition || member.type === AST_NODE_TYPES109.TSAbstractMethodDefinition) continue;
|
|
23627
23731
|
walk(member, context.sourceCode.visitorKeys, (current) => {
|
|
23628
|
-
if (current.type !==
|
|
23732
|
+
if (current.type !== AST_NODE_TYPES109.MemberExpression) return;
|
|
23629
23733
|
if (externalReceiverDomain(context, current.object, classReceivers) === "unrelated") return;
|
|
23630
23734
|
pinNames(referencedPropertyName(current));
|
|
23631
23735
|
});
|
|
@@ -23657,32 +23761,32 @@ function classScope(context, node, computedReferences) {
|
|
|
23657
23761
|
function classReceiverBindings(context, node) {
|
|
23658
23762
|
const classReceivers = /* @__PURE__ */ new Map();
|
|
23659
23763
|
if (node.id !== null) {
|
|
23660
|
-
const internal =
|
|
23764
|
+
const internal = ASTUtils67.findVariable(context.sourceCode.getScope(node), node.id.name);
|
|
23661
23765
|
if (internal !== null && stableVariable(internal)) classReceivers.set(internal, true);
|
|
23662
23766
|
}
|
|
23663
|
-
if (node.type ===
|
|
23664
|
-
const outer =
|
|
23767
|
+
if (node.type === AST_NODE_TYPES109.ClassExpression && node.parent.type === AST_NODE_TYPES109.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES109.Identifier && node.parent.parent.type === AST_NODE_TYPES109.VariableDeclaration && node.parent.parent.kind === "const") {
|
|
23768
|
+
const outer = ASTUtils67.findVariable(context.sourceCode.getScope(node.parent), node.parent.id.name);
|
|
23665
23769
|
if (outer !== null && stableVariable(outer)) classReceivers.set(outer, true);
|
|
23666
23770
|
}
|
|
23667
23771
|
return classReceivers;
|
|
23668
23772
|
}
|
|
23669
23773
|
function receiverDestructuring(node) {
|
|
23670
|
-
if (node.type ===
|
|
23774
|
+
if (node.type === AST_NODE_TYPES109.VariableDeclarator && node.id.type === AST_NODE_TYPES109.ObjectPattern && node.init !== null) {
|
|
23671
23775
|
return { binding: node.id, value: node.init };
|
|
23672
23776
|
}
|
|
23673
|
-
if ((node.type ===
|
|
23777
|
+
if ((node.type === AST_NODE_TYPES109.AssignmentPattern || node.type === AST_NODE_TYPES109.AssignmentExpression) && node.left.type === AST_NODE_TYPES109.ObjectPattern) {
|
|
23674
23778
|
return { binding: node.left, value: node.right };
|
|
23675
23779
|
}
|
|
23676
23780
|
return null;
|
|
23677
23781
|
}
|
|
23678
23782
|
function isClassRuntimeBarrier(member) {
|
|
23679
23783
|
switch (member.type) {
|
|
23680
|
-
case
|
|
23784
|
+
case AST_NODE_TYPES109.StaticBlock:
|
|
23681
23785
|
return true;
|
|
23682
|
-
case
|
|
23683
|
-
case
|
|
23786
|
+
case AST_NODE_TYPES109.PropertyDefinition:
|
|
23787
|
+
case AST_NODE_TYPES109.AccessorProperty:
|
|
23684
23788
|
return member.static || member.computed || member.decorators.length > 0 || member.value !== null;
|
|
23685
|
-
case
|
|
23789
|
+
case AST_NODE_TYPES109.MethodDefinition:
|
|
23686
23790
|
return member.computed || member.decorators.length > 0;
|
|
23687
23791
|
default:
|
|
23688
23792
|
return false;
|
|
@@ -23712,14 +23816,14 @@ var stepdown_default = createRule({
|
|
|
23712
23816
|
classes.push(node);
|
|
23713
23817
|
},
|
|
23714
23818
|
"FunctionDeclaration, FunctionExpression, ArrowFunctionExpression": (node) => {
|
|
23715
|
-
if (isFunction(node) && node.body?.type ===
|
|
23819
|
+
if (isFunction(node) && node.body?.type === AST_NODE_TYPES109.BlockStatement) functionBodies.push(node.body);
|
|
23716
23820
|
},
|
|
23717
23821
|
"Program:exit": (program) => {
|
|
23718
23822
|
declarationScope(context, program);
|
|
23719
23823
|
for (const body2 of functionBodies) declarationScope(context, body2);
|
|
23720
23824
|
const computedReferences = [];
|
|
23721
23825
|
walk(program, context.sourceCode.visitorKeys, (node) => {
|
|
23722
|
-
if (node.type ===
|
|
23826
|
+
if (node.type === AST_NODE_TYPES109.MemberExpression && node.computed) computedReferences.push(node);
|
|
23723
23827
|
});
|
|
23724
23828
|
for (const node of classes) classScope(context, node, computedReferences);
|
|
23725
23829
|
}
|
|
@@ -23736,8 +23840,8 @@ function classMethodCounts(body2, methods) {
|
|
|
23736
23840
|
}
|
|
23737
23841
|
}
|
|
23738
23842
|
for (const member of body2.body) {
|
|
23739
|
-
if (member.type !==
|
|
23740
|
-
const name = !member.computed && member.key.type ===
|
|
23843
|
+
if (member.type !== AST_NODE_TYPES109.TSAbstractMethodDefinition) continue;
|
|
23844
|
+
const name = !member.computed && member.key.type === AST_NODE_TYPES109.Identifier ? member.key.name : null;
|
|
23741
23845
|
if (name !== null) {
|
|
23742
23846
|
const key = methodKey(name, member.static);
|
|
23743
23847
|
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
@@ -23747,7 +23851,7 @@ function classMethodCounts(body2, methods) {
|
|
|
23747
23851
|
}
|
|
23748
23852
|
|
|
23749
23853
|
// src/rules/source-coupled-test.ts
|
|
23750
|
-
import { AST_NODE_TYPES as
|
|
23854
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES110, ASTUtils as ASTUtils68 } from "@typescript-eslint/utils";
|
|
23751
23855
|
var GENERAL_SOURCE_SUFFIX_RE = /\.(?:bash|sh|ya?ml|jsonc?|toml|py|[cm]?[jt]s)$/iu;
|
|
23752
23856
|
var FS_MODULES = /* @__PURE__ */ new Set(["fs", "node:fs", "fs/promises", "node:fs/promises"]);
|
|
23753
23857
|
var FS_READERS = /* @__PURE__ */ new Set(["readFile", "readFileSync"]);
|
|
@@ -23821,16 +23925,16 @@ var SOURCE_COUPLED_TEST_DOCUMENTATION = {
|
|
|
23821
23925
|
function unwrap6(node) {
|
|
23822
23926
|
for (; ; ) {
|
|
23823
23927
|
node = unwrapExpression(node);
|
|
23824
|
-
if (node.type ===
|
|
23825
|
-
else if (node.type ===
|
|
23928
|
+
if (node.type === AST_NODE_TYPES110.AwaitExpression) node = node.argument;
|
|
23929
|
+
else if (node.type === AST_NODE_TYPES110.ChainExpression) node = node.expression;
|
|
23826
23930
|
else return node;
|
|
23827
23931
|
}
|
|
23828
23932
|
}
|
|
23829
23933
|
function stringValue(node) {
|
|
23830
23934
|
const current = unwrap6(node);
|
|
23831
|
-
if (current.type ===
|
|
23832
|
-
if (current.type ===
|
|
23833
|
-
if (current.type ===
|
|
23935
|
+
if (current.type === AST_NODE_TYPES110.Literal && typeof current.value === "string") return current.value;
|
|
23936
|
+
if (current.type === AST_NODE_TYPES110.TemplateLiteral && current.expressions.length === 0) return current.quasis[0]?.value.cooked ?? null;
|
|
23937
|
+
if (current.type === AST_NODE_TYPES110.BinaryExpression && current.operator === "+") {
|
|
23834
23938
|
const left = stringValue(current.left);
|
|
23835
23939
|
const right = stringValue(current.right);
|
|
23836
23940
|
return left === null || right === null ? null : left + right;
|
|
@@ -23842,7 +23946,7 @@ function importSource(node) {
|
|
|
23842
23946
|
}
|
|
23843
23947
|
function requireSource(node) {
|
|
23844
23948
|
const current = unwrap6(node);
|
|
23845
|
-
if (current.type !==
|
|
23949
|
+
if (current.type !== AST_NODE_TYPES110.CallExpression || current.callee.type !== AST_NODE_TYPES110.Identifier || current.callee.name !== "require" || current.arguments.length !== 1 || current.arguments[0]?.type === AST_NODE_TYPES110.SpreadElement) return null;
|
|
23846
23950
|
return stringValue(current.arguments[0]);
|
|
23847
23951
|
}
|
|
23848
23952
|
function newScope() {
|
|
@@ -23864,7 +23968,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
23864
23968
|
const scopes = [newScope()];
|
|
23865
23969
|
const reportedOrigins = /* @__PURE__ */ new Set();
|
|
23866
23970
|
const currentScope = () => scopes.at(-1) ?? scopes[0];
|
|
23867
|
-
const bindingOf = (node) =>
|
|
23971
|
+
const bindingOf = (node) => ASTUtils68.findVariable(context.sourceCode.getScope(node), node.name);
|
|
23868
23972
|
const assertionKind = (node) => {
|
|
23869
23973
|
const binding = bindingOf(node);
|
|
23870
23974
|
if (binding === null || binding.defs.length === 0) {
|
|
@@ -23898,75 +24002,75 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
23898
24002
|
const current = unwrap6(node);
|
|
23899
24003
|
const value = stringValue(current);
|
|
23900
24004
|
if (value !== null) return sourceSuffixRe.test(value);
|
|
23901
|
-
if (current.type ===
|
|
23902
|
-
if (current.type ===
|
|
24005
|
+
if (current.type === AST_NODE_TYPES110.Identifier) return visible("paths", current);
|
|
24006
|
+
if (current.type === AST_NODE_TYPES110.CallExpression || current.type === AST_NODE_TYPES110.NewExpression) {
|
|
23903
24007
|
const callee = unwrapExpression(current.callee);
|
|
23904
24008
|
const first = current.arguments[0];
|
|
23905
|
-
if (first === void 0 || first.type ===
|
|
23906
|
-
if (current.type ===
|
|
23907
|
-
if (callee.type ===
|
|
24009
|
+
if (first === void 0 || first.type === AST_NODE_TYPES110.SpreadElement) return false;
|
|
24010
|
+
if (current.type === AST_NODE_TYPES110.NewExpression && callee.type === AST_NODE_TYPES110.Identifier && callee.name === "URL" && (bindingOf(callee)?.defs.length ?? 0) === 0) return sourcePath(first);
|
|
24011
|
+
if (callee.type === AST_NODE_TYPES110.Identifier && bindingOf(callee)?.defs.some((definition) => definition.node.type === AST_NODE_TYPES110.ImportSpecifier && definition.node.imported.type === AST_NODE_TYPES110.Identifier && definition.node.imported.name === "fileURLToPath" && definition.node.parent.type === AST_NODE_TYPES110.ImportDeclaration && ["node:url", "url"].includes(String(definition.node.parent.source.value)))) return sourcePath(first);
|
|
23908
24012
|
}
|
|
23909
24013
|
return false;
|
|
23910
24014
|
};
|
|
23911
24015
|
const rawRead = (node) => {
|
|
23912
24016
|
const current = unwrap6(node);
|
|
23913
|
-
if (current.type !==
|
|
24017
|
+
if (current.type !== AST_NODE_TYPES110.CallExpression || current.arguments.length === 0) return false;
|
|
23914
24018
|
const callee = unwrap6(current.callee);
|
|
23915
|
-
const calleeReceiver = callee.type ===
|
|
23916
|
-
if (callee.type ===
|
|
24019
|
+
const calleeReceiver = callee.type === AST_NODE_TYPES110.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
24020
|
+
if (callee.type === AST_NODE_TYPES110.Identifier) {
|
|
23917
24021
|
return visible("fsReaders", callee) && sourcePath(current.arguments[0]);
|
|
23918
24022
|
}
|
|
23919
|
-
if (callee.type !==
|
|
23920
|
-
const name2 =
|
|
24023
|
+
if (callee.type !== AST_NODE_TYPES110.MemberExpression) return false;
|
|
24024
|
+
const name2 = ASTUtils68.getPropertyName(callee);
|
|
23921
24025
|
const object = unwrap6(calleeReceiver);
|
|
23922
|
-
return name2 !== null && FS_READERS.has(name2) && object.type ===
|
|
24026
|
+
return name2 !== null && FS_READERS.has(name2) && object.type === AST_NODE_TYPES110.Identifier && visible("fsObjects", object) && sourcePath(current.arguments[0]);
|
|
23923
24027
|
};
|
|
23924
24028
|
const rawOrigins = (node) => {
|
|
23925
24029
|
const current = unwrap6(node);
|
|
23926
|
-
if (current.type ===
|
|
24030
|
+
if (current.type === AST_NODE_TYPES110.Identifier) return visibleRawOrigins(current);
|
|
23927
24031
|
if (rawRead(current)) return /* @__PURE__ */ new Set([`${current.range[0]}:${current.range[1]}`]);
|
|
23928
|
-
if (current.type ===
|
|
23929
|
-
if (current.type ===
|
|
23930
|
-
if (current.type !==
|
|
24032
|
+
if (current.type === AST_NODE_TYPES110.BinaryExpression && current.operator === "+") return /* @__PURE__ */ new Set([...rawOrigins(current.left), ...rawOrigins(current.right)]);
|
|
24033
|
+
if (current.type === AST_NODE_TYPES110.MemberExpression && ASTUtils68.getPropertyName(current) === "length") return rawOrigins(current.object);
|
|
24034
|
+
if (current.type !== AST_NODE_TYPES110.CallExpression) return /* @__PURE__ */ new Set();
|
|
23931
24035
|
const callee = unwrap6(current.callee);
|
|
23932
|
-
const calleeReceiver = callee.type ===
|
|
23933
|
-
if (callee.type !==
|
|
23934
|
-
const name2 =
|
|
24036
|
+
const calleeReceiver = callee.type === AST_NODE_TYPES110.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
24037
|
+
if (callee.type !== AST_NODE_TYPES110.MemberExpression) return /* @__PURE__ */ new Set();
|
|
24038
|
+
const name2 = ASTUtils68.getPropertyName(callee);
|
|
23935
24039
|
return name2 !== null && TEXT_TRANSFORMS.has(name2) ? rawOrigins(calleeReceiver) : /* @__PURE__ */ new Set();
|
|
23936
24040
|
};
|
|
23937
24041
|
const evidenceOrigins = (node) => {
|
|
23938
24042
|
const current = unwrap6(node);
|
|
23939
24043
|
const direct = rawOrigins(current);
|
|
23940
24044
|
if (direct.size > 0) return direct;
|
|
23941
|
-
if (current.type ===
|
|
23942
|
-
if (current.type ===
|
|
23943
|
-
if (current.type !==
|
|
24045
|
+
if (current.type === AST_NODE_TYPES110.BinaryExpression || current.type === AST_NODE_TYPES110.LogicalExpression) return /* @__PURE__ */ new Set([...evidenceOrigins(current.left), ...evidenceOrigins(current.right)]);
|
|
24046
|
+
if (current.type === AST_NODE_TYPES110.UnaryExpression) return evidenceOrigins(current.argument);
|
|
24047
|
+
if (current.type !== AST_NODE_TYPES110.CallExpression) return /* @__PURE__ */ new Set();
|
|
23944
24048
|
const callee = unwrap6(current.callee);
|
|
23945
|
-
const calleeReceiver = callee.type ===
|
|
23946
|
-
if (callee.type !==
|
|
23947
|
-
const name2 =
|
|
24049
|
+
const calleeReceiver = callee.type === AST_NODE_TYPES110.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
24050
|
+
if (callee.type !== AST_NODE_TYPES110.MemberExpression) return /* @__PURE__ */ new Set();
|
|
24051
|
+
const name2 = ASTUtils68.getPropertyName(callee);
|
|
23948
24052
|
if (name2 !== null && TEXT_PREDICATES.has(name2)) return rawOrigins(calleeReceiver);
|
|
23949
|
-
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type ===
|
|
24053
|
+
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES110.SpreadElement ? [] : [...rawOrigins(argument)]));
|
|
23950
24054
|
return /* @__PURE__ */ new Set();
|
|
23951
24055
|
};
|
|
23952
24056
|
const rawAssertionOrigins = (node) => {
|
|
23953
24057
|
const callee = unwrap6(node.callee);
|
|
23954
|
-
const calleeReceiver = callee.type ===
|
|
23955
|
-
if (callee.type ===
|
|
23956
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
24058
|
+
const calleeReceiver = callee.type === AST_NODE_TYPES110.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
24059
|
+
if (callee.type === AST_NODE_TYPES110.Identifier && assertionKind(callee) === "assert") {
|
|
24060
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES110.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
23957
24061
|
}
|
|
23958
|
-
if (callee.type !==
|
|
23959
|
-
const matcher =
|
|
24062
|
+
if (callee.type !== AST_NODE_TYPES110.MemberExpression) return /* @__PURE__ */ new Set();
|
|
24063
|
+
const matcher = ASTUtils68.getPropertyName(callee);
|
|
23960
24064
|
if (matcher === null) return /* @__PURE__ */ new Set();
|
|
23961
24065
|
let receiver = unwrap6(calleeReceiver);
|
|
23962
|
-
while (receiver.type ===
|
|
23963
|
-
const expectCallee = receiver.type ===
|
|
23964
|
-
if (receiver.type ===
|
|
24066
|
+
while (receiver.type === AST_NODE_TYPES110.MemberExpression && EXPECT_MODIFIERS2.has(ASTUtils68.getPropertyName(receiver) ?? "")) receiver = unwrap6(receiver.object);
|
|
24067
|
+
const expectCallee = receiver.type === AST_NODE_TYPES110.CallExpression ? unwrapExpression(receiver.callee) : null;
|
|
24068
|
+
if (receiver.type === AST_NODE_TYPES110.CallExpression && expectCallee?.type === AST_NODE_TYPES110.Identifier && assertionKind(expectCallee) === "expect") {
|
|
23965
24069
|
if (!EXPECT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
23966
|
-
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type ===
|
|
24070
|
+
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type === AST_NODE_TYPES110.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
23967
24071
|
}
|
|
23968
|
-
if (receiver.type !==
|
|
23969
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
24072
|
+
if (receiver.type !== AST_NODE_TYPES110.Identifier || assertionKind(receiver) !== "assert" || !ASSERT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
24073
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES110.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
23970
24074
|
};
|
|
23971
24075
|
const declare = (node, state) => {
|
|
23972
24076
|
const name2 = bindingOf(node);
|
|
@@ -23988,7 +24092,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
23988
24092
|
};
|
|
23989
24093
|
const sourceCollection = (node) => {
|
|
23990
24094
|
const current = unwrap6(node);
|
|
23991
|
-
return current.type ===
|
|
24095
|
+
return current.type === AST_NODE_TYPES110.ArrayExpression && current.elements.length > 0 && current.elements.every((element) => element !== null && element.type !== AST_NODE_TYPES110.SpreadElement && sourcePath(element));
|
|
23992
24096
|
};
|
|
23993
24097
|
const enterFunction = () => {
|
|
23994
24098
|
scopes.push(newScope());
|
|
@@ -23998,8 +24102,8 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
23998
24102
|
};
|
|
23999
24103
|
function declareFsReaders(pattern) {
|
|
24000
24104
|
for (const property of pattern.properties) {
|
|
24001
|
-
if (property.type !==
|
|
24002
|
-
const key = property.key.type ===
|
|
24105
|
+
if (property.type !== AST_NODE_TYPES110.Property || property.value.type !== AST_NODE_TYPES110.Identifier) continue;
|
|
24106
|
+
const key = property.key.type === AST_NODE_TYPES110.Identifier ? property.key.name : property.key.type === AST_NODE_TYPES110.Literal ? String(property.key.value) : "";
|
|
24003
24107
|
if (FS_READERS.has(key)) declare(property.value, { fsReader: true });
|
|
24004
24108
|
}
|
|
24005
24109
|
}
|
|
@@ -24008,8 +24112,8 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
24008
24112
|
const source = importSource(node);
|
|
24009
24113
|
if (source === null || !FS_MODULES.has(source)) return;
|
|
24010
24114
|
for (const specifier of node.specifiers) {
|
|
24011
|
-
if (specifier.type ===
|
|
24012
|
-
const imported = specifier.imported.type ===
|
|
24115
|
+
if (specifier.type === AST_NODE_TYPES110.ImportSpecifier) {
|
|
24116
|
+
const imported = specifier.imported.type === AST_NODE_TYPES110.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
24013
24117
|
if (FS_READERS.has(imported)) declare(specifier.local, { fsReader: true });
|
|
24014
24118
|
} else {
|
|
24015
24119
|
declare(specifier.local, { fsObject: true });
|
|
@@ -24022,26 +24126,26 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
24022
24126
|
if (node.init === null) return;
|
|
24023
24127
|
const required = requireSource(node.init);
|
|
24024
24128
|
const initializer = unwrap6(node.init);
|
|
24025
|
-
if (required !== null && initializer.type ===
|
|
24026
|
-
if (required !== null && FS_MODULES.has(required) && node.id.type ===
|
|
24129
|
+
if (required !== null && initializer.type === AST_NODE_TYPES110.CallExpression && initializer.callee.type === AST_NODE_TYPES110.Identifier && (bindingOf(initializer.callee)?.defs.length ?? 0) > 0) return;
|
|
24130
|
+
if (required !== null && FS_MODULES.has(required) && node.id.type === AST_NODE_TYPES110.Identifier) {
|
|
24027
24131
|
declare(node.id, { fsObject: true });
|
|
24028
24132
|
return;
|
|
24029
24133
|
}
|
|
24030
|
-
if (node.id.type ===
|
|
24134
|
+
if (node.id.type === AST_NODE_TYPES110.ObjectPattern && required !== null && FS_MODULES.has(required)) {
|
|
24031
24135
|
declareFsReaders(node.id);
|
|
24032
24136
|
return;
|
|
24033
24137
|
}
|
|
24034
|
-
if (node.id.type !==
|
|
24138
|
+
if (node.id.type !== AST_NODE_TYPES110.Identifier) return;
|
|
24035
24139
|
declare(node.id, { collection: sourceCollection(node.init), path: sourcePath(node.init), rawOrigins: rawOrigins(node.init) });
|
|
24036
24140
|
},
|
|
24037
24141
|
AssignmentExpression(node) {
|
|
24038
|
-
if (node.left.type ===
|
|
24142
|
+
if (node.left.type === AST_NODE_TYPES110.Identifier) declare(node.left, {});
|
|
24039
24143
|
},
|
|
24040
24144
|
ForOfStatement(node) {
|
|
24041
24145
|
const right = unwrap6(node.right);
|
|
24042
|
-
const collection = right.type ===
|
|
24043
|
-
const left = node.left.type ===
|
|
24044
|
-
if (collection && left?.type ===
|
|
24146
|
+
const collection = right.type === AST_NODE_TYPES110.Identifier && visible("collections", right);
|
|
24147
|
+
const left = node.left.type === AST_NODE_TYPES110.VariableDeclaration ? node.left.declarations[0]?.id : node.left;
|
|
24148
|
+
if (collection && left?.type === AST_NODE_TYPES110.Identifier) declare(left, { path: true });
|
|
24045
24149
|
},
|
|
24046
24150
|
CallExpression(node) {
|
|
24047
24151
|
const origins = rawAssertionOrigins(node);
|
|
@@ -24059,22 +24163,22 @@ var source_coupled_test_default = createSourceCoupledRule(
|
|
|
24059
24163
|
GENERAL_SOURCE_SUFFIX_RE
|
|
24060
24164
|
);
|
|
24061
24165
|
function importedAssertionKind(specifier) {
|
|
24062
|
-
if (specifier.type !==
|
|
24166
|
+
if (specifier.type !== AST_NODE_TYPES110.ImportSpecifier && specifier.type !== AST_NODE_TYPES110.ImportDefaultSpecifier && specifier.type !== AST_NODE_TYPES110.ImportNamespaceSpecifier || specifier.parent.type !== AST_NODE_TYPES110.ImportDeclaration) return null;
|
|
24063
24167
|
const source = importSource(specifier.parent);
|
|
24064
24168
|
if (source !== null && ASSERT_MODULES.has(source)) {
|
|
24065
|
-
if (specifier.type !==
|
|
24066
|
-
const imported2 = specifier.imported.type ===
|
|
24169
|
+
if (specifier.type !== AST_NODE_TYPES110.ImportSpecifier) return "assert";
|
|
24170
|
+
const imported2 = specifier.imported.type === AST_NODE_TYPES110.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
24067
24171
|
if (imported2 === "strict" || ASSERT_MATCHERS.has(imported2)) return "assert";
|
|
24068
24172
|
return null;
|
|
24069
24173
|
}
|
|
24070
|
-
if (source === null || !EXPECT_MODULES.has(source) || specifier.type !==
|
|
24071
|
-
const imported = specifier.imported.type ===
|
|
24174
|
+
if (source === null || !EXPECT_MODULES.has(source) || specifier.type !== AST_NODE_TYPES110.ImportSpecifier) return null;
|
|
24175
|
+
const imported = specifier.imported.type === AST_NODE_TYPES110.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
24072
24176
|
if (imported === "assert" || imported === "expect") return imported;
|
|
24073
24177
|
return null;
|
|
24074
24178
|
}
|
|
24075
24179
|
|
|
24076
24180
|
// src/rules/sole-export-matches-filename.ts
|
|
24077
|
-
import { AST_NODE_TYPES as
|
|
24181
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES111 } from "@typescript-eslint/utils";
|
|
24078
24182
|
|
|
24079
24183
|
// src/rules/_is-framework-entrypoint.ts
|
|
24080
24184
|
import { readFileSync as readFileSync3 } from "fs";
|
|
@@ -24190,7 +24294,7 @@ var sole_export_matches_filename_default = createRule({
|
|
|
24190
24294
|
if (only === void 0) return;
|
|
24191
24295
|
if (isFrameworkEntrypoint(normalizedFilename, only.key)) return;
|
|
24192
24296
|
if (only.name === "onRouterTransitionStart" && /(?:^|\/)instrumentation-client\.[jt]s$/u.test(normalizedFilename)) return;
|
|
24193
|
-
if (only.name === "collections" && /(?:^|\/)src\/content\.config\.(?:ts|js|mjs)$/u.test(normalizedFilename) && program.body.some((statement) => statement.type ===
|
|
24297
|
+
if (only.name === "collections" && /(?:^|\/)src\/content\.config\.(?:ts|js|mjs)$/u.test(normalizedFilename) && program.body.some((statement) => statement.type === AST_NODE_TYPES111.ImportDeclaration && statement.source.value === "astro:content")) return;
|
|
24194
24298
|
const exportedStem = kebabCase(only.name);
|
|
24195
24299
|
if (exportedStem === "") return;
|
|
24196
24300
|
const expected = `${fileStem.startsWith("_") ? "_" : ""}${exportedStem}`;
|
|
@@ -24241,8 +24345,8 @@ var iac_source_coupled_test_default = createSourceCoupledRule(
|
|
|
24241
24345
|
|
|
24242
24346
|
// src/rules/require-pascal-case-zod-schema-name.ts
|
|
24243
24347
|
import {
|
|
24244
|
-
AST_NODE_TYPES as
|
|
24245
|
-
ASTUtils as
|
|
24348
|
+
AST_NODE_TYPES as AST_NODE_TYPES112,
|
|
24349
|
+
ASTUtils as ASTUtils69
|
|
24246
24350
|
} from "@typescript-eslint/utils";
|
|
24247
24351
|
var REQUIRE_PASCAL_CASE_ZOD_SCHEMA_NAME_DOCUMENTATION = {
|
|
24248
24352
|
summary: "Require confirmed module-level Zod schema contracts to use PascalCase with a `Schema` suffix.",
|
|
@@ -24375,19 +24479,19 @@ var SCHEMA_RETURNING_METHODS = /* @__PURE__ */ new Set([
|
|
|
24375
24479
|
"superRefine",
|
|
24376
24480
|
"transform"
|
|
24377
24481
|
]);
|
|
24378
|
-
var terminalMethodName = (callee) =>
|
|
24482
|
+
var terminalMethodName = (callee) => ASTUtils69.getPropertyName(callee) !== null ? ASTUtils69.getPropertyName(callee) ?? "" : null;
|
|
24379
24483
|
var calleeChainRoot2 = (node) => {
|
|
24380
24484
|
let current = node;
|
|
24381
24485
|
for (; ; ) {
|
|
24382
24486
|
current = unwrapExpression(current);
|
|
24383
|
-
if (current.type ===
|
|
24487
|
+
if (current.type === AST_NODE_TYPES112.Identifier) {
|
|
24384
24488
|
return current;
|
|
24385
24489
|
}
|
|
24386
|
-
if (current.type ===
|
|
24490
|
+
if (current.type === AST_NODE_TYPES112.MemberExpression) {
|
|
24387
24491
|
current = current.object;
|
|
24388
24492
|
continue;
|
|
24389
24493
|
}
|
|
24390
|
-
if (current.type ===
|
|
24494
|
+
if (current.type === AST_NODE_TYPES112.CallExpression) {
|
|
24391
24495
|
current = unwrapExpression(current.callee);
|
|
24392
24496
|
continue;
|
|
24393
24497
|
}
|
|
@@ -24399,13 +24503,13 @@ var chainMemberNames2 = (node) => {
|
|
|
24399
24503
|
let current = node;
|
|
24400
24504
|
for (; ; ) {
|
|
24401
24505
|
current = unwrapExpression(current);
|
|
24402
|
-
if (current.type ===
|
|
24403
|
-
if (
|
|
24404
|
-
names.push(
|
|
24506
|
+
if (current.type === AST_NODE_TYPES112.MemberExpression) {
|
|
24507
|
+
if (ASTUtils69.getPropertyName(current) === null) return [];
|
|
24508
|
+
names.push(ASTUtils69.getPropertyName(current) ?? "");
|
|
24405
24509
|
current = current.object;
|
|
24406
24510
|
continue;
|
|
24407
24511
|
}
|
|
24408
|
-
if (current.type ===
|
|
24512
|
+
if (current.type === AST_NODE_TYPES112.CallExpression) {
|
|
24409
24513
|
current = unwrapExpression(current.callee);
|
|
24410
24514
|
continue;
|
|
24411
24515
|
}
|
|
@@ -24416,9 +24520,9 @@ var chainMemberNames2 = (node) => {
|
|
|
24416
24520
|
};
|
|
24417
24521
|
var isModuleDeclarator = (node) => {
|
|
24418
24522
|
const declaration = node.parent;
|
|
24419
|
-
if (declaration.type !==
|
|
24523
|
+
if (declaration.type !== AST_NODE_TYPES112.VariableDeclaration) return false;
|
|
24420
24524
|
const owner = declaration.parent;
|
|
24421
|
-
return owner.type ===
|
|
24525
|
+
return owner.type === AST_NODE_TYPES112.Program || owner.type === AST_NODE_TYPES112.ExportNamedDeclaration && owner.parent.type === AST_NODE_TYPES112.Program;
|
|
24422
24526
|
};
|
|
24423
24527
|
var require_pascal_case_zod_schema_name_default = createRule({
|
|
24424
24528
|
name: "require-pascal-case-zod-schema-name",
|
|
@@ -24438,7 +24542,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
24438
24542
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
24439
24543
|
const schemaBindings = /* @__PURE__ */ new Set();
|
|
24440
24544
|
function resolvedBinding(identifier) {
|
|
24441
|
-
return
|
|
24545
|
+
return ASTUtils69.findVariable(
|
|
24442
24546
|
context.sourceCode.getScope(identifier),
|
|
24443
24547
|
identifier.name
|
|
24444
24548
|
);
|
|
@@ -24449,10 +24553,10 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
24449
24553
|
}
|
|
24450
24554
|
function isConfirmedSchema(expression) {
|
|
24451
24555
|
const init = unwrapExpression(expression);
|
|
24452
|
-
if (init.type ===
|
|
24453
|
-
if (init.type !==
|
|
24556
|
+
if (init.type === AST_NODE_TYPES112.Identifier) return isSchemaBinding(init);
|
|
24557
|
+
if (init.type !== AST_NODE_TYPES112.CallExpression) return false;
|
|
24454
24558
|
const callee = unwrapExpression(init.callee);
|
|
24455
|
-
if (callee.type !==
|
|
24559
|
+
if (callee.type !== AST_NODE_TYPES112.MemberExpression) {
|
|
24456
24560
|
return false;
|
|
24457
24561
|
}
|
|
24458
24562
|
const terminal = terminalMethodName(callee);
|
|
@@ -24482,7 +24586,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
24482
24586
|
ImportDeclaration(node) {
|
|
24483
24587
|
if (!isZodModule(node.source.value)) return;
|
|
24484
24588
|
for (const specifier of node.specifiers) {
|
|
24485
|
-
if (specifier.type ===
|
|
24589
|
+
if (specifier.type === AST_NODE_TYPES112.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES112.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES112.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES112.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
24486
24590
|
recordZodBinding(specifier.local);
|
|
24487
24591
|
}
|
|
24488
24592
|
}
|
|
@@ -24491,7 +24595,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
24491
24595
|
if (!isModuleDeclarator(node)) return;
|
|
24492
24596
|
const init = node.init;
|
|
24493
24597
|
if (init === null || init === void 0) return;
|
|
24494
|
-
if (node.id.type !==
|
|
24598
|
+
if (node.id.type !== AST_NODE_TYPES112.Identifier) return;
|
|
24495
24599
|
if (!isConfirmedSchema(init)) return;
|
|
24496
24600
|
const binding = resolvedBinding(node.id);
|
|
24497
24601
|
if (binding !== null) schemaBindings.add(binding);
|
|
@@ -24693,6 +24797,7 @@ var RULES = {
|
|
|
24693
24797
|
"prefer-whole-object-assertion": prefer_whole_object_assertion_default,
|
|
24694
24798
|
"repeated-static-call-cases": repeated_static_call_cases_default,
|
|
24695
24799
|
"prefer-zod-infer": prefer_zod_infer_default,
|
|
24800
|
+
"named-child-schema-type": named_child_schema_type_default,
|
|
24696
24801
|
"prefer-zod-parse-output-type": prefer_zod_parse_output_type_default,
|
|
24697
24802
|
"require-assert-never": require_assert_never_default,
|
|
24698
24803
|
"require-fetch-timeout": require_fetch_timeout_default,
|
|
@@ -24718,6 +24823,7 @@ var LIBRARY_IMPORT_POLICY = ["error", {
|
|
|
24718
24823
|
}];
|
|
24719
24824
|
var ADVISORY_RULES = [
|
|
24720
24825
|
"@sarj/excessive-commentary",
|
|
24826
|
+
"@sarj/named-child-schema-type",
|
|
24721
24827
|
"@sarj/no-bespoke-api-case-conversion",
|
|
24722
24828
|
"@sarj/no-duplicate-test-case",
|
|
24723
24829
|
"@sarj/no-json-stringify-object-equality",
|
|
@@ -24740,6 +24846,7 @@ var ADVISORY_RULES = [
|
|
|
24740
24846
|
"@sarj/require-sql-access-class"
|
|
24741
24847
|
];
|
|
24742
24848
|
var RECOMMENDED_RULES = {
|
|
24849
|
+
"@sarj/named-child-schema-type": "warn",
|
|
24743
24850
|
"@sarj/no-conditional-empty-object-spread": "error",
|
|
24744
24851
|
"@sarj/prefer-typed-reflection": "error",
|
|
24745
24852
|
"@sarj/no-broad-return-type": "error",
|
|
@@ -24857,6 +24964,7 @@ var RECOMMENDED_RULES = {
|
|
|
24857
24964
|
"@sarj/require-pascal-case-zod-schema-name": "error"
|
|
24858
24965
|
};
|
|
24859
24966
|
var STRICT_RULES = {
|
|
24967
|
+
"@sarj/named-child-schema-type": "warn",
|
|
24860
24968
|
"@sarj/no-conditional-empty-object-spread": "error",
|
|
24861
24969
|
"@sarj/prefer-typed-reflection": "error",
|
|
24862
24970
|
"@sarj/no-broad-return-type": "error",
|