@sarj/eslint-plugin 9.3.0 → 9.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/index.cjs +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 +1 -1
package/dist/index.cjs
CHANGED
|
@@ -664,6 +664,7 @@ function isSectionLabel(text) {
|
|
|
664
664
|
const match = SECTION_LABEL_RE.exec(text);
|
|
665
665
|
return match !== null && SECTION_LABEL_WORDS.has((match[1] ?? "").toLowerCase());
|
|
666
666
|
}
|
|
667
|
+
var SHOUTED_LABEL_RE = /^[A-Z]{2,}(?:[ -][A-Z]{2,}){1,3}$/;
|
|
667
668
|
var HELPER_OPENER_RE = /^(?:a\s+)?helper\s+(?:function|method|component|hook|class|type|util(?:ity)?)\b/i;
|
|
668
669
|
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;
|
|
669
670
|
var ENUMERATION_RE = /^(?:\d+[.)]\s+\S|(?:phase|step)\s+\d+\b)/i;
|
|
@@ -818,6 +819,12 @@ var no_comment_cruft_default = createRule({
|
|
|
818
819
|
function isJsDoc(comment) {
|
|
819
820
|
return comment.type === "Block" && /^\*/.test(comment.value);
|
|
820
821
|
}
|
|
822
|
+
function isSectionJsDoc(comment) {
|
|
823
|
+
const texts = comment.value.split("\n").map(stripCommentMarker).filter((line) => line.length > 0 && !isDirective(line));
|
|
824
|
+
return texts.length > 0 && texts.every(
|
|
825
|
+
(text) => !isProtected(text) && (isBanner(text) || isSectionLabel(text) || SHOUTED_LABEL_RE.test(text.replace(/[.:]$/, "")))
|
|
826
|
+
);
|
|
827
|
+
}
|
|
821
828
|
function reportLeadingPreamble(comments, firstCodeLine) {
|
|
822
829
|
const leading = [];
|
|
823
830
|
let prevLine = null;
|
|
@@ -851,7 +858,13 @@ var no_comment_cruft_default = createRule({
|
|
|
851
858
|
for (let i = 0; i < comments.length; i++) {
|
|
852
859
|
const comment = comments[i];
|
|
853
860
|
if (comment === void 0) continue;
|
|
854
|
-
if (isJsDoc(comment)
|
|
861
|
+
if (isJsDoc(comment)) {
|
|
862
|
+
if (isStandalone(comment) && isSectionJsDoc(comment)) {
|
|
863
|
+
context.report({ node: comment, messageId: "sectionBanner" });
|
|
864
|
+
}
|
|
865
|
+
continue;
|
|
866
|
+
}
|
|
867
|
+
if (!isStandalone(comment)) continue;
|
|
855
868
|
if (LICENSE_RE.test(comment.value)) continue;
|
|
856
869
|
const texts = comment.value.split("\n").map(stripCommentMarker).filter((l) => l.length > 0 && !isDirective(l));
|
|
857
870
|
const firstText = texts[0];
|
|
@@ -5326,10 +5339,158 @@ var no_declaration_comment_wall_default = createRule({
|
|
|
5326
5339
|
}
|
|
5327
5340
|
});
|
|
5328
5341
|
|
|
5329
|
-
// src/rules/no-
|
|
5342
|
+
// src/rules/no-union-in-comment.ts
|
|
5330
5343
|
var import_utils36 = require("@typescript-eslint/utils");
|
|
5344
|
+
var MAX_LITERAL_LENGTH = 28;
|
|
5345
|
+
var LITERAL = String.raw`(?:'[^'\n]*'|"[^"\n]*"|\`[^\`\n]*\`)`;
|
|
5346
|
+
var LEAD_IN_RE2 = /^(?:one of|either|values?|allowed(?: values)?|options?|possible(?: values)?)\s*[:=-]?\s*/i;
|
|
5347
|
+
var UNION_BODY_RE = new RegExp(String.raw`^${LITERAL}(?:\s*[|,/]\s*${LITERAL})+\.?$`);
|
|
5348
|
+
var LITERAL_G = new RegExp(LITERAL, "g");
|
|
5349
|
+
var STRING_BUILDERS = /* @__PURE__ */ new Set([
|
|
5350
|
+
"char",
|
|
5351
|
+
"citext",
|
|
5352
|
+
"longtext",
|
|
5353
|
+
"mediumtext",
|
|
5354
|
+
"string",
|
|
5355
|
+
"text",
|
|
5356
|
+
"tinytext",
|
|
5357
|
+
"varchar"
|
|
5358
|
+
]);
|
|
5359
|
+
function isBareString(node) {
|
|
5360
|
+
if (node === void 0) return false;
|
|
5361
|
+
switch (node.type) {
|
|
5362
|
+
case import_utils36.AST_NODE_TYPES.TSStringKeyword:
|
|
5363
|
+
return true;
|
|
5364
|
+
// `string[]` holds members of the same closed set, one element at a time.
|
|
5365
|
+
case import_utils36.AST_NODE_TYPES.TSArrayType:
|
|
5366
|
+
return isBareString(node.elementType);
|
|
5367
|
+
// `string | null` is still an unconstrained string, and so is `string | "a"`
|
|
5368
|
+
// — the checker collapses that one to `string`.
|
|
5369
|
+
case import_utils36.AST_NODE_TYPES.TSUnionType:
|
|
5370
|
+
return node.types.some((member) => isBareString(member));
|
|
5371
|
+
default:
|
|
5372
|
+
return false;
|
|
5373
|
+
}
|
|
5374
|
+
}
|
|
5375
|
+
function rootCallee(node) {
|
|
5376
|
+
let current = node;
|
|
5377
|
+
for (let hops = 0; current != null && hops < 12; hops += 1) {
|
|
5378
|
+
switch (current.type) {
|
|
5379
|
+
case import_utils36.AST_NODE_TYPES.CallExpression:
|
|
5380
|
+
current = current.callee;
|
|
5381
|
+
break;
|
|
5382
|
+
case import_utils36.AST_NODE_TYPES.MemberExpression:
|
|
5383
|
+
current = current.object;
|
|
5384
|
+
break;
|
|
5385
|
+
case import_utils36.AST_NODE_TYPES.Identifier:
|
|
5386
|
+
return current.name;
|
|
5387
|
+
default:
|
|
5388
|
+
return null;
|
|
5389
|
+
}
|
|
5390
|
+
}
|
|
5391
|
+
return null;
|
|
5392
|
+
}
|
|
5393
|
+
function nameOf(key) {
|
|
5394
|
+
if (key.type === import_utils36.AST_NODE_TYPES.Identifier) return key.name;
|
|
5395
|
+
if (key.type === import_utils36.AST_NODE_TYPES.Literal && typeof key.value === "string") return key.value;
|
|
5396
|
+
return null;
|
|
5397
|
+
}
|
|
5398
|
+
function targetOf(node) {
|
|
5399
|
+
switch (node.type) {
|
|
5400
|
+
case import_utils36.AST_NODE_TYPES.TSPropertySignature:
|
|
5401
|
+
case import_utils36.AST_NODE_TYPES.PropertyDefinition: {
|
|
5402
|
+
const name = node.computed ? null : nameOf(node.key);
|
|
5403
|
+
if (name === null || !isBareString(node.typeAnnotation?.typeAnnotation)) return null;
|
|
5404
|
+
return { node, name };
|
|
5405
|
+
}
|
|
5406
|
+
case import_utils36.AST_NODE_TYPES.Property: {
|
|
5407
|
+
const name = node.computed || node.shorthand ? null : nameOf(node.key);
|
|
5408
|
+
const callee = rootCallee(node.value);
|
|
5409
|
+
if (name === null || callee === null || !STRING_BUILDERS.has(callee)) return null;
|
|
5410
|
+
return { node, name };
|
|
5411
|
+
}
|
|
5412
|
+
case import_utils36.AST_NODE_TYPES.VariableDeclarator: {
|
|
5413
|
+
if (node.id.type !== import_utils36.AST_NODE_TYPES.Identifier) return null;
|
|
5414
|
+
if (!isBareString(node.id.typeAnnotation?.typeAnnotation)) return null;
|
|
5415
|
+
return { node, name: node.id.name };
|
|
5416
|
+
}
|
|
5417
|
+
default:
|
|
5418
|
+
return null;
|
|
5419
|
+
}
|
|
5420
|
+
}
|
|
5421
|
+
function unionLiterals(body) {
|
|
5422
|
+
const list = body.replace(LEAD_IN_RE2, "").trim();
|
|
5423
|
+
if (!UNION_BODY_RE.test(list)) return null;
|
|
5424
|
+
const literals = (list.match(LITERAL_G) ?? []).map((raw) => raw.slice(1, -1));
|
|
5425
|
+
if (literals.some((literal) => literal.length === 0 || literal.length > MAX_LITERAL_LENGTH)) {
|
|
5426
|
+
return null;
|
|
5427
|
+
}
|
|
5428
|
+
return literals;
|
|
5429
|
+
}
|
|
5430
|
+
var no_union_in_comment_default = createRule({
|
|
5431
|
+
name: "no-union-in-comment",
|
|
5432
|
+
meta: {
|
|
5433
|
+
type: "suggestion",
|
|
5434
|
+
docs: {
|
|
5435
|
+
description: "Flag a comment that lists a `string` field's allowed values instead of the type listing them."
|
|
5436
|
+
},
|
|
5437
|
+
schema: [],
|
|
5438
|
+
messages: {
|
|
5439
|
+
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.'
|
|
5440
|
+
}
|
|
5441
|
+
},
|
|
5442
|
+
defaultOptions: [],
|
|
5443
|
+
create(context) {
|
|
5444
|
+
const sourceCode = context.sourceCode;
|
|
5445
|
+
if (isGeneratedFile(context.filename, sourceCode.text)) {
|
|
5446
|
+
return {};
|
|
5447
|
+
}
|
|
5448
|
+
function annotated(comment) {
|
|
5449
|
+
const before = sourceCode.getTokenBefore(comment, { includeComments: false });
|
|
5450
|
+
let anchor;
|
|
5451
|
+
if (before !== null && before.loc.end.line === comment.loc.start.line) {
|
|
5452
|
+
let token = before;
|
|
5453
|
+
while (token !== null && (token.value === "," || token.value === ";")) {
|
|
5454
|
+
token = sourceCode.getTokenBefore(token, { includeComments: false });
|
|
5455
|
+
}
|
|
5456
|
+
anchor = token === null ? null : sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
5457
|
+
} else {
|
|
5458
|
+
const after = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
5459
|
+
if (after === null || after.loc.start.line !== comment.loc.end.line + 1) return null;
|
|
5460
|
+
anchor = sourceCode.getNodeByRangeIndex(after.range[0]);
|
|
5461
|
+
}
|
|
5462
|
+
for (let node = anchor; node != null && node.type !== import_utils36.AST_NODE_TYPES.Program; node = node.parent) {
|
|
5463
|
+
const target = targetOf(node);
|
|
5464
|
+
if (target !== null) return target;
|
|
5465
|
+
}
|
|
5466
|
+
return null;
|
|
5467
|
+
}
|
|
5468
|
+
return {
|
|
5469
|
+
Program() {
|
|
5470
|
+
for (const comment of sourceCode.getAllComments()) {
|
|
5471
|
+
const body = comment.value.replace(/^\*+/, "").replace(/\*+$/, "").trim();
|
|
5472
|
+
if (body.length === 0) continue;
|
|
5473
|
+
const literals = unionLiterals(body);
|
|
5474
|
+
if (literals === null) continue;
|
|
5475
|
+
const target = annotated(comment);
|
|
5476
|
+
if (target === null) continue;
|
|
5477
|
+
const declaration = sourceCode.getText(target.node);
|
|
5478
|
+
if (literals.every((literal) => declaration.includes(literal))) continue;
|
|
5479
|
+
context.report({
|
|
5480
|
+
node: comment,
|
|
5481
|
+
messageId: "unionInComment",
|
|
5482
|
+
data: { name: target.name, first: literals[0] ?? "" }
|
|
5483
|
+
});
|
|
5484
|
+
}
|
|
5485
|
+
}
|
|
5486
|
+
};
|
|
5487
|
+
}
|
|
5488
|
+
});
|
|
5489
|
+
|
|
5490
|
+
// src/rules/no-type-member-comment-wall.ts
|
|
5491
|
+
var import_utils37 = require("@typescript-eslint/utils");
|
|
5331
5492
|
function isNamedMember(node) {
|
|
5332
|
-
return (node.type ===
|
|
5493
|
+
return (node.type === import_utils37.AST_NODE_TYPES.TSPropertySignature || node.type === import_utils37.AST_NODE_TYPES.TSMethodSignature) && !node.computed;
|
|
5333
5494
|
}
|
|
5334
5495
|
var no_type_member_comment_wall_default = createRule({
|
|
5335
5496
|
name: "no-type-member-comment-wall",
|
|
@@ -5376,7 +5537,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5376
5537
|
return headsRun || lineAbove !== void 0 && lineAbove.trim().length === 0;
|
|
5377
5538
|
}
|
|
5378
5539
|
function check(node) {
|
|
5379
|
-
const members = node.type ===
|
|
5540
|
+
const members = node.type === import_utils37.AST_NODE_TYPES.TSInterfaceBody ? node.body : node.members;
|
|
5380
5541
|
const named2 = members.filter(isNamedMember);
|
|
5381
5542
|
if (named2.length === 0) return;
|
|
5382
5543
|
const documented = named2.map((member) => ({ member, comment: documentingComment(member) }));
|
|
@@ -5416,7 +5577,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5416
5577
|
});
|
|
5417
5578
|
|
|
5418
5579
|
// src/rules/no-unnecessary-use-client.ts
|
|
5419
|
-
var
|
|
5580
|
+
var import_utils38 = require("@typescript-eslint/utils");
|
|
5420
5581
|
var HOOK_REGEX = /^use([A-Z]|$)/;
|
|
5421
5582
|
var EVENT_PROP_REGEX = /^on[A-Z]/;
|
|
5422
5583
|
var ERROR_FILE_REGEX = /\b(?:global-)?error\.[jt]sx?$/;
|
|
@@ -5442,13 +5603,13 @@ var CLIENT_ONLY_PACKAGES_REGEX = /^(?:@radix-ui\/|framer-motion|react-dom|react-
|
|
|
5442
5603
|
var isBareSpecifier = (source) => !source.startsWith(".") && !source.startsWith("/") && !source.startsWith("@/") && !source.startsWith("~");
|
|
5443
5604
|
var jsxRootName = (name) => {
|
|
5444
5605
|
let current = name;
|
|
5445
|
-
while (current.type ===
|
|
5606
|
+
while (current.type === import_utils38.AST_NODE_TYPES.JSXMemberExpression) {
|
|
5446
5607
|
current = current.object;
|
|
5447
5608
|
}
|
|
5448
|
-
return current.type ===
|
|
5609
|
+
return current.type === import_utils38.AST_NODE_TYPES.JSXIdentifier ? current.name : "";
|
|
5449
5610
|
};
|
|
5450
5611
|
var subtreeReadsImportedBinding = (node, imported) => {
|
|
5451
|
-
if (node.type ===
|
|
5612
|
+
if (node.type === import_utils38.AST_NODE_TYPES.Identifier) {
|
|
5452
5613
|
return imported.has(node.name);
|
|
5453
5614
|
}
|
|
5454
5615
|
for (const key of Object.keys(node)) {
|
|
@@ -5463,16 +5624,16 @@ var subtreeReadsImportedBinding = (node, imported) => {
|
|
|
5463
5624
|
return false;
|
|
5464
5625
|
};
|
|
5465
5626
|
var isUseClientDirective = (node) => {
|
|
5466
|
-
return node.type ===
|
|
5627
|
+
return node.type === import_utils38.AST_NODE_TYPES.ExpressionStatement && node.expression.type === import_utils38.AST_NODE_TYPES.Literal && node.expression.value === "use client";
|
|
5467
5628
|
};
|
|
5468
5629
|
var isGlobalReference = (node, context) => {
|
|
5469
5630
|
if (!BROWSER_GLOBALS.has(node.name)) return false;
|
|
5470
5631
|
const parent = node.parent;
|
|
5471
5632
|
if (parent !== void 0) {
|
|
5472
|
-
if (parent.type ===
|
|
5633
|
+
if (parent.type === import_utils38.AST_NODE_TYPES.MemberExpression && parent.property === node && !parent.computed) {
|
|
5473
5634
|
return false;
|
|
5474
5635
|
}
|
|
5475
|
-
if (parent.type ===
|
|
5636
|
+
if (parent.type === import_utils38.AST_NODE_TYPES.Property && parent.key === node && !parent.computed) {
|
|
5476
5637
|
return false;
|
|
5477
5638
|
}
|
|
5478
5639
|
if (parent.type.startsWith("TS")) {
|
|
@@ -5512,13 +5673,13 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5512
5673
|
const importedLocals = /* @__PURE__ */ new Set();
|
|
5513
5674
|
const externalLocals = /* @__PURE__ */ new Set();
|
|
5514
5675
|
const markIfHookOrContext = (callee) => {
|
|
5515
|
-
if (callee.type ===
|
|
5676
|
+
if (callee.type === import_utils38.AST_NODE_TYPES.Identifier) {
|
|
5516
5677
|
if (HOOK_REGEX.test(callee.name) || callee.name === "createContext") {
|
|
5517
5678
|
hasClientIndicator = true;
|
|
5518
5679
|
}
|
|
5519
5680
|
return;
|
|
5520
5681
|
}
|
|
5521
|
-
if (callee.type ===
|
|
5682
|
+
if (callee.type === import_utils38.AST_NODE_TYPES.MemberExpression && callee.property.type === import_utils38.AST_NODE_TYPES.Identifier) {
|
|
5522
5683
|
const name = callee.property.name;
|
|
5523
5684
|
if (HOOK_REGEX.test(name) || name === "createContext") {
|
|
5524
5685
|
hasClientIndicator = true;
|
|
@@ -5528,7 +5689,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5528
5689
|
return {
|
|
5529
5690
|
Program(node) {
|
|
5530
5691
|
for (const stmt of node.body) {
|
|
5531
|
-
if (stmt.type !==
|
|
5692
|
+
if (stmt.type !== import_utils38.AST_NODE_TYPES.ExpressionStatement) break;
|
|
5532
5693
|
if (isUseClientDirective(stmt)) {
|
|
5533
5694
|
directiveNode = stmt;
|
|
5534
5695
|
break;
|
|
@@ -5541,7 +5702,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5541
5702
|
},
|
|
5542
5703
|
JSXAttribute(node) {
|
|
5543
5704
|
if (directiveNode === null) return;
|
|
5544
|
-
if (node.name.type ===
|
|
5705
|
+
if (node.name.type === import_utils38.AST_NODE_TYPES.JSXIdentifier && EVENT_PROP_REGEX.test(node.name.name)) {
|
|
5545
5706
|
hasClientIndicator = true;
|
|
5546
5707
|
}
|
|
5547
5708
|
},
|
|
@@ -5608,18 +5769,18 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5608
5769
|
});
|
|
5609
5770
|
|
|
5610
5771
|
// src/rules/no-unsafe-mock-casting.ts
|
|
5611
|
-
var import_utils38 = require("@typescript-eslint/utils");
|
|
5612
5772
|
var import_utils39 = require("@typescript-eslint/utils");
|
|
5773
|
+
var import_utils40 = require("@typescript-eslint/utils");
|
|
5613
5774
|
function isMockTypeReference(node) {
|
|
5614
|
-
if (node.type !==
|
|
5775
|
+
if (node.type !== import_utils40.AST_NODE_TYPES.TSTypeReference) {
|
|
5615
5776
|
return false;
|
|
5616
5777
|
}
|
|
5617
5778
|
const typeName = node.typeName;
|
|
5618
|
-
if (typeName.type ===
|
|
5779
|
+
if (typeName.type === import_utils40.AST_NODE_TYPES.Identifier) {
|
|
5619
5780
|
const name = typeName.name;
|
|
5620
5781
|
return name === "Mock" || name === "MockInstance" || name === "SpyInstance";
|
|
5621
5782
|
}
|
|
5622
|
-
if (typeName.type ===
|
|
5783
|
+
if (typeName.type === import_utils40.AST_NODE_TYPES.TSQualifiedName) {
|
|
5623
5784
|
const rightName = typeName.right.name;
|
|
5624
5785
|
return rightName === "Mock" || rightName === "MockInstance" || rightName === "SpyInstance";
|
|
5625
5786
|
}
|
|
@@ -5655,7 +5816,7 @@ var no_unsafe_mock_casting_default = createRule({
|
|
|
5655
5816
|
});
|
|
5656
5817
|
|
|
5657
5818
|
// src/rules/no-zod-native-enum.ts
|
|
5658
|
-
var
|
|
5819
|
+
var import_utils41 = require("@typescript-eslint/utils");
|
|
5659
5820
|
var ts = __toESM(require("typescript"), 1);
|
|
5660
5821
|
var IGNORE_PATTERNS = [
|
|
5661
5822
|
/[\\/]generated[\\/]/,
|
|
@@ -5673,7 +5834,7 @@ function isZodModule(source) {
|
|
|
5673
5834
|
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
5674
5835
|
}
|
|
5675
5836
|
function unwrap2(node) {
|
|
5676
|
-
if (node.type ===
|
|
5837
|
+
if (node.type === import_utils41.AST_NODE_TYPES.TSAsExpression || node.type === import_utils41.AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
5677
5838
|
return unwrap2(node.expression);
|
|
5678
5839
|
}
|
|
5679
5840
|
return node;
|
|
@@ -5681,14 +5842,14 @@ function unwrap2(node) {
|
|
|
5681
5842
|
function stringValueTexts(node, sourceCode) {
|
|
5682
5843
|
const texts = [];
|
|
5683
5844
|
for (const prop of node.properties) {
|
|
5684
|
-
if (prop.type !==
|
|
5845
|
+
if (prop.type !== import_utils41.AST_NODE_TYPES.Property) {
|
|
5685
5846
|
return null;
|
|
5686
5847
|
}
|
|
5687
5848
|
if (prop.computed || prop.shorthand || prop.method || prop.kind !== "init") {
|
|
5688
5849
|
return null;
|
|
5689
5850
|
}
|
|
5690
5851
|
const value = prop.value;
|
|
5691
|
-
if (value.type !==
|
|
5852
|
+
if (value.type !== import_utils41.AST_NODE_TYPES.Literal || typeof value.value !== "string") {
|
|
5692
5853
|
return null;
|
|
5693
5854
|
}
|
|
5694
5855
|
const text = sourceCode.getText(value);
|
|
@@ -5704,7 +5865,7 @@ function resolvesToLocalEnum(node, scope) {
|
|
|
5704
5865
|
const variable = current.variables.find((v) => v.name === node.name);
|
|
5705
5866
|
if (variable !== void 0) {
|
|
5706
5867
|
return variable.defs.some(
|
|
5707
|
-
(def) => def.node.type ===
|
|
5868
|
+
(def) => def.node.type === import_utils41.AST_NODE_TYPES.TSEnumDeclaration
|
|
5708
5869
|
);
|
|
5709
5870
|
}
|
|
5710
5871
|
current = current.upper;
|
|
@@ -5749,32 +5910,32 @@ var no_zod_native_enum_default = createRule({
|
|
|
5749
5910
|
}
|
|
5750
5911
|
let services;
|
|
5751
5912
|
try {
|
|
5752
|
-
services =
|
|
5913
|
+
services = import_utils41.ESLintUtils.getParserServices(context);
|
|
5753
5914
|
} catch {
|
|
5754
5915
|
services = null;
|
|
5755
5916
|
}
|
|
5756
5917
|
const zodImportedNames = /* @__PURE__ */ new Map();
|
|
5757
5918
|
function isZodMemberCall(node, api) {
|
|
5758
5919
|
const callee = node.callee;
|
|
5759
|
-
if (callee.type ===
|
|
5920
|
+
if (callee.type === import_utils41.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils41.AST_NODE_TYPES.Identifier) {
|
|
5760
5921
|
return callee.property.name === api;
|
|
5761
5922
|
}
|
|
5762
|
-
if (callee.type ===
|
|
5923
|
+
if (callee.type === import_utils41.AST_NODE_TYPES.Identifier) {
|
|
5763
5924
|
return zodImportedNames.get(callee.name) === api;
|
|
5764
5925
|
}
|
|
5765
5926
|
return false;
|
|
5766
5927
|
}
|
|
5767
5928
|
function buildFix(node) {
|
|
5768
5929
|
const callee = node.callee;
|
|
5769
|
-
if (callee.type !==
|
|
5930
|
+
if (callee.type !== import_utils41.AST_NODE_TYPES.MemberExpression || callee.property.type !== import_utils41.AST_NODE_TYPES.Identifier) {
|
|
5770
5931
|
return null;
|
|
5771
5932
|
}
|
|
5772
5933
|
const arg = node.arguments[0];
|
|
5773
|
-
if (arg === void 0 || node.arguments.length !== 1 || arg.type ===
|
|
5934
|
+
if (arg === void 0 || node.arguments.length !== 1 || arg.type === import_utils41.AST_NODE_TYPES.SpreadElement) {
|
|
5774
5935
|
return null;
|
|
5775
5936
|
}
|
|
5776
5937
|
const inner = unwrap2(arg);
|
|
5777
|
-
if (inner.type !==
|
|
5938
|
+
if (inner.type !== import_utils41.AST_NODE_TYPES.ObjectExpression) {
|
|
5778
5939
|
return null;
|
|
5779
5940
|
}
|
|
5780
5941
|
const values = stringValueTexts(inner, sourceCode);
|
|
@@ -5794,7 +5955,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
5794
5955
|
return;
|
|
5795
5956
|
}
|
|
5796
5957
|
for (const spec of node.specifiers) {
|
|
5797
|
-
if (spec.type ===
|
|
5958
|
+
if (spec.type === import_utils41.AST_NODE_TYPES.ImportSpecifier && spec.imported.type === import_utils41.AST_NODE_TYPES.Identifier) {
|
|
5798
5959
|
zodImportedNames.set(spec.local.name, spec.imported.name);
|
|
5799
5960
|
}
|
|
5800
5961
|
}
|
|
@@ -5813,7 +5974,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
5813
5974
|
return;
|
|
5814
5975
|
}
|
|
5815
5976
|
const arg = node.arguments[0];
|
|
5816
|
-
if (arg === void 0 || arg.type !==
|
|
5977
|
+
if (arg === void 0 || arg.type !== import_utils41.AST_NODE_TYPES.Identifier) {
|
|
5817
5978
|
return;
|
|
5818
5979
|
}
|
|
5819
5980
|
const isEnum = resolvesToLocalEnum(arg, sourceCode.getScope(arg)) || services !== null && resolvesToImportedEnum(arg, services);
|
|
@@ -5830,7 +5991,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
5830
5991
|
});
|
|
5831
5992
|
|
|
5832
5993
|
// src/rules/prefer-constant-time-secret-compare.ts
|
|
5833
|
-
var
|
|
5994
|
+
var import_utils42 = require("@typescript-eslint/utils");
|
|
5834
5995
|
var EQUALITY_OPERATORS = /* @__PURE__ */ new Set(["===", "!==", "==", "!="]);
|
|
5835
5996
|
var SENTINEL_IDENTIFIERS = /* @__PURE__ */ new Set(["undefined", "NaN"]);
|
|
5836
5997
|
var SENTINEL_WORDS = /(^|_)(SENTINEL|EMPTY|NONE|NULL|UNSET|MISSING|PLACEHOLDER|DUMMY|FAKE|EXAMPLE)(_|$)/;
|
|
@@ -5843,36 +6004,36 @@ function isConstantReference(identifier) {
|
|
|
5843
6004
|
}
|
|
5844
6005
|
function isExcludedOperand(node) {
|
|
5845
6006
|
switch (node.type) {
|
|
5846
|
-
case
|
|
6007
|
+
case import_utils42.AST_NODE_TYPES.Literal:
|
|
5847
6008
|
return true;
|
|
5848
|
-
case
|
|
6009
|
+
case import_utils42.AST_NODE_TYPES.TemplateLiteral:
|
|
5849
6010
|
return node.expressions.length === 0;
|
|
5850
|
-
case
|
|
6011
|
+
case import_utils42.AST_NODE_TYPES.Identifier:
|
|
5851
6012
|
return SENTINEL_IDENTIFIERS.has(node.name) || SENTINEL_PREFIX_RE.test(node.name) || isConstantReference(node.name);
|
|
5852
|
-
case
|
|
5853
|
-
return !node.computed && node.property.type ===
|
|
6013
|
+
case import_utils42.AST_NODE_TYPES.MemberExpression:
|
|
6014
|
+
return !node.computed && node.property.type === import_utils42.AST_NODE_TYPES.Identifier && (SENTINEL_PREFIX_RE.test(node.property.name) || isConstantReference(node.property.name));
|
|
5854
6015
|
default:
|
|
5855
6016
|
return false;
|
|
5856
6017
|
}
|
|
5857
6018
|
}
|
|
5858
6019
|
function operandName(node) {
|
|
5859
|
-
if (node.type ===
|
|
6020
|
+
if (node.type === import_utils42.AST_NODE_TYPES.Identifier) {
|
|
5860
6021
|
return node.name;
|
|
5861
6022
|
}
|
|
5862
|
-
if (node.type ===
|
|
6023
|
+
if (node.type === import_utils42.AST_NODE_TYPES.MemberExpression && !node.computed && node.property.type === import_utils42.AST_NODE_TYPES.Identifier) {
|
|
5863
6024
|
return node.property.name;
|
|
5864
6025
|
}
|
|
5865
6026
|
return null;
|
|
5866
6027
|
}
|
|
5867
6028
|
function isSecretOperand(node) {
|
|
5868
|
-
if (node.type ===
|
|
6029
|
+
if (node.type === import_utils42.AST_NODE_TYPES.TemplateLiteral) {
|
|
5869
6030
|
return node.expressions.some((expression) => isSecretOperand(expression));
|
|
5870
6031
|
}
|
|
5871
6032
|
const name = operandName(node);
|
|
5872
6033
|
return name !== null && isAuthSecretName(name);
|
|
5873
6034
|
}
|
|
5874
6035
|
function secretNameOf(node) {
|
|
5875
|
-
if (node.type ===
|
|
6036
|
+
if (node.type === import_utils42.AST_NODE_TYPES.TemplateLiteral) {
|
|
5876
6037
|
for (const expression of node.expressions) {
|
|
5877
6038
|
const nested = secretNameOf(expression);
|
|
5878
6039
|
if (nested !== null) {
|
|
@@ -5924,8 +6085,8 @@ var prefer_constant_time_secret_compare_default = createRule({
|
|
|
5924
6085
|
});
|
|
5925
6086
|
|
|
5926
6087
|
// src/rules/prefer-discriminated-union.ts
|
|
5927
|
-
var import_utils42 = require("@typescript-eslint/utils");
|
|
5928
6088
|
var import_utils43 = require("@typescript-eslint/utils");
|
|
6089
|
+
var import_utils44 = require("@typescript-eslint/utils");
|
|
5929
6090
|
var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
5930
6091
|
"success",
|
|
5931
6092
|
"ok",
|
|
@@ -5935,27 +6096,27 @@ var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
|
5935
6096
|
]);
|
|
5936
6097
|
var MIN_OPTIONAL_MEMBERS = 2;
|
|
5937
6098
|
function getMemberName(member) {
|
|
5938
|
-
if (member.type !==
|
|
6099
|
+
if (member.type !== import_utils44.AST_NODE_TYPES.TSPropertySignature) {
|
|
5939
6100
|
return null;
|
|
5940
6101
|
}
|
|
5941
6102
|
const { key } = member;
|
|
5942
|
-
if (key.type ===
|
|
6103
|
+
if (key.type === import_utils44.AST_NODE_TYPES.Identifier) {
|
|
5943
6104
|
return key.name;
|
|
5944
6105
|
}
|
|
5945
|
-
if (key.type ===
|
|
6106
|
+
if (key.type === import_utils44.AST_NODE_TYPES.Literal && typeof key.value === "string") {
|
|
5946
6107
|
return key.value;
|
|
5947
6108
|
}
|
|
5948
6109
|
return null;
|
|
5949
6110
|
}
|
|
5950
6111
|
function isBooleanTyped(member) {
|
|
5951
|
-
return member.typeAnnotation?.typeAnnotation.type ===
|
|
6112
|
+
return member.typeAnnotation?.typeAnnotation.type === import_utils44.AST_NODE_TYPES.TSBooleanKeyword;
|
|
5952
6113
|
}
|
|
5953
6114
|
function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
5954
6115
|
let hasStatusBoolean = false;
|
|
5955
6116
|
let optionalCount = 0;
|
|
5956
6117
|
let optionalPayloadCount = 0;
|
|
5957
6118
|
for (const member of typeLiteral.members) {
|
|
5958
|
-
if (member.type !==
|
|
6119
|
+
if (member.type !== import_utils44.AST_NODE_TYPES.TSPropertySignature) {
|
|
5959
6120
|
continue;
|
|
5960
6121
|
}
|
|
5961
6122
|
if (member.optional) {
|
|
@@ -5997,7 +6158,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
5997
6158
|
TSInterfaceDeclaration(node) {
|
|
5998
6159
|
const synthetic = {
|
|
5999
6160
|
...node.body,
|
|
6000
|
-
type:
|
|
6161
|
+
type: import_utils44.AST_NODE_TYPES.TSTypeLiteral,
|
|
6001
6162
|
members: node.body.body
|
|
6002
6163
|
};
|
|
6003
6164
|
checkTypeLiteral(synthetic, node);
|
|
@@ -6010,7 +6171,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
6010
6171
|
});
|
|
6011
6172
|
|
|
6012
6173
|
// src/rules/prefer-module-level-constant.ts
|
|
6013
|
-
var
|
|
6174
|
+
var import_utils45 = require("@typescript-eslint/utils");
|
|
6014
6175
|
var DEFAULT_MIN_ELEMENTS = 3;
|
|
6015
6176
|
var MAX_LITERAL_DEPTH = 4;
|
|
6016
6177
|
var IGNORE_PATTERNS2 = [
|
|
@@ -6039,9 +6200,9 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
|
6039
6200
|
"assign"
|
|
6040
6201
|
]);
|
|
6041
6202
|
var FUNCTION_TYPES5 = /* @__PURE__ */ new Set([
|
|
6042
|
-
|
|
6043
|
-
|
|
6044
|
-
|
|
6203
|
+
import_utils45.AST_NODE_TYPES.FunctionDeclaration,
|
|
6204
|
+
import_utils45.AST_NODE_TYPES.FunctionExpression,
|
|
6205
|
+
import_utils45.AST_NODE_TYPES.ArrowFunctionExpression
|
|
6045
6206
|
]);
|
|
6046
6207
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
6047
6208
|
function isIgnoredFile2(filename, sourceText) {
|
|
@@ -6054,14 +6215,14 @@ function isLocalFixtureFile(filename) {
|
|
|
6054
6215
|
return isTestFile(filename) || isStoryFile(filename);
|
|
6055
6216
|
}
|
|
6056
6217
|
function unwrap3(node) {
|
|
6057
|
-
if (node.type ===
|
|
6218
|
+
if (node.type === import_utils45.AST_NODE_TYPES.TSAsExpression || node.type === import_utils45.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils45.AST_NODE_TYPES.TSNonNullExpression) {
|
|
6058
6219
|
return unwrap3(node.expression);
|
|
6059
6220
|
}
|
|
6060
6221
|
return node;
|
|
6061
6222
|
}
|
|
6062
6223
|
var HAS_STATEFUL_FLAG_RE = /[gy]/;
|
|
6063
6224
|
function isRegexLiteral(node) {
|
|
6064
|
-
return node.type ===
|
|
6225
|
+
return node.type === import_utils45.AST_NODE_TYPES.Literal && "regex" in node && node.regex !== void 0;
|
|
6065
6226
|
}
|
|
6066
6227
|
function isLiteralOnly(node, depth) {
|
|
6067
6228
|
if (depth > MAX_LITERAL_DEPTH) {
|
|
@@ -6069,29 +6230,29 @@ function isLiteralOnly(node, depth) {
|
|
|
6069
6230
|
}
|
|
6070
6231
|
const inner = unwrap3(node);
|
|
6071
6232
|
switch (inner.type) {
|
|
6072
|
-
case
|
|
6233
|
+
case import_utils45.AST_NODE_TYPES.Literal: {
|
|
6073
6234
|
return !(isRegexLiteral(inner) && HAS_STATEFUL_FLAG_RE.test(inner.regex.flags));
|
|
6074
6235
|
}
|
|
6075
|
-
case
|
|
6236
|
+
case import_utils45.AST_NODE_TYPES.TemplateLiteral: {
|
|
6076
6237
|
return inner.expressions.length === 0;
|
|
6077
6238
|
}
|
|
6078
|
-
case
|
|
6079
|
-
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type ===
|
|
6239
|
+
case import_utils45.AST_NODE_TYPES.UnaryExpression: {
|
|
6240
|
+
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type === import_utils45.AST_NODE_TYPES.Literal && typeof inner.argument.value === "number";
|
|
6080
6241
|
}
|
|
6081
|
-
case
|
|
6242
|
+
case import_utils45.AST_NODE_TYPES.ArrayExpression: {
|
|
6082
6243
|
return inner.elements.every(
|
|
6083
|
-
(el) => el !== null && el.type !==
|
|
6244
|
+
(el) => el !== null && el.type !== import_utils45.AST_NODE_TYPES.SpreadElement && isLiteralOnly(el, depth + 1)
|
|
6084
6245
|
);
|
|
6085
6246
|
}
|
|
6086
|
-
case
|
|
6247
|
+
case import_utils45.AST_NODE_TYPES.ObjectExpression: {
|
|
6087
6248
|
return inner.properties.every((prop) => {
|
|
6088
|
-
if (prop.type !==
|
|
6249
|
+
if (prop.type !== import_utils45.AST_NODE_TYPES.Property) {
|
|
6089
6250
|
return false;
|
|
6090
6251
|
}
|
|
6091
6252
|
if (prop.shorthand || prop.method || prop.kind !== "init") {
|
|
6092
6253
|
return false;
|
|
6093
6254
|
}
|
|
6094
|
-
if (prop.computed && prop.key.type !==
|
|
6255
|
+
if (prop.computed && prop.key.type !== import_utils45.AST_NODE_TYPES.Literal) {
|
|
6095
6256
|
return false;
|
|
6096
6257
|
}
|
|
6097
6258
|
return isLiteralOnly(prop.value, depth + 1);
|
|
@@ -6104,7 +6265,7 @@ function isLiteralOnly(node, depth) {
|
|
|
6104
6265
|
}
|
|
6105
6266
|
function unwrapObjectFreeze(node) {
|
|
6106
6267
|
const inner = unwrap3(node);
|
|
6107
|
-
if (inner.type ===
|
|
6268
|
+
if (inner.type === import_utils45.AST_NODE_TYPES.CallExpression && inner.callee.type === import_utils45.AST_NODE_TYPES.MemberExpression && !inner.callee.computed && inner.callee.object.type === import_utils45.AST_NODE_TYPES.Identifier && inner.callee.object.name === "Object" && inner.callee.property.type === import_utils45.AST_NODE_TYPES.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== import_utils45.AST_NODE_TYPES.SpreadElement) {
|
|
6108
6269
|
return unwrap3(inner.arguments[0]);
|
|
6109
6270
|
}
|
|
6110
6271
|
return inner;
|
|
@@ -6120,19 +6281,19 @@ function classify(init, checkRegex) {
|
|
|
6120
6281
|
}
|
|
6121
6282
|
return { kind: "regex", size: 1 };
|
|
6122
6283
|
}
|
|
6123
|
-
if (node.type ===
|
|
6284
|
+
if (node.type === import_utils45.AST_NODE_TYPES.ArrayExpression) {
|
|
6124
6285
|
return isLiteralOnly(node, 0) ? { kind: "array", size: node.elements.length } : null;
|
|
6125
6286
|
}
|
|
6126
|
-
if (node.type ===
|
|
6287
|
+
if (node.type === import_utils45.AST_NODE_TYPES.ObjectExpression) {
|
|
6127
6288
|
return isLiteralOnly(node, 0) ? { kind: "object", size: node.properties.length } : null;
|
|
6128
6289
|
}
|
|
6129
|
-
if (node.type ===
|
|
6290
|
+
if (node.type === import_utils45.AST_NODE_TYPES.NewExpression && node.callee.type === import_utils45.AST_NODE_TYPES.Identifier && COLLECTION_CONSTRUCTORS.has(node.callee.name)) {
|
|
6130
6291
|
const arg = node.arguments[0];
|
|
6131
|
-
if (node.arguments.length !== 1 || arg === void 0 || arg.type ===
|
|
6292
|
+
if (node.arguments.length !== 1 || arg === void 0 || arg.type === import_utils45.AST_NODE_TYPES.SpreadElement) {
|
|
6132
6293
|
return null;
|
|
6133
6294
|
}
|
|
6134
6295
|
const entries = unwrap3(arg);
|
|
6135
|
-
if (entries.type !==
|
|
6296
|
+
if (entries.type !== import_utils45.AST_NODE_TYPES.ArrayExpression) {
|
|
6136
6297
|
return null;
|
|
6137
6298
|
}
|
|
6138
6299
|
return isLiteralOnly(entries, 0) ? { kind: node.callee.name === "Set" ? "Set" : "Map", size: entries.elements.length } : null;
|
|
@@ -6161,10 +6322,10 @@ var NON_RETAINING_BUILTINS = /* @__PURE__ */ new Map(
|
|
|
6161
6322
|
);
|
|
6162
6323
|
function isNonRetainingBuiltinCall(node, argument) {
|
|
6163
6324
|
const callee = node.callee;
|
|
6164
|
-
if (callee.type ===
|
|
6325
|
+
if (callee.type === import_utils45.AST_NODE_TYPES.Identifier && callee.name === "structuredClone") {
|
|
6165
6326
|
return true;
|
|
6166
6327
|
}
|
|
6167
|
-
if (callee.type !==
|
|
6328
|
+
if (callee.type !== import_utils45.AST_NODE_TYPES.MemberExpression || callee.computed || callee.object.type !== import_utils45.AST_NODE_TYPES.Identifier || callee.property.type !== import_utils45.AST_NODE_TYPES.Identifier) {
|
|
6168
6329
|
return false;
|
|
6169
6330
|
}
|
|
6170
6331
|
const members = NON_RETAINING_BUILTINS.get(callee.object.name);
|
|
@@ -6178,38 +6339,38 @@ function isNonRetainingBuiltinCall(node, argument) {
|
|
|
6178
6339
|
}
|
|
6179
6340
|
function isSafeRead(identifier) {
|
|
6180
6341
|
const parent = identifier.parent;
|
|
6181
|
-
if (parent.type ===
|
|
6342
|
+
if (parent.type === import_utils45.AST_NODE_TYPES.MemberExpression) {
|
|
6182
6343
|
if (parent.object !== identifier) {
|
|
6183
6344
|
return true;
|
|
6184
6345
|
}
|
|
6185
6346
|
const grandparent = parent.parent;
|
|
6186
|
-
if (grandparent.type ===
|
|
6347
|
+
if (grandparent.type === import_utils45.AST_NODE_TYPES.AssignmentExpression && grandparent.left === parent) {
|
|
6187
6348
|
return false;
|
|
6188
6349
|
}
|
|
6189
|
-
if (grandparent.type ===
|
|
6350
|
+
if (grandparent.type === import_utils45.AST_NODE_TYPES.UpdateExpression) {
|
|
6190
6351
|
return false;
|
|
6191
6352
|
}
|
|
6192
|
-
if (grandparent.type ===
|
|
6353
|
+
if (grandparent.type === import_utils45.AST_NODE_TYPES.UnaryExpression && grandparent.operator === "delete") {
|
|
6193
6354
|
return false;
|
|
6194
6355
|
}
|
|
6195
|
-
if (!parent.computed && parent.property.type ===
|
|
6356
|
+
if (!parent.computed && parent.property.type === import_utils45.AST_NODE_TYPES.Identifier && MUTATING_METHODS.has(parent.property.name) && grandparent.type === import_utils45.AST_NODE_TYPES.CallExpression && grandparent.callee === parent) {
|
|
6196
6357
|
return false;
|
|
6197
6358
|
}
|
|
6198
6359
|
return true;
|
|
6199
6360
|
}
|
|
6200
|
-
if (parent.type ===
|
|
6361
|
+
if (parent.type === import_utils45.AST_NODE_TYPES.ForOfStatement && parent.right === identifier) {
|
|
6201
6362
|
return true;
|
|
6202
6363
|
}
|
|
6203
|
-
if (parent.type ===
|
|
6364
|
+
if (parent.type === import_utils45.AST_NODE_TYPES.SpreadElement) {
|
|
6204
6365
|
return true;
|
|
6205
6366
|
}
|
|
6206
|
-
if (parent.type ===
|
|
6367
|
+
if (parent.type === import_utils45.AST_NODE_TYPES.BinaryExpression) {
|
|
6207
6368
|
return true;
|
|
6208
6369
|
}
|
|
6209
|
-
if (parent.type ===
|
|
6370
|
+
if (parent.type === import_utils45.AST_NODE_TYPES.CallExpression && parent.arguments.includes(identifier) && isNonRetainingBuiltinCall(parent, identifier)) {
|
|
6210
6371
|
return true;
|
|
6211
6372
|
}
|
|
6212
|
-
if (parent.type ===
|
|
6373
|
+
if (parent.type === import_utils45.AST_NODE_TYPES.UnaryExpression && parent.operator !== "delete") {
|
|
6213
6374
|
return true;
|
|
6214
6375
|
}
|
|
6215
6376
|
return false;
|
|
@@ -6264,7 +6425,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6264
6425
|
if (reference.isWrite()) {
|
|
6265
6426
|
return false;
|
|
6266
6427
|
}
|
|
6267
|
-
if (reference.identifier.type !==
|
|
6428
|
+
if (reference.identifier.type !== import_utils45.AST_NODE_TYPES.Identifier) {
|
|
6268
6429
|
return false;
|
|
6269
6430
|
}
|
|
6270
6431
|
if (!isSafeRead(reference.identifier)) {
|
|
@@ -6276,10 +6437,10 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6276
6437
|
return {
|
|
6277
6438
|
VariableDeclarator(node) {
|
|
6278
6439
|
const declaration = node.parent;
|
|
6279
|
-
if (declaration.type !==
|
|
6440
|
+
if (declaration.type !== import_utils45.AST_NODE_TYPES.VariableDeclaration || declaration.kind !== "const" || declaration.declare === true) {
|
|
6280
6441
|
return;
|
|
6281
6442
|
}
|
|
6282
|
-
if (node.id.type !==
|
|
6443
|
+
if (node.id.type !== import_utils45.AST_NODE_TYPES.Identifier || node.init === null) {
|
|
6283
6444
|
return;
|
|
6284
6445
|
}
|
|
6285
6446
|
if (enclosingFunction2(node) === null) {
|
|
@@ -6306,7 +6467,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6306
6467
|
});
|
|
6307
6468
|
|
|
6308
6469
|
// src/rules/prefer-module-level-schema.ts
|
|
6309
|
-
var
|
|
6470
|
+
var import_utils46 = require("@typescript-eslint/utils");
|
|
6310
6471
|
|
|
6311
6472
|
// src/rules/_zod.ts
|
|
6312
6473
|
var ZOD_PREFIX_RE = /^Z[A-Z]/;
|
|
@@ -6372,9 +6533,9 @@ var I18N_RECEIVER_NAMES = /* @__PURE__ */ new Set([
|
|
|
6372
6533
|
"intl"
|
|
6373
6534
|
]);
|
|
6374
6535
|
var FUNCTION_TYPES6 = /* @__PURE__ */ new Set([
|
|
6375
|
-
|
|
6376
|
-
|
|
6377
|
-
|
|
6536
|
+
import_utils46.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
6537
|
+
import_utils46.AST_NODE_TYPES.FunctionDeclaration,
|
|
6538
|
+
import_utils46.AST_NODE_TYPES.FunctionExpression
|
|
6378
6539
|
]);
|
|
6379
6540
|
function schemaExpression(node) {
|
|
6380
6541
|
let current = node;
|
|
@@ -6383,10 +6544,10 @@ function schemaExpression(node) {
|
|
|
6383
6544
|
if (parent === void 0) {
|
|
6384
6545
|
return current;
|
|
6385
6546
|
}
|
|
6386
|
-
if (parent.type ===
|
|
6547
|
+
if (parent.type === import_utils46.AST_NODE_TYPES.MemberExpression && parent.object === current && !parent.computed && parent.property.type === import_utils46.AST_NODE_TYPES.Identifier && TERMINAL_METHODS.has(parent.property.name)) {
|
|
6387
6548
|
return current;
|
|
6388
6549
|
}
|
|
6389
|
-
if (parent.type ===
|
|
6550
|
+
if (parent.type === import_utils46.AST_NODE_TYPES.MemberExpression && parent.object === current || parent.type === import_utils46.AST_NODE_TYPES.CallExpression && parent.callee === current || parent.type === import_utils46.AST_NODE_TYPES.TSAsExpression && parent.expression === current || parent.type === import_utils46.AST_NODE_TYPES.TSNonNullExpression && parent.expression === current) {
|
|
6390
6551
|
current = parent;
|
|
6391
6552
|
continue;
|
|
6392
6553
|
}
|
|
@@ -6437,22 +6598,22 @@ function subtreeSome(root, predicate) {
|
|
|
6437
6598
|
function readsReceiver(node) {
|
|
6438
6599
|
return subtreeSome(
|
|
6439
6600
|
node,
|
|
6440
|
-
(inner) => inner.type ===
|
|
6601
|
+
(inner) => inner.type === import_utils46.AST_NODE_TYPES.ThisExpression || inner.type === import_utils46.AST_NODE_TYPES.Super || inner.type === import_utils46.AST_NODE_TYPES.Identifier && inner.name === "arguments"
|
|
6441
6602
|
);
|
|
6442
6603
|
}
|
|
6443
6604
|
function buildsLocalizedText(node) {
|
|
6444
6605
|
return subtreeSome(node, (inner) => {
|
|
6445
|
-
if (inner.type ===
|
|
6606
|
+
if (inner.type === import_utils46.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
6446
6607
|
return true;
|
|
6447
6608
|
}
|
|
6448
|
-
if (inner.type !==
|
|
6609
|
+
if (inner.type !== import_utils46.AST_NODE_TYPES.CallExpression) {
|
|
6449
6610
|
return false;
|
|
6450
6611
|
}
|
|
6451
6612
|
const { callee } = inner;
|
|
6452
|
-
if (callee.type ===
|
|
6613
|
+
if (callee.type === import_utils46.AST_NODE_TYPES.Identifier) {
|
|
6453
6614
|
return I18N_CALLEE_NAMES.has(callee.name);
|
|
6454
6615
|
}
|
|
6455
|
-
return callee.type ===
|
|
6616
|
+
return callee.type === import_utils46.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.object.type === import_utils46.AST_NODE_TYPES.Identifier && I18N_RECEIVER_NAMES.has(callee.object.name);
|
|
6456
6617
|
});
|
|
6457
6618
|
}
|
|
6458
6619
|
function collectReferences(scope, out) {
|
|
@@ -6509,15 +6670,15 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6509
6670
|
}
|
|
6510
6671
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
6511
6672
|
function isZodCall(node) {
|
|
6512
|
-
return node.type ===
|
|
6673
|
+
return node.type === import_utils46.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils46.AST_NODE_TYPES.MemberExpression && !node.callee.computed && node.callee.object.type === import_utils46.AST_NODE_TYPES.Identifier && zodNamespaces.has(node.callee.object.name);
|
|
6513
6674
|
}
|
|
6514
6675
|
function isCovered(node) {
|
|
6515
6676
|
let current = node.parent ?? void 0;
|
|
6516
6677
|
while (current !== void 0) {
|
|
6517
|
-
if (current !== node && isZodCall(current) && current.callee.type ===
|
|
6678
|
+
if (current !== node && isZodCall(current) && current.callee.type === import_utils46.AST_NODE_TYPES.MemberExpression && current.callee.property.type === import_utils46.AST_NODE_TYPES.Identifier && factories.has(current.callee.property.name)) {
|
|
6518
6679
|
return true;
|
|
6519
6680
|
}
|
|
6520
|
-
if (current.type ===
|
|
6681
|
+
if (current.type === import_utils46.AST_NODE_TYPES.CallExpression && (current.callee.type === import_utils46.AST_NODE_TYPES.Identifier && MEMO_CALLEES.has(current.callee.name) || current.callee.type === import_utils46.AST_NODE_TYPES.MemberExpression && !current.callee.computed && current.callee.property.type === import_utils46.AST_NODE_TYPES.Identifier && MEMO_CALLEES.has(current.callee.property.name))) {
|
|
6521
6682
|
return true;
|
|
6522
6683
|
}
|
|
6523
6684
|
current = current.parent ?? void 0;
|
|
@@ -6532,11 +6693,11 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6532
6693
|
if (parent === void 0) {
|
|
6533
6694
|
return confirmed;
|
|
6534
6695
|
}
|
|
6535
|
-
if (parent.type ===
|
|
6696
|
+
if (parent.type === import_utils46.AST_NODE_TYPES.Property && parent.value === current || parent.type === import_utils46.AST_NODE_TYPES.ObjectExpression || parent.type === import_utils46.AST_NODE_TYPES.ArrayExpression) {
|
|
6536
6697
|
current = parent;
|
|
6537
6698
|
continue;
|
|
6538
6699
|
}
|
|
6539
|
-
if (parent.type ===
|
|
6700
|
+
if (parent.type === import_utils46.AST_NODE_TYPES.CallExpression && parent.arguments.includes(current) && isSchemaComposition(parent)) {
|
|
6540
6701
|
current = schemaExpression(parent);
|
|
6541
6702
|
confirmed = current;
|
|
6542
6703
|
continue;
|
|
@@ -6546,7 +6707,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6546
6707
|
}
|
|
6547
6708
|
function isSchemaComposition(node) {
|
|
6548
6709
|
const { callee } = node;
|
|
6549
|
-
const isCombinator = callee.type ===
|
|
6710
|
+
const isCombinator = callee.type === import_utils46.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils46.AST_NODE_TYPES.Identifier && ZOD_COMBINATOR_METHODS.has(callee.property.name);
|
|
6550
6711
|
return isCombinator || isZodCall(node);
|
|
6551
6712
|
}
|
|
6552
6713
|
function closesOverNothing(node, enclosing) {
|
|
@@ -6580,13 +6741,13 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6580
6741
|
}
|
|
6581
6742
|
function ownerName(enclosing) {
|
|
6582
6743
|
const parent = enclosing.parent ?? void 0;
|
|
6583
|
-
if (enclosing.type ===
|
|
6744
|
+
if (enclosing.type === import_utils46.AST_NODE_TYPES.FunctionDeclaration && enclosing.id !== null) {
|
|
6584
6745
|
return enclosing.id.name;
|
|
6585
6746
|
}
|
|
6586
|
-
if (parent !== void 0 && parent.type ===
|
|
6747
|
+
if (parent !== void 0 && parent.type === import_utils46.AST_NODE_TYPES.VariableDeclarator && parent.id.type === import_utils46.AST_NODE_TYPES.Identifier) {
|
|
6587
6748
|
return parent.id.name;
|
|
6588
6749
|
}
|
|
6589
|
-
if (parent !== void 0 && (parent.type ===
|
|
6750
|
+
if (parent !== void 0 && (parent.type === import_utils46.AST_NODE_TYPES.MethodDefinition || parent.type === import_utils46.AST_NODE_TYPES.Property) && parent.key.type === import_utils46.AST_NODE_TYPES.Identifier) {
|
|
6590
6751
|
return parent.key.name;
|
|
6591
6752
|
}
|
|
6592
6753
|
return "this function";
|
|
@@ -6597,7 +6758,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6597
6758
|
return;
|
|
6598
6759
|
}
|
|
6599
6760
|
for (const specifier of node.specifiers) {
|
|
6600
|
-
if (specifier.type ===
|
|
6761
|
+
if (specifier.type === import_utils46.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils46.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils46.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils46.AST_NODE_TYPES.Identifier && specifier.imported.name === "z") {
|
|
6601
6762
|
zodNamespaces.add(specifier.local.name);
|
|
6602
6763
|
}
|
|
6603
6764
|
}
|
|
@@ -6607,7 +6768,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6607
6768
|
return;
|
|
6608
6769
|
}
|
|
6609
6770
|
const callee = node.callee;
|
|
6610
|
-
if (callee.property.type !==
|
|
6771
|
+
if (callee.property.type !== import_utils46.AST_NODE_TYPES.Identifier) {
|
|
6611
6772
|
return;
|
|
6612
6773
|
}
|
|
6613
6774
|
const factory = callee.property.name;
|
|
@@ -6622,7 +6783,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6622
6783
|
return;
|
|
6623
6784
|
}
|
|
6624
6785
|
const shape = node.arguments[0];
|
|
6625
|
-
if (shape !== void 0 && shape.type ===
|
|
6786
|
+
if (shape !== void 0 && shape.type === import_utils46.AST_NODE_TYPES.ObjectExpression && shape.properties.length < minProperties) {
|
|
6626
6787
|
return;
|
|
6627
6788
|
}
|
|
6628
6789
|
const expression = schemaExpression(node);
|
|
@@ -6650,20 +6811,20 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6650
6811
|
});
|
|
6651
6812
|
|
|
6652
6813
|
// src/rules/prefer-non-nullable-collection.ts
|
|
6653
|
-
var
|
|
6814
|
+
var import_utils47 = require("@typescript-eslint/utils");
|
|
6654
6815
|
var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
6655
6816
|
function propertyName(node) {
|
|
6656
6817
|
const key = node.key;
|
|
6657
|
-
if (key.type ===
|
|
6658
|
-
if (key.type ===
|
|
6818
|
+
if (key.type === import_utils47.AST_NODE_TYPES.Identifier) return key.name;
|
|
6819
|
+
if (key.type === import_utils47.AST_NODE_TYPES.Literal) return String(key.value);
|
|
6659
6820
|
return "collection";
|
|
6660
6821
|
}
|
|
6661
6822
|
function isArrayType(node) {
|
|
6662
|
-
if (node.type ===
|
|
6663
|
-
return node.type ===
|
|
6823
|
+
if (node.type === import_utils47.AST_NODE_TYPES.TSArrayType) return true;
|
|
6824
|
+
return node.type === import_utils47.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils47.AST_NODE_TYPES.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
6664
6825
|
}
|
|
6665
6826
|
function isNullishType(node) {
|
|
6666
|
-
return node.type ===
|
|
6827
|
+
return node.type === import_utils47.AST_NODE_TYPES.TSNullKeyword || node.type === import_utils47.AST_NODE_TYPES.TSUndefinedKeyword;
|
|
6667
6828
|
}
|
|
6668
6829
|
function isNullableArrayOnly(node) {
|
|
6669
6830
|
const values = node.types.filter((member) => !isNullishType(member));
|
|
@@ -6690,7 +6851,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
6690
6851
|
function checkOptionalProperty(node) {
|
|
6691
6852
|
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
6692
6853
|
if (annotation === void 0) return;
|
|
6693
|
-
if (annotation.type !==
|
|
6854
|
+
if (annotation.type !== import_utils47.AST_NODE_TYPES.TSUnionType || !isNullableArrayOnly(annotation)) {
|
|
6694
6855
|
return;
|
|
6695
6856
|
}
|
|
6696
6857
|
context.report({
|
|
@@ -6703,7 +6864,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
6703
6864
|
TSPropertySignature: checkOptionalProperty,
|
|
6704
6865
|
PropertyDefinition: checkOptionalProperty,
|
|
6705
6866
|
TSTypeAliasDeclaration(node) {
|
|
6706
|
-
if (node.typeAnnotation.type !==
|
|
6867
|
+
if (node.typeAnnotation.type !== import_utils47.AST_NODE_TYPES.TSUnionType) return;
|
|
6707
6868
|
if (!isNullableArrayOnly(node.typeAnnotation)) return;
|
|
6708
6869
|
context.report({
|
|
6709
6870
|
node,
|
|
@@ -6716,13 +6877,13 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
6716
6877
|
});
|
|
6717
6878
|
|
|
6718
6879
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
6719
|
-
var
|
|
6880
|
+
var import_utils48 = require("@typescript-eslint/utils");
|
|
6720
6881
|
var unwrap4 = (node) => {
|
|
6721
6882
|
let current = node;
|
|
6722
6883
|
while (current !== null && current !== void 0) {
|
|
6723
|
-
if (current.type ===
|
|
6884
|
+
if (current.type === import_utils48.AST_NODE_TYPES.TSAsExpression || current.type === import_utils48.AST_NODE_TYPES.TSTypeAssertion || current.type === import_utils48.AST_NODE_TYPES.TSNonNullExpression || current.type === import_utils48.AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
6724
6885
|
current = current.expression;
|
|
6725
|
-
} else if (current.type ===
|
|
6886
|
+
} else if (current.type === import_utils48.AST_NODE_TYPES.ChainExpression) {
|
|
6726
6887
|
current = current.expression;
|
|
6727
6888
|
} else {
|
|
6728
6889
|
break;
|
|
@@ -6737,23 +6898,23 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
6737
6898
|
]);
|
|
6738
6899
|
var isSchemaParseReference = (node) => {
|
|
6739
6900
|
const inner = unwrap4(node);
|
|
6740
|
-
return inner !== null && inner.type ===
|
|
6901
|
+
return inner !== null && inner.type === import_utils48.AST_NODE_TYPES.MemberExpression && !inner.computed && inner.property.type === import_utils48.AST_NODE_TYPES.Identifier && (inner.property.name === "parse" || inner.property.name === "safeParse");
|
|
6741
6902
|
};
|
|
6742
6903
|
var isRawPayloadSource = (node) => {
|
|
6743
6904
|
let current = unwrap4(node);
|
|
6744
6905
|
if (current === null) return false;
|
|
6745
|
-
if (current.type ===
|
|
6906
|
+
if (current.type === import_utils48.AST_NODE_TYPES.AwaitExpression) {
|
|
6746
6907
|
current = unwrap4(current.argument);
|
|
6747
6908
|
}
|
|
6748
|
-
if (current === null || current.type !==
|
|
6909
|
+
if (current === null || current.type !== import_utils48.AST_NODE_TYPES.CallExpression) {
|
|
6749
6910
|
return false;
|
|
6750
6911
|
}
|
|
6751
6912
|
const callee = unwrap4(current.callee);
|
|
6752
|
-
if (callee === null || callee.type !==
|
|
6913
|
+
if (callee === null || callee.type !== import_utils48.AST_NODE_TYPES.MemberExpression) {
|
|
6753
6914
|
return false;
|
|
6754
6915
|
}
|
|
6755
6916
|
const property = unwrap4(callee.property);
|
|
6756
|
-
if (property === null || property.type !==
|
|
6917
|
+
if (property === null || property.type !== import_utils48.AST_NODE_TYPES.Identifier) {
|
|
6757
6918
|
return false;
|
|
6758
6919
|
}
|
|
6759
6920
|
if (property.name === "json") {
|
|
@@ -6763,7 +6924,7 @@ var isRawPayloadSource = (node) => {
|
|
|
6763
6924
|
return !current.arguments.some(isSchemaParseReference) && isRawPayloadSource(callee.object);
|
|
6764
6925
|
}
|
|
6765
6926
|
const object = unwrap4(callee.object);
|
|
6766
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
6927
|
+
return property.name === "parse" && object !== null && object.type === import_utils48.AST_NODE_TYPES.Identifier && object.name === "JSON" && // ...but not `JSON.parse(readFileSync(p, "utf8"))` — see isLocalFileRead.
|
|
6767
6928
|
!isLocalFileRead(current.arguments[0]);
|
|
6768
6929
|
};
|
|
6769
6930
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
@@ -6771,9 +6932,9 @@ var isLocalFileRead = (node) => {
|
|
|
6771
6932
|
let found = false;
|
|
6772
6933
|
const visit = (current) => {
|
|
6773
6934
|
if (found || current === null || current === void 0) return;
|
|
6774
|
-
if (current.type ===
|
|
6935
|
+
if (current.type === import_utils48.AST_NODE_TYPES.CallExpression) {
|
|
6775
6936
|
const callee = unwrap4(current.callee);
|
|
6776
|
-
const name = callee?.type ===
|
|
6937
|
+
const name = callee?.type === import_utils48.AST_NODE_TYPES.Identifier ? callee.name : callee?.type === import_utils48.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils48.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
6777
6938
|
if (name !== null && FILE_READ_RE.test(name)) {
|
|
6778
6939
|
found = true;
|
|
6779
6940
|
return;
|
|
@@ -6795,15 +6956,15 @@ var isLocalFileRead = (node) => {
|
|
|
6795
6956
|
var ASSERTION_CALLEE_RE = /^(expect|assert|should|invariant)$/;
|
|
6796
6957
|
var isInsideAssertion = (node) => {
|
|
6797
6958
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
6798
|
-
if (current.type !==
|
|
6959
|
+
if (current.type !== import_utils48.AST_NODE_TYPES.CallExpression) continue;
|
|
6799
6960
|
let callee = current.callee;
|
|
6800
|
-
while (callee.type ===
|
|
6961
|
+
while (callee.type === import_utils48.AST_NODE_TYPES.MemberExpression) {
|
|
6801
6962
|
callee = callee.object;
|
|
6802
6963
|
}
|
|
6803
|
-
if (callee.type ===
|
|
6964
|
+
if (callee.type === import_utils48.AST_NODE_TYPES.CallExpression) {
|
|
6804
6965
|
callee = callee.callee;
|
|
6805
6966
|
}
|
|
6806
|
-
if (callee.type ===
|
|
6967
|
+
if (callee.type === import_utils48.AST_NODE_TYPES.Identifier && ASSERTION_CALLEE_RE.test(callee.name)) {
|
|
6807
6968
|
return true;
|
|
6808
6969
|
}
|
|
6809
6970
|
}
|
|
@@ -6822,39 +6983,39 @@ var GUARD_NAME_RE = /^(?:is|validate|parse|assert|decode|coerce)[A-Z]/;
|
|
|
6822
6983
|
var isValidationRead = (node) => {
|
|
6823
6984
|
let current = node;
|
|
6824
6985
|
let parent = current.parent;
|
|
6825
|
-
while (parent !== null && parent !== void 0 && (parent.type ===
|
|
6986
|
+
while (parent !== null && parent !== void 0 && (parent.type === import_utils48.AST_NODE_TYPES.TSAsExpression || parent.type === import_utils48.AST_NODE_TYPES.TSTypeAssertion || parent.type === import_utils48.AST_NODE_TYPES.TSNonNullExpression || parent.type === import_utils48.AST_NODE_TYPES.TSSatisfiesExpression || parent.type === import_utils48.AST_NODE_TYPES.ChainExpression)) {
|
|
6826
6987
|
current = parent;
|
|
6827
6988
|
parent = parent.parent;
|
|
6828
6989
|
}
|
|
6829
6990
|
if (parent === null || parent === void 0) return false;
|
|
6830
|
-
if (parent.type ===
|
|
6991
|
+
if (parent.type === import_utils48.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof" && parent.argument === current) {
|
|
6831
6992
|
return true;
|
|
6832
6993
|
}
|
|
6833
|
-
if (parent.type !==
|
|
6994
|
+
if (parent.type !== import_utils48.AST_NODE_TYPES.CallExpression || !parent.arguments.some((arg) => arg === current)) {
|
|
6834
6995
|
return false;
|
|
6835
6996
|
}
|
|
6836
6997
|
const callee = parent.callee;
|
|
6837
|
-
if (callee.type ===
|
|
6998
|
+
if (callee.type === import_utils48.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.object.type === import_utils48.AST_NODE_TYPES.Identifier && callee.object.name === "Array" && callee.property.type === import_utils48.AST_NODE_TYPES.Identifier && callee.property.name === "isArray") {
|
|
6838
6999
|
return parent.arguments.length === 1;
|
|
6839
7000
|
}
|
|
6840
|
-
return callee.type ===
|
|
7001
|
+
return callee.type === import_utils48.AST_NODE_TYPES.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
6841
7002
|
};
|
|
6842
7003
|
var isGuardTestPosition = (node) => {
|
|
6843
7004
|
let current = node;
|
|
6844
7005
|
let parent = current.parent;
|
|
6845
7006
|
while (parent !== void 0 && parent !== null) {
|
|
6846
7007
|
switch (parent.type) {
|
|
6847
|
-
case
|
|
6848
|
-
case
|
|
6849
|
-
case
|
|
7008
|
+
case import_utils48.AST_NODE_TYPES.UnaryExpression:
|
|
7009
|
+
case import_utils48.AST_NODE_TYPES.LogicalExpression:
|
|
7010
|
+
case import_utils48.AST_NODE_TYPES.ChainExpression:
|
|
6850
7011
|
current = parent;
|
|
6851
7012
|
parent = parent.parent;
|
|
6852
7013
|
continue;
|
|
6853
|
-
case
|
|
6854
|
-
case
|
|
6855
|
-
case
|
|
6856
|
-
case
|
|
6857
|
-
case
|
|
7014
|
+
case import_utils48.AST_NODE_TYPES.IfStatement:
|
|
7015
|
+
case import_utils48.AST_NODE_TYPES.ConditionalExpression:
|
|
7016
|
+
case import_utils48.AST_NODE_TYPES.WhileStatement:
|
|
7017
|
+
case import_utils48.AST_NODE_TYPES.DoWhileStatement:
|
|
7018
|
+
case import_utils48.AST_NODE_TYPES.ForStatement:
|
|
6858
7019
|
return parent.test === current;
|
|
6859
7020
|
default:
|
|
6860
7021
|
return false;
|
|
@@ -6864,7 +7025,7 @@ var isGuardTestPosition = (node) => {
|
|
|
6864
7025
|
};
|
|
6865
7026
|
var isUnvalidatedVariableRef = (node, scope, tracked) => {
|
|
6866
7027
|
const unwrapped = unwrap4(node);
|
|
6867
|
-
if (unwrapped === null || unwrapped.type !==
|
|
7028
|
+
if (unwrapped === null || unwrapped.type !== import_utils48.AST_NODE_TYPES.Identifier) {
|
|
6868
7029
|
return false;
|
|
6869
7030
|
}
|
|
6870
7031
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -6907,11 +7068,11 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6907
7068
|
return {
|
|
6908
7069
|
VariableDeclarator(node) {
|
|
6909
7070
|
const scope = context.sourceCode.getScope(node);
|
|
6910
|
-
if (node.id.type ===
|
|
7071
|
+
if (node.id.type === import_utils48.AST_NODE_TYPES.Identifier) {
|
|
6911
7072
|
trackInitializer(node);
|
|
6912
7073
|
return;
|
|
6913
7074
|
}
|
|
6914
|
-
if (node.id.type ===
|
|
7075
|
+
if (node.id.type === import_utils48.AST_NODE_TYPES.ObjectPattern || node.id.type === import_utils48.AST_NODE_TYPES.ArrayPattern) {
|
|
6915
7076
|
if (isRawPayloadSource(node.init)) {
|
|
6916
7077
|
if (!isFullyNarrowedPattern(node)) {
|
|
6917
7078
|
context.report({ node: node.id, messageId: "unparsedJsonAccess" });
|
|
@@ -6925,7 +7086,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6925
7086
|
},
|
|
6926
7087
|
AssignmentExpression(node) {
|
|
6927
7088
|
const scope = context.sourceCode.getScope(node);
|
|
6928
|
-
if (node.left.type ===
|
|
7089
|
+
if (node.left.type === import_utils48.AST_NODE_TYPES.Identifier) {
|
|
6929
7090
|
const variable = findVariable2(scope, node.left.name);
|
|
6930
7091
|
if (variable === null) return;
|
|
6931
7092
|
if (isRawPayloadSource(node.right)) {
|
|
@@ -6935,7 +7096,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6935
7096
|
}
|
|
6936
7097
|
return;
|
|
6937
7098
|
}
|
|
6938
|
-
if (node.left.type ===
|
|
7099
|
+
if (node.left.type === import_utils48.AST_NODE_TYPES.ObjectPattern || node.left.type === import_utils48.AST_NODE_TYPES.ArrayPattern) {
|
|
6939
7100
|
if (isRawPayloadSource(node.right)) {
|
|
6940
7101
|
context.report({
|
|
6941
7102
|
node: node.left,
|
|
@@ -6952,15 +7113,15 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6952
7113
|
}
|
|
6953
7114
|
},
|
|
6954
7115
|
CallExpression(node) {
|
|
6955
|
-
if (node.callee.type !==
|
|
7116
|
+
if (node.callee.type !== import_utils48.AST_NODE_TYPES.Identifier) return;
|
|
6956
7117
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
6957
7118
|
return;
|
|
6958
7119
|
}
|
|
6959
7120
|
const scope = context.sourceCode.getScope(node);
|
|
6960
7121
|
for (const arg of node.arguments) {
|
|
6961
|
-
if (arg.type ===
|
|
7122
|
+
if (arg.type === import_utils48.AST_NODE_TYPES.SpreadElement) continue;
|
|
6962
7123
|
const unwrapped = unwrap4(arg);
|
|
6963
|
-
if (unwrapped === null || unwrapped.type !==
|
|
7124
|
+
if (unwrapped === null || unwrapped.type !== import_utils48.AST_NODE_TYPES.Identifier) {
|
|
6964
7125
|
continue;
|
|
6965
7126
|
}
|
|
6966
7127
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -6974,13 +7135,13 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6974
7135
|
const obj = unwrap4(node.object);
|
|
6975
7136
|
if (isRawPayloadSource(obj)) {
|
|
6976
7137
|
const parent = node.parent;
|
|
6977
|
-
if (parent.type ===
|
|
7138
|
+
if (parent.type === import_utils48.AST_NODE_TYPES.CallExpression && parent.callee === node && node.property.type === import_utils48.AST_NODE_TYPES.Identifier && (node.property.name === "parse" || node.property.name === "safeParse" || PROMISE_CHAIN_METHODS.has(node.property.name))) {
|
|
6978
7139
|
return;
|
|
6979
7140
|
}
|
|
6980
7141
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
6981
7142
|
return;
|
|
6982
7143
|
}
|
|
6983
|
-
if (obj !== null && obj.type ===
|
|
7144
|
+
if (obj !== null && obj.type === import_utils48.AST_NODE_TYPES.Identifier && isUnvalidatedVariableRef(obj, scope, unvalidatedVariables)) {
|
|
6984
7145
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
6985
7146
|
const variable = findVariable2(scope, obj.name);
|
|
6986
7147
|
if (variable !== null) {
|
|
@@ -6993,7 +7154,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6993
7154
|
});
|
|
6994
7155
|
|
|
6995
7156
|
// src/rules/prefer-semantic-colors.ts
|
|
6996
|
-
var
|
|
7157
|
+
var import_utils49 = require("@typescript-eslint/utils");
|
|
6997
7158
|
var import_fs = require("fs");
|
|
6998
7159
|
var import_path = require("path");
|
|
6999
7160
|
|
|
@@ -7093,8 +7254,8 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
7093
7254
|
]);
|
|
7094
7255
|
function jsxElementName(node) {
|
|
7095
7256
|
const name = node.openingElement.name;
|
|
7096
|
-
if (name.type ===
|
|
7097
|
-
if (name.type ===
|
|
7257
|
+
if (name.type === import_utils49.AST_NODE_TYPES.JSXIdentifier) return name.name;
|
|
7258
|
+
if (name.type === import_utils49.AST_NODE_TYPES.JSXMemberExpression && name.property.type === import_utils49.AST_NODE_TYPES.JSXIdentifier) {
|
|
7098
7259
|
return name.property.name;
|
|
7099
7260
|
}
|
|
7100
7261
|
return null;
|
|
@@ -7120,7 +7281,7 @@ var EMAIL_OR_PDF_IMPORT_RE = /@react-(?:email|pdf)\//;
|
|
|
7120
7281
|
var isInsideSvg = (node) => {
|
|
7121
7282
|
let current = node.parent;
|
|
7122
7283
|
while (current !== void 0 && current !== null) {
|
|
7123
|
-
if (current.type ===
|
|
7284
|
+
if (current.type === import_utils49.AST_NODE_TYPES.JSXElement) {
|
|
7124
7285
|
const name = jsxElementName(current);
|
|
7125
7286
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
7126
7287
|
}
|
|
@@ -7131,7 +7292,7 @@ var isInsideSvg = (node) => {
|
|
|
7131
7292
|
var isInsideIconFactoryPath = (node) => {
|
|
7132
7293
|
let current = node.parent;
|
|
7133
7294
|
while (current !== void 0 && current !== null) {
|
|
7134
|
-
if (current.type ===
|
|
7295
|
+
if (current.type === import_utils49.AST_NODE_TYPES.Property && propName(current.key) === "path" && current.parent.type === import_utils49.AST_NODE_TYPES.ObjectExpression && current.parent.parent.type === import_utils49.AST_NODE_TYPES.CallExpression && current.parent.parent.callee.type === import_utils49.AST_NODE_TYPES.Identifier && current.parent.parent.callee.name === "createIcon") {
|
|
7135
7296
|
return true;
|
|
7136
7297
|
}
|
|
7137
7298
|
current = current.parent;
|
|
@@ -7268,8 +7429,8 @@ var hasSemanticTokenSystem = (filename) => {
|
|
|
7268
7429
|
return root !== null && workspaceHasMarker(root);
|
|
7269
7430
|
};
|
|
7270
7431
|
var propName = (key) => {
|
|
7271
|
-
if (key.type ===
|
|
7272
|
-
if (key.type ===
|
|
7432
|
+
if (key.type === import_utils49.AST_NODE_TYPES.Identifier) return key.name;
|
|
7433
|
+
if (key.type === import_utils49.AST_NODE_TYPES.Literal && typeof key.value === "string") return key.value;
|
|
7273
7434
|
return null;
|
|
7274
7435
|
};
|
|
7275
7436
|
var prefer_semantic_colors_default = createRule({
|
|
@@ -7314,27 +7475,27 @@ var prefer_semantic_colors_default = createRule({
|
|
|
7314
7475
|
const checkClassNode = (node) => {
|
|
7315
7476
|
if (node === null) return;
|
|
7316
7477
|
switch (node.type) {
|
|
7317
|
-
case
|
|
7478
|
+
case import_utils49.AST_NODE_TYPES.Literal:
|
|
7318
7479
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
7319
7480
|
break;
|
|
7320
|
-
case
|
|
7481
|
+
case import_utils49.AST_NODE_TYPES.TemplateLiteral:
|
|
7321
7482
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
7322
7483
|
break;
|
|
7323
|
-
case
|
|
7484
|
+
case import_utils49.AST_NODE_TYPES.ArrayExpression:
|
|
7324
7485
|
for (const element of node.elements) {
|
|
7325
|
-
if (element !== null && element.type !==
|
|
7486
|
+
if (element !== null && element.type !== import_utils49.AST_NODE_TYPES.SpreadElement) checkClassNode(element);
|
|
7326
7487
|
}
|
|
7327
7488
|
break;
|
|
7328
|
-
case
|
|
7489
|
+
case import_utils49.AST_NODE_TYPES.ObjectExpression:
|
|
7329
7490
|
for (const property of node.properties) {
|
|
7330
|
-
if (property.type ===
|
|
7491
|
+
if (property.type === import_utils49.AST_NODE_TYPES.Property) checkClassNode(property.value);
|
|
7331
7492
|
}
|
|
7332
7493
|
break;
|
|
7333
|
-
case
|
|
7494
|
+
case import_utils49.AST_NODE_TYPES.ConditionalExpression:
|
|
7334
7495
|
checkClassNode(node.consequent);
|
|
7335
7496
|
checkClassNode(node.alternate);
|
|
7336
7497
|
break;
|
|
7337
|
-
case
|
|
7498
|
+
case import_utils49.AST_NODE_TYPES.LogicalExpression:
|
|
7338
7499
|
checkClassNode(node.right);
|
|
7339
7500
|
break;
|
|
7340
7501
|
default:
|
|
@@ -7342,29 +7503,29 @@ var prefer_semantic_colors_default = createRule({
|
|
|
7342
7503
|
}
|
|
7343
7504
|
};
|
|
7344
7505
|
const checkColorValueNode = (node) => {
|
|
7345
|
-
if (node.type ===
|
|
7506
|
+
if (node.type === import_utils49.AST_NODE_TYPES.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value) && !CSS_VAR_REFERENCE_RE.test(node.value)) {
|
|
7346
7507
|
context.report({ node, messageId: "inlineColor", data: { value: node.value } });
|
|
7347
7508
|
}
|
|
7348
7509
|
};
|
|
7349
7510
|
return {
|
|
7350
7511
|
"JSXAttribute[name.name='className']"(node) {
|
|
7351
7512
|
if (node.value === null) return;
|
|
7352
|
-
if (node.value.type ===
|
|
7353
|
-
else if (node.value.type ===
|
|
7354
|
-
if (node.value.expression.type !==
|
|
7513
|
+
if (node.value.type === import_utils49.AST_NODE_TYPES.Literal) checkClassNode(node.value);
|
|
7514
|
+
else if (node.value.type === import_utils49.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
7515
|
+
if (node.value.expression.type !== import_utils49.AST_NODE_TYPES.JSXEmptyExpression) {
|
|
7355
7516
|
checkClassNode(node.value.expression);
|
|
7356
7517
|
}
|
|
7357
7518
|
}
|
|
7358
7519
|
},
|
|
7359
7520
|
CallExpression(node) {
|
|
7360
|
-
if (node.callee.type ===
|
|
7521
|
+
if (node.callee.type === import_utils49.AST_NODE_TYPES.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
7361
7522
|
for (const arg of node.arguments) {
|
|
7362
|
-
if (arg.type !==
|
|
7523
|
+
if (arg.type !== import_utils49.AST_NODE_TYPES.SpreadElement) checkClassNode(arg);
|
|
7363
7524
|
}
|
|
7364
7525
|
}
|
|
7365
7526
|
},
|
|
7366
7527
|
VariableDeclarator(node) {
|
|
7367
|
-
if (node.id.type ===
|
|
7528
|
+
if (node.id.type === import_utils49.AST_NODE_TYPES.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
7368
7529
|
checkClassNode(node.init);
|
|
7369
7530
|
}
|
|
7370
7531
|
},
|
|
@@ -7376,9 +7537,9 @@ var prefer_semantic_colors_default = createRule({
|
|
|
7376
7537
|
// Neutral drawing literals and anything inside an SVG defs container are
|
|
7377
7538
|
// structural, not UI tokens, so they never fire.
|
|
7378
7539
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
7379
|
-
if (node.value?.type !==
|
|
7540
|
+
if (node.value?.type !== import_utils49.AST_NODE_TYPES.Literal) return;
|
|
7380
7541
|
const owner = node.parent.name;
|
|
7381
|
-
if (owner.type ===
|
|
7542
|
+
if (owner.type === import_utils49.AST_NODE_TYPES.JSXIdentifier && SVG_SHAPE_PRIMITIVES.has(owner.name)) {
|
|
7382
7543
|
return;
|
|
7383
7544
|
}
|
|
7384
7545
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
@@ -7396,7 +7557,7 @@ var prefer_semantic_colors_default = createRule({
|
|
|
7396
7557
|
});
|
|
7397
7558
|
|
|
7398
7559
|
// src/rules/prefer-server-actions.ts
|
|
7399
|
-
var
|
|
7560
|
+
var import_utils50 = require("@typescript-eslint/utils");
|
|
7400
7561
|
var MUTATION_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "DELETE", "PATCH"]);
|
|
7401
7562
|
var AXIOS_MUTATION_METHODS = /* @__PURE__ */ new Set(["post", "put", "delete", "patch"]);
|
|
7402
7563
|
var SKIP_FILE_REGEX = /(?:\.test\.[jt]sx?$|\.spec\.[jt]sx?$|-(?:test|spec)\.[jt]sx?$|\/tests?\/|\/__tests__\/|\/__testfixtures__\/|\/scripts?\/|\/app\/api\/.*\/route\.[jt]sx?$|\/pages\/api\/)/;
|
|
@@ -7549,7 +7710,7 @@ var prefer_server_actions_default = createRule({
|
|
|
7549
7710
|
});
|
|
7550
7711
|
|
|
7551
7712
|
// src/rules/prefer-string-literal-union.ts
|
|
7552
|
-
var
|
|
7713
|
+
var import_utils51 = require("@typescript-eslint/utils");
|
|
7553
7714
|
var ts2 = __toESM(require("typescript"), 1);
|
|
7554
7715
|
var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
7555
7716
|
"status",
|
|
@@ -7592,19 +7753,19 @@ function isChoiceLikeName(name) {
|
|
|
7592
7753
|
return CHOICE_TOKENS.has(lastWord(name));
|
|
7593
7754
|
}
|
|
7594
7755
|
function keyName(key) {
|
|
7595
|
-
if (key.type ===
|
|
7756
|
+
if (key.type === import_utils51.AST_NODE_TYPES.Identifier) {
|
|
7596
7757
|
return key.name;
|
|
7597
7758
|
}
|
|
7598
|
-
if (key.type ===
|
|
7759
|
+
if (key.type === import_utils51.AST_NODE_TYPES.Literal && typeof key.value === "string") {
|
|
7599
7760
|
return key.value;
|
|
7600
7761
|
}
|
|
7601
7762
|
return null;
|
|
7602
7763
|
}
|
|
7603
7764
|
function isStringLiteralMember(t) {
|
|
7604
|
-
return t.type ===
|
|
7765
|
+
return t.type === import_utils51.AST_NODE_TYPES.TSLiteralType && t.literal.type === import_utils51.AST_NODE_TYPES.Literal && typeof t.literal.value === "string";
|
|
7605
7766
|
}
|
|
7606
7767
|
function isStringLiteralUnion(node) {
|
|
7607
|
-
if (node?.type !==
|
|
7768
|
+
if (node?.type !== import_utils51.AST_NODE_TYPES.TSUnionType) {
|
|
7608
7769
|
return false;
|
|
7609
7770
|
}
|
|
7610
7771
|
return node.types.filter(isStringLiteralMember).length >= MIN_CLUSTER_SIZE;
|
|
@@ -7633,12 +7794,12 @@ function bindingSourceExpression(decl) {
|
|
|
7633
7794
|
return ts2.isForOfStatement(node) ? node.expression : node.initializer;
|
|
7634
7795
|
}
|
|
7635
7796
|
function refKey(node) {
|
|
7636
|
-
if (node.type ===
|
|
7797
|
+
if (node.type === import_utils51.AST_NODE_TYPES.Identifier) {
|
|
7637
7798
|
return node.name;
|
|
7638
7799
|
}
|
|
7639
|
-
if (node.type ===
|
|
7800
|
+
if (node.type === import_utils51.AST_NODE_TYPES.MemberExpression && !node.computed) {
|
|
7640
7801
|
const inner = refKey(node.object);
|
|
7641
|
-
if (inner === null || node.property.type !==
|
|
7802
|
+
if (inner === null || node.property.type !== import_utils51.AST_NODE_TYPES.Identifier) {
|
|
7642
7803
|
return null;
|
|
7643
7804
|
}
|
|
7644
7805
|
return `${inner}.${node.property.name}`;
|
|
@@ -7646,7 +7807,7 @@ function refKey(node) {
|
|
|
7646
7807
|
return null;
|
|
7647
7808
|
}
|
|
7648
7809
|
function strLiteral(node) {
|
|
7649
|
-
if (node.type ===
|
|
7810
|
+
if (node.type === import_utils51.AST_NODE_TYPES.Literal && typeof node.value === "string") {
|
|
7650
7811
|
return node.value;
|
|
7651
7812
|
}
|
|
7652
7813
|
return null;
|
|
@@ -7687,7 +7848,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
7687
7848
|
);
|
|
7688
7849
|
let services;
|
|
7689
7850
|
try {
|
|
7690
|
-
services =
|
|
7851
|
+
services = import_utils51.ESLintUtils.getParserServices(context);
|
|
7691
7852
|
} catch {
|
|
7692
7853
|
services = null;
|
|
7693
7854
|
}
|
|
@@ -7799,7 +7960,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
7799
7960
|
containersWithUnion.add(container);
|
|
7800
7961
|
return;
|
|
7801
7962
|
}
|
|
7802
|
-
if (typeNode?.type !==
|
|
7963
|
+
if (typeNode?.type !== import_utils51.AST_NODE_TYPES.TSStringKeyword) {
|
|
7803
7964
|
return;
|
|
7804
7965
|
}
|
|
7805
7966
|
const name = keyName(key);
|
|
@@ -7887,10 +8048,10 @@ var prefer_string_literal_union_default = createRule({
|
|
|
7887
8048
|
}
|
|
7888
8049
|
};
|
|
7889
8050
|
function refKeyText(node) {
|
|
7890
|
-
if (node.type ===
|
|
8051
|
+
if (node.type === import_utils51.AST_NODE_TYPES.BinaryExpression) {
|
|
7891
8052
|
return refKey(node.left) ?? refKey(node.right) ?? "value";
|
|
7892
8053
|
}
|
|
7893
|
-
if (node.type ===
|
|
8054
|
+
if (node.type === import_utils51.AST_NODE_TYPES.SwitchStatement) {
|
|
7894
8055
|
return refKey(node.discriminant) ?? "value";
|
|
7895
8056
|
}
|
|
7896
8057
|
return "value";
|
|
@@ -7899,7 +8060,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
7899
8060
|
});
|
|
7900
8061
|
|
|
7901
8062
|
// src/rules/prefer-whole-object-assertion.ts
|
|
7902
|
-
var
|
|
8063
|
+
var import_utils52 = require("@typescript-eslint/utils");
|
|
7903
8064
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
7904
8065
|
var ARRAY_MATCHERS = /* @__PURE__ */ new Set(["toEqual", "toStrictEqual"]);
|
|
7905
8066
|
var COLLECTION_PROPERTIES = /* @__PURE__ */ new Set(["length", "size"]);
|
|
@@ -7908,11 +8069,11 @@ var NUMERIC_SIGNS2 = /* @__PURE__ */ new Set(["-", "+"]);
|
|
|
7908
8069
|
var MIN_RUN_LENGTH = 2;
|
|
7909
8070
|
function literalText(node, getText) {
|
|
7910
8071
|
switch (node.type) {
|
|
7911
|
-
case
|
|
8072
|
+
case import_utils52.AST_NODE_TYPES.Literal:
|
|
7912
8073
|
return "regex" in node ? null : getText(node);
|
|
7913
|
-
case
|
|
8074
|
+
case import_utils52.AST_NODE_TYPES.TemplateLiteral:
|
|
7914
8075
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
7915
|
-
case
|
|
8076
|
+
case import_utils52.AST_NODE_TYPES.UnaryExpression:
|
|
7916
8077
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
7917
8078
|
default:
|
|
7918
8079
|
return null;
|
|
@@ -7920,15 +8081,15 @@ function literalText(node, getText) {
|
|
|
7920
8081
|
}
|
|
7921
8082
|
function isPureReceiver(node) {
|
|
7922
8083
|
switch (node.type) {
|
|
7923
|
-
case
|
|
7924
|
-
case
|
|
8084
|
+
case import_utils52.AST_NODE_TYPES.Identifier:
|
|
8085
|
+
case import_utils52.AST_NODE_TYPES.ThisExpression:
|
|
7925
8086
|
return true;
|
|
7926
|
-
case
|
|
8087
|
+
case import_utils52.AST_NODE_TYPES.MemberExpression:
|
|
7927
8088
|
if (node.optional) {
|
|
7928
8089
|
return false;
|
|
7929
8090
|
}
|
|
7930
8091
|
if (node.computed) {
|
|
7931
|
-
return node.property.type ===
|
|
8092
|
+
return node.property.type === import_utils52.AST_NODE_TYPES.Literal && isPureReceiver(node.object);
|
|
7932
8093
|
}
|
|
7933
8094
|
return isPureReceiver(node.object);
|
|
7934
8095
|
default:
|
|
@@ -7936,7 +8097,7 @@ function isPureReceiver(node) {
|
|
|
7936
8097
|
}
|
|
7937
8098
|
}
|
|
7938
8099
|
function literalIndex(node) {
|
|
7939
|
-
if (node.type !==
|
|
8100
|
+
if (node.type !== import_utils52.AST_NODE_TYPES.Literal || typeof node.value !== "number") {
|
|
7940
8101
|
return null;
|
|
7941
8102
|
}
|
|
7942
8103
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
@@ -7962,24 +8123,24 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
7962
8123
|
}
|
|
7963
8124
|
const { sourceCode } = context;
|
|
7964
8125
|
function parseAssertion(statement) {
|
|
7965
|
-
if (statement.type !==
|
|
8126
|
+
if (statement.type !== import_utils52.AST_NODE_TYPES.ExpressionStatement) {
|
|
7966
8127
|
return null;
|
|
7967
8128
|
}
|
|
7968
8129
|
const call = statement.expression;
|
|
7969
|
-
if (call.type !==
|
|
8130
|
+
if (call.type !== import_utils52.AST_NODE_TYPES.CallExpression) {
|
|
7970
8131
|
return null;
|
|
7971
8132
|
}
|
|
7972
8133
|
const callee = call.callee;
|
|
7973
|
-
if (callee.type !==
|
|
8134
|
+
if (callee.type !== import_utils52.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils52.AST_NODE_TYPES.Identifier) {
|
|
7974
8135
|
return null;
|
|
7975
8136
|
}
|
|
7976
8137
|
const matcher = callee.property.name;
|
|
7977
8138
|
const expectCall = callee.object;
|
|
7978
|
-
if (expectCall.type !==
|
|
8139
|
+
if (expectCall.type !== import_utils52.AST_NODE_TYPES.CallExpression || expectCall.callee.type !== import_utils52.AST_NODE_TYPES.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
7979
8140
|
return null;
|
|
7980
8141
|
}
|
|
7981
8142
|
const actual = expectCall.arguments[0];
|
|
7982
|
-
if (actual === void 0 || actual.type !==
|
|
8143
|
+
if (actual === void 0 || actual.type !== import_utils52.AST_NODE_TYPES.MemberExpression || actual.optional) {
|
|
7983
8144
|
return null;
|
|
7984
8145
|
}
|
|
7985
8146
|
if (!isPureReceiver(actual.object)) {
|
|
@@ -7993,7 +8154,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
7993
8154
|
}
|
|
7994
8155
|
key = { kind: "index", index };
|
|
7995
8156
|
} else {
|
|
7996
|
-
if (actual.property.type !==
|
|
8157
|
+
if (actual.property.type !== import_utils52.AST_NODE_TYPES.Identifier || COLLECTION_PROPERTIES.has(actual.property.name) || LITERAL_KEY_HAZARDS.has(actual.property.name)) {
|
|
7997
8158
|
return null;
|
|
7998
8159
|
}
|
|
7999
8160
|
key = { kind: "property", name: actual.property.name };
|
|
@@ -8005,7 +8166,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8005
8166
|
return null;
|
|
8006
8167
|
}
|
|
8007
8168
|
const expected = call.arguments[0];
|
|
8008
|
-
if (call.arguments.length !== 1 || expected === void 0 || expected.type ===
|
|
8169
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === import_utils52.AST_NODE_TYPES.SpreadElement) {
|
|
8009
8170
|
return null;
|
|
8010
8171
|
}
|
|
8011
8172
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
@@ -8120,7 +8281,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8120
8281
|
});
|
|
8121
8282
|
|
|
8122
8283
|
// src/rules/prefer-zod-enum.ts
|
|
8123
|
-
var
|
|
8284
|
+
var import_utils53 = require("@typescript-eslint/utils");
|
|
8124
8285
|
var prefer_zod_enum_default = createRule({
|
|
8125
8286
|
name: "prefer-zod-enum",
|
|
8126
8287
|
meta: {
|
|
@@ -8140,20 +8301,20 @@ var prefer_zod_enum_default = createRule({
|
|
|
8140
8301
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
8141
8302
|
function enumValues(node) {
|
|
8142
8303
|
const callee = node.callee;
|
|
8143
|
-
if (callee.type !==
|
|
8304
|
+
if (callee.type !== import_utils53.AST_NODE_TYPES.MemberExpression || callee.computed || callee.object.type !== import_utils53.AST_NODE_TYPES.Identifier || !zodNamespaces.has(callee.object.name) || callee.property.type !== import_utils53.AST_NODE_TYPES.Identifier || callee.property.name !== "union" || node.arguments.length !== 1) {
|
|
8144
8305
|
return null;
|
|
8145
8306
|
}
|
|
8146
8307
|
const argument = node.arguments[0];
|
|
8147
|
-
if (argument === void 0 || argument.type !==
|
|
8308
|
+
if (argument === void 0 || argument.type !== import_utils53.AST_NODE_TYPES.ArrayExpression || argument.elements.length === 0) {
|
|
8148
8309
|
return null;
|
|
8149
8310
|
}
|
|
8150
8311
|
const values = [];
|
|
8151
8312
|
for (const element of argument.elements) {
|
|
8152
|
-
if (element === null || element.type !==
|
|
8313
|
+
if (element === null || element.type !== import_utils53.AST_NODE_TYPES.CallExpression || element.arguments.length !== 1 || element.callee.type !== import_utils53.AST_NODE_TYPES.MemberExpression || element.callee.computed || element.callee.object.type !== import_utils53.AST_NODE_TYPES.Identifier || !zodNamespaces.has(element.callee.object.name) || element.callee.property.type !== import_utils53.AST_NODE_TYPES.Identifier || element.callee.property.name !== "literal") {
|
|
8153
8314
|
return null;
|
|
8154
8315
|
}
|
|
8155
8316
|
const value = element.arguments[0];
|
|
8156
|
-
if (value === void 0 || value.type !==
|
|
8317
|
+
if (value === void 0 || value.type !== import_utils53.AST_NODE_TYPES.Literal || typeof value.value !== "string") {
|
|
8157
8318
|
return null;
|
|
8158
8319
|
}
|
|
8159
8320
|
values.push(value);
|
|
@@ -8162,11 +8323,11 @@ var prefer_zod_enum_default = createRule({
|
|
|
8162
8323
|
}
|
|
8163
8324
|
function buildFix(node, values) {
|
|
8164
8325
|
const argument = node.arguments[0];
|
|
8165
|
-
if (argument === void 0 || argument.type !==
|
|
8326
|
+
if (argument === void 0 || argument.type !== import_utils53.AST_NODE_TYPES.ArrayExpression || sourceCode.getCommentsInside(argument).length > 0) {
|
|
8166
8327
|
return void 0;
|
|
8167
8328
|
}
|
|
8168
8329
|
const callee = node.callee;
|
|
8169
|
-
if (callee.type !==
|
|
8330
|
+
if (callee.type !== import_utils53.AST_NODE_TYPES.MemberExpression || callee.property.type !== import_utils53.AST_NODE_TYPES.Identifier) {
|
|
8170
8331
|
return void 0;
|
|
8171
8332
|
}
|
|
8172
8333
|
return (fixer) => [
|
|
@@ -8183,7 +8344,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
8183
8344
|
return;
|
|
8184
8345
|
}
|
|
8185
8346
|
for (const specifier of node.specifiers) {
|
|
8186
|
-
if (specifier.type ===
|
|
8347
|
+
if (specifier.type === import_utils53.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils53.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils53.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils53.AST_NODE_TYPES.Identifier && specifier.imported.name === "z") {
|
|
8187
8348
|
zodNamespaces.add(specifier.local.name);
|
|
8188
8349
|
}
|
|
8189
8350
|
}
|
|
@@ -8205,7 +8366,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
8205
8366
|
});
|
|
8206
8367
|
|
|
8207
8368
|
// src/rules/prefer-zod-infer.ts
|
|
8208
|
-
var
|
|
8369
|
+
var import_utils54 = require("@typescript-eslint/utils");
|
|
8209
8370
|
var SHAPE_PRESERVING_METHODS = /* @__PURE__ */ new Set([
|
|
8210
8371
|
"describe",
|
|
8211
8372
|
"refine",
|
|
@@ -8242,44 +8403,44 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
8242
8403
|
"Schema"
|
|
8243
8404
|
]);
|
|
8244
8405
|
var LEAF_NODE_TYPES = {
|
|
8245
|
-
string: [
|
|
8246
|
-
email: [
|
|
8247
|
-
url: [
|
|
8248
|
-
uuid: [
|
|
8249
|
-
ulid: [
|
|
8250
|
-
cuid: [
|
|
8251
|
-
cuid2: [
|
|
8252
|
-
nanoid: [
|
|
8253
|
-
iso: [
|
|
8254
|
-
number: [
|
|
8255
|
-
int: [
|
|
8256
|
-
float32: [
|
|
8257
|
-
float64: [
|
|
8258
|
-
boolean: [
|
|
8259
|
-
bigint: [
|
|
8260
|
-
symbol: [
|
|
8261
|
-
any: [
|
|
8262
|
-
unknown: [
|
|
8263
|
-
never: [
|
|
8264
|
-
void: [
|
|
8265
|
-
null: [
|
|
8266
|
-
undefined: [
|
|
8267
|
-
literal: [
|
|
8268
|
-
date: [
|
|
8269
|
-
array: [
|
|
8270
|
-
tuple: [
|
|
8271
|
-
object: [
|
|
8272
|
-
strictObject: [
|
|
8273
|
-
looseObject: [
|
|
8274
|
-
record: [
|
|
8275
|
-
map: [
|
|
8276
|
-
set: [
|
|
8277
|
-
promise: [
|
|
8278
|
-
enum: [
|
|
8279
|
-
nativeEnum: [
|
|
8280
|
-
union: [
|
|
8281
|
-
discriminatedUnion: [
|
|
8282
|
-
intersection: [
|
|
8406
|
+
string: [import_utils54.AST_NODE_TYPES.TSStringKeyword],
|
|
8407
|
+
email: [import_utils54.AST_NODE_TYPES.TSStringKeyword],
|
|
8408
|
+
url: [import_utils54.AST_NODE_TYPES.TSStringKeyword],
|
|
8409
|
+
uuid: [import_utils54.AST_NODE_TYPES.TSStringKeyword],
|
|
8410
|
+
ulid: [import_utils54.AST_NODE_TYPES.TSStringKeyword],
|
|
8411
|
+
cuid: [import_utils54.AST_NODE_TYPES.TSStringKeyword],
|
|
8412
|
+
cuid2: [import_utils54.AST_NODE_TYPES.TSStringKeyword],
|
|
8413
|
+
nanoid: [import_utils54.AST_NODE_TYPES.TSStringKeyword],
|
|
8414
|
+
iso: [import_utils54.AST_NODE_TYPES.TSStringKeyword],
|
|
8415
|
+
number: [import_utils54.AST_NODE_TYPES.TSNumberKeyword],
|
|
8416
|
+
int: [import_utils54.AST_NODE_TYPES.TSNumberKeyword],
|
|
8417
|
+
float32: [import_utils54.AST_NODE_TYPES.TSNumberKeyword],
|
|
8418
|
+
float64: [import_utils54.AST_NODE_TYPES.TSNumberKeyword],
|
|
8419
|
+
boolean: [import_utils54.AST_NODE_TYPES.TSBooleanKeyword],
|
|
8420
|
+
bigint: [import_utils54.AST_NODE_TYPES.TSBigIntKeyword],
|
|
8421
|
+
symbol: [import_utils54.AST_NODE_TYPES.TSSymbolKeyword],
|
|
8422
|
+
any: [import_utils54.AST_NODE_TYPES.TSAnyKeyword],
|
|
8423
|
+
unknown: [import_utils54.AST_NODE_TYPES.TSUnknownKeyword],
|
|
8424
|
+
never: [import_utils54.AST_NODE_TYPES.TSNeverKeyword],
|
|
8425
|
+
void: [import_utils54.AST_NODE_TYPES.TSVoidKeyword],
|
|
8426
|
+
null: [import_utils54.AST_NODE_TYPES.TSNullKeyword],
|
|
8427
|
+
undefined: [import_utils54.AST_NODE_TYPES.TSUndefinedKeyword],
|
|
8428
|
+
literal: [import_utils54.AST_NODE_TYPES.TSLiteralType],
|
|
8429
|
+
date: [import_utils54.AST_NODE_TYPES.TSTypeReference],
|
|
8430
|
+
array: [import_utils54.AST_NODE_TYPES.TSArrayType, import_utils54.AST_NODE_TYPES.TSTypeReference],
|
|
8431
|
+
tuple: [import_utils54.AST_NODE_TYPES.TSTupleType],
|
|
8432
|
+
object: [import_utils54.AST_NODE_TYPES.TSTypeLiteral, import_utils54.AST_NODE_TYPES.TSTypeReference],
|
|
8433
|
+
strictObject: [import_utils54.AST_NODE_TYPES.TSTypeLiteral, import_utils54.AST_NODE_TYPES.TSTypeReference],
|
|
8434
|
+
looseObject: [import_utils54.AST_NODE_TYPES.TSTypeLiteral, import_utils54.AST_NODE_TYPES.TSTypeReference],
|
|
8435
|
+
record: [import_utils54.AST_NODE_TYPES.TSTypeReference, import_utils54.AST_NODE_TYPES.TSTypeLiteral],
|
|
8436
|
+
map: [import_utils54.AST_NODE_TYPES.TSTypeReference],
|
|
8437
|
+
set: [import_utils54.AST_NODE_TYPES.TSTypeReference],
|
|
8438
|
+
promise: [import_utils54.AST_NODE_TYPES.TSTypeReference],
|
|
8439
|
+
enum: [import_utils54.AST_NODE_TYPES.TSUnionType, import_utils54.AST_NODE_TYPES.TSTypeReference, import_utils54.AST_NODE_TYPES.TSLiteralType],
|
|
8440
|
+
nativeEnum: [import_utils54.AST_NODE_TYPES.TSUnionType, import_utils54.AST_NODE_TYPES.TSTypeReference, import_utils54.AST_NODE_TYPES.TSLiteralType],
|
|
8441
|
+
union: [import_utils54.AST_NODE_TYPES.TSUnionType, import_utils54.AST_NODE_TYPES.TSTypeReference],
|
|
8442
|
+
discriminatedUnion: [import_utils54.AST_NODE_TYPES.TSUnionType, import_utils54.AST_NODE_TYPES.TSTypeReference],
|
|
8443
|
+
intersection: [import_utils54.AST_NODE_TYPES.TSIntersectionType, import_utils54.AST_NODE_TYPES.TSTypeReference]
|
|
8283
8444
|
};
|
|
8284
8445
|
function normalizeSchemaName(name) {
|
|
8285
8446
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -8288,20 +8449,20 @@ function normalizeTypeName(name) {
|
|
|
8288
8449
|
return name.replace(/Type$/, "").toLowerCase();
|
|
8289
8450
|
}
|
|
8290
8451
|
function unwrapNullish(annotation) {
|
|
8291
|
-
if (annotation.type !==
|
|
8452
|
+
if (annotation.type !== import_utils54.AST_NODE_TYPES.TSUnionType) {
|
|
8292
8453
|
return {
|
|
8293
8454
|
core: annotation,
|
|
8294
|
-
nullable: annotation.type ===
|
|
8455
|
+
nullable: annotation.type === import_utils54.AST_NODE_TYPES.TSNullKeyword
|
|
8295
8456
|
};
|
|
8296
8457
|
}
|
|
8297
8458
|
const rest = [];
|
|
8298
8459
|
let nullable = false;
|
|
8299
8460
|
for (const member of annotation.types) {
|
|
8300
|
-
if (member.type ===
|
|
8461
|
+
if (member.type === import_utils54.AST_NODE_TYPES.TSNullKeyword) {
|
|
8301
8462
|
nullable = true;
|
|
8302
8463
|
continue;
|
|
8303
8464
|
}
|
|
8304
|
-
if (member.type ===
|
|
8465
|
+
if (member.type === import_utils54.AST_NODE_TYPES.TSUndefinedKeyword) {
|
|
8305
8466
|
continue;
|
|
8306
8467
|
}
|
|
8307
8468
|
rest.push(member);
|
|
@@ -8366,14 +8527,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
8366
8527
|
function zodCallChain(node) {
|
|
8367
8528
|
const chain = [];
|
|
8368
8529
|
let current = node;
|
|
8369
|
-
while (current.type ===
|
|
8530
|
+
while (current.type === import_utils54.AST_NODE_TYPES.CallExpression) {
|
|
8370
8531
|
const callee = current.callee;
|
|
8371
|
-
if (callee.type !==
|
|
8532
|
+
if (callee.type !== import_utils54.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils54.AST_NODE_TYPES.Identifier) {
|
|
8372
8533
|
return null;
|
|
8373
8534
|
}
|
|
8374
8535
|
chain.push(current);
|
|
8375
8536
|
const receiver = callee.object;
|
|
8376
|
-
if (receiver.type ===
|
|
8537
|
+
if (receiver.type === import_utils54.AST_NODE_TYPES.Identifier) {
|
|
8377
8538
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
8378
8539
|
}
|
|
8379
8540
|
current = receiver;
|
|
@@ -8382,19 +8543,19 @@ var prefer_zod_infer_default = createRule({
|
|
|
8382
8543
|
}
|
|
8383
8544
|
function methodName(call) {
|
|
8384
8545
|
const callee = call.callee;
|
|
8385
|
-
return callee.type ===
|
|
8546
|
+
return callee.type === import_utils54.AST_NODE_TYPES.MemberExpression && callee.property.type === import_utils54.AST_NODE_TYPES.Identifier ? callee.property.name : "";
|
|
8386
8547
|
}
|
|
8387
8548
|
function schemaField(node) {
|
|
8388
8549
|
const modifiers = [];
|
|
8389
8550
|
let current = node;
|
|
8390
8551
|
let leaf = null;
|
|
8391
|
-
while (current.type ===
|
|
8552
|
+
while (current.type === import_utils54.AST_NODE_TYPES.CallExpression) {
|
|
8392
8553
|
const callee = current.callee;
|
|
8393
|
-
if (callee.type !==
|
|
8554
|
+
if (callee.type !== import_utils54.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils54.AST_NODE_TYPES.Identifier) {
|
|
8394
8555
|
break;
|
|
8395
8556
|
}
|
|
8396
8557
|
const receiver = callee.object;
|
|
8397
|
-
if (receiver.type ===
|
|
8558
|
+
if (receiver.type === import_utils54.AST_NODE_TYPES.Identifier && zodNamespaces.has(receiver.name)) {
|
|
8398
8559
|
leaf = callee.property.name;
|
|
8399
8560
|
break;
|
|
8400
8561
|
}
|
|
@@ -8425,16 +8586,16 @@ var prefer_zod_infer_default = createRule({
|
|
|
8425
8586
|
return null;
|
|
8426
8587
|
}
|
|
8427
8588
|
const shape = base.arguments[0];
|
|
8428
|
-
if (shape === void 0 || shape.type !==
|
|
8589
|
+
if (shape === void 0 || shape.type !== import_utils54.AST_NODE_TYPES.ObjectExpression) {
|
|
8429
8590
|
return null;
|
|
8430
8591
|
}
|
|
8431
8592
|
const fields = /* @__PURE__ */ new Map();
|
|
8432
8593
|
for (const property of shape.properties) {
|
|
8433
|
-
if (property.type !==
|
|
8594
|
+
if (property.type !== import_utils54.AST_NODE_TYPES.Property || property.computed) {
|
|
8434
8595
|
return null;
|
|
8435
8596
|
}
|
|
8436
8597
|
const { key } = property;
|
|
8437
|
-
const name = key.type ===
|
|
8598
|
+
const name = key.type === import_utils54.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils54.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
8438
8599
|
if (name === null) {
|
|
8439
8600
|
return null;
|
|
8440
8601
|
}
|
|
@@ -8445,11 +8606,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
8445
8606
|
function typeMembers(members) {
|
|
8446
8607
|
const result = /* @__PURE__ */ new Map();
|
|
8447
8608
|
for (const member of members) {
|
|
8448
|
-
if (member.type !==
|
|
8609
|
+
if (member.type !== import_utils54.AST_NODE_TYPES.TSPropertySignature || member.computed) {
|
|
8449
8610
|
return null;
|
|
8450
8611
|
}
|
|
8451
8612
|
const { key } = member;
|
|
8452
|
-
const name = key.type ===
|
|
8613
|
+
const name = key.type === import_utils54.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils54.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
8453
8614
|
if (name === null) {
|
|
8454
8615
|
return null;
|
|
8455
8616
|
}
|
|
@@ -8463,8 +8624,8 @@ var prefer_zod_infer_default = createRule({
|
|
|
8463
8624
|
return result.size === 0 ? null : result;
|
|
8464
8625
|
}
|
|
8465
8626
|
function collectConstrainedNames(node) {
|
|
8466
|
-
if (node.type ===
|
|
8467
|
-
if (node.typeName.type ===
|
|
8627
|
+
if (node.type === import_utils54.AST_NODE_TYPES.TSTypeReference) {
|
|
8628
|
+
if (node.typeName.type === import_utils54.AST_NODE_TYPES.Identifier) {
|
|
8468
8629
|
constrainedTypeNames.add(node.typeName.name);
|
|
8469
8630
|
}
|
|
8470
8631
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -8472,11 +8633,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
8472
8633
|
}
|
|
8473
8634
|
return;
|
|
8474
8635
|
}
|
|
8475
|
-
if (node.type ===
|
|
8636
|
+
if (node.type === import_utils54.AST_NODE_TYPES.TSArrayType) {
|
|
8476
8637
|
collectConstrainedNames(node.elementType);
|
|
8477
8638
|
return;
|
|
8478
8639
|
}
|
|
8479
|
-
if (node.type ===
|
|
8640
|
+
if (node.type === import_utils54.AST_NODE_TYPES.TSUnionType || node.type === import_utils54.AST_NODE_TYPES.TSIntersectionType) {
|
|
8480
8641
|
for (const member of node.types) {
|
|
8481
8642
|
collectConstrainedNames(member);
|
|
8482
8643
|
}
|
|
@@ -8520,13 +8681,13 @@ var prefer_zod_infer_default = createRule({
|
|
|
8520
8681
|
return;
|
|
8521
8682
|
}
|
|
8522
8683
|
for (const specifier of node.specifiers) {
|
|
8523
|
-
if (specifier.type ===
|
|
8684
|
+
if (specifier.type === import_utils54.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils54.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils54.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils54.AST_NODE_TYPES.Identifier && specifier.imported.name === "z") {
|
|
8524
8685
|
zodNamespaces.add(specifier.local.name);
|
|
8525
8686
|
}
|
|
8526
8687
|
}
|
|
8527
8688
|
},
|
|
8528
8689
|
VariableDeclarator(node) {
|
|
8529
|
-
if (node.id.type !==
|
|
8690
|
+
if (node.id.type !== import_utils54.AST_NODE_TYPES.Identifier || node.init == null) {
|
|
8530
8691
|
return;
|
|
8531
8692
|
}
|
|
8532
8693
|
const fields = schemaFields(node.init);
|
|
@@ -8536,14 +8697,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
8536
8697
|
},
|
|
8537
8698
|
/** Guard (f): `XSchema.transform(...)` anywhere in the module. */
|
|
8538
8699
|
"MemberExpression[computed=false]"(node) {
|
|
8539
|
-
if (node.object.type ===
|
|
8700
|
+
if (node.object.type === import_utils54.AST_NODE_TYPES.Identifier && node.property.type === import_utils54.AST_NODE_TYPES.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
8540
8701
|
reshapedSchemaNames.add(node.object.name);
|
|
8541
8702
|
}
|
|
8542
8703
|
},
|
|
8543
8704
|
/** Guard (c): `z.ZodType<T>` and every other type argument it carries. */
|
|
8544
8705
|
TSTypeReference(node) {
|
|
8545
8706
|
const { typeName } = node;
|
|
8546
|
-
const referenced = typeName.type ===
|
|
8707
|
+
const referenced = typeName.type === import_utils54.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils54.AST_NODE_TYPES.TSQualifiedName && typeName.right.type === import_utils54.AST_NODE_TYPES.Identifier ? typeName.right.name : null;
|
|
8547
8708
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
8548
8709
|
return;
|
|
8549
8710
|
}
|
|
@@ -8561,7 +8722,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
8561
8722
|
}
|
|
8562
8723
|
},
|
|
8563
8724
|
TSTypeAliasDeclaration(node) {
|
|
8564
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
8725
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== import_utils54.AST_NODE_TYPES.TSTypeLiteral) {
|
|
8565
8726
|
return;
|
|
8566
8727
|
}
|
|
8567
8728
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -8606,10 +8767,10 @@ var prefer_zod_infer_default = createRule({
|
|
|
8606
8767
|
});
|
|
8607
8768
|
|
|
8608
8769
|
// src/rules/require-assert-never.ts
|
|
8609
|
-
var
|
|
8770
|
+
var import_utils55 = require("@typescript-eslint/utils");
|
|
8610
8771
|
var isRuntimeHandlingStatement = (statement) => {
|
|
8611
|
-
if (statement.type ===
|
|
8612
|
-
if (statement.type ===
|
|
8772
|
+
if (statement.type === import_utils55.AST_NODE_TYPES.EmptyStatement) return false;
|
|
8773
|
+
if (statement.type === import_utils55.AST_NODE_TYPES.BlockStatement) {
|
|
8613
8774
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
8614
8775
|
}
|
|
8615
8776
|
return true;
|
|
@@ -8625,7 +8786,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
8625
8786
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
8626
8787
|
}
|
|
8627
8788
|
const only = defaultCase.consequent[0];
|
|
8628
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
8789
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === import_utils55.AST_NODE_TYPES.BlockStatement && only.body.length === 0) {
|
|
8629
8790
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
8630
8791
|
}
|
|
8631
8792
|
return false;
|
|
@@ -8665,7 +8826,7 @@ var require_assert_never_default = createRule({
|
|
|
8665
8826
|
});
|
|
8666
8827
|
|
|
8667
8828
|
// src/rules/require-fetch-timeout.ts
|
|
8668
|
-
var
|
|
8829
|
+
var import_utils56 = require("@typescript-eslint/utils");
|
|
8669
8830
|
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set([
|
|
8670
8831
|
"globalThis",
|
|
8671
8832
|
"window",
|
|
@@ -8681,14 +8842,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
8681
8842
|
return false;
|
|
8682
8843
|
}
|
|
8683
8844
|
function initProvablyLacksSignal(init) {
|
|
8684
|
-
if (init.type !==
|
|
8845
|
+
if (init.type !== import_utils56.AST_NODE_TYPES.ObjectExpression) {
|
|
8685
8846
|
return false;
|
|
8686
8847
|
}
|
|
8687
8848
|
for (const prop of init.properties) {
|
|
8688
|
-
if (prop.type ===
|
|
8849
|
+
if (prop.type === import_utils56.AST_NODE_TYPES.SpreadElement) {
|
|
8689
8850
|
return false;
|
|
8690
8851
|
}
|
|
8691
|
-
if (prop.key.type ===
|
|
8852
|
+
if (prop.key.type === import_utils56.AST_NODE_TYPES.Identifier && prop.key.name === "signal" || prop.key.type === import_utils56.AST_NODE_TYPES.Literal && prop.key.value === "signal") {
|
|
8692
8853
|
return false;
|
|
8693
8854
|
}
|
|
8694
8855
|
if (prop.computed) {
|
|
@@ -8698,7 +8859,7 @@ function initProvablyLacksSignal(init) {
|
|
|
8698
8859
|
return true;
|
|
8699
8860
|
}
|
|
8700
8861
|
function isStringish(node) {
|
|
8701
|
-
return node.type ===
|
|
8862
|
+
return node.type === import_utils56.AST_NODE_TYPES.Literal && typeof node.value === "string" || node.type === import_utils56.AST_NODE_TYPES.TemplateLiteral;
|
|
8702
8863
|
}
|
|
8703
8864
|
var require_fetch_timeout_default = createRule({
|
|
8704
8865
|
name: "require-fetch-timeout",
|
|
@@ -8735,14 +8896,14 @@ var require_fetch_timeout_default = createRule({
|
|
|
8735
8896
|
}
|
|
8736
8897
|
function resolvesToGlobal(identifier) {
|
|
8737
8898
|
const scope = context.sourceCode.getScope(identifier);
|
|
8738
|
-
const variable =
|
|
8899
|
+
const variable = import_utils56.ASTUtils.findVariable(scope, identifier.name);
|
|
8739
8900
|
return variable === null || variable.defs.length === 0;
|
|
8740
8901
|
}
|
|
8741
8902
|
function isGlobalFetchCall2(callee) {
|
|
8742
|
-
if (callee.type ===
|
|
8903
|
+
if (callee.type === import_utils56.AST_NODE_TYPES.Identifier) {
|
|
8743
8904
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
8744
8905
|
}
|
|
8745
|
-
return callee.type ===
|
|
8906
|
+
return callee.type === import_utils56.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils56.AST_NODE_TYPES.Identifier && callee.property.name === "fetch" && callee.object.type === import_utils56.AST_NODE_TYPES.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
8746
8907
|
}
|
|
8747
8908
|
return {
|
|
8748
8909
|
CallExpression(node) {
|
|
@@ -8762,7 +8923,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
8762
8923
|
});
|
|
8763
8924
|
|
|
8764
8925
|
// src/rules/require-interface-for-injected-service.ts
|
|
8765
|
-
var
|
|
8926
|
+
var import_utils57 = require("@typescript-eslint/utils");
|
|
8766
8927
|
var CONFIGISH_TYPE_RE = /(?:Options|Opts|Config|Configuration|Settings|Params|Props|Args|Env|Environment|Callbacks|Flags)$/;
|
|
8767
8928
|
var CONFIGISH_NAME_RE = /^(?:options|opts|config|configuration|settings|params|props|args|env|environment|callbacks|flags|logger|log|clock)$/i;
|
|
8768
8929
|
var HTTP_TRANSPORT_TYPE_RE = /^(?:KyInstance|AxiosInstance|Session)$/;
|
|
@@ -8770,20 +8931,20 @@ var BUILTIN_CONTAINER_TYPE_RE = /^(?:Record|Map|WeakMap|Set|WeakSet|Array|Readon
|
|
|
8770
8931
|
var TRANSPORT_WRAPPER_NAME_RE = /Client$/;
|
|
8771
8932
|
var ROUTER_FACTORY_NAME = "Router";
|
|
8772
8933
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
8773
|
-
var isExportedClass = (node) => node.parent.type ===
|
|
8774
|
-
var qualifiedName = (name) => name.type ===
|
|
8934
|
+
var isExportedClass = (node) => node.parent.type === import_utils57.AST_NODE_TYPES.ExportNamedDeclaration || node.parent.type === import_utils57.AST_NODE_TYPES.ExportDefaultDeclaration;
|
|
8935
|
+
var qualifiedName = (name) => name.type === import_utils57.AST_NODE_TYPES.Identifier ? name.name : name.type === import_utils57.AST_NODE_TYPES.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
8775
8936
|
var readTypeReference = (annotation) => {
|
|
8776
|
-
if (annotation === void 0 || annotation.type !==
|
|
8937
|
+
if (annotation === void 0 || annotation.type !== import_utils57.AST_NODE_TYPES.TSTypeReference) return null;
|
|
8777
8938
|
const { typeName } = annotation;
|
|
8778
|
-
const rightmost = typeName.type ===
|
|
8939
|
+
const rightmost = typeName.type === import_utils57.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils57.AST_NODE_TYPES.TSQualifiedName ? typeName.right.name : null;
|
|
8779
8940
|
if (rightmost === null) return null;
|
|
8780
8941
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
8781
8942
|
};
|
|
8782
8943
|
var namedParameterCollaborator = (annotated) => {
|
|
8783
8944
|
let target = annotated;
|
|
8784
|
-
if (target.type ===
|
|
8785
|
-
if (target.type ===
|
|
8786
|
-
if (target.type !==
|
|
8945
|
+
if (target.type === import_utils57.AST_NODE_TYPES.TSParameterProperty) target = target.parameter;
|
|
8946
|
+
if (target.type === import_utils57.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
8947
|
+
if (target.type !== import_utils57.AST_NODE_TYPES.Identifier) return null;
|
|
8787
8948
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
8788
8949
|
if (reference === null) return null;
|
|
8789
8950
|
return { name: target.name, ...reference };
|
|
@@ -8791,8 +8952,8 @@ var namedParameterCollaborator = (annotated) => {
|
|
|
8791
8952
|
var propertySignatureTypes = (members) => {
|
|
8792
8953
|
const types = /* @__PURE__ */ new Map();
|
|
8793
8954
|
for (const member of members) {
|
|
8794
|
-
if (member.type !==
|
|
8795
|
-
if (member.computed || member.key.type !==
|
|
8955
|
+
if (member.type !== import_utils57.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
8956
|
+
if (member.computed || member.key.type !== import_utils57.AST_NODE_TYPES.Identifier) continue;
|
|
8796
8957
|
const reference = readTypeReference(member.typeAnnotation?.typeAnnotation);
|
|
8797
8958
|
if (reference === null) continue;
|
|
8798
8959
|
types.set(member.key.name, reference);
|
|
@@ -8803,18 +8964,18 @@ var fileTypeIndex = (program) => {
|
|
|
8803
8964
|
const objects = /* @__PURE__ */ new Map();
|
|
8804
8965
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
8805
8966
|
for (const statement of program.body) {
|
|
8806
|
-
const declaration = statement.type ===
|
|
8807
|
-
if (declaration?.type ===
|
|
8967
|
+
const declaration = statement.type === import_utils57.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
8968
|
+
if (declaration?.type === import_utils57.AST_NODE_TYPES.TSInterfaceDeclaration) {
|
|
8808
8969
|
objects.set(declaration.id.name, propertySignatureTypes(declaration.body.body));
|
|
8809
8970
|
continue;
|
|
8810
8971
|
}
|
|
8811
|
-
if (declaration?.type !==
|
|
8972
|
+
if (declaration?.type !== import_utils57.AST_NODE_TYPES.TSTypeAliasDeclaration) continue;
|
|
8812
8973
|
const aliased = declaration.typeAnnotation;
|
|
8813
|
-
if (aliased.type ===
|
|
8974
|
+
if (aliased.type === import_utils57.AST_NODE_TYPES.TSFunctionType || aliased.type === import_utils57.AST_NODE_TYPES.TSConstructorType) {
|
|
8814
8975
|
functionAliases.add(declaration.id.name);
|
|
8815
8976
|
continue;
|
|
8816
8977
|
}
|
|
8817
|
-
const literals = aliased.type ===
|
|
8978
|
+
const literals = aliased.type === import_utils57.AST_NODE_TYPES.TSTypeLiteral ? [aliased] : aliased.type === import_utils57.AST_NODE_TYPES.TSIntersectionType ? aliased.types.filter((part) => part.type === import_utils57.AST_NODE_TYPES.TSTypeLiteral) : [];
|
|
8818
8979
|
if (literals.length === 0) continue;
|
|
8819
8980
|
const merged = /* @__PURE__ */ new Map();
|
|
8820
8981
|
for (const literal of literals) {
|
|
@@ -8827,10 +8988,10 @@ var fileTypeIndex = (program) => {
|
|
|
8827
8988
|
return { objects, functionAliases };
|
|
8828
8989
|
};
|
|
8829
8990
|
var bagMemberTypes = (annotation, declared) => {
|
|
8830
|
-
if (annotation.type ===
|
|
8991
|
+
if (annotation.type === import_utils57.AST_NODE_TYPES.TSTypeLiteral) {
|
|
8831
8992
|
return propertySignatureTypes(annotation.members);
|
|
8832
8993
|
}
|
|
8833
|
-
if (annotation.type !==
|
|
8994
|
+
if (annotation.type !== import_utils57.AST_NODE_TYPES.TSTypeReference || annotation.typeName.type !== import_utils57.AST_NODE_TYPES.Identifier) {
|
|
8834
8995
|
return null;
|
|
8835
8996
|
}
|
|
8836
8997
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
@@ -8842,11 +9003,11 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
8842
9003
|
if (members === null) return [];
|
|
8843
9004
|
const collaborators = [];
|
|
8844
9005
|
for (const property of pattern.properties) {
|
|
8845
|
-
if (property.type !==
|
|
8846
|
-
if (property.key.type !==
|
|
9006
|
+
if (property.type !== import_utils57.AST_NODE_TYPES.Property || property.computed) continue;
|
|
9007
|
+
if (property.key.type !== import_utils57.AST_NODE_TYPES.Identifier) continue;
|
|
8847
9008
|
const key = property.key.name;
|
|
8848
|
-
const bound = property.value.type ===
|
|
8849
|
-
if (bound.type !==
|
|
9009
|
+
const bound = property.value.type === import_utils57.AST_NODE_TYPES.AssignmentPattern ? property.value.left : property.value;
|
|
9010
|
+
if (bound.type !== import_utils57.AST_NODE_TYPES.Identifier) continue;
|
|
8850
9011
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
8851
9012
|
const reference = members.get(key);
|
|
8852
9013
|
if (reference === void 0) continue;
|
|
@@ -8856,8 +9017,8 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
8856
9017
|
};
|
|
8857
9018
|
var parameterCollaborators = (parameter, declared) => {
|
|
8858
9019
|
let target = parameter;
|
|
8859
|
-
if (target.type ===
|
|
8860
|
-
if (target.type ===
|
|
9020
|
+
if (target.type === import_utils57.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
9021
|
+
if (target.type === import_utils57.AST_NODE_TYPES.ObjectPattern) {
|
|
8861
9022
|
return objectPatternCollaborators(target, declared);
|
|
8862
9023
|
}
|
|
8863
9024
|
const named2 = namedParameterCollaborator(parameter);
|
|
@@ -8876,17 +9037,17 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
8876
9037
|
let constructedFields = 0;
|
|
8877
9038
|
if (body !== null && body !== void 0) {
|
|
8878
9039
|
for (const statement of body.body) {
|
|
8879
|
-
if (statement.type !==
|
|
9040
|
+
if (statement.type !== import_utils57.AST_NODE_TYPES.ExpressionStatement) continue;
|
|
8880
9041
|
const expression = statement.expression;
|
|
8881
|
-
if (expression.type !==
|
|
9042
|
+
if (expression.type !== import_utils57.AST_NODE_TYPES.AssignmentExpression || expression.operator !== "=" || expression.left.type !== import_utils57.AST_NODE_TYPES.MemberExpression || expression.left.object.type !== import_utils57.AST_NODE_TYPES.ThisExpression) {
|
|
8882
9043
|
continue;
|
|
8883
9044
|
}
|
|
8884
9045
|
const source = expression.right;
|
|
8885
|
-
if (source.type ===
|
|
9046
|
+
if (source.type === import_utils57.AST_NODE_TYPES.NewExpression) {
|
|
8886
9047
|
constructedFields += 1;
|
|
8887
|
-
} else if (source.type ===
|
|
9048
|
+
} else if (source.type === import_utils57.AST_NODE_TYPES.Identifier) {
|
|
8888
9049
|
storedFrom.add(source.name);
|
|
8889
|
-
} else if (source.type ===
|
|
9050
|
+
} else if (source.type === import_utils57.AST_NODE_TYPES.MemberExpression && source.object.type === import_utils57.AST_NODE_TYPES.Identifier) {
|
|
8890
9051
|
storedFrom.add(source.object.name);
|
|
8891
9052
|
}
|
|
8892
9053
|
}
|
|
@@ -8894,7 +9055,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
8894
9055
|
const collaborators = [];
|
|
8895
9056
|
for (const parameter of ctor.value.params) {
|
|
8896
9057
|
for (const reference of parameterCollaborators(parameter, declared)) {
|
|
8897
|
-
const stored = parameter.type ===
|
|
9058
|
+
const stored = parameter.type === import_utils57.AST_NODE_TYPES.TSParameterProperty || storedFrom.has(reference.name);
|
|
8898
9059
|
if (!stored) continue;
|
|
8899
9060
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
8900
9061
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -8928,19 +9089,19 @@ var subtreeHas = (root, found) => {
|
|
|
8928
9089
|
return hit;
|
|
8929
9090
|
};
|
|
8930
9091
|
var isFrameworkWiring = (body) => subtreeHas(body, (node) => {
|
|
8931
|
-
if (node.type ===
|
|
9092
|
+
if (node.type === import_utils57.AST_NODE_TYPES.CallExpression) {
|
|
8932
9093
|
const { callee } = node;
|
|
8933
|
-
if (callee.type ===
|
|
8934
|
-
return callee.type ===
|
|
9094
|
+
if (callee.type === import_utils57.AST_NODE_TYPES.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
9095
|
+
return callee.type === import_utils57.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils57.AST_NODE_TYPES.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
8935
9096
|
}
|
|
8936
|
-
return node.type ===
|
|
9097
|
+
return node.type === import_utils57.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils57.AST_NODE_TYPES.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
8937
9098
|
});
|
|
8938
9099
|
var stem2 = (name) => name.replace(/^I(?=[A-Z])/, "").replace(/Impl$/, "");
|
|
8939
9100
|
var fileInterfaceNames = (program) => {
|
|
8940
9101
|
const names = [];
|
|
8941
9102
|
for (const statement of program.body) {
|
|
8942
|
-
const declaration = statement.type ===
|
|
8943
|
-
if (declaration?.type ===
|
|
9103
|
+
const declaration = statement.type === import_utils57.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
9104
|
+
if (declaration?.type === import_utils57.AST_NODE_TYPES.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
8944
9105
|
}
|
|
8945
9106
|
return names;
|
|
8946
9107
|
};
|
|
@@ -8958,11 +9119,11 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
8958
9119
|
var publicMethodNames = (body) => {
|
|
8959
9120
|
const names = [];
|
|
8960
9121
|
for (const member of body.body) {
|
|
8961
|
-
if (member.type !==
|
|
9122
|
+
if (member.type !== import_utils57.AST_NODE_TYPES.MethodDefinition) continue;
|
|
8962
9123
|
if (member.kind !== "method" || member.static) continue;
|
|
8963
9124
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
8964
|
-
if (member.key.type ===
|
|
8965
|
-
if (member.key.type ===
|
|
9125
|
+
if (member.key.type === import_utils57.AST_NODE_TYPES.PrivateIdentifier) continue;
|
|
9126
|
+
if (member.key.type === import_utils57.AST_NODE_TYPES.Identifier) names.push(member.key.name);
|
|
8966
9127
|
else names.push("\u2026");
|
|
8967
9128
|
}
|
|
8968
9129
|
return names;
|
|
@@ -8995,7 +9156,7 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
8995
9156
|
if (node.implements.length > 0) return;
|
|
8996
9157
|
if (node.decorators.length > 0) return;
|
|
8997
9158
|
const ctor = node.body.body.find(
|
|
8998
|
-
(member) => member.type ===
|
|
9159
|
+
(member) => member.type === import_utils57.AST_NODE_TYPES.MethodDefinition && member.kind === "constructor"
|
|
8999
9160
|
);
|
|
9000
9161
|
if (ctor === void 0) return;
|
|
9001
9162
|
const { collaborators, constructedFields } = readConstructor(
|
|
@@ -9024,18 +9185,18 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
9024
9185
|
});
|
|
9025
9186
|
|
|
9026
9187
|
// src/rules/require-zod-form-validation.ts
|
|
9027
|
-
var
|
|
9188
|
+
var import_utils58 = require("@typescript-eslint/utils");
|
|
9028
9189
|
var looksLikeZodSchema = (node) => {
|
|
9029
9190
|
let current = node;
|
|
9030
9191
|
while (true) {
|
|
9031
|
-
if (current.type ===
|
|
9192
|
+
if (current.type === import_utils58.AST_NODE_TYPES.Identifier) {
|
|
9032
9193
|
return current.name === "z" || ZOD_SCHEMA_NAME_RE.test(current.name);
|
|
9033
9194
|
}
|
|
9034
|
-
if (current.type ===
|
|
9195
|
+
if (current.type === import_utils58.AST_NODE_TYPES.CallExpression) {
|
|
9035
9196
|
current = current.callee;
|
|
9036
9197
|
continue;
|
|
9037
9198
|
}
|
|
9038
|
-
if (current.type ===
|
|
9199
|
+
if (current.type === import_utils58.AST_NODE_TYPES.MemberExpression) {
|
|
9039
9200
|
current = current.object;
|
|
9040
9201
|
continue;
|
|
9041
9202
|
}
|
|
@@ -9043,23 +9204,23 @@ var looksLikeZodSchema = (node) => {
|
|
|
9043
9204
|
}
|
|
9044
9205
|
};
|
|
9045
9206
|
var isZodParseCall = (node) => {
|
|
9046
|
-
if (node.type !==
|
|
9207
|
+
if (node.type !== import_utils58.AST_NODE_TYPES.CallExpression) return false;
|
|
9047
9208
|
const callee = node.callee;
|
|
9048
|
-
if (callee.type !==
|
|
9209
|
+
if (callee.type !== import_utils58.AST_NODE_TYPES.MemberExpression) return false;
|
|
9049
9210
|
if (callee.computed) return false;
|
|
9050
|
-
if (callee.property.type !==
|
|
9211
|
+
if (callee.property.type !== import_utils58.AST_NODE_TYPES.Identifier) return false;
|
|
9051
9212
|
const method = callee.property.name;
|
|
9052
9213
|
if (method !== "parse" && method !== "safeParse") return false;
|
|
9053
9214
|
return looksLikeZodSchema(callee.object);
|
|
9054
9215
|
};
|
|
9055
9216
|
var isFormDataMethodCall = (node) => {
|
|
9056
9217
|
let current = node;
|
|
9057
|
-
if (current.type ===
|
|
9218
|
+
if (current.type === import_utils58.AST_NODE_TYPES.AwaitExpression) {
|
|
9058
9219
|
current = current.argument;
|
|
9059
9220
|
}
|
|
9060
|
-
if (current.type !==
|
|
9221
|
+
if (current.type !== import_utils58.AST_NODE_TYPES.CallExpression) return false;
|
|
9061
9222
|
const callee = current.callee;
|
|
9062
|
-
return callee.type ===
|
|
9223
|
+
return callee.type === import_utils58.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils58.AST_NODE_TYPES.Identifier && callee.property.name === "formData";
|
|
9063
9224
|
};
|
|
9064
9225
|
var require_zod_form_validation_default = createRule({
|
|
9065
9226
|
name: "require-zod-form-validation",
|
|
@@ -9079,14 +9240,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
9079
9240
|
return {};
|
|
9080
9241
|
}
|
|
9081
9242
|
const isFormSourceIdentifier = (node) => {
|
|
9082
|
-
if (node.type !==
|
|
9243
|
+
if (node.type !== import_utils58.AST_NODE_TYPES.Identifier) return false;
|
|
9083
9244
|
if (/formdata/i.test(node.name)) return true;
|
|
9084
9245
|
let scope = context.sourceCode.getScope(node);
|
|
9085
9246
|
while (scope !== null) {
|
|
9086
9247
|
const variable = scope.set.get(node.name);
|
|
9087
9248
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
9088
9249
|
const def = variable.defs[0];
|
|
9089
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
9250
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === import_utils58.AST_NODE_TYPES.VariableDeclarator && def.node.init !== null) {
|
|
9090
9251
|
return isFormDataMethodCall(def.node.init);
|
|
9091
9252
|
}
|
|
9092
9253
|
return false;
|
|
@@ -9097,8 +9258,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
9097
9258
|
};
|
|
9098
9259
|
const isFormDataGetCall = (node) => {
|
|
9099
9260
|
const callee = node.callee;
|
|
9100
|
-
if (callee.type !==
|
|
9101
|
-
if (callee.property.type !==
|
|
9261
|
+
if (callee.type !== import_utils58.AST_NODE_TYPES.MemberExpression) return false;
|
|
9262
|
+
if (callee.property.type !== import_utils58.AST_NODE_TYPES.Identifier || callee.property.name !== "get") {
|
|
9102
9263
|
return false;
|
|
9103
9264
|
}
|
|
9104
9265
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -9113,11 +9274,11 @@ var require_zod_form_validation_default = createRule({
|
|
|
9113
9274
|
};
|
|
9114
9275
|
const isInstanceofNarrowing = (node) => {
|
|
9115
9276
|
const parent = node.parent;
|
|
9116
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
9277
|
+
return parent !== null && parent !== void 0 && parent.type === import_utils58.AST_NODE_TYPES.BinaryExpression && parent.operator === "instanceof" && parent.left === node;
|
|
9117
9278
|
};
|
|
9118
9279
|
const boundDeclarator = (node) => {
|
|
9119
9280
|
const parent = node.parent;
|
|
9120
|
-
if (parent.type ===
|
|
9281
|
+
if (parent.type === import_utils58.AST_NODE_TYPES.VariableDeclarator && parent.init === node && parent.id.type === import_utils58.AST_NODE_TYPES.Identifier) {
|
|
9121
9282
|
return parent;
|
|
9122
9283
|
}
|
|
9123
9284
|
return null;
|
|
@@ -9145,7 +9306,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
9145
9306
|
});
|
|
9146
9307
|
|
|
9147
9308
|
// src/rules/store-insert-requires-on-conflict.ts
|
|
9148
|
-
var
|
|
9309
|
+
var import_utils59 = require("@typescript-eslint/utils");
|
|
9149
9310
|
var INSERT_WRITE = /\bINSERT\s+(?:OR\s+\w+\s+)?INTO\s+[\w."'`?$:@-]+\s*(?:\([^)]*\)\s*)?(?:VALUES|SELECT|DEFAULT\s+VALUES)\b/i;
|
|
9150
9311
|
var CONFLICT_HANDLED = /\bON\s+CONFLICT\b|\bON\s+DUPLICATE\s+KEY\b|\bINSERT\s+OR\s+(?:IGNORE|REPLACE)\b/i;
|
|
9151
9312
|
var INSERT_GATE = /insert/i;
|
|
@@ -9176,7 +9337,7 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
9176
9337
|
});
|
|
9177
9338
|
|
|
9178
9339
|
// src/rules/zod-naming-convention.ts
|
|
9179
|
-
var
|
|
9340
|
+
var import_utils60 = require("@typescript-eslint/utils");
|
|
9180
9341
|
var CONVENTIONS = {
|
|
9181
9342
|
prefix: { test: ZOD_PREFIX_RE, messageId: "zPrefix" },
|
|
9182
9343
|
suffix: { test: ZOD_SUFFIX_RE, messageId: "schemaSuffix" },
|
|
@@ -9201,15 +9362,15 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
9201
9362
|
"registry",
|
|
9202
9363
|
"implement"
|
|
9203
9364
|
]);
|
|
9204
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
9365
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === import_utils60.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
9205
9366
|
var calleeChainStartsWithZ = (node) => {
|
|
9206
9367
|
let current = node;
|
|
9207
|
-
while (current.type ===
|
|
9368
|
+
while (current.type === import_utils60.AST_NODE_TYPES.MemberExpression) {
|
|
9208
9369
|
const receiver = current.object;
|
|
9209
|
-
if (receiver.type ===
|
|
9370
|
+
if (receiver.type === import_utils60.AST_NODE_TYPES.Identifier && receiver.name === "z") {
|
|
9210
9371
|
return true;
|
|
9211
9372
|
}
|
|
9212
|
-
if (receiver.type ===
|
|
9373
|
+
if (receiver.type === import_utils60.AST_NODE_TYPES.CallExpression) {
|
|
9213
9374
|
current = receiver.callee;
|
|
9214
9375
|
continue;
|
|
9215
9376
|
}
|
|
@@ -9254,13 +9415,13 @@ var zod_naming_convention_default = createRule({
|
|
|
9254
9415
|
VariableDeclarator(node) {
|
|
9255
9416
|
const init = node.init;
|
|
9256
9417
|
if (init === null || init === void 0) return;
|
|
9257
|
-
if (init.type !==
|
|
9418
|
+
if (init.type !== import_utils60.AST_NODE_TYPES.CallExpression) return;
|
|
9258
9419
|
const callee = init.callee;
|
|
9259
|
-
if (callee.type !==
|
|
9420
|
+
if (callee.type !== import_utils60.AST_NODE_TYPES.MemberExpression) return;
|
|
9260
9421
|
if (!calleeChainStartsWithZ(callee)) return;
|
|
9261
9422
|
const terminal = terminalMethodName(callee);
|
|
9262
9423
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
9263
|
-
if (node.id.type !==
|
|
9424
|
+
if (node.id.type !== import_utils60.AST_NODE_TYPES.Identifier) return;
|
|
9264
9425
|
if (test.test(node.id.name)) return;
|
|
9265
9426
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
9266
9427
|
context.report({
|
|
@@ -9360,6 +9521,7 @@ var rules = {
|
|
|
9360
9521
|
"no-tautological-expect": no_tautological_expect_default,
|
|
9361
9522
|
"no-trailing-value-narration": no_trailing_value_narration_default,
|
|
9362
9523
|
"no-declaration-comment-wall": no_declaration_comment_wall_default,
|
|
9524
|
+
"no-union-in-comment": no_union_in_comment_default,
|
|
9363
9525
|
"no-type-member-comment-wall": no_type_member_comment_wall_default,
|
|
9364
9526
|
"no-unnecessary-use-client": no_unnecessary_use_client_default,
|
|
9365
9527
|
"no-unsafe-mock-casting": no_unsafe_mock_casting_default,
|
|
@@ -9385,7 +9547,7 @@ var rules = {
|
|
|
9385
9547
|
};
|
|
9386
9548
|
var meta = {
|
|
9387
9549
|
name: "@sarj/eslint-plugin",
|
|
9388
|
-
version: "9.
|
|
9550
|
+
version: "9.4.0"
|
|
9389
9551
|
};
|
|
9390
9552
|
var recommendedRules = {
|
|
9391
9553
|
"@sarj/enforce-file-structure": "warn",
|
|
@@ -9414,6 +9576,7 @@ var recommendedRules = {
|
|
|
9414
9576
|
"@sarj/no-tautological-expect": "warn",
|
|
9415
9577
|
"@sarj/no-trailing-value-narration": "warn",
|
|
9416
9578
|
"@sarj/no-declaration-comment-wall": "warn",
|
|
9579
|
+
"@sarj/no-union-in-comment": "warn",
|
|
9417
9580
|
"@sarj/no-type-member-comment-wall": "warn",
|
|
9418
9581
|
"@sarj/no-unnecessary-use-client": "warn",
|
|
9419
9582
|
"@sarj/no-unsafe-mock-casting": "warn",
|
|
@@ -9468,6 +9631,7 @@ var strictRules = {
|
|
|
9468
9631
|
"@sarj/no-tautological-expect": "error",
|
|
9469
9632
|
"@sarj/no-trailing-value-narration": "error",
|
|
9470
9633
|
"@sarj/no-declaration-comment-wall": "error",
|
|
9634
|
+
"@sarj/no-union-in-comment": "error",
|
|
9471
9635
|
"@sarj/no-type-member-comment-wall": "error",
|
|
9472
9636
|
"@sarj/no-unnecessary-use-client": "error",
|
|
9473
9637
|
"@sarj/no-unsafe-mock-casting": "error",
|