@sarj/eslint-plugin 11.1.0 → 12.0.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 +1085 -1104
- package/dist/index.d.cts +11 -21
- package/dist/index.d.ts +11 -21
- package/dist/index.js +1385 -1396
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -869,6 +869,7 @@ var BANNER_RUN_RE = /={4,}|-{4,}|#{4,}|\*{4,}|~{4,}|[\u2500-\u257f]{4,}/;
|
|
|
869
869
|
var REGION_MARKER_RE = /^#?(?:end)?region\b(.*)$/i;
|
|
870
870
|
var REGION_TITLE_RE = /^[\s:\-\u2013\u2014]*\w[\w \-/&+]*$/;
|
|
871
871
|
var REGION_TITLE_MAX_WORDS = 5;
|
|
872
|
+
var REGION_PROSE_VERB_RE = /^(?:is|are|was|were|comes?|defaults?|derives?|inherits?|depends?|uses?|maps?|resolves?)\b/i;
|
|
872
873
|
function stripCommentMarker(line) {
|
|
873
874
|
return line.replace(/^\s*\/{1,2}/, "").replace(/^\s*\*+/, "").trim();
|
|
874
875
|
}
|
|
@@ -930,7 +931,9 @@ var CALL_RE = /^[A-Za-z_$][\w.$]*\([^)]*\)\s*;?\s*$/;
|
|
|
930
931
|
var ASSERTION_CODE_RE = /^(?:await\s+)?(?:expect(?:TypeOf)?|assert(?:\.\w+)?)\s*\(/;
|
|
931
932
|
var HTTP_CONTRACT_RE = /\b(?:GET|HEAD|OPTIONS|PATCH|POST|PUT|DELETE)\s+(?:https?:\/\/|\/|\{[A-Za-z_$])/;
|
|
932
933
|
var PROSE_ASSIGNMENT_RE = /^[A-Za-z_$][\w.$[\]]*\s*=\s*[A-Za-z][A-Za-z '-]{2,}\s+\((?:how|what|when|where|which|who|why)\b[^)]*\)[.!]?$/i;
|
|
933
|
-
var PSEUDOCODE_RE = /%\w+%|\[opt\]|(?:^|\s)<[A-Za-z]\w
|
|
934
|
+
var PSEUDOCODE_RE = /%\w+%|\[opt\]|(?:^|\s)<[A-Za-z]\w*>|\b[A-Za-z_$][\w$]*\s+x\d+\b|…|\.\.\./;
|
|
935
|
+
var CALL_LABEL_RE = /^([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*)\([^;{}]*\)$/;
|
|
936
|
+
var MULTIPLIER_PSEUDOCODE_RE = /\b[A-Za-z_$][\w$]*\s+x\d+\b/;
|
|
934
937
|
function isBanner(text) {
|
|
935
938
|
const t = text.trim();
|
|
936
939
|
if (!t) return false;
|
|
@@ -942,6 +945,7 @@ function isRegionMarker(text) {
|
|
|
942
945
|
if (match === null) return false;
|
|
943
946
|
const title = (match[1] ?? "").trim();
|
|
944
947
|
if (title.length === 0) return true;
|
|
948
|
+
if (REGION_PROSE_VERB_RE.test(title)) return false;
|
|
945
949
|
if (!REGION_TITLE_RE.test(title)) return false;
|
|
946
950
|
return title.split(/\s+/).length <= REGION_TITLE_MAX_WORDS;
|
|
947
951
|
}
|
|
@@ -957,6 +961,15 @@ function looksLikeCode(text, allowCall = true) {
|
|
|
957
961
|
function hasPseudocode(text) {
|
|
958
962
|
return PSEUDOCODE_RE.test(text);
|
|
959
963
|
}
|
|
964
|
+
function testCallMatrixStems(comments) {
|
|
965
|
+
const stems = /* @__PURE__ */ new Set();
|
|
966
|
+
for (const comment of comments) {
|
|
967
|
+
const body2 = stripCommentMarker(comment.value);
|
|
968
|
+
const stem3 = CALL_LABEL_RE.exec(body2)?.[1];
|
|
969
|
+
if (stem3 !== void 0 && MULTIPLIER_PSEUDOCODE_RE.test(body2)) stems.add(stem3);
|
|
970
|
+
}
|
|
971
|
+
return stems;
|
|
972
|
+
}
|
|
960
973
|
function isEnumeratedProseItem(text) {
|
|
961
974
|
const t = text.trim();
|
|
962
975
|
return ENUMERATED_ITEM_RE.test(t) && t.split(/\s+/).length >= ENUMERATED_ITEM_MIN_WORDS;
|
|
@@ -1245,6 +1258,7 @@ var no_comment_cruft_default = createRule({
|
|
|
1245
1258
|
return {
|
|
1246
1259
|
Program() {
|
|
1247
1260
|
const comments = sourceCode.getAllComments();
|
|
1261
|
+
const callMatrixStems = isTestFile(context.filename) ? testCallMatrixStems(comments) : /* @__PURE__ */ new Set();
|
|
1248
1262
|
const walls = findCommentWalls(comments);
|
|
1249
1263
|
const wallByLeader = new Map(walls.map((wall) => [wall.leader, wall]));
|
|
1250
1264
|
const wallMembers = new Set(walls.flatMap((wall) => [...wall.members]));
|
|
@@ -1282,6 +1296,8 @@ var no_comment_cruft_default = createRule({
|
|
|
1282
1296
|
continue;
|
|
1283
1297
|
}
|
|
1284
1298
|
const firstText = texts[0];
|
|
1299
|
+
const firstTextStem = firstText === void 0 ? void 0 : CALL_LABEL_RE.exec(firstText)?.[1];
|
|
1300
|
+
if (firstTextStem !== void 0 && texts.length === 1 && callMatrixStems.has(firstTextStem)) continue;
|
|
1285
1301
|
if (firstText !== void 0 && /^(?:todo|fixme)\b/i.test(firstText)) {
|
|
1286
1302
|
if (!runCitesAReference(comments, i)) {
|
|
1287
1303
|
context.report({
|
|
@@ -1486,13 +1502,17 @@ function calleeRootName(call) {
|
|
|
1486
1502
|
var isAssertionCall = (node) => node.type === import_utils8.AST_NODE_TYPES.CallExpression && ASSERTION_ROOTS.has(calleeRootName(node) ?? "");
|
|
1487
1503
|
var isTypeAssertionCall = (node) => node.type === import_utils8.AST_NODE_TYPES.CallExpression && TYPE_ASSERTION_ROOTS.has(calleeRootName(node) ?? "");
|
|
1488
1504
|
var containsAssertion = (node) => subtreeMatches(node, isAssertionCall);
|
|
1505
|
+
var containsRuntimeAssertion = (node) => subtreeMatches(
|
|
1506
|
+
node,
|
|
1507
|
+
(current) => isAssertionCall(current) && !isTypeAssertionCall(current)
|
|
1508
|
+
);
|
|
1489
1509
|
var containsSkipCall = (node) => subtreeMatches(
|
|
1490
1510
|
node,
|
|
1491
1511
|
(current) => current.type === import_utils8.AST_NODE_TYPES.CallExpression && current.callee.type === import_utils8.AST_NODE_TYPES.MemberExpression && !current.callee.computed && current.callee.property.type === import_utils8.AST_NODE_TYPES.Identifier && current.callee.property.name === "skip"
|
|
1492
1512
|
);
|
|
1493
1513
|
var containsEscape = (node) => subtreeMatches(
|
|
1494
1514
|
node,
|
|
1495
|
-
(current) => current.type === import_utils8.AST_NODE_TYPES.ReturnStatement || current.type === import_utils8.AST_NODE_TYPES.ContinueStatement || current.type === import_utils8.AST_NODE_TYPES.BreakStatement,
|
|
1515
|
+
(current) => current.type === import_utils8.AST_NODE_TYPES.ReturnStatement || current.type === import_utils8.AST_NODE_TYPES.ContinueStatement || current.type === import_utils8.AST_NODE_TYPES.BreakStatement || current.type === import_utils8.AST_NODE_TYPES.ThrowStatement,
|
|
1496
1516
|
false
|
|
1497
1517
|
);
|
|
1498
1518
|
function branchStatements(branch) {
|
|
@@ -1523,7 +1543,7 @@ function isPinnedNarrowingGuard(node) {
|
|
|
1523
1543
|
}
|
|
1524
1544
|
let matched = false;
|
|
1525
1545
|
subtreeMatches(previous, (current) => {
|
|
1526
|
-
if (current.type !== import_utils8.AST_NODE_TYPES.CallExpression ||
|
|
1546
|
+
if (current.type !== import_utils8.AST_NODE_TYPES.CallExpression || !ASSERTION_ROOTS.has(calleeRootName(current) ?? "")) {
|
|
1527
1547
|
return false;
|
|
1528
1548
|
}
|
|
1529
1549
|
const subject = current.arguments[0];
|
|
@@ -1579,6 +1599,30 @@ function isInertNormalization(node) {
|
|
|
1579
1599
|
function isExemptIfStatement(node) {
|
|
1580
1600
|
return isPinnedNarrowingGuard(node) || isThrowingGuard(node) || isTypeLevelNarrowing(node) || isInertNormalization(node);
|
|
1581
1601
|
}
|
|
1602
|
+
function skipsAssertionOrTest(node) {
|
|
1603
|
+
const branches = [node.consequent, node.alternate].filter(
|
|
1604
|
+
(branch) => branch !== null
|
|
1605
|
+
);
|
|
1606
|
+
if (branches.some(
|
|
1607
|
+
(branch) => containsEscape(branch) || containsSkipCall(branch)
|
|
1608
|
+
)) {
|
|
1609
|
+
return true;
|
|
1610
|
+
}
|
|
1611
|
+
const asserted = branches.map(containsRuntimeAssertion);
|
|
1612
|
+
return asserted.some(Boolean) && (node.alternate === null || !asserted.every(Boolean));
|
|
1613
|
+
}
|
|
1614
|
+
function switchSkipsAssertion(node) {
|
|
1615
|
+
const asserted = node.cases.map(
|
|
1616
|
+
(caseNode) => caseNode.consequent.some(containsRuntimeAssertion)
|
|
1617
|
+
);
|
|
1618
|
+
if (!asserted.some(Boolean)) return false;
|
|
1619
|
+
return node.cases.every((caseNode) => caseNode.test !== null) || !asserted.every(Boolean);
|
|
1620
|
+
}
|
|
1621
|
+
function conditionalSkipsAssertion(node) {
|
|
1622
|
+
const consequent = containsRuntimeAssertion(node.consequent);
|
|
1623
|
+
const alternate = containsRuntimeAssertion(node.alternate);
|
|
1624
|
+
return consequent !== alternate;
|
|
1625
|
+
}
|
|
1582
1626
|
function isShortCircuitedAssertion(node) {
|
|
1583
1627
|
return node.operator !== "??" && node.parent.type === import_utils8.AST_NODE_TYPES.ExpressionStatement && containsAssertion(node.right);
|
|
1584
1628
|
}
|
|
@@ -1587,11 +1631,11 @@ var no_conditional_in_test_default = createRule({
|
|
|
1587
1631
|
meta: {
|
|
1588
1632
|
type: "problem",
|
|
1589
1633
|
docs: {
|
|
1590
|
-
description: "Disallow
|
|
1634
|
+
description: "Disallow test conditionals that can skip a runtime assertion or exit the test before one runs."
|
|
1591
1635
|
},
|
|
1592
1636
|
schema: [],
|
|
1593
1637
|
messages: {
|
|
1594
|
-
noConditionalInTest: "
|
|
1638
|
+
noConditionalInTest: "This conditional can skip a runtime assertion or exit the test before it runs. Make the assertion unconditional or split the test."
|
|
1595
1639
|
}
|
|
1596
1640
|
},
|
|
1597
1641
|
defaultOptions: [],
|
|
@@ -1608,16 +1652,16 @@ var no_conditional_in_test_default = createRule({
|
|
|
1608
1652
|
};
|
|
1609
1653
|
return {
|
|
1610
1654
|
IfStatement(node) {
|
|
1611
|
-
if (isExemptIfStatement(node)) {
|
|
1655
|
+
if (isExemptIfStatement(node) || !skipsAssertionOrTest(node)) {
|
|
1612
1656
|
return;
|
|
1613
1657
|
}
|
|
1614
1658
|
report(node);
|
|
1615
1659
|
},
|
|
1616
1660
|
SwitchStatement(node) {
|
|
1617
|
-
report(node);
|
|
1661
|
+
if (switchSkipsAssertion(node)) report(node);
|
|
1618
1662
|
},
|
|
1619
1663
|
ConditionalExpression(node) {
|
|
1620
|
-
report(node);
|
|
1664
|
+
if (conditionalSkipsAssertion(node)) report(node);
|
|
1621
1665
|
},
|
|
1622
1666
|
LogicalExpression(node) {
|
|
1623
1667
|
if (!isShortCircuitedAssertion(node)) {
|
|
@@ -2211,6 +2255,20 @@ var PURE_METHODS = /* @__PURE__ */ new Set([
|
|
|
2211
2255
|
"startsWith",
|
|
2212
2256
|
"endsWith"
|
|
2213
2257
|
]);
|
|
2258
|
+
var SYNC_CALLBACK_METHODS = /* @__PURE__ */ new Set([
|
|
2259
|
+
"every",
|
|
2260
|
+
"filter",
|
|
2261
|
+
"findIndex",
|
|
2262
|
+
"findLast",
|
|
2263
|
+
"findLastIndex",
|
|
2264
|
+
"flatMap",
|
|
2265
|
+
"forEach",
|
|
2266
|
+
"map",
|
|
2267
|
+
"reduce",
|
|
2268
|
+
"reduceRight",
|
|
2269
|
+
"some",
|
|
2270
|
+
"sort"
|
|
2271
|
+
]);
|
|
2214
2272
|
var PURE_NAMESPACES = /* @__PURE__ */ new Set([
|
|
2215
2273
|
"Object",
|
|
2216
2274
|
"Array",
|
|
@@ -2260,7 +2318,17 @@ function isPureCall(node) {
|
|
|
2260
2318
|
if (callee.object.type === import_utils13.AST_NODE_TYPES.Identifier && PURE_NAMESPACES.has(callee.object.name)) {
|
|
2261
2319
|
return !IMPURE_NAMESPACE_METHODS.has(`${callee.object.name}.${property.name}`);
|
|
2262
2320
|
}
|
|
2263
|
-
return PURE_METHODS.has(property.name);
|
|
2321
|
+
return PURE_METHODS.has(property.name) && (!SYNC_CALLBACK_METHODS.has(property.name) || !synchronousCallbackCanThrow(node));
|
|
2322
|
+
}
|
|
2323
|
+
function synchronousCallbackCanThrow(node) {
|
|
2324
|
+
return node.arguments.some((argument) => {
|
|
2325
|
+
if (argument.type !== import_utils13.AST_NODE_TYPES.ArrowFunctionExpression && argument.type !== import_utils13.AST_NODE_TYPES.FunctionExpression) return false;
|
|
2326
|
+
if (argument.async) return false;
|
|
2327
|
+
return subtreeMatches2(
|
|
2328
|
+
argument.body,
|
|
2329
|
+
(current) => current.type === import_utils13.AST_NODE_TYPES.ThrowStatement || current.type === import_utils13.AST_NODE_TYPES.CallExpression && current.callee.type === import_utils13.AST_NODE_TYPES.MemberExpression && !current.callee.computed && current.callee.object.type === import_utils13.AST_NODE_TYPES.Identifier && current.callee.object.name === "JSON" && current.callee.property.type === import_utils13.AST_NODE_TYPES.Identifier && current.callee.property.name === "parse"
|
|
2330
|
+
);
|
|
2331
|
+
});
|
|
2264
2332
|
}
|
|
2265
2333
|
function isPureNew(node) {
|
|
2266
2334
|
return node.callee.type === import_utils13.AST_NODE_TYPES.Identifier && PURE_CONSTRUCTORS.has(node.callee.name);
|
|
@@ -3147,11 +3215,233 @@ var no_json_stringify_error_default = createRule({
|
|
|
3147
3215
|
}
|
|
3148
3216
|
});
|
|
3149
3217
|
|
|
3218
|
+
// src/rules/no-impossible-zod-literal-bounds.ts
|
|
3219
|
+
var import_utils18 = require("@typescript-eslint/utils");
|
|
3220
|
+
|
|
3221
|
+
// src/rules/_zod.ts
|
|
3222
|
+
var ZOD_PREFIX_RE = /^Z[A-Z]/;
|
|
3223
|
+
var ZOD_SUFFIX_RE = /Schema$/;
|
|
3224
|
+
var ZOD_SCHEMA_NAME_RE = /Schema$|^Z[A-Z]/;
|
|
3225
|
+
function isZodModule(source) {
|
|
3226
|
+
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
3227
|
+
}
|
|
3228
|
+
|
|
3229
|
+
// src/rules/no-impossible-zod-literal-bounds.ts
|
|
3230
|
+
var KINDS = /* @__PURE__ */ new Set(["array", "number", "string"]);
|
|
3231
|
+
var NUMBER_METHODS = /* @__PURE__ */ new Set([
|
|
3232
|
+
"gt",
|
|
3233
|
+
"gte",
|
|
3234
|
+
"lt",
|
|
3235
|
+
"lte",
|
|
3236
|
+
"max",
|
|
3237
|
+
"min"
|
|
3238
|
+
]);
|
|
3239
|
+
var LENGTH_METHODS = /* @__PURE__ */ new Set(["length", "max", "min"]);
|
|
3240
|
+
var RESHAPING_METHODS = /* @__PURE__ */ new Set([
|
|
3241
|
+
"pipe",
|
|
3242
|
+
"preprocess",
|
|
3243
|
+
"transform"
|
|
3244
|
+
]);
|
|
3245
|
+
function importedName(specifier) {
|
|
3246
|
+
return specifier.imported.type === import_utils18.AST_NODE_TYPES.Identifier ? specifier.imported.name : typeof specifier.imported.value === "string" ? specifier.imported.value : null;
|
|
3247
|
+
}
|
|
3248
|
+
function memberName(node) {
|
|
3249
|
+
if (!node.computed && node.property.type === import_utils18.AST_NODE_TYPES.Identifier) {
|
|
3250
|
+
return node.property.name;
|
|
3251
|
+
}
|
|
3252
|
+
if (node.computed && node.property.type === import_utils18.AST_NODE_TYPES.Literal && typeof node.property.value === "string") {
|
|
3253
|
+
return node.property.value;
|
|
3254
|
+
}
|
|
3255
|
+
return null;
|
|
3256
|
+
}
|
|
3257
|
+
function finiteNumber(node) {
|
|
3258
|
+
if (node?.type === import_utils18.AST_NODE_TYPES.Literal && typeof node.value === "number") {
|
|
3259
|
+
return Number.isFinite(node.value) ? node.value : null;
|
|
3260
|
+
}
|
|
3261
|
+
if (node?.type === import_utils18.AST_NODE_TYPES.UnaryExpression && (node.operator === "-" || node.operator === "+") && node.argument.type === import_utils18.AST_NODE_TYPES.Literal && typeof node.argument.value === "number") {
|
|
3262
|
+
const value = node.operator === "-" ? -node.argument.value : node.argument.value;
|
|
3263
|
+
return Number.isFinite(value) ? value : null;
|
|
3264
|
+
}
|
|
3265
|
+
return null;
|
|
3266
|
+
}
|
|
3267
|
+
function strongerLower(current, candidate) {
|
|
3268
|
+
if (current === null || candidate.value > current.value || candidate.value === current.value && candidate.exclusive && !current.exclusive) {
|
|
3269
|
+
return candidate;
|
|
3270
|
+
}
|
|
3271
|
+
return current;
|
|
3272
|
+
}
|
|
3273
|
+
function strongerUpper(current, candidate) {
|
|
3274
|
+
if (current === null || candidate.value < current.value || candidate.value === current.value && candidate.exclusive && !current.exclusive) {
|
|
3275
|
+
return candidate;
|
|
3276
|
+
}
|
|
3277
|
+
return current;
|
|
3278
|
+
}
|
|
3279
|
+
function isEmpty(lower, upper) {
|
|
3280
|
+
if (lower === null || upper === null) return false;
|
|
3281
|
+
return lower.value > upper.value || lower.value === upper.value && (lower.exclusive || upper.exclusive);
|
|
3282
|
+
}
|
|
3283
|
+
function isOutermostCall(node) {
|
|
3284
|
+
const parent = node.parent;
|
|
3285
|
+
return !(parent?.type === import_utils18.AST_NODE_TYPES.MemberExpression && parent.object === node && parent.parent?.type === import_utils18.AST_NODE_TYPES.CallExpression && parent.parent.callee === parent);
|
|
3286
|
+
}
|
|
3287
|
+
var no_impossible_zod_literal_bounds_default = createRule({
|
|
3288
|
+
name: "no-impossible-zod-literal-bounds",
|
|
3289
|
+
meta: {
|
|
3290
|
+
type: "problem",
|
|
3291
|
+
docs: {
|
|
3292
|
+
description: "Disallow same-chain literal Zod bounds whose accepted set is mathematically empty."
|
|
3293
|
+
},
|
|
3294
|
+
schema: [],
|
|
3295
|
+
messages: {
|
|
3296
|
+
impossibleBounds: "This Zod {{kind}} schema accepts no values: {{lower}} conflicts with {{upper}}."
|
|
3297
|
+
}
|
|
3298
|
+
},
|
|
3299
|
+
defaultOptions: [],
|
|
3300
|
+
create(context) {
|
|
3301
|
+
const sourceCode = context.sourceCode;
|
|
3302
|
+
if (isTestFile(context.filename) || isGeneratedFile(context.filename, sourceCode.getText())) {
|
|
3303
|
+
return {};
|
|
3304
|
+
}
|
|
3305
|
+
const namespaces = /* @__PURE__ */ new Set();
|
|
3306
|
+
const constructors = /* @__PURE__ */ new Map();
|
|
3307
|
+
const preprocessors = /* @__PURE__ */ new Set();
|
|
3308
|
+
const importBindings = /* @__PURE__ */ new Map();
|
|
3309
|
+
function resolvesToTrackedImport(node) {
|
|
3310
|
+
const binding = importBindings.get(node.name);
|
|
3311
|
+
if (binding === void 0) return false;
|
|
3312
|
+
let scope = sourceCode.getScope(node);
|
|
3313
|
+
while (scope !== null) {
|
|
3314
|
+
const variable = scope.variables.find((candidate) => candidate.name === node.name);
|
|
3315
|
+
if (variable !== void 0) {
|
|
3316
|
+
return variable.defs.some((definition) => definition.name === binding);
|
|
3317
|
+
}
|
|
3318
|
+
scope = scope.upper;
|
|
3319
|
+
}
|
|
3320
|
+
return false;
|
|
3321
|
+
}
|
|
3322
|
+
function baseKind(node) {
|
|
3323
|
+
const callee = node.callee;
|
|
3324
|
+
if (callee.type === import_utils18.AST_NODE_TYPES.Identifier) {
|
|
3325
|
+
return resolvesToTrackedImport(callee) ? constructors.get(callee.name) ?? null : null;
|
|
3326
|
+
}
|
|
3327
|
+
if (callee.type !== import_utils18.AST_NODE_TYPES.MemberExpression || callee.object.type !== import_utils18.AST_NODE_TYPES.Identifier || !namespaces.has(callee.object.name) || !resolvesToTrackedImport(callee.object)) {
|
|
3328
|
+
return null;
|
|
3329
|
+
}
|
|
3330
|
+
const name = memberName(callee);
|
|
3331
|
+
return name !== null && KINDS.has(name) ? name : null;
|
|
3332
|
+
}
|
|
3333
|
+
function readChain(node) {
|
|
3334
|
+
const calls = [];
|
|
3335
|
+
let current = node;
|
|
3336
|
+
while (true) {
|
|
3337
|
+
const kind = baseKind(current);
|
|
3338
|
+
if (kind !== null) return { calls, kind };
|
|
3339
|
+
const callee = current.callee;
|
|
3340
|
+
if (callee.type !== import_utils18.AST_NODE_TYPES.MemberExpression || callee.object.type !== import_utils18.AST_NODE_TYPES.CallExpression) {
|
|
3341
|
+
return null;
|
|
3342
|
+
}
|
|
3343
|
+
const method = memberName(callee);
|
|
3344
|
+
if (method === null) return null;
|
|
3345
|
+
calls.push({ method, node: current });
|
|
3346
|
+
current = callee.object;
|
|
3347
|
+
}
|
|
3348
|
+
}
|
|
3349
|
+
function isInsideReshapingCall(node) {
|
|
3350
|
+
let child = node;
|
|
3351
|
+
let parent = child.parent;
|
|
3352
|
+
while (parent !== void 0 && parent.type !== import_utils18.AST_NODE_TYPES.Program) {
|
|
3353
|
+
if (parent.type === import_utils18.AST_NODE_TYPES.CallExpression) {
|
|
3354
|
+
const callee = parent.callee;
|
|
3355
|
+
if (callee.type === import_utils18.AST_NODE_TYPES.MemberExpression && RESHAPING_METHODS.has(memberName(callee) ?? "") && (callee.object.type === import_utils18.AST_NODE_TYPES.CallExpression || callee.object.type === import_utils18.AST_NODE_TYPES.Identifier && namespaces.has(callee.object.name) && resolvesToTrackedImport(callee.object))) {
|
|
3356
|
+
return true;
|
|
3357
|
+
}
|
|
3358
|
+
if (callee.type === import_utils18.AST_NODE_TYPES.Identifier && preprocessors.has(callee.name) && resolvesToTrackedImport(callee)) {
|
|
3359
|
+
return true;
|
|
3360
|
+
}
|
|
3361
|
+
}
|
|
3362
|
+
child = parent;
|
|
3363
|
+
parent = child.parent;
|
|
3364
|
+
}
|
|
3365
|
+
return false;
|
|
3366
|
+
}
|
|
3367
|
+
function contradiction(chain) {
|
|
3368
|
+
const allowed = chain.kind === "number" ? NUMBER_METHODS : LENGTH_METHODS;
|
|
3369
|
+
let lower = null;
|
|
3370
|
+
let upper = null;
|
|
3371
|
+
for (const { method, node } of chain.calls) {
|
|
3372
|
+
if (!allowed.has(method)) return null;
|
|
3373
|
+
const value = finiteNumber(node.arguments[0]);
|
|
3374
|
+
if (value === null) return null;
|
|
3375
|
+
if (chain.kind !== "number" && (!Number.isInteger(value) || value < 0)) {
|
|
3376
|
+
return null;
|
|
3377
|
+
}
|
|
3378
|
+
const label = `${method}(${String(value)})`;
|
|
3379
|
+
if (method === "length") {
|
|
3380
|
+
lower = strongerLower(lower, { exclusive: false, label, value });
|
|
3381
|
+
upper = strongerUpper(upper, { exclusive: false, label, value });
|
|
3382
|
+
} else if (method === "gt" || method === "gte" || method === "min") {
|
|
3383
|
+
lower = strongerLower(lower, {
|
|
3384
|
+
exclusive: method === "gt",
|
|
3385
|
+
label,
|
|
3386
|
+
value
|
|
3387
|
+
});
|
|
3388
|
+
} else {
|
|
3389
|
+
upper = strongerUpper(upper, {
|
|
3390
|
+
exclusive: method === "lt",
|
|
3391
|
+
label,
|
|
3392
|
+
value
|
|
3393
|
+
});
|
|
3394
|
+
}
|
|
3395
|
+
}
|
|
3396
|
+
return isEmpty(lower, upper) && lower !== null && upper !== null ? { lower, upper } : null;
|
|
3397
|
+
}
|
|
3398
|
+
return {
|
|
3399
|
+
ImportDeclaration(node) {
|
|
3400
|
+
if (!isZodModule(node.source.value)) return;
|
|
3401
|
+
for (const specifier of node.specifiers) {
|
|
3402
|
+
if (specifier.type === import_utils18.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils18.AST_NODE_TYPES.ImportDefaultSpecifier) {
|
|
3403
|
+
namespaces.add(specifier.local.name);
|
|
3404
|
+
importBindings.set(specifier.local.name, specifier.local);
|
|
3405
|
+
continue;
|
|
3406
|
+
}
|
|
3407
|
+
const imported = importedName(specifier);
|
|
3408
|
+
if (imported === "z") {
|
|
3409
|
+
namespaces.add(specifier.local.name);
|
|
3410
|
+
importBindings.set(specifier.local.name, specifier.local);
|
|
3411
|
+
} else if (imported !== null && KINDS.has(imported)) {
|
|
3412
|
+
constructors.set(specifier.local.name, imported);
|
|
3413
|
+
importBindings.set(specifier.local.name, specifier.local);
|
|
3414
|
+
} else if (imported === "preprocess") {
|
|
3415
|
+
preprocessors.add(specifier.local.name);
|
|
3416
|
+
importBindings.set(specifier.local.name, specifier.local);
|
|
3417
|
+
}
|
|
3418
|
+
}
|
|
3419
|
+
},
|
|
3420
|
+
CallExpression(node) {
|
|
3421
|
+
if (!isOutermostCall(node) || isInsideReshapingCall(node)) return;
|
|
3422
|
+
const chain = readChain(node);
|
|
3423
|
+
if (chain === null) return;
|
|
3424
|
+
const conflict = contradiction(chain);
|
|
3425
|
+
if (conflict === null) return;
|
|
3426
|
+
context.report({
|
|
3427
|
+
node,
|
|
3428
|
+
messageId: "impossibleBounds",
|
|
3429
|
+
data: {
|
|
3430
|
+
kind: chain.kind,
|
|
3431
|
+
lower: conflict.lower.label,
|
|
3432
|
+
upper: conflict.upper.label
|
|
3433
|
+
}
|
|
3434
|
+
});
|
|
3435
|
+
}
|
|
3436
|
+
};
|
|
3437
|
+
}
|
|
3438
|
+
});
|
|
3439
|
+
|
|
3150
3440
|
// src/rules/no-log-only-catch.ts
|
|
3151
|
-
var
|
|
3441
|
+
var import_utils20 = require("@typescript-eslint/utils");
|
|
3152
3442
|
|
|
3153
3443
|
// src/rules/_logging.ts
|
|
3154
|
-
var
|
|
3444
|
+
var import_utils19 = require("@typescript-eslint/utils");
|
|
3155
3445
|
var LOG_METHODS = /* @__PURE__ */ new Set([
|
|
3156
3446
|
"debug",
|
|
3157
3447
|
"info",
|
|
@@ -3255,29 +3545,29 @@ function createLogMatcher(options = {}) {
|
|
|
3255
3545
|
// src/rules/no-log-only-catch.ts
|
|
3256
3546
|
var BENCHMARK_DIR_RE = /(?:^|[\\/])benchmarks?[\\/]/;
|
|
3257
3547
|
var SINGLE_STATEMENT_HOSTS = /* @__PURE__ */ new Set([
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3548
|
+
import_utils20.AST_NODE_TYPES.DoWhileStatement,
|
|
3549
|
+
import_utils20.AST_NODE_TYPES.ForInStatement,
|
|
3550
|
+
import_utils20.AST_NODE_TYPES.ForOfStatement,
|
|
3551
|
+
import_utils20.AST_NODE_TYPES.ForStatement,
|
|
3552
|
+
import_utils20.AST_NODE_TYPES.IfStatement,
|
|
3553
|
+
import_utils20.AST_NODE_TYPES.WhileStatement
|
|
3264
3554
|
]);
|
|
3265
3555
|
var FUNCTION_TYPES3 = /* @__PURE__ */ new Set([
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3556
|
+
import_utils20.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
3557
|
+
import_utils20.AST_NODE_TYPES.FunctionDeclaration,
|
|
3558
|
+
import_utils20.AST_NODE_TYPES.FunctionExpression
|
|
3269
3559
|
]);
|
|
3270
3560
|
function statementSlot(node) {
|
|
3271
3561
|
const parent = node.parent;
|
|
3272
3562
|
if (parent === void 0) return null;
|
|
3273
3563
|
let list;
|
|
3274
3564
|
switch (parent.type) {
|
|
3275
|
-
case
|
|
3276
|
-
case
|
|
3277
|
-
case
|
|
3565
|
+
case import_utils20.AST_NODE_TYPES.BlockStatement:
|
|
3566
|
+
case import_utils20.AST_NODE_TYPES.Program:
|
|
3567
|
+
case import_utils20.AST_NODE_TYPES.StaticBlock:
|
|
3278
3568
|
list = parent.body;
|
|
3279
3569
|
break;
|
|
3280
|
-
case
|
|
3570
|
+
case import_utils20.AST_NODE_TYPES.SwitchCase:
|
|
3281
3571
|
list = parent.consequent;
|
|
3282
3572
|
break;
|
|
3283
3573
|
default:
|
|
@@ -3289,7 +3579,7 @@ function statementSlot(node) {
|
|
|
3289
3579
|
function fallbackFollowsTry(tryStatement) {
|
|
3290
3580
|
const body2 = tryStatement.block.body;
|
|
3291
3581
|
const last = body2.at(-1);
|
|
3292
|
-
return last?.type ===
|
|
3582
|
+
return last?.type === import_utils20.AST_NODE_TYPES.ReturnStatement && hasFollowingStatement(tryStatement);
|
|
3293
3583
|
}
|
|
3294
3584
|
function hasFollowingStatement(node) {
|
|
3295
3585
|
for (let current = node; current !== void 0 && !FUNCTION_TYPES3.has(current.type); current = current.parent) {
|
|
@@ -3302,14 +3592,14 @@ function seededFallbackHandled(tryStatement, scope) {
|
|
|
3302
3592
|
const slot = statementSlot(tryStatement);
|
|
3303
3593
|
if (slot === null || slot.index === 0) return false;
|
|
3304
3594
|
const previous = slot.list[slot.index - 1];
|
|
3305
|
-
if (previous?.type !==
|
|
3595
|
+
if (previous?.type !== import_utils20.AST_NODE_TYPES.VariableDeclaration || previous.kind === "const") {
|
|
3306
3596
|
return false;
|
|
3307
3597
|
}
|
|
3308
3598
|
const declarator = previous.declarations[0];
|
|
3309
3599
|
if (previous.declarations.length !== 1 || declarator === void 0) return false;
|
|
3310
|
-
if (declarator.id.type !==
|
|
3600
|
+
if (declarator.id.type !== import_utils20.AST_NODE_TYPES.Identifier) return false;
|
|
3311
3601
|
if (declarator.init == null || !isSeedValue(declarator.init)) return false;
|
|
3312
|
-
const variable =
|
|
3602
|
+
const variable = import_utils20.ASTUtils.findVariable(scope, declarator.id.name);
|
|
3313
3603
|
if (variable === null) return false;
|
|
3314
3604
|
const [tryStart, tryEnd] = tryStatement.block.range;
|
|
3315
3605
|
let writtenInTry = false;
|
|
@@ -3322,17 +3612,17 @@ function seededFallbackHandled(tryStatement, scope) {
|
|
|
3322
3612
|
return writtenInTry && readAfter;
|
|
3323
3613
|
}
|
|
3324
3614
|
function isSeedValue(node) {
|
|
3325
|
-
const inner = node.type ===
|
|
3615
|
+
const inner = node.type === import_utils20.AST_NODE_TYPES.TSAsExpression ? node.expression : node;
|
|
3326
3616
|
switch (inner.type) {
|
|
3327
|
-
case
|
|
3617
|
+
case import_utils20.AST_NODE_TYPES.Literal:
|
|
3328
3618
|
return true;
|
|
3329
|
-
case
|
|
3619
|
+
case import_utils20.AST_NODE_TYPES.Identifier:
|
|
3330
3620
|
return inner.name === "undefined";
|
|
3331
|
-
case
|
|
3332
|
-
return inner.argument.type ===
|
|
3333
|
-
case
|
|
3621
|
+
case import_utils20.AST_NODE_TYPES.UnaryExpression:
|
|
3622
|
+
return inner.argument.type === import_utils20.AST_NODE_TYPES.Literal;
|
|
3623
|
+
case import_utils20.AST_NODE_TYPES.ArrayExpression:
|
|
3334
3624
|
return inner.elements.length === 0;
|
|
3335
|
-
case
|
|
3625
|
+
case import_utils20.AST_NODE_TYPES.ObjectExpression:
|
|
3336
3626
|
return inner.properties.length === 0;
|
|
3337
3627
|
default:
|
|
3338
3628
|
return false;
|
|
@@ -3376,7 +3666,7 @@ var no_log_only_catch_default = createRule({
|
|
|
3376
3666
|
const tryStatement = node.parent;
|
|
3377
3667
|
if (hasCommentDirectlyAbove(tryStatement) || hasCommentDirectlyAbove(node)) return true;
|
|
3378
3668
|
const block = tryStatement.parent;
|
|
3379
|
-
if (block?.type !==
|
|
3669
|
+
if (block?.type !== import_utils20.AST_NODE_TYPES.BlockStatement || block.body.length !== 1 || block.parent === void 0 || !SINGLE_STATEMENT_HOSTS.has(block.parent.type)) {
|
|
3380
3670
|
return false;
|
|
3381
3671
|
}
|
|
3382
3672
|
return hasCommentDirectlyAbove(block.parent);
|
|
@@ -3413,10 +3703,10 @@ var no_log_only_catch_default = createRule({
|
|
|
3413
3703
|
});
|
|
3414
3704
|
|
|
3415
3705
|
// src/rules/no-long-comment.ts
|
|
3416
|
-
var
|
|
3706
|
+
var import_utils22 = require("@typescript-eslint/utils");
|
|
3417
3707
|
|
|
3418
3708
|
// src/rules/_prose-budget.ts
|
|
3419
|
-
var
|
|
3709
|
+
var import_utils21 = require("@typescript-eslint/utils");
|
|
3420
3710
|
var DIRECTIVE_RE2 = /^(?:!|eslint\b|eslint-|@ts-|prettier|biome-|c8\b|v8\b|istanbul\b|@vite|webpack|@jsx|@jest-environment|@vitest-environment|#__|todo\b|fixme\b|hack\b)/i;
|
|
3421
3711
|
var LICENSE_RE2 = /\b(?:copyright|spdx-license-identifier|licensed under)\b/i;
|
|
3422
3712
|
var TYPED_TAG_RE = /@(arg|argument|param|return|returns|yield|yields)\b/i;
|
|
@@ -3485,15 +3775,15 @@ function proseGroups(filename, sourceCode, includeValueTags = false) {
|
|
|
3485
3775
|
return groups;
|
|
3486
3776
|
}
|
|
3487
3777
|
function annotatedParameter(parameter) {
|
|
3488
|
-
if (parameter.type ===
|
|
3489
|
-
const target = parameter.type ===
|
|
3778
|
+
if (parameter.type === import_utils21.AST_NODE_TYPES.TSParameterProperty) return annotatedParameter(parameter.parameter);
|
|
3779
|
+
const target = parameter.type === import_utils21.AST_NODE_TYPES.AssignmentPattern ? parameter.left : parameter;
|
|
3490
3780
|
return "typeAnnotation" in target && target.typeAnnotation != null;
|
|
3491
3781
|
}
|
|
3492
3782
|
function documentsTypedFunction(sourceCode, comment) {
|
|
3493
3783
|
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
3494
3784
|
if (token === null || token.loc.start.line !== comment.loc.end.line + 1) return false;
|
|
3495
3785
|
let node = sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
3496
|
-
while (node != null && node.type !==
|
|
3786
|
+
while (node != null && node.type !== import_utils21.AST_NODE_TYPES.Program) {
|
|
3497
3787
|
if (typedFunction(node)) return true;
|
|
3498
3788
|
node = node.parent ?? null;
|
|
3499
3789
|
}
|
|
@@ -3501,19 +3791,19 @@ function documentsTypedFunction(sourceCode, comment) {
|
|
|
3501
3791
|
}
|
|
3502
3792
|
function typedFunction(node) {
|
|
3503
3793
|
switch (node.type) {
|
|
3504
|
-
case
|
|
3505
|
-
case
|
|
3794
|
+
case import_utils21.AST_NODE_TYPES.ExportNamedDeclaration:
|
|
3795
|
+
case import_utils21.AST_NODE_TYPES.ExportDefaultDeclaration:
|
|
3506
3796
|
return node.declaration != null && typedFunction(node.declaration);
|
|
3507
|
-
case
|
|
3508
|
-
case
|
|
3797
|
+
case import_utils21.AST_NODE_TYPES.FunctionDeclaration:
|
|
3798
|
+
case import_utils21.AST_NODE_TYPES.TSDeclareFunction:
|
|
3509
3799
|
return node.returnType != null && node.params.every(annotatedParameter);
|
|
3510
|
-
case
|
|
3800
|
+
case import_utils21.AST_NODE_TYPES.VariableDeclaration: {
|
|
3511
3801
|
const init = node.declarations[0]?.init;
|
|
3512
|
-
return init != null && (init.type ===
|
|
3802
|
+
return init != null && (init.type === import_utils21.AST_NODE_TYPES.ArrowFunctionExpression || init.type === import_utils21.AST_NODE_TYPES.FunctionExpression) && init.returnType != null && init.params.every(annotatedParameter);
|
|
3513
3803
|
}
|
|
3514
|
-
case
|
|
3804
|
+
case import_utils21.AST_NODE_TYPES.MethodDefinition:
|
|
3515
3805
|
return node.value.returnType != null && node.value.params.every(annotatedParameter);
|
|
3516
|
-
case
|
|
3806
|
+
case import_utils21.AST_NODE_TYPES.TSMethodSignature:
|
|
3517
3807
|
return node.returnType != null && node.params.every(annotatedParameter);
|
|
3518
3808
|
default:
|
|
3519
3809
|
return false;
|
|
@@ -3522,17 +3812,22 @@ function typedFunction(node) {
|
|
|
3522
3812
|
|
|
3523
3813
|
// src/rules/no-long-comment.ts
|
|
3524
3814
|
var EXCESSIVE_SENTENCE_COUNT = 8;
|
|
3815
|
+
var EXCESSIVE_WORD_COUNT = 120;
|
|
3816
|
+
var PROSE_WORD_RE = /[\p{L}\p{N}][\p{L}\p{N}'’-]*/gu;
|
|
3525
3817
|
var VERSIONED_DEPENDENCY_TREE_RE = /(?:^|\/)lib\/[^/]*-?v?\d+\.\d+(?:\.\d+)?[^/]*\//iu;
|
|
3526
3818
|
function documentsTypeOrMember(sourceCode, comment) {
|
|
3527
3819
|
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
3528
3820
|
if (token === null || token.loc.start.line !== comment.loc.end.line + 1) return false;
|
|
3529
3821
|
let node = sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
3530
|
-
while (node != null && node.type !==
|
|
3531
|
-
if (node.type ===
|
|
3822
|
+
while (node != null && node.type !== import_utils22.AST_NODE_TYPES.Program) {
|
|
3823
|
+
if (node.type === import_utils22.AST_NODE_TYPES.TSInterfaceDeclaration || node.type === import_utils22.AST_NODE_TYPES.TSTypeAliasDeclaration || node.type === import_utils22.AST_NODE_TYPES.ClassDeclaration || node.type === import_utils22.AST_NODE_TYPES.MethodDefinition || node.type === import_utils22.AST_NODE_TYPES.TSMethodSignature || node.type === import_utils22.AST_NODE_TYPES.TSPropertySignature) return true;
|
|
3532
3824
|
node = node.parent;
|
|
3533
3825
|
}
|
|
3534
3826
|
return false;
|
|
3535
3827
|
}
|
|
3828
|
+
function wordUnits(text) {
|
|
3829
|
+
return text.match(PROSE_WORD_RE)?.length ?? 0;
|
|
3830
|
+
}
|
|
3536
3831
|
var no_long_comment_default = createRule({
|
|
3537
3832
|
name: "no-long-comment",
|
|
3538
3833
|
meta: {
|
|
@@ -3550,7 +3845,7 @@ var no_long_comment_default = createRule({
|
|
|
3550
3845
|
return {
|
|
3551
3846
|
Program() {
|
|
3552
3847
|
for (const group of proseGroups(context.filename, context.sourceCode)) {
|
|
3553
|
-
if (group.comment.type !== "Block" || !group.comment.value.startsWith("*") || group.hasTypedTags || hasDocumentationStructure(group.text) || hasTechnicalAnchor(group.text) || documentsTypedFunction(context.sourceCode, group.comment) || documentsTypeOrMember(context.sourceCode, group.comment) || sentenceUnits(group.text) < EXCESSIVE_SENTENCE_COUNT) continue;
|
|
3848
|
+
if (group.comment.type !== "Block" || !group.comment.value.startsWith("*") || group.hasTypedTags || hasDocumentationStructure(group.text) || hasTechnicalAnchor(group.text) || documentsTypedFunction(context.sourceCode, group.comment) || documentsTypeOrMember(context.sourceCode, group.comment) || sentenceUnits(group.text) < EXCESSIVE_SENTENCE_COUNT && wordUnits(group.text) < EXCESSIVE_WORD_COUNT) continue;
|
|
3554
3849
|
context.report({ node: group.comment, messageId: "tooLong" });
|
|
3555
3850
|
}
|
|
3556
3851
|
}
|
|
@@ -3559,7 +3854,7 @@ var no_long_comment_default = createRule({
|
|
|
3559
3854
|
});
|
|
3560
3855
|
|
|
3561
3856
|
// src/rules/no-generic-single-export-module.ts
|
|
3562
|
-
var
|
|
3857
|
+
var import_utils23 = require("@typescript-eslint/utils");
|
|
3563
3858
|
var GENERIC_STEMS = /* @__PURE__ */ new Set([
|
|
3564
3859
|
"base",
|
|
3565
3860
|
"common",
|
|
@@ -3594,34 +3889,34 @@ function fileParts(filename) {
|
|
|
3594
3889
|
}
|
|
3595
3890
|
function declaredNames(declaration) {
|
|
3596
3891
|
if (declaration.declare === true) return [];
|
|
3597
|
-
if (declaration.type ===
|
|
3598
|
-
if (declaration.type ===
|
|
3892
|
+
if (declaration.type === import_utils23.AST_NODE_TYPES.FunctionDeclaration || declaration.type === import_utils23.AST_NODE_TYPES.ClassDeclaration || declaration.type === import_utils23.AST_NODE_TYPES.TSEnumDeclaration) {
|
|
3893
|
+
if (declaration.type === import_utils23.AST_NODE_TYPES.TSEnumDeclaration && declaration.const) return [];
|
|
3599
3894
|
return declaration.id === null ? [] : [declaration.id.name];
|
|
3600
3895
|
}
|
|
3601
|
-
if (declaration.type ===
|
|
3896
|
+
if (declaration.type === import_utils23.AST_NODE_TYPES.TSModuleDeclaration && declaration.id.type === import_utils23.AST_NODE_TYPES.Identifier) {
|
|
3602
3897
|
return [declaration.id.name];
|
|
3603
3898
|
}
|
|
3604
|
-
if (declaration.type !==
|
|
3899
|
+
if (declaration.type !== import_utils23.AST_NODE_TYPES.VariableDeclaration) return [];
|
|
3605
3900
|
return declaration.declarations.flatMap(
|
|
3606
|
-
(item) => item.id.type ===
|
|
3901
|
+
(item) => item.id.type === import_utils23.AST_NODE_TYPES.Identifier ? [item.id.name] : []
|
|
3607
3902
|
);
|
|
3608
3903
|
}
|
|
3609
3904
|
function typeOnlyBindings(program) {
|
|
3610
3905
|
const names = /* @__PURE__ */ new Set();
|
|
3611
3906
|
const runtimeNames = /* @__PURE__ */ new Set();
|
|
3612
3907
|
for (const statement of program.body) {
|
|
3613
|
-
const declaration = statement.type ===
|
|
3614
|
-
if (declaration?.type ===
|
|
3908
|
+
const declaration = statement.type === import_utils23.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
3909
|
+
if (declaration?.type === import_utils23.AST_NODE_TYPES.TSInterfaceDeclaration || declaration?.type === import_utils23.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
3615
3910
|
names.add(declaration.id.name);
|
|
3616
3911
|
continue;
|
|
3617
3912
|
}
|
|
3618
|
-
if (declaration?.type ===
|
|
3913
|
+
if (declaration?.type === import_utils23.AST_NODE_TYPES.TSEnumDeclaration && declaration.const) {
|
|
3619
3914
|
names.add(declaration.id.name);
|
|
3620
3915
|
continue;
|
|
3621
3916
|
}
|
|
3622
|
-
if (statement.type ===
|
|
3917
|
+
if (statement.type === import_utils23.AST_NODE_TYPES.ImportDeclaration) {
|
|
3623
3918
|
for (const specifier of statement.specifiers) {
|
|
3624
|
-
if (statement.importKind === "type" || specifier.type ===
|
|
3919
|
+
if (statement.importKind === "type" || specifier.type === import_utils23.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === "type") {
|
|
3625
3920
|
names.add(specifier.local.name);
|
|
3626
3921
|
} else {
|
|
3627
3922
|
runtimeNames.add(specifier.local.name);
|
|
@@ -3629,15 +3924,15 @@ function typeOnlyBindings(program) {
|
|
|
3629
3924
|
}
|
|
3630
3925
|
continue;
|
|
3631
3926
|
}
|
|
3632
|
-
if (declaration?.type ===
|
|
3927
|
+
if (declaration?.type === import_utils23.AST_NODE_TYPES.TSDeclareFunction && declaration.id !== null) {
|
|
3633
3928
|
names.add(declaration.id.name);
|
|
3634
3929
|
continue;
|
|
3635
3930
|
}
|
|
3636
3931
|
if (declaration !== null && declaration.declare === true) {
|
|
3637
|
-
if ((declaration.type ===
|
|
3638
|
-
if (declaration.type ===
|
|
3932
|
+
if ((declaration.type === import_utils23.AST_NODE_TYPES.ClassDeclaration || declaration.type === import_utils23.AST_NODE_TYPES.FunctionDeclaration || declaration.type === import_utils23.AST_NODE_TYPES.TSEnumDeclaration || declaration.type === import_utils23.AST_NODE_TYPES.TSModuleDeclaration) && declaration.id !== null && declaration.id.type === import_utils23.AST_NODE_TYPES.Identifier) names.add(declaration.id.name);
|
|
3933
|
+
if (declaration.type === import_utils23.AST_NODE_TYPES.VariableDeclaration) {
|
|
3639
3934
|
for (const item of declaration.declarations) {
|
|
3640
|
-
if (item.id.type ===
|
|
3935
|
+
if (item.id.type === import_utils23.AST_NODE_TYPES.Identifier) names.add(item.id.name);
|
|
3641
3936
|
}
|
|
3642
3937
|
}
|
|
3643
3938
|
continue;
|
|
@@ -3655,21 +3950,21 @@ function runtimeExports(program) {
|
|
|
3655
3950
|
const typeBindings = typeOnlyBindings(program);
|
|
3656
3951
|
let ambiguous = false;
|
|
3657
3952
|
for (const statement of program.body) {
|
|
3658
|
-
if (statement.type ===
|
|
3953
|
+
if (statement.type === import_utils23.AST_NODE_TYPES.ExportAllDeclaration) {
|
|
3659
3954
|
if (statement.exportKind !== "type") ambiguous = true;
|
|
3660
3955
|
continue;
|
|
3661
3956
|
}
|
|
3662
|
-
if (statement.type ===
|
|
3957
|
+
if (statement.type === import_utils23.AST_NODE_TYPES.ExportDefaultDeclaration) {
|
|
3663
3958
|
const declaration = statement.declaration;
|
|
3664
|
-
if (declaration.type ===
|
|
3959
|
+
if (declaration.type === import_utils23.AST_NODE_TYPES.Identifier) {
|
|
3665
3960
|
if (!typeBindings.has(declaration.name)) {
|
|
3666
3961
|
exports2.push({ key: "default", name: declaration.name, node: statement });
|
|
3667
3962
|
}
|
|
3668
|
-
} else if ((declaration.type ===
|
|
3669
|
-
else if (declaration.type !==
|
|
3963
|
+
} else if ((declaration.type === import_utils23.AST_NODE_TYPES.FunctionDeclaration || declaration.type === import_utils23.AST_NODE_TYPES.ClassDeclaration) && declaration.id !== null && declaration.declare !== true) exports2.push({ key: "default", name: declaration.id.name, node: declaration });
|
|
3964
|
+
else if (declaration.type !== import_utils23.AST_NODE_TYPES.TSInterfaceDeclaration && declaration.type !== import_utils23.AST_NODE_TYPES.TSTypeAliasDeclaration) ambiguous = true;
|
|
3670
3965
|
continue;
|
|
3671
3966
|
}
|
|
3672
|
-
if (statement.type !==
|
|
3967
|
+
if (statement.type !== import_utils23.AST_NODE_TYPES.ExportNamedDeclaration || statement.exportKind === "type") continue;
|
|
3673
3968
|
if (statement.source !== null) {
|
|
3674
3969
|
if (statement.specifiers.some((specifier) => specifier.exportKind !== "type")) ambiguous = true;
|
|
3675
3970
|
continue;
|
|
@@ -3680,7 +3975,7 @@ function runtimeExports(program) {
|
|
|
3680
3975
|
}
|
|
3681
3976
|
for (const specifier of statement.specifiers) {
|
|
3682
3977
|
if (specifier.exportKind === "type" || typeBindings.has(specifier.local.name)) continue;
|
|
3683
|
-
const exported = specifier.exported.type ===
|
|
3978
|
+
const exported = specifier.exported.type === import_utils23.AST_NODE_TYPES.Identifier ? specifier.exported.name : specifier.exported.value;
|
|
3684
3979
|
const local = specifier.local.name;
|
|
3685
3980
|
exports2.push({ key: exported, name: exported === "default" ? local : exported, node: specifier });
|
|
3686
3981
|
}
|
|
@@ -3692,15 +3987,15 @@ function publicTypeExportCount(program) {
|
|
|
3692
3987
|
const names = /* @__PURE__ */ new Set();
|
|
3693
3988
|
const typeBindings = typeOnlyBindings(program);
|
|
3694
3989
|
for (const statement of program.body) {
|
|
3695
|
-
if (statement.type !==
|
|
3990
|
+
if (statement.type !== import_utils23.AST_NODE_TYPES.ExportNamedDeclaration) continue;
|
|
3696
3991
|
const declaration = statement.declaration;
|
|
3697
|
-
if (declaration?.type ===
|
|
3992
|
+
if (declaration?.type === import_utils23.AST_NODE_TYPES.TSInterfaceDeclaration || declaration?.type === import_utils23.AST_NODE_TYPES.TSTypeAliasDeclaration) names.add(declaration.id.name);
|
|
3698
3993
|
for (const specifier of statement.specifiers) {
|
|
3699
|
-
const local = specifier.local.type ===
|
|
3994
|
+
const local = specifier.local.type === import_utils23.AST_NODE_TYPES.Identifier ? specifier.local.name : specifier.local.value;
|
|
3700
3995
|
if (statement.exportKind !== "type" && specifier.exportKind !== "type" && !typeBindings.has(local)) {
|
|
3701
3996
|
continue;
|
|
3702
3997
|
}
|
|
3703
|
-
names.add(specifier.exported.type ===
|
|
3998
|
+
names.add(specifier.exported.type === import_utils23.AST_NODE_TYPES.Identifier ? specifier.exported.name : specifier.exported.value);
|
|
3704
3999
|
}
|
|
3705
4000
|
}
|
|
3706
4001
|
return names.size;
|
|
@@ -3709,7 +4004,7 @@ function kebabCase(name) {
|
|
|
3709
4004
|
return name.replaceAll(/oauth/giu, "Oauth").replaceAll(/graphql/giu, "Graphql").replaceAll(/grpc/giu, "Grpc").replaceAll(/([a-z\d])([A-Z])/gu, "$1-$2").replaceAll(/([A-Z]+)([A-Z][a-z])/gu, "$1-$2").replaceAll(/[_\s]+/gu, "-").replaceAll(/-+/gu, "-").replaceAll(/^-|-$/gu, "").toLowerCase();
|
|
3710
4005
|
}
|
|
3711
4006
|
function isGlobalIdentifier(context, node) {
|
|
3712
|
-
const variable =
|
|
4007
|
+
const variable = import_utils23.ASTUtils.findVariable(context.sourceCode.getScope(node), node.name);
|
|
3713
4008
|
return variable === null || variable.defs.length === 0;
|
|
3714
4009
|
}
|
|
3715
4010
|
function isConventionalFrameworkUtility(filename, exported) {
|
|
@@ -3717,8 +4012,8 @@ function isConventionalFrameworkUtility(filename, exported) {
|
|
|
3717
4012
|
return exported === "cn" && /(?:^|\/)lib\/utils\.[cm]?[jt]sx?$/u.test(normalized);
|
|
3718
4013
|
}
|
|
3719
4014
|
function memberPropertyName(node) {
|
|
3720
|
-
if (!node.computed && node.property.type ===
|
|
3721
|
-
return node.computed && node.property.type ===
|
|
4015
|
+
if (!node.computed && node.property.type === import_utils23.AST_NODE_TYPES.Identifier) return node.property.name;
|
|
4016
|
+
return node.computed && node.property.type === import_utils23.AST_NODE_TYPES.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
3722
4017
|
}
|
|
3723
4018
|
var no_generic_single_export_module_default = createRule({
|
|
3724
4019
|
name: "no-generic-single-export-module",
|
|
@@ -3739,11 +4034,11 @@ var no_generic_single_export_module_default = createRule({
|
|
|
3739
4034
|
return {
|
|
3740
4035
|
CallExpression(node) {
|
|
3741
4036
|
const first = node.arguments[0];
|
|
3742
|
-
if (first?.type ===
|
|
4037
|
+
if (first?.type === import_utils23.AST_NODE_TYPES.Identifier && first.name === "exports" && isGlobalIdentifier(context, first) && node.callee.type === import_utils23.AST_NODE_TYPES.MemberExpression && node.callee.object.type === import_utils23.AST_NODE_TYPES.Identifier && node.callee.object.name === "Object" && isGlobalIdentifier(context, node.callee.object) && memberPropertyName(node.callee) !== null && CJS_OBJECT_EXPORT_METHODS.has(memberPropertyName(node.callee))) hasCommonJsExport = true;
|
|
3743
4038
|
},
|
|
3744
4039
|
MemberExpression(node) {
|
|
3745
|
-
if (node.object.type ===
|
|
3746
|
-
if (node.object.type ===
|
|
4040
|
+
if (node.object.type === import_utils23.AST_NODE_TYPES.Identifier && node.object.name === "exports" && isGlobalIdentifier(context, node.object)) hasCommonJsExport = true;
|
|
4041
|
+
if (node.object.type === import_utils23.AST_NODE_TYPES.Identifier && node.object.name === "module" && isGlobalIdentifier(context, node.object) && memberPropertyName(node) === "exports") hasCommonJsExport = true;
|
|
3747
4042
|
},
|
|
3748
4043
|
"Program:exit"(program) {
|
|
3749
4044
|
if (hasCommonJsExport) return;
|
|
@@ -3773,7 +4068,7 @@ var no_generic_single_export_module_default = createRule({
|
|
|
3773
4068
|
});
|
|
3774
4069
|
|
|
3775
4070
|
// src/rules/no-offset-pagination.ts
|
|
3776
|
-
var
|
|
4071
|
+
var import_utils24 = require("@typescript-eslint/utils");
|
|
3777
4072
|
var OFFSET_PAGINATION = /\bOFFSET\s+(?:%s|%\(\w+\)s|\?\d*|:\w+|@\w+|\$\d+|\d+)/i;
|
|
3778
4073
|
var OFFSET_GATE = /offset/i;
|
|
3779
4074
|
var no_offset_pagination_default = createRule({
|
|
@@ -3803,25 +4098,32 @@ var no_offset_pagination_default = createRule({
|
|
|
3803
4098
|
});
|
|
3804
4099
|
|
|
3805
4100
|
// src/rules/no-positional-tuple-return.ts
|
|
3806
|
-
var
|
|
4101
|
+
var import_utils25 = require("@typescript-eslint/utils");
|
|
3807
4102
|
var MIN_ELEMENTS = 2;
|
|
3808
4103
|
var AWAITABLE_TYPES = /* @__PURE__ */ new Set(["Promise", "PromiseLike", "Awaited", "Readonly"]);
|
|
4104
|
+
function staticMemberName2(key) {
|
|
4105
|
+
if (key.type === import_utils25.AST_NODE_TYPES.Identifier) return key.name;
|
|
4106
|
+
if (key.type === import_utils25.AST_NODE_TYPES.Literal && typeof key.value === "string") {
|
|
4107
|
+
return key.value;
|
|
4108
|
+
}
|
|
4109
|
+
return null;
|
|
4110
|
+
}
|
|
3809
4111
|
function tupleReturnType(node, aliases, resolving = /* @__PURE__ */ new Set()) {
|
|
3810
|
-
if (node.type ===
|
|
4112
|
+
if (node.type === import_utils25.AST_NODE_TYPES.TSTupleType) {
|
|
3811
4113
|
return node;
|
|
3812
4114
|
}
|
|
3813
|
-
if (node.type ===
|
|
4115
|
+
if (node.type === import_utils25.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils25.AST_NODE_TYPES.Identifier && AWAITABLE_TYPES.has(node.typeName.name)) {
|
|
3814
4116
|
const argument = node.typeArguments?.params.at(0);
|
|
3815
4117
|
return argument === void 0 ? null : tupleReturnType(argument, aliases, resolving);
|
|
3816
4118
|
}
|
|
3817
|
-
if (node.type ===
|
|
4119
|
+
if (node.type === import_utils25.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils25.AST_NODE_TYPES.Identifier && !resolving.has(node.typeName.name)) {
|
|
3818
4120
|
const target = aliases.get(node.typeName.name);
|
|
3819
4121
|
if (target !== void 0) return tupleReturnType(target, aliases, /* @__PURE__ */ new Set([...resolving, node.typeName.name]));
|
|
3820
4122
|
}
|
|
3821
|
-
if (node.type ===
|
|
4123
|
+
if (node.type === import_utils25.AST_NODE_TYPES.TSTypeOperator && node.operator === "readonly") {
|
|
3822
4124
|
return node.typeAnnotation === void 0 ? null : tupleReturnType(node.typeAnnotation, aliases, resolving);
|
|
3823
4125
|
}
|
|
3824
|
-
if (node.type ===
|
|
4126
|
+
if (node.type === import_utils25.AST_NODE_TYPES.TSUnionType || node.type === import_utils25.AST_NODE_TYPES.TSIntersectionType) {
|
|
3825
4127
|
for (const member of node.types) {
|
|
3826
4128
|
const tuple = tupleReturnType(member, aliases, resolving);
|
|
3827
4129
|
if (tuple !== null) return tuple;
|
|
@@ -3830,21 +4132,21 @@ function tupleReturnType(node, aliases, resolving = /* @__PURE__ */ new Set()) {
|
|
|
3830
4132
|
return null;
|
|
3831
4133
|
}
|
|
3832
4134
|
function functionName(node) {
|
|
3833
|
-
if (node.type ===
|
|
4135
|
+
if (node.type === import_utils25.AST_NODE_TYPES.FunctionDeclaration) {
|
|
3834
4136
|
if (node.id !== null) return node.id.name;
|
|
3835
|
-
return node.parent?.type ===
|
|
4137
|
+
return node.parent?.type === import_utils25.AST_NODE_TYPES.ExportDefaultDeclaration ? "default" : null;
|
|
3836
4138
|
}
|
|
3837
4139
|
let wrapped = node;
|
|
3838
|
-
while ((wrapped.parent?.type ===
|
|
4140
|
+
while ((wrapped.parent?.type === import_utils25.AST_NODE_TYPES.TSAsExpression || wrapped.parent?.type === import_utils25.AST_NODE_TYPES.TSSatisfiesExpression || wrapped.parent?.type === import_utils25.AST_NODE_TYPES.TSNonNullExpression) && wrapped.parent.expression === wrapped) {
|
|
3839
4141
|
wrapped = wrapped.parent;
|
|
3840
4142
|
}
|
|
3841
4143
|
const parent = wrapped.parent;
|
|
3842
|
-
if (parent?.type ===
|
|
3843
|
-
if (parent?.type ===
|
|
4144
|
+
if (parent?.type === import_utils25.AST_NODE_TYPES.ExportDefaultDeclaration) return "default";
|
|
4145
|
+
if (parent?.type === import_utils25.AST_NODE_TYPES.VariableDeclarator && parent.id.type === import_utils25.AST_NODE_TYPES.Identifier) {
|
|
3844
4146
|
return parent.id.name;
|
|
3845
4147
|
}
|
|
3846
|
-
if ((parent?.type ===
|
|
3847
|
-
if ((parent.type ===
|
|
4148
|
+
if ((parent?.type === import_utils25.AST_NODE_TYPES.MethodDefinition || parent?.type === import_utils25.AST_NODE_TYPES.TSAbstractMethodDefinition || parent?.type === import_utils25.AST_NODE_TYPES.PropertyDefinition || parent?.type === import_utils25.AST_NODE_TYPES.Property) && parent.key.type === import_utils25.AST_NODE_TYPES.Identifier) {
|
|
4149
|
+
if ((parent.type === import_utils25.AST_NODE_TYPES.MethodDefinition || parent.type === import_utils25.AST_NODE_TYPES.TSAbstractMethodDefinition || parent.type === import_utils25.AST_NODE_TYPES.PropertyDefinition) && (parent.accessibility === "private" || parent.accessibility === "protected")) return null;
|
|
3848
4150
|
return parent.key.name;
|
|
3849
4151
|
}
|
|
3850
4152
|
return null;
|
|
@@ -3853,7 +4155,7 @@ function isInlineExported(node) {
|
|
|
3853
4155
|
if (moduleScopeBindingName(node) === null) return false;
|
|
3854
4156
|
for (let current = node; current != null; current = current.parent) {
|
|
3855
4157
|
const parent = current.parent;
|
|
3856
|
-
if (parent?.type ===
|
|
4158
|
+
if (parent?.type === import_utils25.AST_NODE_TYPES.ExportNamedDeclaration || parent?.type === import_utils25.AST_NODE_TYPES.ExportDefaultDeclaration) {
|
|
3857
4159
|
return true;
|
|
3858
4160
|
}
|
|
3859
4161
|
}
|
|
@@ -3861,39 +4163,39 @@ function isInlineExported(node) {
|
|
|
3861
4163
|
}
|
|
3862
4164
|
function moduleScopeBindingName(node) {
|
|
3863
4165
|
let current = node;
|
|
3864
|
-
while (current.parent != null && current.parent.type !==
|
|
4166
|
+
while (current.parent != null && current.parent.type !== import_utils25.AST_NODE_TYPES.Program) {
|
|
3865
4167
|
current = current.parent;
|
|
3866
4168
|
}
|
|
3867
|
-
if (current.parent?.type !==
|
|
4169
|
+
if (current.parent?.type !== import_utils25.AST_NODE_TYPES.Program) {
|
|
3868
4170
|
return null;
|
|
3869
4171
|
}
|
|
3870
4172
|
let topLevel = current;
|
|
3871
|
-
if (current.type ===
|
|
4173
|
+
if (current.type === import_utils25.AST_NODE_TYPES.ExportNamedDeclaration || current.type === import_utils25.AST_NODE_TYPES.ExportDefaultDeclaration) {
|
|
3872
4174
|
topLevel = current.declaration;
|
|
3873
4175
|
}
|
|
3874
4176
|
if (topLevel === null) return null;
|
|
3875
|
-
if (topLevel.type ===
|
|
4177
|
+
if (topLevel.type === import_utils25.AST_NODE_TYPES.FunctionDeclaration) {
|
|
3876
4178
|
if (topLevel !== node) return null;
|
|
3877
|
-
return topLevel.id?.name ?? (current.type ===
|
|
4179
|
+
return topLevel.id?.name ?? (current.type === import_utils25.AST_NODE_TYPES.ExportDefaultDeclaration ? "default" : null);
|
|
3878
4180
|
}
|
|
3879
|
-
if ((topLevel.type ===
|
|
4181
|
+
if ((topLevel.type === import_utils25.AST_NODE_TYPES.ArrowFunctionExpression || topLevel.type === import_utils25.AST_NODE_TYPES.FunctionExpression) && topLevel === node && current.type === import_utils25.AST_NODE_TYPES.ExportDefaultDeclaration) {
|
|
3880
4182
|
return "default";
|
|
3881
4183
|
}
|
|
3882
|
-
if (topLevel.type ===
|
|
4184
|
+
if (topLevel.type === import_utils25.AST_NODE_TYPES.ClassDeclaration) {
|
|
3883
4185
|
let owner = node.parent;
|
|
3884
4186
|
while (owner != null && owner.parent !== topLevel.body) owner = owner.parent;
|
|
3885
|
-
return (owner?.type ===
|
|
4187
|
+
return (owner?.type === import_utils25.AST_NODE_TYPES.MethodDefinition || owner?.type === import_utils25.AST_NODE_TYPES.TSAbstractMethodDefinition || owner?.type === import_utils25.AST_NODE_TYPES.PropertyDefinition) && owner.value === node ? topLevel.id?.name ?? (current.type === import_utils25.AST_NODE_TYPES.ExportDefaultDeclaration ? "default" : null) : null;
|
|
3886
4188
|
}
|
|
3887
|
-
if (topLevel.type ===
|
|
4189
|
+
if (topLevel.type === import_utils25.AST_NODE_TYPES.VariableDeclaration) {
|
|
3888
4190
|
for (const declarator of topLevel.declarations) {
|
|
3889
4191
|
let initializer = declarator.init;
|
|
3890
|
-
while (initializer?.type ===
|
|
3891
|
-
if (declarator.id.type ===
|
|
3892
|
-
if (declarator.id.type ===
|
|
4192
|
+
while (initializer?.type === import_utils25.AST_NODE_TYPES.TSAsExpression || initializer?.type === import_utils25.AST_NODE_TYPES.TSSatisfiesExpression || initializer?.type === import_utils25.AST_NODE_TYPES.TSNonNullExpression) initializer = initializer.expression;
|
|
4193
|
+
if (declarator.id.type === import_utils25.AST_NODE_TYPES.Identifier && initializer === node) return declarator.id.name;
|
|
4194
|
+
if (declarator.id.type === import_utils25.AST_NODE_TYPES.Identifier && (initializer?.type === import_utils25.AST_NODE_TYPES.ClassExpression || initializer?.type === import_utils25.AST_NODE_TYPES.ObjectExpression)) {
|
|
3893
4195
|
let owner = node.parent;
|
|
3894
|
-
const container = initializer.type ===
|
|
4196
|
+
const container = initializer.type === import_utils25.AST_NODE_TYPES.ClassExpression ? initializer.body : initializer;
|
|
3895
4197
|
while (owner != null && owner.parent !== container) owner = owner.parent;
|
|
3896
|
-
if ((owner?.type ===
|
|
4198
|
+
if ((owner?.type === import_utils25.AST_NODE_TYPES.MethodDefinition || owner?.type === import_utils25.AST_NODE_TYPES.PropertyDefinition || owner?.type === import_utils25.AST_NODE_TYPES.Property) && owner.value === node) return declarator.id.name;
|
|
3897
4199
|
}
|
|
3898
4200
|
}
|
|
3899
4201
|
}
|
|
@@ -3902,19 +4204,19 @@ function moduleScopeBindingName(node) {
|
|
|
3902
4204
|
function specifierExportedNames(program) {
|
|
3903
4205
|
const names = /* @__PURE__ */ new Set();
|
|
3904
4206
|
for (const statement of program.body) {
|
|
3905
|
-
if (statement.type ===
|
|
4207
|
+
if (statement.type === import_utils25.AST_NODE_TYPES.ExportNamedDeclaration && statement.declaration == null && statement.source == null && statement.exportKind !== "type") {
|
|
3906
4208
|
for (const specifier of statement.specifiers) {
|
|
3907
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
4209
|
+
if (specifier.exportKind !== "type" && specifier.local.type === import_utils25.AST_NODE_TYPES.Identifier) {
|
|
3908
4210
|
names.add(specifier.local.name);
|
|
3909
4211
|
}
|
|
3910
4212
|
}
|
|
3911
4213
|
continue;
|
|
3912
4214
|
}
|
|
3913
|
-
if (statement.type ===
|
|
4215
|
+
if (statement.type === import_utils25.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils25.AST_NODE_TYPES.Identifier) {
|
|
3914
4216
|
names.add(statement.declaration.name);
|
|
3915
4217
|
continue;
|
|
3916
4218
|
}
|
|
3917
|
-
if (statement.type ===
|
|
4219
|
+
if (statement.type === import_utils25.AST_NODE_TYPES.TSExportAssignment && statement.expression.type === import_utils25.AST_NODE_TYPES.Identifier) {
|
|
3918
4220
|
names.add(statement.expression.name);
|
|
3919
4221
|
}
|
|
3920
4222
|
}
|
|
@@ -3923,28 +4225,28 @@ function specifierExportedNames(program) {
|
|
|
3923
4225
|
function exportedTypeNames(program) {
|
|
3924
4226
|
const names = /* @__PURE__ */ new Set();
|
|
3925
4227
|
for (const statement of program.body) {
|
|
3926
|
-
if (statement.type !==
|
|
3927
|
-
if (statement.declaration?.type ===
|
|
4228
|
+
if (statement.type !== import_utils25.AST_NODE_TYPES.ExportNamedDeclaration || statement.source !== null) continue;
|
|
4229
|
+
if (statement.declaration?.type === import_utils25.AST_NODE_TYPES.TSInterfaceDeclaration || statement.declaration?.type === import_utils25.AST_NODE_TYPES.TSTypeAliasDeclaration) names.add(statement.declaration.id.name);
|
|
3928
4230
|
for (const specifier of statement.specifiers) names.add(specifier.local.name);
|
|
3929
4231
|
}
|
|
3930
4232
|
for (const statement of program.body) {
|
|
3931
|
-
if (statement.type ===
|
|
4233
|
+
if (statement.type === import_utils25.AST_NODE_TYPES.ExportDefaultDeclaration && (statement.declaration.type === import_utils25.AST_NODE_TYPES.TSInterfaceDeclaration || statement.declaration.type === import_utils25.AST_NODE_TYPES.TSTypeAliasDeclaration)) names.add(statement.declaration.id.name);
|
|
3932
4234
|
}
|
|
3933
4235
|
return names;
|
|
3934
4236
|
}
|
|
3935
4237
|
function typeAliases(program) {
|
|
3936
4238
|
const aliases = /* @__PURE__ */ new Map();
|
|
3937
4239
|
for (const statement of program.body) {
|
|
3938
|
-
const declaration = statement.type ===
|
|
3939
|
-
if (declaration?.type ===
|
|
4240
|
+
const declaration = statement.type === import_utils25.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
4241
|
+
if (declaration?.type === import_utils25.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
3940
4242
|
aliases.set(declaration.id.name, declaration.typeAnnotation);
|
|
3941
4243
|
}
|
|
3942
4244
|
}
|
|
3943
4245
|
return aliases;
|
|
3944
4246
|
}
|
|
3945
4247
|
function callableReturnType(node, aliases, resolving = /* @__PURE__ */ new Set()) {
|
|
3946
|
-
if (node.type ===
|
|
3947
|
-
if (node.type ===
|
|
4248
|
+
if (node.type === import_utils25.AST_NODE_TYPES.TSFunctionType) return node.returnType?.typeAnnotation ?? null;
|
|
4249
|
+
if (node.type === import_utils25.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils25.AST_NODE_TYPES.Identifier && !resolving.has(node.typeName.name)) {
|
|
3948
4250
|
const target = aliases.get(node.typeName.name);
|
|
3949
4251
|
if (target !== void 0) {
|
|
3950
4252
|
return callableReturnType(target, aliases, /* @__PURE__ */ new Set([...resolving, node.typeName.name]));
|
|
@@ -3956,8 +4258,8 @@ function publiclyReachableTypeNames(program, exported) {
|
|
|
3956
4258
|
const names = new Set(exported);
|
|
3957
4259
|
const interfaces = /* @__PURE__ */ new Map();
|
|
3958
4260
|
for (const statement of program.body) {
|
|
3959
|
-
const declaration = statement.type ===
|
|
3960
|
-
if (declaration?.type ===
|
|
4261
|
+
const declaration = statement.type === import_utils25.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
4262
|
+
if (declaration?.type === import_utils25.AST_NODE_TYPES.TSInterfaceDeclaration) {
|
|
3961
4263
|
interfaces.set(declaration.id.name, declaration.extends);
|
|
3962
4264
|
}
|
|
3963
4265
|
}
|
|
@@ -3965,7 +4267,7 @@ function publiclyReachableTypeNames(program, exported) {
|
|
|
3965
4267
|
let changed = false;
|
|
3966
4268
|
for (const name of [...names]) {
|
|
3967
4269
|
for (const heritage of interfaces.get(name) ?? []) {
|
|
3968
|
-
if (heritage.expression.type ===
|
|
4270
|
+
if (heritage.expression.type === import_utils25.AST_NODE_TYPES.Identifier && !names.has(heritage.expression.name)) {
|
|
3969
4271
|
names.add(heritage.expression.name);
|
|
3970
4272
|
changed = true;
|
|
3971
4273
|
}
|
|
@@ -3977,37 +4279,37 @@ function publiclyReachableTypeNames(program, exported) {
|
|
|
3977
4279
|
}
|
|
3978
4280
|
function owningInterface(node) {
|
|
3979
4281
|
for (let current = node.parent; current !== void 0; current = current.parent) {
|
|
3980
|
-
if (current.type ===
|
|
3981
|
-
if (current.type ===
|
|
4282
|
+
if (current.type === import_utils25.AST_NODE_TYPES.TSInterfaceDeclaration) return current;
|
|
4283
|
+
if (current.type === import_utils25.AST_NODE_TYPES.Program) return null;
|
|
3982
4284
|
}
|
|
3983
4285
|
return null;
|
|
3984
4286
|
}
|
|
3985
4287
|
function owningTypeAlias(node) {
|
|
3986
4288
|
for (let current = node.parent; current !== void 0; current = current.parent) {
|
|
3987
|
-
if (current.type ===
|
|
3988
|
-
if (current.type ===
|
|
4289
|
+
if (current.type === import_utils25.AST_NODE_TYPES.TSTypeAliasDeclaration) return current;
|
|
4290
|
+
if (current.type === import_utils25.AST_NODE_TYPES.Program) return null;
|
|
3989
4291
|
}
|
|
3990
4292
|
return null;
|
|
3991
4293
|
}
|
|
3992
4294
|
function owningClass(node) {
|
|
3993
4295
|
for (let current = node.parent; current !== void 0; current = current.parent) {
|
|
3994
|
-
if (current.type ===
|
|
4296
|
+
if (current.type === import_utils25.AST_NODE_TYPES.ClassDeclaration || current.type === import_utils25.AST_NODE_TYPES.ClassExpression) {
|
|
3995
4297
|
return current;
|
|
3996
4298
|
}
|
|
3997
|
-
if (current.type ===
|
|
4299
|
+
if (current.type === import_utils25.AST_NODE_TYPES.Program) return null;
|
|
3998
4300
|
}
|
|
3999
4301
|
return null;
|
|
4000
4302
|
}
|
|
4001
4303
|
function isExportedClass(node, specifierExports) {
|
|
4002
|
-
if (node.parent.type ===
|
|
4003
|
-
if (node.type ===
|
|
4004
|
-
return node.id !== null && node.parent.type ===
|
|
4304
|
+
if (node.parent.type === import_utils25.AST_NODE_TYPES.ExportNamedDeclaration || node.parent.type === import_utils25.AST_NODE_TYPES.ExportDefaultDeclaration) return true;
|
|
4305
|
+
if (node.type === import_utils25.AST_NODE_TYPES.ClassDeclaration) {
|
|
4306
|
+
return node.id !== null && node.parent.type === import_utils25.AST_NODE_TYPES.Program && specifierExports.has(node.id.name);
|
|
4005
4307
|
}
|
|
4006
|
-
if (node.parent.type ===
|
|
4308
|
+
if (node.parent.type === import_utils25.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === import_utils25.AST_NODE_TYPES.Identifier) return specifierExports.has(node.parent.id.name) || isInlineExported(node);
|
|
4007
4309
|
return false;
|
|
4008
4310
|
}
|
|
4009
4311
|
function isExportedInterface(node, exports2) {
|
|
4010
|
-
return node.parent.type ===
|
|
4312
|
+
return node.parent.type === import_utils25.AST_NODE_TYPES.ExportNamedDeclaration || node.parent.type === import_utils25.AST_NODE_TYPES.ExportDefaultDeclaration || node.parent.type === import_utils25.AST_NODE_TYPES.Program && exports2.has(node.id.name);
|
|
4011
4313
|
}
|
|
4012
4314
|
function isExported(node, specifierExports) {
|
|
4013
4315
|
if (isInlineExported(node)) {
|
|
@@ -4069,7 +4371,7 @@ var no_positional_tuple_return_default = createRule({
|
|
|
4069
4371
|
ArrowFunctionExpression: check,
|
|
4070
4372
|
TSEmptyBodyFunctionExpression: check,
|
|
4071
4373
|
TSDeclareFunction(node) {
|
|
4072
|
-
if (node.id === null || node.returnType === void 0 || node.parent.type !==
|
|
4374
|
+
if (node.id === null || node.returnType === void 0 || node.parent.type !== import_utils25.AST_NODE_TYPES.ExportNamedDeclaration && node.parent.type !== import_utils25.AST_NODE_TYPES.ExportDefaultDeclaration && !specifierExports.has(node.id.name)) return;
|
|
4073
4375
|
report(node.returnType.typeAnnotation, node.id.name);
|
|
4074
4376
|
},
|
|
4075
4377
|
TSCallSignatureDeclaration(node) {
|
|
@@ -4080,8 +4382,9 @@ var no_positional_tuple_return_default = createRule({
|
|
|
4080
4382
|
TSMethodSignature(node) {
|
|
4081
4383
|
const owner = owningInterface(node);
|
|
4082
4384
|
const alias = owningTypeAlias(node);
|
|
4083
|
-
|
|
4084
|
-
|
|
4385
|
+
const memberName2 = staticMemberName2(node.key);
|
|
4386
|
+
if ((owner === null || !isExportedInterface(owner, typeExports)) && (alias === null || !typeExports.has(alias.id.name)) || node.returnType === void 0 || memberName2 === null) return;
|
|
4387
|
+
report(node.returnType.typeAnnotation, `${owner?.id.name ?? alias?.id.name ?? "type"}.${memberName2}`);
|
|
4085
4388
|
},
|
|
4086
4389
|
TSTypeAliasDeclaration(node) {
|
|
4087
4390
|
if (!typeExports.has(node.id.name)) return;
|
|
@@ -4092,10 +4395,11 @@ var no_positional_tuple_return_default = createRule({
|
|
|
4092
4395
|
const owner = owningInterface(node);
|
|
4093
4396
|
const alias = owningTypeAlias(node);
|
|
4094
4397
|
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
4095
|
-
|
|
4398
|
+
const memberName2 = staticMemberName2(node.key);
|
|
4399
|
+
if ((owner === null || !isExportedInterface(owner, typeExports)) && (alias === null || !typeExports.has(alias.id.name)) || memberName2 === null || annotation === void 0) return;
|
|
4096
4400
|
const returnType = callableReturnType(annotation, aliases);
|
|
4097
4401
|
if (returnType !== null) {
|
|
4098
|
-
report(returnType, `${owner?.id.name ?? alias?.id.name ?? "type"}.${
|
|
4402
|
+
report(returnType, `${owner?.id.name ?? alias?.id.name ?? "type"}.${memberName2}`);
|
|
4099
4403
|
}
|
|
4100
4404
|
},
|
|
4101
4405
|
PropertyDefinition(node) {
|
|
@@ -4105,7 +4409,7 @@ var no_positional_tuple_return_default = createRule({
|
|
|
4105
4409
|
if (owner === null || !isExportedClass(owner, specifierExports) || annotation === void 0) return;
|
|
4106
4410
|
const returnType = callableReturnType(annotation, aliases);
|
|
4107
4411
|
if (returnType !== null) {
|
|
4108
|
-
const name = node.key.type ===
|
|
4412
|
+
const name = node.key.type === import_utils25.AST_NODE_TYPES.Identifier ? node.key.name : "property";
|
|
4109
4413
|
report(returnType, name);
|
|
4110
4414
|
}
|
|
4111
4415
|
}
|
|
@@ -4114,7 +4418,7 @@ var no_positional_tuple_return_default = createRule({
|
|
|
4114
4418
|
});
|
|
4115
4419
|
|
|
4116
4420
|
// src/rules/no-raw-env.ts
|
|
4117
|
-
var
|
|
4421
|
+
var import_utils26 = require("@typescript-eslint/utils");
|
|
4118
4422
|
var CONFIG_FILE_RE = /(^|[\\/])[\w.-]+\.config\.[cm]?[jt]sx?$/;
|
|
4119
4423
|
var ENV_BOUNDARY_FILE_RE = /(^|[\\/])(?:env|client-env|server-env|client-settings|server-settings)\.[cm]?[jt]sx?$/;
|
|
4120
4424
|
var ENV_VALIDATION_MARKER_RE = /\bcreateEnv\s*\(|\bz\.object\s*\(|\.(?:safeParse|parse)\s*\(/;
|
|
@@ -4191,7 +4495,7 @@ var no_raw_env_default = createRule({
|
|
|
4191
4495
|
});
|
|
4192
4496
|
|
|
4193
4497
|
// src/rules/no-raw-fetch-outside-clients.ts
|
|
4194
|
-
var
|
|
4498
|
+
var import_utils27 = require("@typescript-eslint/utils");
|
|
4195
4499
|
var DEFAULT_ALLOW = [
|
|
4196
4500
|
"[\\\\/]clients?[\\\\/]",
|
|
4197
4501
|
"-client\\.[cm]?[jt]sx?$",
|
|
@@ -4224,7 +4528,7 @@ function isGlobalFetchCall(node) {
|
|
|
4224
4528
|
}
|
|
4225
4529
|
function isConstructedArgumentHandoff(node) {
|
|
4226
4530
|
const [first] = node.arguments;
|
|
4227
|
-
return node.arguments.length === 1 && first !== void 0 && first.type ===
|
|
4531
|
+
return node.arguments.length === 1 && first !== void 0 && first.type === import_utils27.AST_NODE_TYPES.NewExpression;
|
|
4228
4532
|
}
|
|
4229
4533
|
function isPresignedUrlTransfer(node) {
|
|
4230
4534
|
const first = node.arguments[0];
|
|
@@ -4302,9 +4606,9 @@ var no_raw_fetch_outside_clients_default = createRule({
|
|
|
4302
4606
|
});
|
|
4303
4607
|
|
|
4304
4608
|
// src/rules/no-restricted-library-load.ts
|
|
4305
|
-
var
|
|
4609
|
+
var import_utils28 = require("@typescript-eslint/utils");
|
|
4306
4610
|
function literalModule(node) {
|
|
4307
|
-
return node?.type ===
|
|
4611
|
+
return node?.type === import_utils28.AST_NODE_TYPES.Literal && typeof node.value === "string" ? node.value : null;
|
|
4308
4612
|
}
|
|
4309
4613
|
function matchesModule(source, module2) {
|
|
4310
4614
|
return source === module2 || source.startsWith(`${module2}/`);
|
|
@@ -4363,7 +4667,7 @@ var no_restricted_library_load_default = createRule({
|
|
|
4363
4667
|
});
|
|
4364
4668
|
}
|
|
4365
4669
|
function isUnshadowedRequire(node) {
|
|
4366
|
-
const variable =
|
|
4670
|
+
const variable = import_utils28.ASTUtils.findVariable(
|
|
4367
4671
|
context.sourceCode.getScope(node),
|
|
4368
4672
|
node.name
|
|
4369
4673
|
);
|
|
@@ -4376,9 +4680,9 @@ var no_restricted_library_load_default = createRule({
|
|
|
4376
4680
|
},
|
|
4377
4681
|
CallExpression(node) {
|
|
4378
4682
|
let requireIdentifier = null;
|
|
4379
|
-
if (node.callee.type ===
|
|
4683
|
+
if (node.callee.type === import_utils28.AST_NODE_TYPES.Identifier && node.callee.name === "require") {
|
|
4380
4684
|
requireIdentifier = node.callee;
|
|
4381
|
-
} else if (node.callee.type ===
|
|
4685
|
+
} else if (node.callee.type === import_utils28.AST_NODE_TYPES.MemberExpression && !node.callee.computed && node.callee.object.type === import_utils28.AST_NODE_TYPES.Identifier && node.callee.object.name === "require" && node.callee.property.type === import_utils28.AST_NODE_TYPES.Identifier && node.callee.property.name === "resolve") {
|
|
4382
4686
|
requireIdentifier = node.callee.object;
|
|
4383
4687
|
}
|
|
4384
4688
|
if (requireIdentifier === null || !isUnshadowedRequire(requireIdentifier)) return;
|
|
@@ -4386,7 +4690,7 @@ var no_restricted_library_load_default = createRule({
|
|
|
4386
4690
|
if (source !== null) report(node.arguments[0], source);
|
|
4387
4691
|
},
|
|
4388
4692
|
TSImportEqualsDeclaration(node) {
|
|
4389
|
-
if (node.moduleReference.type !==
|
|
4693
|
+
if (node.moduleReference.type !== import_utils28.AST_NODE_TYPES.TSExternalModuleReference) return;
|
|
4390
4694
|
const source = literalModule(node.moduleReference.expression);
|
|
4391
4695
|
if (source !== null) report(node.moduleReference.expression, source);
|
|
4392
4696
|
}
|
|
@@ -4395,16 +4699,16 @@ var no_restricted_library_load_default = createRule({
|
|
|
4395
4699
|
});
|
|
4396
4700
|
|
|
4397
4701
|
// src/rules/no-repeated-string-literal.ts
|
|
4398
|
-
var
|
|
4702
|
+
var import_utils29 = require("@typescript-eslint/utils");
|
|
4399
4703
|
var MIN_LENGTH = 40;
|
|
4400
4704
|
var MIN_DISTINCT_SCOPES = 2;
|
|
4401
4705
|
var PREVIEW_LENGTH = 40;
|
|
4402
4706
|
var SQL_KEYWORD_RE = /\b(SELECT|INSERT|UPDATE|DELETE|FROM|WHERE|JOIN|VALUES|ON CONFLICT|RETURNING|GROUP BY|ORDER BY)\b/;
|
|
4403
4707
|
var IDENTIFIER_RE = /^[a-z_][a-z0-9_.]*$/;
|
|
4404
4708
|
var FUNCTION_TYPES4 = /* @__PURE__ */ new Set([
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4709
|
+
import_utils29.AST_NODE_TYPES.FunctionDeclaration,
|
|
4710
|
+
import_utils29.AST_NODE_TYPES.FunctionExpression,
|
|
4711
|
+
import_utils29.AST_NODE_TYPES.ArrowFunctionExpression
|
|
4408
4712
|
]);
|
|
4409
4713
|
function isStructured(value) {
|
|
4410
4714
|
return value.includes("\n") || SQL_KEYWORD_RE.test(value) || IDENTIFIER_RE.test(value);
|
|
@@ -4426,8 +4730,8 @@ function isScaffolding(node) {
|
|
|
4426
4730
|
if (parent === void 0) {
|
|
4427
4731
|
return true;
|
|
4428
4732
|
}
|
|
4429
|
-
const isRequireSource = parent.type ===
|
|
4430
|
-
return parent.type ===
|
|
4733
|
+
const isRequireSource = parent.type === import_utils29.AST_NODE_TYPES.CallExpression && parent.callee.type === import_utils29.AST_NODE_TYPES.Identifier && parent.callee.name === "require";
|
|
4734
|
+
return parent.type === import_utils29.AST_NODE_TYPES.ImportDeclaration || parent.type === import_utils29.AST_NODE_TYPES.ImportExpression || parent.type === import_utils29.AST_NODE_TYPES.ExportNamedDeclaration || parent.type === import_utils29.AST_NODE_TYPES.ExportAllDeclaration || parent.type === import_utils29.AST_NODE_TYPES.TSImportType || parent.type === import_utils29.AST_NODE_TYPES.JSXAttribute || parent.type === import_utils29.AST_NODE_TYPES.TSLiteralType || isRequireSource;
|
|
4431
4735
|
}
|
|
4432
4736
|
var no_repeated_string_literal_default = createRule({
|
|
4433
4737
|
name: "no-repeated-string-literal",
|
|
@@ -4467,7 +4771,7 @@ var no_repeated_string_literal_default = createRule({
|
|
|
4467
4771
|
}
|
|
4468
4772
|
},
|
|
4469
4773
|
TemplateLiteral(node) {
|
|
4470
|
-
if (node.parent.type ===
|
|
4774
|
+
if (node.parent.type === import_utils29.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
4471
4775
|
return;
|
|
4472
4776
|
}
|
|
4473
4777
|
const [only] = node.quasis;
|
|
@@ -4501,7 +4805,7 @@ var no_repeated_string_literal_default = createRule({
|
|
|
4501
4805
|
});
|
|
4502
4806
|
|
|
4503
4807
|
// src/rules/no-restated-comment.ts
|
|
4504
|
-
var
|
|
4808
|
+
var import_utils30 = require("@typescript-eslint/utils");
|
|
4505
4809
|
var MAX_WORDS = 8;
|
|
4506
4810
|
var MIN_CONTENT_TOKENS = 2;
|
|
4507
4811
|
var DIRECTIVE_RE3 = /^(eslint\b|eslint-|sarj-noqa\b|@ts-|prettier-ignore|prettier\b|biome-|c8\b|v8\b|istanbul\b|@type\b|@vite|webpack|<reference|<amd|global\b|noinspection|todo\b|fixme\b|hack\b|xxx\b)/i;
|
|
@@ -4554,7 +4858,7 @@ var no_restated_comment_default = createRule({
|
|
|
4554
4858
|
function labelsASiblingRun(comment) {
|
|
4555
4859
|
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
4556
4860
|
if (token === null) return false;
|
|
4557
|
-
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !==
|
|
4861
|
+
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !== import_utils30.AST_NODE_TYPES.Program; node = node.parent) {
|
|
4558
4862
|
if (headsSiblingRun(node)) return true;
|
|
4559
4863
|
}
|
|
4560
4864
|
return false;
|
|
@@ -4614,7 +4918,7 @@ var no_restated_comment_default = createRule({
|
|
|
4614
4918
|
});
|
|
4615
4919
|
|
|
4616
4920
|
// src/rules/no-restated-jsdoc.ts
|
|
4617
|
-
var
|
|
4921
|
+
var import_utils31 = require("@typescript-eslint/utils");
|
|
4618
4922
|
var MODELLED_TAGS = /* @__PURE__ */ new Set([
|
|
4619
4923
|
"arg",
|
|
4620
4924
|
"argument",
|
|
@@ -4668,30 +4972,30 @@ function declarationNames(node) {
|
|
|
4668
4972
|
switch (node.type) {
|
|
4669
4973
|
// `export function f()` — the JSDoc sits above the `export`, so the token
|
|
4670
4974
|
// after it resolves to the wrapper, not to the thing being documented.
|
|
4671
|
-
case
|
|
4672
|
-
case
|
|
4975
|
+
case import_utils31.AST_NODE_TYPES.ExportNamedDeclaration:
|
|
4976
|
+
case import_utils31.AST_NODE_TYPES.ExportDefaultDeclaration:
|
|
4673
4977
|
return node.declaration == null ? null : declarationNames(node.declaration);
|
|
4674
|
-
case
|
|
4675
|
-
case
|
|
4978
|
+
case import_utils31.AST_NODE_TYPES.FunctionDeclaration:
|
|
4979
|
+
case import_utils31.AST_NODE_TYPES.TSDeclareFunction:
|
|
4676
4980
|
return node.id === null ? null : { name: node.id.name, params: paramNames(node.params) };
|
|
4677
|
-
case
|
|
4678
|
-
case
|
|
4679
|
-
case
|
|
4680
|
-
case
|
|
4981
|
+
case import_utils31.AST_NODE_TYPES.ClassDeclaration:
|
|
4982
|
+
case import_utils31.AST_NODE_TYPES.TSInterfaceDeclaration:
|
|
4983
|
+
case import_utils31.AST_NODE_TYPES.TSTypeAliasDeclaration:
|
|
4984
|
+
case import_utils31.AST_NODE_TYPES.TSEnumDeclaration:
|
|
4681
4985
|
return node.id === null ? null : { name: node.id.name, params: [] };
|
|
4682
|
-
case
|
|
4986
|
+
case import_utils31.AST_NODE_TYPES.VariableDeclaration: {
|
|
4683
4987
|
const declarator = node.declarations[0];
|
|
4684
|
-
if (declarator === void 0 || declarator.id.type !==
|
|
4988
|
+
if (declarator === void 0 || declarator.id.type !== import_utils31.AST_NODE_TYPES.Identifier) return null;
|
|
4685
4989
|
const init = declarator.init;
|
|
4686
|
-
const params = init != null && (init.type ===
|
|
4990
|
+
const params = init != null && (init.type === import_utils31.AST_NODE_TYPES.ArrowFunctionExpression || init.type === import_utils31.AST_NODE_TYPES.FunctionExpression) ? paramNames(init.params) : [];
|
|
4687
4991
|
return { name: declarator.id.name, params };
|
|
4688
4992
|
}
|
|
4689
|
-
case
|
|
4690
|
-
case
|
|
4691
|
-
case
|
|
4692
|
-
case
|
|
4693
|
-
if (node.key.type !==
|
|
4694
|
-
const params = node.type ===
|
|
4993
|
+
case import_utils31.AST_NODE_TYPES.MethodDefinition:
|
|
4994
|
+
case import_utils31.AST_NODE_TYPES.PropertyDefinition:
|
|
4995
|
+
case import_utils31.AST_NODE_TYPES.TSMethodSignature:
|
|
4996
|
+
case import_utils31.AST_NODE_TYPES.TSPropertySignature: {
|
|
4997
|
+
if (node.key.type !== import_utils31.AST_NODE_TYPES.Identifier) return null;
|
|
4998
|
+
const params = node.type === import_utils31.AST_NODE_TYPES.MethodDefinition ? paramNames(node.value.params) : node.type === import_utils31.AST_NODE_TYPES.TSMethodSignature ? paramNames(node.params) : [];
|
|
4695
4999
|
return { name: node.key.name, params };
|
|
4696
5000
|
}
|
|
4697
5001
|
default:
|
|
@@ -4701,9 +5005,9 @@ function declarationNames(node) {
|
|
|
4701
5005
|
function paramNames(params) {
|
|
4702
5006
|
const names = [];
|
|
4703
5007
|
for (const param of params) {
|
|
4704
|
-
const target = param.type ===
|
|
4705
|
-
if (target.type ===
|
|
4706
|
-
else if (target.type ===
|
|
5008
|
+
const target = param.type === import_utils31.AST_NODE_TYPES.AssignmentPattern ? param.left : param;
|
|
5009
|
+
if (target.type === import_utils31.AST_NODE_TYPES.Identifier) names.push(target.name);
|
|
5010
|
+
else if (target.type === import_utils31.AST_NODE_TYPES.TSParameterProperty) continue;
|
|
4707
5011
|
}
|
|
4708
5012
|
return names;
|
|
4709
5013
|
}
|
|
@@ -4745,7 +5049,7 @@ var no_restated_jsdoc_default = createRule({
|
|
|
4745
5049
|
if (token === null || token.loc.start.line !== comment.loc.end.line + 1) continue;
|
|
4746
5050
|
let node = sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
4747
5051
|
let declaration = null;
|
|
4748
|
-
while (node != null && node.type !==
|
|
5052
|
+
while (node != null && node.type !== import_utils31.AST_NODE_TYPES.Program) {
|
|
4749
5053
|
declaration = declarationNames(node);
|
|
4750
5054
|
if (declaration !== null) break;
|
|
4751
5055
|
node = node.parent ?? null;
|
|
@@ -4800,7 +5104,7 @@ var no_restated_jsdoc_default = createRule({
|
|
|
4800
5104
|
});
|
|
4801
5105
|
|
|
4802
5106
|
// src/rules/no-secret-in-log.ts
|
|
4803
|
-
var
|
|
5107
|
+
var import_utils32 = require("@typescript-eslint/utils");
|
|
4804
5108
|
|
|
4805
5109
|
// src/rules/_secret-names.ts
|
|
4806
5110
|
var SECRET_WORDS = /* @__PURE__ */ new Set([
|
|
@@ -5094,11 +5398,11 @@ var no_secret_in_log_default = createRule({
|
|
|
5094
5398
|
return true;
|
|
5095
5399
|
}
|
|
5096
5400
|
function reportSecretProperty(prop) {
|
|
5097
|
-
const
|
|
5098
|
-
if (
|
|
5401
|
+
const keyName = propertyKeyName2(prop);
|
|
5402
|
+
if (keyName === null || !isSecretKeyword(keyName) || !isRawSecretValue(prop)) {
|
|
5099
5403
|
return false;
|
|
5100
5404
|
}
|
|
5101
|
-
context.report({ node: prop, messageId: "noSecretInLog", data: { name:
|
|
5405
|
+
context.report({ node: prop, messageId: "noSecretInLog", data: { name: keyName } });
|
|
5102
5406
|
return true;
|
|
5103
5407
|
}
|
|
5104
5408
|
function reportRawBlob(node, value) {
|
|
@@ -5137,7 +5441,7 @@ var no_secret_in_log_default = createRule({
|
|
|
5137
5441
|
});
|
|
5138
5442
|
|
|
5139
5443
|
// src/rules/no-select-star.ts
|
|
5140
|
-
var
|
|
5444
|
+
var import_utils33 = require("@typescript-eslint/utils");
|
|
5141
5445
|
var QUERY_SHAPE = /\bSELECT\b[\s\S]*?\bFROM\b/i;
|
|
5142
5446
|
var SELECT_KEYWORD = /\bSELECT\b/gi;
|
|
5143
5447
|
var FROM_KEYWORD = /^FROM\b/i;
|
|
@@ -5204,10 +5508,10 @@ var no_select_star_default = createRule({
|
|
|
5204
5508
|
});
|
|
5205
5509
|
|
|
5206
5510
|
// src/rules/no-sentinel-return-on-catch.ts
|
|
5207
|
-
var
|
|
5511
|
+
var import_utils34 = require("@typescript-eslint/utils");
|
|
5208
5512
|
function unwrapSentinelExpression(arg) {
|
|
5209
5513
|
let current = arg;
|
|
5210
|
-
while (current?.type ===
|
|
5514
|
+
while (current?.type === import_utils34.AST_NODE_TYPES.TSAsExpression || current?.type === import_utils34.AST_NODE_TYPES.TSTypeAssertion || current?.type === import_utils34.AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
5211
5515
|
current = current.expression;
|
|
5212
5516
|
}
|
|
5213
5517
|
return current;
|
|
@@ -5217,7 +5521,7 @@ function sentinelKind(arg) {
|
|
|
5217
5521
|
if (value === null) {
|
|
5218
5522
|
return null;
|
|
5219
5523
|
}
|
|
5220
|
-
if (value.type ===
|
|
5524
|
+
if (value.type === import_utils34.AST_NODE_TYPES.Literal) {
|
|
5221
5525
|
if (value.value === null) {
|
|
5222
5526
|
return "nullish";
|
|
5223
5527
|
}
|
|
@@ -5229,13 +5533,13 @@ function sentinelKind(arg) {
|
|
|
5229
5533
|
}
|
|
5230
5534
|
return null;
|
|
5231
5535
|
}
|
|
5232
|
-
if (value.type ===
|
|
5536
|
+
if (value.type === import_utils34.AST_NODE_TYPES.Identifier && value.name === "undefined") {
|
|
5233
5537
|
return "nullish";
|
|
5234
5538
|
}
|
|
5235
|
-
if (value.type ===
|
|
5539
|
+
if (value.type === import_utils34.AST_NODE_TYPES.ArrayExpression) {
|
|
5236
5540
|
return "array";
|
|
5237
5541
|
}
|
|
5238
|
-
if (value.type ===
|
|
5542
|
+
if (value.type === import_utils34.AST_NODE_TYPES.ObjectExpression) {
|
|
5239
5543
|
return "object";
|
|
5240
5544
|
}
|
|
5241
5545
|
return null;
|
|
@@ -5245,25 +5549,25 @@ function isSentinelArgument(arg) {
|
|
|
5245
5549
|
if (value === null) {
|
|
5246
5550
|
return false;
|
|
5247
5551
|
}
|
|
5248
|
-
if (value.type ===
|
|
5552
|
+
if (value.type === import_utils34.AST_NODE_TYPES.Literal && value.value === null) {
|
|
5249
5553
|
return true;
|
|
5250
5554
|
}
|
|
5251
|
-
if (value.type ===
|
|
5555
|
+
if (value.type === import_utils34.AST_NODE_TYPES.Literal && value.value === false) {
|
|
5252
5556
|
return true;
|
|
5253
5557
|
}
|
|
5254
|
-
if (value.type ===
|
|
5558
|
+
if (value.type === import_utils34.AST_NODE_TYPES.Identifier && value.name === "undefined") {
|
|
5255
5559
|
return true;
|
|
5256
5560
|
}
|
|
5257
|
-
if (value.type ===
|
|
5561
|
+
if (value.type === import_utils34.AST_NODE_TYPES.ArrayExpression && value.elements.length === 0) {
|
|
5258
5562
|
return true;
|
|
5259
5563
|
}
|
|
5260
|
-
if (value.type ===
|
|
5564
|
+
if (value.type === import_utils34.AST_NODE_TYPES.ObjectExpression && value.properties.length === 0) {
|
|
5261
5565
|
return true;
|
|
5262
5566
|
}
|
|
5263
5567
|
return false;
|
|
5264
5568
|
}
|
|
5265
5569
|
function isFunctionNode(node) {
|
|
5266
|
-
return node.type ===
|
|
5570
|
+
return node.type === import_utils34.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils34.AST_NODE_TYPES.FunctionExpression || node.type === import_utils34.AST_NODE_TYPES.ArrowFunctionExpression;
|
|
5267
5571
|
}
|
|
5268
5572
|
function isNode3(value) {
|
|
5269
5573
|
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
@@ -5303,24 +5607,24 @@ function walkWithinScope(node, visit) {
|
|
|
5303
5607
|
function containsThrow(node) {
|
|
5304
5608
|
return walkWithinScope(
|
|
5305
5609
|
node,
|
|
5306
|
-
(current) => current.type ===
|
|
5610
|
+
(current) => current.type === import_utils34.AST_NODE_TYPES.ThrowStatement
|
|
5307
5611
|
);
|
|
5308
5612
|
}
|
|
5309
5613
|
function bindsName(param, name) {
|
|
5310
5614
|
switch (param.type) {
|
|
5311
|
-
case
|
|
5615
|
+
case import_utils34.AST_NODE_TYPES.Identifier:
|
|
5312
5616
|
return param.name === name;
|
|
5313
|
-
case
|
|
5617
|
+
case import_utils34.AST_NODE_TYPES.AssignmentPattern:
|
|
5314
5618
|
return bindsName(param.left, name);
|
|
5315
|
-
case
|
|
5619
|
+
case import_utils34.AST_NODE_TYPES.RestElement:
|
|
5316
5620
|
return bindsName(param.argument, name);
|
|
5317
|
-
case
|
|
5621
|
+
case import_utils34.AST_NODE_TYPES.ArrayPattern:
|
|
5318
5622
|
return param.elements.some(
|
|
5319
5623
|
(element) => element !== null && bindsName(element, name)
|
|
5320
5624
|
);
|
|
5321
|
-
case
|
|
5625
|
+
case import_utils34.AST_NODE_TYPES.ObjectPattern:
|
|
5322
5626
|
return param.properties.some(
|
|
5323
|
-
(property) => property.type ===
|
|
5627
|
+
(property) => property.type === import_utils34.AST_NODE_TYPES.RestElement ? bindsName(property.argument, name) : bindsName(property.value, name)
|
|
5324
5628
|
);
|
|
5325
5629
|
default:
|
|
5326
5630
|
return false;
|
|
@@ -5335,7 +5639,7 @@ function subtreeReadsName(node, name) {
|
|
|
5335
5639
|
if (found) {
|
|
5336
5640
|
return;
|
|
5337
5641
|
}
|
|
5338
|
-
if (current.type ===
|
|
5642
|
+
if (current.type === import_utils34.AST_NODE_TYPES.Identifier && current.name === name) {
|
|
5339
5643
|
found = true;
|
|
5340
5644
|
return;
|
|
5341
5645
|
}
|
|
@@ -5346,10 +5650,10 @@ function subtreeReadsName(node, name) {
|
|
|
5346
5650
|
if (key === "parent") {
|
|
5347
5651
|
continue;
|
|
5348
5652
|
}
|
|
5349
|
-
if (key === "key" && current.type ===
|
|
5653
|
+
if (key === "key" && current.type === import_utils34.AST_NODE_TYPES.Property && !current.computed) {
|
|
5350
5654
|
continue;
|
|
5351
5655
|
}
|
|
5352
|
-
if (key === "property" && current.type ===
|
|
5656
|
+
if (key === "property" && current.type === import_utils34.AST_NODE_TYPES.MemberExpression && !current.computed) {
|
|
5353
5657
|
continue;
|
|
5354
5658
|
}
|
|
5355
5659
|
const value = current[key];
|
|
@@ -5374,10 +5678,10 @@ function argsIncludeBinding(args, caughtName) {
|
|
|
5374
5678
|
return args.some((arg) => subtreeReadsName(arg, caughtName));
|
|
5375
5679
|
}
|
|
5376
5680
|
function isParseShapedNode(node) {
|
|
5377
|
-
if (node.type ===
|
|
5681
|
+
if (node.type === import_utils34.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils34.AST_NODE_TYPES.MemberExpression && !node.callee.computed && node.callee.property.type === import_utils34.AST_NODE_TYPES.Identifier) {
|
|
5378
5682
|
return node.callee.property.name === "parse";
|
|
5379
5683
|
}
|
|
5380
|
-
if (node.type ===
|
|
5684
|
+
if (node.type === import_utils34.AST_NODE_TYPES.NewExpression && node.callee.type === import_utils34.AST_NODE_TYPES.Identifier) {
|
|
5381
5685
|
return SAFE_PARSE_CONSTRUCTORS.has(node.callee.name);
|
|
5382
5686
|
}
|
|
5383
5687
|
return false;
|
|
@@ -5388,7 +5692,7 @@ var SAFE_PARSE_CONSTRUCTORS = /* @__PURE__ */ new Set([
|
|
|
5388
5692
|
"URLPattern"
|
|
5389
5693
|
]);
|
|
5390
5694
|
function isBodyDecodeNode(node) {
|
|
5391
|
-
return node.type ===
|
|
5695
|
+
return node.type === import_utils34.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils34.AST_NODE_TYPES.MemberExpression && !node.callee.computed && node.callee.property.type === import_utils34.AST_NODE_TYPES.Identifier && BODY_DECODE_METHODS.has(node.callee.property.name);
|
|
5392
5696
|
}
|
|
5393
5697
|
var BODY_DECODE_METHODS = /* @__PURE__ */ new Set([
|
|
5394
5698
|
"json",
|
|
@@ -5396,7 +5700,7 @@ var BODY_DECODE_METHODS = /* @__PURE__ */ new Set([
|
|
|
5396
5700
|
"arrayBuffer"
|
|
5397
5701
|
]);
|
|
5398
5702
|
function returnsMatching(stmt, predicate) {
|
|
5399
|
-
return stmt.type ===
|
|
5703
|
+
return stmt.type === import_utils34.AST_NODE_TYPES.ReturnStatement && stmt.argument !== null && walkWithinScope(stmt.argument, predicate);
|
|
5400
5704
|
}
|
|
5401
5705
|
function isNamedBooleanPredicate(catchNode, kind) {
|
|
5402
5706
|
if (kind !== "boolean") {
|
|
@@ -5409,11 +5713,11 @@ function enclosingFunctionName(node) {
|
|
|
5409
5713
|
let current = node.parent;
|
|
5410
5714
|
while (current !== void 0 && current !== null) {
|
|
5411
5715
|
if (isFunctionNode(current)) {
|
|
5412
|
-
if ("id" in current && isNode3(current.id) && current.id.type ===
|
|
5716
|
+
if ("id" in current && isNode3(current.id) && current.id.type === import_utils34.AST_NODE_TYPES.Identifier) {
|
|
5413
5717
|
return current.id.name;
|
|
5414
5718
|
}
|
|
5415
5719
|
const parent = current.parent;
|
|
5416
|
-
if (parent?.type ===
|
|
5720
|
+
if (parent?.type === import_utils34.AST_NODE_TYPES.VariableDeclarator && parent.id.type === import_utils34.AST_NODE_TYPES.Identifier) {
|
|
5417
5721
|
return parent.id.name;
|
|
5418
5722
|
}
|
|
5419
5723
|
return null;
|
|
@@ -5429,10 +5733,10 @@ function isDeclaredBooleanPredicate(catchNode, kind) {
|
|
|
5429
5733
|
return false;
|
|
5430
5734
|
}
|
|
5431
5735
|
let declared = enclosingReturnTypeNode(catchNode);
|
|
5432
|
-
if (declared?.type ===
|
|
5736
|
+
if (declared?.type === import_utils34.AST_NODE_TYPES.TSTypeReference && declared.typeName.type === import_utils34.AST_NODE_TYPES.Identifier && declared.typeName.name === "Promise") {
|
|
5433
5737
|
declared = declared.typeArguments?.params[0] ?? null;
|
|
5434
5738
|
}
|
|
5435
|
-
return declared?.type ===
|
|
5739
|
+
return declared?.type === import_utils34.AST_NODE_TYPES.TSBooleanKeyword;
|
|
5436
5740
|
}
|
|
5437
5741
|
function enclosingReturnTypeNode(node) {
|
|
5438
5742
|
let current = node.parent;
|
|
@@ -5459,9 +5763,9 @@ function isIntentionalStackCapture(catchNode, caughtName) {
|
|
|
5459
5763
|
if (caughtName === null) return false;
|
|
5460
5764
|
const tryBody = tryBlockOf(catchNode).body;
|
|
5461
5765
|
const only = tryBody.length === 1 ? tryBody[0] : void 0;
|
|
5462
|
-
if (only?.type !==
|
|
5766
|
+
if (only?.type !== import_utils34.AST_NODE_TYPES.ThrowStatement) return false;
|
|
5463
5767
|
const thrown = unwrapSentinelExpression(only.argument);
|
|
5464
|
-
const constructsError = (thrown?.type ===
|
|
5768
|
+
const constructsError = (thrown?.type === import_utils34.AST_NODE_TYPES.CallExpression || thrown?.type === import_utils34.AST_NODE_TYPES.NewExpression) && thrown.callee.type === import_utils34.AST_NODE_TYPES.Identifier && thrown.callee.name === "Error";
|
|
5465
5769
|
if (!constructsError) return false;
|
|
5466
5770
|
return catchNode.body.body.slice(0, -1).some((statement) => subtreeReadsName(statement, caughtName));
|
|
5467
5771
|
}
|
|
@@ -5474,7 +5778,7 @@ function functionReturnsSameSentinelKindElsewhere(catchNode, kind) {
|
|
|
5474
5778
|
return false;
|
|
5475
5779
|
}
|
|
5476
5780
|
return walkWithinScope(functionBody, (current) => {
|
|
5477
|
-
if (current.type !==
|
|
5781
|
+
if (current.type !== import_utils34.AST_NODE_TYPES.ReturnStatement) {
|
|
5478
5782
|
return false;
|
|
5479
5783
|
}
|
|
5480
5784
|
if (isWithin(current, catchNode.body)) {
|
|
@@ -5486,7 +5790,7 @@ function functionReturnsSameSentinelKindElsewhere(catchNode, kind) {
|
|
|
5486
5790
|
function enclosingFunctionBody(node) {
|
|
5487
5791
|
let current = node.parent;
|
|
5488
5792
|
while (current !== void 0 && current !== null) {
|
|
5489
|
-
if (isFunctionNode(current) && "body" in current && isNode3(current.body) && current.body.type ===
|
|
5793
|
+
if (isFunctionNode(current) && "body" in current && isNode3(current.body) && current.body.type === import_utils34.AST_NODE_TYPES.BlockStatement) {
|
|
5490
5794
|
return current.body;
|
|
5491
5795
|
}
|
|
5492
5796
|
current = current.parent;
|
|
@@ -5503,13 +5807,13 @@ function returnedSentinelKinds(arg) {
|
|
|
5503
5807
|
kinds.add(direct);
|
|
5504
5808
|
return kinds;
|
|
5505
5809
|
}
|
|
5506
|
-
if (arg.type ===
|
|
5810
|
+
if (arg.type === import_utils34.AST_NODE_TYPES.ConditionalExpression) {
|
|
5507
5811
|
for (const branch of [arg.consequent, arg.alternate]) {
|
|
5508
5812
|
for (const nested of returnedSentinelKinds(branch)) {
|
|
5509
5813
|
kinds.add(nested);
|
|
5510
5814
|
}
|
|
5511
5815
|
}
|
|
5512
|
-
} else if (arg.type ===
|
|
5816
|
+
} else if (arg.type === import_utils34.AST_NODE_TYPES.LogicalExpression && (arg.operator === "??" || arg.operator === "||")) {
|
|
5513
5817
|
for (const nested of returnedSentinelKinds(arg.right)) {
|
|
5514
5818
|
kinds.add(nested);
|
|
5515
5819
|
}
|
|
@@ -5552,7 +5856,7 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
5552
5856
|
const matcher = createLogMatcher(loggingOptions);
|
|
5553
5857
|
function logsOrReportsError(catchBody, caughtName) {
|
|
5554
5858
|
return walkWithinScope(catchBody, (current) => {
|
|
5555
|
-
if (current.type !==
|
|
5859
|
+
if (current.type !== import_utils34.AST_NODE_TYPES.CallExpression) {
|
|
5556
5860
|
return false;
|
|
5557
5861
|
}
|
|
5558
5862
|
if (matcher.isLoggingCall(current)) {
|
|
@@ -5569,7 +5873,7 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
5569
5873
|
return;
|
|
5570
5874
|
}
|
|
5571
5875
|
const last = body2[body2.length - 1];
|
|
5572
|
-
if (last === void 0 || last.type !==
|
|
5876
|
+
if (last === void 0 || last.type !== import_utils34.AST_NODE_TYPES.ReturnStatement) {
|
|
5573
5877
|
return;
|
|
5574
5878
|
}
|
|
5575
5879
|
if (!isSentinelArgument(last.argument)) {
|
|
@@ -5578,7 +5882,7 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
5578
5882
|
if (containsThrow(node.body)) {
|
|
5579
5883
|
return;
|
|
5580
5884
|
}
|
|
5581
|
-
const caughtName = node.param?.type ===
|
|
5885
|
+
const caughtName = node.param?.type === import_utils34.AST_NODE_TYPES.Identifier ? node.param.name : null;
|
|
5582
5886
|
if (logsOrReportsError(node.body, caughtName)) {
|
|
5583
5887
|
return;
|
|
5584
5888
|
}
|
|
@@ -5608,9 +5912,9 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
5608
5912
|
});
|
|
5609
5913
|
|
|
5610
5914
|
// src/rules/no-silent-promise-catch.ts
|
|
5611
|
-
var
|
|
5915
|
+
var import_utils35 = require("@typescript-eslint/utils");
|
|
5612
5916
|
function isBodyParseCall(node) {
|
|
5613
|
-
return node.type ===
|
|
5917
|
+
return node.type === import_utils35.AST_NODE_TYPES.CallExpression && node.arguments.length === 0 && node.callee.type === import_utils35.AST_NODE_TYPES.MemberExpression && !node.callee.computed && node.callee.property.type === import_utils35.AST_NODE_TYPES.Identifier && (node.callee.property.name === "json" || node.callee.property.name === "text");
|
|
5614
5918
|
}
|
|
5615
5919
|
var TEARDOWN_METHODS = /* @__PURE__ */ new Set([
|
|
5616
5920
|
"cancel",
|
|
@@ -5625,11 +5929,11 @@ var TEARDOWN_METHODS = /* @__PURE__ */ new Set([
|
|
|
5625
5929
|
var DIRECTIVE_COMMENT_RE = /^\s*(eslint-|@ts-|prettier-ignore|biome-ignore|c8 |v8 |istanbul )/;
|
|
5626
5930
|
var isExplanatory = (comment) => !DIRECTIVE_COMMENT_RE.test(comment.value);
|
|
5627
5931
|
function isTeardownCall(node) {
|
|
5628
|
-
return node.type ===
|
|
5932
|
+
return node.type === import_utils35.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils35.AST_NODE_TYPES.MemberExpression && !node.callee.computed && node.callee.property.type === import_utils35.AST_NODE_TYPES.Identifier && TEARDOWN_METHODS.has(node.callee.property.name);
|
|
5629
5933
|
}
|
|
5630
5934
|
function isSilentHandler(handler) {
|
|
5631
5935
|
const body2 = handler.body;
|
|
5632
|
-
if (body2.type !==
|
|
5936
|
+
if (body2.type !== import_utils35.AST_NODE_TYPES.BlockStatement) {
|
|
5633
5937
|
return isSilentExpression(body2);
|
|
5634
5938
|
}
|
|
5635
5939
|
if (body2.body.length === 0) {
|
|
@@ -5637,7 +5941,7 @@ function isSilentHandler(handler) {
|
|
|
5637
5941
|
}
|
|
5638
5942
|
if (body2.body.length === 1) {
|
|
5639
5943
|
const only = body2.body[0];
|
|
5640
|
-
if (only !== void 0 && only.type ===
|
|
5944
|
+
if (only !== void 0 && only.type === import_utils35.AST_NODE_TYPES.ReturnStatement) {
|
|
5641
5945
|
return only.argument === null || isSilentExpression(only.argument);
|
|
5642
5946
|
}
|
|
5643
5947
|
}
|
|
@@ -5645,17 +5949,17 @@ function isSilentHandler(handler) {
|
|
|
5645
5949
|
}
|
|
5646
5950
|
function isSilentExpression(node) {
|
|
5647
5951
|
switch (node.type) {
|
|
5648
|
-
case
|
|
5952
|
+
case import_utils35.AST_NODE_TYPES.Literal:
|
|
5649
5953
|
return !("regex" in node);
|
|
5650
|
-
case
|
|
5954
|
+
case import_utils35.AST_NODE_TYPES.Identifier:
|
|
5651
5955
|
return node.name === "undefined";
|
|
5652
|
-
case
|
|
5653
|
-
return node.operator === "void" && node.argument.type ===
|
|
5654
|
-
case
|
|
5956
|
+
case import_utils35.AST_NODE_TYPES.UnaryExpression:
|
|
5957
|
+
return node.operator === "void" && node.argument.type === import_utils35.AST_NODE_TYPES.Literal;
|
|
5958
|
+
case import_utils35.AST_NODE_TYPES.ObjectExpression:
|
|
5655
5959
|
return node.properties.length === 0;
|
|
5656
|
-
case
|
|
5960
|
+
case import_utils35.AST_NODE_TYPES.ArrayExpression:
|
|
5657
5961
|
return node.elements.length === 0;
|
|
5658
|
-
case
|
|
5962
|
+
case import_utils35.AST_NODE_TYPES.TSAsExpression:
|
|
5659
5963
|
return isSilentExpression(node.expression);
|
|
5660
5964
|
default:
|
|
5661
5965
|
return false;
|
|
@@ -5684,7 +5988,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
5684
5988
|
return true;
|
|
5685
5989
|
}
|
|
5686
5990
|
let statement = call;
|
|
5687
|
-
while (statement.parent !== void 0 && statement.parent !== null && !statement.type.endsWith("Statement") && statement.type !==
|
|
5991
|
+
while (statement.parent !== void 0 && statement.parent !== null && !statement.type.endsWith("Statement") && statement.type !== import_utils35.AST_NODE_TYPES.VariableDeclaration) {
|
|
5688
5992
|
statement = statement.parent;
|
|
5689
5993
|
}
|
|
5690
5994
|
if (sourceCode.getCommentsBefore(statement).some(isExplanatory)) {
|
|
@@ -5696,7 +6000,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
5696
6000
|
};
|
|
5697
6001
|
return {
|
|
5698
6002
|
CallExpression(node) {
|
|
5699
|
-
if (node.callee.type !==
|
|
6003
|
+
if (node.callee.type !== import_utils35.AST_NODE_TYPES.MemberExpression || node.callee.computed || node.callee.property.type !== import_utils35.AST_NODE_TYPES.Identifier) {
|
|
5700
6004
|
return;
|
|
5701
6005
|
}
|
|
5702
6006
|
const method = node.callee.property.name;
|
|
@@ -5708,7 +6012,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
5708
6012
|
if (isTeardownCall(node.callee.object)) {
|
|
5709
6013
|
return;
|
|
5710
6014
|
}
|
|
5711
|
-
if (node.parent.type ===
|
|
6015
|
+
if (node.parent.type === import_utils35.AST_NODE_TYPES.MemberExpression && node.parent.object === node) {
|
|
5712
6016
|
return;
|
|
5713
6017
|
}
|
|
5714
6018
|
const expectedArguments = method === "catch" ? 1 : 2;
|
|
@@ -5716,7 +6020,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
5716
6020
|
return;
|
|
5717
6021
|
}
|
|
5718
6022
|
const handler = node.arguments[handlerIndex];
|
|
5719
|
-
if (handler === void 0 || handler.type !==
|
|
6023
|
+
if (handler === void 0 || handler.type !== import_utils35.AST_NODE_TYPES.ArrowFunctionExpression && handler.type !== import_utils35.AST_NODE_TYPES.FunctionExpression) {
|
|
5720
6024
|
return;
|
|
5721
6025
|
}
|
|
5722
6026
|
if (hasExplanatoryComment(node, handler)) {
|
|
@@ -5731,7 +6035,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
5731
6035
|
});
|
|
5732
6036
|
|
|
5733
6037
|
// src/rules/no-sleep-in-test-body.ts
|
|
5734
|
-
var
|
|
6038
|
+
var import_utils36 = require("@typescript-eslint/utils");
|
|
5735
6039
|
var SLEEP_HELPERS = /* @__PURE__ */ new Set(["sleep", "delay", "wait", "pause"]);
|
|
5736
6040
|
var TEST_CALLERS3 = /* @__PURE__ */ new Set([
|
|
5737
6041
|
"it",
|
|
@@ -5740,34 +6044,34 @@ var TEST_CALLERS3 = /* @__PURE__ */ new Set([
|
|
|
5740
6044
|
"afterEach"
|
|
5741
6045
|
]);
|
|
5742
6046
|
var FUNCTION_TYPES5 = /* @__PURE__ */ new Set([
|
|
5743
|
-
|
|
5744
|
-
|
|
5745
|
-
|
|
6047
|
+
import_utils36.AST_NODE_TYPES.FunctionDeclaration,
|
|
6048
|
+
import_utils36.AST_NODE_TYPES.FunctionExpression,
|
|
6049
|
+
import_utils36.AST_NODE_TYPES.ArrowFunctionExpression
|
|
5746
6050
|
]);
|
|
5747
6051
|
function isNonzeroNumericLiteral(node) {
|
|
5748
|
-
return node?.type ===
|
|
6052
|
+
return node?.type === import_utils36.AST_NODE_TYPES.Literal && typeof node.value === "number" && node.value !== 0;
|
|
5749
6053
|
}
|
|
5750
6054
|
function isTimedSetTimeout(node) {
|
|
5751
|
-
return node.type ===
|
|
6055
|
+
return node.type === import_utils36.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils36.AST_NODE_TYPES.Identifier && node.callee.name === "setTimeout" && node.arguments.length >= 2 && isNonzeroNumericLiteral(node.arguments[1]);
|
|
5752
6056
|
}
|
|
5753
6057
|
function isPromiseSleep(node) {
|
|
5754
|
-
if (node.callee.type !==
|
|
6058
|
+
if (node.callee.type !== import_utils36.AST_NODE_TYPES.Identifier || node.callee.name !== "Promise") {
|
|
5755
6059
|
return false;
|
|
5756
6060
|
}
|
|
5757
6061
|
const executor = node.arguments[0];
|
|
5758
|
-
if (executor?.type !==
|
|
6062
|
+
if (executor?.type !== import_utils36.AST_NODE_TYPES.ArrowFunctionExpression && executor?.type !== import_utils36.AST_NODE_TYPES.FunctionExpression) {
|
|
5759
6063
|
return false;
|
|
5760
6064
|
}
|
|
5761
6065
|
const body2 = executor.body;
|
|
5762
|
-
if (body2.type !==
|
|
6066
|
+
if (body2.type !== import_utils36.AST_NODE_TYPES.BlockStatement) {
|
|
5763
6067
|
return isTimedSetTimeout(body2);
|
|
5764
6068
|
}
|
|
5765
6069
|
return body2.body.some(
|
|
5766
|
-
(stmt) => stmt.type ===
|
|
6070
|
+
(stmt) => stmt.type === import_utils36.AST_NODE_TYPES.ExpressionStatement && isTimedSetTimeout(stmt.expression)
|
|
5767
6071
|
);
|
|
5768
6072
|
}
|
|
5769
6073
|
function isHelperSleep(node) {
|
|
5770
|
-
return node.callee.type ===
|
|
6074
|
+
return node.callee.type === import_utils36.AST_NODE_TYPES.Identifier && SLEEP_HELPERS.has(node.callee.name) && node.arguments.length >= 1 && isNonzeroNumericLiteral(node.arguments[0]);
|
|
5771
6075
|
}
|
|
5772
6076
|
function nearestEnclosingFunction2(node) {
|
|
5773
6077
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
@@ -5775,7 +6079,7 @@ function nearestEnclosingFunction2(node) {
|
|
|
5775
6079
|
continue;
|
|
5776
6080
|
}
|
|
5777
6081
|
const grandparent = current.parent;
|
|
5778
|
-
const isPromiseExecutor = grandparent?.type ===
|
|
6082
|
+
const isPromiseExecutor = grandparent?.type === import_utils36.AST_NODE_TYPES.NewExpression && isPromiseSleep(grandparent);
|
|
5779
6083
|
if (!isPromiseExecutor) {
|
|
5780
6084
|
return current;
|
|
5781
6085
|
}
|
|
@@ -5784,23 +6088,23 @@ function nearestEnclosingFunction2(node) {
|
|
|
5784
6088
|
}
|
|
5785
6089
|
function isTestBody2(fn) {
|
|
5786
6090
|
const call = fn.parent;
|
|
5787
|
-
if (call?.type !==
|
|
6091
|
+
if (call?.type !== import_utils36.AST_NODE_TYPES.CallExpression || !call.arguments.some((argument) => argument === fn)) {
|
|
5788
6092
|
return false;
|
|
5789
6093
|
}
|
|
5790
6094
|
const name = testCallerName2(call.callee);
|
|
5791
6095
|
return name !== null && TEST_CALLERS3.has(name);
|
|
5792
6096
|
}
|
|
5793
6097
|
function testCallerName2(callee) {
|
|
5794
|
-
if (callee.type ===
|
|
6098
|
+
if (callee.type === import_utils36.AST_NODE_TYPES.Identifier) {
|
|
5795
6099
|
return callee.name;
|
|
5796
6100
|
}
|
|
5797
|
-
if (callee.type ===
|
|
6101
|
+
if (callee.type === import_utils36.AST_NODE_TYPES.MemberExpression) {
|
|
5798
6102
|
return testCallerName2(callee.object);
|
|
5799
6103
|
}
|
|
5800
|
-
if (callee.type ===
|
|
6104
|
+
if (callee.type === import_utils36.AST_NODE_TYPES.CallExpression) {
|
|
5801
6105
|
return testCallerName2(callee.callee);
|
|
5802
6106
|
}
|
|
5803
|
-
if (callee.type ===
|
|
6107
|
+
if (callee.type === import_utils36.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
5804
6108
|
return testCallerName2(callee.tag);
|
|
5805
6109
|
}
|
|
5806
6110
|
return null;
|
|
@@ -5845,7 +6149,7 @@ var no_sleep_in_test_body_default = createRule({
|
|
|
5845
6149
|
});
|
|
5846
6150
|
|
|
5847
6151
|
// src/rules/no-storage-in-stateless-modules.ts
|
|
5848
|
-
var
|
|
6152
|
+
var import_utils37 = require("@typescript-eslint/utils");
|
|
5849
6153
|
var DEFAULT_METHODS2 = [
|
|
5850
6154
|
"prepare",
|
|
5851
6155
|
"put",
|
|
@@ -5864,7 +6168,7 @@ function compile2(patterns) {
|
|
|
5864
6168
|
}
|
|
5865
6169
|
function storageMethodName(node, methods) {
|
|
5866
6170
|
const callee = node.callee;
|
|
5867
|
-
if (callee.type !==
|
|
6171
|
+
if (callee.type !== import_utils37.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils37.AST_NODE_TYPES.Identifier) {
|
|
5868
6172
|
return null;
|
|
5869
6173
|
}
|
|
5870
6174
|
const name = callee.property.name;
|
|
@@ -5932,7 +6236,7 @@ var no_storage_in_stateless_modules_default = createRule({
|
|
|
5932
6236
|
});
|
|
5933
6237
|
|
|
5934
6238
|
// src/rules/no-string-concat-in-loop.ts
|
|
5935
|
-
var
|
|
6239
|
+
var import_utils38 = require("@typescript-eslint/utils");
|
|
5936
6240
|
var LOOP_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
5937
6241
|
"ForStatement",
|
|
5938
6242
|
"ForOfStatement",
|
|
@@ -6083,7 +6387,7 @@ var no_string_concat_in_loop_default = createRule({
|
|
|
6083
6387
|
});
|
|
6084
6388
|
|
|
6085
6389
|
// src/rules/no-tautological-expect.ts
|
|
6086
|
-
var
|
|
6390
|
+
var import_utils39 = require("@typescript-eslint/utils");
|
|
6087
6391
|
var EQUALITY_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
6088
6392
|
var ZERO_ARG_MATCHERS = /* @__PURE__ */ new Set([
|
|
6089
6393
|
"toBeDefined",
|
|
@@ -6097,17 +6401,17 @@ var OPERAND_PREVIEW_CHARS = 40;
|
|
|
6097
6401
|
var NUMERIC_SIGNS = /* @__PURE__ */ new Set(["-", "+"]);
|
|
6098
6402
|
function isLiteral(node) {
|
|
6099
6403
|
switch (node.type) {
|
|
6100
|
-
case
|
|
6404
|
+
case import_utils39.AST_NODE_TYPES.Literal:
|
|
6101
6405
|
return true;
|
|
6102
|
-
case
|
|
6406
|
+
case import_utils39.AST_NODE_TYPES.TemplateLiteral:
|
|
6103
6407
|
return node.expressions.length === 0;
|
|
6104
|
-
case
|
|
6408
|
+
case import_utils39.AST_NODE_TYPES.UnaryExpression:
|
|
6105
6409
|
return NUMERIC_SIGNS.has(node.operator) && isLiteral(node.argument);
|
|
6106
|
-
case
|
|
6410
|
+
case import_utils39.AST_NODE_TYPES.ArrayExpression:
|
|
6107
6411
|
return node.elements.every((element) => element !== null && isLiteral(element));
|
|
6108
|
-
case
|
|
6412
|
+
case import_utils39.AST_NODE_TYPES.ObjectExpression:
|
|
6109
6413
|
return node.properties.every(
|
|
6110
|
-
(property) => property.type ===
|
|
6414
|
+
(property) => property.type === import_utils39.AST_NODE_TYPES.Property && !property.computed && isLiteral(property.value)
|
|
6111
6415
|
);
|
|
6112
6416
|
default:
|
|
6113
6417
|
return false;
|
|
@@ -6115,7 +6419,7 @@ function isLiteral(node) {
|
|
|
6115
6419
|
}
|
|
6116
6420
|
function expectOperand(callee) {
|
|
6117
6421
|
const receiver = callee.object;
|
|
6118
|
-
if (receiver.type !==
|
|
6422
|
+
if (receiver.type !== import_utils39.AST_NODE_TYPES.CallExpression || receiver.callee.type !== import_utils39.AST_NODE_TYPES.Identifier || receiver.callee.name !== "expect" || receiver.arguments.length !== 1) {
|
|
6119
6423
|
return null;
|
|
6120
6424
|
}
|
|
6121
6425
|
return receiver.arguments[0] ?? null;
|
|
@@ -6145,10 +6449,10 @@ var no_tautological_expect_default = createRule({
|
|
|
6145
6449
|
return {
|
|
6146
6450
|
CallExpression(node) {
|
|
6147
6451
|
const callee = node.callee;
|
|
6148
|
-
if (callee.type !==
|
|
6452
|
+
if (callee.type !== import_utils39.AST_NODE_TYPES.MemberExpression || callee.computed) {
|
|
6149
6453
|
return;
|
|
6150
6454
|
}
|
|
6151
|
-
if (callee.property.type !==
|
|
6455
|
+
if (callee.property.type !== import_utils39.AST_NODE_TYPES.Identifier) {
|
|
6152
6456
|
return;
|
|
6153
6457
|
}
|
|
6154
6458
|
const matcher = callee.property.name;
|
|
@@ -6207,7 +6511,7 @@ var no_typed_doc_sections_default = createRule({
|
|
|
6207
6511
|
});
|
|
6208
6512
|
|
|
6209
6513
|
// src/rules/no-trailing-value-narration.ts
|
|
6210
|
-
var
|
|
6514
|
+
var import_utils40 = require("@typescript-eslint/utils");
|
|
6211
6515
|
var NUMBER_RE = /(?<![\w.])(\d+(?:\.\d+)?)(?![\w.])/g;
|
|
6212
6516
|
var WORD_RE3 = /[A-Za-z]+(?:'[a-z]+)?|\d+(?:\.\d+)?/g;
|
|
6213
6517
|
var UNIT_WORDS = /* @__PURE__ */ new Set([
|
|
@@ -6342,10 +6646,10 @@ var no_trailing_value_narration_default = createRule({
|
|
|
6342
6646
|
});
|
|
6343
6647
|
|
|
6344
6648
|
// src/rules/no-declaration-comment-wall.ts
|
|
6345
|
-
var
|
|
6649
|
+
var import_utils42 = require("@typescript-eslint/utils");
|
|
6346
6650
|
|
|
6347
6651
|
// src/rules/_comment-wall.ts
|
|
6348
|
-
var
|
|
6652
|
+
var import_utils41 = require("@typescript-eslint/utils");
|
|
6349
6653
|
var WALL_DEFAULTS = {
|
|
6350
6654
|
// Below three rows "a wall" is not a fair description of what the reader sees.
|
|
6351
6655
|
minCommentedMembers: 3,
|
|
@@ -6446,10 +6750,10 @@ function isWall(members, commented, restated, options) {
|
|
|
6446
6750
|
return commented >= options.minCommentedMembers && commented / members >= options.minCommentedRatio && restated / commented >= options.minRestatedRatio;
|
|
6447
6751
|
}
|
|
6448
6752
|
var OPAQUE_VALUE_TYPES = /* @__PURE__ */ new Set([
|
|
6449
|
-
|
|
6450
|
-
|
|
6451
|
-
|
|
6452
|
-
|
|
6753
|
+
import_utils41.AST_NODE_TYPES.FunctionExpression,
|
|
6754
|
+
import_utils41.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
6755
|
+
import_utils41.AST_NODE_TYPES.ObjectExpression,
|
|
6756
|
+
import_utils41.AST_NODE_TYPES.ArrayExpression
|
|
6453
6757
|
]);
|
|
6454
6758
|
function declarationRange(member) {
|
|
6455
6759
|
const body2 = bodyOf(member);
|
|
@@ -6459,10 +6763,10 @@ function declarationRange(member) {
|
|
|
6459
6763
|
};
|
|
6460
6764
|
}
|
|
6461
6765
|
function bodyOf(member) {
|
|
6462
|
-
if (member.type ===
|
|
6766
|
+
if (member.type === import_utils41.AST_NODE_TYPES.MethodDefinition || member.type === import_utils41.AST_NODE_TYPES.TSAbstractMethodDefinition) {
|
|
6463
6767
|
return member.value.body ?? void 0;
|
|
6464
6768
|
}
|
|
6465
|
-
if (member.type ===
|
|
6769
|
+
if (member.type === import_utils41.AST_NODE_TYPES.Property || member.type === import_utils41.AST_NODE_TYPES.PropertyDefinition) {
|
|
6466
6770
|
const value = member.value;
|
|
6467
6771
|
if (value !== null && OPAQUE_VALUE_TYPES.has(value.type)) return value;
|
|
6468
6772
|
}
|
|
@@ -6472,12 +6776,12 @@ function bodyOf(member) {
|
|
|
6472
6776
|
// src/rules/no-declaration-comment-wall.ts
|
|
6473
6777
|
function named(node) {
|
|
6474
6778
|
switch (node.type) {
|
|
6475
|
-
case
|
|
6779
|
+
case import_utils42.AST_NODE_TYPES.TSEnumMember:
|
|
6476
6780
|
return { node, key: node.id };
|
|
6477
|
-
case
|
|
6478
|
-
case
|
|
6479
|
-
case
|
|
6480
|
-
case
|
|
6781
|
+
case import_utils42.AST_NODE_TYPES.PropertyDefinition:
|
|
6782
|
+
case import_utils42.AST_NODE_TYPES.TSAbstractPropertyDefinition:
|
|
6783
|
+
case import_utils42.AST_NODE_TYPES.MethodDefinition:
|
|
6784
|
+
case import_utils42.AST_NODE_TYPES.TSAbstractMethodDefinition:
|
|
6481
6785
|
return node.computed ? void 0 : { node, key: node.key };
|
|
6482
6786
|
default:
|
|
6483
6787
|
return void 0;
|
|
@@ -6577,7 +6881,7 @@ var no_declaration_comment_wall_default = createRule({
|
|
|
6577
6881
|
});
|
|
6578
6882
|
|
|
6579
6883
|
// src/rules/no-union-in-comment.ts
|
|
6580
|
-
var
|
|
6884
|
+
var import_utils43 = require("@typescript-eslint/utils");
|
|
6581
6885
|
var MAX_LITERAL_LENGTH = 28;
|
|
6582
6886
|
var LITERAL = String.raw`(?:'[^'\n]*'|"[^"\n]*"|\`[^\`\n]*\`)`;
|
|
6583
6887
|
var LEAD_IN_RE2 = /^(?:one of|either|values?|allowed(?: values)?|options?|possible(?: values)?)\s*[:=-]?\s*/i;
|
|
@@ -6596,14 +6900,14 @@ var STRING_BUILDERS = /* @__PURE__ */ new Set([
|
|
|
6596
6900
|
function isBareString(node) {
|
|
6597
6901
|
if (node === void 0) return false;
|
|
6598
6902
|
switch (node.type) {
|
|
6599
|
-
case
|
|
6903
|
+
case import_utils43.AST_NODE_TYPES.TSStringKeyword:
|
|
6600
6904
|
return true;
|
|
6601
6905
|
// `string[]` holds members of the same closed set, one element at a time.
|
|
6602
|
-
case
|
|
6906
|
+
case import_utils43.AST_NODE_TYPES.TSArrayType:
|
|
6603
6907
|
return isBareString(node.elementType);
|
|
6604
6908
|
// `string | null` is still an unconstrained string, and so is `string | "a"`
|
|
6605
6909
|
// — the checker collapses that one to `string`.
|
|
6606
|
-
case
|
|
6910
|
+
case import_utils43.AST_NODE_TYPES.TSUnionType:
|
|
6607
6911
|
return node.types.some((member) => isBareString(member));
|
|
6608
6912
|
default:
|
|
6609
6913
|
return false;
|
|
@@ -6611,20 +6915,20 @@ function isBareString(node) {
|
|
|
6611
6915
|
}
|
|
6612
6916
|
function targetOf(node) {
|
|
6613
6917
|
switch (node.type) {
|
|
6614
|
-
case
|
|
6615
|
-
case
|
|
6918
|
+
case import_utils43.AST_NODE_TYPES.TSPropertySignature:
|
|
6919
|
+
case import_utils43.AST_NODE_TYPES.PropertyDefinition: {
|
|
6616
6920
|
const name = node.computed ? null : nameOf(node.key);
|
|
6617
6921
|
if (name === null || !isBareString(node.typeAnnotation?.typeAnnotation)) return null;
|
|
6618
6922
|
return { node, name };
|
|
6619
6923
|
}
|
|
6620
|
-
case
|
|
6924
|
+
case import_utils43.AST_NODE_TYPES.Property: {
|
|
6621
6925
|
const name = node.computed || node.shorthand ? null : nameOf(node.key);
|
|
6622
6926
|
const callee = rootCallee(node.value);
|
|
6623
6927
|
if (name === null || callee === null || !STRING_BUILDERS.has(callee)) return null;
|
|
6624
6928
|
return { node, name };
|
|
6625
6929
|
}
|
|
6626
|
-
case
|
|
6627
|
-
if (node.id.type !==
|
|
6930
|
+
case import_utils43.AST_NODE_TYPES.VariableDeclarator: {
|
|
6931
|
+
if (node.id.type !== import_utils43.AST_NODE_TYPES.Identifier) return null;
|
|
6628
6932
|
if (!isBareString(node.id.typeAnnotation?.typeAnnotation)) return null;
|
|
6629
6933
|
return { node, name: node.id.name };
|
|
6630
6934
|
}
|
|
@@ -6636,13 +6940,13 @@ function rootCallee(node) {
|
|
|
6636
6940
|
let current = node;
|
|
6637
6941
|
for (let hops = 0; current != null && hops < 12; hops += 1) {
|
|
6638
6942
|
switch (current.type) {
|
|
6639
|
-
case
|
|
6943
|
+
case import_utils43.AST_NODE_TYPES.CallExpression:
|
|
6640
6944
|
current = current.callee;
|
|
6641
6945
|
break;
|
|
6642
|
-
case
|
|
6946
|
+
case import_utils43.AST_NODE_TYPES.MemberExpression:
|
|
6643
6947
|
current = current.object;
|
|
6644
6948
|
break;
|
|
6645
|
-
case
|
|
6949
|
+
case import_utils43.AST_NODE_TYPES.Identifier:
|
|
6646
6950
|
return current.name;
|
|
6647
6951
|
default:
|
|
6648
6952
|
return null;
|
|
@@ -6651,8 +6955,8 @@ function rootCallee(node) {
|
|
|
6651
6955
|
return null;
|
|
6652
6956
|
}
|
|
6653
6957
|
function nameOf(key) {
|
|
6654
|
-
if (key.type ===
|
|
6655
|
-
if (key.type ===
|
|
6958
|
+
if (key.type === import_utils43.AST_NODE_TYPES.Identifier) return key.name;
|
|
6959
|
+
if (key.type === import_utils43.AST_NODE_TYPES.Literal && typeof key.value === "string") return key.value;
|
|
6656
6960
|
return null;
|
|
6657
6961
|
}
|
|
6658
6962
|
function unionLiterals(body2) {
|
|
@@ -6696,7 +7000,7 @@ var no_union_in_comment_default = createRule({
|
|
|
6696
7000
|
if (after === null || after.loc.start.line !== comment.loc.end.line + 1) return null;
|
|
6697
7001
|
anchor = sourceCode.getNodeByRangeIndex(after.range[0]);
|
|
6698
7002
|
}
|
|
6699
|
-
for (let node = anchor; node != null && node.type !==
|
|
7003
|
+
for (let node = anchor; node != null && node.type !== import_utils43.AST_NODE_TYPES.Program; node = node.parent) {
|
|
6700
7004
|
const target = targetOf(node);
|
|
6701
7005
|
if (target !== null) return target;
|
|
6702
7006
|
}
|
|
@@ -6725,9 +7029,9 @@ var no_union_in_comment_default = createRule({
|
|
|
6725
7029
|
});
|
|
6726
7030
|
|
|
6727
7031
|
// src/rules/no-type-member-comment-wall.ts
|
|
6728
|
-
var
|
|
7032
|
+
var import_utils44 = require("@typescript-eslint/utils");
|
|
6729
7033
|
function isNamedMember(node) {
|
|
6730
|
-
return (node.type ===
|
|
7034
|
+
return (node.type === import_utils44.AST_NODE_TYPES.TSPropertySignature || node.type === import_utils44.AST_NODE_TYPES.TSMethodSignature) && !node.computed;
|
|
6731
7035
|
}
|
|
6732
7036
|
var no_type_member_comment_wall_default = createRule({
|
|
6733
7037
|
name: "no-type-member-comment-wall",
|
|
@@ -6774,7 +7078,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
6774
7078
|
return headsRun || lineAbove !== void 0 && lineAbove.trim().length === 0;
|
|
6775
7079
|
}
|
|
6776
7080
|
function check(node) {
|
|
6777
|
-
const members = node.type ===
|
|
7081
|
+
const members = node.type === import_utils44.AST_NODE_TYPES.TSInterfaceBody ? node.body : node.members;
|
|
6778
7082
|
const named2 = members.filter(isNamedMember);
|
|
6779
7083
|
if (named2.length === 0) return;
|
|
6780
7084
|
const documented = named2.map((member) => ({ member, comment: documentingComment(member) }));
|
|
@@ -6814,7 +7118,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
6814
7118
|
});
|
|
6815
7119
|
|
|
6816
7120
|
// src/rules/no-unnecessary-use-client.ts
|
|
6817
|
-
var
|
|
7121
|
+
var import_utils45 = require("@typescript-eslint/utils");
|
|
6818
7122
|
var HOOK_REGEX = /^use([A-Z]|$)/;
|
|
6819
7123
|
var EVENT_PROP_REGEX = /^on[A-Z]/;
|
|
6820
7124
|
var ERROR_FILE_REGEX = /\b(?:global-)?error\.[jt]sx?$/;
|
|
@@ -6840,13 +7144,13 @@ var CLIENT_ONLY_PACKAGES_REGEX = /^(?:@radix-ui\/|framer-motion|react-dom|react-
|
|
|
6840
7144
|
var isBareSpecifier = (source) => !source.startsWith(".") && !source.startsWith("/") && !source.startsWith("@/") && !source.startsWith("~");
|
|
6841
7145
|
var jsxRootName = (name) => {
|
|
6842
7146
|
let current = name;
|
|
6843
|
-
while (current.type ===
|
|
7147
|
+
while (current.type === import_utils45.AST_NODE_TYPES.JSXMemberExpression) {
|
|
6844
7148
|
current = current.object;
|
|
6845
7149
|
}
|
|
6846
|
-
return current.type ===
|
|
7150
|
+
return current.type === import_utils45.AST_NODE_TYPES.JSXIdentifier ? current.name : "";
|
|
6847
7151
|
};
|
|
6848
7152
|
var subtreeReadsImportedBinding = (node, imported) => {
|
|
6849
|
-
if (node.type ===
|
|
7153
|
+
if (node.type === import_utils45.AST_NODE_TYPES.Identifier) {
|
|
6850
7154
|
return imported.has(node.name);
|
|
6851
7155
|
}
|
|
6852
7156
|
for (const key of Object.keys(node)) {
|
|
@@ -6861,16 +7165,16 @@ var subtreeReadsImportedBinding = (node, imported) => {
|
|
|
6861
7165
|
return false;
|
|
6862
7166
|
};
|
|
6863
7167
|
var isUseClientDirective = (node) => {
|
|
6864
|
-
return node.type ===
|
|
7168
|
+
return node.type === import_utils45.AST_NODE_TYPES.ExpressionStatement && node.expression.type === import_utils45.AST_NODE_TYPES.Literal && node.expression.value === "use client";
|
|
6865
7169
|
};
|
|
6866
7170
|
var isGlobalReference = (node, context) => {
|
|
6867
7171
|
if (!BROWSER_GLOBALS.has(node.name)) return false;
|
|
6868
7172
|
const parent = node.parent;
|
|
6869
7173
|
if (parent !== void 0) {
|
|
6870
|
-
if (parent.type ===
|
|
7174
|
+
if (parent.type === import_utils45.AST_NODE_TYPES.MemberExpression && parent.property === node && !parent.computed) {
|
|
6871
7175
|
return false;
|
|
6872
7176
|
}
|
|
6873
|
-
if (parent.type ===
|
|
7177
|
+
if (parent.type === import_utils45.AST_NODE_TYPES.Property && parent.key === node && !parent.computed) {
|
|
6874
7178
|
return false;
|
|
6875
7179
|
}
|
|
6876
7180
|
if (parent.type.startsWith("TS")) {
|
|
@@ -6910,13 +7214,13 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
6910
7214
|
const importedLocals = /* @__PURE__ */ new Set();
|
|
6911
7215
|
const externalLocals = /* @__PURE__ */ new Set();
|
|
6912
7216
|
const markIfHookOrContext = (callee) => {
|
|
6913
|
-
if (callee.type ===
|
|
7217
|
+
if (callee.type === import_utils45.AST_NODE_TYPES.Identifier) {
|
|
6914
7218
|
if (HOOK_REGEX.test(callee.name) || callee.name === "createContext") {
|
|
6915
7219
|
hasClientIndicator = true;
|
|
6916
7220
|
}
|
|
6917
7221
|
return;
|
|
6918
7222
|
}
|
|
6919
|
-
if (callee.type ===
|
|
7223
|
+
if (callee.type === import_utils45.AST_NODE_TYPES.MemberExpression && callee.property.type === import_utils45.AST_NODE_TYPES.Identifier) {
|
|
6920
7224
|
const name = callee.property.name;
|
|
6921
7225
|
if (HOOK_REGEX.test(name) || name === "createContext") {
|
|
6922
7226
|
hasClientIndicator = true;
|
|
@@ -6926,7 +7230,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
6926
7230
|
return {
|
|
6927
7231
|
Program(node) {
|
|
6928
7232
|
for (const stmt of node.body) {
|
|
6929
|
-
if (stmt.type !==
|
|
7233
|
+
if (stmt.type !== import_utils45.AST_NODE_TYPES.ExpressionStatement) break;
|
|
6930
7234
|
if (isUseClientDirective(stmt)) {
|
|
6931
7235
|
directiveNode = stmt;
|
|
6932
7236
|
break;
|
|
@@ -6939,7 +7243,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
6939
7243
|
},
|
|
6940
7244
|
JSXAttribute(node) {
|
|
6941
7245
|
if (directiveNode === null) return;
|
|
6942
|
-
if (node.name.type ===
|
|
7246
|
+
if (node.name.type === import_utils45.AST_NODE_TYPES.JSXIdentifier && EVENT_PROP_REGEX.test(node.name.name)) {
|
|
6943
7247
|
hasClientIndicator = true;
|
|
6944
7248
|
}
|
|
6945
7249
|
},
|
|
@@ -7006,23 +7310,19 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
7006
7310
|
});
|
|
7007
7311
|
|
|
7008
7312
|
// src/rules/no-unsafe-mock-casting.ts
|
|
7009
|
-
var import_utils45 = require("@typescript-eslint/utils");
|
|
7010
7313
|
var import_utils46 = require("@typescript-eslint/utils");
|
|
7011
|
-
|
|
7012
|
-
|
|
7013
|
-
|
|
7014
|
-
|
|
7015
|
-
|
|
7016
|
-
|
|
7017
|
-
|
|
7018
|
-
|
|
7019
|
-
|
|
7020
|
-
|
|
7021
|
-
|
|
7022
|
-
|
|
7023
|
-
}
|
|
7024
|
-
return false;
|
|
7025
|
-
}
|
|
7314
|
+
var MOCK_TYPE_NAMES = /* @__PURE__ */ new Set([
|
|
7315
|
+
"Mock",
|
|
7316
|
+
"MockInstance",
|
|
7317
|
+
"SpyInstance"
|
|
7318
|
+
]);
|
|
7319
|
+
var MOCK_MODULES = /* @__PURE__ */ new Set([
|
|
7320
|
+
"vitest",
|
|
7321
|
+
"@vitest/spy",
|
|
7322
|
+
"jest",
|
|
7323
|
+
"jest-mock",
|
|
7324
|
+
"@jest/globals"
|
|
7325
|
+
]);
|
|
7026
7326
|
var no_unsafe_mock_casting_default = createRule({
|
|
7027
7327
|
name: "no-unsafe-mock-casting",
|
|
7028
7328
|
meta: {
|
|
@@ -7040,12 +7340,49 @@ var no_unsafe_mock_casting_default = createRule({
|
|
|
7040
7340
|
if (isGeneratedFile(context.filename, context.sourceCode.text)) {
|
|
7041
7341
|
return {};
|
|
7042
7342
|
}
|
|
7343
|
+
const directBindings = /* @__PURE__ */ new Set();
|
|
7344
|
+
const namespaceBindings = /* @__PURE__ */ new Set();
|
|
7345
|
+
function resolve(identifier) {
|
|
7346
|
+
return import_utils46.ASTUtils.findVariable(
|
|
7347
|
+
context.sourceCode.getScope(identifier),
|
|
7348
|
+
identifier.name
|
|
7349
|
+
);
|
|
7350
|
+
}
|
|
7351
|
+
function record(identifier, destination) {
|
|
7352
|
+
const binding = resolve(identifier);
|
|
7353
|
+
if (binding !== null) destination.add(binding);
|
|
7354
|
+
}
|
|
7355
|
+
function isMockTypeReference(node) {
|
|
7356
|
+
if (node.type !== import_utils46.AST_NODE_TYPES.TSTypeReference) return false;
|
|
7357
|
+
const typeName = node.typeName;
|
|
7358
|
+
if (typeName.type === import_utils46.AST_NODE_TYPES.Identifier) {
|
|
7359
|
+
const binding = resolve(typeName);
|
|
7360
|
+
return binding !== null && directBindings.has(binding);
|
|
7361
|
+
}
|
|
7362
|
+
if (typeName.type === import_utils46.AST_NODE_TYPES.TSQualifiedName && typeName.left.type === import_utils46.AST_NODE_TYPES.Identifier && MOCK_TYPE_NAMES.has(typeName.right.name)) {
|
|
7363
|
+
const binding = resolve(typeName.left);
|
|
7364
|
+
return binding !== null && namespaceBindings.has(binding);
|
|
7365
|
+
}
|
|
7366
|
+
return false;
|
|
7367
|
+
}
|
|
7043
7368
|
function checkAssertion(node) {
|
|
7044
7369
|
if (isMockTypeReference(node.typeAnnotation)) {
|
|
7045
7370
|
context.report({ node, messageId: "unsafeMockCast" });
|
|
7046
7371
|
}
|
|
7047
7372
|
}
|
|
7048
7373
|
return {
|
|
7374
|
+
ImportDeclaration(node) {
|
|
7375
|
+
if (!MOCK_MODULES.has(node.source.value)) return;
|
|
7376
|
+
for (const specifier of node.specifiers) {
|
|
7377
|
+
if (specifier.type === import_utils46.AST_NODE_TYPES.ImportNamespaceSpecifier) {
|
|
7378
|
+
record(specifier.local, namespaceBindings);
|
|
7379
|
+
} else if (specifier.type === import_utils46.AST_NODE_TYPES.ImportSpecifier && MOCK_TYPE_NAMES.has(
|
|
7380
|
+
specifier.imported.type === import_utils46.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value
|
|
7381
|
+
)) {
|
|
7382
|
+
record(specifier.local, directBindings);
|
|
7383
|
+
}
|
|
7384
|
+
}
|
|
7385
|
+
},
|
|
7049
7386
|
TSAsExpression: checkAssertion,
|
|
7050
7387
|
TSTypeAssertion: checkAssertion
|
|
7051
7388
|
};
|
|
@@ -7067,7 +7404,7 @@ function isIgnoredFile(filename, sourceText) {
|
|
|
7067
7404
|
}
|
|
7068
7405
|
return /@generated\b/.test(sourceText.slice(0, 1024));
|
|
7069
7406
|
}
|
|
7070
|
-
function
|
|
7407
|
+
function isZodModule2(source) {
|
|
7071
7408
|
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
7072
7409
|
}
|
|
7073
7410
|
function unwrap2(node) {
|
|
@@ -7152,9 +7489,10 @@ var no_zod_native_enum_default = createRule({
|
|
|
7152
7489
|
services = null;
|
|
7153
7490
|
}
|
|
7154
7491
|
const zodImportedNames = /* @__PURE__ */ new Map();
|
|
7492
|
+
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
7155
7493
|
function isZodMemberCall(node, api) {
|
|
7156
7494
|
const callee = node.callee;
|
|
7157
|
-
if (callee.type === import_utils47.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils47.AST_NODE_TYPES.Identifier) {
|
|
7495
|
+
if (callee.type === import_utils47.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.object.type === import_utils47.AST_NODE_TYPES.Identifier && zodNamespaces.has(callee.object.name) && callee.property.type === import_utils47.AST_NODE_TYPES.Identifier) {
|
|
7158
7496
|
return callee.property.name === api;
|
|
7159
7497
|
}
|
|
7160
7498
|
if (callee.type === import_utils47.AST_NODE_TYPES.Identifier) {
|
|
@@ -7188,10 +7526,13 @@ var no_zod_native_enum_default = createRule({
|
|
|
7188
7526
|
}
|
|
7189
7527
|
return {
|
|
7190
7528
|
ImportDeclaration(node) {
|
|
7191
|
-
if (!
|
|
7529
|
+
if (!isZodModule2(node.source.value)) {
|
|
7192
7530
|
return;
|
|
7193
7531
|
}
|
|
7194
7532
|
for (const spec of node.specifiers) {
|
|
7533
|
+
if (spec.type === import_utils47.AST_NODE_TYPES.ImportNamespaceSpecifier || spec.type === import_utils47.AST_NODE_TYPES.ImportDefaultSpecifier || spec.type === import_utils47.AST_NODE_TYPES.ImportSpecifier && (spec.imported.type === import_utils47.AST_NODE_TYPES.Identifier ? spec.imported.name === "z" : spec.imported.value === "z")) {
|
|
7534
|
+
zodNamespaces.add(spec.local.name);
|
|
7535
|
+
}
|
|
7195
7536
|
if (spec.type === import_utils47.AST_NODE_TYPES.ImportSpecifier && spec.imported.type === import_utils47.AST_NODE_TYPES.Identifier) {
|
|
7196
7537
|
zodImportedNames.set(spec.local.name, spec.imported.name);
|
|
7197
7538
|
}
|
|
@@ -7210,10 +7551,12 @@ var no_zod_native_enum_default = createRule({
|
|
|
7210
7551
|
if (!isZodMemberCall(node, "enum")) {
|
|
7211
7552
|
return;
|
|
7212
7553
|
}
|
|
7213
|
-
const
|
|
7214
|
-
if (
|
|
7554
|
+
const argument = node.arguments[0];
|
|
7555
|
+
if (argument === void 0 || argument.type === import_utils47.AST_NODE_TYPES.SpreadElement) {
|
|
7215
7556
|
return;
|
|
7216
7557
|
}
|
|
7558
|
+
const arg = unwrap2(argument);
|
|
7559
|
+
if (arg.type !== import_utils47.AST_NODE_TYPES.Identifier) return;
|
|
7217
7560
|
const isEnum = resolvesToLocalEnum(arg, sourceCode.getScope(arg)) || services !== null && resolvesToImportedEnum(arg, services);
|
|
7218
7561
|
if (isEnum) {
|
|
7219
7562
|
context.report({
|
|
@@ -7252,7 +7595,7 @@ function rootIdentifier3(callee) {
|
|
|
7252
7595
|
if (callee.type === import_utils48.AST_NODE_TYPES.TaggedTemplateExpression) return rootIdentifier3(callee.tag);
|
|
7253
7596
|
return null;
|
|
7254
7597
|
}
|
|
7255
|
-
function
|
|
7598
|
+
function staticMemberName3(member) {
|
|
7256
7599
|
if (!member.computed && member.property.type === import_utils48.AST_NODE_TYPES.Identifier) return member.property.name;
|
|
7257
7600
|
if (member.computed && member.property.type === import_utils48.AST_NODE_TYPES.Literal && typeof member.property.value === "string") {
|
|
7258
7601
|
return member.property.value;
|
|
@@ -7267,7 +7610,7 @@ function isTestBody3(node, isFrameworkTest) {
|
|
|
7267
7610
|
function isTestCaller(callee) {
|
|
7268
7611
|
if (callee.type === import_utils48.AST_NODE_TYPES.Identifier) return TEST_CALLERS4.has(callee.name);
|
|
7269
7612
|
if (callee.type !== import_utils48.AST_NODE_TYPES.MemberExpression) return false;
|
|
7270
|
-
const member =
|
|
7613
|
+
const member = staticMemberName3(callee);
|
|
7271
7614
|
return member !== null && TEST_MODIFIERS2.has(member) && isTestCaller(callee.object);
|
|
7272
7615
|
}
|
|
7273
7616
|
function nearestEnclosingFunction3(node) {
|
|
@@ -7348,7 +7691,7 @@ function opensSubtest(node, callbackParameters) {
|
|
|
7348
7691
|
return false;
|
|
7349
7692
|
}
|
|
7350
7693
|
const callee = node.callee;
|
|
7351
|
-
return callee.type === import_utils48.AST_NODE_TYPES.MemberExpression &&
|
|
7694
|
+
return callee.type === import_utils48.AST_NODE_TYPES.MemberExpression && staticMemberName3(callee) === "test" && callee.object.type === import_utils48.AST_NODE_TYPES.Identifier && callbackParameters.has(callee.object.name) && node.arguments.some(
|
|
7352
7695
|
(argument) => argument.type !== import_utils48.AST_NODE_TYPES.SpreadElement && FUNCTION_TYPES6.has(argument.type)
|
|
7353
7696
|
);
|
|
7354
7697
|
}
|
|
@@ -7648,9 +7991,9 @@ var import_utils52 = require("@typescript-eslint/utils");
|
|
|
7648
7991
|
var INPUT_MODULE = /(?:^|\/)components\/ui\/input$/u;
|
|
7649
7992
|
var INPUT_GROUP_MODULE = /(?:^|\/)components\/ui\/input-group$/u;
|
|
7650
7993
|
var MAX_JSX_DISTANCE = 2;
|
|
7651
|
-
function localNamedImports(node,
|
|
7994
|
+
function localNamedImports(node, importedName2) {
|
|
7652
7995
|
return node.specifiers.filter(
|
|
7653
|
-
(specifier) => specifier.type === import_utils52.AST_NODE_TYPES.ImportSpecifier && (specifier.imported.type === import_utils52.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value) ===
|
|
7996
|
+
(specifier) => specifier.type === import_utils52.AST_NODE_TYPES.ImportSpecifier && (specifier.imported.type === import_utils52.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value) === importedName2
|
|
7654
7997
|
).map((specifier) => specifier.local.name);
|
|
7655
7998
|
}
|
|
7656
7999
|
function elementName(node) {
|
|
@@ -8380,16 +8723,6 @@ var prefer_module_level_constant_default = createRule({
|
|
|
8380
8723
|
|
|
8381
8724
|
// src/rules/prefer-module-level-schema.ts
|
|
8382
8725
|
var import_utils56 = require("@typescript-eslint/utils");
|
|
8383
|
-
|
|
8384
|
-
// src/rules/_zod.ts
|
|
8385
|
-
var ZOD_PREFIX_RE = /^Z[A-Z]/;
|
|
8386
|
-
var ZOD_SUFFIX_RE = /Schema$/;
|
|
8387
|
-
var ZOD_SCHEMA_NAME_RE = /Schema$|^Z[A-Z]/;
|
|
8388
|
-
function isZodModule2(source) {
|
|
8389
|
-
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
8390
|
-
}
|
|
8391
|
-
|
|
8392
|
-
// src/rules/prefer-module-level-schema.ts
|
|
8393
8726
|
var DEFAULT_FACTORIES = [
|
|
8394
8727
|
"discriminatedUnion",
|
|
8395
8728
|
"intersection",
|
|
@@ -8554,6 +8887,11 @@ var prefer_module_level_schema_default = createRule({
|
|
|
8554
8887
|
type: "boolean",
|
|
8555
8888
|
description: "Skip test files, where a fixture schema belongs next to its assertion."
|
|
8556
8889
|
},
|
|
8890
|
+
memoCallees: {
|
|
8891
|
+
type: "array",
|
|
8892
|
+
items: { type: "string" },
|
|
8893
|
+
description: "Wrappers that construct their callback at most once. Defaults to lazy, memo, once, and useMemo."
|
|
8894
|
+
},
|
|
8557
8895
|
minProperties: {
|
|
8558
8896
|
type: "number",
|
|
8559
8897
|
minimum: 0,
|
|
@@ -8571,6 +8909,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
8571
8909
|
create(context, [options]) {
|
|
8572
8910
|
const factories = new Set(options?.factories ?? DEFAULT_FACTORIES);
|
|
8573
8911
|
const ignoreTestFiles = options?.ignoreTestFiles ?? true;
|
|
8912
|
+
const memoCallees = new Set(options?.memoCallees ?? MEMO_CALLEES);
|
|
8574
8913
|
const minProperties = options?.minProperties ?? DEFAULT_MIN_PROPERTIES;
|
|
8575
8914
|
const sourceCode = context.sourceCode;
|
|
8576
8915
|
const filename = context.filename;
|
|
@@ -8590,7 +8929,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
8590
8929
|
if (current !== node && isZodCall(current) && current.callee.type === import_utils56.AST_NODE_TYPES.MemberExpression && current.callee.property.type === import_utils56.AST_NODE_TYPES.Identifier && factories.has(current.callee.property.name)) {
|
|
8591
8930
|
return true;
|
|
8592
8931
|
}
|
|
8593
|
-
if (current.type === import_utils56.AST_NODE_TYPES.CallExpression && (current.callee.type === import_utils56.AST_NODE_TYPES.Identifier &&
|
|
8932
|
+
if (current.type === import_utils56.AST_NODE_TYPES.CallExpression && (current.callee.type === import_utils56.AST_NODE_TYPES.Identifier && memoCallees.has(current.callee.name) || current.callee.type === import_utils56.AST_NODE_TYPES.MemberExpression && !current.callee.computed && current.callee.property.type === import_utils56.AST_NODE_TYPES.Identifier && memoCallees.has(current.callee.property.name))) {
|
|
8594
8933
|
return true;
|
|
8595
8934
|
}
|
|
8596
8935
|
current = current.parent ?? void 0;
|
|
@@ -8640,6 +8979,9 @@ var prefer_module_level_schema_default = createRule({
|
|
|
8640
8979
|
if (definition.type === "ImportBinding") {
|
|
8641
8980
|
continue;
|
|
8642
8981
|
}
|
|
8982
|
+
if (definition.node.type === import_utils56.AST_NODE_TYPES.VariableDeclarator && definition.node.parent.type === import_utils56.AST_NODE_TYPES.VariableDeclaration && definition.node.parent.kind !== "const") {
|
|
8983
|
+
return false;
|
|
8984
|
+
}
|
|
8643
8985
|
const [defStart, defEnd] = definition.node.range;
|
|
8644
8986
|
if (defStart >= schemaStart && defEnd <= schemaEnd) {
|
|
8645
8987
|
continue;
|
|
@@ -8666,7 +9008,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
8666
9008
|
}
|
|
8667
9009
|
return {
|
|
8668
9010
|
ImportDeclaration(node) {
|
|
8669
|
-
if (!
|
|
9011
|
+
if (!isZodModule(node.source.value)) {
|
|
8670
9012
|
return;
|
|
8671
9013
|
}
|
|
8672
9014
|
for (const specifier of node.specifiers) {
|
|
@@ -8874,7 +9216,7 @@ function sameAccess(node, access) {
|
|
|
8874
9216
|
return node.type === import_utils58.AST_NODE_TYPES.MemberExpression && !node.computed && node.object.type === import_utils58.AST_NODE_TYPES.Identifier && node.object.name === access.object && node.property.type === import_utils58.AST_NODE_TYPES.Identifier && node.property.name === access.property;
|
|
8875
9217
|
}
|
|
8876
9218
|
function isNullGuard(node, access) {
|
|
8877
|
-
if (node.type === import_utils58.AST_NODE_TYPES.UnaryExpression && node.operator === "!" && sameAccess(node.argument, access)) return true;
|
|
9219
|
+
if (node.type === import_utils58.AST_NODE_TYPES.UnaryExpression && node.operator === "!" && (sameAccess(node.argument, access) || optionalMemberLengthOf(node.argument, access))) return true;
|
|
8878
9220
|
if (node.type !== import_utils58.AST_NODE_TYPES.BinaryExpression || !["==", "==="].includes(node.operator)) {
|
|
8879
9221
|
return false;
|
|
8880
9222
|
}
|
|
@@ -8890,7 +9232,11 @@ function isEmptyGuard(node, access) {
|
|
|
8890
9232
|
return memberLengthOf(node.left, access) && zero(node.right) || memberLengthOf(node.right, access) && zero(node.left);
|
|
8891
9233
|
}
|
|
8892
9234
|
function memberLengthOf(node, access) {
|
|
8893
|
-
|
|
9235
|
+
const target = node.type === import_utils58.AST_NODE_TYPES.ChainExpression ? node.expression : node;
|
|
9236
|
+
return target.type === import_utils58.AST_NODE_TYPES.MemberExpression && !target.computed && target.property.type === import_utils58.AST_NODE_TYPES.Identifier && target.property.name === "length" && sameAccess(target.object, access);
|
|
9237
|
+
}
|
|
9238
|
+
function optionalMemberLengthOf(node, access) {
|
|
9239
|
+
return node.type === import_utils58.AST_NODE_TYPES.ChainExpression && node.expression.type === import_utils58.AST_NODE_TYPES.MemberExpression && node.expression.optional && memberLengthOf(node, access);
|
|
8894
9240
|
}
|
|
8895
9241
|
function hasEquivalentLeadingGuard(fn, access, visitorKeys) {
|
|
8896
9242
|
if (fn.body.type !== import_utils58.AST_NODE_TYPES.BlockStatement) return false;
|
|
@@ -8898,6 +9244,7 @@ function hasEquivalentLeadingGuard(fn, access, visitorKeys) {
|
|
|
8898
9244
|
if (first?.type !== import_utils58.AST_NODE_TYPES.IfStatement) return false;
|
|
8899
9245
|
const terminating = first.consequent.type === import_utils58.AST_NODE_TYPES.ReturnStatement || first.consequent.type === import_utils58.AST_NODE_TYPES.ThrowStatement || first.consequent.type === import_utils58.AST_NODE_TYPES.BlockStatement && first.consequent.body.length === 1 && (first.consequent.body[0]?.type === import_utils58.AST_NODE_TYPES.ReturnStatement || first.consequent.body[0]?.type === import_utils58.AST_NODE_TYPES.ThrowStatement);
|
|
8900
9246
|
if (!terminating) return false;
|
|
9247
|
+
if (contains(first.consequent, visitorKeys, (node) => sameAccess(node, access))) return false;
|
|
8901
9248
|
return contains(first.test, visitorKeys, (node) => isNullGuard(node, access)) && contains(first.test, visitorKeys, (node) => isEmptyGuard(node, access));
|
|
8902
9249
|
}
|
|
8903
9250
|
function contains(node, visitorKeys, predicate) {
|
|
@@ -9977,13 +10324,13 @@ function getPropertyNode(objNode, propName2) {
|
|
|
9977
10324
|
if (!objNode || objNode.type !== "ObjectExpression") return null;
|
|
9978
10325
|
for (const prop of objNode.properties) {
|
|
9979
10326
|
if (prop.type !== "Property") continue;
|
|
9980
|
-
let
|
|
10327
|
+
let keyName = null;
|
|
9981
10328
|
if (prop.key.type === "Identifier" && !prop.computed) {
|
|
9982
|
-
|
|
10329
|
+
keyName = prop.key.name;
|
|
9983
10330
|
} else if (prop.key.type === "Literal" && typeof prop.key.value === "string") {
|
|
9984
|
-
|
|
10331
|
+
keyName = prop.key.value;
|
|
9985
10332
|
}
|
|
9986
|
-
if (
|
|
10333
|
+
if (keyName === propName2) {
|
|
9987
10334
|
if (prop.value.type === "AssignmentPattern" || prop.value.type === "ArrayPattern" || prop.value.type === "ObjectPattern") {
|
|
9988
10335
|
return null;
|
|
9989
10336
|
}
|
|
@@ -10061,370 +10408,8 @@ var prefer_server_actions_default = createRule({
|
|
|
10061
10408
|
}
|
|
10062
10409
|
});
|
|
10063
10410
|
|
|
10064
|
-
// src/rules/prefer-
|
|
10411
|
+
// src/rules/prefer-whole-object-assertion.ts
|
|
10065
10412
|
var import_utils62 = require("@typescript-eslint/utils");
|
|
10066
|
-
var ts2 = __toESM(require("typescript"), 1);
|
|
10067
|
-
var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
10068
|
-
"status",
|
|
10069
|
-
"state",
|
|
10070
|
-
"kind",
|
|
10071
|
-
"role",
|
|
10072
|
-
"priority",
|
|
10073
|
-
"severity",
|
|
10074
|
-
"direction",
|
|
10075
|
-
"tier",
|
|
10076
|
-
"stage",
|
|
10077
|
-
"type",
|
|
10078
|
-
"mode",
|
|
10079
|
-
"level"
|
|
10080
|
-
]);
|
|
10081
|
-
var LOWER_TOKEN_RE = /^[a-z][a-z0-9_-]{0,30}$/;
|
|
10082
|
-
var MIN_CLUSTER_SIZE = 2;
|
|
10083
|
-
var BOOLEANISH = /* @__PURE__ */ new Set(["true", "false"]);
|
|
10084
|
-
function isEnumToken(lit) {
|
|
10085
|
-
return LOWER_TOKEN_RE.test(lit) && lit.length >= 2 && !BOOLEANISH.has(lit);
|
|
10086
|
-
}
|
|
10087
|
-
var IGNORE_PATTERNS3 = [
|
|
10088
|
-
/[\\/]generated[\\/]/,
|
|
10089
|
-
/\.gen\.tsx?$/,
|
|
10090
|
-
/\.generated\.tsx?$/,
|
|
10091
|
-
/\.d\.ts$/
|
|
10092
|
-
];
|
|
10093
|
-
function isIgnoredFile3(filename, sourceText) {
|
|
10094
|
-
if (IGNORE_PATTERNS3.some((re) => re.test(filename))) {
|
|
10095
|
-
return true;
|
|
10096
|
-
}
|
|
10097
|
-
return /@generated\b/.test(sourceText.slice(0, 1024));
|
|
10098
|
-
}
|
|
10099
|
-
function isChoiceLikeName(name) {
|
|
10100
|
-
return CHOICE_TOKENS.has(lastWord(name));
|
|
10101
|
-
}
|
|
10102
|
-
function lastWord(name) {
|
|
10103
|
-
const words = name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").split(/[_\s]+/).filter((w) => w.length > 0);
|
|
10104
|
-
const last = words[words.length - 1] ?? name;
|
|
10105
|
-
return last.toLowerCase();
|
|
10106
|
-
}
|
|
10107
|
-
function keyName(key) {
|
|
10108
|
-
if (key.type === import_utils62.AST_NODE_TYPES.Identifier) {
|
|
10109
|
-
return key.name;
|
|
10110
|
-
}
|
|
10111
|
-
if (key.type === import_utils62.AST_NODE_TYPES.Literal && typeof key.value === "string") {
|
|
10112
|
-
return key.value;
|
|
10113
|
-
}
|
|
10114
|
-
return null;
|
|
10115
|
-
}
|
|
10116
|
-
function isStringLiteralMember(t) {
|
|
10117
|
-
return t.type === import_utils62.AST_NODE_TYPES.TSLiteralType && t.literal.type === import_utils62.AST_NODE_TYPES.Literal && typeof t.literal.value === "string";
|
|
10118
|
-
}
|
|
10119
|
-
function isStringLiteralUnion(node) {
|
|
10120
|
-
if (node?.type !== import_utils62.AST_NODE_TYPES.TSUnionType) {
|
|
10121
|
-
return false;
|
|
10122
|
-
}
|
|
10123
|
-
return node.types.filter(isStringLiteralMember).length >= MIN_CLUSTER_SIZE;
|
|
10124
|
-
}
|
|
10125
|
-
function typeHasRawString(type) {
|
|
10126
|
-
const parts = type.isUnion() ? type.types : [type];
|
|
10127
|
-
return parts.some((t) => (t.flags & ts2.TypeFlags.String) !== 0);
|
|
10128
|
-
}
|
|
10129
|
-
function isExternalSourceFile(sf) {
|
|
10130
|
-
if (sf === void 0) {
|
|
10131
|
-
return false;
|
|
10132
|
-
}
|
|
10133
|
-
return sf.isDeclarationFile || sf.fileName.includes("/node_modules/");
|
|
10134
|
-
}
|
|
10135
|
-
function symbolIsExternallyDeclared(sym) {
|
|
10136
|
-
return sym?.declarations?.some((d) => isExternalSourceFile(d.getSourceFile())) ?? false;
|
|
10137
|
-
}
|
|
10138
|
-
function bindingSourceExpression(decl) {
|
|
10139
|
-
let node = decl.parent;
|
|
10140
|
-
while (!ts2.isForOfStatement(node) && !(ts2.isVariableDeclaration(node) && node.initializer !== void 0)) {
|
|
10141
|
-
if (node.parent === void 0) {
|
|
10142
|
-
return void 0;
|
|
10143
|
-
}
|
|
10144
|
-
node = node.parent;
|
|
10145
|
-
}
|
|
10146
|
-
return ts2.isForOfStatement(node) ? node.expression : node.initializer;
|
|
10147
|
-
}
|
|
10148
|
-
function refKey(node) {
|
|
10149
|
-
if (node.type === import_utils62.AST_NODE_TYPES.Identifier) {
|
|
10150
|
-
return node.name;
|
|
10151
|
-
}
|
|
10152
|
-
if (node.type === import_utils62.AST_NODE_TYPES.MemberExpression && !node.computed) {
|
|
10153
|
-
const inner = refKey(node.object);
|
|
10154
|
-
if (inner === null || node.property.type !== import_utils62.AST_NODE_TYPES.Identifier) {
|
|
10155
|
-
return null;
|
|
10156
|
-
}
|
|
10157
|
-
return `${inner}.${node.property.name}`;
|
|
10158
|
-
}
|
|
10159
|
-
return null;
|
|
10160
|
-
}
|
|
10161
|
-
function strLiteral(node) {
|
|
10162
|
-
if (node.type === import_utils62.AST_NODE_TYPES.Literal && typeof node.value === "string") {
|
|
10163
|
-
return node.value;
|
|
10164
|
-
}
|
|
10165
|
-
return null;
|
|
10166
|
-
}
|
|
10167
|
-
var prefer_string_literal_union_default = createRule({
|
|
10168
|
-
name: "prefer-string-literal-union",
|
|
10169
|
-
meta: {
|
|
10170
|
-
type: "suggestion",
|
|
10171
|
-
docs: {
|
|
10172
|
-
description: "Flag raw `string` choice fields and string-literal comparison clusters; prefer a string-literal union type."
|
|
10173
|
-
},
|
|
10174
|
-
schema: [
|
|
10175
|
-
{
|
|
10176
|
-
type: "object",
|
|
10177
|
-
additionalProperties: false,
|
|
10178
|
-
properties: {
|
|
10179
|
-
ignoreFields: {
|
|
10180
|
-
type: "array",
|
|
10181
|
-
items: { type: "string" }
|
|
10182
|
-
}
|
|
10183
|
-
}
|
|
10184
|
-
}
|
|
10185
|
-
],
|
|
10186
|
-
messages: {
|
|
10187
|
-
bareChoiceField: '`{{name}}: string` looks like a choice field \u2014 prefer a string-literal union type (e.g. `type X = "a" | "b"`). Enums are banned by `no-enum`; use a union.',
|
|
10188
|
-
comparisonCluster: '`{{key}}` is compared against a closed set of string literals \u2014 define a string-literal union type (e.g. `type X = "a" | "b"`).'
|
|
10189
|
-
}
|
|
10190
|
-
},
|
|
10191
|
-
defaultOptions: [{}],
|
|
10192
|
-
create(context, [optionsArg]) {
|
|
10193
|
-
const filename = context.filename;
|
|
10194
|
-
const sourceText = context.sourceCode.getText();
|
|
10195
|
-
if (isIgnoredFile3(filename, sourceText)) {
|
|
10196
|
-
return {};
|
|
10197
|
-
}
|
|
10198
|
-
const ignoredFields = new Set(
|
|
10199
|
-
(optionsArg?.ignoreFields ?? []).map((name) => name.toLowerCase())
|
|
10200
|
-
);
|
|
10201
|
-
let services;
|
|
10202
|
-
try {
|
|
10203
|
-
services = import_utils62.ESLintUtils.getParserServices(context);
|
|
10204
|
-
} catch {
|
|
10205
|
-
services = null;
|
|
10206
|
-
}
|
|
10207
|
-
const scopeStack = [];
|
|
10208
|
-
const validClusters = [];
|
|
10209
|
-
const bareChoiceProps = [];
|
|
10210
|
-
const containersWithUnion = /* @__PURE__ */ new Set();
|
|
10211
|
-
function operandIsRawString(node) {
|
|
10212
|
-
if (services === null) {
|
|
10213
|
-
return false;
|
|
10214
|
-
}
|
|
10215
|
-
return typeHasRawString(services.getTypeAtLocation(node));
|
|
10216
|
-
}
|
|
10217
|
-
function parameterRoot(node) {
|
|
10218
|
-
if (services === null) return false;
|
|
10219
|
-
const checker = services.program.getTypeChecker();
|
|
10220
|
-
let current = services.esTreeNodeToTSNodeMap.get(node);
|
|
10221
|
-
while (ts2.isPropertyAccessExpression(current)) current = current.expression;
|
|
10222
|
-
if (!ts2.isIdentifier(current)) return false;
|
|
10223
|
-
let declaration = checker.getSymbolAtLocation(current)?.valueDeclaration;
|
|
10224
|
-
while (declaration !== void 0 && (ts2.isBindingElement(declaration) || ts2.isObjectBindingPattern(declaration) || ts2.isArrayBindingPattern(declaration))) {
|
|
10225
|
-
declaration = declaration.parent;
|
|
10226
|
-
}
|
|
10227
|
-
return declaration !== void 0 && ts2.isParameter(declaration);
|
|
10228
|
-
}
|
|
10229
|
-
function originIsExternal(node, depth) {
|
|
10230
|
-
if (node === void 0 || services === null || depth > 6) {
|
|
10231
|
-
return false;
|
|
10232
|
-
}
|
|
10233
|
-
const checker = services.program.getTypeChecker();
|
|
10234
|
-
if (ts2.isParenthesizedExpression(node) || ts2.isNonNullExpression(node) || ts2.isAsExpression(node)) {
|
|
10235
|
-
return originIsExternal(node.expression, depth + 1);
|
|
10236
|
-
}
|
|
10237
|
-
if (ts2.isPropertyAccessExpression(node)) {
|
|
10238
|
-
return symbolIsExternallyDeclared(checker.getSymbolAtLocation(node.name));
|
|
10239
|
-
}
|
|
10240
|
-
if (ts2.isCallExpression(node)) {
|
|
10241
|
-
return originIsExternal(node.expression, depth + 1);
|
|
10242
|
-
}
|
|
10243
|
-
if (ts2.isIdentifier(node)) {
|
|
10244
|
-
const decl = checker.getSymbolAtLocation(node)?.valueDeclaration;
|
|
10245
|
-
if (decl === void 0) {
|
|
10246
|
-
return false;
|
|
10247
|
-
}
|
|
10248
|
-
if (ts2.isVariableDeclaration(decl) && decl.initializer !== void 0) {
|
|
10249
|
-
return originIsExternal(decl.initializer, depth + 1);
|
|
10250
|
-
}
|
|
10251
|
-
if (ts2.isBindingElement(decl)) {
|
|
10252
|
-
return originIsExternal(bindingSourceExpression(decl), depth + 1);
|
|
10253
|
-
}
|
|
10254
|
-
}
|
|
10255
|
-
return false;
|
|
10256
|
-
}
|
|
10257
|
-
function operandIsFlaggable(node) {
|
|
10258
|
-
return operandIsRawString(node) && parameterRoot(node) && !originIsExternal(services?.esTreeNodeToTSNodeMap.get(node), 0);
|
|
10259
|
-
}
|
|
10260
|
-
function declaredReturnLiterals(fn) {
|
|
10261
|
-
const annotation = fn.returnType?.typeAnnotation;
|
|
10262
|
-
if (annotation === void 0 || services === null) {
|
|
10263
|
-
return null;
|
|
10264
|
-
}
|
|
10265
|
-
const tsNode = services.esTreeNodeToTSNodeMap.get(annotation);
|
|
10266
|
-
if (!ts2.isTypeNode(tsNode)) {
|
|
10267
|
-
return null;
|
|
10268
|
-
}
|
|
10269
|
-
const checker = services.program.getTypeChecker();
|
|
10270
|
-
const declared = checker.getTypeFromTypeNode(tsNode);
|
|
10271
|
-
const type = checker.getAwaitedType(declared) ?? declared;
|
|
10272
|
-
const literals = /* @__PURE__ */ new Set();
|
|
10273
|
-
for (const part of type.isUnion() ? type.types : [type]) {
|
|
10274
|
-
if (part.isStringLiteral()) {
|
|
10275
|
-
literals.add(part.value);
|
|
10276
|
-
}
|
|
10277
|
-
}
|
|
10278
|
-
return literals.size >= MIN_CLUSTER_SIZE ? literals : null;
|
|
10279
|
-
}
|
|
10280
|
-
function pushScope(node) {
|
|
10281
|
-
scopeStack.push({ clusters: /* @__PURE__ */ new Map(), fn: node });
|
|
10282
|
-
}
|
|
10283
|
-
function popScope() {
|
|
10284
|
-
const scope = scopeStack.pop();
|
|
10285
|
-
if (scope === void 0) {
|
|
10286
|
-
return;
|
|
10287
|
-
}
|
|
10288
|
-
const candidates = [...scope.clusters.values()].filter(
|
|
10289
|
-
(entry) => entry.allTokens && entry.literals.size >= MIN_CLUSTER_SIZE
|
|
10290
|
-
);
|
|
10291
|
-
if (candidates.length === 0) {
|
|
10292
|
-
return;
|
|
10293
|
-
}
|
|
10294
|
-
const returnLiterals = scope.fn === null ? null : declaredReturnLiterals(scope.fn);
|
|
10295
|
-
for (const entry of candidates) {
|
|
10296
|
-
if (returnLiterals !== null && [...entry.literals].every((lit) => returnLiterals.has(lit))) {
|
|
10297
|
-
continue;
|
|
10298
|
-
}
|
|
10299
|
-
validClusters.push(entry.node);
|
|
10300
|
-
}
|
|
10301
|
-
}
|
|
10302
|
-
function accumulate(key, literals, node) {
|
|
10303
|
-
const scope = scopeStack[scopeStack.length - 1];
|
|
10304
|
-
if (scope === void 0) {
|
|
10305
|
-
return;
|
|
10306
|
-
}
|
|
10307
|
-
const allTokens = literals.every((lit) => isEnumToken(lit));
|
|
10308
|
-
const existing = scope.clusters.get(key);
|
|
10309
|
-
if (existing === void 0) {
|
|
10310
|
-
scope.clusters.set(key, {
|
|
10311
|
-
node,
|
|
10312
|
-
literals: new Set(literals),
|
|
10313
|
-
allTokens
|
|
10314
|
-
});
|
|
10315
|
-
return;
|
|
10316
|
-
}
|
|
10317
|
-
for (const lit of literals) {
|
|
10318
|
-
existing.literals.add(lit);
|
|
10319
|
-
}
|
|
10320
|
-
existing.allTokens = existing.allTokens && allTokens;
|
|
10321
|
-
}
|
|
10322
|
-
function collectProperty(key, typeNode, container, node) {
|
|
10323
|
-
if (isStringLiteralUnion(typeNode)) {
|
|
10324
|
-
containersWithUnion.add(container);
|
|
10325
|
-
return;
|
|
10326
|
-
}
|
|
10327
|
-
if (typeNode?.type !== import_utils62.AST_NODE_TYPES.TSStringKeyword) {
|
|
10328
|
-
return;
|
|
10329
|
-
}
|
|
10330
|
-
const name = keyName(key);
|
|
10331
|
-
if (name === null || !isChoiceLikeName(name) || ignoredFields.has(name.toLowerCase())) {
|
|
10332
|
-
return;
|
|
10333
|
-
}
|
|
10334
|
-
bareChoiceProps.push({ name, container, node });
|
|
10335
|
-
}
|
|
10336
|
-
return {
|
|
10337
|
-
FunctionDeclaration: pushScope,
|
|
10338
|
-
"FunctionDeclaration:exit": popScope,
|
|
10339
|
-
FunctionExpression: pushScope,
|
|
10340
|
-
"FunctionExpression:exit": popScope,
|
|
10341
|
-
ArrowFunctionExpression: pushScope,
|
|
10342
|
-
"ArrowFunctionExpression:exit": popScope,
|
|
10343
|
-
BinaryExpression(node) {
|
|
10344
|
-
if (node.operator !== "===" && node.operator !== "!==" && node.operator !== "==" && node.operator !== "!=") {
|
|
10345
|
-
return;
|
|
10346
|
-
}
|
|
10347
|
-
const leftKey = refKey(node.left);
|
|
10348
|
-
const rightLit = strLiteral(node.right);
|
|
10349
|
-
const rightKey = refKey(node.right);
|
|
10350
|
-
const leftLit = strLiteral(node.left);
|
|
10351
|
-
if (leftKey !== null && rightLit !== null) {
|
|
10352
|
-
if (operandIsFlaggable(node.left)) {
|
|
10353
|
-
accumulate(leftKey, [rightLit], node);
|
|
10354
|
-
}
|
|
10355
|
-
} else if (rightKey !== null && leftLit !== null) {
|
|
10356
|
-
if (operandIsFlaggable(node.right)) {
|
|
10357
|
-
accumulate(rightKey, [leftLit], node);
|
|
10358
|
-
}
|
|
10359
|
-
}
|
|
10360
|
-
},
|
|
10361
|
-
SwitchStatement(node) {
|
|
10362
|
-
const key = refKey(node.discriminant);
|
|
10363
|
-
if (key === null || !operandIsFlaggable(node.discriminant)) {
|
|
10364
|
-
return;
|
|
10365
|
-
}
|
|
10366
|
-
const literals = [];
|
|
10367
|
-
for (const c of node.cases) {
|
|
10368
|
-
if (c.test !== null) {
|
|
10369
|
-
const lit = strLiteral(c.test);
|
|
10370
|
-
if (lit !== null) {
|
|
10371
|
-
literals.push(lit);
|
|
10372
|
-
}
|
|
10373
|
-
}
|
|
10374
|
-
}
|
|
10375
|
-
if (literals.length > 0) {
|
|
10376
|
-
accumulate(key, literals, node);
|
|
10377
|
-
}
|
|
10378
|
-
},
|
|
10379
|
-
TSPropertySignature(node) {
|
|
10380
|
-
collectProperty(
|
|
10381
|
-
node.key,
|
|
10382
|
-
node.typeAnnotation?.typeAnnotation,
|
|
10383
|
-
node.parent,
|
|
10384
|
-
node
|
|
10385
|
-
);
|
|
10386
|
-
},
|
|
10387
|
-
PropertyDefinition(node) {
|
|
10388
|
-
collectProperty(
|
|
10389
|
-
node.key,
|
|
10390
|
-
node.typeAnnotation?.typeAnnotation,
|
|
10391
|
-
node.parent,
|
|
10392
|
-
node
|
|
10393
|
-
);
|
|
10394
|
-
},
|
|
10395
|
-
"Program:exit"() {
|
|
10396
|
-
for (const clusterNode of validClusters) {
|
|
10397
|
-
context.report({
|
|
10398
|
-
node: clusterNode,
|
|
10399
|
-
messageId: "comparisonCluster",
|
|
10400
|
-
data: { key: refKeyText(clusterNode) }
|
|
10401
|
-
});
|
|
10402
|
-
}
|
|
10403
|
-
for (const prop of bareChoiceProps) {
|
|
10404
|
-
if (containersWithUnion.has(prop.container)) {
|
|
10405
|
-
context.report({
|
|
10406
|
-
node: prop.node,
|
|
10407
|
-
messageId: "bareChoiceField",
|
|
10408
|
-
data: { name: prop.name }
|
|
10409
|
-
});
|
|
10410
|
-
}
|
|
10411
|
-
}
|
|
10412
|
-
}
|
|
10413
|
-
};
|
|
10414
|
-
function refKeyText(node) {
|
|
10415
|
-
if (node.type === import_utils62.AST_NODE_TYPES.BinaryExpression) {
|
|
10416
|
-
return refKey(node.left) ?? refKey(node.right) ?? "value";
|
|
10417
|
-
}
|
|
10418
|
-
if (node.type === import_utils62.AST_NODE_TYPES.SwitchStatement) {
|
|
10419
|
-
return refKey(node.discriminant) ?? "value";
|
|
10420
|
-
}
|
|
10421
|
-
return "value";
|
|
10422
|
-
}
|
|
10423
|
-
}
|
|
10424
|
-
});
|
|
10425
|
-
|
|
10426
|
-
// src/rules/prefer-whole-object-assertion.ts
|
|
10427
|
-
var import_utils63 = require("@typescript-eslint/utils");
|
|
10428
10413
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
10429
10414
|
var ARRAY_MATCHERS = /* @__PURE__ */ new Set(["toEqual", "toStrictEqual"]);
|
|
10430
10415
|
var COLLECTION_PROPERTIES = /* @__PURE__ */ new Set(["length", "size"]);
|
|
@@ -10433,11 +10418,11 @@ var NUMERIC_SIGNS2 = /* @__PURE__ */ new Set(["-", "+"]);
|
|
|
10433
10418
|
var MIN_RUN_LENGTH = 2;
|
|
10434
10419
|
function literalText(node, getText) {
|
|
10435
10420
|
switch (node.type) {
|
|
10436
|
-
case
|
|
10421
|
+
case import_utils62.AST_NODE_TYPES.Literal:
|
|
10437
10422
|
return "regex" in node ? null : getText(node);
|
|
10438
|
-
case
|
|
10423
|
+
case import_utils62.AST_NODE_TYPES.TemplateLiteral:
|
|
10439
10424
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
10440
|
-
case
|
|
10425
|
+
case import_utils62.AST_NODE_TYPES.UnaryExpression:
|
|
10441
10426
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
10442
10427
|
default:
|
|
10443
10428
|
return null;
|
|
@@ -10445,15 +10430,15 @@ function literalText(node, getText) {
|
|
|
10445
10430
|
}
|
|
10446
10431
|
function isPureReceiver(node) {
|
|
10447
10432
|
switch (node.type) {
|
|
10448
|
-
case
|
|
10449
|
-
case
|
|
10433
|
+
case import_utils62.AST_NODE_TYPES.Identifier:
|
|
10434
|
+
case import_utils62.AST_NODE_TYPES.ThisExpression:
|
|
10450
10435
|
return true;
|
|
10451
|
-
case
|
|
10436
|
+
case import_utils62.AST_NODE_TYPES.MemberExpression:
|
|
10452
10437
|
if (node.optional) {
|
|
10453
10438
|
return false;
|
|
10454
10439
|
}
|
|
10455
10440
|
if (node.computed) {
|
|
10456
|
-
return node.property.type ===
|
|
10441
|
+
return node.property.type === import_utils62.AST_NODE_TYPES.Literal && isPureReceiver(node.object);
|
|
10457
10442
|
}
|
|
10458
10443
|
return isPureReceiver(node.object);
|
|
10459
10444
|
default:
|
|
@@ -10461,7 +10446,7 @@ function isPureReceiver(node) {
|
|
|
10461
10446
|
}
|
|
10462
10447
|
}
|
|
10463
10448
|
function literalIndex(node) {
|
|
10464
|
-
if (node.type !==
|
|
10449
|
+
if (node.type !== import_utils62.AST_NODE_TYPES.Literal || typeof node.value !== "number") {
|
|
10465
10450
|
return null;
|
|
10466
10451
|
}
|
|
10467
10452
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
@@ -10487,24 +10472,24 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
10487
10472
|
}
|
|
10488
10473
|
const { sourceCode } = context;
|
|
10489
10474
|
function parseAssertion(statement) {
|
|
10490
|
-
if (statement.type !==
|
|
10475
|
+
if (statement.type !== import_utils62.AST_NODE_TYPES.ExpressionStatement) {
|
|
10491
10476
|
return null;
|
|
10492
10477
|
}
|
|
10493
10478
|
const call = statement.expression;
|
|
10494
|
-
if (call.type !==
|
|
10479
|
+
if (call.type !== import_utils62.AST_NODE_TYPES.CallExpression) {
|
|
10495
10480
|
return null;
|
|
10496
10481
|
}
|
|
10497
10482
|
const callee = call.callee;
|
|
10498
|
-
if (callee.type !==
|
|
10483
|
+
if (callee.type !== import_utils62.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils62.AST_NODE_TYPES.Identifier) {
|
|
10499
10484
|
return null;
|
|
10500
10485
|
}
|
|
10501
10486
|
const matcher = callee.property.name;
|
|
10502
10487
|
const expectCall = callee.object;
|
|
10503
|
-
if (expectCall.type !==
|
|
10488
|
+
if (expectCall.type !== import_utils62.AST_NODE_TYPES.CallExpression || expectCall.callee.type !== import_utils62.AST_NODE_TYPES.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
10504
10489
|
return null;
|
|
10505
10490
|
}
|
|
10506
10491
|
const actual = expectCall.arguments[0];
|
|
10507
|
-
if (actual === void 0 || actual.type !==
|
|
10492
|
+
if (actual === void 0 || actual.type !== import_utils62.AST_NODE_TYPES.MemberExpression || actual.optional) {
|
|
10508
10493
|
return null;
|
|
10509
10494
|
}
|
|
10510
10495
|
if (!isPureReceiver(actual.object)) {
|
|
@@ -10518,7 +10503,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
10518
10503
|
}
|
|
10519
10504
|
key = { kind: "index", index };
|
|
10520
10505
|
} else {
|
|
10521
|
-
if (actual.property.type !==
|
|
10506
|
+
if (actual.property.type !== import_utils62.AST_NODE_TYPES.Identifier || COLLECTION_PROPERTIES.has(actual.property.name) || LITERAL_KEY_HAZARDS.has(actual.property.name)) {
|
|
10522
10507
|
return null;
|
|
10523
10508
|
}
|
|
10524
10509
|
key = { kind: "property", name: actual.property.name };
|
|
@@ -10530,7 +10515,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
10530
10515
|
return null;
|
|
10531
10516
|
}
|
|
10532
10517
|
const expected = call.arguments[0];
|
|
10533
|
-
if (call.arguments.length !== 1 || expected === void 0 || expected.type ===
|
|
10518
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === import_utils62.AST_NODE_TYPES.SpreadElement) {
|
|
10534
10519
|
return null;
|
|
10535
10520
|
}
|
|
10536
10521
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
@@ -10644,99 +10629,8 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
10644
10629
|
}
|
|
10645
10630
|
});
|
|
10646
10631
|
|
|
10647
|
-
// src/rules/prefer-zod-enum.ts
|
|
10648
|
-
var import_utils64 = require("@typescript-eslint/utils");
|
|
10649
|
-
var prefer_zod_enum_default = createRule({
|
|
10650
|
-
name: "prefer-zod-enum",
|
|
10651
|
-
meta: {
|
|
10652
|
-
type: "suggestion",
|
|
10653
|
-
docs: {
|
|
10654
|
-
description: "Prefer z.enum([...]) over z.union([z.literal(...), ...]) for string choices"
|
|
10655
|
-
},
|
|
10656
|
-
fixable: "code",
|
|
10657
|
-
schema: [],
|
|
10658
|
-
messages: {
|
|
10659
|
-
preferEnum: "Use `z.enum([...])` instead of a union of string-literal schemas."
|
|
10660
|
-
}
|
|
10661
|
-
},
|
|
10662
|
-
defaultOptions: [],
|
|
10663
|
-
create(context) {
|
|
10664
|
-
const sourceCode = context.sourceCode;
|
|
10665
|
-
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
10666
|
-
function enumValues(node) {
|
|
10667
|
-
const callee = node.callee;
|
|
10668
|
-
if (callee.type !== import_utils64.AST_NODE_TYPES.MemberExpression || callee.computed || callee.object.type !== import_utils64.AST_NODE_TYPES.Identifier || !zodNamespaces.has(callee.object.name) || callee.property.type !== import_utils64.AST_NODE_TYPES.Identifier || callee.property.name !== "union" || node.arguments.length !== 1) {
|
|
10669
|
-
return null;
|
|
10670
|
-
}
|
|
10671
|
-
const argument = node.arguments[0];
|
|
10672
|
-
if (argument === void 0 || argument.type !== import_utils64.AST_NODE_TYPES.ArrayExpression || argument.elements.length === 0) {
|
|
10673
|
-
return null;
|
|
10674
|
-
}
|
|
10675
|
-
const values = [];
|
|
10676
|
-
let canFix = true;
|
|
10677
|
-
for (const element of argument.elements) {
|
|
10678
|
-
if (element?.type === import_utils64.AST_NODE_TYPES.SpreadElement) {
|
|
10679
|
-
canFix = false;
|
|
10680
|
-
continue;
|
|
10681
|
-
}
|
|
10682
|
-
if (element === null || element.type !== import_utils64.AST_NODE_TYPES.CallExpression || element.callee.type !== import_utils64.AST_NODE_TYPES.MemberExpression || element.callee.computed || element.callee.object.type !== import_utils64.AST_NODE_TYPES.Identifier || !zodNamespaces.has(element.callee.object.name) || element.callee.property.type !== import_utils64.AST_NODE_TYPES.Identifier || element.callee.property.name !== "literal") {
|
|
10683
|
-
return null;
|
|
10684
|
-
}
|
|
10685
|
-
const value = element.arguments[0];
|
|
10686
|
-
if (element.arguments.length !== 1 || value === void 0 || value.type !== import_utils64.AST_NODE_TYPES.Literal || typeof value.value !== "string") {
|
|
10687
|
-
canFix = false;
|
|
10688
|
-
continue;
|
|
10689
|
-
}
|
|
10690
|
-
values.push(value);
|
|
10691
|
-
}
|
|
10692
|
-
return canFix ? values : void 0;
|
|
10693
|
-
}
|
|
10694
|
-
function buildFix(node, values) {
|
|
10695
|
-
const argument = node.arguments[0];
|
|
10696
|
-
if (argument === void 0 || argument.type !== import_utils64.AST_NODE_TYPES.ArrayExpression || sourceCode.getCommentsInside(argument).length > 0) {
|
|
10697
|
-
return void 0;
|
|
10698
|
-
}
|
|
10699
|
-
const callee = node.callee;
|
|
10700
|
-
if (callee.type !== import_utils64.AST_NODE_TYPES.MemberExpression || callee.property.type !== import_utils64.AST_NODE_TYPES.Identifier) {
|
|
10701
|
-
return void 0;
|
|
10702
|
-
}
|
|
10703
|
-
return (fixer) => [
|
|
10704
|
-
fixer.replaceText(callee.property, "enum"),
|
|
10705
|
-
fixer.replaceText(
|
|
10706
|
-
argument,
|
|
10707
|
-
`[${values.map((value) => sourceCode.getText(value)).join(", ")}]`
|
|
10708
|
-
)
|
|
10709
|
-
];
|
|
10710
|
-
}
|
|
10711
|
-
return {
|
|
10712
|
-
ImportDeclaration(node) {
|
|
10713
|
-
if (!isZodModule2(node.source.value)) {
|
|
10714
|
-
return;
|
|
10715
|
-
}
|
|
10716
|
-
for (const specifier of node.specifiers) {
|
|
10717
|
-
if (specifier.type === import_utils64.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils64.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils64.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils64.AST_NODE_TYPES.Identifier && specifier.imported.name === "z") {
|
|
10718
|
-
zodNamespaces.add(specifier.local.name);
|
|
10719
|
-
}
|
|
10720
|
-
}
|
|
10721
|
-
},
|
|
10722
|
-
CallExpression(node) {
|
|
10723
|
-
const values = enumValues(node);
|
|
10724
|
-
if (values === null) {
|
|
10725
|
-
return;
|
|
10726
|
-
}
|
|
10727
|
-
const fix = values === void 0 ? void 0 : buildFix(node, values);
|
|
10728
|
-
context.report({
|
|
10729
|
-
node,
|
|
10730
|
-
messageId: "preferEnum",
|
|
10731
|
-
...fix === void 0 ? {} : { fix }
|
|
10732
|
-
});
|
|
10733
|
-
}
|
|
10734
|
-
};
|
|
10735
|
-
}
|
|
10736
|
-
});
|
|
10737
|
-
|
|
10738
10632
|
// src/rules/prefer-zod-infer.ts
|
|
10739
|
-
var
|
|
10633
|
+
var import_utils63 = require("@typescript-eslint/utils");
|
|
10740
10634
|
var SHAPE_PRESERVING_METHODS = /* @__PURE__ */ new Set([
|
|
10741
10635
|
"describe",
|
|
10742
10636
|
"refine",
|
|
@@ -10758,7 +10652,8 @@ var RESHAPING_MODIFIERS = /* @__PURE__ */ new Set([
|
|
|
10758
10652
|
"pipe",
|
|
10759
10653
|
"preprocess",
|
|
10760
10654
|
"brand",
|
|
10761
|
-
"overwrite"
|
|
10655
|
+
"overwrite",
|
|
10656
|
+
"readonly"
|
|
10762
10657
|
]);
|
|
10763
10658
|
var MODULE_LEVEL_RESHAPERS = /* @__PURE__ */ new Set([
|
|
10764
10659
|
"transform",
|
|
@@ -10773,44 +10668,44 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
10773
10668
|
"Schema"
|
|
10774
10669
|
]);
|
|
10775
10670
|
var LEAF_NODE_TYPES = {
|
|
10776
|
-
string: [
|
|
10777
|
-
email: [
|
|
10778
|
-
url: [
|
|
10779
|
-
uuid: [
|
|
10780
|
-
ulid: [
|
|
10781
|
-
cuid: [
|
|
10782
|
-
cuid2: [
|
|
10783
|
-
nanoid: [
|
|
10784
|
-
iso: [
|
|
10785
|
-
number: [
|
|
10786
|
-
int: [
|
|
10787
|
-
float32: [
|
|
10788
|
-
float64: [
|
|
10789
|
-
boolean: [
|
|
10790
|
-
bigint: [
|
|
10791
|
-
symbol: [
|
|
10792
|
-
any: [
|
|
10793
|
-
unknown: [
|
|
10794
|
-
never: [
|
|
10795
|
-
void: [
|
|
10796
|
-
null: [
|
|
10797
|
-
undefined: [
|
|
10798
|
-
literal: [
|
|
10799
|
-
date: [
|
|
10800
|
-
array: [
|
|
10801
|
-
tuple: [
|
|
10802
|
-
object: [
|
|
10803
|
-
strictObject: [
|
|
10804
|
-
looseObject: [
|
|
10805
|
-
record: [
|
|
10806
|
-
map: [
|
|
10807
|
-
set: [
|
|
10808
|
-
promise: [
|
|
10809
|
-
enum: [
|
|
10810
|
-
nativeEnum: [
|
|
10811
|
-
union: [
|
|
10812
|
-
discriminatedUnion: [
|
|
10813
|
-
intersection: [
|
|
10671
|
+
string: [import_utils63.AST_NODE_TYPES.TSStringKeyword],
|
|
10672
|
+
email: [import_utils63.AST_NODE_TYPES.TSStringKeyword],
|
|
10673
|
+
url: [import_utils63.AST_NODE_TYPES.TSStringKeyword],
|
|
10674
|
+
uuid: [import_utils63.AST_NODE_TYPES.TSStringKeyword],
|
|
10675
|
+
ulid: [import_utils63.AST_NODE_TYPES.TSStringKeyword],
|
|
10676
|
+
cuid: [import_utils63.AST_NODE_TYPES.TSStringKeyword],
|
|
10677
|
+
cuid2: [import_utils63.AST_NODE_TYPES.TSStringKeyword],
|
|
10678
|
+
nanoid: [import_utils63.AST_NODE_TYPES.TSStringKeyword],
|
|
10679
|
+
iso: [import_utils63.AST_NODE_TYPES.TSStringKeyword],
|
|
10680
|
+
number: [import_utils63.AST_NODE_TYPES.TSNumberKeyword],
|
|
10681
|
+
int: [import_utils63.AST_NODE_TYPES.TSNumberKeyword],
|
|
10682
|
+
float32: [import_utils63.AST_NODE_TYPES.TSNumberKeyword],
|
|
10683
|
+
float64: [import_utils63.AST_NODE_TYPES.TSNumberKeyword],
|
|
10684
|
+
boolean: [import_utils63.AST_NODE_TYPES.TSBooleanKeyword],
|
|
10685
|
+
bigint: [import_utils63.AST_NODE_TYPES.TSBigIntKeyword],
|
|
10686
|
+
symbol: [import_utils63.AST_NODE_TYPES.TSSymbolKeyword],
|
|
10687
|
+
any: [import_utils63.AST_NODE_TYPES.TSAnyKeyword],
|
|
10688
|
+
unknown: [import_utils63.AST_NODE_TYPES.TSUnknownKeyword],
|
|
10689
|
+
never: [import_utils63.AST_NODE_TYPES.TSNeverKeyword],
|
|
10690
|
+
void: [import_utils63.AST_NODE_TYPES.TSVoidKeyword],
|
|
10691
|
+
null: [import_utils63.AST_NODE_TYPES.TSNullKeyword],
|
|
10692
|
+
undefined: [import_utils63.AST_NODE_TYPES.TSUndefinedKeyword],
|
|
10693
|
+
literal: [import_utils63.AST_NODE_TYPES.TSLiteralType],
|
|
10694
|
+
date: [import_utils63.AST_NODE_TYPES.TSTypeReference],
|
|
10695
|
+
array: [import_utils63.AST_NODE_TYPES.TSArrayType, import_utils63.AST_NODE_TYPES.TSTypeReference],
|
|
10696
|
+
tuple: [import_utils63.AST_NODE_TYPES.TSTupleType],
|
|
10697
|
+
object: [import_utils63.AST_NODE_TYPES.TSTypeLiteral, import_utils63.AST_NODE_TYPES.TSTypeReference],
|
|
10698
|
+
strictObject: [import_utils63.AST_NODE_TYPES.TSTypeLiteral, import_utils63.AST_NODE_TYPES.TSTypeReference],
|
|
10699
|
+
looseObject: [import_utils63.AST_NODE_TYPES.TSTypeLiteral, import_utils63.AST_NODE_TYPES.TSTypeReference],
|
|
10700
|
+
record: [import_utils63.AST_NODE_TYPES.TSTypeReference, import_utils63.AST_NODE_TYPES.TSTypeLiteral],
|
|
10701
|
+
map: [import_utils63.AST_NODE_TYPES.TSTypeReference],
|
|
10702
|
+
set: [import_utils63.AST_NODE_TYPES.TSTypeReference],
|
|
10703
|
+
promise: [import_utils63.AST_NODE_TYPES.TSTypeReference],
|
|
10704
|
+
enum: [import_utils63.AST_NODE_TYPES.TSUnionType, import_utils63.AST_NODE_TYPES.TSTypeReference, import_utils63.AST_NODE_TYPES.TSLiteralType],
|
|
10705
|
+
nativeEnum: [import_utils63.AST_NODE_TYPES.TSUnionType, import_utils63.AST_NODE_TYPES.TSTypeReference, import_utils63.AST_NODE_TYPES.TSLiteralType],
|
|
10706
|
+
union: [import_utils63.AST_NODE_TYPES.TSUnionType, import_utils63.AST_NODE_TYPES.TSTypeReference],
|
|
10707
|
+
discriminatedUnion: [import_utils63.AST_NODE_TYPES.TSUnionType, import_utils63.AST_NODE_TYPES.TSTypeReference],
|
|
10708
|
+
intersection: [import_utils63.AST_NODE_TYPES.TSIntersectionType, import_utils63.AST_NODE_TYPES.TSTypeReference]
|
|
10814
10709
|
};
|
|
10815
10710
|
function normalizeSchemaName(name) {
|
|
10816
10711
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -10819,20 +10714,20 @@ function normalizeTypeName(name) {
|
|
|
10819
10714
|
return name.replace(/Type$/, "").toLowerCase();
|
|
10820
10715
|
}
|
|
10821
10716
|
function unwrapNullish(annotation) {
|
|
10822
|
-
if (annotation.type !==
|
|
10717
|
+
if (annotation.type !== import_utils63.AST_NODE_TYPES.TSUnionType) {
|
|
10823
10718
|
return {
|
|
10824
10719
|
core: annotation,
|
|
10825
|
-
nullable: annotation.type ===
|
|
10720
|
+
nullable: annotation.type === import_utils63.AST_NODE_TYPES.TSNullKeyword
|
|
10826
10721
|
};
|
|
10827
10722
|
}
|
|
10828
10723
|
const rest = [];
|
|
10829
10724
|
let nullable = false;
|
|
10830
10725
|
for (const member of annotation.types) {
|
|
10831
|
-
if (member.type ===
|
|
10726
|
+
if (member.type === import_utils63.AST_NODE_TYPES.TSNullKeyword) {
|
|
10832
10727
|
nullable = true;
|
|
10833
10728
|
continue;
|
|
10834
10729
|
}
|
|
10835
|
-
if (member.type ===
|
|
10730
|
+
if (member.type === import_utils63.AST_NODE_TYPES.TSUndefinedKeyword) {
|
|
10836
10731
|
continue;
|
|
10837
10732
|
}
|
|
10838
10733
|
rest.push(member);
|
|
@@ -10854,6 +10749,9 @@ function leafAgrees(leaf, annotation) {
|
|
|
10854
10749
|
if (core === null) {
|
|
10855
10750
|
return null;
|
|
10856
10751
|
}
|
|
10752
|
+
if (leaf === "date") {
|
|
10753
|
+
return core.type === import_utils63.AST_NODE_TYPES.TSTypeReference && core.typeName.type === import_utils63.AST_NODE_TYPES.Identifier && core.typeName.name === "Date";
|
|
10754
|
+
}
|
|
10857
10755
|
return expected.includes(core.type);
|
|
10858
10756
|
}
|
|
10859
10757
|
var prefer_zod_infer_default = createRule({
|
|
@@ -10897,14 +10795,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
10897
10795
|
function zodCallChain(node) {
|
|
10898
10796
|
const chain = [];
|
|
10899
10797
|
let current = node;
|
|
10900
|
-
while (current.type ===
|
|
10798
|
+
while (current.type === import_utils63.AST_NODE_TYPES.CallExpression) {
|
|
10901
10799
|
const callee = current.callee;
|
|
10902
|
-
if (callee.type !==
|
|
10800
|
+
if (callee.type !== import_utils63.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils63.AST_NODE_TYPES.Identifier) {
|
|
10903
10801
|
return null;
|
|
10904
10802
|
}
|
|
10905
10803
|
chain.push(current);
|
|
10906
10804
|
const receiver = callee.object;
|
|
10907
|
-
if (receiver.type ===
|
|
10805
|
+
if (receiver.type === import_utils63.AST_NODE_TYPES.Identifier) {
|
|
10908
10806
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
10909
10807
|
}
|
|
10910
10808
|
current = receiver;
|
|
@@ -10913,19 +10811,19 @@ var prefer_zod_infer_default = createRule({
|
|
|
10913
10811
|
}
|
|
10914
10812
|
function methodName2(call) {
|
|
10915
10813
|
const callee = call.callee;
|
|
10916
|
-
return callee.type ===
|
|
10814
|
+
return callee.type === import_utils63.AST_NODE_TYPES.MemberExpression && callee.property.type === import_utils63.AST_NODE_TYPES.Identifier ? callee.property.name : "";
|
|
10917
10815
|
}
|
|
10918
10816
|
function schemaField(node) {
|
|
10919
10817
|
const modifiers = [];
|
|
10920
10818
|
let current = node;
|
|
10921
10819
|
let leaf = null;
|
|
10922
|
-
while (current.type ===
|
|
10820
|
+
while (current.type === import_utils63.AST_NODE_TYPES.CallExpression) {
|
|
10923
10821
|
const callee = current.callee;
|
|
10924
|
-
if (callee.type !==
|
|
10822
|
+
if (callee.type !== import_utils63.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils63.AST_NODE_TYPES.Identifier) {
|
|
10925
10823
|
break;
|
|
10926
10824
|
}
|
|
10927
10825
|
const receiver = callee.object;
|
|
10928
|
-
if (receiver.type ===
|
|
10826
|
+
if (receiver.type === import_utils63.AST_NODE_TYPES.Identifier && zodNamespaces.has(receiver.name)) {
|
|
10929
10827
|
leaf = callee.property.name;
|
|
10930
10828
|
break;
|
|
10931
10829
|
}
|
|
@@ -10956,16 +10854,16 @@ var prefer_zod_infer_default = createRule({
|
|
|
10956
10854
|
return null;
|
|
10957
10855
|
}
|
|
10958
10856
|
const shape = base.arguments[0];
|
|
10959
|
-
if (shape === void 0 || shape.type !==
|
|
10857
|
+
if (shape === void 0 || shape.type !== import_utils63.AST_NODE_TYPES.ObjectExpression) {
|
|
10960
10858
|
return null;
|
|
10961
10859
|
}
|
|
10962
10860
|
const fields = /* @__PURE__ */ new Map();
|
|
10963
10861
|
for (const property of shape.properties) {
|
|
10964
|
-
if (property.type !==
|
|
10862
|
+
if (property.type !== import_utils63.AST_NODE_TYPES.Property || property.computed) {
|
|
10965
10863
|
return null;
|
|
10966
10864
|
}
|
|
10967
10865
|
const { key } = property;
|
|
10968
|
-
const name = key.type ===
|
|
10866
|
+
const name = key.type === import_utils63.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils63.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
10969
10867
|
if (name === null) {
|
|
10970
10868
|
return null;
|
|
10971
10869
|
}
|
|
@@ -10976,11 +10874,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
10976
10874
|
function typeMembers(members) {
|
|
10977
10875
|
const result = /* @__PURE__ */ new Map();
|
|
10978
10876
|
for (const member of members) {
|
|
10979
|
-
if (member.type !==
|
|
10877
|
+
if (member.type !== import_utils63.AST_NODE_TYPES.TSPropertySignature || member.computed) {
|
|
10980
10878
|
return null;
|
|
10981
10879
|
}
|
|
10982
10880
|
const { key } = member;
|
|
10983
|
-
const name = key.type ===
|
|
10881
|
+
const name = key.type === import_utils63.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils63.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
10984
10882
|
if (name === null) {
|
|
10985
10883
|
return null;
|
|
10986
10884
|
}
|
|
@@ -10988,14 +10886,15 @@ var prefer_zod_infer_default = createRule({
|
|
|
10988
10886
|
result.set(name, {
|
|
10989
10887
|
optional: member.optional === true,
|
|
10990
10888
|
nullable: annotation !== null && unwrapNullish(annotation).nullable,
|
|
10889
|
+
readonly: member.readonly === true,
|
|
10991
10890
|
annotation
|
|
10992
10891
|
});
|
|
10993
10892
|
}
|
|
10994
10893
|
return result.size === 0 ? null : result;
|
|
10995
10894
|
}
|
|
10996
10895
|
function collectConstrainedNames(node) {
|
|
10997
|
-
if (node.type ===
|
|
10998
|
-
if (node.typeName.type ===
|
|
10896
|
+
if (node.type === import_utils63.AST_NODE_TYPES.TSTypeReference) {
|
|
10897
|
+
if (node.typeName.type === import_utils63.AST_NODE_TYPES.Identifier) {
|
|
10999
10898
|
constrainedTypeNames.add(node.typeName.name);
|
|
11000
10899
|
}
|
|
11001
10900
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -11003,11 +10902,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
11003
10902
|
}
|
|
11004
10903
|
return;
|
|
11005
10904
|
}
|
|
11006
|
-
if (node.type ===
|
|
10905
|
+
if (node.type === import_utils63.AST_NODE_TYPES.TSArrayType) {
|
|
11007
10906
|
collectConstrainedNames(node.elementType);
|
|
11008
10907
|
return;
|
|
11009
10908
|
}
|
|
11010
|
-
if (node.type ===
|
|
10909
|
+
if (node.type === import_utils63.AST_NODE_TYPES.TSUnionType || node.type === import_utils63.AST_NODE_TYPES.TSIntersectionType) {
|
|
11011
10910
|
for (const member of node.types) {
|
|
11012
10911
|
collectConstrainedNames(member);
|
|
11013
10912
|
}
|
|
@@ -11035,6 +10934,9 @@ var prefer_zod_infer_default = createRule({
|
|
|
11035
10934
|
if (field.nullable !== member.nullable) {
|
|
11036
10935
|
return false;
|
|
11037
10936
|
}
|
|
10937
|
+
if (member.readonly) {
|
|
10938
|
+
return false;
|
|
10939
|
+
}
|
|
11038
10940
|
const agrees = leafAgrees(field.leaf, member.annotation);
|
|
11039
10941
|
if (agrees === false) {
|
|
11040
10942
|
return false;
|
|
@@ -11047,17 +10949,17 @@ var prefer_zod_infer_default = createRule({
|
|
|
11047
10949
|
}
|
|
11048
10950
|
return {
|
|
11049
10951
|
ImportDeclaration(node) {
|
|
11050
|
-
if (!
|
|
10952
|
+
if (!isZodModule(node.source.value)) {
|
|
11051
10953
|
return;
|
|
11052
10954
|
}
|
|
11053
10955
|
for (const specifier of node.specifiers) {
|
|
11054
|
-
if (specifier.type ===
|
|
10956
|
+
if (specifier.type === import_utils63.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils63.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils63.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils63.AST_NODE_TYPES.Identifier && specifier.imported.name === "z") {
|
|
11055
10957
|
zodNamespaces.add(specifier.local.name);
|
|
11056
10958
|
}
|
|
11057
10959
|
}
|
|
11058
10960
|
},
|
|
11059
10961
|
VariableDeclarator(node) {
|
|
11060
|
-
if (node.id.type !==
|
|
10962
|
+
if (node.id.type !== import_utils63.AST_NODE_TYPES.Identifier || node.init == null) {
|
|
11061
10963
|
return;
|
|
11062
10964
|
}
|
|
11063
10965
|
const fields = schemaFields(node.init);
|
|
@@ -11067,14 +10969,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
11067
10969
|
},
|
|
11068
10970
|
/** Records `XSchema.transform(...)` and equivalent module-level reshaping. */
|
|
11069
10971
|
"MemberExpression[computed=false]"(node) {
|
|
11070
|
-
if (node.object.type ===
|
|
10972
|
+
if (node.object.type === import_utils63.AST_NODE_TYPES.Identifier && node.property.type === import_utils63.AST_NODE_TYPES.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
11071
10973
|
reshapedSchemaNames.add(node.object.name);
|
|
11072
10974
|
}
|
|
11073
10975
|
},
|
|
11074
10976
|
/** Records every type argument carried by a Zod constraint. */
|
|
11075
10977
|
TSTypeReference(node) {
|
|
11076
10978
|
const { typeName } = node;
|
|
11077
|
-
const referenced = typeName.type ===
|
|
10979
|
+
const referenced = typeName.type === import_utils63.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils63.AST_NODE_TYPES.TSQualifiedName && typeName.right.type === import_utils63.AST_NODE_TYPES.Identifier ? typeName.right.name : null;
|
|
11078
10980
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
11079
10981
|
return;
|
|
11080
10982
|
}
|
|
@@ -11092,7 +10994,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
11092
10994
|
}
|
|
11093
10995
|
},
|
|
11094
10996
|
TSTypeAliasDeclaration(node) {
|
|
11095
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
10997
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== import_utils63.AST_NODE_TYPES.TSTypeLiteral) {
|
|
11096
10998
|
return;
|
|
11097
10999
|
}
|
|
11098
11000
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -11137,10 +11039,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
11137
11039
|
});
|
|
11138
11040
|
|
|
11139
11041
|
// src/rules/require-assert-never.ts
|
|
11140
|
-
var
|
|
11042
|
+
var import_utils64 = require("@typescript-eslint/utils");
|
|
11043
|
+
var import_typescript = __toESM(require("typescript"), 1);
|
|
11141
11044
|
var isRuntimeHandlingStatement = (statement) => {
|
|
11142
|
-
if (statement.type ===
|
|
11143
|
-
if (statement.type ===
|
|
11045
|
+
if (statement.type === import_utils64.AST_NODE_TYPES.EmptyStatement) return false;
|
|
11046
|
+
if (statement.type === import_utils64.AST_NODE_TYPES.TSTypeAliasDeclaration || statement.type === import_utils64.AST_NODE_TYPES.TSInterfaceDeclaration) {
|
|
11047
|
+
return false;
|
|
11048
|
+
}
|
|
11049
|
+
if (statement.type === import_utils64.AST_NODE_TYPES.BlockStatement) {
|
|
11144
11050
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
11145
11051
|
}
|
|
11146
11052
|
return true;
|
|
@@ -11156,11 +11062,40 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
11156
11062
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
11157
11063
|
}
|
|
11158
11064
|
const only = defaultCase.consequent[0];
|
|
11159
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
11065
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === import_utils64.AST_NODE_TYPES.BlockStatement && !only.body.some(isRuntimeHandlingStatement)) {
|
|
11160
11066
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
11161
11067
|
}
|
|
11162
11068
|
return false;
|
|
11163
11069
|
};
|
|
11070
|
+
function isExhaustiveFiniteSwitch(node, services) {
|
|
11071
|
+
const checker = services.program.getTypeChecker();
|
|
11072
|
+
const discriminant = services.esTreeNodeToTSNodeMap.get(node.discriminant);
|
|
11073
|
+
const discriminantType = checker.getTypeAtLocation(discriminant);
|
|
11074
|
+
const constituents = discriminantType.isUnion() ? discriminantType.types : [discriminantType];
|
|
11075
|
+
if (constituents.length === 0) return false;
|
|
11076
|
+
const expected = /* @__PURE__ */ new Set();
|
|
11077
|
+
for (const constituent of constituents) {
|
|
11078
|
+
const key = finiteTypeKey(constituent, checker);
|
|
11079
|
+
if (key === null) return false;
|
|
11080
|
+
expected.add(key);
|
|
11081
|
+
}
|
|
11082
|
+
const handled = /* @__PURE__ */ new Set();
|
|
11083
|
+
for (const caseNode of node.cases) {
|
|
11084
|
+
if (caseNode.test === null) continue;
|
|
11085
|
+
const test = services.esTreeNodeToTSNodeMap.get(caseNode.test);
|
|
11086
|
+
const testType = checker.getTypeAtLocation(test);
|
|
11087
|
+
const alternatives = testType.isUnion() ? testType.types : [testType];
|
|
11088
|
+
for (const alternative of alternatives) {
|
|
11089
|
+
const key = finiteTypeKey(alternative, checker);
|
|
11090
|
+
if (key !== null) handled.add(key);
|
|
11091
|
+
}
|
|
11092
|
+
}
|
|
11093
|
+
return [...expected].every((key) => handled.has(key));
|
|
11094
|
+
}
|
|
11095
|
+
function finiteTypeKey(type, checker) {
|
|
11096
|
+
const finiteFlags = import_typescript.default.TypeFlags.StringLiteral | import_typescript.default.TypeFlags.NumberLiteral | import_typescript.default.TypeFlags.BooleanLiteral | import_typescript.default.TypeFlags.EnumLiteral | import_typescript.default.TypeFlags.UniqueESSymbol | import_typescript.default.TypeFlags.Null | import_typescript.default.TypeFlags.Undefined;
|
|
11097
|
+
return (type.flags & finiteFlags) !== 0 ? checker.typeToString(type) : null;
|
|
11098
|
+
}
|
|
11164
11099
|
var require_assert_never_default = createRule({
|
|
11165
11100
|
name: "require-assert-never",
|
|
11166
11101
|
meta: {
|
|
@@ -11175,6 +11110,12 @@ var require_assert_never_default = createRule({
|
|
|
11175
11110
|
},
|
|
11176
11111
|
defaultOptions: [],
|
|
11177
11112
|
create(context) {
|
|
11113
|
+
let services;
|
|
11114
|
+
try {
|
|
11115
|
+
services = import_utils64.ESLintUtils.getParserServices(context);
|
|
11116
|
+
} catch {
|
|
11117
|
+
return {};
|
|
11118
|
+
}
|
|
11178
11119
|
return {
|
|
11179
11120
|
SwitchStatement(node) {
|
|
11180
11121
|
const defaultIndex = node.cases.findIndex(
|
|
@@ -11186,6 +11127,7 @@ var require_assert_never_default = createRule({
|
|
|
11186
11127
|
if (defaultCase.consequent.some(isRuntimeHandlingStatement)) return;
|
|
11187
11128
|
if (isFallthroughDefault(node, defaultIndex)) return;
|
|
11188
11129
|
if (isCommentOnlyNoopDefault(defaultCase, context.sourceCode)) return;
|
|
11130
|
+
if (!isExhaustiveFiniteSwitch(node, services)) return;
|
|
11189
11131
|
context.report({
|
|
11190
11132
|
node: defaultCase,
|
|
11191
11133
|
messageId: "missingAssertNever"
|
|
@@ -11196,7 +11138,7 @@ var require_assert_never_default = createRule({
|
|
|
11196
11138
|
});
|
|
11197
11139
|
|
|
11198
11140
|
// src/rules/require-fetch-timeout.ts
|
|
11199
|
-
var
|
|
11141
|
+
var import_utils65 = require("@typescript-eslint/utils");
|
|
11200
11142
|
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set([
|
|
11201
11143
|
"globalThis",
|
|
11202
11144
|
"window",
|
|
@@ -11212,14 +11154,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
11212
11154
|
return false;
|
|
11213
11155
|
}
|
|
11214
11156
|
function initProvablyLacksSignal(init) {
|
|
11215
|
-
if (init.type !==
|
|
11157
|
+
if (init.type !== import_utils65.AST_NODE_TYPES.ObjectExpression) {
|
|
11216
11158
|
return false;
|
|
11217
11159
|
}
|
|
11218
11160
|
for (const prop of init.properties) {
|
|
11219
|
-
if (prop.type ===
|
|
11161
|
+
if (prop.type === import_utils65.AST_NODE_TYPES.SpreadElement) {
|
|
11220
11162
|
return false;
|
|
11221
11163
|
}
|
|
11222
|
-
if (prop.key.type ===
|
|
11164
|
+
if (prop.key.type === import_utils65.AST_NODE_TYPES.Identifier && prop.key.name === "signal" || prop.key.type === import_utils65.AST_NODE_TYPES.Literal && prop.key.value === "signal") {
|
|
11223
11165
|
return false;
|
|
11224
11166
|
}
|
|
11225
11167
|
if (prop.computed) {
|
|
@@ -11229,7 +11171,7 @@ function initProvablyLacksSignal(init) {
|
|
|
11229
11171
|
return true;
|
|
11230
11172
|
}
|
|
11231
11173
|
function isInlineUrl(node, resolvesToGlobal) {
|
|
11232
|
-
return node.type ===
|
|
11174
|
+
return node.type === import_utils65.AST_NODE_TYPES.Literal && typeof node.value === "string" || node.type === import_utils65.AST_NODE_TYPES.TemplateLiteral || node.type === import_utils65.AST_NODE_TYPES.NewExpression && node.callee.type === import_utils65.AST_NODE_TYPES.Identifier && node.callee.name === "URL" && resolvesToGlobal(node.callee);
|
|
11233
11175
|
}
|
|
11234
11176
|
var require_fetch_timeout_default = createRule({
|
|
11235
11177
|
name: "require-fetch-timeout",
|
|
@@ -11266,14 +11208,14 @@ var require_fetch_timeout_default = createRule({
|
|
|
11266
11208
|
}
|
|
11267
11209
|
function resolvesToGlobal(identifier) {
|
|
11268
11210
|
const scope = context.sourceCode.getScope(identifier);
|
|
11269
|
-
const variable =
|
|
11211
|
+
const variable = import_utils65.ASTUtils.findVariable(scope, identifier.name);
|
|
11270
11212
|
return variable === null || variable.defs.length === 0;
|
|
11271
11213
|
}
|
|
11272
11214
|
function isGlobalFetchCall2(callee) {
|
|
11273
|
-
if (callee.type ===
|
|
11215
|
+
if (callee.type === import_utils65.AST_NODE_TYPES.Identifier) {
|
|
11274
11216
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
11275
11217
|
}
|
|
11276
|
-
return callee.type ===
|
|
11218
|
+
return callee.type === import_utils65.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils65.AST_NODE_TYPES.Identifier && callee.property.name === "fetch" && callee.object.type === import_utils65.AST_NODE_TYPES.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
11277
11219
|
}
|
|
11278
11220
|
return {
|
|
11279
11221
|
CallExpression(node) {
|
|
@@ -11293,7 +11235,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
11293
11235
|
});
|
|
11294
11236
|
|
|
11295
11237
|
// src/rules/require-interface-for-injected-service.ts
|
|
11296
|
-
var
|
|
11238
|
+
var import_utils66 = require("@typescript-eslint/utils");
|
|
11297
11239
|
var CONFIGISH_TYPE_RE = /(?:Options|Opts|Config|Configuration|Settings|Params|Props|Args|Env|Environment|Callbacks|Flags)$/;
|
|
11298
11240
|
var CONFIGISH_NAME_RE = /^(?:options|opts|config|configuration|settings|params|props|args|env|environment|callbacks|flags|logger|log|clock)$/i;
|
|
11299
11241
|
var HTTP_TRANSPORT_TYPE_RE = /^(?:KyInstance|AxiosInstance|Session)$/;
|
|
@@ -11306,46 +11248,46 @@ var FLUENT_RESULT_TYPE_RE = /(?:Builder|Base|Query|Without)(?:\W|$)/;
|
|
|
11306
11248
|
var ROUTER_FACTORY_NAME = "Router";
|
|
11307
11249
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
11308
11250
|
var STORAGE_ASSIGNMENT_OPERATORS = /* @__PURE__ */ new Set(["=", "&&=", "??=", "||="]);
|
|
11309
|
-
var
|
|
11310
|
-
if (member.property.type ===
|
|
11311
|
-
if (!member.computed && member.property.type ===
|
|
11312
|
-
return member.computed && member.property.type ===
|
|
11251
|
+
var staticMemberName4 = (member) => {
|
|
11252
|
+
if (member.property.type === import_utils66.AST_NODE_TYPES.PrivateIdentifier) return `#${member.property.name}`;
|
|
11253
|
+
if (!member.computed && member.property.type === import_utils66.AST_NODE_TYPES.Identifier) return member.property.name;
|
|
11254
|
+
return member.computed && member.property.type === import_utils66.AST_NODE_TYPES.Literal && typeof member.property.value === "string" ? member.property.value : null;
|
|
11313
11255
|
};
|
|
11314
11256
|
var detachedValueExports = (program) => {
|
|
11315
11257
|
const names = /* @__PURE__ */ new Set();
|
|
11316
11258
|
for (const statement of program.body) {
|
|
11317
|
-
if (statement.type ===
|
|
11259
|
+
if (statement.type === import_utils66.AST_NODE_TYPES.ExportNamedDeclaration && statement.declaration === null && statement.source === null && statement.exportKind !== "type") {
|
|
11318
11260
|
for (const specifier of statement.specifiers) {
|
|
11319
11261
|
if (specifier.exportKind !== "type") names.add(specifier.local.name);
|
|
11320
11262
|
}
|
|
11321
|
-
} else if (statement.type ===
|
|
11263
|
+
} else if (statement.type === import_utils66.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils66.AST_NODE_TYPES.Identifier) {
|
|
11322
11264
|
names.add(statement.declaration.name);
|
|
11323
|
-
} else if (statement.type ===
|
|
11265
|
+
} else if (statement.type === import_utils66.AST_NODE_TYPES.TSExportAssignment && statement.expression.type === import_utils66.AST_NODE_TYPES.Identifier) {
|
|
11324
11266
|
names.add(statement.expression.name);
|
|
11325
11267
|
}
|
|
11326
11268
|
}
|
|
11327
11269
|
return names;
|
|
11328
11270
|
};
|
|
11329
|
-
var isExportedClass2 = (node, detached) => node.parent.type ===
|
|
11271
|
+
var isExportedClass2 = (node, detached) => node.parent.type === import_utils66.AST_NODE_TYPES.ExportNamedDeclaration || node.parent.type === import_utils66.AST_NODE_TYPES.ExportDefaultDeclaration || node.id !== null && detached.has(node.id.name);
|
|
11330
11272
|
var readTypeReference = (annotation) => {
|
|
11331
|
-
if (annotation?.type ===
|
|
11273
|
+
if (annotation?.type === import_utils66.AST_NODE_TYPES.TSUnionType) {
|
|
11332
11274
|
const members = annotation.types.filter(
|
|
11333
|
-
(member) => member.type !==
|
|
11275
|
+
(member) => member.type !== import_utils66.AST_NODE_TYPES.TSUndefinedKeyword && member.type !== import_utils66.AST_NODE_TYPES.TSNullKeyword
|
|
11334
11276
|
);
|
|
11335
11277
|
annotation = members.length === 1 ? members[0] : void 0;
|
|
11336
11278
|
}
|
|
11337
|
-
if (annotation === void 0 || annotation.type !==
|
|
11279
|
+
if (annotation === void 0 || annotation.type !== import_utils66.AST_NODE_TYPES.TSTypeReference) return null;
|
|
11338
11280
|
const { typeName } = annotation;
|
|
11339
|
-
const rightmost = typeName.type ===
|
|
11281
|
+
const rightmost = typeName.type === import_utils66.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils66.AST_NODE_TYPES.TSQualifiedName ? typeName.right.name : null;
|
|
11340
11282
|
if (rightmost === null) return null;
|
|
11341
11283
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
11342
11284
|
};
|
|
11343
|
-
var qualifiedName = (name) => name.type ===
|
|
11285
|
+
var qualifiedName = (name) => name.type === import_utils66.AST_NODE_TYPES.Identifier ? name.name : name.type === import_utils66.AST_NODE_TYPES.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
11344
11286
|
var propertySignatureTypes = (members) => {
|
|
11345
11287
|
const types = /* @__PURE__ */ new Map();
|
|
11346
11288
|
for (const member of members) {
|
|
11347
|
-
if (member.type !==
|
|
11348
|
-
if (member.computed || member.key.type !==
|
|
11289
|
+
if (member.type !== import_utils66.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
11290
|
+
if (member.computed || member.key.type !== import_utils66.AST_NODE_TYPES.Identifier) continue;
|
|
11349
11291
|
const reference = readTypeReference(member.typeAnnotation?.typeAnnotation);
|
|
11350
11292
|
if (reference === null) continue;
|
|
11351
11293
|
types.set(member.key.name, reference);
|
|
@@ -11356,18 +11298,18 @@ var fileTypeIndex = (program) => {
|
|
|
11356
11298
|
const objects = /* @__PURE__ */ new Map();
|
|
11357
11299
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
11358
11300
|
for (const statement of program.body) {
|
|
11359
|
-
const declaration = statement.type ===
|
|
11360
|
-
if (declaration?.type ===
|
|
11301
|
+
const declaration = statement.type === import_utils66.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
11302
|
+
if (declaration?.type === import_utils66.AST_NODE_TYPES.TSInterfaceDeclaration) {
|
|
11361
11303
|
objects.set(declaration.id.name, propertySignatureTypes(declaration.body.body));
|
|
11362
11304
|
continue;
|
|
11363
11305
|
}
|
|
11364
|
-
if (declaration?.type !==
|
|
11306
|
+
if (declaration?.type !== import_utils66.AST_NODE_TYPES.TSTypeAliasDeclaration) continue;
|
|
11365
11307
|
const aliased = declaration.typeAnnotation;
|
|
11366
|
-
if (aliased.type ===
|
|
11308
|
+
if (aliased.type === import_utils66.AST_NODE_TYPES.TSFunctionType || aliased.type === import_utils66.AST_NODE_TYPES.TSConstructorType) {
|
|
11367
11309
|
functionAliases.add(declaration.id.name);
|
|
11368
11310
|
continue;
|
|
11369
11311
|
}
|
|
11370
|
-
const literals = aliased.type ===
|
|
11312
|
+
const literals = aliased.type === import_utils66.AST_NODE_TYPES.TSTypeLiteral ? [aliased] : aliased.type === import_utils66.AST_NODE_TYPES.TSIntersectionType ? aliased.types.filter((part) => part.type === import_utils66.AST_NODE_TYPES.TSTypeLiteral) : [];
|
|
11371
11313
|
if (literals.length === 0) continue;
|
|
11372
11314
|
const merged = /* @__PURE__ */ new Map();
|
|
11373
11315
|
for (const literal of literals) {
|
|
@@ -11395,10 +11337,10 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
11395
11337
|
while (pending.length > 0) {
|
|
11396
11338
|
const current = pending.pop();
|
|
11397
11339
|
if (current === void 0) break;
|
|
11398
|
-
if (current.type ===
|
|
11399
|
-
const expression = current.type ===
|
|
11400
|
-
const storedField = expression?.type ===
|
|
11401
|
-
if (expression?.type !==
|
|
11340
|
+
if (current.type === import_utils66.AST_NODE_TYPES.ArrowFunctionExpression || current.type === import_utils66.AST_NODE_TYPES.FunctionExpression || current.type === import_utils66.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils66.AST_NODE_TYPES.ClassExpression || current.type === import_utils66.AST_NODE_TYPES.ClassDeclaration) continue;
|
|
11341
|
+
const expression = current.type === import_utils66.AST_NODE_TYPES.ExpressionStatement ? current.expression : null;
|
|
11342
|
+
const storedField = expression?.type === import_utils66.AST_NODE_TYPES.AssignmentExpression && expression.left.type === import_utils66.AST_NODE_TYPES.MemberExpression && expression.left.object.type === import_utils66.AST_NODE_TYPES.ThisExpression ? staticMemberName4(expression.left) : null;
|
|
11343
|
+
if (expression?.type !== import_utils66.AST_NODE_TYPES.AssignmentExpression || !STORAGE_ASSIGNMENT_OPERATORS.has(expression.operator) || expression.left.type !== import_utils66.AST_NODE_TYPES.MemberExpression || expression.left.object.type !== import_utils66.AST_NODE_TYPES.ThisExpression || storedField === null) {
|
|
11402
11344
|
for (const key of Object.keys(current)) {
|
|
11403
11345
|
if (key === "parent") continue;
|
|
11404
11346
|
const value = current[key];
|
|
@@ -11411,14 +11353,14 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
11411
11353
|
continue;
|
|
11412
11354
|
}
|
|
11413
11355
|
let source = expression.right;
|
|
11414
|
-
while (source.type ===
|
|
11415
|
-
if (source.type ===
|
|
11356
|
+
while (source.type === import_utils66.AST_NODE_TYPES.TSNonNullExpression || source.type === import_utils66.AST_NODE_TYPES.TSAsExpression || source.type === import_utils66.AST_NODE_TYPES.TSSatisfiesExpression || source.type === import_utils66.AST_NODE_TYPES.TSTypeAssertion) source = source.expression;
|
|
11357
|
+
if (source.type === import_utils66.AST_NODE_TYPES.NewExpression) {
|
|
11416
11358
|
constructedFields += 1;
|
|
11417
|
-
} else if (source.type ===
|
|
11359
|
+
} else if (source.type === import_utils66.AST_NODE_TYPES.Identifier) {
|
|
11418
11360
|
const fields = storedFieldsFrom.get(source.name) ?? /* @__PURE__ */ new Set();
|
|
11419
11361
|
fields.add(storedField);
|
|
11420
11362
|
storedFieldsFrom.set(source.name, fields);
|
|
11421
|
-
} else if (source.type ===
|
|
11363
|
+
} else if (source.type === import_utils66.AST_NODE_TYPES.MemberExpression && source.object.type === import_utils66.AST_NODE_TYPES.Identifier) {
|
|
11422
11364
|
const fields = storedFieldsFrom.get(source.object.name) ?? /* @__PURE__ */ new Set();
|
|
11423
11365
|
fields.add(storedField);
|
|
11424
11366
|
storedFieldsFrom.set(source.object.name, fields);
|
|
@@ -11428,7 +11370,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
11428
11370
|
const collaborators = [];
|
|
11429
11371
|
for (const parameter of ctor.value.params) {
|
|
11430
11372
|
for (const reference of parameterCollaborators(parameter, declared)) {
|
|
11431
|
-
const fields = parameter.type ===
|
|
11373
|
+
const fields = parameter.type === import_utils66.AST_NODE_TYPES.TSParameterProperty ? [reference.name] : [...storedFieldsFrom.get(reference.name) ?? []];
|
|
11432
11374
|
if (fields.length === 0) continue;
|
|
11433
11375
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
11434
11376
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -11443,8 +11385,8 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
11443
11385
|
};
|
|
11444
11386
|
var parameterCollaborators = (parameter, declared) => {
|
|
11445
11387
|
let target = parameter;
|
|
11446
|
-
if (target.type ===
|
|
11447
|
-
if (target.type ===
|
|
11388
|
+
if (target.type === import_utils66.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
11389
|
+
if (target.type === import_utils66.AST_NODE_TYPES.ObjectPattern) {
|
|
11448
11390
|
return objectPatternCollaborators(target, declared);
|
|
11449
11391
|
}
|
|
11450
11392
|
const named2 = namedParameterCollaborator(parameter);
|
|
@@ -11452,9 +11394,9 @@ var parameterCollaborators = (parameter, declared) => {
|
|
|
11452
11394
|
};
|
|
11453
11395
|
var namedParameterCollaborator = (annotated) => {
|
|
11454
11396
|
let target = annotated;
|
|
11455
|
-
if (target.type ===
|
|
11456
|
-
if (target.type ===
|
|
11457
|
-
if (target.type !==
|
|
11397
|
+
if (target.type === import_utils66.AST_NODE_TYPES.TSParameterProperty) target = target.parameter;
|
|
11398
|
+
if (target.type === import_utils66.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
11399
|
+
if (target.type !== import_utils66.AST_NODE_TYPES.Identifier) return null;
|
|
11458
11400
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
11459
11401
|
if (reference === null) return null;
|
|
11460
11402
|
return { name: target.name, ...reference, fields: [] };
|
|
@@ -11466,11 +11408,11 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
11466
11408
|
if (members === null) return [];
|
|
11467
11409
|
const collaborators = [];
|
|
11468
11410
|
for (const property of pattern.properties) {
|
|
11469
|
-
if (property.type !==
|
|
11470
|
-
if (property.key.type !==
|
|
11411
|
+
if (property.type !== import_utils66.AST_NODE_TYPES.Property || property.computed) continue;
|
|
11412
|
+
if (property.key.type !== import_utils66.AST_NODE_TYPES.Identifier) continue;
|
|
11471
11413
|
const key = property.key.name;
|
|
11472
|
-
const bound = property.value.type ===
|
|
11473
|
-
if (bound.type !==
|
|
11414
|
+
const bound = property.value.type === import_utils66.AST_NODE_TYPES.AssignmentPattern ? property.value.left : property.value;
|
|
11415
|
+
if (bound.type !== import_utils66.AST_NODE_TYPES.Identifier) continue;
|
|
11474
11416
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
11475
11417
|
const reference = members.get(key);
|
|
11476
11418
|
if (reference === void 0) continue;
|
|
@@ -11479,21 +11421,21 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
11479
11421
|
return collaborators;
|
|
11480
11422
|
};
|
|
11481
11423
|
var bagMemberTypes = (annotation, declared) => {
|
|
11482
|
-
if (annotation.type ===
|
|
11424
|
+
if (annotation.type === import_utils66.AST_NODE_TYPES.TSTypeLiteral) {
|
|
11483
11425
|
return propertySignatureTypes(annotation.members);
|
|
11484
11426
|
}
|
|
11485
|
-
if (annotation.type !==
|
|
11427
|
+
if (annotation.type !== import_utils66.AST_NODE_TYPES.TSTypeReference || annotation.typeName.type !== import_utils66.AST_NODE_TYPES.Identifier) {
|
|
11486
11428
|
return null;
|
|
11487
11429
|
}
|
|
11488
11430
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
11489
11431
|
};
|
|
11490
11432
|
var isFrameworkWiring = (body2) => subtreeHas(body2, (node) => {
|
|
11491
|
-
if (node.type ===
|
|
11433
|
+
if (node.type === import_utils66.AST_NODE_TYPES.CallExpression) {
|
|
11492
11434
|
const { callee } = node;
|
|
11493
|
-
if (callee.type ===
|
|
11494
|
-
return callee.type ===
|
|
11435
|
+
if (callee.type === import_utils66.AST_NODE_TYPES.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
11436
|
+
return callee.type === import_utils66.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils66.AST_NODE_TYPES.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
11495
11437
|
}
|
|
11496
|
-
return node.type ===
|
|
11438
|
+
return node.type === import_utils66.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils66.AST_NODE_TYPES.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
11497
11439
|
});
|
|
11498
11440
|
var subtreeHas = (root, found) => {
|
|
11499
11441
|
let hit = false;
|
|
@@ -11520,19 +11462,19 @@ var invokedInstanceField = (call) => {
|
|
|
11520
11462
|
const direct = instanceField(call.callee);
|
|
11521
11463
|
if (direct !== null) return direct;
|
|
11522
11464
|
let callee = call.callee;
|
|
11523
|
-
while (callee.type ===
|
|
11524
|
-
return callee.type ===
|
|
11465
|
+
while (callee.type === import_utils66.AST_NODE_TYPES.ChainExpression || callee.type === import_utils66.AST_NODE_TYPES.TSAsExpression || callee.type === import_utils66.AST_NODE_TYPES.TSNonNullExpression || callee.type === import_utils66.AST_NODE_TYPES.TSSatisfiesExpression || callee.type === import_utils66.AST_NODE_TYPES.TSTypeAssertion) callee = callee.expression;
|
|
11466
|
+
return callee.type === import_utils66.AST_NODE_TYPES.MemberExpression ? instanceField(callee.object) : null;
|
|
11525
11467
|
};
|
|
11526
11468
|
var instanceField = (candidate) => {
|
|
11527
11469
|
let node = candidate;
|
|
11528
|
-
while (node.type ===
|
|
11529
|
-
return node.type ===
|
|
11470
|
+
while (node.type === import_utils66.AST_NODE_TYPES.ChainExpression || node.type === import_utils66.AST_NODE_TYPES.TSAsExpression || node.type === import_utils66.AST_NODE_TYPES.TSNonNullExpression || node.type === import_utils66.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils66.AST_NODE_TYPES.TSTypeAssertion) node = node.expression;
|
|
11471
|
+
return node.type === import_utils66.AST_NODE_TYPES.MemberExpression && node.object.type === import_utils66.AST_NODE_TYPES.ThisExpression ? staticMemberName4(node) : null;
|
|
11530
11472
|
};
|
|
11531
11473
|
var behaviorallyInvokedFields = (body2) => {
|
|
11532
11474
|
const invoked = /* @__PURE__ */ new Set();
|
|
11533
11475
|
const visit = (current) => {
|
|
11534
|
-
if (current.type ===
|
|
11535
|
-
if (current.type ===
|
|
11476
|
+
if (current.type === import_utils66.AST_NODE_TYPES.ClassDeclaration || current.type === import_utils66.AST_NODE_TYPES.ClassExpression || current.type === import_utils66.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils66.AST_NODE_TYPES.FunctionExpression) return;
|
|
11477
|
+
if (current.type === import_utils66.AST_NODE_TYPES.CallExpression) {
|
|
11536
11478
|
const field = invokedInstanceField(current);
|
|
11537
11479
|
if (field !== null) invoked.add(field);
|
|
11538
11480
|
}
|
|
@@ -11545,14 +11487,14 @@ var behaviorallyInvokedFields = (body2) => {
|
|
|
11545
11487
|
}
|
|
11546
11488
|
};
|
|
11547
11489
|
for (const member of body2.body) {
|
|
11548
|
-
if (member.type ===
|
|
11549
|
-
if (member.type ===
|
|
11490
|
+
if (member.type === import_utils66.AST_NODE_TYPES.StaticBlock || member.static) continue;
|
|
11491
|
+
if (member.type === import_utils66.AST_NODE_TYPES.MethodDefinition) {
|
|
11550
11492
|
if (member.value.body !== null && member.value.body !== void 0) visit(member.value.body);
|
|
11551
11493
|
continue;
|
|
11552
11494
|
}
|
|
11553
|
-
if (member.type !==
|
|
11495
|
+
if (member.type !== import_utils66.AST_NODE_TYPES.PropertyDefinition || member.value === null) continue;
|
|
11554
11496
|
visit(
|
|
11555
|
-
member.value.type ===
|
|
11497
|
+
member.value.type === import_utils66.AST_NODE_TYPES.ArrowFunctionExpression ? member.value.body : member.value
|
|
11556
11498
|
);
|
|
11557
11499
|
}
|
|
11558
11500
|
return invoked;
|
|
@@ -11572,25 +11514,25 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
11572
11514
|
var fileInterfaceNames = (program) => {
|
|
11573
11515
|
const names = [];
|
|
11574
11516
|
for (const statement of program.body) {
|
|
11575
|
-
const declaration = statement.type ===
|
|
11576
|
-
if (declaration?.type ===
|
|
11517
|
+
const declaration = statement.type === import_utils66.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
11518
|
+
if (declaration?.type === import_utils66.AST_NODE_TYPES.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
11577
11519
|
}
|
|
11578
11520
|
return names;
|
|
11579
11521
|
};
|
|
11580
11522
|
var publicMethodNames = (body2, functionAliases) => {
|
|
11581
11523
|
const names = [];
|
|
11582
11524
|
for (const member of body2.body) {
|
|
11583
|
-
if (member.type ===
|
|
11525
|
+
if (member.type === import_utils66.AST_NODE_TYPES.PropertyDefinition) {
|
|
11584
11526
|
if (member.static || member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
11585
|
-
if (member.value?.type !==
|
|
11586
|
-
names.push(member.key.type ===
|
|
11527
|
+
if (member.value?.type !== import_utils66.AST_NODE_TYPES.ArrowFunctionExpression && member.value?.type !== import_utils66.AST_NODE_TYPES.FunctionExpression && member.typeAnnotation?.typeAnnotation.type !== import_utils66.AST_NODE_TYPES.TSFunctionType && !(member.typeAnnotation?.typeAnnotation.type === import_utils66.AST_NODE_TYPES.TSTypeReference && member.typeAnnotation.typeAnnotation.typeName.type === import_utils66.AST_NODE_TYPES.Identifier && functionAliases.has(member.typeAnnotation.typeAnnotation.typeName.name))) continue;
|
|
11528
|
+
names.push(member.key.type === import_utils66.AST_NODE_TYPES.Identifier ? member.key.name : "\u2026");
|
|
11587
11529
|
continue;
|
|
11588
11530
|
}
|
|
11589
|
-
if (member.type !==
|
|
11531
|
+
if (member.type !== import_utils66.AST_NODE_TYPES.MethodDefinition) continue;
|
|
11590
11532
|
if (member.kind !== "method" || member.static) continue;
|
|
11591
11533
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
11592
|
-
if (member.key.type ===
|
|
11593
|
-
if (member.key.type ===
|
|
11534
|
+
if (member.key.type === import_utils66.AST_NODE_TYPES.PrivateIdentifier) continue;
|
|
11535
|
+
if (member.key.type === import_utils66.AST_NODE_TYPES.Identifier) names.push(member.key.name);
|
|
11594
11536
|
else names.push("\u2026");
|
|
11595
11537
|
}
|
|
11596
11538
|
return names;
|
|
@@ -11598,13 +11540,13 @@ var publicMethodNames = (body2, functionAliases) => {
|
|
|
11598
11540
|
var isFluentConstructionObject = (node, getText) => {
|
|
11599
11541
|
if (node.id === null) return false;
|
|
11600
11542
|
const methods = node.body.body.filter(
|
|
11601
|
-
(member) => member.type ===
|
|
11543
|
+
(member) => member.type === import_utils66.AST_NODE_TYPES.MethodDefinition && member.kind === "method" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.value.body !== null
|
|
11602
11544
|
);
|
|
11603
11545
|
if (methods.length === 0) return false;
|
|
11604
11546
|
return methods.every((member) => {
|
|
11605
11547
|
const result = member.value.returnType?.typeAnnotation;
|
|
11606
11548
|
if (result === void 0) return false;
|
|
11607
|
-
const returnsOwnType = result.type ===
|
|
11549
|
+
const returnsOwnType = result.type === import_utils66.AST_NODE_TYPES.TSTypeReference && result.typeName.type === import_utils66.AST_NODE_TYPES.Identifier && result.typeName.name === node.id?.name;
|
|
11608
11550
|
return returnsOwnType || FLUENT_BUILDER_NAME_RE.test(node.id?.name ?? "") && FLUENT_RESULT_TYPE_RE.test(getText(result));
|
|
11609
11551
|
});
|
|
11610
11552
|
};
|
|
@@ -11612,10 +11554,10 @@ function localClassAbstractness(program) {
|
|
|
11612
11554
|
const classes = /* @__PURE__ */ new Map();
|
|
11613
11555
|
const parents = /* @__PURE__ */ new Map();
|
|
11614
11556
|
for (const statement of program.body) {
|
|
11615
|
-
const declaration = statement.type ===
|
|
11616
|
-
if (declaration?.type ===
|
|
11557
|
+
const declaration = statement.type === import_utils66.AST_NODE_TYPES.ExportNamedDeclaration || statement.type === import_utils66.AST_NODE_TYPES.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
11558
|
+
if (declaration?.type === import_utils66.AST_NODE_TYPES.ClassDeclaration && declaration.id !== null) {
|
|
11617
11559
|
classes.set(declaration.id.name, declaration.abstract === true);
|
|
11618
|
-
if (declaration.superClass?.type ===
|
|
11560
|
+
if (declaration.superClass?.type === import_utils66.AST_NODE_TYPES.Identifier) {
|
|
11619
11561
|
parents.set(declaration.id.name, declaration.superClass.name);
|
|
11620
11562
|
}
|
|
11621
11563
|
}
|
|
@@ -11637,43 +11579,43 @@ function localInterfaceSurfaces(program) {
|
|
|
11637
11579
|
const parents = /* @__PURE__ */ new Map();
|
|
11638
11580
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
11639
11581
|
for (const statement of program.body) {
|
|
11640
|
-
const declaration = statement.type ===
|
|
11641
|
-
if (declaration?.type ===
|
|
11582
|
+
const declaration = statement.type === import_utils66.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
11583
|
+
if (declaration?.type === import_utils66.AST_NODE_TYPES.TSTypeAliasDeclaration && (declaration.typeAnnotation.type === import_utils66.AST_NODE_TYPES.TSFunctionType || declaration.typeAnnotation.type === import_utils66.AST_NODE_TYPES.TSConstructorType)) functionAliases.add(declaration.id.name);
|
|
11642
11584
|
}
|
|
11643
11585
|
for (const statement of program.body) {
|
|
11644
|
-
const declaration = statement.type ===
|
|
11645
|
-
if (declaration?.type ===
|
|
11586
|
+
const declaration = statement.type === import_utils66.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
11587
|
+
if (declaration?.type === import_utils66.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
11646
11588
|
const callables2 = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
11647
|
-
const parts = declaration.typeAnnotation.type ===
|
|
11589
|
+
const parts = declaration.typeAnnotation.type === import_utils66.AST_NODE_TYPES.TSIntersectionType ? declaration.typeAnnotation.types : [declaration.typeAnnotation];
|
|
11648
11590
|
const inherited = parents.get(declaration.id.name) ?? [];
|
|
11649
11591
|
for (const part of parts) {
|
|
11650
|
-
if (part.type ===
|
|
11592
|
+
if (part.type === import_utils66.AST_NODE_TYPES.TSTypeReference && part.typeName.type === import_utils66.AST_NODE_TYPES.Identifier) {
|
|
11651
11593
|
inherited.push(part.typeName.name);
|
|
11652
11594
|
continue;
|
|
11653
11595
|
}
|
|
11654
|
-
if (part.type !==
|
|
11596
|
+
if (part.type !== import_utils66.AST_NODE_TYPES.TSTypeLiteral) continue;
|
|
11655
11597
|
for (const member of part.members) {
|
|
11656
|
-
if (member.type !==
|
|
11657
|
-
if (member.computed || member.key.type !==
|
|
11658
|
-
if (member.type ===
|
|
11598
|
+
if (member.type !== import_utils66.AST_NODE_TYPES.TSMethodSignature && member.type !== import_utils66.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
11599
|
+
if (member.computed || member.key.type !== import_utils66.AST_NODE_TYPES.Identifier) continue;
|
|
11600
|
+
if (member.type === import_utils66.AST_NODE_TYPES.TSMethodSignature) {
|
|
11659
11601
|
callables2.add(member.key.name);
|
|
11660
11602
|
continue;
|
|
11661
11603
|
}
|
|
11662
|
-
if (member.type !==
|
|
11604
|
+
if (member.type !== import_utils66.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
11663
11605
|
const annotation = member.typeAnnotation?.typeAnnotation;
|
|
11664
|
-
if (annotation?.type ===
|
|
11606
|
+
if (annotation?.type === import_utils66.AST_NODE_TYPES.TSFunctionType || annotation?.type === import_utils66.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils66.AST_NODE_TYPES.Identifier && functionAliases.has(annotation.typeName.name)) callables2.add(member.key.name);
|
|
11665
11607
|
}
|
|
11666
11608
|
}
|
|
11667
11609
|
interfaces.set(declaration.id.name, callables2);
|
|
11668
11610
|
parents.set(declaration.id.name, inherited);
|
|
11669
11611
|
continue;
|
|
11670
11612
|
}
|
|
11671
|
-
if (declaration?.type !==
|
|
11613
|
+
if (declaration?.type !== import_utils66.AST_NODE_TYPES.TSInterfaceDeclaration) continue;
|
|
11672
11614
|
const callables = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
11673
11615
|
for (const member of declaration.body.body) {
|
|
11674
|
-
if (member.type !==
|
|
11675
|
-
if (member.computed || member.key.type !==
|
|
11676
|
-
if (member.type ===
|
|
11616
|
+
if (member.type !== import_utils66.AST_NODE_TYPES.TSMethodSignature && member.type !== import_utils66.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
11617
|
+
if (member.computed || member.key.type !== import_utils66.AST_NODE_TYPES.Identifier) continue;
|
|
11618
|
+
if (member.type === import_utils66.AST_NODE_TYPES.TSMethodSignature || member.typeAnnotation?.typeAnnotation.type === import_utils66.AST_NODE_TYPES.TSFunctionType || member.typeAnnotation?.typeAnnotation.type === import_utils66.AST_NODE_TYPES.TSTypeReference && member.typeAnnotation.typeAnnotation.typeName.type === import_utils66.AST_NODE_TYPES.Identifier && functionAliases.has(member.typeAnnotation.typeAnnotation.typeName.name)) callables.add(member.key.name);
|
|
11677
11619
|
}
|
|
11678
11620
|
interfaces.set(declaration.id.name, callables);
|
|
11679
11621
|
parents.set(
|
|
@@ -11681,7 +11623,7 @@ function localInterfaceSurfaces(program) {
|
|
|
11681
11623
|
[
|
|
11682
11624
|
...parents.get(declaration.id.name) ?? [],
|
|
11683
11625
|
...declaration.extends.flatMap(
|
|
11684
|
-
(heritage) => heritage.expression.type ===
|
|
11626
|
+
(heritage) => heritage.expression.type === import_utils66.AST_NODE_TYPES.Identifier ? [heritage.expression.name] : ["*"]
|
|
11685
11627
|
)
|
|
11686
11628
|
]
|
|
11687
11629
|
);
|
|
@@ -11708,7 +11650,7 @@ function localInterfaceSurfaces(program) {
|
|
|
11708
11650
|
}
|
|
11709
11651
|
function hasServicePort(node, methods, classes, interfaces) {
|
|
11710
11652
|
if (node.superClass !== null) {
|
|
11711
|
-
if (node.superClass.type !==
|
|
11653
|
+
if (node.superClass.type !== import_utils66.AST_NODE_TYPES.Identifier) return true;
|
|
11712
11654
|
const localAbstract = classes.get(node.superClass.name);
|
|
11713
11655
|
if (localAbstract === void 0 || localAbstract) return true;
|
|
11714
11656
|
}
|
|
@@ -11720,7 +11662,7 @@ function hasServicePort(node, methods, classes, interfaces) {
|
|
|
11720
11662
|
if (node.implements.length === 0) return false;
|
|
11721
11663
|
const combined = /* @__PURE__ */ new Set();
|
|
11722
11664
|
for (const implementation of node.implements) {
|
|
11723
|
-
if (implementation.expression.type !==
|
|
11665
|
+
if (implementation.expression.type !== import_utils66.AST_NODE_TYPES.Identifier) return true;
|
|
11724
11666
|
const name = implementation.expression.name;
|
|
11725
11667
|
const localAbstract = classes.get(name);
|
|
11726
11668
|
if (localAbstract === true) return true;
|
|
@@ -11762,7 +11704,7 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
11762
11704
|
if (node.abstract === true) return;
|
|
11763
11705
|
if (node.decorators.length > 0) return;
|
|
11764
11706
|
const ctor = node.body.body.find(
|
|
11765
|
-
(member) => member.type ===
|
|
11707
|
+
(member) => member.type === import_utils66.AST_NODE_TYPES.MethodDefinition && member.kind === "constructor" && member.value.body !== null && member.value.body !== void 0
|
|
11766
11708
|
);
|
|
11767
11709
|
if (ctor === void 0) return;
|
|
11768
11710
|
const constructorFacts = readConstructor(
|
|
@@ -11797,37 +11739,37 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
11797
11739
|
});
|
|
11798
11740
|
|
|
11799
11741
|
// src/rules/require-static-next-matcher.ts
|
|
11800
|
-
var
|
|
11742
|
+
var import_utils67 = require("@typescript-eslint/utils");
|
|
11801
11743
|
var NEXT_ENTRY_FILE = /(?:^|[/\\])(?:middleware|proxy)\.[cm]?[jt]sx?$/u;
|
|
11802
11744
|
function unwrapExpression3(node) {
|
|
11803
|
-
if (node.type ===
|
|
11745
|
+
if (node.type === import_utils67.AST_NODE_TYPES.TSAsExpression || node.type === import_utils67.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils67.AST_NODE_TYPES.TSNonNullExpression || node.type === import_utils67.AST_NODE_TYPES.TSTypeAssertion) {
|
|
11804
11746
|
return unwrapExpression3(node.expression);
|
|
11805
11747
|
}
|
|
11806
11748
|
return node;
|
|
11807
11749
|
}
|
|
11808
11750
|
function isStaticValue(node) {
|
|
11809
11751
|
const value = unwrapExpression3(node);
|
|
11810
|
-
if (value.type ===
|
|
11752
|
+
if (value.type === import_utils67.AST_NODE_TYPES.Literal) {
|
|
11811
11753
|
return true;
|
|
11812
11754
|
}
|
|
11813
|
-
if (value.type ===
|
|
11755
|
+
if (value.type === import_utils67.AST_NODE_TYPES.TemplateLiteral) {
|
|
11814
11756
|
return value.expressions.length === 0;
|
|
11815
11757
|
}
|
|
11816
|
-
if (value.type ===
|
|
11758
|
+
if (value.type === import_utils67.AST_NODE_TYPES.ArrayExpression) {
|
|
11817
11759
|
return value.elements.every(
|
|
11818
|
-
(element) => element !== null && element.type !==
|
|
11760
|
+
(element) => element !== null && element.type !== import_utils67.AST_NODE_TYPES.SpreadElement && isStaticValue(element)
|
|
11819
11761
|
);
|
|
11820
11762
|
}
|
|
11821
|
-
if (value.type ===
|
|
11763
|
+
if (value.type === import_utils67.AST_NODE_TYPES.ObjectExpression) {
|
|
11822
11764
|
return value.properties.every(
|
|
11823
|
-
(property) => property.type ===
|
|
11765
|
+
(property) => property.type === import_utils67.AST_NODE_TYPES.Property && property.kind === "init" && !property.computed && property.value.type !== import_utils67.AST_NODE_TYPES.AssignmentPattern && isStaticValue(property.value)
|
|
11824
11766
|
);
|
|
11825
11767
|
}
|
|
11826
11768
|
return false;
|
|
11827
11769
|
}
|
|
11828
11770
|
function propertyName2(property) {
|
|
11829
11771
|
if (property.computed) return null;
|
|
11830
|
-
if (property.key.type ===
|
|
11772
|
+
if (property.key.type === import_utils67.AST_NODE_TYPES.Identifier) return property.key.name;
|
|
11831
11773
|
return typeof property.key.value === "string" ? property.key.value : null;
|
|
11832
11774
|
}
|
|
11833
11775
|
var require_static_next_matcher_default = createRule({
|
|
@@ -11849,19 +11791,19 @@ var require_static_next_matcher_default = createRule({
|
|
|
11849
11791
|
}
|
|
11850
11792
|
return {
|
|
11851
11793
|
ExportNamedDeclaration(node) {
|
|
11852
|
-
if (node.declaration?.type !==
|
|
11794
|
+
if (node.declaration?.type !== import_utils67.AST_NODE_TYPES.VariableDeclaration) {
|
|
11853
11795
|
return;
|
|
11854
11796
|
}
|
|
11855
11797
|
for (const declaration of node.declaration.declarations) {
|
|
11856
|
-
if (declaration.id.type !==
|
|
11798
|
+
if (declaration.id.type !== import_utils67.AST_NODE_TYPES.Identifier || declaration.id.name !== "config" || declaration.init === null) {
|
|
11857
11799
|
continue;
|
|
11858
11800
|
}
|
|
11859
11801
|
const config = unwrapExpression3(declaration.init);
|
|
11860
|
-
if (config.type !==
|
|
11802
|
+
if (config.type !== import_utils67.AST_NODE_TYPES.ObjectExpression) {
|
|
11861
11803
|
continue;
|
|
11862
11804
|
}
|
|
11863
11805
|
for (const property of config.properties) {
|
|
11864
|
-
if (property.type !==
|
|
11806
|
+
if (property.type !== import_utils67.AST_NODE_TYPES.Property || propertyName2(property) !== "matcher" || property.value.type === import_utils67.AST_NODE_TYPES.AssignmentPattern) {
|
|
11865
11807
|
continue;
|
|
11866
11808
|
}
|
|
11867
11809
|
if (!isStaticValue(property.value)) {
|
|
@@ -11875,28 +11817,30 @@ var require_static_next_matcher_default = createRule({
|
|
|
11875
11817
|
});
|
|
11876
11818
|
|
|
11877
11819
|
// src/rules/require-zod-form-validation.ts
|
|
11878
|
-
var
|
|
11820
|
+
var import_utils68 = require("@typescript-eslint/utils");
|
|
11879
11821
|
var isZodParseCall = (node) => {
|
|
11880
|
-
if (node.type !==
|
|
11822
|
+
if (node.type !== import_utils68.AST_NODE_TYPES.CallExpression) return false;
|
|
11881
11823
|
const callee = node.callee;
|
|
11882
|
-
if (callee.type !==
|
|
11824
|
+
if (callee.type !== import_utils68.AST_NODE_TYPES.MemberExpression) return false;
|
|
11883
11825
|
if (callee.computed) return false;
|
|
11884
|
-
if (callee.property.type !==
|
|
11826
|
+
if (callee.property.type !== import_utils68.AST_NODE_TYPES.Identifier) return false;
|
|
11885
11827
|
const method = callee.property.name;
|
|
11886
|
-
if (method !== "parse" && method !== "safeParse")
|
|
11828
|
+
if (method !== "parse" && method !== "safeParse" && method !== "parseAsync" && method !== "safeParseAsync") {
|
|
11829
|
+
return false;
|
|
11830
|
+
}
|
|
11887
11831
|
return looksLikeZodSchema(callee.object);
|
|
11888
11832
|
};
|
|
11889
11833
|
var looksLikeZodSchema = (node) => {
|
|
11890
11834
|
let current = node;
|
|
11891
11835
|
while (true) {
|
|
11892
|
-
if (current.type ===
|
|
11836
|
+
if (current.type === import_utils68.AST_NODE_TYPES.Identifier) {
|
|
11893
11837
|
return current.name === "z" || ZOD_SCHEMA_NAME_RE.test(current.name);
|
|
11894
11838
|
}
|
|
11895
|
-
if (current.type ===
|
|
11839
|
+
if (current.type === import_utils68.AST_NODE_TYPES.CallExpression) {
|
|
11896
11840
|
current = current.callee;
|
|
11897
11841
|
continue;
|
|
11898
11842
|
}
|
|
11899
|
-
if (current.type ===
|
|
11843
|
+
if (current.type === import_utils68.AST_NODE_TYPES.MemberExpression) {
|
|
11900
11844
|
current = current.object;
|
|
11901
11845
|
continue;
|
|
11902
11846
|
}
|
|
@@ -11905,12 +11849,12 @@ var looksLikeZodSchema = (node) => {
|
|
|
11905
11849
|
};
|
|
11906
11850
|
var isFormDataMethodCall = (node) => {
|
|
11907
11851
|
let current = node;
|
|
11908
|
-
if (current.type ===
|
|
11852
|
+
if (current.type === import_utils68.AST_NODE_TYPES.AwaitExpression) {
|
|
11909
11853
|
current = current.argument;
|
|
11910
11854
|
}
|
|
11911
|
-
if (current.type !==
|
|
11855
|
+
if (current.type !== import_utils68.AST_NODE_TYPES.CallExpression) return false;
|
|
11912
11856
|
const callee = current.callee;
|
|
11913
|
-
return callee.type ===
|
|
11857
|
+
return callee.type === import_utils68.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils68.AST_NODE_TYPES.Identifier && callee.property.name === "formData";
|
|
11914
11858
|
};
|
|
11915
11859
|
var require_zod_form_validation_default = createRule({
|
|
11916
11860
|
name: "require-zod-form-validation",
|
|
@@ -11930,14 +11874,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
11930
11874
|
return {};
|
|
11931
11875
|
}
|
|
11932
11876
|
const isFormSourceIdentifier = (node) => {
|
|
11933
|
-
if (node.type !==
|
|
11877
|
+
if (node.type !== import_utils68.AST_NODE_TYPES.Identifier) return false;
|
|
11934
11878
|
if (/formdata/i.test(node.name)) return true;
|
|
11935
11879
|
let scope = context.sourceCode.getScope(node);
|
|
11936
11880
|
while (scope !== null) {
|
|
11937
11881
|
const variable = scope.set.get(node.name);
|
|
11938
11882
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
11939
11883
|
const def = variable.defs[0];
|
|
11940
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
11884
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === import_utils68.AST_NODE_TYPES.VariableDeclarator && def.node.init !== null) {
|
|
11941
11885
|
return isFormDataMethodCall(def.node.init);
|
|
11942
11886
|
}
|
|
11943
11887
|
return false;
|
|
@@ -11948,8 +11892,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
11948
11892
|
};
|
|
11949
11893
|
const isFormDataGetCall = (node) => {
|
|
11950
11894
|
const callee = node.callee;
|
|
11951
|
-
if (callee.type !==
|
|
11952
|
-
if (callee.property.type !==
|
|
11895
|
+
if (callee.type !== import_utils68.AST_NODE_TYPES.MemberExpression) return false;
|
|
11896
|
+
if (callee.property.type !== import_utils68.AST_NODE_TYPES.Identifier || callee.property.name !== "get") {
|
|
11953
11897
|
return false;
|
|
11954
11898
|
}
|
|
11955
11899
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -11964,11 +11908,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
11964
11908
|
};
|
|
11965
11909
|
const isInstanceofNarrowing = (node) => {
|
|
11966
11910
|
const parent = node.parent;
|
|
11967
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
11911
|
+
return parent !== null && parent !== void 0 && parent.type === import_utils68.AST_NODE_TYPES.BinaryExpression && parent.operator === "instanceof" && parent.left === node && parent.right.type === import_utils68.AST_NODE_TYPES.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
11968
11912
|
};
|
|
11969
11913
|
const boundDeclarator = (node) => {
|
|
11970
|
-
|
|
11971
|
-
|
|
11914
|
+
let current = node;
|
|
11915
|
+
let parent = current.parent;
|
|
11916
|
+
while ((parent.type === import_utils68.AST_NODE_TYPES.TSAsExpression || parent.type === import_utils68.AST_NODE_TYPES.TSSatisfiesExpression || parent.type === import_utils68.AST_NODE_TYPES.TSNonNullExpression || parent.type === import_utils68.AST_NODE_TYPES.ChainExpression) && parent.expression === current) {
|
|
11917
|
+
current = parent;
|
|
11918
|
+
parent = current.parent;
|
|
11919
|
+
}
|
|
11920
|
+
if (parent.type === import_utils68.AST_NODE_TYPES.VariableDeclarator && parent.init === current && parent.id.type === import_utils68.AST_NODE_TYPES.Identifier) {
|
|
11972
11921
|
return parent;
|
|
11973
11922
|
}
|
|
11974
11923
|
return null;
|
|
@@ -11996,7 +11945,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
11996
11945
|
});
|
|
11997
11946
|
|
|
11998
11947
|
// src/rules/store-insert-requires-on-conflict.ts
|
|
11999
|
-
var
|
|
11948
|
+
var import_utils69 = require("@typescript-eslint/utils");
|
|
12000
11949
|
var INSERT_WRITE = /\bINSERT\s+(?:OR\s+\w+\s+)?INTO\s+[\w."'`?$:@-]+\s*(?:\([^)]*\)\s*)?(?:VALUES|SELECT|DEFAULT\s+VALUES)\b/i;
|
|
12001
11950
|
var CONFLICT_HANDLED = /\bON\s+CONFLICT\b|\bON\s+DUPLICATE\s+KEY\b|\bINSERT\s+OR\s+(?:IGNORE|REPLACE)\b/i;
|
|
12002
11951
|
var INSERT_GATE = /insert/i;
|
|
@@ -12027,9 +11976,9 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
12027
11976
|
});
|
|
12028
11977
|
|
|
12029
11978
|
// src/rules/stepdown.ts
|
|
12030
|
-
var
|
|
11979
|
+
var import_utils70 = require("@typescript-eslint/utils");
|
|
12031
11980
|
function isFunction(node) {
|
|
12032
|
-
return node.type ===
|
|
11981
|
+
return node.type === import_utils70.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils70.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils70.AST_NODE_TYPES.FunctionExpression;
|
|
12033
11982
|
}
|
|
12034
11983
|
function reportMisordered(context, candidates, scopeDefinitions, calls, pinned) {
|
|
12035
11984
|
const byName = new Map(scopeDefinitions.map((definition) => [definition.name, definition]));
|
|
@@ -12124,8 +12073,8 @@ function moduleScope(context, program) {
|
|
|
12124
12073
|
for (const node of declarations) counts.set(node.name, (counts.get(node.name) ?? 0) + 1);
|
|
12125
12074
|
const overloadNames = new Set(
|
|
12126
12075
|
program.body.flatMap((statement) => {
|
|
12127
|
-
const node = statement.type ===
|
|
12128
|
-
return node?.type ===
|
|
12076
|
+
const node = statement.type === import_utils70.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
12077
|
+
return node?.type === import_utils70.AST_NODE_TYPES.TSDeclareFunction && node.id !== null ? [node.id.name] : [];
|
|
12129
12078
|
})
|
|
12130
12079
|
);
|
|
12131
12080
|
const exported = exportedNames(program);
|
|
@@ -12147,7 +12096,7 @@ function moduleScope(context, program) {
|
|
|
12147
12096
|
const nearestFunction = [...ancestors].reverse().find(isFunction);
|
|
12148
12097
|
const parent = identifier.parent;
|
|
12149
12098
|
const callerDefinition = nearestFunction === void 0 ? void 0 : byFunction.get(nearestFunction);
|
|
12150
|
-
if (callerDefinition === void 0 || parent.type !==
|
|
12099
|
+
if (callerDefinition === void 0 || parent.type !== import_utils70.AST_NODE_TYPES.CallExpression || parent.callee !== identifier) {
|
|
12151
12100
|
pinned.add(definition.name);
|
|
12152
12101
|
continue;
|
|
12153
12102
|
}
|
|
@@ -12162,38 +12111,38 @@ function moduleScope(context, program) {
|
|
|
12162
12111
|
function exportedNames(program) {
|
|
12163
12112
|
const names = /* @__PURE__ */ new Set();
|
|
12164
12113
|
for (const statement of program.body) {
|
|
12165
|
-
if (statement.type !==
|
|
12166
|
-
if (statement.declaration?.type ===
|
|
12114
|
+
if (statement.type !== import_utils70.AST_NODE_TYPES.ExportNamedDeclaration || statement.exportKind === "type" || statement.source !== null) continue;
|
|
12115
|
+
if (statement.declaration?.type === import_utils70.AST_NODE_TYPES.FunctionDeclaration && statement.declaration.id !== null) {
|
|
12167
12116
|
names.add(statement.declaration.id.name);
|
|
12168
12117
|
}
|
|
12169
|
-
if (statement.declaration?.type ===
|
|
12118
|
+
if (statement.declaration?.type === import_utils70.AST_NODE_TYPES.VariableDeclaration) {
|
|
12170
12119
|
for (const declarator of statement.declaration.declarations) {
|
|
12171
|
-
if (declarator.id.type ===
|
|
12120
|
+
if (declarator.id.type === import_utils70.AST_NODE_TYPES.Identifier) names.add(declarator.id.name);
|
|
12172
12121
|
}
|
|
12173
12122
|
}
|
|
12174
12123
|
for (const specifier of statement.specifiers) {
|
|
12175
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
12124
|
+
if (specifier.exportKind !== "type" && specifier.local.type === import_utils70.AST_NODE_TYPES.Identifier) {
|
|
12176
12125
|
names.add(specifier.local.name);
|
|
12177
12126
|
}
|
|
12178
12127
|
}
|
|
12179
12128
|
}
|
|
12180
12129
|
for (const statement of program.body) {
|
|
12181
|
-
if (statement.type ===
|
|
12182
|
-
if (statement.type ===
|
|
12130
|
+
if (statement.type === import_utils70.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils70.AST_NODE_TYPES.Identifier) names.add(statement.declaration.name);
|
|
12131
|
+
if (statement.type === import_utils70.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils70.AST_NODE_TYPES.FunctionDeclaration && statement.declaration.id !== null) names.add(statement.declaration.id.name);
|
|
12183
12132
|
}
|
|
12184
12133
|
return names;
|
|
12185
12134
|
}
|
|
12186
12135
|
function moduleDefinitions(program) {
|
|
12187
12136
|
const definitions = [];
|
|
12188
12137
|
for (const statement of program.body) {
|
|
12189
|
-
const node = statement.type ===
|
|
12190
|
-
if (node?.type ===
|
|
12138
|
+
const node = statement.type === import_utils70.AST_NODE_TYPES.ExportNamedDeclaration || statement.type === import_utils70.AST_NODE_TYPES.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
12139
|
+
if (node?.type === import_utils70.AST_NODE_TYPES.FunctionDeclaration && node.id !== null && node.body !== null) {
|
|
12191
12140
|
definitions.push({ name: node.id.name, node, functionNode: node, bindingNode: node });
|
|
12192
12141
|
continue;
|
|
12193
12142
|
}
|
|
12194
|
-
if (node?.type !==
|
|
12143
|
+
if (node?.type !== import_utils70.AST_NODE_TYPES.VariableDeclaration || node.kind !== "const") continue;
|
|
12195
12144
|
for (const declarator of node.declarations) {
|
|
12196
|
-
if (declarator.id.type ===
|
|
12145
|
+
if (declarator.id.type === import_utils70.AST_NODE_TYPES.Identifier && declarator.init !== null && isFunction(declarator.init)) {
|
|
12197
12146
|
definitions.push({
|
|
12198
12147
|
name: declarator.id.name,
|
|
12199
12148
|
node: declarator,
|
|
@@ -12206,21 +12155,21 @@ function moduleDefinitions(program) {
|
|
|
12206
12155
|
return definitions;
|
|
12207
12156
|
}
|
|
12208
12157
|
function methodName(node) {
|
|
12209
|
-
if (node.key.type ===
|
|
12210
|
-
return !node.computed && node.key.type ===
|
|
12158
|
+
if (node.key.type === import_utils70.AST_NODE_TYPES.PrivateIdentifier) return `#${node.key.name}`;
|
|
12159
|
+
return !node.computed && node.key.type === import_utils70.AST_NODE_TYPES.Identifier ? node.key.name : null;
|
|
12211
12160
|
}
|
|
12212
12161
|
function referencedMethod(context, node, classVariables) {
|
|
12213
|
-
const objectVariable = node.object.type ===
|
|
12162
|
+
const objectVariable = node.object.type === import_utils70.AST_NODE_TYPES.Identifier ? import_utils70.ASTUtils.findVariable(context.sourceCode.getScope(node.object), node.object.name) : null;
|
|
12214
12163
|
const isClassReference = objectVariable !== null && classVariables.has(objectVariable);
|
|
12215
|
-
if (node.object.type !==
|
|
12216
|
-
if (node.property.type ===
|
|
12217
|
-
if (!node.computed && node.property.type ===
|
|
12218
|
-
return node.computed && node.property.type ===
|
|
12164
|
+
if (node.object.type !== import_utils70.AST_NODE_TYPES.ThisExpression && !isClassReference) return null;
|
|
12165
|
+
if (node.property.type === import_utils70.AST_NODE_TYPES.PrivateIdentifier) return `#${node.property.name}`;
|
|
12166
|
+
if (!node.computed && node.property.type === import_utils70.AST_NODE_TYPES.Identifier) return node.property.name;
|
|
12167
|
+
return node.computed && node.property.type === import_utils70.AST_NODE_TYPES.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
12219
12168
|
}
|
|
12220
12169
|
function referencedPropertyName(node) {
|
|
12221
|
-
if (node.property.type ===
|
|
12222
|
-
if (!node.computed && node.property.type ===
|
|
12223
|
-
return node.computed && node.property.type ===
|
|
12170
|
+
if (node.property.type === import_utils70.AST_NODE_TYPES.PrivateIdentifier) return `#${node.property.name}`;
|
|
12171
|
+
if (!node.computed && node.property.type === import_utils70.AST_NODE_TYPES.Identifier) return node.property.name;
|
|
12172
|
+
return node.computed && node.property.type === import_utils70.AST_NODE_TYPES.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
12224
12173
|
}
|
|
12225
12174
|
function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
12226
12175
|
visit(node, nestedFunction);
|
|
@@ -12236,7 +12185,7 @@ function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
|
12236
12185
|
}
|
|
12237
12186
|
function classScope(context, node, computedReferenceNames) {
|
|
12238
12187
|
const methods = node.body.body.filter(
|
|
12239
|
-
(member) => member.type ===
|
|
12188
|
+
(member) => member.type === import_utils70.AST_NODE_TYPES.MethodDefinition
|
|
12240
12189
|
);
|
|
12241
12190
|
const counts = /* @__PURE__ */ new Map();
|
|
12242
12191
|
for (const method of methods) {
|
|
@@ -12244,8 +12193,8 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
12244
12193
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
12245
12194
|
}
|
|
12246
12195
|
for (const member of node.body.body) {
|
|
12247
|
-
if (member.type !==
|
|
12248
|
-
const name = !member.computed && member.key.type ===
|
|
12196
|
+
if (member.type !== import_utils70.AST_NODE_TYPES.TSAbstractMethodDefinition) continue;
|
|
12197
|
+
const name = !member.computed && member.key.type === import_utils70.AST_NODE_TYPES.Identifier ? member.key.name : null;
|
|
12249
12198
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
12250
12199
|
}
|
|
12251
12200
|
const scopeDefinitions = methods.flatMap((method) => {
|
|
@@ -12254,7 +12203,7 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
12254
12203
|
});
|
|
12255
12204
|
const definitions = methods.flatMap((method) => {
|
|
12256
12205
|
const name = methodName(method);
|
|
12257
|
-
const isPrivate = method.accessibility === "private" || method.key.type ===
|
|
12206
|
+
const isPrivate = method.accessibility === "private" || method.key.type === import_utils70.AST_NODE_TYPES.PrivateIdentifier;
|
|
12258
12207
|
return name !== null && isPrivate && counts.get(name) === 1 && method.decorators.length === 0 ? [{ name, node: method }] : [];
|
|
12259
12208
|
});
|
|
12260
12209
|
if (definitions.length === 0) return;
|
|
@@ -12263,11 +12212,11 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
12263
12212
|
const pinned = /* @__PURE__ */ new Set();
|
|
12264
12213
|
const classVariables = /* @__PURE__ */ new Set();
|
|
12265
12214
|
if (node.id !== null) {
|
|
12266
|
-
const internal =
|
|
12215
|
+
const internal = import_utils70.ASTUtils.findVariable(context.sourceCode.getScope(node), node.id.name);
|
|
12267
12216
|
if (internal !== null) classVariables.add(internal);
|
|
12268
12217
|
}
|
|
12269
|
-
if (node.type ===
|
|
12270
|
-
const outer =
|
|
12218
|
+
if (node.type === import_utils70.AST_NODE_TYPES.ClassExpression && node.parent.type === import_utils70.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === import_utils70.AST_NODE_TYPES.Identifier) {
|
|
12219
|
+
const outer = import_utils70.ASTUtils.findVariable(context.sourceCode.getScope(node.parent), node.parent.id.name);
|
|
12271
12220
|
if (outer !== null) classVariables.add(outer);
|
|
12272
12221
|
}
|
|
12273
12222
|
for (const method of methods) {
|
|
@@ -12283,27 +12232,27 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
12283
12232
|
}
|
|
12284
12233
|
const thisValue = (value) => {
|
|
12285
12234
|
let current = value;
|
|
12286
|
-
while (current?.type ===
|
|
12287
|
-
return current?.type ===
|
|
12235
|
+
while (current?.type === import_utils70.AST_NODE_TYPES.TSAsExpression || current?.type === import_utils70.AST_NODE_TYPES.TSSatisfiesExpression || current?.type === import_utils70.AST_NODE_TYPES.TSNonNullExpression) current = current.expression;
|
|
12236
|
+
return current?.type === import_utils70.AST_NODE_TYPES.ThisExpression;
|
|
12288
12237
|
};
|
|
12289
12238
|
const collectAlias = (current, nestedFunction) => {
|
|
12290
|
-
if (nestedFunction || current.type !==
|
|
12291
|
-
if (current.type ===
|
|
12292
|
-
const binding = current.type ===
|
|
12293
|
-
const value = current.type ===
|
|
12239
|
+
if (nestedFunction || current.type !== import_utils70.AST_NODE_TYPES.VariableDeclarator && current.type !== import_utils70.AST_NODE_TYPES.AssignmentPattern) return;
|
|
12240
|
+
if (current.type === import_utils70.AST_NODE_TYPES.VariableDeclarator && (current.parent.type !== import_utils70.AST_NODE_TYPES.VariableDeclaration || current.parent.kind !== "const")) return;
|
|
12241
|
+
const binding = current.type === import_utils70.AST_NODE_TYPES.VariableDeclarator ? current.id : current.left;
|
|
12242
|
+
const value = current.type === import_utils70.AST_NODE_TYPES.VariableDeclarator ? current.init : current.right;
|
|
12294
12243
|
if (!thisValue(value)) return;
|
|
12295
|
-
if (binding.type ===
|
|
12244
|
+
if (binding.type === import_utils70.AST_NODE_TYPES.ObjectPattern) {
|
|
12296
12245
|
for (const property of binding.properties) {
|
|
12297
|
-
if (property.type ===
|
|
12246
|
+
if (property.type === import_utils70.AST_NODE_TYPES.RestElement) {
|
|
12298
12247
|
for (const name of privateNames) pinned.add(name);
|
|
12299
|
-
} else if (property.key.type ===
|
|
12248
|
+
} else if (property.key.type === import_utils70.AST_NODE_TYPES.Identifier && privateNames.has(property.key.name)) {
|
|
12300
12249
|
pinned.add(property.key.name);
|
|
12301
12250
|
}
|
|
12302
12251
|
}
|
|
12303
12252
|
return;
|
|
12304
12253
|
}
|
|
12305
|
-
if (binding.type !==
|
|
12306
|
-
const variable =
|
|
12254
|
+
if (binding.type !== import_utils70.AST_NODE_TYPES.Identifier) return;
|
|
12255
|
+
const variable = import_utils70.ASTUtils.findVariable(context.sourceCode.getScope(binding), binding.name);
|
|
12307
12256
|
if (variable !== null) {
|
|
12308
12257
|
methodClassVariables.add(variable);
|
|
12309
12258
|
methodAliases.add(variable);
|
|
@@ -12316,16 +12265,16 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
12316
12265
|
walk(statement, context.sourceCode.visitorKeys, collectAlias);
|
|
12317
12266
|
}
|
|
12318
12267
|
const visitCall = (current, nestedFunction) => {
|
|
12319
|
-
if (current.type ===
|
|
12268
|
+
if (current.type === import_utils70.AST_NODE_TYPES.VariableDeclarator && current.id.type === import_utils70.AST_NODE_TYPES.ObjectPattern && thisValue(current.init)) {
|
|
12320
12269
|
for (const property of current.id.properties) {
|
|
12321
|
-
if (property.type ===
|
|
12270
|
+
if (property.type === import_utils70.AST_NODE_TYPES.RestElement) {
|
|
12322
12271
|
for (const name of privateNames) pinned.add(name);
|
|
12323
12272
|
continue;
|
|
12324
12273
|
}
|
|
12325
|
-
if (property.type ===
|
|
12274
|
+
if (property.type === import_utils70.AST_NODE_TYPES.Property && property.key.type === import_utils70.AST_NODE_TYPES.Identifier && privateNames.has(property.key.name)) pinned.add(property.key.name);
|
|
12326
12275
|
}
|
|
12327
12276
|
}
|
|
12328
|
-
if (current.type !==
|
|
12277
|
+
if (current.type !== import_utils70.AST_NODE_TYPES.MemberExpression) return;
|
|
12329
12278
|
const target = referencedMethod(context, current, methodClassVariables);
|
|
12330
12279
|
if (target === null) {
|
|
12331
12280
|
const possibleTarget = referencedPropertyName(current);
|
|
@@ -12333,12 +12282,12 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
12333
12282
|
return;
|
|
12334
12283
|
}
|
|
12335
12284
|
if (!privateNames.has(target)) return;
|
|
12336
|
-
const objectVariable = current.object.type ===
|
|
12285
|
+
const objectVariable = current.object.type === import_utils70.AST_NODE_TYPES.Identifier ? import_utils70.ASTUtils.findVariable(context.sourceCode.getScope(current.object), current.object.name) : null;
|
|
12337
12286
|
if (objectVariable !== null && methodAliases.has(objectVariable)) {
|
|
12338
12287
|
pinned.add(target);
|
|
12339
12288
|
return;
|
|
12340
12289
|
}
|
|
12341
|
-
if (current.computed || nestedFunction || parameterDecoratorNodes.has(current) || current.parent.type !==
|
|
12290
|
+
if (current.computed || nestedFunction || parameterDecoratorNodes.has(current) || current.parent.type !== import_utils70.AST_NODE_TYPES.CallExpression || current.parent.callee !== current) {
|
|
12342
12291
|
pinned.add(target);
|
|
12343
12292
|
return;
|
|
12344
12293
|
}
|
|
@@ -12358,9 +12307,9 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
12358
12307
|
}
|
|
12359
12308
|
}
|
|
12360
12309
|
for (const member of node.body.body) {
|
|
12361
|
-
if (member.type ===
|
|
12310
|
+
if (member.type === import_utils70.AST_NODE_TYPES.MethodDefinition || member.type === import_utils70.AST_NODE_TYPES.TSAbstractMethodDefinition) continue;
|
|
12362
12311
|
walk(member, context.sourceCode.visitorKeys, (current) => {
|
|
12363
|
-
if (current.type !==
|
|
12312
|
+
if (current.type !== import_utils70.AST_NODE_TYPES.MemberExpression) return;
|
|
12364
12313
|
const target = referencedMethod(context, current, classVariables);
|
|
12365
12314
|
const possibleTarget = target ?? referencedPropertyName(current);
|
|
12366
12315
|
if (possibleTarget !== null && privateNames.has(possibleTarget)) pinned.add(possibleTarget);
|
|
@@ -12370,7 +12319,7 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
12370
12319
|
const accessibility = new Map(
|
|
12371
12320
|
scopeDefinitions.map((definition) => {
|
|
12372
12321
|
const method = definition.node;
|
|
12373
|
-
const accessibility2 = method.key.type ===
|
|
12322
|
+
const accessibility2 = method.key.type === import_utils70.AST_NODE_TYPES.PrivateIdentifier ? "private" : method.accessibility ?? "public";
|
|
12374
12323
|
return [definition.name, accessibility2];
|
|
12375
12324
|
})
|
|
12376
12325
|
);
|
|
@@ -12405,7 +12354,7 @@ var stepdown_default = createRule({
|
|
|
12405
12354
|
moduleScope(context, program);
|
|
12406
12355
|
const computedReferenceNames = /* @__PURE__ */ new Set();
|
|
12407
12356
|
walk(program, context.sourceCode.visitorKeys, (node) => {
|
|
12408
|
-
if (node.type ===
|
|
12357
|
+
if (node.type === import_utils70.AST_NODE_TYPES.MemberExpression && node.computed && node.property.type === import_utils70.AST_NODE_TYPES.Literal && typeof node.property.value === "string") computedReferenceNames.add(node.property.value);
|
|
12409
12358
|
});
|
|
12410
12359
|
for (const node of classes) classScope(context, node, computedReferenceNames);
|
|
12411
12360
|
}
|
|
@@ -12414,7 +12363,7 @@ var stepdown_default = createRule({
|
|
|
12414
12363
|
});
|
|
12415
12364
|
|
|
12416
12365
|
// src/rules/zod-naming-convention.ts
|
|
12417
|
-
var
|
|
12366
|
+
var import_utils71 = require("@typescript-eslint/utils");
|
|
12418
12367
|
var CONVENTIONS = {
|
|
12419
12368
|
prefix: { test: ZOD_PREFIX_RE, messageId: "zPrefix" },
|
|
12420
12369
|
suffix: { test: ZOD_SUFFIX_RE, messageId: "schemaSuffix" },
|
|
@@ -12439,21 +12388,23 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
12439
12388
|
"registry",
|
|
12440
12389
|
"implement"
|
|
12441
12390
|
]);
|
|
12442
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
12443
|
-
var
|
|
12391
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === import_utils71.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
12392
|
+
var calleeChainRoot = (node) => {
|
|
12444
12393
|
let current = node;
|
|
12445
|
-
|
|
12446
|
-
|
|
12447
|
-
|
|
12448
|
-
|
|
12394
|
+
for (; ; ) {
|
|
12395
|
+
if (current.type === import_utils71.AST_NODE_TYPES.Identifier) {
|
|
12396
|
+
return current;
|
|
12397
|
+
}
|
|
12398
|
+
if (current.type === import_utils71.AST_NODE_TYPES.MemberExpression) {
|
|
12399
|
+
current = current.object;
|
|
12400
|
+
continue;
|
|
12449
12401
|
}
|
|
12450
|
-
if (
|
|
12451
|
-
current =
|
|
12402
|
+
if (current.type === import_utils71.AST_NODE_TYPES.CallExpression) {
|
|
12403
|
+
current = current.callee;
|
|
12452
12404
|
continue;
|
|
12453
12405
|
}
|
|
12454
|
-
return
|
|
12406
|
+
return null;
|
|
12455
12407
|
}
|
|
12456
|
-
return false;
|
|
12457
12408
|
};
|
|
12458
12409
|
var zod_naming_convention_default = createRule({
|
|
12459
12410
|
name: "zod-naming-convention",
|
|
@@ -12485,20 +12436,45 @@ var zod_naming_convention_default = createRule({
|
|
|
12485
12436
|
const convention = optionsArg?.convention ?? "either";
|
|
12486
12437
|
const { test, messageId } = CONVENTIONS[convention];
|
|
12487
12438
|
const acceptsSchemaWord = convention !== "prefix";
|
|
12439
|
+
const zodBindings = /* @__PURE__ */ new Set();
|
|
12440
|
+
function resolvedBinding(identifier) {
|
|
12441
|
+
return import_utils71.ASTUtils.findVariable(
|
|
12442
|
+
context.sourceCode.getScope(identifier),
|
|
12443
|
+
identifier.name
|
|
12444
|
+
);
|
|
12445
|
+
}
|
|
12446
|
+
function recordZodBinding(identifier) {
|
|
12447
|
+
const binding = resolvedBinding(identifier);
|
|
12448
|
+
if (binding !== null) zodBindings.add(binding);
|
|
12449
|
+
}
|
|
12450
|
+
function isZodChain(node) {
|
|
12451
|
+
const root = calleeChainRoot(node);
|
|
12452
|
+
if (root === null) return false;
|
|
12453
|
+
const binding = resolvedBinding(root);
|
|
12454
|
+
return binding !== null && zodBindings.has(binding);
|
|
12455
|
+
}
|
|
12488
12456
|
if (isTestFile(context.filename) || BENCHMARK_PATH_RE.test(context.filename.replaceAll("\\", "/")) || isGeneratedFile(context.filename, context.sourceCode.text)) {
|
|
12489
12457
|
return {};
|
|
12490
12458
|
}
|
|
12491
12459
|
return {
|
|
12460
|
+
ImportDeclaration(node) {
|
|
12461
|
+
if (!isZodModule(node.source.value)) return;
|
|
12462
|
+
for (const specifier of node.specifiers) {
|
|
12463
|
+
if (specifier.type === import_utils71.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils71.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils71.AST_NODE_TYPES.ImportSpecifier && (specifier.imported.type === import_utils71.AST_NODE_TYPES.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
12464
|
+
recordZodBinding(specifier.local);
|
|
12465
|
+
}
|
|
12466
|
+
}
|
|
12467
|
+
},
|
|
12492
12468
|
VariableDeclarator(node) {
|
|
12493
12469
|
const init = node.init;
|
|
12494
12470
|
if (init === null || init === void 0) return;
|
|
12495
|
-
if (init.type !==
|
|
12471
|
+
if (init.type !== import_utils71.AST_NODE_TYPES.CallExpression) return;
|
|
12496
12472
|
const callee = init.callee;
|
|
12497
|
-
if (callee.type !==
|
|
12498
|
-
if (!
|
|
12473
|
+
if (callee.type !== import_utils71.AST_NODE_TYPES.MemberExpression) return;
|
|
12474
|
+
if (!isZodChain(callee)) return;
|
|
12499
12475
|
const terminal = terminalMethodName(callee);
|
|
12500
12476
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
12501
|
-
if (node.id.type !==
|
|
12477
|
+
if (node.id.type !== import_utils71.AST_NODE_TYPES.Identifier) return;
|
|
12502
12478
|
if (test.test(node.id.name)) return;
|
|
12503
12479
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
12504
12480
|
context.report({
|
|
@@ -12552,6 +12528,14 @@ var retiredRules = {
|
|
|
12552
12528
|
removedIn: "10.0.0",
|
|
12553
12529
|
reason: "Delete the config entry and suppressions; use the narrower no-comment-cruft, no-restated-comment, and no-long-comment rules."
|
|
12554
12530
|
},
|
|
12531
|
+
"prefer-string-literal-union": {
|
|
12532
|
+
removedIn: "12.0.0",
|
|
12533
|
+
reason: "Delete the config entry and suppressions; syntax cannot prove that an open string domain is closed."
|
|
12534
|
+
},
|
|
12535
|
+
"prefer-zod-enum": {
|
|
12536
|
+
removedIn: "12.0.0",
|
|
12537
|
+
reason: "Delete the entry; use `zod/prefer-enum-over-literal-union`, which proves every arm is a string literal."
|
|
12538
|
+
},
|
|
12555
12539
|
"primary-export-file-name": {
|
|
12556
12540
|
removedIn: "4.0.0",
|
|
12557
12541
|
reason: "Delete the config entry and suppressions; there is no replacement."
|
|
@@ -12586,6 +12570,7 @@ var rules = {
|
|
|
12586
12570
|
"no-hand-rolled-spinner": no_hand_rolled_spinner_default,
|
|
12587
12571
|
"no-insecure-random-id": no_insecure_random_id_default,
|
|
12588
12572
|
"no-json-stringify-error": no_json_stringify_error_default,
|
|
12573
|
+
"no-impossible-zod-literal-bounds": no_impossible_zod_literal_bounds_default,
|
|
12589
12574
|
"no-log-only-catch": no_log_only_catch_default,
|
|
12590
12575
|
"no-long-comment": no_long_comment_default,
|
|
12591
12576
|
"no-generic-single-export-module": no_generic_single_export_module_default,
|
|
@@ -12626,9 +12611,7 @@ var rules = {
|
|
|
12626
12611
|
"prefer-schema-for-api-payload": prefer_schema_for_api_payload_default,
|
|
12627
12612
|
"prefer-semantic-colors": prefer_semantic_colors_default,
|
|
12628
12613
|
"prefer-server-actions": prefer_server_actions_default,
|
|
12629
|
-
"prefer-string-literal-union": prefer_string_literal_union_default,
|
|
12630
12614
|
"prefer-whole-object-assertion": prefer_whole_object_assertion_default,
|
|
12631
|
-
"prefer-zod-enum": prefer_zod_enum_default,
|
|
12632
12615
|
"prefer-zod-infer": prefer_zod_infer_default,
|
|
12633
12616
|
"require-assert-never": require_assert_never_default,
|
|
12634
12617
|
"require-fetch-timeout": require_fetch_timeout_default,
|
|
@@ -12641,7 +12624,7 @@ var rules = {
|
|
|
12641
12624
|
};
|
|
12642
12625
|
var meta = {
|
|
12643
12626
|
name: "@sarj/eslint-plugin",
|
|
12644
|
-
version: "
|
|
12627
|
+
version: "12.0.0"
|
|
12645
12628
|
};
|
|
12646
12629
|
var applicationOnlyRules = [
|
|
12647
12630
|
"no-restricted-library-load",
|
|
@@ -12662,6 +12645,7 @@ var recommendedRules = {
|
|
|
12662
12645
|
"@sarj/no-hand-rolled-spinner": "error",
|
|
12663
12646
|
"@sarj/no-insecure-random-id": "error",
|
|
12664
12647
|
"@sarj/no-json-stringify-error": "error",
|
|
12648
|
+
"@sarj/no-impossible-zod-literal-bounds": "error",
|
|
12665
12649
|
"@sarj/no-log-only-catch": "error",
|
|
12666
12650
|
"@sarj/no-long-comment": "error",
|
|
12667
12651
|
"@sarj/no-generic-single-export-module": "error",
|
|
@@ -12696,9 +12680,7 @@ var recommendedRules = {
|
|
|
12696
12680
|
"@sarj/prefer-schema-for-api-payload": "error",
|
|
12697
12681
|
"@sarj/prefer-semantic-colors": ["error", { requireSemanticTokens: true }],
|
|
12698
12682
|
"@sarj/prefer-server-actions": "error",
|
|
12699
|
-
"@sarj/prefer-string-literal-union": "error",
|
|
12700
12683
|
"@sarj/prefer-whole-object-assertion": "error",
|
|
12701
|
-
"@sarj/prefer-zod-enum": "error",
|
|
12702
12684
|
"@sarj/prefer-zod-infer": "error",
|
|
12703
12685
|
"@sarj/require-assert-never": "error",
|
|
12704
12686
|
"@sarj/require-fetch-timeout": "error",
|
|
@@ -12724,6 +12706,7 @@ var strictRules = {
|
|
|
12724
12706
|
"@sarj/no-hand-rolled-spinner": "error",
|
|
12725
12707
|
"@sarj/no-insecure-random-id": "error",
|
|
12726
12708
|
"@sarj/no-json-stringify-error": "error",
|
|
12709
|
+
"@sarj/no-impossible-zod-literal-bounds": "error",
|
|
12727
12710
|
"@sarj/no-log-only-catch": "error",
|
|
12728
12711
|
"@sarj/no-long-comment": "error",
|
|
12729
12712
|
"@sarj/no-generic-single-export-module": "error",
|
|
@@ -12761,9 +12744,7 @@ var strictRules = {
|
|
|
12761
12744
|
"@sarj/prefer-schema-for-api-payload": "error",
|
|
12762
12745
|
"@sarj/prefer-semantic-colors": ["error", { requireSemanticTokens: true }],
|
|
12763
12746
|
"@sarj/prefer-server-actions": "error",
|
|
12764
|
-
"@sarj/prefer-string-literal-union": "error",
|
|
12765
12747
|
"@sarj/prefer-whole-object-assertion": "error",
|
|
12766
|
-
"@sarj/prefer-zod-enum": "error",
|
|
12767
12748
|
"@sarj/prefer-zod-infer": "error",
|
|
12768
12749
|
"@sarj/require-assert-never": "error",
|
|
12769
12750
|
"@sarj/require-fetch-timeout": "error",
|