@sarj/eslint-plugin 15.9.0 → 15.10.1
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 +833 -731
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +820 -718
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1412,7 +1412,7 @@ var no_comment_cruft_default = createRule({
|
|
|
1412
1412
|
sectionBanner: "Section-banner / region comment \u2014 remove the decoration or replace it with a named code boundary.",
|
|
1413
1413
|
fileHeaderPreamble: "File-header comment preamble \u2014 use a brief doc comment for the why, not a block of `//` lines.",
|
|
1414
1414
|
commentWall: "Statement comment wall ({{count}} narrated steps) \u2014 delete the walkthrough and name the operations in code; keep only constraints or rationale.",
|
|
1415
|
-
redundantNarration: "Comment narrates the code \u2014 delete it or
|
|
1415
|
+
redundantNarration: "Comment narrates the code \u2014 delete it; if the code still needs explanation, use clearer names or extract a named helper. Keep only constraints or rationale.",
|
|
1416
1416
|
placeholderImplementation: "Placeholder implementation comment \u2014 implement the behavior or use an explicit unsupported path.",
|
|
1417
1417
|
untrackedTodo: "Untracked TODO/FIXME marker \u2014 add an issue ticket or context link."
|
|
1418
1418
|
}
|
|
@@ -4173,6 +4173,7 @@ var DIRECTIVE_RE2 = /^(?:!|eslint\b|eslint-|@ts-|prettier|biome-|c8\b|v8\b|istan
|
|
|
4173
4173
|
var LICENSE_RE2 = /\b(?:copyright|spdx-license-identifier|licensed under)\b/i;
|
|
4174
4174
|
var TYPED_TAG_RE = /@(arg|argument|param|return|returns|yield|yields)\b/i;
|
|
4175
4175
|
var VALUE_TAG_RE = /@(example|deprecated|see|remarks|throws|internal|public|alpha|beta|since|template|fileoverview)\b/i;
|
|
4176
|
+
var ANY_TAG_RE = /(?:^|\s)@[A-Za-z][\w-]*\b/u;
|
|
4176
4177
|
var BOUNDARY_RE = /(?<=[.!?])["'`)\]]*\s+(?=[A-Z0-9`])/;
|
|
4177
4178
|
var BULLET_RE = /^\s*(?:[-*+] |\d+[.)] )/;
|
|
4178
4179
|
var HEADING_RE = /^[A-Za-z][A-Za-z ]+:$/;
|
|
@@ -4180,8 +4181,8 @@ var TECHNICAL_ANCHOR_RE = /https?:\/\/|`[^`\n]+`|:[a-z][a-z0-9_-]*:|(["'])[^"'\n
|
|
|
4180
4181
|
function body(comment) {
|
|
4181
4182
|
return comment.value.replace(/^\*/, "").split("\n").map((line) => line.replace(/^\s*\*?\s?/, "")).join("\n").trim();
|
|
4182
4183
|
}
|
|
4183
|
-
function eligible(text, includeValueTags) {
|
|
4184
|
-
return text.length > 0 && !DIRECTIVE_RE2.test(text) && !LICENSE_RE2.test(text) && (includeValueTags || !VALUE_TAG_RE.test(text));
|
|
4184
|
+
function eligible(text, includeValueTags, jsDoc = false) {
|
|
4185
|
+
return text.length > 0 && !DIRECTIVE_RE2.test(text) && !LICENSE_RE2.test(text) && (includeValueTags || !VALUE_TAG_RE.test(text) && (!jsDoc || !ANY_TAG_RE.test(text)));
|
|
4185
4186
|
}
|
|
4186
4187
|
function sentenceUnits(text) {
|
|
4187
4188
|
const cleaned = text.replace(/https?:\/\/\S+/g, "URL").replace(/`[^`\n]+`/g, "CODE").replace(/\b\d+\.\d+\b/g, "NUMBER").replace(/\b(?:e\.g\.|i\.e\.|vs\.|etc\.)/gi, "ABBREVIATION");
|
|
@@ -4221,7 +4222,9 @@ function proseGroups(filename, sourceCode, includeValueTags = false) {
|
|
|
4221
4222
|
const text = body(comment);
|
|
4222
4223
|
if (comment.type === "Block") {
|
|
4223
4224
|
flush();
|
|
4224
|
-
if (eligible(text, includeValueTags
|
|
4225
|
+
if (eligible(text, includeValueTags, comment.value.startsWith("*"))) {
|
|
4226
|
+
groups.push({ comment, text, hasTypedTags: TYPED_TAG_RE.test(text) });
|
|
4227
|
+
}
|
|
4225
4228
|
continue;
|
|
4226
4229
|
}
|
|
4227
4230
|
const ownLine = sourceCode.lines[comment.loc.start.line - 1]?.slice(0, comment.loc.start.column).trim() === "";
|
|
@@ -5917,7 +5920,7 @@ var no_restated_jsdoc_default = createRule({
|
|
|
5917
5920
|
},
|
|
5918
5921
|
schema: [],
|
|
5919
5922
|
messages: {
|
|
5920
|
-
restatesSignature: "JSDoc only re-spells the signature \u2014 delete it
|
|
5923
|
+
restatesSignature: "JSDoc only re-spells the signature \u2014 delete it; if the signature still needs explanation, improve its names or types. Keep constraints, failures, and rationale.",
|
|
5921
5924
|
deleteBlock: "Delete the JSDoc block."
|
|
5922
5925
|
}
|
|
5923
5926
|
},
|
|
@@ -7790,7 +7793,7 @@ var no_typed_doc_sections_default = createRule({
|
|
|
7790
7793
|
docs: { description: "Reject typed-signature repetition while preserving behavior that types cannot express." },
|
|
7791
7794
|
schema: [],
|
|
7792
7795
|
messages: {
|
|
7793
|
-
typedSection: "Typed JSDoc repeats parameters or returns \u2014 delete the tags
|
|
7796
|
+
typedSection: "Typed JSDoc repeats parameters or returns \u2014 delete the repeated tags; if the signature still needs explanation, improve its names or types. Keep constraints and rationale."
|
|
7794
7797
|
}
|
|
7795
7798
|
},
|
|
7796
7799
|
defaultOptions: [],
|
|
@@ -7991,10 +7994,10 @@ var no_trailing_value_narration_default = createRule({
|
|
|
7991
7994
|
});
|
|
7992
7995
|
|
|
7993
7996
|
// src/rules/no-declaration-comment-wall.ts
|
|
7994
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES30, AST_TOKEN_TYPES } from "@typescript-eslint/utils";
|
|
7997
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES30, AST_TOKEN_TYPES as AST_TOKEN_TYPES2 } from "@typescript-eslint/utils";
|
|
7995
7998
|
|
|
7996
7999
|
// src/rules/_comment-wall.ts
|
|
7997
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES29 } from "@typescript-eslint/utils";
|
|
8000
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES29, AST_TOKEN_TYPES } from "@typescript-eslint/utils";
|
|
7998
8001
|
var WALL_DEFAULTS = {
|
|
7999
8002
|
// Below three rows "a wall" is not a fair description of what the reader sees.
|
|
8000
8003
|
minCommentedMembers: 3,
|
|
@@ -8059,6 +8062,9 @@ function labelStems(body2) {
|
|
|
8059
8062
|
function commentBody(comment) {
|
|
8060
8063
|
return comment.value.replace(/^\*+/, "").replace(/^[ \t]*\*[ \t]?/gm, "").trim();
|
|
8061
8064
|
}
|
|
8065
|
+
function hasJsDocTag(comment) {
|
|
8066
|
+
return comment.type === AST_TOKEN_TYPES.Block && comment.value.startsWith("*") && /(?:^|\s)@[A-Za-z][\w-]*\b/u.test(commentBody(comment));
|
|
8067
|
+
}
|
|
8062
8068
|
function carriesValue(body2) {
|
|
8063
8069
|
return isProtected(body2) || VALUE_TAG_RE2.test(body2) || DEFAULT_RE.test(body2) || DIGIT_RE.test(body2) || UNIT_WORD_RE.test(body2) || EXAMPLE_RE.test(body2) || BANNER_RE.test(body2) || NON_ASCII_LETTER_RE2.test(body2);
|
|
8064
8070
|
}
|
|
@@ -8169,7 +8175,7 @@ var no_declaration_comment_wall_default = createRule({
|
|
|
8169
8175
|
},
|
|
8170
8176
|
schema: [WALL_SCHEMA],
|
|
8171
8177
|
messages: {
|
|
8172
|
-
commentWall: "{{restated}} of this declaration's {{commented}} member comments only re-spell
|
|
8178
|
+
commentWall: "{{restated}} of this declaration's {{commented}} member comments only re-spell member names \u2014 delete them; if a row still needs narration, give the member a clearer name. Keep constraints, lifecycle, and rationale."
|
|
8173
8179
|
}
|
|
8174
8180
|
},
|
|
8175
8181
|
defaultOptions: [WALL_DEFAULTS],
|
|
@@ -8193,7 +8199,7 @@ var no_declaration_comment_wall_default = createRule({
|
|
|
8193
8199
|
const before = sourceCode.getTokenBefore(lead, { includeComments: false });
|
|
8194
8200
|
if (before === null || before.loc.end.line < lead.loc.start.line) {
|
|
8195
8201
|
const previousLine = endingOn.get(lead.loc.start.line - 1);
|
|
8196
|
-
if (lead.type ===
|
|
8202
|
+
if (lead.type === AST_TOKEN_TYPES2.Line && previousLine?.type === AST_TOKEN_TYPES2.Line && previousLine.loc.start.column === lead.loc.start.column) {
|
|
8197
8203
|
return void 0;
|
|
8198
8204
|
}
|
|
8199
8205
|
return lead;
|
|
@@ -8229,7 +8235,7 @@ var no_declaration_comment_wall_default = createRule({
|
|
|
8229
8235
|
claimed.add(comment);
|
|
8230
8236
|
commented += 1;
|
|
8231
8237
|
const body2 = commentBody(comment);
|
|
8232
|
-
if (body2.length === 0 || carriesValue(body2) || isTagsOnly(body2) || isLabel(body2)) {
|
|
8238
|
+
if (body2.length === 0 || hasJsDocTag(comment) || carriesValue(body2) || isTagsOnly(body2) || isLabel(body2)) {
|
|
8233
8239
|
continue;
|
|
8234
8240
|
}
|
|
8235
8241
|
const { end, start } = declarationRange(member.node);
|
|
@@ -8436,7 +8442,7 @@ var no_union_in_comment_default = createRule({
|
|
|
8436
8442
|
});
|
|
8437
8443
|
|
|
8438
8444
|
// src/rules/no-type-member-comment-wall.ts
|
|
8439
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES32, AST_TOKEN_TYPES as
|
|
8445
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES32, AST_TOKEN_TYPES as AST_TOKEN_TYPES3 } from "@typescript-eslint/utils";
|
|
8440
8446
|
var noTypeMemberCommentWallDocumentation = {
|
|
8441
8447
|
summary: "Flag an object type whose member comments mostly re-spell the members' own names and types.",
|
|
8442
8448
|
rationale: "Repetitive member comments add scanning cost while hiding the comments that describe facts absent from the type.",
|
|
@@ -8477,7 +8483,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
8477
8483
|
},
|
|
8478
8484
|
schema: [WALL_SCHEMA],
|
|
8479
8485
|
messages: {
|
|
8480
|
-
commentWall: "{{restated}} of this type's {{commented}} member comments only re-spell
|
|
8486
|
+
commentWall: "{{restated}} of this type's {{commented}} member comments only re-spell names and types \u2014 delete them; if a row still needs narration, improve its name or type. Keep constraints and rationale."
|
|
8481
8487
|
}
|
|
8482
8488
|
},
|
|
8483
8489
|
defaultOptions: [WALL_DEFAULTS],
|
|
@@ -8501,7 +8507,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
8501
8507
|
const before = sourceCode.getTokenBefore(lead, { includeComments: false });
|
|
8502
8508
|
if (before === null || before.loc.end.line < lead.loc.start.line) {
|
|
8503
8509
|
const previousLine = endingOn.get(lead.loc.start.line - 1);
|
|
8504
|
-
if (lead.type ===
|
|
8510
|
+
if (lead.type === AST_TOKEN_TYPES3.Line && previousLine?.type === AST_TOKEN_TYPES3.Line && previousLine.loc.start.column === lead.loc.start.column) {
|
|
8505
8511
|
return void 0;
|
|
8506
8512
|
}
|
|
8507
8513
|
return lead;
|
|
@@ -8535,7 +8541,9 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
8535
8541
|
claimed.add(comment);
|
|
8536
8542
|
commented += 1;
|
|
8537
8543
|
const body2 = commentBody(comment);
|
|
8538
|
-
if (body2.length === 0 || carriesValue(body2) || isTagsOnly(body2))
|
|
8544
|
+
if (body2.length === 0 || hasJsDocTag(comment) || carriesValue(body2) || isTagsOnly(body2)) {
|
|
8545
|
+
continue;
|
|
8546
|
+
}
|
|
8539
8547
|
if (novelWords(body2, knownTokens(sourceCode.getText(member))) <= options.maxNovelWords) {
|
|
8540
8548
|
restated += 1;
|
|
8541
8549
|
}
|
|
@@ -9345,8 +9353,98 @@ function unwrapExpression(node) {
|
|
|
9345
9353
|
return node;
|
|
9346
9354
|
}
|
|
9347
9355
|
|
|
9348
|
-
// src/rules/
|
|
9356
|
+
// src/rules/test-phase-label-comment.ts
|
|
9349
9357
|
import { AST_NODE_TYPES as AST_NODE_TYPES37 } from "@typescript-eslint/utils";
|
|
9358
|
+
var PHASE_WORD = String.raw`arrange|act|assert(?:ion)?s?|given|when|then|exercise|execute|verif(?:y|ication)|cleanup|prepare|sanity(?:\s+check)?`;
|
|
9359
|
+
var PHASE_RE = new RegExp(
|
|
9360
|
+
String.raw`^[-=~*_#.\s]{0,40}(?:${PHASE_WORD})(?:\s*(?:[/&+,|]|->|and)\s*(?:${PHASE_WORD}))*[-=~*_#.\s:;!–—]{0,40}$`,
|
|
9361
|
+
"iu"
|
|
9362
|
+
);
|
|
9363
|
+
var testPhaseLabelCommentDocumentation = {
|
|
9364
|
+
summary: "Tests must not use bare Arrange, Act, Assert, Given, When, or Then phase comments.",
|
|
9365
|
+
rationale: "Phase labels narrate test structure without explaining behavior and often hide unclear names or oversized tests.",
|
|
9366
|
+
remediation: "Delete the label; if the phases remain hard to follow, extract a named helper or split the test.",
|
|
9367
|
+
category: "testing",
|
|
9368
|
+
autofix: "safe",
|
|
9369
|
+
limitations: [
|
|
9370
|
+
"Only standalone line comments in recognized test files are checked.",
|
|
9371
|
+
"Comments inside bracketed expressions or containing words outside the bounded phase grammar are preserved."
|
|
9372
|
+
],
|
|
9373
|
+
examples: [
|
|
9374
|
+
{
|
|
9375
|
+
id: "behavioral-comment",
|
|
9376
|
+
title: "Behavioral consequence is retained",
|
|
9377
|
+
outcome: "no-match",
|
|
9378
|
+
files: [{ path: "widget.test.ts", source: "// Then the retry loop would spin forever.\nexpect(run()).toBe(true);" }],
|
|
9379
|
+
focusPath: "widget.test.ts",
|
|
9380
|
+
expectedCount: 0,
|
|
9381
|
+
public: true
|
|
9382
|
+
},
|
|
9383
|
+
{
|
|
9384
|
+
id: "bare-phase-label",
|
|
9385
|
+
title: "Bare phase label is removed",
|
|
9386
|
+
outcome: "match",
|
|
9387
|
+
files: [{ path: "widget.test.ts", source: "// Arrange\nconst widget = makeWidget();" }],
|
|
9388
|
+
focusPath: "widget.test.ts",
|
|
9389
|
+
expectedCount: 1,
|
|
9390
|
+
fixedFiles: [{ path: "widget.test.ts", source: "const widget = makeWidget();" }],
|
|
9391
|
+
public: true
|
|
9392
|
+
}
|
|
9393
|
+
]
|
|
9394
|
+
};
|
|
9395
|
+
function insideExpression(sourceCode, comment) {
|
|
9396
|
+
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
9397
|
+
if (token === null) return false;
|
|
9398
|
+
let node = sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
9399
|
+
while (node != null && node.type !== AST_NODE_TYPES37.Program) {
|
|
9400
|
+
if (node.type === AST_NODE_TYPES37.ArrayExpression || node.type === AST_NODE_TYPES37.ObjectExpression || node.type === AST_NODE_TYPES37.CallExpression || node.type === AST_NODE_TYPES37.NewExpression) return node.loc.start.line < comment.loc.start.line;
|
|
9401
|
+
if (/Statement$/u.test(node.type) || /Declaration$/u.test(node.type)) return false;
|
|
9402
|
+
node = node.parent;
|
|
9403
|
+
}
|
|
9404
|
+
return false;
|
|
9405
|
+
}
|
|
9406
|
+
function continuesProseRun(comments, index) {
|
|
9407
|
+
const comment = comments[index];
|
|
9408
|
+
if (comment?.type !== "Line") return false;
|
|
9409
|
+
return [comments[index - 1], comments[index + 1]].some(
|
|
9410
|
+
(neighbor) => neighbor?.type === "Line" && Math.abs(neighbor.loc.start.line - comment.loc.start.line) === 1 && !PHASE_RE.test(neighbor.value.trim())
|
|
9411
|
+
);
|
|
9412
|
+
}
|
|
9413
|
+
var test_phase_label_comment_default = createRule({
|
|
9414
|
+
name: "test-phase-label-comment",
|
|
9415
|
+
documentation: testPhaseLabelCommentDocumentation,
|
|
9416
|
+
meta: {
|
|
9417
|
+
type: "suggestion",
|
|
9418
|
+
fixable: "code",
|
|
9419
|
+
docs: { description: testPhaseLabelCommentDocumentation.summary },
|
|
9420
|
+
schema: [],
|
|
9421
|
+
messages: { removeLabel: "Bare test phase label \u2014 delete it and let the test names and helpers carry the structure." }
|
|
9422
|
+
},
|
|
9423
|
+
defaultOptions: [],
|
|
9424
|
+
create(context) {
|
|
9425
|
+
if (!isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text)) return {};
|
|
9426
|
+
return {
|
|
9427
|
+
Program() {
|
|
9428
|
+
const comments = context.sourceCode.getAllComments();
|
|
9429
|
+
for (const [index, comment] of comments.entries()) {
|
|
9430
|
+
if (comment.type !== "Line" || !PHASE_RE.test(comment.value.trim())) continue;
|
|
9431
|
+
const removal = wholeLineRemovalRange(context.sourceCode.text, comment);
|
|
9432
|
+
if (removal === null || insideExpression(context.sourceCode, comment) || continuesProseRun(comments, index)) {
|
|
9433
|
+
continue;
|
|
9434
|
+
}
|
|
9435
|
+
context.report({
|
|
9436
|
+
node: comment,
|
|
9437
|
+
messageId: "removeLabel",
|
|
9438
|
+
fix: (fixer) => fixer.removeRange(removal.range)
|
|
9439
|
+
});
|
|
9440
|
+
}
|
|
9441
|
+
}
|
|
9442
|
+
};
|
|
9443
|
+
}
|
|
9444
|
+
});
|
|
9445
|
+
|
|
9446
|
+
// src/rules/prefer-constant-time-secret-compare.ts
|
|
9447
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES38 } from "@typescript-eslint/utils";
|
|
9350
9448
|
var preferConstantTimeSecretCompareDocumentation = {
|
|
9351
9449
|
summary: "Disallow `===`/`!==` on a secret-like value; short-circuiting comparison leaks the secret through timing. Use a constant-time compare.",
|
|
9352
9450
|
rationale: "Ordinary equality stops at the first differing byte, allowing repeated measurements to reveal secret material.",
|
|
@@ -9365,14 +9463,14 @@ var SENTINEL_PREFIX_RE = /^(skip|sentinel|empty|none|missing|unset|placeholder|d
|
|
|
9365
9463
|
var AST_NODE_TYPE_RE = /^(?:TS|JSX)?[A-Z][A-Za-z]*(?:Signature|Keyword|Expression|Declaration|Element|Literal|Identifier)$/;
|
|
9366
9464
|
function isExcludedOperand(node) {
|
|
9367
9465
|
switch (node.type) {
|
|
9368
|
-
case
|
|
9466
|
+
case AST_NODE_TYPES38.Literal:
|
|
9369
9467
|
return true;
|
|
9370
|
-
case
|
|
9468
|
+
case AST_NODE_TYPES38.TemplateLiteral:
|
|
9371
9469
|
return node.expressions.length === 0;
|
|
9372
|
-
case
|
|
9470
|
+
case AST_NODE_TYPES38.Identifier:
|
|
9373
9471
|
return SENTINEL_IDENTIFIERS.has(node.name) || SENTINEL_PREFIX_RE.test(node.name) || isConstantReference(node.name);
|
|
9374
|
-
case
|
|
9375
|
-
return !node.computed && node.property.type ===
|
|
9472
|
+
case AST_NODE_TYPES38.MemberExpression:
|
|
9473
|
+
return !node.computed && node.property.type === AST_NODE_TYPES38.Identifier && (SENTINEL_PREFIX_RE.test(node.property.name) || isConstantReference(node.property.name));
|
|
9376
9474
|
default:
|
|
9377
9475
|
return false;
|
|
9378
9476
|
}
|
|
@@ -9383,23 +9481,23 @@ function isConstantReference(identifier) {
|
|
|
9383
9481
|
return identifier === identifier.toUpperCase() && /[A-Za-z]/.test(identifier);
|
|
9384
9482
|
}
|
|
9385
9483
|
function operandName(node) {
|
|
9386
|
-
if (node.type ===
|
|
9484
|
+
if (node.type === AST_NODE_TYPES38.Identifier) {
|
|
9387
9485
|
return node.name;
|
|
9388
9486
|
}
|
|
9389
|
-
if (node.type ===
|
|
9487
|
+
if (node.type === AST_NODE_TYPES38.MemberExpression && !node.computed && node.property.type === AST_NODE_TYPES38.Identifier) {
|
|
9390
9488
|
return node.property.name;
|
|
9391
9489
|
}
|
|
9392
9490
|
return null;
|
|
9393
9491
|
}
|
|
9394
9492
|
function isSecretOperand(node) {
|
|
9395
|
-
if (node.type ===
|
|
9493
|
+
if (node.type === AST_NODE_TYPES38.TemplateLiteral) {
|
|
9396
9494
|
return node.expressions.some((expression) => isSecretOperand(expression));
|
|
9397
9495
|
}
|
|
9398
9496
|
const name = operandName(node);
|
|
9399
9497
|
return name !== null && isAuthSecretName(name);
|
|
9400
9498
|
}
|
|
9401
9499
|
function secretNameOf(node) {
|
|
9402
|
-
if (node.type ===
|
|
9500
|
+
if (node.type === AST_NODE_TYPES38.TemplateLiteral) {
|
|
9403
9501
|
for (const expression of node.expressions) {
|
|
9404
9502
|
const nested = secretNameOf(expression);
|
|
9405
9503
|
if (nested !== null) {
|
|
@@ -9453,7 +9551,7 @@ var prefer_constant_time_secret_compare_default = createRule({
|
|
|
9453
9551
|
|
|
9454
9552
|
// src/rules/prefer-discriminated-union.ts
|
|
9455
9553
|
import "@typescript-eslint/utils";
|
|
9456
|
-
import { AST_NODE_TYPES as
|
|
9554
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES39 } from "@typescript-eslint/utils";
|
|
9457
9555
|
var preferDiscriminatedUnionDocumentation = {
|
|
9458
9556
|
summary: "Flag flat result objects with a required positive boolean status and optional success/failure payloads.",
|
|
9459
9557
|
rationale: "A boolean status plus optional branch data permits contradictory and incomplete states.",
|
|
@@ -9485,13 +9583,13 @@ var SUCCESS_PAYLOAD_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
|
9485
9583
|
]);
|
|
9486
9584
|
var REQUIRED_STATUS_MEMBER_COUNT = 1;
|
|
9487
9585
|
var FUNCTION_RETURN_OWNER_TYPES = /* @__PURE__ */ new Set([
|
|
9488
|
-
|
|
9489
|
-
|
|
9490
|
-
|
|
9491
|
-
|
|
9492
|
-
|
|
9493
|
-
|
|
9494
|
-
|
|
9586
|
+
AST_NODE_TYPES39.ArrowFunctionExpression,
|
|
9587
|
+
AST_NODE_TYPES39.FunctionDeclaration,
|
|
9588
|
+
AST_NODE_TYPES39.FunctionExpression,
|
|
9589
|
+
AST_NODE_TYPES39.TSDeclareFunction,
|
|
9590
|
+
AST_NODE_TYPES39.TSEmptyBodyFunctionExpression,
|
|
9591
|
+
AST_NODE_TYPES39.TSFunctionType,
|
|
9592
|
+
AST_NODE_TYPES39.TSMethodSignature
|
|
9495
9593
|
]);
|
|
9496
9594
|
function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
9497
9595
|
let statusMemberCount = 0;
|
|
@@ -9499,7 +9597,7 @@ function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
|
9499
9597
|
let hasSuccessPayload = false;
|
|
9500
9598
|
let hasUnrecognizedMember = false;
|
|
9501
9599
|
for (const member of typeLiteral.members) {
|
|
9502
|
-
if (member.type !==
|
|
9600
|
+
if (member.type !== AST_NODE_TYPES39.TSPropertySignature) {
|
|
9503
9601
|
hasUnrecognizedMember = true;
|
|
9504
9602
|
continue;
|
|
9505
9603
|
}
|
|
@@ -9523,26 +9621,26 @@ function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
|
9523
9621
|
return statusMemberCount === REQUIRED_STATUS_MEMBER_COUNT && hasFailurePayload && (hasSuccessPayload || !hasUnrecognizedMember);
|
|
9524
9622
|
}
|
|
9525
9623
|
function getMemberName(member) {
|
|
9526
|
-
if (member.type !==
|
|
9624
|
+
if (member.type !== AST_NODE_TYPES39.TSPropertySignature) {
|
|
9527
9625
|
return null;
|
|
9528
9626
|
}
|
|
9529
9627
|
const { key } = member;
|
|
9530
|
-
if (key.type ===
|
|
9628
|
+
if (key.type === AST_NODE_TYPES39.Identifier) {
|
|
9531
9629
|
return key.name;
|
|
9532
9630
|
}
|
|
9533
|
-
if (key.type ===
|
|
9631
|
+
if (key.type === AST_NODE_TYPES39.Literal && typeof key.value === "string") {
|
|
9534
9632
|
return key.value;
|
|
9535
9633
|
}
|
|
9536
9634
|
return null;
|
|
9537
9635
|
}
|
|
9538
9636
|
function isBooleanTyped(member) {
|
|
9539
|
-
return member.typeAnnotation?.typeAnnotation.type ===
|
|
9637
|
+
return member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES39.TSBooleanKeyword;
|
|
9540
9638
|
}
|
|
9541
9639
|
function inlineReturnTypeLiteral(node) {
|
|
9542
9640
|
let annotation = null;
|
|
9543
|
-
if (node.parent.type ===
|
|
9641
|
+
if (node.parent.type === AST_NODE_TYPES39.TSTypeAnnotation) {
|
|
9544
9642
|
annotation = node.parent;
|
|
9545
|
-
} else if (node.parent.type ===
|
|
9643
|
+
} else if (node.parent.type === AST_NODE_TYPES39.TSTypeParameterInstantiation && node.parent.params.length === 1 && node.parent.params[0] === node && node.parent.parent.type === AST_NODE_TYPES39.TSTypeReference && node.parent.parent.typeName.type === AST_NODE_TYPES39.Identifier && node.parent.parent.typeName.name === "Promise" && node.parent.parent.parent.type === AST_NODE_TYPES39.TSTypeAnnotation) {
|
|
9546
9644
|
annotation = node.parent.parent.parent;
|
|
9547
9645
|
}
|
|
9548
9646
|
if (annotation === null) return null;
|
|
@@ -9582,7 +9680,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
9582
9680
|
}
|
|
9583
9681
|
const synthetic = {
|
|
9584
9682
|
...node.body,
|
|
9585
|
-
type:
|
|
9683
|
+
type: AST_NODE_TYPES39.TSTypeLiteral,
|
|
9586
9684
|
members: node.body.body
|
|
9587
9685
|
};
|
|
9588
9686
|
checkTypeLiteral(synthetic, node);
|
|
@@ -9599,7 +9697,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
9599
9697
|
});
|
|
9600
9698
|
|
|
9601
9699
|
// src/rules/prefer-input-group-search.ts
|
|
9602
|
-
import { AST_NODE_TYPES as
|
|
9700
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES40 } from "@typescript-eslint/utils";
|
|
9603
9701
|
var preferInputGroupSearchDocumentation = {
|
|
9604
9702
|
summary: "Require search icons and shared Input controls in the same visual wrapper to use InputGroup.",
|
|
9605
9703
|
rationale: "The shared compound control provides consistent spacing, focus behavior, and accessible composition.",
|
|
@@ -9620,15 +9718,15 @@ var MAX_JSX_DISTANCE = 2;
|
|
|
9620
9718
|
var SEARCH_EXPORTS = ["Search", "SearchIcon", "LucideSearch"];
|
|
9621
9719
|
function localNamedImports(node, importedName4) {
|
|
9622
9720
|
return node.specifiers.filter(
|
|
9623
|
-
(specifier) => specifier.type ===
|
|
9721
|
+
(specifier) => specifier.type === AST_NODE_TYPES40.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES40.Identifier ? specifier.imported.name : specifier.imported.value) === importedName4
|
|
9624
9722
|
).map((specifier) => specifier.local.name);
|
|
9625
9723
|
}
|
|
9626
9724
|
function elementName(node) {
|
|
9627
|
-
return node.name.type ===
|
|
9725
|
+
return node.name.type === AST_NODE_TYPES40.JSXIdentifier ? node.name.name : null;
|
|
9628
9726
|
}
|
|
9629
9727
|
function jsxAncestors(occurrence) {
|
|
9630
9728
|
return occurrence.ancestors.filter(
|
|
9631
|
-
(ancestor) => ancestor.type ===
|
|
9729
|
+
(ancestor) => ancestor.type === AST_NODE_TYPES40.JSXElement
|
|
9632
9730
|
);
|
|
9633
9731
|
}
|
|
9634
9732
|
function isWithinInputGroup(occurrence, inputGroupNames) {
|
|
@@ -9741,7 +9839,7 @@ var prefer_input_group_search_default = createRule({
|
|
|
9741
9839
|
});
|
|
9742
9840
|
|
|
9743
9841
|
// src/rules/prefer-immutable-module-constant.ts
|
|
9744
|
-
import { AST_NODE_TYPES as
|
|
9842
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES41, ASTUtils as ASTUtils11 } from "@typescript-eslint/utils";
|
|
9745
9843
|
var preferImmutableModuleConstantDocumentation = {
|
|
9746
9844
|
summary: "Require module-level constant collections to expose readonly state.",
|
|
9747
9845
|
rationale: "A const binding prevents reassignment but does not stop callers from mutating its array, object, Set, or Map contents.",
|
|
@@ -9789,59 +9887,59 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
|
9789
9887
|
"unshift"
|
|
9790
9888
|
]);
|
|
9791
9889
|
function isAsConst(node, sourceText) {
|
|
9792
|
-
if (node.type ===
|
|
9890
|
+
if (node.type === AST_NODE_TYPES41.TSSatisfiesExpression || node.type === AST_NODE_TYPES41.TSNonNullExpression) {
|
|
9793
9891
|
return isAsConst(node.expression, sourceText);
|
|
9794
9892
|
}
|
|
9795
|
-
if (node.type !==
|
|
9893
|
+
if (node.type !== AST_NODE_TYPES41.TSAsExpression) return false;
|
|
9796
9894
|
return sourceText(node.typeAnnotation).trim() === "const";
|
|
9797
9895
|
}
|
|
9798
9896
|
function unwrapExpression2(node) {
|
|
9799
|
-
if (node.type ===
|
|
9897
|
+
if (node.type === AST_NODE_TYPES41.TSAsExpression || node.type === AST_NODE_TYPES41.TSSatisfiesExpression || node.type === AST_NODE_TYPES41.TSNonNullExpression) {
|
|
9800
9898
|
return unwrapExpression2(node.expression);
|
|
9801
9899
|
}
|
|
9802
9900
|
return node;
|
|
9803
9901
|
}
|
|
9804
9902
|
function isObjectFreeze(node, isUnshadowedGlobal) {
|
|
9805
9903
|
const inner = unwrapExpression2(node);
|
|
9806
|
-
if (inner.type ===
|
|
9904
|
+
if (inner.type === AST_NODE_TYPES41.CallExpression && inner.callee.type === AST_NODE_TYPES41.MemberExpression && !inner.callee.computed && inner.callee.object.type === AST_NODE_TYPES41.Identifier && inner.callee.object.name === "Object" && isUnshadowedGlobal(inner.callee.object) && inner.callee.property.type === AST_NODE_TYPES41.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1) {
|
|
9807
9905
|
const argument = inner.arguments[0];
|
|
9808
|
-
return argument !== void 0 && argument.type !==
|
|
9906
|
+
return argument !== void 0 && argument.type !== AST_NODE_TYPES41.SpreadElement && collectionKind(argument, isUnshadowedGlobal) === "literal";
|
|
9809
9907
|
}
|
|
9810
9908
|
return false;
|
|
9811
9909
|
}
|
|
9812
9910
|
function collectionKind(node, isUnshadowedGlobal) {
|
|
9813
9911
|
const inner = unwrapExpression2(node);
|
|
9814
|
-
if (inner.type ===
|
|
9912
|
+
if (inner.type === AST_NODE_TYPES41.CallExpression && inner.callee.type === AST_NODE_TYPES41.MemberExpression && !inner.callee.computed && inner.callee.object.type === AST_NODE_TYPES41.Identifier && inner.callee.object.name === "Object" && isUnshadowedGlobal(inner.callee.object) && inner.callee.property.type === AST_NODE_TYPES41.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== AST_NODE_TYPES41.SpreadElement) {
|
|
9815
9913
|
return collectionKind(inner.arguments[0], isUnshadowedGlobal);
|
|
9816
9914
|
}
|
|
9817
|
-
if (inner.type ===
|
|
9915
|
+
if (inner.type === AST_NODE_TYPES41.ArrayExpression || inner.type === AST_NODE_TYPES41.ObjectExpression) {
|
|
9818
9916
|
return "literal";
|
|
9819
9917
|
}
|
|
9820
|
-
if (inner.type ===
|
|
9918
|
+
if (inner.type === AST_NODE_TYPES41.NewExpression && inner.callee.type === AST_NODE_TYPES41.Identifier && (inner.callee.name === "Set" || inner.callee.name === "Map") && isUnshadowedGlobal(inner.callee)) {
|
|
9821
9919
|
return inner.callee.name;
|
|
9822
9920
|
}
|
|
9823
9921
|
return null;
|
|
9824
9922
|
}
|
|
9825
9923
|
function declaredReadonlyType(node, kind, aliases) {
|
|
9826
|
-
const annotation = node.id.type ===
|
|
9924
|
+
const annotation = node.id.type === AST_NODE_TYPES41.Identifier ? node.id.typeAnnotation : void 0;
|
|
9827
9925
|
if (annotation !== void 0 && isReadonlyTypeResolved(annotation.typeAnnotation, kind, aliases)) {
|
|
9828
9926
|
return true;
|
|
9829
9927
|
}
|
|
9830
|
-
return node.init?.type ===
|
|
9928
|
+
return node.init?.type === AST_NODE_TYPES41.TSAsExpression && isReadonlyTypeResolved(node.init.typeAnnotation, kind, aliases);
|
|
9831
9929
|
}
|
|
9832
9930
|
function isReadonlyTypeResolved(node, kind, aliases, seen = /* @__PURE__ */ new Set()) {
|
|
9833
9931
|
if (isReadonlyType(node, kind)) return true;
|
|
9834
|
-
if (node.type !==
|
|
9932
|
+
if (node.type !== AST_NODE_TYPES41.TSTypeReference || node.typeName.type !== AST_NODE_TYPES41.Identifier) return false;
|
|
9835
9933
|
const name = node.typeName.name;
|
|
9836
9934
|
const target = aliases.get(name);
|
|
9837
9935
|
if (target === void 0 || seen.has(name)) return false;
|
|
9838
9936
|
return isReadonlyTypeResolved(target, kind, aliases, /* @__PURE__ */ new Set([...seen, name]));
|
|
9839
9937
|
}
|
|
9840
9938
|
function isReadonlyType(node, kind) {
|
|
9841
|
-
if (node.type ===
|
|
9939
|
+
if (node.type === AST_NODE_TYPES41.TSTypeOperator && node.operator === "readonly") {
|
|
9842
9940
|
return true;
|
|
9843
9941
|
}
|
|
9844
|
-
if (node.type !==
|
|
9942
|
+
if (node.type !== AST_NODE_TYPES41.TSTypeReference || node.typeName.type !== AST_NODE_TYPES41.Identifier) {
|
|
9845
9943
|
return false;
|
|
9846
9944
|
}
|
|
9847
9945
|
if (node.typeName.name === "Readonly") {
|
|
@@ -9850,31 +9948,31 @@ function isReadonlyType(node, kind) {
|
|
|
9850
9948
|
return kind === "literal" ? node.typeName.name === "ReadonlyArray" : node.typeName.name === `Readonly${kind}`;
|
|
9851
9949
|
}
|
|
9852
9950
|
function hasUnknownExplicitType(node, aliases) {
|
|
9853
|
-
const annotation = node.id.type ===
|
|
9951
|
+
const annotation = node.id.type === AST_NODE_TYPES41.Identifier ? node.id.typeAnnotation?.typeAnnotation : void 0;
|
|
9854
9952
|
if (annotation === void 0) return false;
|
|
9855
|
-
if (annotation.type ===
|
|
9856
|
-
if (annotation.type !==
|
|
9953
|
+
if (annotation.type === AST_NODE_TYPES41.TSArrayType || annotation.type === AST_NODE_TYPES41.TSTypeOperator) return false;
|
|
9954
|
+
if (annotation.type !== AST_NODE_TYPES41.TSTypeReference || annotation.typeName.type !== AST_NODE_TYPES41.Identifier) return true;
|
|
9857
9955
|
return !aliases.has(annotation.typeName.name) && !["Array", "Map", "Readonly", "ReadonlyArray", "ReadonlyMap", "ReadonlySet", "Set"].includes(annotation.typeName.name);
|
|
9858
9956
|
}
|
|
9859
9957
|
function referenceMutates(identifier, isUnshadowedGlobal) {
|
|
9860
9958
|
let member = identifier.parent;
|
|
9861
|
-
if (member?.type !==
|
|
9862
|
-
return member?.type ===
|
|
9959
|
+
if (member?.type !== AST_NODE_TYPES41.MemberExpression || member.object !== identifier) {
|
|
9960
|
+
return member?.type === AST_NODE_TYPES41.CallExpression && member.arguments[0] === identifier && member.callee.type === AST_NODE_TYPES41.MemberExpression && !member.callee.computed && member.callee.object.type === AST_NODE_TYPES41.Identifier && member.callee.object.name === "Object" && isUnshadowedGlobal(member.callee.object) && member.callee.property.type === AST_NODE_TYPES41.Identifier && member.callee.property.name === "assign";
|
|
9863
9961
|
}
|
|
9864
|
-
while (member.parent.type ===
|
|
9962
|
+
while (member.parent.type === AST_NODE_TYPES41.MemberExpression && member.parent.object === member) {
|
|
9865
9963
|
member = member.parent;
|
|
9866
9964
|
}
|
|
9867
9965
|
const parent = member.parent;
|
|
9868
|
-
if (parent?.type ===
|
|
9966
|
+
if (parent?.type === AST_NODE_TYPES41.AssignmentExpression && parent.left === member) {
|
|
9869
9967
|
return true;
|
|
9870
9968
|
}
|
|
9871
|
-
if (parent?.type ===
|
|
9969
|
+
if (parent?.type === AST_NODE_TYPES41.UpdateExpression && parent.argument === member) {
|
|
9872
9970
|
return true;
|
|
9873
9971
|
}
|
|
9874
|
-
if (parent?.type ===
|
|
9972
|
+
if (parent?.type === AST_NODE_TYPES41.UnaryExpression && parent.operator === "delete" && parent.argument === member) {
|
|
9875
9973
|
return true;
|
|
9876
9974
|
}
|
|
9877
|
-
return parent?.type ===
|
|
9975
|
+
return parent?.type === AST_NODE_TYPES41.CallExpression && parent.callee === member && (member.property.type === AST_NODE_TYPES41.Identifier && !member.computed || member.property.type === AST_NODE_TYPES41.Literal && typeof member.property.value === "string") && MUTATING_METHODS.has(member.property.type === AST_NODE_TYPES41.Identifier ? member.property.name : member.property.value);
|
|
9878
9976
|
}
|
|
9879
9977
|
var prefer_immutable_module_constant_default = createRule({
|
|
9880
9978
|
name: "prefer-immutable-module-constant",
|
|
@@ -9911,10 +10009,10 @@ var prefer_immutable_module_constant_default = createRule({
|
|
|
9911
10009
|
seen.add(variable);
|
|
9912
10010
|
for (const reference of variable.references) {
|
|
9913
10011
|
const identifier = reference.identifier;
|
|
9914
|
-
if (identifier.type !==
|
|
10012
|
+
if (identifier.type !== AST_NODE_TYPES41.Identifier) continue;
|
|
9915
10013
|
if (referenceMutates(identifier, isUnshadowedGlobal)) return true;
|
|
9916
10014
|
const declarator = identifier.parent;
|
|
9917
|
-
if (declarator.type !==
|
|
10015
|
+
if (declarator.type !== AST_NODE_TYPES41.VariableDeclarator || declarator.init !== identifier || declarator.id.type !== AST_NODE_TYPES41.Identifier || declarator.parent.type !== AST_NODE_TYPES41.VariableDeclaration || declarator.parent.kind !== "const") {
|
|
9918
10016
|
continue;
|
|
9919
10017
|
}
|
|
9920
10018
|
const alias = sourceCode.getDeclaredVariables(declarator)[0];
|
|
@@ -9926,32 +10024,32 @@ var prefer_immutable_module_constant_default = createRule({
|
|
|
9926
10024
|
return {
|
|
9927
10025
|
Program(node) {
|
|
9928
10026
|
for (const statement of node.body) {
|
|
9929
|
-
const declaration = statement.type ===
|
|
9930
|
-
if (declaration?.type ===
|
|
10027
|
+
const declaration = statement.type === AST_NODE_TYPES41.ExportNamedDeclaration ? statement.declaration : statement;
|
|
10028
|
+
if (declaration?.type === AST_NODE_TYPES41.TSTypeAliasDeclaration) {
|
|
9931
10029
|
typeAliases2.set(declaration.id.name, declaration.typeAnnotation);
|
|
9932
10030
|
}
|
|
9933
|
-
if (statement.type ===
|
|
10031
|
+
if (statement.type === AST_NODE_TYPES41.ExportNamedDeclaration) {
|
|
9934
10032
|
if (statement.source !== null || statement.exportKind === "type") continue;
|
|
9935
10033
|
for (const specifier of statement.specifiers) {
|
|
9936
|
-
if (specifier.type ===
|
|
10034
|
+
if (specifier.type === AST_NODE_TYPES41.ExportSpecifier && specifier.exportKind !== "type" && specifier.local.type === AST_NODE_TYPES41.Identifier) {
|
|
9937
10035
|
exportedNames2.add(specifier.local.name);
|
|
9938
10036
|
}
|
|
9939
10037
|
}
|
|
9940
|
-
} else if (statement.type ===
|
|
10038
|
+
} else if (statement.type === AST_NODE_TYPES41.ExportDefaultDeclaration && unwrapTransparentExport(statement.declaration)?.type === AST_NODE_TYPES41.Identifier) {
|
|
9941
10039
|
exportedNames2.add(unwrapTransparentExport(statement.declaration).name);
|
|
9942
10040
|
}
|
|
9943
10041
|
}
|
|
9944
10042
|
},
|
|
9945
10043
|
VariableDeclarator(node) {
|
|
9946
10044
|
const declaration = node.parent;
|
|
9947
|
-
if (declaration.type !==
|
|
10045
|
+
if (declaration.type !== AST_NODE_TYPES41.VariableDeclaration || declaration.kind !== "const" || node.id.type !== AST_NODE_TYPES41.Identifier || node.init === null) {
|
|
9948
10046
|
return;
|
|
9949
10047
|
}
|
|
9950
10048
|
const container = declaration.parent;
|
|
9951
|
-
if (container.type !==
|
|
10049
|
+
if (container.type !== AST_NODE_TYPES41.Program && !(container.type === AST_NODE_TYPES41.ExportNamedDeclaration && container.parent.type === AST_NODE_TYPES41.Program)) {
|
|
9952
10050
|
return;
|
|
9953
10051
|
}
|
|
9954
|
-
const directlyExported = container.type ===
|
|
10052
|
+
const directlyExported = container.type === AST_NODE_TYPES41.ExportNamedDeclaration;
|
|
9955
10053
|
if (!CONSTANT_NAME.test(node.id.name) && !directlyExported && !exportedNames2.has(node.id.name)) {
|
|
9956
10054
|
return;
|
|
9957
10055
|
}
|
|
@@ -9976,14 +10074,14 @@ var prefer_immutable_module_constant_default = createRule({
|
|
|
9976
10074
|
}
|
|
9977
10075
|
});
|
|
9978
10076
|
function unwrapTransparentExport(node) {
|
|
9979
|
-
if (node.type ===
|
|
10077
|
+
if (node.type === AST_NODE_TYPES41.TSSatisfiesExpression || node.type === AST_NODE_TYPES41.TSNonNullExpression) {
|
|
9980
10078
|
return unwrapTransparentExport(node.expression);
|
|
9981
10079
|
}
|
|
9982
10080
|
return node;
|
|
9983
10081
|
}
|
|
9984
10082
|
|
|
9985
10083
|
// src/rules/prefer-shadcn-primitives.ts
|
|
9986
|
-
import { AST_NODE_TYPES as
|
|
10084
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES42 } from "@typescript-eslint/utils";
|
|
9987
10085
|
var preferShadcnPrimitivesDocumentation = {
|
|
9988
10086
|
summary: "Require visible raw JSX controls to use the corresponding shared shadcn primitive.",
|
|
9989
10087
|
rationale: "Shared primitives centralize interaction, accessibility, and visual behavior across the product.",
|
|
@@ -10028,16 +10126,16 @@ var AMBIGUOUS_INPUT_TYPES = /* @__PURE__ */ new Set([
|
|
|
10028
10126
|
"submit"
|
|
10029
10127
|
]);
|
|
10030
10128
|
function rawElementName(node) {
|
|
10031
|
-
if (node.name.type !==
|
|
10129
|
+
if (node.name.type !== AST_NODE_TYPES42.JSXIdentifier) return null;
|
|
10032
10130
|
const name = node.name.name;
|
|
10033
10131
|
return Object.hasOwn(SHADCN_PRIMITIVES, name) ? name : null;
|
|
10034
10132
|
}
|
|
10035
10133
|
function effectiveAttribute(node, attributeName) {
|
|
10036
10134
|
for (const attribute of node.attributes.toReversed()) {
|
|
10037
|
-
if (attribute.type ===
|
|
10135
|
+
if (attribute.type === AST_NODE_TYPES42.JSXSpreadAttribute) {
|
|
10038
10136
|
return { kind: "unknown" };
|
|
10039
10137
|
}
|
|
10040
|
-
if (attribute.name.type !==
|
|
10138
|
+
if (attribute.name.type !== AST_NODE_TYPES42.JSXIdentifier || attribute.name.name !== attributeName) {
|
|
10041
10139
|
continue;
|
|
10042
10140
|
}
|
|
10043
10141
|
const value = staticString(attribute.value);
|
|
@@ -10046,17 +10144,17 @@ function effectiveAttribute(node, attributeName) {
|
|
|
10046
10144
|
return { kind: "missing" };
|
|
10047
10145
|
}
|
|
10048
10146
|
function staticString(value) {
|
|
10049
|
-
if (value?.type ===
|
|
10147
|
+
if (value?.type === AST_NODE_TYPES42.Literal) {
|
|
10050
10148
|
return typeof value.value === "string" ? value.value : null;
|
|
10051
10149
|
}
|
|
10052
|
-
if (value?.type !==
|
|
10150
|
+
if (value?.type !== AST_NODE_TYPES42.JSXExpressionContainer) return null;
|
|
10053
10151
|
return staticExpressionString(value.expression);
|
|
10054
10152
|
}
|
|
10055
10153
|
function staticExpressionString(expression) {
|
|
10056
|
-
if (expression.type ===
|
|
10154
|
+
if (expression.type === AST_NODE_TYPES42.Literal) {
|
|
10057
10155
|
return typeof expression.value === "string" ? expression.value : null;
|
|
10058
10156
|
}
|
|
10059
|
-
if (expression.type ===
|
|
10157
|
+
if (expression.type === AST_NODE_TYPES42.TemplateLiteral) {
|
|
10060
10158
|
let value = expression.quasis[0]?.value.cooked ?? "";
|
|
10061
10159
|
for (const [index, substitution] of expression.expressions.entries()) {
|
|
10062
10160
|
const staticSubstitution = staticExpressionString(substitution);
|
|
@@ -10066,13 +10164,13 @@ function staticExpressionString(expression) {
|
|
|
10066
10164
|
}
|
|
10067
10165
|
return value;
|
|
10068
10166
|
}
|
|
10069
|
-
if (expression.type ===
|
|
10167
|
+
if (expression.type === AST_NODE_TYPES42.TSAsExpression || expression.type === AST_NODE_TYPES42.TSNonNullExpression || expression.type === AST_NODE_TYPES42.TSSatisfiesExpression || expression.type === AST_NODE_TYPES42.TSTypeAssertion) {
|
|
10070
10168
|
return staticExpressionString(expression.expression);
|
|
10071
10169
|
}
|
|
10072
10170
|
return null;
|
|
10073
10171
|
}
|
|
10074
10172
|
function isLabelableElement(node) {
|
|
10075
|
-
if (node.openingElement.name.type !==
|
|
10173
|
+
if (node.openingElement.name.type !== AST_NODE_TYPES42.JSXIdentifier) {
|
|
10076
10174
|
return false;
|
|
10077
10175
|
}
|
|
10078
10176
|
const name = node.openingElement.name.name;
|
|
@@ -10084,10 +10182,10 @@ function isLabelableElement(node) {
|
|
|
10084
10182
|
}
|
|
10085
10183
|
function containsLabelableElement(node) {
|
|
10086
10184
|
return node.children.some((child) => {
|
|
10087
|
-
if (child.type ===
|
|
10185
|
+
if (child.type === AST_NODE_TYPES42.JSXElement) {
|
|
10088
10186
|
return isLabelableElement(child) || containsLabelableElement(child);
|
|
10089
10187
|
}
|
|
10090
|
-
if (child.type ===
|
|
10188
|
+
if (child.type === AST_NODE_TYPES42.JSXFragment) {
|
|
10091
10189
|
return containsLabelableElement(child);
|
|
10092
10190
|
}
|
|
10093
10191
|
return false;
|
|
@@ -10096,7 +10194,7 @@ function containsLabelableElement(node) {
|
|
|
10096
10194
|
function isStaticallyAssociatedLabel(node) {
|
|
10097
10195
|
const htmlFor = effectiveAttribute(node, "htmlFor");
|
|
10098
10196
|
if (htmlFor.kind === "known" && htmlFor.value.trim().length > 0) return true;
|
|
10099
|
-
return node.parent.type ===
|
|
10197
|
+
return node.parent.type === AST_NODE_TYPES42.JSXElement && containsLabelableElement(node.parent);
|
|
10100
10198
|
}
|
|
10101
10199
|
function replacementFor(node, element) {
|
|
10102
10200
|
if (element !== "input") return SHADCN_PRIMITIVES[element];
|
|
@@ -10167,7 +10265,7 @@ var prefer_shadcn_primitives_default = createRule({
|
|
|
10167
10265
|
});
|
|
10168
10266
|
|
|
10169
10267
|
// src/rules/prefer-module-level-constant.ts
|
|
10170
|
-
import { AST_NODE_TYPES as
|
|
10268
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES43 } from "@typescript-eslint/utils";
|
|
10171
10269
|
var preferModuleLevelConstantDocumentation = {
|
|
10172
10270
|
summary: "Hoist literal-only constant collections and regexes out of function bodies to module scope so they are allocated once.",
|
|
10173
10271
|
rationale: "Recreating immutable lookup data on every call wastes allocations and obscures its constant nature.",
|
|
@@ -10207,9 +10305,9 @@ var MUTATING_METHODS2 = /* @__PURE__ */ new Set([
|
|
|
10207
10305
|
"assign"
|
|
10208
10306
|
]);
|
|
10209
10307
|
var FUNCTION_TYPES7 = /* @__PURE__ */ new Set([
|
|
10210
|
-
|
|
10211
|
-
|
|
10212
|
-
|
|
10308
|
+
AST_NODE_TYPES43.FunctionDeclaration,
|
|
10309
|
+
AST_NODE_TYPES43.FunctionExpression,
|
|
10310
|
+
AST_NODE_TYPES43.ArrowFunctionExpression
|
|
10213
10311
|
]);
|
|
10214
10312
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
10215
10313
|
function isIgnoredFile2(filename, sourceText) {
|
|
@@ -10222,14 +10320,14 @@ function isLocalFixtureFile(filename) {
|
|
|
10222
10320
|
return isTestFile(filename) || isStoryFile(filename);
|
|
10223
10321
|
}
|
|
10224
10322
|
function unwrap3(node) {
|
|
10225
|
-
if (node.type ===
|
|
10323
|
+
if (node.type === AST_NODE_TYPES43.TSAsExpression || node.type === AST_NODE_TYPES43.TSSatisfiesExpression || node.type === AST_NODE_TYPES43.TSNonNullExpression) {
|
|
10226
10324
|
return unwrap3(node.expression);
|
|
10227
10325
|
}
|
|
10228
10326
|
return node;
|
|
10229
10327
|
}
|
|
10230
10328
|
var HAS_STATEFUL_FLAG_RE = /[gy]/;
|
|
10231
10329
|
function isRegexLiteral(node) {
|
|
10232
|
-
return node.type ===
|
|
10330
|
+
return node.type === AST_NODE_TYPES43.Literal && "regex" in node && node.regex !== void 0;
|
|
10233
10331
|
}
|
|
10234
10332
|
function isLiteralOnly(node, depth) {
|
|
10235
10333
|
if (depth > MAX_LITERAL_DEPTH) {
|
|
@@ -10237,29 +10335,29 @@ function isLiteralOnly(node, depth) {
|
|
|
10237
10335
|
}
|
|
10238
10336
|
const inner = unwrap3(node);
|
|
10239
10337
|
switch (inner.type) {
|
|
10240
|
-
case
|
|
10338
|
+
case AST_NODE_TYPES43.Literal: {
|
|
10241
10339
|
return !(isRegexLiteral(inner) && HAS_STATEFUL_FLAG_RE.test(inner.regex.flags));
|
|
10242
10340
|
}
|
|
10243
|
-
case
|
|
10341
|
+
case AST_NODE_TYPES43.TemplateLiteral: {
|
|
10244
10342
|
return inner.expressions.length === 0;
|
|
10245
10343
|
}
|
|
10246
|
-
case
|
|
10247
|
-
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type ===
|
|
10344
|
+
case AST_NODE_TYPES43.UnaryExpression: {
|
|
10345
|
+
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type === AST_NODE_TYPES43.Literal && typeof inner.argument.value === "number";
|
|
10248
10346
|
}
|
|
10249
|
-
case
|
|
10347
|
+
case AST_NODE_TYPES43.ArrayExpression: {
|
|
10250
10348
|
return inner.elements.every(
|
|
10251
|
-
(el) => el !== null && el.type !==
|
|
10349
|
+
(el) => el !== null && el.type !== AST_NODE_TYPES43.SpreadElement && isLiteralOnly(el, depth + 1)
|
|
10252
10350
|
);
|
|
10253
10351
|
}
|
|
10254
|
-
case
|
|
10352
|
+
case AST_NODE_TYPES43.ObjectExpression: {
|
|
10255
10353
|
return inner.properties.every((prop) => {
|
|
10256
|
-
if (prop.type !==
|
|
10354
|
+
if (prop.type !== AST_NODE_TYPES43.Property) {
|
|
10257
10355
|
return false;
|
|
10258
10356
|
}
|
|
10259
10357
|
if (prop.shorthand || prop.method || prop.kind !== "init") {
|
|
10260
10358
|
return false;
|
|
10261
10359
|
}
|
|
10262
|
-
if (prop.computed && prop.key.type !==
|
|
10360
|
+
if (prop.computed && prop.key.type !== AST_NODE_TYPES43.Literal) {
|
|
10263
10361
|
return false;
|
|
10264
10362
|
}
|
|
10265
10363
|
return isLiteralOnly(prop.value, depth + 1);
|
|
@@ -10281,19 +10379,19 @@ function classify(init, checkRegex) {
|
|
|
10281
10379
|
}
|
|
10282
10380
|
return { kind: "regex", size: 1 };
|
|
10283
10381
|
}
|
|
10284
|
-
if (node.type ===
|
|
10382
|
+
if (node.type === AST_NODE_TYPES43.ArrayExpression) {
|
|
10285
10383
|
return isLiteralOnly(node, 0) ? { kind: "array", size: node.elements.length } : null;
|
|
10286
10384
|
}
|
|
10287
|
-
if (node.type ===
|
|
10385
|
+
if (node.type === AST_NODE_TYPES43.ObjectExpression) {
|
|
10288
10386
|
return isLiteralOnly(node, 0) ? { kind: "object", size: node.properties.length } : null;
|
|
10289
10387
|
}
|
|
10290
|
-
if (node.type ===
|
|
10388
|
+
if (node.type === AST_NODE_TYPES43.NewExpression && node.callee.type === AST_NODE_TYPES43.Identifier && COLLECTION_CONSTRUCTORS.has(node.callee.name)) {
|
|
10291
10389
|
const arg = node.arguments[0];
|
|
10292
|
-
if (node.arguments.length !== 1 || arg === void 0 || arg.type ===
|
|
10390
|
+
if (node.arguments.length !== 1 || arg === void 0 || arg.type === AST_NODE_TYPES43.SpreadElement) {
|
|
10293
10391
|
return null;
|
|
10294
10392
|
}
|
|
10295
10393
|
const entries = unwrap3(arg);
|
|
10296
|
-
if (entries.type !==
|
|
10394
|
+
if (entries.type !== AST_NODE_TYPES43.ArrayExpression) {
|
|
10297
10395
|
return null;
|
|
10298
10396
|
}
|
|
10299
10397
|
return isLiteralOnly(entries, 0) ? { kind: node.callee.name === "Set" ? "Set" : "Map", size: entries.elements.length } : null;
|
|
@@ -10302,7 +10400,7 @@ function classify(init, checkRegex) {
|
|
|
10302
10400
|
}
|
|
10303
10401
|
function unwrapObjectFreeze(node) {
|
|
10304
10402
|
const inner = unwrap3(node);
|
|
10305
|
-
if (inner.type ===
|
|
10403
|
+
if (inner.type === AST_NODE_TYPES43.CallExpression && inner.callee.type === AST_NODE_TYPES43.MemberExpression && !inner.callee.computed && inner.callee.object.type === AST_NODE_TYPES43.Identifier && inner.callee.object.name === "Object" && inner.callee.property.type === AST_NODE_TYPES43.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== AST_NODE_TYPES43.SpreadElement) {
|
|
10306
10404
|
return unwrap3(inner.arguments[0]);
|
|
10307
10405
|
}
|
|
10308
10406
|
return inner;
|
|
@@ -10329,48 +10427,48 @@ var NON_RETAINING_BUILTINS = /* @__PURE__ */ new Map(
|
|
|
10329
10427
|
);
|
|
10330
10428
|
function isSafeRead(identifier) {
|
|
10331
10429
|
const parent = identifier.parent;
|
|
10332
|
-
if (parent.type ===
|
|
10430
|
+
if (parent.type === AST_NODE_TYPES43.MemberExpression) {
|
|
10333
10431
|
if (parent.object !== identifier) {
|
|
10334
10432
|
return true;
|
|
10335
10433
|
}
|
|
10336
10434
|
const grandparent = parent.parent;
|
|
10337
|
-
if (grandparent.type ===
|
|
10435
|
+
if (grandparent.type === AST_NODE_TYPES43.AssignmentExpression && grandparent.left === parent) {
|
|
10338
10436
|
return false;
|
|
10339
10437
|
}
|
|
10340
|
-
if (grandparent.type ===
|
|
10438
|
+
if (grandparent.type === AST_NODE_TYPES43.UpdateExpression) {
|
|
10341
10439
|
return false;
|
|
10342
10440
|
}
|
|
10343
|
-
if (grandparent.type ===
|
|
10441
|
+
if (grandparent.type === AST_NODE_TYPES43.UnaryExpression && grandparent.operator === "delete") {
|
|
10344
10442
|
return false;
|
|
10345
10443
|
}
|
|
10346
|
-
if (!parent.computed && parent.property.type ===
|
|
10444
|
+
if (!parent.computed && parent.property.type === AST_NODE_TYPES43.Identifier && MUTATING_METHODS2.has(parent.property.name) && grandparent.type === AST_NODE_TYPES43.CallExpression && grandparent.callee === parent) {
|
|
10347
10445
|
return false;
|
|
10348
10446
|
}
|
|
10349
10447
|
return true;
|
|
10350
10448
|
}
|
|
10351
|
-
if (parent.type ===
|
|
10449
|
+
if (parent.type === AST_NODE_TYPES43.ForOfStatement && parent.right === identifier) {
|
|
10352
10450
|
return true;
|
|
10353
10451
|
}
|
|
10354
|
-
if (parent.type ===
|
|
10452
|
+
if (parent.type === AST_NODE_TYPES43.SpreadElement) {
|
|
10355
10453
|
return true;
|
|
10356
10454
|
}
|
|
10357
|
-
if (parent.type ===
|
|
10455
|
+
if (parent.type === AST_NODE_TYPES43.BinaryExpression) {
|
|
10358
10456
|
return true;
|
|
10359
10457
|
}
|
|
10360
|
-
if (parent.type ===
|
|
10458
|
+
if (parent.type === AST_NODE_TYPES43.CallExpression && parent.arguments.includes(identifier) && isNonRetainingBuiltinCall(parent, identifier)) {
|
|
10361
10459
|
return true;
|
|
10362
10460
|
}
|
|
10363
|
-
if (parent.type ===
|
|
10461
|
+
if (parent.type === AST_NODE_TYPES43.UnaryExpression && parent.operator !== "delete") {
|
|
10364
10462
|
return true;
|
|
10365
10463
|
}
|
|
10366
10464
|
return false;
|
|
10367
10465
|
}
|
|
10368
10466
|
function isNonRetainingBuiltinCall(node, argument) {
|
|
10369
10467
|
const callee = node.callee;
|
|
10370
|
-
if (callee.type ===
|
|
10468
|
+
if (callee.type === AST_NODE_TYPES43.Identifier && callee.name === "structuredClone") {
|
|
10371
10469
|
return true;
|
|
10372
10470
|
}
|
|
10373
|
-
if (callee.type !==
|
|
10471
|
+
if (callee.type !== AST_NODE_TYPES43.MemberExpression || callee.computed || callee.object.type !== AST_NODE_TYPES43.Identifier || callee.property.type !== AST_NODE_TYPES43.Identifier) {
|
|
10374
10472
|
return false;
|
|
10375
10473
|
}
|
|
10376
10474
|
const members = NON_RETAINING_BUILTINS.get(callee.object.name);
|
|
@@ -10433,7 +10531,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
10433
10531
|
if (reference.isWrite()) {
|
|
10434
10532
|
return false;
|
|
10435
10533
|
}
|
|
10436
|
-
if (reference.identifier.type !==
|
|
10534
|
+
if (reference.identifier.type !== AST_NODE_TYPES43.Identifier) {
|
|
10437
10535
|
return false;
|
|
10438
10536
|
}
|
|
10439
10537
|
if (!isSafeRead(reference.identifier)) {
|
|
@@ -10445,10 +10543,10 @@ var prefer_module_level_constant_default = createRule({
|
|
|
10445
10543
|
return {
|
|
10446
10544
|
VariableDeclarator(node) {
|
|
10447
10545
|
const declaration = node.parent;
|
|
10448
|
-
if (declaration.type !==
|
|
10546
|
+
if (declaration.type !== AST_NODE_TYPES43.VariableDeclaration || declaration.kind !== "const" || declaration.declare === true) {
|
|
10449
10547
|
return;
|
|
10450
10548
|
}
|
|
10451
|
-
if (node.id.type !==
|
|
10549
|
+
if (node.id.type !== AST_NODE_TYPES43.Identifier || node.init === null) {
|
|
10452
10550
|
return;
|
|
10453
10551
|
}
|
|
10454
10552
|
if (enclosingFunction2(node) === null) {
|
|
@@ -10475,7 +10573,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
10475
10573
|
});
|
|
10476
10574
|
|
|
10477
10575
|
// src/rules/prefer-module-level-schema.ts
|
|
10478
|
-
import { AST_NODE_TYPES as
|
|
10576
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES44 } from "@typescript-eslint/utils";
|
|
10479
10577
|
var preferModuleLevelSchemaDocumentation = {
|
|
10480
10578
|
summary: "Declare a Zod schema at module scope when it closes over nothing in the enclosing function",
|
|
10481
10579
|
rationale: "A closed schema created inside a function is rebuilt on every call and cannot be reused or exported for inference.",
|
|
@@ -10542,9 +10640,9 @@ var I18N_RECEIVER_NAMES = /* @__PURE__ */ new Set([
|
|
|
10542
10640
|
"intl"
|
|
10543
10641
|
]);
|
|
10544
10642
|
var FUNCTION_TYPES8 = /* @__PURE__ */ new Set([
|
|
10545
|
-
|
|
10546
|
-
|
|
10547
|
-
|
|
10643
|
+
AST_NODE_TYPES44.ArrowFunctionExpression,
|
|
10644
|
+
AST_NODE_TYPES44.FunctionDeclaration,
|
|
10645
|
+
AST_NODE_TYPES44.FunctionExpression
|
|
10548
10646
|
]);
|
|
10549
10647
|
function schemaExpression(node) {
|
|
10550
10648
|
let current = node;
|
|
@@ -10553,10 +10651,10 @@ function schemaExpression(node) {
|
|
|
10553
10651
|
if (parent === void 0) {
|
|
10554
10652
|
return current;
|
|
10555
10653
|
}
|
|
10556
|
-
if (parent.type ===
|
|
10654
|
+
if (parent.type === AST_NODE_TYPES44.MemberExpression && parent.object === current && !parent.computed && parent.property.type === AST_NODE_TYPES44.Identifier && TERMINAL_METHODS.has(parent.property.name)) {
|
|
10557
10655
|
return current;
|
|
10558
10656
|
}
|
|
10559
|
-
if (parent.type ===
|
|
10657
|
+
if (parent.type === AST_NODE_TYPES44.MemberExpression && parent.object === current || parent.type === AST_NODE_TYPES44.CallExpression && parent.callee === current || parent.type === AST_NODE_TYPES44.TSAsExpression && parent.expression === current || parent.type === AST_NODE_TYPES44.TSNonNullExpression && parent.expression === current) {
|
|
10560
10658
|
current = parent;
|
|
10561
10659
|
continue;
|
|
10562
10660
|
}
|
|
@@ -10607,22 +10705,22 @@ function subtreeSome(root, predicate) {
|
|
|
10607
10705
|
function readsReceiver(node) {
|
|
10608
10706
|
return subtreeSome(
|
|
10609
10707
|
node,
|
|
10610
|
-
(inner) => inner.type ===
|
|
10708
|
+
(inner) => inner.type === AST_NODE_TYPES44.ThisExpression || inner.type === AST_NODE_TYPES44.Super || inner.type === AST_NODE_TYPES44.Identifier && inner.name === "arguments"
|
|
10611
10709
|
);
|
|
10612
10710
|
}
|
|
10613
10711
|
function buildsLocalizedText(node) {
|
|
10614
10712
|
return subtreeSome(node, (inner) => {
|
|
10615
|
-
if (inner.type ===
|
|
10713
|
+
if (inner.type === AST_NODE_TYPES44.TaggedTemplateExpression) {
|
|
10616
10714
|
return true;
|
|
10617
10715
|
}
|
|
10618
|
-
if (inner.type !==
|
|
10716
|
+
if (inner.type !== AST_NODE_TYPES44.CallExpression) {
|
|
10619
10717
|
return false;
|
|
10620
10718
|
}
|
|
10621
10719
|
const { callee } = inner;
|
|
10622
|
-
if (callee.type ===
|
|
10720
|
+
if (callee.type === AST_NODE_TYPES44.Identifier) {
|
|
10623
10721
|
return I18N_CALLEE_NAMES.has(callee.name);
|
|
10624
10722
|
}
|
|
10625
|
-
return callee.type ===
|
|
10723
|
+
return callee.type === AST_NODE_TYPES44.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES44.Identifier && I18N_RECEIVER_NAMES.has(callee.object.name);
|
|
10626
10724
|
});
|
|
10627
10725
|
}
|
|
10628
10726
|
function collectReferences(scope, out) {
|
|
@@ -10686,15 +10784,15 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10686
10784
|
}
|
|
10687
10785
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
10688
10786
|
function isZodCall(node) {
|
|
10689
|
-
return node.type ===
|
|
10787
|
+
return node.type === AST_NODE_TYPES44.CallExpression && node.callee.type === AST_NODE_TYPES44.MemberExpression && !node.callee.computed && node.callee.object.type === AST_NODE_TYPES44.Identifier && zodNamespaces.has(node.callee.object.name);
|
|
10690
10788
|
}
|
|
10691
10789
|
function isCovered(node) {
|
|
10692
10790
|
let current = node.parent ?? void 0;
|
|
10693
10791
|
while (current !== void 0) {
|
|
10694
|
-
if (current !== node && isZodCall(current) && current.callee.type ===
|
|
10792
|
+
if (current !== node && isZodCall(current) && current.callee.type === AST_NODE_TYPES44.MemberExpression && current.callee.property.type === AST_NODE_TYPES44.Identifier && factories.has(current.callee.property.name)) {
|
|
10695
10793
|
return true;
|
|
10696
10794
|
}
|
|
10697
|
-
if (current.type ===
|
|
10795
|
+
if (current.type === AST_NODE_TYPES44.CallExpression && (current.callee.type === AST_NODE_TYPES44.Identifier && memoCallees.has(current.callee.name) || current.callee.type === AST_NODE_TYPES44.MemberExpression && !current.callee.computed && current.callee.property.type === AST_NODE_TYPES44.Identifier && memoCallees.has(current.callee.property.name))) {
|
|
10698
10796
|
return true;
|
|
10699
10797
|
}
|
|
10700
10798
|
current = current.parent ?? void 0;
|
|
@@ -10709,11 +10807,11 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10709
10807
|
if (parent === void 0) {
|
|
10710
10808
|
return confirmed;
|
|
10711
10809
|
}
|
|
10712
|
-
if (parent.type ===
|
|
10810
|
+
if (parent.type === AST_NODE_TYPES44.Property && parent.value === current || parent.type === AST_NODE_TYPES44.ObjectExpression || parent.type === AST_NODE_TYPES44.ArrayExpression) {
|
|
10713
10811
|
current = parent;
|
|
10714
10812
|
continue;
|
|
10715
10813
|
}
|
|
10716
|
-
if (parent.type ===
|
|
10814
|
+
if (parent.type === AST_NODE_TYPES44.CallExpression && parent.arguments.includes(current) && isSchemaComposition(parent)) {
|
|
10717
10815
|
current = schemaExpression(parent);
|
|
10718
10816
|
confirmed = current;
|
|
10719
10817
|
continue;
|
|
@@ -10723,7 +10821,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10723
10821
|
}
|
|
10724
10822
|
function isSchemaComposition(node) {
|
|
10725
10823
|
const { callee } = node;
|
|
10726
|
-
const isCombinator = callee.type ===
|
|
10824
|
+
const isCombinator = callee.type === AST_NODE_TYPES44.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES44.Identifier && ZOD_COMBINATOR_METHODS.has(callee.property.name);
|
|
10727
10825
|
return isCombinator || isZodCall(node);
|
|
10728
10826
|
}
|
|
10729
10827
|
function closesOverNothing(node, enclosing) {
|
|
@@ -10743,12 +10841,12 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10743
10841
|
for (const definition of resolved.defs) {
|
|
10744
10842
|
if (definition.type === "ImportBinding") {
|
|
10745
10843
|
const parent = reference.identifier.parent;
|
|
10746
|
-
if (parent?.type ===
|
|
10844
|
+
if (parent?.type === AST_NODE_TYPES44.CallExpression && parent.callee === reference.identifier && !zodNamespaces.has(reference.identifier.name)) {
|
|
10747
10845
|
return false;
|
|
10748
10846
|
}
|
|
10749
10847
|
continue;
|
|
10750
10848
|
}
|
|
10751
|
-
if (definition.node.type ===
|
|
10849
|
+
if (definition.node.type === AST_NODE_TYPES44.VariableDeclarator && definition.node.parent.type === AST_NODE_TYPES44.VariableDeclaration && definition.node.parent.kind !== "const") {
|
|
10752
10850
|
return false;
|
|
10753
10851
|
}
|
|
10754
10852
|
const [defStart, defEnd] = definition.node.range;
|
|
@@ -10764,13 +10862,13 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10764
10862
|
}
|
|
10765
10863
|
function ownerName(enclosing) {
|
|
10766
10864
|
const parent = enclosing.parent ?? void 0;
|
|
10767
|
-
if (enclosing.type ===
|
|
10865
|
+
if (enclosing.type === AST_NODE_TYPES44.FunctionDeclaration && enclosing.id !== null) {
|
|
10768
10866
|
return enclosing.id.name;
|
|
10769
10867
|
}
|
|
10770
|
-
if (parent !== void 0 && parent.type ===
|
|
10868
|
+
if (parent !== void 0 && parent.type === AST_NODE_TYPES44.VariableDeclarator && parent.id.type === AST_NODE_TYPES44.Identifier) {
|
|
10771
10869
|
return parent.id.name;
|
|
10772
10870
|
}
|
|
10773
|
-
if (parent !== void 0 && (parent.type ===
|
|
10871
|
+
if (parent !== void 0 && (parent.type === AST_NODE_TYPES44.MethodDefinition || parent.type === AST_NODE_TYPES44.Property) && parent.key.type === AST_NODE_TYPES44.Identifier) {
|
|
10774
10872
|
return parent.key.name;
|
|
10775
10873
|
}
|
|
10776
10874
|
return "this function";
|
|
@@ -10781,7 +10879,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10781
10879
|
return;
|
|
10782
10880
|
}
|
|
10783
10881
|
for (const specifier of node.specifiers) {
|
|
10784
|
-
if (specifier.type ===
|
|
10882
|
+
if (specifier.type === AST_NODE_TYPES44.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES44.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES44.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES44.Identifier && specifier.imported.name === "z") {
|
|
10785
10883
|
zodNamespaces.add(specifier.local.name);
|
|
10786
10884
|
}
|
|
10787
10885
|
}
|
|
@@ -10791,7 +10889,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10791
10889
|
return;
|
|
10792
10890
|
}
|
|
10793
10891
|
const callee = node.callee;
|
|
10794
|
-
if (callee.property.type !==
|
|
10892
|
+
if (callee.property.type !== AST_NODE_TYPES44.Identifier) {
|
|
10795
10893
|
return;
|
|
10796
10894
|
}
|
|
10797
10895
|
const factory = callee.property.name;
|
|
@@ -10806,7 +10904,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10806
10904
|
return;
|
|
10807
10905
|
}
|
|
10808
10906
|
const shape = node.arguments[0];
|
|
10809
|
-
if (shape !== void 0 && shape.type ===
|
|
10907
|
+
if (shape !== void 0 && shape.type === AST_NODE_TYPES44.ObjectExpression && shape.properties.length < minProperties) {
|
|
10810
10908
|
return;
|
|
10811
10909
|
}
|
|
10812
10910
|
const expression = schemaExpression(node);
|
|
@@ -10834,7 +10932,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10834
10932
|
});
|
|
10835
10933
|
|
|
10836
10934
|
// src/rules/prefer-native-random-uuid.ts
|
|
10837
|
-
import { AST_NODE_TYPES as
|
|
10935
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES45, ASTUtils as ASTUtils12 } from "@typescript-eslint/utils";
|
|
10838
10936
|
var preferNativeRandomUuidDocumentation = {
|
|
10839
10937
|
summary: "Prefer `globalThis.crypto.randomUUID()` over resolved zero-argument UUID v4 bindings from the `uuid` package.",
|
|
10840
10938
|
rationale: "The platform implementation avoids an unnecessary dependency for standard random UUID generation.",
|
|
@@ -10848,7 +10946,7 @@ var preferNativeRandomUuidDocumentation = {
|
|
|
10848
10946
|
]
|
|
10849
10947
|
};
|
|
10850
10948
|
function requireUuid(node) {
|
|
10851
|
-
return node?.type ===
|
|
10949
|
+
return node?.type === AST_NODE_TYPES45.CallExpression && node.callee.type === AST_NODE_TYPES45.Identifier && node.callee.name === "require" && node.arguments.length === 1 && node.arguments[0]?.type === AST_NODE_TYPES45.Literal && node.arguments[0].value === "uuid";
|
|
10852
10950
|
}
|
|
10853
10951
|
var prefer_native_random_uuid_default = createRule({
|
|
10854
10952
|
name: "prefer-native-random-uuid",
|
|
@@ -10892,37 +10990,37 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
10892
10990
|
ImportDeclaration(node) {
|
|
10893
10991
|
if (node.source.value !== "uuid") return;
|
|
10894
10992
|
for (const specifier of node.specifiers) {
|
|
10895
|
-
if (specifier.type ===
|
|
10993
|
+
if (specifier.type === AST_NODE_TYPES45.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES45.Identifier ? specifier.imported.name === "v4" : specifier.imported.value === "v4")) {
|
|
10896
10994
|
record(specifier.local, directBindings);
|
|
10897
|
-
} else if (specifier.type ===
|
|
10995
|
+
} else if (specifier.type === AST_NODE_TYPES45.ImportNamespaceSpecifier) {
|
|
10898
10996
|
record(specifier.local, namespaceBindings);
|
|
10899
10997
|
}
|
|
10900
10998
|
}
|
|
10901
10999
|
},
|
|
10902
11000
|
VariableDeclarator(node) {
|
|
10903
11001
|
if (node.parent.kind !== "const" || !requireUuid(node.init)) return;
|
|
10904
|
-
if (node.init?.type !==
|
|
11002
|
+
if (node.init?.type !== AST_NODE_TYPES45.CallExpression || node.init.callee.type !== AST_NODE_TYPES45.Identifier || (resolve(node.init.callee)?.defs.length ?? 0) > 0) {
|
|
10905
11003
|
return;
|
|
10906
11004
|
}
|
|
10907
|
-
if (node.id.type ===
|
|
11005
|
+
if (node.id.type === AST_NODE_TYPES45.Identifier) {
|
|
10908
11006
|
record(node.id, namespaceBindings);
|
|
10909
11007
|
return;
|
|
10910
11008
|
}
|
|
10911
|
-
if (node.id.type !==
|
|
11009
|
+
if (node.id.type !== AST_NODE_TYPES45.ObjectPattern) return;
|
|
10912
11010
|
for (const property of node.id.properties) {
|
|
10913
|
-
if (property.type ===
|
|
11011
|
+
if (property.type === AST_NODE_TYPES45.Property && !property.computed && (property.key.type === AST_NODE_TYPES45.Identifier && property.key.name === "v4" || property.key.type === AST_NODE_TYPES45.Literal && property.key.value === "v4") && property.value.type === AST_NODE_TYPES45.Identifier) {
|
|
10914
11012
|
record(property.value, directBindings);
|
|
10915
11013
|
}
|
|
10916
11014
|
}
|
|
10917
11015
|
},
|
|
10918
11016
|
"CallExpression:exit"(node) {
|
|
10919
11017
|
if (node.arguments.length !== 0) return;
|
|
10920
|
-
if (node.callee.type ===
|
|
11018
|
+
if (node.callee.type === AST_NODE_TYPES45.Identifier) {
|
|
10921
11019
|
const variable2 = resolve(node.callee);
|
|
10922
11020
|
if (variable2 !== null && directBindings.has(variable2)) report(node);
|
|
10923
11021
|
return;
|
|
10924
11022
|
}
|
|
10925
|
-
if (node.callee.type !==
|
|
11023
|
+
if (node.callee.type !== AST_NODE_TYPES45.MemberExpression || node.callee.computed || node.callee.object.type !== AST_NODE_TYPES45.Identifier || node.callee.property.type !== AST_NODE_TYPES45.Identifier || node.callee.property.name !== "v4") {
|
|
10926
11024
|
return;
|
|
10927
11025
|
}
|
|
10928
11026
|
const variable = resolve(node.callee.object);
|
|
@@ -10933,7 +11031,7 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
10933
11031
|
});
|
|
10934
11032
|
|
|
10935
11033
|
// src/rules/prefer-non-nullable-collection.ts
|
|
10936
|
-
import { AST_NODE_TYPES as
|
|
11034
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES46, ASTUtils as ASTUtils13 } from "@typescript-eslint/utils";
|
|
10937
11035
|
var preferNonNullableCollectionDocumentation = {
|
|
10938
11036
|
summary: "Suggest non-null arrays only when local control flow proves the nullish state is equivalent to an empty collection.",
|
|
10939
11037
|
rationale: "A redundant nullish collection state spreads defaults and guards through consumers without carrying information.",
|
|
@@ -10949,33 +11047,33 @@ var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
|
10949
11047
|
function propertyName(node) {
|
|
10950
11048
|
const key = node.key;
|
|
10951
11049
|
if (node.computed) return null;
|
|
10952
|
-
if (key.type ===
|
|
10953
|
-
if (key.type ===
|
|
11050
|
+
if (key.type === AST_NODE_TYPES46.Identifier) return key.name;
|
|
11051
|
+
if (key.type === AST_NODE_TYPES46.Literal && typeof key.value === "string") return key.value;
|
|
10954
11052
|
return null;
|
|
10955
11053
|
}
|
|
10956
11054
|
function isArrayType(node) {
|
|
10957
|
-
if (node.type ===
|
|
10958
|
-
return node.type ===
|
|
11055
|
+
if (node.type === AST_NODE_TYPES46.TSArrayType) return true;
|
|
11056
|
+
return node.type === AST_NODE_TYPES46.TSTypeReference && node.typeName.type === AST_NODE_TYPES46.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
10959
11057
|
}
|
|
10960
11058
|
function nullableProperty(node) {
|
|
10961
11059
|
if (node.optional) return null;
|
|
10962
11060
|
const name = propertyName(node);
|
|
10963
11061
|
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
10964
|
-
if (name === null || annotation?.type !==
|
|
11062
|
+
if (name === null || annotation?.type !== AST_NODE_TYPES46.TSUnionType) return null;
|
|
10965
11063
|
const concrete = annotation.types.filter(
|
|
10966
|
-
(member) => member.type !==
|
|
11064
|
+
(member) => member.type !== AST_NODE_TYPES46.TSNullKeyword && member.type !== AST_NODE_TYPES46.TSUndefinedKeyword
|
|
10967
11065
|
);
|
|
10968
11066
|
if (concrete.length === 0 || !concrete.every(isArrayType)) return null;
|
|
10969
|
-
const acceptsNull = annotation.types.some((member) => member.type ===
|
|
11067
|
+
const acceptsNull = annotation.types.some((member) => member.type === AST_NODE_TYPES46.TSNullKeyword);
|
|
10970
11068
|
const acceptsUndefined = annotation.types.some(
|
|
10971
|
-
(member) => member.type ===
|
|
11069
|
+
(member) => member.type === AST_NODE_TYPES46.TSUndefinedKeyword
|
|
10972
11070
|
);
|
|
10973
11071
|
if (!acceptsNull && !acceptsUndefined) return null;
|
|
10974
11072
|
return { name, node, acceptsNull, acceptsUndefined };
|
|
10975
11073
|
}
|
|
10976
11074
|
function shapeProperties(members) {
|
|
10977
11075
|
return members.flatMap((member) => {
|
|
10978
|
-
if (member.type !==
|
|
11076
|
+
if (member.type !== AST_NODE_TYPES46.TSPropertySignature) return [];
|
|
10979
11077
|
const property = nullableProperty(member);
|
|
10980
11078
|
return property === null ? [] : [property];
|
|
10981
11079
|
});
|
|
@@ -10983,14 +11081,14 @@ function shapeProperties(members) {
|
|
|
10983
11081
|
function typeIndex(program) {
|
|
10984
11082
|
const index = /* @__PURE__ */ new Map();
|
|
10985
11083
|
for (const statement of program.body) {
|
|
10986
|
-
const exported = statement.type ===
|
|
11084
|
+
const exported = statement.type === AST_NODE_TYPES46.ExportNamedDeclaration;
|
|
10987
11085
|
const declaration = exported ? statement.declaration : statement;
|
|
10988
|
-
if (declaration?.type ===
|
|
11086
|
+
if (declaration?.type === AST_NODE_TYPES46.TSInterfaceDeclaration) {
|
|
10989
11087
|
index.set(declaration.id.name, {
|
|
10990
11088
|
exported,
|
|
10991
11089
|
properties: shapeProperties(declaration.body.body)
|
|
10992
11090
|
});
|
|
10993
|
-
} else if (declaration?.type ===
|
|
11091
|
+
} else if (declaration?.type === AST_NODE_TYPES46.TSTypeAliasDeclaration && declaration.typeAnnotation.type === AST_NODE_TYPES46.TSTypeLiteral) {
|
|
10994
11092
|
index.set(declaration.id.name, {
|
|
10995
11093
|
exported,
|
|
10996
11094
|
properties: shapeProperties(declaration.typeAnnotation.members)
|
|
@@ -11000,42 +11098,42 @@ function typeIndex(program) {
|
|
|
11000
11098
|
return index;
|
|
11001
11099
|
}
|
|
11002
11100
|
function emptyArray(node) {
|
|
11003
|
-
return node.type ===
|
|
11101
|
+
return node.type === AST_NODE_TYPES46.ArrayExpression && node.elements.length === 0;
|
|
11004
11102
|
}
|
|
11005
11103
|
function sameAccess(node, access) {
|
|
11006
11104
|
if (access.kind === "identifier") {
|
|
11007
|
-
return node.type ===
|
|
11105
|
+
return node.type === AST_NODE_TYPES46.Identifier && node.name === access.name;
|
|
11008
11106
|
}
|
|
11009
|
-
return node.type ===
|
|
11107
|
+
return node.type === AST_NODE_TYPES46.MemberExpression && !node.computed && node.object.type === AST_NODE_TYPES46.Identifier && node.object.name === access.object && node.property.type === AST_NODE_TYPES46.Identifier && node.property.name === access.property;
|
|
11010
11108
|
}
|
|
11011
11109
|
function isNullGuard(node, access) {
|
|
11012
|
-
if (node.type ===
|
|
11013
|
-
if (node.type !==
|
|
11110
|
+
if (node.type === AST_NODE_TYPES46.UnaryExpression && node.operator === "!" && (sameAccess(node.argument, access) || optionalMemberLengthOf(node.argument, access))) return true;
|
|
11111
|
+
if (node.type !== AST_NODE_TYPES46.BinaryExpression || !["==", "==="].includes(node.operator)) {
|
|
11014
11112
|
return false;
|
|
11015
11113
|
}
|
|
11016
|
-
const nullish = (value) => value.type ===
|
|
11114
|
+
const nullish = (value) => value.type === AST_NODE_TYPES46.Literal && value.value === null || value.type === AST_NODE_TYPES46.Identifier && value.name === "undefined";
|
|
11017
11115
|
return sameAccess(node.left, access) && nullish(node.right) || sameAccess(node.right, access) && nullish(node.left);
|
|
11018
11116
|
}
|
|
11019
11117
|
function isEmptyGuard(node, access) {
|
|
11020
|
-
if (node.type ===
|
|
11021
|
-
if (node.type !==
|
|
11118
|
+
if (node.type === AST_NODE_TYPES46.UnaryExpression && node.operator === "!" && memberLengthOf(node.argument, access)) return true;
|
|
11119
|
+
if (node.type !== AST_NODE_TYPES46.BinaryExpression || !["==", "===", "<="].includes(node.operator)) {
|
|
11022
11120
|
return false;
|
|
11023
11121
|
}
|
|
11024
|
-
const zero = (value) => value.type ===
|
|
11122
|
+
const zero = (value) => value.type === AST_NODE_TYPES46.Literal && value.value === 0;
|
|
11025
11123
|
return memberLengthOf(node.left, access) && zero(node.right) || memberLengthOf(node.right, access) && zero(node.left);
|
|
11026
11124
|
}
|
|
11027
11125
|
function memberLengthOf(node, access) {
|
|
11028
|
-
const target = node.type ===
|
|
11029
|
-
return target.type ===
|
|
11126
|
+
const target = node.type === AST_NODE_TYPES46.ChainExpression ? node.expression : node;
|
|
11127
|
+
return target.type === AST_NODE_TYPES46.MemberExpression && !target.computed && target.property.type === AST_NODE_TYPES46.Identifier && target.property.name === "length" && sameAccess(target.object, access);
|
|
11030
11128
|
}
|
|
11031
11129
|
function optionalMemberLengthOf(node, access) {
|
|
11032
|
-
return node.type ===
|
|
11130
|
+
return node.type === AST_NODE_TYPES46.ChainExpression && node.expression.type === AST_NODE_TYPES46.MemberExpression && node.expression.optional && memberLengthOf(node, access);
|
|
11033
11131
|
}
|
|
11034
11132
|
function hasEquivalentLeadingGuard(fn, access, visitorKeys) {
|
|
11035
|
-
if (fn.body.type !==
|
|
11133
|
+
if (fn.body.type !== AST_NODE_TYPES46.BlockStatement) return false;
|
|
11036
11134
|
const first = fn.body.body[0];
|
|
11037
|
-
if (first?.type !==
|
|
11038
|
-
const terminating = first.consequent.type ===
|
|
11135
|
+
if (first?.type !== AST_NODE_TYPES46.IfStatement) return false;
|
|
11136
|
+
const terminating = first.consequent.type === AST_NODE_TYPES46.ReturnStatement || first.consequent.type === AST_NODE_TYPES46.ThrowStatement || first.consequent.type === AST_NODE_TYPES46.BlockStatement && first.consequent.body.length === 1 && (first.consequent.body[0]?.type === AST_NODE_TYPES46.ReturnStatement || first.consequent.body[0]?.type === AST_NODE_TYPES46.ThrowStatement);
|
|
11039
11137
|
if (!terminating) return false;
|
|
11040
11138
|
if (contains(first.consequent, visitorKeys, (node) => sameAccess(node, access))) return false;
|
|
11041
11139
|
return contains(first.test, visitorKeys, (node) => isNullGuard(node, access)) && contains(first.test, visitorKeys, (node) => isEmptyGuard(node, access));
|
|
@@ -11053,14 +11151,14 @@ function contains(node, visitorKeys, predicate) {
|
|
|
11053
11151
|
function belongsToFunction(node, fn) {
|
|
11054
11152
|
let current = node;
|
|
11055
11153
|
while (current !== void 0 && current !== fn) {
|
|
11056
|
-
if (current !== node && (current.type ===
|
|
11154
|
+
if (current !== node && (current.type === AST_NODE_TYPES46.ArrowFunctionExpression || current.type === AST_NODE_TYPES46.FunctionDeclaration || current.type === AST_NODE_TYPES46.FunctionExpression)) return false;
|
|
11057
11155
|
current = current.parent;
|
|
11058
11156
|
}
|
|
11059
11157
|
return current === fn;
|
|
11060
11158
|
}
|
|
11061
11159
|
function directlyCoalesced(node) {
|
|
11062
11160
|
const parent = node.parent;
|
|
11063
|
-
return parent?.type ===
|
|
11161
|
+
return parent?.type === AST_NODE_TYPES46.LogicalExpression && parent.left === node && (parent.operator === "??" || parent.operator === "||") && emptyArray(parent.right);
|
|
11064
11162
|
}
|
|
11065
11163
|
function identifierIsOnlyCoalesced(context, binding, fn) {
|
|
11066
11164
|
const variable = ASTUtils13.findVariable(context.sourceCode.getScope(binding), binding.name);
|
|
@@ -11075,7 +11173,7 @@ function memberIsOnlyCoalesced(context, object, property, fn) {
|
|
|
11075
11173
|
const accesses = variable.references.flatMap((reference) => {
|
|
11076
11174
|
if (!belongsToFunction(reference.identifier, fn)) return [null];
|
|
11077
11175
|
const parent = reference.identifier.parent;
|
|
11078
|
-
if (parent?.type ===
|
|
11176
|
+
if (parent?.type === AST_NODE_TYPES46.MemberExpression && !parent.computed && parent.object === reference.identifier && parent.property.type === AST_NODE_TYPES46.Identifier && parent.property.name === property) return [parent];
|
|
11079
11177
|
return [];
|
|
11080
11178
|
});
|
|
11081
11179
|
return accesses.length > 0 && accesses.every((access) => access !== null && directlyCoalesced(access));
|
|
@@ -11101,8 +11199,8 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
11101
11199
|
let shapes = /* @__PURE__ */ new Map();
|
|
11102
11200
|
const evidence = /* @__PURE__ */ new Map();
|
|
11103
11201
|
function propertiesFor(annotation) {
|
|
11104
|
-
if (annotation?.type ===
|
|
11105
|
-
if (annotation?.type ===
|
|
11202
|
+
if (annotation?.type === AST_NODE_TYPES46.TSTypeLiteral) return shapeProperties(annotation.members);
|
|
11203
|
+
if (annotation?.type === AST_NODE_TYPES46.TSTypeReference && annotation.typeName.type === AST_NODE_TYPES46.Identifier) {
|
|
11106
11204
|
const shape = shapes.get(annotation.typeName.name);
|
|
11107
11205
|
return shape?.exported === false ? shape.properties : [];
|
|
11108
11206
|
}
|
|
@@ -11115,21 +11213,21 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
11115
11213
|
}
|
|
11116
11214
|
function checkFunction(fn) {
|
|
11117
11215
|
for (const rawParameter of fn.params) {
|
|
11118
|
-
const parameter = rawParameter.type ===
|
|
11119
|
-
if (parameter.type ===
|
|
11216
|
+
const parameter = rawParameter.type === AST_NODE_TYPES46.AssignmentPattern ? rawParameter.left : rawParameter;
|
|
11217
|
+
if (parameter.type === AST_NODE_TYPES46.ObjectPattern) {
|
|
11120
11218
|
const properties2 = propertiesFor(parameter.typeAnnotation?.typeAnnotation);
|
|
11121
11219
|
for (const property of properties2) {
|
|
11122
11220
|
const bindingProperty = parameter.properties.find(
|
|
11123
|
-
(entry) => entry.type ===
|
|
11221
|
+
(entry) => entry.type === AST_NODE_TYPES46.Property && !entry.computed && entry.key.type === AST_NODE_TYPES46.Identifier && entry.key.name === property.name
|
|
11124
11222
|
);
|
|
11125
11223
|
if (bindingProperty === void 0) continue;
|
|
11126
11224
|
const value = bindingProperty.value;
|
|
11127
|
-
const binding = value.type ===
|
|
11128
|
-
if (binding.type !==
|
|
11225
|
+
const binding = value.type === AST_NODE_TYPES46.AssignmentPattern ? value.left : value;
|
|
11226
|
+
if (binding.type !== AST_NODE_TYPES46.Identifier) {
|
|
11129
11227
|
record(property, false);
|
|
11130
11228
|
continue;
|
|
11131
11229
|
}
|
|
11132
|
-
if (value.type ===
|
|
11230
|
+
if (value.type === AST_NODE_TYPES46.AssignmentPattern && emptyArray(value.right) && property.acceptsUndefined && !property.acceptsNull) {
|
|
11133
11231
|
record(property, true);
|
|
11134
11232
|
continue;
|
|
11135
11233
|
}
|
|
@@ -11141,7 +11239,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
11141
11239
|
}
|
|
11142
11240
|
continue;
|
|
11143
11241
|
}
|
|
11144
|
-
if (parameter.type !==
|
|
11242
|
+
if (parameter.type !== AST_NODE_TYPES46.Identifier) continue;
|
|
11145
11243
|
const properties = propertiesFor(parameter.typeAnnotation?.typeAnnotation);
|
|
11146
11244
|
for (const property of properties) {
|
|
11147
11245
|
const access = {
|
|
@@ -11181,7 +11279,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
11181
11279
|
import {
|
|
11182
11280
|
ASTUtils as ASTUtils14,
|
|
11183
11281
|
ESLintUtils as ESLintUtils3,
|
|
11184
|
-
AST_NODE_TYPES as
|
|
11282
|
+
AST_NODE_TYPES as AST_NODE_TYPES47
|
|
11185
11283
|
} from "@typescript-eslint/utils";
|
|
11186
11284
|
import * as ts2 from "typescript";
|
|
11187
11285
|
var preferAwaitInAsyncReturnDocumentation = {
|
|
@@ -11224,10 +11322,10 @@ var preferAwaitInAsyncReturnDocumentation = {
|
|
|
11224
11322
|
};
|
|
11225
11323
|
function directAsyncReturnOwner(node) {
|
|
11226
11324
|
const parent = node.parent;
|
|
11227
|
-
if (parent.type ===
|
|
11325
|
+
if (parent.type === AST_NODE_TYPES47.ArrowFunctionExpression && parent.body === node) {
|
|
11228
11326
|
return parent.async && !parent.generator ? parent : null;
|
|
11229
11327
|
}
|
|
11230
|
-
if (parent.type !==
|
|
11328
|
+
if (parent.type !== AST_NODE_TYPES47.ReturnStatement || parent.argument !== node) {
|
|
11231
11329
|
return null;
|
|
11232
11330
|
}
|
|
11233
11331
|
let owner = parent.parent;
|
|
@@ -11237,15 +11335,15 @@ function directAsyncReturnOwner(node) {
|
|
|
11237
11335
|
return owner !== void 0 && owner.async && !owner.generator ? owner : null;
|
|
11238
11336
|
}
|
|
11239
11337
|
function isRuntimeFunction(node) {
|
|
11240
|
-
return node.type ===
|
|
11338
|
+
return node.type === AST_NODE_TYPES47.ArrowFunctionExpression || node.type === AST_NODE_TYPES47.FunctionDeclaration || node.type === AST_NODE_TYPES47.FunctionExpression;
|
|
11241
11339
|
}
|
|
11242
11340
|
function promiseThenReceiver(node) {
|
|
11243
11341
|
const callee = node.callee;
|
|
11244
|
-
if (callee.type !==
|
|
11342
|
+
if (callee.type !== AST_NODE_TYPES47.MemberExpression || callee.computed || callee.optional || callee.property.type !== AST_NODE_TYPES47.Identifier || callee.property.name !== "then" || node.optional || node.arguments.length !== 1) {
|
|
11245
11343
|
return null;
|
|
11246
11344
|
}
|
|
11247
11345
|
const callback = node.arguments[0];
|
|
11248
|
-
if (callback === void 0 || callback.type !==
|
|
11346
|
+
if (callback === void 0 || callback.type !== AST_NODE_TYPES47.ArrowFunctionExpression && callback.type !== AST_NODE_TYPES47.FunctionExpression) {
|
|
11249
11347
|
return null;
|
|
11250
11348
|
}
|
|
11251
11349
|
return callee.object;
|
|
@@ -11298,7 +11396,7 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
11298
11396
|
};
|
|
11299
11397
|
const isFrameworkLoaderCallback = (owner) => {
|
|
11300
11398
|
const parent = owner.parent;
|
|
11301
|
-
if (parent.type !==
|
|
11399
|
+
if (parent.type !== AST_NODE_TYPES47.CallExpression || parent.arguments[0] !== owner || parent.callee.type !== AST_NODE_TYPES47.Identifier) return false;
|
|
11302
11400
|
const variable = ASTUtils14.findVariable(context.sourceCode.getScope(parent.callee), parent.callee.name);
|
|
11303
11401
|
return variable !== null && frameworkLoaders.has(variable);
|
|
11304
11402
|
};
|
|
@@ -11306,12 +11404,12 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
11306
11404
|
ImportDeclaration(node) {
|
|
11307
11405
|
if (node.source.value === "react") {
|
|
11308
11406
|
for (const specifier of node.specifiers) {
|
|
11309
|
-
if (specifier.type ===
|
|
11407
|
+
if (specifier.type === AST_NODE_TYPES47.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES47.Identifier ? specifier.imported.name : specifier.imported.value) === "lazy") rememberFrameworkLoader(specifier.local);
|
|
11310
11408
|
}
|
|
11311
11409
|
}
|
|
11312
11410
|
if (node.source.value === "next/dynamic") {
|
|
11313
11411
|
for (const specifier of node.specifiers) {
|
|
11314
|
-
if (specifier.type ===
|
|
11412
|
+
if (specifier.type === AST_NODE_TYPES47.ImportDefaultSpecifier) rememberFrameworkLoader(specifier.local);
|
|
11315
11413
|
}
|
|
11316
11414
|
}
|
|
11317
11415
|
},
|
|
@@ -11329,7 +11427,7 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
11329
11427
|
});
|
|
11330
11428
|
|
|
11331
11429
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
11332
|
-
import { AST_NODE_TYPES as
|
|
11430
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES48 } from "@typescript-eslint/utils";
|
|
11333
11431
|
var preferSchemaForApiPayloadDocumentation = {
|
|
11334
11432
|
summary: "Require Zod (or similar) schema validation on `response.json()` / `JSON.parse()` results before property access.",
|
|
11335
11433
|
rationale: "External JSON is untrusted at runtime even when its expected TypeScript shape is known statically.",
|
|
@@ -11344,9 +11442,9 @@ var preferSchemaForApiPayloadDocumentation = {
|
|
|
11344
11442
|
var unwrap4 = (node) => {
|
|
11345
11443
|
let current = node;
|
|
11346
11444
|
while (current !== null && current !== void 0) {
|
|
11347
|
-
if (current.type ===
|
|
11445
|
+
if (current.type === AST_NODE_TYPES48.TSAsExpression || current.type === AST_NODE_TYPES48.TSTypeAssertion || current.type === AST_NODE_TYPES48.TSNonNullExpression || current.type === AST_NODE_TYPES48.TSSatisfiesExpression) {
|
|
11348
11446
|
current = current.expression;
|
|
11349
|
-
} else if (current.type ===
|
|
11447
|
+
} else if (current.type === AST_NODE_TYPES48.ChainExpression) {
|
|
11350
11448
|
current = current.expression;
|
|
11351
11449
|
} else {
|
|
11352
11450
|
break;
|
|
@@ -11361,23 +11459,23 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
11361
11459
|
]);
|
|
11362
11460
|
var isSchemaParseReference = (node) => {
|
|
11363
11461
|
const inner = unwrap4(node);
|
|
11364
|
-
return inner !== null && inner.type ===
|
|
11462
|
+
return inner !== null && inner.type === AST_NODE_TYPES48.MemberExpression && !inner.computed && inner.property.type === AST_NODE_TYPES48.Identifier && (inner.property.name === "parse" || inner.property.name === "safeParse");
|
|
11365
11463
|
};
|
|
11366
11464
|
var isRawPayloadSource = (node, isKnownLocalText) => {
|
|
11367
11465
|
let current = unwrap4(node);
|
|
11368
11466
|
if (current === null) return false;
|
|
11369
|
-
if (current.type ===
|
|
11467
|
+
if (current.type === AST_NODE_TYPES48.AwaitExpression) {
|
|
11370
11468
|
current = unwrap4(current.argument);
|
|
11371
11469
|
}
|
|
11372
|
-
if (current === null || current.type !==
|
|
11470
|
+
if (current === null || current.type !== AST_NODE_TYPES48.CallExpression) {
|
|
11373
11471
|
return false;
|
|
11374
11472
|
}
|
|
11375
11473
|
const callee = unwrap4(current.callee);
|
|
11376
|
-
if (callee === null || callee.type !==
|
|
11474
|
+
if (callee === null || callee.type !== AST_NODE_TYPES48.MemberExpression) {
|
|
11377
11475
|
return false;
|
|
11378
11476
|
}
|
|
11379
11477
|
const property = unwrap4(callee.property);
|
|
11380
|
-
if (property === null || property.type !==
|
|
11478
|
+
if (property === null || property.type !== AST_NODE_TYPES48.Identifier) {
|
|
11381
11479
|
return false;
|
|
11382
11480
|
}
|
|
11383
11481
|
if (property.name === "json") {
|
|
@@ -11387,17 +11485,17 @@ var isRawPayloadSource = (node, isKnownLocalText) => {
|
|
|
11387
11485
|
return !current.arguments.some(isSchemaParseReference) && isRawPayloadSource(callee.object);
|
|
11388
11486
|
}
|
|
11389
11487
|
const object = unwrap4(callee.object);
|
|
11390
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
11488
|
+
return property.name === "parse" && object !== null && object.type === AST_NODE_TYPES48.Identifier && object.name === "JSON" && !isLocalFileRead(current.arguments[0]) && isKnownLocalText?.(current.arguments[0]) !== true;
|
|
11391
11489
|
};
|
|
11392
11490
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
11393
11491
|
var isDirectLocalFileRead = (node) => {
|
|
11394
11492
|
let current = unwrap4(node);
|
|
11395
|
-
if (current?.type ===
|
|
11493
|
+
if (current?.type === AST_NODE_TYPES48.AwaitExpression) {
|
|
11396
11494
|
current = unwrap4(current.argument);
|
|
11397
11495
|
}
|
|
11398
|
-
if (current?.type !==
|
|
11496
|
+
if (current?.type !== AST_NODE_TYPES48.CallExpression) return false;
|
|
11399
11497
|
const callee = unwrap4(current.callee);
|
|
11400
|
-
const name = callee?.type ===
|
|
11498
|
+
const name = callee?.type === AST_NODE_TYPES48.Identifier ? callee.name : callee?.type === AST_NODE_TYPES48.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES48.Identifier ? callee.property.name : null;
|
|
11401
11499
|
return name !== null && FILE_READ_RE.test(name);
|
|
11402
11500
|
};
|
|
11403
11501
|
var isLocalFileRead = (node) => {
|
|
@@ -11424,15 +11522,15 @@ var isLocalFileRead = (node) => {
|
|
|
11424
11522
|
var ASSERTION_CALLEE_RE = /^(expect|assert|should|invariant)$/;
|
|
11425
11523
|
var isInsideAssertion = (node) => {
|
|
11426
11524
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11427
|
-
if (current.type !==
|
|
11525
|
+
if (current.type !== AST_NODE_TYPES48.CallExpression) continue;
|
|
11428
11526
|
let callee = current.callee;
|
|
11429
|
-
while (callee.type ===
|
|
11527
|
+
while (callee.type === AST_NODE_TYPES48.MemberExpression) {
|
|
11430
11528
|
callee = callee.object;
|
|
11431
11529
|
}
|
|
11432
|
-
if (callee.type ===
|
|
11530
|
+
if (callee.type === AST_NODE_TYPES48.CallExpression) {
|
|
11433
11531
|
callee = callee.callee;
|
|
11434
11532
|
}
|
|
11435
|
-
if (callee.type ===
|
|
11533
|
+
if (callee.type === AST_NODE_TYPES48.Identifier && ASSERTION_CALLEE_RE.test(callee.name)) {
|
|
11436
11534
|
return true;
|
|
11437
11535
|
}
|
|
11438
11536
|
}
|
|
@@ -11451,22 +11549,22 @@ var GUARD_NAME_RE = /^(?:is|validate|parse|assert|decode|coerce)[A-Z]/;
|
|
|
11451
11549
|
var isValidationRead = (node) => {
|
|
11452
11550
|
let current = node;
|
|
11453
11551
|
let parent = current.parent;
|
|
11454
|
-
while (parent !== null && parent !== void 0 && (parent.type ===
|
|
11552
|
+
while (parent !== null && parent !== void 0 && (parent.type === AST_NODE_TYPES48.TSAsExpression || parent.type === AST_NODE_TYPES48.TSTypeAssertion || parent.type === AST_NODE_TYPES48.TSNonNullExpression || parent.type === AST_NODE_TYPES48.TSSatisfiesExpression || parent.type === AST_NODE_TYPES48.ChainExpression)) {
|
|
11455
11553
|
current = parent;
|
|
11456
11554
|
parent = parent.parent;
|
|
11457
11555
|
}
|
|
11458
11556
|
if (parent === null || parent === void 0) return false;
|
|
11459
|
-
if (parent.type ===
|
|
11557
|
+
if (parent.type === AST_NODE_TYPES48.UnaryExpression && parent.operator === "typeof" && parent.argument === current) {
|
|
11460
11558
|
return true;
|
|
11461
11559
|
}
|
|
11462
|
-
if (parent.type !==
|
|
11560
|
+
if (parent.type !== AST_NODE_TYPES48.CallExpression || !parent.arguments.some((arg) => arg === current)) {
|
|
11463
11561
|
return false;
|
|
11464
11562
|
}
|
|
11465
11563
|
const callee = parent.callee;
|
|
11466
|
-
if (callee.type ===
|
|
11564
|
+
if (callee.type === AST_NODE_TYPES48.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES48.Identifier && callee.object.name === "Array" && callee.property.type === AST_NODE_TYPES48.Identifier && callee.property.name === "isArray") {
|
|
11467
11565
|
return parent.arguments.length === 1;
|
|
11468
11566
|
}
|
|
11469
|
-
return callee.type ===
|
|
11567
|
+
return callee.type === AST_NODE_TYPES48.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
11470
11568
|
};
|
|
11471
11569
|
var PRIMITIVE_TYPEOF_RESULTS = /* @__PURE__ */ new Set([
|
|
11472
11570
|
"bigint",
|
|
@@ -11477,13 +11575,13 @@ var PRIMITIVE_TYPEOF_RESULTS = /* @__PURE__ */ new Set([
|
|
|
11477
11575
|
"undefined"
|
|
11478
11576
|
]);
|
|
11479
11577
|
var bindingValidationPolarity = (test, bindingName) => {
|
|
11480
|
-
if (test.type ===
|
|
11578
|
+
if (test.type === AST_NODE_TYPES48.UnaryExpression && test.operator === "!") {
|
|
11481
11579
|
const inner = bindingValidationPolarity(test.argument, bindingName);
|
|
11482
11580
|
return inner === "valid-when-true" ? "valid-when-false" : inner === "valid-when-false" ? "valid-when-true" : null;
|
|
11483
11581
|
}
|
|
11484
|
-
if (test.type ===
|
|
11485
|
-
const typeofName = (node) => node.type ===
|
|
11486
|
-
const literalType = (node) => node.type ===
|
|
11582
|
+
if (test.type === AST_NODE_TYPES48.BinaryExpression) {
|
|
11583
|
+
const typeofName = (node) => node.type === AST_NODE_TYPES48.UnaryExpression && node.operator === "typeof" && node.argument.type === AST_NODE_TYPES48.Identifier ? node.argument.name : null;
|
|
11584
|
+
const literalType = (node) => node.type === AST_NODE_TYPES48.Literal && typeof node.value === "string" && PRIMITIVE_TYPEOF_RESULTS.has(node.value) ? node.value : null;
|
|
11487
11585
|
const matches = typeofName(test.left) === bindingName && literalType(test.right) !== null || typeofName(test.right) === bindingName && literalType(test.left) !== null;
|
|
11488
11586
|
if (!matches) return null;
|
|
11489
11587
|
if (test.operator === "===" || test.operator === "==") {
|
|
@@ -11491,9 +11589,9 @@ var bindingValidationPolarity = (test, bindingName) => {
|
|
|
11491
11589
|
}
|
|
11492
11590
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
11493
11591
|
}
|
|
11494
|
-
return test.type ===
|
|
11592
|
+
return test.type === AST_NODE_TYPES48.CallExpression && test.arguments.length === 1 && test.arguments[0]?.type === AST_NODE_TYPES48.Identifier && test.arguments[0].name === bindingName && test.callee.type === AST_NODE_TYPES48.MemberExpression && !test.callee.computed && test.callee.object.type === AST_NODE_TYPES48.Identifier && test.callee.object.name === "Array" && test.callee.property.type === AST_NODE_TYPES48.Identifier && test.callee.property.name === "isArray" ? "valid-when-true" : null;
|
|
11495
11593
|
};
|
|
11496
|
-
var plainMemberAccess = (node) => node.type ===
|
|
11594
|
+
var plainMemberAccess = (node) => node.type === AST_NODE_TYPES48.MemberExpression && !node.computed && node.object.type === AST_NODE_TYPES48.Identifier && node.property.type === AST_NODE_TYPES48.Identifier ? { object: node.object.name, property: node.property.name } : null;
|
|
11497
11595
|
var isSamePlainMember = (node, access) => {
|
|
11498
11596
|
const candidate = plainMemberAccess(node);
|
|
11499
11597
|
return candidate !== null && candidate.object === access.object && candidate.property === access.property;
|
|
@@ -11501,19 +11599,19 @@ var isSamePlainMember = (node, access) => {
|
|
|
11501
11599
|
var nodeWithin2 = (node, container) => node.range[0] >= container.range[0] && node.range[1] <= container.range[1];
|
|
11502
11600
|
var isUseWithinValidatedBranch = (node, bindingName) => {
|
|
11503
11601
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11504
|
-
if (current.type ===
|
|
11602
|
+
if (current.type === AST_NODE_TYPES48.ConditionalExpression) {
|
|
11505
11603
|
const polarity = bindingValidationPolarity(current.test, bindingName);
|
|
11506
11604
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && nodeWithin2(node, current.alternate)) {
|
|
11507
11605
|
return true;
|
|
11508
11606
|
}
|
|
11509
11607
|
}
|
|
11510
|
-
if (current.type ===
|
|
11608
|
+
if (current.type === AST_NODE_TYPES48.IfStatement) {
|
|
11511
11609
|
const polarity = bindingValidationPolarity(current.test, bindingName);
|
|
11512
11610
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && current.alternate !== null && nodeWithin2(node, current.alternate)) {
|
|
11513
11611
|
return true;
|
|
11514
11612
|
}
|
|
11515
11613
|
}
|
|
11516
|
-
if (current.type ===
|
|
11614
|
+
if (current.type === AST_NODE_TYPES48.FunctionDeclaration || current.type === AST_NODE_TYPES48.FunctionExpression || current.type === AST_NODE_TYPES48.ArrowFunctionExpression) {
|
|
11517
11615
|
return false;
|
|
11518
11616
|
}
|
|
11519
11617
|
}
|
|
@@ -11521,32 +11619,32 @@ var isUseWithinValidatedBranch = (node, bindingName) => {
|
|
|
11521
11619
|
};
|
|
11522
11620
|
var isMemberUseWithinValidatedBranch = (node, access) => {
|
|
11523
11621
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11524
|
-
if (current.type ===
|
|
11622
|
+
if (current.type === AST_NODE_TYPES48.ConditionalExpression) {
|
|
11525
11623
|
const polarity = memberValidationPolarity(current.test, access);
|
|
11526
11624
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && nodeWithin2(node, current.alternate)) {
|
|
11527
11625
|
return true;
|
|
11528
11626
|
}
|
|
11529
11627
|
}
|
|
11530
|
-
if (current.type ===
|
|
11628
|
+
if (current.type === AST_NODE_TYPES48.IfStatement) {
|
|
11531
11629
|
const polarity = memberValidationPolarity(current.test, access);
|
|
11532
11630
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && current.alternate !== null && nodeWithin2(node, current.alternate)) {
|
|
11533
11631
|
return true;
|
|
11534
11632
|
}
|
|
11535
11633
|
}
|
|
11536
|
-
if (current.type ===
|
|
11634
|
+
if (current.type === AST_NODE_TYPES48.FunctionDeclaration || current.type === AST_NODE_TYPES48.FunctionExpression || current.type === AST_NODE_TYPES48.ArrowFunctionExpression) {
|
|
11537
11635
|
return false;
|
|
11538
11636
|
}
|
|
11539
11637
|
}
|
|
11540
11638
|
return false;
|
|
11541
11639
|
};
|
|
11542
11640
|
var memberValidationPolarity = (test, access) => {
|
|
11543
|
-
if (test.type ===
|
|
11641
|
+
if (test.type === AST_NODE_TYPES48.UnaryExpression && test.operator === "!") {
|
|
11544
11642
|
const inner = memberValidationPolarity(test.argument, access);
|
|
11545
11643
|
return inner === "valid-when-true" ? "valid-when-false" : inner === "valid-when-false" ? "valid-when-true" : null;
|
|
11546
11644
|
}
|
|
11547
|
-
if (test.type ===
|
|
11548
|
-
const isMatchingTypeof = (node) => node.type ===
|
|
11549
|
-
const isPrimitiveType = (node) => node.type ===
|
|
11645
|
+
if (test.type === AST_NODE_TYPES48.BinaryExpression) {
|
|
11646
|
+
const isMatchingTypeof = (node) => node.type === AST_NODE_TYPES48.UnaryExpression && node.operator === "typeof" && isSamePlainMember(node.argument, access);
|
|
11647
|
+
const isPrimitiveType = (node) => node.type === AST_NODE_TYPES48.Literal && typeof node.value === "string" && PRIMITIVE_TYPEOF_RESULTS.has(node.value);
|
|
11550
11648
|
if (!(isMatchingTypeof(test.left) && isPrimitiveType(test.right) || isMatchingTypeof(test.right) && isPrimitiveType(test.left))) {
|
|
11551
11649
|
return null;
|
|
11552
11650
|
}
|
|
@@ -11555,15 +11653,15 @@ var memberValidationPolarity = (test, access) => {
|
|
|
11555
11653
|
}
|
|
11556
11654
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
11557
11655
|
}
|
|
11558
|
-
return test.type ===
|
|
11656
|
+
return test.type === AST_NODE_TYPES48.CallExpression && test.arguments.length === 1 && test.arguments[0] !== void 0 && test.arguments[0].type !== AST_NODE_TYPES48.SpreadElement && isSamePlainMember(test.arguments[0], access) && test.callee.type === AST_NODE_TYPES48.MemberExpression && !test.callee.computed && test.callee.object.type === AST_NODE_TYPES48.Identifier && test.callee.object.name === "Array" && test.callee.property.type === AST_NODE_TYPES48.Identifier && test.callee.property.name === "isArray" ? "valid-when-true" : null;
|
|
11559
11657
|
};
|
|
11560
11658
|
var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
11561
11659
|
const isValidationReference = (identifier) => {
|
|
11562
11660
|
for (let current = identifier.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11563
|
-
if ((current.type ===
|
|
11661
|
+
if ((current.type === AST_NODE_TYPES48.BinaryExpression || current.type === AST_NODE_TYPES48.CallExpression || current.type === AST_NODE_TYPES48.UnaryExpression) && bindingValidationPolarity(current, identifier.name) !== null) {
|
|
11564
11662
|
return true;
|
|
11565
11663
|
}
|
|
11566
|
-
if (current.type !==
|
|
11664
|
+
if (current.type !== AST_NODE_TYPES48.UnaryExpression && current.type !== AST_NODE_TYPES48.MemberExpression && current.type !== AST_NODE_TYPES48.CallExpression) {
|
|
11567
11665
|
return false;
|
|
11568
11666
|
}
|
|
11569
11667
|
}
|
|
@@ -11571,7 +11669,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11571
11669
|
};
|
|
11572
11670
|
const isGuardedUse = (identifier) => {
|
|
11573
11671
|
for (let current = identifier.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11574
|
-
if (current.type ===
|
|
11672
|
+
if (current.type === AST_NODE_TYPES48.ConditionalExpression) {
|
|
11575
11673
|
const polarity = bindingValidationPolarity(current.test, identifier.name);
|
|
11576
11674
|
if (polarity === "valid-when-true" && nodeWithin2(identifier, current.consequent)) {
|
|
11577
11675
|
return true;
|
|
@@ -11580,7 +11678,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11580
11678
|
return true;
|
|
11581
11679
|
}
|
|
11582
11680
|
}
|
|
11583
|
-
if (current.type ===
|
|
11681
|
+
if (current.type === AST_NODE_TYPES48.IfStatement) {
|
|
11584
11682
|
const polarity = bindingValidationPolarity(current.test, identifier.name);
|
|
11585
11683
|
if (polarity === "valid-when-true" && nodeWithin2(identifier, current.consequent)) {
|
|
11586
11684
|
return true;
|
|
@@ -11589,14 +11687,14 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11589
11687
|
return true;
|
|
11590
11688
|
}
|
|
11591
11689
|
}
|
|
11592
|
-
if (current.type ===
|
|
11690
|
+
if (current.type === AST_NODE_TYPES48.FunctionDeclaration || current.type === AST_NODE_TYPES48.FunctionExpression || current.type === AST_NODE_TYPES48.ArrowFunctionExpression) {
|
|
11593
11691
|
return false;
|
|
11594
11692
|
}
|
|
11595
11693
|
}
|
|
11596
11694
|
return false;
|
|
11597
11695
|
};
|
|
11598
11696
|
const declarator = member.parent;
|
|
11599
|
-
if (declarator.type !==
|
|
11697
|
+
if (declarator.type !== AST_NODE_TYPES48.VariableDeclarator || declarator.init !== member || declarator.id.type !== AST_NODE_TYPES48.Identifier || declarator.parent.type !== AST_NODE_TYPES48.VariableDeclaration || declarator.parent.kind !== "const") {
|
|
11600
11698
|
return false;
|
|
11601
11699
|
}
|
|
11602
11700
|
const extracted = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
@@ -11604,7 +11702,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11604
11702
|
let hasValueUse = false;
|
|
11605
11703
|
for (const reference of extracted.references) {
|
|
11606
11704
|
const identifier = reference.identifier;
|
|
11607
|
-
if (identifier.type !==
|
|
11705
|
+
if (identifier.type !== AST_NODE_TYPES48.Identifier) return false;
|
|
11608
11706
|
if (nodeWithin2(identifier, declarator)) continue;
|
|
11609
11707
|
if (isValidationReference(identifier)) continue;
|
|
11610
11708
|
hasValueUse = true;
|
|
@@ -11617,17 +11715,17 @@ var isGuardTestPosition = (node) => {
|
|
|
11617
11715
|
let parent = current.parent;
|
|
11618
11716
|
while (parent !== void 0 && parent !== null) {
|
|
11619
11717
|
switch (parent.type) {
|
|
11620
|
-
case
|
|
11621
|
-
case
|
|
11622
|
-
case
|
|
11718
|
+
case AST_NODE_TYPES48.UnaryExpression:
|
|
11719
|
+
case AST_NODE_TYPES48.LogicalExpression:
|
|
11720
|
+
case AST_NODE_TYPES48.ChainExpression:
|
|
11623
11721
|
current = parent;
|
|
11624
11722
|
parent = parent.parent;
|
|
11625
11723
|
continue;
|
|
11626
|
-
case
|
|
11627
|
-
case
|
|
11628
|
-
case
|
|
11629
|
-
case
|
|
11630
|
-
case
|
|
11724
|
+
case AST_NODE_TYPES48.IfStatement:
|
|
11725
|
+
case AST_NODE_TYPES48.ConditionalExpression:
|
|
11726
|
+
case AST_NODE_TYPES48.WhileStatement:
|
|
11727
|
+
case AST_NODE_TYPES48.DoWhileStatement:
|
|
11728
|
+
case AST_NODE_TYPES48.ForStatement:
|
|
11631
11729
|
return parent.test === current;
|
|
11632
11730
|
default:
|
|
11633
11731
|
return false;
|
|
@@ -11637,7 +11735,7 @@ var isGuardTestPosition = (node) => {
|
|
|
11637
11735
|
};
|
|
11638
11736
|
var unvalidatedVariableRef = (node, scope, tracked) => {
|
|
11639
11737
|
const unwrapped = unwrap4(node);
|
|
11640
|
-
if (unwrapped === null || unwrapped.type !==
|
|
11738
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES48.Identifier) {
|
|
11641
11739
|
return null;
|
|
11642
11740
|
}
|
|
11643
11741
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -11666,7 +11764,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11666
11764
|
const localFileTextVariables = /* @__PURE__ */ new Set();
|
|
11667
11765
|
const localFileTextRef = (node, scope) => {
|
|
11668
11766
|
const unwrapped = unwrap4(node);
|
|
11669
|
-
if (unwrapped?.type !==
|
|
11767
|
+
if (unwrapped?.type !== AST_NODE_TYPES48.Identifier) return null;
|
|
11670
11768
|
const variable = findVariable2(scope, unwrapped.name);
|
|
11671
11769
|
return variable !== null && localFileTextVariables.has(variable) ? variable : null;
|
|
11672
11770
|
};
|
|
@@ -11735,7 +11833,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11735
11833
|
return {
|
|
11736
11834
|
VariableDeclarator(node) {
|
|
11737
11835
|
const scope = context.sourceCode.getScope(node);
|
|
11738
|
-
if (node.id.type ===
|
|
11836
|
+
if (node.id.type === AST_NODE_TYPES48.Identifier) {
|
|
11739
11837
|
const variable = context.sourceCode.getDeclaredVariables(node)[0];
|
|
11740
11838
|
if (variable !== void 0) {
|
|
11741
11839
|
updateLocalFileText(variable, node.init, scope);
|
|
@@ -11743,7 +11841,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11743
11841
|
trackInitializer(node, scope);
|
|
11744
11842
|
return;
|
|
11745
11843
|
}
|
|
11746
|
-
if (node.id.type ===
|
|
11844
|
+
if (node.id.type === AST_NODE_TYPES48.ObjectPattern || node.id.type === AST_NODE_TYPES48.ArrayPattern) {
|
|
11747
11845
|
if (isRawPayloadSource(
|
|
11748
11846
|
node.init,
|
|
11749
11847
|
(candidate) => localFileTextRef(candidate, scope) !== null
|
|
@@ -11760,7 +11858,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11760
11858
|
},
|
|
11761
11859
|
AssignmentExpression(node) {
|
|
11762
11860
|
const scope = context.sourceCode.getScope(node);
|
|
11763
|
-
if (node.left.type ===
|
|
11861
|
+
if (node.left.type === AST_NODE_TYPES48.Identifier) {
|
|
11764
11862
|
const variable = findVariable2(scope, node.left.name);
|
|
11765
11863
|
if (variable === null) return;
|
|
11766
11864
|
const isLocalText = (candidate) => localFileTextRef(candidate, scope) !== null;
|
|
@@ -11774,7 +11872,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11774
11872
|
}
|
|
11775
11873
|
return;
|
|
11776
11874
|
}
|
|
11777
|
-
if (node.left.type ===
|
|
11875
|
+
if (node.left.type === AST_NODE_TYPES48.ObjectPattern || node.left.type === AST_NODE_TYPES48.ArrayPattern) {
|
|
11778
11876
|
if (isRawPayloadSource(
|
|
11779
11877
|
node.right,
|
|
11780
11878
|
(candidate) => localFileTextRef(candidate, scope) !== null
|
|
@@ -11794,15 +11892,15 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11794
11892
|
}
|
|
11795
11893
|
},
|
|
11796
11894
|
CallExpression(node) {
|
|
11797
|
-
if (node.callee.type !==
|
|
11895
|
+
if (node.callee.type !== AST_NODE_TYPES48.Identifier) return;
|
|
11798
11896
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
11799
11897
|
return;
|
|
11800
11898
|
}
|
|
11801
11899
|
const scope = context.sourceCode.getScope(node);
|
|
11802
11900
|
for (const arg of node.arguments) {
|
|
11803
|
-
if (arg.type ===
|
|
11901
|
+
if (arg.type === AST_NODE_TYPES48.SpreadElement) continue;
|
|
11804
11902
|
const unwrapped = unwrap4(arg);
|
|
11805
|
-
if (unwrapped === null || unwrapped.type !==
|
|
11903
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES48.Identifier) {
|
|
11806
11904
|
continue;
|
|
11807
11905
|
}
|
|
11808
11906
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -11819,14 +11917,14 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11819
11917
|
(candidate) => localFileTextRef(candidate, scope) !== null
|
|
11820
11918
|
)) {
|
|
11821
11919
|
const parent = node.parent;
|
|
11822
|
-
if (parent.type ===
|
|
11920
|
+
if (parent.type === AST_NODE_TYPES48.CallExpression && parent.callee === node && node.property.type === AST_NODE_TYPES48.Identifier && (node.property.name === "parse" || node.property.name === "safeParse" || PROMISE_CHAIN_METHODS.has(node.property.name))) {
|
|
11823
11921
|
return;
|
|
11824
11922
|
}
|
|
11825
11923
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
11826
11924
|
return;
|
|
11827
11925
|
}
|
|
11828
|
-
const variable = obj?.type ===
|
|
11829
|
-
if (variable !== null && obj?.type ===
|
|
11926
|
+
const variable = obj?.type === AST_NODE_TYPES48.Identifier ? unvalidatedVariableRef(obj, scope, unvalidatedVariables) : null;
|
|
11927
|
+
if (variable !== null && obj?.type === AST_NODE_TYPES48.Identifier) {
|
|
11830
11928
|
if (isUseWithinValidatedBranch(node, obj.name)) {
|
|
11831
11929
|
return;
|
|
11832
11930
|
}
|
|
@@ -11846,7 +11944,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11846
11944
|
});
|
|
11847
11945
|
|
|
11848
11946
|
// src/rules/prefer-semantic-colors.ts
|
|
11849
|
-
import { AST_NODE_TYPES as
|
|
11947
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES49 } from "@typescript-eslint/utils";
|
|
11850
11948
|
import { existsSync, readdirSync, readFileSync } from "fs";
|
|
11851
11949
|
import { dirname, join, parse } from "path";
|
|
11852
11950
|
|
|
@@ -11958,7 +12056,7 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
11958
12056
|
var isInsideSvg = (node) => {
|
|
11959
12057
|
let current = node.parent;
|
|
11960
12058
|
while (current !== void 0 && current !== null) {
|
|
11961
|
-
if (current.type ===
|
|
12059
|
+
if (current.type === AST_NODE_TYPES49.JSXElement) {
|
|
11962
12060
|
const name = jsxElementName(current);
|
|
11963
12061
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
11964
12062
|
}
|
|
@@ -11968,8 +12066,8 @@ var isInsideSvg = (node) => {
|
|
|
11968
12066
|
};
|
|
11969
12067
|
function jsxElementName(node) {
|
|
11970
12068
|
const name = node.openingElement.name;
|
|
11971
|
-
if (name.type ===
|
|
11972
|
-
if (name.type ===
|
|
12069
|
+
if (name.type === AST_NODE_TYPES49.JSXIdentifier) return name.name;
|
|
12070
|
+
if (name.type === AST_NODE_TYPES49.JSXMemberExpression && name.property.type === AST_NODE_TYPES49.JSXIdentifier) {
|
|
11973
12071
|
return name.property.name;
|
|
11974
12072
|
}
|
|
11975
12073
|
return null;
|
|
@@ -11995,7 +12093,7 @@ function isSvgLikeElementName(name) {
|
|
|
11995
12093
|
var isInsideIconFactoryPath = (node) => {
|
|
11996
12094
|
let current = node.parent;
|
|
11997
12095
|
while (current !== void 0 && current !== null) {
|
|
11998
|
-
if (current.type ===
|
|
12096
|
+
if (current.type === AST_NODE_TYPES49.Property && propName(current.key) === "path" && current.parent.type === AST_NODE_TYPES49.ObjectExpression && current.parent.parent.type === AST_NODE_TYPES49.CallExpression && current.parent.parent.callee.type === AST_NODE_TYPES49.Identifier && current.parent.parent.callee.name === "createIcon") {
|
|
11999
12097
|
return true;
|
|
12000
12098
|
}
|
|
12001
12099
|
current = current.parent;
|
|
@@ -12129,12 +12227,12 @@ var expandWorkspaceGlob = (root, glob) => {
|
|
|
12129
12227
|
return readdirSync(parent, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => join(parent, entry.name));
|
|
12130
12228
|
};
|
|
12131
12229
|
var propName = (key) => {
|
|
12132
|
-
if (key.type ===
|
|
12133
|
-
if (key.type ===
|
|
12230
|
+
if (key.type === AST_NODE_TYPES49.Identifier) return key.name;
|
|
12231
|
+
if (key.type === AST_NODE_TYPES49.Literal && typeof key.value === "string") return key.value;
|
|
12134
12232
|
return null;
|
|
12135
12233
|
};
|
|
12136
12234
|
var staticallyImportsEmailOrPdfRenderer = (program) => program.body.some((statement) => {
|
|
12137
|
-
if (statement.type !==
|
|
12235
|
+
if (statement.type !== AST_NODE_TYPES49.ImportDeclaration && statement.type !== AST_NODE_TYPES49.ExportNamedDeclaration && statement.type !== AST_NODE_TYPES49.ExportAllDeclaration) {
|
|
12138
12236
|
return false;
|
|
12139
12237
|
}
|
|
12140
12238
|
return statement.source !== null && typeof statement.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(statement.source.value);
|
|
@@ -12187,27 +12285,27 @@ var prefer_semantic_colors_default = createRule({
|
|
|
12187
12285
|
const checkClassNode = (node) => {
|
|
12188
12286
|
if (node === null) return;
|
|
12189
12287
|
switch (node.type) {
|
|
12190
|
-
case
|
|
12288
|
+
case AST_NODE_TYPES49.Literal:
|
|
12191
12289
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
12192
12290
|
break;
|
|
12193
|
-
case
|
|
12291
|
+
case AST_NODE_TYPES49.TemplateLiteral:
|
|
12194
12292
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
12195
12293
|
break;
|
|
12196
|
-
case
|
|
12294
|
+
case AST_NODE_TYPES49.ArrayExpression:
|
|
12197
12295
|
for (const element of node.elements) {
|
|
12198
|
-
if (element !== null && element.type !==
|
|
12296
|
+
if (element !== null && element.type !== AST_NODE_TYPES49.SpreadElement) checkClassNode(element);
|
|
12199
12297
|
}
|
|
12200
12298
|
break;
|
|
12201
|
-
case
|
|
12299
|
+
case AST_NODE_TYPES49.ObjectExpression:
|
|
12202
12300
|
for (const property of node.properties) {
|
|
12203
|
-
if (property.type ===
|
|
12301
|
+
if (property.type === AST_NODE_TYPES49.Property) checkClassNode(property.value);
|
|
12204
12302
|
}
|
|
12205
12303
|
break;
|
|
12206
|
-
case
|
|
12304
|
+
case AST_NODE_TYPES49.ConditionalExpression:
|
|
12207
12305
|
checkClassNode(node.consequent);
|
|
12208
12306
|
checkClassNode(node.alternate);
|
|
12209
12307
|
break;
|
|
12210
|
-
case
|
|
12308
|
+
case AST_NODE_TYPES49.LogicalExpression:
|
|
12211
12309
|
checkClassNode(node.right);
|
|
12212
12310
|
break;
|
|
12213
12311
|
default:
|
|
@@ -12215,32 +12313,32 @@ var prefer_semantic_colors_default = createRule({
|
|
|
12215
12313
|
}
|
|
12216
12314
|
};
|
|
12217
12315
|
const checkColorValueNode = (node) => {
|
|
12218
|
-
if (node.type ===
|
|
12316
|
+
if (node.type === AST_NODE_TYPES49.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value) && !CSS_VAR_REFERENCE_RE.test(node.value)) {
|
|
12219
12317
|
report(node, "inlineColor", { value: node.value });
|
|
12220
12318
|
}
|
|
12221
12319
|
};
|
|
12222
12320
|
return {
|
|
12223
12321
|
"JSXAttribute[name.name='className']"(node) {
|
|
12224
12322
|
if (node.value === null) return;
|
|
12225
|
-
if (node.value.type ===
|
|
12226
|
-
else if (node.value.type ===
|
|
12227
|
-
if (node.value.expression.type !==
|
|
12323
|
+
if (node.value.type === AST_NODE_TYPES49.Literal) checkClassNode(node.value);
|
|
12324
|
+
else if (node.value.type === AST_NODE_TYPES49.JSXExpressionContainer) {
|
|
12325
|
+
if (node.value.expression.type !== AST_NODE_TYPES49.JSXEmptyExpression) {
|
|
12228
12326
|
checkClassNode(node.value.expression);
|
|
12229
12327
|
}
|
|
12230
12328
|
}
|
|
12231
12329
|
},
|
|
12232
12330
|
CallExpression(node) {
|
|
12233
|
-
if (node.callee.type ===
|
|
12331
|
+
if (node.callee.type === AST_NODE_TYPES49.Identifier && node.callee.name === "require" && node.arguments[0]?.type === AST_NODE_TYPES49.Literal && typeof node.arguments[0].value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.arguments[0].value)) {
|
|
12234
12332
|
importsEmailOrPdfRenderer = true;
|
|
12235
12333
|
}
|
|
12236
|
-
if (node.callee.type ===
|
|
12334
|
+
if (node.callee.type === AST_NODE_TYPES49.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
12237
12335
|
for (const arg of node.arguments) {
|
|
12238
|
-
if (arg.type !==
|
|
12336
|
+
if (arg.type !== AST_NODE_TYPES49.SpreadElement) checkClassNode(arg);
|
|
12239
12337
|
}
|
|
12240
12338
|
}
|
|
12241
12339
|
},
|
|
12242
12340
|
VariableDeclarator(node) {
|
|
12243
|
-
if (node.id.type ===
|
|
12341
|
+
if (node.id.type === AST_NODE_TYPES49.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
12244
12342
|
checkClassNode(node.init);
|
|
12245
12343
|
}
|
|
12246
12344
|
},
|
|
@@ -12250,9 +12348,9 @@ var prefer_semantic_colors_default = createRule({
|
|
|
12250
12348
|
},
|
|
12251
12349
|
// SVG artwork colors are exempt; component presentation colors still report.
|
|
12252
12350
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
12253
|
-
if (node.value?.type !==
|
|
12351
|
+
if (node.value?.type !== AST_NODE_TYPES49.Literal) return;
|
|
12254
12352
|
const owner = node.parent.name;
|
|
12255
|
-
if (owner.type ===
|
|
12353
|
+
if (owner.type === AST_NODE_TYPES49.JSXIdentifier && SVG_SHAPE_PRIMITIVES.has(owner.name)) {
|
|
12256
12354
|
return;
|
|
12257
12355
|
}
|
|
12258
12356
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
@@ -12266,7 +12364,7 @@ var prefer_semantic_colors_default = createRule({
|
|
|
12266
12364
|
if (name !== null && STYLE_COLOR_PROPS.has(name)) checkColorValueNode(node.value);
|
|
12267
12365
|
},
|
|
12268
12366
|
ImportExpression(node) {
|
|
12269
|
-
if (node.source.type ===
|
|
12367
|
+
if (node.source.type === AST_NODE_TYPES49.Literal && typeof node.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.source.value)) {
|
|
12270
12368
|
importsEmailOrPdfRenderer = true;
|
|
12271
12369
|
}
|
|
12272
12370
|
},
|
|
@@ -12468,7 +12566,7 @@ var prefer_server_actions_default = createRule({
|
|
|
12468
12566
|
});
|
|
12469
12567
|
|
|
12470
12568
|
// src/rules/prefer-whole-object-assertion.ts
|
|
12471
|
-
import { AST_NODE_TYPES as
|
|
12569
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES50 } from "@typescript-eslint/utils";
|
|
12472
12570
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
12473
12571
|
var SYNTHETIC_LITERAL_MATCHERS = /* @__PURE__ */ new Map([
|
|
12474
12572
|
["toBeNull", "null"],
|
|
@@ -12493,11 +12591,11 @@ var preferWholeObjectAssertionDocumentation = {
|
|
|
12493
12591
|
};
|
|
12494
12592
|
function literalText(node, getText) {
|
|
12495
12593
|
switch (node.type) {
|
|
12496
|
-
case
|
|
12594
|
+
case AST_NODE_TYPES50.Literal:
|
|
12497
12595
|
return "regex" in node ? null : getText(node);
|
|
12498
|
-
case
|
|
12596
|
+
case AST_NODE_TYPES50.TemplateLiteral:
|
|
12499
12597
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
12500
|
-
case
|
|
12598
|
+
case AST_NODE_TYPES50.UnaryExpression:
|
|
12501
12599
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
12502
12600
|
default:
|
|
12503
12601
|
return null;
|
|
@@ -12505,15 +12603,15 @@ function literalText(node, getText) {
|
|
|
12505
12603
|
}
|
|
12506
12604
|
function isPureReceiver(node) {
|
|
12507
12605
|
switch (node.type) {
|
|
12508
|
-
case
|
|
12509
|
-
case
|
|
12606
|
+
case AST_NODE_TYPES50.Identifier:
|
|
12607
|
+
case AST_NODE_TYPES50.ThisExpression:
|
|
12510
12608
|
return true;
|
|
12511
|
-
case
|
|
12609
|
+
case AST_NODE_TYPES50.MemberExpression:
|
|
12512
12610
|
if (node.optional) {
|
|
12513
12611
|
return false;
|
|
12514
12612
|
}
|
|
12515
12613
|
if (node.computed) {
|
|
12516
|
-
return node.property.type ===
|
|
12614
|
+
return node.property.type === AST_NODE_TYPES50.Literal && isPureReceiver(node.object);
|
|
12517
12615
|
}
|
|
12518
12616
|
return isPureReceiver(node.object);
|
|
12519
12617
|
default:
|
|
@@ -12521,7 +12619,7 @@ function isPureReceiver(node) {
|
|
|
12521
12619
|
}
|
|
12522
12620
|
}
|
|
12523
12621
|
function literalIndex(node) {
|
|
12524
|
-
if (node.type !==
|
|
12622
|
+
if (node.type !== AST_NODE_TYPES50.Literal || typeof node.value !== "number") {
|
|
12525
12623
|
return null;
|
|
12526
12624
|
}
|
|
12527
12625
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
@@ -12529,8 +12627,8 @@ function literalIndex(node) {
|
|
|
12529
12627
|
function propertyAccess(node) {
|
|
12530
12628
|
const path = [];
|
|
12531
12629
|
let current = node;
|
|
12532
|
-
while (current.type ===
|
|
12533
|
-
if (current.property.type !==
|
|
12630
|
+
while (current.type === AST_NODE_TYPES50.MemberExpression && !current.computed && !current.optional) {
|
|
12631
|
+
if (current.property.type !== AST_NODE_TYPES50.Identifier || COLLECTION_PROPERTIES.has(current.property.name) || LITERAL_KEY_HAZARDS.has(current.property.name)) return null;
|
|
12534
12632
|
path.unshift(current.property.name);
|
|
12535
12633
|
current = current.object;
|
|
12536
12634
|
}
|
|
@@ -12558,24 +12656,24 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
12558
12656
|
}
|
|
12559
12657
|
const { sourceCode } = context;
|
|
12560
12658
|
function parseAssertion(statement) {
|
|
12561
|
-
if (statement.type !==
|
|
12659
|
+
if (statement.type !== AST_NODE_TYPES50.ExpressionStatement) {
|
|
12562
12660
|
return null;
|
|
12563
12661
|
}
|
|
12564
12662
|
const call = statement.expression;
|
|
12565
|
-
if (call.type !==
|
|
12663
|
+
if (call.type !== AST_NODE_TYPES50.CallExpression) {
|
|
12566
12664
|
return null;
|
|
12567
12665
|
}
|
|
12568
12666
|
const callee = call.callee;
|
|
12569
|
-
if (callee.type !==
|
|
12667
|
+
if (callee.type !== AST_NODE_TYPES50.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES50.Identifier) {
|
|
12570
12668
|
return null;
|
|
12571
12669
|
}
|
|
12572
12670
|
const matcher = callee.property.name;
|
|
12573
12671
|
const expectCall = callee.object;
|
|
12574
|
-
if (expectCall.type !==
|
|
12672
|
+
if (expectCall.type !== AST_NODE_TYPES50.CallExpression || expectCall.callee.type !== AST_NODE_TYPES50.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
12575
12673
|
return null;
|
|
12576
12674
|
}
|
|
12577
12675
|
const actual = expectCall.arguments[0];
|
|
12578
|
-
if (actual === void 0 || actual.type !==
|
|
12676
|
+
if (actual === void 0 || actual.type !== AST_NODE_TYPES50.MemberExpression || actual.optional) {
|
|
12579
12677
|
return null;
|
|
12580
12678
|
}
|
|
12581
12679
|
if (!isPureReceiver(actual.object)) {
|
|
@@ -12604,7 +12702,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
12604
12702
|
return null;
|
|
12605
12703
|
}
|
|
12606
12704
|
const expected = call.arguments[0];
|
|
12607
|
-
if (call.arguments.length !== 1 || expected === void 0 || expected.type ===
|
|
12705
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === AST_NODE_TYPES50.SpreadElement) {
|
|
12608
12706
|
return null;
|
|
12609
12707
|
}
|
|
12610
12708
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
@@ -12745,7 +12843,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
12745
12843
|
});
|
|
12746
12844
|
|
|
12747
12845
|
// src/rules/repeated-static-call-cases.ts
|
|
12748
|
-
import { AST_NODE_TYPES as
|
|
12846
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES51, ASTUtils as ASTUtils15 } from "@typescript-eslint/utils";
|
|
12749
12847
|
var repeatedStaticCallCasesDocumentation = {
|
|
12750
12848
|
summary: "Report three or more consecutive literal call assertions that should be independently named test cases.",
|
|
12751
12849
|
rationale: "Copy-pasted cases obscure the input table and stop later cases from being reported after the first failure.",
|
|
@@ -12766,67 +12864,67 @@ var EXPECT_MODIFIERS = /* @__PURE__ */ new Set(["not", "rejects", "resolves"]);
|
|
|
12766
12864
|
var SNAPSHOT_MATCHERS = /snapshot/iu;
|
|
12767
12865
|
var MIN_CASES2 = 3;
|
|
12768
12866
|
function staticMemberName5(node) {
|
|
12769
|
-
if (!node.computed && node.property.type ===
|
|
12770
|
-
if (node.computed && node.property.type ===
|
|
12867
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES51.Identifier) return node.property.name;
|
|
12868
|
+
if (node.computed && node.property.type === AST_NODE_TYPES51.Literal && typeof node.property.value === "string") return node.property.value;
|
|
12771
12869
|
return null;
|
|
12772
12870
|
}
|
|
12773
12871
|
function importedName3(identifier, context, modules) {
|
|
12774
12872
|
const variable = ASTUtils15.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
12775
12873
|
if (variable === null || variable.defs.length === 0) return identifier.name;
|
|
12776
12874
|
for (const definition of variable.defs) {
|
|
12777
|
-
if (definition.node.type !==
|
|
12875
|
+
if (definition.node.type !== AST_NODE_TYPES51.ImportSpecifier) continue;
|
|
12778
12876
|
const declaration = definition.node.parent;
|
|
12779
|
-
if (declaration.type !==
|
|
12877
|
+
if (declaration.type !== AST_NODE_TYPES51.ImportDeclaration || typeof declaration.source.value !== "string" || !modules.has(declaration.source.value)) continue;
|
|
12780
12878
|
const imported = definition.node.imported;
|
|
12781
|
-
return imported.type ===
|
|
12879
|
+
return imported.type === AST_NODE_TYPES51.Identifier ? imported.name : String(imported.value);
|
|
12782
12880
|
}
|
|
12783
12881
|
return null;
|
|
12784
12882
|
}
|
|
12785
12883
|
function isDirectTestCallback2(node, context) {
|
|
12786
|
-
if (node.type !==
|
|
12884
|
+
if (node.type !== AST_NODE_TYPES51.ArrowFunctionExpression && node.type !== AST_NODE_TYPES51.FunctionExpression) return false;
|
|
12787
12885
|
const call = node.parent;
|
|
12788
|
-
if (call?.type !==
|
|
12886
|
+
if (call?.type !== AST_NODE_TYPES51.CallExpression || !call.arguments.includes(node)) return false;
|
|
12789
12887
|
const root = testRoot2(call.callee);
|
|
12790
12888
|
return root !== null && TEST_NAMES2.has(importedName3(root, context, TEST_MODULES4) ?? "");
|
|
12791
12889
|
}
|
|
12792
12890
|
function testRoot2(callee) {
|
|
12793
|
-
if (callee.type ===
|
|
12794
|
-
if (callee.type !==
|
|
12891
|
+
if (callee.type === AST_NODE_TYPES51.Identifier) return callee;
|
|
12892
|
+
if (callee.type !== AST_NODE_TYPES51.MemberExpression) return null;
|
|
12795
12893
|
const modifier = staticMemberName5(callee);
|
|
12796
12894
|
return modifier !== null && TEST_MODIFIERS4.has(modifier) ? testRoot2(callee.object) : null;
|
|
12797
12895
|
}
|
|
12798
12896
|
function isStatic(node) {
|
|
12799
|
-
if (node.type ===
|
|
12897
|
+
if (node.type === AST_NODE_TYPES51.TSAsExpression || node.type === AST_NODE_TYPES51.TSTypeAssertion || node.type === AST_NODE_TYPES51.TSSatisfiesExpression || node.type === AST_NODE_TYPES51.TSNonNullExpression) return isStatic(node.expression);
|
|
12800
12898
|
switch (node.type) {
|
|
12801
|
-
case
|
|
12899
|
+
case AST_NODE_TYPES51.Literal:
|
|
12802
12900
|
return true;
|
|
12803
|
-
case
|
|
12901
|
+
case AST_NODE_TYPES51.TemplateLiteral:
|
|
12804
12902
|
return node.expressions.length === 0;
|
|
12805
|
-
case
|
|
12903
|
+
case AST_NODE_TYPES51.UnaryExpression:
|
|
12806
12904
|
return (node.operator === "+" || node.operator === "-") && isStatic(node.argument);
|
|
12807
|
-
case
|
|
12808
|
-
return node.elements.every((item) => item !== null && item.type !==
|
|
12809
|
-
case
|
|
12810
|
-
return node.properties.every((property) => property.type ===
|
|
12905
|
+
case AST_NODE_TYPES51.ArrayExpression:
|
|
12906
|
+
return node.elements.every((item) => item !== null && item.type !== AST_NODE_TYPES51.SpreadElement && isStatic(item));
|
|
12907
|
+
case AST_NODE_TYPES51.ObjectExpression:
|
|
12908
|
+
return node.properties.every((property) => property.type === AST_NODE_TYPES51.Property && !property.computed && property.kind === "init" && property.value.type !== AST_NODE_TYPES51.AssignmentPattern && isStatic(property.value));
|
|
12811
12909
|
default:
|
|
12812
12910
|
return false;
|
|
12813
12911
|
}
|
|
12814
12912
|
}
|
|
12815
12913
|
function staticShape(node) {
|
|
12816
|
-
if (node.type ===
|
|
12914
|
+
if (node.type === AST_NODE_TYPES51.TSAsExpression || node.type === AST_NODE_TYPES51.TSTypeAssertion || node.type === AST_NODE_TYPES51.TSSatisfiesExpression || node.type === AST_NODE_TYPES51.TSNonNullExpression) return staticShape(node.expression);
|
|
12817
12915
|
switch (node.type) {
|
|
12818
|
-
case
|
|
12916
|
+
case AST_NODE_TYPES51.Literal:
|
|
12819
12917
|
return `literal:${typeof node.value}`;
|
|
12820
|
-
case
|
|
12918
|
+
case AST_NODE_TYPES51.TemplateLiteral:
|
|
12821
12919
|
return "template";
|
|
12822
|
-
case
|
|
12920
|
+
case AST_NODE_TYPES51.UnaryExpression:
|
|
12823
12921
|
return `unary:${node.operator}:${staticShape(node.argument)}`;
|
|
12824
|
-
case
|
|
12825
|
-
return `array(${node.elements.map((item) => item === null || item.type ===
|
|
12826
|
-
case
|
|
12922
|
+
case AST_NODE_TYPES51.ArrayExpression:
|
|
12923
|
+
return `array(${node.elements.map((item) => item === null || item.type === AST_NODE_TYPES51.SpreadElement ? "invalid" : staticShape(item)).join(",")})`;
|
|
12924
|
+
case AST_NODE_TYPES51.ObjectExpression:
|
|
12827
12925
|
return `object(${node.properties.map((property) => {
|
|
12828
|
-
if (property.type !==
|
|
12829
|
-
const key = property.key.type ===
|
|
12926
|
+
if (property.type !== AST_NODE_TYPES51.Property || property.computed || property.value.type === AST_NODE_TYPES51.AssignmentPattern) return "invalid";
|
|
12927
|
+
const key = property.key.type === AST_NODE_TYPES51.Identifier ? property.key.name : String(property.key.value);
|
|
12830
12928
|
return `${key}:${staticShape(property.value)}`;
|
|
12831
12929
|
}).join(",")})`;
|
|
12832
12930
|
default:
|
|
@@ -12834,16 +12932,16 @@ function staticShape(node) {
|
|
|
12834
12932
|
}
|
|
12835
12933
|
}
|
|
12836
12934
|
function assertionShape(statement, context) {
|
|
12837
|
-
if (statement.type !==
|
|
12935
|
+
if (statement.type !== AST_NODE_TYPES51.ExpressionStatement || statement.expression.type !== AST_NODE_TYPES51.CallExpression) return null;
|
|
12838
12936
|
const matcherCall = statement.expression;
|
|
12839
|
-
if (matcherCall.callee.type !==
|
|
12937
|
+
if (matcherCall.callee.type !== AST_NODE_TYPES51.MemberExpression || matcherCall.callee.computed || matcherCall.callee.property.type !== AST_NODE_TYPES51.Identifier || matcherCall.arguments.length !== 1) return null;
|
|
12840
12938
|
const matcher = matcherCall.callee.property.name;
|
|
12841
12939
|
if (SNAPSHOT_MATCHERS.test(matcher)) return null;
|
|
12842
12940
|
const chain = expectCallFromMatcher(matcherCall.callee);
|
|
12843
|
-
if (chain === null || chain.call.callee.type !==
|
|
12941
|
+
if (chain === null || chain.call.callee.type !== AST_NODE_TYPES51.Identifier || importedName3(chain.call.callee, context, ASSERTION_MODULES3) !== "expect" || chain.call.arguments.length !== 1) return null;
|
|
12844
12942
|
const observed = chain.call.arguments[0];
|
|
12845
12943
|
const expected = matcherCall.arguments[0];
|
|
12846
|
-
if (observed?.type !==
|
|
12944
|
+
if (observed?.type !== AST_NODE_TYPES51.CallExpression || observed.callee.type !== AST_NODE_TYPES51.Identifier || observed.arguments.length === 0 || observed.arguments.some((arg) => arg.type === AST_NODE_TYPES51.SpreadElement || !isStatic(arg)) || expected?.type === AST_NODE_TYPES51.SpreadElement || expected === void 0 || !isStatic(expected)) return null;
|
|
12847
12945
|
const skeleton = `${observed.callee.name}/${observed.arguments.map((item) => staticShape(item)).join(",")}/${chain.modifiers.join(".")}/${matcher}/${staticShape(expected)}`;
|
|
12848
12946
|
const values = [...observed.arguments, expected].map((item) => context.sourceCode.getText(item)).join("\0");
|
|
12849
12947
|
return { statement, skeleton, values };
|
|
@@ -12851,13 +12949,13 @@ function assertionShape(statement, context) {
|
|
|
12851
12949
|
function expectCallFromMatcher(node) {
|
|
12852
12950
|
const modifiers = [];
|
|
12853
12951
|
let receiver = node.object;
|
|
12854
|
-
while (receiver.type ===
|
|
12952
|
+
while (receiver.type === AST_NODE_TYPES51.MemberExpression) {
|
|
12855
12953
|
const modifier = staticMemberName5(receiver);
|
|
12856
12954
|
if (modifier === null || !EXPECT_MODIFIERS.has(modifier)) return null;
|
|
12857
12955
|
modifiers.unshift(modifier);
|
|
12858
12956
|
receiver = receiver.object;
|
|
12859
12957
|
}
|
|
12860
|
-
return receiver.type ===
|
|
12958
|
+
return receiver.type === AST_NODE_TYPES51.CallExpression ? { call: receiver, modifiers } : null;
|
|
12861
12959
|
}
|
|
12862
12960
|
var repeated_static_call_cases_default = createRule({
|
|
12863
12961
|
name: "repeated-static-call-cases",
|
|
@@ -12877,7 +12975,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
12877
12975
|
return {
|
|
12878
12976
|
"CallExpression > ArrowFunctionExpression, CallExpression > FunctionExpression"(node) {
|
|
12879
12977
|
const call = node.parent;
|
|
12880
|
-
if (call?.type ===
|
|
12978
|
+
if (call?.type === AST_NODE_TYPES51.CallExpression) {
|
|
12881
12979
|
const duplicate = duplicateTestBodyCandidate(call, sourceCode);
|
|
12882
12980
|
if (duplicate !== null && duplicate.body === node) {
|
|
12883
12981
|
const groups = duplicateGroups.get(duplicate.container) ?? /* @__PURE__ */ new Map();
|
|
@@ -12887,7 +12985,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
12887
12985
|
duplicateGroups.set(duplicate.container, groups);
|
|
12888
12986
|
}
|
|
12889
12987
|
}
|
|
12890
|
-
if (!isDirectTestCallback2(node, context) || node.body.type !==
|
|
12988
|
+
if (!isDirectTestCallback2(node, context) || node.body.type !== AST_NODE_TYPES51.BlockStatement) return;
|
|
12891
12989
|
let run = [];
|
|
12892
12990
|
const flush = () => {
|
|
12893
12991
|
if (run.length >= MIN_CASES2 && new Set(run.map((item) => item.values)).size > 1) {
|
|
@@ -12928,7 +13026,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
12928
13026
|
});
|
|
12929
13027
|
|
|
12930
13028
|
// src/rules/prefer-zod-infer.ts
|
|
12931
|
-
import { AST_NODE_TYPES as
|
|
13029
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES52 } from "@typescript-eslint/utils";
|
|
12932
13030
|
var preferZodInferDocumentation = {
|
|
12933
13031
|
summary: "Derive a type from its Zod schema with `z.infer` instead of hand-writing a twin declaration beside it.",
|
|
12934
13032
|
rationale: "A derived type stays synchronized when the runtime schema changes.",
|
|
@@ -12981,47 +13079,47 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
12981
13079
|
"Schema"
|
|
12982
13080
|
]);
|
|
12983
13081
|
var LEAF_NODE_TYPES = {
|
|
12984
|
-
string: [
|
|
12985
|
-
email: [
|
|
12986
|
-
url: [
|
|
12987
|
-
uuid: [
|
|
12988
|
-
ulid: [
|
|
12989
|
-
cuid: [
|
|
12990
|
-
cuid2: [
|
|
12991
|
-
nanoid: [
|
|
12992
|
-
iso: [
|
|
12993
|
-
number: [
|
|
12994
|
-
int: [
|
|
12995
|
-
float32: [
|
|
12996
|
-
float64: [
|
|
12997
|
-
boolean: [
|
|
12998
|
-
bigint: [
|
|
12999
|
-
symbol: [
|
|
13000
|
-
any: [
|
|
13001
|
-
unknown: [
|
|
13002
|
-
never: [
|
|
13003
|
-
void: [
|
|
13004
|
-
null: [
|
|
13005
|
-
undefined: [
|
|
13006
|
-
literal: [
|
|
13007
|
-
date: [
|
|
13008
|
-
array: [
|
|
13009
|
-
tuple: [
|
|
13010
|
-
object: [
|
|
13011
|
-
strictObject: [
|
|
13012
|
-
looseObject: [
|
|
13013
|
-
record: [
|
|
13014
|
-
map: [
|
|
13015
|
-
set: [
|
|
13016
|
-
promise: [
|
|
13017
|
-
enum: [
|
|
13018
|
-
nativeEnum: [
|
|
13019
|
-
union: [
|
|
13020
|
-
discriminatedUnion: [
|
|
13021
|
-
intersection: [
|
|
13082
|
+
string: [AST_NODE_TYPES52.TSStringKeyword],
|
|
13083
|
+
email: [AST_NODE_TYPES52.TSStringKeyword],
|
|
13084
|
+
url: [AST_NODE_TYPES52.TSStringKeyword],
|
|
13085
|
+
uuid: [AST_NODE_TYPES52.TSStringKeyword],
|
|
13086
|
+
ulid: [AST_NODE_TYPES52.TSStringKeyword],
|
|
13087
|
+
cuid: [AST_NODE_TYPES52.TSStringKeyword],
|
|
13088
|
+
cuid2: [AST_NODE_TYPES52.TSStringKeyword],
|
|
13089
|
+
nanoid: [AST_NODE_TYPES52.TSStringKeyword],
|
|
13090
|
+
iso: [AST_NODE_TYPES52.TSStringKeyword],
|
|
13091
|
+
number: [AST_NODE_TYPES52.TSNumberKeyword],
|
|
13092
|
+
int: [AST_NODE_TYPES52.TSNumberKeyword],
|
|
13093
|
+
float32: [AST_NODE_TYPES52.TSNumberKeyword],
|
|
13094
|
+
float64: [AST_NODE_TYPES52.TSNumberKeyword],
|
|
13095
|
+
boolean: [AST_NODE_TYPES52.TSBooleanKeyword],
|
|
13096
|
+
bigint: [AST_NODE_TYPES52.TSBigIntKeyword],
|
|
13097
|
+
symbol: [AST_NODE_TYPES52.TSSymbolKeyword],
|
|
13098
|
+
any: [AST_NODE_TYPES52.TSAnyKeyword],
|
|
13099
|
+
unknown: [AST_NODE_TYPES52.TSUnknownKeyword],
|
|
13100
|
+
never: [AST_NODE_TYPES52.TSNeverKeyword],
|
|
13101
|
+
void: [AST_NODE_TYPES52.TSVoidKeyword],
|
|
13102
|
+
null: [AST_NODE_TYPES52.TSNullKeyword],
|
|
13103
|
+
undefined: [AST_NODE_TYPES52.TSUndefinedKeyword],
|
|
13104
|
+
literal: [AST_NODE_TYPES52.TSLiteralType],
|
|
13105
|
+
date: [AST_NODE_TYPES52.TSTypeReference],
|
|
13106
|
+
array: [AST_NODE_TYPES52.TSArrayType, AST_NODE_TYPES52.TSTypeReference],
|
|
13107
|
+
tuple: [AST_NODE_TYPES52.TSTupleType],
|
|
13108
|
+
object: [AST_NODE_TYPES52.TSTypeLiteral, AST_NODE_TYPES52.TSTypeReference],
|
|
13109
|
+
strictObject: [AST_NODE_TYPES52.TSTypeLiteral, AST_NODE_TYPES52.TSTypeReference],
|
|
13110
|
+
looseObject: [AST_NODE_TYPES52.TSTypeLiteral, AST_NODE_TYPES52.TSTypeReference],
|
|
13111
|
+
record: [AST_NODE_TYPES52.TSTypeReference, AST_NODE_TYPES52.TSTypeLiteral],
|
|
13112
|
+
map: [AST_NODE_TYPES52.TSTypeReference],
|
|
13113
|
+
set: [AST_NODE_TYPES52.TSTypeReference],
|
|
13114
|
+
promise: [AST_NODE_TYPES52.TSTypeReference],
|
|
13115
|
+
enum: [AST_NODE_TYPES52.TSUnionType, AST_NODE_TYPES52.TSTypeReference, AST_NODE_TYPES52.TSLiteralType],
|
|
13116
|
+
nativeEnum: [AST_NODE_TYPES52.TSUnionType, AST_NODE_TYPES52.TSTypeReference, AST_NODE_TYPES52.TSLiteralType],
|
|
13117
|
+
union: [AST_NODE_TYPES52.TSUnionType, AST_NODE_TYPES52.TSTypeReference],
|
|
13118
|
+
discriminatedUnion: [AST_NODE_TYPES52.TSUnionType, AST_NODE_TYPES52.TSTypeReference],
|
|
13119
|
+
intersection: [AST_NODE_TYPES52.TSIntersectionType, AST_NODE_TYPES52.TSTypeReference]
|
|
13022
13120
|
};
|
|
13023
13121
|
function primitiveLiteralKey(node) {
|
|
13024
|
-
if (node.type !==
|
|
13122
|
+
if (node.type !== AST_NODE_TYPES52.Literal) {
|
|
13025
13123
|
return null;
|
|
13026
13124
|
}
|
|
13027
13125
|
if (node.value === null) {
|
|
@@ -13053,13 +13151,13 @@ function staticZodDomain(leaf, call) {
|
|
|
13053
13151
|
}
|
|
13054
13152
|
if (leaf === "literal") {
|
|
13055
13153
|
const [argument] = call.arguments;
|
|
13056
|
-
if (argument === void 0 || argument.type ===
|
|
13154
|
+
if (argument === void 0 || argument.type === AST_NODE_TYPES52.SpreadElement) {
|
|
13057
13155
|
return null;
|
|
13058
13156
|
}
|
|
13059
|
-
if (argument.type ===
|
|
13157
|
+
if (argument.type === AST_NODE_TYPES52.ArrayExpression) {
|
|
13060
13158
|
return exactDomain(
|
|
13061
13159
|
argument.elements.map(
|
|
13062
|
-
(element) => element === null || element.type ===
|
|
13160
|
+
(element) => element === null || element.type === AST_NODE_TYPES52.SpreadElement ? null : primitiveLiteralKey(element)
|
|
13063
13161
|
)
|
|
13064
13162
|
);
|
|
13065
13163
|
}
|
|
@@ -13067,13 +13165,13 @@ function staticZodDomain(leaf, call) {
|
|
|
13067
13165
|
}
|
|
13068
13166
|
if (leaf === "enum") {
|
|
13069
13167
|
const [argument] = call.arguments;
|
|
13070
|
-
if (argument === void 0 || argument.type ===
|
|
13168
|
+
if (argument === void 0 || argument.type === AST_NODE_TYPES52.SpreadElement) {
|
|
13071
13169
|
return null;
|
|
13072
13170
|
}
|
|
13073
|
-
if (argument.type ===
|
|
13171
|
+
if (argument.type === AST_NODE_TYPES52.ArrayExpression) {
|
|
13074
13172
|
return exactDomain(
|
|
13075
13173
|
argument.elements.map((element) => {
|
|
13076
|
-
if (element === null || element.type ===
|
|
13174
|
+
if (element === null || element.type === AST_NODE_TYPES52.SpreadElement) {
|
|
13077
13175
|
return null;
|
|
13078
13176
|
}
|
|
13079
13177
|
const key = primitiveLiteralKey(element);
|
|
@@ -13081,10 +13179,10 @@ function staticZodDomain(leaf, call) {
|
|
|
13081
13179
|
})
|
|
13082
13180
|
);
|
|
13083
13181
|
}
|
|
13084
|
-
if (argument.type ===
|
|
13182
|
+
if (argument.type === AST_NODE_TYPES52.ObjectExpression) {
|
|
13085
13183
|
return exactDomain(
|
|
13086
13184
|
argument.properties.map((property) => {
|
|
13087
|
-
if (property.type !==
|
|
13185
|
+
if (property.type !== AST_NODE_TYPES52.Property || property.computed || property.kind !== "init" || property.method || property.shorthand) {
|
|
13088
13186
|
return null;
|
|
13089
13187
|
}
|
|
13090
13188
|
const key = primitiveLiteralKey(property.value);
|
|
@@ -13111,15 +13209,15 @@ function sameDomain(left, right) {
|
|
|
13111
13209
|
return true;
|
|
13112
13210
|
}
|
|
13113
13211
|
function isExportedDeclaration(node) {
|
|
13114
|
-
return node.parent?.type ===
|
|
13212
|
+
return node.parent?.type === AST_NODE_TYPES52.ExportNamedDeclaration;
|
|
13115
13213
|
}
|
|
13116
13214
|
function isModuleLevelConst(node) {
|
|
13117
13215
|
const declaration = node.parent;
|
|
13118
|
-
if (declaration.type !==
|
|
13216
|
+
if (declaration.type !== AST_NODE_TYPES52.VariableDeclaration || declaration.kind !== "const") {
|
|
13119
13217
|
return false;
|
|
13120
13218
|
}
|
|
13121
13219
|
const container = declaration.parent;
|
|
13122
|
-
return container.type ===
|
|
13220
|
+
return container.type === AST_NODE_TYPES52.Program || container.type === AST_NODE_TYPES52.ExportNamedDeclaration && container.parent.type === AST_NODE_TYPES52.Program;
|
|
13123
13221
|
}
|
|
13124
13222
|
function normalizeSchemaName(name) {
|
|
13125
13223
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -13128,20 +13226,20 @@ function normalizeTypeName(name) {
|
|
|
13128
13226
|
return name.replace(/Type$/, "").toLowerCase();
|
|
13129
13227
|
}
|
|
13130
13228
|
function unwrapNullish(annotation) {
|
|
13131
|
-
if (annotation.type !==
|
|
13229
|
+
if (annotation.type !== AST_NODE_TYPES52.TSUnionType) {
|
|
13132
13230
|
return {
|
|
13133
13231
|
core: annotation,
|
|
13134
|
-
nullable: annotation.type ===
|
|
13232
|
+
nullable: annotation.type === AST_NODE_TYPES52.TSNullKeyword
|
|
13135
13233
|
};
|
|
13136
13234
|
}
|
|
13137
13235
|
const rest = [];
|
|
13138
13236
|
let nullable = false;
|
|
13139
13237
|
for (const member of annotation.types) {
|
|
13140
|
-
if (member.type ===
|
|
13238
|
+
if (member.type === AST_NODE_TYPES52.TSNullKeyword) {
|
|
13141
13239
|
nullable = true;
|
|
13142
13240
|
continue;
|
|
13143
13241
|
}
|
|
13144
|
-
if (member.type ===
|
|
13242
|
+
if (member.type === AST_NODE_TYPES52.TSUndefinedKeyword) {
|
|
13145
13243
|
continue;
|
|
13146
13244
|
}
|
|
13147
13245
|
rest.push(member);
|
|
@@ -13175,18 +13273,18 @@ function leafAgrees(field, annotation) {
|
|
|
13175
13273
|
return null;
|
|
13176
13274
|
}
|
|
13177
13275
|
if (leaf === "date") {
|
|
13178
|
-
return core.type ===
|
|
13276
|
+
return core.type === AST_NODE_TYPES52.TSTypeReference && core.typeName.type === AST_NODE_TYPES52.Identifier && core.typeName.name === "Date";
|
|
13179
13277
|
}
|
|
13180
13278
|
return expected.includes(core.type);
|
|
13181
13279
|
}
|
|
13182
13280
|
function typeLiteralDomain(annotation) {
|
|
13183
|
-
const members = annotation.type ===
|
|
13281
|
+
const members = annotation.type === AST_NODE_TYPES52.TSUnionType ? annotation.types : [annotation];
|
|
13184
13282
|
const keys = [];
|
|
13185
13283
|
for (const member of members) {
|
|
13186
|
-
if (member.type ===
|
|
13284
|
+
if (member.type === AST_NODE_TYPES52.TSNullKeyword) {
|
|
13187
13285
|
continue;
|
|
13188
13286
|
}
|
|
13189
|
-
if (member.type !==
|
|
13287
|
+
if (member.type !== AST_NODE_TYPES52.TSLiteralType) {
|
|
13190
13288
|
return null;
|
|
13191
13289
|
}
|
|
13192
13290
|
keys.push(primitiveLiteralKey(member.literal));
|
|
@@ -13194,11 +13292,11 @@ function typeLiteralDomain(annotation) {
|
|
|
13194
13292
|
return exactDomain(keys);
|
|
13195
13293
|
}
|
|
13196
13294
|
function staticStringUnionDomain(node) {
|
|
13197
|
-
if (node.type !==
|
|
13295
|
+
if (node.type !== AST_NODE_TYPES52.TSUnionType) {
|
|
13198
13296
|
return null;
|
|
13199
13297
|
}
|
|
13200
13298
|
const keys = node.types.map((member) => {
|
|
13201
|
-
if (member.type !==
|
|
13299
|
+
if (member.type !== AST_NODE_TYPES52.TSLiteralType) {
|
|
13202
13300
|
return null;
|
|
13203
13301
|
}
|
|
13204
13302
|
const key = primitiveLiteralKey(member.literal);
|
|
@@ -13266,14 +13364,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
13266
13364
|
function zodCallChain(node) {
|
|
13267
13365
|
const chain = [];
|
|
13268
13366
|
let current = node;
|
|
13269
|
-
while (current.type ===
|
|
13367
|
+
while (current.type === AST_NODE_TYPES52.CallExpression) {
|
|
13270
13368
|
const callee = current.callee;
|
|
13271
|
-
if (callee.type !==
|
|
13369
|
+
if (callee.type !== AST_NODE_TYPES52.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES52.Identifier) {
|
|
13272
13370
|
return null;
|
|
13273
13371
|
}
|
|
13274
13372
|
chain.push(current);
|
|
13275
13373
|
const receiver = callee.object;
|
|
13276
|
-
if (receiver.type ===
|
|
13374
|
+
if (receiver.type === AST_NODE_TYPES52.Identifier) {
|
|
13277
13375
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
13278
13376
|
}
|
|
13279
13377
|
current = receiver;
|
|
@@ -13282,14 +13380,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
13282
13380
|
}
|
|
13283
13381
|
function methodName2(call) {
|
|
13284
13382
|
const callee = call.callee;
|
|
13285
|
-
return callee.type ===
|
|
13383
|
+
return callee.type === AST_NODE_TYPES52.MemberExpression && callee.property.type === AST_NODE_TYPES52.Identifier ? callee.property.name : "";
|
|
13286
13384
|
}
|
|
13287
13385
|
function recordZodImport(node) {
|
|
13288
13386
|
if (!isZodModule(node.source.value)) {
|
|
13289
13387
|
return;
|
|
13290
13388
|
}
|
|
13291
13389
|
for (const specifier of node.specifiers) {
|
|
13292
|
-
if (specifier.type ===
|
|
13390
|
+
if (specifier.type === AST_NODE_TYPES52.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES52.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES52.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES52.Identifier && specifier.imported.name === "z") {
|
|
13293
13391
|
zodNamespaces.add(specifier.local.name);
|
|
13294
13392
|
}
|
|
13295
13393
|
}
|
|
@@ -13299,13 +13397,13 @@ var prefer_zod_infer_default = createRule({
|
|
|
13299
13397
|
let current = node;
|
|
13300
13398
|
let leaf = null;
|
|
13301
13399
|
let leafCall = null;
|
|
13302
|
-
while (current.type ===
|
|
13400
|
+
while (current.type === AST_NODE_TYPES52.CallExpression) {
|
|
13303
13401
|
const callee = current.callee;
|
|
13304
|
-
if (callee.type !==
|
|
13402
|
+
if (callee.type !== AST_NODE_TYPES52.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES52.Identifier) {
|
|
13305
13403
|
break;
|
|
13306
13404
|
}
|
|
13307
13405
|
const receiver = callee.object;
|
|
13308
|
-
if (receiver.type ===
|
|
13406
|
+
if (receiver.type === AST_NODE_TYPES52.Identifier && zodNamespaces.has(receiver.name)) {
|
|
13309
13407
|
leaf = callee.property.name;
|
|
13310
13408
|
leafCall = current;
|
|
13311
13409
|
break;
|
|
@@ -13336,20 +13434,20 @@ var prefer_zod_infer_default = createRule({
|
|
|
13336
13434
|
return domain instanceof Set && domain.size >= 2 ? domain : null;
|
|
13337
13435
|
}
|
|
13338
13436
|
function inferredSchemaName(node) {
|
|
13339
|
-
if (node.type !==
|
|
13437
|
+
if (node.type !== AST_NODE_TYPES52.TSTypeReference || node.typeName.type !== AST_NODE_TYPES52.TSQualifiedName || node.typeName.left.type !== AST_NODE_TYPES52.Identifier || !zodNamespaces.has(node.typeName.left.name) || node.typeName.right.name !== "infer") {
|
|
13340
13438
|
return null;
|
|
13341
13439
|
}
|
|
13342
13440
|
const arguments_ = node.typeArguments?.params ?? [];
|
|
13343
13441
|
const [argument] = arguments_;
|
|
13344
|
-
return arguments_.length === 1 && argument?.type ===
|
|
13442
|
+
return arguments_.length === 1 && argument?.type === AST_NODE_TYPES52.TSTypeQuery && argument.exprName.type === AST_NODE_TYPES52.Identifier ? argument.exprName.name : null;
|
|
13345
13443
|
}
|
|
13346
13444
|
function recordLiteralUnions(members, owner, ownerName, exported) {
|
|
13347
13445
|
for (const member of members) {
|
|
13348
|
-
if (member.type !==
|
|
13446
|
+
if (member.type !== AST_NODE_TYPES52.TSPropertySignature || member.computed || member.optional || member.readonly || member.typeAnnotation === void 0) {
|
|
13349
13447
|
continue;
|
|
13350
13448
|
}
|
|
13351
13449
|
const key = member.key;
|
|
13352
|
-
const propertyName3 = key.type ===
|
|
13450
|
+
const propertyName3 = key.type === AST_NODE_TYPES52.Identifier ? key.name : key.type === AST_NODE_TYPES52.Literal && typeof key.value === "string" ? key.value : null;
|
|
13353
13451
|
if (propertyName3 === null) {
|
|
13354
13452
|
continue;
|
|
13355
13453
|
}
|
|
@@ -13359,7 +13457,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
13359
13457
|
}
|
|
13360
13458
|
const annotation = member.typeAnnotation.typeAnnotation;
|
|
13361
13459
|
const domain = staticStringUnionDomain(annotation);
|
|
13362
|
-
if (domain === null || annotation.type !==
|
|
13460
|
+
if (domain === null || annotation.type !== AST_NODE_TYPES52.TSUnionType) {
|
|
13363
13461
|
continue;
|
|
13364
13462
|
}
|
|
13365
13463
|
literalUnionOccurrences.push({
|
|
@@ -13390,16 +13488,16 @@ var prefer_zod_infer_default = createRule({
|
|
|
13390
13488
|
return null;
|
|
13391
13489
|
}
|
|
13392
13490
|
const shape = base.arguments[0];
|
|
13393
|
-
if (shape === void 0 || shape.type !==
|
|
13491
|
+
if (shape === void 0 || shape.type !== AST_NODE_TYPES52.ObjectExpression) {
|
|
13394
13492
|
return null;
|
|
13395
13493
|
}
|
|
13396
13494
|
const fields = /* @__PURE__ */ new Map();
|
|
13397
13495
|
for (const property of shape.properties) {
|
|
13398
|
-
if (property.type !==
|
|
13496
|
+
if (property.type !== AST_NODE_TYPES52.Property || property.computed) {
|
|
13399
13497
|
return null;
|
|
13400
13498
|
}
|
|
13401
13499
|
const { key } = property;
|
|
13402
|
-
const name = key.type ===
|
|
13500
|
+
const name = key.type === AST_NODE_TYPES52.Identifier ? key.name : key.type === AST_NODE_TYPES52.Literal && typeof key.value === "string" ? key.value : null;
|
|
13403
13501
|
if (name === null) {
|
|
13404
13502
|
return null;
|
|
13405
13503
|
}
|
|
@@ -13410,11 +13508,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
13410
13508
|
function typeMembers(members) {
|
|
13411
13509
|
const result = /* @__PURE__ */ new Map();
|
|
13412
13510
|
for (const member of members) {
|
|
13413
|
-
if (member.type !==
|
|
13511
|
+
if (member.type !== AST_NODE_TYPES52.TSPropertySignature || member.computed) {
|
|
13414
13512
|
return null;
|
|
13415
13513
|
}
|
|
13416
13514
|
const { key } = member;
|
|
13417
|
-
const name = key.type ===
|
|
13515
|
+
const name = key.type === AST_NODE_TYPES52.Identifier ? key.name : key.type === AST_NODE_TYPES52.Literal && typeof key.value === "string" ? key.value : null;
|
|
13418
13516
|
if (name === null) {
|
|
13419
13517
|
return null;
|
|
13420
13518
|
}
|
|
@@ -13429,8 +13527,8 @@ var prefer_zod_infer_default = createRule({
|
|
|
13429
13527
|
return result.size === 0 ? null : result;
|
|
13430
13528
|
}
|
|
13431
13529
|
function collectConstrainedNames(node) {
|
|
13432
|
-
if (node.type ===
|
|
13433
|
-
if (node.typeName.type ===
|
|
13530
|
+
if (node.type === AST_NODE_TYPES52.TSTypeReference) {
|
|
13531
|
+
if (node.typeName.type === AST_NODE_TYPES52.Identifier) {
|
|
13434
13532
|
constrainedTypeNames.add(node.typeName.name);
|
|
13435
13533
|
}
|
|
13436
13534
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -13438,11 +13536,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
13438
13536
|
}
|
|
13439
13537
|
return;
|
|
13440
13538
|
}
|
|
13441
|
-
if (node.type ===
|
|
13539
|
+
if (node.type === AST_NODE_TYPES52.TSArrayType) {
|
|
13442
13540
|
collectConstrainedNames(node.elementType);
|
|
13443
13541
|
return;
|
|
13444
13542
|
}
|
|
13445
|
-
if (node.type ===
|
|
13543
|
+
if (node.type === AST_NODE_TYPES52.TSUnionType || node.type === AST_NODE_TYPES52.TSIntersectionType) {
|
|
13446
13544
|
for (const member of node.types) {
|
|
13447
13545
|
collectConstrainedNames(member);
|
|
13448
13546
|
}
|
|
@@ -13486,7 +13584,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
13486
13584
|
return {
|
|
13487
13585
|
Program(node) {
|
|
13488
13586
|
for (const statement of node.body) {
|
|
13489
|
-
if (statement.type ===
|
|
13587
|
+
if (statement.type === AST_NODE_TYPES52.ImportDeclaration) {
|
|
13490
13588
|
recordZodImport(statement);
|
|
13491
13589
|
}
|
|
13492
13590
|
}
|
|
@@ -13495,7 +13593,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
13495
13593
|
recordZodImport(node);
|
|
13496
13594
|
},
|
|
13497
13595
|
VariableDeclarator(node) {
|
|
13498
|
-
if (node.id.type !==
|
|
13596
|
+
if (node.id.type !== AST_NODE_TYPES52.Identifier || node.init == null) {
|
|
13499
13597
|
return;
|
|
13500
13598
|
}
|
|
13501
13599
|
const fields = schemaFields(node.init);
|
|
@@ -13512,14 +13610,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
13512
13610
|
},
|
|
13513
13611
|
/** Records `XSchema.transform(...)` and equivalent module-level reshaping. */
|
|
13514
13612
|
"MemberExpression[computed=false]"(node) {
|
|
13515
|
-
if (node.object.type ===
|
|
13613
|
+
if (node.object.type === AST_NODE_TYPES52.Identifier && node.property.type === AST_NODE_TYPES52.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
13516
13614
|
reshapedSchemaNames.add(node.object.name);
|
|
13517
13615
|
}
|
|
13518
13616
|
},
|
|
13519
13617
|
/** Records every type argument carried by a Zod constraint. */
|
|
13520
13618
|
TSTypeReference(node) {
|
|
13521
13619
|
const { typeName } = node;
|
|
13522
|
-
const referenced = typeName.type ===
|
|
13620
|
+
const referenced = typeName.type === AST_NODE_TYPES52.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES52.TSQualifiedName && typeName.right.type === AST_NODE_TYPES52.Identifier ? typeName.right.name : null;
|
|
13523
13621
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
13524
13622
|
return;
|
|
13525
13623
|
}
|
|
@@ -13551,7 +13649,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
13551
13649
|
typeName: node.id.name
|
|
13552
13650
|
});
|
|
13553
13651
|
}
|
|
13554
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
13652
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== AST_NODE_TYPES52.TSTypeLiteral) {
|
|
13555
13653
|
return;
|
|
13556
13654
|
}
|
|
13557
13655
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -13652,7 +13750,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
13652
13750
|
// src/rules/require-assert-never.ts
|
|
13653
13751
|
import {
|
|
13654
13752
|
ESLintUtils as ESLintUtils4,
|
|
13655
|
-
AST_NODE_TYPES as
|
|
13753
|
+
AST_NODE_TYPES as AST_NODE_TYPES53
|
|
13656
13754
|
} from "@typescript-eslint/utils";
|
|
13657
13755
|
import ts3 from "typescript";
|
|
13658
13756
|
var requireAssertNeverDocumentation = {
|
|
@@ -13666,14 +13764,14 @@ var requireAssertNeverDocumentation = {
|
|
|
13666
13764
|
]
|
|
13667
13765
|
};
|
|
13668
13766
|
var isRuntimeHandlingStatement = (statement) => {
|
|
13669
|
-
if (statement.type ===
|
|
13670
|
-
if (statement.type ===
|
|
13767
|
+
if (statement.type === AST_NODE_TYPES53.EmptyStatement) return false;
|
|
13768
|
+
if (statement.type === AST_NODE_TYPES53.BreakStatement) {
|
|
13671
13769
|
return statement.label !== null;
|
|
13672
13770
|
}
|
|
13673
|
-
if (statement.type ===
|
|
13771
|
+
if (statement.type === AST_NODE_TYPES53.TSTypeAliasDeclaration || statement.type === AST_NODE_TYPES53.TSInterfaceDeclaration) {
|
|
13674
13772
|
return false;
|
|
13675
13773
|
}
|
|
13676
|
-
if (statement.type ===
|
|
13774
|
+
if (statement.type === AST_NODE_TYPES53.BlockStatement) {
|
|
13677
13775
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
13678
13776
|
}
|
|
13679
13777
|
return true;
|
|
@@ -13689,7 +13787,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
13689
13787
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
13690
13788
|
}
|
|
13691
13789
|
const only = defaultCase.consequent[0];
|
|
13692
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
13790
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === AST_NODE_TYPES53.BlockStatement && !only.body.some(isRuntimeHandlingStatement)) {
|
|
13693
13791
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
13694
13792
|
}
|
|
13695
13793
|
return false;
|
|
@@ -13772,7 +13870,7 @@ var require_assert_never_default = createRule({
|
|
|
13772
13870
|
});
|
|
13773
13871
|
|
|
13774
13872
|
// src/rules/require-fetch-timeout.ts
|
|
13775
|
-
import { AST_NODE_TYPES as
|
|
13873
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES54, ASTUtils as ASTUtils16 } from "@typescript-eslint/utils";
|
|
13776
13874
|
var requireFetchTimeoutDocumentation = {
|
|
13777
13875
|
summary: "Require an abort `signal` (e.g. `AbortSignal.timeout(ms)`) on global `fetch()` calls so stalled upstreams cannot hang the caller forever.",
|
|
13778
13876
|
rationale: "An unbounded request can occupy work indefinitely when an upstream stalls.",
|
|
@@ -13798,14 +13896,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
13798
13896
|
return false;
|
|
13799
13897
|
}
|
|
13800
13898
|
function initProvablyLacksSignal(init) {
|
|
13801
|
-
if (init.type !==
|
|
13899
|
+
if (init.type !== AST_NODE_TYPES54.ObjectExpression) {
|
|
13802
13900
|
return false;
|
|
13803
13901
|
}
|
|
13804
13902
|
for (const prop of init.properties) {
|
|
13805
|
-
if (prop.type ===
|
|
13903
|
+
if (prop.type === AST_NODE_TYPES54.SpreadElement) {
|
|
13806
13904
|
return false;
|
|
13807
13905
|
}
|
|
13808
|
-
if (prop.key.type ===
|
|
13906
|
+
if (prop.key.type === AST_NODE_TYPES54.Identifier && prop.key.name === "signal" || prop.key.type === AST_NODE_TYPES54.Literal && prop.key.value === "signal") {
|
|
13809
13907
|
return false;
|
|
13810
13908
|
}
|
|
13811
13909
|
if (prop.computed) {
|
|
@@ -13815,7 +13913,7 @@ function initProvablyLacksSignal(init) {
|
|
|
13815
13913
|
return true;
|
|
13816
13914
|
}
|
|
13817
13915
|
function isInlineUrl(node, resolvesToGlobal) {
|
|
13818
|
-
return node.type ===
|
|
13916
|
+
return node.type === AST_NODE_TYPES54.Literal && typeof node.value === "string" || node.type === AST_NODE_TYPES54.TemplateLiteral || node.type === AST_NODE_TYPES54.NewExpression && node.callee.type === AST_NODE_TYPES54.Identifier && node.callee.name === "URL" && resolvesToGlobal(node.callee);
|
|
13819
13917
|
}
|
|
13820
13918
|
var require_fetch_timeout_default = createRule({
|
|
13821
13919
|
name: "require-fetch-timeout",
|
|
@@ -13857,10 +13955,10 @@ var require_fetch_timeout_default = createRule({
|
|
|
13857
13955
|
return variable === null || variable.defs.length === 0;
|
|
13858
13956
|
}
|
|
13859
13957
|
function isGlobalFetchCall2(callee) {
|
|
13860
|
-
if (callee.type ===
|
|
13958
|
+
if (callee.type === AST_NODE_TYPES54.Identifier) {
|
|
13861
13959
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
13862
13960
|
}
|
|
13863
|
-
return callee.type ===
|
|
13961
|
+
return callee.type === AST_NODE_TYPES54.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES54.Identifier && callee.property.name === "fetch" && callee.object.type === AST_NODE_TYPES54.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
13864
13962
|
}
|
|
13865
13963
|
function localConstInitProvablyLacksSignal(identifier) {
|
|
13866
13964
|
const variable = ASTUtils16.findVariable(
|
|
@@ -13869,14 +13967,14 @@ var require_fetch_timeout_default = createRule({
|
|
|
13869
13967
|
);
|
|
13870
13968
|
if (variable?.defs.length !== 1) return false;
|
|
13871
13969
|
const definition = variable.defs[0];
|
|
13872
|
-
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !==
|
|
13970
|
+
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !== AST_NODE_TYPES54.ObjectExpression || !initProvablyLacksSignal(definition.node.init)) {
|
|
13873
13971
|
return false;
|
|
13874
13972
|
}
|
|
13875
13973
|
for (const reference of variable.references) {
|
|
13876
13974
|
const ref = reference.identifier;
|
|
13877
13975
|
if (ref === identifier || ref === definition.name) continue;
|
|
13878
13976
|
const member = ref.parent;
|
|
13879
|
-
if (member.type !==
|
|
13977
|
+
if (member.type !== AST_NODE_TYPES54.MemberExpression || member.object !== ref || member.computed || member.property.type !== AST_NODE_TYPES54.Identifier || member.property.name === "signal" || member.parent.type !== AST_NODE_TYPES54.AssignmentExpression || member.parent.left !== member) {
|
|
13880
13978
|
return false;
|
|
13881
13979
|
}
|
|
13882
13980
|
}
|
|
@@ -13891,7 +13989,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
13891
13989
|
if (node.arguments.length === 1 && first !== void 0 && !isInlineUrl(first, resolvesToGlobal)) {
|
|
13892
13990
|
return;
|
|
13893
13991
|
}
|
|
13894
|
-
if (init === void 0 || initProvablyLacksSignal(init) || init.type ===
|
|
13992
|
+
if (init === void 0 || initProvablyLacksSignal(init) || init.type === AST_NODE_TYPES54.Identifier && localConstInitProvablyLacksSignal(init)) {
|
|
13895
13993
|
context.report({ node, messageId: "missingSignal" });
|
|
13896
13994
|
}
|
|
13897
13995
|
}
|
|
@@ -13900,7 +13998,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
13900
13998
|
});
|
|
13901
13999
|
|
|
13902
14000
|
// src/rules/require-port-for-service.ts
|
|
13903
|
-
import { AST_NODE_TYPES as
|
|
14001
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES55 } from "@typescript-eslint/utils";
|
|
13904
14002
|
var requirePortForServiceDocumentation = {
|
|
13905
14003
|
summary: "Advise when an exported service with injected collaborators has public methods not covered by its declared ports.",
|
|
13906
14004
|
rationale: "A declared port keeps consumers coupled to the service capability instead of its concrete implementation.",
|
|
@@ -13925,45 +14023,45 @@ var ROUTER_FACTORY_NAME = "Router";
|
|
|
13925
14023
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
13926
14024
|
var STORAGE_ASSIGNMENT_OPERATORS = /* @__PURE__ */ new Set(["=", "&&=", "??=", "||="]);
|
|
13927
14025
|
var staticMemberName6 = (member) => {
|
|
13928
|
-
if (member.property.type ===
|
|
13929
|
-
if (!member.computed && member.property.type ===
|
|
13930
|
-
return member.computed && member.property.type ===
|
|
14026
|
+
if (member.property.type === AST_NODE_TYPES55.PrivateIdentifier) return `#${member.property.name}`;
|
|
14027
|
+
if (!member.computed && member.property.type === AST_NODE_TYPES55.Identifier) return member.property.name;
|
|
14028
|
+
return member.computed && member.property.type === AST_NODE_TYPES55.Literal && typeof member.property.value === "string" ? member.property.value : null;
|
|
13931
14029
|
};
|
|
13932
14030
|
var detachedValueExports = (program) => {
|
|
13933
14031
|
const names = /* @__PURE__ */ new Set();
|
|
13934
14032
|
for (const statement of program.body) {
|
|
13935
|
-
if (statement.type ===
|
|
14033
|
+
if (statement.type === AST_NODE_TYPES55.ExportNamedDeclaration && statement.declaration === null && statement.source === null && statement.exportKind !== "type") {
|
|
13936
14034
|
for (const specifier of statement.specifiers) {
|
|
13937
14035
|
if (specifier.exportKind !== "type") names.add(specifier.local.name);
|
|
13938
14036
|
}
|
|
13939
|
-
} else if (statement.type ===
|
|
14037
|
+
} else if (statement.type === AST_NODE_TYPES55.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES55.Identifier) {
|
|
13940
14038
|
names.add(statement.declaration.name);
|
|
13941
|
-
} else if (statement.type ===
|
|
14039
|
+
} else if (statement.type === AST_NODE_TYPES55.TSExportAssignment && statement.expression.type === AST_NODE_TYPES55.Identifier) {
|
|
13942
14040
|
names.add(statement.expression.name);
|
|
13943
14041
|
}
|
|
13944
14042
|
}
|
|
13945
14043
|
return names;
|
|
13946
14044
|
};
|
|
13947
|
-
var isExportedClass2 = (node, detached) => node.parent.type ===
|
|
14045
|
+
var isExportedClass2 = (node, detached) => node.parent.type === AST_NODE_TYPES55.ExportNamedDeclaration || node.parent.type === AST_NODE_TYPES55.ExportDefaultDeclaration || node.id !== null && detached.has(node.id.name);
|
|
13948
14046
|
var readTypeReference = (annotation) => {
|
|
13949
|
-
if (annotation?.type ===
|
|
14047
|
+
if (annotation?.type === AST_NODE_TYPES55.TSUnionType) {
|
|
13950
14048
|
const members = annotation.types.filter(
|
|
13951
|
-
(member) => member.type !==
|
|
14049
|
+
(member) => member.type !== AST_NODE_TYPES55.TSUndefinedKeyword && member.type !== AST_NODE_TYPES55.TSNullKeyword
|
|
13952
14050
|
);
|
|
13953
14051
|
annotation = members.length === 1 ? members[0] : void 0;
|
|
13954
14052
|
}
|
|
13955
|
-
if (annotation === void 0 || annotation.type !==
|
|
14053
|
+
if (annotation === void 0 || annotation.type !== AST_NODE_TYPES55.TSTypeReference) return null;
|
|
13956
14054
|
const { typeName } = annotation;
|
|
13957
|
-
const rightmost = typeName.type ===
|
|
14055
|
+
const rightmost = typeName.type === AST_NODE_TYPES55.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES55.TSQualifiedName ? typeName.right.name : null;
|
|
13958
14056
|
if (rightmost === null) return null;
|
|
13959
14057
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
13960
14058
|
};
|
|
13961
|
-
var qualifiedName = (name) => name.type ===
|
|
14059
|
+
var qualifiedName = (name) => name.type === AST_NODE_TYPES55.Identifier ? name.name : name.type === AST_NODE_TYPES55.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
13962
14060
|
var propertySignatureTypes = (members) => {
|
|
13963
14061
|
const types = /* @__PURE__ */ new Map();
|
|
13964
14062
|
for (const member of members) {
|
|
13965
|
-
if (member.type !==
|
|
13966
|
-
if (member.computed || member.key.type !==
|
|
14063
|
+
if (member.type !== AST_NODE_TYPES55.TSPropertySignature) continue;
|
|
14064
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES55.Identifier) continue;
|
|
13967
14065
|
const reference = readTypeReference(member.typeAnnotation?.typeAnnotation);
|
|
13968
14066
|
if (reference === null) continue;
|
|
13969
14067
|
types.set(member.key.name, reference);
|
|
@@ -13974,18 +14072,18 @@ var fileTypeIndex = (program) => {
|
|
|
13974
14072
|
const objects = /* @__PURE__ */ new Map();
|
|
13975
14073
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
13976
14074
|
for (const statement of program.body) {
|
|
13977
|
-
const declaration = statement.type ===
|
|
13978
|
-
if (declaration?.type ===
|
|
14075
|
+
const declaration = statement.type === AST_NODE_TYPES55.ExportNamedDeclaration ? statement.declaration : statement;
|
|
14076
|
+
if (declaration?.type === AST_NODE_TYPES55.TSInterfaceDeclaration) {
|
|
13979
14077
|
objects.set(declaration.id.name, propertySignatureTypes(declaration.body.body));
|
|
13980
14078
|
continue;
|
|
13981
14079
|
}
|
|
13982
|
-
if (declaration?.type !==
|
|
14080
|
+
if (declaration?.type !== AST_NODE_TYPES55.TSTypeAliasDeclaration) continue;
|
|
13983
14081
|
const aliased = declaration.typeAnnotation;
|
|
13984
|
-
if (aliased.type ===
|
|
14082
|
+
if (aliased.type === AST_NODE_TYPES55.TSFunctionType || aliased.type === AST_NODE_TYPES55.TSConstructorType) {
|
|
13985
14083
|
functionAliases.add(declaration.id.name);
|
|
13986
14084
|
continue;
|
|
13987
14085
|
}
|
|
13988
|
-
const literals = aliased.type ===
|
|
14086
|
+
const literals = aliased.type === AST_NODE_TYPES55.TSTypeLiteral ? [aliased] : aliased.type === AST_NODE_TYPES55.TSIntersectionType ? aliased.types.filter((part) => part.type === AST_NODE_TYPES55.TSTypeLiteral) : [];
|
|
13989
14087
|
if (literals.length === 0) continue;
|
|
13990
14088
|
const merged = /* @__PURE__ */ new Map();
|
|
13991
14089
|
for (const literal of literals) {
|
|
@@ -14013,10 +14111,10 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
14013
14111
|
while (pending.length > 0) {
|
|
14014
14112
|
const current = pending.pop();
|
|
14015
14113
|
if (current === void 0) break;
|
|
14016
|
-
if (current.type ===
|
|
14017
|
-
const expression = current.type ===
|
|
14018
|
-
const storedField = expression?.type ===
|
|
14019
|
-
if (expression?.type !==
|
|
14114
|
+
if (current.type === AST_NODE_TYPES55.ArrowFunctionExpression || current.type === AST_NODE_TYPES55.FunctionExpression || current.type === AST_NODE_TYPES55.FunctionDeclaration || current.type === AST_NODE_TYPES55.ClassExpression || current.type === AST_NODE_TYPES55.ClassDeclaration) continue;
|
|
14115
|
+
const expression = current.type === AST_NODE_TYPES55.ExpressionStatement ? current.expression : null;
|
|
14116
|
+
const storedField = expression?.type === AST_NODE_TYPES55.AssignmentExpression && expression.left.type === AST_NODE_TYPES55.MemberExpression && expression.left.object.type === AST_NODE_TYPES55.ThisExpression ? staticMemberName6(expression.left) : null;
|
|
14117
|
+
if (expression?.type !== AST_NODE_TYPES55.AssignmentExpression || !STORAGE_ASSIGNMENT_OPERATORS.has(expression.operator) || expression.left.type !== AST_NODE_TYPES55.MemberExpression || expression.left.object.type !== AST_NODE_TYPES55.ThisExpression || storedField === null) {
|
|
14020
14118
|
for (const key of Object.keys(current)) {
|
|
14021
14119
|
if (key === "parent") continue;
|
|
14022
14120
|
const value = current[key];
|
|
@@ -14029,14 +14127,14 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
14029
14127
|
continue;
|
|
14030
14128
|
}
|
|
14031
14129
|
let source = expression.right;
|
|
14032
|
-
while (source.type ===
|
|
14033
|
-
if (source.type ===
|
|
14130
|
+
while (source.type === AST_NODE_TYPES55.TSNonNullExpression || source.type === AST_NODE_TYPES55.TSAsExpression || source.type === AST_NODE_TYPES55.TSSatisfiesExpression || source.type === AST_NODE_TYPES55.TSTypeAssertion) source = source.expression;
|
|
14131
|
+
if (source.type === AST_NODE_TYPES55.NewExpression) {
|
|
14034
14132
|
constructedFields += 1;
|
|
14035
|
-
} else if (source.type ===
|
|
14133
|
+
} else if (source.type === AST_NODE_TYPES55.Identifier) {
|
|
14036
14134
|
const fields = storedFieldsFrom.get(source.name) ?? /* @__PURE__ */ new Set();
|
|
14037
14135
|
fields.add(storedField);
|
|
14038
14136
|
storedFieldsFrom.set(source.name, fields);
|
|
14039
|
-
} else if (source.type ===
|
|
14137
|
+
} else if (source.type === AST_NODE_TYPES55.MemberExpression && source.object.type === AST_NODE_TYPES55.Identifier) {
|
|
14040
14138
|
const fields = storedFieldsFrom.get(source.object.name) ?? /* @__PURE__ */ new Set();
|
|
14041
14139
|
fields.add(storedField);
|
|
14042
14140
|
storedFieldsFrom.set(source.object.name, fields);
|
|
@@ -14046,7 +14144,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
14046
14144
|
const collaborators = [];
|
|
14047
14145
|
for (const parameter of ctor.value.params) {
|
|
14048
14146
|
for (const reference of parameterCollaborators(parameter, declared)) {
|
|
14049
|
-
const fields = parameter.type ===
|
|
14147
|
+
const fields = parameter.type === AST_NODE_TYPES55.TSParameterProperty ? [reference.name] : [...storedFieldsFrom.get(reference.name) ?? []];
|
|
14050
14148
|
if (fields.length === 0) continue;
|
|
14051
14149
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
14052
14150
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -14061,8 +14159,8 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
14061
14159
|
};
|
|
14062
14160
|
var parameterCollaborators = (parameter, declared) => {
|
|
14063
14161
|
let target = parameter;
|
|
14064
|
-
if (target.type ===
|
|
14065
|
-
if (target.type ===
|
|
14162
|
+
if (target.type === AST_NODE_TYPES55.AssignmentPattern) target = target.left;
|
|
14163
|
+
if (target.type === AST_NODE_TYPES55.ObjectPattern) {
|
|
14066
14164
|
return objectPatternCollaborators(target, declared);
|
|
14067
14165
|
}
|
|
14068
14166
|
const named2 = namedParameterCollaborator(parameter);
|
|
@@ -14070,9 +14168,9 @@ var parameterCollaborators = (parameter, declared) => {
|
|
|
14070
14168
|
};
|
|
14071
14169
|
var namedParameterCollaborator = (annotated) => {
|
|
14072
14170
|
let target = annotated;
|
|
14073
|
-
if (target.type ===
|
|
14074
|
-
if (target.type ===
|
|
14075
|
-
if (target.type !==
|
|
14171
|
+
if (target.type === AST_NODE_TYPES55.TSParameterProperty) target = target.parameter;
|
|
14172
|
+
if (target.type === AST_NODE_TYPES55.AssignmentPattern) target = target.left;
|
|
14173
|
+
if (target.type !== AST_NODE_TYPES55.Identifier) return null;
|
|
14076
14174
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
14077
14175
|
if (reference === null) return null;
|
|
14078
14176
|
return { name: target.name, ...reference, fields: [] };
|
|
@@ -14084,11 +14182,11 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
14084
14182
|
if (members === null) return [];
|
|
14085
14183
|
const collaborators = [];
|
|
14086
14184
|
for (const property of pattern.properties) {
|
|
14087
|
-
if (property.type !==
|
|
14088
|
-
if (property.key.type !==
|
|
14185
|
+
if (property.type !== AST_NODE_TYPES55.Property || property.computed) continue;
|
|
14186
|
+
if (property.key.type !== AST_NODE_TYPES55.Identifier) continue;
|
|
14089
14187
|
const key = property.key.name;
|
|
14090
|
-
const bound = property.value.type ===
|
|
14091
|
-
if (bound.type !==
|
|
14188
|
+
const bound = property.value.type === AST_NODE_TYPES55.AssignmentPattern ? property.value.left : property.value;
|
|
14189
|
+
if (bound.type !== AST_NODE_TYPES55.Identifier) continue;
|
|
14092
14190
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
14093
14191
|
const reference = members.get(key);
|
|
14094
14192
|
if (reference === void 0) continue;
|
|
@@ -14097,21 +14195,21 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
14097
14195
|
return collaborators;
|
|
14098
14196
|
};
|
|
14099
14197
|
var bagMemberTypes = (annotation, declared) => {
|
|
14100
|
-
if (annotation.type ===
|
|
14198
|
+
if (annotation.type === AST_NODE_TYPES55.TSTypeLiteral) {
|
|
14101
14199
|
return propertySignatureTypes(annotation.members);
|
|
14102
14200
|
}
|
|
14103
|
-
if (annotation.type !==
|
|
14201
|
+
if (annotation.type !== AST_NODE_TYPES55.TSTypeReference || annotation.typeName.type !== AST_NODE_TYPES55.Identifier) {
|
|
14104
14202
|
return null;
|
|
14105
14203
|
}
|
|
14106
14204
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
14107
14205
|
};
|
|
14108
14206
|
var isFrameworkWiring = (body2) => subtreeHas(body2, (node) => {
|
|
14109
|
-
if (node.type ===
|
|
14207
|
+
if (node.type === AST_NODE_TYPES55.CallExpression) {
|
|
14110
14208
|
const { callee } = node;
|
|
14111
|
-
if (callee.type ===
|
|
14112
|
-
return callee.type ===
|
|
14209
|
+
if (callee.type === AST_NODE_TYPES55.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
14210
|
+
return callee.type === AST_NODE_TYPES55.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES55.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
14113
14211
|
}
|
|
14114
|
-
return node.type ===
|
|
14212
|
+
return node.type === AST_NODE_TYPES55.TSTypeReference && node.typeName.type === AST_NODE_TYPES55.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
14115
14213
|
});
|
|
14116
14214
|
var subtreeHas = (root, found) => {
|
|
14117
14215
|
let hit = false;
|
|
@@ -14138,19 +14236,19 @@ var invokedInstanceField = (call) => {
|
|
|
14138
14236
|
const direct = instanceField(call.callee);
|
|
14139
14237
|
if (direct !== null) return direct;
|
|
14140
14238
|
let callee = call.callee;
|
|
14141
|
-
while (callee.type ===
|
|
14142
|
-
return callee.type ===
|
|
14239
|
+
while (callee.type === AST_NODE_TYPES55.ChainExpression || callee.type === AST_NODE_TYPES55.TSAsExpression || callee.type === AST_NODE_TYPES55.TSNonNullExpression || callee.type === AST_NODE_TYPES55.TSSatisfiesExpression || callee.type === AST_NODE_TYPES55.TSTypeAssertion) callee = callee.expression;
|
|
14240
|
+
return callee.type === AST_NODE_TYPES55.MemberExpression ? instanceField(callee.object) : null;
|
|
14143
14241
|
};
|
|
14144
14242
|
var instanceField = (candidate) => {
|
|
14145
14243
|
let node = candidate;
|
|
14146
|
-
while (node.type ===
|
|
14147
|
-
return node.type ===
|
|
14244
|
+
while (node.type === AST_NODE_TYPES55.ChainExpression || node.type === AST_NODE_TYPES55.TSAsExpression || node.type === AST_NODE_TYPES55.TSNonNullExpression || node.type === AST_NODE_TYPES55.TSSatisfiesExpression || node.type === AST_NODE_TYPES55.TSTypeAssertion) node = node.expression;
|
|
14245
|
+
return node.type === AST_NODE_TYPES55.MemberExpression && node.object.type === AST_NODE_TYPES55.ThisExpression ? staticMemberName6(node) : null;
|
|
14148
14246
|
};
|
|
14149
14247
|
var behaviorallyInvokedFields = (body2) => {
|
|
14150
14248
|
const invoked = /* @__PURE__ */ new Set();
|
|
14151
14249
|
const visit = (current) => {
|
|
14152
|
-
if (current.type ===
|
|
14153
|
-
if (current.type ===
|
|
14250
|
+
if (current.type === AST_NODE_TYPES55.ClassDeclaration || current.type === AST_NODE_TYPES55.ClassExpression || current.type === AST_NODE_TYPES55.FunctionDeclaration || current.type === AST_NODE_TYPES55.FunctionExpression) return;
|
|
14251
|
+
if (current.type === AST_NODE_TYPES55.CallExpression) {
|
|
14154
14252
|
const field = invokedInstanceField(current);
|
|
14155
14253
|
if (field !== null) invoked.add(field);
|
|
14156
14254
|
}
|
|
@@ -14163,14 +14261,14 @@ var behaviorallyInvokedFields = (body2) => {
|
|
|
14163
14261
|
}
|
|
14164
14262
|
};
|
|
14165
14263
|
for (const member of body2.body) {
|
|
14166
|
-
if (member.type ===
|
|
14167
|
-
if (member.type ===
|
|
14264
|
+
if (member.type === AST_NODE_TYPES55.StaticBlock || member.static) continue;
|
|
14265
|
+
if (member.type === AST_NODE_TYPES55.MethodDefinition) {
|
|
14168
14266
|
if (member.value.body !== null && member.value.body !== void 0) visit(member.value.body);
|
|
14169
14267
|
continue;
|
|
14170
14268
|
}
|
|
14171
|
-
if (member.type !==
|
|
14269
|
+
if (member.type !== AST_NODE_TYPES55.PropertyDefinition || member.value === null) continue;
|
|
14172
14270
|
visit(
|
|
14173
|
-
member.value.type ===
|
|
14271
|
+
member.value.type === AST_NODE_TYPES55.ArrowFunctionExpression ? member.value.body : member.value
|
|
14174
14272
|
);
|
|
14175
14273
|
}
|
|
14176
14274
|
return invoked;
|
|
@@ -14190,25 +14288,25 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
14190
14288
|
var fileInterfaceNames = (program) => {
|
|
14191
14289
|
const names = [];
|
|
14192
14290
|
for (const statement of program.body) {
|
|
14193
|
-
const declaration = statement.type ===
|
|
14194
|
-
if (declaration?.type ===
|
|
14291
|
+
const declaration = statement.type === AST_NODE_TYPES55.ExportNamedDeclaration ? statement.declaration : statement;
|
|
14292
|
+
if (declaration?.type === AST_NODE_TYPES55.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
14195
14293
|
}
|
|
14196
14294
|
return names;
|
|
14197
14295
|
};
|
|
14198
14296
|
var publicMethodNames = (body2, functionAliases) => {
|
|
14199
14297
|
const names = [];
|
|
14200
14298
|
for (const member of body2.body) {
|
|
14201
|
-
if (member.type ===
|
|
14299
|
+
if (member.type === AST_NODE_TYPES55.PropertyDefinition) {
|
|
14202
14300
|
if (member.static || member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
14203
|
-
if (member.value?.type !==
|
|
14204
|
-
names.push(member.key.type ===
|
|
14301
|
+
if (member.value?.type !== AST_NODE_TYPES55.ArrowFunctionExpression && member.value?.type !== AST_NODE_TYPES55.FunctionExpression && member.typeAnnotation?.typeAnnotation.type !== AST_NODE_TYPES55.TSFunctionType && !(member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES55.TSTypeReference && member.typeAnnotation.typeAnnotation.typeName.type === AST_NODE_TYPES55.Identifier && functionAliases.has(member.typeAnnotation.typeAnnotation.typeName.name))) continue;
|
|
14302
|
+
names.push(member.key.type === AST_NODE_TYPES55.Identifier ? member.key.name : "\u2026");
|
|
14205
14303
|
continue;
|
|
14206
14304
|
}
|
|
14207
|
-
if (member.type !==
|
|
14305
|
+
if (member.type !== AST_NODE_TYPES55.MethodDefinition) continue;
|
|
14208
14306
|
if (member.kind !== "method" || member.static) continue;
|
|
14209
14307
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
14210
|
-
if (member.key.type ===
|
|
14211
|
-
if (member.key.type ===
|
|
14308
|
+
if (member.key.type === AST_NODE_TYPES55.PrivateIdentifier) continue;
|
|
14309
|
+
if (member.key.type === AST_NODE_TYPES55.Identifier) names.push(member.key.name);
|
|
14212
14310
|
else names.push("\u2026");
|
|
14213
14311
|
}
|
|
14214
14312
|
return names;
|
|
@@ -14216,13 +14314,13 @@ var publicMethodNames = (body2, functionAliases) => {
|
|
|
14216
14314
|
var isFluentConstructionObject = (node, getText) => {
|
|
14217
14315
|
if (node.id === null) return false;
|
|
14218
14316
|
const methods = node.body.body.filter(
|
|
14219
|
-
(member) => member.type ===
|
|
14317
|
+
(member) => member.type === AST_NODE_TYPES55.MethodDefinition && member.kind === "method" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.value.body !== null
|
|
14220
14318
|
);
|
|
14221
14319
|
if (methods.length === 0) return false;
|
|
14222
14320
|
return methods.every((member) => {
|
|
14223
14321
|
const result = member.value.returnType?.typeAnnotation;
|
|
14224
14322
|
if (result === void 0) return false;
|
|
14225
|
-
const returnsOwnType = result.type ===
|
|
14323
|
+
const returnsOwnType = result.type === AST_NODE_TYPES55.TSTypeReference && result.typeName.type === AST_NODE_TYPES55.Identifier && result.typeName.name === node.id?.name;
|
|
14226
14324
|
return returnsOwnType || FLUENT_BUILDER_NAME_RE.test(node.id?.name ?? "") && FLUENT_RESULT_TYPE_RE.test(getText(result));
|
|
14227
14325
|
});
|
|
14228
14326
|
};
|
|
@@ -14230,10 +14328,10 @@ function localClassAbstractness(program) {
|
|
|
14230
14328
|
const classes = /* @__PURE__ */ new Map();
|
|
14231
14329
|
const parents = /* @__PURE__ */ new Map();
|
|
14232
14330
|
for (const statement of program.body) {
|
|
14233
|
-
const declaration = statement.type ===
|
|
14234
|
-
if (declaration?.type ===
|
|
14331
|
+
const declaration = statement.type === AST_NODE_TYPES55.ExportNamedDeclaration || statement.type === AST_NODE_TYPES55.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
14332
|
+
if (declaration?.type === AST_NODE_TYPES55.ClassDeclaration && declaration.id !== null) {
|
|
14235
14333
|
classes.set(declaration.id.name, declaration.abstract === true);
|
|
14236
|
-
if (declaration.superClass?.type ===
|
|
14334
|
+
if (declaration.superClass?.type === AST_NODE_TYPES55.Identifier) {
|
|
14237
14335
|
parents.set(declaration.id.name, declaration.superClass.name);
|
|
14238
14336
|
}
|
|
14239
14337
|
}
|
|
@@ -14255,43 +14353,43 @@ function localInterfaceSurfaces(program) {
|
|
|
14255
14353
|
const parents = /* @__PURE__ */ new Map();
|
|
14256
14354
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
14257
14355
|
for (const statement of program.body) {
|
|
14258
|
-
const declaration = statement.type ===
|
|
14259
|
-
if (declaration?.type ===
|
|
14356
|
+
const declaration = statement.type === AST_NODE_TYPES55.ExportNamedDeclaration ? statement.declaration : statement;
|
|
14357
|
+
if (declaration?.type === AST_NODE_TYPES55.TSTypeAliasDeclaration && (declaration.typeAnnotation.type === AST_NODE_TYPES55.TSFunctionType || declaration.typeAnnotation.type === AST_NODE_TYPES55.TSConstructorType)) functionAliases.add(declaration.id.name);
|
|
14260
14358
|
}
|
|
14261
14359
|
for (const statement of program.body) {
|
|
14262
|
-
const declaration = statement.type ===
|
|
14263
|
-
if (declaration?.type ===
|
|
14360
|
+
const declaration = statement.type === AST_NODE_TYPES55.ExportNamedDeclaration ? statement.declaration : statement;
|
|
14361
|
+
if (declaration?.type === AST_NODE_TYPES55.TSTypeAliasDeclaration) {
|
|
14264
14362
|
const callables2 = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
14265
|
-
const parts = declaration.typeAnnotation.type ===
|
|
14363
|
+
const parts = declaration.typeAnnotation.type === AST_NODE_TYPES55.TSIntersectionType ? declaration.typeAnnotation.types : [declaration.typeAnnotation];
|
|
14266
14364
|
const inherited = parents.get(declaration.id.name) ?? [];
|
|
14267
14365
|
for (const part of parts) {
|
|
14268
|
-
if (part.type ===
|
|
14366
|
+
if (part.type === AST_NODE_TYPES55.TSTypeReference && part.typeName.type === AST_NODE_TYPES55.Identifier) {
|
|
14269
14367
|
inherited.push(part.typeName.name);
|
|
14270
14368
|
continue;
|
|
14271
14369
|
}
|
|
14272
|
-
if (part.type !==
|
|
14370
|
+
if (part.type !== AST_NODE_TYPES55.TSTypeLiteral) continue;
|
|
14273
14371
|
for (const member of part.members) {
|
|
14274
|
-
if (member.type !==
|
|
14275
|
-
if (member.computed || member.key.type !==
|
|
14276
|
-
if (member.type ===
|
|
14372
|
+
if (member.type !== AST_NODE_TYPES55.TSMethodSignature && member.type !== AST_NODE_TYPES55.TSPropertySignature) continue;
|
|
14373
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES55.Identifier) continue;
|
|
14374
|
+
if (member.type === AST_NODE_TYPES55.TSMethodSignature) {
|
|
14277
14375
|
callables2.add(member.key.name);
|
|
14278
14376
|
continue;
|
|
14279
14377
|
}
|
|
14280
|
-
if (member.type !==
|
|
14378
|
+
if (member.type !== AST_NODE_TYPES55.TSPropertySignature) continue;
|
|
14281
14379
|
const annotation = member.typeAnnotation?.typeAnnotation;
|
|
14282
|
-
if (annotation?.type ===
|
|
14380
|
+
if (annotation?.type === AST_NODE_TYPES55.TSFunctionType || annotation?.type === AST_NODE_TYPES55.TSTypeReference && annotation.typeName.type === AST_NODE_TYPES55.Identifier && functionAliases.has(annotation.typeName.name)) callables2.add(member.key.name);
|
|
14283
14381
|
}
|
|
14284
14382
|
}
|
|
14285
14383
|
interfaces.set(declaration.id.name, callables2);
|
|
14286
14384
|
parents.set(declaration.id.name, inherited);
|
|
14287
14385
|
continue;
|
|
14288
14386
|
}
|
|
14289
|
-
if (declaration?.type !==
|
|
14387
|
+
if (declaration?.type !== AST_NODE_TYPES55.TSInterfaceDeclaration) continue;
|
|
14290
14388
|
const callables = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
14291
14389
|
for (const member of declaration.body.body) {
|
|
14292
|
-
if (member.type !==
|
|
14293
|
-
if (member.computed || member.key.type !==
|
|
14294
|
-
if (member.type ===
|
|
14390
|
+
if (member.type !== AST_NODE_TYPES55.TSMethodSignature && member.type !== AST_NODE_TYPES55.TSPropertySignature) continue;
|
|
14391
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES55.Identifier) continue;
|
|
14392
|
+
if (member.type === AST_NODE_TYPES55.TSMethodSignature || member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES55.TSFunctionType || member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES55.TSTypeReference && member.typeAnnotation.typeAnnotation.typeName.type === AST_NODE_TYPES55.Identifier && functionAliases.has(member.typeAnnotation.typeAnnotation.typeName.name)) callables.add(member.key.name);
|
|
14295
14393
|
}
|
|
14296
14394
|
interfaces.set(declaration.id.name, callables);
|
|
14297
14395
|
parents.set(
|
|
@@ -14299,7 +14397,7 @@ function localInterfaceSurfaces(program) {
|
|
|
14299
14397
|
[
|
|
14300
14398
|
...parents.get(declaration.id.name) ?? [],
|
|
14301
14399
|
...declaration.extends.flatMap(
|
|
14302
|
-
(heritage) => heritage.expression.type ===
|
|
14400
|
+
(heritage) => heritage.expression.type === AST_NODE_TYPES55.Identifier ? [heritage.expression.name] : ["*"]
|
|
14303
14401
|
)
|
|
14304
14402
|
]
|
|
14305
14403
|
);
|
|
@@ -14326,7 +14424,7 @@ function localInterfaceSurfaces(program) {
|
|
|
14326
14424
|
}
|
|
14327
14425
|
function hasServicePort(node, methods, classes, interfaces) {
|
|
14328
14426
|
if (node.superClass !== null) {
|
|
14329
|
-
if (node.superClass.type !==
|
|
14427
|
+
if (node.superClass.type !== AST_NODE_TYPES55.Identifier) return true;
|
|
14330
14428
|
const localAbstract = classes.get(node.superClass.name);
|
|
14331
14429
|
if (localAbstract === void 0 || localAbstract) return true;
|
|
14332
14430
|
}
|
|
@@ -14338,7 +14436,7 @@ function hasServicePort(node, methods, classes, interfaces) {
|
|
|
14338
14436
|
if (node.implements.length === 0) return false;
|
|
14339
14437
|
const combined = /* @__PURE__ */ new Set();
|
|
14340
14438
|
for (const implementation of node.implements) {
|
|
14341
|
-
if (implementation.expression.type !==
|
|
14439
|
+
if (implementation.expression.type !== AST_NODE_TYPES55.Identifier) return true;
|
|
14342
14440
|
const name = implementation.expression.name;
|
|
14343
14441
|
const localAbstract = classes.get(name);
|
|
14344
14442
|
if (localAbstract === true) return true;
|
|
@@ -14381,7 +14479,7 @@ var require_port_for_service_default = createRule({
|
|
|
14381
14479
|
if (node.abstract === true) return;
|
|
14382
14480
|
if (node.decorators.length > 0) return;
|
|
14383
14481
|
const ctor = node.body.body.find(
|
|
14384
|
-
(member) => member.type ===
|
|
14482
|
+
(member) => member.type === AST_NODE_TYPES55.MethodDefinition && member.kind === "constructor" && member.value.body !== null && member.value.body !== void 0
|
|
14385
14483
|
);
|
|
14386
14484
|
if (ctor === void 0) return;
|
|
14387
14485
|
const constructorFacts = readConstructor(
|
|
@@ -14416,7 +14514,7 @@ var require_port_for_service_default = createRule({
|
|
|
14416
14514
|
});
|
|
14417
14515
|
|
|
14418
14516
|
// src/rules/require-static-next-matcher.ts
|
|
14419
|
-
import { AST_NODE_TYPES as
|
|
14517
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES56 } from "@typescript-eslint/utils";
|
|
14420
14518
|
var requireStaticNextMatcherDocumentation = {
|
|
14421
14519
|
summary: "Require Next.js middleware and proxy matcher configuration to contain only build-time literals.",
|
|
14422
14520
|
rationale: "Next.js must statically analyze matcher values at build time; computed values are ignored.",
|
|
@@ -14429,34 +14527,34 @@ var requireStaticNextMatcherDocumentation = {
|
|
|
14429
14527
|
};
|
|
14430
14528
|
var NEXT_ENTRY_FILE = /(?:^|[/\\])(?:middleware|proxy)\.[cm]?[jt]sx?$/u;
|
|
14431
14529
|
function unwrapExpression3(node) {
|
|
14432
|
-
if (node.type ===
|
|
14530
|
+
if (node.type === AST_NODE_TYPES56.TSAsExpression || node.type === AST_NODE_TYPES56.TSSatisfiesExpression || node.type === AST_NODE_TYPES56.TSNonNullExpression || node.type === AST_NODE_TYPES56.TSTypeAssertion) {
|
|
14433
14531
|
return unwrapExpression3(node.expression);
|
|
14434
14532
|
}
|
|
14435
14533
|
return node;
|
|
14436
14534
|
}
|
|
14437
14535
|
function isStaticValue(node) {
|
|
14438
14536
|
const value = unwrapExpression3(node);
|
|
14439
|
-
if (value.type ===
|
|
14537
|
+
if (value.type === AST_NODE_TYPES56.Literal) {
|
|
14440
14538
|
return true;
|
|
14441
14539
|
}
|
|
14442
|
-
if (value.type ===
|
|
14540
|
+
if (value.type === AST_NODE_TYPES56.TemplateLiteral) {
|
|
14443
14541
|
return value.expressions.length === 0;
|
|
14444
14542
|
}
|
|
14445
|
-
if (value.type ===
|
|
14543
|
+
if (value.type === AST_NODE_TYPES56.ArrayExpression) {
|
|
14446
14544
|
return value.elements.every(
|
|
14447
|
-
(element) => element !== null && element.type !==
|
|
14545
|
+
(element) => element !== null && element.type !== AST_NODE_TYPES56.SpreadElement && isStaticValue(element)
|
|
14448
14546
|
);
|
|
14449
14547
|
}
|
|
14450
|
-
if (value.type ===
|
|
14548
|
+
if (value.type === AST_NODE_TYPES56.ObjectExpression) {
|
|
14451
14549
|
return value.properties.every(
|
|
14452
|
-
(property) => property.type ===
|
|
14550
|
+
(property) => property.type === AST_NODE_TYPES56.Property && property.kind === "init" && !property.computed && property.value.type !== AST_NODE_TYPES56.AssignmentPattern && isStaticValue(property.value)
|
|
14453
14551
|
);
|
|
14454
14552
|
}
|
|
14455
14553
|
return false;
|
|
14456
14554
|
}
|
|
14457
14555
|
function propertyName2(property) {
|
|
14458
14556
|
if (property.computed) return null;
|
|
14459
|
-
if (property.key.type ===
|
|
14557
|
+
if (property.key.type === AST_NODE_TYPES56.Identifier) return property.key.name;
|
|
14460
14558
|
return typeof property.key.value === "string" ? property.key.value : null;
|
|
14461
14559
|
}
|
|
14462
14560
|
var require_static_next_matcher_default = createRule({
|
|
@@ -14479,19 +14577,19 @@ var require_static_next_matcher_default = createRule({
|
|
|
14479
14577
|
}
|
|
14480
14578
|
return {
|
|
14481
14579
|
ExportNamedDeclaration(node) {
|
|
14482
|
-
if (node.declaration?.type !==
|
|
14580
|
+
if (node.declaration?.type !== AST_NODE_TYPES56.VariableDeclaration) {
|
|
14483
14581
|
return;
|
|
14484
14582
|
}
|
|
14485
14583
|
for (const declaration of node.declaration.declarations) {
|
|
14486
|
-
if (declaration.id.type !==
|
|
14584
|
+
if (declaration.id.type !== AST_NODE_TYPES56.Identifier || declaration.id.name !== "config" || declaration.init === null) {
|
|
14487
14585
|
continue;
|
|
14488
14586
|
}
|
|
14489
14587
|
const config = unwrapExpression3(declaration.init);
|
|
14490
|
-
if (config.type !==
|
|
14588
|
+
if (config.type !== AST_NODE_TYPES56.ObjectExpression) {
|
|
14491
14589
|
continue;
|
|
14492
14590
|
}
|
|
14493
14591
|
for (const property of config.properties) {
|
|
14494
|
-
if (property.type !==
|
|
14592
|
+
if (property.type !== AST_NODE_TYPES56.Property || propertyName2(property) !== "matcher" || property.value.type === AST_NODE_TYPES56.AssignmentPattern) {
|
|
14495
14593
|
continue;
|
|
14496
14594
|
}
|
|
14497
14595
|
if (!isStaticValue(property.value)) {
|
|
@@ -14506,7 +14604,7 @@ var require_static_next_matcher_default = createRule({
|
|
|
14506
14604
|
|
|
14507
14605
|
// src/rules/require-zod-form-validation.ts
|
|
14508
14606
|
import {
|
|
14509
|
-
AST_NODE_TYPES as
|
|
14607
|
+
AST_NODE_TYPES as AST_NODE_TYPES57,
|
|
14510
14608
|
ASTUtils as ASTUtils17
|
|
14511
14609
|
} from "@typescript-eslint/utils";
|
|
14512
14610
|
var requireZodFormValidationDocumentation = {
|
|
@@ -14533,14 +14631,14 @@ var FORM_VALUE_METHODS = /* @__PURE__ */ new Set(["get", "getAll"]);
|
|
|
14533
14631
|
var zodReceiverRoot = (node) => {
|
|
14534
14632
|
let current = node;
|
|
14535
14633
|
while (true) {
|
|
14536
|
-
if (current.type ===
|
|
14634
|
+
if (current.type === AST_NODE_TYPES57.Identifier) {
|
|
14537
14635
|
return current;
|
|
14538
14636
|
}
|
|
14539
|
-
if (current.type ===
|
|
14637
|
+
if (current.type === AST_NODE_TYPES57.CallExpression) {
|
|
14540
14638
|
current = current.callee;
|
|
14541
14639
|
continue;
|
|
14542
14640
|
}
|
|
14543
|
-
if (current.type ===
|
|
14641
|
+
if (current.type === AST_NODE_TYPES57.MemberExpression) {
|
|
14544
14642
|
current = current.object;
|
|
14545
14643
|
continue;
|
|
14546
14644
|
}
|
|
@@ -14549,12 +14647,12 @@ var zodReceiverRoot = (node) => {
|
|
|
14549
14647
|
};
|
|
14550
14648
|
var isFormDataMethodCall = (node) => {
|
|
14551
14649
|
let current = node;
|
|
14552
|
-
if (current.type ===
|
|
14650
|
+
if (current.type === AST_NODE_TYPES57.AwaitExpression) {
|
|
14553
14651
|
current = current.argument;
|
|
14554
14652
|
}
|
|
14555
|
-
if (current.type !==
|
|
14653
|
+
if (current.type !== AST_NODE_TYPES57.CallExpression) return false;
|
|
14556
14654
|
const callee = current.callee;
|
|
14557
|
-
return callee.type ===
|
|
14655
|
+
return callee.type === AST_NODE_TYPES57.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES57.Identifier && callee.property.name === "formData";
|
|
14558
14656
|
};
|
|
14559
14657
|
var require_zod_form_validation_default = createRule({
|
|
14560
14658
|
name: "require-zod-form-validation",
|
|
@@ -14585,16 +14683,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
14585
14683
|
return false;
|
|
14586
14684
|
}
|
|
14587
14685
|
const definition = binding.defs[0];
|
|
14588
|
-
if (definition?.type !== "Variable" || definition.node.type !==
|
|
14686
|
+
if (definition?.type !== "Variable" || definition.node.type !== AST_NODE_TYPES57.VariableDeclarator) {
|
|
14589
14687
|
return false;
|
|
14590
14688
|
}
|
|
14591
14689
|
const init = definition.node.init;
|
|
14592
|
-
return init?.type ===
|
|
14690
|
+
return init?.type === AST_NODE_TYPES57.ObjectExpression || init?.type === AST_NODE_TYPES57.ArrayExpression || init?.type === AST_NODE_TYPES57.Literal || init?.type === AST_NODE_TYPES57.ArrowFunctionExpression || init?.type === AST_NODE_TYPES57.FunctionExpression;
|
|
14593
14691
|
};
|
|
14594
14692
|
const isZodParseCall = (node) => {
|
|
14595
|
-
if (node.type !==
|
|
14693
|
+
if (node.type !== AST_NODE_TYPES57.CallExpression) return false;
|
|
14596
14694
|
const callee = node.callee;
|
|
14597
|
-
if (callee.type !==
|
|
14695
|
+
if (callee.type !== AST_NODE_TYPES57.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES57.Identifier || !ZOD_PARSE_METHODS.has(callee.property.name)) {
|
|
14598
14696
|
return false;
|
|
14599
14697
|
}
|
|
14600
14698
|
const root = zodReceiverRoot(callee.object);
|
|
@@ -14603,14 +14701,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
14603
14701
|
return binding !== null && zodBindings.has(binding) || (root.name === "z" || ZOD_SCHEMA_NAME_RE.test(root.name)) && !isProvablyNonZodLocal(root);
|
|
14604
14702
|
};
|
|
14605
14703
|
const isFormSourceIdentifier = (node) => {
|
|
14606
|
-
if (node.type !==
|
|
14704
|
+
if (node.type !== AST_NODE_TYPES57.Identifier) return false;
|
|
14607
14705
|
const conventionalName = /formdata/i.test(node.name);
|
|
14608
14706
|
let scope = context.sourceCode.getScope(node);
|
|
14609
14707
|
while (scope !== null) {
|
|
14610
14708
|
const variable = scope.set.get(node.name);
|
|
14611
14709
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
14612
14710
|
const def = variable.defs[0];
|
|
14613
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
14711
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === AST_NODE_TYPES57.VariableDeclarator && def.node.init !== null) {
|
|
14614
14712
|
return isFormDataMethodCall(def.node.init);
|
|
14615
14713
|
}
|
|
14616
14714
|
return def?.type === "Parameter" && conventionalName;
|
|
@@ -14621,8 +14719,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
14621
14719
|
};
|
|
14622
14720
|
const isFormDataGetCall = (node) => {
|
|
14623
14721
|
const callee = node.callee;
|
|
14624
|
-
if (callee.type !==
|
|
14625
|
-
if (callee.property.type !==
|
|
14722
|
+
if (callee.type !== AST_NODE_TYPES57.MemberExpression) return false;
|
|
14723
|
+
if (callee.property.type !== AST_NODE_TYPES57.Identifier || !FORM_VALUE_METHODS.has(callee.property.name)) {
|
|
14626
14724
|
return false;
|
|
14627
14725
|
}
|
|
14628
14726
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -14638,16 +14736,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
14638
14736
|
const hasZodParseAncestor = (node) => zodParseAncestor(node) !== null;
|
|
14639
14737
|
const isInstanceofNarrowing = (node) => {
|
|
14640
14738
|
const parent = node.parent;
|
|
14641
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
14739
|
+
return parent !== null && parent !== void 0 && parent.type === AST_NODE_TYPES57.BinaryExpression && parent.operator === "instanceof" && parent.left === node && parent.right.type === AST_NODE_TYPES57.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
14642
14740
|
};
|
|
14643
14741
|
const boundDeclarator = (node) => {
|
|
14644
14742
|
let current = node;
|
|
14645
14743
|
let parent = current.parent;
|
|
14646
|
-
while ((parent.type ===
|
|
14744
|
+
while ((parent.type === AST_NODE_TYPES57.TSAsExpression || parent.type === AST_NODE_TYPES57.TSSatisfiesExpression || parent.type === AST_NODE_TYPES57.TSNonNullExpression || parent.type === AST_NODE_TYPES57.ChainExpression) && parent.expression === current) {
|
|
14647
14745
|
current = parent;
|
|
14648
14746
|
parent = current.parent;
|
|
14649
14747
|
}
|
|
14650
|
-
if (parent.type ===
|
|
14748
|
+
if (parent.type === AST_NODE_TYPES57.VariableDeclarator && parent.init === current && parent.id.type === AST_NODE_TYPES57.Identifier) {
|
|
14651
14749
|
return parent;
|
|
14652
14750
|
}
|
|
14653
14751
|
return null;
|
|
@@ -14656,7 +14754,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14656
14754
|
let current = node;
|
|
14657
14755
|
while (current.parent !== void 0) {
|
|
14658
14756
|
const parent = current.parent;
|
|
14659
|
-
if (parent.type ===
|
|
14757
|
+
if (parent.type === AST_NODE_TYPES57.BlockStatement || parent.type === AST_NODE_TYPES57.Program) {
|
|
14660
14758
|
return current;
|
|
14661
14759
|
}
|
|
14662
14760
|
current = parent;
|
|
@@ -14665,12 +14763,12 @@ var require_zod_form_validation_default = createRule({
|
|
|
14665
14763
|
};
|
|
14666
14764
|
const zodParseMethod = (call) => {
|
|
14667
14765
|
const callee = call.callee;
|
|
14668
|
-
return callee.type ===
|
|
14766
|
+
return callee.type === AST_NODE_TYPES57.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES57.Identifier ? callee.property.name : null;
|
|
14669
14767
|
};
|
|
14670
14768
|
const hasConditionalAncestorBeforeStatement = (node, statement) => {
|
|
14671
14769
|
let current = node.parent;
|
|
14672
14770
|
while (current !== void 0 && current !== statement) {
|
|
14673
|
-
if (current.type ===
|
|
14771
|
+
if (current.type === AST_NODE_TYPES57.LogicalExpression || current.type === AST_NODE_TYPES57.ConditionalExpression) {
|
|
14674
14772
|
return true;
|
|
14675
14773
|
}
|
|
14676
14774
|
current = current.parent;
|
|
@@ -14680,7 +14778,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14680
14778
|
const isAwaitedBeforeStatement = (node, statement) => {
|
|
14681
14779
|
let current = node.parent;
|
|
14682
14780
|
while (current !== void 0 && current !== statement) {
|
|
14683
|
-
if (current.type ===
|
|
14781
|
+
if (current.type === AST_NODE_TYPES57.AwaitExpression) return true;
|
|
14684
14782
|
current = current.parent;
|
|
14685
14783
|
}
|
|
14686
14784
|
return false;
|
|
@@ -14693,7 +14791,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14693
14791
|
if (declarationStatement === null || validationStatement === null || declarationStatement.parent !== validationStatement.parent || validationStatement.range[0] <= declarationStatement.range[1] || hasConditionalAncestorBeforeStatement(parse2, validationStatement)) {
|
|
14694
14792
|
return null;
|
|
14695
14793
|
}
|
|
14696
|
-
if (validationStatement.type !==
|
|
14794
|
+
if (validationStatement.type !== AST_NODE_TYPES57.VariableDeclaration && validationStatement.type !== AST_NODE_TYPES57.ExpressionStatement) {
|
|
14697
14795
|
return null;
|
|
14698
14796
|
}
|
|
14699
14797
|
const method = zodParseMethod(parse2);
|
|
@@ -14705,16 +14803,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
14705
14803
|
};
|
|
14706
14804
|
const isSafePrevalidationInspection = (identifier) => {
|
|
14707
14805
|
const parent = identifier.parent;
|
|
14708
|
-
if (parent.type ===
|
|
14806
|
+
if (parent.type === AST_NODE_TYPES57.UnaryExpression && parent.operator === "typeof") {
|
|
14709
14807
|
return true;
|
|
14710
14808
|
}
|
|
14711
|
-
if (parent.type !==
|
|
14809
|
+
if (parent.type !== AST_NODE_TYPES57.BinaryExpression || parent.left !== identifier) {
|
|
14712
14810
|
return false;
|
|
14713
14811
|
}
|
|
14714
14812
|
if (parent.operator === "instanceof") {
|
|
14715
|
-
return parent.right.type ===
|
|
14813
|
+
return parent.right.type === AST_NODE_TYPES57.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
14716
14814
|
}
|
|
14717
|
-
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type ===
|
|
14815
|
+
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type === AST_NODE_TYPES57.Literal && parent.right.value === null || parent.right.type === AST_NODE_TYPES57.Identifier && parent.right.name === "undefined");
|
|
14718
14816
|
};
|
|
14719
14817
|
const isDescendantOf = (node, ancestor) => {
|
|
14720
14818
|
let current = node;
|
|
@@ -14725,23 +14823,23 @@ var require_zod_form_validation_default = createRule({
|
|
|
14725
14823
|
return false;
|
|
14726
14824
|
};
|
|
14727
14825
|
const blockTerminates = (node) => {
|
|
14728
|
-
if (node.type ===
|
|
14826
|
+
if (node.type === AST_NODE_TYPES57.ReturnStatement || node.type === AST_NODE_TYPES57.ThrowStatement) {
|
|
14729
14827
|
return true;
|
|
14730
14828
|
}
|
|
14731
|
-
if (node.type !==
|
|
14829
|
+
if (node.type !== AST_NODE_TYPES57.BlockStatement || node.body.length === 0) return false;
|
|
14732
14830
|
const last = node.body.at(-1);
|
|
14733
14831
|
return last !== void 0 && blockTerminates(last);
|
|
14734
14832
|
};
|
|
14735
14833
|
const narrowingIf = (identifier) => {
|
|
14736
14834
|
const comparison = identifier.parent;
|
|
14737
|
-
if (comparison?.type !==
|
|
14835
|
+
if (comparison?.type !== AST_NODE_TYPES57.BinaryExpression || comparison.operator !== "instanceof" || comparison.left !== identifier || comparison.right.type !== AST_NODE_TYPES57.Identifier || comparison.right.name !== "File" && comparison.right.name !== "Blob") {
|
|
14738
14836
|
return null;
|
|
14739
14837
|
}
|
|
14740
14838
|
const maybeNegation = comparison.parent;
|
|
14741
|
-
const negated = maybeNegation?.type ===
|
|
14839
|
+
const negated = maybeNegation?.type === AST_NODE_TYPES57.UnaryExpression && maybeNegation.operator === "!";
|
|
14742
14840
|
const test = negated ? maybeNegation : comparison;
|
|
14743
14841
|
const branch = test.parent;
|
|
14744
|
-
return branch?.type ===
|
|
14842
|
+
return branch?.type === AST_NODE_TYPES57.IfStatement && branch.test === test ? { branch, positive: !negated } : null;
|
|
14745
14843
|
};
|
|
14746
14844
|
const useDominatedByNarrowing = (use, narrowings) => narrowings.some(({ branch, positive }) => {
|
|
14747
14845
|
if (positive) return isDescendantOf(use, branch.consequent);
|
|
@@ -14761,7 +14859,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14761
14859
|
const variable = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
14762
14860
|
if (variable === void 0) return false;
|
|
14763
14861
|
const references = variable.references.filter((reference) => !reference.isWriteOnly()).map((reference) => reference.identifier).filter(
|
|
14764
|
-
(identifier) => identifier.type ===
|
|
14862
|
+
(identifier) => identifier.type === AST_NODE_TYPES57.Identifier
|
|
14765
14863
|
);
|
|
14766
14864
|
if (references.length === 0) return false;
|
|
14767
14865
|
const narrowings = references.map(narrowingIf).filter(
|
|
@@ -14787,7 +14885,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14787
14885
|
ImportDeclaration(node) {
|
|
14788
14886
|
if (!isZodModule(node.source.value)) return;
|
|
14789
14887
|
for (const specifier of node.specifiers) {
|
|
14790
|
-
if (specifier.type ===
|
|
14888
|
+
if (specifier.type === AST_NODE_TYPES57.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES57.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES57.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES57.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
14791
14889
|
const binding = resolvedBinding(specifier.local);
|
|
14792
14890
|
if (binding !== null) zodBindings.add(binding);
|
|
14793
14891
|
}
|
|
@@ -14872,7 +14970,7 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
14872
14970
|
});
|
|
14873
14971
|
|
|
14874
14972
|
// src/rules/stepdown.ts
|
|
14875
|
-
import { AST_NODE_TYPES as
|
|
14973
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES58, ASTUtils as ASTUtils18 } from "@typescript-eslint/utils";
|
|
14876
14974
|
var stepdownDocumentation = {
|
|
14877
14975
|
summary: "Place a private helper below its sole direct same-scope caller.",
|
|
14878
14976
|
rationale: "Caller-first ordering lets a reader follow the main flow before descending into implementation details.",
|
|
@@ -14889,7 +14987,7 @@ var stepdownDocumentation = {
|
|
|
14889
14987
|
]
|
|
14890
14988
|
};
|
|
14891
14989
|
function isFunction(node) {
|
|
14892
|
-
return node.type ===
|
|
14990
|
+
return node.type === AST_NODE_TYPES58.ArrowFunctionExpression || node.type === AST_NODE_TYPES58.FunctionDeclaration || node.type === AST_NODE_TYPES58.FunctionExpression;
|
|
14893
14991
|
}
|
|
14894
14992
|
function reportMisordered(context, candidates, scopeDefinitions, calls, pinned, canMove = () => true) {
|
|
14895
14993
|
const byName = new Map(scopeDefinitions.map((definition) => [definition.name, definition]));
|
|
@@ -14984,8 +15082,8 @@ function moduleScope(context, program) {
|
|
|
14984
15082
|
for (const node of declarations) counts.set(node.name, (counts.get(node.name) ?? 0) + 1);
|
|
14985
15083
|
const overloadNames = new Set(
|
|
14986
15084
|
program.body.flatMap((statement) => {
|
|
14987
|
-
const node = statement.type ===
|
|
14988
|
-
return node?.type ===
|
|
15085
|
+
const node = statement.type === AST_NODE_TYPES58.ExportNamedDeclaration ? statement.declaration : statement;
|
|
15086
|
+
return node?.type === AST_NODE_TYPES58.TSDeclareFunction && node.id !== null ? [node.id.name] : [];
|
|
14989
15087
|
})
|
|
14990
15088
|
);
|
|
14991
15089
|
const exported = exportedNames(program);
|
|
@@ -15009,7 +15107,7 @@ function moduleScope(context, program) {
|
|
|
15009
15107
|
const nearestFunction2 = [...ancestors].reverse().find(isFunction);
|
|
15010
15108
|
const parent = identifier.parent;
|
|
15011
15109
|
const callerDefinition = nearestFunction2 === void 0 ? void 0 : byFunction.get(nearestFunction2);
|
|
15012
|
-
if (callerDefinition === void 0 || parent.type !==
|
|
15110
|
+
if (callerDefinition === void 0 || parent.type !== AST_NODE_TYPES58.CallExpression || parent.callee !== identifier) {
|
|
15013
15111
|
pinned.add(definition.name);
|
|
15014
15112
|
continue;
|
|
15015
15113
|
}
|
|
@@ -15024,38 +15122,38 @@ function moduleScope(context, program) {
|
|
|
15024
15122
|
function exportedNames(program) {
|
|
15025
15123
|
const names = /* @__PURE__ */ new Set();
|
|
15026
15124
|
for (const statement of program.body) {
|
|
15027
|
-
if (statement.type !==
|
|
15028
|
-
if (statement.declaration?.type ===
|
|
15125
|
+
if (statement.type !== AST_NODE_TYPES58.ExportNamedDeclaration || statement.exportKind === "type" || statement.source !== null) continue;
|
|
15126
|
+
if (statement.declaration?.type === AST_NODE_TYPES58.FunctionDeclaration && statement.declaration.id !== null) {
|
|
15029
15127
|
names.add(statement.declaration.id.name);
|
|
15030
15128
|
}
|
|
15031
|
-
if (statement.declaration?.type ===
|
|
15129
|
+
if (statement.declaration?.type === AST_NODE_TYPES58.VariableDeclaration) {
|
|
15032
15130
|
for (const declarator of statement.declaration.declarations) {
|
|
15033
|
-
if (declarator.id.type ===
|
|
15131
|
+
if (declarator.id.type === AST_NODE_TYPES58.Identifier) names.add(declarator.id.name);
|
|
15034
15132
|
}
|
|
15035
15133
|
}
|
|
15036
15134
|
for (const specifier of statement.specifiers) {
|
|
15037
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
15135
|
+
if (specifier.exportKind !== "type" && specifier.local.type === AST_NODE_TYPES58.Identifier) {
|
|
15038
15136
|
names.add(specifier.local.name);
|
|
15039
15137
|
}
|
|
15040
15138
|
}
|
|
15041
15139
|
}
|
|
15042
15140
|
for (const statement of program.body) {
|
|
15043
|
-
if (statement.type ===
|
|
15044
|
-
if (statement.type ===
|
|
15141
|
+
if (statement.type === AST_NODE_TYPES58.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES58.Identifier) names.add(statement.declaration.name);
|
|
15142
|
+
if (statement.type === AST_NODE_TYPES58.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES58.FunctionDeclaration && statement.declaration.id !== null) names.add(statement.declaration.id.name);
|
|
15045
15143
|
}
|
|
15046
15144
|
return names;
|
|
15047
15145
|
}
|
|
15048
15146
|
function moduleDefinitions(program) {
|
|
15049
15147
|
const definitions = [];
|
|
15050
15148
|
for (const statement of program.body) {
|
|
15051
|
-
const node = statement.type ===
|
|
15052
|
-
if (node?.type ===
|
|
15149
|
+
const node = statement.type === AST_NODE_TYPES58.ExportNamedDeclaration || statement.type === AST_NODE_TYPES58.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
15150
|
+
if (node?.type === AST_NODE_TYPES58.FunctionDeclaration && node.id !== null && node.body !== null) {
|
|
15053
15151
|
definitions.push({ name: node.id.name, node, functionNode: node, bindingNode: node });
|
|
15054
15152
|
continue;
|
|
15055
15153
|
}
|
|
15056
|
-
if (node?.type !==
|
|
15154
|
+
if (node?.type !== AST_NODE_TYPES58.VariableDeclaration || node.kind !== "const") continue;
|
|
15057
15155
|
for (const declarator of node.declarations) {
|
|
15058
|
-
if (declarator.id.type ===
|
|
15156
|
+
if (declarator.id.type === AST_NODE_TYPES58.Identifier && declarator.init !== null && isFunction(declarator.init)) {
|
|
15059
15157
|
definitions.push({
|
|
15060
15158
|
name: declarator.id.name,
|
|
15061
15159
|
node: declarator,
|
|
@@ -15068,21 +15166,21 @@ function moduleDefinitions(program) {
|
|
|
15068
15166
|
return definitions;
|
|
15069
15167
|
}
|
|
15070
15168
|
function methodName(node) {
|
|
15071
|
-
if (node.key.type ===
|
|
15072
|
-
return !node.computed && node.key.type ===
|
|
15169
|
+
if (node.key.type === AST_NODE_TYPES58.PrivateIdentifier) return `#${node.key.name}`;
|
|
15170
|
+
return !node.computed && node.key.type === AST_NODE_TYPES58.Identifier ? node.key.name : null;
|
|
15073
15171
|
}
|
|
15074
15172
|
function referencedMethod(context, node, classVariables) {
|
|
15075
|
-
const objectVariable = node.object.type ===
|
|
15173
|
+
const objectVariable = node.object.type === AST_NODE_TYPES58.Identifier ? ASTUtils18.findVariable(context.sourceCode.getScope(node.object), node.object.name) : null;
|
|
15076
15174
|
const isClassReference = objectVariable !== null && classVariables.has(objectVariable);
|
|
15077
|
-
if (node.object.type !==
|
|
15078
|
-
if (node.property.type ===
|
|
15079
|
-
if (!node.computed && node.property.type ===
|
|
15080
|
-
return node.computed && node.property.type ===
|
|
15175
|
+
if (node.object.type !== AST_NODE_TYPES58.ThisExpression && !isClassReference) return null;
|
|
15176
|
+
if (node.property.type === AST_NODE_TYPES58.PrivateIdentifier) return `#${node.property.name}`;
|
|
15177
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES58.Identifier) return node.property.name;
|
|
15178
|
+
return node.computed && node.property.type === AST_NODE_TYPES58.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
15081
15179
|
}
|
|
15082
15180
|
function referencedPropertyName(node) {
|
|
15083
|
-
if (node.property.type ===
|
|
15084
|
-
if (!node.computed && node.property.type ===
|
|
15085
|
-
return node.computed && node.property.type ===
|
|
15181
|
+
if (node.property.type === AST_NODE_TYPES58.PrivateIdentifier) return `#${node.property.name}`;
|
|
15182
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES58.Identifier) return node.property.name;
|
|
15183
|
+
return node.computed && node.property.type === AST_NODE_TYPES58.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
15086
15184
|
}
|
|
15087
15185
|
function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
15088
15186
|
visit(node, nestedFunction);
|
|
@@ -15098,7 +15196,7 @@ function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
|
15098
15196
|
}
|
|
15099
15197
|
function classScope(context, node, computedReferenceNames) {
|
|
15100
15198
|
const methods = node.body.body.filter(
|
|
15101
|
-
(member) => member.type ===
|
|
15199
|
+
(member) => member.type === AST_NODE_TYPES58.MethodDefinition
|
|
15102
15200
|
);
|
|
15103
15201
|
const counts = /* @__PURE__ */ new Map();
|
|
15104
15202
|
for (const method of methods) {
|
|
@@ -15106,8 +15204,8 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15106
15204
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
15107
15205
|
}
|
|
15108
15206
|
for (const member of node.body.body) {
|
|
15109
|
-
if (member.type !==
|
|
15110
|
-
const name = !member.computed && member.key.type ===
|
|
15207
|
+
if (member.type !== AST_NODE_TYPES58.TSAbstractMethodDefinition) continue;
|
|
15208
|
+
const name = !member.computed && member.key.type === AST_NODE_TYPES58.Identifier ? member.key.name : null;
|
|
15111
15209
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
15112
15210
|
}
|
|
15113
15211
|
const scopeDefinitions = methods.flatMap((method) => {
|
|
@@ -15116,7 +15214,7 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15116
15214
|
});
|
|
15117
15215
|
const definitions = methods.flatMap((method) => {
|
|
15118
15216
|
const name = methodName(method);
|
|
15119
|
-
const isPrivate = method.accessibility === "private" || method.key.type ===
|
|
15217
|
+
const isPrivate = method.accessibility === "private" || method.key.type === AST_NODE_TYPES58.PrivateIdentifier;
|
|
15120
15218
|
return name !== null && isPrivate && counts.get(name) === 1 && method.decorators.length === 0 ? [{ name, node: method }] : [];
|
|
15121
15219
|
});
|
|
15122
15220
|
if (definitions.length === 0) return;
|
|
@@ -15128,7 +15226,7 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15128
15226
|
const internal = ASTUtils18.findVariable(context.sourceCode.getScope(node), node.id.name);
|
|
15129
15227
|
if (internal !== null) classVariables.add(internal);
|
|
15130
15228
|
}
|
|
15131
|
-
if (node.type ===
|
|
15229
|
+
if (node.type === AST_NODE_TYPES58.ClassExpression && node.parent.type === AST_NODE_TYPES58.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES58.Identifier) {
|
|
15132
15230
|
const outer = ASTUtils18.findVariable(context.sourceCode.getScope(node.parent), node.parent.id.name);
|
|
15133
15231
|
if (outer !== null) classVariables.add(outer);
|
|
15134
15232
|
}
|
|
@@ -15145,26 +15243,26 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15145
15243
|
}
|
|
15146
15244
|
const thisValue = (value) => {
|
|
15147
15245
|
let current = value;
|
|
15148
|
-
while (current?.type ===
|
|
15149
|
-
return current?.type ===
|
|
15246
|
+
while (current?.type === AST_NODE_TYPES58.TSAsExpression || current?.type === AST_NODE_TYPES58.TSSatisfiesExpression || current?.type === AST_NODE_TYPES58.TSNonNullExpression) current = current.expression;
|
|
15247
|
+
return current?.type === AST_NODE_TYPES58.ThisExpression;
|
|
15150
15248
|
};
|
|
15151
15249
|
const collectAlias = (current, nestedFunction) => {
|
|
15152
|
-
if (nestedFunction || current.type !==
|
|
15153
|
-
if (current.type ===
|
|
15154
|
-
const binding = current.type ===
|
|
15155
|
-
const value = current.type ===
|
|
15250
|
+
if (nestedFunction || current.type !== AST_NODE_TYPES58.VariableDeclarator && current.type !== AST_NODE_TYPES58.AssignmentPattern) return;
|
|
15251
|
+
if (current.type === AST_NODE_TYPES58.VariableDeclarator && (current.parent.type !== AST_NODE_TYPES58.VariableDeclaration || current.parent.kind !== "const")) return;
|
|
15252
|
+
const binding = current.type === AST_NODE_TYPES58.VariableDeclarator ? current.id : current.left;
|
|
15253
|
+
const value = current.type === AST_NODE_TYPES58.VariableDeclarator ? current.init : current.right;
|
|
15156
15254
|
if (!thisValue(value)) return;
|
|
15157
|
-
if (binding.type ===
|
|
15255
|
+
if (binding.type === AST_NODE_TYPES58.ObjectPattern) {
|
|
15158
15256
|
for (const property of binding.properties) {
|
|
15159
|
-
if (property.type ===
|
|
15257
|
+
if (property.type === AST_NODE_TYPES58.RestElement) {
|
|
15160
15258
|
for (const name of privateNames) pinned.add(name);
|
|
15161
|
-
} else if (property.key.type ===
|
|
15259
|
+
} else if (property.key.type === AST_NODE_TYPES58.Identifier && privateNames.has(property.key.name)) {
|
|
15162
15260
|
pinned.add(property.key.name);
|
|
15163
15261
|
}
|
|
15164
15262
|
}
|
|
15165
15263
|
return;
|
|
15166
15264
|
}
|
|
15167
|
-
if (binding.type !==
|
|
15265
|
+
if (binding.type !== AST_NODE_TYPES58.Identifier) return;
|
|
15168
15266
|
const variable = ASTUtils18.findVariable(context.sourceCode.getScope(binding), binding.name);
|
|
15169
15267
|
if (variable !== null) {
|
|
15170
15268
|
methodClassVariables.add(variable);
|
|
@@ -15178,16 +15276,16 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15178
15276
|
walk(statement, context.sourceCode.visitorKeys, collectAlias);
|
|
15179
15277
|
}
|
|
15180
15278
|
const visitCall = (current, nestedFunction) => {
|
|
15181
|
-
if (current.type ===
|
|
15279
|
+
if (current.type === AST_NODE_TYPES58.VariableDeclarator && current.id.type === AST_NODE_TYPES58.ObjectPattern && thisValue(current.init)) {
|
|
15182
15280
|
for (const property of current.id.properties) {
|
|
15183
|
-
if (property.type ===
|
|
15281
|
+
if (property.type === AST_NODE_TYPES58.RestElement) {
|
|
15184
15282
|
for (const name of privateNames) pinned.add(name);
|
|
15185
15283
|
continue;
|
|
15186
15284
|
}
|
|
15187
|
-
if (property.type ===
|
|
15285
|
+
if (property.type === AST_NODE_TYPES58.Property && property.key.type === AST_NODE_TYPES58.Identifier && privateNames.has(property.key.name)) pinned.add(property.key.name);
|
|
15188
15286
|
}
|
|
15189
15287
|
}
|
|
15190
|
-
if (current.type !==
|
|
15288
|
+
if (current.type !== AST_NODE_TYPES58.MemberExpression) return;
|
|
15191
15289
|
const target = referencedMethod(context, current, methodClassVariables);
|
|
15192
15290
|
if (target === null) {
|
|
15193
15291
|
const possibleTarget = referencedPropertyName(current);
|
|
@@ -15195,12 +15293,12 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15195
15293
|
return;
|
|
15196
15294
|
}
|
|
15197
15295
|
if (!privateNames.has(target)) return;
|
|
15198
|
-
const objectVariable = current.object.type ===
|
|
15296
|
+
const objectVariable = current.object.type === AST_NODE_TYPES58.Identifier ? ASTUtils18.findVariable(context.sourceCode.getScope(current.object), current.object.name) : null;
|
|
15199
15297
|
if (objectVariable !== null && methodAliases.has(objectVariable)) {
|
|
15200
15298
|
pinned.add(target);
|
|
15201
15299
|
return;
|
|
15202
15300
|
}
|
|
15203
|
-
if (current.computed || nestedFunction || parameterDecoratorNodes.has(current) || current.parent.type !==
|
|
15301
|
+
if (current.computed || nestedFunction || parameterDecoratorNodes.has(current) || current.parent.type !== AST_NODE_TYPES58.CallExpression || current.parent.callee !== current) {
|
|
15204
15302
|
pinned.add(target);
|
|
15205
15303
|
return;
|
|
15206
15304
|
}
|
|
@@ -15220,9 +15318,9 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15220
15318
|
}
|
|
15221
15319
|
}
|
|
15222
15320
|
for (const member of node.body.body) {
|
|
15223
|
-
if (member.type ===
|
|
15321
|
+
if (member.type === AST_NODE_TYPES58.MethodDefinition || member.type === AST_NODE_TYPES58.TSAbstractMethodDefinition) continue;
|
|
15224
15322
|
walk(member, context.sourceCode.visitorKeys, (current) => {
|
|
15225
|
-
if (current.type !==
|
|
15323
|
+
if (current.type !== AST_NODE_TYPES58.MemberExpression) return;
|
|
15226
15324
|
const target = referencedMethod(context, current, classVariables);
|
|
15227
15325
|
const possibleTarget = target ?? referencedPropertyName(current);
|
|
15228
15326
|
if (possibleTarget !== null && privateNames.has(possibleTarget)) pinned.add(possibleTarget);
|
|
@@ -15232,14 +15330,14 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15232
15330
|
const accessibility = new Map(
|
|
15233
15331
|
scopeDefinitions.map((definition) => {
|
|
15234
15332
|
const method = definition.node;
|
|
15235
|
-
const accessibility2 = method.key.type ===
|
|
15333
|
+
const accessibility2 = method.key.type === AST_NODE_TYPES58.PrivateIdentifier ? "private" : method.accessibility ?? "public";
|
|
15236
15334
|
return [definition.name, accessibility2];
|
|
15237
15335
|
})
|
|
15238
15336
|
);
|
|
15239
15337
|
const methodByName = new Map(scopeDefinitions.map((definition) => [definition.name, definition.node]));
|
|
15240
15338
|
for (const [caller, callees] of calls) {
|
|
15241
15339
|
const callerMethod = methodByName.get(caller);
|
|
15242
|
-
if (accessibility.get(caller) === "private" && callerMethod?.type ===
|
|
15340
|
+
if (accessibility.get(caller) === "private" && callerMethod?.type === AST_NODE_TYPES58.MethodDefinition && callerMethod.decorators.length === 0) continue;
|
|
15243
15341
|
for (const callee of callees) pinned.add(callee);
|
|
15244
15342
|
}
|
|
15245
15343
|
const memberIndexes = new Map(node.body.body.map((member, index) => [member, index]));
|
|
@@ -15256,12 +15354,12 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15256
15354
|
}
|
|
15257
15355
|
function isClassRuntimeBarrier(member) {
|
|
15258
15356
|
switch (member.type) {
|
|
15259
|
-
case
|
|
15357
|
+
case AST_NODE_TYPES58.StaticBlock:
|
|
15260
15358
|
return true;
|
|
15261
|
-
case
|
|
15262
|
-
case
|
|
15359
|
+
case AST_NODE_TYPES58.PropertyDefinition:
|
|
15360
|
+
case AST_NODE_TYPES58.AccessorProperty:
|
|
15263
15361
|
return member.static || member.computed || member.decorators.length > 0 || member.value !== null;
|
|
15264
|
-
case
|
|
15362
|
+
case AST_NODE_TYPES58.MethodDefinition:
|
|
15265
15363
|
return member.computed || member.decorators.length > 0;
|
|
15266
15364
|
default:
|
|
15267
15365
|
return false;
|
|
@@ -15293,7 +15391,7 @@ var stepdown_default = createRule({
|
|
|
15293
15391
|
moduleScope(context, program);
|
|
15294
15392
|
const computedReferenceNames = /* @__PURE__ */ new Set();
|
|
15295
15393
|
walk(program, context.sourceCode.visitorKeys, (node) => {
|
|
15296
|
-
if (node.type ===
|
|
15394
|
+
if (node.type === AST_NODE_TYPES58.MemberExpression && node.computed && node.property.type === AST_NODE_TYPES58.Literal && typeof node.property.value === "string") computedReferenceNames.add(node.property.value);
|
|
15297
15395
|
});
|
|
15298
15396
|
for (const node of classes) classScope(context, node, computedReferenceNames);
|
|
15299
15397
|
}
|
|
@@ -15302,7 +15400,7 @@ var stepdown_default = createRule({
|
|
|
15302
15400
|
});
|
|
15303
15401
|
|
|
15304
15402
|
// src/rules/source-coupled-test.ts
|
|
15305
|
-
import { AST_NODE_TYPES as
|
|
15403
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES59 } from "@typescript-eslint/utils";
|
|
15306
15404
|
var GENERAL_SOURCE_SUFFIX_RE = /\.(?:bash|sh|ya?ml|jsonc|py|[cm]?[jt]s)$/iu;
|
|
15307
15405
|
var FS_MODULES = /* @__PURE__ */ new Set(["fs", "node:fs", "fs/promises", "node:fs/promises"]);
|
|
15308
15406
|
var FS_READERS = /* @__PURE__ */ new Set(["readFile", "readFileSync"]);
|
|
@@ -15371,20 +15469,20 @@ var sourceCoupledTestDocumentation = {
|
|
|
15371
15469
|
]
|
|
15372
15470
|
};
|
|
15373
15471
|
function staticMemberName7(node) {
|
|
15374
|
-
if (!node.computed && node.property.type ===
|
|
15375
|
-
if (node.computed && node.property.type ===
|
|
15472
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES59.Identifier) return node.property.name;
|
|
15473
|
+
if (node.computed && node.property.type === AST_NODE_TYPES59.Literal && typeof node.property.value === "string") return node.property.value;
|
|
15376
15474
|
return null;
|
|
15377
15475
|
}
|
|
15378
15476
|
function unwrap5(node) {
|
|
15379
|
-
if (node.type ===
|
|
15380
|
-
if (node.type ===
|
|
15381
|
-
if (node.type ===
|
|
15477
|
+
if (node.type === AST_NODE_TYPES59.AwaitExpression) return unwrap5(node.argument);
|
|
15478
|
+
if (node.type === AST_NODE_TYPES59.ChainExpression) return unwrap5(node.expression);
|
|
15479
|
+
if (node.type === AST_NODE_TYPES59.TSAsExpression || node.type === AST_NODE_TYPES59.TSNonNullExpression || node.type === AST_NODE_TYPES59.TSTypeAssertion) return unwrap5(node.expression);
|
|
15382
15480
|
return node;
|
|
15383
15481
|
}
|
|
15384
15482
|
function stringValue(node) {
|
|
15385
15483
|
const current = unwrap5(node);
|
|
15386
|
-
if (current.type ===
|
|
15387
|
-
if (current.type ===
|
|
15484
|
+
if (current.type === AST_NODE_TYPES59.Literal && typeof current.value === "string") return current.value;
|
|
15485
|
+
if (current.type === AST_NODE_TYPES59.TemplateLiteral && current.expressions.length === 0) return current.quasis[0]?.value.cooked ?? null;
|
|
15388
15486
|
return null;
|
|
15389
15487
|
}
|
|
15390
15488
|
function importSource(node) {
|
|
@@ -15392,7 +15490,7 @@ function importSource(node) {
|
|
|
15392
15490
|
}
|
|
15393
15491
|
function requireSource(node) {
|
|
15394
15492
|
const current = unwrap5(node);
|
|
15395
|
-
if (current.type !==
|
|
15493
|
+
if (current.type !== AST_NODE_TYPES59.CallExpression || current.callee.type !== AST_NODE_TYPES59.Identifier || current.callee.name !== "require" || current.arguments.length !== 1 || current.arguments[0]?.type === AST_NODE_TYPES59.SpreadElement) return null;
|
|
15396
15494
|
return stringValue(current.arguments[0]);
|
|
15397
15495
|
}
|
|
15398
15496
|
function newScope() {
|
|
@@ -15432,38 +15530,38 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
15432
15530
|
const current = unwrap5(node);
|
|
15433
15531
|
const value = stringValue(current);
|
|
15434
15532
|
if (value !== null) return sourceSuffixRe.test(value);
|
|
15435
|
-
if (current.type ===
|
|
15436
|
-
if (current.type ===
|
|
15533
|
+
if (current.type === AST_NODE_TYPES59.Identifier) return visible("paths", current.name);
|
|
15534
|
+
if (current.type === AST_NODE_TYPES59.BinaryExpression && current.operator === "+") {
|
|
15437
15535
|
return sourcePath(current.left) || sourcePath(current.right);
|
|
15438
15536
|
}
|
|
15439
|
-
if (current.type ===
|
|
15440
|
-
if (current.type ===
|
|
15441
|
-
return current.arguments.some((argument) => argument.type !==
|
|
15537
|
+
if (current.type === AST_NODE_TYPES59.TemplateLiteral) return current.expressions.some(sourcePath);
|
|
15538
|
+
if (current.type === AST_NODE_TYPES59.CallExpression || current.type === AST_NODE_TYPES59.NewExpression) {
|
|
15539
|
+
return current.arguments.some((argument) => argument.type !== AST_NODE_TYPES59.SpreadElement && sourcePath(argument));
|
|
15442
15540
|
}
|
|
15443
|
-
if (current.type ===
|
|
15541
|
+
if (current.type === AST_NODE_TYPES59.MemberExpression) return sourcePath(current.object);
|
|
15444
15542
|
return false;
|
|
15445
15543
|
};
|
|
15446
15544
|
const rawRead = (node) => {
|
|
15447
15545
|
const current = unwrap5(node);
|
|
15448
|
-
if (current.type !==
|
|
15546
|
+
if (current.type !== AST_NODE_TYPES59.CallExpression || current.arguments.length === 0) return false;
|
|
15449
15547
|
const callee = unwrap5(current.callee);
|
|
15450
|
-
if (callee.type ===
|
|
15548
|
+
if (callee.type === AST_NODE_TYPES59.Identifier) {
|
|
15451
15549
|
return visible("fsReaders", callee.name) && sourcePath(current.arguments[0]);
|
|
15452
15550
|
}
|
|
15453
|
-
if (callee.type !==
|
|
15551
|
+
if (callee.type !== AST_NODE_TYPES59.MemberExpression) return false;
|
|
15454
15552
|
const name2 = staticMemberName7(callee);
|
|
15455
15553
|
const object = unwrap5(callee.object);
|
|
15456
|
-
return name2 !== null && FS_READERS.has(name2) && object.type ===
|
|
15554
|
+
return name2 !== null && FS_READERS.has(name2) && object.type === AST_NODE_TYPES59.Identifier && visible("fsObjects", object.name) && sourcePath(current.arguments[0]);
|
|
15457
15555
|
};
|
|
15458
15556
|
const rawOrigins = (node) => {
|
|
15459
15557
|
const current = unwrap5(node);
|
|
15460
|
-
if (current.type ===
|
|
15558
|
+
if (current.type === AST_NODE_TYPES59.Identifier) return visibleRawOrigins(current.name);
|
|
15461
15559
|
if (rawRead(current)) return /* @__PURE__ */ new Set([`${current.range[0]}:${current.range[1]}`]);
|
|
15462
|
-
if (current.type ===
|
|
15463
|
-
if (current.type ===
|
|
15464
|
-
if (current.type !==
|
|
15560
|
+
if (current.type === AST_NODE_TYPES59.BinaryExpression && current.operator === "+") return /* @__PURE__ */ new Set([...rawOrigins(current.left), ...rawOrigins(current.right)]);
|
|
15561
|
+
if (current.type === AST_NODE_TYPES59.MemberExpression && staticMemberName7(current) === "length") return rawOrigins(current.object);
|
|
15562
|
+
if (current.type !== AST_NODE_TYPES59.CallExpression) return /* @__PURE__ */ new Set();
|
|
15465
15563
|
const callee = unwrap5(current.callee);
|
|
15466
|
-
if (callee.type !==
|
|
15564
|
+
if (callee.type !== AST_NODE_TYPES59.MemberExpression) return /* @__PURE__ */ new Set();
|
|
15467
15565
|
const name2 = staticMemberName7(callee);
|
|
15468
15566
|
return name2 !== null && TEXT_TRANSFORMS.has(name2) ? rawOrigins(callee.object) : /* @__PURE__ */ new Set();
|
|
15469
15567
|
};
|
|
@@ -15471,38 +15569,38 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
15471
15569
|
const current = unwrap5(node);
|
|
15472
15570
|
const direct = rawOrigins(current);
|
|
15473
15571
|
if (direct.size > 0) return direct;
|
|
15474
|
-
if (current.type ===
|
|
15475
|
-
if (current.type ===
|
|
15476
|
-
if (current.type !==
|
|
15572
|
+
if (current.type === AST_NODE_TYPES59.BinaryExpression || current.type === AST_NODE_TYPES59.LogicalExpression) return /* @__PURE__ */ new Set([...evidenceOrigins(current.left), ...evidenceOrigins(current.right)]);
|
|
15573
|
+
if (current.type === AST_NODE_TYPES59.UnaryExpression) return evidenceOrigins(current.argument);
|
|
15574
|
+
if (current.type !== AST_NODE_TYPES59.CallExpression) return /* @__PURE__ */ new Set();
|
|
15477
15575
|
const callee = unwrap5(current.callee);
|
|
15478
|
-
if (callee.type !==
|
|
15576
|
+
if (callee.type !== AST_NODE_TYPES59.MemberExpression) return /* @__PURE__ */ new Set();
|
|
15479
15577
|
const name2 = staticMemberName7(callee);
|
|
15480
15578
|
if (name2 !== null && TEXT_PREDICATES.has(name2)) return rawOrigins(callee.object);
|
|
15481
|
-
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type ===
|
|
15579
|
+
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES59.SpreadElement ? [] : [...rawOrigins(argument)]));
|
|
15482
15580
|
return /* @__PURE__ */ new Set();
|
|
15483
15581
|
};
|
|
15484
15582
|
const rawAssertionOrigins = (node) => {
|
|
15485
15583
|
const callee = unwrap5(node.callee);
|
|
15486
|
-
if (callee.type ===
|
|
15487
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
15584
|
+
if (callee.type === AST_NODE_TYPES59.Identifier && callee.name === "assert") {
|
|
15585
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES59.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
15488
15586
|
}
|
|
15489
|
-
if (callee.type !==
|
|
15587
|
+
if (callee.type !== AST_NODE_TYPES59.MemberExpression) return /* @__PURE__ */ new Set();
|
|
15490
15588
|
const matcher = staticMemberName7(callee);
|
|
15491
15589
|
if (matcher === null) return /* @__PURE__ */ new Set();
|
|
15492
15590
|
let receiver = unwrap5(callee.object);
|
|
15493
|
-
while (receiver.type ===
|
|
15494
|
-
if (receiver.type ===
|
|
15591
|
+
while (receiver.type === AST_NODE_TYPES59.MemberExpression && EXPECT_MODIFIERS2.has(staticMemberName7(receiver) ?? "")) receiver = unwrap5(receiver.object);
|
|
15592
|
+
if (receiver.type === AST_NODE_TYPES59.CallExpression && receiver.callee.type === AST_NODE_TYPES59.Identifier && receiver.callee.name === "expect") {
|
|
15495
15593
|
if (!EXPECT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
15496
|
-
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type ===
|
|
15594
|
+
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type === AST_NODE_TYPES59.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
15497
15595
|
}
|
|
15498
|
-
if (receiver.type !==
|
|
15499
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
15596
|
+
if (receiver.type !== AST_NODE_TYPES59.Identifier || receiver.name !== "assert" || !ASSERT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
15597
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES59.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
15500
15598
|
};
|
|
15501
15599
|
const rawRegexExtractionOrigins = (node) => {
|
|
15502
15600
|
const callee = unwrap5(node.callee);
|
|
15503
|
-
if (callee.type !==
|
|
15601
|
+
if (callee.type !== AST_NODE_TYPES59.MemberExpression || staticMemberName7(callee) !== "matchAll" || node.arguments.length !== 1) return /* @__PURE__ */ new Set();
|
|
15504
15602
|
const argument = node.arguments[0];
|
|
15505
|
-
if (argument?.type !==
|
|
15603
|
+
if (argument?.type !== AST_NODE_TYPES59.Literal || !(argument.value instanceof RegExp)) return /* @__PURE__ */ new Set();
|
|
15506
15604
|
return rawOrigins(callee.object);
|
|
15507
15605
|
};
|
|
15508
15606
|
const declare = (name2, state) => {
|
|
@@ -15523,15 +15621,15 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
15523
15621
|
};
|
|
15524
15622
|
const sourceCollection = (node) => {
|
|
15525
15623
|
const current = unwrap5(node);
|
|
15526
|
-
return current.type ===
|
|
15624
|
+
return current.type === AST_NODE_TYPES59.ArrayExpression && current.elements.length > 0 && current.elements.every((element) => element !== null && element.type !== AST_NODE_TYPES59.SpreadElement && sourcePath(element));
|
|
15527
15625
|
};
|
|
15528
15626
|
const declaredNames2 = (node) => {
|
|
15529
15627
|
const current = unwrap5(node);
|
|
15530
|
-
if (current.type ===
|
|
15531
|
-
if (current.type ===
|
|
15532
|
-
if (current.type ===
|
|
15533
|
-
if (current.type ===
|
|
15534
|
-
if (current.type ===
|
|
15628
|
+
if (current.type === AST_NODE_TYPES59.Identifier) return [current.name];
|
|
15629
|
+
if (current.type === AST_NODE_TYPES59.AssignmentPattern) return declaredNames2(current.left);
|
|
15630
|
+
if (current.type === AST_NODE_TYPES59.RestElement) return declaredNames2(current.argument);
|
|
15631
|
+
if (current.type === AST_NODE_TYPES59.ArrayPattern) return current.elements.flatMap((element) => element === null ? [] : declaredNames2(element));
|
|
15632
|
+
if (current.type === AST_NODE_TYPES59.ObjectPattern) return current.properties.flatMap((property) => property.type === AST_NODE_TYPES59.RestElement ? declaredNames2(property.argument) : declaredNames2(property.value));
|
|
15535
15633
|
return [];
|
|
15536
15634
|
};
|
|
15537
15635
|
const enterFunction = (node) => {
|
|
@@ -15546,8 +15644,8 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
15546
15644
|
const source = importSource(node);
|
|
15547
15645
|
if (source === null || !FS_MODULES.has(source)) return;
|
|
15548
15646
|
for (const specifier of node.specifiers) {
|
|
15549
|
-
if (specifier.type ===
|
|
15550
|
-
const imported = specifier.imported.type ===
|
|
15647
|
+
if (specifier.type === AST_NODE_TYPES59.ImportSpecifier) {
|
|
15648
|
+
const imported = specifier.imported.type === AST_NODE_TYPES59.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
15551
15649
|
if (FS_READERS.has(imported)) declare(specifier.local.name, { fsReader: true });
|
|
15552
15650
|
} else {
|
|
15553
15651
|
declare(specifier.local.name, { fsObject: true });
|
|
@@ -15559,29 +15657,29 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
15559
15657
|
VariableDeclarator(node) {
|
|
15560
15658
|
if (node.init === null) return;
|
|
15561
15659
|
const required = requireSource(node.init);
|
|
15562
|
-
if (required !== null && FS_MODULES.has(required) && node.id.type ===
|
|
15660
|
+
if (required !== null && FS_MODULES.has(required) && node.id.type === AST_NODE_TYPES59.Identifier) {
|
|
15563
15661
|
declare(node.id.name, { fsObject: true });
|
|
15564
15662
|
return;
|
|
15565
15663
|
}
|
|
15566
|
-
if (node.id.type ===
|
|
15664
|
+
if (node.id.type === AST_NODE_TYPES59.ObjectPattern && required !== null && FS_MODULES.has(required)) {
|
|
15567
15665
|
for (const property of node.id.properties) {
|
|
15568
|
-
if (property.type !==
|
|
15569
|
-
const key = property.key.type ===
|
|
15666
|
+
if (property.type !== AST_NODE_TYPES59.Property || property.value.type !== AST_NODE_TYPES59.Identifier) continue;
|
|
15667
|
+
const key = property.key.type === AST_NODE_TYPES59.Identifier ? property.key.name : property.key.type === AST_NODE_TYPES59.Literal ? String(property.key.value) : "";
|
|
15570
15668
|
if (FS_READERS.has(key)) declare(property.value.name, { fsReader: true });
|
|
15571
15669
|
}
|
|
15572
15670
|
return;
|
|
15573
15671
|
}
|
|
15574
|
-
if (node.id.type !==
|
|
15672
|
+
if (node.id.type !== AST_NODE_TYPES59.Identifier) return;
|
|
15575
15673
|
declare(node.id.name, { collection: sourceCollection(node.init), path: sourcePath(node.init), rawOrigins: rawOrigins(node.init) });
|
|
15576
15674
|
},
|
|
15577
15675
|
AssignmentExpression(node) {
|
|
15578
|
-
if (node.left.type ===
|
|
15676
|
+
if (node.left.type === AST_NODE_TYPES59.Identifier) declare(node.left.name, { path: sourcePath(node.right), rawOrigins: rawOrigins(node.right) });
|
|
15579
15677
|
},
|
|
15580
15678
|
ForOfStatement(node) {
|
|
15581
15679
|
const right = unwrap5(node.right);
|
|
15582
|
-
const collection = right.type ===
|
|
15583
|
-
const left = node.left.type ===
|
|
15584
|
-
if (collection && left?.type ===
|
|
15680
|
+
const collection = right.type === AST_NODE_TYPES59.Identifier && visible("collections", right.name);
|
|
15681
|
+
const left = node.left.type === AST_NODE_TYPES59.VariableDeclaration ? node.left.declarations[0]?.id : node.left;
|
|
15682
|
+
if (collection && left?.type === AST_NODE_TYPES59.Identifier) declare(left.name, { path: true });
|
|
15585
15683
|
},
|
|
15586
15684
|
CallExpression(node) {
|
|
15587
15685
|
const origins = /* @__PURE__ */ new Set([
|
|
@@ -15642,7 +15740,7 @@ var iac_source_coupled_test_default = createSourceCoupledRule(
|
|
|
15642
15740
|
|
|
15643
15741
|
// src/rules/zod-naming-convention.ts
|
|
15644
15742
|
import {
|
|
15645
|
-
AST_NODE_TYPES as
|
|
15743
|
+
AST_NODE_TYPES as AST_NODE_TYPES60,
|
|
15646
15744
|
ASTUtils as ASTUtils19
|
|
15647
15745
|
} from "@typescript-eslint/utils";
|
|
15648
15746
|
var zodNamingConventionDocumentation = {
|
|
@@ -15685,18 +15783,18 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
15685
15783
|
"prettifyError",
|
|
15686
15784
|
"treeifyError"
|
|
15687
15785
|
]);
|
|
15688
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
15786
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === AST_NODE_TYPES60.Identifier ? callee.property.name : null;
|
|
15689
15787
|
var calleeChainRoot = (node) => {
|
|
15690
15788
|
let current = node;
|
|
15691
15789
|
for (; ; ) {
|
|
15692
|
-
if (current.type ===
|
|
15790
|
+
if (current.type === AST_NODE_TYPES60.Identifier) {
|
|
15693
15791
|
return current;
|
|
15694
15792
|
}
|
|
15695
|
-
if (current.type ===
|
|
15793
|
+
if (current.type === AST_NODE_TYPES60.MemberExpression) {
|
|
15696
15794
|
current = current.object;
|
|
15697
15795
|
continue;
|
|
15698
15796
|
}
|
|
15699
|
-
if (current.type ===
|
|
15797
|
+
if (current.type === AST_NODE_TYPES60.CallExpression) {
|
|
15700
15798
|
current = current.callee;
|
|
15701
15799
|
continue;
|
|
15702
15800
|
}
|
|
@@ -15758,7 +15856,7 @@ var zod_naming_convention_default = createRule({
|
|
|
15758
15856
|
ImportDeclaration(node) {
|
|
15759
15857
|
if (!isZodModule(node.source.value)) return;
|
|
15760
15858
|
for (const specifier of node.specifiers) {
|
|
15761
|
-
if (specifier.type ===
|
|
15859
|
+
if (specifier.type === AST_NODE_TYPES60.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES60.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES60.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES60.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
15762
15860
|
recordZodBinding(specifier.local);
|
|
15763
15861
|
}
|
|
15764
15862
|
}
|
|
@@ -15766,13 +15864,13 @@ var zod_naming_convention_default = createRule({
|
|
|
15766
15864
|
VariableDeclarator(node) {
|
|
15767
15865
|
const init = node.init;
|
|
15768
15866
|
if (init === null || init === void 0) return;
|
|
15769
|
-
if (init.type !==
|
|
15867
|
+
if (init.type !== AST_NODE_TYPES60.CallExpression) return;
|
|
15770
15868
|
const callee = init.callee;
|
|
15771
|
-
if (callee.type !==
|
|
15869
|
+
if (callee.type !== AST_NODE_TYPES60.MemberExpression) return;
|
|
15772
15870
|
if (!isZodChain(callee)) return;
|
|
15773
15871
|
const terminal = terminalMethodName(callee);
|
|
15774
15872
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
15775
|
-
if (node.id.type !==
|
|
15873
|
+
if (node.id.type !== AST_NODE_TYPES60.Identifier) return;
|
|
15776
15874
|
if (test.test(node.id.name)) return;
|
|
15777
15875
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
15778
15876
|
context.report({
|
|
@@ -15910,6 +16008,7 @@ var rules = {
|
|
|
15910
16008
|
"no-unsafe-mock-casting": no_unsafe_mock_casting_default,
|
|
15911
16009
|
"no-zod-native-enum": no_zod_native_enum_default,
|
|
15912
16010
|
"test-loops-over-literal-cases": test_loops_over_literal_cases_default,
|
|
16011
|
+
"test-phase-label-comment": test_phase_label_comment_default,
|
|
15913
16012
|
"prefer-constant-time-secret-compare": prefer_constant_time_secret_compare_default,
|
|
15914
16013
|
"prefer-discriminated-union": prefer_discriminated_union_default,
|
|
15915
16014
|
"prefer-input-group-search": prefer_input_group_search_default,
|
|
@@ -15938,7 +16037,7 @@ var rules = {
|
|
|
15938
16037
|
};
|
|
15939
16038
|
var meta = {
|
|
15940
16039
|
name: "@sarj/eslint-plugin",
|
|
15941
|
-
version: "15.
|
|
16040
|
+
version: "15.10.1"
|
|
15942
16041
|
};
|
|
15943
16042
|
var applicationOnlyRules = [
|
|
15944
16043
|
"no-restricted-library-load",
|
|
@@ -15949,7 +16048,8 @@ var advisoryRules = [
|
|
|
15949
16048
|
"no-bare-return-from-test-catch",
|
|
15950
16049
|
"iac-source-coupled-test",
|
|
15951
16050
|
"repeated-static-call-cases",
|
|
15952
|
-
"source-coupled-test"
|
|
16051
|
+
"source-coupled-test",
|
|
16052
|
+
"test-phase-label-comment"
|
|
15953
16053
|
];
|
|
15954
16054
|
var recommendedRules = {
|
|
15955
16055
|
"@sarj/iac-source-coupled-test": "warn",
|
|
@@ -16013,6 +16113,7 @@ var recommendedRules = {
|
|
|
16013
16113
|
"@sarj/store-insert-requires-on-conflict": "error",
|
|
16014
16114
|
"@sarj/stepdown": "error",
|
|
16015
16115
|
"@sarj/source-coupled-test": "warn",
|
|
16116
|
+
"@sarj/test-phase-label-comment": "warn",
|
|
16016
16117
|
"@sarj/zod-naming-convention": "error"
|
|
16017
16118
|
};
|
|
16018
16119
|
var strictRules = {
|
|
@@ -16081,6 +16182,7 @@ var strictRules = {
|
|
|
16081
16182
|
"@sarj/store-insert-requires-on-conflict": "error",
|
|
16082
16183
|
"@sarj/stepdown": "error",
|
|
16083
16184
|
"@sarj/source-coupled-test": "warn",
|
|
16185
|
+
"@sarj/test-phase-label-comment": "warn",
|
|
16084
16186
|
"@sarj/zod-naming-convention": "error"
|
|
16085
16187
|
};
|
|
16086
16188
|
var plugin = {
|