@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.cjs
CHANGED
|
@@ -5032,29 +5032,61 @@ var no_trailing_value_narration_default = createRule({
|
|
|
5032
5032
|
}
|
|
5033
5033
|
});
|
|
5034
5034
|
|
|
5035
|
-
// src/rules/no-
|
|
5035
|
+
// src/rules/no-declaration-comment-wall.ts
|
|
5036
|
+
var import_utils35 = require("@typescript-eslint/utils");
|
|
5037
|
+
|
|
5038
|
+
// src/rules/_comment-wall.ts
|
|
5036
5039
|
var import_utils34 = require("@typescript-eslint/utils");
|
|
5037
|
-
var
|
|
5040
|
+
var WALL_DEFAULTS = {
|
|
5038
5041
|
// Below three rows "a wall" is not a fair description of what the reader sees.
|
|
5039
5042
|
minCommentedMembers: 3,
|
|
5040
5043
|
// A minority of commented members is a GROUP LABEL, not a wall.
|
|
5041
5044
|
minCommentedRatio: 0.6,
|
|
5042
|
-
// Room for one substantive row in four; a
|
|
5043
|
-
// say something real is
|
|
5045
|
+
// Room for one substantive row in four; a declaration where a quarter of the
|
|
5046
|
+
// comments say something real is one someone was documenting, not decorating.
|
|
5044
5047
|
minRestatedRatio: 0.75,
|
|
5045
|
-
// One word beyond the member's own text. Zero is `no-restated-jsdoc`'s
|
|
5046
|
-
//
|
|
5047
|
-
// beside "Exact match")
|
|
5048
|
+
// One word beyond the member's own text. Zero is `no-restated-jsdoc`'s test
|
|
5049
|
+
// and is already covered there; two admits definitions ("Partial match"
|
|
5050
|
+
// beside "Exact match").
|
|
5048
5051
|
maxNovelWords: 1
|
|
5049
5052
|
};
|
|
5053
|
+
var WALL_SCHEMA = {
|
|
5054
|
+
type: "object",
|
|
5055
|
+
additionalProperties: false,
|
|
5056
|
+
properties: {
|
|
5057
|
+
minCommentedMembers: {
|
|
5058
|
+
type: "integer",
|
|
5059
|
+
minimum: 2,
|
|
5060
|
+
description: "Fewest commented members that can count as a wall."
|
|
5061
|
+
},
|
|
5062
|
+
minCommentedRatio: {
|
|
5063
|
+
type: "number",
|
|
5064
|
+
minimum: 0,
|
|
5065
|
+
maximum: 1,
|
|
5066
|
+
description: "Least share of the members that must be commented; below it the comments are group labels."
|
|
5067
|
+
},
|
|
5068
|
+
minRestatedRatio: {
|
|
5069
|
+
type: "number",
|
|
5070
|
+
minimum: 0,
|
|
5071
|
+
maximum: 1,
|
|
5072
|
+
description: "Least share of the member comments that must be restatements."
|
|
5073
|
+
},
|
|
5074
|
+
maxNovelWords: {
|
|
5075
|
+
type: "integer",
|
|
5076
|
+
minimum: 0,
|
|
5077
|
+
description: "Most content words a comment may add beyond its member's own source and still count as a restatement."
|
|
5078
|
+
}
|
|
5079
|
+
}
|
|
5080
|
+
};
|
|
5050
5081
|
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;
|
|
5051
5082
|
var DEFAULT_RE = /^\s*@?default\b|\bdefaults? (?:to|:)/i;
|
|
5052
5083
|
var DIGIT_RE = /\d/;
|
|
5053
5084
|
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;
|
|
5054
5085
|
var EXAMPLE_RE = /["'`]|\be\.g\.|\bi\.e\./;
|
|
5086
|
+
var TAG_TOKEN_RE = /@\w+/g;
|
|
5055
5087
|
var BANNER_RE = /[=\-─-╿*#~_.]{3,}/;
|
|
5056
5088
|
var NON_ASCII_LETTER_RE2 = /[^\p{ASCII}\p{N}\p{P}\p{Z}]/u;
|
|
5057
|
-
var
|
|
5089
|
+
var WALL_STOPWORDS = new Set(
|
|
5058
5090
|
`the a an of to for in on with and or as at by is are was be been being
|
|
5059
5091
|
this that it its if whether when where which what will would can could should
|
|
5060
5092
|
must may into from over about not no does do done has have had used use uses
|
|
@@ -5069,15 +5101,22 @@ var BARE_LABEL_RE = /^[A-Za-z][A-Za-z0-9]*$/;
|
|
|
5069
5101
|
function labelStems(body) {
|
|
5070
5102
|
return splitIdentifier(body).map(stem).join(" ");
|
|
5071
5103
|
}
|
|
5072
|
-
function isNamedMember(node) {
|
|
5073
|
-
return (node.type === import_utils34.AST_NODE_TYPES.TSPropertySignature || node.type === import_utils34.AST_NODE_TYPES.TSMethodSignature) && !node.computed;
|
|
5074
|
-
}
|
|
5075
5104
|
function commentBody(comment) {
|
|
5076
5105
|
return comment.value.replace(/^\*+/, "").replace(/^[ \t]*\*[ \t]?/gm, "").trim();
|
|
5077
5106
|
}
|
|
5078
5107
|
function carriesValue(body) {
|
|
5079
5108
|
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);
|
|
5080
5109
|
}
|
|
5110
|
+
function isLabel(body) {
|
|
5111
|
+
let content = 0;
|
|
5112
|
+
for (const word of body.match(WORD_RE4) ?? []) {
|
|
5113
|
+
if (word.length >= 2 && !WALL_STOPWORDS.has(word.toLowerCase())) content += 1;
|
|
5114
|
+
}
|
|
5115
|
+
return content <= 1;
|
|
5116
|
+
}
|
|
5117
|
+
function isTagsOnly(body) {
|
|
5118
|
+
return body.length > 0 && body.replace(TAG_TOKEN_RE, "").trim().length === 0;
|
|
5119
|
+
}
|
|
5081
5120
|
function knownTokens(source) {
|
|
5082
5121
|
const tokens = /* @__PURE__ */ new Set();
|
|
5083
5122
|
for (const identifier of source.match(/[A-Za-z_$][\w$]*/g) ?? []) {
|
|
@@ -5092,11 +5131,146 @@ function novelWords(body, known) {
|
|
|
5092
5131
|
let novel = 0;
|
|
5093
5132
|
for (const word of body.match(WORD_RE4) ?? []) {
|
|
5094
5133
|
const lower = word.toLowerCase();
|
|
5095
|
-
if (lower.length < 2 ||
|
|
5134
|
+
if (lower.length < 2 || WALL_STOPWORDS.has(lower)) continue;
|
|
5096
5135
|
if (!known.has(lower) && !known.has(stem(lower))) novel += 1;
|
|
5097
5136
|
}
|
|
5098
5137
|
return novel;
|
|
5099
5138
|
}
|
|
5139
|
+
function isWall(members, commented, restated, options) {
|
|
5140
|
+
return commented >= options.minCommentedMembers && commented / members >= options.minCommentedRatio && restated / commented >= options.minRestatedRatio;
|
|
5141
|
+
}
|
|
5142
|
+
var OPAQUE_VALUE_TYPES = /* @__PURE__ */ new Set([
|
|
5143
|
+
import_utils34.AST_NODE_TYPES.FunctionExpression,
|
|
5144
|
+
import_utils34.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
5145
|
+
import_utils34.AST_NODE_TYPES.ObjectExpression,
|
|
5146
|
+
import_utils34.AST_NODE_TYPES.ArrayExpression
|
|
5147
|
+
]);
|
|
5148
|
+
function declarationRange(member) {
|
|
5149
|
+
const body = bodyOf(member);
|
|
5150
|
+
if (body === void 0) return [member.range[0], member.range[1]];
|
|
5151
|
+
return [member.range[0], body.range[0]];
|
|
5152
|
+
}
|
|
5153
|
+
function bodyOf(member) {
|
|
5154
|
+
if (member.type === import_utils34.AST_NODE_TYPES.MethodDefinition || member.type === import_utils34.AST_NODE_TYPES.TSAbstractMethodDefinition) {
|
|
5155
|
+
return member.value.body ?? void 0;
|
|
5156
|
+
}
|
|
5157
|
+
if (member.type === import_utils34.AST_NODE_TYPES.Property || member.type === import_utils34.AST_NODE_TYPES.PropertyDefinition) {
|
|
5158
|
+
const value = member.value;
|
|
5159
|
+
if (value !== null && OPAQUE_VALUE_TYPES.has(value.type)) return value;
|
|
5160
|
+
}
|
|
5161
|
+
return void 0;
|
|
5162
|
+
}
|
|
5163
|
+
|
|
5164
|
+
// src/rules/no-declaration-comment-wall.ts
|
|
5165
|
+
function named(node) {
|
|
5166
|
+
switch (node.type) {
|
|
5167
|
+
case import_utils35.AST_NODE_TYPES.TSEnumMember:
|
|
5168
|
+
return { node, key: node.id };
|
|
5169
|
+
case import_utils35.AST_NODE_TYPES.PropertyDefinition:
|
|
5170
|
+
case import_utils35.AST_NODE_TYPES.TSAbstractPropertyDefinition:
|
|
5171
|
+
case import_utils35.AST_NODE_TYPES.MethodDefinition:
|
|
5172
|
+
case import_utils35.AST_NODE_TYPES.TSAbstractMethodDefinition:
|
|
5173
|
+
return node.computed ? void 0 : { node, key: node.key };
|
|
5174
|
+
default:
|
|
5175
|
+
return void 0;
|
|
5176
|
+
}
|
|
5177
|
+
}
|
|
5178
|
+
var no_declaration_comment_wall_default = createRule({
|
|
5179
|
+
name: "no-declaration-comment-wall",
|
|
5180
|
+
meta: {
|
|
5181
|
+
type: "suggestion",
|
|
5182
|
+
docs: {
|
|
5183
|
+
description: "Flag an enum body or class body whose member comments mostly re-spell the members' own names."
|
|
5184
|
+
},
|
|
5185
|
+
schema: [WALL_SCHEMA],
|
|
5186
|
+
messages: {
|
|
5187
|
+
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."
|
|
5188
|
+
}
|
|
5189
|
+
},
|
|
5190
|
+
defaultOptions: [WALL_DEFAULTS],
|
|
5191
|
+
create(context, [provided]) {
|
|
5192
|
+
const options = { ...WALL_DEFAULTS, ...provided };
|
|
5193
|
+
const sourceCode = context.sourceCode;
|
|
5194
|
+
if (isGeneratedFile(context.filename, sourceCode.text) || isTestFile(context.filename) || isStoryFile(context.filename)) {
|
|
5195
|
+
return {};
|
|
5196
|
+
}
|
|
5197
|
+
const endingOn = /* @__PURE__ */ new Map();
|
|
5198
|
+
const startingOn = /* @__PURE__ */ new Map();
|
|
5199
|
+
for (const comment of sourceCode.getAllComments()) {
|
|
5200
|
+
endingOn.set(comment.loc.end.line, comment);
|
|
5201
|
+
if (!startingOn.has(comment.loc.start.line)) startingOn.set(comment.loc.start.line, comment);
|
|
5202
|
+
}
|
|
5203
|
+
function documentingComment(member) {
|
|
5204
|
+
const beforeMember = sourceCode.getTokenBefore(member, { includeComments: false });
|
|
5205
|
+
const ownsItsLine = beforeMember === null || beforeMember.loc.end.line < member.loc.start.line;
|
|
5206
|
+
const lead = ownsItsLine ? endingOn.get(member.loc.start.line - 1) : void 0;
|
|
5207
|
+
if (lead !== void 0) {
|
|
5208
|
+
const before = sourceCode.getTokenBefore(lead, { includeComments: false });
|
|
5209
|
+
if (before === null || before.loc.end.line < lead.loc.start.line) return lead;
|
|
5210
|
+
}
|
|
5211
|
+
const trail = startingOn.get(member.loc.end.line);
|
|
5212
|
+
return trail !== void 0 && trail.range[0] > member.range[0] ? trail : void 0;
|
|
5213
|
+
}
|
|
5214
|
+
function isGroupLabel(comment, member, headsRun) {
|
|
5215
|
+
if (comment.loc.end.line >= member.node.loc.start.line) return false;
|
|
5216
|
+
const body = commentBody(comment);
|
|
5217
|
+
if (!BARE_LABEL_RE.test(body)) return false;
|
|
5218
|
+
if (labelStems(body) === labelStems(sourceCode.getText(member.key))) return false;
|
|
5219
|
+
const lineAbove = sourceCode.lines[comment.loc.start.line - 2];
|
|
5220
|
+
return headsRun || lineAbove !== void 0 && lineAbove.trim().length === 0;
|
|
5221
|
+
}
|
|
5222
|
+
function check(node, members) {
|
|
5223
|
+
const judged = members.map(named).filter((member) => member !== void 0);
|
|
5224
|
+
if (judged.length === 0) return;
|
|
5225
|
+
const documented = judged.map((member) => ({
|
|
5226
|
+
member,
|
|
5227
|
+
comment: documentingComment(member.node)
|
|
5228
|
+
}));
|
|
5229
|
+
let commented = 0;
|
|
5230
|
+
let restated = 0;
|
|
5231
|
+
for (const [index, { member, comment }] of documented.entries()) {
|
|
5232
|
+
if (comment === void 0) continue;
|
|
5233
|
+
const next = documented[index + 1];
|
|
5234
|
+
if (isGroupLabel(comment, member, next !== void 0 && next.comment === void 0)) {
|
|
5235
|
+
continue;
|
|
5236
|
+
}
|
|
5237
|
+
commented += 1;
|
|
5238
|
+
const body = commentBody(comment);
|
|
5239
|
+
if (body.length === 0 || carriesValue(body) || isTagsOnly(body) || isLabel(body)) {
|
|
5240
|
+
continue;
|
|
5241
|
+
}
|
|
5242
|
+
const [start, end] = declarationRange(member.node);
|
|
5243
|
+
if (novelWords(body, knownTokens(sourceCode.text.slice(start, end))) <= options.maxNovelWords) {
|
|
5244
|
+
restated += 1;
|
|
5245
|
+
}
|
|
5246
|
+
}
|
|
5247
|
+
if (!isWall(judged.length, commented, restated, options)) return;
|
|
5248
|
+
context.report({
|
|
5249
|
+
node,
|
|
5250
|
+
loc: {
|
|
5251
|
+
start: node.loc.start,
|
|
5252
|
+
end: { line: node.loc.start.line, column: node.loc.start.column + 1 }
|
|
5253
|
+
},
|
|
5254
|
+
messageId: "commentWall",
|
|
5255
|
+
data: { restated: String(restated), commented: String(commented) }
|
|
5256
|
+
});
|
|
5257
|
+
}
|
|
5258
|
+
return {
|
|
5259
|
+
ClassBody: (node) => {
|
|
5260
|
+
check(node, node.body);
|
|
5261
|
+
},
|
|
5262
|
+
TSEnumDeclaration: (node) => {
|
|
5263
|
+
check(node, node.body.members);
|
|
5264
|
+
}
|
|
5265
|
+
};
|
|
5266
|
+
}
|
|
5267
|
+
});
|
|
5268
|
+
|
|
5269
|
+
// src/rules/no-type-member-comment-wall.ts
|
|
5270
|
+
var import_utils36 = require("@typescript-eslint/utils");
|
|
5271
|
+
function isNamedMember(node) {
|
|
5272
|
+
return (node.type === import_utils36.AST_NODE_TYPES.TSPropertySignature || node.type === import_utils36.AST_NODE_TYPES.TSMethodSignature) && !node.computed;
|
|
5273
|
+
}
|
|
5100
5274
|
var no_type_member_comment_wall_default = createRule({
|
|
5101
5275
|
name: "no-type-member-comment-wall",
|
|
5102
5276
|
meta: {
|
|
@@ -5104,43 +5278,14 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5104
5278
|
docs: {
|
|
5105
5279
|
description: "Flag an object type whose member comments mostly re-spell the members' own names and types."
|
|
5106
5280
|
},
|
|
5107
|
-
schema: [
|
|
5108
|
-
{
|
|
5109
|
-
type: "object",
|
|
5110
|
-
additionalProperties: false,
|
|
5111
|
-
properties: {
|
|
5112
|
-
minCommentedMembers: {
|
|
5113
|
-
type: "integer",
|
|
5114
|
-
minimum: 2,
|
|
5115
|
-
description: "Fewest commented members that can count as a wall."
|
|
5116
|
-
},
|
|
5117
|
-
minCommentedRatio: {
|
|
5118
|
-
type: "number",
|
|
5119
|
-
minimum: 0,
|
|
5120
|
-
maximum: 1,
|
|
5121
|
-
description: "Least share of the type's members that must be commented; below it the comments are group labels."
|
|
5122
|
-
},
|
|
5123
|
-
minRestatedRatio: {
|
|
5124
|
-
type: "number",
|
|
5125
|
-
minimum: 0,
|
|
5126
|
-
maximum: 1,
|
|
5127
|
-
description: "Least share of the member comments that must be restatements."
|
|
5128
|
-
},
|
|
5129
|
-
maxNovelWords: {
|
|
5130
|
-
type: "integer",
|
|
5131
|
-
minimum: 0,
|
|
5132
|
-
description: "Most content words a comment may add beyond its member's own source and still count as a restatement."
|
|
5133
|
-
}
|
|
5134
|
-
}
|
|
5135
|
-
}
|
|
5136
|
-
],
|
|
5281
|
+
schema: [WALL_SCHEMA],
|
|
5137
5282
|
messages: {
|
|
5138
5283
|
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."
|
|
5139
5284
|
}
|
|
5140
5285
|
},
|
|
5141
|
-
defaultOptions: [
|
|
5286
|
+
defaultOptions: [WALL_DEFAULTS],
|
|
5142
5287
|
create(context, [provided]) {
|
|
5143
|
-
const options = { ...
|
|
5288
|
+
const options = { ...WALL_DEFAULTS, ...provided };
|
|
5144
5289
|
const sourceCode = context.sourceCode;
|
|
5145
5290
|
if (isGeneratedFile(context.filename, sourceCode.text) || isTestFile(context.filename) || isStoryFile(context.filename)) {
|
|
5146
5291
|
return {};
|
|
@@ -5171,10 +5316,10 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5171
5316
|
return headsRun || lineAbove !== void 0 && lineAbove.trim().length === 0;
|
|
5172
5317
|
}
|
|
5173
5318
|
function check(node) {
|
|
5174
|
-
const members = node.type ===
|
|
5175
|
-
const
|
|
5176
|
-
if (
|
|
5177
|
-
const documented =
|
|
5319
|
+
const members = node.type === import_utils36.AST_NODE_TYPES.TSInterfaceBody ? node.body : node.members;
|
|
5320
|
+
const named2 = members.filter(isNamedMember);
|
|
5321
|
+
if (named2.length === 0) return;
|
|
5322
|
+
const documented = named2.map((member) => ({ member, comment: documentingComment(member) }));
|
|
5178
5323
|
let commented = 0;
|
|
5179
5324
|
let restated = 0;
|
|
5180
5325
|
const claimed = /* @__PURE__ */ new Set();
|
|
@@ -5192,9 +5337,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5192
5337
|
restated += 1;
|
|
5193
5338
|
}
|
|
5194
5339
|
}
|
|
5195
|
-
if (
|
|
5196
|
-
return;
|
|
5197
|
-
}
|
|
5340
|
+
if (!isWall(named2.length, commented, restated, options)) return;
|
|
5198
5341
|
context.report({
|
|
5199
5342
|
node,
|
|
5200
5343
|
loc: {
|
|
@@ -5213,7 +5356,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5213
5356
|
});
|
|
5214
5357
|
|
|
5215
5358
|
// src/rules/no-unnecessary-use-client.ts
|
|
5216
|
-
var
|
|
5359
|
+
var import_utils37 = require("@typescript-eslint/utils");
|
|
5217
5360
|
var HOOK_REGEX = /^use([A-Z]|$)/;
|
|
5218
5361
|
var EVENT_PROP_REGEX = /^on[A-Z]/;
|
|
5219
5362
|
var ERROR_FILE_REGEX = /\b(?:global-)?error\.[jt]sx?$/;
|
|
@@ -5239,13 +5382,13 @@ var CLIENT_ONLY_PACKAGES_REGEX = /^(?:@radix-ui\/|framer-motion|react-dom|react-
|
|
|
5239
5382
|
var isBareSpecifier = (source) => !source.startsWith(".") && !source.startsWith("/") && !source.startsWith("@/") && !source.startsWith("~");
|
|
5240
5383
|
var jsxRootName = (name) => {
|
|
5241
5384
|
let current = name;
|
|
5242
|
-
while (current.type ===
|
|
5385
|
+
while (current.type === import_utils37.AST_NODE_TYPES.JSXMemberExpression) {
|
|
5243
5386
|
current = current.object;
|
|
5244
5387
|
}
|
|
5245
|
-
return current.type ===
|
|
5388
|
+
return current.type === import_utils37.AST_NODE_TYPES.JSXIdentifier ? current.name : "";
|
|
5246
5389
|
};
|
|
5247
5390
|
var subtreeReadsImportedBinding = (node, imported) => {
|
|
5248
|
-
if (node.type ===
|
|
5391
|
+
if (node.type === import_utils37.AST_NODE_TYPES.Identifier) {
|
|
5249
5392
|
return imported.has(node.name);
|
|
5250
5393
|
}
|
|
5251
5394
|
for (const key of Object.keys(node)) {
|
|
@@ -5260,16 +5403,16 @@ var subtreeReadsImportedBinding = (node, imported) => {
|
|
|
5260
5403
|
return false;
|
|
5261
5404
|
};
|
|
5262
5405
|
var isUseClientDirective = (node) => {
|
|
5263
|
-
return node.type ===
|
|
5406
|
+
return node.type === import_utils37.AST_NODE_TYPES.ExpressionStatement && node.expression.type === import_utils37.AST_NODE_TYPES.Literal && node.expression.value === "use client";
|
|
5264
5407
|
};
|
|
5265
5408
|
var isGlobalReference = (node, context) => {
|
|
5266
5409
|
if (!BROWSER_GLOBALS.has(node.name)) return false;
|
|
5267
5410
|
const parent = node.parent;
|
|
5268
5411
|
if (parent !== void 0) {
|
|
5269
|
-
if (parent.type ===
|
|
5412
|
+
if (parent.type === import_utils37.AST_NODE_TYPES.MemberExpression && parent.property === node && !parent.computed) {
|
|
5270
5413
|
return false;
|
|
5271
5414
|
}
|
|
5272
|
-
if (parent.type ===
|
|
5415
|
+
if (parent.type === import_utils37.AST_NODE_TYPES.Property && parent.key === node && !parent.computed) {
|
|
5273
5416
|
return false;
|
|
5274
5417
|
}
|
|
5275
5418
|
if (parent.type.startsWith("TS")) {
|
|
@@ -5309,13 +5452,13 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5309
5452
|
const importedLocals = /* @__PURE__ */ new Set();
|
|
5310
5453
|
const externalLocals = /* @__PURE__ */ new Set();
|
|
5311
5454
|
const markIfHookOrContext = (callee) => {
|
|
5312
|
-
if (callee.type ===
|
|
5455
|
+
if (callee.type === import_utils37.AST_NODE_TYPES.Identifier) {
|
|
5313
5456
|
if (HOOK_REGEX.test(callee.name) || callee.name === "createContext") {
|
|
5314
5457
|
hasClientIndicator = true;
|
|
5315
5458
|
}
|
|
5316
5459
|
return;
|
|
5317
5460
|
}
|
|
5318
|
-
if (callee.type ===
|
|
5461
|
+
if (callee.type === import_utils37.AST_NODE_TYPES.MemberExpression && callee.property.type === import_utils37.AST_NODE_TYPES.Identifier) {
|
|
5319
5462
|
const name = callee.property.name;
|
|
5320
5463
|
if (HOOK_REGEX.test(name) || name === "createContext") {
|
|
5321
5464
|
hasClientIndicator = true;
|
|
@@ -5325,7 +5468,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5325
5468
|
return {
|
|
5326
5469
|
Program(node) {
|
|
5327
5470
|
for (const stmt of node.body) {
|
|
5328
|
-
if (stmt.type !==
|
|
5471
|
+
if (stmt.type !== import_utils37.AST_NODE_TYPES.ExpressionStatement) break;
|
|
5329
5472
|
if (isUseClientDirective(stmt)) {
|
|
5330
5473
|
directiveNode = stmt;
|
|
5331
5474
|
break;
|
|
@@ -5338,7 +5481,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5338
5481
|
},
|
|
5339
5482
|
JSXAttribute(node) {
|
|
5340
5483
|
if (directiveNode === null) return;
|
|
5341
|
-
if (node.name.type ===
|
|
5484
|
+
if (node.name.type === import_utils37.AST_NODE_TYPES.JSXIdentifier && EVENT_PROP_REGEX.test(node.name.name)) {
|
|
5342
5485
|
hasClientIndicator = true;
|
|
5343
5486
|
}
|
|
5344
5487
|
},
|
|
@@ -5405,18 +5548,18 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5405
5548
|
});
|
|
5406
5549
|
|
|
5407
5550
|
// src/rules/no-unsafe-mock-casting.ts
|
|
5408
|
-
var
|
|
5409
|
-
var
|
|
5551
|
+
var import_utils38 = require("@typescript-eslint/utils");
|
|
5552
|
+
var import_utils39 = require("@typescript-eslint/utils");
|
|
5410
5553
|
function isMockTypeReference(node) {
|
|
5411
|
-
if (node.type !==
|
|
5554
|
+
if (node.type !== import_utils39.AST_NODE_TYPES.TSTypeReference) {
|
|
5412
5555
|
return false;
|
|
5413
5556
|
}
|
|
5414
5557
|
const typeName = node.typeName;
|
|
5415
|
-
if (typeName.type ===
|
|
5558
|
+
if (typeName.type === import_utils39.AST_NODE_TYPES.Identifier) {
|
|
5416
5559
|
const name = typeName.name;
|
|
5417
5560
|
return name === "Mock" || name === "MockInstance" || name === "SpyInstance";
|
|
5418
5561
|
}
|
|
5419
|
-
if (typeName.type ===
|
|
5562
|
+
if (typeName.type === import_utils39.AST_NODE_TYPES.TSQualifiedName) {
|
|
5420
5563
|
const rightName = typeName.right.name;
|
|
5421
5564
|
return rightName === "Mock" || rightName === "MockInstance" || rightName === "SpyInstance";
|
|
5422
5565
|
}
|
|
@@ -5452,7 +5595,7 @@ var no_unsafe_mock_casting_default = createRule({
|
|
|
5452
5595
|
});
|
|
5453
5596
|
|
|
5454
5597
|
// src/rules/no-zod-native-enum.ts
|
|
5455
|
-
var
|
|
5598
|
+
var import_utils40 = require("@typescript-eslint/utils");
|
|
5456
5599
|
var ts = __toESM(require("typescript"), 1);
|
|
5457
5600
|
var IGNORE_PATTERNS = [
|
|
5458
5601
|
/[\\/]generated[\\/]/,
|
|
@@ -5470,7 +5613,7 @@ function isZodModule(source) {
|
|
|
5470
5613
|
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
5471
5614
|
}
|
|
5472
5615
|
function unwrap2(node) {
|
|
5473
|
-
if (node.type ===
|
|
5616
|
+
if (node.type === import_utils40.AST_NODE_TYPES.TSAsExpression || node.type === import_utils40.AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
5474
5617
|
return unwrap2(node.expression);
|
|
5475
5618
|
}
|
|
5476
5619
|
return node;
|
|
@@ -5478,14 +5621,14 @@ function unwrap2(node) {
|
|
|
5478
5621
|
function stringValueTexts(node, sourceCode) {
|
|
5479
5622
|
const texts = [];
|
|
5480
5623
|
for (const prop of node.properties) {
|
|
5481
|
-
if (prop.type !==
|
|
5624
|
+
if (prop.type !== import_utils40.AST_NODE_TYPES.Property) {
|
|
5482
5625
|
return null;
|
|
5483
5626
|
}
|
|
5484
5627
|
if (prop.computed || prop.shorthand || prop.method || prop.kind !== "init") {
|
|
5485
5628
|
return null;
|
|
5486
5629
|
}
|
|
5487
5630
|
const value = prop.value;
|
|
5488
|
-
if (value.type !==
|
|
5631
|
+
if (value.type !== import_utils40.AST_NODE_TYPES.Literal || typeof value.value !== "string") {
|
|
5489
5632
|
return null;
|
|
5490
5633
|
}
|
|
5491
5634
|
const text = sourceCode.getText(value);
|
|
@@ -5501,7 +5644,7 @@ function resolvesToLocalEnum(node, scope) {
|
|
|
5501
5644
|
const variable = current.variables.find((v) => v.name === node.name);
|
|
5502
5645
|
if (variable !== void 0) {
|
|
5503
5646
|
return variable.defs.some(
|
|
5504
|
-
(def) => def.node.type ===
|
|
5647
|
+
(def) => def.node.type === import_utils40.AST_NODE_TYPES.TSEnumDeclaration
|
|
5505
5648
|
);
|
|
5506
5649
|
}
|
|
5507
5650
|
current = current.upper;
|
|
@@ -5546,32 +5689,32 @@ var no_zod_native_enum_default = createRule({
|
|
|
5546
5689
|
}
|
|
5547
5690
|
let services;
|
|
5548
5691
|
try {
|
|
5549
|
-
services =
|
|
5692
|
+
services = import_utils40.ESLintUtils.getParserServices(context);
|
|
5550
5693
|
} catch {
|
|
5551
5694
|
services = null;
|
|
5552
5695
|
}
|
|
5553
5696
|
const zodImportedNames = /* @__PURE__ */ new Map();
|
|
5554
5697
|
function isZodMemberCall(node, api) {
|
|
5555
5698
|
const callee = node.callee;
|
|
5556
|
-
if (callee.type ===
|
|
5699
|
+
if (callee.type === import_utils40.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils40.AST_NODE_TYPES.Identifier) {
|
|
5557
5700
|
return callee.property.name === api;
|
|
5558
5701
|
}
|
|
5559
|
-
if (callee.type ===
|
|
5702
|
+
if (callee.type === import_utils40.AST_NODE_TYPES.Identifier) {
|
|
5560
5703
|
return zodImportedNames.get(callee.name) === api;
|
|
5561
5704
|
}
|
|
5562
5705
|
return false;
|
|
5563
5706
|
}
|
|
5564
5707
|
function buildFix(node) {
|
|
5565
5708
|
const callee = node.callee;
|
|
5566
|
-
if (callee.type !==
|
|
5709
|
+
if (callee.type !== import_utils40.AST_NODE_TYPES.MemberExpression || callee.property.type !== import_utils40.AST_NODE_TYPES.Identifier) {
|
|
5567
5710
|
return null;
|
|
5568
5711
|
}
|
|
5569
5712
|
const arg = node.arguments[0];
|
|
5570
|
-
if (arg === void 0 || node.arguments.length !== 1 || arg.type ===
|
|
5713
|
+
if (arg === void 0 || node.arguments.length !== 1 || arg.type === import_utils40.AST_NODE_TYPES.SpreadElement) {
|
|
5571
5714
|
return null;
|
|
5572
5715
|
}
|
|
5573
5716
|
const inner = unwrap2(arg);
|
|
5574
|
-
if (inner.type !==
|
|
5717
|
+
if (inner.type !== import_utils40.AST_NODE_TYPES.ObjectExpression) {
|
|
5575
5718
|
return null;
|
|
5576
5719
|
}
|
|
5577
5720
|
const values = stringValueTexts(inner, sourceCode);
|
|
@@ -5591,7 +5734,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
5591
5734
|
return;
|
|
5592
5735
|
}
|
|
5593
5736
|
for (const spec of node.specifiers) {
|
|
5594
|
-
if (spec.type ===
|
|
5737
|
+
if (spec.type === import_utils40.AST_NODE_TYPES.ImportSpecifier && spec.imported.type === import_utils40.AST_NODE_TYPES.Identifier) {
|
|
5595
5738
|
zodImportedNames.set(spec.local.name, spec.imported.name);
|
|
5596
5739
|
}
|
|
5597
5740
|
}
|
|
@@ -5610,7 +5753,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
5610
5753
|
return;
|
|
5611
5754
|
}
|
|
5612
5755
|
const arg = node.arguments[0];
|
|
5613
|
-
if (arg === void 0 || arg.type !==
|
|
5756
|
+
if (arg === void 0 || arg.type !== import_utils40.AST_NODE_TYPES.Identifier) {
|
|
5614
5757
|
return;
|
|
5615
5758
|
}
|
|
5616
5759
|
const isEnum = resolvesToLocalEnum(arg, sourceCode.getScope(arg)) || services !== null && resolvesToImportedEnum(arg, services);
|
|
@@ -5627,7 +5770,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
5627
5770
|
});
|
|
5628
5771
|
|
|
5629
5772
|
// src/rules/prefer-constant-time-secret-compare.ts
|
|
5630
|
-
var
|
|
5773
|
+
var import_utils41 = require("@typescript-eslint/utils");
|
|
5631
5774
|
var EQUALITY_OPERATORS = /* @__PURE__ */ new Set(["===", "!==", "==", "!="]);
|
|
5632
5775
|
var SENTINEL_IDENTIFIERS = /* @__PURE__ */ new Set(["undefined", "NaN"]);
|
|
5633
5776
|
var SENTINEL_WORDS = /(^|_)(SENTINEL|EMPTY|NONE|NULL|UNSET|MISSING|PLACEHOLDER|DUMMY|FAKE|EXAMPLE)(_|$)/;
|
|
@@ -5640,36 +5783,36 @@ function isConstantReference(identifier) {
|
|
|
5640
5783
|
}
|
|
5641
5784
|
function isExcludedOperand(node) {
|
|
5642
5785
|
switch (node.type) {
|
|
5643
|
-
case
|
|
5786
|
+
case import_utils41.AST_NODE_TYPES.Literal:
|
|
5644
5787
|
return true;
|
|
5645
|
-
case
|
|
5788
|
+
case import_utils41.AST_NODE_TYPES.TemplateLiteral:
|
|
5646
5789
|
return node.expressions.length === 0;
|
|
5647
|
-
case
|
|
5790
|
+
case import_utils41.AST_NODE_TYPES.Identifier:
|
|
5648
5791
|
return SENTINEL_IDENTIFIERS.has(node.name) || SENTINEL_PREFIX_RE.test(node.name) || isConstantReference(node.name);
|
|
5649
|
-
case
|
|
5650
|
-
return !node.computed && node.property.type ===
|
|
5792
|
+
case import_utils41.AST_NODE_TYPES.MemberExpression:
|
|
5793
|
+
return !node.computed && node.property.type === import_utils41.AST_NODE_TYPES.Identifier && (SENTINEL_PREFIX_RE.test(node.property.name) || isConstantReference(node.property.name));
|
|
5651
5794
|
default:
|
|
5652
5795
|
return false;
|
|
5653
5796
|
}
|
|
5654
5797
|
}
|
|
5655
5798
|
function operandName(node) {
|
|
5656
|
-
if (node.type ===
|
|
5799
|
+
if (node.type === import_utils41.AST_NODE_TYPES.Identifier) {
|
|
5657
5800
|
return node.name;
|
|
5658
5801
|
}
|
|
5659
|
-
if (node.type ===
|
|
5802
|
+
if (node.type === import_utils41.AST_NODE_TYPES.MemberExpression && !node.computed && node.property.type === import_utils41.AST_NODE_TYPES.Identifier) {
|
|
5660
5803
|
return node.property.name;
|
|
5661
5804
|
}
|
|
5662
5805
|
return null;
|
|
5663
5806
|
}
|
|
5664
5807
|
function isSecretOperand(node) {
|
|
5665
|
-
if (node.type ===
|
|
5808
|
+
if (node.type === import_utils41.AST_NODE_TYPES.TemplateLiteral) {
|
|
5666
5809
|
return node.expressions.some((expression) => isSecretOperand(expression));
|
|
5667
5810
|
}
|
|
5668
5811
|
const name = operandName(node);
|
|
5669
5812
|
return name !== null && isAuthSecretName(name);
|
|
5670
5813
|
}
|
|
5671
5814
|
function secretNameOf(node) {
|
|
5672
|
-
if (node.type ===
|
|
5815
|
+
if (node.type === import_utils41.AST_NODE_TYPES.TemplateLiteral) {
|
|
5673
5816
|
for (const expression of node.expressions) {
|
|
5674
5817
|
const nested = secretNameOf(expression);
|
|
5675
5818
|
if (nested !== null) {
|
|
@@ -5721,8 +5864,8 @@ var prefer_constant_time_secret_compare_default = createRule({
|
|
|
5721
5864
|
});
|
|
5722
5865
|
|
|
5723
5866
|
// src/rules/prefer-discriminated-union.ts
|
|
5724
|
-
var
|
|
5725
|
-
var
|
|
5867
|
+
var import_utils42 = require("@typescript-eslint/utils");
|
|
5868
|
+
var import_utils43 = require("@typescript-eslint/utils");
|
|
5726
5869
|
var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
5727
5870
|
"success",
|
|
5728
5871
|
"ok",
|
|
@@ -5732,27 +5875,27 @@ var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
|
5732
5875
|
]);
|
|
5733
5876
|
var MIN_OPTIONAL_MEMBERS = 2;
|
|
5734
5877
|
function getMemberName(member) {
|
|
5735
|
-
if (member.type !==
|
|
5878
|
+
if (member.type !== import_utils43.AST_NODE_TYPES.TSPropertySignature) {
|
|
5736
5879
|
return null;
|
|
5737
5880
|
}
|
|
5738
5881
|
const { key } = member;
|
|
5739
|
-
if (key.type ===
|
|
5882
|
+
if (key.type === import_utils43.AST_NODE_TYPES.Identifier) {
|
|
5740
5883
|
return key.name;
|
|
5741
5884
|
}
|
|
5742
|
-
if (key.type ===
|
|
5885
|
+
if (key.type === import_utils43.AST_NODE_TYPES.Literal && typeof key.value === "string") {
|
|
5743
5886
|
return key.value;
|
|
5744
5887
|
}
|
|
5745
5888
|
return null;
|
|
5746
5889
|
}
|
|
5747
5890
|
function isBooleanTyped(member) {
|
|
5748
|
-
return member.typeAnnotation?.typeAnnotation.type ===
|
|
5891
|
+
return member.typeAnnotation?.typeAnnotation.type === import_utils43.AST_NODE_TYPES.TSBooleanKeyword;
|
|
5749
5892
|
}
|
|
5750
5893
|
function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
5751
5894
|
let hasStatusBoolean = false;
|
|
5752
5895
|
let optionalCount = 0;
|
|
5753
5896
|
let optionalPayloadCount = 0;
|
|
5754
5897
|
for (const member of typeLiteral.members) {
|
|
5755
|
-
if (member.type !==
|
|
5898
|
+
if (member.type !== import_utils43.AST_NODE_TYPES.TSPropertySignature) {
|
|
5756
5899
|
continue;
|
|
5757
5900
|
}
|
|
5758
5901
|
if (member.optional) {
|
|
@@ -5794,7 +5937,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
5794
5937
|
TSInterfaceDeclaration(node) {
|
|
5795
5938
|
const synthetic = {
|
|
5796
5939
|
...node.body,
|
|
5797
|
-
type:
|
|
5940
|
+
type: import_utils43.AST_NODE_TYPES.TSTypeLiteral,
|
|
5798
5941
|
members: node.body.body
|
|
5799
5942
|
};
|
|
5800
5943
|
checkTypeLiteral(synthetic, node);
|
|
@@ -5807,7 +5950,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
5807
5950
|
});
|
|
5808
5951
|
|
|
5809
5952
|
// src/rules/prefer-module-level-constant.ts
|
|
5810
|
-
var
|
|
5953
|
+
var import_utils44 = require("@typescript-eslint/utils");
|
|
5811
5954
|
var DEFAULT_MIN_ELEMENTS = 3;
|
|
5812
5955
|
var MAX_LITERAL_DEPTH = 4;
|
|
5813
5956
|
var IGNORE_PATTERNS2 = [
|
|
@@ -5836,9 +5979,9 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
|
5836
5979
|
"assign"
|
|
5837
5980
|
]);
|
|
5838
5981
|
var FUNCTION_TYPES5 = /* @__PURE__ */ new Set([
|
|
5839
|
-
|
|
5840
|
-
|
|
5841
|
-
|
|
5982
|
+
import_utils44.AST_NODE_TYPES.FunctionDeclaration,
|
|
5983
|
+
import_utils44.AST_NODE_TYPES.FunctionExpression,
|
|
5984
|
+
import_utils44.AST_NODE_TYPES.ArrowFunctionExpression
|
|
5842
5985
|
]);
|
|
5843
5986
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
5844
5987
|
function isIgnoredFile2(filename, sourceText) {
|
|
@@ -5851,14 +5994,14 @@ function isLocalFixtureFile(filename) {
|
|
|
5851
5994
|
return isTestFile(filename) || isStoryFile(filename);
|
|
5852
5995
|
}
|
|
5853
5996
|
function unwrap3(node) {
|
|
5854
|
-
if (node.type ===
|
|
5997
|
+
if (node.type === import_utils44.AST_NODE_TYPES.TSAsExpression || node.type === import_utils44.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils44.AST_NODE_TYPES.TSNonNullExpression) {
|
|
5855
5998
|
return unwrap3(node.expression);
|
|
5856
5999
|
}
|
|
5857
6000
|
return node;
|
|
5858
6001
|
}
|
|
5859
6002
|
var HAS_STATEFUL_FLAG_RE = /[gy]/;
|
|
5860
6003
|
function isRegexLiteral(node) {
|
|
5861
|
-
return node.type ===
|
|
6004
|
+
return node.type === import_utils44.AST_NODE_TYPES.Literal && "regex" in node && node.regex !== void 0;
|
|
5862
6005
|
}
|
|
5863
6006
|
function isLiteralOnly(node, depth) {
|
|
5864
6007
|
if (depth > MAX_LITERAL_DEPTH) {
|
|
@@ -5866,29 +6009,29 @@ function isLiteralOnly(node, depth) {
|
|
|
5866
6009
|
}
|
|
5867
6010
|
const inner = unwrap3(node);
|
|
5868
6011
|
switch (inner.type) {
|
|
5869
|
-
case
|
|
6012
|
+
case import_utils44.AST_NODE_TYPES.Literal: {
|
|
5870
6013
|
return !(isRegexLiteral(inner) && HAS_STATEFUL_FLAG_RE.test(inner.regex.flags));
|
|
5871
6014
|
}
|
|
5872
|
-
case
|
|
6015
|
+
case import_utils44.AST_NODE_TYPES.TemplateLiteral: {
|
|
5873
6016
|
return inner.expressions.length === 0;
|
|
5874
6017
|
}
|
|
5875
|
-
case
|
|
5876
|
-
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type ===
|
|
6018
|
+
case import_utils44.AST_NODE_TYPES.UnaryExpression: {
|
|
6019
|
+
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type === import_utils44.AST_NODE_TYPES.Literal && typeof inner.argument.value === "number";
|
|
5877
6020
|
}
|
|
5878
|
-
case
|
|
6021
|
+
case import_utils44.AST_NODE_TYPES.ArrayExpression: {
|
|
5879
6022
|
return inner.elements.every(
|
|
5880
|
-
(el) => el !== null && el.type !==
|
|
6023
|
+
(el) => el !== null && el.type !== import_utils44.AST_NODE_TYPES.SpreadElement && isLiteralOnly(el, depth + 1)
|
|
5881
6024
|
);
|
|
5882
6025
|
}
|
|
5883
|
-
case
|
|
6026
|
+
case import_utils44.AST_NODE_TYPES.ObjectExpression: {
|
|
5884
6027
|
return inner.properties.every((prop) => {
|
|
5885
|
-
if (prop.type !==
|
|
6028
|
+
if (prop.type !== import_utils44.AST_NODE_TYPES.Property) {
|
|
5886
6029
|
return false;
|
|
5887
6030
|
}
|
|
5888
6031
|
if (prop.shorthand || prop.method || prop.kind !== "init") {
|
|
5889
6032
|
return false;
|
|
5890
6033
|
}
|
|
5891
|
-
if (prop.computed && prop.key.type !==
|
|
6034
|
+
if (prop.computed && prop.key.type !== import_utils44.AST_NODE_TYPES.Literal) {
|
|
5892
6035
|
return false;
|
|
5893
6036
|
}
|
|
5894
6037
|
return isLiteralOnly(prop.value, depth + 1);
|
|
@@ -5901,7 +6044,7 @@ function isLiteralOnly(node, depth) {
|
|
|
5901
6044
|
}
|
|
5902
6045
|
function unwrapObjectFreeze(node) {
|
|
5903
6046
|
const inner = unwrap3(node);
|
|
5904
|
-
if (inner.type ===
|
|
6047
|
+
if (inner.type === import_utils44.AST_NODE_TYPES.CallExpression && inner.callee.type === import_utils44.AST_NODE_TYPES.MemberExpression && !inner.callee.computed && inner.callee.object.type === import_utils44.AST_NODE_TYPES.Identifier && inner.callee.object.name === "Object" && inner.callee.property.type === import_utils44.AST_NODE_TYPES.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== import_utils44.AST_NODE_TYPES.SpreadElement) {
|
|
5905
6048
|
return unwrap3(inner.arguments[0]);
|
|
5906
6049
|
}
|
|
5907
6050
|
return inner;
|
|
@@ -5917,19 +6060,19 @@ function classify(init, checkRegex) {
|
|
|
5917
6060
|
}
|
|
5918
6061
|
return { kind: "regex", size: 1 };
|
|
5919
6062
|
}
|
|
5920
|
-
if (node.type ===
|
|
6063
|
+
if (node.type === import_utils44.AST_NODE_TYPES.ArrayExpression) {
|
|
5921
6064
|
return isLiteralOnly(node, 0) ? { kind: "array", size: node.elements.length } : null;
|
|
5922
6065
|
}
|
|
5923
|
-
if (node.type ===
|
|
6066
|
+
if (node.type === import_utils44.AST_NODE_TYPES.ObjectExpression) {
|
|
5924
6067
|
return isLiteralOnly(node, 0) ? { kind: "object", size: node.properties.length } : null;
|
|
5925
6068
|
}
|
|
5926
|
-
if (node.type ===
|
|
6069
|
+
if (node.type === import_utils44.AST_NODE_TYPES.NewExpression && node.callee.type === import_utils44.AST_NODE_TYPES.Identifier && COLLECTION_CONSTRUCTORS.has(node.callee.name)) {
|
|
5927
6070
|
const arg = node.arguments[0];
|
|
5928
|
-
if (node.arguments.length !== 1 || arg === void 0 || arg.type ===
|
|
6071
|
+
if (node.arguments.length !== 1 || arg === void 0 || arg.type === import_utils44.AST_NODE_TYPES.SpreadElement) {
|
|
5929
6072
|
return null;
|
|
5930
6073
|
}
|
|
5931
6074
|
const entries = unwrap3(arg);
|
|
5932
|
-
if (entries.type !==
|
|
6075
|
+
if (entries.type !== import_utils44.AST_NODE_TYPES.ArrayExpression) {
|
|
5933
6076
|
return null;
|
|
5934
6077
|
}
|
|
5935
6078
|
return isLiteralOnly(entries, 0) ? { kind: node.callee.name === "Set" ? "Set" : "Map", size: entries.elements.length } : null;
|
|
@@ -5958,10 +6101,10 @@ var NON_RETAINING_BUILTINS = /* @__PURE__ */ new Map(
|
|
|
5958
6101
|
);
|
|
5959
6102
|
function isNonRetainingBuiltinCall(node, argument) {
|
|
5960
6103
|
const callee = node.callee;
|
|
5961
|
-
if (callee.type ===
|
|
6104
|
+
if (callee.type === import_utils44.AST_NODE_TYPES.Identifier && callee.name === "structuredClone") {
|
|
5962
6105
|
return true;
|
|
5963
6106
|
}
|
|
5964
|
-
if (callee.type !==
|
|
6107
|
+
if (callee.type !== import_utils44.AST_NODE_TYPES.MemberExpression || callee.computed || callee.object.type !== import_utils44.AST_NODE_TYPES.Identifier || callee.property.type !== import_utils44.AST_NODE_TYPES.Identifier) {
|
|
5965
6108
|
return false;
|
|
5966
6109
|
}
|
|
5967
6110
|
const members = NON_RETAINING_BUILTINS.get(callee.object.name);
|
|
@@ -5975,38 +6118,38 @@ function isNonRetainingBuiltinCall(node, argument) {
|
|
|
5975
6118
|
}
|
|
5976
6119
|
function isSafeRead(identifier) {
|
|
5977
6120
|
const parent = identifier.parent;
|
|
5978
|
-
if (parent.type ===
|
|
6121
|
+
if (parent.type === import_utils44.AST_NODE_TYPES.MemberExpression) {
|
|
5979
6122
|
if (parent.object !== identifier) {
|
|
5980
6123
|
return true;
|
|
5981
6124
|
}
|
|
5982
6125
|
const grandparent = parent.parent;
|
|
5983
|
-
if (grandparent.type ===
|
|
6126
|
+
if (grandparent.type === import_utils44.AST_NODE_TYPES.AssignmentExpression && grandparent.left === parent) {
|
|
5984
6127
|
return false;
|
|
5985
6128
|
}
|
|
5986
|
-
if (grandparent.type ===
|
|
6129
|
+
if (grandparent.type === import_utils44.AST_NODE_TYPES.UpdateExpression) {
|
|
5987
6130
|
return false;
|
|
5988
6131
|
}
|
|
5989
|
-
if (grandparent.type ===
|
|
6132
|
+
if (grandparent.type === import_utils44.AST_NODE_TYPES.UnaryExpression && grandparent.operator === "delete") {
|
|
5990
6133
|
return false;
|
|
5991
6134
|
}
|
|
5992
|
-
if (!parent.computed && parent.property.type ===
|
|
6135
|
+
if (!parent.computed && parent.property.type === import_utils44.AST_NODE_TYPES.Identifier && MUTATING_METHODS.has(parent.property.name) && grandparent.type === import_utils44.AST_NODE_TYPES.CallExpression && grandparent.callee === parent) {
|
|
5993
6136
|
return false;
|
|
5994
6137
|
}
|
|
5995
6138
|
return true;
|
|
5996
6139
|
}
|
|
5997
|
-
if (parent.type ===
|
|
6140
|
+
if (parent.type === import_utils44.AST_NODE_TYPES.ForOfStatement && parent.right === identifier) {
|
|
5998
6141
|
return true;
|
|
5999
6142
|
}
|
|
6000
|
-
if (parent.type ===
|
|
6143
|
+
if (parent.type === import_utils44.AST_NODE_TYPES.SpreadElement) {
|
|
6001
6144
|
return true;
|
|
6002
6145
|
}
|
|
6003
|
-
if (parent.type ===
|
|
6146
|
+
if (parent.type === import_utils44.AST_NODE_TYPES.BinaryExpression) {
|
|
6004
6147
|
return true;
|
|
6005
6148
|
}
|
|
6006
|
-
if (parent.type ===
|
|
6149
|
+
if (parent.type === import_utils44.AST_NODE_TYPES.CallExpression && parent.arguments.includes(identifier) && isNonRetainingBuiltinCall(parent, identifier)) {
|
|
6007
6150
|
return true;
|
|
6008
6151
|
}
|
|
6009
|
-
if (parent.type ===
|
|
6152
|
+
if (parent.type === import_utils44.AST_NODE_TYPES.UnaryExpression && parent.operator !== "delete") {
|
|
6010
6153
|
return true;
|
|
6011
6154
|
}
|
|
6012
6155
|
return false;
|
|
@@ -6061,7 +6204,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6061
6204
|
if (reference.isWrite()) {
|
|
6062
6205
|
return false;
|
|
6063
6206
|
}
|
|
6064
|
-
if (reference.identifier.type !==
|
|
6207
|
+
if (reference.identifier.type !== import_utils44.AST_NODE_TYPES.Identifier) {
|
|
6065
6208
|
return false;
|
|
6066
6209
|
}
|
|
6067
6210
|
if (!isSafeRead(reference.identifier)) {
|
|
@@ -6073,10 +6216,10 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6073
6216
|
return {
|
|
6074
6217
|
VariableDeclarator(node) {
|
|
6075
6218
|
const declaration = node.parent;
|
|
6076
|
-
if (declaration.type !==
|
|
6219
|
+
if (declaration.type !== import_utils44.AST_NODE_TYPES.VariableDeclaration || declaration.kind !== "const" || declaration.declare === true) {
|
|
6077
6220
|
return;
|
|
6078
6221
|
}
|
|
6079
|
-
if (node.id.type !==
|
|
6222
|
+
if (node.id.type !== import_utils44.AST_NODE_TYPES.Identifier || node.init === null) {
|
|
6080
6223
|
return;
|
|
6081
6224
|
}
|
|
6082
6225
|
if (enclosingFunction2(node) === null) {
|
|
@@ -6103,7 +6246,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6103
6246
|
});
|
|
6104
6247
|
|
|
6105
6248
|
// src/rules/prefer-module-level-schema.ts
|
|
6106
|
-
var
|
|
6249
|
+
var import_utils45 = require("@typescript-eslint/utils");
|
|
6107
6250
|
|
|
6108
6251
|
// src/rules/_zod.ts
|
|
6109
6252
|
var ZOD_PREFIX_RE = /^Z[A-Z]/;
|
|
@@ -6141,9 +6284,9 @@ var TERMINAL_METHODS = /* @__PURE__ */ new Set([
|
|
|
6141
6284
|
"spa"
|
|
6142
6285
|
]);
|
|
6143
6286
|
var FUNCTION_TYPES6 = /* @__PURE__ */ new Set([
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6287
|
+
import_utils45.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
6288
|
+
import_utils45.AST_NODE_TYPES.FunctionDeclaration,
|
|
6289
|
+
import_utils45.AST_NODE_TYPES.FunctionExpression
|
|
6147
6290
|
]);
|
|
6148
6291
|
function schemaExpression(node) {
|
|
6149
6292
|
let current = node;
|
|
@@ -6152,10 +6295,10 @@ function schemaExpression(node) {
|
|
|
6152
6295
|
if (parent === void 0) {
|
|
6153
6296
|
return current;
|
|
6154
6297
|
}
|
|
6155
|
-
if (parent.type ===
|
|
6298
|
+
if (parent.type === import_utils45.AST_NODE_TYPES.MemberExpression && parent.object === current && !parent.computed && parent.property.type === import_utils45.AST_NODE_TYPES.Identifier && TERMINAL_METHODS.has(parent.property.name)) {
|
|
6156
6299
|
return current;
|
|
6157
6300
|
}
|
|
6158
|
-
if (parent.type ===
|
|
6301
|
+
if (parent.type === import_utils45.AST_NODE_TYPES.MemberExpression && parent.object === current || parent.type === import_utils45.AST_NODE_TYPES.CallExpression && parent.callee === current || parent.type === import_utils45.AST_NODE_TYPES.TSAsExpression && parent.expression === current || parent.type === import_utils45.AST_NODE_TYPES.TSNonNullExpression && parent.expression === current) {
|
|
6159
6302
|
current = parent;
|
|
6160
6303
|
continue;
|
|
6161
6304
|
}
|
|
@@ -6189,7 +6332,7 @@ function readsReceiver(node) {
|
|
|
6189
6332
|
if (typeof candidate.type !== "string") {
|
|
6190
6333
|
return;
|
|
6191
6334
|
}
|
|
6192
|
-
if (candidate.type ===
|
|
6335
|
+
if (candidate.type === import_utils45.AST_NODE_TYPES.ThisExpression || candidate.type === import_utils45.AST_NODE_TYPES.Super || candidate.type === import_utils45.AST_NODE_TYPES.Identifier && candidate.name === "arguments") {
|
|
6193
6336
|
found = true;
|
|
6194
6337
|
return;
|
|
6195
6338
|
}
|
|
@@ -6257,15 +6400,15 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6257
6400
|
}
|
|
6258
6401
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
6259
6402
|
function isZodCall(node) {
|
|
6260
|
-
return node.type ===
|
|
6403
|
+
return node.type === import_utils45.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils45.AST_NODE_TYPES.MemberExpression && !node.callee.computed && node.callee.object.type === import_utils45.AST_NODE_TYPES.Identifier && zodNamespaces.has(node.callee.object.name);
|
|
6261
6404
|
}
|
|
6262
6405
|
function isCovered(node) {
|
|
6263
6406
|
let current = node.parent ?? void 0;
|
|
6264
6407
|
while (current !== void 0) {
|
|
6265
|
-
if (current !== node && isZodCall(current) && current.callee.type ===
|
|
6408
|
+
if (current !== node && isZodCall(current) && current.callee.type === import_utils45.AST_NODE_TYPES.MemberExpression && current.callee.property.type === import_utils45.AST_NODE_TYPES.Identifier && factories.has(current.callee.property.name)) {
|
|
6266
6409
|
return true;
|
|
6267
6410
|
}
|
|
6268
|
-
if (current.type ===
|
|
6411
|
+
if (current.type === import_utils45.AST_NODE_TYPES.CallExpression && (current.callee.type === import_utils45.AST_NODE_TYPES.Identifier && MEMO_CALLEES.has(current.callee.name) || current.callee.type === import_utils45.AST_NODE_TYPES.MemberExpression && !current.callee.computed && current.callee.property.type === import_utils45.AST_NODE_TYPES.Identifier && MEMO_CALLEES.has(current.callee.property.name))) {
|
|
6269
6412
|
return true;
|
|
6270
6413
|
}
|
|
6271
6414
|
current = current.parent ?? void 0;
|
|
@@ -6300,13 +6443,13 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6300
6443
|
}
|
|
6301
6444
|
function ownerName(enclosing) {
|
|
6302
6445
|
const parent = enclosing.parent ?? void 0;
|
|
6303
|
-
if (enclosing.type ===
|
|
6446
|
+
if (enclosing.type === import_utils45.AST_NODE_TYPES.FunctionDeclaration && enclosing.id !== null) {
|
|
6304
6447
|
return enclosing.id.name;
|
|
6305
6448
|
}
|
|
6306
|
-
if (parent !== void 0 && parent.type ===
|
|
6449
|
+
if (parent !== void 0 && parent.type === import_utils45.AST_NODE_TYPES.VariableDeclarator && parent.id.type === import_utils45.AST_NODE_TYPES.Identifier) {
|
|
6307
6450
|
return parent.id.name;
|
|
6308
6451
|
}
|
|
6309
|
-
if (parent !== void 0 && (parent.type ===
|
|
6452
|
+
if (parent !== void 0 && (parent.type === import_utils45.AST_NODE_TYPES.MethodDefinition || parent.type === import_utils45.AST_NODE_TYPES.Property) && parent.key.type === import_utils45.AST_NODE_TYPES.Identifier) {
|
|
6310
6453
|
return parent.key.name;
|
|
6311
6454
|
}
|
|
6312
6455
|
return "this function";
|
|
@@ -6317,7 +6460,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6317
6460
|
return;
|
|
6318
6461
|
}
|
|
6319
6462
|
for (const specifier of node.specifiers) {
|
|
6320
|
-
if (specifier.type ===
|
|
6463
|
+
if (specifier.type === import_utils45.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils45.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils45.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils45.AST_NODE_TYPES.Identifier && specifier.imported.name === "z") {
|
|
6321
6464
|
zodNamespaces.add(specifier.local.name);
|
|
6322
6465
|
}
|
|
6323
6466
|
}
|
|
@@ -6327,7 +6470,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6327
6470
|
return;
|
|
6328
6471
|
}
|
|
6329
6472
|
const callee = node.callee;
|
|
6330
|
-
if (callee.property.type !==
|
|
6473
|
+
if (callee.property.type !== import_utils45.AST_NODE_TYPES.Identifier) {
|
|
6331
6474
|
return;
|
|
6332
6475
|
}
|
|
6333
6476
|
const factory = callee.property.name;
|
|
@@ -6342,7 +6485,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6342
6485
|
return;
|
|
6343
6486
|
}
|
|
6344
6487
|
const shape = node.arguments[0];
|
|
6345
|
-
if (shape !== void 0 && shape.type ===
|
|
6488
|
+
if (shape !== void 0 && shape.type === import_utils45.AST_NODE_TYPES.ObjectExpression && shape.properties.length < minProperties) {
|
|
6346
6489
|
return;
|
|
6347
6490
|
}
|
|
6348
6491
|
const expression = schemaExpression(node);
|
|
@@ -6363,20 +6506,20 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6363
6506
|
});
|
|
6364
6507
|
|
|
6365
6508
|
// src/rules/prefer-non-nullable-collection.ts
|
|
6366
|
-
var
|
|
6509
|
+
var import_utils46 = require("@typescript-eslint/utils");
|
|
6367
6510
|
var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
6368
6511
|
function propertyName(node) {
|
|
6369
6512
|
const key = node.key;
|
|
6370
|
-
if (key.type ===
|
|
6371
|
-
if (key.type ===
|
|
6513
|
+
if (key.type === import_utils46.AST_NODE_TYPES.Identifier) return key.name;
|
|
6514
|
+
if (key.type === import_utils46.AST_NODE_TYPES.Literal) return String(key.value);
|
|
6372
6515
|
return "collection";
|
|
6373
6516
|
}
|
|
6374
6517
|
function isArrayType(node) {
|
|
6375
|
-
if (node.type ===
|
|
6376
|
-
return node.type ===
|
|
6518
|
+
if (node.type === import_utils46.AST_NODE_TYPES.TSArrayType) return true;
|
|
6519
|
+
return node.type === import_utils46.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils46.AST_NODE_TYPES.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
6377
6520
|
}
|
|
6378
6521
|
function isNullishType(node) {
|
|
6379
|
-
return node.type ===
|
|
6522
|
+
return node.type === import_utils46.AST_NODE_TYPES.TSNullKeyword || node.type === import_utils46.AST_NODE_TYPES.TSUndefinedKeyword;
|
|
6380
6523
|
}
|
|
6381
6524
|
function isNullableArrayOnly(node) {
|
|
6382
6525
|
const values = node.types.filter((member) => !isNullishType(member));
|
|
@@ -6403,7 +6546,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
6403
6546
|
function checkOptionalProperty(node) {
|
|
6404
6547
|
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
6405
6548
|
if (annotation === void 0) return;
|
|
6406
|
-
if (annotation.type !==
|
|
6549
|
+
if (annotation.type !== import_utils46.AST_NODE_TYPES.TSUnionType || !isNullableArrayOnly(annotation)) {
|
|
6407
6550
|
return;
|
|
6408
6551
|
}
|
|
6409
6552
|
context.report({
|
|
@@ -6416,7 +6559,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
6416
6559
|
TSPropertySignature: checkOptionalProperty,
|
|
6417
6560
|
PropertyDefinition: checkOptionalProperty,
|
|
6418
6561
|
TSTypeAliasDeclaration(node) {
|
|
6419
|
-
if (node.typeAnnotation.type !==
|
|
6562
|
+
if (node.typeAnnotation.type !== import_utils46.AST_NODE_TYPES.TSUnionType) return;
|
|
6420
6563
|
if (!isNullableArrayOnly(node.typeAnnotation)) return;
|
|
6421
6564
|
context.report({
|
|
6422
6565
|
node,
|
|
@@ -6429,13 +6572,13 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
6429
6572
|
});
|
|
6430
6573
|
|
|
6431
6574
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
6432
|
-
var
|
|
6575
|
+
var import_utils47 = require("@typescript-eslint/utils");
|
|
6433
6576
|
var unwrap4 = (node) => {
|
|
6434
6577
|
let current = node;
|
|
6435
6578
|
while (current !== null && current !== void 0) {
|
|
6436
|
-
if (current.type ===
|
|
6579
|
+
if (current.type === import_utils47.AST_NODE_TYPES.TSAsExpression || current.type === import_utils47.AST_NODE_TYPES.TSTypeAssertion || current.type === import_utils47.AST_NODE_TYPES.TSNonNullExpression || current.type === import_utils47.AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
6437
6580
|
current = current.expression;
|
|
6438
|
-
} else if (current.type ===
|
|
6581
|
+
} else if (current.type === import_utils47.AST_NODE_TYPES.ChainExpression) {
|
|
6439
6582
|
current = current.expression;
|
|
6440
6583
|
} else {
|
|
6441
6584
|
break;
|
|
@@ -6450,23 +6593,23 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
6450
6593
|
]);
|
|
6451
6594
|
var isSchemaParseReference = (node) => {
|
|
6452
6595
|
const inner = unwrap4(node);
|
|
6453
|
-
return inner !== null && inner.type ===
|
|
6596
|
+
return inner !== null && inner.type === import_utils47.AST_NODE_TYPES.MemberExpression && !inner.computed && inner.property.type === import_utils47.AST_NODE_TYPES.Identifier && (inner.property.name === "parse" || inner.property.name === "safeParse");
|
|
6454
6597
|
};
|
|
6455
6598
|
var isRawPayloadSource = (node) => {
|
|
6456
6599
|
let current = unwrap4(node);
|
|
6457
6600
|
if (current === null) return false;
|
|
6458
|
-
if (current.type ===
|
|
6601
|
+
if (current.type === import_utils47.AST_NODE_TYPES.AwaitExpression) {
|
|
6459
6602
|
current = unwrap4(current.argument);
|
|
6460
6603
|
}
|
|
6461
|
-
if (current === null || current.type !==
|
|
6604
|
+
if (current === null || current.type !== import_utils47.AST_NODE_TYPES.CallExpression) {
|
|
6462
6605
|
return false;
|
|
6463
6606
|
}
|
|
6464
6607
|
const callee = unwrap4(current.callee);
|
|
6465
|
-
if (callee === null || callee.type !==
|
|
6608
|
+
if (callee === null || callee.type !== import_utils47.AST_NODE_TYPES.MemberExpression) {
|
|
6466
6609
|
return false;
|
|
6467
6610
|
}
|
|
6468
6611
|
const property = unwrap4(callee.property);
|
|
6469
|
-
if (property === null || property.type !==
|
|
6612
|
+
if (property === null || property.type !== import_utils47.AST_NODE_TYPES.Identifier) {
|
|
6470
6613
|
return false;
|
|
6471
6614
|
}
|
|
6472
6615
|
if (property.name === "json") {
|
|
@@ -6476,7 +6619,7 @@ var isRawPayloadSource = (node) => {
|
|
|
6476
6619
|
return !current.arguments.some(isSchemaParseReference) && isRawPayloadSource(callee.object);
|
|
6477
6620
|
}
|
|
6478
6621
|
const object = unwrap4(callee.object);
|
|
6479
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
6622
|
+
return property.name === "parse" && object !== null && object.type === import_utils47.AST_NODE_TYPES.Identifier && object.name === "JSON" && // ...but not `JSON.parse(readFileSync(p, "utf8"))` — see isLocalFileRead.
|
|
6480
6623
|
!isLocalFileRead(current.arguments[0]);
|
|
6481
6624
|
};
|
|
6482
6625
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
@@ -6484,9 +6627,9 @@ var isLocalFileRead = (node) => {
|
|
|
6484
6627
|
let found = false;
|
|
6485
6628
|
const visit = (current) => {
|
|
6486
6629
|
if (found || current === null || current === void 0) return;
|
|
6487
|
-
if (current.type ===
|
|
6630
|
+
if (current.type === import_utils47.AST_NODE_TYPES.CallExpression) {
|
|
6488
6631
|
const callee = unwrap4(current.callee);
|
|
6489
|
-
const name = callee?.type ===
|
|
6632
|
+
const name = callee?.type === import_utils47.AST_NODE_TYPES.Identifier ? callee.name : callee?.type === import_utils47.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils47.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
6490
6633
|
if (name !== null && FILE_READ_RE.test(name)) {
|
|
6491
6634
|
found = true;
|
|
6492
6635
|
return;
|
|
@@ -6508,15 +6651,15 @@ var isLocalFileRead = (node) => {
|
|
|
6508
6651
|
var ASSERTION_CALLEE_RE = /^(expect|assert|should|invariant)$/;
|
|
6509
6652
|
var isInsideAssertion = (node) => {
|
|
6510
6653
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
6511
|
-
if (current.type !==
|
|
6654
|
+
if (current.type !== import_utils47.AST_NODE_TYPES.CallExpression) continue;
|
|
6512
6655
|
let callee = current.callee;
|
|
6513
|
-
while (callee.type ===
|
|
6656
|
+
while (callee.type === import_utils47.AST_NODE_TYPES.MemberExpression) {
|
|
6514
6657
|
callee = callee.object;
|
|
6515
6658
|
}
|
|
6516
|
-
if (callee.type ===
|
|
6659
|
+
if (callee.type === import_utils47.AST_NODE_TYPES.CallExpression) {
|
|
6517
6660
|
callee = callee.callee;
|
|
6518
6661
|
}
|
|
6519
|
-
if (callee.type ===
|
|
6662
|
+
if (callee.type === import_utils47.AST_NODE_TYPES.Identifier && ASSERTION_CALLEE_RE.test(callee.name)) {
|
|
6520
6663
|
return true;
|
|
6521
6664
|
}
|
|
6522
6665
|
}
|
|
@@ -6535,39 +6678,39 @@ var GUARD_NAME_RE = /^(?:is|validate|parse|assert|decode|coerce)[A-Z]/;
|
|
|
6535
6678
|
var isValidationRead = (node) => {
|
|
6536
6679
|
let current = node;
|
|
6537
6680
|
let parent = current.parent;
|
|
6538
|
-
while (parent !== null && parent !== void 0 && (parent.type ===
|
|
6681
|
+
while (parent !== null && parent !== void 0 && (parent.type === import_utils47.AST_NODE_TYPES.TSAsExpression || parent.type === import_utils47.AST_NODE_TYPES.TSTypeAssertion || parent.type === import_utils47.AST_NODE_TYPES.TSNonNullExpression || parent.type === import_utils47.AST_NODE_TYPES.TSSatisfiesExpression || parent.type === import_utils47.AST_NODE_TYPES.ChainExpression)) {
|
|
6539
6682
|
current = parent;
|
|
6540
6683
|
parent = parent.parent;
|
|
6541
6684
|
}
|
|
6542
6685
|
if (parent === null || parent === void 0) return false;
|
|
6543
|
-
if (parent.type ===
|
|
6686
|
+
if (parent.type === import_utils47.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof" && parent.argument === current) {
|
|
6544
6687
|
return true;
|
|
6545
6688
|
}
|
|
6546
|
-
if (parent.type !==
|
|
6689
|
+
if (parent.type !== import_utils47.AST_NODE_TYPES.CallExpression || !parent.arguments.some((arg) => arg === current)) {
|
|
6547
6690
|
return false;
|
|
6548
6691
|
}
|
|
6549
6692
|
const callee = parent.callee;
|
|
6550
|
-
if (callee.type ===
|
|
6693
|
+
if (callee.type === import_utils47.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.object.type === import_utils47.AST_NODE_TYPES.Identifier && callee.object.name === "Array" && callee.property.type === import_utils47.AST_NODE_TYPES.Identifier && callee.property.name === "isArray") {
|
|
6551
6694
|
return parent.arguments.length === 1;
|
|
6552
6695
|
}
|
|
6553
|
-
return callee.type ===
|
|
6696
|
+
return callee.type === import_utils47.AST_NODE_TYPES.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
6554
6697
|
};
|
|
6555
6698
|
var isGuardTestPosition = (node) => {
|
|
6556
6699
|
let current = node;
|
|
6557
6700
|
let parent = current.parent;
|
|
6558
6701
|
while (parent !== void 0 && parent !== null) {
|
|
6559
6702
|
switch (parent.type) {
|
|
6560
|
-
case
|
|
6561
|
-
case
|
|
6562
|
-
case
|
|
6703
|
+
case import_utils47.AST_NODE_TYPES.UnaryExpression:
|
|
6704
|
+
case import_utils47.AST_NODE_TYPES.LogicalExpression:
|
|
6705
|
+
case import_utils47.AST_NODE_TYPES.ChainExpression:
|
|
6563
6706
|
current = parent;
|
|
6564
6707
|
parent = parent.parent;
|
|
6565
6708
|
continue;
|
|
6566
|
-
case
|
|
6567
|
-
case
|
|
6568
|
-
case
|
|
6569
|
-
case
|
|
6570
|
-
case
|
|
6709
|
+
case import_utils47.AST_NODE_TYPES.IfStatement:
|
|
6710
|
+
case import_utils47.AST_NODE_TYPES.ConditionalExpression:
|
|
6711
|
+
case import_utils47.AST_NODE_TYPES.WhileStatement:
|
|
6712
|
+
case import_utils47.AST_NODE_TYPES.DoWhileStatement:
|
|
6713
|
+
case import_utils47.AST_NODE_TYPES.ForStatement:
|
|
6571
6714
|
return parent.test === current;
|
|
6572
6715
|
default:
|
|
6573
6716
|
return false;
|
|
@@ -6577,7 +6720,7 @@ var isGuardTestPosition = (node) => {
|
|
|
6577
6720
|
};
|
|
6578
6721
|
var isUnvalidatedVariableRef = (node, scope, tracked) => {
|
|
6579
6722
|
const unwrapped = unwrap4(node);
|
|
6580
|
-
if (unwrapped === null || unwrapped.type !==
|
|
6723
|
+
if (unwrapped === null || unwrapped.type !== import_utils47.AST_NODE_TYPES.Identifier) {
|
|
6581
6724
|
return false;
|
|
6582
6725
|
}
|
|
6583
6726
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -6620,11 +6763,11 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6620
6763
|
return {
|
|
6621
6764
|
VariableDeclarator(node) {
|
|
6622
6765
|
const scope = context.sourceCode.getScope(node);
|
|
6623
|
-
if (node.id.type ===
|
|
6766
|
+
if (node.id.type === import_utils47.AST_NODE_TYPES.Identifier) {
|
|
6624
6767
|
trackInitializer(node);
|
|
6625
6768
|
return;
|
|
6626
6769
|
}
|
|
6627
|
-
if (node.id.type ===
|
|
6770
|
+
if (node.id.type === import_utils47.AST_NODE_TYPES.ObjectPattern || node.id.type === import_utils47.AST_NODE_TYPES.ArrayPattern) {
|
|
6628
6771
|
if (isRawPayloadSource(node.init)) {
|
|
6629
6772
|
if (!isFullyNarrowedPattern(node)) {
|
|
6630
6773
|
context.report({ node: node.id, messageId: "unparsedJsonAccess" });
|
|
@@ -6638,7 +6781,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6638
6781
|
},
|
|
6639
6782
|
AssignmentExpression(node) {
|
|
6640
6783
|
const scope = context.sourceCode.getScope(node);
|
|
6641
|
-
if (node.left.type ===
|
|
6784
|
+
if (node.left.type === import_utils47.AST_NODE_TYPES.Identifier) {
|
|
6642
6785
|
const variable = findVariable2(scope, node.left.name);
|
|
6643
6786
|
if (variable === null) return;
|
|
6644
6787
|
if (isRawPayloadSource(node.right)) {
|
|
@@ -6648,7 +6791,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6648
6791
|
}
|
|
6649
6792
|
return;
|
|
6650
6793
|
}
|
|
6651
|
-
if (node.left.type ===
|
|
6794
|
+
if (node.left.type === import_utils47.AST_NODE_TYPES.ObjectPattern || node.left.type === import_utils47.AST_NODE_TYPES.ArrayPattern) {
|
|
6652
6795
|
if (isRawPayloadSource(node.right)) {
|
|
6653
6796
|
context.report({
|
|
6654
6797
|
node: node.left,
|
|
@@ -6665,15 +6808,15 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6665
6808
|
}
|
|
6666
6809
|
},
|
|
6667
6810
|
CallExpression(node) {
|
|
6668
|
-
if (node.callee.type !==
|
|
6811
|
+
if (node.callee.type !== import_utils47.AST_NODE_TYPES.Identifier) return;
|
|
6669
6812
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
6670
6813
|
return;
|
|
6671
6814
|
}
|
|
6672
6815
|
const scope = context.sourceCode.getScope(node);
|
|
6673
6816
|
for (const arg of node.arguments) {
|
|
6674
|
-
if (arg.type ===
|
|
6817
|
+
if (arg.type === import_utils47.AST_NODE_TYPES.SpreadElement) continue;
|
|
6675
6818
|
const unwrapped = unwrap4(arg);
|
|
6676
|
-
if (unwrapped === null || unwrapped.type !==
|
|
6819
|
+
if (unwrapped === null || unwrapped.type !== import_utils47.AST_NODE_TYPES.Identifier) {
|
|
6677
6820
|
continue;
|
|
6678
6821
|
}
|
|
6679
6822
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -6687,13 +6830,13 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6687
6830
|
const obj = unwrap4(node.object);
|
|
6688
6831
|
if (isRawPayloadSource(obj)) {
|
|
6689
6832
|
const parent = node.parent;
|
|
6690
|
-
if (parent.type ===
|
|
6833
|
+
if (parent.type === import_utils47.AST_NODE_TYPES.CallExpression && parent.callee === node && node.property.type === import_utils47.AST_NODE_TYPES.Identifier && (node.property.name === "parse" || node.property.name === "safeParse" || PROMISE_CHAIN_METHODS.has(node.property.name))) {
|
|
6691
6834
|
return;
|
|
6692
6835
|
}
|
|
6693
6836
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
6694
6837
|
return;
|
|
6695
6838
|
}
|
|
6696
|
-
if (obj !== null && obj.type ===
|
|
6839
|
+
if (obj !== null && obj.type === import_utils47.AST_NODE_TYPES.Identifier && isUnvalidatedVariableRef(obj, scope, unvalidatedVariables)) {
|
|
6697
6840
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
6698
6841
|
const variable = findVariable2(scope, obj.name);
|
|
6699
6842
|
if (variable !== null) {
|
|
@@ -6706,7 +6849,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6706
6849
|
});
|
|
6707
6850
|
|
|
6708
6851
|
// src/rules/prefer-semantic-colors.ts
|
|
6709
|
-
var
|
|
6852
|
+
var import_utils48 = require("@typescript-eslint/utils");
|
|
6710
6853
|
var import_fs = require("fs");
|
|
6711
6854
|
var import_path = require("path");
|
|
6712
6855
|
|
|
@@ -6783,8 +6926,8 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
6783
6926
|
]);
|
|
6784
6927
|
function jsxElementName(node) {
|
|
6785
6928
|
const name = node.openingElement.name;
|
|
6786
|
-
if (name.type ===
|
|
6787
|
-
if (name.type ===
|
|
6929
|
+
if (name.type === import_utils48.AST_NODE_TYPES.JSXIdentifier) return name.name;
|
|
6930
|
+
if (name.type === import_utils48.AST_NODE_TYPES.JSXMemberExpression && name.property.type === import_utils48.AST_NODE_TYPES.JSXIdentifier) {
|
|
6788
6931
|
return name.property.name;
|
|
6789
6932
|
}
|
|
6790
6933
|
return null;
|
|
@@ -6810,7 +6953,7 @@ var EMAIL_OR_PDF_IMPORT_RE = /@react-(?:email|pdf)\//;
|
|
|
6810
6953
|
var isInsideSvg = (node) => {
|
|
6811
6954
|
let current = node.parent;
|
|
6812
6955
|
while (current !== void 0 && current !== null) {
|
|
6813
|
-
if (current.type ===
|
|
6956
|
+
if (current.type === import_utils48.AST_NODE_TYPES.JSXElement) {
|
|
6814
6957
|
const name = jsxElementName(current);
|
|
6815
6958
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
6816
6959
|
}
|
|
@@ -6821,7 +6964,7 @@ var isInsideSvg = (node) => {
|
|
|
6821
6964
|
var isInsideIconFactoryPath = (node) => {
|
|
6822
6965
|
let current = node.parent;
|
|
6823
6966
|
while (current !== void 0 && current !== null) {
|
|
6824
|
-
if (current.type ===
|
|
6967
|
+
if (current.type === import_utils48.AST_NODE_TYPES.Property && propName(current.key) === "path" && current.parent.type === import_utils48.AST_NODE_TYPES.ObjectExpression && current.parent.parent.type === import_utils48.AST_NODE_TYPES.CallExpression && current.parent.parent.callee.type === import_utils48.AST_NODE_TYPES.Identifier && current.parent.parent.callee.name === "createIcon") {
|
|
6825
6968
|
return true;
|
|
6826
6969
|
}
|
|
6827
6970
|
current = current.parent;
|
|
@@ -6871,8 +7014,8 @@ var hasSemanticTokenSystem = (filename) => {
|
|
|
6871
7014
|
return answer;
|
|
6872
7015
|
};
|
|
6873
7016
|
var propName = (key) => {
|
|
6874
|
-
if (key.type ===
|
|
6875
|
-
if (key.type ===
|
|
7017
|
+
if (key.type === import_utils48.AST_NODE_TYPES.Identifier) return key.name;
|
|
7018
|
+
if (key.type === import_utils48.AST_NODE_TYPES.Literal && typeof key.value === "string") return key.value;
|
|
6876
7019
|
return null;
|
|
6877
7020
|
};
|
|
6878
7021
|
var prefer_semantic_colors_default = createRule({
|
|
@@ -6917,27 +7060,27 @@ var prefer_semantic_colors_default = createRule({
|
|
|
6917
7060
|
const checkClassNode = (node) => {
|
|
6918
7061
|
if (node === null) return;
|
|
6919
7062
|
switch (node.type) {
|
|
6920
|
-
case
|
|
7063
|
+
case import_utils48.AST_NODE_TYPES.Literal:
|
|
6921
7064
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
6922
7065
|
break;
|
|
6923
|
-
case
|
|
7066
|
+
case import_utils48.AST_NODE_TYPES.TemplateLiteral:
|
|
6924
7067
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
6925
7068
|
break;
|
|
6926
|
-
case
|
|
7069
|
+
case import_utils48.AST_NODE_TYPES.ArrayExpression:
|
|
6927
7070
|
for (const element of node.elements) {
|
|
6928
|
-
if (element !== null && element.type !==
|
|
7071
|
+
if (element !== null && element.type !== import_utils48.AST_NODE_TYPES.SpreadElement) checkClassNode(element);
|
|
6929
7072
|
}
|
|
6930
7073
|
break;
|
|
6931
|
-
case
|
|
7074
|
+
case import_utils48.AST_NODE_TYPES.ObjectExpression:
|
|
6932
7075
|
for (const property of node.properties) {
|
|
6933
|
-
if (property.type ===
|
|
7076
|
+
if (property.type === import_utils48.AST_NODE_TYPES.Property) checkClassNode(property.value);
|
|
6934
7077
|
}
|
|
6935
7078
|
break;
|
|
6936
|
-
case
|
|
7079
|
+
case import_utils48.AST_NODE_TYPES.ConditionalExpression:
|
|
6937
7080
|
checkClassNode(node.consequent);
|
|
6938
7081
|
checkClassNode(node.alternate);
|
|
6939
7082
|
break;
|
|
6940
|
-
case
|
|
7083
|
+
case import_utils48.AST_NODE_TYPES.LogicalExpression:
|
|
6941
7084
|
checkClassNode(node.right);
|
|
6942
7085
|
break;
|
|
6943
7086
|
default:
|
|
@@ -6945,29 +7088,29 @@ var prefer_semantic_colors_default = createRule({
|
|
|
6945
7088
|
}
|
|
6946
7089
|
};
|
|
6947
7090
|
const checkColorValueNode = (node) => {
|
|
6948
|
-
if (node.type ===
|
|
7091
|
+
if (node.type === import_utils48.AST_NODE_TYPES.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value) && !CSS_VAR_REFERENCE_RE.test(node.value)) {
|
|
6949
7092
|
context.report({ node, messageId: "inlineColor", data: { value: node.value } });
|
|
6950
7093
|
}
|
|
6951
7094
|
};
|
|
6952
7095
|
return {
|
|
6953
7096
|
"JSXAttribute[name.name='className']"(node) {
|
|
6954
7097
|
if (node.value === null) return;
|
|
6955
|
-
if (node.value.type ===
|
|
6956
|
-
else if (node.value.type ===
|
|
6957
|
-
if (node.value.expression.type !==
|
|
7098
|
+
if (node.value.type === import_utils48.AST_NODE_TYPES.Literal) checkClassNode(node.value);
|
|
7099
|
+
else if (node.value.type === import_utils48.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
7100
|
+
if (node.value.expression.type !== import_utils48.AST_NODE_TYPES.JSXEmptyExpression) {
|
|
6958
7101
|
checkClassNode(node.value.expression);
|
|
6959
7102
|
}
|
|
6960
7103
|
}
|
|
6961
7104
|
},
|
|
6962
7105
|
CallExpression(node) {
|
|
6963
|
-
if (node.callee.type ===
|
|
7106
|
+
if (node.callee.type === import_utils48.AST_NODE_TYPES.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
6964
7107
|
for (const arg of node.arguments) {
|
|
6965
|
-
if (arg.type !==
|
|
7108
|
+
if (arg.type !== import_utils48.AST_NODE_TYPES.SpreadElement) checkClassNode(arg);
|
|
6966
7109
|
}
|
|
6967
7110
|
}
|
|
6968
7111
|
},
|
|
6969
7112
|
VariableDeclarator(node) {
|
|
6970
|
-
if (node.id.type ===
|
|
7113
|
+
if (node.id.type === import_utils48.AST_NODE_TYPES.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
6971
7114
|
checkClassNode(node.init);
|
|
6972
7115
|
}
|
|
6973
7116
|
},
|
|
@@ -6979,9 +7122,9 @@ var prefer_semantic_colors_default = createRule({
|
|
|
6979
7122
|
// Neutral drawing literals and anything inside an SVG defs container are
|
|
6980
7123
|
// structural, not UI tokens, so they never fire.
|
|
6981
7124
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
6982
|
-
if (node.value?.type !==
|
|
7125
|
+
if (node.value?.type !== import_utils48.AST_NODE_TYPES.Literal) return;
|
|
6983
7126
|
const owner = node.parent.name;
|
|
6984
|
-
if (owner.type ===
|
|
7127
|
+
if (owner.type === import_utils48.AST_NODE_TYPES.JSXIdentifier && SVG_SHAPE_PRIMITIVES.has(owner.name)) {
|
|
6985
7128
|
return;
|
|
6986
7129
|
}
|
|
6987
7130
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
@@ -6999,7 +7142,7 @@ var prefer_semantic_colors_default = createRule({
|
|
|
6999
7142
|
});
|
|
7000
7143
|
|
|
7001
7144
|
// src/rules/prefer-server-actions.ts
|
|
7002
|
-
var
|
|
7145
|
+
var import_utils49 = require("@typescript-eslint/utils");
|
|
7003
7146
|
var MUTATION_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "DELETE", "PATCH"]);
|
|
7004
7147
|
var AXIOS_MUTATION_METHODS = /* @__PURE__ */ new Set(["post", "put", "delete", "patch"]);
|
|
7005
7148
|
var SKIP_FILE_REGEX = /(?:\.test\.[jt]sx?$|\.spec\.[jt]sx?$|-(?:test|spec)\.[jt]sx?$|\/tests?\/|\/__tests__\/|\/__testfixtures__\/|\/scripts?\/|\/app\/api\/.*\/route\.[jt]sx?$|\/pages\/api\/)/;
|
|
@@ -7152,7 +7295,7 @@ var prefer_server_actions_default = createRule({
|
|
|
7152
7295
|
});
|
|
7153
7296
|
|
|
7154
7297
|
// src/rules/prefer-string-literal-union.ts
|
|
7155
|
-
var
|
|
7298
|
+
var import_utils50 = require("@typescript-eslint/utils");
|
|
7156
7299
|
var ts2 = __toESM(require("typescript"), 1);
|
|
7157
7300
|
var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
7158
7301
|
"status",
|
|
@@ -7195,19 +7338,19 @@ function isChoiceLikeName(name) {
|
|
|
7195
7338
|
return CHOICE_TOKENS.has(lastWord(name));
|
|
7196
7339
|
}
|
|
7197
7340
|
function keyName(key) {
|
|
7198
|
-
if (key.type ===
|
|
7341
|
+
if (key.type === import_utils50.AST_NODE_TYPES.Identifier) {
|
|
7199
7342
|
return key.name;
|
|
7200
7343
|
}
|
|
7201
|
-
if (key.type ===
|
|
7344
|
+
if (key.type === import_utils50.AST_NODE_TYPES.Literal && typeof key.value === "string") {
|
|
7202
7345
|
return key.value;
|
|
7203
7346
|
}
|
|
7204
7347
|
return null;
|
|
7205
7348
|
}
|
|
7206
7349
|
function isStringLiteralMember(t) {
|
|
7207
|
-
return t.type ===
|
|
7350
|
+
return t.type === import_utils50.AST_NODE_TYPES.TSLiteralType && t.literal.type === import_utils50.AST_NODE_TYPES.Literal && typeof t.literal.value === "string";
|
|
7208
7351
|
}
|
|
7209
7352
|
function isStringLiteralUnion(node) {
|
|
7210
|
-
if (node?.type !==
|
|
7353
|
+
if (node?.type !== import_utils50.AST_NODE_TYPES.TSUnionType) {
|
|
7211
7354
|
return false;
|
|
7212
7355
|
}
|
|
7213
7356
|
return node.types.filter(isStringLiteralMember).length >= MIN_CLUSTER_SIZE;
|
|
@@ -7236,12 +7379,12 @@ function bindingSourceExpression(decl) {
|
|
|
7236
7379
|
return ts2.isForOfStatement(node) ? node.expression : node.initializer;
|
|
7237
7380
|
}
|
|
7238
7381
|
function refKey(node) {
|
|
7239
|
-
if (node.type ===
|
|
7382
|
+
if (node.type === import_utils50.AST_NODE_TYPES.Identifier) {
|
|
7240
7383
|
return node.name;
|
|
7241
7384
|
}
|
|
7242
|
-
if (node.type ===
|
|
7385
|
+
if (node.type === import_utils50.AST_NODE_TYPES.MemberExpression && !node.computed) {
|
|
7243
7386
|
const inner = refKey(node.object);
|
|
7244
|
-
if (inner === null || node.property.type !==
|
|
7387
|
+
if (inner === null || node.property.type !== import_utils50.AST_NODE_TYPES.Identifier) {
|
|
7245
7388
|
return null;
|
|
7246
7389
|
}
|
|
7247
7390
|
return `${inner}.${node.property.name}`;
|
|
@@ -7249,7 +7392,7 @@ function refKey(node) {
|
|
|
7249
7392
|
return null;
|
|
7250
7393
|
}
|
|
7251
7394
|
function strLiteral(node) {
|
|
7252
|
-
if (node.type ===
|
|
7395
|
+
if (node.type === import_utils50.AST_NODE_TYPES.Literal && typeof node.value === "string") {
|
|
7253
7396
|
return node.value;
|
|
7254
7397
|
}
|
|
7255
7398
|
return null;
|
|
@@ -7290,7 +7433,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
7290
7433
|
);
|
|
7291
7434
|
let services;
|
|
7292
7435
|
try {
|
|
7293
|
-
services =
|
|
7436
|
+
services = import_utils50.ESLintUtils.getParserServices(context);
|
|
7294
7437
|
} catch {
|
|
7295
7438
|
services = null;
|
|
7296
7439
|
}
|
|
@@ -7402,7 +7545,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
7402
7545
|
containersWithUnion.add(container);
|
|
7403
7546
|
return;
|
|
7404
7547
|
}
|
|
7405
|
-
if (typeNode?.type !==
|
|
7548
|
+
if (typeNode?.type !== import_utils50.AST_NODE_TYPES.TSStringKeyword) {
|
|
7406
7549
|
return;
|
|
7407
7550
|
}
|
|
7408
7551
|
const name = keyName(key);
|
|
@@ -7490,10 +7633,10 @@ var prefer_string_literal_union_default = createRule({
|
|
|
7490
7633
|
}
|
|
7491
7634
|
};
|
|
7492
7635
|
function refKeyText(node) {
|
|
7493
|
-
if (node.type ===
|
|
7636
|
+
if (node.type === import_utils50.AST_NODE_TYPES.BinaryExpression) {
|
|
7494
7637
|
return refKey(node.left) ?? refKey(node.right) ?? "value";
|
|
7495
7638
|
}
|
|
7496
|
-
if (node.type ===
|
|
7639
|
+
if (node.type === import_utils50.AST_NODE_TYPES.SwitchStatement) {
|
|
7497
7640
|
return refKey(node.discriminant) ?? "value";
|
|
7498
7641
|
}
|
|
7499
7642
|
return "value";
|
|
@@ -7502,7 +7645,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
7502
7645
|
});
|
|
7503
7646
|
|
|
7504
7647
|
// src/rules/prefer-whole-object-assertion.ts
|
|
7505
|
-
var
|
|
7648
|
+
var import_utils51 = require("@typescript-eslint/utils");
|
|
7506
7649
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
7507
7650
|
var ARRAY_MATCHERS = /* @__PURE__ */ new Set(["toEqual", "toStrictEqual"]);
|
|
7508
7651
|
var COLLECTION_PROPERTIES = /* @__PURE__ */ new Set(["length", "size"]);
|
|
@@ -7510,11 +7653,11 @@ var NUMERIC_SIGNS2 = /* @__PURE__ */ new Set(["-", "+"]);
|
|
|
7510
7653
|
var MIN_RUN_LENGTH = 2;
|
|
7511
7654
|
function literalText(node, getText) {
|
|
7512
7655
|
switch (node.type) {
|
|
7513
|
-
case
|
|
7656
|
+
case import_utils51.AST_NODE_TYPES.Literal:
|
|
7514
7657
|
return "regex" in node ? null : getText(node);
|
|
7515
|
-
case
|
|
7658
|
+
case import_utils51.AST_NODE_TYPES.TemplateLiteral:
|
|
7516
7659
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
7517
|
-
case
|
|
7660
|
+
case import_utils51.AST_NODE_TYPES.UnaryExpression:
|
|
7518
7661
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
7519
7662
|
default:
|
|
7520
7663
|
return null;
|
|
@@ -7522,15 +7665,15 @@ function literalText(node, getText) {
|
|
|
7522
7665
|
}
|
|
7523
7666
|
function isPureReceiver(node) {
|
|
7524
7667
|
switch (node.type) {
|
|
7525
|
-
case
|
|
7526
|
-
case
|
|
7668
|
+
case import_utils51.AST_NODE_TYPES.Identifier:
|
|
7669
|
+
case import_utils51.AST_NODE_TYPES.ThisExpression:
|
|
7527
7670
|
return true;
|
|
7528
|
-
case
|
|
7671
|
+
case import_utils51.AST_NODE_TYPES.MemberExpression:
|
|
7529
7672
|
if (node.optional) {
|
|
7530
7673
|
return false;
|
|
7531
7674
|
}
|
|
7532
7675
|
if (node.computed) {
|
|
7533
|
-
return node.property.type ===
|
|
7676
|
+
return node.property.type === import_utils51.AST_NODE_TYPES.Literal && isPureReceiver(node.object);
|
|
7534
7677
|
}
|
|
7535
7678
|
return isPureReceiver(node.object);
|
|
7536
7679
|
default:
|
|
@@ -7538,7 +7681,7 @@ function isPureReceiver(node) {
|
|
|
7538
7681
|
}
|
|
7539
7682
|
}
|
|
7540
7683
|
function literalIndex(node) {
|
|
7541
|
-
if (node.type !==
|
|
7684
|
+
if (node.type !== import_utils51.AST_NODE_TYPES.Literal || typeof node.value !== "number") {
|
|
7542
7685
|
return null;
|
|
7543
7686
|
}
|
|
7544
7687
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
@@ -7564,24 +7707,24 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
7564
7707
|
}
|
|
7565
7708
|
const { sourceCode } = context;
|
|
7566
7709
|
function parseAssertion(statement) {
|
|
7567
|
-
if (statement.type !==
|
|
7710
|
+
if (statement.type !== import_utils51.AST_NODE_TYPES.ExpressionStatement) {
|
|
7568
7711
|
return null;
|
|
7569
7712
|
}
|
|
7570
7713
|
const call = statement.expression;
|
|
7571
|
-
if (call.type !==
|
|
7714
|
+
if (call.type !== import_utils51.AST_NODE_TYPES.CallExpression) {
|
|
7572
7715
|
return null;
|
|
7573
7716
|
}
|
|
7574
7717
|
const callee = call.callee;
|
|
7575
|
-
if (callee.type !==
|
|
7718
|
+
if (callee.type !== import_utils51.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils51.AST_NODE_TYPES.Identifier) {
|
|
7576
7719
|
return null;
|
|
7577
7720
|
}
|
|
7578
7721
|
const matcher = callee.property.name;
|
|
7579
7722
|
const expectCall = callee.object;
|
|
7580
|
-
if (expectCall.type !==
|
|
7723
|
+
if (expectCall.type !== import_utils51.AST_NODE_TYPES.CallExpression || expectCall.callee.type !== import_utils51.AST_NODE_TYPES.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
7581
7724
|
return null;
|
|
7582
7725
|
}
|
|
7583
7726
|
const actual = expectCall.arguments[0];
|
|
7584
|
-
if (actual === void 0 || actual.type !==
|
|
7727
|
+
if (actual === void 0 || actual.type !== import_utils51.AST_NODE_TYPES.MemberExpression || actual.optional) {
|
|
7585
7728
|
return null;
|
|
7586
7729
|
}
|
|
7587
7730
|
if (!isPureReceiver(actual.object)) {
|
|
@@ -7595,7 +7738,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
7595
7738
|
}
|
|
7596
7739
|
key = { kind: "index", index };
|
|
7597
7740
|
} else {
|
|
7598
|
-
if (actual.property.type !==
|
|
7741
|
+
if (actual.property.type !== import_utils51.AST_NODE_TYPES.Identifier || COLLECTION_PROPERTIES.has(actual.property.name)) {
|
|
7599
7742
|
return null;
|
|
7600
7743
|
}
|
|
7601
7744
|
key = { kind: "property", name: actual.property.name };
|
|
@@ -7607,7 +7750,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
7607
7750
|
return null;
|
|
7608
7751
|
}
|
|
7609
7752
|
const expected = call.arguments[0];
|
|
7610
|
-
if (call.arguments.length !== 1 || expected === void 0 || expected.type ===
|
|
7753
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === import_utils51.AST_NODE_TYPES.SpreadElement) {
|
|
7611
7754
|
return null;
|
|
7612
7755
|
}
|
|
7613
7756
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
@@ -7717,7 +7860,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
7717
7860
|
});
|
|
7718
7861
|
|
|
7719
7862
|
// src/rules/prefer-zod-enum.ts
|
|
7720
|
-
var
|
|
7863
|
+
var import_utils52 = require("@typescript-eslint/utils");
|
|
7721
7864
|
var prefer_zod_enum_default = createRule({
|
|
7722
7865
|
name: "prefer-zod-enum",
|
|
7723
7866
|
meta: {
|
|
@@ -7737,20 +7880,20 @@ var prefer_zod_enum_default = createRule({
|
|
|
7737
7880
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
7738
7881
|
function enumValues(node) {
|
|
7739
7882
|
const callee = node.callee;
|
|
7740
|
-
if (callee.type !==
|
|
7883
|
+
if (callee.type !== import_utils52.AST_NODE_TYPES.MemberExpression || callee.computed || callee.object.type !== import_utils52.AST_NODE_TYPES.Identifier || !zodNamespaces.has(callee.object.name) || callee.property.type !== import_utils52.AST_NODE_TYPES.Identifier || callee.property.name !== "union" || node.arguments.length !== 1) {
|
|
7741
7884
|
return null;
|
|
7742
7885
|
}
|
|
7743
7886
|
const argument = node.arguments[0];
|
|
7744
|
-
if (argument === void 0 || argument.type !==
|
|
7887
|
+
if (argument === void 0 || argument.type !== import_utils52.AST_NODE_TYPES.ArrayExpression || argument.elements.length === 0) {
|
|
7745
7888
|
return null;
|
|
7746
7889
|
}
|
|
7747
7890
|
const values = [];
|
|
7748
7891
|
for (const element of argument.elements) {
|
|
7749
|
-
if (element === null || element.type !==
|
|
7892
|
+
if (element === null || element.type !== import_utils52.AST_NODE_TYPES.CallExpression || element.arguments.length !== 1 || element.callee.type !== import_utils52.AST_NODE_TYPES.MemberExpression || element.callee.computed || element.callee.object.type !== import_utils52.AST_NODE_TYPES.Identifier || !zodNamespaces.has(element.callee.object.name) || element.callee.property.type !== import_utils52.AST_NODE_TYPES.Identifier || element.callee.property.name !== "literal") {
|
|
7750
7893
|
return null;
|
|
7751
7894
|
}
|
|
7752
7895
|
const value = element.arguments[0];
|
|
7753
|
-
if (value === void 0 || value.type !==
|
|
7896
|
+
if (value === void 0 || value.type !== import_utils52.AST_NODE_TYPES.Literal || typeof value.value !== "string") {
|
|
7754
7897
|
return null;
|
|
7755
7898
|
}
|
|
7756
7899
|
values.push(value);
|
|
@@ -7759,11 +7902,11 @@ var prefer_zod_enum_default = createRule({
|
|
|
7759
7902
|
}
|
|
7760
7903
|
function buildFix(node, values) {
|
|
7761
7904
|
const argument = node.arguments[0];
|
|
7762
|
-
if (argument === void 0 || argument.type !==
|
|
7905
|
+
if (argument === void 0 || argument.type !== import_utils52.AST_NODE_TYPES.ArrayExpression || sourceCode.getCommentsInside(argument).length > 0) {
|
|
7763
7906
|
return void 0;
|
|
7764
7907
|
}
|
|
7765
7908
|
const callee = node.callee;
|
|
7766
|
-
if (callee.type !==
|
|
7909
|
+
if (callee.type !== import_utils52.AST_NODE_TYPES.MemberExpression || callee.property.type !== import_utils52.AST_NODE_TYPES.Identifier) {
|
|
7767
7910
|
return void 0;
|
|
7768
7911
|
}
|
|
7769
7912
|
return (fixer) => [
|
|
@@ -7780,7 +7923,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
7780
7923
|
return;
|
|
7781
7924
|
}
|
|
7782
7925
|
for (const specifier of node.specifiers) {
|
|
7783
|
-
if (specifier.type ===
|
|
7926
|
+
if (specifier.type === import_utils52.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils52.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils52.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils52.AST_NODE_TYPES.Identifier && specifier.imported.name === "z") {
|
|
7784
7927
|
zodNamespaces.add(specifier.local.name);
|
|
7785
7928
|
}
|
|
7786
7929
|
}
|
|
@@ -7802,7 +7945,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
7802
7945
|
});
|
|
7803
7946
|
|
|
7804
7947
|
// src/rules/prefer-zod-infer.ts
|
|
7805
|
-
var
|
|
7948
|
+
var import_utils53 = require("@typescript-eslint/utils");
|
|
7806
7949
|
var SHAPE_PRESERVING_METHODS = /* @__PURE__ */ new Set([
|
|
7807
7950
|
"describe",
|
|
7808
7951
|
"refine",
|
|
@@ -7839,44 +7982,44 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
7839
7982
|
"Schema"
|
|
7840
7983
|
]);
|
|
7841
7984
|
var LEAF_NODE_TYPES = {
|
|
7842
|
-
string: [
|
|
7843
|
-
email: [
|
|
7844
|
-
url: [
|
|
7845
|
-
uuid: [
|
|
7846
|
-
ulid: [
|
|
7847
|
-
cuid: [
|
|
7848
|
-
cuid2: [
|
|
7849
|
-
nanoid: [
|
|
7850
|
-
iso: [
|
|
7851
|
-
number: [
|
|
7852
|
-
int: [
|
|
7853
|
-
float32: [
|
|
7854
|
-
float64: [
|
|
7855
|
-
boolean: [
|
|
7856
|
-
bigint: [
|
|
7857
|
-
symbol: [
|
|
7858
|
-
any: [
|
|
7859
|
-
unknown: [
|
|
7860
|
-
never: [
|
|
7861
|
-
void: [
|
|
7862
|
-
null: [
|
|
7863
|
-
undefined: [
|
|
7864
|
-
literal: [
|
|
7865
|
-
date: [
|
|
7866
|
-
array: [
|
|
7867
|
-
tuple: [
|
|
7868
|
-
object: [
|
|
7869
|
-
strictObject: [
|
|
7870
|
-
looseObject: [
|
|
7871
|
-
record: [
|
|
7872
|
-
map: [
|
|
7873
|
-
set: [
|
|
7874
|
-
promise: [
|
|
7875
|
-
enum: [
|
|
7876
|
-
nativeEnum: [
|
|
7877
|
-
union: [
|
|
7878
|
-
discriminatedUnion: [
|
|
7879
|
-
intersection: [
|
|
7985
|
+
string: [import_utils53.AST_NODE_TYPES.TSStringKeyword],
|
|
7986
|
+
email: [import_utils53.AST_NODE_TYPES.TSStringKeyword],
|
|
7987
|
+
url: [import_utils53.AST_NODE_TYPES.TSStringKeyword],
|
|
7988
|
+
uuid: [import_utils53.AST_NODE_TYPES.TSStringKeyword],
|
|
7989
|
+
ulid: [import_utils53.AST_NODE_TYPES.TSStringKeyword],
|
|
7990
|
+
cuid: [import_utils53.AST_NODE_TYPES.TSStringKeyword],
|
|
7991
|
+
cuid2: [import_utils53.AST_NODE_TYPES.TSStringKeyword],
|
|
7992
|
+
nanoid: [import_utils53.AST_NODE_TYPES.TSStringKeyword],
|
|
7993
|
+
iso: [import_utils53.AST_NODE_TYPES.TSStringKeyword],
|
|
7994
|
+
number: [import_utils53.AST_NODE_TYPES.TSNumberKeyword],
|
|
7995
|
+
int: [import_utils53.AST_NODE_TYPES.TSNumberKeyword],
|
|
7996
|
+
float32: [import_utils53.AST_NODE_TYPES.TSNumberKeyword],
|
|
7997
|
+
float64: [import_utils53.AST_NODE_TYPES.TSNumberKeyword],
|
|
7998
|
+
boolean: [import_utils53.AST_NODE_TYPES.TSBooleanKeyword],
|
|
7999
|
+
bigint: [import_utils53.AST_NODE_TYPES.TSBigIntKeyword],
|
|
8000
|
+
symbol: [import_utils53.AST_NODE_TYPES.TSSymbolKeyword],
|
|
8001
|
+
any: [import_utils53.AST_NODE_TYPES.TSAnyKeyword],
|
|
8002
|
+
unknown: [import_utils53.AST_NODE_TYPES.TSUnknownKeyword],
|
|
8003
|
+
never: [import_utils53.AST_NODE_TYPES.TSNeverKeyword],
|
|
8004
|
+
void: [import_utils53.AST_NODE_TYPES.TSVoidKeyword],
|
|
8005
|
+
null: [import_utils53.AST_NODE_TYPES.TSNullKeyword],
|
|
8006
|
+
undefined: [import_utils53.AST_NODE_TYPES.TSUndefinedKeyword],
|
|
8007
|
+
literal: [import_utils53.AST_NODE_TYPES.TSLiteralType],
|
|
8008
|
+
date: [import_utils53.AST_NODE_TYPES.TSTypeReference],
|
|
8009
|
+
array: [import_utils53.AST_NODE_TYPES.TSArrayType, import_utils53.AST_NODE_TYPES.TSTypeReference],
|
|
8010
|
+
tuple: [import_utils53.AST_NODE_TYPES.TSTupleType],
|
|
8011
|
+
object: [import_utils53.AST_NODE_TYPES.TSTypeLiteral, import_utils53.AST_NODE_TYPES.TSTypeReference],
|
|
8012
|
+
strictObject: [import_utils53.AST_NODE_TYPES.TSTypeLiteral, import_utils53.AST_NODE_TYPES.TSTypeReference],
|
|
8013
|
+
looseObject: [import_utils53.AST_NODE_TYPES.TSTypeLiteral, import_utils53.AST_NODE_TYPES.TSTypeReference],
|
|
8014
|
+
record: [import_utils53.AST_NODE_TYPES.TSTypeReference, import_utils53.AST_NODE_TYPES.TSTypeLiteral],
|
|
8015
|
+
map: [import_utils53.AST_NODE_TYPES.TSTypeReference],
|
|
8016
|
+
set: [import_utils53.AST_NODE_TYPES.TSTypeReference],
|
|
8017
|
+
promise: [import_utils53.AST_NODE_TYPES.TSTypeReference],
|
|
8018
|
+
enum: [import_utils53.AST_NODE_TYPES.TSUnionType, import_utils53.AST_NODE_TYPES.TSTypeReference, import_utils53.AST_NODE_TYPES.TSLiteralType],
|
|
8019
|
+
nativeEnum: [import_utils53.AST_NODE_TYPES.TSUnionType, import_utils53.AST_NODE_TYPES.TSTypeReference, import_utils53.AST_NODE_TYPES.TSLiteralType],
|
|
8020
|
+
union: [import_utils53.AST_NODE_TYPES.TSUnionType, import_utils53.AST_NODE_TYPES.TSTypeReference],
|
|
8021
|
+
discriminatedUnion: [import_utils53.AST_NODE_TYPES.TSUnionType, import_utils53.AST_NODE_TYPES.TSTypeReference],
|
|
8022
|
+
intersection: [import_utils53.AST_NODE_TYPES.TSIntersectionType, import_utils53.AST_NODE_TYPES.TSTypeReference]
|
|
7880
8023
|
};
|
|
7881
8024
|
function normalizeSchemaName(name) {
|
|
7882
8025
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -7885,20 +8028,20 @@ function normalizeTypeName(name) {
|
|
|
7885
8028
|
return name.replace(/Type$/, "").toLowerCase();
|
|
7886
8029
|
}
|
|
7887
8030
|
function unwrapNullish(annotation) {
|
|
7888
|
-
if (annotation.type !==
|
|
8031
|
+
if (annotation.type !== import_utils53.AST_NODE_TYPES.TSUnionType) {
|
|
7889
8032
|
return {
|
|
7890
8033
|
core: annotation,
|
|
7891
|
-
nullable: annotation.type ===
|
|
8034
|
+
nullable: annotation.type === import_utils53.AST_NODE_TYPES.TSNullKeyword
|
|
7892
8035
|
};
|
|
7893
8036
|
}
|
|
7894
8037
|
const rest = [];
|
|
7895
8038
|
let nullable = false;
|
|
7896
8039
|
for (const member of annotation.types) {
|
|
7897
|
-
if (member.type ===
|
|
8040
|
+
if (member.type === import_utils53.AST_NODE_TYPES.TSNullKeyword) {
|
|
7898
8041
|
nullable = true;
|
|
7899
8042
|
continue;
|
|
7900
8043
|
}
|
|
7901
|
-
if (member.type ===
|
|
8044
|
+
if (member.type === import_utils53.AST_NODE_TYPES.TSUndefinedKeyword) {
|
|
7902
8045
|
continue;
|
|
7903
8046
|
}
|
|
7904
8047
|
rest.push(member);
|
|
@@ -7963,14 +8106,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
7963
8106
|
function zodCallChain(node) {
|
|
7964
8107
|
const chain = [];
|
|
7965
8108
|
let current = node;
|
|
7966
|
-
while (current.type ===
|
|
8109
|
+
while (current.type === import_utils53.AST_NODE_TYPES.CallExpression) {
|
|
7967
8110
|
const callee = current.callee;
|
|
7968
|
-
if (callee.type !==
|
|
8111
|
+
if (callee.type !== import_utils53.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils53.AST_NODE_TYPES.Identifier) {
|
|
7969
8112
|
return null;
|
|
7970
8113
|
}
|
|
7971
8114
|
chain.push(current);
|
|
7972
8115
|
const receiver = callee.object;
|
|
7973
|
-
if (receiver.type ===
|
|
8116
|
+
if (receiver.type === import_utils53.AST_NODE_TYPES.Identifier) {
|
|
7974
8117
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
7975
8118
|
}
|
|
7976
8119
|
current = receiver;
|
|
@@ -7979,19 +8122,19 @@ var prefer_zod_infer_default = createRule({
|
|
|
7979
8122
|
}
|
|
7980
8123
|
function methodName(call) {
|
|
7981
8124
|
const callee = call.callee;
|
|
7982
|
-
return callee.type ===
|
|
8125
|
+
return callee.type === import_utils53.AST_NODE_TYPES.MemberExpression && callee.property.type === import_utils53.AST_NODE_TYPES.Identifier ? callee.property.name : "";
|
|
7983
8126
|
}
|
|
7984
8127
|
function schemaField(node) {
|
|
7985
8128
|
const modifiers = [];
|
|
7986
8129
|
let current = node;
|
|
7987
8130
|
let leaf = null;
|
|
7988
|
-
while (current.type ===
|
|
8131
|
+
while (current.type === import_utils53.AST_NODE_TYPES.CallExpression) {
|
|
7989
8132
|
const callee = current.callee;
|
|
7990
|
-
if (callee.type !==
|
|
8133
|
+
if (callee.type !== import_utils53.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils53.AST_NODE_TYPES.Identifier) {
|
|
7991
8134
|
break;
|
|
7992
8135
|
}
|
|
7993
8136
|
const receiver = callee.object;
|
|
7994
|
-
if (receiver.type ===
|
|
8137
|
+
if (receiver.type === import_utils53.AST_NODE_TYPES.Identifier && zodNamespaces.has(receiver.name)) {
|
|
7995
8138
|
leaf = callee.property.name;
|
|
7996
8139
|
break;
|
|
7997
8140
|
}
|
|
@@ -8022,16 +8165,16 @@ var prefer_zod_infer_default = createRule({
|
|
|
8022
8165
|
return null;
|
|
8023
8166
|
}
|
|
8024
8167
|
const shape = base.arguments[0];
|
|
8025
|
-
if (shape === void 0 || shape.type !==
|
|
8168
|
+
if (shape === void 0 || shape.type !== import_utils53.AST_NODE_TYPES.ObjectExpression) {
|
|
8026
8169
|
return null;
|
|
8027
8170
|
}
|
|
8028
8171
|
const fields = /* @__PURE__ */ new Map();
|
|
8029
8172
|
for (const property of shape.properties) {
|
|
8030
|
-
if (property.type !==
|
|
8173
|
+
if (property.type !== import_utils53.AST_NODE_TYPES.Property || property.computed) {
|
|
8031
8174
|
return null;
|
|
8032
8175
|
}
|
|
8033
8176
|
const { key } = property;
|
|
8034
|
-
const name = key.type ===
|
|
8177
|
+
const name = key.type === import_utils53.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils53.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
8035
8178
|
if (name === null) {
|
|
8036
8179
|
return null;
|
|
8037
8180
|
}
|
|
@@ -8042,11 +8185,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
8042
8185
|
function typeMembers(members) {
|
|
8043
8186
|
const result = /* @__PURE__ */ new Map();
|
|
8044
8187
|
for (const member of members) {
|
|
8045
|
-
if (member.type !==
|
|
8188
|
+
if (member.type !== import_utils53.AST_NODE_TYPES.TSPropertySignature || member.computed) {
|
|
8046
8189
|
return null;
|
|
8047
8190
|
}
|
|
8048
8191
|
const { key } = member;
|
|
8049
|
-
const name = key.type ===
|
|
8192
|
+
const name = key.type === import_utils53.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils53.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
8050
8193
|
if (name === null) {
|
|
8051
8194
|
return null;
|
|
8052
8195
|
}
|
|
@@ -8060,8 +8203,8 @@ var prefer_zod_infer_default = createRule({
|
|
|
8060
8203
|
return result.size === 0 ? null : result;
|
|
8061
8204
|
}
|
|
8062
8205
|
function collectConstrainedNames(node) {
|
|
8063
|
-
if (node.type ===
|
|
8064
|
-
if (node.typeName.type ===
|
|
8206
|
+
if (node.type === import_utils53.AST_NODE_TYPES.TSTypeReference) {
|
|
8207
|
+
if (node.typeName.type === import_utils53.AST_NODE_TYPES.Identifier) {
|
|
8065
8208
|
constrainedTypeNames.add(node.typeName.name);
|
|
8066
8209
|
}
|
|
8067
8210
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -8069,11 +8212,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
8069
8212
|
}
|
|
8070
8213
|
return;
|
|
8071
8214
|
}
|
|
8072
|
-
if (node.type ===
|
|
8215
|
+
if (node.type === import_utils53.AST_NODE_TYPES.TSArrayType) {
|
|
8073
8216
|
collectConstrainedNames(node.elementType);
|
|
8074
8217
|
return;
|
|
8075
8218
|
}
|
|
8076
|
-
if (node.type ===
|
|
8219
|
+
if (node.type === import_utils53.AST_NODE_TYPES.TSUnionType || node.type === import_utils53.AST_NODE_TYPES.TSIntersectionType) {
|
|
8077
8220
|
for (const member of node.types) {
|
|
8078
8221
|
collectConstrainedNames(member);
|
|
8079
8222
|
}
|
|
@@ -8117,13 +8260,13 @@ var prefer_zod_infer_default = createRule({
|
|
|
8117
8260
|
return;
|
|
8118
8261
|
}
|
|
8119
8262
|
for (const specifier of node.specifiers) {
|
|
8120
|
-
if (specifier.type ===
|
|
8263
|
+
if (specifier.type === import_utils53.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils53.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils53.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils53.AST_NODE_TYPES.Identifier && specifier.imported.name === "z") {
|
|
8121
8264
|
zodNamespaces.add(specifier.local.name);
|
|
8122
8265
|
}
|
|
8123
8266
|
}
|
|
8124
8267
|
},
|
|
8125
8268
|
VariableDeclarator(node) {
|
|
8126
|
-
if (node.id.type !==
|
|
8269
|
+
if (node.id.type !== import_utils53.AST_NODE_TYPES.Identifier || node.init == null) {
|
|
8127
8270
|
return;
|
|
8128
8271
|
}
|
|
8129
8272
|
const fields = schemaFields(node.init);
|
|
@@ -8133,14 +8276,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
8133
8276
|
},
|
|
8134
8277
|
/** Guard (f): `XSchema.transform(...)` anywhere in the module. */
|
|
8135
8278
|
"MemberExpression[computed=false]"(node) {
|
|
8136
|
-
if (node.object.type ===
|
|
8279
|
+
if (node.object.type === import_utils53.AST_NODE_TYPES.Identifier && node.property.type === import_utils53.AST_NODE_TYPES.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
8137
8280
|
reshapedSchemaNames.add(node.object.name);
|
|
8138
8281
|
}
|
|
8139
8282
|
},
|
|
8140
8283
|
/** Guard (c): `z.ZodType<T>` and every other type argument it carries. */
|
|
8141
8284
|
TSTypeReference(node) {
|
|
8142
8285
|
const { typeName } = node;
|
|
8143
|
-
const referenced = typeName.type ===
|
|
8286
|
+
const referenced = typeName.type === import_utils53.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils53.AST_NODE_TYPES.TSQualifiedName && typeName.right.type === import_utils53.AST_NODE_TYPES.Identifier ? typeName.right.name : null;
|
|
8144
8287
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
8145
8288
|
return;
|
|
8146
8289
|
}
|
|
@@ -8158,7 +8301,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
8158
8301
|
}
|
|
8159
8302
|
},
|
|
8160
8303
|
TSTypeAliasDeclaration(node) {
|
|
8161
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
8304
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== import_utils53.AST_NODE_TYPES.TSTypeLiteral) {
|
|
8162
8305
|
return;
|
|
8163
8306
|
}
|
|
8164
8307
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -8203,36 +8346,36 @@ var prefer_zod_infer_default = createRule({
|
|
|
8203
8346
|
});
|
|
8204
8347
|
|
|
8205
8348
|
// src/rules/require-assert-never.ts
|
|
8206
|
-
var
|
|
8349
|
+
var import_utils54 = require("@typescript-eslint/utils");
|
|
8207
8350
|
var isAssertNeverCall = (expression) => {
|
|
8208
|
-
if (expression.type !==
|
|
8351
|
+
if (expression.type !== import_utils54.AST_NODE_TYPES.CallExpression) return false;
|
|
8209
8352
|
const callee = expression.callee;
|
|
8210
|
-
if (callee.type ===
|
|
8353
|
+
if (callee.type === import_utils54.AST_NODE_TYPES.Identifier) {
|
|
8211
8354
|
return callee.name === "assertNever";
|
|
8212
8355
|
}
|
|
8213
|
-
if (callee.type ===
|
|
8356
|
+
if (callee.type === import_utils54.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils54.AST_NODE_TYPES.Identifier) {
|
|
8214
8357
|
return callee.property.name === "assertNever";
|
|
8215
8358
|
}
|
|
8216
8359
|
return false;
|
|
8217
8360
|
};
|
|
8218
8361
|
var statementContainsAssertNever = (statement) => {
|
|
8219
|
-
if (statement.type ===
|
|
8362
|
+
if (statement.type === import_utils54.AST_NODE_TYPES.ExpressionStatement) {
|
|
8220
8363
|
return isAssertNeverCall(statement.expression);
|
|
8221
8364
|
}
|
|
8222
|
-
if (statement.type ===
|
|
8365
|
+
if (statement.type === import_utils54.AST_NODE_TYPES.ThrowStatement) {
|
|
8223
8366
|
return isAssertNeverCall(statement.argument);
|
|
8224
8367
|
}
|
|
8225
|
-
if (statement.type ===
|
|
8368
|
+
if (statement.type === import_utils54.AST_NODE_TYPES.ReturnStatement) {
|
|
8226
8369
|
return statement.argument !== null && isAssertNeverCall(statement.argument);
|
|
8227
8370
|
}
|
|
8228
|
-
if (statement.type ===
|
|
8371
|
+
if (statement.type === import_utils54.AST_NODE_TYPES.BlockStatement) {
|
|
8229
8372
|
return statement.body.some(statementContainsAssertNever);
|
|
8230
8373
|
}
|
|
8231
8374
|
return false;
|
|
8232
8375
|
};
|
|
8233
8376
|
var isRuntimeHandlingStatement = (statement) => {
|
|
8234
|
-
if (statement.type ===
|
|
8235
|
-
if (statement.type ===
|
|
8377
|
+
if (statement.type === import_utils54.AST_NODE_TYPES.EmptyStatement) return false;
|
|
8378
|
+
if (statement.type === import_utils54.AST_NODE_TYPES.BlockStatement) {
|
|
8236
8379
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
8237
8380
|
}
|
|
8238
8381
|
return true;
|
|
@@ -8248,7 +8391,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
8248
8391
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
8249
8392
|
}
|
|
8250
8393
|
const only = defaultCase.consequent[0];
|
|
8251
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
8394
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === import_utils54.AST_NODE_TYPES.BlockStatement && only.body.length === 0) {
|
|
8252
8395
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
8253
8396
|
}
|
|
8254
8397
|
return false;
|
|
@@ -8289,7 +8432,7 @@ var require_assert_never_default = createRule({
|
|
|
8289
8432
|
});
|
|
8290
8433
|
|
|
8291
8434
|
// src/rules/require-fetch-timeout.ts
|
|
8292
|
-
var
|
|
8435
|
+
var import_utils55 = require("@typescript-eslint/utils");
|
|
8293
8436
|
var CODEMOD_FIXTURE_RE = /[\\/]__testfixtures__[\\/]/;
|
|
8294
8437
|
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set([
|
|
8295
8438
|
"globalThis",
|
|
@@ -8306,14 +8449,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
8306
8449
|
return false;
|
|
8307
8450
|
}
|
|
8308
8451
|
function initProvablyLacksSignal(init) {
|
|
8309
|
-
if (init.type !==
|
|
8452
|
+
if (init.type !== import_utils55.AST_NODE_TYPES.ObjectExpression) {
|
|
8310
8453
|
return false;
|
|
8311
8454
|
}
|
|
8312
8455
|
for (const prop of init.properties) {
|
|
8313
|
-
if (prop.type ===
|
|
8456
|
+
if (prop.type === import_utils55.AST_NODE_TYPES.SpreadElement) {
|
|
8314
8457
|
return false;
|
|
8315
8458
|
}
|
|
8316
|
-
if (prop.key.type ===
|
|
8459
|
+
if (prop.key.type === import_utils55.AST_NODE_TYPES.Identifier && prop.key.name === "signal" || prop.key.type === import_utils55.AST_NODE_TYPES.Literal && prop.key.value === "signal") {
|
|
8317
8460
|
return false;
|
|
8318
8461
|
}
|
|
8319
8462
|
if (prop.computed) {
|
|
@@ -8323,7 +8466,7 @@ function initProvablyLacksSignal(init) {
|
|
|
8323
8466
|
return true;
|
|
8324
8467
|
}
|
|
8325
8468
|
function isStringish(node) {
|
|
8326
|
-
return node.type ===
|
|
8469
|
+
return node.type === import_utils55.AST_NODE_TYPES.Literal && typeof node.value === "string" || node.type === import_utils55.AST_NODE_TYPES.TemplateLiteral;
|
|
8327
8470
|
}
|
|
8328
8471
|
var require_fetch_timeout_default = createRule({
|
|
8329
8472
|
name: "require-fetch-timeout",
|
|
@@ -8360,14 +8503,14 @@ var require_fetch_timeout_default = createRule({
|
|
|
8360
8503
|
}
|
|
8361
8504
|
function resolvesToGlobal(identifier) {
|
|
8362
8505
|
const scope = context.sourceCode.getScope(identifier);
|
|
8363
|
-
const variable =
|
|
8506
|
+
const variable = import_utils55.ASTUtils.findVariable(scope, identifier.name);
|
|
8364
8507
|
return variable === null || variable.defs.length === 0;
|
|
8365
8508
|
}
|
|
8366
8509
|
function isGlobalFetchCall2(callee) {
|
|
8367
|
-
if (callee.type ===
|
|
8510
|
+
if (callee.type === import_utils55.AST_NODE_TYPES.Identifier) {
|
|
8368
8511
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
8369
8512
|
}
|
|
8370
|
-
return callee.type ===
|
|
8513
|
+
return callee.type === import_utils55.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils55.AST_NODE_TYPES.Identifier && callee.property.name === "fetch" && callee.object.type === import_utils55.AST_NODE_TYPES.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
8371
8514
|
}
|
|
8372
8515
|
return {
|
|
8373
8516
|
CallExpression(node) {
|
|
@@ -8387,26 +8530,26 @@ var require_fetch_timeout_default = createRule({
|
|
|
8387
8530
|
});
|
|
8388
8531
|
|
|
8389
8532
|
// src/rules/require-interface-for-injected-service.ts
|
|
8390
|
-
var
|
|
8533
|
+
var import_utils56 = require("@typescript-eslint/utils");
|
|
8391
8534
|
var CONFIGISH_TYPE_RE = /(?:Options|Opts|Config|Configuration|Settings|Params|Props|Args|Env|Environment|Callbacks|Flags)$/;
|
|
8392
8535
|
var CONFIGISH_NAME_RE = /^(?:options|opts|config|configuration|settings|params|props|args|env|environment|callbacks|flags|logger|log|clock)$/i;
|
|
8393
8536
|
var HTTP_TRANSPORT_TYPE_RE = /^(?:KyInstance|AxiosInstance|Session)$/;
|
|
8394
8537
|
var TRANSPORT_WRAPPER_NAME_RE = /Client$/;
|
|
8395
8538
|
var ROUTER_FACTORY_NAME = "Router";
|
|
8396
8539
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
8397
|
-
var isExportedClass = (node) => node.parent.type ===
|
|
8398
|
-
var qualifiedName = (name) => name.type ===
|
|
8540
|
+
var isExportedClass = (node) => node.parent.type === import_utils56.AST_NODE_TYPES.ExportNamedDeclaration || node.parent.type === import_utils56.AST_NODE_TYPES.ExportDefaultDeclaration;
|
|
8541
|
+
var qualifiedName = (name) => name.type === import_utils56.AST_NODE_TYPES.Identifier ? name.name : name.type === import_utils56.AST_NODE_TYPES.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
8399
8542
|
var typeReferenceName = (annotated) => {
|
|
8400
8543
|
let target = annotated;
|
|
8401
|
-
if (target.type ===
|
|
8402
|
-
if (target.type ===
|
|
8403
|
-
if (target.type !==
|
|
8544
|
+
if (target.type === import_utils56.AST_NODE_TYPES.TSParameterProperty) target = target.parameter;
|
|
8545
|
+
if (target.type === import_utils56.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
8546
|
+
if (target.type !== import_utils56.AST_NODE_TYPES.Identifier) return null;
|
|
8404
8547
|
const annotation = target.typeAnnotation?.typeAnnotation;
|
|
8405
|
-
if (annotation === void 0 || annotation.type !==
|
|
8548
|
+
if (annotation === void 0 || annotation.type !== import_utils56.AST_NODE_TYPES.TSTypeReference) {
|
|
8406
8549
|
return null;
|
|
8407
8550
|
}
|
|
8408
8551
|
const { typeName } = annotation;
|
|
8409
|
-
const rightmost = typeName.type ===
|
|
8552
|
+
const rightmost = typeName.type === import_utils56.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils56.AST_NODE_TYPES.TSQualifiedName ? typeName.right.name : null;
|
|
8410
8553
|
if (rightmost === null) return null;
|
|
8411
8554
|
return { name: target.name, typeName: rightmost, display: qualifiedName(typeName) };
|
|
8412
8555
|
};
|
|
@@ -8416,17 +8559,17 @@ var readConstructor = (ctor) => {
|
|
|
8416
8559
|
let constructedFields = 0;
|
|
8417
8560
|
if (body !== null && body !== void 0) {
|
|
8418
8561
|
for (const statement of body.body) {
|
|
8419
|
-
if (statement.type !==
|
|
8562
|
+
if (statement.type !== import_utils56.AST_NODE_TYPES.ExpressionStatement) continue;
|
|
8420
8563
|
const expression = statement.expression;
|
|
8421
|
-
if (expression.type !==
|
|
8564
|
+
if (expression.type !== import_utils56.AST_NODE_TYPES.AssignmentExpression || expression.operator !== "=" || expression.left.type !== import_utils56.AST_NODE_TYPES.MemberExpression || expression.left.object.type !== import_utils56.AST_NODE_TYPES.ThisExpression) {
|
|
8422
8565
|
continue;
|
|
8423
8566
|
}
|
|
8424
8567
|
const source = expression.right;
|
|
8425
|
-
if (source.type ===
|
|
8568
|
+
if (source.type === import_utils56.AST_NODE_TYPES.NewExpression) {
|
|
8426
8569
|
constructedFields += 1;
|
|
8427
|
-
} else if (source.type ===
|
|
8570
|
+
} else if (source.type === import_utils56.AST_NODE_TYPES.Identifier) {
|
|
8428
8571
|
storedFrom.add(source.name);
|
|
8429
|
-
} else if (source.type ===
|
|
8572
|
+
} else if (source.type === import_utils56.AST_NODE_TYPES.MemberExpression && source.object.type === import_utils56.AST_NODE_TYPES.Identifier) {
|
|
8430
8573
|
storedFrom.add(source.object.name);
|
|
8431
8574
|
}
|
|
8432
8575
|
}
|
|
@@ -8435,7 +8578,7 @@ var readConstructor = (ctor) => {
|
|
|
8435
8578
|
for (const parameter of ctor.value.params) {
|
|
8436
8579
|
const reference = typeReferenceName(parameter);
|
|
8437
8580
|
if (reference === null) continue;
|
|
8438
|
-
const stored = parameter.type ===
|
|
8581
|
+
const stored = parameter.type === import_utils56.AST_NODE_TYPES.TSParameterProperty || storedFrom.has(reference.name);
|
|
8439
8582
|
if (!stored) continue;
|
|
8440
8583
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
8441
8584
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -8465,19 +8608,19 @@ var subtreeHas = (root, found) => {
|
|
|
8465
8608
|
return hit;
|
|
8466
8609
|
};
|
|
8467
8610
|
var isFrameworkWiring = (body) => subtreeHas(body, (node) => {
|
|
8468
|
-
if (node.type ===
|
|
8611
|
+
if (node.type === import_utils56.AST_NODE_TYPES.CallExpression) {
|
|
8469
8612
|
const { callee } = node;
|
|
8470
|
-
if (callee.type ===
|
|
8471
|
-
return callee.type ===
|
|
8613
|
+
if (callee.type === import_utils56.AST_NODE_TYPES.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
8614
|
+
return callee.type === import_utils56.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils56.AST_NODE_TYPES.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
8472
8615
|
}
|
|
8473
|
-
return node.type ===
|
|
8616
|
+
return node.type === import_utils56.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils56.AST_NODE_TYPES.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
8474
8617
|
});
|
|
8475
8618
|
var stem2 = (name) => name.replace(/^I(?=[A-Z])/, "").replace(/Impl$/, "");
|
|
8476
8619
|
var fileInterfaceNames = (program) => {
|
|
8477
8620
|
const names = [];
|
|
8478
8621
|
for (const statement of program.body) {
|
|
8479
|
-
const declaration = statement.type ===
|
|
8480
|
-
if (declaration?.type ===
|
|
8622
|
+
const declaration = statement.type === import_utils56.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
8623
|
+
if (declaration?.type === import_utils56.AST_NODE_TYPES.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
8481
8624
|
}
|
|
8482
8625
|
return names;
|
|
8483
8626
|
};
|
|
@@ -8495,11 +8638,11 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
8495
8638
|
var publicMethodNames = (body) => {
|
|
8496
8639
|
const names = [];
|
|
8497
8640
|
for (const member of body.body) {
|
|
8498
|
-
if (member.type !==
|
|
8641
|
+
if (member.type !== import_utils56.AST_NODE_TYPES.MethodDefinition) continue;
|
|
8499
8642
|
if (member.kind !== "method" || member.static) continue;
|
|
8500
8643
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
8501
|
-
if (member.key.type ===
|
|
8502
|
-
if (member.key.type ===
|
|
8644
|
+
if (member.key.type === import_utils56.AST_NODE_TYPES.PrivateIdentifier) continue;
|
|
8645
|
+
if (member.key.type === import_utils56.AST_NODE_TYPES.Identifier) names.push(member.key.name);
|
|
8503
8646
|
else names.push("\u2026");
|
|
8504
8647
|
}
|
|
8505
8648
|
return names;
|
|
@@ -8530,7 +8673,7 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
8530
8673
|
if (node.implements.length > 0) return;
|
|
8531
8674
|
if (node.decorators.length > 0) return;
|
|
8532
8675
|
const ctor = node.body.body.find(
|
|
8533
|
-
(member) => member.type ===
|
|
8676
|
+
(member) => member.type === import_utils56.AST_NODE_TYPES.MethodDefinition && member.kind === "constructor"
|
|
8534
8677
|
);
|
|
8535
8678
|
if (ctor === void 0) return;
|
|
8536
8679
|
const { collaborators, constructedFields } = readConstructor(ctor);
|
|
@@ -8555,18 +8698,18 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
8555
8698
|
});
|
|
8556
8699
|
|
|
8557
8700
|
// src/rules/require-zod-form-validation.ts
|
|
8558
|
-
var
|
|
8701
|
+
var import_utils57 = require("@typescript-eslint/utils");
|
|
8559
8702
|
var looksLikeZodSchema = (node) => {
|
|
8560
8703
|
let current = node;
|
|
8561
8704
|
while (true) {
|
|
8562
|
-
if (current.type ===
|
|
8705
|
+
if (current.type === import_utils57.AST_NODE_TYPES.Identifier) {
|
|
8563
8706
|
return current.name === "z" || ZOD_SCHEMA_NAME_RE.test(current.name);
|
|
8564
8707
|
}
|
|
8565
|
-
if (current.type ===
|
|
8708
|
+
if (current.type === import_utils57.AST_NODE_TYPES.CallExpression) {
|
|
8566
8709
|
current = current.callee;
|
|
8567
8710
|
continue;
|
|
8568
8711
|
}
|
|
8569
|
-
if (current.type ===
|
|
8712
|
+
if (current.type === import_utils57.AST_NODE_TYPES.MemberExpression) {
|
|
8570
8713
|
current = current.object;
|
|
8571
8714
|
continue;
|
|
8572
8715
|
}
|
|
@@ -8574,23 +8717,23 @@ var looksLikeZodSchema = (node) => {
|
|
|
8574
8717
|
}
|
|
8575
8718
|
};
|
|
8576
8719
|
var isZodParseCall = (node) => {
|
|
8577
|
-
if (node.type !==
|
|
8720
|
+
if (node.type !== import_utils57.AST_NODE_TYPES.CallExpression) return false;
|
|
8578
8721
|
const callee = node.callee;
|
|
8579
|
-
if (callee.type !==
|
|
8722
|
+
if (callee.type !== import_utils57.AST_NODE_TYPES.MemberExpression) return false;
|
|
8580
8723
|
if (callee.computed) return false;
|
|
8581
|
-
if (callee.property.type !==
|
|
8724
|
+
if (callee.property.type !== import_utils57.AST_NODE_TYPES.Identifier) return false;
|
|
8582
8725
|
const method = callee.property.name;
|
|
8583
8726
|
if (method !== "parse" && method !== "safeParse") return false;
|
|
8584
8727
|
return looksLikeZodSchema(callee.object);
|
|
8585
8728
|
};
|
|
8586
8729
|
var isFormDataMethodCall = (node) => {
|
|
8587
8730
|
let current = node;
|
|
8588
|
-
if (current.type ===
|
|
8731
|
+
if (current.type === import_utils57.AST_NODE_TYPES.AwaitExpression) {
|
|
8589
8732
|
current = current.argument;
|
|
8590
8733
|
}
|
|
8591
|
-
if (current.type !==
|
|
8734
|
+
if (current.type !== import_utils57.AST_NODE_TYPES.CallExpression) return false;
|
|
8592
8735
|
const callee = current.callee;
|
|
8593
|
-
return callee.type ===
|
|
8736
|
+
return callee.type === import_utils57.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils57.AST_NODE_TYPES.Identifier && callee.property.name === "formData";
|
|
8594
8737
|
};
|
|
8595
8738
|
var require_zod_form_validation_default = createRule({
|
|
8596
8739
|
name: "require-zod-form-validation",
|
|
@@ -8610,14 +8753,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
8610
8753
|
return {};
|
|
8611
8754
|
}
|
|
8612
8755
|
const isFormSourceIdentifier = (node) => {
|
|
8613
|
-
if (node.type !==
|
|
8756
|
+
if (node.type !== import_utils57.AST_NODE_TYPES.Identifier) return false;
|
|
8614
8757
|
if (/formdata/i.test(node.name)) return true;
|
|
8615
8758
|
let scope = context.sourceCode.getScope(node);
|
|
8616
8759
|
while (scope !== null) {
|
|
8617
8760
|
const variable = scope.set.get(node.name);
|
|
8618
8761
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
8619
8762
|
const def = variable.defs[0];
|
|
8620
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
8763
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === import_utils57.AST_NODE_TYPES.VariableDeclarator && def.node.init !== null) {
|
|
8621
8764
|
return isFormDataMethodCall(def.node.init);
|
|
8622
8765
|
}
|
|
8623
8766
|
return false;
|
|
@@ -8628,8 +8771,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
8628
8771
|
};
|
|
8629
8772
|
const isFormDataGetCall = (node) => {
|
|
8630
8773
|
const callee = node.callee;
|
|
8631
|
-
if (callee.type !==
|
|
8632
|
-
if (callee.property.type !==
|
|
8774
|
+
if (callee.type !== import_utils57.AST_NODE_TYPES.MemberExpression) return false;
|
|
8775
|
+
if (callee.property.type !== import_utils57.AST_NODE_TYPES.Identifier || callee.property.name !== "get") {
|
|
8633
8776
|
return false;
|
|
8634
8777
|
}
|
|
8635
8778
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -8644,11 +8787,11 @@ var require_zod_form_validation_default = createRule({
|
|
|
8644
8787
|
};
|
|
8645
8788
|
const isInstanceofNarrowing = (node) => {
|
|
8646
8789
|
const parent = node.parent;
|
|
8647
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
8790
|
+
return parent !== null && parent !== void 0 && parent.type === import_utils57.AST_NODE_TYPES.BinaryExpression && parent.operator === "instanceof" && parent.left === node;
|
|
8648
8791
|
};
|
|
8649
8792
|
const boundDeclarator = (node) => {
|
|
8650
8793
|
const parent = node.parent;
|
|
8651
|
-
if (parent.type ===
|
|
8794
|
+
if (parent.type === import_utils57.AST_NODE_TYPES.VariableDeclarator && parent.init === node && parent.id.type === import_utils57.AST_NODE_TYPES.Identifier) {
|
|
8652
8795
|
return parent;
|
|
8653
8796
|
}
|
|
8654
8797
|
return null;
|
|
@@ -8676,7 +8819,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
8676
8819
|
});
|
|
8677
8820
|
|
|
8678
8821
|
// src/rules/store-insert-requires-on-conflict.ts
|
|
8679
|
-
var
|
|
8822
|
+
var import_utils58 = require("@typescript-eslint/utils");
|
|
8680
8823
|
var INSERT_WRITE = /\bINSERT\s+(?:OR\s+\w+\s+)?INTO\s+[\w."'`?$:@-]+\s*(?:\([^)]*\)\s*)?(?:VALUES|SELECT|DEFAULT\s+VALUES)\b/i;
|
|
8681
8824
|
var CONFLICT_HANDLED = /\bON\s+CONFLICT\b|\bON\s+DUPLICATE\s+KEY\b|\bINSERT\s+OR\s+(?:IGNORE|REPLACE)\b/i;
|
|
8682
8825
|
var INSERT_GATE = /insert/i;
|
|
@@ -8707,7 +8850,7 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
8707
8850
|
});
|
|
8708
8851
|
|
|
8709
8852
|
// src/rules/zod-naming-convention.ts
|
|
8710
|
-
var
|
|
8853
|
+
var import_utils59 = require("@typescript-eslint/utils");
|
|
8711
8854
|
var CONVENTIONS = {
|
|
8712
8855
|
prefix: { test: ZOD_PREFIX_RE, messageId: "zPrefix" },
|
|
8713
8856
|
suffix: { test: ZOD_SUFFIX_RE, messageId: "schemaSuffix" },
|
|
@@ -8732,15 +8875,15 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
8732
8875
|
"registry",
|
|
8733
8876
|
"implement"
|
|
8734
8877
|
]);
|
|
8735
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
8878
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === import_utils59.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
8736
8879
|
var calleeChainStartsWithZ = (node) => {
|
|
8737
8880
|
let current = node;
|
|
8738
|
-
while (current.type ===
|
|
8881
|
+
while (current.type === import_utils59.AST_NODE_TYPES.MemberExpression) {
|
|
8739
8882
|
const receiver = current.object;
|
|
8740
|
-
if (receiver.type ===
|
|
8883
|
+
if (receiver.type === import_utils59.AST_NODE_TYPES.Identifier && receiver.name === "z") {
|
|
8741
8884
|
return true;
|
|
8742
8885
|
}
|
|
8743
|
-
if (receiver.type ===
|
|
8886
|
+
if (receiver.type === import_utils59.AST_NODE_TYPES.CallExpression) {
|
|
8744
8887
|
current = receiver.callee;
|
|
8745
8888
|
continue;
|
|
8746
8889
|
}
|
|
@@ -8785,13 +8928,13 @@ var zod_naming_convention_default = createRule({
|
|
|
8785
8928
|
VariableDeclarator(node) {
|
|
8786
8929
|
const init = node.init;
|
|
8787
8930
|
if (init === null || init === void 0) return;
|
|
8788
|
-
if (init.type !==
|
|
8931
|
+
if (init.type !== import_utils59.AST_NODE_TYPES.CallExpression) return;
|
|
8789
8932
|
const callee = init.callee;
|
|
8790
|
-
if (callee.type !==
|
|
8933
|
+
if (callee.type !== import_utils59.AST_NODE_TYPES.MemberExpression) return;
|
|
8791
8934
|
if (!calleeChainStartsWithZ(callee)) return;
|
|
8792
8935
|
const terminal = terminalMethodName(callee);
|
|
8793
8936
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
8794
|
-
if (node.id.type !==
|
|
8937
|
+
if (node.id.type !== import_utils59.AST_NODE_TYPES.Identifier) return;
|
|
8795
8938
|
if (test.test(node.id.name)) return;
|
|
8796
8939
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
8797
8940
|
context.report({
|
|
@@ -8842,6 +8985,7 @@ var rules = {
|
|
|
8842
8985
|
"no-string-concat-in-loop": no_string_concat_in_loop_default,
|
|
8843
8986
|
"no-tautological-expect": no_tautological_expect_default,
|
|
8844
8987
|
"no-trailing-value-narration": no_trailing_value_narration_default,
|
|
8988
|
+
"no-declaration-comment-wall": no_declaration_comment_wall_default,
|
|
8845
8989
|
"no-type-member-comment-wall": no_type_member_comment_wall_default,
|
|
8846
8990
|
"no-unnecessary-use-client": no_unnecessary_use_client_default,
|
|
8847
8991
|
"no-unsafe-mock-casting": no_unsafe_mock_casting_default,
|
|
@@ -8867,7 +9011,7 @@ var rules = {
|
|
|
8867
9011
|
};
|
|
8868
9012
|
var meta = {
|
|
8869
9013
|
name: "@sarj/eslint-plugin",
|
|
8870
|
-
version: "7.
|
|
9014
|
+
version: "7.1.0"
|
|
8871
9015
|
};
|
|
8872
9016
|
var renames = renamedRules;
|
|
8873
9017
|
var deprecatedAliases = Object.fromEntries(
|
|
@@ -8916,6 +9060,7 @@ var recommendedRules = {
|
|
|
8916
9060
|
"@sarj/no-string-concat-in-loop": "warn",
|
|
8917
9061
|
"@sarj/no-tautological-expect": "warn",
|
|
8918
9062
|
"@sarj/no-trailing-value-narration": "warn",
|
|
9063
|
+
"@sarj/no-declaration-comment-wall": "warn",
|
|
8919
9064
|
"@sarj/no-type-member-comment-wall": "warn",
|
|
8920
9065
|
"@sarj/no-unnecessary-use-client": "warn",
|
|
8921
9066
|
"@sarj/no-unsafe-mock-casting": "warn",
|
|
@@ -8969,6 +9114,7 @@ var strictRules = {
|
|
|
8969
9114
|
"@sarj/no-string-concat-in-loop": "error",
|
|
8970
9115
|
"@sarj/no-tautological-expect": "error",
|
|
8971
9116
|
"@sarj/no-trailing-value-narration": "error",
|
|
9117
|
+
"@sarj/no-declaration-comment-wall": "error",
|
|
8972
9118
|
"@sarj/no-type-member-comment-wall": "error",
|
|
8973
9119
|
"@sarj/no-unnecessary-use-client": "error",
|
|
8974
9120
|
"@sarj/no-unsafe-mock-casting": "error",
|