@sarj/eslint-plugin 9.7.1 → 9.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -2
- package/dist/index.cjs +894 -571
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +48 -2
- package/dist/index.d.ts +48 -2
- package/dist/index.js +877 -555
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2340,6 +2340,58 @@ var no_hand_rolled_sleep_default = createRule({
|
|
|
2340
2340
|
}
|
|
2341
2341
|
});
|
|
2342
2342
|
|
|
2343
|
+
// src/rules/no-hand-rolled-spinner.ts
|
|
2344
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES11 } from "@typescript-eslint/utils";
|
|
2345
|
+
var DESIGN_SYSTEM_PATH = /(?:^|[/\\])components[/\\]ui[/\\]/u;
|
|
2346
|
+
var BORDER_WIDTH = /^border(?:-[0-9]+)?$/u;
|
|
2347
|
+
var TRANSPARENT_EDGE = /^border-[trbl]-transparent$/u;
|
|
2348
|
+
function staticClassName(attribute) {
|
|
2349
|
+
const value = attribute.value;
|
|
2350
|
+
if (value?.type === AST_NODE_TYPES11.Literal && typeof value.value === "string") {
|
|
2351
|
+
return value.value;
|
|
2352
|
+
}
|
|
2353
|
+
if (value?.type === AST_NODE_TYPES11.JSXExpressionContainer && value.expression.type === AST_NODE_TYPES11.Literal && typeof value.expression.value === "string") {
|
|
2354
|
+
return value.expression.value;
|
|
2355
|
+
}
|
|
2356
|
+
return null;
|
|
2357
|
+
}
|
|
2358
|
+
var no_hand_rolled_spinner_default = createRule({
|
|
2359
|
+
name: "no-hand-rolled-spinner",
|
|
2360
|
+
meta: {
|
|
2361
|
+
type: "suggestion",
|
|
2362
|
+
docs: {
|
|
2363
|
+
description: "Disallow intrinsic elements styled as Tailwind border-ring spinners outside the design-system implementation."
|
|
2364
|
+
},
|
|
2365
|
+
schema: [],
|
|
2366
|
+
messages: {
|
|
2367
|
+
handRolledSpinner: "Use the design-system Spinner component instead of rebuilding a border-ring spinner with utility classes."
|
|
2368
|
+
}
|
|
2369
|
+
},
|
|
2370
|
+
defaultOptions: [],
|
|
2371
|
+
create(context) {
|
|
2372
|
+
if (DESIGN_SYSTEM_PATH.test(context.filename)) {
|
|
2373
|
+
return {};
|
|
2374
|
+
}
|
|
2375
|
+
return {
|
|
2376
|
+
JSXOpeningElement(node) {
|
|
2377
|
+
if (node.name.type !== AST_NODE_TYPES11.JSXIdentifier || node.name.name !== "div" && node.name.name !== "span") {
|
|
2378
|
+
return;
|
|
2379
|
+
}
|
|
2380
|
+
const classNameAttribute = node.attributes.find(
|
|
2381
|
+
(attribute) => attribute.type === AST_NODE_TYPES11.JSXAttribute && attribute.name.type === AST_NODE_TYPES11.JSXIdentifier && attribute.name.name === "className"
|
|
2382
|
+
);
|
|
2383
|
+
if (classNameAttribute === void 0) return;
|
|
2384
|
+
const className = staticClassName(classNameAttribute);
|
|
2385
|
+
if (className === null) return;
|
|
2386
|
+
const classes = className.split(/\s+/u);
|
|
2387
|
+
if (classes.includes("animate-spin") && classes.includes("rounded-full") && classes.some((token) => BORDER_WIDTH.test(token)) && classes.some((token) => TRANSPARENT_EDGE.test(token))) {
|
|
2388
|
+
context.report({ node, messageId: "handRolledSpinner" });
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
};
|
|
2392
|
+
}
|
|
2393
|
+
});
|
|
2394
|
+
|
|
2343
2395
|
// src/rules/no-insecure-random-id.ts
|
|
2344
2396
|
import "@typescript-eslint/utils";
|
|
2345
2397
|
var STRONG_SECURITY_PATTERN = /token|secret|csrf|password|passwd|apikey|api[-_]?key|nonce|salt|uuid|authid/i;
|
|
@@ -2706,7 +2758,7 @@ var no_json_stringify_error_default = createRule({
|
|
|
2706
2758
|
});
|
|
2707
2759
|
|
|
2708
2760
|
// src/rules/no-log-only-catch.ts
|
|
2709
|
-
import { AST_NODE_TYPES as
|
|
2761
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES12, ASTUtils } from "@typescript-eslint/utils";
|
|
2710
2762
|
|
|
2711
2763
|
// src/rules/_logging.ts
|
|
2712
2764
|
import "@typescript-eslint/utils";
|
|
@@ -2813,29 +2865,29 @@ function createLogMatcher(options = {}) {
|
|
|
2813
2865
|
// src/rules/no-log-only-catch.ts
|
|
2814
2866
|
var BENCHMARK_DIR_RE = /(?:^|[\\/])benchmarks?[\\/]/;
|
|
2815
2867
|
var SINGLE_STATEMENT_HOSTS = /* @__PURE__ */ new Set([
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2868
|
+
AST_NODE_TYPES12.DoWhileStatement,
|
|
2869
|
+
AST_NODE_TYPES12.ForInStatement,
|
|
2870
|
+
AST_NODE_TYPES12.ForOfStatement,
|
|
2871
|
+
AST_NODE_TYPES12.ForStatement,
|
|
2872
|
+
AST_NODE_TYPES12.IfStatement,
|
|
2873
|
+
AST_NODE_TYPES12.WhileStatement
|
|
2822
2874
|
]);
|
|
2823
2875
|
var FUNCTION_TYPES2 = /* @__PURE__ */ new Set([
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2876
|
+
AST_NODE_TYPES12.ArrowFunctionExpression,
|
|
2877
|
+
AST_NODE_TYPES12.FunctionDeclaration,
|
|
2878
|
+
AST_NODE_TYPES12.FunctionExpression
|
|
2827
2879
|
]);
|
|
2828
2880
|
function statementSlot(node) {
|
|
2829
2881
|
const parent = node.parent;
|
|
2830
2882
|
if (parent === void 0) return null;
|
|
2831
2883
|
let list;
|
|
2832
2884
|
switch (parent.type) {
|
|
2833
|
-
case
|
|
2834
|
-
case
|
|
2835
|
-
case
|
|
2885
|
+
case AST_NODE_TYPES12.BlockStatement:
|
|
2886
|
+
case AST_NODE_TYPES12.Program:
|
|
2887
|
+
case AST_NODE_TYPES12.StaticBlock:
|
|
2836
2888
|
list = parent.body;
|
|
2837
2889
|
break;
|
|
2838
|
-
case
|
|
2890
|
+
case AST_NODE_TYPES12.SwitchCase:
|
|
2839
2891
|
list = parent.consequent;
|
|
2840
2892
|
break;
|
|
2841
2893
|
default:
|
|
@@ -2854,20 +2906,20 @@ function hasFollowingStatement(node) {
|
|
|
2854
2906
|
function fallbackFollowsTry(tryStatement) {
|
|
2855
2907
|
const body2 = tryStatement.block.body;
|
|
2856
2908
|
const last = body2.at(-1);
|
|
2857
|
-
return last?.type ===
|
|
2909
|
+
return last?.type === AST_NODE_TYPES12.ReturnStatement && hasFollowingStatement(tryStatement);
|
|
2858
2910
|
}
|
|
2859
2911
|
function isSeedValue(node) {
|
|
2860
|
-
const inner = node.type ===
|
|
2912
|
+
const inner = node.type === AST_NODE_TYPES12.TSAsExpression ? node.expression : node;
|
|
2861
2913
|
switch (inner.type) {
|
|
2862
|
-
case
|
|
2914
|
+
case AST_NODE_TYPES12.Literal:
|
|
2863
2915
|
return true;
|
|
2864
|
-
case
|
|
2916
|
+
case AST_NODE_TYPES12.Identifier:
|
|
2865
2917
|
return inner.name === "undefined";
|
|
2866
|
-
case
|
|
2867
|
-
return inner.argument.type ===
|
|
2868
|
-
case
|
|
2918
|
+
case AST_NODE_TYPES12.UnaryExpression:
|
|
2919
|
+
return inner.argument.type === AST_NODE_TYPES12.Literal;
|
|
2920
|
+
case AST_NODE_TYPES12.ArrayExpression:
|
|
2869
2921
|
return inner.elements.length === 0;
|
|
2870
|
-
case
|
|
2922
|
+
case AST_NODE_TYPES12.ObjectExpression:
|
|
2871
2923
|
return inner.properties.length === 0;
|
|
2872
2924
|
default:
|
|
2873
2925
|
return false;
|
|
@@ -2877,12 +2929,12 @@ function seededFallbackHandled(tryStatement, scope) {
|
|
|
2877
2929
|
const slot = statementSlot(tryStatement);
|
|
2878
2930
|
if (slot === null || slot.index === 0) return false;
|
|
2879
2931
|
const previous = slot.list[slot.index - 1];
|
|
2880
|
-
if (previous?.type !==
|
|
2932
|
+
if (previous?.type !== AST_NODE_TYPES12.VariableDeclaration || previous.kind === "const") {
|
|
2881
2933
|
return false;
|
|
2882
2934
|
}
|
|
2883
2935
|
const declarator = previous.declarations[0];
|
|
2884
2936
|
if (previous.declarations.length !== 1 || declarator === void 0) return false;
|
|
2885
|
-
if (declarator.id.type !==
|
|
2937
|
+
if (declarator.id.type !== AST_NODE_TYPES12.Identifier) return false;
|
|
2886
2938
|
if (declarator.init == null || !isSeedValue(declarator.init)) return false;
|
|
2887
2939
|
const variable = ASTUtils.findVariable(scope, declarator.id.name);
|
|
2888
2940
|
if (variable === null) return false;
|
|
@@ -2934,7 +2986,7 @@ var no_log_only_catch_default = createRule({
|
|
|
2934
2986
|
const tryStatement = node.parent;
|
|
2935
2987
|
if (hasCommentDirectlyAbove(tryStatement) || hasCommentDirectlyAbove(node)) return true;
|
|
2936
2988
|
const block = tryStatement.parent;
|
|
2937
|
-
if (block?.type !==
|
|
2989
|
+
if (block?.type !== AST_NODE_TYPES12.BlockStatement || block.body.length !== 1 || block.parent === void 0 || !SINGLE_STATEMENT_HOSTS.has(block.parent.type)) {
|
|
2938
2990
|
return false;
|
|
2939
2991
|
}
|
|
2940
2992
|
return hasCommentDirectlyAbove(block.parent);
|
|
@@ -2971,7 +3023,7 @@ var no_log_only_catch_default = createRule({
|
|
|
2971
3023
|
});
|
|
2972
3024
|
|
|
2973
3025
|
// src/rules/_prose-budget.ts
|
|
2974
|
-
import { AST_NODE_TYPES as
|
|
3026
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES13 } from "@typescript-eslint/utils";
|
|
2975
3027
|
var DIRECTIVE_RE2 = /^(?:!|eslint\b|eslint-|@ts-|prettier|biome-|c8\b|v8\b|istanbul\b|@vite|webpack|@jsx|@jest-environment|@vitest-environment|#__|todo\b|fixme\b|hack\b)/i;
|
|
2976
3028
|
var LICENSE_RE2 = /\b(?:copyright|spdx-license-identifier|licensed under)\b/i;
|
|
2977
3029
|
var TYPED_TAG_RE = /@(arg|argument|param|return|returns|yield|yields)\b/i;
|
|
@@ -3027,25 +3079,25 @@ function proseGroups(filename, sourceCode, includeValueTags = false) {
|
|
|
3027
3079
|
return groups;
|
|
3028
3080
|
}
|
|
3029
3081
|
function annotatedParameter(parameter) {
|
|
3030
|
-
if (parameter.type ===
|
|
3031
|
-
const target = parameter.type ===
|
|
3082
|
+
if (parameter.type === AST_NODE_TYPES13.TSParameterProperty) return annotatedParameter(parameter.parameter);
|
|
3083
|
+
const target = parameter.type === AST_NODE_TYPES13.AssignmentPattern ? parameter.left : parameter;
|
|
3032
3084
|
return "typeAnnotation" in target && target.typeAnnotation != null;
|
|
3033
3085
|
}
|
|
3034
3086
|
function typedFunction(node) {
|
|
3035
3087
|
switch (node.type) {
|
|
3036
|
-
case
|
|
3037
|
-
case
|
|
3088
|
+
case AST_NODE_TYPES13.ExportNamedDeclaration:
|
|
3089
|
+
case AST_NODE_TYPES13.ExportDefaultDeclaration:
|
|
3038
3090
|
return node.declaration != null && typedFunction(node.declaration);
|
|
3039
|
-
case
|
|
3040
|
-
case
|
|
3091
|
+
case AST_NODE_TYPES13.FunctionDeclaration:
|
|
3092
|
+
case AST_NODE_TYPES13.TSDeclareFunction:
|
|
3041
3093
|
return node.returnType != null && node.params.every(annotatedParameter);
|
|
3042
|
-
case
|
|
3094
|
+
case AST_NODE_TYPES13.VariableDeclaration: {
|
|
3043
3095
|
const init = node.declarations[0]?.init;
|
|
3044
|
-
return init != null && (init.type ===
|
|
3096
|
+
return init != null && (init.type === AST_NODE_TYPES13.ArrowFunctionExpression || init.type === AST_NODE_TYPES13.FunctionExpression) && init.returnType != null && init.params.every(annotatedParameter);
|
|
3045
3097
|
}
|
|
3046
|
-
case
|
|
3098
|
+
case AST_NODE_TYPES13.MethodDefinition:
|
|
3047
3099
|
return node.value.returnType != null && node.value.params.every(annotatedParameter);
|
|
3048
|
-
case
|
|
3100
|
+
case AST_NODE_TYPES13.TSMethodSignature:
|
|
3049
3101
|
return node.returnType != null && node.params.every(annotatedParameter);
|
|
3050
3102
|
default:
|
|
3051
3103
|
return false;
|
|
@@ -3055,7 +3107,7 @@ function documentsTypedFunction(sourceCode, comment) {
|
|
|
3055
3107
|
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
3056
3108
|
if (token === null || token.loc.start.line !== comment.loc.end.line + 1) return false;
|
|
3057
3109
|
let node = sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
3058
|
-
while (node != null && node.type !==
|
|
3110
|
+
while (node != null && node.type !== AST_NODE_TYPES13.Program) {
|
|
3059
3111
|
if (typedFunction(node)) return true;
|
|
3060
3112
|
node = node.parent ?? null;
|
|
3061
3113
|
}
|
|
@@ -3118,15 +3170,15 @@ var no_offset_pagination_default = createRule({
|
|
|
3118
3170
|
});
|
|
3119
3171
|
|
|
3120
3172
|
// src/rules/no-positional-tuple-return.ts
|
|
3121
|
-
import { AST_NODE_TYPES as
|
|
3173
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES14 } from "@typescript-eslint/utils";
|
|
3122
3174
|
var MIN_ELEMENTS = 2;
|
|
3123
3175
|
var ACCESSOR_PAIR_LENGTH = 2;
|
|
3124
3176
|
var AWAITABLE_TYPES = /* @__PURE__ */ new Set(["Promise", "PromiseLike", "Awaited"]);
|
|
3125
3177
|
function tupleReturnType(node) {
|
|
3126
|
-
if (node.type ===
|
|
3178
|
+
if (node.type === AST_NODE_TYPES14.TSTupleType) {
|
|
3127
3179
|
return node;
|
|
3128
3180
|
}
|
|
3129
|
-
if (node.type ===
|
|
3181
|
+
if (node.type === AST_NODE_TYPES14.TSTypeReference && node.typeName.type === AST_NODE_TYPES14.Identifier && AWAITABLE_TYPES.has(node.typeName.name)) {
|
|
3130
3182
|
const argument = node.typeArguments?.params[0];
|
|
3131
3183
|
return argument === void 0 ? null : tupleReturnType(argument);
|
|
3132
3184
|
}
|
|
@@ -3140,30 +3192,30 @@ function isPermittedTuple(tuple, sourceCode) {
|
|
|
3140
3192
|
if (elements.length < MIN_ELEMENTS) {
|
|
3141
3193
|
return true;
|
|
3142
3194
|
}
|
|
3143
|
-
if (elements.some((element) => element.type ===
|
|
3195
|
+
if (elements.some((element) => element.type === AST_NODE_TYPES14.TSRestType)) {
|
|
3144
3196
|
return true;
|
|
3145
3197
|
}
|
|
3146
|
-
if (elements.some((element) => element.type ===
|
|
3198
|
+
if (elements.some((element) => element.type === AST_NODE_TYPES14.TSNamedTupleMember)) {
|
|
3147
3199
|
return true;
|
|
3148
3200
|
}
|
|
3149
|
-
if (elements[0]?.type ===
|
|
3201
|
+
if (elements[0]?.type === AST_NODE_TYPES14.TSLiteralType) {
|
|
3150
3202
|
return true;
|
|
3151
3203
|
}
|
|
3152
|
-
if (elements.length === ACCESSOR_PAIR_LENGTH && elements.some((element) => element.type ===
|
|
3204
|
+
if (elements.length === ACCESSOR_PAIR_LENGTH && elements.some((element) => element.type === AST_NODE_TYPES14.TSFunctionType)) {
|
|
3153
3205
|
return true;
|
|
3154
3206
|
}
|
|
3155
3207
|
const texts = new Set(elements.map((element) => normalizedText(sourceCode, element)));
|
|
3156
3208
|
return texts.size === 1;
|
|
3157
3209
|
}
|
|
3158
3210
|
function functionName(node) {
|
|
3159
|
-
if (node.type ===
|
|
3211
|
+
if (node.type === AST_NODE_TYPES14.FunctionDeclaration) {
|
|
3160
3212
|
return node.id?.name ?? null;
|
|
3161
3213
|
}
|
|
3162
3214
|
const parent = node.parent;
|
|
3163
|
-
if (parent?.type ===
|
|
3215
|
+
if (parent?.type === AST_NODE_TYPES14.VariableDeclarator && parent.id.type === AST_NODE_TYPES14.Identifier) {
|
|
3164
3216
|
return parent.id.name;
|
|
3165
3217
|
}
|
|
3166
|
-
if ((parent?.type ===
|
|
3218
|
+
if ((parent?.type === AST_NODE_TYPES14.MethodDefinition || parent?.type === AST_NODE_TYPES14.PropertyDefinition || parent?.type === AST_NODE_TYPES14.Property) && parent.key.type === AST_NODE_TYPES14.Identifier) {
|
|
3167
3219
|
return parent.key.name;
|
|
3168
3220
|
}
|
|
3169
3221
|
return null;
|
|
@@ -3171,7 +3223,7 @@ function functionName(node) {
|
|
|
3171
3223
|
function isInlineExported(node) {
|
|
3172
3224
|
for (let current = node; current != null; current = current.parent) {
|
|
3173
3225
|
const parent = current.parent;
|
|
3174
|
-
if (parent?.type ===
|
|
3226
|
+
if (parent?.type === AST_NODE_TYPES14.ExportNamedDeclaration || parent?.type === AST_NODE_TYPES14.ExportDefaultDeclaration) {
|
|
3175
3227
|
return true;
|
|
3176
3228
|
}
|
|
3177
3229
|
}
|
|
@@ -3180,18 +3232,18 @@ function isInlineExported(node) {
|
|
|
3180
3232
|
function moduleScopeBindingName(node) {
|
|
3181
3233
|
let current = node;
|
|
3182
3234
|
let child = node;
|
|
3183
|
-
while (current.parent != null && current.parent.type !==
|
|
3235
|
+
while (current.parent != null && current.parent.type !== AST_NODE_TYPES14.Program) {
|
|
3184
3236
|
child = current;
|
|
3185
3237
|
current = current.parent;
|
|
3186
3238
|
}
|
|
3187
|
-
if (current.parent?.type !==
|
|
3239
|
+
if (current.parent?.type !== AST_NODE_TYPES14.Program) {
|
|
3188
3240
|
return null;
|
|
3189
3241
|
}
|
|
3190
|
-
if (current.type ===
|
|
3242
|
+
if (current.type === AST_NODE_TYPES14.FunctionDeclaration || current.type === AST_NODE_TYPES14.ClassDeclaration) {
|
|
3191
3243
|
return current.id?.name ?? null;
|
|
3192
3244
|
}
|
|
3193
|
-
if (current.type ===
|
|
3194
|
-
if (child.type !==
|
|
3245
|
+
if (current.type === AST_NODE_TYPES14.VariableDeclaration) {
|
|
3246
|
+
if (child.type !== AST_NODE_TYPES14.VariableDeclarator || child.id.type !== AST_NODE_TYPES14.Identifier) {
|
|
3195
3247
|
return null;
|
|
3196
3248
|
}
|
|
3197
3249
|
return child.id.name;
|
|
@@ -3201,19 +3253,19 @@ function moduleScopeBindingName(node) {
|
|
|
3201
3253
|
function specifierExportedNames(program) {
|
|
3202
3254
|
const names = /* @__PURE__ */ new Set();
|
|
3203
3255
|
for (const statement of program.body) {
|
|
3204
|
-
if (statement.type ===
|
|
3256
|
+
if (statement.type === AST_NODE_TYPES14.ExportNamedDeclaration && statement.declaration == null && statement.source == null && statement.exportKind !== "type") {
|
|
3205
3257
|
for (const specifier of statement.specifiers) {
|
|
3206
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
3258
|
+
if (specifier.exportKind !== "type" && specifier.local.type === AST_NODE_TYPES14.Identifier) {
|
|
3207
3259
|
names.add(specifier.local.name);
|
|
3208
3260
|
}
|
|
3209
3261
|
}
|
|
3210
3262
|
continue;
|
|
3211
3263
|
}
|
|
3212
|
-
if (statement.type ===
|
|
3264
|
+
if (statement.type === AST_NODE_TYPES14.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES14.Identifier) {
|
|
3213
3265
|
names.add(statement.declaration.name);
|
|
3214
3266
|
continue;
|
|
3215
3267
|
}
|
|
3216
|
-
if (statement.type ===
|
|
3268
|
+
if (statement.type === AST_NODE_TYPES14.TSExportAssignment && statement.expression.type === AST_NODE_TYPES14.Identifier) {
|
|
3217
3269
|
names.add(statement.expression.name);
|
|
3218
3270
|
}
|
|
3219
3271
|
}
|
|
@@ -3352,7 +3404,7 @@ var no_raw_env_default = createRule({
|
|
|
3352
3404
|
});
|
|
3353
3405
|
|
|
3354
3406
|
// src/rules/no-raw-fetch-outside-clients.ts
|
|
3355
|
-
import { AST_NODE_TYPES as
|
|
3407
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES15 } from "@typescript-eslint/utils";
|
|
3356
3408
|
var DEFAULT_ALLOW = [
|
|
3357
3409
|
"[\\\\/]clients?[\\\\/]",
|
|
3358
3410
|
"-client\\.[cm]?[jt]sx?$",
|
|
@@ -3394,7 +3446,7 @@ function identifierLikeName(node) {
|
|
|
3394
3446
|
}
|
|
3395
3447
|
function isConstructedArgumentHandoff(node) {
|
|
3396
3448
|
const [first] = node.arguments;
|
|
3397
|
-
return node.arguments.length === 1 && first !== void 0 && first.type ===
|
|
3449
|
+
return node.arguments.length === 1 && first !== void 0 && first.type === AST_NODE_TYPES15.NewExpression;
|
|
3398
3450
|
}
|
|
3399
3451
|
function isPresignedUrlTransfer(node) {
|
|
3400
3452
|
const first = node.arguments[0];
|
|
@@ -3462,17 +3514,110 @@ var no_raw_fetch_outside_clients_default = createRule({
|
|
|
3462
3514
|
}
|
|
3463
3515
|
});
|
|
3464
3516
|
|
|
3517
|
+
// src/rules/no-restricted-library-load.ts
|
|
3518
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES16, ASTUtils as ASTUtils2 } from "@typescript-eslint/utils";
|
|
3519
|
+
function literalModule(node) {
|
|
3520
|
+
return node?.type === AST_NODE_TYPES16.Literal && typeof node.value === "string" ? node.value : null;
|
|
3521
|
+
}
|
|
3522
|
+
function matchesModule(source, module) {
|
|
3523
|
+
return source === module || source.startsWith(`${module}/`);
|
|
3524
|
+
}
|
|
3525
|
+
var no_restricted_library_load_default = createRule({
|
|
3526
|
+
name: "no-restricted-library-load",
|
|
3527
|
+
meta: {
|
|
3528
|
+
type: "problem",
|
|
3529
|
+
docs: {
|
|
3530
|
+
description: "Apply a configured library-replacement policy to literal dynamic imports, CommonJS loads, and TypeScript import-equals declarations."
|
|
3531
|
+
},
|
|
3532
|
+
schema: [
|
|
3533
|
+
{
|
|
3534
|
+
type: "object",
|
|
3535
|
+
additionalProperties: false,
|
|
3536
|
+
required: ["libraries"],
|
|
3537
|
+
properties: {
|
|
3538
|
+
libraries: {
|
|
3539
|
+
type: "array",
|
|
3540
|
+
items: {
|
|
3541
|
+
type: "object",
|
|
3542
|
+
additionalProperties: false,
|
|
3543
|
+
required: ["id", "module", "replacement"],
|
|
3544
|
+
properties: {
|
|
3545
|
+
id: { type: "string", minLength: 1 },
|
|
3546
|
+
module: { type: "string", minLength: 1 },
|
|
3547
|
+
replacement: { type: "string", minLength: 1 },
|
|
3548
|
+
note: { type: "string", minLength: 1 }
|
|
3549
|
+
}
|
|
3550
|
+
}
|
|
3551
|
+
}
|
|
3552
|
+
}
|
|
3553
|
+
}
|
|
3554
|
+
],
|
|
3555
|
+
messages: {
|
|
3556
|
+
restrictedLibraryLoad: "{{id}}: Replace runtime loading of {{module}} with {{replacement}}.{{note}}"
|
|
3557
|
+
}
|
|
3558
|
+
},
|
|
3559
|
+
defaultOptions: [{ libraries: [] }],
|
|
3560
|
+
create(context, [options]) {
|
|
3561
|
+
const restrictions = options.libraries;
|
|
3562
|
+
function report(node, source) {
|
|
3563
|
+
const restriction = restrictions.find(
|
|
3564
|
+
(entry) => matchesModule(source, entry.module)
|
|
3565
|
+
);
|
|
3566
|
+
if (restriction === void 0) return;
|
|
3567
|
+
context.report({
|
|
3568
|
+
node,
|
|
3569
|
+
messageId: "restrictedLibraryLoad",
|
|
3570
|
+
data: {
|
|
3571
|
+
id: restriction.id,
|
|
3572
|
+
module: restriction.module,
|
|
3573
|
+
replacement: restriction.replacement,
|
|
3574
|
+
note: restriction.note === void 0 ? "" : ` ${restriction.note}`
|
|
3575
|
+
}
|
|
3576
|
+
});
|
|
3577
|
+
}
|
|
3578
|
+
function isUnshadowedRequire(node) {
|
|
3579
|
+
const variable = ASTUtils2.findVariable(
|
|
3580
|
+
context.sourceCode.getScope(node),
|
|
3581
|
+
node.name
|
|
3582
|
+
);
|
|
3583
|
+
return variable === null || variable.defs.length === 0;
|
|
3584
|
+
}
|
|
3585
|
+
return {
|
|
3586
|
+
ImportExpression(node) {
|
|
3587
|
+
const source = literalModule(node.source);
|
|
3588
|
+
if (source !== null) report(node.source, source);
|
|
3589
|
+
},
|
|
3590
|
+
CallExpression(node) {
|
|
3591
|
+
let requireIdentifier = null;
|
|
3592
|
+
if (node.callee.type === AST_NODE_TYPES16.Identifier && node.callee.name === "require") {
|
|
3593
|
+
requireIdentifier = node.callee;
|
|
3594
|
+
} else if (node.callee.type === AST_NODE_TYPES16.MemberExpression && !node.callee.computed && node.callee.object.type === AST_NODE_TYPES16.Identifier && node.callee.object.name === "require" && node.callee.property.type === AST_NODE_TYPES16.Identifier && node.callee.property.name === "resolve") {
|
|
3595
|
+
requireIdentifier = node.callee.object;
|
|
3596
|
+
}
|
|
3597
|
+
if (requireIdentifier === null || !isUnshadowedRequire(requireIdentifier)) return;
|
|
3598
|
+
const source = literalModule(node.arguments[0]);
|
|
3599
|
+
if (source !== null) report(node.arguments[0], source);
|
|
3600
|
+
},
|
|
3601
|
+
TSImportEqualsDeclaration(node) {
|
|
3602
|
+
if (node.moduleReference.type !== AST_NODE_TYPES16.TSExternalModuleReference) return;
|
|
3603
|
+
const source = literalModule(node.moduleReference.expression);
|
|
3604
|
+
if (source !== null) report(node.moduleReference.expression, source);
|
|
3605
|
+
}
|
|
3606
|
+
};
|
|
3607
|
+
}
|
|
3608
|
+
});
|
|
3609
|
+
|
|
3465
3610
|
// src/rules/no-repeated-string-literal.ts
|
|
3466
|
-
import { AST_NODE_TYPES as
|
|
3611
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES17 } from "@typescript-eslint/utils";
|
|
3467
3612
|
var MIN_LENGTH = 40;
|
|
3468
3613
|
var MIN_DISTINCT_SCOPES = 2;
|
|
3469
3614
|
var PREVIEW_LENGTH = 40;
|
|
3470
3615
|
var SQL_KEYWORD_RE = /\b(SELECT|INSERT|UPDATE|DELETE|FROM|WHERE|JOIN|VALUES|ON CONFLICT|RETURNING|GROUP BY|ORDER BY)\b/;
|
|
3471
3616
|
var IDENTIFIER_RE = /^[a-z_][a-z0-9_.]*$/;
|
|
3472
3617
|
var FUNCTION_TYPES3 = /* @__PURE__ */ new Set([
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3618
|
+
AST_NODE_TYPES17.FunctionDeclaration,
|
|
3619
|
+
AST_NODE_TYPES17.FunctionExpression,
|
|
3620
|
+
AST_NODE_TYPES17.ArrowFunctionExpression
|
|
3476
3621
|
]);
|
|
3477
3622
|
function isStructured(value) {
|
|
3478
3623
|
return value.includes("\n") || SQL_KEYWORD_RE.test(value) || IDENTIFIER_RE.test(value);
|
|
@@ -3494,8 +3639,8 @@ function isScaffolding(node) {
|
|
|
3494
3639
|
if (parent === void 0) {
|
|
3495
3640
|
return true;
|
|
3496
3641
|
}
|
|
3497
|
-
const isRequireSource = parent.type ===
|
|
3498
|
-
return parent.type ===
|
|
3642
|
+
const isRequireSource = parent.type === AST_NODE_TYPES17.CallExpression && parent.callee.type === AST_NODE_TYPES17.Identifier && parent.callee.name === "require";
|
|
3643
|
+
return parent.type === AST_NODE_TYPES17.ImportDeclaration || parent.type === AST_NODE_TYPES17.ImportExpression || parent.type === AST_NODE_TYPES17.ExportNamedDeclaration || parent.type === AST_NODE_TYPES17.ExportAllDeclaration || parent.type === AST_NODE_TYPES17.TSImportType || parent.type === AST_NODE_TYPES17.JSXAttribute || parent.type === AST_NODE_TYPES17.TSLiteralType || isRequireSource;
|
|
3499
3644
|
}
|
|
3500
3645
|
var no_repeated_string_literal_default = createRule({
|
|
3501
3646
|
name: "no-repeated-string-literal",
|
|
@@ -3535,7 +3680,7 @@ var no_repeated_string_literal_default = createRule({
|
|
|
3535
3680
|
}
|
|
3536
3681
|
},
|
|
3537
3682
|
TemplateLiteral(node) {
|
|
3538
|
-
if (node.parent.type ===
|
|
3683
|
+
if (node.parent.type === AST_NODE_TYPES17.TaggedTemplateExpression) {
|
|
3539
3684
|
return;
|
|
3540
3685
|
}
|
|
3541
3686
|
const [only] = node.quasis;
|
|
@@ -3569,7 +3714,7 @@ var no_repeated_string_literal_default = createRule({
|
|
|
3569
3714
|
});
|
|
3570
3715
|
|
|
3571
3716
|
// src/rules/no-restated-comment.ts
|
|
3572
|
-
import { AST_NODE_TYPES as
|
|
3717
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES18 } from "@typescript-eslint/utils";
|
|
3573
3718
|
var MAX_WORDS = 8;
|
|
3574
3719
|
var MIN_CONTENT_TOKENS = 2;
|
|
3575
3720
|
var DIRECTIVE_RE3 = /^(eslint\b|eslint-|sarj-noqa\b|@ts-|prettier-ignore|prettier\b|biome-|c8\b|v8\b|istanbul\b|@type\b|@vite|webpack|<reference|<amd|global\b|noinspection|todo\b|fixme\b|hack\b|xxx\b)/i;
|
|
@@ -3622,7 +3767,7 @@ var no_restated_comment_default = createRule({
|
|
|
3622
3767
|
function labelsASiblingRun(comment) {
|
|
3623
3768
|
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
3624
3769
|
if (token === null) return false;
|
|
3625
|
-
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !==
|
|
3770
|
+
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !== AST_NODE_TYPES18.Program; node = node.parent) {
|
|
3626
3771
|
if (headsSiblingRun(node)) return true;
|
|
3627
3772
|
}
|
|
3628
3773
|
return false;
|
|
@@ -3682,7 +3827,7 @@ var no_restated_comment_default = createRule({
|
|
|
3682
3827
|
});
|
|
3683
3828
|
|
|
3684
3829
|
// src/rules/no-restated-jsdoc.ts
|
|
3685
|
-
import { AST_NODE_TYPES as
|
|
3830
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES19 } from "@typescript-eslint/utils";
|
|
3686
3831
|
var MODELLED_TAGS = /* @__PURE__ */ new Set([
|
|
3687
3832
|
"arg",
|
|
3688
3833
|
"argument",
|
|
@@ -3736,30 +3881,30 @@ function declarationNames(node) {
|
|
|
3736
3881
|
switch (node.type) {
|
|
3737
3882
|
// `export function f()` — the JSDoc sits above the `export`, so the token
|
|
3738
3883
|
// after it resolves to the wrapper, not to the thing being documented.
|
|
3739
|
-
case
|
|
3740
|
-
case
|
|
3884
|
+
case AST_NODE_TYPES19.ExportNamedDeclaration:
|
|
3885
|
+
case AST_NODE_TYPES19.ExportDefaultDeclaration:
|
|
3741
3886
|
return node.declaration == null ? null : declarationNames(node.declaration);
|
|
3742
|
-
case
|
|
3743
|
-
case
|
|
3887
|
+
case AST_NODE_TYPES19.FunctionDeclaration:
|
|
3888
|
+
case AST_NODE_TYPES19.TSDeclareFunction:
|
|
3744
3889
|
return node.id === null ? null : { name: node.id.name, params: paramNames(node.params) };
|
|
3745
|
-
case
|
|
3746
|
-
case
|
|
3747
|
-
case
|
|
3748
|
-
case
|
|
3890
|
+
case AST_NODE_TYPES19.ClassDeclaration:
|
|
3891
|
+
case AST_NODE_TYPES19.TSInterfaceDeclaration:
|
|
3892
|
+
case AST_NODE_TYPES19.TSTypeAliasDeclaration:
|
|
3893
|
+
case AST_NODE_TYPES19.TSEnumDeclaration:
|
|
3749
3894
|
return node.id === null ? null : { name: node.id.name, params: [] };
|
|
3750
|
-
case
|
|
3895
|
+
case AST_NODE_TYPES19.VariableDeclaration: {
|
|
3751
3896
|
const declarator = node.declarations[0];
|
|
3752
|
-
if (declarator === void 0 || declarator.id.type !==
|
|
3897
|
+
if (declarator === void 0 || declarator.id.type !== AST_NODE_TYPES19.Identifier) return null;
|
|
3753
3898
|
const init = declarator.init;
|
|
3754
|
-
const params = init != null && (init.type ===
|
|
3899
|
+
const params = init != null && (init.type === AST_NODE_TYPES19.ArrowFunctionExpression || init.type === AST_NODE_TYPES19.FunctionExpression) ? paramNames(init.params) : [];
|
|
3755
3900
|
return { name: declarator.id.name, params };
|
|
3756
3901
|
}
|
|
3757
|
-
case
|
|
3758
|
-
case
|
|
3759
|
-
case
|
|
3760
|
-
case
|
|
3761
|
-
if (node.key.type !==
|
|
3762
|
-
const params = node.type ===
|
|
3902
|
+
case AST_NODE_TYPES19.MethodDefinition:
|
|
3903
|
+
case AST_NODE_TYPES19.PropertyDefinition:
|
|
3904
|
+
case AST_NODE_TYPES19.TSMethodSignature:
|
|
3905
|
+
case AST_NODE_TYPES19.TSPropertySignature: {
|
|
3906
|
+
if (node.key.type !== AST_NODE_TYPES19.Identifier) return null;
|
|
3907
|
+
const params = node.type === AST_NODE_TYPES19.MethodDefinition ? paramNames(node.value.params) : node.type === AST_NODE_TYPES19.TSMethodSignature ? paramNames(node.params) : [];
|
|
3763
3908
|
return { name: node.key.name, params };
|
|
3764
3909
|
}
|
|
3765
3910
|
default:
|
|
@@ -3769,9 +3914,9 @@ function declarationNames(node) {
|
|
|
3769
3914
|
function paramNames(params) {
|
|
3770
3915
|
const names = [];
|
|
3771
3916
|
for (const param of params) {
|
|
3772
|
-
const target = param.type ===
|
|
3773
|
-
if (target.type ===
|
|
3774
|
-
else if (target.type ===
|
|
3917
|
+
const target = param.type === AST_NODE_TYPES19.AssignmentPattern ? param.left : param;
|
|
3918
|
+
if (target.type === AST_NODE_TYPES19.Identifier) names.push(target.name);
|
|
3919
|
+
else if (target.type === AST_NODE_TYPES19.TSParameterProperty) continue;
|
|
3775
3920
|
}
|
|
3776
3921
|
return names;
|
|
3777
3922
|
}
|
|
@@ -3813,7 +3958,7 @@ var no_restated_jsdoc_default = createRule({
|
|
|
3813
3958
|
if (token === null || token.loc.start.line !== comment.loc.end.line + 1) continue;
|
|
3814
3959
|
let node = sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
3815
3960
|
let declaration = null;
|
|
3816
|
-
while (node != null && node.type !==
|
|
3961
|
+
while (node != null && node.type !== AST_NODE_TYPES19.Program) {
|
|
3817
3962
|
declaration = declarationNames(node);
|
|
3818
3963
|
if (declaration !== null) break;
|
|
3819
3964
|
node = node.parent ?? null;
|
|
@@ -4272,12 +4417,12 @@ var no_select_star_default = createRule({
|
|
|
4272
4417
|
});
|
|
4273
4418
|
|
|
4274
4419
|
// src/rules/no-sentinel-return-on-catch.ts
|
|
4275
|
-
import { AST_NODE_TYPES as
|
|
4420
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES20 } from "@typescript-eslint/utils";
|
|
4276
4421
|
function sentinelKind(arg) {
|
|
4277
4422
|
if (arg === null) {
|
|
4278
4423
|
return null;
|
|
4279
4424
|
}
|
|
4280
|
-
if (arg.type ===
|
|
4425
|
+
if (arg.type === AST_NODE_TYPES20.Literal) {
|
|
4281
4426
|
if (arg.value === null) {
|
|
4282
4427
|
return "nullish";
|
|
4283
4428
|
}
|
|
@@ -4289,13 +4434,13 @@ function sentinelKind(arg) {
|
|
|
4289
4434
|
}
|
|
4290
4435
|
return null;
|
|
4291
4436
|
}
|
|
4292
|
-
if (arg.type ===
|
|
4437
|
+
if (arg.type === AST_NODE_TYPES20.Identifier && arg.name === "undefined") {
|
|
4293
4438
|
return "nullish";
|
|
4294
4439
|
}
|
|
4295
|
-
if (arg.type ===
|
|
4440
|
+
if (arg.type === AST_NODE_TYPES20.ArrayExpression) {
|
|
4296
4441
|
return "array";
|
|
4297
4442
|
}
|
|
4298
|
-
if (arg.type ===
|
|
4443
|
+
if (arg.type === AST_NODE_TYPES20.ObjectExpression) {
|
|
4299
4444
|
return "object";
|
|
4300
4445
|
}
|
|
4301
4446
|
return null;
|
|
@@ -4304,25 +4449,25 @@ function isSentinelArgument(arg) {
|
|
|
4304
4449
|
if (arg === null) {
|
|
4305
4450
|
return false;
|
|
4306
4451
|
}
|
|
4307
|
-
if (arg.type ===
|
|
4452
|
+
if (arg.type === AST_NODE_TYPES20.Literal && arg.value === null) {
|
|
4308
4453
|
return true;
|
|
4309
4454
|
}
|
|
4310
|
-
if (arg.type ===
|
|
4455
|
+
if (arg.type === AST_NODE_TYPES20.Literal && arg.value === false) {
|
|
4311
4456
|
return true;
|
|
4312
4457
|
}
|
|
4313
|
-
if (arg.type ===
|
|
4458
|
+
if (arg.type === AST_NODE_TYPES20.Identifier && arg.name === "undefined") {
|
|
4314
4459
|
return true;
|
|
4315
4460
|
}
|
|
4316
|
-
if (arg.type ===
|
|
4461
|
+
if (arg.type === AST_NODE_TYPES20.ArrayExpression && arg.elements.length === 0) {
|
|
4317
4462
|
return true;
|
|
4318
4463
|
}
|
|
4319
|
-
if (arg.type ===
|
|
4464
|
+
if (arg.type === AST_NODE_TYPES20.ObjectExpression && arg.properties.length === 0) {
|
|
4320
4465
|
return true;
|
|
4321
4466
|
}
|
|
4322
4467
|
return false;
|
|
4323
4468
|
}
|
|
4324
4469
|
function isFunctionNode(node) {
|
|
4325
|
-
return node.type ===
|
|
4470
|
+
return node.type === AST_NODE_TYPES20.FunctionDeclaration || node.type === AST_NODE_TYPES20.FunctionExpression || node.type === AST_NODE_TYPES20.ArrowFunctionExpression;
|
|
4326
4471
|
}
|
|
4327
4472
|
function isNode3(value) {
|
|
4328
4473
|
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
@@ -4362,24 +4507,24 @@ function walkWithinScope(node, visit) {
|
|
|
4362
4507
|
function containsThrow(node) {
|
|
4363
4508
|
return walkWithinScope(
|
|
4364
4509
|
node,
|
|
4365
|
-
(current) => current.type ===
|
|
4510
|
+
(current) => current.type === AST_NODE_TYPES20.ThrowStatement
|
|
4366
4511
|
);
|
|
4367
4512
|
}
|
|
4368
4513
|
function bindsName(param, name) {
|
|
4369
4514
|
switch (param.type) {
|
|
4370
|
-
case
|
|
4515
|
+
case AST_NODE_TYPES20.Identifier:
|
|
4371
4516
|
return param.name === name;
|
|
4372
|
-
case
|
|
4517
|
+
case AST_NODE_TYPES20.AssignmentPattern:
|
|
4373
4518
|
return bindsName(param.left, name);
|
|
4374
|
-
case
|
|
4519
|
+
case AST_NODE_TYPES20.RestElement:
|
|
4375
4520
|
return bindsName(param.argument, name);
|
|
4376
|
-
case
|
|
4521
|
+
case AST_NODE_TYPES20.ArrayPattern:
|
|
4377
4522
|
return param.elements.some(
|
|
4378
4523
|
(element) => element !== null && bindsName(element, name)
|
|
4379
4524
|
);
|
|
4380
|
-
case
|
|
4525
|
+
case AST_NODE_TYPES20.ObjectPattern:
|
|
4381
4526
|
return param.properties.some(
|
|
4382
|
-
(property) => property.type ===
|
|
4527
|
+
(property) => property.type === AST_NODE_TYPES20.RestElement ? bindsName(property.argument, name) : bindsName(property.value, name)
|
|
4383
4528
|
);
|
|
4384
4529
|
default:
|
|
4385
4530
|
return false;
|
|
@@ -4394,7 +4539,7 @@ function subtreeReadsName(node, name) {
|
|
|
4394
4539
|
if (found) {
|
|
4395
4540
|
return;
|
|
4396
4541
|
}
|
|
4397
|
-
if (current.type ===
|
|
4542
|
+
if (current.type === AST_NODE_TYPES20.Identifier && current.name === name) {
|
|
4398
4543
|
found = true;
|
|
4399
4544
|
return;
|
|
4400
4545
|
}
|
|
@@ -4405,10 +4550,10 @@ function subtreeReadsName(node, name) {
|
|
|
4405
4550
|
if (key === "parent") {
|
|
4406
4551
|
continue;
|
|
4407
4552
|
}
|
|
4408
|
-
if (key === "key" && current.type ===
|
|
4553
|
+
if (key === "key" && current.type === AST_NODE_TYPES20.Property && !current.computed) {
|
|
4409
4554
|
continue;
|
|
4410
4555
|
}
|
|
4411
|
-
if (key === "property" && current.type ===
|
|
4556
|
+
if (key === "property" && current.type === AST_NODE_TYPES20.MemberExpression && !current.computed) {
|
|
4412
4557
|
continue;
|
|
4413
4558
|
}
|
|
4414
4559
|
const value = current[key];
|
|
@@ -4441,10 +4586,10 @@ var SAFE_PARSE_CONSTRUCTORS = /* @__PURE__ */ new Set([
|
|
|
4441
4586
|
"URLPattern"
|
|
4442
4587
|
]);
|
|
4443
4588
|
function isParseShapedNode(node) {
|
|
4444
|
-
if (node.type ===
|
|
4589
|
+
if (node.type === AST_NODE_TYPES20.CallExpression && node.callee.type === AST_NODE_TYPES20.MemberExpression && !node.callee.computed && node.callee.property.type === AST_NODE_TYPES20.Identifier) {
|
|
4445
4590
|
return node.callee.property.name === "parse";
|
|
4446
4591
|
}
|
|
4447
|
-
if (node.type ===
|
|
4592
|
+
if (node.type === AST_NODE_TYPES20.NewExpression && node.callee.type === AST_NODE_TYPES20.Identifier) {
|
|
4448
4593
|
return SAFE_PARSE_CONSTRUCTORS.has(node.callee.name);
|
|
4449
4594
|
}
|
|
4450
4595
|
return false;
|
|
@@ -4455,10 +4600,10 @@ var BODY_DECODE_METHODS = /* @__PURE__ */ new Set([
|
|
|
4455
4600
|
"arrayBuffer"
|
|
4456
4601
|
]);
|
|
4457
4602
|
function isBodyDecodeNode(node) {
|
|
4458
|
-
return node.type ===
|
|
4603
|
+
return node.type === AST_NODE_TYPES20.CallExpression && node.callee.type === AST_NODE_TYPES20.MemberExpression && !node.callee.computed && node.callee.property.type === AST_NODE_TYPES20.Identifier && BODY_DECODE_METHODS.has(node.callee.property.name);
|
|
4459
4604
|
}
|
|
4460
4605
|
function returnsMatching(stmt, predicate) {
|
|
4461
|
-
return stmt.type ===
|
|
4606
|
+
return stmt.type === AST_NODE_TYPES20.ReturnStatement && stmt.argument !== null && walkWithinScope(stmt.argument, predicate);
|
|
4462
4607
|
}
|
|
4463
4608
|
function enclosingReturnTypeNode(node) {
|
|
4464
4609
|
let current = node.parent;
|
|
@@ -4476,11 +4621,11 @@ function enclosingFunctionName(node) {
|
|
|
4476
4621
|
let current = node.parent;
|
|
4477
4622
|
while (current !== void 0 && current !== null) {
|
|
4478
4623
|
if (isFunctionNode(current)) {
|
|
4479
|
-
if ("id" in current && isNode3(current.id) && current.id.type ===
|
|
4624
|
+
if ("id" in current && isNode3(current.id) && current.id.type === AST_NODE_TYPES20.Identifier) {
|
|
4480
4625
|
return current.id.name;
|
|
4481
4626
|
}
|
|
4482
4627
|
const parent = current.parent;
|
|
4483
|
-
if (parent?.type ===
|
|
4628
|
+
if (parent?.type === AST_NODE_TYPES20.VariableDeclarator && parent.id.type === AST_NODE_TYPES20.Identifier) {
|
|
4484
4629
|
return parent.id.name;
|
|
4485
4630
|
}
|
|
4486
4631
|
return null;
|
|
@@ -4501,10 +4646,10 @@ function isDeclaredBooleanPredicate(catchNode, kind) {
|
|
|
4501
4646
|
return false;
|
|
4502
4647
|
}
|
|
4503
4648
|
let declared = enclosingReturnTypeNode(catchNode);
|
|
4504
|
-
if (declared?.type ===
|
|
4649
|
+
if (declared?.type === AST_NODE_TYPES20.TSTypeReference && declared.typeName.type === AST_NODE_TYPES20.Identifier && declared.typeName.name === "Promise") {
|
|
4505
4650
|
declared = declared.typeArguments?.params[0] ?? null;
|
|
4506
4651
|
}
|
|
4507
|
-
return declared?.type ===
|
|
4652
|
+
return declared?.type === AST_NODE_TYPES20.TSBooleanKeyword;
|
|
4508
4653
|
}
|
|
4509
4654
|
function tryReturnsSafeParse(catchNode) {
|
|
4510
4655
|
const tryBlock = tryBlockOf(catchNode);
|
|
@@ -4520,7 +4665,7 @@ function tryReturnsSafeParse(catchNode) {
|
|
|
4520
4665
|
function enclosingFunctionBody(node) {
|
|
4521
4666
|
let current = node.parent;
|
|
4522
4667
|
while (current !== void 0 && current !== null) {
|
|
4523
|
-
if (isFunctionNode(current) && "body" in current && isNode3(current.body) && current.body.type ===
|
|
4668
|
+
if (isFunctionNode(current) && "body" in current && isNode3(current.body) && current.body.type === AST_NODE_TYPES20.BlockStatement) {
|
|
4524
4669
|
return current.body;
|
|
4525
4670
|
}
|
|
4526
4671
|
current = current.parent;
|
|
@@ -4533,7 +4678,7 @@ function functionReturnsSameSentinelKindElsewhere(catchNode, kind) {
|
|
|
4533
4678
|
return false;
|
|
4534
4679
|
}
|
|
4535
4680
|
return walkWithinScope(functionBody, (current) => {
|
|
4536
|
-
if (current.type !==
|
|
4681
|
+
if (current.type !== AST_NODE_TYPES20.ReturnStatement) {
|
|
4537
4682
|
return false;
|
|
4538
4683
|
}
|
|
4539
4684
|
if (isWithin(current, catchNode.body)) {
|
|
@@ -4552,13 +4697,13 @@ function returnedSentinelKinds(arg) {
|
|
|
4552
4697
|
kinds.add(direct);
|
|
4553
4698
|
return kinds;
|
|
4554
4699
|
}
|
|
4555
|
-
if (arg.type ===
|
|
4700
|
+
if (arg.type === AST_NODE_TYPES20.ConditionalExpression) {
|
|
4556
4701
|
for (const branch of [arg.consequent, arg.alternate]) {
|
|
4557
4702
|
for (const nested of returnedSentinelKinds(branch)) {
|
|
4558
4703
|
kinds.add(nested);
|
|
4559
4704
|
}
|
|
4560
4705
|
}
|
|
4561
|
-
} else if (arg.type ===
|
|
4706
|
+
} else if (arg.type === AST_NODE_TYPES20.LogicalExpression && (arg.operator === "??" || arg.operator === "||")) {
|
|
4562
4707
|
for (const nested of returnedSentinelKinds(arg.right)) {
|
|
4563
4708
|
kinds.add(nested);
|
|
4564
4709
|
}
|
|
@@ -4601,7 +4746,7 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
4601
4746
|
const matcher = createLogMatcher(loggingOptions);
|
|
4602
4747
|
function logsOrReportsError(catchBody, caughtName) {
|
|
4603
4748
|
return walkWithinScope(catchBody, (current) => {
|
|
4604
|
-
if (current.type !==
|
|
4749
|
+
if (current.type !== AST_NODE_TYPES20.CallExpression) {
|
|
4605
4750
|
return false;
|
|
4606
4751
|
}
|
|
4607
4752
|
if (matcher.isLoggingCall(current)) {
|
|
@@ -4618,7 +4763,7 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
4618
4763
|
return;
|
|
4619
4764
|
}
|
|
4620
4765
|
const last = body2[body2.length - 1];
|
|
4621
|
-
if (last === void 0 || last.type !==
|
|
4766
|
+
if (last === void 0 || last.type !== AST_NODE_TYPES20.ReturnStatement) {
|
|
4622
4767
|
return;
|
|
4623
4768
|
}
|
|
4624
4769
|
if (!isSentinelArgument(last.argument)) {
|
|
@@ -4627,7 +4772,7 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
4627
4772
|
if (containsThrow(node.body)) {
|
|
4628
4773
|
return;
|
|
4629
4774
|
}
|
|
4630
|
-
const caughtName = node.param?.type ===
|
|
4775
|
+
const caughtName = node.param?.type === AST_NODE_TYPES20.Identifier ? node.param.name : null;
|
|
4631
4776
|
if (logsOrReportsError(node.body, caughtName)) {
|
|
4632
4777
|
return;
|
|
4633
4778
|
}
|
|
@@ -4654,9 +4799,9 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
4654
4799
|
});
|
|
4655
4800
|
|
|
4656
4801
|
// src/rules/no-silent-promise-catch.ts
|
|
4657
|
-
import { AST_NODE_TYPES as
|
|
4802
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES21 } from "@typescript-eslint/utils";
|
|
4658
4803
|
function isBodyParseCall(node) {
|
|
4659
|
-
return node.type ===
|
|
4804
|
+
return node.type === AST_NODE_TYPES21.CallExpression && node.arguments.length === 0 && node.callee.type === AST_NODE_TYPES21.MemberExpression && !node.callee.computed && node.callee.property.type === AST_NODE_TYPES21.Identifier && (node.callee.property.name === "json" || node.callee.property.name === "text");
|
|
4660
4805
|
}
|
|
4661
4806
|
var TEARDOWN_METHODS = /* @__PURE__ */ new Set([
|
|
4662
4807
|
"cancel",
|
|
@@ -4671,21 +4816,21 @@ var TEARDOWN_METHODS = /* @__PURE__ */ new Set([
|
|
|
4671
4816
|
var DIRECTIVE_COMMENT_RE = /^\s*(eslint-|@ts-|prettier-ignore|biome-ignore|c8 |v8 |istanbul )/;
|
|
4672
4817
|
var isExplanatory = (comment) => !DIRECTIVE_COMMENT_RE.test(comment.value);
|
|
4673
4818
|
function isTeardownCall(node) {
|
|
4674
|
-
return node.type ===
|
|
4819
|
+
return node.type === AST_NODE_TYPES21.CallExpression && node.callee.type === AST_NODE_TYPES21.MemberExpression && !node.callee.computed && node.callee.property.type === AST_NODE_TYPES21.Identifier && TEARDOWN_METHODS.has(node.callee.property.name);
|
|
4675
4820
|
}
|
|
4676
4821
|
function isSilentExpression(node) {
|
|
4677
4822
|
switch (node.type) {
|
|
4678
|
-
case
|
|
4823
|
+
case AST_NODE_TYPES21.Literal:
|
|
4679
4824
|
return !("regex" in node);
|
|
4680
|
-
case
|
|
4825
|
+
case AST_NODE_TYPES21.Identifier:
|
|
4681
4826
|
return node.name === "undefined";
|
|
4682
|
-
case
|
|
4683
|
-
return node.operator === "void" && node.argument.type ===
|
|
4684
|
-
case
|
|
4827
|
+
case AST_NODE_TYPES21.UnaryExpression:
|
|
4828
|
+
return node.operator === "void" && node.argument.type === AST_NODE_TYPES21.Literal;
|
|
4829
|
+
case AST_NODE_TYPES21.ObjectExpression:
|
|
4685
4830
|
return node.properties.length === 0;
|
|
4686
|
-
case
|
|
4831
|
+
case AST_NODE_TYPES21.ArrayExpression:
|
|
4687
4832
|
return node.elements.length === 0;
|
|
4688
|
-
case
|
|
4833
|
+
case AST_NODE_TYPES21.TSAsExpression:
|
|
4689
4834
|
return isSilentExpression(node.expression);
|
|
4690
4835
|
default:
|
|
4691
4836
|
return false;
|
|
@@ -4693,7 +4838,7 @@ function isSilentExpression(node) {
|
|
|
4693
4838
|
}
|
|
4694
4839
|
function isSilentHandler(handler) {
|
|
4695
4840
|
const body2 = handler.body;
|
|
4696
|
-
if (body2.type !==
|
|
4841
|
+
if (body2.type !== AST_NODE_TYPES21.BlockStatement) {
|
|
4697
4842
|
return isSilentExpression(body2);
|
|
4698
4843
|
}
|
|
4699
4844
|
if (body2.body.length === 0) {
|
|
@@ -4701,7 +4846,7 @@ function isSilentHandler(handler) {
|
|
|
4701
4846
|
}
|
|
4702
4847
|
if (body2.body.length === 1) {
|
|
4703
4848
|
const only = body2.body[0];
|
|
4704
|
-
if (only !== void 0 && only.type ===
|
|
4849
|
+
if (only !== void 0 && only.type === AST_NODE_TYPES21.ReturnStatement) {
|
|
4705
4850
|
return only.argument === null || isSilentExpression(only.argument);
|
|
4706
4851
|
}
|
|
4707
4852
|
}
|
|
@@ -4730,7 +4875,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
4730
4875
|
return true;
|
|
4731
4876
|
}
|
|
4732
4877
|
let statement = call;
|
|
4733
|
-
while (statement.parent !== void 0 && statement.parent !== null && !statement.type.endsWith("Statement") && statement.type !==
|
|
4878
|
+
while (statement.parent !== void 0 && statement.parent !== null && !statement.type.endsWith("Statement") && statement.type !== AST_NODE_TYPES21.VariableDeclaration) {
|
|
4734
4879
|
statement = statement.parent;
|
|
4735
4880
|
}
|
|
4736
4881
|
if (sourceCode.getCommentsBefore(statement).some(isExplanatory)) {
|
|
@@ -4742,7 +4887,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
4742
4887
|
};
|
|
4743
4888
|
return {
|
|
4744
4889
|
CallExpression(node) {
|
|
4745
|
-
if (node.callee.type !==
|
|
4890
|
+
if (node.callee.type !== AST_NODE_TYPES21.MemberExpression || node.callee.computed || node.callee.property.type !== AST_NODE_TYPES21.Identifier || node.callee.property.name !== "catch") {
|
|
4746
4891
|
return;
|
|
4747
4892
|
}
|
|
4748
4893
|
if (isBodyParseCall(node.callee.object)) {
|
|
@@ -4751,14 +4896,14 @@ var no_silent_promise_catch_default = createRule({
|
|
|
4751
4896
|
if (isTeardownCall(node.callee.object)) {
|
|
4752
4897
|
return;
|
|
4753
4898
|
}
|
|
4754
|
-
if (node.parent.type ===
|
|
4899
|
+
if (node.parent.type === AST_NODE_TYPES21.MemberExpression && node.parent.object === node) {
|
|
4755
4900
|
return;
|
|
4756
4901
|
}
|
|
4757
4902
|
if (node.arguments.length !== 1) {
|
|
4758
4903
|
return;
|
|
4759
4904
|
}
|
|
4760
4905
|
const handler = node.arguments[0];
|
|
4761
|
-
if (handler === void 0 || handler.type !==
|
|
4906
|
+
if (handler === void 0 || handler.type !== AST_NODE_TYPES21.ArrowFunctionExpression && handler.type !== AST_NODE_TYPES21.FunctionExpression) {
|
|
4762
4907
|
return;
|
|
4763
4908
|
}
|
|
4764
4909
|
if (hasExplanatoryComment(node, handler)) {
|
|
@@ -4773,7 +4918,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
4773
4918
|
});
|
|
4774
4919
|
|
|
4775
4920
|
// src/rules/no-sleep-in-test-body.ts
|
|
4776
|
-
import { AST_NODE_TYPES as
|
|
4921
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES22 } from "@typescript-eslint/utils";
|
|
4777
4922
|
var SLEEP_HELPERS = /* @__PURE__ */ new Set(["sleep", "delay", "wait", "pause"]);
|
|
4778
4923
|
var TEST_CALLERS2 = /* @__PURE__ */ new Set([
|
|
4779
4924
|
"it",
|
|
@@ -4782,34 +4927,34 @@ var TEST_CALLERS2 = /* @__PURE__ */ new Set([
|
|
|
4782
4927
|
"afterEach"
|
|
4783
4928
|
]);
|
|
4784
4929
|
var FUNCTION_TYPES4 = /* @__PURE__ */ new Set([
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4930
|
+
AST_NODE_TYPES22.FunctionDeclaration,
|
|
4931
|
+
AST_NODE_TYPES22.FunctionExpression,
|
|
4932
|
+
AST_NODE_TYPES22.ArrowFunctionExpression
|
|
4788
4933
|
]);
|
|
4789
4934
|
function isNonzeroNumericLiteral(node) {
|
|
4790
|
-
return node?.type ===
|
|
4935
|
+
return node?.type === AST_NODE_TYPES22.Literal && typeof node.value === "number" && node.value !== 0;
|
|
4791
4936
|
}
|
|
4792
4937
|
function isTimedSetTimeout(node) {
|
|
4793
|
-
return node.type ===
|
|
4938
|
+
return node.type === AST_NODE_TYPES22.CallExpression && node.callee.type === AST_NODE_TYPES22.Identifier && node.callee.name === "setTimeout" && node.arguments.length >= 2 && isNonzeroNumericLiteral(node.arguments[1]);
|
|
4794
4939
|
}
|
|
4795
4940
|
function isPromiseSleep(node) {
|
|
4796
|
-
if (node.callee.type !==
|
|
4941
|
+
if (node.callee.type !== AST_NODE_TYPES22.Identifier || node.callee.name !== "Promise") {
|
|
4797
4942
|
return false;
|
|
4798
4943
|
}
|
|
4799
4944
|
const executor = node.arguments[0];
|
|
4800
|
-
if (executor?.type !==
|
|
4945
|
+
if (executor?.type !== AST_NODE_TYPES22.ArrowFunctionExpression && executor?.type !== AST_NODE_TYPES22.FunctionExpression) {
|
|
4801
4946
|
return false;
|
|
4802
4947
|
}
|
|
4803
4948
|
const body2 = executor.body;
|
|
4804
|
-
if (body2.type !==
|
|
4949
|
+
if (body2.type !== AST_NODE_TYPES22.BlockStatement) {
|
|
4805
4950
|
return isTimedSetTimeout(body2);
|
|
4806
4951
|
}
|
|
4807
4952
|
return body2.body.some(
|
|
4808
|
-
(stmt) => stmt.type ===
|
|
4953
|
+
(stmt) => stmt.type === AST_NODE_TYPES22.ExpressionStatement && isTimedSetTimeout(stmt.expression)
|
|
4809
4954
|
);
|
|
4810
4955
|
}
|
|
4811
4956
|
function isHelperSleep(node) {
|
|
4812
|
-
return node.callee.type ===
|
|
4957
|
+
return node.callee.type === AST_NODE_TYPES22.Identifier && SLEEP_HELPERS.has(node.callee.name) && node.arguments.length >= 1 && isNonzeroNumericLiteral(node.arguments[0]);
|
|
4813
4958
|
}
|
|
4814
4959
|
function nearestEnclosingFunction2(node) {
|
|
4815
4960
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
@@ -4817,7 +4962,7 @@ function nearestEnclosingFunction2(node) {
|
|
|
4817
4962
|
continue;
|
|
4818
4963
|
}
|
|
4819
4964
|
const grandparent = current.parent;
|
|
4820
|
-
const isPromiseExecutor = grandparent?.type ===
|
|
4965
|
+
const isPromiseExecutor = grandparent?.type === AST_NODE_TYPES22.NewExpression && isPromiseSleep(grandparent);
|
|
4821
4966
|
if (!isPromiseExecutor) {
|
|
4822
4967
|
return current;
|
|
4823
4968
|
}
|
|
@@ -4825,23 +4970,23 @@ function nearestEnclosingFunction2(node) {
|
|
|
4825
4970
|
return null;
|
|
4826
4971
|
}
|
|
4827
4972
|
function testCallerName2(callee) {
|
|
4828
|
-
if (callee.type ===
|
|
4973
|
+
if (callee.type === AST_NODE_TYPES22.Identifier) {
|
|
4829
4974
|
return callee.name;
|
|
4830
4975
|
}
|
|
4831
|
-
if (callee.type ===
|
|
4976
|
+
if (callee.type === AST_NODE_TYPES22.MemberExpression) {
|
|
4832
4977
|
return testCallerName2(callee.object);
|
|
4833
4978
|
}
|
|
4834
|
-
if (callee.type ===
|
|
4979
|
+
if (callee.type === AST_NODE_TYPES22.CallExpression) {
|
|
4835
4980
|
return testCallerName2(callee.callee);
|
|
4836
4981
|
}
|
|
4837
|
-
if (callee.type ===
|
|
4982
|
+
if (callee.type === AST_NODE_TYPES22.TaggedTemplateExpression) {
|
|
4838
4983
|
return testCallerName2(callee.tag);
|
|
4839
4984
|
}
|
|
4840
4985
|
return null;
|
|
4841
4986
|
}
|
|
4842
4987
|
function isTestBody2(fn) {
|
|
4843
4988
|
const call = fn.parent;
|
|
4844
|
-
if (call?.type !==
|
|
4989
|
+
if (call?.type !== AST_NODE_TYPES22.CallExpression || !call.arguments.some((argument) => argument === fn)) {
|
|
4845
4990
|
return false;
|
|
4846
4991
|
}
|
|
4847
4992
|
const name = testCallerName2(call.callee);
|
|
@@ -4887,7 +5032,7 @@ var no_sleep_in_test_body_default = createRule({
|
|
|
4887
5032
|
});
|
|
4888
5033
|
|
|
4889
5034
|
// src/rules/no-storage-in-stateless-modules.ts
|
|
4890
|
-
import { AST_NODE_TYPES as
|
|
5035
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES23 } from "@typescript-eslint/utils";
|
|
4891
5036
|
var DEFAULT_METHODS2 = [
|
|
4892
5037
|
"prepare",
|
|
4893
5038
|
"put",
|
|
@@ -4906,7 +5051,7 @@ function compile2(patterns) {
|
|
|
4906
5051
|
}
|
|
4907
5052
|
function storageMethodName(node, methods) {
|
|
4908
5053
|
const callee = node.callee;
|
|
4909
|
-
if (callee.type !==
|
|
5054
|
+
if (callee.type !== AST_NODE_TYPES23.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES23.Identifier) {
|
|
4910
5055
|
return null;
|
|
4911
5056
|
}
|
|
4912
5057
|
const name = callee.property.name;
|
|
@@ -5120,7 +5265,7 @@ var no_string_concat_in_loop_default = createRule({
|
|
|
5120
5265
|
});
|
|
5121
5266
|
|
|
5122
5267
|
// src/rules/no-tautological-expect.ts
|
|
5123
|
-
import { AST_NODE_TYPES as
|
|
5268
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES24 } from "@typescript-eslint/utils";
|
|
5124
5269
|
var EQUALITY_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
5125
5270
|
var ZERO_ARG_MATCHERS = /* @__PURE__ */ new Set([
|
|
5126
5271
|
"toBeDefined",
|
|
@@ -5134,17 +5279,17 @@ var OPERAND_PREVIEW_CHARS = 40;
|
|
|
5134
5279
|
var NUMERIC_SIGNS = /* @__PURE__ */ new Set(["-", "+"]);
|
|
5135
5280
|
function isLiteral(node) {
|
|
5136
5281
|
switch (node.type) {
|
|
5137
|
-
case
|
|
5282
|
+
case AST_NODE_TYPES24.Literal:
|
|
5138
5283
|
return true;
|
|
5139
|
-
case
|
|
5284
|
+
case AST_NODE_TYPES24.TemplateLiteral:
|
|
5140
5285
|
return node.expressions.length === 0;
|
|
5141
|
-
case
|
|
5286
|
+
case AST_NODE_TYPES24.UnaryExpression:
|
|
5142
5287
|
return NUMERIC_SIGNS.has(node.operator) && isLiteral(node.argument);
|
|
5143
|
-
case
|
|
5288
|
+
case AST_NODE_TYPES24.ArrayExpression:
|
|
5144
5289
|
return node.elements.every((element) => element !== null && isLiteral(element));
|
|
5145
|
-
case
|
|
5290
|
+
case AST_NODE_TYPES24.ObjectExpression:
|
|
5146
5291
|
return node.properties.every(
|
|
5147
|
-
(property) => property.type ===
|
|
5292
|
+
(property) => property.type === AST_NODE_TYPES24.Property && !property.computed && isLiteral(property.value)
|
|
5148
5293
|
);
|
|
5149
5294
|
default:
|
|
5150
5295
|
return false;
|
|
@@ -5152,7 +5297,7 @@ function isLiteral(node) {
|
|
|
5152
5297
|
}
|
|
5153
5298
|
function expectOperand(callee) {
|
|
5154
5299
|
const receiver = callee.object;
|
|
5155
|
-
if (receiver.type !==
|
|
5300
|
+
if (receiver.type !== AST_NODE_TYPES24.CallExpression || receiver.callee.type !== AST_NODE_TYPES24.Identifier || receiver.callee.name !== "expect" || receiver.arguments.length !== 1) {
|
|
5156
5301
|
return null;
|
|
5157
5302
|
}
|
|
5158
5303
|
return receiver.arguments[0] ?? null;
|
|
@@ -5182,10 +5327,10 @@ var no_tautological_expect_default = createRule({
|
|
|
5182
5327
|
return {
|
|
5183
5328
|
CallExpression(node) {
|
|
5184
5329
|
const callee = node.callee;
|
|
5185
|
-
if (callee.type !==
|
|
5330
|
+
if (callee.type !== AST_NODE_TYPES24.MemberExpression || callee.computed) {
|
|
5186
5331
|
return;
|
|
5187
5332
|
}
|
|
5188
|
-
if (callee.property.type !==
|
|
5333
|
+
if (callee.property.type !== AST_NODE_TYPES24.Identifier) {
|
|
5189
5334
|
return;
|
|
5190
5335
|
}
|
|
5191
5336
|
const matcher = callee.property.name;
|
|
@@ -5379,10 +5524,10 @@ var no_trailing_value_narration_default = createRule({
|
|
|
5379
5524
|
});
|
|
5380
5525
|
|
|
5381
5526
|
// src/rules/no-declaration-comment-wall.ts
|
|
5382
|
-
import { AST_NODE_TYPES as
|
|
5527
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES26 } from "@typescript-eslint/utils";
|
|
5383
5528
|
|
|
5384
5529
|
// src/rules/_comment-wall.ts
|
|
5385
|
-
import { AST_NODE_TYPES as
|
|
5530
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES25 } from "@typescript-eslint/utils";
|
|
5386
5531
|
var WALL_DEFAULTS = {
|
|
5387
5532
|
// Below three rows "a wall" is not a fair description of what the reader sees.
|
|
5388
5533
|
minCommentedMembers: 3,
|
|
@@ -5486,10 +5631,10 @@ function isWall(members, commented, restated, options) {
|
|
|
5486
5631
|
return commented >= options.minCommentedMembers && commented / members >= options.minCommentedRatio && restated / commented >= options.minRestatedRatio;
|
|
5487
5632
|
}
|
|
5488
5633
|
var OPAQUE_VALUE_TYPES = /* @__PURE__ */ new Set([
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
|
|
5634
|
+
AST_NODE_TYPES25.FunctionExpression,
|
|
5635
|
+
AST_NODE_TYPES25.ArrowFunctionExpression,
|
|
5636
|
+
AST_NODE_TYPES25.ObjectExpression,
|
|
5637
|
+
AST_NODE_TYPES25.ArrayExpression
|
|
5493
5638
|
]);
|
|
5494
5639
|
function declarationRange(member) {
|
|
5495
5640
|
const body2 = bodyOf(member);
|
|
@@ -5497,10 +5642,10 @@ function declarationRange(member) {
|
|
|
5497
5642
|
return [member.range[0], body2.range[0]];
|
|
5498
5643
|
}
|
|
5499
5644
|
function bodyOf(member) {
|
|
5500
|
-
if (member.type ===
|
|
5645
|
+
if (member.type === AST_NODE_TYPES25.MethodDefinition || member.type === AST_NODE_TYPES25.TSAbstractMethodDefinition) {
|
|
5501
5646
|
return member.value.body ?? void 0;
|
|
5502
5647
|
}
|
|
5503
|
-
if (member.type ===
|
|
5648
|
+
if (member.type === AST_NODE_TYPES25.Property || member.type === AST_NODE_TYPES25.PropertyDefinition) {
|
|
5504
5649
|
const value = member.value;
|
|
5505
5650
|
if (value !== null && OPAQUE_VALUE_TYPES.has(value.type)) return value;
|
|
5506
5651
|
}
|
|
@@ -5510,12 +5655,12 @@ function bodyOf(member) {
|
|
|
5510
5655
|
// src/rules/no-declaration-comment-wall.ts
|
|
5511
5656
|
function named(node) {
|
|
5512
5657
|
switch (node.type) {
|
|
5513
|
-
case
|
|
5658
|
+
case AST_NODE_TYPES26.TSEnumMember:
|
|
5514
5659
|
return { node, key: node.id };
|
|
5515
|
-
case
|
|
5516
|
-
case
|
|
5517
|
-
case
|
|
5518
|
-
case
|
|
5660
|
+
case AST_NODE_TYPES26.PropertyDefinition:
|
|
5661
|
+
case AST_NODE_TYPES26.TSAbstractPropertyDefinition:
|
|
5662
|
+
case AST_NODE_TYPES26.MethodDefinition:
|
|
5663
|
+
case AST_NODE_TYPES26.TSAbstractMethodDefinition:
|
|
5519
5664
|
return node.computed ? void 0 : { node, key: node.key };
|
|
5520
5665
|
default:
|
|
5521
5666
|
return void 0;
|
|
@@ -5615,7 +5760,7 @@ var no_declaration_comment_wall_default = createRule({
|
|
|
5615
5760
|
});
|
|
5616
5761
|
|
|
5617
5762
|
// src/rules/no-union-in-comment.ts
|
|
5618
|
-
import { AST_NODE_TYPES as
|
|
5763
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES27 } from "@typescript-eslint/utils";
|
|
5619
5764
|
var MAX_LITERAL_LENGTH = 28;
|
|
5620
5765
|
var LITERAL = String.raw`(?:'[^'\n]*'|"[^"\n]*"|\`[^\`\n]*\`)`;
|
|
5621
5766
|
var LEAD_IN_RE2 = /^(?:one of|either|values?|allowed(?: values)?|options?|possible(?: values)?)\s*[:=-]?\s*/i;
|
|
@@ -5634,14 +5779,14 @@ var STRING_BUILDERS = /* @__PURE__ */ new Set([
|
|
|
5634
5779
|
function isBareString(node) {
|
|
5635
5780
|
if (node === void 0) return false;
|
|
5636
5781
|
switch (node.type) {
|
|
5637
|
-
case
|
|
5782
|
+
case AST_NODE_TYPES27.TSStringKeyword:
|
|
5638
5783
|
return true;
|
|
5639
5784
|
// `string[]` holds members of the same closed set, one element at a time.
|
|
5640
|
-
case
|
|
5785
|
+
case AST_NODE_TYPES27.TSArrayType:
|
|
5641
5786
|
return isBareString(node.elementType);
|
|
5642
5787
|
// `string | null` is still an unconstrained string, and so is `string | "a"`
|
|
5643
5788
|
// — the checker collapses that one to `string`.
|
|
5644
|
-
case
|
|
5789
|
+
case AST_NODE_TYPES27.TSUnionType:
|
|
5645
5790
|
return node.types.some((member) => isBareString(member));
|
|
5646
5791
|
default:
|
|
5647
5792
|
return false;
|
|
@@ -5651,13 +5796,13 @@ function rootCallee(node) {
|
|
|
5651
5796
|
let current = node;
|
|
5652
5797
|
for (let hops = 0; current != null && hops < 12; hops += 1) {
|
|
5653
5798
|
switch (current.type) {
|
|
5654
|
-
case
|
|
5799
|
+
case AST_NODE_TYPES27.CallExpression:
|
|
5655
5800
|
current = current.callee;
|
|
5656
5801
|
break;
|
|
5657
|
-
case
|
|
5802
|
+
case AST_NODE_TYPES27.MemberExpression:
|
|
5658
5803
|
current = current.object;
|
|
5659
5804
|
break;
|
|
5660
|
-
case
|
|
5805
|
+
case AST_NODE_TYPES27.Identifier:
|
|
5661
5806
|
return current.name;
|
|
5662
5807
|
default:
|
|
5663
5808
|
return null;
|
|
@@ -5666,26 +5811,26 @@ function rootCallee(node) {
|
|
|
5666
5811
|
return null;
|
|
5667
5812
|
}
|
|
5668
5813
|
function nameOf(key) {
|
|
5669
|
-
if (key.type ===
|
|
5670
|
-
if (key.type ===
|
|
5814
|
+
if (key.type === AST_NODE_TYPES27.Identifier) return key.name;
|
|
5815
|
+
if (key.type === AST_NODE_TYPES27.Literal && typeof key.value === "string") return key.value;
|
|
5671
5816
|
return null;
|
|
5672
5817
|
}
|
|
5673
5818
|
function targetOf(node) {
|
|
5674
5819
|
switch (node.type) {
|
|
5675
|
-
case
|
|
5676
|
-
case
|
|
5820
|
+
case AST_NODE_TYPES27.TSPropertySignature:
|
|
5821
|
+
case AST_NODE_TYPES27.PropertyDefinition: {
|
|
5677
5822
|
const name = node.computed ? null : nameOf(node.key);
|
|
5678
5823
|
if (name === null || !isBareString(node.typeAnnotation?.typeAnnotation)) return null;
|
|
5679
5824
|
return { node, name };
|
|
5680
5825
|
}
|
|
5681
|
-
case
|
|
5826
|
+
case AST_NODE_TYPES27.Property: {
|
|
5682
5827
|
const name = node.computed || node.shorthand ? null : nameOf(node.key);
|
|
5683
5828
|
const callee = rootCallee(node.value);
|
|
5684
5829
|
if (name === null || callee === null || !STRING_BUILDERS.has(callee)) return null;
|
|
5685
5830
|
return { node, name };
|
|
5686
5831
|
}
|
|
5687
|
-
case
|
|
5688
|
-
if (node.id.type !==
|
|
5832
|
+
case AST_NODE_TYPES27.VariableDeclarator: {
|
|
5833
|
+
if (node.id.type !== AST_NODE_TYPES27.Identifier) return null;
|
|
5689
5834
|
if (!isBareString(node.id.typeAnnotation?.typeAnnotation)) return null;
|
|
5690
5835
|
return { node, name: node.id.name };
|
|
5691
5836
|
}
|
|
@@ -5734,7 +5879,7 @@ var no_union_in_comment_default = createRule({
|
|
|
5734
5879
|
if (after === null || after.loc.start.line !== comment.loc.end.line + 1) return null;
|
|
5735
5880
|
anchor = sourceCode.getNodeByRangeIndex(after.range[0]);
|
|
5736
5881
|
}
|
|
5737
|
-
for (let node = anchor; node != null && node.type !==
|
|
5882
|
+
for (let node = anchor; node != null && node.type !== AST_NODE_TYPES27.Program; node = node.parent) {
|
|
5738
5883
|
const target = targetOf(node);
|
|
5739
5884
|
if (target !== null) return target;
|
|
5740
5885
|
}
|
|
@@ -5763,9 +5908,9 @@ var no_union_in_comment_default = createRule({
|
|
|
5763
5908
|
});
|
|
5764
5909
|
|
|
5765
5910
|
// src/rules/no-type-member-comment-wall.ts
|
|
5766
|
-
import { AST_NODE_TYPES as
|
|
5911
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES28 } from "@typescript-eslint/utils";
|
|
5767
5912
|
function isNamedMember(node) {
|
|
5768
|
-
return (node.type ===
|
|
5913
|
+
return (node.type === AST_NODE_TYPES28.TSPropertySignature || node.type === AST_NODE_TYPES28.TSMethodSignature) && !node.computed;
|
|
5769
5914
|
}
|
|
5770
5915
|
var no_type_member_comment_wall_default = createRule({
|
|
5771
5916
|
name: "no-type-member-comment-wall",
|
|
@@ -5812,7 +5957,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5812
5957
|
return headsRun || lineAbove !== void 0 && lineAbove.trim().length === 0;
|
|
5813
5958
|
}
|
|
5814
5959
|
function check(node) {
|
|
5815
|
-
const members = node.type ===
|
|
5960
|
+
const members = node.type === AST_NODE_TYPES28.TSInterfaceBody ? node.body : node.members;
|
|
5816
5961
|
const named2 = members.filter(isNamedMember);
|
|
5817
5962
|
if (named2.length === 0) return;
|
|
5818
5963
|
const documented = named2.map((member) => ({ member, comment: documentingComment(member) }));
|
|
@@ -5852,7 +5997,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5852
5997
|
});
|
|
5853
5998
|
|
|
5854
5999
|
// src/rules/no-unnecessary-use-client.ts
|
|
5855
|
-
import { AST_NODE_TYPES as
|
|
6000
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES29 } from "@typescript-eslint/utils";
|
|
5856
6001
|
var HOOK_REGEX = /^use([A-Z]|$)/;
|
|
5857
6002
|
var EVENT_PROP_REGEX = /^on[A-Z]/;
|
|
5858
6003
|
var ERROR_FILE_REGEX = /\b(?:global-)?error\.[jt]sx?$/;
|
|
@@ -5878,13 +6023,13 @@ var CLIENT_ONLY_PACKAGES_REGEX = /^(?:@radix-ui\/|framer-motion|react-dom|react-
|
|
|
5878
6023
|
var isBareSpecifier = (source) => !source.startsWith(".") && !source.startsWith("/") && !source.startsWith("@/") && !source.startsWith("~");
|
|
5879
6024
|
var jsxRootName = (name) => {
|
|
5880
6025
|
let current = name;
|
|
5881
|
-
while (current.type ===
|
|
6026
|
+
while (current.type === AST_NODE_TYPES29.JSXMemberExpression) {
|
|
5882
6027
|
current = current.object;
|
|
5883
6028
|
}
|
|
5884
|
-
return current.type ===
|
|
6029
|
+
return current.type === AST_NODE_TYPES29.JSXIdentifier ? current.name : "";
|
|
5885
6030
|
};
|
|
5886
6031
|
var subtreeReadsImportedBinding = (node, imported) => {
|
|
5887
|
-
if (node.type ===
|
|
6032
|
+
if (node.type === AST_NODE_TYPES29.Identifier) {
|
|
5888
6033
|
return imported.has(node.name);
|
|
5889
6034
|
}
|
|
5890
6035
|
for (const key of Object.keys(node)) {
|
|
@@ -5899,16 +6044,16 @@ var subtreeReadsImportedBinding = (node, imported) => {
|
|
|
5899
6044
|
return false;
|
|
5900
6045
|
};
|
|
5901
6046
|
var isUseClientDirective = (node) => {
|
|
5902
|
-
return node.type ===
|
|
6047
|
+
return node.type === AST_NODE_TYPES29.ExpressionStatement && node.expression.type === AST_NODE_TYPES29.Literal && node.expression.value === "use client";
|
|
5903
6048
|
};
|
|
5904
6049
|
var isGlobalReference = (node, context) => {
|
|
5905
6050
|
if (!BROWSER_GLOBALS.has(node.name)) return false;
|
|
5906
6051
|
const parent = node.parent;
|
|
5907
6052
|
if (parent !== void 0) {
|
|
5908
|
-
if (parent.type ===
|
|
6053
|
+
if (parent.type === AST_NODE_TYPES29.MemberExpression && parent.property === node && !parent.computed) {
|
|
5909
6054
|
return false;
|
|
5910
6055
|
}
|
|
5911
|
-
if (parent.type ===
|
|
6056
|
+
if (parent.type === AST_NODE_TYPES29.Property && parent.key === node && !parent.computed) {
|
|
5912
6057
|
return false;
|
|
5913
6058
|
}
|
|
5914
6059
|
if (parent.type.startsWith("TS")) {
|
|
@@ -5948,13 +6093,13 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5948
6093
|
const importedLocals = /* @__PURE__ */ new Set();
|
|
5949
6094
|
const externalLocals = /* @__PURE__ */ new Set();
|
|
5950
6095
|
const markIfHookOrContext = (callee) => {
|
|
5951
|
-
if (callee.type ===
|
|
6096
|
+
if (callee.type === AST_NODE_TYPES29.Identifier) {
|
|
5952
6097
|
if (HOOK_REGEX.test(callee.name) || callee.name === "createContext") {
|
|
5953
6098
|
hasClientIndicator = true;
|
|
5954
6099
|
}
|
|
5955
6100
|
return;
|
|
5956
6101
|
}
|
|
5957
|
-
if (callee.type ===
|
|
6102
|
+
if (callee.type === AST_NODE_TYPES29.MemberExpression && callee.property.type === AST_NODE_TYPES29.Identifier) {
|
|
5958
6103
|
const name = callee.property.name;
|
|
5959
6104
|
if (HOOK_REGEX.test(name) || name === "createContext") {
|
|
5960
6105
|
hasClientIndicator = true;
|
|
@@ -5964,7 +6109,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5964
6109
|
return {
|
|
5965
6110
|
Program(node) {
|
|
5966
6111
|
for (const stmt of node.body) {
|
|
5967
|
-
if (stmt.type !==
|
|
6112
|
+
if (stmt.type !== AST_NODE_TYPES29.ExpressionStatement) break;
|
|
5968
6113
|
if (isUseClientDirective(stmt)) {
|
|
5969
6114
|
directiveNode = stmt;
|
|
5970
6115
|
break;
|
|
@@ -5977,7 +6122,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5977
6122
|
},
|
|
5978
6123
|
JSXAttribute(node) {
|
|
5979
6124
|
if (directiveNode === null) return;
|
|
5980
|
-
if (node.name.type ===
|
|
6125
|
+
if (node.name.type === AST_NODE_TYPES29.JSXIdentifier && EVENT_PROP_REGEX.test(node.name.name)) {
|
|
5981
6126
|
hasClientIndicator = true;
|
|
5982
6127
|
}
|
|
5983
6128
|
},
|
|
@@ -6045,17 +6190,17 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
6045
6190
|
|
|
6046
6191
|
// src/rules/no-unsafe-mock-casting.ts
|
|
6047
6192
|
import "@typescript-eslint/utils";
|
|
6048
|
-
import { AST_NODE_TYPES as
|
|
6193
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES30 } from "@typescript-eslint/utils";
|
|
6049
6194
|
function isMockTypeReference(node) {
|
|
6050
|
-
if (node.type !==
|
|
6195
|
+
if (node.type !== AST_NODE_TYPES30.TSTypeReference) {
|
|
6051
6196
|
return false;
|
|
6052
6197
|
}
|
|
6053
6198
|
const typeName = node.typeName;
|
|
6054
|
-
if (typeName.type ===
|
|
6199
|
+
if (typeName.type === AST_NODE_TYPES30.Identifier) {
|
|
6055
6200
|
const name = typeName.name;
|
|
6056
6201
|
return name === "Mock" || name === "MockInstance" || name === "SpyInstance";
|
|
6057
6202
|
}
|
|
6058
|
-
if (typeName.type ===
|
|
6203
|
+
if (typeName.type === AST_NODE_TYPES30.TSQualifiedName) {
|
|
6059
6204
|
const rightName = typeName.right.name;
|
|
6060
6205
|
return rightName === "Mock" || rightName === "MockInstance" || rightName === "SpyInstance";
|
|
6061
6206
|
}
|
|
@@ -6093,7 +6238,7 @@ var no_unsafe_mock_casting_default = createRule({
|
|
|
6093
6238
|
// src/rules/no-zod-native-enum.ts
|
|
6094
6239
|
import {
|
|
6095
6240
|
ESLintUtils as ESLintUtils2,
|
|
6096
|
-
AST_NODE_TYPES as
|
|
6241
|
+
AST_NODE_TYPES as AST_NODE_TYPES31
|
|
6097
6242
|
} from "@typescript-eslint/utils";
|
|
6098
6243
|
import * as ts from "typescript";
|
|
6099
6244
|
var IGNORE_PATTERNS = [
|
|
@@ -6112,7 +6257,7 @@ function isZodModule(source) {
|
|
|
6112
6257
|
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
6113
6258
|
}
|
|
6114
6259
|
function unwrap2(node) {
|
|
6115
|
-
if (node.type ===
|
|
6260
|
+
if (node.type === AST_NODE_TYPES31.TSAsExpression || node.type === AST_NODE_TYPES31.TSSatisfiesExpression) {
|
|
6116
6261
|
return unwrap2(node.expression);
|
|
6117
6262
|
}
|
|
6118
6263
|
return node;
|
|
@@ -6120,14 +6265,14 @@ function unwrap2(node) {
|
|
|
6120
6265
|
function stringValueTexts(node, sourceCode) {
|
|
6121
6266
|
const texts = [];
|
|
6122
6267
|
for (const prop of node.properties) {
|
|
6123
|
-
if (prop.type !==
|
|
6268
|
+
if (prop.type !== AST_NODE_TYPES31.Property) {
|
|
6124
6269
|
return null;
|
|
6125
6270
|
}
|
|
6126
6271
|
if (prop.computed || prop.shorthand || prop.method || prop.kind !== "init") {
|
|
6127
6272
|
return null;
|
|
6128
6273
|
}
|
|
6129
6274
|
const value = prop.value;
|
|
6130
|
-
if (value.type !==
|
|
6275
|
+
if (value.type !== AST_NODE_TYPES31.Literal || typeof value.value !== "string") {
|
|
6131
6276
|
return null;
|
|
6132
6277
|
}
|
|
6133
6278
|
const text = sourceCode.getText(value);
|
|
@@ -6143,7 +6288,7 @@ function resolvesToLocalEnum(node, scope) {
|
|
|
6143
6288
|
const variable = current.variables.find((v) => v.name === node.name);
|
|
6144
6289
|
if (variable !== void 0) {
|
|
6145
6290
|
return variable.defs.some(
|
|
6146
|
-
(def) => def.node.type ===
|
|
6291
|
+
(def) => def.node.type === AST_NODE_TYPES31.TSEnumDeclaration
|
|
6147
6292
|
);
|
|
6148
6293
|
}
|
|
6149
6294
|
current = current.upper;
|
|
@@ -6195,25 +6340,25 @@ var no_zod_native_enum_default = createRule({
|
|
|
6195
6340
|
const zodImportedNames = /* @__PURE__ */ new Map();
|
|
6196
6341
|
function isZodMemberCall(node, api) {
|
|
6197
6342
|
const callee = node.callee;
|
|
6198
|
-
if (callee.type ===
|
|
6343
|
+
if (callee.type === AST_NODE_TYPES31.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES31.Identifier) {
|
|
6199
6344
|
return callee.property.name === api;
|
|
6200
6345
|
}
|
|
6201
|
-
if (callee.type ===
|
|
6346
|
+
if (callee.type === AST_NODE_TYPES31.Identifier) {
|
|
6202
6347
|
return zodImportedNames.get(callee.name) === api;
|
|
6203
6348
|
}
|
|
6204
6349
|
return false;
|
|
6205
6350
|
}
|
|
6206
6351
|
function buildFix(node) {
|
|
6207
6352
|
const callee = node.callee;
|
|
6208
|
-
if (callee.type !==
|
|
6353
|
+
if (callee.type !== AST_NODE_TYPES31.MemberExpression || callee.property.type !== AST_NODE_TYPES31.Identifier) {
|
|
6209
6354
|
return null;
|
|
6210
6355
|
}
|
|
6211
6356
|
const arg = node.arguments[0];
|
|
6212
|
-
if (arg === void 0 || node.arguments.length !== 1 || arg.type ===
|
|
6357
|
+
if (arg === void 0 || node.arguments.length !== 1 || arg.type === AST_NODE_TYPES31.SpreadElement) {
|
|
6213
6358
|
return null;
|
|
6214
6359
|
}
|
|
6215
6360
|
const inner = unwrap2(arg);
|
|
6216
|
-
if (inner.type !==
|
|
6361
|
+
if (inner.type !== AST_NODE_TYPES31.ObjectExpression) {
|
|
6217
6362
|
return null;
|
|
6218
6363
|
}
|
|
6219
6364
|
const values = stringValueTexts(inner, sourceCode);
|
|
@@ -6233,7 +6378,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
6233
6378
|
return;
|
|
6234
6379
|
}
|
|
6235
6380
|
for (const spec of node.specifiers) {
|
|
6236
|
-
if (spec.type ===
|
|
6381
|
+
if (spec.type === AST_NODE_TYPES31.ImportSpecifier && spec.imported.type === AST_NODE_TYPES31.Identifier) {
|
|
6237
6382
|
zodImportedNames.set(spec.local.name, spec.imported.name);
|
|
6238
6383
|
}
|
|
6239
6384
|
}
|
|
@@ -6252,7 +6397,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
6252
6397
|
return;
|
|
6253
6398
|
}
|
|
6254
6399
|
const arg = node.arguments[0];
|
|
6255
|
-
if (arg === void 0 || arg.type !==
|
|
6400
|
+
if (arg === void 0 || arg.type !== AST_NODE_TYPES31.Identifier) {
|
|
6256
6401
|
return;
|
|
6257
6402
|
}
|
|
6258
6403
|
const isEnum = resolvesToLocalEnum(arg, sourceCode.getScope(arg)) || services !== null && resolvesToImportedEnum(arg, services);
|
|
@@ -6269,7 +6414,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
6269
6414
|
});
|
|
6270
6415
|
|
|
6271
6416
|
// src/rules/prefer-constant-time-secret-compare.ts
|
|
6272
|
-
import { AST_NODE_TYPES as
|
|
6417
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES32 } from "@typescript-eslint/utils";
|
|
6273
6418
|
var EQUALITY_OPERATORS = /* @__PURE__ */ new Set(["===", "!==", "==", "!="]);
|
|
6274
6419
|
var SENTINEL_IDENTIFIERS = /* @__PURE__ */ new Set(["undefined", "NaN"]);
|
|
6275
6420
|
var SENTINEL_WORDS = /(^|_)(SENTINEL|EMPTY|NONE|NULL|UNSET|MISSING|PLACEHOLDER|DUMMY|FAKE|EXAMPLE)(_|$)/;
|
|
@@ -6282,36 +6427,36 @@ function isConstantReference(identifier) {
|
|
|
6282
6427
|
}
|
|
6283
6428
|
function isExcludedOperand(node) {
|
|
6284
6429
|
switch (node.type) {
|
|
6285
|
-
case
|
|
6430
|
+
case AST_NODE_TYPES32.Literal:
|
|
6286
6431
|
return true;
|
|
6287
|
-
case
|
|
6432
|
+
case AST_NODE_TYPES32.TemplateLiteral:
|
|
6288
6433
|
return node.expressions.length === 0;
|
|
6289
|
-
case
|
|
6434
|
+
case AST_NODE_TYPES32.Identifier:
|
|
6290
6435
|
return SENTINEL_IDENTIFIERS.has(node.name) || SENTINEL_PREFIX_RE.test(node.name) || isConstantReference(node.name);
|
|
6291
|
-
case
|
|
6292
|
-
return !node.computed && node.property.type ===
|
|
6436
|
+
case AST_NODE_TYPES32.MemberExpression:
|
|
6437
|
+
return !node.computed && node.property.type === AST_NODE_TYPES32.Identifier && (SENTINEL_PREFIX_RE.test(node.property.name) || isConstantReference(node.property.name));
|
|
6293
6438
|
default:
|
|
6294
6439
|
return false;
|
|
6295
6440
|
}
|
|
6296
6441
|
}
|
|
6297
6442
|
function operandName(node) {
|
|
6298
|
-
if (node.type ===
|
|
6443
|
+
if (node.type === AST_NODE_TYPES32.Identifier) {
|
|
6299
6444
|
return node.name;
|
|
6300
6445
|
}
|
|
6301
|
-
if (node.type ===
|
|
6446
|
+
if (node.type === AST_NODE_TYPES32.MemberExpression && !node.computed && node.property.type === AST_NODE_TYPES32.Identifier) {
|
|
6302
6447
|
return node.property.name;
|
|
6303
6448
|
}
|
|
6304
6449
|
return null;
|
|
6305
6450
|
}
|
|
6306
6451
|
function isSecretOperand(node) {
|
|
6307
|
-
if (node.type ===
|
|
6452
|
+
if (node.type === AST_NODE_TYPES32.TemplateLiteral) {
|
|
6308
6453
|
return node.expressions.some((expression) => isSecretOperand(expression));
|
|
6309
6454
|
}
|
|
6310
6455
|
const name = operandName(node);
|
|
6311
6456
|
return name !== null && isAuthSecretName(name);
|
|
6312
6457
|
}
|
|
6313
6458
|
function secretNameOf(node) {
|
|
6314
|
-
if (node.type ===
|
|
6459
|
+
if (node.type === AST_NODE_TYPES32.TemplateLiteral) {
|
|
6315
6460
|
for (const expression of node.expressions) {
|
|
6316
6461
|
const nested = secretNameOf(expression);
|
|
6317
6462
|
if (nested !== null) {
|
|
@@ -6364,7 +6509,7 @@ var prefer_constant_time_secret_compare_default = createRule({
|
|
|
6364
6509
|
|
|
6365
6510
|
// src/rules/prefer-discriminated-union.ts
|
|
6366
6511
|
import "@typescript-eslint/utils";
|
|
6367
|
-
import { AST_NODE_TYPES as
|
|
6512
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES33 } from "@typescript-eslint/utils";
|
|
6368
6513
|
var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
6369
6514
|
"success",
|
|
6370
6515
|
"ok",
|
|
@@ -6374,27 +6519,27 @@ var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
|
6374
6519
|
]);
|
|
6375
6520
|
var MIN_OPTIONAL_MEMBERS = 2;
|
|
6376
6521
|
function getMemberName(member) {
|
|
6377
|
-
if (member.type !==
|
|
6522
|
+
if (member.type !== AST_NODE_TYPES33.TSPropertySignature) {
|
|
6378
6523
|
return null;
|
|
6379
6524
|
}
|
|
6380
6525
|
const { key } = member;
|
|
6381
|
-
if (key.type ===
|
|
6526
|
+
if (key.type === AST_NODE_TYPES33.Identifier) {
|
|
6382
6527
|
return key.name;
|
|
6383
6528
|
}
|
|
6384
|
-
if (key.type ===
|
|
6529
|
+
if (key.type === AST_NODE_TYPES33.Literal && typeof key.value === "string") {
|
|
6385
6530
|
return key.value;
|
|
6386
6531
|
}
|
|
6387
6532
|
return null;
|
|
6388
6533
|
}
|
|
6389
6534
|
function isBooleanTyped(member) {
|
|
6390
|
-
return member.typeAnnotation?.typeAnnotation.type ===
|
|
6535
|
+
return member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES33.TSBooleanKeyword;
|
|
6391
6536
|
}
|
|
6392
6537
|
function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
6393
6538
|
let hasStatusBoolean = false;
|
|
6394
6539
|
let optionalCount = 0;
|
|
6395
6540
|
let optionalPayloadCount = 0;
|
|
6396
6541
|
for (const member of typeLiteral.members) {
|
|
6397
|
-
if (member.type !==
|
|
6542
|
+
if (member.type !== AST_NODE_TYPES33.TSPropertySignature) {
|
|
6398
6543
|
continue;
|
|
6399
6544
|
}
|
|
6400
6545
|
if (member.optional) {
|
|
@@ -6436,7 +6581,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
6436
6581
|
TSInterfaceDeclaration(node) {
|
|
6437
6582
|
const synthetic = {
|
|
6438
6583
|
...node.body,
|
|
6439
|
-
type:
|
|
6584
|
+
type: AST_NODE_TYPES33.TSTypeLiteral,
|
|
6440
6585
|
members: node.body.body
|
|
6441
6586
|
};
|
|
6442
6587
|
checkTypeLiteral(synthetic, node);
|
|
@@ -6449,7 +6594,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
6449
6594
|
});
|
|
6450
6595
|
|
|
6451
6596
|
// src/rules/prefer-module-level-constant.ts
|
|
6452
|
-
import { AST_NODE_TYPES as
|
|
6597
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES34 } from "@typescript-eslint/utils";
|
|
6453
6598
|
var DEFAULT_MIN_ELEMENTS = 3;
|
|
6454
6599
|
var MAX_LITERAL_DEPTH = 4;
|
|
6455
6600
|
var IGNORE_PATTERNS2 = [
|
|
@@ -6478,9 +6623,9 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
|
6478
6623
|
"assign"
|
|
6479
6624
|
]);
|
|
6480
6625
|
var FUNCTION_TYPES5 = /* @__PURE__ */ new Set([
|
|
6481
|
-
|
|
6482
|
-
|
|
6483
|
-
|
|
6626
|
+
AST_NODE_TYPES34.FunctionDeclaration,
|
|
6627
|
+
AST_NODE_TYPES34.FunctionExpression,
|
|
6628
|
+
AST_NODE_TYPES34.ArrowFunctionExpression
|
|
6484
6629
|
]);
|
|
6485
6630
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
6486
6631
|
function isIgnoredFile2(filename, sourceText) {
|
|
@@ -6493,14 +6638,14 @@ function isLocalFixtureFile(filename) {
|
|
|
6493
6638
|
return isTestFile(filename) || isStoryFile(filename);
|
|
6494
6639
|
}
|
|
6495
6640
|
function unwrap3(node) {
|
|
6496
|
-
if (node.type ===
|
|
6641
|
+
if (node.type === AST_NODE_TYPES34.TSAsExpression || node.type === AST_NODE_TYPES34.TSSatisfiesExpression || node.type === AST_NODE_TYPES34.TSNonNullExpression) {
|
|
6497
6642
|
return unwrap3(node.expression);
|
|
6498
6643
|
}
|
|
6499
6644
|
return node;
|
|
6500
6645
|
}
|
|
6501
6646
|
var HAS_STATEFUL_FLAG_RE = /[gy]/;
|
|
6502
6647
|
function isRegexLiteral(node) {
|
|
6503
|
-
return node.type ===
|
|
6648
|
+
return node.type === AST_NODE_TYPES34.Literal && "regex" in node && node.regex !== void 0;
|
|
6504
6649
|
}
|
|
6505
6650
|
function isLiteralOnly(node, depth) {
|
|
6506
6651
|
if (depth > MAX_LITERAL_DEPTH) {
|
|
@@ -6508,29 +6653,29 @@ function isLiteralOnly(node, depth) {
|
|
|
6508
6653
|
}
|
|
6509
6654
|
const inner = unwrap3(node);
|
|
6510
6655
|
switch (inner.type) {
|
|
6511
|
-
case
|
|
6656
|
+
case AST_NODE_TYPES34.Literal: {
|
|
6512
6657
|
return !(isRegexLiteral(inner) && HAS_STATEFUL_FLAG_RE.test(inner.regex.flags));
|
|
6513
6658
|
}
|
|
6514
|
-
case
|
|
6659
|
+
case AST_NODE_TYPES34.TemplateLiteral: {
|
|
6515
6660
|
return inner.expressions.length === 0;
|
|
6516
6661
|
}
|
|
6517
|
-
case
|
|
6518
|
-
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type ===
|
|
6662
|
+
case AST_NODE_TYPES34.UnaryExpression: {
|
|
6663
|
+
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type === AST_NODE_TYPES34.Literal && typeof inner.argument.value === "number";
|
|
6519
6664
|
}
|
|
6520
|
-
case
|
|
6665
|
+
case AST_NODE_TYPES34.ArrayExpression: {
|
|
6521
6666
|
return inner.elements.every(
|
|
6522
|
-
(el) => el !== null && el.type !==
|
|
6667
|
+
(el) => el !== null && el.type !== AST_NODE_TYPES34.SpreadElement && isLiteralOnly(el, depth + 1)
|
|
6523
6668
|
);
|
|
6524
6669
|
}
|
|
6525
|
-
case
|
|
6670
|
+
case AST_NODE_TYPES34.ObjectExpression: {
|
|
6526
6671
|
return inner.properties.every((prop) => {
|
|
6527
|
-
if (prop.type !==
|
|
6672
|
+
if (prop.type !== AST_NODE_TYPES34.Property) {
|
|
6528
6673
|
return false;
|
|
6529
6674
|
}
|
|
6530
6675
|
if (prop.shorthand || prop.method || prop.kind !== "init") {
|
|
6531
6676
|
return false;
|
|
6532
6677
|
}
|
|
6533
|
-
if (prop.computed && prop.key.type !==
|
|
6678
|
+
if (prop.computed && prop.key.type !== AST_NODE_TYPES34.Literal) {
|
|
6534
6679
|
return false;
|
|
6535
6680
|
}
|
|
6536
6681
|
return isLiteralOnly(prop.value, depth + 1);
|
|
@@ -6543,7 +6688,7 @@ function isLiteralOnly(node, depth) {
|
|
|
6543
6688
|
}
|
|
6544
6689
|
function unwrapObjectFreeze(node) {
|
|
6545
6690
|
const inner = unwrap3(node);
|
|
6546
|
-
if (inner.type ===
|
|
6691
|
+
if (inner.type === AST_NODE_TYPES34.CallExpression && inner.callee.type === AST_NODE_TYPES34.MemberExpression && !inner.callee.computed && inner.callee.object.type === AST_NODE_TYPES34.Identifier && inner.callee.object.name === "Object" && inner.callee.property.type === AST_NODE_TYPES34.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== AST_NODE_TYPES34.SpreadElement) {
|
|
6547
6692
|
return unwrap3(inner.arguments[0]);
|
|
6548
6693
|
}
|
|
6549
6694
|
return inner;
|
|
@@ -6559,19 +6704,19 @@ function classify(init, checkRegex) {
|
|
|
6559
6704
|
}
|
|
6560
6705
|
return { kind: "regex", size: 1 };
|
|
6561
6706
|
}
|
|
6562
|
-
if (node.type ===
|
|
6707
|
+
if (node.type === AST_NODE_TYPES34.ArrayExpression) {
|
|
6563
6708
|
return isLiteralOnly(node, 0) ? { kind: "array", size: node.elements.length } : null;
|
|
6564
6709
|
}
|
|
6565
|
-
if (node.type ===
|
|
6710
|
+
if (node.type === AST_NODE_TYPES34.ObjectExpression) {
|
|
6566
6711
|
return isLiteralOnly(node, 0) ? { kind: "object", size: node.properties.length } : null;
|
|
6567
6712
|
}
|
|
6568
|
-
if (node.type ===
|
|
6713
|
+
if (node.type === AST_NODE_TYPES34.NewExpression && node.callee.type === AST_NODE_TYPES34.Identifier && COLLECTION_CONSTRUCTORS.has(node.callee.name)) {
|
|
6569
6714
|
const arg = node.arguments[0];
|
|
6570
|
-
if (node.arguments.length !== 1 || arg === void 0 || arg.type ===
|
|
6715
|
+
if (node.arguments.length !== 1 || arg === void 0 || arg.type === AST_NODE_TYPES34.SpreadElement) {
|
|
6571
6716
|
return null;
|
|
6572
6717
|
}
|
|
6573
6718
|
const entries = unwrap3(arg);
|
|
6574
|
-
if (entries.type !==
|
|
6719
|
+
if (entries.type !== AST_NODE_TYPES34.ArrayExpression) {
|
|
6575
6720
|
return null;
|
|
6576
6721
|
}
|
|
6577
6722
|
return isLiteralOnly(entries, 0) ? { kind: node.callee.name === "Set" ? "Set" : "Map", size: entries.elements.length } : null;
|
|
@@ -6600,10 +6745,10 @@ var NON_RETAINING_BUILTINS = /* @__PURE__ */ new Map(
|
|
|
6600
6745
|
);
|
|
6601
6746
|
function isNonRetainingBuiltinCall(node, argument) {
|
|
6602
6747
|
const callee = node.callee;
|
|
6603
|
-
if (callee.type ===
|
|
6748
|
+
if (callee.type === AST_NODE_TYPES34.Identifier && callee.name === "structuredClone") {
|
|
6604
6749
|
return true;
|
|
6605
6750
|
}
|
|
6606
|
-
if (callee.type !==
|
|
6751
|
+
if (callee.type !== AST_NODE_TYPES34.MemberExpression || callee.computed || callee.object.type !== AST_NODE_TYPES34.Identifier || callee.property.type !== AST_NODE_TYPES34.Identifier) {
|
|
6607
6752
|
return false;
|
|
6608
6753
|
}
|
|
6609
6754
|
const members = NON_RETAINING_BUILTINS.get(callee.object.name);
|
|
@@ -6617,38 +6762,38 @@ function isNonRetainingBuiltinCall(node, argument) {
|
|
|
6617
6762
|
}
|
|
6618
6763
|
function isSafeRead(identifier) {
|
|
6619
6764
|
const parent = identifier.parent;
|
|
6620
|
-
if (parent.type ===
|
|
6765
|
+
if (parent.type === AST_NODE_TYPES34.MemberExpression) {
|
|
6621
6766
|
if (parent.object !== identifier) {
|
|
6622
6767
|
return true;
|
|
6623
6768
|
}
|
|
6624
6769
|
const grandparent = parent.parent;
|
|
6625
|
-
if (grandparent.type ===
|
|
6770
|
+
if (grandparent.type === AST_NODE_TYPES34.AssignmentExpression && grandparent.left === parent) {
|
|
6626
6771
|
return false;
|
|
6627
6772
|
}
|
|
6628
|
-
if (grandparent.type ===
|
|
6773
|
+
if (grandparent.type === AST_NODE_TYPES34.UpdateExpression) {
|
|
6629
6774
|
return false;
|
|
6630
6775
|
}
|
|
6631
|
-
if (grandparent.type ===
|
|
6776
|
+
if (grandparent.type === AST_NODE_TYPES34.UnaryExpression && grandparent.operator === "delete") {
|
|
6632
6777
|
return false;
|
|
6633
6778
|
}
|
|
6634
|
-
if (!parent.computed && parent.property.type ===
|
|
6779
|
+
if (!parent.computed && parent.property.type === AST_NODE_TYPES34.Identifier && MUTATING_METHODS.has(parent.property.name) && grandparent.type === AST_NODE_TYPES34.CallExpression && grandparent.callee === parent) {
|
|
6635
6780
|
return false;
|
|
6636
6781
|
}
|
|
6637
6782
|
return true;
|
|
6638
6783
|
}
|
|
6639
|
-
if (parent.type ===
|
|
6784
|
+
if (parent.type === AST_NODE_TYPES34.ForOfStatement && parent.right === identifier) {
|
|
6640
6785
|
return true;
|
|
6641
6786
|
}
|
|
6642
|
-
if (parent.type ===
|
|
6787
|
+
if (parent.type === AST_NODE_TYPES34.SpreadElement) {
|
|
6643
6788
|
return true;
|
|
6644
6789
|
}
|
|
6645
|
-
if (parent.type ===
|
|
6790
|
+
if (parent.type === AST_NODE_TYPES34.BinaryExpression) {
|
|
6646
6791
|
return true;
|
|
6647
6792
|
}
|
|
6648
|
-
if (parent.type ===
|
|
6793
|
+
if (parent.type === AST_NODE_TYPES34.CallExpression && parent.arguments.includes(identifier) && isNonRetainingBuiltinCall(parent, identifier)) {
|
|
6649
6794
|
return true;
|
|
6650
6795
|
}
|
|
6651
|
-
if (parent.type ===
|
|
6796
|
+
if (parent.type === AST_NODE_TYPES34.UnaryExpression && parent.operator !== "delete") {
|
|
6652
6797
|
return true;
|
|
6653
6798
|
}
|
|
6654
6799
|
return false;
|
|
@@ -6703,7 +6848,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6703
6848
|
if (reference.isWrite()) {
|
|
6704
6849
|
return false;
|
|
6705
6850
|
}
|
|
6706
|
-
if (reference.identifier.type !==
|
|
6851
|
+
if (reference.identifier.type !== AST_NODE_TYPES34.Identifier) {
|
|
6707
6852
|
return false;
|
|
6708
6853
|
}
|
|
6709
6854
|
if (!isSafeRead(reference.identifier)) {
|
|
@@ -6715,10 +6860,10 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6715
6860
|
return {
|
|
6716
6861
|
VariableDeclarator(node) {
|
|
6717
6862
|
const declaration = node.parent;
|
|
6718
|
-
if (declaration.type !==
|
|
6863
|
+
if (declaration.type !== AST_NODE_TYPES34.VariableDeclaration || declaration.kind !== "const" || declaration.declare === true) {
|
|
6719
6864
|
return;
|
|
6720
6865
|
}
|
|
6721
|
-
if (node.id.type !==
|
|
6866
|
+
if (node.id.type !== AST_NODE_TYPES34.Identifier || node.init === null) {
|
|
6722
6867
|
return;
|
|
6723
6868
|
}
|
|
6724
6869
|
if (enclosingFunction2(node) === null) {
|
|
@@ -6745,7 +6890,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6745
6890
|
});
|
|
6746
6891
|
|
|
6747
6892
|
// src/rules/prefer-module-level-schema.ts
|
|
6748
|
-
import { AST_NODE_TYPES as
|
|
6893
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES35 } from "@typescript-eslint/utils";
|
|
6749
6894
|
|
|
6750
6895
|
// src/rules/_zod.ts
|
|
6751
6896
|
var ZOD_PREFIX_RE = /^Z[A-Z]/;
|
|
@@ -6811,9 +6956,9 @@ var I18N_RECEIVER_NAMES = /* @__PURE__ */ new Set([
|
|
|
6811
6956
|
"intl"
|
|
6812
6957
|
]);
|
|
6813
6958
|
var FUNCTION_TYPES6 = /* @__PURE__ */ new Set([
|
|
6814
|
-
|
|
6815
|
-
|
|
6816
|
-
|
|
6959
|
+
AST_NODE_TYPES35.ArrowFunctionExpression,
|
|
6960
|
+
AST_NODE_TYPES35.FunctionDeclaration,
|
|
6961
|
+
AST_NODE_TYPES35.FunctionExpression
|
|
6817
6962
|
]);
|
|
6818
6963
|
function schemaExpression(node) {
|
|
6819
6964
|
let current = node;
|
|
@@ -6822,10 +6967,10 @@ function schemaExpression(node) {
|
|
|
6822
6967
|
if (parent === void 0) {
|
|
6823
6968
|
return current;
|
|
6824
6969
|
}
|
|
6825
|
-
if (parent.type ===
|
|
6970
|
+
if (parent.type === AST_NODE_TYPES35.MemberExpression && parent.object === current && !parent.computed && parent.property.type === AST_NODE_TYPES35.Identifier && TERMINAL_METHODS.has(parent.property.name)) {
|
|
6826
6971
|
return current;
|
|
6827
6972
|
}
|
|
6828
|
-
if (parent.type ===
|
|
6973
|
+
if (parent.type === AST_NODE_TYPES35.MemberExpression && parent.object === current || parent.type === AST_NODE_TYPES35.CallExpression && parent.callee === current || parent.type === AST_NODE_TYPES35.TSAsExpression && parent.expression === current || parent.type === AST_NODE_TYPES35.TSNonNullExpression && parent.expression === current) {
|
|
6829
6974
|
current = parent;
|
|
6830
6975
|
continue;
|
|
6831
6976
|
}
|
|
@@ -6876,22 +7021,22 @@ function subtreeSome(root, predicate) {
|
|
|
6876
7021
|
function readsReceiver(node) {
|
|
6877
7022
|
return subtreeSome(
|
|
6878
7023
|
node,
|
|
6879
|
-
(inner) => inner.type ===
|
|
7024
|
+
(inner) => inner.type === AST_NODE_TYPES35.ThisExpression || inner.type === AST_NODE_TYPES35.Super || inner.type === AST_NODE_TYPES35.Identifier && inner.name === "arguments"
|
|
6880
7025
|
);
|
|
6881
7026
|
}
|
|
6882
7027
|
function buildsLocalizedText(node) {
|
|
6883
7028
|
return subtreeSome(node, (inner) => {
|
|
6884
|
-
if (inner.type ===
|
|
7029
|
+
if (inner.type === AST_NODE_TYPES35.TaggedTemplateExpression) {
|
|
6885
7030
|
return true;
|
|
6886
7031
|
}
|
|
6887
|
-
if (inner.type !==
|
|
7032
|
+
if (inner.type !== AST_NODE_TYPES35.CallExpression) {
|
|
6888
7033
|
return false;
|
|
6889
7034
|
}
|
|
6890
7035
|
const { callee } = inner;
|
|
6891
|
-
if (callee.type ===
|
|
7036
|
+
if (callee.type === AST_NODE_TYPES35.Identifier) {
|
|
6892
7037
|
return I18N_CALLEE_NAMES.has(callee.name);
|
|
6893
7038
|
}
|
|
6894
|
-
return callee.type ===
|
|
7039
|
+
return callee.type === AST_NODE_TYPES35.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES35.Identifier && I18N_RECEIVER_NAMES.has(callee.object.name);
|
|
6895
7040
|
});
|
|
6896
7041
|
}
|
|
6897
7042
|
function collectReferences(scope, out) {
|
|
@@ -6948,15 +7093,15 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6948
7093
|
}
|
|
6949
7094
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
6950
7095
|
function isZodCall(node) {
|
|
6951
|
-
return node.type ===
|
|
7096
|
+
return node.type === AST_NODE_TYPES35.CallExpression && node.callee.type === AST_NODE_TYPES35.MemberExpression && !node.callee.computed && node.callee.object.type === AST_NODE_TYPES35.Identifier && zodNamespaces.has(node.callee.object.name);
|
|
6952
7097
|
}
|
|
6953
7098
|
function isCovered(node) {
|
|
6954
7099
|
let current = node.parent ?? void 0;
|
|
6955
7100
|
while (current !== void 0) {
|
|
6956
|
-
if (current !== node && isZodCall(current) && current.callee.type ===
|
|
7101
|
+
if (current !== node && isZodCall(current) && current.callee.type === AST_NODE_TYPES35.MemberExpression && current.callee.property.type === AST_NODE_TYPES35.Identifier && factories.has(current.callee.property.name)) {
|
|
6957
7102
|
return true;
|
|
6958
7103
|
}
|
|
6959
|
-
if (current.type ===
|
|
7104
|
+
if (current.type === AST_NODE_TYPES35.CallExpression && (current.callee.type === AST_NODE_TYPES35.Identifier && MEMO_CALLEES.has(current.callee.name) || current.callee.type === AST_NODE_TYPES35.MemberExpression && !current.callee.computed && current.callee.property.type === AST_NODE_TYPES35.Identifier && MEMO_CALLEES.has(current.callee.property.name))) {
|
|
6960
7105
|
return true;
|
|
6961
7106
|
}
|
|
6962
7107
|
current = current.parent ?? void 0;
|
|
@@ -6971,11 +7116,11 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6971
7116
|
if (parent === void 0) {
|
|
6972
7117
|
return confirmed;
|
|
6973
7118
|
}
|
|
6974
|
-
if (parent.type ===
|
|
7119
|
+
if (parent.type === AST_NODE_TYPES35.Property && parent.value === current || parent.type === AST_NODE_TYPES35.ObjectExpression || parent.type === AST_NODE_TYPES35.ArrayExpression) {
|
|
6975
7120
|
current = parent;
|
|
6976
7121
|
continue;
|
|
6977
7122
|
}
|
|
6978
|
-
if (parent.type ===
|
|
7123
|
+
if (parent.type === AST_NODE_TYPES35.CallExpression && parent.arguments.includes(current) && isSchemaComposition(parent)) {
|
|
6979
7124
|
current = schemaExpression(parent);
|
|
6980
7125
|
confirmed = current;
|
|
6981
7126
|
continue;
|
|
@@ -6985,7 +7130,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6985
7130
|
}
|
|
6986
7131
|
function isSchemaComposition(node) {
|
|
6987
7132
|
const { callee } = node;
|
|
6988
|
-
const isCombinator = callee.type ===
|
|
7133
|
+
const isCombinator = callee.type === AST_NODE_TYPES35.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES35.Identifier && ZOD_COMBINATOR_METHODS.has(callee.property.name);
|
|
6989
7134
|
return isCombinator || isZodCall(node);
|
|
6990
7135
|
}
|
|
6991
7136
|
function closesOverNothing(node, enclosing) {
|
|
@@ -7019,13 +7164,13 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7019
7164
|
}
|
|
7020
7165
|
function ownerName(enclosing) {
|
|
7021
7166
|
const parent = enclosing.parent ?? void 0;
|
|
7022
|
-
if (enclosing.type ===
|
|
7167
|
+
if (enclosing.type === AST_NODE_TYPES35.FunctionDeclaration && enclosing.id !== null) {
|
|
7023
7168
|
return enclosing.id.name;
|
|
7024
7169
|
}
|
|
7025
|
-
if (parent !== void 0 && parent.type ===
|
|
7170
|
+
if (parent !== void 0 && parent.type === AST_NODE_TYPES35.VariableDeclarator && parent.id.type === AST_NODE_TYPES35.Identifier) {
|
|
7026
7171
|
return parent.id.name;
|
|
7027
7172
|
}
|
|
7028
|
-
if (parent !== void 0 && (parent.type ===
|
|
7173
|
+
if (parent !== void 0 && (parent.type === AST_NODE_TYPES35.MethodDefinition || parent.type === AST_NODE_TYPES35.Property) && parent.key.type === AST_NODE_TYPES35.Identifier) {
|
|
7029
7174
|
return parent.key.name;
|
|
7030
7175
|
}
|
|
7031
7176
|
return "this function";
|
|
@@ -7036,7 +7181,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7036
7181
|
return;
|
|
7037
7182
|
}
|
|
7038
7183
|
for (const specifier of node.specifiers) {
|
|
7039
|
-
if (specifier.type ===
|
|
7184
|
+
if (specifier.type === AST_NODE_TYPES35.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES35.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES35.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES35.Identifier && specifier.imported.name === "z") {
|
|
7040
7185
|
zodNamespaces.add(specifier.local.name);
|
|
7041
7186
|
}
|
|
7042
7187
|
}
|
|
@@ -7046,7 +7191,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7046
7191
|
return;
|
|
7047
7192
|
}
|
|
7048
7193
|
const callee = node.callee;
|
|
7049
|
-
if (callee.property.type !==
|
|
7194
|
+
if (callee.property.type !== AST_NODE_TYPES35.Identifier) {
|
|
7050
7195
|
return;
|
|
7051
7196
|
}
|
|
7052
7197
|
const factory = callee.property.name;
|
|
@@ -7061,7 +7206,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7061
7206
|
return;
|
|
7062
7207
|
}
|
|
7063
7208
|
const shape = node.arguments[0];
|
|
7064
|
-
if (shape !== void 0 && shape.type ===
|
|
7209
|
+
if (shape !== void 0 && shape.type === AST_NODE_TYPES35.ObjectExpression && shape.properties.length < minProperties) {
|
|
7065
7210
|
return;
|
|
7066
7211
|
}
|
|
7067
7212
|
const expression = schemaExpression(node);
|
|
@@ -7089,20 +7234,20 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7089
7234
|
});
|
|
7090
7235
|
|
|
7091
7236
|
// src/rules/prefer-non-nullable-collection.ts
|
|
7092
|
-
import { AST_NODE_TYPES as
|
|
7237
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES36 } from "@typescript-eslint/utils";
|
|
7093
7238
|
var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
7094
7239
|
function propertyName(node) {
|
|
7095
7240
|
const key = node.key;
|
|
7096
|
-
if (key.type ===
|
|
7097
|
-
if (key.type ===
|
|
7241
|
+
if (key.type === AST_NODE_TYPES36.Identifier) return key.name;
|
|
7242
|
+
if (key.type === AST_NODE_TYPES36.Literal) return String(key.value);
|
|
7098
7243
|
return "collection";
|
|
7099
7244
|
}
|
|
7100
7245
|
function isArrayType(node) {
|
|
7101
|
-
if (node.type ===
|
|
7102
|
-
return node.type ===
|
|
7246
|
+
if (node.type === AST_NODE_TYPES36.TSArrayType) return true;
|
|
7247
|
+
return node.type === AST_NODE_TYPES36.TSTypeReference && node.typeName.type === AST_NODE_TYPES36.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
7103
7248
|
}
|
|
7104
7249
|
function isNullishType(node) {
|
|
7105
|
-
return node.type ===
|
|
7250
|
+
return node.type === AST_NODE_TYPES36.TSNullKeyword || node.type === AST_NODE_TYPES36.TSUndefinedKeyword;
|
|
7106
7251
|
}
|
|
7107
7252
|
function isNullableArrayOnly(node) {
|
|
7108
7253
|
const values = node.types.filter((member) => !isNullishType(member));
|
|
@@ -7130,7 +7275,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
7130
7275
|
if (node.optional) return;
|
|
7131
7276
|
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
7132
7277
|
if (annotation === void 0) return;
|
|
7133
|
-
if (annotation.type !==
|
|
7278
|
+
if (annotation.type !== AST_NODE_TYPES36.TSUnionType || !isNullableArrayOnly(annotation)) {
|
|
7134
7279
|
return;
|
|
7135
7280
|
}
|
|
7136
7281
|
context.report({
|
|
@@ -7143,7 +7288,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
7143
7288
|
TSPropertySignature: checkOptionalProperty,
|
|
7144
7289
|
PropertyDefinition: checkOptionalProperty,
|
|
7145
7290
|
TSTypeAliasDeclaration(node) {
|
|
7146
|
-
if (node.typeAnnotation.type !==
|
|
7291
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES36.TSUnionType) return;
|
|
7147
7292
|
if (!isNullableArrayOnly(node.typeAnnotation)) return;
|
|
7148
7293
|
context.report({
|
|
7149
7294
|
node,
|
|
@@ -7155,14 +7300,100 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
7155
7300
|
}
|
|
7156
7301
|
});
|
|
7157
7302
|
|
|
7303
|
+
// src/rules/prefer-native-random-uuid.ts
|
|
7304
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES37, ASTUtils as ASTUtils3 } from "@typescript-eslint/utils";
|
|
7305
|
+
function requireUuid(node) {
|
|
7306
|
+
return node?.type === AST_NODE_TYPES37.CallExpression && node.callee.type === AST_NODE_TYPES37.Identifier && node.callee.name === "require" && node.arguments.length === 1 && node.arguments[0]?.type === AST_NODE_TYPES37.Literal && node.arguments[0].value === "uuid";
|
|
7307
|
+
}
|
|
7308
|
+
var prefer_native_random_uuid_default = createRule({
|
|
7309
|
+
name: "prefer-native-random-uuid",
|
|
7310
|
+
meta: {
|
|
7311
|
+
type: "suggestion",
|
|
7312
|
+
docs: {
|
|
7313
|
+
description: "Prefer `globalThis.crypto.randomUUID()` over resolved zero-argument UUID v4 bindings from the `uuid` package."
|
|
7314
|
+
},
|
|
7315
|
+
hasSuggestions: true,
|
|
7316
|
+
schema: [],
|
|
7317
|
+
messages: {
|
|
7318
|
+
preferNative: "Use the Node 22 native `globalThis.crypto.randomUUID()` instead of the `uuid` package for UUID v4.",
|
|
7319
|
+
replaceWithNative: "Replace this UUID v4 call with the native implementation."
|
|
7320
|
+
}
|
|
7321
|
+
},
|
|
7322
|
+
defaultOptions: [],
|
|
7323
|
+
create(context) {
|
|
7324
|
+
const directBindings = /* @__PURE__ */ new Set();
|
|
7325
|
+
const namespaceBindings = /* @__PURE__ */ new Set();
|
|
7326
|
+
function resolve(identifier) {
|
|
7327
|
+
return ASTUtils3.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
7328
|
+
}
|
|
7329
|
+
function record(identifier, destination) {
|
|
7330
|
+
const variable = resolve(identifier);
|
|
7331
|
+
if (variable !== null) destination.add(variable);
|
|
7332
|
+
}
|
|
7333
|
+
function report(node) {
|
|
7334
|
+
context.report({
|
|
7335
|
+
node,
|
|
7336
|
+
messageId: "preferNative",
|
|
7337
|
+
suggest: [
|
|
7338
|
+
{
|
|
7339
|
+
messageId: "replaceWithNative",
|
|
7340
|
+
fix: (fixer) => fixer.replaceText(node, "globalThis.crypto.randomUUID()")
|
|
7341
|
+
}
|
|
7342
|
+
]
|
|
7343
|
+
});
|
|
7344
|
+
}
|
|
7345
|
+
return {
|
|
7346
|
+
ImportDeclaration(node) {
|
|
7347
|
+
if (node.source.value !== "uuid") return;
|
|
7348
|
+
for (const specifier of node.specifiers) {
|
|
7349
|
+
if (specifier.type === AST_NODE_TYPES37.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES37.Identifier ? specifier.imported.name === "v4" : specifier.imported.value === "v4")) {
|
|
7350
|
+
record(specifier.local, directBindings);
|
|
7351
|
+
} else if (specifier.type === AST_NODE_TYPES37.ImportNamespaceSpecifier) {
|
|
7352
|
+
record(specifier.local, namespaceBindings);
|
|
7353
|
+
}
|
|
7354
|
+
}
|
|
7355
|
+
},
|
|
7356
|
+
VariableDeclarator(node) {
|
|
7357
|
+
if (node.parent.kind !== "const" || !requireUuid(node.init)) return;
|
|
7358
|
+
if (node.init?.type !== AST_NODE_TYPES37.CallExpression || node.init.callee.type !== AST_NODE_TYPES37.Identifier || (resolve(node.init.callee)?.defs.length ?? 0) > 0) {
|
|
7359
|
+
return;
|
|
7360
|
+
}
|
|
7361
|
+
if (node.id.type === AST_NODE_TYPES37.Identifier) {
|
|
7362
|
+
record(node.id, namespaceBindings);
|
|
7363
|
+
return;
|
|
7364
|
+
}
|
|
7365
|
+
if (node.id.type !== AST_NODE_TYPES37.ObjectPattern) return;
|
|
7366
|
+
for (const property of node.id.properties) {
|
|
7367
|
+
if (property.type === AST_NODE_TYPES37.Property && !property.computed && (property.key.type === AST_NODE_TYPES37.Identifier && property.key.name === "v4" || property.key.type === AST_NODE_TYPES37.Literal && property.key.value === "v4") && property.value.type === AST_NODE_TYPES37.Identifier) {
|
|
7368
|
+
record(property.value, directBindings);
|
|
7369
|
+
}
|
|
7370
|
+
}
|
|
7371
|
+
},
|
|
7372
|
+
"CallExpression:exit"(node) {
|
|
7373
|
+
if (node.arguments.length !== 0) return;
|
|
7374
|
+
if (node.callee.type === AST_NODE_TYPES37.Identifier) {
|
|
7375
|
+
const variable2 = resolve(node.callee);
|
|
7376
|
+
if (variable2 !== null && directBindings.has(variable2)) report(node);
|
|
7377
|
+
return;
|
|
7378
|
+
}
|
|
7379
|
+
if (node.callee.type !== AST_NODE_TYPES37.MemberExpression || node.callee.computed || node.callee.object.type !== AST_NODE_TYPES37.Identifier || node.callee.property.type !== AST_NODE_TYPES37.Identifier || node.callee.property.name !== "v4") {
|
|
7380
|
+
return;
|
|
7381
|
+
}
|
|
7382
|
+
const variable = resolve(node.callee.object);
|
|
7383
|
+
if (variable !== null && namespaceBindings.has(variable)) report(node);
|
|
7384
|
+
}
|
|
7385
|
+
};
|
|
7386
|
+
}
|
|
7387
|
+
});
|
|
7388
|
+
|
|
7158
7389
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
7159
|
-
import { AST_NODE_TYPES as
|
|
7390
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES38 } from "@typescript-eslint/utils";
|
|
7160
7391
|
var unwrap4 = (node) => {
|
|
7161
7392
|
let current = node;
|
|
7162
7393
|
while (current !== null && current !== void 0) {
|
|
7163
|
-
if (current.type ===
|
|
7394
|
+
if (current.type === AST_NODE_TYPES38.TSAsExpression || current.type === AST_NODE_TYPES38.TSTypeAssertion || current.type === AST_NODE_TYPES38.TSNonNullExpression || current.type === AST_NODE_TYPES38.TSSatisfiesExpression) {
|
|
7164
7395
|
current = current.expression;
|
|
7165
|
-
} else if (current.type ===
|
|
7396
|
+
} else if (current.type === AST_NODE_TYPES38.ChainExpression) {
|
|
7166
7397
|
current = current.expression;
|
|
7167
7398
|
} else {
|
|
7168
7399
|
break;
|
|
@@ -7177,23 +7408,23 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
7177
7408
|
]);
|
|
7178
7409
|
var isSchemaParseReference = (node) => {
|
|
7179
7410
|
const inner = unwrap4(node);
|
|
7180
|
-
return inner !== null && inner.type ===
|
|
7411
|
+
return inner !== null && inner.type === AST_NODE_TYPES38.MemberExpression && !inner.computed && inner.property.type === AST_NODE_TYPES38.Identifier && (inner.property.name === "parse" || inner.property.name === "safeParse");
|
|
7181
7412
|
};
|
|
7182
7413
|
var isRawPayloadSource = (node) => {
|
|
7183
7414
|
let current = unwrap4(node);
|
|
7184
7415
|
if (current === null) return false;
|
|
7185
|
-
if (current.type ===
|
|
7416
|
+
if (current.type === AST_NODE_TYPES38.AwaitExpression) {
|
|
7186
7417
|
current = unwrap4(current.argument);
|
|
7187
7418
|
}
|
|
7188
|
-
if (current === null || current.type !==
|
|
7419
|
+
if (current === null || current.type !== AST_NODE_TYPES38.CallExpression) {
|
|
7189
7420
|
return false;
|
|
7190
7421
|
}
|
|
7191
7422
|
const callee = unwrap4(current.callee);
|
|
7192
|
-
if (callee === null || callee.type !==
|
|
7423
|
+
if (callee === null || callee.type !== AST_NODE_TYPES38.MemberExpression) {
|
|
7193
7424
|
return false;
|
|
7194
7425
|
}
|
|
7195
7426
|
const property = unwrap4(callee.property);
|
|
7196
|
-
if (property === null || property.type !==
|
|
7427
|
+
if (property === null || property.type !== AST_NODE_TYPES38.Identifier) {
|
|
7197
7428
|
return false;
|
|
7198
7429
|
}
|
|
7199
7430
|
if (property.name === "json") {
|
|
@@ -7203,16 +7434,16 @@ var isRawPayloadSource = (node) => {
|
|
|
7203
7434
|
return !current.arguments.some(isSchemaParseReference) && isRawPayloadSource(callee.object);
|
|
7204
7435
|
}
|
|
7205
7436
|
const object = unwrap4(callee.object);
|
|
7206
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
7437
|
+
return property.name === "parse" && object !== null && object.type === AST_NODE_TYPES38.Identifier && object.name === "JSON" && !isLocalFileRead(current.arguments[0]);
|
|
7207
7438
|
};
|
|
7208
7439
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
7209
7440
|
var isLocalFileRead = (node) => {
|
|
7210
7441
|
let found = false;
|
|
7211
7442
|
const visit = (current) => {
|
|
7212
7443
|
if (found || current === null || current === void 0) return;
|
|
7213
|
-
if (current.type ===
|
|
7444
|
+
if (current.type === AST_NODE_TYPES38.CallExpression) {
|
|
7214
7445
|
const callee = unwrap4(current.callee);
|
|
7215
|
-
const name = callee?.type ===
|
|
7446
|
+
const name = callee?.type === AST_NODE_TYPES38.Identifier ? callee.name : callee?.type === AST_NODE_TYPES38.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES38.Identifier ? callee.property.name : null;
|
|
7216
7447
|
if (name !== null && FILE_READ_RE.test(name)) {
|
|
7217
7448
|
found = true;
|
|
7218
7449
|
return;
|
|
@@ -7234,15 +7465,15 @@ var isLocalFileRead = (node) => {
|
|
|
7234
7465
|
var ASSERTION_CALLEE_RE = /^(expect|assert|should|invariant)$/;
|
|
7235
7466
|
var isInsideAssertion = (node) => {
|
|
7236
7467
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
7237
|
-
if (current.type !==
|
|
7468
|
+
if (current.type !== AST_NODE_TYPES38.CallExpression) continue;
|
|
7238
7469
|
let callee = current.callee;
|
|
7239
|
-
while (callee.type ===
|
|
7470
|
+
while (callee.type === AST_NODE_TYPES38.MemberExpression) {
|
|
7240
7471
|
callee = callee.object;
|
|
7241
7472
|
}
|
|
7242
|
-
if (callee.type ===
|
|
7473
|
+
if (callee.type === AST_NODE_TYPES38.CallExpression) {
|
|
7243
7474
|
callee = callee.callee;
|
|
7244
7475
|
}
|
|
7245
|
-
if (callee.type ===
|
|
7476
|
+
if (callee.type === AST_NODE_TYPES38.Identifier && ASSERTION_CALLEE_RE.test(callee.name)) {
|
|
7246
7477
|
return true;
|
|
7247
7478
|
}
|
|
7248
7479
|
}
|
|
@@ -7261,39 +7492,39 @@ var GUARD_NAME_RE = /^(?:is|validate|parse|assert|decode|coerce)[A-Z]/;
|
|
|
7261
7492
|
var isValidationRead = (node) => {
|
|
7262
7493
|
let current = node;
|
|
7263
7494
|
let parent = current.parent;
|
|
7264
|
-
while (parent !== null && parent !== void 0 && (parent.type ===
|
|
7495
|
+
while (parent !== null && parent !== void 0 && (parent.type === AST_NODE_TYPES38.TSAsExpression || parent.type === AST_NODE_TYPES38.TSTypeAssertion || parent.type === AST_NODE_TYPES38.TSNonNullExpression || parent.type === AST_NODE_TYPES38.TSSatisfiesExpression || parent.type === AST_NODE_TYPES38.ChainExpression)) {
|
|
7265
7496
|
current = parent;
|
|
7266
7497
|
parent = parent.parent;
|
|
7267
7498
|
}
|
|
7268
7499
|
if (parent === null || parent === void 0) return false;
|
|
7269
|
-
if (parent.type ===
|
|
7500
|
+
if (parent.type === AST_NODE_TYPES38.UnaryExpression && parent.operator === "typeof" && parent.argument === current) {
|
|
7270
7501
|
return true;
|
|
7271
7502
|
}
|
|
7272
|
-
if (parent.type !==
|
|
7503
|
+
if (parent.type !== AST_NODE_TYPES38.CallExpression || !parent.arguments.some((arg) => arg === current)) {
|
|
7273
7504
|
return false;
|
|
7274
7505
|
}
|
|
7275
7506
|
const callee = parent.callee;
|
|
7276
|
-
if (callee.type ===
|
|
7507
|
+
if (callee.type === AST_NODE_TYPES38.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES38.Identifier && callee.object.name === "Array" && callee.property.type === AST_NODE_TYPES38.Identifier && callee.property.name === "isArray") {
|
|
7277
7508
|
return parent.arguments.length === 1;
|
|
7278
7509
|
}
|
|
7279
|
-
return callee.type ===
|
|
7510
|
+
return callee.type === AST_NODE_TYPES38.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
7280
7511
|
};
|
|
7281
7512
|
var isGuardTestPosition = (node) => {
|
|
7282
7513
|
let current = node;
|
|
7283
7514
|
let parent = current.parent;
|
|
7284
7515
|
while (parent !== void 0 && parent !== null) {
|
|
7285
7516
|
switch (parent.type) {
|
|
7286
|
-
case
|
|
7287
|
-
case
|
|
7288
|
-
case
|
|
7517
|
+
case AST_NODE_TYPES38.UnaryExpression:
|
|
7518
|
+
case AST_NODE_TYPES38.LogicalExpression:
|
|
7519
|
+
case AST_NODE_TYPES38.ChainExpression:
|
|
7289
7520
|
current = parent;
|
|
7290
7521
|
parent = parent.parent;
|
|
7291
7522
|
continue;
|
|
7292
|
-
case
|
|
7293
|
-
case
|
|
7294
|
-
case
|
|
7295
|
-
case
|
|
7296
|
-
case
|
|
7523
|
+
case AST_NODE_TYPES38.IfStatement:
|
|
7524
|
+
case AST_NODE_TYPES38.ConditionalExpression:
|
|
7525
|
+
case AST_NODE_TYPES38.WhileStatement:
|
|
7526
|
+
case AST_NODE_TYPES38.DoWhileStatement:
|
|
7527
|
+
case AST_NODE_TYPES38.ForStatement:
|
|
7297
7528
|
return parent.test === current;
|
|
7298
7529
|
default:
|
|
7299
7530
|
return false;
|
|
@@ -7303,7 +7534,7 @@ var isGuardTestPosition = (node) => {
|
|
|
7303
7534
|
};
|
|
7304
7535
|
var isUnvalidatedVariableRef = (node, scope, tracked) => {
|
|
7305
7536
|
const unwrapped = unwrap4(node);
|
|
7306
|
-
if (unwrapped === null || unwrapped.type !==
|
|
7537
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES38.Identifier) {
|
|
7307
7538
|
return false;
|
|
7308
7539
|
}
|
|
7309
7540
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -7346,11 +7577,11 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7346
7577
|
return {
|
|
7347
7578
|
VariableDeclarator(node) {
|
|
7348
7579
|
const scope = context.sourceCode.getScope(node);
|
|
7349
|
-
if (node.id.type ===
|
|
7580
|
+
if (node.id.type === AST_NODE_TYPES38.Identifier) {
|
|
7350
7581
|
trackInitializer(node);
|
|
7351
7582
|
return;
|
|
7352
7583
|
}
|
|
7353
|
-
if (node.id.type ===
|
|
7584
|
+
if (node.id.type === AST_NODE_TYPES38.ObjectPattern || node.id.type === AST_NODE_TYPES38.ArrayPattern) {
|
|
7354
7585
|
if (isRawPayloadSource(node.init)) {
|
|
7355
7586
|
if (!isFullyNarrowedPattern(node)) {
|
|
7356
7587
|
context.report({ node: node.id, messageId: "unparsedJsonAccess" });
|
|
@@ -7364,7 +7595,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7364
7595
|
},
|
|
7365
7596
|
AssignmentExpression(node) {
|
|
7366
7597
|
const scope = context.sourceCode.getScope(node);
|
|
7367
|
-
if (node.left.type ===
|
|
7598
|
+
if (node.left.type === AST_NODE_TYPES38.Identifier) {
|
|
7368
7599
|
const variable = findVariable2(scope, node.left.name);
|
|
7369
7600
|
if (variable === null) return;
|
|
7370
7601
|
if (isRawPayloadSource(node.right)) {
|
|
@@ -7374,7 +7605,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7374
7605
|
}
|
|
7375
7606
|
return;
|
|
7376
7607
|
}
|
|
7377
|
-
if (node.left.type ===
|
|
7608
|
+
if (node.left.type === AST_NODE_TYPES38.ObjectPattern || node.left.type === AST_NODE_TYPES38.ArrayPattern) {
|
|
7378
7609
|
if (isRawPayloadSource(node.right)) {
|
|
7379
7610
|
context.report({
|
|
7380
7611
|
node: node.left,
|
|
@@ -7391,15 +7622,15 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7391
7622
|
}
|
|
7392
7623
|
},
|
|
7393
7624
|
CallExpression(node) {
|
|
7394
|
-
if (node.callee.type !==
|
|
7625
|
+
if (node.callee.type !== AST_NODE_TYPES38.Identifier) return;
|
|
7395
7626
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
7396
7627
|
return;
|
|
7397
7628
|
}
|
|
7398
7629
|
const scope = context.sourceCode.getScope(node);
|
|
7399
7630
|
for (const arg of node.arguments) {
|
|
7400
|
-
if (arg.type ===
|
|
7631
|
+
if (arg.type === AST_NODE_TYPES38.SpreadElement) continue;
|
|
7401
7632
|
const unwrapped = unwrap4(arg);
|
|
7402
|
-
if (unwrapped === null || unwrapped.type !==
|
|
7633
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES38.Identifier) {
|
|
7403
7634
|
continue;
|
|
7404
7635
|
}
|
|
7405
7636
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -7413,13 +7644,13 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7413
7644
|
const obj = unwrap4(node.object);
|
|
7414
7645
|
if (isRawPayloadSource(obj)) {
|
|
7415
7646
|
const parent = node.parent;
|
|
7416
|
-
if (parent.type ===
|
|
7647
|
+
if (parent.type === AST_NODE_TYPES38.CallExpression && parent.callee === node && node.property.type === AST_NODE_TYPES38.Identifier && (node.property.name === "parse" || node.property.name === "safeParse" || PROMISE_CHAIN_METHODS.has(node.property.name))) {
|
|
7417
7648
|
return;
|
|
7418
7649
|
}
|
|
7419
7650
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
7420
7651
|
return;
|
|
7421
7652
|
}
|
|
7422
|
-
if (obj !== null && obj.type ===
|
|
7653
|
+
if (obj !== null && obj.type === AST_NODE_TYPES38.Identifier && isUnvalidatedVariableRef(obj, scope, unvalidatedVariables)) {
|
|
7423
7654
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
7424
7655
|
const variable = findVariable2(scope, obj.name);
|
|
7425
7656
|
if (variable !== null) {
|
|
@@ -7432,7 +7663,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7432
7663
|
});
|
|
7433
7664
|
|
|
7434
7665
|
// src/rules/prefer-semantic-colors.ts
|
|
7435
|
-
import { AST_NODE_TYPES as
|
|
7666
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES39 } from "@typescript-eslint/utils";
|
|
7436
7667
|
import { existsSync, readdirSync, readFileSync } from "fs";
|
|
7437
7668
|
import { dirname, join, parse } from "path";
|
|
7438
7669
|
|
|
@@ -7532,8 +7763,8 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
7532
7763
|
]);
|
|
7533
7764
|
function jsxElementName(node) {
|
|
7534
7765
|
const name = node.openingElement.name;
|
|
7535
|
-
if (name.type ===
|
|
7536
|
-
if (name.type ===
|
|
7766
|
+
if (name.type === AST_NODE_TYPES39.JSXIdentifier) return name.name;
|
|
7767
|
+
if (name.type === AST_NODE_TYPES39.JSXMemberExpression && name.property.type === AST_NODE_TYPES39.JSXIdentifier) {
|
|
7537
7768
|
return name.property.name;
|
|
7538
7769
|
}
|
|
7539
7770
|
return null;
|
|
@@ -7559,7 +7790,7 @@ var EMAIL_OR_PDF_MODULE_RE = /^@react-(?:email|pdf)\//;
|
|
|
7559
7790
|
var isInsideSvg = (node) => {
|
|
7560
7791
|
let current = node.parent;
|
|
7561
7792
|
while (current !== void 0 && current !== null) {
|
|
7562
|
-
if (current.type ===
|
|
7793
|
+
if (current.type === AST_NODE_TYPES39.JSXElement) {
|
|
7563
7794
|
const name = jsxElementName(current);
|
|
7564
7795
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
7565
7796
|
}
|
|
@@ -7570,7 +7801,7 @@ var isInsideSvg = (node) => {
|
|
|
7570
7801
|
var isInsideIconFactoryPath = (node) => {
|
|
7571
7802
|
let current = node.parent;
|
|
7572
7803
|
while (current !== void 0 && current !== null) {
|
|
7573
|
-
if (current.type ===
|
|
7804
|
+
if (current.type === AST_NODE_TYPES39.Property && propName(current.key) === "path" && current.parent.type === AST_NODE_TYPES39.ObjectExpression && current.parent.parent.type === AST_NODE_TYPES39.CallExpression && current.parent.parent.callee.type === AST_NODE_TYPES39.Identifier && current.parent.parent.callee.name === "createIcon") {
|
|
7574
7805
|
return true;
|
|
7575
7806
|
}
|
|
7576
7807
|
current = current.parent;
|
|
@@ -7707,12 +7938,12 @@ var hasSemanticTokenSystem = (filename) => {
|
|
|
7707
7938
|
return root !== null && workspaceHasMarker(root);
|
|
7708
7939
|
};
|
|
7709
7940
|
var propName = (key) => {
|
|
7710
|
-
if (key.type ===
|
|
7711
|
-
if (key.type ===
|
|
7941
|
+
if (key.type === AST_NODE_TYPES39.Identifier) return key.name;
|
|
7942
|
+
if (key.type === AST_NODE_TYPES39.Literal && typeof key.value === "string") return key.value;
|
|
7712
7943
|
return null;
|
|
7713
7944
|
};
|
|
7714
7945
|
var staticallyImportsEmailOrPdfRenderer = (program) => program.body.some((statement) => {
|
|
7715
|
-
if (statement.type !==
|
|
7946
|
+
if (statement.type !== AST_NODE_TYPES39.ImportDeclaration && statement.type !== AST_NODE_TYPES39.ExportNamedDeclaration && statement.type !== AST_NODE_TYPES39.ExportAllDeclaration) {
|
|
7716
7947
|
return false;
|
|
7717
7948
|
}
|
|
7718
7949
|
return statement.source !== null && typeof statement.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(statement.source.value);
|
|
@@ -7764,27 +7995,27 @@ var prefer_semantic_colors_default = createRule({
|
|
|
7764
7995
|
const checkClassNode = (node) => {
|
|
7765
7996
|
if (node === null) return;
|
|
7766
7997
|
switch (node.type) {
|
|
7767
|
-
case
|
|
7998
|
+
case AST_NODE_TYPES39.Literal:
|
|
7768
7999
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
7769
8000
|
break;
|
|
7770
|
-
case
|
|
8001
|
+
case AST_NODE_TYPES39.TemplateLiteral:
|
|
7771
8002
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
7772
8003
|
break;
|
|
7773
|
-
case
|
|
8004
|
+
case AST_NODE_TYPES39.ArrayExpression:
|
|
7774
8005
|
for (const element of node.elements) {
|
|
7775
|
-
if (element !== null && element.type !==
|
|
8006
|
+
if (element !== null && element.type !== AST_NODE_TYPES39.SpreadElement) checkClassNode(element);
|
|
7776
8007
|
}
|
|
7777
8008
|
break;
|
|
7778
|
-
case
|
|
8009
|
+
case AST_NODE_TYPES39.ObjectExpression:
|
|
7779
8010
|
for (const property of node.properties) {
|
|
7780
|
-
if (property.type ===
|
|
8011
|
+
if (property.type === AST_NODE_TYPES39.Property) checkClassNode(property.value);
|
|
7781
8012
|
}
|
|
7782
8013
|
break;
|
|
7783
|
-
case
|
|
8014
|
+
case AST_NODE_TYPES39.ConditionalExpression:
|
|
7784
8015
|
checkClassNode(node.consequent);
|
|
7785
8016
|
checkClassNode(node.alternate);
|
|
7786
8017
|
break;
|
|
7787
|
-
case
|
|
8018
|
+
case AST_NODE_TYPES39.LogicalExpression:
|
|
7788
8019
|
checkClassNode(node.right);
|
|
7789
8020
|
break;
|
|
7790
8021
|
default:
|
|
@@ -7792,32 +8023,32 @@ var prefer_semantic_colors_default = createRule({
|
|
|
7792
8023
|
}
|
|
7793
8024
|
};
|
|
7794
8025
|
const checkColorValueNode = (node) => {
|
|
7795
|
-
if (node.type ===
|
|
8026
|
+
if (node.type === AST_NODE_TYPES39.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value) && !CSS_VAR_REFERENCE_RE.test(node.value)) {
|
|
7796
8027
|
report(node, "inlineColor", { value: node.value });
|
|
7797
8028
|
}
|
|
7798
8029
|
};
|
|
7799
8030
|
return {
|
|
7800
8031
|
"JSXAttribute[name.name='className']"(node) {
|
|
7801
8032
|
if (node.value === null) return;
|
|
7802
|
-
if (node.value.type ===
|
|
7803
|
-
else if (node.value.type ===
|
|
7804
|
-
if (node.value.expression.type !==
|
|
8033
|
+
if (node.value.type === AST_NODE_TYPES39.Literal) checkClassNode(node.value);
|
|
8034
|
+
else if (node.value.type === AST_NODE_TYPES39.JSXExpressionContainer) {
|
|
8035
|
+
if (node.value.expression.type !== AST_NODE_TYPES39.JSXEmptyExpression) {
|
|
7805
8036
|
checkClassNode(node.value.expression);
|
|
7806
8037
|
}
|
|
7807
8038
|
}
|
|
7808
8039
|
},
|
|
7809
8040
|
CallExpression(node) {
|
|
7810
|
-
if (node.callee.type ===
|
|
8041
|
+
if (node.callee.type === AST_NODE_TYPES39.Identifier && node.callee.name === "require" && node.arguments[0]?.type === AST_NODE_TYPES39.Literal && typeof node.arguments[0].value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.arguments[0].value)) {
|
|
7811
8042
|
importsEmailOrPdfRenderer = true;
|
|
7812
8043
|
}
|
|
7813
|
-
if (node.callee.type ===
|
|
8044
|
+
if (node.callee.type === AST_NODE_TYPES39.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
7814
8045
|
for (const arg of node.arguments) {
|
|
7815
|
-
if (arg.type !==
|
|
8046
|
+
if (arg.type !== AST_NODE_TYPES39.SpreadElement) checkClassNode(arg);
|
|
7816
8047
|
}
|
|
7817
8048
|
}
|
|
7818
8049
|
},
|
|
7819
8050
|
VariableDeclarator(node) {
|
|
7820
|
-
if (node.id.type ===
|
|
8051
|
+
if (node.id.type === AST_NODE_TYPES39.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
7821
8052
|
checkClassNode(node.init);
|
|
7822
8053
|
}
|
|
7823
8054
|
},
|
|
@@ -7827,9 +8058,9 @@ var prefer_semantic_colors_default = createRule({
|
|
|
7827
8058
|
},
|
|
7828
8059
|
// SVG artwork colors are exempt; component presentation colors still report.
|
|
7829
8060
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
7830
|
-
if (node.value?.type !==
|
|
8061
|
+
if (node.value?.type !== AST_NODE_TYPES39.Literal) return;
|
|
7831
8062
|
const owner = node.parent.name;
|
|
7832
|
-
if (owner.type ===
|
|
8063
|
+
if (owner.type === AST_NODE_TYPES39.JSXIdentifier && SVG_SHAPE_PRIMITIVES.has(owner.name)) {
|
|
7833
8064
|
return;
|
|
7834
8065
|
}
|
|
7835
8066
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
@@ -7843,7 +8074,7 @@ var prefer_semantic_colors_default = createRule({
|
|
|
7843
8074
|
if (name !== null && STYLE_COLOR_PROPS.has(name)) checkColorValueNode(node.value);
|
|
7844
8075
|
},
|
|
7845
8076
|
ImportExpression(node) {
|
|
7846
|
-
if (node.source.type ===
|
|
8077
|
+
if (node.source.type === AST_NODE_TYPES39.Literal && typeof node.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.source.value)) {
|
|
7847
8078
|
importsEmailOrPdfRenderer = true;
|
|
7848
8079
|
}
|
|
7849
8080
|
},
|
|
@@ -8049,7 +8280,7 @@ var prefer_single_sentence_comment_default = createRule({
|
|
|
8049
8280
|
// src/rules/prefer-string-literal-union.ts
|
|
8050
8281
|
import {
|
|
8051
8282
|
ESLintUtils as ESLintUtils3,
|
|
8052
|
-
AST_NODE_TYPES as
|
|
8283
|
+
AST_NODE_TYPES as AST_NODE_TYPES40
|
|
8053
8284
|
} from "@typescript-eslint/utils";
|
|
8054
8285
|
import * as ts2 from "typescript";
|
|
8055
8286
|
var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
@@ -8093,19 +8324,19 @@ function isChoiceLikeName(name) {
|
|
|
8093
8324
|
return CHOICE_TOKENS.has(lastWord(name));
|
|
8094
8325
|
}
|
|
8095
8326
|
function keyName(key) {
|
|
8096
|
-
if (key.type ===
|
|
8327
|
+
if (key.type === AST_NODE_TYPES40.Identifier) {
|
|
8097
8328
|
return key.name;
|
|
8098
8329
|
}
|
|
8099
|
-
if (key.type ===
|
|
8330
|
+
if (key.type === AST_NODE_TYPES40.Literal && typeof key.value === "string") {
|
|
8100
8331
|
return key.value;
|
|
8101
8332
|
}
|
|
8102
8333
|
return null;
|
|
8103
8334
|
}
|
|
8104
8335
|
function isStringLiteralMember(t) {
|
|
8105
|
-
return t.type ===
|
|
8336
|
+
return t.type === AST_NODE_TYPES40.TSLiteralType && t.literal.type === AST_NODE_TYPES40.Literal && typeof t.literal.value === "string";
|
|
8106
8337
|
}
|
|
8107
8338
|
function isStringLiteralUnion(node) {
|
|
8108
|
-
if (node?.type !==
|
|
8339
|
+
if (node?.type !== AST_NODE_TYPES40.TSUnionType) {
|
|
8109
8340
|
return false;
|
|
8110
8341
|
}
|
|
8111
8342
|
return node.types.filter(isStringLiteralMember).length >= MIN_CLUSTER_SIZE;
|
|
@@ -8134,12 +8365,12 @@ function bindingSourceExpression(decl) {
|
|
|
8134
8365
|
return ts2.isForOfStatement(node) ? node.expression : node.initializer;
|
|
8135
8366
|
}
|
|
8136
8367
|
function refKey(node) {
|
|
8137
|
-
if (node.type ===
|
|
8368
|
+
if (node.type === AST_NODE_TYPES40.Identifier) {
|
|
8138
8369
|
return node.name;
|
|
8139
8370
|
}
|
|
8140
|
-
if (node.type ===
|
|
8371
|
+
if (node.type === AST_NODE_TYPES40.MemberExpression && !node.computed) {
|
|
8141
8372
|
const inner = refKey(node.object);
|
|
8142
|
-
if (inner === null || node.property.type !==
|
|
8373
|
+
if (inner === null || node.property.type !== AST_NODE_TYPES40.Identifier) {
|
|
8143
8374
|
return null;
|
|
8144
8375
|
}
|
|
8145
8376
|
return `${inner}.${node.property.name}`;
|
|
@@ -8147,7 +8378,7 @@ function refKey(node) {
|
|
|
8147
8378
|
return null;
|
|
8148
8379
|
}
|
|
8149
8380
|
function strLiteral(node) {
|
|
8150
|
-
if (node.type ===
|
|
8381
|
+
if (node.type === AST_NODE_TYPES40.Literal && typeof node.value === "string") {
|
|
8151
8382
|
return node.value;
|
|
8152
8383
|
}
|
|
8153
8384
|
return null;
|
|
@@ -8300,7 +8531,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
8300
8531
|
containersWithUnion.add(container);
|
|
8301
8532
|
return;
|
|
8302
8533
|
}
|
|
8303
|
-
if (typeNode?.type !==
|
|
8534
|
+
if (typeNode?.type !== AST_NODE_TYPES40.TSStringKeyword) {
|
|
8304
8535
|
return;
|
|
8305
8536
|
}
|
|
8306
8537
|
const name = keyName(key);
|
|
@@ -8388,10 +8619,10 @@ var prefer_string_literal_union_default = createRule({
|
|
|
8388
8619
|
}
|
|
8389
8620
|
};
|
|
8390
8621
|
function refKeyText(node) {
|
|
8391
|
-
if (node.type ===
|
|
8622
|
+
if (node.type === AST_NODE_TYPES40.BinaryExpression) {
|
|
8392
8623
|
return refKey(node.left) ?? refKey(node.right) ?? "value";
|
|
8393
8624
|
}
|
|
8394
|
-
if (node.type ===
|
|
8625
|
+
if (node.type === AST_NODE_TYPES40.SwitchStatement) {
|
|
8395
8626
|
return refKey(node.discriminant) ?? "value";
|
|
8396
8627
|
}
|
|
8397
8628
|
return "value";
|
|
@@ -8400,7 +8631,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
8400
8631
|
});
|
|
8401
8632
|
|
|
8402
8633
|
// src/rules/prefer-whole-object-assertion.ts
|
|
8403
|
-
import { AST_NODE_TYPES as
|
|
8634
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES41 } from "@typescript-eslint/utils";
|
|
8404
8635
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
8405
8636
|
var ARRAY_MATCHERS = /* @__PURE__ */ new Set(["toEqual", "toStrictEqual"]);
|
|
8406
8637
|
var COLLECTION_PROPERTIES = /* @__PURE__ */ new Set(["length", "size"]);
|
|
@@ -8409,11 +8640,11 @@ var NUMERIC_SIGNS2 = /* @__PURE__ */ new Set(["-", "+"]);
|
|
|
8409
8640
|
var MIN_RUN_LENGTH = 2;
|
|
8410
8641
|
function literalText(node, getText) {
|
|
8411
8642
|
switch (node.type) {
|
|
8412
|
-
case
|
|
8643
|
+
case AST_NODE_TYPES41.Literal:
|
|
8413
8644
|
return "regex" in node ? null : getText(node);
|
|
8414
|
-
case
|
|
8645
|
+
case AST_NODE_TYPES41.TemplateLiteral:
|
|
8415
8646
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
8416
|
-
case
|
|
8647
|
+
case AST_NODE_TYPES41.UnaryExpression:
|
|
8417
8648
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
8418
8649
|
default:
|
|
8419
8650
|
return null;
|
|
@@ -8421,15 +8652,15 @@ function literalText(node, getText) {
|
|
|
8421
8652
|
}
|
|
8422
8653
|
function isPureReceiver(node) {
|
|
8423
8654
|
switch (node.type) {
|
|
8424
|
-
case
|
|
8425
|
-
case
|
|
8655
|
+
case AST_NODE_TYPES41.Identifier:
|
|
8656
|
+
case AST_NODE_TYPES41.ThisExpression:
|
|
8426
8657
|
return true;
|
|
8427
|
-
case
|
|
8658
|
+
case AST_NODE_TYPES41.MemberExpression:
|
|
8428
8659
|
if (node.optional) {
|
|
8429
8660
|
return false;
|
|
8430
8661
|
}
|
|
8431
8662
|
if (node.computed) {
|
|
8432
|
-
return node.property.type ===
|
|
8663
|
+
return node.property.type === AST_NODE_TYPES41.Literal && isPureReceiver(node.object);
|
|
8433
8664
|
}
|
|
8434
8665
|
return isPureReceiver(node.object);
|
|
8435
8666
|
default:
|
|
@@ -8437,7 +8668,7 @@ function isPureReceiver(node) {
|
|
|
8437
8668
|
}
|
|
8438
8669
|
}
|
|
8439
8670
|
function literalIndex(node) {
|
|
8440
|
-
if (node.type !==
|
|
8671
|
+
if (node.type !== AST_NODE_TYPES41.Literal || typeof node.value !== "number") {
|
|
8441
8672
|
return null;
|
|
8442
8673
|
}
|
|
8443
8674
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
@@ -8463,24 +8694,24 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8463
8694
|
}
|
|
8464
8695
|
const { sourceCode } = context;
|
|
8465
8696
|
function parseAssertion(statement) {
|
|
8466
|
-
if (statement.type !==
|
|
8697
|
+
if (statement.type !== AST_NODE_TYPES41.ExpressionStatement) {
|
|
8467
8698
|
return null;
|
|
8468
8699
|
}
|
|
8469
8700
|
const call = statement.expression;
|
|
8470
|
-
if (call.type !==
|
|
8701
|
+
if (call.type !== AST_NODE_TYPES41.CallExpression) {
|
|
8471
8702
|
return null;
|
|
8472
8703
|
}
|
|
8473
8704
|
const callee = call.callee;
|
|
8474
|
-
if (callee.type !==
|
|
8705
|
+
if (callee.type !== AST_NODE_TYPES41.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES41.Identifier) {
|
|
8475
8706
|
return null;
|
|
8476
8707
|
}
|
|
8477
8708
|
const matcher = callee.property.name;
|
|
8478
8709
|
const expectCall = callee.object;
|
|
8479
|
-
if (expectCall.type !==
|
|
8710
|
+
if (expectCall.type !== AST_NODE_TYPES41.CallExpression || expectCall.callee.type !== AST_NODE_TYPES41.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
8480
8711
|
return null;
|
|
8481
8712
|
}
|
|
8482
8713
|
const actual = expectCall.arguments[0];
|
|
8483
|
-
if (actual === void 0 || actual.type !==
|
|
8714
|
+
if (actual === void 0 || actual.type !== AST_NODE_TYPES41.MemberExpression || actual.optional) {
|
|
8484
8715
|
return null;
|
|
8485
8716
|
}
|
|
8486
8717
|
if (!isPureReceiver(actual.object)) {
|
|
@@ -8494,7 +8725,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8494
8725
|
}
|
|
8495
8726
|
key = { kind: "index", index };
|
|
8496
8727
|
} else {
|
|
8497
|
-
if (actual.property.type !==
|
|
8728
|
+
if (actual.property.type !== AST_NODE_TYPES41.Identifier || COLLECTION_PROPERTIES.has(actual.property.name) || LITERAL_KEY_HAZARDS.has(actual.property.name)) {
|
|
8498
8729
|
return null;
|
|
8499
8730
|
}
|
|
8500
8731
|
key = { kind: "property", name: actual.property.name };
|
|
@@ -8506,7 +8737,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8506
8737
|
return null;
|
|
8507
8738
|
}
|
|
8508
8739
|
const expected = call.arguments[0];
|
|
8509
|
-
if (call.arguments.length !== 1 || expected === void 0 || expected.type ===
|
|
8740
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === AST_NODE_TYPES41.SpreadElement) {
|
|
8510
8741
|
return null;
|
|
8511
8742
|
}
|
|
8512
8743
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
@@ -8621,7 +8852,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8621
8852
|
});
|
|
8622
8853
|
|
|
8623
8854
|
// src/rules/prefer-zod-enum.ts
|
|
8624
|
-
import { AST_NODE_TYPES as
|
|
8855
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES42 } from "@typescript-eslint/utils";
|
|
8625
8856
|
var prefer_zod_enum_default = createRule({
|
|
8626
8857
|
name: "prefer-zod-enum",
|
|
8627
8858
|
meta: {
|
|
@@ -8641,25 +8872,25 @@ var prefer_zod_enum_default = createRule({
|
|
|
8641
8872
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
8642
8873
|
function enumValues(node) {
|
|
8643
8874
|
const callee = node.callee;
|
|
8644
|
-
if (callee.type !==
|
|
8875
|
+
if (callee.type !== AST_NODE_TYPES42.MemberExpression || callee.computed || callee.object.type !== AST_NODE_TYPES42.Identifier || !zodNamespaces.has(callee.object.name) || callee.property.type !== AST_NODE_TYPES42.Identifier || callee.property.name !== "union" || node.arguments.length !== 1) {
|
|
8645
8876
|
return null;
|
|
8646
8877
|
}
|
|
8647
8878
|
const argument = node.arguments[0];
|
|
8648
|
-
if (argument === void 0 || argument.type !==
|
|
8879
|
+
if (argument === void 0 || argument.type !== AST_NODE_TYPES42.ArrayExpression || argument.elements.length === 0) {
|
|
8649
8880
|
return null;
|
|
8650
8881
|
}
|
|
8651
8882
|
const values = [];
|
|
8652
8883
|
let canFix = true;
|
|
8653
8884
|
for (const element of argument.elements) {
|
|
8654
|
-
if (element?.type ===
|
|
8885
|
+
if (element?.type === AST_NODE_TYPES42.SpreadElement) {
|
|
8655
8886
|
canFix = false;
|
|
8656
8887
|
continue;
|
|
8657
8888
|
}
|
|
8658
|
-
if (element === null || element.type !==
|
|
8889
|
+
if (element === null || element.type !== AST_NODE_TYPES42.CallExpression || element.callee.type !== AST_NODE_TYPES42.MemberExpression || element.callee.computed || element.callee.object.type !== AST_NODE_TYPES42.Identifier || !zodNamespaces.has(element.callee.object.name) || element.callee.property.type !== AST_NODE_TYPES42.Identifier || element.callee.property.name !== "literal") {
|
|
8659
8890
|
return null;
|
|
8660
8891
|
}
|
|
8661
8892
|
const value = element.arguments[0];
|
|
8662
|
-
if (element.arguments.length !== 1 || value === void 0 || value.type !==
|
|
8893
|
+
if (element.arguments.length !== 1 || value === void 0 || value.type !== AST_NODE_TYPES42.Literal || typeof value.value !== "string") {
|
|
8663
8894
|
canFix = false;
|
|
8664
8895
|
continue;
|
|
8665
8896
|
}
|
|
@@ -8669,11 +8900,11 @@ var prefer_zod_enum_default = createRule({
|
|
|
8669
8900
|
}
|
|
8670
8901
|
function buildFix(node, values) {
|
|
8671
8902
|
const argument = node.arguments[0];
|
|
8672
|
-
if (argument === void 0 || argument.type !==
|
|
8903
|
+
if (argument === void 0 || argument.type !== AST_NODE_TYPES42.ArrayExpression || sourceCode.getCommentsInside(argument).length > 0) {
|
|
8673
8904
|
return void 0;
|
|
8674
8905
|
}
|
|
8675
8906
|
const callee = node.callee;
|
|
8676
|
-
if (callee.type !==
|
|
8907
|
+
if (callee.type !== AST_NODE_TYPES42.MemberExpression || callee.property.type !== AST_NODE_TYPES42.Identifier) {
|
|
8677
8908
|
return void 0;
|
|
8678
8909
|
}
|
|
8679
8910
|
return (fixer) => [
|
|
@@ -8690,7 +8921,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
8690
8921
|
return;
|
|
8691
8922
|
}
|
|
8692
8923
|
for (const specifier of node.specifiers) {
|
|
8693
|
-
if (specifier.type ===
|
|
8924
|
+
if (specifier.type === AST_NODE_TYPES42.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES42.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES42.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES42.Identifier && specifier.imported.name === "z") {
|
|
8694
8925
|
zodNamespaces.add(specifier.local.name);
|
|
8695
8926
|
}
|
|
8696
8927
|
}
|
|
@@ -8712,7 +8943,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
8712
8943
|
});
|
|
8713
8944
|
|
|
8714
8945
|
// src/rules/prefer-zod-infer.ts
|
|
8715
|
-
import { AST_NODE_TYPES as
|
|
8946
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES43 } from "@typescript-eslint/utils";
|
|
8716
8947
|
var SHAPE_PRESERVING_METHODS = /* @__PURE__ */ new Set([
|
|
8717
8948
|
"describe",
|
|
8718
8949
|
"refine",
|
|
@@ -8749,44 +8980,44 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
8749
8980
|
"Schema"
|
|
8750
8981
|
]);
|
|
8751
8982
|
var LEAF_NODE_TYPES = {
|
|
8752
|
-
string: [
|
|
8753
|
-
email: [
|
|
8754
|
-
url: [
|
|
8755
|
-
uuid: [
|
|
8756
|
-
ulid: [
|
|
8757
|
-
cuid: [
|
|
8758
|
-
cuid2: [
|
|
8759
|
-
nanoid: [
|
|
8760
|
-
iso: [
|
|
8761
|
-
number: [
|
|
8762
|
-
int: [
|
|
8763
|
-
float32: [
|
|
8764
|
-
float64: [
|
|
8765
|
-
boolean: [
|
|
8766
|
-
bigint: [
|
|
8767
|
-
symbol: [
|
|
8768
|
-
any: [
|
|
8769
|
-
unknown: [
|
|
8770
|
-
never: [
|
|
8771
|
-
void: [
|
|
8772
|
-
null: [
|
|
8773
|
-
undefined: [
|
|
8774
|
-
literal: [
|
|
8775
|
-
date: [
|
|
8776
|
-
array: [
|
|
8777
|
-
tuple: [
|
|
8778
|
-
object: [
|
|
8779
|
-
strictObject: [
|
|
8780
|
-
looseObject: [
|
|
8781
|
-
record: [
|
|
8782
|
-
map: [
|
|
8783
|
-
set: [
|
|
8784
|
-
promise: [
|
|
8785
|
-
enum: [
|
|
8786
|
-
nativeEnum: [
|
|
8787
|
-
union: [
|
|
8788
|
-
discriminatedUnion: [
|
|
8789
|
-
intersection: [
|
|
8983
|
+
string: [AST_NODE_TYPES43.TSStringKeyword],
|
|
8984
|
+
email: [AST_NODE_TYPES43.TSStringKeyword],
|
|
8985
|
+
url: [AST_NODE_TYPES43.TSStringKeyword],
|
|
8986
|
+
uuid: [AST_NODE_TYPES43.TSStringKeyword],
|
|
8987
|
+
ulid: [AST_NODE_TYPES43.TSStringKeyword],
|
|
8988
|
+
cuid: [AST_NODE_TYPES43.TSStringKeyword],
|
|
8989
|
+
cuid2: [AST_NODE_TYPES43.TSStringKeyword],
|
|
8990
|
+
nanoid: [AST_NODE_TYPES43.TSStringKeyword],
|
|
8991
|
+
iso: [AST_NODE_TYPES43.TSStringKeyword],
|
|
8992
|
+
number: [AST_NODE_TYPES43.TSNumberKeyword],
|
|
8993
|
+
int: [AST_NODE_TYPES43.TSNumberKeyword],
|
|
8994
|
+
float32: [AST_NODE_TYPES43.TSNumberKeyword],
|
|
8995
|
+
float64: [AST_NODE_TYPES43.TSNumberKeyword],
|
|
8996
|
+
boolean: [AST_NODE_TYPES43.TSBooleanKeyword],
|
|
8997
|
+
bigint: [AST_NODE_TYPES43.TSBigIntKeyword],
|
|
8998
|
+
symbol: [AST_NODE_TYPES43.TSSymbolKeyword],
|
|
8999
|
+
any: [AST_NODE_TYPES43.TSAnyKeyword],
|
|
9000
|
+
unknown: [AST_NODE_TYPES43.TSUnknownKeyword],
|
|
9001
|
+
never: [AST_NODE_TYPES43.TSNeverKeyword],
|
|
9002
|
+
void: [AST_NODE_TYPES43.TSVoidKeyword],
|
|
9003
|
+
null: [AST_NODE_TYPES43.TSNullKeyword],
|
|
9004
|
+
undefined: [AST_NODE_TYPES43.TSUndefinedKeyword],
|
|
9005
|
+
literal: [AST_NODE_TYPES43.TSLiteralType],
|
|
9006
|
+
date: [AST_NODE_TYPES43.TSTypeReference],
|
|
9007
|
+
array: [AST_NODE_TYPES43.TSArrayType, AST_NODE_TYPES43.TSTypeReference],
|
|
9008
|
+
tuple: [AST_NODE_TYPES43.TSTupleType],
|
|
9009
|
+
object: [AST_NODE_TYPES43.TSTypeLiteral, AST_NODE_TYPES43.TSTypeReference],
|
|
9010
|
+
strictObject: [AST_NODE_TYPES43.TSTypeLiteral, AST_NODE_TYPES43.TSTypeReference],
|
|
9011
|
+
looseObject: [AST_NODE_TYPES43.TSTypeLiteral, AST_NODE_TYPES43.TSTypeReference],
|
|
9012
|
+
record: [AST_NODE_TYPES43.TSTypeReference, AST_NODE_TYPES43.TSTypeLiteral],
|
|
9013
|
+
map: [AST_NODE_TYPES43.TSTypeReference],
|
|
9014
|
+
set: [AST_NODE_TYPES43.TSTypeReference],
|
|
9015
|
+
promise: [AST_NODE_TYPES43.TSTypeReference],
|
|
9016
|
+
enum: [AST_NODE_TYPES43.TSUnionType, AST_NODE_TYPES43.TSTypeReference, AST_NODE_TYPES43.TSLiteralType],
|
|
9017
|
+
nativeEnum: [AST_NODE_TYPES43.TSUnionType, AST_NODE_TYPES43.TSTypeReference, AST_NODE_TYPES43.TSLiteralType],
|
|
9018
|
+
union: [AST_NODE_TYPES43.TSUnionType, AST_NODE_TYPES43.TSTypeReference],
|
|
9019
|
+
discriminatedUnion: [AST_NODE_TYPES43.TSUnionType, AST_NODE_TYPES43.TSTypeReference],
|
|
9020
|
+
intersection: [AST_NODE_TYPES43.TSIntersectionType, AST_NODE_TYPES43.TSTypeReference]
|
|
8790
9021
|
};
|
|
8791
9022
|
function normalizeSchemaName(name) {
|
|
8792
9023
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -8795,20 +9026,20 @@ function normalizeTypeName(name) {
|
|
|
8795
9026
|
return name.replace(/Type$/, "").toLowerCase();
|
|
8796
9027
|
}
|
|
8797
9028
|
function unwrapNullish(annotation) {
|
|
8798
|
-
if (annotation.type !==
|
|
9029
|
+
if (annotation.type !== AST_NODE_TYPES43.TSUnionType) {
|
|
8799
9030
|
return {
|
|
8800
9031
|
core: annotation,
|
|
8801
|
-
nullable: annotation.type ===
|
|
9032
|
+
nullable: annotation.type === AST_NODE_TYPES43.TSNullKeyword
|
|
8802
9033
|
};
|
|
8803
9034
|
}
|
|
8804
9035
|
const rest = [];
|
|
8805
9036
|
let nullable = false;
|
|
8806
9037
|
for (const member of annotation.types) {
|
|
8807
|
-
if (member.type ===
|
|
9038
|
+
if (member.type === AST_NODE_TYPES43.TSNullKeyword) {
|
|
8808
9039
|
nullable = true;
|
|
8809
9040
|
continue;
|
|
8810
9041
|
}
|
|
8811
|
-
if (member.type ===
|
|
9042
|
+
if (member.type === AST_NODE_TYPES43.TSUndefinedKeyword) {
|
|
8812
9043
|
continue;
|
|
8813
9044
|
}
|
|
8814
9045
|
rest.push(member);
|
|
@@ -8873,14 +9104,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
8873
9104
|
function zodCallChain(node) {
|
|
8874
9105
|
const chain = [];
|
|
8875
9106
|
let current = node;
|
|
8876
|
-
while (current.type ===
|
|
9107
|
+
while (current.type === AST_NODE_TYPES43.CallExpression) {
|
|
8877
9108
|
const callee = current.callee;
|
|
8878
|
-
if (callee.type !==
|
|
9109
|
+
if (callee.type !== AST_NODE_TYPES43.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES43.Identifier) {
|
|
8879
9110
|
return null;
|
|
8880
9111
|
}
|
|
8881
9112
|
chain.push(current);
|
|
8882
9113
|
const receiver = callee.object;
|
|
8883
|
-
if (receiver.type ===
|
|
9114
|
+
if (receiver.type === AST_NODE_TYPES43.Identifier) {
|
|
8884
9115
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
8885
9116
|
}
|
|
8886
9117
|
current = receiver;
|
|
@@ -8889,19 +9120,19 @@ var prefer_zod_infer_default = createRule({
|
|
|
8889
9120
|
}
|
|
8890
9121
|
function methodName(call) {
|
|
8891
9122
|
const callee = call.callee;
|
|
8892
|
-
return callee.type ===
|
|
9123
|
+
return callee.type === AST_NODE_TYPES43.MemberExpression && callee.property.type === AST_NODE_TYPES43.Identifier ? callee.property.name : "";
|
|
8893
9124
|
}
|
|
8894
9125
|
function schemaField(node) {
|
|
8895
9126
|
const modifiers = [];
|
|
8896
9127
|
let current = node;
|
|
8897
9128
|
let leaf = null;
|
|
8898
|
-
while (current.type ===
|
|
9129
|
+
while (current.type === AST_NODE_TYPES43.CallExpression) {
|
|
8899
9130
|
const callee = current.callee;
|
|
8900
|
-
if (callee.type !==
|
|
9131
|
+
if (callee.type !== AST_NODE_TYPES43.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES43.Identifier) {
|
|
8901
9132
|
break;
|
|
8902
9133
|
}
|
|
8903
9134
|
const receiver = callee.object;
|
|
8904
|
-
if (receiver.type ===
|
|
9135
|
+
if (receiver.type === AST_NODE_TYPES43.Identifier && zodNamespaces.has(receiver.name)) {
|
|
8905
9136
|
leaf = callee.property.name;
|
|
8906
9137
|
break;
|
|
8907
9138
|
}
|
|
@@ -8932,16 +9163,16 @@ var prefer_zod_infer_default = createRule({
|
|
|
8932
9163
|
return null;
|
|
8933
9164
|
}
|
|
8934
9165
|
const shape = base.arguments[0];
|
|
8935
|
-
if (shape === void 0 || shape.type !==
|
|
9166
|
+
if (shape === void 0 || shape.type !== AST_NODE_TYPES43.ObjectExpression) {
|
|
8936
9167
|
return null;
|
|
8937
9168
|
}
|
|
8938
9169
|
const fields = /* @__PURE__ */ new Map();
|
|
8939
9170
|
for (const property of shape.properties) {
|
|
8940
|
-
if (property.type !==
|
|
9171
|
+
if (property.type !== AST_NODE_TYPES43.Property || property.computed) {
|
|
8941
9172
|
return null;
|
|
8942
9173
|
}
|
|
8943
9174
|
const { key } = property;
|
|
8944
|
-
const name = key.type ===
|
|
9175
|
+
const name = key.type === AST_NODE_TYPES43.Identifier ? key.name : key.type === AST_NODE_TYPES43.Literal && typeof key.value === "string" ? key.value : null;
|
|
8945
9176
|
if (name === null) {
|
|
8946
9177
|
return null;
|
|
8947
9178
|
}
|
|
@@ -8952,11 +9183,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
8952
9183
|
function typeMembers(members) {
|
|
8953
9184
|
const result = /* @__PURE__ */ new Map();
|
|
8954
9185
|
for (const member of members) {
|
|
8955
|
-
if (member.type !==
|
|
9186
|
+
if (member.type !== AST_NODE_TYPES43.TSPropertySignature || member.computed) {
|
|
8956
9187
|
return null;
|
|
8957
9188
|
}
|
|
8958
9189
|
const { key } = member;
|
|
8959
|
-
const name = key.type ===
|
|
9190
|
+
const name = key.type === AST_NODE_TYPES43.Identifier ? key.name : key.type === AST_NODE_TYPES43.Literal && typeof key.value === "string" ? key.value : null;
|
|
8960
9191
|
if (name === null) {
|
|
8961
9192
|
return null;
|
|
8962
9193
|
}
|
|
@@ -8970,8 +9201,8 @@ var prefer_zod_infer_default = createRule({
|
|
|
8970
9201
|
return result.size === 0 ? null : result;
|
|
8971
9202
|
}
|
|
8972
9203
|
function collectConstrainedNames(node) {
|
|
8973
|
-
if (node.type ===
|
|
8974
|
-
if (node.typeName.type ===
|
|
9204
|
+
if (node.type === AST_NODE_TYPES43.TSTypeReference) {
|
|
9205
|
+
if (node.typeName.type === AST_NODE_TYPES43.Identifier) {
|
|
8975
9206
|
constrainedTypeNames.add(node.typeName.name);
|
|
8976
9207
|
}
|
|
8977
9208
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -8979,11 +9210,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
8979
9210
|
}
|
|
8980
9211
|
return;
|
|
8981
9212
|
}
|
|
8982
|
-
if (node.type ===
|
|
9213
|
+
if (node.type === AST_NODE_TYPES43.TSArrayType) {
|
|
8983
9214
|
collectConstrainedNames(node.elementType);
|
|
8984
9215
|
return;
|
|
8985
9216
|
}
|
|
8986
|
-
if (node.type ===
|
|
9217
|
+
if (node.type === AST_NODE_TYPES43.TSUnionType || node.type === AST_NODE_TYPES43.TSIntersectionType) {
|
|
8987
9218
|
for (const member of node.types) {
|
|
8988
9219
|
collectConstrainedNames(member);
|
|
8989
9220
|
}
|
|
@@ -9027,13 +9258,13 @@ var prefer_zod_infer_default = createRule({
|
|
|
9027
9258
|
return;
|
|
9028
9259
|
}
|
|
9029
9260
|
for (const specifier of node.specifiers) {
|
|
9030
|
-
if (specifier.type ===
|
|
9261
|
+
if (specifier.type === AST_NODE_TYPES43.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES43.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES43.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES43.Identifier && specifier.imported.name === "z") {
|
|
9031
9262
|
zodNamespaces.add(specifier.local.name);
|
|
9032
9263
|
}
|
|
9033
9264
|
}
|
|
9034
9265
|
},
|
|
9035
9266
|
VariableDeclarator(node) {
|
|
9036
|
-
if (node.id.type !==
|
|
9267
|
+
if (node.id.type !== AST_NODE_TYPES43.Identifier || node.init == null) {
|
|
9037
9268
|
return;
|
|
9038
9269
|
}
|
|
9039
9270
|
const fields = schemaFields(node.init);
|
|
@@ -9043,14 +9274,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
9043
9274
|
},
|
|
9044
9275
|
/** Records `XSchema.transform(...)` and equivalent module-level reshaping. */
|
|
9045
9276
|
"MemberExpression[computed=false]"(node) {
|
|
9046
|
-
if (node.object.type ===
|
|
9277
|
+
if (node.object.type === AST_NODE_TYPES43.Identifier && node.property.type === AST_NODE_TYPES43.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
9047
9278
|
reshapedSchemaNames.add(node.object.name);
|
|
9048
9279
|
}
|
|
9049
9280
|
},
|
|
9050
9281
|
/** Records every type argument carried by a Zod constraint. */
|
|
9051
9282
|
TSTypeReference(node) {
|
|
9052
9283
|
const { typeName } = node;
|
|
9053
|
-
const referenced = typeName.type ===
|
|
9284
|
+
const referenced = typeName.type === AST_NODE_TYPES43.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES43.TSQualifiedName && typeName.right.type === AST_NODE_TYPES43.Identifier ? typeName.right.name : null;
|
|
9054
9285
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
9055
9286
|
return;
|
|
9056
9287
|
}
|
|
@@ -9068,7 +9299,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
9068
9299
|
}
|
|
9069
9300
|
},
|
|
9070
9301
|
TSTypeAliasDeclaration(node) {
|
|
9071
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
9302
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== AST_NODE_TYPES43.TSTypeLiteral) {
|
|
9072
9303
|
return;
|
|
9073
9304
|
}
|
|
9074
9305
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -9113,10 +9344,10 @@ var prefer_zod_infer_default = createRule({
|
|
|
9113
9344
|
});
|
|
9114
9345
|
|
|
9115
9346
|
// src/rules/require-assert-never.ts
|
|
9116
|
-
import { AST_NODE_TYPES as
|
|
9347
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES44 } from "@typescript-eslint/utils";
|
|
9117
9348
|
var isRuntimeHandlingStatement = (statement) => {
|
|
9118
|
-
if (statement.type ===
|
|
9119
|
-
if (statement.type ===
|
|
9349
|
+
if (statement.type === AST_NODE_TYPES44.EmptyStatement) return false;
|
|
9350
|
+
if (statement.type === AST_NODE_TYPES44.BlockStatement) {
|
|
9120
9351
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
9121
9352
|
}
|
|
9122
9353
|
return true;
|
|
@@ -9132,7 +9363,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
9132
9363
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
9133
9364
|
}
|
|
9134
9365
|
const only = defaultCase.consequent[0];
|
|
9135
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
9366
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === AST_NODE_TYPES44.BlockStatement && only.body.length === 0) {
|
|
9136
9367
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
9137
9368
|
}
|
|
9138
9369
|
return false;
|
|
@@ -9172,7 +9403,7 @@ var require_assert_never_default = createRule({
|
|
|
9172
9403
|
});
|
|
9173
9404
|
|
|
9174
9405
|
// src/rules/require-fetch-timeout.ts
|
|
9175
|
-
import { AST_NODE_TYPES as
|
|
9406
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES45, ASTUtils as ASTUtils4 } from "@typescript-eslint/utils";
|
|
9176
9407
|
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set([
|
|
9177
9408
|
"globalThis",
|
|
9178
9409
|
"window",
|
|
@@ -9188,14 +9419,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
9188
9419
|
return false;
|
|
9189
9420
|
}
|
|
9190
9421
|
function initProvablyLacksSignal(init) {
|
|
9191
|
-
if (init.type !==
|
|
9422
|
+
if (init.type !== AST_NODE_TYPES45.ObjectExpression) {
|
|
9192
9423
|
return false;
|
|
9193
9424
|
}
|
|
9194
9425
|
for (const prop of init.properties) {
|
|
9195
|
-
if (prop.type ===
|
|
9426
|
+
if (prop.type === AST_NODE_TYPES45.SpreadElement) {
|
|
9196
9427
|
return false;
|
|
9197
9428
|
}
|
|
9198
|
-
if (prop.key.type ===
|
|
9429
|
+
if (prop.key.type === AST_NODE_TYPES45.Identifier && prop.key.name === "signal" || prop.key.type === AST_NODE_TYPES45.Literal && prop.key.value === "signal") {
|
|
9199
9430
|
return false;
|
|
9200
9431
|
}
|
|
9201
9432
|
if (prop.computed) {
|
|
@@ -9205,7 +9436,7 @@ function initProvablyLacksSignal(init) {
|
|
|
9205
9436
|
return true;
|
|
9206
9437
|
}
|
|
9207
9438
|
function isStringish(node) {
|
|
9208
|
-
return node.type ===
|
|
9439
|
+
return node.type === AST_NODE_TYPES45.Literal && typeof node.value === "string" || node.type === AST_NODE_TYPES45.TemplateLiteral;
|
|
9209
9440
|
}
|
|
9210
9441
|
var require_fetch_timeout_default = createRule({
|
|
9211
9442
|
name: "require-fetch-timeout",
|
|
@@ -9242,14 +9473,14 @@ var require_fetch_timeout_default = createRule({
|
|
|
9242
9473
|
}
|
|
9243
9474
|
function resolvesToGlobal(identifier) {
|
|
9244
9475
|
const scope = context.sourceCode.getScope(identifier);
|
|
9245
|
-
const variable =
|
|
9476
|
+
const variable = ASTUtils4.findVariable(scope, identifier.name);
|
|
9246
9477
|
return variable === null || variable.defs.length === 0;
|
|
9247
9478
|
}
|
|
9248
9479
|
function isGlobalFetchCall2(callee) {
|
|
9249
|
-
if (callee.type ===
|
|
9480
|
+
if (callee.type === AST_NODE_TYPES45.Identifier) {
|
|
9250
9481
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
9251
9482
|
}
|
|
9252
|
-
return callee.type ===
|
|
9483
|
+
return callee.type === AST_NODE_TYPES45.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES45.Identifier && callee.property.name === "fetch" && callee.object.type === AST_NODE_TYPES45.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
9253
9484
|
}
|
|
9254
9485
|
return {
|
|
9255
9486
|
CallExpression(node) {
|
|
@@ -9269,7 +9500,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
9269
9500
|
});
|
|
9270
9501
|
|
|
9271
9502
|
// src/rules/require-interface-for-injected-service.ts
|
|
9272
|
-
import { AST_NODE_TYPES as
|
|
9503
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES46 } from "@typescript-eslint/utils";
|
|
9273
9504
|
var CONFIGISH_TYPE_RE = /(?:Options|Opts|Config|Configuration|Settings|Params|Props|Args|Env|Environment|Callbacks|Flags)$/;
|
|
9274
9505
|
var CONFIGISH_NAME_RE = /^(?:options|opts|config|configuration|settings|params|props|args|env|environment|callbacks|flags|logger|log|clock)$/i;
|
|
9275
9506
|
var HTTP_TRANSPORT_TYPE_RE = /^(?:KyInstance|AxiosInstance|Session)$/;
|
|
@@ -9277,20 +9508,20 @@ var BUILTIN_CONTAINER_TYPE_RE = /^(?:Record|Map|WeakMap|Set|WeakSet|Array|Readon
|
|
|
9277
9508
|
var TRANSPORT_WRAPPER_NAME_RE = /Client$/;
|
|
9278
9509
|
var ROUTER_FACTORY_NAME = "Router";
|
|
9279
9510
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
9280
|
-
var isExportedClass = (node) => node.parent.type ===
|
|
9281
|
-
var qualifiedName = (name) => name.type ===
|
|
9511
|
+
var isExportedClass = (node) => node.parent.type === AST_NODE_TYPES46.ExportNamedDeclaration || node.parent.type === AST_NODE_TYPES46.ExportDefaultDeclaration;
|
|
9512
|
+
var qualifiedName = (name) => name.type === AST_NODE_TYPES46.Identifier ? name.name : name.type === AST_NODE_TYPES46.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
9282
9513
|
var readTypeReference = (annotation) => {
|
|
9283
|
-
if (annotation === void 0 || annotation.type !==
|
|
9514
|
+
if (annotation === void 0 || annotation.type !== AST_NODE_TYPES46.TSTypeReference) return null;
|
|
9284
9515
|
const { typeName } = annotation;
|
|
9285
|
-
const rightmost = typeName.type ===
|
|
9516
|
+
const rightmost = typeName.type === AST_NODE_TYPES46.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES46.TSQualifiedName ? typeName.right.name : null;
|
|
9286
9517
|
if (rightmost === null) return null;
|
|
9287
9518
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
9288
9519
|
};
|
|
9289
9520
|
var namedParameterCollaborator = (annotated) => {
|
|
9290
9521
|
let target = annotated;
|
|
9291
|
-
if (target.type ===
|
|
9292
|
-
if (target.type ===
|
|
9293
|
-
if (target.type !==
|
|
9522
|
+
if (target.type === AST_NODE_TYPES46.TSParameterProperty) target = target.parameter;
|
|
9523
|
+
if (target.type === AST_NODE_TYPES46.AssignmentPattern) target = target.left;
|
|
9524
|
+
if (target.type !== AST_NODE_TYPES46.Identifier) return null;
|
|
9294
9525
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
9295
9526
|
if (reference === null) return null;
|
|
9296
9527
|
return { name: target.name, ...reference };
|
|
@@ -9298,8 +9529,8 @@ var namedParameterCollaborator = (annotated) => {
|
|
|
9298
9529
|
var propertySignatureTypes = (members) => {
|
|
9299
9530
|
const types = /* @__PURE__ */ new Map();
|
|
9300
9531
|
for (const member of members) {
|
|
9301
|
-
if (member.type !==
|
|
9302
|
-
if (member.computed || member.key.type !==
|
|
9532
|
+
if (member.type !== AST_NODE_TYPES46.TSPropertySignature) continue;
|
|
9533
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES46.Identifier) continue;
|
|
9303
9534
|
const reference = readTypeReference(member.typeAnnotation?.typeAnnotation);
|
|
9304
9535
|
if (reference === null) continue;
|
|
9305
9536
|
types.set(member.key.name, reference);
|
|
@@ -9310,18 +9541,18 @@ var fileTypeIndex = (program) => {
|
|
|
9310
9541
|
const objects = /* @__PURE__ */ new Map();
|
|
9311
9542
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
9312
9543
|
for (const statement of program.body) {
|
|
9313
|
-
const declaration = statement.type ===
|
|
9314
|
-
if (declaration?.type ===
|
|
9544
|
+
const declaration = statement.type === AST_NODE_TYPES46.ExportNamedDeclaration ? statement.declaration : statement;
|
|
9545
|
+
if (declaration?.type === AST_NODE_TYPES46.TSInterfaceDeclaration) {
|
|
9315
9546
|
objects.set(declaration.id.name, propertySignatureTypes(declaration.body.body));
|
|
9316
9547
|
continue;
|
|
9317
9548
|
}
|
|
9318
|
-
if (declaration?.type !==
|
|
9549
|
+
if (declaration?.type !== AST_NODE_TYPES46.TSTypeAliasDeclaration) continue;
|
|
9319
9550
|
const aliased = declaration.typeAnnotation;
|
|
9320
|
-
if (aliased.type ===
|
|
9551
|
+
if (aliased.type === AST_NODE_TYPES46.TSFunctionType || aliased.type === AST_NODE_TYPES46.TSConstructorType) {
|
|
9321
9552
|
functionAliases.add(declaration.id.name);
|
|
9322
9553
|
continue;
|
|
9323
9554
|
}
|
|
9324
|
-
const literals = aliased.type ===
|
|
9555
|
+
const literals = aliased.type === AST_NODE_TYPES46.TSTypeLiteral ? [aliased] : aliased.type === AST_NODE_TYPES46.TSIntersectionType ? aliased.types.filter((part) => part.type === AST_NODE_TYPES46.TSTypeLiteral) : [];
|
|
9325
9556
|
if (literals.length === 0) continue;
|
|
9326
9557
|
const merged = /* @__PURE__ */ new Map();
|
|
9327
9558
|
for (const literal of literals) {
|
|
@@ -9334,10 +9565,10 @@ var fileTypeIndex = (program) => {
|
|
|
9334
9565
|
return { objects, functionAliases };
|
|
9335
9566
|
};
|
|
9336
9567
|
var bagMemberTypes = (annotation, declared) => {
|
|
9337
|
-
if (annotation.type ===
|
|
9568
|
+
if (annotation.type === AST_NODE_TYPES46.TSTypeLiteral) {
|
|
9338
9569
|
return propertySignatureTypes(annotation.members);
|
|
9339
9570
|
}
|
|
9340
|
-
if (annotation.type !==
|
|
9571
|
+
if (annotation.type !== AST_NODE_TYPES46.TSTypeReference || annotation.typeName.type !== AST_NODE_TYPES46.Identifier) {
|
|
9341
9572
|
return null;
|
|
9342
9573
|
}
|
|
9343
9574
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
@@ -9349,11 +9580,11 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
9349
9580
|
if (members === null) return [];
|
|
9350
9581
|
const collaborators = [];
|
|
9351
9582
|
for (const property of pattern.properties) {
|
|
9352
|
-
if (property.type !==
|
|
9353
|
-
if (property.key.type !==
|
|
9583
|
+
if (property.type !== AST_NODE_TYPES46.Property || property.computed) continue;
|
|
9584
|
+
if (property.key.type !== AST_NODE_TYPES46.Identifier) continue;
|
|
9354
9585
|
const key = property.key.name;
|
|
9355
|
-
const bound = property.value.type ===
|
|
9356
|
-
if (bound.type !==
|
|
9586
|
+
const bound = property.value.type === AST_NODE_TYPES46.AssignmentPattern ? property.value.left : property.value;
|
|
9587
|
+
if (bound.type !== AST_NODE_TYPES46.Identifier) continue;
|
|
9357
9588
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
9358
9589
|
const reference = members.get(key);
|
|
9359
9590
|
if (reference === void 0) continue;
|
|
@@ -9363,8 +9594,8 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
9363
9594
|
};
|
|
9364
9595
|
var parameterCollaborators = (parameter, declared) => {
|
|
9365
9596
|
let target = parameter;
|
|
9366
|
-
if (target.type ===
|
|
9367
|
-
if (target.type ===
|
|
9597
|
+
if (target.type === AST_NODE_TYPES46.AssignmentPattern) target = target.left;
|
|
9598
|
+
if (target.type === AST_NODE_TYPES46.ObjectPattern) {
|
|
9368
9599
|
return objectPatternCollaborators(target, declared);
|
|
9369
9600
|
}
|
|
9370
9601
|
const named2 = namedParameterCollaborator(parameter);
|
|
@@ -9383,17 +9614,17 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
9383
9614
|
let constructedFields = 0;
|
|
9384
9615
|
if (body2 !== null && body2 !== void 0) {
|
|
9385
9616
|
for (const statement of body2.body) {
|
|
9386
|
-
if (statement.type !==
|
|
9617
|
+
if (statement.type !== AST_NODE_TYPES46.ExpressionStatement) continue;
|
|
9387
9618
|
const expression = statement.expression;
|
|
9388
|
-
if (expression.type !==
|
|
9619
|
+
if (expression.type !== AST_NODE_TYPES46.AssignmentExpression || expression.operator !== "=" || expression.left.type !== AST_NODE_TYPES46.MemberExpression || expression.left.object.type !== AST_NODE_TYPES46.ThisExpression) {
|
|
9389
9620
|
continue;
|
|
9390
9621
|
}
|
|
9391
9622
|
const source = expression.right;
|
|
9392
|
-
if (source.type ===
|
|
9623
|
+
if (source.type === AST_NODE_TYPES46.NewExpression) {
|
|
9393
9624
|
constructedFields += 1;
|
|
9394
|
-
} else if (source.type ===
|
|
9625
|
+
} else if (source.type === AST_NODE_TYPES46.Identifier) {
|
|
9395
9626
|
storedFrom.add(source.name);
|
|
9396
|
-
} else if (source.type ===
|
|
9627
|
+
} else if (source.type === AST_NODE_TYPES46.MemberExpression && source.object.type === AST_NODE_TYPES46.Identifier) {
|
|
9397
9628
|
storedFrom.add(source.object.name);
|
|
9398
9629
|
}
|
|
9399
9630
|
}
|
|
@@ -9401,7 +9632,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
9401
9632
|
const collaborators = [];
|
|
9402
9633
|
for (const parameter of ctor.value.params) {
|
|
9403
9634
|
for (const reference of parameterCollaborators(parameter, declared)) {
|
|
9404
|
-
const stored = parameter.type ===
|
|
9635
|
+
const stored = parameter.type === AST_NODE_TYPES46.TSParameterProperty || storedFrom.has(reference.name);
|
|
9405
9636
|
if (!stored) continue;
|
|
9406
9637
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
9407
9638
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -9435,19 +9666,19 @@ var subtreeHas = (root, found) => {
|
|
|
9435
9666
|
return hit;
|
|
9436
9667
|
};
|
|
9437
9668
|
var isFrameworkWiring = (body2) => subtreeHas(body2, (node) => {
|
|
9438
|
-
if (node.type ===
|
|
9669
|
+
if (node.type === AST_NODE_TYPES46.CallExpression) {
|
|
9439
9670
|
const { callee } = node;
|
|
9440
|
-
if (callee.type ===
|
|
9441
|
-
return callee.type ===
|
|
9671
|
+
if (callee.type === AST_NODE_TYPES46.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
9672
|
+
return callee.type === AST_NODE_TYPES46.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES46.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
9442
9673
|
}
|
|
9443
|
-
return node.type ===
|
|
9674
|
+
return node.type === AST_NODE_TYPES46.TSTypeReference && node.typeName.type === AST_NODE_TYPES46.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
9444
9675
|
});
|
|
9445
9676
|
var stem2 = (name) => name.replace(/^I(?=[A-Z])/, "").replace(/Impl$/, "");
|
|
9446
9677
|
var fileInterfaceNames = (program) => {
|
|
9447
9678
|
const names = [];
|
|
9448
9679
|
for (const statement of program.body) {
|
|
9449
|
-
const declaration = statement.type ===
|
|
9450
|
-
if (declaration?.type ===
|
|
9680
|
+
const declaration = statement.type === AST_NODE_TYPES46.ExportNamedDeclaration ? statement.declaration : statement;
|
|
9681
|
+
if (declaration?.type === AST_NODE_TYPES46.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
9451
9682
|
}
|
|
9452
9683
|
return names;
|
|
9453
9684
|
};
|
|
@@ -9465,11 +9696,11 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
9465
9696
|
var publicMethodNames = (body2) => {
|
|
9466
9697
|
const names = [];
|
|
9467
9698
|
for (const member of body2.body) {
|
|
9468
|
-
if (member.type !==
|
|
9699
|
+
if (member.type !== AST_NODE_TYPES46.MethodDefinition) continue;
|
|
9469
9700
|
if (member.kind !== "method" || member.static) continue;
|
|
9470
9701
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
9471
|
-
if (member.key.type ===
|
|
9472
|
-
if (member.key.type ===
|
|
9702
|
+
if (member.key.type === AST_NODE_TYPES46.PrivateIdentifier) continue;
|
|
9703
|
+
if (member.key.type === AST_NODE_TYPES46.Identifier) names.push(member.key.name);
|
|
9473
9704
|
else names.push("\u2026");
|
|
9474
9705
|
}
|
|
9475
9706
|
return names;
|
|
@@ -9502,7 +9733,7 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
9502
9733
|
if (node.implements.length > 0) return;
|
|
9503
9734
|
if (node.decorators.length > 0) return;
|
|
9504
9735
|
const ctor = node.body.body.find(
|
|
9505
|
-
(member) => member.type ===
|
|
9736
|
+
(member) => member.type === AST_NODE_TYPES46.MethodDefinition && member.kind === "constructor"
|
|
9506
9737
|
);
|
|
9507
9738
|
if (ctor === void 0) return;
|
|
9508
9739
|
const { collaborators, constructedFields } = readConstructor(
|
|
@@ -9530,19 +9761,97 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
9530
9761
|
}
|
|
9531
9762
|
});
|
|
9532
9763
|
|
|
9764
|
+
// src/rules/require-static-next-matcher.ts
|
|
9765
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES47 } from "@typescript-eslint/utils";
|
|
9766
|
+
var NEXT_ENTRY_FILE = /(?:^|[/\\])(?:middleware|proxy)\.[cm]?[jt]sx?$/u;
|
|
9767
|
+
function unwrapExpression(node) {
|
|
9768
|
+
if (node.type === AST_NODE_TYPES47.TSAsExpression || node.type === AST_NODE_TYPES47.TSSatisfiesExpression || node.type === AST_NODE_TYPES47.TSNonNullExpression || node.type === AST_NODE_TYPES47.TSTypeAssertion) {
|
|
9769
|
+
return unwrapExpression(node.expression);
|
|
9770
|
+
}
|
|
9771
|
+
return node;
|
|
9772
|
+
}
|
|
9773
|
+
function isStaticValue(node) {
|
|
9774
|
+
const value = unwrapExpression(node);
|
|
9775
|
+
if (value.type === AST_NODE_TYPES47.Literal) {
|
|
9776
|
+
return true;
|
|
9777
|
+
}
|
|
9778
|
+
if (value.type === AST_NODE_TYPES47.TemplateLiteral) {
|
|
9779
|
+
return value.expressions.length === 0;
|
|
9780
|
+
}
|
|
9781
|
+
if (value.type === AST_NODE_TYPES47.ArrayExpression) {
|
|
9782
|
+
return value.elements.every(
|
|
9783
|
+
(element) => element !== null && element.type !== AST_NODE_TYPES47.SpreadElement && isStaticValue(element)
|
|
9784
|
+
);
|
|
9785
|
+
}
|
|
9786
|
+
if (value.type === AST_NODE_TYPES47.ObjectExpression) {
|
|
9787
|
+
return value.properties.every(
|
|
9788
|
+
(property) => property.type === AST_NODE_TYPES47.Property && property.kind === "init" && !property.computed && property.value.type !== AST_NODE_TYPES47.AssignmentPattern && isStaticValue(property.value)
|
|
9789
|
+
);
|
|
9790
|
+
}
|
|
9791
|
+
return false;
|
|
9792
|
+
}
|
|
9793
|
+
function propertyName2(property) {
|
|
9794
|
+
if (property.computed) return null;
|
|
9795
|
+
if (property.key.type === AST_NODE_TYPES47.Identifier) return property.key.name;
|
|
9796
|
+
return typeof property.key.value === "string" ? property.key.value : null;
|
|
9797
|
+
}
|
|
9798
|
+
var require_static_next_matcher_default = createRule({
|
|
9799
|
+
name: "require-static-next-matcher",
|
|
9800
|
+
meta: {
|
|
9801
|
+
type: "problem",
|
|
9802
|
+
docs: {
|
|
9803
|
+
description: "Require Next.js middleware and proxy matcher configuration to contain only build-time literals."
|
|
9804
|
+
},
|
|
9805
|
+
schema: [],
|
|
9806
|
+
messages: {
|
|
9807
|
+
dynamicMatcher: "Next.js matcher values must contain only literal arrays and objects. Calls, identifiers, concatenation, interpolated templates, and spreads are not statically analyzable and fail the production build."
|
|
9808
|
+
}
|
|
9809
|
+
},
|
|
9810
|
+
defaultOptions: [],
|
|
9811
|
+
create(context) {
|
|
9812
|
+
if (!NEXT_ENTRY_FILE.test(context.filename)) {
|
|
9813
|
+
return {};
|
|
9814
|
+
}
|
|
9815
|
+
return {
|
|
9816
|
+
ExportNamedDeclaration(node) {
|
|
9817
|
+
if (node.declaration?.type !== AST_NODE_TYPES47.VariableDeclaration) {
|
|
9818
|
+
return;
|
|
9819
|
+
}
|
|
9820
|
+
for (const declaration of node.declaration.declarations) {
|
|
9821
|
+
if (declaration.id.type !== AST_NODE_TYPES47.Identifier || declaration.id.name !== "config" || declaration.init === null) {
|
|
9822
|
+
continue;
|
|
9823
|
+
}
|
|
9824
|
+
const config = unwrapExpression(declaration.init);
|
|
9825
|
+
if (config.type !== AST_NODE_TYPES47.ObjectExpression) {
|
|
9826
|
+
continue;
|
|
9827
|
+
}
|
|
9828
|
+
for (const property of config.properties) {
|
|
9829
|
+
if (property.type !== AST_NODE_TYPES47.Property || propertyName2(property) !== "matcher" || property.value.type === AST_NODE_TYPES47.AssignmentPattern) {
|
|
9830
|
+
continue;
|
|
9831
|
+
}
|
|
9832
|
+
if (!isStaticValue(property.value)) {
|
|
9833
|
+
context.report({ node: property.value, messageId: "dynamicMatcher" });
|
|
9834
|
+
}
|
|
9835
|
+
}
|
|
9836
|
+
}
|
|
9837
|
+
}
|
|
9838
|
+
};
|
|
9839
|
+
}
|
|
9840
|
+
});
|
|
9841
|
+
|
|
9533
9842
|
// src/rules/require-zod-form-validation.ts
|
|
9534
|
-
import { AST_NODE_TYPES as
|
|
9843
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES48 } from "@typescript-eslint/utils";
|
|
9535
9844
|
var looksLikeZodSchema = (node) => {
|
|
9536
9845
|
let current = node;
|
|
9537
9846
|
while (true) {
|
|
9538
|
-
if (current.type ===
|
|
9847
|
+
if (current.type === AST_NODE_TYPES48.Identifier) {
|
|
9539
9848
|
return current.name === "z" || ZOD_SCHEMA_NAME_RE.test(current.name);
|
|
9540
9849
|
}
|
|
9541
|
-
if (current.type ===
|
|
9850
|
+
if (current.type === AST_NODE_TYPES48.CallExpression) {
|
|
9542
9851
|
current = current.callee;
|
|
9543
9852
|
continue;
|
|
9544
9853
|
}
|
|
9545
|
-
if (current.type ===
|
|
9854
|
+
if (current.type === AST_NODE_TYPES48.MemberExpression) {
|
|
9546
9855
|
current = current.object;
|
|
9547
9856
|
continue;
|
|
9548
9857
|
}
|
|
@@ -9550,23 +9859,23 @@ var looksLikeZodSchema = (node) => {
|
|
|
9550
9859
|
}
|
|
9551
9860
|
};
|
|
9552
9861
|
var isZodParseCall = (node) => {
|
|
9553
|
-
if (node.type !==
|
|
9862
|
+
if (node.type !== AST_NODE_TYPES48.CallExpression) return false;
|
|
9554
9863
|
const callee = node.callee;
|
|
9555
|
-
if (callee.type !==
|
|
9864
|
+
if (callee.type !== AST_NODE_TYPES48.MemberExpression) return false;
|
|
9556
9865
|
if (callee.computed) return false;
|
|
9557
|
-
if (callee.property.type !==
|
|
9866
|
+
if (callee.property.type !== AST_NODE_TYPES48.Identifier) return false;
|
|
9558
9867
|
const method = callee.property.name;
|
|
9559
9868
|
if (method !== "parse" && method !== "safeParse") return false;
|
|
9560
9869
|
return looksLikeZodSchema(callee.object);
|
|
9561
9870
|
};
|
|
9562
9871
|
var isFormDataMethodCall = (node) => {
|
|
9563
9872
|
let current = node;
|
|
9564
|
-
if (current.type ===
|
|
9873
|
+
if (current.type === AST_NODE_TYPES48.AwaitExpression) {
|
|
9565
9874
|
current = current.argument;
|
|
9566
9875
|
}
|
|
9567
|
-
if (current.type !==
|
|
9876
|
+
if (current.type !== AST_NODE_TYPES48.CallExpression) return false;
|
|
9568
9877
|
const callee = current.callee;
|
|
9569
|
-
return callee.type ===
|
|
9878
|
+
return callee.type === AST_NODE_TYPES48.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES48.Identifier && callee.property.name === "formData";
|
|
9570
9879
|
};
|
|
9571
9880
|
var require_zod_form_validation_default = createRule({
|
|
9572
9881
|
name: "require-zod-form-validation",
|
|
@@ -9586,14 +9895,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
9586
9895
|
return {};
|
|
9587
9896
|
}
|
|
9588
9897
|
const isFormSourceIdentifier = (node) => {
|
|
9589
|
-
if (node.type !==
|
|
9898
|
+
if (node.type !== AST_NODE_TYPES48.Identifier) return false;
|
|
9590
9899
|
if (/formdata/i.test(node.name)) return true;
|
|
9591
9900
|
let scope = context.sourceCode.getScope(node);
|
|
9592
9901
|
while (scope !== null) {
|
|
9593
9902
|
const variable = scope.set.get(node.name);
|
|
9594
9903
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
9595
9904
|
const def = variable.defs[0];
|
|
9596
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
9905
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === AST_NODE_TYPES48.VariableDeclarator && def.node.init !== null) {
|
|
9597
9906
|
return isFormDataMethodCall(def.node.init);
|
|
9598
9907
|
}
|
|
9599
9908
|
return false;
|
|
@@ -9604,8 +9913,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
9604
9913
|
};
|
|
9605
9914
|
const isFormDataGetCall = (node) => {
|
|
9606
9915
|
const callee = node.callee;
|
|
9607
|
-
if (callee.type !==
|
|
9608
|
-
if (callee.property.type !==
|
|
9916
|
+
if (callee.type !== AST_NODE_TYPES48.MemberExpression) return false;
|
|
9917
|
+
if (callee.property.type !== AST_NODE_TYPES48.Identifier || callee.property.name !== "get") {
|
|
9609
9918
|
return false;
|
|
9610
9919
|
}
|
|
9611
9920
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -9620,11 +9929,11 @@ var require_zod_form_validation_default = createRule({
|
|
|
9620
9929
|
};
|
|
9621
9930
|
const isInstanceofNarrowing = (node) => {
|
|
9622
9931
|
const parent = node.parent;
|
|
9623
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
9932
|
+
return parent !== null && parent !== void 0 && parent.type === AST_NODE_TYPES48.BinaryExpression && parent.operator === "instanceof" && parent.left === node && parent.right.type === AST_NODE_TYPES48.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
9624
9933
|
};
|
|
9625
9934
|
const boundDeclarator = (node) => {
|
|
9626
9935
|
const parent = node.parent;
|
|
9627
|
-
if (parent.type ===
|
|
9936
|
+
if (parent.type === AST_NODE_TYPES48.VariableDeclarator && parent.init === node && parent.id.type === AST_NODE_TYPES48.Identifier) {
|
|
9628
9937
|
return parent;
|
|
9629
9938
|
}
|
|
9630
9939
|
return null;
|
|
@@ -9683,7 +9992,7 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
9683
9992
|
});
|
|
9684
9993
|
|
|
9685
9994
|
// src/rules/zod-naming-convention.ts
|
|
9686
|
-
import { AST_NODE_TYPES as
|
|
9995
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES49 } from "@typescript-eslint/utils";
|
|
9687
9996
|
var CONVENTIONS = {
|
|
9688
9997
|
prefix: { test: ZOD_PREFIX_RE, messageId: "zPrefix" },
|
|
9689
9998
|
suffix: { test: ZOD_SUFFIX_RE, messageId: "schemaSuffix" },
|
|
@@ -9708,15 +10017,15 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
9708
10017
|
"registry",
|
|
9709
10018
|
"implement"
|
|
9710
10019
|
]);
|
|
9711
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
10020
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === AST_NODE_TYPES49.Identifier ? callee.property.name : null;
|
|
9712
10021
|
var calleeChainStartsWithZ = (node) => {
|
|
9713
10022
|
let current = node;
|
|
9714
|
-
while (current.type ===
|
|
10023
|
+
while (current.type === AST_NODE_TYPES49.MemberExpression) {
|
|
9715
10024
|
const receiver = current.object;
|
|
9716
|
-
if (receiver.type ===
|
|
10025
|
+
if (receiver.type === AST_NODE_TYPES49.Identifier && receiver.name === "z") {
|
|
9717
10026
|
return true;
|
|
9718
10027
|
}
|
|
9719
|
-
if (receiver.type ===
|
|
10028
|
+
if (receiver.type === AST_NODE_TYPES49.CallExpression) {
|
|
9720
10029
|
current = receiver.callee;
|
|
9721
10030
|
continue;
|
|
9722
10031
|
}
|
|
@@ -9761,13 +10070,13 @@ var zod_naming_convention_default = createRule({
|
|
|
9761
10070
|
VariableDeclarator(node) {
|
|
9762
10071
|
const init = node.init;
|
|
9763
10072
|
if (init === null || init === void 0) return;
|
|
9764
|
-
if (init.type !==
|
|
10073
|
+
if (init.type !== AST_NODE_TYPES49.CallExpression) return;
|
|
9765
10074
|
const callee = init.callee;
|
|
9766
|
-
if (callee.type !==
|
|
10075
|
+
if (callee.type !== AST_NODE_TYPES49.MemberExpression) return;
|
|
9767
10076
|
if (!calleeChainStartsWithZ(callee)) return;
|
|
9768
10077
|
const terminal = terminalMethodName(callee);
|
|
9769
10078
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
9770
|
-
if (node.id.type !==
|
|
10079
|
+
if (node.id.type !== AST_NODE_TYPES49.Identifier) return;
|
|
9771
10080
|
if (test.test(node.id.name)) return;
|
|
9772
10081
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
9773
10082
|
context.report({
|
|
@@ -9847,6 +10156,7 @@ var rules = {
|
|
|
9847
10156
|
"no-enum": no_enum_default,
|
|
9848
10157
|
"no-fat-try-blocks": no_fat_try_blocks_default,
|
|
9849
10158
|
"no-hand-rolled-sleep": no_hand_rolled_sleep_default,
|
|
10159
|
+
"no-hand-rolled-spinner": no_hand_rolled_spinner_default,
|
|
9850
10160
|
"no-insecure-random-id": no_insecure_random_id_default,
|
|
9851
10161
|
"no-json-stringify-error": no_json_stringify_error_default,
|
|
9852
10162
|
"no-log-only-catch": no_log_only_catch_default,
|
|
@@ -9855,6 +10165,7 @@ var rules = {
|
|
|
9855
10165
|
"no-positional-tuple-return": no_positional_tuple_return_default,
|
|
9856
10166
|
"no-raw-env": no_raw_env_default,
|
|
9857
10167
|
"no-raw-fetch-outside-clients": no_raw_fetch_outside_clients_default,
|
|
10168
|
+
"no-restricted-library-load": no_restricted_library_load_default,
|
|
9858
10169
|
"no-repeated-string-literal": no_repeated_string_literal_default,
|
|
9859
10170
|
"no-restated-comment": no_restated_comment_default,
|
|
9860
10171
|
"no-restated-jsdoc": no_restated_jsdoc_default,
|
|
@@ -9879,6 +10190,7 @@ var rules = {
|
|
|
9879
10190
|
"prefer-module-level-constant": prefer_module_level_constant_default,
|
|
9880
10191
|
"prefer-module-level-schema": prefer_module_level_schema_default,
|
|
9881
10192
|
"prefer-non-nullable-collection": prefer_non_nullable_collection_default,
|
|
10193
|
+
"prefer-native-random-uuid": prefer_native_random_uuid_default,
|
|
9882
10194
|
"prefer-schema-for-api-payload": prefer_schema_for_api_payload_default,
|
|
9883
10195
|
"prefer-semantic-colors": prefer_semantic_colors_default,
|
|
9884
10196
|
"prefer-server-actions": prefer_server_actions_default,
|
|
@@ -9890,14 +10202,19 @@ var rules = {
|
|
|
9890
10202
|
"require-assert-never": require_assert_never_default,
|
|
9891
10203
|
"require-fetch-timeout": require_fetch_timeout_default,
|
|
9892
10204
|
"require-interface-for-injected-service": require_interface_for_injected_service_default,
|
|
10205
|
+
"require-static-next-matcher": require_static_next_matcher_default,
|
|
9893
10206
|
"require-zod-form-validation": require_zod_form_validation_default,
|
|
9894
10207
|
"store-insert-requires-on-conflict": store_insert_requires_on_conflict_default,
|
|
9895
10208
|
"zod-naming-convention": zod_naming_convention_default
|
|
9896
10209
|
};
|
|
9897
10210
|
var meta = {
|
|
9898
10211
|
name: "@sarj/eslint-plugin",
|
|
9899
|
-
version: "9.
|
|
10212
|
+
version: "9.9.0"
|
|
9900
10213
|
};
|
|
10214
|
+
var applicationOnlyRules = [
|
|
10215
|
+
"no-restricted-library-load",
|
|
10216
|
+
"prefer-native-random-uuid"
|
|
10217
|
+
];
|
|
9901
10218
|
var recommendedRules = {
|
|
9902
10219
|
"@sarj/enforce-file-structure": "warn",
|
|
9903
10220
|
"@sarj/no-async-callback-in-wait-for": "warn",
|
|
@@ -9908,6 +10225,7 @@ var recommendedRules = {
|
|
|
9908
10225
|
"@sarj/no-dynamic-sql": "warn",
|
|
9909
10226
|
"@sarj/no-fat-try-blocks": "warn",
|
|
9910
10227
|
"@sarj/no-hand-rolled-sleep": "warn",
|
|
10228
|
+
"@sarj/no-hand-rolled-spinner": "error",
|
|
9911
10229
|
"@sarj/no-insecure-random-id": "warn",
|
|
9912
10230
|
"@sarj/no-json-stringify-error": "warn",
|
|
9913
10231
|
"@sarj/no-log-only-catch": "warn",
|
|
@@ -9948,6 +10266,7 @@ var recommendedRules = {
|
|
|
9948
10266
|
"@sarj/require-assert-never": "error",
|
|
9949
10267
|
"@sarj/require-fetch-timeout": "warn",
|
|
9950
10268
|
"@sarj/require-interface-for-injected-service": "warn",
|
|
10269
|
+
"@sarj/require-static-next-matcher": "error",
|
|
9951
10270
|
"@sarj/require-zod-form-validation": "error",
|
|
9952
10271
|
"@sarj/store-insert-requires-on-conflict": "warn",
|
|
9953
10272
|
"@sarj/zod-naming-convention": "warn"
|
|
@@ -9963,6 +10282,7 @@ var strictRules = {
|
|
|
9963
10282
|
"@sarj/no-enum": "error",
|
|
9964
10283
|
"@sarj/no-fat-try-blocks": "error",
|
|
9965
10284
|
"@sarj/no-hand-rolled-sleep": "error",
|
|
10285
|
+
"@sarj/no-hand-rolled-spinner": "error",
|
|
9966
10286
|
"@sarj/no-insecure-random-id": "error",
|
|
9967
10287
|
"@sarj/no-json-stringify-error": "error",
|
|
9968
10288
|
"@sarj/no-log-only-catch": "error",
|
|
@@ -10006,6 +10326,7 @@ var strictRules = {
|
|
|
10006
10326
|
"@sarj/require-assert-never": "error",
|
|
10007
10327
|
"@sarj/require-fetch-timeout": "error",
|
|
10008
10328
|
"@sarj/require-interface-for-injected-service": "error",
|
|
10329
|
+
"@sarj/require-static-next-matcher": "error",
|
|
10009
10330
|
"@sarj/require-zod-form-validation": "error",
|
|
10010
10331
|
"@sarj/store-insert-requires-on-conflict": "error",
|
|
10011
10332
|
"@sarj/zod-naming-convention": "error"
|
|
@@ -10033,6 +10354,7 @@ plugin.configs.strict = {
|
|
|
10033
10354
|
};
|
|
10034
10355
|
var index_default = plugin;
|
|
10035
10356
|
export {
|
|
10357
|
+
applicationOnlyRules,
|
|
10036
10358
|
index_default as default,
|
|
10037
10359
|
recommendedRules,
|
|
10038
10360
|
renamedRules,
|