@sarj/eslint-plugin 9.3.0 → 9.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/index.cjs +521 -357
- 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 +516 -352
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -623,6 +623,7 @@ function isSectionLabel(text) {
|
|
|
623
623
|
const match = SECTION_LABEL_RE.exec(text);
|
|
624
624
|
return match !== null && SECTION_LABEL_WORDS.has((match[1] ?? "").toLowerCase());
|
|
625
625
|
}
|
|
626
|
+
var SHOUTED_LABEL_RE = /^[A-Z]{2,}(?:[ -][A-Z]{2,}){1,3}$/;
|
|
626
627
|
var HELPER_OPENER_RE = /^(?:a\s+)?helper\s+(?:function|method|component|hook|class|type|util(?:ity)?)\b/i;
|
|
627
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;
|
|
628
629
|
var ENUMERATION_RE = /^(?:\d+[.)]\s+\S|(?:phase|step)\s+\d+\b)/i;
|
|
@@ -777,6 +778,12 @@ var no_comment_cruft_default = createRule({
|
|
|
777
778
|
function isJsDoc(comment) {
|
|
778
779
|
return comment.type === "Block" && /^\*/.test(comment.value);
|
|
779
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
|
+
}
|
|
780
787
|
function reportLeadingPreamble(comments, firstCodeLine) {
|
|
781
788
|
const leading = [];
|
|
782
789
|
let prevLine = null;
|
|
@@ -810,7 +817,13 @@ var no_comment_cruft_default = createRule({
|
|
|
810
817
|
for (let i = 0; i < comments.length; i++) {
|
|
811
818
|
const comment = comments[i];
|
|
812
819
|
if (comment === void 0) continue;
|
|
813
|
-
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;
|
|
814
827
|
if (LICENSE_RE.test(comment.value)) continue;
|
|
815
828
|
const texts = comment.value.split("\n").map(stripCommentMarker).filter((l) => l.length > 0 && !isDirective(l));
|
|
816
829
|
const firstText = texts[0];
|
|
@@ -5285,10 +5298,158 @@ var no_declaration_comment_wall_default = createRule({
|
|
|
5285
5298
|
}
|
|
5286
5299
|
});
|
|
5287
5300
|
|
|
5288
|
-
// src/rules/no-
|
|
5301
|
+
// src/rules/no-union-in-comment.ts
|
|
5289
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";
|
|
5290
5451
|
function isNamedMember(node) {
|
|
5291
|
-
return (node.type ===
|
|
5452
|
+
return (node.type === AST_NODE_TYPES25.TSPropertySignature || node.type === AST_NODE_TYPES25.TSMethodSignature) && !node.computed;
|
|
5292
5453
|
}
|
|
5293
5454
|
var no_type_member_comment_wall_default = createRule({
|
|
5294
5455
|
name: "no-type-member-comment-wall",
|
|
@@ -5335,7 +5496,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5335
5496
|
return headsRun || lineAbove !== void 0 && lineAbove.trim().length === 0;
|
|
5336
5497
|
}
|
|
5337
5498
|
function check(node) {
|
|
5338
|
-
const members = node.type ===
|
|
5499
|
+
const members = node.type === AST_NODE_TYPES25.TSInterfaceBody ? node.body : node.members;
|
|
5339
5500
|
const named2 = members.filter(isNamedMember);
|
|
5340
5501
|
if (named2.length === 0) return;
|
|
5341
5502
|
const documented = named2.map((member) => ({ member, comment: documentingComment(member) }));
|
|
@@ -5375,7 +5536,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5375
5536
|
});
|
|
5376
5537
|
|
|
5377
5538
|
// src/rules/no-unnecessary-use-client.ts
|
|
5378
|
-
import { AST_NODE_TYPES as
|
|
5539
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES26 } from "@typescript-eslint/utils";
|
|
5379
5540
|
var HOOK_REGEX = /^use([A-Z]|$)/;
|
|
5380
5541
|
var EVENT_PROP_REGEX = /^on[A-Z]/;
|
|
5381
5542
|
var ERROR_FILE_REGEX = /\b(?:global-)?error\.[jt]sx?$/;
|
|
@@ -5401,13 +5562,13 @@ var CLIENT_ONLY_PACKAGES_REGEX = /^(?:@radix-ui\/|framer-motion|react-dom|react-
|
|
|
5401
5562
|
var isBareSpecifier = (source) => !source.startsWith(".") && !source.startsWith("/") && !source.startsWith("@/") && !source.startsWith("~");
|
|
5402
5563
|
var jsxRootName = (name) => {
|
|
5403
5564
|
let current = name;
|
|
5404
|
-
while (current.type ===
|
|
5565
|
+
while (current.type === AST_NODE_TYPES26.JSXMemberExpression) {
|
|
5405
5566
|
current = current.object;
|
|
5406
5567
|
}
|
|
5407
|
-
return current.type ===
|
|
5568
|
+
return current.type === AST_NODE_TYPES26.JSXIdentifier ? current.name : "";
|
|
5408
5569
|
};
|
|
5409
5570
|
var subtreeReadsImportedBinding = (node, imported) => {
|
|
5410
|
-
if (node.type ===
|
|
5571
|
+
if (node.type === AST_NODE_TYPES26.Identifier) {
|
|
5411
5572
|
return imported.has(node.name);
|
|
5412
5573
|
}
|
|
5413
5574
|
for (const key of Object.keys(node)) {
|
|
@@ -5422,16 +5583,16 @@ var subtreeReadsImportedBinding = (node, imported) => {
|
|
|
5422
5583
|
return false;
|
|
5423
5584
|
};
|
|
5424
5585
|
var isUseClientDirective = (node) => {
|
|
5425
|
-
return node.type ===
|
|
5586
|
+
return node.type === AST_NODE_TYPES26.ExpressionStatement && node.expression.type === AST_NODE_TYPES26.Literal && node.expression.value === "use client";
|
|
5426
5587
|
};
|
|
5427
5588
|
var isGlobalReference = (node, context) => {
|
|
5428
5589
|
if (!BROWSER_GLOBALS.has(node.name)) return false;
|
|
5429
5590
|
const parent = node.parent;
|
|
5430
5591
|
if (parent !== void 0) {
|
|
5431
|
-
if (parent.type ===
|
|
5592
|
+
if (parent.type === AST_NODE_TYPES26.MemberExpression && parent.property === node && !parent.computed) {
|
|
5432
5593
|
return false;
|
|
5433
5594
|
}
|
|
5434
|
-
if (parent.type ===
|
|
5595
|
+
if (parent.type === AST_NODE_TYPES26.Property && parent.key === node && !parent.computed) {
|
|
5435
5596
|
return false;
|
|
5436
5597
|
}
|
|
5437
5598
|
if (parent.type.startsWith("TS")) {
|
|
@@ -5471,13 +5632,13 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5471
5632
|
const importedLocals = /* @__PURE__ */ new Set();
|
|
5472
5633
|
const externalLocals = /* @__PURE__ */ new Set();
|
|
5473
5634
|
const markIfHookOrContext = (callee) => {
|
|
5474
|
-
if (callee.type ===
|
|
5635
|
+
if (callee.type === AST_NODE_TYPES26.Identifier) {
|
|
5475
5636
|
if (HOOK_REGEX.test(callee.name) || callee.name === "createContext") {
|
|
5476
5637
|
hasClientIndicator = true;
|
|
5477
5638
|
}
|
|
5478
5639
|
return;
|
|
5479
5640
|
}
|
|
5480
|
-
if (callee.type ===
|
|
5641
|
+
if (callee.type === AST_NODE_TYPES26.MemberExpression && callee.property.type === AST_NODE_TYPES26.Identifier) {
|
|
5481
5642
|
const name = callee.property.name;
|
|
5482
5643
|
if (HOOK_REGEX.test(name) || name === "createContext") {
|
|
5483
5644
|
hasClientIndicator = true;
|
|
@@ -5487,7 +5648,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5487
5648
|
return {
|
|
5488
5649
|
Program(node) {
|
|
5489
5650
|
for (const stmt of node.body) {
|
|
5490
|
-
if (stmt.type !==
|
|
5651
|
+
if (stmt.type !== AST_NODE_TYPES26.ExpressionStatement) break;
|
|
5491
5652
|
if (isUseClientDirective(stmt)) {
|
|
5492
5653
|
directiveNode = stmt;
|
|
5493
5654
|
break;
|
|
@@ -5500,7 +5661,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5500
5661
|
},
|
|
5501
5662
|
JSXAttribute(node) {
|
|
5502
5663
|
if (directiveNode === null) return;
|
|
5503
|
-
if (node.name.type ===
|
|
5664
|
+
if (node.name.type === AST_NODE_TYPES26.JSXIdentifier && EVENT_PROP_REGEX.test(node.name.name)) {
|
|
5504
5665
|
hasClientIndicator = true;
|
|
5505
5666
|
}
|
|
5506
5667
|
},
|
|
@@ -5568,17 +5729,17 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5568
5729
|
|
|
5569
5730
|
// src/rules/no-unsafe-mock-casting.ts
|
|
5570
5731
|
import "@typescript-eslint/utils";
|
|
5571
|
-
import { AST_NODE_TYPES as
|
|
5732
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES27 } from "@typescript-eslint/utils";
|
|
5572
5733
|
function isMockTypeReference(node) {
|
|
5573
|
-
if (node.type !==
|
|
5734
|
+
if (node.type !== AST_NODE_TYPES27.TSTypeReference) {
|
|
5574
5735
|
return false;
|
|
5575
5736
|
}
|
|
5576
5737
|
const typeName = node.typeName;
|
|
5577
|
-
if (typeName.type ===
|
|
5738
|
+
if (typeName.type === AST_NODE_TYPES27.Identifier) {
|
|
5578
5739
|
const name = typeName.name;
|
|
5579
5740
|
return name === "Mock" || name === "MockInstance" || name === "SpyInstance";
|
|
5580
5741
|
}
|
|
5581
|
-
if (typeName.type ===
|
|
5742
|
+
if (typeName.type === AST_NODE_TYPES27.TSQualifiedName) {
|
|
5582
5743
|
const rightName = typeName.right.name;
|
|
5583
5744
|
return rightName === "Mock" || rightName === "MockInstance" || rightName === "SpyInstance";
|
|
5584
5745
|
}
|
|
@@ -5616,7 +5777,7 @@ var no_unsafe_mock_casting_default = createRule({
|
|
|
5616
5777
|
// src/rules/no-zod-native-enum.ts
|
|
5617
5778
|
import {
|
|
5618
5779
|
ESLintUtils as ESLintUtils2,
|
|
5619
|
-
AST_NODE_TYPES as
|
|
5780
|
+
AST_NODE_TYPES as AST_NODE_TYPES28
|
|
5620
5781
|
} from "@typescript-eslint/utils";
|
|
5621
5782
|
import * as ts from "typescript";
|
|
5622
5783
|
var IGNORE_PATTERNS = [
|
|
@@ -5635,7 +5796,7 @@ function isZodModule(source) {
|
|
|
5635
5796
|
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
5636
5797
|
}
|
|
5637
5798
|
function unwrap2(node) {
|
|
5638
|
-
if (node.type ===
|
|
5799
|
+
if (node.type === AST_NODE_TYPES28.TSAsExpression || node.type === AST_NODE_TYPES28.TSSatisfiesExpression) {
|
|
5639
5800
|
return unwrap2(node.expression);
|
|
5640
5801
|
}
|
|
5641
5802
|
return node;
|
|
@@ -5643,14 +5804,14 @@ function unwrap2(node) {
|
|
|
5643
5804
|
function stringValueTexts(node, sourceCode) {
|
|
5644
5805
|
const texts = [];
|
|
5645
5806
|
for (const prop of node.properties) {
|
|
5646
|
-
if (prop.type !==
|
|
5807
|
+
if (prop.type !== AST_NODE_TYPES28.Property) {
|
|
5647
5808
|
return null;
|
|
5648
5809
|
}
|
|
5649
5810
|
if (prop.computed || prop.shorthand || prop.method || prop.kind !== "init") {
|
|
5650
5811
|
return null;
|
|
5651
5812
|
}
|
|
5652
5813
|
const value = prop.value;
|
|
5653
|
-
if (value.type !==
|
|
5814
|
+
if (value.type !== AST_NODE_TYPES28.Literal || typeof value.value !== "string") {
|
|
5654
5815
|
return null;
|
|
5655
5816
|
}
|
|
5656
5817
|
const text = sourceCode.getText(value);
|
|
@@ -5666,7 +5827,7 @@ function resolvesToLocalEnum(node, scope) {
|
|
|
5666
5827
|
const variable = current.variables.find((v) => v.name === node.name);
|
|
5667
5828
|
if (variable !== void 0) {
|
|
5668
5829
|
return variable.defs.some(
|
|
5669
|
-
(def) => def.node.type ===
|
|
5830
|
+
(def) => def.node.type === AST_NODE_TYPES28.TSEnumDeclaration
|
|
5670
5831
|
);
|
|
5671
5832
|
}
|
|
5672
5833
|
current = current.upper;
|
|
@@ -5718,25 +5879,25 @@ var no_zod_native_enum_default = createRule({
|
|
|
5718
5879
|
const zodImportedNames = /* @__PURE__ */ new Map();
|
|
5719
5880
|
function isZodMemberCall(node, api) {
|
|
5720
5881
|
const callee = node.callee;
|
|
5721
|
-
if (callee.type ===
|
|
5882
|
+
if (callee.type === AST_NODE_TYPES28.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES28.Identifier) {
|
|
5722
5883
|
return callee.property.name === api;
|
|
5723
5884
|
}
|
|
5724
|
-
if (callee.type ===
|
|
5885
|
+
if (callee.type === AST_NODE_TYPES28.Identifier) {
|
|
5725
5886
|
return zodImportedNames.get(callee.name) === api;
|
|
5726
5887
|
}
|
|
5727
5888
|
return false;
|
|
5728
5889
|
}
|
|
5729
5890
|
function buildFix(node) {
|
|
5730
5891
|
const callee = node.callee;
|
|
5731
|
-
if (callee.type !==
|
|
5892
|
+
if (callee.type !== AST_NODE_TYPES28.MemberExpression || callee.property.type !== AST_NODE_TYPES28.Identifier) {
|
|
5732
5893
|
return null;
|
|
5733
5894
|
}
|
|
5734
5895
|
const arg = node.arguments[0];
|
|
5735
|
-
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) {
|
|
5736
5897
|
return null;
|
|
5737
5898
|
}
|
|
5738
5899
|
const inner = unwrap2(arg);
|
|
5739
|
-
if (inner.type !==
|
|
5900
|
+
if (inner.type !== AST_NODE_TYPES28.ObjectExpression) {
|
|
5740
5901
|
return null;
|
|
5741
5902
|
}
|
|
5742
5903
|
const values = stringValueTexts(inner, sourceCode);
|
|
@@ -5756,7 +5917,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
5756
5917
|
return;
|
|
5757
5918
|
}
|
|
5758
5919
|
for (const spec of node.specifiers) {
|
|
5759
|
-
if (spec.type ===
|
|
5920
|
+
if (spec.type === AST_NODE_TYPES28.ImportSpecifier && spec.imported.type === AST_NODE_TYPES28.Identifier) {
|
|
5760
5921
|
zodImportedNames.set(spec.local.name, spec.imported.name);
|
|
5761
5922
|
}
|
|
5762
5923
|
}
|
|
@@ -5775,7 +5936,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
5775
5936
|
return;
|
|
5776
5937
|
}
|
|
5777
5938
|
const arg = node.arguments[0];
|
|
5778
|
-
if (arg === void 0 || arg.type !==
|
|
5939
|
+
if (arg === void 0 || arg.type !== AST_NODE_TYPES28.Identifier) {
|
|
5779
5940
|
return;
|
|
5780
5941
|
}
|
|
5781
5942
|
const isEnum = resolvesToLocalEnum(arg, sourceCode.getScope(arg)) || services !== null && resolvesToImportedEnum(arg, services);
|
|
@@ -5792,7 +5953,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
5792
5953
|
});
|
|
5793
5954
|
|
|
5794
5955
|
// src/rules/prefer-constant-time-secret-compare.ts
|
|
5795
|
-
import { AST_NODE_TYPES as
|
|
5956
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES29 } from "@typescript-eslint/utils";
|
|
5796
5957
|
var EQUALITY_OPERATORS = /* @__PURE__ */ new Set(["===", "!==", "==", "!="]);
|
|
5797
5958
|
var SENTINEL_IDENTIFIERS = /* @__PURE__ */ new Set(["undefined", "NaN"]);
|
|
5798
5959
|
var SENTINEL_WORDS = /(^|_)(SENTINEL|EMPTY|NONE|NULL|UNSET|MISSING|PLACEHOLDER|DUMMY|FAKE|EXAMPLE)(_|$)/;
|
|
@@ -5805,36 +5966,36 @@ function isConstantReference(identifier) {
|
|
|
5805
5966
|
}
|
|
5806
5967
|
function isExcludedOperand(node) {
|
|
5807
5968
|
switch (node.type) {
|
|
5808
|
-
case
|
|
5969
|
+
case AST_NODE_TYPES29.Literal:
|
|
5809
5970
|
return true;
|
|
5810
|
-
case
|
|
5971
|
+
case AST_NODE_TYPES29.TemplateLiteral:
|
|
5811
5972
|
return node.expressions.length === 0;
|
|
5812
|
-
case
|
|
5973
|
+
case AST_NODE_TYPES29.Identifier:
|
|
5813
5974
|
return SENTINEL_IDENTIFIERS.has(node.name) || SENTINEL_PREFIX_RE.test(node.name) || isConstantReference(node.name);
|
|
5814
|
-
case
|
|
5815
|
-
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));
|
|
5816
5977
|
default:
|
|
5817
5978
|
return false;
|
|
5818
5979
|
}
|
|
5819
5980
|
}
|
|
5820
5981
|
function operandName(node) {
|
|
5821
|
-
if (node.type ===
|
|
5982
|
+
if (node.type === AST_NODE_TYPES29.Identifier) {
|
|
5822
5983
|
return node.name;
|
|
5823
5984
|
}
|
|
5824
|
-
if (node.type ===
|
|
5985
|
+
if (node.type === AST_NODE_TYPES29.MemberExpression && !node.computed && node.property.type === AST_NODE_TYPES29.Identifier) {
|
|
5825
5986
|
return node.property.name;
|
|
5826
5987
|
}
|
|
5827
5988
|
return null;
|
|
5828
5989
|
}
|
|
5829
5990
|
function isSecretOperand(node) {
|
|
5830
|
-
if (node.type ===
|
|
5991
|
+
if (node.type === AST_NODE_TYPES29.TemplateLiteral) {
|
|
5831
5992
|
return node.expressions.some((expression) => isSecretOperand(expression));
|
|
5832
5993
|
}
|
|
5833
5994
|
const name = operandName(node);
|
|
5834
5995
|
return name !== null && isAuthSecretName(name);
|
|
5835
5996
|
}
|
|
5836
5997
|
function secretNameOf(node) {
|
|
5837
|
-
if (node.type ===
|
|
5998
|
+
if (node.type === AST_NODE_TYPES29.TemplateLiteral) {
|
|
5838
5999
|
for (const expression of node.expressions) {
|
|
5839
6000
|
const nested = secretNameOf(expression);
|
|
5840
6001
|
if (nested !== null) {
|
|
@@ -5887,7 +6048,7 @@ var prefer_constant_time_secret_compare_default = createRule({
|
|
|
5887
6048
|
|
|
5888
6049
|
// src/rules/prefer-discriminated-union.ts
|
|
5889
6050
|
import "@typescript-eslint/utils";
|
|
5890
|
-
import { AST_NODE_TYPES as
|
|
6051
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES30 } from "@typescript-eslint/utils";
|
|
5891
6052
|
var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
5892
6053
|
"success",
|
|
5893
6054
|
"ok",
|
|
@@ -5897,27 +6058,27 @@ var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
|
5897
6058
|
]);
|
|
5898
6059
|
var MIN_OPTIONAL_MEMBERS = 2;
|
|
5899
6060
|
function getMemberName(member) {
|
|
5900
|
-
if (member.type !==
|
|
6061
|
+
if (member.type !== AST_NODE_TYPES30.TSPropertySignature) {
|
|
5901
6062
|
return null;
|
|
5902
6063
|
}
|
|
5903
6064
|
const { key } = member;
|
|
5904
|
-
if (key.type ===
|
|
6065
|
+
if (key.type === AST_NODE_TYPES30.Identifier) {
|
|
5905
6066
|
return key.name;
|
|
5906
6067
|
}
|
|
5907
|
-
if (key.type ===
|
|
6068
|
+
if (key.type === AST_NODE_TYPES30.Literal && typeof key.value === "string") {
|
|
5908
6069
|
return key.value;
|
|
5909
6070
|
}
|
|
5910
6071
|
return null;
|
|
5911
6072
|
}
|
|
5912
6073
|
function isBooleanTyped(member) {
|
|
5913
|
-
return member.typeAnnotation?.typeAnnotation.type ===
|
|
6074
|
+
return member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES30.TSBooleanKeyword;
|
|
5914
6075
|
}
|
|
5915
6076
|
function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
5916
6077
|
let hasStatusBoolean = false;
|
|
5917
6078
|
let optionalCount = 0;
|
|
5918
6079
|
let optionalPayloadCount = 0;
|
|
5919
6080
|
for (const member of typeLiteral.members) {
|
|
5920
|
-
if (member.type !==
|
|
6081
|
+
if (member.type !== AST_NODE_TYPES30.TSPropertySignature) {
|
|
5921
6082
|
continue;
|
|
5922
6083
|
}
|
|
5923
6084
|
if (member.optional) {
|
|
@@ -5959,7 +6120,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
5959
6120
|
TSInterfaceDeclaration(node) {
|
|
5960
6121
|
const synthetic = {
|
|
5961
6122
|
...node.body,
|
|
5962
|
-
type:
|
|
6123
|
+
type: AST_NODE_TYPES30.TSTypeLiteral,
|
|
5963
6124
|
members: node.body.body
|
|
5964
6125
|
};
|
|
5965
6126
|
checkTypeLiteral(synthetic, node);
|
|
@@ -5972,7 +6133,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
5972
6133
|
});
|
|
5973
6134
|
|
|
5974
6135
|
// src/rules/prefer-module-level-constant.ts
|
|
5975
|
-
import { AST_NODE_TYPES as
|
|
6136
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES31 } from "@typescript-eslint/utils";
|
|
5976
6137
|
var DEFAULT_MIN_ELEMENTS = 3;
|
|
5977
6138
|
var MAX_LITERAL_DEPTH = 4;
|
|
5978
6139
|
var IGNORE_PATTERNS2 = [
|
|
@@ -6001,9 +6162,9 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
|
6001
6162
|
"assign"
|
|
6002
6163
|
]);
|
|
6003
6164
|
var FUNCTION_TYPES5 = /* @__PURE__ */ new Set([
|
|
6004
|
-
|
|
6005
|
-
|
|
6006
|
-
|
|
6165
|
+
AST_NODE_TYPES31.FunctionDeclaration,
|
|
6166
|
+
AST_NODE_TYPES31.FunctionExpression,
|
|
6167
|
+
AST_NODE_TYPES31.ArrowFunctionExpression
|
|
6007
6168
|
]);
|
|
6008
6169
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
6009
6170
|
function isIgnoredFile2(filename, sourceText) {
|
|
@@ -6016,14 +6177,14 @@ function isLocalFixtureFile(filename) {
|
|
|
6016
6177
|
return isTestFile(filename) || isStoryFile(filename);
|
|
6017
6178
|
}
|
|
6018
6179
|
function unwrap3(node) {
|
|
6019
|
-
if (node.type ===
|
|
6180
|
+
if (node.type === AST_NODE_TYPES31.TSAsExpression || node.type === AST_NODE_TYPES31.TSSatisfiesExpression || node.type === AST_NODE_TYPES31.TSNonNullExpression) {
|
|
6020
6181
|
return unwrap3(node.expression);
|
|
6021
6182
|
}
|
|
6022
6183
|
return node;
|
|
6023
6184
|
}
|
|
6024
6185
|
var HAS_STATEFUL_FLAG_RE = /[gy]/;
|
|
6025
6186
|
function isRegexLiteral(node) {
|
|
6026
|
-
return node.type ===
|
|
6187
|
+
return node.type === AST_NODE_TYPES31.Literal && "regex" in node && node.regex !== void 0;
|
|
6027
6188
|
}
|
|
6028
6189
|
function isLiteralOnly(node, depth) {
|
|
6029
6190
|
if (depth > MAX_LITERAL_DEPTH) {
|
|
@@ -6031,29 +6192,29 @@ function isLiteralOnly(node, depth) {
|
|
|
6031
6192
|
}
|
|
6032
6193
|
const inner = unwrap3(node);
|
|
6033
6194
|
switch (inner.type) {
|
|
6034
|
-
case
|
|
6195
|
+
case AST_NODE_TYPES31.Literal: {
|
|
6035
6196
|
return !(isRegexLiteral(inner) && HAS_STATEFUL_FLAG_RE.test(inner.regex.flags));
|
|
6036
6197
|
}
|
|
6037
|
-
case
|
|
6198
|
+
case AST_NODE_TYPES31.TemplateLiteral: {
|
|
6038
6199
|
return inner.expressions.length === 0;
|
|
6039
6200
|
}
|
|
6040
|
-
case
|
|
6041
|
-
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";
|
|
6042
6203
|
}
|
|
6043
|
-
case
|
|
6204
|
+
case AST_NODE_TYPES31.ArrayExpression: {
|
|
6044
6205
|
return inner.elements.every(
|
|
6045
|
-
(el) => el !== null && el.type !==
|
|
6206
|
+
(el) => el !== null && el.type !== AST_NODE_TYPES31.SpreadElement && isLiteralOnly(el, depth + 1)
|
|
6046
6207
|
);
|
|
6047
6208
|
}
|
|
6048
|
-
case
|
|
6209
|
+
case AST_NODE_TYPES31.ObjectExpression: {
|
|
6049
6210
|
return inner.properties.every((prop) => {
|
|
6050
|
-
if (prop.type !==
|
|
6211
|
+
if (prop.type !== AST_NODE_TYPES31.Property) {
|
|
6051
6212
|
return false;
|
|
6052
6213
|
}
|
|
6053
6214
|
if (prop.shorthand || prop.method || prop.kind !== "init") {
|
|
6054
6215
|
return false;
|
|
6055
6216
|
}
|
|
6056
|
-
if (prop.computed && prop.key.type !==
|
|
6217
|
+
if (prop.computed && prop.key.type !== AST_NODE_TYPES31.Literal) {
|
|
6057
6218
|
return false;
|
|
6058
6219
|
}
|
|
6059
6220
|
return isLiteralOnly(prop.value, depth + 1);
|
|
@@ -6066,7 +6227,7 @@ function isLiteralOnly(node, depth) {
|
|
|
6066
6227
|
}
|
|
6067
6228
|
function unwrapObjectFreeze(node) {
|
|
6068
6229
|
const inner = unwrap3(node);
|
|
6069
|
-
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) {
|
|
6070
6231
|
return unwrap3(inner.arguments[0]);
|
|
6071
6232
|
}
|
|
6072
6233
|
return inner;
|
|
@@ -6082,19 +6243,19 @@ function classify(init, checkRegex) {
|
|
|
6082
6243
|
}
|
|
6083
6244
|
return { kind: "regex", size: 1 };
|
|
6084
6245
|
}
|
|
6085
|
-
if (node.type ===
|
|
6246
|
+
if (node.type === AST_NODE_TYPES31.ArrayExpression) {
|
|
6086
6247
|
return isLiteralOnly(node, 0) ? { kind: "array", size: node.elements.length } : null;
|
|
6087
6248
|
}
|
|
6088
|
-
if (node.type ===
|
|
6249
|
+
if (node.type === AST_NODE_TYPES31.ObjectExpression) {
|
|
6089
6250
|
return isLiteralOnly(node, 0) ? { kind: "object", size: node.properties.length } : null;
|
|
6090
6251
|
}
|
|
6091
|
-
if (node.type ===
|
|
6252
|
+
if (node.type === AST_NODE_TYPES31.NewExpression && node.callee.type === AST_NODE_TYPES31.Identifier && COLLECTION_CONSTRUCTORS.has(node.callee.name)) {
|
|
6092
6253
|
const arg = node.arguments[0];
|
|
6093
|
-
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) {
|
|
6094
6255
|
return null;
|
|
6095
6256
|
}
|
|
6096
6257
|
const entries = unwrap3(arg);
|
|
6097
|
-
if (entries.type !==
|
|
6258
|
+
if (entries.type !== AST_NODE_TYPES31.ArrayExpression) {
|
|
6098
6259
|
return null;
|
|
6099
6260
|
}
|
|
6100
6261
|
return isLiteralOnly(entries, 0) ? { kind: node.callee.name === "Set" ? "Set" : "Map", size: entries.elements.length } : null;
|
|
@@ -6123,10 +6284,10 @@ var NON_RETAINING_BUILTINS = /* @__PURE__ */ new Map(
|
|
|
6123
6284
|
);
|
|
6124
6285
|
function isNonRetainingBuiltinCall(node, argument) {
|
|
6125
6286
|
const callee = node.callee;
|
|
6126
|
-
if (callee.type ===
|
|
6287
|
+
if (callee.type === AST_NODE_TYPES31.Identifier && callee.name === "structuredClone") {
|
|
6127
6288
|
return true;
|
|
6128
6289
|
}
|
|
6129
|
-
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) {
|
|
6130
6291
|
return false;
|
|
6131
6292
|
}
|
|
6132
6293
|
const members = NON_RETAINING_BUILTINS.get(callee.object.name);
|
|
@@ -6140,38 +6301,38 @@ function isNonRetainingBuiltinCall(node, argument) {
|
|
|
6140
6301
|
}
|
|
6141
6302
|
function isSafeRead(identifier) {
|
|
6142
6303
|
const parent = identifier.parent;
|
|
6143
|
-
if (parent.type ===
|
|
6304
|
+
if (parent.type === AST_NODE_TYPES31.MemberExpression) {
|
|
6144
6305
|
if (parent.object !== identifier) {
|
|
6145
6306
|
return true;
|
|
6146
6307
|
}
|
|
6147
6308
|
const grandparent = parent.parent;
|
|
6148
|
-
if (grandparent.type ===
|
|
6309
|
+
if (grandparent.type === AST_NODE_TYPES31.AssignmentExpression && grandparent.left === parent) {
|
|
6149
6310
|
return false;
|
|
6150
6311
|
}
|
|
6151
|
-
if (grandparent.type ===
|
|
6312
|
+
if (grandparent.type === AST_NODE_TYPES31.UpdateExpression) {
|
|
6152
6313
|
return false;
|
|
6153
6314
|
}
|
|
6154
|
-
if (grandparent.type ===
|
|
6315
|
+
if (grandparent.type === AST_NODE_TYPES31.UnaryExpression && grandparent.operator === "delete") {
|
|
6155
6316
|
return false;
|
|
6156
6317
|
}
|
|
6157
|
-
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) {
|
|
6158
6319
|
return false;
|
|
6159
6320
|
}
|
|
6160
6321
|
return true;
|
|
6161
6322
|
}
|
|
6162
|
-
if (parent.type ===
|
|
6323
|
+
if (parent.type === AST_NODE_TYPES31.ForOfStatement && parent.right === identifier) {
|
|
6163
6324
|
return true;
|
|
6164
6325
|
}
|
|
6165
|
-
if (parent.type ===
|
|
6326
|
+
if (parent.type === AST_NODE_TYPES31.SpreadElement) {
|
|
6166
6327
|
return true;
|
|
6167
6328
|
}
|
|
6168
|
-
if (parent.type ===
|
|
6329
|
+
if (parent.type === AST_NODE_TYPES31.BinaryExpression) {
|
|
6169
6330
|
return true;
|
|
6170
6331
|
}
|
|
6171
|
-
if (parent.type ===
|
|
6332
|
+
if (parent.type === AST_NODE_TYPES31.CallExpression && parent.arguments.includes(identifier) && isNonRetainingBuiltinCall(parent, identifier)) {
|
|
6172
6333
|
return true;
|
|
6173
6334
|
}
|
|
6174
|
-
if (parent.type ===
|
|
6335
|
+
if (parent.type === AST_NODE_TYPES31.UnaryExpression && parent.operator !== "delete") {
|
|
6175
6336
|
return true;
|
|
6176
6337
|
}
|
|
6177
6338
|
return false;
|
|
@@ -6226,7 +6387,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6226
6387
|
if (reference.isWrite()) {
|
|
6227
6388
|
return false;
|
|
6228
6389
|
}
|
|
6229
|
-
if (reference.identifier.type !==
|
|
6390
|
+
if (reference.identifier.type !== AST_NODE_TYPES31.Identifier) {
|
|
6230
6391
|
return false;
|
|
6231
6392
|
}
|
|
6232
6393
|
if (!isSafeRead(reference.identifier)) {
|
|
@@ -6238,10 +6399,10 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6238
6399
|
return {
|
|
6239
6400
|
VariableDeclarator(node) {
|
|
6240
6401
|
const declaration = node.parent;
|
|
6241
|
-
if (declaration.type !==
|
|
6402
|
+
if (declaration.type !== AST_NODE_TYPES31.VariableDeclaration || declaration.kind !== "const" || declaration.declare === true) {
|
|
6242
6403
|
return;
|
|
6243
6404
|
}
|
|
6244
|
-
if (node.id.type !==
|
|
6405
|
+
if (node.id.type !== AST_NODE_TYPES31.Identifier || node.init === null) {
|
|
6245
6406
|
return;
|
|
6246
6407
|
}
|
|
6247
6408
|
if (enclosingFunction2(node) === null) {
|
|
@@ -6268,7 +6429,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6268
6429
|
});
|
|
6269
6430
|
|
|
6270
6431
|
// src/rules/prefer-module-level-schema.ts
|
|
6271
|
-
import { AST_NODE_TYPES as
|
|
6432
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES32 } from "@typescript-eslint/utils";
|
|
6272
6433
|
|
|
6273
6434
|
// src/rules/_zod.ts
|
|
6274
6435
|
var ZOD_PREFIX_RE = /^Z[A-Z]/;
|
|
@@ -6334,9 +6495,9 @@ var I18N_RECEIVER_NAMES = /* @__PURE__ */ new Set([
|
|
|
6334
6495
|
"intl"
|
|
6335
6496
|
]);
|
|
6336
6497
|
var FUNCTION_TYPES6 = /* @__PURE__ */ new Set([
|
|
6337
|
-
|
|
6338
|
-
|
|
6339
|
-
|
|
6498
|
+
AST_NODE_TYPES32.ArrowFunctionExpression,
|
|
6499
|
+
AST_NODE_TYPES32.FunctionDeclaration,
|
|
6500
|
+
AST_NODE_TYPES32.FunctionExpression
|
|
6340
6501
|
]);
|
|
6341
6502
|
function schemaExpression(node) {
|
|
6342
6503
|
let current = node;
|
|
@@ -6345,10 +6506,10 @@ function schemaExpression(node) {
|
|
|
6345
6506
|
if (parent === void 0) {
|
|
6346
6507
|
return current;
|
|
6347
6508
|
}
|
|
6348
|
-
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)) {
|
|
6349
6510
|
return current;
|
|
6350
6511
|
}
|
|
6351
|
-
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) {
|
|
6352
6513
|
current = parent;
|
|
6353
6514
|
continue;
|
|
6354
6515
|
}
|
|
@@ -6399,22 +6560,22 @@ function subtreeSome(root, predicate) {
|
|
|
6399
6560
|
function readsReceiver(node) {
|
|
6400
6561
|
return subtreeSome(
|
|
6401
6562
|
node,
|
|
6402
|
-
(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"
|
|
6403
6564
|
);
|
|
6404
6565
|
}
|
|
6405
6566
|
function buildsLocalizedText(node) {
|
|
6406
6567
|
return subtreeSome(node, (inner) => {
|
|
6407
|
-
if (inner.type ===
|
|
6568
|
+
if (inner.type === AST_NODE_TYPES32.TaggedTemplateExpression) {
|
|
6408
6569
|
return true;
|
|
6409
6570
|
}
|
|
6410
|
-
if (inner.type !==
|
|
6571
|
+
if (inner.type !== AST_NODE_TYPES32.CallExpression) {
|
|
6411
6572
|
return false;
|
|
6412
6573
|
}
|
|
6413
6574
|
const { callee } = inner;
|
|
6414
|
-
if (callee.type ===
|
|
6575
|
+
if (callee.type === AST_NODE_TYPES32.Identifier) {
|
|
6415
6576
|
return I18N_CALLEE_NAMES.has(callee.name);
|
|
6416
6577
|
}
|
|
6417
|
-
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);
|
|
6418
6579
|
});
|
|
6419
6580
|
}
|
|
6420
6581
|
function collectReferences(scope, out) {
|
|
@@ -6471,15 +6632,15 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6471
6632
|
}
|
|
6472
6633
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
6473
6634
|
function isZodCall(node) {
|
|
6474
|
-
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);
|
|
6475
6636
|
}
|
|
6476
6637
|
function isCovered(node) {
|
|
6477
6638
|
let current = node.parent ?? void 0;
|
|
6478
6639
|
while (current !== void 0) {
|
|
6479
|
-
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)) {
|
|
6480
6641
|
return true;
|
|
6481
6642
|
}
|
|
6482
|
-
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))) {
|
|
6483
6644
|
return true;
|
|
6484
6645
|
}
|
|
6485
6646
|
current = current.parent ?? void 0;
|
|
@@ -6494,11 +6655,11 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6494
6655
|
if (parent === void 0) {
|
|
6495
6656
|
return confirmed;
|
|
6496
6657
|
}
|
|
6497
|
-
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) {
|
|
6498
6659
|
current = parent;
|
|
6499
6660
|
continue;
|
|
6500
6661
|
}
|
|
6501
|
-
if (parent.type ===
|
|
6662
|
+
if (parent.type === AST_NODE_TYPES32.CallExpression && parent.arguments.includes(current) && isSchemaComposition(parent)) {
|
|
6502
6663
|
current = schemaExpression(parent);
|
|
6503
6664
|
confirmed = current;
|
|
6504
6665
|
continue;
|
|
@@ -6508,7 +6669,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6508
6669
|
}
|
|
6509
6670
|
function isSchemaComposition(node) {
|
|
6510
6671
|
const { callee } = node;
|
|
6511
|
-
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);
|
|
6512
6673
|
return isCombinator || isZodCall(node);
|
|
6513
6674
|
}
|
|
6514
6675
|
function closesOverNothing(node, enclosing) {
|
|
@@ -6542,13 +6703,13 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6542
6703
|
}
|
|
6543
6704
|
function ownerName(enclosing) {
|
|
6544
6705
|
const parent = enclosing.parent ?? void 0;
|
|
6545
|
-
if (enclosing.type ===
|
|
6706
|
+
if (enclosing.type === AST_NODE_TYPES32.FunctionDeclaration && enclosing.id !== null) {
|
|
6546
6707
|
return enclosing.id.name;
|
|
6547
6708
|
}
|
|
6548
|
-
if (parent !== void 0 && parent.type ===
|
|
6709
|
+
if (parent !== void 0 && parent.type === AST_NODE_TYPES32.VariableDeclarator && parent.id.type === AST_NODE_TYPES32.Identifier) {
|
|
6549
6710
|
return parent.id.name;
|
|
6550
6711
|
}
|
|
6551
|
-
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) {
|
|
6552
6713
|
return parent.key.name;
|
|
6553
6714
|
}
|
|
6554
6715
|
return "this function";
|
|
@@ -6559,7 +6720,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6559
6720
|
return;
|
|
6560
6721
|
}
|
|
6561
6722
|
for (const specifier of node.specifiers) {
|
|
6562
|
-
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") {
|
|
6563
6724
|
zodNamespaces.add(specifier.local.name);
|
|
6564
6725
|
}
|
|
6565
6726
|
}
|
|
@@ -6569,7 +6730,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6569
6730
|
return;
|
|
6570
6731
|
}
|
|
6571
6732
|
const callee = node.callee;
|
|
6572
|
-
if (callee.property.type !==
|
|
6733
|
+
if (callee.property.type !== AST_NODE_TYPES32.Identifier) {
|
|
6573
6734
|
return;
|
|
6574
6735
|
}
|
|
6575
6736
|
const factory = callee.property.name;
|
|
@@ -6584,7 +6745,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6584
6745
|
return;
|
|
6585
6746
|
}
|
|
6586
6747
|
const shape = node.arguments[0];
|
|
6587
|
-
if (shape !== void 0 && shape.type ===
|
|
6748
|
+
if (shape !== void 0 && shape.type === AST_NODE_TYPES32.ObjectExpression && shape.properties.length < minProperties) {
|
|
6588
6749
|
return;
|
|
6589
6750
|
}
|
|
6590
6751
|
const expression = schemaExpression(node);
|
|
@@ -6612,20 +6773,20 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6612
6773
|
});
|
|
6613
6774
|
|
|
6614
6775
|
// src/rules/prefer-non-nullable-collection.ts
|
|
6615
|
-
import { AST_NODE_TYPES as
|
|
6776
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES33 } from "@typescript-eslint/utils";
|
|
6616
6777
|
var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
6617
6778
|
function propertyName(node) {
|
|
6618
6779
|
const key = node.key;
|
|
6619
|
-
if (key.type ===
|
|
6620
|
-
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);
|
|
6621
6782
|
return "collection";
|
|
6622
6783
|
}
|
|
6623
6784
|
function isArrayType(node) {
|
|
6624
|
-
if (node.type ===
|
|
6625
|
-
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);
|
|
6626
6787
|
}
|
|
6627
6788
|
function isNullishType(node) {
|
|
6628
|
-
return node.type ===
|
|
6789
|
+
return node.type === AST_NODE_TYPES33.TSNullKeyword || node.type === AST_NODE_TYPES33.TSUndefinedKeyword;
|
|
6629
6790
|
}
|
|
6630
6791
|
function isNullableArrayOnly(node) {
|
|
6631
6792
|
const values = node.types.filter((member) => !isNullishType(member));
|
|
@@ -6652,7 +6813,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
6652
6813
|
function checkOptionalProperty(node) {
|
|
6653
6814
|
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
6654
6815
|
if (annotation === void 0) return;
|
|
6655
|
-
if (annotation.type !==
|
|
6816
|
+
if (annotation.type !== AST_NODE_TYPES33.TSUnionType || !isNullableArrayOnly(annotation)) {
|
|
6656
6817
|
return;
|
|
6657
6818
|
}
|
|
6658
6819
|
context.report({
|
|
@@ -6665,7 +6826,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
6665
6826
|
TSPropertySignature: checkOptionalProperty,
|
|
6666
6827
|
PropertyDefinition: checkOptionalProperty,
|
|
6667
6828
|
TSTypeAliasDeclaration(node) {
|
|
6668
|
-
if (node.typeAnnotation.type !==
|
|
6829
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES33.TSUnionType) return;
|
|
6669
6830
|
if (!isNullableArrayOnly(node.typeAnnotation)) return;
|
|
6670
6831
|
context.report({
|
|
6671
6832
|
node,
|
|
@@ -6678,13 +6839,13 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
6678
6839
|
});
|
|
6679
6840
|
|
|
6680
6841
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
6681
|
-
import { AST_NODE_TYPES as
|
|
6842
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES34 } from "@typescript-eslint/utils";
|
|
6682
6843
|
var unwrap4 = (node) => {
|
|
6683
6844
|
let current = node;
|
|
6684
6845
|
while (current !== null && current !== void 0) {
|
|
6685
|
-
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) {
|
|
6686
6847
|
current = current.expression;
|
|
6687
|
-
} else if (current.type ===
|
|
6848
|
+
} else if (current.type === AST_NODE_TYPES34.ChainExpression) {
|
|
6688
6849
|
current = current.expression;
|
|
6689
6850
|
} else {
|
|
6690
6851
|
break;
|
|
@@ -6699,23 +6860,23 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
6699
6860
|
]);
|
|
6700
6861
|
var isSchemaParseReference = (node) => {
|
|
6701
6862
|
const inner = unwrap4(node);
|
|
6702
|
-
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");
|
|
6703
6864
|
};
|
|
6704
6865
|
var isRawPayloadSource = (node) => {
|
|
6705
6866
|
let current = unwrap4(node);
|
|
6706
6867
|
if (current === null) return false;
|
|
6707
|
-
if (current.type ===
|
|
6868
|
+
if (current.type === AST_NODE_TYPES34.AwaitExpression) {
|
|
6708
6869
|
current = unwrap4(current.argument);
|
|
6709
6870
|
}
|
|
6710
|
-
if (current === null || current.type !==
|
|
6871
|
+
if (current === null || current.type !== AST_NODE_TYPES34.CallExpression) {
|
|
6711
6872
|
return false;
|
|
6712
6873
|
}
|
|
6713
6874
|
const callee = unwrap4(current.callee);
|
|
6714
|
-
if (callee === null || callee.type !==
|
|
6875
|
+
if (callee === null || callee.type !== AST_NODE_TYPES34.MemberExpression) {
|
|
6715
6876
|
return false;
|
|
6716
6877
|
}
|
|
6717
6878
|
const property = unwrap4(callee.property);
|
|
6718
|
-
if (property === null || property.type !==
|
|
6879
|
+
if (property === null || property.type !== AST_NODE_TYPES34.Identifier) {
|
|
6719
6880
|
return false;
|
|
6720
6881
|
}
|
|
6721
6882
|
if (property.name === "json") {
|
|
@@ -6725,7 +6886,7 @@ var isRawPayloadSource = (node) => {
|
|
|
6725
6886
|
return !current.arguments.some(isSchemaParseReference) && isRawPayloadSource(callee.object);
|
|
6726
6887
|
}
|
|
6727
6888
|
const object = unwrap4(callee.object);
|
|
6728
|
-
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.
|
|
6729
6890
|
!isLocalFileRead(current.arguments[0]);
|
|
6730
6891
|
};
|
|
6731
6892
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
@@ -6733,9 +6894,9 @@ var isLocalFileRead = (node) => {
|
|
|
6733
6894
|
let found = false;
|
|
6734
6895
|
const visit = (current) => {
|
|
6735
6896
|
if (found || current === null || current === void 0) return;
|
|
6736
|
-
if (current.type ===
|
|
6897
|
+
if (current.type === AST_NODE_TYPES34.CallExpression) {
|
|
6737
6898
|
const callee = unwrap4(current.callee);
|
|
6738
|
-
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;
|
|
6739
6900
|
if (name !== null && FILE_READ_RE.test(name)) {
|
|
6740
6901
|
found = true;
|
|
6741
6902
|
return;
|
|
@@ -6757,15 +6918,15 @@ var isLocalFileRead = (node) => {
|
|
|
6757
6918
|
var ASSERTION_CALLEE_RE = /^(expect|assert|should|invariant)$/;
|
|
6758
6919
|
var isInsideAssertion = (node) => {
|
|
6759
6920
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
6760
|
-
if (current.type !==
|
|
6921
|
+
if (current.type !== AST_NODE_TYPES34.CallExpression) continue;
|
|
6761
6922
|
let callee = current.callee;
|
|
6762
|
-
while (callee.type ===
|
|
6923
|
+
while (callee.type === AST_NODE_TYPES34.MemberExpression) {
|
|
6763
6924
|
callee = callee.object;
|
|
6764
6925
|
}
|
|
6765
|
-
if (callee.type ===
|
|
6926
|
+
if (callee.type === AST_NODE_TYPES34.CallExpression) {
|
|
6766
6927
|
callee = callee.callee;
|
|
6767
6928
|
}
|
|
6768
|
-
if (callee.type ===
|
|
6929
|
+
if (callee.type === AST_NODE_TYPES34.Identifier && ASSERTION_CALLEE_RE.test(callee.name)) {
|
|
6769
6930
|
return true;
|
|
6770
6931
|
}
|
|
6771
6932
|
}
|
|
@@ -6784,39 +6945,39 @@ var GUARD_NAME_RE = /^(?:is|validate|parse|assert|decode|coerce)[A-Z]/;
|
|
|
6784
6945
|
var isValidationRead = (node) => {
|
|
6785
6946
|
let current = node;
|
|
6786
6947
|
let parent = current.parent;
|
|
6787
|
-
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)) {
|
|
6788
6949
|
current = parent;
|
|
6789
6950
|
parent = parent.parent;
|
|
6790
6951
|
}
|
|
6791
6952
|
if (parent === null || parent === void 0) return false;
|
|
6792
|
-
if (parent.type ===
|
|
6953
|
+
if (parent.type === AST_NODE_TYPES34.UnaryExpression && parent.operator === "typeof" && parent.argument === current) {
|
|
6793
6954
|
return true;
|
|
6794
6955
|
}
|
|
6795
|
-
if (parent.type !==
|
|
6956
|
+
if (parent.type !== AST_NODE_TYPES34.CallExpression || !parent.arguments.some((arg) => arg === current)) {
|
|
6796
6957
|
return false;
|
|
6797
6958
|
}
|
|
6798
6959
|
const callee = parent.callee;
|
|
6799
|
-
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") {
|
|
6800
6961
|
return parent.arguments.length === 1;
|
|
6801
6962
|
}
|
|
6802
|
-
return callee.type ===
|
|
6963
|
+
return callee.type === AST_NODE_TYPES34.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
6803
6964
|
};
|
|
6804
6965
|
var isGuardTestPosition = (node) => {
|
|
6805
6966
|
let current = node;
|
|
6806
6967
|
let parent = current.parent;
|
|
6807
6968
|
while (parent !== void 0 && parent !== null) {
|
|
6808
6969
|
switch (parent.type) {
|
|
6809
|
-
case
|
|
6810
|
-
case
|
|
6811
|
-
case
|
|
6970
|
+
case AST_NODE_TYPES34.UnaryExpression:
|
|
6971
|
+
case AST_NODE_TYPES34.LogicalExpression:
|
|
6972
|
+
case AST_NODE_TYPES34.ChainExpression:
|
|
6812
6973
|
current = parent;
|
|
6813
6974
|
parent = parent.parent;
|
|
6814
6975
|
continue;
|
|
6815
|
-
case
|
|
6816
|
-
case
|
|
6817
|
-
case
|
|
6818
|
-
case
|
|
6819
|
-
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:
|
|
6820
6981
|
return parent.test === current;
|
|
6821
6982
|
default:
|
|
6822
6983
|
return false;
|
|
@@ -6826,7 +6987,7 @@ var isGuardTestPosition = (node) => {
|
|
|
6826
6987
|
};
|
|
6827
6988
|
var isUnvalidatedVariableRef = (node, scope, tracked) => {
|
|
6828
6989
|
const unwrapped = unwrap4(node);
|
|
6829
|
-
if (unwrapped === null || unwrapped.type !==
|
|
6990
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES34.Identifier) {
|
|
6830
6991
|
return false;
|
|
6831
6992
|
}
|
|
6832
6993
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -6869,11 +7030,11 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6869
7030
|
return {
|
|
6870
7031
|
VariableDeclarator(node) {
|
|
6871
7032
|
const scope = context.sourceCode.getScope(node);
|
|
6872
|
-
if (node.id.type ===
|
|
7033
|
+
if (node.id.type === AST_NODE_TYPES34.Identifier) {
|
|
6873
7034
|
trackInitializer(node);
|
|
6874
7035
|
return;
|
|
6875
7036
|
}
|
|
6876
|
-
if (node.id.type ===
|
|
7037
|
+
if (node.id.type === AST_NODE_TYPES34.ObjectPattern || node.id.type === AST_NODE_TYPES34.ArrayPattern) {
|
|
6877
7038
|
if (isRawPayloadSource(node.init)) {
|
|
6878
7039
|
if (!isFullyNarrowedPattern(node)) {
|
|
6879
7040
|
context.report({ node: node.id, messageId: "unparsedJsonAccess" });
|
|
@@ -6887,7 +7048,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6887
7048
|
},
|
|
6888
7049
|
AssignmentExpression(node) {
|
|
6889
7050
|
const scope = context.sourceCode.getScope(node);
|
|
6890
|
-
if (node.left.type ===
|
|
7051
|
+
if (node.left.type === AST_NODE_TYPES34.Identifier) {
|
|
6891
7052
|
const variable = findVariable2(scope, node.left.name);
|
|
6892
7053
|
if (variable === null) return;
|
|
6893
7054
|
if (isRawPayloadSource(node.right)) {
|
|
@@ -6897,7 +7058,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6897
7058
|
}
|
|
6898
7059
|
return;
|
|
6899
7060
|
}
|
|
6900
|
-
if (node.left.type ===
|
|
7061
|
+
if (node.left.type === AST_NODE_TYPES34.ObjectPattern || node.left.type === AST_NODE_TYPES34.ArrayPattern) {
|
|
6901
7062
|
if (isRawPayloadSource(node.right)) {
|
|
6902
7063
|
context.report({
|
|
6903
7064
|
node: node.left,
|
|
@@ -6914,15 +7075,15 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6914
7075
|
}
|
|
6915
7076
|
},
|
|
6916
7077
|
CallExpression(node) {
|
|
6917
|
-
if (node.callee.type !==
|
|
7078
|
+
if (node.callee.type !== AST_NODE_TYPES34.Identifier) return;
|
|
6918
7079
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
6919
7080
|
return;
|
|
6920
7081
|
}
|
|
6921
7082
|
const scope = context.sourceCode.getScope(node);
|
|
6922
7083
|
for (const arg of node.arguments) {
|
|
6923
|
-
if (arg.type ===
|
|
7084
|
+
if (arg.type === AST_NODE_TYPES34.SpreadElement) continue;
|
|
6924
7085
|
const unwrapped = unwrap4(arg);
|
|
6925
|
-
if (unwrapped === null || unwrapped.type !==
|
|
7086
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES34.Identifier) {
|
|
6926
7087
|
continue;
|
|
6927
7088
|
}
|
|
6928
7089
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -6936,13 +7097,13 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6936
7097
|
const obj = unwrap4(node.object);
|
|
6937
7098
|
if (isRawPayloadSource(obj)) {
|
|
6938
7099
|
const parent = node.parent;
|
|
6939
|
-
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))) {
|
|
6940
7101
|
return;
|
|
6941
7102
|
}
|
|
6942
7103
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
6943
7104
|
return;
|
|
6944
7105
|
}
|
|
6945
|
-
if (obj !== null && obj.type ===
|
|
7106
|
+
if (obj !== null && obj.type === AST_NODE_TYPES34.Identifier && isUnvalidatedVariableRef(obj, scope, unvalidatedVariables)) {
|
|
6946
7107
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
6947
7108
|
const variable = findVariable2(scope, obj.name);
|
|
6948
7109
|
if (variable !== null) {
|
|
@@ -6955,7 +7116,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6955
7116
|
});
|
|
6956
7117
|
|
|
6957
7118
|
// src/rules/prefer-semantic-colors.ts
|
|
6958
|
-
import { AST_NODE_TYPES as
|
|
7119
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES35 } from "@typescript-eslint/utils";
|
|
6959
7120
|
import { existsSync, readdirSync, readFileSync } from "fs";
|
|
6960
7121
|
import { dirname, join, parse } from "path";
|
|
6961
7122
|
|
|
@@ -7055,8 +7216,8 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
7055
7216
|
]);
|
|
7056
7217
|
function jsxElementName(node) {
|
|
7057
7218
|
const name = node.openingElement.name;
|
|
7058
|
-
if (name.type ===
|
|
7059
|
-
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) {
|
|
7060
7221
|
return name.property.name;
|
|
7061
7222
|
}
|
|
7062
7223
|
return null;
|
|
@@ -7082,7 +7243,7 @@ var EMAIL_OR_PDF_IMPORT_RE = /@react-(?:email|pdf)\//;
|
|
|
7082
7243
|
var isInsideSvg = (node) => {
|
|
7083
7244
|
let current = node.parent;
|
|
7084
7245
|
while (current !== void 0 && current !== null) {
|
|
7085
|
-
if (current.type ===
|
|
7246
|
+
if (current.type === AST_NODE_TYPES35.JSXElement) {
|
|
7086
7247
|
const name = jsxElementName(current);
|
|
7087
7248
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
7088
7249
|
}
|
|
@@ -7093,7 +7254,7 @@ var isInsideSvg = (node) => {
|
|
|
7093
7254
|
var isInsideIconFactoryPath = (node) => {
|
|
7094
7255
|
let current = node.parent;
|
|
7095
7256
|
while (current !== void 0 && current !== null) {
|
|
7096
|
-
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") {
|
|
7097
7258
|
return true;
|
|
7098
7259
|
}
|
|
7099
7260
|
current = current.parent;
|
|
@@ -7230,8 +7391,8 @@ var hasSemanticTokenSystem = (filename) => {
|
|
|
7230
7391
|
return root !== null && workspaceHasMarker(root);
|
|
7231
7392
|
};
|
|
7232
7393
|
var propName = (key) => {
|
|
7233
|
-
if (key.type ===
|
|
7234
|
-
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;
|
|
7235
7396
|
return null;
|
|
7236
7397
|
};
|
|
7237
7398
|
var prefer_semantic_colors_default = createRule({
|
|
@@ -7276,27 +7437,27 @@ var prefer_semantic_colors_default = createRule({
|
|
|
7276
7437
|
const checkClassNode = (node) => {
|
|
7277
7438
|
if (node === null) return;
|
|
7278
7439
|
switch (node.type) {
|
|
7279
|
-
case
|
|
7440
|
+
case AST_NODE_TYPES35.Literal:
|
|
7280
7441
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
7281
7442
|
break;
|
|
7282
|
-
case
|
|
7443
|
+
case AST_NODE_TYPES35.TemplateLiteral:
|
|
7283
7444
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
7284
7445
|
break;
|
|
7285
|
-
case
|
|
7446
|
+
case AST_NODE_TYPES35.ArrayExpression:
|
|
7286
7447
|
for (const element of node.elements) {
|
|
7287
|
-
if (element !== null && element.type !==
|
|
7448
|
+
if (element !== null && element.type !== AST_NODE_TYPES35.SpreadElement) checkClassNode(element);
|
|
7288
7449
|
}
|
|
7289
7450
|
break;
|
|
7290
|
-
case
|
|
7451
|
+
case AST_NODE_TYPES35.ObjectExpression:
|
|
7291
7452
|
for (const property of node.properties) {
|
|
7292
|
-
if (property.type ===
|
|
7453
|
+
if (property.type === AST_NODE_TYPES35.Property) checkClassNode(property.value);
|
|
7293
7454
|
}
|
|
7294
7455
|
break;
|
|
7295
|
-
case
|
|
7456
|
+
case AST_NODE_TYPES35.ConditionalExpression:
|
|
7296
7457
|
checkClassNode(node.consequent);
|
|
7297
7458
|
checkClassNode(node.alternate);
|
|
7298
7459
|
break;
|
|
7299
|
-
case
|
|
7460
|
+
case AST_NODE_TYPES35.LogicalExpression:
|
|
7300
7461
|
checkClassNode(node.right);
|
|
7301
7462
|
break;
|
|
7302
7463
|
default:
|
|
@@ -7304,29 +7465,29 @@ var prefer_semantic_colors_default = createRule({
|
|
|
7304
7465
|
}
|
|
7305
7466
|
};
|
|
7306
7467
|
const checkColorValueNode = (node) => {
|
|
7307
|
-
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)) {
|
|
7308
7469
|
context.report({ node, messageId: "inlineColor", data: { value: node.value } });
|
|
7309
7470
|
}
|
|
7310
7471
|
};
|
|
7311
7472
|
return {
|
|
7312
7473
|
"JSXAttribute[name.name='className']"(node) {
|
|
7313
7474
|
if (node.value === null) return;
|
|
7314
|
-
if (node.value.type ===
|
|
7315
|
-
else if (node.value.type ===
|
|
7316
|
-
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) {
|
|
7317
7478
|
checkClassNode(node.value.expression);
|
|
7318
7479
|
}
|
|
7319
7480
|
}
|
|
7320
7481
|
},
|
|
7321
7482
|
CallExpression(node) {
|
|
7322
|
-
if (node.callee.type ===
|
|
7483
|
+
if (node.callee.type === AST_NODE_TYPES35.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
7323
7484
|
for (const arg of node.arguments) {
|
|
7324
|
-
if (arg.type !==
|
|
7485
|
+
if (arg.type !== AST_NODE_TYPES35.SpreadElement) checkClassNode(arg);
|
|
7325
7486
|
}
|
|
7326
7487
|
}
|
|
7327
7488
|
},
|
|
7328
7489
|
VariableDeclarator(node) {
|
|
7329
|
-
if (node.id.type ===
|
|
7490
|
+
if (node.id.type === AST_NODE_TYPES35.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
7330
7491
|
checkClassNode(node.init);
|
|
7331
7492
|
}
|
|
7332
7493
|
},
|
|
@@ -7338,9 +7499,9 @@ var prefer_semantic_colors_default = createRule({
|
|
|
7338
7499
|
// Neutral drawing literals and anything inside an SVG defs container are
|
|
7339
7500
|
// structural, not UI tokens, so they never fire.
|
|
7340
7501
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
7341
|
-
if (node.value?.type !==
|
|
7502
|
+
if (node.value?.type !== AST_NODE_TYPES35.Literal) return;
|
|
7342
7503
|
const owner = node.parent.name;
|
|
7343
|
-
if (owner.type ===
|
|
7504
|
+
if (owner.type === AST_NODE_TYPES35.JSXIdentifier && SVG_SHAPE_PRIMITIVES.has(owner.name)) {
|
|
7344
7505
|
return;
|
|
7345
7506
|
}
|
|
7346
7507
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
@@ -7513,7 +7674,7 @@ var prefer_server_actions_default = createRule({
|
|
|
7513
7674
|
// src/rules/prefer-string-literal-union.ts
|
|
7514
7675
|
import {
|
|
7515
7676
|
ESLintUtils as ESLintUtils3,
|
|
7516
|
-
AST_NODE_TYPES as
|
|
7677
|
+
AST_NODE_TYPES as AST_NODE_TYPES36
|
|
7517
7678
|
} from "@typescript-eslint/utils";
|
|
7518
7679
|
import * as ts2 from "typescript";
|
|
7519
7680
|
var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
@@ -7557,19 +7718,19 @@ function isChoiceLikeName(name) {
|
|
|
7557
7718
|
return CHOICE_TOKENS.has(lastWord(name));
|
|
7558
7719
|
}
|
|
7559
7720
|
function keyName(key) {
|
|
7560
|
-
if (key.type ===
|
|
7721
|
+
if (key.type === AST_NODE_TYPES36.Identifier) {
|
|
7561
7722
|
return key.name;
|
|
7562
7723
|
}
|
|
7563
|
-
if (key.type ===
|
|
7724
|
+
if (key.type === AST_NODE_TYPES36.Literal && typeof key.value === "string") {
|
|
7564
7725
|
return key.value;
|
|
7565
7726
|
}
|
|
7566
7727
|
return null;
|
|
7567
7728
|
}
|
|
7568
7729
|
function isStringLiteralMember(t) {
|
|
7569
|
-
return t.type ===
|
|
7730
|
+
return t.type === AST_NODE_TYPES36.TSLiteralType && t.literal.type === AST_NODE_TYPES36.Literal && typeof t.literal.value === "string";
|
|
7570
7731
|
}
|
|
7571
7732
|
function isStringLiteralUnion(node) {
|
|
7572
|
-
if (node?.type !==
|
|
7733
|
+
if (node?.type !== AST_NODE_TYPES36.TSUnionType) {
|
|
7573
7734
|
return false;
|
|
7574
7735
|
}
|
|
7575
7736
|
return node.types.filter(isStringLiteralMember).length >= MIN_CLUSTER_SIZE;
|
|
@@ -7598,12 +7759,12 @@ function bindingSourceExpression(decl) {
|
|
|
7598
7759
|
return ts2.isForOfStatement(node) ? node.expression : node.initializer;
|
|
7599
7760
|
}
|
|
7600
7761
|
function refKey(node) {
|
|
7601
|
-
if (node.type ===
|
|
7762
|
+
if (node.type === AST_NODE_TYPES36.Identifier) {
|
|
7602
7763
|
return node.name;
|
|
7603
7764
|
}
|
|
7604
|
-
if (node.type ===
|
|
7765
|
+
if (node.type === AST_NODE_TYPES36.MemberExpression && !node.computed) {
|
|
7605
7766
|
const inner = refKey(node.object);
|
|
7606
|
-
if (inner === null || node.property.type !==
|
|
7767
|
+
if (inner === null || node.property.type !== AST_NODE_TYPES36.Identifier) {
|
|
7607
7768
|
return null;
|
|
7608
7769
|
}
|
|
7609
7770
|
return `${inner}.${node.property.name}`;
|
|
@@ -7611,7 +7772,7 @@ function refKey(node) {
|
|
|
7611
7772
|
return null;
|
|
7612
7773
|
}
|
|
7613
7774
|
function strLiteral(node) {
|
|
7614
|
-
if (node.type ===
|
|
7775
|
+
if (node.type === AST_NODE_TYPES36.Literal && typeof node.value === "string") {
|
|
7615
7776
|
return node.value;
|
|
7616
7777
|
}
|
|
7617
7778
|
return null;
|
|
@@ -7764,7 +7925,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
7764
7925
|
containersWithUnion.add(container);
|
|
7765
7926
|
return;
|
|
7766
7927
|
}
|
|
7767
|
-
if (typeNode?.type !==
|
|
7928
|
+
if (typeNode?.type !== AST_NODE_TYPES36.TSStringKeyword) {
|
|
7768
7929
|
return;
|
|
7769
7930
|
}
|
|
7770
7931
|
const name = keyName(key);
|
|
@@ -7852,10 +8013,10 @@ var prefer_string_literal_union_default = createRule({
|
|
|
7852
8013
|
}
|
|
7853
8014
|
};
|
|
7854
8015
|
function refKeyText(node) {
|
|
7855
|
-
if (node.type ===
|
|
8016
|
+
if (node.type === AST_NODE_TYPES36.BinaryExpression) {
|
|
7856
8017
|
return refKey(node.left) ?? refKey(node.right) ?? "value";
|
|
7857
8018
|
}
|
|
7858
|
-
if (node.type ===
|
|
8019
|
+
if (node.type === AST_NODE_TYPES36.SwitchStatement) {
|
|
7859
8020
|
return refKey(node.discriminant) ?? "value";
|
|
7860
8021
|
}
|
|
7861
8022
|
return "value";
|
|
@@ -7864,7 +8025,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
7864
8025
|
});
|
|
7865
8026
|
|
|
7866
8027
|
// src/rules/prefer-whole-object-assertion.ts
|
|
7867
|
-
import { AST_NODE_TYPES as
|
|
8028
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES37 } from "@typescript-eslint/utils";
|
|
7868
8029
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
7869
8030
|
var ARRAY_MATCHERS = /* @__PURE__ */ new Set(["toEqual", "toStrictEqual"]);
|
|
7870
8031
|
var COLLECTION_PROPERTIES = /* @__PURE__ */ new Set(["length", "size"]);
|
|
@@ -7873,11 +8034,11 @@ var NUMERIC_SIGNS2 = /* @__PURE__ */ new Set(["-", "+"]);
|
|
|
7873
8034
|
var MIN_RUN_LENGTH = 2;
|
|
7874
8035
|
function literalText(node, getText) {
|
|
7875
8036
|
switch (node.type) {
|
|
7876
|
-
case
|
|
8037
|
+
case AST_NODE_TYPES37.Literal:
|
|
7877
8038
|
return "regex" in node ? null : getText(node);
|
|
7878
|
-
case
|
|
8039
|
+
case AST_NODE_TYPES37.TemplateLiteral:
|
|
7879
8040
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
7880
|
-
case
|
|
8041
|
+
case AST_NODE_TYPES37.UnaryExpression:
|
|
7881
8042
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
7882
8043
|
default:
|
|
7883
8044
|
return null;
|
|
@@ -7885,15 +8046,15 @@ function literalText(node, getText) {
|
|
|
7885
8046
|
}
|
|
7886
8047
|
function isPureReceiver(node) {
|
|
7887
8048
|
switch (node.type) {
|
|
7888
|
-
case
|
|
7889
|
-
case
|
|
8049
|
+
case AST_NODE_TYPES37.Identifier:
|
|
8050
|
+
case AST_NODE_TYPES37.ThisExpression:
|
|
7890
8051
|
return true;
|
|
7891
|
-
case
|
|
8052
|
+
case AST_NODE_TYPES37.MemberExpression:
|
|
7892
8053
|
if (node.optional) {
|
|
7893
8054
|
return false;
|
|
7894
8055
|
}
|
|
7895
8056
|
if (node.computed) {
|
|
7896
|
-
return node.property.type ===
|
|
8057
|
+
return node.property.type === AST_NODE_TYPES37.Literal && isPureReceiver(node.object);
|
|
7897
8058
|
}
|
|
7898
8059
|
return isPureReceiver(node.object);
|
|
7899
8060
|
default:
|
|
@@ -7901,7 +8062,7 @@ function isPureReceiver(node) {
|
|
|
7901
8062
|
}
|
|
7902
8063
|
}
|
|
7903
8064
|
function literalIndex(node) {
|
|
7904
|
-
if (node.type !==
|
|
8065
|
+
if (node.type !== AST_NODE_TYPES37.Literal || typeof node.value !== "number") {
|
|
7905
8066
|
return null;
|
|
7906
8067
|
}
|
|
7907
8068
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
@@ -7927,24 +8088,24 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
7927
8088
|
}
|
|
7928
8089
|
const { sourceCode } = context;
|
|
7929
8090
|
function parseAssertion(statement) {
|
|
7930
|
-
if (statement.type !==
|
|
8091
|
+
if (statement.type !== AST_NODE_TYPES37.ExpressionStatement) {
|
|
7931
8092
|
return null;
|
|
7932
8093
|
}
|
|
7933
8094
|
const call = statement.expression;
|
|
7934
|
-
if (call.type !==
|
|
8095
|
+
if (call.type !== AST_NODE_TYPES37.CallExpression) {
|
|
7935
8096
|
return null;
|
|
7936
8097
|
}
|
|
7937
8098
|
const callee = call.callee;
|
|
7938
|
-
if (callee.type !==
|
|
8099
|
+
if (callee.type !== AST_NODE_TYPES37.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES37.Identifier) {
|
|
7939
8100
|
return null;
|
|
7940
8101
|
}
|
|
7941
8102
|
const matcher = callee.property.name;
|
|
7942
8103
|
const expectCall = callee.object;
|
|
7943
|
-
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) {
|
|
7944
8105
|
return null;
|
|
7945
8106
|
}
|
|
7946
8107
|
const actual = expectCall.arguments[0];
|
|
7947
|
-
if (actual === void 0 || actual.type !==
|
|
8108
|
+
if (actual === void 0 || actual.type !== AST_NODE_TYPES37.MemberExpression || actual.optional) {
|
|
7948
8109
|
return null;
|
|
7949
8110
|
}
|
|
7950
8111
|
if (!isPureReceiver(actual.object)) {
|
|
@@ -7958,7 +8119,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
7958
8119
|
}
|
|
7959
8120
|
key = { kind: "index", index };
|
|
7960
8121
|
} else {
|
|
7961
|
-
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)) {
|
|
7962
8123
|
return null;
|
|
7963
8124
|
}
|
|
7964
8125
|
key = { kind: "property", name: actual.property.name };
|
|
@@ -7970,7 +8131,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
7970
8131
|
return null;
|
|
7971
8132
|
}
|
|
7972
8133
|
const expected = call.arguments[0];
|
|
7973
|
-
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) {
|
|
7974
8135
|
return null;
|
|
7975
8136
|
}
|
|
7976
8137
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
@@ -8085,7 +8246,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8085
8246
|
});
|
|
8086
8247
|
|
|
8087
8248
|
// src/rules/prefer-zod-enum.ts
|
|
8088
|
-
import { AST_NODE_TYPES as
|
|
8249
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES38 } from "@typescript-eslint/utils";
|
|
8089
8250
|
var prefer_zod_enum_default = createRule({
|
|
8090
8251
|
name: "prefer-zod-enum",
|
|
8091
8252
|
meta: {
|
|
@@ -8105,20 +8266,20 @@ var prefer_zod_enum_default = createRule({
|
|
|
8105
8266
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
8106
8267
|
function enumValues(node) {
|
|
8107
8268
|
const callee = node.callee;
|
|
8108
|
-
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) {
|
|
8109
8270
|
return null;
|
|
8110
8271
|
}
|
|
8111
8272
|
const argument = node.arguments[0];
|
|
8112
|
-
if (argument === void 0 || argument.type !==
|
|
8273
|
+
if (argument === void 0 || argument.type !== AST_NODE_TYPES38.ArrayExpression || argument.elements.length === 0) {
|
|
8113
8274
|
return null;
|
|
8114
8275
|
}
|
|
8115
8276
|
const values = [];
|
|
8116
8277
|
for (const element of argument.elements) {
|
|
8117
|
-
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") {
|
|
8118
8279
|
return null;
|
|
8119
8280
|
}
|
|
8120
8281
|
const value = element.arguments[0];
|
|
8121
|
-
if (value === void 0 || value.type !==
|
|
8282
|
+
if (value === void 0 || value.type !== AST_NODE_TYPES38.Literal || typeof value.value !== "string") {
|
|
8122
8283
|
return null;
|
|
8123
8284
|
}
|
|
8124
8285
|
values.push(value);
|
|
@@ -8127,11 +8288,11 @@ var prefer_zod_enum_default = createRule({
|
|
|
8127
8288
|
}
|
|
8128
8289
|
function buildFix(node, values) {
|
|
8129
8290
|
const argument = node.arguments[0];
|
|
8130
|
-
if (argument === void 0 || argument.type !==
|
|
8291
|
+
if (argument === void 0 || argument.type !== AST_NODE_TYPES38.ArrayExpression || sourceCode.getCommentsInside(argument).length > 0) {
|
|
8131
8292
|
return void 0;
|
|
8132
8293
|
}
|
|
8133
8294
|
const callee = node.callee;
|
|
8134
|
-
if (callee.type !==
|
|
8295
|
+
if (callee.type !== AST_NODE_TYPES38.MemberExpression || callee.property.type !== AST_NODE_TYPES38.Identifier) {
|
|
8135
8296
|
return void 0;
|
|
8136
8297
|
}
|
|
8137
8298
|
return (fixer) => [
|
|
@@ -8148,7 +8309,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
8148
8309
|
return;
|
|
8149
8310
|
}
|
|
8150
8311
|
for (const specifier of node.specifiers) {
|
|
8151
|
-
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") {
|
|
8152
8313
|
zodNamespaces.add(specifier.local.name);
|
|
8153
8314
|
}
|
|
8154
8315
|
}
|
|
@@ -8170,7 +8331,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
8170
8331
|
});
|
|
8171
8332
|
|
|
8172
8333
|
// src/rules/prefer-zod-infer.ts
|
|
8173
|
-
import { AST_NODE_TYPES as
|
|
8334
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES39 } from "@typescript-eslint/utils";
|
|
8174
8335
|
var SHAPE_PRESERVING_METHODS = /* @__PURE__ */ new Set([
|
|
8175
8336
|
"describe",
|
|
8176
8337
|
"refine",
|
|
@@ -8207,44 +8368,44 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
8207
8368
|
"Schema"
|
|
8208
8369
|
]);
|
|
8209
8370
|
var LEAF_NODE_TYPES = {
|
|
8210
|
-
string: [
|
|
8211
|
-
email: [
|
|
8212
|
-
url: [
|
|
8213
|
-
uuid: [
|
|
8214
|
-
ulid: [
|
|
8215
|
-
cuid: [
|
|
8216
|
-
cuid2: [
|
|
8217
|
-
nanoid: [
|
|
8218
|
-
iso: [
|
|
8219
|
-
number: [
|
|
8220
|
-
int: [
|
|
8221
|
-
float32: [
|
|
8222
|
-
float64: [
|
|
8223
|
-
boolean: [
|
|
8224
|
-
bigint: [
|
|
8225
|
-
symbol: [
|
|
8226
|
-
any: [
|
|
8227
|
-
unknown: [
|
|
8228
|
-
never: [
|
|
8229
|
-
void: [
|
|
8230
|
-
null: [
|
|
8231
|
-
undefined: [
|
|
8232
|
-
literal: [
|
|
8233
|
-
date: [
|
|
8234
|
-
array: [
|
|
8235
|
-
tuple: [
|
|
8236
|
-
object: [
|
|
8237
|
-
strictObject: [
|
|
8238
|
-
looseObject: [
|
|
8239
|
-
record: [
|
|
8240
|
-
map: [
|
|
8241
|
-
set: [
|
|
8242
|
-
promise: [
|
|
8243
|
-
enum: [
|
|
8244
|
-
nativeEnum: [
|
|
8245
|
-
union: [
|
|
8246
|
-
discriminatedUnion: [
|
|
8247
|
-
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]
|
|
8248
8409
|
};
|
|
8249
8410
|
function normalizeSchemaName(name) {
|
|
8250
8411
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -8253,20 +8414,20 @@ function normalizeTypeName(name) {
|
|
|
8253
8414
|
return name.replace(/Type$/, "").toLowerCase();
|
|
8254
8415
|
}
|
|
8255
8416
|
function unwrapNullish(annotation) {
|
|
8256
|
-
if (annotation.type !==
|
|
8417
|
+
if (annotation.type !== AST_NODE_TYPES39.TSUnionType) {
|
|
8257
8418
|
return {
|
|
8258
8419
|
core: annotation,
|
|
8259
|
-
nullable: annotation.type ===
|
|
8420
|
+
nullable: annotation.type === AST_NODE_TYPES39.TSNullKeyword
|
|
8260
8421
|
};
|
|
8261
8422
|
}
|
|
8262
8423
|
const rest = [];
|
|
8263
8424
|
let nullable = false;
|
|
8264
8425
|
for (const member of annotation.types) {
|
|
8265
|
-
if (member.type ===
|
|
8426
|
+
if (member.type === AST_NODE_TYPES39.TSNullKeyword) {
|
|
8266
8427
|
nullable = true;
|
|
8267
8428
|
continue;
|
|
8268
8429
|
}
|
|
8269
|
-
if (member.type ===
|
|
8430
|
+
if (member.type === AST_NODE_TYPES39.TSUndefinedKeyword) {
|
|
8270
8431
|
continue;
|
|
8271
8432
|
}
|
|
8272
8433
|
rest.push(member);
|
|
@@ -8331,14 +8492,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
8331
8492
|
function zodCallChain(node) {
|
|
8332
8493
|
const chain = [];
|
|
8333
8494
|
let current = node;
|
|
8334
|
-
while (current.type ===
|
|
8495
|
+
while (current.type === AST_NODE_TYPES39.CallExpression) {
|
|
8335
8496
|
const callee = current.callee;
|
|
8336
|
-
if (callee.type !==
|
|
8497
|
+
if (callee.type !== AST_NODE_TYPES39.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES39.Identifier) {
|
|
8337
8498
|
return null;
|
|
8338
8499
|
}
|
|
8339
8500
|
chain.push(current);
|
|
8340
8501
|
const receiver = callee.object;
|
|
8341
|
-
if (receiver.type ===
|
|
8502
|
+
if (receiver.type === AST_NODE_TYPES39.Identifier) {
|
|
8342
8503
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
8343
8504
|
}
|
|
8344
8505
|
current = receiver;
|
|
@@ -8347,19 +8508,19 @@ var prefer_zod_infer_default = createRule({
|
|
|
8347
8508
|
}
|
|
8348
8509
|
function methodName(call) {
|
|
8349
8510
|
const callee = call.callee;
|
|
8350
|
-
return callee.type ===
|
|
8511
|
+
return callee.type === AST_NODE_TYPES39.MemberExpression && callee.property.type === AST_NODE_TYPES39.Identifier ? callee.property.name : "";
|
|
8351
8512
|
}
|
|
8352
8513
|
function schemaField(node) {
|
|
8353
8514
|
const modifiers = [];
|
|
8354
8515
|
let current = node;
|
|
8355
8516
|
let leaf = null;
|
|
8356
|
-
while (current.type ===
|
|
8517
|
+
while (current.type === AST_NODE_TYPES39.CallExpression) {
|
|
8357
8518
|
const callee = current.callee;
|
|
8358
|
-
if (callee.type !==
|
|
8519
|
+
if (callee.type !== AST_NODE_TYPES39.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES39.Identifier) {
|
|
8359
8520
|
break;
|
|
8360
8521
|
}
|
|
8361
8522
|
const receiver = callee.object;
|
|
8362
|
-
if (receiver.type ===
|
|
8523
|
+
if (receiver.type === AST_NODE_TYPES39.Identifier && zodNamespaces.has(receiver.name)) {
|
|
8363
8524
|
leaf = callee.property.name;
|
|
8364
8525
|
break;
|
|
8365
8526
|
}
|
|
@@ -8390,16 +8551,16 @@ var prefer_zod_infer_default = createRule({
|
|
|
8390
8551
|
return null;
|
|
8391
8552
|
}
|
|
8392
8553
|
const shape = base.arguments[0];
|
|
8393
|
-
if (shape === void 0 || shape.type !==
|
|
8554
|
+
if (shape === void 0 || shape.type !== AST_NODE_TYPES39.ObjectExpression) {
|
|
8394
8555
|
return null;
|
|
8395
8556
|
}
|
|
8396
8557
|
const fields = /* @__PURE__ */ new Map();
|
|
8397
8558
|
for (const property of shape.properties) {
|
|
8398
|
-
if (property.type !==
|
|
8559
|
+
if (property.type !== AST_NODE_TYPES39.Property || property.computed) {
|
|
8399
8560
|
return null;
|
|
8400
8561
|
}
|
|
8401
8562
|
const { key } = property;
|
|
8402
|
-
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;
|
|
8403
8564
|
if (name === null) {
|
|
8404
8565
|
return null;
|
|
8405
8566
|
}
|
|
@@ -8410,11 +8571,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
8410
8571
|
function typeMembers(members) {
|
|
8411
8572
|
const result = /* @__PURE__ */ new Map();
|
|
8412
8573
|
for (const member of members) {
|
|
8413
|
-
if (member.type !==
|
|
8574
|
+
if (member.type !== AST_NODE_TYPES39.TSPropertySignature || member.computed) {
|
|
8414
8575
|
return null;
|
|
8415
8576
|
}
|
|
8416
8577
|
const { key } = member;
|
|
8417
|
-
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;
|
|
8418
8579
|
if (name === null) {
|
|
8419
8580
|
return null;
|
|
8420
8581
|
}
|
|
@@ -8428,8 +8589,8 @@ var prefer_zod_infer_default = createRule({
|
|
|
8428
8589
|
return result.size === 0 ? null : result;
|
|
8429
8590
|
}
|
|
8430
8591
|
function collectConstrainedNames(node) {
|
|
8431
|
-
if (node.type ===
|
|
8432
|
-
if (node.typeName.type ===
|
|
8592
|
+
if (node.type === AST_NODE_TYPES39.TSTypeReference) {
|
|
8593
|
+
if (node.typeName.type === AST_NODE_TYPES39.Identifier) {
|
|
8433
8594
|
constrainedTypeNames.add(node.typeName.name);
|
|
8434
8595
|
}
|
|
8435
8596
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -8437,11 +8598,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
8437
8598
|
}
|
|
8438
8599
|
return;
|
|
8439
8600
|
}
|
|
8440
|
-
if (node.type ===
|
|
8601
|
+
if (node.type === AST_NODE_TYPES39.TSArrayType) {
|
|
8441
8602
|
collectConstrainedNames(node.elementType);
|
|
8442
8603
|
return;
|
|
8443
8604
|
}
|
|
8444
|
-
if (node.type ===
|
|
8605
|
+
if (node.type === AST_NODE_TYPES39.TSUnionType || node.type === AST_NODE_TYPES39.TSIntersectionType) {
|
|
8445
8606
|
for (const member of node.types) {
|
|
8446
8607
|
collectConstrainedNames(member);
|
|
8447
8608
|
}
|
|
@@ -8485,13 +8646,13 @@ var prefer_zod_infer_default = createRule({
|
|
|
8485
8646
|
return;
|
|
8486
8647
|
}
|
|
8487
8648
|
for (const specifier of node.specifiers) {
|
|
8488
|
-
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") {
|
|
8489
8650
|
zodNamespaces.add(specifier.local.name);
|
|
8490
8651
|
}
|
|
8491
8652
|
}
|
|
8492
8653
|
},
|
|
8493
8654
|
VariableDeclarator(node) {
|
|
8494
|
-
if (node.id.type !==
|
|
8655
|
+
if (node.id.type !== AST_NODE_TYPES39.Identifier || node.init == null) {
|
|
8495
8656
|
return;
|
|
8496
8657
|
}
|
|
8497
8658
|
const fields = schemaFields(node.init);
|
|
@@ -8501,14 +8662,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
8501
8662
|
},
|
|
8502
8663
|
/** Guard (f): `XSchema.transform(...)` anywhere in the module. */
|
|
8503
8664
|
"MemberExpression[computed=false]"(node) {
|
|
8504
|
-
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)) {
|
|
8505
8666
|
reshapedSchemaNames.add(node.object.name);
|
|
8506
8667
|
}
|
|
8507
8668
|
},
|
|
8508
8669
|
/** Guard (c): `z.ZodType<T>` and every other type argument it carries. */
|
|
8509
8670
|
TSTypeReference(node) {
|
|
8510
8671
|
const { typeName } = node;
|
|
8511
|
-
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;
|
|
8512
8673
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
8513
8674
|
return;
|
|
8514
8675
|
}
|
|
@@ -8526,7 +8687,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
8526
8687
|
}
|
|
8527
8688
|
},
|
|
8528
8689
|
TSTypeAliasDeclaration(node) {
|
|
8529
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
8690
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== AST_NODE_TYPES39.TSTypeLiteral) {
|
|
8530
8691
|
return;
|
|
8531
8692
|
}
|
|
8532
8693
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -8571,10 +8732,10 @@ var prefer_zod_infer_default = createRule({
|
|
|
8571
8732
|
});
|
|
8572
8733
|
|
|
8573
8734
|
// src/rules/require-assert-never.ts
|
|
8574
|
-
import { AST_NODE_TYPES as
|
|
8735
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES40 } from "@typescript-eslint/utils";
|
|
8575
8736
|
var isRuntimeHandlingStatement = (statement) => {
|
|
8576
|
-
if (statement.type ===
|
|
8577
|
-
if (statement.type ===
|
|
8737
|
+
if (statement.type === AST_NODE_TYPES40.EmptyStatement) return false;
|
|
8738
|
+
if (statement.type === AST_NODE_TYPES40.BlockStatement) {
|
|
8578
8739
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
8579
8740
|
}
|
|
8580
8741
|
return true;
|
|
@@ -8590,7 +8751,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
8590
8751
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
8591
8752
|
}
|
|
8592
8753
|
const only = defaultCase.consequent[0];
|
|
8593
|
-
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) {
|
|
8594
8755
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
8595
8756
|
}
|
|
8596
8757
|
return false;
|
|
@@ -8630,7 +8791,7 @@ var require_assert_never_default = createRule({
|
|
|
8630
8791
|
});
|
|
8631
8792
|
|
|
8632
8793
|
// src/rules/require-fetch-timeout.ts
|
|
8633
|
-
import { AST_NODE_TYPES as
|
|
8794
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES41, ASTUtils as ASTUtils2 } from "@typescript-eslint/utils";
|
|
8634
8795
|
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set([
|
|
8635
8796
|
"globalThis",
|
|
8636
8797
|
"window",
|
|
@@ -8646,14 +8807,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
8646
8807
|
return false;
|
|
8647
8808
|
}
|
|
8648
8809
|
function initProvablyLacksSignal(init) {
|
|
8649
|
-
if (init.type !==
|
|
8810
|
+
if (init.type !== AST_NODE_TYPES41.ObjectExpression) {
|
|
8650
8811
|
return false;
|
|
8651
8812
|
}
|
|
8652
8813
|
for (const prop of init.properties) {
|
|
8653
|
-
if (prop.type ===
|
|
8814
|
+
if (prop.type === AST_NODE_TYPES41.SpreadElement) {
|
|
8654
8815
|
return false;
|
|
8655
8816
|
}
|
|
8656
|
-
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") {
|
|
8657
8818
|
return false;
|
|
8658
8819
|
}
|
|
8659
8820
|
if (prop.computed) {
|
|
@@ -8663,7 +8824,7 @@ function initProvablyLacksSignal(init) {
|
|
|
8663
8824
|
return true;
|
|
8664
8825
|
}
|
|
8665
8826
|
function isStringish(node) {
|
|
8666
|
-
return node.type ===
|
|
8827
|
+
return node.type === AST_NODE_TYPES41.Literal && typeof node.value === "string" || node.type === AST_NODE_TYPES41.TemplateLiteral;
|
|
8667
8828
|
}
|
|
8668
8829
|
var require_fetch_timeout_default = createRule({
|
|
8669
8830
|
name: "require-fetch-timeout",
|
|
@@ -8704,10 +8865,10 @@ var require_fetch_timeout_default = createRule({
|
|
|
8704
8865
|
return variable === null || variable.defs.length === 0;
|
|
8705
8866
|
}
|
|
8706
8867
|
function isGlobalFetchCall2(callee) {
|
|
8707
|
-
if (callee.type ===
|
|
8868
|
+
if (callee.type === AST_NODE_TYPES41.Identifier) {
|
|
8708
8869
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
8709
8870
|
}
|
|
8710
|
-
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);
|
|
8711
8872
|
}
|
|
8712
8873
|
return {
|
|
8713
8874
|
CallExpression(node) {
|
|
@@ -8727,7 +8888,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
8727
8888
|
});
|
|
8728
8889
|
|
|
8729
8890
|
// src/rules/require-interface-for-injected-service.ts
|
|
8730
|
-
import { AST_NODE_TYPES as
|
|
8891
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES42 } from "@typescript-eslint/utils";
|
|
8731
8892
|
var CONFIGISH_TYPE_RE = /(?:Options|Opts|Config|Configuration|Settings|Params|Props|Args|Env|Environment|Callbacks|Flags)$/;
|
|
8732
8893
|
var CONFIGISH_NAME_RE = /^(?:options|opts|config|configuration|settings|params|props|args|env|environment|callbacks|flags|logger|log|clock)$/i;
|
|
8733
8894
|
var HTTP_TRANSPORT_TYPE_RE = /^(?:KyInstance|AxiosInstance|Session)$/;
|
|
@@ -8735,20 +8896,20 @@ var BUILTIN_CONTAINER_TYPE_RE = /^(?:Record|Map|WeakMap|Set|WeakSet|Array|Readon
|
|
|
8735
8896
|
var TRANSPORT_WRAPPER_NAME_RE = /Client$/;
|
|
8736
8897
|
var ROUTER_FACTORY_NAME = "Router";
|
|
8737
8898
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
8738
|
-
var isExportedClass = (node) => node.parent.type ===
|
|
8739
|
-
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}` : "";
|
|
8740
8901
|
var readTypeReference = (annotation) => {
|
|
8741
|
-
if (annotation === void 0 || annotation.type !==
|
|
8902
|
+
if (annotation === void 0 || annotation.type !== AST_NODE_TYPES42.TSTypeReference) return null;
|
|
8742
8903
|
const { typeName } = annotation;
|
|
8743
|
-
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;
|
|
8744
8905
|
if (rightmost === null) return null;
|
|
8745
8906
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
8746
8907
|
};
|
|
8747
8908
|
var namedParameterCollaborator = (annotated) => {
|
|
8748
8909
|
let target = annotated;
|
|
8749
|
-
if (target.type ===
|
|
8750
|
-
if (target.type ===
|
|
8751
|
-
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;
|
|
8752
8913
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
8753
8914
|
if (reference === null) return null;
|
|
8754
8915
|
return { name: target.name, ...reference };
|
|
@@ -8756,8 +8917,8 @@ var namedParameterCollaborator = (annotated) => {
|
|
|
8756
8917
|
var propertySignatureTypes = (members) => {
|
|
8757
8918
|
const types = /* @__PURE__ */ new Map();
|
|
8758
8919
|
for (const member of members) {
|
|
8759
|
-
if (member.type !==
|
|
8760
|
-
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;
|
|
8761
8922
|
const reference = readTypeReference(member.typeAnnotation?.typeAnnotation);
|
|
8762
8923
|
if (reference === null) continue;
|
|
8763
8924
|
types.set(member.key.name, reference);
|
|
@@ -8768,18 +8929,18 @@ var fileTypeIndex = (program) => {
|
|
|
8768
8929
|
const objects = /* @__PURE__ */ new Map();
|
|
8769
8930
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
8770
8931
|
for (const statement of program.body) {
|
|
8771
|
-
const declaration = statement.type ===
|
|
8772
|
-
if (declaration?.type ===
|
|
8932
|
+
const declaration = statement.type === AST_NODE_TYPES42.ExportNamedDeclaration ? statement.declaration : statement;
|
|
8933
|
+
if (declaration?.type === AST_NODE_TYPES42.TSInterfaceDeclaration) {
|
|
8773
8934
|
objects.set(declaration.id.name, propertySignatureTypes(declaration.body.body));
|
|
8774
8935
|
continue;
|
|
8775
8936
|
}
|
|
8776
|
-
if (declaration?.type !==
|
|
8937
|
+
if (declaration?.type !== AST_NODE_TYPES42.TSTypeAliasDeclaration) continue;
|
|
8777
8938
|
const aliased = declaration.typeAnnotation;
|
|
8778
|
-
if (aliased.type ===
|
|
8939
|
+
if (aliased.type === AST_NODE_TYPES42.TSFunctionType || aliased.type === AST_NODE_TYPES42.TSConstructorType) {
|
|
8779
8940
|
functionAliases.add(declaration.id.name);
|
|
8780
8941
|
continue;
|
|
8781
8942
|
}
|
|
8782
|
-
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) : [];
|
|
8783
8944
|
if (literals.length === 0) continue;
|
|
8784
8945
|
const merged = /* @__PURE__ */ new Map();
|
|
8785
8946
|
for (const literal of literals) {
|
|
@@ -8792,10 +8953,10 @@ var fileTypeIndex = (program) => {
|
|
|
8792
8953
|
return { objects, functionAliases };
|
|
8793
8954
|
};
|
|
8794
8955
|
var bagMemberTypes = (annotation, declared) => {
|
|
8795
|
-
if (annotation.type ===
|
|
8956
|
+
if (annotation.type === AST_NODE_TYPES42.TSTypeLiteral) {
|
|
8796
8957
|
return propertySignatureTypes(annotation.members);
|
|
8797
8958
|
}
|
|
8798
|
-
if (annotation.type !==
|
|
8959
|
+
if (annotation.type !== AST_NODE_TYPES42.TSTypeReference || annotation.typeName.type !== AST_NODE_TYPES42.Identifier) {
|
|
8799
8960
|
return null;
|
|
8800
8961
|
}
|
|
8801
8962
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
@@ -8807,11 +8968,11 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
8807
8968
|
if (members === null) return [];
|
|
8808
8969
|
const collaborators = [];
|
|
8809
8970
|
for (const property of pattern.properties) {
|
|
8810
|
-
if (property.type !==
|
|
8811
|
-
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;
|
|
8812
8973
|
const key = property.key.name;
|
|
8813
|
-
const bound = property.value.type ===
|
|
8814
|
-
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;
|
|
8815
8976
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
8816
8977
|
const reference = members.get(key);
|
|
8817
8978
|
if (reference === void 0) continue;
|
|
@@ -8821,8 +8982,8 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
8821
8982
|
};
|
|
8822
8983
|
var parameterCollaborators = (parameter, declared) => {
|
|
8823
8984
|
let target = parameter;
|
|
8824
|
-
if (target.type ===
|
|
8825
|
-
if (target.type ===
|
|
8985
|
+
if (target.type === AST_NODE_TYPES42.AssignmentPattern) target = target.left;
|
|
8986
|
+
if (target.type === AST_NODE_TYPES42.ObjectPattern) {
|
|
8826
8987
|
return objectPatternCollaborators(target, declared);
|
|
8827
8988
|
}
|
|
8828
8989
|
const named2 = namedParameterCollaborator(parameter);
|
|
@@ -8841,17 +9002,17 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
8841
9002
|
let constructedFields = 0;
|
|
8842
9003
|
if (body !== null && body !== void 0) {
|
|
8843
9004
|
for (const statement of body.body) {
|
|
8844
|
-
if (statement.type !==
|
|
9005
|
+
if (statement.type !== AST_NODE_TYPES42.ExpressionStatement) continue;
|
|
8845
9006
|
const expression = statement.expression;
|
|
8846
|
-
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) {
|
|
8847
9008
|
continue;
|
|
8848
9009
|
}
|
|
8849
9010
|
const source = expression.right;
|
|
8850
|
-
if (source.type ===
|
|
9011
|
+
if (source.type === AST_NODE_TYPES42.NewExpression) {
|
|
8851
9012
|
constructedFields += 1;
|
|
8852
|
-
} else if (source.type ===
|
|
9013
|
+
} else if (source.type === AST_NODE_TYPES42.Identifier) {
|
|
8853
9014
|
storedFrom.add(source.name);
|
|
8854
|
-
} else if (source.type ===
|
|
9015
|
+
} else if (source.type === AST_NODE_TYPES42.MemberExpression && source.object.type === AST_NODE_TYPES42.Identifier) {
|
|
8855
9016
|
storedFrom.add(source.object.name);
|
|
8856
9017
|
}
|
|
8857
9018
|
}
|
|
@@ -8859,7 +9020,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
8859
9020
|
const collaborators = [];
|
|
8860
9021
|
for (const parameter of ctor.value.params) {
|
|
8861
9022
|
for (const reference of parameterCollaborators(parameter, declared)) {
|
|
8862
|
-
const stored = parameter.type ===
|
|
9023
|
+
const stored = parameter.type === AST_NODE_TYPES42.TSParameterProperty || storedFrom.has(reference.name);
|
|
8863
9024
|
if (!stored) continue;
|
|
8864
9025
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
8865
9026
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -8893,19 +9054,19 @@ var subtreeHas = (root, found) => {
|
|
|
8893
9054
|
return hit;
|
|
8894
9055
|
};
|
|
8895
9056
|
var isFrameworkWiring = (body) => subtreeHas(body, (node) => {
|
|
8896
|
-
if (node.type ===
|
|
9057
|
+
if (node.type === AST_NODE_TYPES42.CallExpression) {
|
|
8897
9058
|
const { callee } = node;
|
|
8898
|
-
if (callee.type ===
|
|
8899
|
-
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;
|
|
8900
9061
|
}
|
|
8901
|
-
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);
|
|
8902
9063
|
});
|
|
8903
9064
|
var stem2 = (name) => name.replace(/^I(?=[A-Z])/, "").replace(/Impl$/, "");
|
|
8904
9065
|
var fileInterfaceNames = (program) => {
|
|
8905
9066
|
const names = [];
|
|
8906
9067
|
for (const statement of program.body) {
|
|
8907
|
-
const declaration = statement.type ===
|
|
8908
|
-
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);
|
|
8909
9070
|
}
|
|
8910
9071
|
return names;
|
|
8911
9072
|
};
|
|
@@ -8923,11 +9084,11 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
8923
9084
|
var publicMethodNames = (body) => {
|
|
8924
9085
|
const names = [];
|
|
8925
9086
|
for (const member of body.body) {
|
|
8926
|
-
if (member.type !==
|
|
9087
|
+
if (member.type !== AST_NODE_TYPES42.MethodDefinition) continue;
|
|
8927
9088
|
if (member.kind !== "method" || member.static) continue;
|
|
8928
9089
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
8929
|
-
if (member.key.type ===
|
|
8930
|
-
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);
|
|
8931
9092
|
else names.push("\u2026");
|
|
8932
9093
|
}
|
|
8933
9094
|
return names;
|
|
@@ -8960,7 +9121,7 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
8960
9121
|
if (node.implements.length > 0) return;
|
|
8961
9122
|
if (node.decorators.length > 0) return;
|
|
8962
9123
|
const ctor = node.body.body.find(
|
|
8963
|
-
(member) => member.type ===
|
|
9124
|
+
(member) => member.type === AST_NODE_TYPES42.MethodDefinition && member.kind === "constructor"
|
|
8964
9125
|
);
|
|
8965
9126
|
if (ctor === void 0) return;
|
|
8966
9127
|
const { collaborators, constructedFields } = readConstructor(
|
|
@@ -8989,18 +9150,18 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
8989
9150
|
});
|
|
8990
9151
|
|
|
8991
9152
|
// src/rules/require-zod-form-validation.ts
|
|
8992
|
-
import { AST_NODE_TYPES as
|
|
9153
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES43 } from "@typescript-eslint/utils";
|
|
8993
9154
|
var looksLikeZodSchema = (node) => {
|
|
8994
9155
|
let current = node;
|
|
8995
9156
|
while (true) {
|
|
8996
|
-
if (current.type ===
|
|
9157
|
+
if (current.type === AST_NODE_TYPES43.Identifier) {
|
|
8997
9158
|
return current.name === "z" || ZOD_SCHEMA_NAME_RE.test(current.name);
|
|
8998
9159
|
}
|
|
8999
|
-
if (current.type ===
|
|
9160
|
+
if (current.type === AST_NODE_TYPES43.CallExpression) {
|
|
9000
9161
|
current = current.callee;
|
|
9001
9162
|
continue;
|
|
9002
9163
|
}
|
|
9003
|
-
if (current.type ===
|
|
9164
|
+
if (current.type === AST_NODE_TYPES43.MemberExpression) {
|
|
9004
9165
|
current = current.object;
|
|
9005
9166
|
continue;
|
|
9006
9167
|
}
|
|
@@ -9008,23 +9169,23 @@ var looksLikeZodSchema = (node) => {
|
|
|
9008
9169
|
}
|
|
9009
9170
|
};
|
|
9010
9171
|
var isZodParseCall = (node) => {
|
|
9011
|
-
if (node.type !==
|
|
9172
|
+
if (node.type !== AST_NODE_TYPES43.CallExpression) return false;
|
|
9012
9173
|
const callee = node.callee;
|
|
9013
|
-
if (callee.type !==
|
|
9174
|
+
if (callee.type !== AST_NODE_TYPES43.MemberExpression) return false;
|
|
9014
9175
|
if (callee.computed) return false;
|
|
9015
|
-
if (callee.property.type !==
|
|
9176
|
+
if (callee.property.type !== AST_NODE_TYPES43.Identifier) return false;
|
|
9016
9177
|
const method = callee.property.name;
|
|
9017
9178
|
if (method !== "parse" && method !== "safeParse") return false;
|
|
9018
9179
|
return looksLikeZodSchema(callee.object);
|
|
9019
9180
|
};
|
|
9020
9181
|
var isFormDataMethodCall = (node) => {
|
|
9021
9182
|
let current = node;
|
|
9022
|
-
if (current.type ===
|
|
9183
|
+
if (current.type === AST_NODE_TYPES43.AwaitExpression) {
|
|
9023
9184
|
current = current.argument;
|
|
9024
9185
|
}
|
|
9025
|
-
if (current.type !==
|
|
9186
|
+
if (current.type !== AST_NODE_TYPES43.CallExpression) return false;
|
|
9026
9187
|
const callee = current.callee;
|
|
9027
|
-
return callee.type ===
|
|
9188
|
+
return callee.type === AST_NODE_TYPES43.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES43.Identifier && callee.property.name === "formData";
|
|
9028
9189
|
};
|
|
9029
9190
|
var require_zod_form_validation_default = createRule({
|
|
9030
9191
|
name: "require-zod-form-validation",
|
|
@@ -9044,14 +9205,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
9044
9205
|
return {};
|
|
9045
9206
|
}
|
|
9046
9207
|
const isFormSourceIdentifier = (node) => {
|
|
9047
|
-
if (node.type !==
|
|
9208
|
+
if (node.type !== AST_NODE_TYPES43.Identifier) return false;
|
|
9048
9209
|
if (/formdata/i.test(node.name)) return true;
|
|
9049
9210
|
let scope = context.sourceCode.getScope(node);
|
|
9050
9211
|
while (scope !== null) {
|
|
9051
9212
|
const variable = scope.set.get(node.name);
|
|
9052
9213
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
9053
9214
|
const def = variable.defs[0];
|
|
9054
|
-
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) {
|
|
9055
9216
|
return isFormDataMethodCall(def.node.init);
|
|
9056
9217
|
}
|
|
9057
9218
|
return false;
|
|
@@ -9062,8 +9223,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
9062
9223
|
};
|
|
9063
9224
|
const isFormDataGetCall = (node) => {
|
|
9064
9225
|
const callee = node.callee;
|
|
9065
|
-
if (callee.type !==
|
|
9066
|
-
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") {
|
|
9067
9228
|
return false;
|
|
9068
9229
|
}
|
|
9069
9230
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -9078,11 +9239,11 @@ var require_zod_form_validation_default = createRule({
|
|
|
9078
9239
|
};
|
|
9079
9240
|
const isInstanceofNarrowing = (node) => {
|
|
9080
9241
|
const parent = node.parent;
|
|
9081
|
-
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;
|
|
9082
9243
|
};
|
|
9083
9244
|
const boundDeclarator = (node) => {
|
|
9084
9245
|
const parent = node.parent;
|
|
9085
|
-
if (parent.type ===
|
|
9246
|
+
if (parent.type === AST_NODE_TYPES43.VariableDeclarator && parent.init === node && parent.id.type === AST_NODE_TYPES43.Identifier) {
|
|
9086
9247
|
return parent;
|
|
9087
9248
|
}
|
|
9088
9249
|
return null;
|
|
@@ -9141,7 +9302,7 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
9141
9302
|
});
|
|
9142
9303
|
|
|
9143
9304
|
// src/rules/zod-naming-convention.ts
|
|
9144
|
-
import { AST_NODE_TYPES as
|
|
9305
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES44 } from "@typescript-eslint/utils";
|
|
9145
9306
|
var CONVENTIONS = {
|
|
9146
9307
|
prefix: { test: ZOD_PREFIX_RE, messageId: "zPrefix" },
|
|
9147
9308
|
suffix: { test: ZOD_SUFFIX_RE, messageId: "schemaSuffix" },
|
|
@@ -9166,15 +9327,15 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
9166
9327
|
"registry",
|
|
9167
9328
|
"implement"
|
|
9168
9329
|
]);
|
|
9169
|
-
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;
|
|
9170
9331
|
var calleeChainStartsWithZ = (node) => {
|
|
9171
9332
|
let current = node;
|
|
9172
|
-
while (current.type ===
|
|
9333
|
+
while (current.type === AST_NODE_TYPES44.MemberExpression) {
|
|
9173
9334
|
const receiver = current.object;
|
|
9174
|
-
if (receiver.type ===
|
|
9335
|
+
if (receiver.type === AST_NODE_TYPES44.Identifier && receiver.name === "z") {
|
|
9175
9336
|
return true;
|
|
9176
9337
|
}
|
|
9177
|
-
if (receiver.type ===
|
|
9338
|
+
if (receiver.type === AST_NODE_TYPES44.CallExpression) {
|
|
9178
9339
|
current = receiver.callee;
|
|
9179
9340
|
continue;
|
|
9180
9341
|
}
|
|
@@ -9219,13 +9380,13 @@ var zod_naming_convention_default = createRule({
|
|
|
9219
9380
|
VariableDeclarator(node) {
|
|
9220
9381
|
const init = node.init;
|
|
9221
9382
|
if (init === null || init === void 0) return;
|
|
9222
|
-
if (init.type !==
|
|
9383
|
+
if (init.type !== AST_NODE_TYPES44.CallExpression) return;
|
|
9223
9384
|
const callee = init.callee;
|
|
9224
|
-
if (callee.type !==
|
|
9385
|
+
if (callee.type !== AST_NODE_TYPES44.MemberExpression) return;
|
|
9225
9386
|
if (!calleeChainStartsWithZ(callee)) return;
|
|
9226
9387
|
const terminal = terminalMethodName(callee);
|
|
9227
9388
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
9228
|
-
if (node.id.type !==
|
|
9389
|
+
if (node.id.type !== AST_NODE_TYPES44.Identifier) return;
|
|
9229
9390
|
if (test.test(node.id.name)) return;
|
|
9230
9391
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
9231
9392
|
context.report({
|
|
@@ -9325,6 +9486,7 @@ var rules = {
|
|
|
9325
9486
|
"no-tautological-expect": no_tautological_expect_default,
|
|
9326
9487
|
"no-trailing-value-narration": no_trailing_value_narration_default,
|
|
9327
9488
|
"no-declaration-comment-wall": no_declaration_comment_wall_default,
|
|
9489
|
+
"no-union-in-comment": no_union_in_comment_default,
|
|
9328
9490
|
"no-type-member-comment-wall": no_type_member_comment_wall_default,
|
|
9329
9491
|
"no-unnecessary-use-client": no_unnecessary_use_client_default,
|
|
9330
9492
|
"no-unsafe-mock-casting": no_unsafe_mock_casting_default,
|
|
@@ -9350,7 +9512,7 @@ var rules = {
|
|
|
9350
9512
|
};
|
|
9351
9513
|
var meta = {
|
|
9352
9514
|
name: "@sarj/eslint-plugin",
|
|
9353
|
-
version: "9.
|
|
9515
|
+
version: "9.5.0"
|
|
9354
9516
|
};
|
|
9355
9517
|
var recommendedRules = {
|
|
9356
9518
|
"@sarj/enforce-file-structure": "warn",
|
|
@@ -9379,6 +9541,7 @@ var recommendedRules = {
|
|
|
9379
9541
|
"@sarj/no-tautological-expect": "warn",
|
|
9380
9542
|
"@sarj/no-trailing-value-narration": "warn",
|
|
9381
9543
|
"@sarj/no-declaration-comment-wall": "warn",
|
|
9544
|
+
"@sarj/no-union-in-comment": "warn",
|
|
9382
9545
|
"@sarj/no-type-member-comment-wall": "warn",
|
|
9383
9546
|
"@sarj/no-unnecessary-use-client": "warn",
|
|
9384
9547
|
"@sarj/no-unsafe-mock-casting": "warn",
|
|
@@ -9433,6 +9596,7 @@ var strictRules = {
|
|
|
9433
9596
|
"@sarj/no-tautological-expect": "error",
|
|
9434
9597
|
"@sarj/no-trailing-value-narration": "error",
|
|
9435
9598
|
"@sarj/no-declaration-comment-wall": "error",
|
|
9599
|
+
"@sarj/no-union-in-comment": "error",
|
|
9436
9600
|
"@sarj/no-type-member-comment-wall": "error",
|
|
9437
9601
|
"@sarj/no-unnecessary-use-client": "error",
|
|
9438
9602
|
"@sarj/no-unsafe-mock-casting": "error",
|