@sarj/eslint-plugin 11.2.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 +1020 -1098
- package/dist/index.d.cts +9 -21
- package/dist/index.d.ts +9 -21
- package/dist/index.js +1326 -1396
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1502,13 +1502,17 @@ function calleeRootName(call) {
|
|
|
1502
1502
|
var isAssertionCall = (node) => node.type === import_utils8.AST_NODE_TYPES.CallExpression && ASSERTION_ROOTS.has(calleeRootName(node) ?? "");
|
|
1503
1503
|
var isTypeAssertionCall = (node) => node.type === import_utils8.AST_NODE_TYPES.CallExpression && TYPE_ASSERTION_ROOTS.has(calleeRootName(node) ?? "");
|
|
1504
1504
|
var containsAssertion = (node) => subtreeMatches(node, isAssertionCall);
|
|
1505
|
+
var containsRuntimeAssertion = (node) => subtreeMatches(
|
|
1506
|
+
node,
|
|
1507
|
+
(current) => isAssertionCall(current) && !isTypeAssertionCall(current)
|
|
1508
|
+
);
|
|
1505
1509
|
var containsSkipCall = (node) => subtreeMatches(
|
|
1506
1510
|
node,
|
|
1507
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"
|
|
1508
1512
|
);
|
|
1509
1513
|
var containsEscape = (node) => subtreeMatches(
|
|
1510
1514
|
node,
|
|
1511
|
-
(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,
|
|
1512
1516
|
false
|
|
1513
1517
|
);
|
|
1514
1518
|
function branchStatements(branch) {
|
|
@@ -1539,7 +1543,7 @@ function isPinnedNarrowingGuard(node) {
|
|
|
1539
1543
|
}
|
|
1540
1544
|
let matched = false;
|
|
1541
1545
|
subtreeMatches(previous, (current) => {
|
|
1542
|
-
if (current.type !== import_utils8.AST_NODE_TYPES.CallExpression ||
|
|
1546
|
+
if (current.type !== import_utils8.AST_NODE_TYPES.CallExpression || !ASSERTION_ROOTS.has(calleeRootName(current) ?? "")) {
|
|
1543
1547
|
return false;
|
|
1544
1548
|
}
|
|
1545
1549
|
const subject = current.arguments[0];
|
|
@@ -1595,6 +1599,30 @@ function isInertNormalization(node) {
|
|
|
1595
1599
|
function isExemptIfStatement(node) {
|
|
1596
1600
|
return isPinnedNarrowingGuard(node) || isThrowingGuard(node) || isTypeLevelNarrowing(node) || isInertNormalization(node);
|
|
1597
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
|
+
}
|
|
1598
1626
|
function isShortCircuitedAssertion(node) {
|
|
1599
1627
|
return node.operator !== "??" && node.parent.type === import_utils8.AST_NODE_TYPES.ExpressionStatement && containsAssertion(node.right);
|
|
1600
1628
|
}
|
|
@@ -1603,11 +1631,11 @@ var no_conditional_in_test_default = createRule({
|
|
|
1603
1631
|
meta: {
|
|
1604
1632
|
type: "problem",
|
|
1605
1633
|
docs: {
|
|
1606
|
-
description: "Disallow
|
|
1634
|
+
description: "Disallow test conditionals that can skip a runtime assertion or exit the test before one runs."
|
|
1607
1635
|
},
|
|
1608
1636
|
schema: [],
|
|
1609
1637
|
messages: {
|
|
1610
|
-
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."
|
|
1611
1639
|
}
|
|
1612
1640
|
},
|
|
1613
1641
|
defaultOptions: [],
|
|
@@ -1624,16 +1652,16 @@ var no_conditional_in_test_default = createRule({
|
|
|
1624
1652
|
};
|
|
1625
1653
|
return {
|
|
1626
1654
|
IfStatement(node) {
|
|
1627
|
-
if (isExemptIfStatement(node)) {
|
|
1655
|
+
if (isExemptIfStatement(node) || !skipsAssertionOrTest(node)) {
|
|
1628
1656
|
return;
|
|
1629
1657
|
}
|
|
1630
1658
|
report(node);
|
|
1631
1659
|
},
|
|
1632
1660
|
SwitchStatement(node) {
|
|
1633
|
-
report(node);
|
|
1661
|
+
if (switchSkipsAssertion(node)) report(node);
|
|
1634
1662
|
},
|
|
1635
1663
|
ConditionalExpression(node) {
|
|
1636
|
-
report(node);
|
|
1664
|
+
if (conditionalSkipsAssertion(node)) report(node);
|
|
1637
1665
|
},
|
|
1638
1666
|
LogicalExpression(node) {
|
|
1639
1667
|
if (!isShortCircuitedAssertion(node)) {
|
|
@@ -3187,11 +3215,233 @@ var no_json_stringify_error_default = createRule({
|
|
|
3187
3215
|
}
|
|
3188
3216
|
});
|
|
3189
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
|
+
|
|
3190
3440
|
// src/rules/no-log-only-catch.ts
|
|
3191
|
-
var
|
|
3441
|
+
var import_utils20 = require("@typescript-eslint/utils");
|
|
3192
3442
|
|
|
3193
3443
|
// src/rules/_logging.ts
|
|
3194
|
-
var
|
|
3444
|
+
var import_utils19 = require("@typescript-eslint/utils");
|
|
3195
3445
|
var LOG_METHODS = /* @__PURE__ */ new Set([
|
|
3196
3446
|
"debug",
|
|
3197
3447
|
"info",
|
|
@@ -3295,29 +3545,29 @@ function createLogMatcher(options = {}) {
|
|
|
3295
3545
|
// src/rules/no-log-only-catch.ts
|
|
3296
3546
|
var BENCHMARK_DIR_RE = /(?:^|[\\/])benchmarks?[\\/]/;
|
|
3297
3547
|
var SINGLE_STATEMENT_HOSTS = /* @__PURE__ */ new Set([
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
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
|
|
3304
3554
|
]);
|
|
3305
3555
|
var FUNCTION_TYPES3 = /* @__PURE__ */ new Set([
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3556
|
+
import_utils20.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
3557
|
+
import_utils20.AST_NODE_TYPES.FunctionDeclaration,
|
|
3558
|
+
import_utils20.AST_NODE_TYPES.FunctionExpression
|
|
3309
3559
|
]);
|
|
3310
3560
|
function statementSlot(node) {
|
|
3311
3561
|
const parent = node.parent;
|
|
3312
3562
|
if (parent === void 0) return null;
|
|
3313
3563
|
let list;
|
|
3314
3564
|
switch (parent.type) {
|
|
3315
|
-
case
|
|
3316
|
-
case
|
|
3317
|
-
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:
|
|
3318
3568
|
list = parent.body;
|
|
3319
3569
|
break;
|
|
3320
|
-
case
|
|
3570
|
+
case import_utils20.AST_NODE_TYPES.SwitchCase:
|
|
3321
3571
|
list = parent.consequent;
|
|
3322
3572
|
break;
|
|
3323
3573
|
default:
|
|
@@ -3329,7 +3579,7 @@ function statementSlot(node) {
|
|
|
3329
3579
|
function fallbackFollowsTry(tryStatement) {
|
|
3330
3580
|
const body2 = tryStatement.block.body;
|
|
3331
3581
|
const last = body2.at(-1);
|
|
3332
|
-
return last?.type ===
|
|
3582
|
+
return last?.type === import_utils20.AST_NODE_TYPES.ReturnStatement && hasFollowingStatement(tryStatement);
|
|
3333
3583
|
}
|
|
3334
3584
|
function hasFollowingStatement(node) {
|
|
3335
3585
|
for (let current = node; current !== void 0 && !FUNCTION_TYPES3.has(current.type); current = current.parent) {
|
|
@@ -3342,14 +3592,14 @@ function seededFallbackHandled(tryStatement, scope) {
|
|
|
3342
3592
|
const slot = statementSlot(tryStatement);
|
|
3343
3593
|
if (slot === null || slot.index === 0) return false;
|
|
3344
3594
|
const previous = slot.list[slot.index - 1];
|
|
3345
|
-
if (previous?.type !==
|
|
3595
|
+
if (previous?.type !== import_utils20.AST_NODE_TYPES.VariableDeclaration || previous.kind === "const") {
|
|
3346
3596
|
return false;
|
|
3347
3597
|
}
|
|
3348
3598
|
const declarator = previous.declarations[0];
|
|
3349
3599
|
if (previous.declarations.length !== 1 || declarator === void 0) return false;
|
|
3350
|
-
if (declarator.id.type !==
|
|
3600
|
+
if (declarator.id.type !== import_utils20.AST_NODE_TYPES.Identifier) return false;
|
|
3351
3601
|
if (declarator.init == null || !isSeedValue(declarator.init)) return false;
|
|
3352
|
-
const variable =
|
|
3602
|
+
const variable = import_utils20.ASTUtils.findVariable(scope, declarator.id.name);
|
|
3353
3603
|
if (variable === null) return false;
|
|
3354
3604
|
const [tryStart, tryEnd] = tryStatement.block.range;
|
|
3355
3605
|
let writtenInTry = false;
|
|
@@ -3362,17 +3612,17 @@ function seededFallbackHandled(tryStatement, scope) {
|
|
|
3362
3612
|
return writtenInTry && readAfter;
|
|
3363
3613
|
}
|
|
3364
3614
|
function isSeedValue(node) {
|
|
3365
|
-
const inner = node.type ===
|
|
3615
|
+
const inner = node.type === import_utils20.AST_NODE_TYPES.TSAsExpression ? node.expression : node;
|
|
3366
3616
|
switch (inner.type) {
|
|
3367
|
-
case
|
|
3617
|
+
case import_utils20.AST_NODE_TYPES.Literal:
|
|
3368
3618
|
return true;
|
|
3369
|
-
case
|
|
3619
|
+
case import_utils20.AST_NODE_TYPES.Identifier:
|
|
3370
3620
|
return inner.name === "undefined";
|
|
3371
|
-
case
|
|
3372
|
-
return inner.argument.type ===
|
|
3373
|
-
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:
|
|
3374
3624
|
return inner.elements.length === 0;
|
|
3375
|
-
case
|
|
3625
|
+
case import_utils20.AST_NODE_TYPES.ObjectExpression:
|
|
3376
3626
|
return inner.properties.length === 0;
|
|
3377
3627
|
default:
|
|
3378
3628
|
return false;
|
|
@@ -3416,7 +3666,7 @@ var no_log_only_catch_default = createRule({
|
|
|
3416
3666
|
const tryStatement = node.parent;
|
|
3417
3667
|
if (hasCommentDirectlyAbove(tryStatement) || hasCommentDirectlyAbove(node)) return true;
|
|
3418
3668
|
const block = tryStatement.parent;
|
|
3419
|
-
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)) {
|
|
3420
3670
|
return false;
|
|
3421
3671
|
}
|
|
3422
3672
|
return hasCommentDirectlyAbove(block.parent);
|
|
@@ -3453,10 +3703,10 @@ var no_log_only_catch_default = createRule({
|
|
|
3453
3703
|
});
|
|
3454
3704
|
|
|
3455
3705
|
// src/rules/no-long-comment.ts
|
|
3456
|
-
var
|
|
3706
|
+
var import_utils22 = require("@typescript-eslint/utils");
|
|
3457
3707
|
|
|
3458
3708
|
// src/rules/_prose-budget.ts
|
|
3459
|
-
var
|
|
3709
|
+
var import_utils21 = require("@typescript-eslint/utils");
|
|
3460
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;
|
|
3461
3711
|
var LICENSE_RE2 = /\b(?:copyright|spdx-license-identifier|licensed under)\b/i;
|
|
3462
3712
|
var TYPED_TAG_RE = /@(arg|argument|param|return|returns|yield|yields)\b/i;
|
|
@@ -3525,15 +3775,15 @@ function proseGroups(filename, sourceCode, includeValueTags = false) {
|
|
|
3525
3775
|
return groups;
|
|
3526
3776
|
}
|
|
3527
3777
|
function annotatedParameter(parameter) {
|
|
3528
|
-
if (parameter.type ===
|
|
3529
|
-
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;
|
|
3530
3780
|
return "typeAnnotation" in target && target.typeAnnotation != null;
|
|
3531
3781
|
}
|
|
3532
3782
|
function documentsTypedFunction(sourceCode, comment) {
|
|
3533
3783
|
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
3534
3784
|
if (token === null || token.loc.start.line !== comment.loc.end.line + 1) return false;
|
|
3535
3785
|
let node = sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
3536
|
-
while (node != null && node.type !==
|
|
3786
|
+
while (node != null && node.type !== import_utils21.AST_NODE_TYPES.Program) {
|
|
3537
3787
|
if (typedFunction(node)) return true;
|
|
3538
3788
|
node = node.parent ?? null;
|
|
3539
3789
|
}
|
|
@@ -3541,19 +3791,19 @@ function documentsTypedFunction(sourceCode, comment) {
|
|
|
3541
3791
|
}
|
|
3542
3792
|
function typedFunction(node) {
|
|
3543
3793
|
switch (node.type) {
|
|
3544
|
-
case
|
|
3545
|
-
case
|
|
3794
|
+
case import_utils21.AST_NODE_TYPES.ExportNamedDeclaration:
|
|
3795
|
+
case import_utils21.AST_NODE_TYPES.ExportDefaultDeclaration:
|
|
3546
3796
|
return node.declaration != null && typedFunction(node.declaration);
|
|
3547
|
-
case
|
|
3548
|
-
case
|
|
3797
|
+
case import_utils21.AST_NODE_TYPES.FunctionDeclaration:
|
|
3798
|
+
case import_utils21.AST_NODE_TYPES.TSDeclareFunction:
|
|
3549
3799
|
return node.returnType != null && node.params.every(annotatedParameter);
|
|
3550
|
-
case
|
|
3800
|
+
case import_utils21.AST_NODE_TYPES.VariableDeclaration: {
|
|
3551
3801
|
const init = node.declarations[0]?.init;
|
|
3552
|
-
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);
|
|
3553
3803
|
}
|
|
3554
|
-
case
|
|
3804
|
+
case import_utils21.AST_NODE_TYPES.MethodDefinition:
|
|
3555
3805
|
return node.value.returnType != null && node.value.params.every(annotatedParameter);
|
|
3556
|
-
case
|
|
3806
|
+
case import_utils21.AST_NODE_TYPES.TSMethodSignature:
|
|
3557
3807
|
return node.returnType != null && node.params.every(annotatedParameter);
|
|
3558
3808
|
default:
|
|
3559
3809
|
return false;
|
|
@@ -3569,8 +3819,8 @@ function documentsTypeOrMember(sourceCode, comment) {
|
|
|
3569
3819
|
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
3570
3820
|
if (token === null || token.loc.start.line !== comment.loc.end.line + 1) return false;
|
|
3571
3821
|
let node = sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
3572
|
-
while (node != null && node.type !==
|
|
3573
|
-
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;
|
|
3574
3824
|
node = node.parent;
|
|
3575
3825
|
}
|
|
3576
3826
|
return false;
|
|
@@ -3604,7 +3854,7 @@ var no_long_comment_default = createRule({
|
|
|
3604
3854
|
});
|
|
3605
3855
|
|
|
3606
3856
|
// src/rules/no-generic-single-export-module.ts
|
|
3607
|
-
var
|
|
3857
|
+
var import_utils23 = require("@typescript-eslint/utils");
|
|
3608
3858
|
var GENERIC_STEMS = /* @__PURE__ */ new Set([
|
|
3609
3859
|
"base",
|
|
3610
3860
|
"common",
|
|
@@ -3639,34 +3889,34 @@ function fileParts(filename) {
|
|
|
3639
3889
|
}
|
|
3640
3890
|
function declaredNames(declaration) {
|
|
3641
3891
|
if (declaration.declare === true) return [];
|
|
3642
|
-
if (declaration.type ===
|
|
3643
|
-
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 [];
|
|
3644
3894
|
return declaration.id === null ? [] : [declaration.id.name];
|
|
3645
3895
|
}
|
|
3646
|
-
if (declaration.type ===
|
|
3896
|
+
if (declaration.type === import_utils23.AST_NODE_TYPES.TSModuleDeclaration && declaration.id.type === import_utils23.AST_NODE_TYPES.Identifier) {
|
|
3647
3897
|
return [declaration.id.name];
|
|
3648
3898
|
}
|
|
3649
|
-
if (declaration.type !==
|
|
3899
|
+
if (declaration.type !== import_utils23.AST_NODE_TYPES.VariableDeclaration) return [];
|
|
3650
3900
|
return declaration.declarations.flatMap(
|
|
3651
|
-
(item) => item.id.type ===
|
|
3901
|
+
(item) => item.id.type === import_utils23.AST_NODE_TYPES.Identifier ? [item.id.name] : []
|
|
3652
3902
|
);
|
|
3653
3903
|
}
|
|
3654
3904
|
function typeOnlyBindings(program) {
|
|
3655
3905
|
const names = /* @__PURE__ */ new Set();
|
|
3656
3906
|
const runtimeNames = /* @__PURE__ */ new Set();
|
|
3657
3907
|
for (const statement of program.body) {
|
|
3658
|
-
const declaration = statement.type ===
|
|
3659
|
-
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) {
|
|
3660
3910
|
names.add(declaration.id.name);
|
|
3661
3911
|
continue;
|
|
3662
3912
|
}
|
|
3663
|
-
if (declaration?.type ===
|
|
3913
|
+
if (declaration?.type === import_utils23.AST_NODE_TYPES.TSEnumDeclaration && declaration.const) {
|
|
3664
3914
|
names.add(declaration.id.name);
|
|
3665
3915
|
continue;
|
|
3666
3916
|
}
|
|
3667
|
-
if (statement.type ===
|
|
3917
|
+
if (statement.type === import_utils23.AST_NODE_TYPES.ImportDeclaration) {
|
|
3668
3918
|
for (const specifier of statement.specifiers) {
|
|
3669
|
-
if (statement.importKind === "type" || specifier.type ===
|
|
3919
|
+
if (statement.importKind === "type" || specifier.type === import_utils23.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === "type") {
|
|
3670
3920
|
names.add(specifier.local.name);
|
|
3671
3921
|
} else {
|
|
3672
3922
|
runtimeNames.add(specifier.local.name);
|
|
@@ -3674,15 +3924,15 @@ function typeOnlyBindings(program) {
|
|
|
3674
3924
|
}
|
|
3675
3925
|
continue;
|
|
3676
3926
|
}
|
|
3677
|
-
if (declaration?.type ===
|
|
3927
|
+
if (declaration?.type === import_utils23.AST_NODE_TYPES.TSDeclareFunction && declaration.id !== null) {
|
|
3678
3928
|
names.add(declaration.id.name);
|
|
3679
3929
|
continue;
|
|
3680
3930
|
}
|
|
3681
3931
|
if (declaration !== null && declaration.declare === true) {
|
|
3682
|
-
if ((declaration.type ===
|
|
3683
|
-
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) {
|
|
3684
3934
|
for (const item of declaration.declarations) {
|
|
3685
|
-
if (item.id.type ===
|
|
3935
|
+
if (item.id.type === import_utils23.AST_NODE_TYPES.Identifier) names.add(item.id.name);
|
|
3686
3936
|
}
|
|
3687
3937
|
}
|
|
3688
3938
|
continue;
|
|
@@ -3700,21 +3950,21 @@ function runtimeExports(program) {
|
|
|
3700
3950
|
const typeBindings = typeOnlyBindings(program);
|
|
3701
3951
|
let ambiguous = false;
|
|
3702
3952
|
for (const statement of program.body) {
|
|
3703
|
-
if (statement.type ===
|
|
3953
|
+
if (statement.type === import_utils23.AST_NODE_TYPES.ExportAllDeclaration) {
|
|
3704
3954
|
if (statement.exportKind !== "type") ambiguous = true;
|
|
3705
3955
|
continue;
|
|
3706
3956
|
}
|
|
3707
|
-
if (statement.type ===
|
|
3957
|
+
if (statement.type === import_utils23.AST_NODE_TYPES.ExportDefaultDeclaration) {
|
|
3708
3958
|
const declaration = statement.declaration;
|
|
3709
|
-
if (declaration.type ===
|
|
3959
|
+
if (declaration.type === import_utils23.AST_NODE_TYPES.Identifier) {
|
|
3710
3960
|
if (!typeBindings.has(declaration.name)) {
|
|
3711
3961
|
exports2.push({ key: "default", name: declaration.name, node: statement });
|
|
3712
3962
|
}
|
|
3713
|
-
} else if ((declaration.type ===
|
|
3714
|
-
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;
|
|
3715
3965
|
continue;
|
|
3716
3966
|
}
|
|
3717
|
-
if (statement.type !==
|
|
3967
|
+
if (statement.type !== import_utils23.AST_NODE_TYPES.ExportNamedDeclaration || statement.exportKind === "type") continue;
|
|
3718
3968
|
if (statement.source !== null) {
|
|
3719
3969
|
if (statement.specifiers.some((specifier) => specifier.exportKind !== "type")) ambiguous = true;
|
|
3720
3970
|
continue;
|
|
@@ -3725,7 +3975,7 @@ function runtimeExports(program) {
|
|
|
3725
3975
|
}
|
|
3726
3976
|
for (const specifier of statement.specifiers) {
|
|
3727
3977
|
if (specifier.exportKind === "type" || typeBindings.has(specifier.local.name)) continue;
|
|
3728
|
-
const exported = specifier.exported.type ===
|
|
3978
|
+
const exported = specifier.exported.type === import_utils23.AST_NODE_TYPES.Identifier ? specifier.exported.name : specifier.exported.value;
|
|
3729
3979
|
const local = specifier.local.name;
|
|
3730
3980
|
exports2.push({ key: exported, name: exported === "default" ? local : exported, node: specifier });
|
|
3731
3981
|
}
|
|
@@ -3737,15 +3987,15 @@ function publicTypeExportCount(program) {
|
|
|
3737
3987
|
const names = /* @__PURE__ */ new Set();
|
|
3738
3988
|
const typeBindings = typeOnlyBindings(program);
|
|
3739
3989
|
for (const statement of program.body) {
|
|
3740
|
-
if (statement.type !==
|
|
3990
|
+
if (statement.type !== import_utils23.AST_NODE_TYPES.ExportNamedDeclaration) continue;
|
|
3741
3991
|
const declaration = statement.declaration;
|
|
3742
|
-
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);
|
|
3743
3993
|
for (const specifier of statement.specifiers) {
|
|
3744
|
-
const local = specifier.local.type ===
|
|
3994
|
+
const local = specifier.local.type === import_utils23.AST_NODE_TYPES.Identifier ? specifier.local.name : specifier.local.value;
|
|
3745
3995
|
if (statement.exportKind !== "type" && specifier.exportKind !== "type" && !typeBindings.has(local)) {
|
|
3746
3996
|
continue;
|
|
3747
3997
|
}
|
|
3748
|
-
names.add(specifier.exported.type ===
|
|
3998
|
+
names.add(specifier.exported.type === import_utils23.AST_NODE_TYPES.Identifier ? specifier.exported.name : specifier.exported.value);
|
|
3749
3999
|
}
|
|
3750
4000
|
}
|
|
3751
4001
|
return names.size;
|
|
@@ -3754,7 +4004,7 @@ function kebabCase(name) {
|
|
|
3754
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();
|
|
3755
4005
|
}
|
|
3756
4006
|
function isGlobalIdentifier(context, node) {
|
|
3757
|
-
const variable =
|
|
4007
|
+
const variable = import_utils23.ASTUtils.findVariable(context.sourceCode.getScope(node), node.name);
|
|
3758
4008
|
return variable === null || variable.defs.length === 0;
|
|
3759
4009
|
}
|
|
3760
4010
|
function isConventionalFrameworkUtility(filename, exported) {
|
|
@@ -3762,8 +4012,8 @@ function isConventionalFrameworkUtility(filename, exported) {
|
|
|
3762
4012
|
return exported === "cn" && /(?:^|\/)lib\/utils\.[cm]?[jt]sx?$/u.test(normalized);
|
|
3763
4013
|
}
|
|
3764
4014
|
function memberPropertyName(node) {
|
|
3765
|
-
if (!node.computed && node.property.type ===
|
|
3766
|
-
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;
|
|
3767
4017
|
}
|
|
3768
4018
|
var no_generic_single_export_module_default = createRule({
|
|
3769
4019
|
name: "no-generic-single-export-module",
|
|
@@ -3784,11 +4034,11 @@ var no_generic_single_export_module_default = createRule({
|
|
|
3784
4034
|
return {
|
|
3785
4035
|
CallExpression(node) {
|
|
3786
4036
|
const first = node.arguments[0];
|
|
3787
|
-
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;
|
|
3788
4038
|
},
|
|
3789
4039
|
MemberExpression(node) {
|
|
3790
|
-
if (node.object.type ===
|
|
3791
|
-
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;
|
|
3792
4042
|
},
|
|
3793
4043
|
"Program:exit"(program) {
|
|
3794
4044
|
if (hasCommonJsExport) return;
|
|
@@ -3818,7 +4068,7 @@ var no_generic_single_export_module_default = createRule({
|
|
|
3818
4068
|
});
|
|
3819
4069
|
|
|
3820
4070
|
// src/rules/no-offset-pagination.ts
|
|
3821
|
-
var
|
|
4071
|
+
var import_utils24 = require("@typescript-eslint/utils");
|
|
3822
4072
|
var OFFSET_PAGINATION = /\bOFFSET\s+(?:%s|%\(\w+\)s|\?\d*|:\w+|@\w+|\$\d+|\d+)/i;
|
|
3823
4073
|
var OFFSET_GATE = /offset/i;
|
|
3824
4074
|
var no_offset_pagination_default = createRule({
|
|
@@ -3848,25 +4098,32 @@ var no_offset_pagination_default = createRule({
|
|
|
3848
4098
|
});
|
|
3849
4099
|
|
|
3850
4100
|
// src/rules/no-positional-tuple-return.ts
|
|
3851
|
-
var
|
|
4101
|
+
var import_utils25 = require("@typescript-eslint/utils");
|
|
3852
4102
|
var MIN_ELEMENTS = 2;
|
|
3853
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
|
+
}
|
|
3854
4111
|
function tupleReturnType(node, aliases, resolving = /* @__PURE__ */ new Set()) {
|
|
3855
|
-
if (node.type ===
|
|
4112
|
+
if (node.type === import_utils25.AST_NODE_TYPES.TSTupleType) {
|
|
3856
4113
|
return node;
|
|
3857
4114
|
}
|
|
3858
|
-
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)) {
|
|
3859
4116
|
const argument = node.typeArguments?.params.at(0);
|
|
3860
4117
|
return argument === void 0 ? null : tupleReturnType(argument, aliases, resolving);
|
|
3861
4118
|
}
|
|
3862
|
-
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)) {
|
|
3863
4120
|
const target = aliases.get(node.typeName.name);
|
|
3864
4121
|
if (target !== void 0) return tupleReturnType(target, aliases, /* @__PURE__ */ new Set([...resolving, node.typeName.name]));
|
|
3865
4122
|
}
|
|
3866
|
-
if (node.type ===
|
|
4123
|
+
if (node.type === import_utils25.AST_NODE_TYPES.TSTypeOperator && node.operator === "readonly") {
|
|
3867
4124
|
return node.typeAnnotation === void 0 ? null : tupleReturnType(node.typeAnnotation, aliases, resolving);
|
|
3868
4125
|
}
|
|
3869
|
-
if (node.type ===
|
|
4126
|
+
if (node.type === import_utils25.AST_NODE_TYPES.TSUnionType || node.type === import_utils25.AST_NODE_TYPES.TSIntersectionType) {
|
|
3870
4127
|
for (const member of node.types) {
|
|
3871
4128
|
const tuple = tupleReturnType(member, aliases, resolving);
|
|
3872
4129
|
if (tuple !== null) return tuple;
|
|
@@ -3875,21 +4132,21 @@ function tupleReturnType(node, aliases, resolving = /* @__PURE__ */ new Set()) {
|
|
|
3875
4132
|
return null;
|
|
3876
4133
|
}
|
|
3877
4134
|
function functionName(node) {
|
|
3878
|
-
if (node.type ===
|
|
4135
|
+
if (node.type === import_utils25.AST_NODE_TYPES.FunctionDeclaration) {
|
|
3879
4136
|
if (node.id !== null) return node.id.name;
|
|
3880
|
-
return node.parent?.type ===
|
|
4137
|
+
return node.parent?.type === import_utils25.AST_NODE_TYPES.ExportDefaultDeclaration ? "default" : null;
|
|
3881
4138
|
}
|
|
3882
4139
|
let wrapped = node;
|
|
3883
|
-
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) {
|
|
3884
4141
|
wrapped = wrapped.parent;
|
|
3885
4142
|
}
|
|
3886
4143
|
const parent = wrapped.parent;
|
|
3887
|
-
if (parent?.type ===
|
|
3888
|
-
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) {
|
|
3889
4146
|
return parent.id.name;
|
|
3890
4147
|
}
|
|
3891
|
-
if ((parent?.type ===
|
|
3892
|
-
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;
|
|
3893
4150
|
return parent.key.name;
|
|
3894
4151
|
}
|
|
3895
4152
|
return null;
|
|
@@ -3898,7 +4155,7 @@ function isInlineExported(node) {
|
|
|
3898
4155
|
if (moduleScopeBindingName(node) === null) return false;
|
|
3899
4156
|
for (let current = node; current != null; current = current.parent) {
|
|
3900
4157
|
const parent = current.parent;
|
|
3901
|
-
if (parent?.type ===
|
|
4158
|
+
if (parent?.type === import_utils25.AST_NODE_TYPES.ExportNamedDeclaration || parent?.type === import_utils25.AST_NODE_TYPES.ExportDefaultDeclaration) {
|
|
3902
4159
|
return true;
|
|
3903
4160
|
}
|
|
3904
4161
|
}
|
|
@@ -3906,39 +4163,39 @@ function isInlineExported(node) {
|
|
|
3906
4163
|
}
|
|
3907
4164
|
function moduleScopeBindingName(node) {
|
|
3908
4165
|
let current = node;
|
|
3909
|
-
while (current.parent != null && current.parent.type !==
|
|
4166
|
+
while (current.parent != null && current.parent.type !== import_utils25.AST_NODE_TYPES.Program) {
|
|
3910
4167
|
current = current.parent;
|
|
3911
4168
|
}
|
|
3912
|
-
if (current.parent?.type !==
|
|
4169
|
+
if (current.parent?.type !== import_utils25.AST_NODE_TYPES.Program) {
|
|
3913
4170
|
return null;
|
|
3914
4171
|
}
|
|
3915
4172
|
let topLevel = current;
|
|
3916
|
-
if (current.type ===
|
|
4173
|
+
if (current.type === import_utils25.AST_NODE_TYPES.ExportNamedDeclaration || current.type === import_utils25.AST_NODE_TYPES.ExportDefaultDeclaration) {
|
|
3917
4174
|
topLevel = current.declaration;
|
|
3918
4175
|
}
|
|
3919
4176
|
if (topLevel === null) return null;
|
|
3920
|
-
if (topLevel.type ===
|
|
4177
|
+
if (topLevel.type === import_utils25.AST_NODE_TYPES.FunctionDeclaration) {
|
|
3921
4178
|
if (topLevel !== node) return null;
|
|
3922
|
-
return topLevel.id?.name ?? (current.type ===
|
|
4179
|
+
return topLevel.id?.name ?? (current.type === import_utils25.AST_NODE_TYPES.ExportDefaultDeclaration ? "default" : null);
|
|
3923
4180
|
}
|
|
3924
|
-
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) {
|
|
3925
4182
|
return "default";
|
|
3926
4183
|
}
|
|
3927
|
-
if (topLevel.type ===
|
|
4184
|
+
if (topLevel.type === import_utils25.AST_NODE_TYPES.ClassDeclaration) {
|
|
3928
4185
|
let owner = node.parent;
|
|
3929
4186
|
while (owner != null && owner.parent !== topLevel.body) owner = owner.parent;
|
|
3930
|
-
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;
|
|
3931
4188
|
}
|
|
3932
|
-
if (topLevel.type ===
|
|
4189
|
+
if (topLevel.type === import_utils25.AST_NODE_TYPES.VariableDeclaration) {
|
|
3933
4190
|
for (const declarator of topLevel.declarations) {
|
|
3934
4191
|
let initializer = declarator.init;
|
|
3935
|
-
while (initializer?.type ===
|
|
3936
|
-
if (declarator.id.type ===
|
|
3937
|
-
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)) {
|
|
3938
4195
|
let owner = node.parent;
|
|
3939
|
-
const container = initializer.type ===
|
|
4196
|
+
const container = initializer.type === import_utils25.AST_NODE_TYPES.ClassExpression ? initializer.body : initializer;
|
|
3940
4197
|
while (owner != null && owner.parent !== container) owner = owner.parent;
|
|
3941
|
-
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;
|
|
3942
4199
|
}
|
|
3943
4200
|
}
|
|
3944
4201
|
}
|
|
@@ -3947,19 +4204,19 @@ function moduleScopeBindingName(node) {
|
|
|
3947
4204
|
function specifierExportedNames(program) {
|
|
3948
4205
|
const names = /* @__PURE__ */ new Set();
|
|
3949
4206
|
for (const statement of program.body) {
|
|
3950
|
-
if (statement.type ===
|
|
4207
|
+
if (statement.type === import_utils25.AST_NODE_TYPES.ExportNamedDeclaration && statement.declaration == null && statement.source == null && statement.exportKind !== "type") {
|
|
3951
4208
|
for (const specifier of statement.specifiers) {
|
|
3952
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
4209
|
+
if (specifier.exportKind !== "type" && specifier.local.type === import_utils25.AST_NODE_TYPES.Identifier) {
|
|
3953
4210
|
names.add(specifier.local.name);
|
|
3954
4211
|
}
|
|
3955
4212
|
}
|
|
3956
4213
|
continue;
|
|
3957
4214
|
}
|
|
3958
|
-
if (statement.type ===
|
|
4215
|
+
if (statement.type === import_utils25.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils25.AST_NODE_TYPES.Identifier) {
|
|
3959
4216
|
names.add(statement.declaration.name);
|
|
3960
4217
|
continue;
|
|
3961
4218
|
}
|
|
3962
|
-
if (statement.type ===
|
|
4219
|
+
if (statement.type === import_utils25.AST_NODE_TYPES.TSExportAssignment && statement.expression.type === import_utils25.AST_NODE_TYPES.Identifier) {
|
|
3963
4220
|
names.add(statement.expression.name);
|
|
3964
4221
|
}
|
|
3965
4222
|
}
|
|
@@ -3968,28 +4225,28 @@ function specifierExportedNames(program) {
|
|
|
3968
4225
|
function exportedTypeNames(program) {
|
|
3969
4226
|
const names = /* @__PURE__ */ new Set();
|
|
3970
4227
|
for (const statement of program.body) {
|
|
3971
|
-
if (statement.type !==
|
|
3972
|
-
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);
|
|
3973
4230
|
for (const specifier of statement.specifiers) names.add(specifier.local.name);
|
|
3974
4231
|
}
|
|
3975
4232
|
for (const statement of program.body) {
|
|
3976
|
-
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);
|
|
3977
4234
|
}
|
|
3978
4235
|
return names;
|
|
3979
4236
|
}
|
|
3980
4237
|
function typeAliases(program) {
|
|
3981
4238
|
const aliases = /* @__PURE__ */ new Map();
|
|
3982
4239
|
for (const statement of program.body) {
|
|
3983
|
-
const declaration = statement.type ===
|
|
3984
|
-
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) {
|
|
3985
4242
|
aliases.set(declaration.id.name, declaration.typeAnnotation);
|
|
3986
4243
|
}
|
|
3987
4244
|
}
|
|
3988
4245
|
return aliases;
|
|
3989
4246
|
}
|
|
3990
4247
|
function callableReturnType(node, aliases, resolving = /* @__PURE__ */ new Set()) {
|
|
3991
|
-
if (node.type ===
|
|
3992
|
-
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)) {
|
|
3993
4250
|
const target = aliases.get(node.typeName.name);
|
|
3994
4251
|
if (target !== void 0) {
|
|
3995
4252
|
return callableReturnType(target, aliases, /* @__PURE__ */ new Set([...resolving, node.typeName.name]));
|
|
@@ -4001,8 +4258,8 @@ function publiclyReachableTypeNames(program, exported) {
|
|
|
4001
4258
|
const names = new Set(exported);
|
|
4002
4259
|
const interfaces = /* @__PURE__ */ new Map();
|
|
4003
4260
|
for (const statement of program.body) {
|
|
4004
|
-
const declaration = statement.type ===
|
|
4005
|
-
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) {
|
|
4006
4263
|
interfaces.set(declaration.id.name, declaration.extends);
|
|
4007
4264
|
}
|
|
4008
4265
|
}
|
|
@@ -4010,7 +4267,7 @@ function publiclyReachableTypeNames(program, exported) {
|
|
|
4010
4267
|
let changed = false;
|
|
4011
4268
|
for (const name of [...names]) {
|
|
4012
4269
|
for (const heritage of interfaces.get(name) ?? []) {
|
|
4013
|
-
if (heritage.expression.type ===
|
|
4270
|
+
if (heritage.expression.type === import_utils25.AST_NODE_TYPES.Identifier && !names.has(heritage.expression.name)) {
|
|
4014
4271
|
names.add(heritage.expression.name);
|
|
4015
4272
|
changed = true;
|
|
4016
4273
|
}
|
|
@@ -4022,37 +4279,37 @@ function publiclyReachableTypeNames(program, exported) {
|
|
|
4022
4279
|
}
|
|
4023
4280
|
function owningInterface(node) {
|
|
4024
4281
|
for (let current = node.parent; current !== void 0; current = current.parent) {
|
|
4025
|
-
if (current.type ===
|
|
4026
|
-
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;
|
|
4027
4284
|
}
|
|
4028
4285
|
return null;
|
|
4029
4286
|
}
|
|
4030
4287
|
function owningTypeAlias(node) {
|
|
4031
4288
|
for (let current = node.parent; current !== void 0; current = current.parent) {
|
|
4032
|
-
if (current.type ===
|
|
4033
|
-
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;
|
|
4034
4291
|
}
|
|
4035
4292
|
return null;
|
|
4036
4293
|
}
|
|
4037
4294
|
function owningClass(node) {
|
|
4038
4295
|
for (let current = node.parent; current !== void 0; current = current.parent) {
|
|
4039
|
-
if (current.type ===
|
|
4296
|
+
if (current.type === import_utils25.AST_NODE_TYPES.ClassDeclaration || current.type === import_utils25.AST_NODE_TYPES.ClassExpression) {
|
|
4040
4297
|
return current;
|
|
4041
4298
|
}
|
|
4042
|
-
if (current.type ===
|
|
4299
|
+
if (current.type === import_utils25.AST_NODE_TYPES.Program) return null;
|
|
4043
4300
|
}
|
|
4044
4301
|
return null;
|
|
4045
4302
|
}
|
|
4046
4303
|
function isExportedClass(node, specifierExports) {
|
|
4047
|
-
if (node.parent.type ===
|
|
4048
|
-
if (node.type ===
|
|
4049
|
-
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);
|
|
4050
4307
|
}
|
|
4051
|
-
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);
|
|
4052
4309
|
return false;
|
|
4053
4310
|
}
|
|
4054
4311
|
function isExportedInterface(node, exports2) {
|
|
4055
|
-
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);
|
|
4056
4313
|
}
|
|
4057
4314
|
function isExported(node, specifierExports) {
|
|
4058
4315
|
if (isInlineExported(node)) {
|
|
@@ -4114,7 +4371,7 @@ var no_positional_tuple_return_default = createRule({
|
|
|
4114
4371
|
ArrowFunctionExpression: check,
|
|
4115
4372
|
TSEmptyBodyFunctionExpression: check,
|
|
4116
4373
|
TSDeclareFunction(node) {
|
|
4117
|
-
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;
|
|
4118
4375
|
report(node.returnType.typeAnnotation, node.id.name);
|
|
4119
4376
|
},
|
|
4120
4377
|
TSCallSignatureDeclaration(node) {
|
|
@@ -4125,8 +4382,9 @@ var no_positional_tuple_return_default = createRule({
|
|
|
4125
4382
|
TSMethodSignature(node) {
|
|
4126
4383
|
const owner = owningInterface(node);
|
|
4127
4384
|
const alias = owningTypeAlias(node);
|
|
4128
|
-
|
|
4129
|
-
|
|
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}`);
|
|
4130
4388
|
},
|
|
4131
4389
|
TSTypeAliasDeclaration(node) {
|
|
4132
4390
|
if (!typeExports.has(node.id.name)) return;
|
|
@@ -4137,10 +4395,11 @@ var no_positional_tuple_return_default = createRule({
|
|
|
4137
4395
|
const owner = owningInterface(node);
|
|
4138
4396
|
const alias = owningTypeAlias(node);
|
|
4139
4397
|
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
4140
|
-
|
|
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;
|
|
4141
4400
|
const returnType = callableReturnType(annotation, aliases);
|
|
4142
4401
|
if (returnType !== null) {
|
|
4143
|
-
report(returnType, `${owner?.id.name ?? alias?.id.name ?? "type"}.${
|
|
4402
|
+
report(returnType, `${owner?.id.name ?? alias?.id.name ?? "type"}.${memberName2}`);
|
|
4144
4403
|
}
|
|
4145
4404
|
},
|
|
4146
4405
|
PropertyDefinition(node) {
|
|
@@ -4150,7 +4409,7 @@ var no_positional_tuple_return_default = createRule({
|
|
|
4150
4409
|
if (owner === null || !isExportedClass(owner, specifierExports) || annotation === void 0) return;
|
|
4151
4410
|
const returnType = callableReturnType(annotation, aliases);
|
|
4152
4411
|
if (returnType !== null) {
|
|
4153
|
-
const name = node.key.type ===
|
|
4412
|
+
const name = node.key.type === import_utils25.AST_NODE_TYPES.Identifier ? node.key.name : "property";
|
|
4154
4413
|
report(returnType, name);
|
|
4155
4414
|
}
|
|
4156
4415
|
}
|
|
@@ -4159,7 +4418,7 @@ var no_positional_tuple_return_default = createRule({
|
|
|
4159
4418
|
});
|
|
4160
4419
|
|
|
4161
4420
|
// src/rules/no-raw-env.ts
|
|
4162
|
-
var
|
|
4421
|
+
var import_utils26 = require("@typescript-eslint/utils");
|
|
4163
4422
|
var CONFIG_FILE_RE = /(^|[\\/])[\w.-]+\.config\.[cm]?[jt]sx?$/;
|
|
4164
4423
|
var ENV_BOUNDARY_FILE_RE = /(^|[\\/])(?:env|client-env|server-env|client-settings|server-settings)\.[cm]?[jt]sx?$/;
|
|
4165
4424
|
var ENV_VALIDATION_MARKER_RE = /\bcreateEnv\s*\(|\bz\.object\s*\(|\.(?:safeParse|parse)\s*\(/;
|
|
@@ -4236,7 +4495,7 @@ var no_raw_env_default = createRule({
|
|
|
4236
4495
|
});
|
|
4237
4496
|
|
|
4238
4497
|
// src/rules/no-raw-fetch-outside-clients.ts
|
|
4239
|
-
var
|
|
4498
|
+
var import_utils27 = require("@typescript-eslint/utils");
|
|
4240
4499
|
var DEFAULT_ALLOW = [
|
|
4241
4500
|
"[\\\\/]clients?[\\\\/]",
|
|
4242
4501
|
"-client\\.[cm]?[jt]sx?$",
|
|
@@ -4269,7 +4528,7 @@ function isGlobalFetchCall(node) {
|
|
|
4269
4528
|
}
|
|
4270
4529
|
function isConstructedArgumentHandoff(node) {
|
|
4271
4530
|
const [first] = node.arguments;
|
|
4272
|
-
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;
|
|
4273
4532
|
}
|
|
4274
4533
|
function isPresignedUrlTransfer(node) {
|
|
4275
4534
|
const first = node.arguments[0];
|
|
@@ -4347,9 +4606,9 @@ var no_raw_fetch_outside_clients_default = createRule({
|
|
|
4347
4606
|
});
|
|
4348
4607
|
|
|
4349
4608
|
// src/rules/no-restricted-library-load.ts
|
|
4350
|
-
var
|
|
4609
|
+
var import_utils28 = require("@typescript-eslint/utils");
|
|
4351
4610
|
function literalModule(node) {
|
|
4352
|
-
return node?.type ===
|
|
4611
|
+
return node?.type === import_utils28.AST_NODE_TYPES.Literal && typeof node.value === "string" ? node.value : null;
|
|
4353
4612
|
}
|
|
4354
4613
|
function matchesModule(source, module2) {
|
|
4355
4614
|
return source === module2 || source.startsWith(`${module2}/`);
|
|
@@ -4408,7 +4667,7 @@ var no_restricted_library_load_default = createRule({
|
|
|
4408
4667
|
});
|
|
4409
4668
|
}
|
|
4410
4669
|
function isUnshadowedRequire(node) {
|
|
4411
|
-
const variable =
|
|
4670
|
+
const variable = import_utils28.ASTUtils.findVariable(
|
|
4412
4671
|
context.sourceCode.getScope(node),
|
|
4413
4672
|
node.name
|
|
4414
4673
|
);
|
|
@@ -4421,9 +4680,9 @@ var no_restricted_library_load_default = createRule({
|
|
|
4421
4680
|
},
|
|
4422
4681
|
CallExpression(node) {
|
|
4423
4682
|
let requireIdentifier = null;
|
|
4424
|
-
if (node.callee.type ===
|
|
4683
|
+
if (node.callee.type === import_utils28.AST_NODE_TYPES.Identifier && node.callee.name === "require") {
|
|
4425
4684
|
requireIdentifier = node.callee;
|
|
4426
|
-
} 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") {
|
|
4427
4686
|
requireIdentifier = node.callee.object;
|
|
4428
4687
|
}
|
|
4429
4688
|
if (requireIdentifier === null || !isUnshadowedRequire(requireIdentifier)) return;
|
|
@@ -4431,7 +4690,7 @@ var no_restricted_library_load_default = createRule({
|
|
|
4431
4690
|
if (source !== null) report(node.arguments[0], source);
|
|
4432
4691
|
},
|
|
4433
4692
|
TSImportEqualsDeclaration(node) {
|
|
4434
|
-
if (node.moduleReference.type !==
|
|
4693
|
+
if (node.moduleReference.type !== import_utils28.AST_NODE_TYPES.TSExternalModuleReference) return;
|
|
4435
4694
|
const source = literalModule(node.moduleReference.expression);
|
|
4436
4695
|
if (source !== null) report(node.moduleReference.expression, source);
|
|
4437
4696
|
}
|
|
@@ -4440,16 +4699,16 @@ var no_restricted_library_load_default = createRule({
|
|
|
4440
4699
|
});
|
|
4441
4700
|
|
|
4442
4701
|
// src/rules/no-repeated-string-literal.ts
|
|
4443
|
-
var
|
|
4702
|
+
var import_utils29 = require("@typescript-eslint/utils");
|
|
4444
4703
|
var MIN_LENGTH = 40;
|
|
4445
4704
|
var MIN_DISTINCT_SCOPES = 2;
|
|
4446
4705
|
var PREVIEW_LENGTH = 40;
|
|
4447
4706
|
var SQL_KEYWORD_RE = /\b(SELECT|INSERT|UPDATE|DELETE|FROM|WHERE|JOIN|VALUES|ON CONFLICT|RETURNING|GROUP BY|ORDER BY)\b/;
|
|
4448
4707
|
var IDENTIFIER_RE = /^[a-z_][a-z0-9_.]*$/;
|
|
4449
4708
|
var FUNCTION_TYPES4 = /* @__PURE__ */ new Set([
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4709
|
+
import_utils29.AST_NODE_TYPES.FunctionDeclaration,
|
|
4710
|
+
import_utils29.AST_NODE_TYPES.FunctionExpression,
|
|
4711
|
+
import_utils29.AST_NODE_TYPES.ArrowFunctionExpression
|
|
4453
4712
|
]);
|
|
4454
4713
|
function isStructured(value) {
|
|
4455
4714
|
return value.includes("\n") || SQL_KEYWORD_RE.test(value) || IDENTIFIER_RE.test(value);
|
|
@@ -4471,8 +4730,8 @@ function isScaffolding(node) {
|
|
|
4471
4730
|
if (parent === void 0) {
|
|
4472
4731
|
return true;
|
|
4473
4732
|
}
|
|
4474
|
-
const isRequireSource = parent.type ===
|
|
4475
|
-
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;
|
|
4476
4735
|
}
|
|
4477
4736
|
var no_repeated_string_literal_default = createRule({
|
|
4478
4737
|
name: "no-repeated-string-literal",
|
|
@@ -4512,7 +4771,7 @@ var no_repeated_string_literal_default = createRule({
|
|
|
4512
4771
|
}
|
|
4513
4772
|
},
|
|
4514
4773
|
TemplateLiteral(node) {
|
|
4515
|
-
if (node.parent.type ===
|
|
4774
|
+
if (node.parent.type === import_utils29.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
4516
4775
|
return;
|
|
4517
4776
|
}
|
|
4518
4777
|
const [only] = node.quasis;
|
|
@@ -4546,7 +4805,7 @@ var no_repeated_string_literal_default = createRule({
|
|
|
4546
4805
|
});
|
|
4547
4806
|
|
|
4548
4807
|
// src/rules/no-restated-comment.ts
|
|
4549
|
-
var
|
|
4808
|
+
var import_utils30 = require("@typescript-eslint/utils");
|
|
4550
4809
|
var MAX_WORDS = 8;
|
|
4551
4810
|
var MIN_CONTENT_TOKENS = 2;
|
|
4552
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;
|
|
@@ -4599,7 +4858,7 @@ var no_restated_comment_default = createRule({
|
|
|
4599
4858
|
function labelsASiblingRun(comment) {
|
|
4600
4859
|
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
4601
4860
|
if (token === null) return false;
|
|
4602
|
-
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) {
|
|
4603
4862
|
if (headsSiblingRun(node)) return true;
|
|
4604
4863
|
}
|
|
4605
4864
|
return false;
|
|
@@ -4659,7 +4918,7 @@ var no_restated_comment_default = createRule({
|
|
|
4659
4918
|
});
|
|
4660
4919
|
|
|
4661
4920
|
// src/rules/no-restated-jsdoc.ts
|
|
4662
|
-
var
|
|
4921
|
+
var import_utils31 = require("@typescript-eslint/utils");
|
|
4663
4922
|
var MODELLED_TAGS = /* @__PURE__ */ new Set([
|
|
4664
4923
|
"arg",
|
|
4665
4924
|
"argument",
|
|
@@ -4713,30 +4972,30 @@ function declarationNames(node) {
|
|
|
4713
4972
|
switch (node.type) {
|
|
4714
4973
|
// `export function f()` — the JSDoc sits above the `export`, so the token
|
|
4715
4974
|
// after it resolves to the wrapper, not to the thing being documented.
|
|
4716
|
-
case
|
|
4717
|
-
case
|
|
4975
|
+
case import_utils31.AST_NODE_TYPES.ExportNamedDeclaration:
|
|
4976
|
+
case import_utils31.AST_NODE_TYPES.ExportDefaultDeclaration:
|
|
4718
4977
|
return node.declaration == null ? null : declarationNames(node.declaration);
|
|
4719
|
-
case
|
|
4720
|
-
case
|
|
4978
|
+
case import_utils31.AST_NODE_TYPES.FunctionDeclaration:
|
|
4979
|
+
case import_utils31.AST_NODE_TYPES.TSDeclareFunction:
|
|
4721
4980
|
return node.id === null ? null : { name: node.id.name, params: paramNames(node.params) };
|
|
4722
|
-
case
|
|
4723
|
-
case
|
|
4724
|
-
case
|
|
4725
|
-
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:
|
|
4726
4985
|
return node.id === null ? null : { name: node.id.name, params: [] };
|
|
4727
|
-
case
|
|
4986
|
+
case import_utils31.AST_NODE_TYPES.VariableDeclaration: {
|
|
4728
4987
|
const declarator = node.declarations[0];
|
|
4729
|
-
if (declarator === void 0 || declarator.id.type !==
|
|
4988
|
+
if (declarator === void 0 || declarator.id.type !== import_utils31.AST_NODE_TYPES.Identifier) return null;
|
|
4730
4989
|
const init = declarator.init;
|
|
4731
|
-
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) : [];
|
|
4732
4991
|
return { name: declarator.id.name, params };
|
|
4733
4992
|
}
|
|
4734
|
-
case
|
|
4735
|
-
case
|
|
4736
|
-
case
|
|
4737
|
-
case
|
|
4738
|
-
if (node.key.type !==
|
|
4739
|
-
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) : [];
|
|
4740
4999
|
return { name: node.key.name, params };
|
|
4741
5000
|
}
|
|
4742
5001
|
default:
|
|
@@ -4746,9 +5005,9 @@ function declarationNames(node) {
|
|
|
4746
5005
|
function paramNames(params) {
|
|
4747
5006
|
const names = [];
|
|
4748
5007
|
for (const param of params) {
|
|
4749
|
-
const target = param.type ===
|
|
4750
|
-
if (target.type ===
|
|
4751
|
-
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;
|
|
4752
5011
|
}
|
|
4753
5012
|
return names;
|
|
4754
5013
|
}
|
|
@@ -4790,7 +5049,7 @@ var no_restated_jsdoc_default = createRule({
|
|
|
4790
5049
|
if (token === null || token.loc.start.line !== comment.loc.end.line + 1) continue;
|
|
4791
5050
|
let node = sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
4792
5051
|
let declaration = null;
|
|
4793
|
-
while (node != null && node.type !==
|
|
5052
|
+
while (node != null && node.type !== import_utils31.AST_NODE_TYPES.Program) {
|
|
4794
5053
|
declaration = declarationNames(node);
|
|
4795
5054
|
if (declaration !== null) break;
|
|
4796
5055
|
node = node.parent ?? null;
|
|
@@ -4845,7 +5104,7 @@ var no_restated_jsdoc_default = createRule({
|
|
|
4845
5104
|
});
|
|
4846
5105
|
|
|
4847
5106
|
// src/rules/no-secret-in-log.ts
|
|
4848
|
-
var
|
|
5107
|
+
var import_utils32 = require("@typescript-eslint/utils");
|
|
4849
5108
|
|
|
4850
5109
|
// src/rules/_secret-names.ts
|
|
4851
5110
|
var SECRET_WORDS = /* @__PURE__ */ new Set([
|
|
@@ -5139,11 +5398,11 @@ var no_secret_in_log_default = createRule({
|
|
|
5139
5398
|
return true;
|
|
5140
5399
|
}
|
|
5141
5400
|
function reportSecretProperty(prop) {
|
|
5142
|
-
const
|
|
5143
|
-
if (
|
|
5401
|
+
const keyName = propertyKeyName2(prop);
|
|
5402
|
+
if (keyName === null || !isSecretKeyword(keyName) || !isRawSecretValue(prop)) {
|
|
5144
5403
|
return false;
|
|
5145
5404
|
}
|
|
5146
|
-
context.report({ node: prop, messageId: "noSecretInLog", data: { name:
|
|
5405
|
+
context.report({ node: prop, messageId: "noSecretInLog", data: { name: keyName } });
|
|
5147
5406
|
return true;
|
|
5148
5407
|
}
|
|
5149
5408
|
function reportRawBlob(node, value) {
|
|
@@ -5182,7 +5441,7 @@ var no_secret_in_log_default = createRule({
|
|
|
5182
5441
|
});
|
|
5183
5442
|
|
|
5184
5443
|
// src/rules/no-select-star.ts
|
|
5185
|
-
var
|
|
5444
|
+
var import_utils33 = require("@typescript-eslint/utils");
|
|
5186
5445
|
var QUERY_SHAPE = /\bSELECT\b[\s\S]*?\bFROM\b/i;
|
|
5187
5446
|
var SELECT_KEYWORD = /\bSELECT\b/gi;
|
|
5188
5447
|
var FROM_KEYWORD = /^FROM\b/i;
|
|
@@ -5249,10 +5508,10 @@ var no_select_star_default = createRule({
|
|
|
5249
5508
|
});
|
|
5250
5509
|
|
|
5251
5510
|
// src/rules/no-sentinel-return-on-catch.ts
|
|
5252
|
-
var
|
|
5511
|
+
var import_utils34 = require("@typescript-eslint/utils");
|
|
5253
5512
|
function unwrapSentinelExpression(arg) {
|
|
5254
5513
|
let current = arg;
|
|
5255
|
-
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) {
|
|
5256
5515
|
current = current.expression;
|
|
5257
5516
|
}
|
|
5258
5517
|
return current;
|
|
@@ -5262,7 +5521,7 @@ function sentinelKind(arg) {
|
|
|
5262
5521
|
if (value === null) {
|
|
5263
5522
|
return null;
|
|
5264
5523
|
}
|
|
5265
|
-
if (value.type ===
|
|
5524
|
+
if (value.type === import_utils34.AST_NODE_TYPES.Literal) {
|
|
5266
5525
|
if (value.value === null) {
|
|
5267
5526
|
return "nullish";
|
|
5268
5527
|
}
|
|
@@ -5274,13 +5533,13 @@ function sentinelKind(arg) {
|
|
|
5274
5533
|
}
|
|
5275
5534
|
return null;
|
|
5276
5535
|
}
|
|
5277
|
-
if (value.type ===
|
|
5536
|
+
if (value.type === import_utils34.AST_NODE_TYPES.Identifier && value.name === "undefined") {
|
|
5278
5537
|
return "nullish";
|
|
5279
5538
|
}
|
|
5280
|
-
if (value.type ===
|
|
5539
|
+
if (value.type === import_utils34.AST_NODE_TYPES.ArrayExpression) {
|
|
5281
5540
|
return "array";
|
|
5282
5541
|
}
|
|
5283
|
-
if (value.type ===
|
|
5542
|
+
if (value.type === import_utils34.AST_NODE_TYPES.ObjectExpression) {
|
|
5284
5543
|
return "object";
|
|
5285
5544
|
}
|
|
5286
5545
|
return null;
|
|
@@ -5290,25 +5549,25 @@ function isSentinelArgument(arg) {
|
|
|
5290
5549
|
if (value === null) {
|
|
5291
5550
|
return false;
|
|
5292
5551
|
}
|
|
5293
|
-
if (value.type ===
|
|
5552
|
+
if (value.type === import_utils34.AST_NODE_TYPES.Literal && value.value === null) {
|
|
5294
5553
|
return true;
|
|
5295
5554
|
}
|
|
5296
|
-
if (value.type ===
|
|
5555
|
+
if (value.type === import_utils34.AST_NODE_TYPES.Literal && value.value === false) {
|
|
5297
5556
|
return true;
|
|
5298
5557
|
}
|
|
5299
|
-
if (value.type ===
|
|
5558
|
+
if (value.type === import_utils34.AST_NODE_TYPES.Identifier && value.name === "undefined") {
|
|
5300
5559
|
return true;
|
|
5301
5560
|
}
|
|
5302
|
-
if (value.type ===
|
|
5561
|
+
if (value.type === import_utils34.AST_NODE_TYPES.ArrayExpression && value.elements.length === 0) {
|
|
5303
5562
|
return true;
|
|
5304
5563
|
}
|
|
5305
|
-
if (value.type ===
|
|
5564
|
+
if (value.type === import_utils34.AST_NODE_TYPES.ObjectExpression && value.properties.length === 0) {
|
|
5306
5565
|
return true;
|
|
5307
5566
|
}
|
|
5308
5567
|
return false;
|
|
5309
5568
|
}
|
|
5310
5569
|
function isFunctionNode(node) {
|
|
5311
|
-
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;
|
|
5312
5571
|
}
|
|
5313
5572
|
function isNode3(value) {
|
|
5314
5573
|
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
@@ -5348,24 +5607,24 @@ function walkWithinScope(node, visit) {
|
|
|
5348
5607
|
function containsThrow(node) {
|
|
5349
5608
|
return walkWithinScope(
|
|
5350
5609
|
node,
|
|
5351
|
-
(current) => current.type ===
|
|
5610
|
+
(current) => current.type === import_utils34.AST_NODE_TYPES.ThrowStatement
|
|
5352
5611
|
);
|
|
5353
5612
|
}
|
|
5354
5613
|
function bindsName(param, name) {
|
|
5355
5614
|
switch (param.type) {
|
|
5356
|
-
case
|
|
5615
|
+
case import_utils34.AST_NODE_TYPES.Identifier:
|
|
5357
5616
|
return param.name === name;
|
|
5358
|
-
case
|
|
5617
|
+
case import_utils34.AST_NODE_TYPES.AssignmentPattern:
|
|
5359
5618
|
return bindsName(param.left, name);
|
|
5360
|
-
case
|
|
5619
|
+
case import_utils34.AST_NODE_TYPES.RestElement:
|
|
5361
5620
|
return bindsName(param.argument, name);
|
|
5362
|
-
case
|
|
5621
|
+
case import_utils34.AST_NODE_TYPES.ArrayPattern:
|
|
5363
5622
|
return param.elements.some(
|
|
5364
5623
|
(element) => element !== null && bindsName(element, name)
|
|
5365
5624
|
);
|
|
5366
|
-
case
|
|
5625
|
+
case import_utils34.AST_NODE_TYPES.ObjectPattern:
|
|
5367
5626
|
return param.properties.some(
|
|
5368
|
-
(property) => property.type ===
|
|
5627
|
+
(property) => property.type === import_utils34.AST_NODE_TYPES.RestElement ? bindsName(property.argument, name) : bindsName(property.value, name)
|
|
5369
5628
|
);
|
|
5370
5629
|
default:
|
|
5371
5630
|
return false;
|
|
@@ -5380,7 +5639,7 @@ function subtreeReadsName(node, name) {
|
|
|
5380
5639
|
if (found) {
|
|
5381
5640
|
return;
|
|
5382
5641
|
}
|
|
5383
|
-
if (current.type ===
|
|
5642
|
+
if (current.type === import_utils34.AST_NODE_TYPES.Identifier && current.name === name) {
|
|
5384
5643
|
found = true;
|
|
5385
5644
|
return;
|
|
5386
5645
|
}
|
|
@@ -5391,10 +5650,10 @@ function subtreeReadsName(node, name) {
|
|
|
5391
5650
|
if (key === "parent") {
|
|
5392
5651
|
continue;
|
|
5393
5652
|
}
|
|
5394
|
-
if (key === "key" && current.type ===
|
|
5653
|
+
if (key === "key" && current.type === import_utils34.AST_NODE_TYPES.Property && !current.computed) {
|
|
5395
5654
|
continue;
|
|
5396
5655
|
}
|
|
5397
|
-
if (key === "property" && current.type ===
|
|
5656
|
+
if (key === "property" && current.type === import_utils34.AST_NODE_TYPES.MemberExpression && !current.computed) {
|
|
5398
5657
|
continue;
|
|
5399
5658
|
}
|
|
5400
5659
|
const value = current[key];
|
|
@@ -5419,10 +5678,10 @@ function argsIncludeBinding(args, caughtName) {
|
|
|
5419
5678
|
return args.some((arg) => subtreeReadsName(arg, caughtName));
|
|
5420
5679
|
}
|
|
5421
5680
|
function isParseShapedNode(node) {
|
|
5422
|
-
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) {
|
|
5423
5682
|
return node.callee.property.name === "parse";
|
|
5424
5683
|
}
|
|
5425
|
-
if (node.type ===
|
|
5684
|
+
if (node.type === import_utils34.AST_NODE_TYPES.NewExpression && node.callee.type === import_utils34.AST_NODE_TYPES.Identifier) {
|
|
5426
5685
|
return SAFE_PARSE_CONSTRUCTORS.has(node.callee.name);
|
|
5427
5686
|
}
|
|
5428
5687
|
return false;
|
|
@@ -5433,7 +5692,7 @@ var SAFE_PARSE_CONSTRUCTORS = /* @__PURE__ */ new Set([
|
|
|
5433
5692
|
"URLPattern"
|
|
5434
5693
|
]);
|
|
5435
5694
|
function isBodyDecodeNode(node) {
|
|
5436
|
-
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);
|
|
5437
5696
|
}
|
|
5438
5697
|
var BODY_DECODE_METHODS = /* @__PURE__ */ new Set([
|
|
5439
5698
|
"json",
|
|
@@ -5441,7 +5700,7 @@ var BODY_DECODE_METHODS = /* @__PURE__ */ new Set([
|
|
|
5441
5700
|
"arrayBuffer"
|
|
5442
5701
|
]);
|
|
5443
5702
|
function returnsMatching(stmt, predicate) {
|
|
5444
|
-
return stmt.type ===
|
|
5703
|
+
return stmt.type === import_utils34.AST_NODE_TYPES.ReturnStatement && stmt.argument !== null && walkWithinScope(stmt.argument, predicate);
|
|
5445
5704
|
}
|
|
5446
5705
|
function isNamedBooleanPredicate(catchNode, kind) {
|
|
5447
5706
|
if (kind !== "boolean") {
|
|
@@ -5454,11 +5713,11 @@ function enclosingFunctionName(node) {
|
|
|
5454
5713
|
let current = node.parent;
|
|
5455
5714
|
while (current !== void 0 && current !== null) {
|
|
5456
5715
|
if (isFunctionNode(current)) {
|
|
5457
|
-
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) {
|
|
5458
5717
|
return current.id.name;
|
|
5459
5718
|
}
|
|
5460
5719
|
const parent = current.parent;
|
|
5461
|
-
if (parent?.type ===
|
|
5720
|
+
if (parent?.type === import_utils34.AST_NODE_TYPES.VariableDeclarator && parent.id.type === import_utils34.AST_NODE_TYPES.Identifier) {
|
|
5462
5721
|
return parent.id.name;
|
|
5463
5722
|
}
|
|
5464
5723
|
return null;
|
|
@@ -5474,10 +5733,10 @@ function isDeclaredBooleanPredicate(catchNode, kind) {
|
|
|
5474
5733
|
return false;
|
|
5475
5734
|
}
|
|
5476
5735
|
let declared = enclosingReturnTypeNode(catchNode);
|
|
5477
|
-
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") {
|
|
5478
5737
|
declared = declared.typeArguments?.params[0] ?? null;
|
|
5479
5738
|
}
|
|
5480
|
-
return declared?.type ===
|
|
5739
|
+
return declared?.type === import_utils34.AST_NODE_TYPES.TSBooleanKeyword;
|
|
5481
5740
|
}
|
|
5482
5741
|
function enclosingReturnTypeNode(node) {
|
|
5483
5742
|
let current = node.parent;
|
|
@@ -5504,9 +5763,9 @@ function isIntentionalStackCapture(catchNode, caughtName) {
|
|
|
5504
5763
|
if (caughtName === null) return false;
|
|
5505
5764
|
const tryBody = tryBlockOf(catchNode).body;
|
|
5506
5765
|
const only = tryBody.length === 1 ? tryBody[0] : void 0;
|
|
5507
|
-
if (only?.type !==
|
|
5766
|
+
if (only?.type !== import_utils34.AST_NODE_TYPES.ThrowStatement) return false;
|
|
5508
5767
|
const thrown = unwrapSentinelExpression(only.argument);
|
|
5509
|
-
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";
|
|
5510
5769
|
if (!constructsError) return false;
|
|
5511
5770
|
return catchNode.body.body.slice(0, -1).some((statement) => subtreeReadsName(statement, caughtName));
|
|
5512
5771
|
}
|
|
@@ -5519,7 +5778,7 @@ function functionReturnsSameSentinelKindElsewhere(catchNode, kind) {
|
|
|
5519
5778
|
return false;
|
|
5520
5779
|
}
|
|
5521
5780
|
return walkWithinScope(functionBody, (current) => {
|
|
5522
|
-
if (current.type !==
|
|
5781
|
+
if (current.type !== import_utils34.AST_NODE_TYPES.ReturnStatement) {
|
|
5523
5782
|
return false;
|
|
5524
5783
|
}
|
|
5525
5784
|
if (isWithin(current, catchNode.body)) {
|
|
@@ -5531,7 +5790,7 @@ function functionReturnsSameSentinelKindElsewhere(catchNode, kind) {
|
|
|
5531
5790
|
function enclosingFunctionBody(node) {
|
|
5532
5791
|
let current = node.parent;
|
|
5533
5792
|
while (current !== void 0 && current !== null) {
|
|
5534
|
-
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) {
|
|
5535
5794
|
return current.body;
|
|
5536
5795
|
}
|
|
5537
5796
|
current = current.parent;
|
|
@@ -5548,13 +5807,13 @@ function returnedSentinelKinds(arg) {
|
|
|
5548
5807
|
kinds.add(direct);
|
|
5549
5808
|
return kinds;
|
|
5550
5809
|
}
|
|
5551
|
-
if (arg.type ===
|
|
5810
|
+
if (arg.type === import_utils34.AST_NODE_TYPES.ConditionalExpression) {
|
|
5552
5811
|
for (const branch of [arg.consequent, arg.alternate]) {
|
|
5553
5812
|
for (const nested of returnedSentinelKinds(branch)) {
|
|
5554
5813
|
kinds.add(nested);
|
|
5555
5814
|
}
|
|
5556
5815
|
}
|
|
5557
|
-
} else if (arg.type ===
|
|
5816
|
+
} else if (arg.type === import_utils34.AST_NODE_TYPES.LogicalExpression && (arg.operator === "??" || arg.operator === "||")) {
|
|
5558
5817
|
for (const nested of returnedSentinelKinds(arg.right)) {
|
|
5559
5818
|
kinds.add(nested);
|
|
5560
5819
|
}
|
|
@@ -5597,7 +5856,7 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
5597
5856
|
const matcher = createLogMatcher(loggingOptions);
|
|
5598
5857
|
function logsOrReportsError(catchBody, caughtName) {
|
|
5599
5858
|
return walkWithinScope(catchBody, (current) => {
|
|
5600
|
-
if (current.type !==
|
|
5859
|
+
if (current.type !== import_utils34.AST_NODE_TYPES.CallExpression) {
|
|
5601
5860
|
return false;
|
|
5602
5861
|
}
|
|
5603
5862
|
if (matcher.isLoggingCall(current)) {
|
|
@@ -5614,7 +5873,7 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
5614
5873
|
return;
|
|
5615
5874
|
}
|
|
5616
5875
|
const last = body2[body2.length - 1];
|
|
5617
|
-
if (last === void 0 || last.type !==
|
|
5876
|
+
if (last === void 0 || last.type !== import_utils34.AST_NODE_TYPES.ReturnStatement) {
|
|
5618
5877
|
return;
|
|
5619
5878
|
}
|
|
5620
5879
|
if (!isSentinelArgument(last.argument)) {
|
|
@@ -5623,7 +5882,7 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
5623
5882
|
if (containsThrow(node.body)) {
|
|
5624
5883
|
return;
|
|
5625
5884
|
}
|
|
5626
|
-
const caughtName = node.param?.type ===
|
|
5885
|
+
const caughtName = node.param?.type === import_utils34.AST_NODE_TYPES.Identifier ? node.param.name : null;
|
|
5627
5886
|
if (logsOrReportsError(node.body, caughtName)) {
|
|
5628
5887
|
return;
|
|
5629
5888
|
}
|
|
@@ -5653,9 +5912,9 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
5653
5912
|
});
|
|
5654
5913
|
|
|
5655
5914
|
// src/rules/no-silent-promise-catch.ts
|
|
5656
|
-
var
|
|
5915
|
+
var import_utils35 = require("@typescript-eslint/utils");
|
|
5657
5916
|
function isBodyParseCall(node) {
|
|
5658
|
-
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");
|
|
5659
5918
|
}
|
|
5660
5919
|
var TEARDOWN_METHODS = /* @__PURE__ */ new Set([
|
|
5661
5920
|
"cancel",
|
|
@@ -5670,11 +5929,11 @@ var TEARDOWN_METHODS = /* @__PURE__ */ new Set([
|
|
|
5670
5929
|
var DIRECTIVE_COMMENT_RE = /^\s*(eslint-|@ts-|prettier-ignore|biome-ignore|c8 |v8 |istanbul )/;
|
|
5671
5930
|
var isExplanatory = (comment) => !DIRECTIVE_COMMENT_RE.test(comment.value);
|
|
5672
5931
|
function isTeardownCall(node) {
|
|
5673
|
-
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);
|
|
5674
5933
|
}
|
|
5675
5934
|
function isSilentHandler(handler) {
|
|
5676
5935
|
const body2 = handler.body;
|
|
5677
|
-
if (body2.type !==
|
|
5936
|
+
if (body2.type !== import_utils35.AST_NODE_TYPES.BlockStatement) {
|
|
5678
5937
|
return isSilentExpression(body2);
|
|
5679
5938
|
}
|
|
5680
5939
|
if (body2.body.length === 0) {
|
|
@@ -5682,7 +5941,7 @@ function isSilentHandler(handler) {
|
|
|
5682
5941
|
}
|
|
5683
5942
|
if (body2.body.length === 1) {
|
|
5684
5943
|
const only = body2.body[0];
|
|
5685
|
-
if (only !== void 0 && only.type ===
|
|
5944
|
+
if (only !== void 0 && only.type === import_utils35.AST_NODE_TYPES.ReturnStatement) {
|
|
5686
5945
|
return only.argument === null || isSilentExpression(only.argument);
|
|
5687
5946
|
}
|
|
5688
5947
|
}
|
|
@@ -5690,17 +5949,17 @@ function isSilentHandler(handler) {
|
|
|
5690
5949
|
}
|
|
5691
5950
|
function isSilentExpression(node) {
|
|
5692
5951
|
switch (node.type) {
|
|
5693
|
-
case
|
|
5952
|
+
case import_utils35.AST_NODE_TYPES.Literal:
|
|
5694
5953
|
return !("regex" in node);
|
|
5695
|
-
case
|
|
5954
|
+
case import_utils35.AST_NODE_TYPES.Identifier:
|
|
5696
5955
|
return node.name === "undefined";
|
|
5697
|
-
case
|
|
5698
|
-
return node.operator === "void" && node.argument.type ===
|
|
5699
|
-
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:
|
|
5700
5959
|
return node.properties.length === 0;
|
|
5701
|
-
case
|
|
5960
|
+
case import_utils35.AST_NODE_TYPES.ArrayExpression:
|
|
5702
5961
|
return node.elements.length === 0;
|
|
5703
|
-
case
|
|
5962
|
+
case import_utils35.AST_NODE_TYPES.TSAsExpression:
|
|
5704
5963
|
return isSilentExpression(node.expression);
|
|
5705
5964
|
default:
|
|
5706
5965
|
return false;
|
|
@@ -5729,7 +5988,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
5729
5988
|
return true;
|
|
5730
5989
|
}
|
|
5731
5990
|
let statement = call;
|
|
5732
|
-
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) {
|
|
5733
5992
|
statement = statement.parent;
|
|
5734
5993
|
}
|
|
5735
5994
|
if (sourceCode.getCommentsBefore(statement).some(isExplanatory)) {
|
|
@@ -5741,7 +6000,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
5741
6000
|
};
|
|
5742
6001
|
return {
|
|
5743
6002
|
CallExpression(node) {
|
|
5744
|
-
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) {
|
|
5745
6004
|
return;
|
|
5746
6005
|
}
|
|
5747
6006
|
const method = node.callee.property.name;
|
|
@@ -5753,7 +6012,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
5753
6012
|
if (isTeardownCall(node.callee.object)) {
|
|
5754
6013
|
return;
|
|
5755
6014
|
}
|
|
5756
|
-
if (node.parent.type ===
|
|
6015
|
+
if (node.parent.type === import_utils35.AST_NODE_TYPES.MemberExpression && node.parent.object === node) {
|
|
5757
6016
|
return;
|
|
5758
6017
|
}
|
|
5759
6018
|
const expectedArguments = method === "catch" ? 1 : 2;
|
|
@@ -5761,7 +6020,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
5761
6020
|
return;
|
|
5762
6021
|
}
|
|
5763
6022
|
const handler = node.arguments[handlerIndex];
|
|
5764
|
-
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) {
|
|
5765
6024
|
return;
|
|
5766
6025
|
}
|
|
5767
6026
|
if (hasExplanatoryComment(node, handler)) {
|
|
@@ -5776,7 +6035,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
5776
6035
|
});
|
|
5777
6036
|
|
|
5778
6037
|
// src/rules/no-sleep-in-test-body.ts
|
|
5779
|
-
var
|
|
6038
|
+
var import_utils36 = require("@typescript-eslint/utils");
|
|
5780
6039
|
var SLEEP_HELPERS = /* @__PURE__ */ new Set(["sleep", "delay", "wait", "pause"]);
|
|
5781
6040
|
var TEST_CALLERS3 = /* @__PURE__ */ new Set([
|
|
5782
6041
|
"it",
|
|
@@ -5785,34 +6044,34 @@ var TEST_CALLERS3 = /* @__PURE__ */ new Set([
|
|
|
5785
6044
|
"afterEach"
|
|
5786
6045
|
]);
|
|
5787
6046
|
var FUNCTION_TYPES5 = /* @__PURE__ */ new Set([
|
|
5788
|
-
|
|
5789
|
-
|
|
5790
|
-
|
|
6047
|
+
import_utils36.AST_NODE_TYPES.FunctionDeclaration,
|
|
6048
|
+
import_utils36.AST_NODE_TYPES.FunctionExpression,
|
|
6049
|
+
import_utils36.AST_NODE_TYPES.ArrowFunctionExpression
|
|
5791
6050
|
]);
|
|
5792
6051
|
function isNonzeroNumericLiteral(node) {
|
|
5793
|
-
return node?.type ===
|
|
6052
|
+
return node?.type === import_utils36.AST_NODE_TYPES.Literal && typeof node.value === "number" && node.value !== 0;
|
|
5794
6053
|
}
|
|
5795
6054
|
function isTimedSetTimeout(node) {
|
|
5796
|
-
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]);
|
|
5797
6056
|
}
|
|
5798
6057
|
function isPromiseSleep(node) {
|
|
5799
|
-
if (node.callee.type !==
|
|
6058
|
+
if (node.callee.type !== import_utils36.AST_NODE_TYPES.Identifier || node.callee.name !== "Promise") {
|
|
5800
6059
|
return false;
|
|
5801
6060
|
}
|
|
5802
6061
|
const executor = node.arguments[0];
|
|
5803
|
-
if (executor?.type !==
|
|
6062
|
+
if (executor?.type !== import_utils36.AST_NODE_TYPES.ArrowFunctionExpression && executor?.type !== import_utils36.AST_NODE_TYPES.FunctionExpression) {
|
|
5804
6063
|
return false;
|
|
5805
6064
|
}
|
|
5806
6065
|
const body2 = executor.body;
|
|
5807
|
-
if (body2.type !==
|
|
6066
|
+
if (body2.type !== import_utils36.AST_NODE_TYPES.BlockStatement) {
|
|
5808
6067
|
return isTimedSetTimeout(body2);
|
|
5809
6068
|
}
|
|
5810
6069
|
return body2.body.some(
|
|
5811
|
-
(stmt) => stmt.type ===
|
|
6070
|
+
(stmt) => stmt.type === import_utils36.AST_NODE_TYPES.ExpressionStatement && isTimedSetTimeout(stmt.expression)
|
|
5812
6071
|
);
|
|
5813
6072
|
}
|
|
5814
6073
|
function isHelperSleep(node) {
|
|
5815
|
-
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]);
|
|
5816
6075
|
}
|
|
5817
6076
|
function nearestEnclosingFunction2(node) {
|
|
5818
6077
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
@@ -5820,7 +6079,7 @@ function nearestEnclosingFunction2(node) {
|
|
|
5820
6079
|
continue;
|
|
5821
6080
|
}
|
|
5822
6081
|
const grandparent = current.parent;
|
|
5823
|
-
const isPromiseExecutor = grandparent?.type ===
|
|
6082
|
+
const isPromiseExecutor = grandparent?.type === import_utils36.AST_NODE_TYPES.NewExpression && isPromiseSleep(grandparent);
|
|
5824
6083
|
if (!isPromiseExecutor) {
|
|
5825
6084
|
return current;
|
|
5826
6085
|
}
|
|
@@ -5829,23 +6088,23 @@ function nearestEnclosingFunction2(node) {
|
|
|
5829
6088
|
}
|
|
5830
6089
|
function isTestBody2(fn) {
|
|
5831
6090
|
const call = fn.parent;
|
|
5832
|
-
if (call?.type !==
|
|
6091
|
+
if (call?.type !== import_utils36.AST_NODE_TYPES.CallExpression || !call.arguments.some((argument) => argument === fn)) {
|
|
5833
6092
|
return false;
|
|
5834
6093
|
}
|
|
5835
6094
|
const name = testCallerName2(call.callee);
|
|
5836
6095
|
return name !== null && TEST_CALLERS3.has(name);
|
|
5837
6096
|
}
|
|
5838
6097
|
function testCallerName2(callee) {
|
|
5839
|
-
if (callee.type ===
|
|
6098
|
+
if (callee.type === import_utils36.AST_NODE_TYPES.Identifier) {
|
|
5840
6099
|
return callee.name;
|
|
5841
6100
|
}
|
|
5842
|
-
if (callee.type ===
|
|
6101
|
+
if (callee.type === import_utils36.AST_NODE_TYPES.MemberExpression) {
|
|
5843
6102
|
return testCallerName2(callee.object);
|
|
5844
6103
|
}
|
|
5845
|
-
if (callee.type ===
|
|
6104
|
+
if (callee.type === import_utils36.AST_NODE_TYPES.CallExpression) {
|
|
5846
6105
|
return testCallerName2(callee.callee);
|
|
5847
6106
|
}
|
|
5848
|
-
if (callee.type ===
|
|
6107
|
+
if (callee.type === import_utils36.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
5849
6108
|
return testCallerName2(callee.tag);
|
|
5850
6109
|
}
|
|
5851
6110
|
return null;
|
|
@@ -5890,7 +6149,7 @@ var no_sleep_in_test_body_default = createRule({
|
|
|
5890
6149
|
});
|
|
5891
6150
|
|
|
5892
6151
|
// src/rules/no-storage-in-stateless-modules.ts
|
|
5893
|
-
var
|
|
6152
|
+
var import_utils37 = require("@typescript-eslint/utils");
|
|
5894
6153
|
var DEFAULT_METHODS2 = [
|
|
5895
6154
|
"prepare",
|
|
5896
6155
|
"put",
|
|
@@ -5909,7 +6168,7 @@ function compile2(patterns) {
|
|
|
5909
6168
|
}
|
|
5910
6169
|
function storageMethodName(node, methods) {
|
|
5911
6170
|
const callee = node.callee;
|
|
5912
|
-
if (callee.type !==
|
|
6171
|
+
if (callee.type !== import_utils37.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils37.AST_NODE_TYPES.Identifier) {
|
|
5913
6172
|
return null;
|
|
5914
6173
|
}
|
|
5915
6174
|
const name = callee.property.name;
|
|
@@ -5977,7 +6236,7 @@ var no_storage_in_stateless_modules_default = createRule({
|
|
|
5977
6236
|
});
|
|
5978
6237
|
|
|
5979
6238
|
// src/rules/no-string-concat-in-loop.ts
|
|
5980
|
-
var
|
|
6239
|
+
var import_utils38 = require("@typescript-eslint/utils");
|
|
5981
6240
|
var LOOP_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
5982
6241
|
"ForStatement",
|
|
5983
6242
|
"ForOfStatement",
|
|
@@ -6128,7 +6387,7 @@ var no_string_concat_in_loop_default = createRule({
|
|
|
6128
6387
|
});
|
|
6129
6388
|
|
|
6130
6389
|
// src/rules/no-tautological-expect.ts
|
|
6131
|
-
var
|
|
6390
|
+
var import_utils39 = require("@typescript-eslint/utils");
|
|
6132
6391
|
var EQUALITY_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
6133
6392
|
var ZERO_ARG_MATCHERS = /* @__PURE__ */ new Set([
|
|
6134
6393
|
"toBeDefined",
|
|
@@ -6142,17 +6401,17 @@ var OPERAND_PREVIEW_CHARS = 40;
|
|
|
6142
6401
|
var NUMERIC_SIGNS = /* @__PURE__ */ new Set(["-", "+"]);
|
|
6143
6402
|
function isLiteral(node) {
|
|
6144
6403
|
switch (node.type) {
|
|
6145
|
-
case
|
|
6404
|
+
case import_utils39.AST_NODE_TYPES.Literal:
|
|
6146
6405
|
return true;
|
|
6147
|
-
case
|
|
6406
|
+
case import_utils39.AST_NODE_TYPES.TemplateLiteral:
|
|
6148
6407
|
return node.expressions.length === 0;
|
|
6149
|
-
case
|
|
6408
|
+
case import_utils39.AST_NODE_TYPES.UnaryExpression:
|
|
6150
6409
|
return NUMERIC_SIGNS.has(node.operator) && isLiteral(node.argument);
|
|
6151
|
-
case
|
|
6410
|
+
case import_utils39.AST_NODE_TYPES.ArrayExpression:
|
|
6152
6411
|
return node.elements.every((element) => element !== null && isLiteral(element));
|
|
6153
|
-
case
|
|
6412
|
+
case import_utils39.AST_NODE_TYPES.ObjectExpression:
|
|
6154
6413
|
return node.properties.every(
|
|
6155
|
-
(property) => property.type ===
|
|
6414
|
+
(property) => property.type === import_utils39.AST_NODE_TYPES.Property && !property.computed && isLiteral(property.value)
|
|
6156
6415
|
);
|
|
6157
6416
|
default:
|
|
6158
6417
|
return false;
|
|
@@ -6160,7 +6419,7 @@ function isLiteral(node) {
|
|
|
6160
6419
|
}
|
|
6161
6420
|
function expectOperand(callee) {
|
|
6162
6421
|
const receiver = callee.object;
|
|
6163
|
-
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) {
|
|
6164
6423
|
return null;
|
|
6165
6424
|
}
|
|
6166
6425
|
return receiver.arguments[0] ?? null;
|
|
@@ -6190,10 +6449,10 @@ var no_tautological_expect_default = createRule({
|
|
|
6190
6449
|
return {
|
|
6191
6450
|
CallExpression(node) {
|
|
6192
6451
|
const callee = node.callee;
|
|
6193
|
-
if (callee.type !==
|
|
6452
|
+
if (callee.type !== import_utils39.AST_NODE_TYPES.MemberExpression || callee.computed) {
|
|
6194
6453
|
return;
|
|
6195
6454
|
}
|
|
6196
|
-
if (callee.property.type !==
|
|
6455
|
+
if (callee.property.type !== import_utils39.AST_NODE_TYPES.Identifier) {
|
|
6197
6456
|
return;
|
|
6198
6457
|
}
|
|
6199
6458
|
const matcher = callee.property.name;
|
|
@@ -6252,7 +6511,7 @@ var no_typed_doc_sections_default = createRule({
|
|
|
6252
6511
|
});
|
|
6253
6512
|
|
|
6254
6513
|
// src/rules/no-trailing-value-narration.ts
|
|
6255
|
-
var
|
|
6514
|
+
var import_utils40 = require("@typescript-eslint/utils");
|
|
6256
6515
|
var NUMBER_RE = /(?<![\w.])(\d+(?:\.\d+)?)(?![\w.])/g;
|
|
6257
6516
|
var WORD_RE3 = /[A-Za-z]+(?:'[a-z]+)?|\d+(?:\.\d+)?/g;
|
|
6258
6517
|
var UNIT_WORDS = /* @__PURE__ */ new Set([
|
|
@@ -6387,10 +6646,10 @@ var no_trailing_value_narration_default = createRule({
|
|
|
6387
6646
|
});
|
|
6388
6647
|
|
|
6389
6648
|
// src/rules/no-declaration-comment-wall.ts
|
|
6390
|
-
var
|
|
6649
|
+
var import_utils42 = require("@typescript-eslint/utils");
|
|
6391
6650
|
|
|
6392
6651
|
// src/rules/_comment-wall.ts
|
|
6393
|
-
var
|
|
6652
|
+
var import_utils41 = require("@typescript-eslint/utils");
|
|
6394
6653
|
var WALL_DEFAULTS = {
|
|
6395
6654
|
// Below three rows "a wall" is not a fair description of what the reader sees.
|
|
6396
6655
|
minCommentedMembers: 3,
|
|
@@ -6491,10 +6750,10 @@ function isWall(members, commented, restated, options) {
|
|
|
6491
6750
|
return commented >= options.minCommentedMembers && commented / members >= options.minCommentedRatio && restated / commented >= options.minRestatedRatio;
|
|
6492
6751
|
}
|
|
6493
6752
|
var OPAQUE_VALUE_TYPES = /* @__PURE__ */ new Set([
|
|
6494
|
-
|
|
6495
|
-
|
|
6496
|
-
|
|
6497
|
-
|
|
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
|
|
6498
6757
|
]);
|
|
6499
6758
|
function declarationRange(member) {
|
|
6500
6759
|
const body2 = bodyOf(member);
|
|
@@ -6504,10 +6763,10 @@ function declarationRange(member) {
|
|
|
6504
6763
|
};
|
|
6505
6764
|
}
|
|
6506
6765
|
function bodyOf(member) {
|
|
6507
|
-
if (member.type ===
|
|
6766
|
+
if (member.type === import_utils41.AST_NODE_TYPES.MethodDefinition || member.type === import_utils41.AST_NODE_TYPES.TSAbstractMethodDefinition) {
|
|
6508
6767
|
return member.value.body ?? void 0;
|
|
6509
6768
|
}
|
|
6510
|
-
if (member.type ===
|
|
6769
|
+
if (member.type === import_utils41.AST_NODE_TYPES.Property || member.type === import_utils41.AST_NODE_TYPES.PropertyDefinition) {
|
|
6511
6770
|
const value = member.value;
|
|
6512
6771
|
if (value !== null && OPAQUE_VALUE_TYPES.has(value.type)) return value;
|
|
6513
6772
|
}
|
|
@@ -6517,12 +6776,12 @@ function bodyOf(member) {
|
|
|
6517
6776
|
// src/rules/no-declaration-comment-wall.ts
|
|
6518
6777
|
function named(node) {
|
|
6519
6778
|
switch (node.type) {
|
|
6520
|
-
case
|
|
6779
|
+
case import_utils42.AST_NODE_TYPES.TSEnumMember:
|
|
6521
6780
|
return { node, key: node.id };
|
|
6522
|
-
case
|
|
6523
|
-
case
|
|
6524
|
-
case
|
|
6525
|
-
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:
|
|
6526
6785
|
return node.computed ? void 0 : { node, key: node.key };
|
|
6527
6786
|
default:
|
|
6528
6787
|
return void 0;
|
|
@@ -6622,7 +6881,7 @@ var no_declaration_comment_wall_default = createRule({
|
|
|
6622
6881
|
});
|
|
6623
6882
|
|
|
6624
6883
|
// src/rules/no-union-in-comment.ts
|
|
6625
|
-
var
|
|
6884
|
+
var import_utils43 = require("@typescript-eslint/utils");
|
|
6626
6885
|
var MAX_LITERAL_LENGTH = 28;
|
|
6627
6886
|
var LITERAL = String.raw`(?:'[^'\n]*'|"[^"\n]*"|\`[^\`\n]*\`)`;
|
|
6628
6887
|
var LEAD_IN_RE2 = /^(?:one of|either|values?|allowed(?: values)?|options?|possible(?: values)?)\s*[:=-]?\s*/i;
|
|
@@ -6641,14 +6900,14 @@ var STRING_BUILDERS = /* @__PURE__ */ new Set([
|
|
|
6641
6900
|
function isBareString(node) {
|
|
6642
6901
|
if (node === void 0) return false;
|
|
6643
6902
|
switch (node.type) {
|
|
6644
|
-
case
|
|
6903
|
+
case import_utils43.AST_NODE_TYPES.TSStringKeyword:
|
|
6645
6904
|
return true;
|
|
6646
6905
|
// `string[]` holds members of the same closed set, one element at a time.
|
|
6647
|
-
case
|
|
6906
|
+
case import_utils43.AST_NODE_TYPES.TSArrayType:
|
|
6648
6907
|
return isBareString(node.elementType);
|
|
6649
6908
|
// `string | null` is still an unconstrained string, and so is `string | "a"`
|
|
6650
6909
|
// — the checker collapses that one to `string`.
|
|
6651
|
-
case
|
|
6910
|
+
case import_utils43.AST_NODE_TYPES.TSUnionType:
|
|
6652
6911
|
return node.types.some((member) => isBareString(member));
|
|
6653
6912
|
default:
|
|
6654
6913
|
return false;
|
|
@@ -6656,20 +6915,20 @@ function isBareString(node) {
|
|
|
6656
6915
|
}
|
|
6657
6916
|
function targetOf(node) {
|
|
6658
6917
|
switch (node.type) {
|
|
6659
|
-
case
|
|
6660
|
-
case
|
|
6918
|
+
case import_utils43.AST_NODE_TYPES.TSPropertySignature:
|
|
6919
|
+
case import_utils43.AST_NODE_TYPES.PropertyDefinition: {
|
|
6661
6920
|
const name = node.computed ? null : nameOf(node.key);
|
|
6662
6921
|
if (name === null || !isBareString(node.typeAnnotation?.typeAnnotation)) return null;
|
|
6663
6922
|
return { node, name };
|
|
6664
6923
|
}
|
|
6665
|
-
case
|
|
6924
|
+
case import_utils43.AST_NODE_TYPES.Property: {
|
|
6666
6925
|
const name = node.computed || node.shorthand ? null : nameOf(node.key);
|
|
6667
6926
|
const callee = rootCallee(node.value);
|
|
6668
6927
|
if (name === null || callee === null || !STRING_BUILDERS.has(callee)) return null;
|
|
6669
6928
|
return { node, name };
|
|
6670
6929
|
}
|
|
6671
|
-
case
|
|
6672
|
-
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;
|
|
6673
6932
|
if (!isBareString(node.id.typeAnnotation?.typeAnnotation)) return null;
|
|
6674
6933
|
return { node, name: node.id.name };
|
|
6675
6934
|
}
|
|
@@ -6681,13 +6940,13 @@ function rootCallee(node) {
|
|
|
6681
6940
|
let current = node;
|
|
6682
6941
|
for (let hops = 0; current != null && hops < 12; hops += 1) {
|
|
6683
6942
|
switch (current.type) {
|
|
6684
|
-
case
|
|
6943
|
+
case import_utils43.AST_NODE_TYPES.CallExpression:
|
|
6685
6944
|
current = current.callee;
|
|
6686
6945
|
break;
|
|
6687
|
-
case
|
|
6946
|
+
case import_utils43.AST_NODE_TYPES.MemberExpression:
|
|
6688
6947
|
current = current.object;
|
|
6689
6948
|
break;
|
|
6690
|
-
case
|
|
6949
|
+
case import_utils43.AST_NODE_TYPES.Identifier:
|
|
6691
6950
|
return current.name;
|
|
6692
6951
|
default:
|
|
6693
6952
|
return null;
|
|
@@ -6696,8 +6955,8 @@ function rootCallee(node) {
|
|
|
6696
6955
|
return null;
|
|
6697
6956
|
}
|
|
6698
6957
|
function nameOf(key) {
|
|
6699
|
-
if (key.type ===
|
|
6700
|
-
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;
|
|
6701
6960
|
return null;
|
|
6702
6961
|
}
|
|
6703
6962
|
function unionLiterals(body2) {
|
|
@@ -6741,7 +7000,7 @@ var no_union_in_comment_default = createRule({
|
|
|
6741
7000
|
if (after === null || after.loc.start.line !== comment.loc.end.line + 1) return null;
|
|
6742
7001
|
anchor = sourceCode.getNodeByRangeIndex(after.range[0]);
|
|
6743
7002
|
}
|
|
6744
|
-
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) {
|
|
6745
7004
|
const target = targetOf(node);
|
|
6746
7005
|
if (target !== null) return target;
|
|
6747
7006
|
}
|
|
@@ -6770,9 +7029,9 @@ var no_union_in_comment_default = createRule({
|
|
|
6770
7029
|
});
|
|
6771
7030
|
|
|
6772
7031
|
// src/rules/no-type-member-comment-wall.ts
|
|
6773
|
-
var
|
|
7032
|
+
var import_utils44 = require("@typescript-eslint/utils");
|
|
6774
7033
|
function isNamedMember(node) {
|
|
6775
|
-
return (node.type ===
|
|
7034
|
+
return (node.type === import_utils44.AST_NODE_TYPES.TSPropertySignature || node.type === import_utils44.AST_NODE_TYPES.TSMethodSignature) && !node.computed;
|
|
6776
7035
|
}
|
|
6777
7036
|
var no_type_member_comment_wall_default = createRule({
|
|
6778
7037
|
name: "no-type-member-comment-wall",
|
|
@@ -6819,7 +7078,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
6819
7078
|
return headsRun || lineAbove !== void 0 && lineAbove.trim().length === 0;
|
|
6820
7079
|
}
|
|
6821
7080
|
function check(node) {
|
|
6822
|
-
const members = node.type ===
|
|
7081
|
+
const members = node.type === import_utils44.AST_NODE_TYPES.TSInterfaceBody ? node.body : node.members;
|
|
6823
7082
|
const named2 = members.filter(isNamedMember);
|
|
6824
7083
|
if (named2.length === 0) return;
|
|
6825
7084
|
const documented = named2.map((member) => ({ member, comment: documentingComment(member) }));
|
|
@@ -6859,7 +7118,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
6859
7118
|
});
|
|
6860
7119
|
|
|
6861
7120
|
// src/rules/no-unnecessary-use-client.ts
|
|
6862
|
-
var
|
|
7121
|
+
var import_utils45 = require("@typescript-eslint/utils");
|
|
6863
7122
|
var HOOK_REGEX = /^use([A-Z]|$)/;
|
|
6864
7123
|
var EVENT_PROP_REGEX = /^on[A-Z]/;
|
|
6865
7124
|
var ERROR_FILE_REGEX = /\b(?:global-)?error\.[jt]sx?$/;
|
|
@@ -6885,13 +7144,13 @@ var CLIENT_ONLY_PACKAGES_REGEX = /^(?:@radix-ui\/|framer-motion|react-dom|react-
|
|
|
6885
7144
|
var isBareSpecifier = (source) => !source.startsWith(".") && !source.startsWith("/") && !source.startsWith("@/") && !source.startsWith("~");
|
|
6886
7145
|
var jsxRootName = (name) => {
|
|
6887
7146
|
let current = name;
|
|
6888
|
-
while (current.type ===
|
|
7147
|
+
while (current.type === import_utils45.AST_NODE_TYPES.JSXMemberExpression) {
|
|
6889
7148
|
current = current.object;
|
|
6890
7149
|
}
|
|
6891
|
-
return current.type ===
|
|
7150
|
+
return current.type === import_utils45.AST_NODE_TYPES.JSXIdentifier ? current.name : "";
|
|
6892
7151
|
};
|
|
6893
7152
|
var subtreeReadsImportedBinding = (node, imported) => {
|
|
6894
|
-
if (node.type ===
|
|
7153
|
+
if (node.type === import_utils45.AST_NODE_TYPES.Identifier) {
|
|
6895
7154
|
return imported.has(node.name);
|
|
6896
7155
|
}
|
|
6897
7156
|
for (const key of Object.keys(node)) {
|
|
@@ -6906,16 +7165,16 @@ var subtreeReadsImportedBinding = (node, imported) => {
|
|
|
6906
7165
|
return false;
|
|
6907
7166
|
};
|
|
6908
7167
|
var isUseClientDirective = (node) => {
|
|
6909
|
-
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";
|
|
6910
7169
|
};
|
|
6911
7170
|
var isGlobalReference = (node, context) => {
|
|
6912
7171
|
if (!BROWSER_GLOBALS.has(node.name)) return false;
|
|
6913
7172
|
const parent = node.parent;
|
|
6914
7173
|
if (parent !== void 0) {
|
|
6915
|
-
if (parent.type ===
|
|
7174
|
+
if (parent.type === import_utils45.AST_NODE_TYPES.MemberExpression && parent.property === node && !parent.computed) {
|
|
6916
7175
|
return false;
|
|
6917
7176
|
}
|
|
6918
|
-
if (parent.type ===
|
|
7177
|
+
if (parent.type === import_utils45.AST_NODE_TYPES.Property && parent.key === node && !parent.computed) {
|
|
6919
7178
|
return false;
|
|
6920
7179
|
}
|
|
6921
7180
|
if (parent.type.startsWith("TS")) {
|
|
@@ -6955,13 +7214,13 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
6955
7214
|
const importedLocals = /* @__PURE__ */ new Set();
|
|
6956
7215
|
const externalLocals = /* @__PURE__ */ new Set();
|
|
6957
7216
|
const markIfHookOrContext = (callee) => {
|
|
6958
|
-
if (callee.type ===
|
|
7217
|
+
if (callee.type === import_utils45.AST_NODE_TYPES.Identifier) {
|
|
6959
7218
|
if (HOOK_REGEX.test(callee.name) || callee.name === "createContext") {
|
|
6960
7219
|
hasClientIndicator = true;
|
|
6961
7220
|
}
|
|
6962
7221
|
return;
|
|
6963
7222
|
}
|
|
6964
|
-
if (callee.type ===
|
|
7223
|
+
if (callee.type === import_utils45.AST_NODE_TYPES.MemberExpression && callee.property.type === import_utils45.AST_NODE_TYPES.Identifier) {
|
|
6965
7224
|
const name = callee.property.name;
|
|
6966
7225
|
if (HOOK_REGEX.test(name) || name === "createContext") {
|
|
6967
7226
|
hasClientIndicator = true;
|
|
@@ -6971,7 +7230,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
6971
7230
|
return {
|
|
6972
7231
|
Program(node) {
|
|
6973
7232
|
for (const stmt of node.body) {
|
|
6974
|
-
if (stmt.type !==
|
|
7233
|
+
if (stmt.type !== import_utils45.AST_NODE_TYPES.ExpressionStatement) break;
|
|
6975
7234
|
if (isUseClientDirective(stmt)) {
|
|
6976
7235
|
directiveNode = stmt;
|
|
6977
7236
|
break;
|
|
@@ -6984,7 +7243,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
6984
7243
|
},
|
|
6985
7244
|
JSXAttribute(node) {
|
|
6986
7245
|
if (directiveNode === null) return;
|
|
6987
|
-
if (node.name.type ===
|
|
7246
|
+
if (node.name.type === import_utils45.AST_NODE_TYPES.JSXIdentifier && EVENT_PROP_REGEX.test(node.name.name)) {
|
|
6988
7247
|
hasClientIndicator = true;
|
|
6989
7248
|
}
|
|
6990
7249
|
},
|
|
@@ -7051,23 +7310,19 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
7051
7310
|
});
|
|
7052
7311
|
|
|
7053
7312
|
// src/rules/no-unsafe-mock-casting.ts
|
|
7054
|
-
var import_utils45 = require("@typescript-eslint/utils");
|
|
7055
7313
|
var import_utils46 = require("@typescript-eslint/utils");
|
|
7056
|
-
|
|
7057
|
-
|
|
7058
|
-
|
|
7059
|
-
|
|
7060
|
-
|
|
7061
|
-
|
|
7062
|
-
|
|
7063
|
-
|
|
7064
|
-
|
|
7065
|
-
|
|
7066
|
-
|
|
7067
|
-
|
|
7068
|
-
}
|
|
7069
|
-
return false;
|
|
7070
|
-
}
|
|
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
|
+
]);
|
|
7071
7326
|
var no_unsafe_mock_casting_default = createRule({
|
|
7072
7327
|
name: "no-unsafe-mock-casting",
|
|
7073
7328
|
meta: {
|
|
@@ -7085,12 +7340,49 @@ var no_unsafe_mock_casting_default = createRule({
|
|
|
7085
7340
|
if (isGeneratedFile(context.filename, context.sourceCode.text)) {
|
|
7086
7341
|
return {};
|
|
7087
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
|
+
}
|
|
7088
7368
|
function checkAssertion(node) {
|
|
7089
7369
|
if (isMockTypeReference(node.typeAnnotation)) {
|
|
7090
7370
|
context.report({ node, messageId: "unsafeMockCast" });
|
|
7091
7371
|
}
|
|
7092
7372
|
}
|
|
7093
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
|
+
},
|
|
7094
7386
|
TSAsExpression: checkAssertion,
|
|
7095
7387
|
TSTypeAssertion: checkAssertion
|
|
7096
7388
|
};
|
|
@@ -7112,7 +7404,7 @@ function isIgnoredFile(filename, sourceText) {
|
|
|
7112
7404
|
}
|
|
7113
7405
|
return /@generated\b/.test(sourceText.slice(0, 1024));
|
|
7114
7406
|
}
|
|
7115
|
-
function
|
|
7407
|
+
function isZodModule2(source) {
|
|
7116
7408
|
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
7117
7409
|
}
|
|
7118
7410
|
function unwrap2(node) {
|
|
@@ -7197,9 +7489,10 @@ var no_zod_native_enum_default = createRule({
|
|
|
7197
7489
|
services = null;
|
|
7198
7490
|
}
|
|
7199
7491
|
const zodImportedNames = /* @__PURE__ */ new Map();
|
|
7492
|
+
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
7200
7493
|
function isZodMemberCall(node, api) {
|
|
7201
7494
|
const callee = node.callee;
|
|
7202
|
-
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) {
|
|
7203
7496
|
return callee.property.name === api;
|
|
7204
7497
|
}
|
|
7205
7498
|
if (callee.type === import_utils47.AST_NODE_TYPES.Identifier) {
|
|
@@ -7233,10 +7526,13 @@ var no_zod_native_enum_default = createRule({
|
|
|
7233
7526
|
}
|
|
7234
7527
|
return {
|
|
7235
7528
|
ImportDeclaration(node) {
|
|
7236
|
-
if (!
|
|
7529
|
+
if (!isZodModule2(node.source.value)) {
|
|
7237
7530
|
return;
|
|
7238
7531
|
}
|
|
7239
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
|
+
}
|
|
7240
7536
|
if (spec.type === import_utils47.AST_NODE_TYPES.ImportSpecifier && spec.imported.type === import_utils47.AST_NODE_TYPES.Identifier) {
|
|
7241
7537
|
zodImportedNames.set(spec.local.name, spec.imported.name);
|
|
7242
7538
|
}
|
|
@@ -7255,10 +7551,12 @@ var no_zod_native_enum_default = createRule({
|
|
|
7255
7551
|
if (!isZodMemberCall(node, "enum")) {
|
|
7256
7552
|
return;
|
|
7257
7553
|
}
|
|
7258
|
-
const
|
|
7259
|
-
if (
|
|
7554
|
+
const argument = node.arguments[0];
|
|
7555
|
+
if (argument === void 0 || argument.type === import_utils47.AST_NODE_TYPES.SpreadElement) {
|
|
7260
7556
|
return;
|
|
7261
7557
|
}
|
|
7558
|
+
const arg = unwrap2(argument);
|
|
7559
|
+
if (arg.type !== import_utils47.AST_NODE_TYPES.Identifier) return;
|
|
7262
7560
|
const isEnum = resolvesToLocalEnum(arg, sourceCode.getScope(arg)) || services !== null && resolvesToImportedEnum(arg, services);
|
|
7263
7561
|
if (isEnum) {
|
|
7264
7562
|
context.report({
|
|
@@ -7297,7 +7595,7 @@ function rootIdentifier3(callee) {
|
|
|
7297
7595
|
if (callee.type === import_utils48.AST_NODE_TYPES.TaggedTemplateExpression) return rootIdentifier3(callee.tag);
|
|
7298
7596
|
return null;
|
|
7299
7597
|
}
|
|
7300
|
-
function
|
|
7598
|
+
function staticMemberName3(member) {
|
|
7301
7599
|
if (!member.computed && member.property.type === import_utils48.AST_NODE_TYPES.Identifier) return member.property.name;
|
|
7302
7600
|
if (member.computed && member.property.type === import_utils48.AST_NODE_TYPES.Literal && typeof member.property.value === "string") {
|
|
7303
7601
|
return member.property.value;
|
|
@@ -7312,7 +7610,7 @@ function isTestBody3(node, isFrameworkTest) {
|
|
|
7312
7610
|
function isTestCaller(callee) {
|
|
7313
7611
|
if (callee.type === import_utils48.AST_NODE_TYPES.Identifier) return TEST_CALLERS4.has(callee.name);
|
|
7314
7612
|
if (callee.type !== import_utils48.AST_NODE_TYPES.MemberExpression) return false;
|
|
7315
|
-
const member =
|
|
7613
|
+
const member = staticMemberName3(callee);
|
|
7316
7614
|
return member !== null && TEST_MODIFIERS2.has(member) && isTestCaller(callee.object);
|
|
7317
7615
|
}
|
|
7318
7616
|
function nearestEnclosingFunction3(node) {
|
|
@@ -7393,7 +7691,7 @@ function opensSubtest(node, callbackParameters) {
|
|
|
7393
7691
|
return false;
|
|
7394
7692
|
}
|
|
7395
7693
|
const callee = node.callee;
|
|
7396
|
-
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(
|
|
7397
7695
|
(argument) => argument.type !== import_utils48.AST_NODE_TYPES.SpreadElement && FUNCTION_TYPES6.has(argument.type)
|
|
7398
7696
|
);
|
|
7399
7697
|
}
|
|
@@ -7693,9 +7991,9 @@ var import_utils52 = require("@typescript-eslint/utils");
|
|
|
7693
7991
|
var INPUT_MODULE = /(?:^|\/)components\/ui\/input$/u;
|
|
7694
7992
|
var INPUT_GROUP_MODULE = /(?:^|\/)components\/ui\/input-group$/u;
|
|
7695
7993
|
var MAX_JSX_DISTANCE = 2;
|
|
7696
|
-
function localNamedImports(node,
|
|
7994
|
+
function localNamedImports(node, importedName2) {
|
|
7697
7995
|
return node.specifiers.filter(
|
|
7698
|
-
(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
|
|
7699
7997
|
).map((specifier) => specifier.local.name);
|
|
7700
7998
|
}
|
|
7701
7999
|
function elementName(node) {
|
|
@@ -8425,16 +8723,6 @@ var prefer_module_level_constant_default = createRule({
|
|
|
8425
8723
|
|
|
8426
8724
|
// src/rules/prefer-module-level-schema.ts
|
|
8427
8725
|
var import_utils56 = require("@typescript-eslint/utils");
|
|
8428
|
-
|
|
8429
|
-
// src/rules/_zod.ts
|
|
8430
|
-
var ZOD_PREFIX_RE = /^Z[A-Z]/;
|
|
8431
|
-
var ZOD_SUFFIX_RE = /Schema$/;
|
|
8432
|
-
var ZOD_SCHEMA_NAME_RE = /Schema$|^Z[A-Z]/;
|
|
8433
|
-
function isZodModule2(source) {
|
|
8434
|
-
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
8435
|
-
}
|
|
8436
|
-
|
|
8437
|
-
// src/rules/prefer-module-level-schema.ts
|
|
8438
8726
|
var DEFAULT_FACTORIES = [
|
|
8439
8727
|
"discriminatedUnion",
|
|
8440
8728
|
"intersection",
|
|
@@ -8720,7 +9008,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
8720
9008
|
}
|
|
8721
9009
|
return {
|
|
8722
9010
|
ImportDeclaration(node) {
|
|
8723
|
-
if (!
|
|
9011
|
+
if (!isZodModule(node.source.value)) {
|
|
8724
9012
|
return;
|
|
8725
9013
|
}
|
|
8726
9014
|
for (const specifier of node.specifiers) {
|
|
@@ -10036,13 +10324,13 @@ function getPropertyNode(objNode, propName2) {
|
|
|
10036
10324
|
if (!objNode || objNode.type !== "ObjectExpression") return null;
|
|
10037
10325
|
for (const prop of objNode.properties) {
|
|
10038
10326
|
if (prop.type !== "Property") continue;
|
|
10039
|
-
let
|
|
10327
|
+
let keyName = null;
|
|
10040
10328
|
if (prop.key.type === "Identifier" && !prop.computed) {
|
|
10041
|
-
|
|
10329
|
+
keyName = prop.key.name;
|
|
10042
10330
|
} else if (prop.key.type === "Literal" && typeof prop.key.value === "string") {
|
|
10043
|
-
|
|
10331
|
+
keyName = prop.key.value;
|
|
10044
10332
|
}
|
|
10045
|
-
if (
|
|
10333
|
+
if (keyName === propName2) {
|
|
10046
10334
|
if (prop.value.type === "AssignmentPattern" || prop.value.type === "ArrayPattern" || prop.value.type === "ObjectPattern") {
|
|
10047
10335
|
return null;
|
|
10048
10336
|
}
|
|
@@ -10120,370 +10408,8 @@ var prefer_server_actions_default = createRule({
|
|
|
10120
10408
|
}
|
|
10121
10409
|
});
|
|
10122
10410
|
|
|
10123
|
-
// src/rules/prefer-string-literal-union.ts
|
|
10124
|
-
var import_utils62 = require("@typescript-eslint/utils");
|
|
10125
|
-
var ts2 = __toESM(require("typescript"), 1);
|
|
10126
|
-
var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
10127
|
-
"status",
|
|
10128
|
-
"state",
|
|
10129
|
-
"kind",
|
|
10130
|
-
"role",
|
|
10131
|
-
"priority",
|
|
10132
|
-
"severity",
|
|
10133
|
-
"direction",
|
|
10134
|
-
"tier",
|
|
10135
|
-
"stage",
|
|
10136
|
-
"type",
|
|
10137
|
-
"mode",
|
|
10138
|
-
"level"
|
|
10139
|
-
]);
|
|
10140
|
-
var LOWER_TOKEN_RE = /^[a-z][a-z0-9_-]{0,30}$/;
|
|
10141
|
-
var MIN_CLUSTER_SIZE = 2;
|
|
10142
|
-
var BOOLEANISH = /* @__PURE__ */ new Set(["true", "false"]);
|
|
10143
|
-
function isEnumToken(lit) {
|
|
10144
|
-
return LOWER_TOKEN_RE.test(lit) && lit.length >= 2 && !BOOLEANISH.has(lit);
|
|
10145
|
-
}
|
|
10146
|
-
var IGNORE_PATTERNS3 = [
|
|
10147
|
-
/[\\/]generated[\\/]/,
|
|
10148
|
-
/\.gen\.tsx?$/,
|
|
10149
|
-
/\.generated\.tsx?$/,
|
|
10150
|
-
/\.d\.ts$/
|
|
10151
|
-
];
|
|
10152
|
-
function isIgnoredFile3(filename, sourceText) {
|
|
10153
|
-
if (IGNORE_PATTERNS3.some((re) => re.test(filename))) {
|
|
10154
|
-
return true;
|
|
10155
|
-
}
|
|
10156
|
-
return /@generated\b/.test(sourceText.slice(0, 1024));
|
|
10157
|
-
}
|
|
10158
|
-
function isChoiceLikeName(name) {
|
|
10159
|
-
return CHOICE_TOKENS.has(lastWord(name));
|
|
10160
|
-
}
|
|
10161
|
-
function lastWord(name) {
|
|
10162
|
-
const words = name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").split(/[_\s]+/).filter((w) => w.length > 0);
|
|
10163
|
-
const last = words[words.length - 1] ?? name;
|
|
10164
|
-
return last.toLowerCase();
|
|
10165
|
-
}
|
|
10166
|
-
function keyName(key) {
|
|
10167
|
-
if (key.type === import_utils62.AST_NODE_TYPES.Identifier) {
|
|
10168
|
-
return key.name;
|
|
10169
|
-
}
|
|
10170
|
-
if (key.type === import_utils62.AST_NODE_TYPES.Literal && typeof key.value === "string") {
|
|
10171
|
-
return key.value;
|
|
10172
|
-
}
|
|
10173
|
-
return null;
|
|
10174
|
-
}
|
|
10175
|
-
function isStringLiteralMember(t) {
|
|
10176
|
-
return t.type === import_utils62.AST_NODE_TYPES.TSLiteralType && t.literal.type === import_utils62.AST_NODE_TYPES.Literal && typeof t.literal.value === "string";
|
|
10177
|
-
}
|
|
10178
|
-
function isStringLiteralUnion(node) {
|
|
10179
|
-
if (node?.type !== import_utils62.AST_NODE_TYPES.TSUnionType) {
|
|
10180
|
-
return false;
|
|
10181
|
-
}
|
|
10182
|
-
return node.types.filter(isStringLiteralMember).length >= MIN_CLUSTER_SIZE;
|
|
10183
|
-
}
|
|
10184
|
-
function typeHasRawString(type) {
|
|
10185
|
-
const parts = type.isUnion() ? type.types : [type];
|
|
10186
|
-
return parts.some((t) => (t.flags & ts2.TypeFlags.String) !== 0);
|
|
10187
|
-
}
|
|
10188
|
-
function isExternalSourceFile(sf) {
|
|
10189
|
-
if (sf === void 0) {
|
|
10190
|
-
return false;
|
|
10191
|
-
}
|
|
10192
|
-
return sf.isDeclarationFile || sf.fileName.includes("/node_modules/");
|
|
10193
|
-
}
|
|
10194
|
-
function symbolIsExternallyDeclared(sym) {
|
|
10195
|
-
return sym?.declarations?.some((d) => isExternalSourceFile(d.getSourceFile())) ?? false;
|
|
10196
|
-
}
|
|
10197
|
-
function bindingSourceExpression(decl) {
|
|
10198
|
-
let node = decl.parent;
|
|
10199
|
-
while (!ts2.isForOfStatement(node) && !(ts2.isVariableDeclaration(node) && node.initializer !== void 0)) {
|
|
10200
|
-
if (node.parent === void 0) {
|
|
10201
|
-
return void 0;
|
|
10202
|
-
}
|
|
10203
|
-
node = node.parent;
|
|
10204
|
-
}
|
|
10205
|
-
return ts2.isForOfStatement(node) ? node.expression : node.initializer;
|
|
10206
|
-
}
|
|
10207
|
-
function refKey(node) {
|
|
10208
|
-
if (node.type === import_utils62.AST_NODE_TYPES.Identifier) {
|
|
10209
|
-
return node.name;
|
|
10210
|
-
}
|
|
10211
|
-
if (node.type === import_utils62.AST_NODE_TYPES.MemberExpression && !node.computed) {
|
|
10212
|
-
const inner = refKey(node.object);
|
|
10213
|
-
if (inner === null || node.property.type !== import_utils62.AST_NODE_TYPES.Identifier) {
|
|
10214
|
-
return null;
|
|
10215
|
-
}
|
|
10216
|
-
return `${inner}.${node.property.name}`;
|
|
10217
|
-
}
|
|
10218
|
-
return null;
|
|
10219
|
-
}
|
|
10220
|
-
function strLiteral(node) {
|
|
10221
|
-
if (node.type === import_utils62.AST_NODE_TYPES.Literal && typeof node.value === "string") {
|
|
10222
|
-
return node.value;
|
|
10223
|
-
}
|
|
10224
|
-
return null;
|
|
10225
|
-
}
|
|
10226
|
-
var prefer_string_literal_union_default = createRule({
|
|
10227
|
-
name: "prefer-string-literal-union",
|
|
10228
|
-
meta: {
|
|
10229
|
-
type: "suggestion",
|
|
10230
|
-
docs: {
|
|
10231
|
-
description: "Flag raw `string` choice fields and string-literal comparison clusters; prefer a string-literal union type."
|
|
10232
|
-
},
|
|
10233
|
-
schema: [
|
|
10234
|
-
{
|
|
10235
|
-
type: "object",
|
|
10236
|
-
additionalProperties: false,
|
|
10237
|
-
properties: {
|
|
10238
|
-
ignoreFields: {
|
|
10239
|
-
type: "array",
|
|
10240
|
-
items: { type: "string" }
|
|
10241
|
-
}
|
|
10242
|
-
}
|
|
10243
|
-
}
|
|
10244
|
-
],
|
|
10245
|
-
messages: {
|
|
10246
|
-
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.',
|
|
10247
|
-
comparisonCluster: '`{{key}}` is compared against a closed set of string literals \u2014 define a string-literal union type (e.g. `type X = "a" | "b"`).'
|
|
10248
|
-
}
|
|
10249
|
-
},
|
|
10250
|
-
defaultOptions: [{}],
|
|
10251
|
-
create(context, [optionsArg]) {
|
|
10252
|
-
const filename = context.filename;
|
|
10253
|
-
const sourceText = context.sourceCode.getText();
|
|
10254
|
-
if (isIgnoredFile3(filename, sourceText)) {
|
|
10255
|
-
return {};
|
|
10256
|
-
}
|
|
10257
|
-
const ignoredFields = new Set(
|
|
10258
|
-
(optionsArg?.ignoreFields ?? []).map((name) => name.toLowerCase())
|
|
10259
|
-
);
|
|
10260
|
-
let services;
|
|
10261
|
-
try {
|
|
10262
|
-
services = import_utils62.ESLintUtils.getParserServices(context);
|
|
10263
|
-
} catch {
|
|
10264
|
-
services = null;
|
|
10265
|
-
}
|
|
10266
|
-
const scopeStack = [];
|
|
10267
|
-
const validClusters = [];
|
|
10268
|
-
const bareChoiceProps = [];
|
|
10269
|
-
const containersWithUnion = /* @__PURE__ */ new Set();
|
|
10270
|
-
function operandIsRawString(node) {
|
|
10271
|
-
if (services === null) {
|
|
10272
|
-
return false;
|
|
10273
|
-
}
|
|
10274
|
-
return typeHasRawString(services.getTypeAtLocation(node));
|
|
10275
|
-
}
|
|
10276
|
-
function parameterRoot(node) {
|
|
10277
|
-
if (services === null) return false;
|
|
10278
|
-
const checker = services.program.getTypeChecker();
|
|
10279
|
-
let current = services.esTreeNodeToTSNodeMap.get(node);
|
|
10280
|
-
while (ts2.isPropertyAccessExpression(current)) current = current.expression;
|
|
10281
|
-
if (!ts2.isIdentifier(current)) return false;
|
|
10282
|
-
let declaration = checker.getSymbolAtLocation(current)?.valueDeclaration;
|
|
10283
|
-
while (declaration !== void 0 && (ts2.isBindingElement(declaration) || ts2.isObjectBindingPattern(declaration) || ts2.isArrayBindingPattern(declaration))) {
|
|
10284
|
-
declaration = declaration.parent;
|
|
10285
|
-
}
|
|
10286
|
-
return declaration !== void 0 && ts2.isParameter(declaration);
|
|
10287
|
-
}
|
|
10288
|
-
function originIsExternal(node, depth) {
|
|
10289
|
-
if (node === void 0 || services === null || depth > 6) {
|
|
10290
|
-
return false;
|
|
10291
|
-
}
|
|
10292
|
-
const checker = services.program.getTypeChecker();
|
|
10293
|
-
if (ts2.isParenthesizedExpression(node) || ts2.isNonNullExpression(node) || ts2.isAsExpression(node)) {
|
|
10294
|
-
return originIsExternal(node.expression, depth + 1);
|
|
10295
|
-
}
|
|
10296
|
-
if (ts2.isPropertyAccessExpression(node)) {
|
|
10297
|
-
return symbolIsExternallyDeclared(checker.getSymbolAtLocation(node.name));
|
|
10298
|
-
}
|
|
10299
|
-
if (ts2.isCallExpression(node)) {
|
|
10300
|
-
return originIsExternal(node.expression, depth + 1);
|
|
10301
|
-
}
|
|
10302
|
-
if (ts2.isIdentifier(node)) {
|
|
10303
|
-
const decl = checker.getSymbolAtLocation(node)?.valueDeclaration;
|
|
10304
|
-
if (decl === void 0) {
|
|
10305
|
-
return false;
|
|
10306
|
-
}
|
|
10307
|
-
if (ts2.isVariableDeclaration(decl) && decl.initializer !== void 0) {
|
|
10308
|
-
return originIsExternal(decl.initializer, depth + 1);
|
|
10309
|
-
}
|
|
10310
|
-
if (ts2.isBindingElement(decl)) {
|
|
10311
|
-
return originIsExternal(bindingSourceExpression(decl), depth + 1);
|
|
10312
|
-
}
|
|
10313
|
-
}
|
|
10314
|
-
return false;
|
|
10315
|
-
}
|
|
10316
|
-
function operandIsFlaggable(node) {
|
|
10317
|
-
return operandIsRawString(node) && parameterRoot(node) && !originIsExternal(services?.esTreeNodeToTSNodeMap.get(node), 0);
|
|
10318
|
-
}
|
|
10319
|
-
function declaredReturnLiterals(fn) {
|
|
10320
|
-
const annotation = fn.returnType?.typeAnnotation;
|
|
10321
|
-
if (annotation === void 0 || services === null) {
|
|
10322
|
-
return null;
|
|
10323
|
-
}
|
|
10324
|
-
const tsNode = services.esTreeNodeToTSNodeMap.get(annotation);
|
|
10325
|
-
if (!ts2.isTypeNode(tsNode)) {
|
|
10326
|
-
return null;
|
|
10327
|
-
}
|
|
10328
|
-
const checker = services.program.getTypeChecker();
|
|
10329
|
-
const declared = checker.getTypeFromTypeNode(tsNode);
|
|
10330
|
-
const type = checker.getAwaitedType(declared) ?? declared;
|
|
10331
|
-
const literals = /* @__PURE__ */ new Set();
|
|
10332
|
-
for (const part of type.isUnion() ? type.types : [type]) {
|
|
10333
|
-
if (part.isStringLiteral()) {
|
|
10334
|
-
literals.add(part.value);
|
|
10335
|
-
}
|
|
10336
|
-
}
|
|
10337
|
-
return literals.size >= MIN_CLUSTER_SIZE ? literals : null;
|
|
10338
|
-
}
|
|
10339
|
-
function pushScope(node) {
|
|
10340
|
-
scopeStack.push({ clusters: /* @__PURE__ */ new Map(), fn: node });
|
|
10341
|
-
}
|
|
10342
|
-
function popScope() {
|
|
10343
|
-
const scope = scopeStack.pop();
|
|
10344
|
-
if (scope === void 0) {
|
|
10345
|
-
return;
|
|
10346
|
-
}
|
|
10347
|
-
const candidates = [...scope.clusters.values()].filter(
|
|
10348
|
-
(entry) => entry.allTokens && entry.literals.size >= MIN_CLUSTER_SIZE
|
|
10349
|
-
);
|
|
10350
|
-
if (candidates.length === 0) {
|
|
10351
|
-
return;
|
|
10352
|
-
}
|
|
10353
|
-
const returnLiterals = scope.fn === null ? null : declaredReturnLiterals(scope.fn);
|
|
10354
|
-
for (const entry of candidates) {
|
|
10355
|
-
if (returnLiterals !== null && [...entry.literals].every((lit) => returnLiterals.has(lit))) {
|
|
10356
|
-
continue;
|
|
10357
|
-
}
|
|
10358
|
-
validClusters.push(entry.node);
|
|
10359
|
-
}
|
|
10360
|
-
}
|
|
10361
|
-
function accumulate(key, literals, node) {
|
|
10362
|
-
const scope = scopeStack[scopeStack.length - 1];
|
|
10363
|
-
if (scope === void 0) {
|
|
10364
|
-
return;
|
|
10365
|
-
}
|
|
10366
|
-
const allTokens = literals.every((lit) => isEnumToken(lit));
|
|
10367
|
-
const existing = scope.clusters.get(key);
|
|
10368
|
-
if (existing === void 0) {
|
|
10369
|
-
scope.clusters.set(key, {
|
|
10370
|
-
node,
|
|
10371
|
-
literals: new Set(literals),
|
|
10372
|
-
allTokens
|
|
10373
|
-
});
|
|
10374
|
-
return;
|
|
10375
|
-
}
|
|
10376
|
-
for (const lit of literals) {
|
|
10377
|
-
existing.literals.add(lit);
|
|
10378
|
-
}
|
|
10379
|
-
existing.allTokens = existing.allTokens && allTokens;
|
|
10380
|
-
}
|
|
10381
|
-
function collectProperty(key, typeNode, container, node) {
|
|
10382
|
-
if (isStringLiteralUnion(typeNode)) {
|
|
10383
|
-
containersWithUnion.add(container);
|
|
10384
|
-
return;
|
|
10385
|
-
}
|
|
10386
|
-
if (typeNode?.type !== import_utils62.AST_NODE_TYPES.TSStringKeyword) {
|
|
10387
|
-
return;
|
|
10388
|
-
}
|
|
10389
|
-
const name = keyName(key);
|
|
10390
|
-
if (name === null || !isChoiceLikeName(name) || ignoredFields.has(name.toLowerCase())) {
|
|
10391
|
-
return;
|
|
10392
|
-
}
|
|
10393
|
-
bareChoiceProps.push({ name, container, node });
|
|
10394
|
-
}
|
|
10395
|
-
return {
|
|
10396
|
-
FunctionDeclaration: pushScope,
|
|
10397
|
-
"FunctionDeclaration:exit": popScope,
|
|
10398
|
-
FunctionExpression: pushScope,
|
|
10399
|
-
"FunctionExpression:exit": popScope,
|
|
10400
|
-
ArrowFunctionExpression: pushScope,
|
|
10401
|
-
"ArrowFunctionExpression:exit": popScope,
|
|
10402
|
-
BinaryExpression(node) {
|
|
10403
|
-
if (node.operator !== "===" && node.operator !== "!==" && node.operator !== "==" && node.operator !== "!=") {
|
|
10404
|
-
return;
|
|
10405
|
-
}
|
|
10406
|
-
const leftKey = refKey(node.left);
|
|
10407
|
-
const rightLit = strLiteral(node.right);
|
|
10408
|
-
const rightKey = refKey(node.right);
|
|
10409
|
-
const leftLit = strLiteral(node.left);
|
|
10410
|
-
if (leftKey !== null && rightLit !== null) {
|
|
10411
|
-
if (operandIsFlaggable(node.left)) {
|
|
10412
|
-
accumulate(leftKey, [rightLit], node);
|
|
10413
|
-
}
|
|
10414
|
-
} else if (rightKey !== null && leftLit !== null) {
|
|
10415
|
-
if (operandIsFlaggable(node.right)) {
|
|
10416
|
-
accumulate(rightKey, [leftLit], node);
|
|
10417
|
-
}
|
|
10418
|
-
}
|
|
10419
|
-
},
|
|
10420
|
-
SwitchStatement(node) {
|
|
10421
|
-
const key = refKey(node.discriminant);
|
|
10422
|
-
if (key === null || !operandIsFlaggable(node.discriminant)) {
|
|
10423
|
-
return;
|
|
10424
|
-
}
|
|
10425
|
-
const literals = [];
|
|
10426
|
-
for (const c of node.cases) {
|
|
10427
|
-
if (c.test !== null) {
|
|
10428
|
-
const lit = strLiteral(c.test);
|
|
10429
|
-
if (lit !== null) {
|
|
10430
|
-
literals.push(lit);
|
|
10431
|
-
}
|
|
10432
|
-
}
|
|
10433
|
-
}
|
|
10434
|
-
if (literals.length > 0) {
|
|
10435
|
-
accumulate(key, literals, node);
|
|
10436
|
-
}
|
|
10437
|
-
},
|
|
10438
|
-
TSPropertySignature(node) {
|
|
10439
|
-
collectProperty(
|
|
10440
|
-
node.key,
|
|
10441
|
-
node.typeAnnotation?.typeAnnotation,
|
|
10442
|
-
node.parent,
|
|
10443
|
-
node
|
|
10444
|
-
);
|
|
10445
|
-
},
|
|
10446
|
-
PropertyDefinition(node) {
|
|
10447
|
-
collectProperty(
|
|
10448
|
-
node.key,
|
|
10449
|
-
node.typeAnnotation?.typeAnnotation,
|
|
10450
|
-
node.parent,
|
|
10451
|
-
node
|
|
10452
|
-
);
|
|
10453
|
-
},
|
|
10454
|
-
"Program:exit"() {
|
|
10455
|
-
for (const clusterNode of validClusters) {
|
|
10456
|
-
context.report({
|
|
10457
|
-
node: clusterNode,
|
|
10458
|
-
messageId: "comparisonCluster",
|
|
10459
|
-
data: { key: refKeyText(clusterNode) }
|
|
10460
|
-
});
|
|
10461
|
-
}
|
|
10462
|
-
for (const prop of bareChoiceProps) {
|
|
10463
|
-
if (containersWithUnion.has(prop.container)) {
|
|
10464
|
-
context.report({
|
|
10465
|
-
node: prop.node,
|
|
10466
|
-
messageId: "bareChoiceField",
|
|
10467
|
-
data: { name: prop.name }
|
|
10468
|
-
});
|
|
10469
|
-
}
|
|
10470
|
-
}
|
|
10471
|
-
}
|
|
10472
|
-
};
|
|
10473
|
-
function refKeyText(node) {
|
|
10474
|
-
if (node.type === import_utils62.AST_NODE_TYPES.BinaryExpression) {
|
|
10475
|
-
return refKey(node.left) ?? refKey(node.right) ?? "value";
|
|
10476
|
-
}
|
|
10477
|
-
if (node.type === import_utils62.AST_NODE_TYPES.SwitchStatement) {
|
|
10478
|
-
return refKey(node.discriminant) ?? "value";
|
|
10479
|
-
}
|
|
10480
|
-
return "value";
|
|
10481
|
-
}
|
|
10482
|
-
}
|
|
10483
|
-
});
|
|
10484
|
-
|
|
10485
10411
|
// src/rules/prefer-whole-object-assertion.ts
|
|
10486
|
-
var
|
|
10412
|
+
var import_utils62 = require("@typescript-eslint/utils");
|
|
10487
10413
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
10488
10414
|
var ARRAY_MATCHERS = /* @__PURE__ */ new Set(["toEqual", "toStrictEqual"]);
|
|
10489
10415
|
var COLLECTION_PROPERTIES = /* @__PURE__ */ new Set(["length", "size"]);
|
|
@@ -10492,11 +10418,11 @@ var NUMERIC_SIGNS2 = /* @__PURE__ */ new Set(["-", "+"]);
|
|
|
10492
10418
|
var MIN_RUN_LENGTH = 2;
|
|
10493
10419
|
function literalText(node, getText) {
|
|
10494
10420
|
switch (node.type) {
|
|
10495
|
-
case
|
|
10421
|
+
case import_utils62.AST_NODE_TYPES.Literal:
|
|
10496
10422
|
return "regex" in node ? null : getText(node);
|
|
10497
|
-
case
|
|
10423
|
+
case import_utils62.AST_NODE_TYPES.TemplateLiteral:
|
|
10498
10424
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
10499
|
-
case
|
|
10425
|
+
case import_utils62.AST_NODE_TYPES.UnaryExpression:
|
|
10500
10426
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
10501
10427
|
default:
|
|
10502
10428
|
return null;
|
|
@@ -10504,15 +10430,15 @@ function literalText(node, getText) {
|
|
|
10504
10430
|
}
|
|
10505
10431
|
function isPureReceiver(node) {
|
|
10506
10432
|
switch (node.type) {
|
|
10507
|
-
case
|
|
10508
|
-
case
|
|
10433
|
+
case import_utils62.AST_NODE_TYPES.Identifier:
|
|
10434
|
+
case import_utils62.AST_NODE_TYPES.ThisExpression:
|
|
10509
10435
|
return true;
|
|
10510
|
-
case
|
|
10436
|
+
case import_utils62.AST_NODE_TYPES.MemberExpression:
|
|
10511
10437
|
if (node.optional) {
|
|
10512
10438
|
return false;
|
|
10513
10439
|
}
|
|
10514
10440
|
if (node.computed) {
|
|
10515
|
-
return node.property.type ===
|
|
10441
|
+
return node.property.type === import_utils62.AST_NODE_TYPES.Literal && isPureReceiver(node.object);
|
|
10516
10442
|
}
|
|
10517
10443
|
return isPureReceiver(node.object);
|
|
10518
10444
|
default:
|
|
@@ -10520,7 +10446,7 @@ function isPureReceiver(node) {
|
|
|
10520
10446
|
}
|
|
10521
10447
|
}
|
|
10522
10448
|
function literalIndex(node) {
|
|
10523
|
-
if (node.type !==
|
|
10449
|
+
if (node.type !== import_utils62.AST_NODE_TYPES.Literal || typeof node.value !== "number") {
|
|
10524
10450
|
return null;
|
|
10525
10451
|
}
|
|
10526
10452
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
@@ -10546,24 +10472,24 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
10546
10472
|
}
|
|
10547
10473
|
const { sourceCode } = context;
|
|
10548
10474
|
function parseAssertion(statement) {
|
|
10549
|
-
if (statement.type !==
|
|
10475
|
+
if (statement.type !== import_utils62.AST_NODE_TYPES.ExpressionStatement) {
|
|
10550
10476
|
return null;
|
|
10551
10477
|
}
|
|
10552
10478
|
const call = statement.expression;
|
|
10553
|
-
if (call.type !==
|
|
10479
|
+
if (call.type !== import_utils62.AST_NODE_TYPES.CallExpression) {
|
|
10554
10480
|
return null;
|
|
10555
10481
|
}
|
|
10556
10482
|
const callee = call.callee;
|
|
10557
|
-
if (callee.type !==
|
|
10483
|
+
if (callee.type !== import_utils62.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils62.AST_NODE_TYPES.Identifier) {
|
|
10558
10484
|
return null;
|
|
10559
10485
|
}
|
|
10560
10486
|
const matcher = callee.property.name;
|
|
10561
10487
|
const expectCall = callee.object;
|
|
10562
|
-
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) {
|
|
10563
10489
|
return null;
|
|
10564
10490
|
}
|
|
10565
10491
|
const actual = expectCall.arguments[0];
|
|
10566
|
-
if (actual === void 0 || actual.type !==
|
|
10492
|
+
if (actual === void 0 || actual.type !== import_utils62.AST_NODE_TYPES.MemberExpression || actual.optional) {
|
|
10567
10493
|
return null;
|
|
10568
10494
|
}
|
|
10569
10495
|
if (!isPureReceiver(actual.object)) {
|
|
@@ -10577,7 +10503,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
10577
10503
|
}
|
|
10578
10504
|
key = { kind: "index", index };
|
|
10579
10505
|
} else {
|
|
10580
|
-
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)) {
|
|
10581
10507
|
return null;
|
|
10582
10508
|
}
|
|
10583
10509
|
key = { kind: "property", name: actual.property.name };
|
|
@@ -10589,7 +10515,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
10589
10515
|
return null;
|
|
10590
10516
|
}
|
|
10591
10517
|
const expected = call.arguments[0];
|
|
10592
|
-
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) {
|
|
10593
10519
|
return null;
|
|
10594
10520
|
}
|
|
10595
10521
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
@@ -10703,99 +10629,8 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
10703
10629
|
}
|
|
10704
10630
|
});
|
|
10705
10631
|
|
|
10706
|
-
// src/rules/prefer-zod-enum.ts
|
|
10707
|
-
var import_utils64 = require("@typescript-eslint/utils");
|
|
10708
|
-
var prefer_zod_enum_default = createRule({
|
|
10709
|
-
name: "prefer-zod-enum",
|
|
10710
|
-
meta: {
|
|
10711
|
-
type: "suggestion",
|
|
10712
|
-
docs: {
|
|
10713
|
-
description: "Prefer z.enum([...]) over z.union([z.literal(...), ...]) for string choices"
|
|
10714
|
-
},
|
|
10715
|
-
fixable: "code",
|
|
10716
|
-
schema: [],
|
|
10717
|
-
messages: {
|
|
10718
|
-
preferEnum: "Use `z.enum([...])` instead of a union of string-literal schemas."
|
|
10719
|
-
}
|
|
10720
|
-
},
|
|
10721
|
-
defaultOptions: [],
|
|
10722
|
-
create(context) {
|
|
10723
|
-
const sourceCode = context.sourceCode;
|
|
10724
|
-
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
10725
|
-
function enumValues(node) {
|
|
10726
|
-
const callee = node.callee;
|
|
10727
|
-
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) {
|
|
10728
|
-
return null;
|
|
10729
|
-
}
|
|
10730
|
-
const argument = node.arguments[0];
|
|
10731
|
-
if (argument === void 0 || argument.type !== import_utils64.AST_NODE_TYPES.ArrayExpression || argument.elements.length === 0) {
|
|
10732
|
-
return null;
|
|
10733
|
-
}
|
|
10734
|
-
const values = [];
|
|
10735
|
-
let canFix = true;
|
|
10736
|
-
for (const element of argument.elements) {
|
|
10737
|
-
if (element?.type === import_utils64.AST_NODE_TYPES.SpreadElement) {
|
|
10738
|
-
canFix = false;
|
|
10739
|
-
continue;
|
|
10740
|
-
}
|
|
10741
|
-
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") {
|
|
10742
|
-
return null;
|
|
10743
|
-
}
|
|
10744
|
-
const value = element.arguments[0];
|
|
10745
|
-
if (element.arguments.length !== 1 || value === void 0 || value.type !== import_utils64.AST_NODE_TYPES.Literal || typeof value.value !== "string") {
|
|
10746
|
-
canFix = false;
|
|
10747
|
-
continue;
|
|
10748
|
-
}
|
|
10749
|
-
values.push(value);
|
|
10750
|
-
}
|
|
10751
|
-
return canFix ? values : void 0;
|
|
10752
|
-
}
|
|
10753
|
-
function buildFix(node, values) {
|
|
10754
|
-
const argument = node.arguments[0];
|
|
10755
|
-
if (argument === void 0 || argument.type !== import_utils64.AST_NODE_TYPES.ArrayExpression || sourceCode.getCommentsInside(argument).length > 0) {
|
|
10756
|
-
return void 0;
|
|
10757
|
-
}
|
|
10758
|
-
const callee = node.callee;
|
|
10759
|
-
if (callee.type !== import_utils64.AST_NODE_TYPES.MemberExpression || callee.property.type !== import_utils64.AST_NODE_TYPES.Identifier) {
|
|
10760
|
-
return void 0;
|
|
10761
|
-
}
|
|
10762
|
-
return (fixer) => [
|
|
10763
|
-
fixer.replaceText(callee.property, "enum"),
|
|
10764
|
-
fixer.replaceText(
|
|
10765
|
-
argument,
|
|
10766
|
-
`[${values.map((value) => sourceCode.getText(value)).join(", ")}]`
|
|
10767
|
-
)
|
|
10768
|
-
];
|
|
10769
|
-
}
|
|
10770
|
-
return {
|
|
10771
|
-
ImportDeclaration(node) {
|
|
10772
|
-
if (!isZodModule2(node.source.value)) {
|
|
10773
|
-
return;
|
|
10774
|
-
}
|
|
10775
|
-
for (const specifier of node.specifiers) {
|
|
10776
|
-
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") {
|
|
10777
|
-
zodNamespaces.add(specifier.local.name);
|
|
10778
|
-
}
|
|
10779
|
-
}
|
|
10780
|
-
},
|
|
10781
|
-
CallExpression(node) {
|
|
10782
|
-
const values = enumValues(node);
|
|
10783
|
-
if (values === null) {
|
|
10784
|
-
return;
|
|
10785
|
-
}
|
|
10786
|
-
const fix = values === void 0 ? void 0 : buildFix(node, values);
|
|
10787
|
-
context.report({
|
|
10788
|
-
node,
|
|
10789
|
-
messageId: "preferEnum",
|
|
10790
|
-
...fix === void 0 ? {} : { fix }
|
|
10791
|
-
});
|
|
10792
|
-
}
|
|
10793
|
-
};
|
|
10794
|
-
}
|
|
10795
|
-
});
|
|
10796
|
-
|
|
10797
10632
|
// src/rules/prefer-zod-infer.ts
|
|
10798
|
-
var
|
|
10633
|
+
var import_utils63 = require("@typescript-eslint/utils");
|
|
10799
10634
|
var SHAPE_PRESERVING_METHODS = /* @__PURE__ */ new Set([
|
|
10800
10635
|
"describe",
|
|
10801
10636
|
"refine",
|
|
@@ -10817,7 +10652,8 @@ var RESHAPING_MODIFIERS = /* @__PURE__ */ new Set([
|
|
|
10817
10652
|
"pipe",
|
|
10818
10653
|
"preprocess",
|
|
10819
10654
|
"brand",
|
|
10820
|
-
"overwrite"
|
|
10655
|
+
"overwrite",
|
|
10656
|
+
"readonly"
|
|
10821
10657
|
]);
|
|
10822
10658
|
var MODULE_LEVEL_RESHAPERS = /* @__PURE__ */ new Set([
|
|
10823
10659
|
"transform",
|
|
@@ -10832,44 +10668,44 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
10832
10668
|
"Schema"
|
|
10833
10669
|
]);
|
|
10834
10670
|
var LEAF_NODE_TYPES = {
|
|
10835
|
-
string: [
|
|
10836
|
-
email: [
|
|
10837
|
-
url: [
|
|
10838
|
-
uuid: [
|
|
10839
|
-
ulid: [
|
|
10840
|
-
cuid: [
|
|
10841
|
-
cuid2: [
|
|
10842
|
-
nanoid: [
|
|
10843
|
-
iso: [
|
|
10844
|
-
number: [
|
|
10845
|
-
int: [
|
|
10846
|
-
float32: [
|
|
10847
|
-
float64: [
|
|
10848
|
-
boolean: [
|
|
10849
|
-
bigint: [
|
|
10850
|
-
symbol: [
|
|
10851
|
-
any: [
|
|
10852
|
-
unknown: [
|
|
10853
|
-
never: [
|
|
10854
|
-
void: [
|
|
10855
|
-
null: [
|
|
10856
|
-
undefined: [
|
|
10857
|
-
literal: [
|
|
10858
|
-
date: [
|
|
10859
|
-
array: [
|
|
10860
|
-
tuple: [
|
|
10861
|
-
object: [
|
|
10862
|
-
strictObject: [
|
|
10863
|
-
looseObject: [
|
|
10864
|
-
record: [
|
|
10865
|
-
map: [
|
|
10866
|
-
set: [
|
|
10867
|
-
promise: [
|
|
10868
|
-
enum: [
|
|
10869
|
-
nativeEnum: [
|
|
10870
|
-
union: [
|
|
10871
|
-
discriminatedUnion: [
|
|
10872
|
-
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]
|
|
10873
10709
|
};
|
|
10874
10710
|
function normalizeSchemaName(name) {
|
|
10875
10711
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -10878,20 +10714,20 @@ function normalizeTypeName(name) {
|
|
|
10878
10714
|
return name.replace(/Type$/, "").toLowerCase();
|
|
10879
10715
|
}
|
|
10880
10716
|
function unwrapNullish(annotation) {
|
|
10881
|
-
if (annotation.type !==
|
|
10717
|
+
if (annotation.type !== import_utils63.AST_NODE_TYPES.TSUnionType) {
|
|
10882
10718
|
return {
|
|
10883
10719
|
core: annotation,
|
|
10884
|
-
nullable: annotation.type ===
|
|
10720
|
+
nullable: annotation.type === import_utils63.AST_NODE_TYPES.TSNullKeyword
|
|
10885
10721
|
};
|
|
10886
10722
|
}
|
|
10887
10723
|
const rest = [];
|
|
10888
10724
|
let nullable = false;
|
|
10889
10725
|
for (const member of annotation.types) {
|
|
10890
|
-
if (member.type ===
|
|
10726
|
+
if (member.type === import_utils63.AST_NODE_TYPES.TSNullKeyword) {
|
|
10891
10727
|
nullable = true;
|
|
10892
10728
|
continue;
|
|
10893
10729
|
}
|
|
10894
|
-
if (member.type ===
|
|
10730
|
+
if (member.type === import_utils63.AST_NODE_TYPES.TSUndefinedKeyword) {
|
|
10895
10731
|
continue;
|
|
10896
10732
|
}
|
|
10897
10733
|
rest.push(member);
|
|
@@ -10913,6 +10749,9 @@ function leafAgrees(leaf, annotation) {
|
|
|
10913
10749
|
if (core === null) {
|
|
10914
10750
|
return null;
|
|
10915
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
|
+
}
|
|
10916
10755
|
return expected.includes(core.type);
|
|
10917
10756
|
}
|
|
10918
10757
|
var prefer_zod_infer_default = createRule({
|
|
@@ -10956,14 +10795,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
10956
10795
|
function zodCallChain(node) {
|
|
10957
10796
|
const chain = [];
|
|
10958
10797
|
let current = node;
|
|
10959
|
-
while (current.type ===
|
|
10798
|
+
while (current.type === import_utils63.AST_NODE_TYPES.CallExpression) {
|
|
10960
10799
|
const callee = current.callee;
|
|
10961
|
-
if (callee.type !==
|
|
10800
|
+
if (callee.type !== import_utils63.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils63.AST_NODE_TYPES.Identifier) {
|
|
10962
10801
|
return null;
|
|
10963
10802
|
}
|
|
10964
10803
|
chain.push(current);
|
|
10965
10804
|
const receiver = callee.object;
|
|
10966
|
-
if (receiver.type ===
|
|
10805
|
+
if (receiver.type === import_utils63.AST_NODE_TYPES.Identifier) {
|
|
10967
10806
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
10968
10807
|
}
|
|
10969
10808
|
current = receiver;
|
|
@@ -10972,19 +10811,19 @@ var prefer_zod_infer_default = createRule({
|
|
|
10972
10811
|
}
|
|
10973
10812
|
function methodName2(call) {
|
|
10974
10813
|
const callee = call.callee;
|
|
10975
|
-
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 : "";
|
|
10976
10815
|
}
|
|
10977
10816
|
function schemaField(node) {
|
|
10978
10817
|
const modifiers = [];
|
|
10979
10818
|
let current = node;
|
|
10980
10819
|
let leaf = null;
|
|
10981
|
-
while (current.type ===
|
|
10820
|
+
while (current.type === import_utils63.AST_NODE_TYPES.CallExpression) {
|
|
10982
10821
|
const callee = current.callee;
|
|
10983
|
-
if (callee.type !==
|
|
10822
|
+
if (callee.type !== import_utils63.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils63.AST_NODE_TYPES.Identifier) {
|
|
10984
10823
|
break;
|
|
10985
10824
|
}
|
|
10986
10825
|
const receiver = callee.object;
|
|
10987
|
-
if (receiver.type ===
|
|
10826
|
+
if (receiver.type === import_utils63.AST_NODE_TYPES.Identifier && zodNamespaces.has(receiver.name)) {
|
|
10988
10827
|
leaf = callee.property.name;
|
|
10989
10828
|
break;
|
|
10990
10829
|
}
|
|
@@ -11015,16 +10854,16 @@ var prefer_zod_infer_default = createRule({
|
|
|
11015
10854
|
return null;
|
|
11016
10855
|
}
|
|
11017
10856
|
const shape = base.arguments[0];
|
|
11018
|
-
if (shape === void 0 || shape.type !==
|
|
10857
|
+
if (shape === void 0 || shape.type !== import_utils63.AST_NODE_TYPES.ObjectExpression) {
|
|
11019
10858
|
return null;
|
|
11020
10859
|
}
|
|
11021
10860
|
const fields = /* @__PURE__ */ new Map();
|
|
11022
10861
|
for (const property of shape.properties) {
|
|
11023
|
-
if (property.type !==
|
|
10862
|
+
if (property.type !== import_utils63.AST_NODE_TYPES.Property || property.computed) {
|
|
11024
10863
|
return null;
|
|
11025
10864
|
}
|
|
11026
10865
|
const { key } = property;
|
|
11027
|
-
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;
|
|
11028
10867
|
if (name === null) {
|
|
11029
10868
|
return null;
|
|
11030
10869
|
}
|
|
@@ -11035,11 +10874,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
11035
10874
|
function typeMembers(members) {
|
|
11036
10875
|
const result = /* @__PURE__ */ new Map();
|
|
11037
10876
|
for (const member of members) {
|
|
11038
|
-
if (member.type !==
|
|
10877
|
+
if (member.type !== import_utils63.AST_NODE_TYPES.TSPropertySignature || member.computed) {
|
|
11039
10878
|
return null;
|
|
11040
10879
|
}
|
|
11041
10880
|
const { key } = member;
|
|
11042
|
-
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;
|
|
11043
10882
|
if (name === null) {
|
|
11044
10883
|
return null;
|
|
11045
10884
|
}
|
|
@@ -11047,14 +10886,15 @@ var prefer_zod_infer_default = createRule({
|
|
|
11047
10886
|
result.set(name, {
|
|
11048
10887
|
optional: member.optional === true,
|
|
11049
10888
|
nullable: annotation !== null && unwrapNullish(annotation).nullable,
|
|
10889
|
+
readonly: member.readonly === true,
|
|
11050
10890
|
annotation
|
|
11051
10891
|
});
|
|
11052
10892
|
}
|
|
11053
10893
|
return result.size === 0 ? null : result;
|
|
11054
10894
|
}
|
|
11055
10895
|
function collectConstrainedNames(node) {
|
|
11056
|
-
if (node.type ===
|
|
11057
|
-
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) {
|
|
11058
10898
|
constrainedTypeNames.add(node.typeName.name);
|
|
11059
10899
|
}
|
|
11060
10900
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -11062,11 +10902,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
11062
10902
|
}
|
|
11063
10903
|
return;
|
|
11064
10904
|
}
|
|
11065
|
-
if (node.type ===
|
|
10905
|
+
if (node.type === import_utils63.AST_NODE_TYPES.TSArrayType) {
|
|
11066
10906
|
collectConstrainedNames(node.elementType);
|
|
11067
10907
|
return;
|
|
11068
10908
|
}
|
|
11069
|
-
if (node.type ===
|
|
10909
|
+
if (node.type === import_utils63.AST_NODE_TYPES.TSUnionType || node.type === import_utils63.AST_NODE_TYPES.TSIntersectionType) {
|
|
11070
10910
|
for (const member of node.types) {
|
|
11071
10911
|
collectConstrainedNames(member);
|
|
11072
10912
|
}
|
|
@@ -11094,6 +10934,9 @@ var prefer_zod_infer_default = createRule({
|
|
|
11094
10934
|
if (field.nullable !== member.nullable) {
|
|
11095
10935
|
return false;
|
|
11096
10936
|
}
|
|
10937
|
+
if (member.readonly) {
|
|
10938
|
+
return false;
|
|
10939
|
+
}
|
|
11097
10940
|
const agrees = leafAgrees(field.leaf, member.annotation);
|
|
11098
10941
|
if (agrees === false) {
|
|
11099
10942
|
return false;
|
|
@@ -11106,17 +10949,17 @@ var prefer_zod_infer_default = createRule({
|
|
|
11106
10949
|
}
|
|
11107
10950
|
return {
|
|
11108
10951
|
ImportDeclaration(node) {
|
|
11109
|
-
if (!
|
|
10952
|
+
if (!isZodModule(node.source.value)) {
|
|
11110
10953
|
return;
|
|
11111
10954
|
}
|
|
11112
10955
|
for (const specifier of node.specifiers) {
|
|
11113
|
-
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") {
|
|
11114
10957
|
zodNamespaces.add(specifier.local.name);
|
|
11115
10958
|
}
|
|
11116
10959
|
}
|
|
11117
10960
|
},
|
|
11118
10961
|
VariableDeclarator(node) {
|
|
11119
|
-
if (node.id.type !==
|
|
10962
|
+
if (node.id.type !== import_utils63.AST_NODE_TYPES.Identifier || node.init == null) {
|
|
11120
10963
|
return;
|
|
11121
10964
|
}
|
|
11122
10965
|
const fields = schemaFields(node.init);
|
|
@@ -11126,14 +10969,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
11126
10969
|
},
|
|
11127
10970
|
/** Records `XSchema.transform(...)` and equivalent module-level reshaping. */
|
|
11128
10971
|
"MemberExpression[computed=false]"(node) {
|
|
11129
|
-
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)) {
|
|
11130
10973
|
reshapedSchemaNames.add(node.object.name);
|
|
11131
10974
|
}
|
|
11132
10975
|
},
|
|
11133
10976
|
/** Records every type argument carried by a Zod constraint. */
|
|
11134
10977
|
TSTypeReference(node) {
|
|
11135
10978
|
const { typeName } = node;
|
|
11136
|
-
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;
|
|
11137
10980
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
11138
10981
|
return;
|
|
11139
10982
|
}
|
|
@@ -11151,7 +10994,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
11151
10994
|
}
|
|
11152
10995
|
},
|
|
11153
10996
|
TSTypeAliasDeclaration(node) {
|
|
11154
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
10997
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== import_utils63.AST_NODE_TYPES.TSTypeLiteral) {
|
|
11155
10998
|
return;
|
|
11156
10999
|
}
|
|
11157
11000
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -11196,10 +11039,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
11196
11039
|
});
|
|
11197
11040
|
|
|
11198
11041
|
// src/rules/require-assert-never.ts
|
|
11199
|
-
var
|
|
11042
|
+
var import_utils64 = require("@typescript-eslint/utils");
|
|
11043
|
+
var import_typescript = __toESM(require("typescript"), 1);
|
|
11200
11044
|
var isRuntimeHandlingStatement = (statement) => {
|
|
11201
|
-
if (statement.type ===
|
|
11202
|
-
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) {
|
|
11203
11050
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
11204
11051
|
}
|
|
11205
11052
|
return true;
|
|
@@ -11215,11 +11062,40 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
11215
11062
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
11216
11063
|
}
|
|
11217
11064
|
const only = defaultCase.consequent[0];
|
|
11218
|
-
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)) {
|
|
11219
11066
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
11220
11067
|
}
|
|
11221
11068
|
return false;
|
|
11222
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
|
+
}
|
|
11223
11099
|
var require_assert_never_default = createRule({
|
|
11224
11100
|
name: "require-assert-never",
|
|
11225
11101
|
meta: {
|
|
@@ -11234,6 +11110,12 @@ var require_assert_never_default = createRule({
|
|
|
11234
11110
|
},
|
|
11235
11111
|
defaultOptions: [],
|
|
11236
11112
|
create(context) {
|
|
11113
|
+
let services;
|
|
11114
|
+
try {
|
|
11115
|
+
services = import_utils64.ESLintUtils.getParserServices(context);
|
|
11116
|
+
} catch {
|
|
11117
|
+
return {};
|
|
11118
|
+
}
|
|
11237
11119
|
return {
|
|
11238
11120
|
SwitchStatement(node) {
|
|
11239
11121
|
const defaultIndex = node.cases.findIndex(
|
|
@@ -11245,6 +11127,7 @@ var require_assert_never_default = createRule({
|
|
|
11245
11127
|
if (defaultCase.consequent.some(isRuntimeHandlingStatement)) return;
|
|
11246
11128
|
if (isFallthroughDefault(node, defaultIndex)) return;
|
|
11247
11129
|
if (isCommentOnlyNoopDefault(defaultCase, context.sourceCode)) return;
|
|
11130
|
+
if (!isExhaustiveFiniteSwitch(node, services)) return;
|
|
11248
11131
|
context.report({
|
|
11249
11132
|
node: defaultCase,
|
|
11250
11133
|
messageId: "missingAssertNever"
|
|
@@ -11255,7 +11138,7 @@ var require_assert_never_default = createRule({
|
|
|
11255
11138
|
});
|
|
11256
11139
|
|
|
11257
11140
|
// src/rules/require-fetch-timeout.ts
|
|
11258
|
-
var
|
|
11141
|
+
var import_utils65 = require("@typescript-eslint/utils");
|
|
11259
11142
|
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set([
|
|
11260
11143
|
"globalThis",
|
|
11261
11144
|
"window",
|
|
@@ -11271,14 +11154,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
11271
11154
|
return false;
|
|
11272
11155
|
}
|
|
11273
11156
|
function initProvablyLacksSignal(init) {
|
|
11274
|
-
if (init.type !==
|
|
11157
|
+
if (init.type !== import_utils65.AST_NODE_TYPES.ObjectExpression) {
|
|
11275
11158
|
return false;
|
|
11276
11159
|
}
|
|
11277
11160
|
for (const prop of init.properties) {
|
|
11278
|
-
if (prop.type ===
|
|
11161
|
+
if (prop.type === import_utils65.AST_NODE_TYPES.SpreadElement) {
|
|
11279
11162
|
return false;
|
|
11280
11163
|
}
|
|
11281
|
-
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") {
|
|
11282
11165
|
return false;
|
|
11283
11166
|
}
|
|
11284
11167
|
if (prop.computed) {
|
|
@@ -11288,7 +11171,7 @@ function initProvablyLacksSignal(init) {
|
|
|
11288
11171
|
return true;
|
|
11289
11172
|
}
|
|
11290
11173
|
function isInlineUrl(node, resolvesToGlobal) {
|
|
11291
|
-
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);
|
|
11292
11175
|
}
|
|
11293
11176
|
var require_fetch_timeout_default = createRule({
|
|
11294
11177
|
name: "require-fetch-timeout",
|
|
@@ -11325,14 +11208,14 @@ var require_fetch_timeout_default = createRule({
|
|
|
11325
11208
|
}
|
|
11326
11209
|
function resolvesToGlobal(identifier) {
|
|
11327
11210
|
const scope = context.sourceCode.getScope(identifier);
|
|
11328
|
-
const variable =
|
|
11211
|
+
const variable = import_utils65.ASTUtils.findVariable(scope, identifier.name);
|
|
11329
11212
|
return variable === null || variable.defs.length === 0;
|
|
11330
11213
|
}
|
|
11331
11214
|
function isGlobalFetchCall2(callee) {
|
|
11332
|
-
if (callee.type ===
|
|
11215
|
+
if (callee.type === import_utils65.AST_NODE_TYPES.Identifier) {
|
|
11333
11216
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
11334
11217
|
}
|
|
11335
|
-
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);
|
|
11336
11219
|
}
|
|
11337
11220
|
return {
|
|
11338
11221
|
CallExpression(node) {
|
|
@@ -11352,7 +11235,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
11352
11235
|
});
|
|
11353
11236
|
|
|
11354
11237
|
// src/rules/require-interface-for-injected-service.ts
|
|
11355
|
-
var
|
|
11238
|
+
var import_utils66 = require("@typescript-eslint/utils");
|
|
11356
11239
|
var CONFIGISH_TYPE_RE = /(?:Options|Opts|Config|Configuration|Settings|Params|Props|Args|Env|Environment|Callbacks|Flags)$/;
|
|
11357
11240
|
var CONFIGISH_NAME_RE = /^(?:options|opts|config|configuration|settings|params|props|args|env|environment|callbacks|flags|logger|log|clock)$/i;
|
|
11358
11241
|
var HTTP_TRANSPORT_TYPE_RE = /^(?:KyInstance|AxiosInstance|Session)$/;
|
|
@@ -11365,46 +11248,46 @@ var FLUENT_RESULT_TYPE_RE = /(?:Builder|Base|Query|Without)(?:\W|$)/;
|
|
|
11365
11248
|
var ROUTER_FACTORY_NAME = "Router";
|
|
11366
11249
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
11367
11250
|
var STORAGE_ASSIGNMENT_OPERATORS = /* @__PURE__ */ new Set(["=", "&&=", "??=", "||="]);
|
|
11368
|
-
var
|
|
11369
|
-
if (member.property.type ===
|
|
11370
|
-
if (!member.computed && member.property.type ===
|
|
11371
|
-
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;
|
|
11372
11255
|
};
|
|
11373
11256
|
var detachedValueExports = (program) => {
|
|
11374
11257
|
const names = /* @__PURE__ */ new Set();
|
|
11375
11258
|
for (const statement of program.body) {
|
|
11376
|
-
if (statement.type ===
|
|
11259
|
+
if (statement.type === import_utils66.AST_NODE_TYPES.ExportNamedDeclaration && statement.declaration === null && statement.source === null && statement.exportKind !== "type") {
|
|
11377
11260
|
for (const specifier of statement.specifiers) {
|
|
11378
11261
|
if (specifier.exportKind !== "type") names.add(specifier.local.name);
|
|
11379
11262
|
}
|
|
11380
|
-
} else if (statement.type ===
|
|
11263
|
+
} else if (statement.type === import_utils66.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils66.AST_NODE_TYPES.Identifier) {
|
|
11381
11264
|
names.add(statement.declaration.name);
|
|
11382
|
-
} else if (statement.type ===
|
|
11265
|
+
} else if (statement.type === import_utils66.AST_NODE_TYPES.TSExportAssignment && statement.expression.type === import_utils66.AST_NODE_TYPES.Identifier) {
|
|
11383
11266
|
names.add(statement.expression.name);
|
|
11384
11267
|
}
|
|
11385
11268
|
}
|
|
11386
11269
|
return names;
|
|
11387
11270
|
};
|
|
11388
|
-
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);
|
|
11389
11272
|
var readTypeReference = (annotation) => {
|
|
11390
|
-
if (annotation?.type ===
|
|
11273
|
+
if (annotation?.type === import_utils66.AST_NODE_TYPES.TSUnionType) {
|
|
11391
11274
|
const members = annotation.types.filter(
|
|
11392
|
-
(member) => member.type !==
|
|
11275
|
+
(member) => member.type !== import_utils66.AST_NODE_TYPES.TSUndefinedKeyword && member.type !== import_utils66.AST_NODE_TYPES.TSNullKeyword
|
|
11393
11276
|
);
|
|
11394
11277
|
annotation = members.length === 1 ? members[0] : void 0;
|
|
11395
11278
|
}
|
|
11396
|
-
if (annotation === void 0 || annotation.type !==
|
|
11279
|
+
if (annotation === void 0 || annotation.type !== import_utils66.AST_NODE_TYPES.TSTypeReference) return null;
|
|
11397
11280
|
const { typeName } = annotation;
|
|
11398
|
-
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;
|
|
11399
11282
|
if (rightmost === null) return null;
|
|
11400
11283
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
11401
11284
|
};
|
|
11402
|
-
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}` : "";
|
|
11403
11286
|
var propertySignatureTypes = (members) => {
|
|
11404
11287
|
const types = /* @__PURE__ */ new Map();
|
|
11405
11288
|
for (const member of members) {
|
|
11406
|
-
if (member.type !==
|
|
11407
|
-
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;
|
|
11408
11291
|
const reference = readTypeReference(member.typeAnnotation?.typeAnnotation);
|
|
11409
11292
|
if (reference === null) continue;
|
|
11410
11293
|
types.set(member.key.name, reference);
|
|
@@ -11415,18 +11298,18 @@ var fileTypeIndex = (program) => {
|
|
|
11415
11298
|
const objects = /* @__PURE__ */ new Map();
|
|
11416
11299
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
11417
11300
|
for (const statement of program.body) {
|
|
11418
|
-
const declaration = statement.type ===
|
|
11419
|
-
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) {
|
|
11420
11303
|
objects.set(declaration.id.name, propertySignatureTypes(declaration.body.body));
|
|
11421
11304
|
continue;
|
|
11422
11305
|
}
|
|
11423
|
-
if (declaration?.type !==
|
|
11306
|
+
if (declaration?.type !== import_utils66.AST_NODE_TYPES.TSTypeAliasDeclaration) continue;
|
|
11424
11307
|
const aliased = declaration.typeAnnotation;
|
|
11425
|
-
if (aliased.type ===
|
|
11308
|
+
if (aliased.type === import_utils66.AST_NODE_TYPES.TSFunctionType || aliased.type === import_utils66.AST_NODE_TYPES.TSConstructorType) {
|
|
11426
11309
|
functionAliases.add(declaration.id.name);
|
|
11427
11310
|
continue;
|
|
11428
11311
|
}
|
|
11429
|
-
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) : [];
|
|
11430
11313
|
if (literals.length === 0) continue;
|
|
11431
11314
|
const merged = /* @__PURE__ */ new Map();
|
|
11432
11315
|
for (const literal of literals) {
|
|
@@ -11454,10 +11337,10 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
11454
11337
|
while (pending.length > 0) {
|
|
11455
11338
|
const current = pending.pop();
|
|
11456
11339
|
if (current === void 0) break;
|
|
11457
|
-
if (current.type ===
|
|
11458
|
-
const expression = current.type ===
|
|
11459
|
-
const storedField = expression?.type ===
|
|
11460
|
-
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) {
|
|
11461
11344
|
for (const key of Object.keys(current)) {
|
|
11462
11345
|
if (key === "parent") continue;
|
|
11463
11346
|
const value = current[key];
|
|
@@ -11470,14 +11353,14 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
11470
11353
|
continue;
|
|
11471
11354
|
}
|
|
11472
11355
|
let source = expression.right;
|
|
11473
|
-
while (source.type ===
|
|
11474
|
-
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) {
|
|
11475
11358
|
constructedFields += 1;
|
|
11476
|
-
} else if (source.type ===
|
|
11359
|
+
} else if (source.type === import_utils66.AST_NODE_TYPES.Identifier) {
|
|
11477
11360
|
const fields = storedFieldsFrom.get(source.name) ?? /* @__PURE__ */ new Set();
|
|
11478
11361
|
fields.add(storedField);
|
|
11479
11362
|
storedFieldsFrom.set(source.name, fields);
|
|
11480
|
-
} else if (source.type ===
|
|
11363
|
+
} else if (source.type === import_utils66.AST_NODE_TYPES.MemberExpression && source.object.type === import_utils66.AST_NODE_TYPES.Identifier) {
|
|
11481
11364
|
const fields = storedFieldsFrom.get(source.object.name) ?? /* @__PURE__ */ new Set();
|
|
11482
11365
|
fields.add(storedField);
|
|
11483
11366
|
storedFieldsFrom.set(source.object.name, fields);
|
|
@@ -11487,7 +11370,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
11487
11370
|
const collaborators = [];
|
|
11488
11371
|
for (const parameter of ctor.value.params) {
|
|
11489
11372
|
for (const reference of parameterCollaborators(parameter, declared)) {
|
|
11490
|
-
const fields = parameter.type ===
|
|
11373
|
+
const fields = parameter.type === import_utils66.AST_NODE_TYPES.TSParameterProperty ? [reference.name] : [...storedFieldsFrom.get(reference.name) ?? []];
|
|
11491
11374
|
if (fields.length === 0) continue;
|
|
11492
11375
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
11493
11376
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -11502,8 +11385,8 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
11502
11385
|
};
|
|
11503
11386
|
var parameterCollaborators = (parameter, declared) => {
|
|
11504
11387
|
let target = parameter;
|
|
11505
|
-
if (target.type ===
|
|
11506
|
-
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) {
|
|
11507
11390
|
return objectPatternCollaborators(target, declared);
|
|
11508
11391
|
}
|
|
11509
11392
|
const named2 = namedParameterCollaborator(parameter);
|
|
@@ -11511,9 +11394,9 @@ var parameterCollaborators = (parameter, declared) => {
|
|
|
11511
11394
|
};
|
|
11512
11395
|
var namedParameterCollaborator = (annotated) => {
|
|
11513
11396
|
let target = annotated;
|
|
11514
|
-
if (target.type ===
|
|
11515
|
-
if (target.type ===
|
|
11516
|
-
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;
|
|
11517
11400
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
11518
11401
|
if (reference === null) return null;
|
|
11519
11402
|
return { name: target.name, ...reference, fields: [] };
|
|
@@ -11525,11 +11408,11 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
11525
11408
|
if (members === null) return [];
|
|
11526
11409
|
const collaborators = [];
|
|
11527
11410
|
for (const property of pattern.properties) {
|
|
11528
|
-
if (property.type !==
|
|
11529
|
-
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;
|
|
11530
11413
|
const key = property.key.name;
|
|
11531
|
-
const bound = property.value.type ===
|
|
11532
|
-
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;
|
|
11533
11416
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
11534
11417
|
const reference = members.get(key);
|
|
11535
11418
|
if (reference === void 0) continue;
|
|
@@ -11538,21 +11421,21 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
11538
11421
|
return collaborators;
|
|
11539
11422
|
};
|
|
11540
11423
|
var bagMemberTypes = (annotation, declared) => {
|
|
11541
|
-
if (annotation.type ===
|
|
11424
|
+
if (annotation.type === import_utils66.AST_NODE_TYPES.TSTypeLiteral) {
|
|
11542
11425
|
return propertySignatureTypes(annotation.members);
|
|
11543
11426
|
}
|
|
11544
|
-
if (annotation.type !==
|
|
11427
|
+
if (annotation.type !== import_utils66.AST_NODE_TYPES.TSTypeReference || annotation.typeName.type !== import_utils66.AST_NODE_TYPES.Identifier) {
|
|
11545
11428
|
return null;
|
|
11546
11429
|
}
|
|
11547
11430
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
11548
11431
|
};
|
|
11549
11432
|
var isFrameworkWiring = (body2) => subtreeHas(body2, (node) => {
|
|
11550
|
-
if (node.type ===
|
|
11433
|
+
if (node.type === import_utils66.AST_NODE_TYPES.CallExpression) {
|
|
11551
11434
|
const { callee } = node;
|
|
11552
|
-
if (callee.type ===
|
|
11553
|
-
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;
|
|
11554
11437
|
}
|
|
11555
|
-
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);
|
|
11556
11439
|
});
|
|
11557
11440
|
var subtreeHas = (root, found) => {
|
|
11558
11441
|
let hit = false;
|
|
@@ -11579,19 +11462,19 @@ var invokedInstanceField = (call) => {
|
|
|
11579
11462
|
const direct = instanceField(call.callee);
|
|
11580
11463
|
if (direct !== null) return direct;
|
|
11581
11464
|
let callee = call.callee;
|
|
11582
|
-
while (callee.type ===
|
|
11583
|
-
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;
|
|
11584
11467
|
};
|
|
11585
11468
|
var instanceField = (candidate) => {
|
|
11586
11469
|
let node = candidate;
|
|
11587
|
-
while (node.type ===
|
|
11588
|
-
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;
|
|
11589
11472
|
};
|
|
11590
11473
|
var behaviorallyInvokedFields = (body2) => {
|
|
11591
11474
|
const invoked = /* @__PURE__ */ new Set();
|
|
11592
11475
|
const visit = (current) => {
|
|
11593
|
-
if (current.type ===
|
|
11594
|
-
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) {
|
|
11595
11478
|
const field = invokedInstanceField(current);
|
|
11596
11479
|
if (field !== null) invoked.add(field);
|
|
11597
11480
|
}
|
|
@@ -11604,14 +11487,14 @@ var behaviorallyInvokedFields = (body2) => {
|
|
|
11604
11487
|
}
|
|
11605
11488
|
};
|
|
11606
11489
|
for (const member of body2.body) {
|
|
11607
|
-
if (member.type ===
|
|
11608
|
-
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) {
|
|
11609
11492
|
if (member.value.body !== null && member.value.body !== void 0) visit(member.value.body);
|
|
11610
11493
|
continue;
|
|
11611
11494
|
}
|
|
11612
|
-
if (member.type !==
|
|
11495
|
+
if (member.type !== import_utils66.AST_NODE_TYPES.PropertyDefinition || member.value === null) continue;
|
|
11613
11496
|
visit(
|
|
11614
|
-
member.value.type ===
|
|
11497
|
+
member.value.type === import_utils66.AST_NODE_TYPES.ArrowFunctionExpression ? member.value.body : member.value
|
|
11615
11498
|
);
|
|
11616
11499
|
}
|
|
11617
11500
|
return invoked;
|
|
@@ -11631,25 +11514,25 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
11631
11514
|
var fileInterfaceNames = (program) => {
|
|
11632
11515
|
const names = [];
|
|
11633
11516
|
for (const statement of program.body) {
|
|
11634
|
-
const declaration = statement.type ===
|
|
11635
|
-
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);
|
|
11636
11519
|
}
|
|
11637
11520
|
return names;
|
|
11638
11521
|
};
|
|
11639
11522
|
var publicMethodNames = (body2, functionAliases) => {
|
|
11640
11523
|
const names = [];
|
|
11641
11524
|
for (const member of body2.body) {
|
|
11642
|
-
if (member.type ===
|
|
11525
|
+
if (member.type === import_utils66.AST_NODE_TYPES.PropertyDefinition) {
|
|
11643
11526
|
if (member.static || member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
11644
|
-
if (member.value?.type !==
|
|
11645
|
-
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");
|
|
11646
11529
|
continue;
|
|
11647
11530
|
}
|
|
11648
|
-
if (member.type !==
|
|
11531
|
+
if (member.type !== import_utils66.AST_NODE_TYPES.MethodDefinition) continue;
|
|
11649
11532
|
if (member.kind !== "method" || member.static) continue;
|
|
11650
11533
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
11651
|
-
if (member.key.type ===
|
|
11652
|
-
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);
|
|
11653
11536
|
else names.push("\u2026");
|
|
11654
11537
|
}
|
|
11655
11538
|
return names;
|
|
@@ -11657,13 +11540,13 @@ var publicMethodNames = (body2, functionAliases) => {
|
|
|
11657
11540
|
var isFluentConstructionObject = (node, getText) => {
|
|
11658
11541
|
if (node.id === null) return false;
|
|
11659
11542
|
const methods = node.body.body.filter(
|
|
11660
|
-
(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
|
|
11661
11544
|
);
|
|
11662
11545
|
if (methods.length === 0) return false;
|
|
11663
11546
|
return methods.every((member) => {
|
|
11664
11547
|
const result = member.value.returnType?.typeAnnotation;
|
|
11665
11548
|
if (result === void 0) return false;
|
|
11666
|
-
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;
|
|
11667
11550
|
return returnsOwnType || FLUENT_BUILDER_NAME_RE.test(node.id?.name ?? "") && FLUENT_RESULT_TYPE_RE.test(getText(result));
|
|
11668
11551
|
});
|
|
11669
11552
|
};
|
|
@@ -11671,10 +11554,10 @@ function localClassAbstractness(program) {
|
|
|
11671
11554
|
const classes = /* @__PURE__ */ new Map();
|
|
11672
11555
|
const parents = /* @__PURE__ */ new Map();
|
|
11673
11556
|
for (const statement of program.body) {
|
|
11674
|
-
const declaration = statement.type ===
|
|
11675
|
-
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) {
|
|
11676
11559
|
classes.set(declaration.id.name, declaration.abstract === true);
|
|
11677
|
-
if (declaration.superClass?.type ===
|
|
11560
|
+
if (declaration.superClass?.type === import_utils66.AST_NODE_TYPES.Identifier) {
|
|
11678
11561
|
parents.set(declaration.id.name, declaration.superClass.name);
|
|
11679
11562
|
}
|
|
11680
11563
|
}
|
|
@@ -11696,43 +11579,43 @@ function localInterfaceSurfaces(program) {
|
|
|
11696
11579
|
const parents = /* @__PURE__ */ new Map();
|
|
11697
11580
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
11698
11581
|
for (const statement of program.body) {
|
|
11699
|
-
const declaration = statement.type ===
|
|
11700
|
-
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);
|
|
11701
11584
|
}
|
|
11702
11585
|
for (const statement of program.body) {
|
|
11703
|
-
const declaration = statement.type ===
|
|
11704
|
-
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) {
|
|
11705
11588
|
const callables2 = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
11706
|
-
const parts = declaration.typeAnnotation.type ===
|
|
11589
|
+
const parts = declaration.typeAnnotation.type === import_utils66.AST_NODE_TYPES.TSIntersectionType ? declaration.typeAnnotation.types : [declaration.typeAnnotation];
|
|
11707
11590
|
const inherited = parents.get(declaration.id.name) ?? [];
|
|
11708
11591
|
for (const part of parts) {
|
|
11709
|
-
if (part.type ===
|
|
11592
|
+
if (part.type === import_utils66.AST_NODE_TYPES.TSTypeReference && part.typeName.type === import_utils66.AST_NODE_TYPES.Identifier) {
|
|
11710
11593
|
inherited.push(part.typeName.name);
|
|
11711
11594
|
continue;
|
|
11712
11595
|
}
|
|
11713
|
-
if (part.type !==
|
|
11596
|
+
if (part.type !== import_utils66.AST_NODE_TYPES.TSTypeLiteral) continue;
|
|
11714
11597
|
for (const member of part.members) {
|
|
11715
|
-
if (member.type !==
|
|
11716
|
-
if (member.computed || member.key.type !==
|
|
11717
|
-
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) {
|
|
11718
11601
|
callables2.add(member.key.name);
|
|
11719
11602
|
continue;
|
|
11720
11603
|
}
|
|
11721
|
-
if (member.type !==
|
|
11604
|
+
if (member.type !== import_utils66.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
11722
11605
|
const annotation = member.typeAnnotation?.typeAnnotation;
|
|
11723
|
-
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);
|
|
11724
11607
|
}
|
|
11725
11608
|
}
|
|
11726
11609
|
interfaces.set(declaration.id.name, callables2);
|
|
11727
11610
|
parents.set(declaration.id.name, inherited);
|
|
11728
11611
|
continue;
|
|
11729
11612
|
}
|
|
11730
|
-
if (declaration?.type !==
|
|
11613
|
+
if (declaration?.type !== import_utils66.AST_NODE_TYPES.TSInterfaceDeclaration) continue;
|
|
11731
11614
|
const callables = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
11732
11615
|
for (const member of declaration.body.body) {
|
|
11733
|
-
if (member.type !==
|
|
11734
|
-
if (member.computed || member.key.type !==
|
|
11735
|
-
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);
|
|
11736
11619
|
}
|
|
11737
11620
|
interfaces.set(declaration.id.name, callables);
|
|
11738
11621
|
parents.set(
|
|
@@ -11740,7 +11623,7 @@ function localInterfaceSurfaces(program) {
|
|
|
11740
11623
|
[
|
|
11741
11624
|
...parents.get(declaration.id.name) ?? [],
|
|
11742
11625
|
...declaration.extends.flatMap(
|
|
11743
|
-
(heritage) => heritage.expression.type ===
|
|
11626
|
+
(heritage) => heritage.expression.type === import_utils66.AST_NODE_TYPES.Identifier ? [heritage.expression.name] : ["*"]
|
|
11744
11627
|
)
|
|
11745
11628
|
]
|
|
11746
11629
|
);
|
|
@@ -11767,7 +11650,7 @@ function localInterfaceSurfaces(program) {
|
|
|
11767
11650
|
}
|
|
11768
11651
|
function hasServicePort(node, methods, classes, interfaces) {
|
|
11769
11652
|
if (node.superClass !== null) {
|
|
11770
|
-
if (node.superClass.type !==
|
|
11653
|
+
if (node.superClass.type !== import_utils66.AST_NODE_TYPES.Identifier) return true;
|
|
11771
11654
|
const localAbstract = classes.get(node.superClass.name);
|
|
11772
11655
|
if (localAbstract === void 0 || localAbstract) return true;
|
|
11773
11656
|
}
|
|
@@ -11779,7 +11662,7 @@ function hasServicePort(node, methods, classes, interfaces) {
|
|
|
11779
11662
|
if (node.implements.length === 0) return false;
|
|
11780
11663
|
const combined = /* @__PURE__ */ new Set();
|
|
11781
11664
|
for (const implementation of node.implements) {
|
|
11782
|
-
if (implementation.expression.type !==
|
|
11665
|
+
if (implementation.expression.type !== import_utils66.AST_NODE_TYPES.Identifier) return true;
|
|
11783
11666
|
const name = implementation.expression.name;
|
|
11784
11667
|
const localAbstract = classes.get(name);
|
|
11785
11668
|
if (localAbstract === true) return true;
|
|
@@ -11821,7 +11704,7 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
11821
11704
|
if (node.abstract === true) return;
|
|
11822
11705
|
if (node.decorators.length > 0) return;
|
|
11823
11706
|
const ctor = node.body.body.find(
|
|
11824
|
-
(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
|
|
11825
11708
|
);
|
|
11826
11709
|
if (ctor === void 0) return;
|
|
11827
11710
|
const constructorFacts = readConstructor(
|
|
@@ -11856,37 +11739,37 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
11856
11739
|
});
|
|
11857
11740
|
|
|
11858
11741
|
// src/rules/require-static-next-matcher.ts
|
|
11859
|
-
var
|
|
11742
|
+
var import_utils67 = require("@typescript-eslint/utils");
|
|
11860
11743
|
var NEXT_ENTRY_FILE = /(?:^|[/\\])(?:middleware|proxy)\.[cm]?[jt]sx?$/u;
|
|
11861
11744
|
function unwrapExpression3(node) {
|
|
11862
|
-
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) {
|
|
11863
11746
|
return unwrapExpression3(node.expression);
|
|
11864
11747
|
}
|
|
11865
11748
|
return node;
|
|
11866
11749
|
}
|
|
11867
11750
|
function isStaticValue(node) {
|
|
11868
11751
|
const value = unwrapExpression3(node);
|
|
11869
|
-
if (value.type ===
|
|
11752
|
+
if (value.type === import_utils67.AST_NODE_TYPES.Literal) {
|
|
11870
11753
|
return true;
|
|
11871
11754
|
}
|
|
11872
|
-
if (value.type ===
|
|
11755
|
+
if (value.type === import_utils67.AST_NODE_TYPES.TemplateLiteral) {
|
|
11873
11756
|
return value.expressions.length === 0;
|
|
11874
11757
|
}
|
|
11875
|
-
if (value.type ===
|
|
11758
|
+
if (value.type === import_utils67.AST_NODE_TYPES.ArrayExpression) {
|
|
11876
11759
|
return value.elements.every(
|
|
11877
|
-
(element) => element !== null && element.type !==
|
|
11760
|
+
(element) => element !== null && element.type !== import_utils67.AST_NODE_TYPES.SpreadElement && isStaticValue(element)
|
|
11878
11761
|
);
|
|
11879
11762
|
}
|
|
11880
|
-
if (value.type ===
|
|
11763
|
+
if (value.type === import_utils67.AST_NODE_TYPES.ObjectExpression) {
|
|
11881
11764
|
return value.properties.every(
|
|
11882
|
-
(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)
|
|
11883
11766
|
);
|
|
11884
11767
|
}
|
|
11885
11768
|
return false;
|
|
11886
11769
|
}
|
|
11887
11770
|
function propertyName2(property) {
|
|
11888
11771
|
if (property.computed) return null;
|
|
11889
|
-
if (property.key.type ===
|
|
11772
|
+
if (property.key.type === import_utils67.AST_NODE_TYPES.Identifier) return property.key.name;
|
|
11890
11773
|
return typeof property.key.value === "string" ? property.key.value : null;
|
|
11891
11774
|
}
|
|
11892
11775
|
var require_static_next_matcher_default = createRule({
|
|
@@ -11908,19 +11791,19 @@ var require_static_next_matcher_default = createRule({
|
|
|
11908
11791
|
}
|
|
11909
11792
|
return {
|
|
11910
11793
|
ExportNamedDeclaration(node) {
|
|
11911
|
-
if (node.declaration?.type !==
|
|
11794
|
+
if (node.declaration?.type !== import_utils67.AST_NODE_TYPES.VariableDeclaration) {
|
|
11912
11795
|
return;
|
|
11913
11796
|
}
|
|
11914
11797
|
for (const declaration of node.declaration.declarations) {
|
|
11915
|
-
if (declaration.id.type !==
|
|
11798
|
+
if (declaration.id.type !== import_utils67.AST_NODE_TYPES.Identifier || declaration.id.name !== "config" || declaration.init === null) {
|
|
11916
11799
|
continue;
|
|
11917
11800
|
}
|
|
11918
11801
|
const config = unwrapExpression3(declaration.init);
|
|
11919
|
-
if (config.type !==
|
|
11802
|
+
if (config.type !== import_utils67.AST_NODE_TYPES.ObjectExpression) {
|
|
11920
11803
|
continue;
|
|
11921
11804
|
}
|
|
11922
11805
|
for (const property of config.properties) {
|
|
11923
|
-
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) {
|
|
11924
11807
|
continue;
|
|
11925
11808
|
}
|
|
11926
11809
|
if (!isStaticValue(property.value)) {
|
|
@@ -11934,28 +11817,30 @@ var require_static_next_matcher_default = createRule({
|
|
|
11934
11817
|
});
|
|
11935
11818
|
|
|
11936
11819
|
// src/rules/require-zod-form-validation.ts
|
|
11937
|
-
var
|
|
11820
|
+
var import_utils68 = require("@typescript-eslint/utils");
|
|
11938
11821
|
var isZodParseCall = (node) => {
|
|
11939
|
-
if (node.type !==
|
|
11822
|
+
if (node.type !== import_utils68.AST_NODE_TYPES.CallExpression) return false;
|
|
11940
11823
|
const callee = node.callee;
|
|
11941
|
-
if (callee.type !==
|
|
11824
|
+
if (callee.type !== import_utils68.AST_NODE_TYPES.MemberExpression) return false;
|
|
11942
11825
|
if (callee.computed) return false;
|
|
11943
|
-
if (callee.property.type !==
|
|
11826
|
+
if (callee.property.type !== import_utils68.AST_NODE_TYPES.Identifier) return false;
|
|
11944
11827
|
const method = callee.property.name;
|
|
11945
|
-
if (method !== "parse" && method !== "safeParse")
|
|
11828
|
+
if (method !== "parse" && method !== "safeParse" && method !== "parseAsync" && method !== "safeParseAsync") {
|
|
11829
|
+
return false;
|
|
11830
|
+
}
|
|
11946
11831
|
return looksLikeZodSchema(callee.object);
|
|
11947
11832
|
};
|
|
11948
11833
|
var looksLikeZodSchema = (node) => {
|
|
11949
11834
|
let current = node;
|
|
11950
11835
|
while (true) {
|
|
11951
|
-
if (current.type ===
|
|
11836
|
+
if (current.type === import_utils68.AST_NODE_TYPES.Identifier) {
|
|
11952
11837
|
return current.name === "z" || ZOD_SCHEMA_NAME_RE.test(current.name);
|
|
11953
11838
|
}
|
|
11954
|
-
if (current.type ===
|
|
11839
|
+
if (current.type === import_utils68.AST_NODE_TYPES.CallExpression) {
|
|
11955
11840
|
current = current.callee;
|
|
11956
11841
|
continue;
|
|
11957
11842
|
}
|
|
11958
|
-
if (current.type ===
|
|
11843
|
+
if (current.type === import_utils68.AST_NODE_TYPES.MemberExpression) {
|
|
11959
11844
|
current = current.object;
|
|
11960
11845
|
continue;
|
|
11961
11846
|
}
|
|
@@ -11964,12 +11849,12 @@ var looksLikeZodSchema = (node) => {
|
|
|
11964
11849
|
};
|
|
11965
11850
|
var isFormDataMethodCall = (node) => {
|
|
11966
11851
|
let current = node;
|
|
11967
|
-
if (current.type ===
|
|
11852
|
+
if (current.type === import_utils68.AST_NODE_TYPES.AwaitExpression) {
|
|
11968
11853
|
current = current.argument;
|
|
11969
11854
|
}
|
|
11970
|
-
if (current.type !==
|
|
11855
|
+
if (current.type !== import_utils68.AST_NODE_TYPES.CallExpression) return false;
|
|
11971
11856
|
const callee = current.callee;
|
|
11972
|
-
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";
|
|
11973
11858
|
};
|
|
11974
11859
|
var require_zod_form_validation_default = createRule({
|
|
11975
11860
|
name: "require-zod-form-validation",
|
|
@@ -11989,14 +11874,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
11989
11874
|
return {};
|
|
11990
11875
|
}
|
|
11991
11876
|
const isFormSourceIdentifier = (node) => {
|
|
11992
|
-
if (node.type !==
|
|
11877
|
+
if (node.type !== import_utils68.AST_NODE_TYPES.Identifier) return false;
|
|
11993
11878
|
if (/formdata/i.test(node.name)) return true;
|
|
11994
11879
|
let scope = context.sourceCode.getScope(node);
|
|
11995
11880
|
while (scope !== null) {
|
|
11996
11881
|
const variable = scope.set.get(node.name);
|
|
11997
11882
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
11998
11883
|
const def = variable.defs[0];
|
|
11999
|
-
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) {
|
|
12000
11885
|
return isFormDataMethodCall(def.node.init);
|
|
12001
11886
|
}
|
|
12002
11887
|
return false;
|
|
@@ -12007,8 +11892,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
12007
11892
|
};
|
|
12008
11893
|
const isFormDataGetCall = (node) => {
|
|
12009
11894
|
const callee = node.callee;
|
|
12010
|
-
if (callee.type !==
|
|
12011
|
-
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") {
|
|
12012
11897
|
return false;
|
|
12013
11898
|
}
|
|
12014
11899
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -12023,11 +11908,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
12023
11908
|
};
|
|
12024
11909
|
const isInstanceofNarrowing = (node) => {
|
|
12025
11910
|
const parent = node.parent;
|
|
12026
|
-
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");
|
|
12027
11912
|
};
|
|
12028
11913
|
const boundDeclarator = (node) => {
|
|
12029
|
-
|
|
12030
|
-
|
|
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) {
|
|
12031
11921
|
return parent;
|
|
12032
11922
|
}
|
|
12033
11923
|
return null;
|
|
@@ -12055,7 +11945,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
12055
11945
|
});
|
|
12056
11946
|
|
|
12057
11947
|
// src/rules/store-insert-requires-on-conflict.ts
|
|
12058
|
-
var
|
|
11948
|
+
var import_utils69 = require("@typescript-eslint/utils");
|
|
12059
11949
|
var INSERT_WRITE = /\bINSERT\s+(?:OR\s+\w+\s+)?INTO\s+[\w."'`?$:@-]+\s*(?:\([^)]*\)\s*)?(?:VALUES|SELECT|DEFAULT\s+VALUES)\b/i;
|
|
12060
11950
|
var CONFLICT_HANDLED = /\bON\s+CONFLICT\b|\bON\s+DUPLICATE\s+KEY\b|\bINSERT\s+OR\s+(?:IGNORE|REPLACE)\b/i;
|
|
12061
11951
|
var INSERT_GATE = /insert/i;
|
|
@@ -12086,9 +11976,9 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
12086
11976
|
});
|
|
12087
11977
|
|
|
12088
11978
|
// src/rules/stepdown.ts
|
|
12089
|
-
var
|
|
11979
|
+
var import_utils70 = require("@typescript-eslint/utils");
|
|
12090
11980
|
function isFunction(node) {
|
|
12091
|
-
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;
|
|
12092
11982
|
}
|
|
12093
11983
|
function reportMisordered(context, candidates, scopeDefinitions, calls, pinned) {
|
|
12094
11984
|
const byName = new Map(scopeDefinitions.map((definition) => [definition.name, definition]));
|
|
@@ -12183,8 +12073,8 @@ function moduleScope(context, program) {
|
|
|
12183
12073
|
for (const node of declarations) counts.set(node.name, (counts.get(node.name) ?? 0) + 1);
|
|
12184
12074
|
const overloadNames = new Set(
|
|
12185
12075
|
program.body.flatMap((statement) => {
|
|
12186
|
-
const node = statement.type ===
|
|
12187
|
-
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] : [];
|
|
12188
12078
|
})
|
|
12189
12079
|
);
|
|
12190
12080
|
const exported = exportedNames(program);
|
|
@@ -12206,7 +12096,7 @@ function moduleScope(context, program) {
|
|
|
12206
12096
|
const nearestFunction = [...ancestors].reverse().find(isFunction);
|
|
12207
12097
|
const parent = identifier.parent;
|
|
12208
12098
|
const callerDefinition = nearestFunction === void 0 ? void 0 : byFunction.get(nearestFunction);
|
|
12209
|
-
if (callerDefinition === void 0 || parent.type !==
|
|
12099
|
+
if (callerDefinition === void 0 || parent.type !== import_utils70.AST_NODE_TYPES.CallExpression || parent.callee !== identifier) {
|
|
12210
12100
|
pinned.add(definition.name);
|
|
12211
12101
|
continue;
|
|
12212
12102
|
}
|
|
@@ -12221,38 +12111,38 @@ function moduleScope(context, program) {
|
|
|
12221
12111
|
function exportedNames(program) {
|
|
12222
12112
|
const names = /* @__PURE__ */ new Set();
|
|
12223
12113
|
for (const statement of program.body) {
|
|
12224
|
-
if (statement.type !==
|
|
12225
|
-
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) {
|
|
12226
12116
|
names.add(statement.declaration.id.name);
|
|
12227
12117
|
}
|
|
12228
|
-
if (statement.declaration?.type ===
|
|
12118
|
+
if (statement.declaration?.type === import_utils70.AST_NODE_TYPES.VariableDeclaration) {
|
|
12229
12119
|
for (const declarator of statement.declaration.declarations) {
|
|
12230
|
-
if (declarator.id.type ===
|
|
12120
|
+
if (declarator.id.type === import_utils70.AST_NODE_TYPES.Identifier) names.add(declarator.id.name);
|
|
12231
12121
|
}
|
|
12232
12122
|
}
|
|
12233
12123
|
for (const specifier of statement.specifiers) {
|
|
12234
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
12124
|
+
if (specifier.exportKind !== "type" && specifier.local.type === import_utils70.AST_NODE_TYPES.Identifier) {
|
|
12235
12125
|
names.add(specifier.local.name);
|
|
12236
12126
|
}
|
|
12237
12127
|
}
|
|
12238
12128
|
}
|
|
12239
12129
|
for (const statement of program.body) {
|
|
12240
|
-
if (statement.type ===
|
|
12241
|
-
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);
|
|
12242
12132
|
}
|
|
12243
12133
|
return names;
|
|
12244
12134
|
}
|
|
12245
12135
|
function moduleDefinitions(program) {
|
|
12246
12136
|
const definitions = [];
|
|
12247
12137
|
for (const statement of program.body) {
|
|
12248
|
-
const node = statement.type ===
|
|
12249
|
-
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) {
|
|
12250
12140
|
definitions.push({ name: node.id.name, node, functionNode: node, bindingNode: node });
|
|
12251
12141
|
continue;
|
|
12252
12142
|
}
|
|
12253
|
-
if (node?.type !==
|
|
12143
|
+
if (node?.type !== import_utils70.AST_NODE_TYPES.VariableDeclaration || node.kind !== "const") continue;
|
|
12254
12144
|
for (const declarator of node.declarations) {
|
|
12255
|
-
if (declarator.id.type ===
|
|
12145
|
+
if (declarator.id.type === import_utils70.AST_NODE_TYPES.Identifier && declarator.init !== null && isFunction(declarator.init)) {
|
|
12256
12146
|
definitions.push({
|
|
12257
12147
|
name: declarator.id.name,
|
|
12258
12148
|
node: declarator,
|
|
@@ -12265,21 +12155,21 @@ function moduleDefinitions(program) {
|
|
|
12265
12155
|
return definitions;
|
|
12266
12156
|
}
|
|
12267
12157
|
function methodName(node) {
|
|
12268
|
-
if (node.key.type ===
|
|
12269
|
-
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;
|
|
12270
12160
|
}
|
|
12271
12161
|
function referencedMethod(context, node, classVariables) {
|
|
12272
|
-
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;
|
|
12273
12163
|
const isClassReference = objectVariable !== null && classVariables.has(objectVariable);
|
|
12274
|
-
if (node.object.type !==
|
|
12275
|
-
if (node.property.type ===
|
|
12276
|
-
if (!node.computed && node.property.type ===
|
|
12277
|
-
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;
|
|
12278
12168
|
}
|
|
12279
12169
|
function referencedPropertyName(node) {
|
|
12280
|
-
if (node.property.type ===
|
|
12281
|
-
if (!node.computed && node.property.type ===
|
|
12282
|
-
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;
|
|
12283
12173
|
}
|
|
12284
12174
|
function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
12285
12175
|
visit(node, nestedFunction);
|
|
@@ -12295,7 +12185,7 @@ function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
|
12295
12185
|
}
|
|
12296
12186
|
function classScope(context, node, computedReferenceNames) {
|
|
12297
12187
|
const methods = node.body.body.filter(
|
|
12298
|
-
(member) => member.type ===
|
|
12188
|
+
(member) => member.type === import_utils70.AST_NODE_TYPES.MethodDefinition
|
|
12299
12189
|
);
|
|
12300
12190
|
const counts = /* @__PURE__ */ new Map();
|
|
12301
12191
|
for (const method of methods) {
|
|
@@ -12303,8 +12193,8 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
12303
12193
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
12304
12194
|
}
|
|
12305
12195
|
for (const member of node.body.body) {
|
|
12306
|
-
if (member.type !==
|
|
12307
|
-
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;
|
|
12308
12198
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
12309
12199
|
}
|
|
12310
12200
|
const scopeDefinitions = methods.flatMap((method) => {
|
|
@@ -12313,7 +12203,7 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
12313
12203
|
});
|
|
12314
12204
|
const definitions = methods.flatMap((method) => {
|
|
12315
12205
|
const name = methodName(method);
|
|
12316
|
-
const isPrivate = method.accessibility === "private" || method.key.type ===
|
|
12206
|
+
const isPrivate = method.accessibility === "private" || method.key.type === import_utils70.AST_NODE_TYPES.PrivateIdentifier;
|
|
12317
12207
|
return name !== null && isPrivate && counts.get(name) === 1 && method.decorators.length === 0 ? [{ name, node: method }] : [];
|
|
12318
12208
|
});
|
|
12319
12209
|
if (definitions.length === 0) return;
|
|
@@ -12322,11 +12212,11 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
12322
12212
|
const pinned = /* @__PURE__ */ new Set();
|
|
12323
12213
|
const classVariables = /* @__PURE__ */ new Set();
|
|
12324
12214
|
if (node.id !== null) {
|
|
12325
|
-
const internal =
|
|
12215
|
+
const internal = import_utils70.ASTUtils.findVariable(context.sourceCode.getScope(node), node.id.name);
|
|
12326
12216
|
if (internal !== null) classVariables.add(internal);
|
|
12327
12217
|
}
|
|
12328
|
-
if (node.type ===
|
|
12329
|
-
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);
|
|
12330
12220
|
if (outer !== null) classVariables.add(outer);
|
|
12331
12221
|
}
|
|
12332
12222
|
for (const method of methods) {
|
|
@@ -12342,27 +12232,27 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
12342
12232
|
}
|
|
12343
12233
|
const thisValue = (value) => {
|
|
12344
12234
|
let current = value;
|
|
12345
|
-
while (current?.type ===
|
|
12346
|
-
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;
|
|
12347
12237
|
};
|
|
12348
12238
|
const collectAlias = (current, nestedFunction) => {
|
|
12349
|
-
if (nestedFunction || current.type !==
|
|
12350
|
-
if (current.type ===
|
|
12351
|
-
const binding = current.type ===
|
|
12352
|
-
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;
|
|
12353
12243
|
if (!thisValue(value)) return;
|
|
12354
|
-
if (binding.type ===
|
|
12244
|
+
if (binding.type === import_utils70.AST_NODE_TYPES.ObjectPattern) {
|
|
12355
12245
|
for (const property of binding.properties) {
|
|
12356
|
-
if (property.type ===
|
|
12246
|
+
if (property.type === import_utils70.AST_NODE_TYPES.RestElement) {
|
|
12357
12247
|
for (const name of privateNames) pinned.add(name);
|
|
12358
|
-
} else if (property.key.type ===
|
|
12248
|
+
} else if (property.key.type === import_utils70.AST_NODE_TYPES.Identifier && privateNames.has(property.key.name)) {
|
|
12359
12249
|
pinned.add(property.key.name);
|
|
12360
12250
|
}
|
|
12361
12251
|
}
|
|
12362
12252
|
return;
|
|
12363
12253
|
}
|
|
12364
|
-
if (binding.type !==
|
|
12365
|
-
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);
|
|
12366
12256
|
if (variable !== null) {
|
|
12367
12257
|
methodClassVariables.add(variable);
|
|
12368
12258
|
methodAliases.add(variable);
|
|
@@ -12375,16 +12265,16 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
12375
12265
|
walk(statement, context.sourceCode.visitorKeys, collectAlias);
|
|
12376
12266
|
}
|
|
12377
12267
|
const visitCall = (current, nestedFunction) => {
|
|
12378
|
-
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)) {
|
|
12379
12269
|
for (const property of current.id.properties) {
|
|
12380
|
-
if (property.type ===
|
|
12270
|
+
if (property.type === import_utils70.AST_NODE_TYPES.RestElement) {
|
|
12381
12271
|
for (const name of privateNames) pinned.add(name);
|
|
12382
12272
|
continue;
|
|
12383
12273
|
}
|
|
12384
|
-
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);
|
|
12385
12275
|
}
|
|
12386
12276
|
}
|
|
12387
|
-
if (current.type !==
|
|
12277
|
+
if (current.type !== import_utils70.AST_NODE_TYPES.MemberExpression) return;
|
|
12388
12278
|
const target = referencedMethod(context, current, methodClassVariables);
|
|
12389
12279
|
if (target === null) {
|
|
12390
12280
|
const possibleTarget = referencedPropertyName(current);
|
|
@@ -12392,12 +12282,12 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
12392
12282
|
return;
|
|
12393
12283
|
}
|
|
12394
12284
|
if (!privateNames.has(target)) return;
|
|
12395
|
-
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;
|
|
12396
12286
|
if (objectVariable !== null && methodAliases.has(objectVariable)) {
|
|
12397
12287
|
pinned.add(target);
|
|
12398
12288
|
return;
|
|
12399
12289
|
}
|
|
12400
|
-
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) {
|
|
12401
12291
|
pinned.add(target);
|
|
12402
12292
|
return;
|
|
12403
12293
|
}
|
|
@@ -12417,9 +12307,9 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
12417
12307
|
}
|
|
12418
12308
|
}
|
|
12419
12309
|
for (const member of node.body.body) {
|
|
12420
|
-
if (member.type ===
|
|
12310
|
+
if (member.type === import_utils70.AST_NODE_TYPES.MethodDefinition || member.type === import_utils70.AST_NODE_TYPES.TSAbstractMethodDefinition) continue;
|
|
12421
12311
|
walk(member, context.sourceCode.visitorKeys, (current) => {
|
|
12422
|
-
if (current.type !==
|
|
12312
|
+
if (current.type !== import_utils70.AST_NODE_TYPES.MemberExpression) return;
|
|
12423
12313
|
const target = referencedMethod(context, current, classVariables);
|
|
12424
12314
|
const possibleTarget = target ?? referencedPropertyName(current);
|
|
12425
12315
|
if (possibleTarget !== null && privateNames.has(possibleTarget)) pinned.add(possibleTarget);
|
|
@@ -12429,7 +12319,7 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
12429
12319
|
const accessibility = new Map(
|
|
12430
12320
|
scopeDefinitions.map((definition) => {
|
|
12431
12321
|
const method = definition.node;
|
|
12432
|
-
const accessibility2 = method.key.type ===
|
|
12322
|
+
const accessibility2 = method.key.type === import_utils70.AST_NODE_TYPES.PrivateIdentifier ? "private" : method.accessibility ?? "public";
|
|
12433
12323
|
return [definition.name, accessibility2];
|
|
12434
12324
|
})
|
|
12435
12325
|
);
|
|
@@ -12464,7 +12354,7 @@ var stepdown_default = createRule({
|
|
|
12464
12354
|
moduleScope(context, program);
|
|
12465
12355
|
const computedReferenceNames = /* @__PURE__ */ new Set();
|
|
12466
12356
|
walk(program, context.sourceCode.visitorKeys, (node) => {
|
|
12467
|
-
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);
|
|
12468
12358
|
});
|
|
12469
12359
|
for (const node of classes) classScope(context, node, computedReferenceNames);
|
|
12470
12360
|
}
|
|
@@ -12473,7 +12363,7 @@ var stepdown_default = createRule({
|
|
|
12473
12363
|
});
|
|
12474
12364
|
|
|
12475
12365
|
// src/rules/zod-naming-convention.ts
|
|
12476
|
-
var
|
|
12366
|
+
var import_utils71 = require("@typescript-eslint/utils");
|
|
12477
12367
|
var CONVENTIONS = {
|
|
12478
12368
|
prefix: { test: ZOD_PREFIX_RE, messageId: "zPrefix" },
|
|
12479
12369
|
suffix: { test: ZOD_SUFFIX_RE, messageId: "schemaSuffix" },
|
|
@@ -12498,21 +12388,23 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
12498
12388
|
"registry",
|
|
12499
12389
|
"implement"
|
|
12500
12390
|
]);
|
|
12501
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
12502
|
-
var
|
|
12391
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === import_utils71.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
12392
|
+
var calleeChainRoot = (node) => {
|
|
12503
12393
|
let current = node;
|
|
12504
|
-
|
|
12505
|
-
|
|
12506
|
-
|
|
12507
|
-
return true;
|
|
12394
|
+
for (; ; ) {
|
|
12395
|
+
if (current.type === import_utils71.AST_NODE_TYPES.Identifier) {
|
|
12396
|
+
return current;
|
|
12508
12397
|
}
|
|
12509
|
-
if (
|
|
12510
|
-
current =
|
|
12398
|
+
if (current.type === import_utils71.AST_NODE_TYPES.MemberExpression) {
|
|
12399
|
+
current = current.object;
|
|
12511
12400
|
continue;
|
|
12512
12401
|
}
|
|
12513
|
-
|
|
12402
|
+
if (current.type === import_utils71.AST_NODE_TYPES.CallExpression) {
|
|
12403
|
+
current = current.callee;
|
|
12404
|
+
continue;
|
|
12405
|
+
}
|
|
12406
|
+
return null;
|
|
12514
12407
|
}
|
|
12515
|
-
return false;
|
|
12516
12408
|
};
|
|
12517
12409
|
var zod_naming_convention_default = createRule({
|
|
12518
12410
|
name: "zod-naming-convention",
|
|
@@ -12544,20 +12436,45 @@ var zod_naming_convention_default = createRule({
|
|
|
12544
12436
|
const convention = optionsArg?.convention ?? "either";
|
|
12545
12437
|
const { test, messageId } = CONVENTIONS[convention];
|
|
12546
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
|
+
}
|
|
12547
12456
|
if (isTestFile(context.filename) || BENCHMARK_PATH_RE.test(context.filename.replaceAll("\\", "/")) || isGeneratedFile(context.filename, context.sourceCode.text)) {
|
|
12548
12457
|
return {};
|
|
12549
12458
|
}
|
|
12550
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
|
+
},
|
|
12551
12468
|
VariableDeclarator(node) {
|
|
12552
12469
|
const init = node.init;
|
|
12553
12470
|
if (init === null || init === void 0) return;
|
|
12554
|
-
if (init.type !==
|
|
12471
|
+
if (init.type !== import_utils71.AST_NODE_TYPES.CallExpression) return;
|
|
12555
12472
|
const callee = init.callee;
|
|
12556
|
-
if (callee.type !==
|
|
12557
|
-
if (!
|
|
12473
|
+
if (callee.type !== import_utils71.AST_NODE_TYPES.MemberExpression) return;
|
|
12474
|
+
if (!isZodChain(callee)) return;
|
|
12558
12475
|
const terminal = terminalMethodName(callee);
|
|
12559
12476
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
12560
|
-
if (node.id.type !==
|
|
12477
|
+
if (node.id.type !== import_utils71.AST_NODE_TYPES.Identifier) return;
|
|
12561
12478
|
if (test.test(node.id.name)) return;
|
|
12562
12479
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
12563
12480
|
context.report({
|
|
@@ -12611,6 +12528,14 @@ var retiredRules = {
|
|
|
12611
12528
|
removedIn: "10.0.0",
|
|
12612
12529
|
reason: "Delete the config entry and suppressions; use the narrower no-comment-cruft, no-restated-comment, and no-long-comment rules."
|
|
12613
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
|
+
},
|
|
12614
12539
|
"primary-export-file-name": {
|
|
12615
12540
|
removedIn: "4.0.0",
|
|
12616
12541
|
reason: "Delete the config entry and suppressions; there is no replacement."
|
|
@@ -12645,6 +12570,7 @@ var rules = {
|
|
|
12645
12570
|
"no-hand-rolled-spinner": no_hand_rolled_spinner_default,
|
|
12646
12571
|
"no-insecure-random-id": no_insecure_random_id_default,
|
|
12647
12572
|
"no-json-stringify-error": no_json_stringify_error_default,
|
|
12573
|
+
"no-impossible-zod-literal-bounds": no_impossible_zod_literal_bounds_default,
|
|
12648
12574
|
"no-log-only-catch": no_log_only_catch_default,
|
|
12649
12575
|
"no-long-comment": no_long_comment_default,
|
|
12650
12576
|
"no-generic-single-export-module": no_generic_single_export_module_default,
|
|
@@ -12685,9 +12611,7 @@ var rules = {
|
|
|
12685
12611
|
"prefer-schema-for-api-payload": prefer_schema_for_api_payload_default,
|
|
12686
12612
|
"prefer-semantic-colors": prefer_semantic_colors_default,
|
|
12687
12613
|
"prefer-server-actions": prefer_server_actions_default,
|
|
12688
|
-
"prefer-string-literal-union": prefer_string_literal_union_default,
|
|
12689
12614
|
"prefer-whole-object-assertion": prefer_whole_object_assertion_default,
|
|
12690
|
-
"prefer-zod-enum": prefer_zod_enum_default,
|
|
12691
12615
|
"prefer-zod-infer": prefer_zod_infer_default,
|
|
12692
12616
|
"require-assert-never": require_assert_never_default,
|
|
12693
12617
|
"require-fetch-timeout": require_fetch_timeout_default,
|
|
@@ -12700,7 +12624,7 @@ var rules = {
|
|
|
12700
12624
|
};
|
|
12701
12625
|
var meta = {
|
|
12702
12626
|
name: "@sarj/eslint-plugin",
|
|
12703
|
-
version: "
|
|
12627
|
+
version: "12.0.0"
|
|
12704
12628
|
};
|
|
12705
12629
|
var applicationOnlyRules = [
|
|
12706
12630
|
"no-restricted-library-load",
|
|
@@ -12721,6 +12645,7 @@ var recommendedRules = {
|
|
|
12721
12645
|
"@sarj/no-hand-rolled-spinner": "error",
|
|
12722
12646
|
"@sarj/no-insecure-random-id": "error",
|
|
12723
12647
|
"@sarj/no-json-stringify-error": "error",
|
|
12648
|
+
"@sarj/no-impossible-zod-literal-bounds": "error",
|
|
12724
12649
|
"@sarj/no-log-only-catch": "error",
|
|
12725
12650
|
"@sarj/no-long-comment": "error",
|
|
12726
12651
|
"@sarj/no-generic-single-export-module": "error",
|
|
@@ -12755,9 +12680,7 @@ var recommendedRules = {
|
|
|
12755
12680
|
"@sarj/prefer-schema-for-api-payload": "error",
|
|
12756
12681
|
"@sarj/prefer-semantic-colors": ["error", { requireSemanticTokens: true }],
|
|
12757
12682
|
"@sarj/prefer-server-actions": "error",
|
|
12758
|
-
"@sarj/prefer-string-literal-union": "error",
|
|
12759
12683
|
"@sarj/prefer-whole-object-assertion": "error",
|
|
12760
|
-
"@sarj/prefer-zod-enum": "error",
|
|
12761
12684
|
"@sarj/prefer-zod-infer": "error",
|
|
12762
12685
|
"@sarj/require-assert-never": "error",
|
|
12763
12686
|
"@sarj/require-fetch-timeout": "error",
|
|
@@ -12783,6 +12706,7 @@ var strictRules = {
|
|
|
12783
12706
|
"@sarj/no-hand-rolled-spinner": "error",
|
|
12784
12707
|
"@sarj/no-insecure-random-id": "error",
|
|
12785
12708
|
"@sarj/no-json-stringify-error": "error",
|
|
12709
|
+
"@sarj/no-impossible-zod-literal-bounds": "error",
|
|
12786
12710
|
"@sarj/no-log-only-catch": "error",
|
|
12787
12711
|
"@sarj/no-long-comment": "error",
|
|
12788
12712
|
"@sarj/no-generic-single-export-module": "error",
|
|
@@ -12820,9 +12744,7 @@ var strictRules = {
|
|
|
12820
12744
|
"@sarj/prefer-schema-for-api-payload": "error",
|
|
12821
12745
|
"@sarj/prefer-semantic-colors": ["error", { requireSemanticTokens: true }],
|
|
12822
12746
|
"@sarj/prefer-server-actions": "error",
|
|
12823
|
-
"@sarj/prefer-string-literal-union": "error",
|
|
12824
12747
|
"@sarj/prefer-whole-object-assertion": "error",
|
|
12825
|
-
"@sarj/prefer-zod-enum": "error",
|
|
12826
12748
|
"@sarj/prefer-zod-infer": "error",
|
|
12827
12749
|
"@sarj/require-assert-never": "error",
|
|
12828
12750
|
"@sarj/require-fetch-timeout": "error",
|