@sarj/eslint-plugin 9.13.0 → 9.14.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/LICENSE +21 -0
- package/README.md +23 -3
- package/dist/index.cjs +1580 -661
- package/dist/index.d.cts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +1570 -651
- package/package.json +5 -3
package/dist/index.cjs
CHANGED
|
@@ -55,9 +55,10 @@ var createRule = import_utils.ESLintUtils.RuleCreator(examplesUrl);
|
|
|
55
55
|
var SCRIPT_FILE_RE = /([\\/]scripts[\\/])|(\.mjs$)/;
|
|
56
56
|
var STORY_FILE_RE = /\.stories\.[cm]?[jt]sx?$/i;
|
|
57
57
|
var STORY_TREE_RE = /(^|\/)stories(?:[_-][^/]*)?\//i;
|
|
58
|
-
var GENERATED_FILE_RE = /([\\/](?:generated|openapi-gen|graphql[\\/]types|vendor|vendored|third[-_]?party)[\\/])|(\.gen\.[cm]?[jt]sx?$)|(\.generated\.[cm]?[jt]sx?$)|(\.d\.[cm]?ts$)|(\.types\.[cm]?ts$)
|
|
58
|
+
var GENERATED_FILE_RE = /((?:^|[\\/])(?:generated|__generated__|openapi-gen|graphql[\\/]types|vendor|vendored|third[-_]?party)[\\/])|(\.gen\.[cm]?[jt]sx?$)|(\.generated\.[cm]?[jt]sx?$)|(\.d\.[cm]?ts$)|(\.types\.[cm]?ts$)/i;
|
|
59
59
|
var EXTERNAL_TREE_RE = /[\\/]external[\\/]/;
|
|
60
60
|
var GENERATED_MARKER_RE = /(?:@generated\b|this file (?:is|was|has been)[\w\s,'-]{0,40}?generated|auto-?generated file\b|generated (?:with|by)|generated (?:graphql )?types|do not edit(?: directly| manually)?|do not (?:modify|change) this file)/i;
|
|
61
|
+
var COMMENT_LINE_RE = /^\s*(?:\/\/|\/\*+|\*|#)/;
|
|
61
62
|
var TEST_BASENAME_RE = /[.\-_](test|spec|e2e)\.[cm]?[jt]sx?$/;
|
|
62
63
|
var TEST_INTEGRATION_BASENAME_RE = /\.integration\.[cm]?[jt]sx?$/;
|
|
63
64
|
var TEST_DIR_RE = /(^|\/)(tests?|__tests__|__mocks__|fixtures|__fixtures__|__testfixtures__|e2e|integration)\//;
|
|
@@ -88,7 +89,7 @@ function isGeneratedFile(filename, sourceText = "", gates = []) {
|
|
|
88
89
|
if (gates.includes("externalTree") && EXTERNAL_TREE_RE.test(normalized)) {
|
|
89
90
|
return true;
|
|
90
91
|
}
|
|
91
|
-
return
|
|
92
|
+
return sourceText.slice(0, 2048).split("\n").some((line) => COMMENT_LINE_RE.test(line) && GENERATED_MARKER_RE.test(line));
|
|
92
93
|
}
|
|
93
94
|
function isScriptFile(filename) {
|
|
94
95
|
return SCRIPT_FILE_RE.test(filename);
|
|
@@ -3183,8 +3184,204 @@ var no_long_comment_default = createRule({
|
|
|
3183
3184
|
}
|
|
3184
3185
|
});
|
|
3185
3186
|
|
|
3186
|
-
// src/rules/no-
|
|
3187
|
+
// src/rules/no-generic-single-export-module.ts
|
|
3187
3188
|
var import_utils20 = require("@typescript-eslint/utils");
|
|
3189
|
+
var GENERIC_STEMS = /* @__PURE__ */ new Set([
|
|
3190
|
+
"base",
|
|
3191
|
+
"common",
|
|
3192
|
+
"constant",
|
|
3193
|
+
"constants",
|
|
3194
|
+
"core",
|
|
3195
|
+
"enum",
|
|
3196
|
+
"enums",
|
|
3197
|
+
"helper",
|
|
3198
|
+
"helpers",
|
|
3199
|
+
"misc",
|
|
3200
|
+
"model",
|
|
3201
|
+
"models",
|
|
3202
|
+
"shared",
|
|
3203
|
+
"stuff",
|
|
3204
|
+
"type",
|
|
3205
|
+
"types",
|
|
3206
|
+
"util",
|
|
3207
|
+
"utils"
|
|
3208
|
+
]);
|
|
3209
|
+
var CONVENTIONAL_STEMS = /* @__PURE__ */ new Set(["base", "models"]);
|
|
3210
|
+
var CJS_OBJECT_EXPORT_METHODS = /* @__PURE__ */ new Set(["assign", "defineProperties", "defineProperty"]);
|
|
3211
|
+
function fileParts(filename) {
|
|
3212
|
+
const base = filename.replaceAll("\\", "/").split("/").at(-1) ?? "";
|
|
3213
|
+
const extension = base.match(/(\.[cm]?[jt]sx?)$/u)?.[1] ?? ".ts";
|
|
3214
|
+
const segments = base.slice(0, -extension.length).split(".");
|
|
3215
|
+
return {
|
|
3216
|
+
extension,
|
|
3217
|
+
stem: segments[0]?.toLowerCase() ?? "",
|
|
3218
|
+
suffixes: segments.slice(1)
|
|
3219
|
+
};
|
|
3220
|
+
}
|
|
3221
|
+
function declaredNames(declaration) {
|
|
3222
|
+
if (declaration.declare === true) return [];
|
|
3223
|
+
if (declaration.type === import_utils20.AST_NODE_TYPES.FunctionDeclaration || declaration.type === import_utils20.AST_NODE_TYPES.ClassDeclaration || declaration.type === import_utils20.AST_NODE_TYPES.TSEnumDeclaration) {
|
|
3224
|
+
if (declaration.type === import_utils20.AST_NODE_TYPES.TSEnumDeclaration && declaration.const) return [];
|
|
3225
|
+
return declaration.id === null ? [] : [declaration.id.name];
|
|
3226
|
+
}
|
|
3227
|
+
if (declaration.type === import_utils20.AST_NODE_TYPES.TSModuleDeclaration && declaration.id.type === import_utils20.AST_NODE_TYPES.Identifier) {
|
|
3228
|
+
return [declaration.id.name];
|
|
3229
|
+
}
|
|
3230
|
+
if (declaration.type !== import_utils20.AST_NODE_TYPES.VariableDeclaration) return [];
|
|
3231
|
+
return declaration.declarations.flatMap(
|
|
3232
|
+
(item) => item.id.type === import_utils20.AST_NODE_TYPES.Identifier ? [item.id.name] : []
|
|
3233
|
+
);
|
|
3234
|
+
}
|
|
3235
|
+
function typeOnlyBindings(program) {
|
|
3236
|
+
const names = /* @__PURE__ */ new Set();
|
|
3237
|
+
const runtimeNames = /* @__PURE__ */ new Set();
|
|
3238
|
+
for (const statement of program.body) {
|
|
3239
|
+
const declaration = statement.type === import_utils20.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
3240
|
+
if (declaration?.type === import_utils20.AST_NODE_TYPES.TSInterfaceDeclaration || declaration?.type === import_utils20.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
3241
|
+
names.add(declaration.id.name);
|
|
3242
|
+
continue;
|
|
3243
|
+
}
|
|
3244
|
+
if (declaration?.type === import_utils20.AST_NODE_TYPES.TSEnumDeclaration && declaration.const) {
|
|
3245
|
+
names.add(declaration.id.name);
|
|
3246
|
+
continue;
|
|
3247
|
+
}
|
|
3248
|
+
if (statement.type === import_utils20.AST_NODE_TYPES.ImportDeclaration) {
|
|
3249
|
+
for (const specifier of statement.specifiers) {
|
|
3250
|
+
if (statement.importKind === "type" || specifier.type === import_utils20.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === "type") {
|
|
3251
|
+
names.add(specifier.local.name);
|
|
3252
|
+
} else {
|
|
3253
|
+
runtimeNames.add(specifier.local.name);
|
|
3254
|
+
}
|
|
3255
|
+
}
|
|
3256
|
+
continue;
|
|
3257
|
+
}
|
|
3258
|
+
if (declaration?.type === import_utils20.AST_NODE_TYPES.TSDeclareFunction && declaration.id !== null) {
|
|
3259
|
+
names.add(declaration.id.name);
|
|
3260
|
+
continue;
|
|
3261
|
+
}
|
|
3262
|
+
if (declaration !== null && declaration.declare === true) {
|
|
3263
|
+
if ((declaration.type === import_utils20.AST_NODE_TYPES.ClassDeclaration || declaration.type === import_utils20.AST_NODE_TYPES.FunctionDeclaration || declaration.type === import_utils20.AST_NODE_TYPES.TSEnumDeclaration || declaration.type === import_utils20.AST_NODE_TYPES.TSModuleDeclaration) && declaration.id !== null && declaration.id.type === import_utils20.AST_NODE_TYPES.Identifier) names.add(declaration.id.name);
|
|
3264
|
+
if (declaration.type === import_utils20.AST_NODE_TYPES.VariableDeclaration) {
|
|
3265
|
+
for (const item of declaration.declarations) {
|
|
3266
|
+
if (item.id.type === import_utils20.AST_NODE_TYPES.Identifier) names.add(item.id.name);
|
|
3267
|
+
}
|
|
3268
|
+
}
|
|
3269
|
+
continue;
|
|
3270
|
+
}
|
|
3271
|
+
if (declaration !== null && "type" in declaration) {
|
|
3272
|
+
for (const name of declaredNames(declaration)) {
|
|
3273
|
+
runtimeNames.add(name);
|
|
3274
|
+
}
|
|
3275
|
+
}
|
|
3276
|
+
}
|
|
3277
|
+
return new Set([...names].filter((name) => !runtimeNames.has(name)));
|
|
3278
|
+
}
|
|
3279
|
+
function runtimeExports(program) {
|
|
3280
|
+
const exports2 = [];
|
|
3281
|
+
const typeBindings = typeOnlyBindings(program);
|
|
3282
|
+
let ambiguous = false;
|
|
3283
|
+
for (const statement of program.body) {
|
|
3284
|
+
if (statement.type === import_utils20.AST_NODE_TYPES.ExportAllDeclaration) {
|
|
3285
|
+
if (statement.exportKind !== "type") ambiguous = true;
|
|
3286
|
+
continue;
|
|
3287
|
+
}
|
|
3288
|
+
if (statement.type === import_utils20.AST_NODE_TYPES.ExportDefaultDeclaration) {
|
|
3289
|
+
const declaration = statement.declaration;
|
|
3290
|
+
if (declaration.type === import_utils20.AST_NODE_TYPES.Identifier) {
|
|
3291
|
+
if (!typeBindings.has(declaration.name)) {
|
|
3292
|
+
exports2.push({ key: "default", name: declaration.name, node: statement });
|
|
3293
|
+
}
|
|
3294
|
+
} else if ((declaration.type === import_utils20.AST_NODE_TYPES.FunctionDeclaration || declaration.type === import_utils20.AST_NODE_TYPES.ClassDeclaration) && declaration.id !== null && declaration.declare !== true) exports2.push({ key: "default", name: declaration.id.name, node: declaration });
|
|
3295
|
+
else if (declaration.type !== import_utils20.AST_NODE_TYPES.TSInterfaceDeclaration && declaration.type !== import_utils20.AST_NODE_TYPES.TSTypeAliasDeclaration) ambiguous = true;
|
|
3296
|
+
continue;
|
|
3297
|
+
}
|
|
3298
|
+
if (statement.type !== import_utils20.AST_NODE_TYPES.ExportNamedDeclaration || statement.exportKind === "type") continue;
|
|
3299
|
+
if (statement.source !== null) {
|
|
3300
|
+
if (statement.specifiers.some((specifier) => specifier.exportKind !== "type")) ambiguous = true;
|
|
3301
|
+
continue;
|
|
3302
|
+
}
|
|
3303
|
+
if (statement.declaration !== null) {
|
|
3304
|
+
const declaration = statement.declaration;
|
|
3305
|
+
exports2.push(...declaredNames(declaration).map((name) => ({ key: name, name, node: declaration })));
|
|
3306
|
+
}
|
|
3307
|
+
for (const specifier of statement.specifiers) {
|
|
3308
|
+
if (specifier.exportKind === "type" || typeBindings.has(specifier.local.name)) continue;
|
|
3309
|
+
const exported = specifier.exported.type === import_utils20.AST_NODE_TYPES.Identifier ? specifier.exported.name : specifier.exported.value;
|
|
3310
|
+
const local = specifier.local.name;
|
|
3311
|
+
exports2.push({ key: exported, name: exported === "default" ? local : exported, node: specifier });
|
|
3312
|
+
}
|
|
3313
|
+
}
|
|
3314
|
+
const unique = new Map(exports2.map((entry) => [entry.key, entry]));
|
|
3315
|
+
return { exports: [...unique.values()], ambiguous };
|
|
3316
|
+
}
|
|
3317
|
+
function kebabCase(name) {
|
|
3318
|
+
return name.replaceAll(/oauth/giu, "Oauth").replaceAll(/graphql/giu, "Graphql").replaceAll(/grpc/giu, "Grpc").replaceAll(/([a-z\d])([A-Z])/gu, "$1-$2").replaceAll(/([A-Z]+)([A-Z][a-z])/gu, "$1-$2").replaceAll(/[_\s]+/gu, "-").replaceAll(/-+/gu, "-").replaceAll(/^-|-$/gu, "").toLowerCase();
|
|
3319
|
+
}
|
|
3320
|
+
function isGlobalIdentifier(context, node) {
|
|
3321
|
+
const variable = import_utils20.ASTUtils.findVariable(context.sourceCode.getScope(node), node.name);
|
|
3322
|
+
return variable === null || variable.defs.length === 0;
|
|
3323
|
+
}
|
|
3324
|
+
function isConventionalFrameworkUtility(filename, exported) {
|
|
3325
|
+
const normalized = filename.replaceAll("\\", "/");
|
|
3326
|
+
return exported === "cn" && /(?:^|\/)lib\/utils\.[cm]?[jt]sx?$/u.test(normalized);
|
|
3327
|
+
}
|
|
3328
|
+
function memberPropertyName(node) {
|
|
3329
|
+
if (!node.computed && node.property.type === import_utils20.AST_NODE_TYPES.Identifier) return node.property.name;
|
|
3330
|
+
return node.computed && node.property.type === import_utils20.AST_NODE_TYPES.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
3331
|
+
}
|
|
3332
|
+
var no_generic_single_export_module_default = createRule({
|
|
3333
|
+
name: "no-generic-single-export-module",
|
|
3334
|
+
meta: {
|
|
3335
|
+
type: "suggestion",
|
|
3336
|
+
docs: { description: "Disallow generic module stems when one runtime export already names the responsibility." },
|
|
3337
|
+
schema: [],
|
|
3338
|
+
messages: {
|
|
3339
|
+
genericSingleExport: "Module stem `{{stem}}` is generic and its only runtime export is `{{exported}}`; rename the file to `{{expected}}`."
|
|
3340
|
+
}
|
|
3341
|
+
},
|
|
3342
|
+
defaultOptions: [],
|
|
3343
|
+
create(context) {
|
|
3344
|
+
const file = fileParts(context.filename);
|
|
3345
|
+
const { stem: stem3 } = file;
|
|
3346
|
+
if (!GENERIC_STEMS.has(stem3) || CONVENTIONAL_STEMS.has(stem3) || isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text)) return {};
|
|
3347
|
+
let hasCommonJsExport = false;
|
|
3348
|
+
return {
|
|
3349
|
+
CallExpression(node) {
|
|
3350
|
+
const first = node.arguments[0];
|
|
3351
|
+
if (first?.type === import_utils20.AST_NODE_TYPES.Identifier && first.name === "exports" && isGlobalIdentifier(context, first) && node.callee.type === import_utils20.AST_NODE_TYPES.MemberExpression && node.callee.object.type === import_utils20.AST_NODE_TYPES.Identifier && node.callee.object.name === "Object" && isGlobalIdentifier(context, node.callee.object) && memberPropertyName(node.callee) !== null && CJS_OBJECT_EXPORT_METHODS.has(memberPropertyName(node.callee))) hasCommonJsExport = true;
|
|
3352
|
+
},
|
|
3353
|
+
MemberExpression(node) {
|
|
3354
|
+
if (node.object.type === import_utils20.AST_NODE_TYPES.Identifier && node.object.name === "exports" && isGlobalIdentifier(context, node.object)) hasCommonJsExport = true;
|
|
3355
|
+
if (node.object.type === import_utils20.AST_NODE_TYPES.Identifier && node.object.name === "module" && isGlobalIdentifier(context, node.object) && memberPropertyName(node) === "exports") hasCommonJsExport = true;
|
|
3356
|
+
},
|
|
3357
|
+
"Program:exit"(program) {
|
|
3358
|
+
if (hasCommonJsExport) return;
|
|
3359
|
+
const exports2 = runtimeExports(program);
|
|
3360
|
+
if (exports2.ambiguous || exports2.exports.length !== 1) return;
|
|
3361
|
+
const onlyExport = exports2.exports[0];
|
|
3362
|
+
if (onlyExport === void 0) return;
|
|
3363
|
+
const { name: exported, node } = onlyExport;
|
|
3364
|
+
if (isConventionalFrameworkUtility(context.filename, exported)) return;
|
|
3365
|
+
const expectedStem = kebabCase(exported);
|
|
3366
|
+
const suffixStem = file.suffixes.map(kebabCase).join("-");
|
|
3367
|
+
const currentResponsibility = [stem3, suffixStem].filter(Boolean).join("-");
|
|
3368
|
+
if (expectedStem === currentResponsibility || GENERIC_STEMS.has(expectedStem) || !/^[a-z0-9]+(?:-[a-z0-9]+)*$/u.test(expectedStem)) return;
|
|
3369
|
+
const suffixTail = suffixStem === "" ? "" : `-${suffixStem}`;
|
|
3370
|
+
const renameStem = suffixTail !== "" && expectedStem.endsWith(suffixTail) ? expectedStem.slice(0, -suffixTail.length) : expectedStem;
|
|
3371
|
+
if (renameStem === "" || GENERIC_STEMS.has(renameStem)) return;
|
|
3372
|
+
const suffix = file.suffixes.map((part) => `.${kebabCase(part)}`).join("");
|
|
3373
|
+
context.report({
|
|
3374
|
+
node,
|
|
3375
|
+
messageId: "genericSingleExport",
|
|
3376
|
+
data: { stem: stem3, exported, expected: `${renameStem}${suffix}${file.extension}` }
|
|
3377
|
+
});
|
|
3378
|
+
}
|
|
3379
|
+
};
|
|
3380
|
+
}
|
|
3381
|
+
});
|
|
3382
|
+
|
|
3383
|
+
// src/rules/no-offset-pagination.ts
|
|
3384
|
+
var import_utils21 = require("@typescript-eslint/utils");
|
|
3188
3385
|
var OFFSET_PAGINATION = /\bOFFSET\s+(?:%s|%\(\w+\)s|\?\d*|:\w+|@\w+|\$\d+|\d+)/i;
|
|
3189
3386
|
var OFFSET_GATE = /offset/i;
|
|
3190
3387
|
var no_offset_pagination_default = createRule({
|
|
@@ -3214,60 +3411,57 @@ var no_offset_pagination_default = createRule({
|
|
|
3214
3411
|
});
|
|
3215
3412
|
|
|
3216
3413
|
// src/rules/no-positional-tuple-return.ts
|
|
3217
|
-
var
|
|
3414
|
+
var import_utils22 = require("@typescript-eslint/utils");
|
|
3218
3415
|
var MIN_ELEMENTS = 2;
|
|
3219
|
-
var
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
if (node.type === import_utils21.AST_NODE_TYPES.TSTupleType) {
|
|
3416
|
+
var AWAITABLE_TYPES = /* @__PURE__ */ new Set(["Promise", "PromiseLike", "Awaited", "Readonly"]);
|
|
3417
|
+
function tupleReturnType(node, aliases, resolving = /* @__PURE__ */ new Set()) {
|
|
3418
|
+
if (node.type === import_utils22.AST_NODE_TYPES.TSTupleType) {
|
|
3223
3419
|
return node;
|
|
3224
3420
|
}
|
|
3225
|
-
if (node.type ===
|
|
3226
|
-
const argument = node.typeArguments?.params
|
|
3227
|
-
return argument === void 0 ? null : tupleReturnType(argument);
|
|
3421
|
+
if (node.type === import_utils22.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils22.AST_NODE_TYPES.Identifier && AWAITABLE_TYPES.has(node.typeName.name)) {
|
|
3422
|
+
const argument = node.typeArguments?.params.at(0);
|
|
3423
|
+
return argument === void 0 ? null : tupleReturnType(argument, aliases, resolving);
|
|
3228
3424
|
}
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
return sourceCode.getText(node).replaceAll(/\s+/g, " ").trim();
|
|
3233
|
-
}
|
|
3234
|
-
function isPermittedTuple(tuple, sourceCode) {
|
|
3235
|
-
const elements = tuple.elementTypes;
|
|
3236
|
-
if (elements.length < MIN_ELEMENTS) {
|
|
3237
|
-
return true;
|
|
3425
|
+
if (node.type === import_utils22.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils22.AST_NODE_TYPES.Identifier && !resolving.has(node.typeName.name)) {
|
|
3426
|
+
const target = aliases.get(node.typeName.name);
|
|
3427
|
+
if (target !== void 0) return tupleReturnType(target, aliases, /* @__PURE__ */ new Set([...resolving, node.typeName.name]));
|
|
3238
3428
|
}
|
|
3239
|
-
if (
|
|
3240
|
-
return
|
|
3429
|
+
if (node.type === import_utils22.AST_NODE_TYPES.TSTypeOperator && node.operator === "readonly") {
|
|
3430
|
+
return node.typeAnnotation === void 0 ? null : tupleReturnType(node.typeAnnotation, aliases, resolving);
|
|
3241
3431
|
}
|
|
3242
|
-
if (
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
}
|
|
3248
|
-
if (elements.length === ACCESSOR_PAIR_LENGTH && elements.some((element) => element.type === import_utils21.AST_NODE_TYPES.TSFunctionType)) {
|
|
3249
|
-
return true;
|
|
3432
|
+
if (node.type === import_utils22.AST_NODE_TYPES.TSUnionType || node.type === import_utils22.AST_NODE_TYPES.TSIntersectionType) {
|
|
3433
|
+
for (const member of node.types) {
|
|
3434
|
+
const tuple = tupleReturnType(member, aliases, resolving);
|
|
3435
|
+
if (tuple !== null) return tuple;
|
|
3436
|
+
}
|
|
3250
3437
|
}
|
|
3251
|
-
|
|
3252
|
-
return texts.size === 1;
|
|
3438
|
+
return null;
|
|
3253
3439
|
}
|
|
3254
3440
|
function functionName(node) {
|
|
3255
|
-
if (node.type ===
|
|
3256
|
-
|
|
3441
|
+
if (node.type === import_utils22.AST_NODE_TYPES.FunctionDeclaration) {
|
|
3442
|
+
if (node.id !== null) return node.id.name;
|
|
3443
|
+
return node.parent?.type === import_utils22.AST_NODE_TYPES.ExportDefaultDeclaration ? "default" : null;
|
|
3257
3444
|
}
|
|
3258
|
-
|
|
3259
|
-
|
|
3445
|
+
let wrapped = node;
|
|
3446
|
+
while ((wrapped.parent?.type === import_utils22.AST_NODE_TYPES.TSAsExpression || wrapped.parent?.type === import_utils22.AST_NODE_TYPES.TSSatisfiesExpression || wrapped.parent?.type === import_utils22.AST_NODE_TYPES.TSNonNullExpression) && wrapped.parent.expression === wrapped) {
|
|
3447
|
+
wrapped = wrapped.parent;
|
|
3448
|
+
}
|
|
3449
|
+
const parent = wrapped.parent;
|
|
3450
|
+
if (parent?.type === import_utils22.AST_NODE_TYPES.ExportDefaultDeclaration) return "default";
|
|
3451
|
+
if (parent?.type === import_utils22.AST_NODE_TYPES.VariableDeclarator && parent.id.type === import_utils22.AST_NODE_TYPES.Identifier) {
|
|
3260
3452
|
return parent.id.name;
|
|
3261
3453
|
}
|
|
3262
|
-
if ((parent?.type ===
|
|
3454
|
+
if ((parent?.type === import_utils22.AST_NODE_TYPES.MethodDefinition || parent?.type === import_utils22.AST_NODE_TYPES.TSAbstractMethodDefinition || parent?.type === import_utils22.AST_NODE_TYPES.PropertyDefinition || parent?.type === import_utils22.AST_NODE_TYPES.Property) && parent.key.type === import_utils22.AST_NODE_TYPES.Identifier) {
|
|
3455
|
+
if ((parent.type === import_utils22.AST_NODE_TYPES.MethodDefinition || parent.type === import_utils22.AST_NODE_TYPES.TSAbstractMethodDefinition || parent.type === import_utils22.AST_NODE_TYPES.PropertyDefinition) && (parent.accessibility === "private" || parent.accessibility === "protected")) return null;
|
|
3263
3456
|
return parent.key.name;
|
|
3264
3457
|
}
|
|
3265
3458
|
return null;
|
|
3266
3459
|
}
|
|
3267
3460
|
function isInlineExported(node) {
|
|
3461
|
+
if (moduleScopeBindingName(node) === null) return false;
|
|
3268
3462
|
for (let current = node; current != null; current = current.parent) {
|
|
3269
3463
|
const parent = current.parent;
|
|
3270
|
-
if (parent?.type ===
|
|
3464
|
+
if (parent?.type === import_utils22.AST_NODE_TYPES.ExportNamedDeclaration || parent?.type === import_utils22.AST_NODE_TYPES.ExportDefaultDeclaration) {
|
|
3271
3465
|
return true;
|
|
3272
3466
|
}
|
|
3273
3467
|
}
|
|
@@ -3275,46 +3469,154 @@ function isInlineExported(node) {
|
|
|
3275
3469
|
}
|
|
3276
3470
|
function moduleScopeBindingName(node) {
|
|
3277
3471
|
let current = node;
|
|
3278
|
-
|
|
3279
|
-
while (current.parent != null && current.parent.type !== import_utils21.AST_NODE_TYPES.Program) {
|
|
3280
|
-
child = current;
|
|
3472
|
+
while (current.parent != null && current.parent.type !== import_utils22.AST_NODE_TYPES.Program) {
|
|
3281
3473
|
current = current.parent;
|
|
3282
3474
|
}
|
|
3283
|
-
if (current.parent?.type !==
|
|
3475
|
+
if (current.parent?.type !== import_utils22.AST_NODE_TYPES.Program) {
|
|
3284
3476
|
return null;
|
|
3285
3477
|
}
|
|
3286
|
-
|
|
3287
|
-
|
|
3478
|
+
let topLevel = current;
|
|
3479
|
+
if (current.type === import_utils22.AST_NODE_TYPES.ExportNamedDeclaration || current.type === import_utils22.AST_NODE_TYPES.ExportDefaultDeclaration) {
|
|
3480
|
+
topLevel = current.declaration;
|
|
3288
3481
|
}
|
|
3289
|
-
if (
|
|
3290
|
-
|
|
3291
|
-
|
|
3482
|
+
if (topLevel === null) return null;
|
|
3483
|
+
if (topLevel.type === import_utils22.AST_NODE_TYPES.FunctionDeclaration) {
|
|
3484
|
+
if (topLevel !== node) return null;
|
|
3485
|
+
return topLevel.id?.name ?? (current.type === import_utils22.AST_NODE_TYPES.ExportDefaultDeclaration ? "default" : null);
|
|
3486
|
+
}
|
|
3487
|
+
if ((topLevel.type === import_utils22.AST_NODE_TYPES.ArrowFunctionExpression || topLevel.type === import_utils22.AST_NODE_TYPES.FunctionExpression) && topLevel === node && current.type === import_utils22.AST_NODE_TYPES.ExportDefaultDeclaration) {
|
|
3488
|
+
return "default";
|
|
3489
|
+
}
|
|
3490
|
+
if (topLevel.type === import_utils22.AST_NODE_TYPES.ClassDeclaration) {
|
|
3491
|
+
let owner = node.parent;
|
|
3492
|
+
while (owner !== void 0 && owner.parent !== topLevel.body) owner = owner.parent;
|
|
3493
|
+
return (owner?.type === import_utils22.AST_NODE_TYPES.MethodDefinition || owner?.type === import_utils22.AST_NODE_TYPES.TSAbstractMethodDefinition || owner?.type === import_utils22.AST_NODE_TYPES.PropertyDefinition) && owner.value === node ? topLevel.id?.name ?? (current.type === import_utils22.AST_NODE_TYPES.ExportDefaultDeclaration ? "default" : null) : null;
|
|
3494
|
+
}
|
|
3495
|
+
if (topLevel.type === import_utils22.AST_NODE_TYPES.VariableDeclaration) {
|
|
3496
|
+
for (const declarator of topLevel.declarations) {
|
|
3497
|
+
let initializer = declarator.init;
|
|
3498
|
+
while (initializer?.type === import_utils22.AST_NODE_TYPES.TSAsExpression || initializer?.type === import_utils22.AST_NODE_TYPES.TSSatisfiesExpression || initializer?.type === import_utils22.AST_NODE_TYPES.TSNonNullExpression) initializer = initializer.expression;
|
|
3499
|
+
if (declarator.id.type === import_utils22.AST_NODE_TYPES.Identifier && initializer === node) return declarator.id.name;
|
|
3500
|
+
if (declarator.id.type === import_utils22.AST_NODE_TYPES.Identifier && (initializer?.type === import_utils22.AST_NODE_TYPES.ClassExpression || initializer?.type === import_utils22.AST_NODE_TYPES.ObjectExpression)) {
|
|
3501
|
+
let owner = node.parent;
|
|
3502
|
+
const container = initializer.type === import_utils22.AST_NODE_TYPES.ClassExpression ? initializer.body : initializer;
|
|
3503
|
+
while (owner !== void 0 && owner.parent !== container) owner = owner.parent;
|
|
3504
|
+
if ((owner?.type === import_utils22.AST_NODE_TYPES.MethodDefinition || owner?.type === import_utils22.AST_NODE_TYPES.PropertyDefinition || owner?.type === import_utils22.AST_NODE_TYPES.Property) && owner.value === node) return declarator.id.name;
|
|
3505
|
+
}
|
|
3292
3506
|
}
|
|
3293
|
-
return child.id.name;
|
|
3294
3507
|
}
|
|
3295
3508
|
return null;
|
|
3296
3509
|
}
|
|
3297
3510
|
function specifierExportedNames(program) {
|
|
3298
3511
|
const names = /* @__PURE__ */ new Set();
|
|
3299
3512
|
for (const statement of program.body) {
|
|
3300
|
-
if (statement.type ===
|
|
3513
|
+
if (statement.type === import_utils22.AST_NODE_TYPES.ExportNamedDeclaration && statement.declaration == null && statement.source == null && statement.exportKind !== "type") {
|
|
3301
3514
|
for (const specifier of statement.specifiers) {
|
|
3302
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
3515
|
+
if (specifier.exportKind !== "type" && specifier.local.type === import_utils22.AST_NODE_TYPES.Identifier) {
|
|
3303
3516
|
names.add(specifier.local.name);
|
|
3304
3517
|
}
|
|
3305
3518
|
}
|
|
3306
3519
|
continue;
|
|
3307
3520
|
}
|
|
3308
|
-
if (statement.type ===
|
|
3521
|
+
if (statement.type === import_utils22.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils22.AST_NODE_TYPES.Identifier) {
|
|
3309
3522
|
names.add(statement.declaration.name);
|
|
3310
3523
|
continue;
|
|
3311
3524
|
}
|
|
3312
|
-
if (statement.type ===
|
|
3525
|
+
if (statement.type === import_utils22.AST_NODE_TYPES.TSExportAssignment && statement.expression.type === import_utils22.AST_NODE_TYPES.Identifier) {
|
|
3313
3526
|
names.add(statement.expression.name);
|
|
3314
3527
|
}
|
|
3315
3528
|
}
|
|
3316
3529
|
return names;
|
|
3317
3530
|
}
|
|
3531
|
+
function exportedTypeNames(program) {
|
|
3532
|
+
const names = /* @__PURE__ */ new Set();
|
|
3533
|
+
for (const statement of program.body) {
|
|
3534
|
+
if (statement.type !== import_utils22.AST_NODE_TYPES.ExportNamedDeclaration || statement.source !== null) continue;
|
|
3535
|
+
if (statement.declaration?.type === import_utils22.AST_NODE_TYPES.TSInterfaceDeclaration || statement.declaration?.type === import_utils22.AST_NODE_TYPES.TSTypeAliasDeclaration) names.add(statement.declaration.id.name);
|
|
3536
|
+
for (const specifier of statement.specifiers) names.add(specifier.local.name);
|
|
3537
|
+
}
|
|
3538
|
+
for (const statement of program.body) {
|
|
3539
|
+
if (statement.type === import_utils22.AST_NODE_TYPES.ExportDefaultDeclaration && (statement.declaration.type === import_utils22.AST_NODE_TYPES.TSInterfaceDeclaration || statement.declaration.type === import_utils22.AST_NODE_TYPES.TSTypeAliasDeclaration)) names.add(statement.declaration.id.name);
|
|
3540
|
+
}
|
|
3541
|
+
return names;
|
|
3542
|
+
}
|
|
3543
|
+
function typeAliases(program) {
|
|
3544
|
+
const aliases = /* @__PURE__ */ new Map();
|
|
3545
|
+
for (const statement of program.body) {
|
|
3546
|
+
const declaration = statement.type === import_utils22.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
3547
|
+
if (declaration?.type === import_utils22.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
3548
|
+
aliases.set(declaration.id.name, declaration.typeAnnotation);
|
|
3549
|
+
}
|
|
3550
|
+
}
|
|
3551
|
+
return aliases;
|
|
3552
|
+
}
|
|
3553
|
+
function callableReturnType(node, aliases, resolving = /* @__PURE__ */ new Set()) {
|
|
3554
|
+
if (node.type === import_utils22.AST_NODE_TYPES.TSFunctionType) return node.returnType?.typeAnnotation ?? null;
|
|
3555
|
+
if (node.type === import_utils22.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils22.AST_NODE_TYPES.Identifier && !resolving.has(node.typeName.name)) {
|
|
3556
|
+
const target = aliases.get(node.typeName.name);
|
|
3557
|
+
if (target !== void 0) {
|
|
3558
|
+
return callableReturnType(target, aliases, /* @__PURE__ */ new Set([...resolving, node.typeName.name]));
|
|
3559
|
+
}
|
|
3560
|
+
}
|
|
3561
|
+
return null;
|
|
3562
|
+
}
|
|
3563
|
+
function publiclyReachableTypeNames(program, exported) {
|
|
3564
|
+
const names = new Set(exported);
|
|
3565
|
+
const interfaces = /* @__PURE__ */ new Map();
|
|
3566
|
+
for (const statement of program.body) {
|
|
3567
|
+
const declaration = statement.type === import_utils22.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
3568
|
+
if (declaration?.type === import_utils22.AST_NODE_TYPES.TSInterfaceDeclaration) {
|
|
3569
|
+
interfaces.set(declaration.id.name, declaration.extends);
|
|
3570
|
+
}
|
|
3571
|
+
}
|
|
3572
|
+
for (let pass = 0; pass < interfaces.size; pass += 1) {
|
|
3573
|
+
let changed = false;
|
|
3574
|
+
for (const name of [...names]) {
|
|
3575
|
+
for (const heritage of interfaces.get(name) ?? []) {
|
|
3576
|
+
if (heritage.expression.type === import_utils22.AST_NODE_TYPES.Identifier && !names.has(heritage.expression.name)) {
|
|
3577
|
+
names.add(heritage.expression.name);
|
|
3578
|
+
changed = true;
|
|
3579
|
+
}
|
|
3580
|
+
}
|
|
3581
|
+
}
|
|
3582
|
+
if (!changed) break;
|
|
3583
|
+
}
|
|
3584
|
+
return names;
|
|
3585
|
+
}
|
|
3586
|
+
function owningInterface(node) {
|
|
3587
|
+
for (let current = node.parent; current !== void 0; current = current.parent) {
|
|
3588
|
+
if (current.type === import_utils22.AST_NODE_TYPES.TSInterfaceDeclaration) return current;
|
|
3589
|
+
if (current.type === import_utils22.AST_NODE_TYPES.Program) return null;
|
|
3590
|
+
}
|
|
3591
|
+
return null;
|
|
3592
|
+
}
|
|
3593
|
+
function owningTypeAlias(node) {
|
|
3594
|
+
for (let current = node.parent; current !== void 0; current = current.parent) {
|
|
3595
|
+
if (current.type === import_utils22.AST_NODE_TYPES.TSTypeAliasDeclaration) return current;
|
|
3596
|
+
if (current.type === import_utils22.AST_NODE_TYPES.Program) return null;
|
|
3597
|
+
}
|
|
3598
|
+
return null;
|
|
3599
|
+
}
|
|
3600
|
+
function owningClass(node) {
|
|
3601
|
+
for (let current = node.parent; current !== void 0; current = current.parent) {
|
|
3602
|
+
if (current.type === import_utils22.AST_NODE_TYPES.ClassDeclaration || current.type === import_utils22.AST_NODE_TYPES.ClassExpression) {
|
|
3603
|
+
return current;
|
|
3604
|
+
}
|
|
3605
|
+
if (current.type === import_utils22.AST_NODE_TYPES.Program) return null;
|
|
3606
|
+
}
|
|
3607
|
+
return null;
|
|
3608
|
+
}
|
|
3609
|
+
function isExportedClass(node, specifierExports) {
|
|
3610
|
+
if (node.parent.type === import_utils22.AST_NODE_TYPES.ExportNamedDeclaration || node.parent.type === import_utils22.AST_NODE_TYPES.ExportDefaultDeclaration) return true;
|
|
3611
|
+
if (node.type === import_utils22.AST_NODE_TYPES.ClassDeclaration) {
|
|
3612
|
+
return node.id !== null && node.parent.type === import_utils22.AST_NODE_TYPES.Program && specifierExports.has(node.id.name);
|
|
3613
|
+
}
|
|
3614
|
+
if (node.parent.type === import_utils22.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === import_utils22.AST_NODE_TYPES.Identifier) return specifierExports.has(node.parent.id.name) || isInlineExported(node);
|
|
3615
|
+
return false;
|
|
3616
|
+
}
|
|
3617
|
+
function isExportedInterface(node, exports2) {
|
|
3618
|
+
return node.parent.type === import_utils22.AST_NODE_TYPES.ExportNamedDeclaration || node.parent.type === import_utils22.AST_NODE_TYPES.ExportDefaultDeclaration || node.parent.type === import_utils22.AST_NODE_TYPES.Program && exports2.has(node.id.name);
|
|
3619
|
+
}
|
|
3318
3620
|
function isExported(node, specifierExports) {
|
|
3319
3621
|
if (isInlineExported(node)) {
|
|
3320
3622
|
return true;
|
|
@@ -3330,48 +3632,97 @@ var no_positional_tuple_return_default = createRule({
|
|
|
3330
3632
|
meta: {
|
|
3331
3633
|
type: "suggestion",
|
|
3332
3634
|
docs: {
|
|
3333
|
-
description: "Disallow returning a
|
|
3635
|
+
description: "Disallow returning a multi-field tuple from an exported function; return a named object so call sites cannot mismatch slots."
|
|
3334
3636
|
},
|
|
3335
3637
|
schema: [],
|
|
3336
3638
|
messages: {
|
|
3337
|
-
noPositionalTupleReturn: "Exported `{{name}}` returns a
|
|
3639
|
+
noPositionalTupleReturn: "Exported `{{name}}` returns a {{count}}-field tuple, so consumers depend on positional slots that can be reordered silently. Return a named object instead."
|
|
3338
3640
|
}
|
|
3339
3641
|
},
|
|
3340
3642
|
defaultOptions: [],
|
|
3341
3643
|
create(context) {
|
|
3644
|
+
if (isGeneratedFile(context.filename, context.sourceCode.text)) return {};
|
|
3342
3645
|
const specifierExports = specifierExportedNames(context.sourceCode.ast);
|
|
3646
|
+
const typeExports = publiclyReachableTypeNames(
|
|
3647
|
+
context.sourceCode.ast,
|
|
3648
|
+
exportedTypeNames(context.sourceCode.ast)
|
|
3649
|
+
);
|
|
3650
|
+
const aliases = typeAliases(context.sourceCode.ast);
|
|
3651
|
+
const report = (annotation, name) => {
|
|
3652
|
+
const tuple = tupleReturnType(annotation, aliases);
|
|
3653
|
+
if (tuple === null || tuple.elementTypes.length < MIN_ELEMENTS) return;
|
|
3654
|
+
context.report({
|
|
3655
|
+
node: tuple,
|
|
3656
|
+
messageId: "noPositionalTupleReturn",
|
|
3657
|
+
data: { name, count: String(tuple.elementTypes.length) }
|
|
3658
|
+
});
|
|
3659
|
+
};
|
|
3343
3660
|
const check = (node) => {
|
|
3344
3661
|
const annotation = node.returnType?.typeAnnotation;
|
|
3345
3662
|
if (annotation === void 0) {
|
|
3346
3663
|
return;
|
|
3347
3664
|
}
|
|
3348
|
-
const tuple = tupleReturnType(annotation);
|
|
3349
|
-
if (tuple === null || isPermittedTuple(tuple, context.sourceCode)) {
|
|
3350
|
-
return;
|
|
3351
|
-
}
|
|
3352
3665
|
const name = functionName(node);
|
|
3353
|
-
if (name === null
|
|
3666
|
+
if (name === null) {
|
|
3354
3667
|
return;
|
|
3355
3668
|
}
|
|
3356
3669
|
if (!isExported(node, specifierExports)) {
|
|
3357
3670
|
return;
|
|
3358
3671
|
}
|
|
3359
|
-
|
|
3360
|
-
node: tuple,
|
|
3361
|
-
messageId: "noPositionalTupleReturn",
|
|
3362
|
-
data: { name, count: String(tuple.elementTypes.length) }
|
|
3363
|
-
});
|
|
3672
|
+
report(annotation, name);
|
|
3364
3673
|
};
|
|
3365
3674
|
return {
|
|
3366
3675
|
FunctionDeclaration: check,
|
|
3367
3676
|
FunctionExpression: check,
|
|
3368
|
-
ArrowFunctionExpression: check
|
|
3677
|
+
ArrowFunctionExpression: check,
|
|
3678
|
+
TSEmptyBodyFunctionExpression: check,
|
|
3679
|
+
TSDeclareFunction(node) {
|
|
3680
|
+
if (node.id === null || node.returnType === void 0 || node.parent.type !== import_utils22.AST_NODE_TYPES.ExportNamedDeclaration && node.parent.type !== import_utils22.AST_NODE_TYPES.ExportDefaultDeclaration && !specifierExports.has(node.id.name)) return;
|
|
3681
|
+
report(node.returnType.typeAnnotation, node.id.name);
|
|
3682
|
+
},
|
|
3683
|
+
TSCallSignatureDeclaration(node) {
|
|
3684
|
+
const owner = owningInterface(node);
|
|
3685
|
+
if (owner === null || !isExportedInterface(owner, typeExports) || node.returnType === void 0) return;
|
|
3686
|
+
report(node.returnType.typeAnnotation, `${owner.id.name}.call`);
|
|
3687
|
+
},
|
|
3688
|
+
TSMethodSignature(node) {
|
|
3689
|
+
const owner = owningInterface(node);
|
|
3690
|
+
const alias = owningTypeAlias(node);
|
|
3691
|
+
if ((owner === null || !isExportedInterface(owner, typeExports)) && (alias === null || !typeExports.has(alias.id.name)) || node.returnType === void 0 || node.key.type !== import_utils22.AST_NODE_TYPES.Identifier) return;
|
|
3692
|
+
report(node.returnType.typeAnnotation, `${owner?.id.name ?? alias?.id.name ?? "type"}.${node.key.name}`);
|
|
3693
|
+
},
|
|
3694
|
+
TSTypeAliasDeclaration(node) {
|
|
3695
|
+
if (!typeExports.has(node.id.name)) return;
|
|
3696
|
+
const returnType = callableReturnType(node.typeAnnotation, aliases);
|
|
3697
|
+
if (returnType !== null) report(returnType, node.id.name);
|
|
3698
|
+
},
|
|
3699
|
+
TSPropertySignature(node) {
|
|
3700
|
+
const owner = owningInterface(node);
|
|
3701
|
+
const alias = owningTypeAlias(node);
|
|
3702
|
+
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
3703
|
+
if ((owner === null || !isExportedInterface(owner, typeExports)) && (alias === null || !typeExports.has(alias.id.name)) || node.key.type !== import_utils22.AST_NODE_TYPES.Identifier || annotation === void 0) return;
|
|
3704
|
+
const returnType = callableReturnType(annotation, aliases);
|
|
3705
|
+
if (returnType !== null) {
|
|
3706
|
+
report(returnType, `${owner?.id.name ?? alias?.id.name ?? "type"}.${node.key.name}`);
|
|
3707
|
+
}
|
|
3708
|
+
},
|
|
3709
|
+
PropertyDefinition(node) {
|
|
3710
|
+
if (node.accessibility === "private" || node.accessibility === "protected") return;
|
|
3711
|
+
const owner = owningClass(node);
|
|
3712
|
+
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
3713
|
+
if (owner === null || !isExportedClass(owner, specifierExports) || annotation === void 0) return;
|
|
3714
|
+
const returnType = callableReturnType(annotation, aliases);
|
|
3715
|
+
if (returnType !== null) {
|
|
3716
|
+
const name = node.key.type === import_utils22.AST_NODE_TYPES.Identifier ? node.key.name : "property";
|
|
3717
|
+
report(returnType, name);
|
|
3718
|
+
}
|
|
3719
|
+
}
|
|
3369
3720
|
};
|
|
3370
3721
|
}
|
|
3371
3722
|
});
|
|
3372
3723
|
|
|
3373
3724
|
// src/rules/no-raw-env.ts
|
|
3374
|
-
var
|
|
3725
|
+
var import_utils23 = require("@typescript-eslint/utils");
|
|
3375
3726
|
var CONFIG_FILE_RE = /(^|[\\/])[\w.-]+\.config\.[cm]?[jt]sx?$/;
|
|
3376
3727
|
var ENV_BOUNDARY_FILE_RE = /(^|[\\/])(?:env|client-env|server-env|client-settings|server-settings)\.[cm]?[jt]sx?$/;
|
|
3377
3728
|
var ENV_VALIDATION_MARKER_RE = /\bcreateEnv\s*\(|\bz\.object\s*\(|\.(?:safeParse|parse)\s*\(/;
|
|
@@ -3448,7 +3799,7 @@ var no_raw_env_default = createRule({
|
|
|
3448
3799
|
});
|
|
3449
3800
|
|
|
3450
3801
|
// src/rules/no-raw-fetch-outside-clients.ts
|
|
3451
|
-
var
|
|
3802
|
+
var import_utils24 = require("@typescript-eslint/utils");
|
|
3452
3803
|
var DEFAULT_ALLOW = [
|
|
3453
3804
|
"[\\\\/]clients?[\\\\/]",
|
|
3454
3805
|
"-client\\.[cm]?[jt]sx?$",
|
|
@@ -3490,7 +3841,7 @@ function identifierLikeName(node) {
|
|
|
3490
3841
|
}
|
|
3491
3842
|
function isConstructedArgumentHandoff(node) {
|
|
3492
3843
|
const [first] = node.arguments;
|
|
3493
|
-
return node.arguments.length === 1 && first !== void 0 && first.type ===
|
|
3844
|
+
return node.arguments.length === 1 && first !== void 0 && first.type === import_utils24.AST_NODE_TYPES.NewExpression;
|
|
3494
3845
|
}
|
|
3495
3846
|
function isPresignedUrlTransfer(node) {
|
|
3496
3847
|
const first = node.arguments[0];
|
|
@@ -3559,9 +3910,9 @@ var no_raw_fetch_outside_clients_default = createRule({
|
|
|
3559
3910
|
});
|
|
3560
3911
|
|
|
3561
3912
|
// src/rules/no-restricted-library-load.ts
|
|
3562
|
-
var
|
|
3913
|
+
var import_utils25 = require("@typescript-eslint/utils");
|
|
3563
3914
|
function literalModule(node) {
|
|
3564
|
-
return node?.type ===
|
|
3915
|
+
return node?.type === import_utils25.AST_NODE_TYPES.Literal && typeof node.value === "string" ? node.value : null;
|
|
3565
3916
|
}
|
|
3566
3917
|
function matchesModule(source, module2) {
|
|
3567
3918
|
return source === module2 || source.startsWith(`${module2}/`);
|
|
@@ -3620,7 +3971,7 @@ var no_restricted_library_load_default = createRule({
|
|
|
3620
3971
|
});
|
|
3621
3972
|
}
|
|
3622
3973
|
function isUnshadowedRequire(node) {
|
|
3623
|
-
const variable =
|
|
3974
|
+
const variable = import_utils25.ASTUtils.findVariable(
|
|
3624
3975
|
context.sourceCode.getScope(node),
|
|
3625
3976
|
node.name
|
|
3626
3977
|
);
|
|
@@ -3633,9 +3984,9 @@ var no_restricted_library_load_default = createRule({
|
|
|
3633
3984
|
},
|
|
3634
3985
|
CallExpression(node) {
|
|
3635
3986
|
let requireIdentifier = null;
|
|
3636
|
-
if (node.callee.type ===
|
|
3987
|
+
if (node.callee.type === import_utils25.AST_NODE_TYPES.Identifier && node.callee.name === "require") {
|
|
3637
3988
|
requireIdentifier = node.callee;
|
|
3638
|
-
} else if (node.callee.type ===
|
|
3989
|
+
} else if (node.callee.type === import_utils25.AST_NODE_TYPES.MemberExpression && !node.callee.computed && node.callee.object.type === import_utils25.AST_NODE_TYPES.Identifier && node.callee.object.name === "require" && node.callee.property.type === import_utils25.AST_NODE_TYPES.Identifier && node.callee.property.name === "resolve") {
|
|
3639
3990
|
requireIdentifier = node.callee.object;
|
|
3640
3991
|
}
|
|
3641
3992
|
if (requireIdentifier === null || !isUnshadowedRequire(requireIdentifier)) return;
|
|
@@ -3643,7 +3994,7 @@ var no_restricted_library_load_default = createRule({
|
|
|
3643
3994
|
if (source !== null) report(node.arguments[0], source);
|
|
3644
3995
|
},
|
|
3645
3996
|
TSImportEqualsDeclaration(node) {
|
|
3646
|
-
if (node.moduleReference.type !==
|
|
3997
|
+
if (node.moduleReference.type !== import_utils25.AST_NODE_TYPES.TSExternalModuleReference) return;
|
|
3647
3998
|
const source = literalModule(node.moduleReference.expression);
|
|
3648
3999
|
if (source !== null) report(node.moduleReference.expression, source);
|
|
3649
4000
|
}
|
|
@@ -3652,16 +4003,16 @@ var no_restricted_library_load_default = createRule({
|
|
|
3652
4003
|
});
|
|
3653
4004
|
|
|
3654
4005
|
// src/rules/no-repeated-string-literal.ts
|
|
3655
|
-
var
|
|
4006
|
+
var import_utils26 = require("@typescript-eslint/utils");
|
|
3656
4007
|
var MIN_LENGTH = 40;
|
|
3657
4008
|
var MIN_DISTINCT_SCOPES = 2;
|
|
3658
4009
|
var PREVIEW_LENGTH = 40;
|
|
3659
4010
|
var SQL_KEYWORD_RE = /\b(SELECT|INSERT|UPDATE|DELETE|FROM|WHERE|JOIN|VALUES|ON CONFLICT|RETURNING|GROUP BY|ORDER BY)\b/;
|
|
3660
4011
|
var IDENTIFIER_RE = /^[a-z_][a-z0-9_.]*$/;
|
|
3661
4012
|
var FUNCTION_TYPES3 = /* @__PURE__ */ new Set([
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
4013
|
+
import_utils26.AST_NODE_TYPES.FunctionDeclaration,
|
|
4014
|
+
import_utils26.AST_NODE_TYPES.FunctionExpression,
|
|
4015
|
+
import_utils26.AST_NODE_TYPES.ArrowFunctionExpression
|
|
3665
4016
|
]);
|
|
3666
4017
|
function isStructured(value) {
|
|
3667
4018
|
return value.includes("\n") || SQL_KEYWORD_RE.test(value) || IDENTIFIER_RE.test(value);
|
|
@@ -3683,8 +4034,8 @@ function isScaffolding(node) {
|
|
|
3683
4034
|
if (parent === void 0) {
|
|
3684
4035
|
return true;
|
|
3685
4036
|
}
|
|
3686
|
-
const isRequireSource = parent.type ===
|
|
3687
|
-
return parent.type ===
|
|
4037
|
+
const isRequireSource = parent.type === import_utils26.AST_NODE_TYPES.CallExpression && parent.callee.type === import_utils26.AST_NODE_TYPES.Identifier && parent.callee.name === "require";
|
|
4038
|
+
return parent.type === import_utils26.AST_NODE_TYPES.ImportDeclaration || parent.type === import_utils26.AST_NODE_TYPES.ImportExpression || parent.type === import_utils26.AST_NODE_TYPES.ExportNamedDeclaration || parent.type === import_utils26.AST_NODE_TYPES.ExportAllDeclaration || parent.type === import_utils26.AST_NODE_TYPES.TSImportType || parent.type === import_utils26.AST_NODE_TYPES.JSXAttribute || parent.type === import_utils26.AST_NODE_TYPES.TSLiteralType || isRequireSource;
|
|
3688
4039
|
}
|
|
3689
4040
|
var no_repeated_string_literal_default = createRule({
|
|
3690
4041
|
name: "no-repeated-string-literal",
|
|
@@ -3724,7 +4075,7 @@ var no_repeated_string_literal_default = createRule({
|
|
|
3724
4075
|
}
|
|
3725
4076
|
},
|
|
3726
4077
|
TemplateLiteral(node) {
|
|
3727
|
-
if (node.parent.type ===
|
|
4078
|
+
if (node.parent.type === import_utils26.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
3728
4079
|
return;
|
|
3729
4080
|
}
|
|
3730
4081
|
const [only] = node.quasis;
|
|
@@ -3758,7 +4109,7 @@ var no_repeated_string_literal_default = createRule({
|
|
|
3758
4109
|
});
|
|
3759
4110
|
|
|
3760
4111
|
// src/rules/no-restated-comment.ts
|
|
3761
|
-
var
|
|
4112
|
+
var import_utils27 = require("@typescript-eslint/utils");
|
|
3762
4113
|
var MAX_WORDS = 8;
|
|
3763
4114
|
var MIN_CONTENT_TOKENS = 2;
|
|
3764
4115
|
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;
|
|
@@ -3811,7 +4162,7 @@ var no_restated_comment_default = createRule({
|
|
|
3811
4162
|
function labelsASiblingRun(comment) {
|
|
3812
4163
|
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
3813
4164
|
if (token === null) return false;
|
|
3814
|
-
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !==
|
|
4165
|
+
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !== import_utils27.AST_NODE_TYPES.Program; node = node.parent) {
|
|
3815
4166
|
if (headsSiblingRun(node)) return true;
|
|
3816
4167
|
}
|
|
3817
4168
|
return false;
|
|
@@ -3871,7 +4222,7 @@ var no_restated_comment_default = createRule({
|
|
|
3871
4222
|
});
|
|
3872
4223
|
|
|
3873
4224
|
// src/rules/no-restated-jsdoc.ts
|
|
3874
|
-
var
|
|
4225
|
+
var import_utils28 = require("@typescript-eslint/utils");
|
|
3875
4226
|
var MODELLED_TAGS = /* @__PURE__ */ new Set([
|
|
3876
4227
|
"arg",
|
|
3877
4228
|
"argument",
|
|
@@ -3925,30 +4276,30 @@ function declarationNames(node) {
|
|
|
3925
4276
|
switch (node.type) {
|
|
3926
4277
|
// `export function f()` — the JSDoc sits above the `export`, so the token
|
|
3927
4278
|
// after it resolves to the wrapper, not to the thing being documented.
|
|
3928
|
-
case
|
|
3929
|
-
case
|
|
4279
|
+
case import_utils28.AST_NODE_TYPES.ExportNamedDeclaration:
|
|
4280
|
+
case import_utils28.AST_NODE_TYPES.ExportDefaultDeclaration:
|
|
3930
4281
|
return node.declaration == null ? null : declarationNames(node.declaration);
|
|
3931
|
-
case
|
|
3932
|
-
case
|
|
4282
|
+
case import_utils28.AST_NODE_TYPES.FunctionDeclaration:
|
|
4283
|
+
case import_utils28.AST_NODE_TYPES.TSDeclareFunction:
|
|
3933
4284
|
return node.id === null ? null : { name: node.id.name, params: paramNames(node.params) };
|
|
3934
|
-
case
|
|
3935
|
-
case
|
|
3936
|
-
case
|
|
3937
|
-
case
|
|
4285
|
+
case import_utils28.AST_NODE_TYPES.ClassDeclaration:
|
|
4286
|
+
case import_utils28.AST_NODE_TYPES.TSInterfaceDeclaration:
|
|
4287
|
+
case import_utils28.AST_NODE_TYPES.TSTypeAliasDeclaration:
|
|
4288
|
+
case import_utils28.AST_NODE_TYPES.TSEnumDeclaration:
|
|
3938
4289
|
return node.id === null ? null : { name: node.id.name, params: [] };
|
|
3939
|
-
case
|
|
4290
|
+
case import_utils28.AST_NODE_TYPES.VariableDeclaration: {
|
|
3940
4291
|
const declarator = node.declarations[0];
|
|
3941
|
-
if (declarator === void 0 || declarator.id.type !==
|
|
4292
|
+
if (declarator === void 0 || declarator.id.type !== import_utils28.AST_NODE_TYPES.Identifier) return null;
|
|
3942
4293
|
const init = declarator.init;
|
|
3943
|
-
const params = init != null && (init.type ===
|
|
4294
|
+
const params = init != null && (init.type === import_utils28.AST_NODE_TYPES.ArrowFunctionExpression || init.type === import_utils28.AST_NODE_TYPES.FunctionExpression) ? paramNames(init.params) : [];
|
|
3944
4295
|
return { name: declarator.id.name, params };
|
|
3945
4296
|
}
|
|
3946
|
-
case
|
|
3947
|
-
case
|
|
3948
|
-
case
|
|
3949
|
-
case
|
|
3950
|
-
if (node.key.type !==
|
|
3951
|
-
const params = node.type ===
|
|
4297
|
+
case import_utils28.AST_NODE_TYPES.MethodDefinition:
|
|
4298
|
+
case import_utils28.AST_NODE_TYPES.PropertyDefinition:
|
|
4299
|
+
case import_utils28.AST_NODE_TYPES.TSMethodSignature:
|
|
4300
|
+
case import_utils28.AST_NODE_TYPES.TSPropertySignature: {
|
|
4301
|
+
if (node.key.type !== import_utils28.AST_NODE_TYPES.Identifier) return null;
|
|
4302
|
+
const params = node.type === import_utils28.AST_NODE_TYPES.MethodDefinition ? paramNames(node.value.params) : node.type === import_utils28.AST_NODE_TYPES.TSMethodSignature ? paramNames(node.params) : [];
|
|
3952
4303
|
return { name: node.key.name, params };
|
|
3953
4304
|
}
|
|
3954
4305
|
default:
|
|
@@ -3958,9 +4309,9 @@ function declarationNames(node) {
|
|
|
3958
4309
|
function paramNames(params) {
|
|
3959
4310
|
const names = [];
|
|
3960
4311
|
for (const param of params) {
|
|
3961
|
-
const target = param.type ===
|
|
3962
|
-
if (target.type ===
|
|
3963
|
-
else if (target.type ===
|
|
4312
|
+
const target = param.type === import_utils28.AST_NODE_TYPES.AssignmentPattern ? param.left : param;
|
|
4313
|
+
if (target.type === import_utils28.AST_NODE_TYPES.Identifier) names.push(target.name);
|
|
4314
|
+
else if (target.type === import_utils28.AST_NODE_TYPES.TSParameterProperty) continue;
|
|
3964
4315
|
}
|
|
3965
4316
|
return names;
|
|
3966
4317
|
}
|
|
@@ -4002,7 +4353,7 @@ var no_restated_jsdoc_default = createRule({
|
|
|
4002
4353
|
if (token === null || token.loc.start.line !== comment.loc.end.line + 1) continue;
|
|
4003
4354
|
let node = sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
4004
4355
|
let declaration = null;
|
|
4005
|
-
while (node != null && node.type !==
|
|
4356
|
+
while (node != null && node.type !== import_utils28.AST_NODE_TYPES.Program) {
|
|
4006
4357
|
declaration = declarationNames(node);
|
|
4007
4358
|
if (declaration !== null) break;
|
|
4008
4359
|
node = node.parent ?? null;
|
|
@@ -4057,7 +4408,7 @@ var no_restated_jsdoc_default = createRule({
|
|
|
4057
4408
|
});
|
|
4058
4409
|
|
|
4059
4410
|
// src/rules/no-secret-in-log.ts
|
|
4060
|
-
var
|
|
4411
|
+
var import_utils29 = require("@typescript-eslint/utils");
|
|
4061
4412
|
|
|
4062
4413
|
// src/rules/_secret-names.ts
|
|
4063
4414
|
var SECRET_WORDS = /* @__PURE__ */ new Set([
|
|
@@ -4394,7 +4745,7 @@ var no_secret_in_log_default = createRule({
|
|
|
4394
4745
|
});
|
|
4395
4746
|
|
|
4396
4747
|
// src/rules/no-select-star.ts
|
|
4397
|
-
var
|
|
4748
|
+
var import_utils30 = require("@typescript-eslint/utils");
|
|
4398
4749
|
var QUERY_SHAPE = /\bSELECT\b[\s\S]*?\bFROM\b/i;
|
|
4399
4750
|
var SELECT_KEYWORD = /\bSELECT\b/gi;
|
|
4400
4751
|
var FROM_KEYWORD = /^FROM\b/i;
|
|
@@ -4461,12 +4812,12 @@ var no_select_star_default = createRule({
|
|
|
4461
4812
|
});
|
|
4462
4813
|
|
|
4463
4814
|
// src/rules/no-sentinel-return-on-catch.ts
|
|
4464
|
-
var
|
|
4815
|
+
var import_utils31 = require("@typescript-eslint/utils");
|
|
4465
4816
|
function sentinelKind(arg) {
|
|
4466
4817
|
if (arg === null) {
|
|
4467
4818
|
return null;
|
|
4468
4819
|
}
|
|
4469
|
-
if (arg.type ===
|
|
4820
|
+
if (arg.type === import_utils31.AST_NODE_TYPES.Literal) {
|
|
4470
4821
|
if (arg.value === null) {
|
|
4471
4822
|
return "nullish";
|
|
4472
4823
|
}
|
|
@@ -4478,13 +4829,13 @@ function sentinelKind(arg) {
|
|
|
4478
4829
|
}
|
|
4479
4830
|
return null;
|
|
4480
4831
|
}
|
|
4481
|
-
if (arg.type ===
|
|
4832
|
+
if (arg.type === import_utils31.AST_NODE_TYPES.Identifier && arg.name === "undefined") {
|
|
4482
4833
|
return "nullish";
|
|
4483
4834
|
}
|
|
4484
|
-
if (arg.type ===
|
|
4835
|
+
if (arg.type === import_utils31.AST_NODE_TYPES.ArrayExpression) {
|
|
4485
4836
|
return "array";
|
|
4486
4837
|
}
|
|
4487
|
-
if (arg.type ===
|
|
4838
|
+
if (arg.type === import_utils31.AST_NODE_TYPES.ObjectExpression) {
|
|
4488
4839
|
return "object";
|
|
4489
4840
|
}
|
|
4490
4841
|
return null;
|
|
@@ -4493,25 +4844,25 @@ function isSentinelArgument(arg) {
|
|
|
4493
4844
|
if (arg === null) {
|
|
4494
4845
|
return false;
|
|
4495
4846
|
}
|
|
4496
|
-
if (arg.type ===
|
|
4847
|
+
if (arg.type === import_utils31.AST_NODE_TYPES.Literal && arg.value === null) {
|
|
4497
4848
|
return true;
|
|
4498
4849
|
}
|
|
4499
|
-
if (arg.type ===
|
|
4850
|
+
if (arg.type === import_utils31.AST_NODE_TYPES.Literal && arg.value === false) {
|
|
4500
4851
|
return true;
|
|
4501
4852
|
}
|
|
4502
|
-
if (arg.type ===
|
|
4853
|
+
if (arg.type === import_utils31.AST_NODE_TYPES.Identifier && arg.name === "undefined") {
|
|
4503
4854
|
return true;
|
|
4504
4855
|
}
|
|
4505
|
-
if (arg.type ===
|
|
4856
|
+
if (arg.type === import_utils31.AST_NODE_TYPES.ArrayExpression && arg.elements.length === 0) {
|
|
4506
4857
|
return true;
|
|
4507
4858
|
}
|
|
4508
|
-
if (arg.type ===
|
|
4859
|
+
if (arg.type === import_utils31.AST_NODE_TYPES.ObjectExpression && arg.properties.length === 0) {
|
|
4509
4860
|
return true;
|
|
4510
4861
|
}
|
|
4511
4862
|
return false;
|
|
4512
4863
|
}
|
|
4513
4864
|
function isFunctionNode(node) {
|
|
4514
|
-
return node.type ===
|
|
4865
|
+
return node.type === import_utils31.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils31.AST_NODE_TYPES.FunctionExpression || node.type === import_utils31.AST_NODE_TYPES.ArrowFunctionExpression;
|
|
4515
4866
|
}
|
|
4516
4867
|
function isNode3(value) {
|
|
4517
4868
|
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
@@ -4551,24 +4902,24 @@ function walkWithinScope(node, visit) {
|
|
|
4551
4902
|
function containsThrow(node) {
|
|
4552
4903
|
return walkWithinScope(
|
|
4553
4904
|
node,
|
|
4554
|
-
(current) => current.type ===
|
|
4905
|
+
(current) => current.type === import_utils31.AST_NODE_TYPES.ThrowStatement
|
|
4555
4906
|
);
|
|
4556
4907
|
}
|
|
4557
4908
|
function bindsName(param, name) {
|
|
4558
4909
|
switch (param.type) {
|
|
4559
|
-
case
|
|
4910
|
+
case import_utils31.AST_NODE_TYPES.Identifier:
|
|
4560
4911
|
return param.name === name;
|
|
4561
|
-
case
|
|
4912
|
+
case import_utils31.AST_NODE_TYPES.AssignmentPattern:
|
|
4562
4913
|
return bindsName(param.left, name);
|
|
4563
|
-
case
|
|
4914
|
+
case import_utils31.AST_NODE_TYPES.RestElement:
|
|
4564
4915
|
return bindsName(param.argument, name);
|
|
4565
|
-
case
|
|
4916
|
+
case import_utils31.AST_NODE_TYPES.ArrayPattern:
|
|
4566
4917
|
return param.elements.some(
|
|
4567
4918
|
(element) => element !== null && bindsName(element, name)
|
|
4568
4919
|
);
|
|
4569
|
-
case
|
|
4920
|
+
case import_utils31.AST_NODE_TYPES.ObjectPattern:
|
|
4570
4921
|
return param.properties.some(
|
|
4571
|
-
(property) => property.type ===
|
|
4922
|
+
(property) => property.type === import_utils31.AST_NODE_TYPES.RestElement ? bindsName(property.argument, name) : bindsName(property.value, name)
|
|
4572
4923
|
);
|
|
4573
4924
|
default:
|
|
4574
4925
|
return false;
|
|
@@ -4583,7 +4934,7 @@ function subtreeReadsName(node, name) {
|
|
|
4583
4934
|
if (found) {
|
|
4584
4935
|
return;
|
|
4585
4936
|
}
|
|
4586
|
-
if (current.type ===
|
|
4937
|
+
if (current.type === import_utils31.AST_NODE_TYPES.Identifier && current.name === name) {
|
|
4587
4938
|
found = true;
|
|
4588
4939
|
return;
|
|
4589
4940
|
}
|
|
@@ -4594,10 +4945,10 @@ function subtreeReadsName(node, name) {
|
|
|
4594
4945
|
if (key === "parent") {
|
|
4595
4946
|
continue;
|
|
4596
4947
|
}
|
|
4597
|
-
if (key === "key" && current.type ===
|
|
4948
|
+
if (key === "key" && current.type === import_utils31.AST_NODE_TYPES.Property && !current.computed) {
|
|
4598
4949
|
continue;
|
|
4599
4950
|
}
|
|
4600
|
-
if (key === "property" && current.type ===
|
|
4951
|
+
if (key === "property" && current.type === import_utils31.AST_NODE_TYPES.MemberExpression && !current.computed) {
|
|
4601
4952
|
continue;
|
|
4602
4953
|
}
|
|
4603
4954
|
const value = current[key];
|
|
@@ -4630,10 +4981,10 @@ var SAFE_PARSE_CONSTRUCTORS = /* @__PURE__ */ new Set([
|
|
|
4630
4981
|
"URLPattern"
|
|
4631
4982
|
]);
|
|
4632
4983
|
function isParseShapedNode(node) {
|
|
4633
|
-
if (node.type ===
|
|
4984
|
+
if (node.type === import_utils31.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils31.AST_NODE_TYPES.MemberExpression && !node.callee.computed && node.callee.property.type === import_utils31.AST_NODE_TYPES.Identifier) {
|
|
4634
4985
|
return node.callee.property.name === "parse";
|
|
4635
4986
|
}
|
|
4636
|
-
if (node.type ===
|
|
4987
|
+
if (node.type === import_utils31.AST_NODE_TYPES.NewExpression && node.callee.type === import_utils31.AST_NODE_TYPES.Identifier) {
|
|
4637
4988
|
return SAFE_PARSE_CONSTRUCTORS.has(node.callee.name);
|
|
4638
4989
|
}
|
|
4639
4990
|
return false;
|
|
@@ -4644,10 +4995,10 @@ var BODY_DECODE_METHODS = /* @__PURE__ */ new Set([
|
|
|
4644
4995
|
"arrayBuffer"
|
|
4645
4996
|
]);
|
|
4646
4997
|
function isBodyDecodeNode(node) {
|
|
4647
|
-
return node.type ===
|
|
4998
|
+
return node.type === import_utils31.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils31.AST_NODE_TYPES.MemberExpression && !node.callee.computed && node.callee.property.type === import_utils31.AST_NODE_TYPES.Identifier && BODY_DECODE_METHODS.has(node.callee.property.name);
|
|
4648
4999
|
}
|
|
4649
5000
|
function returnsMatching(stmt, predicate) {
|
|
4650
|
-
return stmt.type ===
|
|
5001
|
+
return stmt.type === import_utils31.AST_NODE_TYPES.ReturnStatement && stmt.argument !== null && walkWithinScope(stmt.argument, predicate);
|
|
4651
5002
|
}
|
|
4652
5003
|
function enclosingReturnTypeNode(node) {
|
|
4653
5004
|
let current = node.parent;
|
|
@@ -4665,11 +5016,11 @@ function enclosingFunctionName(node) {
|
|
|
4665
5016
|
let current = node.parent;
|
|
4666
5017
|
while (current !== void 0 && current !== null) {
|
|
4667
5018
|
if (isFunctionNode(current)) {
|
|
4668
|
-
if ("id" in current && isNode3(current.id) && current.id.type ===
|
|
5019
|
+
if ("id" in current && isNode3(current.id) && current.id.type === import_utils31.AST_NODE_TYPES.Identifier) {
|
|
4669
5020
|
return current.id.name;
|
|
4670
5021
|
}
|
|
4671
5022
|
const parent = current.parent;
|
|
4672
|
-
if (parent?.type ===
|
|
5023
|
+
if (parent?.type === import_utils31.AST_NODE_TYPES.VariableDeclarator && parent.id.type === import_utils31.AST_NODE_TYPES.Identifier) {
|
|
4673
5024
|
return parent.id.name;
|
|
4674
5025
|
}
|
|
4675
5026
|
return null;
|
|
@@ -4690,10 +5041,10 @@ function isDeclaredBooleanPredicate(catchNode, kind) {
|
|
|
4690
5041
|
return false;
|
|
4691
5042
|
}
|
|
4692
5043
|
let declared = enclosingReturnTypeNode(catchNode);
|
|
4693
|
-
if (declared?.type ===
|
|
5044
|
+
if (declared?.type === import_utils31.AST_NODE_TYPES.TSTypeReference && declared.typeName.type === import_utils31.AST_NODE_TYPES.Identifier && declared.typeName.name === "Promise") {
|
|
4694
5045
|
declared = declared.typeArguments?.params[0] ?? null;
|
|
4695
5046
|
}
|
|
4696
|
-
return declared?.type ===
|
|
5047
|
+
return declared?.type === import_utils31.AST_NODE_TYPES.TSBooleanKeyword;
|
|
4697
5048
|
}
|
|
4698
5049
|
function tryReturnsSafeParse(catchNode) {
|
|
4699
5050
|
const tryBlock = tryBlockOf(catchNode);
|
|
@@ -4709,7 +5060,7 @@ function tryReturnsSafeParse(catchNode) {
|
|
|
4709
5060
|
function enclosingFunctionBody(node) {
|
|
4710
5061
|
let current = node.parent;
|
|
4711
5062
|
while (current !== void 0 && current !== null) {
|
|
4712
|
-
if (isFunctionNode(current) && "body" in current && isNode3(current.body) && current.body.type ===
|
|
5063
|
+
if (isFunctionNode(current) && "body" in current && isNode3(current.body) && current.body.type === import_utils31.AST_NODE_TYPES.BlockStatement) {
|
|
4713
5064
|
return current.body;
|
|
4714
5065
|
}
|
|
4715
5066
|
current = current.parent;
|
|
@@ -4722,7 +5073,7 @@ function functionReturnsSameSentinelKindElsewhere(catchNode, kind) {
|
|
|
4722
5073
|
return false;
|
|
4723
5074
|
}
|
|
4724
5075
|
return walkWithinScope(functionBody, (current) => {
|
|
4725
|
-
if (current.type !==
|
|
5076
|
+
if (current.type !== import_utils31.AST_NODE_TYPES.ReturnStatement) {
|
|
4726
5077
|
return false;
|
|
4727
5078
|
}
|
|
4728
5079
|
if (isWithin(current, catchNode.body)) {
|
|
@@ -4741,13 +5092,13 @@ function returnedSentinelKinds(arg) {
|
|
|
4741
5092
|
kinds.add(direct);
|
|
4742
5093
|
return kinds;
|
|
4743
5094
|
}
|
|
4744
|
-
if (arg.type ===
|
|
5095
|
+
if (arg.type === import_utils31.AST_NODE_TYPES.ConditionalExpression) {
|
|
4745
5096
|
for (const branch of [arg.consequent, arg.alternate]) {
|
|
4746
5097
|
for (const nested of returnedSentinelKinds(branch)) {
|
|
4747
5098
|
kinds.add(nested);
|
|
4748
5099
|
}
|
|
4749
5100
|
}
|
|
4750
|
-
} else if (arg.type ===
|
|
5101
|
+
} else if (arg.type === import_utils31.AST_NODE_TYPES.LogicalExpression && (arg.operator === "??" || arg.operator === "||")) {
|
|
4751
5102
|
for (const nested of returnedSentinelKinds(arg.right)) {
|
|
4752
5103
|
kinds.add(nested);
|
|
4753
5104
|
}
|
|
@@ -4790,7 +5141,7 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
4790
5141
|
const matcher = createLogMatcher(loggingOptions);
|
|
4791
5142
|
function logsOrReportsError(catchBody, caughtName) {
|
|
4792
5143
|
return walkWithinScope(catchBody, (current) => {
|
|
4793
|
-
if (current.type !==
|
|
5144
|
+
if (current.type !== import_utils31.AST_NODE_TYPES.CallExpression) {
|
|
4794
5145
|
return false;
|
|
4795
5146
|
}
|
|
4796
5147
|
if (matcher.isLoggingCall(current)) {
|
|
@@ -4807,7 +5158,7 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
4807
5158
|
return;
|
|
4808
5159
|
}
|
|
4809
5160
|
const last = body2[body2.length - 1];
|
|
4810
|
-
if (last === void 0 || last.type !==
|
|
5161
|
+
if (last === void 0 || last.type !== import_utils31.AST_NODE_TYPES.ReturnStatement) {
|
|
4811
5162
|
return;
|
|
4812
5163
|
}
|
|
4813
5164
|
if (!isSentinelArgument(last.argument)) {
|
|
@@ -4816,7 +5167,7 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
4816
5167
|
if (containsThrow(node.body)) {
|
|
4817
5168
|
return;
|
|
4818
5169
|
}
|
|
4819
|
-
const caughtName = node.param?.type ===
|
|
5170
|
+
const caughtName = node.param?.type === import_utils31.AST_NODE_TYPES.Identifier ? node.param.name : null;
|
|
4820
5171
|
if (logsOrReportsError(node.body, caughtName)) {
|
|
4821
5172
|
return;
|
|
4822
5173
|
}
|
|
@@ -4843,9 +5194,9 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
4843
5194
|
});
|
|
4844
5195
|
|
|
4845
5196
|
// src/rules/no-silent-promise-catch.ts
|
|
4846
|
-
var
|
|
5197
|
+
var import_utils32 = require("@typescript-eslint/utils");
|
|
4847
5198
|
function isBodyParseCall(node) {
|
|
4848
|
-
return node.type ===
|
|
5199
|
+
return node.type === import_utils32.AST_NODE_TYPES.CallExpression && node.arguments.length === 0 && node.callee.type === import_utils32.AST_NODE_TYPES.MemberExpression && !node.callee.computed && node.callee.property.type === import_utils32.AST_NODE_TYPES.Identifier && (node.callee.property.name === "json" || node.callee.property.name === "text");
|
|
4849
5200
|
}
|
|
4850
5201
|
var TEARDOWN_METHODS = /* @__PURE__ */ new Set([
|
|
4851
5202
|
"cancel",
|
|
@@ -4860,21 +5211,21 @@ var TEARDOWN_METHODS = /* @__PURE__ */ new Set([
|
|
|
4860
5211
|
var DIRECTIVE_COMMENT_RE = /^\s*(eslint-|@ts-|prettier-ignore|biome-ignore|c8 |v8 |istanbul )/;
|
|
4861
5212
|
var isExplanatory = (comment) => !DIRECTIVE_COMMENT_RE.test(comment.value);
|
|
4862
5213
|
function isTeardownCall(node) {
|
|
4863
|
-
return node.type ===
|
|
5214
|
+
return node.type === import_utils32.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils32.AST_NODE_TYPES.MemberExpression && !node.callee.computed && node.callee.property.type === import_utils32.AST_NODE_TYPES.Identifier && TEARDOWN_METHODS.has(node.callee.property.name);
|
|
4864
5215
|
}
|
|
4865
5216
|
function isSilentExpression(node) {
|
|
4866
5217
|
switch (node.type) {
|
|
4867
|
-
case
|
|
5218
|
+
case import_utils32.AST_NODE_TYPES.Literal:
|
|
4868
5219
|
return !("regex" in node);
|
|
4869
|
-
case
|
|
5220
|
+
case import_utils32.AST_NODE_TYPES.Identifier:
|
|
4870
5221
|
return node.name === "undefined";
|
|
4871
|
-
case
|
|
4872
|
-
return node.operator === "void" && node.argument.type ===
|
|
4873
|
-
case
|
|
5222
|
+
case import_utils32.AST_NODE_TYPES.UnaryExpression:
|
|
5223
|
+
return node.operator === "void" && node.argument.type === import_utils32.AST_NODE_TYPES.Literal;
|
|
5224
|
+
case import_utils32.AST_NODE_TYPES.ObjectExpression:
|
|
4874
5225
|
return node.properties.length === 0;
|
|
4875
|
-
case
|
|
5226
|
+
case import_utils32.AST_NODE_TYPES.ArrayExpression:
|
|
4876
5227
|
return node.elements.length === 0;
|
|
4877
|
-
case
|
|
5228
|
+
case import_utils32.AST_NODE_TYPES.TSAsExpression:
|
|
4878
5229
|
return isSilentExpression(node.expression);
|
|
4879
5230
|
default:
|
|
4880
5231
|
return false;
|
|
@@ -4882,7 +5233,7 @@ function isSilentExpression(node) {
|
|
|
4882
5233
|
}
|
|
4883
5234
|
function isSilentHandler(handler) {
|
|
4884
5235
|
const body2 = handler.body;
|
|
4885
|
-
if (body2.type !==
|
|
5236
|
+
if (body2.type !== import_utils32.AST_NODE_TYPES.BlockStatement) {
|
|
4886
5237
|
return isSilentExpression(body2);
|
|
4887
5238
|
}
|
|
4888
5239
|
if (body2.body.length === 0) {
|
|
@@ -4890,7 +5241,7 @@ function isSilentHandler(handler) {
|
|
|
4890
5241
|
}
|
|
4891
5242
|
if (body2.body.length === 1) {
|
|
4892
5243
|
const only = body2.body[0];
|
|
4893
|
-
if (only !== void 0 && only.type ===
|
|
5244
|
+
if (only !== void 0 && only.type === import_utils32.AST_NODE_TYPES.ReturnStatement) {
|
|
4894
5245
|
return only.argument === null || isSilentExpression(only.argument);
|
|
4895
5246
|
}
|
|
4896
5247
|
}
|
|
@@ -4919,7 +5270,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
4919
5270
|
return true;
|
|
4920
5271
|
}
|
|
4921
5272
|
let statement = call;
|
|
4922
|
-
while (statement.parent !== void 0 && statement.parent !== null && !statement.type.endsWith("Statement") && statement.type !==
|
|
5273
|
+
while (statement.parent !== void 0 && statement.parent !== null && !statement.type.endsWith("Statement") && statement.type !== import_utils32.AST_NODE_TYPES.VariableDeclaration) {
|
|
4923
5274
|
statement = statement.parent;
|
|
4924
5275
|
}
|
|
4925
5276
|
if (sourceCode.getCommentsBefore(statement).some(isExplanatory)) {
|
|
@@ -4931,7 +5282,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
4931
5282
|
};
|
|
4932
5283
|
return {
|
|
4933
5284
|
CallExpression(node) {
|
|
4934
|
-
if (node.callee.type !==
|
|
5285
|
+
if (node.callee.type !== import_utils32.AST_NODE_TYPES.MemberExpression || node.callee.computed || node.callee.property.type !== import_utils32.AST_NODE_TYPES.Identifier || node.callee.property.name !== "catch") {
|
|
4935
5286
|
return;
|
|
4936
5287
|
}
|
|
4937
5288
|
if (isBodyParseCall(node.callee.object)) {
|
|
@@ -4940,14 +5291,14 @@ var no_silent_promise_catch_default = createRule({
|
|
|
4940
5291
|
if (isTeardownCall(node.callee.object)) {
|
|
4941
5292
|
return;
|
|
4942
5293
|
}
|
|
4943
|
-
if (node.parent.type ===
|
|
5294
|
+
if (node.parent.type === import_utils32.AST_NODE_TYPES.MemberExpression && node.parent.object === node) {
|
|
4944
5295
|
return;
|
|
4945
5296
|
}
|
|
4946
5297
|
if (node.arguments.length !== 1) {
|
|
4947
5298
|
return;
|
|
4948
5299
|
}
|
|
4949
5300
|
const handler = node.arguments[0];
|
|
4950
|
-
if (handler === void 0 || handler.type !==
|
|
5301
|
+
if (handler === void 0 || handler.type !== import_utils32.AST_NODE_TYPES.ArrowFunctionExpression && handler.type !== import_utils32.AST_NODE_TYPES.FunctionExpression) {
|
|
4951
5302
|
return;
|
|
4952
5303
|
}
|
|
4953
5304
|
if (hasExplanatoryComment(node, handler)) {
|
|
@@ -4962,7 +5313,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
4962
5313
|
});
|
|
4963
5314
|
|
|
4964
5315
|
// src/rules/no-sleep-in-test-body.ts
|
|
4965
|
-
var
|
|
5316
|
+
var import_utils33 = require("@typescript-eslint/utils");
|
|
4966
5317
|
var SLEEP_HELPERS = /* @__PURE__ */ new Set(["sleep", "delay", "wait", "pause"]);
|
|
4967
5318
|
var TEST_CALLERS2 = /* @__PURE__ */ new Set([
|
|
4968
5319
|
"it",
|
|
@@ -4971,34 +5322,34 @@ var TEST_CALLERS2 = /* @__PURE__ */ new Set([
|
|
|
4971
5322
|
"afterEach"
|
|
4972
5323
|
]);
|
|
4973
5324
|
var FUNCTION_TYPES4 = /* @__PURE__ */ new Set([
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
5325
|
+
import_utils33.AST_NODE_TYPES.FunctionDeclaration,
|
|
5326
|
+
import_utils33.AST_NODE_TYPES.FunctionExpression,
|
|
5327
|
+
import_utils33.AST_NODE_TYPES.ArrowFunctionExpression
|
|
4977
5328
|
]);
|
|
4978
5329
|
function isNonzeroNumericLiteral(node) {
|
|
4979
|
-
return node?.type ===
|
|
5330
|
+
return node?.type === import_utils33.AST_NODE_TYPES.Literal && typeof node.value === "number" && node.value !== 0;
|
|
4980
5331
|
}
|
|
4981
5332
|
function isTimedSetTimeout(node) {
|
|
4982
|
-
return node.type ===
|
|
5333
|
+
return node.type === import_utils33.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils33.AST_NODE_TYPES.Identifier && node.callee.name === "setTimeout" && node.arguments.length >= 2 && isNonzeroNumericLiteral(node.arguments[1]);
|
|
4983
5334
|
}
|
|
4984
5335
|
function isPromiseSleep(node) {
|
|
4985
|
-
if (node.callee.type !==
|
|
5336
|
+
if (node.callee.type !== import_utils33.AST_NODE_TYPES.Identifier || node.callee.name !== "Promise") {
|
|
4986
5337
|
return false;
|
|
4987
5338
|
}
|
|
4988
5339
|
const executor = node.arguments[0];
|
|
4989
|
-
if (executor?.type !==
|
|
5340
|
+
if (executor?.type !== import_utils33.AST_NODE_TYPES.ArrowFunctionExpression && executor?.type !== import_utils33.AST_NODE_TYPES.FunctionExpression) {
|
|
4990
5341
|
return false;
|
|
4991
5342
|
}
|
|
4992
5343
|
const body2 = executor.body;
|
|
4993
|
-
if (body2.type !==
|
|
5344
|
+
if (body2.type !== import_utils33.AST_NODE_TYPES.BlockStatement) {
|
|
4994
5345
|
return isTimedSetTimeout(body2);
|
|
4995
5346
|
}
|
|
4996
5347
|
return body2.body.some(
|
|
4997
|
-
(stmt) => stmt.type ===
|
|
5348
|
+
(stmt) => stmt.type === import_utils33.AST_NODE_TYPES.ExpressionStatement && isTimedSetTimeout(stmt.expression)
|
|
4998
5349
|
);
|
|
4999
5350
|
}
|
|
5000
5351
|
function isHelperSleep(node) {
|
|
5001
|
-
return node.callee.type ===
|
|
5352
|
+
return node.callee.type === import_utils33.AST_NODE_TYPES.Identifier && SLEEP_HELPERS.has(node.callee.name) && node.arguments.length >= 1 && isNonzeroNumericLiteral(node.arguments[0]);
|
|
5002
5353
|
}
|
|
5003
5354
|
function nearestEnclosingFunction2(node) {
|
|
5004
5355
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
@@ -5006,7 +5357,7 @@ function nearestEnclosingFunction2(node) {
|
|
|
5006
5357
|
continue;
|
|
5007
5358
|
}
|
|
5008
5359
|
const grandparent = current.parent;
|
|
5009
|
-
const isPromiseExecutor = grandparent?.type ===
|
|
5360
|
+
const isPromiseExecutor = grandparent?.type === import_utils33.AST_NODE_TYPES.NewExpression && isPromiseSleep(grandparent);
|
|
5010
5361
|
if (!isPromiseExecutor) {
|
|
5011
5362
|
return current;
|
|
5012
5363
|
}
|
|
@@ -5014,23 +5365,23 @@ function nearestEnclosingFunction2(node) {
|
|
|
5014
5365
|
return null;
|
|
5015
5366
|
}
|
|
5016
5367
|
function testCallerName2(callee) {
|
|
5017
|
-
if (callee.type ===
|
|
5368
|
+
if (callee.type === import_utils33.AST_NODE_TYPES.Identifier) {
|
|
5018
5369
|
return callee.name;
|
|
5019
5370
|
}
|
|
5020
|
-
if (callee.type ===
|
|
5371
|
+
if (callee.type === import_utils33.AST_NODE_TYPES.MemberExpression) {
|
|
5021
5372
|
return testCallerName2(callee.object);
|
|
5022
5373
|
}
|
|
5023
|
-
if (callee.type ===
|
|
5374
|
+
if (callee.type === import_utils33.AST_NODE_TYPES.CallExpression) {
|
|
5024
5375
|
return testCallerName2(callee.callee);
|
|
5025
5376
|
}
|
|
5026
|
-
if (callee.type ===
|
|
5377
|
+
if (callee.type === import_utils33.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
5027
5378
|
return testCallerName2(callee.tag);
|
|
5028
5379
|
}
|
|
5029
5380
|
return null;
|
|
5030
5381
|
}
|
|
5031
5382
|
function isTestBody2(fn) {
|
|
5032
5383
|
const call = fn.parent;
|
|
5033
|
-
if (call?.type !==
|
|
5384
|
+
if (call?.type !== import_utils33.AST_NODE_TYPES.CallExpression || !call.arguments.some((argument) => argument === fn)) {
|
|
5034
5385
|
return false;
|
|
5035
5386
|
}
|
|
5036
5387
|
const name = testCallerName2(call.callee);
|
|
@@ -5076,7 +5427,7 @@ var no_sleep_in_test_body_default = createRule({
|
|
|
5076
5427
|
});
|
|
5077
5428
|
|
|
5078
5429
|
// src/rules/no-storage-in-stateless-modules.ts
|
|
5079
|
-
var
|
|
5430
|
+
var import_utils34 = require("@typescript-eslint/utils");
|
|
5080
5431
|
var DEFAULT_METHODS2 = [
|
|
5081
5432
|
"prepare",
|
|
5082
5433
|
"put",
|
|
@@ -5095,7 +5446,7 @@ function compile2(patterns) {
|
|
|
5095
5446
|
}
|
|
5096
5447
|
function storageMethodName(node, methods) {
|
|
5097
5448
|
const callee = node.callee;
|
|
5098
|
-
if (callee.type !==
|
|
5449
|
+
if (callee.type !== import_utils34.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils34.AST_NODE_TYPES.Identifier) {
|
|
5099
5450
|
return null;
|
|
5100
5451
|
}
|
|
5101
5452
|
const name = callee.property.name;
|
|
@@ -5163,7 +5514,7 @@ var no_storage_in_stateless_modules_default = createRule({
|
|
|
5163
5514
|
});
|
|
5164
5515
|
|
|
5165
5516
|
// src/rules/no-string-concat-in-loop.ts
|
|
5166
|
-
var
|
|
5517
|
+
var import_utils35 = require("@typescript-eslint/utils");
|
|
5167
5518
|
var LOOP_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
5168
5519
|
"ForStatement",
|
|
5169
5520
|
"ForOfStatement",
|
|
@@ -5309,7 +5660,7 @@ var no_string_concat_in_loop_default = createRule({
|
|
|
5309
5660
|
});
|
|
5310
5661
|
|
|
5311
5662
|
// src/rules/no-tautological-expect.ts
|
|
5312
|
-
var
|
|
5663
|
+
var import_utils36 = require("@typescript-eslint/utils");
|
|
5313
5664
|
var EQUALITY_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
5314
5665
|
var ZERO_ARG_MATCHERS = /* @__PURE__ */ new Set([
|
|
5315
5666
|
"toBeDefined",
|
|
@@ -5323,17 +5674,17 @@ var OPERAND_PREVIEW_CHARS = 40;
|
|
|
5323
5674
|
var NUMERIC_SIGNS = /* @__PURE__ */ new Set(["-", "+"]);
|
|
5324
5675
|
function isLiteral(node) {
|
|
5325
5676
|
switch (node.type) {
|
|
5326
|
-
case
|
|
5677
|
+
case import_utils36.AST_NODE_TYPES.Literal:
|
|
5327
5678
|
return true;
|
|
5328
|
-
case
|
|
5679
|
+
case import_utils36.AST_NODE_TYPES.TemplateLiteral:
|
|
5329
5680
|
return node.expressions.length === 0;
|
|
5330
|
-
case
|
|
5681
|
+
case import_utils36.AST_NODE_TYPES.UnaryExpression:
|
|
5331
5682
|
return NUMERIC_SIGNS.has(node.operator) && isLiteral(node.argument);
|
|
5332
|
-
case
|
|
5683
|
+
case import_utils36.AST_NODE_TYPES.ArrayExpression:
|
|
5333
5684
|
return node.elements.every((element) => element !== null && isLiteral(element));
|
|
5334
|
-
case
|
|
5685
|
+
case import_utils36.AST_NODE_TYPES.ObjectExpression:
|
|
5335
5686
|
return node.properties.every(
|
|
5336
|
-
(property) => property.type ===
|
|
5687
|
+
(property) => property.type === import_utils36.AST_NODE_TYPES.Property && !property.computed && isLiteral(property.value)
|
|
5337
5688
|
);
|
|
5338
5689
|
default:
|
|
5339
5690
|
return false;
|
|
@@ -5341,7 +5692,7 @@ function isLiteral(node) {
|
|
|
5341
5692
|
}
|
|
5342
5693
|
function expectOperand(callee) {
|
|
5343
5694
|
const receiver = callee.object;
|
|
5344
|
-
if (receiver.type !==
|
|
5695
|
+
if (receiver.type !== import_utils36.AST_NODE_TYPES.CallExpression || receiver.callee.type !== import_utils36.AST_NODE_TYPES.Identifier || receiver.callee.name !== "expect" || receiver.arguments.length !== 1) {
|
|
5345
5696
|
return null;
|
|
5346
5697
|
}
|
|
5347
5698
|
return receiver.arguments[0] ?? null;
|
|
@@ -5371,10 +5722,10 @@ var no_tautological_expect_default = createRule({
|
|
|
5371
5722
|
return {
|
|
5372
5723
|
CallExpression(node) {
|
|
5373
5724
|
const callee = node.callee;
|
|
5374
|
-
if (callee.type !==
|
|
5725
|
+
if (callee.type !== import_utils36.AST_NODE_TYPES.MemberExpression || callee.computed) {
|
|
5375
5726
|
return;
|
|
5376
5727
|
}
|
|
5377
|
-
if (callee.property.type !==
|
|
5728
|
+
if (callee.property.type !== import_utils36.AST_NODE_TYPES.Identifier) {
|
|
5378
5729
|
return;
|
|
5379
5730
|
}
|
|
5380
5731
|
const matcher = callee.property.name;
|
|
@@ -5433,7 +5784,7 @@ var no_typed_doc_sections_default = createRule({
|
|
|
5433
5784
|
});
|
|
5434
5785
|
|
|
5435
5786
|
// src/rules/no-trailing-value-narration.ts
|
|
5436
|
-
var
|
|
5787
|
+
var import_utils37 = require("@typescript-eslint/utils");
|
|
5437
5788
|
var NUMBER_RE = /(?<![\w.])(\d+(?:\.\d+)?)(?![\w.])/g;
|
|
5438
5789
|
var WORD_RE3 = /[A-Za-z]+(?:'[a-z]+)?|\d+(?:\.\d+)?/g;
|
|
5439
5790
|
var UNIT_WORDS = /* @__PURE__ */ new Set([
|
|
@@ -5568,10 +5919,10 @@ var no_trailing_value_narration_default = createRule({
|
|
|
5568
5919
|
});
|
|
5569
5920
|
|
|
5570
5921
|
// src/rules/no-declaration-comment-wall.ts
|
|
5571
|
-
var
|
|
5922
|
+
var import_utils39 = require("@typescript-eslint/utils");
|
|
5572
5923
|
|
|
5573
5924
|
// src/rules/_comment-wall.ts
|
|
5574
|
-
var
|
|
5925
|
+
var import_utils38 = require("@typescript-eslint/utils");
|
|
5575
5926
|
var WALL_DEFAULTS = {
|
|
5576
5927
|
// Below three rows "a wall" is not a fair description of what the reader sees.
|
|
5577
5928
|
minCommentedMembers: 3,
|
|
@@ -5675,10 +6026,10 @@ function isWall(members, commented, restated, options) {
|
|
|
5675
6026
|
return commented >= options.minCommentedMembers && commented / members >= options.minCommentedRatio && restated / commented >= options.minRestatedRatio;
|
|
5676
6027
|
}
|
|
5677
6028
|
var OPAQUE_VALUE_TYPES = /* @__PURE__ */ new Set([
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
|
|
6029
|
+
import_utils38.AST_NODE_TYPES.FunctionExpression,
|
|
6030
|
+
import_utils38.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
6031
|
+
import_utils38.AST_NODE_TYPES.ObjectExpression,
|
|
6032
|
+
import_utils38.AST_NODE_TYPES.ArrayExpression
|
|
5682
6033
|
]);
|
|
5683
6034
|
function declarationRange(member) {
|
|
5684
6035
|
const body2 = bodyOf(member);
|
|
@@ -5686,10 +6037,10 @@ function declarationRange(member) {
|
|
|
5686
6037
|
return [member.range[0], body2.range[0]];
|
|
5687
6038
|
}
|
|
5688
6039
|
function bodyOf(member) {
|
|
5689
|
-
if (member.type ===
|
|
6040
|
+
if (member.type === import_utils38.AST_NODE_TYPES.MethodDefinition || member.type === import_utils38.AST_NODE_TYPES.TSAbstractMethodDefinition) {
|
|
5690
6041
|
return member.value.body ?? void 0;
|
|
5691
6042
|
}
|
|
5692
|
-
if (member.type ===
|
|
6043
|
+
if (member.type === import_utils38.AST_NODE_TYPES.Property || member.type === import_utils38.AST_NODE_TYPES.PropertyDefinition) {
|
|
5693
6044
|
const value = member.value;
|
|
5694
6045
|
if (value !== null && OPAQUE_VALUE_TYPES.has(value.type)) return value;
|
|
5695
6046
|
}
|
|
@@ -5699,12 +6050,12 @@ function bodyOf(member) {
|
|
|
5699
6050
|
// src/rules/no-declaration-comment-wall.ts
|
|
5700
6051
|
function named(node) {
|
|
5701
6052
|
switch (node.type) {
|
|
5702
|
-
case
|
|
6053
|
+
case import_utils39.AST_NODE_TYPES.TSEnumMember:
|
|
5703
6054
|
return { node, key: node.id };
|
|
5704
|
-
case
|
|
5705
|
-
case
|
|
5706
|
-
case
|
|
5707
|
-
case
|
|
6055
|
+
case import_utils39.AST_NODE_TYPES.PropertyDefinition:
|
|
6056
|
+
case import_utils39.AST_NODE_TYPES.TSAbstractPropertyDefinition:
|
|
6057
|
+
case import_utils39.AST_NODE_TYPES.MethodDefinition:
|
|
6058
|
+
case import_utils39.AST_NODE_TYPES.TSAbstractMethodDefinition:
|
|
5708
6059
|
return node.computed ? void 0 : { node, key: node.key };
|
|
5709
6060
|
default:
|
|
5710
6061
|
return void 0;
|
|
@@ -5804,7 +6155,7 @@ var no_declaration_comment_wall_default = createRule({
|
|
|
5804
6155
|
});
|
|
5805
6156
|
|
|
5806
6157
|
// src/rules/no-union-in-comment.ts
|
|
5807
|
-
var
|
|
6158
|
+
var import_utils40 = require("@typescript-eslint/utils");
|
|
5808
6159
|
var MAX_LITERAL_LENGTH = 28;
|
|
5809
6160
|
var LITERAL = String.raw`(?:'[^'\n]*'|"[^"\n]*"|\`[^\`\n]*\`)`;
|
|
5810
6161
|
var LEAD_IN_RE2 = /^(?:one of|either|values?|allowed(?: values)?|options?|possible(?: values)?)\s*[:=-]?\s*/i;
|
|
@@ -5823,14 +6174,14 @@ var STRING_BUILDERS = /* @__PURE__ */ new Set([
|
|
|
5823
6174
|
function isBareString(node) {
|
|
5824
6175
|
if (node === void 0) return false;
|
|
5825
6176
|
switch (node.type) {
|
|
5826
|
-
case
|
|
6177
|
+
case import_utils40.AST_NODE_TYPES.TSStringKeyword:
|
|
5827
6178
|
return true;
|
|
5828
6179
|
// `string[]` holds members of the same closed set, one element at a time.
|
|
5829
|
-
case
|
|
6180
|
+
case import_utils40.AST_NODE_TYPES.TSArrayType:
|
|
5830
6181
|
return isBareString(node.elementType);
|
|
5831
6182
|
// `string | null` is still an unconstrained string, and so is `string | "a"`
|
|
5832
6183
|
// — the checker collapses that one to `string`.
|
|
5833
|
-
case
|
|
6184
|
+
case import_utils40.AST_NODE_TYPES.TSUnionType:
|
|
5834
6185
|
return node.types.some((member) => isBareString(member));
|
|
5835
6186
|
default:
|
|
5836
6187
|
return false;
|
|
@@ -5840,13 +6191,13 @@ function rootCallee(node) {
|
|
|
5840
6191
|
let current = node;
|
|
5841
6192
|
for (let hops = 0; current != null && hops < 12; hops += 1) {
|
|
5842
6193
|
switch (current.type) {
|
|
5843
|
-
case
|
|
6194
|
+
case import_utils40.AST_NODE_TYPES.CallExpression:
|
|
5844
6195
|
current = current.callee;
|
|
5845
6196
|
break;
|
|
5846
|
-
case
|
|
6197
|
+
case import_utils40.AST_NODE_TYPES.MemberExpression:
|
|
5847
6198
|
current = current.object;
|
|
5848
6199
|
break;
|
|
5849
|
-
case
|
|
6200
|
+
case import_utils40.AST_NODE_TYPES.Identifier:
|
|
5850
6201
|
return current.name;
|
|
5851
6202
|
default:
|
|
5852
6203
|
return null;
|
|
@@ -5855,26 +6206,26 @@ function rootCallee(node) {
|
|
|
5855
6206
|
return null;
|
|
5856
6207
|
}
|
|
5857
6208
|
function nameOf(key) {
|
|
5858
|
-
if (key.type ===
|
|
5859
|
-
if (key.type ===
|
|
6209
|
+
if (key.type === import_utils40.AST_NODE_TYPES.Identifier) return key.name;
|
|
6210
|
+
if (key.type === import_utils40.AST_NODE_TYPES.Literal && typeof key.value === "string") return key.value;
|
|
5860
6211
|
return null;
|
|
5861
6212
|
}
|
|
5862
6213
|
function targetOf(node) {
|
|
5863
6214
|
switch (node.type) {
|
|
5864
|
-
case
|
|
5865
|
-
case
|
|
6215
|
+
case import_utils40.AST_NODE_TYPES.TSPropertySignature:
|
|
6216
|
+
case import_utils40.AST_NODE_TYPES.PropertyDefinition: {
|
|
5866
6217
|
const name = node.computed ? null : nameOf(node.key);
|
|
5867
6218
|
if (name === null || !isBareString(node.typeAnnotation?.typeAnnotation)) return null;
|
|
5868
6219
|
return { node, name };
|
|
5869
6220
|
}
|
|
5870
|
-
case
|
|
6221
|
+
case import_utils40.AST_NODE_TYPES.Property: {
|
|
5871
6222
|
const name = node.computed || node.shorthand ? null : nameOf(node.key);
|
|
5872
6223
|
const callee = rootCallee(node.value);
|
|
5873
6224
|
if (name === null || callee === null || !STRING_BUILDERS.has(callee)) return null;
|
|
5874
6225
|
return { node, name };
|
|
5875
6226
|
}
|
|
5876
|
-
case
|
|
5877
|
-
if (node.id.type !==
|
|
6227
|
+
case import_utils40.AST_NODE_TYPES.VariableDeclarator: {
|
|
6228
|
+
if (node.id.type !== import_utils40.AST_NODE_TYPES.Identifier) return null;
|
|
5878
6229
|
if (!isBareString(node.id.typeAnnotation?.typeAnnotation)) return null;
|
|
5879
6230
|
return { node, name: node.id.name };
|
|
5880
6231
|
}
|
|
@@ -5923,7 +6274,7 @@ var no_union_in_comment_default = createRule({
|
|
|
5923
6274
|
if (after === null || after.loc.start.line !== comment.loc.end.line + 1) return null;
|
|
5924
6275
|
anchor = sourceCode.getNodeByRangeIndex(after.range[0]);
|
|
5925
6276
|
}
|
|
5926
|
-
for (let node = anchor; node != null && node.type !==
|
|
6277
|
+
for (let node = anchor; node != null && node.type !== import_utils40.AST_NODE_TYPES.Program; node = node.parent) {
|
|
5927
6278
|
const target = targetOf(node);
|
|
5928
6279
|
if (target !== null) return target;
|
|
5929
6280
|
}
|
|
@@ -5952,9 +6303,9 @@ var no_union_in_comment_default = createRule({
|
|
|
5952
6303
|
});
|
|
5953
6304
|
|
|
5954
6305
|
// src/rules/no-type-member-comment-wall.ts
|
|
5955
|
-
var
|
|
6306
|
+
var import_utils41 = require("@typescript-eslint/utils");
|
|
5956
6307
|
function isNamedMember(node) {
|
|
5957
|
-
return (node.type ===
|
|
6308
|
+
return (node.type === import_utils41.AST_NODE_TYPES.TSPropertySignature || node.type === import_utils41.AST_NODE_TYPES.TSMethodSignature) && !node.computed;
|
|
5958
6309
|
}
|
|
5959
6310
|
var no_type_member_comment_wall_default = createRule({
|
|
5960
6311
|
name: "no-type-member-comment-wall",
|
|
@@ -6001,7 +6352,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
6001
6352
|
return headsRun || lineAbove !== void 0 && lineAbove.trim().length === 0;
|
|
6002
6353
|
}
|
|
6003
6354
|
function check(node) {
|
|
6004
|
-
const members = node.type ===
|
|
6355
|
+
const members = node.type === import_utils41.AST_NODE_TYPES.TSInterfaceBody ? node.body : node.members;
|
|
6005
6356
|
const named2 = members.filter(isNamedMember);
|
|
6006
6357
|
if (named2.length === 0) return;
|
|
6007
6358
|
const documented = named2.map((member) => ({ member, comment: documentingComment(member) }));
|
|
@@ -6041,7 +6392,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
6041
6392
|
});
|
|
6042
6393
|
|
|
6043
6394
|
// src/rules/no-unnecessary-use-client.ts
|
|
6044
|
-
var
|
|
6395
|
+
var import_utils42 = require("@typescript-eslint/utils");
|
|
6045
6396
|
var HOOK_REGEX = /^use([A-Z]|$)/;
|
|
6046
6397
|
var EVENT_PROP_REGEX = /^on[A-Z]/;
|
|
6047
6398
|
var ERROR_FILE_REGEX = /\b(?:global-)?error\.[jt]sx?$/;
|
|
@@ -6067,13 +6418,13 @@ var CLIENT_ONLY_PACKAGES_REGEX = /^(?:@radix-ui\/|framer-motion|react-dom|react-
|
|
|
6067
6418
|
var isBareSpecifier = (source) => !source.startsWith(".") && !source.startsWith("/") && !source.startsWith("@/") && !source.startsWith("~");
|
|
6068
6419
|
var jsxRootName = (name) => {
|
|
6069
6420
|
let current = name;
|
|
6070
|
-
while (current.type ===
|
|
6421
|
+
while (current.type === import_utils42.AST_NODE_TYPES.JSXMemberExpression) {
|
|
6071
6422
|
current = current.object;
|
|
6072
6423
|
}
|
|
6073
|
-
return current.type ===
|
|
6424
|
+
return current.type === import_utils42.AST_NODE_TYPES.JSXIdentifier ? current.name : "";
|
|
6074
6425
|
};
|
|
6075
6426
|
var subtreeReadsImportedBinding = (node, imported) => {
|
|
6076
|
-
if (node.type ===
|
|
6427
|
+
if (node.type === import_utils42.AST_NODE_TYPES.Identifier) {
|
|
6077
6428
|
return imported.has(node.name);
|
|
6078
6429
|
}
|
|
6079
6430
|
for (const key of Object.keys(node)) {
|
|
@@ -6088,16 +6439,16 @@ var subtreeReadsImportedBinding = (node, imported) => {
|
|
|
6088
6439
|
return false;
|
|
6089
6440
|
};
|
|
6090
6441
|
var isUseClientDirective = (node) => {
|
|
6091
|
-
return node.type ===
|
|
6442
|
+
return node.type === import_utils42.AST_NODE_TYPES.ExpressionStatement && node.expression.type === import_utils42.AST_NODE_TYPES.Literal && node.expression.value === "use client";
|
|
6092
6443
|
};
|
|
6093
6444
|
var isGlobalReference = (node, context) => {
|
|
6094
6445
|
if (!BROWSER_GLOBALS.has(node.name)) return false;
|
|
6095
6446
|
const parent = node.parent;
|
|
6096
6447
|
if (parent !== void 0) {
|
|
6097
|
-
if (parent.type ===
|
|
6448
|
+
if (parent.type === import_utils42.AST_NODE_TYPES.MemberExpression && parent.property === node && !parent.computed) {
|
|
6098
6449
|
return false;
|
|
6099
6450
|
}
|
|
6100
|
-
if (parent.type ===
|
|
6451
|
+
if (parent.type === import_utils42.AST_NODE_TYPES.Property && parent.key === node && !parent.computed) {
|
|
6101
6452
|
return false;
|
|
6102
6453
|
}
|
|
6103
6454
|
if (parent.type.startsWith("TS")) {
|
|
@@ -6137,13 +6488,13 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
6137
6488
|
const importedLocals = /* @__PURE__ */ new Set();
|
|
6138
6489
|
const externalLocals = /* @__PURE__ */ new Set();
|
|
6139
6490
|
const markIfHookOrContext = (callee) => {
|
|
6140
|
-
if (callee.type ===
|
|
6491
|
+
if (callee.type === import_utils42.AST_NODE_TYPES.Identifier) {
|
|
6141
6492
|
if (HOOK_REGEX.test(callee.name) || callee.name === "createContext") {
|
|
6142
6493
|
hasClientIndicator = true;
|
|
6143
6494
|
}
|
|
6144
6495
|
return;
|
|
6145
6496
|
}
|
|
6146
|
-
if (callee.type ===
|
|
6497
|
+
if (callee.type === import_utils42.AST_NODE_TYPES.MemberExpression && callee.property.type === import_utils42.AST_NODE_TYPES.Identifier) {
|
|
6147
6498
|
const name = callee.property.name;
|
|
6148
6499
|
if (HOOK_REGEX.test(name) || name === "createContext") {
|
|
6149
6500
|
hasClientIndicator = true;
|
|
@@ -6153,7 +6504,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
6153
6504
|
return {
|
|
6154
6505
|
Program(node) {
|
|
6155
6506
|
for (const stmt of node.body) {
|
|
6156
|
-
if (stmt.type !==
|
|
6507
|
+
if (stmt.type !== import_utils42.AST_NODE_TYPES.ExpressionStatement) break;
|
|
6157
6508
|
if (isUseClientDirective(stmt)) {
|
|
6158
6509
|
directiveNode = stmt;
|
|
6159
6510
|
break;
|
|
@@ -6166,7 +6517,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
6166
6517
|
},
|
|
6167
6518
|
JSXAttribute(node) {
|
|
6168
6519
|
if (directiveNode === null) return;
|
|
6169
|
-
if (node.name.type ===
|
|
6520
|
+
if (node.name.type === import_utils42.AST_NODE_TYPES.JSXIdentifier && EVENT_PROP_REGEX.test(node.name.name)) {
|
|
6170
6521
|
hasClientIndicator = true;
|
|
6171
6522
|
}
|
|
6172
6523
|
},
|
|
@@ -6233,18 +6584,18 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
6233
6584
|
});
|
|
6234
6585
|
|
|
6235
6586
|
// src/rules/no-unsafe-mock-casting.ts
|
|
6236
|
-
var import_utils42 = require("@typescript-eslint/utils");
|
|
6237
6587
|
var import_utils43 = require("@typescript-eslint/utils");
|
|
6588
|
+
var import_utils44 = require("@typescript-eslint/utils");
|
|
6238
6589
|
function isMockTypeReference(node) {
|
|
6239
|
-
if (node.type !==
|
|
6590
|
+
if (node.type !== import_utils44.AST_NODE_TYPES.TSTypeReference) {
|
|
6240
6591
|
return false;
|
|
6241
6592
|
}
|
|
6242
6593
|
const typeName = node.typeName;
|
|
6243
|
-
if (typeName.type ===
|
|
6594
|
+
if (typeName.type === import_utils44.AST_NODE_TYPES.Identifier) {
|
|
6244
6595
|
const name = typeName.name;
|
|
6245
6596
|
return name === "Mock" || name === "MockInstance" || name === "SpyInstance";
|
|
6246
6597
|
}
|
|
6247
|
-
if (typeName.type ===
|
|
6598
|
+
if (typeName.type === import_utils44.AST_NODE_TYPES.TSQualifiedName) {
|
|
6248
6599
|
const rightName = typeName.right.name;
|
|
6249
6600
|
return rightName === "Mock" || rightName === "MockInstance" || rightName === "SpyInstance";
|
|
6250
6601
|
}
|
|
@@ -6280,7 +6631,7 @@ var no_unsafe_mock_casting_default = createRule({
|
|
|
6280
6631
|
});
|
|
6281
6632
|
|
|
6282
6633
|
// src/rules/no-zod-native-enum.ts
|
|
6283
|
-
var
|
|
6634
|
+
var import_utils45 = require("@typescript-eslint/utils");
|
|
6284
6635
|
var ts = __toESM(require("typescript"), 1);
|
|
6285
6636
|
var IGNORE_PATTERNS = [
|
|
6286
6637
|
/[\\/]generated[\\/]/,
|
|
@@ -6298,7 +6649,7 @@ function isZodModule(source) {
|
|
|
6298
6649
|
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
6299
6650
|
}
|
|
6300
6651
|
function unwrap2(node) {
|
|
6301
|
-
if (node.type ===
|
|
6652
|
+
if (node.type === import_utils45.AST_NODE_TYPES.TSAsExpression || node.type === import_utils45.AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
6302
6653
|
return unwrap2(node.expression);
|
|
6303
6654
|
}
|
|
6304
6655
|
return node;
|
|
@@ -6306,14 +6657,14 @@ function unwrap2(node) {
|
|
|
6306
6657
|
function stringValueTexts(node, sourceCode) {
|
|
6307
6658
|
const texts = [];
|
|
6308
6659
|
for (const prop of node.properties) {
|
|
6309
|
-
if (prop.type !==
|
|
6660
|
+
if (prop.type !== import_utils45.AST_NODE_TYPES.Property) {
|
|
6310
6661
|
return null;
|
|
6311
6662
|
}
|
|
6312
6663
|
if (prop.computed || prop.shorthand || prop.method || prop.kind !== "init") {
|
|
6313
6664
|
return null;
|
|
6314
6665
|
}
|
|
6315
6666
|
const value = prop.value;
|
|
6316
|
-
if (value.type !==
|
|
6667
|
+
if (value.type !== import_utils45.AST_NODE_TYPES.Literal || typeof value.value !== "string") {
|
|
6317
6668
|
return null;
|
|
6318
6669
|
}
|
|
6319
6670
|
const text = sourceCode.getText(value);
|
|
@@ -6329,7 +6680,7 @@ function resolvesToLocalEnum(node, scope) {
|
|
|
6329
6680
|
const variable = current.variables.find((v) => v.name === node.name);
|
|
6330
6681
|
if (variable !== void 0) {
|
|
6331
6682
|
return variable.defs.some(
|
|
6332
|
-
(def) => def.node.type ===
|
|
6683
|
+
(def) => def.node.type === import_utils45.AST_NODE_TYPES.TSEnumDeclaration
|
|
6333
6684
|
);
|
|
6334
6685
|
}
|
|
6335
6686
|
current = current.upper;
|
|
@@ -6374,32 +6725,32 @@ var no_zod_native_enum_default = createRule({
|
|
|
6374
6725
|
}
|
|
6375
6726
|
let services;
|
|
6376
6727
|
try {
|
|
6377
|
-
services =
|
|
6728
|
+
services = import_utils45.ESLintUtils.getParserServices(context);
|
|
6378
6729
|
} catch {
|
|
6379
6730
|
services = null;
|
|
6380
6731
|
}
|
|
6381
6732
|
const zodImportedNames = /* @__PURE__ */ new Map();
|
|
6382
6733
|
function isZodMemberCall(node, api) {
|
|
6383
6734
|
const callee = node.callee;
|
|
6384
|
-
if (callee.type ===
|
|
6735
|
+
if (callee.type === import_utils45.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils45.AST_NODE_TYPES.Identifier) {
|
|
6385
6736
|
return callee.property.name === api;
|
|
6386
6737
|
}
|
|
6387
|
-
if (callee.type ===
|
|
6738
|
+
if (callee.type === import_utils45.AST_NODE_TYPES.Identifier) {
|
|
6388
6739
|
return zodImportedNames.get(callee.name) === api;
|
|
6389
6740
|
}
|
|
6390
6741
|
return false;
|
|
6391
6742
|
}
|
|
6392
6743
|
function buildFix(node) {
|
|
6393
6744
|
const callee = node.callee;
|
|
6394
|
-
if (callee.type !==
|
|
6745
|
+
if (callee.type !== import_utils45.AST_NODE_TYPES.MemberExpression || callee.property.type !== import_utils45.AST_NODE_TYPES.Identifier) {
|
|
6395
6746
|
return null;
|
|
6396
6747
|
}
|
|
6397
6748
|
const arg = node.arguments[0];
|
|
6398
|
-
if (arg === void 0 || node.arguments.length !== 1 || arg.type ===
|
|
6749
|
+
if (arg === void 0 || node.arguments.length !== 1 || arg.type === import_utils45.AST_NODE_TYPES.SpreadElement) {
|
|
6399
6750
|
return null;
|
|
6400
6751
|
}
|
|
6401
6752
|
const inner = unwrap2(arg);
|
|
6402
|
-
if (inner.type !==
|
|
6753
|
+
if (inner.type !== import_utils45.AST_NODE_TYPES.ObjectExpression) {
|
|
6403
6754
|
return null;
|
|
6404
6755
|
}
|
|
6405
6756
|
const values = stringValueTexts(inner, sourceCode);
|
|
@@ -6419,7 +6770,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
6419
6770
|
return;
|
|
6420
6771
|
}
|
|
6421
6772
|
for (const spec of node.specifiers) {
|
|
6422
|
-
if (spec.type ===
|
|
6773
|
+
if (spec.type === import_utils45.AST_NODE_TYPES.ImportSpecifier && spec.imported.type === import_utils45.AST_NODE_TYPES.Identifier) {
|
|
6423
6774
|
zodImportedNames.set(spec.local.name, spec.imported.name);
|
|
6424
6775
|
}
|
|
6425
6776
|
}
|
|
@@ -6438,7 +6789,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
6438
6789
|
return;
|
|
6439
6790
|
}
|
|
6440
6791
|
const arg = node.arguments[0];
|
|
6441
|
-
if (arg === void 0 || arg.type !==
|
|
6792
|
+
if (arg === void 0 || arg.type !== import_utils45.AST_NODE_TYPES.Identifier) {
|
|
6442
6793
|
return;
|
|
6443
6794
|
}
|
|
6444
6795
|
const isEnum = resolvesToLocalEnum(arg, sourceCode.getScope(arg)) || services !== null && resolvesToImportedEnum(arg, services);
|
|
@@ -6455,7 +6806,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
6455
6806
|
});
|
|
6456
6807
|
|
|
6457
6808
|
// src/rules/prefer-constant-time-secret-compare.ts
|
|
6458
|
-
var
|
|
6809
|
+
var import_utils46 = require("@typescript-eslint/utils");
|
|
6459
6810
|
var EQUALITY_OPERATORS = /* @__PURE__ */ new Set(["===", "!==", "==", "!="]);
|
|
6460
6811
|
var SENTINEL_IDENTIFIERS = /* @__PURE__ */ new Set(["undefined", "NaN"]);
|
|
6461
6812
|
var SENTINEL_WORDS = /(^|_)(SENTINEL|EMPTY|NONE|NULL|UNSET|MISSING|PLACEHOLDER|DUMMY|FAKE|EXAMPLE)(_|$)/;
|
|
@@ -6468,36 +6819,36 @@ function isConstantReference(identifier) {
|
|
|
6468
6819
|
}
|
|
6469
6820
|
function isExcludedOperand(node) {
|
|
6470
6821
|
switch (node.type) {
|
|
6471
|
-
case
|
|
6822
|
+
case import_utils46.AST_NODE_TYPES.Literal:
|
|
6472
6823
|
return true;
|
|
6473
|
-
case
|
|
6824
|
+
case import_utils46.AST_NODE_TYPES.TemplateLiteral:
|
|
6474
6825
|
return node.expressions.length === 0;
|
|
6475
|
-
case
|
|
6826
|
+
case import_utils46.AST_NODE_TYPES.Identifier:
|
|
6476
6827
|
return SENTINEL_IDENTIFIERS.has(node.name) || SENTINEL_PREFIX_RE.test(node.name) || isConstantReference(node.name);
|
|
6477
|
-
case
|
|
6478
|
-
return !node.computed && node.property.type ===
|
|
6828
|
+
case import_utils46.AST_NODE_TYPES.MemberExpression:
|
|
6829
|
+
return !node.computed && node.property.type === import_utils46.AST_NODE_TYPES.Identifier && (SENTINEL_PREFIX_RE.test(node.property.name) || isConstantReference(node.property.name));
|
|
6479
6830
|
default:
|
|
6480
6831
|
return false;
|
|
6481
6832
|
}
|
|
6482
6833
|
}
|
|
6483
6834
|
function operandName(node) {
|
|
6484
|
-
if (node.type ===
|
|
6835
|
+
if (node.type === import_utils46.AST_NODE_TYPES.Identifier) {
|
|
6485
6836
|
return node.name;
|
|
6486
6837
|
}
|
|
6487
|
-
if (node.type ===
|
|
6838
|
+
if (node.type === import_utils46.AST_NODE_TYPES.MemberExpression && !node.computed && node.property.type === import_utils46.AST_NODE_TYPES.Identifier) {
|
|
6488
6839
|
return node.property.name;
|
|
6489
6840
|
}
|
|
6490
6841
|
return null;
|
|
6491
6842
|
}
|
|
6492
6843
|
function isSecretOperand(node) {
|
|
6493
|
-
if (node.type ===
|
|
6844
|
+
if (node.type === import_utils46.AST_NODE_TYPES.TemplateLiteral) {
|
|
6494
6845
|
return node.expressions.some((expression) => isSecretOperand(expression));
|
|
6495
6846
|
}
|
|
6496
6847
|
const name = operandName(node);
|
|
6497
6848
|
return name !== null && isAuthSecretName(name);
|
|
6498
6849
|
}
|
|
6499
6850
|
function secretNameOf(node) {
|
|
6500
|
-
if (node.type ===
|
|
6851
|
+
if (node.type === import_utils46.AST_NODE_TYPES.TemplateLiteral) {
|
|
6501
6852
|
for (const expression of node.expressions) {
|
|
6502
6853
|
const nested = secretNameOf(expression);
|
|
6503
6854
|
if (nested !== null) {
|
|
@@ -6549,8 +6900,8 @@ var prefer_constant_time_secret_compare_default = createRule({
|
|
|
6549
6900
|
});
|
|
6550
6901
|
|
|
6551
6902
|
// src/rules/prefer-discriminated-union.ts
|
|
6552
|
-
var import_utils46 = require("@typescript-eslint/utils");
|
|
6553
6903
|
var import_utils47 = require("@typescript-eslint/utils");
|
|
6904
|
+
var import_utils48 = require("@typescript-eslint/utils");
|
|
6554
6905
|
var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
6555
6906
|
"success",
|
|
6556
6907
|
"ok",
|
|
@@ -6560,27 +6911,27 @@ var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
|
6560
6911
|
]);
|
|
6561
6912
|
var MIN_OPTIONAL_MEMBERS = 2;
|
|
6562
6913
|
function getMemberName(member) {
|
|
6563
|
-
if (member.type !==
|
|
6914
|
+
if (member.type !== import_utils48.AST_NODE_TYPES.TSPropertySignature) {
|
|
6564
6915
|
return null;
|
|
6565
6916
|
}
|
|
6566
6917
|
const { key } = member;
|
|
6567
|
-
if (key.type ===
|
|
6918
|
+
if (key.type === import_utils48.AST_NODE_TYPES.Identifier) {
|
|
6568
6919
|
return key.name;
|
|
6569
6920
|
}
|
|
6570
|
-
if (key.type ===
|
|
6921
|
+
if (key.type === import_utils48.AST_NODE_TYPES.Literal && typeof key.value === "string") {
|
|
6571
6922
|
return key.value;
|
|
6572
6923
|
}
|
|
6573
6924
|
return null;
|
|
6574
6925
|
}
|
|
6575
6926
|
function isBooleanTyped(member) {
|
|
6576
|
-
return member.typeAnnotation?.typeAnnotation.type ===
|
|
6927
|
+
return member.typeAnnotation?.typeAnnotation.type === import_utils48.AST_NODE_TYPES.TSBooleanKeyword;
|
|
6577
6928
|
}
|
|
6578
6929
|
function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
6579
6930
|
let hasStatusBoolean = false;
|
|
6580
6931
|
let optionalCount = 0;
|
|
6581
6932
|
let optionalPayloadCount = 0;
|
|
6582
6933
|
for (const member of typeLiteral.members) {
|
|
6583
|
-
if (member.type !==
|
|
6934
|
+
if (member.type !== import_utils48.AST_NODE_TYPES.TSPropertySignature) {
|
|
6584
6935
|
continue;
|
|
6585
6936
|
}
|
|
6586
6937
|
if (member.optional) {
|
|
@@ -6622,7 +6973,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
6622
6973
|
TSInterfaceDeclaration(node) {
|
|
6623
6974
|
const synthetic = {
|
|
6624
6975
|
...node.body,
|
|
6625
|
-
type:
|
|
6976
|
+
type: import_utils48.AST_NODE_TYPES.TSTypeLiteral,
|
|
6626
6977
|
members: node.body.body
|
|
6627
6978
|
};
|
|
6628
6979
|
checkTypeLiteral(synthetic, node);
|
|
@@ -6635,21 +6986,21 @@ var prefer_discriminated_union_default = createRule({
|
|
|
6635
6986
|
});
|
|
6636
6987
|
|
|
6637
6988
|
// src/rules/prefer-input-group-search.ts
|
|
6638
|
-
var
|
|
6989
|
+
var import_utils49 = require("@typescript-eslint/utils");
|
|
6639
6990
|
var INPUT_MODULE = /(?:^|\/)components\/ui\/input$/u;
|
|
6640
6991
|
var INPUT_GROUP_MODULE = /(?:^|\/)components\/ui\/input-group$/u;
|
|
6641
6992
|
var MAX_JSX_DISTANCE = 2;
|
|
6642
6993
|
function localNamedImports(node, importedName) {
|
|
6643
6994
|
return node.specifiers.filter(
|
|
6644
|
-
(specifier) => specifier.type ===
|
|
6995
|
+
(specifier) => specifier.type === import_utils49.AST_NODE_TYPES.ImportSpecifier && (specifier.imported.type === import_utils49.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value) === importedName
|
|
6645
6996
|
).map((specifier) => specifier.local.name);
|
|
6646
6997
|
}
|
|
6647
6998
|
function elementName(node) {
|
|
6648
|
-
return node.name.type ===
|
|
6999
|
+
return node.name.type === import_utils49.AST_NODE_TYPES.JSXIdentifier ? node.name.name : null;
|
|
6649
7000
|
}
|
|
6650
7001
|
function jsxAncestors(occurrence) {
|
|
6651
7002
|
return occurrence.ancestors.filter(
|
|
6652
|
-
(ancestor) => ancestor.type ===
|
|
7003
|
+
(ancestor) => ancestor.type === import_utils49.AST_NODE_TYPES.JSXElement
|
|
6653
7004
|
);
|
|
6654
7005
|
}
|
|
6655
7006
|
function isWithinInputGroup(occurrence, inputGroupNames) {
|
|
@@ -6748,7 +7099,7 @@ var prefer_input_group_search_default = createRule({
|
|
|
6748
7099
|
});
|
|
6749
7100
|
|
|
6750
7101
|
// src/rules/prefer-immutable-module-constant.ts
|
|
6751
|
-
var
|
|
7102
|
+
var import_utils50 = require("@typescript-eslint/utils");
|
|
6752
7103
|
var CONSTANT_NAME = /^_?[A-Z][A-Z0-9_]*$/;
|
|
6753
7104
|
var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
6754
7105
|
"add",
|
|
@@ -6766,69 +7117,76 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
|
6766
7117
|
"unshift"
|
|
6767
7118
|
]);
|
|
6768
7119
|
function isAsConst(node, sourceText) {
|
|
6769
|
-
if (node.type ===
|
|
7120
|
+
if (node.type === import_utils50.AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
6770
7121
|
return isAsConst(node.expression, sourceText);
|
|
6771
7122
|
}
|
|
6772
|
-
return node.type ===
|
|
7123
|
+
return node.type === import_utils50.AST_NODE_TYPES.TSAsExpression && sourceText(node.typeAnnotation).trim() === "const";
|
|
6773
7124
|
}
|
|
6774
7125
|
function unwrapExpression(node) {
|
|
6775
|
-
if (node.type ===
|
|
7126
|
+
if (node.type === import_utils50.AST_NODE_TYPES.TSAsExpression || node.type === import_utils50.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils50.AST_NODE_TYPES.TSNonNullExpression) {
|
|
6776
7127
|
return unwrapExpression(node.expression);
|
|
6777
7128
|
}
|
|
6778
7129
|
return node;
|
|
6779
7130
|
}
|
|
6780
|
-
function isObjectFreeze(node) {
|
|
7131
|
+
function isObjectFreeze(node, isUnshadowedGlobal) {
|
|
6781
7132
|
const inner = unwrapExpression(node);
|
|
6782
|
-
|
|
7133
|
+
if (inner.type === import_utils50.AST_NODE_TYPES.CallExpression && inner.callee.type === import_utils50.AST_NODE_TYPES.MemberExpression && !inner.callee.computed && inner.callee.object.type === import_utils50.AST_NODE_TYPES.Identifier && inner.callee.object.name === "Object" && isUnshadowedGlobal(inner.callee.object) && inner.callee.property.type === import_utils50.AST_NODE_TYPES.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1) {
|
|
7134
|
+
const argument = inner.arguments[0];
|
|
7135
|
+
return argument !== void 0 && argument.type !== import_utils50.AST_NODE_TYPES.SpreadElement && collectionKind(argument, isUnshadowedGlobal) === "literal";
|
|
7136
|
+
}
|
|
7137
|
+
return false;
|
|
6783
7138
|
}
|
|
6784
|
-
function collectionKind(node) {
|
|
7139
|
+
function collectionKind(node, isUnshadowedGlobal) {
|
|
6785
7140
|
const inner = unwrapExpression(node);
|
|
6786
|
-
if (inner.type ===
|
|
7141
|
+
if (inner.type === import_utils50.AST_NODE_TYPES.CallExpression && inner.callee.type === import_utils50.AST_NODE_TYPES.MemberExpression && !inner.callee.computed && inner.callee.object.type === import_utils50.AST_NODE_TYPES.Identifier && inner.callee.object.name === "Object" && isUnshadowedGlobal(inner.callee.object) && inner.callee.property.type === import_utils50.AST_NODE_TYPES.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== import_utils50.AST_NODE_TYPES.SpreadElement) {
|
|
7142
|
+
return collectionKind(inner.arguments[0], isUnshadowedGlobal);
|
|
7143
|
+
}
|
|
7144
|
+
if (inner.type === import_utils50.AST_NODE_TYPES.ArrayExpression || inner.type === import_utils50.AST_NODE_TYPES.ObjectExpression) {
|
|
6787
7145
|
return "literal";
|
|
6788
7146
|
}
|
|
6789
|
-
if (inner.type ===
|
|
7147
|
+
if (inner.type === import_utils50.AST_NODE_TYPES.NewExpression && inner.callee.type === import_utils50.AST_NODE_TYPES.Identifier && (inner.callee.name === "Set" || inner.callee.name === "Map") && isUnshadowedGlobal(inner.callee)) {
|
|
6790
7148
|
return inner.callee.name;
|
|
6791
7149
|
}
|
|
6792
7150
|
return null;
|
|
6793
7151
|
}
|
|
6794
7152
|
function isReadonlyType(node, kind) {
|
|
6795
|
-
if (node.type ===
|
|
7153
|
+
if (node.type === import_utils50.AST_NODE_TYPES.TSTypeOperator && node.operator === "readonly") {
|
|
6796
7154
|
return true;
|
|
6797
7155
|
}
|
|
6798
|
-
if (node.type !==
|
|
7156
|
+
if (node.type !== import_utils50.AST_NODE_TYPES.TSTypeReference || node.typeName.type !== import_utils50.AST_NODE_TYPES.Identifier) {
|
|
6799
7157
|
return false;
|
|
6800
7158
|
}
|
|
6801
7159
|
if (node.typeName.name === "Readonly") {
|
|
6802
|
-
return
|
|
7160
|
+
return kind === "literal";
|
|
6803
7161
|
}
|
|
6804
7162
|
return kind === "literal" ? node.typeName.name === "ReadonlyArray" : node.typeName.name === `Readonly${kind}`;
|
|
6805
7163
|
}
|
|
6806
7164
|
function declaredReadonlyType(node, kind) {
|
|
6807
|
-
const annotation = node.id.type ===
|
|
7165
|
+
const annotation = node.id.type === import_utils50.AST_NODE_TYPES.Identifier ? node.id.typeAnnotation : void 0;
|
|
6808
7166
|
if (annotation !== void 0 && isReadonlyType(annotation.typeAnnotation, kind)) {
|
|
6809
7167
|
return true;
|
|
6810
7168
|
}
|
|
6811
|
-
return node.init?.type ===
|
|
7169
|
+
return node.init?.type === import_utils50.AST_NODE_TYPES.TSAsExpression && isReadonlyType(node.init.typeAnnotation, kind);
|
|
6812
7170
|
}
|
|
6813
7171
|
function referenceMutates(identifier) {
|
|
6814
7172
|
let member = identifier.parent;
|
|
6815
|
-
if (member?.type !==
|
|
6816
|
-
return member?.type ===
|
|
7173
|
+
if (member?.type !== import_utils50.AST_NODE_TYPES.MemberExpression || member.object !== identifier) {
|
|
7174
|
+
return member?.type === import_utils50.AST_NODE_TYPES.CallExpression && member.arguments[0] === identifier && member.callee.type === import_utils50.AST_NODE_TYPES.MemberExpression && !member.callee.computed && member.callee.object.type === import_utils50.AST_NODE_TYPES.Identifier && member.callee.object.name === "Object" && member.callee.property.type === import_utils50.AST_NODE_TYPES.Identifier && member.callee.property.name === "assign";
|
|
6817
7175
|
}
|
|
6818
|
-
while (member.parent.type ===
|
|
7176
|
+
while (member.parent.type === import_utils50.AST_NODE_TYPES.MemberExpression && member.parent.object === member) {
|
|
6819
7177
|
member = member.parent;
|
|
6820
7178
|
}
|
|
6821
7179
|
const parent = member.parent;
|
|
6822
|
-
if (parent?.type ===
|
|
7180
|
+
if (parent?.type === import_utils50.AST_NODE_TYPES.AssignmentExpression && parent.left === member) {
|
|
6823
7181
|
return true;
|
|
6824
7182
|
}
|
|
6825
|
-
if (parent?.type ===
|
|
7183
|
+
if (parent?.type === import_utils50.AST_NODE_TYPES.UpdateExpression && parent.argument === member) {
|
|
6826
7184
|
return true;
|
|
6827
7185
|
}
|
|
6828
|
-
if (parent?.type ===
|
|
7186
|
+
if (parent?.type === import_utils50.AST_NODE_TYPES.UnaryExpression && parent.operator === "delete" && parent.argument === member) {
|
|
6829
7187
|
return true;
|
|
6830
7188
|
}
|
|
6831
|
-
return parent?.type ===
|
|
7189
|
+
return parent?.type === import_utils50.AST_NODE_TYPES.CallExpression && parent.callee === member && member.property.type === import_utils50.AST_NODE_TYPES.Identifier && MUTATING_METHODS.has(member.property.name);
|
|
6832
7190
|
}
|
|
6833
7191
|
var prefer_immutable_module_constant_default = createRule({
|
|
6834
7192
|
name: "prefer-immutable-module-constant",
|
|
@@ -6846,29 +7204,33 @@ var prefer_immutable_module_constant_default = createRule({
|
|
|
6846
7204
|
defaultOptions: [],
|
|
6847
7205
|
create(context) {
|
|
6848
7206
|
const sourceCode = context.sourceCode;
|
|
7207
|
+
const isUnshadowedGlobal = (identifier) => {
|
|
7208
|
+
const variable = import_utils50.ASTUtils.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
7209
|
+
return variable === null || variable.defs.length === 0;
|
|
7210
|
+
};
|
|
6849
7211
|
if (isTestFile(context.filename) || isGeneratedFile(context.filename, sourceCode.getText())) {
|
|
6850
7212
|
return {};
|
|
6851
7213
|
}
|
|
6852
7214
|
return {
|
|
6853
7215
|
VariableDeclarator(node) {
|
|
6854
7216
|
const declaration = node.parent;
|
|
6855
|
-
if (declaration.type !==
|
|
7217
|
+
if (declaration.type !== import_utils50.AST_NODE_TYPES.VariableDeclaration || declaration.kind !== "const" || node.id.type !== import_utils50.AST_NODE_TYPES.Identifier || node.init === null || !CONSTANT_NAME.test(node.id.name)) {
|
|
6856
7218
|
return;
|
|
6857
7219
|
}
|
|
6858
7220
|
const container = declaration.parent;
|
|
6859
|
-
if (container.type !==
|
|
7221
|
+
if (container.type !== import_utils50.AST_NODE_TYPES.Program && !(container.type === import_utils50.AST_NODE_TYPES.ExportNamedDeclaration && container.parent.type === import_utils50.AST_NODE_TYPES.Program)) {
|
|
6860
7222
|
return;
|
|
6861
7223
|
}
|
|
6862
|
-
if (isAsConst(node.init, (target) => sourceCode.getText(target)) || isObjectFreeze(node.init)) {
|
|
7224
|
+
if (isAsConst(node.init, (target) => sourceCode.getText(target)) || isObjectFreeze(node.init, isUnshadowedGlobal)) {
|
|
6863
7225
|
return;
|
|
6864
7226
|
}
|
|
6865
|
-
const kind = collectionKind(node.init);
|
|
7227
|
+
const kind = collectionKind(node.init, isUnshadowedGlobal);
|
|
6866
7228
|
if (kind === null || declaredReadonlyType(node, kind)) {
|
|
6867
7229
|
return;
|
|
6868
7230
|
}
|
|
6869
7231
|
const variable = sourceCode.getDeclaredVariables(node)[0];
|
|
6870
7232
|
if (variable?.references.some(
|
|
6871
|
-
(reference) => reference.identifier.type ===
|
|
7233
|
+
(reference) => reference.identifier.type === import_utils50.AST_NODE_TYPES.Identifier && referenceMutates(reference.identifier)
|
|
6872
7234
|
) === true) {
|
|
6873
7235
|
return;
|
|
6874
7236
|
}
|
|
@@ -6883,7 +7245,7 @@ var prefer_immutable_module_constant_default = createRule({
|
|
|
6883
7245
|
});
|
|
6884
7246
|
|
|
6885
7247
|
// src/rules/prefer-shadcn-primitives.ts
|
|
6886
|
-
var
|
|
7248
|
+
var import_utils51 = require("@typescript-eslint/utils");
|
|
6887
7249
|
var SHADCN_PRIMITIVES = {
|
|
6888
7250
|
button: "Button",
|
|
6889
7251
|
dialog: "Dialog or AlertDialog family",
|
|
@@ -6904,15 +7266,15 @@ var LABELABLE_ELEMENTS = /* @__PURE__ */ new Set([
|
|
|
6904
7266
|
"textarea"
|
|
6905
7267
|
]);
|
|
6906
7268
|
function rawElementName(node) {
|
|
6907
|
-
if (node.name.type !==
|
|
7269
|
+
if (node.name.type !== import_utils51.AST_NODE_TYPES.JSXIdentifier) return null;
|
|
6908
7270
|
const name = node.name.name;
|
|
6909
7271
|
return Object.hasOwn(SHADCN_PRIMITIVES, name) ? name : null;
|
|
6910
7272
|
}
|
|
6911
7273
|
function staticExpressionString(expression) {
|
|
6912
|
-
if (expression.type ===
|
|
7274
|
+
if (expression.type === import_utils51.AST_NODE_TYPES.Literal) {
|
|
6913
7275
|
return typeof expression.value === "string" ? expression.value : null;
|
|
6914
7276
|
}
|
|
6915
|
-
if (expression.type ===
|
|
7277
|
+
if (expression.type === import_utils51.AST_NODE_TYPES.TemplateLiteral) {
|
|
6916
7278
|
let value = expression.quasis[0]?.value.cooked ?? "";
|
|
6917
7279
|
for (const [index, substitution] of expression.expressions.entries()) {
|
|
6918
7280
|
const staticSubstitution = staticExpressionString(substitution);
|
|
@@ -6922,24 +7284,24 @@ function staticExpressionString(expression) {
|
|
|
6922
7284
|
}
|
|
6923
7285
|
return value;
|
|
6924
7286
|
}
|
|
6925
|
-
if (expression.type ===
|
|
7287
|
+
if (expression.type === import_utils51.AST_NODE_TYPES.TSAsExpression || expression.type === import_utils51.AST_NODE_TYPES.TSNonNullExpression || expression.type === import_utils51.AST_NODE_TYPES.TSSatisfiesExpression || expression.type === import_utils51.AST_NODE_TYPES.TSTypeAssertion) {
|
|
6926
7288
|
return staticExpressionString(expression.expression);
|
|
6927
7289
|
}
|
|
6928
7290
|
return null;
|
|
6929
7291
|
}
|
|
6930
7292
|
function staticString(value) {
|
|
6931
|
-
if (value?.type ===
|
|
7293
|
+
if (value?.type === import_utils51.AST_NODE_TYPES.Literal) {
|
|
6932
7294
|
return typeof value.value === "string" ? value.value : null;
|
|
6933
7295
|
}
|
|
6934
|
-
if (value?.type !==
|
|
7296
|
+
if (value?.type !== import_utils51.AST_NODE_TYPES.JSXExpressionContainer) return null;
|
|
6935
7297
|
return staticExpressionString(value.expression);
|
|
6936
7298
|
}
|
|
6937
7299
|
function effectiveAttribute(node, attributeName) {
|
|
6938
7300
|
for (const attribute of node.attributes.toReversed()) {
|
|
6939
|
-
if (attribute.type ===
|
|
7301
|
+
if (attribute.type === import_utils51.AST_NODE_TYPES.JSXSpreadAttribute) {
|
|
6940
7302
|
return { kind: "unknown" };
|
|
6941
7303
|
}
|
|
6942
|
-
if (attribute.name.type !==
|
|
7304
|
+
if (attribute.name.type !== import_utils51.AST_NODE_TYPES.JSXIdentifier || attribute.name.name !== attributeName) {
|
|
6943
7305
|
continue;
|
|
6944
7306
|
}
|
|
6945
7307
|
const value = staticString(attribute.value);
|
|
@@ -6948,7 +7310,7 @@ function effectiveAttribute(node, attributeName) {
|
|
|
6948
7310
|
return { kind: "missing" };
|
|
6949
7311
|
}
|
|
6950
7312
|
function isLabelableElement(node) {
|
|
6951
|
-
if (node.openingElement.name.type !==
|
|
7313
|
+
if (node.openingElement.name.type !== import_utils51.AST_NODE_TYPES.JSXIdentifier) {
|
|
6952
7314
|
return false;
|
|
6953
7315
|
}
|
|
6954
7316
|
const name = node.openingElement.name.name;
|
|
@@ -6960,10 +7322,10 @@ function isLabelableElement(node) {
|
|
|
6960
7322
|
}
|
|
6961
7323
|
function containsLabelableElement(node) {
|
|
6962
7324
|
return node.children.some((child) => {
|
|
6963
|
-
if (child.type ===
|
|
7325
|
+
if (child.type === import_utils51.AST_NODE_TYPES.JSXElement) {
|
|
6964
7326
|
return isLabelableElement(child) || containsLabelableElement(child);
|
|
6965
7327
|
}
|
|
6966
|
-
if (child.type ===
|
|
7328
|
+
if (child.type === import_utils51.AST_NODE_TYPES.JSXFragment) {
|
|
6967
7329
|
return containsLabelableElement(child);
|
|
6968
7330
|
}
|
|
6969
7331
|
return false;
|
|
@@ -6972,7 +7334,7 @@ function containsLabelableElement(node) {
|
|
|
6972
7334
|
function isStaticallyAssociatedLabel(node) {
|
|
6973
7335
|
const htmlFor = effectiveAttribute(node, "htmlFor");
|
|
6974
7336
|
if (htmlFor.kind === "known" && htmlFor.value.trim().length > 0) return true;
|
|
6975
|
-
return node.parent.type ===
|
|
7337
|
+
return node.parent.type === import_utils51.AST_NODE_TYPES.JSXElement && containsLabelableElement(node.parent);
|
|
6976
7338
|
}
|
|
6977
7339
|
function replacementFor(node, element) {
|
|
6978
7340
|
if (element !== "input") return SHADCN_PRIMITIVES[element];
|
|
@@ -7016,7 +7378,7 @@ var prefer_shadcn_primitives_default = createRule({
|
|
|
7016
7378
|
});
|
|
7017
7379
|
|
|
7018
7380
|
// src/rules/prefer-module-level-constant.ts
|
|
7019
|
-
var
|
|
7381
|
+
var import_utils52 = require("@typescript-eslint/utils");
|
|
7020
7382
|
var DEFAULT_MIN_ELEMENTS = 3;
|
|
7021
7383
|
var MAX_LITERAL_DEPTH = 4;
|
|
7022
7384
|
var IGNORE_PATTERNS2 = [
|
|
@@ -7045,9 +7407,9 @@ var MUTATING_METHODS2 = /* @__PURE__ */ new Set([
|
|
|
7045
7407
|
"assign"
|
|
7046
7408
|
]);
|
|
7047
7409
|
var FUNCTION_TYPES5 = /* @__PURE__ */ new Set([
|
|
7048
|
-
|
|
7049
|
-
|
|
7050
|
-
|
|
7410
|
+
import_utils52.AST_NODE_TYPES.FunctionDeclaration,
|
|
7411
|
+
import_utils52.AST_NODE_TYPES.FunctionExpression,
|
|
7412
|
+
import_utils52.AST_NODE_TYPES.ArrowFunctionExpression
|
|
7051
7413
|
]);
|
|
7052
7414
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
7053
7415
|
function isIgnoredFile2(filename, sourceText) {
|
|
@@ -7060,14 +7422,14 @@ function isLocalFixtureFile(filename) {
|
|
|
7060
7422
|
return isTestFile(filename) || isStoryFile(filename);
|
|
7061
7423
|
}
|
|
7062
7424
|
function unwrap3(node) {
|
|
7063
|
-
if (node.type ===
|
|
7425
|
+
if (node.type === import_utils52.AST_NODE_TYPES.TSAsExpression || node.type === import_utils52.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils52.AST_NODE_TYPES.TSNonNullExpression) {
|
|
7064
7426
|
return unwrap3(node.expression);
|
|
7065
7427
|
}
|
|
7066
7428
|
return node;
|
|
7067
7429
|
}
|
|
7068
7430
|
var HAS_STATEFUL_FLAG_RE = /[gy]/;
|
|
7069
7431
|
function isRegexLiteral(node) {
|
|
7070
|
-
return node.type ===
|
|
7432
|
+
return node.type === import_utils52.AST_NODE_TYPES.Literal && "regex" in node && node.regex !== void 0;
|
|
7071
7433
|
}
|
|
7072
7434
|
function isLiteralOnly(node, depth) {
|
|
7073
7435
|
if (depth > MAX_LITERAL_DEPTH) {
|
|
@@ -7075,29 +7437,29 @@ function isLiteralOnly(node, depth) {
|
|
|
7075
7437
|
}
|
|
7076
7438
|
const inner = unwrap3(node);
|
|
7077
7439
|
switch (inner.type) {
|
|
7078
|
-
case
|
|
7440
|
+
case import_utils52.AST_NODE_TYPES.Literal: {
|
|
7079
7441
|
return !(isRegexLiteral(inner) && HAS_STATEFUL_FLAG_RE.test(inner.regex.flags));
|
|
7080
7442
|
}
|
|
7081
|
-
case
|
|
7443
|
+
case import_utils52.AST_NODE_TYPES.TemplateLiteral: {
|
|
7082
7444
|
return inner.expressions.length === 0;
|
|
7083
7445
|
}
|
|
7084
|
-
case
|
|
7085
|
-
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type ===
|
|
7446
|
+
case import_utils52.AST_NODE_TYPES.UnaryExpression: {
|
|
7447
|
+
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type === import_utils52.AST_NODE_TYPES.Literal && typeof inner.argument.value === "number";
|
|
7086
7448
|
}
|
|
7087
|
-
case
|
|
7449
|
+
case import_utils52.AST_NODE_TYPES.ArrayExpression: {
|
|
7088
7450
|
return inner.elements.every(
|
|
7089
|
-
(el) => el !== null && el.type !==
|
|
7451
|
+
(el) => el !== null && el.type !== import_utils52.AST_NODE_TYPES.SpreadElement && isLiteralOnly(el, depth + 1)
|
|
7090
7452
|
);
|
|
7091
7453
|
}
|
|
7092
|
-
case
|
|
7454
|
+
case import_utils52.AST_NODE_TYPES.ObjectExpression: {
|
|
7093
7455
|
return inner.properties.every((prop) => {
|
|
7094
|
-
if (prop.type !==
|
|
7456
|
+
if (prop.type !== import_utils52.AST_NODE_TYPES.Property) {
|
|
7095
7457
|
return false;
|
|
7096
7458
|
}
|
|
7097
7459
|
if (prop.shorthand || prop.method || prop.kind !== "init") {
|
|
7098
7460
|
return false;
|
|
7099
7461
|
}
|
|
7100
|
-
if (prop.computed && prop.key.type !==
|
|
7462
|
+
if (prop.computed && prop.key.type !== import_utils52.AST_NODE_TYPES.Literal) {
|
|
7101
7463
|
return false;
|
|
7102
7464
|
}
|
|
7103
7465
|
return isLiteralOnly(prop.value, depth + 1);
|
|
@@ -7110,7 +7472,7 @@ function isLiteralOnly(node, depth) {
|
|
|
7110
7472
|
}
|
|
7111
7473
|
function unwrapObjectFreeze(node) {
|
|
7112
7474
|
const inner = unwrap3(node);
|
|
7113
|
-
if (inner.type ===
|
|
7475
|
+
if (inner.type === import_utils52.AST_NODE_TYPES.CallExpression && inner.callee.type === import_utils52.AST_NODE_TYPES.MemberExpression && !inner.callee.computed && inner.callee.object.type === import_utils52.AST_NODE_TYPES.Identifier && inner.callee.object.name === "Object" && inner.callee.property.type === import_utils52.AST_NODE_TYPES.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== import_utils52.AST_NODE_TYPES.SpreadElement) {
|
|
7114
7476
|
return unwrap3(inner.arguments[0]);
|
|
7115
7477
|
}
|
|
7116
7478
|
return inner;
|
|
@@ -7126,19 +7488,19 @@ function classify(init, checkRegex) {
|
|
|
7126
7488
|
}
|
|
7127
7489
|
return { kind: "regex", size: 1 };
|
|
7128
7490
|
}
|
|
7129
|
-
if (node.type ===
|
|
7491
|
+
if (node.type === import_utils52.AST_NODE_TYPES.ArrayExpression) {
|
|
7130
7492
|
return isLiteralOnly(node, 0) ? { kind: "array", size: node.elements.length } : null;
|
|
7131
7493
|
}
|
|
7132
|
-
if (node.type ===
|
|
7494
|
+
if (node.type === import_utils52.AST_NODE_TYPES.ObjectExpression) {
|
|
7133
7495
|
return isLiteralOnly(node, 0) ? { kind: "object", size: node.properties.length } : null;
|
|
7134
7496
|
}
|
|
7135
|
-
if (node.type ===
|
|
7497
|
+
if (node.type === import_utils52.AST_NODE_TYPES.NewExpression && node.callee.type === import_utils52.AST_NODE_TYPES.Identifier && COLLECTION_CONSTRUCTORS.has(node.callee.name)) {
|
|
7136
7498
|
const arg = node.arguments[0];
|
|
7137
|
-
if (node.arguments.length !== 1 || arg === void 0 || arg.type ===
|
|
7499
|
+
if (node.arguments.length !== 1 || arg === void 0 || arg.type === import_utils52.AST_NODE_TYPES.SpreadElement) {
|
|
7138
7500
|
return null;
|
|
7139
7501
|
}
|
|
7140
7502
|
const entries = unwrap3(arg);
|
|
7141
|
-
if (entries.type !==
|
|
7503
|
+
if (entries.type !== import_utils52.AST_NODE_TYPES.ArrayExpression) {
|
|
7142
7504
|
return null;
|
|
7143
7505
|
}
|
|
7144
7506
|
return isLiteralOnly(entries, 0) ? { kind: node.callee.name === "Set" ? "Set" : "Map", size: entries.elements.length } : null;
|
|
@@ -7167,10 +7529,10 @@ var NON_RETAINING_BUILTINS = /* @__PURE__ */ new Map(
|
|
|
7167
7529
|
);
|
|
7168
7530
|
function isNonRetainingBuiltinCall(node, argument) {
|
|
7169
7531
|
const callee = node.callee;
|
|
7170
|
-
if (callee.type ===
|
|
7532
|
+
if (callee.type === import_utils52.AST_NODE_TYPES.Identifier && callee.name === "structuredClone") {
|
|
7171
7533
|
return true;
|
|
7172
7534
|
}
|
|
7173
|
-
if (callee.type !==
|
|
7535
|
+
if (callee.type !== import_utils52.AST_NODE_TYPES.MemberExpression || callee.computed || callee.object.type !== import_utils52.AST_NODE_TYPES.Identifier || callee.property.type !== import_utils52.AST_NODE_TYPES.Identifier) {
|
|
7174
7536
|
return false;
|
|
7175
7537
|
}
|
|
7176
7538
|
const members = NON_RETAINING_BUILTINS.get(callee.object.name);
|
|
@@ -7184,38 +7546,38 @@ function isNonRetainingBuiltinCall(node, argument) {
|
|
|
7184
7546
|
}
|
|
7185
7547
|
function isSafeRead(identifier) {
|
|
7186
7548
|
const parent = identifier.parent;
|
|
7187
|
-
if (parent.type ===
|
|
7549
|
+
if (parent.type === import_utils52.AST_NODE_TYPES.MemberExpression) {
|
|
7188
7550
|
if (parent.object !== identifier) {
|
|
7189
7551
|
return true;
|
|
7190
7552
|
}
|
|
7191
7553
|
const grandparent = parent.parent;
|
|
7192
|
-
if (grandparent.type ===
|
|
7554
|
+
if (grandparent.type === import_utils52.AST_NODE_TYPES.AssignmentExpression && grandparent.left === parent) {
|
|
7193
7555
|
return false;
|
|
7194
7556
|
}
|
|
7195
|
-
if (grandparent.type ===
|
|
7557
|
+
if (grandparent.type === import_utils52.AST_NODE_TYPES.UpdateExpression) {
|
|
7196
7558
|
return false;
|
|
7197
7559
|
}
|
|
7198
|
-
if (grandparent.type ===
|
|
7560
|
+
if (grandparent.type === import_utils52.AST_NODE_TYPES.UnaryExpression && grandparent.operator === "delete") {
|
|
7199
7561
|
return false;
|
|
7200
7562
|
}
|
|
7201
|
-
if (!parent.computed && parent.property.type ===
|
|
7563
|
+
if (!parent.computed && parent.property.type === import_utils52.AST_NODE_TYPES.Identifier && MUTATING_METHODS2.has(parent.property.name) && grandparent.type === import_utils52.AST_NODE_TYPES.CallExpression && grandparent.callee === parent) {
|
|
7202
7564
|
return false;
|
|
7203
7565
|
}
|
|
7204
7566
|
return true;
|
|
7205
7567
|
}
|
|
7206
|
-
if (parent.type ===
|
|
7568
|
+
if (parent.type === import_utils52.AST_NODE_TYPES.ForOfStatement && parent.right === identifier) {
|
|
7207
7569
|
return true;
|
|
7208
7570
|
}
|
|
7209
|
-
if (parent.type ===
|
|
7571
|
+
if (parent.type === import_utils52.AST_NODE_TYPES.SpreadElement) {
|
|
7210
7572
|
return true;
|
|
7211
7573
|
}
|
|
7212
|
-
if (parent.type ===
|
|
7574
|
+
if (parent.type === import_utils52.AST_NODE_TYPES.BinaryExpression) {
|
|
7213
7575
|
return true;
|
|
7214
7576
|
}
|
|
7215
|
-
if (parent.type ===
|
|
7577
|
+
if (parent.type === import_utils52.AST_NODE_TYPES.CallExpression && parent.arguments.includes(identifier) && isNonRetainingBuiltinCall(parent, identifier)) {
|
|
7216
7578
|
return true;
|
|
7217
7579
|
}
|
|
7218
|
-
if (parent.type ===
|
|
7580
|
+
if (parent.type === import_utils52.AST_NODE_TYPES.UnaryExpression && parent.operator !== "delete") {
|
|
7219
7581
|
return true;
|
|
7220
7582
|
}
|
|
7221
7583
|
return false;
|
|
@@ -7239,7 +7601,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
7239
7601
|
}
|
|
7240
7602
|
],
|
|
7241
7603
|
messages: {
|
|
7242
|
-
hoistCollection: "`{{name}}` is a literal-only {{kind}} rebuilt on every call. Hoist it to module scope so it is allocated once
|
|
7604
|
+
hoistCollection: "`{{name}}` is a literal-only {{kind}} rebuilt on every call. Hoist it to module scope in immutable form (`as const`, a readonly collection, or `Object.freeze`) so it is allocated once without exposing mutable shared state.",
|
|
7243
7605
|
hoistRegex: "`{{name}}` is a constant regex recompiled on every call. Hoist it to module scope."
|
|
7244
7606
|
}
|
|
7245
7607
|
},
|
|
@@ -7270,7 +7632,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
7270
7632
|
if (reference.isWrite()) {
|
|
7271
7633
|
return false;
|
|
7272
7634
|
}
|
|
7273
|
-
if (reference.identifier.type !==
|
|
7635
|
+
if (reference.identifier.type !== import_utils52.AST_NODE_TYPES.Identifier) {
|
|
7274
7636
|
return false;
|
|
7275
7637
|
}
|
|
7276
7638
|
if (!isSafeRead(reference.identifier)) {
|
|
@@ -7282,10 +7644,10 @@ var prefer_module_level_constant_default = createRule({
|
|
|
7282
7644
|
return {
|
|
7283
7645
|
VariableDeclarator(node) {
|
|
7284
7646
|
const declaration = node.parent;
|
|
7285
|
-
if (declaration.type !==
|
|
7647
|
+
if (declaration.type !== import_utils52.AST_NODE_TYPES.VariableDeclaration || declaration.kind !== "const" || declaration.declare === true) {
|
|
7286
7648
|
return;
|
|
7287
7649
|
}
|
|
7288
|
-
if (node.id.type !==
|
|
7650
|
+
if (node.id.type !== import_utils52.AST_NODE_TYPES.Identifier || node.init === null) {
|
|
7289
7651
|
return;
|
|
7290
7652
|
}
|
|
7291
7653
|
if (enclosingFunction2(node) === null) {
|
|
@@ -7312,7 +7674,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
7312
7674
|
});
|
|
7313
7675
|
|
|
7314
7676
|
// src/rules/prefer-module-level-schema.ts
|
|
7315
|
-
var
|
|
7677
|
+
var import_utils53 = require("@typescript-eslint/utils");
|
|
7316
7678
|
|
|
7317
7679
|
// src/rules/_zod.ts
|
|
7318
7680
|
var ZOD_PREFIX_RE = /^Z[A-Z]/;
|
|
@@ -7378,9 +7740,9 @@ var I18N_RECEIVER_NAMES = /* @__PURE__ */ new Set([
|
|
|
7378
7740
|
"intl"
|
|
7379
7741
|
]);
|
|
7380
7742
|
var FUNCTION_TYPES6 = /* @__PURE__ */ new Set([
|
|
7381
|
-
|
|
7382
|
-
|
|
7383
|
-
|
|
7743
|
+
import_utils53.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
7744
|
+
import_utils53.AST_NODE_TYPES.FunctionDeclaration,
|
|
7745
|
+
import_utils53.AST_NODE_TYPES.FunctionExpression
|
|
7384
7746
|
]);
|
|
7385
7747
|
function schemaExpression(node) {
|
|
7386
7748
|
let current = node;
|
|
@@ -7389,10 +7751,10 @@ function schemaExpression(node) {
|
|
|
7389
7751
|
if (parent === void 0) {
|
|
7390
7752
|
return current;
|
|
7391
7753
|
}
|
|
7392
|
-
if (parent.type ===
|
|
7754
|
+
if (parent.type === import_utils53.AST_NODE_TYPES.MemberExpression && parent.object === current && !parent.computed && parent.property.type === import_utils53.AST_NODE_TYPES.Identifier && TERMINAL_METHODS.has(parent.property.name)) {
|
|
7393
7755
|
return current;
|
|
7394
7756
|
}
|
|
7395
|
-
if (parent.type ===
|
|
7757
|
+
if (parent.type === import_utils53.AST_NODE_TYPES.MemberExpression && parent.object === current || parent.type === import_utils53.AST_NODE_TYPES.CallExpression && parent.callee === current || parent.type === import_utils53.AST_NODE_TYPES.TSAsExpression && parent.expression === current || parent.type === import_utils53.AST_NODE_TYPES.TSNonNullExpression && parent.expression === current) {
|
|
7396
7758
|
current = parent;
|
|
7397
7759
|
continue;
|
|
7398
7760
|
}
|
|
@@ -7443,22 +7805,22 @@ function subtreeSome(root, predicate) {
|
|
|
7443
7805
|
function readsReceiver(node) {
|
|
7444
7806
|
return subtreeSome(
|
|
7445
7807
|
node,
|
|
7446
|
-
(inner) => inner.type ===
|
|
7808
|
+
(inner) => inner.type === import_utils53.AST_NODE_TYPES.ThisExpression || inner.type === import_utils53.AST_NODE_TYPES.Super || inner.type === import_utils53.AST_NODE_TYPES.Identifier && inner.name === "arguments"
|
|
7447
7809
|
);
|
|
7448
7810
|
}
|
|
7449
7811
|
function buildsLocalizedText(node) {
|
|
7450
7812
|
return subtreeSome(node, (inner) => {
|
|
7451
|
-
if (inner.type ===
|
|
7813
|
+
if (inner.type === import_utils53.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
7452
7814
|
return true;
|
|
7453
7815
|
}
|
|
7454
|
-
if (inner.type !==
|
|
7816
|
+
if (inner.type !== import_utils53.AST_NODE_TYPES.CallExpression) {
|
|
7455
7817
|
return false;
|
|
7456
7818
|
}
|
|
7457
7819
|
const { callee } = inner;
|
|
7458
|
-
if (callee.type ===
|
|
7820
|
+
if (callee.type === import_utils53.AST_NODE_TYPES.Identifier) {
|
|
7459
7821
|
return I18N_CALLEE_NAMES.has(callee.name);
|
|
7460
7822
|
}
|
|
7461
|
-
return callee.type ===
|
|
7823
|
+
return callee.type === import_utils53.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.object.type === import_utils53.AST_NODE_TYPES.Identifier && I18N_RECEIVER_NAMES.has(callee.object.name);
|
|
7462
7824
|
});
|
|
7463
7825
|
}
|
|
7464
7826
|
function collectReferences(scope, out) {
|
|
@@ -7515,15 +7877,15 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7515
7877
|
}
|
|
7516
7878
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
7517
7879
|
function isZodCall(node) {
|
|
7518
|
-
return node.type ===
|
|
7880
|
+
return node.type === import_utils53.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils53.AST_NODE_TYPES.MemberExpression && !node.callee.computed && node.callee.object.type === import_utils53.AST_NODE_TYPES.Identifier && zodNamespaces.has(node.callee.object.name);
|
|
7519
7881
|
}
|
|
7520
7882
|
function isCovered(node) {
|
|
7521
7883
|
let current = node.parent ?? void 0;
|
|
7522
7884
|
while (current !== void 0) {
|
|
7523
|
-
if (current !== node && isZodCall(current) && current.callee.type ===
|
|
7885
|
+
if (current !== node && isZodCall(current) && current.callee.type === import_utils53.AST_NODE_TYPES.MemberExpression && current.callee.property.type === import_utils53.AST_NODE_TYPES.Identifier && factories.has(current.callee.property.name)) {
|
|
7524
7886
|
return true;
|
|
7525
7887
|
}
|
|
7526
|
-
if (current.type ===
|
|
7888
|
+
if (current.type === import_utils53.AST_NODE_TYPES.CallExpression && (current.callee.type === import_utils53.AST_NODE_TYPES.Identifier && MEMO_CALLEES.has(current.callee.name) || current.callee.type === import_utils53.AST_NODE_TYPES.MemberExpression && !current.callee.computed && current.callee.property.type === import_utils53.AST_NODE_TYPES.Identifier && MEMO_CALLEES.has(current.callee.property.name))) {
|
|
7527
7889
|
return true;
|
|
7528
7890
|
}
|
|
7529
7891
|
current = current.parent ?? void 0;
|
|
@@ -7538,11 +7900,11 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7538
7900
|
if (parent === void 0) {
|
|
7539
7901
|
return confirmed;
|
|
7540
7902
|
}
|
|
7541
|
-
if (parent.type ===
|
|
7903
|
+
if (parent.type === import_utils53.AST_NODE_TYPES.Property && parent.value === current || parent.type === import_utils53.AST_NODE_TYPES.ObjectExpression || parent.type === import_utils53.AST_NODE_TYPES.ArrayExpression) {
|
|
7542
7904
|
current = parent;
|
|
7543
7905
|
continue;
|
|
7544
7906
|
}
|
|
7545
|
-
if (parent.type ===
|
|
7907
|
+
if (parent.type === import_utils53.AST_NODE_TYPES.CallExpression && parent.arguments.includes(current) && isSchemaComposition(parent)) {
|
|
7546
7908
|
current = schemaExpression(parent);
|
|
7547
7909
|
confirmed = current;
|
|
7548
7910
|
continue;
|
|
@@ -7552,7 +7914,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7552
7914
|
}
|
|
7553
7915
|
function isSchemaComposition(node) {
|
|
7554
7916
|
const { callee } = node;
|
|
7555
|
-
const isCombinator = callee.type ===
|
|
7917
|
+
const isCombinator = callee.type === import_utils53.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils53.AST_NODE_TYPES.Identifier && ZOD_COMBINATOR_METHODS.has(callee.property.name);
|
|
7556
7918
|
return isCombinator || isZodCall(node);
|
|
7557
7919
|
}
|
|
7558
7920
|
function closesOverNothing(node, enclosing) {
|
|
@@ -7586,13 +7948,13 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7586
7948
|
}
|
|
7587
7949
|
function ownerName(enclosing) {
|
|
7588
7950
|
const parent = enclosing.parent ?? void 0;
|
|
7589
|
-
if (enclosing.type ===
|
|
7951
|
+
if (enclosing.type === import_utils53.AST_NODE_TYPES.FunctionDeclaration && enclosing.id !== null) {
|
|
7590
7952
|
return enclosing.id.name;
|
|
7591
7953
|
}
|
|
7592
|
-
if (parent !== void 0 && parent.type ===
|
|
7954
|
+
if (parent !== void 0 && parent.type === import_utils53.AST_NODE_TYPES.VariableDeclarator && parent.id.type === import_utils53.AST_NODE_TYPES.Identifier) {
|
|
7593
7955
|
return parent.id.name;
|
|
7594
7956
|
}
|
|
7595
|
-
if (parent !== void 0 && (parent.type ===
|
|
7957
|
+
if (parent !== void 0 && (parent.type === import_utils53.AST_NODE_TYPES.MethodDefinition || parent.type === import_utils53.AST_NODE_TYPES.Property) && parent.key.type === import_utils53.AST_NODE_TYPES.Identifier) {
|
|
7596
7958
|
return parent.key.name;
|
|
7597
7959
|
}
|
|
7598
7960
|
return "this function";
|
|
@@ -7603,7 +7965,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7603
7965
|
return;
|
|
7604
7966
|
}
|
|
7605
7967
|
for (const specifier of node.specifiers) {
|
|
7606
|
-
if (specifier.type ===
|
|
7968
|
+
if (specifier.type === import_utils53.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils53.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils53.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils53.AST_NODE_TYPES.Identifier && specifier.imported.name === "z") {
|
|
7607
7969
|
zodNamespaces.add(specifier.local.name);
|
|
7608
7970
|
}
|
|
7609
7971
|
}
|
|
@@ -7613,7 +7975,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7613
7975
|
return;
|
|
7614
7976
|
}
|
|
7615
7977
|
const callee = node.callee;
|
|
7616
|
-
if (callee.property.type !==
|
|
7978
|
+
if (callee.property.type !== import_utils53.AST_NODE_TYPES.Identifier) {
|
|
7617
7979
|
return;
|
|
7618
7980
|
}
|
|
7619
7981
|
const factory = callee.property.name;
|
|
@@ -7628,7 +7990,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7628
7990
|
return;
|
|
7629
7991
|
}
|
|
7630
7992
|
const shape = node.arguments[0];
|
|
7631
|
-
if (shape !== void 0 && shape.type ===
|
|
7993
|
+
if (shape !== void 0 && shape.type === import_utils53.AST_NODE_TYPES.ObjectExpression && shape.properties.length < minProperties) {
|
|
7632
7994
|
return;
|
|
7633
7995
|
}
|
|
7634
7996
|
const expression = schemaExpression(node);
|
|
@@ -7656,9 +8018,9 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7656
8018
|
});
|
|
7657
8019
|
|
|
7658
8020
|
// src/rules/prefer-native-random-uuid.ts
|
|
7659
|
-
var
|
|
8021
|
+
var import_utils54 = require("@typescript-eslint/utils");
|
|
7660
8022
|
function requireUuid(node) {
|
|
7661
|
-
return node?.type ===
|
|
8023
|
+
return node?.type === import_utils54.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils54.AST_NODE_TYPES.Identifier && node.callee.name === "require" && node.arguments.length === 1 && node.arguments[0]?.type === import_utils54.AST_NODE_TYPES.Literal && node.arguments[0].value === "uuid";
|
|
7662
8024
|
}
|
|
7663
8025
|
var prefer_native_random_uuid_default = createRule({
|
|
7664
8026
|
name: "prefer-native-random-uuid",
|
|
@@ -7679,7 +8041,7 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
7679
8041
|
const directBindings = /* @__PURE__ */ new Set();
|
|
7680
8042
|
const namespaceBindings = /* @__PURE__ */ new Set();
|
|
7681
8043
|
function resolve(identifier) {
|
|
7682
|
-
return
|
|
8044
|
+
return import_utils54.ASTUtils.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
7683
8045
|
}
|
|
7684
8046
|
function record(identifier, destination) {
|
|
7685
8047
|
const variable = resolve(identifier);
|
|
@@ -7701,37 +8063,37 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
7701
8063
|
ImportDeclaration(node) {
|
|
7702
8064
|
if (node.source.value !== "uuid") return;
|
|
7703
8065
|
for (const specifier of node.specifiers) {
|
|
7704
|
-
if (specifier.type ===
|
|
8066
|
+
if (specifier.type === import_utils54.AST_NODE_TYPES.ImportSpecifier && (specifier.imported.type === import_utils54.AST_NODE_TYPES.Identifier ? specifier.imported.name === "v4" : specifier.imported.value === "v4")) {
|
|
7705
8067
|
record(specifier.local, directBindings);
|
|
7706
|
-
} else if (specifier.type ===
|
|
8068
|
+
} else if (specifier.type === import_utils54.AST_NODE_TYPES.ImportNamespaceSpecifier) {
|
|
7707
8069
|
record(specifier.local, namespaceBindings);
|
|
7708
8070
|
}
|
|
7709
8071
|
}
|
|
7710
8072
|
},
|
|
7711
8073
|
VariableDeclarator(node) {
|
|
7712
8074
|
if (node.parent.kind !== "const" || !requireUuid(node.init)) return;
|
|
7713
|
-
if (node.init?.type !==
|
|
8075
|
+
if (node.init?.type !== import_utils54.AST_NODE_TYPES.CallExpression || node.init.callee.type !== import_utils54.AST_NODE_TYPES.Identifier || (resolve(node.init.callee)?.defs.length ?? 0) > 0) {
|
|
7714
8076
|
return;
|
|
7715
8077
|
}
|
|
7716
|
-
if (node.id.type ===
|
|
8078
|
+
if (node.id.type === import_utils54.AST_NODE_TYPES.Identifier) {
|
|
7717
8079
|
record(node.id, namespaceBindings);
|
|
7718
8080
|
return;
|
|
7719
8081
|
}
|
|
7720
|
-
if (node.id.type !==
|
|
8082
|
+
if (node.id.type !== import_utils54.AST_NODE_TYPES.ObjectPattern) return;
|
|
7721
8083
|
for (const property of node.id.properties) {
|
|
7722
|
-
if (property.type ===
|
|
8084
|
+
if (property.type === import_utils54.AST_NODE_TYPES.Property && !property.computed && (property.key.type === import_utils54.AST_NODE_TYPES.Identifier && property.key.name === "v4" || property.key.type === import_utils54.AST_NODE_TYPES.Literal && property.key.value === "v4") && property.value.type === import_utils54.AST_NODE_TYPES.Identifier) {
|
|
7723
8085
|
record(property.value, directBindings);
|
|
7724
8086
|
}
|
|
7725
8087
|
}
|
|
7726
8088
|
},
|
|
7727
8089
|
"CallExpression:exit"(node) {
|
|
7728
8090
|
if (node.arguments.length !== 0) return;
|
|
7729
|
-
if (node.callee.type ===
|
|
8091
|
+
if (node.callee.type === import_utils54.AST_NODE_TYPES.Identifier) {
|
|
7730
8092
|
const variable2 = resolve(node.callee);
|
|
7731
8093
|
if (variable2 !== null && directBindings.has(variable2)) report(node);
|
|
7732
8094
|
return;
|
|
7733
8095
|
}
|
|
7734
|
-
if (node.callee.type !==
|
|
8096
|
+
if (node.callee.type !== import_utils54.AST_NODE_TYPES.MemberExpression || node.callee.computed || node.callee.object.type !== import_utils54.AST_NODE_TYPES.Identifier || node.callee.property.type !== import_utils54.AST_NODE_TYPES.Identifier || node.callee.property.name !== "v4") {
|
|
7735
8097
|
return;
|
|
7736
8098
|
}
|
|
7737
8099
|
const variable = resolve(node.callee.object);
|
|
@@ -7742,20 +8104,20 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
7742
8104
|
});
|
|
7743
8105
|
|
|
7744
8106
|
// src/rules/prefer-non-nullable-collection.ts
|
|
7745
|
-
var
|
|
8107
|
+
var import_utils55 = require("@typescript-eslint/utils");
|
|
7746
8108
|
var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
7747
8109
|
function propertyName(node) {
|
|
7748
8110
|
const key = node.key;
|
|
7749
|
-
if (key.type ===
|
|
7750
|
-
if (key.type ===
|
|
8111
|
+
if (key.type === import_utils55.AST_NODE_TYPES.Identifier) return key.name;
|
|
8112
|
+
if (key.type === import_utils55.AST_NODE_TYPES.Literal) return String(key.value);
|
|
7751
8113
|
return "collection";
|
|
7752
8114
|
}
|
|
7753
8115
|
function isArrayType(node) {
|
|
7754
|
-
if (node.type ===
|
|
7755
|
-
return node.type ===
|
|
8116
|
+
if (node.type === import_utils55.AST_NODE_TYPES.TSArrayType) return true;
|
|
8117
|
+
return node.type === import_utils55.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils55.AST_NODE_TYPES.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
7756
8118
|
}
|
|
7757
8119
|
function isNullishType(node) {
|
|
7758
|
-
return node.type ===
|
|
8120
|
+
return node.type === import_utils55.AST_NODE_TYPES.TSNullKeyword || node.type === import_utils55.AST_NODE_TYPES.TSUndefinedKeyword;
|
|
7759
8121
|
}
|
|
7760
8122
|
function isNullableArrayOnly(node) {
|
|
7761
8123
|
const values = node.types.filter((member) => !isNullishType(member));
|
|
@@ -7783,7 +8145,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
7783
8145
|
if (node.optional) return;
|
|
7784
8146
|
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
7785
8147
|
if (annotation === void 0) return;
|
|
7786
|
-
if (annotation.type !==
|
|
8148
|
+
if (annotation.type !== import_utils55.AST_NODE_TYPES.TSUnionType || !isNullableArrayOnly(annotation)) {
|
|
7787
8149
|
return;
|
|
7788
8150
|
}
|
|
7789
8151
|
context.report({
|
|
@@ -7796,7 +8158,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
7796
8158
|
TSPropertySignature: checkOptionalProperty,
|
|
7797
8159
|
PropertyDefinition: checkOptionalProperty,
|
|
7798
8160
|
TSTypeAliasDeclaration(node) {
|
|
7799
|
-
if (node.typeAnnotation.type !==
|
|
8161
|
+
if (node.typeAnnotation.type !== import_utils55.AST_NODE_TYPES.TSUnionType) return;
|
|
7800
8162
|
if (!isNullableArrayOnly(node.typeAnnotation)) return;
|
|
7801
8163
|
context.report({
|
|
7802
8164
|
node,
|
|
@@ -7809,13 +8171,13 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
7809
8171
|
});
|
|
7810
8172
|
|
|
7811
8173
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
7812
|
-
var
|
|
8174
|
+
var import_utils56 = require("@typescript-eslint/utils");
|
|
7813
8175
|
var unwrap4 = (node) => {
|
|
7814
8176
|
let current = node;
|
|
7815
8177
|
while (current !== null && current !== void 0) {
|
|
7816
|
-
if (current.type ===
|
|
8178
|
+
if (current.type === import_utils56.AST_NODE_TYPES.TSAsExpression || current.type === import_utils56.AST_NODE_TYPES.TSTypeAssertion || current.type === import_utils56.AST_NODE_TYPES.TSNonNullExpression || current.type === import_utils56.AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
7817
8179
|
current = current.expression;
|
|
7818
|
-
} else if (current.type ===
|
|
8180
|
+
} else if (current.type === import_utils56.AST_NODE_TYPES.ChainExpression) {
|
|
7819
8181
|
current = current.expression;
|
|
7820
8182
|
} else {
|
|
7821
8183
|
break;
|
|
@@ -7830,23 +8192,23 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
7830
8192
|
]);
|
|
7831
8193
|
var isSchemaParseReference = (node) => {
|
|
7832
8194
|
const inner = unwrap4(node);
|
|
7833
|
-
return inner !== null && inner.type ===
|
|
8195
|
+
return inner !== null && inner.type === import_utils56.AST_NODE_TYPES.MemberExpression && !inner.computed && inner.property.type === import_utils56.AST_NODE_TYPES.Identifier && (inner.property.name === "parse" || inner.property.name === "safeParse");
|
|
7834
8196
|
};
|
|
7835
8197
|
var isRawPayloadSource = (node) => {
|
|
7836
8198
|
let current = unwrap4(node);
|
|
7837
8199
|
if (current === null) return false;
|
|
7838
|
-
if (current.type ===
|
|
8200
|
+
if (current.type === import_utils56.AST_NODE_TYPES.AwaitExpression) {
|
|
7839
8201
|
current = unwrap4(current.argument);
|
|
7840
8202
|
}
|
|
7841
|
-
if (current === null || current.type !==
|
|
8203
|
+
if (current === null || current.type !== import_utils56.AST_NODE_TYPES.CallExpression) {
|
|
7842
8204
|
return false;
|
|
7843
8205
|
}
|
|
7844
8206
|
const callee = unwrap4(current.callee);
|
|
7845
|
-
if (callee === null || callee.type !==
|
|
8207
|
+
if (callee === null || callee.type !== import_utils56.AST_NODE_TYPES.MemberExpression) {
|
|
7846
8208
|
return false;
|
|
7847
8209
|
}
|
|
7848
8210
|
const property = unwrap4(callee.property);
|
|
7849
|
-
if (property === null || property.type !==
|
|
8211
|
+
if (property === null || property.type !== import_utils56.AST_NODE_TYPES.Identifier) {
|
|
7850
8212
|
return false;
|
|
7851
8213
|
}
|
|
7852
8214
|
if (property.name === "json") {
|
|
@@ -7856,16 +8218,16 @@ var isRawPayloadSource = (node) => {
|
|
|
7856
8218
|
return !current.arguments.some(isSchemaParseReference) && isRawPayloadSource(callee.object);
|
|
7857
8219
|
}
|
|
7858
8220
|
const object = unwrap4(callee.object);
|
|
7859
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
8221
|
+
return property.name === "parse" && object !== null && object.type === import_utils56.AST_NODE_TYPES.Identifier && object.name === "JSON" && !isLocalFileRead(current.arguments[0]);
|
|
7860
8222
|
};
|
|
7861
8223
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
7862
8224
|
var isLocalFileRead = (node) => {
|
|
7863
8225
|
let found = false;
|
|
7864
8226
|
const visit = (current) => {
|
|
7865
8227
|
if (found || current === null || current === void 0) return;
|
|
7866
|
-
if (current.type ===
|
|
8228
|
+
if (current.type === import_utils56.AST_NODE_TYPES.CallExpression) {
|
|
7867
8229
|
const callee = unwrap4(current.callee);
|
|
7868
|
-
const name = callee?.type ===
|
|
8230
|
+
const name = callee?.type === import_utils56.AST_NODE_TYPES.Identifier ? callee.name : callee?.type === import_utils56.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils56.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
7869
8231
|
if (name !== null && FILE_READ_RE.test(name)) {
|
|
7870
8232
|
found = true;
|
|
7871
8233
|
return;
|
|
@@ -7887,15 +8249,15 @@ var isLocalFileRead = (node) => {
|
|
|
7887
8249
|
var ASSERTION_CALLEE_RE = /^(expect|assert|should|invariant)$/;
|
|
7888
8250
|
var isInsideAssertion = (node) => {
|
|
7889
8251
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
7890
|
-
if (current.type !==
|
|
8252
|
+
if (current.type !== import_utils56.AST_NODE_TYPES.CallExpression) continue;
|
|
7891
8253
|
let callee = current.callee;
|
|
7892
|
-
while (callee.type ===
|
|
8254
|
+
while (callee.type === import_utils56.AST_NODE_TYPES.MemberExpression) {
|
|
7893
8255
|
callee = callee.object;
|
|
7894
8256
|
}
|
|
7895
|
-
if (callee.type ===
|
|
8257
|
+
if (callee.type === import_utils56.AST_NODE_TYPES.CallExpression) {
|
|
7896
8258
|
callee = callee.callee;
|
|
7897
8259
|
}
|
|
7898
|
-
if (callee.type ===
|
|
8260
|
+
if (callee.type === import_utils56.AST_NODE_TYPES.Identifier && ASSERTION_CALLEE_RE.test(callee.name)) {
|
|
7899
8261
|
return true;
|
|
7900
8262
|
}
|
|
7901
8263
|
}
|
|
@@ -7914,39 +8276,39 @@ var GUARD_NAME_RE = /^(?:is|validate|parse|assert|decode|coerce)[A-Z]/;
|
|
|
7914
8276
|
var isValidationRead = (node) => {
|
|
7915
8277
|
let current = node;
|
|
7916
8278
|
let parent = current.parent;
|
|
7917
|
-
while (parent !== null && parent !== void 0 && (parent.type ===
|
|
8279
|
+
while (parent !== null && parent !== void 0 && (parent.type === import_utils56.AST_NODE_TYPES.TSAsExpression || parent.type === import_utils56.AST_NODE_TYPES.TSTypeAssertion || parent.type === import_utils56.AST_NODE_TYPES.TSNonNullExpression || parent.type === import_utils56.AST_NODE_TYPES.TSSatisfiesExpression || parent.type === import_utils56.AST_NODE_TYPES.ChainExpression)) {
|
|
7918
8280
|
current = parent;
|
|
7919
8281
|
parent = parent.parent;
|
|
7920
8282
|
}
|
|
7921
8283
|
if (parent === null || parent === void 0) return false;
|
|
7922
|
-
if (parent.type ===
|
|
8284
|
+
if (parent.type === import_utils56.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof" && parent.argument === current) {
|
|
7923
8285
|
return true;
|
|
7924
8286
|
}
|
|
7925
|
-
if (parent.type !==
|
|
8287
|
+
if (parent.type !== import_utils56.AST_NODE_TYPES.CallExpression || !parent.arguments.some((arg) => arg === current)) {
|
|
7926
8288
|
return false;
|
|
7927
8289
|
}
|
|
7928
8290
|
const callee = parent.callee;
|
|
7929
|
-
if (callee.type ===
|
|
8291
|
+
if (callee.type === import_utils56.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.object.type === import_utils56.AST_NODE_TYPES.Identifier && callee.object.name === "Array" && callee.property.type === import_utils56.AST_NODE_TYPES.Identifier && callee.property.name === "isArray") {
|
|
7930
8292
|
return parent.arguments.length === 1;
|
|
7931
8293
|
}
|
|
7932
|
-
return callee.type ===
|
|
8294
|
+
return callee.type === import_utils56.AST_NODE_TYPES.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
7933
8295
|
};
|
|
7934
8296
|
var isGuardTestPosition = (node) => {
|
|
7935
8297
|
let current = node;
|
|
7936
8298
|
let parent = current.parent;
|
|
7937
8299
|
while (parent !== void 0 && parent !== null) {
|
|
7938
8300
|
switch (parent.type) {
|
|
7939
|
-
case
|
|
7940
|
-
case
|
|
7941
|
-
case
|
|
8301
|
+
case import_utils56.AST_NODE_TYPES.UnaryExpression:
|
|
8302
|
+
case import_utils56.AST_NODE_TYPES.LogicalExpression:
|
|
8303
|
+
case import_utils56.AST_NODE_TYPES.ChainExpression:
|
|
7942
8304
|
current = parent;
|
|
7943
8305
|
parent = parent.parent;
|
|
7944
8306
|
continue;
|
|
7945
|
-
case
|
|
7946
|
-
case
|
|
7947
|
-
case
|
|
7948
|
-
case
|
|
7949
|
-
case
|
|
8307
|
+
case import_utils56.AST_NODE_TYPES.IfStatement:
|
|
8308
|
+
case import_utils56.AST_NODE_TYPES.ConditionalExpression:
|
|
8309
|
+
case import_utils56.AST_NODE_TYPES.WhileStatement:
|
|
8310
|
+
case import_utils56.AST_NODE_TYPES.DoWhileStatement:
|
|
8311
|
+
case import_utils56.AST_NODE_TYPES.ForStatement:
|
|
7950
8312
|
return parent.test === current;
|
|
7951
8313
|
default:
|
|
7952
8314
|
return false;
|
|
@@ -7956,7 +8318,7 @@ var isGuardTestPosition = (node) => {
|
|
|
7956
8318
|
};
|
|
7957
8319
|
var isUnvalidatedVariableRef = (node, scope, tracked) => {
|
|
7958
8320
|
const unwrapped = unwrap4(node);
|
|
7959
|
-
if (unwrapped === null || unwrapped.type !==
|
|
8321
|
+
if (unwrapped === null || unwrapped.type !== import_utils56.AST_NODE_TYPES.Identifier) {
|
|
7960
8322
|
return false;
|
|
7961
8323
|
}
|
|
7962
8324
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -7999,11 +8361,11 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7999
8361
|
return {
|
|
8000
8362
|
VariableDeclarator(node) {
|
|
8001
8363
|
const scope = context.sourceCode.getScope(node);
|
|
8002
|
-
if (node.id.type ===
|
|
8364
|
+
if (node.id.type === import_utils56.AST_NODE_TYPES.Identifier) {
|
|
8003
8365
|
trackInitializer(node);
|
|
8004
8366
|
return;
|
|
8005
8367
|
}
|
|
8006
|
-
if (node.id.type ===
|
|
8368
|
+
if (node.id.type === import_utils56.AST_NODE_TYPES.ObjectPattern || node.id.type === import_utils56.AST_NODE_TYPES.ArrayPattern) {
|
|
8007
8369
|
if (isRawPayloadSource(node.init)) {
|
|
8008
8370
|
if (!isFullyNarrowedPattern(node)) {
|
|
8009
8371
|
context.report({ node: node.id, messageId: "unparsedJsonAccess" });
|
|
@@ -8017,7 +8379,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
8017
8379
|
},
|
|
8018
8380
|
AssignmentExpression(node) {
|
|
8019
8381
|
const scope = context.sourceCode.getScope(node);
|
|
8020
|
-
if (node.left.type ===
|
|
8382
|
+
if (node.left.type === import_utils56.AST_NODE_TYPES.Identifier) {
|
|
8021
8383
|
const variable = findVariable2(scope, node.left.name);
|
|
8022
8384
|
if (variable === null) return;
|
|
8023
8385
|
if (isRawPayloadSource(node.right)) {
|
|
@@ -8027,7 +8389,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
8027
8389
|
}
|
|
8028
8390
|
return;
|
|
8029
8391
|
}
|
|
8030
|
-
if (node.left.type ===
|
|
8392
|
+
if (node.left.type === import_utils56.AST_NODE_TYPES.ObjectPattern || node.left.type === import_utils56.AST_NODE_TYPES.ArrayPattern) {
|
|
8031
8393
|
if (isRawPayloadSource(node.right)) {
|
|
8032
8394
|
context.report({
|
|
8033
8395
|
node: node.left,
|
|
@@ -8044,15 +8406,15 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
8044
8406
|
}
|
|
8045
8407
|
},
|
|
8046
8408
|
CallExpression(node) {
|
|
8047
|
-
if (node.callee.type !==
|
|
8409
|
+
if (node.callee.type !== import_utils56.AST_NODE_TYPES.Identifier) return;
|
|
8048
8410
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
8049
8411
|
return;
|
|
8050
8412
|
}
|
|
8051
8413
|
const scope = context.sourceCode.getScope(node);
|
|
8052
8414
|
for (const arg of node.arguments) {
|
|
8053
|
-
if (arg.type ===
|
|
8415
|
+
if (arg.type === import_utils56.AST_NODE_TYPES.SpreadElement) continue;
|
|
8054
8416
|
const unwrapped = unwrap4(arg);
|
|
8055
|
-
if (unwrapped === null || unwrapped.type !==
|
|
8417
|
+
if (unwrapped === null || unwrapped.type !== import_utils56.AST_NODE_TYPES.Identifier) {
|
|
8056
8418
|
continue;
|
|
8057
8419
|
}
|
|
8058
8420
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -8066,13 +8428,13 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
8066
8428
|
const obj = unwrap4(node.object);
|
|
8067
8429
|
if (isRawPayloadSource(obj)) {
|
|
8068
8430
|
const parent = node.parent;
|
|
8069
|
-
if (parent.type ===
|
|
8431
|
+
if (parent.type === import_utils56.AST_NODE_TYPES.CallExpression && parent.callee === node && node.property.type === import_utils56.AST_NODE_TYPES.Identifier && (node.property.name === "parse" || node.property.name === "safeParse" || PROMISE_CHAIN_METHODS.has(node.property.name))) {
|
|
8070
8432
|
return;
|
|
8071
8433
|
}
|
|
8072
8434
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
8073
8435
|
return;
|
|
8074
8436
|
}
|
|
8075
|
-
if (obj !== null && obj.type ===
|
|
8437
|
+
if (obj !== null && obj.type === import_utils56.AST_NODE_TYPES.Identifier && isUnvalidatedVariableRef(obj, scope, unvalidatedVariables)) {
|
|
8076
8438
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
8077
8439
|
const variable = findVariable2(scope, obj.name);
|
|
8078
8440
|
if (variable !== null) {
|
|
@@ -8085,7 +8447,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
8085
8447
|
});
|
|
8086
8448
|
|
|
8087
8449
|
// src/rules/prefer-semantic-colors.ts
|
|
8088
|
-
var
|
|
8450
|
+
var import_utils57 = require("@typescript-eslint/utils");
|
|
8089
8451
|
var import_fs = require("fs");
|
|
8090
8452
|
var import_path = require("path");
|
|
8091
8453
|
|
|
@@ -8185,8 +8547,8 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
8185
8547
|
]);
|
|
8186
8548
|
function jsxElementName(node) {
|
|
8187
8549
|
const name = node.openingElement.name;
|
|
8188
|
-
if (name.type ===
|
|
8189
|
-
if (name.type ===
|
|
8550
|
+
if (name.type === import_utils57.AST_NODE_TYPES.JSXIdentifier) return name.name;
|
|
8551
|
+
if (name.type === import_utils57.AST_NODE_TYPES.JSXMemberExpression && name.property.type === import_utils57.AST_NODE_TYPES.JSXIdentifier) {
|
|
8190
8552
|
return name.property.name;
|
|
8191
8553
|
}
|
|
8192
8554
|
return null;
|
|
@@ -8212,7 +8574,7 @@ var EMAIL_OR_PDF_MODULE_RE = /^@react-(?:email|pdf)\//;
|
|
|
8212
8574
|
var isInsideSvg = (node) => {
|
|
8213
8575
|
let current = node.parent;
|
|
8214
8576
|
while (current !== void 0 && current !== null) {
|
|
8215
|
-
if (current.type ===
|
|
8577
|
+
if (current.type === import_utils57.AST_NODE_TYPES.JSXElement) {
|
|
8216
8578
|
const name = jsxElementName(current);
|
|
8217
8579
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
8218
8580
|
}
|
|
@@ -8223,7 +8585,7 @@ var isInsideSvg = (node) => {
|
|
|
8223
8585
|
var isInsideIconFactoryPath = (node) => {
|
|
8224
8586
|
let current = node.parent;
|
|
8225
8587
|
while (current !== void 0 && current !== null) {
|
|
8226
|
-
if (current.type ===
|
|
8588
|
+
if (current.type === import_utils57.AST_NODE_TYPES.Property && propName(current.key) === "path" && current.parent.type === import_utils57.AST_NODE_TYPES.ObjectExpression && current.parent.parent.type === import_utils57.AST_NODE_TYPES.CallExpression && current.parent.parent.callee.type === import_utils57.AST_NODE_TYPES.Identifier && current.parent.parent.callee.name === "createIcon") {
|
|
8227
8589
|
return true;
|
|
8228
8590
|
}
|
|
8229
8591
|
current = current.parent;
|
|
@@ -8360,12 +8722,12 @@ var hasSemanticTokenSystem = (filename) => {
|
|
|
8360
8722
|
return root !== null && workspaceHasMarker(root);
|
|
8361
8723
|
};
|
|
8362
8724
|
var propName = (key) => {
|
|
8363
|
-
if (key.type ===
|
|
8364
|
-
if (key.type ===
|
|
8725
|
+
if (key.type === import_utils57.AST_NODE_TYPES.Identifier) return key.name;
|
|
8726
|
+
if (key.type === import_utils57.AST_NODE_TYPES.Literal && typeof key.value === "string") return key.value;
|
|
8365
8727
|
return null;
|
|
8366
8728
|
};
|
|
8367
8729
|
var staticallyImportsEmailOrPdfRenderer = (program) => program.body.some((statement) => {
|
|
8368
|
-
if (statement.type !==
|
|
8730
|
+
if (statement.type !== import_utils57.AST_NODE_TYPES.ImportDeclaration && statement.type !== import_utils57.AST_NODE_TYPES.ExportNamedDeclaration && statement.type !== import_utils57.AST_NODE_TYPES.ExportAllDeclaration) {
|
|
8369
8731
|
return false;
|
|
8370
8732
|
}
|
|
8371
8733
|
return statement.source !== null && typeof statement.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(statement.source.value);
|
|
@@ -8417,27 +8779,27 @@ var prefer_semantic_colors_default = createRule({
|
|
|
8417
8779
|
const checkClassNode = (node) => {
|
|
8418
8780
|
if (node === null) return;
|
|
8419
8781
|
switch (node.type) {
|
|
8420
|
-
case
|
|
8782
|
+
case import_utils57.AST_NODE_TYPES.Literal:
|
|
8421
8783
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
8422
8784
|
break;
|
|
8423
|
-
case
|
|
8785
|
+
case import_utils57.AST_NODE_TYPES.TemplateLiteral:
|
|
8424
8786
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
8425
8787
|
break;
|
|
8426
|
-
case
|
|
8788
|
+
case import_utils57.AST_NODE_TYPES.ArrayExpression:
|
|
8427
8789
|
for (const element of node.elements) {
|
|
8428
|
-
if (element !== null && element.type !==
|
|
8790
|
+
if (element !== null && element.type !== import_utils57.AST_NODE_TYPES.SpreadElement) checkClassNode(element);
|
|
8429
8791
|
}
|
|
8430
8792
|
break;
|
|
8431
|
-
case
|
|
8793
|
+
case import_utils57.AST_NODE_TYPES.ObjectExpression:
|
|
8432
8794
|
for (const property of node.properties) {
|
|
8433
|
-
if (property.type ===
|
|
8795
|
+
if (property.type === import_utils57.AST_NODE_TYPES.Property) checkClassNode(property.value);
|
|
8434
8796
|
}
|
|
8435
8797
|
break;
|
|
8436
|
-
case
|
|
8798
|
+
case import_utils57.AST_NODE_TYPES.ConditionalExpression:
|
|
8437
8799
|
checkClassNode(node.consequent);
|
|
8438
8800
|
checkClassNode(node.alternate);
|
|
8439
8801
|
break;
|
|
8440
|
-
case
|
|
8802
|
+
case import_utils57.AST_NODE_TYPES.LogicalExpression:
|
|
8441
8803
|
checkClassNode(node.right);
|
|
8442
8804
|
break;
|
|
8443
8805
|
default:
|
|
@@ -8445,32 +8807,32 @@ var prefer_semantic_colors_default = createRule({
|
|
|
8445
8807
|
}
|
|
8446
8808
|
};
|
|
8447
8809
|
const checkColorValueNode = (node) => {
|
|
8448
|
-
if (node.type ===
|
|
8810
|
+
if (node.type === import_utils57.AST_NODE_TYPES.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value) && !CSS_VAR_REFERENCE_RE.test(node.value)) {
|
|
8449
8811
|
report(node, "inlineColor", { value: node.value });
|
|
8450
8812
|
}
|
|
8451
8813
|
};
|
|
8452
8814
|
return {
|
|
8453
8815
|
"JSXAttribute[name.name='className']"(node) {
|
|
8454
8816
|
if (node.value === null) return;
|
|
8455
|
-
if (node.value.type ===
|
|
8456
|
-
else if (node.value.type ===
|
|
8457
|
-
if (node.value.expression.type !==
|
|
8817
|
+
if (node.value.type === import_utils57.AST_NODE_TYPES.Literal) checkClassNode(node.value);
|
|
8818
|
+
else if (node.value.type === import_utils57.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
8819
|
+
if (node.value.expression.type !== import_utils57.AST_NODE_TYPES.JSXEmptyExpression) {
|
|
8458
8820
|
checkClassNode(node.value.expression);
|
|
8459
8821
|
}
|
|
8460
8822
|
}
|
|
8461
8823
|
},
|
|
8462
8824
|
CallExpression(node) {
|
|
8463
|
-
if (node.callee.type ===
|
|
8825
|
+
if (node.callee.type === import_utils57.AST_NODE_TYPES.Identifier && node.callee.name === "require" && node.arguments[0]?.type === import_utils57.AST_NODE_TYPES.Literal && typeof node.arguments[0].value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.arguments[0].value)) {
|
|
8464
8826
|
importsEmailOrPdfRenderer = true;
|
|
8465
8827
|
}
|
|
8466
|
-
if (node.callee.type ===
|
|
8828
|
+
if (node.callee.type === import_utils57.AST_NODE_TYPES.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
8467
8829
|
for (const arg of node.arguments) {
|
|
8468
|
-
if (arg.type !==
|
|
8830
|
+
if (arg.type !== import_utils57.AST_NODE_TYPES.SpreadElement) checkClassNode(arg);
|
|
8469
8831
|
}
|
|
8470
8832
|
}
|
|
8471
8833
|
},
|
|
8472
8834
|
VariableDeclarator(node) {
|
|
8473
|
-
if (node.id.type ===
|
|
8835
|
+
if (node.id.type === import_utils57.AST_NODE_TYPES.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
8474
8836
|
checkClassNode(node.init);
|
|
8475
8837
|
}
|
|
8476
8838
|
},
|
|
@@ -8480,9 +8842,9 @@ var prefer_semantic_colors_default = createRule({
|
|
|
8480
8842
|
},
|
|
8481
8843
|
// SVG artwork colors are exempt; component presentation colors still report.
|
|
8482
8844
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
8483
|
-
if (node.value?.type !==
|
|
8845
|
+
if (node.value?.type !== import_utils57.AST_NODE_TYPES.Literal) return;
|
|
8484
8846
|
const owner = node.parent.name;
|
|
8485
|
-
if (owner.type ===
|
|
8847
|
+
if (owner.type === import_utils57.AST_NODE_TYPES.JSXIdentifier && SVG_SHAPE_PRIMITIVES.has(owner.name)) {
|
|
8486
8848
|
return;
|
|
8487
8849
|
}
|
|
8488
8850
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
@@ -8496,7 +8858,7 @@ var prefer_semantic_colors_default = createRule({
|
|
|
8496
8858
|
if (name !== null && STYLE_COLOR_PROPS.has(name)) checkColorValueNode(node.value);
|
|
8497
8859
|
},
|
|
8498
8860
|
ImportExpression(node) {
|
|
8499
|
-
if (node.source.type ===
|
|
8861
|
+
if (node.source.type === import_utils57.AST_NODE_TYPES.Literal && typeof node.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.source.value)) {
|
|
8500
8862
|
importsEmailOrPdfRenderer = true;
|
|
8501
8863
|
}
|
|
8502
8864
|
},
|
|
@@ -8509,7 +8871,7 @@ var prefer_semantic_colors_default = createRule({
|
|
|
8509
8871
|
});
|
|
8510
8872
|
|
|
8511
8873
|
// src/rules/prefer-server-actions.ts
|
|
8512
|
-
var
|
|
8874
|
+
var import_utils58 = require("@typescript-eslint/utils");
|
|
8513
8875
|
var MUTATION_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "DELETE", "PATCH"]);
|
|
8514
8876
|
var AXIOS_MUTATION_METHODS = /* @__PURE__ */ new Set(["post", "put", "delete", "patch"]);
|
|
8515
8877
|
var SKIP_FILE_REGEX = /(?:\.test\.[jt]sx?$|\.spec\.[jt]sx?$|-(?:test|spec)\.[jt]sx?$|\/tests?\/|\/__tests__\/|\/__testfixtures__\/|\/scripts?\/|\/app\/api\/.*\/route\.[jt]sx?$|\/pages\/api\/)/;
|
|
@@ -8643,8 +9005,8 @@ var prefer_server_actions_default = createRule({
|
|
|
8643
9005
|
}
|
|
8644
9006
|
}
|
|
8645
9007
|
} else if (node.callee.type === "MemberExpression" && node.callee.property.type === "Identifier" && !node.callee.computed) {
|
|
8646
|
-
const
|
|
8647
|
-
if (AXIOS_MUTATION_METHODS.has(
|
|
9008
|
+
const methodName2 = node.callee.property.name.toLowerCase();
|
|
9009
|
+
if (AXIOS_MUTATION_METHODS.has(methodName2)) {
|
|
8648
9010
|
const urlArg = node.arguments[0];
|
|
8649
9011
|
const hasHandlerArg = node.arguments.some(
|
|
8650
9012
|
(arg) => arg.type !== "SpreadElement" && isFunctionArgument(arg, context)
|
|
@@ -8700,7 +9062,7 @@ var prefer_single_sentence_comment_default = createRule({
|
|
|
8700
9062
|
});
|
|
8701
9063
|
|
|
8702
9064
|
// src/rules/prefer-string-literal-union.ts
|
|
8703
|
-
var
|
|
9065
|
+
var import_utils59 = require("@typescript-eslint/utils");
|
|
8704
9066
|
var ts2 = __toESM(require("typescript"), 1);
|
|
8705
9067
|
var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
8706
9068
|
"status",
|
|
@@ -8743,19 +9105,19 @@ function isChoiceLikeName(name) {
|
|
|
8743
9105
|
return CHOICE_TOKENS.has(lastWord(name));
|
|
8744
9106
|
}
|
|
8745
9107
|
function keyName(key) {
|
|
8746
|
-
if (key.type ===
|
|
9108
|
+
if (key.type === import_utils59.AST_NODE_TYPES.Identifier) {
|
|
8747
9109
|
return key.name;
|
|
8748
9110
|
}
|
|
8749
|
-
if (key.type ===
|
|
9111
|
+
if (key.type === import_utils59.AST_NODE_TYPES.Literal && typeof key.value === "string") {
|
|
8750
9112
|
return key.value;
|
|
8751
9113
|
}
|
|
8752
9114
|
return null;
|
|
8753
9115
|
}
|
|
8754
9116
|
function isStringLiteralMember(t) {
|
|
8755
|
-
return t.type ===
|
|
9117
|
+
return t.type === import_utils59.AST_NODE_TYPES.TSLiteralType && t.literal.type === import_utils59.AST_NODE_TYPES.Literal && typeof t.literal.value === "string";
|
|
8756
9118
|
}
|
|
8757
9119
|
function isStringLiteralUnion(node) {
|
|
8758
|
-
if (node?.type !==
|
|
9120
|
+
if (node?.type !== import_utils59.AST_NODE_TYPES.TSUnionType) {
|
|
8759
9121
|
return false;
|
|
8760
9122
|
}
|
|
8761
9123
|
return node.types.filter(isStringLiteralMember).length >= MIN_CLUSTER_SIZE;
|
|
@@ -8784,12 +9146,12 @@ function bindingSourceExpression(decl) {
|
|
|
8784
9146
|
return ts2.isForOfStatement(node) ? node.expression : node.initializer;
|
|
8785
9147
|
}
|
|
8786
9148
|
function refKey(node) {
|
|
8787
|
-
if (node.type ===
|
|
9149
|
+
if (node.type === import_utils59.AST_NODE_TYPES.Identifier) {
|
|
8788
9150
|
return node.name;
|
|
8789
9151
|
}
|
|
8790
|
-
if (node.type ===
|
|
9152
|
+
if (node.type === import_utils59.AST_NODE_TYPES.MemberExpression && !node.computed) {
|
|
8791
9153
|
const inner = refKey(node.object);
|
|
8792
|
-
if (inner === null || node.property.type !==
|
|
9154
|
+
if (inner === null || node.property.type !== import_utils59.AST_NODE_TYPES.Identifier) {
|
|
8793
9155
|
return null;
|
|
8794
9156
|
}
|
|
8795
9157
|
return `${inner}.${node.property.name}`;
|
|
@@ -8797,7 +9159,7 @@ function refKey(node) {
|
|
|
8797
9159
|
return null;
|
|
8798
9160
|
}
|
|
8799
9161
|
function strLiteral(node) {
|
|
8800
|
-
if (node.type ===
|
|
9162
|
+
if (node.type === import_utils59.AST_NODE_TYPES.Literal && typeof node.value === "string") {
|
|
8801
9163
|
return node.value;
|
|
8802
9164
|
}
|
|
8803
9165
|
return null;
|
|
@@ -8838,7 +9200,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
8838
9200
|
);
|
|
8839
9201
|
let services;
|
|
8840
9202
|
try {
|
|
8841
|
-
services =
|
|
9203
|
+
services = import_utils59.ESLintUtils.getParserServices(context);
|
|
8842
9204
|
} catch {
|
|
8843
9205
|
services = null;
|
|
8844
9206
|
}
|
|
@@ -8950,7 +9312,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
8950
9312
|
containersWithUnion.add(container);
|
|
8951
9313
|
return;
|
|
8952
9314
|
}
|
|
8953
|
-
if (typeNode?.type !==
|
|
9315
|
+
if (typeNode?.type !== import_utils59.AST_NODE_TYPES.TSStringKeyword) {
|
|
8954
9316
|
return;
|
|
8955
9317
|
}
|
|
8956
9318
|
const name = keyName(key);
|
|
@@ -9038,10 +9400,10 @@ var prefer_string_literal_union_default = createRule({
|
|
|
9038
9400
|
}
|
|
9039
9401
|
};
|
|
9040
9402
|
function refKeyText(node) {
|
|
9041
|
-
if (node.type ===
|
|
9403
|
+
if (node.type === import_utils59.AST_NODE_TYPES.BinaryExpression) {
|
|
9042
9404
|
return refKey(node.left) ?? refKey(node.right) ?? "value";
|
|
9043
9405
|
}
|
|
9044
|
-
if (node.type ===
|
|
9406
|
+
if (node.type === import_utils59.AST_NODE_TYPES.SwitchStatement) {
|
|
9045
9407
|
return refKey(node.discriminant) ?? "value";
|
|
9046
9408
|
}
|
|
9047
9409
|
return "value";
|
|
@@ -9050,7 +9412,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
9050
9412
|
});
|
|
9051
9413
|
|
|
9052
9414
|
// src/rules/prefer-whole-object-assertion.ts
|
|
9053
|
-
var
|
|
9415
|
+
var import_utils60 = require("@typescript-eslint/utils");
|
|
9054
9416
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
9055
9417
|
var ARRAY_MATCHERS = /* @__PURE__ */ new Set(["toEqual", "toStrictEqual"]);
|
|
9056
9418
|
var COLLECTION_PROPERTIES = /* @__PURE__ */ new Set(["length", "size"]);
|
|
@@ -9059,11 +9421,11 @@ var NUMERIC_SIGNS2 = /* @__PURE__ */ new Set(["-", "+"]);
|
|
|
9059
9421
|
var MIN_RUN_LENGTH = 2;
|
|
9060
9422
|
function literalText(node, getText) {
|
|
9061
9423
|
switch (node.type) {
|
|
9062
|
-
case
|
|
9424
|
+
case import_utils60.AST_NODE_TYPES.Literal:
|
|
9063
9425
|
return "regex" in node ? null : getText(node);
|
|
9064
|
-
case
|
|
9426
|
+
case import_utils60.AST_NODE_TYPES.TemplateLiteral:
|
|
9065
9427
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
9066
|
-
case
|
|
9428
|
+
case import_utils60.AST_NODE_TYPES.UnaryExpression:
|
|
9067
9429
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
9068
9430
|
default:
|
|
9069
9431
|
return null;
|
|
@@ -9071,15 +9433,15 @@ function literalText(node, getText) {
|
|
|
9071
9433
|
}
|
|
9072
9434
|
function isPureReceiver(node) {
|
|
9073
9435
|
switch (node.type) {
|
|
9074
|
-
case
|
|
9075
|
-
case
|
|
9436
|
+
case import_utils60.AST_NODE_TYPES.Identifier:
|
|
9437
|
+
case import_utils60.AST_NODE_TYPES.ThisExpression:
|
|
9076
9438
|
return true;
|
|
9077
|
-
case
|
|
9439
|
+
case import_utils60.AST_NODE_TYPES.MemberExpression:
|
|
9078
9440
|
if (node.optional) {
|
|
9079
9441
|
return false;
|
|
9080
9442
|
}
|
|
9081
9443
|
if (node.computed) {
|
|
9082
|
-
return node.property.type ===
|
|
9444
|
+
return node.property.type === import_utils60.AST_NODE_TYPES.Literal && isPureReceiver(node.object);
|
|
9083
9445
|
}
|
|
9084
9446
|
return isPureReceiver(node.object);
|
|
9085
9447
|
default:
|
|
@@ -9087,7 +9449,7 @@ function isPureReceiver(node) {
|
|
|
9087
9449
|
}
|
|
9088
9450
|
}
|
|
9089
9451
|
function literalIndex(node) {
|
|
9090
|
-
if (node.type !==
|
|
9452
|
+
if (node.type !== import_utils60.AST_NODE_TYPES.Literal || typeof node.value !== "number") {
|
|
9091
9453
|
return null;
|
|
9092
9454
|
}
|
|
9093
9455
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
@@ -9113,24 +9475,24 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
9113
9475
|
}
|
|
9114
9476
|
const { sourceCode } = context;
|
|
9115
9477
|
function parseAssertion(statement) {
|
|
9116
|
-
if (statement.type !==
|
|
9478
|
+
if (statement.type !== import_utils60.AST_NODE_TYPES.ExpressionStatement) {
|
|
9117
9479
|
return null;
|
|
9118
9480
|
}
|
|
9119
9481
|
const call = statement.expression;
|
|
9120
|
-
if (call.type !==
|
|
9482
|
+
if (call.type !== import_utils60.AST_NODE_TYPES.CallExpression) {
|
|
9121
9483
|
return null;
|
|
9122
9484
|
}
|
|
9123
9485
|
const callee = call.callee;
|
|
9124
|
-
if (callee.type !==
|
|
9486
|
+
if (callee.type !== import_utils60.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils60.AST_NODE_TYPES.Identifier) {
|
|
9125
9487
|
return null;
|
|
9126
9488
|
}
|
|
9127
9489
|
const matcher = callee.property.name;
|
|
9128
9490
|
const expectCall = callee.object;
|
|
9129
|
-
if (expectCall.type !==
|
|
9491
|
+
if (expectCall.type !== import_utils60.AST_NODE_TYPES.CallExpression || expectCall.callee.type !== import_utils60.AST_NODE_TYPES.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
9130
9492
|
return null;
|
|
9131
9493
|
}
|
|
9132
9494
|
const actual = expectCall.arguments[0];
|
|
9133
|
-
if (actual === void 0 || actual.type !==
|
|
9495
|
+
if (actual === void 0 || actual.type !== import_utils60.AST_NODE_TYPES.MemberExpression || actual.optional) {
|
|
9134
9496
|
return null;
|
|
9135
9497
|
}
|
|
9136
9498
|
if (!isPureReceiver(actual.object)) {
|
|
@@ -9144,7 +9506,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
9144
9506
|
}
|
|
9145
9507
|
key = { kind: "index", index };
|
|
9146
9508
|
} else {
|
|
9147
|
-
if (actual.property.type !==
|
|
9509
|
+
if (actual.property.type !== import_utils60.AST_NODE_TYPES.Identifier || COLLECTION_PROPERTIES.has(actual.property.name) || LITERAL_KEY_HAZARDS.has(actual.property.name)) {
|
|
9148
9510
|
return null;
|
|
9149
9511
|
}
|
|
9150
9512
|
key = { kind: "property", name: actual.property.name };
|
|
@@ -9156,7 +9518,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
9156
9518
|
return null;
|
|
9157
9519
|
}
|
|
9158
9520
|
const expected = call.arguments[0];
|
|
9159
|
-
if (call.arguments.length !== 1 || expected === void 0 || expected.type ===
|
|
9521
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === import_utils60.AST_NODE_TYPES.SpreadElement) {
|
|
9160
9522
|
return null;
|
|
9161
9523
|
}
|
|
9162
9524
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
@@ -9271,7 +9633,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
9271
9633
|
});
|
|
9272
9634
|
|
|
9273
9635
|
// src/rules/prefer-zod-enum.ts
|
|
9274
|
-
var
|
|
9636
|
+
var import_utils61 = require("@typescript-eslint/utils");
|
|
9275
9637
|
var prefer_zod_enum_default = createRule({
|
|
9276
9638
|
name: "prefer-zod-enum",
|
|
9277
9639
|
meta: {
|
|
@@ -9291,25 +9653,25 @@ var prefer_zod_enum_default = createRule({
|
|
|
9291
9653
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
9292
9654
|
function enumValues(node) {
|
|
9293
9655
|
const callee = node.callee;
|
|
9294
|
-
if (callee.type !==
|
|
9656
|
+
if (callee.type !== import_utils61.AST_NODE_TYPES.MemberExpression || callee.computed || callee.object.type !== import_utils61.AST_NODE_TYPES.Identifier || !zodNamespaces.has(callee.object.name) || callee.property.type !== import_utils61.AST_NODE_TYPES.Identifier || callee.property.name !== "union" || node.arguments.length !== 1) {
|
|
9295
9657
|
return null;
|
|
9296
9658
|
}
|
|
9297
9659
|
const argument = node.arguments[0];
|
|
9298
|
-
if (argument === void 0 || argument.type !==
|
|
9660
|
+
if (argument === void 0 || argument.type !== import_utils61.AST_NODE_TYPES.ArrayExpression || argument.elements.length === 0) {
|
|
9299
9661
|
return null;
|
|
9300
9662
|
}
|
|
9301
9663
|
const values = [];
|
|
9302
9664
|
let canFix = true;
|
|
9303
9665
|
for (const element of argument.elements) {
|
|
9304
|
-
if (element?.type ===
|
|
9666
|
+
if (element?.type === import_utils61.AST_NODE_TYPES.SpreadElement) {
|
|
9305
9667
|
canFix = false;
|
|
9306
9668
|
continue;
|
|
9307
9669
|
}
|
|
9308
|
-
if (element === null || element.type !==
|
|
9670
|
+
if (element === null || element.type !== import_utils61.AST_NODE_TYPES.CallExpression || element.callee.type !== import_utils61.AST_NODE_TYPES.MemberExpression || element.callee.computed || element.callee.object.type !== import_utils61.AST_NODE_TYPES.Identifier || !zodNamespaces.has(element.callee.object.name) || element.callee.property.type !== import_utils61.AST_NODE_TYPES.Identifier || element.callee.property.name !== "literal") {
|
|
9309
9671
|
return null;
|
|
9310
9672
|
}
|
|
9311
9673
|
const value = element.arguments[0];
|
|
9312
|
-
if (element.arguments.length !== 1 || value === void 0 || value.type !==
|
|
9674
|
+
if (element.arguments.length !== 1 || value === void 0 || value.type !== import_utils61.AST_NODE_TYPES.Literal || typeof value.value !== "string") {
|
|
9313
9675
|
canFix = false;
|
|
9314
9676
|
continue;
|
|
9315
9677
|
}
|
|
@@ -9319,11 +9681,11 @@ var prefer_zod_enum_default = createRule({
|
|
|
9319
9681
|
}
|
|
9320
9682
|
function buildFix(node, values) {
|
|
9321
9683
|
const argument = node.arguments[0];
|
|
9322
|
-
if (argument === void 0 || argument.type !==
|
|
9684
|
+
if (argument === void 0 || argument.type !== import_utils61.AST_NODE_TYPES.ArrayExpression || sourceCode.getCommentsInside(argument).length > 0) {
|
|
9323
9685
|
return void 0;
|
|
9324
9686
|
}
|
|
9325
9687
|
const callee = node.callee;
|
|
9326
|
-
if (callee.type !==
|
|
9688
|
+
if (callee.type !== import_utils61.AST_NODE_TYPES.MemberExpression || callee.property.type !== import_utils61.AST_NODE_TYPES.Identifier) {
|
|
9327
9689
|
return void 0;
|
|
9328
9690
|
}
|
|
9329
9691
|
return (fixer) => [
|
|
@@ -9340,7 +9702,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
9340
9702
|
return;
|
|
9341
9703
|
}
|
|
9342
9704
|
for (const specifier of node.specifiers) {
|
|
9343
|
-
if (specifier.type ===
|
|
9705
|
+
if (specifier.type === import_utils61.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils61.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils61.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils61.AST_NODE_TYPES.Identifier && specifier.imported.name === "z") {
|
|
9344
9706
|
zodNamespaces.add(specifier.local.name);
|
|
9345
9707
|
}
|
|
9346
9708
|
}
|
|
@@ -9362,7 +9724,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
9362
9724
|
});
|
|
9363
9725
|
|
|
9364
9726
|
// src/rules/prefer-zod-infer.ts
|
|
9365
|
-
var
|
|
9727
|
+
var import_utils62 = require("@typescript-eslint/utils");
|
|
9366
9728
|
var SHAPE_PRESERVING_METHODS = /* @__PURE__ */ new Set([
|
|
9367
9729
|
"describe",
|
|
9368
9730
|
"refine",
|
|
@@ -9399,44 +9761,44 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
9399
9761
|
"Schema"
|
|
9400
9762
|
]);
|
|
9401
9763
|
var LEAF_NODE_TYPES = {
|
|
9402
|
-
string: [
|
|
9403
|
-
email: [
|
|
9404
|
-
url: [
|
|
9405
|
-
uuid: [
|
|
9406
|
-
ulid: [
|
|
9407
|
-
cuid: [
|
|
9408
|
-
cuid2: [
|
|
9409
|
-
nanoid: [
|
|
9410
|
-
iso: [
|
|
9411
|
-
number: [
|
|
9412
|
-
int: [
|
|
9413
|
-
float32: [
|
|
9414
|
-
float64: [
|
|
9415
|
-
boolean: [
|
|
9416
|
-
bigint: [
|
|
9417
|
-
symbol: [
|
|
9418
|
-
any: [
|
|
9419
|
-
unknown: [
|
|
9420
|
-
never: [
|
|
9421
|
-
void: [
|
|
9422
|
-
null: [
|
|
9423
|
-
undefined: [
|
|
9424
|
-
literal: [
|
|
9425
|
-
date: [
|
|
9426
|
-
array: [
|
|
9427
|
-
tuple: [
|
|
9428
|
-
object: [
|
|
9429
|
-
strictObject: [
|
|
9430
|
-
looseObject: [
|
|
9431
|
-
record: [
|
|
9432
|
-
map: [
|
|
9433
|
-
set: [
|
|
9434
|
-
promise: [
|
|
9435
|
-
enum: [
|
|
9436
|
-
nativeEnum: [
|
|
9437
|
-
union: [
|
|
9438
|
-
discriminatedUnion: [
|
|
9439
|
-
intersection: [
|
|
9764
|
+
string: [import_utils62.AST_NODE_TYPES.TSStringKeyword],
|
|
9765
|
+
email: [import_utils62.AST_NODE_TYPES.TSStringKeyword],
|
|
9766
|
+
url: [import_utils62.AST_NODE_TYPES.TSStringKeyword],
|
|
9767
|
+
uuid: [import_utils62.AST_NODE_TYPES.TSStringKeyword],
|
|
9768
|
+
ulid: [import_utils62.AST_NODE_TYPES.TSStringKeyword],
|
|
9769
|
+
cuid: [import_utils62.AST_NODE_TYPES.TSStringKeyword],
|
|
9770
|
+
cuid2: [import_utils62.AST_NODE_TYPES.TSStringKeyword],
|
|
9771
|
+
nanoid: [import_utils62.AST_NODE_TYPES.TSStringKeyword],
|
|
9772
|
+
iso: [import_utils62.AST_NODE_TYPES.TSStringKeyword],
|
|
9773
|
+
number: [import_utils62.AST_NODE_TYPES.TSNumberKeyword],
|
|
9774
|
+
int: [import_utils62.AST_NODE_TYPES.TSNumberKeyword],
|
|
9775
|
+
float32: [import_utils62.AST_NODE_TYPES.TSNumberKeyword],
|
|
9776
|
+
float64: [import_utils62.AST_NODE_TYPES.TSNumberKeyword],
|
|
9777
|
+
boolean: [import_utils62.AST_NODE_TYPES.TSBooleanKeyword],
|
|
9778
|
+
bigint: [import_utils62.AST_NODE_TYPES.TSBigIntKeyword],
|
|
9779
|
+
symbol: [import_utils62.AST_NODE_TYPES.TSSymbolKeyword],
|
|
9780
|
+
any: [import_utils62.AST_NODE_TYPES.TSAnyKeyword],
|
|
9781
|
+
unknown: [import_utils62.AST_NODE_TYPES.TSUnknownKeyword],
|
|
9782
|
+
never: [import_utils62.AST_NODE_TYPES.TSNeverKeyword],
|
|
9783
|
+
void: [import_utils62.AST_NODE_TYPES.TSVoidKeyword],
|
|
9784
|
+
null: [import_utils62.AST_NODE_TYPES.TSNullKeyword],
|
|
9785
|
+
undefined: [import_utils62.AST_NODE_TYPES.TSUndefinedKeyword],
|
|
9786
|
+
literal: [import_utils62.AST_NODE_TYPES.TSLiteralType],
|
|
9787
|
+
date: [import_utils62.AST_NODE_TYPES.TSTypeReference],
|
|
9788
|
+
array: [import_utils62.AST_NODE_TYPES.TSArrayType, import_utils62.AST_NODE_TYPES.TSTypeReference],
|
|
9789
|
+
tuple: [import_utils62.AST_NODE_TYPES.TSTupleType],
|
|
9790
|
+
object: [import_utils62.AST_NODE_TYPES.TSTypeLiteral, import_utils62.AST_NODE_TYPES.TSTypeReference],
|
|
9791
|
+
strictObject: [import_utils62.AST_NODE_TYPES.TSTypeLiteral, import_utils62.AST_NODE_TYPES.TSTypeReference],
|
|
9792
|
+
looseObject: [import_utils62.AST_NODE_TYPES.TSTypeLiteral, import_utils62.AST_NODE_TYPES.TSTypeReference],
|
|
9793
|
+
record: [import_utils62.AST_NODE_TYPES.TSTypeReference, import_utils62.AST_NODE_TYPES.TSTypeLiteral],
|
|
9794
|
+
map: [import_utils62.AST_NODE_TYPES.TSTypeReference],
|
|
9795
|
+
set: [import_utils62.AST_NODE_TYPES.TSTypeReference],
|
|
9796
|
+
promise: [import_utils62.AST_NODE_TYPES.TSTypeReference],
|
|
9797
|
+
enum: [import_utils62.AST_NODE_TYPES.TSUnionType, import_utils62.AST_NODE_TYPES.TSTypeReference, import_utils62.AST_NODE_TYPES.TSLiteralType],
|
|
9798
|
+
nativeEnum: [import_utils62.AST_NODE_TYPES.TSUnionType, import_utils62.AST_NODE_TYPES.TSTypeReference, import_utils62.AST_NODE_TYPES.TSLiteralType],
|
|
9799
|
+
union: [import_utils62.AST_NODE_TYPES.TSUnionType, import_utils62.AST_NODE_TYPES.TSTypeReference],
|
|
9800
|
+
discriminatedUnion: [import_utils62.AST_NODE_TYPES.TSUnionType, import_utils62.AST_NODE_TYPES.TSTypeReference],
|
|
9801
|
+
intersection: [import_utils62.AST_NODE_TYPES.TSIntersectionType, import_utils62.AST_NODE_TYPES.TSTypeReference]
|
|
9440
9802
|
};
|
|
9441
9803
|
function normalizeSchemaName(name) {
|
|
9442
9804
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -9445,20 +9807,20 @@ function normalizeTypeName(name) {
|
|
|
9445
9807
|
return name.replace(/Type$/, "").toLowerCase();
|
|
9446
9808
|
}
|
|
9447
9809
|
function unwrapNullish(annotation) {
|
|
9448
|
-
if (annotation.type !==
|
|
9810
|
+
if (annotation.type !== import_utils62.AST_NODE_TYPES.TSUnionType) {
|
|
9449
9811
|
return {
|
|
9450
9812
|
core: annotation,
|
|
9451
|
-
nullable: annotation.type ===
|
|
9813
|
+
nullable: annotation.type === import_utils62.AST_NODE_TYPES.TSNullKeyword
|
|
9452
9814
|
};
|
|
9453
9815
|
}
|
|
9454
9816
|
const rest = [];
|
|
9455
9817
|
let nullable = false;
|
|
9456
9818
|
for (const member of annotation.types) {
|
|
9457
|
-
if (member.type ===
|
|
9819
|
+
if (member.type === import_utils62.AST_NODE_TYPES.TSNullKeyword) {
|
|
9458
9820
|
nullable = true;
|
|
9459
9821
|
continue;
|
|
9460
9822
|
}
|
|
9461
|
-
if (member.type ===
|
|
9823
|
+
if (member.type === import_utils62.AST_NODE_TYPES.TSUndefinedKeyword) {
|
|
9462
9824
|
continue;
|
|
9463
9825
|
}
|
|
9464
9826
|
rest.push(member);
|
|
@@ -9523,35 +9885,35 @@ var prefer_zod_infer_default = createRule({
|
|
|
9523
9885
|
function zodCallChain(node) {
|
|
9524
9886
|
const chain = [];
|
|
9525
9887
|
let current = node;
|
|
9526
|
-
while (current.type ===
|
|
9888
|
+
while (current.type === import_utils62.AST_NODE_TYPES.CallExpression) {
|
|
9527
9889
|
const callee = current.callee;
|
|
9528
|
-
if (callee.type !==
|
|
9890
|
+
if (callee.type !== import_utils62.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils62.AST_NODE_TYPES.Identifier) {
|
|
9529
9891
|
return null;
|
|
9530
9892
|
}
|
|
9531
9893
|
chain.push(current);
|
|
9532
9894
|
const receiver = callee.object;
|
|
9533
|
-
if (receiver.type ===
|
|
9895
|
+
if (receiver.type === import_utils62.AST_NODE_TYPES.Identifier) {
|
|
9534
9896
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
9535
9897
|
}
|
|
9536
9898
|
current = receiver;
|
|
9537
9899
|
}
|
|
9538
9900
|
return null;
|
|
9539
9901
|
}
|
|
9540
|
-
function
|
|
9902
|
+
function methodName2(call) {
|
|
9541
9903
|
const callee = call.callee;
|
|
9542
|
-
return callee.type ===
|
|
9904
|
+
return callee.type === import_utils62.AST_NODE_TYPES.MemberExpression && callee.property.type === import_utils62.AST_NODE_TYPES.Identifier ? callee.property.name : "";
|
|
9543
9905
|
}
|
|
9544
9906
|
function schemaField(node) {
|
|
9545
9907
|
const modifiers = [];
|
|
9546
9908
|
let current = node;
|
|
9547
9909
|
let leaf = null;
|
|
9548
|
-
while (current.type ===
|
|
9910
|
+
while (current.type === import_utils62.AST_NODE_TYPES.CallExpression) {
|
|
9549
9911
|
const callee = current.callee;
|
|
9550
|
-
if (callee.type !==
|
|
9912
|
+
if (callee.type !== import_utils62.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils62.AST_NODE_TYPES.Identifier) {
|
|
9551
9913
|
break;
|
|
9552
9914
|
}
|
|
9553
9915
|
const receiver = callee.object;
|
|
9554
|
-
if (receiver.type ===
|
|
9916
|
+
if (receiver.type === import_utils62.AST_NODE_TYPES.Identifier && zodNamespaces.has(receiver.name)) {
|
|
9555
9917
|
leaf = callee.property.name;
|
|
9556
9918
|
break;
|
|
9557
9919
|
}
|
|
@@ -9574,24 +9936,24 @@ var prefer_zod_infer_default = createRule({
|
|
|
9574
9936
|
if (base === void 0) {
|
|
9575
9937
|
return null;
|
|
9576
9938
|
}
|
|
9577
|
-
const baseMethod =
|
|
9939
|
+
const baseMethod = methodName2(base);
|
|
9578
9940
|
if (baseMethod !== "object" && baseMethod !== "strictObject") {
|
|
9579
9941
|
return null;
|
|
9580
9942
|
}
|
|
9581
|
-
if (rest.some((call) => !SHAPE_PRESERVING_METHODS.has(
|
|
9943
|
+
if (rest.some((call) => !SHAPE_PRESERVING_METHODS.has(methodName2(call)))) {
|
|
9582
9944
|
return null;
|
|
9583
9945
|
}
|
|
9584
9946
|
const shape = base.arguments[0];
|
|
9585
|
-
if (shape === void 0 || shape.type !==
|
|
9947
|
+
if (shape === void 0 || shape.type !== import_utils62.AST_NODE_TYPES.ObjectExpression) {
|
|
9586
9948
|
return null;
|
|
9587
9949
|
}
|
|
9588
9950
|
const fields = /* @__PURE__ */ new Map();
|
|
9589
9951
|
for (const property of shape.properties) {
|
|
9590
|
-
if (property.type !==
|
|
9952
|
+
if (property.type !== import_utils62.AST_NODE_TYPES.Property || property.computed) {
|
|
9591
9953
|
return null;
|
|
9592
9954
|
}
|
|
9593
9955
|
const { key } = property;
|
|
9594
|
-
const name = key.type ===
|
|
9956
|
+
const name = key.type === import_utils62.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils62.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
9595
9957
|
if (name === null) {
|
|
9596
9958
|
return null;
|
|
9597
9959
|
}
|
|
@@ -9602,11 +9964,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
9602
9964
|
function typeMembers(members) {
|
|
9603
9965
|
const result = /* @__PURE__ */ new Map();
|
|
9604
9966
|
for (const member of members) {
|
|
9605
|
-
if (member.type !==
|
|
9967
|
+
if (member.type !== import_utils62.AST_NODE_TYPES.TSPropertySignature || member.computed) {
|
|
9606
9968
|
return null;
|
|
9607
9969
|
}
|
|
9608
9970
|
const { key } = member;
|
|
9609
|
-
const name = key.type ===
|
|
9971
|
+
const name = key.type === import_utils62.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils62.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
9610
9972
|
if (name === null) {
|
|
9611
9973
|
return null;
|
|
9612
9974
|
}
|
|
@@ -9620,8 +9982,8 @@ var prefer_zod_infer_default = createRule({
|
|
|
9620
9982
|
return result.size === 0 ? null : result;
|
|
9621
9983
|
}
|
|
9622
9984
|
function collectConstrainedNames(node) {
|
|
9623
|
-
if (node.type ===
|
|
9624
|
-
if (node.typeName.type ===
|
|
9985
|
+
if (node.type === import_utils62.AST_NODE_TYPES.TSTypeReference) {
|
|
9986
|
+
if (node.typeName.type === import_utils62.AST_NODE_TYPES.Identifier) {
|
|
9625
9987
|
constrainedTypeNames.add(node.typeName.name);
|
|
9626
9988
|
}
|
|
9627
9989
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -9629,11 +9991,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
9629
9991
|
}
|
|
9630
9992
|
return;
|
|
9631
9993
|
}
|
|
9632
|
-
if (node.type ===
|
|
9994
|
+
if (node.type === import_utils62.AST_NODE_TYPES.TSArrayType) {
|
|
9633
9995
|
collectConstrainedNames(node.elementType);
|
|
9634
9996
|
return;
|
|
9635
9997
|
}
|
|
9636
|
-
if (node.type ===
|
|
9998
|
+
if (node.type === import_utils62.AST_NODE_TYPES.TSUnionType || node.type === import_utils62.AST_NODE_TYPES.TSIntersectionType) {
|
|
9637
9999
|
for (const member of node.types) {
|
|
9638
10000
|
collectConstrainedNames(member);
|
|
9639
10001
|
}
|
|
@@ -9677,13 +10039,13 @@ var prefer_zod_infer_default = createRule({
|
|
|
9677
10039
|
return;
|
|
9678
10040
|
}
|
|
9679
10041
|
for (const specifier of node.specifiers) {
|
|
9680
|
-
if (specifier.type ===
|
|
10042
|
+
if (specifier.type === import_utils62.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils62.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils62.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils62.AST_NODE_TYPES.Identifier && specifier.imported.name === "z") {
|
|
9681
10043
|
zodNamespaces.add(specifier.local.name);
|
|
9682
10044
|
}
|
|
9683
10045
|
}
|
|
9684
10046
|
},
|
|
9685
10047
|
VariableDeclarator(node) {
|
|
9686
|
-
if (node.id.type !==
|
|
10048
|
+
if (node.id.type !== import_utils62.AST_NODE_TYPES.Identifier || node.init == null) {
|
|
9687
10049
|
return;
|
|
9688
10050
|
}
|
|
9689
10051
|
const fields = schemaFields(node.init);
|
|
@@ -9693,14 +10055,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
9693
10055
|
},
|
|
9694
10056
|
/** Records `XSchema.transform(...)` and equivalent module-level reshaping. */
|
|
9695
10057
|
"MemberExpression[computed=false]"(node) {
|
|
9696
|
-
if (node.object.type ===
|
|
10058
|
+
if (node.object.type === import_utils62.AST_NODE_TYPES.Identifier && node.property.type === import_utils62.AST_NODE_TYPES.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
9697
10059
|
reshapedSchemaNames.add(node.object.name);
|
|
9698
10060
|
}
|
|
9699
10061
|
},
|
|
9700
10062
|
/** Records every type argument carried by a Zod constraint. */
|
|
9701
10063
|
TSTypeReference(node) {
|
|
9702
10064
|
const { typeName } = node;
|
|
9703
|
-
const referenced = typeName.type ===
|
|
10065
|
+
const referenced = typeName.type === import_utils62.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils62.AST_NODE_TYPES.TSQualifiedName && typeName.right.type === import_utils62.AST_NODE_TYPES.Identifier ? typeName.right.name : null;
|
|
9704
10066
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
9705
10067
|
return;
|
|
9706
10068
|
}
|
|
@@ -9718,7 +10080,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
9718
10080
|
}
|
|
9719
10081
|
},
|
|
9720
10082
|
TSTypeAliasDeclaration(node) {
|
|
9721
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
10083
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== import_utils62.AST_NODE_TYPES.TSTypeLiteral) {
|
|
9722
10084
|
return;
|
|
9723
10085
|
}
|
|
9724
10086
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -9763,10 +10125,10 @@ var prefer_zod_infer_default = createRule({
|
|
|
9763
10125
|
});
|
|
9764
10126
|
|
|
9765
10127
|
// src/rules/require-assert-never.ts
|
|
9766
|
-
var
|
|
10128
|
+
var import_utils63 = require("@typescript-eslint/utils");
|
|
9767
10129
|
var isRuntimeHandlingStatement = (statement) => {
|
|
9768
|
-
if (statement.type ===
|
|
9769
|
-
if (statement.type ===
|
|
10130
|
+
if (statement.type === import_utils63.AST_NODE_TYPES.EmptyStatement) return false;
|
|
10131
|
+
if (statement.type === import_utils63.AST_NODE_TYPES.BlockStatement) {
|
|
9770
10132
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
9771
10133
|
}
|
|
9772
10134
|
return true;
|
|
@@ -9782,7 +10144,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
9782
10144
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
9783
10145
|
}
|
|
9784
10146
|
const only = defaultCase.consequent[0];
|
|
9785
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
10147
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === import_utils63.AST_NODE_TYPES.BlockStatement && only.body.length === 0) {
|
|
9786
10148
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
9787
10149
|
}
|
|
9788
10150
|
return false;
|
|
@@ -9822,7 +10184,7 @@ var require_assert_never_default = createRule({
|
|
|
9822
10184
|
});
|
|
9823
10185
|
|
|
9824
10186
|
// src/rules/require-fetch-timeout.ts
|
|
9825
|
-
var
|
|
10187
|
+
var import_utils64 = require("@typescript-eslint/utils");
|
|
9826
10188
|
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set([
|
|
9827
10189
|
"globalThis",
|
|
9828
10190
|
"window",
|
|
@@ -9838,14 +10200,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
9838
10200
|
return false;
|
|
9839
10201
|
}
|
|
9840
10202
|
function initProvablyLacksSignal(init) {
|
|
9841
|
-
if (init.type !==
|
|
10203
|
+
if (init.type !== import_utils64.AST_NODE_TYPES.ObjectExpression) {
|
|
9842
10204
|
return false;
|
|
9843
10205
|
}
|
|
9844
10206
|
for (const prop of init.properties) {
|
|
9845
|
-
if (prop.type ===
|
|
10207
|
+
if (prop.type === import_utils64.AST_NODE_TYPES.SpreadElement) {
|
|
9846
10208
|
return false;
|
|
9847
10209
|
}
|
|
9848
|
-
if (prop.key.type ===
|
|
10210
|
+
if (prop.key.type === import_utils64.AST_NODE_TYPES.Identifier && prop.key.name === "signal" || prop.key.type === import_utils64.AST_NODE_TYPES.Literal && prop.key.value === "signal") {
|
|
9849
10211
|
return false;
|
|
9850
10212
|
}
|
|
9851
10213
|
if (prop.computed) {
|
|
@@ -9855,7 +10217,7 @@ function initProvablyLacksSignal(init) {
|
|
|
9855
10217
|
return true;
|
|
9856
10218
|
}
|
|
9857
10219
|
function isStringish(node) {
|
|
9858
|
-
return node.type ===
|
|
10220
|
+
return node.type === import_utils64.AST_NODE_TYPES.Literal && typeof node.value === "string" || node.type === import_utils64.AST_NODE_TYPES.TemplateLiteral;
|
|
9859
10221
|
}
|
|
9860
10222
|
var require_fetch_timeout_default = createRule({
|
|
9861
10223
|
name: "require-fetch-timeout",
|
|
@@ -9892,14 +10254,14 @@ var require_fetch_timeout_default = createRule({
|
|
|
9892
10254
|
}
|
|
9893
10255
|
function resolvesToGlobal(identifier) {
|
|
9894
10256
|
const scope = context.sourceCode.getScope(identifier);
|
|
9895
|
-
const variable =
|
|
10257
|
+
const variable = import_utils64.ASTUtils.findVariable(scope, identifier.name);
|
|
9896
10258
|
return variable === null || variable.defs.length === 0;
|
|
9897
10259
|
}
|
|
9898
10260
|
function isGlobalFetchCall2(callee) {
|
|
9899
|
-
if (callee.type ===
|
|
10261
|
+
if (callee.type === import_utils64.AST_NODE_TYPES.Identifier) {
|
|
9900
10262
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
9901
10263
|
}
|
|
9902
|
-
return callee.type ===
|
|
10264
|
+
return callee.type === import_utils64.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils64.AST_NODE_TYPES.Identifier && callee.property.name === "fetch" && callee.object.type === import_utils64.AST_NODE_TYPES.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
9903
10265
|
}
|
|
9904
10266
|
return {
|
|
9905
10267
|
CallExpression(node) {
|
|
@@ -9919,28 +10281,51 @@ var require_fetch_timeout_default = createRule({
|
|
|
9919
10281
|
});
|
|
9920
10282
|
|
|
9921
10283
|
// src/rules/require-interface-for-injected-service.ts
|
|
9922
|
-
var
|
|
10284
|
+
var import_utils65 = require("@typescript-eslint/utils");
|
|
9923
10285
|
var CONFIGISH_TYPE_RE = /(?:Options|Opts|Config|Configuration|Settings|Params|Props|Args|Env|Environment|Callbacks|Flags)$/;
|
|
9924
10286
|
var CONFIGISH_NAME_RE = /^(?:options|opts|config|configuration|settings|params|props|args|env|environment|callbacks|flags|logger|log|clock)$/i;
|
|
9925
10287
|
var HTTP_TRANSPORT_TYPE_RE = /^(?:KyInstance|AxiosInstance|Session)$/;
|
|
9926
10288
|
var BUILTIN_CONTAINER_TYPE_RE = /^(?:Record|Map|WeakMap|Set|WeakSet|Array|ReadonlyArray|ReadonlyMap|ReadonlySet|Promise|Partial|Required|Readonly|Pick|Omit|Exclude|Extract|NonNullable|Awaited|Parameters|ReturnType|InstanceType)$/;
|
|
10289
|
+
var VALUE_TYPE_RE = /^(?:ArrayBuffer|Blob|Buffer|Date|RegExp|URL|URLSearchParams)$/;
|
|
9927
10290
|
var TRANSPORT_WRAPPER_NAME_RE = /Client$/;
|
|
9928
10291
|
var ROUTER_FACTORY_NAME = "Router";
|
|
9929
10292
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
9930
|
-
var
|
|
9931
|
-
var
|
|
10293
|
+
var STORAGE_ASSIGNMENT_OPERATORS = /* @__PURE__ */ new Set(["=", "&&=", "??=", "||="]);
|
|
10294
|
+
var detachedValueExports = (program) => {
|
|
10295
|
+
const names = /* @__PURE__ */ new Set();
|
|
10296
|
+
for (const statement of program.body) {
|
|
10297
|
+
if (statement.type === import_utils65.AST_NODE_TYPES.ExportNamedDeclaration && statement.declaration === null && statement.source === null && statement.exportKind !== "type") {
|
|
10298
|
+
for (const specifier of statement.specifiers) {
|
|
10299
|
+
if (specifier.exportKind !== "type") names.add(specifier.local.name);
|
|
10300
|
+
}
|
|
10301
|
+
} else if (statement.type === import_utils65.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils65.AST_NODE_TYPES.Identifier) {
|
|
10302
|
+
names.add(statement.declaration.name);
|
|
10303
|
+
} else if (statement.type === import_utils65.AST_NODE_TYPES.TSExportAssignment && statement.expression.type === import_utils65.AST_NODE_TYPES.Identifier) {
|
|
10304
|
+
names.add(statement.expression.name);
|
|
10305
|
+
}
|
|
10306
|
+
}
|
|
10307
|
+
return names;
|
|
10308
|
+
};
|
|
10309
|
+
var isExportedClass2 = (node, detached) => node.parent.type === import_utils65.AST_NODE_TYPES.ExportNamedDeclaration || node.parent.type === import_utils65.AST_NODE_TYPES.ExportDefaultDeclaration || node.id !== null && detached.has(node.id.name);
|
|
10310
|
+
var qualifiedName = (name) => name.type === import_utils65.AST_NODE_TYPES.Identifier ? name.name : name.type === import_utils65.AST_NODE_TYPES.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
9932
10311
|
var readTypeReference = (annotation) => {
|
|
9933
|
-
if (annotation ===
|
|
10312
|
+
if (annotation?.type === import_utils65.AST_NODE_TYPES.TSUnionType) {
|
|
10313
|
+
const members = annotation.types.filter(
|
|
10314
|
+
(member) => member.type !== import_utils65.AST_NODE_TYPES.TSUndefinedKeyword && member.type !== import_utils65.AST_NODE_TYPES.TSNullKeyword
|
|
10315
|
+
);
|
|
10316
|
+
annotation = members.length === 1 ? members[0] : void 0;
|
|
10317
|
+
}
|
|
10318
|
+
if (annotation === void 0 || annotation.type !== import_utils65.AST_NODE_TYPES.TSTypeReference) return null;
|
|
9934
10319
|
const { typeName } = annotation;
|
|
9935
|
-
const rightmost = typeName.type ===
|
|
10320
|
+
const rightmost = typeName.type === import_utils65.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils65.AST_NODE_TYPES.TSQualifiedName ? typeName.right.name : null;
|
|
9936
10321
|
if (rightmost === null) return null;
|
|
9937
10322
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
9938
10323
|
};
|
|
9939
10324
|
var namedParameterCollaborator = (annotated) => {
|
|
9940
10325
|
let target = annotated;
|
|
9941
|
-
if (target.type ===
|
|
9942
|
-
if (target.type ===
|
|
9943
|
-
if (target.type !==
|
|
10326
|
+
if (target.type === import_utils65.AST_NODE_TYPES.TSParameterProperty) target = target.parameter;
|
|
10327
|
+
if (target.type === import_utils65.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
10328
|
+
if (target.type !== import_utils65.AST_NODE_TYPES.Identifier) return null;
|
|
9944
10329
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
9945
10330
|
if (reference === null) return null;
|
|
9946
10331
|
return { name: target.name, ...reference };
|
|
@@ -9948,8 +10333,8 @@ var namedParameterCollaborator = (annotated) => {
|
|
|
9948
10333
|
var propertySignatureTypes = (members) => {
|
|
9949
10334
|
const types = /* @__PURE__ */ new Map();
|
|
9950
10335
|
for (const member of members) {
|
|
9951
|
-
if (member.type !==
|
|
9952
|
-
if (member.computed || member.key.type !==
|
|
10336
|
+
if (member.type !== import_utils65.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
10337
|
+
if (member.computed || member.key.type !== import_utils65.AST_NODE_TYPES.Identifier) continue;
|
|
9953
10338
|
const reference = readTypeReference(member.typeAnnotation?.typeAnnotation);
|
|
9954
10339
|
if (reference === null) continue;
|
|
9955
10340
|
types.set(member.key.name, reference);
|
|
@@ -9960,18 +10345,18 @@ var fileTypeIndex = (program) => {
|
|
|
9960
10345
|
const objects = /* @__PURE__ */ new Map();
|
|
9961
10346
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
9962
10347
|
for (const statement of program.body) {
|
|
9963
|
-
const declaration = statement.type ===
|
|
9964
|
-
if (declaration?.type ===
|
|
10348
|
+
const declaration = statement.type === import_utils65.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
10349
|
+
if (declaration?.type === import_utils65.AST_NODE_TYPES.TSInterfaceDeclaration) {
|
|
9965
10350
|
objects.set(declaration.id.name, propertySignatureTypes(declaration.body.body));
|
|
9966
10351
|
continue;
|
|
9967
10352
|
}
|
|
9968
|
-
if (declaration?.type !==
|
|
10353
|
+
if (declaration?.type !== import_utils65.AST_NODE_TYPES.TSTypeAliasDeclaration) continue;
|
|
9969
10354
|
const aliased = declaration.typeAnnotation;
|
|
9970
|
-
if (aliased.type ===
|
|
10355
|
+
if (aliased.type === import_utils65.AST_NODE_TYPES.TSFunctionType || aliased.type === import_utils65.AST_NODE_TYPES.TSConstructorType) {
|
|
9971
10356
|
functionAliases.add(declaration.id.name);
|
|
9972
10357
|
continue;
|
|
9973
10358
|
}
|
|
9974
|
-
const literals = aliased.type ===
|
|
10359
|
+
const literals = aliased.type === import_utils65.AST_NODE_TYPES.TSTypeLiteral ? [aliased] : aliased.type === import_utils65.AST_NODE_TYPES.TSIntersectionType ? aliased.types.filter((part) => part.type === import_utils65.AST_NODE_TYPES.TSTypeLiteral) : [];
|
|
9975
10360
|
if (literals.length === 0) continue;
|
|
9976
10361
|
const merged = /* @__PURE__ */ new Map();
|
|
9977
10362
|
for (const literal of literals) {
|
|
@@ -9984,10 +10369,10 @@ var fileTypeIndex = (program) => {
|
|
|
9984
10369
|
return { objects, functionAliases };
|
|
9985
10370
|
};
|
|
9986
10371
|
var bagMemberTypes = (annotation, declared) => {
|
|
9987
|
-
if (annotation.type ===
|
|
10372
|
+
if (annotation.type === import_utils65.AST_NODE_TYPES.TSTypeLiteral) {
|
|
9988
10373
|
return propertySignatureTypes(annotation.members);
|
|
9989
10374
|
}
|
|
9990
|
-
if (annotation.type !==
|
|
10375
|
+
if (annotation.type !== import_utils65.AST_NODE_TYPES.TSTypeReference || annotation.typeName.type !== import_utils65.AST_NODE_TYPES.Identifier) {
|
|
9991
10376
|
return null;
|
|
9992
10377
|
}
|
|
9993
10378
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
@@ -9999,11 +10384,11 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
9999
10384
|
if (members === null) return [];
|
|
10000
10385
|
const collaborators = [];
|
|
10001
10386
|
for (const property of pattern.properties) {
|
|
10002
|
-
if (property.type !==
|
|
10003
|
-
if (property.key.type !==
|
|
10387
|
+
if (property.type !== import_utils65.AST_NODE_TYPES.Property || property.computed) continue;
|
|
10388
|
+
if (property.key.type !== import_utils65.AST_NODE_TYPES.Identifier) continue;
|
|
10004
10389
|
const key = property.key.name;
|
|
10005
|
-
const bound = property.value.type ===
|
|
10006
|
-
if (bound.type !==
|
|
10390
|
+
const bound = property.value.type === import_utils65.AST_NODE_TYPES.AssignmentPattern ? property.value.left : property.value;
|
|
10391
|
+
if (bound.type !== import_utils65.AST_NODE_TYPES.Identifier) continue;
|
|
10007
10392
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
10008
10393
|
const reference = members.get(key);
|
|
10009
10394
|
if (reference === void 0) continue;
|
|
@@ -10013,8 +10398,8 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
10013
10398
|
};
|
|
10014
10399
|
var parameterCollaborators = (parameter, declared) => {
|
|
10015
10400
|
let target = parameter;
|
|
10016
|
-
if (target.type ===
|
|
10017
|
-
if (target.type ===
|
|
10401
|
+
if (target.type === import_utils65.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
10402
|
+
if (target.type === import_utils65.AST_NODE_TYPES.ObjectPattern) {
|
|
10018
10403
|
return objectPatternCollaborators(target, declared);
|
|
10019
10404
|
}
|
|
10020
10405
|
const named2 = namedParameterCollaborator(parameter);
|
|
@@ -10032,18 +10417,31 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
10032
10417
|
const storedFrom = /* @__PURE__ */ new Set();
|
|
10033
10418
|
let constructedFields = 0;
|
|
10034
10419
|
if (body2 !== null && body2 !== void 0) {
|
|
10035
|
-
|
|
10036
|
-
|
|
10037
|
-
const
|
|
10038
|
-
if (
|
|
10420
|
+
const pending = [...body2.body];
|
|
10421
|
+
while (pending.length > 0) {
|
|
10422
|
+
const current = pending.pop();
|
|
10423
|
+
if (current === void 0) break;
|
|
10424
|
+
if (current.type === import_utils65.AST_NODE_TYPES.ArrowFunctionExpression || current.type === import_utils65.AST_NODE_TYPES.FunctionExpression || current.type === import_utils65.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils65.AST_NODE_TYPES.ClassExpression || current.type === import_utils65.AST_NODE_TYPES.ClassDeclaration) continue;
|
|
10425
|
+
const expression = current.type === import_utils65.AST_NODE_TYPES.ExpressionStatement ? current.expression : null;
|
|
10426
|
+
if (expression?.type !== import_utils65.AST_NODE_TYPES.AssignmentExpression || !STORAGE_ASSIGNMENT_OPERATORS.has(expression.operator) || expression.left.type !== import_utils65.AST_NODE_TYPES.MemberExpression || expression.left.object.type !== import_utils65.AST_NODE_TYPES.ThisExpression) {
|
|
10427
|
+
for (const key of Object.keys(current)) {
|
|
10428
|
+
if (key === "parent") continue;
|
|
10429
|
+
const value = current[key];
|
|
10430
|
+
for (const child of Array.isArray(value) ? value : [value]) {
|
|
10431
|
+
if (child !== null && typeof child === "object" && typeof child.type === "string") {
|
|
10432
|
+
pending.push(child);
|
|
10433
|
+
}
|
|
10434
|
+
}
|
|
10435
|
+
}
|
|
10039
10436
|
continue;
|
|
10040
10437
|
}
|
|
10041
|
-
|
|
10042
|
-
|
|
10438
|
+
let source = expression.right;
|
|
10439
|
+
while (source.type === import_utils65.AST_NODE_TYPES.TSNonNullExpression || source.type === import_utils65.AST_NODE_TYPES.TSAsExpression || source.type === import_utils65.AST_NODE_TYPES.TSSatisfiesExpression || source.type === import_utils65.AST_NODE_TYPES.TSTypeAssertion) source = source.expression;
|
|
10440
|
+
if (source.type === import_utils65.AST_NODE_TYPES.NewExpression) {
|
|
10043
10441
|
constructedFields += 1;
|
|
10044
|
-
} else if (source.type ===
|
|
10442
|
+
} else if (source.type === import_utils65.AST_NODE_TYPES.Identifier) {
|
|
10045
10443
|
storedFrom.add(source.name);
|
|
10046
|
-
} else if (source.type ===
|
|
10444
|
+
} else if (source.type === import_utils65.AST_NODE_TYPES.MemberExpression && source.object.type === import_utils65.AST_NODE_TYPES.Identifier) {
|
|
10047
10445
|
storedFrom.add(source.object.name);
|
|
10048
10446
|
}
|
|
10049
10447
|
}
|
|
@@ -10051,12 +10449,13 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
10051
10449
|
const collaborators = [];
|
|
10052
10450
|
for (const parameter of ctor.value.params) {
|
|
10053
10451
|
for (const reference of parameterCollaborators(parameter, declared)) {
|
|
10054
|
-
const stored = parameter.type ===
|
|
10452
|
+
const stored = parameter.type === import_utils65.AST_NODE_TYPES.TSParameterProperty || storedFrom.has(reference.name);
|
|
10055
10453
|
if (!stored) continue;
|
|
10056
10454
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
10057
10455
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
10058
10456
|
if (typeParameters.has(reference.typeName)) continue;
|
|
10059
10457
|
if (BUILTIN_CONTAINER_TYPE_RE.test(reference.typeName)) continue;
|
|
10458
|
+
if (VALUE_TYPE_RE.test(reference.typeName)) continue;
|
|
10060
10459
|
if (declared().functionAliases.has(reference.typeName)) continue;
|
|
10061
10460
|
collaborators.push(reference);
|
|
10062
10461
|
}
|
|
@@ -10085,19 +10484,19 @@ var subtreeHas = (root, found) => {
|
|
|
10085
10484
|
return hit;
|
|
10086
10485
|
};
|
|
10087
10486
|
var isFrameworkWiring = (body2) => subtreeHas(body2, (node) => {
|
|
10088
|
-
if (node.type ===
|
|
10487
|
+
if (node.type === import_utils65.AST_NODE_TYPES.CallExpression) {
|
|
10089
10488
|
const { callee } = node;
|
|
10090
|
-
if (callee.type ===
|
|
10091
|
-
return callee.type ===
|
|
10489
|
+
if (callee.type === import_utils65.AST_NODE_TYPES.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
10490
|
+
return callee.type === import_utils65.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils65.AST_NODE_TYPES.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
10092
10491
|
}
|
|
10093
|
-
return node.type ===
|
|
10492
|
+
return node.type === import_utils65.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils65.AST_NODE_TYPES.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
10094
10493
|
});
|
|
10095
10494
|
var stem2 = (name) => name.replace(/^I(?=[A-Z])/, "").replace(/Impl$/, "");
|
|
10096
10495
|
var fileInterfaceNames = (program) => {
|
|
10097
10496
|
const names = [];
|
|
10098
10497
|
for (const statement of program.body) {
|
|
10099
|
-
const declaration = statement.type ===
|
|
10100
|
-
if (declaration?.type ===
|
|
10498
|
+
const declaration = statement.type === import_utils65.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
10499
|
+
if (declaration?.type === import_utils65.AST_NODE_TYPES.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
10101
10500
|
}
|
|
10102
10501
|
return names;
|
|
10103
10502
|
};
|
|
@@ -10112,28 +10511,153 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
10112
10511
|
return target.endsWith(other) || other.endsWith(target);
|
|
10113
10512
|
});
|
|
10114
10513
|
};
|
|
10115
|
-
var publicMethodNames = (body2) => {
|
|
10514
|
+
var publicMethodNames = (body2, functionAliases) => {
|
|
10116
10515
|
const names = [];
|
|
10117
10516
|
for (const member of body2.body) {
|
|
10118
|
-
if (member.type
|
|
10517
|
+
if (member.type === import_utils65.AST_NODE_TYPES.PropertyDefinition) {
|
|
10518
|
+
if (member.static || member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
10519
|
+
if (member.value?.type !== import_utils65.AST_NODE_TYPES.ArrowFunctionExpression && member.value?.type !== import_utils65.AST_NODE_TYPES.FunctionExpression && member.typeAnnotation?.typeAnnotation.type !== import_utils65.AST_NODE_TYPES.TSFunctionType && !(member.typeAnnotation?.typeAnnotation.type === import_utils65.AST_NODE_TYPES.TSTypeReference && member.typeAnnotation.typeAnnotation.typeName.type === import_utils65.AST_NODE_TYPES.Identifier && functionAliases.has(member.typeAnnotation.typeAnnotation.typeName.name))) continue;
|
|
10520
|
+
names.push(member.key.type === import_utils65.AST_NODE_TYPES.Identifier ? member.key.name : "\u2026");
|
|
10521
|
+
continue;
|
|
10522
|
+
}
|
|
10523
|
+
if (member.type !== import_utils65.AST_NODE_TYPES.MethodDefinition) continue;
|
|
10119
10524
|
if (member.kind !== "method" || member.static) continue;
|
|
10120
10525
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
10121
|
-
if (member.key.type ===
|
|
10122
|
-
if (member.key.type ===
|
|
10526
|
+
if (member.key.type === import_utils65.AST_NODE_TYPES.PrivateIdentifier) continue;
|
|
10527
|
+
if (member.key.type === import_utils65.AST_NODE_TYPES.Identifier) names.push(member.key.name);
|
|
10123
10528
|
else names.push("\u2026");
|
|
10124
10529
|
}
|
|
10125
10530
|
return names;
|
|
10126
10531
|
};
|
|
10532
|
+
function localClassAbstractness(program) {
|
|
10533
|
+
const classes = /* @__PURE__ */ new Map();
|
|
10534
|
+
const parents = /* @__PURE__ */ new Map();
|
|
10535
|
+
for (const statement of program.body) {
|
|
10536
|
+
const declaration = statement.type === import_utils65.AST_NODE_TYPES.ExportNamedDeclaration || statement.type === import_utils65.AST_NODE_TYPES.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
10537
|
+
if (declaration?.type === import_utils65.AST_NODE_TYPES.ClassDeclaration && declaration.id !== null) {
|
|
10538
|
+
classes.set(declaration.id.name, declaration.abstract === true);
|
|
10539
|
+
if (declaration.superClass?.type === import_utils65.AST_NODE_TYPES.Identifier) {
|
|
10540
|
+
parents.set(declaration.id.name, declaration.superClass.name);
|
|
10541
|
+
}
|
|
10542
|
+
}
|
|
10543
|
+
}
|
|
10544
|
+
for (let pass = 0; pass < classes.size; pass += 1) {
|
|
10545
|
+
let changed = false;
|
|
10546
|
+
for (const [name, parent] of parents) {
|
|
10547
|
+
if (classes.get(name) !== true && classes.get(parent) === true) {
|
|
10548
|
+
classes.set(name, true);
|
|
10549
|
+
changed = true;
|
|
10550
|
+
}
|
|
10551
|
+
}
|
|
10552
|
+
if (!changed) break;
|
|
10553
|
+
}
|
|
10554
|
+
return classes;
|
|
10555
|
+
}
|
|
10556
|
+
function localInterfaceSurfaces(program) {
|
|
10557
|
+
const interfaces = /* @__PURE__ */ new Map();
|
|
10558
|
+
const parents = /* @__PURE__ */ new Map();
|
|
10559
|
+
const functionAliases = /* @__PURE__ */ new Set();
|
|
10560
|
+
for (const statement of program.body) {
|
|
10561
|
+
const declaration = statement.type === import_utils65.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
10562
|
+
if (declaration?.type === import_utils65.AST_NODE_TYPES.TSTypeAliasDeclaration && (declaration.typeAnnotation.type === import_utils65.AST_NODE_TYPES.TSFunctionType || declaration.typeAnnotation.type === import_utils65.AST_NODE_TYPES.TSConstructorType)) functionAliases.add(declaration.id.name);
|
|
10563
|
+
}
|
|
10564
|
+
for (const statement of program.body) {
|
|
10565
|
+
const declaration = statement.type === import_utils65.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
10566
|
+
if (declaration?.type === import_utils65.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
10567
|
+
const callables2 = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
10568
|
+
const parts = declaration.typeAnnotation.type === import_utils65.AST_NODE_TYPES.TSIntersectionType ? declaration.typeAnnotation.types : [declaration.typeAnnotation];
|
|
10569
|
+
const inherited = parents.get(declaration.id.name) ?? [];
|
|
10570
|
+
for (const part of parts) {
|
|
10571
|
+
if (part.type === import_utils65.AST_NODE_TYPES.TSTypeReference && part.typeName.type === import_utils65.AST_NODE_TYPES.Identifier) {
|
|
10572
|
+
inherited.push(part.typeName.name);
|
|
10573
|
+
continue;
|
|
10574
|
+
}
|
|
10575
|
+
if (part.type !== import_utils65.AST_NODE_TYPES.TSTypeLiteral) continue;
|
|
10576
|
+
for (const member of part.members) {
|
|
10577
|
+
if (member.type !== import_utils65.AST_NODE_TYPES.TSMethodSignature && member.type !== import_utils65.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
10578
|
+
if (member.computed || member.key.type !== import_utils65.AST_NODE_TYPES.Identifier) continue;
|
|
10579
|
+
if (member.type === import_utils65.AST_NODE_TYPES.TSMethodSignature) {
|
|
10580
|
+
callables2.add(member.key.name);
|
|
10581
|
+
continue;
|
|
10582
|
+
}
|
|
10583
|
+
if (member.type !== import_utils65.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
10584
|
+
const annotation = member.typeAnnotation?.typeAnnotation;
|
|
10585
|
+
if (annotation?.type === import_utils65.AST_NODE_TYPES.TSFunctionType || annotation?.type === import_utils65.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils65.AST_NODE_TYPES.Identifier && functionAliases.has(annotation.typeName.name)) callables2.add(member.key.name);
|
|
10586
|
+
}
|
|
10587
|
+
}
|
|
10588
|
+
interfaces.set(declaration.id.name, callables2);
|
|
10589
|
+
parents.set(declaration.id.name, inherited);
|
|
10590
|
+
continue;
|
|
10591
|
+
}
|
|
10592
|
+
if (declaration?.type !== import_utils65.AST_NODE_TYPES.TSInterfaceDeclaration) continue;
|
|
10593
|
+
const callables = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
10594
|
+
for (const member of declaration.body.body) {
|
|
10595
|
+
if (member.type !== import_utils65.AST_NODE_TYPES.TSMethodSignature && member.type !== import_utils65.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
10596
|
+
if (member.computed || member.key.type !== import_utils65.AST_NODE_TYPES.Identifier) continue;
|
|
10597
|
+
if (member.type === import_utils65.AST_NODE_TYPES.TSMethodSignature || member.typeAnnotation?.typeAnnotation.type === import_utils65.AST_NODE_TYPES.TSFunctionType || member.typeAnnotation?.typeAnnotation.type === import_utils65.AST_NODE_TYPES.TSTypeReference && member.typeAnnotation.typeAnnotation.typeName.type === import_utils65.AST_NODE_TYPES.Identifier && functionAliases.has(member.typeAnnotation.typeAnnotation.typeName.name)) callables.add(member.key.name);
|
|
10598
|
+
}
|
|
10599
|
+
interfaces.set(declaration.id.name, callables);
|
|
10600
|
+
parents.set(
|
|
10601
|
+
declaration.id.name,
|
|
10602
|
+
[
|
|
10603
|
+
...parents.get(declaration.id.name) ?? [],
|
|
10604
|
+
...declaration.extends.flatMap(
|
|
10605
|
+
(heritage) => heritage.expression.type === import_utils65.AST_NODE_TYPES.Identifier ? [heritage.expression.name] : ["*"]
|
|
10606
|
+
)
|
|
10607
|
+
]
|
|
10608
|
+
);
|
|
10609
|
+
}
|
|
10610
|
+
for (let pass = 0; pass <= interfaces.size; pass += 1) {
|
|
10611
|
+
let changed = false;
|
|
10612
|
+
for (const [name, inherited] of parents) {
|
|
10613
|
+
const surface = interfaces.get(name);
|
|
10614
|
+
if (surface === void 0) continue;
|
|
10615
|
+
for (const parent of inherited) {
|
|
10616
|
+
const parentSurface = interfaces.get(parent);
|
|
10617
|
+
const additions = parentSurface ?? /* @__PURE__ */ new Set(["*"]);
|
|
10618
|
+
for (const method of additions) {
|
|
10619
|
+
if (!surface.has(method)) {
|
|
10620
|
+
surface.add(method);
|
|
10621
|
+
changed = true;
|
|
10622
|
+
}
|
|
10623
|
+
}
|
|
10624
|
+
}
|
|
10625
|
+
}
|
|
10626
|
+
if (!changed) break;
|
|
10627
|
+
}
|
|
10628
|
+
return interfaces;
|
|
10629
|
+
}
|
|
10630
|
+
function hasServicePort(node, methods, classes, interfaces) {
|
|
10631
|
+
if (node.superClass !== null) {
|
|
10632
|
+
if (node.superClass.type !== import_utils65.AST_NODE_TYPES.Identifier) return true;
|
|
10633
|
+
const localAbstract = classes.get(node.superClass.name);
|
|
10634
|
+
if (localAbstract === void 0 || localAbstract) return true;
|
|
10635
|
+
}
|
|
10636
|
+
if (node.implements.length === 0) return false;
|
|
10637
|
+
const combined = /* @__PURE__ */ new Set();
|
|
10638
|
+
for (const implementation of node.implements) {
|
|
10639
|
+
if (implementation.expression.type !== import_utils65.AST_NODE_TYPES.Identifier) return true;
|
|
10640
|
+
const name = implementation.expression.name;
|
|
10641
|
+
const localAbstract = classes.get(name);
|
|
10642
|
+
if (localAbstract === true) return true;
|
|
10643
|
+
const surface = interfaces.get(name);
|
|
10644
|
+
if (surface === void 0 && localAbstract === void 0) return true;
|
|
10645
|
+
if (surface === void 0) continue;
|
|
10646
|
+
if (surface.has("*")) return true;
|
|
10647
|
+
for (const method of surface) combined.add(method);
|
|
10648
|
+
}
|
|
10649
|
+
return methods.every((method) => combined.has(method));
|
|
10650
|
+
}
|
|
10127
10651
|
var require_interface_for_injected_service_default = createRule({
|
|
10128
10652
|
name: "require-interface-for-injected-service",
|
|
10129
10653
|
meta: {
|
|
10130
10654
|
type: "suggestion",
|
|
10131
10655
|
docs: {
|
|
10132
|
-
description: "An exported service class with constructor-injected collaborators
|
|
10656
|
+
description: "An exported service class with constructor-injected collaborators should declare the interface its public callable surface implements."
|
|
10133
10657
|
},
|
|
10134
10658
|
schema: [],
|
|
10135
10659
|
messages: {
|
|
10136
|
-
requireInterface: "`{{name}}` stores injected collaborator(s) ({{deps}}) but
|
|
10660
|
+
requireInterface: "`{{name}}` stores injected collaborator(s) ({{deps}}) but declares no service interface. Extract its public callable surface ({{methods}}) into a port and declare `class {{name}} implements <Interface>` so consumers can inject that port."
|
|
10137
10661
|
}
|
|
10138
10662
|
},
|
|
10139
10663
|
defaultOptions: [],
|
|
@@ -10142,17 +10666,18 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
10142
10666
|
if (isTestFile(filename) || isStoryFile(filename) || isScriptFile(filename)) return {};
|
|
10143
10667
|
if (isGeneratedFile(filename, context.sourceCode.getText())) return {};
|
|
10144
10668
|
let declaredTypes = null;
|
|
10669
|
+
const detachedExports = detachedValueExports(context.sourceCode.ast);
|
|
10670
|
+
const localClasses = localClassAbstractness(context.sourceCode.ast);
|
|
10671
|
+
const localInterfaces = localInterfaceSurfaces(context.sourceCode.ast);
|
|
10145
10672
|
const objectTypes = () => declaredTypes ??= fileTypeIndex(context.sourceCode.ast);
|
|
10146
10673
|
return {
|
|
10147
10674
|
ClassDeclaration(node) {
|
|
10148
10675
|
if (node.id === null) return;
|
|
10149
|
-
if (!
|
|
10676
|
+
if (!isExportedClass2(node, detachedExports)) return;
|
|
10150
10677
|
if (node.abstract === true) return;
|
|
10151
|
-
if (node.superClass !== null) return;
|
|
10152
|
-
if (node.implements.length > 0) return;
|
|
10153
10678
|
if (node.decorators.length > 0) return;
|
|
10154
10679
|
const ctor = node.body.body.find(
|
|
10155
|
-
(member) => member.type ===
|
|
10680
|
+
(member) => member.type === import_utils65.AST_NODE_TYPES.MethodDefinition && member.kind === "constructor"
|
|
10156
10681
|
);
|
|
10157
10682
|
if (ctor === void 0) return;
|
|
10158
10683
|
const { collaborators, constructedFields } = readConstructor(
|
|
@@ -10164,8 +10689,9 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
10164
10689
|
if (constructedFields > collaborators.length) return;
|
|
10165
10690
|
if (isFrameworkWiring(node.body)) return;
|
|
10166
10691
|
if (isTransportWrapper(node.id.name, collaborators, context.sourceCode.ast)) return;
|
|
10167
|
-
const methods = publicMethodNames(node.body);
|
|
10692
|
+
const methods = publicMethodNames(node.body, objectTypes().functionAliases);
|
|
10168
10693
|
if (methods.length === 0) return;
|
|
10694
|
+
if (hasServicePort(node, methods, localClasses, localInterfaces)) return;
|
|
10169
10695
|
context.report({
|
|
10170
10696
|
node: node.id,
|
|
10171
10697
|
messageId: "requireInterface",
|
|
@@ -10181,37 +10707,37 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
10181
10707
|
});
|
|
10182
10708
|
|
|
10183
10709
|
// src/rules/require-static-next-matcher.ts
|
|
10184
|
-
var
|
|
10710
|
+
var import_utils66 = require("@typescript-eslint/utils");
|
|
10185
10711
|
var NEXT_ENTRY_FILE = /(?:^|[/\\])(?:middleware|proxy)\.[cm]?[jt]sx?$/u;
|
|
10186
10712
|
function unwrapExpression2(node) {
|
|
10187
|
-
if (node.type ===
|
|
10713
|
+
if (node.type === import_utils66.AST_NODE_TYPES.TSAsExpression || node.type === import_utils66.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils66.AST_NODE_TYPES.TSNonNullExpression || node.type === import_utils66.AST_NODE_TYPES.TSTypeAssertion) {
|
|
10188
10714
|
return unwrapExpression2(node.expression);
|
|
10189
10715
|
}
|
|
10190
10716
|
return node;
|
|
10191
10717
|
}
|
|
10192
10718
|
function isStaticValue(node) {
|
|
10193
10719
|
const value = unwrapExpression2(node);
|
|
10194
|
-
if (value.type ===
|
|
10720
|
+
if (value.type === import_utils66.AST_NODE_TYPES.Literal) {
|
|
10195
10721
|
return true;
|
|
10196
10722
|
}
|
|
10197
|
-
if (value.type ===
|
|
10723
|
+
if (value.type === import_utils66.AST_NODE_TYPES.TemplateLiteral) {
|
|
10198
10724
|
return value.expressions.length === 0;
|
|
10199
10725
|
}
|
|
10200
|
-
if (value.type ===
|
|
10726
|
+
if (value.type === import_utils66.AST_NODE_TYPES.ArrayExpression) {
|
|
10201
10727
|
return value.elements.every(
|
|
10202
|
-
(element) => element !== null && element.type !==
|
|
10728
|
+
(element) => element !== null && element.type !== import_utils66.AST_NODE_TYPES.SpreadElement && isStaticValue(element)
|
|
10203
10729
|
);
|
|
10204
10730
|
}
|
|
10205
|
-
if (value.type ===
|
|
10731
|
+
if (value.type === import_utils66.AST_NODE_TYPES.ObjectExpression) {
|
|
10206
10732
|
return value.properties.every(
|
|
10207
|
-
(property) => property.type ===
|
|
10733
|
+
(property) => property.type === import_utils66.AST_NODE_TYPES.Property && property.kind === "init" && !property.computed && property.value.type !== import_utils66.AST_NODE_TYPES.AssignmentPattern && isStaticValue(property.value)
|
|
10208
10734
|
);
|
|
10209
10735
|
}
|
|
10210
10736
|
return false;
|
|
10211
10737
|
}
|
|
10212
10738
|
function propertyName2(property) {
|
|
10213
10739
|
if (property.computed) return null;
|
|
10214
|
-
if (property.key.type ===
|
|
10740
|
+
if (property.key.type === import_utils66.AST_NODE_TYPES.Identifier) return property.key.name;
|
|
10215
10741
|
return typeof property.key.value === "string" ? property.key.value : null;
|
|
10216
10742
|
}
|
|
10217
10743
|
var require_static_next_matcher_default = createRule({
|
|
@@ -10233,19 +10759,19 @@ var require_static_next_matcher_default = createRule({
|
|
|
10233
10759
|
}
|
|
10234
10760
|
return {
|
|
10235
10761
|
ExportNamedDeclaration(node) {
|
|
10236
|
-
if (node.declaration?.type !==
|
|
10762
|
+
if (node.declaration?.type !== import_utils66.AST_NODE_TYPES.VariableDeclaration) {
|
|
10237
10763
|
return;
|
|
10238
10764
|
}
|
|
10239
10765
|
for (const declaration of node.declaration.declarations) {
|
|
10240
|
-
if (declaration.id.type !==
|
|
10766
|
+
if (declaration.id.type !== import_utils66.AST_NODE_TYPES.Identifier || declaration.id.name !== "config" || declaration.init === null) {
|
|
10241
10767
|
continue;
|
|
10242
10768
|
}
|
|
10243
10769
|
const config = unwrapExpression2(declaration.init);
|
|
10244
|
-
if (config.type !==
|
|
10770
|
+
if (config.type !== import_utils66.AST_NODE_TYPES.ObjectExpression) {
|
|
10245
10771
|
continue;
|
|
10246
10772
|
}
|
|
10247
10773
|
for (const property of config.properties) {
|
|
10248
|
-
if (property.type !==
|
|
10774
|
+
if (property.type !== import_utils66.AST_NODE_TYPES.Property || propertyName2(property) !== "matcher" || property.value.type === import_utils66.AST_NODE_TYPES.AssignmentPattern) {
|
|
10249
10775
|
continue;
|
|
10250
10776
|
}
|
|
10251
10777
|
if (!isStaticValue(property.value)) {
|
|
@@ -10259,18 +10785,18 @@ var require_static_next_matcher_default = createRule({
|
|
|
10259
10785
|
});
|
|
10260
10786
|
|
|
10261
10787
|
// src/rules/require-zod-form-validation.ts
|
|
10262
|
-
var
|
|
10788
|
+
var import_utils67 = require("@typescript-eslint/utils");
|
|
10263
10789
|
var looksLikeZodSchema = (node) => {
|
|
10264
10790
|
let current = node;
|
|
10265
10791
|
while (true) {
|
|
10266
|
-
if (current.type ===
|
|
10792
|
+
if (current.type === import_utils67.AST_NODE_TYPES.Identifier) {
|
|
10267
10793
|
return current.name === "z" || ZOD_SCHEMA_NAME_RE.test(current.name);
|
|
10268
10794
|
}
|
|
10269
|
-
if (current.type ===
|
|
10795
|
+
if (current.type === import_utils67.AST_NODE_TYPES.CallExpression) {
|
|
10270
10796
|
current = current.callee;
|
|
10271
10797
|
continue;
|
|
10272
10798
|
}
|
|
10273
|
-
if (current.type ===
|
|
10799
|
+
if (current.type === import_utils67.AST_NODE_TYPES.MemberExpression) {
|
|
10274
10800
|
current = current.object;
|
|
10275
10801
|
continue;
|
|
10276
10802
|
}
|
|
@@ -10278,23 +10804,23 @@ var looksLikeZodSchema = (node) => {
|
|
|
10278
10804
|
}
|
|
10279
10805
|
};
|
|
10280
10806
|
var isZodParseCall = (node) => {
|
|
10281
|
-
if (node.type !==
|
|
10807
|
+
if (node.type !== import_utils67.AST_NODE_TYPES.CallExpression) return false;
|
|
10282
10808
|
const callee = node.callee;
|
|
10283
|
-
if (callee.type !==
|
|
10809
|
+
if (callee.type !== import_utils67.AST_NODE_TYPES.MemberExpression) return false;
|
|
10284
10810
|
if (callee.computed) return false;
|
|
10285
|
-
if (callee.property.type !==
|
|
10811
|
+
if (callee.property.type !== import_utils67.AST_NODE_TYPES.Identifier) return false;
|
|
10286
10812
|
const method = callee.property.name;
|
|
10287
10813
|
if (method !== "parse" && method !== "safeParse") return false;
|
|
10288
10814
|
return looksLikeZodSchema(callee.object);
|
|
10289
10815
|
};
|
|
10290
10816
|
var isFormDataMethodCall = (node) => {
|
|
10291
10817
|
let current = node;
|
|
10292
|
-
if (current.type ===
|
|
10818
|
+
if (current.type === import_utils67.AST_NODE_TYPES.AwaitExpression) {
|
|
10293
10819
|
current = current.argument;
|
|
10294
10820
|
}
|
|
10295
|
-
if (current.type !==
|
|
10821
|
+
if (current.type !== import_utils67.AST_NODE_TYPES.CallExpression) return false;
|
|
10296
10822
|
const callee = current.callee;
|
|
10297
|
-
return callee.type ===
|
|
10823
|
+
return callee.type === import_utils67.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils67.AST_NODE_TYPES.Identifier && callee.property.name === "formData";
|
|
10298
10824
|
};
|
|
10299
10825
|
var require_zod_form_validation_default = createRule({
|
|
10300
10826
|
name: "require-zod-form-validation",
|
|
@@ -10314,14 +10840,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
10314
10840
|
return {};
|
|
10315
10841
|
}
|
|
10316
10842
|
const isFormSourceIdentifier = (node) => {
|
|
10317
|
-
if (node.type !==
|
|
10843
|
+
if (node.type !== import_utils67.AST_NODE_TYPES.Identifier) return false;
|
|
10318
10844
|
if (/formdata/i.test(node.name)) return true;
|
|
10319
10845
|
let scope = context.sourceCode.getScope(node);
|
|
10320
10846
|
while (scope !== null) {
|
|
10321
10847
|
const variable = scope.set.get(node.name);
|
|
10322
10848
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
10323
10849
|
const def = variable.defs[0];
|
|
10324
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
10850
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === import_utils67.AST_NODE_TYPES.VariableDeclarator && def.node.init !== null) {
|
|
10325
10851
|
return isFormDataMethodCall(def.node.init);
|
|
10326
10852
|
}
|
|
10327
10853
|
return false;
|
|
@@ -10332,8 +10858,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
10332
10858
|
};
|
|
10333
10859
|
const isFormDataGetCall = (node) => {
|
|
10334
10860
|
const callee = node.callee;
|
|
10335
|
-
if (callee.type !==
|
|
10336
|
-
if (callee.property.type !==
|
|
10861
|
+
if (callee.type !== import_utils67.AST_NODE_TYPES.MemberExpression) return false;
|
|
10862
|
+
if (callee.property.type !== import_utils67.AST_NODE_TYPES.Identifier || callee.property.name !== "get") {
|
|
10337
10863
|
return false;
|
|
10338
10864
|
}
|
|
10339
10865
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -10348,11 +10874,11 @@ var require_zod_form_validation_default = createRule({
|
|
|
10348
10874
|
};
|
|
10349
10875
|
const isInstanceofNarrowing = (node) => {
|
|
10350
10876
|
const parent = node.parent;
|
|
10351
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
10877
|
+
return parent !== null && parent !== void 0 && parent.type === import_utils67.AST_NODE_TYPES.BinaryExpression && parent.operator === "instanceof" && parent.left === node && parent.right.type === import_utils67.AST_NODE_TYPES.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
10352
10878
|
};
|
|
10353
10879
|
const boundDeclarator = (node) => {
|
|
10354
10880
|
const parent = node.parent;
|
|
10355
|
-
if (parent.type ===
|
|
10881
|
+
if (parent.type === import_utils67.AST_NODE_TYPES.VariableDeclarator && parent.init === node && parent.id.type === import_utils67.AST_NODE_TYPES.Identifier) {
|
|
10356
10882
|
return parent;
|
|
10357
10883
|
}
|
|
10358
10884
|
return null;
|
|
@@ -10380,7 +10906,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
10380
10906
|
});
|
|
10381
10907
|
|
|
10382
10908
|
// src/rules/store-insert-requires-on-conflict.ts
|
|
10383
|
-
var
|
|
10909
|
+
var import_utils68 = require("@typescript-eslint/utils");
|
|
10384
10910
|
var INSERT_WRITE = /\bINSERT\s+(?:OR\s+\w+\s+)?INTO\s+[\w."'`?$:@-]+\s*(?:\([^)]*\)\s*)?(?:VALUES|SELECT|DEFAULT\s+VALUES)\b/i;
|
|
10385
10911
|
var CONFLICT_HANDLED = /\bON\s+CONFLICT\b|\bON\s+DUPLICATE\s+KEY\b|\bINSERT\s+OR\s+(?:IGNORE|REPLACE)\b/i;
|
|
10386
10912
|
var INSERT_GATE = /insert/i;
|
|
@@ -10410,8 +10936,395 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
10410
10936
|
}
|
|
10411
10937
|
});
|
|
10412
10938
|
|
|
10939
|
+
// src/rules/stepdown.ts
|
|
10940
|
+
var import_utils69 = require("@typescript-eslint/utils");
|
|
10941
|
+
function isFunction(node) {
|
|
10942
|
+
return node.type === import_utils69.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils69.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils69.AST_NODE_TYPES.FunctionExpression;
|
|
10943
|
+
}
|
|
10944
|
+
function cycleComponents(graph) {
|
|
10945
|
+
const nodes = /* @__PURE__ */ new Set();
|
|
10946
|
+
const reverse = /* @__PURE__ */ new Map();
|
|
10947
|
+
for (const [caller, callees] of graph) {
|
|
10948
|
+
nodes.add(caller);
|
|
10949
|
+
for (const callee of callees) {
|
|
10950
|
+
nodes.add(callee);
|
|
10951
|
+
const incoming = reverse.get(callee) ?? /* @__PURE__ */ new Set();
|
|
10952
|
+
incoming.add(caller);
|
|
10953
|
+
reverse.set(callee, incoming);
|
|
10954
|
+
}
|
|
10955
|
+
}
|
|
10956
|
+
const seen = /* @__PURE__ */ new Set();
|
|
10957
|
+
const finishOrder = [];
|
|
10958
|
+
for (const root of nodes) {
|
|
10959
|
+
if (seen.has(root)) continue;
|
|
10960
|
+
const pending = [
|
|
10961
|
+
{ name: root, exiting: false }
|
|
10962
|
+
];
|
|
10963
|
+
while (pending.length > 0) {
|
|
10964
|
+
const current = pending.pop();
|
|
10965
|
+
if (current === void 0) break;
|
|
10966
|
+
if (current.exiting) {
|
|
10967
|
+
finishOrder.push(current.name);
|
|
10968
|
+
continue;
|
|
10969
|
+
}
|
|
10970
|
+
if (seen.has(current.name)) continue;
|
|
10971
|
+
seen.add(current.name);
|
|
10972
|
+
pending.push({ name: current.name, exiting: true });
|
|
10973
|
+
for (const callee of graph.get(current.name) ?? []) {
|
|
10974
|
+
if (!seen.has(callee)) pending.push({ name: callee, exiting: false });
|
|
10975
|
+
}
|
|
10976
|
+
}
|
|
10977
|
+
}
|
|
10978
|
+
const components = /* @__PURE__ */ new Map();
|
|
10979
|
+
let nextComponent = 0;
|
|
10980
|
+
const assigned = /* @__PURE__ */ new Set();
|
|
10981
|
+
for (let index = finishOrder.length - 1; index >= 0; index -= 1) {
|
|
10982
|
+
const root = finishOrder[index];
|
|
10983
|
+
if (root === void 0 || assigned.has(root)) continue;
|
|
10984
|
+
const members = [];
|
|
10985
|
+
const pending = [root];
|
|
10986
|
+
assigned.add(root);
|
|
10987
|
+
while (pending.length > 0) {
|
|
10988
|
+
const member = pending.pop();
|
|
10989
|
+
if (member === void 0) break;
|
|
10990
|
+
members.push(member);
|
|
10991
|
+
for (const caller of reverse.get(member) ?? []) {
|
|
10992
|
+
if (!assigned.has(caller)) {
|
|
10993
|
+
assigned.add(caller);
|
|
10994
|
+
pending.push(caller);
|
|
10995
|
+
}
|
|
10996
|
+
}
|
|
10997
|
+
}
|
|
10998
|
+
if (members.length > 1) {
|
|
10999
|
+
for (const cyclicName of members) components.set(cyclicName, nextComponent);
|
|
11000
|
+
nextComponent += 1;
|
|
11001
|
+
}
|
|
11002
|
+
}
|
|
11003
|
+
return components;
|
|
11004
|
+
}
|
|
11005
|
+
function reportMisordered(context, candidates, scopeDefinitions, calls, pinned) {
|
|
11006
|
+
const byName = new Map(scopeDefinitions.map((definition) => [definition.name, definition]));
|
|
11007
|
+
const cycles = cycleComponents(calls);
|
|
11008
|
+
const callers = /* @__PURE__ */ new Map();
|
|
11009
|
+
for (const [caller, callees] of calls) {
|
|
11010
|
+
for (const callee of callees) {
|
|
11011
|
+
if (caller === callee) continue;
|
|
11012
|
+
const names = callers.get(callee) ?? /* @__PURE__ */ new Set();
|
|
11013
|
+
names.add(caller);
|
|
11014
|
+
callers.set(callee, names);
|
|
11015
|
+
}
|
|
11016
|
+
}
|
|
11017
|
+
for (const helper of candidates) {
|
|
11018
|
+
const helperCallers = [...callers.get(helper.name) ?? []];
|
|
11019
|
+
if (pinned.has(helper.name) || helperCallers.length !== 1) continue;
|
|
11020
|
+
const callerName = helperCallers[0];
|
|
11021
|
+
if (callerName === void 0 || cycles.has(helper.name) && cycles.get(helper.name) === cycles.get(callerName)) continue;
|
|
11022
|
+
const caller = byName.get(callerName);
|
|
11023
|
+
if (caller === void 0 || helper.node.range[0] >= caller.node.range[0]) continue;
|
|
11024
|
+
context.report({
|
|
11025
|
+
node: helper.node,
|
|
11026
|
+
messageId: "helperAboveOnlyCaller",
|
|
11027
|
+
data: { helper: helper.name, caller: callerName }
|
|
11028
|
+
});
|
|
11029
|
+
}
|
|
11030
|
+
}
|
|
11031
|
+
function exportedNames(program) {
|
|
11032
|
+
const names = /* @__PURE__ */ new Set();
|
|
11033
|
+
for (const statement of program.body) {
|
|
11034
|
+
if (statement.type !== import_utils69.AST_NODE_TYPES.ExportNamedDeclaration || statement.exportKind === "type" || statement.source !== null) continue;
|
|
11035
|
+
if (statement.declaration?.type === import_utils69.AST_NODE_TYPES.FunctionDeclaration && statement.declaration.id !== null) {
|
|
11036
|
+
names.add(statement.declaration.id.name);
|
|
11037
|
+
}
|
|
11038
|
+
if (statement.declaration?.type === import_utils69.AST_NODE_TYPES.VariableDeclaration) {
|
|
11039
|
+
for (const declarator of statement.declaration.declarations) {
|
|
11040
|
+
if (declarator.id.type === import_utils69.AST_NODE_TYPES.Identifier) names.add(declarator.id.name);
|
|
11041
|
+
}
|
|
11042
|
+
}
|
|
11043
|
+
for (const specifier of statement.specifiers) {
|
|
11044
|
+
if (specifier.exportKind !== "type" && specifier.local.type === import_utils69.AST_NODE_TYPES.Identifier) {
|
|
11045
|
+
names.add(specifier.local.name);
|
|
11046
|
+
}
|
|
11047
|
+
}
|
|
11048
|
+
}
|
|
11049
|
+
for (const statement of program.body) {
|
|
11050
|
+
if (statement.type === import_utils69.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils69.AST_NODE_TYPES.Identifier) names.add(statement.declaration.name);
|
|
11051
|
+
if (statement.type === import_utils69.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils69.AST_NODE_TYPES.FunctionDeclaration && statement.declaration.id !== null) names.add(statement.declaration.id.name);
|
|
11052
|
+
}
|
|
11053
|
+
return names;
|
|
11054
|
+
}
|
|
11055
|
+
function moduleDefinitions(program) {
|
|
11056
|
+
const definitions = [];
|
|
11057
|
+
for (const statement of program.body) {
|
|
11058
|
+
const node = statement.type === import_utils69.AST_NODE_TYPES.ExportNamedDeclaration || statement.type === import_utils69.AST_NODE_TYPES.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
11059
|
+
if (node?.type === import_utils69.AST_NODE_TYPES.FunctionDeclaration && node.id !== null && node.body !== null) {
|
|
11060
|
+
definitions.push({ name: node.id.name, node, functionNode: node, bindingNode: node });
|
|
11061
|
+
continue;
|
|
11062
|
+
}
|
|
11063
|
+
if (node?.type !== import_utils69.AST_NODE_TYPES.VariableDeclaration || node.kind !== "const") continue;
|
|
11064
|
+
for (const declarator of node.declarations) {
|
|
11065
|
+
if (declarator.id.type === import_utils69.AST_NODE_TYPES.Identifier && declarator.init !== null && isFunction(declarator.init)) {
|
|
11066
|
+
definitions.push({
|
|
11067
|
+
name: declarator.id.name,
|
|
11068
|
+
node: declarator,
|
|
11069
|
+
functionNode: declarator.init,
|
|
11070
|
+
bindingNode: declarator
|
|
11071
|
+
});
|
|
11072
|
+
}
|
|
11073
|
+
}
|
|
11074
|
+
}
|
|
11075
|
+
return definitions;
|
|
11076
|
+
}
|
|
11077
|
+
function moduleScope(context, program) {
|
|
11078
|
+
const declarations = moduleDefinitions(program);
|
|
11079
|
+
const counts = /* @__PURE__ */ new Map();
|
|
11080
|
+
for (const node of declarations) counts.set(node.name, (counts.get(node.name) ?? 0) + 1);
|
|
11081
|
+
const overloadNames = new Set(
|
|
11082
|
+
program.body.flatMap((statement) => {
|
|
11083
|
+
const node = statement.type === import_utils69.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
11084
|
+
return node?.type === import_utils69.AST_NODE_TYPES.TSDeclareFunction && node.id !== null ? [node.id.name] : [];
|
|
11085
|
+
})
|
|
11086
|
+
);
|
|
11087
|
+
const exported = exportedNames(program);
|
|
11088
|
+
const scopeDefinitions = declarations.filter((node) => counts.get(node.name) === 1 && !overloadNames.has(node.name));
|
|
11089
|
+
const definitions = scopeDefinitions.filter((definition) => !exported.has(definition.name));
|
|
11090
|
+
const byFunction = new Map(scopeDefinitions.map((definition) => [definition.functionNode, definition]));
|
|
11091
|
+
const calls = /* @__PURE__ */ new Map();
|
|
11092
|
+
const pinned = /* @__PURE__ */ new Set();
|
|
11093
|
+
for (const definition of scopeDefinitions) {
|
|
11094
|
+
const variable = context.sourceCode.getDeclaredVariables(definition.bindingNode)[0];
|
|
11095
|
+
for (const reference of variable?.references ?? []) {
|
|
11096
|
+
if (reference.isWrite() && reference.init !== true) {
|
|
11097
|
+
pinned.add(definition.name);
|
|
11098
|
+
continue;
|
|
11099
|
+
}
|
|
11100
|
+
if (!reference.isRead()) continue;
|
|
11101
|
+
const identifier = reference.identifier;
|
|
11102
|
+
const ancestors = context.sourceCode.getAncestors(identifier);
|
|
11103
|
+
const nearestFunction = [...ancestors].reverse().find(isFunction);
|
|
11104
|
+
const parent = identifier.parent;
|
|
11105
|
+
const callerDefinition = nearestFunction === void 0 ? void 0 : byFunction.get(nearestFunction);
|
|
11106
|
+
if (callerDefinition === void 0 || parent.type !== import_utils69.AST_NODE_TYPES.CallExpression || parent.callee !== identifier) {
|
|
11107
|
+
pinned.add(definition.name);
|
|
11108
|
+
continue;
|
|
11109
|
+
}
|
|
11110
|
+
const caller = callerDefinition.name;
|
|
11111
|
+
const callees = calls.get(caller) ?? /* @__PURE__ */ new Set();
|
|
11112
|
+
callees.add(definition.name);
|
|
11113
|
+
calls.set(caller, callees);
|
|
11114
|
+
}
|
|
11115
|
+
}
|
|
11116
|
+
reportMisordered(context, definitions, scopeDefinitions, calls, pinned);
|
|
11117
|
+
}
|
|
11118
|
+
function methodName(node) {
|
|
11119
|
+
if (node.key.type === import_utils69.AST_NODE_TYPES.PrivateIdentifier) return `#${node.key.name}`;
|
|
11120
|
+
return !node.computed && node.key.type === import_utils69.AST_NODE_TYPES.Identifier ? node.key.name : null;
|
|
11121
|
+
}
|
|
11122
|
+
function referencedMethod(context, node, classVariables) {
|
|
11123
|
+
const objectVariable = node.object.type === import_utils69.AST_NODE_TYPES.Identifier ? import_utils69.ASTUtils.findVariable(context.sourceCode.getScope(node.object), node.object.name) : null;
|
|
11124
|
+
const isClassReference = objectVariable !== null && classVariables.has(objectVariable);
|
|
11125
|
+
if (node.object.type !== import_utils69.AST_NODE_TYPES.ThisExpression && !isClassReference) return null;
|
|
11126
|
+
if (node.property.type === import_utils69.AST_NODE_TYPES.PrivateIdentifier) return `#${node.property.name}`;
|
|
11127
|
+
if (!node.computed && node.property.type === import_utils69.AST_NODE_TYPES.Identifier) return node.property.name;
|
|
11128
|
+
return node.computed && node.property.type === import_utils69.AST_NODE_TYPES.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
11129
|
+
}
|
|
11130
|
+
function referencedPropertyName(node) {
|
|
11131
|
+
if (node.property.type === import_utils69.AST_NODE_TYPES.PrivateIdentifier) return `#${node.property.name}`;
|
|
11132
|
+
if (!node.computed && node.property.type === import_utils69.AST_NODE_TYPES.Identifier) return node.property.name;
|
|
11133
|
+
return node.computed && node.property.type === import_utils69.AST_NODE_TYPES.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
11134
|
+
}
|
|
11135
|
+
function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
11136
|
+
visit(node, nestedFunction);
|
|
11137
|
+
const nested = nestedFunction || isFunction(node);
|
|
11138
|
+
for (const key of visitorKeys[node.type] ?? []) {
|
|
11139
|
+
const child = node[key];
|
|
11140
|
+
if (Array.isArray(child)) {
|
|
11141
|
+
for (const item of child) if (typeof item === "object" && item !== null && "type" in item) walk(item, visitorKeys, visit, nested);
|
|
11142
|
+
} else if (typeof child === "object" && child !== null && "type" in child) {
|
|
11143
|
+
walk(child, visitorKeys, visit, nested);
|
|
11144
|
+
}
|
|
11145
|
+
}
|
|
11146
|
+
}
|
|
11147
|
+
function classScope(context, node, computedReferenceNames) {
|
|
11148
|
+
const methods = node.body.body.filter(
|
|
11149
|
+
(member) => member.type === import_utils69.AST_NODE_TYPES.MethodDefinition
|
|
11150
|
+
);
|
|
11151
|
+
const counts = /* @__PURE__ */ new Map();
|
|
11152
|
+
for (const method of methods) {
|
|
11153
|
+
const name = methodName(method);
|
|
11154
|
+
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
11155
|
+
}
|
|
11156
|
+
for (const member of node.body.body) {
|
|
11157
|
+
if (member.type !== import_utils69.AST_NODE_TYPES.TSAbstractMethodDefinition) continue;
|
|
11158
|
+
const name = !member.computed && member.key.type === import_utils69.AST_NODE_TYPES.Identifier ? member.key.name : null;
|
|
11159
|
+
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
11160
|
+
}
|
|
11161
|
+
const scopeDefinitions = methods.flatMap((method) => {
|
|
11162
|
+
const name = methodName(method);
|
|
11163
|
+
return name !== null && counts.get(name) === 1 ? [{ name, node: method }] : [];
|
|
11164
|
+
});
|
|
11165
|
+
const definitions = methods.flatMap((method) => {
|
|
11166
|
+
const name = methodName(method);
|
|
11167
|
+
const isPrivate = method.accessibility === "private" || method.key.type === import_utils69.AST_NODE_TYPES.PrivateIdentifier;
|
|
11168
|
+
return name !== null && isPrivate && counts.get(name) === 1 && method.decorators.length === 0 ? [{ name, node: method }] : [];
|
|
11169
|
+
});
|
|
11170
|
+
if (definitions.length === 0) return;
|
|
11171
|
+
const privateNames = new Set(definitions.map((definition) => definition.name));
|
|
11172
|
+
const calls = /* @__PURE__ */ new Map();
|
|
11173
|
+
const pinned = /* @__PURE__ */ new Set();
|
|
11174
|
+
const classVariables = /* @__PURE__ */ new Set();
|
|
11175
|
+
if (node.id !== null) {
|
|
11176
|
+
const internal = import_utils69.ASTUtils.findVariable(context.sourceCode.getScope(node), node.id.name);
|
|
11177
|
+
if (internal !== null) classVariables.add(internal);
|
|
11178
|
+
}
|
|
11179
|
+
if (node.type === import_utils69.AST_NODE_TYPES.ClassExpression && node.parent.type === import_utils69.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === import_utils69.AST_NODE_TYPES.Identifier) {
|
|
11180
|
+
const outer = import_utils69.ASTUtils.findVariable(context.sourceCode.getScope(node.parent), node.parent.id.name);
|
|
11181
|
+
if (outer !== null) classVariables.add(outer);
|
|
11182
|
+
}
|
|
11183
|
+
for (const method of methods) {
|
|
11184
|
+
const caller = methodName(method);
|
|
11185
|
+
if (caller === null || method.value.body === null) continue;
|
|
11186
|
+
const methodClassVariables = new Set(classVariables);
|
|
11187
|
+
const methodAliases = /* @__PURE__ */ new Set();
|
|
11188
|
+
const parameterDecoratorNodes = /* @__PURE__ */ new Set();
|
|
11189
|
+
for (const parameter of method.value.params) {
|
|
11190
|
+
for (const decorator of parameter.decorators) {
|
|
11191
|
+
walk(decorator, context.sourceCode.visitorKeys, (current) => parameterDecoratorNodes.add(current));
|
|
11192
|
+
}
|
|
11193
|
+
}
|
|
11194
|
+
const thisValue = (value) => {
|
|
11195
|
+
let current = value;
|
|
11196
|
+
while (current?.type === import_utils69.AST_NODE_TYPES.TSAsExpression || current?.type === import_utils69.AST_NODE_TYPES.TSSatisfiesExpression || current?.type === import_utils69.AST_NODE_TYPES.TSNonNullExpression) current = current.expression;
|
|
11197
|
+
return current?.type === import_utils69.AST_NODE_TYPES.ThisExpression;
|
|
11198
|
+
};
|
|
11199
|
+
const collectAlias = (current, nestedFunction) => {
|
|
11200
|
+
if (nestedFunction || current.type !== import_utils69.AST_NODE_TYPES.VariableDeclarator && current.type !== import_utils69.AST_NODE_TYPES.AssignmentPattern) return;
|
|
11201
|
+
if (current.type === import_utils69.AST_NODE_TYPES.VariableDeclarator && (current.parent.type !== import_utils69.AST_NODE_TYPES.VariableDeclaration || current.parent.kind !== "const")) return;
|
|
11202
|
+
const binding = current.type === import_utils69.AST_NODE_TYPES.VariableDeclarator ? current.id : current.left;
|
|
11203
|
+
const value = current.type === import_utils69.AST_NODE_TYPES.VariableDeclarator ? current.init : current.right;
|
|
11204
|
+
if (!thisValue(value)) return;
|
|
11205
|
+
if (binding.type === import_utils69.AST_NODE_TYPES.ObjectPattern) {
|
|
11206
|
+
for (const property of binding.properties) {
|
|
11207
|
+
if (property.type === import_utils69.AST_NODE_TYPES.RestElement) {
|
|
11208
|
+
for (const name of privateNames) pinned.add(name);
|
|
11209
|
+
} else if (property.key.type === import_utils69.AST_NODE_TYPES.Identifier && privateNames.has(property.key.name)) {
|
|
11210
|
+
pinned.add(property.key.name);
|
|
11211
|
+
}
|
|
11212
|
+
}
|
|
11213
|
+
return;
|
|
11214
|
+
}
|
|
11215
|
+
if (binding.type !== import_utils69.AST_NODE_TYPES.Identifier) return;
|
|
11216
|
+
const variable = import_utils69.ASTUtils.findVariable(context.sourceCode.getScope(binding), binding.name);
|
|
11217
|
+
if (variable !== null) {
|
|
11218
|
+
methodClassVariables.add(variable);
|
|
11219
|
+
methodAliases.add(variable);
|
|
11220
|
+
}
|
|
11221
|
+
};
|
|
11222
|
+
for (const parameter of method.value.params) {
|
|
11223
|
+
walk(parameter, context.sourceCode.visitorKeys, collectAlias);
|
|
11224
|
+
}
|
|
11225
|
+
for (const statement of method.value.body.body) {
|
|
11226
|
+
walk(statement, context.sourceCode.visitorKeys, collectAlias);
|
|
11227
|
+
}
|
|
11228
|
+
const visitCall = (current, nestedFunction) => {
|
|
11229
|
+
if (current.type === import_utils69.AST_NODE_TYPES.VariableDeclarator && current.id.type === import_utils69.AST_NODE_TYPES.ObjectPattern && thisValue(current.init)) {
|
|
11230
|
+
for (const property of current.id.properties) {
|
|
11231
|
+
if (property.type === import_utils69.AST_NODE_TYPES.RestElement) {
|
|
11232
|
+
for (const name of privateNames) pinned.add(name);
|
|
11233
|
+
continue;
|
|
11234
|
+
}
|
|
11235
|
+
if (property.type === import_utils69.AST_NODE_TYPES.Property && property.key.type === import_utils69.AST_NODE_TYPES.Identifier && privateNames.has(property.key.name)) pinned.add(property.key.name);
|
|
11236
|
+
}
|
|
11237
|
+
}
|
|
11238
|
+
if (current.type !== import_utils69.AST_NODE_TYPES.MemberExpression) return;
|
|
11239
|
+
const target = referencedMethod(context, current, methodClassVariables);
|
|
11240
|
+
if (target === null) {
|
|
11241
|
+
const possibleTarget = referencedPropertyName(current);
|
|
11242
|
+
if (possibleTarget !== null && privateNames.has(possibleTarget)) pinned.add(possibleTarget);
|
|
11243
|
+
return;
|
|
11244
|
+
}
|
|
11245
|
+
if (!privateNames.has(target)) return;
|
|
11246
|
+
const objectVariable = current.object.type === import_utils69.AST_NODE_TYPES.Identifier ? import_utils69.ASTUtils.findVariable(context.sourceCode.getScope(current.object), current.object.name) : null;
|
|
11247
|
+
if (objectVariable !== null && methodAliases.has(objectVariable)) {
|
|
11248
|
+
pinned.add(target);
|
|
11249
|
+
return;
|
|
11250
|
+
}
|
|
11251
|
+
if (current.computed || nestedFunction || parameterDecoratorNodes.has(current) || current.parent.type !== import_utils69.AST_NODE_TYPES.CallExpression || current.parent.callee !== current) {
|
|
11252
|
+
pinned.add(target);
|
|
11253
|
+
return;
|
|
11254
|
+
}
|
|
11255
|
+
const callees = calls.get(caller) ?? /* @__PURE__ */ new Set();
|
|
11256
|
+
callees.add(target);
|
|
11257
|
+
calls.set(caller, callees);
|
|
11258
|
+
};
|
|
11259
|
+
for (const decorator of method.decorators) {
|
|
11260
|
+
walk(decorator, context.sourceCode.visitorKeys, visitCall, true);
|
|
11261
|
+
}
|
|
11262
|
+
if (method.computed) walk(method.key, context.sourceCode.visitorKeys, visitCall, true);
|
|
11263
|
+
for (const parameter of method.value.params) {
|
|
11264
|
+
walk(parameter, context.sourceCode.visitorKeys, visitCall);
|
|
11265
|
+
}
|
|
11266
|
+
for (const statement of method.value.body.body) {
|
|
11267
|
+
walk(statement, context.sourceCode.visitorKeys, visitCall);
|
|
11268
|
+
}
|
|
11269
|
+
}
|
|
11270
|
+
for (const member of node.body.body) {
|
|
11271
|
+
if (member.type === import_utils69.AST_NODE_TYPES.MethodDefinition || member.type === import_utils69.AST_NODE_TYPES.TSAbstractMethodDefinition) continue;
|
|
11272
|
+
walk(member, context.sourceCode.visitorKeys, (current) => {
|
|
11273
|
+
if (current.type !== import_utils69.AST_NODE_TYPES.MemberExpression) return;
|
|
11274
|
+
const target = referencedMethod(context, current, classVariables);
|
|
11275
|
+
const possibleTarget = target ?? referencedPropertyName(current);
|
|
11276
|
+
if (possibleTarget !== null && privateNames.has(possibleTarget)) pinned.add(possibleTarget);
|
|
11277
|
+
});
|
|
11278
|
+
}
|
|
11279
|
+
for (const name of privateNames) if (computedReferenceNames.has(name)) pinned.add(name);
|
|
11280
|
+
const accessibility = new Map(
|
|
11281
|
+
scopeDefinitions.map((definition) => {
|
|
11282
|
+
const method = definition.node;
|
|
11283
|
+
const accessibility2 = method.key.type === import_utils69.AST_NODE_TYPES.PrivateIdentifier ? "private" : method.accessibility ?? "public";
|
|
11284
|
+
return [definition.name, accessibility2];
|
|
11285
|
+
})
|
|
11286
|
+
);
|
|
11287
|
+
for (const [caller, callees] of calls) {
|
|
11288
|
+
if (accessibility.get(caller) === "private") continue;
|
|
11289
|
+
for (const callee of callees) pinned.add(callee);
|
|
11290
|
+
}
|
|
11291
|
+
reportMisordered(context, definitions, scopeDefinitions, calls, pinned);
|
|
11292
|
+
}
|
|
11293
|
+
var stepdown_default = createRule({
|
|
11294
|
+
name: "stepdown",
|
|
11295
|
+
meta: {
|
|
11296
|
+
type: "suggestion",
|
|
11297
|
+
docs: { description: "Place a private helper below its sole direct same-scope caller." },
|
|
11298
|
+
schema: [],
|
|
11299
|
+
messages: {
|
|
11300
|
+
helperAboveOnlyCaller: "Private helper `{{helper}}` is defined above its only caller `{{caller}}`; move it below the caller."
|
|
11301
|
+
}
|
|
11302
|
+
},
|
|
11303
|
+
defaultOptions: [],
|
|
11304
|
+
create(context) {
|
|
11305
|
+
if (isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text)) return {};
|
|
11306
|
+
const classes = [];
|
|
11307
|
+
return {
|
|
11308
|
+
ClassDeclaration: (node) => {
|
|
11309
|
+
classes.push(node);
|
|
11310
|
+
},
|
|
11311
|
+
ClassExpression: (node) => {
|
|
11312
|
+
classes.push(node);
|
|
11313
|
+
},
|
|
11314
|
+
"Program:exit": (program) => {
|
|
11315
|
+
moduleScope(context, program);
|
|
11316
|
+
const computedReferenceNames = /* @__PURE__ */ new Set();
|
|
11317
|
+
walk(program, context.sourceCode.visitorKeys, (node) => {
|
|
11318
|
+
if (node.type === import_utils69.AST_NODE_TYPES.MemberExpression && node.computed && node.property.type === import_utils69.AST_NODE_TYPES.Literal && typeof node.property.value === "string") computedReferenceNames.add(node.property.value);
|
|
11319
|
+
});
|
|
11320
|
+
for (const node of classes) classScope(context, node, computedReferenceNames);
|
|
11321
|
+
}
|
|
11322
|
+
};
|
|
11323
|
+
}
|
|
11324
|
+
});
|
|
11325
|
+
|
|
10413
11326
|
// src/rules/zod-naming-convention.ts
|
|
10414
|
-
var
|
|
11327
|
+
var import_utils70 = require("@typescript-eslint/utils");
|
|
10415
11328
|
var CONVENTIONS = {
|
|
10416
11329
|
prefix: { test: ZOD_PREFIX_RE, messageId: "zPrefix" },
|
|
10417
11330
|
suffix: { test: ZOD_SUFFIX_RE, messageId: "schemaSuffix" },
|
|
@@ -10436,15 +11349,15 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
10436
11349
|
"registry",
|
|
10437
11350
|
"implement"
|
|
10438
11351
|
]);
|
|
10439
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
11352
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === import_utils70.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
10440
11353
|
var calleeChainStartsWithZ = (node) => {
|
|
10441
11354
|
let current = node;
|
|
10442
|
-
while (current.type ===
|
|
11355
|
+
while (current.type === import_utils70.AST_NODE_TYPES.MemberExpression) {
|
|
10443
11356
|
const receiver = current.object;
|
|
10444
|
-
if (receiver.type ===
|
|
11357
|
+
if (receiver.type === import_utils70.AST_NODE_TYPES.Identifier && receiver.name === "z") {
|
|
10445
11358
|
return true;
|
|
10446
11359
|
}
|
|
10447
|
-
if (receiver.type ===
|
|
11360
|
+
if (receiver.type === import_utils70.AST_NODE_TYPES.CallExpression) {
|
|
10448
11361
|
current = receiver.callee;
|
|
10449
11362
|
continue;
|
|
10450
11363
|
}
|
|
@@ -10489,13 +11402,13 @@ var zod_naming_convention_default = createRule({
|
|
|
10489
11402
|
VariableDeclarator(node) {
|
|
10490
11403
|
const init = node.init;
|
|
10491
11404
|
if (init === null || init === void 0) return;
|
|
10492
|
-
if (init.type !==
|
|
11405
|
+
if (init.type !== import_utils70.AST_NODE_TYPES.CallExpression) return;
|
|
10493
11406
|
const callee = init.callee;
|
|
10494
|
-
if (callee.type !==
|
|
11407
|
+
if (callee.type !== import_utils70.AST_NODE_TYPES.MemberExpression) return;
|
|
10495
11408
|
if (!calleeChainStartsWithZ(callee)) return;
|
|
10496
11409
|
const terminal = terminalMethodName(callee);
|
|
10497
11410
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
10498
|
-
if (node.id.type !==
|
|
11411
|
+
if (node.id.type !== import_utils70.AST_NODE_TYPES.Identifier) return;
|
|
10499
11412
|
if (test.test(node.id.name)) return;
|
|
10500
11413
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
10501
11414
|
context.report({
|
|
@@ -10580,6 +11493,7 @@ var rules = {
|
|
|
10580
11493
|
"no-json-stringify-error": no_json_stringify_error_default,
|
|
10581
11494
|
"no-log-only-catch": no_log_only_catch_default,
|
|
10582
11495
|
"no-long-comment": no_long_comment_default,
|
|
11496
|
+
"no-generic-single-export-module": no_generic_single_export_module_default,
|
|
10583
11497
|
"no-offset-pagination": no_offset_pagination_default,
|
|
10584
11498
|
"no-positional-tuple-return": no_positional_tuple_return_default,
|
|
10585
11499
|
"no-raw-env": no_raw_env_default,
|
|
@@ -10627,11 +11541,12 @@ var rules = {
|
|
|
10627
11541
|
"require-static-next-matcher": require_static_next_matcher_default,
|
|
10628
11542
|
"require-zod-form-validation": require_zod_form_validation_default,
|
|
10629
11543
|
"store-insert-requires-on-conflict": store_insert_requires_on_conflict_default,
|
|
11544
|
+
"stepdown": stepdown_default,
|
|
10630
11545
|
"zod-naming-convention": zod_naming_convention_default
|
|
10631
11546
|
};
|
|
10632
11547
|
var meta = {
|
|
10633
11548
|
name: "@sarj/eslint-plugin",
|
|
10634
|
-
version: "9.
|
|
11549
|
+
version: "9.14.0"
|
|
10635
11550
|
};
|
|
10636
11551
|
var applicationOnlyRules = [
|
|
10637
11552
|
"no-restricted-library-load",
|
|
@@ -10653,6 +11568,7 @@ var recommendedRules = {
|
|
|
10653
11568
|
"@sarj/no-json-stringify-error": "warn",
|
|
10654
11569
|
"@sarj/no-log-only-catch": "warn",
|
|
10655
11570
|
"@sarj/no-long-comment": "warn",
|
|
11571
|
+
"@sarj/no-generic-single-export-module": "warn",
|
|
10656
11572
|
"@sarj/no-offset-pagination": "warn",
|
|
10657
11573
|
"@sarj/no-positional-tuple-return": "warn",
|
|
10658
11574
|
"@sarj/no-repeated-string-literal": "warn",
|
|
@@ -10694,6 +11610,7 @@ var recommendedRules = {
|
|
|
10694
11610
|
"@sarj/require-static-next-matcher": "error",
|
|
10695
11611
|
"@sarj/require-zod-form-validation": "error",
|
|
10696
11612
|
"@sarj/store-insert-requires-on-conflict": "warn",
|
|
11613
|
+
"@sarj/stepdown": "warn",
|
|
10697
11614
|
"@sarj/zod-naming-convention": "warn"
|
|
10698
11615
|
};
|
|
10699
11616
|
var strictRules = {
|
|
@@ -10712,6 +11629,7 @@ var strictRules = {
|
|
|
10712
11629
|
"@sarj/no-json-stringify-error": "error",
|
|
10713
11630
|
"@sarj/no-log-only-catch": "error",
|
|
10714
11631
|
"@sarj/no-long-comment": "error",
|
|
11632
|
+
"@sarj/no-generic-single-export-module": "warn",
|
|
10715
11633
|
"@sarj/no-offset-pagination": "error",
|
|
10716
11634
|
"@sarj/no-positional-tuple-return": "error",
|
|
10717
11635
|
"@sarj/no-raw-env": "error",
|
|
@@ -10756,6 +11674,7 @@ var strictRules = {
|
|
|
10756
11674
|
"@sarj/require-static-next-matcher": "error",
|
|
10757
11675
|
"@sarj/require-zod-form-validation": "error",
|
|
10758
11676
|
"@sarj/store-insert-requires-on-conflict": "error",
|
|
11677
|
+
"@sarj/stepdown": "warn",
|
|
10759
11678
|
"@sarj/zod-naming-convention": "error"
|
|
10760
11679
|
};
|
|
10761
11680
|
var plugin = {
|