@sarj/eslint-plugin 7.0.0 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/index.cjs +537 -391
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -8
- package/dist/index.d.ts +16 -8
- package/dist/index.js +530 -384
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4992,29 +4992,61 @@ var no_trailing_value_narration_default = createRule({
|
|
|
4992
4992
|
}
|
|
4993
4993
|
});
|
|
4994
4994
|
|
|
4995
|
-
// src/rules/no-
|
|
4995
|
+
// src/rules/no-declaration-comment-wall.ts
|
|
4996
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES23 } from "@typescript-eslint/utils";
|
|
4997
|
+
|
|
4998
|
+
// src/rules/_comment-wall.ts
|
|
4996
4999
|
import { AST_NODE_TYPES as AST_NODE_TYPES22 } from "@typescript-eslint/utils";
|
|
4997
|
-
var
|
|
5000
|
+
var WALL_DEFAULTS = {
|
|
4998
5001
|
// Below three rows "a wall" is not a fair description of what the reader sees.
|
|
4999
5002
|
minCommentedMembers: 3,
|
|
5000
5003
|
// A minority of commented members is a GROUP LABEL, not a wall.
|
|
5001
5004
|
minCommentedRatio: 0.6,
|
|
5002
|
-
// Room for one substantive row in four; a
|
|
5003
|
-
// say something real is
|
|
5005
|
+
// Room for one substantive row in four; a declaration where a quarter of the
|
|
5006
|
+
// comments say something real is one someone was documenting, not decorating.
|
|
5004
5007
|
minRestatedRatio: 0.75,
|
|
5005
|
-
// One word beyond the member's own text. Zero is `no-restated-jsdoc`'s
|
|
5006
|
-
//
|
|
5007
|
-
// beside "Exact match")
|
|
5008
|
+
// One word beyond the member's own text. Zero is `no-restated-jsdoc`'s test
|
|
5009
|
+
// and is already covered there; two admits definitions ("Partial match"
|
|
5010
|
+
// beside "Exact match").
|
|
5008
5011
|
maxNovelWords: 1
|
|
5009
5012
|
};
|
|
5013
|
+
var WALL_SCHEMA = {
|
|
5014
|
+
type: "object",
|
|
5015
|
+
additionalProperties: false,
|
|
5016
|
+
properties: {
|
|
5017
|
+
minCommentedMembers: {
|
|
5018
|
+
type: "integer",
|
|
5019
|
+
minimum: 2,
|
|
5020
|
+
description: "Fewest commented members that can count as a wall."
|
|
5021
|
+
},
|
|
5022
|
+
minCommentedRatio: {
|
|
5023
|
+
type: "number",
|
|
5024
|
+
minimum: 0,
|
|
5025
|
+
maximum: 1,
|
|
5026
|
+
description: "Least share of the members that must be commented; below it the comments are group labels."
|
|
5027
|
+
},
|
|
5028
|
+
minRestatedRatio: {
|
|
5029
|
+
type: "number",
|
|
5030
|
+
minimum: 0,
|
|
5031
|
+
maximum: 1,
|
|
5032
|
+
description: "Least share of the member comments that must be restatements."
|
|
5033
|
+
},
|
|
5034
|
+
maxNovelWords: {
|
|
5035
|
+
type: "integer",
|
|
5036
|
+
minimum: 0,
|
|
5037
|
+
description: "Most content words a comment may add beyond its member's own source and still count as a restatement."
|
|
5038
|
+
}
|
|
5039
|
+
}
|
|
5040
|
+
};
|
|
5010
5041
|
var VALUE_TAG_RE = /@(?:deprecated|see|example|throws|remarks|since|default|defaultvalue|link|internal|alpha|beta|experimental|template|typeparam|inheritdoc|todo|fixme|override)\b/i;
|
|
5011
5042
|
var DEFAULT_RE = /^\s*@?default\b|\bdefaults? (?:to|:)/i;
|
|
5012
5043
|
var DIGIT_RE = /\d/;
|
|
5013
5044
|
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;
|
|
5014
5045
|
var EXAMPLE_RE = /["'`]|\be\.g\.|\bi\.e\./;
|
|
5046
|
+
var TAG_TOKEN_RE = /@\w+/g;
|
|
5015
5047
|
var BANNER_RE = /[=\-─-╿*#~_.]{3,}/;
|
|
5016
5048
|
var NON_ASCII_LETTER_RE2 = /[^\p{ASCII}\p{N}\p{P}\p{Z}]/u;
|
|
5017
|
-
var
|
|
5049
|
+
var WALL_STOPWORDS = new Set(
|
|
5018
5050
|
`the a an of to for in on with and or as at by is are was be been being
|
|
5019
5051
|
this that it its if whether when where which what will would can could should
|
|
5020
5052
|
must may into from over about not no does do done has have had used use uses
|
|
@@ -5029,15 +5061,22 @@ var BARE_LABEL_RE = /^[A-Za-z][A-Za-z0-9]*$/;
|
|
|
5029
5061
|
function labelStems(body) {
|
|
5030
5062
|
return splitIdentifier(body).map(stem).join(" ");
|
|
5031
5063
|
}
|
|
5032
|
-
function isNamedMember(node) {
|
|
5033
|
-
return (node.type === AST_NODE_TYPES22.TSPropertySignature || node.type === AST_NODE_TYPES22.TSMethodSignature) && !node.computed;
|
|
5034
|
-
}
|
|
5035
5064
|
function commentBody(comment) {
|
|
5036
5065
|
return comment.value.replace(/^\*+/, "").replace(/^[ \t]*\*[ \t]?/gm, "").trim();
|
|
5037
5066
|
}
|
|
5038
5067
|
function carriesValue(body) {
|
|
5039
5068
|
return isProtected(body) || VALUE_TAG_RE.test(body) || DEFAULT_RE.test(body) || DIGIT_RE.test(body) || UNIT_WORD_RE.test(body) || EXAMPLE_RE.test(body) || BANNER_RE.test(body) || NON_ASCII_LETTER_RE2.test(body);
|
|
5040
5069
|
}
|
|
5070
|
+
function isLabel(body) {
|
|
5071
|
+
let content = 0;
|
|
5072
|
+
for (const word of body.match(WORD_RE4) ?? []) {
|
|
5073
|
+
if (word.length >= 2 && !WALL_STOPWORDS.has(word.toLowerCase())) content += 1;
|
|
5074
|
+
}
|
|
5075
|
+
return content <= 1;
|
|
5076
|
+
}
|
|
5077
|
+
function isTagsOnly(body) {
|
|
5078
|
+
return body.length > 0 && body.replace(TAG_TOKEN_RE, "").trim().length === 0;
|
|
5079
|
+
}
|
|
5041
5080
|
function knownTokens(source) {
|
|
5042
5081
|
const tokens = /* @__PURE__ */ new Set();
|
|
5043
5082
|
for (const identifier of source.match(/[A-Za-z_$][\w$]*/g) ?? []) {
|
|
@@ -5052,11 +5091,146 @@ function novelWords(body, known) {
|
|
|
5052
5091
|
let novel = 0;
|
|
5053
5092
|
for (const word of body.match(WORD_RE4) ?? []) {
|
|
5054
5093
|
const lower = word.toLowerCase();
|
|
5055
|
-
if (lower.length < 2 ||
|
|
5094
|
+
if (lower.length < 2 || WALL_STOPWORDS.has(lower)) continue;
|
|
5056
5095
|
if (!known.has(lower) && !known.has(stem(lower))) novel += 1;
|
|
5057
5096
|
}
|
|
5058
5097
|
return novel;
|
|
5059
5098
|
}
|
|
5099
|
+
function isWall(members, commented, restated, options) {
|
|
5100
|
+
return commented >= options.minCommentedMembers && commented / members >= options.minCommentedRatio && restated / commented >= options.minRestatedRatio;
|
|
5101
|
+
}
|
|
5102
|
+
var OPAQUE_VALUE_TYPES = /* @__PURE__ */ new Set([
|
|
5103
|
+
AST_NODE_TYPES22.FunctionExpression,
|
|
5104
|
+
AST_NODE_TYPES22.ArrowFunctionExpression,
|
|
5105
|
+
AST_NODE_TYPES22.ObjectExpression,
|
|
5106
|
+
AST_NODE_TYPES22.ArrayExpression
|
|
5107
|
+
]);
|
|
5108
|
+
function declarationRange(member) {
|
|
5109
|
+
const body = bodyOf(member);
|
|
5110
|
+
if (body === void 0) return [member.range[0], member.range[1]];
|
|
5111
|
+
return [member.range[0], body.range[0]];
|
|
5112
|
+
}
|
|
5113
|
+
function bodyOf(member) {
|
|
5114
|
+
if (member.type === AST_NODE_TYPES22.MethodDefinition || member.type === AST_NODE_TYPES22.TSAbstractMethodDefinition) {
|
|
5115
|
+
return member.value.body ?? void 0;
|
|
5116
|
+
}
|
|
5117
|
+
if (member.type === AST_NODE_TYPES22.Property || member.type === AST_NODE_TYPES22.PropertyDefinition) {
|
|
5118
|
+
const value = member.value;
|
|
5119
|
+
if (value !== null && OPAQUE_VALUE_TYPES.has(value.type)) return value;
|
|
5120
|
+
}
|
|
5121
|
+
return void 0;
|
|
5122
|
+
}
|
|
5123
|
+
|
|
5124
|
+
// src/rules/no-declaration-comment-wall.ts
|
|
5125
|
+
function named(node) {
|
|
5126
|
+
switch (node.type) {
|
|
5127
|
+
case AST_NODE_TYPES23.TSEnumMember:
|
|
5128
|
+
return { node, key: node.id };
|
|
5129
|
+
case AST_NODE_TYPES23.PropertyDefinition:
|
|
5130
|
+
case AST_NODE_TYPES23.TSAbstractPropertyDefinition:
|
|
5131
|
+
case AST_NODE_TYPES23.MethodDefinition:
|
|
5132
|
+
case AST_NODE_TYPES23.TSAbstractMethodDefinition:
|
|
5133
|
+
return node.computed ? void 0 : { node, key: node.key };
|
|
5134
|
+
default:
|
|
5135
|
+
return void 0;
|
|
5136
|
+
}
|
|
5137
|
+
}
|
|
5138
|
+
var no_declaration_comment_wall_default = createRule({
|
|
5139
|
+
name: "no-declaration-comment-wall",
|
|
5140
|
+
meta: {
|
|
5141
|
+
type: "suggestion",
|
|
5142
|
+
docs: {
|
|
5143
|
+
description: "Flag an enum body or class body whose member comments mostly re-spell the members' own names."
|
|
5144
|
+
},
|
|
5145
|
+
schema: [WALL_SCHEMA],
|
|
5146
|
+
messages: {
|
|
5147
|
+
commentWall: "{{restated}} of this declaration's {{commented}} member comments only re-spell the member's own name \u2014 delete them, and keep the rows that say what the name cannot."
|
|
5148
|
+
}
|
|
5149
|
+
},
|
|
5150
|
+
defaultOptions: [WALL_DEFAULTS],
|
|
5151
|
+
create(context, [provided]) {
|
|
5152
|
+
const options = { ...WALL_DEFAULTS, ...provided };
|
|
5153
|
+
const sourceCode = context.sourceCode;
|
|
5154
|
+
if (isGeneratedFile(context.filename, sourceCode.text) || isTestFile(context.filename) || isStoryFile(context.filename)) {
|
|
5155
|
+
return {};
|
|
5156
|
+
}
|
|
5157
|
+
const endingOn = /* @__PURE__ */ new Map();
|
|
5158
|
+
const startingOn = /* @__PURE__ */ new Map();
|
|
5159
|
+
for (const comment of sourceCode.getAllComments()) {
|
|
5160
|
+
endingOn.set(comment.loc.end.line, comment);
|
|
5161
|
+
if (!startingOn.has(comment.loc.start.line)) startingOn.set(comment.loc.start.line, comment);
|
|
5162
|
+
}
|
|
5163
|
+
function documentingComment(member) {
|
|
5164
|
+
const beforeMember = sourceCode.getTokenBefore(member, { includeComments: false });
|
|
5165
|
+
const ownsItsLine = beforeMember === null || beforeMember.loc.end.line < member.loc.start.line;
|
|
5166
|
+
const lead = ownsItsLine ? endingOn.get(member.loc.start.line - 1) : void 0;
|
|
5167
|
+
if (lead !== void 0) {
|
|
5168
|
+
const before = sourceCode.getTokenBefore(lead, { includeComments: false });
|
|
5169
|
+
if (before === null || before.loc.end.line < lead.loc.start.line) return lead;
|
|
5170
|
+
}
|
|
5171
|
+
const trail = startingOn.get(member.loc.end.line);
|
|
5172
|
+
return trail !== void 0 && trail.range[0] > member.range[0] ? trail : void 0;
|
|
5173
|
+
}
|
|
5174
|
+
function isGroupLabel(comment, member, headsRun) {
|
|
5175
|
+
if (comment.loc.end.line >= member.node.loc.start.line) return false;
|
|
5176
|
+
const body = commentBody(comment);
|
|
5177
|
+
if (!BARE_LABEL_RE.test(body)) return false;
|
|
5178
|
+
if (labelStems(body) === labelStems(sourceCode.getText(member.key))) return false;
|
|
5179
|
+
const lineAbove = sourceCode.lines[comment.loc.start.line - 2];
|
|
5180
|
+
return headsRun || lineAbove !== void 0 && lineAbove.trim().length === 0;
|
|
5181
|
+
}
|
|
5182
|
+
function check(node, members) {
|
|
5183
|
+
const judged = members.map(named).filter((member) => member !== void 0);
|
|
5184
|
+
if (judged.length === 0) return;
|
|
5185
|
+
const documented = judged.map((member) => ({
|
|
5186
|
+
member,
|
|
5187
|
+
comment: documentingComment(member.node)
|
|
5188
|
+
}));
|
|
5189
|
+
let commented = 0;
|
|
5190
|
+
let restated = 0;
|
|
5191
|
+
for (const [index, { member, comment }] of documented.entries()) {
|
|
5192
|
+
if (comment === void 0) continue;
|
|
5193
|
+
const next = documented[index + 1];
|
|
5194
|
+
if (isGroupLabel(comment, member, next !== void 0 && next.comment === void 0)) {
|
|
5195
|
+
continue;
|
|
5196
|
+
}
|
|
5197
|
+
commented += 1;
|
|
5198
|
+
const body = commentBody(comment);
|
|
5199
|
+
if (body.length === 0 || carriesValue(body) || isTagsOnly(body) || isLabel(body)) {
|
|
5200
|
+
continue;
|
|
5201
|
+
}
|
|
5202
|
+
const [start, end] = declarationRange(member.node);
|
|
5203
|
+
if (novelWords(body, knownTokens(sourceCode.text.slice(start, end))) <= options.maxNovelWords) {
|
|
5204
|
+
restated += 1;
|
|
5205
|
+
}
|
|
5206
|
+
}
|
|
5207
|
+
if (!isWall(judged.length, commented, restated, options)) return;
|
|
5208
|
+
context.report({
|
|
5209
|
+
node,
|
|
5210
|
+
loc: {
|
|
5211
|
+
start: node.loc.start,
|
|
5212
|
+
end: { line: node.loc.start.line, column: node.loc.start.column + 1 }
|
|
5213
|
+
},
|
|
5214
|
+
messageId: "commentWall",
|
|
5215
|
+
data: { restated: String(restated), commented: String(commented) }
|
|
5216
|
+
});
|
|
5217
|
+
}
|
|
5218
|
+
return {
|
|
5219
|
+
ClassBody: (node) => {
|
|
5220
|
+
check(node, node.body);
|
|
5221
|
+
},
|
|
5222
|
+
TSEnumDeclaration: (node) => {
|
|
5223
|
+
check(node, node.body.members);
|
|
5224
|
+
}
|
|
5225
|
+
};
|
|
5226
|
+
}
|
|
5227
|
+
});
|
|
5228
|
+
|
|
5229
|
+
// src/rules/no-type-member-comment-wall.ts
|
|
5230
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES24 } from "@typescript-eslint/utils";
|
|
5231
|
+
function isNamedMember(node) {
|
|
5232
|
+
return (node.type === AST_NODE_TYPES24.TSPropertySignature || node.type === AST_NODE_TYPES24.TSMethodSignature) && !node.computed;
|
|
5233
|
+
}
|
|
5060
5234
|
var no_type_member_comment_wall_default = createRule({
|
|
5061
5235
|
name: "no-type-member-comment-wall",
|
|
5062
5236
|
meta: {
|
|
@@ -5064,43 +5238,14 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5064
5238
|
docs: {
|
|
5065
5239
|
description: "Flag an object type whose member comments mostly re-spell the members' own names and types."
|
|
5066
5240
|
},
|
|
5067
|
-
schema: [
|
|
5068
|
-
{
|
|
5069
|
-
type: "object",
|
|
5070
|
-
additionalProperties: false,
|
|
5071
|
-
properties: {
|
|
5072
|
-
minCommentedMembers: {
|
|
5073
|
-
type: "integer",
|
|
5074
|
-
minimum: 2,
|
|
5075
|
-
description: "Fewest commented members that can count as a wall."
|
|
5076
|
-
},
|
|
5077
|
-
minCommentedRatio: {
|
|
5078
|
-
type: "number",
|
|
5079
|
-
minimum: 0,
|
|
5080
|
-
maximum: 1,
|
|
5081
|
-
description: "Least share of the type's members that must be commented; below it the comments are group labels."
|
|
5082
|
-
},
|
|
5083
|
-
minRestatedRatio: {
|
|
5084
|
-
type: "number",
|
|
5085
|
-
minimum: 0,
|
|
5086
|
-
maximum: 1,
|
|
5087
|
-
description: "Least share of the member comments that must be restatements."
|
|
5088
|
-
},
|
|
5089
|
-
maxNovelWords: {
|
|
5090
|
-
type: "integer",
|
|
5091
|
-
minimum: 0,
|
|
5092
|
-
description: "Most content words a comment may add beyond its member's own source and still count as a restatement."
|
|
5093
|
-
}
|
|
5094
|
-
}
|
|
5095
|
-
}
|
|
5096
|
-
],
|
|
5241
|
+
schema: [WALL_SCHEMA],
|
|
5097
5242
|
messages: {
|
|
5098
5243
|
commentWall: "{{restated}} of this type's {{commented}} member comments only re-spell the member's own name and type \u2014 delete them, and keep the rows that say what the name cannot."
|
|
5099
5244
|
}
|
|
5100
5245
|
},
|
|
5101
|
-
defaultOptions: [
|
|
5246
|
+
defaultOptions: [WALL_DEFAULTS],
|
|
5102
5247
|
create(context, [provided]) {
|
|
5103
|
-
const options = { ...
|
|
5248
|
+
const options = { ...WALL_DEFAULTS, ...provided };
|
|
5104
5249
|
const sourceCode = context.sourceCode;
|
|
5105
5250
|
if (isGeneratedFile(context.filename, sourceCode.text) || isTestFile(context.filename) || isStoryFile(context.filename)) {
|
|
5106
5251
|
return {};
|
|
@@ -5131,10 +5276,10 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5131
5276
|
return headsRun || lineAbove !== void 0 && lineAbove.trim().length === 0;
|
|
5132
5277
|
}
|
|
5133
5278
|
function check(node) {
|
|
5134
|
-
const members = node.type ===
|
|
5135
|
-
const
|
|
5136
|
-
if (
|
|
5137
|
-
const documented =
|
|
5279
|
+
const members = node.type === AST_NODE_TYPES24.TSInterfaceBody ? node.body : node.members;
|
|
5280
|
+
const named2 = members.filter(isNamedMember);
|
|
5281
|
+
if (named2.length === 0) return;
|
|
5282
|
+
const documented = named2.map((member) => ({ member, comment: documentingComment(member) }));
|
|
5138
5283
|
let commented = 0;
|
|
5139
5284
|
let restated = 0;
|
|
5140
5285
|
const claimed = /* @__PURE__ */ new Set();
|
|
@@ -5152,9 +5297,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5152
5297
|
restated += 1;
|
|
5153
5298
|
}
|
|
5154
5299
|
}
|
|
5155
|
-
if (
|
|
5156
|
-
return;
|
|
5157
|
-
}
|
|
5300
|
+
if (!isWall(named2.length, commented, restated, options)) return;
|
|
5158
5301
|
context.report({
|
|
5159
5302
|
node,
|
|
5160
5303
|
loc: {
|
|
@@ -5173,7 +5316,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5173
5316
|
});
|
|
5174
5317
|
|
|
5175
5318
|
// src/rules/no-unnecessary-use-client.ts
|
|
5176
|
-
import { AST_NODE_TYPES as
|
|
5319
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES25 } from "@typescript-eslint/utils";
|
|
5177
5320
|
var HOOK_REGEX = /^use([A-Z]|$)/;
|
|
5178
5321
|
var EVENT_PROP_REGEX = /^on[A-Z]/;
|
|
5179
5322
|
var ERROR_FILE_REGEX = /\b(?:global-)?error\.[jt]sx?$/;
|
|
@@ -5199,13 +5342,13 @@ var CLIENT_ONLY_PACKAGES_REGEX = /^(?:@radix-ui\/|framer-motion|react-dom|react-
|
|
|
5199
5342
|
var isBareSpecifier = (source) => !source.startsWith(".") && !source.startsWith("/") && !source.startsWith("@/") && !source.startsWith("~");
|
|
5200
5343
|
var jsxRootName = (name) => {
|
|
5201
5344
|
let current = name;
|
|
5202
|
-
while (current.type ===
|
|
5345
|
+
while (current.type === AST_NODE_TYPES25.JSXMemberExpression) {
|
|
5203
5346
|
current = current.object;
|
|
5204
5347
|
}
|
|
5205
|
-
return current.type ===
|
|
5348
|
+
return current.type === AST_NODE_TYPES25.JSXIdentifier ? current.name : "";
|
|
5206
5349
|
};
|
|
5207
5350
|
var subtreeReadsImportedBinding = (node, imported) => {
|
|
5208
|
-
if (node.type ===
|
|
5351
|
+
if (node.type === AST_NODE_TYPES25.Identifier) {
|
|
5209
5352
|
return imported.has(node.name);
|
|
5210
5353
|
}
|
|
5211
5354
|
for (const key of Object.keys(node)) {
|
|
@@ -5220,16 +5363,16 @@ var subtreeReadsImportedBinding = (node, imported) => {
|
|
|
5220
5363
|
return false;
|
|
5221
5364
|
};
|
|
5222
5365
|
var isUseClientDirective = (node) => {
|
|
5223
|
-
return node.type ===
|
|
5366
|
+
return node.type === AST_NODE_TYPES25.ExpressionStatement && node.expression.type === AST_NODE_TYPES25.Literal && node.expression.value === "use client";
|
|
5224
5367
|
};
|
|
5225
5368
|
var isGlobalReference = (node, context) => {
|
|
5226
5369
|
if (!BROWSER_GLOBALS.has(node.name)) return false;
|
|
5227
5370
|
const parent = node.parent;
|
|
5228
5371
|
if (parent !== void 0) {
|
|
5229
|
-
if (parent.type ===
|
|
5372
|
+
if (parent.type === AST_NODE_TYPES25.MemberExpression && parent.property === node && !parent.computed) {
|
|
5230
5373
|
return false;
|
|
5231
5374
|
}
|
|
5232
|
-
if (parent.type ===
|
|
5375
|
+
if (parent.type === AST_NODE_TYPES25.Property && parent.key === node && !parent.computed) {
|
|
5233
5376
|
return false;
|
|
5234
5377
|
}
|
|
5235
5378
|
if (parent.type.startsWith("TS")) {
|
|
@@ -5269,13 +5412,13 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5269
5412
|
const importedLocals = /* @__PURE__ */ new Set();
|
|
5270
5413
|
const externalLocals = /* @__PURE__ */ new Set();
|
|
5271
5414
|
const markIfHookOrContext = (callee) => {
|
|
5272
|
-
if (callee.type ===
|
|
5415
|
+
if (callee.type === AST_NODE_TYPES25.Identifier) {
|
|
5273
5416
|
if (HOOK_REGEX.test(callee.name) || callee.name === "createContext") {
|
|
5274
5417
|
hasClientIndicator = true;
|
|
5275
5418
|
}
|
|
5276
5419
|
return;
|
|
5277
5420
|
}
|
|
5278
|
-
if (callee.type ===
|
|
5421
|
+
if (callee.type === AST_NODE_TYPES25.MemberExpression && callee.property.type === AST_NODE_TYPES25.Identifier) {
|
|
5279
5422
|
const name = callee.property.name;
|
|
5280
5423
|
if (HOOK_REGEX.test(name) || name === "createContext") {
|
|
5281
5424
|
hasClientIndicator = true;
|
|
@@ -5285,7 +5428,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5285
5428
|
return {
|
|
5286
5429
|
Program(node) {
|
|
5287
5430
|
for (const stmt of node.body) {
|
|
5288
|
-
if (stmt.type !==
|
|
5431
|
+
if (stmt.type !== AST_NODE_TYPES25.ExpressionStatement) break;
|
|
5289
5432
|
if (isUseClientDirective(stmt)) {
|
|
5290
5433
|
directiveNode = stmt;
|
|
5291
5434
|
break;
|
|
@@ -5298,7 +5441,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5298
5441
|
},
|
|
5299
5442
|
JSXAttribute(node) {
|
|
5300
5443
|
if (directiveNode === null) return;
|
|
5301
|
-
if (node.name.type ===
|
|
5444
|
+
if (node.name.type === AST_NODE_TYPES25.JSXIdentifier && EVENT_PROP_REGEX.test(node.name.name)) {
|
|
5302
5445
|
hasClientIndicator = true;
|
|
5303
5446
|
}
|
|
5304
5447
|
},
|
|
@@ -5366,17 +5509,17 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5366
5509
|
|
|
5367
5510
|
// src/rules/no-unsafe-mock-casting.ts
|
|
5368
5511
|
import "@typescript-eslint/utils";
|
|
5369
|
-
import { AST_NODE_TYPES as
|
|
5512
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES26 } from "@typescript-eslint/utils";
|
|
5370
5513
|
function isMockTypeReference(node) {
|
|
5371
|
-
if (node.type !==
|
|
5514
|
+
if (node.type !== AST_NODE_TYPES26.TSTypeReference) {
|
|
5372
5515
|
return false;
|
|
5373
5516
|
}
|
|
5374
5517
|
const typeName = node.typeName;
|
|
5375
|
-
if (typeName.type ===
|
|
5518
|
+
if (typeName.type === AST_NODE_TYPES26.Identifier) {
|
|
5376
5519
|
const name = typeName.name;
|
|
5377
5520
|
return name === "Mock" || name === "MockInstance" || name === "SpyInstance";
|
|
5378
5521
|
}
|
|
5379
|
-
if (typeName.type ===
|
|
5522
|
+
if (typeName.type === AST_NODE_TYPES26.TSQualifiedName) {
|
|
5380
5523
|
const rightName = typeName.right.name;
|
|
5381
5524
|
return rightName === "Mock" || rightName === "MockInstance" || rightName === "SpyInstance";
|
|
5382
5525
|
}
|
|
@@ -5414,7 +5557,7 @@ var no_unsafe_mock_casting_default = createRule({
|
|
|
5414
5557
|
// src/rules/no-zod-native-enum.ts
|
|
5415
5558
|
import {
|
|
5416
5559
|
ESLintUtils as ESLintUtils2,
|
|
5417
|
-
AST_NODE_TYPES as
|
|
5560
|
+
AST_NODE_TYPES as AST_NODE_TYPES27
|
|
5418
5561
|
} from "@typescript-eslint/utils";
|
|
5419
5562
|
import * as ts from "typescript";
|
|
5420
5563
|
var IGNORE_PATTERNS = [
|
|
@@ -5433,7 +5576,7 @@ function isZodModule(source) {
|
|
|
5433
5576
|
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
5434
5577
|
}
|
|
5435
5578
|
function unwrap2(node) {
|
|
5436
|
-
if (node.type ===
|
|
5579
|
+
if (node.type === AST_NODE_TYPES27.TSAsExpression || node.type === AST_NODE_TYPES27.TSSatisfiesExpression) {
|
|
5437
5580
|
return unwrap2(node.expression);
|
|
5438
5581
|
}
|
|
5439
5582
|
return node;
|
|
@@ -5441,14 +5584,14 @@ function unwrap2(node) {
|
|
|
5441
5584
|
function stringValueTexts(node, sourceCode) {
|
|
5442
5585
|
const texts = [];
|
|
5443
5586
|
for (const prop of node.properties) {
|
|
5444
|
-
if (prop.type !==
|
|
5587
|
+
if (prop.type !== AST_NODE_TYPES27.Property) {
|
|
5445
5588
|
return null;
|
|
5446
5589
|
}
|
|
5447
5590
|
if (prop.computed || prop.shorthand || prop.method || prop.kind !== "init") {
|
|
5448
5591
|
return null;
|
|
5449
5592
|
}
|
|
5450
5593
|
const value = prop.value;
|
|
5451
|
-
if (value.type !==
|
|
5594
|
+
if (value.type !== AST_NODE_TYPES27.Literal || typeof value.value !== "string") {
|
|
5452
5595
|
return null;
|
|
5453
5596
|
}
|
|
5454
5597
|
const text = sourceCode.getText(value);
|
|
@@ -5464,7 +5607,7 @@ function resolvesToLocalEnum(node, scope) {
|
|
|
5464
5607
|
const variable = current.variables.find((v) => v.name === node.name);
|
|
5465
5608
|
if (variable !== void 0) {
|
|
5466
5609
|
return variable.defs.some(
|
|
5467
|
-
(def) => def.node.type ===
|
|
5610
|
+
(def) => def.node.type === AST_NODE_TYPES27.TSEnumDeclaration
|
|
5468
5611
|
);
|
|
5469
5612
|
}
|
|
5470
5613
|
current = current.upper;
|
|
@@ -5516,25 +5659,25 @@ var no_zod_native_enum_default = createRule({
|
|
|
5516
5659
|
const zodImportedNames = /* @__PURE__ */ new Map();
|
|
5517
5660
|
function isZodMemberCall(node, api) {
|
|
5518
5661
|
const callee = node.callee;
|
|
5519
|
-
if (callee.type ===
|
|
5662
|
+
if (callee.type === AST_NODE_TYPES27.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES27.Identifier) {
|
|
5520
5663
|
return callee.property.name === api;
|
|
5521
5664
|
}
|
|
5522
|
-
if (callee.type ===
|
|
5665
|
+
if (callee.type === AST_NODE_TYPES27.Identifier) {
|
|
5523
5666
|
return zodImportedNames.get(callee.name) === api;
|
|
5524
5667
|
}
|
|
5525
5668
|
return false;
|
|
5526
5669
|
}
|
|
5527
5670
|
function buildFix(node) {
|
|
5528
5671
|
const callee = node.callee;
|
|
5529
|
-
if (callee.type !==
|
|
5672
|
+
if (callee.type !== AST_NODE_TYPES27.MemberExpression || callee.property.type !== AST_NODE_TYPES27.Identifier) {
|
|
5530
5673
|
return null;
|
|
5531
5674
|
}
|
|
5532
5675
|
const arg = node.arguments[0];
|
|
5533
|
-
if (arg === void 0 || node.arguments.length !== 1 || arg.type ===
|
|
5676
|
+
if (arg === void 0 || node.arguments.length !== 1 || arg.type === AST_NODE_TYPES27.SpreadElement) {
|
|
5534
5677
|
return null;
|
|
5535
5678
|
}
|
|
5536
5679
|
const inner = unwrap2(arg);
|
|
5537
|
-
if (inner.type !==
|
|
5680
|
+
if (inner.type !== AST_NODE_TYPES27.ObjectExpression) {
|
|
5538
5681
|
return null;
|
|
5539
5682
|
}
|
|
5540
5683
|
const values = stringValueTexts(inner, sourceCode);
|
|
@@ -5554,7 +5697,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
5554
5697
|
return;
|
|
5555
5698
|
}
|
|
5556
5699
|
for (const spec of node.specifiers) {
|
|
5557
|
-
if (spec.type ===
|
|
5700
|
+
if (spec.type === AST_NODE_TYPES27.ImportSpecifier && spec.imported.type === AST_NODE_TYPES27.Identifier) {
|
|
5558
5701
|
zodImportedNames.set(spec.local.name, spec.imported.name);
|
|
5559
5702
|
}
|
|
5560
5703
|
}
|
|
@@ -5573,7 +5716,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
5573
5716
|
return;
|
|
5574
5717
|
}
|
|
5575
5718
|
const arg = node.arguments[0];
|
|
5576
|
-
if (arg === void 0 || arg.type !==
|
|
5719
|
+
if (arg === void 0 || arg.type !== AST_NODE_TYPES27.Identifier) {
|
|
5577
5720
|
return;
|
|
5578
5721
|
}
|
|
5579
5722
|
const isEnum = resolvesToLocalEnum(arg, sourceCode.getScope(arg)) || services !== null && resolvesToImportedEnum(arg, services);
|
|
@@ -5590,7 +5733,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
5590
5733
|
});
|
|
5591
5734
|
|
|
5592
5735
|
// src/rules/prefer-constant-time-secret-compare.ts
|
|
5593
|
-
import { AST_NODE_TYPES as
|
|
5736
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES28 } from "@typescript-eslint/utils";
|
|
5594
5737
|
var EQUALITY_OPERATORS = /* @__PURE__ */ new Set(["===", "!==", "==", "!="]);
|
|
5595
5738
|
var SENTINEL_IDENTIFIERS = /* @__PURE__ */ new Set(["undefined", "NaN"]);
|
|
5596
5739
|
var SENTINEL_WORDS = /(^|_)(SENTINEL|EMPTY|NONE|NULL|UNSET|MISSING|PLACEHOLDER|DUMMY|FAKE|EXAMPLE)(_|$)/;
|
|
@@ -5603,36 +5746,36 @@ function isConstantReference(identifier) {
|
|
|
5603
5746
|
}
|
|
5604
5747
|
function isExcludedOperand(node) {
|
|
5605
5748
|
switch (node.type) {
|
|
5606
|
-
case
|
|
5749
|
+
case AST_NODE_TYPES28.Literal:
|
|
5607
5750
|
return true;
|
|
5608
|
-
case
|
|
5751
|
+
case AST_NODE_TYPES28.TemplateLiteral:
|
|
5609
5752
|
return node.expressions.length === 0;
|
|
5610
|
-
case
|
|
5753
|
+
case AST_NODE_TYPES28.Identifier:
|
|
5611
5754
|
return SENTINEL_IDENTIFIERS.has(node.name) || SENTINEL_PREFIX_RE.test(node.name) || isConstantReference(node.name);
|
|
5612
|
-
case
|
|
5613
|
-
return !node.computed && node.property.type ===
|
|
5755
|
+
case AST_NODE_TYPES28.MemberExpression:
|
|
5756
|
+
return !node.computed && node.property.type === AST_NODE_TYPES28.Identifier && (SENTINEL_PREFIX_RE.test(node.property.name) || isConstantReference(node.property.name));
|
|
5614
5757
|
default:
|
|
5615
5758
|
return false;
|
|
5616
5759
|
}
|
|
5617
5760
|
}
|
|
5618
5761
|
function operandName(node) {
|
|
5619
|
-
if (node.type ===
|
|
5762
|
+
if (node.type === AST_NODE_TYPES28.Identifier) {
|
|
5620
5763
|
return node.name;
|
|
5621
5764
|
}
|
|
5622
|
-
if (node.type ===
|
|
5765
|
+
if (node.type === AST_NODE_TYPES28.MemberExpression && !node.computed && node.property.type === AST_NODE_TYPES28.Identifier) {
|
|
5623
5766
|
return node.property.name;
|
|
5624
5767
|
}
|
|
5625
5768
|
return null;
|
|
5626
5769
|
}
|
|
5627
5770
|
function isSecretOperand(node) {
|
|
5628
|
-
if (node.type ===
|
|
5771
|
+
if (node.type === AST_NODE_TYPES28.TemplateLiteral) {
|
|
5629
5772
|
return node.expressions.some((expression) => isSecretOperand(expression));
|
|
5630
5773
|
}
|
|
5631
5774
|
const name = operandName(node);
|
|
5632
5775
|
return name !== null && isAuthSecretName(name);
|
|
5633
5776
|
}
|
|
5634
5777
|
function secretNameOf(node) {
|
|
5635
|
-
if (node.type ===
|
|
5778
|
+
if (node.type === AST_NODE_TYPES28.TemplateLiteral) {
|
|
5636
5779
|
for (const expression of node.expressions) {
|
|
5637
5780
|
const nested = secretNameOf(expression);
|
|
5638
5781
|
if (nested !== null) {
|
|
@@ -5685,7 +5828,7 @@ var prefer_constant_time_secret_compare_default = createRule({
|
|
|
5685
5828
|
|
|
5686
5829
|
// src/rules/prefer-discriminated-union.ts
|
|
5687
5830
|
import "@typescript-eslint/utils";
|
|
5688
|
-
import { AST_NODE_TYPES as
|
|
5831
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES29 } from "@typescript-eslint/utils";
|
|
5689
5832
|
var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
5690
5833
|
"success",
|
|
5691
5834
|
"ok",
|
|
@@ -5695,27 +5838,27 @@ var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
|
5695
5838
|
]);
|
|
5696
5839
|
var MIN_OPTIONAL_MEMBERS = 2;
|
|
5697
5840
|
function getMemberName(member) {
|
|
5698
|
-
if (member.type !==
|
|
5841
|
+
if (member.type !== AST_NODE_TYPES29.TSPropertySignature) {
|
|
5699
5842
|
return null;
|
|
5700
5843
|
}
|
|
5701
5844
|
const { key } = member;
|
|
5702
|
-
if (key.type ===
|
|
5845
|
+
if (key.type === AST_NODE_TYPES29.Identifier) {
|
|
5703
5846
|
return key.name;
|
|
5704
5847
|
}
|
|
5705
|
-
if (key.type ===
|
|
5848
|
+
if (key.type === AST_NODE_TYPES29.Literal && typeof key.value === "string") {
|
|
5706
5849
|
return key.value;
|
|
5707
5850
|
}
|
|
5708
5851
|
return null;
|
|
5709
5852
|
}
|
|
5710
5853
|
function isBooleanTyped(member) {
|
|
5711
|
-
return member.typeAnnotation?.typeAnnotation.type ===
|
|
5854
|
+
return member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES29.TSBooleanKeyword;
|
|
5712
5855
|
}
|
|
5713
5856
|
function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
5714
5857
|
let hasStatusBoolean = false;
|
|
5715
5858
|
let optionalCount = 0;
|
|
5716
5859
|
let optionalPayloadCount = 0;
|
|
5717
5860
|
for (const member of typeLiteral.members) {
|
|
5718
|
-
if (member.type !==
|
|
5861
|
+
if (member.type !== AST_NODE_TYPES29.TSPropertySignature) {
|
|
5719
5862
|
continue;
|
|
5720
5863
|
}
|
|
5721
5864
|
if (member.optional) {
|
|
@@ -5757,7 +5900,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
5757
5900
|
TSInterfaceDeclaration(node) {
|
|
5758
5901
|
const synthetic = {
|
|
5759
5902
|
...node.body,
|
|
5760
|
-
type:
|
|
5903
|
+
type: AST_NODE_TYPES29.TSTypeLiteral,
|
|
5761
5904
|
members: node.body.body
|
|
5762
5905
|
};
|
|
5763
5906
|
checkTypeLiteral(synthetic, node);
|
|
@@ -5770,7 +5913,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
5770
5913
|
});
|
|
5771
5914
|
|
|
5772
5915
|
// src/rules/prefer-module-level-constant.ts
|
|
5773
|
-
import { AST_NODE_TYPES as
|
|
5916
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES30 } from "@typescript-eslint/utils";
|
|
5774
5917
|
var DEFAULT_MIN_ELEMENTS = 3;
|
|
5775
5918
|
var MAX_LITERAL_DEPTH = 4;
|
|
5776
5919
|
var IGNORE_PATTERNS2 = [
|
|
@@ -5799,9 +5942,9 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
|
5799
5942
|
"assign"
|
|
5800
5943
|
]);
|
|
5801
5944
|
var FUNCTION_TYPES5 = /* @__PURE__ */ new Set([
|
|
5802
|
-
|
|
5803
|
-
|
|
5804
|
-
|
|
5945
|
+
AST_NODE_TYPES30.FunctionDeclaration,
|
|
5946
|
+
AST_NODE_TYPES30.FunctionExpression,
|
|
5947
|
+
AST_NODE_TYPES30.ArrowFunctionExpression
|
|
5805
5948
|
]);
|
|
5806
5949
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
5807
5950
|
function isIgnoredFile2(filename, sourceText) {
|
|
@@ -5814,14 +5957,14 @@ function isLocalFixtureFile(filename) {
|
|
|
5814
5957
|
return isTestFile(filename) || isStoryFile(filename);
|
|
5815
5958
|
}
|
|
5816
5959
|
function unwrap3(node) {
|
|
5817
|
-
if (node.type ===
|
|
5960
|
+
if (node.type === AST_NODE_TYPES30.TSAsExpression || node.type === AST_NODE_TYPES30.TSSatisfiesExpression || node.type === AST_NODE_TYPES30.TSNonNullExpression) {
|
|
5818
5961
|
return unwrap3(node.expression);
|
|
5819
5962
|
}
|
|
5820
5963
|
return node;
|
|
5821
5964
|
}
|
|
5822
5965
|
var HAS_STATEFUL_FLAG_RE = /[gy]/;
|
|
5823
5966
|
function isRegexLiteral(node) {
|
|
5824
|
-
return node.type ===
|
|
5967
|
+
return node.type === AST_NODE_TYPES30.Literal && "regex" in node && node.regex !== void 0;
|
|
5825
5968
|
}
|
|
5826
5969
|
function isLiteralOnly(node, depth) {
|
|
5827
5970
|
if (depth > MAX_LITERAL_DEPTH) {
|
|
@@ -5829,29 +5972,29 @@ function isLiteralOnly(node, depth) {
|
|
|
5829
5972
|
}
|
|
5830
5973
|
const inner = unwrap3(node);
|
|
5831
5974
|
switch (inner.type) {
|
|
5832
|
-
case
|
|
5975
|
+
case AST_NODE_TYPES30.Literal: {
|
|
5833
5976
|
return !(isRegexLiteral(inner) && HAS_STATEFUL_FLAG_RE.test(inner.regex.flags));
|
|
5834
5977
|
}
|
|
5835
|
-
case
|
|
5978
|
+
case AST_NODE_TYPES30.TemplateLiteral: {
|
|
5836
5979
|
return inner.expressions.length === 0;
|
|
5837
5980
|
}
|
|
5838
|
-
case
|
|
5839
|
-
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type ===
|
|
5981
|
+
case AST_NODE_TYPES30.UnaryExpression: {
|
|
5982
|
+
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type === AST_NODE_TYPES30.Literal && typeof inner.argument.value === "number";
|
|
5840
5983
|
}
|
|
5841
|
-
case
|
|
5984
|
+
case AST_NODE_TYPES30.ArrayExpression: {
|
|
5842
5985
|
return inner.elements.every(
|
|
5843
|
-
(el) => el !== null && el.type !==
|
|
5986
|
+
(el) => el !== null && el.type !== AST_NODE_TYPES30.SpreadElement && isLiteralOnly(el, depth + 1)
|
|
5844
5987
|
);
|
|
5845
5988
|
}
|
|
5846
|
-
case
|
|
5989
|
+
case AST_NODE_TYPES30.ObjectExpression: {
|
|
5847
5990
|
return inner.properties.every((prop) => {
|
|
5848
|
-
if (prop.type !==
|
|
5991
|
+
if (prop.type !== AST_NODE_TYPES30.Property) {
|
|
5849
5992
|
return false;
|
|
5850
5993
|
}
|
|
5851
5994
|
if (prop.shorthand || prop.method || prop.kind !== "init") {
|
|
5852
5995
|
return false;
|
|
5853
5996
|
}
|
|
5854
|
-
if (prop.computed && prop.key.type !==
|
|
5997
|
+
if (prop.computed && prop.key.type !== AST_NODE_TYPES30.Literal) {
|
|
5855
5998
|
return false;
|
|
5856
5999
|
}
|
|
5857
6000
|
return isLiteralOnly(prop.value, depth + 1);
|
|
@@ -5864,7 +6007,7 @@ function isLiteralOnly(node, depth) {
|
|
|
5864
6007
|
}
|
|
5865
6008
|
function unwrapObjectFreeze(node) {
|
|
5866
6009
|
const inner = unwrap3(node);
|
|
5867
|
-
if (inner.type ===
|
|
6010
|
+
if (inner.type === AST_NODE_TYPES30.CallExpression && inner.callee.type === AST_NODE_TYPES30.MemberExpression && !inner.callee.computed && inner.callee.object.type === AST_NODE_TYPES30.Identifier && inner.callee.object.name === "Object" && inner.callee.property.type === AST_NODE_TYPES30.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== AST_NODE_TYPES30.SpreadElement) {
|
|
5868
6011
|
return unwrap3(inner.arguments[0]);
|
|
5869
6012
|
}
|
|
5870
6013
|
return inner;
|
|
@@ -5880,19 +6023,19 @@ function classify(init, checkRegex) {
|
|
|
5880
6023
|
}
|
|
5881
6024
|
return { kind: "regex", size: 1 };
|
|
5882
6025
|
}
|
|
5883
|
-
if (node.type ===
|
|
6026
|
+
if (node.type === AST_NODE_TYPES30.ArrayExpression) {
|
|
5884
6027
|
return isLiteralOnly(node, 0) ? { kind: "array", size: node.elements.length } : null;
|
|
5885
6028
|
}
|
|
5886
|
-
if (node.type ===
|
|
6029
|
+
if (node.type === AST_NODE_TYPES30.ObjectExpression) {
|
|
5887
6030
|
return isLiteralOnly(node, 0) ? { kind: "object", size: node.properties.length } : null;
|
|
5888
6031
|
}
|
|
5889
|
-
if (node.type ===
|
|
6032
|
+
if (node.type === AST_NODE_TYPES30.NewExpression && node.callee.type === AST_NODE_TYPES30.Identifier && COLLECTION_CONSTRUCTORS.has(node.callee.name)) {
|
|
5890
6033
|
const arg = node.arguments[0];
|
|
5891
|
-
if (node.arguments.length !== 1 || arg === void 0 || arg.type ===
|
|
6034
|
+
if (node.arguments.length !== 1 || arg === void 0 || arg.type === AST_NODE_TYPES30.SpreadElement) {
|
|
5892
6035
|
return null;
|
|
5893
6036
|
}
|
|
5894
6037
|
const entries = unwrap3(arg);
|
|
5895
|
-
if (entries.type !==
|
|
6038
|
+
if (entries.type !== AST_NODE_TYPES30.ArrayExpression) {
|
|
5896
6039
|
return null;
|
|
5897
6040
|
}
|
|
5898
6041
|
return isLiteralOnly(entries, 0) ? { kind: node.callee.name === "Set" ? "Set" : "Map", size: entries.elements.length } : null;
|
|
@@ -5921,10 +6064,10 @@ var NON_RETAINING_BUILTINS = /* @__PURE__ */ new Map(
|
|
|
5921
6064
|
);
|
|
5922
6065
|
function isNonRetainingBuiltinCall(node, argument) {
|
|
5923
6066
|
const callee = node.callee;
|
|
5924
|
-
if (callee.type ===
|
|
6067
|
+
if (callee.type === AST_NODE_TYPES30.Identifier && callee.name === "structuredClone") {
|
|
5925
6068
|
return true;
|
|
5926
6069
|
}
|
|
5927
|
-
if (callee.type !==
|
|
6070
|
+
if (callee.type !== AST_NODE_TYPES30.MemberExpression || callee.computed || callee.object.type !== AST_NODE_TYPES30.Identifier || callee.property.type !== AST_NODE_TYPES30.Identifier) {
|
|
5928
6071
|
return false;
|
|
5929
6072
|
}
|
|
5930
6073
|
const members = NON_RETAINING_BUILTINS.get(callee.object.name);
|
|
@@ -5938,38 +6081,38 @@ function isNonRetainingBuiltinCall(node, argument) {
|
|
|
5938
6081
|
}
|
|
5939
6082
|
function isSafeRead(identifier) {
|
|
5940
6083
|
const parent = identifier.parent;
|
|
5941
|
-
if (parent.type ===
|
|
6084
|
+
if (parent.type === AST_NODE_TYPES30.MemberExpression) {
|
|
5942
6085
|
if (parent.object !== identifier) {
|
|
5943
6086
|
return true;
|
|
5944
6087
|
}
|
|
5945
6088
|
const grandparent = parent.parent;
|
|
5946
|
-
if (grandparent.type ===
|
|
6089
|
+
if (grandparent.type === AST_NODE_TYPES30.AssignmentExpression && grandparent.left === parent) {
|
|
5947
6090
|
return false;
|
|
5948
6091
|
}
|
|
5949
|
-
if (grandparent.type ===
|
|
6092
|
+
if (grandparent.type === AST_NODE_TYPES30.UpdateExpression) {
|
|
5950
6093
|
return false;
|
|
5951
6094
|
}
|
|
5952
|
-
if (grandparent.type ===
|
|
6095
|
+
if (grandparent.type === AST_NODE_TYPES30.UnaryExpression && grandparent.operator === "delete") {
|
|
5953
6096
|
return false;
|
|
5954
6097
|
}
|
|
5955
|
-
if (!parent.computed && parent.property.type ===
|
|
6098
|
+
if (!parent.computed && parent.property.type === AST_NODE_TYPES30.Identifier && MUTATING_METHODS.has(parent.property.name) && grandparent.type === AST_NODE_TYPES30.CallExpression && grandparent.callee === parent) {
|
|
5956
6099
|
return false;
|
|
5957
6100
|
}
|
|
5958
6101
|
return true;
|
|
5959
6102
|
}
|
|
5960
|
-
if (parent.type ===
|
|
6103
|
+
if (parent.type === AST_NODE_TYPES30.ForOfStatement && parent.right === identifier) {
|
|
5961
6104
|
return true;
|
|
5962
6105
|
}
|
|
5963
|
-
if (parent.type ===
|
|
6106
|
+
if (parent.type === AST_NODE_TYPES30.SpreadElement) {
|
|
5964
6107
|
return true;
|
|
5965
6108
|
}
|
|
5966
|
-
if (parent.type ===
|
|
6109
|
+
if (parent.type === AST_NODE_TYPES30.BinaryExpression) {
|
|
5967
6110
|
return true;
|
|
5968
6111
|
}
|
|
5969
|
-
if (parent.type ===
|
|
6112
|
+
if (parent.type === AST_NODE_TYPES30.CallExpression && parent.arguments.includes(identifier) && isNonRetainingBuiltinCall(parent, identifier)) {
|
|
5970
6113
|
return true;
|
|
5971
6114
|
}
|
|
5972
|
-
if (parent.type ===
|
|
6115
|
+
if (parent.type === AST_NODE_TYPES30.UnaryExpression && parent.operator !== "delete") {
|
|
5973
6116
|
return true;
|
|
5974
6117
|
}
|
|
5975
6118
|
return false;
|
|
@@ -6024,7 +6167,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6024
6167
|
if (reference.isWrite()) {
|
|
6025
6168
|
return false;
|
|
6026
6169
|
}
|
|
6027
|
-
if (reference.identifier.type !==
|
|
6170
|
+
if (reference.identifier.type !== AST_NODE_TYPES30.Identifier) {
|
|
6028
6171
|
return false;
|
|
6029
6172
|
}
|
|
6030
6173
|
if (!isSafeRead(reference.identifier)) {
|
|
@@ -6036,10 +6179,10 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6036
6179
|
return {
|
|
6037
6180
|
VariableDeclarator(node) {
|
|
6038
6181
|
const declaration = node.parent;
|
|
6039
|
-
if (declaration.type !==
|
|
6182
|
+
if (declaration.type !== AST_NODE_TYPES30.VariableDeclaration || declaration.kind !== "const" || declaration.declare === true) {
|
|
6040
6183
|
return;
|
|
6041
6184
|
}
|
|
6042
|
-
if (node.id.type !==
|
|
6185
|
+
if (node.id.type !== AST_NODE_TYPES30.Identifier || node.init === null) {
|
|
6043
6186
|
return;
|
|
6044
6187
|
}
|
|
6045
6188
|
if (enclosingFunction2(node) === null) {
|
|
@@ -6066,7 +6209,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6066
6209
|
});
|
|
6067
6210
|
|
|
6068
6211
|
// src/rules/prefer-module-level-schema.ts
|
|
6069
|
-
import { AST_NODE_TYPES as
|
|
6212
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES31 } from "@typescript-eslint/utils";
|
|
6070
6213
|
|
|
6071
6214
|
// src/rules/_zod.ts
|
|
6072
6215
|
var ZOD_PREFIX_RE = /^Z[A-Z]/;
|
|
@@ -6104,9 +6247,9 @@ var TERMINAL_METHODS = /* @__PURE__ */ new Set([
|
|
|
6104
6247
|
"spa"
|
|
6105
6248
|
]);
|
|
6106
6249
|
var FUNCTION_TYPES6 = /* @__PURE__ */ new Set([
|
|
6107
|
-
|
|
6108
|
-
|
|
6109
|
-
|
|
6250
|
+
AST_NODE_TYPES31.ArrowFunctionExpression,
|
|
6251
|
+
AST_NODE_TYPES31.FunctionDeclaration,
|
|
6252
|
+
AST_NODE_TYPES31.FunctionExpression
|
|
6110
6253
|
]);
|
|
6111
6254
|
function schemaExpression(node) {
|
|
6112
6255
|
let current = node;
|
|
@@ -6115,10 +6258,10 @@ function schemaExpression(node) {
|
|
|
6115
6258
|
if (parent === void 0) {
|
|
6116
6259
|
return current;
|
|
6117
6260
|
}
|
|
6118
|
-
if (parent.type ===
|
|
6261
|
+
if (parent.type === AST_NODE_TYPES31.MemberExpression && parent.object === current && !parent.computed && parent.property.type === AST_NODE_TYPES31.Identifier && TERMINAL_METHODS.has(parent.property.name)) {
|
|
6119
6262
|
return current;
|
|
6120
6263
|
}
|
|
6121
|
-
if (parent.type ===
|
|
6264
|
+
if (parent.type === AST_NODE_TYPES31.MemberExpression && parent.object === current || parent.type === AST_NODE_TYPES31.CallExpression && parent.callee === current || parent.type === AST_NODE_TYPES31.TSAsExpression && parent.expression === current || parent.type === AST_NODE_TYPES31.TSNonNullExpression && parent.expression === current) {
|
|
6122
6265
|
current = parent;
|
|
6123
6266
|
continue;
|
|
6124
6267
|
}
|
|
@@ -6152,7 +6295,7 @@ function readsReceiver(node) {
|
|
|
6152
6295
|
if (typeof candidate.type !== "string") {
|
|
6153
6296
|
return;
|
|
6154
6297
|
}
|
|
6155
|
-
if (candidate.type ===
|
|
6298
|
+
if (candidate.type === AST_NODE_TYPES31.ThisExpression || candidate.type === AST_NODE_TYPES31.Super || candidate.type === AST_NODE_TYPES31.Identifier && candidate.name === "arguments") {
|
|
6156
6299
|
found = true;
|
|
6157
6300
|
return;
|
|
6158
6301
|
}
|
|
@@ -6220,15 +6363,15 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6220
6363
|
}
|
|
6221
6364
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
6222
6365
|
function isZodCall(node) {
|
|
6223
|
-
return node.type ===
|
|
6366
|
+
return node.type === AST_NODE_TYPES31.CallExpression && node.callee.type === AST_NODE_TYPES31.MemberExpression && !node.callee.computed && node.callee.object.type === AST_NODE_TYPES31.Identifier && zodNamespaces.has(node.callee.object.name);
|
|
6224
6367
|
}
|
|
6225
6368
|
function isCovered(node) {
|
|
6226
6369
|
let current = node.parent ?? void 0;
|
|
6227
6370
|
while (current !== void 0) {
|
|
6228
|
-
if (current !== node && isZodCall(current) && current.callee.type ===
|
|
6371
|
+
if (current !== node && isZodCall(current) && current.callee.type === AST_NODE_TYPES31.MemberExpression && current.callee.property.type === AST_NODE_TYPES31.Identifier && factories.has(current.callee.property.name)) {
|
|
6229
6372
|
return true;
|
|
6230
6373
|
}
|
|
6231
|
-
if (current.type ===
|
|
6374
|
+
if (current.type === AST_NODE_TYPES31.CallExpression && (current.callee.type === AST_NODE_TYPES31.Identifier && MEMO_CALLEES.has(current.callee.name) || current.callee.type === AST_NODE_TYPES31.MemberExpression && !current.callee.computed && current.callee.property.type === AST_NODE_TYPES31.Identifier && MEMO_CALLEES.has(current.callee.property.name))) {
|
|
6232
6375
|
return true;
|
|
6233
6376
|
}
|
|
6234
6377
|
current = current.parent ?? void 0;
|
|
@@ -6263,13 +6406,13 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6263
6406
|
}
|
|
6264
6407
|
function ownerName(enclosing) {
|
|
6265
6408
|
const parent = enclosing.parent ?? void 0;
|
|
6266
|
-
if (enclosing.type ===
|
|
6409
|
+
if (enclosing.type === AST_NODE_TYPES31.FunctionDeclaration && enclosing.id !== null) {
|
|
6267
6410
|
return enclosing.id.name;
|
|
6268
6411
|
}
|
|
6269
|
-
if (parent !== void 0 && parent.type ===
|
|
6412
|
+
if (parent !== void 0 && parent.type === AST_NODE_TYPES31.VariableDeclarator && parent.id.type === AST_NODE_TYPES31.Identifier) {
|
|
6270
6413
|
return parent.id.name;
|
|
6271
6414
|
}
|
|
6272
|
-
if (parent !== void 0 && (parent.type ===
|
|
6415
|
+
if (parent !== void 0 && (parent.type === AST_NODE_TYPES31.MethodDefinition || parent.type === AST_NODE_TYPES31.Property) && parent.key.type === AST_NODE_TYPES31.Identifier) {
|
|
6273
6416
|
return parent.key.name;
|
|
6274
6417
|
}
|
|
6275
6418
|
return "this function";
|
|
@@ -6280,7 +6423,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6280
6423
|
return;
|
|
6281
6424
|
}
|
|
6282
6425
|
for (const specifier of node.specifiers) {
|
|
6283
|
-
if (specifier.type ===
|
|
6426
|
+
if (specifier.type === AST_NODE_TYPES31.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES31.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES31.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES31.Identifier && specifier.imported.name === "z") {
|
|
6284
6427
|
zodNamespaces.add(specifier.local.name);
|
|
6285
6428
|
}
|
|
6286
6429
|
}
|
|
@@ -6290,7 +6433,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6290
6433
|
return;
|
|
6291
6434
|
}
|
|
6292
6435
|
const callee = node.callee;
|
|
6293
|
-
if (callee.property.type !==
|
|
6436
|
+
if (callee.property.type !== AST_NODE_TYPES31.Identifier) {
|
|
6294
6437
|
return;
|
|
6295
6438
|
}
|
|
6296
6439
|
const factory = callee.property.name;
|
|
@@ -6305,7 +6448,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6305
6448
|
return;
|
|
6306
6449
|
}
|
|
6307
6450
|
const shape = node.arguments[0];
|
|
6308
|
-
if (shape !== void 0 && shape.type ===
|
|
6451
|
+
if (shape !== void 0 && shape.type === AST_NODE_TYPES31.ObjectExpression && shape.properties.length < minProperties) {
|
|
6309
6452
|
return;
|
|
6310
6453
|
}
|
|
6311
6454
|
const expression = schemaExpression(node);
|
|
@@ -6326,20 +6469,20 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6326
6469
|
});
|
|
6327
6470
|
|
|
6328
6471
|
// src/rules/prefer-non-nullable-collection.ts
|
|
6329
|
-
import { AST_NODE_TYPES as
|
|
6472
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES32 } from "@typescript-eslint/utils";
|
|
6330
6473
|
var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
6331
6474
|
function propertyName(node) {
|
|
6332
6475
|
const key = node.key;
|
|
6333
|
-
if (key.type ===
|
|
6334
|
-
if (key.type ===
|
|
6476
|
+
if (key.type === AST_NODE_TYPES32.Identifier) return key.name;
|
|
6477
|
+
if (key.type === AST_NODE_TYPES32.Literal) return String(key.value);
|
|
6335
6478
|
return "collection";
|
|
6336
6479
|
}
|
|
6337
6480
|
function isArrayType(node) {
|
|
6338
|
-
if (node.type ===
|
|
6339
|
-
return node.type ===
|
|
6481
|
+
if (node.type === AST_NODE_TYPES32.TSArrayType) return true;
|
|
6482
|
+
return node.type === AST_NODE_TYPES32.TSTypeReference && node.typeName.type === AST_NODE_TYPES32.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
6340
6483
|
}
|
|
6341
6484
|
function isNullishType(node) {
|
|
6342
|
-
return node.type ===
|
|
6485
|
+
return node.type === AST_NODE_TYPES32.TSNullKeyword || node.type === AST_NODE_TYPES32.TSUndefinedKeyword;
|
|
6343
6486
|
}
|
|
6344
6487
|
function isNullableArrayOnly(node) {
|
|
6345
6488
|
const values = node.types.filter((member) => !isNullishType(member));
|
|
@@ -6366,7 +6509,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
6366
6509
|
function checkOptionalProperty(node) {
|
|
6367
6510
|
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
6368
6511
|
if (annotation === void 0) return;
|
|
6369
|
-
if (annotation.type !==
|
|
6512
|
+
if (annotation.type !== AST_NODE_TYPES32.TSUnionType || !isNullableArrayOnly(annotation)) {
|
|
6370
6513
|
return;
|
|
6371
6514
|
}
|
|
6372
6515
|
context.report({
|
|
@@ -6379,7 +6522,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
6379
6522
|
TSPropertySignature: checkOptionalProperty,
|
|
6380
6523
|
PropertyDefinition: checkOptionalProperty,
|
|
6381
6524
|
TSTypeAliasDeclaration(node) {
|
|
6382
|
-
if (node.typeAnnotation.type !==
|
|
6525
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES32.TSUnionType) return;
|
|
6383
6526
|
if (!isNullableArrayOnly(node.typeAnnotation)) return;
|
|
6384
6527
|
context.report({
|
|
6385
6528
|
node,
|
|
@@ -6392,13 +6535,13 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
6392
6535
|
});
|
|
6393
6536
|
|
|
6394
6537
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
6395
|
-
import { AST_NODE_TYPES as
|
|
6538
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES33 } from "@typescript-eslint/utils";
|
|
6396
6539
|
var unwrap4 = (node) => {
|
|
6397
6540
|
let current = node;
|
|
6398
6541
|
while (current !== null && current !== void 0) {
|
|
6399
|
-
if (current.type ===
|
|
6542
|
+
if (current.type === AST_NODE_TYPES33.TSAsExpression || current.type === AST_NODE_TYPES33.TSTypeAssertion || current.type === AST_NODE_TYPES33.TSNonNullExpression || current.type === AST_NODE_TYPES33.TSSatisfiesExpression) {
|
|
6400
6543
|
current = current.expression;
|
|
6401
|
-
} else if (current.type ===
|
|
6544
|
+
} else if (current.type === AST_NODE_TYPES33.ChainExpression) {
|
|
6402
6545
|
current = current.expression;
|
|
6403
6546
|
} else {
|
|
6404
6547
|
break;
|
|
@@ -6413,23 +6556,23 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
6413
6556
|
]);
|
|
6414
6557
|
var isSchemaParseReference = (node) => {
|
|
6415
6558
|
const inner = unwrap4(node);
|
|
6416
|
-
return inner !== null && inner.type ===
|
|
6559
|
+
return inner !== null && inner.type === AST_NODE_TYPES33.MemberExpression && !inner.computed && inner.property.type === AST_NODE_TYPES33.Identifier && (inner.property.name === "parse" || inner.property.name === "safeParse");
|
|
6417
6560
|
};
|
|
6418
6561
|
var isRawPayloadSource = (node) => {
|
|
6419
6562
|
let current = unwrap4(node);
|
|
6420
6563
|
if (current === null) return false;
|
|
6421
|
-
if (current.type ===
|
|
6564
|
+
if (current.type === AST_NODE_TYPES33.AwaitExpression) {
|
|
6422
6565
|
current = unwrap4(current.argument);
|
|
6423
6566
|
}
|
|
6424
|
-
if (current === null || current.type !==
|
|
6567
|
+
if (current === null || current.type !== AST_NODE_TYPES33.CallExpression) {
|
|
6425
6568
|
return false;
|
|
6426
6569
|
}
|
|
6427
6570
|
const callee = unwrap4(current.callee);
|
|
6428
|
-
if (callee === null || callee.type !==
|
|
6571
|
+
if (callee === null || callee.type !== AST_NODE_TYPES33.MemberExpression) {
|
|
6429
6572
|
return false;
|
|
6430
6573
|
}
|
|
6431
6574
|
const property = unwrap4(callee.property);
|
|
6432
|
-
if (property === null || property.type !==
|
|
6575
|
+
if (property === null || property.type !== AST_NODE_TYPES33.Identifier) {
|
|
6433
6576
|
return false;
|
|
6434
6577
|
}
|
|
6435
6578
|
if (property.name === "json") {
|
|
@@ -6439,7 +6582,7 @@ var isRawPayloadSource = (node) => {
|
|
|
6439
6582
|
return !current.arguments.some(isSchemaParseReference) && isRawPayloadSource(callee.object);
|
|
6440
6583
|
}
|
|
6441
6584
|
const object = unwrap4(callee.object);
|
|
6442
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
6585
|
+
return property.name === "parse" && object !== null && object.type === AST_NODE_TYPES33.Identifier && object.name === "JSON" && // ...but not `JSON.parse(readFileSync(p, "utf8"))` — see isLocalFileRead.
|
|
6443
6586
|
!isLocalFileRead(current.arguments[0]);
|
|
6444
6587
|
};
|
|
6445
6588
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
@@ -6447,9 +6590,9 @@ var isLocalFileRead = (node) => {
|
|
|
6447
6590
|
let found = false;
|
|
6448
6591
|
const visit = (current) => {
|
|
6449
6592
|
if (found || current === null || current === void 0) return;
|
|
6450
|
-
if (current.type ===
|
|
6593
|
+
if (current.type === AST_NODE_TYPES33.CallExpression) {
|
|
6451
6594
|
const callee = unwrap4(current.callee);
|
|
6452
|
-
const name = callee?.type ===
|
|
6595
|
+
const name = callee?.type === AST_NODE_TYPES33.Identifier ? callee.name : callee?.type === AST_NODE_TYPES33.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES33.Identifier ? callee.property.name : null;
|
|
6453
6596
|
if (name !== null && FILE_READ_RE.test(name)) {
|
|
6454
6597
|
found = true;
|
|
6455
6598
|
return;
|
|
@@ -6471,15 +6614,15 @@ var isLocalFileRead = (node) => {
|
|
|
6471
6614
|
var ASSERTION_CALLEE_RE = /^(expect|assert|should|invariant)$/;
|
|
6472
6615
|
var isInsideAssertion = (node) => {
|
|
6473
6616
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
6474
|
-
if (current.type !==
|
|
6617
|
+
if (current.type !== AST_NODE_TYPES33.CallExpression) continue;
|
|
6475
6618
|
let callee = current.callee;
|
|
6476
|
-
while (callee.type ===
|
|
6619
|
+
while (callee.type === AST_NODE_TYPES33.MemberExpression) {
|
|
6477
6620
|
callee = callee.object;
|
|
6478
6621
|
}
|
|
6479
|
-
if (callee.type ===
|
|
6622
|
+
if (callee.type === AST_NODE_TYPES33.CallExpression) {
|
|
6480
6623
|
callee = callee.callee;
|
|
6481
6624
|
}
|
|
6482
|
-
if (callee.type ===
|
|
6625
|
+
if (callee.type === AST_NODE_TYPES33.Identifier && ASSERTION_CALLEE_RE.test(callee.name)) {
|
|
6483
6626
|
return true;
|
|
6484
6627
|
}
|
|
6485
6628
|
}
|
|
@@ -6498,39 +6641,39 @@ var GUARD_NAME_RE = /^(?:is|validate|parse|assert|decode|coerce)[A-Z]/;
|
|
|
6498
6641
|
var isValidationRead = (node) => {
|
|
6499
6642
|
let current = node;
|
|
6500
6643
|
let parent = current.parent;
|
|
6501
|
-
while (parent !== null && parent !== void 0 && (parent.type ===
|
|
6644
|
+
while (parent !== null && parent !== void 0 && (parent.type === AST_NODE_TYPES33.TSAsExpression || parent.type === AST_NODE_TYPES33.TSTypeAssertion || parent.type === AST_NODE_TYPES33.TSNonNullExpression || parent.type === AST_NODE_TYPES33.TSSatisfiesExpression || parent.type === AST_NODE_TYPES33.ChainExpression)) {
|
|
6502
6645
|
current = parent;
|
|
6503
6646
|
parent = parent.parent;
|
|
6504
6647
|
}
|
|
6505
6648
|
if (parent === null || parent === void 0) return false;
|
|
6506
|
-
if (parent.type ===
|
|
6649
|
+
if (parent.type === AST_NODE_TYPES33.UnaryExpression && parent.operator === "typeof" && parent.argument === current) {
|
|
6507
6650
|
return true;
|
|
6508
6651
|
}
|
|
6509
|
-
if (parent.type !==
|
|
6652
|
+
if (parent.type !== AST_NODE_TYPES33.CallExpression || !parent.arguments.some((arg) => arg === current)) {
|
|
6510
6653
|
return false;
|
|
6511
6654
|
}
|
|
6512
6655
|
const callee = parent.callee;
|
|
6513
|
-
if (callee.type ===
|
|
6656
|
+
if (callee.type === AST_NODE_TYPES33.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES33.Identifier && callee.object.name === "Array" && callee.property.type === AST_NODE_TYPES33.Identifier && callee.property.name === "isArray") {
|
|
6514
6657
|
return parent.arguments.length === 1;
|
|
6515
6658
|
}
|
|
6516
|
-
return callee.type ===
|
|
6659
|
+
return callee.type === AST_NODE_TYPES33.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
6517
6660
|
};
|
|
6518
6661
|
var isGuardTestPosition = (node) => {
|
|
6519
6662
|
let current = node;
|
|
6520
6663
|
let parent = current.parent;
|
|
6521
6664
|
while (parent !== void 0 && parent !== null) {
|
|
6522
6665
|
switch (parent.type) {
|
|
6523
|
-
case
|
|
6524
|
-
case
|
|
6525
|
-
case
|
|
6666
|
+
case AST_NODE_TYPES33.UnaryExpression:
|
|
6667
|
+
case AST_NODE_TYPES33.LogicalExpression:
|
|
6668
|
+
case AST_NODE_TYPES33.ChainExpression:
|
|
6526
6669
|
current = parent;
|
|
6527
6670
|
parent = parent.parent;
|
|
6528
6671
|
continue;
|
|
6529
|
-
case
|
|
6530
|
-
case
|
|
6531
|
-
case
|
|
6532
|
-
case
|
|
6533
|
-
case
|
|
6672
|
+
case AST_NODE_TYPES33.IfStatement:
|
|
6673
|
+
case AST_NODE_TYPES33.ConditionalExpression:
|
|
6674
|
+
case AST_NODE_TYPES33.WhileStatement:
|
|
6675
|
+
case AST_NODE_TYPES33.DoWhileStatement:
|
|
6676
|
+
case AST_NODE_TYPES33.ForStatement:
|
|
6534
6677
|
return parent.test === current;
|
|
6535
6678
|
default:
|
|
6536
6679
|
return false;
|
|
@@ -6540,7 +6683,7 @@ var isGuardTestPosition = (node) => {
|
|
|
6540
6683
|
};
|
|
6541
6684
|
var isUnvalidatedVariableRef = (node, scope, tracked) => {
|
|
6542
6685
|
const unwrapped = unwrap4(node);
|
|
6543
|
-
if (unwrapped === null || unwrapped.type !==
|
|
6686
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES33.Identifier) {
|
|
6544
6687
|
return false;
|
|
6545
6688
|
}
|
|
6546
6689
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -6583,11 +6726,11 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6583
6726
|
return {
|
|
6584
6727
|
VariableDeclarator(node) {
|
|
6585
6728
|
const scope = context.sourceCode.getScope(node);
|
|
6586
|
-
if (node.id.type ===
|
|
6729
|
+
if (node.id.type === AST_NODE_TYPES33.Identifier) {
|
|
6587
6730
|
trackInitializer(node);
|
|
6588
6731
|
return;
|
|
6589
6732
|
}
|
|
6590
|
-
if (node.id.type ===
|
|
6733
|
+
if (node.id.type === AST_NODE_TYPES33.ObjectPattern || node.id.type === AST_NODE_TYPES33.ArrayPattern) {
|
|
6591
6734
|
if (isRawPayloadSource(node.init)) {
|
|
6592
6735
|
if (!isFullyNarrowedPattern(node)) {
|
|
6593
6736
|
context.report({ node: node.id, messageId: "unparsedJsonAccess" });
|
|
@@ -6601,7 +6744,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6601
6744
|
},
|
|
6602
6745
|
AssignmentExpression(node) {
|
|
6603
6746
|
const scope = context.sourceCode.getScope(node);
|
|
6604
|
-
if (node.left.type ===
|
|
6747
|
+
if (node.left.type === AST_NODE_TYPES33.Identifier) {
|
|
6605
6748
|
const variable = findVariable2(scope, node.left.name);
|
|
6606
6749
|
if (variable === null) return;
|
|
6607
6750
|
if (isRawPayloadSource(node.right)) {
|
|
@@ -6611,7 +6754,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6611
6754
|
}
|
|
6612
6755
|
return;
|
|
6613
6756
|
}
|
|
6614
|
-
if (node.left.type ===
|
|
6757
|
+
if (node.left.type === AST_NODE_TYPES33.ObjectPattern || node.left.type === AST_NODE_TYPES33.ArrayPattern) {
|
|
6615
6758
|
if (isRawPayloadSource(node.right)) {
|
|
6616
6759
|
context.report({
|
|
6617
6760
|
node: node.left,
|
|
@@ -6628,15 +6771,15 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6628
6771
|
}
|
|
6629
6772
|
},
|
|
6630
6773
|
CallExpression(node) {
|
|
6631
|
-
if (node.callee.type !==
|
|
6774
|
+
if (node.callee.type !== AST_NODE_TYPES33.Identifier) return;
|
|
6632
6775
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
6633
6776
|
return;
|
|
6634
6777
|
}
|
|
6635
6778
|
const scope = context.sourceCode.getScope(node);
|
|
6636
6779
|
for (const arg of node.arguments) {
|
|
6637
|
-
if (arg.type ===
|
|
6780
|
+
if (arg.type === AST_NODE_TYPES33.SpreadElement) continue;
|
|
6638
6781
|
const unwrapped = unwrap4(arg);
|
|
6639
|
-
if (unwrapped === null || unwrapped.type !==
|
|
6782
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES33.Identifier) {
|
|
6640
6783
|
continue;
|
|
6641
6784
|
}
|
|
6642
6785
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -6650,13 +6793,13 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6650
6793
|
const obj = unwrap4(node.object);
|
|
6651
6794
|
if (isRawPayloadSource(obj)) {
|
|
6652
6795
|
const parent = node.parent;
|
|
6653
|
-
if (parent.type ===
|
|
6796
|
+
if (parent.type === AST_NODE_TYPES33.CallExpression && parent.callee === node && node.property.type === AST_NODE_TYPES33.Identifier && (node.property.name === "parse" || node.property.name === "safeParse" || PROMISE_CHAIN_METHODS.has(node.property.name))) {
|
|
6654
6797
|
return;
|
|
6655
6798
|
}
|
|
6656
6799
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
6657
6800
|
return;
|
|
6658
6801
|
}
|
|
6659
|
-
if (obj !== null && obj.type ===
|
|
6802
|
+
if (obj !== null && obj.type === AST_NODE_TYPES33.Identifier && isUnvalidatedVariableRef(obj, scope, unvalidatedVariables)) {
|
|
6660
6803
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
6661
6804
|
const variable = findVariable2(scope, obj.name);
|
|
6662
6805
|
if (variable !== null) {
|
|
@@ -6669,7 +6812,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6669
6812
|
});
|
|
6670
6813
|
|
|
6671
6814
|
// src/rules/prefer-semantic-colors.ts
|
|
6672
|
-
import { AST_NODE_TYPES as
|
|
6815
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES34 } from "@typescript-eslint/utils";
|
|
6673
6816
|
import { existsSync, readFileSync } from "fs";
|
|
6674
6817
|
import { dirname, join, parse } from "path";
|
|
6675
6818
|
|
|
@@ -6746,8 +6889,8 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
6746
6889
|
]);
|
|
6747
6890
|
function jsxElementName(node) {
|
|
6748
6891
|
const name = node.openingElement.name;
|
|
6749
|
-
if (name.type ===
|
|
6750
|
-
if (name.type ===
|
|
6892
|
+
if (name.type === AST_NODE_TYPES34.JSXIdentifier) return name.name;
|
|
6893
|
+
if (name.type === AST_NODE_TYPES34.JSXMemberExpression && name.property.type === AST_NODE_TYPES34.JSXIdentifier) {
|
|
6751
6894
|
return name.property.name;
|
|
6752
6895
|
}
|
|
6753
6896
|
return null;
|
|
@@ -6773,7 +6916,7 @@ var EMAIL_OR_PDF_IMPORT_RE = /@react-(?:email|pdf)\//;
|
|
|
6773
6916
|
var isInsideSvg = (node) => {
|
|
6774
6917
|
let current = node.parent;
|
|
6775
6918
|
while (current !== void 0 && current !== null) {
|
|
6776
|
-
if (current.type ===
|
|
6919
|
+
if (current.type === AST_NODE_TYPES34.JSXElement) {
|
|
6777
6920
|
const name = jsxElementName(current);
|
|
6778
6921
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
6779
6922
|
}
|
|
@@ -6784,7 +6927,7 @@ var isInsideSvg = (node) => {
|
|
|
6784
6927
|
var isInsideIconFactoryPath = (node) => {
|
|
6785
6928
|
let current = node.parent;
|
|
6786
6929
|
while (current !== void 0 && current !== null) {
|
|
6787
|
-
if (current.type ===
|
|
6930
|
+
if (current.type === AST_NODE_TYPES34.Property && propName(current.key) === "path" && current.parent.type === AST_NODE_TYPES34.ObjectExpression && current.parent.parent.type === AST_NODE_TYPES34.CallExpression && current.parent.parent.callee.type === AST_NODE_TYPES34.Identifier && current.parent.parent.callee.name === "createIcon") {
|
|
6788
6931
|
return true;
|
|
6789
6932
|
}
|
|
6790
6933
|
current = current.parent;
|
|
@@ -6834,8 +6977,8 @@ var hasSemanticTokenSystem = (filename) => {
|
|
|
6834
6977
|
return answer;
|
|
6835
6978
|
};
|
|
6836
6979
|
var propName = (key) => {
|
|
6837
|
-
if (key.type ===
|
|
6838
|
-
if (key.type ===
|
|
6980
|
+
if (key.type === AST_NODE_TYPES34.Identifier) return key.name;
|
|
6981
|
+
if (key.type === AST_NODE_TYPES34.Literal && typeof key.value === "string") return key.value;
|
|
6839
6982
|
return null;
|
|
6840
6983
|
};
|
|
6841
6984
|
var prefer_semantic_colors_default = createRule({
|
|
@@ -6880,27 +7023,27 @@ var prefer_semantic_colors_default = createRule({
|
|
|
6880
7023
|
const checkClassNode = (node) => {
|
|
6881
7024
|
if (node === null) return;
|
|
6882
7025
|
switch (node.type) {
|
|
6883
|
-
case
|
|
7026
|
+
case AST_NODE_TYPES34.Literal:
|
|
6884
7027
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
6885
7028
|
break;
|
|
6886
|
-
case
|
|
7029
|
+
case AST_NODE_TYPES34.TemplateLiteral:
|
|
6887
7030
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
6888
7031
|
break;
|
|
6889
|
-
case
|
|
7032
|
+
case AST_NODE_TYPES34.ArrayExpression:
|
|
6890
7033
|
for (const element of node.elements) {
|
|
6891
|
-
if (element !== null && element.type !==
|
|
7034
|
+
if (element !== null && element.type !== AST_NODE_TYPES34.SpreadElement) checkClassNode(element);
|
|
6892
7035
|
}
|
|
6893
7036
|
break;
|
|
6894
|
-
case
|
|
7037
|
+
case AST_NODE_TYPES34.ObjectExpression:
|
|
6895
7038
|
for (const property of node.properties) {
|
|
6896
|
-
if (property.type ===
|
|
7039
|
+
if (property.type === AST_NODE_TYPES34.Property) checkClassNode(property.value);
|
|
6897
7040
|
}
|
|
6898
7041
|
break;
|
|
6899
|
-
case
|
|
7042
|
+
case AST_NODE_TYPES34.ConditionalExpression:
|
|
6900
7043
|
checkClassNode(node.consequent);
|
|
6901
7044
|
checkClassNode(node.alternate);
|
|
6902
7045
|
break;
|
|
6903
|
-
case
|
|
7046
|
+
case AST_NODE_TYPES34.LogicalExpression:
|
|
6904
7047
|
checkClassNode(node.right);
|
|
6905
7048
|
break;
|
|
6906
7049
|
default:
|
|
@@ -6908,29 +7051,29 @@ var prefer_semantic_colors_default = createRule({
|
|
|
6908
7051
|
}
|
|
6909
7052
|
};
|
|
6910
7053
|
const checkColorValueNode = (node) => {
|
|
6911
|
-
if (node.type ===
|
|
7054
|
+
if (node.type === AST_NODE_TYPES34.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value) && !CSS_VAR_REFERENCE_RE.test(node.value)) {
|
|
6912
7055
|
context.report({ node, messageId: "inlineColor", data: { value: node.value } });
|
|
6913
7056
|
}
|
|
6914
7057
|
};
|
|
6915
7058
|
return {
|
|
6916
7059
|
"JSXAttribute[name.name='className']"(node) {
|
|
6917
7060
|
if (node.value === null) return;
|
|
6918
|
-
if (node.value.type ===
|
|
6919
|
-
else if (node.value.type ===
|
|
6920
|
-
if (node.value.expression.type !==
|
|
7061
|
+
if (node.value.type === AST_NODE_TYPES34.Literal) checkClassNode(node.value);
|
|
7062
|
+
else if (node.value.type === AST_NODE_TYPES34.JSXExpressionContainer) {
|
|
7063
|
+
if (node.value.expression.type !== AST_NODE_TYPES34.JSXEmptyExpression) {
|
|
6921
7064
|
checkClassNode(node.value.expression);
|
|
6922
7065
|
}
|
|
6923
7066
|
}
|
|
6924
7067
|
},
|
|
6925
7068
|
CallExpression(node) {
|
|
6926
|
-
if (node.callee.type ===
|
|
7069
|
+
if (node.callee.type === AST_NODE_TYPES34.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
6927
7070
|
for (const arg of node.arguments) {
|
|
6928
|
-
if (arg.type !==
|
|
7071
|
+
if (arg.type !== AST_NODE_TYPES34.SpreadElement) checkClassNode(arg);
|
|
6929
7072
|
}
|
|
6930
7073
|
}
|
|
6931
7074
|
},
|
|
6932
7075
|
VariableDeclarator(node) {
|
|
6933
|
-
if (node.id.type ===
|
|
7076
|
+
if (node.id.type === AST_NODE_TYPES34.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
6934
7077
|
checkClassNode(node.init);
|
|
6935
7078
|
}
|
|
6936
7079
|
},
|
|
@@ -6942,9 +7085,9 @@ var prefer_semantic_colors_default = createRule({
|
|
|
6942
7085
|
// Neutral drawing literals and anything inside an SVG defs container are
|
|
6943
7086
|
// structural, not UI tokens, so they never fire.
|
|
6944
7087
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
6945
|
-
if (node.value?.type !==
|
|
7088
|
+
if (node.value?.type !== AST_NODE_TYPES34.Literal) return;
|
|
6946
7089
|
const owner = node.parent.name;
|
|
6947
|
-
if (owner.type ===
|
|
7090
|
+
if (owner.type === AST_NODE_TYPES34.JSXIdentifier && SVG_SHAPE_PRIMITIVES.has(owner.name)) {
|
|
6948
7091
|
return;
|
|
6949
7092
|
}
|
|
6950
7093
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
@@ -7117,7 +7260,7 @@ var prefer_server_actions_default = createRule({
|
|
|
7117
7260
|
// src/rules/prefer-string-literal-union.ts
|
|
7118
7261
|
import {
|
|
7119
7262
|
ESLintUtils as ESLintUtils3,
|
|
7120
|
-
AST_NODE_TYPES as
|
|
7263
|
+
AST_NODE_TYPES as AST_NODE_TYPES35
|
|
7121
7264
|
} from "@typescript-eslint/utils";
|
|
7122
7265
|
import * as ts2 from "typescript";
|
|
7123
7266
|
var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
@@ -7161,19 +7304,19 @@ function isChoiceLikeName(name) {
|
|
|
7161
7304
|
return CHOICE_TOKENS.has(lastWord(name));
|
|
7162
7305
|
}
|
|
7163
7306
|
function keyName(key) {
|
|
7164
|
-
if (key.type ===
|
|
7307
|
+
if (key.type === AST_NODE_TYPES35.Identifier) {
|
|
7165
7308
|
return key.name;
|
|
7166
7309
|
}
|
|
7167
|
-
if (key.type ===
|
|
7310
|
+
if (key.type === AST_NODE_TYPES35.Literal && typeof key.value === "string") {
|
|
7168
7311
|
return key.value;
|
|
7169
7312
|
}
|
|
7170
7313
|
return null;
|
|
7171
7314
|
}
|
|
7172
7315
|
function isStringLiteralMember(t) {
|
|
7173
|
-
return t.type ===
|
|
7316
|
+
return t.type === AST_NODE_TYPES35.TSLiteralType && t.literal.type === AST_NODE_TYPES35.Literal && typeof t.literal.value === "string";
|
|
7174
7317
|
}
|
|
7175
7318
|
function isStringLiteralUnion(node) {
|
|
7176
|
-
if (node?.type !==
|
|
7319
|
+
if (node?.type !== AST_NODE_TYPES35.TSUnionType) {
|
|
7177
7320
|
return false;
|
|
7178
7321
|
}
|
|
7179
7322
|
return node.types.filter(isStringLiteralMember).length >= MIN_CLUSTER_SIZE;
|
|
@@ -7202,12 +7345,12 @@ function bindingSourceExpression(decl) {
|
|
|
7202
7345
|
return ts2.isForOfStatement(node) ? node.expression : node.initializer;
|
|
7203
7346
|
}
|
|
7204
7347
|
function refKey(node) {
|
|
7205
|
-
if (node.type ===
|
|
7348
|
+
if (node.type === AST_NODE_TYPES35.Identifier) {
|
|
7206
7349
|
return node.name;
|
|
7207
7350
|
}
|
|
7208
|
-
if (node.type ===
|
|
7351
|
+
if (node.type === AST_NODE_TYPES35.MemberExpression && !node.computed) {
|
|
7209
7352
|
const inner = refKey(node.object);
|
|
7210
|
-
if (inner === null || node.property.type !==
|
|
7353
|
+
if (inner === null || node.property.type !== AST_NODE_TYPES35.Identifier) {
|
|
7211
7354
|
return null;
|
|
7212
7355
|
}
|
|
7213
7356
|
return `${inner}.${node.property.name}`;
|
|
@@ -7215,7 +7358,7 @@ function refKey(node) {
|
|
|
7215
7358
|
return null;
|
|
7216
7359
|
}
|
|
7217
7360
|
function strLiteral(node) {
|
|
7218
|
-
if (node.type ===
|
|
7361
|
+
if (node.type === AST_NODE_TYPES35.Literal && typeof node.value === "string") {
|
|
7219
7362
|
return node.value;
|
|
7220
7363
|
}
|
|
7221
7364
|
return null;
|
|
@@ -7368,7 +7511,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
7368
7511
|
containersWithUnion.add(container);
|
|
7369
7512
|
return;
|
|
7370
7513
|
}
|
|
7371
|
-
if (typeNode?.type !==
|
|
7514
|
+
if (typeNode?.type !== AST_NODE_TYPES35.TSStringKeyword) {
|
|
7372
7515
|
return;
|
|
7373
7516
|
}
|
|
7374
7517
|
const name = keyName(key);
|
|
@@ -7456,10 +7599,10 @@ var prefer_string_literal_union_default = createRule({
|
|
|
7456
7599
|
}
|
|
7457
7600
|
};
|
|
7458
7601
|
function refKeyText(node) {
|
|
7459
|
-
if (node.type ===
|
|
7602
|
+
if (node.type === AST_NODE_TYPES35.BinaryExpression) {
|
|
7460
7603
|
return refKey(node.left) ?? refKey(node.right) ?? "value";
|
|
7461
7604
|
}
|
|
7462
|
-
if (node.type ===
|
|
7605
|
+
if (node.type === AST_NODE_TYPES35.SwitchStatement) {
|
|
7463
7606
|
return refKey(node.discriminant) ?? "value";
|
|
7464
7607
|
}
|
|
7465
7608
|
return "value";
|
|
@@ -7468,7 +7611,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
7468
7611
|
});
|
|
7469
7612
|
|
|
7470
7613
|
// src/rules/prefer-whole-object-assertion.ts
|
|
7471
|
-
import { AST_NODE_TYPES as
|
|
7614
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES36 } from "@typescript-eslint/utils";
|
|
7472
7615
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
7473
7616
|
var ARRAY_MATCHERS = /* @__PURE__ */ new Set(["toEqual", "toStrictEqual"]);
|
|
7474
7617
|
var COLLECTION_PROPERTIES = /* @__PURE__ */ new Set(["length", "size"]);
|
|
@@ -7476,11 +7619,11 @@ var NUMERIC_SIGNS2 = /* @__PURE__ */ new Set(["-", "+"]);
|
|
|
7476
7619
|
var MIN_RUN_LENGTH = 2;
|
|
7477
7620
|
function literalText(node, getText) {
|
|
7478
7621
|
switch (node.type) {
|
|
7479
|
-
case
|
|
7622
|
+
case AST_NODE_TYPES36.Literal:
|
|
7480
7623
|
return "regex" in node ? null : getText(node);
|
|
7481
|
-
case
|
|
7624
|
+
case AST_NODE_TYPES36.TemplateLiteral:
|
|
7482
7625
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
7483
|
-
case
|
|
7626
|
+
case AST_NODE_TYPES36.UnaryExpression:
|
|
7484
7627
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
7485
7628
|
default:
|
|
7486
7629
|
return null;
|
|
@@ -7488,15 +7631,15 @@ function literalText(node, getText) {
|
|
|
7488
7631
|
}
|
|
7489
7632
|
function isPureReceiver(node) {
|
|
7490
7633
|
switch (node.type) {
|
|
7491
|
-
case
|
|
7492
|
-
case
|
|
7634
|
+
case AST_NODE_TYPES36.Identifier:
|
|
7635
|
+
case AST_NODE_TYPES36.ThisExpression:
|
|
7493
7636
|
return true;
|
|
7494
|
-
case
|
|
7637
|
+
case AST_NODE_TYPES36.MemberExpression:
|
|
7495
7638
|
if (node.optional) {
|
|
7496
7639
|
return false;
|
|
7497
7640
|
}
|
|
7498
7641
|
if (node.computed) {
|
|
7499
|
-
return node.property.type ===
|
|
7642
|
+
return node.property.type === AST_NODE_TYPES36.Literal && isPureReceiver(node.object);
|
|
7500
7643
|
}
|
|
7501
7644
|
return isPureReceiver(node.object);
|
|
7502
7645
|
default:
|
|
@@ -7504,7 +7647,7 @@ function isPureReceiver(node) {
|
|
|
7504
7647
|
}
|
|
7505
7648
|
}
|
|
7506
7649
|
function literalIndex(node) {
|
|
7507
|
-
if (node.type !==
|
|
7650
|
+
if (node.type !== AST_NODE_TYPES36.Literal || typeof node.value !== "number") {
|
|
7508
7651
|
return null;
|
|
7509
7652
|
}
|
|
7510
7653
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
@@ -7530,24 +7673,24 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
7530
7673
|
}
|
|
7531
7674
|
const { sourceCode } = context;
|
|
7532
7675
|
function parseAssertion(statement) {
|
|
7533
|
-
if (statement.type !==
|
|
7676
|
+
if (statement.type !== AST_NODE_TYPES36.ExpressionStatement) {
|
|
7534
7677
|
return null;
|
|
7535
7678
|
}
|
|
7536
7679
|
const call = statement.expression;
|
|
7537
|
-
if (call.type !==
|
|
7680
|
+
if (call.type !== AST_NODE_TYPES36.CallExpression) {
|
|
7538
7681
|
return null;
|
|
7539
7682
|
}
|
|
7540
7683
|
const callee = call.callee;
|
|
7541
|
-
if (callee.type !==
|
|
7684
|
+
if (callee.type !== AST_NODE_TYPES36.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES36.Identifier) {
|
|
7542
7685
|
return null;
|
|
7543
7686
|
}
|
|
7544
7687
|
const matcher = callee.property.name;
|
|
7545
7688
|
const expectCall = callee.object;
|
|
7546
|
-
if (expectCall.type !==
|
|
7689
|
+
if (expectCall.type !== AST_NODE_TYPES36.CallExpression || expectCall.callee.type !== AST_NODE_TYPES36.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
7547
7690
|
return null;
|
|
7548
7691
|
}
|
|
7549
7692
|
const actual = expectCall.arguments[0];
|
|
7550
|
-
if (actual === void 0 || actual.type !==
|
|
7693
|
+
if (actual === void 0 || actual.type !== AST_NODE_TYPES36.MemberExpression || actual.optional) {
|
|
7551
7694
|
return null;
|
|
7552
7695
|
}
|
|
7553
7696
|
if (!isPureReceiver(actual.object)) {
|
|
@@ -7561,7 +7704,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
7561
7704
|
}
|
|
7562
7705
|
key = { kind: "index", index };
|
|
7563
7706
|
} else {
|
|
7564
|
-
if (actual.property.type !==
|
|
7707
|
+
if (actual.property.type !== AST_NODE_TYPES36.Identifier || COLLECTION_PROPERTIES.has(actual.property.name)) {
|
|
7565
7708
|
return null;
|
|
7566
7709
|
}
|
|
7567
7710
|
key = { kind: "property", name: actual.property.name };
|
|
@@ -7573,7 +7716,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
7573
7716
|
return null;
|
|
7574
7717
|
}
|
|
7575
7718
|
const expected = call.arguments[0];
|
|
7576
|
-
if (call.arguments.length !== 1 || expected === void 0 || expected.type ===
|
|
7719
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === AST_NODE_TYPES36.SpreadElement) {
|
|
7577
7720
|
return null;
|
|
7578
7721
|
}
|
|
7579
7722
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
@@ -7683,7 +7826,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
7683
7826
|
});
|
|
7684
7827
|
|
|
7685
7828
|
// src/rules/prefer-zod-enum.ts
|
|
7686
|
-
import { AST_NODE_TYPES as
|
|
7829
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES37 } from "@typescript-eslint/utils";
|
|
7687
7830
|
var prefer_zod_enum_default = createRule({
|
|
7688
7831
|
name: "prefer-zod-enum",
|
|
7689
7832
|
meta: {
|
|
@@ -7703,20 +7846,20 @@ var prefer_zod_enum_default = createRule({
|
|
|
7703
7846
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
7704
7847
|
function enumValues(node) {
|
|
7705
7848
|
const callee = node.callee;
|
|
7706
|
-
if (callee.type !==
|
|
7849
|
+
if (callee.type !== AST_NODE_TYPES37.MemberExpression || callee.computed || callee.object.type !== AST_NODE_TYPES37.Identifier || !zodNamespaces.has(callee.object.name) || callee.property.type !== AST_NODE_TYPES37.Identifier || callee.property.name !== "union" || node.arguments.length !== 1) {
|
|
7707
7850
|
return null;
|
|
7708
7851
|
}
|
|
7709
7852
|
const argument = node.arguments[0];
|
|
7710
|
-
if (argument === void 0 || argument.type !==
|
|
7853
|
+
if (argument === void 0 || argument.type !== AST_NODE_TYPES37.ArrayExpression || argument.elements.length === 0) {
|
|
7711
7854
|
return null;
|
|
7712
7855
|
}
|
|
7713
7856
|
const values = [];
|
|
7714
7857
|
for (const element of argument.elements) {
|
|
7715
|
-
if (element === null || element.type !==
|
|
7858
|
+
if (element === null || element.type !== AST_NODE_TYPES37.CallExpression || element.arguments.length !== 1 || element.callee.type !== AST_NODE_TYPES37.MemberExpression || element.callee.computed || element.callee.object.type !== AST_NODE_TYPES37.Identifier || !zodNamespaces.has(element.callee.object.name) || element.callee.property.type !== AST_NODE_TYPES37.Identifier || element.callee.property.name !== "literal") {
|
|
7716
7859
|
return null;
|
|
7717
7860
|
}
|
|
7718
7861
|
const value = element.arguments[0];
|
|
7719
|
-
if (value === void 0 || value.type !==
|
|
7862
|
+
if (value === void 0 || value.type !== AST_NODE_TYPES37.Literal || typeof value.value !== "string") {
|
|
7720
7863
|
return null;
|
|
7721
7864
|
}
|
|
7722
7865
|
values.push(value);
|
|
@@ -7725,11 +7868,11 @@ var prefer_zod_enum_default = createRule({
|
|
|
7725
7868
|
}
|
|
7726
7869
|
function buildFix(node, values) {
|
|
7727
7870
|
const argument = node.arguments[0];
|
|
7728
|
-
if (argument === void 0 || argument.type !==
|
|
7871
|
+
if (argument === void 0 || argument.type !== AST_NODE_TYPES37.ArrayExpression || sourceCode.getCommentsInside(argument).length > 0) {
|
|
7729
7872
|
return void 0;
|
|
7730
7873
|
}
|
|
7731
7874
|
const callee = node.callee;
|
|
7732
|
-
if (callee.type !==
|
|
7875
|
+
if (callee.type !== AST_NODE_TYPES37.MemberExpression || callee.property.type !== AST_NODE_TYPES37.Identifier) {
|
|
7733
7876
|
return void 0;
|
|
7734
7877
|
}
|
|
7735
7878
|
return (fixer) => [
|
|
@@ -7746,7 +7889,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
7746
7889
|
return;
|
|
7747
7890
|
}
|
|
7748
7891
|
for (const specifier of node.specifiers) {
|
|
7749
|
-
if (specifier.type ===
|
|
7892
|
+
if (specifier.type === AST_NODE_TYPES37.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES37.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES37.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES37.Identifier && specifier.imported.name === "z") {
|
|
7750
7893
|
zodNamespaces.add(specifier.local.name);
|
|
7751
7894
|
}
|
|
7752
7895
|
}
|
|
@@ -7768,7 +7911,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
7768
7911
|
});
|
|
7769
7912
|
|
|
7770
7913
|
// src/rules/prefer-zod-infer.ts
|
|
7771
|
-
import { AST_NODE_TYPES as
|
|
7914
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES38 } from "@typescript-eslint/utils";
|
|
7772
7915
|
var SHAPE_PRESERVING_METHODS = /* @__PURE__ */ new Set([
|
|
7773
7916
|
"describe",
|
|
7774
7917
|
"refine",
|
|
@@ -7805,44 +7948,44 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
7805
7948
|
"Schema"
|
|
7806
7949
|
]);
|
|
7807
7950
|
var LEAF_NODE_TYPES = {
|
|
7808
|
-
string: [
|
|
7809
|
-
email: [
|
|
7810
|
-
url: [
|
|
7811
|
-
uuid: [
|
|
7812
|
-
ulid: [
|
|
7813
|
-
cuid: [
|
|
7814
|
-
cuid2: [
|
|
7815
|
-
nanoid: [
|
|
7816
|
-
iso: [
|
|
7817
|
-
number: [
|
|
7818
|
-
int: [
|
|
7819
|
-
float32: [
|
|
7820
|
-
float64: [
|
|
7821
|
-
boolean: [
|
|
7822
|
-
bigint: [
|
|
7823
|
-
symbol: [
|
|
7824
|
-
any: [
|
|
7825
|
-
unknown: [
|
|
7826
|
-
never: [
|
|
7827
|
-
void: [
|
|
7828
|
-
null: [
|
|
7829
|
-
undefined: [
|
|
7830
|
-
literal: [
|
|
7831
|
-
date: [
|
|
7832
|
-
array: [
|
|
7833
|
-
tuple: [
|
|
7834
|
-
object: [
|
|
7835
|
-
strictObject: [
|
|
7836
|
-
looseObject: [
|
|
7837
|
-
record: [
|
|
7838
|
-
map: [
|
|
7839
|
-
set: [
|
|
7840
|
-
promise: [
|
|
7841
|
-
enum: [
|
|
7842
|
-
nativeEnum: [
|
|
7843
|
-
union: [
|
|
7844
|
-
discriminatedUnion: [
|
|
7845
|
-
intersection: [
|
|
7951
|
+
string: [AST_NODE_TYPES38.TSStringKeyword],
|
|
7952
|
+
email: [AST_NODE_TYPES38.TSStringKeyword],
|
|
7953
|
+
url: [AST_NODE_TYPES38.TSStringKeyword],
|
|
7954
|
+
uuid: [AST_NODE_TYPES38.TSStringKeyword],
|
|
7955
|
+
ulid: [AST_NODE_TYPES38.TSStringKeyword],
|
|
7956
|
+
cuid: [AST_NODE_TYPES38.TSStringKeyword],
|
|
7957
|
+
cuid2: [AST_NODE_TYPES38.TSStringKeyword],
|
|
7958
|
+
nanoid: [AST_NODE_TYPES38.TSStringKeyword],
|
|
7959
|
+
iso: [AST_NODE_TYPES38.TSStringKeyword],
|
|
7960
|
+
number: [AST_NODE_TYPES38.TSNumberKeyword],
|
|
7961
|
+
int: [AST_NODE_TYPES38.TSNumberKeyword],
|
|
7962
|
+
float32: [AST_NODE_TYPES38.TSNumberKeyword],
|
|
7963
|
+
float64: [AST_NODE_TYPES38.TSNumberKeyword],
|
|
7964
|
+
boolean: [AST_NODE_TYPES38.TSBooleanKeyword],
|
|
7965
|
+
bigint: [AST_NODE_TYPES38.TSBigIntKeyword],
|
|
7966
|
+
symbol: [AST_NODE_TYPES38.TSSymbolKeyword],
|
|
7967
|
+
any: [AST_NODE_TYPES38.TSAnyKeyword],
|
|
7968
|
+
unknown: [AST_NODE_TYPES38.TSUnknownKeyword],
|
|
7969
|
+
never: [AST_NODE_TYPES38.TSNeverKeyword],
|
|
7970
|
+
void: [AST_NODE_TYPES38.TSVoidKeyword],
|
|
7971
|
+
null: [AST_NODE_TYPES38.TSNullKeyword],
|
|
7972
|
+
undefined: [AST_NODE_TYPES38.TSUndefinedKeyword],
|
|
7973
|
+
literal: [AST_NODE_TYPES38.TSLiteralType],
|
|
7974
|
+
date: [AST_NODE_TYPES38.TSTypeReference],
|
|
7975
|
+
array: [AST_NODE_TYPES38.TSArrayType, AST_NODE_TYPES38.TSTypeReference],
|
|
7976
|
+
tuple: [AST_NODE_TYPES38.TSTupleType],
|
|
7977
|
+
object: [AST_NODE_TYPES38.TSTypeLiteral, AST_NODE_TYPES38.TSTypeReference],
|
|
7978
|
+
strictObject: [AST_NODE_TYPES38.TSTypeLiteral, AST_NODE_TYPES38.TSTypeReference],
|
|
7979
|
+
looseObject: [AST_NODE_TYPES38.TSTypeLiteral, AST_NODE_TYPES38.TSTypeReference],
|
|
7980
|
+
record: [AST_NODE_TYPES38.TSTypeReference, AST_NODE_TYPES38.TSTypeLiteral],
|
|
7981
|
+
map: [AST_NODE_TYPES38.TSTypeReference],
|
|
7982
|
+
set: [AST_NODE_TYPES38.TSTypeReference],
|
|
7983
|
+
promise: [AST_NODE_TYPES38.TSTypeReference],
|
|
7984
|
+
enum: [AST_NODE_TYPES38.TSUnionType, AST_NODE_TYPES38.TSTypeReference, AST_NODE_TYPES38.TSLiteralType],
|
|
7985
|
+
nativeEnum: [AST_NODE_TYPES38.TSUnionType, AST_NODE_TYPES38.TSTypeReference, AST_NODE_TYPES38.TSLiteralType],
|
|
7986
|
+
union: [AST_NODE_TYPES38.TSUnionType, AST_NODE_TYPES38.TSTypeReference],
|
|
7987
|
+
discriminatedUnion: [AST_NODE_TYPES38.TSUnionType, AST_NODE_TYPES38.TSTypeReference],
|
|
7988
|
+
intersection: [AST_NODE_TYPES38.TSIntersectionType, AST_NODE_TYPES38.TSTypeReference]
|
|
7846
7989
|
};
|
|
7847
7990
|
function normalizeSchemaName(name) {
|
|
7848
7991
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -7851,20 +7994,20 @@ function normalizeTypeName(name) {
|
|
|
7851
7994
|
return name.replace(/Type$/, "").toLowerCase();
|
|
7852
7995
|
}
|
|
7853
7996
|
function unwrapNullish(annotation) {
|
|
7854
|
-
if (annotation.type !==
|
|
7997
|
+
if (annotation.type !== AST_NODE_TYPES38.TSUnionType) {
|
|
7855
7998
|
return {
|
|
7856
7999
|
core: annotation,
|
|
7857
|
-
nullable: annotation.type ===
|
|
8000
|
+
nullable: annotation.type === AST_NODE_TYPES38.TSNullKeyword
|
|
7858
8001
|
};
|
|
7859
8002
|
}
|
|
7860
8003
|
const rest = [];
|
|
7861
8004
|
let nullable = false;
|
|
7862
8005
|
for (const member of annotation.types) {
|
|
7863
|
-
if (member.type ===
|
|
8006
|
+
if (member.type === AST_NODE_TYPES38.TSNullKeyword) {
|
|
7864
8007
|
nullable = true;
|
|
7865
8008
|
continue;
|
|
7866
8009
|
}
|
|
7867
|
-
if (member.type ===
|
|
8010
|
+
if (member.type === AST_NODE_TYPES38.TSUndefinedKeyword) {
|
|
7868
8011
|
continue;
|
|
7869
8012
|
}
|
|
7870
8013
|
rest.push(member);
|
|
@@ -7929,14 +8072,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
7929
8072
|
function zodCallChain(node) {
|
|
7930
8073
|
const chain = [];
|
|
7931
8074
|
let current = node;
|
|
7932
|
-
while (current.type ===
|
|
8075
|
+
while (current.type === AST_NODE_TYPES38.CallExpression) {
|
|
7933
8076
|
const callee = current.callee;
|
|
7934
|
-
if (callee.type !==
|
|
8077
|
+
if (callee.type !== AST_NODE_TYPES38.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES38.Identifier) {
|
|
7935
8078
|
return null;
|
|
7936
8079
|
}
|
|
7937
8080
|
chain.push(current);
|
|
7938
8081
|
const receiver = callee.object;
|
|
7939
|
-
if (receiver.type ===
|
|
8082
|
+
if (receiver.type === AST_NODE_TYPES38.Identifier) {
|
|
7940
8083
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
7941
8084
|
}
|
|
7942
8085
|
current = receiver;
|
|
@@ -7945,19 +8088,19 @@ var prefer_zod_infer_default = createRule({
|
|
|
7945
8088
|
}
|
|
7946
8089
|
function methodName(call) {
|
|
7947
8090
|
const callee = call.callee;
|
|
7948
|
-
return callee.type ===
|
|
8091
|
+
return callee.type === AST_NODE_TYPES38.MemberExpression && callee.property.type === AST_NODE_TYPES38.Identifier ? callee.property.name : "";
|
|
7949
8092
|
}
|
|
7950
8093
|
function schemaField(node) {
|
|
7951
8094
|
const modifiers = [];
|
|
7952
8095
|
let current = node;
|
|
7953
8096
|
let leaf = null;
|
|
7954
|
-
while (current.type ===
|
|
8097
|
+
while (current.type === AST_NODE_TYPES38.CallExpression) {
|
|
7955
8098
|
const callee = current.callee;
|
|
7956
|
-
if (callee.type !==
|
|
8099
|
+
if (callee.type !== AST_NODE_TYPES38.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES38.Identifier) {
|
|
7957
8100
|
break;
|
|
7958
8101
|
}
|
|
7959
8102
|
const receiver = callee.object;
|
|
7960
|
-
if (receiver.type ===
|
|
8103
|
+
if (receiver.type === AST_NODE_TYPES38.Identifier && zodNamespaces.has(receiver.name)) {
|
|
7961
8104
|
leaf = callee.property.name;
|
|
7962
8105
|
break;
|
|
7963
8106
|
}
|
|
@@ -7988,16 +8131,16 @@ var prefer_zod_infer_default = createRule({
|
|
|
7988
8131
|
return null;
|
|
7989
8132
|
}
|
|
7990
8133
|
const shape = base.arguments[0];
|
|
7991
|
-
if (shape === void 0 || shape.type !==
|
|
8134
|
+
if (shape === void 0 || shape.type !== AST_NODE_TYPES38.ObjectExpression) {
|
|
7992
8135
|
return null;
|
|
7993
8136
|
}
|
|
7994
8137
|
const fields = /* @__PURE__ */ new Map();
|
|
7995
8138
|
for (const property of shape.properties) {
|
|
7996
|
-
if (property.type !==
|
|
8139
|
+
if (property.type !== AST_NODE_TYPES38.Property || property.computed) {
|
|
7997
8140
|
return null;
|
|
7998
8141
|
}
|
|
7999
8142
|
const { key } = property;
|
|
8000
|
-
const name = key.type ===
|
|
8143
|
+
const name = key.type === AST_NODE_TYPES38.Identifier ? key.name : key.type === AST_NODE_TYPES38.Literal && typeof key.value === "string" ? key.value : null;
|
|
8001
8144
|
if (name === null) {
|
|
8002
8145
|
return null;
|
|
8003
8146
|
}
|
|
@@ -8008,11 +8151,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
8008
8151
|
function typeMembers(members) {
|
|
8009
8152
|
const result = /* @__PURE__ */ new Map();
|
|
8010
8153
|
for (const member of members) {
|
|
8011
|
-
if (member.type !==
|
|
8154
|
+
if (member.type !== AST_NODE_TYPES38.TSPropertySignature || member.computed) {
|
|
8012
8155
|
return null;
|
|
8013
8156
|
}
|
|
8014
8157
|
const { key } = member;
|
|
8015
|
-
const name = key.type ===
|
|
8158
|
+
const name = key.type === AST_NODE_TYPES38.Identifier ? key.name : key.type === AST_NODE_TYPES38.Literal && typeof key.value === "string" ? key.value : null;
|
|
8016
8159
|
if (name === null) {
|
|
8017
8160
|
return null;
|
|
8018
8161
|
}
|
|
@@ -8026,8 +8169,8 @@ var prefer_zod_infer_default = createRule({
|
|
|
8026
8169
|
return result.size === 0 ? null : result;
|
|
8027
8170
|
}
|
|
8028
8171
|
function collectConstrainedNames(node) {
|
|
8029
|
-
if (node.type ===
|
|
8030
|
-
if (node.typeName.type ===
|
|
8172
|
+
if (node.type === AST_NODE_TYPES38.TSTypeReference) {
|
|
8173
|
+
if (node.typeName.type === AST_NODE_TYPES38.Identifier) {
|
|
8031
8174
|
constrainedTypeNames.add(node.typeName.name);
|
|
8032
8175
|
}
|
|
8033
8176
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -8035,11 +8178,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
8035
8178
|
}
|
|
8036
8179
|
return;
|
|
8037
8180
|
}
|
|
8038
|
-
if (node.type ===
|
|
8181
|
+
if (node.type === AST_NODE_TYPES38.TSArrayType) {
|
|
8039
8182
|
collectConstrainedNames(node.elementType);
|
|
8040
8183
|
return;
|
|
8041
8184
|
}
|
|
8042
|
-
if (node.type ===
|
|
8185
|
+
if (node.type === AST_NODE_TYPES38.TSUnionType || node.type === AST_NODE_TYPES38.TSIntersectionType) {
|
|
8043
8186
|
for (const member of node.types) {
|
|
8044
8187
|
collectConstrainedNames(member);
|
|
8045
8188
|
}
|
|
@@ -8083,13 +8226,13 @@ var prefer_zod_infer_default = createRule({
|
|
|
8083
8226
|
return;
|
|
8084
8227
|
}
|
|
8085
8228
|
for (const specifier of node.specifiers) {
|
|
8086
|
-
if (specifier.type ===
|
|
8229
|
+
if (specifier.type === AST_NODE_TYPES38.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES38.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES38.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES38.Identifier && specifier.imported.name === "z") {
|
|
8087
8230
|
zodNamespaces.add(specifier.local.name);
|
|
8088
8231
|
}
|
|
8089
8232
|
}
|
|
8090
8233
|
},
|
|
8091
8234
|
VariableDeclarator(node) {
|
|
8092
|
-
if (node.id.type !==
|
|
8235
|
+
if (node.id.type !== AST_NODE_TYPES38.Identifier || node.init == null) {
|
|
8093
8236
|
return;
|
|
8094
8237
|
}
|
|
8095
8238
|
const fields = schemaFields(node.init);
|
|
@@ -8099,14 +8242,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
8099
8242
|
},
|
|
8100
8243
|
/** Guard (f): `XSchema.transform(...)` anywhere in the module. */
|
|
8101
8244
|
"MemberExpression[computed=false]"(node) {
|
|
8102
|
-
if (node.object.type ===
|
|
8245
|
+
if (node.object.type === AST_NODE_TYPES38.Identifier && node.property.type === AST_NODE_TYPES38.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
8103
8246
|
reshapedSchemaNames.add(node.object.name);
|
|
8104
8247
|
}
|
|
8105
8248
|
},
|
|
8106
8249
|
/** Guard (c): `z.ZodType<T>` and every other type argument it carries. */
|
|
8107
8250
|
TSTypeReference(node) {
|
|
8108
8251
|
const { typeName } = node;
|
|
8109
|
-
const referenced = typeName.type ===
|
|
8252
|
+
const referenced = typeName.type === AST_NODE_TYPES38.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES38.TSQualifiedName && typeName.right.type === AST_NODE_TYPES38.Identifier ? typeName.right.name : null;
|
|
8110
8253
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
8111
8254
|
return;
|
|
8112
8255
|
}
|
|
@@ -8124,7 +8267,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
8124
8267
|
}
|
|
8125
8268
|
},
|
|
8126
8269
|
TSTypeAliasDeclaration(node) {
|
|
8127
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
8270
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== AST_NODE_TYPES38.TSTypeLiteral) {
|
|
8128
8271
|
return;
|
|
8129
8272
|
}
|
|
8130
8273
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -8169,36 +8312,36 @@ var prefer_zod_infer_default = createRule({
|
|
|
8169
8312
|
});
|
|
8170
8313
|
|
|
8171
8314
|
// src/rules/require-assert-never.ts
|
|
8172
|
-
import { AST_NODE_TYPES as
|
|
8315
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES39 } from "@typescript-eslint/utils";
|
|
8173
8316
|
var isAssertNeverCall = (expression) => {
|
|
8174
|
-
if (expression.type !==
|
|
8317
|
+
if (expression.type !== AST_NODE_TYPES39.CallExpression) return false;
|
|
8175
8318
|
const callee = expression.callee;
|
|
8176
|
-
if (callee.type ===
|
|
8319
|
+
if (callee.type === AST_NODE_TYPES39.Identifier) {
|
|
8177
8320
|
return callee.name === "assertNever";
|
|
8178
8321
|
}
|
|
8179
|
-
if (callee.type ===
|
|
8322
|
+
if (callee.type === AST_NODE_TYPES39.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES39.Identifier) {
|
|
8180
8323
|
return callee.property.name === "assertNever";
|
|
8181
8324
|
}
|
|
8182
8325
|
return false;
|
|
8183
8326
|
};
|
|
8184
8327
|
var statementContainsAssertNever = (statement) => {
|
|
8185
|
-
if (statement.type ===
|
|
8328
|
+
if (statement.type === AST_NODE_TYPES39.ExpressionStatement) {
|
|
8186
8329
|
return isAssertNeverCall(statement.expression);
|
|
8187
8330
|
}
|
|
8188
|
-
if (statement.type ===
|
|
8331
|
+
if (statement.type === AST_NODE_TYPES39.ThrowStatement) {
|
|
8189
8332
|
return isAssertNeverCall(statement.argument);
|
|
8190
8333
|
}
|
|
8191
|
-
if (statement.type ===
|
|
8334
|
+
if (statement.type === AST_NODE_TYPES39.ReturnStatement) {
|
|
8192
8335
|
return statement.argument !== null && isAssertNeverCall(statement.argument);
|
|
8193
8336
|
}
|
|
8194
|
-
if (statement.type ===
|
|
8337
|
+
if (statement.type === AST_NODE_TYPES39.BlockStatement) {
|
|
8195
8338
|
return statement.body.some(statementContainsAssertNever);
|
|
8196
8339
|
}
|
|
8197
8340
|
return false;
|
|
8198
8341
|
};
|
|
8199
8342
|
var isRuntimeHandlingStatement = (statement) => {
|
|
8200
|
-
if (statement.type ===
|
|
8201
|
-
if (statement.type ===
|
|
8343
|
+
if (statement.type === AST_NODE_TYPES39.EmptyStatement) return false;
|
|
8344
|
+
if (statement.type === AST_NODE_TYPES39.BlockStatement) {
|
|
8202
8345
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
8203
8346
|
}
|
|
8204
8347
|
return true;
|
|
@@ -8214,7 +8357,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
8214
8357
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
8215
8358
|
}
|
|
8216
8359
|
const only = defaultCase.consequent[0];
|
|
8217
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
8360
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === AST_NODE_TYPES39.BlockStatement && only.body.length === 0) {
|
|
8218
8361
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
8219
8362
|
}
|
|
8220
8363
|
return false;
|
|
@@ -8255,7 +8398,7 @@ var require_assert_never_default = createRule({
|
|
|
8255
8398
|
});
|
|
8256
8399
|
|
|
8257
8400
|
// src/rules/require-fetch-timeout.ts
|
|
8258
|
-
import { AST_NODE_TYPES as
|
|
8401
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES40, ASTUtils as ASTUtils2 } from "@typescript-eslint/utils";
|
|
8259
8402
|
var CODEMOD_FIXTURE_RE = /[\\/]__testfixtures__[\\/]/;
|
|
8260
8403
|
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set([
|
|
8261
8404
|
"globalThis",
|
|
@@ -8272,14 +8415,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
8272
8415
|
return false;
|
|
8273
8416
|
}
|
|
8274
8417
|
function initProvablyLacksSignal(init) {
|
|
8275
|
-
if (init.type !==
|
|
8418
|
+
if (init.type !== AST_NODE_TYPES40.ObjectExpression) {
|
|
8276
8419
|
return false;
|
|
8277
8420
|
}
|
|
8278
8421
|
for (const prop of init.properties) {
|
|
8279
|
-
if (prop.type ===
|
|
8422
|
+
if (prop.type === AST_NODE_TYPES40.SpreadElement) {
|
|
8280
8423
|
return false;
|
|
8281
8424
|
}
|
|
8282
|
-
if (prop.key.type ===
|
|
8425
|
+
if (prop.key.type === AST_NODE_TYPES40.Identifier && prop.key.name === "signal" || prop.key.type === AST_NODE_TYPES40.Literal && prop.key.value === "signal") {
|
|
8283
8426
|
return false;
|
|
8284
8427
|
}
|
|
8285
8428
|
if (prop.computed) {
|
|
@@ -8289,7 +8432,7 @@ function initProvablyLacksSignal(init) {
|
|
|
8289
8432
|
return true;
|
|
8290
8433
|
}
|
|
8291
8434
|
function isStringish(node) {
|
|
8292
|
-
return node.type ===
|
|
8435
|
+
return node.type === AST_NODE_TYPES40.Literal && typeof node.value === "string" || node.type === AST_NODE_TYPES40.TemplateLiteral;
|
|
8293
8436
|
}
|
|
8294
8437
|
var require_fetch_timeout_default = createRule({
|
|
8295
8438
|
name: "require-fetch-timeout",
|
|
@@ -8330,10 +8473,10 @@ var require_fetch_timeout_default = createRule({
|
|
|
8330
8473
|
return variable === null || variable.defs.length === 0;
|
|
8331
8474
|
}
|
|
8332
8475
|
function isGlobalFetchCall2(callee) {
|
|
8333
|
-
if (callee.type ===
|
|
8476
|
+
if (callee.type === AST_NODE_TYPES40.Identifier) {
|
|
8334
8477
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
8335
8478
|
}
|
|
8336
|
-
return callee.type ===
|
|
8479
|
+
return callee.type === AST_NODE_TYPES40.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES40.Identifier && callee.property.name === "fetch" && callee.object.type === AST_NODE_TYPES40.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
8337
8480
|
}
|
|
8338
8481
|
return {
|
|
8339
8482
|
CallExpression(node) {
|
|
@@ -8353,26 +8496,26 @@ var require_fetch_timeout_default = createRule({
|
|
|
8353
8496
|
});
|
|
8354
8497
|
|
|
8355
8498
|
// src/rules/require-interface-for-injected-service.ts
|
|
8356
|
-
import { AST_NODE_TYPES as
|
|
8499
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES41 } from "@typescript-eslint/utils";
|
|
8357
8500
|
var CONFIGISH_TYPE_RE = /(?:Options|Opts|Config|Configuration|Settings|Params|Props|Args|Env|Environment|Callbacks|Flags)$/;
|
|
8358
8501
|
var CONFIGISH_NAME_RE = /^(?:options|opts|config|configuration|settings|params|props|args|env|environment|callbacks|flags|logger|log|clock)$/i;
|
|
8359
8502
|
var HTTP_TRANSPORT_TYPE_RE = /^(?:KyInstance|AxiosInstance|Session)$/;
|
|
8360
8503
|
var TRANSPORT_WRAPPER_NAME_RE = /Client$/;
|
|
8361
8504
|
var ROUTER_FACTORY_NAME = "Router";
|
|
8362
8505
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
8363
|
-
var isExportedClass = (node) => node.parent.type ===
|
|
8364
|
-
var qualifiedName = (name) => name.type ===
|
|
8506
|
+
var isExportedClass = (node) => node.parent.type === AST_NODE_TYPES41.ExportNamedDeclaration || node.parent.type === AST_NODE_TYPES41.ExportDefaultDeclaration;
|
|
8507
|
+
var qualifiedName = (name) => name.type === AST_NODE_TYPES41.Identifier ? name.name : name.type === AST_NODE_TYPES41.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
8365
8508
|
var typeReferenceName = (annotated) => {
|
|
8366
8509
|
let target = annotated;
|
|
8367
|
-
if (target.type ===
|
|
8368
|
-
if (target.type ===
|
|
8369
|
-
if (target.type !==
|
|
8510
|
+
if (target.type === AST_NODE_TYPES41.TSParameterProperty) target = target.parameter;
|
|
8511
|
+
if (target.type === AST_NODE_TYPES41.AssignmentPattern) target = target.left;
|
|
8512
|
+
if (target.type !== AST_NODE_TYPES41.Identifier) return null;
|
|
8370
8513
|
const annotation = target.typeAnnotation?.typeAnnotation;
|
|
8371
|
-
if (annotation === void 0 || annotation.type !==
|
|
8514
|
+
if (annotation === void 0 || annotation.type !== AST_NODE_TYPES41.TSTypeReference) {
|
|
8372
8515
|
return null;
|
|
8373
8516
|
}
|
|
8374
8517
|
const { typeName } = annotation;
|
|
8375
|
-
const rightmost = typeName.type ===
|
|
8518
|
+
const rightmost = typeName.type === AST_NODE_TYPES41.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES41.TSQualifiedName ? typeName.right.name : null;
|
|
8376
8519
|
if (rightmost === null) return null;
|
|
8377
8520
|
return { name: target.name, typeName: rightmost, display: qualifiedName(typeName) };
|
|
8378
8521
|
};
|
|
@@ -8382,17 +8525,17 @@ var readConstructor = (ctor) => {
|
|
|
8382
8525
|
let constructedFields = 0;
|
|
8383
8526
|
if (body !== null && body !== void 0) {
|
|
8384
8527
|
for (const statement of body.body) {
|
|
8385
|
-
if (statement.type !==
|
|
8528
|
+
if (statement.type !== AST_NODE_TYPES41.ExpressionStatement) continue;
|
|
8386
8529
|
const expression = statement.expression;
|
|
8387
|
-
if (expression.type !==
|
|
8530
|
+
if (expression.type !== AST_NODE_TYPES41.AssignmentExpression || expression.operator !== "=" || expression.left.type !== AST_NODE_TYPES41.MemberExpression || expression.left.object.type !== AST_NODE_TYPES41.ThisExpression) {
|
|
8388
8531
|
continue;
|
|
8389
8532
|
}
|
|
8390
8533
|
const source = expression.right;
|
|
8391
|
-
if (source.type ===
|
|
8534
|
+
if (source.type === AST_NODE_TYPES41.NewExpression) {
|
|
8392
8535
|
constructedFields += 1;
|
|
8393
|
-
} else if (source.type ===
|
|
8536
|
+
} else if (source.type === AST_NODE_TYPES41.Identifier) {
|
|
8394
8537
|
storedFrom.add(source.name);
|
|
8395
|
-
} else if (source.type ===
|
|
8538
|
+
} else if (source.type === AST_NODE_TYPES41.MemberExpression && source.object.type === AST_NODE_TYPES41.Identifier) {
|
|
8396
8539
|
storedFrom.add(source.object.name);
|
|
8397
8540
|
}
|
|
8398
8541
|
}
|
|
@@ -8401,7 +8544,7 @@ var readConstructor = (ctor) => {
|
|
|
8401
8544
|
for (const parameter of ctor.value.params) {
|
|
8402
8545
|
const reference = typeReferenceName(parameter);
|
|
8403
8546
|
if (reference === null) continue;
|
|
8404
|
-
const stored = parameter.type ===
|
|
8547
|
+
const stored = parameter.type === AST_NODE_TYPES41.TSParameterProperty || storedFrom.has(reference.name);
|
|
8405
8548
|
if (!stored) continue;
|
|
8406
8549
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
8407
8550
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -8431,19 +8574,19 @@ var subtreeHas = (root, found) => {
|
|
|
8431
8574
|
return hit;
|
|
8432
8575
|
};
|
|
8433
8576
|
var isFrameworkWiring = (body) => subtreeHas(body, (node) => {
|
|
8434
|
-
if (node.type ===
|
|
8577
|
+
if (node.type === AST_NODE_TYPES41.CallExpression) {
|
|
8435
8578
|
const { callee } = node;
|
|
8436
|
-
if (callee.type ===
|
|
8437
|
-
return callee.type ===
|
|
8579
|
+
if (callee.type === AST_NODE_TYPES41.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
8580
|
+
return callee.type === AST_NODE_TYPES41.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES41.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
8438
8581
|
}
|
|
8439
|
-
return node.type ===
|
|
8582
|
+
return node.type === AST_NODE_TYPES41.TSTypeReference && node.typeName.type === AST_NODE_TYPES41.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
8440
8583
|
});
|
|
8441
8584
|
var stem2 = (name) => name.replace(/^I(?=[A-Z])/, "").replace(/Impl$/, "");
|
|
8442
8585
|
var fileInterfaceNames = (program) => {
|
|
8443
8586
|
const names = [];
|
|
8444
8587
|
for (const statement of program.body) {
|
|
8445
|
-
const declaration = statement.type ===
|
|
8446
|
-
if (declaration?.type ===
|
|
8588
|
+
const declaration = statement.type === AST_NODE_TYPES41.ExportNamedDeclaration ? statement.declaration : statement;
|
|
8589
|
+
if (declaration?.type === AST_NODE_TYPES41.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
8447
8590
|
}
|
|
8448
8591
|
return names;
|
|
8449
8592
|
};
|
|
@@ -8461,11 +8604,11 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
8461
8604
|
var publicMethodNames = (body) => {
|
|
8462
8605
|
const names = [];
|
|
8463
8606
|
for (const member of body.body) {
|
|
8464
|
-
if (member.type !==
|
|
8607
|
+
if (member.type !== AST_NODE_TYPES41.MethodDefinition) continue;
|
|
8465
8608
|
if (member.kind !== "method" || member.static) continue;
|
|
8466
8609
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
8467
|
-
if (member.key.type ===
|
|
8468
|
-
if (member.key.type ===
|
|
8610
|
+
if (member.key.type === AST_NODE_TYPES41.PrivateIdentifier) continue;
|
|
8611
|
+
if (member.key.type === AST_NODE_TYPES41.Identifier) names.push(member.key.name);
|
|
8469
8612
|
else names.push("\u2026");
|
|
8470
8613
|
}
|
|
8471
8614
|
return names;
|
|
@@ -8496,7 +8639,7 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
8496
8639
|
if (node.implements.length > 0) return;
|
|
8497
8640
|
if (node.decorators.length > 0) return;
|
|
8498
8641
|
const ctor = node.body.body.find(
|
|
8499
|
-
(member) => member.type ===
|
|
8642
|
+
(member) => member.type === AST_NODE_TYPES41.MethodDefinition && member.kind === "constructor"
|
|
8500
8643
|
);
|
|
8501
8644
|
if (ctor === void 0) return;
|
|
8502
8645
|
const { collaborators, constructedFields } = readConstructor(ctor);
|
|
@@ -8521,18 +8664,18 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
8521
8664
|
});
|
|
8522
8665
|
|
|
8523
8666
|
// src/rules/require-zod-form-validation.ts
|
|
8524
|
-
import { AST_NODE_TYPES as
|
|
8667
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES42 } from "@typescript-eslint/utils";
|
|
8525
8668
|
var looksLikeZodSchema = (node) => {
|
|
8526
8669
|
let current = node;
|
|
8527
8670
|
while (true) {
|
|
8528
|
-
if (current.type ===
|
|
8671
|
+
if (current.type === AST_NODE_TYPES42.Identifier) {
|
|
8529
8672
|
return current.name === "z" || ZOD_SCHEMA_NAME_RE.test(current.name);
|
|
8530
8673
|
}
|
|
8531
|
-
if (current.type ===
|
|
8674
|
+
if (current.type === AST_NODE_TYPES42.CallExpression) {
|
|
8532
8675
|
current = current.callee;
|
|
8533
8676
|
continue;
|
|
8534
8677
|
}
|
|
8535
|
-
if (current.type ===
|
|
8678
|
+
if (current.type === AST_NODE_TYPES42.MemberExpression) {
|
|
8536
8679
|
current = current.object;
|
|
8537
8680
|
continue;
|
|
8538
8681
|
}
|
|
@@ -8540,23 +8683,23 @@ var looksLikeZodSchema = (node) => {
|
|
|
8540
8683
|
}
|
|
8541
8684
|
};
|
|
8542
8685
|
var isZodParseCall = (node) => {
|
|
8543
|
-
if (node.type !==
|
|
8686
|
+
if (node.type !== AST_NODE_TYPES42.CallExpression) return false;
|
|
8544
8687
|
const callee = node.callee;
|
|
8545
|
-
if (callee.type !==
|
|
8688
|
+
if (callee.type !== AST_NODE_TYPES42.MemberExpression) return false;
|
|
8546
8689
|
if (callee.computed) return false;
|
|
8547
|
-
if (callee.property.type !==
|
|
8690
|
+
if (callee.property.type !== AST_NODE_TYPES42.Identifier) return false;
|
|
8548
8691
|
const method = callee.property.name;
|
|
8549
8692
|
if (method !== "parse" && method !== "safeParse") return false;
|
|
8550
8693
|
return looksLikeZodSchema(callee.object);
|
|
8551
8694
|
};
|
|
8552
8695
|
var isFormDataMethodCall = (node) => {
|
|
8553
8696
|
let current = node;
|
|
8554
|
-
if (current.type ===
|
|
8697
|
+
if (current.type === AST_NODE_TYPES42.AwaitExpression) {
|
|
8555
8698
|
current = current.argument;
|
|
8556
8699
|
}
|
|
8557
|
-
if (current.type !==
|
|
8700
|
+
if (current.type !== AST_NODE_TYPES42.CallExpression) return false;
|
|
8558
8701
|
const callee = current.callee;
|
|
8559
|
-
return callee.type ===
|
|
8702
|
+
return callee.type === AST_NODE_TYPES42.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES42.Identifier && callee.property.name === "formData";
|
|
8560
8703
|
};
|
|
8561
8704
|
var require_zod_form_validation_default = createRule({
|
|
8562
8705
|
name: "require-zod-form-validation",
|
|
@@ -8576,14 +8719,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
8576
8719
|
return {};
|
|
8577
8720
|
}
|
|
8578
8721
|
const isFormSourceIdentifier = (node) => {
|
|
8579
|
-
if (node.type !==
|
|
8722
|
+
if (node.type !== AST_NODE_TYPES42.Identifier) return false;
|
|
8580
8723
|
if (/formdata/i.test(node.name)) return true;
|
|
8581
8724
|
let scope = context.sourceCode.getScope(node);
|
|
8582
8725
|
while (scope !== null) {
|
|
8583
8726
|
const variable = scope.set.get(node.name);
|
|
8584
8727
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
8585
8728
|
const def = variable.defs[0];
|
|
8586
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
8729
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === AST_NODE_TYPES42.VariableDeclarator && def.node.init !== null) {
|
|
8587
8730
|
return isFormDataMethodCall(def.node.init);
|
|
8588
8731
|
}
|
|
8589
8732
|
return false;
|
|
@@ -8594,8 +8737,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
8594
8737
|
};
|
|
8595
8738
|
const isFormDataGetCall = (node) => {
|
|
8596
8739
|
const callee = node.callee;
|
|
8597
|
-
if (callee.type !==
|
|
8598
|
-
if (callee.property.type !==
|
|
8740
|
+
if (callee.type !== AST_NODE_TYPES42.MemberExpression) return false;
|
|
8741
|
+
if (callee.property.type !== AST_NODE_TYPES42.Identifier || callee.property.name !== "get") {
|
|
8599
8742
|
return false;
|
|
8600
8743
|
}
|
|
8601
8744
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -8610,11 +8753,11 @@ var require_zod_form_validation_default = createRule({
|
|
|
8610
8753
|
};
|
|
8611
8754
|
const isInstanceofNarrowing = (node) => {
|
|
8612
8755
|
const parent = node.parent;
|
|
8613
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
8756
|
+
return parent !== null && parent !== void 0 && parent.type === AST_NODE_TYPES42.BinaryExpression && parent.operator === "instanceof" && parent.left === node;
|
|
8614
8757
|
};
|
|
8615
8758
|
const boundDeclarator = (node) => {
|
|
8616
8759
|
const parent = node.parent;
|
|
8617
|
-
if (parent.type ===
|
|
8760
|
+
if (parent.type === AST_NODE_TYPES42.VariableDeclarator && parent.init === node && parent.id.type === AST_NODE_TYPES42.Identifier) {
|
|
8618
8761
|
return parent;
|
|
8619
8762
|
}
|
|
8620
8763
|
return null;
|
|
@@ -8673,7 +8816,7 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
8673
8816
|
});
|
|
8674
8817
|
|
|
8675
8818
|
// src/rules/zod-naming-convention.ts
|
|
8676
|
-
import { AST_NODE_TYPES as
|
|
8819
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES43 } from "@typescript-eslint/utils";
|
|
8677
8820
|
var CONVENTIONS = {
|
|
8678
8821
|
prefix: { test: ZOD_PREFIX_RE, messageId: "zPrefix" },
|
|
8679
8822
|
suffix: { test: ZOD_SUFFIX_RE, messageId: "schemaSuffix" },
|
|
@@ -8698,15 +8841,15 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
8698
8841
|
"registry",
|
|
8699
8842
|
"implement"
|
|
8700
8843
|
]);
|
|
8701
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
8844
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === AST_NODE_TYPES43.Identifier ? callee.property.name : null;
|
|
8702
8845
|
var calleeChainStartsWithZ = (node) => {
|
|
8703
8846
|
let current = node;
|
|
8704
|
-
while (current.type ===
|
|
8847
|
+
while (current.type === AST_NODE_TYPES43.MemberExpression) {
|
|
8705
8848
|
const receiver = current.object;
|
|
8706
|
-
if (receiver.type ===
|
|
8849
|
+
if (receiver.type === AST_NODE_TYPES43.Identifier && receiver.name === "z") {
|
|
8707
8850
|
return true;
|
|
8708
8851
|
}
|
|
8709
|
-
if (receiver.type ===
|
|
8852
|
+
if (receiver.type === AST_NODE_TYPES43.CallExpression) {
|
|
8710
8853
|
current = receiver.callee;
|
|
8711
8854
|
continue;
|
|
8712
8855
|
}
|
|
@@ -8751,13 +8894,13 @@ var zod_naming_convention_default = createRule({
|
|
|
8751
8894
|
VariableDeclarator(node) {
|
|
8752
8895
|
const init = node.init;
|
|
8753
8896
|
if (init === null || init === void 0) return;
|
|
8754
|
-
if (init.type !==
|
|
8897
|
+
if (init.type !== AST_NODE_TYPES43.CallExpression) return;
|
|
8755
8898
|
const callee = init.callee;
|
|
8756
|
-
if (callee.type !==
|
|
8899
|
+
if (callee.type !== AST_NODE_TYPES43.MemberExpression) return;
|
|
8757
8900
|
if (!calleeChainStartsWithZ(callee)) return;
|
|
8758
8901
|
const terminal = terminalMethodName(callee);
|
|
8759
8902
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
8760
|
-
if (node.id.type !==
|
|
8903
|
+
if (node.id.type !== AST_NODE_TYPES43.Identifier) return;
|
|
8761
8904
|
if (test.test(node.id.name)) return;
|
|
8762
8905
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
8763
8906
|
context.report({
|
|
@@ -8808,6 +8951,7 @@ var rules = {
|
|
|
8808
8951
|
"no-string-concat-in-loop": no_string_concat_in_loop_default,
|
|
8809
8952
|
"no-tautological-expect": no_tautological_expect_default,
|
|
8810
8953
|
"no-trailing-value-narration": no_trailing_value_narration_default,
|
|
8954
|
+
"no-declaration-comment-wall": no_declaration_comment_wall_default,
|
|
8811
8955
|
"no-type-member-comment-wall": no_type_member_comment_wall_default,
|
|
8812
8956
|
"no-unnecessary-use-client": no_unnecessary_use_client_default,
|
|
8813
8957
|
"no-unsafe-mock-casting": no_unsafe_mock_casting_default,
|
|
@@ -8833,7 +8977,7 @@ var rules = {
|
|
|
8833
8977
|
};
|
|
8834
8978
|
var meta = {
|
|
8835
8979
|
name: "@sarj/eslint-plugin",
|
|
8836
|
-
version: "7.
|
|
8980
|
+
version: "7.1.0"
|
|
8837
8981
|
};
|
|
8838
8982
|
var renames = renamedRules;
|
|
8839
8983
|
var deprecatedAliases = Object.fromEntries(
|
|
@@ -8882,6 +9026,7 @@ var recommendedRules = {
|
|
|
8882
9026
|
"@sarj/no-string-concat-in-loop": "warn",
|
|
8883
9027
|
"@sarj/no-tautological-expect": "warn",
|
|
8884
9028
|
"@sarj/no-trailing-value-narration": "warn",
|
|
9029
|
+
"@sarj/no-declaration-comment-wall": "warn",
|
|
8885
9030
|
"@sarj/no-type-member-comment-wall": "warn",
|
|
8886
9031
|
"@sarj/no-unnecessary-use-client": "warn",
|
|
8887
9032
|
"@sarj/no-unsafe-mock-casting": "warn",
|
|
@@ -8935,6 +9080,7 @@ var strictRules = {
|
|
|
8935
9080
|
"@sarj/no-string-concat-in-loop": "error",
|
|
8936
9081
|
"@sarj/no-tautological-expect": "error",
|
|
8937
9082
|
"@sarj/no-trailing-value-narration": "error",
|
|
9083
|
+
"@sarj/no-declaration-comment-wall": "error",
|
|
8938
9084
|
"@sarj/no-type-member-comment-wall": "error",
|
|
8939
9085
|
"@sarj/no-unnecessary-use-client": "error",
|
|
8940
9086
|
"@sarj/no-unsafe-mock-casting": "error",
|