@sarj/eslint-plugin 9.2.0 → 9.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/index.cjs +588 -358
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +583 -353
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -493,7 +493,72 @@ function restatesStatementHead(body, statement) {
|
|
|
493
493
|
// src/rules/no-comment-cruft.ts
|
|
494
494
|
var LEADING_PREAMBLE_MIN = 4;
|
|
495
495
|
var STEP_NARRATION_RE = /^(?:first(?:ly)?|second(?:ly)?|third(?:ly)?|then|next|after(?:wards| that)?|finally|lastly|now)\s*[,:]\s*\S/i;
|
|
496
|
-
var META_COMMENTARY_RE = /\b(?:
|
|
496
|
+
var META_COMMENTARY_RE = /\b(?:keeping (?:it|this) simple|could be (?:refactored|improved|cleaned up|simplified)|refactor(?:ed|ing)? (?:later|this)|not sure (?:if|whether|why|how)|quick[- ](?:and[- ]dirty|fix)|(?:a |bit of a )?hacky|is a hack|temporary (?:solution|workaround|fix|hack)|revisit (?:this|later|below)|clean (?:this|it) up|not ideal|placeholder for now)\b/i;
|
|
497
|
+
var FOR_NOW_RE = /\bfor now\b/i;
|
|
498
|
+
var DEFERRAL_STOPWORDS = /* @__PURE__ */ new Set([
|
|
499
|
+
"a",
|
|
500
|
+
"an",
|
|
501
|
+
"and",
|
|
502
|
+
"are",
|
|
503
|
+
"as",
|
|
504
|
+
"at",
|
|
505
|
+
"be",
|
|
506
|
+
"but",
|
|
507
|
+
"by",
|
|
508
|
+
"can",
|
|
509
|
+
"could",
|
|
510
|
+
"do",
|
|
511
|
+
"does",
|
|
512
|
+
"for",
|
|
513
|
+
"from",
|
|
514
|
+
"had",
|
|
515
|
+
"has",
|
|
516
|
+
"have",
|
|
517
|
+
"here",
|
|
518
|
+
"i",
|
|
519
|
+
"in",
|
|
520
|
+
"is",
|
|
521
|
+
"it",
|
|
522
|
+
"its",
|
|
523
|
+
"just",
|
|
524
|
+
"may",
|
|
525
|
+
"might",
|
|
526
|
+
"no",
|
|
527
|
+
"not",
|
|
528
|
+
"now",
|
|
529
|
+
"of",
|
|
530
|
+
"on",
|
|
531
|
+
"only",
|
|
532
|
+
"our",
|
|
533
|
+
"shall",
|
|
534
|
+
"should",
|
|
535
|
+
"so",
|
|
536
|
+
"still",
|
|
537
|
+
"that",
|
|
538
|
+
"the",
|
|
539
|
+
"then",
|
|
540
|
+
"there",
|
|
541
|
+
"this",
|
|
542
|
+
"to",
|
|
543
|
+
"us",
|
|
544
|
+
"was",
|
|
545
|
+
"we",
|
|
546
|
+
"were",
|
|
547
|
+
"will",
|
|
548
|
+
"with",
|
|
549
|
+
"would",
|
|
550
|
+
"you",
|
|
551
|
+
"your"
|
|
552
|
+
]);
|
|
553
|
+
var DEFERRAL_MAX_CONTENT_WORDS = 2;
|
|
554
|
+
function isBareDeferral(text) {
|
|
555
|
+
if (!FOR_NOW_RE.test(text)) return false;
|
|
556
|
+
const rest = text.replace(FOR_NOW_RE, " ");
|
|
557
|
+
const content = (rest.match(/[A-Za-z][\w']*/g) ?? []).filter(
|
|
558
|
+
(word) => !DEFERRAL_STOPWORDS.has(word.toLowerCase())
|
|
559
|
+
);
|
|
560
|
+
return content.length <= DEFERRAL_MAX_CONTENT_WORDS;
|
|
561
|
+
}
|
|
497
562
|
var DIRECTIVE_RE = /^(eslint\b|eslint-|sarj-noqa\b|@ts-|prettier-ignore|prettier\b|biome-|c8\b|v8\b|istanbul\b|@type\b|@vite|webpack|<reference|<amd|global\b|noinspection|hack\b|xxx\b)/i;
|
|
498
563
|
var LICENSE_RE = /copyright|licen[cs]ed?|spdx|permission is hereby granted|all rights reserved/i;
|
|
499
564
|
var ENUMERATED_ITEM_RE = /^(?:\d+[.):]|[-*•])\s+\S/;
|
|
@@ -558,6 +623,7 @@ function isSectionLabel(text) {
|
|
|
558
623
|
const match = SECTION_LABEL_RE.exec(text);
|
|
559
624
|
return match !== null && SECTION_LABEL_WORDS.has((match[1] ?? "").toLowerCase());
|
|
560
625
|
}
|
|
626
|
+
var SHOUTED_LABEL_RE = /^[A-Z]{2,}(?:[ -][A-Z]{2,}){1,3}$/;
|
|
561
627
|
var HELPER_OPENER_RE = /^(?:a\s+)?helper\s+(?:function|method|component|hook|class|type|util(?:ity)?)\b/i;
|
|
562
628
|
var LETS_RE = /^let'?s\s+(?:not\s+|just\s+|now\s+|first\s+)?(?:add|append|assign|await|build|calculate|call|check|clear|close|compute|convert|copy|count|create|declare|decrement|define|delete|extract|fetch|filter|find|format|generate|get|handle|increment|init|initialise|initialize|insert|iterate|join|load|log|loop|map|merge|open|parse|print|process|push|read|remove|render|reset|return|save|send|set|setup|sort|split|start|stop|store|update|validate|wrap|write)(?:s|es|ed|ing)?\b/i;
|
|
563
629
|
var ENUMERATION_RE = /^(?:\d+[.)]\s+\S|(?:phase|step)\s+\d+\b)/i;
|
|
@@ -614,6 +680,7 @@ function isRedundantNarration(body, statementBelow, standalone, isolatedEnumerat
|
|
|
614
680
|
const justified = JUSTIFICATION_RE.test(t);
|
|
615
681
|
if (STEP_NARRATION_RE.test(t) && !justified) return true;
|
|
616
682
|
if (META_COMMENTARY_RE.test(t) && !justified) return true;
|
|
683
|
+
if (isBareDeferral(t) && !justified) return true;
|
|
617
684
|
if (HELPER_OPENER_RE.test(t) || LETS_RE.test(t)) return true;
|
|
618
685
|
const words = t.split(/\s+/);
|
|
619
686
|
if (words.length > 1 && words.length <= 4 && DUMMY_TRANSLATION_RE.test(t) && !/[():=]/.test(t)) {
|
|
@@ -711,6 +778,12 @@ var no_comment_cruft_default = createRule({
|
|
|
711
778
|
function isJsDoc(comment) {
|
|
712
779
|
return comment.type === "Block" && /^\*/.test(comment.value);
|
|
713
780
|
}
|
|
781
|
+
function isSectionJsDoc(comment) {
|
|
782
|
+
const texts = comment.value.split("\n").map(stripCommentMarker).filter((line) => line.length > 0 && !isDirective(line));
|
|
783
|
+
return texts.length > 0 && texts.every(
|
|
784
|
+
(text) => !isProtected(text) && (isBanner(text) || isSectionLabel(text) || SHOUTED_LABEL_RE.test(text.replace(/[.:]$/, "")))
|
|
785
|
+
);
|
|
786
|
+
}
|
|
714
787
|
function reportLeadingPreamble(comments, firstCodeLine) {
|
|
715
788
|
const leading = [];
|
|
716
789
|
let prevLine = null;
|
|
@@ -744,7 +817,13 @@ var no_comment_cruft_default = createRule({
|
|
|
744
817
|
for (let i = 0; i < comments.length; i++) {
|
|
745
818
|
const comment = comments[i];
|
|
746
819
|
if (comment === void 0) continue;
|
|
747
|
-
if (isJsDoc(comment)
|
|
820
|
+
if (isJsDoc(comment)) {
|
|
821
|
+
if (isStandalone(comment) && isSectionJsDoc(comment)) {
|
|
822
|
+
context.report({ node: comment, messageId: "sectionBanner" });
|
|
823
|
+
}
|
|
824
|
+
continue;
|
|
825
|
+
}
|
|
826
|
+
if (!isStandalone(comment)) continue;
|
|
748
827
|
if (LICENSE_RE.test(comment.value)) continue;
|
|
749
828
|
const texts = comment.value.split("\n").map(stripCommentMarker).filter((l) => l.length > 0 && !isDirective(l));
|
|
750
829
|
const firstText = texts[0];
|
|
@@ -5219,10 +5298,158 @@ var no_declaration_comment_wall_default = createRule({
|
|
|
5219
5298
|
}
|
|
5220
5299
|
});
|
|
5221
5300
|
|
|
5222
|
-
// src/rules/no-
|
|
5301
|
+
// src/rules/no-union-in-comment.ts
|
|
5223
5302
|
import { AST_NODE_TYPES as AST_NODE_TYPES24 } from "@typescript-eslint/utils";
|
|
5303
|
+
var MAX_LITERAL_LENGTH = 28;
|
|
5304
|
+
var LITERAL = String.raw`(?:'[^'\n]*'|"[^"\n]*"|\`[^\`\n]*\`)`;
|
|
5305
|
+
var LEAD_IN_RE2 = /^(?:one of|either|values?|allowed(?: values)?|options?|possible(?: values)?)\s*[:=-]?\s*/i;
|
|
5306
|
+
var UNION_BODY_RE = new RegExp(String.raw`^${LITERAL}(?:\s*[|,/]\s*${LITERAL})+\.?$`);
|
|
5307
|
+
var LITERAL_G = new RegExp(LITERAL, "g");
|
|
5308
|
+
var STRING_BUILDERS = /* @__PURE__ */ new Set([
|
|
5309
|
+
"char",
|
|
5310
|
+
"citext",
|
|
5311
|
+
"longtext",
|
|
5312
|
+
"mediumtext",
|
|
5313
|
+
"string",
|
|
5314
|
+
"text",
|
|
5315
|
+
"tinytext",
|
|
5316
|
+
"varchar"
|
|
5317
|
+
]);
|
|
5318
|
+
function isBareString(node) {
|
|
5319
|
+
if (node === void 0) return false;
|
|
5320
|
+
switch (node.type) {
|
|
5321
|
+
case AST_NODE_TYPES24.TSStringKeyword:
|
|
5322
|
+
return true;
|
|
5323
|
+
// `string[]` holds members of the same closed set, one element at a time.
|
|
5324
|
+
case AST_NODE_TYPES24.TSArrayType:
|
|
5325
|
+
return isBareString(node.elementType);
|
|
5326
|
+
// `string | null` is still an unconstrained string, and so is `string | "a"`
|
|
5327
|
+
// — the checker collapses that one to `string`.
|
|
5328
|
+
case AST_NODE_TYPES24.TSUnionType:
|
|
5329
|
+
return node.types.some((member) => isBareString(member));
|
|
5330
|
+
default:
|
|
5331
|
+
return false;
|
|
5332
|
+
}
|
|
5333
|
+
}
|
|
5334
|
+
function rootCallee(node) {
|
|
5335
|
+
let current = node;
|
|
5336
|
+
for (let hops = 0; current != null && hops < 12; hops += 1) {
|
|
5337
|
+
switch (current.type) {
|
|
5338
|
+
case AST_NODE_TYPES24.CallExpression:
|
|
5339
|
+
current = current.callee;
|
|
5340
|
+
break;
|
|
5341
|
+
case AST_NODE_TYPES24.MemberExpression:
|
|
5342
|
+
current = current.object;
|
|
5343
|
+
break;
|
|
5344
|
+
case AST_NODE_TYPES24.Identifier:
|
|
5345
|
+
return current.name;
|
|
5346
|
+
default:
|
|
5347
|
+
return null;
|
|
5348
|
+
}
|
|
5349
|
+
}
|
|
5350
|
+
return null;
|
|
5351
|
+
}
|
|
5352
|
+
function nameOf(key) {
|
|
5353
|
+
if (key.type === AST_NODE_TYPES24.Identifier) return key.name;
|
|
5354
|
+
if (key.type === AST_NODE_TYPES24.Literal && typeof key.value === "string") return key.value;
|
|
5355
|
+
return null;
|
|
5356
|
+
}
|
|
5357
|
+
function targetOf(node) {
|
|
5358
|
+
switch (node.type) {
|
|
5359
|
+
case AST_NODE_TYPES24.TSPropertySignature:
|
|
5360
|
+
case AST_NODE_TYPES24.PropertyDefinition: {
|
|
5361
|
+
const name = node.computed ? null : nameOf(node.key);
|
|
5362
|
+
if (name === null || !isBareString(node.typeAnnotation?.typeAnnotation)) return null;
|
|
5363
|
+
return { node, name };
|
|
5364
|
+
}
|
|
5365
|
+
case AST_NODE_TYPES24.Property: {
|
|
5366
|
+
const name = node.computed || node.shorthand ? null : nameOf(node.key);
|
|
5367
|
+
const callee = rootCallee(node.value);
|
|
5368
|
+
if (name === null || callee === null || !STRING_BUILDERS.has(callee)) return null;
|
|
5369
|
+
return { node, name };
|
|
5370
|
+
}
|
|
5371
|
+
case AST_NODE_TYPES24.VariableDeclarator: {
|
|
5372
|
+
if (node.id.type !== AST_NODE_TYPES24.Identifier) return null;
|
|
5373
|
+
if (!isBareString(node.id.typeAnnotation?.typeAnnotation)) return null;
|
|
5374
|
+
return { node, name: node.id.name };
|
|
5375
|
+
}
|
|
5376
|
+
default:
|
|
5377
|
+
return null;
|
|
5378
|
+
}
|
|
5379
|
+
}
|
|
5380
|
+
function unionLiterals(body) {
|
|
5381
|
+
const list = body.replace(LEAD_IN_RE2, "").trim();
|
|
5382
|
+
if (!UNION_BODY_RE.test(list)) return null;
|
|
5383
|
+
const literals = (list.match(LITERAL_G) ?? []).map((raw) => raw.slice(1, -1));
|
|
5384
|
+
if (literals.some((literal) => literal.length === 0 || literal.length > MAX_LITERAL_LENGTH)) {
|
|
5385
|
+
return null;
|
|
5386
|
+
}
|
|
5387
|
+
return literals;
|
|
5388
|
+
}
|
|
5389
|
+
var no_union_in_comment_default = createRule({
|
|
5390
|
+
name: "no-union-in-comment",
|
|
5391
|
+
meta: {
|
|
5392
|
+
type: "suggestion",
|
|
5393
|
+
docs: {
|
|
5394
|
+
description: "Flag a comment that lists a `string` field's allowed values instead of the type listing them."
|
|
5395
|
+
},
|
|
5396
|
+
schema: [],
|
|
5397
|
+
messages: {
|
|
5398
|
+
unionInComment: 'This comment is a type \u2014 `{{name}}` still accepts every string, so the set it lists is enforced by nobody. Make it a string-literal union ("{{first}}" | \u2026) and delete the comment.'
|
|
5399
|
+
}
|
|
5400
|
+
},
|
|
5401
|
+
defaultOptions: [],
|
|
5402
|
+
create(context) {
|
|
5403
|
+
const sourceCode = context.sourceCode;
|
|
5404
|
+
if (isGeneratedFile(context.filename, sourceCode.text)) {
|
|
5405
|
+
return {};
|
|
5406
|
+
}
|
|
5407
|
+
function annotated(comment) {
|
|
5408
|
+
const before = sourceCode.getTokenBefore(comment, { includeComments: false });
|
|
5409
|
+
let anchor;
|
|
5410
|
+
if (before !== null && before.loc.end.line === comment.loc.start.line) {
|
|
5411
|
+
let token = before;
|
|
5412
|
+
while (token !== null && (token.value === "," || token.value === ";")) {
|
|
5413
|
+
token = sourceCode.getTokenBefore(token, { includeComments: false });
|
|
5414
|
+
}
|
|
5415
|
+
anchor = token === null ? null : sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
5416
|
+
} else {
|
|
5417
|
+
const after = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
5418
|
+
if (after === null || after.loc.start.line !== comment.loc.end.line + 1) return null;
|
|
5419
|
+
anchor = sourceCode.getNodeByRangeIndex(after.range[0]);
|
|
5420
|
+
}
|
|
5421
|
+
for (let node = anchor; node != null && node.type !== AST_NODE_TYPES24.Program; node = node.parent) {
|
|
5422
|
+
const target = targetOf(node);
|
|
5423
|
+
if (target !== null) return target;
|
|
5424
|
+
}
|
|
5425
|
+
return null;
|
|
5426
|
+
}
|
|
5427
|
+
return {
|
|
5428
|
+
Program() {
|
|
5429
|
+
for (const comment of sourceCode.getAllComments()) {
|
|
5430
|
+
const body = comment.value.replace(/^\*+/, "").replace(/\*+$/, "").trim();
|
|
5431
|
+
if (body.length === 0) continue;
|
|
5432
|
+
const literals = unionLiterals(body);
|
|
5433
|
+
if (literals === null) continue;
|
|
5434
|
+
const target = annotated(comment);
|
|
5435
|
+
if (target === null) continue;
|
|
5436
|
+
const declaration = sourceCode.getText(target.node);
|
|
5437
|
+
if (literals.every((literal) => declaration.includes(literal))) continue;
|
|
5438
|
+
context.report({
|
|
5439
|
+
node: comment,
|
|
5440
|
+
messageId: "unionInComment",
|
|
5441
|
+
data: { name: target.name, first: literals[0] ?? "" }
|
|
5442
|
+
});
|
|
5443
|
+
}
|
|
5444
|
+
}
|
|
5445
|
+
};
|
|
5446
|
+
}
|
|
5447
|
+
});
|
|
5448
|
+
|
|
5449
|
+
// src/rules/no-type-member-comment-wall.ts
|
|
5450
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES25 } from "@typescript-eslint/utils";
|
|
5224
5451
|
function isNamedMember(node) {
|
|
5225
|
-
return (node.type ===
|
|
5452
|
+
return (node.type === AST_NODE_TYPES25.TSPropertySignature || node.type === AST_NODE_TYPES25.TSMethodSignature) && !node.computed;
|
|
5226
5453
|
}
|
|
5227
5454
|
var no_type_member_comment_wall_default = createRule({
|
|
5228
5455
|
name: "no-type-member-comment-wall",
|
|
@@ -5269,7 +5496,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5269
5496
|
return headsRun || lineAbove !== void 0 && lineAbove.trim().length === 0;
|
|
5270
5497
|
}
|
|
5271
5498
|
function check(node) {
|
|
5272
|
-
const members = node.type ===
|
|
5499
|
+
const members = node.type === AST_NODE_TYPES25.TSInterfaceBody ? node.body : node.members;
|
|
5273
5500
|
const named2 = members.filter(isNamedMember);
|
|
5274
5501
|
if (named2.length === 0) return;
|
|
5275
5502
|
const documented = named2.map((member) => ({ member, comment: documentingComment(member) }));
|
|
@@ -5309,7 +5536,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5309
5536
|
});
|
|
5310
5537
|
|
|
5311
5538
|
// src/rules/no-unnecessary-use-client.ts
|
|
5312
|
-
import { AST_NODE_TYPES as
|
|
5539
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES26 } from "@typescript-eslint/utils";
|
|
5313
5540
|
var HOOK_REGEX = /^use([A-Z]|$)/;
|
|
5314
5541
|
var EVENT_PROP_REGEX = /^on[A-Z]/;
|
|
5315
5542
|
var ERROR_FILE_REGEX = /\b(?:global-)?error\.[jt]sx?$/;
|
|
@@ -5335,13 +5562,13 @@ var CLIENT_ONLY_PACKAGES_REGEX = /^(?:@radix-ui\/|framer-motion|react-dom|react-
|
|
|
5335
5562
|
var isBareSpecifier = (source) => !source.startsWith(".") && !source.startsWith("/") && !source.startsWith("@/") && !source.startsWith("~");
|
|
5336
5563
|
var jsxRootName = (name) => {
|
|
5337
5564
|
let current = name;
|
|
5338
|
-
while (current.type ===
|
|
5565
|
+
while (current.type === AST_NODE_TYPES26.JSXMemberExpression) {
|
|
5339
5566
|
current = current.object;
|
|
5340
5567
|
}
|
|
5341
|
-
return current.type ===
|
|
5568
|
+
return current.type === AST_NODE_TYPES26.JSXIdentifier ? current.name : "";
|
|
5342
5569
|
};
|
|
5343
5570
|
var subtreeReadsImportedBinding = (node, imported) => {
|
|
5344
|
-
if (node.type ===
|
|
5571
|
+
if (node.type === AST_NODE_TYPES26.Identifier) {
|
|
5345
5572
|
return imported.has(node.name);
|
|
5346
5573
|
}
|
|
5347
5574
|
for (const key of Object.keys(node)) {
|
|
@@ -5356,16 +5583,16 @@ var subtreeReadsImportedBinding = (node, imported) => {
|
|
|
5356
5583
|
return false;
|
|
5357
5584
|
};
|
|
5358
5585
|
var isUseClientDirective = (node) => {
|
|
5359
|
-
return node.type ===
|
|
5586
|
+
return node.type === AST_NODE_TYPES26.ExpressionStatement && node.expression.type === AST_NODE_TYPES26.Literal && node.expression.value === "use client";
|
|
5360
5587
|
};
|
|
5361
5588
|
var isGlobalReference = (node, context) => {
|
|
5362
5589
|
if (!BROWSER_GLOBALS.has(node.name)) return false;
|
|
5363
5590
|
const parent = node.parent;
|
|
5364
5591
|
if (parent !== void 0) {
|
|
5365
|
-
if (parent.type ===
|
|
5592
|
+
if (parent.type === AST_NODE_TYPES26.MemberExpression && parent.property === node && !parent.computed) {
|
|
5366
5593
|
return false;
|
|
5367
5594
|
}
|
|
5368
|
-
if (parent.type ===
|
|
5595
|
+
if (parent.type === AST_NODE_TYPES26.Property && parent.key === node && !parent.computed) {
|
|
5369
5596
|
return false;
|
|
5370
5597
|
}
|
|
5371
5598
|
if (parent.type.startsWith("TS")) {
|
|
@@ -5405,13 +5632,13 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5405
5632
|
const importedLocals = /* @__PURE__ */ new Set();
|
|
5406
5633
|
const externalLocals = /* @__PURE__ */ new Set();
|
|
5407
5634
|
const markIfHookOrContext = (callee) => {
|
|
5408
|
-
if (callee.type ===
|
|
5635
|
+
if (callee.type === AST_NODE_TYPES26.Identifier) {
|
|
5409
5636
|
if (HOOK_REGEX.test(callee.name) || callee.name === "createContext") {
|
|
5410
5637
|
hasClientIndicator = true;
|
|
5411
5638
|
}
|
|
5412
5639
|
return;
|
|
5413
5640
|
}
|
|
5414
|
-
if (callee.type ===
|
|
5641
|
+
if (callee.type === AST_NODE_TYPES26.MemberExpression && callee.property.type === AST_NODE_TYPES26.Identifier) {
|
|
5415
5642
|
const name = callee.property.name;
|
|
5416
5643
|
if (HOOK_REGEX.test(name) || name === "createContext") {
|
|
5417
5644
|
hasClientIndicator = true;
|
|
@@ -5421,7 +5648,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5421
5648
|
return {
|
|
5422
5649
|
Program(node) {
|
|
5423
5650
|
for (const stmt of node.body) {
|
|
5424
|
-
if (stmt.type !==
|
|
5651
|
+
if (stmt.type !== AST_NODE_TYPES26.ExpressionStatement) break;
|
|
5425
5652
|
if (isUseClientDirective(stmt)) {
|
|
5426
5653
|
directiveNode = stmt;
|
|
5427
5654
|
break;
|
|
@@ -5434,7 +5661,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5434
5661
|
},
|
|
5435
5662
|
JSXAttribute(node) {
|
|
5436
5663
|
if (directiveNode === null) return;
|
|
5437
|
-
if (node.name.type ===
|
|
5664
|
+
if (node.name.type === AST_NODE_TYPES26.JSXIdentifier && EVENT_PROP_REGEX.test(node.name.name)) {
|
|
5438
5665
|
hasClientIndicator = true;
|
|
5439
5666
|
}
|
|
5440
5667
|
},
|
|
@@ -5502,17 +5729,17 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5502
5729
|
|
|
5503
5730
|
// src/rules/no-unsafe-mock-casting.ts
|
|
5504
5731
|
import "@typescript-eslint/utils";
|
|
5505
|
-
import { AST_NODE_TYPES as
|
|
5732
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES27 } from "@typescript-eslint/utils";
|
|
5506
5733
|
function isMockTypeReference(node) {
|
|
5507
|
-
if (node.type !==
|
|
5734
|
+
if (node.type !== AST_NODE_TYPES27.TSTypeReference) {
|
|
5508
5735
|
return false;
|
|
5509
5736
|
}
|
|
5510
5737
|
const typeName = node.typeName;
|
|
5511
|
-
if (typeName.type ===
|
|
5738
|
+
if (typeName.type === AST_NODE_TYPES27.Identifier) {
|
|
5512
5739
|
const name = typeName.name;
|
|
5513
5740
|
return name === "Mock" || name === "MockInstance" || name === "SpyInstance";
|
|
5514
5741
|
}
|
|
5515
|
-
if (typeName.type ===
|
|
5742
|
+
if (typeName.type === AST_NODE_TYPES27.TSQualifiedName) {
|
|
5516
5743
|
const rightName = typeName.right.name;
|
|
5517
5744
|
return rightName === "Mock" || rightName === "MockInstance" || rightName === "SpyInstance";
|
|
5518
5745
|
}
|
|
@@ -5550,7 +5777,7 @@ var no_unsafe_mock_casting_default = createRule({
|
|
|
5550
5777
|
// src/rules/no-zod-native-enum.ts
|
|
5551
5778
|
import {
|
|
5552
5779
|
ESLintUtils as ESLintUtils2,
|
|
5553
|
-
AST_NODE_TYPES as
|
|
5780
|
+
AST_NODE_TYPES as AST_NODE_TYPES28
|
|
5554
5781
|
} from "@typescript-eslint/utils";
|
|
5555
5782
|
import * as ts from "typescript";
|
|
5556
5783
|
var IGNORE_PATTERNS = [
|
|
@@ -5569,7 +5796,7 @@ function isZodModule(source) {
|
|
|
5569
5796
|
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
5570
5797
|
}
|
|
5571
5798
|
function unwrap2(node) {
|
|
5572
|
-
if (node.type ===
|
|
5799
|
+
if (node.type === AST_NODE_TYPES28.TSAsExpression || node.type === AST_NODE_TYPES28.TSSatisfiesExpression) {
|
|
5573
5800
|
return unwrap2(node.expression);
|
|
5574
5801
|
}
|
|
5575
5802
|
return node;
|
|
@@ -5577,14 +5804,14 @@ function unwrap2(node) {
|
|
|
5577
5804
|
function stringValueTexts(node, sourceCode) {
|
|
5578
5805
|
const texts = [];
|
|
5579
5806
|
for (const prop of node.properties) {
|
|
5580
|
-
if (prop.type !==
|
|
5807
|
+
if (prop.type !== AST_NODE_TYPES28.Property) {
|
|
5581
5808
|
return null;
|
|
5582
5809
|
}
|
|
5583
5810
|
if (prop.computed || prop.shorthand || prop.method || prop.kind !== "init") {
|
|
5584
5811
|
return null;
|
|
5585
5812
|
}
|
|
5586
5813
|
const value = prop.value;
|
|
5587
|
-
if (value.type !==
|
|
5814
|
+
if (value.type !== AST_NODE_TYPES28.Literal || typeof value.value !== "string") {
|
|
5588
5815
|
return null;
|
|
5589
5816
|
}
|
|
5590
5817
|
const text = sourceCode.getText(value);
|
|
@@ -5600,7 +5827,7 @@ function resolvesToLocalEnum(node, scope) {
|
|
|
5600
5827
|
const variable = current.variables.find((v) => v.name === node.name);
|
|
5601
5828
|
if (variable !== void 0) {
|
|
5602
5829
|
return variable.defs.some(
|
|
5603
|
-
(def) => def.node.type ===
|
|
5830
|
+
(def) => def.node.type === AST_NODE_TYPES28.TSEnumDeclaration
|
|
5604
5831
|
);
|
|
5605
5832
|
}
|
|
5606
5833
|
current = current.upper;
|
|
@@ -5652,25 +5879,25 @@ var no_zod_native_enum_default = createRule({
|
|
|
5652
5879
|
const zodImportedNames = /* @__PURE__ */ new Map();
|
|
5653
5880
|
function isZodMemberCall(node, api) {
|
|
5654
5881
|
const callee = node.callee;
|
|
5655
|
-
if (callee.type ===
|
|
5882
|
+
if (callee.type === AST_NODE_TYPES28.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES28.Identifier) {
|
|
5656
5883
|
return callee.property.name === api;
|
|
5657
5884
|
}
|
|
5658
|
-
if (callee.type ===
|
|
5885
|
+
if (callee.type === AST_NODE_TYPES28.Identifier) {
|
|
5659
5886
|
return zodImportedNames.get(callee.name) === api;
|
|
5660
5887
|
}
|
|
5661
5888
|
return false;
|
|
5662
5889
|
}
|
|
5663
5890
|
function buildFix(node) {
|
|
5664
5891
|
const callee = node.callee;
|
|
5665
|
-
if (callee.type !==
|
|
5892
|
+
if (callee.type !== AST_NODE_TYPES28.MemberExpression || callee.property.type !== AST_NODE_TYPES28.Identifier) {
|
|
5666
5893
|
return null;
|
|
5667
5894
|
}
|
|
5668
5895
|
const arg = node.arguments[0];
|
|
5669
|
-
if (arg === void 0 || node.arguments.length !== 1 || arg.type ===
|
|
5896
|
+
if (arg === void 0 || node.arguments.length !== 1 || arg.type === AST_NODE_TYPES28.SpreadElement) {
|
|
5670
5897
|
return null;
|
|
5671
5898
|
}
|
|
5672
5899
|
const inner = unwrap2(arg);
|
|
5673
|
-
if (inner.type !==
|
|
5900
|
+
if (inner.type !== AST_NODE_TYPES28.ObjectExpression) {
|
|
5674
5901
|
return null;
|
|
5675
5902
|
}
|
|
5676
5903
|
const values = stringValueTexts(inner, sourceCode);
|
|
@@ -5690,7 +5917,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
5690
5917
|
return;
|
|
5691
5918
|
}
|
|
5692
5919
|
for (const spec of node.specifiers) {
|
|
5693
|
-
if (spec.type ===
|
|
5920
|
+
if (spec.type === AST_NODE_TYPES28.ImportSpecifier && spec.imported.type === AST_NODE_TYPES28.Identifier) {
|
|
5694
5921
|
zodImportedNames.set(spec.local.name, spec.imported.name);
|
|
5695
5922
|
}
|
|
5696
5923
|
}
|
|
@@ -5709,7 +5936,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
5709
5936
|
return;
|
|
5710
5937
|
}
|
|
5711
5938
|
const arg = node.arguments[0];
|
|
5712
|
-
if (arg === void 0 || arg.type !==
|
|
5939
|
+
if (arg === void 0 || arg.type !== AST_NODE_TYPES28.Identifier) {
|
|
5713
5940
|
return;
|
|
5714
5941
|
}
|
|
5715
5942
|
const isEnum = resolvesToLocalEnum(arg, sourceCode.getScope(arg)) || services !== null && resolvesToImportedEnum(arg, services);
|
|
@@ -5726,7 +5953,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
5726
5953
|
});
|
|
5727
5954
|
|
|
5728
5955
|
// src/rules/prefer-constant-time-secret-compare.ts
|
|
5729
|
-
import { AST_NODE_TYPES as
|
|
5956
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES29 } from "@typescript-eslint/utils";
|
|
5730
5957
|
var EQUALITY_OPERATORS = /* @__PURE__ */ new Set(["===", "!==", "==", "!="]);
|
|
5731
5958
|
var SENTINEL_IDENTIFIERS = /* @__PURE__ */ new Set(["undefined", "NaN"]);
|
|
5732
5959
|
var SENTINEL_WORDS = /(^|_)(SENTINEL|EMPTY|NONE|NULL|UNSET|MISSING|PLACEHOLDER|DUMMY|FAKE|EXAMPLE)(_|$)/;
|
|
@@ -5739,36 +5966,36 @@ function isConstantReference(identifier) {
|
|
|
5739
5966
|
}
|
|
5740
5967
|
function isExcludedOperand(node) {
|
|
5741
5968
|
switch (node.type) {
|
|
5742
|
-
case
|
|
5969
|
+
case AST_NODE_TYPES29.Literal:
|
|
5743
5970
|
return true;
|
|
5744
|
-
case
|
|
5971
|
+
case AST_NODE_TYPES29.TemplateLiteral:
|
|
5745
5972
|
return node.expressions.length === 0;
|
|
5746
|
-
case
|
|
5973
|
+
case AST_NODE_TYPES29.Identifier:
|
|
5747
5974
|
return SENTINEL_IDENTIFIERS.has(node.name) || SENTINEL_PREFIX_RE.test(node.name) || isConstantReference(node.name);
|
|
5748
|
-
case
|
|
5749
|
-
return !node.computed && node.property.type ===
|
|
5975
|
+
case AST_NODE_TYPES29.MemberExpression:
|
|
5976
|
+
return !node.computed && node.property.type === AST_NODE_TYPES29.Identifier && (SENTINEL_PREFIX_RE.test(node.property.name) || isConstantReference(node.property.name));
|
|
5750
5977
|
default:
|
|
5751
5978
|
return false;
|
|
5752
5979
|
}
|
|
5753
5980
|
}
|
|
5754
5981
|
function operandName(node) {
|
|
5755
|
-
if (node.type ===
|
|
5982
|
+
if (node.type === AST_NODE_TYPES29.Identifier) {
|
|
5756
5983
|
return node.name;
|
|
5757
5984
|
}
|
|
5758
|
-
if (node.type ===
|
|
5985
|
+
if (node.type === AST_NODE_TYPES29.MemberExpression && !node.computed && node.property.type === AST_NODE_TYPES29.Identifier) {
|
|
5759
5986
|
return node.property.name;
|
|
5760
5987
|
}
|
|
5761
5988
|
return null;
|
|
5762
5989
|
}
|
|
5763
5990
|
function isSecretOperand(node) {
|
|
5764
|
-
if (node.type ===
|
|
5991
|
+
if (node.type === AST_NODE_TYPES29.TemplateLiteral) {
|
|
5765
5992
|
return node.expressions.some((expression) => isSecretOperand(expression));
|
|
5766
5993
|
}
|
|
5767
5994
|
const name = operandName(node);
|
|
5768
5995
|
return name !== null && isAuthSecretName(name);
|
|
5769
5996
|
}
|
|
5770
5997
|
function secretNameOf(node) {
|
|
5771
|
-
if (node.type ===
|
|
5998
|
+
if (node.type === AST_NODE_TYPES29.TemplateLiteral) {
|
|
5772
5999
|
for (const expression of node.expressions) {
|
|
5773
6000
|
const nested = secretNameOf(expression);
|
|
5774
6001
|
if (nested !== null) {
|
|
@@ -5821,7 +6048,7 @@ var prefer_constant_time_secret_compare_default = createRule({
|
|
|
5821
6048
|
|
|
5822
6049
|
// src/rules/prefer-discriminated-union.ts
|
|
5823
6050
|
import "@typescript-eslint/utils";
|
|
5824
|
-
import { AST_NODE_TYPES as
|
|
6051
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES30 } from "@typescript-eslint/utils";
|
|
5825
6052
|
var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
5826
6053
|
"success",
|
|
5827
6054
|
"ok",
|
|
@@ -5831,27 +6058,27 @@ var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
|
5831
6058
|
]);
|
|
5832
6059
|
var MIN_OPTIONAL_MEMBERS = 2;
|
|
5833
6060
|
function getMemberName(member) {
|
|
5834
|
-
if (member.type !==
|
|
6061
|
+
if (member.type !== AST_NODE_TYPES30.TSPropertySignature) {
|
|
5835
6062
|
return null;
|
|
5836
6063
|
}
|
|
5837
6064
|
const { key } = member;
|
|
5838
|
-
if (key.type ===
|
|
6065
|
+
if (key.type === AST_NODE_TYPES30.Identifier) {
|
|
5839
6066
|
return key.name;
|
|
5840
6067
|
}
|
|
5841
|
-
if (key.type ===
|
|
6068
|
+
if (key.type === AST_NODE_TYPES30.Literal && typeof key.value === "string") {
|
|
5842
6069
|
return key.value;
|
|
5843
6070
|
}
|
|
5844
6071
|
return null;
|
|
5845
6072
|
}
|
|
5846
6073
|
function isBooleanTyped(member) {
|
|
5847
|
-
return member.typeAnnotation?.typeAnnotation.type ===
|
|
6074
|
+
return member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES30.TSBooleanKeyword;
|
|
5848
6075
|
}
|
|
5849
6076
|
function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
5850
6077
|
let hasStatusBoolean = false;
|
|
5851
6078
|
let optionalCount = 0;
|
|
5852
6079
|
let optionalPayloadCount = 0;
|
|
5853
6080
|
for (const member of typeLiteral.members) {
|
|
5854
|
-
if (member.type !==
|
|
6081
|
+
if (member.type !== AST_NODE_TYPES30.TSPropertySignature) {
|
|
5855
6082
|
continue;
|
|
5856
6083
|
}
|
|
5857
6084
|
if (member.optional) {
|
|
@@ -5893,7 +6120,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
5893
6120
|
TSInterfaceDeclaration(node) {
|
|
5894
6121
|
const synthetic = {
|
|
5895
6122
|
...node.body,
|
|
5896
|
-
type:
|
|
6123
|
+
type: AST_NODE_TYPES30.TSTypeLiteral,
|
|
5897
6124
|
members: node.body.body
|
|
5898
6125
|
};
|
|
5899
6126
|
checkTypeLiteral(synthetic, node);
|
|
@@ -5906,7 +6133,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
5906
6133
|
});
|
|
5907
6134
|
|
|
5908
6135
|
// src/rules/prefer-module-level-constant.ts
|
|
5909
|
-
import { AST_NODE_TYPES as
|
|
6136
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES31 } from "@typescript-eslint/utils";
|
|
5910
6137
|
var DEFAULT_MIN_ELEMENTS = 3;
|
|
5911
6138
|
var MAX_LITERAL_DEPTH = 4;
|
|
5912
6139
|
var IGNORE_PATTERNS2 = [
|
|
@@ -5935,9 +6162,9 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
|
5935
6162
|
"assign"
|
|
5936
6163
|
]);
|
|
5937
6164
|
var FUNCTION_TYPES5 = /* @__PURE__ */ new Set([
|
|
5938
|
-
|
|
5939
|
-
|
|
5940
|
-
|
|
6165
|
+
AST_NODE_TYPES31.FunctionDeclaration,
|
|
6166
|
+
AST_NODE_TYPES31.FunctionExpression,
|
|
6167
|
+
AST_NODE_TYPES31.ArrowFunctionExpression
|
|
5941
6168
|
]);
|
|
5942
6169
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
5943
6170
|
function isIgnoredFile2(filename, sourceText) {
|
|
@@ -5950,14 +6177,14 @@ function isLocalFixtureFile(filename) {
|
|
|
5950
6177
|
return isTestFile(filename) || isStoryFile(filename);
|
|
5951
6178
|
}
|
|
5952
6179
|
function unwrap3(node) {
|
|
5953
|
-
if (node.type ===
|
|
6180
|
+
if (node.type === AST_NODE_TYPES31.TSAsExpression || node.type === AST_NODE_TYPES31.TSSatisfiesExpression || node.type === AST_NODE_TYPES31.TSNonNullExpression) {
|
|
5954
6181
|
return unwrap3(node.expression);
|
|
5955
6182
|
}
|
|
5956
6183
|
return node;
|
|
5957
6184
|
}
|
|
5958
6185
|
var HAS_STATEFUL_FLAG_RE = /[gy]/;
|
|
5959
6186
|
function isRegexLiteral(node) {
|
|
5960
|
-
return node.type ===
|
|
6187
|
+
return node.type === AST_NODE_TYPES31.Literal && "regex" in node && node.regex !== void 0;
|
|
5961
6188
|
}
|
|
5962
6189
|
function isLiteralOnly(node, depth) {
|
|
5963
6190
|
if (depth > MAX_LITERAL_DEPTH) {
|
|
@@ -5965,29 +6192,29 @@ function isLiteralOnly(node, depth) {
|
|
|
5965
6192
|
}
|
|
5966
6193
|
const inner = unwrap3(node);
|
|
5967
6194
|
switch (inner.type) {
|
|
5968
|
-
case
|
|
6195
|
+
case AST_NODE_TYPES31.Literal: {
|
|
5969
6196
|
return !(isRegexLiteral(inner) && HAS_STATEFUL_FLAG_RE.test(inner.regex.flags));
|
|
5970
6197
|
}
|
|
5971
|
-
case
|
|
6198
|
+
case AST_NODE_TYPES31.TemplateLiteral: {
|
|
5972
6199
|
return inner.expressions.length === 0;
|
|
5973
6200
|
}
|
|
5974
|
-
case
|
|
5975
|
-
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type ===
|
|
6201
|
+
case AST_NODE_TYPES31.UnaryExpression: {
|
|
6202
|
+
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type === AST_NODE_TYPES31.Literal && typeof inner.argument.value === "number";
|
|
5976
6203
|
}
|
|
5977
|
-
case
|
|
6204
|
+
case AST_NODE_TYPES31.ArrayExpression: {
|
|
5978
6205
|
return inner.elements.every(
|
|
5979
|
-
(el) => el !== null && el.type !==
|
|
6206
|
+
(el) => el !== null && el.type !== AST_NODE_TYPES31.SpreadElement && isLiteralOnly(el, depth + 1)
|
|
5980
6207
|
);
|
|
5981
6208
|
}
|
|
5982
|
-
case
|
|
6209
|
+
case AST_NODE_TYPES31.ObjectExpression: {
|
|
5983
6210
|
return inner.properties.every((prop) => {
|
|
5984
|
-
if (prop.type !==
|
|
6211
|
+
if (prop.type !== AST_NODE_TYPES31.Property) {
|
|
5985
6212
|
return false;
|
|
5986
6213
|
}
|
|
5987
6214
|
if (prop.shorthand || prop.method || prop.kind !== "init") {
|
|
5988
6215
|
return false;
|
|
5989
6216
|
}
|
|
5990
|
-
if (prop.computed && prop.key.type !==
|
|
6217
|
+
if (prop.computed && prop.key.type !== AST_NODE_TYPES31.Literal) {
|
|
5991
6218
|
return false;
|
|
5992
6219
|
}
|
|
5993
6220
|
return isLiteralOnly(prop.value, depth + 1);
|
|
@@ -6000,7 +6227,7 @@ function isLiteralOnly(node, depth) {
|
|
|
6000
6227
|
}
|
|
6001
6228
|
function unwrapObjectFreeze(node) {
|
|
6002
6229
|
const inner = unwrap3(node);
|
|
6003
|
-
if (inner.type ===
|
|
6230
|
+
if (inner.type === AST_NODE_TYPES31.CallExpression && inner.callee.type === AST_NODE_TYPES31.MemberExpression && !inner.callee.computed && inner.callee.object.type === AST_NODE_TYPES31.Identifier && inner.callee.object.name === "Object" && inner.callee.property.type === AST_NODE_TYPES31.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== AST_NODE_TYPES31.SpreadElement) {
|
|
6004
6231
|
return unwrap3(inner.arguments[0]);
|
|
6005
6232
|
}
|
|
6006
6233
|
return inner;
|
|
@@ -6016,19 +6243,19 @@ function classify(init, checkRegex) {
|
|
|
6016
6243
|
}
|
|
6017
6244
|
return { kind: "regex", size: 1 };
|
|
6018
6245
|
}
|
|
6019
|
-
if (node.type ===
|
|
6246
|
+
if (node.type === AST_NODE_TYPES31.ArrayExpression) {
|
|
6020
6247
|
return isLiteralOnly(node, 0) ? { kind: "array", size: node.elements.length } : null;
|
|
6021
6248
|
}
|
|
6022
|
-
if (node.type ===
|
|
6249
|
+
if (node.type === AST_NODE_TYPES31.ObjectExpression) {
|
|
6023
6250
|
return isLiteralOnly(node, 0) ? { kind: "object", size: node.properties.length } : null;
|
|
6024
6251
|
}
|
|
6025
|
-
if (node.type ===
|
|
6252
|
+
if (node.type === AST_NODE_TYPES31.NewExpression && node.callee.type === AST_NODE_TYPES31.Identifier && COLLECTION_CONSTRUCTORS.has(node.callee.name)) {
|
|
6026
6253
|
const arg = node.arguments[0];
|
|
6027
|
-
if (node.arguments.length !== 1 || arg === void 0 || arg.type ===
|
|
6254
|
+
if (node.arguments.length !== 1 || arg === void 0 || arg.type === AST_NODE_TYPES31.SpreadElement) {
|
|
6028
6255
|
return null;
|
|
6029
6256
|
}
|
|
6030
6257
|
const entries = unwrap3(arg);
|
|
6031
|
-
if (entries.type !==
|
|
6258
|
+
if (entries.type !== AST_NODE_TYPES31.ArrayExpression) {
|
|
6032
6259
|
return null;
|
|
6033
6260
|
}
|
|
6034
6261
|
return isLiteralOnly(entries, 0) ? { kind: node.callee.name === "Set" ? "Set" : "Map", size: entries.elements.length } : null;
|
|
@@ -6057,10 +6284,10 @@ var NON_RETAINING_BUILTINS = /* @__PURE__ */ new Map(
|
|
|
6057
6284
|
);
|
|
6058
6285
|
function isNonRetainingBuiltinCall(node, argument) {
|
|
6059
6286
|
const callee = node.callee;
|
|
6060
|
-
if (callee.type ===
|
|
6287
|
+
if (callee.type === AST_NODE_TYPES31.Identifier && callee.name === "structuredClone") {
|
|
6061
6288
|
return true;
|
|
6062
6289
|
}
|
|
6063
|
-
if (callee.type !==
|
|
6290
|
+
if (callee.type !== AST_NODE_TYPES31.MemberExpression || callee.computed || callee.object.type !== AST_NODE_TYPES31.Identifier || callee.property.type !== AST_NODE_TYPES31.Identifier) {
|
|
6064
6291
|
return false;
|
|
6065
6292
|
}
|
|
6066
6293
|
const members = NON_RETAINING_BUILTINS.get(callee.object.name);
|
|
@@ -6074,38 +6301,38 @@ function isNonRetainingBuiltinCall(node, argument) {
|
|
|
6074
6301
|
}
|
|
6075
6302
|
function isSafeRead(identifier) {
|
|
6076
6303
|
const parent = identifier.parent;
|
|
6077
|
-
if (parent.type ===
|
|
6304
|
+
if (parent.type === AST_NODE_TYPES31.MemberExpression) {
|
|
6078
6305
|
if (parent.object !== identifier) {
|
|
6079
6306
|
return true;
|
|
6080
6307
|
}
|
|
6081
6308
|
const grandparent = parent.parent;
|
|
6082
|
-
if (grandparent.type ===
|
|
6309
|
+
if (grandparent.type === AST_NODE_TYPES31.AssignmentExpression && grandparent.left === parent) {
|
|
6083
6310
|
return false;
|
|
6084
6311
|
}
|
|
6085
|
-
if (grandparent.type ===
|
|
6312
|
+
if (grandparent.type === AST_NODE_TYPES31.UpdateExpression) {
|
|
6086
6313
|
return false;
|
|
6087
6314
|
}
|
|
6088
|
-
if (grandparent.type ===
|
|
6315
|
+
if (grandparent.type === AST_NODE_TYPES31.UnaryExpression && grandparent.operator === "delete") {
|
|
6089
6316
|
return false;
|
|
6090
6317
|
}
|
|
6091
|
-
if (!parent.computed && parent.property.type ===
|
|
6318
|
+
if (!parent.computed && parent.property.type === AST_NODE_TYPES31.Identifier && MUTATING_METHODS.has(parent.property.name) && grandparent.type === AST_NODE_TYPES31.CallExpression && grandparent.callee === parent) {
|
|
6092
6319
|
return false;
|
|
6093
6320
|
}
|
|
6094
6321
|
return true;
|
|
6095
6322
|
}
|
|
6096
|
-
if (parent.type ===
|
|
6323
|
+
if (parent.type === AST_NODE_TYPES31.ForOfStatement && parent.right === identifier) {
|
|
6097
6324
|
return true;
|
|
6098
6325
|
}
|
|
6099
|
-
if (parent.type ===
|
|
6326
|
+
if (parent.type === AST_NODE_TYPES31.SpreadElement) {
|
|
6100
6327
|
return true;
|
|
6101
6328
|
}
|
|
6102
|
-
if (parent.type ===
|
|
6329
|
+
if (parent.type === AST_NODE_TYPES31.BinaryExpression) {
|
|
6103
6330
|
return true;
|
|
6104
6331
|
}
|
|
6105
|
-
if (parent.type ===
|
|
6332
|
+
if (parent.type === AST_NODE_TYPES31.CallExpression && parent.arguments.includes(identifier) && isNonRetainingBuiltinCall(parent, identifier)) {
|
|
6106
6333
|
return true;
|
|
6107
6334
|
}
|
|
6108
|
-
if (parent.type ===
|
|
6335
|
+
if (parent.type === AST_NODE_TYPES31.UnaryExpression && parent.operator !== "delete") {
|
|
6109
6336
|
return true;
|
|
6110
6337
|
}
|
|
6111
6338
|
return false;
|
|
@@ -6160,7 +6387,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6160
6387
|
if (reference.isWrite()) {
|
|
6161
6388
|
return false;
|
|
6162
6389
|
}
|
|
6163
|
-
if (reference.identifier.type !==
|
|
6390
|
+
if (reference.identifier.type !== AST_NODE_TYPES31.Identifier) {
|
|
6164
6391
|
return false;
|
|
6165
6392
|
}
|
|
6166
6393
|
if (!isSafeRead(reference.identifier)) {
|
|
@@ -6172,10 +6399,10 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6172
6399
|
return {
|
|
6173
6400
|
VariableDeclarator(node) {
|
|
6174
6401
|
const declaration = node.parent;
|
|
6175
|
-
if (declaration.type !==
|
|
6402
|
+
if (declaration.type !== AST_NODE_TYPES31.VariableDeclaration || declaration.kind !== "const" || declaration.declare === true) {
|
|
6176
6403
|
return;
|
|
6177
6404
|
}
|
|
6178
|
-
if (node.id.type !==
|
|
6405
|
+
if (node.id.type !== AST_NODE_TYPES31.Identifier || node.init === null) {
|
|
6179
6406
|
return;
|
|
6180
6407
|
}
|
|
6181
6408
|
if (enclosingFunction2(node) === null) {
|
|
@@ -6202,7 +6429,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6202
6429
|
});
|
|
6203
6430
|
|
|
6204
6431
|
// src/rules/prefer-module-level-schema.ts
|
|
6205
|
-
import { AST_NODE_TYPES as
|
|
6432
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES32 } from "@typescript-eslint/utils";
|
|
6206
6433
|
|
|
6207
6434
|
// src/rules/_zod.ts
|
|
6208
6435
|
var ZOD_PREFIX_RE = /^Z[A-Z]/;
|
|
@@ -6268,9 +6495,9 @@ var I18N_RECEIVER_NAMES = /* @__PURE__ */ new Set([
|
|
|
6268
6495
|
"intl"
|
|
6269
6496
|
]);
|
|
6270
6497
|
var FUNCTION_TYPES6 = /* @__PURE__ */ new Set([
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6498
|
+
AST_NODE_TYPES32.ArrowFunctionExpression,
|
|
6499
|
+
AST_NODE_TYPES32.FunctionDeclaration,
|
|
6500
|
+
AST_NODE_TYPES32.FunctionExpression
|
|
6274
6501
|
]);
|
|
6275
6502
|
function schemaExpression(node) {
|
|
6276
6503
|
let current = node;
|
|
@@ -6279,10 +6506,10 @@ function schemaExpression(node) {
|
|
|
6279
6506
|
if (parent === void 0) {
|
|
6280
6507
|
return current;
|
|
6281
6508
|
}
|
|
6282
|
-
if (parent.type ===
|
|
6509
|
+
if (parent.type === AST_NODE_TYPES32.MemberExpression && parent.object === current && !parent.computed && parent.property.type === AST_NODE_TYPES32.Identifier && TERMINAL_METHODS.has(parent.property.name)) {
|
|
6283
6510
|
return current;
|
|
6284
6511
|
}
|
|
6285
|
-
if (parent.type ===
|
|
6512
|
+
if (parent.type === AST_NODE_TYPES32.MemberExpression && parent.object === current || parent.type === AST_NODE_TYPES32.CallExpression && parent.callee === current || parent.type === AST_NODE_TYPES32.TSAsExpression && parent.expression === current || parent.type === AST_NODE_TYPES32.TSNonNullExpression && parent.expression === current) {
|
|
6286
6513
|
current = parent;
|
|
6287
6514
|
continue;
|
|
6288
6515
|
}
|
|
@@ -6333,22 +6560,22 @@ function subtreeSome(root, predicate) {
|
|
|
6333
6560
|
function readsReceiver(node) {
|
|
6334
6561
|
return subtreeSome(
|
|
6335
6562
|
node,
|
|
6336
|
-
(inner) => inner.type ===
|
|
6563
|
+
(inner) => inner.type === AST_NODE_TYPES32.ThisExpression || inner.type === AST_NODE_TYPES32.Super || inner.type === AST_NODE_TYPES32.Identifier && inner.name === "arguments"
|
|
6337
6564
|
);
|
|
6338
6565
|
}
|
|
6339
6566
|
function buildsLocalizedText(node) {
|
|
6340
6567
|
return subtreeSome(node, (inner) => {
|
|
6341
|
-
if (inner.type ===
|
|
6568
|
+
if (inner.type === AST_NODE_TYPES32.TaggedTemplateExpression) {
|
|
6342
6569
|
return true;
|
|
6343
6570
|
}
|
|
6344
|
-
if (inner.type !==
|
|
6571
|
+
if (inner.type !== AST_NODE_TYPES32.CallExpression) {
|
|
6345
6572
|
return false;
|
|
6346
6573
|
}
|
|
6347
6574
|
const { callee } = inner;
|
|
6348
|
-
if (callee.type ===
|
|
6575
|
+
if (callee.type === AST_NODE_TYPES32.Identifier) {
|
|
6349
6576
|
return I18N_CALLEE_NAMES.has(callee.name);
|
|
6350
6577
|
}
|
|
6351
|
-
return callee.type ===
|
|
6578
|
+
return callee.type === AST_NODE_TYPES32.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES32.Identifier && I18N_RECEIVER_NAMES.has(callee.object.name);
|
|
6352
6579
|
});
|
|
6353
6580
|
}
|
|
6354
6581
|
function collectReferences(scope, out) {
|
|
@@ -6405,15 +6632,15 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6405
6632
|
}
|
|
6406
6633
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
6407
6634
|
function isZodCall(node) {
|
|
6408
|
-
return node.type ===
|
|
6635
|
+
return node.type === AST_NODE_TYPES32.CallExpression && node.callee.type === AST_NODE_TYPES32.MemberExpression && !node.callee.computed && node.callee.object.type === AST_NODE_TYPES32.Identifier && zodNamespaces.has(node.callee.object.name);
|
|
6409
6636
|
}
|
|
6410
6637
|
function isCovered(node) {
|
|
6411
6638
|
let current = node.parent ?? void 0;
|
|
6412
6639
|
while (current !== void 0) {
|
|
6413
|
-
if (current !== node && isZodCall(current) && current.callee.type ===
|
|
6640
|
+
if (current !== node && isZodCall(current) && current.callee.type === AST_NODE_TYPES32.MemberExpression && current.callee.property.type === AST_NODE_TYPES32.Identifier && factories.has(current.callee.property.name)) {
|
|
6414
6641
|
return true;
|
|
6415
6642
|
}
|
|
6416
|
-
if (current.type ===
|
|
6643
|
+
if (current.type === AST_NODE_TYPES32.CallExpression && (current.callee.type === AST_NODE_TYPES32.Identifier && MEMO_CALLEES.has(current.callee.name) || current.callee.type === AST_NODE_TYPES32.MemberExpression && !current.callee.computed && current.callee.property.type === AST_NODE_TYPES32.Identifier && MEMO_CALLEES.has(current.callee.property.name))) {
|
|
6417
6644
|
return true;
|
|
6418
6645
|
}
|
|
6419
6646
|
current = current.parent ?? void 0;
|
|
@@ -6428,11 +6655,11 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6428
6655
|
if (parent === void 0) {
|
|
6429
6656
|
return confirmed;
|
|
6430
6657
|
}
|
|
6431
|
-
if (parent.type ===
|
|
6658
|
+
if (parent.type === AST_NODE_TYPES32.Property && parent.value === current || parent.type === AST_NODE_TYPES32.ObjectExpression || parent.type === AST_NODE_TYPES32.ArrayExpression) {
|
|
6432
6659
|
current = parent;
|
|
6433
6660
|
continue;
|
|
6434
6661
|
}
|
|
6435
|
-
if (parent.type ===
|
|
6662
|
+
if (parent.type === AST_NODE_TYPES32.CallExpression && parent.arguments.includes(current) && isSchemaComposition(parent)) {
|
|
6436
6663
|
current = schemaExpression(parent);
|
|
6437
6664
|
confirmed = current;
|
|
6438
6665
|
continue;
|
|
@@ -6442,7 +6669,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6442
6669
|
}
|
|
6443
6670
|
function isSchemaComposition(node) {
|
|
6444
6671
|
const { callee } = node;
|
|
6445
|
-
const isCombinator = callee.type ===
|
|
6672
|
+
const isCombinator = callee.type === AST_NODE_TYPES32.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES32.Identifier && ZOD_COMBINATOR_METHODS.has(callee.property.name);
|
|
6446
6673
|
return isCombinator || isZodCall(node);
|
|
6447
6674
|
}
|
|
6448
6675
|
function closesOverNothing(node, enclosing) {
|
|
@@ -6476,13 +6703,13 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6476
6703
|
}
|
|
6477
6704
|
function ownerName(enclosing) {
|
|
6478
6705
|
const parent = enclosing.parent ?? void 0;
|
|
6479
|
-
if (enclosing.type ===
|
|
6706
|
+
if (enclosing.type === AST_NODE_TYPES32.FunctionDeclaration && enclosing.id !== null) {
|
|
6480
6707
|
return enclosing.id.name;
|
|
6481
6708
|
}
|
|
6482
|
-
if (parent !== void 0 && parent.type ===
|
|
6709
|
+
if (parent !== void 0 && parent.type === AST_NODE_TYPES32.VariableDeclarator && parent.id.type === AST_NODE_TYPES32.Identifier) {
|
|
6483
6710
|
return parent.id.name;
|
|
6484
6711
|
}
|
|
6485
|
-
if (parent !== void 0 && (parent.type ===
|
|
6712
|
+
if (parent !== void 0 && (parent.type === AST_NODE_TYPES32.MethodDefinition || parent.type === AST_NODE_TYPES32.Property) && parent.key.type === AST_NODE_TYPES32.Identifier) {
|
|
6486
6713
|
return parent.key.name;
|
|
6487
6714
|
}
|
|
6488
6715
|
return "this function";
|
|
@@ -6493,7 +6720,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6493
6720
|
return;
|
|
6494
6721
|
}
|
|
6495
6722
|
for (const specifier of node.specifiers) {
|
|
6496
|
-
if (specifier.type ===
|
|
6723
|
+
if (specifier.type === AST_NODE_TYPES32.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES32.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES32.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES32.Identifier && specifier.imported.name === "z") {
|
|
6497
6724
|
zodNamespaces.add(specifier.local.name);
|
|
6498
6725
|
}
|
|
6499
6726
|
}
|
|
@@ -6503,7 +6730,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6503
6730
|
return;
|
|
6504
6731
|
}
|
|
6505
6732
|
const callee = node.callee;
|
|
6506
|
-
if (callee.property.type !==
|
|
6733
|
+
if (callee.property.type !== AST_NODE_TYPES32.Identifier) {
|
|
6507
6734
|
return;
|
|
6508
6735
|
}
|
|
6509
6736
|
const factory = callee.property.name;
|
|
@@ -6518,7 +6745,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6518
6745
|
return;
|
|
6519
6746
|
}
|
|
6520
6747
|
const shape = node.arguments[0];
|
|
6521
|
-
if (shape !== void 0 && shape.type ===
|
|
6748
|
+
if (shape !== void 0 && shape.type === AST_NODE_TYPES32.ObjectExpression && shape.properties.length < minProperties) {
|
|
6522
6749
|
return;
|
|
6523
6750
|
}
|
|
6524
6751
|
const expression = schemaExpression(node);
|
|
@@ -6546,20 +6773,20 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6546
6773
|
});
|
|
6547
6774
|
|
|
6548
6775
|
// src/rules/prefer-non-nullable-collection.ts
|
|
6549
|
-
import { AST_NODE_TYPES as
|
|
6776
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES33 } from "@typescript-eslint/utils";
|
|
6550
6777
|
var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
6551
6778
|
function propertyName(node) {
|
|
6552
6779
|
const key = node.key;
|
|
6553
|
-
if (key.type ===
|
|
6554
|
-
if (key.type ===
|
|
6780
|
+
if (key.type === AST_NODE_TYPES33.Identifier) return key.name;
|
|
6781
|
+
if (key.type === AST_NODE_TYPES33.Literal) return String(key.value);
|
|
6555
6782
|
return "collection";
|
|
6556
6783
|
}
|
|
6557
6784
|
function isArrayType(node) {
|
|
6558
|
-
if (node.type ===
|
|
6559
|
-
return node.type ===
|
|
6785
|
+
if (node.type === AST_NODE_TYPES33.TSArrayType) return true;
|
|
6786
|
+
return node.type === AST_NODE_TYPES33.TSTypeReference && node.typeName.type === AST_NODE_TYPES33.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
6560
6787
|
}
|
|
6561
6788
|
function isNullishType(node) {
|
|
6562
|
-
return node.type ===
|
|
6789
|
+
return node.type === AST_NODE_TYPES33.TSNullKeyword || node.type === AST_NODE_TYPES33.TSUndefinedKeyword;
|
|
6563
6790
|
}
|
|
6564
6791
|
function isNullableArrayOnly(node) {
|
|
6565
6792
|
const values = node.types.filter((member) => !isNullishType(member));
|
|
@@ -6586,7 +6813,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
6586
6813
|
function checkOptionalProperty(node) {
|
|
6587
6814
|
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
6588
6815
|
if (annotation === void 0) return;
|
|
6589
|
-
if (annotation.type !==
|
|
6816
|
+
if (annotation.type !== AST_NODE_TYPES33.TSUnionType || !isNullableArrayOnly(annotation)) {
|
|
6590
6817
|
return;
|
|
6591
6818
|
}
|
|
6592
6819
|
context.report({
|
|
@@ -6599,7 +6826,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
6599
6826
|
TSPropertySignature: checkOptionalProperty,
|
|
6600
6827
|
PropertyDefinition: checkOptionalProperty,
|
|
6601
6828
|
TSTypeAliasDeclaration(node) {
|
|
6602
|
-
if (node.typeAnnotation.type !==
|
|
6829
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES33.TSUnionType) return;
|
|
6603
6830
|
if (!isNullableArrayOnly(node.typeAnnotation)) return;
|
|
6604
6831
|
context.report({
|
|
6605
6832
|
node,
|
|
@@ -6612,13 +6839,13 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
6612
6839
|
});
|
|
6613
6840
|
|
|
6614
6841
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
6615
|
-
import { AST_NODE_TYPES as
|
|
6842
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES34 } from "@typescript-eslint/utils";
|
|
6616
6843
|
var unwrap4 = (node) => {
|
|
6617
6844
|
let current = node;
|
|
6618
6845
|
while (current !== null && current !== void 0) {
|
|
6619
|
-
if (current.type ===
|
|
6846
|
+
if (current.type === AST_NODE_TYPES34.TSAsExpression || current.type === AST_NODE_TYPES34.TSTypeAssertion || current.type === AST_NODE_TYPES34.TSNonNullExpression || current.type === AST_NODE_TYPES34.TSSatisfiesExpression) {
|
|
6620
6847
|
current = current.expression;
|
|
6621
|
-
} else if (current.type ===
|
|
6848
|
+
} else if (current.type === AST_NODE_TYPES34.ChainExpression) {
|
|
6622
6849
|
current = current.expression;
|
|
6623
6850
|
} else {
|
|
6624
6851
|
break;
|
|
@@ -6633,23 +6860,23 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
6633
6860
|
]);
|
|
6634
6861
|
var isSchemaParseReference = (node) => {
|
|
6635
6862
|
const inner = unwrap4(node);
|
|
6636
|
-
return inner !== null && inner.type ===
|
|
6863
|
+
return inner !== null && inner.type === AST_NODE_TYPES34.MemberExpression && !inner.computed && inner.property.type === AST_NODE_TYPES34.Identifier && (inner.property.name === "parse" || inner.property.name === "safeParse");
|
|
6637
6864
|
};
|
|
6638
6865
|
var isRawPayloadSource = (node) => {
|
|
6639
6866
|
let current = unwrap4(node);
|
|
6640
6867
|
if (current === null) return false;
|
|
6641
|
-
if (current.type ===
|
|
6868
|
+
if (current.type === AST_NODE_TYPES34.AwaitExpression) {
|
|
6642
6869
|
current = unwrap4(current.argument);
|
|
6643
6870
|
}
|
|
6644
|
-
if (current === null || current.type !==
|
|
6871
|
+
if (current === null || current.type !== AST_NODE_TYPES34.CallExpression) {
|
|
6645
6872
|
return false;
|
|
6646
6873
|
}
|
|
6647
6874
|
const callee = unwrap4(current.callee);
|
|
6648
|
-
if (callee === null || callee.type !==
|
|
6875
|
+
if (callee === null || callee.type !== AST_NODE_TYPES34.MemberExpression) {
|
|
6649
6876
|
return false;
|
|
6650
6877
|
}
|
|
6651
6878
|
const property = unwrap4(callee.property);
|
|
6652
|
-
if (property === null || property.type !==
|
|
6879
|
+
if (property === null || property.type !== AST_NODE_TYPES34.Identifier) {
|
|
6653
6880
|
return false;
|
|
6654
6881
|
}
|
|
6655
6882
|
if (property.name === "json") {
|
|
@@ -6659,7 +6886,7 @@ var isRawPayloadSource = (node) => {
|
|
|
6659
6886
|
return !current.arguments.some(isSchemaParseReference) && isRawPayloadSource(callee.object);
|
|
6660
6887
|
}
|
|
6661
6888
|
const object = unwrap4(callee.object);
|
|
6662
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
6889
|
+
return property.name === "parse" && object !== null && object.type === AST_NODE_TYPES34.Identifier && object.name === "JSON" && // ...but not `JSON.parse(readFileSync(p, "utf8"))` — see isLocalFileRead.
|
|
6663
6890
|
!isLocalFileRead(current.arguments[0]);
|
|
6664
6891
|
};
|
|
6665
6892
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
@@ -6667,9 +6894,9 @@ var isLocalFileRead = (node) => {
|
|
|
6667
6894
|
let found = false;
|
|
6668
6895
|
const visit = (current) => {
|
|
6669
6896
|
if (found || current === null || current === void 0) return;
|
|
6670
|
-
if (current.type ===
|
|
6897
|
+
if (current.type === AST_NODE_TYPES34.CallExpression) {
|
|
6671
6898
|
const callee = unwrap4(current.callee);
|
|
6672
|
-
const name = callee?.type ===
|
|
6899
|
+
const name = callee?.type === AST_NODE_TYPES34.Identifier ? callee.name : callee?.type === AST_NODE_TYPES34.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES34.Identifier ? callee.property.name : null;
|
|
6673
6900
|
if (name !== null && FILE_READ_RE.test(name)) {
|
|
6674
6901
|
found = true;
|
|
6675
6902
|
return;
|
|
@@ -6691,15 +6918,15 @@ var isLocalFileRead = (node) => {
|
|
|
6691
6918
|
var ASSERTION_CALLEE_RE = /^(expect|assert|should|invariant)$/;
|
|
6692
6919
|
var isInsideAssertion = (node) => {
|
|
6693
6920
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
6694
|
-
if (current.type !==
|
|
6921
|
+
if (current.type !== AST_NODE_TYPES34.CallExpression) continue;
|
|
6695
6922
|
let callee = current.callee;
|
|
6696
|
-
while (callee.type ===
|
|
6923
|
+
while (callee.type === AST_NODE_TYPES34.MemberExpression) {
|
|
6697
6924
|
callee = callee.object;
|
|
6698
6925
|
}
|
|
6699
|
-
if (callee.type ===
|
|
6926
|
+
if (callee.type === AST_NODE_TYPES34.CallExpression) {
|
|
6700
6927
|
callee = callee.callee;
|
|
6701
6928
|
}
|
|
6702
|
-
if (callee.type ===
|
|
6929
|
+
if (callee.type === AST_NODE_TYPES34.Identifier && ASSERTION_CALLEE_RE.test(callee.name)) {
|
|
6703
6930
|
return true;
|
|
6704
6931
|
}
|
|
6705
6932
|
}
|
|
@@ -6718,39 +6945,39 @@ var GUARD_NAME_RE = /^(?:is|validate|parse|assert|decode|coerce)[A-Z]/;
|
|
|
6718
6945
|
var isValidationRead = (node) => {
|
|
6719
6946
|
let current = node;
|
|
6720
6947
|
let parent = current.parent;
|
|
6721
|
-
while (parent !== null && parent !== void 0 && (parent.type ===
|
|
6948
|
+
while (parent !== null && parent !== void 0 && (parent.type === AST_NODE_TYPES34.TSAsExpression || parent.type === AST_NODE_TYPES34.TSTypeAssertion || parent.type === AST_NODE_TYPES34.TSNonNullExpression || parent.type === AST_NODE_TYPES34.TSSatisfiesExpression || parent.type === AST_NODE_TYPES34.ChainExpression)) {
|
|
6722
6949
|
current = parent;
|
|
6723
6950
|
parent = parent.parent;
|
|
6724
6951
|
}
|
|
6725
6952
|
if (parent === null || parent === void 0) return false;
|
|
6726
|
-
if (parent.type ===
|
|
6953
|
+
if (parent.type === AST_NODE_TYPES34.UnaryExpression && parent.operator === "typeof" && parent.argument === current) {
|
|
6727
6954
|
return true;
|
|
6728
6955
|
}
|
|
6729
|
-
if (parent.type !==
|
|
6956
|
+
if (parent.type !== AST_NODE_TYPES34.CallExpression || !parent.arguments.some((arg) => arg === current)) {
|
|
6730
6957
|
return false;
|
|
6731
6958
|
}
|
|
6732
6959
|
const callee = parent.callee;
|
|
6733
|
-
if (callee.type ===
|
|
6960
|
+
if (callee.type === AST_NODE_TYPES34.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES34.Identifier && callee.object.name === "Array" && callee.property.type === AST_NODE_TYPES34.Identifier && callee.property.name === "isArray") {
|
|
6734
6961
|
return parent.arguments.length === 1;
|
|
6735
6962
|
}
|
|
6736
|
-
return callee.type ===
|
|
6963
|
+
return callee.type === AST_NODE_TYPES34.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
6737
6964
|
};
|
|
6738
6965
|
var isGuardTestPosition = (node) => {
|
|
6739
6966
|
let current = node;
|
|
6740
6967
|
let parent = current.parent;
|
|
6741
6968
|
while (parent !== void 0 && parent !== null) {
|
|
6742
6969
|
switch (parent.type) {
|
|
6743
|
-
case
|
|
6744
|
-
case
|
|
6745
|
-
case
|
|
6970
|
+
case AST_NODE_TYPES34.UnaryExpression:
|
|
6971
|
+
case AST_NODE_TYPES34.LogicalExpression:
|
|
6972
|
+
case AST_NODE_TYPES34.ChainExpression:
|
|
6746
6973
|
current = parent;
|
|
6747
6974
|
parent = parent.parent;
|
|
6748
6975
|
continue;
|
|
6749
|
-
case
|
|
6750
|
-
case
|
|
6751
|
-
case
|
|
6752
|
-
case
|
|
6753
|
-
case
|
|
6976
|
+
case AST_NODE_TYPES34.IfStatement:
|
|
6977
|
+
case AST_NODE_TYPES34.ConditionalExpression:
|
|
6978
|
+
case AST_NODE_TYPES34.WhileStatement:
|
|
6979
|
+
case AST_NODE_TYPES34.DoWhileStatement:
|
|
6980
|
+
case AST_NODE_TYPES34.ForStatement:
|
|
6754
6981
|
return parent.test === current;
|
|
6755
6982
|
default:
|
|
6756
6983
|
return false;
|
|
@@ -6760,7 +6987,7 @@ var isGuardTestPosition = (node) => {
|
|
|
6760
6987
|
};
|
|
6761
6988
|
var isUnvalidatedVariableRef = (node, scope, tracked) => {
|
|
6762
6989
|
const unwrapped = unwrap4(node);
|
|
6763
|
-
if (unwrapped === null || unwrapped.type !==
|
|
6990
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES34.Identifier) {
|
|
6764
6991
|
return false;
|
|
6765
6992
|
}
|
|
6766
6993
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -6803,11 +7030,11 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6803
7030
|
return {
|
|
6804
7031
|
VariableDeclarator(node) {
|
|
6805
7032
|
const scope = context.sourceCode.getScope(node);
|
|
6806
|
-
if (node.id.type ===
|
|
7033
|
+
if (node.id.type === AST_NODE_TYPES34.Identifier) {
|
|
6807
7034
|
trackInitializer(node);
|
|
6808
7035
|
return;
|
|
6809
7036
|
}
|
|
6810
|
-
if (node.id.type ===
|
|
7037
|
+
if (node.id.type === AST_NODE_TYPES34.ObjectPattern || node.id.type === AST_NODE_TYPES34.ArrayPattern) {
|
|
6811
7038
|
if (isRawPayloadSource(node.init)) {
|
|
6812
7039
|
if (!isFullyNarrowedPattern(node)) {
|
|
6813
7040
|
context.report({ node: node.id, messageId: "unparsedJsonAccess" });
|
|
@@ -6821,7 +7048,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6821
7048
|
},
|
|
6822
7049
|
AssignmentExpression(node) {
|
|
6823
7050
|
const scope = context.sourceCode.getScope(node);
|
|
6824
|
-
if (node.left.type ===
|
|
7051
|
+
if (node.left.type === AST_NODE_TYPES34.Identifier) {
|
|
6825
7052
|
const variable = findVariable2(scope, node.left.name);
|
|
6826
7053
|
if (variable === null) return;
|
|
6827
7054
|
if (isRawPayloadSource(node.right)) {
|
|
@@ -6831,7 +7058,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6831
7058
|
}
|
|
6832
7059
|
return;
|
|
6833
7060
|
}
|
|
6834
|
-
if (node.left.type ===
|
|
7061
|
+
if (node.left.type === AST_NODE_TYPES34.ObjectPattern || node.left.type === AST_NODE_TYPES34.ArrayPattern) {
|
|
6835
7062
|
if (isRawPayloadSource(node.right)) {
|
|
6836
7063
|
context.report({
|
|
6837
7064
|
node: node.left,
|
|
@@ -6848,15 +7075,15 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6848
7075
|
}
|
|
6849
7076
|
},
|
|
6850
7077
|
CallExpression(node) {
|
|
6851
|
-
if (node.callee.type !==
|
|
7078
|
+
if (node.callee.type !== AST_NODE_TYPES34.Identifier) return;
|
|
6852
7079
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
6853
7080
|
return;
|
|
6854
7081
|
}
|
|
6855
7082
|
const scope = context.sourceCode.getScope(node);
|
|
6856
7083
|
for (const arg of node.arguments) {
|
|
6857
|
-
if (arg.type ===
|
|
7084
|
+
if (arg.type === AST_NODE_TYPES34.SpreadElement) continue;
|
|
6858
7085
|
const unwrapped = unwrap4(arg);
|
|
6859
|
-
if (unwrapped === null || unwrapped.type !==
|
|
7086
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES34.Identifier) {
|
|
6860
7087
|
continue;
|
|
6861
7088
|
}
|
|
6862
7089
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -6870,13 +7097,13 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6870
7097
|
const obj = unwrap4(node.object);
|
|
6871
7098
|
if (isRawPayloadSource(obj)) {
|
|
6872
7099
|
const parent = node.parent;
|
|
6873
|
-
if (parent.type ===
|
|
7100
|
+
if (parent.type === AST_NODE_TYPES34.CallExpression && parent.callee === node && node.property.type === AST_NODE_TYPES34.Identifier && (node.property.name === "parse" || node.property.name === "safeParse" || PROMISE_CHAIN_METHODS.has(node.property.name))) {
|
|
6874
7101
|
return;
|
|
6875
7102
|
}
|
|
6876
7103
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
6877
7104
|
return;
|
|
6878
7105
|
}
|
|
6879
|
-
if (obj !== null && obj.type ===
|
|
7106
|
+
if (obj !== null && obj.type === AST_NODE_TYPES34.Identifier && isUnvalidatedVariableRef(obj, scope, unvalidatedVariables)) {
|
|
6880
7107
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
6881
7108
|
const variable = findVariable2(scope, obj.name);
|
|
6882
7109
|
if (variable !== null) {
|
|
@@ -6889,7 +7116,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6889
7116
|
});
|
|
6890
7117
|
|
|
6891
7118
|
// src/rules/prefer-semantic-colors.ts
|
|
6892
|
-
import { AST_NODE_TYPES as
|
|
7119
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES35 } from "@typescript-eslint/utils";
|
|
6893
7120
|
import { existsSync, readdirSync, readFileSync } from "fs";
|
|
6894
7121
|
import { dirname, join, parse } from "path";
|
|
6895
7122
|
|
|
@@ -6989,8 +7216,8 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
6989
7216
|
]);
|
|
6990
7217
|
function jsxElementName(node) {
|
|
6991
7218
|
const name = node.openingElement.name;
|
|
6992
|
-
if (name.type ===
|
|
6993
|
-
if (name.type ===
|
|
7219
|
+
if (name.type === AST_NODE_TYPES35.JSXIdentifier) return name.name;
|
|
7220
|
+
if (name.type === AST_NODE_TYPES35.JSXMemberExpression && name.property.type === AST_NODE_TYPES35.JSXIdentifier) {
|
|
6994
7221
|
return name.property.name;
|
|
6995
7222
|
}
|
|
6996
7223
|
return null;
|
|
@@ -7016,7 +7243,7 @@ var EMAIL_OR_PDF_IMPORT_RE = /@react-(?:email|pdf)\//;
|
|
|
7016
7243
|
var isInsideSvg = (node) => {
|
|
7017
7244
|
let current = node.parent;
|
|
7018
7245
|
while (current !== void 0 && current !== null) {
|
|
7019
|
-
if (current.type ===
|
|
7246
|
+
if (current.type === AST_NODE_TYPES35.JSXElement) {
|
|
7020
7247
|
const name = jsxElementName(current);
|
|
7021
7248
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
7022
7249
|
}
|
|
@@ -7027,7 +7254,7 @@ var isInsideSvg = (node) => {
|
|
|
7027
7254
|
var isInsideIconFactoryPath = (node) => {
|
|
7028
7255
|
let current = node.parent;
|
|
7029
7256
|
while (current !== void 0 && current !== null) {
|
|
7030
|
-
if (current.type ===
|
|
7257
|
+
if (current.type === AST_NODE_TYPES35.Property && propName(current.key) === "path" && current.parent.type === AST_NODE_TYPES35.ObjectExpression && current.parent.parent.type === AST_NODE_TYPES35.CallExpression && current.parent.parent.callee.type === AST_NODE_TYPES35.Identifier && current.parent.parent.callee.name === "createIcon") {
|
|
7031
7258
|
return true;
|
|
7032
7259
|
}
|
|
7033
7260
|
current = current.parent;
|
|
@@ -7164,8 +7391,8 @@ var hasSemanticTokenSystem = (filename) => {
|
|
|
7164
7391
|
return root !== null && workspaceHasMarker(root);
|
|
7165
7392
|
};
|
|
7166
7393
|
var propName = (key) => {
|
|
7167
|
-
if (key.type ===
|
|
7168
|
-
if (key.type ===
|
|
7394
|
+
if (key.type === AST_NODE_TYPES35.Identifier) return key.name;
|
|
7395
|
+
if (key.type === AST_NODE_TYPES35.Literal && typeof key.value === "string") return key.value;
|
|
7169
7396
|
return null;
|
|
7170
7397
|
};
|
|
7171
7398
|
var prefer_semantic_colors_default = createRule({
|
|
@@ -7210,27 +7437,27 @@ var prefer_semantic_colors_default = createRule({
|
|
|
7210
7437
|
const checkClassNode = (node) => {
|
|
7211
7438
|
if (node === null) return;
|
|
7212
7439
|
switch (node.type) {
|
|
7213
|
-
case
|
|
7440
|
+
case AST_NODE_TYPES35.Literal:
|
|
7214
7441
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
7215
7442
|
break;
|
|
7216
|
-
case
|
|
7443
|
+
case AST_NODE_TYPES35.TemplateLiteral:
|
|
7217
7444
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
7218
7445
|
break;
|
|
7219
|
-
case
|
|
7446
|
+
case AST_NODE_TYPES35.ArrayExpression:
|
|
7220
7447
|
for (const element of node.elements) {
|
|
7221
|
-
if (element !== null && element.type !==
|
|
7448
|
+
if (element !== null && element.type !== AST_NODE_TYPES35.SpreadElement) checkClassNode(element);
|
|
7222
7449
|
}
|
|
7223
7450
|
break;
|
|
7224
|
-
case
|
|
7451
|
+
case AST_NODE_TYPES35.ObjectExpression:
|
|
7225
7452
|
for (const property of node.properties) {
|
|
7226
|
-
if (property.type ===
|
|
7453
|
+
if (property.type === AST_NODE_TYPES35.Property) checkClassNode(property.value);
|
|
7227
7454
|
}
|
|
7228
7455
|
break;
|
|
7229
|
-
case
|
|
7456
|
+
case AST_NODE_TYPES35.ConditionalExpression:
|
|
7230
7457
|
checkClassNode(node.consequent);
|
|
7231
7458
|
checkClassNode(node.alternate);
|
|
7232
7459
|
break;
|
|
7233
|
-
case
|
|
7460
|
+
case AST_NODE_TYPES35.LogicalExpression:
|
|
7234
7461
|
checkClassNode(node.right);
|
|
7235
7462
|
break;
|
|
7236
7463
|
default:
|
|
@@ -7238,29 +7465,29 @@ var prefer_semantic_colors_default = createRule({
|
|
|
7238
7465
|
}
|
|
7239
7466
|
};
|
|
7240
7467
|
const checkColorValueNode = (node) => {
|
|
7241
|
-
if (node.type ===
|
|
7468
|
+
if (node.type === AST_NODE_TYPES35.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value) && !CSS_VAR_REFERENCE_RE.test(node.value)) {
|
|
7242
7469
|
context.report({ node, messageId: "inlineColor", data: { value: node.value } });
|
|
7243
7470
|
}
|
|
7244
7471
|
};
|
|
7245
7472
|
return {
|
|
7246
7473
|
"JSXAttribute[name.name='className']"(node) {
|
|
7247
7474
|
if (node.value === null) return;
|
|
7248
|
-
if (node.value.type ===
|
|
7249
|
-
else if (node.value.type ===
|
|
7250
|
-
if (node.value.expression.type !==
|
|
7475
|
+
if (node.value.type === AST_NODE_TYPES35.Literal) checkClassNode(node.value);
|
|
7476
|
+
else if (node.value.type === AST_NODE_TYPES35.JSXExpressionContainer) {
|
|
7477
|
+
if (node.value.expression.type !== AST_NODE_TYPES35.JSXEmptyExpression) {
|
|
7251
7478
|
checkClassNode(node.value.expression);
|
|
7252
7479
|
}
|
|
7253
7480
|
}
|
|
7254
7481
|
},
|
|
7255
7482
|
CallExpression(node) {
|
|
7256
|
-
if (node.callee.type ===
|
|
7483
|
+
if (node.callee.type === AST_NODE_TYPES35.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
7257
7484
|
for (const arg of node.arguments) {
|
|
7258
|
-
if (arg.type !==
|
|
7485
|
+
if (arg.type !== AST_NODE_TYPES35.SpreadElement) checkClassNode(arg);
|
|
7259
7486
|
}
|
|
7260
7487
|
}
|
|
7261
7488
|
},
|
|
7262
7489
|
VariableDeclarator(node) {
|
|
7263
|
-
if (node.id.type ===
|
|
7490
|
+
if (node.id.type === AST_NODE_TYPES35.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
7264
7491
|
checkClassNode(node.init);
|
|
7265
7492
|
}
|
|
7266
7493
|
},
|
|
@@ -7272,9 +7499,9 @@ var prefer_semantic_colors_default = createRule({
|
|
|
7272
7499
|
// Neutral drawing literals and anything inside an SVG defs container are
|
|
7273
7500
|
// structural, not UI tokens, so they never fire.
|
|
7274
7501
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
7275
|
-
if (node.value?.type !==
|
|
7502
|
+
if (node.value?.type !== AST_NODE_TYPES35.Literal) return;
|
|
7276
7503
|
const owner = node.parent.name;
|
|
7277
|
-
if (owner.type ===
|
|
7504
|
+
if (owner.type === AST_NODE_TYPES35.JSXIdentifier && SVG_SHAPE_PRIMITIVES.has(owner.name)) {
|
|
7278
7505
|
return;
|
|
7279
7506
|
}
|
|
7280
7507
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
@@ -7447,7 +7674,7 @@ var prefer_server_actions_default = createRule({
|
|
|
7447
7674
|
// src/rules/prefer-string-literal-union.ts
|
|
7448
7675
|
import {
|
|
7449
7676
|
ESLintUtils as ESLintUtils3,
|
|
7450
|
-
AST_NODE_TYPES as
|
|
7677
|
+
AST_NODE_TYPES as AST_NODE_TYPES36
|
|
7451
7678
|
} from "@typescript-eslint/utils";
|
|
7452
7679
|
import * as ts2 from "typescript";
|
|
7453
7680
|
var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
@@ -7491,19 +7718,19 @@ function isChoiceLikeName(name) {
|
|
|
7491
7718
|
return CHOICE_TOKENS.has(lastWord(name));
|
|
7492
7719
|
}
|
|
7493
7720
|
function keyName(key) {
|
|
7494
|
-
if (key.type ===
|
|
7721
|
+
if (key.type === AST_NODE_TYPES36.Identifier) {
|
|
7495
7722
|
return key.name;
|
|
7496
7723
|
}
|
|
7497
|
-
if (key.type ===
|
|
7724
|
+
if (key.type === AST_NODE_TYPES36.Literal && typeof key.value === "string") {
|
|
7498
7725
|
return key.value;
|
|
7499
7726
|
}
|
|
7500
7727
|
return null;
|
|
7501
7728
|
}
|
|
7502
7729
|
function isStringLiteralMember(t) {
|
|
7503
|
-
return t.type ===
|
|
7730
|
+
return t.type === AST_NODE_TYPES36.TSLiteralType && t.literal.type === AST_NODE_TYPES36.Literal && typeof t.literal.value === "string";
|
|
7504
7731
|
}
|
|
7505
7732
|
function isStringLiteralUnion(node) {
|
|
7506
|
-
if (node?.type !==
|
|
7733
|
+
if (node?.type !== AST_NODE_TYPES36.TSUnionType) {
|
|
7507
7734
|
return false;
|
|
7508
7735
|
}
|
|
7509
7736
|
return node.types.filter(isStringLiteralMember).length >= MIN_CLUSTER_SIZE;
|
|
@@ -7532,12 +7759,12 @@ function bindingSourceExpression(decl) {
|
|
|
7532
7759
|
return ts2.isForOfStatement(node) ? node.expression : node.initializer;
|
|
7533
7760
|
}
|
|
7534
7761
|
function refKey(node) {
|
|
7535
|
-
if (node.type ===
|
|
7762
|
+
if (node.type === AST_NODE_TYPES36.Identifier) {
|
|
7536
7763
|
return node.name;
|
|
7537
7764
|
}
|
|
7538
|
-
if (node.type ===
|
|
7765
|
+
if (node.type === AST_NODE_TYPES36.MemberExpression && !node.computed) {
|
|
7539
7766
|
const inner = refKey(node.object);
|
|
7540
|
-
if (inner === null || node.property.type !==
|
|
7767
|
+
if (inner === null || node.property.type !== AST_NODE_TYPES36.Identifier) {
|
|
7541
7768
|
return null;
|
|
7542
7769
|
}
|
|
7543
7770
|
return `${inner}.${node.property.name}`;
|
|
@@ -7545,7 +7772,7 @@ function refKey(node) {
|
|
|
7545
7772
|
return null;
|
|
7546
7773
|
}
|
|
7547
7774
|
function strLiteral(node) {
|
|
7548
|
-
if (node.type ===
|
|
7775
|
+
if (node.type === AST_NODE_TYPES36.Literal && typeof node.value === "string") {
|
|
7549
7776
|
return node.value;
|
|
7550
7777
|
}
|
|
7551
7778
|
return null;
|
|
@@ -7698,7 +7925,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
7698
7925
|
containersWithUnion.add(container);
|
|
7699
7926
|
return;
|
|
7700
7927
|
}
|
|
7701
|
-
if (typeNode?.type !==
|
|
7928
|
+
if (typeNode?.type !== AST_NODE_TYPES36.TSStringKeyword) {
|
|
7702
7929
|
return;
|
|
7703
7930
|
}
|
|
7704
7931
|
const name = keyName(key);
|
|
@@ -7786,10 +8013,10 @@ var prefer_string_literal_union_default = createRule({
|
|
|
7786
8013
|
}
|
|
7787
8014
|
};
|
|
7788
8015
|
function refKeyText(node) {
|
|
7789
|
-
if (node.type ===
|
|
8016
|
+
if (node.type === AST_NODE_TYPES36.BinaryExpression) {
|
|
7790
8017
|
return refKey(node.left) ?? refKey(node.right) ?? "value";
|
|
7791
8018
|
}
|
|
7792
|
-
if (node.type ===
|
|
8019
|
+
if (node.type === AST_NODE_TYPES36.SwitchStatement) {
|
|
7793
8020
|
return refKey(node.discriminant) ?? "value";
|
|
7794
8021
|
}
|
|
7795
8022
|
return "value";
|
|
@@ -7798,7 +8025,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
7798
8025
|
});
|
|
7799
8026
|
|
|
7800
8027
|
// src/rules/prefer-whole-object-assertion.ts
|
|
7801
|
-
import { AST_NODE_TYPES as
|
|
8028
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES37 } from "@typescript-eslint/utils";
|
|
7802
8029
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
7803
8030
|
var ARRAY_MATCHERS = /* @__PURE__ */ new Set(["toEqual", "toStrictEqual"]);
|
|
7804
8031
|
var COLLECTION_PROPERTIES = /* @__PURE__ */ new Set(["length", "size"]);
|
|
@@ -7807,11 +8034,11 @@ var NUMERIC_SIGNS2 = /* @__PURE__ */ new Set(["-", "+"]);
|
|
|
7807
8034
|
var MIN_RUN_LENGTH = 2;
|
|
7808
8035
|
function literalText(node, getText) {
|
|
7809
8036
|
switch (node.type) {
|
|
7810
|
-
case
|
|
8037
|
+
case AST_NODE_TYPES37.Literal:
|
|
7811
8038
|
return "regex" in node ? null : getText(node);
|
|
7812
|
-
case
|
|
8039
|
+
case AST_NODE_TYPES37.TemplateLiteral:
|
|
7813
8040
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
7814
|
-
case
|
|
8041
|
+
case AST_NODE_TYPES37.UnaryExpression:
|
|
7815
8042
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
7816
8043
|
default:
|
|
7817
8044
|
return null;
|
|
@@ -7819,15 +8046,15 @@ function literalText(node, getText) {
|
|
|
7819
8046
|
}
|
|
7820
8047
|
function isPureReceiver(node) {
|
|
7821
8048
|
switch (node.type) {
|
|
7822
|
-
case
|
|
7823
|
-
case
|
|
8049
|
+
case AST_NODE_TYPES37.Identifier:
|
|
8050
|
+
case AST_NODE_TYPES37.ThisExpression:
|
|
7824
8051
|
return true;
|
|
7825
|
-
case
|
|
8052
|
+
case AST_NODE_TYPES37.MemberExpression:
|
|
7826
8053
|
if (node.optional) {
|
|
7827
8054
|
return false;
|
|
7828
8055
|
}
|
|
7829
8056
|
if (node.computed) {
|
|
7830
|
-
return node.property.type ===
|
|
8057
|
+
return node.property.type === AST_NODE_TYPES37.Literal && isPureReceiver(node.object);
|
|
7831
8058
|
}
|
|
7832
8059
|
return isPureReceiver(node.object);
|
|
7833
8060
|
default:
|
|
@@ -7835,7 +8062,7 @@ function isPureReceiver(node) {
|
|
|
7835
8062
|
}
|
|
7836
8063
|
}
|
|
7837
8064
|
function literalIndex(node) {
|
|
7838
|
-
if (node.type !==
|
|
8065
|
+
if (node.type !== AST_NODE_TYPES37.Literal || typeof node.value !== "number") {
|
|
7839
8066
|
return null;
|
|
7840
8067
|
}
|
|
7841
8068
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
@@ -7861,24 +8088,24 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
7861
8088
|
}
|
|
7862
8089
|
const { sourceCode } = context;
|
|
7863
8090
|
function parseAssertion(statement) {
|
|
7864
|
-
if (statement.type !==
|
|
8091
|
+
if (statement.type !== AST_NODE_TYPES37.ExpressionStatement) {
|
|
7865
8092
|
return null;
|
|
7866
8093
|
}
|
|
7867
8094
|
const call = statement.expression;
|
|
7868
|
-
if (call.type !==
|
|
8095
|
+
if (call.type !== AST_NODE_TYPES37.CallExpression) {
|
|
7869
8096
|
return null;
|
|
7870
8097
|
}
|
|
7871
8098
|
const callee = call.callee;
|
|
7872
|
-
if (callee.type !==
|
|
8099
|
+
if (callee.type !== AST_NODE_TYPES37.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES37.Identifier) {
|
|
7873
8100
|
return null;
|
|
7874
8101
|
}
|
|
7875
8102
|
const matcher = callee.property.name;
|
|
7876
8103
|
const expectCall = callee.object;
|
|
7877
|
-
if (expectCall.type !==
|
|
8104
|
+
if (expectCall.type !== AST_NODE_TYPES37.CallExpression || expectCall.callee.type !== AST_NODE_TYPES37.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
7878
8105
|
return null;
|
|
7879
8106
|
}
|
|
7880
8107
|
const actual = expectCall.arguments[0];
|
|
7881
|
-
if (actual === void 0 || actual.type !==
|
|
8108
|
+
if (actual === void 0 || actual.type !== AST_NODE_TYPES37.MemberExpression || actual.optional) {
|
|
7882
8109
|
return null;
|
|
7883
8110
|
}
|
|
7884
8111
|
if (!isPureReceiver(actual.object)) {
|
|
@@ -7892,7 +8119,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
7892
8119
|
}
|
|
7893
8120
|
key = { kind: "index", index };
|
|
7894
8121
|
} else {
|
|
7895
|
-
if (actual.property.type !==
|
|
8122
|
+
if (actual.property.type !== AST_NODE_TYPES37.Identifier || COLLECTION_PROPERTIES.has(actual.property.name) || LITERAL_KEY_HAZARDS.has(actual.property.name)) {
|
|
7896
8123
|
return null;
|
|
7897
8124
|
}
|
|
7898
8125
|
key = { kind: "property", name: actual.property.name };
|
|
@@ -7904,7 +8131,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
7904
8131
|
return null;
|
|
7905
8132
|
}
|
|
7906
8133
|
const expected = call.arguments[0];
|
|
7907
|
-
if (call.arguments.length !== 1 || expected === void 0 || expected.type ===
|
|
8134
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === AST_NODE_TYPES37.SpreadElement) {
|
|
7908
8135
|
return null;
|
|
7909
8136
|
}
|
|
7910
8137
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
@@ -8019,7 +8246,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8019
8246
|
});
|
|
8020
8247
|
|
|
8021
8248
|
// src/rules/prefer-zod-enum.ts
|
|
8022
|
-
import { AST_NODE_TYPES as
|
|
8249
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES38 } from "@typescript-eslint/utils";
|
|
8023
8250
|
var prefer_zod_enum_default = createRule({
|
|
8024
8251
|
name: "prefer-zod-enum",
|
|
8025
8252
|
meta: {
|
|
@@ -8039,20 +8266,20 @@ var prefer_zod_enum_default = createRule({
|
|
|
8039
8266
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
8040
8267
|
function enumValues(node) {
|
|
8041
8268
|
const callee = node.callee;
|
|
8042
|
-
if (callee.type !==
|
|
8269
|
+
if (callee.type !== AST_NODE_TYPES38.MemberExpression || callee.computed || callee.object.type !== AST_NODE_TYPES38.Identifier || !zodNamespaces.has(callee.object.name) || callee.property.type !== AST_NODE_TYPES38.Identifier || callee.property.name !== "union" || node.arguments.length !== 1) {
|
|
8043
8270
|
return null;
|
|
8044
8271
|
}
|
|
8045
8272
|
const argument = node.arguments[0];
|
|
8046
|
-
if (argument === void 0 || argument.type !==
|
|
8273
|
+
if (argument === void 0 || argument.type !== AST_NODE_TYPES38.ArrayExpression || argument.elements.length === 0) {
|
|
8047
8274
|
return null;
|
|
8048
8275
|
}
|
|
8049
8276
|
const values = [];
|
|
8050
8277
|
for (const element of argument.elements) {
|
|
8051
|
-
if (element === null || element.type !==
|
|
8278
|
+
if (element === null || element.type !== AST_NODE_TYPES38.CallExpression || element.arguments.length !== 1 || element.callee.type !== AST_NODE_TYPES38.MemberExpression || element.callee.computed || element.callee.object.type !== AST_NODE_TYPES38.Identifier || !zodNamespaces.has(element.callee.object.name) || element.callee.property.type !== AST_NODE_TYPES38.Identifier || element.callee.property.name !== "literal") {
|
|
8052
8279
|
return null;
|
|
8053
8280
|
}
|
|
8054
8281
|
const value = element.arguments[0];
|
|
8055
|
-
if (value === void 0 || value.type !==
|
|
8282
|
+
if (value === void 0 || value.type !== AST_NODE_TYPES38.Literal || typeof value.value !== "string") {
|
|
8056
8283
|
return null;
|
|
8057
8284
|
}
|
|
8058
8285
|
values.push(value);
|
|
@@ -8061,11 +8288,11 @@ var prefer_zod_enum_default = createRule({
|
|
|
8061
8288
|
}
|
|
8062
8289
|
function buildFix(node, values) {
|
|
8063
8290
|
const argument = node.arguments[0];
|
|
8064
|
-
if (argument === void 0 || argument.type !==
|
|
8291
|
+
if (argument === void 0 || argument.type !== AST_NODE_TYPES38.ArrayExpression || sourceCode.getCommentsInside(argument).length > 0) {
|
|
8065
8292
|
return void 0;
|
|
8066
8293
|
}
|
|
8067
8294
|
const callee = node.callee;
|
|
8068
|
-
if (callee.type !==
|
|
8295
|
+
if (callee.type !== AST_NODE_TYPES38.MemberExpression || callee.property.type !== AST_NODE_TYPES38.Identifier) {
|
|
8069
8296
|
return void 0;
|
|
8070
8297
|
}
|
|
8071
8298
|
return (fixer) => [
|
|
@@ -8082,7 +8309,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
8082
8309
|
return;
|
|
8083
8310
|
}
|
|
8084
8311
|
for (const specifier of node.specifiers) {
|
|
8085
|
-
if (specifier.type ===
|
|
8312
|
+
if (specifier.type === AST_NODE_TYPES38.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES38.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES38.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES38.Identifier && specifier.imported.name === "z") {
|
|
8086
8313
|
zodNamespaces.add(specifier.local.name);
|
|
8087
8314
|
}
|
|
8088
8315
|
}
|
|
@@ -8104,7 +8331,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
8104
8331
|
});
|
|
8105
8332
|
|
|
8106
8333
|
// src/rules/prefer-zod-infer.ts
|
|
8107
|
-
import { AST_NODE_TYPES as
|
|
8334
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES39 } from "@typescript-eslint/utils";
|
|
8108
8335
|
var SHAPE_PRESERVING_METHODS = /* @__PURE__ */ new Set([
|
|
8109
8336
|
"describe",
|
|
8110
8337
|
"refine",
|
|
@@ -8141,44 +8368,44 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
8141
8368
|
"Schema"
|
|
8142
8369
|
]);
|
|
8143
8370
|
var LEAF_NODE_TYPES = {
|
|
8144
|
-
string: [
|
|
8145
|
-
email: [
|
|
8146
|
-
url: [
|
|
8147
|
-
uuid: [
|
|
8148
|
-
ulid: [
|
|
8149
|
-
cuid: [
|
|
8150
|
-
cuid2: [
|
|
8151
|
-
nanoid: [
|
|
8152
|
-
iso: [
|
|
8153
|
-
number: [
|
|
8154
|
-
int: [
|
|
8155
|
-
float32: [
|
|
8156
|
-
float64: [
|
|
8157
|
-
boolean: [
|
|
8158
|
-
bigint: [
|
|
8159
|
-
symbol: [
|
|
8160
|
-
any: [
|
|
8161
|
-
unknown: [
|
|
8162
|
-
never: [
|
|
8163
|
-
void: [
|
|
8164
|
-
null: [
|
|
8165
|
-
undefined: [
|
|
8166
|
-
literal: [
|
|
8167
|
-
date: [
|
|
8168
|
-
array: [
|
|
8169
|
-
tuple: [
|
|
8170
|
-
object: [
|
|
8171
|
-
strictObject: [
|
|
8172
|
-
looseObject: [
|
|
8173
|
-
record: [
|
|
8174
|
-
map: [
|
|
8175
|
-
set: [
|
|
8176
|
-
promise: [
|
|
8177
|
-
enum: [
|
|
8178
|
-
nativeEnum: [
|
|
8179
|
-
union: [
|
|
8180
|
-
discriminatedUnion: [
|
|
8181
|
-
intersection: [
|
|
8371
|
+
string: [AST_NODE_TYPES39.TSStringKeyword],
|
|
8372
|
+
email: [AST_NODE_TYPES39.TSStringKeyword],
|
|
8373
|
+
url: [AST_NODE_TYPES39.TSStringKeyword],
|
|
8374
|
+
uuid: [AST_NODE_TYPES39.TSStringKeyword],
|
|
8375
|
+
ulid: [AST_NODE_TYPES39.TSStringKeyword],
|
|
8376
|
+
cuid: [AST_NODE_TYPES39.TSStringKeyword],
|
|
8377
|
+
cuid2: [AST_NODE_TYPES39.TSStringKeyword],
|
|
8378
|
+
nanoid: [AST_NODE_TYPES39.TSStringKeyword],
|
|
8379
|
+
iso: [AST_NODE_TYPES39.TSStringKeyword],
|
|
8380
|
+
number: [AST_NODE_TYPES39.TSNumberKeyword],
|
|
8381
|
+
int: [AST_NODE_TYPES39.TSNumberKeyword],
|
|
8382
|
+
float32: [AST_NODE_TYPES39.TSNumberKeyword],
|
|
8383
|
+
float64: [AST_NODE_TYPES39.TSNumberKeyword],
|
|
8384
|
+
boolean: [AST_NODE_TYPES39.TSBooleanKeyword],
|
|
8385
|
+
bigint: [AST_NODE_TYPES39.TSBigIntKeyword],
|
|
8386
|
+
symbol: [AST_NODE_TYPES39.TSSymbolKeyword],
|
|
8387
|
+
any: [AST_NODE_TYPES39.TSAnyKeyword],
|
|
8388
|
+
unknown: [AST_NODE_TYPES39.TSUnknownKeyword],
|
|
8389
|
+
never: [AST_NODE_TYPES39.TSNeverKeyword],
|
|
8390
|
+
void: [AST_NODE_TYPES39.TSVoidKeyword],
|
|
8391
|
+
null: [AST_NODE_TYPES39.TSNullKeyword],
|
|
8392
|
+
undefined: [AST_NODE_TYPES39.TSUndefinedKeyword],
|
|
8393
|
+
literal: [AST_NODE_TYPES39.TSLiteralType],
|
|
8394
|
+
date: [AST_NODE_TYPES39.TSTypeReference],
|
|
8395
|
+
array: [AST_NODE_TYPES39.TSArrayType, AST_NODE_TYPES39.TSTypeReference],
|
|
8396
|
+
tuple: [AST_NODE_TYPES39.TSTupleType],
|
|
8397
|
+
object: [AST_NODE_TYPES39.TSTypeLiteral, AST_NODE_TYPES39.TSTypeReference],
|
|
8398
|
+
strictObject: [AST_NODE_TYPES39.TSTypeLiteral, AST_NODE_TYPES39.TSTypeReference],
|
|
8399
|
+
looseObject: [AST_NODE_TYPES39.TSTypeLiteral, AST_NODE_TYPES39.TSTypeReference],
|
|
8400
|
+
record: [AST_NODE_TYPES39.TSTypeReference, AST_NODE_TYPES39.TSTypeLiteral],
|
|
8401
|
+
map: [AST_NODE_TYPES39.TSTypeReference],
|
|
8402
|
+
set: [AST_NODE_TYPES39.TSTypeReference],
|
|
8403
|
+
promise: [AST_NODE_TYPES39.TSTypeReference],
|
|
8404
|
+
enum: [AST_NODE_TYPES39.TSUnionType, AST_NODE_TYPES39.TSTypeReference, AST_NODE_TYPES39.TSLiteralType],
|
|
8405
|
+
nativeEnum: [AST_NODE_TYPES39.TSUnionType, AST_NODE_TYPES39.TSTypeReference, AST_NODE_TYPES39.TSLiteralType],
|
|
8406
|
+
union: [AST_NODE_TYPES39.TSUnionType, AST_NODE_TYPES39.TSTypeReference],
|
|
8407
|
+
discriminatedUnion: [AST_NODE_TYPES39.TSUnionType, AST_NODE_TYPES39.TSTypeReference],
|
|
8408
|
+
intersection: [AST_NODE_TYPES39.TSIntersectionType, AST_NODE_TYPES39.TSTypeReference]
|
|
8182
8409
|
};
|
|
8183
8410
|
function normalizeSchemaName(name) {
|
|
8184
8411
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -8187,20 +8414,20 @@ function normalizeTypeName(name) {
|
|
|
8187
8414
|
return name.replace(/Type$/, "").toLowerCase();
|
|
8188
8415
|
}
|
|
8189
8416
|
function unwrapNullish(annotation) {
|
|
8190
|
-
if (annotation.type !==
|
|
8417
|
+
if (annotation.type !== AST_NODE_TYPES39.TSUnionType) {
|
|
8191
8418
|
return {
|
|
8192
8419
|
core: annotation,
|
|
8193
|
-
nullable: annotation.type ===
|
|
8420
|
+
nullable: annotation.type === AST_NODE_TYPES39.TSNullKeyword
|
|
8194
8421
|
};
|
|
8195
8422
|
}
|
|
8196
8423
|
const rest = [];
|
|
8197
8424
|
let nullable = false;
|
|
8198
8425
|
for (const member of annotation.types) {
|
|
8199
|
-
if (member.type ===
|
|
8426
|
+
if (member.type === AST_NODE_TYPES39.TSNullKeyword) {
|
|
8200
8427
|
nullable = true;
|
|
8201
8428
|
continue;
|
|
8202
8429
|
}
|
|
8203
|
-
if (member.type ===
|
|
8430
|
+
if (member.type === AST_NODE_TYPES39.TSUndefinedKeyword) {
|
|
8204
8431
|
continue;
|
|
8205
8432
|
}
|
|
8206
8433
|
rest.push(member);
|
|
@@ -8265,14 +8492,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
8265
8492
|
function zodCallChain(node) {
|
|
8266
8493
|
const chain = [];
|
|
8267
8494
|
let current = node;
|
|
8268
|
-
while (current.type ===
|
|
8495
|
+
while (current.type === AST_NODE_TYPES39.CallExpression) {
|
|
8269
8496
|
const callee = current.callee;
|
|
8270
|
-
if (callee.type !==
|
|
8497
|
+
if (callee.type !== AST_NODE_TYPES39.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES39.Identifier) {
|
|
8271
8498
|
return null;
|
|
8272
8499
|
}
|
|
8273
8500
|
chain.push(current);
|
|
8274
8501
|
const receiver = callee.object;
|
|
8275
|
-
if (receiver.type ===
|
|
8502
|
+
if (receiver.type === AST_NODE_TYPES39.Identifier) {
|
|
8276
8503
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
8277
8504
|
}
|
|
8278
8505
|
current = receiver;
|
|
@@ -8281,19 +8508,19 @@ var prefer_zod_infer_default = createRule({
|
|
|
8281
8508
|
}
|
|
8282
8509
|
function methodName(call) {
|
|
8283
8510
|
const callee = call.callee;
|
|
8284
|
-
return callee.type ===
|
|
8511
|
+
return callee.type === AST_NODE_TYPES39.MemberExpression && callee.property.type === AST_NODE_TYPES39.Identifier ? callee.property.name : "";
|
|
8285
8512
|
}
|
|
8286
8513
|
function schemaField(node) {
|
|
8287
8514
|
const modifiers = [];
|
|
8288
8515
|
let current = node;
|
|
8289
8516
|
let leaf = null;
|
|
8290
|
-
while (current.type ===
|
|
8517
|
+
while (current.type === AST_NODE_TYPES39.CallExpression) {
|
|
8291
8518
|
const callee = current.callee;
|
|
8292
|
-
if (callee.type !==
|
|
8519
|
+
if (callee.type !== AST_NODE_TYPES39.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES39.Identifier) {
|
|
8293
8520
|
break;
|
|
8294
8521
|
}
|
|
8295
8522
|
const receiver = callee.object;
|
|
8296
|
-
if (receiver.type ===
|
|
8523
|
+
if (receiver.type === AST_NODE_TYPES39.Identifier && zodNamespaces.has(receiver.name)) {
|
|
8297
8524
|
leaf = callee.property.name;
|
|
8298
8525
|
break;
|
|
8299
8526
|
}
|
|
@@ -8324,16 +8551,16 @@ var prefer_zod_infer_default = createRule({
|
|
|
8324
8551
|
return null;
|
|
8325
8552
|
}
|
|
8326
8553
|
const shape = base.arguments[0];
|
|
8327
|
-
if (shape === void 0 || shape.type !==
|
|
8554
|
+
if (shape === void 0 || shape.type !== AST_NODE_TYPES39.ObjectExpression) {
|
|
8328
8555
|
return null;
|
|
8329
8556
|
}
|
|
8330
8557
|
const fields = /* @__PURE__ */ new Map();
|
|
8331
8558
|
for (const property of shape.properties) {
|
|
8332
|
-
if (property.type !==
|
|
8559
|
+
if (property.type !== AST_NODE_TYPES39.Property || property.computed) {
|
|
8333
8560
|
return null;
|
|
8334
8561
|
}
|
|
8335
8562
|
const { key } = property;
|
|
8336
|
-
const name = key.type ===
|
|
8563
|
+
const name = key.type === AST_NODE_TYPES39.Identifier ? key.name : key.type === AST_NODE_TYPES39.Literal && typeof key.value === "string" ? key.value : null;
|
|
8337
8564
|
if (name === null) {
|
|
8338
8565
|
return null;
|
|
8339
8566
|
}
|
|
@@ -8344,11 +8571,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
8344
8571
|
function typeMembers(members) {
|
|
8345
8572
|
const result = /* @__PURE__ */ new Map();
|
|
8346
8573
|
for (const member of members) {
|
|
8347
|
-
if (member.type !==
|
|
8574
|
+
if (member.type !== AST_NODE_TYPES39.TSPropertySignature || member.computed) {
|
|
8348
8575
|
return null;
|
|
8349
8576
|
}
|
|
8350
8577
|
const { key } = member;
|
|
8351
|
-
const name = key.type ===
|
|
8578
|
+
const name = key.type === AST_NODE_TYPES39.Identifier ? key.name : key.type === AST_NODE_TYPES39.Literal && typeof key.value === "string" ? key.value : null;
|
|
8352
8579
|
if (name === null) {
|
|
8353
8580
|
return null;
|
|
8354
8581
|
}
|
|
@@ -8362,8 +8589,8 @@ var prefer_zod_infer_default = createRule({
|
|
|
8362
8589
|
return result.size === 0 ? null : result;
|
|
8363
8590
|
}
|
|
8364
8591
|
function collectConstrainedNames(node) {
|
|
8365
|
-
if (node.type ===
|
|
8366
|
-
if (node.typeName.type ===
|
|
8592
|
+
if (node.type === AST_NODE_TYPES39.TSTypeReference) {
|
|
8593
|
+
if (node.typeName.type === AST_NODE_TYPES39.Identifier) {
|
|
8367
8594
|
constrainedTypeNames.add(node.typeName.name);
|
|
8368
8595
|
}
|
|
8369
8596
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -8371,11 +8598,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
8371
8598
|
}
|
|
8372
8599
|
return;
|
|
8373
8600
|
}
|
|
8374
|
-
if (node.type ===
|
|
8601
|
+
if (node.type === AST_NODE_TYPES39.TSArrayType) {
|
|
8375
8602
|
collectConstrainedNames(node.elementType);
|
|
8376
8603
|
return;
|
|
8377
8604
|
}
|
|
8378
|
-
if (node.type ===
|
|
8605
|
+
if (node.type === AST_NODE_TYPES39.TSUnionType || node.type === AST_NODE_TYPES39.TSIntersectionType) {
|
|
8379
8606
|
for (const member of node.types) {
|
|
8380
8607
|
collectConstrainedNames(member);
|
|
8381
8608
|
}
|
|
@@ -8419,13 +8646,13 @@ var prefer_zod_infer_default = createRule({
|
|
|
8419
8646
|
return;
|
|
8420
8647
|
}
|
|
8421
8648
|
for (const specifier of node.specifiers) {
|
|
8422
|
-
if (specifier.type ===
|
|
8649
|
+
if (specifier.type === AST_NODE_TYPES39.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES39.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES39.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES39.Identifier && specifier.imported.name === "z") {
|
|
8423
8650
|
zodNamespaces.add(specifier.local.name);
|
|
8424
8651
|
}
|
|
8425
8652
|
}
|
|
8426
8653
|
},
|
|
8427
8654
|
VariableDeclarator(node) {
|
|
8428
|
-
if (node.id.type !==
|
|
8655
|
+
if (node.id.type !== AST_NODE_TYPES39.Identifier || node.init == null) {
|
|
8429
8656
|
return;
|
|
8430
8657
|
}
|
|
8431
8658
|
const fields = schemaFields(node.init);
|
|
@@ -8435,14 +8662,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
8435
8662
|
},
|
|
8436
8663
|
/** Guard (f): `XSchema.transform(...)` anywhere in the module. */
|
|
8437
8664
|
"MemberExpression[computed=false]"(node) {
|
|
8438
|
-
if (node.object.type ===
|
|
8665
|
+
if (node.object.type === AST_NODE_TYPES39.Identifier && node.property.type === AST_NODE_TYPES39.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
8439
8666
|
reshapedSchemaNames.add(node.object.name);
|
|
8440
8667
|
}
|
|
8441
8668
|
},
|
|
8442
8669
|
/** Guard (c): `z.ZodType<T>` and every other type argument it carries. */
|
|
8443
8670
|
TSTypeReference(node) {
|
|
8444
8671
|
const { typeName } = node;
|
|
8445
|
-
const referenced = typeName.type ===
|
|
8672
|
+
const referenced = typeName.type === AST_NODE_TYPES39.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES39.TSQualifiedName && typeName.right.type === AST_NODE_TYPES39.Identifier ? typeName.right.name : null;
|
|
8446
8673
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
8447
8674
|
return;
|
|
8448
8675
|
}
|
|
@@ -8460,7 +8687,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
8460
8687
|
}
|
|
8461
8688
|
},
|
|
8462
8689
|
TSTypeAliasDeclaration(node) {
|
|
8463
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
8690
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== AST_NODE_TYPES39.TSTypeLiteral) {
|
|
8464
8691
|
return;
|
|
8465
8692
|
}
|
|
8466
8693
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -8505,10 +8732,10 @@ var prefer_zod_infer_default = createRule({
|
|
|
8505
8732
|
});
|
|
8506
8733
|
|
|
8507
8734
|
// src/rules/require-assert-never.ts
|
|
8508
|
-
import { AST_NODE_TYPES as
|
|
8735
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES40 } from "@typescript-eslint/utils";
|
|
8509
8736
|
var isRuntimeHandlingStatement = (statement) => {
|
|
8510
|
-
if (statement.type ===
|
|
8511
|
-
if (statement.type ===
|
|
8737
|
+
if (statement.type === AST_NODE_TYPES40.EmptyStatement) return false;
|
|
8738
|
+
if (statement.type === AST_NODE_TYPES40.BlockStatement) {
|
|
8512
8739
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
8513
8740
|
}
|
|
8514
8741
|
return true;
|
|
@@ -8524,7 +8751,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
8524
8751
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
8525
8752
|
}
|
|
8526
8753
|
const only = defaultCase.consequent[0];
|
|
8527
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
8754
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === AST_NODE_TYPES40.BlockStatement && only.body.length === 0) {
|
|
8528
8755
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
8529
8756
|
}
|
|
8530
8757
|
return false;
|
|
@@ -8564,7 +8791,7 @@ var require_assert_never_default = createRule({
|
|
|
8564
8791
|
});
|
|
8565
8792
|
|
|
8566
8793
|
// src/rules/require-fetch-timeout.ts
|
|
8567
|
-
import { AST_NODE_TYPES as
|
|
8794
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES41, ASTUtils as ASTUtils2 } from "@typescript-eslint/utils";
|
|
8568
8795
|
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set([
|
|
8569
8796
|
"globalThis",
|
|
8570
8797
|
"window",
|
|
@@ -8580,14 +8807,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
8580
8807
|
return false;
|
|
8581
8808
|
}
|
|
8582
8809
|
function initProvablyLacksSignal(init) {
|
|
8583
|
-
if (init.type !==
|
|
8810
|
+
if (init.type !== AST_NODE_TYPES41.ObjectExpression) {
|
|
8584
8811
|
return false;
|
|
8585
8812
|
}
|
|
8586
8813
|
for (const prop of init.properties) {
|
|
8587
|
-
if (prop.type ===
|
|
8814
|
+
if (prop.type === AST_NODE_TYPES41.SpreadElement) {
|
|
8588
8815
|
return false;
|
|
8589
8816
|
}
|
|
8590
|
-
if (prop.key.type ===
|
|
8817
|
+
if (prop.key.type === AST_NODE_TYPES41.Identifier && prop.key.name === "signal" || prop.key.type === AST_NODE_TYPES41.Literal && prop.key.value === "signal") {
|
|
8591
8818
|
return false;
|
|
8592
8819
|
}
|
|
8593
8820
|
if (prop.computed) {
|
|
@@ -8597,7 +8824,7 @@ function initProvablyLacksSignal(init) {
|
|
|
8597
8824
|
return true;
|
|
8598
8825
|
}
|
|
8599
8826
|
function isStringish(node) {
|
|
8600
|
-
return node.type ===
|
|
8827
|
+
return node.type === AST_NODE_TYPES41.Literal && typeof node.value === "string" || node.type === AST_NODE_TYPES41.TemplateLiteral;
|
|
8601
8828
|
}
|
|
8602
8829
|
var require_fetch_timeout_default = createRule({
|
|
8603
8830
|
name: "require-fetch-timeout",
|
|
@@ -8638,10 +8865,10 @@ var require_fetch_timeout_default = createRule({
|
|
|
8638
8865
|
return variable === null || variable.defs.length === 0;
|
|
8639
8866
|
}
|
|
8640
8867
|
function isGlobalFetchCall2(callee) {
|
|
8641
|
-
if (callee.type ===
|
|
8868
|
+
if (callee.type === AST_NODE_TYPES41.Identifier) {
|
|
8642
8869
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
8643
8870
|
}
|
|
8644
|
-
return callee.type ===
|
|
8871
|
+
return callee.type === AST_NODE_TYPES41.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES41.Identifier && callee.property.name === "fetch" && callee.object.type === AST_NODE_TYPES41.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
8645
8872
|
}
|
|
8646
8873
|
return {
|
|
8647
8874
|
CallExpression(node) {
|
|
@@ -8661,7 +8888,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
8661
8888
|
});
|
|
8662
8889
|
|
|
8663
8890
|
// src/rules/require-interface-for-injected-service.ts
|
|
8664
|
-
import { AST_NODE_TYPES as
|
|
8891
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES42 } from "@typescript-eslint/utils";
|
|
8665
8892
|
var CONFIGISH_TYPE_RE = /(?:Options|Opts|Config|Configuration|Settings|Params|Props|Args|Env|Environment|Callbacks|Flags)$/;
|
|
8666
8893
|
var CONFIGISH_NAME_RE = /^(?:options|opts|config|configuration|settings|params|props|args|env|environment|callbacks|flags|logger|log|clock)$/i;
|
|
8667
8894
|
var HTTP_TRANSPORT_TYPE_RE = /^(?:KyInstance|AxiosInstance|Session)$/;
|
|
@@ -8669,20 +8896,20 @@ var BUILTIN_CONTAINER_TYPE_RE = /^(?:Record|Map|WeakMap|Set|WeakSet|Array|Readon
|
|
|
8669
8896
|
var TRANSPORT_WRAPPER_NAME_RE = /Client$/;
|
|
8670
8897
|
var ROUTER_FACTORY_NAME = "Router";
|
|
8671
8898
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
8672
|
-
var isExportedClass = (node) => node.parent.type ===
|
|
8673
|
-
var qualifiedName = (name) => name.type ===
|
|
8899
|
+
var isExportedClass = (node) => node.parent.type === AST_NODE_TYPES42.ExportNamedDeclaration || node.parent.type === AST_NODE_TYPES42.ExportDefaultDeclaration;
|
|
8900
|
+
var qualifiedName = (name) => name.type === AST_NODE_TYPES42.Identifier ? name.name : name.type === AST_NODE_TYPES42.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
8674
8901
|
var readTypeReference = (annotation) => {
|
|
8675
|
-
if (annotation === void 0 || annotation.type !==
|
|
8902
|
+
if (annotation === void 0 || annotation.type !== AST_NODE_TYPES42.TSTypeReference) return null;
|
|
8676
8903
|
const { typeName } = annotation;
|
|
8677
|
-
const rightmost = typeName.type ===
|
|
8904
|
+
const rightmost = typeName.type === AST_NODE_TYPES42.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES42.TSQualifiedName ? typeName.right.name : null;
|
|
8678
8905
|
if (rightmost === null) return null;
|
|
8679
8906
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
8680
8907
|
};
|
|
8681
8908
|
var namedParameterCollaborator = (annotated) => {
|
|
8682
8909
|
let target = annotated;
|
|
8683
|
-
if (target.type ===
|
|
8684
|
-
if (target.type ===
|
|
8685
|
-
if (target.type !==
|
|
8910
|
+
if (target.type === AST_NODE_TYPES42.TSParameterProperty) target = target.parameter;
|
|
8911
|
+
if (target.type === AST_NODE_TYPES42.AssignmentPattern) target = target.left;
|
|
8912
|
+
if (target.type !== AST_NODE_TYPES42.Identifier) return null;
|
|
8686
8913
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
8687
8914
|
if (reference === null) return null;
|
|
8688
8915
|
return { name: target.name, ...reference };
|
|
@@ -8690,8 +8917,8 @@ var namedParameterCollaborator = (annotated) => {
|
|
|
8690
8917
|
var propertySignatureTypes = (members) => {
|
|
8691
8918
|
const types = /* @__PURE__ */ new Map();
|
|
8692
8919
|
for (const member of members) {
|
|
8693
|
-
if (member.type !==
|
|
8694
|
-
if (member.computed || member.key.type !==
|
|
8920
|
+
if (member.type !== AST_NODE_TYPES42.TSPropertySignature) continue;
|
|
8921
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES42.Identifier) continue;
|
|
8695
8922
|
const reference = readTypeReference(member.typeAnnotation?.typeAnnotation);
|
|
8696
8923
|
if (reference === null) continue;
|
|
8697
8924
|
types.set(member.key.name, reference);
|
|
@@ -8702,18 +8929,18 @@ var fileTypeIndex = (program) => {
|
|
|
8702
8929
|
const objects = /* @__PURE__ */ new Map();
|
|
8703
8930
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
8704
8931
|
for (const statement of program.body) {
|
|
8705
|
-
const declaration = statement.type ===
|
|
8706
|
-
if (declaration?.type ===
|
|
8932
|
+
const declaration = statement.type === AST_NODE_TYPES42.ExportNamedDeclaration ? statement.declaration : statement;
|
|
8933
|
+
if (declaration?.type === AST_NODE_TYPES42.TSInterfaceDeclaration) {
|
|
8707
8934
|
objects.set(declaration.id.name, propertySignatureTypes(declaration.body.body));
|
|
8708
8935
|
continue;
|
|
8709
8936
|
}
|
|
8710
|
-
if (declaration?.type !==
|
|
8937
|
+
if (declaration?.type !== AST_NODE_TYPES42.TSTypeAliasDeclaration) continue;
|
|
8711
8938
|
const aliased = declaration.typeAnnotation;
|
|
8712
|
-
if (aliased.type ===
|
|
8939
|
+
if (aliased.type === AST_NODE_TYPES42.TSFunctionType || aliased.type === AST_NODE_TYPES42.TSConstructorType) {
|
|
8713
8940
|
functionAliases.add(declaration.id.name);
|
|
8714
8941
|
continue;
|
|
8715
8942
|
}
|
|
8716
|
-
const literals = aliased.type ===
|
|
8943
|
+
const literals = aliased.type === AST_NODE_TYPES42.TSTypeLiteral ? [aliased] : aliased.type === AST_NODE_TYPES42.TSIntersectionType ? aliased.types.filter((part) => part.type === AST_NODE_TYPES42.TSTypeLiteral) : [];
|
|
8717
8944
|
if (literals.length === 0) continue;
|
|
8718
8945
|
const merged = /* @__PURE__ */ new Map();
|
|
8719
8946
|
for (const literal of literals) {
|
|
@@ -8726,10 +8953,10 @@ var fileTypeIndex = (program) => {
|
|
|
8726
8953
|
return { objects, functionAliases };
|
|
8727
8954
|
};
|
|
8728
8955
|
var bagMemberTypes = (annotation, declared) => {
|
|
8729
|
-
if (annotation.type ===
|
|
8956
|
+
if (annotation.type === AST_NODE_TYPES42.TSTypeLiteral) {
|
|
8730
8957
|
return propertySignatureTypes(annotation.members);
|
|
8731
8958
|
}
|
|
8732
|
-
if (annotation.type !==
|
|
8959
|
+
if (annotation.type !== AST_NODE_TYPES42.TSTypeReference || annotation.typeName.type !== AST_NODE_TYPES42.Identifier) {
|
|
8733
8960
|
return null;
|
|
8734
8961
|
}
|
|
8735
8962
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
@@ -8741,11 +8968,11 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
8741
8968
|
if (members === null) return [];
|
|
8742
8969
|
const collaborators = [];
|
|
8743
8970
|
for (const property of pattern.properties) {
|
|
8744
|
-
if (property.type !==
|
|
8745
|
-
if (property.key.type !==
|
|
8971
|
+
if (property.type !== AST_NODE_TYPES42.Property || property.computed) continue;
|
|
8972
|
+
if (property.key.type !== AST_NODE_TYPES42.Identifier) continue;
|
|
8746
8973
|
const key = property.key.name;
|
|
8747
|
-
const bound = property.value.type ===
|
|
8748
|
-
if (bound.type !==
|
|
8974
|
+
const bound = property.value.type === AST_NODE_TYPES42.AssignmentPattern ? property.value.left : property.value;
|
|
8975
|
+
if (bound.type !== AST_NODE_TYPES42.Identifier) continue;
|
|
8749
8976
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
8750
8977
|
const reference = members.get(key);
|
|
8751
8978
|
if (reference === void 0) continue;
|
|
@@ -8755,8 +8982,8 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
8755
8982
|
};
|
|
8756
8983
|
var parameterCollaborators = (parameter, declared) => {
|
|
8757
8984
|
let target = parameter;
|
|
8758
|
-
if (target.type ===
|
|
8759
|
-
if (target.type ===
|
|
8985
|
+
if (target.type === AST_NODE_TYPES42.AssignmentPattern) target = target.left;
|
|
8986
|
+
if (target.type === AST_NODE_TYPES42.ObjectPattern) {
|
|
8760
8987
|
return objectPatternCollaborators(target, declared);
|
|
8761
8988
|
}
|
|
8762
8989
|
const named2 = namedParameterCollaborator(parameter);
|
|
@@ -8775,17 +9002,17 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
8775
9002
|
let constructedFields = 0;
|
|
8776
9003
|
if (body !== null && body !== void 0) {
|
|
8777
9004
|
for (const statement of body.body) {
|
|
8778
|
-
if (statement.type !==
|
|
9005
|
+
if (statement.type !== AST_NODE_TYPES42.ExpressionStatement) continue;
|
|
8779
9006
|
const expression = statement.expression;
|
|
8780
|
-
if (expression.type !==
|
|
9007
|
+
if (expression.type !== AST_NODE_TYPES42.AssignmentExpression || expression.operator !== "=" || expression.left.type !== AST_NODE_TYPES42.MemberExpression || expression.left.object.type !== AST_NODE_TYPES42.ThisExpression) {
|
|
8781
9008
|
continue;
|
|
8782
9009
|
}
|
|
8783
9010
|
const source = expression.right;
|
|
8784
|
-
if (source.type ===
|
|
9011
|
+
if (source.type === AST_NODE_TYPES42.NewExpression) {
|
|
8785
9012
|
constructedFields += 1;
|
|
8786
|
-
} else if (source.type ===
|
|
9013
|
+
} else if (source.type === AST_NODE_TYPES42.Identifier) {
|
|
8787
9014
|
storedFrom.add(source.name);
|
|
8788
|
-
} else if (source.type ===
|
|
9015
|
+
} else if (source.type === AST_NODE_TYPES42.MemberExpression && source.object.type === AST_NODE_TYPES42.Identifier) {
|
|
8789
9016
|
storedFrom.add(source.object.name);
|
|
8790
9017
|
}
|
|
8791
9018
|
}
|
|
@@ -8793,7 +9020,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
8793
9020
|
const collaborators = [];
|
|
8794
9021
|
for (const parameter of ctor.value.params) {
|
|
8795
9022
|
for (const reference of parameterCollaborators(parameter, declared)) {
|
|
8796
|
-
const stored = parameter.type ===
|
|
9023
|
+
const stored = parameter.type === AST_NODE_TYPES42.TSParameterProperty || storedFrom.has(reference.name);
|
|
8797
9024
|
if (!stored) continue;
|
|
8798
9025
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
8799
9026
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -8827,19 +9054,19 @@ var subtreeHas = (root, found) => {
|
|
|
8827
9054
|
return hit;
|
|
8828
9055
|
};
|
|
8829
9056
|
var isFrameworkWiring = (body) => subtreeHas(body, (node) => {
|
|
8830
|
-
if (node.type ===
|
|
9057
|
+
if (node.type === AST_NODE_TYPES42.CallExpression) {
|
|
8831
9058
|
const { callee } = node;
|
|
8832
|
-
if (callee.type ===
|
|
8833
|
-
return callee.type ===
|
|
9059
|
+
if (callee.type === AST_NODE_TYPES42.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
9060
|
+
return callee.type === AST_NODE_TYPES42.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES42.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
8834
9061
|
}
|
|
8835
|
-
return node.type ===
|
|
9062
|
+
return node.type === AST_NODE_TYPES42.TSTypeReference && node.typeName.type === AST_NODE_TYPES42.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
8836
9063
|
});
|
|
8837
9064
|
var stem2 = (name) => name.replace(/^I(?=[A-Z])/, "").replace(/Impl$/, "");
|
|
8838
9065
|
var fileInterfaceNames = (program) => {
|
|
8839
9066
|
const names = [];
|
|
8840
9067
|
for (const statement of program.body) {
|
|
8841
|
-
const declaration = statement.type ===
|
|
8842
|
-
if (declaration?.type ===
|
|
9068
|
+
const declaration = statement.type === AST_NODE_TYPES42.ExportNamedDeclaration ? statement.declaration : statement;
|
|
9069
|
+
if (declaration?.type === AST_NODE_TYPES42.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
8843
9070
|
}
|
|
8844
9071
|
return names;
|
|
8845
9072
|
};
|
|
@@ -8857,11 +9084,11 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
8857
9084
|
var publicMethodNames = (body) => {
|
|
8858
9085
|
const names = [];
|
|
8859
9086
|
for (const member of body.body) {
|
|
8860
|
-
if (member.type !==
|
|
9087
|
+
if (member.type !== AST_NODE_TYPES42.MethodDefinition) continue;
|
|
8861
9088
|
if (member.kind !== "method" || member.static) continue;
|
|
8862
9089
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
8863
|
-
if (member.key.type ===
|
|
8864
|
-
if (member.key.type ===
|
|
9090
|
+
if (member.key.type === AST_NODE_TYPES42.PrivateIdentifier) continue;
|
|
9091
|
+
if (member.key.type === AST_NODE_TYPES42.Identifier) names.push(member.key.name);
|
|
8865
9092
|
else names.push("\u2026");
|
|
8866
9093
|
}
|
|
8867
9094
|
return names;
|
|
@@ -8894,7 +9121,7 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
8894
9121
|
if (node.implements.length > 0) return;
|
|
8895
9122
|
if (node.decorators.length > 0) return;
|
|
8896
9123
|
const ctor = node.body.body.find(
|
|
8897
|
-
(member) => member.type ===
|
|
9124
|
+
(member) => member.type === AST_NODE_TYPES42.MethodDefinition && member.kind === "constructor"
|
|
8898
9125
|
);
|
|
8899
9126
|
if (ctor === void 0) return;
|
|
8900
9127
|
const { collaborators, constructedFields } = readConstructor(
|
|
@@ -8923,18 +9150,18 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
8923
9150
|
});
|
|
8924
9151
|
|
|
8925
9152
|
// src/rules/require-zod-form-validation.ts
|
|
8926
|
-
import { AST_NODE_TYPES as
|
|
9153
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES43 } from "@typescript-eslint/utils";
|
|
8927
9154
|
var looksLikeZodSchema = (node) => {
|
|
8928
9155
|
let current = node;
|
|
8929
9156
|
while (true) {
|
|
8930
|
-
if (current.type ===
|
|
9157
|
+
if (current.type === AST_NODE_TYPES43.Identifier) {
|
|
8931
9158
|
return current.name === "z" || ZOD_SCHEMA_NAME_RE.test(current.name);
|
|
8932
9159
|
}
|
|
8933
|
-
if (current.type ===
|
|
9160
|
+
if (current.type === AST_NODE_TYPES43.CallExpression) {
|
|
8934
9161
|
current = current.callee;
|
|
8935
9162
|
continue;
|
|
8936
9163
|
}
|
|
8937
|
-
if (current.type ===
|
|
9164
|
+
if (current.type === AST_NODE_TYPES43.MemberExpression) {
|
|
8938
9165
|
current = current.object;
|
|
8939
9166
|
continue;
|
|
8940
9167
|
}
|
|
@@ -8942,23 +9169,23 @@ var looksLikeZodSchema = (node) => {
|
|
|
8942
9169
|
}
|
|
8943
9170
|
};
|
|
8944
9171
|
var isZodParseCall = (node) => {
|
|
8945
|
-
if (node.type !==
|
|
9172
|
+
if (node.type !== AST_NODE_TYPES43.CallExpression) return false;
|
|
8946
9173
|
const callee = node.callee;
|
|
8947
|
-
if (callee.type !==
|
|
9174
|
+
if (callee.type !== AST_NODE_TYPES43.MemberExpression) return false;
|
|
8948
9175
|
if (callee.computed) return false;
|
|
8949
|
-
if (callee.property.type !==
|
|
9176
|
+
if (callee.property.type !== AST_NODE_TYPES43.Identifier) return false;
|
|
8950
9177
|
const method = callee.property.name;
|
|
8951
9178
|
if (method !== "parse" && method !== "safeParse") return false;
|
|
8952
9179
|
return looksLikeZodSchema(callee.object);
|
|
8953
9180
|
};
|
|
8954
9181
|
var isFormDataMethodCall = (node) => {
|
|
8955
9182
|
let current = node;
|
|
8956
|
-
if (current.type ===
|
|
9183
|
+
if (current.type === AST_NODE_TYPES43.AwaitExpression) {
|
|
8957
9184
|
current = current.argument;
|
|
8958
9185
|
}
|
|
8959
|
-
if (current.type !==
|
|
9186
|
+
if (current.type !== AST_NODE_TYPES43.CallExpression) return false;
|
|
8960
9187
|
const callee = current.callee;
|
|
8961
|
-
return callee.type ===
|
|
9188
|
+
return callee.type === AST_NODE_TYPES43.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES43.Identifier && callee.property.name === "formData";
|
|
8962
9189
|
};
|
|
8963
9190
|
var require_zod_form_validation_default = createRule({
|
|
8964
9191
|
name: "require-zod-form-validation",
|
|
@@ -8978,14 +9205,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
8978
9205
|
return {};
|
|
8979
9206
|
}
|
|
8980
9207
|
const isFormSourceIdentifier = (node) => {
|
|
8981
|
-
if (node.type !==
|
|
9208
|
+
if (node.type !== AST_NODE_TYPES43.Identifier) return false;
|
|
8982
9209
|
if (/formdata/i.test(node.name)) return true;
|
|
8983
9210
|
let scope = context.sourceCode.getScope(node);
|
|
8984
9211
|
while (scope !== null) {
|
|
8985
9212
|
const variable = scope.set.get(node.name);
|
|
8986
9213
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
8987
9214
|
const def = variable.defs[0];
|
|
8988
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
9215
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === AST_NODE_TYPES43.VariableDeclarator && def.node.init !== null) {
|
|
8989
9216
|
return isFormDataMethodCall(def.node.init);
|
|
8990
9217
|
}
|
|
8991
9218
|
return false;
|
|
@@ -8996,8 +9223,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
8996
9223
|
};
|
|
8997
9224
|
const isFormDataGetCall = (node) => {
|
|
8998
9225
|
const callee = node.callee;
|
|
8999
|
-
if (callee.type !==
|
|
9000
|
-
if (callee.property.type !==
|
|
9226
|
+
if (callee.type !== AST_NODE_TYPES43.MemberExpression) return false;
|
|
9227
|
+
if (callee.property.type !== AST_NODE_TYPES43.Identifier || callee.property.name !== "get") {
|
|
9001
9228
|
return false;
|
|
9002
9229
|
}
|
|
9003
9230
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -9012,11 +9239,11 @@ var require_zod_form_validation_default = createRule({
|
|
|
9012
9239
|
};
|
|
9013
9240
|
const isInstanceofNarrowing = (node) => {
|
|
9014
9241
|
const parent = node.parent;
|
|
9015
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
9242
|
+
return parent !== null && parent !== void 0 && parent.type === AST_NODE_TYPES43.BinaryExpression && parent.operator === "instanceof" && parent.left === node;
|
|
9016
9243
|
};
|
|
9017
9244
|
const boundDeclarator = (node) => {
|
|
9018
9245
|
const parent = node.parent;
|
|
9019
|
-
if (parent.type ===
|
|
9246
|
+
if (parent.type === AST_NODE_TYPES43.VariableDeclarator && parent.init === node && parent.id.type === AST_NODE_TYPES43.Identifier) {
|
|
9020
9247
|
return parent;
|
|
9021
9248
|
}
|
|
9022
9249
|
return null;
|
|
@@ -9075,7 +9302,7 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
9075
9302
|
});
|
|
9076
9303
|
|
|
9077
9304
|
// src/rules/zod-naming-convention.ts
|
|
9078
|
-
import { AST_NODE_TYPES as
|
|
9305
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES44 } from "@typescript-eslint/utils";
|
|
9079
9306
|
var CONVENTIONS = {
|
|
9080
9307
|
prefix: { test: ZOD_PREFIX_RE, messageId: "zPrefix" },
|
|
9081
9308
|
suffix: { test: ZOD_SUFFIX_RE, messageId: "schemaSuffix" },
|
|
@@ -9100,15 +9327,15 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
9100
9327
|
"registry",
|
|
9101
9328
|
"implement"
|
|
9102
9329
|
]);
|
|
9103
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
9330
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === AST_NODE_TYPES44.Identifier ? callee.property.name : null;
|
|
9104
9331
|
var calleeChainStartsWithZ = (node) => {
|
|
9105
9332
|
let current = node;
|
|
9106
|
-
while (current.type ===
|
|
9333
|
+
while (current.type === AST_NODE_TYPES44.MemberExpression) {
|
|
9107
9334
|
const receiver = current.object;
|
|
9108
|
-
if (receiver.type ===
|
|
9335
|
+
if (receiver.type === AST_NODE_TYPES44.Identifier && receiver.name === "z") {
|
|
9109
9336
|
return true;
|
|
9110
9337
|
}
|
|
9111
|
-
if (receiver.type ===
|
|
9338
|
+
if (receiver.type === AST_NODE_TYPES44.CallExpression) {
|
|
9112
9339
|
current = receiver.callee;
|
|
9113
9340
|
continue;
|
|
9114
9341
|
}
|
|
@@ -9153,13 +9380,13 @@ var zod_naming_convention_default = createRule({
|
|
|
9153
9380
|
VariableDeclarator(node) {
|
|
9154
9381
|
const init = node.init;
|
|
9155
9382
|
if (init === null || init === void 0) return;
|
|
9156
|
-
if (init.type !==
|
|
9383
|
+
if (init.type !== AST_NODE_TYPES44.CallExpression) return;
|
|
9157
9384
|
const callee = init.callee;
|
|
9158
|
-
if (callee.type !==
|
|
9385
|
+
if (callee.type !== AST_NODE_TYPES44.MemberExpression) return;
|
|
9159
9386
|
if (!calleeChainStartsWithZ(callee)) return;
|
|
9160
9387
|
const terminal = terminalMethodName(callee);
|
|
9161
9388
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
9162
|
-
if (node.id.type !==
|
|
9389
|
+
if (node.id.type !== AST_NODE_TYPES44.Identifier) return;
|
|
9163
9390
|
if (test.test(node.id.name)) return;
|
|
9164
9391
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
9165
9392
|
context.report({
|
|
@@ -9259,6 +9486,7 @@ var rules = {
|
|
|
9259
9486
|
"no-tautological-expect": no_tautological_expect_default,
|
|
9260
9487
|
"no-trailing-value-narration": no_trailing_value_narration_default,
|
|
9261
9488
|
"no-declaration-comment-wall": no_declaration_comment_wall_default,
|
|
9489
|
+
"no-union-in-comment": no_union_in_comment_default,
|
|
9262
9490
|
"no-type-member-comment-wall": no_type_member_comment_wall_default,
|
|
9263
9491
|
"no-unnecessary-use-client": no_unnecessary_use_client_default,
|
|
9264
9492
|
"no-unsafe-mock-casting": no_unsafe_mock_casting_default,
|
|
@@ -9284,7 +9512,7 @@ var rules = {
|
|
|
9284
9512
|
};
|
|
9285
9513
|
var meta = {
|
|
9286
9514
|
name: "@sarj/eslint-plugin",
|
|
9287
|
-
version: "9.
|
|
9515
|
+
version: "9.4.0"
|
|
9288
9516
|
};
|
|
9289
9517
|
var recommendedRules = {
|
|
9290
9518
|
"@sarj/enforce-file-structure": "warn",
|
|
@@ -9313,6 +9541,7 @@ var recommendedRules = {
|
|
|
9313
9541
|
"@sarj/no-tautological-expect": "warn",
|
|
9314
9542
|
"@sarj/no-trailing-value-narration": "warn",
|
|
9315
9543
|
"@sarj/no-declaration-comment-wall": "warn",
|
|
9544
|
+
"@sarj/no-union-in-comment": "warn",
|
|
9316
9545
|
"@sarj/no-type-member-comment-wall": "warn",
|
|
9317
9546
|
"@sarj/no-unnecessary-use-client": "warn",
|
|
9318
9547
|
"@sarj/no-unsafe-mock-casting": "warn",
|
|
@@ -9367,6 +9596,7 @@ var strictRules = {
|
|
|
9367
9596
|
"@sarj/no-tautological-expect": "error",
|
|
9368
9597
|
"@sarj/no-trailing-value-narration": "error",
|
|
9369
9598
|
"@sarj/no-declaration-comment-wall": "error",
|
|
9599
|
+
"@sarj/no-union-in-comment": "error",
|
|
9370
9600
|
"@sarj/no-type-member-comment-wall": "error",
|
|
9371
9601
|
"@sarj/no-unnecessary-use-client": "error",
|
|
9372
9602
|
"@sarj/no-unsafe-mock-casting": "error",
|