@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.cjs
CHANGED
|
@@ -52,7 +52,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
52
52
|
// package.json
|
|
53
53
|
var package_default = {
|
|
54
54
|
name: "@sarj/eslint-plugin",
|
|
55
|
-
version: "16.
|
|
55
|
+
version: "16.5.0",
|
|
56
56
|
packageManager: "npm@12.1.0",
|
|
57
57
|
description: "Custom ESLint rules for hypermodern TypeScript / React / Next.js projects",
|
|
58
58
|
type: "module",
|
|
@@ -21360,8 +21360,112 @@ function staticFieldName(key) {
|
|
|
21360
21360
|
return key.type === import_utils115.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils115.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
21361
21361
|
}
|
|
21362
21362
|
|
|
21363
|
-
// src/rules/
|
|
21363
|
+
// src/rules/named-child-schema-type.ts
|
|
21364
21364
|
var import_utils116 = require("@typescript-eslint/utils");
|
|
21365
|
+
var UNRESOLVED_TYPE_NODES = /* @__PURE__ */ new Set([
|
|
21366
|
+
import_utils116.AST_NODE_TYPES.TSTypeQuery,
|
|
21367
|
+
import_utils116.AST_NODE_TYPES.TSImportType,
|
|
21368
|
+
import_utils116.AST_NODE_TYPES.TSTypeParameter,
|
|
21369
|
+
import_utils116.AST_NODE_TYPES.TSAnyKeyword,
|
|
21370
|
+
import_utils116.AST_NODE_TYPES.TSUnknownKeyword
|
|
21371
|
+
]);
|
|
21372
|
+
var NAMED_CHILD_SCHEMA_TYPE_DOCUMENTATION = {
|
|
21373
|
+
defaultLevel: "warning",
|
|
21374
|
+
summary: "Reference a named Zod record child's complete schema type instead of repeating its explicit annotation.",
|
|
21375
|
+
rationale: "Repeating a child schema's generic contract creates a second maintained declaration even though the record already uses that child at runtime.",
|
|
21376
|
+
remediation: "Replace only the matching record type argument with `typeof ChildSchema`; retain the outer annotation required by isolatedDeclarations and every runtime schema operation.",
|
|
21377
|
+
category: "maintainability",
|
|
21378
|
+
autofix: "none",
|
|
21379
|
+
limitations: [
|
|
21380
|
+
"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.",
|
|
21381
|
+
"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.",
|
|
21382
|
+
"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.",
|
|
21383
|
+
"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."
|
|
21384
|
+
],
|
|
21385
|
+
examples: [
|
|
21386
|
+
{ 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 },
|
|
21387
|
+
{ 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 }
|
|
21388
|
+
]
|
|
21389
|
+
};
|
|
21390
|
+
function isModuleConst(node) {
|
|
21391
|
+
if (node.parent.kind !== "const" || node.id.type !== import_utils116.AST_NODE_TYPES.Identifier) return false;
|
|
21392
|
+
const parent = node.parent.parent;
|
|
21393
|
+
return parent.type === import_utils116.AST_NODE_TYPES.Program || parent.type === import_utils116.AST_NODE_TYPES.ExportNamedDeclaration && parent.parent.type === import_utils116.AST_NODE_TYPES.Program;
|
|
21394
|
+
}
|
|
21395
|
+
var named_child_schema_type_default = createRule({
|
|
21396
|
+
name: "named-child-schema-type",
|
|
21397
|
+
documentation: NAMED_CHILD_SCHEMA_TYPE_DOCUMENTATION,
|
|
21398
|
+
meta: {
|
|
21399
|
+
type: "suggestion",
|
|
21400
|
+
docs: { description: NAMED_CHILD_SCHEMA_TYPE_DOCUMENTATION.summary },
|
|
21401
|
+
schema: [],
|
|
21402
|
+
messages: { namedChildType: "Use `typeof {{name}}` for this exact child contract; keep the outer schema annotation and runtime operations." }
|
|
21403
|
+
},
|
|
21404
|
+
defaultOptions: [],
|
|
21405
|
+
create(context) {
|
|
21406
|
+
const source = context.sourceCode;
|
|
21407
|
+
if (isGeneratedFile(context.filename, source.text)) return {};
|
|
21408
|
+
const namespaces = /* @__PURE__ */ new Set();
|
|
21409
|
+
const bindingOf = (node) => import_utils116.ASTUtils.findVariable(source.getScope(node), node.name);
|
|
21410
|
+
function namespaceOf(type) {
|
|
21411
|
+
if (type.typeName.type !== import_utils116.AST_NODE_TYPES.TSQualifiedName || type.typeName.left.type !== import_utils116.AST_NODE_TYPES.Identifier) return null;
|
|
21412
|
+
const binding = bindingOf(type.typeName.left);
|
|
21413
|
+
return binding !== null && namespaces.has(binding) ? binding : null;
|
|
21414
|
+
}
|
|
21415
|
+
function closedType(node, namespace) {
|
|
21416
|
+
if (UNRESOLVED_TYPE_NODES.has(node.type)) return false;
|
|
21417
|
+
if (node.type === import_utils116.AST_NODE_TYPES.TSTypeReference && namespaceOf(node) !== namespace) return false;
|
|
21418
|
+
return !forEachOwnAstChild(node, (child) => !closedType(child, namespace));
|
|
21419
|
+
}
|
|
21420
|
+
function inspectChild(argument, repeated, namespace, parent) {
|
|
21421
|
+
if (argument.type !== import_utils116.AST_NODE_TYPES.Identifier || repeated.type !== import_utils116.AST_NODE_TYPES.TSTypeReference || repeated.typeArguments === void 0) return;
|
|
21422
|
+
if (repeated.typeName.type !== import_utils116.AST_NODE_TYPES.TSQualifiedName || /^(?:ZodType|ZodSchema|ZodTypeAny)$/u.test(repeated.typeName.right.name)) return;
|
|
21423
|
+
const variable = bindingOf(argument);
|
|
21424
|
+
const definition = variable?.defs.length === 1 ? variable.defs[0] : void 0;
|
|
21425
|
+
if (definition?.type !== "Variable" || !isModuleConst(definition.node)) return;
|
|
21426
|
+
const child = definition.node;
|
|
21427
|
+
if (child.id.type !== import_utils116.AST_NODE_TYPES.Identifier || child.init === null || child.range[0] >= parent.range[0]) return;
|
|
21428
|
+
const annotation = child.id.typeAnnotation?.typeAnnotation;
|
|
21429
|
+
if (annotation === void 0 || factoryNamespace(child.init) !== namespace || !closedType(annotation, namespace)) return;
|
|
21430
|
+
if (source.getCommentsInside(repeated).length > 0 || source.getCommentsBefore(repeated).length > 0) return;
|
|
21431
|
+
const expected = source.getTokens(annotation);
|
|
21432
|
+
const actual = source.getTokens(repeated);
|
|
21433
|
+
if (expected.length !== actual.length || expected.some((token, index) => token.type !== actual[index]?.type || token.value !== actual[index]?.value)) return;
|
|
21434
|
+
context.report({ node: repeated, messageId: "namedChildType", data: { name: argument.name } });
|
|
21435
|
+
}
|
|
21436
|
+
function factoryNamespace(expression) {
|
|
21437
|
+
if (expression.type !== import_utils116.AST_NODE_TYPES.CallExpression || expression.callee.type !== import_utils116.AST_NODE_TYPES.MemberExpression) return null;
|
|
21438
|
+
const object = expression.callee.object;
|
|
21439
|
+
return object.type === import_utils116.AST_NODE_TYPES.Identifier ? bindingOf(object) : factoryNamespace(object);
|
|
21440
|
+
}
|
|
21441
|
+
return {
|
|
21442
|
+
ImportDeclaration(node) {
|
|
21443
|
+
if (node.importKind === "type" || !isZodModule(node.source.value)) return;
|
|
21444
|
+
for (const specifier of node.specifiers) {
|
|
21445
|
+
if (specifier.type !== import_utils116.AST_NODE_TYPES.ImportNamespaceSpecifier && (specifier.type !== import_utils116.AST_NODE_TYPES.ImportSpecifier || specifier.importKind === "type" || importSpecifierName(specifier) !== "z")) continue;
|
|
21446
|
+
const binding = bindingOf(specifier.local);
|
|
21447
|
+
if (binding !== null) namespaces.add(binding);
|
|
21448
|
+
}
|
|
21449
|
+
},
|
|
21450
|
+
VariableDeclarator(node) {
|
|
21451
|
+
if (!isModuleConst(node) || node.id.type !== import_utils116.AST_NODE_TYPES.Identifier || node.init?.type !== import_utils116.AST_NODE_TYPES.CallExpression) return;
|
|
21452
|
+
const call = node.init;
|
|
21453
|
+
if (call.arguments.length !== 2 || call.callee.type !== import_utils116.AST_NODE_TYPES.MemberExpression || call.callee.object.type !== import_utils116.AST_NODE_TYPES.Identifier || import_utils116.ASTUtils.getPropertyName(call.callee) !== "record") return;
|
|
21454
|
+
const annotation = node.id.typeAnnotation?.typeAnnotation;
|
|
21455
|
+
if (annotation?.type !== import_utils116.AST_NODE_TYPES.TSTypeReference || annotation.typeName.type !== import_utils116.AST_NODE_TYPES.TSQualifiedName || annotation.typeName.right.name !== "ZodRecord") return;
|
|
21456
|
+
const namespace = namespaceOf(annotation);
|
|
21457
|
+
if (namespace === null || bindingOf(call.callee.object) !== namespace || annotation.typeArguments?.params.length !== 2) return;
|
|
21458
|
+
for (const [index, argument] of call.arguments.entries()) {
|
|
21459
|
+
const repeated = annotation.typeArguments.params[index];
|
|
21460
|
+
if (repeated !== void 0) inspectChild(argument, repeated, namespace, node);
|
|
21461
|
+
}
|
|
21462
|
+
}
|
|
21463
|
+
};
|
|
21464
|
+
}
|
|
21465
|
+
});
|
|
21466
|
+
|
|
21467
|
+
// src/rules/prefer-zod-parse-output-type.ts
|
|
21468
|
+
var import_utils117 = require("@typescript-eslint/utils");
|
|
21365
21469
|
var import_typescript7 = __toESM(require("typescript"), 1);
|
|
21366
21470
|
var PREFER_ZOD_PARSE_OUTPUT_TYPE_DOCUMENTATION = {
|
|
21367
21471
|
summary: "Derive a function's return contract from the local Zod schema whose parsed output it returns.",
|
|
@@ -21417,22 +21521,22 @@ var PREFER_ZOD_PARSE_OUTPUT_TYPE_DOCUMENTATION = {
|
|
|
21417
21521
|
};
|
|
21418
21522
|
function isModuleLevelConst2(node) {
|
|
21419
21523
|
const declaration = node.parent;
|
|
21420
|
-
if (declaration.type !==
|
|
21524
|
+
if (declaration.type !== import_utils117.AST_NODE_TYPES.VariableDeclaration || declaration.kind !== "const") {
|
|
21421
21525
|
return false;
|
|
21422
21526
|
}
|
|
21423
21527
|
const container = declaration.parent;
|
|
21424
|
-
return container.type ===
|
|
21528
|
+
return container.type === import_utils117.AST_NODE_TYPES.Program || container.type === import_utils117.AST_NODE_TYPES.ExportNamedDeclaration && container.parent.type === import_utils117.AST_NODE_TYPES.Program;
|
|
21425
21529
|
}
|
|
21426
21530
|
function isLocalZodObjectSchema(node, namespaces) {
|
|
21427
21531
|
let current = node;
|
|
21428
|
-
while (current.type ===
|
|
21532
|
+
while (current.type === import_utils117.AST_NODE_TYPES.CallExpression) {
|
|
21429
21533
|
const callee = unwrapExpression(current.callee);
|
|
21430
|
-
const calleeReceiver = callee.type ===
|
|
21431
|
-
if (callee.type !==
|
|
21534
|
+
const calleeReceiver = callee.type === import_utils117.AST_NODE_TYPES.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
21535
|
+
if (callee.type !== import_utils117.AST_NODE_TYPES.MemberExpression || import_utils117.ASTUtils.getPropertyName(callee) === null) {
|
|
21432
21536
|
return false;
|
|
21433
21537
|
}
|
|
21434
|
-
if (calleeReceiver.type ===
|
|
21435
|
-
return namespaces.has(calleeReceiver.name) && ((
|
|
21538
|
+
if (calleeReceiver.type === import_utils117.AST_NODE_TYPES.Identifier) {
|
|
21539
|
+
return namespaces.has(calleeReceiver.name) && ((import_utils117.ASTUtils.getPropertyName(callee) ?? "") === "object" || (import_utils117.ASTUtils.getPropertyName(callee) ?? "") === "strictObject");
|
|
21436
21540
|
}
|
|
21437
21541
|
current = calleeReceiver;
|
|
21438
21542
|
}
|
|
@@ -21440,11 +21544,11 @@ function isLocalZodObjectSchema(node, namespaces) {
|
|
|
21440
21544
|
}
|
|
21441
21545
|
function zodParseCall(node) {
|
|
21442
21546
|
const callee = unwrapExpression(node.callee);
|
|
21443
|
-
const calleeReceiver = callee.type ===
|
|
21444
|
-
if (callee.type !==
|
|
21547
|
+
const calleeReceiver = callee.type === import_utils117.AST_NODE_TYPES.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
21548
|
+
if (callee.type !== import_utils117.AST_NODE_TYPES.MemberExpression || calleeReceiver.type !== import_utils117.AST_NODE_TYPES.Identifier || import_utils117.ASTUtils.getPropertyName(callee) === null) {
|
|
21445
21549
|
return null;
|
|
21446
21550
|
}
|
|
21447
|
-
const method =
|
|
21551
|
+
const method = import_utils117.ASTUtils.getPropertyName(callee);
|
|
21448
21552
|
if (method !== "parse" && method !== "safeParse") return null;
|
|
21449
21553
|
return {
|
|
21450
21554
|
call: node,
|
|
@@ -21458,7 +21562,7 @@ function returnedOutputCandidate(parsed, output) {
|
|
|
21458
21562
|
const annotation = owner?.returnType?.typeAnnotation;
|
|
21459
21563
|
if (annotation === void 0) return null;
|
|
21460
21564
|
const typeReference = returnContractReference(annotation);
|
|
21461
|
-
if (typeReference === null || typeReference.typeName.type !==
|
|
21565
|
+
if (typeReference === null || typeReference.typeName.type !== import_utils117.AST_NODE_TYPES.Identifier) {
|
|
21462
21566
|
return null;
|
|
21463
21567
|
}
|
|
21464
21568
|
return {
|
|
@@ -21475,7 +21579,7 @@ function directParseReturnCandidate(node) {
|
|
|
21475
21579
|
return parsed?.method === "parse" ? returnedOutputCandidate(parsed, node) : null;
|
|
21476
21580
|
}
|
|
21477
21581
|
function localParseReturnCandidates(node, sourceCode) {
|
|
21478
|
-
if (node.id.type !==
|
|
21582
|
+
if (node.id.type !== import_utils117.AST_NODE_TYPES.Identifier || node.init?.type !== import_utils117.AST_NODE_TYPES.CallExpression || node.parent.type !== import_utils117.AST_NODE_TYPES.VariableDeclaration || node.parent.kind !== "const" || enclosingFunction4(node.init) === null) {
|
|
21479
21583
|
return [];
|
|
21480
21584
|
}
|
|
21481
21585
|
const parsed = zodParseCall(node.init);
|
|
@@ -21486,7 +21590,7 @@ function localParseReturnCandidates(node, sourceCode) {
|
|
|
21486
21590
|
for (const reference of variable.references) {
|
|
21487
21591
|
const identifier = reference.identifier;
|
|
21488
21592
|
const parent = identifier.parent;
|
|
21489
|
-
const output = parsed.method === "parse" ? identifier : parent.type ===
|
|
21593
|
+
const output = parsed.method === "parse" ? identifier : parent.type === import_utils117.AST_NODE_TYPES.MemberExpression && parent.object === identifier && import_utils117.ASTUtils.getPropertyName(parent) !== null && (import_utils117.ASTUtils.getPropertyName(parent) ?? "") === "data" ? parent : null;
|
|
21490
21594
|
if (output === null) continue;
|
|
21491
21595
|
const candidate2 = returnedOutputCandidate(parsed, output);
|
|
21492
21596
|
if (candidate2 !== null) candidates.push(candidate2);
|
|
@@ -21497,17 +21601,17 @@ function directReturnOwner(node) {
|
|
|
21497
21601
|
let current = node;
|
|
21498
21602
|
while (current.parent !== void 0) {
|
|
21499
21603
|
const parent = current.parent;
|
|
21500
|
-
if (parent.type ===
|
|
21604
|
+
if (parent.type === import_utils117.AST_NODE_TYPES.ReturnStatement) {
|
|
21501
21605
|
return parent.argument === current ? enclosingFunction4(parent) : null;
|
|
21502
21606
|
}
|
|
21503
|
-
if (parent.type ===
|
|
21607
|
+
if (parent.type === import_utils117.AST_NODE_TYPES.ArrowFunctionExpression && parent.expression && parent.body === current) {
|
|
21504
21608
|
return parent;
|
|
21505
21609
|
}
|
|
21506
|
-
if (parent.type ===
|
|
21610
|
+
if (parent.type === import_utils117.AST_NODE_TYPES.AwaitExpression && parent.argument === current) {
|
|
21507
21611
|
current = parent;
|
|
21508
21612
|
continue;
|
|
21509
21613
|
}
|
|
21510
|
-
if (parent.type ===
|
|
21614
|
+
if (parent.type === import_utils117.AST_NODE_TYPES.ConditionalExpression) {
|
|
21511
21615
|
const parsedWhenTrue = parent.consequent === current && isNullishExpression(parent.alternate);
|
|
21512
21616
|
const parsedWhenFalse = parent.alternate === current && isNullishExpression(parent.consequent);
|
|
21513
21617
|
if (parsedWhenTrue || parsedWhenFalse) {
|
|
@@ -21520,12 +21624,12 @@ function directReturnOwner(node) {
|
|
|
21520
21624
|
return null;
|
|
21521
21625
|
}
|
|
21522
21626
|
function isNullishExpression(node) {
|
|
21523
|
-
return node.type ===
|
|
21627
|
+
return node.type === import_utils117.AST_NODE_TYPES.Literal && node.value === null || node.type === import_utils117.AST_NODE_TYPES.Identifier && node.name === "undefined";
|
|
21524
21628
|
}
|
|
21525
21629
|
function enclosingFunction4(node) {
|
|
21526
21630
|
let current = node.parent;
|
|
21527
21631
|
while (current != null) {
|
|
21528
|
-
if (current.type ===
|
|
21632
|
+
if (current.type === import_utils117.AST_NODE_TYPES.ArrowFunctionExpression || current.type === import_utils117.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils117.AST_NODE_TYPES.FunctionExpression) {
|
|
21529
21633
|
return current;
|
|
21530
21634
|
}
|
|
21531
21635
|
current = current.parent;
|
|
@@ -21533,45 +21637,45 @@ function enclosingFunction4(node) {
|
|
|
21533
21637
|
return null;
|
|
21534
21638
|
}
|
|
21535
21639
|
function returnContractReference(node) {
|
|
21536
|
-
if (node.type ===
|
|
21640
|
+
if (node.type === import_utils117.AST_NODE_TYPES.TSUnionType) {
|
|
21537
21641
|
const substantive = node.types.filter(
|
|
21538
|
-
(member) => member.type !==
|
|
21642
|
+
(member) => member.type !== import_utils117.AST_NODE_TYPES.TSNullKeyword && member.type !== import_utils117.AST_NODE_TYPES.TSUndefinedKeyword
|
|
21539
21643
|
);
|
|
21540
21644
|
const [only] = substantive;
|
|
21541
21645
|
return substantive.length === 1 && only !== void 0 ? returnContractReference(only) : null;
|
|
21542
21646
|
}
|
|
21543
|
-
if (node.type ===
|
|
21647
|
+
if (node.type === import_utils117.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils117.AST_NODE_TYPES.Identifier && node.typeName.name === "Promise") {
|
|
21544
21648
|
const parameters = node.typeArguments?.params ?? [];
|
|
21545
21649
|
const [only] = parameters;
|
|
21546
21650
|
return parameters.length === 1 && only !== void 0 ? returnContractReference(only) : null;
|
|
21547
21651
|
}
|
|
21548
|
-
return node.type ===
|
|
21652
|
+
return node.type === import_utils117.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils117.AST_NODE_TYPES.Identifier && (node.typeArguments?.params.length ?? 0) === 0 ? node : null;
|
|
21549
21653
|
}
|
|
21550
21654
|
function recordZodNamespaces(node, namespaces) {
|
|
21551
21655
|
for (const statement of node.body) {
|
|
21552
|
-
if (statement.type !==
|
|
21656
|
+
if (statement.type !== import_utils117.AST_NODE_TYPES.ImportDeclaration || !isZodModule(statement.source.value)) {
|
|
21553
21657
|
continue;
|
|
21554
21658
|
}
|
|
21555
21659
|
for (const specifier of statement.specifiers) {
|
|
21556
|
-
if (specifier.type ===
|
|
21660
|
+
if (specifier.type === import_utils117.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils117.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils117.AST_NODE_TYPES.ImportSpecifier && importSpecifierName(specifier) === "z") {
|
|
21557
21661
|
namespaces.add(specifier.local.name);
|
|
21558
21662
|
}
|
|
21559
21663
|
}
|
|
21560
21664
|
}
|
|
21561
21665
|
}
|
|
21562
21666
|
function collectConstrainedNames(node, names) {
|
|
21563
|
-
if (node.type ===
|
|
21564
|
-
if (node.typeName.type ===
|
|
21667
|
+
if (node.type === import_utils117.AST_NODE_TYPES.TSTypeReference) {
|
|
21668
|
+
if (node.typeName.type === import_utils117.AST_NODE_TYPES.Identifier) names.add(node.typeName.name);
|
|
21565
21669
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
21566
21670
|
collectConstrainedNames(argument, names);
|
|
21567
21671
|
}
|
|
21568
21672
|
return;
|
|
21569
21673
|
}
|
|
21570
|
-
if (node.type ===
|
|
21674
|
+
if (node.type === import_utils117.AST_NODE_TYPES.TSArrayType) {
|
|
21571
21675
|
collectConstrainedNames(node.elementType, names);
|
|
21572
21676
|
return;
|
|
21573
21677
|
}
|
|
21574
|
-
if (node.type ===
|
|
21678
|
+
if (node.type === import_utils117.AST_NODE_TYPES.TSUnionType || node.type === import_utils117.AST_NODE_TYPES.TSIntersectionType) {
|
|
21575
21679
|
for (const member of node.types) collectConstrainedNames(member, names);
|
|
21576
21680
|
}
|
|
21577
21681
|
}
|
|
@@ -21605,7 +21709,7 @@ function reportCandidates(context, services, schemas, candidates, zodNamespaces,
|
|
|
21605
21709
|
if (constrained) return;
|
|
21606
21710
|
if (declaration.getSourceFile() === tsSchema.getSourceFile()) {
|
|
21607
21711
|
const estreeDeclaration = services.tsNodeToESTreeNodeMap.get(declaration);
|
|
21608
|
-
if ((estreeDeclaration.type ===
|
|
21712
|
+
if ((estreeDeclaration.type === import_utils117.AST_NODE_TYPES.TSInterfaceDeclaration || estreeDeclaration.type === import_utils117.AST_NODE_TYPES.TSTypeAliasDeclaration) && preferZodInferOwnsDefaultTwin({
|
|
21609
21713
|
constrained,
|
|
21610
21714
|
declaration: estreeDeclaration,
|
|
21611
21715
|
initializer: schema.initializer,
|
|
@@ -21695,7 +21799,7 @@ var prefer_zod_parse_output_type_default = createRule({
|
|
|
21695
21799
|
}
|
|
21696
21800
|
let services;
|
|
21697
21801
|
try {
|
|
21698
|
-
services =
|
|
21802
|
+
services = import_utils117.ESLintUtils.getParserServices(context);
|
|
21699
21803
|
} catch {
|
|
21700
21804
|
services = null;
|
|
21701
21805
|
}
|
|
@@ -21710,7 +21814,7 @@ var prefer_zod_parse_output_type_default = createRule({
|
|
|
21710
21814
|
recordZodNamespaces(node, namespaces);
|
|
21711
21815
|
},
|
|
21712
21816
|
VariableDeclarator(node) {
|
|
21713
|
-
if (node.id.type ===
|
|
21817
|
+
if (node.id.type === import_utils117.AST_NODE_TYPES.Identifier && node.init !== null && isModuleLevelConst2(node) && isLocalZodObjectSchema(node.init, namespaces)) {
|
|
21714
21818
|
schemas.push({ identifier: node.id, initializer: node.init, name: node.id.name });
|
|
21715
21819
|
}
|
|
21716
21820
|
candidates.push(...localParseReturnCandidates(node, context.sourceCode));
|
|
@@ -21720,13 +21824,13 @@ var prefer_zod_parse_output_type_default = createRule({
|
|
|
21720
21824
|
if (candidate2 !== null) candidates.push(candidate2);
|
|
21721
21825
|
},
|
|
21722
21826
|
"MemberExpression"(node) {
|
|
21723
|
-
if (node.object.type ===
|
|
21827
|
+
if (node.object.type === import_utils117.AST_NODE_TYPES.Identifier && node.property.type === import_utils117.AST_NODE_TYPES.Identifier && isPreferZodInferModuleReshaper(node.property.name)) {
|
|
21724
21828
|
reshapedSchemas.add(node.object.name);
|
|
21725
21829
|
}
|
|
21726
21830
|
},
|
|
21727
21831
|
TSTypeReference(node) {
|
|
21728
21832
|
const { typeName } = node;
|
|
21729
|
-
const name = typeName.type ===
|
|
21833
|
+
const name = typeName.type === import_utils117.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils117.AST_NODE_TYPES.TSQualifiedName && typeName.right.type === import_utils117.AST_NODE_TYPES.Identifier ? typeName.right.name : null;
|
|
21730
21834
|
if (name === null || !isPreferZodInferTypeConstraintName(name)) return;
|
|
21731
21835
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
21732
21836
|
collectConstrainedNames(argument, constrainedTypeNames);
|
|
@@ -21748,7 +21852,7 @@ var prefer_zod_parse_output_type_default = createRule({
|
|
|
21748
21852
|
});
|
|
21749
21853
|
|
|
21750
21854
|
// src/rules/require-assert-never.ts
|
|
21751
|
-
var
|
|
21855
|
+
var import_utils118 = require("@typescript-eslint/utils");
|
|
21752
21856
|
var import_typescript8 = __toESM(require("typescript"), 1);
|
|
21753
21857
|
var REQUIRE_ASSERT_NEVER_DOCUMENTATION = {
|
|
21754
21858
|
summary: "Require an empty switch default to call `assertNever` so discriminated unions remain exhaustive at compile time.",
|
|
@@ -21762,14 +21866,14 @@ var REQUIRE_ASSERT_NEVER_DOCUMENTATION = {
|
|
|
21762
21866
|
]
|
|
21763
21867
|
};
|
|
21764
21868
|
var isRuntimeHandlingStatement = (statement) => {
|
|
21765
|
-
if (statement.type ===
|
|
21766
|
-
if (statement.type ===
|
|
21869
|
+
if (statement.type === import_utils118.AST_NODE_TYPES.EmptyStatement) return false;
|
|
21870
|
+
if (statement.type === import_utils118.AST_NODE_TYPES.BreakStatement) {
|
|
21767
21871
|
return statement.label !== null;
|
|
21768
21872
|
}
|
|
21769
|
-
if (statement.type ===
|
|
21873
|
+
if (statement.type === import_utils118.AST_NODE_TYPES.TSTypeAliasDeclaration || statement.type === import_utils118.AST_NODE_TYPES.TSInterfaceDeclaration) {
|
|
21770
21874
|
return false;
|
|
21771
21875
|
}
|
|
21772
|
-
if (statement.type ===
|
|
21876
|
+
if (statement.type === import_utils118.AST_NODE_TYPES.BlockStatement) {
|
|
21773
21877
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
21774
21878
|
}
|
|
21775
21879
|
return true;
|
|
@@ -21785,7 +21889,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
21785
21889
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
21786
21890
|
}
|
|
21787
21891
|
const only = defaultCase.consequent[0];
|
|
21788
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
21892
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === import_utils118.AST_NODE_TYPES.BlockStatement && !only.body.some(isRuntimeHandlingStatement)) {
|
|
21789
21893
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
21790
21894
|
}
|
|
21791
21895
|
return false;
|
|
@@ -21839,7 +21943,7 @@ var require_assert_never_default = createRule({
|
|
|
21839
21943
|
create(context) {
|
|
21840
21944
|
let services;
|
|
21841
21945
|
try {
|
|
21842
|
-
services =
|
|
21946
|
+
services = import_utils118.ESLintUtils.getParserServices(context);
|
|
21843
21947
|
} catch {
|
|
21844
21948
|
services = null;
|
|
21845
21949
|
}
|
|
@@ -21866,7 +21970,7 @@ var require_assert_never_default = createRule({
|
|
|
21866
21970
|
});
|
|
21867
21971
|
|
|
21868
21972
|
// src/rules/require-fetch-timeout.ts
|
|
21869
|
-
var
|
|
21973
|
+
var import_utils119 = require("@typescript-eslint/utils");
|
|
21870
21974
|
var REQUIRE_FETCH_TIMEOUT_DOCUMENTATION = {
|
|
21871
21975
|
summary: "Require an explicit abort signal on locally analyzable global fetch calls.",
|
|
21872
21976
|
rationale: "An unbounded request can occupy work indefinitely when an upstream stalls.",
|
|
@@ -21893,18 +21997,18 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
21893
21997
|
return false;
|
|
21894
21998
|
}
|
|
21895
21999
|
function initProvablyLacksSignal(init, resolvesToGlobal) {
|
|
21896
|
-
if (init.type !==
|
|
22000
|
+
if (init.type !== import_utils119.AST_NODE_TYPES.ObjectExpression) return false;
|
|
21897
22001
|
let lacksSignal = true;
|
|
21898
22002
|
for (const prop of init.properties) {
|
|
21899
|
-
if (prop.type ===
|
|
22003
|
+
if (prop.type === import_utils119.AST_NODE_TYPES.SpreadElement) {
|
|
21900
22004
|
lacksSignal = false;
|
|
21901
22005
|
continue;
|
|
21902
22006
|
}
|
|
21903
|
-
const isSignal = !prop.computed && prop.key.type ===
|
|
22007
|
+
const isSignal = !prop.computed && prop.key.type === import_utils119.AST_NODE_TYPES.Identifier && prop.key.name === "signal" || prop.key.type === import_utils119.AST_NODE_TYPES.Literal && prop.key.value === "signal";
|
|
21904
22008
|
if (isSignal) {
|
|
21905
22009
|
const value = prop.value;
|
|
21906
|
-
lacksSignal = prop.kind === "init" && !prop.method && (value.type ===
|
|
21907
|
-
} else if (prop.computed && prop.key.type !==
|
|
22010
|
+
lacksSignal = prop.kind === "init" && !prop.method && (value.type === import_utils119.AST_NODE_TYPES.Literal && value.value === null || value.type === import_utils119.AST_NODE_TYPES.Identifier && value.name === "undefined" && resolvesToGlobal(value) || value.type === import_utils119.AST_NODE_TYPES.UnaryExpression && value.operator === "void" && value.argument.type === import_utils119.AST_NODE_TYPES.Literal && value.argument.value === 0);
|
|
22011
|
+
} else if (prop.computed && prop.key.type !== import_utils119.AST_NODE_TYPES.Literal) {
|
|
21908
22012
|
lacksSignal = false;
|
|
21909
22013
|
}
|
|
21910
22014
|
}
|
|
@@ -21912,7 +22016,7 @@ function initProvablyLacksSignal(init, resolvesToGlobal) {
|
|
|
21912
22016
|
}
|
|
21913
22017
|
function isInlineUrl(node, resolvesToGlobal) {
|
|
21914
22018
|
node = unwrapExpression(node);
|
|
21915
|
-
return node.type ===
|
|
22019
|
+
return node.type === import_utils119.AST_NODE_TYPES.Literal && typeof node.value === "string" || node.type === import_utils119.AST_NODE_TYPES.TemplateLiteral || node.type === import_utils119.AST_NODE_TYPES.NewExpression && node.callee.type === import_utils119.AST_NODE_TYPES.Identifier && node.callee.name === "URL" && resolvesToGlobal(node.callee);
|
|
21916
22020
|
}
|
|
21917
22021
|
var require_fetch_timeout_default = createRule({
|
|
21918
22022
|
name: "require-fetch-timeout",
|
|
@@ -21950,30 +22054,30 @@ var require_fetch_timeout_default = createRule({
|
|
|
21950
22054
|
}
|
|
21951
22055
|
function resolvesToGlobal(identifier) {
|
|
21952
22056
|
const scope = context.sourceCode.getScope(identifier);
|
|
21953
|
-
const variable =
|
|
22057
|
+
const variable = import_utils119.ASTUtils.findVariable(scope, identifier.name);
|
|
21954
22058
|
return variable === null || variable.defs.length === 0;
|
|
21955
22059
|
}
|
|
21956
22060
|
function isGlobalFetchCall2(callee) {
|
|
21957
|
-
if (callee.type ===
|
|
22061
|
+
if (callee.type === import_utils119.AST_NODE_TYPES.Identifier) {
|
|
21958
22062
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
21959
22063
|
}
|
|
21960
|
-
return callee.type ===
|
|
22064
|
+
return callee.type === import_utils119.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils119.AST_NODE_TYPES.Identifier && callee.property.name === "fetch" && callee.object.type === import_utils119.AST_NODE_TYPES.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
21961
22065
|
}
|
|
21962
22066
|
function localConstInitProvablyLacksSignal(identifier) {
|
|
21963
|
-
const variable =
|
|
22067
|
+
const variable = import_utils119.ASTUtils.findVariable(
|
|
21964
22068
|
context.sourceCode.getScope(identifier),
|
|
21965
22069
|
identifier.name
|
|
21966
22070
|
);
|
|
21967
22071
|
if (variable?.defs.length !== 1) return false;
|
|
21968
22072
|
const definition = variable.defs[0];
|
|
21969
|
-
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !==
|
|
22073
|
+
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !== import_utils119.AST_NODE_TYPES.ObjectExpression || !initProvablyLacksSignal(definition.node.init, resolvesToGlobal)) {
|
|
21970
22074
|
return false;
|
|
21971
22075
|
}
|
|
21972
22076
|
for (const reference of variable.references) {
|
|
21973
22077
|
const ref = reference.identifier;
|
|
21974
22078
|
if (ref === identifier || ref === definition.name) continue;
|
|
21975
22079
|
const member = ref.parent;
|
|
21976
|
-
if (member.type !==
|
|
22080
|
+
if (member.type !== import_utils119.AST_NODE_TYPES.MemberExpression || member.object !== ref || member.computed || member.property.type !== import_utils119.AST_NODE_TYPES.Identifier || member.property.name === "signal" || member.parent.type !== import_utils119.AST_NODE_TYPES.AssignmentExpression || member.parent.left !== member) {
|
|
21977
22081
|
return false;
|
|
21978
22082
|
}
|
|
21979
22083
|
}
|
|
@@ -21981,13 +22085,13 @@ var require_fetch_timeout_default = createRule({
|
|
|
21981
22085
|
}
|
|
21982
22086
|
function isForwardedRequest(argument) {
|
|
21983
22087
|
let value = argument;
|
|
21984
|
-
if (value.type ===
|
|
21985
|
-
const binding =
|
|
22088
|
+
if (value.type === import_utils119.AST_NODE_TYPES.Identifier) {
|
|
22089
|
+
const binding = import_utils119.ASTUtils.findVariable(context.sourceCode.getScope(value), value.name);
|
|
21986
22090
|
const definition = binding?.defs.length === 1 ? binding.defs[0] : void 0;
|
|
21987
22091
|
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init === null || binding?.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
21988
22092
|
value = definition.node.init;
|
|
21989
22093
|
}
|
|
21990
|
-
return value.type ===
|
|
22094
|
+
return value.type === import_utils119.AST_NODE_TYPES.NewExpression && value.callee.type === import_utils119.AST_NODE_TYPES.Identifier && value.callee.name === "Request" && resolvesToGlobal(value.callee);
|
|
21991
22095
|
}
|
|
21992
22096
|
return {
|
|
21993
22097
|
CallExpression(node) {
|
|
@@ -21999,7 +22103,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
21999
22103
|
if (first !== void 0 && (node.arguments.length === 1 && !isInlineUrl(first, resolvesToGlobal) || isForwardedRequest(first))) {
|
|
22000
22104
|
return;
|
|
22001
22105
|
}
|
|
22002
|
-
if (init === void 0 || initProvablyLacksSignal(init, resolvesToGlobal) || init.type ===
|
|
22106
|
+
if (init === void 0 || initProvablyLacksSignal(init, resolvesToGlobal) || init.type === import_utils119.AST_NODE_TYPES.Identifier && localConstInitProvablyLacksSignal(init)) {
|
|
22003
22107
|
context.report({ node, messageId: "missingSignal" });
|
|
22004
22108
|
}
|
|
22005
22109
|
}
|
|
@@ -22008,7 +22112,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
22008
22112
|
});
|
|
22009
22113
|
|
|
22010
22114
|
// src/rules/require-interface-for-exported-class.ts
|
|
22011
|
-
var
|
|
22115
|
+
var import_utils120 = require("@typescript-eslint/utils");
|
|
22012
22116
|
var REQUIRE_INTERFACE_FOR_EXPORTED_CLASS_DOCUMENTATION = {
|
|
22013
22117
|
defaultLevel: "warning",
|
|
22014
22118
|
summary: "Require exported concrete classes with public behavior to declare a contract.",
|
|
@@ -22055,23 +22159,23 @@ var REQUIRE_INTERFACE_FOR_EXPORTED_CLASS_DOCUMENTATION = {
|
|
|
22055
22159
|
};
|
|
22056
22160
|
function hasPublicInstanceBehavior(node) {
|
|
22057
22161
|
return node.body.body.some((member) => {
|
|
22058
|
-
if (member.type ===
|
|
22059
|
-
return member.kind !== "constructor" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.key.type !==
|
|
22162
|
+
if (member.type === import_utils120.AST_NODE_TYPES.MethodDefinition) {
|
|
22163
|
+
return member.kind !== "constructor" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.key.type !== import_utils120.AST_NODE_TYPES.PrivateIdentifier;
|
|
22060
22164
|
}
|
|
22061
|
-
if (member.type !==
|
|
22165
|
+
if (member.type !== import_utils120.AST_NODE_TYPES.PropertyDefinition || member.static)
|
|
22062
22166
|
return false;
|
|
22063
|
-
if (member.accessibility === "private" || member.accessibility === "protected" || member.key.type ===
|
|
22064
|
-
return member.value?.type ===
|
|
22167
|
+
if (member.accessibility === "private" || member.accessibility === "protected" || member.key.type === import_utils120.AST_NODE_TYPES.PrivateIdentifier) return false;
|
|
22168
|
+
return member.value?.type === import_utils120.AST_NODE_TYPES.ArrowFunctionExpression || member.value?.type === import_utils120.AST_NODE_TYPES.FunctionExpression || member.typeAnnotation?.typeAnnotation.type === import_utils120.AST_NODE_TYPES.TSFunctionType;
|
|
22065
22169
|
});
|
|
22066
22170
|
}
|
|
22067
22171
|
function classBindings(statement) {
|
|
22068
|
-
const declaration = statement.type ===
|
|
22069
|
-
if (declaration?.type ===
|
|
22172
|
+
const declaration = statement.type === import_utils120.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
22173
|
+
if (declaration?.type === import_utils120.AST_NODE_TYPES.ClassDeclaration) {
|
|
22070
22174
|
return declaration.id === null ? [] : [{ declaration, name: declaration.id.name }];
|
|
22071
22175
|
}
|
|
22072
|
-
if (declaration?.type !==
|
|
22176
|
+
if (declaration?.type !== import_utils120.AST_NODE_TYPES.VariableDeclaration) return [];
|
|
22073
22177
|
return declaration.declarations.flatMap(
|
|
22074
|
-
(item) => item.id.type ===
|
|
22178
|
+
(item) => item.id.type === import_utils120.AST_NODE_TYPES.Identifier && item.init?.type === import_utils120.AST_NODE_TYPES.ClassExpression ? [{ declaration: item.init, name: item.id.name }] : []
|
|
22075
22179
|
);
|
|
22076
22180
|
}
|
|
22077
22181
|
var require_interface_for_exported_class_default = createRule({
|
|
@@ -22105,7 +22209,7 @@ var require_interface_for_exported_class_default = createRule({
|
|
|
22105
22209
|
}
|
|
22106
22210
|
const exported = exportedClasses(program, classes);
|
|
22107
22211
|
for (const [declaration, exportedName] of exported) {
|
|
22108
|
-
const extendsLocalAbstractBase = declaration.superClass?.type ===
|
|
22212
|
+
const extendsLocalAbstractBase = declaration.superClass?.type === import_utils120.AST_NODE_TYPES.Identifier && abstractBases.has(declaration.superClass.name);
|
|
22109
22213
|
if (declaration.abstract || declaration.implements.length > 0 || extendsLocalAbstractBase || !hasPublicInstanceBehavior(declaration)) continue;
|
|
22110
22214
|
context.report({
|
|
22111
22215
|
node: declaration.id ?? declaration,
|
|
@@ -22120,7 +22224,7 @@ var require_interface_for_exported_class_default = createRule({
|
|
|
22120
22224
|
function exportedClasses(program, classes) {
|
|
22121
22225
|
const exported = /* @__PURE__ */ new Map();
|
|
22122
22226
|
function collectExportedClass(statement) {
|
|
22123
|
-
if (statement.type ===
|
|
22227
|
+
if (statement.type === import_utils120.AST_NODE_TYPES.ExportNamedDeclaration) {
|
|
22124
22228
|
for (const binding of classBindings(statement)) {
|
|
22125
22229
|
exported.set(binding.declaration, binding.name);
|
|
22126
22230
|
}
|
|
@@ -22128,13 +22232,13 @@ function exportedClasses(program, classes) {
|
|
|
22128
22232
|
collectClassSpecifiers(statement);
|
|
22129
22233
|
return;
|
|
22130
22234
|
}
|
|
22131
|
-
if (statement.type !==
|
|
22132
|
-
if (statement.declaration.type ===
|
|
22235
|
+
if (statement.type !== import_utils120.AST_NODE_TYPES.ExportDefaultDeclaration) return;
|
|
22236
|
+
if (statement.declaration.type === import_utils120.AST_NODE_TYPES.ClassDeclaration || statement.declaration.type === import_utils120.AST_NODE_TYPES.ClassExpression) {
|
|
22133
22237
|
exported.set(
|
|
22134
22238
|
statement.declaration,
|
|
22135
22239
|
statement.declaration.id?.name ?? "default"
|
|
22136
22240
|
);
|
|
22137
|
-
} else if (statement.declaration.type ===
|
|
22241
|
+
} else if (statement.declaration.type === import_utils120.AST_NODE_TYPES.Identifier) {
|
|
22138
22242
|
const candidate2 = classes.get(statement.declaration.name);
|
|
22139
22243
|
if (candidate2 !== void 0) {
|
|
22140
22244
|
exported.set(candidate2, statement.declaration.name);
|
|
@@ -22146,7 +22250,7 @@ function exportedClasses(program, classes) {
|
|
|
22146
22250
|
if (specifier.exportKind === "type") continue;
|
|
22147
22251
|
const candidate2 = classes.get(specifier.local.name);
|
|
22148
22252
|
if (candidate2 === void 0) continue;
|
|
22149
|
-
const exportedName = specifier.exported.type ===
|
|
22253
|
+
const exportedName = specifier.exported.type === import_utils120.AST_NODE_TYPES.Identifier ? specifier.exported.name : specifier.exported.value;
|
|
22150
22254
|
exported.set(candidate2, exportedName);
|
|
22151
22255
|
}
|
|
22152
22256
|
}
|
|
@@ -22157,7 +22261,7 @@ function exportedClasses(program, classes) {
|
|
|
22157
22261
|
}
|
|
22158
22262
|
|
|
22159
22263
|
// src/rules/require-sql-access-class.ts
|
|
22160
|
-
var
|
|
22264
|
+
var import_utils121 = require("@typescript-eslint/utils");
|
|
22161
22265
|
var DIRECT_EXECUTION_METHODS = /* @__PURE__ */ new Set([
|
|
22162
22266
|
"all",
|
|
22163
22267
|
"batch",
|
|
@@ -22261,80 +22365,80 @@ function isDatabaseOperation(method, receiver) {
|
|
|
22261
22365
|
}
|
|
22262
22366
|
function databaseReceiver(node) {
|
|
22263
22367
|
node = unwrapExpression(node);
|
|
22264
|
-
if (node.type ===
|
|
22368
|
+
if (node.type === import_utils121.AST_NODE_TYPES.Identifier)
|
|
22265
22369
|
return DATABASE_NAMES.test(node.name);
|
|
22266
|
-
if (node.type !==
|
|
22267
|
-
const name =
|
|
22370
|
+
if (node.type !== import_utils121.AST_NODE_TYPES.MemberExpression) return false;
|
|
22371
|
+
const name = import_utils121.ASTUtils.getPropertyName(node);
|
|
22268
22372
|
return name === "DB" || name !== null && DATABASE_NAMES.test(name);
|
|
22269
22373
|
}
|
|
22270
22374
|
function databaseRootMember(node) {
|
|
22271
22375
|
let current = node;
|
|
22272
22376
|
for (; ; ) {
|
|
22273
22377
|
current = unwrapExpression(current);
|
|
22274
|
-
if (current.type ===
|
|
22378
|
+
if (current.type === import_utils121.AST_NODE_TYPES.ChainExpression) {
|
|
22275
22379
|
current = current.expression;
|
|
22276
22380
|
continue;
|
|
22277
22381
|
}
|
|
22278
|
-
if (current.type ===
|
|
22279
|
-
if (current.callee.type !==
|
|
22382
|
+
if (current.type === import_utils121.AST_NODE_TYPES.CallExpression) {
|
|
22383
|
+
if (current.callee.type !== import_utils121.AST_NODE_TYPES.MemberExpression) return null;
|
|
22280
22384
|
current = current.callee.object;
|
|
22281
22385
|
continue;
|
|
22282
22386
|
}
|
|
22283
|
-
if (current.type ===
|
|
22284
|
-
if (current.object.type ===
|
|
22285
|
-
return
|
|
22387
|
+
if (current.type === import_utils121.AST_NODE_TYPES.MemberExpression) {
|
|
22388
|
+
if (current.object.type === import_utils121.AST_NODE_TYPES.ThisExpression)
|
|
22389
|
+
return import_utils121.ASTUtils.getPropertyName(current);
|
|
22286
22390
|
current = current.object;
|
|
22287
22391
|
continue;
|
|
22288
22392
|
}
|
|
22289
|
-
return current.type ===
|
|
22393
|
+
return current.type === import_utils121.AST_NODE_TYPES.Identifier ? current.name : null;
|
|
22290
22394
|
}
|
|
22291
22395
|
}
|
|
22292
22396
|
function expressionHasDatabaseMarker(node) {
|
|
22293
22397
|
let current = node;
|
|
22294
22398
|
for (; ; ) {
|
|
22295
22399
|
current = unwrapExpression(current);
|
|
22296
|
-
if (current.type ===
|
|
22400
|
+
if (current.type === import_utils121.AST_NODE_TYPES.ChainExpression) {
|
|
22297
22401
|
current = current.expression;
|
|
22298
22402
|
continue;
|
|
22299
22403
|
}
|
|
22300
|
-
if (current.type ===
|
|
22301
|
-
if (current.callee.type !==
|
|
22404
|
+
if (current.type === import_utils121.AST_NODE_TYPES.CallExpression) {
|
|
22405
|
+
if (current.callee.type !== import_utils121.AST_NODE_TYPES.MemberExpression) return false;
|
|
22302
22406
|
current = current.callee.object;
|
|
22303
22407
|
continue;
|
|
22304
22408
|
}
|
|
22305
|
-
if (current.type ===
|
|
22306
|
-
const name =
|
|
22409
|
+
if (current.type === import_utils121.AST_NODE_TYPES.MemberExpression) {
|
|
22410
|
+
const name = import_utils121.ASTUtils.getPropertyName(current);
|
|
22307
22411
|
if (name === "DB" || name !== null && DATABASE_NAMES.test(name))
|
|
22308
22412
|
return true;
|
|
22309
22413
|
current = current.object;
|
|
22310
22414
|
continue;
|
|
22311
22415
|
}
|
|
22312
|
-
return current.type ===
|
|
22416
|
+
return current.type === import_utils121.AST_NODE_TYPES.Identifier && DATABASE_NAMES.test(current.name);
|
|
22313
22417
|
}
|
|
22314
22418
|
}
|
|
22315
22419
|
function expressionCallsBuilder(node) {
|
|
22316
22420
|
let current = node;
|
|
22317
22421
|
for (; ; ) {
|
|
22318
22422
|
current = unwrapExpression(current);
|
|
22319
|
-
if (current.type ===
|
|
22423
|
+
if (current.type === import_utils121.AST_NODE_TYPES.ChainExpression) {
|
|
22320
22424
|
current = current.expression;
|
|
22321
22425
|
continue;
|
|
22322
22426
|
}
|
|
22323
|
-
if (current.type ===
|
|
22324
|
-
if (current.callee.type !==
|
|
22325
|
-
const name =
|
|
22427
|
+
if (current.type === import_utils121.AST_NODE_TYPES.CallExpression) {
|
|
22428
|
+
if (current.callee.type !== import_utils121.AST_NODE_TYPES.MemberExpression) return false;
|
|
22429
|
+
const name = import_utils121.ASTUtils.getPropertyName(current.callee);
|
|
22326
22430
|
if (name !== null && BUILDER_METHODS.has(name)) return true;
|
|
22327
22431
|
current = current.callee.object;
|
|
22328
22432
|
continue;
|
|
22329
22433
|
}
|
|
22330
|
-
if (current.type !==
|
|
22434
|
+
if (current.type !== import_utils121.AST_NODE_TYPES.MemberExpression) return false;
|
|
22331
22435
|
current = current.object;
|
|
22332
22436
|
}
|
|
22333
22437
|
}
|
|
22334
22438
|
function owningClass2(node) {
|
|
22335
22439
|
let current = node.parent;
|
|
22336
22440
|
while (current != null) {
|
|
22337
|
-
if (current.type ===
|
|
22441
|
+
if (current.type === import_utils121.AST_NODE_TYPES.ClassDeclaration || current.type === import_utils121.AST_NODE_TYPES.ClassExpression)
|
|
22338
22442
|
return current;
|
|
22339
22443
|
current = current.parent;
|
|
22340
22444
|
}
|
|
@@ -22343,25 +22447,25 @@ function owningClass2(node) {
|
|
|
22343
22447
|
function injectedMembers(owner) {
|
|
22344
22448
|
const injected = /* @__PURE__ */ new Set();
|
|
22345
22449
|
const constructor = owner.body.body.find(
|
|
22346
|
-
(member) => member.type ===
|
|
22450
|
+
(member) => member.type === import_utils121.AST_NODE_TYPES.MethodDefinition && member.kind === "constructor"
|
|
22347
22451
|
);
|
|
22348
22452
|
if (constructor === void 0) return injected;
|
|
22349
22453
|
const parameters = /* @__PURE__ */ new Set();
|
|
22350
22454
|
for (const parameter of constructor.value.params) {
|
|
22351
22455
|
for (const name of parameterNames(parameter)) parameters.add(name);
|
|
22352
|
-
if (parameter.type !==
|
|
22353
|
-
const value = parameter.parameter.type ===
|
|
22354
|
-
if (value.type ===
|
|
22456
|
+
if (parameter.type !== import_utils121.AST_NODE_TYPES.TSParameterProperty) continue;
|
|
22457
|
+
const value = parameter.parameter.type === import_utils121.AST_NODE_TYPES.AssignmentPattern ? parameter.parameter.left : parameter.parameter;
|
|
22458
|
+
if (value.type === import_utils121.AST_NODE_TYPES.Identifier) injected.add(value.name);
|
|
22355
22459
|
}
|
|
22356
22460
|
const body2 = constructor.value.body;
|
|
22357
22461
|
if (body2 === null) return injected;
|
|
22358
22462
|
function collectInjectedMember(statement) {
|
|
22359
|
-
if (statement.type !==
|
|
22463
|
+
if (statement.type !== import_utils121.AST_NODE_TYPES.ExpressionStatement || statement.expression.type !== import_utils121.AST_NODE_TYPES.AssignmentExpression || statement.expression.operator !== "=") return;
|
|
22360
22464
|
const { left, right } = statement.expression;
|
|
22361
|
-
if (left.type !==
|
|
22465
|
+
if (left.type !== import_utils121.AST_NODE_TYPES.MemberExpression) return;
|
|
22362
22466
|
const target = thisRootMember(left);
|
|
22363
22467
|
if (target === null) return;
|
|
22364
|
-
const source = right.type ===
|
|
22468
|
+
const source = right.type === import_utils121.AST_NODE_TYPES.Identifier ? right.name : right.type === import_utils121.AST_NODE_TYPES.MemberExpression && right.object.type === import_utils121.AST_NODE_TYPES.Identifier ? right.object.name : null;
|
|
22365
22469
|
if (source !== null && parameters.has(source)) injected.add(target);
|
|
22366
22470
|
}
|
|
22367
22471
|
for (const statement of body2.body) {
|
|
@@ -22372,26 +22476,26 @@ function injectedMembers(owner) {
|
|
|
22372
22476
|
function thisRootMember(node) {
|
|
22373
22477
|
let current = node;
|
|
22374
22478
|
let root = null;
|
|
22375
|
-
while (current.type ===
|
|
22376
|
-
const name =
|
|
22479
|
+
while (current.type === import_utils121.AST_NODE_TYPES.MemberExpression) {
|
|
22480
|
+
const name = import_utils121.ASTUtils.getPropertyName(current);
|
|
22377
22481
|
if (name === null) return null;
|
|
22378
22482
|
root = name;
|
|
22379
22483
|
current = current.object;
|
|
22380
22484
|
}
|
|
22381
|
-
return current.type ===
|
|
22485
|
+
return current.type === import_utils121.AST_NODE_TYPES.ThisExpression ? root : null;
|
|
22382
22486
|
}
|
|
22383
22487
|
function parameterNames(parameter) {
|
|
22384
22488
|
let value = parameter;
|
|
22385
|
-
if (value.type ===
|
|
22386
|
-
if (value.type ===
|
|
22387
|
-
if (value.type ===
|
|
22388
|
-
if (value.type !==
|
|
22489
|
+
if (value.type === import_utils121.AST_NODE_TYPES.TSParameterProperty) value = value.parameter;
|
|
22490
|
+
if (value.type === import_utils121.AST_NODE_TYPES.AssignmentPattern) value = value.left;
|
|
22491
|
+
if (value.type === import_utils121.AST_NODE_TYPES.Identifier) return /* @__PURE__ */ new Set([value.name]);
|
|
22492
|
+
if (value.type !== import_utils121.AST_NODE_TYPES.ObjectPattern) return /* @__PURE__ */ new Set();
|
|
22389
22493
|
return new Set(
|
|
22390
22494
|
value.properties.flatMap((property) => {
|
|
22391
|
-
if (property.type ===
|
|
22392
|
-
return property.argument.type ===
|
|
22393
|
-
const target = property.value.type ===
|
|
22394
|
-
return target.type ===
|
|
22495
|
+
if (property.type === import_utils121.AST_NODE_TYPES.RestElement)
|
|
22496
|
+
return property.argument.type === import_utils121.AST_NODE_TYPES.Identifier ? [property.argument.name] : [];
|
|
22497
|
+
const target = property.value.type === import_utils121.AST_NODE_TYPES.AssignmentPattern ? property.value.left : property.value;
|
|
22498
|
+
return target.type === import_utils121.AST_NODE_TYPES.Identifier ? [target.name] : [];
|
|
22395
22499
|
})
|
|
22396
22500
|
);
|
|
22397
22501
|
}
|
|
@@ -22416,20 +22520,20 @@ var require_sql_access_class_default = createRule({
|
|
|
22416
22520
|
const unwrappedNodeCallee = node.type === "CallExpression" || node.type === "NewExpression" ? unwrapExpression(node.callee) : null;
|
|
22417
22521
|
if (seen.has(node)) return false;
|
|
22418
22522
|
seen.add(node);
|
|
22419
|
-
if (node.type ===
|
|
22420
|
-
const binding =
|
|
22523
|
+
if (node.type === import_utils121.AST_NODE_TYPES.Identifier) {
|
|
22524
|
+
const binding = import_utils121.ASTUtils.findVariable(context.sourceCode.getScope(node), node.name);
|
|
22421
22525
|
if (binding?.defs.length !== 1 || binding.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
22422
22526
|
const definition = binding.defs[0];
|
|
22423
22527
|
return definition?.type === "Variable" && definition.node.init !== null && knownNonDatabase(definition.node.init, seen);
|
|
22424
22528
|
}
|
|
22425
|
-
return node.type ===
|
|
22529
|
+
return node.type === import_utils121.AST_NODE_TYPES.NewExpression && unwrappedNodeCallee?.type === import_utils121.AST_NODE_TYPES.Identifier && ["Map", "WeakMap", "URLSearchParams"].includes(unwrappedNodeCallee.name) && (import_utils121.ASTUtils.findVariable(context.sourceCode.getScope(unwrappedNodeCallee), unwrappedNodeCallee.name)?.defs.length ?? 0) === 0;
|
|
22426
22530
|
}
|
|
22427
22531
|
return {
|
|
22428
22532
|
CallExpression(node) {
|
|
22429
22533
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
22430
|
-
if (unwrappedNodeCallee.type !==
|
|
22534
|
+
if (unwrappedNodeCallee.type !== import_utils121.AST_NODE_TYPES.MemberExpression)
|
|
22431
22535
|
return;
|
|
22432
|
-
const method =
|
|
22536
|
+
const method = import_utils121.ASTUtils.getPropertyName(unwrappedNodeCallee);
|
|
22433
22537
|
if (knownNonDatabase(unwrappedNodeCallee.object)) return;
|
|
22434
22538
|
if (method === null || !isDatabaseOperation(method, unwrappedNodeCallee.object))
|
|
22435
22539
|
return;
|
|
@@ -22445,7 +22549,7 @@ var require_sql_access_class_default = createRule({
|
|
|
22445
22549
|
});
|
|
22446
22550
|
|
|
22447
22551
|
// src/rules/require-static-next-matcher.ts
|
|
22448
|
-
var
|
|
22552
|
+
var import_utils122 = require("@typescript-eslint/utils");
|
|
22449
22553
|
var REQUIRE_STATIC_NEXT_MATCHER_DOCUMENTATION = {
|
|
22450
22554
|
summary: "Require Next.js middleware and proxy matcher configuration to contain only build-time literals.",
|
|
22451
22555
|
rationale: "Next.js must statically analyze matcher values at build time; computed values are ignored.",
|
|
@@ -22461,27 +22565,27 @@ var REQUIRE_STATIC_NEXT_MATCHER_DOCUMENTATION = {
|
|
|
22461
22565
|
var NEXT_ENTRY_FILE = /(?:^|[/\\])(?:middleware|proxy)\.[cm]?[jt]sx?$/u;
|
|
22462
22566
|
function isStaticValue(node) {
|
|
22463
22567
|
const value = unwrapExpression(node);
|
|
22464
|
-
if (value.type ===
|
|
22568
|
+
if (value.type === import_utils122.AST_NODE_TYPES.Literal) {
|
|
22465
22569
|
return true;
|
|
22466
22570
|
}
|
|
22467
|
-
if (value.type ===
|
|
22571
|
+
if (value.type === import_utils122.AST_NODE_TYPES.TemplateLiteral) {
|
|
22468
22572
|
return value.expressions.length === 0;
|
|
22469
22573
|
}
|
|
22470
|
-
if (value.type ===
|
|
22574
|
+
if (value.type === import_utils122.AST_NODE_TYPES.ArrayExpression) {
|
|
22471
22575
|
return value.elements.every(
|
|
22472
|
-
(element) => element !== null && element.type !==
|
|
22576
|
+
(element) => element !== null && element.type !== import_utils122.AST_NODE_TYPES.SpreadElement && isStaticValue(element)
|
|
22473
22577
|
);
|
|
22474
22578
|
}
|
|
22475
|
-
if (value.type ===
|
|
22579
|
+
if (value.type === import_utils122.AST_NODE_TYPES.ObjectExpression) {
|
|
22476
22580
|
return value.properties.every(
|
|
22477
|
-
(property) => property.type ===
|
|
22581
|
+
(property) => property.type === import_utils122.AST_NODE_TYPES.Property && property.kind === "init" && !property.computed && property.value.type !== import_utils122.AST_NODE_TYPES.AssignmentPattern && isStaticValue(property.value)
|
|
22478
22582
|
);
|
|
22479
22583
|
}
|
|
22480
22584
|
return false;
|
|
22481
22585
|
}
|
|
22482
22586
|
function propertyName5(property) {
|
|
22483
|
-
if (!property.computed && property.key.type ===
|
|
22484
|
-
return property.key.type ===
|
|
22587
|
+
if (!property.computed && property.key.type === import_utils122.AST_NODE_TYPES.Identifier) return property.key.name;
|
|
22588
|
+
return property.key.type === import_utils122.AST_NODE_TYPES.Literal && typeof property.key.value === "string" ? property.key.value : null;
|
|
22485
22589
|
}
|
|
22486
22590
|
var require_static_next_matcher_default = createRule({
|
|
22487
22591
|
name: "require-static-next-matcher",
|
|
@@ -22503,19 +22607,19 @@ var require_static_next_matcher_default = createRule({
|
|
|
22503
22607
|
}
|
|
22504
22608
|
return {
|
|
22505
22609
|
ExportNamedDeclaration(node) {
|
|
22506
|
-
if (node.declaration?.type !==
|
|
22610
|
+
if (node.declaration?.type !== import_utils122.AST_NODE_TYPES.VariableDeclaration) {
|
|
22507
22611
|
return;
|
|
22508
22612
|
}
|
|
22509
22613
|
for (const declaration of node.declaration.declarations) {
|
|
22510
|
-
if (declaration.id.type !==
|
|
22614
|
+
if (declaration.id.type !== import_utils122.AST_NODE_TYPES.Identifier || declaration.id.name !== "config" || declaration.init === null) {
|
|
22511
22615
|
continue;
|
|
22512
22616
|
}
|
|
22513
22617
|
const config = unwrapExpression(declaration.init);
|
|
22514
|
-
if (config.type !==
|
|
22618
|
+
if (config.type !== import_utils122.AST_NODE_TYPES.ObjectExpression) {
|
|
22515
22619
|
continue;
|
|
22516
22620
|
}
|
|
22517
22621
|
for (const property of config.properties) {
|
|
22518
|
-
if (property.type !==
|
|
22622
|
+
if (property.type !== import_utils122.AST_NODE_TYPES.Property || propertyName5(property) !== "matcher" || property.value.type === import_utils122.AST_NODE_TYPES.AssignmentPattern) {
|
|
22519
22623
|
continue;
|
|
22520
22624
|
}
|
|
22521
22625
|
if (!isStaticValue(property.value)) {
|
|
@@ -22529,7 +22633,7 @@ var require_static_next_matcher_default = createRule({
|
|
|
22529
22633
|
});
|
|
22530
22634
|
|
|
22531
22635
|
// src/rules/require-use-form-default-values.ts
|
|
22532
|
-
var
|
|
22636
|
+
var import_utils123 = require("@typescript-eslint/utils");
|
|
22533
22637
|
var REQUIRE_USE_FORM_DEFAULT_VALUES_DOCUMENTATION = {
|
|
22534
22638
|
summary: "Require explicit form-level initialization or a field default for directly bound Controller fields.",
|
|
22535
22639
|
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.",
|
|
@@ -22562,8 +22666,8 @@ var REQUIRE_USE_FORM_DEFAULT_VALUES_DOCUMENTATION = {
|
|
|
22562
22666
|
};
|
|
22563
22667
|
function staticPropertyName2(property) {
|
|
22564
22668
|
if (property.computed) return null;
|
|
22565
|
-
if (property.key.type ===
|
|
22566
|
-
if (property.key.type ===
|
|
22669
|
+
if (property.key.type === import_utils123.AST_NODE_TYPES.Identifier) return property.key.name;
|
|
22670
|
+
if (property.key.type === import_utils123.AST_NODE_TYPES.Literal && typeof property.key.value === "string") return property.key.value;
|
|
22567
22671
|
return null;
|
|
22568
22672
|
}
|
|
22569
22673
|
var require_use_form_default_values_default = createRule({
|
|
@@ -22580,7 +22684,7 @@ var require_use_form_default_values_default = createRule({
|
|
|
22580
22684
|
const imported = /* @__PURE__ */ new Map();
|
|
22581
22685
|
const uninitializedForms = /* @__PURE__ */ new Set();
|
|
22582
22686
|
const uninitializedControls = /* @__PURE__ */ new Set();
|
|
22583
|
-
const bindingNamed = (node, name) =>
|
|
22687
|
+
const bindingNamed = (node, name) => import_utils123.ASTUtils.findVariable(context.sourceCode.getScope(node), name);
|
|
22584
22688
|
const bindingOf = (node) => bindingNamed(node, node.name);
|
|
22585
22689
|
const stable = (variable) => !variable.references.some((reference) => reference.isWrite() && reference.init !== true);
|
|
22586
22690
|
const importedKind = (node) => {
|
|
@@ -22593,22 +22697,22 @@ var require_use_form_default_values_default = createRule({
|
|
|
22593
22697
|
};
|
|
22594
22698
|
const isDefinitelyUndefined = (node) => {
|
|
22595
22699
|
const value = unwrapExpression(node);
|
|
22596
|
-
return value.type ===
|
|
22700
|
+
return value.type === import_utils123.AST_NODE_TYPES.UnaryExpression && value.operator === "void" || value.type === import_utils123.AST_NODE_TYPES.Identifier && value.name === "undefined" && (bindingOf(value)?.defs.length ?? 0) === 0;
|
|
22597
22701
|
};
|
|
22598
22702
|
const uninitializedUseFormCall = (node) => {
|
|
22599
22703
|
node = unwrapExpression(node);
|
|
22600
22704
|
const unwrappedNodeCallee = node.type === "CallExpression" || node.type === "NewExpression" ? unwrapExpression(node.callee) : null;
|
|
22601
|
-
if (node.type !==
|
|
22705
|
+
if (node.type !== import_utils123.AST_NODE_TYPES.CallExpression || unwrappedNodeCallee?.type !== import_utils123.AST_NODE_TYPES.Identifier || importedKind(unwrappedNodeCallee) !== "useForm") return false;
|
|
22602
22706
|
const options = node.arguments[0];
|
|
22603
|
-
return options?.type !==
|
|
22707
|
+
return options?.type !== import_utils123.AST_NODE_TYPES.SpreadElement && initializationState(options) === "uninitialized";
|
|
22604
22708
|
};
|
|
22605
22709
|
const initializationState = (node) => {
|
|
22606
22710
|
if (node === void 0) return "uninitialized";
|
|
22607
|
-
if (node.type !==
|
|
22711
|
+
if (node.type !== import_utils123.AST_NODE_TYPES.ObjectExpression) return "unknown";
|
|
22608
22712
|
const initialization = /* @__PURE__ */ new Map();
|
|
22609
22713
|
for (const property of node.properties) {
|
|
22610
|
-
if (property.type ===
|
|
22611
|
-
if (property.type !==
|
|
22714
|
+
if (property.type === import_utils123.AST_NODE_TYPES.SpreadElement || property.computed) return "unknown";
|
|
22715
|
+
if (property.type !== import_utils123.AST_NODE_TYPES.Property) continue;
|
|
22612
22716
|
const name = staticPropertyName2(property);
|
|
22613
22717
|
if (name === "defaultValues" || name === "values") initialization.set(name, !isDefinitelyUndefined(property.value));
|
|
22614
22718
|
}
|
|
@@ -22616,25 +22720,25 @@ var require_use_form_default_values_default = createRule({
|
|
|
22616
22720
|
};
|
|
22617
22721
|
const isUninitializedForm = (node) => {
|
|
22618
22722
|
node = unwrapExpression(node);
|
|
22619
|
-
if (node.type !==
|
|
22723
|
+
if (node.type !== import_utils123.AST_NODE_TYPES.Identifier) return false;
|
|
22620
22724
|
const variable = bindingOf(node);
|
|
22621
22725
|
return variable !== null && stable(variable) && uninitializedForms.has(variable);
|
|
22622
22726
|
};
|
|
22623
22727
|
const isUninitializedControl = (node) => {
|
|
22624
22728
|
node = unwrapExpression(node);
|
|
22625
|
-
if (node.type ===
|
|
22729
|
+
if (node.type === import_utils123.AST_NODE_TYPES.Identifier) {
|
|
22626
22730
|
const variable = bindingOf(node);
|
|
22627
22731
|
return variable !== null && stable(variable) && uninitializedControls.has(variable);
|
|
22628
22732
|
}
|
|
22629
|
-
return node.type ===
|
|
22733
|
+
return node.type === import_utils123.AST_NODE_TYPES.MemberExpression && import_utils123.ASTUtils.getPropertyName(node) !== null && (import_utils123.ASTUtils.getPropertyName(node) ?? "") === "control" && isUninitializedForm(node.object);
|
|
22630
22734
|
};
|
|
22631
22735
|
const fieldOptionsNeedDefault = (node) => {
|
|
22632
|
-
if (node?.type !==
|
|
22736
|
+
if (node?.type !== import_utils123.AST_NODE_TYPES.ObjectExpression) return false;
|
|
22633
22737
|
let control = null;
|
|
22634
22738
|
let hasDefault = false;
|
|
22635
22739
|
for (const property of node.properties) {
|
|
22636
|
-
if (property.type ===
|
|
22637
|
-
if (property.type !==
|
|
22740
|
+
if (property.type === import_utils123.AST_NODE_TYPES.SpreadElement || property.computed) return false;
|
|
22741
|
+
if (property.type !== import_utils123.AST_NODE_TYPES.Property) continue;
|
|
22638
22742
|
const name = staticPropertyName2(property);
|
|
22639
22743
|
if (name === "control") control = property.value;
|
|
22640
22744
|
if (name === "defaultValue") hasDefault = !isDefinitelyUndefined(property.value);
|
|
@@ -22644,14 +22748,14 @@ var require_use_form_default_values_default = createRule({
|
|
|
22644
22748
|
const jsxAttribute = (node, name) => {
|
|
22645
22749
|
let result = null;
|
|
22646
22750
|
for (const attribute of node.attributes) {
|
|
22647
|
-
if (attribute.type ===
|
|
22648
|
-
if (attribute.name.type ===
|
|
22751
|
+
if (attribute.type === import_utils123.AST_NODE_TYPES.JSXSpreadAttribute) return null;
|
|
22752
|
+
if (attribute.name.type === import_utils123.AST_NODE_TYPES.JSXIdentifier && attribute.name.name === name) result = attribute;
|
|
22649
22753
|
}
|
|
22650
22754
|
return result;
|
|
22651
22755
|
};
|
|
22652
22756
|
const trackDestructuredControl = (pattern) => {
|
|
22653
22757
|
for (const property of pattern.properties) {
|
|
22654
|
-
if (property.type !==
|
|
22758
|
+
if (property.type !== import_utils123.AST_NODE_TYPES.Property || staticPropertyName2(property) !== "control" || property.value.type !== import_utils123.AST_NODE_TYPES.Identifier) continue;
|
|
22655
22759
|
const variable = bindingOf(property.value);
|
|
22656
22760
|
if (variable !== null) uninitializedControls.add(variable);
|
|
22657
22761
|
}
|
|
@@ -22660,8 +22764,8 @@ var require_use_form_default_values_default = createRule({
|
|
|
22660
22764
|
ImportDeclaration(node) {
|
|
22661
22765
|
if (node.source.value !== "react-hook-form") return;
|
|
22662
22766
|
for (const specifier of node.specifiers) {
|
|
22663
|
-
if (specifier.type !==
|
|
22664
|
-
const name = specifier.imported.type ===
|
|
22767
|
+
if (specifier.type !== import_utils123.AST_NODE_TYPES.ImportSpecifier) continue;
|
|
22768
|
+
const name = specifier.imported.type === import_utils123.AST_NODE_TYPES.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
22665
22769
|
if (name !== "Controller" && name !== "useController" && name !== "useForm") continue;
|
|
22666
22770
|
const variable = bindingOf(specifier.local);
|
|
22667
22771
|
if (variable !== null) imported.set(variable, name);
|
|
@@ -22670,35 +22774,35 @@ var require_use_form_default_values_default = createRule({
|
|
|
22670
22774
|
VariableDeclarator(node) {
|
|
22671
22775
|
if (node.init === null) return;
|
|
22672
22776
|
if (uninitializedUseFormCall(node.init)) {
|
|
22673
|
-
if (node.id.type ===
|
|
22777
|
+
if (node.id.type === import_utils123.AST_NODE_TYPES.Identifier) {
|
|
22674
22778
|
const variable = bindingOf(node.id);
|
|
22675
22779
|
if (variable !== null) uninitializedForms.add(variable);
|
|
22676
|
-
} else if (node.id.type ===
|
|
22780
|
+
} else if (node.id.type === import_utils123.AST_NODE_TYPES.ObjectPattern) {
|
|
22677
22781
|
trackDestructuredControl(node.id);
|
|
22678
22782
|
}
|
|
22679
22783
|
return;
|
|
22680
22784
|
}
|
|
22681
|
-
if (node.id.type ===
|
|
22785
|
+
if (node.id.type === import_utils123.AST_NODE_TYPES.ObjectPattern && isUninitializedForm(node.init)) {
|
|
22682
22786
|
trackDestructuredControl(node.id);
|
|
22683
22787
|
return;
|
|
22684
22788
|
}
|
|
22685
|
-
if (node.id.type ===
|
|
22789
|
+
if (node.id.type === import_utils123.AST_NODE_TYPES.Identifier && node.init.type === import_utils123.AST_NODE_TYPES.MemberExpression && import_utils123.ASTUtils.getPropertyName(node.init) !== null && (import_utils123.ASTUtils.getPropertyName(node.init) ?? "") === "control" && isUninitializedForm(node.init.object)) {
|
|
22686
22790
|
const variable = bindingOf(node.id);
|
|
22687
22791
|
if (variable !== null) uninitializedControls.add(variable);
|
|
22688
22792
|
}
|
|
22689
22793
|
},
|
|
22690
22794
|
CallExpression(node) {
|
|
22691
22795
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
22692
|
-
if (unwrappedNodeCallee.type !==
|
|
22796
|
+
if (unwrappedNodeCallee.type !== import_utils123.AST_NODE_TYPES.Identifier || importedKind(unwrappedNodeCallee) !== "useController" || !fieldOptionsNeedDefault(node.arguments[0]?.type === import_utils123.AST_NODE_TYPES.SpreadElement ? void 0 : node.arguments[0])) return;
|
|
22693
22797
|
context.report({ node, messageId: "requireUseFormDefaultValues" });
|
|
22694
22798
|
},
|
|
22695
22799
|
JSXOpeningElement(node) {
|
|
22696
|
-
if (node.name.type !==
|
|
22697
|
-
if (node.attributes.some((attribute) => attribute.type ===
|
|
22800
|
+
if (node.name.type !== import_utils123.AST_NODE_TYPES.JSXIdentifier || importedJsxKind(node.name) !== "Controller") return;
|
|
22801
|
+
if (node.attributes.some((attribute) => attribute.type === import_utils123.AST_NODE_TYPES.JSXSpreadAttribute)) return;
|
|
22698
22802
|
const control = jsxAttribute(node, "control");
|
|
22699
|
-
if (control?.value?.type !==
|
|
22803
|
+
if (control?.value?.type !== import_utils123.AST_NODE_TYPES.JSXExpressionContainer || control.value.expression.type === import_utils123.AST_NODE_TYPES.JSXEmptyExpression || !isUninitializedControl(control.value.expression)) return;
|
|
22700
22804
|
const defaultValue = jsxAttribute(node, "defaultValue");
|
|
22701
|
-
if (defaultValue !== null && (defaultValue.value === null || defaultValue.value.type !==
|
|
22805
|
+
if (defaultValue !== null && (defaultValue.value === null || defaultValue.value.type !== import_utils123.AST_NODE_TYPES.JSXExpressionContainer || defaultValue.value.expression.type !== import_utils123.AST_NODE_TYPES.JSXEmptyExpression && !isDefinitelyUndefined(defaultValue.value.expression))) return;
|
|
22702
22806
|
context.report({ node, messageId: "requireUseFormDefaultValues" });
|
|
22703
22807
|
}
|
|
22704
22808
|
};
|
|
@@ -22706,7 +22810,7 @@ var require_use_form_default_values_default = createRule({
|
|
|
22706
22810
|
});
|
|
22707
22811
|
|
|
22708
22812
|
// src/rules/require-use-server-in-actions-file.ts
|
|
22709
|
-
var
|
|
22813
|
+
var import_utils124 = require("@typescript-eslint/utils");
|
|
22710
22814
|
var ACTION_MODULE_RE = /(?:^|\/)app\/.*\/(?:actions|[^/]+-actions)\.[cm]?[jt]s$/u;
|
|
22711
22815
|
var REQUIRE_USE_SERVER_IN_ACTIONS_FILE_DOCUMENTATION = {
|
|
22712
22816
|
summary: "route action module missing the use server directive",
|
|
@@ -22773,7 +22877,7 @@ var require_use_server_in_actions_file_default = createRule({
|
|
|
22773
22877
|
});
|
|
22774
22878
|
|
|
22775
22879
|
// src/rules/require-zod-form-validation.ts
|
|
22776
|
-
var
|
|
22880
|
+
var import_utils125 = require("@typescript-eslint/utils");
|
|
22777
22881
|
var REQUIRE_ZOD_FORM_VALIDATION_DOCUMENTATION = {
|
|
22778
22882
|
summary: "Require Zod validation (`Schema.parse(...)` / `Schema.safeParse(...)`) when reading values out of a `FormData` object.",
|
|
22779
22883
|
rationale: "FormData values are untrusted strings or files and need runtime validation before use.",
|
|
@@ -22799,14 +22903,14 @@ var FORM_VALUE_METHODS = /* @__PURE__ */ new Set(["get", "getAll"]);
|
|
|
22799
22903
|
var zodReceiverRoot = (node) => {
|
|
22800
22904
|
let current = node;
|
|
22801
22905
|
while (true) {
|
|
22802
|
-
if (current.type ===
|
|
22906
|
+
if (current.type === import_utils125.AST_NODE_TYPES.Identifier) {
|
|
22803
22907
|
return current;
|
|
22804
22908
|
}
|
|
22805
|
-
if (current.type ===
|
|
22909
|
+
if (current.type === import_utils125.AST_NODE_TYPES.CallExpression) {
|
|
22806
22910
|
current = current.callee;
|
|
22807
22911
|
continue;
|
|
22808
22912
|
}
|
|
22809
|
-
if (current.type ===
|
|
22913
|
+
if (current.type === import_utils125.AST_NODE_TYPES.MemberExpression) {
|
|
22810
22914
|
current = current.object;
|
|
22811
22915
|
continue;
|
|
22812
22916
|
}
|
|
@@ -22815,12 +22919,12 @@ var zodReceiverRoot = (node) => {
|
|
|
22815
22919
|
};
|
|
22816
22920
|
var isFormDataMethodCall = (node) => {
|
|
22817
22921
|
let current = node;
|
|
22818
|
-
if (current.type ===
|
|
22922
|
+
if (current.type === import_utils125.AST_NODE_TYPES.AwaitExpression) {
|
|
22819
22923
|
current = current.argument;
|
|
22820
22924
|
}
|
|
22821
|
-
if (current.type !==
|
|
22925
|
+
if (current.type !== import_utils125.AST_NODE_TYPES.CallExpression) return false;
|
|
22822
22926
|
const callee = unwrapExpression(current.callee);
|
|
22823
|
-
return callee.type ===
|
|
22927
|
+
return callee.type === import_utils125.AST_NODE_TYPES.MemberExpression && import_utils125.ASTUtils.getPropertyName(callee) === "formData";
|
|
22824
22928
|
};
|
|
22825
22929
|
var require_zod_form_validation_default = createRule({
|
|
22826
22930
|
name: "require-zod-form-validation",
|
|
@@ -22841,29 +22945,29 @@ var require_zod_form_validation_default = createRule({
|
|
|
22841
22945
|
return {};
|
|
22842
22946
|
}
|
|
22843
22947
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
22844
|
-
const resolvedBinding = (identifier) =>
|
|
22948
|
+
const resolvedBinding = (identifier) => import_utils125.ASTUtils.findVariable(
|
|
22845
22949
|
context.sourceCode.getScope(identifier),
|
|
22846
22950
|
identifier.name
|
|
22847
22951
|
);
|
|
22848
22952
|
const isFormDataGetCall = (node) => {
|
|
22849
22953
|
const callee = unwrapExpression(node.callee);
|
|
22850
|
-
const calleeReceiver = callee.type ===
|
|
22851
|
-
if (callee.type !==
|
|
22852
|
-
if (
|
|
22954
|
+
const calleeReceiver = callee.type === import_utils125.AST_NODE_TYPES.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
22955
|
+
if (callee.type !== import_utils125.AST_NODE_TYPES.MemberExpression) return false;
|
|
22956
|
+
if (import_utils125.ASTUtils.getPropertyName(callee) === null || !FORM_VALUE_METHODS.has(import_utils125.ASTUtils.getPropertyName(callee) ?? "")) {
|
|
22853
22957
|
return false;
|
|
22854
22958
|
}
|
|
22855
22959
|
return isFormSourceIdentifier(calleeReceiver);
|
|
22856
22960
|
};
|
|
22857
22961
|
const isFormSourceIdentifier = (node) => {
|
|
22858
22962
|
node = unwrapExpression(node);
|
|
22859
|
-
if (node.type !==
|
|
22963
|
+
if (node.type !== import_utils125.AST_NODE_TYPES.Identifier) return false;
|
|
22860
22964
|
const conventionalName = /formdata/i.test(node.name);
|
|
22861
22965
|
let scope = context.sourceCode.getScope(node);
|
|
22862
22966
|
while (scope !== null) {
|
|
22863
22967
|
const variable = scope.set.get(node.name);
|
|
22864
22968
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
22865
22969
|
const def = variable.defs[0];
|
|
22866
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
22970
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === import_utils125.AST_NODE_TYPES.VariableDeclarator && def.node.init !== null) {
|
|
22867
22971
|
return isFormDataMethodCall(def.node.init);
|
|
22868
22972
|
}
|
|
22869
22973
|
return def?.type === "Parameter" && conventionalName;
|
|
@@ -22876,24 +22980,24 @@ var require_zod_form_validation_default = createRule({
|
|
|
22876
22980
|
let parent = node.parent;
|
|
22877
22981
|
while (parent !== null && parent !== void 0) {
|
|
22878
22982
|
if (isZodParseCall(parent)) return parent;
|
|
22879
|
-
if (parent.type ===
|
|
22983
|
+
if (parent.type === import_utils125.AST_NODE_TYPES.CallExpression && parent.callee.type === import_utils125.AST_NODE_TYPES.Identifier && ["Number", "String", "Boolean"].includes(parent.callee.name) && parent.arguments.length === 1 && (resolvedBinding(parent.callee)?.defs.length ?? 0) === 0) {
|
|
22880
22984
|
parent = parent.parent;
|
|
22881
22985
|
continue;
|
|
22882
22986
|
}
|
|
22883
|
-
if (parent.type ===
|
|
22987
|
+
if (parent.type === import_utils125.AST_NODE_TYPES.CallExpression && parent.callee.type === import_utils125.AST_NODE_TYPES.MemberExpression && parent.callee.object.type === import_utils125.AST_NODE_TYPES.Identifier && parent.callee.object.name === "Object" && import_utils125.ASTUtils.getPropertyName(parent.callee) === "fromEntries" && (resolvedBinding(parent.callee.object)?.defs.length ?? 0) === 0) {
|
|
22884
22988
|
parent = parent.parent;
|
|
22885
22989
|
continue;
|
|
22886
22990
|
}
|
|
22887
|
-
if (parent.type ===
|
|
22991
|
+
if (parent.type === import_utils125.AST_NODE_TYPES.CallExpression || parent.type === import_utils125.AST_NODE_TYPES.NewExpression || parent.type === import_utils125.AST_NODE_TYPES.TaggedTemplateExpression || parent.type === import_utils125.AST_NODE_TYPES.ArrowFunctionExpression || parent.type === import_utils125.AST_NODE_TYPES.FunctionExpression || parent.type === import_utils125.AST_NODE_TYPES.FunctionDeclaration) return null;
|
|
22888
22992
|
parent = parent.parent;
|
|
22889
22993
|
}
|
|
22890
22994
|
return null;
|
|
22891
22995
|
};
|
|
22892
22996
|
const isZodParseCall = (node) => {
|
|
22893
|
-
if (node.type !==
|
|
22997
|
+
if (node.type !== import_utils125.AST_NODE_TYPES.CallExpression) return false;
|
|
22894
22998
|
const callee = unwrapExpression(node.callee);
|
|
22895
|
-
const calleeReceiver = callee.type ===
|
|
22896
|
-
if (callee.type !==
|
|
22999
|
+
const calleeReceiver = callee.type === import_utils125.AST_NODE_TYPES.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
23000
|
+
if (callee.type !== import_utils125.AST_NODE_TYPES.MemberExpression || import_utils125.ASTUtils.getPropertyName(callee) === null || !ZOD_PARSE_METHODS.has(import_utils125.ASTUtils.getPropertyName(callee) ?? "")) {
|
|
22897
23001
|
return false;
|
|
22898
23002
|
}
|
|
22899
23003
|
const root = zodReceiverRoot(calleeReceiver);
|
|
@@ -22907,25 +23011,25 @@ var require_zod_form_validation_default = createRule({
|
|
|
22907
23011
|
return false;
|
|
22908
23012
|
}
|
|
22909
23013
|
const definition = binding.defs[0];
|
|
22910
|
-
if (definition?.type !== "Variable" || definition.node.type !==
|
|
23014
|
+
if (definition?.type !== "Variable" || definition.node.type !== import_utils125.AST_NODE_TYPES.VariableDeclarator) {
|
|
22911
23015
|
return false;
|
|
22912
23016
|
}
|
|
22913
23017
|
const init = definition.node.init;
|
|
22914
|
-
return init?.type ===
|
|
23018
|
+
return init?.type === import_utils125.AST_NODE_TYPES.ObjectExpression || init?.type === import_utils125.AST_NODE_TYPES.ArrayExpression || init?.type === import_utils125.AST_NODE_TYPES.Literal || init?.type === import_utils125.AST_NODE_TYPES.ArrowFunctionExpression || init?.type === import_utils125.AST_NODE_TYPES.FunctionExpression;
|
|
22915
23019
|
};
|
|
22916
23020
|
const hasZodParseAncestor = (node) => zodParseAncestor(node) !== null;
|
|
22917
23021
|
const isInstanceofNarrowing = (node) => {
|
|
22918
23022
|
const parent = node.parent;
|
|
22919
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
23023
|
+
return parent !== null && parent !== void 0 && parent.type === import_utils125.AST_NODE_TYPES.BinaryExpression && parent.operator === "instanceof" && parent.left === node && parent.right.type === import_utils125.AST_NODE_TYPES.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
22920
23024
|
};
|
|
22921
23025
|
const boundDeclarator = (node) => {
|
|
22922
23026
|
let current = node;
|
|
22923
23027
|
let parent = current.parent;
|
|
22924
|
-
while ((parent.type ===
|
|
23028
|
+
while ((parent.type === import_utils125.AST_NODE_TYPES.TSAsExpression || parent.type === import_utils125.AST_NODE_TYPES.TSSatisfiesExpression || parent.type === import_utils125.AST_NODE_TYPES.TSNonNullExpression || parent.type === import_utils125.AST_NODE_TYPES.ChainExpression) && parent.expression === current) {
|
|
22925
23029
|
current = parent;
|
|
22926
23030
|
parent = current.parent;
|
|
22927
23031
|
}
|
|
22928
|
-
if (parent.type ===
|
|
23032
|
+
if (parent.type === import_utils125.AST_NODE_TYPES.VariableDeclarator && parent.init === current && parent.id.type === import_utils125.AST_NODE_TYPES.Identifier) {
|
|
22929
23033
|
return parent;
|
|
22930
23034
|
}
|
|
22931
23035
|
return null;
|
|
@@ -22934,7 +23038,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
22934
23038
|
let current = node;
|
|
22935
23039
|
while (current.parent !== void 0) {
|
|
22936
23040
|
const parent = current.parent;
|
|
22937
|
-
if (parent.type ===
|
|
23041
|
+
if (parent.type === import_utils125.AST_NODE_TYPES.BlockStatement || parent.type === import_utils125.AST_NODE_TYPES.Program) {
|
|
22938
23042
|
return current;
|
|
22939
23043
|
}
|
|
22940
23044
|
current = parent;
|
|
@@ -22949,7 +23053,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
22949
23053
|
if (declarationStatement === null || validationStatement === null || declarationStatement.parent !== validationStatement.parent || validationStatement.range[0] <= declarationStatement.range[1] || hasConditionalAncestorBeforeStatement(parse2, validationStatement)) {
|
|
22950
23054
|
return null;
|
|
22951
23055
|
}
|
|
22952
|
-
if (validationStatement.type !==
|
|
23056
|
+
if (validationStatement.type !== import_utils125.AST_NODE_TYPES.VariableDeclaration && validationStatement.type !== import_utils125.AST_NODE_TYPES.ExpressionStatement) {
|
|
22953
23057
|
return null;
|
|
22954
23058
|
}
|
|
22955
23059
|
const method = zodParseMethod(parse2);
|
|
@@ -22962,7 +23066,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
22962
23066
|
const isAwaitedBeforeStatement = (node, statement) => {
|
|
22963
23067
|
let current = node.parent;
|
|
22964
23068
|
while (current !== void 0 && current !== statement) {
|
|
22965
|
-
if (current.type ===
|
|
23069
|
+
if (current.type === import_utils125.AST_NODE_TYPES.AwaitExpression) return true;
|
|
22966
23070
|
current = current.parent;
|
|
22967
23071
|
}
|
|
22968
23072
|
return false;
|
|
@@ -22970,7 +23074,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
22970
23074
|
const hasConditionalAncestorBeforeStatement = (node, statement) => {
|
|
22971
23075
|
let current = node.parent;
|
|
22972
23076
|
while (current !== void 0 && current !== statement) {
|
|
22973
|
-
if (current.type ===
|
|
23077
|
+
if (current.type === import_utils125.AST_NODE_TYPES.LogicalExpression || current.type === import_utils125.AST_NODE_TYPES.ConditionalExpression) {
|
|
22974
23078
|
return true;
|
|
22975
23079
|
}
|
|
22976
23080
|
current = current.parent;
|
|
@@ -22979,20 +23083,20 @@ var require_zod_form_validation_default = createRule({
|
|
|
22979
23083
|
};
|
|
22980
23084
|
const zodParseMethod = (call) => {
|
|
22981
23085
|
const callee = unwrapExpression(call.callee);
|
|
22982
|
-
return callee.type ===
|
|
23086
|
+
return callee.type === import_utils125.AST_NODE_TYPES.MemberExpression && import_utils125.ASTUtils.getPropertyName(callee) !== null ? import_utils125.ASTUtils.getPropertyName(callee) ?? "" : null;
|
|
22983
23087
|
};
|
|
22984
23088
|
const isSafePrevalidationInspection = (identifier) => {
|
|
22985
23089
|
const parent = identifier.parent;
|
|
22986
|
-
if (parent.type ===
|
|
23090
|
+
if (parent.type === import_utils125.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof") {
|
|
22987
23091
|
return true;
|
|
22988
23092
|
}
|
|
22989
|
-
if (parent.type !==
|
|
23093
|
+
if (parent.type !== import_utils125.AST_NODE_TYPES.BinaryExpression || parent.left !== identifier) {
|
|
22990
23094
|
return false;
|
|
22991
23095
|
}
|
|
22992
23096
|
if (parent.operator === "instanceof") {
|
|
22993
|
-
return parent.right.type ===
|
|
23097
|
+
return parent.right.type === import_utils125.AST_NODE_TYPES.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
22994
23098
|
}
|
|
22995
|
-
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type ===
|
|
23099
|
+
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type === import_utils125.AST_NODE_TYPES.Literal && parent.right.value === null || parent.right.type === import_utils125.AST_NODE_TYPES.Identifier && parent.right.name === "undefined");
|
|
22996
23100
|
};
|
|
22997
23101
|
const isDescendantOf = (node, ancestor) => {
|
|
22998
23102
|
let current = node;
|
|
@@ -23003,23 +23107,23 @@ var require_zod_form_validation_default = createRule({
|
|
|
23003
23107
|
return false;
|
|
23004
23108
|
};
|
|
23005
23109
|
const blockTerminates = (node) => {
|
|
23006
|
-
if (node.type ===
|
|
23110
|
+
if (node.type === import_utils125.AST_NODE_TYPES.ReturnStatement || node.type === import_utils125.AST_NODE_TYPES.ThrowStatement) {
|
|
23007
23111
|
return true;
|
|
23008
23112
|
}
|
|
23009
|
-
if (node.type !==
|
|
23113
|
+
if (node.type !== import_utils125.AST_NODE_TYPES.BlockStatement || node.body.length === 0) return false;
|
|
23010
23114
|
const last = node.body.at(-1);
|
|
23011
23115
|
return last !== void 0 && blockTerminates(last);
|
|
23012
23116
|
};
|
|
23013
23117
|
const narrowingIf = (identifier) => {
|
|
23014
23118
|
const comparison = identifier.parent;
|
|
23015
|
-
if (comparison?.type !==
|
|
23119
|
+
if (comparison?.type !== import_utils125.AST_NODE_TYPES.BinaryExpression || comparison.operator !== "instanceof" || comparison.left !== identifier || comparison.right.type !== import_utils125.AST_NODE_TYPES.Identifier || comparison.right.name !== "File" && comparison.right.name !== "Blob") {
|
|
23016
23120
|
return null;
|
|
23017
23121
|
}
|
|
23018
23122
|
const maybeNegation = comparison.parent;
|
|
23019
|
-
const negated = maybeNegation?.type ===
|
|
23123
|
+
const negated = maybeNegation?.type === import_utils125.AST_NODE_TYPES.UnaryExpression && maybeNegation.operator === "!";
|
|
23020
23124
|
const test = negated ? maybeNegation : comparison;
|
|
23021
23125
|
const branch = test.parent;
|
|
23022
|
-
return branch?.type ===
|
|
23126
|
+
return branch?.type === import_utils125.AST_NODE_TYPES.IfStatement && branch.test === test ? { branch, positive: !negated } : null;
|
|
23023
23127
|
};
|
|
23024
23128
|
const useDominatedByNarrowing = (use, narrowings) => narrowings.some(({ branch, positive }) => {
|
|
23025
23129
|
if (positive) return isDescendantOf(use, branch.consequent);
|
|
@@ -23039,7 +23143,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
23039
23143
|
const variable = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
23040
23144
|
if (variable === void 0) return false;
|
|
23041
23145
|
const references = variable.references.filter((reference) => !reference.isWriteOnly()).map((reference) => reference.identifier).filter(
|
|
23042
|
-
(identifier) => identifier.type ===
|
|
23146
|
+
(identifier) => identifier.type === import_utils125.AST_NODE_TYPES.Identifier
|
|
23043
23147
|
);
|
|
23044
23148
|
if (references.length === 0) return false;
|
|
23045
23149
|
const narrowings = references.map(narrowingIf).filter(
|
|
@@ -23065,7 +23169,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
23065
23169
|
ImportDeclaration(node) {
|
|
23066
23170
|
if (!isZodModule(node.source.value)) return;
|
|
23067
23171
|
for (const specifier of node.specifiers) {
|
|
23068
|
-
if (specifier.type ===
|
|
23172
|
+
if (specifier.type === import_utils125.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils125.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils125.AST_NODE_TYPES.ImportSpecifier && (specifier.imported.type === import_utils125.AST_NODE_TYPES.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
23069
23173
|
const binding = resolvedBinding(specifier.local);
|
|
23070
23174
|
if (binding !== null) zodBindings.add(binding);
|
|
23071
23175
|
}
|
|
@@ -23086,7 +23190,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
23086
23190
|
});
|
|
23087
23191
|
|
|
23088
23192
|
// src/rules/store-insert-requires-on-conflict.ts
|
|
23089
|
-
var
|
|
23193
|
+
var import_utils126 = require("@typescript-eslint/utils");
|
|
23090
23194
|
var STORE_INSERT_REQUIRES_ON_CONFLICT_DOCUMENTATION = {
|
|
23091
23195
|
summary: "Review conflict handling for embedded inserts in replay-named callables.",
|
|
23092
23196
|
rationale: "Names such as seed, enqueue, or upsert suggest that repeated execution deserves a conflict-policy review, but do not prove a replay contract.",
|
|
@@ -23155,7 +23259,7 @@ function expressionCallableName(current) {
|
|
|
23155
23259
|
}
|
|
23156
23260
|
|
|
23157
23261
|
// src/rules/stepdown.ts
|
|
23158
|
-
var
|
|
23262
|
+
var import_utils127 = require("@typescript-eslint/utils");
|
|
23159
23263
|
var STEPDOWN_DOCUMENTATION = {
|
|
23160
23264
|
summary: "Place a private helper below its sole direct same-scope caller.",
|
|
23161
23265
|
rationale: "Caller-first ordering lets a reader follow the main flow before descending into implementation details.",
|
|
@@ -23173,7 +23277,7 @@ var STEPDOWN_DOCUMENTATION = {
|
|
|
23173
23277
|
]
|
|
23174
23278
|
};
|
|
23175
23279
|
function isFunction(node) {
|
|
23176
|
-
return node.type ===
|
|
23280
|
+
return node.type === import_utils127.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils127.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils127.AST_NODE_TYPES.FunctionExpression;
|
|
23177
23281
|
}
|
|
23178
23282
|
function reportMisordered(context, candidates, scopeDefinitions, calls, pinned, canMove = () => true) {
|
|
23179
23283
|
const byName = new Map(scopeDefinitions.map((definition) => [definition.key, definition]));
|
|
@@ -23269,7 +23373,7 @@ function cycleComponents(graph) {
|
|
|
23269
23373
|
return components;
|
|
23270
23374
|
}
|
|
23271
23375
|
function isErasedExpression2(node) {
|
|
23272
|
-
return node.type ===
|
|
23376
|
+
return node.type === import_utils127.AST_NODE_TYPES.TSAsExpression || node.type === import_utils127.AST_NODE_TYPES.TSTypeAssertion || node.type === import_utils127.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils127.AST_NODE_TYPES.TSNonNullExpression || node.type === import_utils127.AST_NODE_TYPES.TSInstantiationExpression;
|
|
23273
23377
|
}
|
|
23274
23378
|
function unwrapExpression4(node) {
|
|
23275
23379
|
let current = node;
|
|
@@ -23293,11 +23397,11 @@ function localCallCount(context, node, owner) {
|
|
|
23293
23397
|
if (current === void 0 || enclosingFunction5(context, current) !== owner) return null;
|
|
23294
23398
|
const expression = wrappedExpression(current);
|
|
23295
23399
|
const parent = expression.parent;
|
|
23296
|
-
if (parent?.type ===
|
|
23400
|
+
if (parent?.type === import_utils127.AST_NODE_TYPES.CallExpression && parent.callee === expression) {
|
|
23297
23401
|
count += 1;
|
|
23298
23402
|
continue;
|
|
23299
23403
|
}
|
|
23300
|
-
if (parent?.type !==
|
|
23404
|
+
if (parent?.type !== import_utils127.AST_NODE_TYPES.VariableDeclarator || parent.init !== expression || parent.id.type !== import_utils127.AST_NODE_TYPES.Identifier || parent.parent.type !== import_utils127.AST_NODE_TYPES.VariableDeclaration || parent.parent.kind !== "const") return null;
|
|
23301
23405
|
const variable = context.sourceCode.getDeclaredVariables(parent)[0];
|
|
23302
23406
|
if (variable === void 0 || seen.has(variable) || !stableVariable(variable)) return null;
|
|
23303
23407
|
seen.add(variable);
|
|
@@ -23312,11 +23416,11 @@ function declarationScope(context, program) {
|
|
|
23312
23416
|
for (const node of declarations) counts.set(node.name, (counts.get(node.name) ?? 0) + 1);
|
|
23313
23417
|
const overloadNames = new Set(
|
|
23314
23418
|
program.body.flatMap((statement) => {
|
|
23315
|
-
const node = statement.type ===
|
|
23316
|
-
return node?.type ===
|
|
23419
|
+
const node = statement.type === import_utils127.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
23420
|
+
return node?.type === import_utils127.AST_NODE_TYPES.TSDeclareFunction && node.id !== null ? [node.id.name] : [];
|
|
23317
23421
|
})
|
|
23318
23422
|
);
|
|
23319
|
-
const exported = program.type ===
|
|
23423
|
+
const exported = program.type === import_utils127.AST_NODE_TYPES.Program ? exportedNames(program) : /* @__PURE__ */ new Set();
|
|
23320
23424
|
const scopeDefinitions = declarations.filter((node) => counts.get(node.name) === 1);
|
|
23321
23425
|
const definitions = scopeDefinitions.filter(
|
|
23322
23426
|
(definition) => !exported.has(definition.name) && !overloadNames.has(definition.name)
|
|
@@ -23328,7 +23432,7 @@ function declarationScope(context, program) {
|
|
|
23328
23432
|
runtimeBarrierPrefix.push((runtimeBarrierPrefix.at(-1) ?? 0) + (isDeferredModuleStatement(statement) ? 0 : 1));
|
|
23329
23433
|
}
|
|
23330
23434
|
const canMove = (helper, caller) => {
|
|
23331
|
-
if (helper.node.type ===
|
|
23435
|
+
if (helper.node.type === import_utils127.AST_NODE_TYPES.FunctionDeclaration) return true;
|
|
23332
23436
|
const helperIndex = statementIndex(helper);
|
|
23333
23437
|
const callerIndex = statementIndex(caller);
|
|
23334
23438
|
return helperIndex !== void 0 && callerIndex !== void 0 && runtimeBarrierPrefix[callerIndex + 1] === runtimeBarrierPrefix[helperIndex + 1];
|
|
@@ -23370,26 +23474,26 @@ function moduleCallGraph(context, scopeDefinitions) {
|
|
|
23370
23474
|
return { calls, pinned };
|
|
23371
23475
|
}
|
|
23372
23476
|
function isDeferredModuleStatement(statement) {
|
|
23373
|
-
const node = statement.type ===
|
|
23374
|
-
if (node === null || node.type ===
|
|
23375
|
-
return node.type ===
|
|
23376
|
-
(declaration) => declaration.id.type ===
|
|
23477
|
+
const node = statement.type === import_utils127.AST_NODE_TYPES.ExportNamedDeclaration || statement.type === import_utils127.AST_NODE_TYPES.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
23478
|
+
if (node === null || node.type === import_utils127.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils127.AST_NODE_TYPES.TSDeclareFunction || node.type === import_utils127.AST_NODE_TYPES.TSInterfaceDeclaration || node.type === import_utils127.AST_NODE_TYPES.TSTypeAliasDeclaration || node.type === import_utils127.AST_NODE_TYPES.ImportDeclaration || node.type === import_utils127.AST_NODE_TYPES.ExportAllDeclaration || node.type === import_utils127.AST_NODE_TYPES.EmptyStatement) return true;
|
|
23479
|
+
return node.type === import_utils127.AST_NODE_TYPES.VariableDeclaration && node.declarations.every(
|
|
23480
|
+
(declaration) => declaration.id.type === import_utils127.AST_NODE_TYPES.Identifier && declaration.init !== null && isFunction(unwrapExpression4(declaration.init))
|
|
23377
23481
|
);
|
|
23378
23482
|
}
|
|
23379
23483
|
function exportedNames(program) {
|
|
23380
23484
|
const names = /* @__PURE__ */ new Set();
|
|
23381
23485
|
function collectNamedExports(statement) {
|
|
23382
|
-
if (statement.type !==
|
|
23383
|
-
if (statement.declaration?.type ===
|
|
23486
|
+
if (statement.type !== import_utils127.AST_NODE_TYPES.ExportNamedDeclaration || statement.exportKind === "type" || statement.source !== null) return;
|
|
23487
|
+
if (statement.declaration?.type === import_utils127.AST_NODE_TYPES.FunctionDeclaration && statement.declaration.id !== null) {
|
|
23384
23488
|
names.add(statement.declaration.id.name);
|
|
23385
23489
|
}
|
|
23386
|
-
if (statement.declaration?.type ===
|
|
23490
|
+
if (statement.declaration?.type === import_utils127.AST_NODE_TYPES.VariableDeclaration) {
|
|
23387
23491
|
for (const declarator of statement.declaration.declarations) {
|
|
23388
|
-
if (declarator.id.type ===
|
|
23492
|
+
if (declarator.id.type === import_utils127.AST_NODE_TYPES.Identifier) names.add(declarator.id.name);
|
|
23389
23493
|
}
|
|
23390
23494
|
}
|
|
23391
23495
|
for (const specifier of statement.specifiers) {
|
|
23392
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
23496
|
+
if (specifier.exportKind !== "type" && specifier.local.type === import_utils127.AST_NODE_TYPES.Identifier) {
|
|
23393
23497
|
names.add(specifier.local.name);
|
|
23394
23498
|
}
|
|
23395
23499
|
}
|
|
@@ -23398,23 +23502,23 @@ function exportedNames(program) {
|
|
|
23398
23502
|
collectNamedExports(statement);
|
|
23399
23503
|
}
|
|
23400
23504
|
for (const statement of program.body) {
|
|
23401
|
-
if (statement.type ===
|
|
23402
|
-
if (statement.type ===
|
|
23505
|
+
if (statement.type === import_utils127.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils127.AST_NODE_TYPES.Identifier) names.add(statement.declaration.name);
|
|
23506
|
+
if (statement.type === import_utils127.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils127.AST_NODE_TYPES.FunctionDeclaration && statement.declaration.id !== null) names.add(statement.declaration.id.name);
|
|
23403
23507
|
}
|
|
23404
23508
|
return names;
|
|
23405
23509
|
}
|
|
23406
23510
|
function moduleDefinitions(program) {
|
|
23407
23511
|
const definitions = [];
|
|
23408
23512
|
for (const statement of program.body) {
|
|
23409
|
-
const node = statement.type ===
|
|
23410
|
-
if (node?.type ===
|
|
23513
|
+
const node = statement.type === import_utils127.AST_NODE_TYPES.ExportNamedDeclaration || statement.type === import_utils127.AST_NODE_TYPES.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
23514
|
+
if (node?.type === import_utils127.AST_NODE_TYPES.FunctionDeclaration && node.id !== null && node.body !== null) {
|
|
23411
23515
|
definitions.push({ key: node.id.name, name: node.id.name, node, functionNode: node, bindingNode: node });
|
|
23412
23516
|
continue;
|
|
23413
23517
|
}
|
|
23414
|
-
if (node?.type !==
|
|
23518
|
+
if (node?.type !== import_utils127.AST_NODE_TYPES.VariableDeclaration || node.kind !== "const" || node.declarations.length !== 1) continue;
|
|
23415
23519
|
for (const declarator of node.declarations) {
|
|
23416
23520
|
const initializer = declarator.init === null ? null : unwrapExpression4(declarator.init);
|
|
23417
|
-
if (declarator.id.type ===
|
|
23521
|
+
if (declarator.id.type === import_utils127.AST_NODE_TYPES.Identifier && initializer !== null && isFunction(initializer)) {
|
|
23418
23522
|
definitions.push({
|
|
23419
23523
|
key: declarator.id.name,
|
|
23420
23524
|
name: declarator.id.name,
|
|
@@ -23428,25 +23532,25 @@ function moduleDefinitions(program) {
|
|
|
23428
23532
|
return definitions;
|
|
23429
23533
|
}
|
|
23430
23534
|
function methodName(node) {
|
|
23431
|
-
if (node.key.type ===
|
|
23432
|
-
if (!node.computed && node.key.type ===
|
|
23433
|
-
return node.key.type ===
|
|
23535
|
+
if (node.key.type === import_utils127.AST_NODE_TYPES.PrivateIdentifier) return `#${node.key.name}`;
|
|
23536
|
+
if (!node.computed && node.key.type === import_utils127.AST_NODE_TYPES.Identifier) return node.key.name;
|
|
23537
|
+
return node.key.type === import_utils127.AST_NODE_TYPES.Literal && typeof node.key.value === "string" ? node.key.value : null;
|
|
23434
23538
|
}
|
|
23435
23539
|
function methodKey(name, isStatic2) {
|
|
23436
23540
|
return `${isStatic2 ? "static" : "instance"}:${name}`;
|
|
23437
23541
|
}
|
|
23438
23542
|
function receiverDomain(context, object, receivers, thisIsStatic) {
|
|
23439
23543
|
const unwrapped = unwrapExpression4(object);
|
|
23440
|
-
if (unwrapped.type ===
|
|
23544
|
+
if (unwrapped.type === import_utils127.AST_NODE_TYPES.ThisExpression) return thisIsStatic;
|
|
23441
23545
|
return externalReceiverDomain(context, unwrapped, receivers);
|
|
23442
23546
|
}
|
|
23443
23547
|
function externalReceiverDomain(context, object, receivers) {
|
|
23444
23548
|
const origin = receiverOrigin(context, object, receivers);
|
|
23445
23549
|
if (origin === null || typeof origin === "boolean") return origin;
|
|
23446
|
-
if (origin.type ===
|
|
23550
|
+
if (origin.type === import_utils127.AST_NODE_TYPES.NewExpression) {
|
|
23447
23551
|
return receiverOrigin(context, origin.callee, receivers) === true ? false : null;
|
|
23448
23552
|
}
|
|
23449
|
-
if (origin.type ===
|
|
23553
|
+
if (origin.type === import_utils127.AST_NODE_TYPES.ObjectExpression || origin.type === import_utils127.AST_NODE_TYPES.ArrayExpression || origin.type === import_utils127.AST_NODE_TYPES.Literal || origin.type === import_utils127.AST_NODE_TYPES.ArrowFunctionExpression || origin.type === import_utils127.AST_NODE_TYPES.FunctionExpression) return "unrelated";
|
|
23450
23554
|
return null;
|
|
23451
23555
|
}
|
|
23452
23556
|
function receiverOrigin(context, object, receivers) {
|
|
@@ -23454,8 +23558,8 @@ function receiverOrigin(context, object, receivers) {
|
|
|
23454
23558
|
const seen = /* @__PURE__ */ new Set();
|
|
23455
23559
|
while (true) {
|
|
23456
23560
|
const unwrapped = unwrapExpression4(current);
|
|
23457
|
-
if (unwrapped.type !==
|
|
23458
|
-
const variable =
|
|
23561
|
+
if (unwrapped.type !== import_utils127.AST_NODE_TYPES.Identifier) return unwrapped;
|
|
23562
|
+
const variable = import_utils127.ASTUtils.findVariable(context.sourceCode.getScope(unwrapped), unwrapped.name);
|
|
23459
23563
|
if (variable === null) return null;
|
|
23460
23564
|
const known = receivers.get(variable);
|
|
23461
23565
|
if (known !== void 0) return known;
|
|
@@ -23468,25 +23572,25 @@ function immutableInitializer(variable, seen) {
|
|
|
23468
23572
|
if (seen.has(variable) || !stableVariable(variable) || variable.defs.length !== 1) return null;
|
|
23469
23573
|
seen.add(variable);
|
|
23470
23574
|
const definition = variable.defs[0];
|
|
23471
|
-
if (definition?.node.type !==
|
|
23575
|
+
if (definition?.node.type !== import_utils127.AST_NODE_TYPES.VariableDeclarator || definition.node.parent.type !== import_utils127.AST_NODE_TYPES.VariableDeclaration || definition.node.parent.kind !== "const") return null;
|
|
23472
23576
|
return definition.node.init;
|
|
23473
23577
|
}
|
|
23474
23578
|
function stableVariable(variable) {
|
|
23475
23579
|
return !variable.references.some((reference) => reference.isWrite() && reference.init !== true);
|
|
23476
23580
|
}
|
|
23477
23581
|
function referencedPropertyName(node) {
|
|
23478
|
-
if (node.property.type ===
|
|
23479
|
-
if (!node.computed && node.property.type ===
|
|
23480
|
-
return node.computed && node.property.type ===
|
|
23582
|
+
if (node.property.type === import_utils127.AST_NODE_TYPES.PrivateIdentifier) return `#${node.property.name}`;
|
|
23583
|
+
if (!node.computed && node.property.type === import_utils127.AST_NODE_TYPES.Identifier) return node.property.name;
|
|
23584
|
+
return node.computed && node.property.type === import_utils127.AST_NODE_TYPES.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
23481
23585
|
}
|
|
23482
23586
|
function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
23483
23587
|
visit(node, nestedFunction);
|
|
23484
|
-
const nested = nestedFunction || isFunction(node) || node.type ===
|
|
23588
|
+
const nested = nestedFunction || isFunction(node) || node.type === import_utils127.AST_NODE_TYPES.ClassDeclaration || node.type === import_utils127.AST_NODE_TYPES.ClassExpression;
|
|
23485
23589
|
forEachAstChild(node, visitorKeys, (child) => walk(child, visitorKeys, visit, nested));
|
|
23486
23590
|
}
|
|
23487
23591
|
function classScope(context, node, computedReferences) {
|
|
23488
23592
|
const methods = node.body.body.filter(
|
|
23489
|
-
(member) => member.type ===
|
|
23593
|
+
(member) => member.type === import_utils127.AST_NODE_TYPES.MethodDefinition
|
|
23490
23594
|
);
|
|
23491
23595
|
const counts = classMethodCounts(node.body, methods);
|
|
23492
23596
|
const implementations = methods.filter((method) => isFunction(method.value));
|
|
@@ -23497,7 +23601,7 @@ function classScope(context, node, computedReferences) {
|
|
|
23497
23601
|
return name !== null && key !== null && implementationCounts.get(key) === 1 ? [{ key, name, node: method }] : [];
|
|
23498
23602
|
});
|
|
23499
23603
|
const definitions = scopeDefinitions.filter(
|
|
23500
|
-
({ key, node: method }) => (method.accessibility === "private" || method.key.type ===
|
|
23604
|
+
({ key, node: method }) => (method.accessibility === "private" || method.key.type === import_utils127.AST_NODE_TYPES.PrivateIdentifier) && counts.get(key) === 1 && method.decorators.length === 0 && !method.computed && method.kind === "method"
|
|
23501
23605
|
);
|
|
23502
23606
|
if (definitions.length === 0) return;
|
|
23503
23607
|
const methodKeys = new Set(scopeDefinitions.map((definition) => definition.key));
|
|
@@ -23513,11 +23617,11 @@ function classScope(context, node, computedReferences) {
|
|
|
23513
23617
|
};
|
|
23514
23618
|
function pinDestructuredMembers(binding, domain) {
|
|
23515
23619
|
for (const property of binding.properties) {
|
|
23516
|
-
if (property.type ===
|
|
23620
|
+
if (property.type === import_utils127.AST_NODE_TYPES.RestElement || property.computed) {
|
|
23517
23621
|
pinNames(null, domain);
|
|
23518
|
-
} else if (property.key.type ===
|
|
23622
|
+
} else if (property.key.type === import_utils127.AST_NODE_TYPES.Identifier) {
|
|
23519
23623
|
pinNames(property.key.name, domain);
|
|
23520
|
-
} else if (property.key.type ===
|
|
23624
|
+
} else if (property.key.type === import_utils127.AST_NODE_TYPES.Literal && typeof property.key.value === "string") {
|
|
23521
23625
|
pinNames(property.key.value, domain);
|
|
23522
23626
|
}
|
|
23523
23627
|
}
|
|
@@ -23539,15 +23643,15 @@ function classScope(context, node, computedReferences) {
|
|
|
23539
23643
|
}
|
|
23540
23644
|
}
|
|
23541
23645
|
const collectAlias = (current, nestedFunction) => {
|
|
23542
|
-
if (nestedFunction || current.type !==
|
|
23646
|
+
if (nestedFunction || current.type !== import_utils127.AST_NODE_TYPES.VariableDeclarator || current.init === null) return;
|
|
23543
23647
|
const domain = receiverDomain(context, current.init, receivers, method.static);
|
|
23544
23648
|
if (domain === null || domain === "unrelated") return;
|
|
23545
|
-
if (current.id.type ===
|
|
23649
|
+
if (current.id.type === import_utils127.AST_NODE_TYPES.ObjectPattern) {
|
|
23546
23650
|
pinDestructuredMembers(current.id, domain);
|
|
23547
23651
|
return;
|
|
23548
23652
|
}
|
|
23549
|
-
if (current.id.type !==
|
|
23550
|
-
if (current.parent.type !==
|
|
23653
|
+
if (current.id.type !== import_utils127.AST_NODE_TYPES.Identifier) return;
|
|
23654
|
+
if (current.parent.type !== import_utils127.AST_NODE_TYPES.VariableDeclaration || current.parent.kind !== "const") {
|
|
23551
23655
|
pinNames(null, domain);
|
|
23552
23656
|
return;
|
|
23553
23657
|
}
|
|
@@ -23556,7 +23660,7 @@ function classScope(context, node, computedReferences) {
|
|
|
23556
23660
|
const local = variable.references.every((reference) => {
|
|
23557
23661
|
if (!reference.isRead()) return true;
|
|
23558
23662
|
const expression = wrappedExpression(reference.identifier);
|
|
23559
|
-
return enclosingFunction5(context, reference.identifier) === methodFunction && expression.parent?.type ===
|
|
23663
|
+
return enclosingFunction5(context, reference.identifier) === methodFunction && expression.parent?.type === import_utils127.AST_NODE_TYPES.MemberExpression && expression.parent.object === expression;
|
|
23560
23664
|
});
|
|
23561
23665
|
if (local) receivers.set(variable, domain);
|
|
23562
23666
|
else pinNames(null, domain);
|
|
@@ -23568,7 +23672,7 @@ function classScope(context, node, computedReferences) {
|
|
|
23568
23672
|
const domain2 = receiverDomain(context, destructuring.value, receivers, method.static);
|
|
23569
23673
|
if (domain2 !== "unrelated") pinDestructuredMembers(destructuring.binding, domain2);
|
|
23570
23674
|
}
|
|
23571
|
-
if (current.type !==
|
|
23675
|
+
if (current.type !== import_utils127.AST_NODE_TYPES.MemberExpression) return;
|
|
23572
23676
|
const domain = receiverDomain(context, current.object, receivers, method.static);
|
|
23573
23677
|
const targetName = referencedPropertyName(current);
|
|
23574
23678
|
if (domain === "unrelated") return;
|
|
@@ -23602,9 +23706,9 @@ function classScope(context, node, computedReferences) {
|
|
|
23602
23706
|
}
|
|
23603
23707
|
for (const method of methods) collectMethodCalls(method);
|
|
23604
23708
|
for (const member of node.body.body) {
|
|
23605
|
-
if (member.type ===
|
|
23709
|
+
if (member.type === import_utils127.AST_NODE_TYPES.MethodDefinition || member.type === import_utils127.AST_NODE_TYPES.TSAbstractMethodDefinition) continue;
|
|
23606
23710
|
walk(member, context.sourceCode.visitorKeys, (current) => {
|
|
23607
|
-
if (current.type !==
|
|
23711
|
+
if (current.type !== import_utils127.AST_NODE_TYPES.MemberExpression) return;
|
|
23608
23712
|
if (externalReceiverDomain(context, current.object, classReceivers) === "unrelated") return;
|
|
23609
23713
|
pinNames(referencedPropertyName(current));
|
|
23610
23714
|
});
|
|
@@ -23636,32 +23740,32 @@ function classScope(context, node, computedReferences) {
|
|
|
23636
23740
|
function classReceiverBindings(context, node) {
|
|
23637
23741
|
const classReceivers = /* @__PURE__ */ new Map();
|
|
23638
23742
|
if (node.id !== null) {
|
|
23639
|
-
const internal =
|
|
23743
|
+
const internal = import_utils127.ASTUtils.findVariable(context.sourceCode.getScope(node), node.id.name);
|
|
23640
23744
|
if (internal !== null && stableVariable(internal)) classReceivers.set(internal, true);
|
|
23641
23745
|
}
|
|
23642
|
-
if (node.type ===
|
|
23643
|
-
const outer =
|
|
23746
|
+
if (node.type === import_utils127.AST_NODE_TYPES.ClassExpression && node.parent.type === import_utils127.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === import_utils127.AST_NODE_TYPES.Identifier && node.parent.parent.type === import_utils127.AST_NODE_TYPES.VariableDeclaration && node.parent.parent.kind === "const") {
|
|
23747
|
+
const outer = import_utils127.ASTUtils.findVariable(context.sourceCode.getScope(node.parent), node.parent.id.name);
|
|
23644
23748
|
if (outer !== null && stableVariable(outer)) classReceivers.set(outer, true);
|
|
23645
23749
|
}
|
|
23646
23750
|
return classReceivers;
|
|
23647
23751
|
}
|
|
23648
23752
|
function receiverDestructuring(node) {
|
|
23649
|
-
if (node.type ===
|
|
23753
|
+
if (node.type === import_utils127.AST_NODE_TYPES.VariableDeclarator && node.id.type === import_utils127.AST_NODE_TYPES.ObjectPattern && node.init !== null) {
|
|
23650
23754
|
return { binding: node.id, value: node.init };
|
|
23651
23755
|
}
|
|
23652
|
-
if ((node.type ===
|
|
23756
|
+
if ((node.type === import_utils127.AST_NODE_TYPES.AssignmentPattern || node.type === import_utils127.AST_NODE_TYPES.AssignmentExpression) && node.left.type === import_utils127.AST_NODE_TYPES.ObjectPattern) {
|
|
23653
23757
|
return { binding: node.left, value: node.right };
|
|
23654
23758
|
}
|
|
23655
23759
|
return null;
|
|
23656
23760
|
}
|
|
23657
23761
|
function isClassRuntimeBarrier(member) {
|
|
23658
23762
|
switch (member.type) {
|
|
23659
|
-
case
|
|
23763
|
+
case import_utils127.AST_NODE_TYPES.StaticBlock:
|
|
23660
23764
|
return true;
|
|
23661
|
-
case
|
|
23662
|
-
case
|
|
23765
|
+
case import_utils127.AST_NODE_TYPES.PropertyDefinition:
|
|
23766
|
+
case import_utils127.AST_NODE_TYPES.AccessorProperty:
|
|
23663
23767
|
return member.static || member.computed || member.decorators.length > 0 || member.value !== null;
|
|
23664
|
-
case
|
|
23768
|
+
case import_utils127.AST_NODE_TYPES.MethodDefinition:
|
|
23665
23769
|
return member.computed || member.decorators.length > 0;
|
|
23666
23770
|
default:
|
|
23667
23771
|
return false;
|
|
@@ -23691,14 +23795,14 @@ var stepdown_default = createRule({
|
|
|
23691
23795
|
classes.push(node);
|
|
23692
23796
|
},
|
|
23693
23797
|
"FunctionDeclaration, FunctionExpression, ArrowFunctionExpression": (node) => {
|
|
23694
|
-
if (isFunction(node) && node.body?.type ===
|
|
23798
|
+
if (isFunction(node) && node.body?.type === import_utils127.AST_NODE_TYPES.BlockStatement) functionBodies.push(node.body);
|
|
23695
23799
|
},
|
|
23696
23800
|
"Program:exit": (program) => {
|
|
23697
23801
|
declarationScope(context, program);
|
|
23698
23802
|
for (const body2 of functionBodies) declarationScope(context, body2);
|
|
23699
23803
|
const computedReferences = [];
|
|
23700
23804
|
walk(program, context.sourceCode.visitorKeys, (node) => {
|
|
23701
|
-
if (node.type ===
|
|
23805
|
+
if (node.type === import_utils127.AST_NODE_TYPES.MemberExpression && node.computed) computedReferences.push(node);
|
|
23702
23806
|
});
|
|
23703
23807
|
for (const node of classes) classScope(context, node, computedReferences);
|
|
23704
23808
|
}
|
|
@@ -23715,8 +23819,8 @@ function classMethodCounts(body2, methods) {
|
|
|
23715
23819
|
}
|
|
23716
23820
|
}
|
|
23717
23821
|
for (const member of body2.body) {
|
|
23718
|
-
if (member.type !==
|
|
23719
|
-
const name = !member.computed && member.key.type ===
|
|
23822
|
+
if (member.type !== import_utils127.AST_NODE_TYPES.TSAbstractMethodDefinition) continue;
|
|
23823
|
+
const name = !member.computed && member.key.type === import_utils127.AST_NODE_TYPES.Identifier ? member.key.name : null;
|
|
23720
23824
|
if (name !== null) {
|
|
23721
23825
|
const key = methodKey(name, member.static);
|
|
23722
23826
|
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
@@ -23726,7 +23830,7 @@ function classMethodCounts(body2, methods) {
|
|
|
23726
23830
|
}
|
|
23727
23831
|
|
|
23728
23832
|
// src/rules/source-coupled-test.ts
|
|
23729
|
-
var
|
|
23833
|
+
var import_utils128 = require("@typescript-eslint/utils");
|
|
23730
23834
|
var GENERAL_SOURCE_SUFFIX_RE = /\.(?:bash|sh|ya?ml|jsonc?|toml|py|[cm]?[jt]s)$/iu;
|
|
23731
23835
|
var FS_MODULES = /* @__PURE__ */ new Set(["fs", "node:fs", "fs/promises", "node:fs/promises"]);
|
|
23732
23836
|
var FS_READERS = /* @__PURE__ */ new Set(["readFile", "readFileSync"]);
|
|
@@ -23800,16 +23904,16 @@ var SOURCE_COUPLED_TEST_DOCUMENTATION = {
|
|
|
23800
23904
|
function unwrap6(node) {
|
|
23801
23905
|
for (; ; ) {
|
|
23802
23906
|
node = unwrapExpression(node);
|
|
23803
|
-
if (node.type ===
|
|
23804
|
-
else if (node.type ===
|
|
23907
|
+
if (node.type === import_utils128.AST_NODE_TYPES.AwaitExpression) node = node.argument;
|
|
23908
|
+
else if (node.type === import_utils128.AST_NODE_TYPES.ChainExpression) node = node.expression;
|
|
23805
23909
|
else return node;
|
|
23806
23910
|
}
|
|
23807
23911
|
}
|
|
23808
23912
|
function stringValue(node) {
|
|
23809
23913
|
const current = unwrap6(node);
|
|
23810
|
-
if (current.type ===
|
|
23811
|
-
if (current.type ===
|
|
23812
|
-
if (current.type ===
|
|
23914
|
+
if (current.type === import_utils128.AST_NODE_TYPES.Literal && typeof current.value === "string") return current.value;
|
|
23915
|
+
if (current.type === import_utils128.AST_NODE_TYPES.TemplateLiteral && current.expressions.length === 0) return current.quasis[0]?.value.cooked ?? null;
|
|
23916
|
+
if (current.type === import_utils128.AST_NODE_TYPES.BinaryExpression && current.operator === "+") {
|
|
23813
23917
|
const left = stringValue(current.left);
|
|
23814
23918
|
const right = stringValue(current.right);
|
|
23815
23919
|
return left === null || right === null ? null : left + right;
|
|
@@ -23821,7 +23925,7 @@ function importSource(node) {
|
|
|
23821
23925
|
}
|
|
23822
23926
|
function requireSource(node) {
|
|
23823
23927
|
const current = unwrap6(node);
|
|
23824
|
-
if (current.type !==
|
|
23928
|
+
if (current.type !== import_utils128.AST_NODE_TYPES.CallExpression || current.callee.type !== import_utils128.AST_NODE_TYPES.Identifier || current.callee.name !== "require" || current.arguments.length !== 1 || current.arguments[0]?.type === import_utils128.AST_NODE_TYPES.SpreadElement) return null;
|
|
23825
23929
|
return stringValue(current.arguments[0]);
|
|
23826
23930
|
}
|
|
23827
23931
|
function newScope() {
|
|
@@ -23843,7 +23947,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
23843
23947
|
const scopes = [newScope()];
|
|
23844
23948
|
const reportedOrigins = /* @__PURE__ */ new Set();
|
|
23845
23949
|
const currentScope = () => scopes.at(-1) ?? scopes[0];
|
|
23846
|
-
const bindingOf = (node) =>
|
|
23950
|
+
const bindingOf = (node) => import_utils128.ASTUtils.findVariable(context.sourceCode.getScope(node), node.name);
|
|
23847
23951
|
const assertionKind = (node) => {
|
|
23848
23952
|
const binding = bindingOf(node);
|
|
23849
23953
|
if (binding === null || binding.defs.length === 0) {
|
|
@@ -23877,75 +23981,75 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
23877
23981
|
const current = unwrap6(node);
|
|
23878
23982
|
const value = stringValue(current);
|
|
23879
23983
|
if (value !== null) return sourceSuffixRe.test(value);
|
|
23880
|
-
if (current.type ===
|
|
23881
|
-
if (current.type ===
|
|
23984
|
+
if (current.type === import_utils128.AST_NODE_TYPES.Identifier) return visible("paths", current);
|
|
23985
|
+
if (current.type === import_utils128.AST_NODE_TYPES.CallExpression || current.type === import_utils128.AST_NODE_TYPES.NewExpression) {
|
|
23882
23986
|
const callee = unwrapExpression(current.callee);
|
|
23883
23987
|
const first = current.arguments[0];
|
|
23884
|
-
if (first === void 0 || first.type ===
|
|
23885
|
-
if (current.type ===
|
|
23886
|
-
if (callee.type ===
|
|
23988
|
+
if (first === void 0 || first.type === import_utils128.AST_NODE_TYPES.SpreadElement) return false;
|
|
23989
|
+
if (current.type === import_utils128.AST_NODE_TYPES.NewExpression && callee.type === import_utils128.AST_NODE_TYPES.Identifier && callee.name === "URL" && (bindingOf(callee)?.defs.length ?? 0) === 0) return sourcePath(first);
|
|
23990
|
+
if (callee.type === import_utils128.AST_NODE_TYPES.Identifier && bindingOf(callee)?.defs.some((definition) => definition.node.type === import_utils128.AST_NODE_TYPES.ImportSpecifier && definition.node.imported.type === import_utils128.AST_NODE_TYPES.Identifier && definition.node.imported.name === "fileURLToPath" && definition.node.parent.type === import_utils128.AST_NODE_TYPES.ImportDeclaration && ["node:url", "url"].includes(String(definition.node.parent.source.value)))) return sourcePath(first);
|
|
23887
23991
|
}
|
|
23888
23992
|
return false;
|
|
23889
23993
|
};
|
|
23890
23994
|
const rawRead = (node) => {
|
|
23891
23995
|
const current = unwrap6(node);
|
|
23892
|
-
if (current.type !==
|
|
23996
|
+
if (current.type !== import_utils128.AST_NODE_TYPES.CallExpression || current.arguments.length === 0) return false;
|
|
23893
23997
|
const callee = unwrap6(current.callee);
|
|
23894
|
-
const calleeReceiver = callee.type ===
|
|
23895
|
-
if (callee.type ===
|
|
23998
|
+
const calleeReceiver = callee.type === import_utils128.AST_NODE_TYPES.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
23999
|
+
if (callee.type === import_utils128.AST_NODE_TYPES.Identifier) {
|
|
23896
24000
|
return visible("fsReaders", callee) && sourcePath(current.arguments[0]);
|
|
23897
24001
|
}
|
|
23898
|
-
if (callee.type !==
|
|
23899
|
-
const name2 =
|
|
24002
|
+
if (callee.type !== import_utils128.AST_NODE_TYPES.MemberExpression) return false;
|
|
24003
|
+
const name2 = import_utils128.ASTUtils.getPropertyName(callee);
|
|
23900
24004
|
const object = unwrap6(calleeReceiver);
|
|
23901
|
-
return name2 !== null && FS_READERS.has(name2) && object.type ===
|
|
24005
|
+
return name2 !== null && FS_READERS.has(name2) && object.type === import_utils128.AST_NODE_TYPES.Identifier && visible("fsObjects", object) && sourcePath(current.arguments[0]);
|
|
23902
24006
|
};
|
|
23903
24007
|
const rawOrigins = (node) => {
|
|
23904
24008
|
const current = unwrap6(node);
|
|
23905
|
-
if (current.type ===
|
|
24009
|
+
if (current.type === import_utils128.AST_NODE_TYPES.Identifier) return visibleRawOrigins(current);
|
|
23906
24010
|
if (rawRead(current)) return /* @__PURE__ */ new Set([`${current.range[0]}:${current.range[1]}`]);
|
|
23907
|
-
if (current.type ===
|
|
23908
|
-
if (current.type ===
|
|
23909
|
-
if (current.type !==
|
|
24011
|
+
if (current.type === import_utils128.AST_NODE_TYPES.BinaryExpression && current.operator === "+") return /* @__PURE__ */ new Set([...rawOrigins(current.left), ...rawOrigins(current.right)]);
|
|
24012
|
+
if (current.type === import_utils128.AST_NODE_TYPES.MemberExpression && import_utils128.ASTUtils.getPropertyName(current) === "length") return rawOrigins(current.object);
|
|
24013
|
+
if (current.type !== import_utils128.AST_NODE_TYPES.CallExpression) return /* @__PURE__ */ new Set();
|
|
23910
24014
|
const callee = unwrap6(current.callee);
|
|
23911
|
-
const calleeReceiver = callee.type ===
|
|
23912
|
-
if (callee.type !==
|
|
23913
|
-
const name2 =
|
|
24015
|
+
const calleeReceiver = callee.type === import_utils128.AST_NODE_TYPES.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
24016
|
+
if (callee.type !== import_utils128.AST_NODE_TYPES.MemberExpression) return /* @__PURE__ */ new Set();
|
|
24017
|
+
const name2 = import_utils128.ASTUtils.getPropertyName(callee);
|
|
23914
24018
|
return name2 !== null && TEXT_TRANSFORMS.has(name2) ? rawOrigins(calleeReceiver) : /* @__PURE__ */ new Set();
|
|
23915
24019
|
};
|
|
23916
24020
|
const evidenceOrigins = (node) => {
|
|
23917
24021
|
const current = unwrap6(node);
|
|
23918
24022
|
const direct = rawOrigins(current);
|
|
23919
24023
|
if (direct.size > 0) return direct;
|
|
23920
|
-
if (current.type ===
|
|
23921
|
-
if (current.type ===
|
|
23922
|
-
if (current.type !==
|
|
24024
|
+
if (current.type === import_utils128.AST_NODE_TYPES.BinaryExpression || current.type === import_utils128.AST_NODE_TYPES.LogicalExpression) return /* @__PURE__ */ new Set([...evidenceOrigins(current.left), ...evidenceOrigins(current.right)]);
|
|
24025
|
+
if (current.type === import_utils128.AST_NODE_TYPES.UnaryExpression) return evidenceOrigins(current.argument);
|
|
24026
|
+
if (current.type !== import_utils128.AST_NODE_TYPES.CallExpression) return /* @__PURE__ */ new Set();
|
|
23923
24027
|
const callee = unwrap6(current.callee);
|
|
23924
|
-
const calleeReceiver = callee.type ===
|
|
23925
|
-
if (callee.type !==
|
|
23926
|
-
const name2 =
|
|
24028
|
+
const calleeReceiver = callee.type === import_utils128.AST_NODE_TYPES.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
24029
|
+
if (callee.type !== import_utils128.AST_NODE_TYPES.MemberExpression) return /* @__PURE__ */ new Set();
|
|
24030
|
+
const name2 = import_utils128.ASTUtils.getPropertyName(callee);
|
|
23927
24031
|
if (name2 !== null && TEXT_PREDICATES.has(name2)) return rawOrigins(calleeReceiver);
|
|
23928
|
-
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type ===
|
|
24032
|
+
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type === import_utils128.AST_NODE_TYPES.SpreadElement ? [] : [...rawOrigins(argument)]));
|
|
23929
24033
|
return /* @__PURE__ */ new Set();
|
|
23930
24034
|
};
|
|
23931
24035
|
const rawAssertionOrigins = (node) => {
|
|
23932
24036
|
const callee = unwrap6(node.callee);
|
|
23933
|
-
const calleeReceiver = callee.type ===
|
|
23934
|
-
if (callee.type ===
|
|
23935
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
24037
|
+
const calleeReceiver = callee.type === import_utils128.AST_NODE_TYPES.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
24038
|
+
if (callee.type === import_utils128.AST_NODE_TYPES.Identifier && assertionKind(callee) === "assert") {
|
|
24039
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === import_utils128.AST_NODE_TYPES.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
23936
24040
|
}
|
|
23937
|
-
if (callee.type !==
|
|
23938
|
-
const matcher =
|
|
24041
|
+
if (callee.type !== import_utils128.AST_NODE_TYPES.MemberExpression) return /* @__PURE__ */ new Set();
|
|
24042
|
+
const matcher = import_utils128.ASTUtils.getPropertyName(callee);
|
|
23939
24043
|
if (matcher === null) return /* @__PURE__ */ new Set();
|
|
23940
24044
|
let receiver = unwrap6(calleeReceiver);
|
|
23941
|
-
while (receiver.type ===
|
|
23942
|
-
const expectCallee = receiver.type ===
|
|
23943
|
-
if (receiver.type ===
|
|
24045
|
+
while (receiver.type === import_utils128.AST_NODE_TYPES.MemberExpression && EXPECT_MODIFIERS2.has(import_utils128.ASTUtils.getPropertyName(receiver) ?? "")) receiver = unwrap6(receiver.object);
|
|
24046
|
+
const expectCallee = receiver.type === import_utils128.AST_NODE_TYPES.CallExpression ? unwrapExpression(receiver.callee) : null;
|
|
24047
|
+
if (receiver.type === import_utils128.AST_NODE_TYPES.CallExpression && expectCallee?.type === import_utils128.AST_NODE_TYPES.Identifier && assertionKind(expectCallee) === "expect") {
|
|
23944
24048
|
if (!EXPECT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
23945
|
-
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type ===
|
|
24049
|
+
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type === import_utils128.AST_NODE_TYPES.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
23946
24050
|
}
|
|
23947
|
-
if (receiver.type !==
|
|
23948
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
24051
|
+
if (receiver.type !== import_utils128.AST_NODE_TYPES.Identifier || assertionKind(receiver) !== "assert" || !ASSERT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
24052
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === import_utils128.AST_NODE_TYPES.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
23949
24053
|
};
|
|
23950
24054
|
const declare = (node, state) => {
|
|
23951
24055
|
const name2 = bindingOf(node);
|
|
@@ -23967,7 +24071,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
23967
24071
|
};
|
|
23968
24072
|
const sourceCollection = (node) => {
|
|
23969
24073
|
const current = unwrap6(node);
|
|
23970
|
-
return current.type ===
|
|
24074
|
+
return current.type === import_utils128.AST_NODE_TYPES.ArrayExpression && current.elements.length > 0 && current.elements.every((element) => element !== null && element.type !== import_utils128.AST_NODE_TYPES.SpreadElement && sourcePath(element));
|
|
23971
24075
|
};
|
|
23972
24076
|
const enterFunction = () => {
|
|
23973
24077
|
scopes.push(newScope());
|
|
@@ -23977,8 +24081,8 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
23977
24081
|
};
|
|
23978
24082
|
function declareFsReaders(pattern) {
|
|
23979
24083
|
for (const property of pattern.properties) {
|
|
23980
|
-
if (property.type !==
|
|
23981
|
-
const key = property.key.type ===
|
|
24084
|
+
if (property.type !== import_utils128.AST_NODE_TYPES.Property || property.value.type !== import_utils128.AST_NODE_TYPES.Identifier) continue;
|
|
24085
|
+
const key = property.key.type === import_utils128.AST_NODE_TYPES.Identifier ? property.key.name : property.key.type === import_utils128.AST_NODE_TYPES.Literal ? String(property.key.value) : "";
|
|
23982
24086
|
if (FS_READERS.has(key)) declare(property.value, { fsReader: true });
|
|
23983
24087
|
}
|
|
23984
24088
|
}
|
|
@@ -23987,8 +24091,8 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
23987
24091
|
const source = importSource(node);
|
|
23988
24092
|
if (source === null || !FS_MODULES.has(source)) return;
|
|
23989
24093
|
for (const specifier of node.specifiers) {
|
|
23990
|
-
if (specifier.type ===
|
|
23991
|
-
const imported = specifier.imported.type ===
|
|
24094
|
+
if (specifier.type === import_utils128.AST_NODE_TYPES.ImportSpecifier) {
|
|
24095
|
+
const imported = specifier.imported.type === import_utils128.AST_NODE_TYPES.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
23992
24096
|
if (FS_READERS.has(imported)) declare(specifier.local, { fsReader: true });
|
|
23993
24097
|
} else {
|
|
23994
24098
|
declare(specifier.local, { fsObject: true });
|
|
@@ -24001,26 +24105,26 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
24001
24105
|
if (node.init === null) return;
|
|
24002
24106
|
const required = requireSource(node.init);
|
|
24003
24107
|
const initializer = unwrap6(node.init);
|
|
24004
|
-
if (required !== null && initializer.type ===
|
|
24005
|
-
if (required !== null && FS_MODULES.has(required) && node.id.type ===
|
|
24108
|
+
if (required !== null && initializer.type === import_utils128.AST_NODE_TYPES.CallExpression && initializer.callee.type === import_utils128.AST_NODE_TYPES.Identifier && (bindingOf(initializer.callee)?.defs.length ?? 0) > 0) return;
|
|
24109
|
+
if (required !== null && FS_MODULES.has(required) && node.id.type === import_utils128.AST_NODE_TYPES.Identifier) {
|
|
24006
24110
|
declare(node.id, { fsObject: true });
|
|
24007
24111
|
return;
|
|
24008
24112
|
}
|
|
24009
|
-
if (node.id.type ===
|
|
24113
|
+
if (node.id.type === import_utils128.AST_NODE_TYPES.ObjectPattern && required !== null && FS_MODULES.has(required)) {
|
|
24010
24114
|
declareFsReaders(node.id);
|
|
24011
24115
|
return;
|
|
24012
24116
|
}
|
|
24013
|
-
if (node.id.type !==
|
|
24117
|
+
if (node.id.type !== import_utils128.AST_NODE_TYPES.Identifier) return;
|
|
24014
24118
|
declare(node.id, { collection: sourceCollection(node.init), path: sourcePath(node.init), rawOrigins: rawOrigins(node.init) });
|
|
24015
24119
|
},
|
|
24016
24120
|
AssignmentExpression(node) {
|
|
24017
|
-
if (node.left.type ===
|
|
24121
|
+
if (node.left.type === import_utils128.AST_NODE_TYPES.Identifier) declare(node.left, {});
|
|
24018
24122
|
},
|
|
24019
24123
|
ForOfStatement(node) {
|
|
24020
24124
|
const right = unwrap6(node.right);
|
|
24021
|
-
const collection = right.type ===
|
|
24022
|
-
const left = node.left.type ===
|
|
24023
|
-
if (collection && left?.type ===
|
|
24125
|
+
const collection = right.type === import_utils128.AST_NODE_TYPES.Identifier && visible("collections", right);
|
|
24126
|
+
const left = node.left.type === import_utils128.AST_NODE_TYPES.VariableDeclaration ? node.left.declarations[0]?.id : node.left;
|
|
24127
|
+
if (collection && left?.type === import_utils128.AST_NODE_TYPES.Identifier) declare(left, { path: true });
|
|
24024
24128
|
},
|
|
24025
24129
|
CallExpression(node) {
|
|
24026
24130
|
const origins = rawAssertionOrigins(node);
|
|
@@ -24038,22 +24142,22 @@ var source_coupled_test_default = createSourceCoupledRule(
|
|
|
24038
24142
|
GENERAL_SOURCE_SUFFIX_RE
|
|
24039
24143
|
);
|
|
24040
24144
|
function importedAssertionKind(specifier) {
|
|
24041
|
-
if (specifier.type !==
|
|
24145
|
+
if (specifier.type !== import_utils128.AST_NODE_TYPES.ImportSpecifier && specifier.type !== import_utils128.AST_NODE_TYPES.ImportDefaultSpecifier && specifier.type !== import_utils128.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.parent.type !== import_utils128.AST_NODE_TYPES.ImportDeclaration) return null;
|
|
24042
24146
|
const source = importSource(specifier.parent);
|
|
24043
24147
|
if (source !== null && ASSERT_MODULES.has(source)) {
|
|
24044
|
-
if (specifier.type !==
|
|
24045
|
-
const imported2 = specifier.imported.type ===
|
|
24148
|
+
if (specifier.type !== import_utils128.AST_NODE_TYPES.ImportSpecifier) return "assert";
|
|
24149
|
+
const imported2 = specifier.imported.type === import_utils128.AST_NODE_TYPES.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
24046
24150
|
if (imported2 === "strict" || ASSERT_MATCHERS.has(imported2)) return "assert";
|
|
24047
24151
|
return null;
|
|
24048
24152
|
}
|
|
24049
|
-
if (source === null || !EXPECT_MODULES.has(source) || specifier.type !==
|
|
24050
|
-
const imported = specifier.imported.type ===
|
|
24153
|
+
if (source === null || !EXPECT_MODULES.has(source) || specifier.type !== import_utils128.AST_NODE_TYPES.ImportSpecifier) return null;
|
|
24154
|
+
const imported = specifier.imported.type === import_utils128.AST_NODE_TYPES.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
24051
24155
|
if (imported === "assert" || imported === "expect") return imported;
|
|
24052
24156
|
return null;
|
|
24053
24157
|
}
|
|
24054
24158
|
|
|
24055
24159
|
// src/rules/sole-export-matches-filename.ts
|
|
24056
|
-
var
|
|
24160
|
+
var import_utils129 = require("@typescript-eslint/utils");
|
|
24057
24161
|
|
|
24058
24162
|
// src/rules/_is-framework-entrypoint.ts
|
|
24059
24163
|
var import_node_fs2 = require("fs");
|
|
@@ -24169,7 +24273,7 @@ var sole_export_matches_filename_default = createRule({
|
|
|
24169
24273
|
if (only === void 0) return;
|
|
24170
24274
|
if (isFrameworkEntrypoint(normalizedFilename, only.key)) return;
|
|
24171
24275
|
if (only.name === "onRouterTransitionStart" && /(?:^|\/)instrumentation-client\.[jt]s$/u.test(normalizedFilename)) return;
|
|
24172
|
-
if (only.name === "collections" && /(?:^|\/)src\/content\.config\.(?:ts|js|mjs)$/u.test(normalizedFilename) && program.body.some((statement) => statement.type ===
|
|
24276
|
+
if (only.name === "collections" && /(?:^|\/)src\/content\.config\.(?:ts|js|mjs)$/u.test(normalizedFilename) && program.body.some((statement) => statement.type === import_utils129.AST_NODE_TYPES.ImportDeclaration && statement.source.value === "astro:content")) return;
|
|
24173
24277
|
const exportedStem = kebabCase(only.name);
|
|
24174
24278
|
if (exportedStem === "") return;
|
|
24175
24279
|
const expected = `${fileStem.startsWith("_") ? "_" : ""}${exportedStem}`;
|
|
@@ -24219,7 +24323,7 @@ var iac_source_coupled_test_default = createSourceCoupledRule(
|
|
|
24219
24323
|
);
|
|
24220
24324
|
|
|
24221
24325
|
// src/rules/require-pascal-case-zod-schema-name.ts
|
|
24222
|
-
var
|
|
24326
|
+
var import_utils130 = require("@typescript-eslint/utils");
|
|
24223
24327
|
var REQUIRE_PASCAL_CASE_ZOD_SCHEMA_NAME_DOCUMENTATION = {
|
|
24224
24328
|
summary: "Require confirmed module-level Zod schema contracts to use PascalCase with a `Schema` suffix.",
|
|
24225
24329
|
rationale: "A reusable Zod schema is a runtime type contract. PascalCase mirrors that role; SCREAMING_SNAKE_CASE should remain reserved for scalar values and lookup tables.",
|
|
@@ -24351,19 +24455,19 @@ var SCHEMA_RETURNING_METHODS = /* @__PURE__ */ new Set([
|
|
|
24351
24455
|
"superRefine",
|
|
24352
24456
|
"transform"
|
|
24353
24457
|
]);
|
|
24354
|
-
var terminalMethodName = (callee) =>
|
|
24458
|
+
var terminalMethodName = (callee) => import_utils130.ASTUtils.getPropertyName(callee) !== null ? import_utils130.ASTUtils.getPropertyName(callee) ?? "" : null;
|
|
24355
24459
|
var calleeChainRoot2 = (node) => {
|
|
24356
24460
|
let current = node;
|
|
24357
24461
|
for (; ; ) {
|
|
24358
24462
|
current = unwrapExpression(current);
|
|
24359
|
-
if (current.type ===
|
|
24463
|
+
if (current.type === import_utils130.AST_NODE_TYPES.Identifier) {
|
|
24360
24464
|
return current;
|
|
24361
24465
|
}
|
|
24362
|
-
if (current.type ===
|
|
24466
|
+
if (current.type === import_utils130.AST_NODE_TYPES.MemberExpression) {
|
|
24363
24467
|
current = current.object;
|
|
24364
24468
|
continue;
|
|
24365
24469
|
}
|
|
24366
|
-
if (current.type ===
|
|
24470
|
+
if (current.type === import_utils130.AST_NODE_TYPES.CallExpression) {
|
|
24367
24471
|
current = unwrapExpression(current.callee);
|
|
24368
24472
|
continue;
|
|
24369
24473
|
}
|
|
@@ -24375,13 +24479,13 @@ var chainMemberNames2 = (node) => {
|
|
|
24375
24479
|
let current = node;
|
|
24376
24480
|
for (; ; ) {
|
|
24377
24481
|
current = unwrapExpression(current);
|
|
24378
|
-
if (current.type ===
|
|
24379
|
-
if (
|
|
24380
|
-
names.push(
|
|
24482
|
+
if (current.type === import_utils130.AST_NODE_TYPES.MemberExpression) {
|
|
24483
|
+
if (import_utils130.ASTUtils.getPropertyName(current) === null) return [];
|
|
24484
|
+
names.push(import_utils130.ASTUtils.getPropertyName(current) ?? "");
|
|
24381
24485
|
current = current.object;
|
|
24382
24486
|
continue;
|
|
24383
24487
|
}
|
|
24384
|
-
if (current.type ===
|
|
24488
|
+
if (current.type === import_utils130.AST_NODE_TYPES.CallExpression) {
|
|
24385
24489
|
current = unwrapExpression(current.callee);
|
|
24386
24490
|
continue;
|
|
24387
24491
|
}
|
|
@@ -24392,9 +24496,9 @@ var chainMemberNames2 = (node) => {
|
|
|
24392
24496
|
};
|
|
24393
24497
|
var isModuleDeclarator = (node) => {
|
|
24394
24498
|
const declaration = node.parent;
|
|
24395
|
-
if (declaration.type !==
|
|
24499
|
+
if (declaration.type !== import_utils130.AST_NODE_TYPES.VariableDeclaration) return false;
|
|
24396
24500
|
const owner = declaration.parent;
|
|
24397
|
-
return owner.type ===
|
|
24501
|
+
return owner.type === import_utils130.AST_NODE_TYPES.Program || owner.type === import_utils130.AST_NODE_TYPES.ExportNamedDeclaration && owner.parent.type === import_utils130.AST_NODE_TYPES.Program;
|
|
24398
24502
|
};
|
|
24399
24503
|
var require_pascal_case_zod_schema_name_default = createRule({
|
|
24400
24504
|
name: "require-pascal-case-zod-schema-name",
|
|
@@ -24414,7 +24518,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
24414
24518
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
24415
24519
|
const schemaBindings = /* @__PURE__ */ new Set();
|
|
24416
24520
|
function resolvedBinding(identifier) {
|
|
24417
|
-
return
|
|
24521
|
+
return import_utils130.ASTUtils.findVariable(
|
|
24418
24522
|
context.sourceCode.getScope(identifier),
|
|
24419
24523
|
identifier.name
|
|
24420
24524
|
);
|
|
@@ -24425,10 +24529,10 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
24425
24529
|
}
|
|
24426
24530
|
function isConfirmedSchema(expression) {
|
|
24427
24531
|
const init = unwrapExpression(expression);
|
|
24428
|
-
if (init.type ===
|
|
24429
|
-
if (init.type !==
|
|
24532
|
+
if (init.type === import_utils130.AST_NODE_TYPES.Identifier) return isSchemaBinding(init);
|
|
24533
|
+
if (init.type !== import_utils130.AST_NODE_TYPES.CallExpression) return false;
|
|
24430
24534
|
const callee = unwrapExpression(init.callee);
|
|
24431
|
-
if (callee.type !==
|
|
24535
|
+
if (callee.type !== import_utils130.AST_NODE_TYPES.MemberExpression) {
|
|
24432
24536
|
return false;
|
|
24433
24537
|
}
|
|
24434
24538
|
const terminal = terminalMethodName(callee);
|
|
@@ -24458,7 +24562,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
24458
24562
|
ImportDeclaration(node) {
|
|
24459
24563
|
if (!isZodModule(node.source.value)) return;
|
|
24460
24564
|
for (const specifier of node.specifiers) {
|
|
24461
|
-
if (specifier.type ===
|
|
24565
|
+
if (specifier.type === import_utils130.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils130.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils130.AST_NODE_TYPES.ImportSpecifier && (specifier.imported.type === import_utils130.AST_NODE_TYPES.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
24462
24566
|
recordZodBinding(specifier.local);
|
|
24463
24567
|
}
|
|
24464
24568
|
}
|
|
@@ -24467,7 +24571,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
24467
24571
|
if (!isModuleDeclarator(node)) return;
|
|
24468
24572
|
const init = node.init;
|
|
24469
24573
|
if (init === null || init === void 0) return;
|
|
24470
|
-
if (node.id.type !==
|
|
24574
|
+
if (node.id.type !== import_utils130.AST_NODE_TYPES.Identifier) return;
|
|
24471
24575
|
if (!isConfirmedSchema(init)) return;
|
|
24472
24576
|
const binding = resolvedBinding(node.id);
|
|
24473
24577
|
if (binding !== null) schemaBindings.add(binding);
|
|
@@ -24669,6 +24773,7 @@ var RULES = {
|
|
|
24669
24773
|
"prefer-whole-object-assertion": prefer_whole_object_assertion_default,
|
|
24670
24774
|
"repeated-static-call-cases": repeated_static_call_cases_default,
|
|
24671
24775
|
"prefer-zod-infer": prefer_zod_infer_default,
|
|
24776
|
+
"named-child-schema-type": named_child_schema_type_default,
|
|
24672
24777
|
"prefer-zod-parse-output-type": prefer_zod_parse_output_type_default,
|
|
24673
24778
|
"require-assert-never": require_assert_never_default,
|
|
24674
24779
|
"require-fetch-timeout": require_fetch_timeout_default,
|
|
@@ -24694,6 +24799,7 @@ var LIBRARY_IMPORT_POLICY = ["error", {
|
|
|
24694
24799
|
}];
|
|
24695
24800
|
var ADVISORY_RULES = [
|
|
24696
24801
|
"@sarj/excessive-commentary",
|
|
24802
|
+
"@sarj/named-child-schema-type",
|
|
24697
24803
|
"@sarj/no-bespoke-api-case-conversion",
|
|
24698
24804
|
"@sarj/no-duplicate-test-case",
|
|
24699
24805
|
"@sarj/no-json-stringify-object-equality",
|
|
@@ -24716,6 +24822,7 @@ var ADVISORY_RULES = [
|
|
|
24716
24822
|
"@sarj/require-sql-access-class"
|
|
24717
24823
|
];
|
|
24718
24824
|
var RECOMMENDED_RULES = {
|
|
24825
|
+
"@sarj/named-child-schema-type": "warn",
|
|
24719
24826
|
"@sarj/no-conditional-empty-object-spread": "error",
|
|
24720
24827
|
"@sarj/prefer-typed-reflection": "error",
|
|
24721
24828
|
"@sarj/no-broad-return-type": "error",
|
|
@@ -24833,6 +24940,7 @@ var RECOMMENDED_RULES = {
|
|
|
24833
24940
|
"@sarj/require-pascal-case-zod-schema-name": "error"
|
|
24834
24941
|
};
|
|
24835
24942
|
var STRICT_RULES = {
|
|
24943
|
+
"@sarj/named-child-schema-type": "warn",
|
|
24836
24944
|
"@sarj/no-conditional-empty-object-spread": "error",
|
|
24837
24945
|
"@sarj/prefer-typed-reflection": "error",
|
|
24838
24946
|
"@sarj/no-broad-return-type": "error",
|