@sarj/eslint-plugin 15.9.0 → 15.10.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 +815 -721
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +797 -703
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -9377,8 +9377,98 @@ function unwrapExpression(node) {
|
|
|
9377
9377
|
return node;
|
|
9378
9378
|
}
|
|
9379
9379
|
|
|
9380
|
-
// src/rules/
|
|
9380
|
+
// src/rules/test-phase-label-comment.ts
|
|
9381
9381
|
var import_utils49 = require("@typescript-eslint/utils");
|
|
9382
|
+
var PHASE_WORD = String.raw`arrange|act|assert(?:ion)?s?|given|when|then|exercise|execute|verif(?:y|ication)|cleanup|prepare|sanity(?:\s+check)?`;
|
|
9383
|
+
var PHASE_RE = new RegExp(
|
|
9384
|
+
String.raw`^[-=~*_#.\s]{0,40}(?:${PHASE_WORD})(?:\s*(?:[/&+,|]|->|and)\s*(?:${PHASE_WORD}))*[-=~*_#.\s:;!–—]{0,40}$`,
|
|
9385
|
+
"iu"
|
|
9386
|
+
);
|
|
9387
|
+
var testPhaseLabelCommentDocumentation = {
|
|
9388
|
+
summary: "Tests must not use bare Arrange, Act, Assert, Given, When, or Then phase comments.",
|
|
9389
|
+
rationale: "Phase labels narrate test structure without explaining behavior and often hide unclear names or oversized tests.",
|
|
9390
|
+
remediation: "Delete the label; if the phases remain hard to follow, extract a named helper or split the test.",
|
|
9391
|
+
category: "testing",
|
|
9392
|
+
autofix: "safe",
|
|
9393
|
+
limitations: [
|
|
9394
|
+
"Only standalone line comments in recognized test files are checked.",
|
|
9395
|
+
"Comments inside bracketed expressions or containing words outside the bounded phase grammar are preserved."
|
|
9396
|
+
],
|
|
9397
|
+
examples: [
|
|
9398
|
+
{
|
|
9399
|
+
id: "behavioral-comment",
|
|
9400
|
+
title: "Behavioral consequence is retained",
|
|
9401
|
+
outcome: "no-match",
|
|
9402
|
+
files: [{ path: "widget.test.ts", source: "// Then the retry loop would spin forever.\nexpect(run()).toBe(true);" }],
|
|
9403
|
+
focusPath: "widget.test.ts",
|
|
9404
|
+
expectedCount: 0,
|
|
9405
|
+
public: true
|
|
9406
|
+
},
|
|
9407
|
+
{
|
|
9408
|
+
id: "bare-phase-label",
|
|
9409
|
+
title: "Bare phase label is removed",
|
|
9410
|
+
outcome: "match",
|
|
9411
|
+
files: [{ path: "widget.test.ts", source: "// Arrange\nconst widget = makeWidget();" }],
|
|
9412
|
+
focusPath: "widget.test.ts",
|
|
9413
|
+
expectedCount: 1,
|
|
9414
|
+
fixedFiles: [{ path: "widget.test.ts", source: "const widget = makeWidget();" }],
|
|
9415
|
+
public: true
|
|
9416
|
+
}
|
|
9417
|
+
]
|
|
9418
|
+
};
|
|
9419
|
+
function insideExpression(sourceCode, comment) {
|
|
9420
|
+
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
9421
|
+
if (token === null) return false;
|
|
9422
|
+
let node = sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
9423
|
+
while (node != null && node.type !== import_utils49.AST_NODE_TYPES.Program) {
|
|
9424
|
+
if (node.type === import_utils49.AST_NODE_TYPES.ArrayExpression || node.type === import_utils49.AST_NODE_TYPES.ObjectExpression || node.type === import_utils49.AST_NODE_TYPES.CallExpression || node.type === import_utils49.AST_NODE_TYPES.NewExpression) return node.loc.start.line < comment.loc.start.line;
|
|
9425
|
+
if (/Statement$/u.test(node.type) || /Declaration$/u.test(node.type)) return false;
|
|
9426
|
+
node = node.parent;
|
|
9427
|
+
}
|
|
9428
|
+
return false;
|
|
9429
|
+
}
|
|
9430
|
+
function continuesProseRun(comments, index) {
|
|
9431
|
+
const comment = comments[index];
|
|
9432
|
+
if (comment?.type !== "Line") return false;
|
|
9433
|
+
return [comments[index - 1], comments[index + 1]].some(
|
|
9434
|
+
(neighbor) => neighbor?.type === "Line" && Math.abs(neighbor.loc.start.line - comment.loc.start.line) === 1 && !PHASE_RE.test(neighbor.value.trim())
|
|
9435
|
+
);
|
|
9436
|
+
}
|
|
9437
|
+
var test_phase_label_comment_default = createRule({
|
|
9438
|
+
name: "test-phase-label-comment",
|
|
9439
|
+
documentation: testPhaseLabelCommentDocumentation,
|
|
9440
|
+
meta: {
|
|
9441
|
+
type: "suggestion",
|
|
9442
|
+
fixable: "code",
|
|
9443
|
+
docs: { description: testPhaseLabelCommentDocumentation.summary },
|
|
9444
|
+
schema: [],
|
|
9445
|
+
messages: { removeLabel: "Bare test phase label \u2014 delete it and let the test names and helpers carry the structure." }
|
|
9446
|
+
},
|
|
9447
|
+
defaultOptions: [],
|
|
9448
|
+
create(context) {
|
|
9449
|
+
if (!isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text)) return {};
|
|
9450
|
+
return {
|
|
9451
|
+
Program() {
|
|
9452
|
+
const comments = context.sourceCode.getAllComments();
|
|
9453
|
+
for (const [index, comment] of comments.entries()) {
|
|
9454
|
+
if (comment.type !== "Line" || !PHASE_RE.test(comment.value.trim())) continue;
|
|
9455
|
+
const removal = wholeLineRemovalRange(context.sourceCode.text, comment);
|
|
9456
|
+
if (removal === null || insideExpression(context.sourceCode, comment) || continuesProseRun(comments, index)) {
|
|
9457
|
+
continue;
|
|
9458
|
+
}
|
|
9459
|
+
context.report({
|
|
9460
|
+
node: comment,
|
|
9461
|
+
messageId: "removeLabel",
|
|
9462
|
+
fix: (fixer) => fixer.removeRange(removal.range)
|
|
9463
|
+
});
|
|
9464
|
+
}
|
|
9465
|
+
}
|
|
9466
|
+
};
|
|
9467
|
+
}
|
|
9468
|
+
});
|
|
9469
|
+
|
|
9470
|
+
// src/rules/prefer-constant-time-secret-compare.ts
|
|
9471
|
+
var import_utils50 = require("@typescript-eslint/utils");
|
|
9382
9472
|
var preferConstantTimeSecretCompareDocumentation = {
|
|
9383
9473
|
summary: "Disallow `===`/`!==` on a secret-like value; short-circuiting comparison leaks the secret through timing. Use a constant-time compare.",
|
|
9384
9474
|
rationale: "Ordinary equality stops at the first differing byte, allowing repeated measurements to reveal secret material.",
|
|
@@ -9397,14 +9487,14 @@ var SENTINEL_PREFIX_RE = /^(skip|sentinel|empty|none|missing|unset|placeholder|d
|
|
|
9397
9487
|
var AST_NODE_TYPE_RE = /^(?:TS|JSX)?[A-Z][A-Za-z]*(?:Signature|Keyword|Expression|Declaration|Element|Literal|Identifier)$/;
|
|
9398
9488
|
function isExcludedOperand(node) {
|
|
9399
9489
|
switch (node.type) {
|
|
9400
|
-
case
|
|
9490
|
+
case import_utils50.AST_NODE_TYPES.Literal:
|
|
9401
9491
|
return true;
|
|
9402
|
-
case
|
|
9492
|
+
case import_utils50.AST_NODE_TYPES.TemplateLiteral:
|
|
9403
9493
|
return node.expressions.length === 0;
|
|
9404
|
-
case
|
|
9494
|
+
case import_utils50.AST_NODE_TYPES.Identifier:
|
|
9405
9495
|
return SENTINEL_IDENTIFIERS.has(node.name) || SENTINEL_PREFIX_RE.test(node.name) || isConstantReference(node.name);
|
|
9406
|
-
case
|
|
9407
|
-
return !node.computed && node.property.type ===
|
|
9496
|
+
case import_utils50.AST_NODE_TYPES.MemberExpression:
|
|
9497
|
+
return !node.computed && node.property.type === import_utils50.AST_NODE_TYPES.Identifier && (SENTINEL_PREFIX_RE.test(node.property.name) || isConstantReference(node.property.name));
|
|
9408
9498
|
default:
|
|
9409
9499
|
return false;
|
|
9410
9500
|
}
|
|
@@ -9415,23 +9505,23 @@ function isConstantReference(identifier) {
|
|
|
9415
9505
|
return identifier === identifier.toUpperCase() && /[A-Za-z]/.test(identifier);
|
|
9416
9506
|
}
|
|
9417
9507
|
function operandName(node) {
|
|
9418
|
-
if (node.type ===
|
|
9508
|
+
if (node.type === import_utils50.AST_NODE_TYPES.Identifier) {
|
|
9419
9509
|
return node.name;
|
|
9420
9510
|
}
|
|
9421
|
-
if (node.type ===
|
|
9511
|
+
if (node.type === import_utils50.AST_NODE_TYPES.MemberExpression && !node.computed && node.property.type === import_utils50.AST_NODE_TYPES.Identifier) {
|
|
9422
9512
|
return node.property.name;
|
|
9423
9513
|
}
|
|
9424
9514
|
return null;
|
|
9425
9515
|
}
|
|
9426
9516
|
function isSecretOperand(node) {
|
|
9427
|
-
if (node.type ===
|
|
9517
|
+
if (node.type === import_utils50.AST_NODE_TYPES.TemplateLiteral) {
|
|
9428
9518
|
return node.expressions.some((expression) => isSecretOperand(expression));
|
|
9429
9519
|
}
|
|
9430
9520
|
const name = operandName(node);
|
|
9431
9521
|
return name !== null && isAuthSecretName(name);
|
|
9432
9522
|
}
|
|
9433
9523
|
function secretNameOf(node) {
|
|
9434
|
-
if (node.type ===
|
|
9524
|
+
if (node.type === import_utils50.AST_NODE_TYPES.TemplateLiteral) {
|
|
9435
9525
|
for (const expression of node.expressions) {
|
|
9436
9526
|
const nested = secretNameOf(expression);
|
|
9437
9527
|
if (nested !== null) {
|
|
@@ -9484,8 +9574,8 @@ var prefer_constant_time_secret_compare_default = createRule({
|
|
|
9484
9574
|
});
|
|
9485
9575
|
|
|
9486
9576
|
// src/rules/prefer-discriminated-union.ts
|
|
9487
|
-
var import_utils50 = require("@typescript-eslint/utils");
|
|
9488
9577
|
var import_utils51 = require("@typescript-eslint/utils");
|
|
9578
|
+
var import_utils52 = require("@typescript-eslint/utils");
|
|
9489
9579
|
var preferDiscriminatedUnionDocumentation = {
|
|
9490
9580
|
summary: "Flag flat result objects with a required positive boolean status and optional success/failure payloads.",
|
|
9491
9581
|
rationale: "A boolean status plus optional branch data permits contradictory and incomplete states.",
|
|
@@ -9517,13 +9607,13 @@ var SUCCESS_PAYLOAD_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
|
9517
9607
|
]);
|
|
9518
9608
|
var REQUIRED_STATUS_MEMBER_COUNT = 1;
|
|
9519
9609
|
var FUNCTION_RETURN_OWNER_TYPES = /* @__PURE__ */ new Set([
|
|
9520
|
-
|
|
9521
|
-
|
|
9522
|
-
|
|
9523
|
-
|
|
9524
|
-
|
|
9525
|
-
|
|
9526
|
-
|
|
9610
|
+
import_utils52.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
9611
|
+
import_utils52.AST_NODE_TYPES.FunctionDeclaration,
|
|
9612
|
+
import_utils52.AST_NODE_TYPES.FunctionExpression,
|
|
9613
|
+
import_utils52.AST_NODE_TYPES.TSDeclareFunction,
|
|
9614
|
+
import_utils52.AST_NODE_TYPES.TSEmptyBodyFunctionExpression,
|
|
9615
|
+
import_utils52.AST_NODE_TYPES.TSFunctionType,
|
|
9616
|
+
import_utils52.AST_NODE_TYPES.TSMethodSignature
|
|
9527
9617
|
]);
|
|
9528
9618
|
function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
9529
9619
|
let statusMemberCount = 0;
|
|
@@ -9531,7 +9621,7 @@ function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
|
9531
9621
|
let hasSuccessPayload = false;
|
|
9532
9622
|
let hasUnrecognizedMember = false;
|
|
9533
9623
|
for (const member of typeLiteral.members) {
|
|
9534
|
-
if (member.type !==
|
|
9624
|
+
if (member.type !== import_utils52.AST_NODE_TYPES.TSPropertySignature) {
|
|
9535
9625
|
hasUnrecognizedMember = true;
|
|
9536
9626
|
continue;
|
|
9537
9627
|
}
|
|
@@ -9555,26 +9645,26 @@ function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
|
9555
9645
|
return statusMemberCount === REQUIRED_STATUS_MEMBER_COUNT && hasFailurePayload && (hasSuccessPayload || !hasUnrecognizedMember);
|
|
9556
9646
|
}
|
|
9557
9647
|
function getMemberName(member) {
|
|
9558
|
-
if (member.type !==
|
|
9648
|
+
if (member.type !== import_utils52.AST_NODE_TYPES.TSPropertySignature) {
|
|
9559
9649
|
return null;
|
|
9560
9650
|
}
|
|
9561
9651
|
const { key } = member;
|
|
9562
|
-
if (key.type ===
|
|
9652
|
+
if (key.type === import_utils52.AST_NODE_TYPES.Identifier) {
|
|
9563
9653
|
return key.name;
|
|
9564
9654
|
}
|
|
9565
|
-
if (key.type ===
|
|
9655
|
+
if (key.type === import_utils52.AST_NODE_TYPES.Literal && typeof key.value === "string") {
|
|
9566
9656
|
return key.value;
|
|
9567
9657
|
}
|
|
9568
9658
|
return null;
|
|
9569
9659
|
}
|
|
9570
9660
|
function isBooleanTyped(member) {
|
|
9571
|
-
return member.typeAnnotation?.typeAnnotation.type ===
|
|
9661
|
+
return member.typeAnnotation?.typeAnnotation.type === import_utils52.AST_NODE_TYPES.TSBooleanKeyword;
|
|
9572
9662
|
}
|
|
9573
9663
|
function inlineReturnTypeLiteral(node) {
|
|
9574
9664
|
let annotation = null;
|
|
9575
|
-
if (node.parent.type ===
|
|
9665
|
+
if (node.parent.type === import_utils52.AST_NODE_TYPES.TSTypeAnnotation) {
|
|
9576
9666
|
annotation = node.parent;
|
|
9577
|
-
} else if (node.parent.type ===
|
|
9667
|
+
} else if (node.parent.type === import_utils52.AST_NODE_TYPES.TSTypeParameterInstantiation && node.parent.params.length === 1 && node.parent.params[0] === node && node.parent.parent.type === import_utils52.AST_NODE_TYPES.TSTypeReference && node.parent.parent.typeName.type === import_utils52.AST_NODE_TYPES.Identifier && node.parent.parent.typeName.name === "Promise" && node.parent.parent.parent.type === import_utils52.AST_NODE_TYPES.TSTypeAnnotation) {
|
|
9578
9668
|
annotation = node.parent.parent.parent;
|
|
9579
9669
|
}
|
|
9580
9670
|
if (annotation === null) return null;
|
|
@@ -9614,7 +9704,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
9614
9704
|
}
|
|
9615
9705
|
const synthetic = {
|
|
9616
9706
|
...node.body,
|
|
9617
|
-
type:
|
|
9707
|
+
type: import_utils52.AST_NODE_TYPES.TSTypeLiteral,
|
|
9618
9708
|
members: node.body.body
|
|
9619
9709
|
};
|
|
9620
9710
|
checkTypeLiteral(synthetic, node);
|
|
@@ -9631,7 +9721,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
9631
9721
|
});
|
|
9632
9722
|
|
|
9633
9723
|
// src/rules/prefer-input-group-search.ts
|
|
9634
|
-
var
|
|
9724
|
+
var import_utils53 = require("@typescript-eslint/utils");
|
|
9635
9725
|
var preferInputGroupSearchDocumentation = {
|
|
9636
9726
|
summary: "Require search icons and shared Input controls in the same visual wrapper to use InputGroup.",
|
|
9637
9727
|
rationale: "The shared compound control provides consistent spacing, focus behavior, and accessible composition.",
|
|
@@ -9652,15 +9742,15 @@ var MAX_JSX_DISTANCE = 2;
|
|
|
9652
9742
|
var SEARCH_EXPORTS = ["Search", "SearchIcon", "LucideSearch"];
|
|
9653
9743
|
function localNamedImports(node, importedName4) {
|
|
9654
9744
|
return node.specifiers.filter(
|
|
9655
|
-
(specifier) => specifier.type ===
|
|
9745
|
+
(specifier) => specifier.type === import_utils53.AST_NODE_TYPES.ImportSpecifier && (specifier.imported.type === import_utils53.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value) === importedName4
|
|
9656
9746
|
).map((specifier) => specifier.local.name);
|
|
9657
9747
|
}
|
|
9658
9748
|
function elementName(node) {
|
|
9659
|
-
return node.name.type ===
|
|
9749
|
+
return node.name.type === import_utils53.AST_NODE_TYPES.JSXIdentifier ? node.name.name : null;
|
|
9660
9750
|
}
|
|
9661
9751
|
function jsxAncestors(occurrence) {
|
|
9662
9752
|
return occurrence.ancestors.filter(
|
|
9663
|
-
(ancestor) => ancestor.type ===
|
|
9753
|
+
(ancestor) => ancestor.type === import_utils53.AST_NODE_TYPES.JSXElement
|
|
9664
9754
|
);
|
|
9665
9755
|
}
|
|
9666
9756
|
function isWithinInputGroup(occurrence, inputGroupNames) {
|
|
@@ -9773,7 +9863,7 @@ var prefer_input_group_search_default = createRule({
|
|
|
9773
9863
|
});
|
|
9774
9864
|
|
|
9775
9865
|
// src/rules/prefer-immutable-module-constant.ts
|
|
9776
|
-
var
|
|
9866
|
+
var import_utils54 = require("@typescript-eslint/utils");
|
|
9777
9867
|
var preferImmutableModuleConstantDocumentation = {
|
|
9778
9868
|
summary: "Require module-level constant collections to expose readonly state.",
|
|
9779
9869
|
rationale: "A const binding prevents reassignment but does not stop callers from mutating its array, object, Set, or Map contents.",
|
|
@@ -9821,59 +9911,59 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
|
9821
9911
|
"unshift"
|
|
9822
9912
|
]);
|
|
9823
9913
|
function isAsConst(node, sourceText) {
|
|
9824
|
-
if (node.type ===
|
|
9914
|
+
if (node.type === import_utils54.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils54.AST_NODE_TYPES.TSNonNullExpression) {
|
|
9825
9915
|
return isAsConst(node.expression, sourceText);
|
|
9826
9916
|
}
|
|
9827
|
-
if (node.type !==
|
|
9917
|
+
if (node.type !== import_utils54.AST_NODE_TYPES.TSAsExpression) return false;
|
|
9828
9918
|
return sourceText(node.typeAnnotation).trim() === "const";
|
|
9829
9919
|
}
|
|
9830
9920
|
function unwrapExpression2(node) {
|
|
9831
|
-
if (node.type ===
|
|
9921
|
+
if (node.type === import_utils54.AST_NODE_TYPES.TSAsExpression || node.type === import_utils54.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils54.AST_NODE_TYPES.TSNonNullExpression) {
|
|
9832
9922
|
return unwrapExpression2(node.expression);
|
|
9833
9923
|
}
|
|
9834
9924
|
return node;
|
|
9835
9925
|
}
|
|
9836
9926
|
function isObjectFreeze(node, isUnshadowedGlobal) {
|
|
9837
9927
|
const inner = unwrapExpression2(node);
|
|
9838
|
-
if (inner.type ===
|
|
9928
|
+
if (inner.type === import_utils54.AST_NODE_TYPES.CallExpression && inner.callee.type === import_utils54.AST_NODE_TYPES.MemberExpression && !inner.callee.computed && inner.callee.object.type === import_utils54.AST_NODE_TYPES.Identifier && inner.callee.object.name === "Object" && isUnshadowedGlobal(inner.callee.object) && inner.callee.property.type === import_utils54.AST_NODE_TYPES.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1) {
|
|
9839
9929
|
const argument = inner.arguments[0];
|
|
9840
|
-
return argument !== void 0 && argument.type !==
|
|
9930
|
+
return argument !== void 0 && argument.type !== import_utils54.AST_NODE_TYPES.SpreadElement && collectionKind(argument, isUnshadowedGlobal) === "literal";
|
|
9841
9931
|
}
|
|
9842
9932
|
return false;
|
|
9843
9933
|
}
|
|
9844
9934
|
function collectionKind(node, isUnshadowedGlobal) {
|
|
9845
9935
|
const inner = unwrapExpression2(node);
|
|
9846
|
-
if (inner.type ===
|
|
9936
|
+
if (inner.type === import_utils54.AST_NODE_TYPES.CallExpression && inner.callee.type === import_utils54.AST_NODE_TYPES.MemberExpression && !inner.callee.computed && inner.callee.object.type === import_utils54.AST_NODE_TYPES.Identifier && inner.callee.object.name === "Object" && isUnshadowedGlobal(inner.callee.object) && inner.callee.property.type === import_utils54.AST_NODE_TYPES.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== import_utils54.AST_NODE_TYPES.SpreadElement) {
|
|
9847
9937
|
return collectionKind(inner.arguments[0], isUnshadowedGlobal);
|
|
9848
9938
|
}
|
|
9849
|
-
if (inner.type ===
|
|
9939
|
+
if (inner.type === import_utils54.AST_NODE_TYPES.ArrayExpression || inner.type === import_utils54.AST_NODE_TYPES.ObjectExpression) {
|
|
9850
9940
|
return "literal";
|
|
9851
9941
|
}
|
|
9852
|
-
if (inner.type ===
|
|
9942
|
+
if (inner.type === import_utils54.AST_NODE_TYPES.NewExpression && inner.callee.type === import_utils54.AST_NODE_TYPES.Identifier && (inner.callee.name === "Set" || inner.callee.name === "Map") && isUnshadowedGlobal(inner.callee)) {
|
|
9853
9943
|
return inner.callee.name;
|
|
9854
9944
|
}
|
|
9855
9945
|
return null;
|
|
9856
9946
|
}
|
|
9857
9947
|
function declaredReadonlyType(node, kind, aliases) {
|
|
9858
|
-
const annotation = node.id.type ===
|
|
9948
|
+
const annotation = node.id.type === import_utils54.AST_NODE_TYPES.Identifier ? node.id.typeAnnotation : void 0;
|
|
9859
9949
|
if (annotation !== void 0 && isReadonlyTypeResolved(annotation.typeAnnotation, kind, aliases)) {
|
|
9860
9950
|
return true;
|
|
9861
9951
|
}
|
|
9862
|
-
return node.init?.type ===
|
|
9952
|
+
return node.init?.type === import_utils54.AST_NODE_TYPES.TSAsExpression && isReadonlyTypeResolved(node.init.typeAnnotation, kind, aliases);
|
|
9863
9953
|
}
|
|
9864
9954
|
function isReadonlyTypeResolved(node, kind, aliases, seen = /* @__PURE__ */ new Set()) {
|
|
9865
9955
|
if (isReadonlyType(node, kind)) return true;
|
|
9866
|
-
if (node.type !==
|
|
9956
|
+
if (node.type !== import_utils54.AST_NODE_TYPES.TSTypeReference || node.typeName.type !== import_utils54.AST_NODE_TYPES.Identifier) return false;
|
|
9867
9957
|
const name = node.typeName.name;
|
|
9868
9958
|
const target = aliases.get(name);
|
|
9869
9959
|
if (target === void 0 || seen.has(name)) return false;
|
|
9870
9960
|
return isReadonlyTypeResolved(target, kind, aliases, /* @__PURE__ */ new Set([...seen, name]));
|
|
9871
9961
|
}
|
|
9872
9962
|
function isReadonlyType(node, kind) {
|
|
9873
|
-
if (node.type ===
|
|
9963
|
+
if (node.type === import_utils54.AST_NODE_TYPES.TSTypeOperator && node.operator === "readonly") {
|
|
9874
9964
|
return true;
|
|
9875
9965
|
}
|
|
9876
|
-
if (node.type !==
|
|
9966
|
+
if (node.type !== import_utils54.AST_NODE_TYPES.TSTypeReference || node.typeName.type !== import_utils54.AST_NODE_TYPES.Identifier) {
|
|
9877
9967
|
return false;
|
|
9878
9968
|
}
|
|
9879
9969
|
if (node.typeName.name === "Readonly") {
|
|
@@ -9882,31 +9972,31 @@ function isReadonlyType(node, kind) {
|
|
|
9882
9972
|
return kind === "literal" ? node.typeName.name === "ReadonlyArray" : node.typeName.name === `Readonly${kind}`;
|
|
9883
9973
|
}
|
|
9884
9974
|
function hasUnknownExplicitType(node, aliases) {
|
|
9885
|
-
const annotation = node.id.type ===
|
|
9975
|
+
const annotation = node.id.type === import_utils54.AST_NODE_TYPES.Identifier ? node.id.typeAnnotation?.typeAnnotation : void 0;
|
|
9886
9976
|
if (annotation === void 0) return false;
|
|
9887
|
-
if (annotation.type ===
|
|
9888
|
-
if (annotation.type !==
|
|
9977
|
+
if (annotation.type === import_utils54.AST_NODE_TYPES.TSArrayType || annotation.type === import_utils54.AST_NODE_TYPES.TSTypeOperator) return false;
|
|
9978
|
+
if (annotation.type !== import_utils54.AST_NODE_TYPES.TSTypeReference || annotation.typeName.type !== import_utils54.AST_NODE_TYPES.Identifier) return true;
|
|
9889
9979
|
return !aliases.has(annotation.typeName.name) && !["Array", "Map", "Readonly", "ReadonlyArray", "ReadonlyMap", "ReadonlySet", "Set"].includes(annotation.typeName.name);
|
|
9890
9980
|
}
|
|
9891
9981
|
function referenceMutates(identifier, isUnshadowedGlobal) {
|
|
9892
9982
|
let member = identifier.parent;
|
|
9893
|
-
if (member?.type !==
|
|
9894
|
-
return member?.type ===
|
|
9983
|
+
if (member?.type !== import_utils54.AST_NODE_TYPES.MemberExpression || member.object !== identifier) {
|
|
9984
|
+
return member?.type === import_utils54.AST_NODE_TYPES.CallExpression && member.arguments[0] === identifier && member.callee.type === import_utils54.AST_NODE_TYPES.MemberExpression && !member.callee.computed && member.callee.object.type === import_utils54.AST_NODE_TYPES.Identifier && member.callee.object.name === "Object" && isUnshadowedGlobal(member.callee.object) && member.callee.property.type === import_utils54.AST_NODE_TYPES.Identifier && member.callee.property.name === "assign";
|
|
9895
9985
|
}
|
|
9896
|
-
while (member.parent.type ===
|
|
9986
|
+
while (member.parent.type === import_utils54.AST_NODE_TYPES.MemberExpression && member.parent.object === member) {
|
|
9897
9987
|
member = member.parent;
|
|
9898
9988
|
}
|
|
9899
9989
|
const parent = member.parent;
|
|
9900
|
-
if (parent?.type ===
|
|
9990
|
+
if (parent?.type === import_utils54.AST_NODE_TYPES.AssignmentExpression && parent.left === member) {
|
|
9901
9991
|
return true;
|
|
9902
9992
|
}
|
|
9903
|
-
if (parent?.type ===
|
|
9993
|
+
if (parent?.type === import_utils54.AST_NODE_TYPES.UpdateExpression && parent.argument === member) {
|
|
9904
9994
|
return true;
|
|
9905
9995
|
}
|
|
9906
|
-
if (parent?.type ===
|
|
9996
|
+
if (parent?.type === import_utils54.AST_NODE_TYPES.UnaryExpression && parent.operator === "delete" && parent.argument === member) {
|
|
9907
9997
|
return true;
|
|
9908
9998
|
}
|
|
9909
|
-
return parent?.type ===
|
|
9999
|
+
return parent?.type === import_utils54.AST_NODE_TYPES.CallExpression && parent.callee === member && (member.property.type === import_utils54.AST_NODE_TYPES.Identifier && !member.computed || member.property.type === import_utils54.AST_NODE_TYPES.Literal && typeof member.property.value === "string") && MUTATING_METHODS.has(member.property.type === import_utils54.AST_NODE_TYPES.Identifier ? member.property.name : member.property.value);
|
|
9910
10000
|
}
|
|
9911
10001
|
var prefer_immutable_module_constant_default = createRule({
|
|
9912
10002
|
name: "prefer-immutable-module-constant",
|
|
@@ -9926,7 +10016,7 @@ var prefer_immutable_module_constant_default = createRule({
|
|
|
9926
10016
|
create(context) {
|
|
9927
10017
|
const sourceCode = context.sourceCode;
|
|
9928
10018
|
const isUnshadowedGlobal = (identifier) => {
|
|
9929
|
-
const variable =
|
|
10019
|
+
const variable = import_utils54.ASTUtils.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
9930
10020
|
return variable === null || variable.defs.length === 0;
|
|
9931
10021
|
};
|
|
9932
10022
|
if (JAVASCRIPT_FILE_RE.test(context.filename) || isTestFile(context.filename) || isGeneratedFile(context.filename, sourceCode.getText())) {
|
|
@@ -9943,10 +10033,10 @@ var prefer_immutable_module_constant_default = createRule({
|
|
|
9943
10033
|
seen.add(variable);
|
|
9944
10034
|
for (const reference of variable.references) {
|
|
9945
10035
|
const identifier = reference.identifier;
|
|
9946
|
-
if (identifier.type !==
|
|
10036
|
+
if (identifier.type !== import_utils54.AST_NODE_TYPES.Identifier) continue;
|
|
9947
10037
|
if (referenceMutates(identifier, isUnshadowedGlobal)) return true;
|
|
9948
10038
|
const declarator = identifier.parent;
|
|
9949
|
-
if (declarator.type !==
|
|
10039
|
+
if (declarator.type !== import_utils54.AST_NODE_TYPES.VariableDeclarator || declarator.init !== identifier || declarator.id.type !== import_utils54.AST_NODE_TYPES.Identifier || declarator.parent.type !== import_utils54.AST_NODE_TYPES.VariableDeclaration || declarator.parent.kind !== "const") {
|
|
9950
10040
|
continue;
|
|
9951
10041
|
}
|
|
9952
10042
|
const alias = sourceCode.getDeclaredVariables(declarator)[0];
|
|
@@ -9958,32 +10048,32 @@ var prefer_immutable_module_constant_default = createRule({
|
|
|
9958
10048
|
return {
|
|
9959
10049
|
Program(node) {
|
|
9960
10050
|
for (const statement of node.body) {
|
|
9961
|
-
const declaration = statement.type ===
|
|
9962
|
-
if (declaration?.type ===
|
|
10051
|
+
const declaration = statement.type === import_utils54.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
10052
|
+
if (declaration?.type === import_utils54.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
9963
10053
|
typeAliases2.set(declaration.id.name, declaration.typeAnnotation);
|
|
9964
10054
|
}
|
|
9965
|
-
if (statement.type ===
|
|
10055
|
+
if (statement.type === import_utils54.AST_NODE_TYPES.ExportNamedDeclaration) {
|
|
9966
10056
|
if (statement.source !== null || statement.exportKind === "type") continue;
|
|
9967
10057
|
for (const specifier of statement.specifiers) {
|
|
9968
|
-
if (specifier.type ===
|
|
10058
|
+
if (specifier.type === import_utils54.AST_NODE_TYPES.ExportSpecifier && specifier.exportKind !== "type" && specifier.local.type === import_utils54.AST_NODE_TYPES.Identifier) {
|
|
9969
10059
|
exportedNames2.add(specifier.local.name);
|
|
9970
10060
|
}
|
|
9971
10061
|
}
|
|
9972
|
-
} else if (statement.type ===
|
|
10062
|
+
} else if (statement.type === import_utils54.AST_NODE_TYPES.ExportDefaultDeclaration && unwrapTransparentExport(statement.declaration)?.type === import_utils54.AST_NODE_TYPES.Identifier) {
|
|
9973
10063
|
exportedNames2.add(unwrapTransparentExport(statement.declaration).name);
|
|
9974
10064
|
}
|
|
9975
10065
|
}
|
|
9976
10066
|
},
|
|
9977
10067
|
VariableDeclarator(node) {
|
|
9978
10068
|
const declaration = node.parent;
|
|
9979
|
-
if (declaration.type !==
|
|
10069
|
+
if (declaration.type !== import_utils54.AST_NODE_TYPES.VariableDeclaration || declaration.kind !== "const" || node.id.type !== import_utils54.AST_NODE_TYPES.Identifier || node.init === null) {
|
|
9980
10070
|
return;
|
|
9981
10071
|
}
|
|
9982
10072
|
const container = declaration.parent;
|
|
9983
|
-
if (container.type !==
|
|
10073
|
+
if (container.type !== import_utils54.AST_NODE_TYPES.Program && !(container.type === import_utils54.AST_NODE_TYPES.ExportNamedDeclaration && container.parent.type === import_utils54.AST_NODE_TYPES.Program)) {
|
|
9984
10074
|
return;
|
|
9985
10075
|
}
|
|
9986
|
-
const directlyExported = container.type ===
|
|
10076
|
+
const directlyExported = container.type === import_utils54.AST_NODE_TYPES.ExportNamedDeclaration;
|
|
9987
10077
|
if (!CONSTANT_NAME.test(node.id.name) && !directlyExported && !exportedNames2.has(node.id.name)) {
|
|
9988
10078
|
return;
|
|
9989
10079
|
}
|
|
@@ -10008,14 +10098,14 @@ var prefer_immutable_module_constant_default = createRule({
|
|
|
10008
10098
|
}
|
|
10009
10099
|
});
|
|
10010
10100
|
function unwrapTransparentExport(node) {
|
|
10011
|
-
if (node.type ===
|
|
10101
|
+
if (node.type === import_utils54.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils54.AST_NODE_TYPES.TSNonNullExpression) {
|
|
10012
10102
|
return unwrapTransparentExport(node.expression);
|
|
10013
10103
|
}
|
|
10014
10104
|
return node;
|
|
10015
10105
|
}
|
|
10016
10106
|
|
|
10017
10107
|
// src/rules/prefer-shadcn-primitives.ts
|
|
10018
|
-
var
|
|
10108
|
+
var import_utils55 = require("@typescript-eslint/utils");
|
|
10019
10109
|
var preferShadcnPrimitivesDocumentation = {
|
|
10020
10110
|
summary: "Require visible raw JSX controls to use the corresponding shared shadcn primitive.",
|
|
10021
10111
|
rationale: "Shared primitives centralize interaction, accessibility, and visual behavior across the product.",
|
|
@@ -10060,16 +10150,16 @@ var AMBIGUOUS_INPUT_TYPES = /* @__PURE__ */ new Set([
|
|
|
10060
10150
|
"submit"
|
|
10061
10151
|
]);
|
|
10062
10152
|
function rawElementName(node) {
|
|
10063
|
-
if (node.name.type !==
|
|
10153
|
+
if (node.name.type !== import_utils55.AST_NODE_TYPES.JSXIdentifier) return null;
|
|
10064
10154
|
const name = node.name.name;
|
|
10065
10155
|
return Object.hasOwn(SHADCN_PRIMITIVES, name) ? name : null;
|
|
10066
10156
|
}
|
|
10067
10157
|
function effectiveAttribute(node, attributeName) {
|
|
10068
10158
|
for (const attribute of node.attributes.toReversed()) {
|
|
10069
|
-
if (attribute.type ===
|
|
10159
|
+
if (attribute.type === import_utils55.AST_NODE_TYPES.JSXSpreadAttribute) {
|
|
10070
10160
|
return { kind: "unknown" };
|
|
10071
10161
|
}
|
|
10072
|
-
if (attribute.name.type !==
|
|
10162
|
+
if (attribute.name.type !== import_utils55.AST_NODE_TYPES.JSXIdentifier || attribute.name.name !== attributeName) {
|
|
10073
10163
|
continue;
|
|
10074
10164
|
}
|
|
10075
10165
|
const value = staticString(attribute.value);
|
|
@@ -10078,17 +10168,17 @@ function effectiveAttribute(node, attributeName) {
|
|
|
10078
10168
|
return { kind: "missing" };
|
|
10079
10169
|
}
|
|
10080
10170
|
function staticString(value) {
|
|
10081
|
-
if (value?.type ===
|
|
10171
|
+
if (value?.type === import_utils55.AST_NODE_TYPES.Literal) {
|
|
10082
10172
|
return typeof value.value === "string" ? value.value : null;
|
|
10083
10173
|
}
|
|
10084
|
-
if (value?.type !==
|
|
10174
|
+
if (value?.type !== import_utils55.AST_NODE_TYPES.JSXExpressionContainer) return null;
|
|
10085
10175
|
return staticExpressionString(value.expression);
|
|
10086
10176
|
}
|
|
10087
10177
|
function staticExpressionString(expression) {
|
|
10088
|
-
if (expression.type ===
|
|
10178
|
+
if (expression.type === import_utils55.AST_NODE_TYPES.Literal) {
|
|
10089
10179
|
return typeof expression.value === "string" ? expression.value : null;
|
|
10090
10180
|
}
|
|
10091
|
-
if (expression.type ===
|
|
10181
|
+
if (expression.type === import_utils55.AST_NODE_TYPES.TemplateLiteral) {
|
|
10092
10182
|
let value = expression.quasis[0]?.value.cooked ?? "";
|
|
10093
10183
|
for (const [index, substitution] of expression.expressions.entries()) {
|
|
10094
10184
|
const staticSubstitution = staticExpressionString(substitution);
|
|
@@ -10098,13 +10188,13 @@ function staticExpressionString(expression) {
|
|
|
10098
10188
|
}
|
|
10099
10189
|
return value;
|
|
10100
10190
|
}
|
|
10101
|
-
if (expression.type ===
|
|
10191
|
+
if (expression.type === import_utils55.AST_NODE_TYPES.TSAsExpression || expression.type === import_utils55.AST_NODE_TYPES.TSNonNullExpression || expression.type === import_utils55.AST_NODE_TYPES.TSSatisfiesExpression || expression.type === import_utils55.AST_NODE_TYPES.TSTypeAssertion) {
|
|
10102
10192
|
return staticExpressionString(expression.expression);
|
|
10103
10193
|
}
|
|
10104
10194
|
return null;
|
|
10105
10195
|
}
|
|
10106
10196
|
function isLabelableElement(node) {
|
|
10107
|
-
if (node.openingElement.name.type !==
|
|
10197
|
+
if (node.openingElement.name.type !== import_utils55.AST_NODE_TYPES.JSXIdentifier) {
|
|
10108
10198
|
return false;
|
|
10109
10199
|
}
|
|
10110
10200
|
const name = node.openingElement.name.name;
|
|
@@ -10116,10 +10206,10 @@ function isLabelableElement(node) {
|
|
|
10116
10206
|
}
|
|
10117
10207
|
function containsLabelableElement(node) {
|
|
10118
10208
|
return node.children.some((child) => {
|
|
10119
|
-
if (child.type ===
|
|
10209
|
+
if (child.type === import_utils55.AST_NODE_TYPES.JSXElement) {
|
|
10120
10210
|
return isLabelableElement(child) || containsLabelableElement(child);
|
|
10121
10211
|
}
|
|
10122
|
-
if (child.type ===
|
|
10212
|
+
if (child.type === import_utils55.AST_NODE_TYPES.JSXFragment) {
|
|
10123
10213
|
return containsLabelableElement(child);
|
|
10124
10214
|
}
|
|
10125
10215
|
return false;
|
|
@@ -10128,7 +10218,7 @@ function containsLabelableElement(node) {
|
|
|
10128
10218
|
function isStaticallyAssociatedLabel(node) {
|
|
10129
10219
|
const htmlFor = effectiveAttribute(node, "htmlFor");
|
|
10130
10220
|
if (htmlFor.kind === "known" && htmlFor.value.trim().length > 0) return true;
|
|
10131
|
-
return node.parent.type ===
|
|
10221
|
+
return node.parent.type === import_utils55.AST_NODE_TYPES.JSXElement && containsLabelableElement(node.parent);
|
|
10132
10222
|
}
|
|
10133
10223
|
function replacementFor(node, element) {
|
|
10134
10224
|
if (element !== "input") return SHADCN_PRIMITIVES[element];
|
|
@@ -10199,7 +10289,7 @@ var prefer_shadcn_primitives_default = createRule({
|
|
|
10199
10289
|
});
|
|
10200
10290
|
|
|
10201
10291
|
// src/rules/prefer-module-level-constant.ts
|
|
10202
|
-
var
|
|
10292
|
+
var import_utils56 = require("@typescript-eslint/utils");
|
|
10203
10293
|
var preferModuleLevelConstantDocumentation = {
|
|
10204
10294
|
summary: "Hoist literal-only constant collections and regexes out of function bodies to module scope so they are allocated once.",
|
|
10205
10295
|
rationale: "Recreating immutable lookup data on every call wastes allocations and obscures its constant nature.",
|
|
@@ -10239,9 +10329,9 @@ var MUTATING_METHODS2 = /* @__PURE__ */ new Set([
|
|
|
10239
10329
|
"assign"
|
|
10240
10330
|
]);
|
|
10241
10331
|
var FUNCTION_TYPES7 = /* @__PURE__ */ new Set([
|
|
10242
|
-
|
|
10243
|
-
|
|
10244
|
-
|
|
10332
|
+
import_utils56.AST_NODE_TYPES.FunctionDeclaration,
|
|
10333
|
+
import_utils56.AST_NODE_TYPES.FunctionExpression,
|
|
10334
|
+
import_utils56.AST_NODE_TYPES.ArrowFunctionExpression
|
|
10245
10335
|
]);
|
|
10246
10336
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
10247
10337
|
function isIgnoredFile2(filename, sourceText) {
|
|
@@ -10254,14 +10344,14 @@ function isLocalFixtureFile(filename) {
|
|
|
10254
10344
|
return isTestFile(filename) || isStoryFile(filename);
|
|
10255
10345
|
}
|
|
10256
10346
|
function unwrap3(node) {
|
|
10257
|
-
if (node.type ===
|
|
10347
|
+
if (node.type === import_utils56.AST_NODE_TYPES.TSAsExpression || node.type === import_utils56.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils56.AST_NODE_TYPES.TSNonNullExpression) {
|
|
10258
10348
|
return unwrap3(node.expression);
|
|
10259
10349
|
}
|
|
10260
10350
|
return node;
|
|
10261
10351
|
}
|
|
10262
10352
|
var HAS_STATEFUL_FLAG_RE = /[gy]/;
|
|
10263
10353
|
function isRegexLiteral(node) {
|
|
10264
|
-
return node.type ===
|
|
10354
|
+
return node.type === import_utils56.AST_NODE_TYPES.Literal && "regex" in node && node.regex !== void 0;
|
|
10265
10355
|
}
|
|
10266
10356
|
function isLiteralOnly(node, depth) {
|
|
10267
10357
|
if (depth > MAX_LITERAL_DEPTH) {
|
|
@@ -10269,29 +10359,29 @@ function isLiteralOnly(node, depth) {
|
|
|
10269
10359
|
}
|
|
10270
10360
|
const inner = unwrap3(node);
|
|
10271
10361
|
switch (inner.type) {
|
|
10272
|
-
case
|
|
10362
|
+
case import_utils56.AST_NODE_TYPES.Literal: {
|
|
10273
10363
|
return !(isRegexLiteral(inner) && HAS_STATEFUL_FLAG_RE.test(inner.regex.flags));
|
|
10274
10364
|
}
|
|
10275
|
-
case
|
|
10365
|
+
case import_utils56.AST_NODE_TYPES.TemplateLiteral: {
|
|
10276
10366
|
return inner.expressions.length === 0;
|
|
10277
10367
|
}
|
|
10278
|
-
case
|
|
10279
|
-
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type ===
|
|
10368
|
+
case import_utils56.AST_NODE_TYPES.UnaryExpression: {
|
|
10369
|
+
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type === import_utils56.AST_NODE_TYPES.Literal && typeof inner.argument.value === "number";
|
|
10280
10370
|
}
|
|
10281
|
-
case
|
|
10371
|
+
case import_utils56.AST_NODE_TYPES.ArrayExpression: {
|
|
10282
10372
|
return inner.elements.every(
|
|
10283
|
-
(el) => el !== null && el.type !==
|
|
10373
|
+
(el) => el !== null && el.type !== import_utils56.AST_NODE_TYPES.SpreadElement && isLiteralOnly(el, depth + 1)
|
|
10284
10374
|
);
|
|
10285
10375
|
}
|
|
10286
|
-
case
|
|
10376
|
+
case import_utils56.AST_NODE_TYPES.ObjectExpression: {
|
|
10287
10377
|
return inner.properties.every((prop) => {
|
|
10288
|
-
if (prop.type !==
|
|
10378
|
+
if (prop.type !== import_utils56.AST_NODE_TYPES.Property) {
|
|
10289
10379
|
return false;
|
|
10290
10380
|
}
|
|
10291
10381
|
if (prop.shorthand || prop.method || prop.kind !== "init") {
|
|
10292
10382
|
return false;
|
|
10293
10383
|
}
|
|
10294
|
-
if (prop.computed && prop.key.type !==
|
|
10384
|
+
if (prop.computed && prop.key.type !== import_utils56.AST_NODE_TYPES.Literal) {
|
|
10295
10385
|
return false;
|
|
10296
10386
|
}
|
|
10297
10387
|
return isLiteralOnly(prop.value, depth + 1);
|
|
@@ -10313,19 +10403,19 @@ function classify(init, checkRegex) {
|
|
|
10313
10403
|
}
|
|
10314
10404
|
return { kind: "regex", size: 1 };
|
|
10315
10405
|
}
|
|
10316
|
-
if (node.type ===
|
|
10406
|
+
if (node.type === import_utils56.AST_NODE_TYPES.ArrayExpression) {
|
|
10317
10407
|
return isLiteralOnly(node, 0) ? { kind: "array", size: node.elements.length } : null;
|
|
10318
10408
|
}
|
|
10319
|
-
if (node.type ===
|
|
10409
|
+
if (node.type === import_utils56.AST_NODE_TYPES.ObjectExpression) {
|
|
10320
10410
|
return isLiteralOnly(node, 0) ? { kind: "object", size: node.properties.length } : null;
|
|
10321
10411
|
}
|
|
10322
|
-
if (node.type ===
|
|
10412
|
+
if (node.type === import_utils56.AST_NODE_TYPES.NewExpression && node.callee.type === import_utils56.AST_NODE_TYPES.Identifier && COLLECTION_CONSTRUCTORS.has(node.callee.name)) {
|
|
10323
10413
|
const arg = node.arguments[0];
|
|
10324
|
-
if (node.arguments.length !== 1 || arg === void 0 || arg.type ===
|
|
10414
|
+
if (node.arguments.length !== 1 || arg === void 0 || arg.type === import_utils56.AST_NODE_TYPES.SpreadElement) {
|
|
10325
10415
|
return null;
|
|
10326
10416
|
}
|
|
10327
10417
|
const entries = unwrap3(arg);
|
|
10328
|
-
if (entries.type !==
|
|
10418
|
+
if (entries.type !== import_utils56.AST_NODE_TYPES.ArrayExpression) {
|
|
10329
10419
|
return null;
|
|
10330
10420
|
}
|
|
10331
10421
|
return isLiteralOnly(entries, 0) ? { kind: node.callee.name === "Set" ? "Set" : "Map", size: entries.elements.length } : null;
|
|
@@ -10334,7 +10424,7 @@ function classify(init, checkRegex) {
|
|
|
10334
10424
|
}
|
|
10335
10425
|
function unwrapObjectFreeze(node) {
|
|
10336
10426
|
const inner = unwrap3(node);
|
|
10337
|
-
if (inner.type ===
|
|
10427
|
+
if (inner.type === import_utils56.AST_NODE_TYPES.CallExpression && inner.callee.type === import_utils56.AST_NODE_TYPES.MemberExpression && !inner.callee.computed && inner.callee.object.type === import_utils56.AST_NODE_TYPES.Identifier && inner.callee.object.name === "Object" && inner.callee.property.type === import_utils56.AST_NODE_TYPES.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== import_utils56.AST_NODE_TYPES.SpreadElement) {
|
|
10338
10428
|
return unwrap3(inner.arguments[0]);
|
|
10339
10429
|
}
|
|
10340
10430
|
return inner;
|
|
@@ -10361,48 +10451,48 @@ var NON_RETAINING_BUILTINS = /* @__PURE__ */ new Map(
|
|
|
10361
10451
|
);
|
|
10362
10452
|
function isSafeRead(identifier) {
|
|
10363
10453
|
const parent = identifier.parent;
|
|
10364
|
-
if (parent.type ===
|
|
10454
|
+
if (parent.type === import_utils56.AST_NODE_TYPES.MemberExpression) {
|
|
10365
10455
|
if (parent.object !== identifier) {
|
|
10366
10456
|
return true;
|
|
10367
10457
|
}
|
|
10368
10458
|
const grandparent = parent.parent;
|
|
10369
|
-
if (grandparent.type ===
|
|
10459
|
+
if (grandparent.type === import_utils56.AST_NODE_TYPES.AssignmentExpression && grandparent.left === parent) {
|
|
10370
10460
|
return false;
|
|
10371
10461
|
}
|
|
10372
|
-
if (grandparent.type ===
|
|
10462
|
+
if (grandparent.type === import_utils56.AST_NODE_TYPES.UpdateExpression) {
|
|
10373
10463
|
return false;
|
|
10374
10464
|
}
|
|
10375
|
-
if (grandparent.type ===
|
|
10465
|
+
if (grandparent.type === import_utils56.AST_NODE_TYPES.UnaryExpression && grandparent.operator === "delete") {
|
|
10376
10466
|
return false;
|
|
10377
10467
|
}
|
|
10378
|
-
if (!parent.computed && parent.property.type ===
|
|
10468
|
+
if (!parent.computed && parent.property.type === import_utils56.AST_NODE_TYPES.Identifier && MUTATING_METHODS2.has(parent.property.name) && grandparent.type === import_utils56.AST_NODE_TYPES.CallExpression && grandparent.callee === parent) {
|
|
10379
10469
|
return false;
|
|
10380
10470
|
}
|
|
10381
10471
|
return true;
|
|
10382
10472
|
}
|
|
10383
|
-
if (parent.type ===
|
|
10473
|
+
if (parent.type === import_utils56.AST_NODE_TYPES.ForOfStatement && parent.right === identifier) {
|
|
10384
10474
|
return true;
|
|
10385
10475
|
}
|
|
10386
|
-
if (parent.type ===
|
|
10476
|
+
if (parent.type === import_utils56.AST_NODE_TYPES.SpreadElement) {
|
|
10387
10477
|
return true;
|
|
10388
10478
|
}
|
|
10389
|
-
if (parent.type ===
|
|
10479
|
+
if (parent.type === import_utils56.AST_NODE_TYPES.BinaryExpression) {
|
|
10390
10480
|
return true;
|
|
10391
10481
|
}
|
|
10392
|
-
if (parent.type ===
|
|
10482
|
+
if (parent.type === import_utils56.AST_NODE_TYPES.CallExpression && parent.arguments.includes(identifier) && isNonRetainingBuiltinCall(parent, identifier)) {
|
|
10393
10483
|
return true;
|
|
10394
10484
|
}
|
|
10395
|
-
if (parent.type ===
|
|
10485
|
+
if (parent.type === import_utils56.AST_NODE_TYPES.UnaryExpression && parent.operator !== "delete") {
|
|
10396
10486
|
return true;
|
|
10397
10487
|
}
|
|
10398
10488
|
return false;
|
|
10399
10489
|
}
|
|
10400
10490
|
function isNonRetainingBuiltinCall(node, argument) {
|
|
10401
10491
|
const callee = node.callee;
|
|
10402
|
-
if (callee.type ===
|
|
10492
|
+
if (callee.type === import_utils56.AST_NODE_TYPES.Identifier && callee.name === "structuredClone") {
|
|
10403
10493
|
return true;
|
|
10404
10494
|
}
|
|
10405
|
-
if (callee.type !==
|
|
10495
|
+
if (callee.type !== import_utils56.AST_NODE_TYPES.MemberExpression || callee.computed || callee.object.type !== import_utils56.AST_NODE_TYPES.Identifier || callee.property.type !== import_utils56.AST_NODE_TYPES.Identifier) {
|
|
10406
10496
|
return false;
|
|
10407
10497
|
}
|
|
10408
10498
|
const members = NON_RETAINING_BUILTINS.get(callee.object.name);
|
|
@@ -10465,7 +10555,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
10465
10555
|
if (reference.isWrite()) {
|
|
10466
10556
|
return false;
|
|
10467
10557
|
}
|
|
10468
|
-
if (reference.identifier.type !==
|
|
10558
|
+
if (reference.identifier.type !== import_utils56.AST_NODE_TYPES.Identifier) {
|
|
10469
10559
|
return false;
|
|
10470
10560
|
}
|
|
10471
10561
|
if (!isSafeRead(reference.identifier)) {
|
|
@@ -10477,10 +10567,10 @@ var prefer_module_level_constant_default = createRule({
|
|
|
10477
10567
|
return {
|
|
10478
10568
|
VariableDeclarator(node) {
|
|
10479
10569
|
const declaration = node.parent;
|
|
10480
|
-
if (declaration.type !==
|
|
10570
|
+
if (declaration.type !== import_utils56.AST_NODE_TYPES.VariableDeclaration || declaration.kind !== "const" || declaration.declare === true) {
|
|
10481
10571
|
return;
|
|
10482
10572
|
}
|
|
10483
|
-
if (node.id.type !==
|
|
10573
|
+
if (node.id.type !== import_utils56.AST_NODE_TYPES.Identifier || node.init === null) {
|
|
10484
10574
|
return;
|
|
10485
10575
|
}
|
|
10486
10576
|
if (enclosingFunction2(node) === null) {
|
|
@@ -10507,7 +10597,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
10507
10597
|
});
|
|
10508
10598
|
|
|
10509
10599
|
// src/rules/prefer-module-level-schema.ts
|
|
10510
|
-
var
|
|
10600
|
+
var import_utils57 = require("@typescript-eslint/utils");
|
|
10511
10601
|
var preferModuleLevelSchemaDocumentation = {
|
|
10512
10602
|
summary: "Declare a Zod schema at module scope when it closes over nothing in the enclosing function",
|
|
10513
10603
|
rationale: "A closed schema created inside a function is rebuilt on every call and cannot be reused or exported for inference.",
|
|
@@ -10574,9 +10664,9 @@ var I18N_RECEIVER_NAMES = /* @__PURE__ */ new Set([
|
|
|
10574
10664
|
"intl"
|
|
10575
10665
|
]);
|
|
10576
10666
|
var FUNCTION_TYPES8 = /* @__PURE__ */ new Set([
|
|
10577
|
-
|
|
10578
|
-
|
|
10579
|
-
|
|
10667
|
+
import_utils57.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
10668
|
+
import_utils57.AST_NODE_TYPES.FunctionDeclaration,
|
|
10669
|
+
import_utils57.AST_NODE_TYPES.FunctionExpression
|
|
10580
10670
|
]);
|
|
10581
10671
|
function schemaExpression(node) {
|
|
10582
10672
|
let current = node;
|
|
@@ -10585,10 +10675,10 @@ function schemaExpression(node) {
|
|
|
10585
10675
|
if (parent === void 0) {
|
|
10586
10676
|
return current;
|
|
10587
10677
|
}
|
|
10588
|
-
if (parent.type ===
|
|
10678
|
+
if (parent.type === import_utils57.AST_NODE_TYPES.MemberExpression && parent.object === current && !parent.computed && parent.property.type === import_utils57.AST_NODE_TYPES.Identifier && TERMINAL_METHODS.has(parent.property.name)) {
|
|
10589
10679
|
return current;
|
|
10590
10680
|
}
|
|
10591
|
-
if (parent.type ===
|
|
10681
|
+
if (parent.type === import_utils57.AST_NODE_TYPES.MemberExpression && parent.object === current || parent.type === import_utils57.AST_NODE_TYPES.CallExpression && parent.callee === current || parent.type === import_utils57.AST_NODE_TYPES.TSAsExpression && parent.expression === current || parent.type === import_utils57.AST_NODE_TYPES.TSNonNullExpression && parent.expression === current) {
|
|
10592
10682
|
current = parent;
|
|
10593
10683
|
continue;
|
|
10594
10684
|
}
|
|
@@ -10639,22 +10729,22 @@ function subtreeSome(root, predicate) {
|
|
|
10639
10729
|
function readsReceiver(node) {
|
|
10640
10730
|
return subtreeSome(
|
|
10641
10731
|
node,
|
|
10642
|
-
(inner) => inner.type ===
|
|
10732
|
+
(inner) => inner.type === import_utils57.AST_NODE_TYPES.ThisExpression || inner.type === import_utils57.AST_NODE_TYPES.Super || inner.type === import_utils57.AST_NODE_TYPES.Identifier && inner.name === "arguments"
|
|
10643
10733
|
);
|
|
10644
10734
|
}
|
|
10645
10735
|
function buildsLocalizedText(node) {
|
|
10646
10736
|
return subtreeSome(node, (inner) => {
|
|
10647
|
-
if (inner.type ===
|
|
10737
|
+
if (inner.type === import_utils57.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
10648
10738
|
return true;
|
|
10649
10739
|
}
|
|
10650
|
-
if (inner.type !==
|
|
10740
|
+
if (inner.type !== import_utils57.AST_NODE_TYPES.CallExpression) {
|
|
10651
10741
|
return false;
|
|
10652
10742
|
}
|
|
10653
10743
|
const { callee } = inner;
|
|
10654
|
-
if (callee.type ===
|
|
10744
|
+
if (callee.type === import_utils57.AST_NODE_TYPES.Identifier) {
|
|
10655
10745
|
return I18N_CALLEE_NAMES.has(callee.name);
|
|
10656
10746
|
}
|
|
10657
|
-
return callee.type ===
|
|
10747
|
+
return callee.type === import_utils57.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.object.type === import_utils57.AST_NODE_TYPES.Identifier && I18N_RECEIVER_NAMES.has(callee.object.name);
|
|
10658
10748
|
});
|
|
10659
10749
|
}
|
|
10660
10750
|
function collectReferences(scope, out) {
|
|
@@ -10718,15 +10808,15 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10718
10808
|
}
|
|
10719
10809
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
10720
10810
|
function isZodCall(node) {
|
|
10721
|
-
return node.type ===
|
|
10811
|
+
return node.type === import_utils57.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils57.AST_NODE_TYPES.MemberExpression && !node.callee.computed && node.callee.object.type === import_utils57.AST_NODE_TYPES.Identifier && zodNamespaces.has(node.callee.object.name);
|
|
10722
10812
|
}
|
|
10723
10813
|
function isCovered(node) {
|
|
10724
10814
|
let current = node.parent ?? void 0;
|
|
10725
10815
|
while (current !== void 0) {
|
|
10726
|
-
if (current !== node && isZodCall(current) && current.callee.type ===
|
|
10816
|
+
if (current !== node && isZodCall(current) && current.callee.type === import_utils57.AST_NODE_TYPES.MemberExpression && current.callee.property.type === import_utils57.AST_NODE_TYPES.Identifier && factories.has(current.callee.property.name)) {
|
|
10727
10817
|
return true;
|
|
10728
10818
|
}
|
|
10729
|
-
if (current.type ===
|
|
10819
|
+
if (current.type === import_utils57.AST_NODE_TYPES.CallExpression && (current.callee.type === import_utils57.AST_NODE_TYPES.Identifier && memoCallees.has(current.callee.name) || current.callee.type === import_utils57.AST_NODE_TYPES.MemberExpression && !current.callee.computed && current.callee.property.type === import_utils57.AST_NODE_TYPES.Identifier && memoCallees.has(current.callee.property.name))) {
|
|
10730
10820
|
return true;
|
|
10731
10821
|
}
|
|
10732
10822
|
current = current.parent ?? void 0;
|
|
@@ -10741,11 +10831,11 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10741
10831
|
if (parent === void 0) {
|
|
10742
10832
|
return confirmed;
|
|
10743
10833
|
}
|
|
10744
|
-
if (parent.type ===
|
|
10834
|
+
if (parent.type === import_utils57.AST_NODE_TYPES.Property && parent.value === current || parent.type === import_utils57.AST_NODE_TYPES.ObjectExpression || parent.type === import_utils57.AST_NODE_TYPES.ArrayExpression) {
|
|
10745
10835
|
current = parent;
|
|
10746
10836
|
continue;
|
|
10747
10837
|
}
|
|
10748
|
-
if (parent.type ===
|
|
10838
|
+
if (parent.type === import_utils57.AST_NODE_TYPES.CallExpression && parent.arguments.includes(current) && isSchemaComposition(parent)) {
|
|
10749
10839
|
current = schemaExpression(parent);
|
|
10750
10840
|
confirmed = current;
|
|
10751
10841
|
continue;
|
|
@@ -10755,7 +10845,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10755
10845
|
}
|
|
10756
10846
|
function isSchemaComposition(node) {
|
|
10757
10847
|
const { callee } = node;
|
|
10758
|
-
const isCombinator = callee.type ===
|
|
10848
|
+
const isCombinator = callee.type === import_utils57.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils57.AST_NODE_TYPES.Identifier && ZOD_COMBINATOR_METHODS.has(callee.property.name);
|
|
10759
10849
|
return isCombinator || isZodCall(node);
|
|
10760
10850
|
}
|
|
10761
10851
|
function closesOverNothing(node, enclosing) {
|
|
@@ -10775,12 +10865,12 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10775
10865
|
for (const definition of resolved.defs) {
|
|
10776
10866
|
if (definition.type === "ImportBinding") {
|
|
10777
10867
|
const parent = reference.identifier.parent;
|
|
10778
|
-
if (parent?.type ===
|
|
10868
|
+
if (parent?.type === import_utils57.AST_NODE_TYPES.CallExpression && parent.callee === reference.identifier && !zodNamespaces.has(reference.identifier.name)) {
|
|
10779
10869
|
return false;
|
|
10780
10870
|
}
|
|
10781
10871
|
continue;
|
|
10782
10872
|
}
|
|
10783
|
-
if (definition.node.type ===
|
|
10873
|
+
if (definition.node.type === import_utils57.AST_NODE_TYPES.VariableDeclarator && definition.node.parent.type === import_utils57.AST_NODE_TYPES.VariableDeclaration && definition.node.parent.kind !== "const") {
|
|
10784
10874
|
return false;
|
|
10785
10875
|
}
|
|
10786
10876
|
const [defStart, defEnd] = definition.node.range;
|
|
@@ -10796,13 +10886,13 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10796
10886
|
}
|
|
10797
10887
|
function ownerName(enclosing) {
|
|
10798
10888
|
const parent = enclosing.parent ?? void 0;
|
|
10799
|
-
if (enclosing.type ===
|
|
10889
|
+
if (enclosing.type === import_utils57.AST_NODE_TYPES.FunctionDeclaration && enclosing.id !== null) {
|
|
10800
10890
|
return enclosing.id.name;
|
|
10801
10891
|
}
|
|
10802
|
-
if (parent !== void 0 && parent.type ===
|
|
10892
|
+
if (parent !== void 0 && parent.type === import_utils57.AST_NODE_TYPES.VariableDeclarator && parent.id.type === import_utils57.AST_NODE_TYPES.Identifier) {
|
|
10803
10893
|
return parent.id.name;
|
|
10804
10894
|
}
|
|
10805
|
-
if (parent !== void 0 && (parent.type ===
|
|
10895
|
+
if (parent !== void 0 && (parent.type === import_utils57.AST_NODE_TYPES.MethodDefinition || parent.type === import_utils57.AST_NODE_TYPES.Property) && parent.key.type === import_utils57.AST_NODE_TYPES.Identifier) {
|
|
10806
10896
|
return parent.key.name;
|
|
10807
10897
|
}
|
|
10808
10898
|
return "this function";
|
|
@@ -10813,7 +10903,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10813
10903
|
return;
|
|
10814
10904
|
}
|
|
10815
10905
|
for (const specifier of node.specifiers) {
|
|
10816
|
-
if (specifier.type ===
|
|
10906
|
+
if (specifier.type === import_utils57.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils57.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils57.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils57.AST_NODE_TYPES.Identifier && specifier.imported.name === "z") {
|
|
10817
10907
|
zodNamespaces.add(specifier.local.name);
|
|
10818
10908
|
}
|
|
10819
10909
|
}
|
|
@@ -10823,7 +10913,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10823
10913
|
return;
|
|
10824
10914
|
}
|
|
10825
10915
|
const callee = node.callee;
|
|
10826
|
-
if (callee.property.type !==
|
|
10916
|
+
if (callee.property.type !== import_utils57.AST_NODE_TYPES.Identifier) {
|
|
10827
10917
|
return;
|
|
10828
10918
|
}
|
|
10829
10919
|
const factory = callee.property.name;
|
|
@@ -10838,7 +10928,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10838
10928
|
return;
|
|
10839
10929
|
}
|
|
10840
10930
|
const shape = node.arguments[0];
|
|
10841
|
-
if (shape !== void 0 && shape.type ===
|
|
10931
|
+
if (shape !== void 0 && shape.type === import_utils57.AST_NODE_TYPES.ObjectExpression && shape.properties.length < minProperties) {
|
|
10842
10932
|
return;
|
|
10843
10933
|
}
|
|
10844
10934
|
const expression = schemaExpression(node);
|
|
@@ -10866,7 +10956,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10866
10956
|
});
|
|
10867
10957
|
|
|
10868
10958
|
// src/rules/prefer-native-random-uuid.ts
|
|
10869
|
-
var
|
|
10959
|
+
var import_utils58 = require("@typescript-eslint/utils");
|
|
10870
10960
|
var preferNativeRandomUuidDocumentation = {
|
|
10871
10961
|
summary: "Prefer `globalThis.crypto.randomUUID()` over resolved zero-argument UUID v4 bindings from the `uuid` package.",
|
|
10872
10962
|
rationale: "The platform implementation avoids an unnecessary dependency for standard random UUID generation.",
|
|
@@ -10880,7 +10970,7 @@ var preferNativeRandomUuidDocumentation = {
|
|
|
10880
10970
|
]
|
|
10881
10971
|
};
|
|
10882
10972
|
function requireUuid(node) {
|
|
10883
|
-
return node?.type ===
|
|
10973
|
+
return node?.type === import_utils58.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils58.AST_NODE_TYPES.Identifier && node.callee.name === "require" && node.arguments.length === 1 && node.arguments[0]?.type === import_utils58.AST_NODE_TYPES.Literal && node.arguments[0].value === "uuid";
|
|
10884
10974
|
}
|
|
10885
10975
|
var prefer_native_random_uuid_default = createRule({
|
|
10886
10976
|
name: "prefer-native-random-uuid",
|
|
@@ -10902,7 +10992,7 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
10902
10992
|
const directBindings = /* @__PURE__ */ new Set();
|
|
10903
10993
|
const namespaceBindings = /* @__PURE__ */ new Set();
|
|
10904
10994
|
function resolve(identifier) {
|
|
10905
|
-
return
|
|
10995
|
+
return import_utils58.ASTUtils.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
10906
10996
|
}
|
|
10907
10997
|
function record(identifier, destination) {
|
|
10908
10998
|
const variable = resolve(identifier);
|
|
@@ -10924,37 +11014,37 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
10924
11014
|
ImportDeclaration(node) {
|
|
10925
11015
|
if (node.source.value !== "uuid") return;
|
|
10926
11016
|
for (const specifier of node.specifiers) {
|
|
10927
|
-
if (specifier.type ===
|
|
11017
|
+
if (specifier.type === import_utils58.AST_NODE_TYPES.ImportSpecifier && (specifier.imported.type === import_utils58.AST_NODE_TYPES.Identifier ? specifier.imported.name === "v4" : specifier.imported.value === "v4")) {
|
|
10928
11018
|
record(specifier.local, directBindings);
|
|
10929
|
-
} else if (specifier.type ===
|
|
11019
|
+
} else if (specifier.type === import_utils58.AST_NODE_TYPES.ImportNamespaceSpecifier) {
|
|
10930
11020
|
record(specifier.local, namespaceBindings);
|
|
10931
11021
|
}
|
|
10932
11022
|
}
|
|
10933
11023
|
},
|
|
10934
11024
|
VariableDeclarator(node) {
|
|
10935
11025
|
if (node.parent.kind !== "const" || !requireUuid(node.init)) return;
|
|
10936
|
-
if (node.init?.type !==
|
|
11026
|
+
if (node.init?.type !== import_utils58.AST_NODE_TYPES.CallExpression || node.init.callee.type !== import_utils58.AST_NODE_TYPES.Identifier || (resolve(node.init.callee)?.defs.length ?? 0) > 0) {
|
|
10937
11027
|
return;
|
|
10938
11028
|
}
|
|
10939
|
-
if (node.id.type ===
|
|
11029
|
+
if (node.id.type === import_utils58.AST_NODE_TYPES.Identifier) {
|
|
10940
11030
|
record(node.id, namespaceBindings);
|
|
10941
11031
|
return;
|
|
10942
11032
|
}
|
|
10943
|
-
if (node.id.type !==
|
|
11033
|
+
if (node.id.type !== import_utils58.AST_NODE_TYPES.ObjectPattern) return;
|
|
10944
11034
|
for (const property of node.id.properties) {
|
|
10945
|
-
if (property.type ===
|
|
11035
|
+
if (property.type === import_utils58.AST_NODE_TYPES.Property && !property.computed && (property.key.type === import_utils58.AST_NODE_TYPES.Identifier && property.key.name === "v4" || property.key.type === import_utils58.AST_NODE_TYPES.Literal && property.key.value === "v4") && property.value.type === import_utils58.AST_NODE_TYPES.Identifier) {
|
|
10946
11036
|
record(property.value, directBindings);
|
|
10947
11037
|
}
|
|
10948
11038
|
}
|
|
10949
11039
|
},
|
|
10950
11040
|
"CallExpression:exit"(node) {
|
|
10951
11041
|
if (node.arguments.length !== 0) return;
|
|
10952
|
-
if (node.callee.type ===
|
|
11042
|
+
if (node.callee.type === import_utils58.AST_NODE_TYPES.Identifier) {
|
|
10953
11043
|
const variable2 = resolve(node.callee);
|
|
10954
11044
|
if (variable2 !== null && directBindings.has(variable2)) report(node);
|
|
10955
11045
|
return;
|
|
10956
11046
|
}
|
|
10957
|
-
if (node.callee.type !==
|
|
11047
|
+
if (node.callee.type !== import_utils58.AST_NODE_TYPES.MemberExpression || node.callee.computed || node.callee.object.type !== import_utils58.AST_NODE_TYPES.Identifier || node.callee.property.type !== import_utils58.AST_NODE_TYPES.Identifier || node.callee.property.name !== "v4") {
|
|
10958
11048
|
return;
|
|
10959
11049
|
}
|
|
10960
11050
|
const variable = resolve(node.callee.object);
|
|
@@ -10965,7 +11055,7 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
10965
11055
|
});
|
|
10966
11056
|
|
|
10967
11057
|
// src/rules/prefer-non-nullable-collection.ts
|
|
10968
|
-
var
|
|
11058
|
+
var import_utils59 = require("@typescript-eslint/utils");
|
|
10969
11059
|
var preferNonNullableCollectionDocumentation = {
|
|
10970
11060
|
summary: "Suggest non-null arrays only when local control flow proves the nullish state is equivalent to an empty collection.",
|
|
10971
11061
|
rationale: "A redundant nullish collection state spreads defaults and guards through consumers without carrying information.",
|
|
@@ -10981,33 +11071,33 @@ var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
|
10981
11071
|
function propertyName(node) {
|
|
10982
11072
|
const key = node.key;
|
|
10983
11073
|
if (node.computed) return null;
|
|
10984
|
-
if (key.type ===
|
|
10985
|
-
if (key.type ===
|
|
11074
|
+
if (key.type === import_utils59.AST_NODE_TYPES.Identifier) return key.name;
|
|
11075
|
+
if (key.type === import_utils59.AST_NODE_TYPES.Literal && typeof key.value === "string") return key.value;
|
|
10986
11076
|
return null;
|
|
10987
11077
|
}
|
|
10988
11078
|
function isArrayType(node) {
|
|
10989
|
-
if (node.type ===
|
|
10990
|
-
return node.type ===
|
|
11079
|
+
if (node.type === import_utils59.AST_NODE_TYPES.TSArrayType) return true;
|
|
11080
|
+
return node.type === import_utils59.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils59.AST_NODE_TYPES.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
10991
11081
|
}
|
|
10992
11082
|
function nullableProperty(node) {
|
|
10993
11083
|
if (node.optional) return null;
|
|
10994
11084
|
const name = propertyName(node);
|
|
10995
11085
|
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
10996
|
-
if (name === null || annotation?.type !==
|
|
11086
|
+
if (name === null || annotation?.type !== import_utils59.AST_NODE_TYPES.TSUnionType) return null;
|
|
10997
11087
|
const concrete = annotation.types.filter(
|
|
10998
|
-
(member) => member.type !==
|
|
11088
|
+
(member) => member.type !== import_utils59.AST_NODE_TYPES.TSNullKeyword && member.type !== import_utils59.AST_NODE_TYPES.TSUndefinedKeyword
|
|
10999
11089
|
);
|
|
11000
11090
|
if (concrete.length === 0 || !concrete.every(isArrayType)) return null;
|
|
11001
|
-
const acceptsNull = annotation.types.some((member) => member.type ===
|
|
11091
|
+
const acceptsNull = annotation.types.some((member) => member.type === import_utils59.AST_NODE_TYPES.TSNullKeyword);
|
|
11002
11092
|
const acceptsUndefined = annotation.types.some(
|
|
11003
|
-
(member) => member.type ===
|
|
11093
|
+
(member) => member.type === import_utils59.AST_NODE_TYPES.TSUndefinedKeyword
|
|
11004
11094
|
);
|
|
11005
11095
|
if (!acceptsNull && !acceptsUndefined) return null;
|
|
11006
11096
|
return { name, node, acceptsNull, acceptsUndefined };
|
|
11007
11097
|
}
|
|
11008
11098
|
function shapeProperties(members) {
|
|
11009
11099
|
return members.flatMap((member) => {
|
|
11010
|
-
if (member.type !==
|
|
11100
|
+
if (member.type !== import_utils59.AST_NODE_TYPES.TSPropertySignature) return [];
|
|
11011
11101
|
const property = nullableProperty(member);
|
|
11012
11102
|
return property === null ? [] : [property];
|
|
11013
11103
|
});
|
|
@@ -11015,14 +11105,14 @@ function shapeProperties(members) {
|
|
|
11015
11105
|
function typeIndex(program) {
|
|
11016
11106
|
const index = /* @__PURE__ */ new Map();
|
|
11017
11107
|
for (const statement of program.body) {
|
|
11018
|
-
const exported = statement.type ===
|
|
11108
|
+
const exported = statement.type === import_utils59.AST_NODE_TYPES.ExportNamedDeclaration;
|
|
11019
11109
|
const declaration = exported ? statement.declaration : statement;
|
|
11020
|
-
if (declaration?.type ===
|
|
11110
|
+
if (declaration?.type === import_utils59.AST_NODE_TYPES.TSInterfaceDeclaration) {
|
|
11021
11111
|
index.set(declaration.id.name, {
|
|
11022
11112
|
exported,
|
|
11023
11113
|
properties: shapeProperties(declaration.body.body)
|
|
11024
11114
|
});
|
|
11025
|
-
} else if (declaration?.type ===
|
|
11115
|
+
} else if (declaration?.type === import_utils59.AST_NODE_TYPES.TSTypeAliasDeclaration && declaration.typeAnnotation.type === import_utils59.AST_NODE_TYPES.TSTypeLiteral) {
|
|
11026
11116
|
index.set(declaration.id.name, {
|
|
11027
11117
|
exported,
|
|
11028
11118
|
properties: shapeProperties(declaration.typeAnnotation.members)
|
|
@@ -11032,42 +11122,42 @@ function typeIndex(program) {
|
|
|
11032
11122
|
return index;
|
|
11033
11123
|
}
|
|
11034
11124
|
function emptyArray(node) {
|
|
11035
|
-
return node.type ===
|
|
11125
|
+
return node.type === import_utils59.AST_NODE_TYPES.ArrayExpression && node.elements.length === 0;
|
|
11036
11126
|
}
|
|
11037
11127
|
function sameAccess(node, access) {
|
|
11038
11128
|
if (access.kind === "identifier") {
|
|
11039
|
-
return node.type ===
|
|
11129
|
+
return node.type === import_utils59.AST_NODE_TYPES.Identifier && node.name === access.name;
|
|
11040
11130
|
}
|
|
11041
|
-
return node.type ===
|
|
11131
|
+
return node.type === import_utils59.AST_NODE_TYPES.MemberExpression && !node.computed && node.object.type === import_utils59.AST_NODE_TYPES.Identifier && node.object.name === access.object && node.property.type === import_utils59.AST_NODE_TYPES.Identifier && node.property.name === access.property;
|
|
11042
11132
|
}
|
|
11043
11133
|
function isNullGuard(node, access) {
|
|
11044
|
-
if (node.type ===
|
|
11045
|
-
if (node.type !==
|
|
11134
|
+
if (node.type === import_utils59.AST_NODE_TYPES.UnaryExpression && node.operator === "!" && (sameAccess(node.argument, access) || optionalMemberLengthOf(node.argument, access))) return true;
|
|
11135
|
+
if (node.type !== import_utils59.AST_NODE_TYPES.BinaryExpression || !["==", "==="].includes(node.operator)) {
|
|
11046
11136
|
return false;
|
|
11047
11137
|
}
|
|
11048
|
-
const nullish = (value) => value.type ===
|
|
11138
|
+
const nullish = (value) => value.type === import_utils59.AST_NODE_TYPES.Literal && value.value === null || value.type === import_utils59.AST_NODE_TYPES.Identifier && value.name === "undefined";
|
|
11049
11139
|
return sameAccess(node.left, access) && nullish(node.right) || sameAccess(node.right, access) && nullish(node.left);
|
|
11050
11140
|
}
|
|
11051
11141
|
function isEmptyGuard(node, access) {
|
|
11052
|
-
if (node.type ===
|
|
11053
|
-
if (node.type !==
|
|
11142
|
+
if (node.type === import_utils59.AST_NODE_TYPES.UnaryExpression && node.operator === "!" && memberLengthOf(node.argument, access)) return true;
|
|
11143
|
+
if (node.type !== import_utils59.AST_NODE_TYPES.BinaryExpression || !["==", "===", "<="].includes(node.operator)) {
|
|
11054
11144
|
return false;
|
|
11055
11145
|
}
|
|
11056
|
-
const zero = (value) => value.type ===
|
|
11146
|
+
const zero = (value) => value.type === import_utils59.AST_NODE_TYPES.Literal && value.value === 0;
|
|
11057
11147
|
return memberLengthOf(node.left, access) && zero(node.right) || memberLengthOf(node.right, access) && zero(node.left);
|
|
11058
11148
|
}
|
|
11059
11149
|
function memberLengthOf(node, access) {
|
|
11060
|
-
const target = node.type ===
|
|
11061
|
-
return target.type ===
|
|
11150
|
+
const target = node.type === import_utils59.AST_NODE_TYPES.ChainExpression ? node.expression : node;
|
|
11151
|
+
return target.type === import_utils59.AST_NODE_TYPES.MemberExpression && !target.computed && target.property.type === import_utils59.AST_NODE_TYPES.Identifier && target.property.name === "length" && sameAccess(target.object, access);
|
|
11062
11152
|
}
|
|
11063
11153
|
function optionalMemberLengthOf(node, access) {
|
|
11064
|
-
return node.type ===
|
|
11154
|
+
return node.type === import_utils59.AST_NODE_TYPES.ChainExpression && node.expression.type === import_utils59.AST_NODE_TYPES.MemberExpression && node.expression.optional && memberLengthOf(node, access);
|
|
11065
11155
|
}
|
|
11066
11156
|
function hasEquivalentLeadingGuard(fn, access, visitorKeys) {
|
|
11067
|
-
if (fn.body.type !==
|
|
11157
|
+
if (fn.body.type !== import_utils59.AST_NODE_TYPES.BlockStatement) return false;
|
|
11068
11158
|
const first = fn.body.body[0];
|
|
11069
|
-
if (first?.type !==
|
|
11070
|
-
const terminating = first.consequent.type ===
|
|
11159
|
+
if (first?.type !== import_utils59.AST_NODE_TYPES.IfStatement) return false;
|
|
11160
|
+
const terminating = first.consequent.type === import_utils59.AST_NODE_TYPES.ReturnStatement || first.consequent.type === import_utils59.AST_NODE_TYPES.ThrowStatement || first.consequent.type === import_utils59.AST_NODE_TYPES.BlockStatement && first.consequent.body.length === 1 && (first.consequent.body[0]?.type === import_utils59.AST_NODE_TYPES.ReturnStatement || first.consequent.body[0]?.type === import_utils59.AST_NODE_TYPES.ThrowStatement);
|
|
11071
11161
|
if (!terminating) return false;
|
|
11072
11162
|
if (contains(first.consequent, visitorKeys, (node) => sameAccess(node, access))) return false;
|
|
11073
11163
|
return contains(first.test, visitorKeys, (node) => isNullGuard(node, access)) && contains(first.test, visitorKeys, (node) => isEmptyGuard(node, access));
|
|
@@ -11085,29 +11175,29 @@ function contains(node, visitorKeys, predicate) {
|
|
|
11085
11175
|
function belongsToFunction(node, fn) {
|
|
11086
11176
|
let current = node;
|
|
11087
11177
|
while (current !== void 0 && current !== fn) {
|
|
11088
|
-
if (current !== node && (current.type ===
|
|
11178
|
+
if (current !== node && (current.type === import_utils59.AST_NODE_TYPES.ArrowFunctionExpression || current.type === import_utils59.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils59.AST_NODE_TYPES.FunctionExpression)) return false;
|
|
11089
11179
|
current = current.parent;
|
|
11090
11180
|
}
|
|
11091
11181
|
return current === fn;
|
|
11092
11182
|
}
|
|
11093
11183
|
function directlyCoalesced(node) {
|
|
11094
11184
|
const parent = node.parent;
|
|
11095
|
-
return parent?.type ===
|
|
11185
|
+
return parent?.type === import_utils59.AST_NODE_TYPES.LogicalExpression && parent.left === node && (parent.operator === "??" || parent.operator === "||") && emptyArray(parent.right);
|
|
11096
11186
|
}
|
|
11097
11187
|
function identifierIsOnlyCoalesced(context, binding, fn) {
|
|
11098
|
-
const variable =
|
|
11188
|
+
const variable = import_utils59.ASTUtils.findVariable(context.sourceCode.getScope(binding), binding.name);
|
|
11099
11189
|
if (variable === null || variable.references.length === 0) return false;
|
|
11100
11190
|
return variable.references.every(
|
|
11101
11191
|
(reference) => belongsToFunction(reference.identifier, fn) && directlyCoalesced(reference.identifier)
|
|
11102
11192
|
);
|
|
11103
11193
|
}
|
|
11104
11194
|
function memberIsOnlyCoalesced(context, object, property, fn) {
|
|
11105
|
-
const variable =
|
|
11195
|
+
const variable = import_utils59.ASTUtils.findVariable(context.sourceCode.getScope(object), object.name);
|
|
11106
11196
|
if (variable === null) return false;
|
|
11107
11197
|
const accesses = variable.references.flatMap((reference) => {
|
|
11108
11198
|
if (!belongsToFunction(reference.identifier, fn)) return [null];
|
|
11109
11199
|
const parent = reference.identifier.parent;
|
|
11110
|
-
if (parent?.type ===
|
|
11200
|
+
if (parent?.type === import_utils59.AST_NODE_TYPES.MemberExpression && !parent.computed && parent.object === reference.identifier && parent.property.type === import_utils59.AST_NODE_TYPES.Identifier && parent.property.name === property) return [parent];
|
|
11111
11201
|
return [];
|
|
11112
11202
|
});
|
|
11113
11203
|
return accesses.length > 0 && accesses.every((access) => access !== null && directlyCoalesced(access));
|
|
@@ -11133,8 +11223,8 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
11133
11223
|
let shapes = /* @__PURE__ */ new Map();
|
|
11134
11224
|
const evidence = /* @__PURE__ */ new Map();
|
|
11135
11225
|
function propertiesFor(annotation) {
|
|
11136
|
-
if (annotation?.type ===
|
|
11137
|
-
if (annotation?.type ===
|
|
11226
|
+
if (annotation?.type === import_utils59.AST_NODE_TYPES.TSTypeLiteral) return shapeProperties(annotation.members);
|
|
11227
|
+
if (annotation?.type === import_utils59.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils59.AST_NODE_TYPES.Identifier) {
|
|
11138
11228
|
const shape = shapes.get(annotation.typeName.name);
|
|
11139
11229
|
return shape?.exported === false ? shape.properties : [];
|
|
11140
11230
|
}
|
|
@@ -11147,21 +11237,21 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
11147
11237
|
}
|
|
11148
11238
|
function checkFunction(fn) {
|
|
11149
11239
|
for (const rawParameter of fn.params) {
|
|
11150
|
-
const parameter = rawParameter.type ===
|
|
11151
|
-
if (parameter.type ===
|
|
11240
|
+
const parameter = rawParameter.type === import_utils59.AST_NODE_TYPES.AssignmentPattern ? rawParameter.left : rawParameter;
|
|
11241
|
+
if (parameter.type === import_utils59.AST_NODE_TYPES.ObjectPattern) {
|
|
11152
11242
|
const properties2 = propertiesFor(parameter.typeAnnotation?.typeAnnotation);
|
|
11153
11243
|
for (const property of properties2) {
|
|
11154
11244
|
const bindingProperty = parameter.properties.find(
|
|
11155
|
-
(entry) => entry.type ===
|
|
11245
|
+
(entry) => entry.type === import_utils59.AST_NODE_TYPES.Property && !entry.computed && entry.key.type === import_utils59.AST_NODE_TYPES.Identifier && entry.key.name === property.name
|
|
11156
11246
|
);
|
|
11157
11247
|
if (bindingProperty === void 0) continue;
|
|
11158
11248
|
const value = bindingProperty.value;
|
|
11159
|
-
const binding = value.type ===
|
|
11160
|
-
if (binding.type !==
|
|
11249
|
+
const binding = value.type === import_utils59.AST_NODE_TYPES.AssignmentPattern ? value.left : value;
|
|
11250
|
+
if (binding.type !== import_utils59.AST_NODE_TYPES.Identifier) {
|
|
11161
11251
|
record(property, false);
|
|
11162
11252
|
continue;
|
|
11163
11253
|
}
|
|
11164
|
-
if (value.type ===
|
|
11254
|
+
if (value.type === import_utils59.AST_NODE_TYPES.AssignmentPattern && emptyArray(value.right) && property.acceptsUndefined && !property.acceptsNull) {
|
|
11165
11255
|
record(property, true);
|
|
11166
11256
|
continue;
|
|
11167
11257
|
}
|
|
@@ -11173,7 +11263,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
11173
11263
|
}
|
|
11174
11264
|
continue;
|
|
11175
11265
|
}
|
|
11176
|
-
if (parameter.type !==
|
|
11266
|
+
if (parameter.type !== import_utils59.AST_NODE_TYPES.Identifier) continue;
|
|
11177
11267
|
const properties = propertiesFor(parameter.typeAnnotation?.typeAnnotation);
|
|
11178
11268
|
for (const property of properties) {
|
|
11179
11269
|
const access = {
|
|
@@ -11210,7 +11300,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
11210
11300
|
});
|
|
11211
11301
|
|
|
11212
11302
|
// src/rules/prefer-await-in-async-return.ts
|
|
11213
|
-
var
|
|
11303
|
+
var import_utils60 = require("@typescript-eslint/utils");
|
|
11214
11304
|
var ts2 = __toESM(require("typescript"), 1);
|
|
11215
11305
|
var preferAwaitInAsyncReturnDocumentation = {
|
|
11216
11306
|
summary: "Prefer explicit `await` when an async function directly returns one typed Promise `.then` transform.",
|
|
@@ -11252,10 +11342,10 @@ var preferAwaitInAsyncReturnDocumentation = {
|
|
|
11252
11342
|
};
|
|
11253
11343
|
function directAsyncReturnOwner(node) {
|
|
11254
11344
|
const parent = node.parent;
|
|
11255
|
-
if (parent.type ===
|
|
11345
|
+
if (parent.type === import_utils60.AST_NODE_TYPES.ArrowFunctionExpression && parent.body === node) {
|
|
11256
11346
|
return parent.async && !parent.generator ? parent : null;
|
|
11257
11347
|
}
|
|
11258
|
-
if (parent.type !==
|
|
11348
|
+
if (parent.type !== import_utils60.AST_NODE_TYPES.ReturnStatement || parent.argument !== node) {
|
|
11259
11349
|
return null;
|
|
11260
11350
|
}
|
|
11261
11351
|
let owner = parent.parent;
|
|
@@ -11265,15 +11355,15 @@ function directAsyncReturnOwner(node) {
|
|
|
11265
11355
|
return owner !== void 0 && owner.async && !owner.generator ? owner : null;
|
|
11266
11356
|
}
|
|
11267
11357
|
function isRuntimeFunction(node) {
|
|
11268
|
-
return node.type ===
|
|
11358
|
+
return node.type === import_utils60.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils60.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils60.AST_NODE_TYPES.FunctionExpression;
|
|
11269
11359
|
}
|
|
11270
11360
|
function promiseThenReceiver(node) {
|
|
11271
11361
|
const callee = node.callee;
|
|
11272
|
-
if (callee.type !==
|
|
11362
|
+
if (callee.type !== import_utils60.AST_NODE_TYPES.MemberExpression || callee.computed || callee.optional || callee.property.type !== import_utils60.AST_NODE_TYPES.Identifier || callee.property.name !== "then" || node.optional || node.arguments.length !== 1) {
|
|
11273
11363
|
return null;
|
|
11274
11364
|
}
|
|
11275
11365
|
const callback = node.arguments[0];
|
|
11276
|
-
if (callback === void 0 || callback.type !==
|
|
11366
|
+
if (callback === void 0 || callback.type !== import_utils60.AST_NODE_TYPES.ArrowFunctionExpression && callback.type !== import_utils60.AST_NODE_TYPES.FunctionExpression) {
|
|
11277
11367
|
return null;
|
|
11278
11368
|
}
|
|
11279
11369
|
return callee.object;
|
|
@@ -11314,32 +11404,32 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
11314
11404
|
create(context) {
|
|
11315
11405
|
let services;
|
|
11316
11406
|
try {
|
|
11317
|
-
services =
|
|
11407
|
+
services = import_utils60.ESLintUtils.getParserServices(context);
|
|
11318
11408
|
} catch {
|
|
11319
11409
|
services = null;
|
|
11320
11410
|
}
|
|
11321
11411
|
if (services === null) return {};
|
|
11322
11412
|
const frameworkLoaders = /* @__PURE__ */ new Set();
|
|
11323
11413
|
const rememberFrameworkLoader = (identifier) => {
|
|
11324
|
-
const variable =
|
|
11414
|
+
const variable = import_utils60.ASTUtils.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
11325
11415
|
if (variable !== null) frameworkLoaders.add(variable);
|
|
11326
11416
|
};
|
|
11327
11417
|
const isFrameworkLoaderCallback = (owner) => {
|
|
11328
11418
|
const parent = owner.parent;
|
|
11329
|
-
if (parent.type !==
|
|
11330
|
-
const variable =
|
|
11419
|
+
if (parent.type !== import_utils60.AST_NODE_TYPES.CallExpression || parent.arguments[0] !== owner || parent.callee.type !== import_utils60.AST_NODE_TYPES.Identifier) return false;
|
|
11420
|
+
const variable = import_utils60.ASTUtils.findVariable(context.sourceCode.getScope(parent.callee), parent.callee.name);
|
|
11331
11421
|
return variable !== null && frameworkLoaders.has(variable);
|
|
11332
11422
|
};
|
|
11333
11423
|
return {
|
|
11334
11424
|
ImportDeclaration(node) {
|
|
11335
11425
|
if (node.source.value === "react") {
|
|
11336
11426
|
for (const specifier of node.specifiers) {
|
|
11337
|
-
if (specifier.type ===
|
|
11427
|
+
if (specifier.type === import_utils60.AST_NODE_TYPES.ImportSpecifier && (specifier.imported.type === import_utils60.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value) === "lazy") rememberFrameworkLoader(specifier.local);
|
|
11338
11428
|
}
|
|
11339
11429
|
}
|
|
11340
11430
|
if (node.source.value === "next/dynamic") {
|
|
11341
11431
|
for (const specifier of node.specifiers) {
|
|
11342
|
-
if (specifier.type ===
|
|
11432
|
+
if (specifier.type === import_utils60.AST_NODE_TYPES.ImportDefaultSpecifier) rememberFrameworkLoader(specifier.local);
|
|
11343
11433
|
}
|
|
11344
11434
|
}
|
|
11345
11435
|
},
|
|
@@ -11357,7 +11447,7 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
11357
11447
|
});
|
|
11358
11448
|
|
|
11359
11449
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
11360
|
-
var
|
|
11450
|
+
var import_utils61 = require("@typescript-eslint/utils");
|
|
11361
11451
|
var preferSchemaForApiPayloadDocumentation = {
|
|
11362
11452
|
summary: "Require Zod (or similar) schema validation on `response.json()` / `JSON.parse()` results before property access.",
|
|
11363
11453
|
rationale: "External JSON is untrusted at runtime even when its expected TypeScript shape is known statically.",
|
|
@@ -11372,9 +11462,9 @@ var preferSchemaForApiPayloadDocumentation = {
|
|
|
11372
11462
|
var unwrap4 = (node) => {
|
|
11373
11463
|
let current = node;
|
|
11374
11464
|
while (current !== null && current !== void 0) {
|
|
11375
|
-
if (current.type ===
|
|
11465
|
+
if (current.type === import_utils61.AST_NODE_TYPES.TSAsExpression || current.type === import_utils61.AST_NODE_TYPES.TSTypeAssertion || current.type === import_utils61.AST_NODE_TYPES.TSNonNullExpression || current.type === import_utils61.AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
11376
11466
|
current = current.expression;
|
|
11377
|
-
} else if (current.type ===
|
|
11467
|
+
} else if (current.type === import_utils61.AST_NODE_TYPES.ChainExpression) {
|
|
11378
11468
|
current = current.expression;
|
|
11379
11469
|
} else {
|
|
11380
11470
|
break;
|
|
@@ -11389,23 +11479,23 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
11389
11479
|
]);
|
|
11390
11480
|
var isSchemaParseReference = (node) => {
|
|
11391
11481
|
const inner = unwrap4(node);
|
|
11392
|
-
return inner !== null && inner.type ===
|
|
11482
|
+
return inner !== null && inner.type === import_utils61.AST_NODE_TYPES.MemberExpression && !inner.computed && inner.property.type === import_utils61.AST_NODE_TYPES.Identifier && (inner.property.name === "parse" || inner.property.name === "safeParse");
|
|
11393
11483
|
};
|
|
11394
11484
|
var isRawPayloadSource = (node, isKnownLocalText) => {
|
|
11395
11485
|
let current = unwrap4(node);
|
|
11396
11486
|
if (current === null) return false;
|
|
11397
|
-
if (current.type ===
|
|
11487
|
+
if (current.type === import_utils61.AST_NODE_TYPES.AwaitExpression) {
|
|
11398
11488
|
current = unwrap4(current.argument);
|
|
11399
11489
|
}
|
|
11400
|
-
if (current === null || current.type !==
|
|
11490
|
+
if (current === null || current.type !== import_utils61.AST_NODE_TYPES.CallExpression) {
|
|
11401
11491
|
return false;
|
|
11402
11492
|
}
|
|
11403
11493
|
const callee = unwrap4(current.callee);
|
|
11404
|
-
if (callee === null || callee.type !==
|
|
11494
|
+
if (callee === null || callee.type !== import_utils61.AST_NODE_TYPES.MemberExpression) {
|
|
11405
11495
|
return false;
|
|
11406
11496
|
}
|
|
11407
11497
|
const property = unwrap4(callee.property);
|
|
11408
|
-
if (property === null || property.type !==
|
|
11498
|
+
if (property === null || property.type !== import_utils61.AST_NODE_TYPES.Identifier) {
|
|
11409
11499
|
return false;
|
|
11410
11500
|
}
|
|
11411
11501
|
if (property.name === "json") {
|
|
@@ -11415,17 +11505,17 @@ var isRawPayloadSource = (node, isKnownLocalText) => {
|
|
|
11415
11505
|
return !current.arguments.some(isSchemaParseReference) && isRawPayloadSource(callee.object);
|
|
11416
11506
|
}
|
|
11417
11507
|
const object = unwrap4(callee.object);
|
|
11418
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
11508
|
+
return property.name === "parse" && object !== null && object.type === import_utils61.AST_NODE_TYPES.Identifier && object.name === "JSON" && !isLocalFileRead(current.arguments[0]) && isKnownLocalText?.(current.arguments[0]) !== true;
|
|
11419
11509
|
};
|
|
11420
11510
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
11421
11511
|
var isDirectLocalFileRead = (node) => {
|
|
11422
11512
|
let current = unwrap4(node);
|
|
11423
|
-
if (current?.type ===
|
|
11513
|
+
if (current?.type === import_utils61.AST_NODE_TYPES.AwaitExpression) {
|
|
11424
11514
|
current = unwrap4(current.argument);
|
|
11425
11515
|
}
|
|
11426
|
-
if (current?.type !==
|
|
11516
|
+
if (current?.type !== import_utils61.AST_NODE_TYPES.CallExpression) return false;
|
|
11427
11517
|
const callee = unwrap4(current.callee);
|
|
11428
|
-
const name = callee?.type ===
|
|
11518
|
+
const name = callee?.type === import_utils61.AST_NODE_TYPES.Identifier ? callee.name : callee?.type === import_utils61.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils61.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
11429
11519
|
return name !== null && FILE_READ_RE.test(name);
|
|
11430
11520
|
};
|
|
11431
11521
|
var isLocalFileRead = (node) => {
|
|
@@ -11452,15 +11542,15 @@ var isLocalFileRead = (node) => {
|
|
|
11452
11542
|
var ASSERTION_CALLEE_RE = /^(expect|assert|should|invariant)$/;
|
|
11453
11543
|
var isInsideAssertion = (node) => {
|
|
11454
11544
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11455
|
-
if (current.type !==
|
|
11545
|
+
if (current.type !== import_utils61.AST_NODE_TYPES.CallExpression) continue;
|
|
11456
11546
|
let callee = current.callee;
|
|
11457
|
-
while (callee.type ===
|
|
11547
|
+
while (callee.type === import_utils61.AST_NODE_TYPES.MemberExpression) {
|
|
11458
11548
|
callee = callee.object;
|
|
11459
11549
|
}
|
|
11460
|
-
if (callee.type ===
|
|
11550
|
+
if (callee.type === import_utils61.AST_NODE_TYPES.CallExpression) {
|
|
11461
11551
|
callee = callee.callee;
|
|
11462
11552
|
}
|
|
11463
|
-
if (callee.type ===
|
|
11553
|
+
if (callee.type === import_utils61.AST_NODE_TYPES.Identifier && ASSERTION_CALLEE_RE.test(callee.name)) {
|
|
11464
11554
|
return true;
|
|
11465
11555
|
}
|
|
11466
11556
|
}
|
|
@@ -11479,22 +11569,22 @@ var GUARD_NAME_RE = /^(?:is|validate|parse|assert|decode|coerce)[A-Z]/;
|
|
|
11479
11569
|
var isValidationRead = (node) => {
|
|
11480
11570
|
let current = node;
|
|
11481
11571
|
let parent = current.parent;
|
|
11482
|
-
while (parent !== null && parent !== void 0 && (parent.type ===
|
|
11572
|
+
while (parent !== null && parent !== void 0 && (parent.type === import_utils61.AST_NODE_TYPES.TSAsExpression || parent.type === import_utils61.AST_NODE_TYPES.TSTypeAssertion || parent.type === import_utils61.AST_NODE_TYPES.TSNonNullExpression || parent.type === import_utils61.AST_NODE_TYPES.TSSatisfiesExpression || parent.type === import_utils61.AST_NODE_TYPES.ChainExpression)) {
|
|
11483
11573
|
current = parent;
|
|
11484
11574
|
parent = parent.parent;
|
|
11485
11575
|
}
|
|
11486
11576
|
if (parent === null || parent === void 0) return false;
|
|
11487
|
-
if (parent.type ===
|
|
11577
|
+
if (parent.type === import_utils61.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof" && parent.argument === current) {
|
|
11488
11578
|
return true;
|
|
11489
11579
|
}
|
|
11490
|
-
if (parent.type !==
|
|
11580
|
+
if (parent.type !== import_utils61.AST_NODE_TYPES.CallExpression || !parent.arguments.some((arg) => arg === current)) {
|
|
11491
11581
|
return false;
|
|
11492
11582
|
}
|
|
11493
11583
|
const callee = parent.callee;
|
|
11494
|
-
if (callee.type ===
|
|
11584
|
+
if (callee.type === import_utils61.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.object.type === import_utils61.AST_NODE_TYPES.Identifier && callee.object.name === "Array" && callee.property.type === import_utils61.AST_NODE_TYPES.Identifier && callee.property.name === "isArray") {
|
|
11495
11585
|
return parent.arguments.length === 1;
|
|
11496
11586
|
}
|
|
11497
|
-
return callee.type ===
|
|
11587
|
+
return callee.type === import_utils61.AST_NODE_TYPES.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
11498
11588
|
};
|
|
11499
11589
|
var PRIMITIVE_TYPEOF_RESULTS = /* @__PURE__ */ new Set([
|
|
11500
11590
|
"bigint",
|
|
@@ -11505,13 +11595,13 @@ var PRIMITIVE_TYPEOF_RESULTS = /* @__PURE__ */ new Set([
|
|
|
11505
11595
|
"undefined"
|
|
11506
11596
|
]);
|
|
11507
11597
|
var bindingValidationPolarity = (test, bindingName) => {
|
|
11508
|
-
if (test.type ===
|
|
11598
|
+
if (test.type === import_utils61.AST_NODE_TYPES.UnaryExpression && test.operator === "!") {
|
|
11509
11599
|
const inner = bindingValidationPolarity(test.argument, bindingName);
|
|
11510
11600
|
return inner === "valid-when-true" ? "valid-when-false" : inner === "valid-when-false" ? "valid-when-true" : null;
|
|
11511
11601
|
}
|
|
11512
|
-
if (test.type ===
|
|
11513
|
-
const typeofName = (node) => node.type ===
|
|
11514
|
-
const literalType = (node) => node.type ===
|
|
11602
|
+
if (test.type === import_utils61.AST_NODE_TYPES.BinaryExpression) {
|
|
11603
|
+
const typeofName = (node) => node.type === import_utils61.AST_NODE_TYPES.UnaryExpression && node.operator === "typeof" && node.argument.type === import_utils61.AST_NODE_TYPES.Identifier ? node.argument.name : null;
|
|
11604
|
+
const literalType = (node) => node.type === import_utils61.AST_NODE_TYPES.Literal && typeof node.value === "string" && PRIMITIVE_TYPEOF_RESULTS.has(node.value) ? node.value : null;
|
|
11515
11605
|
const matches = typeofName(test.left) === bindingName && literalType(test.right) !== null || typeofName(test.right) === bindingName && literalType(test.left) !== null;
|
|
11516
11606
|
if (!matches) return null;
|
|
11517
11607
|
if (test.operator === "===" || test.operator === "==") {
|
|
@@ -11519,9 +11609,9 @@ var bindingValidationPolarity = (test, bindingName) => {
|
|
|
11519
11609
|
}
|
|
11520
11610
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
11521
11611
|
}
|
|
11522
|
-
return test.type ===
|
|
11612
|
+
return test.type === import_utils61.AST_NODE_TYPES.CallExpression && test.arguments.length === 1 && test.arguments[0]?.type === import_utils61.AST_NODE_TYPES.Identifier && test.arguments[0].name === bindingName && test.callee.type === import_utils61.AST_NODE_TYPES.MemberExpression && !test.callee.computed && test.callee.object.type === import_utils61.AST_NODE_TYPES.Identifier && test.callee.object.name === "Array" && test.callee.property.type === import_utils61.AST_NODE_TYPES.Identifier && test.callee.property.name === "isArray" ? "valid-when-true" : null;
|
|
11523
11613
|
};
|
|
11524
|
-
var plainMemberAccess = (node) => node.type ===
|
|
11614
|
+
var plainMemberAccess = (node) => node.type === import_utils61.AST_NODE_TYPES.MemberExpression && !node.computed && node.object.type === import_utils61.AST_NODE_TYPES.Identifier && node.property.type === import_utils61.AST_NODE_TYPES.Identifier ? { object: node.object.name, property: node.property.name } : null;
|
|
11525
11615
|
var isSamePlainMember = (node, access) => {
|
|
11526
11616
|
const candidate = plainMemberAccess(node);
|
|
11527
11617
|
return candidate !== null && candidate.object === access.object && candidate.property === access.property;
|
|
@@ -11529,19 +11619,19 @@ var isSamePlainMember = (node, access) => {
|
|
|
11529
11619
|
var nodeWithin2 = (node, container) => node.range[0] >= container.range[0] && node.range[1] <= container.range[1];
|
|
11530
11620
|
var isUseWithinValidatedBranch = (node, bindingName) => {
|
|
11531
11621
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11532
|
-
if (current.type ===
|
|
11622
|
+
if (current.type === import_utils61.AST_NODE_TYPES.ConditionalExpression) {
|
|
11533
11623
|
const polarity = bindingValidationPolarity(current.test, bindingName);
|
|
11534
11624
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && nodeWithin2(node, current.alternate)) {
|
|
11535
11625
|
return true;
|
|
11536
11626
|
}
|
|
11537
11627
|
}
|
|
11538
|
-
if (current.type ===
|
|
11628
|
+
if (current.type === import_utils61.AST_NODE_TYPES.IfStatement) {
|
|
11539
11629
|
const polarity = bindingValidationPolarity(current.test, bindingName);
|
|
11540
11630
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && current.alternate !== null && nodeWithin2(node, current.alternate)) {
|
|
11541
11631
|
return true;
|
|
11542
11632
|
}
|
|
11543
11633
|
}
|
|
11544
|
-
if (current.type ===
|
|
11634
|
+
if (current.type === import_utils61.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils61.AST_NODE_TYPES.FunctionExpression || current.type === import_utils61.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
11545
11635
|
return false;
|
|
11546
11636
|
}
|
|
11547
11637
|
}
|
|
@@ -11549,32 +11639,32 @@ var isUseWithinValidatedBranch = (node, bindingName) => {
|
|
|
11549
11639
|
};
|
|
11550
11640
|
var isMemberUseWithinValidatedBranch = (node, access) => {
|
|
11551
11641
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11552
|
-
if (current.type ===
|
|
11642
|
+
if (current.type === import_utils61.AST_NODE_TYPES.ConditionalExpression) {
|
|
11553
11643
|
const polarity = memberValidationPolarity(current.test, access);
|
|
11554
11644
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && nodeWithin2(node, current.alternate)) {
|
|
11555
11645
|
return true;
|
|
11556
11646
|
}
|
|
11557
11647
|
}
|
|
11558
|
-
if (current.type ===
|
|
11648
|
+
if (current.type === import_utils61.AST_NODE_TYPES.IfStatement) {
|
|
11559
11649
|
const polarity = memberValidationPolarity(current.test, access);
|
|
11560
11650
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && current.alternate !== null && nodeWithin2(node, current.alternate)) {
|
|
11561
11651
|
return true;
|
|
11562
11652
|
}
|
|
11563
11653
|
}
|
|
11564
|
-
if (current.type ===
|
|
11654
|
+
if (current.type === import_utils61.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils61.AST_NODE_TYPES.FunctionExpression || current.type === import_utils61.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
11565
11655
|
return false;
|
|
11566
11656
|
}
|
|
11567
11657
|
}
|
|
11568
11658
|
return false;
|
|
11569
11659
|
};
|
|
11570
11660
|
var memberValidationPolarity = (test, access) => {
|
|
11571
|
-
if (test.type ===
|
|
11661
|
+
if (test.type === import_utils61.AST_NODE_TYPES.UnaryExpression && test.operator === "!") {
|
|
11572
11662
|
const inner = memberValidationPolarity(test.argument, access);
|
|
11573
11663
|
return inner === "valid-when-true" ? "valid-when-false" : inner === "valid-when-false" ? "valid-when-true" : null;
|
|
11574
11664
|
}
|
|
11575
|
-
if (test.type ===
|
|
11576
|
-
const isMatchingTypeof = (node) => node.type ===
|
|
11577
|
-
const isPrimitiveType = (node) => node.type ===
|
|
11665
|
+
if (test.type === import_utils61.AST_NODE_TYPES.BinaryExpression) {
|
|
11666
|
+
const isMatchingTypeof = (node) => node.type === import_utils61.AST_NODE_TYPES.UnaryExpression && node.operator === "typeof" && isSamePlainMember(node.argument, access);
|
|
11667
|
+
const isPrimitiveType = (node) => node.type === import_utils61.AST_NODE_TYPES.Literal && typeof node.value === "string" && PRIMITIVE_TYPEOF_RESULTS.has(node.value);
|
|
11578
11668
|
if (!(isMatchingTypeof(test.left) && isPrimitiveType(test.right) || isMatchingTypeof(test.right) && isPrimitiveType(test.left))) {
|
|
11579
11669
|
return null;
|
|
11580
11670
|
}
|
|
@@ -11583,15 +11673,15 @@ var memberValidationPolarity = (test, access) => {
|
|
|
11583
11673
|
}
|
|
11584
11674
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
11585
11675
|
}
|
|
11586
|
-
return test.type ===
|
|
11676
|
+
return test.type === import_utils61.AST_NODE_TYPES.CallExpression && test.arguments.length === 1 && test.arguments[0] !== void 0 && test.arguments[0].type !== import_utils61.AST_NODE_TYPES.SpreadElement && isSamePlainMember(test.arguments[0], access) && test.callee.type === import_utils61.AST_NODE_TYPES.MemberExpression && !test.callee.computed && test.callee.object.type === import_utils61.AST_NODE_TYPES.Identifier && test.callee.object.name === "Array" && test.callee.property.type === import_utils61.AST_NODE_TYPES.Identifier && test.callee.property.name === "isArray" ? "valid-when-true" : null;
|
|
11587
11677
|
};
|
|
11588
11678
|
var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
11589
11679
|
const isValidationReference = (identifier) => {
|
|
11590
11680
|
for (let current = identifier.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11591
|
-
if ((current.type ===
|
|
11681
|
+
if ((current.type === import_utils61.AST_NODE_TYPES.BinaryExpression || current.type === import_utils61.AST_NODE_TYPES.CallExpression || current.type === import_utils61.AST_NODE_TYPES.UnaryExpression) && bindingValidationPolarity(current, identifier.name) !== null) {
|
|
11592
11682
|
return true;
|
|
11593
11683
|
}
|
|
11594
|
-
if (current.type !==
|
|
11684
|
+
if (current.type !== import_utils61.AST_NODE_TYPES.UnaryExpression && current.type !== import_utils61.AST_NODE_TYPES.MemberExpression && current.type !== import_utils61.AST_NODE_TYPES.CallExpression) {
|
|
11595
11685
|
return false;
|
|
11596
11686
|
}
|
|
11597
11687
|
}
|
|
@@ -11599,7 +11689,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11599
11689
|
};
|
|
11600
11690
|
const isGuardedUse = (identifier) => {
|
|
11601
11691
|
for (let current = identifier.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11602
|
-
if (current.type ===
|
|
11692
|
+
if (current.type === import_utils61.AST_NODE_TYPES.ConditionalExpression) {
|
|
11603
11693
|
const polarity = bindingValidationPolarity(current.test, identifier.name);
|
|
11604
11694
|
if (polarity === "valid-when-true" && nodeWithin2(identifier, current.consequent)) {
|
|
11605
11695
|
return true;
|
|
@@ -11608,7 +11698,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11608
11698
|
return true;
|
|
11609
11699
|
}
|
|
11610
11700
|
}
|
|
11611
|
-
if (current.type ===
|
|
11701
|
+
if (current.type === import_utils61.AST_NODE_TYPES.IfStatement) {
|
|
11612
11702
|
const polarity = bindingValidationPolarity(current.test, identifier.name);
|
|
11613
11703
|
if (polarity === "valid-when-true" && nodeWithin2(identifier, current.consequent)) {
|
|
11614
11704
|
return true;
|
|
@@ -11617,14 +11707,14 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11617
11707
|
return true;
|
|
11618
11708
|
}
|
|
11619
11709
|
}
|
|
11620
|
-
if (current.type ===
|
|
11710
|
+
if (current.type === import_utils61.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils61.AST_NODE_TYPES.FunctionExpression || current.type === import_utils61.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
11621
11711
|
return false;
|
|
11622
11712
|
}
|
|
11623
11713
|
}
|
|
11624
11714
|
return false;
|
|
11625
11715
|
};
|
|
11626
11716
|
const declarator = member.parent;
|
|
11627
|
-
if (declarator.type !==
|
|
11717
|
+
if (declarator.type !== import_utils61.AST_NODE_TYPES.VariableDeclarator || declarator.init !== member || declarator.id.type !== import_utils61.AST_NODE_TYPES.Identifier || declarator.parent.type !== import_utils61.AST_NODE_TYPES.VariableDeclaration || declarator.parent.kind !== "const") {
|
|
11628
11718
|
return false;
|
|
11629
11719
|
}
|
|
11630
11720
|
const extracted = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
@@ -11632,7 +11722,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11632
11722
|
let hasValueUse = false;
|
|
11633
11723
|
for (const reference of extracted.references) {
|
|
11634
11724
|
const identifier = reference.identifier;
|
|
11635
|
-
if (identifier.type !==
|
|
11725
|
+
if (identifier.type !== import_utils61.AST_NODE_TYPES.Identifier) return false;
|
|
11636
11726
|
if (nodeWithin2(identifier, declarator)) continue;
|
|
11637
11727
|
if (isValidationReference(identifier)) continue;
|
|
11638
11728
|
hasValueUse = true;
|
|
@@ -11645,17 +11735,17 @@ var isGuardTestPosition = (node) => {
|
|
|
11645
11735
|
let parent = current.parent;
|
|
11646
11736
|
while (parent !== void 0 && parent !== null) {
|
|
11647
11737
|
switch (parent.type) {
|
|
11648
|
-
case
|
|
11649
|
-
case
|
|
11650
|
-
case
|
|
11738
|
+
case import_utils61.AST_NODE_TYPES.UnaryExpression:
|
|
11739
|
+
case import_utils61.AST_NODE_TYPES.LogicalExpression:
|
|
11740
|
+
case import_utils61.AST_NODE_TYPES.ChainExpression:
|
|
11651
11741
|
current = parent;
|
|
11652
11742
|
parent = parent.parent;
|
|
11653
11743
|
continue;
|
|
11654
|
-
case
|
|
11655
|
-
case
|
|
11656
|
-
case
|
|
11657
|
-
case
|
|
11658
|
-
case
|
|
11744
|
+
case import_utils61.AST_NODE_TYPES.IfStatement:
|
|
11745
|
+
case import_utils61.AST_NODE_TYPES.ConditionalExpression:
|
|
11746
|
+
case import_utils61.AST_NODE_TYPES.WhileStatement:
|
|
11747
|
+
case import_utils61.AST_NODE_TYPES.DoWhileStatement:
|
|
11748
|
+
case import_utils61.AST_NODE_TYPES.ForStatement:
|
|
11659
11749
|
return parent.test === current;
|
|
11660
11750
|
default:
|
|
11661
11751
|
return false;
|
|
@@ -11665,7 +11755,7 @@ var isGuardTestPosition = (node) => {
|
|
|
11665
11755
|
};
|
|
11666
11756
|
var unvalidatedVariableRef = (node, scope, tracked) => {
|
|
11667
11757
|
const unwrapped = unwrap4(node);
|
|
11668
|
-
if (unwrapped === null || unwrapped.type !==
|
|
11758
|
+
if (unwrapped === null || unwrapped.type !== import_utils61.AST_NODE_TYPES.Identifier) {
|
|
11669
11759
|
return null;
|
|
11670
11760
|
}
|
|
11671
11761
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -11694,7 +11784,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11694
11784
|
const localFileTextVariables = /* @__PURE__ */ new Set();
|
|
11695
11785
|
const localFileTextRef = (node, scope) => {
|
|
11696
11786
|
const unwrapped = unwrap4(node);
|
|
11697
|
-
if (unwrapped?.type !==
|
|
11787
|
+
if (unwrapped?.type !== import_utils61.AST_NODE_TYPES.Identifier) return null;
|
|
11698
11788
|
const variable = findVariable2(scope, unwrapped.name);
|
|
11699
11789
|
return variable !== null && localFileTextVariables.has(variable) ? variable : null;
|
|
11700
11790
|
};
|
|
@@ -11763,7 +11853,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11763
11853
|
return {
|
|
11764
11854
|
VariableDeclarator(node) {
|
|
11765
11855
|
const scope = context.sourceCode.getScope(node);
|
|
11766
|
-
if (node.id.type ===
|
|
11856
|
+
if (node.id.type === import_utils61.AST_NODE_TYPES.Identifier) {
|
|
11767
11857
|
const variable = context.sourceCode.getDeclaredVariables(node)[0];
|
|
11768
11858
|
if (variable !== void 0) {
|
|
11769
11859
|
updateLocalFileText(variable, node.init, scope);
|
|
@@ -11771,7 +11861,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11771
11861
|
trackInitializer(node, scope);
|
|
11772
11862
|
return;
|
|
11773
11863
|
}
|
|
11774
|
-
if (node.id.type ===
|
|
11864
|
+
if (node.id.type === import_utils61.AST_NODE_TYPES.ObjectPattern || node.id.type === import_utils61.AST_NODE_TYPES.ArrayPattern) {
|
|
11775
11865
|
if (isRawPayloadSource(
|
|
11776
11866
|
node.init,
|
|
11777
11867
|
(candidate) => localFileTextRef(candidate, scope) !== null
|
|
@@ -11788,7 +11878,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11788
11878
|
},
|
|
11789
11879
|
AssignmentExpression(node) {
|
|
11790
11880
|
const scope = context.sourceCode.getScope(node);
|
|
11791
|
-
if (node.left.type ===
|
|
11881
|
+
if (node.left.type === import_utils61.AST_NODE_TYPES.Identifier) {
|
|
11792
11882
|
const variable = findVariable2(scope, node.left.name);
|
|
11793
11883
|
if (variable === null) return;
|
|
11794
11884
|
const isLocalText = (candidate) => localFileTextRef(candidate, scope) !== null;
|
|
@@ -11802,7 +11892,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11802
11892
|
}
|
|
11803
11893
|
return;
|
|
11804
11894
|
}
|
|
11805
|
-
if (node.left.type ===
|
|
11895
|
+
if (node.left.type === import_utils61.AST_NODE_TYPES.ObjectPattern || node.left.type === import_utils61.AST_NODE_TYPES.ArrayPattern) {
|
|
11806
11896
|
if (isRawPayloadSource(
|
|
11807
11897
|
node.right,
|
|
11808
11898
|
(candidate) => localFileTextRef(candidate, scope) !== null
|
|
@@ -11822,15 +11912,15 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11822
11912
|
}
|
|
11823
11913
|
},
|
|
11824
11914
|
CallExpression(node) {
|
|
11825
|
-
if (node.callee.type !==
|
|
11915
|
+
if (node.callee.type !== import_utils61.AST_NODE_TYPES.Identifier) return;
|
|
11826
11916
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
11827
11917
|
return;
|
|
11828
11918
|
}
|
|
11829
11919
|
const scope = context.sourceCode.getScope(node);
|
|
11830
11920
|
for (const arg of node.arguments) {
|
|
11831
|
-
if (arg.type ===
|
|
11921
|
+
if (arg.type === import_utils61.AST_NODE_TYPES.SpreadElement) continue;
|
|
11832
11922
|
const unwrapped = unwrap4(arg);
|
|
11833
|
-
if (unwrapped === null || unwrapped.type !==
|
|
11923
|
+
if (unwrapped === null || unwrapped.type !== import_utils61.AST_NODE_TYPES.Identifier) {
|
|
11834
11924
|
continue;
|
|
11835
11925
|
}
|
|
11836
11926
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -11847,14 +11937,14 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11847
11937
|
(candidate) => localFileTextRef(candidate, scope) !== null
|
|
11848
11938
|
)) {
|
|
11849
11939
|
const parent = node.parent;
|
|
11850
|
-
if (parent.type ===
|
|
11940
|
+
if (parent.type === import_utils61.AST_NODE_TYPES.CallExpression && parent.callee === node && node.property.type === import_utils61.AST_NODE_TYPES.Identifier && (node.property.name === "parse" || node.property.name === "safeParse" || PROMISE_CHAIN_METHODS.has(node.property.name))) {
|
|
11851
11941
|
return;
|
|
11852
11942
|
}
|
|
11853
11943
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
11854
11944
|
return;
|
|
11855
11945
|
}
|
|
11856
|
-
const variable = obj?.type ===
|
|
11857
|
-
if (variable !== null && obj?.type ===
|
|
11946
|
+
const variable = obj?.type === import_utils61.AST_NODE_TYPES.Identifier ? unvalidatedVariableRef(obj, scope, unvalidatedVariables) : null;
|
|
11947
|
+
if (variable !== null && obj?.type === import_utils61.AST_NODE_TYPES.Identifier) {
|
|
11858
11948
|
if (isUseWithinValidatedBranch(node, obj.name)) {
|
|
11859
11949
|
return;
|
|
11860
11950
|
}
|
|
@@ -11874,7 +11964,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11874
11964
|
});
|
|
11875
11965
|
|
|
11876
11966
|
// src/rules/prefer-semantic-colors.ts
|
|
11877
|
-
var
|
|
11967
|
+
var import_utils62 = require("@typescript-eslint/utils");
|
|
11878
11968
|
var import_fs = require("fs");
|
|
11879
11969
|
var import_path = require("path");
|
|
11880
11970
|
|
|
@@ -11986,7 +12076,7 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
11986
12076
|
var isInsideSvg = (node) => {
|
|
11987
12077
|
let current = node.parent;
|
|
11988
12078
|
while (current !== void 0 && current !== null) {
|
|
11989
|
-
if (current.type ===
|
|
12079
|
+
if (current.type === import_utils62.AST_NODE_TYPES.JSXElement) {
|
|
11990
12080
|
const name = jsxElementName(current);
|
|
11991
12081
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
11992
12082
|
}
|
|
@@ -11996,8 +12086,8 @@ var isInsideSvg = (node) => {
|
|
|
11996
12086
|
};
|
|
11997
12087
|
function jsxElementName(node) {
|
|
11998
12088
|
const name = node.openingElement.name;
|
|
11999
|
-
if (name.type ===
|
|
12000
|
-
if (name.type ===
|
|
12089
|
+
if (name.type === import_utils62.AST_NODE_TYPES.JSXIdentifier) return name.name;
|
|
12090
|
+
if (name.type === import_utils62.AST_NODE_TYPES.JSXMemberExpression && name.property.type === import_utils62.AST_NODE_TYPES.JSXIdentifier) {
|
|
12001
12091
|
return name.property.name;
|
|
12002
12092
|
}
|
|
12003
12093
|
return null;
|
|
@@ -12023,7 +12113,7 @@ function isSvgLikeElementName(name) {
|
|
|
12023
12113
|
var isInsideIconFactoryPath = (node) => {
|
|
12024
12114
|
let current = node.parent;
|
|
12025
12115
|
while (current !== void 0 && current !== null) {
|
|
12026
|
-
if (current.type ===
|
|
12116
|
+
if (current.type === import_utils62.AST_NODE_TYPES.Property && propName(current.key) === "path" && current.parent.type === import_utils62.AST_NODE_TYPES.ObjectExpression && current.parent.parent.type === import_utils62.AST_NODE_TYPES.CallExpression && current.parent.parent.callee.type === import_utils62.AST_NODE_TYPES.Identifier && current.parent.parent.callee.name === "createIcon") {
|
|
12027
12117
|
return true;
|
|
12028
12118
|
}
|
|
12029
12119
|
current = current.parent;
|
|
@@ -12157,12 +12247,12 @@ var expandWorkspaceGlob = (root, glob) => {
|
|
|
12157
12247
|
return (0, import_fs.readdirSync)(parent, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => (0, import_path.join)(parent, entry.name));
|
|
12158
12248
|
};
|
|
12159
12249
|
var propName = (key) => {
|
|
12160
|
-
if (key.type ===
|
|
12161
|
-
if (key.type ===
|
|
12250
|
+
if (key.type === import_utils62.AST_NODE_TYPES.Identifier) return key.name;
|
|
12251
|
+
if (key.type === import_utils62.AST_NODE_TYPES.Literal && typeof key.value === "string") return key.value;
|
|
12162
12252
|
return null;
|
|
12163
12253
|
};
|
|
12164
12254
|
var staticallyImportsEmailOrPdfRenderer = (program) => program.body.some((statement) => {
|
|
12165
|
-
if (statement.type !==
|
|
12255
|
+
if (statement.type !== import_utils62.AST_NODE_TYPES.ImportDeclaration && statement.type !== import_utils62.AST_NODE_TYPES.ExportNamedDeclaration && statement.type !== import_utils62.AST_NODE_TYPES.ExportAllDeclaration) {
|
|
12166
12256
|
return false;
|
|
12167
12257
|
}
|
|
12168
12258
|
return statement.source !== null && typeof statement.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(statement.source.value);
|
|
@@ -12215,27 +12305,27 @@ var prefer_semantic_colors_default = createRule({
|
|
|
12215
12305
|
const checkClassNode = (node) => {
|
|
12216
12306
|
if (node === null) return;
|
|
12217
12307
|
switch (node.type) {
|
|
12218
|
-
case
|
|
12308
|
+
case import_utils62.AST_NODE_TYPES.Literal:
|
|
12219
12309
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
12220
12310
|
break;
|
|
12221
|
-
case
|
|
12311
|
+
case import_utils62.AST_NODE_TYPES.TemplateLiteral:
|
|
12222
12312
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
12223
12313
|
break;
|
|
12224
|
-
case
|
|
12314
|
+
case import_utils62.AST_NODE_TYPES.ArrayExpression:
|
|
12225
12315
|
for (const element of node.elements) {
|
|
12226
|
-
if (element !== null && element.type !==
|
|
12316
|
+
if (element !== null && element.type !== import_utils62.AST_NODE_TYPES.SpreadElement) checkClassNode(element);
|
|
12227
12317
|
}
|
|
12228
12318
|
break;
|
|
12229
|
-
case
|
|
12319
|
+
case import_utils62.AST_NODE_TYPES.ObjectExpression:
|
|
12230
12320
|
for (const property of node.properties) {
|
|
12231
|
-
if (property.type ===
|
|
12321
|
+
if (property.type === import_utils62.AST_NODE_TYPES.Property) checkClassNode(property.value);
|
|
12232
12322
|
}
|
|
12233
12323
|
break;
|
|
12234
|
-
case
|
|
12324
|
+
case import_utils62.AST_NODE_TYPES.ConditionalExpression:
|
|
12235
12325
|
checkClassNode(node.consequent);
|
|
12236
12326
|
checkClassNode(node.alternate);
|
|
12237
12327
|
break;
|
|
12238
|
-
case
|
|
12328
|
+
case import_utils62.AST_NODE_TYPES.LogicalExpression:
|
|
12239
12329
|
checkClassNode(node.right);
|
|
12240
12330
|
break;
|
|
12241
12331
|
default:
|
|
@@ -12243,32 +12333,32 @@ var prefer_semantic_colors_default = createRule({
|
|
|
12243
12333
|
}
|
|
12244
12334
|
};
|
|
12245
12335
|
const checkColorValueNode = (node) => {
|
|
12246
|
-
if (node.type ===
|
|
12336
|
+
if (node.type === import_utils62.AST_NODE_TYPES.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value) && !CSS_VAR_REFERENCE_RE.test(node.value)) {
|
|
12247
12337
|
report(node, "inlineColor", { value: node.value });
|
|
12248
12338
|
}
|
|
12249
12339
|
};
|
|
12250
12340
|
return {
|
|
12251
12341
|
"JSXAttribute[name.name='className']"(node) {
|
|
12252
12342
|
if (node.value === null) return;
|
|
12253
|
-
if (node.value.type ===
|
|
12254
|
-
else if (node.value.type ===
|
|
12255
|
-
if (node.value.expression.type !==
|
|
12343
|
+
if (node.value.type === import_utils62.AST_NODE_TYPES.Literal) checkClassNode(node.value);
|
|
12344
|
+
else if (node.value.type === import_utils62.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
12345
|
+
if (node.value.expression.type !== import_utils62.AST_NODE_TYPES.JSXEmptyExpression) {
|
|
12256
12346
|
checkClassNode(node.value.expression);
|
|
12257
12347
|
}
|
|
12258
12348
|
}
|
|
12259
12349
|
},
|
|
12260
12350
|
CallExpression(node) {
|
|
12261
|
-
if (node.callee.type ===
|
|
12351
|
+
if (node.callee.type === import_utils62.AST_NODE_TYPES.Identifier && node.callee.name === "require" && node.arguments[0]?.type === import_utils62.AST_NODE_TYPES.Literal && typeof node.arguments[0].value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.arguments[0].value)) {
|
|
12262
12352
|
importsEmailOrPdfRenderer = true;
|
|
12263
12353
|
}
|
|
12264
|
-
if (node.callee.type ===
|
|
12354
|
+
if (node.callee.type === import_utils62.AST_NODE_TYPES.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
12265
12355
|
for (const arg of node.arguments) {
|
|
12266
|
-
if (arg.type !==
|
|
12356
|
+
if (arg.type !== import_utils62.AST_NODE_TYPES.SpreadElement) checkClassNode(arg);
|
|
12267
12357
|
}
|
|
12268
12358
|
}
|
|
12269
12359
|
},
|
|
12270
12360
|
VariableDeclarator(node) {
|
|
12271
|
-
if (node.id.type ===
|
|
12361
|
+
if (node.id.type === import_utils62.AST_NODE_TYPES.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
12272
12362
|
checkClassNode(node.init);
|
|
12273
12363
|
}
|
|
12274
12364
|
},
|
|
@@ -12278,9 +12368,9 @@ var prefer_semantic_colors_default = createRule({
|
|
|
12278
12368
|
},
|
|
12279
12369
|
// SVG artwork colors are exempt; component presentation colors still report.
|
|
12280
12370
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
12281
|
-
if (node.value?.type !==
|
|
12371
|
+
if (node.value?.type !== import_utils62.AST_NODE_TYPES.Literal) return;
|
|
12282
12372
|
const owner = node.parent.name;
|
|
12283
|
-
if (owner.type ===
|
|
12373
|
+
if (owner.type === import_utils62.AST_NODE_TYPES.JSXIdentifier && SVG_SHAPE_PRIMITIVES.has(owner.name)) {
|
|
12284
12374
|
return;
|
|
12285
12375
|
}
|
|
12286
12376
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
@@ -12294,7 +12384,7 @@ var prefer_semantic_colors_default = createRule({
|
|
|
12294
12384
|
if (name !== null && STYLE_COLOR_PROPS.has(name)) checkColorValueNode(node.value);
|
|
12295
12385
|
},
|
|
12296
12386
|
ImportExpression(node) {
|
|
12297
|
-
if (node.source.type ===
|
|
12387
|
+
if (node.source.type === import_utils62.AST_NODE_TYPES.Literal && typeof node.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.source.value)) {
|
|
12298
12388
|
importsEmailOrPdfRenderer = true;
|
|
12299
12389
|
}
|
|
12300
12390
|
},
|
|
@@ -12307,7 +12397,7 @@ var prefer_semantic_colors_default = createRule({
|
|
|
12307
12397
|
});
|
|
12308
12398
|
|
|
12309
12399
|
// src/rules/prefer-server-actions.ts
|
|
12310
|
-
var
|
|
12400
|
+
var import_utils63 = require("@typescript-eslint/utils");
|
|
12311
12401
|
var preferServerActionsDocumentation = {
|
|
12312
12402
|
summary: "Prefer Next.js Server Actions over /api/* mutations.",
|
|
12313
12403
|
rationale: "Server Actions preserve typed application calls and avoid an internal JSON request-response boundary.",
|
|
@@ -12496,7 +12586,7 @@ var prefer_server_actions_default = createRule({
|
|
|
12496
12586
|
});
|
|
12497
12587
|
|
|
12498
12588
|
// src/rules/prefer-whole-object-assertion.ts
|
|
12499
|
-
var
|
|
12589
|
+
var import_utils64 = require("@typescript-eslint/utils");
|
|
12500
12590
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
12501
12591
|
var SYNTHETIC_LITERAL_MATCHERS = /* @__PURE__ */ new Map([
|
|
12502
12592
|
["toBeNull", "null"],
|
|
@@ -12521,11 +12611,11 @@ var preferWholeObjectAssertionDocumentation = {
|
|
|
12521
12611
|
};
|
|
12522
12612
|
function literalText(node, getText) {
|
|
12523
12613
|
switch (node.type) {
|
|
12524
|
-
case
|
|
12614
|
+
case import_utils64.AST_NODE_TYPES.Literal:
|
|
12525
12615
|
return "regex" in node ? null : getText(node);
|
|
12526
|
-
case
|
|
12616
|
+
case import_utils64.AST_NODE_TYPES.TemplateLiteral:
|
|
12527
12617
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
12528
|
-
case
|
|
12618
|
+
case import_utils64.AST_NODE_TYPES.UnaryExpression:
|
|
12529
12619
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
12530
12620
|
default:
|
|
12531
12621
|
return null;
|
|
@@ -12533,15 +12623,15 @@ function literalText(node, getText) {
|
|
|
12533
12623
|
}
|
|
12534
12624
|
function isPureReceiver(node) {
|
|
12535
12625
|
switch (node.type) {
|
|
12536
|
-
case
|
|
12537
|
-
case
|
|
12626
|
+
case import_utils64.AST_NODE_TYPES.Identifier:
|
|
12627
|
+
case import_utils64.AST_NODE_TYPES.ThisExpression:
|
|
12538
12628
|
return true;
|
|
12539
|
-
case
|
|
12629
|
+
case import_utils64.AST_NODE_TYPES.MemberExpression:
|
|
12540
12630
|
if (node.optional) {
|
|
12541
12631
|
return false;
|
|
12542
12632
|
}
|
|
12543
12633
|
if (node.computed) {
|
|
12544
|
-
return node.property.type ===
|
|
12634
|
+
return node.property.type === import_utils64.AST_NODE_TYPES.Literal && isPureReceiver(node.object);
|
|
12545
12635
|
}
|
|
12546
12636
|
return isPureReceiver(node.object);
|
|
12547
12637
|
default:
|
|
@@ -12549,7 +12639,7 @@ function isPureReceiver(node) {
|
|
|
12549
12639
|
}
|
|
12550
12640
|
}
|
|
12551
12641
|
function literalIndex(node) {
|
|
12552
|
-
if (node.type !==
|
|
12642
|
+
if (node.type !== import_utils64.AST_NODE_TYPES.Literal || typeof node.value !== "number") {
|
|
12553
12643
|
return null;
|
|
12554
12644
|
}
|
|
12555
12645
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
@@ -12557,8 +12647,8 @@ function literalIndex(node) {
|
|
|
12557
12647
|
function propertyAccess(node) {
|
|
12558
12648
|
const path = [];
|
|
12559
12649
|
let current = node;
|
|
12560
|
-
while (current.type ===
|
|
12561
|
-
if (current.property.type !==
|
|
12650
|
+
while (current.type === import_utils64.AST_NODE_TYPES.MemberExpression && !current.computed && !current.optional) {
|
|
12651
|
+
if (current.property.type !== import_utils64.AST_NODE_TYPES.Identifier || COLLECTION_PROPERTIES.has(current.property.name) || LITERAL_KEY_HAZARDS.has(current.property.name)) return null;
|
|
12562
12652
|
path.unshift(current.property.name);
|
|
12563
12653
|
current = current.object;
|
|
12564
12654
|
}
|
|
@@ -12586,24 +12676,24 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
12586
12676
|
}
|
|
12587
12677
|
const { sourceCode } = context;
|
|
12588
12678
|
function parseAssertion(statement) {
|
|
12589
|
-
if (statement.type !==
|
|
12679
|
+
if (statement.type !== import_utils64.AST_NODE_TYPES.ExpressionStatement) {
|
|
12590
12680
|
return null;
|
|
12591
12681
|
}
|
|
12592
12682
|
const call = statement.expression;
|
|
12593
|
-
if (call.type !==
|
|
12683
|
+
if (call.type !== import_utils64.AST_NODE_TYPES.CallExpression) {
|
|
12594
12684
|
return null;
|
|
12595
12685
|
}
|
|
12596
12686
|
const callee = call.callee;
|
|
12597
|
-
if (callee.type !==
|
|
12687
|
+
if (callee.type !== import_utils64.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils64.AST_NODE_TYPES.Identifier) {
|
|
12598
12688
|
return null;
|
|
12599
12689
|
}
|
|
12600
12690
|
const matcher = callee.property.name;
|
|
12601
12691
|
const expectCall = callee.object;
|
|
12602
|
-
if (expectCall.type !==
|
|
12692
|
+
if (expectCall.type !== import_utils64.AST_NODE_TYPES.CallExpression || expectCall.callee.type !== import_utils64.AST_NODE_TYPES.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
12603
12693
|
return null;
|
|
12604
12694
|
}
|
|
12605
12695
|
const actual = expectCall.arguments[0];
|
|
12606
|
-
if (actual === void 0 || actual.type !==
|
|
12696
|
+
if (actual === void 0 || actual.type !== import_utils64.AST_NODE_TYPES.MemberExpression || actual.optional) {
|
|
12607
12697
|
return null;
|
|
12608
12698
|
}
|
|
12609
12699
|
if (!isPureReceiver(actual.object)) {
|
|
@@ -12632,7 +12722,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
12632
12722
|
return null;
|
|
12633
12723
|
}
|
|
12634
12724
|
const expected = call.arguments[0];
|
|
12635
|
-
if (call.arguments.length !== 1 || expected === void 0 || expected.type ===
|
|
12725
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === import_utils64.AST_NODE_TYPES.SpreadElement) {
|
|
12636
12726
|
return null;
|
|
12637
12727
|
}
|
|
12638
12728
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
@@ -12773,7 +12863,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
12773
12863
|
});
|
|
12774
12864
|
|
|
12775
12865
|
// src/rules/repeated-static-call-cases.ts
|
|
12776
|
-
var
|
|
12866
|
+
var import_utils65 = require("@typescript-eslint/utils");
|
|
12777
12867
|
var repeatedStaticCallCasesDocumentation = {
|
|
12778
12868
|
summary: "Report three or more consecutive literal call assertions that should be independently named test cases.",
|
|
12779
12869
|
rationale: "Copy-pasted cases obscure the input table and stop later cases from being reported after the first failure.",
|
|
@@ -12794,67 +12884,67 @@ var EXPECT_MODIFIERS = /* @__PURE__ */ new Set(["not", "rejects", "resolves"]);
|
|
|
12794
12884
|
var SNAPSHOT_MATCHERS = /snapshot/iu;
|
|
12795
12885
|
var MIN_CASES2 = 3;
|
|
12796
12886
|
function staticMemberName5(node) {
|
|
12797
|
-
if (!node.computed && node.property.type ===
|
|
12798
|
-
if (node.computed && node.property.type ===
|
|
12887
|
+
if (!node.computed && node.property.type === import_utils65.AST_NODE_TYPES.Identifier) return node.property.name;
|
|
12888
|
+
if (node.computed && node.property.type === import_utils65.AST_NODE_TYPES.Literal && typeof node.property.value === "string") return node.property.value;
|
|
12799
12889
|
return null;
|
|
12800
12890
|
}
|
|
12801
12891
|
function importedName3(identifier, context, modules) {
|
|
12802
|
-
const variable =
|
|
12892
|
+
const variable = import_utils65.ASTUtils.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
12803
12893
|
if (variable === null || variable.defs.length === 0) return identifier.name;
|
|
12804
12894
|
for (const definition of variable.defs) {
|
|
12805
|
-
if (definition.node.type !==
|
|
12895
|
+
if (definition.node.type !== import_utils65.AST_NODE_TYPES.ImportSpecifier) continue;
|
|
12806
12896
|
const declaration = definition.node.parent;
|
|
12807
|
-
if (declaration.type !==
|
|
12897
|
+
if (declaration.type !== import_utils65.AST_NODE_TYPES.ImportDeclaration || typeof declaration.source.value !== "string" || !modules.has(declaration.source.value)) continue;
|
|
12808
12898
|
const imported = definition.node.imported;
|
|
12809
|
-
return imported.type ===
|
|
12899
|
+
return imported.type === import_utils65.AST_NODE_TYPES.Identifier ? imported.name : String(imported.value);
|
|
12810
12900
|
}
|
|
12811
12901
|
return null;
|
|
12812
12902
|
}
|
|
12813
12903
|
function isDirectTestCallback2(node, context) {
|
|
12814
|
-
if (node.type !==
|
|
12904
|
+
if (node.type !== import_utils65.AST_NODE_TYPES.ArrowFunctionExpression && node.type !== import_utils65.AST_NODE_TYPES.FunctionExpression) return false;
|
|
12815
12905
|
const call = node.parent;
|
|
12816
|
-
if (call?.type !==
|
|
12906
|
+
if (call?.type !== import_utils65.AST_NODE_TYPES.CallExpression || !call.arguments.includes(node)) return false;
|
|
12817
12907
|
const root = testRoot2(call.callee);
|
|
12818
12908
|
return root !== null && TEST_NAMES2.has(importedName3(root, context, TEST_MODULES4) ?? "");
|
|
12819
12909
|
}
|
|
12820
12910
|
function testRoot2(callee) {
|
|
12821
|
-
if (callee.type ===
|
|
12822
|
-
if (callee.type !==
|
|
12911
|
+
if (callee.type === import_utils65.AST_NODE_TYPES.Identifier) return callee;
|
|
12912
|
+
if (callee.type !== import_utils65.AST_NODE_TYPES.MemberExpression) return null;
|
|
12823
12913
|
const modifier = staticMemberName5(callee);
|
|
12824
12914
|
return modifier !== null && TEST_MODIFIERS4.has(modifier) ? testRoot2(callee.object) : null;
|
|
12825
12915
|
}
|
|
12826
12916
|
function isStatic(node) {
|
|
12827
|
-
if (node.type ===
|
|
12917
|
+
if (node.type === import_utils65.AST_NODE_TYPES.TSAsExpression || node.type === import_utils65.AST_NODE_TYPES.TSTypeAssertion || node.type === import_utils65.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils65.AST_NODE_TYPES.TSNonNullExpression) return isStatic(node.expression);
|
|
12828
12918
|
switch (node.type) {
|
|
12829
|
-
case
|
|
12919
|
+
case import_utils65.AST_NODE_TYPES.Literal:
|
|
12830
12920
|
return true;
|
|
12831
|
-
case
|
|
12921
|
+
case import_utils65.AST_NODE_TYPES.TemplateLiteral:
|
|
12832
12922
|
return node.expressions.length === 0;
|
|
12833
|
-
case
|
|
12923
|
+
case import_utils65.AST_NODE_TYPES.UnaryExpression:
|
|
12834
12924
|
return (node.operator === "+" || node.operator === "-") && isStatic(node.argument);
|
|
12835
|
-
case
|
|
12836
|
-
return node.elements.every((item) => item !== null && item.type !==
|
|
12837
|
-
case
|
|
12838
|
-
return node.properties.every((property) => property.type ===
|
|
12925
|
+
case import_utils65.AST_NODE_TYPES.ArrayExpression:
|
|
12926
|
+
return node.elements.every((item) => item !== null && item.type !== import_utils65.AST_NODE_TYPES.SpreadElement && isStatic(item));
|
|
12927
|
+
case import_utils65.AST_NODE_TYPES.ObjectExpression:
|
|
12928
|
+
return node.properties.every((property) => property.type === import_utils65.AST_NODE_TYPES.Property && !property.computed && property.kind === "init" && property.value.type !== import_utils65.AST_NODE_TYPES.AssignmentPattern && isStatic(property.value));
|
|
12839
12929
|
default:
|
|
12840
12930
|
return false;
|
|
12841
12931
|
}
|
|
12842
12932
|
}
|
|
12843
12933
|
function staticShape(node) {
|
|
12844
|
-
if (node.type ===
|
|
12934
|
+
if (node.type === import_utils65.AST_NODE_TYPES.TSAsExpression || node.type === import_utils65.AST_NODE_TYPES.TSTypeAssertion || node.type === import_utils65.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils65.AST_NODE_TYPES.TSNonNullExpression) return staticShape(node.expression);
|
|
12845
12935
|
switch (node.type) {
|
|
12846
|
-
case
|
|
12936
|
+
case import_utils65.AST_NODE_TYPES.Literal:
|
|
12847
12937
|
return `literal:${typeof node.value}`;
|
|
12848
|
-
case
|
|
12938
|
+
case import_utils65.AST_NODE_TYPES.TemplateLiteral:
|
|
12849
12939
|
return "template";
|
|
12850
|
-
case
|
|
12940
|
+
case import_utils65.AST_NODE_TYPES.UnaryExpression:
|
|
12851
12941
|
return `unary:${node.operator}:${staticShape(node.argument)}`;
|
|
12852
|
-
case
|
|
12853
|
-
return `array(${node.elements.map((item) => item === null || item.type ===
|
|
12854
|
-
case
|
|
12942
|
+
case import_utils65.AST_NODE_TYPES.ArrayExpression:
|
|
12943
|
+
return `array(${node.elements.map((item) => item === null || item.type === import_utils65.AST_NODE_TYPES.SpreadElement ? "invalid" : staticShape(item)).join(",")})`;
|
|
12944
|
+
case import_utils65.AST_NODE_TYPES.ObjectExpression:
|
|
12855
12945
|
return `object(${node.properties.map((property) => {
|
|
12856
|
-
if (property.type !==
|
|
12857
|
-
const key = property.key.type ===
|
|
12946
|
+
if (property.type !== import_utils65.AST_NODE_TYPES.Property || property.computed || property.value.type === import_utils65.AST_NODE_TYPES.AssignmentPattern) return "invalid";
|
|
12947
|
+
const key = property.key.type === import_utils65.AST_NODE_TYPES.Identifier ? property.key.name : String(property.key.value);
|
|
12858
12948
|
return `${key}:${staticShape(property.value)}`;
|
|
12859
12949
|
}).join(",")})`;
|
|
12860
12950
|
default:
|
|
@@ -12862,16 +12952,16 @@ function staticShape(node) {
|
|
|
12862
12952
|
}
|
|
12863
12953
|
}
|
|
12864
12954
|
function assertionShape(statement, context) {
|
|
12865
|
-
if (statement.type !==
|
|
12955
|
+
if (statement.type !== import_utils65.AST_NODE_TYPES.ExpressionStatement || statement.expression.type !== import_utils65.AST_NODE_TYPES.CallExpression) return null;
|
|
12866
12956
|
const matcherCall = statement.expression;
|
|
12867
|
-
if (matcherCall.callee.type !==
|
|
12957
|
+
if (matcherCall.callee.type !== import_utils65.AST_NODE_TYPES.MemberExpression || matcherCall.callee.computed || matcherCall.callee.property.type !== import_utils65.AST_NODE_TYPES.Identifier || matcherCall.arguments.length !== 1) return null;
|
|
12868
12958
|
const matcher = matcherCall.callee.property.name;
|
|
12869
12959
|
if (SNAPSHOT_MATCHERS.test(matcher)) return null;
|
|
12870
12960
|
const chain = expectCallFromMatcher(matcherCall.callee);
|
|
12871
|
-
if (chain === null || chain.call.callee.type !==
|
|
12961
|
+
if (chain === null || chain.call.callee.type !== import_utils65.AST_NODE_TYPES.Identifier || importedName3(chain.call.callee, context, ASSERTION_MODULES3) !== "expect" || chain.call.arguments.length !== 1) return null;
|
|
12872
12962
|
const observed = chain.call.arguments[0];
|
|
12873
12963
|
const expected = matcherCall.arguments[0];
|
|
12874
|
-
if (observed?.type !==
|
|
12964
|
+
if (observed?.type !== import_utils65.AST_NODE_TYPES.CallExpression || observed.callee.type !== import_utils65.AST_NODE_TYPES.Identifier || observed.arguments.length === 0 || observed.arguments.some((arg) => arg.type === import_utils65.AST_NODE_TYPES.SpreadElement || !isStatic(arg)) || expected?.type === import_utils65.AST_NODE_TYPES.SpreadElement || expected === void 0 || !isStatic(expected)) return null;
|
|
12875
12965
|
const skeleton = `${observed.callee.name}/${observed.arguments.map((item) => staticShape(item)).join(",")}/${chain.modifiers.join(".")}/${matcher}/${staticShape(expected)}`;
|
|
12876
12966
|
const values = [...observed.arguments, expected].map((item) => context.sourceCode.getText(item)).join("\0");
|
|
12877
12967
|
return { statement, skeleton, values };
|
|
@@ -12879,13 +12969,13 @@ function assertionShape(statement, context) {
|
|
|
12879
12969
|
function expectCallFromMatcher(node) {
|
|
12880
12970
|
const modifiers = [];
|
|
12881
12971
|
let receiver = node.object;
|
|
12882
|
-
while (receiver.type ===
|
|
12972
|
+
while (receiver.type === import_utils65.AST_NODE_TYPES.MemberExpression) {
|
|
12883
12973
|
const modifier = staticMemberName5(receiver);
|
|
12884
12974
|
if (modifier === null || !EXPECT_MODIFIERS.has(modifier)) return null;
|
|
12885
12975
|
modifiers.unshift(modifier);
|
|
12886
12976
|
receiver = receiver.object;
|
|
12887
12977
|
}
|
|
12888
|
-
return receiver.type ===
|
|
12978
|
+
return receiver.type === import_utils65.AST_NODE_TYPES.CallExpression ? { call: receiver, modifiers } : null;
|
|
12889
12979
|
}
|
|
12890
12980
|
var repeated_static_call_cases_default = createRule({
|
|
12891
12981
|
name: "repeated-static-call-cases",
|
|
@@ -12905,7 +12995,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
12905
12995
|
return {
|
|
12906
12996
|
"CallExpression > ArrowFunctionExpression, CallExpression > FunctionExpression"(node) {
|
|
12907
12997
|
const call = node.parent;
|
|
12908
|
-
if (call?.type ===
|
|
12998
|
+
if (call?.type === import_utils65.AST_NODE_TYPES.CallExpression) {
|
|
12909
12999
|
const duplicate = duplicateTestBodyCandidate(call, sourceCode);
|
|
12910
13000
|
if (duplicate !== null && duplicate.body === node) {
|
|
12911
13001
|
const groups = duplicateGroups.get(duplicate.container) ?? /* @__PURE__ */ new Map();
|
|
@@ -12915,7 +13005,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
12915
13005
|
duplicateGroups.set(duplicate.container, groups);
|
|
12916
13006
|
}
|
|
12917
13007
|
}
|
|
12918
|
-
if (!isDirectTestCallback2(node, context) || node.body.type !==
|
|
13008
|
+
if (!isDirectTestCallback2(node, context) || node.body.type !== import_utils65.AST_NODE_TYPES.BlockStatement) return;
|
|
12919
13009
|
let run = [];
|
|
12920
13010
|
const flush = () => {
|
|
12921
13011
|
if (run.length >= MIN_CASES2 && new Set(run.map((item) => item.values)).size > 1) {
|
|
@@ -12956,7 +13046,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
12956
13046
|
});
|
|
12957
13047
|
|
|
12958
13048
|
// src/rules/prefer-zod-infer.ts
|
|
12959
|
-
var
|
|
13049
|
+
var import_utils66 = require("@typescript-eslint/utils");
|
|
12960
13050
|
var preferZodInferDocumentation = {
|
|
12961
13051
|
summary: "Derive a type from its Zod schema with `z.infer` instead of hand-writing a twin declaration beside it.",
|
|
12962
13052
|
rationale: "A derived type stays synchronized when the runtime schema changes.",
|
|
@@ -13009,47 +13099,47 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
13009
13099
|
"Schema"
|
|
13010
13100
|
]);
|
|
13011
13101
|
var LEAF_NODE_TYPES = {
|
|
13012
|
-
string: [
|
|
13013
|
-
email: [
|
|
13014
|
-
url: [
|
|
13015
|
-
uuid: [
|
|
13016
|
-
ulid: [
|
|
13017
|
-
cuid: [
|
|
13018
|
-
cuid2: [
|
|
13019
|
-
nanoid: [
|
|
13020
|
-
iso: [
|
|
13021
|
-
number: [
|
|
13022
|
-
int: [
|
|
13023
|
-
float32: [
|
|
13024
|
-
float64: [
|
|
13025
|
-
boolean: [
|
|
13026
|
-
bigint: [
|
|
13027
|
-
symbol: [
|
|
13028
|
-
any: [
|
|
13029
|
-
unknown: [
|
|
13030
|
-
never: [
|
|
13031
|
-
void: [
|
|
13032
|
-
null: [
|
|
13033
|
-
undefined: [
|
|
13034
|
-
literal: [
|
|
13035
|
-
date: [
|
|
13036
|
-
array: [
|
|
13037
|
-
tuple: [
|
|
13038
|
-
object: [
|
|
13039
|
-
strictObject: [
|
|
13040
|
-
looseObject: [
|
|
13041
|
-
record: [
|
|
13042
|
-
map: [
|
|
13043
|
-
set: [
|
|
13044
|
-
promise: [
|
|
13045
|
-
enum: [
|
|
13046
|
-
nativeEnum: [
|
|
13047
|
-
union: [
|
|
13048
|
-
discriminatedUnion: [
|
|
13049
|
-
intersection: [
|
|
13102
|
+
string: [import_utils66.AST_NODE_TYPES.TSStringKeyword],
|
|
13103
|
+
email: [import_utils66.AST_NODE_TYPES.TSStringKeyword],
|
|
13104
|
+
url: [import_utils66.AST_NODE_TYPES.TSStringKeyword],
|
|
13105
|
+
uuid: [import_utils66.AST_NODE_TYPES.TSStringKeyword],
|
|
13106
|
+
ulid: [import_utils66.AST_NODE_TYPES.TSStringKeyword],
|
|
13107
|
+
cuid: [import_utils66.AST_NODE_TYPES.TSStringKeyword],
|
|
13108
|
+
cuid2: [import_utils66.AST_NODE_TYPES.TSStringKeyword],
|
|
13109
|
+
nanoid: [import_utils66.AST_NODE_TYPES.TSStringKeyword],
|
|
13110
|
+
iso: [import_utils66.AST_NODE_TYPES.TSStringKeyword],
|
|
13111
|
+
number: [import_utils66.AST_NODE_TYPES.TSNumberKeyword],
|
|
13112
|
+
int: [import_utils66.AST_NODE_TYPES.TSNumberKeyword],
|
|
13113
|
+
float32: [import_utils66.AST_NODE_TYPES.TSNumberKeyword],
|
|
13114
|
+
float64: [import_utils66.AST_NODE_TYPES.TSNumberKeyword],
|
|
13115
|
+
boolean: [import_utils66.AST_NODE_TYPES.TSBooleanKeyword],
|
|
13116
|
+
bigint: [import_utils66.AST_NODE_TYPES.TSBigIntKeyword],
|
|
13117
|
+
symbol: [import_utils66.AST_NODE_TYPES.TSSymbolKeyword],
|
|
13118
|
+
any: [import_utils66.AST_NODE_TYPES.TSAnyKeyword],
|
|
13119
|
+
unknown: [import_utils66.AST_NODE_TYPES.TSUnknownKeyword],
|
|
13120
|
+
never: [import_utils66.AST_NODE_TYPES.TSNeverKeyword],
|
|
13121
|
+
void: [import_utils66.AST_NODE_TYPES.TSVoidKeyword],
|
|
13122
|
+
null: [import_utils66.AST_NODE_TYPES.TSNullKeyword],
|
|
13123
|
+
undefined: [import_utils66.AST_NODE_TYPES.TSUndefinedKeyword],
|
|
13124
|
+
literal: [import_utils66.AST_NODE_TYPES.TSLiteralType],
|
|
13125
|
+
date: [import_utils66.AST_NODE_TYPES.TSTypeReference],
|
|
13126
|
+
array: [import_utils66.AST_NODE_TYPES.TSArrayType, import_utils66.AST_NODE_TYPES.TSTypeReference],
|
|
13127
|
+
tuple: [import_utils66.AST_NODE_TYPES.TSTupleType],
|
|
13128
|
+
object: [import_utils66.AST_NODE_TYPES.TSTypeLiteral, import_utils66.AST_NODE_TYPES.TSTypeReference],
|
|
13129
|
+
strictObject: [import_utils66.AST_NODE_TYPES.TSTypeLiteral, import_utils66.AST_NODE_TYPES.TSTypeReference],
|
|
13130
|
+
looseObject: [import_utils66.AST_NODE_TYPES.TSTypeLiteral, import_utils66.AST_NODE_TYPES.TSTypeReference],
|
|
13131
|
+
record: [import_utils66.AST_NODE_TYPES.TSTypeReference, import_utils66.AST_NODE_TYPES.TSTypeLiteral],
|
|
13132
|
+
map: [import_utils66.AST_NODE_TYPES.TSTypeReference],
|
|
13133
|
+
set: [import_utils66.AST_NODE_TYPES.TSTypeReference],
|
|
13134
|
+
promise: [import_utils66.AST_NODE_TYPES.TSTypeReference],
|
|
13135
|
+
enum: [import_utils66.AST_NODE_TYPES.TSUnionType, import_utils66.AST_NODE_TYPES.TSTypeReference, import_utils66.AST_NODE_TYPES.TSLiteralType],
|
|
13136
|
+
nativeEnum: [import_utils66.AST_NODE_TYPES.TSUnionType, import_utils66.AST_NODE_TYPES.TSTypeReference, import_utils66.AST_NODE_TYPES.TSLiteralType],
|
|
13137
|
+
union: [import_utils66.AST_NODE_TYPES.TSUnionType, import_utils66.AST_NODE_TYPES.TSTypeReference],
|
|
13138
|
+
discriminatedUnion: [import_utils66.AST_NODE_TYPES.TSUnionType, import_utils66.AST_NODE_TYPES.TSTypeReference],
|
|
13139
|
+
intersection: [import_utils66.AST_NODE_TYPES.TSIntersectionType, import_utils66.AST_NODE_TYPES.TSTypeReference]
|
|
13050
13140
|
};
|
|
13051
13141
|
function primitiveLiteralKey(node) {
|
|
13052
|
-
if (node.type !==
|
|
13142
|
+
if (node.type !== import_utils66.AST_NODE_TYPES.Literal) {
|
|
13053
13143
|
return null;
|
|
13054
13144
|
}
|
|
13055
13145
|
if (node.value === null) {
|
|
@@ -13081,13 +13171,13 @@ function staticZodDomain(leaf, call) {
|
|
|
13081
13171
|
}
|
|
13082
13172
|
if (leaf === "literal") {
|
|
13083
13173
|
const [argument] = call.arguments;
|
|
13084
|
-
if (argument === void 0 || argument.type ===
|
|
13174
|
+
if (argument === void 0 || argument.type === import_utils66.AST_NODE_TYPES.SpreadElement) {
|
|
13085
13175
|
return null;
|
|
13086
13176
|
}
|
|
13087
|
-
if (argument.type ===
|
|
13177
|
+
if (argument.type === import_utils66.AST_NODE_TYPES.ArrayExpression) {
|
|
13088
13178
|
return exactDomain(
|
|
13089
13179
|
argument.elements.map(
|
|
13090
|
-
(element) => element === null || element.type ===
|
|
13180
|
+
(element) => element === null || element.type === import_utils66.AST_NODE_TYPES.SpreadElement ? null : primitiveLiteralKey(element)
|
|
13091
13181
|
)
|
|
13092
13182
|
);
|
|
13093
13183
|
}
|
|
@@ -13095,13 +13185,13 @@ function staticZodDomain(leaf, call) {
|
|
|
13095
13185
|
}
|
|
13096
13186
|
if (leaf === "enum") {
|
|
13097
13187
|
const [argument] = call.arguments;
|
|
13098
|
-
if (argument === void 0 || argument.type ===
|
|
13188
|
+
if (argument === void 0 || argument.type === import_utils66.AST_NODE_TYPES.SpreadElement) {
|
|
13099
13189
|
return null;
|
|
13100
13190
|
}
|
|
13101
|
-
if (argument.type ===
|
|
13191
|
+
if (argument.type === import_utils66.AST_NODE_TYPES.ArrayExpression) {
|
|
13102
13192
|
return exactDomain(
|
|
13103
13193
|
argument.elements.map((element) => {
|
|
13104
|
-
if (element === null || element.type ===
|
|
13194
|
+
if (element === null || element.type === import_utils66.AST_NODE_TYPES.SpreadElement) {
|
|
13105
13195
|
return null;
|
|
13106
13196
|
}
|
|
13107
13197
|
const key = primitiveLiteralKey(element);
|
|
@@ -13109,10 +13199,10 @@ function staticZodDomain(leaf, call) {
|
|
|
13109
13199
|
})
|
|
13110
13200
|
);
|
|
13111
13201
|
}
|
|
13112
|
-
if (argument.type ===
|
|
13202
|
+
if (argument.type === import_utils66.AST_NODE_TYPES.ObjectExpression) {
|
|
13113
13203
|
return exactDomain(
|
|
13114
13204
|
argument.properties.map((property) => {
|
|
13115
|
-
if (property.type !==
|
|
13205
|
+
if (property.type !== import_utils66.AST_NODE_TYPES.Property || property.computed || property.kind !== "init" || property.method || property.shorthand) {
|
|
13116
13206
|
return null;
|
|
13117
13207
|
}
|
|
13118
13208
|
const key = primitiveLiteralKey(property.value);
|
|
@@ -13139,15 +13229,15 @@ function sameDomain(left, right) {
|
|
|
13139
13229
|
return true;
|
|
13140
13230
|
}
|
|
13141
13231
|
function isExportedDeclaration(node) {
|
|
13142
|
-
return node.parent?.type ===
|
|
13232
|
+
return node.parent?.type === import_utils66.AST_NODE_TYPES.ExportNamedDeclaration;
|
|
13143
13233
|
}
|
|
13144
13234
|
function isModuleLevelConst(node) {
|
|
13145
13235
|
const declaration = node.parent;
|
|
13146
|
-
if (declaration.type !==
|
|
13236
|
+
if (declaration.type !== import_utils66.AST_NODE_TYPES.VariableDeclaration || declaration.kind !== "const") {
|
|
13147
13237
|
return false;
|
|
13148
13238
|
}
|
|
13149
13239
|
const container = declaration.parent;
|
|
13150
|
-
return container.type ===
|
|
13240
|
+
return container.type === import_utils66.AST_NODE_TYPES.Program || container.type === import_utils66.AST_NODE_TYPES.ExportNamedDeclaration && container.parent.type === import_utils66.AST_NODE_TYPES.Program;
|
|
13151
13241
|
}
|
|
13152
13242
|
function normalizeSchemaName(name) {
|
|
13153
13243
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -13156,20 +13246,20 @@ function normalizeTypeName(name) {
|
|
|
13156
13246
|
return name.replace(/Type$/, "").toLowerCase();
|
|
13157
13247
|
}
|
|
13158
13248
|
function unwrapNullish(annotation) {
|
|
13159
|
-
if (annotation.type !==
|
|
13249
|
+
if (annotation.type !== import_utils66.AST_NODE_TYPES.TSUnionType) {
|
|
13160
13250
|
return {
|
|
13161
13251
|
core: annotation,
|
|
13162
|
-
nullable: annotation.type ===
|
|
13252
|
+
nullable: annotation.type === import_utils66.AST_NODE_TYPES.TSNullKeyword
|
|
13163
13253
|
};
|
|
13164
13254
|
}
|
|
13165
13255
|
const rest = [];
|
|
13166
13256
|
let nullable = false;
|
|
13167
13257
|
for (const member of annotation.types) {
|
|
13168
|
-
if (member.type ===
|
|
13258
|
+
if (member.type === import_utils66.AST_NODE_TYPES.TSNullKeyword) {
|
|
13169
13259
|
nullable = true;
|
|
13170
13260
|
continue;
|
|
13171
13261
|
}
|
|
13172
|
-
if (member.type ===
|
|
13262
|
+
if (member.type === import_utils66.AST_NODE_TYPES.TSUndefinedKeyword) {
|
|
13173
13263
|
continue;
|
|
13174
13264
|
}
|
|
13175
13265
|
rest.push(member);
|
|
@@ -13203,18 +13293,18 @@ function leafAgrees(field, annotation) {
|
|
|
13203
13293
|
return null;
|
|
13204
13294
|
}
|
|
13205
13295
|
if (leaf === "date") {
|
|
13206
|
-
return core.type ===
|
|
13296
|
+
return core.type === import_utils66.AST_NODE_TYPES.TSTypeReference && core.typeName.type === import_utils66.AST_NODE_TYPES.Identifier && core.typeName.name === "Date";
|
|
13207
13297
|
}
|
|
13208
13298
|
return expected.includes(core.type);
|
|
13209
13299
|
}
|
|
13210
13300
|
function typeLiteralDomain(annotation) {
|
|
13211
|
-
const members = annotation.type ===
|
|
13301
|
+
const members = annotation.type === import_utils66.AST_NODE_TYPES.TSUnionType ? annotation.types : [annotation];
|
|
13212
13302
|
const keys = [];
|
|
13213
13303
|
for (const member of members) {
|
|
13214
|
-
if (member.type ===
|
|
13304
|
+
if (member.type === import_utils66.AST_NODE_TYPES.TSNullKeyword) {
|
|
13215
13305
|
continue;
|
|
13216
13306
|
}
|
|
13217
|
-
if (member.type !==
|
|
13307
|
+
if (member.type !== import_utils66.AST_NODE_TYPES.TSLiteralType) {
|
|
13218
13308
|
return null;
|
|
13219
13309
|
}
|
|
13220
13310
|
keys.push(primitiveLiteralKey(member.literal));
|
|
@@ -13222,11 +13312,11 @@ function typeLiteralDomain(annotation) {
|
|
|
13222
13312
|
return exactDomain(keys);
|
|
13223
13313
|
}
|
|
13224
13314
|
function staticStringUnionDomain(node) {
|
|
13225
|
-
if (node.type !==
|
|
13315
|
+
if (node.type !== import_utils66.AST_NODE_TYPES.TSUnionType) {
|
|
13226
13316
|
return null;
|
|
13227
13317
|
}
|
|
13228
13318
|
const keys = node.types.map((member) => {
|
|
13229
|
-
if (member.type !==
|
|
13319
|
+
if (member.type !== import_utils66.AST_NODE_TYPES.TSLiteralType) {
|
|
13230
13320
|
return null;
|
|
13231
13321
|
}
|
|
13232
13322
|
const key = primitiveLiteralKey(member.literal);
|
|
@@ -13294,14 +13384,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
13294
13384
|
function zodCallChain(node) {
|
|
13295
13385
|
const chain = [];
|
|
13296
13386
|
let current = node;
|
|
13297
|
-
while (current.type ===
|
|
13387
|
+
while (current.type === import_utils66.AST_NODE_TYPES.CallExpression) {
|
|
13298
13388
|
const callee = current.callee;
|
|
13299
|
-
if (callee.type !==
|
|
13389
|
+
if (callee.type !== import_utils66.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils66.AST_NODE_TYPES.Identifier) {
|
|
13300
13390
|
return null;
|
|
13301
13391
|
}
|
|
13302
13392
|
chain.push(current);
|
|
13303
13393
|
const receiver = callee.object;
|
|
13304
|
-
if (receiver.type ===
|
|
13394
|
+
if (receiver.type === import_utils66.AST_NODE_TYPES.Identifier) {
|
|
13305
13395
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
13306
13396
|
}
|
|
13307
13397
|
current = receiver;
|
|
@@ -13310,14 +13400,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
13310
13400
|
}
|
|
13311
13401
|
function methodName2(call) {
|
|
13312
13402
|
const callee = call.callee;
|
|
13313
|
-
return callee.type ===
|
|
13403
|
+
return callee.type === import_utils66.AST_NODE_TYPES.MemberExpression && callee.property.type === import_utils66.AST_NODE_TYPES.Identifier ? callee.property.name : "";
|
|
13314
13404
|
}
|
|
13315
13405
|
function recordZodImport(node) {
|
|
13316
13406
|
if (!isZodModule(node.source.value)) {
|
|
13317
13407
|
return;
|
|
13318
13408
|
}
|
|
13319
13409
|
for (const specifier of node.specifiers) {
|
|
13320
|
-
if (specifier.type ===
|
|
13410
|
+
if (specifier.type === import_utils66.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils66.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils66.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils66.AST_NODE_TYPES.Identifier && specifier.imported.name === "z") {
|
|
13321
13411
|
zodNamespaces.add(specifier.local.name);
|
|
13322
13412
|
}
|
|
13323
13413
|
}
|
|
@@ -13327,13 +13417,13 @@ var prefer_zod_infer_default = createRule({
|
|
|
13327
13417
|
let current = node;
|
|
13328
13418
|
let leaf = null;
|
|
13329
13419
|
let leafCall = null;
|
|
13330
|
-
while (current.type ===
|
|
13420
|
+
while (current.type === import_utils66.AST_NODE_TYPES.CallExpression) {
|
|
13331
13421
|
const callee = current.callee;
|
|
13332
|
-
if (callee.type !==
|
|
13422
|
+
if (callee.type !== import_utils66.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils66.AST_NODE_TYPES.Identifier) {
|
|
13333
13423
|
break;
|
|
13334
13424
|
}
|
|
13335
13425
|
const receiver = callee.object;
|
|
13336
|
-
if (receiver.type ===
|
|
13426
|
+
if (receiver.type === import_utils66.AST_NODE_TYPES.Identifier && zodNamespaces.has(receiver.name)) {
|
|
13337
13427
|
leaf = callee.property.name;
|
|
13338
13428
|
leafCall = current;
|
|
13339
13429
|
break;
|
|
@@ -13364,20 +13454,20 @@ var prefer_zod_infer_default = createRule({
|
|
|
13364
13454
|
return domain instanceof Set && domain.size >= 2 ? domain : null;
|
|
13365
13455
|
}
|
|
13366
13456
|
function inferredSchemaName(node) {
|
|
13367
|
-
if (node.type !==
|
|
13457
|
+
if (node.type !== import_utils66.AST_NODE_TYPES.TSTypeReference || node.typeName.type !== import_utils66.AST_NODE_TYPES.TSQualifiedName || node.typeName.left.type !== import_utils66.AST_NODE_TYPES.Identifier || !zodNamespaces.has(node.typeName.left.name) || node.typeName.right.name !== "infer") {
|
|
13368
13458
|
return null;
|
|
13369
13459
|
}
|
|
13370
13460
|
const arguments_ = node.typeArguments?.params ?? [];
|
|
13371
13461
|
const [argument] = arguments_;
|
|
13372
|
-
return arguments_.length === 1 && argument?.type ===
|
|
13462
|
+
return arguments_.length === 1 && argument?.type === import_utils66.AST_NODE_TYPES.TSTypeQuery && argument.exprName.type === import_utils66.AST_NODE_TYPES.Identifier ? argument.exprName.name : null;
|
|
13373
13463
|
}
|
|
13374
13464
|
function recordLiteralUnions(members, owner, ownerName, exported) {
|
|
13375
13465
|
for (const member of members) {
|
|
13376
|
-
if (member.type !==
|
|
13466
|
+
if (member.type !== import_utils66.AST_NODE_TYPES.TSPropertySignature || member.computed || member.optional || member.readonly || member.typeAnnotation === void 0) {
|
|
13377
13467
|
continue;
|
|
13378
13468
|
}
|
|
13379
13469
|
const key = member.key;
|
|
13380
|
-
const propertyName3 = key.type ===
|
|
13470
|
+
const propertyName3 = key.type === import_utils66.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils66.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
13381
13471
|
if (propertyName3 === null) {
|
|
13382
13472
|
continue;
|
|
13383
13473
|
}
|
|
@@ -13387,7 +13477,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
13387
13477
|
}
|
|
13388
13478
|
const annotation = member.typeAnnotation.typeAnnotation;
|
|
13389
13479
|
const domain = staticStringUnionDomain(annotation);
|
|
13390
|
-
if (domain === null || annotation.type !==
|
|
13480
|
+
if (domain === null || annotation.type !== import_utils66.AST_NODE_TYPES.TSUnionType) {
|
|
13391
13481
|
continue;
|
|
13392
13482
|
}
|
|
13393
13483
|
literalUnionOccurrences.push({
|
|
@@ -13418,16 +13508,16 @@ var prefer_zod_infer_default = createRule({
|
|
|
13418
13508
|
return null;
|
|
13419
13509
|
}
|
|
13420
13510
|
const shape = base.arguments[0];
|
|
13421
|
-
if (shape === void 0 || shape.type !==
|
|
13511
|
+
if (shape === void 0 || shape.type !== import_utils66.AST_NODE_TYPES.ObjectExpression) {
|
|
13422
13512
|
return null;
|
|
13423
13513
|
}
|
|
13424
13514
|
const fields = /* @__PURE__ */ new Map();
|
|
13425
13515
|
for (const property of shape.properties) {
|
|
13426
|
-
if (property.type !==
|
|
13516
|
+
if (property.type !== import_utils66.AST_NODE_TYPES.Property || property.computed) {
|
|
13427
13517
|
return null;
|
|
13428
13518
|
}
|
|
13429
13519
|
const { key } = property;
|
|
13430
|
-
const name = key.type ===
|
|
13520
|
+
const name = key.type === import_utils66.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils66.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
13431
13521
|
if (name === null) {
|
|
13432
13522
|
return null;
|
|
13433
13523
|
}
|
|
@@ -13438,11 +13528,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
13438
13528
|
function typeMembers(members) {
|
|
13439
13529
|
const result = /* @__PURE__ */ new Map();
|
|
13440
13530
|
for (const member of members) {
|
|
13441
|
-
if (member.type !==
|
|
13531
|
+
if (member.type !== import_utils66.AST_NODE_TYPES.TSPropertySignature || member.computed) {
|
|
13442
13532
|
return null;
|
|
13443
13533
|
}
|
|
13444
13534
|
const { key } = member;
|
|
13445
|
-
const name = key.type ===
|
|
13535
|
+
const name = key.type === import_utils66.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils66.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
13446
13536
|
if (name === null) {
|
|
13447
13537
|
return null;
|
|
13448
13538
|
}
|
|
@@ -13457,8 +13547,8 @@ var prefer_zod_infer_default = createRule({
|
|
|
13457
13547
|
return result.size === 0 ? null : result;
|
|
13458
13548
|
}
|
|
13459
13549
|
function collectConstrainedNames(node) {
|
|
13460
|
-
if (node.type ===
|
|
13461
|
-
if (node.typeName.type ===
|
|
13550
|
+
if (node.type === import_utils66.AST_NODE_TYPES.TSTypeReference) {
|
|
13551
|
+
if (node.typeName.type === import_utils66.AST_NODE_TYPES.Identifier) {
|
|
13462
13552
|
constrainedTypeNames.add(node.typeName.name);
|
|
13463
13553
|
}
|
|
13464
13554
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -13466,11 +13556,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
13466
13556
|
}
|
|
13467
13557
|
return;
|
|
13468
13558
|
}
|
|
13469
|
-
if (node.type ===
|
|
13559
|
+
if (node.type === import_utils66.AST_NODE_TYPES.TSArrayType) {
|
|
13470
13560
|
collectConstrainedNames(node.elementType);
|
|
13471
13561
|
return;
|
|
13472
13562
|
}
|
|
13473
|
-
if (node.type ===
|
|
13563
|
+
if (node.type === import_utils66.AST_NODE_TYPES.TSUnionType || node.type === import_utils66.AST_NODE_TYPES.TSIntersectionType) {
|
|
13474
13564
|
for (const member of node.types) {
|
|
13475
13565
|
collectConstrainedNames(member);
|
|
13476
13566
|
}
|
|
@@ -13514,7 +13604,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
13514
13604
|
return {
|
|
13515
13605
|
Program(node) {
|
|
13516
13606
|
for (const statement of node.body) {
|
|
13517
|
-
if (statement.type ===
|
|
13607
|
+
if (statement.type === import_utils66.AST_NODE_TYPES.ImportDeclaration) {
|
|
13518
13608
|
recordZodImport(statement);
|
|
13519
13609
|
}
|
|
13520
13610
|
}
|
|
@@ -13523,7 +13613,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
13523
13613
|
recordZodImport(node);
|
|
13524
13614
|
},
|
|
13525
13615
|
VariableDeclarator(node) {
|
|
13526
|
-
if (node.id.type !==
|
|
13616
|
+
if (node.id.type !== import_utils66.AST_NODE_TYPES.Identifier || node.init == null) {
|
|
13527
13617
|
return;
|
|
13528
13618
|
}
|
|
13529
13619
|
const fields = schemaFields(node.init);
|
|
@@ -13540,14 +13630,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
13540
13630
|
},
|
|
13541
13631
|
/** Records `XSchema.transform(...)` and equivalent module-level reshaping. */
|
|
13542
13632
|
"MemberExpression[computed=false]"(node) {
|
|
13543
|
-
if (node.object.type ===
|
|
13633
|
+
if (node.object.type === import_utils66.AST_NODE_TYPES.Identifier && node.property.type === import_utils66.AST_NODE_TYPES.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
13544
13634
|
reshapedSchemaNames.add(node.object.name);
|
|
13545
13635
|
}
|
|
13546
13636
|
},
|
|
13547
13637
|
/** Records every type argument carried by a Zod constraint. */
|
|
13548
13638
|
TSTypeReference(node) {
|
|
13549
13639
|
const { typeName } = node;
|
|
13550
|
-
const referenced = typeName.type ===
|
|
13640
|
+
const referenced = typeName.type === import_utils66.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils66.AST_NODE_TYPES.TSQualifiedName && typeName.right.type === import_utils66.AST_NODE_TYPES.Identifier ? typeName.right.name : null;
|
|
13551
13641
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
13552
13642
|
return;
|
|
13553
13643
|
}
|
|
@@ -13579,7 +13669,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
13579
13669
|
typeName: node.id.name
|
|
13580
13670
|
});
|
|
13581
13671
|
}
|
|
13582
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
13672
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== import_utils66.AST_NODE_TYPES.TSTypeLiteral) {
|
|
13583
13673
|
return;
|
|
13584
13674
|
}
|
|
13585
13675
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -13678,7 +13768,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
13678
13768
|
});
|
|
13679
13769
|
|
|
13680
13770
|
// src/rules/require-assert-never.ts
|
|
13681
|
-
var
|
|
13771
|
+
var import_utils67 = require("@typescript-eslint/utils");
|
|
13682
13772
|
var import_typescript = __toESM(require("typescript"), 1);
|
|
13683
13773
|
var requireAssertNeverDocumentation = {
|
|
13684
13774
|
summary: "Require an empty switch default to call `assertNever` so discriminated unions remain exhaustive at compile time.",
|
|
@@ -13691,14 +13781,14 @@ var requireAssertNeverDocumentation = {
|
|
|
13691
13781
|
]
|
|
13692
13782
|
};
|
|
13693
13783
|
var isRuntimeHandlingStatement = (statement) => {
|
|
13694
|
-
if (statement.type ===
|
|
13695
|
-
if (statement.type ===
|
|
13784
|
+
if (statement.type === import_utils67.AST_NODE_TYPES.EmptyStatement) return false;
|
|
13785
|
+
if (statement.type === import_utils67.AST_NODE_TYPES.BreakStatement) {
|
|
13696
13786
|
return statement.label !== null;
|
|
13697
13787
|
}
|
|
13698
|
-
if (statement.type ===
|
|
13788
|
+
if (statement.type === import_utils67.AST_NODE_TYPES.TSTypeAliasDeclaration || statement.type === import_utils67.AST_NODE_TYPES.TSInterfaceDeclaration) {
|
|
13699
13789
|
return false;
|
|
13700
13790
|
}
|
|
13701
|
-
if (statement.type ===
|
|
13791
|
+
if (statement.type === import_utils67.AST_NODE_TYPES.BlockStatement) {
|
|
13702
13792
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
13703
13793
|
}
|
|
13704
13794
|
return true;
|
|
@@ -13714,7 +13804,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
13714
13804
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
13715
13805
|
}
|
|
13716
13806
|
const only = defaultCase.consequent[0];
|
|
13717
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
13807
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === import_utils67.AST_NODE_TYPES.BlockStatement && !only.body.some(isRuntimeHandlingStatement)) {
|
|
13718
13808
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
13719
13809
|
}
|
|
13720
13810
|
return false;
|
|
@@ -13770,7 +13860,7 @@ var require_assert_never_default = createRule({
|
|
|
13770
13860
|
create(context) {
|
|
13771
13861
|
let services;
|
|
13772
13862
|
try {
|
|
13773
|
-
services =
|
|
13863
|
+
services = import_utils67.ESLintUtils.getParserServices(context);
|
|
13774
13864
|
} catch {
|
|
13775
13865
|
services = null;
|
|
13776
13866
|
}
|
|
@@ -13797,7 +13887,7 @@ var require_assert_never_default = createRule({
|
|
|
13797
13887
|
});
|
|
13798
13888
|
|
|
13799
13889
|
// src/rules/require-fetch-timeout.ts
|
|
13800
|
-
var
|
|
13890
|
+
var import_utils68 = require("@typescript-eslint/utils");
|
|
13801
13891
|
var requireFetchTimeoutDocumentation = {
|
|
13802
13892
|
summary: "Require an abort `signal` (e.g. `AbortSignal.timeout(ms)`) on global `fetch()` calls so stalled upstreams cannot hang the caller forever.",
|
|
13803
13893
|
rationale: "An unbounded request can occupy work indefinitely when an upstream stalls.",
|
|
@@ -13823,14 +13913,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
13823
13913
|
return false;
|
|
13824
13914
|
}
|
|
13825
13915
|
function initProvablyLacksSignal(init) {
|
|
13826
|
-
if (init.type !==
|
|
13916
|
+
if (init.type !== import_utils68.AST_NODE_TYPES.ObjectExpression) {
|
|
13827
13917
|
return false;
|
|
13828
13918
|
}
|
|
13829
13919
|
for (const prop of init.properties) {
|
|
13830
|
-
if (prop.type ===
|
|
13920
|
+
if (prop.type === import_utils68.AST_NODE_TYPES.SpreadElement) {
|
|
13831
13921
|
return false;
|
|
13832
13922
|
}
|
|
13833
|
-
if (prop.key.type ===
|
|
13923
|
+
if (prop.key.type === import_utils68.AST_NODE_TYPES.Identifier && prop.key.name === "signal" || prop.key.type === import_utils68.AST_NODE_TYPES.Literal && prop.key.value === "signal") {
|
|
13834
13924
|
return false;
|
|
13835
13925
|
}
|
|
13836
13926
|
if (prop.computed) {
|
|
@@ -13840,7 +13930,7 @@ function initProvablyLacksSignal(init) {
|
|
|
13840
13930
|
return true;
|
|
13841
13931
|
}
|
|
13842
13932
|
function isInlineUrl(node, resolvesToGlobal) {
|
|
13843
|
-
return node.type ===
|
|
13933
|
+
return node.type === import_utils68.AST_NODE_TYPES.Literal && typeof node.value === "string" || node.type === import_utils68.AST_NODE_TYPES.TemplateLiteral || node.type === import_utils68.AST_NODE_TYPES.NewExpression && node.callee.type === import_utils68.AST_NODE_TYPES.Identifier && node.callee.name === "URL" && resolvesToGlobal(node.callee);
|
|
13844
13934
|
}
|
|
13845
13935
|
var require_fetch_timeout_default = createRule({
|
|
13846
13936
|
name: "require-fetch-timeout",
|
|
@@ -13878,30 +13968,30 @@ var require_fetch_timeout_default = createRule({
|
|
|
13878
13968
|
}
|
|
13879
13969
|
function resolvesToGlobal(identifier) {
|
|
13880
13970
|
const scope = context.sourceCode.getScope(identifier);
|
|
13881
|
-
const variable =
|
|
13971
|
+
const variable = import_utils68.ASTUtils.findVariable(scope, identifier.name);
|
|
13882
13972
|
return variable === null || variable.defs.length === 0;
|
|
13883
13973
|
}
|
|
13884
13974
|
function isGlobalFetchCall2(callee) {
|
|
13885
|
-
if (callee.type ===
|
|
13975
|
+
if (callee.type === import_utils68.AST_NODE_TYPES.Identifier) {
|
|
13886
13976
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
13887
13977
|
}
|
|
13888
|
-
return callee.type ===
|
|
13978
|
+
return callee.type === import_utils68.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils68.AST_NODE_TYPES.Identifier && callee.property.name === "fetch" && callee.object.type === import_utils68.AST_NODE_TYPES.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
13889
13979
|
}
|
|
13890
13980
|
function localConstInitProvablyLacksSignal(identifier) {
|
|
13891
|
-
const variable =
|
|
13981
|
+
const variable = import_utils68.ASTUtils.findVariable(
|
|
13892
13982
|
context.sourceCode.getScope(identifier),
|
|
13893
13983
|
identifier.name
|
|
13894
13984
|
);
|
|
13895
13985
|
if (variable?.defs.length !== 1) return false;
|
|
13896
13986
|
const definition = variable.defs[0];
|
|
13897
|
-
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !==
|
|
13987
|
+
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !== import_utils68.AST_NODE_TYPES.ObjectExpression || !initProvablyLacksSignal(definition.node.init)) {
|
|
13898
13988
|
return false;
|
|
13899
13989
|
}
|
|
13900
13990
|
for (const reference of variable.references) {
|
|
13901
13991
|
const ref = reference.identifier;
|
|
13902
13992
|
if (ref === identifier || ref === definition.name) continue;
|
|
13903
13993
|
const member = ref.parent;
|
|
13904
|
-
if (member.type !==
|
|
13994
|
+
if (member.type !== import_utils68.AST_NODE_TYPES.MemberExpression || member.object !== ref || member.computed || member.property.type !== import_utils68.AST_NODE_TYPES.Identifier || member.property.name === "signal" || member.parent.type !== import_utils68.AST_NODE_TYPES.AssignmentExpression || member.parent.left !== member) {
|
|
13905
13995
|
return false;
|
|
13906
13996
|
}
|
|
13907
13997
|
}
|
|
@@ -13916,7 +14006,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
13916
14006
|
if (node.arguments.length === 1 && first !== void 0 && !isInlineUrl(first, resolvesToGlobal)) {
|
|
13917
14007
|
return;
|
|
13918
14008
|
}
|
|
13919
|
-
if (init === void 0 || initProvablyLacksSignal(init) || init.type ===
|
|
14009
|
+
if (init === void 0 || initProvablyLacksSignal(init) || init.type === import_utils68.AST_NODE_TYPES.Identifier && localConstInitProvablyLacksSignal(init)) {
|
|
13920
14010
|
context.report({ node, messageId: "missingSignal" });
|
|
13921
14011
|
}
|
|
13922
14012
|
}
|
|
@@ -13925,7 +14015,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
13925
14015
|
});
|
|
13926
14016
|
|
|
13927
14017
|
// src/rules/require-port-for-service.ts
|
|
13928
|
-
var
|
|
14018
|
+
var import_utils69 = require("@typescript-eslint/utils");
|
|
13929
14019
|
var requirePortForServiceDocumentation = {
|
|
13930
14020
|
summary: "Advise when an exported service with injected collaborators has public methods not covered by its declared ports.",
|
|
13931
14021
|
rationale: "A declared port keeps consumers coupled to the service capability instead of its concrete implementation.",
|
|
@@ -13950,45 +14040,45 @@ var ROUTER_FACTORY_NAME = "Router";
|
|
|
13950
14040
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
13951
14041
|
var STORAGE_ASSIGNMENT_OPERATORS = /* @__PURE__ */ new Set(["=", "&&=", "??=", "||="]);
|
|
13952
14042
|
var staticMemberName6 = (member) => {
|
|
13953
|
-
if (member.property.type ===
|
|
13954
|
-
if (!member.computed && member.property.type ===
|
|
13955
|
-
return member.computed && member.property.type ===
|
|
14043
|
+
if (member.property.type === import_utils69.AST_NODE_TYPES.PrivateIdentifier) return `#${member.property.name}`;
|
|
14044
|
+
if (!member.computed && member.property.type === import_utils69.AST_NODE_TYPES.Identifier) return member.property.name;
|
|
14045
|
+
return member.computed && member.property.type === import_utils69.AST_NODE_TYPES.Literal && typeof member.property.value === "string" ? member.property.value : null;
|
|
13956
14046
|
};
|
|
13957
14047
|
var detachedValueExports = (program) => {
|
|
13958
14048
|
const names = /* @__PURE__ */ new Set();
|
|
13959
14049
|
for (const statement of program.body) {
|
|
13960
|
-
if (statement.type ===
|
|
14050
|
+
if (statement.type === import_utils69.AST_NODE_TYPES.ExportNamedDeclaration && statement.declaration === null && statement.source === null && statement.exportKind !== "type") {
|
|
13961
14051
|
for (const specifier of statement.specifiers) {
|
|
13962
14052
|
if (specifier.exportKind !== "type") names.add(specifier.local.name);
|
|
13963
14053
|
}
|
|
13964
|
-
} else if (statement.type ===
|
|
14054
|
+
} else if (statement.type === import_utils69.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils69.AST_NODE_TYPES.Identifier) {
|
|
13965
14055
|
names.add(statement.declaration.name);
|
|
13966
|
-
} else if (statement.type ===
|
|
14056
|
+
} else if (statement.type === import_utils69.AST_NODE_TYPES.TSExportAssignment && statement.expression.type === import_utils69.AST_NODE_TYPES.Identifier) {
|
|
13967
14057
|
names.add(statement.expression.name);
|
|
13968
14058
|
}
|
|
13969
14059
|
}
|
|
13970
14060
|
return names;
|
|
13971
14061
|
};
|
|
13972
|
-
var isExportedClass2 = (node, detached) => node.parent.type ===
|
|
14062
|
+
var isExportedClass2 = (node, detached) => node.parent.type === import_utils69.AST_NODE_TYPES.ExportNamedDeclaration || node.parent.type === import_utils69.AST_NODE_TYPES.ExportDefaultDeclaration || node.id !== null && detached.has(node.id.name);
|
|
13973
14063
|
var readTypeReference = (annotation) => {
|
|
13974
|
-
if (annotation?.type ===
|
|
14064
|
+
if (annotation?.type === import_utils69.AST_NODE_TYPES.TSUnionType) {
|
|
13975
14065
|
const members = annotation.types.filter(
|
|
13976
|
-
(member) => member.type !==
|
|
14066
|
+
(member) => member.type !== import_utils69.AST_NODE_TYPES.TSUndefinedKeyword && member.type !== import_utils69.AST_NODE_TYPES.TSNullKeyword
|
|
13977
14067
|
);
|
|
13978
14068
|
annotation = members.length === 1 ? members[0] : void 0;
|
|
13979
14069
|
}
|
|
13980
|
-
if (annotation === void 0 || annotation.type !==
|
|
14070
|
+
if (annotation === void 0 || annotation.type !== import_utils69.AST_NODE_TYPES.TSTypeReference) return null;
|
|
13981
14071
|
const { typeName } = annotation;
|
|
13982
|
-
const rightmost = typeName.type ===
|
|
14072
|
+
const rightmost = typeName.type === import_utils69.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils69.AST_NODE_TYPES.TSQualifiedName ? typeName.right.name : null;
|
|
13983
14073
|
if (rightmost === null) return null;
|
|
13984
14074
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
13985
14075
|
};
|
|
13986
|
-
var qualifiedName = (name) => name.type ===
|
|
14076
|
+
var qualifiedName = (name) => name.type === import_utils69.AST_NODE_TYPES.Identifier ? name.name : name.type === import_utils69.AST_NODE_TYPES.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
13987
14077
|
var propertySignatureTypes = (members) => {
|
|
13988
14078
|
const types = /* @__PURE__ */ new Map();
|
|
13989
14079
|
for (const member of members) {
|
|
13990
|
-
if (member.type !==
|
|
13991
|
-
if (member.computed || member.key.type !==
|
|
14080
|
+
if (member.type !== import_utils69.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
14081
|
+
if (member.computed || member.key.type !== import_utils69.AST_NODE_TYPES.Identifier) continue;
|
|
13992
14082
|
const reference = readTypeReference(member.typeAnnotation?.typeAnnotation);
|
|
13993
14083
|
if (reference === null) continue;
|
|
13994
14084
|
types.set(member.key.name, reference);
|
|
@@ -13999,18 +14089,18 @@ var fileTypeIndex = (program) => {
|
|
|
13999
14089
|
const objects = /* @__PURE__ */ new Map();
|
|
14000
14090
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
14001
14091
|
for (const statement of program.body) {
|
|
14002
|
-
const declaration = statement.type ===
|
|
14003
|
-
if (declaration?.type ===
|
|
14092
|
+
const declaration = statement.type === import_utils69.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
14093
|
+
if (declaration?.type === import_utils69.AST_NODE_TYPES.TSInterfaceDeclaration) {
|
|
14004
14094
|
objects.set(declaration.id.name, propertySignatureTypes(declaration.body.body));
|
|
14005
14095
|
continue;
|
|
14006
14096
|
}
|
|
14007
|
-
if (declaration?.type !==
|
|
14097
|
+
if (declaration?.type !== import_utils69.AST_NODE_TYPES.TSTypeAliasDeclaration) continue;
|
|
14008
14098
|
const aliased = declaration.typeAnnotation;
|
|
14009
|
-
if (aliased.type ===
|
|
14099
|
+
if (aliased.type === import_utils69.AST_NODE_TYPES.TSFunctionType || aliased.type === import_utils69.AST_NODE_TYPES.TSConstructorType) {
|
|
14010
14100
|
functionAliases.add(declaration.id.name);
|
|
14011
14101
|
continue;
|
|
14012
14102
|
}
|
|
14013
|
-
const literals = aliased.type ===
|
|
14103
|
+
const literals = aliased.type === import_utils69.AST_NODE_TYPES.TSTypeLiteral ? [aliased] : aliased.type === import_utils69.AST_NODE_TYPES.TSIntersectionType ? aliased.types.filter((part) => part.type === import_utils69.AST_NODE_TYPES.TSTypeLiteral) : [];
|
|
14014
14104
|
if (literals.length === 0) continue;
|
|
14015
14105
|
const merged = /* @__PURE__ */ new Map();
|
|
14016
14106
|
for (const literal of literals) {
|
|
@@ -14038,10 +14128,10 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
14038
14128
|
while (pending.length > 0) {
|
|
14039
14129
|
const current = pending.pop();
|
|
14040
14130
|
if (current === void 0) break;
|
|
14041
|
-
if (current.type ===
|
|
14042
|
-
const expression = current.type ===
|
|
14043
|
-
const storedField = expression?.type ===
|
|
14044
|
-
if (expression?.type !==
|
|
14131
|
+
if (current.type === import_utils69.AST_NODE_TYPES.ArrowFunctionExpression || current.type === import_utils69.AST_NODE_TYPES.FunctionExpression || current.type === import_utils69.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils69.AST_NODE_TYPES.ClassExpression || current.type === import_utils69.AST_NODE_TYPES.ClassDeclaration) continue;
|
|
14132
|
+
const expression = current.type === import_utils69.AST_NODE_TYPES.ExpressionStatement ? current.expression : null;
|
|
14133
|
+
const storedField = expression?.type === import_utils69.AST_NODE_TYPES.AssignmentExpression && expression.left.type === import_utils69.AST_NODE_TYPES.MemberExpression && expression.left.object.type === import_utils69.AST_NODE_TYPES.ThisExpression ? staticMemberName6(expression.left) : null;
|
|
14134
|
+
if (expression?.type !== import_utils69.AST_NODE_TYPES.AssignmentExpression || !STORAGE_ASSIGNMENT_OPERATORS.has(expression.operator) || expression.left.type !== import_utils69.AST_NODE_TYPES.MemberExpression || expression.left.object.type !== import_utils69.AST_NODE_TYPES.ThisExpression || storedField === null) {
|
|
14045
14135
|
for (const key of Object.keys(current)) {
|
|
14046
14136
|
if (key === "parent") continue;
|
|
14047
14137
|
const value = current[key];
|
|
@@ -14054,14 +14144,14 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
14054
14144
|
continue;
|
|
14055
14145
|
}
|
|
14056
14146
|
let source = expression.right;
|
|
14057
|
-
while (source.type ===
|
|
14058
|
-
if (source.type ===
|
|
14147
|
+
while (source.type === import_utils69.AST_NODE_TYPES.TSNonNullExpression || source.type === import_utils69.AST_NODE_TYPES.TSAsExpression || source.type === import_utils69.AST_NODE_TYPES.TSSatisfiesExpression || source.type === import_utils69.AST_NODE_TYPES.TSTypeAssertion) source = source.expression;
|
|
14148
|
+
if (source.type === import_utils69.AST_NODE_TYPES.NewExpression) {
|
|
14059
14149
|
constructedFields += 1;
|
|
14060
|
-
} else if (source.type ===
|
|
14150
|
+
} else if (source.type === import_utils69.AST_NODE_TYPES.Identifier) {
|
|
14061
14151
|
const fields = storedFieldsFrom.get(source.name) ?? /* @__PURE__ */ new Set();
|
|
14062
14152
|
fields.add(storedField);
|
|
14063
14153
|
storedFieldsFrom.set(source.name, fields);
|
|
14064
|
-
} else if (source.type ===
|
|
14154
|
+
} else if (source.type === import_utils69.AST_NODE_TYPES.MemberExpression && source.object.type === import_utils69.AST_NODE_TYPES.Identifier) {
|
|
14065
14155
|
const fields = storedFieldsFrom.get(source.object.name) ?? /* @__PURE__ */ new Set();
|
|
14066
14156
|
fields.add(storedField);
|
|
14067
14157
|
storedFieldsFrom.set(source.object.name, fields);
|
|
@@ -14071,7 +14161,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
14071
14161
|
const collaborators = [];
|
|
14072
14162
|
for (const parameter of ctor.value.params) {
|
|
14073
14163
|
for (const reference of parameterCollaborators(parameter, declared)) {
|
|
14074
|
-
const fields = parameter.type ===
|
|
14164
|
+
const fields = parameter.type === import_utils69.AST_NODE_TYPES.TSParameterProperty ? [reference.name] : [...storedFieldsFrom.get(reference.name) ?? []];
|
|
14075
14165
|
if (fields.length === 0) continue;
|
|
14076
14166
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
14077
14167
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -14086,8 +14176,8 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
14086
14176
|
};
|
|
14087
14177
|
var parameterCollaborators = (parameter, declared) => {
|
|
14088
14178
|
let target = parameter;
|
|
14089
|
-
if (target.type ===
|
|
14090
|
-
if (target.type ===
|
|
14179
|
+
if (target.type === import_utils69.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
14180
|
+
if (target.type === import_utils69.AST_NODE_TYPES.ObjectPattern) {
|
|
14091
14181
|
return objectPatternCollaborators(target, declared);
|
|
14092
14182
|
}
|
|
14093
14183
|
const named2 = namedParameterCollaborator(parameter);
|
|
@@ -14095,9 +14185,9 @@ var parameterCollaborators = (parameter, declared) => {
|
|
|
14095
14185
|
};
|
|
14096
14186
|
var namedParameterCollaborator = (annotated) => {
|
|
14097
14187
|
let target = annotated;
|
|
14098
|
-
if (target.type ===
|
|
14099
|
-
if (target.type ===
|
|
14100
|
-
if (target.type !==
|
|
14188
|
+
if (target.type === import_utils69.AST_NODE_TYPES.TSParameterProperty) target = target.parameter;
|
|
14189
|
+
if (target.type === import_utils69.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
14190
|
+
if (target.type !== import_utils69.AST_NODE_TYPES.Identifier) return null;
|
|
14101
14191
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
14102
14192
|
if (reference === null) return null;
|
|
14103
14193
|
return { name: target.name, ...reference, fields: [] };
|
|
@@ -14109,11 +14199,11 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
14109
14199
|
if (members === null) return [];
|
|
14110
14200
|
const collaborators = [];
|
|
14111
14201
|
for (const property of pattern.properties) {
|
|
14112
|
-
if (property.type !==
|
|
14113
|
-
if (property.key.type !==
|
|
14202
|
+
if (property.type !== import_utils69.AST_NODE_TYPES.Property || property.computed) continue;
|
|
14203
|
+
if (property.key.type !== import_utils69.AST_NODE_TYPES.Identifier) continue;
|
|
14114
14204
|
const key = property.key.name;
|
|
14115
|
-
const bound = property.value.type ===
|
|
14116
|
-
if (bound.type !==
|
|
14205
|
+
const bound = property.value.type === import_utils69.AST_NODE_TYPES.AssignmentPattern ? property.value.left : property.value;
|
|
14206
|
+
if (bound.type !== import_utils69.AST_NODE_TYPES.Identifier) continue;
|
|
14117
14207
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
14118
14208
|
const reference = members.get(key);
|
|
14119
14209
|
if (reference === void 0) continue;
|
|
@@ -14122,21 +14212,21 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
14122
14212
|
return collaborators;
|
|
14123
14213
|
};
|
|
14124
14214
|
var bagMemberTypes = (annotation, declared) => {
|
|
14125
|
-
if (annotation.type ===
|
|
14215
|
+
if (annotation.type === import_utils69.AST_NODE_TYPES.TSTypeLiteral) {
|
|
14126
14216
|
return propertySignatureTypes(annotation.members);
|
|
14127
14217
|
}
|
|
14128
|
-
if (annotation.type !==
|
|
14218
|
+
if (annotation.type !== import_utils69.AST_NODE_TYPES.TSTypeReference || annotation.typeName.type !== import_utils69.AST_NODE_TYPES.Identifier) {
|
|
14129
14219
|
return null;
|
|
14130
14220
|
}
|
|
14131
14221
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
14132
14222
|
};
|
|
14133
14223
|
var isFrameworkWiring = (body2) => subtreeHas(body2, (node) => {
|
|
14134
|
-
if (node.type ===
|
|
14224
|
+
if (node.type === import_utils69.AST_NODE_TYPES.CallExpression) {
|
|
14135
14225
|
const { callee } = node;
|
|
14136
|
-
if (callee.type ===
|
|
14137
|
-
return callee.type ===
|
|
14226
|
+
if (callee.type === import_utils69.AST_NODE_TYPES.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
14227
|
+
return callee.type === import_utils69.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils69.AST_NODE_TYPES.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
14138
14228
|
}
|
|
14139
|
-
return node.type ===
|
|
14229
|
+
return node.type === import_utils69.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils69.AST_NODE_TYPES.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
14140
14230
|
});
|
|
14141
14231
|
var subtreeHas = (root, found) => {
|
|
14142
14232
|
let hit = false;
|
|
@@ -14163,19 +14253,19 @@ var invokedInstanceField = (call) => {
|
|
|
14163
14253
|
const direct = instanceField(call.callee);
|
|
14164
14254
|
if (direct !== null) return direct;
|
|
14165
14255
|
let callee = call.callee;
|
|
14166
|
-
while (callee.type ===
|
|
14167
|
-
return callee.type ===
|
|
14256
|
+
while (callee.type === import_utils69.AST_NODE_TYPES.ChainExpression || callee.type === import_utils69.AST_NODE_TYPES.TSAsExpression || callee.type === import_utils69.AST_NODE_TYPES.TSNonNullExpression || callee.type === import_utils69.AST_NODE_TYPES.TSSatisfiesExpression || callee.type === import_utils69.AST_NODE_TYPES.TSTypeAssertion) callee = callee.expression;
|
|
14257
|
+
return callee.type === import_utils69.AST_NODE_TYPES.MemberExpression ? instanceField(callee.object) : null;
|
|
14168
14258
|
};
|
|
14169
14259
|
var instanceField = (candidate) => {
|
|
14170
14260
|
let node = candidate;
|
|
14171
|
-
while (node.type ===
|
|
14172
|
-
return node.type ===
|
|
14261
|
+
while (node.type === import_utils69.AST_NODE_TYPES.ChainExpression || node.type === import_utils69.AST_NODE_TYPES.TSAsExpression || node.type === import_utils69.AST_NODE_TYPES.TSNonNullExpression || node.type === import_utils69.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils69.AST_NODE_TYPES.TSTypeAssertion) node = node.expression;
|
|
14262
|
+
return node.type === import_utils69.AST_NODE_TYPES.MemberExpression && node.object.type === import_utils69.AST_NODE_TYPES.ThisExpression ? staticMemberName6(node) : null;
|
|
14173
14263
|
};
|
|
14174
14264
|
var behaviorallyInvokedFields = (body2) => {
|
|
14175
14265
|
const invoked = /* @__PURE__ */ new Set();
|
|
14176
14266
|
const visit = (current) => {
|
|
14177
|
-
if (current.type ===
|
|
14178
|
-
if (current.type ===
|
|
14267
|
+
if (current.type === import_utils69.AST_NODE_TYPES.ClassDeclaration || current.type === import_utils69.AST_NODE_TYPES.ClassExpression || current.type === import_utils69.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils69.AST_NODE_TYPES.FunctionExpression) return;
|
|
14268
|
+
if (current.type === import_utils69.AST_NODE_TYPES.CallExpression) {
|
|
14179
14269
|
const field = invokedInstanceField(current);
|
|
14180
14270
|
if (field !== null) invoked.add(field);
|
|
14181
14271
|
}
|
|
@@ -14188,14 +14278,14 @@ var behaviorallyInvokedFields = (body2) => {
|
|
|
14188
14278
|
}
|
|
14189
14279
|
};
|
|
14190
14280
|
for (const member of body2.body) {
|
|
14191
|
-
if (member.type ===
|
|
14192
|
-
if (member.type ===
|
|
14281
|
+
if (member.type === import_utils69.AST_NODE_TYPES.StaticBlock || member.static) continue;
|
|
14282
|
+
if (member.type === import_utils69.AST_NODE_TYPES.MethodDefinition) {
|
|
14193
14283
|
if (member.value.body !== null && member.value.body !== void 0) visit(member.value.body);
|
|
14194
14284
|
continue;
|
|
14195
14285
|
}
|
|
14196
|
-
if (member.type !==
|
|
14286
|
+
if (member.type !== import_utils69.AST_NODE_TYPES.PropertyDefinition || member.value === null) continue;
|
|
14197
14287
|
visit(
|
|
14198
|
-
member.value.type ===
|
|
14288
|
+
member.value.type === import_utils69.AST_NODE_TYPES.ArrowFunctionExpression ? member.value.body : member.value
|
|
14199
14289
|
);
|
|
14200
14290
|
}
|
|
14201
14291
|
return invoked;
|
|
@@ -14215,25 +14305,25 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
14215
14305
|
var fileInterfaceNames = (program) => {
|
|
14216
14306
|
const names = [];
|
|
14217
14307
|
for (const statement of program.body) {
|
|
14218
|
-
const declaration = statement.type ===
|
|
14219
|
-
if (declaration?.type ===
|
|
14308
|
+
const declaration = statement.type === import_utils69.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
14309
|
+
if (declaration?.type === import_utils69.AST_NODE_TYPES.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
14220
14310
|
}
|
|
14221
14311
|
return names;
|
|
14222
14312
|
};
|
|
14223
14313
|
var publicMethodNames = (body2, functionAliases) => {
|
|
14224
14314
|
const names = [];
|
|
14225
14315
|
for (const member of body2.body) {
|
|
14226
|
-
if (member.type ===
|
|
14316
|
+
if (member.type === import_utils69.AST_NODE_TYPES.PropertyDefinition) {
|
|
14227
14317
|
if (member.static || member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
14228
|
-
if (member.value?.type !==
|
|
14229
|
-
names.push(member.key.type ===
|
|
14318
|
+
if (member.value?.type !== import_utils69.AST_NODE_TYPES.ArrowFunctionExpression && member.value?.type !== import_utils69.AST_NODE_TYPES.FunctionExpression && member.typeAnnotation?.typeAnnotation.type !== import_utils69.AST_NODE_TYPES.TSFunctionType && !(member.typeAnnotation?.typeAnnotation.type === import_utils69.AST_NODE_TYPES.TSTypeReference && member.typeAnnotation.typeAnnotation.typeName.type === import_utils69.AST_NODE_TYPES.Identifier && functionAliases.has(member.typeAnnotation.typeAnnotation.typeName.name))) continue;
|
|
14319
|
+
names.push(member.key.type === import_utils69.AST_NODE_TYPES.Identifier ? member.key.name : "\u2026");
|
|
14230
14320
|
continue;
|
|
14231
14321
|
}
|
|
14232
|
-
if (member.type !==
|
|
14322
|
+
if (member.type !== import_utils69.AST_NODE_TYPES.MethodDefinition) continue;
|
|
14233
14323
|
if (member.kind !== "method" || member.static) continue;
|
|
14234
14324
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
14235
|
-
if (member.key.type ===
|
|
14236
|
-
if (member.key.type ===
|
|
14325
|
+
if (member.key.type === import_utils69.AST_NODE_TYPES.PrivateIdentifier) continue;
|
|
14326
|
+
if (member.key.type === import_utils69.AST_NODE_TYPES.Identifier) names.push(member.key.name);
|
|
14237
14327
|
else names.push("\u2026");
|
|
14238
14328
|
}
|
|
14239
14329
|
return names;
|
|
@@ -14241,13 +14331,13 @@ var publicMethodNames = (body2, functionAliases) => {
|
|
|
14241
14331
|
var isFluentConstructionObject = (node, getText) => {
|
|
14242
14332
|
if (node.id === null) return false;
|
|
14243
14333
|
const methods = node.body.body.filter(
|
|
14244
|
-
(member) => member.type ===
|
|
14334
|
+
(member) => member.type === import_utils69.AST_NODE_TYPES.MethodDefinition && member.kind === "method" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.value.body !== null
|
|
14245
14335
|
);
|
|
14246
14336
|
if (methods.length === 0) return false;
|
|
14247
14337
|
return methods.every((member) => {
|
|
14248
14338
|
const result = member.value.returnType?.typeAnnotation;
|
|
14249
14339
|
if (result === void 0) return false;
|
|
14250
|
-
const returnsOwnType = result.type ===
|
|
14340
|
+
const returnsOwnType = result.type === import_utils69.AST_NODE_TYPES.TSTypeReference && result.typeName.type === import_utils69.AST_NODE_TYPES.Identifier && result.typeName.name === node.id?.name;
|
|
14251
14341
|
return returnsOwnType || FLUENT_BUILDER_NAME_RE.test(node.id?.name ?? "") && FLUENT_RESULT_TYPE_RE.test(getText(result));
|
|
14252
14342
|
});
|
|
14253
14343
|
};
|
|
@@ -14255,10 +14345,10 @@ function localClassAbstractness(program) {
|
|
|
14255
14345
|
const classes = /* @__PURE__ */ new Map();
|
|
14256
14346
|
const parents = /* @__PURE__ */ new Map();
|
|
14257
14347
|
for (const statement of program.body) {
|
|
14258
|
-
const declaration = statement.type ===
|
|
14259
|
-
if (declaration?.type ===
|
|
14348
|
+
const declaration = statement.type === import_utils69.AST_NODE_TYPES.ExportNamedDeclaration || statement.type === import_utils69.AST_NODE_TYPES.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
14349
|
+
if (declaration?.type === import_utils69.AST_NODE_TYPES.ClassDeclaration && declaration.id !== null) {
|
|
14260
14350
|
classes.set(declaration.id.name, declaration.abstract === true);
|
|
14261
|
-
if (declaration.superClass?.type ===
|
|
14351
|
+
if (declaration.superClass?.type === import_utils69.AST_NODE_TYPES.Identifier) {
|
|
14262
14352
|
parents.set(declaration.id.name, declaration.superClass.name);
|
|
14263
14353
|
}
|
|
14264
14354
|
}
|
|
@@ -14280,43 +14370,43 @@ function localInterfaceSurfaces(program) {
|
|
|
14280
14370
|
const parents = /* @__PURE__ */ new Map();
|
|
14281
14371
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
14282
14372
|
for (const statement of program.body) {
|
|
14283
|
-
const declaration = statement.type ===
|
|
14284
|
-
if (declaration?.type ===
|
|
14373
|
+
const declaration = statement.type === import_utils69.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
14374
|
+
if (declaration?.type === import_utils69.AST_NODE_TYPES.TSTypeAliasDeclaration && (declaration.typeAnnotation.type === import_utils69.AST_NODE_TYPES.TSFunctionType || declaration.typeAnnotation.type === import_utils69.AST_NODE_TYPES.TSConstructorType)) functionAliases.add(declaration.id.name);
|
|
14285
14375
|
}
|
|
14286
14376
|
for (const statement of program.body) {
|
|
14287
|
-
const declaration = statement.type ===
|
|
14288
|
-
if (declaration?.type ===
|
|
14377
|
+
const declaration = statement.type === import_utils69.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
14378
|
+
if (declaration?.type === import_utils69.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
14289
14379
|
const callables2 = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
14290
|
-
const parts = declaration.typeAnnotation.type ===
|
|
14380
|
+
const parts = declaration.typeAnnotation.type === import_utils69.AST_NODE_TYPES.TSIntersectionType ? declaration.typeAnnotation.types : [declaration.typeAnnotation];
|
|
14291
14381
|
const inherited = parents.get(declaration.id.name) ?? [];
|
|
14292
14382
|
for (const part of parts) {
|
|
14293
|
-
if (part.type ===
|
|
14383
|
+
if (part.type === import_utils69.AST_NODE_TYPES.TSTypeReference && part.typeName.type === import_utils69.AST_NODE_TYPES.Identifier) {
|
|
14294
14384
|
inherited.push(part.typeName.name);
|
|
14295
14385
|
continue;
|
|
14296
14386
|
}
|
|
14297
|
-
if (part.type !==
|
|
14387
|
+
if (part.type !== import_utils69.AST_NODE_TYPES.TSTypeLiteral) continue;
|
|
14298
14388
|
for (const member of part.members) {
|
|
14299
|
-
if (member.type !==
|
|
14300
|
-
if (member.computed || member.key.type !==
|
|
14301
|
-
if (member.type ===
|
|
14389
|
+
if (member.type !== import_utils69.AST_NODE_TYPES.TSMethodSignature && member.type !== import_utils69.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
14390
|
+
if (member.computed || member.key.type !== import_utils69.AST_NODE_TYPES.Identifier) continue;
|
|
14391
|
+
if (member.type === import_utils69.AST_NODE_TYPES.TSMethodSignature) {
|
|
14302
14392
|
callables2.add(member.key.name);
|
|
14303
14393
|
continue;
|
|
14304
14394
|
}
|
|
14305
|
-
if (member.type !==
|
|
14395
|
+
if (member.type !== import_utils69.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
14306
14396
|
const annotation = member.typeAnnotation?.typeAnnotation;
|
|
14307
|
-
if (annotation?.type ===
|
|
14397
|
+
if (annotation?.type === import_utils69.AST_NODE_TYPES.TSFunctionType || annotation?.type === import_utils69.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils69.AST_NODE_TYPES.Identifier && functionAliases.has(annotation.typeName.name)) callables2.add(member.key.name);
|
|
14308
14398
|
}
|
|
14309
14399
|
}
|
|
14310
14400
|
interfaces.set(declaration.id.name, callables2);
|
|
14311
14401
|
parents.set(declaration.id.name, inherited);
|
|
14312
14402
|
continue;
|
|
14313
14403
|
}
|
|
14314
|
-
if (declaration?.type !==
|
|
14404
|
+
if (declaration?.type !== import_utils69.AST_NODE_TYPES.TSInterfaceDeclaration) continue;
|
|
14315
14405
|
const callables = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
14316
14406
|
for (const member of declaration.body.body) {
|
|
14317
|
-
if (member.type !==
|
|
14318
|
-
if (member.computed || member.key.type !==
|
|
14319
|
-
if (member.type ===
|
|
14407
|
+
if (member.type !== import_utils69.AST_NODE_TYPES.TSMethodSignature && member.type !== import_utils69.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
14408
|
+
if (member.computed || member.key.type !== import_utils69.AST_NODE_TYPES.Identifier) continue;
|
|
14409
|
+
if (member.type === import_utils69.AST_NODE_TYPES.TSMethodSignature || member.typeAnnotation?.typeAnnotation.type === import_utils69.AST_NODE_TYPES.TSFunctionType || member.typeAnnotation?.typeAnnotation.type === import_utils69.AST_NODE_TYPES.TSTypeReference && member.typeAnnotation.typeAnnotation.typeName.type === import_utils69.AST_NODE_TYPES.Identifier && functionAliases.has(member.typeAnnotation.typeAnnotation.typeName.name)) callables.add(member.key.name);
|
|
14320
14410
|
}
|
|
14321
14411
|
interfaces.set(declaration.id.name, callables);
|
|
14322
14412
|
parents.set(
|
|
@@ -14324,7 +14414,7 @@ function localInterfaceSurfaces(program) {
|
|
|
14324
14414
|
[
|
|
14325
14415
|
...parents.get(declaration.id.name) ?? [],
|
|
14326
14416
|
...declaration.extends.flatMap(
|
|
14327
|
-
(heritage) => heritage.expression.type ===
|
|
14417
|
+
(heritage) => heritage.expression.type === import_utils69.AST_NODE_TYPES.Identifier ? [heritage.expression.name] : ["*"]
|
|
14328
14418
|
)
|
|
14329
14419
|
]
|
|
14330
14420
|
);
|
|
@@ -14351,7 +14441,7 @@ function localInterfaceSurfaces(program) {
|
|
|
14351
14441
|
}
|
|
14352
14442
|
function hasServicePort(node, methods, classes, interfaces) {
|
|
14353
14443
|
if (node.superClass !== null) {
|
|
14354
|
-
if (node.superClass.type !==
|
|
14444
|
+
if (node.superClass.type !== import_utils69.AST_NODE_TYPES.Identifier) return true;
|
|
14355
14445
|
const localAbstract = classes.get(node.superClass.name);
|
|
14356
14446
|
if (localAbstract === void 0 || localAbstract) return true;
|
|
14357
14447
|
}
|
|
@@ -14363,7 +14453,7 @@ function hasServicePort(node, methods, classes, interfaces) {
|
|
|
14363
14453
|
if (node.implements.length === 0) return false;
|
|
14364
14454
|
const combined = /* @__PURE__ */ new Set();
|
|
14365
14455
|
for (const implementation of node.implements) {
|
|
14366
|
-
if (implementation.expression.type !==
|
|
14456
|
+
if (implementation.expression.type !== import_utils69.AST_NODE_TYPES.Identifier) return true;
|
|
14367
14457
|
const name = implementation.expression.name;
|
|
14368
14458
|
const localAbstract = classes.get(name);
|
|
14369
14459
|
if (localAbstract === true) return true;
|
|
@@ -14406,7 +14496,7 @@ var require_port_for_service_default = createRule({
|
|
|
14406
14496
|
if (node.abstract === true) return;
|
|
14407
14497
|
if (node.decorators.length > 0) return;
|
|
14408
14498
|
const ctor = node.body.body.find(
|
|
14409
|
-
(member) => member.type ===
|
|
14499
|
+
(member) => member.type === import_utils69.AST_NODE_TYPES.MethodDefinition && member.kind === "constructor" && member.value.body !== null && member.value.body !== void 0
|
|
14410
14500
|
);
|
|
14411
14501
|
if (ctor === void 0) return;
|
|
14412
14502
|
const constructorFacts = readConstructor(
|
|
@@ -14441,7 +14531,7 @@ var require_port_for_service_default = createRule({
|
|
|
14441
14531
|
});
|
|
14442
14532
|
|
|
14443
14533
|
// src/rules/require-static-next-matcher.ts
|
|
14444
|
-
var
|
|
14534
|
+
var import_utils70 = require("@typescript-eslint/utils");
|
|
14445
14535
|
var requireStaticNextMatcherDocumentation = {
|
|
14446
14536
|
summary: "Require Next.js middleware and proxy matcher configuration to contain only build-time literals.",
|
|
14447
14537
|
rationale: "Next.js must statically analyze matcher values at build time; computed values are ignored.",
|
|
@@ -14454,34 +14544,34 @@ var requireStaticNextMatcherDocumentation = {
|
|
|
14454
14544
|
};
|
|
14455
14545
|
var NEXT_ENTRY_FILE = /(?:^|[/\\])(?:middleware|proxy)\.[cm]?[jt]sx?$/u;
|
|
14456
14546
|
function unwrapExpression3(node) {
|
|
14457
|
-
if (node.type ===
|
|
14547
|
+
if (node.type === import_utils70.AST_NODE_TYPES.TSAsExpression || node.type === import_utils70.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils70.AST_NODE_TYPES.TSNonNullExpression || node.type === import_utils70.AST_NODE_TYPES.TSTypeAssertion) {
|
|
14458
14548
|
return unwrapExpression3(node.expression);
|
|
14459
14549
|
}
|
|
14460
14550
|
return node;
|
|
14461
14551
|
}
|
|
14462
14552
|
function isStaticValue(node) {
|
|
14463
14553
|
const value = unwrapExpression3(node);
|
|
14464
|
-
if (value.type ===
|
|
14554
|
+
if (value.type === import_utils70.AST_NODE_TYPES.Literal) {
|
|
14465
14555
|
return true;
|
|
14466
14556
|
}
|
|
14467
|
-
if (value.type ===
|
|
14557
|
+
if (value.type === import_utils70.AST_NODE_TYPES.TemplateLiteral) {
|
|
14468
14558
|
return value.expressions.length === 0;
|
|
14469
14559
|
}
|
|
14470
|
-
if (value.type ===
|
|
14560
|
+
if (value.type === import_utils70.AST_NODE_TYPES.ArrayExpression) {
|
|
14471
14561
|
return value.elements.every(
|
|
14472
|
-
(element) => element !== null && element.type !==
|
|
14562
|
+
(element) => element !== null && element.type !== import_utils70.AST_NODE_TYPES.SpreadElement && isStaticValue(element)
|
|
14473
14563
|
);
|
|
14474
14564
|
}
|
|
14475
|
-
if (value.type ===
|
|
14565
|
+
if (value.type === import_utils70.AST_NODE_TYPES.ObjectExpression) {
|
|
14476
14566
|
return value.properties.every(
|
|
14477
|
-
(property) => property.type ===
|
|
14567
|
+
(property) => property.type === import_utils70.AST_NODE_TYPES.Property && property.kind === "init" && !property.computed && property.value.type !== import_utils70.AST_NODE_TYPES.AssignmentPattern && isStaticValue(property.value)
|
|
14478
14568
|
);
|
|
14479
14569
|
}
|
|
14480
14570
|
return false;
|
|
14481
14571
|
}
|
|
14482
14572
|
function propertyName2(property) {
|
|
14483
14573
|
if (property.computed) return null;
|
|
14484
|
-
if (property.key.type ===
|
|
14574
|
+
if (property.key.type === import_utils70.AST_NODE_TYPES.Identifier) return property.key.name;
|
|
14485
14575
|
return typeof property.key.value === "string" ? property.key.value : null;
|
|
14486
14576
|
}
|
|
14487
14577
|
var require_static_next_matcher_default = createRule({
|
|
@@ -14504,19 +14594,19 @@ var require_static_next_matcher_default = createRule({
|
|
|
14504
14594
|
}
|
|
14505
14595
|
return {
|
|
14506
14596
|
ExportNamedDeclaration(node) {
|
|
14507
|
-
if (node.declaration?.type !==
|
|
14597
|
+
if (node.declaration?.type !== import_utils70.AST_NODE_TYPES.VariableDeclaration) {
|
|
14508
14598
|
return;
|
|
14509
14599
|
}
|
|
14510
14600
|
for (const declaration of node.declaration.declarations) {
|
|
14511
|
-
if (declaration.id.type !==
|
|
14601
|
+
if (declaration.id.type !== import_utils70.AST_NODE_TYPES.Identifier || declaration.id.name !== "config" || declaration.init === null) {
|
|
14512
14602
|
continue;
|
|
14513
14603
|
}
|
|
14514
14604
|
const config = unwrapExpression3(declaration.init);
|
|
14515
|
-
if (config.type !==
|
|
14605
|
+
if (config.type !== import_utils70.AST_NODE_TYPES.ObjectExpression) {
|
|
14516
14606
|
continue;
|
|
14517
14607
|
}
|
|
14518
14608
|
for (const property of config.properties) {
|
|
14519
|
-
if (property.type !==
|
|
14609
|
+
if (property.type !== import_utils70.AST_NODE_TYPES.Property || propertyName2(property) !== "matcher" || property.value.type === import_utils70.AST_NODE_TYPES.AssignmentPattern) {
|
|
14520
14610
|
continue;
|
|
14521
14611
|
}
|
|
14522
14612
|
if (!isStaticValue(property.value)) {
|
|
@@ -14530,7 +14620,7 @@ var require_static_next_matcher_default = createRule({
|
|
|
14530
14620
|
});
|
|
14531
14621
|
|
|
14532
14622
|
// src/rules/require-zod-form-validation.ts
|
|
14533
|
-
var
|
|
14623
|
+
var import_utils71 = require("@typescript-eslint/utils");
|
|
14534
14624
|
var requireZodFormValidationDocumentation = {
|
|
14535
14625
|
summary: "Require Zod validation (`Schema.parse(...)` / `Schema.safeParse(...)`) when reading values out of a `FormData` object.",
|
|
14536
14626
|
rationale: "FormData values are untrusted strings or files and need runtime validation before use.",
|
|
@@ -14555,14 +14645,14 @@ var FORM_VALUE_METHODS = /* @__PURE__ */ new Set(["get", "getAll"]);
|
|
|
14555
14645
|
var zodReceiverRoot = (node) => {
|
|
14556
14646
|
let current = node;
|
|
14557
14647
|
while (true) {
|
|
14558
|
-
if (current.type ===
|
|
14648
|
+
if (current.type === import_utils71.AST_NODE_TYPES.Identifier) {
|
|
14559
14649
|
return current;
|
|
14560
14650
|
}
|
|
14561
|
-
if (current.type ===
|
|
14651
|
+
if (current.type === import_utils71.AST_NODE_TYPES.CallExpression) {
|
|
14562
14652
|
current = current.callee;
|
|
14563
14653
|
continue;
|
|
14564
14654
|
}
|
|
14565
|
-
if (current.type ===
|
|
14655
|
+
if (current.type === import_utils71.AST_NODE_TYPES.MemberExpression) {
|
|
14566
14656
|
current = current.object;
|
|
14567
14657
|
continue;
|
|
14568
14658
|
}
|
|
@@ -14571,12 +14661,12 @@ var zodReceiverRoot = (node) => {
|
|
|
14571
14661
|
};
|
|
14572
14662
|
var isFormDataMethodCall = (node) => {
|
|
14573
14663
|
let current = node;
|
|
14574
|
-
if (current.type ===
|
|
14664
|
+
if (current.type === import_utils71.AST_NODE_TYPES.AwaitExpression) {
|
|
14575
14665
|
current = current.argument;
|
|
14576
14666
|
}
|
|
14577
|
-
if (current.type !==
|
|
14667
|
+
if (current.type !== import_utils71.AST_NODE_TYPES.CallExpression) return false;
|
|
14578
14668
|
const callee = current.callee;
|
|
14579
|
-
return callee.type ===
|
|
14669
|
+
return callee.type === import_utils71.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils71.AST_NODE_TYPES.Identifier && callee.property.name === "formData";
|
|
14580
14670
|
};
|
|
14581
14671
|
var require_zod_form_validation_default = createRule({
|
|
14582
14672
|
name: "require-zod-form-validation",
|
|
@@ -14597,7 +14687,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14597
14687
|
return {};
|
|
14598
14688
|
}
|
|
14599
14689
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
14600
|
-
const resolvedBinding = (identifier) =>
|
|
14690
|
+
const resolvedBinding = (identifier) => import_utils71.ASTUtils.findVariable(
|
|
14601
14691
|
context.sourceCode.getScope(identifier),
|
|
14602
14692
|
identifier.name
|
|
14603
14693
|
);
|
|
@@ -14607,16 +14697,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
14607
14697
|
return false;
|
|
14608
14698
|
}
|
|
14609
14699
|
const definition = binding.defs[0];
|
|
14610
|
-
if (definition?.type !== "Variable" || definition.node.type !==
|
|
14700
|
+
if (definition?.type !== "Variable" || definition.node.type !== import_utils71.AST_NODE_TYPES.VariableDeclarator) {
|
|
14611
14701
|
return false;
|
|
14612
14702
|
}
|
|
14613
14703
|
const init = definition.node.init;
|
|
14614
|
-
return init?.type ===
|
|
14704
|
+
return init?.type === import_utils71.AST_NODE_TYPES.ObjectExpression || init?.type === import_utils71.AST_NODE_TYPES.ArrayExpression || init?.type === import_utils71.AST_NODE_TYPES.Literal || init?.type === import_utils71.AST_NODE_TYPES.ArrowFunctionExpression || init?.type === import_utils71.AST_NODE_TYPES.FunctionExpression;
|
|
14615
14705
|
};
|
|
14616
14706
|
const isZodParseCall = (node) => {
|
|
14617
|
-
if (node.type !==
|
|
14707
|
+
if (node.type !== import_utils71.AST_NODE_TYPES.CallExpression) return false;
|
|
14618
14708
|
const callee = node.callee;
|
|
14619
|
-
if (callee.type !==
|
|
14709
|
+
if (callee.type !== import_utils71.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils71.AST_NODE_TYPES.Identifier || !ZOD_PARSE_METHODS.has(callee.property.name)) {
|
|
14620
14710
|
return false;
|
|
14621
14711
|
}
|
|
14622
14712
|
const root = zodReceiverRoot(callee.object);
|
|
@@ -14625,14 +14715,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
14625
14715
|
return binding !== null && zodBindings.has(binding) || (root.name === "z" || ZOD_SCHEMA_NAME_RE.test(root.name)) && !isProvablyNonZodLocal(root);
|
|
14626
14716
|
};
|
|
14627
14717
|
const isFormSourceIdentifier = (node) => {
|
|
14628
|
-
if (node.type !==
|
|
14718
|
+
if (node.type !== import_utils71.AST_NODE_TYPES.Identifier) return false;
|
|
14629
14719
|
const conventionalName = /formdata/i.test(node.name);
|
|
14630
14720
|
let scope = context.sourceCode.getScope(node);
|
|
14631
14721
|
while (scope !== null) {
|
|
14632
14722
|
const variable = scope.set.get(node.name);
|
|
14633
14723
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
14634
14724
|
const def = variable.defs[0];
|
|
14635
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
14725
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === import_utils71.AST_NODE_TYPES.VariableDeclarator && def.node.init !== null) {
|
|
14636
14726
|
return isFormDataMethodCall(def.node.init);
|
|
14637
14727
|
}
|
|
14638
14728
|
return def?.type === "Parameter" && conventionalName;
|
|
@@ -14643,8 +14733,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
14643
14733
|
};
|
|
14644
14734
|
const isFormDataGetCall = (node) => {
|
|
14645
14735
|
const callee = node.callee;
|
|
14646
|
-
if (callee.type !==
|
|
14647
|
-
if (callee.property.type !==
|
|
14736
|
+
if (callee.type !== import_utils71.AST_NODE_TYPES.MemberExpression) return false;
|
|
14737
|
+
if (callee.property.type !== import_utils71.AST_NODE_TYPES.Identifier || !FORM_VALUE_METHODS.has(callee.property.name)) {
|
|
14648
14738
|
return false;
|
|
14649
14739
|
}
|
|
14650
14740
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -14660,16 +14750,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
14660
14750
|
const hasZodParseAncestor = (node) => zodParseAncestor(node) !== null;
|
|
14661
14751
|
const isInstanceofNarrowing = (node) => {
|
|
14662
14752
|
const parent = node.parent;
|
|
14663
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
14753
|
+
return parent !== null && parent !== void 0 && parent.type === import_utils71.AST_NODE_TYPES.BinaryExpression && parent.operator === "instanceof" && parent.left === node && parent.right.type === import_utils71.AST_NODE_TYPES.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
14664
14754
|
};
|
|
14665
14755
|
const boundDeclarator = (node) => {
|
|
14666
14756
|
let current = node;
|
|
14667
14757
|
let parent = current.parent;
|
|
14668
|
-
while ((parent.type ===
|
|
14758
|
+
while ((parent.type === import_utils71.AST_NODE_TYPES.TSAsExpression || parent.type === import_utils71.AST_NODE_TYPES.TSSatisfiesExpression || parent.type === import_utils71.AST_NODE_TYPES.TSNonNullExpression || parent.type === import_utils71.AST_NODE_TYPES.ChainExpression) && parent.expression === current) {
|
|
14669
14759
|
current = parent;
|
|
14670
14760
|
parent = current.parent;
|
|
14671
14761
|
}
|
|
14672
|
-
if (parent.type ===
|
|
14762
|
+
if (parent.type === import_utils71.AST_NODE_TYPES.VariableDeclarator && parent.init === current && parent.id.type === import_utils71.AST_NODE_TYPES.Identifier) {
|
|
14673
14763
|
return parent;
|
|
14674
14764
|
}
|
|
14675
14765
|
return null;
|
|
@@ -14678,7 +14768,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14678
14768
|
let current = node;
|
|
14679
14769
|
while (current.parent !== void 0) {
|
|
14680
14770
|
const parent = current.parent;
|
|
14681
|
-
if (parent.type ===
|
|
14771
|
+
if (parent.type === import_utils71.AST_NODE_TYPES.BlockStatement || parent.type === import_utils71.AST_NODE_TYPES.Program) {
|
|
14682
14772
|
return current;
|
|
14683
14773
|
}
|
|
14684
14774
|
current = parent;
|
|
@@ -14687,12 +14777,12 @@ var require_zod_form_validation_default = createRule({
|
|
|
14687
14777
|
};
|
|
14688
14778
|
const zodParseMethod = (call) => {
|
|
14689
14779
|
const callee = call.callee;
|
|
14690
|
-
return callee.type ===
|
|
14780
|
+
return callee.type === import_utils71.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils71.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
14691
14781
|
};
|
|
14692
14782
|
const hasConditionalAncestorBeforeStatement = (node, statement) => {
|
|
14693
14783
|
let current = node.parent;
|
|
14694
14784
|
while (current !== void 0 && current !== statement) {
|
|
14695
|
-
if (current.type ===
|
|
14785
|
+
if (current.type === import_utils71.AST_NODE_TYPES.LogicalExpression || current.type === import_utils71.AST_NODE_TYPES.ConditionalExpression) {
|
|
14696
14786
|
return true;
|
|
14697
14787
|
}
|
|
14698
14788
|
current = current.parent;
|
|
@@ -14702,7 +14792,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14702
14792
|
const isAwaitedBeforeStatement = (node, statement) => {
|
|
14703
14793
|
let current = node.parent;
|
|
14704
14794
|
while (current !== void 0 && current !== statement) {
|
|
14705
|
-
if (current.type ===
|
|
14795
|
+
if (current.type === import_utils71.AST_NODE_TYPES.AwaitExpression) return true;
|
|
14706
14796
|
current = current.parent;
|
|
14707
14797
|
}
|
|
14708
14798
|
return false;
|
|
@@ -14715,7 +14805,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14715
14805
|
if (declarationStatement === null || validationStatement === null || declarationStatement.parent !== validationStatement.parent || validationStatement.range[0] <= declarationStatement.range[1] || hasConditionalAncestorBeforeStatement(parse2, validationStatement)) {
|
|
14716
14806
|
return null;
|
|
14717
14807
|
}
|
|
14718
|
-
if (validationStatement.type !==
|
|
14808
|
+
if (validationStatement.type !== import_utils71.AST_NODE_TYPES.VariableDeclaration && validationStatement.type !== import_utils71.AST_NODE_TYPES.ExpressionStatement) {
|
|
14719
14809
|
return null;
|
|
14720
14810
|
}
|
|
14721
14811
|
const method = zodParseMethod(parse2);
|
|
@@ -14727,16 +14817,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
14727
14817
|
};
|
|
14728
14818
|
const isSafePrevalidationInspection = (identifier) => {
|
|
14729
14819
|
const parent = identifier.parent;
|
|
14730
|
-
if (parent.type ===
|
|
14820
|
+
if (parent.type === import_utils71.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof") {
|
|
14731
14821
|
return true;
|
|
14732
14822
|
}
|
|
14733
|
-
if (parent.type !==
|
|
14823
|
+
if (parent.type !== import_utils71.AST_NODE_TYPES.BinaryExpression || parent.left !== identifier) {
|
|
14734
14824
|
return false;
|
|
14735
14825
|
}
|
|
14736
14826
|
if (parent.operator === "instanceof") {
|
|
14737
|
-
return parent.right.type ===
|
|
14827
|
+
return parent.right.type === import_utils71.AST_NODE_TYPES.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
14738
14828
|
}
|
|
14739
|
-
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type ===
|
|
14829
|
+
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type === import_utils71.AST_NODE_TYPES.Literal && parent.right.value === null || parent.right.type === import_utils71.AST_NODE_TYPES.Identifier && parent.right.name === "undefined");
|
|
14740
14830
|
};
|
|
14741
14831
|
const isDescendantOf = (node, ancestor) => {
|
|
14742
14832
|
let current = node;
|
|
@@ -14747,23 +14837,23 @@ var require_zod_form_validation_default = createRule({
|
|
|
14747
14837
|
return false;
|
|
14748
14838
|
};
|
|
14749
14839
|
const blockTerminates = (node) => {
|
|
14750
|
-
if (node.type ===
|
|
14840
|
+
if (node.type === import_utils71.AST_NODE_TYPES.ReturnStatement || node.type === import_utils71.AST_NODE_TYPES.ThrowStatement) {
|
|
14751
14841
|
return true;
|
|
14752
14842
|
}
|
|
14753
|
-
if (node.type !==
|
|
14843
|
+
if (node.type !== import_utils71.AST_NODE_TYPES.BlockStatement || node.body.length === 0) return false;
|
|
14754
14844
|
const last = node.body.at(-1);
|
|
14755
14845
|
return last !== void 0 && blockTerminates(last);
|
|
14756
14846
|
};
|
|
14757
14847
|
const narrowingIf = (identifier) => {
|
|
14758
14848
|
const comparison = identifier.parent;
|
|
14759
|
-
if (comparison?.type !==
|
|
14849
|
+
if (comparison?.type !== import_utils71.AST_NODE_TYPES.BinaryExpression || comparison.operator !== "instanceof" || comparison.left !== identifier || comparison.right.type !== import_utils71.AST_NODE_TYPES.Identifier || comparison.right.name !== "File" && comparison.right.name !== "Blob") {
|
|
14760
14850
|
return null;
|
|
14761
14851
|
}
|
|
14762
14852
|
const maybeNegation = comparison.parent;
|
|
14763
|
-
const negated = maybeNegation?.type ===
|
|
14853
|
+
const negated = maybeNegation?.type === import_utils71.AST_NODE_TYPES.UnaryExpression && maybeNegation.operator === "!";
|
|
14764
14854
|
const test = negated ? maybeNegation : comparison;
|
|
14765
14855
|
const branch = test.parent;
|
|
14766
|
-
return branch?.type ===
|
|
14856
|
+
return branch?.type === import_utils71.AST_NODE_TYPES.IfStatement && branch.test === test ? { branch, positive: !negated } : null;
|
|
14767
14857
|
};
|
|
14768
14858
|
const useDominatedByNarrowing = (use, narrowings) => narrowings.some(({ branch, positive }) => {
|
|
14769
14859
|
if (positive) return isDescendantOf(use, branch.consequent);
|
|
@@ -14783,7 +14873,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14783
14873
|
const variable = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
14784
14874
|
if (variable === void 0) return false;
|
|
14785
14875
|
const references = variable.references.filter((reference) => !reference.isWriteOnly()).map((reference) => reference.identifier).filter(
|
|
14786
|
-
(identifier) => identifier.type ===
|
|
14876
|
+
(identifier) => identifier.type === import_utils71.AST_NODE_TYPES.Identifier
|
|
14787
14877
|
);
|
|
14788
14878
|
if (references.length === 0) return false;
|
|
14789
14879
|
const narrowings = references.map(narrowingIf).filter(
|
|
@@ -14809,7 +14899,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14809
14899
|
ImportDeclaration(node) {
|
|
14810
14900
|
if (!isZodModule(node.source.value)) return;
|
|
14811
14901
|
for (const specifier of node.specifiers) {
|
|
14812
|
-
if (specifier.type ===
|
|
14902
|
+
if (specifier.type === import_utils71.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils71.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils71.AST_NODE_TYPES.ImportSpecifier && (specifier.imported.type === import_utils71.AST_NODE_TYPES.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
14813
14903
|
const binding = resolvedBinding(specifier.local);
|
|
14814
14904
|
if (binding !== null) zodBindings.add(binding);
|
|
14815
14905
|
}
|
|
@@ -14830,7 +14920,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14830
14920
|
});
|
|
14831
14921
|
|
|
14832
14922
|
// src/rules/store-insert-requires-on-conflict.ts
|
|
14833
|
-
var
|
|
14923
|
+
var import_utils72 = require("@typescript-eslint/utils");
|
|
14834
14924
|
var storeInsertRequiresOnConflictDocumentation = {
|
|
14835
14925
|
summary: "Require embedded inserts in explicitly replayable callables to carry conflict handling.",
|
|
14836
14926
|
rationale: "A callable named as an enqueue, seed, migration, schedule, ensure, or upsert promises replay safety.",
|
|
@@ -14894,7 +14984,7 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
14894
14984
|
});
|
|
14895
14985
|
|
|
14896
14986
|
// src/rules/stepdown.ts
|
|
14897
|
-
var
|
|
14987
|
+
var import_utils73 = require("@typescript-eslint/utils");
|
|
14898
14988
|
var stepdownDocumentation = {
|
|
14899
14989
|
summary: "Place a private helper below its sole direct same-scope caller.",
|
|
14900
14990
|
rationale: "Caller-first ordering lets a reader follow the main flow before descending into implementation details.",
|
|
@@ -14911,7 +15001,7 @@ var stepdownDocumentation = {
|
|
|
14911
15001
|
]
|
|
14912
15002
|
};
|
|
14913
15003
|
function isFunction(node) {
|
|
14914
|
-
return node.type ===
|
|
15004
|
+
return node.type === import_utils73.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils73.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils73.AST_NODE_TYPES.FunctionExpression;
|
|
14915
15005
|
}
|
|
14916
15006
|
function reportMisordered(context, candidates, scopeDefinitions, calls, pinned, canMove = () => true) {
|
|
14917
15007
|
const byName = new Map(scopeDefinitions.map((definition) => [definition.name, definition]));
|
|
@@ -15006,8 +15096,8 @@ function moduleScope(context, program) {
|
|
|
15006
15096
|
for (const node of declarations) counts.set(node.name, (counts.get(node.name) ?? 0) + 1);
|
|
15007
15097
|
const overloadNames = new Set(
|
|
15008
15098
|
program.body.flatMap((statement) => {
|
|
15009
|
-
const node = statement.type ===
|
|
15010
|
-
return node?.type ===
|
|
15099
|
+
const node = statement.type === import_utils73.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
15100
|
+
return node?.type === import_utils73.AST_NODE_TYPES.TSDeclareFunction && node.id !== null ? [node.id.name] : [];
|
|
15011
15101
|
})
|
|
15012
15102
|
);
|
|
15013
15103
|
const exported = exportedNames(program);
|
|
@@ -15031,7 +15121,7 @@ function moduleScope(context, program) {
|
|
|
15031
15121
|
const nearestFunction2 = [...ancestors].reverse().find(isFunction);
|
|
15032
15122
|
const parent = identifier.parent;
|
|
15033
15123
|
const callerDefinition = nearestFunction2 === void 0 ? void 0 : byFunction.get(nearestFunction2);
|
|
15034
|
-
if (callerDefinition === void 0 || parent.type !==
|
|
15124
|
+
if (callerDefinition === void 0 || parent.type !== import_utils73.AST_NODE_TYPES.CallExpression || parent.callee !== identifier) {
|
|
15035
15125
|
pinned.add(definition.name);
|
|
15036
15126
|
continue;
|
|
15037
15127
|
}
|
|
@@ -15046,38 +15136,38 @@ function moduleScope(context, program) {
|
|
|
15046
15136
|
function exportedNames(program) {
|
|
15047
15137
|
const names = /* @__PURE__ */ new Set();
|
|
15048
15138
|
for (const statement of program.body) {
|
|
15049
|
-
if (statement.type !==
|
|
15050
|
-
if (statement.declaration?.type ===
|
|
15139
|
+
if (statement.type !== import_utils73.AST_NODE_TYPES.ExportNamedDeclaration || statement.exportKind === "type" || statement.source !== null) continue;
|
|
15140
|
+
if (statement.declaration?.type === import_utils73.AST_NODE_TYPES.FunctionDeclaration && statement.declaration.id !== null) {
|
|
15051
15141
|
names.add(statement.declaration.id.name);
|
|
15052
15142
|
}
|
|
15053
|
-
if (statement.declaration?.type ===
|
|
15143
|
+
if (statement.declaration?.type === import_utils73.AST_NODE_TYPES.VariableDeclaration) {
|
|
15054
15144
|
for (const declarator of statement.declaration.declarations) {
|
|
15055
|
-
if (declarator.id.type ===
|
|
15145
|
+
if (declarator.id.type === import_utils73.AST_NODE_TYPES.Identifier) names.add(declarator.id.name);
|
|
15056
15146
|
}
|
|
15057
15147
|
}
|
|
15058
15148
|
for (const specifier of statement.specifiers) {
|
|
15059
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
15149
|
+
if (specifier.exportKind !== "type" && specifier.local.type === import_utils73.AST_NODE_TYPES.Identifier) {
|
|
15060
15150
|
names.add(specifier.local.name);
|
|
15061
15151
|
}
|
|
15062
15152
|
}
|
|
15063
15153
|
}
|
|
15064
15154
|
for (const statement of program.body) {
|
|
15065
|
-
if (statement.type ===
|
|
15066
|
-
if (statement.type ===
|
|
15155
|
+
if (statement.type === import_utils73.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils73.AST_NODE_TYPES.Identifier) names.add(statement.declaration.name);
|
|
15156
|
+
if (statement.type === import_utils73.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils73.AST_NODE_TYPES.FunctionDeclaration && statement.declaration.id !== null) names.add(statement.declaration.id.name);
|
|
15067
15157
|
}
|
|
15068
15158
|
return names;
|
|
15069
15159
|
}
|
|
15070
15160
|
function moduleDefinitions(program) {
|
|
15071
15161
|
const definitions = [];
|
|
15072
15162
|
for (const statement of program.body) {
|
|
15073
|
-
const node = statement.type ===
|
|
15074
|
-
if (node?.type ===
|
|
15163
|
+
const node = statement.type === import_utils73.AST_NODE_TYPES.ExportNamedDeclaration || statement.type === import_utils73.AST_NODE_TYPES.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
15164
|
+
if (node?.type === import_utils73.AST_NODE_TYPES.FunctionDeclaration && node.id !== null && node.body !== null) {
|
|
15075
15165
|
definitions.push({ name: node.id.name, node, functionNode: node, bindingNode: node });
|
|
15076
15166
|
continue;
|
|
15077
15167
|
}
|
|
15078
|
-
if (node?.type !==
|
|
15168
|
+
if (node?.type !== import_utils73.AST_NODE_TYPES.VariableDeclaration || node.kind !== "const") continue;
|
|
15079
15169
|
for (const declarator of node.declarations) {
|
|
15080
|
-
if (declarator.id.type ===
|
|
15170
|
+
if (declarator.id.type === import_utils73.AST_NODE_TYPES.Identifier && declarator.init !== null && isFunction(declarator.init)) {
|
|
15081
15171
|
definitions.push({
|
|
15082
15172
|
name: declarator.id.name,
|
|
15083
15173
|
node: declarator,
|
|
@@ -15090,21 +15180,21 @@ function moduleDefinitions(program) {
|
|
|
15090
15180
|
return definitions;
|
|
15091
15181
|
}
|
|
15092
15182
|
function methodName(node) {
|
|
15093
|
-
if (node.key.type ===
|
|
15094
|
-
return !node.computed && node.key.type ===
|
|
15183
|
+
if (node.key.type === import_utils73.AST_NODE_TYPES.PrivateIdentifier) return `#${node.key.name}`;
|
|
15184
|
+
return !node.computed && node.key.type === import_utils73.AST_NODE_TYPES.Identifier ? node.key.name : null;
|
|
15095
15185
|
}
|
|
15096
15186
|
function referencedMethod(context, node, classVariables) {
|
|
15097
|
-
const objectVariable = node.object.type ===
|
|
15187
|
+
const objectVariable = node.object.type === import_utils73.AST_NODE_TYPES.Identifier ? import_utils73.ASTUtils.findVariable(context.sourceCode.getScope(node.object), node.object.name) : null;
|
|
15098
15188
|
const isClassReference = objectVariable !== null && classVariables.has(objectVariable);
|
|
15099
|
-
if (node.object.type !==
|
|
15100
|
-
if (node.property.type ===
|
|
15101
|
-
if (!node.computed && node.property.type ===
|
|
15102
|
-
return node.computed && node.property.type ===
|
|
15189
|
+
if (node.object.type !== import_utils73.AST_NODE_TYPES.ThisExpression && !isClassReference) return null;
|
|
15190
|
+
if (node.property.type === import_utils73.AST_NODE_TYPES.PrivateIdentifier) return `#${node.property.name}`;
|
|
15191
|
+
if (!node.computed && node.property.type === import_utils73.AST_NODE_TYPES.Identifier) return node.property.name;
|
|
15192
|
+
return node.computed && node.property.type === import_utils73.AST_NODE_TYPES.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
15103
15193
|
}
|
|
15104
15194
|
function referencedPropertyName(node) {
|
|
15105
|
-
if (node.property.type ===
|
|
15106
|
-
if (!node.computed && node.property.type ===
|
|
15107
|
-
return node.computed && node.property.type ===
|
|
15195
|
+
if (node.property.type === import_utils73.AST_NODE_TYPES.PrivateIdentifier) return `#${node.property.name}`;
|
|
15196
|
+
if (!node.computed && node.property.type === import_utils73.AST_NODE_TYPES.Identifier) return node.property.name;
|
|
15197
|
+
return node.computed && node.property.type === import_utils73.AST_NODE_TYPES.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
15108
15198
|
}
|
|
15109
15199
|
function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
15110
15200
|
visit(node, nestedFunction);
|
|
@@ -15120,7 +15210,7 @@ function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
|
15120
15210
|
}
|
|
15121
15211
|
function classScope(context, node, computedReferenceNames) {
|
|
15122
15212
|
const methods = node.body.body.filter(
|
|
15123
|
-
(member) => member.type ===
|
|
15213
|
+
(member) => member.type === import_utils73.AST_NODE_TYPES.MethodDefinition
|
|
15124
15214
|
);
|
|
15125
15215
|
const counts = /* @__PURE__ */ new Map();
|
|
15126
15216
|
for (const method of methods) {
|
|
@@ -15128,8 +15218,8 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15128
15218
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
15129
15219
|
}
|
|
15130
15220
|
for (const member of node.body.body) {
|
|
15131
|
-
if (member.type !==
|
|
15132
|
-
const name = !member.computed && member.key.type ===
|
|
15221
|
+
if (member.type !== import_utils73.AST_NODE_TYPES.TSAbstractMethodDefinition) continue;
|
|
15222
|
+
const name = !member.computed && member.key.type === import_utils73.AST_NODE_TYPES.Identifier ? member.key.name : null;
|
|
15133
15223
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
15134
15224
|
}
|
|
15135
15225
|
const scopeDefinitions = methods.flatMap((method) => {
|
|
@@ -15138,7 +15228,7 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15138
15228
|
});
|
|
15139
15229
|
const definitions = methods.flatMap((method) => {
|
|
15140
15230
|
const name = methodName(method);
|
|
15141
|
-
const isPrivate = method.accessibility === "private" || method.key.type ===
|
|
15231
|
+
const isPrivate = method.accessibility === "private" || method.key.type === import_utils73.AST_NODE_TYPES.PrivateIdentifier;
|
|
15142
15232
|
return name !== null && isPrivate && counts.get(name) === 1 && method.decorators.length === 0 ? [{ name, node: method }] : [];
|
|
15143
15233
|
});
|
|
15144
15234
|
if (definitions.length === 0) return;
|
|
@@ -15147,11 +15237,11 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15147
15237
|
const pinned = /* @__PURE__ */ new Set();
|
|
15148
15238
|
const classVariables = /* @__PURE__ */ new Set();
|
|
15149
15239
|
if (node.id !== null) {
|
|
15150
|
-
const internal =
|
|
15240
|
+
const internal = import_utils73.ASTUtils.findVariable(context.sourceCode.getScope(node), node.id.name);
|
|
15151
15241
|
if (internal !== null) classVariables.add(internal);
|
|
15152
15242
|
}
|
|
15153
|
-
if (node.type ===
|
|
15154
|
-
const outer =
|
|
15243
|
+
if (node.type === import_utils73.AST_NODE_TYPES.ClassExpression && node.parent.type === import_utils73.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === import_utils73.AST_NODE_TYPES.Identifier) {
|
|
15244
|
+
const outer = import_utils73.ASTUtils.findVariable(context.sourceCode.getScope(node.parent), node.parent.id.name);
|
|
15155
15245
|
if (outer !== null) classVariables.add(outer);
|
|
15156
15246
|
}
|
|
15157
15247
|
for (const method of methods) {
|
|
@@ -15167,27 +15257,27 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15167
15257
|
}
|
|
15168
15258
|
const thisValue = (value) => {
|
|
15169
15259
|
let current = value;
|
|
15170
|
-
while (current?.type ===
|
|
15171
|
-
return current?.type ===
|
|
15260
|
+
while (current?.type === import_utils73.AST_NODE_TYPES.TSAsExpression || current?.type === import_utils73.AST_NODE_TYPES.TSSatisfiesExpression || current?.type === import_utils73.AST_NODE_TYPES.TSNonNullExpression) current = current.expression;
|
|
15261
|
+
return current?.type === import_utils73.AST_NODE_TYPES.ThisExpression;
|
|
15172
15262
|
};
|
|
15173
15263
|
const collectAlias = (current, nestedFunction) => {
|
|
15174
|
-
if (nestedFunction || current.type !==
|
|
15175
|
-
if (current.type ===
|
|
15176
|
-
const binding = current.type ===
|
|
15177
|
-
const value = current.type ===
|
|
15264
|
+
if (nestedFunction || current.type !== import_utils73.AST_NODE_TYPES.VariableDeclarator && current.type !== import_utils73.AST_NODE_TYPES.AssignmentPattern) return;
|
|
15265
|
+
if (current.type === import_utils73.AST_NODE_TYPES.VariableDeclarator && (current.parent.type !== import_utils73.AST_NODE_TYPES.VariableDeclaration || current.parent.kind !== "const")) return;
|
|
15266
|
+
const binding = current.type === import_utils73.AST_NODE_TYPES.VariableDeclarator ? current.id : current.left;
|
|
15267
|
+
const value = current.type === import_utils73.AST_NODE_TYPES.VariableDeclarator ? current.init : current.right;
|
|
15178
15268
|
if (!thisValue(value)) return;
|
|
15179
|
-
if (binding.type ===
|
|
15269
|
+
if (binding.type === import_utils73.AST_NODE_TYPES.ObjectPattern) {
|
|
15180
15270
|
for (const property of binding.properties) {
|
|
15181
|
-
if (property.type ===
|
|
15271
|
+
if (property.type === import_utils73.AST_NODE_TYPES.RestElement) {
|
|
15182
15272
|
for (const name of privateNames) pinned.add(name);
|
|
15183
|
-
} else if (property.key.type ===
|
|
15273
|
+
} else if (property.key.type === import_utils73.AST_NODE_TYPES.Identifier && privateNames.has(property.key.name)) {
|
|
15184
15274
|
pinned.add(property.key.name);
|
|
15185
15275
|
}
|
|
15186
15276
|
}
|
|
15187
15277
|
return;
|
|
15188
15278
|
}
|
|
15189
|
-
if (binding.type !==
|
|
15190
|
-
const variable =
|
|
15279
|
+
if (binding.type !== import_utils73.AST_NODE_TYPES.Identifier) return;
|
|
15280
|
+
const variable = import_utils73.ASTUtils.findVariable(context.sourceCode.getScope(binding), binding.name);
|
|
15191
15281
|
if (variable !== null) {
|
|
15192
15282
|
methodClassVariables.add(variable);
|
|
15193
15283
|
methodAliases.add(variable);
|
|
@@ -15200,16 +15290,16 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15200
15290
|
walk(statement, context.sourceCode.visitorKeys, collectAlias);
|
|
15201
15291
|
}
|
|
15202
15292
|
const visitCall = (current, nestedFunction) => {
|
|
15203
|
-
if (current.type ===
|
|
15293
|
+
if (current.type === import_utils73.AST_NODE_TYPES.VariableDeclarator && current.id.type === import_utils73.AST_NODE_TYPES.ObjectPattern && thisValue(current.init)) {
|
|
15204
15294
|
for (const property of current.id.properties) {
|
|
15205
|
-
if (property.type ===
|
|
15295
|
+
if (property.type === import_utils73.AST_NODE_TYPES.RestElement) {
|
|
15206
15296
|
for (const name of privateNames) pinned.add(name);
|
|
15207
15297
|
continue;
|
|
15208
15298
|
}
|
|
15209
|
-
if (property.type ===
|
|
15299
|
+
if (property.type === import_utils73.AST_NODE_TYPES.Property && property.key.type === import_utils73.AST_NODE_TYPES.Identifier && privateNames.has(property.key.name)) pinned.add(property.key.name);
|
|
15210
15300
|
}
|
|
15211
15301
|
}
|
|
15212
|
-
if (current.type !==
|
|
15302
|
+
if (current.type !== import_utils73.AST_NODE_TYPES.MemberExpression) return;
|
|
15213
15303
|
const target = referencedMethod(context, current, methodClassVariables);
|
|
15214
15304
|
if (target === null) {
|
|
15215
15305
|
const possibleTarget = referencedPropertyName(current);
|
|
@@ -15217,12 +15307,12 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15217
15307
|
return;
|
|
15218
15308
|
}
|
|
15219
15309
|
if (!privateNames.has(target)) return;
|
|
15220
|
-
const objectVariable = current.object.type ===
|
|
15310
|
+
const objectVariable = current.object.type === import_utils73.AST_NODE_TYPES.Identifier ? import_utils73.ASTUtils.findVariable(context.sourceCode.getScope(current.object), current.object.name) : null;
|
|
15221
15311
|
if (objectVariable !== null && methodAliases.has(objectVariable)) {
|
|
15222
15312
|
pinned.add(target);
|
|
15223
15313
|
return;
|
|
15224
15314
|
}
|
|
15225
|
-
if (current.computed || nestedFunction || parameterDecoratorNodes.has(current) || current.parent.type !==
|
|
15315
|
+
if (current.computed || nestedFunction || parameterDecoratorNodes.has(current) || current.parent.type !== import_utils73.AST_NODE_TYPES.CallExpression || current.parent.callee !== current) {
|
|
15226
15316
|
pinned.add(target);
|
|
15227
15317
|
return;
|
|
15228
15318
|
}
|
|
@@ -15242,9 +15332,9 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15242
15332
|
}
|
|
15243
15333
|
}
|
|
15244
15334
|
for (const member of node.body.body) {
|
|
15245
|
-
if (member.type ===
|
|
15335
|
+
if (member.type === import_utils73.AST_NODE_TYPES.MethodDefinition || member.type === import_utils73.AST_NODE_TYPES.TSAbstractMethodDefinition) continue;
|
|
15246
15336
|
walk(member, context.sourceCode.visitorKeys, (current) => {
|
|
15247
|
-
if (current.type !==
|
|
15337
|
+
if (current.type !== import_utils73.AST_NODE_TYPES.MemberExpression) return;
|
|
15248
15338
|
const target = referencedMethod(context, current, classVariables);
|
|
15249
15339
|
const possibleTarget = target ?? referencedPropertyName(current);
|
|
15250
15340
|
if (possibleTarget !== null && privateNames.has(possibleTarget)) pinned.add(possibleTarget);
|
|
@@ -15254,14 +15344,14 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15254
15344
|
const accessibility = new Map(
|
|
15255
15345
|
scopeDefinitions.map((definition) => {
|
|
15256
15346
|
const method = definition.node;
|
|
15257
|
-
const accessibility2 = method.key.type ===
|
|
15347
|
+
const accessibility2 = method.key.type === import_utils73.AST_NODE_TYPES.PrivateIdentifier ? "private" : method.accessibility ?? "public";
|
|
15258
15348
|
return [definition.name, accessibility2];
|
|
15259
15349
|
})
|
|
15260
15350
|
);
|
|
15261
15351
|
const methodByName = new Map(scopeDefinitions.map((definition) => [definition.name, definition.node]));
|
|
15262
15352
|
for (const [caller, callees] of calls) {
|
|
15263
15353
|
const callerMethod = methodByName.get(caller);
|
|
15264
|
-
if (accessibility.get(caller) === "private" && callerMethod?.type ===
|
|
15354
|
+
if (accessibility.get(caller) === "private" && callerMethod?.type === import_utils73.AST_NODE_TYPES.MethodDefinition && callerMethod.decorators.length === 0) continue;
|
|
15265
15355
|
for (const callee of callees) pinned.add(callee);
|
|
15266
15356
|
}
|
|
15267
15357
|
const memberIndexes = new Map(node.body.body.map((member, index) => [member, index]));
|
|
@@ -15278,12 +15368,12 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15278
15368
|
}
|
|
15279
15369
|
function isClassRuntimeBarrier(member) {
|
|
15280
15370
|
switch (member.type) {
|
|
15281
|
-
case
|
|
15371
|
+
case import_utils73.AST_NODE_TYPES.StaticBlock:
|
|
15282
15372
|
return true;
|
|
15283
|
-
case
|
|
15284
|
-
case
|
|
15373
|
+
case import_utils73.AST_NODE_TYPES.PropertyDefinition:
|
|
15374
|
+
case import_utils73.AST_NODE_TYPES.AccessorProperty:
|
|
15285
15375
|
return member.static || member.computed || member.decorators.length > 0 || member.value !== null;
|
|
15286
|
-
case
|
|
15376
|
+
case import_utils73.AST_NODE_TYPES.MethodDefinition:
|
|
15287
15377
|
return member.computed || member.decorators.length > 0;
|
|
15288
15378
|
default:
|
|
15289
15379
|
return false;
|
|
@@ -15315,7 +15405,7 @@ var stepdown_default = createRule({
|
|
|
15315
15405
|
moduleScope(context, program);
|
|
15316
15406
|
const computedReferenceNames = /* @__PURE__ */ new Set();
|
|
15317
15407
|
walk(program, context.sourceCode.visitorKeys, (node) => {
|
|
15318
|
-
if (node.type ===
|
|
15408
|
+
if (node.type === import_utils73.AST_NODE_TYPES.MemberExpression && node.computed && node.property.type === import_utils73.AST_NODE_TYPES.Literal && typeof node.property.value === "string") computedReferenceNames.add(node.property.value);
|
|
15319
15409
|
});
|
|
15320
15410
|
for (const node of classes) classScope(context, node, computedReferenceNames);
|
|
15321
15411
|
}
|
|
@@ -15324,7 +15414,7 @@ var stepdown_default = createRule({
|
|
|
15324
15414
|
});
|
|
15325
15415
|
|
|
15326
15416
|
// src/rules/source-coupled-test.ts
|
|
15327
|
-
var
|
|
15417
|
+
var import_utils74 = require("@typescript-eslint/utils");
|
|
15328
15418
|
var GENERAL_SOURCE_SUFFIX_RE = /\.(?:bash|sh|ya?ml|jsonc|py|[cm]?[jt]s)$/iu;
|
|
15329
15419
|
var FS_MODULES = /* @__PURE__ */ new Set(["fs", "node:fs", "fs/promises", "node:fs/promises"]);
|
|
15330
15420
|
var FS_READERS = /* @__PURE__ */ new Set(["readFile", "readFileSync"]);
|
|
@@ -15393,20 +15483,20 @@ var sourceCoupledTestDocumentation = {
|
|
|
15393
15483
|
]
|
|
15394
15484
|
};
|
|
15395
15485
|
function staticMemberName7(node) {
|
|
15396
|
-
if (!node.computed && node.property.type ===
|
|
15397
|
-
if (node.computed && node.property.type ===
|
|
15486
|
+
if (!node.computed && node.property.type === import_utils74.AST_NODE_TYPES.Identifier) return node.property.name;
|
|
15487
|
+
if (node.computed && node.property.type === import_utils74.AST_NODE_TYPES.Literal && typeof node.property.value === "string") return node.property.value;
|
|
15398
15488
|
return null;
|
|
15399
15489
|
}
|
|
15400
15490
|
function unwrap5(node) {
|
|
15401
|
-
if (node.type ===
|
|
15402
|
-
if (node.type ===
|
|
15403
|
-
if (node.type ===
|
|
15491
|
+
if (node.type === import_utils74.AST_NODE_TYPES.AwaitExpression) return unwrap5(node.argument);
|
|
15492
|
+
if (node.type === import_utils74.AST_NODE_TYPES.ChainExpression) return unwrap5(node.expression);
|
|
15493
|
+
if (node.type === import_utils74.AST_NODE_TYPES.TSAsExpression || node.type === import_utils74.AST_NODE_TYPES.TSNonNullExpression || node.type === import_utils74.AST_NODE_TYPES.TSTypeAssertion) return unwrap5(node.expression);
|
|
15404
15494
|
return node;
|
|
15405
15495
|
}
|
|
15406
15496
|
function stringValue(node) {
|
|
15407
15497
|
const current = unwrap5(node);
|
|
15408
|
-
if (current.type ===
|
|
15409
|
-
if (current.type ===
|
|
15498
|
+
if (current.type === import_utils74.AST_NODE_TYPES.Literal && typeof current.value === "string") return current.value;
|
|
15499
|
+
if (current.type === import_utils74.AST_NODE_TYPES.TemplateLiteral && current.expressions.length === 0) return current.quasis[0]?.value.cooked ?? null;
|
|
15410
15500
|
return null;
|
|
15411
15501
|
}
|
|
15412
15502
|
function importSource(node) {
|
|
@@ -15414,7 +15504,7 @@ function importSource(node) {
|
|
|
15414
15504
|
}
|
|
15415
15505
|
function requireSource(node) {
|
|
15416
15506
|
const current = unwrap5(node);
|
|
15417
|
-
if (current.type !==
|
|
15507
|
+
if (current.type !== import_utils74.AST_NODE_TYPES.CallExpression || current.callee.type !== import_utils74.AST_NODE_TYPES.Identifier || current.callee.name !== "require" || current.arguments.length !== 1 || current.arguments[0]?.type === import_utils74.AST_NODE_TYPES.SpreadElement) return null;
|
|
15418
15508
|
return stringValue(current.arguments[0]);
|
|
15419
15509
|
}
|
|
15420
15510
|
function newScope() {
|
|
@@ -15454,38 +15544,38 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
15454
15544
|
const current = unwrap5(node);
|
|
15455
15545
|
const value = stringValue(current);
|
|
15456
15546
|
if (value !== null) return sourceSuffixRe.test(value);
|
|
15457
|
-
if (current.type ===
|
|
15458
|
-
if (current.type ===
|
|
15547
|
+
if (current.type === import_utils74.AST_NODE_TYPES.Identifier) return visible("paths", current.name);
|
|
15548
|
+
if (current.type === import_utils74.AST_NODE_TYPES.BinaryExpression && current.operator === "+") {
|
|
15459
15549
|
return sourcePath(current.left) || sourcePath(current.right);
|
|
15460
15550
|
}
|
|
15461
|
-
if (current.type ===
|
|
15462
|
-
if (current.type ===
|
|
15463
|
-
return current.arguments.some((argument) => argument.type !==
|
|
15551
|
+
if (current.type === import_utils74.AST_NODE_TYPES.TemplateLiteral) return current.expressions.some(sourcePath);
|
|
15552
|
+
if (current.type === import_utils74.AST_NODE_TYPES.CallExpression || current.type === import_utils74.AST_NODE_TYPES.NewExpression) {
|
|
15553
|
+
return current.arguments.some((argument) => argument.type !== import_utils74.AST_NODE_TYPES.SpreadElement && sourcePath(argument));
|
|
15464
15554
|
}
|
|
15465
|
-
if (current.type ===
|
|
15555
|
+
if (current.type === import_utils74.AST_NODE_TYPES.MemberExpression) return sourcePath(current.object);
|
|
15466
15556
|
return false;
|
|
15467
15557
|
};
|
|
15468
15558
|
const rawRead = (node) => {
|
|
15469
15559
|
const current = unwrap5(node);
|
|
15470
|
-
if (current.type !==
|
|
15560
|
+
if (current.type !== import_utils74.AST_NODE_TYPES.CallExpression || current.arguments.length === 0) return false;
|
|
15471
15561
|
const callee = unwrap5(current.callee);
|
|
15472
|
-
if (callee.type ===
|
|
15562
|
+
if (callee.type === import_utils74.AST_NODE_TYPES.Identifier) {
|
|
15473
15563
|
return visible("fsReaders", callee.name) && sourcePath(current.arguments[0]);
|
|
15474
15564
|
}
|
|
15475
|
-
if (callee.type !==
|
|
15565
|
+
if (callee.type !== import_utils74.AST_NODE_TYPES.MemberExpression) return false;
|
|
15476
15566
|
const name2 = staticMemberName7(callee);
|
|
15477
15567
|
const object = unwrap5(callee.object);
|
|
15478
|
-
return name2 !== null && FS_READERS.has(name2) && object.type ===
|
|
15568
|
+
return name2 !== null && FS_READERS.has(name2) && object.type === import_utils74.AST_NODE_TYPES.Identifier && visible("fsObjects", object.name) && sourcePath(current.arguments[0]);
|
|
15479
15569
|
};
|
|
15480
15570
|
const rawOrigins = (node) => {
|
|
15481
15571
|
const current = unwrap5(node);
|
|
15482
|
-
if (current.type ===
|
|
15572
|
+
if (current.type === import_utils74.AST_NODE_TYPES.Identifier) return visibleRawOrigins(current.name);
|
|
15483
15573
|
if (rawRead(current)) return /* @__PURE__ */ new Set([`${current.range[0]}:${current.range[1]}`]);
|
|
15484
|
-
if (current.type ===
|
|
15485
|
-
if (current.type ===
|
|
15486
|
-
if (current.type !==
|
|
15574
|
+
if (current.type === import_utils74.AST_NODE_TYPES.BinaryExpression && current.operator === "+") return /* @__PURE__ */ new Set([...rawOrigins(current.left), ...rawOrigins(current.right)]);
|
|
15575
|
+
if (current.type === import_utils74.AST_NODE_TYPES.MemberExpression && staticMemberName7(current) === "length") return rawOrigins(current.object);
|
|
15576
|
+
if (current.type !== import_utils74.AST_NODE_TYPES.CallExpression) return /* @__PURE__ */ new Set();
|
|
15487
15577
|
const callee = unwrap5(current.callee);
|
|
15488
|
-
if (callee.type !==
|
|
15578
|
+
if (callee.type !== import_utils74.AST_NODE_TYPES.MemberExpression) return /* @__PURE__ */ new Set();
|
|
15489
15579
|
const name2 = staticMemberName7(callee);
|
|
15490
15580
|
return name2 !== null && TEXT_TRANSFORMS.has(name2) ? rawOrigins(callee.object) : /* @__PURE__ */ new Set();
|
|
15491
15581
|
};
|
|
@@ -15493,38 +15583,38 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
15493
15583
|
const current = unwrap5(node);
|
|
15494
15584
|
const direct = rawOrigins(current);
|
|
15495
15585
|
if (direct.size > 0) return direct;
|
|
15496
|
-
if (current.type ===
|
|
15497
|
-
if (current.type ===
|
|
15498
|
-
if (current.type !==
|
|
15586
|
+
if (current.type === import_utils74.AST_NODE_TYPES.BinaryExpression || current.type === import_utils74.AST_NODE_TYPES.LogicalExpression) return /* @__PURE__ */ new Set([...evidenceOrigins(current.left), ...evidenceOrigins(current.right)]);
|
|
15587
|
+
if (current.type === import_utils74.AST_NODE_TYPES.UnaryExpression) return evidenceOrigins(current.argument);
|
|
15588
|
+
if (current.type !== import_utils74.AST_NODE_TYPES.CallExpression) return /* @__PURE__ */ new Set();
|
|
15499
15589
|
const callee = unwrap5(current.callee);
|
|
15500
|
-
if (callee.type !==
|
|
15590
|
+
if (callee.type !== import_utils74.AST_NODE_TYPES.MemberExpression) return /* @__PURE__ */ new Set();
|
|
15501
15591
|
const name2 = staticMemberName7(callee);
|
|
15502
15592
|
if (name2 !== null && TEXT_PREDICATES.has(name2)) return rawOrigins(callee.object);
|
|
15503
|
-
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type ===
|
|
15593
|
+
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type === import_utils74.AST_NODE_TYPES.SpreadElement ? [] : [...rawOrigins(argument)]));
|
|
15504
15594
|
return /* @__PURE__ */ new Set();
|
|
15505
15595
|
};
|
|
15506
15596
|
const rawAssertionOrigins = (node) => {
|
|
15507
15597
|
const callee = unwrap5(node.callee);
|
|
15508
|
-
if (callee.type ===
|
|
15509
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
15598
|
+
if (callee.type === import_utils74.AST_NODE_TYPES.Identifier && callee.name === "assert") {
|
|
15599
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === import_utils74.AST_NODE_TYPES.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
15510
15600
|
}
|
|
15511
|
-
if (callee.type !==
|
|
15601
|
+
if (callee.type !== import_utils74.AST_NODE_TYPES.MemberExpression) return /* @__PURE__ */ new Set();
|
|
15512
15602
|
const matcher = staticMemberName7(callee);
|
|
15513
15603
|
if (matcher === null) return /* @__PURE__ */ new Set();
|
|
15514
15604
|
let receiver = unwrap5(callee.object);
|
|
15515
|
-
while (receiver.type ===
|
|
15516
|
-
if (receiver.type ===
|
|
15605
|
+
while (receiver.type === import_utils74.AST_NODE_TYPES.MemberExpression && EXPECT_MODIFIERS2.has(staticMemberName7(receiver) ?? "")) receiver = unwrap5(receiver.object);
|
|
15606
|
+
if (receiver.type === import_utils74.AST_NODE_TYPES.CallExpression && receiver.callee.type === import_utils74.AST_NODE_TYPES.Identifier && receiver.callee.name === "expect") {
|
|
15517
15607
|
if (!EXPECT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
15518
|
-
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type ===
|
|
15608
|
+
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type === import_utils74.AST_NODE_TYPES.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
15519
15609
|
}
|
|
15520
|
-
if (receiver.type !==
|
|
15521
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
15610
|
+
if (receiver.type !== import_utils74.AST_NODE_TYPES.Identifier || receiver.name !== "assert" || !ASSERT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
15611
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === import_utils74.AST_NODE_TYPES.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
15522
15612
|
};
|
|
15523
15613
|
const rawRegexExtractionOrigins = (node) => {
|
|
15524
15614
|
const callee = unwrap5(node.callee);
|
|
15525
|
-
if (callee.type !==
|
|
15615
|
+
if (callee.type !== import_utils74.AST_NODE_TYPES.MemberExpression || staticMemberName7(callee) !== "matchAll" || node.arguments.length !== 1) return /* @__PURE__ */ new Set();
|
|
15526
15616
|
const argument = node.arguments[0];
|
|
15527
|
-
if (argument?.type !==
|
|
15617
|
+
if (argument?.type !== import_utils74.AST_NODE_TYPES.Literal || !(argument.value instanceof RegExp)) return /* @__PURE__ */ new Set();
|
|
15528
15618
|
return rawOrigins(callee.object);
|
|
15529
15619
|
};
|
|
15530
15620
|
const declare = (name2, state) => {
|
|
@@ -15545,15 +15635,15 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
15545
15635
|
};
|
|
15546
15636
|
const sourceCollection = (node) => {
|
|
15547
15637
|
const current = unwrap5(node);
|
|
15548
|
-
return current.type ===
|
|
15638
|
+
return current.type === import_utils74.AST_NODE_TYPES.ArrayExpression && current.elements.length > 0 && current.elements.every((element) => element !== null && element.type !== import_utils74.AST_NODE_TYPES.SpreadElement && sourcePath(element));
|
|
15549
15639
|
};
|
|
15550
15640
|
const declaredNames2 = (node) => {
|
|
15551
15641
|
const current = unwrap5(node);
|
|
15552
|
-
if (current.type ===
|
|
15553
|
-
if (current.type ===
|
|
15554
|
-
if (current.type ===
|
|
15555
|
-
if (current.type ===
|
|
15556
|
-
if (current.type ===
|
|
15642
|
+
if (current.type === import_utils74.AST_NODE_TYPES.Identifier) return [current.name];
|
|
15643
|
+
if (current.type === import_utils74.AST_NODE_TYPES.AssignmentPattern) return declaredNames2(current.left);
|
|
15644
|
+
if (current.type === import_utils74.AST_NODE_TYPES.RestElement) return declaredNames2(current.argument);
|
|
15645
|
+
if (current.type === import_utils74.AST_NODE_TYPES.ArrayPattern) return current.elements.flatMap((element) => element === null ? [] : declaredNames2(element));
|
|
15646
|
+
if (current.type === import_utils74.AST_NODE_TYPES.ObjectPattern) return current.properties.flatMap((property) => property.type === import_utils74.AST_NODE_TYPES.RestElement ? declaredNames2(property.argument) : declaredNames2(property.value));
|
|
15557
15647
|
return [];
|
|
15558
15648
|
};
|
|
15559
15649
|
const enterFunction = (node) => {
|
|
@@ -15568,8 +15658,8 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
15568
15658
|
const source = importSource(node);
|
|
15569
15659
|
if (source === null || !FS_MODULES.has(source)) return;
|
|
15570
15660
|
for (const specifier of node.specifiers) {
|
|
15571
|
-
if (specifier.type ===
|
|
15572
|
-
const imported = specifier.imported.type ===
|
|
15661
|
+
if (specifier.type === import_utils74.AST_NODE_TYPES.ImportSpecifier) {
|
|
15662
|
+
const imported = specifier.imported.type === import_utils74.AST_NODE_TYPES.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
15573
15663
|
if (FS_READERS.has(imported)) declare(specifier.local.name, { fsReader: true });
|
|
15574
15664
|
} else {
|
|
15575
15665
|
declare(specifier.local.name, { fsObject: true });
|
|
@@ -15581,29 +15671,29 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
15581
15671
|
VariableDeclarator(node) {
|
|
15582
15672
|
if (node.init === null) return;
|
|
15583
15673
|
const required = requireSource(node.init);
|
|
15584
|
-
if (required !== null && FS_MODULES.has(required) && node.id.type ===
|
|
15674
|
+
if (required !== null && FS_MODULES.has(required) && node.id.type === import_utils74.AST_NODE_TYPES.Identifier) {
|
|
15585
15675
|
declare(node.id.name, { fsObject: true });
|
|
15586
15676
|
return;
|
|
15587
15677
|
}
|
|
15588
|
-
if (node.id.type ===
|
|
15678
|
+
if (node.id.type === import_utils74.AST_NODE_TYPES.ObjectPattern && required !== null && FS_MODULES.has(required)) {
|
|
15589
15679
|
for (const property of node.id.properties) {
|
|
15590
|
-
if (property.type !==
|
|
15591
|
-
const key = property.key.type ===
|
|
15680
|
+
if (property.type !== import_utils74.AST_NODE_TYPES.Property || property.value.type !== import_utils74.AST_NODE_TYPES.Identifier) continue;
|
|
15681
|
+
const key = property.key.type === import_utils74.AST_NODE_TYPES.Identifier ? property.key.name : property.key.type === import_utils74.AST_NODE_TYPES.Literal ? String(property.key.value) : "";
|
|
15592
15682
|
if (FS_READERS.has(key)) declare(property.value.name, { fsReader: true });
|
|
15593
15683
|
}
|
|
15594
15684
|
return;
|
|
15595
15685
|
}
|
|
15596
|
-
if (node.id.type !==
|
|
15686
|
+
if (node.id.type !== import_utils74.AST_NODE_TYPES.Identifier) return;
|
|
15597
15687
|
declare(node.id.name, { collection: sourceCollection(node.init), path: sourcePath(node.init), rawOrigins: rawOrigins(node.init) });
|
|
15598
15688
|
},
|
|
15599
15689
|
AssignmentExpression(node) {
|
|
15600
|
-
if (node.left.type ===
|
|
15690
|
+
if (node.left.type === import_utils74.AST_NODE_TYPES.Identifier) declare(node.left.name, { path: sourcePath(node.right), rawOrigins: rawOrigins(node.right) });
|
|
15601
15691
|
},
|
|
15602
15692
|
ForOfStatement(node) {
|
|
15603
15693
|
const right = unwrap5(node.right);
|
|
15604
|
-
const collection = right.type ===
|
|
15605
|
-
const left = node.left.type ===
|
|
15606
|
-
if (collection && left?.type ===
|
|
15694
|
+
const collection = right.type === import_utils74.AST_NODE_TYPES.Identifier && visible("collections", right.name);
|
|
15695
|
+
const left = node.left.type === import_utils74.AST_NODE_TYPES.VariableDeclaration ? node.left.declarations[0]?.id : node.left;
|
|
15696
|
+
if (collection && left?.type === import_utils74.AST_NODE_TYPES.Identifier) declare(left.name, { path: true });
|
|
15607
15697
|
},
|
|
15608
15698
|
CallExpression(node) {
|
|
15609
15699
|
const origins = /* @__PURE__ */ new Set([
|
|
@@ -15663,7 +15753,7 @@ var iac_source_coupled_test_default = createSourceCoupledRule(
|
|
|
15663
15753
|
);
|
|
15664
15754
|
|
|
15665
15755
|
// src/rules/zod-naming-convention.ts
|
|
15666
|
-
var
|
|
15756
|
+
var import_utils75 = require("@typescript-eslint/utils");
|
|
15667
15757
|
var zodNamingConventionDocumentation = {
|
|
15668
15758
|
summary: "Enforce a consistent Zod schema naming convention \u2014 a `Z` prefix (`ZUser`) or a `Schema` suffix (`userSchema`); both are accepted by default.",
|
|
15669
15759
|
rationale: "A recognizable schema name distinguishes runtime validators from ordinary values at each use site.",
|
|
@@ -15704,18 +15794,18 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
15704
15794
|
"prettifyError",
|
|
15705
15795
|
"treeifyError"
|
|
15706
15796
|
]);
|
|
15707
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
15797
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === import_utils75.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
15708
15798
|
var calleeChainRoot = (node) => {
|
|
15709
15799
|
let current = node;
|
|
15710
15800
|
for (; ; ) {
|
|
15711
|
-
if (current.type ===
|
|
15801
|
+
if (current.type === import_utils75.AST_NODE_TYPES.Identifier) {
|
|
15712
15802
|
return current;
|
|
15713
15803
|
}
|
|
15714
|
-
if (current.type ===
|
|
15804
|
+
if (current.type === import_utils75.AST_NODE_TYPES.MemberExpression) {
|
|
15715
15805
|
current = current.object;
|
|
15716
15806
|
continue;
|
|
15717
15807
|
}
|
|
15718
|
-
if (current.type ===
|
|
15808
|
+
if (current.type === import_utils75.AST_NODE_TYPES.CallExpression) {
|
|
15719
15809
|
current = current.callee;
|
|
15720
15810
|
continue;
|
|
15721
15811
|
}
|
|
@@ -15755,7 +15845,7 @@ var zod_naming_convention_default = createRule({
|
|
|
15755
15845
|
const acceptsSchemaWord = convention !== "prefix";
|
|
15756
15846
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
15757
15847
|
function resolvedBinding(identifier) {
|
|
15758
|
-
return
|
|
15848
|
+
return import_utils75.ASTUtils.findVariable(
|
|
15759
15849
|
context.sourceCode.getScope(identifier),
|
|
15760
15850
|
identifier.name
|
|
15761
15851
|
);
|
|
@@ -15777,7 +15867,7 @@ var zod_naming_convention_default = createRule({
|
|
|
15777
15867
|
ImportDeclaration(node) {
|
|
15778
15868
|
if (!isZodModule(node.source.value)) return;
|
|
15779
15869
|
for (const specifier of node.specifiers) {
|
|
15780
|
-
if (specifier.type ===
|
|
15870
|
+
if (specifier.type === import_utils75.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils75.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils75.AST_NODE_TYPES.ImportSpecifier && (specifier.imported.type === import_utils75.AST_NODE_TYPES.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
15781
15871
|
recordZodBinding(specifier.local);
|
|
15782
15872
|
}
|
|
15783
15873
|
}
|
|
@@ -15785,13 +15875,13 @@ var zod_naming_convention_default = createRule({
|
|
|
15785
15875
|
VariableDeclarator(node) {
|
|
15786
15876
|
const init = node.init;
|
|
15787
15877
|
if (init === null || init === void 0) return;
|
|
15788
|
-
if (init.type !==
|
|
15878
|
+
if (init.type !== import_utils75.AST_NODE_TYPES.CallExpression) return;
|
|
15789
15879
|
const callee = init.callee;
|
|
15790
|
-
if (callee.type !==
|
|
15880
|
+
if (callee.type !== import_utils75.AST_NODE_TYPES.MemberExpression) return;
|
|
15791
15881
|
if (!isZodChain(callee)) return;
|
|
15792
15882
|
const terminal = terminalMethodName(callee);
|
|
15793
15883
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
15794
|
-
if (node.id.type !==
|
|
15884
|
+
if (node.id.type !== import_utils75.AST_NODE_TYPES.Identifier) return;
|
|
15795
15885
|
if (test.test(node.id.name)) return;
|
|
15796
15886
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
15797
15887
|
context.report({
|
|
@@ -15929,6 +16019,7 @@ var rules = {
|
|
|
15929
16019
|
"no-unsafe-mock-casting": no_unsafe_mock_casting_default,
|
|
15930
16020
|
"no-zod-native-enum": no_zod_native_enum_default,
|
|
15931
16021
|
"test-loops-over-literal-cases": test_loops_over_literal_cases_default,
|
|
16022
|
+
"test-phase-label-comment": test_phase_label_comment_default,
|
|
15932
16023
|
"prefer-constant-time-secret-compare": prefer_constant_time_secret_compare_default,
|
|
15933
16024
|
"prefer-discriminated-union": prefer_discriminated_union_default,
|
|
15934
16025
|
"prefer-input-group-search": prefer_input_group_search_default,
|
|
@@ -15957,7 +16048,7 @@ var rules = {
|
|
|
15957
16048
|
};
|
|
15958
16049
|
var meta = {
|
|
15959
16050
|
name: "@sarj/eslint-plugin",
|
|
15960
|
-
version: "15.
|
|
16051
|
+
version: "15.10.0"
|
|
15961
16052
|
};
|
|
15962
16053
|
var applicationOnlyRules = [
|
|
15963
16054
|
"no-restricted-library-load",
|
|
@@ -15968,7 +16059,8 @@ var advisoryRules = [
|
|
|
15968
16059
|
"no-bare-return-from-test-catch",
|
|
15969
16060
|
"iac-source-coupled-test",
|
|
15970
16061
|
"repeated-static-call-cases",
|
|
15971
|
-
"source-coupled-test"
|
|
16062
|
+
"source-coupled-test",
|
|
16063
|
+
"test-phase-label-comment"
|
|
15972
16064
|
];
|
|
15973
16065
|
var recommendedRules = {
|
|
15974
16066
|
"@sarj/iac-source-coupled-test": "warn",
|
|
@@ -16032,6 +16124,7 @@ var recommendedRules = {
|
|
|
16032
16124
|
"@sarj/store-insert-requires-on-conflict": "error",
|
|
16033
16125
|
"@sarj/stepdown": "error",
|
|
16034
16126
|
"@sarj/source-coupled-test": "warn",
|
|
16127
|
+
"@sarj/test-phase-label-comment": "warn",
|
|
16035
16128
|
"@sarj/zod-naming-convention": "error"
|
|
16036
16129
|
};
|
|
16037
16130
|
var strictRules = {
|
|
@@ -16100,6 +16193,7 @@ var strictRules = {
|
|
|
16100
16193
|
"@sarj/store-insert-requires-on-conflict": "error",
|
|
16101
16194
|
"@sarj/stepdown": "error",
|
|
16102
16195
|
"@sarj/source-coupled-test": "warn",
|
|
16196
|
+
"@sarj/test-phase-label-comment": "warn",
|
|
16103
16197
|
"@sarj/zod-naming-convention": "error"
|
|
16104
16198
|
};
|
|
16105
16199
|
var plugin = {
|