@sarj/eslint-plugin 9.5.0 → 9.7.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 +8 -11
- package/dist/index.cjs +1064 -675
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -16
- package/dist/index.d.ts +29 -16
- package/dist/index.js +1053 -664
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -4,10 +4,10 @@ import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
|
4
4
|
// src/rules/_docs.ts
|
|
5
5
|
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
6
6
|
var REPO_BLOB = "https://github.com/sarj-ai/standards/blob/main";
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var createRule = ESLintUtils.RuleCreator(
|
|
7
|
+
var TESTS_DIR = "packages/typescript/tests/rules";
|
|
8
|
+
var examplesPath = (name) => `${TESTS_DIR}/${name}.test.ts`;
|
|
9
|
+
var examplesUrl = (name) => `${REPO_BLOB}/${examplesPath(name)}`;
|
|
10
|
+
var createRule = ESLintUtils.RuleCreator(examplesUrl);
|
|
11
11
|
|
|
12
12
|
// src/rules/_paths.ts
|
|
13
13
|
var SCRIPT_FILE_RE = /([\\/]scripts[\\/])|(\.mjs$)/;
|
|
@@ -92,8 +92,8 @@ var enforce_file_structure_default = createRule({
|
|
|
92
92
|
}
|
|
93
93
|
return {
|
|
94
94
|
Program(node) {
|
|
95
|
-
const
|
|
96
|
-
const misplacedUseServer =
|
|
95
|
+
const body2 = node.body;
|
|
96
|
+
const misplacedUseServer = body2.find(
|
|
97
97
|
(statement, index) => index > 0 && isUseServerDirective(statement)
|
|
98
98
|
);
|
|
99
99
|
if (misplacedUseServer !== void 0) {
|
|
@@ -104,7 +104,7 @@ var enforce_file_structure_default = createRule({
|
|
|
104
104
|
}
|
|
105
105
|
let seenBody = false;
|
|
106
106
|
let inMisplacedRun = false;
|
|
107
|
-
for (const statement of
|
|
107
|
+
for (const statement of body2) {
|
|
108
108
|
if (isStringDirective(statement)) continue;
|
|
109
109
|
switch (classifyStatement(statement)) {
|
|
110
110
|
case "reexport":
|
|
@@ -325,11 +325,11 @@ var PROTECTED_SIGNALS = [
|
|
|
325
325
|
SECURITY_RE,
|
|
326
326
|
VENDOR_RE
|
|
327
327
|
];
|
|
328
|
-
function isProtected(
|
|
329
|
-
return PROTECTED_SIGNALS.some((signal) => signal.test(
|
|
328
|
+
function isProtected(body2) {
|
|
329
|
+
return PROTECTED_SIGNALS.some((signal) => signal.test(body2));
|
|
330
330
|
}
|
|
331
|
-
function hasExternalReference(
|
|
332
|
-
return REF_RE.test(
|
|
331
|
+
function hasExternalReference(body2) {
|
|
332
|
+
return REF_RE.test(body2);
|
|
333
333
|
}
|
|
334
334
|
var STOPWORDS = new Set(
|
|
335
335
|
`a an the this that these those it its their his her our your my
|
|
@@ -477,9 +477,9 @@ function restatableStatementBelow(comment, sourceCode) {
|
|
|
477
477
|
}
|
|
478
478
|
return null;
|
|
479
479
|
}
|
|
480
|
-
function restatesStatementHead(
|
|
480
|
+
function restatesStatementHead(body2, statement) {
|
|
481
481
|
if (statement === null) return false;
|
|
482
|
-
const words =
|
|
482
|
+
const words = body2.match(/[A-Za-z][\w$]*/g) ?? [];
|
|
483
483
|
const opener = words[0];
|
|
484
484
|
if (opener === void 0 || words.length > NARRATION_MAX_WORDS) return false;
|
|
485
485
|
if (!NARRATION_VERB_RE.test(opener)) return false;
|
|
@@ -492,6 +492,14 @@ function restatesStatementHead(body, statement) {
|
|
|
492
492
|
|
|
493
493
|
// src/rules/no-comment-cruft.ts
|
|
494
494
|
var LEADING_PREAMBLE_MIN = 4;
|
|
495
|
+
var WALL_MIN_STATEMENTS = 4;
|
|
496
|
+
var WALL_MIN_COMMENTS = 3;
|
|
497
|
+
var WALL_MIN_COMMENTED_RATIO = 0.6;
|
|
498
|
+
var WALL_MIN_WEAK_RATIO = 0.75;
|
|
499
|
+
var WALL_MAX_WORDS = 18;
|
|
500
|
+
var WALL_MAX_NOVEL_WORDS = 2;
|
|
501
|
+
var WALL_NARRATION_RE = /^(?:first(?:ly)?|second(?:ly)?|third(?:ly)?|then|next|now|finally|lastly|add|append|assign|await|build|calculate|call|check|clear|close|compute|convert|copy|count|create|declare|define|delete|extract|fetch|filter|find|format|generate|get|handle|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|d|ed|ing)?\b/i;
|
|
502
|
+
var WALL_STEP_PREFIX_RE = /^(?:\d+[.)]|(?:phase|step)\s+\d+\s*:)\s*/i;
|
|
495
503
|
var STEP_NARRATION_RE = /^(?:first(?:ly)?|second(?:ly)?|third(?:ly)?|then|next|after(?:wards| that)?|finally|lastly|now)\s*[,:]\s*\S/i;
|
|
496
504
|
var META_COMMENTARY_RE = /\b(?:keeping (?:it|this) simple|could be (?:refactored|improved|cleaned up|simplified)|refactor(?:ed|ing)? (?:later|this)|not sure (?:if|whether|why|how)|quick[- ](?:and[- ]dirty|fix)|(?:a |bit of a )?hacky|is a hack|temporary (?:solution|workaround|fix|hack)|revisit (?:this|later|below)|clean (?:this|it) up|not ideal|placeholder for now)\b/i;
|
|
497
505
|
var FOR_NOW_RE = /\bfor now\b/i;
|
|
@@ -670,11 +678,11 @@ function isProse(text) {
|
|
|
670
678
|
return false;
|
|
671
679
|
}
|
|
672
680
|
var JUSTIFICATION_RE = /\b(?:because|since|until|due to|so that|so we|so it|so the|otherwise|which is why|in order to|to avoid|to work around|to prevent|backwards? compat(?:ibility)?|for compatibility)\b/i;
|
|
673
|
-
function restatesWholeStatement(
|
|
674
|
-
return statement !== null && restatesStatementHead(
|
|
681
|
+
function restatesWholeStatement(body2, statement) {
|
|
682
|
+
return statement !== null && restatesStatementHead(body2, statement.replaceAll("(", " "));
|
|
675
683
|
}
|
|
676
|
-
function isRedundantNarration(
|
|
677
|
-
const t =
|
|
684
|
+
function isRedundantNarration(body2, statementBelow, standalone, isolatedEnumeration, nested) {
|
|
685
|
+
const t = body2.trim();
|
|
678
686
|
if (!t || looksLikeCode(t) || hasPseudocode(t)) return false;
|
|
679
687
|
if (standalone) {
|
|
680
688
|
const justified = JUSTIFICATION_RE.test(t);
|
|
@@ -704,6 +712,63 @@ var STATEMENT_CONTAINERS = /* @__PURE__ */ new Set([
|
|
|
704
712
|
AST_NODE_TYPES5.TSModuleBlock,
|
|
705
713
|
AST_NODE_TYPES5.TSInterfaceBody
|
|
706
714
|
]);
|
|
715
|
+
function directStatements(container) {
|
|
716
|
+
switch (container.type) {
|
|
717
|
+
case AST_NODE_TYPES5.Program:
|
|
718
|
+
case AST_NODE_TYPES5.BlockStatement:
|
|
719
|
+
case AST_NODE_TYPES5.ClassBody:
|
|
720
|
+
case AST_NODE_TYPES5.StaticBlock:
|
|
721
|
+
case AST_NODE_TYPES5.TSModuleBlock:
|
|
722
|
+
return container.body;
|
|
723
|
+
case AST_NODE_TYPES5.SwitchCase:
|
|
724
|
+
return container.consequent;
|
|
725
|
+
case AST_NODE_TYPES5.TSInterfaceBody:
|
|
726
|
+
return container.body;
|
|
727
|
+
default:
|
|
728
|
+
return [];
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
var WALL_STATEMENTS = /* @__PURE__ */ new Set([
|
|
732
|
+
AST_NODE_TYPES5.ExpressionStatement,
|
|
733
|
+
AST_NODE_TYPES5.ReturnStatement,
|
|
734
|
+
AST_NODE_TYPES5.ThrowStatement,
|
|
735
|
+
AST_NODE_TYPES5.VariableDeclaration,
|
|
736
|
+
AST_NODE_TYPES5.IfStatement,
|
|
737
|
+
AST_NODE_TYPES5.ForStatement,
|
|
738
|
+
AST_NODE_TYPES5.ForOfStatement,
|
|
739
|
+
AST_NODE_TYPES5.ForInStatement,
|
|
740
|
+
AST_NODE_TYPES5.WhileStatement,
|
|
741
|
+
AST_NODE_TYPES5.DoWhileStatement,
|
|
742
|
+
AST_NODE_TYPES5.SwitchStatement,
|
|
743
|
+
AST_NODE_TYPES5.TryStatement
|
|
744
|
+
]);
|
|
745
|
+
function statementAttachmentBelow(comment, sourceCode) {
|
|
746
|
+
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
747
|
+
if (token === null || token.loc.start.line !== comment.loc.end.line + 1 || token.loc.start.column !== comment.loc.start.column) {
|
|
748
|
+
return null;
|
|
749
|
+
}
|
|
750
|
+
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node?.parent != null; node = node.parent) {
|
|
751
|
+
if (!STATEMENT_CONTAINERS.has(node.parent.type) || !WALL_STATEMENTS.has(node.type)) {
|
|
752
|
+
continue;
|
|
753
|
+
}
|
|
754
|
+
const siblings = directStatements(node.parent);
|
|
755
|
+
const index = siblings.indexOf(node);
|
|
756
|
+
return index < 0 ? null : { container: node.parent, index, statement: sourceCode.getText(node) };
|
|
757
|
+
}
|
|
758
|
+
return null;
|
|
759
|
+
}
|
|
760
|
+
function isWeakWalkthroughComment(body2, statement) {
|
|
761
|
+
const normalized = body2.replace(WALL_STEP_PREFIX_RE, "");
|
|
762
|
+
if (normalized.length === 0 || normalized.endsWith("?") || normalized.split(/\s+/).length > WALL_MAX_WORDS || isDirective(normalized) || isProtected(normalized) || !WALL_NARRATION_RE.test(normalized)) {
|
|
763
|
+
return false;
|
|
764
|
+
}
|
|
765
|
+
const words = contentTokens(normalized);
|
|
766
|
+
const described = words.slice(1);
|
|
767
|
+
if (described.length === 0) return false;
|
|
768
|
+
const code = codeTokens(statement);
|
|
769
|
+
const matched = described.filter((word) => restates([word], code)).length;
|
|
770
|
+
return matched / described.length >= 0.5 && described.length - matched <= WALL_MAX_NOVEL_WORDS;
|
|
771
|
+
}
|
|
707
772
|
var TYPE_MEMBER_CONTAINERS = /* @__PURE__ */ new Set([
|
|
708
773
|
AST_NODE_TYPES5.TSInterfaceBody,
|
|
709
774
|
AST_NODE_TYPES5.TSTypeLiteral
|
|
@@ -730,8 +795,8 @@ var LEAD_IN_SCAN_LIMIT = 24;
|
|
|
730
795
|
function hasIllustrationLeadInAbove(comments, index) {
|
|
731
796
|
for (let i = index - 1; i >= 0 && index - i <= LEAD_IN_SCAN_LIMIT; i--) {
|
|
732
797
|
if (!areAdjacentLineComments(comments[i], comments[i + 1])) return false;
|
|
733
|
-
const
|
|
734
|
-
if (
|
|
798
|
+
const body2 = stripCommentMarker(comments[i]?.value ?? "");
|
|
799
|
+
if (body2.length > 0 && body2.endsWith(":")) return true;
|
|
735
800
|
}
|
|
736
801
|
return false;
|
|
737
802
|
}
|
|
@@ -759,6 +824,7 @@ var no_comment_cruft_default = createRule({
|
|
|
759
824
|
commentedOutCode: "Commented-out code \u2014 delete it; git history remembers.",
|
|
760
825
|
sectionBanner: "Section-banner / region comment \u2014 structure code with functions, not ASCII rules.",
|
|
761
826
|
fileHeaderPreamble: "File-header comment preamble \u2014 use a brief doc comment for the why, not a block of `//` lines.",
|
|
827
|
+
commentWall: "Statement comment wall ({{count}} narrated steps) \u2014 delete the walkthrough and name the operations in code; keep only constraints or rationale.",
|
|
762
828
|
redundantNarration: "Comment narrates the code \u2014 delete it or say *why*, not *what*. Code is self-documenting.",
|
|
763
829
|
untrackedTodo: "Untracked TODO/FIXME marker \u2014 add an issue ticket or context link."
|
|
764
830
|
}
|
|
@@ -778,6 +844,48 @@ var no_comment_cruft_default = createRule({
|
|
|
778
844
|
function isJsDoc(comment) {
|
|
779
845
|
return comment.type === "Block" && /^\*/.test(comment.value);
|
|
780
846
|
}
|
|
847
|
+
function findCommentWalls(comments) {
|
|
848
|
+
const attached = /* @__PURE__ */ new Map();
|
|
849
|
+
for (const comment of comments) {
|
|
850
|
+
if (comment.type !== "Line" || !isStandalone(comment)) continue;
|
|
851
|
+
const attachment = statementAttachmentBelow(comment, sourceCode);
|
|
852
|
+
if (attachment === null) continue;
|
|
853
|
+
const body2 = stripCommentMarker(comment.value);
|
|
854
|
+
const entries = attached.get(attachment.container) ?? [];
|
|
855
|
+
entries.push({
|
|
856
|
+
comment,
|
|
857
|
+
index: attachment.index,
|
|
858
|
+
weak: isWeakWalkthroughComment(body2, attachment.statement)
|
|
859
|
+
});
|
|
860
|
+
attached.set(attachment.container, entries);
|
|
861
|
+
}
|
|
862
|
+
const walls = [];
|
|
863
|
+
for (const entries of attached.values()) {
|
|
864
|
+
const sorted = entries.toSorted((left, right) => left.index - right.index);
|
|
865
|
+
const clusters = [];
|
|
866
|
+
for (const entry of sorted) {
|
|
867
|
+
const cluster = clusters.at(-1);
|
|
868
|
+
if (cluster !== void 0 && entry.index <= (cluster.at(-1)?.index ?? 0) + 2) {
|
|
869
|
+
cluster.push(entry);
|
|
870
|
+
} else {
|
|
871
|
+
clusters.push([entry]);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
for (const cluster of clusters) {
|
|
875
|
+
const firstIndex = cluster[0]?.index;
|
|
876
|
+
const lastIndex = cluster.at(-1)?.index;
|
|
877
|
+
if (firstIndex === void 0 || lastIndex === void 0) continue;
|
|
878
|
+
const span = lastIndex - firstIndex + 1;
|
|
879
|
+
const weak = cluster.filter((entry) => entry.weak).map((entry) => entry.comment);
|
|
880
|
+
if (span < WALL_MIN_STATEMENTS || weak.length < WALL_MIN_COMMENTS || cluster.length / span < WALL_MIN_COMMENTED_RATIO || weak.length / cluster.length < WALL_MIN_WEAK_RATIO) {
|
|
881
|
+
continue;
|
|
882
|
+
}
|
|
883
|
+
const leader = weak[0];
|
|
884
|
+
if (leader !== void 0) walls.push({ leader, members: new Set(weak) });
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
return walls;
|
|
888
|
+
}
|
|
781
889
|
function isSectionJsDoc(comment) {
|
|
782
890
|
const texts = comment.value.split("\n").map(stripCommentMarker).filter((line) => line.length > 0 && !isDirective(line));
|
|
783
891
|
return texts.length > 0 && texts.every(
|
|
@@ -791,8 +899,8 @@ var no_comment_cruft_default = createRule({
|
|
|
791
899
|
if (comment.type !== "Line") break;
|
|
792
900
|
if (comment.loc.start.line >= firstCodeLine) break;
|
|
793
901
|
if (!isStandalone(comment)) break;
|
|
794
|
-
const
|
|
795
|
-
if (isDirective(
|
|
902
|
+
const body2 = stripCommentMarker(comment.value);
|
|
903
|
+
if (isDirective(body2) || body2.startsWith("!")) continue;
|
|
796
904
|
if (prevLine !== null && comment.loc.start.line !== prevLine + 1) break;
|
|
797
905
|
leading.push(comment);
|
|
798
906
|
prevLine = comment.loc.start.line;
|
|
@@ -800,8 +908,8 @@ var no_comment_cruft_default = createRule({
|
|
|
800
908
|
const first = leading[0];
|
|
801
909
|
if (first === void 0 || leading.length < LEADING_PREAMBLE_MIN) return;
|
|
802
910
|
const bodies = leading.map((c) => stripCommentMarker(c.value));
|
|
803
|
-
if (bodies.some((
|
|
804
|
-
if (bodies.some((
|
|
911
|
+
if (bodies.some((body2) => LICENSE_RE.test(body2))) return;
|
|
912
|
+
if (bodies.some((body2) => isProse(body2))) return;
|
|
805
913
|
if (bodies.filter(isEnumeratedProseItem).length >= ENUMERATED_PREAMBLE_MIN_ITEMS) {
|
|
806
914
|
return;
|
|
807
915
|
}
|
|
@@ -810,6 +918,9 @@ var no_comment_cruft_default = createRule({
|
|
|
810
918
|
return {
|
|
811
919
|
Program() {
|
|
812
920
|
const comments = sourceCode.getAllComments();
|
|
921
|
+
const walls = findCommentWalls(comments);
|
|
922
|
+
const wallByLeader = new Map(walls.map((wall) => [wall.leader, wall]));
|
|
923
|
+
const wallMembers = new Set(walls.flatMap((wall) => [...wall.members]));
|
|
813
924
|
const firstCodeLine = sourceCode.ast.tokens[0]?.loc.start.line ?? Number.MAX_SAFE_INTEGER;
|
|
814
925
|
const enumerated = comments.filter(
|
|
815
926
|
(c) => c.type === "Line" && ENUMERATION_RE.test(stripCommentMarker(c.value))
|
|
@@ -817,6 +928,16 @@ var no_comment_cruft_default = createRule({
|
|
|
817
928
|
for (let i = 0; i < comments.length; i++) {
|
|
818
929
|
const comment = comments[i];
|
|
819
930
|
if (comment === void 0) continue;
|
|
931
|
+
const wall = wallByLeader.get(comment);
|
|
932
|
+
if (wall !== void 0) {
|
|
933
|
+
context.report({
|
|
934
|
+
node: comment,
|
|
935
|
+
messageId: "commentWall",
|
|
936
|
+
data: { count: String(wall.members.size) }
|
|
937
|
+
});
|
|
938
|
+
continue;
|
|
939
|
+
}
|
|
940
|
+
if (wallMembers.has(comment)) continue;
|
|
820
941
|
if (isJsDoc(comment)) {
|
|
821
942
|
if (isStandalone(comment) && isSectionJsDoc(comment)) {
|
|
822
943
|
context.report({ node: comment, messageId: "sectionBanner" });
|
|
@@ -849,11 +970,11 @@ var no_comment_cruft_default = createRule({
|
|
|
849
970
|
continue;
|
|
850
971
|
}
|
|
851
972
|
if (comment.type === "Line" && texts.length === 1) {
|
|
852
|
-
const
|
|
973
|
+
const body2 = texts[0];
|
|
853
974
|
const statement = restatableStatementBelow(comment, sourceCode);
|
|
854
975
|
const standalone = !isInsideCommentRun(comments, i);
|
|
855
976
|
const nested = container !== null && !STATEMENT_CONTAINERS.has(container.type);
|
|
856
|
-
if (
|
|
977
|
+
if (body2 !== void 0 && !runCitesAReference(comments, i) && isRedundantNarration(body2, statement, standalone, enumerated.length === 1, nested)) {
|
|
857
978
|
context.report({ node: comment, messageId: "redundantNarration" });
|
|
858
979
|
}
|
|
859
980
|
}
|
|
@@ -867,11 +988,12 @@ var no_comment_cruft_default = createRule({
|
|
|
867
988
|
// src/rules/no-conditional-in-test.ts
|
|
868
989
|
import { AST_NODE_TYPES as AST_NODE_TYPES6 } from "@typescript-eslint/utils";
|
|
869
990
|
var TEST_CALLERS = /* @__PURE__ */ new Set(["it", "test"]);
|
|
870
|
-
var
|
|
991
|
+
var NON_TEST_MEMBERS = /* @__PURE__ */ new Set([
|
|
871
992
|
"afterAll",
|
|
872
993
|
"afterEach",
|
|
873
994
|
"beforeAll",
|
|
874
|
-
"beforeEach"
|
|
995
|
+
"beforeEach",
|
|
996
|
+
"describe"
|
|
875
997
|
]);
|
|
876
998
|
var FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
877
999
|
AST_NODE_TYPES6.FunctionDeclaration,
|
|
@@ -911,12 +1033,27 @@ function testCallerName(callee) {
|
|
|
911
1033
|
}
|
|
912
1034
|
return null;
|
|
913
1035
|
}
|
|
1036
|
+
function hasNonTestMember(callee) {
|
|
1037
|
+
if (callee.type === AST_NODE_TYPES6.MemberExpression) {
|
|
1038
|
+
if (!callee.computed && callee.property.type === AST_NODE_TYPES6.Identifier && NON_TEST_MEMBERS.has(callee.property.name)) {
|
|
1039
|
+
return true;
|
|
1040
|
+
}
|
|
1041
|
+
return hasNonTestMember(callee.object);
|
|
1042
|
+
}
|
|
1043
|
+
if (callee.type === AST_NODE_TYPES6.CallExpression) {
|
|
1044
|
+
return hasNonTestMember(callee.callee);
|
|
1045
|
+
}
|
|
1046
|
+
if (callee.type === AST_NODE_TYPES6.TaggedTemplateExpression) {
|
|
1047
|
+
return hasNonTestMember(callee.tag);
|
|
1048
|
+
}
|
|
1049
|
+
return false;
|
|
1050
|
+
}
|
|
914
1051
|
function isTestBody(fn) {
|
|
915
1052
|
const call = fn.parent;
|
|
916
1053
|
if (call?.type !== AST_NODE_TYPES6.CallExpression || !call.arguments.some((argument) => argument === fn)) {
|
|
917
1054
|
return false;
|
|
918
1055
|
}
|
|
919
|
-
if (
|
|
1056
|
+
if (hasNonTestMember(call.callee)) {
|
|
920
1057
|
return false;
|
|
921
1058
|
}
|
|
922
1059
|
const name = testCallerName(call.callee);
|
|
@@ -1642,6 +1779,7 @@ var no_enum_default = createRule({
|
|
|
1642
1779
|
properties: {
|
|
1643
1780
|
ignoreFiles: {
|
|
1644
1781
|
type: "array",
|
|
1782
|
+
description: "Additional generated-file globs to ignore; shared generated paths and header markers are always ignored.",
|
|
1645
1783
|
items: { type: "string" }
|
|
1646
1784
|
}
|
|
1647
1785
|
}
|
|
@@ -1851,8 +1989,8 @@ function handlerRethrows(handler) {
|
|
|
1851
1989
|
if (handler === null) {
|
|
1852
1990
|
return false;
|
|
1853
1991
|
}
|
|
1854
|
-
const
|
|
1855
|
-
const last =
|
|
1992
|
+
const body2 = handler.body.body;
|
|
1993
|
+
const last = body2[body2.length - 1];
|
|
1856
1994
|
return last !== void 0 && last.type === AST_NODE_TYPES9.ThrowStatement;
|
|
1857
1995
|
}
|
|
1858
1996
|
var PASS_THROUGH_PARENTS = /* @__PURE__ */ new Set([
|
|
@@ -1886,8 +2024,8 @@ function unwrapAwait(expr) {
|
|
|
1886
2024
|
return inner.type === AST_NODE_TYPES9.AwaitExpression ? unwrap(inner.argument) : inner;
|
|
1887
2025
|
}
|
|
1888
2026
|
function handlerEndsByHandingOff(handler) {
|
|
1889
|
-
const
|
|
1890
|
-
const last =
|
|
2027
|
+
const body2 = handler.body.body;
|
|
2028
|
+
const last = body2[body2.length - 1];
|
|
1891
2029
|
if (last === void 0) {
|
|
1892
2030
|
return false;
|
|
1893
2031
|
}
|
|
@@ -2461,8 +2599,8 @@ function negatedInstanceofErrorSubject(test) {
|
|
|
2461
2599
|
return null;
|
|
2462
2600
|
}
|
|
2463
2601
|
function branchTerminates(branch) {
|
|
2464
|
-
const
|
|
2465
|
-
const last =
|
|
2602
|
+
const body2 = branch.type === "BlockStatement" ? branch.body : [branch];
|
|
2603
|
+
const last = body2[body2.length - 1];
|
|
2466
2604
|
return last !== void 0 && (last.type === "ReturnStatement" || last.type === "ThrowStatement");
|
|
2467
2605
|
}
|
|
2468
2606
|
function isNarrowedByEarlyReturn(node, argExpr, sourceCode) {
|
|
@@ -2714,8 +2852,8 @@ function hasFollowingStatement(node) {
|
|
|
2714
2852
|
return false;
|
|
2715
2853
|
}
|
|
2716
2854
|
function fallbackFollowsTry(tryStatement) {
|
|
2717
|
-
const
|
|
2718
|
-
const last =
|
|
2855
|
+
const body2 = tryStatement.block.body;
|
|
2856
|
+
const last = body2.at(-1);
|
|
2719
2857
|
return last?.type === AST_NODE_TYPES11.ReturnStatement && hasFollowingStatement(tryStatement);
|
|
2720
2858
|
}
|
|
2721
2859
|
function isSeedValue(node) {
|
|
@@ -2832,6 +2970,123 @@ var no_log_only_catch_default = createRule({
|
|
|
2832
2970
|
}
|
|
2833
2971
|
});
|
|
2834
2972
|
|
|
2973
|
+
// src/rules/_prose-budget.ts
|
|
2974
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES12 } from "@typescript-eslint/utils";
|
|
2975
|
+
var DIRECTIVE_RE2 = /^(?:!|eslint\b|eslint-|@ts-|prettier|biome-|c8\b|v8\b|istanbul\b|@vite|webpack|@jsx|@jest-environment|@vitest-environment|#__|todo\b|fixme\b|hack\b)/i;
|
|
2976
|
+
var LICENSE_RE2 = /\b(?:copyright|spdx-license-identifier|licensed under)\b/i;
|
|
2977
|
+
var TYPED_TAG_RE = /@(arg|argument|param|return|returns|yield|yields)\b/i;
|
|
2978
|
+
var VALUE_TAG_RE = /@(example|deprecated|see|remarks|throws|internal|public|alpha|beta|since|template|fileoverview)\b/i;
|
|
2979
|
+
var BOUNDARY_RE = /(?<=[.!?])["'`)\]]*\s+(?=[A-Z0-9`])/;
|
|
2980
|
+
var BULLET_RE = /^\s*(?:[-*+] |\d+[.)] )/;
|
|
2981
|
+
function body(comment) {
|
|
2982
|
+
return comment.value.replace(/^\*/, "").split("\n").map((line) => line.replace(/^\s*\*?\s?/, "")).join("\n").trim();
|
|
2983
|
+
}
|
|
2984
|
+
function eligible(text, includeValueTags) {
|
|
2985
|
+
return text.length > 0 && !DIRECTIVE_RE2.test(text) && !LICENSE_RE2.test(text) && (includeValueTags || !VALUE_TAG_RE.test(text));
|
|
2986
|
+
}
|
|
2987
|
+
function sentenceUnits(text) {
|
|
2988
|
+
const cleaned = text.replace(/https?:\/\/\S+/g, "URL").replace(/`[^`\n]+`/g, "CODE").replace(/\b\d+\.\d+\b/g, "NUMBER").replace(/\b(?:e\.g\.|i\.e\.|vs\.|etc\.)/gi, "ABBREVIATION");
|
|
2989
|
+
let units = 0;
|
|
2990
|
+
const prose = [];
|
|
2991
|
+
for (const raw of cleaned.split("\n")) {
|
|
2992
|
+
const line = raw.trim();
|
|
2993
|
+
if (line.length === 0 || /^[A-Za-z][A-Za-z ]+:$/.test(line)) continue;
|
|
2994
|
+
if (BULLET_RE.test(line)) units += 1;
|
|
2995
|
+
else prose.push(line);
|
|
2996
|
+
}
|
|
2997
|
+
if (prose.length > 0) units += prose.join(" ").split(BOUNDARY_RE).length;
|
|
2998
|
+
return units;
|
|
2999
|
+
}
|
|
3000
|
+
function proseGroups(filename, sourceCode, includeValueTags = false) {
|
|
3001
|
+
if (isGeneratedFile(filename, sourceCode.text) || isStoryFile(filename)) return [];
|
|
3002
|
+
const groups = [];
|
|
3003
|
+
let run = [];
|
|
3004
|
+
const flush = () => {
|
|
3005
|
+
if (run.length === 0) return;
|
|
3006
|
+
const text = run.map(body).join("\n");
|
|
3007
|
+
if (eligible(text, includeValueTags)) groups.push({ comment: run[0], text, hasTypedTags: TYPED_TAG_RE.test(text) });
|
|
3008
|
+
run = [];
|
|
3009
|
+
};
|
|
3010
|
+
for (const comment of sourceCode.getAllComments()) {
|
|
3011
|
+
const text = body(comment);
|
|
3012
|
+
if (comment.type === "Block") {
|
|
3013
|
+
flush();
|
|
3014
|
+
if (eligible(text, includeValueTags)) groups.push({ comment, text, hasTypedTags: TYPED_TAG_RE.test(text) });
|
|
3015
|
+
continue;
|
|
3016
|
+
}
|
|
3017
|
+
const ownLine = sourceCode.lines[comment.loc.start.line - 1]?.slice(0, comment.loc.start.column).trim() === "";
|
|
3018
|
+
if (!ownLine || !eligible(text, includeValueTags)) {
|
|
3019
|
+
flush();
|
|
3020
|
+
continue;
|
|
3021
|
+
}
|
|
3022
|
+
const previous = run.at(-1);
|
|
3023
|
+
if (previous !== void 0 && (comment.loc.start.line !== previous.loc.end.line + 1 || comment.loc.start.column !== previous.loc.start.column)) flush();
|
|
3024
|
+
run.push(comment);
|
|
3025
|
+
}
|
|
3026
|
+
flush();
|
|
3027
|
+
return groups;
|
|
3028
|
+
}
|
|
3029
|
+
function annotatedParameter(parameter) {
|
|
3030
|
+
if (parameter.type === AST_NODE_TYPES12.TSParameterProperty) return annotatedParameter(parameter.parameter);
|
|
3031
|
+
const target = parameter.type === AST_NODE_TYPES12.AssignmentPattern ? parameter.left : parameter;
|
|
3032
|
+
return "typeAnnotation" in target && target.typeAnnotation != null;
|
|
3033
|
+
}
|
|
3034
|
+
function typedFunction(node) {
|
|
3035
|
+
switch (node.type) {
|
|
3036
|
+
case AST_NODE_TYPES12.ExportNamedDeclaration:
|
|
3037
|
+
case AST_NODE_TYPES12.ExportDefaultDeclaration:
|
|
3038
|
+
return node.declaration != null && typedFunction(node.declaration);
|
|
3039
|
+
case AST_NODE_TYPES12.FunctionDeclaration:
|
|
3040
|
+
case AST_NODE_TYPES12.TSDeclareFunction:
|
|
3041
|
+
return node.returnType != null && node.params.every(annotatedParameter);
|
|
3042
|
+
case AST_NODE_TYPES12.VariableDeclaration: {
|
|
3043
|
+
const init = node.declarations[0]?.init;
|
|
3044
|
+
return init != null && (init.type === AST_NODE_TYPES12.ArrowFunctionExpression || init.type === AST_NODE_TYPES12.FunctionExpression) && init.returnType != null && init.params.every(annotatedParameter);
|
|
3045
|
+
}
|
|
3046
|
+
case AST_NODE_TYPES12.MethodDefinition:
|
|
3047
|
+
return node.value.returnType != null && node.value.params.every(annotatedParameter);
|
|
3048
|
+
case AST_NODE_TYPES12.TSMethodSignature:
|
|
3049
|
+
return node.returnType != null && node.params.every(annotatedParameter);
|
|
3050
|
+
default:
|
|
3051
|
+
return false;
|
|
3052
|
+
}
|
|
3053
|
+
}
|
|
3054
|
+
function documentsTypedFunction(sourceCode, comment) {
|
|
3055
|
+
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
3056
|
+
if (token === null || token.loc.start.line !== comment.loc.end.line + 1) return false;
|
|
3057
|
+
let node = sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
3058
|
+
while (node != null && node.type !== AST_NODE_TYPES12.Program) {
|
|
3059
|
+
if (typedFunction(node)) return true;
|
|
3060
|
+
node = node.parent ?? null;
|
|
3061
|
+
}
|
|
3062
|
+
return false;
|
|
3063
|
+
}
|
|
3064
|
+
|
|
3065
|
+
// src/rules/no-long-comment.ts
|
|
3066
|
+
var no_long_comment_default = createRule({
|
|
3067
|
+
name: "no-long-comment",
|
|
3068
|
+
meta: {
|
|
3069
|
+
type: "suggestion",
|
|
3070
|
+
docs: { description: "Limit in-code prose to two sentences." },
|
|
3071
|
+
schema: [],
|
|
3072
|
+
messages: {
|
|
3073
|
+
tooLong: "Comment exceeds two sentences \u2014 keep one local fact and clarify the code itself."
|
|
3074
|
+
}
|
|
3075
|
+
},
|
|
3076
|
+
defaultOptions: [],
|
|
3077
|
+
create(context) {
|
|
3078
|
+
return {
|
|
3079
|
+
Program() {
|
|
3080
|
+
for (const group of proseGroups(context.filename, context.sourceCode)) {
|
|
3081
|
+
if (!group.hasTypedTags && sentenceUnits(group.text) >= 3) {
|
|
3082
|
+
context.report({ node: group.comment, messageId: "tooLong" });
|
|
3083
|
+
}
|
|
3084
|
+
}
|
|
3085
|
+
}
|
|
3086
|
+
};
|
|
3087
|
+
}
|
|
3088
|
+
});
|
|
3089
|
+
|
|
2835
3090
|
// src/rules/no-offset-pagination.ts
|
|
2836
3091
|
import "@typescript-eslint/utils";
|
|
2837
3092
|
var OFFSET_PAGINATION = /\bOFFSET\s+(?:%s|%\(\w+\)s|\?\d*|:\w+|@\w+|\$\d+|\d+)/i;
|
|
@@ -2863,15 +3118,15 @@ var no_offset_pagination_default = createRule({
|
|
|
2863
3118
|
});
|
|
2864
3119
|
|
|
2865
3120
|
// src/rules/no-positional-tuple-return.ts
|
|
2866
|
-
import { AST_NODE_TYPES as
|
|
3121
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES13 } from "@typescript-eslint/utils";
|
|
2867
3122
|
var MIN_ELEMENTS = 2;
|
|
2868
3123
|
var ACCESSOR_PAIR_LENGTH = 2;
|
|
2869
3124
|
var AWAITABLE_TYPES = /* @__PURE__ */ new Set(["Promise", "PromiseLike", "Awaited"]);
|
|
2870
3125
|
function tupleReturnType(node) {
|
|
2871
|
-
if (node.type ===
|
|
3126
|
+
if (node.type === AST_NODE_TYPES13.TSTupleType) {
|
|
2872
3127
|
return node;
|
|
2873
3128
|
}
|
|
2874
|
-
if (node.type ===
|
|
3129
|
+
if (node.type === AST_NODE_TYPES13.TSTypeReference && node.typeName.type === AST_NODE_TYPES13.Identifier && AWAITABLE_TYPES.has(node.typeName.name)) {
|
|
2875
3130
|
const argument = node.typeArguments?.params[0];
|
|
2876
3131
|
return argument === void 0 ? null : tupleReturnType(argument);
|
|
2877
3132
|
}
|
|
@@ -2885,30 +3140,30 @@ function isPermittedTuple(tuple, sourceCode) {
|
|
|
2885
3140
|
if (elements.length < MIN_ELEMENTS) {
|
|
2886
3141
|
return true;
|
|
2887
3142
|
}
|
|
2888
|
-
if (elements.some((element) => element.type ===
|
|
3143
|
+
if (elements.some((element) => element.type === AST_NODE_TYPES13.TSRestType)) {
|
|
2889
3144
|
return true;
|
|
2890
3145
|
}
|
|
2891
|
-
if (elements.some((element) => element.type ===
|
|
3146
|
+
if (elements.some((element) => element.type === AST_NODE_TYPES13.TSNamedTupleMember)) {
|
|
2892
3147
|
return true;
|
|
2893
3148
|
}
|
|
2894
|
-
if (elements[0]?.type ===
|
|
3149
|
+
if (elements[0]?.type === AST_NODE_TYPES13.TSLiteralType) {
|
|
2895
3150
|
return true;
|
|
2896
3151
|
}
|
|
2897
|
-
if (elements.length === ACCESSOR_PAIR_LENGTH && elements.some((element) => element.type ===
|
|
3152
|
+
if (elements.length === ACCESSOR_PAIR_LENGTH && elements.some((element) => element.type === AST_NODE_TYPES13.TSFunctionType)) {
|
|
2898
3153
|
return true;
|
|
2899
3154
|
}
|
|
2900
3155
|
const texts = new Set(elements.map((element) => normalizedText(sourceCode, element)));
|
|
2901
3156
|
return texts.size === 1;
|
|
2902
3157
|
}
|
|
2903
3158
|
function functionName(node) {
|
|
2904
|
-
if (node.type ===
|
|
3159
|
+
if (node.type === AST_NODE_TYPES13.FunctionDeclaration) {
|
|
2905
3160
|
return node.id?.name ?? null;
|
|
2906
3161
|
}
|
|
2907
3162
|
const parent = node.parent;
|
|
2908
|
-
if (parent?.type ===
|
|
3163
|
+
if (parent?.type === AST_NODE_TYPES13.VariableDeclarator && parent.id.type === AST_NODE_TYPES13.Identifier) {
|
|
2909
3164
|
return parent.id.name;
|
|
2910
3165
|
}
|
|
2911
|
-
if ((parent?.type ===
|
|
3166
|
+
if ((parent?.type === AST_NODE_TYPES13.MethodDefinition || parent?.type === AST_NODE_TYPES13.PropertyDefinition || parent?.type === AST_NODE_TYPES13.Property) && parent.key.type === AST_NODE_TYPES13.Identifier) {
|
|
2912
3167
|
return parent.key.name;
|
|
2913
3168
|
}
|
|
2914
3169
|
return null;
|
|
@@ -2916,7 +3171,7 @@ function functionName(node) {
|
|
|
2916
3171
|
function isInlineExported(node) {
|
|
2917
3172
|
for (let current = node; current != null; current = current.parent) {
|
|
2918
3173
|
const parent = current.parent;
|
|
2919
|
-
if (parent?.type ===
|
|
3174
|
+
if (parent?.type === AST_NODE_TYPES13.ExportNamedDeclaration || parent?.type === AST_NODE_TYPES13.ExportDefaultDeclaration) {
|
|
2920
3175
|
return true;
|
|
2921
3176
|
}
|
|
2922
3177
|
}
|
|
@@ -2925,18 +3180,18 @@ function isInlineExported(node) {
|
|
|
2925
3180
|
function moduleScopeBindingName(node) {
|
|
2926
3181
|
let current = node;
|
|
2927
3182
|
let child = node;
|
|
2928
|
-
while (current.parent != null && current.parent.type !==
|
|
3183
|
+
while (current.parent != null && current.parent.type !== AST_NODE_TYPES13.Program) {
|
|
2929
3184
|
child = current;
|
|
2930
3185
|
current = current.parent;
|
|
2931
3186
|
}
|
|
2932
|
-
if (current.parent?.type !==
|
|
3187
|
+
if (current.parent?.type !== AST_NODE_TYPES13.Program) {
|
|
2933
3188
|
return null;
|
|
2934
3189
|
}
|
|
2935
|
-
if (current.type ===
|
|
3190
|
+
if (current.type === AST_NODE_TYPES13.FunctionDeclaration || current.type === AST_NODE_TYPES13.ClassDeclaration) {
|
|
2936
3191
|
return current.id?.name ?? null;
|
|
2937
3192
|
}
|
|
2938
|
-
if (current.type ===
|
|
2939
|
-
if (child.type !==
|
|
3193
|
+
if (current.type === AST_NODE_TYPES13.VariableDeclaration) {
|
|
3194
|
+
if (child.type !== AST_NODE_TYPES13.VariableDeclarator || child.id.type !== AST_NODE_TYPES13.Identifier) {
|
|
2940
3195
|
return null;
|
|
2941
3196
|
}
|
|
2942
3197
|
return child.id.name;
|
|
@@ -2946,19 +3201,19 @@ function moduleScopeBindingName(node) {
|
|
|
2946
3201
|
function specifierExportedNames(program) {
|
|
2947
3202
|
const names = /* @__PURE__ */ new Set();
|
|
2948
3203
|
for (const statement of program.body) {
|
|
2949
|
-
if (statement.type ===
|
|
3204
|
+
if (statement.type === AST_NODE_TYPES13.ExportNamedDeclaration && statement.declaration == null && statement.source == null && statement.exportKind !== "type") {
|
|
2950
3205
|
for (const specifier of statement.specifiers) {
|
|
2951
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
3206
|
+
if (specifier.exportKind !== "type" && specifier.local.type === AST_NODE_TYPES13.Identifier) {
|
|
2952
3207
|
names.add(specifier.local.name);
|
|
2953
3208
|
}
|
|
2954
3209
|
}
|
|
2955
3210
|
continue;
|
|
2956
3211
|
}
|
|
2957
|
-
if (statement.type ===
|
|
3212
|
+
if (statement.type === AST_NODE_TYPES13.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES13.Identifier) {
|
|
2958
3213
|
names.add(statement.declaration.name);
|
|
2959
3214
|
continue;
|
|
2960
3215
|
}
|
|
2961
|
-
if (statement.type ===
|
|
3216
|
+
if (statement.type === AST_NODE_TYPES13.TSExportAssignment && statement.expression.type === AST_NODE_TYPES13.Identifier) {
|
|
2962
3217
|
names.add(statement.expression.name);
|
|
2963
3218
|
}
|
|
2964
3219
|
}
|
|
@@ -3070,11 +3325,11 @@ var no_raw_env_default = createRule({
|
|
|
3070
3325
|
meta: {
|
|
3071
3326
|
type: "problem",
|
|
3072
3327
|
docs: {
|
|
3073
|
-
description: "Disallow direct `process.env`
|
|
3328
|
+
description: "Disallow direct `process.env` and `import.meta.env` reads outside validated boundaries."
|
|
3074
3329
|
},
|
|
3075
3330
|
schema: [],
|
|
3076
3331
|
messages: {
|
|
3077
|
-
noRawEnv: "Do not read
|
|
3332
|
+
noRawEnv: "Do not read raw environment values directly. Import the validated env module so values are typed and checked at startup."
|
|
3078
3333
|
}
|
|
3079
3334
|
},
|
|
3080
3335
|
defaultOptions: [],
|
|
@@ -3097,13 +3352,11 @@ var no_raw_env_default = createRule({
|
|
|
3097
3352
|
});
|
|
3098
3353
|
|
|
3099
3354
|
// src/rules/no-raw-fetch-outside-clients.ts
|
|
3100
|
-
import { AST_NODE_TYPES as
|
|
3355
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES14 } from "@typescript-eslint/utils";
|
|
3101
3356
|
var DEFAULT_ALLOW = [
|
|
3102
3357
|
"[\\\\/]clients?[\\\\/]",
|
|
3103
3358
|
"-client\\.[cm]?[jt]sx?$",
|
|
3104
3359
|
"[\\\\/]http-client\\.[cm]?[jt]sx?$",
|
|
3105
|
-
// The `api` spelling of the same client-layer convention: an `api/` directory,
|
|
3106
|
-
// a bare `api.ts`, or a `*-api.ts` / `*.api.ts` module.
|
|
3107
3360
|
"[\\\\/]api[\\\\/]",
|
|
3108
3361
|
"[\\\\/]api\\.[cm]?[jt]sx?$",
|
|
3109
3362
|
"[-.]api\\.[cm]?[jt]sx?$",
|
|
@@ -3141,7 +3394,7 @@ function identifierLikeName(node) {
|
|
|
3141
3394
|
}
|
|
3142
3395
|
function isConstructedArgumentHandoff(node) {
|
|
3143
3396
|
const [first] = node.arguments;
|
|
3144
|
-
return node.arguments.length === 1 && first !== void 0 && first.type ===
|
|
3397
|
+
return node.arguments.length === 1 && first !== void 0 && first.type === AST_NODE_TYPES14.NewExpression;
|
|
3145
3398
|
}
|
|
3146
3399
|
function isPresignedUrlTransfer(node) {
|
|
3147
3400
|
const first = node.arguments[0];
|
|
@@ -3210,16 +3463,16 @@ var no_raw_fetch_outside_clients_default = createRule({
|
|
|
3210
3463
|
});
|
|
3211
3464
|
|
|
3212
3465
|
// src/rules/no-repeated-string-literal.ts
|
|
3213
|
-
import { AST_NODE_TYPES as
|
|
3466
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES15 } from "@typescript-eslint/utils";
|
|
3214
3467
|
var MIN_LENGTH = 40;
|
|
3215
3468
|
var MIN_DISTINCT_SCOPES = 2;
|
|
3216
3469
|
var PREVIEW_LENGTH = 40;
|
|
3217
3470
|
var SQL_KEYWORD_RE = /\b(SELECT|INSERT|UPDATE|DELETE|FROM|WHERE|JOIN|VALUES|ON CONFLICT|RETURNING|GROUP BY|ORDER BY)\b/;
|
|
3218
3471
|
var IDENTIFIER_RE = /^[a-z_][a-z0-9_.]*$/;
|
|
3219
3472
|
var FUNCTION_TYPES3 = /* @__PURE__ */ new Set([
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3473
|
+
AST_NODE_TYPES15.FunctionDeclaration,
|
|
3474
|
+
AST_NODE_TYPES15.FunctionExpression,
|
|
3475
|
+
AST_NODE_TYPES15.ArrowFunctionExpression
|
|
3223
3476
|
]);
|
|
3224
3477
|
function isStructured(value) {
|
|
3225
3478
|
return value.includes("\n") || SQL_KEYWORD_RE.test(value) || IDENTIFIER_RE.test(value);
|
|
@@ -3241,7 +3494,8 @@ function isScaffolding(node) {
|
|
|
3241
3494
|
if (parent === void 0) {
|
|
3242
3495
|
return true;
|
|
3243
3496
|
}
|
|
3244
|
-
|
|
3497
|
+
const isRequireSource = parent.type === AST_NODE_TYPES15.CallExpression && parent.callee.type === AST_NODE_TYPES15.Identifier && parent.callee.name === "require";
|
|
3498
|
+
return parent.type === AST_NODE_TYPES15.ImportDeclaration || parent.type === AST_NODE_TYPES15.ImportExpression || parent.type === AST_NODE_TYPES15.ExportNamedDeclaration || parent.type === AST_NODE_TYPES15.ExportAllDeclaration || parent.type === AST_NODE_TYPES15.TSImportType || parent.type === AST_NODE_TYPES15.JSXAttribute || parent.type === AST_NODE_TYPES15.TSLiteralType || isRequireSource;
|
|
3245
3499
|
}
|
|
3246
3500
|
var no_repeated_string_literal_default = createRule({
|
|
3247
3501
|
name: "no-repeated-string-literal",
|
|
@@ -3281,7 +3535,7 @@ var no_repeated_string_literal_default = createRule({
|
|
|
3281
3535
|
}
|
|
3282
3536
|
},
|
|
3283
3537
|
TemplateLiteral(node) {
|
|
3284
|
-
if (node.parent.type ===
|
|
3538
|
+
if (node.parent.type === AST_NODE_TYPES15.TaggedTemplateExpression) {
|
|
3285
3539
|
return;
|
|
3286
3540
|
}
|
|
3287
3541
|
const [only] = node.quasis;
|
|
@@ -3315,10 +3569,10 @@ var no_repeated_string_literal_default = createRule({
|
|
|
3315
3569
|
});
|
|
3316
3570
|
|
|
3317
3571
|
// src/rules/no-restated-comment.ts
|
|
3318
|
-
import { AST_NODE_TYPES as
|
|
3572
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES16 } from "@typescript-eslint/utils";
|
|
3319
3573
|
var MAX_WORDS = 8;
|
|
3320
3574
|
var MIN_CONTENT_TOKENS = 2;
|
|
3321
|
-
var
|
|
3575
|
+
var DIRECTIVE_RE3 = /^(eslint\b|eslint-|sarj-noqa\b|@ts-|prettier-ignore|prettier\b|biome-|c8\b|v8\b|istanbul\b|@type\b|@vite|webpack|<reference|<amd|global\b|noinspection|todo\b|fixme\b|hack\b|xxx\b)/i;
|
|
3322
3576
|
var CODEY_RE = /^[\w.$[\]'"]+\s*[:=]\s*\S|^[\w.$]+\s*\(|^(?:return|throw|await|import|export|const|let|var)\b.*[=()[\]{}]/;
|
|
3323
3577
|
var BANNERISH_RE = /[=\-─-╿*#~_.]{3,}|^[A-Z0-9 _:-]+$/;
|
|
3324
3578
|
var MODALITY_RE = /\b(?:can|could|should|shall|may|might|must|will|would|cannot)\b/i;
|
|
@@ -3327,16 +3581,19 @@ var EMPHASIS_RE = /\*\w[^*]*\*|`[^`]+`/;
|
|
|
3327
3581
|
var NEGATION_WORD_RE = /\b(?:no|not|never|neither|nor|without|none|non)\b/i;
|
|
3328
3582
|
var ACTION_STMT_RE = /[\w.$\])]\s*\(|^\s*(?:return|throw|await|yield)\b/;
|
|
3329
3583
|
var NON_ASCII_LETTER_RE = /[^\p{ASCII}\p{N}\p{P}\p{Z}]/u;
|
|
3584
|
+
var WALL_NARRATION_RE2 = /^(?:(?:\d+[.)]|(?:phase|step)\s+\d+\s*:?)\s*)?(?:add|build|call|check|compute|copy|count|create|fetch|filter|find|get|handle|load|map|merge|parse|process|read|remove|return|save|send|set|sort|store|update|validate|write)(?:s|es|d|ed|ing)?\b/i;
|
|
3585
|
+
var WALL_CLUSTER_MAX_LINE_GAP = 8;
|
|
3586
|
+
var WALL_CLUSTER_MIN_COMMENTS = 3;
|
|
3330
3587
|
function areAdjacentLineComments2(a, b) {
|
|
3331
3588
|
return a !== void 0 && b !== void 0 && a.type === "Line" && b.type === "Line" && b.loc.start.line === a.loc.end.line + 1;
|
|
3332
3589
|
}
|
|
3333
3590
|
function headsSiblingRun(node) {
|
|
3334
3591
|
const parent = node.parent;
|
|
3335
3592
|
if (parent === void 0) return false;
|
|
3336
|
-
const
|
|
3337
|
-
if (
|
|
3338
|
-
const index =
|
|
3339
|
-
const next = index >= 0 ?
|
|
3593
|
+
const body2 = "body" in parent && Array.isArray(parent.body) ? parent.body : void 0;
|
|
3594
|
+
if (body2 === void 0) return false;
|
|
3595
|
+
const index = body2.indexOf(node);
|
|
3596
|
+
const next = index >= 0 ? body2[index + 1] : void 0;
|
|
3340
3597
|
return next !== void 0 && next.type === node.type;
|
|
3341
3598
|
}
|
|
3342
3599
|
var no_restated_comment_default = createRule({
|
|
@@ -3365,7 +3622,7 @@ var no_restated_comment_default = createRule({
|
|
|
3365
3622
|
function labelsASiblingRun(comment) {
|
|
3366
3623
|
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
3367
3624
|
if (token === null) return false;
|
|
3368
|
-
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !==
|
|
3625
|
+
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !== AST_NODE_TYPES16.Program; node = node.parent) {
|
|
3369
3626
|
if (headsSiblingRun(node)) return true;
|
|
3370
3627
|
}
|
|
3371
3628
|
return false;
|
|
@@ -3373,25 +3630,45 @@ var no_restated_comment_default = createRule({
|
|
|
3373
3630
|
return {
|
|
3374
3631
|
Program() {
|
|
3375
3632
|
const comments = sourceCode.getAllComments();
|
|
3633
|
+
const wallMembers = /* @__PURE__ */ new Set();
|
|
3634
|
+
let cluster = [];
|
|
3635
|
+
for (const candidate of comments) {
|
|
3636
|
+
const body2 = candidate.value.replace(/^\/*/, "").trim();
|
|
3637
|
+
if (candidate.type !== "Line" || !isStandalone(candidate) || isProtected(body2) || !WALL_NARRATION_RE2.test(body2)) {
|
|
3638
|
+
continue;
|
|
3639
|
+
}
|
|
3640
|
+
const previous = cluster.at(-1);
|
|
3641
|
+
if (previous !== void 0 && candidate.loc.start.line - previous.loc.start.line > WALL_CLUSTER_MAX_LINE_GAP) {
|
|
3642
|
+
if (cluster.length >= WALL_CLUSTER_MIN_COMMENTS) {
|
|
3643
|
+
for (const member of cluster) wallMembers.add(member);
|
|
3644
|
+
}
|
|
3645
|
+
cluster = [];
|
|
3646
|
+
}
|
|
3647
|
+
cluster.push(candidate);
|
|
3648
|
+
}
|
|
3649
|
+
if (cluster.length >= WALL_CLUSTER_MIN_COMMENTS) {
|
|
3650
|
+
for (const member of cluster) wallMembers.add(member);
|
|
3651
|
+
}
|
|
3376
3652
|
for (let i = 0; i < comments.length; i++) {
|
|
3377
3653
|
const comment = comments[i];
|
|
3378
3654
|
if (comment === void 0 || comment.type !== "Line") continue;
|
|
3655
|
+
if (wallMembers.has(comment)) continue;
|
|
3379
3656
|
if (!isStandalone(comment)) continue;
|
|
3380
3657
|
if (areAdjacentLineComments2(comments[i - 1], comment) || areAdjacentLineComments2(comment, comments[i + 1])) {
|
|
3381
3658
|
continue;
|
|
3382
3659
|
}
|
|
3383
|
-
const
|
|
3384
|
-
if (
|
|
3385
|
-
if (
|
|
3386
|
-
if (NON_ASCII_LETTER_RE.test(
|
|
3387
|
-
if (MODALITY_RE.test(
|
|
3388
|
-
if (NEGATION_WORD_RE.test(
|
|
3389
|
-
if (
|
|
3390
|
-
const tokens = contentTokens(
|
|
3660
|
+
const body2 = comment.value.replace(/^\/*/, "").trim();
|
|
3661
|
+
if (body2.length === 0 || body2.endsWith("?")) continue;
|
|
3662
|
+
if (DIRECTIVE_RE3.test(body2) || CODEY_RE.test(body2) || BANNERISH_RE.test(body2)) continue;
|
|
3663
|
+
if (NON_ASCII_LETTER_RE.test(body2) || isProtected(body2)) continue;
|
|
3664
|
+
if (MODALITY_RE.test(body2) || LEAD_IN_RE.test(body2) || EMPHASIS_RE.test(body2)) continue;
|
|
3665
|
+
if (NEGATION_WORD_RE.test(body2)) continue;
|
|
3666
|
+
if (body2.split(/\s+/).length > MAX_WORDS) continue;
|
|
3667
|
+
const tokens = contentTokens(body2);
|
|
3391
3668
|
if (tokens.length < MIN_CONTENT_TOKENS) continue;
|
|
3392
3669
|
const statement = restatableStatementBelow(comment, sourceCode);
|
|
3393
3670
|
if (statement === null) continue;
|
|
3394
|
-
if (restatesStatementHead(
|
|
3671
|
+
if (restatesStatementHead(body2, statement)) continue;
|
|
3395
3672
|
const line = lines[comment.loc.start.line] ?? "";
|
|
3396
3673
|
if (!ACTION_STMT_RE.test(line)) continue;
|
|
3397
3674
|
if (labelsASiblingRun(comment)) continue;
|
|
@@ -3405,7 +3682,7 @@ var no_restated_comment_default = createRule({
|
|
|
3405
3682
|
});
|
|
3406
3683
|
|
|
3407
3684
|
// src/rules/no-restated-jsdoc.ts
|
|
3408
|
-
import { AST_NODE_TYPES as
|
|
3685
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES17 } from "@typescript-eslint/utils";
|
|
3409
3686
|
var MODELLED_TAGS = /* @__PURE__ */ new Set([
|
|
3410
3687
|
"arg",
|
|
3411
3688
|
"argument",
|
|
@@ -3417,7 +3694,7 @@ var MODELLED_TAGS = /* @__PURE__ */ new Set([
|
|
|
3417
3694
|
]);
|
|
3418
3695
|
var PARAM_TAGS = /* @__PURE__ */ new Set(["arg", "argument", "param"]);
|
|
3419
3696
|
var RETURN_TAGS = /* @__PURE__ */ new Set(["return", "returns"]);
|
|
3420
|
-
var
|
|
3697
|
+
var DIRECTIVE_RE4 = /^\s*(?:eslint\b|eslint-|@ts-|prettier|biome-|c8\b|v8\b|istanbul\b|@vite|webpack|@jsx|@jest-environment|@vitest-environment|#__)/i;
|
|
3421
3698
|
var STOPWORDS2 = new Set(
|
|
3422
3699
|
`the a an of to for in on with and or as at by is are was be been being
|
|
3423
3700
|
this that it its if whether when where which what will would can could should
|
|
@@ -3459,30 +3736,30 @@ function declarationNames(node) {
|
|
|
3459
3736
|
switch (node.type) {
|
|
3460
3737
|
// `export function f()` — the JSDoc sits above the `export`, so the token
|
|
3461
3738
|
// after it resolves to the wrapper, not to the thing being documented.
|
|
3462
|
-
case
|
|
3463
|
-
case
|
|
3739
|
+
case AST_NODE_TYPES17.ExportNamedDeclaration:
|
|
3740
|
+
case AST_NODE_TYPES17.ExportDefaultDeclaration:
|
|
3464
3741
|
return node.declaration == null ? null : declarationNames(node.declaration);
|
|
3465
|
-
case
|
|
3466
|
-
case
|
|
3742
|
+
case AST_NODE_TYPES17.FunctionDeclaration:
|
|
3743
|
+
case AST_NODE_TYPES17.TSDeclareFunction:
|
|
3467
3744
|
return node.id === null ? null : { name: node.id.name, params: paramNames(node.params) };
|
|
3468
|
-
case
|
|
3469
|
-
case
|
|
3470
|
-
case
|
|
3471
|
-
case
|
|
3745
|
+
case AST_NODE_TYPES17.ClassDeclaration:
|
|
3746
|
+
case AST_NODE_TYPES17.TSInterfaceDeclaration:
|
|
3747
|
+
case AST_NODE_TYPES17.TSTypeAliasDeclaration:
|
|
3748
|
+
case AST_NODE_TYPES17.TSEnumDeclaration:
|
|
3472
3749
|
return node.id === null ? null : { name: node.id.name, params: [] };
|
|
3473
|
-
case
|
|
3750
|
+
case AST_NODE_TYPES17.VariableDeclaration: {
|
|
3474
3751
|
const declarator = node.declarations[0];
|
|
3475
|
-
if (declarator === void 0 || declarator.id.type !==
|
|
3752
|
+
if (declarator === void 0 || declarator.id.type !== AST_NODE_TYPES17.Identifier) return null;
|
|
3476
3753
|
const init = declarator.init;
|
|
3477
|
-
const params = init != null && (init.type ===
|
|
3754
|
+
const params = init != null && (init.type === AST_NODE_TYPES17.ArrowFunctionExpression || init.type === AST_NODE_TYPES17.FunctionExpression) ? paramNames(init.params) : [];
|
|
3478
3755
|
return { name: declarator.id.name, params };
|
|
3479
3756
|
}
|
|
3480
|
-
case
|
|
3481
|
-
case
|
|
3482
|
-
case
|
|
3483
|
-
case
|
|
3484
|
-
if (node.key.type !==
|
|
3485
|
-
const params = node.type ===
|
|
3757
|
+
case AST_NODE_TYPES17.MethodDefinition:
|
|
3758
|
+
case AST_NODE_TYPES17.PropertyDefinition:
|
|
3759
|
+
case AST_NODE_TYPES17.TSMethodSignature:
|
|
3760
|
+
case AST_NODE_TYPES17.TSPropertySignature: {
|
|
3761
|
+
if (node.key.type !== AST_NODE_TYPES17.Identifier) return null;
|
|
3762
|
+
const params = node.type === AST_NODE_TYPES17.MethodDefinition ? paramNames(node.value.params) : node.type === AST_NODE_TYPES17.TSMethodSignature ? paramNames(node.params) : [];
|
|
3486
3763
|
return { name: node.key.name, params };
|
|
3487
3764
|
}
|
|
3488
3765
|
default:
|
|
@@ -3492,9 +3769,9 @@ function declarationNames(node) {
|
|
|
3492
3769
|
function paramNames(params) {
|
|
3493
3770
|
const names = [];
|
|
3494
3771
|
for (const param of params) {
|
|
3495
|
-
const target = param.type ===
|
|
3496
|
-
if (target.type ===
|
|
3497
|
-
else if (target.type ===
|
|
3772
|
+
const target = param.type === AST_NODE_TYPES17.AssignmentPattern ? param.left : param;
|
|
3773
|
+
if (target.type === AST_NODE_TYPES17.Identifier) names.push(target.name);
|
|
3774
|
+
else if (target.type === AST_NODE_TYPES17.TSParameterProperty) continue;
|
|
3498
3775
|
}
|
|
3499
3776
|
return names;
|
|
3500
3777
|
}
|
|
@@ -3528,7 +3805,7 @@ var no_restated_jsdoc_default = createRule({
|
|
|
3528
3805
|
for (const comment of sourceCode.getAllComments()) {
|
|
3529
3806
|
if (comment.type !== "Block" || !comment.value.startsWith("*")) continue;
|
|
3530
3807
|
const { description, tags } = parseJsDoc(comment.value);
|
|
3531
|
-
if (
|
|
3808
|
+
if (DIRECTIVE_RE4.test(description)) continue;
|
|
3532
3809
|
const tagNames = new Set(tags.map((tag) => tag.name));
|
|
3533
3810
|
if ([...tagNames].some((name) => !MODELLED_TAGS.has(name))) continue;
|
|
3534
3811
|
if (isProtected(description)) continue;
|
|
@@ -3536,7 +3813,7 @@ var no_restated_jsdoc_default = createRule({
|
|
|
3536
3813
|
if (token === null || token.loc.start.line !== comment.loc.end.line + 1) continue;
|
|
3537
3814
|
let node = sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
3538
3815
|
let declaration = null;
|
|
3539
|
-
while (node != null && node.type !==
|
|
3816
|
+
while (node != null && node.type !== AST_NODE_TYPES17.Program) {
|
|
3540
3817
|
declaration = declarationNames(node);
|
|
3541
3818
|
if (declaration !== null) break;
|
|
3542
3819
|
node = node.parent ?? null;
|
|
@@ -3995,12 +4272,12 @@ var no_select_star_default = createRule({
|
|
|
3995
4272
|
});
|
|
3996
4273
|
|
|
3997
4274
|
// src/rules/no-sentinel-return-on-catch.ts
|
|
3998
|
-
import { AST_NODE_TYPES as
|
|
4275
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES18 } from "@typescript-eslint/utils";
|
|
3999
4276
|
function sentinelKind(arg) {
|
|
4000
4277
|
if (arg === null) {
|
|
4001
4278
|
return null;
|
|
4002
4279
|
}
|
|
4003
|
-
if (arg.type ===
|
|
4280
|
+
if (arg.type === AST_NODE_TYPES18.Literal) {
|
|
4004
4281
|
if (arg.value === null) {
|
|
4005
4282
|
return "nullish";
|
|
4006
4283
|
}
|
|
@@ -4012,13 +4289,13 @@ function sentinelKind(arg) {
|
|
|
4012
4289
|
}
|
|
4013
4290
|
return null;
|
|
4014
4291
|
}
|
|
4015
|
-
if (arg.type ===
|
|
4292
|
+
if (arg.type === AST_NODE_TYPES18.Identifier && arg.name === "undefined") {
|
|
4016
4293
|
return "nullish";
|
|
4017
4294
|
}
|
|
4018
|
-
if (arg.type ===
|
|
4295
|
+
if (arg.type === AST_NODE_TYPES18.ArrayExpression) {
|
|
4019
4296
|
return "array";
|
|
4020
4297
|
}
|
|
4021
|
-
if (arg.type ===
|
|
4298
|
+
if (arg.type === AST_NODE_TYPES18.ObjectExpression) {
|
|
4022
4299
|
return "object";
|
|
4023
4300
|
}
|
|
4024
4301
|
return null;
|
|
@@ -4027,25 +4304,25 @@ function isSentinelArgument(arg) {
|
|
|
4027
4304
|
if (arg === null) {
|
|
4028
4305
|
return false;
|
|
4029
4306
|
}
|
|
4030
|
-
if (arg.type ===
|
|
4307
|
+
if (arg.type === AST_NODE_TYPES18.Literal && arg.value === null) {
|
|
4031
4308
|
return true;
|
|
4032
4309
|
}
|
|
4033
|
-
if (arg.type ===
|
|
4310
|
+
if (arg.type === AST_NODE_TYPES18.Literal && arg.value === false) {
|
|
4034
4311
|
return true;
|
|
4035
4312
|
}
|
|
4036
|
-
if (arg.type ===
|
|
4313
|
+
if (arg.type === AST_NODE_TYPES18.Identifier && arg.name === "undefined") {
|
|
4037
4314
|
return true;
|
|
4038
4315
|
}
|
|
4039
|
-
if (arg.type ===
|
|
4316
|
+
if (arg.type === AST_NODE_TYPES18.ArrayExpression && arg.elements.length === 0) {
|
|
4040
4317
|
return true;
|
|
4041
4318
|
}
|
|
4042
|
-
if (arg.type ===
|
|
4319
|
+
if (arg.type === AST_NODE_TYPES18.ObjectExpression && arg.properties.length === 0) {
|
|
4043
4320
|
return true;
|
|
4044
4321
|
}
|
|
4045
4322
|
return false;
|
|
4046
4323
|
}
|
|
4047
4324
|
function isFunctionNode(node) {
|
|
4048
|
-
return node.type ===
|
|
4325
|
+
return node.type === AST_NODE_TYPES18.FunctionDeclaration || node.type === AST_NODE_TYPES18.FunctionExpression || node.type === AST_NODE_TYPES18.ArrowFunctionExpression;
|
|
4049
4326
|
}
|
|
4050
4327
|
function isNode3(value) {
|
|
4051
4328
|
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
@@ -4085,24 +4362,24 @@ function walkWithinScope(node, visit) {
|
|
|
4085
4362
|
function containsThrow(node) {
|
|
4086
4363
|
return walkWithinScope(
|
|
4087
4364
|
node,
|
|
4088
|
-
(current) => current.type ===
|
|
4365
|
+
(current) => current.type === AST_NODE_TYPES18.ThrowStatement
|
|
4089
4366
|
);
|
|
4090
4367
|
}
|
|
4091
4368
|
function bindsName(param, name) {
|
|
4092
4369
|
switch (param.type) {
|
|
4093
|
-
case
|
|
4370
|
+
case AST_NODE_TYPES18.Identifier:
|
|
4094
4371
|
return param.name === name;
|
|
4095
|
-
case
|
|
4372
|
+
case AST_NODE_TYPES18.AssignmentPattern:
|
|
4096
4373
|
return bindsName(param.left, name);
|
|
4097
|
-
case
|
|
4374
|
+
case AST_NODE_TYPES18.RestElement:
|
|
4098
4375
|
return bindsName(param.argument, name);
|
|
4099
|
-
case
|
|
4376
|
+
case AST_NODE_TYPES18.ArrayPattern:
|
|
4100
4377
|
return param.elements.some(
|
|
4101
4378
|
(element) => element !== null && bindsName(element, name)
|
|
4102
4379
|
);
|
|
4103
|
-
case
|
|
4380
|
+
case AST_NODE_TYPES18.ObjectPattern:
|
|
4104
4381
|
return param.properties.some(
|
|
4105
|
-
(property) => property.type ===
|
|
4382
|
+
(property) => property.type === AST_NODE_TYPES18.RestElement ? bindsName(property.argument, name) : bindsName(property.value, name)
|
|
4106
4383
|
);
|
|
4107
4384
|
default:
|
|
4108
4385
|
return false;
|
|
@@ -4117,7 +4394,7 @@ function subtreeReadsName(node, name) {
|
|
|
4117
4394
|
if (found) {
|
|
4118
4395
|
return;
|
|
4119
4396
|
}
|
|
4120
|
-
if (current.type ===
|
|
4397
|
+
if (current.type === AST_NODE_TYPES18.Identifier && current.name === name) {
|
|
4121
4398
|
found = true;
|
|
4122
4399
|
return;
|
|
4123
4400
|
}
|
|
@@ -4128,10 +4405,10 @@ function subtreeReadsName(node, name) {
|
|
|
4128
4405
|
if (key === "parent") {
|
|
4129
4406
|
continue;
|
|
4130
4407
|
}
|
|
4131
|
-
if (key === "key" && current.type ===
|
|
4408
|
+
if (key === "key" && current.type === AST_NODE_TYPES18.Property && !current.computed) {
|
|
4132
4409
|
continue;
|
|
4133
4410
|
}
|
|
4134
|
-
if (key === "property" && current.type ===
|
|
4411
|
+
if (key === "property" && current.type === AST_NODE_TYPES18.MemberExpression && !current.computed) {
|
|
4135
4412
|
continue;
|
|
4136
4413
|
}
|
|
4137
4414
|
const value = current[key];
|
|
@@ -4164,10 +4441,10 @@ var SAFE_PARSE_CONSTRUCTORS = /* @__PURE__ */ new Set([
|
|
|
4164
4441
|
"URLPattern"
|
|
4165
4442
|
]);
|
|
4166
4443
|
function isParseShapedNode(node) {
|
|
4167
|
-
if (node.type ===
|
|
4444
|
+
if (node.type === AST_NODE_TYPES18.CallExpression && node.callee.type === AST_NODE_TYPES18.MemberExpression && !node.callee.computed && node.callee.property.type === AST_NODE_TYPES18.Identifier) {
|
|
4168
4445
|
return node.callee.property.name === "parse";
|
|
4169
4446
|
}
|
|
4170
|
-
if (node.type ===
|
|
4447
|
+
if (node.type === AST_NODE_TYPES18.NewExpression && node.callee.type === AST_NODE_TYPES18.Identifier) {
|
|
4171
4448
|
return SAFE_PARSE_CONSTRUCTORS.has(node.callee.name);
|
|
4172
4449
|
}
|
|
4173
4450
|
return false;
|
|
@@ -4178,10 +4455,10 @@ var BODY_DECODE_METHODS = /* @__PURE__ */ new Set([
|
|
|
4178
4455
|
"arrayBuffer"
|
|
4179
4456
|
]);
|
|
4180
4457
|
function isBodyDecodeNode(node) {
|
|
4181
|
-
return node.type ===
|
|
4458
|
+
return node.type === AST_NODE_TYPES18.CallExpression && node.callee.type === AST_NODE_TYPES18.MemberExpression && !node.callee.computed && node.callee.property.type === AST_NODE_TYPES18.Identifier && BODY_DECODE_METHODS.has(node.callee.property.name);
|
|
4182
4459
|
}
|
|
4183
4460
|
function returnsMatching(stmt, predicate) {
|
|
4184
|
-
return stmt.type ===
|
|
4461
|
+
return stmt.type === AST_NODE_TYPES18.ReturnStatement && stmt.argument !== null && walkWithinScope(stmt.argument, predicate);
|
|
4185
4462
|
}
|
|
4186
4463
|
function enclosingReturnTypeNode(node) {
|
|
4187
4464
|
let current = node.parent;
|
|
@@ -4199,11 +4476,11 @@ function enclosingFunctionName(node) {
|
|
|
4199
4476
|
let current = node.parent;
|
|
4200
4477
|
while (current !== void 0 && current !== null) {
|
|
4201
4478
|
if (isFunctionNode(current)) {
|
|
4202
|
-
if ("id" in current && isNode3(current.id) && current.id.type ===
|
|
4479
|
+
if ("id" in current && isNode3(current.id) && current.id.type === AST_NODE_TYPES18.Identifier) {
|
|
4203
4480
|
return current.id.name;
|
|
4204
4481
|
}
|
|
4205
4482
|
const parent = current.parent;
|
|
4206
|
-
if (parent?.type ===
|
|
4483
|
+
if (parent?.type === AST_NODE_TYPES18.VariableDeclarator && parent.id.type === AST_NODE_TYPES18.Identifier) {
|
|
4207
4484
|
return parent.id.name;
|
|
4208
4485
|
}
|
|
4209
4486
|
return null;
|
|
@@ -4224,10 +4501,10 @@ function isDeclaredBooleanPredicate(catchNode, kind) {
|
|
|
4224
4501
|
return false;
|
|
4225
4502
|
}
|
|
4226
4503
|
let declared = enclosingReturnTypeNode(catchNode);
|
|
4227
|
-
if (declared?.type ===
|
|
4504
|
+
if (declared?.type === AST_NODE_TYPES18.TSTypeReference && declared.typeName.type === AST_NODE_TYPES18.Identifier && declared.typeName.name === "Promise") {
|
|
4228
4505
|
declared = declared.typeArguments?.params[0] ?? null;
|
|
4229
4506
|
}
|
|
4230
|
-
return declared?.type ===
|
|
4507
|
+
return declared?.type === AST_NODE_TYPES18.TSBooleanKeyword;
|
|
4231
4508
|
}
|
|
4232
4509
|
function tryReturnsSafeParse(catchNode) {
|
|
4233
4510
|
const tryBlock = tryBlockOf(catchNode);
|
|
@@ -4243,7 +4520,7 @@ function tryReturnsSafeParse(catchNode) {
|
|
|
4243
4520
|
function enclosingFunctionBody(node) {
|
|
4244
4521
|
let current = node.parent;
|
|
4245
4522
|
while (current !== void 0 && current !== null) {
|
|
4246
|
-
if (isFunctionNode(current) && "body" in current && isNode3(current.body) && current.body.type ===
|
|
4523
|
+
if (isFunctionNode(current) && "body" in current && isNode3(current.body) && current.body.type === AST_NODE_TYPES18.BlockStatement) {
|
|
4247
4524
|
return current.body;
|
|
4248
4525
|
}
|
|
4249
4526
|
current = current.parent;
|
|
@@ -4256,7 +4533,7 @@ function functionReturnsSameSentinelKindElsewhere(catchNode, kind) {
|
|
|
4256
4533
|
return false;
|
|
4257
4534
|
}
|
|
4258
4535
|
return walkWithinScope(functionBody, (current) => {
|
|
4259
|
-
if (current.type !==
|
|
4536
|
+
if (current.type !== AST_NODE_TYPES18.ReturnStatement) {
|
|
4260
4537
|
return false;
|
|
4261
4538
|
}
|
|
4262
4539
|
if (isWithin(current, catchNode.body)) {
|
|
@@ -4275,13 +4552,13 @@ function returnedSentinelKinds(arg) {
|
|
|
4275
4552
|
kinds.add(direct);
|
|
4276
4553
|
return kinds;
|
|
4277
4554
|
}
|
|
4278
|
-
if (arg.type ===
|
|
4555
|
+
if (arg.type === AST_NODE_TYPES18.ConditionalExpression) {
|
|
4279
4556
|
for (const branch of [arg.consequent, arg.alternate]) {
|
|
4280
4557
|
for (const nested of returnedSentinelKinds(branch)) {
|
|
4281
4558
|
kinds.add(nested);
|
|
4282
4559
|
}
|
|
4283
4560
|
}
|
|
4284
|
-
} else if (arg.type ===
|
|
4561
|
+
} else if (arg.type === AST_NODE_TYPES18.LogicalExpression && (arg.operator === "??" || arg.operator === "||")) {
|
|
4285
4562
|
for (const nested of returnedSentinelKinds(arg.right)) {
|
|
4286
4563
|
kinds.add(nested);
|
|
4287
4564
|
}
|
|
@@ -4324,7 +4601,7 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
4324
4601
|
const matcher = createLogMatcher(loggingOptions);
|
|
4325
4602
|
function logsOrReportsError(catchBody, caughtName) {
|
|
4326
4603
|
return walkWithinScope(catchBody, (current) => {
|
|
4327
|
-
if (current.type !==
|
|
4604
|
+
if (current.type !== AST_NODE_TYPES18.CallExpression) {
|
|
4328
4605
|
return false;
|
|
4329
4606
|
}
|
|
4330
4607
|
if (matcher.isLoggingCall(current)) {
|
|
@@ -4336,12 +4613,12 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
4336
4613
|
}
|
|
4337
4614
|
return {
|
|
4338
4615
|
CatchClause(node) {
|
|
4339
|
-
const
|
|
4340
|
-
if (
|
|
4616
|
+
const body2 = node.body.body;
|
|
4617
|
+
if (body2.length === 0) {
|
|
4341
4618
|
return;
|
|
4342
4619
|
}
|
|
4343
|
-
const last =
|
|
4344
|
-
if (last === void 0 || last.type !==
|
|
4620
|
+
const last = body2[body2.length - 1];
|
|
4621
|
+
if (last === void 0 || last.type !== AST_NODE_TYPES18.ReturnStatement) {
|
|
4345
4622
|
return;
|
|
4346
4623
|
}
|
|
4347
4624
|
if (!isSentinelArgument(last.argument)) {
|
|
@@ -4350,7 +4627,7 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
4350
4627
|
if (containsThrow(node.body)) {
|
|
4351
4628
|
return;
|
|
4352
4629
|
}
|
|
4353
|
-
const caughtName = node.param?.type ===
|
|
4630
|
+
const caughtName = node.param?.type === AST_NODE_TYPES18.Identifier ? node.param.name : null;
|
|
4354
4631
|
if (logsOrReportsError(node.body, caughtName)) {
|
|
4355
4632
|
return;
|
|
4356
4633
|
}
|
|
@@ -4377,9 +4654,9 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
4377
4654
|
});
|
|
4378
4655
|
|
|
4379
4656
|
// src/rules/no-silent-promise-catch.ts
|
|
4380
|
-
import { AST_NODE_TYPES as
|
|
4657
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES19 } from "@typescript-eslint/utils";
|
|
4381
4658
|
function isBodyParseCall(node) {
|
|
4382
|
-
return node.type ===
|
|
4659
|
+
return node.type === AST_NODE_TYPES19.CallExpression && node.arguments.length === 0 && node.callee.type === AST_NODE_TYPES19.MemberExpression && !node.callee.computed && node.callee.property.type === AST_NODE_TYPES19.Identifier && (node.callee.property.name === "json" || node.callee.property.name === "text");
|
|
4383
4660
|
}
|
|
4384
4661
|
var TEARDOWN_METHODS = /* @__PURE__ */ new Set([
|
|
4385
4662
|
"cancel",
|
|
@@ -4394,37 +4671,37 @@ var TEARDOWN_METHODS = /* @__PURE__ */ new Set([
|
|
|
4394
4671
|
var DIRECTIVE_COMMENT_RE = /^\s*(eslint-|@ts-|prettier-ignore|biome-ignore|c8 |v8 |istanbul )/;
|
|
4395
4672
|
var isExplanatory = (comment) => !DIRECTIVE_COMMENT_RE.test(comment.value);
|
|
4396
4673
|
function isTeardownCall(node) {
|
|
4397
|
-
return node.type ===
|
|
4674
|
+
return node.type === AST_NODE_TYPES19.CallExpression && node.callee.type === AST_NODE_TYPES19.MemberExpression && !node.callee.computed && node.callee.property.type === AST_NODE_TYPES19.Identifier && TEARDOWN_METHODS.has(node.callee.property.name);
|
|
4398
4675
|
}
|
|
4399
4676
|
function isSilentExpression(node) {
|
|
4400
4677
|
switch (node.type) {
|
|
4401
|
-
case
|
|
4678
|
+
case AST_NODE_TYPES19.Literal:
|
|
4402
4679
|
return !("regex" in node);
|
|
4403
|
-
case
|
|
4680
|
+
case AST_NODE_TYPES19.Identifier:
|
|
4404
4681
|
return node.name === "undefined";
|
|
4405
|
-
case
|
|
4406
|
-
return node.operator === "void" && node.argument.type ===
|
|
4407
|
-
case
|
|
4682
|
+
case AST_NODE_TYPES19.UnaryExpression:
|
|
4683
|
+
return node.operator === "void" && node.argument.type === AST_NODE_TYPES19.Literal;
|
|
4684
|
+
case AST_NODE_TYPES19.ObjectExpression:
|
|
4408
4685
|
return node.properties.length === 0;
|
|
4409
|
-
case
|
|
4686
|
+
case AST_NODE_TYPES19.ArrayExpression:
|
|
4410
4687
|
return node.elements.length === 0;
|
|
4411
|
-
case
|
|
4688
|
+
case AST_NODE_TYPES19.TSAsExpression:
|
|
4412
4689
|
return isSilentExpression(node.expression);
|
|
4413
4690
|
default:
|
|
4414
4691
|
return false;
|
|
4415
4692
|
}
|
|
4416
4693
|
}
|
|
4417
4694
|
function isSilentHandler(handler) {
|
|
4418
|
-
const
|
|
4419
|
-
if (
|
|
4420
|
-
return isSilentExpression(
|
|
4695
|
+
const body2 = handler.body;
|
|
4696
|
+
if (body2.type !== AST_NODE_TYPES19.BlockStatement) {
|
|
4697
|
+
return isSilentExpression(body2);
|
|
4421
4698
|
}
|
|
4422
|
-
if (
|
|
4699
|
+
if (body2.body.length === 0) {
|
|
4423
4700
|
return true;
|
|
4424
4701
|
}
|
|
4425
|
-
if (
|
|
4426
|
-
const only =
|
|
4427
|
-
if (only !== void 0 && only.type ===
|
|
4702
|
+
if (body2.body.length === 1) {
|
|
4703
|
+
const only = body2.body[0];
|
|
4704
|
+
if (only !== void 0 && only.type === AST_NODE_TYPES19.ReturnStatement) {
|
|
4428
4705
|
return only.argument === null || isSilentExpression(only.argument);
|
|
4429
4706
|
}
|
|
4430
4707
|
}
|
|
@@ -4453,7 +4730,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
4453
4730
|
return true;
|
|
4454
4731
|
}
|
|
4455
4732
|
let statement = call;
|
|
4456
|
-
while (statement.parent !== void 0 && statement.parent !== null && !statement.type.endsWith("Statement") && statement.type !==
|
|
4733
|
+
while (statement.parent !== void 0 && statement.parent !== null && !statement.type.endsWith("Statement") && statement.type !== AST_NODE_TYPES19.VariableDeclaration) {
|
|
4457
4734
|
statement = statement.parent;
|
|
4458
4735
|
}
|
|
4459
4736
|
if (sourceCode.getCommentsBefore(statement).some(isExplanatory)) {
|
|
@@ -4465,7 +4742,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
4465
4742
|
};
|
|
4466
4743
|
return {
|
|
4467
4744
|
CallExpression(node) {
|
|
4468
|
-
if (node.callee.type !==
|
|
4745
|
+
if (node.callee.type !== AST_NODE_TYPES19.MemberExpression || node.callee.computed || node.callee.property.type !== AST_NODE_TYPES19.Identifier || node.callee.property.name !== "catch") {
|
|
4469
4746
|
return;
|
|
4470
4747
|
}
|
|
4471
4748
|
if (isBodyParseCall(node.callee.object)) {
|
|
@@ -4474,14 +4751,14 @@ var no_silent_promise_catch_default = createRule({
|
|
|
4474
4751
|
if (isTeardownCall(node.callee.object)) {
|
|
4475
4752
|
return;
|
|
4476
4753
|
}
|
|
4477
|
-
if (node.parent.type ===
|
|
4754
|
+
if (node.parent.type === AST_NODE_TYPES19.MemberExpression && node.parent.object === node) {
|
|
4478
4755
|
return;
|
|
4479
4756
|
}
|
|
4480
4757
|
if (node.arguments.length !== 1) {
|
|
4481
4758
|
return;
|
|
4482
4759
|
}
|
|
4483
4760
|
const handler = node.arguments[0];
|
|
4484
|
-
if (handler === void 0 || handler.type !==
|
|
4761
|
+
if (handler === void 0 || handler.type !== AST_NODE_TYPES19.ArrowFunctionExpression && handler.type !== AST_NODE_TYPES19.FunctionExpression) {
|
|
4485
4762
|
return;
|
|
4486
4763
|
}
|
|
4487
4764
|
if (hasExplanatoryComment(node, handler)) {
|
|
@@ -4496,7 +4773,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
4496
4773
|
});
|
|
4497
4774
|
|
|
4498
4775
|
// src/rules/no-sleep-in-test-body.ts
|
|
4499
|
-
import { AST_NODE_TYPES as
|
|
4776
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES20 } from "@typescript-eslint/utils";
|
|
4500
4777
|
var SLEEP_HELPERS = /* @__PURE__ */ new Set(["sleep", "delay", "wait", "pause"]);
|
|
4501
4778
|
var TEST_CALLERS2 = /* @__PURE__ */ new Set([
|
|
4502
4779
|
"it",
|
|
@@ -4505,34 +4782,34 @@ var TEST_CALLERS2 = /* @__PURE__ */ new Set([
|
|
|
4505
4782
|
"afterEach"
|
|
4506
4783
|
]);
|
|
4507
4784
|
var FUNCTION_TYPES4 = /* @__PURE__ */ new Set([
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4785
|
+
AST_NODE_TYPES20.FunctionDeclaration,
|
|
4786
|
+
AST_NODE_TYPES20.FunctionExpression,
|
|
4787
|
+
AST_NODE_TYPES20.ArrowFunctionExpression
|
|
4511
4788
|
]);
|
|
4512
4789
|
function isNonzeroNumericLiteral(node) {
|
|
4513
|
-
return node?.type ===
|
|
4790
|
+
return node?.type === AST_NODE_TYPES20.Literal && typeof node.value === "number" && node.value !== 0;
|
|
4514
4791
|
}
|
|
4515
4792
|
function isTimedSetTimeout(node) {
|
|
4516
|
-
return node.type ===
|
|
4793
|
+
return node.type === AST_NODE_TYPES20.CallExpression && node.callee.type === AST_NODE_TYPES20.Identifier && node.callee.name === "setTimeout" && node.arguments.length >= 2 && isNonzeroNumericLiteral(node.arguments[1]);
|
|
4517
4794
|
}
|
|
4518
4795
|
function isPromiseSleep(node) {
|
|
4519
|
-
if (node.callee.type !==
|
|
4796
|
+
if (node.callee.type !== AST_NODE_TYPES20.Identifier || node.callee.name !== "Promise") {
|
|
4520
4797
|
return false;
|
|
4521
4798
|
}
|
|
4522
4799
|
const executor = node.arguments[0];
|
|
4523
|
-
if (executor?.type !==
|
|
4800
|
+
if (executor?.type !== AST_NODE_TYPES20.ArrowFunctionExpression && executor?.type !== AST_NODE_TYPES20.FunctionExpression) {
|
|
4524
4801
|
return false;
|
|
4525
4802
|
}
|
|
4526
|
-
const
|
|
4527
|
-
if (
|
|
4528
|
-
return isTimedSetTimeout(
|
|
4803
|
+
const body2 = executor.body;
|
|
4804
|
+
if (body2.type !== AST_NODE_TYPES20.BlockStatement) {
|
|
4805
|
+
return isTimedSetTimeout(body2);
|
|
4529
4806
|
}
|
|
4530
|
-
return
|
|
4531
|
-
(stmt) => stmt.type ===
|
|
4807
|
+
return body2.body.some(
|
|
4808
|
+
(stmt) => stmt.type === AST_NODE_TYPES20.ExpressionStatement && isTimedSetTimeout(stmt.expression)
|
|
4532
4809
|
);
|
|
4533
4810
|
}
|
|
4534
4811
|
function isHelperSleep(node) {
|
|
4535
|
-
return node.callee.type ===
|
|
4812
|
+
return node.callee.type === AST_NODE_TYPES20.Identifier && SLEEP_HELPERS.has(node.callee.name) && node.arguments.length >= 1 && isNonzeroNumericLiteral(node.arguments[0]);
|
|
4536
4813
|
}
|
|
4537
4814
|
function nearestEnclosingFunction2(node) {
|
|
4538
4815
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
@@ -4540,7 +4817,7 @@ function nearestEnclosingFunction2(node) {
|
|
|
4540
4817
|
continue;
|
|
4541
4818
|
}
|
|
4542
4819
|
const grandparent = current.parent;
|
|
4543
|
-
const isPromiseExecutor = grandparent?.type ===
|
|
4820
|
+
const isPromiseExecutor = grandparent?.type === AST_NODE_TYPES20.NewExpression && isPromiseSleep(grandparent);
|
|
4544
4821
|
if (!isPromiseExecutor) {
|
|
4545
4822
|
return current;
|
|
4546
4823
|
}
|
|
@@ -4548,23 +4825,23 @@ function nearestEnclosingFunction2(node) {
|
|
|
4548
4825
|
return null;
|
|
4549
4826
|
}
|
|
4550
4827
|
function testCallerName2(callee) {
|
|
4551
|
-
if (callee.type ===
|
|
4828
|
+
if (callee.type === AST_NODE_TYPES20.Identifier) {
|
|
4552
4829
|
return callee.name;
|
|
4553
4830
|
}
|
|
4554
|
-
if (callee.type ===
|
|
4831
|
+
if (callee.type === AST_NODE_TYPES20.MemberExpression) {
|
|
4555
4832
|
return testCallerName2(callee.object);
|
|
4556
4833
|
}
|
|
4557
|
-
if (callee.type ===
|
|
4834
|
+
if (callee.type === AST_NODE_TYPES20.CallExpression) {
|
|
4558
4835
|
return testCallerName2(callee.callee);
|
|
4559
4836
|
}
|
|
4560
|
-
if (callee.type ===
|
|
4837
|
+
if (callee.type === AST_NODE_TYPES20.TaggedTemplateExpression) {
|
|
4561
4838
|
return testCallerName2(callee.tag);
|
|
4562
4839
|
}
|
|
4563
4840
|
return null;
|
|
4564
4841
|
}
|
|
4565
4842
|
function isTestBody2(fn) {
|
|
4566
4843
|
const call = fn.parent;
|
|
4567
|
-
if (call?.type !==
|
|
4844
|
+
if (call?.type !== AST_NODE_TYPES20.CallExpression || !call.arguments.some((argument) => argument === fn)) {
|
|
4568
4845
|
return false;
|
|
4569
4846
|
}
|
|
4570
4847
|
const name = testCallerName2(call.callee);
|
|
@@ -4610,7 +4887,7 @@ var no_sleep_in_test_body_default = createRule({
|
|
|
4610
4887
|
});
|
|
4611
4888
|
|
|
4612
4889
|
// src/rules/no-storage-in-stateless-modules.ts
|
|
4613
|
-
import { AST_NODE_TYPES as
|
|
4890
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES21 } from "@typescript-eslint/utils";
|
|
4614
4891
|
var DEFAULT_METHODS2 = [
|
|
4615
4892
|
"prepare",
|
|
4616
4893
|
"put",
|
|
@@ -4629,7 +4906,7 @@ function compile2(patterns) {
|
|
|
4629
4906
|
}
|
|
4630
4907
|
function storageMethodName(node, methods) {
|
|
4631
4908
|
const callee = node.callee;
|
|
4632
|
-
if (callee.type !==
|
|
4909
|
+
if (callee.type !== AST_NODE_TYPES21.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES21.Identifier) {
|
|
4633
4910
|
return null;
|
|
4634
4911
|
}
|
|
4635
4912
|
const name = callee.property.name;
|
|
@@ -4762,9 +5039,9 @@ function isDeclaredInsideLoop(variable, loop) {
|
|
|
4762
5039
|
if (def === void 0) {
|
|
4763
5040
|
return false;
|
|
4764
5041
|
}
|
|
4765
|
-
const
|
|
5042
|
+
const body2 = loop.body;
|
|
4766
5043
|
const [declStart, declEnd] = def.node.range;
|
|
4767
|
-
const [bodyStart, bodyEnd] =
|
|
5044
|
+
const [bodyStart, bodyEnd] = body2.range;
|
|
4768
5045
|
return declStart >= bodyStart && declEnd <= bodyEnd;
|
|
4769
5046
|
}
|
|
4770
5047
|
function enclosingLoop(node) {
|
|
@@ -4843,7 +5120,7 @@ var no_string_concat_in_loop_default = createRule({
|
|
|
4843
5120
|
});
|
|
4844
5121
|
|
|
4845
5122
|
// src/rules/no-tautological-expect.ts
|
|
4846
|
-
import { AST_NODE_TYPES as
|
|
5123
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES22 } from "@typescript-eslint/utils";
|
|
4847
5124
|
var EQUALITY_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
4848
5125
|
var ZERO_ARG_MATCHERS = /* @__PURE__ */ new Set([
|
|
4849
5126
|
"toBeDefined",
|
|
@@ -4857,17 +5134,17 @@ var OPERAND_PREVIEW_CHARS = 40;
|
|
|
4857
5134
|
var NUMERIC_SIGNS = /* @__PURE__ */ new Set(["-", "+"]);
|
|
4858
5135
|
function isLiteral(node) {
|
|
4859
5136
|
switch (node.type) {
|
|
4860
|
-
case
|
|
5137
|
+
case AST_NODE_TYPES22.Literal:
|
|
4861
5138
|
return true;
|
|
4862
|
-
case
|
|
5139
|
+
case AST_NODE_TYPES22.TemplateLiteral:
|
|
4863
5140
|
return node.expressions.length === 0;
|
|
4864
|
-
case
|
|
5141
|
+
case AST_NODE_TYPES22.UnaryExpression:
|
|
4865
5142
|
return NUMERIC_SIGNS.has(node.operator) && isLiteral(node.argument);
|
|
4866
|
-
case
|
|
5143
|
+
case AST_NODE_TYPES22.ArrayExpression:
|
|
4867
5144
|
return node.elements.every((element) => element !== null && isLiteral(element));
|
|
4868
|
-
case
|
|
5145
|
+
case AST_NODE_TYPES22.ObjectExpression:
|
|
4869
5146
|
return node.properties.every(
|
|
4870
|
-
(property) => property.type ===
|
|
5147
|
+
(property) => property.type === AST_NODE_TYPES22.Property && !property.computed && isLiteral(property.value)
|
|
4871
5148
|
);
|
|
4872
5149
|
default:
|
|
4873
5150
|
return false;
|
|
@@ -4875,7 +5152,7 @@ function isLiteral(node) {
|
|
|
4875
5152
|
}
|
|
4876
5153
|
function expectOperand(callee) {
|
|
4877
5154
|
const receiver = callee.object;
|
|
4878
|
-
if (receiver.type !==
|
|
5155
|
+
if (receiver.type !== AST_NODE_TYPES22.CallExpression || receiver.callee.type !== AST_NODE_TYPES22.Identifier || receiver.callee.name !== "expect" || receiver.arguments.length !== 1) {
|
|
4879
5156
|
return null;
|
|
4880
5157
|
}
|
|
4881
5158
|
return receiver.arguments[0] ?? null;
|
|
@@ -4905,10 +5182,10 @@ var no_tautological_expect_default = createRule({
|
|
|
4905
5182
|
return {
|
|
4906
5183
|
CallExpression(node) {
|
|
4907
5184
|
const callee = node.callee;
|
|
4908
|
-
if (callee.type !==
|
|
5185
|
+
if (callee.type !== AST_NODE_TYPES22.MemberExpression || callee.computed) {
|
|
4909
5186
|
return;
|
|
4910
5187
|
}
|
|
4911
|
-
if (callee.property.type !==
|
|
5188
|
+
if (callee.property.type !== AST_NODE_TYPES22.Identifier) {
|
|
4912
5189
|
return;
|
|
4913
5190
|
}
|
|
4914
5191
|
const matcher = callee.property.name;
|
|
@@ -4941,6 +5218,31 @@ var no_tautological_expect_default = createRule({
|
|
|
4941
5218
|
}
|
|
4942
5219
|
});
|
|
4943
5220
|
|
|
5221
|
+
// src/rules/no-typed-doc-sections.ts
|
|
5222
|
+
var no_typed_doc_sections_default = createRule({
|
|
5223
|
+
name: "no-typed-doc-sections",
|
|
5224
|
+
meta: {
|
|
5225
|
+
type: "suggestion",
|
|
5226
|
+
docs: { description: "Reject typed-signature repetition while preserving behavior that types cannot express." },
|
|
5227
|
+
schema: [],
|
|
5228
|
+
messages: {
|
|
5229
|
+
typedSection: "Typed JSDoc repeats parameters or returns \u2014 delete the tags and improve names or types instead."
|
|
5230
|
+
}
|
|
5231
|
+
},
|
|
5232
|
+
defaultOptions: [],
|
|
5233
|
+
create(context) {
|
|
5234
|
+
return {
|
|
5235
|
+
Program() {
|
|
5236
|
+
for (const group of proseGroups(context.filename, context.sourceCode, true)) {
|
|
5237
|
+
if (group.hasTypedTags && documentsTypedFunction(context.sourceCode, group.comment)) {
|
|
5238
|
+
context.report({ node: group.comment, messageId: "typedSection" });
|
|
5239
|
+
}
|
|
5240
|
+
}
|
|
5241
|
+
}
|
|
5242
|
+
};
|
|
5243
|
+
}
|
|
5244
|
+
});
|
|
5245
|
+
|
|
4944
5246
|
// src/rules/no-trailing-value-narration.ts
|
|
4945
5247
|
import "@typescript-eslint/utils";
|
|
4946
5248
|
var NUMBER_RE = /(?<![\w.])(\d+(?:\.\d+)?)(?![\w.])/g;
|
|
@@ -5004,21 +5306,22 @@ var STOPWORDS3 = /* @__PURE__ */ new Set([
|
|
|
5004
5306
|
"we",
|
|
5005
5307
|
"with"
|
|
5006
5308
|
]);
|
|
5007
|
-
var
|
|
5309
|
+
var DIRECTIVE_RE5 = /^\s*(?:eslint\b|eslint-|sarj-noqa\b|@ts-|prettier|biome-|c8\b|v8\b|istanbul\b|todo\b|fixme\b|hack\b|xxx\b)/i;
|
|
5008
5310
|
function numbersIn(text) {
|
|
5009
5311
|
return new Set(text.match(NUMBER_RE) ?? []);
|
|
5010
5312
|
}
|
|
5011
|
-
function narratesValue(
|
|
5012
|
-
if (
|
|
5313
|
+
function narratesValue(body2, code) {
|
|
5314
|
+
if (body2.length === 0 || DIRECTIVE_RE5.test(body2) || hasExternalReference(body2)) return false;
|
|
5013
5315
|
const codeNumbers = numbersIn(code);
|
|
5014
5316
|
if (codeNumbers.size === 0) return false;
|
|
5015
|
-
const words = (
|
|
5317
|
+
const words = (body2.match(WORD_RE3) ?? []).map((word) => word.toLowerCase());
|
|
5016
5318
|
if (words.length === 0) return false;
|
|
5017
|
-
const commentNumbers = numbersIn(
|
|
5319
|
+
const commentNumbers = numbersIn(body2);
|
|
5018
5320
|
if (commentNumbers.size === 0) return false;
|
|
5019
5321
|
for (const number of commentNumbers) {
|
|
5020
5322
|
if (!codeNumbers.has(number)) return false;
|
|
5021
5323
|
}
|
|
5324
|
+
if (!words.some((word) => UNIT_WORDS.has(word))) return false;
|
|
5022
5325
|
const identifiers = codeTokens(code);
|
|
5023
5326
|
const stems = /* @__PURE__ */ new Set();
|
|
5024
5327
|
for (const token of identifiers) stems.add(stem(token));
|
|
@@ -5031,7 +5334,7 @@ var no_trailing_value_narration_default = createRule({
|
|
|
5031
5334
|
meta: {
|
|
5032
5335
|
type: "suggestion",
|
|
5033
5336
|
docs: {
|
|
5034
|
-
description: "Flag a trailing comment
|
|
5337
|
+
description: "Flag a trailing comment that repeats the line's numeric value only to name its unit."
|
|
5035
5338
|
},
|
|
5036
5339
|
schema: [],
|
|
5037
5340
|
messages: {
|
|
@@ -5048,14 +5351,25 @@ var no_trailing_value_narration_default = createRule({
|
|
|
5048
5351
|
const before = sourceCode.getTokenBefore(comment, { includeComments: false });
|
|
5049
5352
|
return before !== null && before.loc.end.line === comment.loc.start.line;
|
|
5050
5353
|
}
|
|
5354
|
+
function isInsideBrackets(comment) {
|
|
5355
|
+
let node = sourceCode.getNodeByRangeIndex(comment.range[0]);
|
|
5356
|
+
while (node != null) {
|
|
5357
|
+
if (node.type === "BlockStatement" || node.type === "Program") return false;
|
|
5358
|
+
if (node.type === "ArrayExpression" || node.type === "CallExpression" || node.type === "NewExpression") {
|
|
5359
|
+
return true;
|
|
5360
|
+
}
|
|
5361
|
+
node = node.parent;
|
|
5362
|
+
}
|
|
5363
|
+
return false;
|
|
5364
|
+
}
|
|
5051
5365
|
return {
|
|
5052
5366
|
Program() {
|
|
5053
5367
|
for (const comment of sourceCode.getAllComments()) {
|
|
5054
|
-
if (!isTrailing(comment)) continue;
|
|
5368
|
+
if (!isTrailing(comment) || isInsideBrackets(comment)) continue;
|
|
5055
5369
|
const line = sourceCode.lines[comment.loc.start.line - 1] ?? "";
|
|
5056
5370
|
const code = line.slice(0, comment.loc.start.column);
|
|
5057
|
-
const
|
|
5058
|
-
if (narratesValue(
|
|
5371
|
+
const body2 = comment.value.replace(/^\*+/, "").replace(/\*+$/, "").trim();
|
|
5372
|
+
if (narratesValue(body2, code)) {
|
|
5059
5373
|
context.report({ node: comment, messageId: "narratesValue" });
|
|
5060
5374
|
}
|
|
5061
5375
|
}
|
|
@@ -5065,10 +5379,10 @@ var no_trailing_value_narration_default = createRule({
|
|
|
5065
5379
|
});
|
|
5066
5380
|
|
|
5067
5381
|
// src/rules/no-declaration-comment-wall.ts
|
|
5068
|
-
import { AST_NODE_TYPES as
|
|
5382
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES24 } from "@typescript-eslint/utils";
|
|
5069
5383
|
|
|
5070
5384
|
// src/rules/_comment-wall.ts
|
|
5071
|
-
import { AST_NODE_TYPES as
|
|
5385
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES23 } from "@typescript-eslint/utils";
|
|
5072
5386
|
var WALL_DEFAULTS = {
|
|
5073
5387
|
// Below three rows "a wall" is not a fair description of what the reader sees.
|
|
5074
5388
|
minCommentedMembers: 3,
|
|
@@ -5110,7 +5424,7 @@ var WALL_SCHEMA = {
|
|
|
5110
5424
|
}
|
|
5111
5425
|
}
|
|
5112
5426
|
};
|
|
5113
|
-
var
|
|
5427
|
+
var VALUE_TAG_RE2 = /@(?:deprecated|see|example|throws|remarks|since|default|defaultvalue|link|internal|alpha|beta|experimental|template|typeparam|inheritdoc|todo|fixme|override)\b/i;
|
|
5114
5428
|
var DEFAULT_RE = /^\s*@?default\b|\bdefaults? (?:to|:)/i;
|
|
5115
5429
|
var DIGIT_RE = /\d/;
|
|
5116
5430
|
var UNIT_WORD_RE = /\b(?:ms|milliseconds?|seconds?|minutes?|hours?|days?|weeks?|months?|years?|bytes?|kb|mb|gb|percent|pixels?|px|utc|epoch)\b/i;
|
|
@@ -5130,24 +5444,24 @@ var WALL_STOPWORDS = new Set(
|
|
|
5130
5444
|
);
|
|
5131
5445
|
var WORD_RE4 = /[A-Za-z][A-Za-z0-9]*/g;
|
|
5132
5446
|
var BARE_LABEL_RE = /^[A-Za-z][A-Za-z0-9]*$/;
|
|
5133
|
-
function labelStems(
|
|
5134
|
-
return splitIdentifier(
|
|
5447
|
+
function labelStems(body2) {
|
|
5448
|
+
return splitIdentifier(body2).map(stem).join(" ");
|
|
5135
5449
|
}
|
|
5136
5450
|
function commentBody(comment) {
|
|
5137
5451
|
return comment.value.replace(/^\*+/, "").replace(/^[ \t]*\*[ \t]?/gm, "").trim();
|
|
5138
5452
|
}
|
|
5139
|
-
function carriesValue(
|
|
5140
|
-
return isProtected(
|
|
5453
|
+
function carriesValue(body2) {
|
|
5454
|
+
return isProtected(body2) || VALUE_TAG_RE2.test(body2) || DEFAULT_RE.test(body2) || DIGIT_RE.test(body2) || UNIT_WORD_RE.test(body2) || EXAMPLE_RE.test(body2) || BANNER_RE.test(body2) || NON_ASCII_LETTER_RE2.test(body2);
|
|
5141
5455
|
}
|
|
5142
|
-
function isLabel(
|
|
5456
|
+
function isLabel(body2) {
|
|
5143
5457
|
let content = 0;
|
|
5144
|
-
for (const word of
|
|
5458
|
+
for (const word of body2.match(WORD_RE4) ?? []) {
|
|
5145
5459
|
if (word.length >= 2 && !WALL_STOPWORDS.has(word.toLowerCase())) content += 1;
|
|
5146
5460
|
}
|
|
5147
5461
|
return content <= 1;
|
|
5148
5462
|
}
|
|
5149
|
-
function isTagsOnly(
|
|
5150
|
-
return
|
|
5463
|
+
function isTagsOnly(body2) {
|
|
5464
|
+
return body2.length > 0 && body2.replace(TAG_TOKEN_RE, "").trim().length === 0;
|
|
5151
5465
|
}
|
|
5152
5466
|
function knownTokens(source) {
|
|
5153
5467
|
const tokens = /* @__PURE__ */ new Set();
|
|
@@ -5159,9 +5473,9 @@ function knownTokens(source) {
|
|
|
5159
5473
|
}
|
|
5160
5474
|
return tokens;
|
|
5161
5475
|
}
|
|
5162
|
-
function novelWords(
|
|
5476
|
+
function novelWords(body2, known) {
|
|
5163
5477
|
let novel = 0;
|
|
5164
|
-
for (const word of
|
|
5478
|
+
for (const word of body2.match(WORD_RE4) ?? []) {
|
|
5165
5479
|
const lower = word.toLowerCase();
|
|
5166
5480
|
if (lower.length < 2 || WALL_STOPWORDS.has(lower)) continue;
|
|
5167
5481
|
if (!known.has(lower) && !known.has(stem(lower))) novel += 1;
|
|
@@ -5172,21 +5486,21 @@ function isWall(members, commented, restated, options) {
|
|
|
5172
5486
|
return commented >= options.minCommentedMembers && commented / members >= options.minCommentedRatio && restated / commented >= options.minRestatedRatio;
|
|
5173
5487
|
}
|
|
5174
5488
|
var OPAQUE_VALUE_TYPES = /* @__PURE__ */ new Set([
|
|
5175
|
-
|
|
5176
|
-
|
|
5177
|
-
|
|
5178
|
-
|
|
5489
|
+
AST_NODE_TYPES23.FunctionExpression,
|
|
5490
|
+
AST_NODE_TYPES23.ArrowFunctionExpression,
|
|
5491
|
+
AST_NODE_TYPES23.ObjectExpression,
|
|
5492
|
+
AST_NODE_TYPES23.ArrayExpression
|
|
5179
5493
|
]);
|
|
5180
5494
|
function declarationRange(member) {
|
|
5181
|
-
const
|
|
5182
|
-
if (
|
|
5183
|
-
return [member.range[0],
|
|
5495
|
+
const body2 = bodyOf(member);
|
|
5496
|
+
if (body2 === void 0) return [member.range[0], member.range[1]];
|
|
5497
|
+
return [member.range[0], body2.range[0]];
|
|
5184
5498
|
}
|
|
5185
5499
|
function bodyOf(member) {
|
|
5186
|
-
if (member.type ===
|
|
5500
|
+
if (member.type === AST_NODE_TYPES23.MethodDefinition || member.type === AST_NODE_TYPES23.TSAbstractMethodDefinition) {
|
|
5187
5501
|
return member.value.body ?? void 0;
|
|
5188
5502
|
}
|
|
5189
|
-
if (member.type ===
|
|
5503
|
+
if (member.type === AST_NODE_TYPES23.Property || member.type === AST_NODE_TYPES23.PropertyDefinition) {
|
|
5190
5504
|
const value = member.value;
|
|
5191
5505
|
if (value !== null && OPAQUE_VALUE_TYPES.has(value.type)) return value;
|
|
5192
5506
|
}
|
|
@@ -5196,12 +5510,12 @@ function bodyOf(member) {
|
|
|
5196
5510
|
// src/rules/no-declaration-comment-wall.ts
|
|
5197
5511
|
function named(node) {
|
|
5198
5512
|
switch (node.type) {
|
|
5199
|
-
case
|
|
5513
|
+
case AST_NODE_TYPES24.TSEnumMember:
|
|
5200
5514
|
return { node, key: node.id };
|
|
5201
|
-
case
|
|
5202
|
-
case
|
|
5203
|
-
case
|
|
5204
|
-
case
|
|
5515
|
+
case AST_NODE_TYPES24.PropertyDefinition:
|
|
5516
|
+
case AST_NODE_TYPES24.TSAbstractPropertyDefinition:
|
|
5517
|
+
case AST_NODE_TYPES24.MethodDefinition:
|
|
5518
|
+
case AST_NODE_TYPES24.TSAbstractMethodDefinition:
|
|
5205
5519
|
return node.computed ? void 0 : { node, key: node.key };
|
|
5206
5520
|
default:
|
|
5207
5521
|
return void 0;
|
|
@@ -5245,9 +5559,9 @@ var no_declaration_comment_wall_default = createRule({
|
|
|
5245
5559
|
}
|
|
5246
5560
|
function isGroupLabel(comment, member, headsRun) {
|
|
5247
5561
|
if (comment.loc.end.line >= member.node.loc.start.line) return false;
|
|
5248
|
-
const
|
|
5249
|
-
if (!BARE_LABEL_RE.test(
|
|
5250
|
-
if (labelStems(
|
|
5562
|
+
const body2 = commentBody(comment);
|
|
5563
|
+
if (!BARE_LABEL_RE.test(body2)) return false;
|
|
5564
|
+
if (labelStems(body2) === labelStems(sourceCode.getText(member.key))) return false;
|
|
5251
5565
|
const lineAbove = sourceCode.lines[comment.loc.start.line - 2];
|
|
5252
5566
|
return headsRun || lineAbove !== void 0 && lineAbove.trim().length === 0;
|
|
5253
5567
|
}
|
|
@@ -5260,19 +5574,21 @@ var no_declaration_comment_wall_default = createRule({
|
|
|
5260
5574
|
}));
|
|
5261
5575
|
let commented = 0;
|
|
5262
5576
|
let restated = 0;
|
|
5577
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
5263
5578
|
for (const [index, { member, comment }] of documented.entries()) {
|
|
5264
|
-
if (comment === void 0) continue;
|
|
5579
|
+
if (comment === void 0 || claimed.has(comment)) continue;
|
|
5265
5580
|
const next = documented[index + 1];
|
|
5266
5581
|
if (isGroupLabel(comment, member, next !== void 0 && next.comment === void 0)) {
|
|
5267
5582
|
continue;
|
|
5268
5583
|
}
|
|
5584
|
+
claimed.add(comment);
|
|
5269
5585
|
commented += 1;
|
|
5270
|
-
const
|
|
5271
|
-
if (
|
|
5586
|
+
const body2 = commentBody(comment);
|
|
5587
|
+
if (body2.length === 0 || carriesValue(body2) || isTagsOnly(body2) || isLabel(body2)) {
|
|
5272
5588
|
continue;
|
|
5273
5589
|
}
|
|
5274
5590
|
const [start, end] = declarationRange(member.node);
|
|
5275
|
-
if (novelWords(
|
|
5591
|
+
if (novelWords(body2, knownTokens(sourceCode.text.slice(start, end))) <= options.maxNovelWords) {
|
|
5276
5592
|
restated += 1;
|
|
5277
5593
|
}
|
|
5278
5594
|
}
|
|
@@ -5299,7 +5615,7 @@ var no_declaration_comment_wall_default = createRule({
|
|
|
5299
5615
|
});
|
|
5300
5616
|
|
|
5301
5617
|
// src/rules/no-union-in-comment.ts
|
|
5302
|
-
import { AST_NODE_TYPES as
|
|
5618
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES25 } from "@typescript-eslint/utils";
|
|
5303
5619
|
var MAX_LITERAL_LENGTH = 28;
|
|
5304
5620
|
var LITERAL = String.raw`(?:'[^'\n]*'|"[^"\n]*"|\`[^\`\n]*\`)`;
|
|
5305
5621
|
var LEAD_IN_RE2 = /^(?:one of|either|values?|allowed(?: values)?|options?|possible(?: values)?)\s*[:=-]?\s*/i;
|
|
@@ -5318,14 +5634,14 @@ var STRING_BUILDERS = /* @__PURE__ */ new Set([
|
|
|
5318
5634
|
function isBareString(node) {
|
|
5319
5635
|
if (node === void 0) return false;
|
|
5320
5636
|
switch (node.type) {
|
|
5321
|
-
case
|
|
5637
|
+
case AST_NODE_TYPES25.TSStringKeyword:
|
|
5322
5638
|
return true;
|
|
5323
5639
|
// `string[]` holds members of the same closed set, one element at a time.
|
|
5324
|
-
case
|
|
5640
|
+
case AST_NODE_TYPES25.TSArrayType:
|
|
5325
5641
|
return isBareString(node.elementType);
|
|
5326
5642
|
// `string | null` is still an unconstrained string, and so is `string | "a"`
|
|
5327
5643
|
// — the checker collapses that one to `string`.
|
|
5328
|
-
case
|
|
5644
|
+
case AST_NODE_TYPES25.TSUnionType:
|
|
5329
5645
|
return node.types.some((member) => isBareString(member));
|
|
5330
5646
|
default:
|
|
5331
5647
|
return false;
|
|
@@ -5335,13 +5651,13 @@ function rootCallee(node) {
|
|
|
5335
5651
|
let current = node;
|
|
5336
5652
|
for (let hops = 0; current != null && hops < 12; hops += 1) {
|
|
5337
5653
|
switch (current.type) {
|
|
5338
|
-
case
|
|
5654
|
+
case AST_NODE_TYPES25.CallExpression:
|
|
5339
5655
|
current = current.callee;
|
|
5340
5656
|
break;
|
|
5341
|
-
case
|
|
5657
|
+
case AST_NODE_TYPES25.MemberExpression:
|
|
5342
5658
|
current = current.object;
|
|
5343
5659
|
break;
|
|
5344
|
-
case
|
|
5660
|
+
case AST_NODE_TYPES25.Identifier:
|
|
5345
5661
|
return current.name;
|
|
5346
5662
|
default:
|
|
5347
5663
|
return null;
|
|
@@ -5350,26 +5666,26 @@ function rootCallee(node) {
|
|
|
5350
5666
|
return null;
|
|
5351
5667
|
}
|
|
5352
5668
|
function nameOf(key) {
|
|
5353
|
-
if (key.type ===
|
|
5354
|
-
if (key.type ===
|
|
5669
|
+
if (key.type === AST_NODE_TYPES25.Identifier) return key.name;
|
|
5670
|
+
if (key.type === AST_NODE_TYPES25.Literal && typeof key.value === "string") return key.value;
|
|
5355
5671
|
return null;
|
|
5356
5672
|
}
|
|
5357
5673
|
function targetOf(node) {
|
|
5358
5674
|
switch (node.type) {
|
|
5359
|
-
case
|
|
5360
|
-
case
|
|
5675
|
+
case AST_NODE_TYPES25.TSPropertySignature:
|
|
5676
|
+
case AST_NODE_TYPES25.PropertyDefinition: {
|
|
5361
5677
|
const name = node.computed ? null : nameOf(node.key);
|
|
5362
5678
|
if (name === null || !isBareString(node.typeAnnotation?.typeAnnotation)) return null;
|
|
5363
5679
|
return { node, name };
|
|
5364
5680
|
}
|
|
5365
|
-
case
|
|
5681
|
+
case AST_NODE_TYPES25.Property: {
|
|
5366
5682
|
const name = node.computed || node.shorthand ? null : nameOf(node.key);
|
|
5367
5683
|
const callee = rootCallee(node.value);
|
|
5368
5684
|
if (name === null || callee === null || !STRING_BUILDERS.has(callee)) return null;
|
|
5369
5685
|
return { node, name };
|
|
5370
5686
|
}
|
|
5371
|
-
case
|
|
5372
|
-
if (node.id.type !==
|
|
5687
|
+
case AST_NODE_TYPES25.VariableDeclarator: {
|
|
5688
|
+
if (node.id.type !== AST_NODE_TYPES25.Identifier) return null;
|
|
5373
5689
|
if (!isBareString(node.id.typeAnnotation?.typeAnnotation)) return null;
|
|
5374
5690
|
return { node, name: node.id.name };
|
|
5375
5691
|
}
|
|
@@ -5377,8 +5693,8 @@ function targetOf(node) {
|
|
|
5377
5693
|
return null;
|
|
5378
5694
|
}
|
|
5379
5695
|
}
|
|
5380
|
-
function unionLiterals(
|
|
5381
|
-
const list =
|
|
5696
|
+
function unionLiterals(body2) {
|
|
5697
|
+
const list = body2.replace(LEAD_IN_RE2, "").trim();
|
|
5382
5698
|
if (!UNION_BODY_RE.test(list)) return null;
|
|
5383
5699
|
const literals = (list.match(LITERAL_G) ?? []).map((raw) => raw.slice(1, -1));
|
|
5384
5700
|
if (literals.some((literal) => literal.length === 0 || literal.length > MAX_LITERAL_LENGTH)) {
|
|
@@ -5418,7 +5734,7 @@ var no_union_in_comment_default = createRule({
|
|
|
5418
5734
|
if (after === null || after.loc.start.line !== comment.loc.end.line + 1) return null;
|
|
5419
5735
|
anchor = sourceCode.getNodeByRangeIndex(after.range[0]);
|
|
5420
5736
|
}
|
|
5421
|
-
for (let node = anchor; node != null && node.type !==
|
|
5737
|
+
for (let node = anchor; node != null && node.type !== AST_NODE_TYPES25.Program; node = node.parent) {
|
|
5422
5738
|
const target = targetOf(node);
|
|
5423
5739
|
if (target !== null) return target;
|
|
5424
5740
|
}
|
|
@@ -5427,9 +5743,9 @@ var no_union_in_comment_default = createRule({
|
|
|
5427
5743
|
return {
|
|
5428
5744
|
Program() {
|
|
5429
5745
|
for (const comment of sourceCode.getAllComments()) {
|
|
5430
|
-
const
|
|
5431
|
-
if (
|
|
5432
|
-
const literals = unionLiterals(
|
|
5746
|
+
const body2 = comment.value.replace(/^\*+/, "").replace(/\*+$/, "").trim();
|
|
5747
|
+
if (body2.length === 0) continue;
|
|
5748
|
+
const literals = unionLiterals(body2);
|
|
5433
5749
|
if (literals === null) continue;
|
|
5434
5750
|
const target = annotated(comment);
|
|
5435
5751
|
if (target === null) continue;
|
|
@@ -5447,9 +5763,9 @@ var no_union_in_comment_default = createRule({
|
|
|
5447
5763
|
});
|
|
5448
5764
|
|
|
5449
5765
|
// src/rules/no-type-member-comment-wall.ts
|
|
5450
|
-
import { AST_NODE_TYPES as
|
|
5766
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES26 } from "@typescript-eslint/utils";
|
|
5451
5767
|
function isNamedMember(node) {
|
|
5452
|
-
return (node.type ===
|
|
5768
|
+
return (node.type === AST_NODE_TYPES26.TSPropertySignature || node.type === AST_NODE_TYPES26.TSMethodSignature) && !node.computed;
|
|
5453
5769
|
}
|
|
5454
5770
|
var no_type_member_comment_wall_default = createRule({
|
|
5455
5771
|
name: "no-type-member-comment-wall",
|
|
@@ -5489,14 +5805,14 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5489
5805
|
}
|
|
5490
5806
|
function isGroupLabel(comment, member, headsRun) {
|
|
5491
5807
|
if (comment.loc.end.line >= member.loc.start.line) return false;
|
|
5492
|
-
const
|
|
5493
|
-
if (!BARE_LABEL_RE.test(
|
|
5494
|
-
if (labelStems(
|
|
5808
|
+
const body2 = commentBody(comment);
|
|
5809
|
+
if (!BARE_LABEL_RE.test(body2)) return false;
|
|
5810
|
+
if (labelStems(body2) === labelStems(sourceCode.getText(member.key))) return false;
|
|
5495
5811
|
const lineAbove = sourceCode.lines[comment.loc.start.line - 2];
|
|
5496
5812
|
return headsRun || lineAbove !== void 0 && lineAbove.trim().length === 0;
|
|
5497
5813
|
}
|
|
5498
5814
|
function check(node) {
|
|
5499
|
-
const members = node.type ===
|
|
5815
|
+
const members = node.type === AST_NODE_TYPES26.TSInterfaceBody ? node.body : node.members;
|
|
5500
5816
|
const named2 = members.filter(isNamedMember);
|
|
5501
5817
|
if (named2.length === 0) return;
|
|
5502
5818
|
const documented = named2.map((member) => ({ member, comment: documentingComment(member) }));
|
|
@@ -5511,9 +5827,9 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5511
5827
|
}
|
|
5512
5828
|
claimed.add(comment);
|
|
5513
5829
|
commented += 1;
|
|
5514
|
-
const
|
|
5515
|
-
if (
|
|
5516
|
-
if (novelWords(
|
|
5830
|
+
const body2 = commentBody(comment);
|
|
5831
|
+
if (body2.length === 0 || carriesValue(body2)) continue;
|
|
5832
|
+
if (novelWords(body2, knownTokens(sourceCode.getText(member))) <= options.maxNovelWords) {
|
|
5517
5833
|
restated += 1;
|
|
5518
5834
|
}
|
|
5519
5835
|
}
|
|
@@ -5536,7 +5852,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5536
5852
|
});
|
|
5537
5853
|
|
|
5538
5854
|
// src/rules/no-unnecessary-use-client.ts
|
|
5539
|
-
import { AST_NODE_TYPES as
|
|
5855
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES27 } from "@typescript-eslint/utils";
|
|
5540
5856
|
var HOOK_REGEX = /^use([A-Z]|$)/;
|
|
5541
5857
|
var EVENT_PROP_REGEX = /^on[A-Z]/;
|
|
5542
5858
|
var ERROR_FILE_REGEX = /\b(?:global-)?error\.[jt]sx?$/;
|
|
@@ -5562,13 +5878,13 @@ var CLIENT_ONLY_PACKAGES_REGEX = /^(?:@radix-ui\/|framer-motion|react-dom|react-
|
|
|
5562
5878
|
var isBareSpecifier = (source) => !source.startsWith(".") && !source.startsWith("/") && !source.startsWith("@/") && !source.startsWith("~");
|
|
5563
5879
|
var jsxRootName = (name) => {
|
|
5564
5880
|
let current = name;
|
|
5565
|
-
while (current.type ===
|
|
5881
|
+
while (current.type === AST_NODE_TYPES27.JSXMemberExpression) {
|
|
5566
5882
|
current = current.object;
|
|
5567
5883
|
}
|
|
5568
|
-
return current.type ===
|
|
5884
|
+
return current.type === AST_NODE_TYPES27.JSXIdentifier ? current.name : "";
|
|
5569
5885
|
};
|
|
5570
5886
|
var subtreeReadsImportedBinding = (node, imported) => {
|
|
5571
|
-
if (node.type ===
|
|
5887
|
+
if (node.type === AST_NODE_TYPES27.Identifier) {
|
|
5572
5888
|
return imported.has(node.name);
|
|
5573
5889
|
}
|
|
5574
5890
|
for (const key of Object.keys(node)) {
|
|
@@ -5583,16 +5899,16 @@ var subtreeReadsImportedBinding = (node, imported) => {
|
|
|
5583
5899
|
return false;
|
|
5584
5900
|
};
|
|
5585
5901
|
var isUseClientDirective = (node) => {
|
|
5586
|
-
return node.type ===
|
|
5902
|
+
return node.type === AST_NODE_TYPES27.ExpressionStatement && node.expression.type === AST_NODE_TYPES27.Literal && node.expression.value === "use client";
|
|
5587
5903
|
};
|
|
5588
5904
|
var isGlobalReference = (node, context) => {
|
|
5589
5905
|
if (!BROWSER_GLOBALS.has(node.name)) return false;
|
|
5590
5906
|
const parent = node.parent;
|
|
5591
5907
|
if (parent !== void 0) {
|
|
5592
|
-
if (parent.type ===
|
|
5908
|
+
if (parent.type === AST_NODE_TYPES27.MemberExpression && parent.property === node && !parent.computed) {
|
|
5593
5909
|
return false;
|
|
5594
5910
|
}
|
|
5595
|
-
if (parent.type ===
|
|
5911
|
+
if (parent.type === AST_NODE_TYPES27.Property && parent.key === node && !parent.computed) {
|
|
5596
5912
|
return false;
|
|
5597
5913
|
}
|
|
5598
5914
|
if (parent.type.startsWith("TS")) {
|
|
@@ -5632,13 +5948,13 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5632
5948
|
const importedLocals = /* @__PURE__ */ new Set();
|
|
5633
5949
|
const externalLocals = /* @__PURE__ */ new Set();
|
|
5634
5950
|
const markIfHookOrContext = (callee) => {
|
|
5635
|
-
if (callee.type ===
|
|
5951
|
+
if (callee.type === AST_NODE_TYPES27.Identifier) {
|
|
5636
5952
|
if (HOOK_REGEX.test(callee.name) || callee.name === "createContext") {
|
|
5637
5953
|
hasClientIndicator = true;
|
|
5638
5954
|
}
|
|
5639
5955
|
return;
|
|
5640
5956
|
}
|
|
5641
|
-
if (callee.type ===
|
|
5957
|
+
if (callee.type === AST_NODE_TYPES27.MemberExpression && callee.property.type === AST_NODE_TYPES27.Identifier) {
|
|
5642
5958
|
const name = callee.property.name;
|
|
5643
5959
|
if (HOOK_REGEX.test(name) || name === "createContext") {
|
|
5644
5960
|
hasClientIndicator = true;
|
|
@@ -5648,7 +5964,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5648
5964
|
return {
|
|
5649
5965
|
Program(node) {
|
|
5650
5966
|
for (const stmt of node.body) {
|
|
5651
|
-
if (stmt.type !==
|
|
5967
|
+
if (stmt.type !== AST_NODE_TYPES27.ExpressionStatement) break;
|
|
5652
5968
|
if (isUseClientDirective(stmt)) {
|
|
5653
5969
|
directiveNode = stmt;
|
|
5654
5970
|
break;
|
|
@@ -5661,7 +5977,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5661
5977
|
},
|
|
5662
5978
|
JSXAttribute(node) {
|
|
5663
5979
|
if (directiveNode === null) return;
|
|
5664
|
-
if (node.name.type ===
|
|
5980
|
+
if (node.name.type === AST_NODE_TYPES27.JSXIdentifier && EVENT_PROP_REGEX.test(node.name.name)) {
|
|
5665
5981
|
hasClientIndicator = true;
|
|
5666
5982
|
}
|
|
5667
5983
|
},
|
|
@@ -5729,17 +6045,17 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5729
6045
|
|
|
5730
6046
|
// src/rules/no-unsafe-mock-casting.ts
|
|
5731
6047
|
import "@typescript-eslint/utils";
|
|
5732
|
-
import { AST_NODE_TYPES as
|
|
6048
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES28 } from "@typescript-eslint/utils";
|
|
5733
6049
|
function isMockTypeReference(node) {
|
|
5734
|
-
if (node.type !==
|
|
6050
|
+
if (node.type !== AST_NODE_TYPES28.TSTypeReference) {
|
|
5735
6051
|
return false;
|
|
5736
6052
|
}
|
|
5737
6053
|
const typeName = node.typeName;
|
|
5738
|
-
if (typeName.type ===
|
|
6054
|
+
if (typeName.type === AST_NODE_TYPES28.Identifier) {
|
|
5739
6055
|
const name = typeName.name;
|
|
5740
6056
|
return name === "Mock" || name === "MockInstance" || name === "SpyInstance";
|
|
5741
6057
|
}
|
|
5742
|
-
if (typeName.type ===
|
|
6058
|
+
if (typeName.type === AST_NODE_TYPES28.TSQualifiedName) {
|
|
5743
6059
|
const rightName = typeName.right.name;
|
|
5744
6060
|
return rightName === "Mock" || rightName === "MockInstance" || rightName === "SpyInstance";
|
|
5745
6061
|
}
|
|
@@ -5777,7 +6093,7 @@ var no_unsafe_mock_casting_default = createRule({
|
|
|
5777
6093
|
// src/rules/no-zod-native-enum.ts
|
|
5778
6094
|
import {
|
|
5779
6095
|
ESLintUtils as ESLintUtils2,
|
|
5780
|
-
AST_NODE_TYPES as
|
|
6096
|
+
AST_NODE_TYPES as AST_NODE_TYPES29
|
|
5781
6097
|
} from "@typescript-eslint/utils";
|
|
5782
6098
|
import * as ts from "typescript";
|
|
5783
6099
|
var IGNORE_PATTERNS = [
|
|
@@ -5796,7 +6112,7 @@ function isZodModule(source) {
|
|
|
5796
6112
|
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
5797
6113
|
}
|
|
5798
6114
|
function unwrap2(node) {
|
|
5799
|
-
if (node.type ===
|
|
6115
|
+
if (node.type === AST_NODE_TYPES29.TSAsExpression || node.type === AST_NODE_TYPES29.TSSatisfiesExpression) {
|
|
5800
6116
|
return unwrap2(node.expression);
|
|
5801
6117
|
}
|
|
5802
6118
|
return node;
|
|
@@ -5804,14 +6120,14 @@ function unwrap2(node) {
|
|
|
5804
6120
|
function stringValueTexts(node, sourceCode) {
|
|
5805
6121
|
const texts = [];
|
|
5806
6122
|
for (const prop of node.properties) {
|
|
5807
|
-
if (prop.type !==
|
|
6123
|
+
if (prop.type !== AST_NODE_TYPES29.Property) {
|
|
5808
6124
|
return null;
|
|
5809
6125
|
}
|
|
5810
6126
|
if (prop.computed || prop.shorthand || prop.method || prop.kind !== "init") {
|
|
5811
6127
|
return null;
|
|
5812
6128
|
}
|
|
5813
6129
|
const value = prop.value;
|
|
5814
|
-
if (value.type !==
|
|
6130
|
+
if (value.type !== AST_NODE_TYPES29.Literal || typeof value.value !== "string") {
|
|
5815
6131
|
return null;
|
|
5816
6132
|
}
|
|
5817
6133
|
const text = sourceCode.getText(value);
|
|
@@ -5827,7 +6143,7 @@ function resolvesToLocalEnum(node, scope) {
|
|
|
5827
6143
|
const variable = current.variables.find((v) => v.name === node.name);
|
|
5828
6144
|
if (variable !== void 0) {
|
|
5829
6145
|
return variable.defs.some(
|
|
5830
|
-
(def) => def.node.type ===
|
|
6146
|
+
(def) => def.node.type === AST_NODE_TYPES29.TSEnumDeclaration
|
|
5831
6147
|
);
|
|
5832
6148
|
}
|
|
5833
6149
|
current = current.upper;
|
|
@@ -5879,25 +6195,25 @@ var no_zod_native_enum_default = createRule({
|
|
|
5879
6195
|
const zodImportedNames = /* @__PURE__ */ new Map();
|
|
5880
6196
|
function isZodMemberCall(node, api) {
|
|
5881
6197
|
const callee = node.callee;
|
|
5882
|
-
if (callee.type ===
|
|
6198
|
+
if (callee.type === AST_NODE_TYPES29.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES29.Identifier) {
|
|
5883
6199
|
return callee.property.name === api;
|
|
5884
6200
|
}
|
|
5885
|
-
if (callee.type ===
|
|
6201
|
+
if (callee.type === AST_NODE_TYPES29.Identifier) {
|
|
5886
6202
|
return zodImportedNames.get(callee.name) === api;
|
|
5887
6203
|
}
|
|
5888
6204
|
return false;
|
|
5889
6205
|
}
|
|
5890
6206
|
function buildFix(node) {
|
|
5891
6207
|
const callee = node.callee;
|
|
5892
|
-
if (callee.type !==
|
|
6208
|
+
if (callee.type !== AST_NODE_TYPES29.MemberExpression || callee.property.type !== AST_NODE_TYPES29.Identifier) {
|
|
5893
6209
|
return null;
|
|
5894
6210
|
}
|
|
5895
6211
|
const arg = node.arguments[0];
|
|
5896
|
-
if (arg === void 0 || node.arguments.length !== 1 || arg.type ===
|
|
6212
|
+
if (arg === void 0 || node.arguments.length !== 1 || arg.type === AST_NODE_TYPES29.SpreadElement) {
|
|
5897
6213
|
return null;
|
|
5898
6214
|
}
|
|
5899
6215
|
const inner = unwrap2(arg);
|
|
5900
|
-
if (inner.type !==
|
|
6216
|
+
if (inner.type !== AST_NODE_TYPES29.ObjectExpression) {
|
|
5901
6217
|
return null;
|
|
5902
6218
|
}
|
|
5903
6219
|
const values = stringValueTexts(inner, sourceCode);
|
|
@@ -5917,7 +6233,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
5917
6233
|
return;
|
|
5918
6234
|
}
|
|
5919
6235
|
for (const spec of node.specifiers) {
|
|
5920
|
-
if (spec.type ===
|
|
6236
|
+
if (spec.type === AST_NODE_TYPES29.ImportSpecifier && spec.imported.type === AST_NODE_TYPES29.Identifier) {
|
|
5921
6237
|
zodImportedNames.set(spec.local.name, spec.imported.name);
|
|
5922
6238
|
}
|
|
5923
6239
|
}
|
|
@@ -5936,7 +6252,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
5936
6252
|
return;
|
|
5937
6253
|
}
|
|
5938
6254
|
const arg = node.arguments[0];
|
|
5939
|
-
if (arg === void 0 || arg.type !==
|
|
6255
|
+
if (arg === void 0 || arg.type !== AST_NODE_TYPES29.Identifier) {
|
|
5940
6256
|
return;
|
|
5941
6257
|
}
|
|
5942
6258
|
const isEnum = resolvesToLocalEnum(arg, sourceCode.getScope(arg)) || services !== null && resolvesToImportedEnum(arg, services);
|
|
@@ -5953,7 +6269,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
5953
6269
|
});
|
|
5954
6270
|
|
|
5955
6271
|
// src/rules/prefer-constant-time-secret-compare.ts
|
|
5956
|
-
import { AST_NODE_TYPES as
|
|
6272
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES30 } from "@typescript-eslint/utils";
|
|
5957
6273
|
var EQUALITY_OPERATORS = /* @__PURE__ */ new Set(["===", "!==", "==", "!="]);
|
|
5958
6274
|
var SENTINEL_IDENTIFIERS = /* @__PURE__ */ new Set(["undefined", "NaN"]);
|
|
5959
6275
|
var SENTINEL_WORDS = /(^|_)(SENTINEL|EMPTY|NONE|NULL|UNSET|MISSING|PLACEHOLDER|DUMMY|FAKE|EXAMPLE)(_|$)/;
|
|
@@ -5966,36 +6282,36 @@ function isConstantReference(identifier) {
|
|
|
5966
6282
|
}
|
|
5967
6283
|
function isExcludedOperand(node) {
|
|
5968
6284
|
switch (node.type) {
|
|
5969
|
-
case
|
|
6285
|
+
case AST_NODE_TYPES30.Literal:
|
|
5970
6286
|
return true;
|
|
5971
|
-
case
|
|
6287
|
+
case AST_NODE_TYPES30.TemplateLiteral:
|
|
5972
6288
|
return node.expressions.length === 0;
|
|
5973
|
-
case
|
|
6289
|
+
case AST_NODE_TYPES30.Identifier:
|
|
5974
6290
|
return SENTINEL_IDENTIFIERS.has(node.name) || SENTINEL_PREFIX_RE.test(node.name) || isConstantReference(node.name);
|
|
5975
|
-
case
|
|
5976
|
-
return !node.computed && node.property.type ===
|
|
6291
|
+
case AST_NODE_TYPES30.MemberExpression:
|
|
6292
|
+
return !node.computed && node.property.type === AST_NODE_TYPES30.Identifier && (SENTINEL_PREFIX_RE.test(node.property.name) || isConstantReference(node.property.name));
|
|
5977
6293
|
default:
|
|
5978
6294
|
return false;
|
|
5979
6295
|
}
|
|
5980
6296
|
}
|
|
5981
6297
|
function operandName(node) {
|
|
5982
|
-
if (node.type ===
|
|
6298
|
+
if (node.type === AST_NODE_TYPES30.Identifier) {
|
|
5983
6299
|
return node.name;
|
|
5984
6300
|
}
|
|
5985
|
-
if (node.type ===
|
|
6301
|
+
if (node.type === AST_NODE_TYPES30.MemberExpression && !node.computed && node.property.type === AST_NODE_TYPES30.Identifier) {
|
|
5986
6302
|
return node.property.name;
|
|
5987
6303
|
}
|
|
5988
6304
|
return null;
|
|
5989
6305
|
}
|
|
5990
6306
|
function isSecretOperand(node) {
|
|
5991
|
-
if (node.type ===
|
|
6307
|
+
if (node.type === AST_NODE_TYPES30.TemplateLiteral) {
|
|
5992
6308
|
return node.expressions.some((expression) => isSecretOperand(expression));
|
|
5993
6309
|
}
|
|
5994
6310
|
const name = operandName(node);
|
|
5995
6311
|
return name !== null && isAuthSecretName(name);
|
|
5996
6312
|
}
|
|
5997
6313
|
function secretNameOf(node) {
|
|
5998
|
-
if (node.type ===
|
|
6314
|
+
if (node.type === AST_NODE_TYPES30.TemplateLiteral) {
|
|
5999
6315
|
for (const expression of node.expressions) {
|
|
6000
6316
|
const nested = secretNameOf(expression);
|
|
6001
6317
|
if (nested !== null) {
|
|
@@ -6048,7 +6364,7 @@ var prefer_constant_time_secret_compare_default = createRule({
|
|
|
6048
6364
|
|
|
6049
6365
|
// src/rules/prefer-discriminated-union.ts
|
|
6050
6366
|
import "@typescript-eslint/utils";
|
|
6051
|
-
import { AST_NODE_TYPES as
|
|
6367
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES31 } from "@typescript-eslint/utils";
|
|
6052
6368
|
var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
6053
6369
|
"success",
|
|
6054
6370
|
"ok",
|
|
@@ -6058,27 +6374,27 @@ var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
|
6058
6374
|
]);
|
|
6059
6375
|
var MIN_OPTIONAL_MEMBERS = 2;
|
|
6060
6376
|
function getMemberName(member) {
|
|
6061
|
-
if (member.type !==
|
|
6377
|
+
if (member.type !== AST_NODE_TYPES31.TSPropertySignature) {
|
|
6062
6378
|
return null;
|
|
6063
6379
|
}
|
|
6064
6380
|
const { key } = member;
|
|
6065
|
-
if (key.type ===
|
|
6381
|
+
if (key.type === AST_NODE_TYPES31.Identifier) {
|
|
6066
6382
|
return key.name;
|
|
6067
6383
|
}
|
|
6068
|
-
if (key.type ===
|
|
6384
|
+
if (key.type === AST_NODE_TYPES31.Literal && typeof key.value === "string") {
|
|
6069
6385
|
return key.value;
|
|
6070
6386
|
}
|
|
6071
6387
|
return null;
|
|
6072
6388
|
}
|
|
6073
6389
|
function isBooleanTyped(member) {
|
|
6074
|
-
return member.typeAnnotation?.typeAnnotation.type ===
|
|
6390
|
+
return member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES31.TSBooleanKeyword;
|
|
6075
6391
|
}
|
|
6076
6392
|
function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
6077
6393
|
let hasStatusBoolean = false;
|
|
6078
6394
|
let optionalCount = 0;
|
|
6079
6395
|
let optionalPayloadCount = 0;
|
|
6080
6396
|
for (const member of typeLiteral.members) {
|
|
6081
|
-
if (member.type !==
|
|
6397
|
+
if (member.type !== AST_NODE_TYPES31.TSPropertySignature) {
|
|
6082
6398
|
continue;
|
|
6083
6399
|
}
|
|
6084
6400
|
if (member.optional) {
|
|
@@ -6099,7 +6415,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
6099
6415
|
meta: {
|
|
6100
6416
|
type: "suggestion",
|
|
6101
6417
|
docs: {
|
|
6102
|
-
description: "Flag object types with a boolean status
|
|
6418
|
+
description: "Flag object types with a boolean status member and at least two optional members, including a non-boolean payload."
|
|
6103
6419
|
},
|
|
6104
6420
|
schema: [],
|
|
6105
6421
|
messages: {
|
|
@@ -6120,7 +6436,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
6120
6436
|
TSInterfaceDeclaration(node) {
|
|
6121
6437
|
const synthetic = {
|
|
6122
6438
|
...node.body,
|
|
6123
|
-
type:
|
|
6439
|
+
type: AST_NODE_TYPES31.TSTypeLiteral,
|
|
6124
6440
|
members: node.body.body
|
|
6125
6441
|
};
|
|
6126
6442
|
checkTypeLiteral(synthetic, node);
|
|
@@ -6133,7 +6449,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
6133
6449
|
});
|
|
6134
6450
|
|
|
6135
6451
|
// src/rules/prefer-module-level-constant.ts
|
|
6136
|
-
import { AST_NODE_TYPES as
|
|
6452
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES32 } from "@typescript-eslint/utils";
|
|
6137
6453
|
var DEFAULT_MIN_ELEMENTS = 3;
|
|
6138
6454
|
var MAX_LITERAL_DEPTH = 4;
|
|
6139
6455
|
var IGNORE_PATTERNS2 = [
|
|
@@ -6162,9 +6478,9 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
|
6162
6478
|
"assign"
|
|
6163
6479
|
]);
|
|
6164
6480
|
var FUNCTION_TYPES5 = /* @__PURE__ */ new Set([
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
6481
|
+
AST_NODE_TYPES32.FunctionDeclaration,
|
|
6482
|
+
AST_NODE_TYPES32.FunctionExpression,
|
|
6483
|
+
AST_NODE_TYPES32.ArrowFunctionExpression
|
|
6168
6484
|
]);
|
|
6169
6485
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
6170
6486
|
function isIgnoredFile2(filename, sourceText) {
|
|
@@ -6177,14 +6493,14 @@ function isLocalFixtureFile(filename) {
|
|
|
6177
6493
|
return isTestFile(filename) || isStoryFile(filename);
|
|
6178
6494
|
}
|
|
6179
6495
|
function unwrap3(node) {
|
|
6180
|
-
if (node.type ===
|
|
6496
|
+
if (node.type === AST_NODE_TYPES32.TSAsExpression || node.type === AST_NODE_TYPES32.TSSatisfiesExpression || node.type === AST_NODE_TYPES32.TSNonNullExpression) {
|
|
6181
6497
|
return unwrap3(node.expression);
|
|
6182
6498
|
}
|
|
6183
6499
|
return node;
|
|
6184
6500
|
}
|
|
6185
6501
|
var HAS_STATEFUL_FLAG_RE = /[gy]/;
|
|
6186
6502
|
function isRegexLiteral(node) {
|
|
6187
|
-
return node.type ===
|
|
6503
|
+
return node.type === AST_NODE_TYPES32.Literal && "regex" in node && node.regex !== void 0;
|
|
6188
6504
|
}
|
|
6189
6505
|
function isLiteralOnly(node, depth) {
|
|
6190
6506
|
if (depth > MAX_LITERAL_DEPTH) {
|
|
@@ -6192,29 +6508,29 @@ function isLiteralOnly(node, depth) {
|
|
|
6192
6508
|
}
|
|
6193
6509
|
const inner = unwrap3(node);
|
|
6194
6510
|
switch (inner.type) {
|
|
6195
|
-
case
|
|
6511
|
+
case AST_NODE_TYPES32.Literal: {
|
|
6196
6512
|
return !(isRegexLiteral(inner) && HAS_STATEFUL_FLAG_RE.test(inner.regex.flags));
|
|
6197
6513
|
}
|
|
6198
|
-
case
|
|
6514
|
+
case AST_NODE_TYPES32.TemplateLiteral: {
|
|
6199
6515
|
return inner.expressions.length === 0;
|
|
6200
6516
|
}
|
|
6201
|
-
case
|
|
6202
|
-
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type ===
|
|
6517
|
+
case AST_NODE_TYPES32.UnaryExpression: {
|
|
6518
|
+
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type === AST_NODE_TYPES32.Literal && typeof inner.argument.value === "number";
|
|
6203
6519
|
}
|
|
6204
|
-
case
|
|
6520
|
+
case AST_NODE_TYPES32.ArrayExpression: {
|
|
6205
6521
|
return inner.elements.every(
|
|
6206
|
-
(el) => el !== null && el.type !==
|
|
6522
|
+
(el) => el !== null && el.type !== AST_NODE_TYPES32.SpreadElement && isLiteralOnly(el, depth + 1)
|
|
6207
6523
|
);
|
|
6208
6524
|
}
|
|
6209
|
-
case
|
|
6525
|
+
case AST_NODE_TYPES32.ObjectExpression: {
|
|
6210
6526
|
return inner.properties.every((prop) => {
|
|
6211
|
-
if (prop.type !==
|
|
6527
|
+
if (prop.type !== AST_NODE_TYPES32.Property) {
|
|
6212
6528
|
return false;
|
|
6213
6529
|
}
|
|
6214
6530
|
if (prop.shorthand || prop.method || prop.kind !== "init") {
|
|
6215
6531
|
return false;
|
|
6216
6532
|
}
|
|
6217
|
-
if (prop.computed && prop.key.type !==
|
|
6533
|
+
if (prop.computed && prop.key.type !== AST_NODE_TYPES32.Literal) {
|
|
6218
6534
|
return false;
|
|
6219
6535
|
}
|
|
6220
6536
|
return isLiteralOnly(prop.value, depth + 1);
|
|
@@ -6227,7 +6543,7 @@ function isLiteralOnly(node, depth) {
|
|
|
6227
6543
|
}
|
|
6228
6544
|
function unwrapObjectFreeze(node) {
|
|
6229
6545
|
const inner = unwrap3(node);
|
|
6230
|
-
if (inner.type ===
|
|
6546
|
+
if (inner.type === AST_NODE_TYPES32.CallExpression && inner.callee.type === AST_NODE_TYPES32.MemberExpression && !inner.callee.computed && inner.callee.object.type === AST_NODE_TYPES32.Identifier && inner.callee.object.name === "Object" && inner.callee.property.type === AST_NODE_TYPES32.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== AST_NODE_TYPES32.SpreadElement) {
|
|
6231
6547
|
return unwrap3(inner.arguments[0]);
|
|
6232
6548
|
}
|
|
6233
6549
|
return inner;
|
|
@@ -6243,19 +6559,19 @@ function classify(init, checkRegex) {
|
|
|
6243
6559
|
}
|
|
6244
6560
|
return { kind: "regex", size: 1 };
|
|
6245
6561
|
}
|
|
6246
|
-
if (node.type ===
|
|
6562
|
+
if (node.type === AST_NODE_TYPES32.ArrayExpression) {
|
|
6247
6563
|
return isLiteralOnly(node, 0) ? { kind: "array", size: node.elements.length } : null;
|
|
6248
6564
|
}
|
|
6249
|
-
if (node.type ===
|
|
6565
|
+
if (node.type === AST_NODE_TYPES32.ObjectExpression) {
|
|
6250
6566
|
return isLiteralOnly(node, 0) ? { kind: "object", size: node.properties.length } : null;
|
|
6251
6567
|
}
|
|
6252
|
-
if (node.type ===
|
|
6568
|
+
if (node.type === AST_NODE_TYPES32.NewExpression && node.callee.type === AST_NODE_TYPES32.Identifier && COLLECTION_CONSTRUCTORS.has(node.callee.name)) {
|
|
6253
6569
|
const arg = node.arguments[0];
|
|
6254
|
-
if (node.arguments.length !== 1 || arg === void 0 || arg.type ===
|
|
6570
|
+
if (node.arguments.length !== 1 || arg === void 0 || arg.type === AST_NODE_TYPES32.SpreadElement) {
|
|
6255
6571
|
return null;
|
|
6256
6572
|
}
|
|
6257
6573
|
const entries = unwrap3(arg);
|
|
6258
|
-
if (entries.type !==
|
|
6574
|
+
if (entries.type !== AST_NODE_TYPES32.ArrayExpression) {
|
|
6259
6575
|
return null;
|
|
6260
6576
|
}
|
|
6261
6577
|
return isLiteralOnly(entries, 0) ? { kind: node.callee.name === "Set" ? "Set" : "Map", size: entries.elements.length } : null;
|
|
@@ -6284,10 +6600,10 @@ var NON_RETAINING_BUILTINS = /* @__PURE__ */ new Map(
|
|
|
6284
6600
|
);
|
|
6285
6601
|
function isNonRetainingBuiltinCall(node, argument) {
|
|
6286
6602
|
const callee = node.callee;
|
|
6287
|
-
if (callee.type ===
|
|
6603
|
+
if (callee.type === AST_NODE_TYPES32.Identifier && callee.name === "structuredClone") {
|
|
6288
6604
|
return true;
|
|
6289
6605
|
}
|
|
6290
|
-
if (callee.type !==
|
|
6606
|
+
if (callee.type !== AST_NODE_TYPES32.MemberExpression || callee.computed || callee.object.type !== AST_NODE_TYPES32.Identifier || callee.property.type !== AST_NODE_TYPES32.Identifier) {
|
|
6291
6607
|
return false;
|
|
6292
6608
|
}
|
|
6293
6609
|
const members = NON_RETAINING_BUILTINS.get(callee.object.name);
|
|
@@ -6301,38 +6617,38 @@ function isNonRetainingBuiltinCall(node, argument) {
|
|
|
6301
6617
|
}
|
|
6302
6618
|
function isSafeRead(identifier) {
|
|
6303
6619
|
const parent = identifier.parent;
|
|
6304
|
-
if (parent.type ===
|
|
6620
|
+
if (parent.type === AST_NODE_TYPES32.MemberExpression) {
|
|
6305
6621
|
if (parent.object !== identifier) {
|
|
6306
6622
|
return true;
|
|
6307
6623
|
}
|
|
6308
6624
|
const grandparent = parent.parent;
|
|
6309
|
-
if (grandparent.type ===
|
|
6625
|
+
if (grandparent.type === AST_NODE_TYPES32.AssignmentExpression && grandparent.left === parent) {
|
|
6310
6626
|
return false;
|
|
6311
6627
|
}
|
|
6312
|
-
if (grandparent.type ===
|
|
6628
|
+
if (grandparent.type === AST_NODE_TYPES32.UpdateExpression) {
|
|
6313
6629
|
return false;
|
|
6314
6630
|
}
|
|
6315
|
-
if (grandparent.type ===
|
|
6631
|
+
if (grandparent.type === AST_NODE_TYPES32.UnaryExpression && grandparent.operator === "delete") {
|
|
6316
6632
|
return false;
|
|
6317
6633
|
}
|
|
6318
|
-
if (!parent.computed && parent.property.type ===
|
|
6634
|
+
if (!parent.computed && parent.property.type === AST_NODE_TYPES32.Identifier && MUTATING_METHODS.has(parent.property.name) && grandparent.type === AST_NODE_TYPES32.CallExpression && grandparent.callee === parent) {
|
|
6319
6635
|
return false;
|
|
6320
6636
|
}
|
|
6321
6637
|
return true;
|
|
6322
6638
|
}
|
|
6323
|
-
if (parent.type ===
|
|
6639
|
+
if (parent.type === AST_NODE_TYPES32.ForOfStatement && parent.right === identifier) {
|
|
6324
6640
|
return true;
|
|
6325
6641
|
}
|
|
6326
|
-
if (parent.type ===
|
|
6642
|
+
if (parent.type === AST_NODE_TYPES32.SpreadElement) {
|
|
6327
6643
|
return true;
|
|
6328
6644
|
}
|
|
6329
|
-
if (parent.type ===
|
|
6645
|
+
if (parent.type === AST_NODE_TYPES32.BinaryExpression) {
|
|
6330
6646
|
return true;
|
|
6331
6647
|
}
|
|
6332
|
-
if (parent.type ===
|
|
6648
|
+
if (parent.type === AST_NODE_TYPES32.CallExpression && parent.arguments.includes(identifier) && isNonRetainingBuiltinCall(parent, identifier)) {
|
|
6333
6649
|
return true;
|
|
6334
6650
|
}
|
|
6335
|
-
if (parent.type ===
|
|
6651
|
+
if (parent.type === AST_NODE_TYPES32.UnaryExpression && parent.operator !== "delete") {
|
|
6336
6652
|
return true;
|
|
6337
6653
|
}
|
|
6338
6654
|
return false;
|
|
@@ -6387,7 +6703,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6387
6703
|
if (reference.isWrite()) {
|
|
6388
6704
|
return false;
|
|
6389
6705
|
}
|
|
6390
|
-
if (reference.identifier.type !==
|
|
6706
|
+
if (reference.identifier.type !== AST_NODE_TYPES32.Identifier) {
|
|
6391
6707
|
return false;
|
|
6392
6708
|
}
|
|
6393
6709
|
if (!isSafeRead(reference.identifier)) {
|
|
@@ -6399,10 +6715,10 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6399
6715
|
return {
|
|
6400
6716
|
VariableDeclarator(node) {
|
|
6401
6717
|
const declaration = node.parent;
|
|
6402
|
-
if (declaration.type !==
|
|
6718
|
+
if (declaration.type !== AST_NODE_TYPES32.VariableDeclaration || declaration.kind !== "const" || declaration.declare === true) {
|
|
6403
6719
|
return;
|
|
6404
6720
|
}
|
|
6405
|
-
if (node.id.type !==
|
|
6721
|
+
if (node.id.type !== AST_NODE_TYPES32.Identifier || node.init === null) {
|
|
6406
6722
|
return;
|
|
6407
6723
|
}
|
|
6408
6724
|
if (enclosingFunction2(node) === null) {
|
|
@@ -6429,7 +6745,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6429
6745
|
});
|
|
6430
6746
|
|
|
6431
6747
|
// src/rules/prefer-module-level-schema.ts
|
|
6432
|
-
import { AST_NODE_TYPES as
|
|
6748
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES33 } from "@typescript-eslint/utils";
|
|
6433
6749
|
|
|
6434
6750
|
// src/rules/_zod.ts
|
|
6435
6751
|
var ZOD_PREFIX_RE = /^Z[A-Z]/;
|
|
@@ -6495,9 +6811,9 @@ var I18N_RECEIVER_NAMES = /* @__PURE__ */ new Set([
|
|
|
6495
6811
|
"intl"
|
|
6496
6812
|
]);
|
|
6497
6813
|
var FUNCTION_TYPES6 = /* @__PURE__ */ new Set([
|
|
6498
|
-
|
|
6499
|
-
|
|
6500
|
-
|
|
6814
|
+
AST_NODE_TYPES33.ArrowFunctionExpression,
|
|
6815
|
+
AST_NODE_TYPES33.FunctionDeclaration,
|
|
6816
|
+
AST_NODE_TYPES33.FunctionExpression
|
|
6501
6817
|
]);
|
|
6502
6818
|
function schemaExpression(node) {
|
|
6503
6819
|
let current = node;
|
|
@@ -6506,10 +6822,10 @@ function schemaExpression(node) {
|
|
|
6506
6822
|
if (parent === void 0) {
|
|
6507
6823
|
return current;
|
|
6508
6824
|
}
|
|
6509
|
-
if (parent.type ===
|
|
6825
|
+
if (parent.type === AST_NODE_TYPES33.MemberExpression && parent.object === current && !parent.computed && parent.property.type === AST_NODE_TYPES33.Identifier && TERMINAL_METHODS.has(parent.property.name)) {
|
|
6510
6826
|
return current;
|
|
6511
6827
|
}
|
|
6512
|
-
if (parent.type ===
|
|
6828
|
+
if (parent.type === AST_NODE_TYPES33.MemberExpression && parent.object === current || parent.type === AST_NODE_TYPES33.CallExpression && parent.callee === current || parent.type === AST_NODE_TYPES33.TSAsExpression && parent.expression === current || parent.type === AST_NODE_TYPES33.TSNonNullExpression && parent.expression === current) {
|
|
6513
6829
|
current = parent;
|
|
6514
6830
|
continue;
|
|
6515
6831
|
}
|
|
@@ -6560,22 +6876,22 @@ function subtreeSome(root, predicate) {
|
|
|
6560
6876
|
function readsReceiver(node) {
|
|
6561
6877
|
return subtreeSome(
|
|
6562
6878
|
node,
|
|
6563
|
-
(inner) => inner.type ===
|
|
6879
|
+
(inner) => inner.type === AST_NODE_TYPES33.ThisExpression || inner.type === AST_NODE_TYPES33.Super || inner.type === AST_NODE_TYPES33.Identifier && inner.name === "arguments"
|
|
6564
6880
|
);
|
|
6565
6881
|
}
|
|
6566
6882
|
function buildsLocalizedText(node) {
|
|
6567
6883
|
return subtreeSome(node, (inner) => {
|
|
6568
|
-
if (inner.type ===
|
|
6884
|
+
if (inner.type === AST_NODE_TYPES33.TaggedTemplateExpression) {
|
|
6569
6885
|
return true;
|
|
6570
6886
|
}
|
|
6571
|
-
if (inner.type !==
|
|
6887
|
+
if (inner.type !== AST_NODE_TYPES33.CallExpression) {
|
|
6572
6888
|
return false;
|
|
6573
6889
|
}
|
|
6574
6890
|
const { callee } = inner;
|
|
6575
|
-
if (callee.type ===
|
|
6891
|
+
if (callee.type === AST_NODE_TYPES33.Identifier) {
|
|
6576
6892
|
return I18N_CALLEE_NAMES.has(callee.name);
|
|
6577
6893
|
}
|
|
6578
|
-
return callee.type ===
|
|
6894
|
+
return callee.type === AST_NODE_TYPES33.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES33.Identifier && I18N_RECEIVER_NAMES.has(callee.object.name);
|
|
6579
6895
|
});
|
|
6580
6896
|
}
|
|
6581
6897
|
function collectReferences(scope, out) {
|
|
@@ -6632,15 +6948,15 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6632
6948
|
}
|
|
6633
6949
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
6634
6950
|
function isZodCall(node) {
|
|
6635
|
-
return node.type ===
|
|
6951
|
+
return node.type === AST_NODE_TYPES33.CallExpression && node.callee.type === AST_NODE_TYPES33.MemberExpression && !node.callee.computed && node.callee.object.type === AST_NODE_TYPES33.Identifier && zodNamespaces.has(node.callee.object.name);
|
|
6636
6952
|
}
|
|
6637
6953
|
function isCovered(node) {
|
|
6638
6954
|
let current = node.parent ?? void 0;
|
|
6639
6955
|
while (current !== void 0) {
|
|
6640
|
-
if (current !== node && isZodCall(current) && current.callee.type ===
|
|
6956
|
+
if (current !== node && isZodCall(current) && current.callee.type === AST_NODE_TYPES33.MemberExpression && current.callee.property.type === AST_NODE_TYPES33.Identifier && factories.has(current.callee.property.name)) {
|
|
6641
6957
|
return true;
|
|
6642
6958
|
}
|
|
6643
|
-
if (current.type ===
|
|
6959
|
+
if (current.type === AST_NODE_TYPES33.CallExpression && (current.callee.type === AST_NODE_TYPES33.Identifier && MEMO_CALLEES.has(current.callee.name) || current.callee.type === AST_NODE_TYPES33.MemberExpression && !current.callee.computed && current.callee.property.type === AST_NODE_TYPES33.Identifier && MEMO_CALLEES.has(current.callee.property.name))) {
|
|
6644
6960
|
return true;
|
|
6645
6961
|
}
|
|
6646
6962
|
current = current.parent ?? void 0;
|
|
@@ -6655,11 +6971,11 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6655
6971
|
if (parent === void 0) {
|
|
6656
6972
|
return confirmed;
|
|
6657
6973
|
}
|
|
6658
|
-
if (parent.type ===
|
|
6974
|
+
if (parent.type === AST_NODE_TYPES33.Property && parent.value === current || parent.type === AST_NODE_TYPES33.ObjectExpression || parent.type === AST_NODE_TYPES33.ArrayExpression) {
|
|
6659
6975
|
current = parent;
|
|
6660
6976
|
continue;
|
|
6661
6977
|
}
|
|
6662
|
-
if (parent.type ===
|
|
6978
|
+
if (parent.type === AST_NODE_TYPES33.CallExpression && parent.arguments.includes(current) && isSchemaComposition(parent)) {
|
|
6663
6979
|
current = schemaExpression(parent);
|
|
6664
6980
|
confirmed = current;
|
|
6665
6981
|
continue;
|
|
@@ -6669,7 +6985,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6669
6985
|
}
|
|
6670
6986
|
function isSchemaComposition(node) {
|
|
6671
6987
|
const { callee } = node;
|
|
6672
|
-
const isCombinator = callee.type ===
|
|
6988
|
+
const isCombinator = callee.type === AST_NODE_TYPES33.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES33.Identifier && ZOD_COMBINATOR_METHODS.has(callee.property.name);
|
|
6673
6989
|
return isCombinator || isZodCall(node);
|
|
6674
6990
|
}
|
|
6675
6991
|
function closesOverNothing(node, enclosing) {
|
|
@@ -6703,13 +7019,13 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6703
7019
|
}
|
|
6704
7020
|
function ownerName(enclosing) {
|
|
6705
7021
|
const parent = enclosing.parent ?? void 0;
|
|
6706
|
-
if (enclosing.type ===
|
|
7022
|
+
if (enclosing.type === AST_NODE_TYPES33.FunctionDeclaration && enclosing.id !== null) {
|
|
6707
7023
|
return enclosing.id.name;
|
|
6708
7024
|
}
|
|
6709
|
-
if (parent !== void 0 && parent.type ===
|
|
7025
|
+
if (parent !== void 0 && parent.type === AST_NODE_TYPES33.VariableDeclarator && parent.id.type === AST_NODE_TYPES33.Identifier) {
|
|
6710
7026
|
return parent.id.name;
|
|
6711
7027
|
}
|
|
6712
|
-
if (parent !== void 0 && (parent.type ===
|
|
7028
|
+
if (parent !== void 0 && (parent.type === AST_NODE_TYPES33.MethodDefinition || parent.type === AST_NODE_TYPES33.Property) && parent.key.type === AST_NODE_TYPES33.Identifier) {
|
|
6713
7029
|
return parent.key.name;
|
|
6714
7030
|
}
|
|
6715
7031
|
return "this function";
|
|
@@ -6720,7 +7036,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6720
7036
|
return;
|
|
6721
7037
|
}
|
|
6722
7038
|
for (const specifier of node.specifiers) {
|
|
6723
|
-
if (specifier.type ===
|
|
7039
|
+
if (specifier.type === AST_NODE_TYPES33.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES33.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES33.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES33.Identifier && specifier.imported.name === "z") {
|
|
6724
7040
|
zodNamespaces.add(specifier.local.name);
|
|
6725
7041
|
}
|
|
6726
7042
|
}
|
|
@@ -6730,7 +7046,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6730
7046
|
return;
|
|
6731
7047
|
}
|
|
6732
7048
|
const callee = node.callee;
|
|
6733
|
-
if (callee.property.type !==
|
|
7049
|
+
if (callee.property.type !== AST_NODE_TYPES33.Identifier) {
|
|
6734
7050
|
return;
|
|
6735
7051
|
}
|
|
6736
7052
|
const factory = callee.property.name;
|
|
@@ -6745,7 +7061,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6745
7061
|
return;
|
|
6746
7062
|
}
|
|
6747
7063
|
const shape = node.arguments[0];
|
|
6748
|
-
if (shape !== void 0 && shape.type ===
|
|
7064
|
+
if (shape !== void 0 && shape.type === AST_NODE_TYPES33.ObjectExpression && shape.properties.length < minProperties) {
|
|
6749
7065
|
return;
|
|
6750
7066
|
}
|
|
6751
7067
|
const expression = schemaExpression(node);
|
|
@@ -6773,20 +7089,20 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6773
7089
|
});
|
|
6774
7090
|
|
|
6775
7091
|
// src/rules/prefer-non-nullable-collection.ts
|
|
6776
|
-
import { AST_NODE_TYPES as
|
|
7092
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES34 } from "@typescript-eslint/utils";
|
|
6777
7093
|
var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
6778
7094
|
function propertyName(node) {
|
|
6779
7095
|
const key = node.key;
|
|
6780
|
-
if (key.type ===
|
|
6781
|
-
if (key.type ===
|
|
7096
|
+
if (key.type === AST_NODE_TYPES34.Identifier) return key.name;
|
|
7097
|
+
if (key.type === AST_NODE_TYPES34.Literal) return String(key.value);
|
|
6782
7098
|
return "collection";
|
|
6783
7099
|
}
|
|
6784
7100
|
function isArrayType(node) {
|
|
6785
|
-
if (node.type ===
|
|
6786
|
-
return node.type ===
|
|
7101
|
+
if (node.type === AST_NODE_TYPES34.TSArrayType) return true;
|
|
7102
|
+
return node.type === AST_NODE_TYPES34.TSTypeReference && node.typeName.type === AST_NODE_TYPES34.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
6787
7103
|
}
|
|
6788
7104
|
function isNullishType(node) {
|
|
6789
|
-
return node.type ===
|
|
7105
|
+
return node.type === AST_NODE_TYPES34.TSNullKeyword || node.type === AST_NODE_TYPES34.TSUndefinedKeyword;
|
|
6790
7106
|
}
|
|
6791
7107
|
function isNullableArrayOnly(node) {
|
|
6792
7108
|
const values = node.types.filter((member) => !isNullishType(member));
|
|
@@ -6797,7 +7113,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
6797
7113
|
meta: {
|
|
6798
7114
|
type: "suggestion",
|
|
6799
7115
|
docs: {
|
|
6800
|
-
description: "Require
|
|
7116
|
+
description: "Require declared data-shape properties and direct aliases to use non-null arrays instead of explicit nullish unions."
|
|
6801
7117
|
},
|
|
6802
7118
|
schema: [],
|
|
6803
7119
|
messages: {
|
|
@@ -6813,7 +7129,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
6813
7129
|
function checkOptionalProperty(node) {
|
|
6814
7130
|
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
6815
7131
|
if (annotation === void 0) return;
|
|
6816
|
-
if (annotation.type !==
|
|
7132
|
+
if (annotation.type !== AST_NODE_TYPES34.TSUnionType || !isNullableArrayOnly(annotation)) {
|
|
6817
7133
|
return;
|
|
6818
7134
|
}
|
|
6819
7135
|
context.report({
|
|
@@ -6826,7 +7142,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
6826
7142
|
TSPropertySignature: checkOptionalProperty,
|
|
6827
7143
|
PropertyDefinition: checkOptionalProperty,
|
|
6828
7144
|
TSTypeAliasDeclaration(node) {
|
|
6829
|
-
if (node.typeAnnotation.type !==
|
|
7145
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES34.TSUnionType) return;
|
|
6830
7146
|
if (!isNullableArrayOnly(node.typeAnnotation)) return;
|
|
6831
7147
|
context.report({
|
|
6832
7148
|
node,
|
|
@@ -6839,13 +7155,13 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
6839
7155
|
});
|
|
6840
7156
|
|
|
6841
7157
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
6842
|
-
import { AST_NODE_TYPES as
|
|
7158
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES35 } from "@typescript-eslint/utils";
|
|
6843
7159
|
var unwrap4 = (node) => {
|
|
6844
7160
|
let current = node;
|
|
6845
7161
|
while (current !== null && current !== void 0) {
|
|
6846
|
-
if (current.type ===
|
|
7162
|
+
if (current.type === AST_NODE_TYPES35.TSAsExpression || current.type === AST_NODE_TYPES35.TSTypeAssertion || current.type === AST_NODE_TYPES35.TSNonNullExpression || current.type === AST_NODE_TYPES35.TSSatisfiesExpression) {
|
|
6847
7163
|
current = current.expression;
|
|
6848
|
-
} else if (current.type ===
|
|
7164
|
+
} else if (current.type === AST_NODE_TYPES35.ChainExpression) {
|
|
6849
7165
|
current = current.expression;
|
|
6850
7166
|
} else {
|
|
6851
7167
|
break;
|
|
@@ -6860,23 +7176,23 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
6860
7176
|
]);
|
|
6861
7177
|
var isSchemaParseReference = (node) => {
|
|
6862
7178
|
const inner = unwrap4(node);
|
|
6863
|
-
return inner !== null && inner.type ===
|
|
7179
|
+
return inner !== null && inner.type === AST_NODE_TYPES35.MemberExpression && !inner.computed && inner.property.type === AST_NODE_TYPES35.Identifier && (inner.property.name === "parse" || inner.property.name === "safeParse");
|
|
6864
7180
|
};
|
|
6865
7181
|
var isRawPayloadSource = (node) => {
|
|
6866
7182
|
let current = unwrap4(node);
|
|
6867
7183
|
if (current === null) return false;
|
|
6868
|
-
if (current.type ===
|
|
7184
|
+
if (current.type === AST_NODE_TYPES35.AwaitExpression) {
|
|
6869
7185
|
current = unwrap4(current.argument);
|
|
6870
7186
|
}
|
|
6871
|
-
if (current === null || current.type !==
|
|
7187
|
+
if (current === null || current.type !== AST_NODE_TYPES35.CallExpression) {
|
|
6872
7188
|
return false;
|
|
6873
7189
|
}
|
|
6874
7190
|
const callee = unwrap4(current.callee);
|
|
6875
|
-
if (callee === null || callee.type !==
|
|
7191
|
+
if (callee === null || callee.type !== AST_NODE_TYPES35.MemberExpression) {
|
|
6876
7192
|
return false;
|
|
6877
7193
|
}
|
|
6878
7194
|
const property = unwrap4(callee.property);
|
|
6879
|
-
if (property === null || property.type !==
|
|
7195
|
+
if (property === null || property.type !== AST_NODE_TYPES35.Identifier) {
|
|
6880
7196
|
return false;
|
|
6881
7197
|
}
|
|
6882
7198
|
if (property.name === "json") {
|
|
@@ -6886,17 +7202,16 @@ var isRawPayloadSource = (node) => {
|
|
|
6886
7202
|
return !current.arguments.some(isSchemaParseReference) && isRawPayloadSource(callee.object);
|
|
6887
7203
|
}
|
|
6888
7204
|
const object = unwrap4(callee.object);
|
|
6889
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
6890
|
-
!isLocalFileRead(current.arguments[0]);
|
|
7205
|
+
return property.name === "parse" && object !== null && object.type === AST_NODE_TYPES35.Identifier && object.name === "JSON" && !isLocalFileRead(current.arguments[0]);
|
|
6891
7206
|
};
|
|
6892
7207
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
6893
7208
|
var isLocalFileRead = (node) => {
|
|
6894
7209
|
let found = false;
|
|
6895
7210
|
const visit = (current) => {
|
|
6896
7211
|
if (found || current === null || current === void 0) return;
|
|
6897
|
-
if (current.type ===
|
|
7212
|
+
if (current.type === AST_NODE_TYPES35.CallExpression) {
|
|
6898
7213
|
const callee = unwrap4(current.callee);
|
|
6899
|
-
const name = callee?.type ===
|
|
7214
|
+
const name = callee?.type === AST_NODE_TYPES35.Identifier ? callee.name : callee?.type === AST_NODE_TYPES35.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES35.Identifier ? callee.property.name : null;
|
|
6900
7215
|
if (name !== null && FILE_READ_RE.test(name)) {
|
|
6901
7216
|
found = true;
|
|
6902
7217
|
return;
|
|
@@ -6918,15 +7233,15 @@ var isLocalFileRead = (node) => {
|
|
|
6918
7233
|
var ASSERTION_CALLEE_RE = /^(expect|assert|should|invariant)$/;
|
|
6919
7234
|
var isInsideAssertion = (node) => {
|
|
6920
7235
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
6921
|
-
if (current.type !==
|
|
7236
|
+
if (current.type !== AST_NODE_TYPES35.CallExpression) continue;
|
|
6922
7237
|
let callee = current.callee;
|
|
6923
|
-
while (callee.type ===
|
|
7238
|
+
while (callee.type === AST_NODE_TYPES35.MemberExpression) {
|
|
6924
7239
|
callee = callee.object;
|
|
6925
7240
|
}
|
|
6926
|
-
if (callee.type ===
|
|
7241
|
+
if (callee.type === AST_NODE_TYPES35.CallExpression) {
|
|
6927
7242
|
callee = callee.callee;
|
|
6928
7243
|
}
|
|
6929
|
-
if (callee.type ===
|
|
7244
|
+
if (callee.type === AST_NODE_TYPES35.Identifier && ASSERTION_CALLEE_RE.test(callee.name)) {
|
|
6930
7245
|
return true;
|
|
6931
7246
|
}
|
|
6932
7247
|
}
|
|
@@ -6945,39 +7260,39 @@ var GUARD_NAME_RE = /^(?:is|validate|parse|assert|decode|coerce)[A-Z]/;
|
|
|
6945
7260
|
var isValidationRead = (node) => {
|
|
6946
7261
|
let current = node;
|
|
6947
7262
|
let parent = current.parent;
|
|
6948
|
-
while (parent !== null && parent !== void 0 && (parent.type ===
|
|
7263
|
+
while (parent !== null && parent !== void 0 && (parent.type === AST_NODE_TYPES35.TSAsExpression || parent.type === AST_NODE_TYPES35.TSTypeAssertion || parent.type === AST_NODE_TYPES35.TSNonNullExpression || parent.type === AST_NODE_TYPES35.TSSatisfiesExpression || parent.type === AST_NODE_TYPES35.ChainExpression)) {
|
|
6949
7264
|
current = parent;
|
|
6950
7265
|
parent = parent.parent;
|
|
6951
7266
|
}
|
|
6952
7267
|
if (parent === null || parent === void 0) return false;
|
|
6953
|
-
if (parent.type ===
|
|
7268
|
+
if (parent.type === AST_NODE_TYPES35.UnaryExpression && parent.operator === "typeof" && parent.argument === current) {
|
|
6954
7269
|
return true;
|
|
6955
7270
|
}
|
|
6956
|
-
if (parent.type !==
|
|
7271
|
+
if (parent.type !== AST_NODE_TYPES35.CallExpression || !parent.arguments.some((arg) => arg === current)) {
|
|
6957
7272
|
return false;
|
|
6958
7273
|
}
|
|
6959
7274
|
const callee = parent.callee;
|
|
6960
|
-
if (callee.type ===
|
|
7275
|
+
if (callee.type === AST_NODE_TYPES35.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES35.Identifier && callee.object.name === "Array" && callee.property.type === AST_NODE_TYPES35.Identifier && callee.property.name === "isArray") {
|
|
6961
7276
|
return parent.arguments.length === 1;
|
|
6962
7277
|
}
|
|
6963
|
-
return callee.type ===
|
|
7278
|
+
return callee.type === AST_NODE_TYPES35.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
6964
7279
|
};
|
|
6965
7280
|
var isGuardTestPosition = (node) => {
|
|
6966
7281
|
let current = node;
|
|
6967
7282
|
let parent = current.parent;
|
|
6968
7283
|
while (parent !== void 0 && parent !== null) {
|
|
6969
7284
|
switch (parent.type) {
|
|
6970
|
-
case
|
|
6971
|
-
case
|
|
6972
|
-
case
|
|
7285
|
+
case AST_NODE_TYPES35.UnaryExpression:
|
|
7286
|
+
case AST_NODE_TYPES35.LogicalExpression:
|
|
7287
|
+
case AST_NODE_TYPES35.ChainExpression:
|
|
6973
7288
|
current = parent;
|
|
6974
7289
|
parent = parent.parent;
|
|
6975
7290
|
continue;
|
|
6976
|
-
case
|
|
6977
|
-
case
|
|
6978
|
-
case
|
|
6979
|
-
case
|
|
6980
|
-
case
|
|
7291
|
+
case AST_NODE_TYPES35.IfStatement:
|
|
7292
|
+
case AST_NODE_TYPES35.ConditionalExpression:
|
|
7293
|
+
case AST_NODE_TYPES35.WhileStatement:
|
|
7294
|
+
case AST_NODE_TYPES35.DoWhileStatement:
|
|
7295
|
+
case AST_NODE_TYPES35.ForStatement:
|
|
6981
7296
|
return parent.test === current;
|
|
6982
7297
|
default:
|
|
6983
7298
|
return false;
|
|
@@ -6987,7 +7302,7 @@ var isGuardTestPosition = (node) => {
|
|
|
6987
7302
|
};
|
|
6988
7303
|
var isUnvalidatedVariableRef = (node, scope, tracked) => {
|
|
6989
7304
|
const unwrapped = unwrap4(node);
|
|
6990
|
-
if (unwrapped === null || unwrapped.type !==
|
|
7305
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES35.Identifier) {
|
|
6991
7306
|
return false;
|
|
6992
7307
|
}
|
|
6993
7308
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -7030,11 +7345,11 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7030
7345
|
return {
|
|
7031
7346
|
VariableDeclarator(node) {
|
|
7032
7347
|
const scope = context.sourceCode.getScope(node);
|
|
7033
|
-
if (node.id.type ===
|
|
7348
|
+
if (node.id.type === AST_NODE_TYPES35.Identifier) {
|
|
7034
7349
|
trackInitializer(node);
|
|
7035
7350
|
return;
|
|
7036
7351
|
}
|
|
7037
|
-
if (node.id.type ===
|
|
7352
|
+
if (node.id.type === AST_NODE_TYPES35.ObjectPattern || node.id.type === AST_NODE_TYPES35.ArrayPattern) {
|
|
7038
7353
|
if (isRawPayloadSource(node.init)) {
|
|
7039
7354
|
if (!isFullyNarrowedPattern(node)) {
|
|
7040
7355
|
context.report({ node: node.id, messageId: "unparsedJsonAccess" });
|
|
@@ -7048,7 +7363,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7048
7363
|
},
|
|
7049
7364
|
AssignmentExpression(node) {
|
|
7050
7365
|
const scope = context.sourceCode.getScope(node);
|
|
7051
|
-
if (node.left.type ===
|
|
7366
|
+
if (node.left.type === AST_NODE_TYPES35.Identifier) {
|
|
7052
7367
|
const variable = findVariable2(scope, node.left.name);
|
|
7053
7368
|
if (variable === null) return;
|
|
7054
7369
|
if (isRawPayloadSource(node.right)) {
|
|
@@ -7058,7 +7373,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7058
7373
|
}
|
|
7059
7374
|
return;
|
|
7060
7375
|
}
|
|
7061
|
-
if (node.left.type ===
|
|
7376
|
+
if (node.left.type === AST_NODE_TYPES35.ObjectPattern || node.left.type === AST_NODE_TYPES35.ArrayPattern) {
|
|
7062
7377
|
if (isRawPayloadSource(node.right)) {
|
|
7063
7378
|
context.report({
|
|
7064
7379
|
node: node.left,
|
|
@@ -7075,15 +7390,15 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7075
7390
|
}
|
|
7076
7391
|
},
|
|
7077
7392
|
CallExpression(node) {
|
|
7078
|
-
if (node.callee.type !==
|
|
7393
|
+
if (node.callee.type !== AST_NODE_TYPES35.Identifier) return;
|
|
7079
7394
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
7080
7395
|
return;
|
|
7081
7396
|
}
|
|
7082
7397
|
const scope = context.sourceCode.getScope(node);
|
|
7083
7398
|
for (const arg of node.arguments) {
|
|
7084
|
-
if (arg.type ===
|
|
7399
|
+
if (arg.type === AST_NODE_TYPES35.SpreadElement) continue;
|
|
7085
7400
|
const unwrapped = unwrap4(arg);
|
|
7086
|
-
if (unwrapped === null || unwrapped.type !==
|
|
7401
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES35.Identifier) {
|
|
7087
7402
|
continue;
|
|
7088
7403
|
}
|
|
7089
7404
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -7097,13 +7412,13 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7097
7412
|
const obj = unwrap4(node.object);
|
|
7098
7413
|
if (isRawPayloadSource(obj)) {
|
|
7099
7414
|
const parent = node.parent;
|
|
7100
|
-
if (parent.type ===
|
|
7415
|
+
if (parent.type === AST_NODE_TYPES35.CallExpression && parent.callee === node && node.property.type === AST_NODE_TYPES35.Identifier && (node.property.name === "parse" || node.property.name === "safeParse" || PROMISE_CHAIN_METHODS.has(node.property.name))) {
|
|
7101
7416
|
return;
|
|
7102
7417
|
}
|
|
7103
7418
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
7104
7419
|
return;
|
|
7105
7420
|
}
|
|
7106
|
-
if (obj !== null && obj.type ===
|
|
7421
|
+
if (obj !== null && obj.type === AST_NODE_TYPES35.Identifier && isUnvalidatedVariableRef(obj, scope, unvalidatedVariables)) {
|
|
7107
7422
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
7108
7423
|
const variable = findVariable2(scope, obj.name);
|
|
7109
7424
|
if (variable !== null) {
|
|
@@ -7116,7 +7431,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7116
7431
|
});
|
|
7117
7432
|
|
|
7118
7433
|
// src/rules/prefer-semantic-colors.ts
|
|
7119
|
-
import { AST_NODE_TYPES as
|
|
7434
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES36 } from "@typescript-eslint/utils";
|
|
7120
7435
|
import { existsSync, readdirSync, readFileSync } from "fs";
|
|
7121
7436
|
import { dirname, join, parse } from "path";
|
|
7122
7437
|
|
|
@@ -7216,8 +7531,8 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
7216
7531
|
]);
|
|
7217
7532
|
function jsxElementName(node) {
|
|
7218
7533
|
const name = node.openingElement.name;
|
|
7219
|
-
if (name.type ===
|
|
7220
|
-
if (name.type ===
|
|
7534
|
+
if (name.type === AST_NODE_TYPES36.JSXIdentifier) return name.name;
|
|
7535
|
+
if (name.type === AST_NODE_TYPES36.JSXMemberExpression && name.property.type === AST_NODE_TYPES36.JSXIdentifier) {
|
|
7221
7536
|
return name.property.name;
|
|
7222
7537
|
}
|
|
7223
7538
|
return null;
|
|
@@ -7239,11 +7554,11 @@ var SVG_SHAPE_PRIMITIVES = /* @__PURE__ */ new Set([
|
|
|
7239
7554
|
"tspan",
|
|
7240
7555
|
"use"
|
|
7241
7556
|
]);
|
|
7242
|
-
var
|
|
7557
|
+
var EMAIL_OR_PDF_MODULE_RE = /^@react-(?:email|pdf)\//;
|
|
7243
7558
|
var isInsideSvg = (node) => {
|
|
7244
7559
|
let current = node.parent;
|
|
7245
7560
|
while (current !== void 0 && current !== null) {
|
|
7246
|
-
if (current.type ===
|
|
7561
|
+
if (current.type === AST_NODE_TYPES36.JSXElement) {
|
|
7247
7562
|
const name = jsxElementName(current);
|
|
7248
7563
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
7249
7564
|
}
|
|
@@ -7254,7 +7569,7 @@ var isInsideSvg = (node) => {
|
|
|
7254
7569
|
var isInsideIconFactoryPath = (node) => {
|
|
7255
7570
|
let current = node.parent;
|
|
7256
7571
|
while (current !== void 0 && current !== null) {
|
|
7257
|
-
if (current.type ===
|
|
7572
|
+
if (current.type === AST_NODE_TYPES36.Property && propName(current.key) === "path" && current.parent.type === AST_NODE_TYPES36.ObjectExpression && current.parent.parent.type === AST_NODE_TYPES36.CallExpression && current.parent.parent.callee.type === AST_NODE_TYPES36.Identifier && current.parent.parent.callee.name === "createIcon") {
|
|
7258
7573
|
return true;
|
|
7259
7574
|
}
|
|
7260
7575
|
current = current.parent;
|
|
@@ -7391,10 +7706,16 @@ var hasSemanticTokenSystem = (filename) => {
|
|
|
7391
7706
|
return root !== null && workspaceHasMarker(root);
|
|
7392
7707
|
};
|
|
7393
7708
|
var propName = (key) => {
|
|
7394
|
-
if (key.type ===
|
|
7395
|
-
if (key.type ===
|
|
7709
|
+
if (key.type === AST_NODE_TYPES36.Identifier) return key.name;
|
|
7710
|
+
if (key.type === AST_NODE_TYPES36.Literal && typeof key.value === "string") return key.value;
|
|
7396
7711
|
return null;
|
|
7397
7712
|
};
|
|
7713
|
+
var staticallyImportsEmailOrPdfRenderer = (program) => program.body.some((statement) => {
|
|
7714
|
+
if (statement.type !== AST_NODE_TYPES36.ImportDeclaration && statement.type !== AST_NODE_TYPES36.ExportNamedDeclaration && statement.type !== AST_NODE_TYPES36.ExportAllDeclaration) {
|
|
7715
|
+
return false;
|
|
7716
|
+
}
|
|
7717
|
+
return statement.source !== null && typeof statement.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(statement.source.value);
|
|
7718
|
+
});
|
|
7398
7719
|
var prefer_semantic_colors_default = createRule({
|
|
7399
7720
|
name: "prefer-semantic-colors",
|
|
7400
7721
|
meta: {
|
|
@@ -7420,44 +7741,49 @@ var prefer_semantic_colors_default = createRule({
|
|
|
7420
7741
|
defaultOptions: [{}],
|
|
7421
7742
|
create(context, [options]) {
|
|
7422
7743
|
if (STORIES_FILE_RE.test(context.filename)) return {};
|
|
7423
|
-
if (
|
|
7744
|
+
if (staticallyImportsEmailOrPdfRenderer(context.sourceCode.ast)) return {};
|
|
7424
7745
|
if (options?.requireSemanticTokens === true && !hasSemanticTokenSystem(context.filename)) {
|
|
7425
7746
|
return {};
|
|
7426
7747
|
}
|
|
7748
|
+
let importsEmailOrPdfRenderer = false;
|
|
7749
|
+
const pendingReports = [];
|
|
7750
|
+
const report = (node, messageId, data) => {
|
|
7751
|
+
pendingReports.push({ node, messageId, data });
|
|
7752
|
+
};
|
|
7427
7753
|
const reportClasses = (value, node) => {
|
|
7428
7754
|
for (const token of classTokens(value)) {
|
|
7429
7755
|
const base = tailwindBase(token);
|
|
7430
7756
|
if (RAW_PALETTE_RE.test(base)) {
|
|
7431
|
-
|
|
7757
|
+
report(node, "rawPalette", { class: token });
|
|
7432
7758
|
} else if (ARBITRARY_COLOR_RE.test(base) && !CSS_VAR_REFERENCE_RE.test(base)) {
|
|
7433
|
-
|
|
7759
|
+
report(node, "arbitraryColor", { class: token });
|
|
7434
7760
|
}
|
|
7435
7761
|
}
|
|
7436
7762
|
};
|
|
7437
7763
|
const checkClassNode = (node) => {
|
|
7438
7764
|
if (node === null) return;
|
|
7439
7765
|
switch (node.type) {
|
|
7440
|
-
case
|
|
7766
|
+
case AST_NODE_TYPES36.Literal:
|
|
7441
7767
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
7442
7768
|
break;
|
|
7443
|
-
case
|
|
7769
|
+
case AST_NODE_TYPES36.TemplateLiteral:
|
|
7444
7770
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
7445
7771
|
break;
|
|
7446
|
-
case
|
|
7772
|
+
case AST_NODE_TYPES36.ArrayExpression:
|
|
7447
7773
|
for (const element of node.elements) {
|
|
7448
|
-
if (element !== null && element.type !==
|
|
7774
|
+
if (element !== null && element.type !== AST_NODE_TYPES36.SpreadElement) checkClassNode(element);
|
|
7449
7775
|
}
|
|
7450
7776
|
break;
|
|
7451
|
-
case
|
|
7777
|
+
case AST_NODE_TYPES36.ObjectExpression:
|
|
7452
7778
|
for (const property of node.properties) {
|
|
7453
|
-
if (property.type ===
|
|
7779
|
+
if (property.type === AST_NODE_TYPES36.Property) checkClassNode(property.value);
|
|
7454
7780
|
}
|
|
7455
7781
|
break;
|
|
7456
|
-
case
|
|
7782
|
+
case AST_NODE_TYPES36.ConditionalExpression:
|
|
7457
7783
|
checkClassNode(node.consequent);
|
|
7458
7784
|
checkClassNode(node.alternate);
|
|
7459
7785
|
break;
|
|
7460
|
-
case
|
|
7786
|
+
case AST_NODE_TYPES36.LogicalExpression:
|
|
7461
7787
|
checkClassNode(node.right);
|
|
7462
7788
|
break;
|
|
7463
7789
|
default:
|
|
@@ -7465,29 +7791,32 @@ var prefer_semantic_colors_default = createRule({
|
|
|
7465
7791
|
}
|
|
7466
7792
|
};
|
|
7467
7793
|
const checkColorValueNode = (node) => {
|
|
7468
|
-
if (node.type ===
|
|
7469
|
-
|
|
7794
|
+
if (node.type === AST_NODE_TYPES36.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value) && !CSS_VAR_REFERENCE_RE.test(node.value)) {
|
|
7795
|
+
report(node, "inlineColor", { value: node.value });
|
|
7470
7796
|
}
|
|
7471
7797
|
};
|
|
7472
7798
|
return {
|
|
7473
7799
|
"JSXAttribute[name.name='className']"(node) {
|
|
7474
7800
|
if (node.value === null) return;
|
|
7475
|
-
if (node.value.type ===
|
|
7476
|
-
else if (node.value.type ===
|
|
7477
|
-
if (node.value.expression.type !==
|
|
7801
|
+
if (node.value.type === AST_NODE_TYPES36.Literal) checkClassNode(node.value);
|
|
7802
|
+
else if (node.value.type === AST_NODE_TYPES36.JSXExpressionContainer) {
|
|
7803
|
+
if (node.value.expression.type !== AST_NODE_TYPES36.JSXEmptyExpression) {
|
|
7478
7804
|
checkClassNode(node.value.expression);
|
|
7479
7805
|
}
|
|
7480
7806
|
}
|
|
7481
7807
|
},
|
|
7482
7808
|
CallExpression(node) {
|
|
7483
|
-
if (node.callee.type ===
|
|
7809
|
+
if (node.callee.type === AST_NODE_TYPES36.Identifier && node.callee.name === "require" && node.arguments[0]?.type === AST_NODE_TYPES36.Literal && typeof node.arguments[0].value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.arguments[0].value)) {
|
|
7810
|
+
importsEmailOrPdfRenderer = true;
|
|
7811
|
+
}
|
|
7812
|
+
if (node.callee.type === AST_NODE_TYPES36.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
7484
7813
|
for (const arg of node.arguments) {
|
|
7485
|
-
if (arg.type !==
|
|
7814
|
+
if (arg.type !== AST_NODE_TYPES36.SpreadElement) checkClassNode(arg);
|
|
7486
7815
|
}
|
|
7487
7816
|
}
|
|
7488
7817
|
},
|
|
7489
7818
|
VariableDeclarator(node) {
|
|
7490
|
-
if (node.id.type ===
|
|
7819
|
+
if (node.id.type === AST_NODE_TYPES36.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
7491
7820
|
checkClassNode(node.init);
|
|
7492
7821
|
}
|
|
7493
7822
|
},
|
|
@@ -7495,13 +7824,11 @@ var prefer_semantic_colors_default = createRule({
|
|
|
7495
7824
|
const name = propName(node.key);
|
|
7496
7825
|
if (name !== null && CLASS_NAME_RE.test(name)) checkClassNode(node.value);
|
|
7497
7826
|
},
|
|
7498
|
-
// SVG
|
|
7499
|
-
// Neutral drawing literals and anything inside an SVG defs container are
|
|
7500
|
-
// structural, not UI tokens, so they never fire.
|
|
7827
|
+
// SVG artwork colors are exempt; component presentation colors still report.
|
|
7501
7828
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
7502
|
-
if (node.value?.type !==
|
|
7829
|
+
if (node.value?.type !== AST_NODE_TYPES36.Literal) return;
|
|
7503
7830
|
const owner = node.parent.name;
|
|
7504
|
-
if (owner.type ===
|
|
7831
|
+
if (owner.type === AST_NODE_TYPES36.JSXIdentifier && SVG_SHAPE_PRIMITIVES.has(owner.name)) {
|
|
7505
7832
|
return;
|
|
7506
7833
|
}
|
|
7507
7834
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
@@ -7513,6 +7840,15 @@ var prefer_semantic_colors_default = createRule({
|
|
|
7513
7840
|
"JSXAttribute[name.name='style'] ObjectExpression > Property"(node) {
|
|
7514
7841
|
const name = propName(node.key);
|
|
7515
7842
|
if (name !== null && STYLE_COLOR_PROPS.has(name)) checkColorValueNode(node.value);
|
|
7843
|
+
},
|
|
7844
|
+
ImportExpression(node) {
|
|
7845
|
+
if (node.source.type === AST_NODE_TYPES36.Literal && typeof node.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.source.value)) {
|
|
7846
|
+
importsEmailOrPdfRenderer = true;
|
|
7847
|
+
}
|
|
7848
|
+
},
|
|
7849
|
+
"Program:exit"() {
|
|
7850
|
+
if (importsEmailOrPdfRenderer) return;
|
|
7851
|
+
for (const descriptor of pendingReports) context.report(descriptor);
|
|
7516
7852
|
}
|
|
7517
7853
|
};
|
|
7518
7854
|
}
|
|
@@ -7580,6 +7916,22 @@ function isMutationMethod(node, context) {
|
|
|
7580
7916
|
}
|
|
7581
7917
|
return false;
|
|
7582
7918
|
}
|
|
7919
|
+
function isFunctionArgument(node, context) {
|
|
7920
|
+
const resolved = resolveNode(node, context);
|
|
7921
|
+
if (resolved?.type === "ArrowFunctionExpression" || resolved?.type === "FunctionExpression") {
|
|
7922
|
+
return true;
|
|
7923
|
+
}
|
|
7924
|
+
if (node.type !== "Identifier") return false;
|
|
7925
|
+
let scope = getScope(context, node);
|
|
7926
|
+
while (scope) {
|
|
7927
|
+
const variable = scope.set.get(node.name);
|
|
7928
|
+
if (variable?.defs.some((definition) => definition.type === "FunctionName")) {
|
|
7929
|
+
return true;
|
|
7930
|
+
}
|
|
7931
|
+
scope = scope.upper;
|
|
7932
|
+
}
|
|
7933
|
+
return false;
|
|
7934
|
+
}
|
|
7583
7935
|
function getPropertyNode(objNode, propName2) {
|
|
7584
7936
|
if (!objNode || objNode.type !== "ObjectExpression") return null;
|
|
7585
7937
|
for (const prop of objNode.properties) {
|
|
@@ -7617,13 +7969,10 @@ var prefer_server_actions_default = createRule({
|
|
|
7617
7969
|
if (SKIP_FILE_REGEX.test(filename)) {
|
|
7618
7970
|
return {};
|
|
7619
7971
|
}
|
|
7620
|
-
|
|
7972
|
+
const isNonReactFramework = context.sourceCode.ast.body.some(
|
|
7973
|
+
(node) => node.type === "ImportDeclaration" && typeof node.source.value === "string" && NON_REACT_FRAMEWORK_RE.test(node.source.value)
|
|
7974
|
+
);
|
|
7621
7975
|
return {
|
|
7622
|
-
ImportDeclaration(node) {
|
|
7623
|
-
if (typeof node.source.value === "string" && NON_REACT_FRAMEWORK_RE.test(node.source.value)) {
|
|
7624
|
-
isNonReactFramework = true;
|
|
7625
|
-
}
|
|
7626
|
-
},
|
|
7627
7976
|
CallExpression(node) {
|
|
7628
7977
|
if (isNonReactFramework) return;
|
|
7629
7978
|
let isMutation = false;
|
|
@@ -7644,7 +7993,7 @@ var prefer_server_actions_default = createRule({
|
|
|
7644
7993
|
if (AXIOS_MUTATION_METHODS.has(methodName)) {
|
|
7645
7994
|
const urlArg = node.arguments[0];
|
|
7646
7995
|
const hasHandlerArg = node.arguments.some(
|
|
7647
|
-
(arg) => arg.type
|
|
7996
|
+
(arg) => arg.type !== "SpreadElement" && isFunctionArgument(arg, context)
|
|
7648
7997
|
);
|
|
7649
7998
|
if (urlArg && urlArg.type !== "SpreadElement" && !hasHandlerArg && isApiUrl(urlArg, context)) {
|
|
7650
7999
|
isMutation = true;
|
|
@@ -7671,10 +8020,35 @@ var prefer_server_actions_default = createRule({
|
|
|
7671
8020
|
}
|
|
7672
8021
|
});
|
|
7673
8022
|
|
|
8023
|
+
// src/rules/prefer-single-sentence-comment.ts
|
|
8024
|
+
var prefer_single_sentence_comment_default = createRule({
|
|
8025
|
+
name: "prefer-single-sentence-comment",
|
|
8026
|
+
meta: {
|
|
8027
|
+
type: "suggestion",
|
|
8028
|
+
docs: { description: "Prefer one sentence and self-documenting code over a two-sentence comment." },
|
|
8029
|
+
schema: [],
|
|
8030
|
+
messages: {
|
|
8031
|
+
preferOneSentence: "Two-sentence comment \u2014 prefer one sentence and self-documenting code."
|
|
8032
|
+
}
|
|
8033
|
+
},
|
|
8034
|
+
defaultOptions: [],
|
|
8035
|
+
create(context) {
|
|
8036
|
+
return {
|
|
8037
|
+
Program() {
|
|
8038
|
+
for (const group of proseGroups(context.filename, context.sourceCode)) {
|
|
8039
|
+
if (!group.hasTypedTags && sentenceUnits(group.text) === 2) {
|
|
8040
|
+
context.report({ node: group.comment, messageId: "preferOneSentence" });
|
|
8041
|
+
}
|
|
8042
|
+
}
|
|
8043
|
+
}
|
|
8044
|
+
};
|
|
8045
|
+
}
|
|
8046
|
+
});
|
|
8047
|
+
|
|
7674
8048
|
// src/rules/prefer-string-literal-union.ts
|
|
7675
8049
|
import {
|
|
7676
8050
|
ESLintUtils as ESLintUtils3,
|
|
7677
|
-
AST_NODE_TYPES as
|
|
8051
|
+
AST_NODE_TYPES as AST_NODE_TYPES37
|
|
7678
8052
|
} from "@typescript-eslint/utils";
|
|
7679
8053
|
import * as ts2 from "typescript";
|
|
7680
8054
|
var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
@@ -7718,19 +8092,19 @@ function isChoiceLikeName(name) {
|
|
|
7718
8092
|
return CHOICE_TOKENS.has(lastWord(name));
|
|
7719
8093
|
}
|
|
7720
8094
|
function keyName(key) {
|
|
7721
|
-
if (key.type ===
|
|
8095
|
+
if (key.type === AST_NODE_TYPES37.Identifier) {
|
|
7722
8096
|
return key.name;
|
|
7723
8097
|
}
|
|
7724
|
-
if (key.type ===
|
|
8098
|
+
if (key.type === AST_NODE_TYPES37.Literal && typeof key.value === "string") {
|
|
7725
8099
|
return key.value;
|
|
7726
8100
|
}
|
|
7727
8101
|
return null;
|
|
7728
8102
|
}
|
|
7729
8103
|
function isStringLiteralMember(t) {
|
|
7730
|
-
return t.type ===
|
|
8104
|
+
return t.type === AST_NODE_TYPES37.TSLiteralType && t.literal.type === AST_NODE_TYPES37.Literal && typeof t.literal.value === "string";
|
|
7731
8105
|
}
|
|
7732
8106
|
function isStringLiteralUnion(node) {
|
|
7733
|
-
if (node?.type !==
|
|
8107
|
+
if (node?.type !== AST_NODE_TYPES37.TSUnionType) {
|
|
7734
8108
|
return false;
|
|
7735
8109
|
}
|
|
7736
8110
|
return node.types.filter(isStringLiteralMember).length >= MIN_CLUSTER_SIZE;
|
|
@@ -7759,12 +8133,12 @@ function bindingSourceExpression(decl) {
|
|
|
7759
8133
|
return ts2.isForOfStatement(node) ? node.expression : node.initializer;
|
|
7760
8134
|
}
|
|
7761
8135
|
function refKey(node) {
|
|
7762
|
-
if (node.type ===
|
|
8136
|
+
if (node.type === AST_NODE_TYPES37.Identifier) {
|
|
7763
8137
|
return node.name;
|
|
7764
8138
|
}
|
|
7765
|
-
if (node.type ===
|
|
8139
|
+
if (node.type === AST_NODE_TYPES37.MemberExpression && !node.computed) {
|
|
7766
8140
|
const inner = refKey(node.object);
|
|
7767
|
-
if (inner === null || node.property.type !==
|
|
8141
|
+
if (inner === null || node.property.type !== AST_NODE_TYPES37.Identifier) {
|
|
7768
8142
|
return null;
|
|
7769
8143
|
}
|
|
7770
8144
|
return `${inner}.${node.property.name}`;
|
|
@@ -7772,7 +8146,7 @@ function refKey(node) {
|
|
|
7772
8146
|
return null;
|
|
7773
8147
|
}
|
|
7774
8148
|
function strLiteral(node) {
|
|
7775
|
-
if (node.type ===
|
|
8149
|
+
if (node.type === AST_NODE_TYPES37.Literal && typeof node.value === "string") {
|
|
7776
8150
|
return node.value;
|
|
7777
8151
|
}
|
|
7778
8152
|
return null;
|
|
@@ -7925,7 +8299,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
7925
8299
|
containersWithUnion.add(container);
|
|
7926
8300
|
return;
|
|
7927
8301
|
}
|
|
7928
|
-
if (typeNode?.type !==
|
|
8302
|
+
if (typeNode?.type !== AST_NODE_TYPES37.TSStringKeyword) {
|
|
7929
8303
|
return;
|
|
7930
8304
|
}
|
|
7931
8305
|
const name = keyName(key);
|
|
@@ -8013,10 +8387,10 @@ var prefer_string_literal_union_default = createRule({
|
|
|
8013
8387
|
}
|
|
8014
8388
|
};
|
|
8015
8389
|
function refKeyText(node) {
|
|
8016
|
-
if (node.type ===
|
|
8390
|
+
if (node.type === AST_NODE_TYPES37.BinaryExpression) {
|
|
8017
8391
|
return refKey(node.left) ?? refKey(node.right) ?? "value";
|
|
8018
8392
|
}
|
|
8019
|
-
if (node.type ===
|
|
8393
|
+
if (node.type === AST_NODE_TYPES37.SwitchStatement) {
|
|
8020
8394
|
return refKey(node.discriminant) ?? "value";
|
|
8021
8395
|
}
|
|
8022
8396
|
return "value";
|
|
@@ -8025,7 +8399,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
8025
8399
|
});
|
|
8026
8400
|
|
|
8027
8401
|
// src/rules/prefer-whole-object-assertion.ts
|
|
8028
|
-
import { AST_NODE_TYPES as
|
|
8402
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES38 } from "@typescript-eslint/utils";
|
|
8029
8403
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
8030
8404
|
var ARRAY_MATCHERS = /* @__PURE__ */ new Set(["toEqual", "toStrictEqual"]);
|
|
8031
8405
|
var COLLECTION_PROPERTIES = /* @__PURE__ */ new Set(["length", "size"]);
|
|
@@ -8034,11 +8408,11 @@ var NUMERIC_SIGNS2 = /* @__PURE__ */ new Set(["-", "+"]);
|
|
|
8034
8408
|
var MIN_RUN_LENGTH = 2;
|
|
8035
8409
|
function literalText(node, getText) {
|
|
8036
8410
|
switch (node.type) {
|
|
8037
|
-
case
|
|
8411
|
+
case AST_NODE_TYPES38.Literal:
|
|
8038
8412
|
return "regex" in node ? null : getText(node);
|
|
8039
|
-
case
|
|
8413
|
+
case AST_NODE_TYPES38.TemplateLiteral:
|
|
8040
8414
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
8041
|
-
case
|
|
8415
|
+
case AST_NODE_TYPES38.UnaryExpression:
|
|
8042
8416
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
8043
8417
|
default:
|
|
8044
8418
|
return null;
|
|
@@ -8046,15 +8420,15 @@ function literalText(node, getText) {
|
|
|
8046
8420
|
}
|
|
8047
8421
|
function isPureReceiver(node) {
|
|
8048
8422
|
switch (node.type) {
|
|
8049
|
-
case
|
|
8050
|
-
case
|
|
8423
|
+
case AST_NODE_TYPES38.Identifier:
|
|
8424
|
+
case AST_NODE_TYPES38.ThisExpression:
|
|
8051
8425
|
return true;
|
|
8052
|
-
case
|
|
8426
|
+
case AST_NODE_TYPES38.MemberExpression:
|
|
8053
8427
|
if (node.optional) {
|
|
8054
8428
|
return false;
|
|
8055
8429
|
}
|
|
8056
8430
|
if (node.computed) {
|
|
8057
|
-
return node.property.type ===
|
|
8431
|
+
return node.property.type === AST_NODE_TYPES38.Literal && isPureReceiver(node.object);
|
|
8058
8432
|
}
|
|
8059
8433
|
return isPureReceiver(node.object);
|
|
8060
8434
|
default:
|
|
@@ -8062,7 +8436,7 @@ function isPureReceiver(node) {
|
|
|
8062
8436
|
}
|
|
8063
8437
|
}
|
|
8064
8438
|
function literalIndex(node) {
|
|
8065
|
-
if (node.type !==
|
|
8439
|
+
if (node.type !== AST_NODE_TYPES38.Literal || typeof node.value !== "number") {
|
|
8066
8440
|
return null;
|
|
8067
8441
|
}
|
|
8068
8442
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
@@ -8088,24 +8462,24 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8088
8462
|
}
|
|
8089
8463
|
const { sourceCode } = context;
|
|
8090
8464
|
function parseAssertion(statement) {
|
|
8091
|
-
if (statement.type !==
|
|
8465
|
+
if (statement.type !== AST_NODE_TYPES38.ExpressionStatement) {
|
|
8092
8466
|
return null;
|
|
8093
8467
|
}
|
|
8094
8468
|
const call = statement.expression;
|
|
8095
|
-
if (call.type !==
|
|
8469
|
+
if (call.type !== AST_NODE_TYPES38.CallExpression) {
|
|
8096
8470
|
return null;
|
|
8097
8471
|
}
|
|
8098
8472
|
const callee = call.callee;
|
|
8099
|
-
if (callee.type !==
|
|
8473
|
+
if (callee.type !== AST_NODE_TYPES38.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES38.Identifier) {
|
|
8100
8474
|
return null;
|
|
8101
8475
|
}
|
|
8102
8476
|
const matcher = callee.property.name;
|
|
8103
8477
|
const expectCall = callee.object;
|
|
8104
|
-
if (expectCall.type !==
|
|
8478
|
+
if (expectCall.type !== AST_NODE_TYPES38.CallExpression || expectCall.callee.type !== AST_NODE_TYPES38.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
8105
8479
|
return null;
|
|
8106
8480
|
}
|
|
8107
8481
|
const actual = expectCall.arguments[0];
|
|
8108
|
-
if (actual === void 0 || actual.type !==
|
|
8482
|
+
if (actual === void 0 || actual.type !== AST_NODE_TYPES38.MemberExpression || actual.optional) {
|
|
8109
8483
|
return null;
|
|
8110
8484
|
}
|
|
8111
8485
|
if (!isPureReceiver(actual.object)) {
|
|
@@ -8119,7 +8493,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8119
8493
|
}
|
|
8120
8494
|
key = { kind: "index", index };
|
|
8121
8495
|
} else {
|
|
8122
|
-
if (actual.property.type !==
|
|
8496
|
+
if (actual.property.type !== AST_NODE_TYPES38.Identifier || COLLECTION_PROPERTIES.has(actual.property.name) || LITERAL_KEY_HAZARDS.has(actual.property.name)) {
|
|
8123
8497
|
return null;
|
|
8124
8498
|
}
|
|
8125
8499
|
key = { kind: "property", name: actual.property.name };
|
|
@@ -8131,7 +8505,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8131
8505
|
return null;
|
|
8132
8506
|
}
|
|
8133
8507
|
const expected = call.arguments[0];
|
|
8134
|
-
if (call.arguments.length !== 1 || expected === void 0 || expected.type ===
|
|
8508
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === AST_NODE_TYPES38.SpreadElement) {
|
|
8135
8509
|
return null;
|
|
8136
8510
|
}
|
|
8137
8511
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
@@ -8207,7 +8581,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8207
8581
|
}
|
|
8208
8582
|
});
|
|
8209
8583
|
}
|
|
8210
|
-
function checkBody(
|
|
8584
|
+
function checkBody(body2) {
|
|
8211
8585
|
let run = [];
|
|
8212
8586
|
const flush = () => {
|
|
8213
8587
|
const first = run[0];
|
|
@@ -8220,7 +8594,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8220
8594
|
}
|
|
8221
8595
|
run = [];
|
|
8222
8596
|
};
|
|
8223
|
-
for (const statement of
|
|
8597
|
+
for (const statement of body2) {
|
|
8224
8598
|
const assertion = parseAssertion(statement);
|
|
8225
8599
|
const previous = run.at(-1);
|
|
8226
8600
|
if (assertion !== null && previous !== void 0 && previous.key.kind === assertion.key.kind && sourceCode.getText(previous.receiver) === sourceCode.getText(assertion.receiver)) {
|
|
@@ -8246,7 +8620,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8246
8620
|
});
|
|
8247
8621
|
|
|
8248
8622
|
// src/rules/prefer-zod-enum.ts
|
|
8249
|
-
import { AST_NODE_TYPES as
|
|
8623
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES39 } from "@typescript-eslint/utils";
|
|
8250
8624
|
var prefer_zod_enum_default = createRule({
|
|
8251
8625
|
name: "prefer-zod-enum",
|
|
8252
8626
|
meta: {
|
|
@@ -8266,33 +8640,39 @@ var prefer_zod_enum_default = createRule({
|
|
|
8266
8640
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
8267
8641
|
function enumValues(node) {
|
|
8268
8642
|
const callee = node.callee;
|
|
8269
|
-
if (callee.type !==
|
|
8643
|
+
if (callee.type !== AST_NODE_TYPES39.MemberExpression || callee.computed || callee.object.type !== AST_NODE_TYPES39.Identifier || !zodNamespaces.has(callee.object.name) || callee.property.type !== AST_NODE_TYPES39.Identifier || callee.property.name !== "union" || node.arguments.length !== 1) {
|
|
8270
8644
|
return null;
|
|
8271
8645
|
}
|
|
8272
8646
|
const argument = node.arguments[0];
|
|
8273
|
-
if (argument === void 0 || argument.type !==
|
|
8647
|
+
if (argument === void 0 || argument.type !== AST_NODE_TYPES39.ArrayExpression || argument.elements.length === 0) {
|
|
8274
8648
|
return null;
|
|
8275
8649
|
}
|
|
8276
8650
|
const values = [];
|
|
8651
|
+
let canFix = true;
|
|
8277
8652
|
for (const element of argument.elements) {
|
|
8278
|
-
if (element ===
|
|
8653
|
+
if (element?.type === AST_NODE_TYPES39.SpreadElement) {
|
|
8654
|
+
canFix = false;
|
|
8655
|
+
continue;
|
|
8656
|
+
}
|
|
8657
|
+
if (element === null || element.type !== AST_NODE_TYPES39.CallExpression || element.callee.type !== AST_NODE_TYPES39.MemberExpression || element.callee.computed || element.callee.object.type !== AST_NODE_TYPES39.Identifier || !zodNamespaces.has(element.callee.object.name) || element.callee.property.type !== AST_NODE_TYPES39.Identifier || element.callee.property.name !== "literal") {
|
|
8279
8658
|
return null;
|
|
8280
8659
|
}
|
|
8281
8660
|
const value = element.arguments[0];
|
|
8282
|
-
if (value === void 0 || value.type !==
|
|
8283
|
-
|
|
8661
|
+
if (element.arguments.length !== 1 || value === void 0 || value.type !== AST_NODE_TYPES39.Literal || typeof value.value !== "string") {
|
|
8662
|
+
canFix = false;
|
|
8663
|
+
continue;
|
|
8284
8664
|
}
|
|
8285
8665
|
values.push(value);
|
|
8286
8666
|
}
|
|
8287
|
-
return values;
|
|
8667
|
+
return canFix ? values : void 0;
|
|
8288
8668
|
}
|
|
8289
8669
|
function buildFix(node, values) {
|
|
8290
8670
|
const argument = node.arguments[0];
|
|
8291
|
-
if (argument === void 0 || argument.type !==
|
|
8671
|
+
if (argument === void 0 || argument.type !== AST_NODE_TYPES39.ArrayExpression || sourceCode.getCommentsInside(argument).length > 0) {
|
|
8292
8672
|
return void 0;
|
|
8293
8673
|
}
|
|
8294
8674
|
const callee = node.callee;
|
|
8295
|
-
if (callee.type !==
|
|
8675
|
+
if (callee.type !== AST_NODE_TYPES39.MemberExpression || callee.property.type !== AST_NODE_TYPES39.Identifier) {
|
|
8296
8676
|
return void 0;
|
|
8297
8677
|
}
|
|
8298
8678
|
return (fixer) => [
|
|
@@ -8309,7 +8689,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
8309
8689
|
return;
|
|
8310
8690
|
}
|
|
8311
8691
|
for (const specifier of node.specifiers) {
|
|
8312
|
-
if (specifier.type ===
|
|
8692
|
+
if (specifier.type === AST_NODE_TYPES39.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES39.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES39.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES39.Identifier && specifier.imported.name === "z") {
|
|
8313
8693
|
zodNamespaces.add(specifier.local.name);
|
|
8314
8694
|
}
|
|
8315
8695
|
}
|
|
@@ -8319,7 +8699,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
8319
8699
|
if (values === null) {
|
|
8320
8700
|
return;
|
|
8321
8701
|
}
|
|
8322
|
-
const fix = buildFix(node, values);
|
|
8702
|
+
const fix = values === void 0 ? void 0 : buildFix(node, values);
|
|
8323
8703
|
context.report({
|
|
8324
8704
|
node,
|
|
8325
8705
|
messageId: "preferEnum",
|
|
@@ -8331,7 +8711,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
8331
8711
|
});
|
|
8332
8712
|
|
|
8333
8713
|
// src/rules/prefer-zod-infer.ts
|
|
8334
|
-
import { AST_NODE_TYPES as
|
|
8714
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES40 } from "@typescript-eslint/utils";
|
|
8335
8715
|
var SHAPE_PRESERVING_METHODS = /* @__PURE__ */ new Set([
|
|
8336
8716
|
"describe",
|
|
8337
8717
|
"refine",
|
|
@@ -8368,44 +8748,44 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
8368
8748
|
"Schema"
|
|
8369
8749
|
]);
|
|
8370
8750
|
var LEAF_NODE_TYPES = {
|
|
8371
|
-
string: [
|
|
8372
|
-
email: [
|
|
8373
|
-
url: [
|
|
8374
|
-
uuid: [
|
|
8375
|
-
ulid: [
|
|
8376
|
-
cuid: [
|
|
8377
|
-
cuid2: [
|
|
8378
|
-
nanoid: [
|
|
8379
|
-
iso: [
|
|
8380
|
-
number: [
|
|
8381
|
-
int: [
|
|
8382
|
-
float32: [
|
|
8383
|
-
float64: [
|
|
8384
|
-
boolean: [
|
|
8385
|
-
bigint: [
|
|
8386
|
-
symbol: [
|
|
8387
|
-
any: [
|
|
8388
|
-
unknown: [
|
|
8389
|
-
never: [
|
|
8390
|
-
void: [
|
|
8391
|
-
null: [
|
|
8392
|
-
undefined: [
|
|
8393
|
-
literal: [
|
|
8394
|
-
date: [
|
|
8395
|
-
array: [
|
|
8396
|
-
tuple: [
|
|
8397
|
-
object: [
|
|
8398
|
-
strictObject: [
|
|
8399
|
-
looseObject: [
|
|
8400
|
-
record: [
|
|
8401
|
-
map: [
|
|
8402
|
-
set: [
|
|
8403
|
-
promise: [
|
|
8404
|
-
enum: [
|
|
8405
|
-
nativeEnum: [
|
|
8406
|
-
union: [
|
|
8407
|
-
discriminatedUnion: [
|
|
8408
|
-
intersection: [
|
|
8751
|
+
string: [AST_NODE_TYPES40.TSStringKeyword],
|
|
8752
|
+
email: [AST_NODE_TYPES40.TSStringKeyword],
|
|
8753
|
+
url: [AST_NODE_TYPES40.TSStringKeyword],
|
|
8754
|
+
uuid: [AST_NODE_TYPES40.TSStringKeyword],
|
|
8755
|
+
ulid: [AST_NODE_TYPES40.TSStringKeyword],
|
|
8756
|
+
cuid: [AST_NODE_TYPES40.TSStringKeyword],
|
|
8757
|
+
cuid2: [AST_NODE_TYPES40.TSStringKeyword],
|
|
8758
|
+
nanoid: [AST_NODE_TYPES40.TSStringKeyword],
|
|
8759
|
+
iso: [AST_NODE_TYPES40.TSStringKeyword],
|
|
8760
|
+
number: [AST_NODE_TYPES40.TSNumberKeyword],
|
|
8761
|
+
int: [AST_NODE_TYPES40.TSNumberKeyword],
|
|
8762
|
+
float32: [AST_NODE_TYPES40.TSNumberKeyword],
|
|
8763
|
+
float64: [AST_NODE_TYPES40.TSNumberKeyword],
|
|
8764
|
+
boolean: [AST_NODE_TYPES40.TSBooleanKeyword],
|
|
8765
|
+
bigint: [AST_NODE_TYPES40.TSBigIntKeyword],
|
|
8766
|
+
symbol: [AST_NODE_TYPES40.TSSymbolKeyword],
|
|
8767
|
+
any: [AST_NODE_TYPES40.TSAnyKeyword],
|
|
8768
|
+
unknown: [AST_NODE_TYPES40.TSUnknownKeyword],
|
|
8769
|
+
never: [AST_NODE_TYPES40.TSNeverKeyword],
|
|
8770
|
+
void: [AST_NODE_TYPES40.TSVoidKeyword],
|
|
8771
|
+
null: [AST_NODE_TYPES40.TSNullKeyword],
|
|
8772
|
+
undefined: [AST_NODE_TYPES40.TSUndefinedKeyword],
|
|
8773
|
+
literal: [AST_NODE_TYPES40.TSLiteralType],
|
|
8774
|
+
date: [AST_NODE_TYPES40.TSTypeReference],
|
|
8775
|
+
array: [AST_NODE_TYPES40.TSArrayType, AST_NODE_TYPES40.TSTypeReference],
|
|
8776
|
+
tuple: [AST_NODE_TYPES40.TSTupleType],
|
|
8777
|
+
object: [AST_NODE_TYPES40.TSTypeLiteral, AST_NODE_TYPES40.TSTypeReference],
|
|
8778
|
+
strictObject: [AST_NODE_TYPES40.TSTypeLiteral, AST_NODE_TYPES40.TSTypeReference],
|
|
8779
|
+
looseObject: [AST_NODE_TYPES40.TSTypeLiteral, AST_NODE_TYPES40.TSTypeReference],
|
|
8780
|
+
record: [AST_NODE_TYPES40.TSTypeReference, AST_NODE_TYPES40.TSTypeLiteral],
|
|
8781
|
+
map: [AST_NODE_TYPES40.TSTypeReference],
|
|
8782
|
+
set: [AST_NODE_TYPES40.TSTypeReference],
|
|
8783
|
+
promise: [AST_NODE_TYPES40.TSTypeReference],
|
|
8784
|
+
enum: [AST_NODE_TYPES40.TSUnionType, AST_NODE_TYPES40.TSTypeReference, AST_NODE_TYPES40.TSLiteralType],
|
|
8785
|
+
nativeEnum: [AST_NODE_TYPES40.TSUnionType, AST_NODE_TYPES40.TSTypeReference, AST_NODE_TYPES40.TSLiteralType],
|
|
8786
|
+
union: [AST_NODE_TYPES40.TSUnionType, AST_NODE_TYPES40.TSTypeReference],
|
|
8787
|
+
discriminatedUnion: [AST_NODE_TYPES40.TSUnionType, AST_NODE_TYPES40.TSTypeReference],
|
|
8788
|
+
intersection: [AST_NODE_TYPES40.TSIntersectionType, AST_NODE_TYPES40.TSTypeReference]
|
|
8409
8789
|
};
|
|
8410
8790
|
function normalizeSchemaName(name) {
|
|
8411
8791
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -8414,20 +8794,20 @@ function normalizeTypeName(name) {
|
|
|
8414
8794
|
return name.replace(/Type$/, "").toLowerCase();
|
|
8415
8795
|
}
|
|
8416
8796
|
function unwrapNullish(annotation) {
|
|
8417
|
-
if (annotation.type !==
|
|
8797
|
+
if (annotation.type !== AST_NODE_TYPES40.TSUnionType) {
|
|
8418
8798
|
return {
|
|
8419
8799
|
core: annotation,
|
|
8420
|
-
nullable: annotation.type ===
|
|
8800
|
+
nullable: annotation.type === AST_NODE_TYPES40.TSNullKeyword
|
|
8421
8801
|
};
|
|
8422
8802
|
}
|
|
8423
8803
|
const rest = [];
|
|
8424
8804
|
let nullable = false;
|
|
8425
8805
|
for (const member of annotation.types) {
|
|
8426
|
-
if (member.type ===
|
|
8806
|
+
if (member.type === AST_NODE_TYPES40.TSNullKeyword) {
|
|
8427
8807
|
nullable = true;
|
|
8428
8808
|
continue;
|
|
8429
8809
|
}
|
|
8430
|
-
if (member.type ===
|
|
8810
|
+
if (member.type === AST_NODE_TYPES40.TSUndefinedKeyword) {
|
|
8431
8811
|
continue;
|
|
8432
8812
|
}
|
|
8433
8813
|
rest.push(member);
|
|
@@ -8492,14 +8872,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
8492
8872
|
function zodCallChain(node) {
|
|
8493
8873
|
const chain = [];
|
|
8494
8874
|
let current = node;
|
|
8495
|
-
while (current.type ===
|
|
8875
|
+
while (current.type === AST_NODE_TYPES40.CallExpression) {
|
|
8496
8876
|
const callee = current.callee;
|
|
8497
|
-
if (callee.type !==
|
|
8877
|
+
if (callee.type !== AST_NODE_TYPES40.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES40.Identifier) {
|
|
8498
8878
|
return null;
|
|
8499
8879
|
}
|
|
8500
8880
|
chain.push(current);
|
|
8501
8881
|
const receiver = callee.object;
|
|
8502
|
-
if (receiver.type ===
|
|
8882
|
+
if (receiver.type === AST_NODE_TYPES40.Identifier) {
|
|
8503
8883
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
8504
8884
|
}
|
|
8505
8885
|
current = receiver;
|
|
@@ -8508,19 +8888,19 @@ var prefer_zod_infer_default = createRule({
|
|
|
8508
8888
|
}
|
|
8509
8889
|
function methodName(call) {
|
|
8510
8890
|
const callee = call.callee;
|
|
8511
|
-
return callee.type ===
|
|
8891
|
+
return callee.type === AST_NODE_TYPES40.MemberExpression && callee.property.type === AST_NODE_TYPES40.Identifier ? callee.property.name : "";
|
|
8512
8892
|
}
|
|
8513
8893
|
function schemaField(node) {
|
|
8514
8894
|
const modifiers = [];
|
|
8515
8895
|
let current = node;
|
|
8516
8896
|
let leaf = null;
|
|
8517
|
-
while (current.type ===
|
|
8897
|
+
while (current.type === AST_NODE_TYPES40.CallExpression) {
|
|
8518
8898
|
const callee = current.callee;
|
|
8519
|
-
if (callee.type !==
|
|
8899
|
+
if (callee.type !== AST_NODE_TYPES40.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES40.Identifier) {
|
|
8520
8900
|
break;
|
|
8521
8901
|
}
|
|
8522
8902
|
const receiver = callee.object;
|
|
8523
|
-
if (receiver.type ===
|
|
8903
|
+
if (receiver.type === AST_NODE_TYPES40.Identifier && zodNamespaces.has(receiver.name)) {
|
|
8524
8904
|
leaf = callee.property.name;
|
|
8525
8905
|
break;
|
|
8526
8906
|
}
|
|
@@ -8551,16 +8931,16 @@ var prefer_zod_infer_default = createRule({
|
|
|
8551
8931
|
return null;
|
|
8552
8932
|
}
|
|
8553
8933
|
const shape = base.arguments[0];
|
|
8554
|
-
if (shape === void 0 || shape.type !==
|
|
8934
|
+
if (shape === void 0 || shape.type !== AST_NODE_TYPES40.ObjectExpression) {
|
|
8555
8935
|
return null;
|
|
8556
8936
|
}
|
|
8557
8937
|
const fields = /* @__PURE__ */ new Map();
|
|
8558
8938
|
for (const property of shape.properties) {
|
|
8559
|
-
if (property.type !==
|
|
8939
|
+
if (property.type !== AST_NODE_TYPES40.Property || property.computed) {
|
|
8560
8940
|
return null;
|
|
8561
8941
|
}
|
|
8562
8942
|
const { key } = property;
|
|
8563
|
-
const name = key.type ===
|
|
8943
|
+
const name = key.type === AST_NODE_TYPES40.Identifier ? key.name : key.type === AST_NODE_TYPES40.Literal && typeof key.value === "string" ? key.value : null;
|
|
8564
8944
|
if (name === null) {
|
|
8565
8945
|
return null;
|
|
8566
8946
|
}
|
|
@@ -8571,11 +8951,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
8571
8951
|
function typeMembers(members) {
|
|
8572
8952
|
const result = /* @__PURE__ */ new Map();
|
|
8573
8953
|
for (const member of members) {
|
|
8574
|
-
if (member.type !==
|
|
8954
|
+
if (member.type !== AST_NODE_TYPES40.TSPropertySignature || member.computed) {
|
|
8575
8955
|
return null;
|
|
8576
8956
|
}
|
|
8577
8957
|
const { key } = member;
|
|
8578
|
-
const name = key.type ===
|
|
8958
|
+
const name = key.type === AST_NODE_TYPES40.Identifier ? key.name : key.type === AST_NODE_TYPES40.Literal && typeof key.value === "string" ? key.value : null;
|
|
8579
8959
|
if (name === null) {
|
|
8580
8960
|
return null;
|
|
8581
8961
|
}
|
|
@@ -8589,8 +8969,8 @@ var prefer_zod_infer_default = createRule({
|
|
|
8589
8969
|
return result.size === 0 ? null : result;
|
|
8590
8970
|
}
|
|
8591
8971
|
function collectConstrainedNames(node) {
|
|
8592
|
-
if (node.type ===
|
|
8593
|
-
if (node.typeName.type ===
|
|
8972
|
+
if (node.type === AST_NODE_TYPES40.TSTypeReference) {
|
|
8973
|
+
if (node.typeName.type === AST_NODE_TYPES40.Identifier) {
|
|
8594
8974
|
constrainedTypeNames.add(node.typeName.name);
|
|
8595
8975
|
}
|
|
8596
8976
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -8598,11 +8978,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
8598
8978
|
}
|
|
8599
8979
|
return;
|
|
8600
8980
|
}
|
|
8601
|
-
if (node.type ===
|
|
8981
|
+
if (node.type === AST_NODE_TYPES40.TSArrayType) {
|
|
8602
8982
|
collectConstrainedNames(node.elementType);
|
|
8603
8983
|
return;
|
|
8604
8984
|
}
|
|
8605
|
-
if (node.type ===
|
|
8985
|
+
if (node.type === AST_NODE_TYPES40.TSUnionType || node.type === AST_NODE_TYPES40.TSIntersectionType) {
|
|
8606
8986
|
for (const member of node.types) {
|
|
8607
8987
|
collectConstrainedNames(member);
|
|
8608
8988
|
}
|
|
@@ -8646,13 +9026,13 @@ var prefer_zod_infer_default = createRule({
|
|
|
8646
9026
|
return;
|
|
8647
9027
|
}
|
|
8648
9028
|
for (const specifier of node.specifiers) {
|
|
8649
|
-
if (specifier.type ===
|
|
9029
|
+
if (specifier.type === AST_NODE_TYPES40.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES40.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES40.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES40.Identifier && specifier.imported.name === "z") {
|
|
8650
9030
|
zodNamespaces.add(specifier.local.name);
|
|
8651
9031
|
}
|
|
8652
9032
|
}
|
|
8653
9033
|
},
|
|
8654
9034
|
VariableDeclarator(node) {
|
|
8655
|
-
if (node.id.type !==
|
|
9035
|
+
if (node.id.type !== AST_NODE_TYPES40.Identifier || node.init == null) {
|
|
8656
9036
|
return;
|
|
8657
9037
|
}
|
|
8658
9038
|
const fields = schemaFields(node.init);
|
|
@@ -8660,16 +9040,16 @@ var prefer_zod_infer_default = createRule({
|
|
|
8660
9040
|
schemas.push({ name: node.id.name, fields });
|
|
8661
9041
|
}
|
|
8662
9042
|
},
|
|
8663
|
-
/**
|
|
9043
|
+
/** Records `XSchema.transform(...)` and equivalent module-level reshaping. */
|
|
8664
9044
|
"MemberExpression[computed=false]"(node) {
|
|
8665
|
-
if (node.object.type ===
|
|
9045
|
+
if (node.object.type === AST_NODE_TYPES40.Identifier && node.property.type === AST_NODE_TYPES40.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
8666
9046
|
reshapedSchemaNames.add(node.object.name);
|
|
8667
9047
|
}
|
|
8668
9048
|
},
|
|
8669
|
-
/**
|
|
9049
|
+
/** Records every type argument carried by a Zod constraint. */
|
|
8670
9050
|
TSTypeReference(node) {
|
|
8671
9051
|
const { typeName } = node;
|
|
8672
|
-
const referenced = typeName.type ===
|
|
9052
|
+
const referenced = typeName.type === AST_NODE_TYPES40.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES40.TSQualifiedName && typeName.right.type === AST_NODE_TYPES40.Identifier ? typeName.right.name : null;
|
|
8673
9053
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
8674
9054
|
return;
|
|
8675
9055
|
}
|
|
@@ -8687,7 +9067,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
8687
9067
|
}
|
|
8688
9068
|
},
|
|
8689
9069
|
TSTypeAliasDeclaration(node) {
|
|
8690
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
9070
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== AST_NODE_TYPES40.TSTypeLiteral) {
|
|
8691
9071
|
return;
|
|
8692
9072
|
}
|
|
8693
9073
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -8732,10 +9112,10 @@ var prefer_zod_infer_default = createRule({
|
|
|
8732
9112
|
});
|
|
8733
9113
|
|
|
8734
9114
|
// src/rules/require-assert-never.ts
|
|
8735
|
-
import { AST_NODE_TYPES as
|
|
9115
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES41 } from "@typescript-eslint/utils";
|
|
8736
9116
|
var isRuntimeHandlingStatement = (statement) => {
|
|
8737
|
-
if (statement.type ===
|
|
8738
|
-
if (statement.type ===
|
|
9117
|
+
if (statement.type === AST_NODE_TYPES41.EmptyStatement) return false;
|
|
9118
|
+
if (statement.type === AST_NODE_TYPES41.BlockStatement) {
|
|
8739
9119
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
8740
9120
|
}
|
|
8741
9121
|
return true;
|
|
@@ -8751,7 +9131,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
8751
9131
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
8752
9132
|
}
|
|
8753
9133
|
const only = defaultCase.consequent[0];
|
|
8754
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
9134
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === AST_NODE_TYPES41.BlockStatement && only.body.length === 0) {
|
|
8755
9135
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
8756
9136
|
}
|
|
8757
9137
|
return false;
|
|
@@ -8791,7 +9171,7 @@ var require_assert_never_default = createRule({
|
|
|
8791
9171
|
});
|
|
8792
9172
|
|
|
8793
9173
|
// src/rules/require-fetch-timeout.ts
|
|
8794
|
-
import { AST_NODE_TYPES as
|
|
9174
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES42, ASTUtils as ASTUtils2 } from "@typescript-eslint/utils";
|
|
8795
9175
|
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set([
|
|
8796
9176
|
"globalThis",
|
|
8797
9177
|
"window",
|
|
@@ -8807,14 +9187,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
8807
9187
|
return false;
|
|
8808
9188
|
}
|
|
8809
9189
|
function initProvablyLacksSignal(init) {
|
|
8810
|
-
if (init.type !==
|
|
9190
|
+
if (init.type !== AST_NODE_TYPES42.ObjectExpression) {
|
|
8811
9191
|
return false;
|
|
8812
9192
|
}
|
|
8813
9193
|
for (const prop of init.properties) {
|
|
8814
|
-
if (prop.type ===
|
|
9194
|
+
if (prop.type === AST_NODE_TYPES42.SpreadElement) {
|
|
8815
9195
|
return false;
|
|
8816
9196
|
}
|
|
8817
|
-
if (prop.key.type ===
|
|
9197
|
+
if (prop.key.type === AST_NODE_TYPES42.Identifier && prop.key.name === "signal" || prop.key.type === AST_NODE_TYPES42.Literal && prop.key.value === "signal") {
|
|
8818
9198
|
return false;
|
|
8819
9199
|
}
|
|
8820
9200
|
if (prop.computed) {
|
|
@@ -8824,7 +9204,7 @@ function initProvablyLacksSignal(init) {
|
|
|
8824
9204
|
return true;
|
|
8825
9205
|
}
|
|
8826
9206
|
function isStringish(node) {
|
|
8827
|
-
return node.type ===
|
|
9207
|
+
return node.type === AST_NODE_TYPES42.Literal && typeof node.value === "string" || node.type === AST_NODE_TYPES42.TemplateLiteral;
|
|
8828
9208
|
}
|
|
8829
9209
|
var require_fetch_timeout_default = createRule({
|
|
8830
9210
|
name: "require-fetch-timeout",
|
|
@@ -8865,10 +9245,10 @@ var require_fetch_timeout_default = createRule({
|
|
|
8865
9245
|
return variable === null || variable.defs.length === 0;
|
|
8866
9246
|
}
|
|
8867
9247
|
function isGlobalFetchCall2(callee) {
|
|
8868
|
-
if (callee.type ===
|
|
9248
|
+
if (callee.type === AST_NODE_TYPES42.Identifier) {
|
|
8869
9249
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
8870
9250
|
}
|
|
8871
|
-
return callee.type ===
|
|
9251
|
+
return callee.type === AST_NODE_TYPES42.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES42.Identifier && callee.property.name === "fetch" && callee.object.type === AST_NODE_TYPES42.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
8872
9252
|
}
|
|
8873
9253
|
return {
|
|
8874
9254
|
CallExpression(node) {
|
|
@@ -8888,7 +9268,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
8888
9268
|
});
|
|
8889
9269
|
|
|
8890
9270
|
// src/rules/require-interface-for-injected-service.ts
|
|
8891
|
-
import { AST_NODE_TYPES as
|
|
9271
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES43 } from "@typescript-eslint/utils";
|
|
8892
9272
|
var CONFIGISH_TYPE_RE = /(?:Options|Opts|Config|Configuration|Settings|Params|Props|Args|Env|Environment|Callbacks|Flags)$/;
|
|
8893
9273
|
var CONFIGISH_NAME_RE = /^(?:options|opts|config|configuration|settings|params|props|args|env|environment|callbacks|flags|logger|log|clock)$/i;
|
|
8894
9274
|
var HTTP_TRANSPORT_TYPE_RE = /^(?:KyInstance|AxiosInstance|Session)$/;
|
|
@@ -8896,20 +9276,20 @@ var BUILTIN_CONTAINER_TYPE_RE = /^(?:Record|Map|WeakMap|Set|WeakSet|Array|Readon
|
|
|
8896
9276
|
var TRANSPORT_WRAPPER_NAME_RE = /Client$/;
|
|
8897
9277
|
var ROUTER_FACTORY_NAME = "Router";
|
|
8898
9278
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
8899
|
-
var isExportedClass = (node) => node.parent.type ===
|
|
8900
|
-
var qualifiedName = (name) => name.type ===
|
|
9279
|
+
var isExportedClass = (node) => node.parent.type === AST_NODE_TYPES43.ExportNamedDeclaration || node.parent.type === AST_NODE_TYPES43.ExportDefaultDeclaration;
|
|
9280
|
+
var qualifiedName = (name) => name.type === AST_NODE_TYPES43.Identifier ? name.name : name.type === AST_NODE_TYPES43.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
8901
9281
|
var readTypeReference = (annotation) => {
|
|
8902
|
-
if (annotation === void 0 || annotation.type !==
|
|
9282
|
+
if (annotation === void 0 || annotation.type !== AST_NODE_TYPES43.TSTypeReference) return null;
|
|
8903
9283
|
const { typeName } = annotation;
|
|
8904
|
-
const rightmost = typeName.type ===
|
|
9284
|
+
const rightmost = typeName.type === AST_NODE_TYPES43.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES43.TSQualifiedName ? typeName.right.name : null;
|
|
8905
9285
|
if (rightmost === null) return null;
|
|
8906
9286
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
8907
9287
|
};
|
|
8908
9288
|
var namedParameterCollaborator = (annotated) => {
|
|
8909
9289
|
let target = annotated;
|
|
8910
|
-
if (target.type ===
|
|
8911
|
-
if (target.type ===
|
|
8912
|
-
if (target.type !==
|
|
9290
|
+
if (target.type === AST_NODE_TYPES43.TSParameterProperty) target = target.parameter;
|
|
9291
|
+
if (target.type === AST_NODE_TYPES43.AssignmentPattern) target = target.left;
|
|
9292
|
+
if (target.type !== AST_NODE_TYPES43.Identifier) return null;
|
|
8913
9293
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
8914
9294
|
if (reference === null) return null;
|
|
8915
9295
|
return { name: target.name, ...reference };
|
|
@@ -8917,8 +9297,8 @@ var namedParameterCollaborator = (annotated) => {
|
|
|
8917
9297
|
var propertySignatureTypes = (members) => {
|
|
8918
9298
|
const types = /* @__PURE__ */ new Map();
|
|
8919
9299
|
for (const member of members) {
|
|
8920
|
-
if (member.type !==
|
|
8921
|
-
if (member.computed || member.key.type !==
|
|
9300
|
+
if (member.type !== AST_NODE_TYPES43.TSPropertySignature) continue;
|
|
9301
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES43.Identifier) continue;
|
|
8922
9302
|
const reference = readTypeReference(member.typeAnnotation?.typeAnnotation);
|
|
8923
9303
|
if (reference === null) continue;
|
|
8924
9304
|
types.set(member.key.name, reference);
|
|
@@ -8929,18 +9309,18 @@ var fileTypeIndex = (program) => {
|
|
|
8929
9309
|
const objects = /* @__PURE__ */ new Map();
|
|
8930
9310
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
8931
9311
|
for (const statement of program.body) {
|
|
8932
|
-
const declaration = statement.type ===
|
|
8933
|
-
if (declaration?.type ===
|
|
9312
|
+
const declaration = statement.type === AST_NODE_TYPES43.ExportNamedDeclaration ? statement.declaration : statement;
|
|
9313
|
+
if (declaration?.type === AST_NODE_TYPES43.TSInterfaceDeclaration) {
|
|
8934
9314
|
objects.set(declaration.id.name, propertySignatureTypes(declaration.body.body));
|
|
8935
9315
|
continue;
|
|
8936
9316
|
}
|
|
8937
|
-
if (declaration?.type !==
|
|
9317
|
+
if (declaration?.type !== AST_NODE_TYPES43.TSTypeAliasDeclaration) continue;
|
|
8938
9318
|
const aliased = declaration.typeAnnotation;
|
|
8939
|
-
if (aliased.type ===
|
|
9319
|
+
if (aliased.type === AST_NODE_TYPES43.TSFunctionType || aliased.type === AST_NODE_TYPES43.TSConstructorType) {
|
|
8940
9320
|
functionAliases.add(declaration.id.name);
|
|
8941
9321
|
continue;
|
|
8942
9322
|
}
|
|
8943
|
-
const literals = aliased.type ===
|
|
9323
|
+
const literals = aliased.type === AST_NODE_TYPES43.TSTypeLiteral ? [aliased] : aliased.type === AST_NODE_TYPES43.TSIntersectionType ? aliased.types.filter((part) => part.type === AST_NODE_TYPES43.TSTypeLiteral) : [];
|
|
8944
9324
|
if (literals.length === 0) continue;
|
|
8945
9325
|
const merged = /* @__PURE__ */ new Map();
|
|
8946
9326
|
for (const literal of literals) {
|
|
@@ -8953,10 +9333,10 @@ var fileTypeIndex = (program) => {
|
|
|
8953
9333
|
return { objects, functionAliases };
|
|
8954
9334
|
};
|
|
8955
9335
|
var bagMemberTypes = (annotation, declared) => {
|
|
8956
|
-
if (annotation.type ===
|
|
9336
|
+
if (annotation.type === AST_NODE_TYPES43.TSTypeLiteral) {
|
|
8957
9337
|
return propertySignatureTypes(annotation.members);
|
|
8958
9338
|
}
|
|
8959
|
-
if (annotation.type !==
|
|
9339
|
+
if (annotation.type !== AST_NODE_TYPES43.TSTypeReference || annotation.typeName.type !== AST_NODE_TYPES43.Identifier) {
|
|
8960
9340
|
return null;
|
|
8961
9341
|
}
|
|
8962
9342
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
@@ -8968,11 +9348,11 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
8968
9348
|
if (members === null) return [];
|
|
8969
9349
|
const collaborators = [];
|
|
8970
9350
|
for (const property of pattern.properties) {
|
|
8971
|
-
if (property.type !==
|
|
8972
|
-
if (property.key.type !==
|
|
9351
|
+
if (property.type !== AST_NODE_TYPES43.Property || property.computed) continue;
|
|
9352
|
+
if (property.key.type !== AST_NODE_TYPES43.Identifier) continue;
|
|
8973
9353
|
const key = property.key.name;
|
|
8974
|
-
const bound = property.value.type ===
|
|
8975
|
-
if (bound.type !==
|
|
9354
|
+
const bound = property.value.type === AST_NODE_TYPES43.AssignmentPattern ? property.value.left : property.value;
|
|
9355
|
+
if (bound.type !== AST_NODE_TYPES43.Identifier) continue;
|
|
8976
9356
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
8977
9357
|
const reference = members.get(key);
|
|
8978
9358
|
if (reference === void 0) continue;
|
|
@@ -8982,8 +9362,8 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
8982
9362
|
};
|
|
8983
9363
|
var parameterCollaborators = (parameter, declared) => {
|
|
8984
9364
|
let target = parameter;
|
|
8985
|
-
if (target.type ===
|
|
8986
|
-
if (target.type ===
|
|
9365
|
+
if (target.type === AST_NODE_TYPES43.AssignmentPattern) target = target.left;
|
|
9366
|
+
if (target.type === AST_NODE_TYPES43.ObjectPattern) {
|
|
8987
9367
|
return objectPatternCollaborators(target, declared);
|
|
8988
9368
|
}
|
|
8989
9369
|
const named2 = namedParameterCollaborator(parameter);
|
|
@@ -8997,22 +9377,22 @@ var typeParameterNames = (...declarations) => {
|
|
|
8997
9377
|
return names;
|
|
8998
9378
|
};
|
|
8999
9379
|
var readConstructor = (ctor, declared, typeParameters) => {
|
|
9000
|
-
const
|
|
9380
|
+
const body2 = ctor.value.body;
|
|
9001
9381
|
const storedFrom = /* @__PURE__ */ new Set();
|
|
9002
9382
|
let constructedFields = 0;
|
|
9003
|
-
if (
|
|
9004
|
-
for (const statement of
|
|
9005
|
-
if (statement.type !==
|
|
9383
|
+
if (body2 !== null && body2 !== void 0) {
|
|
9384
|
+
for (const statement of body2.body) {
|
|
9385
|
+
if (statement.type !== AST_NODE_TYPES43.ExpressionStatement) continue;
|
|
9006
9386
|
const expression = statement.expression;
|
|
9007
|
-
if (expression.type !==
|
|
9387
|
+
if (expression.type !== AST_NODE_TYPES43.AssignmentExpression || expression.operator !== "=" || expression.left.type !== AST_NODE_TYPES43.MemberExpression || expression.left.object.type !== AST_NODE_TYPES43.ThisExpression) {
|
|
9008
9388
|
continue;
|
|
9009
9389
|
}
|
|
9010
9390
|
const source = expression.right;
|
|
9011
|
-
if (source.type ===
|
|
9391
|
+
if (source.type === AST_NODE_TYPES43.NewExpression) {
|
|
9012
9392
|
constructedFields += 1;
|
|
9013
|
-
} else if (source.type ===
|
|
9393
|
+
} else if (source.type === AST_NODE_TYPES43.Identifier) {
|
|
9014
9394
|
storedFrom.add(source.name);
|
|
9015
|
-
} else if (source.type ===
|
|
9395
|
+
} else if (source.type === AST_NODE_TYPES43.MemberExpression && source.object.type === AST_NODE_TYPES43.Identifier) {
|
|
9016
9396
|
storedFrom.add(source.object.name);
|
|
9017
9397
|
}
|
|
9018
9398
|
}
|
|
@@ -9020,7 +9400,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
9020
9400
|
const collaborators = [];
|
|
9021
9401
|
for (const parameter of ctor.value.params) {
|
|
9022
9402
|
for (const reference of parameterCollaborators(parameter, declared)) {
|
|
9023
|
-
const stored = parameter.type ===
|
|
9403
|
+
const stored = parameter.type === AST_NODE_TYPES43.TSParameterProperty || storedFrom.has(reference.name);
|
|
9024
9404
|
if (!stored) continue;
|
|
9025
9405
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
9026
9406
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -9053,20 +9433,20 @@ var subtreeHas = (root, found) => {
|
|
|
9053
9433
|
visit(root);
|
|
9054
9434
|
return hit;
|
|
9055
9435
|
};
|
|
9056
|
-
var isFrameworkWiring = (
|
|
9057
|
-
if (node.type ===
|
|
9436
|
+
var isFrameworkWiring = (body2) => subtreeHas(body2, (node) => {
|
|
9437
|
+
if (node.type === AST_NODE_TYPES43.CallExpression) {
|
|
9058
9438
|
const { callee } = node;
|
|
9059
|
-
if (callee.type ===
|
|
9060
|
-
return callee.type ===
|
|
9439
|
+
if (callee.type === AST_NODE_TYPES43.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
9440
|
+
return callee.type === AST_NODE_TYPES43.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES43.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
9061
9441
|
}
|
|
9062
|
-
return node.type ===
|
|
9442
|
+
return node.type === AST_NODE_TYPES43.TSTypeReference && node.typeName.type === AST_NODE_TYPES43.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
9063
9443
|
});
|
|
9064
9444
|
var stem2 = (name) => name.replace(/^I(?=[A-Z])/, "").replace(/Impl$/, "");
|
|
9065
9445
|
var fileInterfaceNames = (program) => {
|
|
9066
9446
|
const names = [];
|
|
9067
9447
|
for (const statement of program.body) {
|
|
9068
|
-
const declaration = statement.type ===
|
|
9069
|
-
if (declaration?.type ===
|
|
9448
|
+
const declaration = statement.type === AST_NODE_TYPES43.ExportNamedDeclaration ? statement.declaration : statement;
|
|
9449
|
+
if (declaration?.type === AST_NODE_TYPES43.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
9070
9450
|
}
|
|
9071
9451
|
return names;
|
|
9072
9452
|
};
|
|
@@ -9081,14 +9461,14 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
9081
9461
|
return target.endsWith(other) || other.endsWith(target);
|
|
9082
9462
|
});
|
|
9083
9463
|
};
|
|
9084
|
-
var publicMethodNames = (
|
|
9464
|
+
var publicMethodNames = (body2) => {
|
|
9085
9465
|
const names = [];
|
|
9086
|
-
for (const member of
|
|
9087
|
-
if (member.type !==
|
|
9466
|
+
for (const member of body2.body) {
|
|
9467
|
+
if (member.type !== AST_NODE_TYPES43.MethodDefinition) continue;
|
|
9088
9468
|
if (member.kind !== "method" || member.static) continue;
|
|
9089
9469
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
9090
|
-
if (member.key.type ===
|
|
9091
|
-
if (member.key.type ===
|
|
9470
|
+
if (member.key.type === AST_NODE_TYPES43.PrivateIdentifier) continue;
|
|
9471
|
+
if (member.key.type === AST_NODE_TYPES43.Identifier) names.push(member.key.name);
|
|
9092
9472
|
else names.push("\u2026");
|
|
9093
9473
|
}
|
|
9094
9474
|
return names;
|
|
@@ -9121,7 +9501,7 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
9121
9501
|
if (node.implements.length > 0) return;
|
|
9122
9502
|
if (node.decorators.length > 0) return;
|
|
9123
9503
|
const ctor = node.body.body.find(
|
|
9124
|
-
(member) => member.type ===
|
|
9504
|
+
(member) => member.type === AST_NODE_TYPES43.MethodDefinition && member.kind === "constructor"
|
|
9125
9505
|
);
|
|
9126
9506
|
if (ctor === void 0) return;
|
|
9127
9507
|
const { collaborators, constructedFields } = readConstructor(
|
|
@@ -9150,18 +9530,18 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
9150
9530
|
});
|
|
9151
9531
|
|
|
9152
9532
|
// src/rules/require-zod-form-validation.ts
|
|
9153
|
-
import { AST_NODE_TYPES as
|
|
9533
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES44 } from "@typescript-eslint/utils";
|
|
9154
9534
|
var looksLikeZodSchema = (node) => {
|
|
9155
9535
|
let current = node;
|
|
9156
9536
|
while (true) {
|
|
9157
|
-
if (current.type ===
|
|
9537
|
+
if (current.type === AST_NODE_TYPES44.Identifier) {
|
|
9158
9538
|
return current.name === "z" || ZOD_SCHEMA_NAME_RE.test(current.name);
|
|
9159
9539
|
}
|
|
9160
|
-
if (current.type ===
|
|
9540
|
+
if (current.type === AST_NODE_TYPES44.CallExpression) {
|
|
9161
9541
|
current = current.callee;
|
|
9162
9542
|
continue;
|
|
9163
9543
|
}
|
|
9164
|
-
if (current.type ===
|
|
9544
|
+
if (current.type === AST_NODE_TYPES44.MemberExpression) {
|
|
9165
9545
|
current = current.object;
|
|
9166
9546
|
continue;
|
|
9167
9547
|
}
|
|
@@ -9169,23 +9549,23 @@ var looksLikeZodSchema = (node) => {
|
|
|
9169
9549
|
}
|
|
9170
9550
|
};
|
|
9171
9551
|
var isZodParseCall = (node) => {
|
|
9172
|
-
if (node.type !==
|
|
9552
|
+
if (node.type !== AST_NODE_TYPES44.CallExpression) return false;
|
|
9173
9553
|
const callee = node.callee;
|
|
9174
|
-
if (callee.type !==
|
|
9554
|
+
if (callee.type !== AST_NODE_TYPES44.MemberExpression) return false;
|
|
9175
9555
|
if (callee.computed) return false;
|
|
9176
|
-
if (callee.property.type !==
|
|
9556
|
+
if (callee.property.type !== AST_NODE_TYPES44.Identifier) return false;
|
|
9177
9557
|
const method = callee.property.name;
|
|
9178
9558
|
if (method !== "parse" && method !== "safeParse") return false;
|
|
9179
9559
|
return looksLikeZodSchema(callee.object);
|
|
9180
9560
|
};
|
|
9181
9561
|
var isFormDataMethodCall = (node) => {
|
|
9182
9562
|
let current = node;
|
|
9183
|
-
if (current.type ===
|
|
9563
|
+
if (current.type === AST_NODE_TYPES44.AwaitExpression) {
|
|
9184
9564
|
current = current.argument;
|
|
9185
9565
|
}
|
|
9186
|
-
if (current.type !==
|
|
9566
|
+
if (current.type !== AST_NODE_TYPES44.CallExpression) return false;
|
|
9187
9567
|
const callee = current.callee;
|
|
9188
|
-
return callee.type ===
|
|
9568
|
+
return callee.type === AST_NODE_TYPES44.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES44.Identifier && callee.property.name === "formData";
|
|
9189
9569
|
};
|
|
9190
9570
|
var require_zod_form_validation_default = createRule({
|
|
9191
9571
|
name: "require-zod-form-validation",
|
|
@@ -9205,14 +9585,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
9205
9585
|
return {};
|
|
9206
9586
|
}
|
|
9207
9587
|
const isFormSourceIdentifier = (node) => {
|
|
9208
|
-
if (node.type !==
|
|
9588
|
+
if (node.type !== AST_NODE_TYPES44.Identifier) return false;
|
|
9209
9589
|
if (/formdata/i.test(node.name)) return true;
|
|
9210
9590
|
let scope = context.sourceCode.getScope(node);
|
|
9211
9591
|
while (scope !== null) {
|
|
9212
9592
|
const variable = scope.set.get(node.name);
|
|
9213
9593
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
9214
9594
|
const def = variable.defs[0];
|
|
9215
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
9595
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === AST_NODE_TYPES44.VariableDeclarator && def.node.init !== null) {
|
|
9216
9596
|
return isFormDataMethodCall(def.node.init);
|
|
9217
9597
|
}
|
|
9218
9598
|
return false;
|
|
@@ -9223,8 +9603,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
9223
9603
|
};
|
|
9224
9604
|
const isFormDataGetCall = (node) => {
|
|
9225
9605
|
const callee = node.callee;
|
|
9226
|
-
if (callee.type !==
|
|
9227
|
-
if (callee.property.type !==
|
|
9606
|
+
if (callee.type !== AST_NODE_TYPES44.MemberExpression) return false;
|
|
9607
|
+
if (callee.property.type !== AST_NODE_TYPES44.Identifier || callee.property.name !== "get") {
|
|
9228
9608
|
return false;
|
|
9229
9609
|
}
|
|
9230
9610
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -9239,11 +9619,11 @@ var require_zod_form_validation_default = createRule({
|
|
|
9239
9619
|
};
|
|
9240
9620
|
const isInstanceofNarrowing = (node) => {
|
|
9241
9621
|
const parent = node.parent;
|
|
9242
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
9622
|
+
return parent !== null && parent !== void 0 && parent.type === AST_NODE_TYPES44.BinaryExpression && parent.operator === "instanceof" && parent.left === node && parent.right.type === AST_NODE_TYPES44.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
9243
9623
|
};
|
|
9244
9624
|
const boundDeclarator = (node) => {
|
|
9245
9625
|
const parent = node.parent;
|
|
9246
|
-
if (parent.type ===
|
|
9626
|
+
if (parent.type === AST_NODE_TYPES44.VariableDeclarator && parent.init === node && parent.id.type === AST_NODE_TYPES44.Identifier) {
|
|
9247
9627
|
return parent;
|
|
9248
9628
|
}
|
|
9249
9629
|
return null;
|
|
@@ -9302,7 +9682,7 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
9302
9682
|
});
|
|
9303
9683
|
|
|
9304
9684
|
// src/rules/zod-naming-convention.ts
|
|
9305
|
-
import { AST_NODE_TYPES as
|
|
9685
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES45 } from "@typescript-eslint/utils";
|
|
9306
9686
|
var CONVENTIONS = {
|
|
9307
9687
|
prefix: { test: ZOD_PREFIX_RE, messageId: "zPrefix" },
|
|
9308
9688
|
suffix: { test: ZOD_SUFFIX_RE, messageId: "schemaSuffix" },
|
|
@@ -9327,15 +9707,15 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
9327
9707
|
"registry",
|
|
9328
9708
|
"implement"
|
|
9329
9709
|
]);
|
|
9330
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
9710
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === AST_NODE_TYPES45.Identifier ? callee.property.name : null;
|
|
9331
9711
|
var calleeChainStartsWithZ = (node) => {
|
|
9332
9712
|
let current = node;
|
|
9333
|
-
while (current.type ===
|
|
9713
|
+
while (current.type === AST_NODE_TYPES45.MemberExpression) {
|
|
9334
9714
|
const receiver = current.object;
|
|
9335
|
-
if (receiver.type ===
|
|
9715
|
+
if (receiver.type === AST_NODE_TYPES45.Identifier && receiver.name === "z") {
|
|
9336
9716
|
return true;
|
|
9337
9717
|
}
|
|
9338
|
-
if (receiver.type ===
|
|
9718
|
+
if (receiver.type === AST_NODE_TYPES45.CallExpression) {
|
|
9339
9719
|
current = receiver.callee;
|
|
9340
9720
|
continue;
|
|
9341
9721
|
}
|
|
@@ -9380,13 +9760,13 @@ var zod_naming_convention_default = createRule({
|
|
|
9380
9760
|
VariableDeclarator(node) {
|
|
9381
9761
|
const init = node.init;
|
|
9382
9762
|
if (init === null || init === void 0) return;
|
|
9383
|
-
if (init.type !==
|
|
9763
|
+
if (init.type !== AST_NODE_TYPES45.CallExpression) return;
|
|
9384
9764
|
const callee = init.callee;
|
|
9385
|
-
if (callee.type !==
|
|
9765
|
+
if (callee.type !== AST_NODE_TYPES45.MemberExpression) return;
|
|
9386
9766
|
if (!calleeChainStartsWithZ(callee)) return;
|
|
9387
9767
|
const terminal = terminalMethodName(callee);
|
|
9388
9768
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
9389
|
-
if (node.id.type !==
|
|
9769
|
+
if (node.id.type !== AST_NODE_TYPES45.Identifier) return;
|
|
9390
9770
|
if (test.test(node.id.name)) return;
|
|
9391
9771
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
9392
9772
|
context.report({
|
|
@@ -9410,47 +9790,47 @@ var renamedRules = {
|
|
|
9410
9790
|
var retiredRules = {
|
|
9411
9791
|
"ban-loose-type-guards-in-tests": {
|
|
9412
9792
|
removedIn: "5.0.0",
|
|
9413
|
-
reason: "
|
|
9793
|
+
reason: "Delete the config entry and suppressions; there is no replacement."
|
|
9414
9794
|
},
|
|
9415
9795
|
"no-implicit-attribute-access": {
|
|
9416
9796
|
removedIn: "5.0.0",
|
|
9417
|
-
reason: "
|
|
9797
|
+
reason: "Delete the config entry and suppressions; there is no replacement."
|
|
9418
9798
|
},
|
|
9419
9799
|
"no-sequential-await": {
|
|
9420
9800
|
removedIn: "3.0.0",
|
|
9421
|
-
reason: "
|
|
9801
|
+
reason: "Delete the entry; core `no-await-in-loop` covers it."
|
|
9422
9802
|
},
|
|
9423
9803
|
"no-template-literal-in-log": {
|
|
9424
9804
|
removedIn: "2.3.1",
|
|
9425
|
-
reason: "
|
|
9805
|
+
reason: "Delete the config entry and suppressions; there is no replacement."
|
|
9426
9806
|
},
|
|
9427
9807
|
"no-unsafe-cast": {
|
|
9428
9808
|
removedIn: "3.0.0",
|
|
9429
|
-
reason:
|
|
9809
|
+
reason: "Delete the entry; keep `@typescript-eslint/consistent-type-assertions` enabled."
|
|
9430
9810
|
},
|
|
9431
9811
|
"prefer-setup-file-mocks": {
|
|
9432
9812
|
removedIn: "5.0.0",
|
|
9433
|
-
reason: "
|
|
9813
|
+
reason: "Delete the config entry and suppressions; there is no replacement."
|
|
9434
9814
|
},
|
|
9435
9815
|
"prefer-shadcn": {
|
|
9436
9816
|
removedIn: "3.0.0",
|
|
9437
|
-
reason: "
|
|
9817
|
+
reason: "Delete the entry; use `react/forbid-elements` for element restrictions."
|
|
9438
9818
|
},
|
|
9439
9819
|
"primary-export-file-name": {
|
|
9440
9820
|
removedIn: "4.0.0",
|
|
9441
|
-
reason: "
|
|
9821
|
+
reason: "Delete the config entry and suppressions; there is no replacement."
|
|
9442
9822
|
},
|
|
9443
9823
|
"require-parameterized-tests": {
|
|
9444
9824
|
removedIn: "4.0.0",
|
|
9445
|
-
reason: "
|
|
9825
|
+
reason: "Delete stale references; the rule was never registered."
|
|
9446
9826
|
},
|
|
9447
9827
|
"require-schema-validate-search": {
|
|
9448
9828
|
removedIn: "3.0.0",
|
|
9449
|
-
reason: "
|
|
9829
|
+
reason: "Delete the entry; use `@typescript-eslint/consistent-type-assertions`."
|
|
9450
9830
|
},
|
|
9451
9831
|
"single-public-export": {
|
|
9452
9832
|
removedIn: "3.0.0",
|
|
9453
|
-
reason: "
|
|
9833
|
+
reason: "Delete the config entry and suppressions; there is no replacement."
|
|
9454
9834
|
}
|
|
9455
9835
|
};
|
|
9456
9836
|
|
|
@@ -9469,6 +9849,7 @@ var rules = {
|
|
|
9469
9849
|
"no-insecure-random-id": no_insecure_random_id_default,
|
|
9470
9850
|
"no-json-stringify-error": no_json_stringify_error_default,
|
|
9471
9851
|
"no-log-only-catch": no_log_only_catch_default,
|
|
9852
|
+
"no-long-comment": no_long_comment_default,
|
|
9472
9853
|
"no-offset-pagination": no_offset_pagination_default,
|
|
9473
9854
|
"no-positional-tuple-return": no_positional_tuple_return_default,
|
|
9474
9855
|
"no-raw-env": no_raw_env_default,
|
|
@@ -9484,6 +9865,7 @@ var rules = {
|
|
|
9484
9865
|
"no-storage-in-stateless-modules": no_storage_in_stateless_modules_default,
|
|
9485
9866
|
"no-string-concat-in-loop": no_string_concat_in_loop_default,
|
|
9486
9867
|
"no-tautological-expect": no_tautological_expect_default,
|
|
9868
|
+
"no-typed-doc-sections": no_typed_doc_sections_default,
|
|
9487
9869
|
"no-trailing-value-narration": no_trailing_value_narration_default,
|
|
9488
9870
|
"no-declaration-comment-wall": no_declaration_comment_wall_default,
|
|
9489
9871
|
"no-union-in-comment": no_union_in_comment_default,
|
|
@@ -9499,6 +9881,7 @@ var rules = {
|
|
|
9499
9881
|
"prefer-schema-for-api-payload": prefer_schema_for_api_payload_default,
|
|
9500
9882
|
"prefer-semantic-colors": prefer_semantic_colors_default,
|
|
9501
9883
|
"prefer-server-actions": prefer_server_actions_default,
|
|
9884
|
+
"prefer-single-sentence-comment": prefer_single_sentence_comment_default,
|
|
9502
9885
|
"prefer-string-literal-union": prefer_string_literal_union_default,
|
|
9503
9886
|
"prefer-whole-object-assertion": prefer_whole_object_assertion_default,
|
|
9504
9887
|
"prefer-zod-enum": prefer_zod_enum_default,
|
|
@@ -9512,7 +9895,7 @@ var rules = {
|
|
|
9512
9895
|
};
|
|
9513
9896
|
var meta = {
|
|
9514
9897
|
name: "@sarj/eslint-plugin",
|
|
9515
|
-
version: "9.
|
|
9898
|
+
version: "9.7.0"
|
|
9516
9899
|
};
|
|
9517
9900
|
var recommendedRules = {
|
|
9518
9901
|
"@sarj/enforce-file-structure": "warn",
|
|
@@ -9527,6 +9910,7 @@ var recommendedRules = {
|
|
|
9527
9910
|
"@sarj/no-insecure-random-id": "warn",
|
|
9528
9911
|
"@sarj/no-json-stringify-error": "warn",
|
|
9529
9912
|
"@sarj/no-log-only-catch": "warn",
|
|
9913
|
+
"@sarj/no-long-comment": "warn",
|
|
9530
9914
|
"@sarj/no-offset-pagination": "warn",
|
|
9531
9915
|
"@sarj/no-positional-tuple-return": "warn",
|
|
9532
9916
|
"@sarj/no-repeated-string-literal": "warn",
|
|
@@ -9539,6 +9923,7 @@ var recommendedRules = {
|
|
|
9539
9923
|
"@sarj/no-sleep-in-test-body": "warn",
|
|
9540
9924
|
"@sarj/no-string-concat-in-loop": "warn",
|
|
9541
9925
|
"@sarj/no-tautological-expect": "warn",
|
|
9926
|
+
"@sarj/no-typed-doc-sections": "warn",
|
|
9542
9927
|
"@sarj/no-trailing-value-narration": "warn",
|
|
9543
9928
|
"@sarj/no-declaration-comment-wall": "warn",
|
|
9544
9929
|
"@sarj/no-union-in-comment": "warn",
|
|
@@ -9554,6 +9939,7 @@ var recommendedRules = {
|
|
|
9554
9939
|
"@sarj/prefer-schema-for-api-payload": "warn",
|
|
9555
9940
|
"@sarj/prefer-semantic-colors": ["warn", { requireSemanticTokens: true }],
|
|
9556
9941
|
"@sarj/prefer-server-actions": "warn",
|
|
9942
|
+
"@sarj/prefer-single-sentence-comment": "warn",
|
|
9557
9943
|
"@sarj/prefer-string-literal-union": "warn",
|
|
9558
9944
|
"@sarj/prefer-whole-object-assertion": "warn",
|
|
9559
9945
|
"@sarj/prefer-zod-enum": "warn",
|
|
@@ -9579,6 +9965,7 @@ var strictRules = {
|
|
|
9579
9965
|
"@sarj/no-insecure-random-id": "error",
|
|
9580
9966
|
"@sarj/no-json-stringify-error": "error",
|
|
9581
9967
|
"@sarj/no-log-only-catch": "error",
|
|
9968
|
+
"@sarj/no-long-comment": "error",
|
|
9582
9969
|
"@sarj/no-offset-pagination": "error",
|
|
9583
9970
|
"@sarj/no-positional-tuple-return": "error",
|
|
9584
9971
|
"@sarj/no-raw-env": "error",
|
|
@@ -9594,6 +9981,7 @@ var strictRules = {
|
|
|
9594
9981
|
"@sarj/no-storage-in-stateless-modules": "error",
|
|
9595
9982
|
"@sarj/no-string-concat-in-loop": "error",
|
|
9596
9983
|
"@sarj/no-tautological-expect": "error",
|
|
9984
|
+
"@sarj/no-typed-doc-sections": "error",
|
|
9597
9985
|
"@sarj/no-trailing-value-narration": "error",
|
|
9598
9986
|
"@sarj/no-declaration-comment-wall": "error",
|
|
9599
9987
|
"@sarj/no-union-in-comment": "error",
|
|
@@ -9609,6 +9997,7 @@ var strictRules = {
|
|
|
9609
9997
|
"@sarj/prefer-schema-for-api-payload": "error",
|
|
9610
9998
|
"@sarj/prefer-semantic-colors": ["error", { requireSemanticTokens: true }],
|
|
9611
9999
|
"@sarj/prefer-server-actions": "error",
|
|
10000
|
+
"@sarj/prefer-single-sentence-comment": "warn",
|
|
9612
10001
|
"@sarj/prefer-string-literal-union": "error",
|
|
9613
10002
|
"@sarj/prefer-whole-object-assertion": "error",
|
|
9614
10003
|
"@sarj/prefer-zod-enum": "error",
|