@sarj/eslint-plugin 2.9.0 → 2.10.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/dist/index.cjs +245 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +554 -348
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -211,7 +211,7 @@ var no_client_side_data_fetching_default = ESLintUtils2.RuleCreator(
|
|
|
211
211
|
});
|
|
212
212
|
|
|
213
213
|
// src/rules/no-comment-cruft.ts
|
|
214
|
-
import { ESLintUtils as ESLintUtils3 } from "@typescript-eslint/utils";
|
|
214
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES3, ESLintUtils as ESLintUtils3 } from "@typescript-eslint/utils";
|
|
215
215
|
var LEADING_PREAMBLE_MIN = 4;
|
|
216
216
|
var STEP_NARRATION_RE = /^(?:first(?:ly)?|second(?:ly)?|third(?:ly)?|then|next|after(?:wards| that)?|finally|lastly|now)\s*[,:]\s*\S|^step\s+\d+\b/i;
|
|
217
217
|
var META_COMMENTARY_RE = /\b(?:for now|keeping (?:it|this) simple|could be (?:refactored|improved|cleaned up|simplified)|refactor(?:ed|ing)? (?:later|this)|not sure (?:if|whether|why|how)|quick[- ](?:and[- ]dirty|fix)|(?:a |bit of a )?hacky|is a hack|temporary (?:solution|workaround|fix|hack)|revisit (?:this|later|below)|clean (?:this|it) up|not ideal|placeholder for now)\b/i;
|
|
@@ -253,12 +253,115 @@ function isProse(text) {
|
|
|
253
253
|
}
|
|
254
254
|
return false;
|
|
255
255
|
}
|
|
256
|
-
|
|
256
|
+
var NARRATION_MAX_WORDS = 6;
|
|
257
|
+
var NARRATION_MIN_CONTENT = 1;
|
|
258
|
+
var TOKEN_PLURAL_MIN = 4;
|
|
259
|
+
var RESTATABLE_STATEMENTS = /* @__PURE__ */ new Set([
|
|
260
|
+
AST_NODE_TYPES3.ExpressionStatement,
|
|
261
|
+
AST_NODE_TYPES3.ReturnStatement,
|
|
262
|
+
AST_NODE_TYPES3.ThrowStatement,
|
|
263
|
+
AST_NODE_TYPES3.VariableDeclaration
|
|
264
|
+
]);
|
|
265
|
+
var NARRATION_VERB_RE = /^(?:add|append|assign|build|calculate|call|check|clear|close|compute|convert|copy|count|create|declare|decrement|define|delete|extract|fetch|filter|find|format|generate|get|handle|increment|init|initialise|initialize|insert|iterate|join|load|log|loop|make|map|merge|open|parse|print|process|push|read|remove|render|reset|return|save|send|set|setup|sort|split|start|stop|store|update|validate|wrap|write)(?:s|es|d|ed|ing)?$/i;
|
|
266
|
+
var NARRATION_STOPWORDS = /* @__PURE__ */ new Set([
|
|
267
|
+
"a",
|
|
268
|
+
"all",
|
|
269
|
+
"an",
|
|
270
|
+
"and",
|
|
271
|
+
"any",
|
|
272
|
+
"are",
|
|
273
|
+
"as",
|
|
274
|
+
"at",
|
|
275
|
+
"back",
|
|
276
|
+
"be",
|
|
277
|
+
"both",
|
|
278
|
+
"by",
|
|
279
|
+
"each",
|
|
280
|
+
"for",
|
|
281
|
+
"from",
|
|
282
|
+
"here",
|
|
283
|
+
"if",
|
|
284
|
+
"in",
|
|
285
|
+
"into",
|
|
286
|
+
"is",
|
|
287
|
+
"it",
|
|
288
|
+
"its",
|
|
289
|
+
"just",
|
|
290
|
+
"new",
|
|
291
|
+
"of",
|
|
292
|
+
"on",
|
|
293
|
+
"one",
|
|
294
|
+
"onto",
|
|
295
|
+
"or",
|
|
296
|
+
"our",
|
|
297
|
+
"out",
|
|
298
|
+
"over",
|
|
299
|
+
"so",
|
|
300
|
+
"that",
|
|
301
|
+
"the",
|
|
302
|
+
"then",
|
|
303
|
+
"this",
|
|
304
|
+
"to",
|
|
305
|
+
"up",
|
|
306
|
+
"us",
|
|
307
|
+
"we",
|
|
308
|
+
"when",
|
|
309
|
+
"with"
|
|
310
|
+
]);
|
|
311
|
+
function normalizeToken(word) {
|
|
312
|
+
const lower = word.toLowerCase();
|
|
313
|
+
return lower.length > TOKEN_PLURAL_MIN && lower.endsWith("s") && !lower.endsWith("ss") ? lower.slice(0, -1) : lower;
|
|
314
|
+
}
|
|
315
|
+
function codeTokens(source) {
|
|
316
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
317
|
+
for (const identifier of source.match(/[A-Za-z_$][\w$]*/g) ?? []) {
|
|
318
|
+
tokens.add(normalizeToken(identifier));
|
|
319
|
+
for (const part of identifier.split(/[_$]+|(?<=[a-z0-9])(?=[A-Z])/)) {
|
|
320
|
+
if (part.length > 0) tokens.add(normalizeToken(part));
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return tokens;
|
|
324
|
+
}
|
|
325
|
+
function isTrivialInitializer(node) {
|
|
326
|
+
return node.declarations.every((declarator) => {
|
|
327
|
+
const init = declarator.init;
|
|
328
|
+
if (init == null || init.type === AST_NODE_TYPES3.Literal) return true;
|
|
329
|
+
return init.type === AST_NODE_TYPES3.ArrayExpression && init.elements.length === 0 || init.type === AST_NODE_TYPES3.ObjectExpression && init.properties.length === 0;
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
function restatableStatementBelow(comment, sourceCode) {
|
|
333
|
+
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
334
|
+
if (token === null || token.loc.start.line !== comment.loc.end.line + 1) return null;
|
|
335
|
+
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !== AST_NODE_TYPES3.Program; node = node.parent) {
|
|
336
|
+
if (!RESTATABLE_STATEMENTS.has(node.type)) continue;
|
|
337
|
+
if (node.loc.start.line !== token.loc.start.line || node.loc.end.line !== node.loc.start.line) {
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
340
|
+
if (node.type === AST_NODE_TYPES3.VariableDeclaration && isTrivialInitializer(node)) {
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
return sourceCode.getText(node);
|
|
344
|
+
}
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
function restatesNextLine(body, statement) {
|
|
348
|
+
if (statement === null) return false;
|
|
349
|
+
const words = body.match(/[A-Za-z][\w$]*/g) ?? [];
|
|
350
|
+
const opener = words[0];
|
|
351
|
+
if (opener === void 0 || words.length > NARRATION_MAX_WORDS) return false;
|
|
352
|
+
if (!NARRATION_VERB_RE.test(opener)) return false;
|
|
353
|
+
const content = words.slice(1).map(normalizeToken).filter((word) => !NARRATION_STOPWORDS.has(word));
|
|
354
|
+
if (content.length < NARRATION_MIN_CONTENT) return false;
|
|
355
|
+
const head = statement.split("(")[0] ?? statement;
|
|
356
|
+
const code = codeTokens(head);
|
|
357
|
+
return content.every((word) => code.has(word));
|
|
358
|
+
}
|
|
359
|
+
function isRedundantNarration(body, statementBelow) {
|
|
257
360
|
const t = body.trim();
|
|
258
361
|
if (!t || looksLikeCode(t) || hasPseudocode(t)) return false;
|
|
259
362
|
if (STEP_NARRATION_RE.test(t)) return true;
|
|
260
363
|
if (META_COMMENTARY_RE.test(t)) return true;
|
|
261
|
-
return
|
|
364
|
+
return restatesNextLine(t, statementBelow);
|
|
262
365
|
}
|
|
263
366
|
function hasCommentedOutCode(texts, precedingProse) {
|
|
264
367
|
for (let i = 0; i < texts.length; i++) {
|
|
@@ -343,7 +446,8 @@ var no_comment_cruft_default = ESLintUtils3.RuleCreator(
|
|
|
343
446
|
}
|
|
344
447
|
if (comment.type === "Line" && texts.length === 1) {
|
|
345
448
|
const body = texts[0];
|
|
346
|
-
|
|
449
|
+
const statement = restatableStatementBelow(comment, sourceCode);
|
|
450
|
+
if (body !== void 0 && isRedundantNarration(body, statement)) {
|
|
347
451
|
context.report({ node: comment, messageId: "redundantNarration" });
|
|
348
452
|
}
|
|
349
453
|
}
|
|
@@ -990,13 +1094,13 @@ var no_raw_env_default = ESLintUtils8.RuleCreator(
|
|
|
990
1094
|
// src/rules/no-sentinel-return-on-catch.ts
|
|
991
1095
|
import {
|
|
992
1096
|
ESLintUtils as ESLintUtils9,
|
|
993
|
-
AST_NODE_TYPES as
|
|
1097
|
+
AST_NODE_TYPES as AST_NODE_TYPES4
|
|
994
1098
|
} from "@typescript-eslint/utils";
|
|
995
1099
|
function sentinelKind(arg) {
|
|
996
1100
|
if (arg === null) {
|
|
997
1101
|
return null;
|
|
998
1102
|
}
|
|
999
|
-
if (arg.type ===
|
|
1103
|
+
if (arg.type === AST_NODE_TYPES4.Literal) {
|
|
1000
1104
|
if (arg.value === null) {
|
|
1001
1105
|
return "nullish";
|
|
1002
1106
|
}
|
|
@@ -1008,13 +1112,13 @@ function sentinelKind(arg) {
|
|
|
1008
1112
|
}
|
|
1009
1113
|
return null;
|
|
1010
1114
|
}
|
|
1011
|
-
if (arg.type ===
|
|
1115
|
+
if (arg.type === AST_NODE_TYPES4.Identifier && arg.name === "undefined") {
|
|
1012
1116
|
return "nullish";
|
|
1013
1117
|
}
|
|
1014
|
-
if (arg.type ===
|
|
1118
|
+
if (arg.type === AST_NODE_TYPES4.ArrayExpression) {
|
|
1015
1119
|
return "array";
|
|
1016
1120
|
}
|
|
1017
|
-
if (arg.type ===
|
|
1121
|
+
if (arg.type === AST_NODE_TYPES4.ObjectExpression) {
|
|
1018
1122
|
return "object";
|
|
1019
1123
|
}
|
|
1020
1124
|
return null;
|
|
@@ -1023,25 +1127,25 @@ function isSentinelArgument(arg) {
|
|
|
1023
1127
|
if (arg === null) {
|
|
1024
1128
|
return false;
|
|
1025
1129
|
}
|
|
1026
|
-
if (arg.type ===
|
|
1130
|
+
if (arg.type === AST_NODE_TYPES4.Literal && arg.value === null) {
|
|
1027
1131
|
return true;
|
|
1028
1132
|
}
|
|
1029
|
-
if (arg.type ===
|
|
1133
|
+
if (arg.type === AST_NODE_TYPES4.Literal && arg.value === false) {
|
|
1030
1134
|
return true;
|
|
1031
1135
|
}
|
|
1032
|
-
if (arg.type ===
|
|
1136
|
+
if (arg.type === AST_NODE_TYPES4.Identifier && arg.name === "undefined") {
|
|
1033
1137
|
return true;
|
|
1034
1138
|
}
|
|
1035
|
-
if (arg.type ===
|
|
1139
|
+
if (arg.type === AST_NODE_TYPES4.ArrayExpression && arg.elements.length === 0) {
|
|
1036
1140
|
return true;
|
|
1037
1141
|
}
|
|
1038
|
-
if (arg.type ===
|
|
1142
|
+
if (arg.type === AST_NODE_TYPES4.ObjectExpression && arg.properties.length === 0) {
|
|
1039
1143
|
return true;
|
|
1040
1144
|
}
|
|
1041
1145
|
return false;
|
|
1042
1146
|
}
|
|
1043
1147
|
function isFunctionNode(node) {
|
|
1044
|
-
return node.type ===
|
|
1148
|
+
return node.type === AST_NODE_TYPES4.FunctionDeclaration || node.type === AST_NODE_TYPES4.FunctionExpression || node.type === AST_NODE_TYPES4.ArrowFunctionExpression;
|
|
1045
1149
|
}
|
|
1046
1150
|
function isNode(value) {
|
|
1047
1151
|
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
@@ -1081,24 +1185,24 @@ function walkWithinScope(node, visit) {
|
|
|
1081
1185
|
function containsThrow(node) {
|
|
1082
1186
|
return walkWithinScope(
|
|
1083
1187
|
node,
|
|
1084
|
-
(current) => current.type ===
|
|
1188
|
+
(current) => current.type === AST_NODE_TYPES4.ThrowStatement
|
|
1085
1189
|
);
|
|
1086
1190
|
}
|
|
1087
1191
|
function bindsName(param, name) {
|
|
1088
1192
|
switch (param.type) {
|
|
1089
|
-
case
|
|
1193
|
+
case AST_NODE_TYPES4.Identifier:
|
|
1090
1194
|
return param.name === name;
|
|
1091
|
-
case
|
|
1195
|
+
case AST_NODE_TYPES4.AssignmentPattern:
|
|
1092
1196
|
return bindsName(param.left, name);
|
|
1093
|
-
case
|
|
1197
|
+
case AST_NODE_TYPES4.RestElement:
|
|
1094
1198
|
return bindsName(param.argument, name);
|
|
1095
|
-
case
|
|
1199
|
+
case AST_NODE_TYPES4.ArrayPattern:
|
|
1096
1200
|
return param.elements.some(
|
|
1097
1201
|
(element) => element !== null && bindsName(element, name)
|
|
1098
1202
|
);
|
|
1099
|
-
case
|
|
1203
|
+
case AST_NODE_TYPES4.ObjectPattern:
|
|
1100
1204
|
return param.properties.some(
|
|
1101
|
-
(property) => property.type ===
|
|
1205
|
+
(property) => property.type === AST_NODE_TYPES4.RestElement ? bindsName(property.argument, name) : bindsName(property.value, name)
|
|
1102
1206
|
);
|
|
1103
1207
|
default:
|
|
1104
1208
|
return false;
|
|
@@ -1113,7 +1217,7 @@ function subtreeReadsName(node, name) {
|
|
|
1113
1217
|
if (found) {
|
|
1114
1218
|
return;
|
|
1115
1219
|
}
|
|
1116
|
-
if (current.type ===
|
|
1220
|
+
if (current.type === AST_NODE_TYPES4.Identifier && current.name === name) {
|
|
1117
1221
|
found = true;
|
|
1118
1222
|
return;
|
|
1119
1223
|
}
|
|
@@ -1124,10 +1228,10 @@ function subtreeReadsName(node, name) {
|
|
|
1124
1228
|
if (key === "parent") {
|
|
1125
1229
|
continue;
|
|
1126
1230
|
}
|
|
1127
|
-
if (key === "key" && current.type ===
|
|
1231
|
+
if (key === "key" && current.type === AST_NODE_TYPES4.Property && !current.computed) {
|
|
1128
1232
|
continue;
|
|
1129
1233
|
}
|
|
1130
|
-
if (key === "property" && current.type ===
|
|
1234
|
+
if (key === "property" && current.type === AST_NODE_TYPES4.MemberExpression && !current.computed) {
|
|
1131
1235
|
continue;
|
|
1132
1236
|
}
|
|
1133
1237
|
const value = current[key];
|
|
@@ -1160,10 +1264,10 @@ var SAFE_PARSE_CONSTRUCTORS = /* @__PURE__ */ new Set([
|
|
|
1160
1264
|
"URLPattern"
|
|
1161
1265
|
]);
|
|
1162
1266
|
function isParseShapedNode(node) {
|
|
1163
|
-
if (node.type ===
|
|
1267
|
+
if (node.type === AST_NODE_TYPES4.CallExpression && node.callee.type === AST_NODE_TYPES4.MemberExpression && !node.callee.computed && node.callee.property.type === AST_NODE_TYPES4.Identifier) {
|
|
1164
1268
|
return node.callee.property.name === "parse";
|
|
1165
1269
|
}
|
|
1166
|
-
if (node.type ===
|
|
1270
|
+
if (node.type === AST_NODE_TYPES4.NewExpression && node.callee.type === AST_NODE_TYPES4.Identifier) {
|
|
1167
1271
|
return SAFE_PARSE_CONSTRUCTORS.has(node.callee.name);
|
|
1168
1272
|
}
|
|
1169
1273
|
return false;
|
|
@@ -1174,10 +1278,10 @@ var BODY_DECODE_METHODS = /* @__PURE__ */ new Set([
|
|
|
1174
1278
|
"arrayBuffer"
|
|
1175
1279
|
]);
|
|
1176
1280
|
function isBodyDecodeNode(node) {
|
|
1177
|
-
return node.type ===
|
|
1281
|
+
return node.type === AST_NODE_TYPES4.CallExpression && node.callee.type === AST_NODE_TYPES4.MemberExpression && !node.callee.computed && node.callee.property.type === AST_NODE_TYPES4.Identifier && BODY_DECODE_METHODS.has(node.callee.property.name);
|
|
1178
1282
|
}
|
|
1179
1283
|
function returnsMatching(stmt, predicate) {
|
|
1180
|
-
return stmt.type ===
|
|
1284
|
+
return stmt.type === AST_NODE_TYPES4.ReturnStatement && stmt.argument !== null && walkWithinScope(stmt.argument, predicate);
|
|
1181
1285
|
}
|
|
1182
1286
|
function enclosingReturnTypeNode(node) {
|
|
1183
1287
|
let current = node.parent;
|
|
@@ -1194,10 +1298,10 @@ function isDeclaredBooleanPredicate(catchNode, kind) {
|
|
|
1194
1298
|
return false;
|
|
1195
1299
|
}
|
|
1196
1300
|
let declared = enclosingReturnTypeNode(catchNode);
|
|
1197
|
-
if (declared?.type ===
|
|
1301
|
+
if (declared?.type === AST_NODE_TYPES4.TSTypeReference && declared.typeName.type === AST_NODE_TYPES4.Identifier && declared.typeName.name === "Promise") {
|
|
1198
1302
|
declared = declared.typeArguments?.params[0] ?? null;
|
|
1199
1303
|
}
|
|
1200
|
-
return declared?.type ===
|
|
1304
|
+
return declared?.type === AST_NODE_TYPES4.TSBooleanKeyword;
|
|
1201
1305
|
}
|
|
1202
1306
|
function tryReturnsSafeParse(catchNode) {
|
|
1203
1307
|
const tryBlock = tryBlockOf(catchNode);
|
|
@@ -1213,7 +1317,7 @@ function tryReturnsSafeParse(catchNode) {
|
|
|
1213
1317
|
function enclosingFunctionBody(node) {
|
|
1214
1318
|
let current = node.parent;
|
|
1215
1319
|
while (current !== void 0 && current !== null) {
|
|
1216
|
-
if (isFunctionNode(current) && "body" in current && isNode(current.body) && current.body.type ===
|
|
1320
|
+
if (isFunctionNode(current) && "body" in current && isNode(current.body) && current.body.type === AST_NODE_TYPES4.BlockStatement) {
|
|
1217
1321
|
return current.body;
|
|
1218
1322
|
}
|
|
1219
1323
|
current = current.parent;
|
|
@@ -1226,7 +1330,7 @@ function functionReturnsSameSentinelKindElsewhere(catchNode, kind) {
|
|
|
1226
1330
|
return false;
|
|
1227
1331
|
}
|
|
1228
1332
|
return walkWithinScope(functionBody, (current) => {
|
|
1229
|
-
if (current.type !==
|
|
1333
|
+
if (current.type !== AST_NODE_TYPES4.ReturnStatement) {
|
|
1230
1334
|
return false;
|
|
1231
1335
|
}
|
|
1232
1336
|
if (isWithin(current, catchNode.body)) {
|
|
@@ -1270,7 +1374,7 @@ var no_sentinel_return_on_catch_default = ESLintUtils9.RuleCreator(
|
|
|
1270
1374
|
const matcher = createLogMatcher(loggingOptions);
|
|
1271
1375
|
function logsOrReportsError(catchBody, caughtName) {
|
|
1272
1376
|
return walkWithinScope(catchBody, (current) => {
|
|
1273
|
-
if (current.type !==
|
|
1377
|
+
if (current.type !== AST_NODE_TYPES4.CallExpression) {
|
|
1274
1378
|
return false;
|
|
1275
1379
|
}
|
|
1276
1380
|
if (matcher.isLoggingCall(current)) {
|
|
@@ -1287,7 +1391,7 @@ var no_sentinel_return_on_catch_default = ESLintUtils9.RuleCreator(
|
|
|
1287
1391
|
return;
|
|
1288
1392
|
}
|
|
1289
1393
|
const last = body[body.length - 1];
|
|
1290
|
-
if (last === void 0 || last.type !==
|
|
1394
|
+
if (last === void 0 || last.type !== AST_NODE_TYPES4.ReturnStatement) {
|
|
1291
1395
|
return;
|
|
1292
1396
|
}
|
|
1293
1397
|
if (!isSentinelArgument(last.argument)) {
|
|
@@ -1296,7 +1400,7 @@ var no_sentinel_return_on_catch_default = ESLintUtils9.RuleCreator(
|
|
|
1296
1400
|
if (containsThrow(node.body)) {
|
|
1297
1401
|
return;
|
|
1298
1402
|
}
|
|
1299
|
-
const caughtName = node.param?.type ===
|
|
1403
|
+
const caughtName = node.param?.type === AST_NODE_TYPES4.Identifier ? node.param.name : null;
|
|
1300
1404
|
if (logsOrReportsError(node.body, caughtName)) {
|
|
1301
1405
|
return;
|
|
1302
1406
|
}
|
|
@@ -1657,7 +1761,7 @@ var no_string_concat_in_loop_default = ESLintUtils11.RuleCreator(
|
|
|
1657
1761
|
|
|
1658
1762
|
// src/rules/no-unnecessary-use-client.ts
|
|
1659
1763
|
import {
|
|
1660
|
-
AST_NODE_TYPES as
|
|
1764
|
+
AST_NODE_TYPES as AST_NODE_TYPES5,
|
|
1661
1765
|
ESLintUtils as ESLintUtils12
|
|
1662
1766
|
} from "@typescript-eslint/utils";
|
|
1663
1767
|
var HOOK_REGEX = /^use([A-Z]|$)/;
|
|
@@ -1682,16 +1786,16 @@ var BROWSER_GLOBALS = /* @__PURE__ */ new Set([
|
|
|
1682
1786
|
]);
|
|
1683
1787
|
var CLIENT_ONLY_PACKAGES_REGEX = /^(?:@radix-ui\/|framer-motion|react-dom|react-day-picker|@floating-ui\/|react-select|react-toastify|react-hook-form|recharts|react-dropzone|react-slick|react-swipeable|react-resizable|react-draggable|react-beautiful-dnd|@hello-pangea\/dnd|react-virtualized|react-window|@tanstack\/react-table|@tanstack\/react-query|react-redux|recoil|jotai|zustand|@tippyjs\/react|react-color|react-datepicker|next-themes|react-helmet|react-helmet-async|styled-components|@emotion\/)/;
|
|
1684
1788
|
var isUseClientDirective = (node) => {
|
|
1685
|
-
return node.type ===
|
|
1789
|
+
return node.type === AST_NODE_TYPES5.ExpressionStatement && node.expression.type === AST_NODE_TYPES5.Literal && node.expression.value === "use client";
|
|
1686
1790
|
};
|
|
1687
1791
|
var isGlobalReference = (node, context) => {
|
|
1688
1792
|
if (!BROWSER_GLOBALS.has(node.name)) return false;
|
|
1689
1793
|
const parent = node.parent;
|
|
1690
1794
|
if (parent !== void 0) {
|
|
1691
|
-
if (parent.type ===
|
|
1795
|
+
if (parent.type === AST_NODE_TYPES5.MemberExpression && parent.property === node && !parent.computed) {
|
|
1692
1796
|
return false;
|
|
1693
1797
|
}
|
|
1694
|
-
if (parent.type ===
|
|
1798
|
+
if (parent.type === AST_NODE_TYPES5.Property && parent.key === node && !parent.computed) {
|
|
1695
1799
|
return false;
|
|
1696
1800
|
}
|
|
1697
1801
|
if (parent.type.startsWith("TS")) {
|
|
@@ -1731,13 +1835,13 @@ var no_unnecessary_use_client_default = ESLintUtils12.RuleCreator(
|
|
|
1731
1835
|
let directiveNode = null;
|
|
1732
1836
|
let hasClientIndicator = false;
|
|
1733
1837
|
const markIfHookOrContext = (callee) => {
|
|
1734
|
-
if (callee.type ===
|
|
1838
|
+
if (callee.type === AST_NODE_TYPES5.Identifier) {
|
|
1735
1839
|
if (HOOK_REGEX.test(callee.name) || callee.name === "createContext") {
|
|
1736
1840
|
hasClientIndicator = true;
|
|
1737
1841
|
}
|
|
1738
1842
|
return;
|
|
1739
1843
|
}
|
|
1740
|
-
if (callee.type ===
|
|
1844
|
+
if (callee.type === AST_NODE_TYPES5.MemberExpression && callee.property.type === AST_NODE_TYPES5.Identifier) {
|
|
1741
1845
|
const name = callee.property.name;
|
|
1742
1846
|
if (HOOK_REGEX.test(name) || name === "createContext") {
|
|
1743
1847
|
hasClientIndicator = true;
|
|
@@ -1747,7 +1851,7 @@ var no_unnecessary_use_client_default = ESLintUtils12.RuleCreator(
|
|
|
1747
1851
|
return {
|
|
1748
1852
|
Program(node) {
|
|
1749
1853
|
for (const stmt of node.body) {
|
|
1750
|
-
if (stmt.type !==
|
|
1854
|
+
if (stmt.type !== AST_NODE_TYPES5.ExpressionStatement) break;
|
|
1751
1855
|
if (isUseClientDirective(stmt)) {
|
|
1752
1856
|
directiveNode = stmt;
|
|
1753
1857
|
break;
|
|
@@ -1760,7 +1864,7 @@ var no_unnecessary_use_client_default = ESLintUtils12.RuleCreator(
|
|
|
1760
1864
|
},
|
|
1761
1865
|
JSXAttribute(node) {
|
|
1762
1866
|
if (directiveNode === null) return;
|
|
1763
|
-
if (node.name.type ===
|
|
1867
|
+
if (node.name.type === AST_NODE_TYPES5.JSXIdentifier && EVENT_PROP_REGEX.test(node.name.name)) {
|
|
1764
1868
|
hasClientIndicator = true;
|
|
1765
1869
|
}
|
|
1766
1870
|
},
|
|
@@ -1810,7 +1914,7 @@ var no_unnecessary_use_client_default = ESLintUtils12.RuleCreator(
|
|
|
1810
1914
|
|
|
1811
1915
|
// src/rules/prefer-discriminated-union.ts
|
|
1812
1916
|
import { ESLintUtils as ESLintUtils13 } from "@typescript-eslint/utils";
|
|
1813
|
-
import { AST_NODE_TYPES as
|
|
1917
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES6 } from "@typescript-eslint/utils";
|
|
1814
1918
|
var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
1815
1919
|
"success",
|
|
1816
1920
|
"ok",
|
|
@@ -1820,26 +1924,26 @@ var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
|
1820
1924
|
]);
|
|
1821
1925
|
var MIN_OPTIONAL_MEMBERS = 2;
|
|
1822
1926
|
function getMemberName(member) {
|
|
1823
|
-
if (member.type !==
|
|
1927
|
+
if (member.type !== AST_NODE_TYPES6.TSPropertySignature) {
|
|
1824
1928
|
return null;
|
|
1825
1929
|
}
|
|
1826
1930
|
const { key } = member;
|
|
1827
|
-
if (key.type ===
|
|
1931
|
+
if (key.type === AST_NODE_TYPES6.Identifier) {
|
|
1828
1932
|
return key.name;
|
|
1829
1933
|
}
|
|
1830
|
-
if (key.type ===
|
|
1934
|
+
if (key.type === AST_NODE_TYPES6.Literal && typeof key.value === "string") {
|
|
1831
1935
|
return key.value;
|
|
1832
1936
|
}
|
|
1833
1937
|
return null;
|
|
1834
1938
|
}
|
|
1835
1939
|
function isBooleanTyped(member) {
|
|
1836
|
-
return member.typeAnnotation?.typeAnnotation.type ===
|
|
1940
|
+
return member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES6.TSBooleanKeyword;
|
|
1837
1941
|
}
|
|
1838
1942
|
function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
1839
1943
|
let hasStatusBoolean = false;
|
|
1840
1944
|
let optionalCount = 0;
|
|
1841
1945
|
for (const member of typeLiteral.members) {
|
|
1842
|
-
if (member.type !==
|
|
1946
|
+
if (member.type !== AST_NODE_TYPES6.TSPropertySignature) {
|
|
1843
1947
|
continue;
|
|
1844
1948
|
}
|
|
1845
1949
|
if (member.optional) {
|
|
@@ -1880,7 +1984,7 @@ var prefer_discriminated_union_default = ESLintUtils13.RuleCreator(
|
|
|
1880
1984
|
TSInterfaceDeclaration(node) {
|
|
1881
1985
|
const synthetic = {
|
|
1882
1986
|
...node.body,
|
|
1883
|
-
type:
|
|
1987
|
+
type: AST_NODE_TYPES6.TSTypeLiteral,
|
|
1884
1988
|
members: node.body.body
|
|
1885
1989
|
};
|
|
1886
1990
|
checkTypeLiteral(synthetic, node);
|
|
@@ -1894,15 +1998,15 @@ var prefer_discriminated_union_default = ESLintUtils13.RuleCreator(
|
|
|
1894
1998
|
|
|
1895
1999
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
1896
2000
|
import {
|
|
1897
|
-
AST_NODE_TYPES as
|
|
2001
|
+
AST_NODE_TYPES as AST_NODE_TYPES7,
|
|
1898
2002
|
ESLintUtils as ESLintUtils14
|
|
1899
2003
|
} from "@typescript-eslint/utils";
|
|
1900
2004
|
var unwrap = (node) => {
|
|
1901
2005
|
let current = node;
|
|
1902
2006
|
while (current !== null && current !== void 0) {
|
|
1903
|
-
if (current.type ===
|
|
2007
|
+
if (current.type === AST_NODE_TYPES7.TSAsExpression || current.type === AST_NODE_TYPES7.TSTypeAssertion || current.type === AST_NODE_TYPES7.TSNonNullExpression || current.type === AST_NODE_TYPES7.TSSatisfiesExpression) {
|
|
1904
2008
|
current = current.expression;
|
|
1905
|
-
} else if (current.type ===
|
|
2009
|
+
} else if (current.type === AST_NODE_TYPES7.ChainExpression) {
|
|
1906
2010
|
current = current.expression;
|
|
1907
2011
|
} else {
|
|
1908
2012
|
break;
|
|
@@ -1913,25 +2017,25 @@ var unwrap = (node) => {
|
|
|
1913
2017
|
var isRawPayloadSource = (node) => {
|
|
1914
2018
|
let current = unwrap(node);
|
|
1915
2019
|
if (current === null) return false;
|
|
1916
|
-
if (current.type ===
|
|
2020
|
+
if (current.type === AST_NODE_TYPES7.AwaitExpression) {
|
|
1917
2021
|
current = unwrap(current.argument);
|
|
1918
2022
|
}
|
|
1919
|
-
if (current === null || current.type !==
|
|
2023
|
+
if (current === null || current.type !== AST_NODE_TYPES7.CallExpression) {
|
|
1920
2024
|
return false;
|
|
1921
2025
|
}
|
|
1922
2026
|
const callee = unwrap(current.callee);
|
|
1923
|
-
if (callee === null || callee.type !==
|
|
2027
|
+
if (callee === null || callee.type !== AST_NODE_TYPES7.MemberExpression) {
|
|
1924
2028
|
return false;
|
|
1925
2029
|
}
|
|
1926
2030
|
const property = unwrap(callee.property);
|
|
1927
|
-
if (property === null || property.type !==
|
|
2031
|
+
if (property === null || property.type !== AST_NODE_TYPES7.Identifier) {
|
|
1928
2032
|
return false;
|
|
1929
2033
|
}
|
|
1930
2034
|
if (property.name === "json") {
|
|
1931
2035
|
return true;
|
|
1932
2036
|
}
|
|
1933
2037
|
const object = unwrap(callee.object);
|
|
1934
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
2038
|
+
return property.name === "parse" && object !== null && object.type === AST_NODE_TYPES7.Identifier && object.name === "JSON";
|
|
1935
2039
|
};
|
|
1936
2040
|
var findVariable2 = (scope, name) => {
|
|
1937
2041
|
let current = scope;
|
|
@@ -1948,17 +2052,17 @@ var isGuardTestPosition = (node) => {
|
|
|
1948
2052
|
let parent = current.parent;
|
|
1949
2053
|
while (parent !== void 0 && parent !== null) {
|
|
1950
2054
|
switch (parent.type) {
|
|
1951
|
-
case
|
|
1952
|
-
case
|
|
1953
|
-
case
|
|
2055
|
+
case AST_NODE_TYPES7.UnaryExpression:
|
|
2056
|
+
case AST_NODE_TYPES7.LogicalExpression:
|
|
2057
|
+
case AST_NODE_TYPES7.ChainExpression:
|
|
1954
2058
|
current = parent;
|
|
1955
2059
|
parent = parent.parent;
|
|
1956
2060
|
continue;
|
|
1957
|
-
case
|
|
1958
|
-
case
|
|
1959
|
-
case
|
|
1960
|
-
case
|
|
1961
|
-
case
|
|
2061
|
+
case AST_NODE_TYPES7.IfStatement:
|
|
2062
|
+
case AST_NODE_TYPES7.ConditionalExpression:
|
|
2063
|
+
case AST_NODE_TYPES7.WhileStatement:
|
|
2064
|
+
case AST_NODE_TYPES7.DoWhileStatement:
|
|
2065
|
+
case AST_NODE_TYPES7.ForStatement:
|
|
1962
2066
|
return parent.test === current;
|
|
1963
2067
|
default:
|
|
1964
2068
|
return false;
|
|
@@ -1968,7 +2072,7 @@ var isGuardTestPosition = (node) => {
|
|
|
1968
2072
|
};
|
|
1969
2073
|
var isUnvalidatedVariableRef = (node, scope, tracked) => {
|
|
1970
2074
|
const unwrapped = unwrap(node);
|
|
1971
|
-
if (unwrapped === null || unwrapped.type !==
|
|
2075
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES7.Identifier) {
|
|
1972
2076
|
return false;
|
|
1973
2077
|
}
|
|
1974
2078
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -2002,11 +2106,11 @@ var prefer_schema_for_api_payload_default = ESLintUtils14.RuleCreator(
|
|
|
2002
2106
|
return {
|
|
2003
2107
|
VariableDeclarator(node) {
|
|
2004
2108
|
const scope = context.sourceCode.getScope(node);
|
|
2005
|
-
if (node.id.type ===
|
|
2109
|
+
if (node.id.type === AST_NODE_TYPES7.Identifier) {
|
|
2006
2110
|
trackInitializer(node);
|
|
2007
2111
|
return;
|
|
2008
2112
|
}
|
|
2009
|
-
if (node.id.type ===
|
|
2113
|
+
if (node.id.type === AST_NODE_TYPES7.ObjectPattern || node.id.type === AST_NODE_TYPES7.ArrayPattern) {
|
|
2010
2114
|
if (isRawPayloadSource(node.init)) {
|
|
2011
2115
|
context.report({ node: node.id, messageId: "unparsedJsonAccess" });
|
|
2012
2116
|
return;
|
|
@@ -2018,7 +2122,7 @@ var prefer_schema_for_api_payload_default = ESLintUtils14.RuleCreator(
|
|
|
2018
2122
|
},
|
|
2019
2123
|
AssignmentExpression(node) {
|
|
2020
2124
|
const scope = context.sourceCode.getScope(node);
|
|
2021
|
-
if (node.left.type ===
|
|
2125
|
+
if (node.left.type === AST_NODE_TYPES7.Identifier) {
|
|
2022
2126
|
const variable = findVariable2(scope, node.left.name);
|
|
2023
2127
|
if (variable === null) return;
|
|
2024
2128
|
if (isRawPayloadSource(node.right)) {
|
|
@@ -2028,7 +2132,7 @@ var prefer_schema_for_api_payload_default = ESLintUtils14.RuleCreator(
|
|
|
2028
2132
|
}
|
|
2029
2133
|
return;
|
|
2030
2134
|
}
|
|
2031
|
-
if (node.left.type ===
|
|
2135
|
+
if (node.left.type === AST_NODE_TYPES7.ObjectPattern || node.left.type === AST_NODE_TYPES7.ArrayPattern) {
|
|
2032
2136
|
if (isRawPayloadSource(node.right)) {
|
|
2033
2137
|
context.report({
|
|
2034
2138
|
node: node.left,
|
|
@@ -2045,15 +2149,15 @@ var prefer_schema_for_api_payload_default = ESLintUtils14.RuleCreator(
|
|
|
2045
2149
|
}
|
|
2046
2150
|
},
|
|
2047
2151
|
CallExpression(node) {
|
|
2048
|
-
if (node.callee.type !==
|
|
2152
|
+
if (node.callee.type !== AST_NODE_TYPES7.Identifier) return;
|
|
2049
2153
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
2050
2154
|
return;
|
|
2051
2155
|
}
|
|
2052
2156
|
const scope = context.sourceCode.getScope(node);
|
|
2053
2157
|
for (const arg of node.arguments) {
|
|
2054
|
-
if (arg.type ===
|
|
2158
|
+
if (arg.type === AST_NODE_TYPES7.SpreadElement) continue;
|
|
2055
2159
|
const unwrapped = unwrap(arg);
|
|
2056
|
-
if (unwrapped === null || unwrapped.type !==
|
|
2160
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES7.Identifier) {
|
|
2057
2161
|
continue;
|
|
2058
2162
|
}
|
|
2059
2163
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -2065,13 +2169,13 @@ var prefer_schema_for_api_payload_default = ESLintUtils14.RuleCreator(
|
|
|
2065
2169
|
const obj = unwrap(node.object);
|
|
2066
2170
|
if (isRawPayloadSource(obj)) {
|
|
2067
2171
|
const parent = node.parent;
|
|
2068
|
-
if (parent.type ===
|
|
2172
|
+
if (parent.type === AST_NODE_TYPES7.CallExpression && parent.callee === node && node.property.type === AST_NODE_TYPES7.Identifier && (node.property.name === "parse" || node.property.name === "safeParse")) {
|
|
2069
2173
|
return;
|
|
2070
2174
|
}
|
|
2071
2175
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
2072
2176
|
return;
|
|
2073
2177
|
}
|
|
2074
|
-
if (obj !== null && obj.type ===
|
|
2178
|
+
if (obj !== null && obj.type === AST_NODE_TYPES7.Identifier && isUnvalidatedVariableRef(obj, scope, unvalidatedVariables)) {
|
|
2075
2179
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
2076
2180
|
const variable = findVariable2(scope, obj.name);
|
|
2077
2181
|
if (variable !== null) {
|
|
@@ -2084,7 +2188,7 @@ var prefer_schema_for_api_payload_default = ESLintUtils14.RuleCreator(
|
|
|
2084
2188
|
});
|
|
2085
2189
|
|
|
2086
2190
|
// src/rules/prefer-semantic-colors.ts
|
|
2087
|
-
import { AST_NODE_TYPES as
|
|
2191
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES8, ESLintUtils as ESLintUtils15 } from "@typescript-eslint/utils";
|
|
2088
2192
|
|
|
2089
2193
|
// src/rules/_tailwind.ts
|
|
2090
2194
|
var tailwindBase = (token) => token.replace(/^(?:[a-z0-9-]+:)+/i, "").replace(/^!/, "");
|
|
@@ -2143,7 +2247,7 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
2143
2247
|
var isInsideSvg = (node) => {
|
|
2144
2248
|
let current = node.parent;
|
|
2145
2249
|
while (current !== void 0 && current !== null) {
|
|
2146
|
-
if (current.type ===
|
|
2250
|
+
if (current.type === AST_NODE_TYPES8.JSXElement && current.openingElement.name.type === AST_NODE_TYPES8.JSXIdentifier && (current.openingElement.name.name === "svg" || SVG_DEFS_CONTAINERS.has(current.openingElement.name.name))) {
|
|
2147
2251
|
return true;
|
|
2148
2252
|
}
|
|
2149
2253
|
current = current.parent;
|
|
@@ -2151,8 +2255,8 @@ var isInsideSvg = (node) => {
|
|
|
2151
2255
|
return false;
|
|
2152
2256
|
};
|
|
2153
2257
|
var propName = (key) => {
|
|
2154
|
-
if (key.type ===
|
|
2155
|
-
if (key.type ===
|
|
2258
|
+
if (key.type === AST_NODE_TYPES8.Identifier) return key.name;
|
|
2259
|
+
if (key.type === AST_NODE_TYPES8.Literal && typeof key.value === "string") return key.value;
|
|
2156
2260
|
return null;
|
|
2157
2261
|
};
|
|
2158
2262
|
var prefer_semantic_colors_default = ESLintUtils15.RuleCreator(
|
|
@@ -2187,27 +2291,27 @@ var prefer_semantic_colors_default = ESLintUtils15.RuleCreator(
|
|
|
2187
2291
|
const checkClassNode = (node) => {
|
|
2188
2292
|
if (node === null) return;
|
|
2189
2293
|
switch (node.type) {
|
|
2190
|
-
case
|
|
2294
|
+
case AST_NODE_TYPES8.Literal:
|
|
2191
2295
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
2192
2296
|
break;
|
|
2193
|
-
case
|
|
2297
|
+
case AST_NODE_TYPES8.TemplateLiteral:
|
|
2194
2298
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
2195
2299
|
break;
|
|
2196
|
-
case
|
|
2300
|
+
case AST_NODE_TYPES8.ArrayExpression:
|
|
2197
2301
|
for (const element of node.elements) {
|
|
2198
|
-
if (element !== null && element.type !==
|
|
2302
|
+
if (element !== null && element.type !== AST_NODE_TYPES8.SpreadElement) checkClassNode(element);
|
|
2199
2303
|
}
|
|
2200
2304
|
break;
|
|
2201
|
-
case
|
|
2305
|
+
case AST_NODE_TYPES8.ObjectExpression:
|
|
2202
2306
|
for (const property of node.properties) {
|
|
2203
|
-
if (property.type ===
|
|
2307
|
+
if (property.type === AST_NODE_TYPES8.Property) checkClassNode(property.value);
|
|
2204
2308
|
}
|
|
2205
2309
|
break;
|
|
2206
|
-
case
|
|
2310
|
+
case AST_NODE_TYPES8.ConditionalExpression:
|
|
2207
2311
|
checkClassNode(node.consequent);
|
|
2208
2312
|
checkClassNode(node.alternate);
|
|
2209
2313
|
break;
|
|
2210
|
-
case
|
|
2314
|
+
case AST_NODE_TYPES8.LogicalExpression:
|
|
2211
2315
|
checkClassNode(node.right);
|
|
2212
2316
|
break;
|
|
2213
2317
|
default:
|
|
@@ -2215,29 +2319,29 @@ var prefer_semantic_colors_default = ESLintUtils15.RuleCreator(
|
|
|
2215
2319
|
}
|
|
2216
2320
|
};
|
|
2217
2321
|
const checkColorValueNode = (node) => {
|
|
2218
|
-
if (node.type ===
|
|
2322
|
+
if (node.type === AST_NODE_TYPES8.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value)) {
|
|
2219
2323
|
context.report({ node, messageId: "inlineColor", data: { value: node.value } });
|
|
2220
2324
|
}
|
|
2221
2325
|
};
|
|
2222
2326
|
return {
|
|
2223
2327
|
"JSXAttribute[name.name='className']"(node) {
|
|
2224
2328
|
if (node.value === null) return;
|
|
2225
|
-
if (node.value.type ===
|
|
2226
|
-
else if (node.value.type ===
|
|
2227
|
-
if (node.value.expression.type !==
|
|
2329
|
+
if (node.value.type === AST_NODE_TYPES8.Literal) checkClassNode(node.value);
|
|
2330
|
+
else if (node.value.type === AST_NODE_TYPES8.JSXExpressionContainer) {
|
|
2331
|
+
if (node.value.expression.type !== AST_NODE_TYPES8.JSXEmptyExpression) {
|
|
2228
2332
|
checkClassNode(node.value.expression);
|
|
2229
2333
|
}
|
|
2230
2334
|
}
|
|
2231
2335
|
},
|
|
2232
2336
|
CallExpression(node) {
|
|
2233
|
-
if (node.callee.type ===
|
|
2337
|
+
if (node.callee.type === AST_NODE_TYPES8.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
2234
2338
|
for (const arg of node.arguments) {
|
|
2235
|
-
if (arg.type !==
|
|
2339
|
+
if (arg.type !== AST_NODE_TYPES8.SpreadElement) checkClassNode(arg);
|
|
2236
2340
|
}
|
|
2237
2341
|
}
|
|
2238
2342
|
},
|
|
2239
2343
|
VariableDeclarator(node) {
|
|
2240
|
-
if (node.id.type ===
|
|
2344
|
+
if (node.id.type === AST_NODE_TYPES8.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
2241
2345
|
checkClassNode(node.init);
|
|
2242
2346
|
}
|
|
2243
2347
|
},
|
|
@@ -2249,7 +2353,7 @@ var prefer_semantic_colors_default = ESLintUtils15.RuleCreator(
|
|
|
2249
2353
|
// Neutral drawing literals and anything inside an SVG defs container are
|
|
2250
2354
|
// structural, not UI tokens, so they never fire.
|
|
2251
2355
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
2252
|
-
if (node.value?.type !==
|
|
2356
|
+
if (node.value?.type !== AST_NODE_TYPES8.Literal) return;
|
|
2253
2357
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
2254
2358
|
return;
|
|
2255
2359
|
}
|
|
@@ -2414,7 +2518,7 @@ var prefer_server_actions_default = ESLintUtils16.RuleCreator(
|
|
|
2414
2518
|
|
|
2415
2519
|
// src/rules/prefer-shadcn.ts
|
|
2416
2520
|
import {
|
|
2417
|
-
AST_NODE_TYPES as
|
|
2521
|
+
AST_NODE_TYPES as AST_NODE_TYPES9,
|
|
2418
2522
|
ESLintUtils as ESLintUtils17
|
|
2419
2523
|
} from "@typescript-eslint/utils";
|
|
2420
2524
|
var REPLACEMENTS = {
|
|
@@ -2431,10 +2535,10 @@ var SKIPPED_INPUT_TYPES = /* @__PURE__ */ new Set(["hidden"]);
|
|
|
2431
2535
|
var kebabCase = (component) => component.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
2432
2536
|
var literalTypeAttr = (node) => {
|
|
2433
2537
|
for (const attribute of node.attributes) {
|
|
2434
|
-
if (attribute.type !==
|
|
2538
|
+
if (attribute.type !== AST_NODE_TYPES9.JSXAttribute || attribute.name.type !== AST_NODE_TYPES9.JSXIdentifier || attribute.name.name !== "type") {
|
|
2435
2539
|
continue;
|
|
2436
2540
|
}
|
|
2437
|
-
if (attribute.value?.type ===
|
|
2541
|
+
if (attribute.value?.type === AST_NODE_TYPES9.Literal && typeof attribute.value.value === "string") {
|
|
2438
2542
|
return { kind: "literal", value: attribute.value.value.toLowerCase() };
|
|
2439
2543
|
}
|
|
2440
2544
|
return { kind: "dynamic" };
|
|
@@ -2490,37 +2594,37 @@ var prefer_shadcn_default = ESLintUtils17.RuleCreator(
|
|
|
2490
2594
|
// src/rules/require-assert-never.ts
|
|
2491
2595
|
import {
|
|
2492
2596
|
ESLintUtils as ESLintUtils18,
|
|
2493
|
-
AST_NODE_TYPES as
|
|
2597
|
+
AST_NODE_TYPES as AST_NODE_TYPES10
|
|
2494
2598
|
} from "@typescript-eslint/utils";
|
|
2495
2599
|
var isAssertNeverCall = (expression) => {
|
|
2496
|
-
if (expression.type !==
|
|
2600
|
+
if (expression.type !== AST_NODE_TYPES10.CallExpression) return false;
|
|
2497
2601
|
const callee = expression.callee;
|
|
2498
|
-
if (callee.type ===
|
|
2602
|
+
if (callee.type === AST_NODE_TYPES10.Identifier) {
|
|
2499
2603
|
return callee.name === "assertNever";
|
|
2500
2604
|
}
|
|
2501
|
-
if (callee.type ===
|
|
2605
|
+
if (callee.type === AST_NODE_TYPES10.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES10.Identifier) {
|
|
2502
2606
|
return callee.property.name === "assertNever";
|
|
2503
2607
|
}
|
|
2504
2608
|
return false;
|
|
2505
2609
|
};
|
|
2506
2610
|
var statementContainsAssertNever = (statement) => {
|
|
2507
|
-
if (statement.type ===
|
|
2611
|
+
if (statement.type === AST_NODE_TYPES10.ExpressionStatement) {
|
|
2508
2612
|
return isAssertNeverCall(statement.expression);
|
|
2509
2613
|
}
|
|
2510
|
-
if (statement.type ===
|
|
2614
|
+
if (statement.type === AST_NODE_TYPES10.ThrowStatement) {
|
|
2511
2615
|
return isAssertNeverCall(statement.argument);
|
|
2512
2616
|
}
|
|
2513
|
-
if (statement.type ===
|
|
2617
|
+
if (statement.type === AST_NODE_TYPES10.ReturnStatement) {
|
|
2514
2618
|
return statement.argument !== null && isAssertNeverCall(statement.argument);
|
|
2515
2619
|
}
|
|
2516
|
-
if (statement.type ===
|
|
2620
|
+
if (statement.type === AST_NODE_TYPES10.BlockStatement) {
|
|
2517
2621
|
return statement.body.some(statementContainsAssertNever);
|
|
2518
2622
|
}
|
|
2519
2623
|
return false;
|
|
2520
2624
|
};
|
|
2521
2625
|
var isRuntimeHandlingStatement = (statement) => {
|
|
2522
|
-
if (statement.type ===
|
|
2523
|
-
if (statement.type ===
|
|
2626
|
+
if (statement.type === AST_NODE_TYPES10.EmptyStatement) return false;
|
|
2627
|
+
if (statement.type === AST_NODE_TYPES10.BlockStatement) {
|
|
2524
2628
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
2525
2629
|
}
|
|
2526
2630
|
return true;
|
|
@@ -2536,7 +2640,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
2536
2640
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
2537
2641
|
}
|
|
2538
2642
|
const only = defaultCase.consequent[0];
|
|
2539
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
2643
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === AST_NODE_TYPES10.BlockStatement && only.body.length === 0) {
|
|
2540
2644
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
2541
2645
|
}
|
|
2542
2646
|
return false;
|
|
@@ -2579,7 +2683,7 @@ var require_assert_never_default = ESLintUtils18.RuleCreator(
|
|
|
2579
2683
|
});
|
|
2580
2684
|
|
|
2581
2685
|
// src/rules/require-zod-form-validation.ts
|
|
2582
|
-
import { ESLintUtils as ESLintUtils19, AST_NODE_TYPES as
|
|
2686
|
+
import { ESLintUtils as ESLintUtils19, AST_NODE_TYPES as AST_NODE_TYPES11 } from "@typescript-eslint/utils";
|
|
2583
2687
|
|
|
2584
2688
|
// src/rules/_zod.ts
|
|
2585
2689
|
var ZOD_PREFIX_RE = /^Z[A-Z]/;
|
|
@@ -2590,14 +2694,14 @@ var ZOD_SCHEMA_NAME_RE = /Schema$|^Z[A-Z]/;
|
|
|
2590
2694
|
var looksLikeZodSchema = (node) => {
|
|
2591
2695
|
let current = node;
|
|
2592
2696
|
while (true) {
|
|
2593
|
-
if (current.type ===
|
|
2697
|
+
if (current.type === AST_NODE_TYPES11.Identifier) {
|
|
2594
2698
|
return current.name === "z" || ZOD_SCHEMA_NAME_RE.test(current.name);
|
|
2595
2699
|
}
|
|
2596
|
-
if (current.type ===
|
|
2700
|
+
if (current.type === AST_NODE_TYPES11.CallExpression) {
|
|
2597
2701
|
current = current.callee;
|
|
2598
2702
|
continue;
|
|
2599
2703
|
}
|
|
2600
|
-
if (current.type ===
|
|
2704
|
+
if (current.type === AST_NODE_TYPES11.MemberExpression) {
|
|
2601
2705
|
current = current.object;
|
|
2602
2706
|
continue;
|
|
2603
2707
|
}
|
|
@@ -2605,23 +2709,23 @@ var looksLikeZodSchema = (node) => {
|
|
|
2605
2709
|
}
|
|
2606
2710
|
};
|
|
2607
2711
|
var isZodParseCall = (node) => {
|
|
2608
|
-
if (node.type !==
|
|
2712
|
+
if (node.type !== AST_NODE_TYPES11.CallExpression) return false;
|
|
2609
2713
|
const callee = node.callee;
|
|
2610
|
-
if (callee.type !==
|
|
2714
|
+
if (callee.type !== AST_NODE_TYPES11.MemberExpression) return false;
|
|
2611
2715
|
if (callee.computed) return false;
|
|
2612
|
-
if (callee.property.type !==
|
|
2716
|
+
if (callee.property.type !== AST_NODE_TYPES11.Identifier) return false;
|
|
2613
2717
|
const method = callee.property.name;
|
|
2614
2718
|
if (method !== "parse" && method !== "safeParse") return false;
|
|
2615
2719
|
return looksLikeZodSchema(callee.object);
|
|
2616
2720
|
};
|
|
2617
2721
|
var isFormDataMethodCall = (node) => {
|
|
2618
2722
|
let current = node;
|
|
2619
|
-
if (current.type ===
|
|
2723
|
+
if (current.type === AST_NODE_TYPES11.AwaitExpression) {
|
|
2620
2724
|
current = current.argument;
|
|
2621
2725
|
}
|
|
2622
|
-
if (current.type !==
|
|
2726
|
+
if (current.type !== AST_NODE_TYPES11.CallExpression) return false;
|
|
2623
2727
|
const callee = current.callee;
|
|
2624
|
-
return callee.type ===
|
|
2728
|
+
return callee.type === AST_NODE_TYPES11.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES11.Identifier && callee.property.name === "formData";
|
|
2625
2729
|
};
|
|
2626
2730
|
var require_zod_form_validation_default = ESLintUtils19.RuleCreator(
|
|
2627
2731
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
@@ -2640,14 +2744,14 @@ var require_zod_form_validation_default = ESLintUtils19.RuleCreator(
|
|
|
2640
2744
|
defaultOptions: [],
|
|
2641
2745
|
create(context) {
|
|
2642
2746
|
const isFormSourceIdentifier = (node) => {
|
|
2643
|
-
if (node.type !==
|
|
2747
|
+
if (node.type !== AST_NODE_TYPES11.Identifier) return false;
|
|
2644
2748
|
if (/formdata/i.test(node.name)) return true;
|
|
2645
2749
|
let scope = context.sourceCode.getScope(node);
|
|
2646
2750
|
while (scope !== null) {
|
|
2647
2751
|
const variable = scope.set.get(node.name);
|
|
2648
2752
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
2649
2753
|
const def = variable.defs[0];
|
|
2650
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
2754
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === AST_NODE_TYPES11.VariableDeclarator && def.node.init !== null) {
|
|
2651
2755
|
return isFormDataMethodCall(def.node.init);
|
|
2652
2756
|
}
|
|
2653
2757
|
return false;
|
|
@@ -2658,8 +2762,8 @@ var require_zod_form_validation_default = ESLintUtils19.RuleCreator(
|
|
|
2658
2762
|
};
|
|
2659
2763
|
const isFormDataGetCall = (node) => {
|
|
2660
2764
|
const callee = node.callee;
|
|
2661
|
-
if (callee.type !==
|
|
2662
|
-
if (callee.property.type !==
|
|
2765
|
+
if (callee.type !== AST_NODE_TYPES11.MemberExpression) return false;
|
|
2766
|
+
if (callee.property.type !== AST_NODE_TYPES11.Identifier || callee.property.name !== "get") {
|
|
2663
2767
|
return false;
|
|
2664
2768
|
}
|
|
2665
2769
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -2674,11 +2778,11 @@ var require_zod_form_validation_default = ESLintUtils19.RuleCreator(
|
|
|
2674
2778
|
};
|
|
2675
2779
|
const isInstanceofNarrowing = (node) => {
|
|
2676
2780
|
const parent = node.parent;
|
|
2677
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
2781
|
+
return parent !== null && parent !== void 0 && parent.type === AST_NODE_TYPES11.BinaryExpression && parent.operator === "instanceof" && parent.left === node;
|
|
2678
2782
|
};
|
|
2679
2783
|
const boundDeclarator = (node) => {
|
|
2680
2784
|
const parent = node.parent;
|
|
2681
|
-
if (parent.type ===
|
|
2785
|
+
if (parent.type === AST_NODE_TYPES11.VariableDeclarator && parent.init === node && parent.id.type === AST_NODE_TYPES11.Identifier) {
|
|
2682
2786
|
return parent;
|
|
2683
2787
|
}
|
|
2684
2788
|
return null;
|
|
@@ -2706,7 +2810,7 @@ var require_zod_form_validation_default = ESLintUtils19.RuleCreator(
|
|
|
2706
2810
|
});
|
|
2707
2811
|
|
|
2708
2812
|
// src/rules/zod-naming-convention.ts
|
|
2709
|
-
import { ESLintUtils as ESLintUtils20, AST_NODE_TYPES as
|
|
2813
|
+
import { ESLintUtils as ESLintUtils20, AST_NODE_TYPES as AST_NODE_TYPES12 } from "@typescript-eslint/utils";
|
|
2710
2814
|
var CONVENTIONS = {
|
|
2711
2815
|
prefix: { test: ZOD_PREFIX_RE, messageId: "zPrefix" },
|
|
2712
2816
|
suffix: { test: ZOD_SUFFIX_RE, messageId: "schemaSuffix" },
|
|
@@ -2714,12 +2818,12 @@ var CONVENTIONS = {
|
|
|
2714
2818
|
};
|
|
2715
2819
|
var calleeChainStartsWithZ = (node) => {
|
|
2716
2820
|
let current = node;
|
|
2717
|
-
while (current.type ===
|
|
2821
|
+
while (current.type === AST_NODE_TYPES12.MemberExpression) {
|
|
2718
2822
|
const receiver = current.object;
|
|
2719
|
-
if (receiver.type ===
|
|
2823
|
+
if (receiver.type === AST_NODE_TYPES12.Identifier && receiver.name === "z") {
|
|
2720
2824
|
return true;
|
|
2721
2825
|
}
|
|
2722
|
-
if (receiver.type ===
|
|
2826
|
+
if (receiver.type === AST_NODE_TYPES12.CallExpression) {
|
|
2723
2827
|
current = receiver.callee;
|
|
2724
2828
|
continue;
|
|
2725
2829
|
}
|
|
@@ -2761,11 +2865,11 @@ var zod_naming_convention_default = ESLintUtils20.RuleCreator(
|
|
|
2761
2865
|
VariableDeclarator(node) {
|
|
2762
2866
|
const init = node.init;
|
|
2763
2867
|
if (init === null || init === void 0) return;
|
|
2764
|
-
if (init.type !==
|
|
2868
|
+
if (init.type !== AST_NODE_TYPES12.CallExpression) return;
|
|
2765
2869
|
const callee = init.callee;
|
|
2766
|
-
if (callee.type !==
|
|
2870
|
+
if (callee.type !== AST_NODE_TYPES12.MemberExpression) return;
|
|
2767
2871
|
if (!calleeChainStartsWithZ(callee)) return;
|
|
2768
|
-
if (node.id.type !==
|
|
2872
|
+
if (node.id.type !== AST_NODE_TYPES12.Identifier) return;
|
|
2769
2873
|
if (test.test(node.id.name)) return;
|
|
2770
2874
|
context.report({
|
|
2771
2875
|
node: node.id,
|
|
@@ -2987,7 +3091,7 @@ var no_cors_wildcard_with_credentials_default = ESLintUtils21.RuleCreator(
|
|
|
2987
3091
|
});
|
|
2988
3092
|
|
|
2989
3093
|
// src/rules/no-silent-promise-catch.ts
|
|
2990
|
-
import { AST_NODE_TYPES as
|
|
3094
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES13, ESLintUtils as ESLintUtils22 } from "@typescript-eslint/utils";
|
|
2991
3095
|
|
|
2992
3096
|
// src/rules/_paths.ts
|
|
2993
3097
|
var SCRIPT_FILE_RE = /([\\/]scripts[\\/])|(\.mjs$)/;
|
|
@@ -3005,21 +3109,21 @@ function isScriptFile(filename) {
|
|
|
3005
3109
|
|
|
3006
3110
|
// src/rules/no-silent-promise-catch.ts
|
|
3007
3111
|
function isBodyParseCall(node) {
|
|
3008
|
-
return node.type ===
|
|
3112
|
+
return node.type === AST_NODE_TYPES13.CallExpression && node.arguments.length === 0 && node.callee.type === AST_NODE_TYPES13.MemberExpression && !node.callee.computed && node.callee.property.type === AST_NODE_TYPES13.Identifier && (node.callee.property.name === "json" || node.callee.property.name === "text");
|
|
3009
3113
|
}
|
|
3010
3114
|
function isSilentExpression(node) {
|
|
3011
3115
|
switch (node.type) {
|
|
3012
|
-
case
|
|
3116
|
+
case AST_NODE_TYPES13.Literal:
|
|
3013
3117
|
return !("regex" in node);
|
|
3014
|
-
case
|
|
3118
|
+
case AST_NODE_TYPES13.Identifier:
|
|
3015
3119
|
return node.name === "undefined";
|
|
3016
|
-
case
|
|
3017
|
-
return node.operator === "void" && node.argument.type ===
|
|
3018
|
-
case
|
|
3120
|
+
case AST_NODE_TYPES13.UnaryExpression:
|
|
3121
|
+
return node.operator === "void" && node.argument.type === AST_NODE_TYPES13.Literal;
|
|
3122
|
+
case AST_NODE_TYPES13.ObjectExpression:
|
|
3019
3123
|
return node.properties.length === 0;
|
|
3020
|
-
case
|
|
3124
|
+
case AST_NODE_TYPES13.ArrayExpression:
|
|
3021
3125
|
return node.elements.length === 0;
|
|
3022
|
-
case
|
|
3126
|
+
case AST_NODE_TYPES13.TSAsExpression:
|
|
3023
3127
|
return isSilentExpression(node.expression);
|
|
3024
3128
|
default:
|
|
3025
3129
|
return false;
|
|
@@ -3027,7 +3131,7 @@ function isSilentExpression(node) {
|
|
|
3027
3131
|
}
|
|
3028
3132
|
function isSilentHandler(handler) {
|
|
3029
3133
|
const body = handler.body;
|
|
3030
|
-
if (body.type !==
|
|
3134
|
+
if (body.type !== AST_NODE_TYPES13.BlockStatement) {
|
|
3031
3135
|
return isSilentExpression(body);
|
|
3032
3136
|
}
|
|
3033
3137
|
if (body.body.length === 0) {
|
|
@@ -3035,7 +3139,7 @@ function isSilentHandler(handler) {
|
|
|
3035
3139
|
}
|
|
3036
3140
|
if (body.body.length === 1) {
|
|
3037
3141
|
const only = body.body[0];
|
|
3038
|
-
if (only !== void 0 && only.type ===
|
|
3142
|
+
if (only !== void 0 && only.type === AST_NODE_TYPES13.ReturnStatement) {
|
|
3039
3143
|
return only.argument === null || isSilentExpression(only.argument);
|
|
3040
3144
|
}
|
|
3041
3145
|
}
|
|
@@ -3062,7 +3166,7 @@ var no_silent_promise_catch_default = ESLintUtils22.RuleCreator(
|
|
|
3062
3166
|
}
|
|
3063
3167
|
return {
|
|
3064
3168
|
CallExpression(node) {
|
|
3065
|
-
if (node.callee.type !==
|
|
3169
|
+
if (node.callee.type !== AST_NODE_TYPES13.MemberExpression || node.callee.computed || node.callee.property.type !== AST_NODE_TYPES13.Identifier || node.callee.property.name !== "catch") {
|
|
3066
3170
|
return;
|
|
3067
3171
|
}
|
|
3068
3172
|
if (isBodyParseCall(node.callee.object)) {
|
|
@@ -3072,7 +3176,7 @@ var no_silent_promise_catch_default = ESLintUtils22.RuleCreator(
|
|
|
3072
3176
|
return;
|
|
3073
3177
|
}
|
|
3074
3178
|
const handler = node.arguments[0];
|
|
3075
|
-
if (handler === void 0 || handler.type !==
|
|
3179
|
+
if (handler === void 0 || handler.type !== AST_NODE_TYPES13.ArrowFunctionExpression && handler.type !== AST_NODE_TYPES13.FunctionExpression) {
|
|
3076
3180
|
return;
|
|
3077
3181
|
}
|
|
3078
3182
|
if (isSilentHandler(handler)) {
|
|
@@ -3085,7 +3189,7 @@ var no_silent_promise_catch_default = ESLintUtils22.RuleCreator(
|
|
|
3085
3189
|
|
|
3086
3190
|
// src/rules/require-fetch-timeout.ts
|
|
3087
3191
|
import {
|
|
3088
|
-
AST_NODE_TYPES as
|
|
3192
|
+
AST_NODE_TYPES as AST_NODE_TYPES14,
|
|
3089
3193
|
ASTUtils,
|
|
3090
3194
|
ESLintUtils as ESLintUtils23
|
|
3091
3195
|
} from "@typescript-eslint/utils";
|
|
@@ -3104,14 +3208,14 @@ function matchesAnyPattern2(filename, patterns) {
|
|
|
3104
3208
|
return false;
|
|
3105
3209
|
}
|
|
3106
3210
|
function initProvablyLacksSignal(init) {
|
|
3107
|
-
if (init.type !==
|
|
3211
|
+
if (init.type !== AST_NODE_TYPES14.ObjectExpression) {
|
|
3108
3212
|
return false;
|
|
3109
3213
|
}
|
|
3110
3214
|
for (const prop of init.properties) {
|
|
3111
|
-
if (prop.type ===
|
|
3215
|
+
if (prop.type === AST_NODE_TYPES14.SpreadElement) {
|
|
3112
3216
|
return false;
|
|
3113
3217
|
}
|
|
3114
|
-
if (prop.key.type ===
|
|
3218
|
+
if (prop.key.type === AST_NODE_TYPES14.Identifier && prop.key.name === "signal" || prop.key.type === AST_NODE_TYPES14.Literal && prop.key.value === "signal") {
|
|
3115
3219
|
return false;
|
|
3116
3220
|
}
|
|
3117
3221
|
if (prop.computed) {
|
|
@@ -3121,7 +3225,7 @@ function initProvablyLacksSignal(init) {
|
|
|
3121
3225
|
return true;
|
|
3122
3226
|
}
|
|
3123
3227
|
function isStringish(node) {
|
|
3124
|
-
return node.type ===
|
|
3228
|
+
return node.type === AST_NODE_TYPES14.Literal && typeof node.value === "string" || node.type === AST_NODE_TYPES14.TemplateLiteral;
|
|
3125
3229
|
}
|
|
3126
3230
|
var require_fetch_timeout_default = ESLintUtils23.RuleCreator(
|
|
3127
3231
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
@@ -3164,10 +3268,10 @@ var require_fetch_timeout_default = ESLintUtils23.RuleCreator(
|
|
|
3164
3268
|
return variable === null || variable.defs.length === 0;
|
|
3165
3269
|
}
|
|
3166
3270
|
function isGlobalFetchCall2(callee) {
|
|
3167
|
-
if (callee.type ===
|
|
3271
|
+
if (callee.type === AST_NODE_TYPES14.Identifier) {
|
|
3168
3272
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
3169
3273
|
}
|
|
3170
|
-
return callee.type ===
|
|
3274
|
+
return callee.type === AST_NODE_TYPES14.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES14.Identifier && callee.property.name === "fetch" && callee.object.type === AST_NODE_TYPES14.Identifier && GLOBAL_OBJECTS.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
3171
3275
|
}
|
|
3172
3276
|
return {
|
|
3173
3277
|
CallExpression(node) {
|
|
@@ -3187,23 +3291,23 @@ var require_fetch_timeout_default = ESLintUtils23.RuleCreator(
|
|
|
3187
3291
|
});
|
|
3188
3292
|
|
|
3189
3293
|
// src/rules/require-schema-validate-search.ts
|
|
3190
|
-
import { AST_NODE_TYPES as
|
|
3294
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES15, ESLintUtils as ESLintUtils24 } from "@typescript-eslint/utils";
|
|
3191
3295
|
var VALIDATOR_METHODS = /* @__PURE__ */ new Set([
|
|
3192
3296
|
"parse",
|
|
3193
3297
|
"safeParse",
|
|
3194
3298
|
"decode"
|
|
3195
3299
|
]);
|
|
3196
3300
|
function isConstTypeAnnotation(typeAnnotation) {
|
|
3197
|
-
return typeAnnotation.type ===
|
|
3301
|
+
return typeAnnotation.type === AST_NODE_TYPES15.TSTypeReference && typeAnnotation.typeName.type === AST_NODE_TYPES15.Identifier && typeAnnotation.typeName.name === "const";
|
|
3198
3302
|
}
|
|
3199
3303
|
function isValidatorCall(node) {
|
|
3200
|
-
return node.callee.type ===
|
|
3304
|
+
return node.callee.type === AST_NODE_TYPES15.MemberExpression && !node.callee.computed && node.callee.property.type === AST_NODE_TYPES15.Identifier && VALIDATOR_METHODS.has(node.callee.property.name);
|
|
3201
3305
|
}
|
|
3202
3306
|
function findCastExpression(node, insideValidatorArg) {
|
|
3203
|
-
if ((node.type ===
|
|
3307
|
+
if ((node.type === AST_NODE_TYPES15.TSAsExpression || node.type === AST_NODE_TYPES15.TSTypeAssertion) && !isConstTypeAnnotation(node.typeAnnotation) && !insideValidatorArg) {
|
|
3204
3308
|
return node;
|
|
3205
3309
|
}
|
|
3206
|
-
if (node.type ===
|
|
3310
|
+
if (node.type === AST_NODE_TYPES15.CallExpression && isValidatorCall(node)) {
|
|
3207
3311
|
const inCallee = findCastExpression(node.callee, insideValidatorArg);
|
|
3208
3312
|
if (inCallee !== null) {
|
|
3209
3313
|
return inCallee;
|
|
@@ -3257,11 +3361,11 @@ var require_schema_validate_search_default = ESLintUtils24.RuleCreator(
|
|
|
3257
3361
|
}
|
|
3258
3362
|
return {
|
|
3259
3363
|
Property(node) {
|
|
3260
|
-
const isValidateSearchKey = !node.computed && node.key.type ===
|
|
3364
|
+
const isValidateSearchKey = !node.computed && node.key.type === AST_NODE_TYPES15.Identifier && node.key.name === "validateSearch" || node.key.type === AST_NODE_TYPES15.Literal && node.key.value === "validateSearch";
|
|
3261
3365
|
if (!isValidateSearchKey) {
|
|
3262
3366
|
return;
|
|
3263
3367
|
}
|
|
3264
|
-
if (node.value.type !==
|
|
3368
|
+
if (node.value.type !== AST_NODE_TYPES15.ArrowFunctionExpression && node.value.type !== AST_NODE_TYPES15.FunctionExpression) {
|
|
3265
3369
|
return;
|
|
3266
3370
|
}
|
|
3267
3371
|
const cast = findCastExpression(node.value.body, false);
|
|
@@ -3276,13 +3380,13 @@ var require_schema_validate_search_default = ESLintUtils24.RuleCreator(
|
|
|
3276
3380
|
// src/rules/no-fat-try-blocks.ts
|
|
3277
3381
|
import {
|
|
3278
3382
|
ESLintUtils as ESLintUtils25,
|
|
3279
|
-
AST_NODE_TYPES as
|
|
3383
|
+
AST_NODE_TYPES as AST_NODE_TYPES16
|
|
3280
3384
|
} from "@typescript-eslint/utils";
|
|
3281
3385
|
var MAX_TRY_BODY_STATEMENTS = 3;
|
|
3282
3386
|
var NESTED_FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3387
|
+
AST_NODE_TYPES16.FunctionDeclaration,
|
|
3388
|
+
AST_NODE_TYPES16.FunctionExpression,
|
|
3389
|
+
AST_NODE_TYPES16.ArrowFunctionExpression
|
|
3286
3390
|
]);
|
|
3287
3391
|
var PURE_METHODS = /* @__PURE__ */ new Set([
|
|
3288
3392
|
"map",
|
|
@@ -3380,20 +3484,20 @@ function isNode4(value) {
|
|
|
3380
3484
|
}
|
|
3381
3485
|
function isPureCall(node) {
|
|
3382
3486
|
const callee = node.callee;
|
|
3383
|
-
if (callee.type !==
|
|
3487
|
+
if (callee.type !== AST_NODE_TYPES16.MemberExpression) {
|
|
3384
3488
|
return false;
|
|
3385
3489
|
}
|
|
3386
3490
|
const property = callee.property;
|
|
3387
|
-
if (property.type !==
|
|
3491
|
+
if (property.type !== AST_NODE_TYPES16.Identifier) {
|
|
3388
3492
|
return false;
|
|
3389
3493
|
}
|
|
3390
|
-
if (callee.object.type ===
|
|
3494
|
+
if (callee.object.type === AST_NODE_TYPES16.Identifier && PURE_NAMESPACES.has(callee.object.name)) {
|
|
3391
3495
|
return true;
|
|
3392
3496
|
}
|
|
3393
3497
|
return PURE_METHODS.has(property.name);
|
|
3394
3498
|
}
|
|
3395
3499
|
function isPureNew(node) {
|
|
3396
|
-
return node.callee.type ===
|
|
3500
|
+
return node.callee.type === AST_NODE_TYPES16.Identifier && PURE_CONSTRUCTORS.has(node.callee.name);
|
|
3397
3501
|
}
|
|
3398
3502
|
function subtreeMatches(stmt, predicate) {
|
|
3399
3503
|
let found = false;
|
|
@@ -3430,20 +3534,20 @@ function subtreeMatches(stmt, predicate) {
|
|
|
3430
3534
|
visit(stmt);
|
|
3431
3535
|
return found;
|
|
3432
3536
|
}
|
|
3433
|
-
var hasAwait = (node) => subtreeMatches(node, (n) => n.type ===
|
|
3537
|
+
var hasAwait = (node) => subtreeMatches(node, (n) => n.type === AST_NODE_TYPES16.AwaitExpression);
|
|
3434
3538
|
var hasThrowingCallOrNew = (node) => subtreeMatches(
|
|
3435
3539
|
node,
|
|
3436
|
-
(n) => n.type ===
|
|
3540
|
+
(n) => n.type === AST_NODE_TYPES16.CallExpression && !isPureCall(n) || n.type === AST_NODE_TYPES16.NewExpression && !isPureNew(n)
|
|
3437
3541
|
);
|
|
3438
3542
|
function unwrap2(expr) {
|
|
3439
3543
|
let current = expr;
|
|
3440
|
-
while (current.type ===
|
|
3544
|
+
while (current.type === AST_NODE_TYPES16.ChainExpression || current.type === AST_NODE_TYPES16.TSNonNullExpression) {
|
|
3441
3545
|
current = current.expression;
|
|
3442
3546
|
}
|
|
3443
3547
|
return current;
|
|
3444
3548
|
}
|
|
3445
3549
|
function isBareCallStatement(stmt) {
|
|
3446
|
-
return stmt.type ===
|
|
3550
|
+
return stmt.type === AST_NODE_TYPES16.ExpressionStatement && unwrap2(stmt.expression).type === AST_NODE_TYPES16.CallExpression;
|
|
3447
3551
|
}
|
|
3448
3552
|
function canThrow(stmt) {
|
|
3449
3553
|
if (hasAwait(stmt)) {
|
|
@@ -3452,10 +3556,10 @@ function canThrow(stmt) {
|
|
|
3452
3556
|
if (isBareCallStatement(stmt)) {
|
|
3453
3557
|
return false;
|
|
3454
3558
|
}
|
|
3455
|
-
if (stmt.type ===
|
|
3559
|
+
if (stmt.type === AST_NODE_TYPES16.BlockStatement) {
|
|
3456
3560
|
return stmt.body.some(canThrow);
|
|
3457
3561
|
}
|
|
3458
|
-
if (stmt.type ===
|
|
3562
|
+
if (stmt.type === AST_NODE_TYPES16.IfStatement) {
|
|
3459
3563
|
return hasThrowingCallOrNew(stmt.test) || canThrow(stmt.consequent) || stmt.alternate !== null && canThrow(stmt.alternate);
|
|
3460
3564
|
}
|
|
3461
3565
|
return hasThrowingCallOrNew(stmt);
|
|
@@ -3466,7 +3570,7 @@ function handlerRethrows(handler) {
|
|
|
3466
3570
|
}
|
|
3467
3571
|
const body = handler.body.body;
|
|
3468
3572
|
const last = body[body.length - 1];
|
|
3469
|
-
return last !== void 0 && last.type ===
|
|
3573
|
+
return last !== void 0 && last.type === AST_NODE_TYPES16.ThrowStatement;
|
|
3470
3574
|
}
|
|
3471
3575
|
var no_fat_try_blocks_default = ESLintUtils25.RuleCreator(
|
|
3472
3576
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
@@ -3626,6 +3730,10 @@ function isSecretName(identifier, innocuous = INNOCUOUS_WORDS) {
|
|
|
3626
3730
|
if (last !== void 0 && innocuous.has(last)) {
|
|
3627
3731
|
return false;
|
|
3628
3732
|
}
|
|
3733
|
+
const first = leadingWord(identifier);
|
|
3734
|
+
if (first !== void 0 && FLAG_PREFIXES.has(first)) {
|
|
3735
|
+
return false;
|
|
3736
|
+
}
|
|
3629
3737
|
if (tokens.some((tok) => SECRET_WORDS.has(tok))) {
|
|
3630
3738
|
return true;
|
|
3631
3739
|
}
|
|
@@ -3636,10 +3744,6 @@ function isAuthSecretName(identifier) {
|
|
|
3636
3744
|
return false;
|
|
3637
3745
|
}
|
|
3638
3746
|
const tokens = tokenize(identifier);
|
|
3639
|
-
const first = leadingWord(identifier);
|
|
3640
|
-
if (first !== void 0 && FLAG_PREFIXES.has(first)) {
|
|
3641
|
-
return false;
|
|
3642
|
-
}
|
|
3643
3747
|
const last = tokens.at(-1);
|
|
3644
3748
|
if (last !== void 0 && DESCRIPTOR_WORDS.has(last)) {
|
|
3645
3749
|
return false;
|
|
@@ -3716,6 +3820,49 @@ function isRawSecretValue(prop) {
|
|
|
3716
3820
|
}
|
|
3717
3821
|
return prop.value.type === "Identifier" || prop.value.type === "MemberExpression";
|
|
3718
3822
|
}
|
|
3823
|
+
var RAW_BLOB_WORDS = /* @__PURE__ */ new Set([
|
|
3824
|
+
"body",
|
|
3825
|
+
"bodies",
|
|
3826
|
+
"payload",
|
|
3827
|
+
"payloads",
|
|
3828
|
+
"params"
|
|
3829
|
+
]);
|
|
3830
|
+
var RAW_BLOB_IDENTIFIERS = /* @__PURE__ */ new Set(["formdata"]);
|
|
3831
|
+
var BLOB_REDACTION_RE = /redact|sanit|scrub|mask|truncat|anonym|filtered|preview|summar/i;
|
|
3832
|
+
var BLOB_REDACTION_TOKENS = /* @__PURE__ */ new Set([
|
|
3833
|
+
"safe",
|
|
3834
|
+
"clean",
|
|
3835
|
+
"shape",
|
|
3836
|
+
"keys",
|
|
3837
|
+
"public"
|
|
3838
|
+
]);
|
|
3839
|
+
function isRawBlobName(name) {
|
|
3840
|
+
if (REDACTION_RE.test(name) || BLOB_REDACTION_RE.test(name)) {
|
|
3841
|
+
return false;
|
|
3842
|
+
}
|
|
3843
|
+
const tokens = tokenize(name);
|
|
3844
|
+
if (tokens.some((tok) => BLOB_REDACTION_TOKENS.has(tok))) {
|
|
3845
|
+
return false;
|
|
3846
|
+
}
|
|
3847
|
+
const first = leadingWord(name);
|
|
3848
|
+
if (first !== void 0 && FLAG_PREFIXES.has(first)) {
|
|
3849
|
+
return false;
|
|
3850
|
+
}
|
|
3851
|
+
if (RAW_BLOB_IDENTIFIERS.has(name.toLowerCase())) {
|
|
3852
|
+
return true;
|
|
3853
|
+
}
|
|
3854
|
+
const last = tokens.at(-1);
|
|
3855
|
+
return last !== void 0 && RAW_BLOB_WORDS.has(last);
|
|
3856
|
+
}
|
|
3857
|
+
function rawBlobValueName(value) {
|
|
3858
|
+
if (value.type === "Identifier") {
|
|
3859
|
+
return isRawBlobName(value.name) ? value.name : null;
|
|
3860
|
+
}
|
|
3861
|
+
if (value.type === "MemberExpression" && !value.computed && value.property.type === "Identifier") {
|
|
3862
|
+
return isRawBlobName(value.property.name) ? value.property.name : null;
|
|
3863
|
+
}
|
|
3864
|
+
return null;
|
|
3865
|
+
}
|
|
3719
3866
|
function propertyKeyName2(prop) {
|
|
3720
3867
|
if (prop.computed) {
|
|
3721
3868
|
return null;
|
|
@@ -3735,7 +3882,7 @@ var no_secret_in_log_default = ESLintUtils26.RuleCreator(
|
|
|
3735
3882
|
meta: {
|
|
3736
3883
|
type: "problem",
|
|
3737
3884
|
docs: {
|
|
3738
|
-
description: "Disallow passing a secret-named value to a logging call;
|
|
3885
|
+
description: "Disallow passing a secret-named value or a raw request/response blob to a logging call; both leak to log sinks. Redact or omit."
|
|
3739
3886
|
},
|
|
3740
3887
|
schema: [
|
|
3741
3888
|
{
|
|
@@ -3745,52 +3892,58 @@ var no_secret_in_log_default = ESLintUtils26.RuleCreator(
|
|
|
3745
3892
|
}
|
|
3746
3893
|
],
|
|
3747
3894
|
messages: {
|
|
3748
|
-
noSecretInLog: "Secret `{{name}}` passed to a logging call leaks it to log sinks. Redact (e.g. `{{name}}Prefix: {{name}}.slice(0, 6)`) or omit it."
|
|
3895
|
+
noSecretInLog: "Secret `{{name}}` passed to a logging call leaks it to log sinks. Redact (e.g. `{{name}}Prefix: {{name}}.slice(0, 6)`) or omit it.",
|
|
3896
|
+
noRawBodyInLog: "Raw `{{name}}` passed to a logging call. Request/response blobs carry PII and often echo credentials back, and log sinks have no retention policy. Log a derived value instead (a status, `{{name}}.id`, a length, a truncated issue list) or pass it through a redactor (`redact({{name}})`)."
|
|
3749
3897
|
}
|
|
3750
3898
|
},
|
|
3751
3899
|
defaultOptions: [{}],
|
|
3752
3900
|
create(context, [loggingOptions]) {
|
|
3753
3901
|
const matcher = createLogMatcher(loggingOptions);
|
|
3902
|
+
const blobArmApplies = !isTestFile(context.filename);
|
|
3903
|
+
function reportSecretArgument(arg) {
|
|
3904
|
+
const name = arg.type === "Identifier" ? arg.name : arg.type === "MemberExpression" && !arg.computed && arg.property.type === "Identifier" ? arg.property.name : null;
|
|
3905
|
+
if (name === null || !isSecretKeyword(name)) {
|
|
3906
|
+
return false;
|
|
3907
|
+
}
|
|
3908
|
+
context.report({ node: arg, messageId: "noSecretInLog", data: { name } });
|
|
3909
|
+
return true;
|
|
3910
|
+
}
|
|
3911
|
+
function reportSecretProperty(prop) {
|
|
3912
|
+
const keyName2 = propertyKeyName2(prop);
|
|
3913
|
+
if (keyName2 === null || !isSecretKeyword(keyName2) || !isRawSecretValue(prop)) {
|
|
3914
|
+
return false;
|
|
3915
|
+
}
|
|
3916
|
+
context.report({ node: prop, messageId: "noSecretInLog", data: { name: keyName2 } });
|
|
3917
|
+
return true;
|
|
3918
|
+
}
|
|
3919
|
+
function reportRawBlob(node, value) {
|
|
3920
|
+
if (!blobArmApplies) {
|
|
3921
|
+
return;
|
|
3922
|
+
}
|
|
3923
|
+
const name = rawBlobValueName(value);
|
|
3924
|
+
if (name !== null) {
|
|
3925
|
+
context.report({ node, messageId: "noRawBodyInLog", data: { name } });
|
|
3926
|
+
}
|
|
3927
|
+
}
|
|
3754
3928
|
return {
|
|
3755
3929
|
CallExpression(node) {
|
|
3756
3930
|
if (!matcher.isLoggingCall(node)) {
|
|
3757
3931
|
return;
|
|
3758
3932
|
}
|
|
3759
3933
|
for (const arg of node.arguments) {
|
|
3760
|
-
if (arg.type === "Identifier") {
|
|
3761
|
-
if (isSecretKeyword(arg.name)) {
|
|
3762
|
-
context.report({
|
|
3763
|
-
node: arg,
|
|
3764
|
-
messageId: "noSecretInLog",
|
|
3765
|
-
data: { name: arg.name }
|
|
3766
|
-
});
|
|
3767
|
-
}
|
|
3768
|
-
continue;
|
|
3769
|
-
}
|
|
3770
|
-
if (arg.type === "MemberExpression") {
|
|
3771
|
-
if (!arg.computed && arg.property.type === "Identifier" && isSecretKeyword(arg.property.name)) {
|
|
3772
|
-
context.report({
|
|
3773
|
-
node: arg,
|
|
3774
|
-
messageId: "noSecretInLog",
|
|
3775
|
-
data: { name: arg.property.name }
|
|
3776
|
-
});
|
|
3777
|
-
}
|
|
3778
|
-
continue;
|
|
3779
|
-
}
|
|
3780
3934
|
if (arg.type === "ObjectExpression") {
|
|
3781
3935
|
for (const prop of arg.properties) {
|
|
3782
3936
|
if (prop.type !== "Property") {
|
|
3783
3937
|
continue;
|
|
3784
3938
|
}
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
context.report({
|
|
3788
|
-
node: prop,
|
|
3789
|
-
messageId: "noSecretInLog",
|
|
3790
|
-
data: { name: keyName2 }
|
|
3791
|
-
});
|
|
3939
|
+
if (!reportSecretProperty(prop)) {
|
|
3940
|
+
reportRawBlob(prop, prop.value);
|
|
3792
3941
|
}
|
|
3793
3942
|
}
|
|
3943
|
+
continue;
|
|
3944
|
+
}
|
|
3945
|
+
if (!reportSecretArgument(arg)) {
|
|
3946
|
+
reportRawBlob(arg, arg);
|
|
3794
3947
|
}
|
|
3795
3948
|
}
|
|
3796
3949
|
}
|
|
@@ -3800,12 +3953,12 @@ var no_secret_in_log_default = ESLintUtils26.RuleCreator(
|
|
|
3800
3953
|
|
|
3801
3954
|
// src/rules/no-unsafe-cast.ts
|
|
3802
3955
|
import { ESLintUtils as ESLintUtils27 } from "@typescript-eslint/utils";
|
|
3803
|
-
import { AST_NODE_TYPES as
|
|
3956
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES17 } from "@typescript-eslint/utils";
|
|
3804
3957
|
function isAnyAnnotation(node) {
|
|
3805
|
-
return node.type ===
|
|
3958
|
+
return node.type === AST_NODE_TYPES17.TSAnyKeyword;
|
|
3806
3959
|
}
|
|
3807
3960
|
function isConstAssertion(typeAnnotation) {
|
|
3808
|
-
return typeAnnotation.type ===
|
|
3961
|
+
return typeAnnotation.type === AST_NODE_TYPES17.TSTypeReference && typeAnnotation.typeName.type === AST_NODE_TYPES17.Identifier && typeAnnotation.typeName.name === "const";
|
|
3809
3962
|
}
|
|
3810
3963
|
var no_unsafe_cast_default = ESLintUtils27.RuleCreator(
|
|
3811
3964
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
@@ -3833,7 +3986,7 @@ var no_unsafe_cast_default = ESLintUtils27.RuleCreator(
|
|
|
3833
3986
|
return;
|
|
3834
3987
|
}
|
|
3835
3988
|
const inner = node.expression;
|
|
3836
|
-
if (inner.type ===
|
|
3989
|
+
if (inner.type === AST_NODE_TYPES17.TSAsExpression || inner.type === AST_NODE_TYPES17.TSTypeAssertion) {
|
|
3837
3990
|
context.report({ node, messageId: "doubleCast" });
|
|
3838
3991
|
}
|
|
3839
3992
|
}
|
|
@@ -3847,7 +4000,7 @@ var no_unsafe_cast_default = ESLintUtils27.RuleCreator(
|
|
|
3847
4000
|
// src/rules/prefer-string-literal-union.ts
|
|
3848
4001
|
import {
|
|
3849
4002
|
ESLintUtils as ESLintUtils28,
|
|
3850
|
-
AST_NODE_TYPES as
|
|
4003
|
+
AST_NODE_TYPES as AST_NODE_TYPES18
|
|
3851
4004
|
} from "@typescript-eslint/utils";
|
|
3852
4005
|
import * as ts from "typescript";
|
|
3853
4006
|
var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
@@ -3891,19 +4044,19 @@ function isChoiceLikeName(name) {
|
|
|
3891
4044
|
return CHOICE_TOKENS.has(lastWord(name));
|
|
3892
4045
|
}
|
|
3893
4046
|
function keyName(key) {
|
|
3894
|
-
if (key.type ===
|
|
4047
|
+
if (key.type === AST_NODE_TYPES18.Identifier) {
|
|
3895
4048
|
return key.name;
|
|
3896
4049
|
}
|
|
3897
|
-
if (key.type ===
|
|
4050
|
+
if (key.type === AST_NODE_TYPES18.Literal && typeof key.value === "string") {
|
|
3898
4051
|
return key.value;
|
|
3899
4052
|
}
|
|
3900
4053
|
return null;
|
|
3901
4054
|
}
|
|
3902
4055
|
function isStringLiteralMember(t) {
|
|
3903
|
-
return t.type ===
|
|
4056
|
+
return t.type === AST_NODE_TYPES18.TSLiteralType && t.literal.type === AST_NODE_TYPES18.Literal && typeof t.literal.value === "string";
|
|
3904
4057
|
}
|
|
3905
4058
|
function isStringLiteralUnion(node) {
|
|
3906
|
-
if (node?.type !==
|
|
4059
|
+
if (node?.type !== AST_NODE_TYPES18.TSUnionType) {
|
|
3907
4060
|
return false;
|
|
3908
4061
|
}
|
|
3909
4062
|
return node.types.filter(isStringLiteralMember).length >= MIN_CLUSTER_SIZE;
|
|
@@ -3932,12 +4085,12 @@ function bindingSourceExpression(decl) {
|
|
|
3932
4085
|
return ts.isForOfStatement(node) ? node.expression : node.initializer;
|
|
3933
4086
|
}
|
|
3934
4087
|
function refKey(node) {
|
|
3935
|
-
if (node.type ===
|
|
4088
|
+
if (node.type === AST_NODE_TYPES18.Identifier) {
|
|
3936
4089
|
return node.name;
|
|
3937
4090
|
}
|
|
3938
|
-
if (node.type ===
|
|
4091
|
+
if (node.type === AST_NODE_TYPES18.MemberExpression && !node.computed) {
|
|
3939
4092
|
const inner = refKey(node.object);
|
|
3940
|
-
if (inner === null || node.property.type !==
|
|
4093
|
+
if (inner === null || node.property.type !== AST_NODE_TYPES18.Identifier) {
|
|
3941
4094
|
return null;
|
|
3942
4095
|
}
|
|
3943
4096
|
return `${inner}.${node.property.name}`;
|
|
@@ -3945,7 +4098,7 @@ function refKey(node) {
|
|
|
3945
4098
|
return null;
|
|
3946
4099
|
}
|
|
3947
4100
|
function strLiteral(node) {
|
|
3948
|
-
if (node.type ===
|
|
4101
|
+
if (node.type === AST_NODE_TYPES18.Literal && typeof node.value === "string") {
|
|
3949
4102
|
return node.value;
|
|
3950
4103
|
}
|
|
3951
4104
|
return null;
|
|
@@ -4100,7 +4253,7 @@ var prefer_string_literal_union_default = ESLintUtils28.RuleCreator(
|
|
|
4100
4253
|
containersWithUnion.add(container);
|
|
4101
4254
|
return;
|
|
4102
4255
|
}
|
|
4103
|
-
if (typeNode?.type !==
|
|
4256
|
+
if (typeNode?.type !== AST_NODE_TYPES18.TSStringKeyword) {
|
|
4104
4257
|
return;
|
|
4105
4258
|
}
|
|
4106
4259
|
const name = keyName(key);
|
|
@@ -4188,10 +4341,10 @@ var prefer_string_literal_union_default = ESLintUtils28.RuleCreator(
|
|
|
4188
4341
|
}
|
|
4189
4342
|
};
|
|
4190
4343
|
function refKeyText(node) {
|
|
4191
|
-
if (node.type ===
|
|
4344
|
+
if (node.type === AST_NODE_TYPES18.BinaryExpression) {
|
|
4192
4345
|
return refKey(node.left) ?? refKey(node.right) ?? "value";
|
|
4193
4346
|
}
|
|
4194
|
-
if (node.type ===
|
|
4347
|
+
if (node.type === AST_NODE_TYPES18.SwitchStatement) {
|
|
4195
4348
|
return refKey(node.discriminant) ?? "value";
|
|
4196
4349
|
}
|
|
4197
4350
|
return "value";
|
|
@@ -4200,7 +4353,7 @@ var prefer_string_literal_union_default = ESLintUtils28.RuleCreator(
|
|
|
4200
4353
|
});
|
|
4201
4354
|
|
|
4202
4355
|
// src/rules/single-public-export.ts
|
|
4203
|
-
import { ESLintUtils as ESLintUtils29, AST_NODE_TYPES as
|
|
4356
|
+
import { ESLintUtils as ESLintUtils29, AST_NODE_TYPES as AST_NODE_TYPES19 } from "@typescript-eslint/utils";
|
|
4204
4357
|
var JUNK_DRAWER_STEMS = /* @__PURE__ */ new Set([
|
|
4205
4358
|
"util",
|
|
4206
4359
|
"utils",
|
|
@@ -4234,12 +4387,12 @@ var kebabCase2 = (name) => {
|
|
|
4234
4387
|
}
|
|
4235
4388
|
return normalized.replace(CAMEL_BOUNDARY_RE, "-").toLowerCase();
|
|
4236
4389
|
};
|
|
4237
|
-
var isFunctionExpression = (node) => node !== null && (node.type ===
|
|
4390
|
+
var isFunctionExpression = (node) => node !== null && (node.type === AST_NODE_TYPES19.ArrowFunctionExpression || node.type === AST_NODE_TYPES19.FunctionExpression);
|
|
4238
4391
|
var functionConstName = (decl) => {
|
|
4239
4392
|
if (decl.declarations.length !== 1) return null;
|
|
4240
4393
|
const [declarator] = decl.declarations;
|
|
4241
4394
|
if (declarator === void 0) return null;
|
|
4242
|
-
if (declarator.id.type !==
|
|
4395
|
+
if (declarator.id.type !== AST_NODE_TYPES19.Identifier) return null;
|
|
4243
4396
|
if (!isFunctionExpression(declarator.init)) return null;
|
|
4244
4397
|
return declarator.id.name;
|
|
4245
4398
|
};
|
|
@@ -4253,20 +4406,20 @@ var summarizeExports = (body) => {
|
|
|
4253
4406
|
};
|
|
4254
4407
|
for (const statement of body) {
|
|
4255
4408
|
switch (statement.type) {
|
|
4256
|
-
case
|
|
4409
|
+
case AST_NODE_TYPES19.ExportAllDeclaration:
|
|
4257
4410
|
hasReExport = true;
|
|
4258
4411
|
break;
|
|
4259
|
-
case
|
|
4412
|
+
case AST_NODE_TYPES19.ExportDefaultDeclaration: {
|
|
4260
4413
|
names += 1;
|
|
4261
4414
|
const decl = statement.declaration;
|
|
4262
|
-
if (decl.type ===
|
|
4415
|
+
if (decl.type === AST_NODE_TYPES19.FunctionDeclaration && decl.id !== null) {
|
|
4263
4416
|
candidate = { name: decl.id.name, node: statement };
|
|
4264
|
-
} else if (decl.type ===
|
|
4417
|
+
} else if (decl.type === AST_NODE_TYPES19.ClassDeclaration && decl.id !== null) {
|
|
4265
4418
|
candidate = { name: decl.id.name, node: statement };
|
|
4266
4419
|
}
|
|
4267
4420
|
break;
|
|
4268
4421
|
}
|
|
4269
|
-
case
|
|
4422
|
+
case AST_NODE_TYPES19.ExportNamedDeclaration: {
|
|
4270
4423
|
if (statement.source !== null) {
|
|
4271
4424
|
hasReExport = true;
|
|
4272
4425
|
break;
|
|
@@ -4277,15 +4430,15 @@ var summarizeExports = (body) => {
|
|
|
4277
4430
|
break;
|
|
4278
4431
|
}
|
|
4279
4432
|
switch (decl.type) {
|
|
4280
|
-
case
|
|
4433
|
+
case AST_NODE_TYPES19.FunctionDeclaration:
|
|
4281
4434
|
if (decl.id !== null) addCandidate(decl.id.name, statement);
|
|
4282
4435
|
else names += 1;
|
|
4283
4436
|
break;
|
|
4284
|
-
case
|
|
4437
|
+
case AST_NODE_TYPES19.ClassDeclaration:
|
|
4285
4438
|
if (decl.id !== null) addCandidate(decl.id.name, statement);
|
|
4286
4439
|
else names += 1;
|
|
4287
4440
|
break;
|
|
4288
|
-
case
|
|
4441
|
+
case AST_NODE_TYPES19.VariableDeclaration: {
|
|
4289
4442
|
const fnName = functionConstName(decl);
|
|
4290
4443
|
if (fnName !== null && decl.declarations.length === 1) {
|
|
4291
4444
|
addCandidate(fnName, statement);
|
|
@@ -4348,7 +4501,7 @@ var single_public_export_default = ESLintUtils29.RuleCreator(
|
|
|
4348
4501
|
import { ESLintUtils as ESLintUtils30 } from "@typescript-eslint/utils";
|
|
4349
4502
|
|
|
4350
4503
|
// src/rules/_sql.ts
|
|
4351
|
-
import { AST_NODE_TYPES as
|
|
4504
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES20 } from "@typescript-eslint/utils";
|
|
4352
4505
|
function stripSqlNoise(text) {
|
|
4353
4506
|
const out = [...text];
|
|
4354
4507
|
const n = text.length;
|
|
@@ -4409,13 +4562,13 @@ function stripSqlNoise(text) {
|
|
|
4409
4562
|
var SUBSTITUTION_MARKER = "?";
|
|
4410
4563
|
function sqlTextOf(node) {
|
|
4411
4564
|
switch (node.type) {
|
|
4412
|
-
case
|
|
4565
|
+
case AST_NODE_TYPES20.Literal:
|
|
4413
4566
|
return typeof node.value === "string" ? node.value : null;
|
|
4414
|
-
case
|
|
4567
|
+
case AST_NODE_TYPES20.TemplateLiteral:
|
|
4415
4568
|
return node.quasis.map((q) => q.value.cooked ?? q.value.raw).join(SUBSTITUTION_MARKER);
|
|
4416
|
-
case
|
|
4569
|
+
case AST_NODE_TYPES20.TaggedTemplateExpression:
|
|
4417
4570
|
return sqlTextOf(node.quasi);
|
|
4418
|
-
case
|
|
4571
|
+
case AST_NODE_TYPES20.BinaryExpression: {
|
|
4419
4572
|
if (node.operator !== "+") {
|
|
4420
4573
|
return null;
|
|
4421
4574
|
}
|
|
@@ -4423,7 +4576,7 @@ function sqlTextOf(node) {
|
|
|
4423
4576
|
const right = sqlTextOf(node.right);
|
|
4424
4577
|
return left !== null && right !== null ? left + right : null;
|
|
4425
4578
|
}
|
|
4426
|
-
case
|
|
4579
|
+
case AST_NODE_TYPES20.ArrayExpression: {
|
|
4427
4580
|
const parts = [];
|
|
4428
4581
|
for (const element of node.elements) {
|
|
4429
4582
|
if (element === null) {
|
|
@@ -4443,7 +4596,7 @@ function sqlTextOf(node) {
|
|
|
4443
4596
|
}
|
|
4444
4597
|
function isJoinedFragmentArray(node) {
|
|
4445
4598
|
const parent = node.parent;
|
|
4446
|
-
return parent?.type ===
|
|
4599
|
+
return parent?.type === AST_NODE_TYPES20.MemberExpression && parent.object === node && !parent.computed && parent.property.type === AST_NODE_TYPES20.Identifier && parent.property.name === "join" && parent.parent?.type === AST_NODE_TYPES20.CallExpression;
|
|
4447
4600
|
}
|
|
4448
4601
|
function markConsumed(node, consumed) {
|
|
4449
4602
|
consumed.add(node);
|
|
@@ -4522,14 +4675,14 @@ var no_offset_pagination_default = ESLintUtils30.RuleCreator(
|
|
|
4522
4675
|
});
|
|
4523
4676
|
|
|
4524
4677
|
// src/rules/no-positional-tuple-return.ts
|
|
4525
|
-
import { AST_NODE_TYPES as
|
|
4678
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES21, ESLintUtils as ESLintUtils31 } from "@typescript-eslint/utils";
|
|
4526
4679
|
var MIN_ELEMENTS = 2;
|
|
4527
4680
|
var AWAITABLE_TYPES = /* @__PURE__ */ new Set(["Promise", "PromiseLike", "Awaited"]);
|
|
4528
4681
|
function tupleReturnType(node) {
|
|
4529
|
-
if (node.type ===
|
|
4682
|
+
if (node.type === AST_NODE_TYPES21.TSTupleType) {
|
|
4530
4683
|
return node;
|
|
4531
4684
|
}
|
|
4532
|
-
if (node.type ===
|
|
4685
|
+
if (node.type === AST_NODE_TYPES21.TSTypeReference && node.typeName.type === AST_NODE_TYPES21.Identifier && AWAITABLE_TYPES.has(node.typeName.name)) {
|
|
4533
4686
|
const argument = node.typeArguments?.params[0];
|
|
4534
4687
|
return argument === void 0 ? null : tupleReturnType(argument);
|
|
4535
4688
|
}
|
|
@@ -4543,40 +4696,92 @@ function isPermittedTuple(tuple, sourceCode) {
|
|
|
4543
4696
|
if (elements.length < MIN_ELEMENTS) {
|
|
4544
4697
|
return true;
|
|
4545
4698
|
}
|
|
4546
|
-
if (elements.some((element) => element.type ===
|
|
4699
|
+
if (elements.some((element) => element.type === AST_NODE_TYPES21.TSRestType)) {
|
|
4547
4700
|
return true;
|
|
4548
4701
|
}
|
|
4549
|
-
if (elements.some((element) => element.type ===
|
|
4702
|
+
if (elements.some((element) => element.type === AST_NODE_TYPES21.TSNamedTupleMember)) {
|
|
4550
4703
|
return true;
|
|
4551
4704
|
}
|
|
4552
|
-
if (elements[0]?.type ===
|
|
4705
|
+
if (elements[0]?.type === AST_NODE_TYPES21.TSLiteralType) {
|
|
4553
4706
|
return true;
|
|
4554
4707
|
}
|
|
4555
4708
|
const texts = new Set(elements.map((element) => normalizedText(sourceCode, element)));
|
|
4556
4709
|
return texts.size === 1;
|
|
4557
4710
|
}
|
|
4558
4711
|
function functionName(node) {
|
|
4559
|
-
if (node.type ===
|
|
4712
|
+
if (node.type === AST_NODE_TYPES21.FunctionDeclaration) {
|
|
4560
4713
|
return node.id?.name ?? null;
|
|
4561
4714
|
}
|
|
4562
4715
|
const parent = node.parent;
|
|
4563
|
-
if (parent?.type ===
|
|
4716
|
+
if (parent?.type === AST_NODE_TYPES21.VariableDeclarator && parent.id.type === AST_NODE_TYPES21.Identifier) {
|
|
4564
4717
|
return parent.id.name;
|
|
4565
4718
|
}
|
|
4566
|
-
if ((parent?.type ===
|
|
4719
|
+
if ((parent?.type === AST_NODE_TYPES21.MethodDefinition || parent?.type === AST_NODE_TYPES21.PropertyDefinition || parent?.type === AST_NODE_TYPES21.Property) && parent.key.type === AST_NODE_TYPES21.Identifier) {
|
|
4567
4720
|
return parent.key.name;
|
|
4568
4721
|
}
|
|
4569
4722
|
return null;
|
|
4570
4723
|
}
|
|
4571
|
-
function
|
|
4724
|
+
function isInlineExported(node) {
|
|
4572
4725
|
for (let current = node; current != null; current = current.parent) {
|
|
4573
4726
|
const parent = current.parent;
|
|
4574
|
-
if (parent?.type ===
|
|
4727
|
+
if (parent?.type === AST_NODE_TYPES21.ExportNamedDeclaration || parent?.type === AST_NODE_TYPES21.ExportDefaultDeclaration) {
|
|
4575
4728
|
return true;
|
|
4576
4729
|
}
|
|
4577
4730
|
}
|
|
4578
4731
|
return false;
|
|
4579
4732
|
}
|
|
4733
|
+
function moduleScopeBindingName(node) {
|
|
4734
|
+
let current = node;
|
|
4735
|
+
let child = node;
|
|
4736
|
+
while (current.parent != null && current.parent.type !== AST_NODE_TYPES21.Program) {
|
|
4737
|
+
child = current;
|
|
4738
|
+
current = current.parent;
|
|
4739
|
+
}
|
|
4740
|
+
if (current.parent?.type !== AST_NODE_TYPES21.Program) {
|
|
4741
|
+
return null;
|
|
4742
|
+
}
|
|
4743
|
+
if (current.type === AST_NODE_TYPES21.FunctionDeclaration || current.type === AST_NODE_TYPES21.ClassDeclaration) {
|
|
4744
|
+
return current.id?.name ?? null;
|
|
4745
|
+
}
|
|
4746
|
+
if (current.type === AST_NODE_TYPES21.VariableDeclaration) {
|
|
4747
|
+
if (child.type !== AST_NODE_TYPES21.VariableDeclarator || child.id.type !== AST_NODE_TYPES21.Identifier) {
|
|
4748
|
+
return null;
|
|
4749
|
+
}
|
|
4750
|
+
return child.id.name;
|
|
4751
|
+
}
|
|
4752
|
+
return null;
|
|
4753
|
+
}
|
|
4754
|
+
function specifierExportedNames(program) {
|
|
4755
|
+
const names = /* @__PURE__ */ new Set();
|
|
4756
|
+
for (const statement of program.body) {
|
|
4757
|
+
if (statement.type === AST_NODE_TYPES21.ExportNamedDeclaration && statement.declaration == null && statement.source == null && statement.exportKind !== "type") {
|
|
4758
|
+
for (const specifier of statement.specifiers) {
|
|
4759
|
+
if (specifier.exportKind !== "type" && specifier.local.type === AST_NODE_TYPES21.Identifier) {
|
|
4760
|
+
names.add(specifier.local.name);
|
|
4761
|
+
}
|
|
4762
|
+
}
|
|
4763
|
+
continue;
|
|
4764
|
+
}
|
|
4765
|
+
if (statement.type === AST_NODE_TYPES21.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES21.Identifier) {
|
|
4766
|
+
names.add(statement.declaration.name);
|
|
4767
|
+
continue;
|
|
4768
|
+
}
|
|
4769
|
+
if (statement.type === AST_NODE_TYPES21.TSExportAssignment && statement.expression.type === AST_NODE_TYPES21.Identifier) {
|
|
4770
|
+
names.add(statement.expression.name);
|
|
4771
|
+
}
|
|
4772
|
+
}
|
|
4773
|
+
return names;
|
|
4774
|
+
}
|
|
4775
|
+
function isExported(node, specifierExports) {
|
|
4776
|
+
if (isInlineExported(node)) {
|
|
4777
|
+
return true;
|
|
4778
|
+
}
|
|
4779
|
+
if (specifierExports.size === 0) {
|
|
4780
|
+
return false;
|
|
4781
|
+
}
|
|
4782
|
+
const binding = moduleScopeBindingName(node);
|
|
4783
|
+
return binding !== null && specifierExports.has(binding);
|
|
4784
|
+
}
|
|
4580
4785
|
var no_positional_tuple_return_default = ESLintUtils31.RuleCreator(
|
|
4581
4786
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
4582
4787
|
)({
|
|
@@ -4593,6 +4798,7 @@ var no_positional_tuple_return_default = ESLintUtils31.RuleCreator(
|
|
|
4593
4798
|
},
|
|
4594
4799
|
defaultOptions: [],
|
|
4595
4800
|
create(context) {
|
|
4801
|
+
const specifierExports = specifierExportedNames(context.sourceCode.ast);
|
|
4596
4802
|
const check = (node) => {
|
|
4597
4803
|
const annotation = node.returnType?.typeAnnotation;
|
|
4598
4804
|
if (annotation === void 0) {
|
|
@@ -4606,7 +4812,7 @@ var no_positional_tuple_return_default = ESLintUtils31.RuleCreator(
|
|
|
4606
4812
|
if (name === null || name.startsWith("_") || /^use[A-Z]/.test(name)) {
|
|
4607
4813
|
return;
|
|
4608
4814
|
}
|
|
4609
|
-
if (!isExported(node)) {
|
|
4815
|
+
if (!isExported(node, specifierExports)) {
|
|
4610
4816
|
return;
|
|
4611
4817
|
}
|
|
4612
4818
|
context.report({
|
|
@@ -4624,7 +4830,7 @@ var no_positional_tuple_return_default = ESLintUtils31.RuleCreator(
|
|
|
4624
4830
|
});
|
|
4625
4831
|
|
|
4626
4832
|
// src/rules/no-repeated-string-literal.ts
|
|
4627
|
-
import { AST_NODE_TYPES as
|
|
4833
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES22, ESLintUtils as ESLintUtils32 } from "@typescript-eslint/utils";
|
|
4628
4834
|
var MIN_LENGTH = 40;
|
|
4629
4835
|
var MIN_OCCURRENCES = 3;
|
|
4630
4836
|
var MIN_DISTINCT_SCOPES = 2;
|
|
@@ -4632,9 +4838,9 @@ var PREVIEW_LENGTH = 40;
|
|
|
4632
4838
|
var SQL_KEYWORD_RE = /\b(SELECT|INSERT|UPDATE|DELETE|FROM|WHERE|JOIN|VALUES|ON CONFLICT|RETURNING|GROUP BY|ORDER BY)\b/;
|
|
4633
4839
|
var IDENTIFIER_RE = /^[a-z_][a-z0-9_.]*$/;
|
|
4634
4840
|
var FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4841
|
+
AST_NODE_TYPES22.FunctionDeclaration,
|
|
4842
|
+
AST_NODE_TYPES22.FunctionExpression,
|
|
4843
|
+
AST_NODE_TYPES22.ArrowFunctionExpression
|
|
4638
4844
|
]);
|
|
4639
4845
|
function isStructured(value) {
|
|
4640
4846
|
return value.includes("\n") || SQL_KEYWORD_RE.test(value) || IDENTIFIER_RE.test(value);
|
|
@@ -4656,7 +4862,7 @@ function isScaffolding(node) {
|
|
|
4656
4862
|
if (parent === void 0) {
|
|
4657
4863
|
return true;
|
|
4658
4864
|
}
|
|
4659
|
-
return parent.type ===
|
|
4865
|
+
return parent.type === AST_NODE_TYPES22.ImportDeclaration || parent.type === AST_NODE_TYPES22.ExportNamedDeclaration || parent.type === AST_NODE_TYPES22.ExportAllDeclaration || parent.type === AST_NODE_TYPES22.TSImportType || parent.type === AST_NODE_TYPES22.JSXAttribute || parent.type === AST_NODE_TYPES22.TSLiteralType;
|
|
4660
4866
|
}
|
|
4661
4867
|
var no_repeated_string_literal_default = ESLintUtils32.RuleCreator(
|
|
4662
4868
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
@@ -4801,7 +5007,7 @@ var no_select_star_default = ESLintUtils33.RuleCreator(
|
|
|
4801
5007
|
});
|
|
4802
5008
|
|
|
4803
5009
|
// src/rules/no-sleep-in-test-body.ts
|
|
4804
|
-
import { AST_NODE_TYPES as
|
|
5010
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES23, ESLintUtils as ESLintUtils34 } from "@typescript-eslint/utils";
|
|
4805
5011
|
var SLEEP_HELPERS = /* @__PURE__ */ new Set(["sleep", "delay", "wait", "pause"]);
|
|
4806
5012
|
var TEST_CALLERS = /* @__PURE__ */ new Set([
|
|
4807
5013
|
"it",
|
|
@@ -4810,34 +5016,34 @@ var TEST_CALLERS = /* @__PURE__ */ new Set([
|
|
|
4810
5016
|
"afterEach"
|
|
4811
5017
|
]);
|
|
4812
5018
|
var FUNCTION_TYPES2 = /* @__PURE__ */ new Set([
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
5019
|
+
AST_NODE_TYPES23.FunctionDeclaration,
|
|
5020
|
+
AST_NODE_TYPES23.FunctionExpression,
|
|
5021
|
+
AST_NODE_TYPES23.ArrowFunctionExpression
|
|
4816
5022
|
]);
|
|
4817
5023
|
function isNonzeroNumericLiteral(node) {
|
|
4818
|
-
return node?.type ===
|
|
5024
|
+
return node?.type === AST_NODE_TYPES23.Literal && typeof node.value === "number" && node.value !== 0;
|
|
4819
5025
|
}
|
|
4820
5026
|
function isTimedSetTimeout(node) {
|
|
4821
|
-
return node.type ===
|
|
5027
|
+
return node.type === AST_NODE_TYPES23.CallExpression && node.callee.type === AST_NODE_TYPES23.Identifier && node.callee.name === "setTimeout" && node.arguments.length >= 2 && isNonzeroNumericLiteral(node.arguments[1]);
|
|
4822
5028
|
}
|
|
4823
5029
|
function isPromiseSleep(node) {
|
|
4824
|
-
if (node.callee.type !==
|
|
5030
|
+
if (node.callee.type !== AST_NODE_TYPES23.Identifier || node.callee.name !== "Promise") {
|
|
4825
5031
|
return false;
|
|
4826
5032
|
}
|
|
4827
5033
|
const executor = node.arguments[0];
|
|
4828
|
-
if (executor?.type !==
|
|
5034
|
+
if (executor?.type !== AST_NODE_TYPES23.ArrowFunctionExpression && executor?.type !== AST_NODE_TYPES23.FunctionExpression) {
|
|
4829
5035
|
return false;
|
|
4830
5036
|
}
|
|
4831
5037
|
const body = executor.body;
|
|
4832
|
-
if (body.type !==
|
|
5038
|
+
if (body.type !== AST_NODE_TYPES23.BlockStatement) {
|
|
4833
5039
|
return isTimedSetTimeout(body);
|
|
4834
5040
|
}
|
|
4835
5041
|
return body.body.some(
|
|
4836
|
-
(stmt) => stmt.type ===
|
|
5042
|
+
(stmt) => stmt.type === AST_NODE_TYPES23.ExpressionStatement && isTimedSetTimeout(stmt.expression)
|
|
4837
5043
|
);
|
|
4838
5044
|
}
|
|
4839
5045
|
function isHelperSleep(node) {
|
|
4840
|
-
return node.callee.type ===
|
|
5046
|
+
return node.callee.type === AST_NODE_TYPES23.Identifier && SLEEP_HELPERS.has(node.callee.name) && node.arguments.length >= 1 && isNonzeroNumericLiteral(node.arguments[0]);
|
|
4841
5047
|
}
|
|
4842
5048
|
function nearestEnclosingFunction(node) {
|
|
4843
5049
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
@@ -4845,7 +5051,7 @@ function nearestEnclosingFunction(node) {
|
|
|
4845
5051
|
continue;
|
|
4846
5052
|
}
|
|
4847
5053
|
const grandparent = current.parent;
|
|
4848
|
-
const isPromiseExecutor = grandparent?.type ===
|
|
5054
|
+
const isPromiseExecutor = grandparent?.type === AST_NODE_TYPES23.NewExpression && isPromiseSleep(grandparent);
|
|
4849
5055
|
if (!isPromiseExecutor) {
|
|
4850
5056
|
return current;
|
|
4851
5057
|
}
|
|
@@ -4853,23 +5059,23 @@ function nearestEnclosingFunction(node) {
|
|
|
4853
5059
|
return null;
|
|
4854
5060
|
}
|
|
4855
5061
|
function testCallerName(callee) {
|
|
4856
|
-
if (callee.type ===
|
|
5062
|
+
if (callee.type === AST_NODE_TYPES23.Identifier) {
|
|
4857
5063
|
return callee.name;
|
|
4858
5064
|
}
|
|
4859
|
-
if (callee.type ===
|
|
5065
|
+
if (callee.type === AST_NODE_TYPES23.MemberExpression) {
|
|
4860
5066
|
return testCallerName(callee.object);
|
|
4861
5067
|
}
|
|
4862
|
-
if (callee.type ===
|
|
5068
|
+
if (callee.type === AST_NODE_TYPES23.CallExpression) {
|
|
4863
5069
|
return testCallerName(callee.callee);
|
|
4864
5070
|
}
|
|
4865
|
-
if (callee.type ===
|
|
5071
|
+
if (callee.type === AST_NODE_TYPES23.TaggedTemplateExpression) {
|
|
4866
5072
|
return testCallerName(callee.tag);
|
|
4867
5073
|
}
|
|
4868
5074
|
return null;
|
|
4869
5075
|
}
|
|
4870
5076
|
function isTestBody(fn) {
|
|
4871
5077
|
const call = fn.parent;
|
|
4872
|
-
if (call?.type !==
|
|
5078
|
+
if (call?.type !== AST_NODE_TYPES23.CallExpression || !call.arguments.some((argument) => argument === fn)) {
|
|
4873
5079
|
return false;
|
|
4874
5080
|
}
|
|
4875
5081
|
const name = testCallerName(call.callee);
|
|
@@ -4917,7 +5123,7 @@ var no_sleep_in_test_body_default = ESLintUtils34.RuleCreator(
|
|
|
4917
5123
|
});
|
|
4918
5124
|
|
|
4919
5125
|
// src/rules/prefer-constant-time-secret-compare.ts
|
|
4920
|
-
import { AST_NODE_TYPES as
|
|
5126
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES24, ESLintUtils as ESLintUtils35 } from "@typescript-eslint/utils";
|
|
4921
5127
|
var EQUALITY_OPERATORS = /* @__PURE__ */ new Set(["===", "!==", "==", "!="]);
|
|
4922
5128
|
var SENTINEL_IDENTIFIERS = /* @__PURE__ */ new Set(["undefined", "NaN"]);
|
|
4923
5129
|
var SENTINEL_WORDS = /(^|_)(SENTINEL|EMPTY|NONE|NULL|UNSET|MISSING|PLACEHOLDER|DUMMY|FAKE|EXAMPLE)(_|$)/;
|
|
@@ -4927,36 +5133,36 @@ function isConstantReference(identifier) {
|
|
|
4927
5133
|
}
|
|
4928
5134
|
function isExcludedOperand(node) {
|
|
4929
5135
|
switch (node.type) {
|
|
4930
|
-
case
|
|
5136
|
+
case AST_NODE_TYPES24.Literal:
|
|
4931
5137
|
return true;
|
|
4932
|
-
case
|
|
5138
|
+
case AST_NODE_TYPES24.TemplateLiteral:
|
|
4933
5139
|
return node.expressions.length === 0;
|
|
4934
|
-
case
|
|
5140
|
+
case AST_NODE_TYPES24.Identifier:
|
|
4935
5141
|
return SENTINEL_IDENTIFIERS.has(node.name) || isConstantReference(node.name);
|
|
4936
|
-
case
|
|
4937
|
-
return !node.computed && node.property.type ===
|
|
5142
|
+
case AST_NODE_TYPES24.MemberExpression:
|
|
5143
|
+
return !node.computed && node.property.type === AST_NODE_TYPES24.Identifier && isConstantReference(node.property.name);
|
|
4938
5144
|
default:
|
|
4939
5145
|
return false;
|
|
4940
5146
|
}
|
|
4941
5147
|
}
|
|
4942
5148
|
function operandName(node) {
|
|
4943
|
-
if (node.type ===
|
|
5149
|
+
if (node.type === AST_NODE_TYPES24.Identifier) {
|
|
4944
5150
|
return node.name;
|
|
4945
5151
|
}
|
|
4946
|
-
if (node.type ===
|
|
5152
|
+
if (node.type === AST_NODE_TYPES24.MemberExpression && !node.computed && node.property.type === AST_NODE_TYPES24.Identifier) {
|
|
4947
5153
|
return node.property.name;
|
|
4948
5154
|
}
|
|
4949
5155
|
return null;
|
|
4950
5156
|
}
|
|
4951
5157
|
function isSecretOperand(node) {
|
|
4952
|
-
if (node.type ===
|
|
5158
|
+
if (node.type === AST_NODE_TYPES24.TemplateLiteral) {
|
|
4953
5159
|
return node.expressions.some((expression) => isSecretOperand(expression));
|
|
4954
5160
|
}
|
|
4955
5161
|
const name = operandName(node);
|
|
4956
5162
|
return name !== null && isAuthSecretName(name);
|
|
4957
5163
|
}
|
|
4958
5164
|
function secretNameOf(node) {
|
|
4959
|
-
if (node.type ===
|
|
5165
|
+
if (node.type === AST_NODE_TYPES24.TemplateLiteral) {
|
|
4960
5166
|
for (const expression of node.expressions) {
|
|
4961
5167
|
const nested = secretNameOf(expression);
|
|
4962
5168
|
if (nested !== null) {
|
|
@@ -5043,17 +5249,17 @@ var store_insert_requires_on_conflict_default = ESLintUtils36.RuleCreator(
|
|
|
5043
5249
|
});
|
|
5044
5250
|
|
|
5045
5251
|
// src/rules/no-dynamic-sql.ts
|
|
5046
|
-
import { AST_NODE_TYPES as
|
|
5252
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES25, ESLintUtils as ESLintUtils37 } from "@typescript-eslint/utils";
|
|
5047
5253
|
var DEFAULT_METHODS = ["prepare", "exec", "query"];
|
|
5048
5254
|
var CONSTANT_CASE_RE = /^[A-Z][A-Z0-9_]*$/;
|
|
5049
5255
|
function isStaticFragment(expression) {
|
|
5050
|
-
if (expression.type ===
|
|
5256
|
+
if (expression.type === AST_NODE_TYPES25.Identifier) {
|
|
5051
5257
|
return CONSTANT_CASE_RE.test(expression.name);
|
|
5052
5258
|
}
|
|
5053
|
-
if (expression.type ===
|
|
5259
|
+
if (expression.type === AST_NODE_TYPES25.MemberExpression && !expression.computed && expression.property.type === AST_NODE_TYPES25.Identifier) {
|
|
5054
5260
|
return CONSTANT_CASE_RE.test(expression.property.name);
|
|
5055
5261
|
}
|
|
5056
|
-
if (expression.type ===
|
|
5262
|
+
if (expression.type === AST_NODE_TYPES25.Literal) {
|
|
5057
5263
|
return typeof expression.value === "string";
|
|
5058
5264
|
}
|
|
5059
5265
|
return false;
|
|
@@ -5064,29 +5270,29 @@ function runtimeInterpolations(template) {
|
|
|
5064
5270
|
);
|
|
5065
5271
|
}
|
|
5066
5272
|
function concatOperands(node) {
|
|
5067
|
-
if (node.type ===
|
|
5273
|
+
if (node.type === AST_NODE_TYPES25.BinaryExpression && node.operator === "+") {
|
|
5068
5274
|
return [...concatOperands(node.left), ...concatOperands(node.right)];
|
|
5069
5275
|
}
|
|
5070
5276
|
return [node];
|
|
5071
5277
|
}
|
|
5072
5278
|
function runtimeConcatOperands(node) {
|
|
5073
|
-
if (node.type !==
|
|
5279
|
+
if (node.type !== AST_NODE_TYPES25.BinaryExpression || node.operator !== "+") {
|
|
5074
5280
|
return [];
|
|
5075
5281
|
}
|
|
5076
5282
|
const operands = concatOperands(node);
|
|
5077
5283
|
const hasStringLiteral = operands.some(
|
|
5078
|
-
(operand) => operand.type ===
|
|
5284
|
+
(operand) => operand.type === AST_NODE_TYPES25.Literal && typeof operand.value === "string"
|
|
5079
5285
|
);
|
|
5080
5286
|
if (!hasStringLiteral) {
|
|
5081
5287
|
return [];
|
|
5082
5288
|
}
|
|
5083
5289
|
return operands.filter(
|
|
5084
|
-
(operand) => operand.type !==
|
|
5290
|
+
(operand) => operand.type !== AST_NODE_TYPES25.Literal && !isStaticFragment(operand)
|
|
5085
5291
|
);
|
|
5086
5292
|
}
|
|
5087
5293
|
function statementMethodName(node, methods) {
|
|
5088
5294
|
const callee = node.callee;
|
|
5089
|
-
if (callee.type !==
|
|
5295
|
+
if (callee.type !== AST_NODE_TYPES25.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES25.Identifier) {
|
|
5090
5296
|
return null;
|
|
5091
5297
|
}
|
|
5092
5298
|
const name = callee.property.name;
|
|
@@ -5131,7 +5337,7 @@ var no_dynamic_sql_default = ESLintUtils37.RuleCreator(
|
|
|
5131
5337
|
if (statement === void 0) {
|
|
5132
5338
|
return;
|
|
5133
5339
|
}
|
|
5134
|
-
const offenders = statement.type ===
|
|
5340
|
+
const offenders = statement.type === AST_NODE_TYPES25.TemplateLiteral ? runtimeInterpolations(statement) : runtimeConcatOperands(statement);
|
|
5135
5341
|
for (const offender of offenders) {
|
|
5136
5342
|
context.report({
|
|
5137
5343
|
node: offender,
|
|
@@ -5225,7 +5431,7 @@ var no_raw_fetch_outside_clients_default = ESLintUtils38.RuleCreator(
|
|
|
5225
5431
|
});
|
|
5226
5432
|
|
|
5227
5433
|
// src/rules/no-storage-in-stateless-modules.ts
|
|
5228
|
-
import { AST_NODE_TYPES as
|
|
5434
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES26, ESLintUtils as ESLintUtils39 } from "@typescript-eslint/utils";
|
|
5229
5435
|
var DEFAULT_METHODS2 = [
|
|
5230
5436
|
"prepare",
|
|
5231
5437
|
"put",
|
|
@@ -5244,7 +5450,7 @@ function compile2(patterns) {
|
|
|
5244
5450
|
}
|
|
5245
5451
|
function storageMethodName(node, methods) {
|
|
5246
5452
|
const callee = node.callee;
|
|
5247
|
-
if (callee.type !==
|
|
5453
|
+
if (callee.type !== AST_NODE_TYPES26.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES26.Identifier) {
|
|
5248
5454
|
return null;
|
|
5249
5455
|
}
|
|
5250
5456
|
const name = callee.property.name;
|
|
@@ -5316,7 +5522,7 @@ var no_storage_in_stateless_modules_default = ESLintUtils39.RuleCreator(
|
|
|
5316
5522
|
// src/rules/no-zod-native-enum.ts
|
|
5317
5523
|
import {
|
|
5318
5524
|
ESLintUtils as ESLintUtils40,
|
|
5319
|
-
AST_NODE_TYPES as
|
|
5525
|
+
AST_NODE_TYPES as AST_NODE_TYPES27
|
|
5320
5526
|
} from "@typescript-eslint/utils";
|
|
5321
5527
|
import * as ts2 from "typescript";
|
|
5322
5528
|
var IGNORE_PATTERNS2 = [
|
|
@@ -5335,7 +5541,7 @@ function isZodModule(source) {
|
|
|
5335
5541
|
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
5336
5542
|
}
|
|
5337
5543
|
function unwrap3(node) {
|
|
5338
|
-
if (node.type ===
|
|
5544
|
+
if (node.type === AST_NODE_TYPES27.TSAsExpression || node.type === AST_NODE_TYPES27.TSSatisfiesExpression) {
|
|
5339
5545
|
return unwrap3(node.expression);
|
|
5340
5546
|
}
|
|
5341
5547
|
return node;
|
|
@@ -5343,14 +5549,14 @@ function unwrap3(node) {
|
|
|
5343
5549
|
function stringValueTexts(node, sourceCode) {
|
|
5344
5550
|
const texts = [];
|
|
5345
5551
|
for (const prop of node.properties) {
|
|
5346
|
-
if (prop.type !==
|
|
5552
|
+
if (prop.type !== AST_NODE_TYPES27.Property) {
|
|
5347
5553
|
return null;
|
|
5348
5554
|
}
|
|
5349
5555
|
if (prop.computed || prop.shorthand || prop.method || prop.kind !== "init") {
|
|
5350
5556
|
return null;
|
|
5351
5557
|
}
|
|
5352
5558
|
const value = prop.value;
|
|
5353
|
-
if (value.type !==
|
|
5559
|
+
if (value.type !== AST_NODE_TYPES27.Literal || typeof value.value !== "string") {
|
|
5354
5560
|
return null;
|
|
5355
5561
|
}
|
|
5356
5562
|
const text = sourceCode.getText(value);
|
|
@@ -5366,7 +5572,7 @@ function resolvesToLocalEnum(node, scope) {
|
|
|
5366
5572
|
const variable = current.variables.find((v) => v.name === node.name);
|
|
5367
5573
|
if (variable !== void 0) {
|
|
5368
5574
|
return variable.defs.some(
|
|
5369
|
-
(def) => def.node.type ===
|
|
5575
|
+
(def) => def.node.type === AST_NODE_TYPES27.TSEnumDeclaration
|
|
5370
5576
|
);
|
|
5371
5577
|
}
|
|
5372
5578
|
current = current.upper;
|
|
@@ -5417,25 +5623,25 @@ var no_zod_native_enum_default = ESLintUtils40.RuleCreator(
|
|
|
5417
5623
|
const zodImportedNames = /* @__PURE__ */ new Map();
|
|
5418
5624
|
function isZodMemberCall(node, api) {
|
|
5419
5625
|
const callee = node.callee;
|
|
5420
|
-
if (callee.type ===
|
|
5626
|
+
if (callee.type === AST_NODE_TYPES27.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES27.Identifier) {
|
|
5421
5627
|
return callee.property.name === api;
|
|
5422
5628
|
}
|
|
5423
|
-
if (callee.type ===
|
|
5629
|
+
if (callee.type === AST_NODE_TYPES27.Identifier) {
|
|
5424
5630
|
return zodImportedNames.get(callee.name) === api;
|
|
5425
5631
|
}
|
|
5426
5632
|
return false;
|
|
5427
5633
|
}
|
|
5428
5634
|
function buildFix(node) {
|
|
5429
5635
|
const callee = node.callee;
|
|
5430
|
-
if (callee.type !==
|
|
5636
|
+
if (callee.type !== AST_NODE_TYPES27.MemberExpression || callee.property.type !== AST_NODE_TYPES27.Identifier) {
|
|
5431
5637
|
return null;
|
|
5432
5638
|
}
|
|
5433
5639
|
const arg = node.arguments[0];
|
|
5434
|
-
if (arg === void 0 || node.arguments.length !== 1 || arg.type ===
|
|
5640
|
+
if (arg === void 0 || node.arguments.length !== 1 || arg.type === AST_NODE_TYPES27.SpreadElement) {
|
|
5435
5641
|
return null;
|
|
5436
5642
|
}
|
|
5437
5643
|
const inner = unwrap3(arg);
|
|
5438
|
-
if (inner.type !==
|
|
5644
|
+
if (inner.type !== AST_NODE_TYPES27.ObjectExpression) {
|
|
5439
5645
|
return null;
|
|
5440
5646
|
}
|
|
5441
5647
|
const values = stringValueTexts(inner, sourceCode);
|
|
@@ -5455,7 +5661,7 @@ var no_zod_native_enum_default = ESLintUtils40.RuleCreator(
|
|
|
5455
5661
|
return;
|
|
5456
5662
|
}
|
|
5457
5663
|
for (const spec of node.specifiers) {
|
|
5458
|
-
if (spec.type ===
|
|
5664
|
+
if (spec.type === AST_NODE_TYPES27.ImportSpecifier && spec.imported.type === AST_NODE_TYPES27.Identifier) {
|
|
5459
5665
|
zodImportedNames.set(spec.local.name, spec.imported.name);
|
|
5460
5666
|
}
|
|
5461
5667
|
}
|
|
@@ -5474,7 +5680,7 @@ var no_zod_native_enum_default = ESLintUtils40.RuleCreator(
|
|
|
5474
5680
|
return;
|
|
5475
5681
|
}
|
|
5476
5682
|
const arg = node.arguments[0];
|
|
5477
|
-
if (arg === void 0 || arg.type !==
|
|
5683
|
+
if (arg === void 0 || arg.type !== AST_NODE_TYPES27.Identifier) {
|
|
5478
5684
|
return;
|
|
5479
5685
|
}
|
|
5480
5686
|
const isEnum = resolvesToLocalEnum(arg, sourceCode.getScope(arg)) || services !== null && resolvesToImportedEnum(arg, services);
|
|
@@ -5493,7 +5699,7 @@ var no_zod_native_enum_default = ESLintUtils40.RuleCreator(
|
|
|
5493
5699
|
// src/rules/prefer-module-level-constant.ts
|
|
5494
5700
|
import {
|
|
5495
5701
|
ESLintUtils as ESLintUtils41,
|
|
5496
|
-
AST_NODE_TYPES as
|
|
5702
|
+
AST_NODE_TYPES as AST_NODE_TYPES28
|
|
5497
5703
|
} from "@typescript-eslint/utils";
|
|
5498
5704
|
var DEFAULT_MIN_ELEMENTS = 3;
|
|
5499
5705
|
var MAX_LITERAL_DEPTH = 4;
|
|
@@ -5530,9 +5736,9 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
|
5530
5736
|
"assign"
|
|
5531
5737
|
]);
|
|
5532
5738
|
var FUNCTION_TYPES3 = /* @__PURE__ */ new Set([
|
|
5533
|
-
|
|
5534
|
-
|
|
5535
|
-
|
|
5739
|
+
AST_NODE_TYPES28.FunctionDeclaration,
|
|
5740
|
+
AST_NODE_TYPES28.FunctionExpression,
|
|
5741
|
+
AST_NODE_TYPES28.ArrowFunctionExpression
|
|
5536
5742
|
]);
|
|
5537
5743
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
5538
5744
|
function isIgnoredFile3(filename, sourceText) {
|
|
@@ -5545,13 +5751,13 @@ function isTestFile2(filename) {
|
|
|
5545
5751
|
return TEST_FILE_PATTERNS.some((re) => re.test(filename));
|
|
5546
5752
|
}
|
|
5547
5753
|
function unwrap4(node) {
|
|
5548
|
-
if (node.type ===
|
|
5754
|
+
if (node.type === AST_NODE_TYPES28.TSAsExpression || node.type === AST_NODE_TYPES28.TSSatisfiesExpression || node.type === AST_NODE_TYPES28.TSNonNullExpression) {
|
|
5549
5755
|
return unwrap4(node.expression);
|
|
5550
5756
|
}
|
|
5551
5757
|
return node;
|
|
5552
5758
|
}
|
|
5553
5759
|
function isRegexLiteral(node) {
|
|
5554
|
-
return node.type ===
|
|
5760
|
+
return node.type === AST_NODE_TYPES28.Literal && "regex" in node && node.regex !== void 0;
|
|
5555
5761
|
}
|
|
5556
5762
|
function isLiteralOnly(node, depth) {
|
|
5557
5763
|
if (depth > MAX_LITERAL_DEPTH) {
|
|
@@ -5559,29 +5765,29 @@ function isLiteralOnly(node, depth) {
|
|
|
5559
5765
|
}
|
|
5560
5766
|
const inner = unwrap4(node);
|
|
5561
5767
|
switch (inner.type) {
|
|
5562
|
-
case
|
|
5768
|
+
case AST_NODE_TYPES28.Literal: {
|
|
5563
5769
|
return true;
|
|
5564
5770
|
}
|
|
5565
|
-
case
|
|
5771
|
+
case AST_NODE_TYPES28.TemplateLiteral: {
|
|
5566
5772
|
return inner.expressions.length === 0;
|
|
5567
5773
|
}
|
|
5568
|
-
case
|
|
5569
|
-
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type ===
|
|
5774
|
+
case AST_NODE_TYPES28.UnaryExpression: {
|
|
5775
|
+
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type === AST_NODE_TYPES28.Literal && typeof inner.argument.value === "number";
|
|
5570
5776
|
}
|
|
5571
|
-
case
|
|
5777
|
+
case AST_NODE_TYPES28.ArrayExpression: {
|
|
5572
5778
|
return inner.elements.every(
|
|
5573
|
-
(el) => el !== null && el.type !==
|
|
5779
|
+
(el) => el !== null && el.type !== AST_NODE_TYPES28.SpreadElement && isLiteralOnly(el, depth + 1)
|
|
5574
5780
|
);
|
|
5575
5781
|
}
|
|
5576
|
-
case
|
|
5782
|
+
case AST_NODE_TYPES28.ObjectExpression: {
|
|
5577
5783
|
return inner.properties.every((prop) => {
|
|
5578
|
-
if (prop.type !==
|
|
5784
|
+
if (prop.type !== AST_NODE_TYPES28.Property) {
|
|
5579
5785
|
return false;
|
|
5580
5786
|
}
|
|
5581
5787
|
if (prop.shorthand || prop.method || prop.kind !== "init") {
|
|
5582
5788
|
return false;
|
|
5583
5789
|
}
|
|
5584
|
-
if (prop.computed && prop.key.type !==
|
|
5790
|
+
if (prop.computed && prop.key.type !== AST_NODE_TYPES28.Literal) {
|
|
5585
5791
|
return false;
|
|
5586
5792
|
}
|
|
5587
5793
|
return isLiteralOnly(prop.value, depth + 1);
|
|
@@ -5594,7 +5800,7 @@ function isLiteralOnly(node, depth) {
|
|
|
5594
5800
|
}
|
|
5595
5801
|
function unwrapObjectFreeze(node) {
|
|
5596
5802
|
const inner = unwrap4(node);
|
|
5597
|
-
if (inner.type ===
|
|
5803
|
+
if (inner.type === AST_NODE_TYPES28.CallExpression && inner.callee.type === AST_NODE_TYPES28.MemberExpression && !inner.callee.computed && inner.callee.object.type === AST_NODE_TYPES28.Identifier && inner.callee.object.name === "Object" && inner.callee.property.type === AST_NODE_TYPES28.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== AST_NODE_TYPES28.SpreadElement) {
|
|
5598
5804
|
return unwrap4(inner.arguments[0]);
|
|
5599
5805
|
}
|
|
5600
5806
|
return inner;
|
|
@@ -5610,19 +5816,19 @@ function classify(init, checkRegex) {
|
|
|
5610
5816
|
}
|
|
5611
5817
|
return { kind: "regex", size: 1 };
|
|
5612
5818
|
}
|
|
5613
|
-
if (node.type ===
|
|
5819
|
+
if (node.type === AST_NODE_TYPES28.ArrayExpression) {
|
|
5614
5820
|
return isLiteralOnly(node, 0) ? { kind: "array", size: node.elements.length } : null;
|
|
5615
5821
|
}
|
|
5616
|
-
if (node.type ===
|
|
5822
|
+
if (node.type === AST_NODE_TYPES28.ObjectExpression) {
|
|
5617
5823
|
return isLiteralOnly(node, 0) ? { kind: "object", size: node.properties.length } : null;
|
|
5618
5824
|
}
|
|
5619
|
-
if (node.type ===
|
|
5825
|
+
if (node.type === AST_NODE_TYPES28.NewExpression && node.callee.type === AST_NODE_TYPES28.Identifier && COLLECTION_CONSTRUCTORS.has(node.callee.name)) {
|
|
5620
5826
|
const arg = node.arguments[0];
|
|
5621
|
-
if (node.arguments.length !== 1 || arg === void 0 || arg.type ===
|
|
5827
|
+
if (node.arguments.length !== 1 || arg === void 0 || arg.type === AST_NODE_TYPES28.SpreadElement) {
|
|
5622
5828
|
return null;
|
|
5623
5829
|
}
|
|
5624
5830
|
const entries = unwrap4(arg);
|
|
5625
|
-
if (entries.type !==
|
|
5831
|
+
if (entries.type !== AST_NODE_TYPES28.ArrayExpression) {
|
|
5626
5832
|
return null;
|
|
5627
5833
|
}
|
|
5628
5834
|
return isLiteralOnly(entries, 0) ? { kind: node.callee.name === "Set" ? "Set" : "Map", size: entries.elements.length } : null;
|
|
@@ -5651,10 +5857,10 @@ var NON_RETAINING_BUILTINS = /* @__PURE__ */ new Map(
|
|
|
5651
5857
|
);
|
|
5652
5858
|
function isNonRetainingBuiltinCall(node, argument) {
|
|
5653
5859
|
const callee = node.callee;
|
|
5654
|
-
if (callee.type ===
|
|
5860
|
+
if (callee.type === AST_NODE_TYPES28.Identifier && callee.name === "structuredClone") {
|
|
5655
5861
|
return true;
|
|
5656
5862
|
}
|
|
5657
|
-
if (callee.type !==
|
|
5863
|
+
if (callee.type !== AST_NODE_TYPES28.MemberExpression || callee.computed || callee.object.type !== AST_NODE_TYPES28.Identifier || callee.property.type !== AST_NODE_TYPES28.Identifier) {
|
|
5658
5864
|
return false;
|
|
5659
5865
|
}
|
|
5660
5866
|
const members = NON_RETAINING_BUILTINS.get(callee.object.name);
|
|
@@ -5668,38 +5874,38 @@ function isNonRetainingBuiltinCall(node, argument) {
|
|
|
5668
5874
|
}
|
|
5669
5875
|
function isSafeRead(identifier) {
|
|
5670
5876
|
const parent = identifier.parent;
|
|
5671
|
-
if (parent.type ===
|
|
5877
|
+
if (parent.type === AST_NODE_TYPES28.MemberExpression) {
|
|
5672
5878
|
if (parent.object !== identifier) {
|
|
5673
5879
|
return true;
|
|
5674
5880
|
}
|
|
5675
5881
|
const grandparent = parent.parent;
|
|
5676
|
-
if (grandparent.type ===
|
|
5882
|
+
if (grandparent.type === AST_NODE_TYPES28.AssignmentExpression && grandparent.left === parent) {
|
|
5677
5883
|
return false;
|
|
5678
5884
|
}
|
|
5679
|
-
if (grandparent.type ===
|
|
5885
|
+
if (grandparent.type === AST_NODE_TYPES28.UpdateExpression) {
|
|
5680
5886
|
return false;
|
|
5681
5887
|
}
|
|
5682
|
-
if (grandparent.type ===
|
|
5888
|
+
if (grandparent.type === AST_NODE_TYPES28.UnaryExpression && grandparent.operator === "delete") {
|
|
5683
5889
|
return false;
|
|
5684
5890
|
}
|
|
5685
|
-
if (!parent.computed && parent.property.type ===
|
|
5891
|
+
if (!parent.computed && parent.property.type === AST_NODE_TYPES28.Identifier && MUTATING_METHODS.has(parent.property.name) && grandparent.type === AST_NODE_TYPES28.CallExpression && grandparent.callee === parent) {
|
|
5686
5892
|
return false;
|
|
5687
5893
|
}
|
|
5688
5894
|
return true;
|
|
5689
5895
|
}
|
|
5690
|
-
if (parent.type ===
|
|
5896
|
+
if (parent.type === AST_NODE_TYPES28.ForOfStatement && parent.right === identifier) {
|
|
5691
5897
|
return true;
|
|
5692
5898
|
}
|
|
5693
|
-
if (parent.type ===
|
|
5899
|
+
if (parent.type === AST_NODE_TYPES28.SpreadElement) {
|
|
5694
5900
|
return true;
|
|
5695
5901
|
}
|
|
5696
|
-
if (parent.type ===
|
|
5902
|
+
if (parent.type === AST_NODE_TYPES28.BinaryExpression) {
|
|
5697
5903
|
return true;
|
|
5698
5904
|
}
|
|
5699
|
-
if (parent.type ===
|
|
5905
|
+
if (parent.type === AST_NODE_TYPES28.CallExpression && parent.arguments.includes(identifier) && isNonRetainingBuiltinCall(parent, identifier)) {
|
|
5700
5906
|
return true;
|
|
5701
5907
|
}
|
|
5702
|
-
if (parent.type ===
|
|
5908
|
+
if (parent.type === AST_NODE_TYPES28.UnaryExpression && parent.operator !== "delete") {
|
|
5703
5909
|
return true;
|
|
5704
5910
|
}
|
|
5705
5911
|
return false;
|
|
@@ -5756,7 +5962,7 @@ var prefer_module_level_constant_default = ESLintUtils41.RuleCreator(
|
|
|
5756
5962
|
if (reference.isWrite()) {
|
|
5757
5963
|
return false;
|
|
5758
5964
|
}
|
|
5759
|
-
if (reference.identifier.type !==
|
|
5965
|
+
if (reference.identifier.type !== AST_NODE_TYPES28.Identifier) {
|
|
5760
5966
|
return false;
|
|
5761
5967
|
}
|
|
5762
5968
|
if (!isSafeRead(reference.identifier)) {
|
|
@@ -5768,10 +5974,10 @@ var prefer_module_level_constant_default = ESLintUtils41.RuleCreator(
|
|
|
5768
5974
|
return {
|
|
5769
5975
|
VariableDeclarator(node) {
|
|
5770
5976
|
const declaration = node.parent;
|
|
5771
|
-
if (declaration.type !==
|
|
5977
|
+
if (declaration.type !== AST_NODE_TYPES28.VariableDeclaration || declaration.kind !== "const" || declaration.declare === true) {
|
|
5772
5978
|
return;
|
|
5773
5979
|
}
|
|
5774
|
-
if (node.id.type !==
|
|
5980
|
+
if (node.id.type !== AST_NODE_TYPES28.Identifier || node.init === null) {
|
|
5775
5981
|
return;
|
|
5776
5982
|
}
|
|
5777
5983
|
if (enclosingFunction2(node) === null) {
|
|
@@ -5844,7 +6050,7 @@ var rules = {
|
|
|
5844
6050
|
var plugin = {
|
|
5845
6051
|
meta: {
|
|
5846
6052
|
name: "@sarj/eslint-plugin",
|
|
5847
|
-
version: "2.
|
|
6053
|
+
version: "2.10.0"
|
|
5848
6054
|
},
|
|
5849
6055
|
rules,
|
|
5850
6056
|
configs: {
|