@sarj/eslint-plugin 9.7.0 → 9.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -3
- package/dist/index.cjs +692 -504
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -2
- package/dist/index.d.ts +32 -2
- package/dist/index.js +683 -496
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3462,17 +3462,110 @@ var no_raw_fetch_outside_clients_default = createRule({
|
|
|
3462
3462
|
}
|
|
3463
3463
|
});
|
|
3464
3464
|
|
|
3465
|
+
// src/rules/no-restricted-library-load.ts
|
|
3466
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES15, ASTUtils as ASTUtils2 } from "@typescript-eslint/utils";
|
|
3467
|
+
function literalModule(node) {
|
|
3468
|
+
return node?.type === AST_NODE_TYPES15.Literal && typeof node.value === "string" ? node.value : null;
|
|
3469
|
+
}
|
|
3470
|
+
function matchesModule(source, module) {
|
|
3471
|
+
return source === module || source.startsWith(`${module}/`);
|
|
3472
|
+
}
|
|
3473
|
+
var no_restricted_library_load_default = createRule({
|
|
3474
|
+
name: "no-restricted-library-load",
|
|
3475
|
+
meta: {
|
|
3476
|
+
type: "problem",
|
|
3477
|
+
docs: {
|
|
3478
|
+
description: "Apply a configured library-replacement policy to literal dynamic imports, CommonJS loads, and TypeScript import-equals declarations."
|
|
3479
|
+
},
|
|
3480
|
+
schema: [
|
|
3481
|
+
{
|
|
3482
|
+
type: "object",
|
|
3483
|
+
additionalProperties: false,
|
|
3484
|
+
required: ["libraries"],
|
|
3485
|
+
properties: {
|
|
3486
|
+
libraries: {
|
|
3487
|
+
type: "array",
|
|
3488
|
+
items: {
|
|
3489
|
+
type: "object",
|
|
3490
|
+
additionalProperties: false,
|
|
3491
|
+
required: ["id", "module", "replacement"],
|
|
3492
|
+
properties: {
|
|
3493
|
+
id: { type: "string", minLength: 1 },
|
|
3494
|
+
module: { type: "string", minLength: 1 },
|
|
3495
|
+
replacement: { type: "string", minLength: 1 },
|
|
3496
|
+
note: { type: "string", minLength: 1 }
|
|
3497
|
+
}
|
|
3498
|
+
}
|
|
3499
|
+
}
|
|
3500
|
+
}
|
|
3501
|
+
}
|
|
3502
|
+
],
|
|
3503
|
+
messages: {
|
|
3504
|
+
restrictedLibraryLoad: "{{id}}: Replace runtime loading of {{module}} with {{replacement}}.{{note}}"
|
|
3505
|
+
}
|
|
3506
|
+
},
|
|
3507
|
+
defaultOptions: [{ libraries: [] }],
|
|
3508
|
+
create(context, [options]) {
|
|
3509
|
+
const restrictions = options.libraries;
|
|
3510
|
+
function report(node, source) {
|
|
3511
|
+
const restriction = restrictions.find(
|
|
3512
|
+
(entry) => matchesModule(source, entry.module)
|
|
3513
|
+
);
|
|
3514
|
+
if (restriction === void 0) return;
|
|
3515
|
+
context.report({
|
|
3516
|
+
node,
|
|
3517
|
+
messageId: "restrictedLibraryLoad",
|
|
3518
|
+
data: {
|
|
3519
|
+
id: restriction.id,
|
|
3520
|
+
module: restriction.module,
|
|
3521
|
+
replacement: restriction.replacement,
|
|
3522
|
+
note: restriction.note === void 0 ? "" : ` ${restriction.note}`
|
|
3523
|
+
}
|
|
3524
|
+
});
|
|
3525
|
+
}
|
|
3526
|
+
function isUnshadowedRequire(node) {
|
|
3527
|
+
const variable = ASTUtils2.findVariable(
|
|
3528
|
+
context.sourceCode.getScope(node),
|
|
3529
|
+
node.name
|
|
3530
|
+
);
|
|
3531
|
+
return variable === null || variable.defs.length === 0;
|
|
3532
|
+
}
|
|
3533
|
+
return {
|
|
3534
|
+
ImportExpression(node) {
|
|
3535
|
+
const source = literalModule(node.source);
|
|
3536
|
+
if (source !== null) report(node.source, source);
|
|
3537
|
+
},
|
|
3538
|
+
CallExpression(node) {
|
|
3539
|
+
let requireIdentifier = null;
|
|
3540
|
+
if (node.callee.type === AST_NODE_TYPES15.Identifier && node.callee.name === "require") {
|
|
3541
|
+
requireIdentifier = node.callee;
|
|
3542
|
+
} else if (node.callee.type === AST_NODE_TYPES15.MemberExpression && !node.callee.computed && node.callee.object.type === AST_NODE_TYPES15.Identifier && node.callee.object.name === "require" && node.callee.property.type === AST_NODE_TYPES15.Identifier && node.callee.property.name === "resolve") {
|
|
3543
|
+
requireIdentifier = node.callee.object;
|
|
3544
|
+
}
|
|
3545
|
+
if (requireIdentifier === null || !isUnshadowedRequire(requireIdentifier)) return;
|
|
3546
|
+
const source = literalModule(node.arguments[0]);
|
|
3547
|
+
if (source !== null) report(node.arguments[0], source);
|
|
3548
|
+
},
|
|
3549
|
+
TSImportEqualsDeclaration(node) {
|
|
3550
|
+
if (node.moduleReference.type !== AST_NODE_TYPES15.TSExternalModuleReference) return;
|
|
3551
|
+
const source = literalModule(node.moduleReference.expression);
|
|
3552
|
+
if (source !== null) report(node.moduleReference.expression, source);
|
|
3553
|
+
}
|
|
3554
|
+
};
|
|
3555
|
+
}
|
|
3556
|
+
});
|
|
3557
|
+
|
|
3465
3558
|
// src/rules/no-repeated-string-literal.ts
|
|
3466
|
-
import { AST_NODE_TYPES as
|
|
3559
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES16 } from "@typescript-eslint/utils";
|
|
3467
3560
|
var MIN_LENGTH = 40;
|
|
3468
3561
|
var MIN_DISTINCT_SCOPES = 2;
|
|
3469
3562
|
var PREVIEW_LENGTH = 40;
|
|
3470
3563
|
var SQL_KEYWORD_RE = /\b(SELECT|INSERT|UPDATE|DELETE|FROM|WHERE|JOIN|VALUES|ON CONFLICT|RETURNING|GROUP BY|ORDER BY)\b/;
|
|
3471
3564
|
var IDENTIFIER_RE = /^[a-z_][a-z0-9_.]*$/;
|
|
3472
3565
|
var FUNCTION_TYPES3 = /* @__PURE__ */ new Set([
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3566
|
+
AST_NODE_TYPES16.FunctionDeclaration,
|
|
3567
|
+
AST_NODE_TYPES16.FunctionExpression,
|
|
3568
|
+
AST_NODE_TYPES16.ArrowFunctionExpression
|
|
3476
3569
|
]);
|
|
3477
3570
|
function isStructured(value) {
|
|
3478
3571
|
return value.includes("\n") || SQL_KEYWORD_RE.test(value) || IDENTIFIER_RE.test(value);
|
|
@@ -3494,8 +3587,8 @@ function isScaffolding(node) {
|
|
|
3494
3587
|
if (parent === void 0) {
|
|
3495
3588
|
return true;
|
|
3496
3589
|
}
|
|
3497
|
-
const isRequireSource = parent.type ===
|
|
3498
|
-
return parent.type ===
|
|
3590
|
+
const isRequireSource = parent.type === AST_NODE_TYPES16.CallExpression && parent.callee.type === AST_NODE_TYPES16.Identifier && parent.callee.name === "require";
|
|
3591
|
+
return parent.type === AST_NODE_TYPES16.ImportDeclaration || parent.type === AST_NODE_TYPES16.ImportExpression || parent.type === AST_NODE_TYPES16.ExportNamedDeclaration || parent.type === AST_NODE_TYPES16.ExportAllDeclaration || parent.type === AST_NODE_TYPES16.TSImportType || parent.type === AST_NODE_TYPES16.JSXAttribute || parent.type === AST_NODE_TYPES16.TSLiteralType || isRequireSource;
|
|
3499
3592
|
}
|
|
3500
3593
|
var no_repeated_string_literal_default = createRule({
|
|
3501
3594
|
name: "no-repeated-string-literal",
|
|
@@ -3535,7 +3628,7 @@ var no_repeated_string_literal_default = createRule({
|
|
|
3535
3628
|
}
|
|
3536
3629
|
},
|
|
3537
3630
|
TemplateLiteral(node) {
|
|
3538
|
-
if (node.parent.type ===
|
|
3631
|
+
if (node.parent.type === AST_NODE_TYPES16.TaggedTemplateExpression) {
|
|
3539
3632
|
return;
|
|
3540
3633
|
}
|
|
3541
3634
|
const [only] = node.quasis;
|
|
@@ -3569,7 +3662,7 @@ var no_repeated_string_literal_default = createRule({
|
|
|
3569
3662
|
});
|
|
3570
3663
|
|
|
3571
3664
|
// src/rules/no-restated-comment.ts
|
|
3572
|
-
import { AST_NODE_TYPES as
|
|
3665
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES17 } from "@typescript-eslint/utils";
|
|
3573
3666
|
var MAX_WORDS = 8;
|
|
3574
3667
|
var MIN_CONTENT_TOKENS = 2;
|
|
3575
3668
|
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;
|
|
@@ -3622,7 +3715,7 @@ var no_restated_comment_default = createRule({
|
|
|
3622
3715
|
function labelsASiblingRun(comment) {
|
|
3623
3716
|
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
3624
3717
|
if (token === null) return false;
|
|
3625
|
-
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !==
|
|
3718
|
+
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !== AST_NODE_TYPES17.Program; node = node.parent) {
|
|
3626
3719
|
if (headsSiblingRun(node)) return true;
|
|
3627
3720
|
}
|
|
3628
3721
|
return false;
|
|
@@ -3682,7 +3775,7 @@ var no_restated_comment_default = createRule({
|
|
|
3682
3775
|
});
|
|
3683
3776
|
|
|
3684
3777
|
// src/rules/no-restated-jsdoc.ts
|
|
3685
|
-
import { AST_NODE_TYPES as
|
|
3778
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES18 } from "@typescript-eslint/utils";
|
|
3686
3779
|
var MODELLED_TAGS = /* @__PURE__ */ new Set([
|
|
3687
3780
|
"arg",
|
|
3688
3781
|
"argument",
|
|
@@ -3736,30 +3829,30 @@ function declarationNames(node) {
|
|
|
3736
3829
|
switch (node.type) {
|
|
3737
3830
|
// `export function f()` — the JSDoc sits above the `export`, so the token
|
|
3738
3831
|
// after it resolves to the wrapper, not to the thing being documented.
|
|
3739
|
-
case
|
|
3740
|
-
case
|
|
3832
|
+
case AST_NODE_TYPES18.ExportNamedDeclaration:
|
|
3833
|
+
case AST_NODE_TYPES18.ExportDefaultDeclaration:
|
|
3741
3834
|
return node.declaration == null ? null : declarationNames(node.declaration);
|
|
3742
|
-
case
|
|
3743
|
-
case
|
|
3835
|
+
case AST_NODE_TYPES18.FunctionDeclaration:
|
|
3836
|
+
case AST_NODE_TYPES18.TSDeclareFunction:
|
|
3744
3837
|
return node.id === null ? null : { name: node.id.name, params: paramNames(node.params) };
|
|
3745
|
-
case
|
|
3746
|
-
case
|
|
3747
|
-
case
|
|
3748
|
-
case
|
|
3838
|
+
case AST_NODE_TYPES18.ClassDeclaration:
|
|
3839
|
+
case AST_NODE_TYPES18.TSInterfaceDeclaration:
|
|
3840
|
+
case AST_NODE_TYPES18.TSTypeAliasDeclaration:
|
|
3841
|
+
case AST_NODE_TYPES18.TSEnumDeclaration:
|
|
3749
3842
|
return node.id === null ? null : { name: node.id.name, params: [] };
|
|
3750
|
-
case
|
|
3843
|
+
case AST_NODE_TYPES18.VariableDeclaration: {
|
|
3751
3844
|
const declarator = node.declarations[0];
|
|
3752
|
-
if (declarator === void 0 || declarator.id.type !==
|
|
3845
|
+
if (declarator === void 0 || declarator.id.type !== AST_NODE_TYPES18.Identifier) return null;
|
|
3753
3846
|
const init = declarator.init;
|
|
3754
|
-
const params = init != null && (init.type ===
|
|
3847
|
+
const params = init != null && (init.type === AST_NODE_TYPES18.ArrowFunctionExpression || init.type === AST_NODE_TYPES18.FunctionExpression) ? paramNames(init.params) : [];
|
|
3755
3848
|
return { name: declarator.id.name, params };
|
|
3756
3849
|
}
|
|
3757
|
-
case
|
|
3758
|
-
case
|
|
3759
|
-
case
|
|
3760
|
-
case
|
|
3761
|
-
if (node.key.type !==
|
|
3762
|
-
const params = node.type ===
|
|
3850
|
+
case AST_NODE_TYPES18.MethodDefinition:
|
|
3851
|
+
case AST_NODE_TYPES18.PropertyDefinition:
|
|
3852
|
+
case AST_NODE_TYPES18.TSMethodSignature:
|
|
3853
|
+
case AST_NODE_TYPES18.TSPropertySignature: {
|
|
3854
|
+
if (node.key.type !== AST_NODE_TYPES18.Identifier) return null;
|
|
3855
|
+
const params = node.type === AST_NODE_TYPES18.MethodDefinition ? paramNames(node.value.params) : node.type === AST_NODE_TYPES18.TSMethodSignature ? paramNames(node.params) : [];
|
|
3763
3856
|
return { name: node.key.name, params };
|
|
3764
3857
|
}
|
|
3765
3858
|
default:
|
|
@@ -3769,9 +3862,9 @@ function declarationNames(node) {
|
|
|
3769
3862
|
function paramNames(params) {
|
|
3770
3863
|
const names = [];
|
|
3771
3864
|
for (const param of params) {
|
|
3772
|
-
const target = param.type ===
|
|
3773
|
-
if (target.type ===
|
|
3774
|
-
else if (target.type ===
|
|
3865
|
+
const target = param.type === AST_NODE_TYPES18.AssignmentPattern ? param.left : param;
|
|
3866
|
+
if (target.type === AST_NODE_TYPES18.Identifier) names.push(target.name);
|
|
3867
|
+
else if (target.type === AST_NODE_TYPES18.TSParameterProperty) continue;
|
|
3775
3868
|
}
|
|
3776
3869
|
return names;
|
|
3777
3870
|
}
|
|
@@ -3813,7 +3906,7 @@ var no_restated_jsdoc_default = createRule({
|
|
|
3813
3906
|
if (token === null || token.loc.start.line !== comment.loc.end.line + 1) continue;
|
|
3814
3907
|
let node = sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
3815
3908
|
let declaration = null;
|
|
3816
|
-
while (node != null && node.type !==
|
|
3909
|
+
while (node != null && node.type !== AST_NODE_TYPES18.Program) {
|
|
3817
3910
|
declaration = declarationNames(node);
|
|
3818
3911
|
if (declaration !== null) break;
|
|
3819
3912
|
node = node.parent ?? null;
|
|
@@ -4272,12 +4365,12 @@ var no_select_star_default = createRule({
|
|
|
4272
4365
|
});
|
|
4273
4366
|
|
|
4274
4367
|
// src/rules/no-sentinel-return-on-catch.ts
|
|
4275
|
-
import { AST_NODE_TYPES as
|
|
4368
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES19 } from "@typescript-eslint/utils";
|
|
4276
4369
|
function sentinelKind(arg) {
|
|
4277
4370
|
if (arg === null) {
|
|
4278
4371
|
return null;
|
|
4279
4372
|
}
|
|
4280
|
-
if (arg.type ===
|
|
4373
|
+
if (arg.type === AST_NODE_TYPES19.Literal) {
|
|
4281
4374
|
if (arg.value === null) {
|
|
4282
4375
|
return "nullish";
|
|
4283
4376
|
}
|
|
@@ -4289,13 +4382,13 @@ function sentinelKind(arg) {
|
|
|
4289
4382
|
}
|
|
4290
4383
|
return null;
|
|
4291
4384
|
}
|
|
4292
|
-
if (arg.type ===
|
|
4385
|
+
if (arg.type === AST_NODE_TYPES19.Identifier && arg.name === "undefined") {
|
|
4293
4386
|
return "nullish";
|
|
4294
4387
|
}
|
|
4295
|
-
if (arg.type ===
|
|
4388
|
+
if (arg.type === AST_NODE_TYPES19.ArrayExpression) {
|
|
4296
4389
|
return "array";
|
|
4297
4390
|
}
|
|
4298
|
-
if (arg.type ===
|
|
4391
|
+
if (arg.type === AST_NODE_TYPES19.ObjectExpression) {
|
|
4299
4392
|
return "object";
|
|
4300
4393
|
}
|
|
4301
4394
|
return null;
|
|
@@ -4304,25 +4397,25 @@ function isSentinelArgument(arg) {
|
|
|
4304
4397
|
if (arg === null) {
|
|
4305
4398
|
return false;
|
|
4306
4399
|
}
|
|
4307
|
-
if (arg.type ===
|
|
4400
|
+
if (arg.type === AST_NODE_TYPES19.Literal && arg.value === null) {
|
|
4308
4401
|
return true;
|
|
4309
4402
|
}
|
|
4310
|
-
if (arg.type ===
|
|
4403
|
+
if (arg.type === AST_NODE_TYPES19.Literal && arg.value === false) {
|
|
4311
4404
|
return true;
|
|
4312
4405
|
}
|
|
4313
|
-
if (arg.type ===
|
|
4406
|
+
if (arg.type === AST_NODE_TYPES19.Identifier && arg.name === "undefined") {
|
|
4314
4407
|
return true;
|
|
4315
4408
|
}
|
|
4316
|
-
if (arg.type ===
|
|
4409
|
+
if (arg.type === AST_NODE_TYPES19.ArrayExpression && arg.elements.length === 0) {
|
|
4317
4410
|
return true;
|
|
4318
4411
|
}
|
|
4319
|
-
if (arg.type ===
|
|
4412
|
+
if (arg.type === AST_NODE_TYPES19.ObjectExpression && arg.properties.length === 0) {
|
|
4320
4413
|
return true;
|
|
4321
4414
|
}
|
|
4322
4415
|
return false;
|
|
4323
4416
|
}
|
|
4324
4417
|
function isFunctionNode(node) {
|
|
4325
|
-
return node.type ===
|
|
4418
|
+
return node.type === AST_NODE_TYPES19.FunctionDeclaration || node.type === AST_NODE_TYPES19.FunctionExpression || node.type === AST_NODE_TYPES19.ArrowFunctionExpression;
|
|
4326
4419
|
}
|
|
4327
4420
|
function isNode3(value) {
|
|
4328
4421
|
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
@@ -4362,24 +4455,24 @@ function walkWithinScope(node, visit) {
|
|
|
4362
4455
|
function containsThrow(node) {
|
|
4363
4456
|
return walkWithinScope(
|
|
4364
4457
|
node,
|
|
4365
|
-
(current) => current.type ===
|
|
4458
|
+
(current) => current.type === AST_NODE_TYPES19.ThrowStatement
|
|
4366
4459
|
);
|
|
4367
4460
|
}
|
|
4368
4461
|
function bindsName(param, name) {
|
|
4369
4462
|
switch (param.type) {
|
|
4370
|
-
case
|
|
4463
|
+
case AST_NODE_TYPES19.Identifier:
|
|
4371
4464
|
return param.name === name;
|
|
4372
|
-
case
|
|
4465
|
+
case AST_NODE_TYPES19.AssignmentPattern:
|
|
4373
4466
|
return bindsName(param.left, name);
|
|
4374
|
-
case
|
|
4467
|
+
case AST_NODE_TYPES19.RestElement:
|
|
4375
4468
|
return bindsName(param.argument, name);
|
|
4376
|
-
case
|
|
4469
|
+
case AST_NODE_TYPES19.ArrayPattern:
|
|
4377
4470
|
return param.elements.some(
|
|
4378
4471
|
(element) => element !== null && bindsName(element, name)
|
|
4379
4472
|
);
|
|
4380
|
-
case
|
|
4473
|
+
case AST_NODE_TYPES19.ObjectPattern:
|
|
4381
4474
|
return param.properties.some(
|
|
4382
|
-
(property) => property.type ===
|
|
4475
|
+
(property) => property.type === AST_NODE_TYPES19.RestElement ? bindsName(property.argument, name) : bindsName(property.value, name)
|
|
4383
4476
|
);
|
|
4384
4477
|
default:
|
|
4385
4478
|
return false;
|
|
@@ -4394,7 +4487,7 @@ function subtreeReadsName(node, name) {
|
|
|
4394
4487
|
if (found) {
|
|
4395
4488
|
return;
|
|
4396
4489
|
}
|
|
4397
|
-
if (current.type ===
|
|
4490
|
+
if (current.type === AST_NODE_TYPES19.Identifier && current.name === name) {
|
|
4398
4491
|
found = true;
|
|
4399
4492
|
return;
|
|
4400
4493
|
}
|
|
@@ -4405,10 +4498,10 @@ function subtreeReadsName(node, name) {
|
|
|
4405
4498
|
if (key === "parent") {
|
|
4406
4499
|
continue;
|
|
4407
4500
|
}
|
|
4408
|
-
if (key === "key" && current.type ===
|
|
4501
|
+
if (key === "key" && current.type === AST_NODE_TYPES19.Property && !current.computed) {
|
|
4409
4502
|
continue;
|
|
4410
4503
|
}
|
|
4411
|
-
if (key === "property" && current.type ===
|
|
4504
|
+
if (key === "property" && current.type === AST_NODE_TYPES19.MemberExpression && !current.computed) {
|
|
4412
4505
|
continue;
|
|
4413
4506
|
}
|
|
4414
4507
|
const value = current[key];
|
|
@@ -4441,10 +4534,10 @@ var SAFE_PARSE_CONSTRUCTORS = /* @__PURE__ */ new Set([
|
|
|
4441
4534
|
"URLPattern"
|
|
4442
4535
|
]);
|
|
4443
4536
|
function isParseShapedNode(node) {
|
|
4444
|
-
if (node.type ===
|
|
4537
|
+
if (node.type === AST_NODE_TYPES19.CallExpression && node.callee.type === AST_NODE_TYPES19.MemberExpression && !node.callee.computed && node.callee.property.type === AST_NODE_TYPES19.Identifier) {
|
|
4445
4538
|
return node.callee.property.name === "parse";
|
|
4446
4539
|
}
|
|
4447
|
-
if (node.type ===
|
|
4540
|
+
if (node.type === AST_NODE_TYPES19.NewExpression && node.callee.type === AST_NODE_TYPES19.Identifier) {
|
|
4448
4541
|
return SAFE_PARSE_CONSTRUCTORS.has(node.callee.name);
|
|
4449
4542
|
}
|
|
4450
4543
|
return false;
|
|
@@ -4455,10 +4548,10 @@ var BODY_DECODE_METHODS = /* @__PURE__ */ new Set([
|
|
|
4455
4548
|
"arrayBuffer"
|
|
4456
4549
|
]);
|
|
4457
4550
|
function isBodyDecodeNode(node) {
|
|
4458
|
-
return node.type ===
|
|
4551
|
+
return node.type === AST_NODE_TYPES19.CallExpression && node.callee.type === AST_NODE_TYPES19.MemberExpression && !node.callee.computed && node.callee.property.type === AST_NODE_TYPES19.Identifier && BODY_DECODE_METHODS.has(node.callee.property.name);
|
|
4459
4552
|
}
|
|
4460
4553
|
function returnsMatching(stmt, predicate) {
|
|
4461
|
-
return stmt.type ===
|
|
4554
|
+
return stmt.type === AST_NODE_TYPES19.ReturnStatement && stmt.argument !== null && walkWithinScope(stmt.argument, predicate);
|
|
4462
4555
|
}
|
|
4463
4556
|
function enclosingReturnTypeNode(node) {
|
|
4464
4557
|
let current = node.parent;
|
|
@@ -4476,11 +4569,11 @@ function enclosingFunctionName(node) {
|
|
|
4476
4569
|
let current = node.parent;
|
|
4477
4570
|
while (current !== void 0 && current !== null) {
|
|
4478
4571
|
if (isFunctionNode(current)) {
|
|
4479
|
-
if ("id" in current && isNode3(current.id) && current.id.type ===
|
|
4572
|
+
if ("id" in current && isNode3(current.id) && current.id.type === AST_NODE_TYPES19.Identifier) {
|
|
4480
4573
|
return current.id.name;
|
|
4481
4574
|
}
|
|
4482
4575
|
const parent = current.parent;
|
|
4483
|
-
if (parent?.type ===
|
|
4576
|
+
if (parent?.type === AST_NODE_TYPES19.VariableDeclarator && parent.id.type === AST_NODE_TYPES19.Identifier) {
|
|
4484
4577
|
return parent.id.name;
|
|
4485
4578
|
}
|
|
4486
4579
|
return null;
|
|
@@ -4501,10 +4594,10 @@ function isDeclaredBooleanPredicate(catchNode, kind) {
|
|
|
4501
4594
|
return false;
|
|
4502
4595
|
}
|
|
4503
4596
|
let declared = enclosingReturnTypeNode(catchNode);
|
|
4504
|
-
if (declared?.type ===
|
|
4597
|
+
if (declared?.type === AST_NODE_TYPES19.TSTypeReference && declared.typeName.type === AST_NODE_TYPES19.Identifier && declared.typeName.name === "Promise") {
|
|
4505
4598
|
declared = declared.typeArguments?.params[0] ?? null;
|
|
4506
4599
|
}
|
|
4507
|
-
return declared?.type ===
|
|
4600
|
+
return declared?.type === AST_NODE_TYPES19.TSBooleanKeyword;
|
|
4508
4601
|
}
|
|
4509
4602
|
function tryReturnsSafeParse(catchNode) {
|
|
4510
4603
|
const tryBlock = tryBlockOf(catchNode);
|
|
@@ -4520,7 +4613,7 @@ function tryReturnsSafeParse(catchNode) {
|
|
|
4520
4613
|
function enclosingFunctionBody(node) {
|
|
4521
4614
|
let current = node.parent;
|
|
4522
4615
|
while (current !== void 0 && current !== null) {
|
|
4523
|
-
if (isFunctionNode(current) && "body" in current && isNode3(current.body) && current.body.type ===
|
|
4616
|
+
if (isFunctionNode(current) && "body" in current && isNode3(current.body) && current.body.type === AST_NODE_TYPES19.BlockStatement) {
|
|
4524
4617
|
return current.body;
|
|
4525
4618
|
}
|
|
4526
4619
|
current = current.parent;
|
|
@@ -4533,7 +4626,7 @@ function functionReturnsSameSentinelKindElsewhere(catchNode, kind) {
|
|
|
4533
4626
|
return false;
|
|
4534
4627
|
}
|
|
4535
4628
|
return walkWithinScope(functionBody, (current) => {
|
|
4536
|
-
if (current.type !==
|
|
4629
|
+
if (current.type !== AST_NODE_TYPES19.ReturnStatement) {
|
|
4537
4630
|
return false;
|
|
4538
4631
|
}
|
|
4539
4632
|
if (isWithin(current, catchNode.body)) {
|
|
@@ -4552,13 +4645,13 @@ function returnedSentinelKinds(arg) {
|
|
|
4552
4645
|
kinds.add(direct);
|
|
4553
4646
|
return kinds;
|
|
4554
4647
|
}
|
|
4555
|
-
if (arg.type ===
|
|
4648
|
+
if (arg.type === AST_NODE_TYPES19.ConditionalExpression) {
|
|
4556
4649
|
for (const branch of [arg.consequent, arg.alternate]) {
|
|
4557
4650
|
for (const nested of returnedSentinelKinds(branch)) {
|
|
4558
4651
|
kinds.add(nested);
|
|
4559
4652
|
}
|
|
4560
4653
|
}
|
|
4561
|
-
} else if (arg.type ===
|
|
4654
|
+
} else if (arg.type === AST_NODE_TYPES19.LogicalExpression && (arg.operator === "??" || arg.operator === "||")) {
|
|
4562
4655
|
for (const nested of returnedSentinelKinds(arg.right)) {
|
|
4563
4656
|
kinds.add(nested);
|
|
4564
4657
|
}
|
|
@@ -4601,7 +4694,7 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
4601
4694
|
const matcher = createLogMatcher(loggingOptions);
|
|
4602
4695
|
function logsOrReportsError(catchBody, caughtName) {
|
|
4603
4696
|
return walkWithinScope(catchBody, (current) => {
|
|
4604
|
-
if (current.type !==
|
|
4697
|
+
if (current.type !== AST_NODE_TYPES19.CallExpression) {
|
|
4605
4698
|
return false;
|
|
4606
4699
|
}
|
|
4607
4700
|
if (matcher.isLoggingCall(current)) {
|
|
@@ -4618,7 +4711,7 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
4618
4711
|
return;
|
|
4619
4712
|
}
|
|
4620
4713
|
const last = body2[body2.length - 1];
|
|
4621
|
-
if (last === void 0 || last.type !==
|
|
4714
|
+
if (last === void 0 || last.type !== AST_NODE_TYPES19.ReturnStatement) {
|
|
4622
4715
|
return;
|
|
4623
4716
|
}
|
|
4624
4717
|
if (!isSentinelArgument(last.argument)) {
|
|
@@ -4627,7 +4720,7 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
4627
4720
|
if (containsThrow(node.body)) {
|
|
4628
4721
|
return;
|
|
4629
4722
|
}
|
|
4630
|
-
const caughtName = node.param?.type ===
|
|
4723
|
+
const caughtName = node.param?.type === AST_NODE_TYPES19.Identifier ? node.param.name : null;
|
|
4631
4724
|
if (logsOrReportsError(node.body, caughtName)) {
|
|
4632
4725
|
return;
|
|
4633
4726
|
}
|
|
@@ -4654,9 +4747,9 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
4654
4747
|
});
|
|
4655
4748
|
|
|
4656
4749
|
// src/rules/no-silent-promise-catch.ts
|
|
4657
|
-
import { AST_NODE_TYPES as
|
|
4750
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES20 } from "@typescript-eslint/utils";
|
|
4658
4751
|
function isBodyParseCall(node) {
|
|
4659
|
-
return node.type ===
|
|
4752
|
+
return node.type === AST_NODE_TYPES20.CallExpression && node.arguments.length === 0 && node.callee.type === AST_NODE_TYPES20.MemberExpression && !node.callee.computed && node.callee.property.type === AST_NODE_TYPES20.Identifier && (node.callee.property.name === "json" || node.callee.property.name === "text");
|
|
4660
4753
|
}
|
|
4661
4754
|
var TEARDOWN_METHODS = /* @__PURE__ */ new Set([
|
|
4662
4755
|
"cancel",
|
|
@@ -4671,21 +4764,21 @@ var TEARDOWN_METHODS = /* @__PURE__ */ new Set([
|
|
|
4671
4764
|
var DIRECTIVE_COMMENT_RE = /^\s*(eslint-|@ts-|prettier-ignore|biome-ignore|c8 |v8 |istanbul )/;
|
|
4672
4765
|
var isExplanatory = (comment) => !DIRECTIVE_COMMENT_RE.test(comment.value);
|
|
4673
4766
|
function isTeardownCall(node) {
|
|
4674
|
-
return node.type ===
|
|
4767
|
+
return node.type === AST_NODE_TYPES20.CallExpression && node.callee.type === AST_NODE_TYPES20.MemberExpression && !node.callee.computed && node.callee.property.type === AST_NODE_TYPES20.Identifier && TEARDOWN_METHODS.has(node.callee.property.name);
|
|
4675
4768
|
}
|
|
4676
4769
|
function isSilentExpression(node) {
|
|
4677
4770
|
switch (node.type) {
|
|
4678
|
-
case
|
|
4771
|
+
case AST_NODE_TYPES20.Literal:
|
|
4679
4772
|
return !("regex" in node);
|
|
4680
|
-
case
|
|
4773
|
+
case AST_NODE_TYPES20.Identifier:
|
|
4681
4774
|
return node.name === "undefined";
|
|
4682
|
-
case
|
|
4683
|
-
return node.operator === "void" && node.argument.type ===
|
|
4684
|
-
case
|
|
4775
|
+
case AST_NODE_TYPES20.UnaryExpression:
|
|
4776
|
+
return node.operator === "void" && node.argument.type === AST_NODE_TYPES20.Literal;
|
|
4777
|
+
case AST_NODE_TYPES20.ObjectExpression:
|
|
4685
4778
|
return node.properties.length === 0;
|
|
4686
|
-
case
|
|
4779
|
+
case AST_NODE_TYPES20.ArrayExpression:
|
|
4687
4780
|
return node.elements.length === 0;
|
|
4688
|
-
case
|
|
4781
|
+
case AST_NODE_TYPES20.TSAsExpression:
|
|
4689
4782
|
return isSilentExpression(node.expression);
|
|
4690
4783
|
default:
|
|
4691
4784
|
return false;
|
|
@@ -4693,7 +4786,7 @@ function isSilentExpression(node) {
|
|
|
4693
4786
|
}
|
|
4694
4787
|
function isSilentHandler(handler) {
|
|
4695
4788
|
const body2 = handler.body;
|
|
4696
|
-
if (body2.type !==
|
|
4789
|
+
if (body2.type !== AST_NODE_TYPES20.BlockStatement) {
|
|
4697
4790
|
return isSilentExpression(body2);
|
|
4698
4791
|
}
|
|
4699
4792
|
if (body2.body.length === 0) {
|
|
@@ -4701,7 +4794,7 @@ function isSilentHandler(handler) {
|
|
|
4701
4794
|
}
|
|
4702
4795
|
if (body2.body.length === 1) {
|
|
4703
4796
|
const only = body2.body[0];
|
|
4704
|
-
if (only !== void 0 && only.type ===
|
|
4797
|
+
if (only !== void 0 && only.type === AST_NODE_TYPES20.ReturnStatement) {
|
|
4705
4798
|
return only.argument === null || isSilentExpression(only.argument);
|
|
4706
4799
|
}
|
|
4707
4800
|
}
|
|
@@ -4730,7 +4823,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
4730
4823
|
return true;
|
|
4731
4824
|
}
|
|
4732
4825
|
let statement = call;
|
|
4733
|
-
while (statement.parent !== void 0 && statement.parent !== null && !statement.type.endsWith("Statement") && statement.type !==
|
|
4826
|
+
while (statement.parent !== void 0 && statement.parent !== null && !statement.type.endsWith("Statement") && statement.type !== AST_NODE_TYPES20.VariableDeclaration) {
|
|
4734
4827
|
statement = statement.parent;
|
|
4735
4828
|
}
|
|
4736
4829
|
if (sourceCode.getCommentsBefore(statement).some(isExplanatory)) {
|
|
@@ -4742,7 +4835,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
4742
4835
|
};
|
|
4743
4836
|
return {
|
|
4744
4837
|
CallExpression(node) {
|
|
4745
|
-
if (node.callee.type !==
|
|
4838
|
+
if (node.callee.type !== AST_NODE_TYPES20.MemberExpression || node.callee.computed || node.callee.property.type !== AST_NODE_TYPES20.Identifier || node.callee.property.name !== "catch") {
|
|
4746
4839
|
return;
|
|
4747
4840
|
}
|
|
4748
4841
|
if (isBodyParseCall(node.callee.object)) {
|
|
@@ -4751,14 +4844,14 @@ var no_silent_promise_catch_default = createRule({
|
|
|
4751
4844
|
if (isTeardownCall(node.callee.object)) {
|
|
4752
4845
|
return;
|
|
4753
4846
|
}
|
|
4754
|
-
if (node.parent.type ===
|
|
4847
|
+
if (node.parent.type === AST_NODE_TYPES20.MemberExpression && node.parent.object === node) {
|
|
4755
4848
|
return;
|
|
4756
4849
|
}
|
|
4757
4850
|
if (node.arguments.length !== 1) {
|
|
4758
4851
|
return;
|
|
4759
4852
|
}
|
|
4760
4853
|
const handler = node.arguments[0];
|
|
4761
|
-
if (handler === void 0 || handler.type !==
|
|
4854
|
+
if (handler === void 0 || handler.type !== AST_NODE_TYPES20.ArrowFunctionExpression && handler.type !== AST_NODE_TYPES20.FunctionExpression) {
|
|
4762
4855
|
return;
|
|
4763
4856
|
}
|
|
4764
4857
|
if (hasExplanatoryComment(node, handler)) {
|
|
@@ -4773,7 +4866,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
4773
4866
|
});
|
|
4774
4867
|
|
|
4775
4868
|
// src/rules/no-sleep-in-test-body.ts
|
|
4776
|
-
import { AST_NODE_TYPES as
|
|
4869
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES21 } from "@typescript-eslint/utils";
|
|
4777
4870
|
var SLEEP_HELPERS = /* @__PURE__ */ new Set(["sleep", "delay", "wait", "pause"]);
|
|
4778
4871
|
var TEST_CALLERS2 = /* @__PURE__ */ new Set([
|
|
4779
4872
|
"it",
|
|
@@ -4782,34 +4875,34 @@ var TEST_CALLERS2 = /* @__PURE__ */ new Set([
|
|
|
4782
4875
|
"afterEach"
|
|
4783
4876
|
]);
|
|
4784
4877
|
var FUNCTION_TYPES4 = /* @__PURE__ */ new Set([
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4878
|
+
AST_NODE_TYPES21.FunctionDeclaration,
|
|
4879
|
+
AST_NODE_TYPES21.FunctionExpression,
|
|
4880
|
+
AST_NODE_TYPES21.ArrowFunctionExpression
|
|
4788
4881
|
]);
|
|
4789
4882
|
function isNonzeroNumericLiteral(node) {
|
|
4790
|
-
return node?.type ===
|
|
4883
|
+
return node?.type === AST_NODE_TYPES21.Literal && typeof node.value === "number" && node.value !== 0;
|
|
4791
4884
|
}
|
|
4792
4885
|
function isTimedSetTimeout(node) {
|
|
4793
|
-
return node.type ===
|
|
4886
|
+
return node.type === AST_NODE_TYPES21.CallExpression && node.callee.type === AST_NODE_TYPES21.Identifier && node.callee.name === "setTimeout" && node.arguments.length >= 2 && isNonzeroNumericLiteral(node.arguments[1]);
|
|
4794
4887
|
}
|
|
4795
4888
|
function isPromiseSleep(node) {
|
|
4796
|
-
if (node.callee.type !==
|
|
4889
|
+
if (node.callee.type !== AST_NODE_TYPES21.Identifier || node.callee.name !== "Promise") {
|
|
4797
4890
|
return false;
|
|
4798
4891
|
}
|
|
4799
4892
|
const executor = node.arguments[0];
|
|
4800
|
-
if (executor?.type !==
|
|
4893
|
+
if (executor?.type !== AST_NODE_TYPES21.ArrowFunctionExpression && executor?.type !== AST_NODE_TYPES21.FunctionExpression) {
|
|
4801
4894
|
return false;
|
|
4802
4895
|
}
|
|
4803
4896
|
const body2 = executor.body;
|
|
4804
|
-
if (body2.type !==
|
|
4897
|
+
if (body2.type !== AST_NODE_TYPES21.BlockStatement) {
|
|
4805
4898
|
return isTimedSetTimeout(body2);
|
|
4806
4899
|
}
|
|
4807
4900
|
return body2.body.some(
|
|
4808
|
-
(stmt) => stmt.type ===
|
|
4901
|
+
(stmt) => stmt.type === AST_NODE_TYPES21.ExpressionStatement && isTimedSetTimeout(stmt.expression)
|
|
4809
4902
|
);
|
|
4810
4903
|
}
|
|
4811
4904
|
function isHelperSleep(node) {
|
|
4812
|
-
return node.callee.type ===
|
|
4905
|
+
return node.callee.type === AST_NODE_TYPES21.Identifier && SLEEP_HELPERS.has(node.callee.name) && node.arguments.length >= 1 && isNonzeroNumericLiteral(node.arguments[0]);
|
|
4813
4906
|
}
|
|
4814
4907
|
function nearestEnclosingFunction2(node) {
|
|
4815
4908
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
@@ -4817,7 +4910,7 @@ function nearestEnclosingFunction2(node) {
|
|
|
4817
4910
|
continue;
|
|
4818
4911
|
}
|
|
4819
4912
|
const grandparent = current.parent;
|
|
4820
|
-
const isPromiseExecutor = grandparent?.type ===
|
|
4913
|
+
const isPromiseExecutor = grandparent?.type === AST_NODE_TYPES21.NewExpression && isPromiseSleep(grandparent);
|
|
4821
4914
|
if (!isPromiseExecutor) {
|
|
4822
4915
|
return current;
|
|
4823
4916
|
}
|
|
@@ -4825,23 +4918,23 @@ function nearestEnclosingFunction2(node) {
|
|
|
4825
4918
|
return null;
|
|
4826
4919
|
}
|
|
4827
4920
|
function testCallerName2(callee) {
|
|
4828
|
-
if (callee.type ===
|
|
4921
|
+
if (callee.type === AST_NODE_TYPES21.Identifier) {
|
|
4829
4922
|
return callee.name;
|
|
4830
4923
|
}
|
|
4831
|
-
if (callee.type ===
|
|
4924
|
+
if (callee.type === AST_NODE_TYPES21.MemberExpression) {
|
|
4832
4925
|
return testCallerName2(callee.object);
|
|
4833
4926
|
}
|
|
4834
|
-
if (callee.type ===
|
|
4927
|
+
if (callee.type === AST_NODE_TYPES21.CallExpression) {
|
|
4835
4928
|
return testCallerName2(callee.callee);
|
|
4836
4929
|
}
|
|
4837
|
-
if (callee.type ===
|
|
4930
|
+
if (callee.type === AST_NODE_TYPES21.TaggedTemplateExpression) {
|
|
4838
4931
|
return testCallerName2(callee.tag);
|
|
4839
4932
|
}
|
|
4840
4933
|
return null;
|
|
4841
4934
|
}
|
|
4842
4935
|
function isTestBody2(fn) {
|
|
4843
4936
|
const call = fn.parent;
|
|
4844
|
-
if (call?.type !==
|
|
4937
|
+
if (call?.type !== AST_NODE_TYPES21.CallExpression || !call.arguments.some((argument) => argument === fn)) {
|
|
4845
4938
|
return false;
|
|
4846
4939
|
}
|
|
4847
4940
|
const name = testCallerName2(call.callee);
|
|
@@ -4887,7 +4980,7 @@ var no_sleep_in_test_body_default = createRule({
|
|
|
4887
4980
|
});
|
|
4888
4981
|
|
|
4889
4982
|
// src/rules/no-storage-in-stateless-modules.ts
|
|
4890
|
-
import { AST_NODE_TYPES as
|
|
4983
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES22 } from "@typescript-eslint/utils";
|
|
4891
4984
|
var DEFAULT_METHODS2 = [
|
|
4892
4985
|
"prepare",
|
|
4893
4986
|
"put",
|
|
@@ -4906,7 +4999,7 @@ function compile2(patterns) {
|
|
|
4906
4999
|
}
|
|
4907
5000
|
function storageMethodName(node, methods) {
|
|
4908
5001
|
const callee = node.callee;
|
|
4909
|
-
if (callee.type !==
|
|
5002
|
+
if (callee.type !== AST_NODE_TYPES22.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES22.Identifier) {
|
|
4910
5003
|
return null;
|
|
4911
5004
|
}
|
|
4912
5005
|
const name = callee.property.name;
|
|
@@ -5120,7 +5213,7 @@ var no_string_concat_in_loop_default = createRule({
|
|
|
5120
5213
|
});
|
|
5121
5214
|
|
|
5122
5215
|
// src/rules/no-tautological-expect.ts
|
|
5123
|
-
import { AST_NODE_TYPES as
|
|
5216
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES23 } from "@typescript-eslint/utils";
|
|
5124
5217
|
var EQUALITY_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
5125
5218
|
var ZERO_ARG_MATCHERS = /* @__PURE__ */ new Set([
|
|
5126
5219
|
"toBeDefined",
|
|
@@ -5134,17 +5227,17 @@ var OPERAND_PREVIEW_CHARS = 40;
|
|
|
5134
5227
|
var NUMERIC_SIGNS = /* @__PURE__ */ new Set(["-", "+"]);
|
|
5135
5228
|
function isLiteral(node) {
|
|
5136
5229
|
switch (node.type) {
|
|
5137
|
-
case
|
|
5230
|
+
case AST_NODE_TYPES23.Literal:
|
|
5138
5231
|
return true;
|
|
5139
|
-
case
|
|
5232
|
+
case AST_NODE_TYPES23.TemplateLiteral:
|
|
5140
5233
|
return node.expressions.length === 0;
|
|
5141
|
-
case
|
|
5234
|
+
case AST_NODE_TYPES23.UnaryExpression:
|
|
5142
5235
|
return NUMERIC_SIGNS.has(node.operator) && isLiteral(node.argument);
|
|
5143
|
-
case
|
|
5236
|
+
case AST_NODE_TYPES23.ArrayExpression:
|
|
5144
5237
|
return node.elements.every((element) => element !== null && isLiteral(element));
|
|
5145
|
-
case
|
|
5238
|
+
case AST_NODE_TYPES23.ObjectExpression:
|
|
5146
5239
|
return node.properties.every(
|
|
5147
|
-
(property) => property.type ===
|
|
5240
|
+
(property) => property.type === AST_NODE_TYPES23.Property && !property.computed && isLiteral(property.value)
|
|
5148
5241
|
);
|
|
5149
5242
|
default:
|
|
5150
5243
|
return false;
|
|
@@ -5152,7 +5245,7 @@ function isLiteral(node) {
|
|
|
5152
5245
|
}
|
|
5153
5246
|
function expectOperand(callee) {
|
|
5154
5247
|
const receiver = callee.object;
|
|
5155
|
-
if (receiver.type !==
|
|
5248
|
+
if (receiver.type !== AST_NODE_TYPES23.CallExpression || receiver.callee.type !== AST_NODE_TYPES23.Identifier || receiver.callee.name !== "expect" || receiver.arguments.length !== 1) {
|
|
5156
5249
|
return null;
|
|
5157
5250
|
}
|
|
5158
5251
|
return receiver.arguments[0] ?? null;
|
|
@@ -5182,10 +5275,10 @@ var no_tautological_expect_default = createRule({
|
|
|
5182
5275
|
return {
|
|
5183
5276
|
CallExpression(node) {
|
|
5184
5277
|
const callee = node.callee;
|
|
5185
|
-
if (callee.type !==
|
|
5278
|
+
if (callee.type !== AST_NODE_TYPES23.MemberExpression || callee.computed) {
|
|
5186
5279
|
return;
|
|
5187
5280
|
}
|
|
5188
|
-
if (callee.property.type !==
|
|
5281
|
+
if (callee.property.type !== AST_NODE_TYPES23.Identifier) {
|
|
5189
5282
|
return;
|
|
5190
5283
|
}
|
|
5191
5284
|
const matcher = callee.property.name;
|
|
@@ -5379,10 +5472,10 @@ var no_trailing_value_narration_default = createRule({
|
|
|
5379
5472
|
});
|
|
5380
5473
|
|
|
5381
5474
|
// src/rules/no-declaration-comment-wall.ts
|
|
5382
|
-
import { AST_NODE_TYPES as
|
|
5475
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES25 } from "@typescript-eslint/utils";
|
|
5383
5476
|
|
|
5384
5477
|
// src/rules/_comment-wall.ts
|
|
5385
|
-
import { AST_NODE_TYPES as
|
|
5478
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES24 } from "@typescript-eslint/utils";
|
|
5386
5479
|
var WALL_DEFAULTS = {
|
|
5387
5480
|
// Below three rows "a wall" is not a fair description of what the reader sees.
|
|
5388
5481
|
minCommentedMembers: 3,
|
|
@@ -5486,10 +5579,10 @@ function isWall(members, commented, restated, options) {
|
|
|
5486
5579
|
return commented >= options.minCommentedMembers && commented / members >= options.minCommentedRatio && restated / commented >= options.minRestatedRatio;
|
|
5487
5580
|
}
|
|
5488
5581
|
var OPAQUE_VALUE_TYPES = /* @__PURE__ */ new Set([
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
|
|
5582
|
+
AST_NODE_TYPES24.FunctionExpression,
|
|
5583
|
+
AST_NODE_TYPES24.ArrowFunctionExpression,
|
|
5584
|
+
AST_NODE_TYPES24.ObjectExpression,
|
|
5585
|
+
AST_NODE_TYPES24.ArrayExpression
|
|
5493
5586
|
]);
|
|
5494
5587
|
function declarationRange(member) {
|
|
5495
5588
|
const body2 = bodyOf(member);
|
|
@@ -5497,10 +5590,10 @@ function declarationRange(member) {
|
|
|
5497
5590
|
return [member.range[0], body2.range[0]];
|
|
5498
5591
|
}
|
|
5499
5592
|
function bodyOf(member) {
|
|
5500
|
-
if (member.type ===
|
|
5593
|
+
if (member.type === AST_NODE_TYPES24.MethodDefinition || member.type === AST_NODE_TYPES24.TSAbstractMethodDefinition) {
|
|
5501
5594
|
return member.value.body ?? void 0;
|
|
5502
5595
|
}
|
|
5503
|
-
if (member.type ===
|
|
5596
|
+
if (member.type === AST_NODE_TYPES24.Property || member.type === AST_NODE_TYPES24.PropertyDefinition) {
|
|
5504
5597
|
const value = member.value;
|
|
5505
5598
|
if (value !== null && OPAQUE_VALUE_TYPES.has(value.type)) return value;
|
|
5506
5599
|
}
|
|
@@ -5510,12 +5603,12 @@ function bodyOf(member) {
|
|
|
5510
5603
|
// src/rules/no-declaration-comment-wall.ts
|
|
5511
5604
|
function named(node) {
|
|
5512
5605
|
switch (node.type) {
|
|
5513
|
-
case
|
|
5606
|
+
case AST_NODE_TYPES25.TSEnumMember:
|
|
5514
5607
|
return { node, key: node.id };
|
|
5515
|
-
case
|
|
5516
|
-
case
|
|
5517
|
-
case
|
|
5518
|
-
case
|
|
5608
|
+
case AST_NODE_TYPES25.PropertyDefinition:
|
|
5609
|
+
case AST_NODE_TYPES25.TSAbstractPropertyDefinition:
|
|
5610
|
+
case AST_NODE_TYPES25.MethodDefinition:
|
|
5611
|
+
case AST_NODE_TYPES25.TSAbstractMethodDefinition:
|
|
5519
5612
|
return node.computed ? void 0 : { node, key: node.key };
|
|
5520
5613
|
default:
|
|
5521
5614
|
return void 0;
|
|
@@ -5615,7 +5708,7 @@ var no_declaration_comment_wall_default = createRule({
|
|
|
5615
5708
|
});
|
|
5616
5709
|
|
|
5617
5710
|
// src/rules/no-union-in-comment.ts
|
|
5618
|
-
import { AST_NODE_TYPES as
|
|
5711
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES26 } from "@typescript-eslint/utils";
|
|
5619
5712
|
var MAX_LITERAL_LENGTH = 28;
|
|
5620
5713
|
var LITERAL = String.raw`(?:'[^'\n]*'|"[^"\n]*"|\`[^\`\n]*\`)`;
|
|
5621
5714
|
var LEAD_IN_RE2 = /^(?:one of|either|values?|allowed(?: values)?|options?|possible(?: values)?)\s*[:=-]?\s*/i;
|
|
@@ -5634,14 +5727,14 @@ var STRING_BUILDERS = /* @__PURE__ */ new Set([
|
|
|
5634
5727
|
function isBareString(node) {
|
|
5635
5728
|
if (node === void 0) return false;
|
|
5636
5729
|
switch (node.type) {
|
|
5637
|
-
case
|
|
5730
|
+
case AST_NODE_TYPES26.TSStringKeyword:
|
|
5638
5731
|
return true;
|
|
5639
5732
|
// `string[]` holds members of the same closed set, one element at a time.
|
|
5640
|
-
case
|
|
5733
|
+
case AST_NODE_TYPES26.TSArrayType:
|
|
5641
5734
|
return isBareString(node.elementType);
|
|
5642
5735
|
// `string | null` is still an unconstrained string, and so is `string | "a"`
|
|
5643
5736
|
// — the checker collapses that one to `string`.
|
|
5644
|
-
case
|
|
5737
|
+
case AST_NODE_TYPES26.TSUnionType:
|
|
5645
5738
|
return node.types.some((member) => isBareString(member));
|
|
5646
5739
|
default:
|
|
5647
5740
|
return false;
|
|
@@ -5651,13 +5744,13 @@ function rootCallee(node) {
|
|
|
5651
5744
|
let current = node;
|
|
5652
5745
|
for (let hops = 0; current != null && hops < 12; hops += 1) {
|
|
5653
5746
|
switch (current.type) {
|
|
5654
|
-
case
|
|
5747
|
+
case AST_NODE_TYPES26.CallExpression:
|
|
5655
5748
|
current = current.callee;
|
|
5656
5749
|
break;
|
|
5657
|
-
case
|
|
5750
|
+
case AST_NODE_TYPES26.MemberExpression:
|
|
5658
5751
|
current = current.object;
|
|
5659
5752
|
break;
|
|
5660
|
-
case
|
|
5753
|
+
case AST_NODE_TYPES26.Identifier:
|
|
5661
5754
|
return current.name;
|
|
5662
5755
|
default:
|
|
5663
5756
|
return null;
|
|
@@ -5666,26 +5759,26 @@ function rootCallee(node) {
|
|
|
5666
5759
|
return null;
|
|
5667
5760
|
}
|
|
5668
5761
|
function nameOf(key) {
|
|
5669
|
-
if (key.type ===
|
|
5670
|
-
if (key.type ===
|
|
5762
|
+
if (key.type === AST_NODE_TYPES26.Identifier) return key.name;
|
|
5763
|
+
if (key.type === AST_NODE_TYPES26.Literal && typeof key.value === "string") return key.value;
|
|
5671
5764
|
return null;
|
|
5672
5765
|
}
|
|
5673
5766
|
function targetOf(node) {
|
|
5674
5767
|
switch (node.type) {
|
|
5675
|
-
case
|
|
5676
|
-
case
|
|
5768
|
+
case AST_NODE_TYPES26.TSPropertySignature:
|
|
5769
|
+
case AST_NODE_TYPES26.PropertyDefinition: {
|
|
5677
5770
|
const name = node.computed ? null : nameOf(node.key);
|
|
5678
5771
|
if (name === null || !isBareString(node.typeAnnotation?.typeAnnotation)) return null;
|
|
5679
5772
|
return { node, name };
|
|
5680
5773
|
}
|
|
5681
|
-
case
|
|
5774
|
+
case AST_NODE_TYPES26.Property: {
|
|
5682
5775
|
const name = node.computed || node.shorthand ? null : nameOf(node.key);
|
|
5683
5776
|
const callee = rootCallee(node.value);
|
|
5684
5777
|
if (name === null || callee === null || !STRING_BUILDERS.has(callee)) return null;
|
|
5685
5778
|
return { node, name };
|
|
5686
5779
|
}
|
|
5687
|
-
case
|
|
5688
|
-
if (node.id.type !==
|
|
5780
|
+
case AST_NODE_TYPES26.VariableDeclarator: {
|
|
5781
|
+
if (node.id.type !== AST_NODE_TYPES26.Identifier) return null;
|
|
5689
5782
|
if (!isBareString(node.id.typeAnnotation?.typeAnnotation)) return null;
|
|
5690
5783
|
return { node, name: node.id.name };
|
|
5691
5784
|
}
|
|
@@ -5734,7 +5827,7 @@ var no_union_in_comment_default = createRule({
|
|
|
5734
5827
|
if (after === null || after.loc.start.line !== comment.loc.end.line + 1) return null;
|
|
5735
5828
|
anchor = sourceCode.getNodeByRangeIndex(after.range[0]);
|
|
5736
5829
|
}
|
|
5737
|
-
for (let node = anchor; node != null && node.type !==
|
|
5830
|
+
for (let node = anchor; node != null && node.type !== AST_NODE_TYPES26.Program; node = node.parent) {
|
|
5738
5831
|
const target = targetOf(node);
|
|
5739
5832
|
if (target !== null) return target;
|
|
5740
5833
|
}
|
|
@@ -5763,9 +5856,9 @@ var no_union_in_comment_default = createRule({
|
|
|
5763
5856
|
});
|
|
5764
5857
|
|
|
5765
5858
|
// src/rules/no-type-member-comment-wall.ts
|
|
5766
|
-
import { AST_NODE_TYPES as
|
|
5859
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES27 } from "@typescript-eslint/utils";
|
|
5767
5860
|
function isNamedMember(node) {
|
|
5768
|
-
return (node.type ===
|
|
5861
|
+
return (node.type === AST_NODE_TYPES27.TSPropertySignature || node.type === AST_NODE_TYPES27.TSMethodSignature) && !node.computed;
|
|
5769
5862
|
}
|
|
5770
5863
|
var no_type_member_comment_wall_default = createRule({
|
|
5771
5864
|
name: "no-type-member-comment-wall",
|
|
@@ -5812,7 +5905,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5812
5905
|
return headsRun || lineAbove !== void 0 && lineAbove.trim().length === 0;
|
|
5813
5906
|
}
|
|
5814
5907
|
function check(node) {
|
|
5815
|
-
const members = node.type ===
|
|
5908
|
+
const members = node.type === AST_NODE_TYPES27.TSInterfaceBody ? node.body : node.members;
|
|
5816
5909
|
const named2 = members.filter(isNamedMember);
|
|
5817
5910
|
if (named2.length === 0) return;
|
|
5818
5911
|
const documented = named2.map((member) => ({ member, comment: documentingComment(member) }));
|
|
@@ -5852,7 +5945,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5852
5945
|
});
|
|
5853
5946
|
|
|
5854
5947
|
// src/rules/no-unnecessary-use-client.ts
|
|
5855
|
-
import { AST_NODE_TYPES as
|
|
5948
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES28 } from "@typescript-eslint/utils";
|
|
5856
5949
|
var HOOK_REGEX = /^use([A-Z]|$)/;
|
|
5857
5950
|
var EVENT_PROP_REGEX = /^on[A-Z]/;
|
|
5858
5951
|
var ERROR_FILE_REGEX = /\b(?:global-)?error\.[jt]sx?$/;
|
|
@@ -5878,13 +5971,13 @@ var CLIENT_ONLY_PACKAGES_REGEX = /^(?:@radix-ui\/|framer-motion|react-dom|react-
|
|
|
5878
5971
|
var isBareSpecifier = (source) => !source.startsWith(".") && !source.startsWith("/") && !source.startsWith("@/") && !source.startsWith("~");
|
|
5879
5972
|
var jsxRootName = (name) => {
|
|
5880
5973
|
let current = name;
|
|
5881
|
-
while (current.type ===
|
|
5974
|
+
while (current.type === AST_NODE_TYPES28.JSXMemberExpression) {
|
|
5882
5975
|
current = current.object;
|
|
5883
5976
|
}
|
|
5884
|
-
return current.type ===
|
|
5977
|
+
return current.type === AST_NODE_TYPES28.JSXIdentifier ? current.name : "";
|
|
5885
5978
|
};
|
|
5886
5979
|
var subtreeReadsImportedBinding = (node, imported) => {
|
|
5887
|
-
if (node.type ===
|
|
5980
|
+
if (node.type === AST_NODE_TYPES28.Identifier) {
|
|
5888
5981
|
return imported.has(node.name);
|
|
5889
5982
|
}
|
|
5890
5983
|
for (const key of Object.keys(node)) {
|
|
@@ -5899,16 +5992,16 @@ var subtreeReadsImportedBinding = (node, imported) => {
|
|
|
5899
5992
|
return false;
|
|
5900
5993
|
};
|
|
5901
5994
|
var isUseClientDirective = (node) => {
|
|
5902
|
-
return node.type ===
|
|
5995
|
+
return node.type === AST_NODE_TYPES28.ExpressionStatement && node.expression.type === AST_NODE_TYPES28.Literal && node.expression.value === "use client";
|
|
5903
5996
|
};
|
|
5904
5997
|
var isGlobalReference = (node, context) => {
|
|
5905
5998
|
if (!BROWSER_GLOBALS.has(node.name)) return false;
|
|
5906
5999
|
const parent = node.parent;
|
|
5907
6000
|
if (parent !== void 0) {
|
|
5908
|
-
if (parent.type ===
|
|
6001
|
+
if (parent.type === AST_NODE_TYPES28.MemberExpression && parent.property === node && !parent.computed) {
|
|
5909
6002
|
return false;
|
|
5910
6003
|
}
|
|
5911
|
-
if (parent.type ===
|
|
6004
|
+
if (parent.type === AST_NODE_TYPES28.Property && parent.key === node && !parent.computed) {
|
|
5912
6005
|
return false;
|
|
5913
6006
|
}
|
|
5914
6007
|
if (parent.type.startsWith("TS")) {
|
|
@@ -5948,13 +6041,13 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5948
6041
|
const importedLocals = /* @__PURE__ */ new Set();
|
|
5949
6042
|
const externalLocals = /* @__PURE__ */ new Set();
|
|
5950
6043
|
const markIfHookOrContext = (callee) => {
|
|
5951
|
-
if (callee.type ===
|
|
6044
|
+
if (callee.type === AST_NODE_TYPES28.Identifier) {
|
|
5952
6045
|
if (HOOK_REGEX.test(callee.name) || callee.name === "createContext") {
|
|
5953
6046
|
hasClientIndicator = true;
|
|
5954
6047
|
}
|
|
5955
6048
|
return;
|
|
5956
6049
|
}
|
|
5957
|
-
if (callee.type ===
|
|
6050
|
+
if (callee.type === AST_NODE_TYPES28.MemberExpression && callee.property.type === AST_NODE_TYPES28.Identifier) {
|
|
5958
6051
|
const name = callee.property.name;
|
|
5959
6052
|
if (HOOK_REGEX.test(name) || name === "createContext") {
|
|
5960
6053
|
hasClientIndicator = true;
|
|
@@ -5964,7 +6057,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5964
6057
|
return {
|
|
5965
6058
|
Program(node) {
|
|
5966
6059
|
for (const stmt of node.body) {
|
|
5967
|
-
if (stmt.type !==
|
|
6060
|
+
if (stmt.type !== AST_NODE_TYPES28.ExpressionStatement) break;
|
|
5968
6061
|
if (isUseClientDirective(stmt)) {
|
|
5969
6062
|
directiveNode = stmt;
|
|
5970
6063
|
break;
|
|
@@ -5977,7 +6070,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5977
6070
|
},
|
|
5978
6071
|
JSXAttribute(node) {
|
|
5979
6072
|
if (directiveNode === null) return;
|
|
5980
|
-
if (node.name.type ===
|
|
6073
|
+
if (node.name.type === AST_NODE_TYPES28.JSXIdentifier && EVENT_PROP_REGEX.test(node.name.name)) {
|
|
5981
6074
|
hasClientIndicator = true;
|
|
5982
6075
|
}
|
|
5983
6076
|
},
|
|
@@ -6045,17 +6138,17 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
6045
6138
|
|
|
6046
6139
|
// src/rules/no-unsafe-mock-casting.ts
|
|
6047
6140
|
import "@typescript-eslint/utils";
|
|
6048
|
-
import { AST_NODE_TYPES as
|
|
6141
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES29 } from "@typescript-eslint/utils";
|
|
6049
6142
|
function isMockTypeReference(node) {
|
|
6050
|
-
if (node.type !==
|
|
6143
|
+
if (node.type !== AST_NODE_TYPES29.TSTypeReference) {
|
|
6051
6144
|
return false;
|
|
6052
6145
|
}
|
|
6053
6146
|
const typeName = node.typeName;
|
|
6054
|
-
if (typeName.type ===
|
|
6147
|
+
if (typeName.type === AST_NODE_TYPES29.Identifier) {
|
|
6055
6148
|
const name = typeName.name;
|
|
6056
6149
|
return name === "Mock" || name === "MockInstance" || name === "SpyInstance";
|
|
6057
6150
|
}
|
|
6058
|
-
if (typeName.type ===
|
|
6151
|
+
if (typeName.type === AST_NODE_TYPES29.TSQualifiedName) {
|
|
6059
6152
|
const rightName = typeName.right.name;
|
|
6060
6153
|
return rightName === "Mock" || rightName === "MockInstance" || rightName === "SpyInstance";
|
|
6061
6154
|
}
|
|
@@ -6093,7 +6186,7 @@ var no_unsafe_mock_casting_default = createRule({
|
|
|
6093
6186
|
// src/rules/no-zod-native-enum.ts
|
|
6094
6187
|
import {
|
|
6095
6188
|
ESLintUtils as ESLintUtils2,
|
|
6096
|
-
AST_NODE_TYPES as
|
|
6189
|
+
AST_NODE_TYPES as AST_NODE_TYPES30
|
|
6097
6190
|
} from "@typescript-eslint/utils";
|
|
6098
6191
|
import * as ts from "typescript";
|
|
6099
6192
|
var IGNORE_PATTERNS = [
|
|
@@ -6112,7 +6205,7 @@ function isZodModule(source) {
|
|
|
6112
6205
|
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
6113
6206
|
}
|
|
6114
6207
|
function unwrap2(node) {
|
|
6115
|
-
if (node.type ===
|
|
6208
|
+
if (node.type === AST_NODE_TYPES30.TSAsExpression || node.type === AST_NODE_TYPES30.TSSatisfiesExpression) {
|
|
6116
6209
|
return unwrap2(node.expression);
|
|
6117
6210
|
}
|
|
6118
6211
|
return node;
|
|
@@ -6120,14 +6213,14 @@ function unwrap2(node) {
|
|
|
6120
6213
|
function stringValueTexts(node, sourceCode) {
|
|
6121
6214
|
const texts = [];
|
|
6122
6215
|
for (const prop of node.properties) {
|
|
6123
|
-
if (prop.type !==
|
|
6216
|
+
if (prop.type !== AST_NODE_TYPES30.Property) {
|
|
6124
6217
|
return null;
|
|
6125
6218
|
}
|
|
6126
6219
|
if (prop.computed || prop.shorthand || prop.method || prop.kind !== "init") {
|
|
6127
6220
|
return null;
|
|
6128
6221
|
}
|
|
6129
6222
|
const value = prop.value;
|
|
6130
|
-
if (value.type !==
|
|
6223
|
+
if (value.type !== AST_NODE_TYPES30.Literal || typeof value.value !== "string") {
|
|
6131
6224
|
return null;
|
|
6132
6225
|
}
|
|
6133
6226
|
const text = sourceCode.getText(value);
|
|
@@ -6143,7 +6236,7 @@ function resolvesToLocalEnum(node, scope) {
|
|
|
6143
6236
|
const variable = current.variables.find((v) => v.name === node.name);
|
|
6144
6237
|
if (variable !== void 0) {
|
|
6145
6238
|
return variable.defs.some(
|
|
6146
|
-
(def) => def.node.type ===
|
|
6239
|
+
(def) => def.node.type === AST_NODE_TYPES30.TSEnumDeclaration
|
|
6147
6240
|
);
|
|
6148
6241
|
}
|
|
6149
6242
|
current = current.upper;
|
|
@@ -6195,25 +6288,25 @@ var no_zod_native_enum_default = createRule({
|
|
|
6195
6288
|
const zodImportedNames = /* @__PURE__ */ new Map();
|
|
6196
6289
|
function isZodMemberCall(node, api) {
|
|
6197
6290
|
const callee = node.callee;
|
|
6198
|
-
if (callee.type ===
|
|
6291
|
+
if (callee.type === AST_NODE_TYPES30.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES30.Identifier) {
|
|
6199
6292
|
return callee.property.name === api;
|
|
6200
6293
|
}
|
|
6201
|
-
if (callee.type ===
|
|
6294
|
+
if (callee.type === AST_NODE_TYPES30.Identifier) {
|
|
6202
6295
|
return zodImportedNames.get(callee.name) === api;
|
|
6203
6296
|
}
|
|
6204
6297
|
return false;
|
|
6205
6298
|
}
|
|
6206
6299
|
function buildFix(node) {
|
|
6207
6300
|
const callee = node.callee;
|
|
6208
|
-
if (callee.type !==
|
|
6301
|
+
if (callee.type !== AST_NODE_TYPES30.MemberExpression || callee.property.type !== AST_NODE_TYPES30.Identifier) {
|
|
6209
6302
|
return null;
|
|
6210
6303
|
}
|
|
6211
6304
|
const arg = node.arguments[0];
|
|
6212
|
-
if (arg === void 0 || node.arguments.length !== 1 || arg.type ===
|
|
6305
|
+
if (arg === void 0 || node.arguments.length !== 1 || arg.type === AST_NODE_TYPES30.SpreadElement) {
|
|
6213
6306
|
return null;
|
|
6214
6307
|
}
|
|
6215
6308
|
const inner = unwrap2(arg);
|
|
6216
|
-
if (inner.type !==
|
|
6309
|
+
if (inner.type !== AST_NODE_TYPES30.ObjectExpression) {
|
|
6217
6310
|
return null;
|
|
6218
6311
|
}
|
|
6219
6312
|
const values = stringValueTexts(inner, sourceCode);
|
|
@@ -6233,7 +6326,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
6233
6326
|
return;
|
|
6234
6327
|
}
|
|
6235
6328
|
for (const spec of node.specifiers) {
|
|
6236
|
-
if (spec.type ===
|
|
6329
|
+
if (spec.type === AST_NODE_TYPES30.ImportSpecifier && spec.imported.type === AST_NODE_TYPES30.Identifier) {
|
|
6237
6330
|
zodImportedNames.set(spec.local.name, spec.imported.name);
|
|
6238
6331
|
}
|
|
6239
6332
|
}
|
|
@@ -6252,7 +6345,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
6252
6345
|
return;
|
|
6253
6346
|
}
|
|
6254
6347
|
const arg = node.arguments[0];
|
|
6255
|
-
if (arg === void 0 || arg.type !==
|
|
6348
|
+
if (arg === void 0 || arg.type !== AST_NODE_TYPES30.Identifier) {
|
|
6256
6349
|
return;
|
|
6257
6350
|
}
|
|
6258
6351
|
const isEnum = resolvesToLocalEnum(arg, sourceCode.getScope(arg)) || services !== null && resolvesToImportedEnum(arg, services);
|
|
@@ -6269,7 +6362,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
6269
6362
|
});
|
|
6270
6363
|
|
|
6271
6364
|
// src/rules/prefer-constant-time-secret-compare.ts
|
|
6272
|
-
import { AST_NODE_TYPES as
|
|
6365
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES31 } from "@typescript-eslint/utils";
|
|
6273
6366
|
var EQUALITY_OPERATORS = /* @__PURE__ */ new Set(["===", "!==", "==", "!="]);
|
|
6274
6367
|
var SENTINEL_IDENTIFIERS = /* @__PURE__ */ new Set(["undefined", "NaN"]);
|
|
6275
6368
|
var SENTINEL_WORDS = /(^|_)(SENTINEL|EMPTY|NONE|NULL|UNSET|MISSING|PLACEHOLDER|DUMMY|FAKE|EXAMPLE)(_|$)/;
|
|
@@ -6282,36 +6375,36 @@ function isConstantReference(identifier) {
|
|
|
6282
6375
|
}
|
|
6283
6376
|
function isExcludedOperand(node) {
|
|
6284
6377
|
switch (node.type) {
|
|
6285
|
-
case
|
|
6378
|
+
case AST_NODE_TYPES31.Literal:
|
|
6286
6379
|
return true;
|
|
6287
|
-
case
|
|
6380
|
+
case AST_NODE_TYPES31.TemplateLiteral:
|
|
6288
6381
|
return node.expressions.length === 0;
|
|
6289
|
-
case
|
|
6382
|
+
case AST_NODE_TYPES31.Identifier:
|
|
6290
6383
|
return SENTINEL_IDENTIFIERS.has(node.name) || SENTINEL_PREFIX_RE.test(node.name) || isConstantReference(node.name);
|
|
6291
|
-
case
|
|
6292
|
-
return !node.computed && node.property.type ===
|
|
6384
|
+
case AST_NODE_TYPES31.MemberExpression:
|
|
6385
|
+
return !node.computed && node.property.type === AST_NODE_TYPES31.Identifier && (SENTINEL_PREFIX_RE.test(node.property.name) || isConstantReference(node.property.name));
|
|
6293
6386
|
default:
|
|
6294
6387
|
return false;
|
|
6295
6388
|
}
|
|
6296
6389
|
}
|
|
6297
6390
|
function operandName(node) {
|
|
6298
|
-
if (node.type ===
|
|
6391
|
+
if (node.type === AST_NODE_TYPES31.Identifier) {
|
|
6299
6392
|
return node.name;
|
|
6300
6393
|
}
|
|
6301
|
-
if (node.type ===
|
|
6394
|
+
if (node.type === AST_NODE_TYPES31.MemberExpression && !node.computed && node.property.type === AST_NODE_TYPES31.Identifier) {
|
|
6302
6395
|
return node.property.name;
|
|
6303
6396
|
}
|
|
6304
6397
|
return null;
|
|
6305
6398
|
}
|
|
6306
6399
|
function isSecretOperand(node) {
|
|
6307
|
-
if (node.type ===
|
|
6400
|
+
if (node.type === AST_NODE_TYPES31.TemplateLiteral) {
|
|
6308
6401
|
return node.expressions.some((expression) => isSecretOperand(expression));
|
|
6309
6402
|
}
|
|
6310
6403
|
const name = operandName(node);
|
|
6311
6404
|
return name !== null && isAuthSecretName(name);
|
|
6312
6405
|
}
|
|
6313
6406
|
function secretNameOf(node) {
|
|
6314
|
-
if (node.type ===
|
|
6407
|
+
if (node.type === AST_NODE_TYPES31.TemplateLiteral) {
|
|
6315
6408
|
for (const expression of node.expressions) {
|
|
6316
6409
|
const nested = secretNameOf(expression);
|
|
6317
6410
|
if (nested !== null) {
|
|
@@ -6364,7 +6457,7 @@ var prefer_constant_time_secret_compare_default = createRule({
|
|
|
6364
6457
|
|
|
6365
6458
|
// src/rules/prefer-discriminated-union.ts
|
|
6366
6459
|
import "@typescript-eslint/utils";
|
|
6367
|
-
import { AST_NODE_TYPES as
|
|
6460
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES32 } from "@typescript-eslint/utils";
|
|
6368
6461
|
var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
6369
6462
|
"success",
|
|
6370
6463
|
"ok",
|
|
@@ -6374,27 +6467,27 @@ var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
|
6374
6467
|
]);
|
|
6375
6468
|
var MIN_OPTIONAL_MEMBERS = 2;
|
|
6376
6469
|
function getMemberName(member) {
|
|
6377
|
-
if (member.type !==
|
|
6470
|
+
if (member.type !== AST_NODE_TYPES32.TSPropertySignature) {
|
|
6378
6471
|
return null;
|
|
6379
6472
|
}
|
|
6380
6473
|
const { key } = member;
|
|
6381
|
-
if (key.type ===
|
|
6474
|
+
if (key.type === AST_NODE_TYPES32.Identifier) {
|
|
6382
6475
|
return key.name;
|
|
6383
6476
|
}
|
|
6384
|
-
if (key.type ===
|
|
6477
|
+
if (key.type === AST_NODE_TYPES32.Literal && typeof key.value === "string") {
|
|
6385
6478
|
return key.value;
|
|
6386
6479
|
}
|
|
6387
6480
|
return null;
|
|
6388
6481
|
}
|
|
6389
6482
|
function isBooleanTyped(member) {
|
|
6390
|
-
return member.typeAnnotation?.typeAnnotation.type ===
|
|
6483
|
+
return member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES32.TSBooleanKeyword;
|
|
6391
6484
|
}
|
|
6392
6485
|
function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
6393
6486
|
let hasStatusBoolean = false;
|
|
6394
6487
|
let optionalCount = 0;
|
|
6395
6488
|
let optionalPayloadCount = 0;
|
|
6396
6489
|
for (const member of typeLiteral.members) {
|
|
6397
|
-
if (member.type !==
|
|
6490
|
+
if (member.type !== AST_NODE_TYPES32.TSPropertySignature) {
|
|
6398
6491
|
continue;
|
|
6399
6492
|
}
|
|
6400
6493
|
if (member.optional) {
|
|
@@ -6436,7 +6529,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
6436
6529
|
TSInterfaceDeclaration(node) {
|
|
6437
6530
|
const synthetic = {
|
|
6438
6531
|
...node.body,
|
|
6439
|
-
type:
|
|
6532
|
+
type: AST_NODE_TYPES32.TSTypeLiteral,
|
|
6440
6533
|
members: node.body.body
|
|
6441
6534
|
};
|
|
6442
6535
|
checkTypeLiteral(synthetic, node);
|
|
@@ -6449,7 +6542,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
6449
6542
|
});
|
|
6450
6543
|
|
|
6451
6544
|
// src/rules/prefer-module-level-constant.ts
|
|
6452
|
-
import { AST_NODE_TYPES as
|
|
6545
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES33 } from "@typescript-eslint/utils";
|
|
6453
6546
|
var DEFAULT_MIN_ELEMENTS = 3;
|
|
6454
6547
|
var MAX_LITERAL_DEPTH = 4;
|
|
6455
6548
|
var IGNORE_PATTERNS2 = [
|
|
@@ -6478,9 +6571,9 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
|
6478
6571
|
"assign"
|
|
6479
6572
|
]);
|
|
6480
6573
|
var FUNCTION_TYPES5 = /* @__PURE__ */ new Set([
|
|
6481
|
-
|
|
6482
|
-
|
|
6483
|
-
|
|
6574
|
+
AST_NODE_TYPES33.FunctionDeclaration,
|
|
6575
|
+
AST_NODE_TYPES33.FunctionExpression,
|
|
6576
|
+
AST_NODE_TYPES33.ArrowFunctionExpression
|
|
6484
6577
|
]);
|
|
6485
6578
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
6486
6579
|
function isIgnoredFile2(filename, sourceText) {
|
|
@@ -6493,14 +6586,14 @@ function isLocalFixtureFile(filename) {
|
|
|
6493
6586
|
return isTestFile(filename) || isStoryFile(filename);
|
|
6494
6587
|
}
|
|
6495
6588
|
function unwrap3(node) {
|
|
6496
|
-
if (node.type ===
|
|
6589
|
+
if (node.type === AST_NODE_TYPES33.TSAsExpression || node.type === AST_NODE_TYPES33.TSSatisfiesExpression || node.type === AST_NODE_TYPES33.TSNonNullExpression) {
|
|
6497
6590
|
return unwrap3(node.expression);
|
|
6498
6591
|
}
|
|
6499
6592
|
return node;
|
|
6500
6593
|
}
|
|
6501
6594
|
var HAS_STATEFUL_FLAG_RE = /[gy]/;
|
|
6502
6595
|
function isRegexLiteral(node) {
|
|
6503
|
-
return node.type ===
|
|
6596
|
+
return node.type === AST_NODE_TYPES33.Literal && "regex" in node && node.regex !== void 0;
|
|
6504
6597
|
}
|
|
6505
6598
|
function isLiteralOnly(node, depth) {
|
|
6506
6599
|
if (depth > MAX_LITERAL_DEPTH) {
|
|
@@ -6508,29 +6601,29 @@ function isLiteralOnly(node, depth) {
|
|
|
6508
6601
|
}
|
|
6509
6602
|
const inner = unwrap3(node);
|
|
6510
6603
|
switch (inner.type) {
|
|
6511
|
-
case
|
|
6604
|
+
case AST_NODE_TYPES33.Literal: {
|
|
6512
6605
|
return !(isRegexLiteral(inner) && HAS_STATEFUL_FLAG_RE.test(inner.regex.flags));
|
|
6513
6606
|
}
|
|
6514
|
-
case
|
|
6607
|
+
case AST_NODE_TYPES33.TemplateLiteral: {
|
|
6515
6608
|
return inner.expressions.length === 0;
|
|
6516
6609
|
}
|
|
6517
|
-
case
|
|
6518
|
-
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type ===
|
|
6610
|
+
case AST_NODE_TYPES33.UnaryExpression: {
|
|
6611
|
+
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type === AST_NODE_TYPES33.Literal && typeof inner.argument.value === "number";
|
|
6519
6612
|
}
|
|
6520
|
-
case
|
|
6613
|
+
case AST_NODE_TYPES33.ArrayExpression: {
|
|
6521
6614
|
return inner.elements.every(
|
|
6522
|
-
(el) => el !== null && el.type !==
|
|
6615
|
+
(el) => el !== null && el.type !== AST_NODE_TYPES33.SpreadElement && isLiteralOnly(el, depth + 1)
|
|
6523
6616
|
);
|
|
6524
6617
|
}
|
|
6525
|
-
case
|
|
6618
|
+
case AST_NODE_TYPES33.ObjectExpression: {
|
|
6526
6619
|
return inner.properties.every((prop) => {
|
|
6527
|
-
if (prop.type !==
|
|
6620
|
+
if (prop.type !== AST_NODE_TYPES33.Property) {
|
|
6528
6621
|
return false;
|
|
6529
6622
|
}
|
|
6530
6623
|
if (prop.shorthand || prop.method || prop.kind !== "init") {
|
|
6531
6624
|
return false;
|
|
6532
6625
|
}
|
|
6533
|
-
if (prop.computed && prop.key.type !==
|
|
6626
|
+
if (prop.computed && prop.key.type !== AST_NODE_TYPES33.Literal) {
|
|
6534
6627
|
return false;
|
|
6535
6628
|
}
|
|
6536
6629
|
return isLiteralOnly(prop.value, depth + 1);
|
|
@@ -6543,7 +6636,7 @@ function isLiteralOnly(node, depth) {
|
|
|
6543
6636
|
}
|
|
6544
6637
|
function unwrapObjectFreeze(node) {
|
|
6545
6638
|
const inner = unwrap3(node);
|
|
6546
|
-
if (inner.type ===
|
|
6639
|
+
if (inner.type === AST_NODE_TYPES33.CallExpression && inner.callee.type === AST_NODE_TYPES33.MemberExpression && !inner.callee.computed && inner.callee.object.type === AST_NODE_TYPES33.Identifier && inner.callee.object.name === "Object" && inner.callee.property.type === AST_NODE_TYPES33.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== AST_NODE_TYPES33.SpreadElement) {
|
|
6547
6640
|
return unwrap3(inner.arguments[0]);
|
|
6548
6641
|
}
|
|
6549
6642
|
return inner;
|
|
@@ -6559,19 +6652,19 @@ function classify(init, checkRegex) {
|
|
|
6559
6652
|
}
|
|
6560
6653
|
return { kind: "regex", size: 1 };
|
|
6561
6654
|
}
|
|
6562
|
-
if (node.type ===
|
|
6655
|
+
if (node.type === AST_NODE_TYPES33.ArrayExpression) {
|
|
6563
6656
|
return isLiteralOnly(node, 0) ? { kind: "array", size: node.elements.length } : null;
|
|
6564
6657
|
}
|
|
6565
|
-
if (node.type ===
|
|
6658
|
+
if (node.type === AST_NODE_TYPES33.ObjectExpression) {
|
|
6566
6659
|
return isLiteralOnly(node, 0) ? { kind: "object", size: node.properties.length } : null;
|
|
6567
6660
|
}
|
|
6568
|
-
if (node.type ===
|
|
6661
|
+
if (node.type === AST_NODE_TYPES33.NewExpression && node.callee.type === AST_NODE_TYPES33.Identifier && COLLECTION_CONSTRUCTORS.has(node.callee.name)) {
|
|
6569
6662
|
const arg = node.arguments[0];
|
|
6570
|
-
if (node.arguments.length !== 1 || arg === void 0 || arg.type ===
|
|
6663
|
+
if (node.arguments.length !== 1 || arg === void 0 || arg.type === AST_NODE_TYPES33.SpreadElement) {
|
|
6571
6664
|
return null;
|
|
6572
6665
|
}
|
|
6573
6666
|
const entries = unwrap3(arg);
|
|
6574
|
-
if (entries.type !==
|
|
6667
|
+
if (entries.type !== AST_NODE_TYPES33.ArrayExpression) {
|
|
6575
6668
|
return null;
|
|
6576
6669
|
}
|
|
6577
6670
|
return isLiteralOnly(entries, 0) ? { kind: node.callee.name === "Set" ? "Set" : "Map", size: entries.elements.length } : null;
|
|
@@ -6600,10 +6693,10 @@ var NON_RETAINING_BUILTINS = /* @__PURE__ */ new Map(
|
|
|
6600
6693
|
);
|
|
6601
6694
|
function isNonRetainingBuiltinCall(node, argument) {
|
|
6602
6695
|
const callee = node.callee;
|
|
6603
|
-
if (callee.type ===
|
|
6696
|
+
if (callee.type === AST_NODE_TYPES33.Identifier && callee.name === "structuredClone") {
|
|
6604
6697
|
return true;
|
|
6605
6698
|
}
|
|
6606
|
-
if (callee.type !==
|
|
6699
|
+
if (callee.type !== AST_NODE_TYPES33.MemberExpression || callee.computed || callee.object.type !== AST_NODE_TYPES33.Identifier || callee.property.type !== AST_NODE_TYPES33.Identifier) {
|
|
6607
6700
|
return false;
|
|
6608
6701
|
}
|
|
6609
6702
|
const members = NON_RETAINING_BUILTINS.get(callee.object.name);
|
|
@@ -6617,38 +6710,38 @@ function isNonRetainingBuiltinCall(node, argument) {
|
|
|
6617
6710
|
}
|
|
6618
6711
|
function isSafeRead(identifier) {
|
|
6619
6712
|
const parent = identifier.parent;
|
|
6620
|
-
if (parent.type ===
|
|
6713
|
+
if (parent.type === AST_NODE_TYPES33.MemberExpression) {
|
|
6621
6714
|
if (parent.object !== identifier) {
|
|
6622
6715
|
return true;
|
|
6623
6716
|
}
|
|
6624
6717
|
const grandparent = parent.parent;
|
|
6625
|
-
if (grandparent.type ===
|
|
6718
|
+
if (grandparent.type === AST_NODE_TYPES33.AssignmentExpression && grandparent.left === parent) {
|
|
6626
6719
|
return false;
|
|
6627
6720
|
}
|
|
6628
|
-
if (grandparent.type ===
|
|
6721
|
+
if (grandparent.type === AST_NODE_TYPES33.UpdateExpression) {
|
|
6629
6722
|
return false;
|
|
6630
6723
|
}
|
|
6631
|
-
if (grandparent.type ===
|
|
6724
|
+
if (grandparent.type === AST_NODE_TYPES33.UnaryExpression && grandparent.operator === "delete") {
|
|
6632
6725
|
return false;
|
|
6633
6726
|
}
|
|
6634
|
-
if (!parent.computed && parent.property.type ===
|
|
6727
|
+
if (!parent.computed && parent.property.type === AST_NODE_TYPES33.Identifier && MUTATING_METHODS.has(parent.property.name) && grandparent.type === AST_NODE_TYPES33.CallExpression && grandparent.callee === parent) {
|
|
6635
6728
|
return false;
|
|
6636
6729
|
}
|
|
6637
6730
|
return true;
|
|
6638
6731
|
}
|
|
6639
|
-
if (parent.type ===
|
|
6732
|
+
if (parent.type === AST_NODE_TYPES33.ForOfStatement && parent.right === identifier) {
|
|
6640
6733
|
return true;
|
|
6641
6734
|
}
|
|
6642
|
-
if (parent.type ===
|
|
6735
|
+
if (parent.type === AST_NODE_TYPES33.SpreadElement) {
|
|
6643
6736
|
return true;
|
|
6644
6737
|
}
|
|
6645
|
-
if (parent.type ===
|
|
6738
|
+
if (parent.type === AST_NODE_TYPES33.BinaryExpression) {
|
|
6646
6739
|
return true;
|
|
6647
6740
|
}
|
|
6648
|
-
if (parent.type ===
|
|
6741
|
+
if (parent.type === AST_NODE_TYPES33.CallExpression && parent.arguments.includes(identifier) && isNonRetainingBuiltinCall(parent, identifier)) {
|
|
6649
6742
|
return true;
|
|
6650
6743
|
}
|
|
6651
|
-
if (parent.type ===
|
|
6744
|
+
if (parent.type === AST_NODE_TYPES33.UnaryExpression && parent.operator !== "delete") {
|
|
6652
6745
|
return true;
|
|
6653
6746
|
}
|
|
6654
6747
|
return false;
|
|
@@ -6703,7 +6796,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6703
6796
|
if (reference.isWrite()) {
|
|
6704
6797
|
return false;
|
|
6705
6798
|
}
|
|
6706
|
-
if (reference.identifier.type !==
|
|
6799
|
+
if (reference.identifier.type !== AST_NODE_TYPES33.Identifier) {
|
|
6707
6800
|
return false;
|
|
6708
6801
|
}
|
|
6709
6802
|
if (!isSafeRead(reference.identifier)) {
|
|
@@ -6715,10 +6808,10 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6715
6808
|
return {
|
|
6716
6809
|
VariableDeclarator(node) {
|
|
6717
6810
|
const declaration = node.parent;
|
|
6718
|
-
if (declaration.type !==
|
|
6811
|
+
if (declaration.type !== AST_NODE_TYPES33.VariableDeclaration || declaration.kind !== "const" || declaration.declare === true) {
|
|
6719
6812
|
return;
|
|
6720
6813
|
}
|
|
6721
|
-
if (node.id.type !==
|
|
6814
|
+
if (node.id.type !== AST_NODE_TYPES33.Identifier || node.init === null) {
|
|
6722
6815
|
return;
|
|
6723
6816
|
}
|
|
6724
6817
|
if (enclosingFunction2(node) === null) {
|
|
@@ -6745,7 +6838,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6745
6838
|
});
|
|
6746
6839
|
|
|
6747
6840
|
// src/rules/prefer-module-level-schema.ts
|
|
6748
|
-
import { AST_NODE_TYPES as
|
|
6841
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES34 } from "@typescript-eslint/utils";
|
|
6749
6842
|
|
|
6750
6843
|
// src/rules/_zod.ts
|
|
6751
6844
|
var ZOD_PREFIX_RE = /^Z[A-Z]/;
|
|
@@ -6811,9 +6904,9 @@ var I18N_RECEIVER_NAMES = /* @__PURE__ */ new Set([
|
|
|
6811
6904
|
"intl"
|
|
6812
6905
|
]);
|
|
6813
6906
|
var FUNCTION_TYPES6 = /* @__PURE__ */ new Set([
|
|
6814
|
-
|
|
6815
|
-
|
|
6816
|
-
|
|
6907
|
+
AST_NODE_TYPES34.ArrowFunctionExpression,
|
|
6908
|
+
AST_NODE_TYPES34.FunctionDeclaration,
|
|
6909
|
+
AST_NODE_TYPES34.FunctionExpression
|
|
6817
6910
|
]);
|
|
6818
6911
|
function schemaExpression(node) {
|
|
6819
6912
|
let current = node;
|
|
@@ -6822,10 +6915,10 @@ function schemaExpression(node) {
|
|
|
6822
6915
|
if (parent === void 0) {
|
|
6823
6916
|
return current;
|
|
6824
6917
|
}
|
|
6825
|
-
if (parent.type ===
|
|
6918
|
+
if (parent.type === AST_NODE_TYPES34.MemberExpression && parent.object === current && !parent.computed && parent.property.type === AST_NODE_TYPES34.Identifier && TERMINAL_METHODS.has(parent.property.name)) {
|
|
6826
6919
|
return current;
|
|
6827
6920
|
}
|
|
6828
|
-
if (parent.type ===
|
|
6921
|
+
if (parent.type === AST_NODE_TYPES34.MemberExpression && parent.object === current || parent.type === AST_NODE_TYPES34.CallExpression && parent.callee === current || parent.type === AST_NODE_TYPES34.TSAsExpression && parent.expression === current || parent.type === AST_NODE_TYPES34.TSNonNullExpression && parent.expression === current) {
|
|
6829
6922
|
current = parent;
|
|
6830
6923
|
continue;
|
|
6831
6924
|
}
|
|
@@ -6876,22 +6969,22 @@ function subtreeSome(root, predicate) {
|
|
|
6876
6969
|
function readsReceiver(node) {
|
|
6877
6970
|
return subtreeSome(
|
|
6878
6971
|
node,
|
|
6879
|
-
(inner) => inner.type ===
|
|
6972
|
+
(inner) => inner.type === AST_NODE_TYPES34.ThisExpression || inner.type === AST_NODE_TYPES34.Super || inner.type === AST_NODE_TYPES34.Identifier && inner.name === "arguments"
|
|
6880
6973
|
);
|
|
6881
6974
|
}
|
|
6882
6975
|
function buildsLocalizedText(node) {
|
|
6883
6976
|
return subtreeSome(node, (inner) => {
|
|
6884
|
-
if (inner.type ===
|
|
6977
|
+
if (inner.type === AST_NODE_TYPES34.TaggedTemplateExpression) {
|
|
6885
6978
|
return true;
|
|
6886
6979
|
}
|
|
6887
|
-
if (inner.type !==
|
|
6980
|
+
if (inner.type !== AST_NODE_TYPES34.CallExpression) {
|
|
6888
6981
|
return false;
|
|
6889
6982
|
}
|
|
6890
6983
|
const { callee } = inner;
|
|
6891
|
-
if (callee.type ===
|
|
6984
|
+
if (callee.type === AST_NODE_TYPES34.Identifier) {
|
|
6892
6985
|
return I18N_CALLEE_NAMES.has(callee.name);
|
|
6893
6986
|
}
|
|
6894
|
-
return callee.type ===
|
|
6987
|
+
return callee.type === AST_NODE_TYPES34.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES34.Identifier && I18N_RECEIVER_NAMES.has(callee.object.name);
|
|
6895
6988
|
});
|
|
6896
6989
|
}
|
|
6897
6990
|
function collectReferences(scope, out) {
|
|
@@ -6948,15 +7041,15 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6948
7041
|
}
|
|
6949
7042
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
6950
7043
|
function isZodCall(node) {
|
|
6951
|
-
return node.type ===
|
|
7044
|
+
return node.type === AST_NODE_TYPES34.CallExpression && node.callee.type === AST_NODE_TYPES34.MemberExpression && !node.callee.computed && node.callee.object.type === AST_NODE_TYPES34.Identifier && zodNamespaces.has(node.callee.object.name);
|
|
6952
7045
|
}
|
|
6953
7046
|
function isCovered(node) {
|
|
6954
7047
|
let current = node.parent ?? void 0;
|
|
6955
7048
|
while (current !== void 0) {
|
|
6956
|
-
if (current !== node && isZodCall(current) && current.callee.type ===
|
|
7049
|
+
if (current !== node && isZodCall(current) && current.callee.type === AST_NODE_TYPES34.MemberExpression && current.callee.property.type === AST_NODE_TYPES34.Identifier && factories.has(current.callee.property.name)) {
|
|
6957
7050
|
return true;
|
|
6958
7051
|
}
|
|
6959
|
-
if (current.type ===
|
|
7052
|
+
if (current.type === AST_NODE_TYPES34.CallExpression && (current.callee.type === AST_NODE_TYPES34.Identifier && MEMO_CALLEES.has(current.callee.name) || current.callee.type === AST_NODE_TYPES34.MemberExpression && !current.callee.computed && current.callee.property.type === AST_NODE_TYPES34.Identifier && MEMO_CALLEES.has(current.callee.property.name))) {
|
|
6960
7053
|
return true;
|
|
6961
7054
|
}
|
|
6962
7055
|
current = current.parent ?? void 0;
|
|
@@ -6971,11 +7064,11 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6971
7064
|
if (parent === void 0) {
|
|
6972
7065
|
return confirmed;
|
|
6973
7066
|
}
|
|
6974
|
-
if (parent.type ===
|
|
7067
|
+
if (parent.type === AST_NODE_TYPES34.Property && parent.value === current || parent.type === AST_NODE_TYPES34.ObjectExpression || parent.type === AST_NODE_TYPES34.ArrayExpression) {
|
|
6975
7068
|
current = parent;
|
|
6976
7069
|
continue;
|
|
6977
7070
|
}
|
|
6978
|
-
if (parent.type ===
|
|
7071
|
+
if (parent.type === AST_NODE_TYPES34.CallExpression && parent.arguments.includes(current) && isSchemaComposition(parent)) {
|
|
6979
7072
|
current = schemaExpression(parent);
|
|
6980
7073
|
confirmed = current;
|
|
6981
7074
|
continue;
|
|
@@ -6985,7 +7078,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6985
7078
|
}
|
|
6986
7079
|
function isSchemaComposition(node) {
|
|
6987
7080
|
const { callee } = node;
|
|
6988
|
-
const isCombinator = callee.type ===
|
|
7081
|
+
const isCombinator = callee.type === AST_NODE_TYPES34.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES34.Identifier && ZOD_COMBINATOR_METHODS.has(callee.property.name);
|
|
6989
7082
|
return isCombinator || isZodCall(node);
|
|
6990
7083
|
}
|
|
6991
7084
|
function closesOverNothing(node, enclosing) {
|
|
@@ -7019,13 +7112,13 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7019
7112
|
}
|
|
7020
7113
|
function ownerName(enclosing) {
|
|
7021
7114
|
const parent = enclosing.parent ?? void 0;
|
|
7022
|
-
if (enclosing.type ===
|
|
7115
|
+
if (enclosing.type === AST_NODE_TYPES34.FunctionDeclaration && enclosing.id !== null) {
|
|
7023
7116
|
return enclosing.id.name;
|
|
7024
7117
|
}
|
|
7025
|
-
if (parent !== void 0 && parent.type ===
|
|
7118
|
+
if (parent !== void 0 && parent.type === AST_NODE_TYPES34.VariableDeclarator && parent.id.type === AST_NODE_TYPES34.Identifier) {
|
|
7026
7119
|
return parent.id.name;
|
|
7027
7120
|
}
|
|
7028
|
-
if (parent !== void 0 && (parent.type ===
|
|
7121
|
+
if (parent !== void 0 && (parent.type === AST_NODE_TYPES34.MethodDefinition || parent.type === AST_NODE_TYPES34.Property) && parent.key.type === AST_NODE_TYPES34.Identifier) {
|
|
7029
7122
|
return parent.key.name;
|
|
7030
7123
|
}
|
|
7031
7124
|
return "this function";
|
|
@@ -7036,7 +7129,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7036
7129
|
return;
|
|
7037
7130
|
}
|
|
7038
7131
|
for (const specifier of node.specifiers) {
|
|
7039
|
-
if (specifier.type ===
|
|
7132
|
+
if (specifier.type === AST_NODE_TYPES34.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES34.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES34.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES34.Identifier && specifier.imported.name === "z") {
|
|
7040
7133
|
zodNamespaces.add(specifier.local.name);
|
|
7041
7134
|
}
|
|
7042
7135
|
}
|
|
@@ -7046,7 +7139,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7046
7139
|
return;
|
|
7047
7140
|
}
|
|
7048
7141
|
const callee = node.callee;
|
|
7049
|
-
if (callee.property.type !==
|
|
7142
|
+
if (callee.property.type !== AST_NODE_TYPES34.Identifier) {
|
|
7050
7143
|
return;
|
|
7051
7144
|
}
|
|
7052
7145
|
const factory = callee.property.name;
|
|
@@ -7061,7 +7154,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7061
7154
|
return;
|
|
7062
7155
|
}
|
|
7063
7156
|
const shape = node.arguments[0];
|
|
7064
|
-
if (shape !== void 0 && shape.type ===
|
|
7157
|
+
if (shape !== void 0 && shape.type === AST_NODE_TYPES34.ObjectExpression && shape.properties.length < minProperties) {
|
|
7065
7158
|
return;
|
|
7066
7159
|
}
|
|
7067
7160
|
const expression = schemaExpression(node);
|
|
@@ -7089,20 +7182,20 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7089
7182
|
});
|
|
7090
7183
|
|
|
7091
7184
|
// src/rules/prefer-non-nullable-collection.ts
|
|
7092
|
-
import { AST_NODE_TYPES as
|
|
7185
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES35 } from "@typescript-eslint/utils";
|
|
7093
7186
|
var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
7094
7187
|
function propertyName(node) {
|
|
7095
7188
|
const key = node.key;
|
|
7096
|
-
if (key.type ===
|
|
7097
|
-
if (key.type ===
|
|
7189
|
+
if (key.type === AST_NODE_TYPES35.Identifier) return key.name;
|
|
7190
|
+
if (key.type === AST_NODE_TYPES35.Literal) return String(key.value);
|
|
7098
7191
|
return "collection";
|
|
7099
7192
|
}
|
|
7100
7193
|
function isArrayType(node) {
|
|
7101
|
-
if (node.type ===
|
|
7102
|
-
return node.type ===
|
|
7194
|
+
if (node.type === AST_NODE_TYPES35.TSArrayType) return true;
|
|
7195
|
+
return node.type === AST_NODE_TYPES35.TSTypeReference && node.typeName.type === AST_NODE_TYPES35.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
7103
7196
|
}
|
|
7104
7197
|
function isNullishType(node) {
|
|
7105
|
-
return node.type ===
|
|
7198
|
+
return node.type === AST_NODE_TYPES35.TSNullKeyword || node.type === AST_NODE_TYPES35.TSUndefinedKeyword;
|
|
7106
7199
|
}
|
|
7107
7200
|
function isNullableArrayOnly(node) {
|
|
7108
7201
|
const values = node.types.filter((member) => !isNullishType(member));
|
|
@@ -7127,9 +7220,10 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
7127
7220
|
return {};
|
|
7128
7221
|
}
|
|
7129
7222
|
function checkOptionalProperty(node) {
|
|
7223
|
+
if (node.optional) return;
|
|
7130
7224
|
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
7131
7225
|
if (annotation === void 0) return;
|
|
7132
|
-
if (annotation.type !==
|
|
7226
|
+
if (annotation.type !== AST_NODE_TYPES35.TSUnionType || !isNullableArrayOnly(annotation)) {
|
|
7133
7227
|
return;
|
|
7134
7228
|
}
|
|
7135
7229
|
context.report({
|
|
@@ -7142,7 +7236,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
7142
7236
|
TSPropertySignature: checkOptionalProperty,
|
|
7143
7237
|
PropertyDefinition: checkOptionalProperty,
|
|
7144
7238
|
TSTypeAliasDeclaration(node) {
|
|
7145
|
-
if (node.typeAnnotation.type !==
|
|
7239
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES35.TSUnionType) return;
|
|
7146
7240
|
if (!isNullableArrayOnly(node.typeAnnotation)) return;
|
|
7147
7241
|
context.report({
|
|
7148
7242
|
node,
|
|
@@ -7154,14 +7248,100 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
7154
7248
|
}
|
|
7155
7249
|
});
|
|
7156
7250
|
|
|
7251
|
+
// src/rules/prefer-native-random-uuid.ts
|
|
7252
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES36, ASTUtils as ASTUtils3 } from "@typescript-eslint/utils";
|
|
7253
|
+
function requireUuid(node) {
|
|
7254
|
+
return node?.type === AST_NODE_TYPES36.CallExpression && node.callee.type === AST_NODE_TYPES36.Identifier && node.callee.name === "require" && node.arguments.length === 1 && node.arguments[0]?.type === AST_NODE_TYPES36.Literal && node.arguments[0].value === "uuid";
|
|
7255
|
+
}
|
|
7256
|
+
var prefer_native_random_uuid_default = createRule({
|
|
7257
|
+
name: "prefer-native-random-uuid",
|
|
7258
|
+
meta: {
|
|
7259
|
+
type: "suggestion",
|
|
7260
|
+
docs: {
|
|
7261
|
+
description: "Prefer `globalThis.crypto.randomUUID()` over resolved zero-argument UUID v4 bindings from the `uuid` package."
|
|
7262
|
+
},
|
|
7263
|
+
hasSuggestions: true,
|
|
7264
|
+
schema: [],
|
|
7265
|
+
messages: {
|
|
7266
|
+
preferNative: "Use the Node 22 native `globalThis.crypto.randomUUID()` instead of the `uuid` package for UUID v4.",
|
|
7267
|
+
replaceWithNative: "Replace this UUID v4 call with the native implementation."
|
|
7268
|
+
}
|
|
7269
|
+
},
|
|
7270
|
+
defaultOptions: [],
|
|
7271
|
+
create(context) {
|
|
7272
|
+
const directBindings = /* @__PURE__ */ new Set();
|
|
7273
|
+
const namespaceBindings = /* @__PURE__ */ new Set();
|
|
7274
|
+
function resolve(identifier) {
|
|
7275
|
+
return ASTUtils3.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
7276
|
+
}
|
|
7277
|
+
function record(identifier, destination) {
|
|
7278
|
+
const variable = resolve(identifier);
|
|
7279
|
+
if (variable !== null) destination.add(variable);
|
|
7280
|
+
}
|
|
7281
|
+
function report(node) {
|
|
7282
|
+
context.report({
|
|
7283
|
+
node,
|
|
7284
|
+
messageId: "preferNative",
|
|
7285
|
+
suggest: [
|
|
7286
|
+
{
|
|
7287
|
+
messageId: "replaceWithNative",
|
|
7288
|
+
fix: (fixer) => fixer.replaceText(node, "globalThis.crypto.randomUUID()")
|
|
7289
|
+
}
|
|
7290
|
+
]
|
|
7291
|
+
});
|
|
7292
|
+
}
|
|
7293
|
+
return {
|
|
7294
|
+
ImportDeclaration(node) {
|
|
7295
|
+
if (node.source.value !== "uuid") return;
|
|
7296
|
+
for (const specifier of node.specifiers) {
|
|
7297
|
+
if (specifier.type === AST_NODE_TYPES36.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES36.Identifier ? specifier.imported.name === "v4" : specifier.imported.value === "v4")) {
|
|
7298
|
+
record(specifier.local, directBindings);
|
|
7299
|
+
} else if (specifier.type === AST_NODE_TYPES36.ImportNamespaceSpecifier) {
|
|
7300
|
+
record(specifier.local, namespaceBindings);
|
|
7301
|
+
}
|
|
7302
|
+
}
|
|
7303
|
+
},
|
|
7304
|
+
VariableDeclarator(node) {
|
|
7305
|
+
if (node.parent.kind !== "const" || !requireUuid(node.init)) return;
|
|
7306
|
+
if (node.init?.type !== AST_NODE_TYPES36.CallExpression || node.init.callee.type !== AST_NODE_TYPES36.Identifier || (resolve(node.init.callee)?.defs.length ?? 0) > 0) {
|
|
7307
|
+
return;
|
|
7308
|
+
}
|
|
7309
|
+
if (node.id.type === AST_NODE_TYPES36.Identifier) {
|
|
7310
|
+
record(node.id, namespaceBindings);
|
|
7311
|
+
return;
|
|
7312
|
+
}
|
|
7313
|
+
if (node.id.type !== AST_NODE_TYPES36.ObjectPattern) return;
|
|
7314
|
+
for (const property of node.id.properties) {
|
|
7315
|
+
if (property.type === AST_NODE_TYPES36.Property && !property.computed && (property.key.type === AST_NODE_TYPES36.Identifier && property.key.name === "v4" || property.key.type === AST_NODE_TYPES36.Literal && property.key.value === "v4") && property.value.type === AST_NODE_TYPES36.Identifier) {
|
|
7316
|
+
record(property.value, directBindings);
|
|
7317
|
+
}
|
|
7318
|
+
}
|
|
7319
|
+
},
|
|
7320
|
+
"CallExpression:exit"(node) {
|
|
7321
|
+
if (node.arguments.length !== 0) return;
|
|
7322
|
+
if (node.callee.type === AST_NODE_TYPES36.Identifier) {
|
|
7323
|
+
const variable2 = resolve(node.callee);
|
|
7324
|
+
if (variable2 !== null && directBindings.has(variable2)) report(node);
|
|
7325
|
+
return;
|
|
7326
|
+
}
|
|
7327
|
+
if (node.callee.type !== AST_NODE_TYPES36.MemberExpression || node.callee.computed || node.callee.object.type !== AST_NODE_TYPES36.Identifier || node.callee.property.type !== AST_NODE_TYPES36.Identifier || node.callee.property.name !== "v4") {
|
|
7328
|
+
return;
|
|
7329
|
+
}
|
|
7330
|
+
const variable = resolve(node.callee.object);
|
|
7331
|
+
if (variable !== null && namespaceBindings.has(variable)) report(node);
|
|
7332
|
+
}
|
|
7333
|
+
};
|
|
7334
|
+
}
|
|
7335
|
+
});
|
|
7336
|
+
|
|
7157
7337
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
7158
|
-
import { AST_NODE_TYPES as
|
|
7338
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES37 } from "@typescript-eslint/utils";
|
|
7159
7339
|
var unwrap4 = (node) => {
|
|
7160
7340
|
let current = node;
|
|
7161
7341
|
while (current !== null && current !== void 0) {
|
|
7162
|
-
if (current.type ===
|
|
7342
|
+
if (current.type === AST_NODE_TYPES37.TSAsExpression || current.type === AST_NODE_TYPES37.TSTypeAssertion || current.type === AST_NODE_TYPES37.TSNonNullExpression || current.type === AST_NODE_TYPES37.TSSatisfiesExpression) {
|
|
7163
7343
|
current = current.expression;
|
|
7164
|
-
} else if (current.type ===
|
|
7344
|
+
} else if (current.type === AST_NODE_TYPES37.ChainExpression) {
|
|
7165
7345
|
current = current.expression;
|
|
7166
7346
|
} else {
|
|
7167
7347
|
break;
|
|
@@ -7176,23 +7356,23 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
7176
7356
|
]);
|
|
7177
7357
|
var isSchemaParseReference = (node) => {
|
|
7178
7358
|
const inner = unwrap4(node);
|
|
7179
|
-
return inner !== null && inner.type ===
|
|
7359
|
+
return inner !== null && inner.type === AST_NODE_TYPES37.MemberExpression && !inner.computed && inner.property.type === AST_NODE_TYPES37.Identifier && (inner.property.name === "parse" || inner.property.name === "safeParse");
|
|
7180
7360
|
};
|
|
7181
7361
|
var isRawPayloadSource = (node) => {
|
|
7182
7362
|
let current = unwrap4(node);
|
|
7183
7363
|
if (current === null) return false;
|
|
7184
|
-
if (current.type ===
|
|
7364
|
+
if (current.type === AST_NODE_TYPES37.AwaitExpression) {
|
|
7185
7365
|
current = unwrap4(current.argument);
|
|
7186
7366
|
}
|
|
7187
|
-
if (current === null || current.type !==
|
|
7367
|
+
if (current === null || current.type !== AST_NODE_TYPES37.CallExpression) {
|
|
7188
7368
|
return false;
|
|
7189
7369
|
}
|
|
7190
7370
|
const callee = unwrap4(current.callee);
|
|
7191
|
-
if (callee === null || callee.type !==
|
|
7371
|
+
if (callee === null || callee.type !== AST_NODE_TYPES37.MemberExpression) {
|
|
7192
7372
|
return false;
|
|
7193
7373
|
}
|
|
7194
7374
|
const property = unwrap4(callee.property);
|
|
7195
|
-
if (property === null || property.type !==
|
|
7375
|
+
if (property === null || property.type !== AST_NODE_TYPES37.Identifier) {
|
|
7196
7376
|
return false;
|
|
7197
7377
|
}
|
|
7198
7378
|
if (property.name === "json") {
|
|
@@ -7202,16 +7382,16 @@ var isRawPayloadSource = (node) => {
|
|
|
7202
7382
|
return !current.arguments.some(isSchemaParseReference) && isRawPayloadSource(callee.object);
|
|
7203
7383
|
}
|
|
7204
7384
|
const object = unwrap4(callee.object);
|
|
7205
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
7385
|
+
return property.name === "parse" && object !== null && object.type === AST_NODE_TYPES37.Identifier && object.name === "JSON" && !isLocalFileRead(current.arguments[0]);
|
|
7206
7386
|
};
|
|
7207
7387
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
7208
7388
|
var isLocalFileRead = (node) => {
|
|
7209
7389
|
let found = false;
|
|
7210
7390
|
const visit = (current) => {
|
|
7211
7391
|
if (found || current === null || current === void 0) return;
|
|
7212
|
-
if (current.type ===
|
|
7392
|
+
if (current.type === AST_NODE_TYPES37.CallExpression) {
|
|
7213
7393
|
const callee = unwrap4(current.callee);
|
|
7214
|
-
const name = callee?.type ===
|
|
7394
|
+
const name = callee?.type === AST_NODE_TYPES37.Identifier ? callee.name : callee?.type === AST_NODE_TYPES37.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES37.Identifier ? callee.property.name : null;
|
|
7215
7395
|
if (name !== null && FILE_READ_RE.test(name)) {
|
|
7216
7396
|
found = true;
|
|
7217
7397
|
return;
|
|
@@ -7233,15 +7413,15 @@ var isLocalFileRead = (node) => {
|
|
|
7233
7413
|
var ASSERTION_CALLEE_RE = /^(expect|assert|should|invariant)$/;
|
|
7234
7414
|
var isInsideAssertion = (node) => {
|
|
7235
7415
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
7236
|
-
if (current.type !==
|
|
7416
|
+
if (current.type !== AST_NODE_TYPES37.CallExpression) continue;
|
|
7237
7417
|
let callee = current.callee;
|
|
7238
|
-
while (callee.type ===
|
|
7418
|
+
while (callee.type === AST_NODE_TYPES37.MemberExpression) {
|
|
7239
7419
|
callee = callee.object;
|
|
7240
7420
|
}
|
|
7241
|
-
if (callee.type ===
|
|
7421
|
+
if (callee.type === AST_NODE_TYPES37.CallExpression) {
|
|
7242
7422
|
callee = callee.callee;
|
|
7243
7423
|
}
|
|
7244
|
-
if (callee.type ===
|
|
7424
|
+
if (callee.type === AST_NODE_TYPES37.Identifier && ASSERTION_CALLEE_RE.test(callee.name)) {
|
|
7245
7425
|
return true;
|
|
7246
7426
|
}
|
|
7247
7427
|
}
|
|
@@ -7260,39 +7440,39 @@ var GUARD_NAME_RE = /^(?:is|validate|parse|assert|decode|coerce)[A-Z]/;
|
|
|
7260
7440
|
var isValidationRead = (node) => {
|
|
7261
7441
|
let current = node;
|
|
7262
7442
|
let parent = current.parent;
|
|
7263
|
-
while (parent !== null && parent !== void 0 && (parent.type ===
|
|
7443
|
+
while (parent !== null && parent !== void 0 && (parent.type === AST_NODE_TYPES37.TSAsExpression || parent.type === AST_NODE_TYPES37.TSTypeAssertion || parent.type === AST_NODE_TYPES37.TSNonNullExpression || parent.type === AST_NODE_TYPES37.TSSatisfiesExpression || parent.type === AST_NODE_TYPES37.ChainExpression)) {
|
|
7264
7444
|
current = parent;
|
|
7265
7445
|
parent = parent.parent;
|
|
7266
7446
|
}
|
|
7267
7447
|
if (parent === null || parent === void 0) return false;
|
|
7268
|
-
if (parent.type ===
|
|
7448
|
+
if (parent.type === AST_NODE_TYPES37.UnaryExpression && parent.operator === "typeof" && parent.argument === current) {
|
|
7269
7449
|
return true;
|
|
7270
7450
|
}
|
|
7271
|
-
if (parent.type !==
|
|
7451
|
+
if (parent.type !== AST_NODE_TYPES37.CallExpression || !parent.arguments.some((arg) => arg === current)) {
|
|
7272
7452
|
return false;
|
|
7273
7453
|
}
|
|
7274
7454
|
const callee = parent.callee;
|
|
7275
|
-
if (callee.type ===
|
|
7455
|
+
if (callee.type === AST_NODE_TYPES37.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES37.Identifier && callee.object.name === "Array" && callee.property.type === AST_NODE_TYPES37.Identifier && callee.property.name === "isArray") {
|
|
7276
7456
|
return parent.arguments.length === 1;
|
|
7277
7457
|
}
|
|
7278
|
-
return callee.type ===
|
|
7458
|
+
return callee.type === AST_NODE_TYPES37.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
7279
7459
|
};
|
|
7280
7460
|
var isGuardTestPosition = (node) => {
|
|
7281
7461
|
let current = node;
|
|
7282
7462
|
let parent = current.parent;
|
|
7283
7463
|
while (parent !== void 0 && parent !== null) {
|
|
7284
7464
|
switch (parent.type) {
|
|
7285
|
-
case
|
|
7286
|
-
case
|
|
7287
|
-
case
|
|
7465
|
+
case AST_NODE_TYPES37.UnaryExpression:
|
|
7466
|
+
case AST_NODE_TYPES37.LogicalExpression:
|
|
7467
|
+
case AST_NODE_TYPES37.ChainExpression:
|
|
7288
7468
|
current = parent;
|
|
7289
7469
|
parent = parent.parent;
|
|
7290
7470
|
continue;
|
|
7291
|
-
case
|
|
7292
|
-
case
|
|
7293
|
-
case
|
|
7294
|
-
case
|
|
7295
|
-
case
|
|
7471
|
+
case AST_NODE_TYPES37.IfStatement:
|
|
7472
|
+
case AST_NODE_TYPES37.ConditionalExpression:
|
|
7473
|
+
case AST_NODE_TYPES37.WhileStatement:
|
|
7474
|
+
case AST_NODE_TYPES37.DoWhileStatement:
|
|
7475
|
+
case AST_NODE_TYPES37.ForStatement:
|
|
7296
7476
|
return parent.test === current;
|
|
7297
7477
|
default:
|
|
7298
7478
|
return false;
|
|
@@ -7302,7 +7482,7 @@ var isGuardTestPosition = (node) => {
|
|
|
7302
7482
|
};
|
|
7303
7483
|
var isUnvalidatedVariableRef = (node, scope, tracked) => {
|
|
7304
7484
|
const unwrapped = unwrap4(node);
|
|
7305
|
-
if (unwrapped === null || unwrapped.type !==
|
|
7485
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES37.Identifier) {
|
|
7306
7486
|
return false;
|
|
7307
7487
|
}
|
|
7308
7488
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -7345,11 +7525,11 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7345
7525
|
return {
|
|
7346
7526
|
VariableDeclarator(node) {
|
|
7347
7527
|
const scope = context.sourceCode.getScope(node);
|
|
7348
|
-
if (node.id.type ===
|
|
7528
|
+
if (node.id.type === AST_NODE_TYPES37.Identifier) {
|
|
7349
7529
|
trackInitializer(node);
|
|
7350
7530
|
return;
|
|
7351
7531
|
}
|
|
7352
|
-
if (node.id.type ===
|
|
7532
|
+
if (node.id.type === AST_NODE_TYPES37.ObjectPattern || node.id.type === AST_NODE_TYPES37.ArrayPattern) {
|
|
7353
7533
|
if (isRawPayloadSource(node.init)) {
|
|
7354
7534
|
if (!isFullyNarrowedPattern(node)) {
|
|
7355
7535
|
context.report({ node: node.id, messageId: "unparsedJsonAccess" });
|
|
@@ -7363,7 +7543,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7363
7543
|
},
|
|
7364
7544
|
AssignmentExpression(node) {
|
|
7365
7545
|
const scope = context.sourceCode.getScope(node);
|
|
7366
|
-
if (node.left.type ===
|
|
7546
|
+
if (node.left.type === AST_NODE_TYPES37.Identifier) {
|
|
7367
7547
|
const variable = findVariable2(scope, node.left.name);
|
|
7368
7548
|
if (variable === null) return;
|
|
7369
7549
|
if (isRawPayloadSource(node.right)) {
|
|
@@ -7373,7 +7553,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7373
7553
|
}
|
|
7374
7554
|
return;
|
|
7375
7555
|
}
|
|
7376
|
-
if (node.left.type ===
|
|
7556
|
+
if (node.left.type === AST_NODE_TYPES37.ObjectPattern || node.left.type === AST_NODE_TYPES37.ArrayPattern) {
|
|
7377
7557
|
if (isRawPayloadSource(node.right)) {
|
|
7378
7558
|
context.report({
|
|
7379
7559
|
node: node.left,
|
|
@@ -7390,15 +7570,15 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7390
7570
|
}
|
|
7391
7571
|
},
|
|
7392
7572
|
CallExpression(node) {
|
|
7393
|
-
if (node.callee.type !==
|
|
7573
|
+
if (node.callee.type !== AST_NODE_TYPES37.Identifier) return;
|
|
7394
7574
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
7395
7575
|
return;
|
|
7396
7576
|
}
|
|
7397
7577
|
const scope = context.sourceCode.getScope(node);
|
|
7398
7578
|
for (const arg of node.arguments) {
|
|
7399
|
-
if (arg.type ===
|
|
7579
|
+
if (arg.type === AST_NODE_TYPES37.SpreadElement) continue;
|
|
7400
7580
|
const unwrapped = unwrap4(arg);
|
|
7401
|
-
if (unwrapped === null || unwrapped.type !==
|
|
7581
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES37.Identifier) {
|
|
7402
7582
|
continue;
|
|
7403
7583
|
}
|
|
7404
7584
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -7412,13 +7592,13 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7412
7592
|
const obj = unwrap4(node.object);
|
|
7413
7593
|
if (isRawPayloadSource(obj)) {
|
|
7414
7594
|
const parent = node.parent;
|
|
7415
|
-
if (parent.type ===
|
|
7595
|
+
if (parent.type === AST_NODE_TYPES37.CallExpression && parent.callee === node && node.property.type === AST_NODE_TYPES37.Identifier && (node.property.name === "parse" || node.property.name === "safeParse" || PROMISE_CHAIN_METHODS.has(node.property.name))) {
|
|
7416
7596
|
return;
|
|
7417
7597
|
}
|
|
7418
7598
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
7419
7599
|
return;
|
|
7420
7600
|
}
|
|
7421
|
-
if (obj !== null && obj.type ===
|
|
7601
|
+
if (obj !== null && obj.type === AST_NODE_TYPES37.Identifier && isUnvalidatedVariableRef(obj, scope, unvalidatedVariables)) {
|
|
7422
7602
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
7423
7603
|
const variable = findVariable2(scope, obj.name);
|
|
7424
7604
|
if (variable !== null) {
|
|
@@ -7431,7 +7611,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7431
7611
|
});
|
|
7432
7612
|
|
|
7433
7613
|
// src/rules/prefer-semantic-colors.ts
|
|
7434
|
-
import { AST_NODE_TYPES as
|
|
7614
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES38 } from "@typescript-eslint/utils";
|
|
7435
7615
|
import { existsSync, readdirSync, readFileSync } from "fs";
|
|
7436
7616
|
import { dirname, join, parse } from "path";
|
|
7437
7617
|
|
|
@@ -7531,8 +7711,8 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
7531
7711
|
]);
|
|
7532
7712
|
function jsxElementName(node) {
|
|
7533
7713
|
const name = node.openingElement.name;
|
|
7534
|
-
if (name.type ===
|
|
7535
|
-
if (name.type ===
|
|
7714
|
+
if (name.type === AST_NODE_TYPES38.JSXIdentifier) return name.name;
|
|
7715
|
+
if (name.type === AST_NODE_TYPES38.JSXMemberExpression && name.property.type === AST_NODE_TYPES38.JSXIdentifier) {
|
|
7536
7716
|
return name.property.name;
|
|
7537
7717
|
}
|
|
7538
7718
|
return null;
|
|
@@ -7558,7 +7738,7 @@ var EMAIL_OR_PDF_MODULE_RE = /^@react-(?:email|pdf)\//;
|
|
|
7558
7738
|
var isInsideSvg = (node) => {
|
|
7559
7739
|
let current = node.parent;
|
|
7560
7740
|
while (current !== void 0 && current !== null) {
|
|
7561
|
-
if (current.type ===
|
|
7741
|
+
if (current.type === AST_NODE_TYPES38.JSXElement) {
|
|
7562
7742
|
const name = jsxElementName(current);
|
|
7563
7743
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
7564
7744
|
}
|
|
@@ -7569,7 +7749,7 @@ var isInsideSvg = (node) => {
|
|
|
7569
7749
|
var isInsideIconFactoryPath = (node) => {
|
|
7570
7750
|
let current = node.parent;
|
|
7571
7751
|
while (current !== void 0 && current !== null) {
|
|
7572
|
-
if (current.type ===
|
|
7752
|
+
if (current.type === AST_NODE_TYPES38.Property && propName(current.key) === "path" && current.parent.type === AST_NODE_TYPES38.ObjectExpression && current.parent.parent.type === AST_NODE_TYPES38.CallExpression && current.parent.parent.callee.type === AST_NODE_TYPES38.Identifier && current.parent.parent.callee.name === "createIcon") {
|
|
7573
7753
|
return true;
|
|
7574
7754
|
}
|
|
7575
7755
|
current = current.parent;
|
|
@@ -7706,12 +7886,12 @@ var hasSemanticTokenSystem = (filename) => {
|
|
|
7706
7886
|
return root !== null && workspaceHasMarker(root);
|
|
7707
7887
|
};
|
|
7708
7888
|
var propName = (key) => {
|
|
7709
|
-
if (key.type ===
|
|
7710
|
-
if (key.type ===
|
|
7889
|
+
if (key.type === AST_NODE_TYPES38.Identifier) return key.name;
|
|
7890
|
+
if (key.type === AST_NODE_TYPES38.Literal && typeof key.value === "string") return key.value;
|
|
7711
7891
|
return null;
|
|
7712
7892
|
};
|
|
7713
7893
|
var staticallyImportsEmailOrPdfRenderer = (program) => program.body.some((statement) => {
|
|
7714
|
-
if (statement.type !==
|
|
7894
|
+
if (statement.type !== AST_NODE_TYPES38.ImportDeclaration && statement.type !== AST_NODE_TYPES38.ExportNamedDeclaration && statement.type !== AST_NODE_TYPES38.ExportAllDeclaration) {
|
|
7715
7895
|
return false;
|
|
7716
7896
|
}
|
|
7717
7897
|
return statement.source !== null && typeof statement.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(statement.source.value);
|
|
@@ -7763,27 +7943,27 @@ var prefer_semantic_colors_default = createRule({
|
|
|
7763
7943
|
const checkClassNode = (node) => {
|
|
7764
7944
|
if (node === null) return;
|
|
7765
7945
|
switch (node.type) {
|
|
7766
|
-
case
|
|
7946
|
+
case AST_NODE_TYPES38.Literal:
|
|
7767
7947
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
7768
7948
|
break;
|
|
7769
|
-
case
|
|
7949
|
+
case AST_NODE_TYPES38.TemplateLiteral:
|
|
7770
7950
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
7771
7951
|
break;
|
|
7772
|
-
case
|
|
7952
|
+
case AST_NODE_TYPES38.ArrayExpression:
|
|
7773
7953
|
for (const element of node.elements) {
|
|
7774
|
-
if (element !== null && element.type !==
|
|
7954
|
+
if (element !== null && element.type !== AST_NODE_TYPES38.SpreadElement) checkClassNode(element);
|
|
7775
7955
|
}
|
|
7776
7956
|
break;
|
|
7777
|
-
case
|
|
7957
|
+
case AST_NODE_TYPES38.ObjectExpression:
|
|
7778
7958
|
for (const property of node.properties) {
|
|
7779
|
-
if (property.type ===
|
|
7959
|
+
if (property.type === AST_NODE_TYPES38.Property) checkClassNode(property.value);
|
|
7780
7960
|
}
|
|
7781
7961
|
break;
|
|
7782
|
-
case
|
|
7962
|
+
case AST_NODE_TYPES38.ConditionalExpression:
|
|
7783
7963
|
checkClassNode(node.consequent);
|
|
7784
7964
|
checkClassNode(node.alternate);
|
|
7785
7965
|
break;
|
|
7786
|
-
case
|
|
7966
|
+
case AST_NODE_TYPES38.LogicalExpression:
|
|
7787
7967
|
checkClassNode(node.right);
|
|
7788
7968
|
break;
|
|
7789
7969
|
default:
|
|
@@ -7791,32 +7971,32 @@ var prefer_semantic_colors_default = createRule({
|
|
|
7791
7971
|
}
|
|
7792
7972
|
};
|
|
7793
7973
|
const checkColorValueNode = (node) => {
|
|
7794
|
-
if (node.type ===
|
|
7974
|
+
if (node.type === AST_NODE_TYPES38.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value) && !CSS_VAR_REFERENCE_RE.test(node.value)) {
|
|
7795
7975
|
report(node, "inlineColor", { value: node.value });
|
|
7796
7976
|
}
|
|
7797
7977
|
};
|
|
7798
7978
|
return {
|
|
7799
7979
|
"JSXAttribute[name.name='className']"(node) {
|
|
7800
7980
|
if (node.value === null) return;
|
|
7801
|
-
if (node.value.type ===
|
|
7802
|
-
else if (node.value.type ===
|
|
7803
|
-
if (node.value.expression.type !==
|
|
7981
|
+
if (node.value.type === AST_NODE_TYPES38.Literal) checkClassNode(node.value);
|
|
7982
|
+
else if (node.value.type === AST_NODE_TYPES38.JSXExpressionContainer) {
|
|
7983
|
+
if (node.value.expression.type !== AST_NODE_TYPES38.JSXEmptyExpression) {
|
|
7804
7984
|
checkClassNode(node.value.expression);
|
|
7805
7985
|
}
|
|
7806
7986
|
}
|
|
7807
7987
|
},
|
|
7808
7988
|
CallExpression(node) {
|
|
7809
|
-
if (node.callee.type ===
|
|
7989
|
+
if (node.callee.type === AST_NODE_TYPES38.Identifier && node.callee.name === "require" && node.arguments[0]?.type === AST_NODE_TYPES38.Literal && typeof node.arguments[0].value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.arguments[0].value)) {
|
|
7810
7990
|
importsEmailOrPdfRenderer = true;
|
|
7811
7991
|
}
|
|
7812
|
-
if (node.callee.type ===
|
|
7992
|
+
if (node.callee.type === AST_NODE_TYPES38.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
7813
7993
|
for (const arg of node.arguments) {
|
|
7814
|
-
if (arg.type !==
|
|
7994
|
+
if (arg.type !== AST_NODE_TYPES38.SpreadElement) checkClassNode(arg);
|
|
7815
7995
|
}
|
|
7816
7996
|
}
|
|
7817
7997
|
},
|
|
7818
7998
|
VariableDeclarator(node) {
|
|
7819
|
-
if (node.id.type ===
|
|
7999
|
+
if (node.id.type === AST_NODE_TYPES38.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
7820
8000
|
checkClassNode(node.init);
|
|
7821
8001
|
}
|
|
7822
8002
|
},
|
|
@@ -7826,9 +8006,9 @@ var prefer_semantic_colors_default = createRule({
|
|
|
7826
8006
|
},
|
|
7827
8007
|
// SVG artwork colors are exempt; component presentation colors still report.
|
|
7828
8008
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
7829
|
-
if (node.value?.type !==
|
|
8009
|
+
if (node.value?.type !== AST_NODE_TYPES38.Literal) return;
|
|
7830
8010
|
const owner = node.parent.name;
|
|
7831
|
-
if (owner.type ===
|
|
8011
|
+
if (owner.type === AST_NODE_TYPES38.JSXIdentifier && SVG_SHAPE_PRIMITIVES.has(owner.name)) {
|
|
7832
8012
|
return;
|
|
7833
8013
|
}
|
|
7834
8014
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
@@ -7842,7 +8022,7 @@ var prefer_semantic_colors_default = createRule({
|
|
|
7842
8022
|
if (name !== null && STYLE_COLOR_PROPS.has(name)) checkColorValueNode(node.value);
|
|
7843
8023
|
},
|
|
7844
8024
|
ImportExpression(node) {
|
|
7845
|
-
if (node.source.type ===
|
|
8025
|
+
if (node.source.type === AST_NODE_TYPES38.Literal && typeof node.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.source.value)) {
|
|
7846
8026
|
importsEmailOrPdfRenderer = true;
|
|
7847
8027
|
}
|
|
7848
8028
|
},
|
|
@@ -8048,7 +8228,7 @@ var prefer_single_sentence_comment_default = createRule({
|
|
|
8048
8228
|
// src/rules/prefer-string-literal-union.ts
|
|
8049
8229
|
import {
|
|
8050
8230
|
ESLintUtils as ESLintUtils3,
|
|
8051
|
-
AST_NODE_TYPES as
|
|
8231
|
+
AST_NODE_TYPES as AST_NODE_TYPES39
|
|
8052
8232
|
} from "@typescript-eslint/utils";
|
|
8053
8233
|
import * as ts2 from "typescript";
|
|
8054
8234
|
var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
@@ -8092,19 +8272,19 @@ function isChoiceLikeName(name) {
|
|
|
8092
8272
|
return CHOICE_TOKENS.has(lastWord(name));
|
|
8093
8273
|
}
|
|
8094
8274
|
function keyName(key) {
|
|
8095
|
-
if (key.type ===
|
|
8275
|
+
if (key.type === AST_NODE_TYPES39.Identifier) {
|
|
8096
8276
|
return key.name;
|
|
8097
8277
|
}
|
|
8098
|
-
if (key.type ===
|
|
8278
|
+
if (key.type === AST_NODE_TYPES39.Literal && typeof key.value === "string") {
|
|
8099
8279
|
return key.value;
|
|
8100
8280
|
}
|
|
8101
8281
|
return null;
|
|
8102
8282
|
}
|
|
8103
8283
|
function isStringLiteralMember(t) {
|
|
8104
|
-
return t.type ===
|
|
8284
|
+
return t.type === AST_NODE_TYPES39.TSLiteralType && t.literal.type === AST_NODE_TYPES39.Literal && typeof t.literal.value === "string";
|
|
8105
8285
|
}
|
|
8106
8286
|
function isStringLiteralUnion(node) {
|
|
8107
|
-
if (node?.type !==
|
|
8287
|
+
if (node?.type !== AST_NODE_TYPES39.TSUnionType) {
|
|
8108
8288
|
return false;
|
|
8109
8289
|
}
|
|
8110
8290
|
return node.types.filter(isStringLiteralMember).length >= MIN_CLUSTER_SIZE;
|
|
@@ -8133,12 +8313,12 @@ function bindingSourceExpression(decl) {
|
|
|
8133
8313
|
return ts2.isForOfStatement(node) ? node.expression : node.initializer;
|
|
8134
8314
|
}
|
|
8135
8315
|
function refKey(node) {
|
|
8136
|
-
if (node.type ===
|
|
8316
|
+
if (node.type === AST_NODE_TYPES39.Identifier) {
|
|
8137
8317
|
return node.name;
|
|
8138
8318
|
}
|
|
8139
|
-
if (node.type ===
|
|
8319
|
+
if (node.type === AST_NODE_TYPES39.MemberExpression && !node.computed) {
|
|
8140
8320
|
const inner = refKey(node.object);
|
|
8141
|
-
if (inner === null || node.property.type !==
|
|
8321
|
+
if (inner === null || node.property.type !== AST_NODE_TYPES39.Identifier) {
|
|
8142
8322
|
return null;
|
|
8143
8323
|
}
|
|
8144
8324
|
return `${inner}.${node.property.name}`;
|
|
@@ -8146,7 +8326,7 @@ function refKey(node) {
|
|
|
8146
8326
|
return null;
|
|
8147
8327
|
}
|
|
8148
8328
|
function strLiteral(node) {
|
|
8149
|
-
if (node.type ===
|
|
8329
|
+
if (node.type === AST_NODE_TYPES39.Literal && typeof node.value === "string") {
|
|
8150
8330
|
return node.value;
|
|
8151
8331
|
}
|
|
8152
8332
|
return null;
|
|
@@ -8299,7 +8479,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
8299
8479
|
containersWithUnion.add(container);
|
|
8300
8480
|
return;
|
|
8301
8481
|
}
|
|
8302
|
-
if (typeNode?.type !==
|
|
8482
|
+
if (typeNode?.type !== AST_NODE_TYPES39.TSStringKeyword) {
|
|
8303
8483
|
return;
|
|
8304
8484
|
}
|
|
8305
8485
|
const name = keyName(key);
|
|
@@ -8387,10 +8567,10 @@ var prefer_string_literal_union_default = createRule({
|
|
|
8387
8567
|
}
|
|
8388
8568
|
};
|
|
8389
8569
|
function refKeyText(node) {
|
|
8390
|
-
if (node.type ===
|
|
8570
|
+
if (node.type === AST_NODE_TYPES39.BinaryExpression) {
|
|
8391
8571
|
return refKey(node.left) ?? refKey(node.right) ?? "value";
|
|
8392
8572
|
}
|
|
8393
|
-
if (node.type ===
|
|
8573
|
+
if (node.type === AST_NODE_TYPES39.SwitchStatement) {
|
|
8394
8574
|
return refKey(node.discriminant) ?? "value";
|
|
8395
8575
|
}
|
|
8396
8576
|
return "value";
|
|
@@ -8399,7 +8579,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
8399
8579
|
});
|
|
8400
8580
|
|
|
8401
8581
|
// src/rules/prefer-whole-object-assertion.ts
|
|
8402
|
-
import { AST_NODE_TYPES as
|
|
8582
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES40 } from "@typescript-eslint/utils";
|
|
8403
8583
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
8404
8584
|
var ARRAY_MATCHERS = /* @__PURE__ */ new Set(["toEqual", "toStrictEqual"]);
|
|
8405
8585
|
var COLLECTION_PROPERTIES = /* @__PURE__ */ new Set(["length", "size"]);
|
|
@@ -8408,11 +8588,11 @@ var NUMERIC_SIGNS2 = /* @__PURE__ */ new Set(["-", "+"]);
|
|
|
8408
8588
|
var MIN_RUN_LENGTH = 2;
|
|
8409
8589
|
function literalText(node, getText) {
|
|
8410
8590
|
switch (node.type) {
|
|
8411
|
-
case
|
|
8591
|
+
case AST_NODE_TYPES40.Literal:
|
|
8412
8592
|
return "regex" in node ? null : getText(node);
|
|
8413
|
-
case
|
|
8593
|
+
case AST_NODE_TYPES40.TemplateLiteral:
|
|
8414
8594
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
8415
|
-
case
|
|
8595
|
+
case AST_NODE_TYPES40.UnaryExpression:
|
|
8416
8596
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
8417
8597
|
default:
|
|
8418
8598
|
return null;
|
|
@@ -8420,15 +8600,15 @@ function literalText(node, getText) {
|
|
|
8420
8600
|
}
|
|
8421
8601
|
function isPureReceiver(node) {
|
|
8422
8602
|
switch (node.type) {
|
|
8423
|
-
case
|
|
8424
|
-
case
|
|
8603
|
+
case AST_NODE_TYPES40.Identifier:
|
|
8604
|
+
case AST_NODE_TYPES40.ThisExpression:
|
|
8425
8605
|
return true;
|
|
8426
|
-
case
|
|
8606
|
+
case AST_NODE_TYPES40.MemberExpression:
|
|
8427
8607
|
if (node.optional) {
|
|
8428
8608
|
return false;
|
|
8429
8609
|
}
|
|
8430
8610
|
if (node.computed) {
|
|
8431
|
-
return node.property.type ===
|
|
8611
|
+
return node.property.type === AST_NODE_TYPES40.Literal && isPureReceiver(node.object);
|
|
8432
8612
|
}
|
|
8433
8613
|
return isPureReceiver(node.object);
|
|
8434
8614
|
default:
|
|
@@ -8436,7 +8616,7 @@ function isPureReceiver(node) {
|
|
|
8436
8616
|
}
|
|
8437
8617
|
}
|
|
8438
8618
|
function literalIndex(node) {
|
|
8439
|
-
if (node.type !==
|
|
8619
|
+
if (node.type !== AST_NODE_TYPES40.Literal || typeof node.value !== "number") {
|
|
8440
8620
|
return null;
|
|
8441
8621
|
}
|
|
8442
8622
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
@@ -8462,24 +8642,24 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8462
8642
|
}
|
|
8463
8643
|
const { sourceCode } = context;
|
|
8464
8644
|
function parseAssertion(statement) {
|
|
8465
|
-
if (statement.type !==
|
|
8645
|
+
if (statement.type !== AST_NODE_TYPES40.ExpressionStatement) {
|
|
8466
8646
|
return null;
|
|
8467
8647
|
}
|
|
8468
8648
|
const call = statement.expression;
|
|
8469
|
-
if (call.type !==
|
|
8649
|
+
if (call.type !== AST_NODE_TYPES40.CallExpression) {
|
|
8470
8650
|
return null;
|
|
8471
8651
|
}
|
|
8472
8652
|
const callee = call.callee;
|
|
8473
|
-
if (callee.type !==
|
|
8653
|
+
if (callee.type !== AST_NODE_TYPES40.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES40.Identifier) {
|
|
8474
8654
|
return null;
|
|
8475
8655
|
}
|
|
8476
8656
|
const matcher = callee.property.name;
|
|
8477
8657
|
const expectCall = callee.object;
|
|
8478
|
-
if (expectCall.type !==
|
|
8658
|
+
if (expectCall.type !== AST_NODE_TYPES40.CallExpression || expectCall.callee.type !== AST_NODE_TYPES40.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
8479
8659
|
return null;
|
|
8480
8660
|
}
|
|
8481
8661
|
const actual = expectCall.arguments[0];
|
|
8482
|
-
if (actual === void 0 || actual.type !==
|
|
8662
|
+
if (actual === void 0 || actual.type !== AST_NODE_TYPES40.MemberExpression || actual.optional) {
|
|
8483
8663
|
return null;
|
|
8484
8664
|
}
|
|
8485
8665
|
if (!isPureReceiver(actual.object)) {
|
|
@@ -8493,7 +8673,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8493
8673
|
}
|
|
8494
8674
|
key = { kind: "index", index };
|
|
8495
8675
|
} else {
|
|
8496
|
-
if (actual.property.type !==
|
|
8676
|
+
if (actual.property.type !== AST_NODE_TYPES40.Identifier || COLLECTION_PROPERTIES.has(actual.property.name) || LITERAL_KEY_HAZARDS.has(actual.property.name)) {
|
|
8497
8677
|
return null;
|
|
8498
8678
|
}
|
|
8499
8679
|
key = { kind: "property", name: actual.property.name };
|
|
@@ -8505,7 +8685,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8505
8685
|
return null;
|
|
8506
8686
|
}
|
|
8507
8687
|
const expected = call.arguments[0];
|
|
8508
|
-
if (call.arguments.length !== 1 || expected === void 0 || expected.type ===
|
|
8688
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === AST_NODE_TYPES40.SpreadElement) {
|
|
8509
8689
|
return null;
|
|
8510
8690
|
}
|
|
8511
8691
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
@@ -8620,7 +8800,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8620
8800
|
});
|
|
8621
8801
|
|
|
8622
8802
|
// src/rules/prefer-zod-enum.ts
|
|
8623
|
-
import { AST_NODE_TYPES as
|
|
8803
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES41 } from "@typescript-eslint/utils";
|
|
8624
8804
|
var prefer_zod_enum_default = createRule({
|
|
8625
8805
|
name: "prefer-zod-enum",
|
|
8626
8806
|
meta: {
|
|
@@ -8640,25 +8820,25 @@ var prefer_zod_enum_default = createRule({
|
|
|
8640
8820
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
8641
8821
|
function enumValues(node) {
|
|
8642
8822
|
const callee = node.callee;
|
|
8643
|
-
if (callee.type !==
|
|
8823
|
+
if (callee.type !== AST_NODE_TYPES41.MemberExpression || callee.computed || callee.object.type !== AST_NODE_TYPES41.Identifier || !zodNamespaces.has(callee.object.name) || callee.property.type !== AST_NODE_TYPES41.Identifier || callee.property.name !== "union" || node.arguments.length !== 1) {
|
|
8644
8824
|
return null;
|
|
8645
8825
|
}
|
|
8646
8826
|
const argument = node.arguments[0];
|
|
8647
|
-
if (argument === void 0 || argument.type !==
|
|
8827
|
+
if (argument === void 0 || argument.type !== AST_NODE_TYPES41.ArrayExpression || argument.elements.length === 0) {
|
|
8648
8828
|
return null;
|
|
8649
8829
|
}
|
|
8650
8830
|
const values = [];
|
|
8651
8831
|
let canFix = true;
|
|
8652
8832
|
for (const element of argument.elements) {
|
|
8653
|
-
if (element?.type ===
|
|
8833
|
+
if (element?.type === AST_NODE_TYPES41.SpreadElement) {
|
|
8654
8834
|
canFix = false;
|
|
8655
8835
|
continue;
|
|
8656
8836
|
}
|
|
8657
|
-
if (element === null || element.type !==
|
|
8837
|
+
if (element === null || element.type !== AST_NODE_TYPES41.CallExpression || element.callee.type !== AST_NODE_TYPES41.MemberExpression || element.callee.computed || element.callee.object.type !== AST_NODE_TYPES41.Identifier || !zodNamespaces.has(element.callee.object.name) || element.callee.property.type !== AST_NODE_TYPES41.Identifier || element.callee.property.name !== "literal") {
|
|
8658
8838
|
return null;
|
|
8659
8839
|
}
|
|
8660
8840
|
const value = element.arguments[0];
|
|
8661
|
-
if (element.arguments.length !== 1 || value === void 0 || value.type !==
|
|
8841
|
+
if (element.arguments.length !== 1 || value === void 0 || value.type !== AST_NODE_TYPES41.Literal || typeof value.value !== "string") {
|
|
8662
8842
|
canFix = false;
|
|
8663
8843
|
continue;
|
|
8664
8844
|
}
|
|
@@ -8668,11 +8848,11 @@ var prefer_zod_enum_default = createRule({
|
|
|
8668
8848
|
}
|
|
8669
8849
|
function buildFix(node, values) {
|
|
8670
8850
|
const argument = node.arguments[0];
|
|
8671
|
-
if (argument === void 0 || argument.type !==
|
|
8851
|
+
if (argument === void 0 || argument.type !== AST_NODE_TYPES41.ArrayExpression || sourceCode.getCommentsInside(argument).length > 0) {
|
|
8672
8852
|
return void 0;
|
|
8673
8853
|
}
|
|
8674
8854
|
const callee = node.callee;
|
|
8675
|
-
if (callee.type !==
|
|
8855
|
+
if (callee.type !== AST_NODE_TYPES41.MemberExpression || callee.property.type !== AST_NODE_TYPES41.Identifier) {
|
|
8676
8856
|
return void 0;
|
|
8677
8857
|
}
|
|
8678
8858
|
return (fixer) => [
|
|
@@ -8689,7 +8869,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
8689
8869
|
return;
|
|
8690
8870
|
}
|
|
8691
8871
|
for (const specifier of node.specifiers) {
|
|
8692
|
-
if (specifier.type ===
|
|
8872
|
+
if (specifier.type === AST_NODE_TYPES41.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES41.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES41.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES41.Identifier && specifier.imported.name === "z") {
|
|
8693
8873
|
zodNamespaces.add(specifier.local.name);
|
|
8694
8874
|
}
|
|
8695
8875
|
}
|
|
@@ -8711,7 +8891,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
8711
8891
|
});
|
|
8712
8892
|
|
|
8713
8893
|
// src/rules/prefer-zod-infer.ts
|
|
8714
|
-
import { AST_NODE_TYPES as
|
|
8894
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES42 } from "@typescript-eslint/utils";
|
|
8715
8895
|
var SHAPE_PRESERVING_METHODS = /* @__PURE__ */ new Set([
|
|
8716
8896
|
"describe",
|
|
8717
8897
|
"refine",
|
|
@@ -8748,44 +8928,44 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
8748
8928
|
"Schema"
|
|
8749
8929
|
]);
|
|
8750
8930
|
var LEAF_NODE_TYPES = {
|
|
8751
|
-
string: [
|
|
8752
|
-
email: [
|
|
8753
|
-
url: [
|
|
8754
|
-
uuid: [
|
|
8755
|
-
ulid: [
|
|
8756
|
-
cuid: [
|
|
8757
|
-
cuid2: [
|
|
8758
|
-
nanoid: [
|
|
8759
|
-
iso: [
|
|
8760
|
-
number: [
|
|
8761
|
-
int: [
|
|
8762
|
-
float32: [
|
|
8763
|
-
float64: [
|
|
8764
|
-
boolean: [
|
|
8765
|
-
bigint: [
|
|
8766
|
-
symbol: [
|
|
8767
|
-
any: [
|
|
8768
|
-
unknown: [
|
|
8769
|
-
never: [
|
|
8770
|
-
void: [
|
|
8771
|
-
null: [
|
|
8772
|
-
undefined: [
|
|
8773
|
-
literal: [
|
|
8774
|
-
date: [
|
|
8775
|
-
array: [
|
|
8776
|
-
tuple: [
|
|
8777
|
-
object: [
|
|
8778
|
-
strictObject: [
|
|
8779
|
-
looseObject: [
|
|
8780
|
-
record: [
|
|
8781
|
-
map: [
|
|
8782
|
-
set: [
|
|
8783
|
-
promise: [
|
|
8784
|
-
enum: [
|
|
8785
|
-
nativeEnum: [
|
|
8786
|
-
union: [
|
|
8787
|
-
discriminatedUnion: [
|
|
8788
|
-
intersection: [
|
|
8931
|
+
string: [AST_NODE_TYPES42.TSStringKeyword],
|
|
8932
|
+
email: [AST_NODE_TYPES42.TSStringKeyword],
|
|
8933
|
+
url: [AST_NODE_TYPES42.TSStringKeyword],
|
|
8934
|
+
uuid: [AST_NODE_TYPES42.TSStringKeyword],
|
|
8935
|
+
ulid: [AST_NODE_TYPES42.TSStringKeyword],
|
|
8936
|
+
cuid: [AST_NODE_TYPES42.TSStringKeyword],
|
|
8937
|
+
cuid2: [AST_NODE_TYPES42.TSStringKeyword],
|
|
8938
|
+
nanoid: [AST_NODE_TYPES42.TSStringKeyword],
|
|
8939
|
+
iso: [AST_NODE_TYPES42.TSStringKeyword],
|
|
8940
|
+
number: [AST_NODE_TYPES42.TSNumberKeyword],
|
|
8941
|
+
int: [AST_NODE_TYPES42.TSNumberKeyword],
|
|
8942
|
+
float32: [AST_NODE_TYPES42.TSNumberKeyword],
|
|
8943
|
+
float64: [AST_NODE_TYPES42.TSNumberKeyword],
|
|
8944
|
+
boolean: [AST_NODE_TYPES42.TSBooleanKeyword],
|
|
8945
|
+
bigint: [AST_NODE_TYPES42.TSBigIntKeyword],
|
|
8946
|
+
symbol: [AST_NODE_TYPES42.TSSymbolKeyword],
|
|
8947
|
+
any: [AST_NODE_TYPES42.TSAnyKeyword],
|
|
8948
|
+
unknown: [AST_NODE_TYPES42.TSUnknownKeyword],
|
|
8949
|
+
never: [AST_NODE_TYPES42.TSNeverKeyword],
|
|
8950
|
+
void: [AST_NODE_TYPES42.TSVoidKeyword],
|
|
8951
|
+
null: [AST_NODE_TYPES42.TSNullKeyword],
|
|
8952
|
+
undefined: [AST_NODE_TYPES42.TSUndefinedKeyword],
|
|
8953
|
+
literal: [AST_NODE_TYPES42.TSLiteralType],
|
|
8954
|
+
date: [AST_NODE_TYPES42.TSTypeReference],
|
|
8955
|
+
array: [AST_NODE_TYPES42.TSArrayType, AST_NODE_TYPES42.TSTypeReference],
|
|
8956
|
+
tuple: [AST_NODE_TYPES42.TSTupleType],
|
|
8957
|
+
object: [AST_NODE_TYPES42.TSTypeLiteral, AST_NODE_TYPES42.TSTypeReference],
|
|
8958
|
+
strictObject: [AST_NODE_TYPES42.TSTypeLiteral, AST_NODE_TYPES42.TSTypeReference],
|
|
8959
|
+
looseObject: [AST_NODE_TYPES42.TSTypeLiteral, AST_NODE_TYPES42.TSTypeReference],
|
|
8960
|
+
record: [AST_NODE_TYPES42.TSTypeReference, AST_NODE_TYPES42.TSTypeLiteral],
|
|
8961
|
+
map: [AST_NODE_TYPES42.TSTypeReference],
|
|
8962
|
+
set: [AST_NODE_TYPES42.TSTypeReference],
|
|
8963
|
+
promise: [AST_NODE_TYPES42.TSTypeReference],
|
|
8964
|
+
enum: [AST_NODE_TYPES42.TSUnionType, AST_NODE_TYPES42.TSTypeReference, AST_NODE_TYPES42.TSLiteralType],
|
|
8965
|
+
nativeEnum: [AST_NODE_TYPES42.TSUnionType, AST_NODE_TYPES42.TSTypeReference, AST_NODE_TYPES42.TSLiteralType],
|
|
8966
|
+
union: [AST_NODE_TYPES42.TSUnionType, AST_NODE_TYPES42.TSTypeReference],
|
|
8967
|
+
discriminatedUnion: [AST_NODE_TYPES42.TSUnionType, AST_NODE_TYPES42.TSTypeReference],
|
|
8968
|
+
intersection: [AST_NODE_TYPES42.TSIntersectionType, AST_NODE_TYPES42.TSTypeReference]
|
|
8789
8969
|
};
|
|
8790
8970
|
function normalizeSchemaName(name) {
|
|
8791
8971
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -8794,20 +8974,20 @@ function normalizeTypeName(name) {
|
|
|
8794
8974
|
return name.replace(/Type$/, "").toLowerCase();
|
|
8795
8975
|
}
|
|
8796
8976
|
function unwrapNullish(annotation) {
|
|
8797
|
-
if (annotation.type !==
|
|
8977
|
+
if (annotation.type !== AST_NODE_TYPES42.TSUnionType) {
|
|
8798
8978
|
return {
|
|
8799
8979
|
core: annotation,
|
|
8800
|
-
nullable: annotation.type ===
|
|
8980
|
+
nullable: annotation.type === AST_NODE_TYPES42.TSNullKeyword
|
|
8801
8981
|
};
|
|
8802
8982
|
}
|
|
8803
8983
|
const rest = [];
|
|
8804
8984
|
let nullable = false;
|
|
8805
8985
|
for (const member of annotation.types) {
|
|
8806
|
-
if (member.type ===
|
|
8986
|
+
if (member.type === AST_NODE_TYPES42.TSNullKeyword) {
|
|
8807
8987
|
nullable = true;
|
|
8808
8988
|
continue;
|
|
8809
8989
|
}
|
|
8810
|
-
if (member.type ===
|
|
8990
|
+
if (member.type === AST_NODE_TYPES42.TSUndefinedKeyword) {
|
|
8811
8991
|
continue;
|
|
8812
8992
|
}
|
|
8813
8993
|
rest.push(member);
|
|
@@ -8872,14 +9052,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
8872
9052
|
function zodCallChain(node) {
|
|
8873
9053
|
const chain = [];
|
|
8874
9054
|
let current = node;
|
|
8875
|
-
while (current.type ===
|
|
9055
|
+
while (current.type === AST_NODE_TYPES42.CallExpression) {
|
|
8876
9056
|
const callee = current.callee;
|
|
8877
|
-
if (callee.type !==
|
|
9057
|
+
if (callee.type !== AST_NODE_TYPES42.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES42.Identifier) {
|
|
8878
9058
|
return null;
|
|
8879
9059
|
}
|
|
8880
9060
|
chain.push(current);
|
|
8881
9061
|
const receiver = callee.object;
|
|
8882
|
-
if (receiver.type ===
|
|
9062
|
+
if (receiver.type === AST_NODE_TYPES42.Identifier) {
|
|
8883
9063
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
8884
9064
|
}
|
|
8885
9065
|
current = receiver;
|
|
@@ -8888,19 +9068,19 @@ var prefer_zod_infer_default = createRule({
|
|
|
8888
9068
|
}
|
|
8889
9069
|
function methodName(call) {
|
|
8890
9070
|
const callee = call.callee;
|
|
8891
|
-
return callee.type ===
|
|
9071
|
+
return callee.type === AST_NODE_TYPES42.MemberExpression && callee.property.type === AST_NODE_TYPES42.Identifier ? callee.property.name : "";
|
|
8892
9072
|
}
|
|
8893
9073
|
function schemaField(node) {
|
|
8894
9074
|
const modifiers = [];
|
|
8895
9075
|
let current = node;
|
|
8896
9076
|
let leaf = null;
|
|
8897
|
-
while (current.type ===
|
|
9077
|
+
while (current.type === AST_NODE_TYPES42.CallExpression) {
|
|
8898
9078
|
const callee = current.callee;
|
|
8899
|
-
if (callee.type !==
|
|
9079
|
+
if (callee.type !== AST_NODE_TYPES42.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES42.Identifier) {
|
|
8900
9080
|
break;
|
|
8901
9081
|
}
|
|
8902
9082
|
const receiver = callee.object;
|
|
8903
|
-
if (receiver.type ===
|
|
9083
|
+
if (receiver.type === AST_NODE_TYPES42.Identifier && zodNamespaces.has(receiver.name)) {
|
|
8904
9084
|
leaf = callee.property.name;
|
|
8905
9085
|
break;
|
|
8906
9086
|
}
|
|
@@ -8931,16 +9111,16 @@ var prefer_zod_infer_default = createRule({
|
|
|
8931
9111
|
return null;
|
|
8932
9112
|
}
|
|
8933
9113
|
const shape = base.arguments[0];
|
|
8934
|
-
if (shape === void 0 || shape.type !==
|
|
9114
|
+
if (shape === void 0 || shape.type !== AST_NODE_TYPES42.ObjectExpression) {
|
|
8935
9115
|
return null;
|
|
8936
9116
|
}
|
|
8937
9117
|
const fields = /* @__PURE__ */ new Map();
|
|
8938
9118
|
for (const property of shape.properties) {
|
|
8939
|
-
if (property.type !==
|
|
9119
|
+
if (property.type !== AST_NODE_TYPES42.Property || property.computed) {
|
|
8940
9120
|
return null;
|
|
8941
9121
|
}
|
|
8942
9122
|
const { key } = property;
|
|
8943
|
-
const name = key.type ===
|
|
9123
|
+
const name = key.type === AST_NODE_TYPES42.Identifier ? key.name : key.type === AST_NODE_TYPES42.Literal && typeof key.value === "string" ? key.value : null;
|
|
8944
9124
|
if (name === null) {
|
|
8945
9125
|
return null;
|
|
8946
9126
|
}
|
|
@@ -8951,11 +9131,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
8951
9131
|
function typeMembers(members) {
|
|
8952
9132
|
const result = /* @__PURE__ */ new Map();
|
|
8953
9133
|
for (const member of members) {
|
|
8954
|
-
if (member.type !==
|
|
9134
|
+
if (member.type !== AST_NODE_TYPES42.TSPropertySignature || member.computed) {
|
|
8955
9135
|
return null;
|
|
8956
9136
|
}
|
|
8957
9137
|
const { key } = member;
|
|
8958
|
-
const name = key.type ===
|
|
9138
|
+
const name = key.type === AST_NODE_TYPES42.Identifier ? key.name : key.type === AST_NODE_TYPES42.Literal && typeof key.value === "string" ? key.value : null;
|
|
8959
9139
|
if (name === null) {
|
|
8960
9140
|
return null;
|
|
8961
9141
|
}
|
|
@@ -8969,8 +9149,8 @@ var prefer_zod_infer_default = createRule({
|
|
|
8969
9149
|
return result.size === 0 ? null : result;
|
|
8970
9150
|
}
|
|
8971
9151
|
function collectConstrainedNames(node) {
|
|
8972
|
-
if (node.type ===
|
|
8973
|
-
if (node.typeName.type ===
|
|
9152
|
+
if (node.type === AST_NODE_TYPES42.TSTypeReference) {
|
|
9153
|
+
if (node.typeName.type === AST_NODE_TYPES42.Identifier) {
|
|
8974
9154
|
constrainedTypeNames.add(node.typeName.name);
|
|
8975
9155
|
}
|
|
8976
9156
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -8978,11 +9158,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
8978
9158
|
}
|
|
8979
9159
|
return;
|
|
8980
9160
|
}
|
|
8981
|
-
if (node.type ===
|
|
9161
|
+
if (node.type === AST_NODE_TYPES42.TSArrayType) {
|
|
8982
9162
|
collectConstrainedNames(node.elementType);
|
|
8983
9163
|
return;
|
|
8984
9164
|
}
|
|
8985
|
-
if (node.type ===
|
|
9165
|
+
if (node.type === AST_NODE_TYPES42.TSUnionType || node.type === AST_NODE_TYPES42.TSIntersectionType) {
|
|
8986
9166
|
for (const member of node.types) {
|
|
8987
9167
|
collectConstrainedNames(member);
|
|
8988
9168
|
}
|
|
@@ -9026,13 +9206,13 @@ var prefer_zod_infer_default = createRule({
|
|
|
9026
9206
|
return;
|
|
9027
9207
|
}
|
|
9028
9208
|
for (const specifier of node.specifiers) {
|
|
9029
|
-
if (specifier.type ===
|
|
9209
|
+
if (specifier.type === AST_NODE_TYPES42.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES42.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES42.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES42.Identifier && specifier.imported.name === "z") {
|
|
9030
9210
|
zodNamespaces.add(specifier.local.name);
|
|
9031
9211
|
}
|
|
9032
9212
|
}
|
|
9033
9213
|
},
|
|
9034
9214
|
VariableDeclarator(node) {
|
|
9035
|
-
if (node.id.type !==
|
|
9215
|
+
if (node.id.type !== AST_NODE_TYPES42.Identifier || node.init == null) {
|
|
9036
9216
|
return;
|
|
9037
9217
|
}
|
|
9038
9218
|
const fields = schemaFields(node.init);
|
|
@@ -9042,14 +9222,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
9042
9222
|
},
|
|
9043
9223
|
/** Records `XSchema.transform(...)` and equivalent module-level reshaping. */
|
|
9044
9224
|
"MemberExpression[computed=false]"(node) {
|
|
9045
|
-
if (node.object.type ===
|
|
9225
|
+
if (node.object.type === AST_NODE_TYPES42.Identifier && node.property.type === AST_NODE_TYPES42.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
9046
9226
|
reshapedSchemaNames.add(node.object.name);
|
|
9047
9227
|
}
|
|
9048
9228
|
},
|
|
9049
9229
|
/** Records every type argument carried by a Zod constraint. */
|
|
9050
9230
|
TSTypeReference(node) {
|
|
9051
9231
|
const { typeName } = node;
|
|
9052
|
-
const referenced = typeName.type ===
|
|
9232
|
+
const referenced = typeName.type === AST_NODE_TYPES42.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES42.TSQualifiedName && typeName.right.type === AST_NODE_TYPES42.Identifier ? typeName.right.name : null;
|
|
9053
9233
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
9054
9234
|
return;
|
|
9055
9235
|
}
|
|
@@ -9067,7 +9247,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
9067
9247
|
}
|
|
9068
9248
|
},
|
|
9069
9249
|
TSTypeAliasDeclaration(node) {
|
|
9070
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
9250
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== AST_NODE_TYPES42.TSTypeLiteral) {
|
|
9071
9251
|
return;
|
|
9072
9252
|
}
|
|
9073
9253
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -9112,10 +9292,10 @@ var prefer_zod_infer_default = createRule({
|
|
|
9112
9292
|
});
|
|
9113
9293
|
|
|
9114
9294
|
// src/rules/require-assert-never.ts
|
|
9115
|
-
import { AST_NODE_TYPES as
|
|
9295
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES43 } from "@typescript-eslint/utils";
|
|
9116
9296
|
var isRuntimeHandlingStatement = (statement) => {
|
|
9117
|
-
if (statement.type ===
|
|
9118
|
-
if (statement.type ===
|
|
9297
|
+
if (statement.type === AST_NODE_TYPES43.EmptyStatement) return false;
|
|
9298
|
+
if (statement.type === AST_NODE_TYPES43.BlockStatement) {
|
|
9119
9299
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
9120
9300
|
}
|
|
9121
9301
|
return true;
|
|
@@ -9131,7 +9311,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
9131
9311
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
9132
9312
|
}
|
|
9133
9313
|
const only = defaultCase.consequent[0];
|
|
9134
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
9314
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === AST_NODE_TYPES43.BlockStatement && only.body.length === 0) {
|
|
9135
9315
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
9136
9316
|
}
|
|
9137
9317
|
return false;
|
|
@@ -9171,7 +9351,7 @@ var require_assert_never_default = createRule({
|
|
|
9171
9351
|
});
|
|
9172
9352
|
|
|
9173
9353
|
// src/rules/require-fetch-timeout.ts
|
|
9174
|
-
import { AST_NODE_TYPES as
|
|
9354
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES44, ASTUtils as ASTUtils4 } from "@typescript-eslint/utils";
|
|
9175
9355
|
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set([
|
|
9176
9356
|
"globalThis",
|
|
9177
9357
|
"window",
|
|
@@ -9187,14 +9367,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
9187
9367
|
return false;
|
|
9188
9368
|
}
|
|
9189
9369
|
function initProvablyLacksSignal(init) {
|
|
9190
|
-
if (init.type !==
|
|
9370
|
+
if (init.type !== AST_NODE_TYPES44.ObjectExpression) {
|
|
9191
9371
|
return false;
|
|
9192
9372
|
}
|
|
9193
9373
|
for (const prop of init.properties) {
|
|
9194
|
-
if (prop.type ===
|
|
9374
|
+
if (prop.type === AST_NODE_TYPES44.SpreadElement) {
|
|
9195
9375
|
return false;
|
|
9196
9376
|
}
|
|
9197
|
-
if (prop.key.type ===
|
|
9377
|
+
if (prop.key.type === AST_NODE_TYPES44.Identifier && prop.key.name === "signal" || prop.key.type === AST_NODE_TYPES44.Literal && prop.key.value === "signal") {
|
|
9198
9378
|
return false;
|
|
9199
9379
|
}
|
|
9200
9380
|
if (prop.computed) {
|
|
@@ -9204,7 +9384,7 @@ function initProvablyLacksSignal(init) {
|
|
|
9204
9384
|
return true;
|
|
9205
9385
|
}
|
|
9206
9386
|
function isStringish(node) {
|
|
9207
|
-
return node.type ===
|
|
9387
|
+
return node.type === AST_NODE_TYPES44.Literal && typeof node.value === "string" || node.type === AST_NODE_TYPES44.TemplateLiteral;
|
|
9208
9388
|
}
|
|
9209
9389
|
var require_fetch_timeout_default = createRule({
|
|
9210
9390
|
name: "require-fetch-timeout",
|
|
@@ -9241,14 +9421,14 @@ var require_fetch_timeout_default = createRule({
|
|
|
9241
9421
|
}
|
|
9242
9422
|
function resolvesToGlobal(identifier) {
|
|
9243
9423
|
const scope = context.sourceCode.getScope(identifier);
|
|
9244
|
-
const variable =
|
|
9424
|
+
const variable = ASTUtils4.findVariable(scope, identifier.name);
|
|
9245
9425
|
return variable === null || variable.defs.length === 0;
|
|
9246
9426
|
}
|
|
9247
9427
|
function isGlobalFetchCall2(callee) {
|
|
9248
|
-
if (callee.type ===
|
|
9428
|
+
if (callee.type === AST_NODE_TYPES44.Identifier) {
|
|
9249
9429
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
9250
9430
|
}
|
|
9251
|
-
return callee.type ===
|
|
9431
|
+
return callee.type === AST_NODE_TYPES44.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES44.Identifier && callee.property.name === "fetch" && callee.object.type === AST_NODE_TYPES44.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
9252
9432
|
}
|
|
9253
9433
|
return {
|
|
9254
9434
|
CallExpression(node) {
|
|
@@ -9268,7 +9448,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
9268
9448
|
});
|
|
9269
9449
|
|
|
9270
9450
|
// src/rules/require-interface-for-injected-service.ts
|
|
9271
|
-
import { AST_NODE_TYPES as
|
|
9451
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES45 } from "@typescript-eslint/utils";
|
|
9272
9452
|
var CONFIGISH_TYPE_RE = /(?:Options|Opts|Config|Configuration|Settings|Params|Props|Args|Env|Environment|Callbacks|Flags)$/;
|
|
9273
9453
|
var CONFIGISH_NAME_RE = /^(?:options|opts|config|configuration|settings|params|props|args|env|environment|callbacks|flags|logger|log|clock)$/i;
|
|
9274
9454
|
var HTTP_TRANSPORT_TYPE_RE = /^(?:KyInstance|AxiosInstance|Session)$/;
|
|
@@ -9276,20 +9456,20 @@ var BUILTIN_CONTAINER_TYPE_RE = /^(?:Record|Map|WeakMap|Set|WeakSet|Array|Readon
|
|
|
9276
9456
|
var TRANSPORT_WRAPPER_NAME_RE = /Client$/;
|
|
9277
9457
|
var ROUTER_FACTORY_NAME = "Router";
|
|
9278
9458
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
9279
|
-
var isExportedClass = (node) => node.parent.type ===
|
|
9280
|
-
var qualifiedName = (name) => name.type ===
|
|
9459
|
+
var isExportedClass = (node) => node.parent.type === AST_NODE_TYPES45.ExportNamedDeclaration || node.parent.type === AST_NODE_TYPES45.ExportDefaultDeclaration;
|
|
9460
|
+
var qualifiedName = (name) => name.type === AST_NODE_TYPES45.Identifier ? name.name : name.type === AST_NODE_TYPES45.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
9281
9461
|
var readTypeReference = (annotation) => {
|
|
9282
|
-
if (annotation === void 0 || annotation.type !==
|
|
9462
|
+
if (annotation === void 0 || annotation.type !== AST_NODE_TYPES45.TSTypeReference) return null;
|
|
9283
9463
|
const { typeName } = annotation;
|
|
9284
|
-
const rightmost = typeName.type ===
|
|
9464
|
+
const rightmost = typeName.type === AST_NODE_TYPES45.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES45.TSQualifiedName ? typeName.right.name : null;
|
|
9285
9465
|
if (rightmost === null) return null;
|
|
9286
9466
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
9287
9467
|
};
|
|
9288
9468
|
var namedParameterCollaborator = (annotated) => {
|
|
9289
9469
|
let target = annotated;
|
|
9290
|
-
if (target.type ===
|
|
9291
|
-
if (target.type ===
|
|
9292
|
-
if (target.type !==
|
|
9470
|
+
if (target.type === AST_NODE_TYPES45.TSParameterProperty) target = target.parameter;
|
|
9471
|
+
if (target.type === AST_NODE_TYPES45.AssignmentPattern) target = target.left;
|
|
9472
|
+
if (target.type !== AST_NODE_TYPES45.Identifier) return null;
|
|
9293
9473
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
9294
9474
|
if (reference === null) return null;
|
|
9295
9475
|
return { name: target.name, ...reference };
|
|
@@ -9297,8 +9477,8 @@ var namedParameterCollaborator = (annotated) => {
|
|
|
9297
9477
|
var propertySignatureTypes = (members) => {
|
|
9298
9478
|
const types = /* @__PURE__ */ new Map();
|
|
9299
9479
|
for (const member of members) {
|
|
9300
|
-
if (member.type !==
|
|
9301
|
-
if (member.computed || member.key.type !==
|
|
9480
|
+
if (member.type !== AST_NODE_TYPES45.TSPropertySignature) continue;
|
|
9481
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES45.Identifier) continue;
|
|
9302
9482
|
const reference = readTypeReference(member.typeAnnotation?.typeAnnotation);
|
|
9303
9483
|
if (reference === null) continue;
|
|
9304
9484
|
types.set(member.key.name, reference);
|
|
@@ -9309,18 +9489,18 @@ var fileTypeIndex = (program) => {
|
|
|
9309
9489
|
const objects = /* @__PURE__ */ new Map();
|
|
9310
9490
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
9311
9491
|
for (const statement of program.body) {
|
|
9312
|
-
const declaration = statement.type ===
|
|
9313
|
-
if (declaration?.type ===
|
|
9492
|
+
const declaration = statement.type === AST_NODE_TYPES45.ExportNamedDeclaration ? statement.declaration : statement;
|
|
9493
|
+
if (declaration?.type === AST_NODE_TYPES45.TSInterfaceDeclaration) {
|
|
9314
9494
|
objects.set(declaration.id.name, propertySignatureTypes(declaration.body.body));
|
|
9315
9495
|
continue;
|
|
9316
9496
|
}
|
|
9317
|
-
if (declaration?.type !==
|
|
9497
|
+
if (declaration?.type !== AST_NODE_TYPES45.TSTypeAliasDeclaration) continue;
|
|
9318
9498
|
const aliased = declaration.typeAnnotation;
|
|
9319
|
-
if (aliased.type ===
|
|
9499
|
+
if (aliased.type === AST_NODE_TYPES45.TSFunctionType || aliased.type === AST_NODE_TYPES45.TSConstructorType) {
|
|
9320
9500
|
functionAliases.add(declaration.id.name);
|
|
9321
9501
|
continue;
|
|
9322
9502
|
}
|
|
9323
|
-
const literals = aliased.type ===
|
|
9503
|
+
const literals = aliased.type === AST_NODE_TYPES45.TSTypeLiteral ? [aliased] : aliased.type === AST_NODE_TYPES45.TSIntersectionType ? aliased.types.filter((part) => part.type === AST_NODE_TYPES45.TSTypeLiteral) : [];
|
|
9324
9504
|
if (literals.length === 0) continue;
|
|
9325
9505
|
const merged = /* @__PURE__ */ new Map();
|
|
9326
9506
|
for (const literal of literals) {
|
|
@@ -9333,10 +9513,10 @@ var fileTypeIndex = (program) => {
|
|
|
9333
9513
|
return { objects, functionAliases };
|
|
9334
9514
|
};
|
|
9335
9515
|
var bagMemberTypes = (annotation, declared) => {
|
|
9336
|
-
if (annotation.type ===
|
|
9516
|
+
if (annotation.type === AST_NODE_TYPES45.TSTypeLiteral) {
|
|
9337
9517
|
return propertySignatureTypes(annotation.members);
|
|
9338
9518
|
}
|
|
9339
|
-
if (annotation.type !==
|
|
9519
|
+
if (annotation.type !== AST_NODE_TYPES45.TSTypeReference || annotation.typeName.type !== AST_NODE_TYPES45.Identifier) {
|
|
9340
9520
|
return null;
|
|
9341
9521
|
}
|
|
9342
9522
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
@@ -9348,11 +9528,11 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
9348
9528
|
if (members === null) return [];
|
|
9349
9529
|
const collaborators = [];
|
|
9350
9530
|
for (const property of pattern.properties) {
|
|
9351
|
-
if (property.type !==
|
|
9352
|
-
if (property.key.type !==
|
|
9531
|
+
if (property.type !== AST_NODE_TYPES45.Property || property.computed) continue;
|
|
9532
|
+
if (property.key.type !== AST_NODE_TYPES45.Identifier) continue;
|
|
9353
9533
|
const key = property.key.name;
|
|
9354
|
-
const bound = property.value.type ===
|
|
9355
|
-
if (bound.type !==
|
|
9534
|
+
const bound = property.value.type === AST_NODE_TYPES45.AssignmentPattern ? property.value.left : property.value;
|
|
9535
|
+
if (bound.type !== AST_NODE_TYPES45.Identifier) continue;
|
|
9356
9536
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
9357
9537
|
const reference = members.get(key);
|
|
9358
9538
|
if (reference === void 0) continue;
|
|
@@ -9362,8 +9542,8 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
9362
9542
|
};
|
|
9363
9543
|
var parameterCollaborators = (parameter, declared) => {
|
|
9364
9544
|
let target = parameter;
|
|
9365
|
-
if (target.type ===
|
|
9366
|
-
if (target.type ===
|
|
9545
|
+
if (target.type === AST_NODE_TYPES45.AssignmentPattern) target = target.left;
|
|
9546
|
+
if (target.type === AST_NODE_TYPES45.ObjectPattern) {
|
|
9367
9547
|
return objectPatternCollaborators(target, declared);
|
|
9368
9548
|
}
|
|
9369
9549
|
const named2 = namedParameterCollaborator(parameter);
|
|
@@ -9382,17 +9562,17 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
9382
9562
|
let constructedFields = 0;
|
|
9383
9563
|
if (body2 !== null && body2 !== void 0) {
|
|
9384
9564
|
for (const statement of body2.body) {
|
|
9385
|
-
if (statement.type !==
|
|
9565
|
+
if (statement.type !== AST_NODE_TYPES45.ExpressionStatement) continue;
|
|
9386
9566
|
const expression = statement.expression;
|
|
9387
|
-
if (expression.type !==
|
|
9567
|
+
if (expression.type !== AST_NODE_TYPES45.AssignmentExpression || expression.operator !== "=" || expression.left.type !== AST_NODE_TYPES45.MemberExpression || expression.left.object.type !== AST_NODE_TYPES45.ThisExpression) {
|
|
9388
9568
|
continue;
|
|
9389
9569
|
}
|
|
9390
9570
|
const source = expression.right;
|
|
9391
|
-
if (source.type ===
|
|
9571
|
+
if (source.type === AST_NODE_TYPES45.NewExpression) {
|
|
9392
9572
|
constructedFields += 1;
|
|
9393
|
-
} else if (source.type ===
|
|
9573
|
+
} else if (source.type === AST_NODE_TYPES45.Identifier) {
|
|
9394
9574
|
storedFrom.add(source.name);
|
|
9395
|
-
} else if (source.type ===
|
|
9575
|
+
} else if (source.type === AST_NODE_TYPES45.MemberExpression && source.object.type === AST_NODE_TYPES45.Identifier) {
|
|
9396
9576
|
storedFrom.add(source.object.name);
|
|
9397
9577
|
}
|
|
9398
9578
|
}
|
|
@@ -9400,7 +9580,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
9400
9580
|
const collaborators = [];
|
|
9401
9581
|
for (const parameter of ctor.value.params) {
|
|
9402
9582
|
for (const reference of parameterCollaborators(parameter, declared)) {
|
|
9403
|
-
const stored = parameter.type ===
|
|
9583
|
+
const stored = parameter.type === AST_NODE_TYPES45.TSParameterProperty || storedFrom.has(reference.name);
|
|
9404
9584
|
if (!stored) continue;
|
|
9405
9585
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
9406
9586
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -9434,19 +9614,19 @@ var subtreeHas = (root, found) => {
|
|
|
9434
9614
|
return hit;
|
|
9435
9615
|
};
|
|
9436
9616
|
var isFrameworkWiring = (body2) => subtreeHas(body2, (node) => {
|
|
9437
|
-
if (node.type ===
|
|
9617
|
+
if (node.type === AST_NODE_TYPES45.CallExpression) {
|
|
9438
9618
|
const { callee } = node;
|
|
9439
|
-
if (callee.type ===
|
|
9440
|
-
return callee.type ===
|
|
9619
|
+
if (callee.type === AST_NODE_TYPES45.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
9620
|
+
return callee.type === AST_NODE_TYPES45.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES45.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
9441
9621
|
}
|
|
9442
|
-
return node.type ===
|
|
9622
|
+
return node.type === AST_NODE_TYPES45.TSTypeReference && node.typeName.type === AST_NODE_TYPES45.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
9443
9623
|
});
|
|
9444
9624
|
var stem2 = (name) => name.replace(/^I(?=[A-Z])/, "").replace(/Impl$/, "");
|
|
9445
9625
|
var fileInterfaceNames = (program) => {
|
|
9446
9626
|
const names = [];
|
|
9447
9627
|
for (const statement of program.body) {
|
|
9448
|
-
const declaration = statement.type ===
|
|
9449
|
-
if (declaration?.type ===
|
|
9628
|
+
const declaration = statement.type === AST_NODE_TYPES45.ExportNamedDeclaration ? statement.declaration : statement;
|
|
9629
|
+
if (declaration?.type === AST_NODE_TYPES45.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
9450
9630
|
}
|
|
9451
9631
|
return names;
|
|
9452
9632
|
};
|
|
@@ -9464,11 +9644,11 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
9464
9644
|
var publicMethodNames = (body2) => {
|
|
9465
9645
|
const names = [];
|
|
9466
9646
|
for (const member of body2.body) {
|
|
9467
|
-
if (member.type !==
|
|
9647
|
+
if (member.type !== AST_NODE_TYPES45.MethodDefinition) continue;
|
|
9468
9648
|
if (member.kind !== "method" || member.static) continue;
|
|
9469
9649
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
9470
|
-
if (member.key.type ===
|
|
9471
|
-
if (member.key.type ===
|
|
9650
|
+
if (member.key.type === AST_NODE_TYPES45.PrivateIdentifier) continue;
|
|
9651
|
+
if (member.key.type === AST_NODE_TYPES45.Identifier) names.push(member.key.name);
|
|
9472
9652
|
else names.push("\u2026");
|
|
9473
9653
|
}
|
|
9474
9654
|
return names;
|
|
@@ -9501,7 +9681,7 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
9501
9681
|
if (node.implements.length > 0) return;
|
|
9502
9682
|
if (node.decorators.length > 0) return;
|
|
9503
9683
|
const ctor = node.body.body.find(
|
|
9504
|
-
(member) => member.type ===
|
|
9684
|
+
(member) => member.type === AST_NODE_TYPES45.MethodDefinition && member.kind === "constructor"
|
|
9505
9685
|
);
|
|
9506
9686
|
if (ctor === void 0) return;
|
|
9507
9687
|
const { collaborators, constructedFields } = readConstructor(
|
|
@@ -9530,18 +9710,18 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
9530
9710
|
});
|
|
9531
9711
|
|
|
9532
9712
|
// src/rules/require-zod-form-validation.ts
|
|
9533
|
-
import { AST_NODE_TYPES as
|
|
9713
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES46 } from "@typescript-eslint/utils";
|
|
9534
9714
|
var looksLikeZodSchema = (node) => {
|
|
9535
9715
|
let current = node;
|
|
9536
9716
|
while (true) {
|
|
9537
|
-
if (current.type ===
|
|
9717
|
+
if (current.type === AST_NODE_TYPES46.Identifier) {
|
|
9538
9718
|
return current.name === "z" || ZOD_SCHEMA_NAME_RE.test(current.name);
|
|
9539
9719
|
}
|
|
9540
|
-
if (current.type ===
|
|
9720
|
+
if (current.type === AST_NODE_TYPES46.CallExpression) {
|
|
9541
9721
|
current = current.callee;
|
|
9542
9722
|
continue;
|
|
9543
9723
|
}
|
|
9544
|
-
if (current.type ===
|
|
9724
|
+
if (current.type === AST_NODE_TYPES46.MemberExpression) {
|
|
9545
9725
|
current = current.object;
|
|
9546
9726
|
continue;
|
|
9547
9727
|
}
|
|
@@ -9549,23 +9729,23 @@ var looksLikeZodSchema = (node) => {
|
|
|
9549
9729
|
}
|
|
9550
9730
|
};
|
|
9551
9731
|
var isZodParseCall = (node) => {
|
|
9552
|
-
if (node.type !==
|
|
9732
|
+
if (node.type !== AST_NODE_TYPES46.CallExpression) return false;
|
|
9553
9733
|
const callee = node.callee;
|
|
9554
|
-
if (callee.type !==
|
|
9734
|
+
if (callee.type !== AST_NODE_TYPES46.MemberExpression) return false;
|
|
9555
9735
|
if (callee.computed) return false;
|
|
9556
|
-
if (callee.property.type !==
|
|
9736
|
+
if (callee.property.type !== AST_NODE_TYPES46.Identifier) return false;
|
|
9557
9737
|
const method = callee.property.name;
|
|
9558
9738
|
if (method !== "parse" && method !== "safeParse") return false;
|
|
9559
9739
|
return looksLikeZodSchema(callee.object);
|
|
9560
9740
|
};
|
|
9561
9741
|
var isFormDataMethodCall = (node) => {
|
|
9562
9742
|
let current = node;
|
|
9563
|
-
if (current.type ===
|
|
9743
|
+
if (current.type === AST_NODE_TYPES46.AwaitExpression) {
|
|
9564
9744
|
current = current.argument;
|
|
9565
9745
|
}
|
|
9566
|
-
if (current.type !==
|
|
9746
|
+
if (current.type !== AST_NODE_TYPES46.CallExpression) return false;
|
|
9567
9747
|
const callee = current.callee;
|
|
9568
|
-
return callee.type ===
|
|
9748
|
+
return callee.type === AST_NODE_TYPES46.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES46.Identifier && callee.property.name === "formData";
|
|
9569
9749
|
};
|
|
9570
9750
|
var require_zod_form_validation_default = createRule({
|
|
9571
9751
|
name: "require-zod-form-validation",
|
|
@@ -9585,14 +9765,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
9585
9765
|
return {};
|
|
9586
9766
|
}
|
|
9587
9767
|
const isFormSourceIdentifier = (node) => {
|
|
9588
|
-
if (node.type !==
|
|
9768
|
+
if (node.type !== AST_NODE_TYPES46.Identifier) return false;
|
|
9589
9769
|
if (/formdata/i.test(node.name)) return true;
|
|
9590
9770
|
let scope = context.sourceCode.getScope(node);
|
|
9591
9771
|
while (scope !== null) {
|
|
9592
9772
|
const variable = scope.set.get(node.name);
|
|
9593
9773
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
9594
9774
|
const def = variable.defs[0];
|
|
9595
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
9775
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === AST_NODE_TYPES46.VariableDeclarator && def.node.init !== null) {
|
|
9596
9776
|
return isFormDataMethodCall(def.node.init);
|
|
9597
9777
|
}
|
|
9598
9778
|
return false;
|
|
@@ -9603,8 +9783,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
9603
9783
|
};
|
|
9604
9784
|
const isFormDataGetCall = (node) => {
|
|
9605
9785
|
const callee = node.callee;
|
|
9606
|
-
if (callee.type !==
|
|
9607
|
-
if (callee.property.type !==
|
|
9786
|
+
if (callee.type !== AST_NODE_TYPES46.MemberExpression) return false;
|
|
9787
|
+
if (callee.property.type !== AST_NODE_TYPES46.Identifier || callee.property.name !== "get") {
|
|
9608
9788
|
return false;
|
|
9609
9789
|
}
|
|
9610
9790
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -9619,11 +9799,11 @@ var require_zod_form_validation_default = createRule({
|
|
|
9619
9799
|
};
|
|
9620
9800
|
const isInstanceofNarrowing = (node) => {
|
|
9621
9801
|
const parent = node.parent;
|
|
9622
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
9802
|
+
return parent !== null && parent !== void 0 && parent.type === AST_NODE_TYPES46.BinaryExpression && parent.operator === "instanceof" && parent.left === node && parent.right.type === AST_NODE_TYPES46.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
9623
9803
|
};
|
|
9624
9804
|
const boundDeclarator = (node) => {
|
|
9625
9805
|
const parent = node.parent;
|
|
9626
|
-
if (parent.type ===
|
|
9806
|
+
if (parent.type === AST_NODE_TYPES46.VariableDeclarator && parent.init === node && parent.id.type === AST_NODE_TYPES46.Identifier) {
|
|
9627
9807
|
return parent;
|
|
9628
9808
|
}
|
|
9629
9809
|
return null;
|
|
@@ -9682,7 +9862,7 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
9682
9862
|
});
|
|
9683
9863
|
|
|
9684
9864
|
// src/rules/zod-naming-convention.ts
|
|
9685
|
-
import { AST_NODE_TYPES as
|
|
9865
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES47 } from "@typescript-eslint/utils";
|
|
9686
9866
|
var CONVENTIONS = {
|
|
9687
9867
|
prefix: { test: ZOD_PREFIX_RE, messageId: "zPrefix" },
|
|
9688
9868
|
suffix: { test: ZOD_SUFFIX_RE, messageId: "schemaSuffix" },
|
|
@@ -9707,15 +9887,15 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
9707
9887
|
"registry",
|
|
9708
9888
|
"implement"
|
|
9709
9889
|
]);
|
|
9710
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
9890
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === AST_NODE_TYPES47.Identifier ? callee.property.name : null;
|
|
9711
9891
|
var calleeChainStartsWithZ = (node) => {
|
|
9712
9892
|
let current = node;
|
|
9713
|
-
while (current.type ===
|
|
9893
|
+
while (current.type === AST_NODE_TYPES47.MemberExpression) {
|
|
9714
9894
|
const receiver = current.object;
|
|
9715
|
-
if (receiver.type ===
|
|
9895
|
+
if (receiver.type === AST_NODE_TYPES47.Identifier && receiver.name === "z") {
|
|
9716
9896
|
return true;
|
|
9717
9897
|
}
|
|
9718
|
-
if (receiver.type ===
|
|
9898
|
+
if (receiver.type === AST_NODE_TYPES47.CallExpression) {
|
|
9719
9899
|
current = receiver.callee;
|
|
9720
9900
|
continue;
|
|
9721
9901
|
}
|
|
@@ -9760,13 +9940,13 @@ var zod_naming_convention_default = createRule({
|
|
|
9760
9940
|
VariableDeclarator(node) {
|
|
9761
9941
|
const init = node.init;
|
|
9762
9942
|
if (init === null || init === void 0) return;
|
|
9763
|
-
if (init.type !==
|
|
9943
|
+
if (init.type !== AST_NODE_TYPES47.CallExpression) return;
|
|
9764
9944
|
const callee = init.callee;
|
|
9765
|
-
if (callee.type !==
|
|
9945
|
+
if (callee.type !== AST_NODE_TYPES47.MemberExpression) return;
|
|
9766
9946
|
if (!calleeChainStartsWithZ(callee)) return;
|
|
9767
9947
|
const terminal = terminalMethodName(callee);
|
|
9768
9948
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
9769
|
-
if (node.id.type !==
|
|
9949
|
+
if (node.id.type !== AST_NODE_TYPES47.Identifier) return;
|
|
9770
9950
|
if (test.test(node.id.name)) return;
|
|
9771
9951
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
9772
9952
|
context.report({
|
|
@@ -9854,6 +10034,7 @@ var rules = {
|
|
|
9854
10034
|
"no-positional-tuple-return": no_positional_tuple_return_default,
|
|
9855
10035
|
"no-raw-env": no_raw_env_default,
|
|
9856
10036
|
"no-raw-fetch-outside-clients": no_raw_fetch_outside_clients_default,
|
|
10037
|
+
"no-restricted-library-load": no_restricted_library_load_default,
|
|
9857
10038
|
"no-repeated-string-literal": no_repeated_string_literal_default,
|
|
9858
10039
|
"no-restated-comment": no_restated_comment_default,
|
|
9859
10040
|
"no-restated-jsdoc": no_restated_jsdoc_default,
|
|
@@ -9878,6 +10059,7 @@ var rules = {
|
|
|
9878
10059
|
"prefer-module-level-constant": prefer_module_level_constant_default,
|
|
9879
10060
|
"prefer-module-level-schema": prefer_module_level_schema_default,
|
|
9880
10061
|
"prefer-non-nullable-collection": prefer_non_nullable_collection_default,
|
|
10062
|
+
"prefer-native-random-uuid": prefer_native_random_uuid_default,
|
|
9881
10063
|
"prefer-schema-for-api-payload": prefer_schema_for_api_payload_default,
|
|
9882
10064
|
"prefer-semantic-colors": prefer_semantic_colors_default,
|
|
9883
10065
|
"prefer-server-actions": prefer_server_actions_default,
|
|
@@ -9895,8 +10077,12 @@ var rules = {
|
|
|
9895
10077
|
};
|
|
9896
10078
|
var meta = {
|
|
9897
10079
|
name: "@sarj/eslint-plugin",
|
|
9898
|
-
version: "9.
|
|
10080
|
+
version: "9.8.0"
|
|
9899
10081
|
};
|
|
10082
|
+
var applicationOnlyRules = [
|
|
10083
|
+
"no-restricted-library-load",
|
|
10084
|
+
"prefer-native-random-uuid"
|
|
10085
|
+
];
|
|
9900
10086
|
var recommendedRules = {
|
|
9901
10087
|
"@sarj/enforce-file-structure": "warn",
|
|
9902
10088
|
"@sarj/no-async-callback-in-wait-for": "warn",
|
|
@@ -10032,6 +10218,7 @@ plugin.configs.strict = {
|
|
|
10032
10218
|
};
|
|
10033
10219
|
var index_default = plugin;
|
|
10034
10220
|
export {
|
|
10221
|
+
applicationOnlyRules,
|
|
10035
10222
|
index_default as default,
|
|
10036
10223
|
recommendedRules,
|
|
10037
10224
|
renamedRules,
|