@sarj/eslint-plugin 15.13.3 → 15.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +703 -544
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +709 -546
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12008,13 +12008,173 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
12008
12008
|
}
|
|
12009
12009
|
});
|
|
12010
12010
|
|
|
12011
|
-
// src/rules/prefer-
|
|
12011
|
+
// src/rules/prefer-nullish-filter-predicate.ts
|
|
12012
12012
|
import {
|
|
12013
|
+
AST_NODE_TYPES as AST_NODE_TYPES52,
|
|
12013
12014
|
ASTUtils as ASTUtils16,
|
|
12014
|
-
ESLintUtils as ESLintUtils5
|
|
12015
|
-
|
|
12015
|
+
ESLintUtils as ESLintUtils5
|
|
12016
|
+
} from "@typescript-eslint/utils";
|
|
12017
|
+
import ts3 from "typescript";
|
|
12018
|
+
var PREFER_NULLISH_FILTER_PREDICATE_DOCUMENTATION = {
|
|
12019
|
+
summary: "Prefer an explicit nullish predicate when `filter(Boolean)` removes only nullish values but does not narrow the result type.",
|
|
12020
|
+
rationale: "An explicit nullish predicate preserves the same runtime elements while letting TypeScript remove `null` and `undefined` from the result.",
|
|
12021
|
+
remediation: "Replace `filter(Boolean)` with `filter((value) => value !== null && value !== undefined)`.",
|
|
12022
|
+
category: "correctness",
|
|
12023
|
+
autofix: "suggestion",
|
|
12024
|
+
limitations: [
|
|
12025
|
+
"The receiver must resolve to the built-in Array or ReadonlyArray filter method.",
|
|
12026
|
+
"Broad primitive types, falsy literals, any, unknown, generics, intersections, custom filters, and shadowed Boolean bindings are excluded."
|
|
12027
|
+
],
|
|
12028
|
+
examples: [
|
|
12029
|
+
{
|
|
12030
|
+
id: "explicit-nullish-predicate",
|
|
12031
|
+
title: "Nullish filtering narrows the result",
|
|
12032
|
+
outcome: "no-match",
|
|
12033
|
+
files: [
|
|
12034
|
+
{
|
|
12035
|
+
path: "src/users.ts",
|
|
12036
|
+
source: "declare const users: readonly ({ id: string } | null)[];\nconst present = users.filter((user) => user !== null && user !== undefined);"
|
|
12037
|
+
}
|
|
12038
|
+
],
|
|
12039
|
+
focusPath: "src/users.ts",
|
|
12040
|
+
expectedCount: 0,
|
|
12041
|
+
public: true
|
|
12042
|
+
},
|
|
12043
|
+
{
|
|
12044
|
+
id: "boolean-nullish-filter",
|
|
12045
|
+
title: "Boolean filtering loses nullish narrowing",
|
|
12046
|
+
outcome: "match",
|
|
12047
|
+
files: [
|
|
12048
|
+
{
|
|
12049
|
+
path: "src/users.ts",
|
|
12050
|
+
source: "declare const users: readonly ({ id: string } | null)[];\nconst present = users.filter(Boolean);"
|
|
12051
|
+
}
|
|
12052
|
+
],
|
|
12053
|
+
focusPath: "src/users.ts",
|
|
12054
|
+
expectedCount: 1,
|
|
12055
|
+
public: true
|
|
12056
|
+
}
|
|
12057
|
+
]
|
|
12058
|
+
};
|
|
12059
|
+
function isUnshadowedBoolean(node, context) {
|
|
12060
|
+
const variable = ASTUtils16.findVariable(context.sourceCode.getScope(node), node.name);
|
|
12061
|
+
return variable === null || variable.defs.length === 0;
|
|
12062
|
+
}
|
|
12063
|
+
function isBuiltinArrayFilter(node, services) {
|
|
12064
|
+
const checker = services.program.getTypeChecker();
|
|
12065
|
+
const property = services.esTreeNodeToTSNodeMap.get(node.property);
|
|
12066
|
+
const symbol = checker.getSymbolAtLocation(property);
|
|
12067
|
+
return symbol?.declarations?.some((declaration) => {
|
|
12068
|
+
const owner = declaration.parent;
|
|
12069
|
+
return ts3.isInterfaceDeclaration(owner) && (owner.name.text === "Array" || owner.name.text === "ReadonlyArray") && services.program.isSourceFileDefaultLibrary(owner.getSourceFile());
|
|
12070
|
+
}) ?? false;
|
|
12071
|
+
}
|
|
12072
|
+
function arrayElementType(node, services) {
|
|
12073
|
+
const checker = services.program.getTypeChecker();
|
|
12074
|
+
const receiver = services.esTreeNodeToTSNodeMap.get(node);
|
|
12075
|
+
return checker.getIndexTypeOfType(checker.getTypeAtLocation(receiver), ts3.IndexKind.Number) ?? null;
|
|
12076
|
+
}
|
|
12077
|
+
var NULLISH_FLAGS = ts3.TypeFlags.Null | ts3.TypeFlags.Undefined;
|
|
12078
|
+
var UNKNOWN_FLAGS = ts3.TypeFlags.Any | ts3.TypeFlags.Unknown | ts3.TypeFlags.TypeParameter | ts3.TypeFlags.Intersection | ts3.TypeFlags.Enum | ts3.TypeFlags.EnumLiteral;
|
|
12079
|
+
function isNullishPlusTruthy(type, checker) {
|
|
12080
|
+
const members = type.isUnion() ? type.types : [type];
|
|
12081
|
+
let sawNullish = false;
|
|
12082
|
+
for (const member of members) {
|
|
12083
|
+
if ((member.flags & NULLISH_FLAGS) !== 0) {
|
|
12084
|
+
sawNullish = true;
|
|
12085
|
+
} else if ((member.flags & ts3.TypeFlags.Never) === 0 && !isProvablyTruthy(member, checker)) {
|
|
12086
|
+
return false;
|
|
12087
|
+
}
|
|
12088
|
+
}
|
|
12089
|
+
return sawNullish;
|
|
12090
|
+
}
|
|
12091
|
+
function isProvablyTruthy(type, checker) {
|
|
12092
|
+
if ((type.flags & UNKNOWN_FLAGS) !== 0) return false;
|
|
12093
|
+
if ((type.flags & ts3.TypeFlags.Object) !== 0) {
|
|
12094
|
+
return ![
|
|
12095
|
+
checker.getStringType(),
|
|
12096
|
+
checker.getNumberType(),
|
|
12097
|
+
checker.getBigIntType(),
|
|
12098
|
+
checker.getBooleanType()
|
|
12099
|
+
].some((primitive) => checker.isTypeAssignableTo(primitive, type));
|
|
12100
|
+
}
|
|
12101
|
+
if ((type.flags & (ts3.TypeFlags.ESSymbol | ts3.TypeFlags.UniqueESSymbol)) !== 0) return true;
|
|
12102
|
+
if ((type.flags & ts3.TypeFlags.BooleanLiteral) !== 0) {
|
|
12103
|
+
return type.intrinsicName === "true";
|
|
12104
|
+
}
|
|
12105
|
+
if ((type.flags & ts3.TypeFlags.StringLiteral) !== 0) {
|
|
12106
|
+
return type.value.length > 0;
|
|
12107
|
+
}
|
|
12108
|
+
if ((type.flags & ts3.TypeFlags.NumberLiteral) !== 0) {
|
|
12109
|
+
const value = type.value;
|
|
12110
|
+
return value !== 0 && !Number.isNaN(value);
|
|
12111
|
+
}
|
|
12112
|
+
if ((type.flags & ts3.TypeFlags.BigIntLiteral) !== 0) {
|
|
12113
|
+
return type.value.base10Value !== "0";
|
|
12114
|
+
}
|
|
12115
|
+
return false;
|
|
12116
|
+
}
|
|
12117
|
+
function availableParameterName(node, context) {
|
|
12118
|
+
for (const name of ["value", "item", "element", "candidate"]) {
|
|
12119
|
+
if (ASTUtils16.findVariable(context.sourceCode.getScope(node), name) === null) return name;
|
|
12120
|
+
}
|
|
12121
|
+
return null;
|
|
12122
|
+
}
|
|
12123
|
+
var prefer_nullish_filter_predicate_default = createRule({
|
|
12124
|
+
name: "prefer-nullish-filter-predicate",
|
|
12125
|
+
documentation: PREFER_NULLISH_FILTER_PREDICATE_DOCUMENTATION,
|
|
12126
|
+
meta: {
|
|
12127
|
+
type: "suggestion",
|
|
12128
|
+
docs: { description: PREFER_NULLISH_FILTER_PREDICATE_DOCUMENTATION.summary },
|
|
12129
|
+
hasSuggestions: true,
|
|
12130
|
+
schema: [],
|
|
12131
|
+
messages: {
|
|
12132
|
+
preferNullishPredicate: "This built-in array contains only nullish or provably truthy values, so `filter(Boolean)` preserves runtime values but loses nullish narrowing. Use an explicit nullish predicate.",
|
|
12133
|
+
replaceBoolean: "Replace `Boolean` with an explicit nullish predicate."
|
|
12134
|
+
}
|
|
12135
|
+
},
|
|
12136
|
+
defaultOptions: [],
|
|
12137
|
+
create(context) {
|
|
12138
|
+
if (isGeneratedFile(context.filename, context.sourceCode.text)) return {};
|
|
12139
|
+
let services;
|
|
12140
|
+
try {
|
|
12141
|
+
services = ESLintUtils5.getParserServices(context);
|
|
12142
|
+
} catch {
|
|
12143
|
+
services = null;
|
|
12144
|
+
}
|
|
12145
|
+
if (services === null) return {};
|
|
12146
|
+
return {
|
|
12147
|
+
CallExpression(node) {
|
|
12148
|
+
const callee = node.callee;
|
|
12149
|
+
const callback = node.arguments[0];
|
|
12150
|
+
if (node.arguments.length !== 1 || callback?.type !== AST_NODE_TYPES52.Identifier || callback.name !== "Boolean" || callee.type !== AST_NODE_TYPES52.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES52.Identifier || callee.property.name !== "filter" || !isUnshadowedBoolean(callback, context) || !isBuiltinArrayFilter(callee, services)) return;
|
|
12151
|
+
const elementType = arrayElementType(callee.object, services);
|
|
12152
|
+
const checker = services.program.getTypeChecker();
|
|
12153
|
+
if (elementType === null || !isNullishPlusTruthy(elementType, checker)) return;
|
|
12154
|
+
const parameter = availableParameterName(node, context);
|
|
12155
|
+
context.report({
|
|
12156
|
+
node: callback,
|
|
12157
|
+
messageId: "preferNullishPredicate",
|
|
12158
|
+
suggest: parameter === null ? null : [{
|
|
12159
|
+
messageId: "replaceBoolean",
|
|
12160
|
+
fix: (fixer) => fixer.replaceText(
|
|
12161
|
+
callback,
|
|
12162
|
+
`(${parameter}) => ${parameter} !== null && ${parameter} !== undefined`
|
|
12163
|
+
)
|
|
12164
|
+
}]
|
|
12165
|
+
});
|
|
12166
|
+
}
|
|
12167
|
+
};
|
|
12168
|
+
}
|
|
12169
|
+
});
|
|
12170
|
+
|
|
12171
|
+
// src/rules/prefer-await-in-async-return.ts
|
|
12172
|
+
import {
|
|
12173
|
+
ASTUtils as ASTUtils17,
|
|
12174
|
+
ESLintUtils as ESLintUtils6,
|
|
12175
|
+
AST_NODE_TYPES as AST_NODE_TYPES53
|
|
12016
12176
|
} from "@typescript-eslint/utils";
|
|
12017
|
-
import * as
|
|
12177
|
+
import * as ts4 from "typescript";
|
|
12018
12178
|
var PREFER_AWAIT_IN_ASYNC_RETURN_DOCUMENTATION = {
|
|
12019
12179
|
summary: "Prefer explicit `await` when an async function directly returns one typed Promise `.then` transform.",
|
|
12020
12180
|
rationale: "Mixing a directly returned Promise callback into otherwise async control flow makes sequencing and failures harder to read.",
|
|
@@ -12055,10 +12215,10 @@ var PREFER_AWAIT_IN_ASYNC_RETURN_DOCUMENTATION = {
|
|
|
12055
12215
|
};
|
|
12056
12216
|
function directAsyncReturnOwner(node) {
|
|
12057
12217
|
const parent = node.parent;
|
|
12058
|
-
if (parent.type ===
|
|
12218
|
+
if (parent.type === AST_NODE_TYPES53.ArrowFunctionExpression && parent.body === node) {
|
|
12059
12219
|
return parent.async && !parent.generator ? parent : null;
|
|
12060
12220
|
}
|
|
12061
|
-
if (parent.type !==
|
|
12221
|
+
if (parent.type !== AST_NODE_TYPES53.ReturnStatement || parent.argument !== node) {
|
|
12062
12222
|
return null;
|
|
12063
12223
|
}
|
|
12064
12224
|
let owner = parent.parent;
|
|
@@ -12068,15 +12228,15 @@ function directAsyncReturnOwner(node) {
|
|
|
12068
12228
|
return owner !== void 0 && owner.async && !owner.generator ? owner : null;
|
|
12069
12229
|
}
|
|
12070
12230
|
function isRuntimeFunction(node) {
|
|
12071
|
-
return node.type ===
|
|
12231
|
+
return node.type === AST_NODE_TYPES53.ArrowFunctionExpression || node.type === AST_NODE_TYPES53.FunctionDeclaration || node.type === AST_NODE_TYPES53.FunctionExpression;
|
|
12072
12232
|
}
|
|
12073
12233
|
function promiseThenReceiver(node) {
|
|
12074
12234
|
const callee = node.callee;
|
|
12075
|
-
if (callee.type !==
|
|
12235
|
+
if (callee.type !== AST_NODE_TYPES53.MemberExpression || callee.computed || callee.optional || callee.property.type !== AST_NODE_TYPES53.Identifier || callee.property.name !== "then" || node.optional || node.arguments.length !== 1) {
|
|
12076
12236
|
return null;
|
|
12077
12237
|
}
|
|
12078
12238
|
const callback = node.arguments[0];
|
|
12079
|
-
if (callback === void 0 || callback.type !==
|
|
12239
|
+
if (callback === void 0 || callback.type !== AST_NODE_TYPES53.ArrowFunctionExpression && callback.type !== AST_NODE_TYPES53.FunctionExpression) {
|
|
12080
12240
|
return null;
|
|
12081
12241
|
}
|
|
12082
12242
|
return callee.object;
|
|
@@ -12085,14 +12245,14 @@ function isProvenPromiseLike(node, services) {
|
|
|
12085
12245
|
const checker = services.program.getTypeChecker();
|
|
12086
12246
|
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
|
12087
12247
|
const receiverType = checker.getTypeAtLocation(tsNode);
|
|
12088
|
-
if ((receiverType.flags & (
|
|
12248
|
+
if ((receiverType.flags & (ts4.TypeFlags.Any | ts4.TypeFlags.Unknown | ts4.TypeFlags.Never)) !== 0) {
|
|
12089
12249
|
return false;
|
|
12090
12250
|
}
|
|
12091
12251
|
const thenSymbol = checker.getPropertyOfType(receiverType, "then");
|
|
12092
12252
|
const hasBuiltInPromiseDeclaration = thenSymbol?.declarations?.some(
|
|
12093
12253
|
(declaration) => {
|
|
12094
12254
|
let owner = declaration.parent;
|
|
12095
|
-
while (owner !== void 0 && !
|
|
12255
|
+
while (owner !== void 0 && !ts4.isInterfaceDeclaration(owner)) {
|
|
12096
12256
|
owner = owner.parent;
|
|
12097
12257
|
}
|
|
12098
12258
|
return owner !== void 0 && (owner.name.text === "Promise" || owner.name.text === "PromiseLike") && services.program.isSourceFileDefaultLibrary(owner.getSourceFile());
|
|
@@ -12117,32 +12277,32 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
12117
12277
|
create(context) {
|
|
12118
12278
|
let services;
|
|
12119
12279
|
try {
|
|
12120
|
-
services =
|
|
12280
|
+
services = ESLintUtils6.getParserServices(context);
|
|
12121
12281
|
} catch {
|
|
12122
12282
|
services = null;
|
|
12123
12283
|
}
|
|
12124
12284
|
if (services === null) return {};
|
|
12125
12285
|
const frameworkLoaders = /* @__PURE__ */ new Set();
|
|
12126
12286
|
const rememberFrameworkLoader = (identifier) => {
|
|
12127
|
-
const variable =
|
|
12287
|
+
const variable = ASTUtils17.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
12128
12288
|
if (variable !== null) frameworkLoaders.add(variable);
|
|
12129
12289
|
};
|
|
12130
12290
|
const isFrameworkLoaderCallback = (owner) => {
|
|
12131
12291
|
const parent = owner.parent;
|
|
12132
|
-
if (parent.type !==
|
|
12133
|
-
const variable =
|
|
12292
|
+
if (parent.type !== AST_NODE_TYPES53.CallExpression || parent.arguments[0] !== owner || parent.callee.type !== AST_NODE_TYPES53.Identifier) return false;
|
|
12293
|
+
const variable = ASTUtils17.findVariable(context.sourceCode.getScope(parent.callee), parent.callee.name);
|
|
12134
12294
|
return variable !== null && frameworkLoaders.has(variable);
|
|
12135
12295
|
};
|
|
12136
12296
|
return {
|
|
12137
12297
|
ImportDeclaration(node) {
|
|
12138
12298
|
if (node.source.value === "react") {
|
|
12139
12299
|
for (const specifier of node.specifiers) {
|
|
12140
|
-
if (specifier.type ===
|
|
12300
|
+
if (specifier.type === AST_NODE_TYPES53.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES53.Identifier ? specifier.imported.name : specifier.imported.value) === "lazy") rememberFrameworkLoader(specifier.local);
|
|
12141
12301
|
}
|
|
12142
12302
|
}
|
|
12143
12303
|
if (node.source.value === "next/dynamic") {
|
|
12144
12304
|
for (const specifier of node.specifiers) {
|
|
12145
|
-
if (specifier.type ===
|
|
12305
|
+
if (specifier.type === AST_NODE_TYPES53.ImportDefaultSpecifier) rememberFrameworkLoader(specifier.local);
|
|
12146
12306
|
}
|
|
12147
12307
|
}
|
|
12148
12308
|
},
|
|
@@ -12160,7 +12320,7 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
12160
12320
|
});
|
|
12161
12321
|
|
|
12162
12322
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
12163
|
-
import { AST_NODE_TYPES as
|
|
12323
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES54 } from "@typescript-eslint/utils";
|
|
12164
12324
|
var PREFER_SCHEMA_FOR_API_PAYLOAD_DOCUMENTATION = {
|
|
12165
12325
|
summary: "Require Zod (or similar) schema validation on `response.json()` / `JSON.parse()` results before property access.",
|
|
12166
12326
|
rationale: "External JSON is untrusted at runtime even when its expected TypeScript shape is known statically.",
|
|
@@ -12175,9 +12335,9 @@ var PREFER_SCHEMA_FOR_API_PAYLOAD_DOCUMENTATION = {
|
|
|
12175
12335
|
var unwrap4 = (node) => {
|
|
12176
12336
|
let current = node;
|
|
12177
12337
|
while (current !== null && current !== void 0) {
|
|
12178
|
-
if (current.type ===
|
|
12338
|
+
if (current.type === AST_NODE_TYPES54.TSAsExpression || current.type === AST_NODE_TYPES54.TSTypeAssertion || current.type === AST_NODE_TYPES54.TSNonNullExpression || current.type === AST_NODE_TYPES54.TSSatisfiesExpression) {
|
|
12179
12339
|
current = current.expression;
|
|
12180
|
-
} else if (current.type ===
|
|
12340
|
+
} else if (current.type === AST_NODE_TYPES54.ChainExpression) {
|
|
12181
12341
|
current = current.expression;
|
|
12182
12342
|
} else {
|
|
12183
12343
|
break;
|
|
@@ -12192,23 +12352,23 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
12192
12352
|
]);
|
|
12193
12353
|
var isSchemaParseReference = (node) => {
|
|
12194
12354
|
const inner = unwrap4(node);
|
|
12195
|
-
return inner !== null && inner.type ===
|
|
12355
|
+
return inner !== null && inner.type === AST_NODE_TYPES54.MemberExpression && !inner.computed && inner.property.type === AST_NODE_TYPES54.Identifier && (inner.property.name === "parse" || inner.property.name === "safeParse");
|
|
12196
12356
|
};
|
|
12197
12357
|
var isRawPayloadSource = (node, isKnownLocalText) => {
|
|
12198
12358
|
let current = unwrap4(node);
|
|
12199
12359
|
if (current === null) return false;
|
|
12200
|
-
if (current.type ===
|
|
12360
|
+
if (current.type === AST_NODE_TYPES54.AwaitExpression) {
|
|
12201
12361
|
current = unwrap4(current.argument);
|
|
12202
12362
|
}
|
|
12203
|
-
if (current === null || current.type !==
|
|
12363
|
+
if (current === null || current.type !== AST_NODE_TYPES54.CallExpression) {
|
|
12204
12364
|
return false;
|
|
12205
12365
|
}
|
|
12206
12366
|
const callee = unwrap4(current.callee);
|
|
12207
|
-
if (callee === null || callee.type !==
|
|
12367
|
+
if (callee === null || callee.type !== AST_NODE_TYPES54.MemberExpression) {
|
|
12208
12368
|
return false;
|
|
12209
12369
|
}
|
|
12210
12370
|
const property = unwrap4(callee.property);
|
|
12211
|
-
if (property === null || property.type !==
|
|
12371
|
+
if (property === null || property.type !== AST_NODE_TYPES54.Identifier) {
|
|
12212
12372
|
return false;
|
|
12213
12373
|
}
|
|
12214
12374
|
if (property.name === "json") {
|
|
@@ -12218,17 +12378,17 @@ var isRawPayloadSource = (node, isKnownLocalText) => {
|
|
|
12218
12378
|
return !current.arguments.some(isSchemaParseReference) && isRawPayloadSource(callee.object);
|
|
12219
12379
|
}
|
|
12220
12380
|
const object = unwrap4(callee.object);
|
|
12221
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
12381
|
+
return property.name === "parse" && object !== null && object.type === AST_NODE_TYPES54.Identifier && object.name === "JSON" && !isLocalFileRead(current.arguments[0]) && isKnownLocalText?.(current.arguments[0]) !== true;
|
|
12222
12382
|
};
|
|
12223
12383
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
12224
12384
|
var isDirectLocalFileRead = (node) => {
|
|
12225
12385
|
let current = unwrap4(node);
|
|
12226
|
-
if (current?.type ===
|
|
12386
|
+
if (current?.type === AST_NODE_TYPES54.AwaitExpression) {
|
|
12227
12387
|
current = unwrap4(current.argument);
|
|
12228
12388
|
}
|
|
12229
|
-
if (current?.type !==
|
|
12389
|
+
if (current?.type !== AST_NODE_TYPES54.CallExpression) return false;
|
|
12230
12390
|
const callee = unwrap4(current.callee);
|
|
12231
|
-
const name = callee?.type ===
|
|
12391
|
+
const name = callee?.type === AST_NODE_TYPES54.Identifier ? callee.name : callee?.type === AST_NODE_TYPES54.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES54.Identifier ? callee.property.name : null;
|
|
12232
12392
|
return name !== null && FILE_READ_RE.test(name);
|
|
12233
12393
|
};
|
|
12234
12394
|
var isLocalFileRead = (node) => {
|
|
@@ -12255,15 +12415,15 @@ var isLocalFileRead = (node) => {
|
|
|
12255
12415
|
var ASSERTION_CALLEE_RE = /^(expect|assert|should|invariant)$/;
|
|
12256
12416
|
var isInsideAssertion = (node) => {
|
|
12257
12417
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
12258
|
-
if (current.type !==
|
|
12418
|
+
if (current.type !== AST_NODE_TYPES54.CallExpression) continue;
|
|
12259
12419
|
let callee = current.callee;
|
|
12260
|
-
while (callee.type ===
|
|
12420
|
+
while (callee.type === AST_NODE_TYPES54.MemberExpression) {
|
|
12261
12421
|
callee = callee.object;
|
|
12262
12422
|
}
|
|
12263
|
-
if (callee.type ===
|
|
12423
|
+
if (callee.type === AST_NODE_TYPES54.CallExpression) {
|
|
12264
12424
|
callee = callee.callee;
|
|
12265
12425
|
}
|
|
12266
|
-
if (callee.type ===
|
|
12426
|
+
if (callee.type === AST_NODE_TYPES54.Identifier && ASSERTION_CALLEE_RE.test(callee.name)) {
|
|
12267
12427
|
return true;
|
|
12268
12428
|
}
|
|
12269
12429
|
}
|
|
@@ -12282,22 +12442,22 @@ var GUARD_NAME_RE = /^(?:is|validate|parse|assert|decode|coerce)[A-Z]/;
|
|
|
12282
12442
|
var isValidationRead = (node) => {
|
|
12283
12443
|
let current = node;
|
|
12284
12444
|
let parent = current.parent;
|
|
12285
|
-
while (parent !== null && parent !== void 0 && (parent.type ===
|
|
12445
|
+
while (parent !== null && parent !== void 0 && (parent.type === AST_NODE_TYPES54.TSAsExpression || parent.type === AST_NODE_TYPES54.TSTypeAssertion || parent.type === AST_NODE_TYPES54.TSNonNullExpression || parent.type === AST_NODE_TYPES54.TSSatisfiesExpression || parent.type === AST_NODE_TYPES54.ChainExpression)) {
|
|
12286
12446
|
current = parent;
|
|
12287
12447
|
parent = parent.parent;
|
|
12288
12448
|
}
|
|
12289
12449
|
if (parent === null || parent === void 0) return false;
|
|
12290
|
-
if (parent.type ===
|
|
12450
|
+
if (parent.type === AST_NODE_TYPES54.UnaryExpression && parent.operator === "typeof" && parent.argument === current) {
|
|
12291
12451
|
return true;
|
|
12292
12452
|
}
|
|
12293
|
-
if (parent.type !==
|
|
12453
|
+
if (parent.type !== AST_NODE_TYPES54.CallExpression || !parent.arguments.some((arg) => arg === current)) {
|
|
12294
12454
|
return false;
|
|
12295
12455
|
}
|
|
12296
12456
|
const callee = parent.callee;
|
|
12297
|
-
if (callee.type ===
|
|
12457
|
+
if (callee.type === AST_NODE_TYPES54.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES54.Identifier && callee.object.name === "Array" && callee.property.type === AST_NODE_TYPES54.Identifier && callee.property.name === "isArray") {
|
|
12298
12458
|
return parent.arguments.length === 1;
|
|
12299
12459
|
}
|
|
12300
|
-
return callee.type ===
|
|
12460
|
+
return callee.type === AST_NODE_TYPES54.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
12301
12461
|
};
|
|
12302
12462
|
var PRIMITIVE_TYPEOF_RESULTS = /* @__PURE__ */ new Set([
|
|
12303
12463
|
"bigint",
|
|
@@ -12308,13 +12468,13 @@ var PRIMITIVE_TYPEOF_RESULTS = /* @__PURE__ */ new Set([
|
|
|
12308
12468
|
"undefined"
|
|
12309
12469
|
]);
|
|
12310
12470
|
var bindingValidationPolarity = (test, bindingName) => {
|
|
12311
|
-
if (test.type ===
|
|
12471
|
+
if (test.type === AST_NODE_TYPES54.UnaryExpression && test.operator === "!") {
|
|
12312
12472
|
const inner = bindingValidationPolarity(test.argument, bindingName);
|
|
12313
12473
|
return inner === "valid-when-true" ? "valid-when-false" : inner === "valid-when-false" ? "valid-when-true" : null;
|
|
12314
12474
|
}
|
|
12315
|
-
if (test.type ===
|
|
12316
|
-
const typeofName = (node) => node.type ===
|
|
12317
|
-
const literalType = (node) => node.type ===
|
|
12475
|
+
if (test.type === AST_NODE_TYPES54.BinaryExpression) {
|
|
12476
|
+
const typeofName = (node) => node.type === AST_NODE_TYPES54.UnaryExpression && node.operator === "typeof" && node.argument.type === AST_NODE_TYPES54.Identifier ? node.argument.name : null;
|
|
12477
|
+
const literalType = (node) => node.type === AST_NODE_TYPES54.Literal && typeof node.value === "string" && PRIMITIVE_TYPEOF_RESULTS.has(node.value) ? node.value : null;
|
|
12318
12478
|
const matches = typeofName(test.left) === bindingName && literalType(test.right) !== null || typeofName(test.right) === bindingName && literalType(test.left) !== null;
|
|
12319
12479
|
if (!matches) return null;
|
|
12320
12480
|
if (test.operator === "===" || test.operator === "==") {
|
|
@@ -12322,9 +12482,9 @@ var bindingValidationPolarity = (test, bindingName) => {
|
|
|
12322
12482
|
}
|
|
12323
12483
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
12324
12484
|
}
|
|
12325
|
-
return test.type ===
|
|
12485
|
+
return test.type === AST_NODE_TYPES54.CallExpression && test.arguments.length === 1 && test.arguments[0]?.type === AST_NODE_TYPES54.Identifier && test.arguments[0].name === bindingName && test.callee.type === AST_NODE_TYPES54.MemberExpression && !test.callee.computed && test.callee.object.type === AST_NODE_TYPES54.Identifier && test.callee.object.name === "Array" && test.callee.property.type === AST_NODE_TYPES54.Identifier && test.callee.property.name === "isArray" ? "valid-when-true" : null;
|
|
12326
12486
|
};
|
|
12327
|
-
var plainMemberAccess = (node) => node.type ===
|
|
12487
|
+
var plainMemberAccess = (node) => node.type === AST_NODE_TYPES54.MemberExpression && !node.computed && node.object.type === AST_NODE_TYPES54.Identifier && node.property.type === AST_NODE_TYPES54.Identifier ? { object: node.object.name, property: node.property.name } : null;
|
|
12328
12488
|
var isSamePlainMember = (node, access) => {
|
|
12329
12489
|
const candidate2 = plainMemberAccess(node);
|
|
12330
12490
|
return candidate2 !== null && candidate2.object === access.object && candidate2.property === access.property;
|
|
@@ -12332,19 +12492,19 @@ var isSamePlainMember = (node, access) => {
|
|
|
12332
12492
|
var nodeWithin2 = (node, container) => node.range[0] >= container.range[0] && node.range[1] <= container.range[1];
|
|
12333
12493
|
var isUseWithinValidatedBranch = (node, bindingName) => {
|
|
12334
12494
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
12335
|
-
if (current.type ===
|
|
12495
|
+
if (current.type === AST_NODE_TYPES54.ConditionalExpression) {
|
|
12336
12496
|
const polarity = bindingValidationPolarity(current.test, bindingName);
|
|
12337
12497
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && nodeWithin2(node, current.alternate)) {
|
|
12338
12498
|
return true;
|
|
12339
12499
|
}
|
|
12340
12500
|
}
|
|
12341
|
-
if (current.type ===
|
|
12501
|
+
if (current.type === AST_NODE_TYPES54.IfStatement) {
|
|
12342
12502
|
const polarity = bindingValidationPolarity(current.test, bindingName);
|
|
12343
12503
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && current.alternate !== null && nodeWithin2(node, current.alternate)) {
|
|
12344
12504
|
return true;
|
|
12345
12505
|
}
|
|
12346
12506
|
}
|
|
12347
|
-
if (current.type ===
|
|
12507
|
+
if (current.type === AST_NODE_TYPES54.FunctionDeclaration || current.type === AST_NODE_TYPES54.FunctionExpression || current.type === AST_NODE_TYPES54.ArrowFunctionExpression) {
|
|
12348
12508
|
return false;
|
|
12349
12509
|
}
|
|
12350
12510
|
}
|
|
@@ -12352,32 +12512,32 @@ var isUseWithinValidatedBranch = (node, bindingName) => {
|
|
|
12352
12512
|
};
|
|
12353
12513
|
var isMemberUseWithinValidatedBranch = (node, access) => {
|
|
12354
12514
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
12355
|
-
if (current.type ===
|
|
12515
|
+
if (current.type === AST_NODE_TYPES54.ConditionalExpression) {
|
|
12356
12516
|
const polarity = memberValidationPolarity(current.test, access);
|
|
12357
12517
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && nodeWithin2(node, current.alternate)) {
|
|
12358
12518
|
return true;
|
|
12359
12519
|
}
|
|
12360
12520
|
}
|
|
12361
|
-
if (current.type ===
|
|
12521
|
+
if (current.type === AST_NODE_TYPES54.IfStatement) {
|
|
12362
12522
|
const polarity = memberValidationPolarity(current.test, access);
|
|
12363
12523
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && current.alternate !== null && nodeWithin2(node, current.alternate)) {
|
|
12364
12524
|
return true;
|
|
12365
12525
|
}
|
|
12366
12526
|
}
|
|
12367
|
-
if (current.type ===
|
|
12527
|
+
if (current.type === AST_NODE_TYPES54.FunctionDeclaration || current.type === AST_NODE_TYPES54.FunctionExpression || current.type === AST_NODE_TYPES54.ArrowFunctionExpression) {
|
|
12368
12528
|
return false;
|
|
12369
12529
|
}
|
|
12370
12530
|
}
|
|
12371
12531
|
return false;
|
|
12372
12532
|
};
|
|
12373
12533
|
var memberValidationPolarity = (test, access) => {
|
|
12374
|
-
if (test.type ===
|
|
12534
|
+
if (test.type === AST_NODE_TYPES54.UnaryExpression && test.operator === "!") {
|
|
12375
12535
|
const inner = memberValidationPolarity(test.argument, access);
|
|
12376
12536
|
return inner === "valid-when-true" ? "valid-when-false" : inner === "valid-when-false" ? "valid-when-true" : null;
|
|
12377
12537
|
}
|
|
12378
|
-
if (test.type ===
|
|
12379
|
-
const isMatchingTypeof = (node) => node.type ===
|
|
12380
|
-
const isPrimitiveType = (node) => node.type ===
|
|
12538
|
+
if (test.type === AST_NODE_TYPES54.BinaryExpression) {
|
|
12539
|
+
const isMatchingTypeof = (node) => node.type === AST_NODE_TYPES54.UnaryExpression && node.operator === "typeof" && isSamePlainMember(node.argument, access);
|
|
12540
|
+
const isPrimitiveType = (node) => node.type === AST_NODE_TYPES54.Literal && typeof node.value === "string" && PRIMITIVE_TYPEOF_RESULTS.has(node.value);
|
|
12381
12541
|
if (!(isMatchingTypeof(test.left) && isPrimitiveType(test.right) || isMatchingTypeof(test.right) && isPrimitiveType(test.left))) {
|
|
12382
12542
|
return null;
|
|
12383
12543
|
}
|
|
@@ -12386,15 +12546,15 @@ var memberValidationPolarity = (test, access) => {
|
|
|
12386
12546
|
}
|
|
12387
12547
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
12388
12548
|
}
|
|
12389
|
-
return test.type ===
|
|
12549
|
+
return test.type === AST_NODE_TYPES54.CallExpression && test.arguments.length === 1 && test.arguments[0] !== void 0 && test.arguments[0].type !== AST_NODE_TYPES54.SpreadElement && isSamePlainMember(test.arguments[0], access) && test.callee.type === AST_NODE_TYPES54.MemberExpression && !test.callee.computed && test.callee.object.type === AST_NODE_TYPES54.Identifier && test.callee.object.name === "Array" && test.callee.property.type === AST_NODE_TYPES54.Identifier && test.callee.property.name === "isArray" ? "valid-when-true" : null;
|
|
12390
12550
|
};
|
|
12391
12551
|
var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
12392
12552
|
const isValidationReference = (identifier) => {
|
|
12393
12553
|
for (let current = identifier.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
12394
|
-
if ((current.type ===
|
|
12554
|
+
if ((current.type === AST_NODE_TYPES54.BinaryExpression || current.type === AST_NODE_TYPES54.CallExpression || current.type === AST_NODE_TYPES54.UnaryExpression) && bindingValidationPolarity(current, identifier.name) !== null) {
|
|
12395
12555
|
return true;
|
|
12396
12556
|
}
|
|
12397
|
-
if (current.type !==
|
|
12557
|
+
if (current.type !== AST_NODE_TYPES54.UnaryExpression && current.type !== AST_NODE_TYPES54.MemberExpression && current.type !== AST_NODE_TYPES54.CallExpression) {
|
|
12398
12558
|
return false;
|
|
12399
12559
|
}
|
|
12400
12560
|
}
|
|
@@ -12402,7 +12562,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
12402
12562
|
};
|
|
12403
12563
|
const isGuardedUse = (identifier) => {
|
|
12404
12564
|
for (let current = identifier.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
12405
|
-
if (current.type ===
|
|
12565
|
+
if (current.type === AST_NODE_TYPES54.ConditionalExpression) {
|
|
12406
12566
|
const polarity = bindingValidationPolarity(current.test, identifier.name);
|
|
12407
12567
|
if (polarity === "valid-when-true" && nodeWithin2(identifier, current.consequent)) {
|
|
12408
12568
|
return true;
|
|
@@ -12411,7 +12571,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
12411
12571
|
return true;
|
|
12412
12572
|
}
|
|
12413
12573
|
}
|
|
12414
|
-
if (current.type ===
|
|
12574
|
+
if (current.type === AST_NODE_TYPES54.IfStatement) {
|
|
12415
12575
|
const polarity = bindingValidationPolarity(current.test, identifier.name);
|
|
12416
12576
|
if (polarity === "valid-when-true" && nodeWithin2(identifier, current.consequent)) {
|
|
12417
12577
|
return true;
|
|
@@ -12420,14 +12580,14 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
12420
12580
|
return true;
|
|
12421
12581
|
}
|
|
12422
12582
|
}
|
|
12423
|
-
if (current.type ===
|
|
12583
|
+
if (current.type === AST_NODE_TYPES54.FunctionDeclaration || current.type === AST_NODE_TYPES54.FunctionExpression || current.type === AST_NODE_TYPES54.ArrowFunctionExpression) {
|
|
12424
12584
|
return false;
|
|
12425
12585
|
}
|
|
12426
12586
|
}
|
|
12427
12587
|
return false;
|
|
12428
12588
|
};
|
|
12429
12589
|
const declarator = member.parent;
|
|
12430
|
-
if (declarator.type !==
|
|
12590
|
+
if (declarator.type !== AST_NODE_TYPES54.VariableDeclarator || declarator.init !== member || declarator.id.type !== AST_NODE_TYPES54.Identifier || declarator.parent.type !== AST_NODE_TYPES54.VariableDeclaration || declarator.parent.kind !== "const") {
|
|
12431
12591
|
return false;
|
|
12432
12592
|
}
|
|
12433
12593
|
const extracted = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
@@ -12435,7 +12595,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
12435
12595
|
let hasValueUse = false;
|
|
12436
12596
|
for (const reference of extracted.references) {
|
|
12437
12597
|
const identifier = reference.identifier;
|
|
12438
|
-
if (identifier.type !==
|
|
12598
|
+
if (identifier.type !== AST_NODE_TYPES54.Identifier) return false;
|
|
12439
12599
|
if (nodeWithin2(identifier, declarator)) continue;
|
|
12440
12600
|
if (isValidationReference(identifier)) continue;
|
|
12441
12601
|
hasValueUse = true;
|
|
@@ -12448,17 +12608,17 @@ var isGuardTestPosition = (node) => {
|
|
|
12448
12608
|
let parent = current.parent;
|
|
12449
12609
|
while (parent !== void 0 && parent !== null) {
|
|
12450
12610
|
switch (parent.type) {
|
|
12451
|
-
case
|
|
12452
|
-
case
|
|
12453
|
-
case
|
|
12611
|
+
case AST_NODE_TYPES54.UnaryExpression:
|
|
12612
|
+
case AST_NODE_TYPES54.LogicalExpression:
|
|
12613
|
+
case AST_NODE_TYPES54.ChainExpression:
|
|
12454
12614
|
current = parent;
|
|
12455
12615
|
parent = parent.parent;
|
|
12456
12616
|
continue;
|
|
12457
|
-
case
|
|
12458
|
-
case
|
|
12459
|
-
case
|
|
12460
|
-
case
|
|
12461
|
-
case
|
|
12617
|
+
case AST_NODE_TYPES54.IfStatement:
|
|
12618
|
+
case AST_NODE_TYPES54.ConditionalExpression:
|
|
12619
|
+
case AST_NODE_TYPES54.WhileStatement:
|
|
12620
|
+
case AST_NODE_TYPES54.DoWhileStatement:
|
|
12621
|
+
case AST_NODE_TYPES54.ForStatement:
|
|
12462
12622
|
return parent.test === current;
|
|
12463
12623
|
default:
|
|
12464
12624
|
return false;
|
|
@@ -12468,7 +12628,7 @@ var isGuardTestPosition = (node) => {
|
|
|
12468
12628
|
};
|
|
12469
12629
|
var unvalidatedVariableRef = (node, scope, tracked) => {
|
|
12470
12630
|
const unwrapped = unwrap4(node);
|
|
12471
|
-
if (unwrapped === null || unwrapped.type !==
|
|
12631
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES54.Identifier) {
|
|
12472
12632
|
return null;
|
|
12473
12633
|
}
|
|
12474
12634
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -12497,7 +12657,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
12497
12657
|
const localFileTextVariables = /* @__PURE__ */ new Set();
|
|
12498
12658
|
const localFileTextRef = (node, scope) => {
|
|
12499
12659
|
const unwrapped = unwrap4(node);
|
|
12500
|
-
if (unwrapped?.type !==
|
|
12660
|
+
if (unwrapped?.type !== AST_NODE_TYPES54.Identifier) return null;
|
|
12501
12661
|
const variable = findVariable2(scope, unwrapped.name);
|
|
12502
12662
|
return variable !== null && localFileTextVariables.has(variable) ? variable : null;
|
|
12503
12663
|
};
|
|
@@ -12566,7 +12726,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
12566
12726
|
return {
|
|
12567
12727
|
VariableDeclarator(node) {
|
|
12568
12728
|
const scope = context.sourceCode.getScope(node);
|
|
12569
|
-
if (node.id.type ===
|
|
12729
|
+
if (node.id.type === AST_NODE_TYPES54.Identifier) {
|
|
12570
12730
|
const variable = context.sourceCode.getDeclaredVariables(node)[0];
|
|
12571
12731
|
if (variable !== void 0) {
|
|
12572
12732
|
updateLocalFileText(variable, node.init, scope);
|
|
@@ -12574,7 +12734,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
12574
12734
|
trackInitializer(node, scope);
|
|
12575
12735
|
return;
|
|
12576
12736
|
}
|
|
12577
|
-
if (node.id.type ===
|
|
12737
|
+
if (node.id.type === AST_NODE_TYPES54.ObjectPattern || node.id.type === AST_NODE_TYPES54.ArrayPattern) {
|
|
12578
12738
|
if (isRawPayloadSource(
|
|
12579
12739
|
node.init,
|
|
12580
12740
|
(candidate2) => localFileTextRef(candidate2, scope) !== null
|
|
@@ -12591,7 +12751,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
12591
12751
|
},
|
|
12592
12752
|
AssignmentExpression(node) {
|
|
12593
12753
|
const scope = context.sourceCode.getScope(node);
|
|
12594
|
-
if (node.left.type ===
|
|
12754
|
+
if (node.left.type === AST_NODE_TYPES54.Identifier) {
|
|
12595
12755
|
const variable = findVariable2(scope, node.left.name);
|
|
12596
12756
|
if (variable === null) return;
|
|
12597
12757
|
const isLocalText = (candidate2) => localFileTextRef(candidate2, scope) !== null;
|
|
@@ -12605,7 +12765,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
12605
12765
|
}
|
|
12606
12766
|
return;
|
|
12607
12767
|
}
|
|
12608
|
-
if (node.left.type ===
|
|
12768
|
+
if (node.left.type === AST_NODE_TYPES54.ObjectPattern || node.left.type === AST_NODE_TYPES54.ArrayPattern) {
|
|
12609
12769
|
if (isRawPayloadSource(
|
|
12610
12770
|
node.right,
|
|
12611
12771
|
(candidate2) => localFileTextRef(candidate2, scope) !== null
|
|
@@ -12625,15 +12785,15 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
12625
12785
|
}
|
|
12626
12786
|
},
|
|
12627
12787
|
CallExpression(node) {
|
|
12628
|
-
if (node.callee.type !==
|
|
12788
|
+
if (node.callee.type !== AST_NODE_TYPES54.Identifier) return;
|
|
12629
12789
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
12630
12790
|
return;
|
|
12631
12791
|
}
|
|
12632
12792
|
const scope = context.sourceCode.getScope(node);
|
|
12633
12793
|
for (const arg of node.arguments) {
|
|
12634
|
-
if (arg.type ===
|
|
12794
|
+
if (arg.type === AST_NODE_TYPES54.SpreadElement) continue;
|
|
12635
12795
|
const unwrapped = unwrap4(arg);
|
|
12636
|
-
if (unwrapped === null || unwrapped.type !==
|
|
12796
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES54.Identifier) {
|
|
12637
12797
|
continue;
|
|
12638
12798
|
}
|
|
12639
12799
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -12650,14 +12810,14 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
12650
12810
|
(candidate2) => localFileTextRef(candidate2, scope) !== null
|
|
12651
12811
|
)) {
|
|
12652
12812
|
const parent = node.parent;
|
|
12653
|
-
if (parent.type ===
|
|
12813
|
+
if (parent.type === AST_NODE_TYPES54.CallExpression && parent.callee === node && node.property.type === AST_NODE_TYPES54.Identifier && (node.property.name === "parse" || node.property.name === "safeParse" || PROMISE_CHAIN_METHODS.has(node.property.name))) {
|
|
12654
12814
|
return;
|
|
12655
12815
|
}
|
|
12656
12816
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
12657
12817
|
return;
|
|
12658
12818
|
}
|
|
12659
|
-
const variable = obj?.type ===
|
|
12660
|
-
if (variable !== null && obj?.type ===
|
|
12819
|
+
const variable = obj?.type === AST_NODE_TYPES54.Identifier ? unvalidatedVariableRef(obj, scope, unvalidatedVariables) : null;
|
|
12820
|
+
if (variable !== null && obj?.type === AST_NODE_TYPES54.Identifier) {
|
|
12661
12821
|
if (isUseWithinValidatedBranch(node, obj.name)) {
|
|
12662
12822
|
return;
|
|
12663
12823
|
}
|
|
@@ -12677,7 +12837,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
12677
12837
|
});
|
|
12678
12838
|
|
|
12679
12839
|
// src/rules/prefer-semantic-colors.ts
|
|
12680
|
-
import { AST_NODE_TYPES as
|
|
12840
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES55 } from "@typescript-eslint/utils";
|
|
12681
12841
|
import { existsSync, readdirSync, readFileSync } from "fs";
|
|
12682
12842
|
import { dirname, join, parse } from "path";
|
|
12683
12843
|
|
|
@@ -12789,7 +12949,7 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
12789
12949
|
var isInsideSvg = (node) => {
|
|
12790
12950
|
let current = node.parent;
|
|
12791
12951
|
while (current !== void 0 && current !== null) {
|
|
12792
|
-
if (current.type ===
|
|
12952
|
+
if (current.type === AST_NODE_TYPES55.JSXElement) {
|
|
12793
12953
|
const name = jsxElementName(current);
|
|
12794
12954
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
12795
12955
|
}
|
|
@@ -12799,8 +12959,8 @@ var isInsideSvg = (node) => {
|
|
|
12799
12959
|
};
|
|
12800
12960
|
function jsxElementName(node) {
|
|
12801
12961
|
const name = node.openingElement.name;
|
|
12802
|
-
if (name.type ===
|
|
12803
|
-
if (name.type ===
|
|
12962
|
+
if (name.type === AST_NODE_TYPES55.JSXIdentifier) return name.name;
|
|
12963
|
+
if (name.type === AST_NODE_TYPES55.JSXMemberExpression && name.property.type === AST_NODE_TYPES55.JSXIdentifier) {
|
|
12804
12964
|
return name.property.name;
|
|
12805
12965
|
}
|
|
12806
12966
|
return null;
|
|
@@ -12826,7 +12986,7 @@ function isSvgLikeElementName(name) {
|
|
|
12826
12986
|
var isInsideIconFactoryPath = (node) => {
|
|
12827
12987
|
let current = node.parent;
|
|
12828
12988
|
while (current !== void 0 && current !== null) {
|
|
12829
|
-
if (current.type ===
|
|
12989
|
+
if (current.type === AST_NODE_TYPES55.Property && propName(current.key) === "path" && current.parent.type === AST_NODE_TYPES55.ObjectExpression && current.parent.parent.type === AST_NODE_TYPES55.CallExpression && current.parent.parent.callee.type === AST_NODE_TYPES55.Identifier && current.parent.parent.callee.name === "createIcon") {
|
|
12830
12990
|
return true;
|
|
12831
12991
|
}
|
|
12832
12992
|
current = current.parent;
|
|
@@ -12960,12 +13120,12 @@ var expandWorkspaceGlob = (root, glob) => {
|
|
|
12960
13120
|
return readdirSync(parent, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => join(parent, entry.name));
|
|
12961
13121
|
};
|
|
12962
13122
|
var propName = (key) => {
|
|
12963
|
-
if (key.type ===
|
|
12964
|
-
if (key.type ===
|
|
13123
|
+
if (key.type === AST_NODE_TYPES55.Identifier) return key.name;
|
|
13124
|
+
if (key.type === AST_NODE_TYPES55.Literal && typeof key.value === "string") return key.value;
|
|
12965
13125
|
return null;
|
|
12966
13126
|
};
|
|
12967
13127
|
var staticallyImportsEmailOrPdfRenderer = (program) => program.body.some((statement) => {
|
|
12968
|
-
if (statement.type !==
|
|
13128
|
+
if (statement.type !== AST_NODE_TYPES55.ImportDeclaration && statement.type !== AST_NODE_TYPES55.ExportNamedDeclaration && statement.type !== AST_NODE_TYPES55.ExportAllDeclaration) {
|
|
12969
13129
|
return false;
|
|
12970
13130
|
}
|
|
12971
13131
|
return statement.source !== null && typeof statement.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(statement.source.value);
|
|
@@ -13018,27 +13178,27 @@ var prefer_semantic_colors_default = createRule({
|
|
|
13018
13178
|
const checkClassNode = (node) => {
|
|
13019
13179
|
if (node === null) return;
|
|
13020
13180
|
switch (node.type) {
|
|
13021
|
-
case
|
|
13181
|
+
case AST_NODE_TYPES55.Literal:
|
|
13022
13182
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
13023
13183
|
break;
|
|
13024
|
-
case
|
|
13184
|
+
case AST_NODE_TYPES55.TemplateLiteral:
|
|
13025
13185
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
13026
13186
|
break;
|
|
13027
|
-
case
|
|
13187
|
+
case AST_NODE_TYPES55.ArrayExpression:
|
|
13028
13188
|
for (const element of node.elements) {
|
|
13029
|
-
if (element !== null && element.type !==
|
|
13189
|
+
if (element !== null && element.type !== AST_NODE_TYPES55.SpreadElement) checkClassNode(element);
|
|
13030
13190
|
}
|
|
13031
13191
|
break;
|
|
13032
|
-
case
|
|
13192
|
+
case AST_NODE_TYPES55.ObjectExpression:
|
|
13033
13193
|
for (const property of node.properties) {
|
|
13034
|
-
if (property.type ===
|
|
13194
|
+
if (property.type === AST_NODE_TYPES55.Property) checkClassNode(property.value);
|
|
13035
13195
|
}
|
|
13036
13196
|
break;
|
|
13037
|
-
case
|
|
13197
|
+
case AST_NODE_TYPES55.ConditionalExpression:
|
|
13038
13198
|
checkClassNode(node.consequent);
|
|
13039
13199
|
checkClassNode(node.alternate);
|
|
13040
13200
|
break;
|
|
13041
|
-
case
|
|
13201
|
+
case AST_NODE_TYPES55.LogicalExpression:
|
|
13042
13202
|
checkClassNode(node.right);
|
|
13043
13203
|
break;
|
|
13044
13204
|
default:
|
|
@@ -13046,32 +13206,32 @@ var prefer_semantic_colors_default = createRule({
|
|
|
13046
13206
|
}
|
|
13047
13207
|
};
|
|
13048
13208
|
const checkColorValueNode = (node) => {
|
|
13049
|
-
if (node.type ===
|
|
13209
|
+
if (node.type === AST_NODE_TYPES55.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value) && !CSS_VAR_REFERENCE_RE.test(node.value)) {
|
|
13050
13210
|
report(node, "inlineColor", { value: node.value });
|
|
13051
13211
|
}
|
|
13052
13212
|
};
|
|
13053
13213
|
return {
|
|
13054
13214
|
"JSXAttribute[name.name='className']"(node) {
|
|
13055
13215
|
if (node.value === null) return;
|
|
13056
|
-
if (node.value.type ===
|
|
13057
|
-
else if (node.value.type ===
|
|
13058
|
-
if (node.value.expression.type !==
|
|
13216
|
+
if (node.value.type === AST_NODE_TYPES55.Literal) checkClassNode(node.value);
|
|
13217
|
+
else if (node.value.type === AST_NODE_TYPES55.JSXExpressionContainer) {
|
|
13218
|
+
if (node.value.expression.type !== AST_NODE_TYPES55.JSXEmptyExpression) {
|
|
13059
13219
|
checkClassNode(node.value.expression);
|
|
13060
13220
|
}
|
|
13061
13221
|
}
|
|
13062
13222
|
},
|
|
13063
13223
|
CallExpression(node) {
|
|
13064
|
-
if (node.callee.type ===
|
|
13224
|
+
if (node.callee.type === AST_NODE_TYPES55.Identifier && node.callee.name === "require" && node.arguments[0]?.type === AST_NODE_TYPES55.Literal && typeof node.arguments[0].value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.arguments[0].value)) {
|
|
13065
13225
|
importsEmailOrPdfRenderer = true;
|
|
13066
13226
|
}
|
|
13067
|
-
if (node.callee.type ===
|
|
13227
|
+
if (node.callee.type === AST_NODE_TYPES55.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
13068
13228
|
for (const arg of node.arguments) {
|
|
13069
|
-
if (arg.type !==
|
|
13229
|
+
if (arg.type !== AST_NODE_TYPES55.SpreadElement) checkClassNode(arg);
|
|
13070
13230
|
}
|
|
13071
13231
|
}
|
|
13072
13232
|
},
|
|
13073
13233
|
VariableDeclarator(node) {
|
|
13074
|
-
if (node.id.type ===
|
|
13234
|
+
if (node.id.type === AST_NODE_TYPES55.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
13075
13235
|
checkClassNode(node.init);
|
|
13076
13236
|
}
|
|
13077
13237
|
},
|
|
@@ -13081,9 +13241,9 @@ var prefer_semantic_colors_default = createRule({
|
|
|
13081
13241
|
},
|
|
13082
13242
|
// SVG artwork colors are exempt; component presentation colors still report.
|
|
13083
13243
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
13084
|
-
if (node.value?.type !==
|
|
13244
|
+
if (node.value?.type !== AST_NODE_TYPES55.Literal) return;
|
|
13085
13245
|
const owner = node.parent.name;
|
|
13086
|
-
if (owner.type ===
|
|
13246
|
+
if (owner.type === AST_NODE_TYPES55.JSXIdentifier && SVG_SHAPE_PRIMITIVES.has(owner.name)) {
|
|
13087
13247
|
return;
|
|
13088
13248
|
}
|
|
13089
13249
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
@@ -13097,7 +13257,7 @@ var prefer_semantic_colors_default = createRule({
|
|
|
13097
13257
|
if (name !== null && STYLE_COLOR_PROPS.has(name)) checkColorValueNode(node.value);
|
|
13098
13258
|
},
|
|
13099
13259
|
ImportExpression(node) {
|
|
13100
|
-
if (node.source.type ===
|
|
13260
|
+
if (node.source.type === AST_NODE_TYPES55.Literal && typeof node.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.source.value)) {
|
|
13101
13261
|
importsEmailOrPdfRenderer = true;
|
|
13102
13262
|
}
|
|
13103
13263
|
},
|
|
@@ -13299,7 +13459,7 @@ var prefer_server_actions_default = createRule({
|
|
|
13299
13459
|
});
|
|
13300
13460
|
|
|
13301
13461
|
// src/rules/prefer-whole-object-assertion.ts
|
|
13302
|
-
import { AST_NODE_TYPES as
|
|
13462
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES56 } from "@typescript-eslint/utils";
|
|
13303
13463
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
13304
13464
|
var SYNTHETIC_LITERAL_MATCHERS = /* @__PURE__ */ new Map([
|
|
13305
13465
|
["toBeNull", "null"],
|
|
@@ -13324,11 +13484,11 @@ var PREFER_WHOLE_OBJECT_ASSERTION_DOCUMENTATION = {
|
|
|
13324
13484
|
};
|
|
13325
13485
|
function literalText(node, getText) {
|
|
13326
13486
|
switch (node.type) {
|
|
13327
|
-
case
|
|
13487
|
+
case AST_NODE_TYPES56.Literal:
|
|
13328
13488
|
return "regex" in node ? null : getText(node);
|
|
13329
|
-
case
|
|
13489
|
+
case AST_NODE_TYPES56.TemplateLiteral:
|
|
13330
13490
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
13331
|
-
case
|
|
13491
|
+
case AST_NODE_TYPES56.UnaryExpression:
|
|
13332
13492
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
13333
13493
|
default:
|
|
13334
13494
|
return null;
|
|
@@ -13336,15 +13496,15 @@ function literalText(node, getText) {
|
|
|
13336
13496
|
}
|
|
13337
13497
|
function isPureReceiver(node) {
|
|
13338
13498
|
switch (node.type) {
|
|
13339
|
-
case
|
|
13340
|
-
case
|
|
13499
|
+
case AST_NODE_TYPES56.Identifier:
|
|
13500
|
+
case AST_NODE_TYPES56.ThisExpression:
|
|
13341
13501
|
return true;
|
|
13342
|
-
case
|
|
13502
|
+
case AST_NODE_TYPES56.MemberExpression:
|
|
13343
13503
|
if (node.optional) {
|
|
13344
13504
|
return false;
|
|
13345
13505
|
}
|
|
13346
13506
|
if (node.computed) {
|
|
13347
|
-
return node.property.type ===
|
|
13507
|
+
return node.property.type === AST_NODE_TYPES56.Literal && isPureReceiver(node.object);
|
|
13348
13508
|
}
|
|
13349
13509
|
return isPureReceiver(node.object);
|
|
13350
13510
|
default:
|
|
@@ -13352,7 +13512,7 @@ function isPureReceiver(node) {
|
|
|
13352
13512
|
}
|
|
13353
13513
|
}
|
|
13354
13514
|
function literalIndex(node) {
|
|
13355
|
-
if (node.type !==
|
|
13515
|
+
if (node.type !== AST_NODE_TYPES56.Literal || typeof node.value !== "number") {
|
|
13356
13516
|
return null;
|
|
13357
13517
|
}
|
|
13358
13518
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
@@ -13360,8 +13520,8 @@ function literalIndex(node) {
|
|
|
13360
13520
|
function propertyAccess(node) {
|
|
13361
13521
|
const path = [];
|
|
13362
13522
|
let current = node;
|
|
13363
|
-
while (current.type ===
|
|
13364
|
-
if (current.property.type !==
|
|
13523
|
+
while (current.type === AST_NODE_TYPES56.MemberExpression && !current.computed && !current.optional) {
|
|
13524
|
+
if (current.property.type !== AST_NODE_TYPES56.Identifier || COLLECTION_PROPERTIES.has(current.property.name) || LITERAL_KEY_HAZARDS.has(current.property.name)) return null;
|
|
13365
13525
|
path.unshift(current.property.name);
|
|
13366
13526
|
current = current.object;
|
|
13367
13527
|
}
|
|
@@ -13389,24 +13549,24 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
13389
13549
|
}
|
|
13390
13550
|
const { sourceCode } = context;
|
|
13391
13551
|
function parseAssertion(statement) {
|
|
13392
|
-
if (statement.type !==
|
|
13552
|
+
if (statement.type !== AST_NODE_TYPES56.ExpressionStatement) {
|
|
13393
13553
|
return null;
|
|
13394
13554
|
}
|
|
13395
13555
|
const call = statement.expression;
|
|
13396
|
-
if (call.type !==
|
|
13556
|
+
if (call.type !== AST_NODE_TYPES56.CallExpression) {
|
|
13397
13557
|
return null;
|
|
13398
13558
|
}
|
|
13399
13559
|
const callee = call.callee;
|
|
13400
|
-
if (callee.type !==
|
|
13560
|
+
if (callee.type !== AST_NODE_TYPES56.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES56.Identifier) {
|
|
13401
13561
|
return null;
|
|
13402
13562
|
}
|
|
13403
13563
|
const matcher = callee.property.name;
|
|
13404
13564
|
const expectCall = callee.object;
|
|
13405
|
-
if (expectCall.type !==
|
|
13565
|
+
if (expectCall.type !== AST_NODE_TYPES56.CallExpression || expectCall.callee.type !== AST_NODE_TYPES56.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
13406
13566
|
return null;
|
|
13407
13567
|
}
|
|
13408
13568
|
const actual = expectCall.arguments[0];
|
|
13409
|
-
if (actual === void 0 || actual.type !==
|
|
13569
|
+
if (actual === void 0 || actual.type !== AST_NODE_TYPES56.MemberExpression || actual.optional) {
|
|
13410
13570
|
return null;
|
|
13411
13571
|
}
|
|
13412
13572
|
if (!isPureReceiver(actual.object)) {
|
|
@@ -13435,7 +13595,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
13435
13595
|
return null;
|
|
13436
13596
|
}
|
|
13437
13597
|
const expected = call.arguments[0];
|
|
13438
|
-
if (call.arguments.length !== 1 || expected === void 0 || expected.type ===
|
|
13598
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === AST_NODE_TYPES56.SpreadElement) {
|
|
13439
13599
|
return null;
|
|
13440
13600
|
}
|
|
13441
13601
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
@@ -13576,7 +13736,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
13576
13736
|
});
|
|
13577
13737
|
|
|
13578
13738
|
// src/rules/repeated-static-call-cases.ts
|
|
13579
|
-
import { AST_NODE_TYPES as
|
|
13739
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES57, ASTUtils as ASTUtils18 } from "@typescript-eslint/utils";
|
|
13580
13740
|
var REPEATED_STATIC_CALL_CASES_DOCUMENTATION = {
|
|
13581
13741
|
summary: "Report three or more consecutive literal call assertions that should be independently named test cases.",
|
|
13582
13742
|
rationale: "Copy-pasted cases obscure the input table and stop later cases from being reported after the first failure.",
|
|
@@ -13597,67 +13757,67 @@ var EXPECT_MODIFIERS = /* @__PURE__ */ new Set(["not", "rejects", "resolves"]);
|
|
|
13597
13757
|
var SNAPSHOT_MATCHERS = /snapshot/iu;
|
|
13598
13758
|
var MIN_CASES2 = 3;
|
|
13599
13759
|
function staticMemberName5(node) {
|
|
13600
|
-
if (!node.computed && node.property.type ===
|
|
13601
|
-
if (node.computed && node.property.type ===
|
|
13760
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES57.Identifier) return node.property.name;
|
|
13761
|
+
if (node.computed && node.property.type === AST_NODE_TYPES57.Literal && typeof node.property.value === "string") return node.property.value;
|
|
13602
13762
|
return null;
|
|
13603
13763
|
}
|
|
13604
13764
|
function importedName5(identifier, context, modules) {
|
|
13605
|
-
const variable =
|
|
13765
|
+
const variable = ASTUtils18.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
13606
13766
|
if (variable === null || variable.defs.length === 0) return identifier.name;
|
|
13607
13767
|
for (const definition of variable.defs) {
|
|
13608
|
-
if (definition.node.type !==
|
|
13768
|
+
if (definition.node.type !== AST_NODE_TYPES57.ImportSpecifier) continue;
|
|
13609
13769
|
const declaration = definition.node.parent;
|
|
13610
|
-
if (declaration.type !==
|
|
13770
|
+
if (declaration.type !== AST_NODE_TYPES57.ImportDeclaration || typeof declaration.source.value !== "string" || !modules.has(declaration.source.value)) continue;
|
|
13611
13771
|
const imported = definition.node.imported;
|
|
13612
|
-
return imported.type ===
|
|
13772
|
+
return imported.type === AST_NODE_TYPES57.Identifier ? imported.name : String(imported.value);
|
|
13613
13773
|
}
|
|
13614
13774
|
return null;
|
|
13615
13775
|
}
|
|
13616
13776
|
function isDirectTestCallback2(node, context) {
|
|
13617
|
-
if (node.type !==
|
|
13777
|
+
if (node.type !== AST_NODE_TYPES57.ArrowFunctionExpression && node.type !== AST_NODE_TYPES57.FunctionExpression) return false;
|
|
13618
13778
|
const call = node.parent;
|
|
13619
|
-
if (call?.type !==
|
|
13779
|
+
if (call?.type !== AST_NODE_TYPES57.CallExpression || !call.arguments.includes(node)) return false;
|
|
13620
13780
|
const root = testRoot2(call.callee);
|
|
13621
13781
|
return root !== null && TEST_NAMES2.has(importedName5(root, context, TEST_MODULES4) ?? "");
|
|
13622
13782
|
}
|
|
13623
13783
|
function testRoot2(callee) {
|
|
13624
|
-
if (callee.type ===
|
|
13625
|
-
if (callee.type !==
|
|
13784
|
+
if (callee.type === AST_NODE_TYPES57.Identifier) return callee;
|
|
13785
|
+
if (callee.type !== AST_NODE_TYPES57.MemberExpression) return null;
|
|
13626
13786
|
const modifier = staticMemberName5(callee);
|
|
13627
13787
|
return modifier !== null && TEST_MODIFIERS4.has(modifier) ? testRoot2(callee.object) : null;
|
|
13628
13788
|
}
|
|
13629
13789
|
function isStatic(node) {
|
|
13630
|
-
if (node.type ===
|
|
13790
|
+
if (node.type === AST_NODE_TYPES57.TSAsExpression || node.type === AST_NODE_TYPES57.TSTypeAssertion || node.type === AST_NODE_TYPES57.TSSatisfiesExpression || node.type === AST_NODE_TYPES57.TSNonNullExpression) return isStatic(node.expression);
|
|
13631
13791
|
switch (node.type) {
|
|
13632
|
-
case
|
|
13792
|
+
case AST_NODE_TYPES57.Literal:
|
|
13633
13793
|
return true;
|
|
13634
|
-
case
|
|
13794
|
+
case AST_NODE_TYPES57.TemplateLiteral:
|
|
13635
13795
|
return node.expressions.length === 0;
|
|
13636
|
-
case
|
|
13796
|
+
case AST_NODE_TYPES57.UnaryExpression:
|
|
13637
13797
|
return (node.operator === "+" || node.operator === "-") && isStatic(node.argument);
|
|
13638
|
-
case
|
|
13639
|
-
return node.elements.every((item) => item !== null && item.type !==
|
|
13640
|
-
case
|
|
13641
|
-
return node.properties.every((property) => property.type ===
|
|
13798
|
+
case AST_NODE_TYPES57.ArrayExpression:
|
|
13799
|
+
return node.elements.every((item) => item !== null && item.type !== AST_NODE_TYPES57.SpreadElement && isStatic(item));
|
|
13800
|
+
case AST_NODE_TYPES57.ObjectExpression:
|
|
13801
|
+
return node.properties.every((property) => property.type === AST_NODE_TYPES57.Property && !property.computed && property.kind === "init" && property.value.type !== AST_NODE_TYPES57.AssignmentPattern && isStatic(property.value));
|
|
13642
13802
|
default:
|
|
13643
13803
|
return false;
|
|
13644
13804
|
}
|
|
13645
13805
|
}
|
|
13646
13806
|
function staticShape(node) {
|
|
13647
|
-
if (node.type ===
|
|
13807
|
+
if (node.type === AST_NODE_TYPES57.TSAsExpression || node.type === AST_NODE_TYPES57.TSTypeAssertion || node.type === AST_NODE_TYPES57.TSSatisfiesExpression || node.type === AST_NODE_TYPES57.TSNonNullExpression) return staticShape(node.expression);
|
|
13648
13808
|
switch (node.type) {
|
|
13649
|
-
case
|
|
13809
|
+
case AST_NODE_TYPES57.Literal:
|
|
13650
13810
|
return `literal:${typeof node.value}`;
|
|
13651
|
-
case
|
|
13811
|
+
case AST_NODE_TYPES57.TemplateLiteral:
|
|
13652
13812
|
return "template";
|
|
13653
|
-
case
|
|
13813
|
+
case AST_NODE_TYPES57.UnaryExpression:
|
|
13654
13814
|
return `unary:${node.operator}:${staticShape(node.argument)}`;
|
|
13655
|
-
case
|
|
13656
|
-
return `array(${node.elements.map((item) => item === null || item.type ===
|
|
13657
|
-
case
|
|
13815
|
+
case AST_NODE_TYPES57.ArrayExpression:
|
|
13816
|
+
return `array(${node.elements.map((item) => item === null || item.type === AST_NODE_TYPES57.SpreadElement ? "invalid" : staticShape(item)).join(",")})`;
|
|
13817
|
+
case AST_NODE_TYPES57.ObjectExpression:
|
|
13658
13818
|
return `object(${node.properties.map((property) => {
|
|
13659
|
-
if (property.type !==
|
|
13660
|
-
const key = property.key.type ===
|
|
13819
|
+
if (property.type !== AST_NODE_TYPES57.Property || property.computed || property.value.type === AST_NODE_TYPES57.AssignmentPattern) return "invalid";
|
|
13820
|
+
const key = property.key.type === AST_NODE_TYPES57.Identifier ? property.key.name : String(property.key.value);
|
|
13661
13821
|
return `${key}:${staticShape(property.value)}`;
|
|
13662
13822
|
}).join(",")})`;
|
|
13663
13823
|
default:
|
|
@@ -13665,16 +13825,16 @@ function staticShape(node) {
|
|
|
13665
13825
|
}
|
|
13666
13826
|
}
|
|
13667
13827
|
function assertionShape(statement, context) {
|
|
13668
|
-
if (statement.type !==
|
|
13828
|
+
if (statement.type !== AST_NODE_TYPES57.ExpressionStatement || statement.expression.type !== AST_NODE_TYPES57.CallExpression) return null;
|
|
13669
13829
|
const matcherCall = statement.expression;
|
|
13670
|
-
if (matcherCall.callee.type !==
|
|
13830
|
+
if (matcherCall.callee.type !== AST_NODE_TYPES57.MemberExpression || matcherCall.callee.computed || matcherCall.callee.property.type !== AST_NODE_TYPES57.Identifier || matcherCall.arguments.length !== 1) return null;
|
|
13671
13831
|
const matcher = matcherCall.callee.property.name;
|
|
13672
13832
|
if (SNAPSHOT_MATCHERS.test(matcher)) return null;
|
|
13673
13833
|
const chain = expectCallFromMatcher(matcherCall.callee);
|
|
13674
|
-
if (chain === null || chain.call.callee.type !==
|
|
13834
|
+
if (chain === null || chain.call.callee.type !== AST_NODE_TYPES57.Identifier || importedName5(chain.call.callee, context, ASSERTION_MODULES3) !== "expect" || chain.call.arguments.length !== 1) return null;
|
|
13675
13835
|
const observed = chain.call.arguments[0];
|
|
13676
13836
|
const expected = matcherCall.arguments[0];
|
|
13677
|
-
if (observed?.type !==
|
|
13837
|
+
if (observed?.type !== AST_NODE_TYPES57.CallExpression || observed.callee.type !== AST_NODE_TYPES57.Identifier || observed.arguments.length === 0 || observed.arguments.some((arg) => arg.type === AST_NODE_TYPES57.SpreadElement || !isStatic(arg)) || expected?.type === AST_NODE_TYPES57.SpreadElement || expected === void 0 || !isStatic(expected)) return null;
|
|
13678
13838
|
const skeleton = `${observed.callee.name}/${observed.arguments.map((item) => staticShape(item)).join(",")}/${chain.modifiers.join(".")}/${matcher}/${staticShape(expected)}`;
|
|
13679
13839
|
const values = [...observed.arguments, expected].map((item) => context.sourceCode.getText(item)).join("\0");
|
|
13680
13840
|
return { statement, skeleton, values };
|
|
@@ -13682,13 +13842,13 @@ function assertionShape(statement, context) {
|
|
|
13682
13842
|
function expectCallFromMatcher(node) {
|
|
13683
13843
|
const modifiers = [];
|
|
13684
13844
|
let receiver = node.object;
|
|
13685
|
-
while (receiver.type ===
|
|
13845
|
+
while (receiver.type === AST_NODE_TYPES57.MemberExpression) {
|
|
13686
13846
|
const modifier = staticMemberName5(receiver);
|
|
13687
13847
|
if (modifier === null || !EXPECT_MODIFIERS.has(modifier)) return null;
|
|
13688
13848
|
modifiers.unshift(modifier);
|
|
13689
13849
|
receiver = receiver.object;
|
|
13690
13850
|
}
|
|
13691
|
-
return receiver.type ===
|
|
13851
|
+
return receiver.type === AST_NODE_TYPES57.CallExpression ? { call: receiver, modifiers } : null;
|
|
13692
13852
|
}
|
|
13693
13853
|
var repeated_static_call_cases_default = createRule({
|
|
13694
13854
|
name: "repeated-static-call-cases",
|
|
@@ -13708,7 +13868,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
13708
13868
|
return {
|
|
13709
13869
|
"CallExpression > ArrowFunctionExpression, CallExpression > FunctionExpression"(node) {
|
|
13710
13870
|
const call = node.parent;
|
|
13711
|
-
if (call?.type ===
|
|
13871
|
+
if (call?.type === AST_NODE_TYPES57.CallExpression) {
|
|
13712
13872
|
const duplicate = duplicateTestBodyCandidate(call, sourceCode);
|
|
13713
13873
|
if (duplicate !== null && duplicate.body === node) {
|
|
13714
13874
|
const groups = duplicateGroups.get(duplicate.container) ?? /* @__PURE__ */ new Map();
|
|
@@ -13718,7 +13878,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
13718
13878
|
duplicateGroups.set(duplicate.container, groups);
|
|
13719
13879
|
}
|
|
13720
13880
|
}
|
|
13721
|
-
if (!isDirectTestCallback2(node, context) || node.body.type !==
|
|
13881
|
+
if (!isDirectTestCallback2(node, context) || node.body.type !== AST_NODE_TYPES57.BlockStatement) return;
|
|
13722
13882
|
let run = [];
|
|
13723
13883
|
const flush = () => {
|
|
13724
13884
|
if (run.length >= MIN_CASES2 && new Set(run.map((item) => item.values)).size > 1) {
|
|
@@ -13759,7 +13919,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
13759
13919
|
});
|
|
13760
13920
|
|
|
13761
13921
|
// src/rules/prefer-zod-infer.ts
|
|
13762
|
-
import { AST_NODE_TYPES as
|
|
13922
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES58 } from "@typescript-eslint/utils";
|
|
13763
13923
|
var PREFER_ZOD_INFER_DOCUMENTATION = {
|
|
13764
13924
|
summary: "Derive a type from its Zod schema with `z.infer` instead of hand-writing a twin declaration beside it.",
|
|
13765
13925
|
rationale: "A derived type stays synchronized when the runtime schema changes.",
|
|
@@ -13812,47 +13972,47 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
13812
13972
|
"Schema"
|
|
13813
13973
|
]);
|
|
13814
13974
|
var LEAF_NODE_TYPES = {
|
|
13815
|
-
string: [
|
|
13816
|
-
email: [
|
|
13817
|
-
url: [
|
|
13818
|
-
uuid: [
|
|
13819
|
-
ulid: [
|
|
13820
|
-
cuid: [
|
|
13821
|
-
cuid2: [
|
|
13822
|
-
nanoid: [
|
|
13823
|
-
iso: [
|
|
13824
|
-
number: [
|
|
13825
|
-
int: [
|
|
13826
|
-
float32: [
|
|
13827
|
-
float64: [
|
|
13828
|
-
boolean: [
|
|
13829
|
-
bigint: [
|
|
13830
|
-
symbol: [
|
|
13831
|
-
any: [
|
|
13832
|
-
unknown: [
|
|
13833
|
-
never: [
|
|
13834
|
-
void: [
|
|
13835
|
-
null: [
|
|
13836
|
-
undefined: [
|
|
13837
|
-
literal: [
|
|
13838
|
-
date: [
|
|
13839
|
-
array: [
|
|
13840
|
-
tuple: [
|
|
13841
|
-
object: [
|
|
13842
|
-
strictObject: [
|
|
13843
|
-
looseObject: [
|
|
13844
|
-
record: [
|
|
13845
|
-
map: [
|
|
13846
|
-
set: [
|
|
13847
|
-
promise: [
|
|
13848
|
-
enum: [
|
|
13849
|
-
nativeEnum: [
|
|
13850
|
-
union: [
|
|
13851
|
-
discriminatedUnion: [
|
|
13852
|
-
intersection: [
|
|
13975
|
+
string: [AST_NODE_TYPES58.TSStringKeyword],
|
|
13976
|
+
email: [AST_NODE_TYPES58.TSStringKeyword],
|
|
13977
|
+
url: [AST_NODE_TYPES58.TSStringKeyword],
|
|
13978
|
+
uuid: [AST_NODE_TYPES58.TSStringKeyword],
|
|
13979
|
+
ulid: [AST_NODE_TYPES58.TSStringKeyword],
|
|
13980
|
+
cuid: [AST_NODE_TYPES58.TSStringKeyword],
|
|
13981
|
+
cuid2: [AST_NODE_TYPES58.TSStringKeyword],
|
|
13982
|
+
nanoid: [AST_NODE_TYPES58.TSStringKeyword],
|
|
13983
|
+
iso: [AST_NODE_TYPES58.TSStringKeyword],
|
|
13984
|
+
number: [AST_NODE_TYPES58.TSNumberKeyword],
|
|
13985
|
+
int: [AST_NODE_TYPES58.TSNumberKeyword],
|
|
13986
|
+
float32: [AST_NODE_TYPES58.TSNumberKeyword],
|
|
13987
|
+
float64: [AST_NODE_TYPES58.TSNumberKeyword],
|
|
13988
|
+
boolean: [AST_NODE_TYPES58.TSBooleanKeyword],
|
|
13989
|
+
bigint: [AST_NODE_TYPES58.TSBigIntKeyword],
|
|
13990
|
+
symbol: [AST_NODE_TYPES58.TSSymbolKeyword],
|
|
13991
|
+
any: [AST_NODE_TYPES58.TSAnyKeyword],
|
|
13992
|
+
unknown: [AST_NODE_TYPES58.TSUnknownKeyword],
|
|
13993
|
+
never: [AST_NODE_TYPES58.TSNeverKeyword],
|
|
13994
|
+
void: [AST_NODE_TYPES58.TSVoidKeyword],
|
|
13995
|
+
null: [AST_NODE_TYPES58.TSNullKeyword],
|
|
13996
|
+
undefined: [AST_NODE_TYPES58.TSUndefinedKeyword],
|
|
13997
|
+
literal: [AST_NODE_TYPES58.TSLiteralType],
|
|
13998
|
+
date: [AST_NODE_TYPES58.TSTypeReference],
|
|
13999
|
+
array: [AST_NODE_TYPES58.TSArrayType, AST_NODE_TYPES58.TSTypeReference],
|
|
14000
|
+
tuple: [AST_NODE_TYPES58.TSTupleType],
|
|
14001
|
+
object: [AST_NODE_TYPES58.TSTypeLiteral, AST_NODE_TYPES58.TSTypeReference],
|
|
14002
|
+
strictObject: [AST_NODE_TYPES58.TSTypeLiteral, AST_NODE_TYPES58.TSTypeReference],
|
|
14003
|
+
looseObject: [AST_NODE_TYPES58.TSTypeLiteral, AST_NODE_TYPES58.TSTypeReference],
|
|
14004
|
+
record: [AST_NODE_TYPES58.TSTypeReference, AST_NODE_TYPES58.TSTypeLiteral],
|
|
14005
|
+
map: [AST_NODE_TYPES58.TSTypeReference],
|
|
14006
|
+
set: [AST_NODE_TYPES58.TSTypeReference],
|
|
14007
|
+
promise: [AST_NODE_TYPES58.TSTypeReference],
|
|
14008
|
+
enum: [AST_NODE_TYPES58.TSUnionType, AST_NODE_TYPES58.TSTypeReference, AST_NODE_TYPES58.TSLiteralType],
|
|
14009
|
+
nativeEnum: [AST_NODE_TYPES58.TSUnionType, AST_NODE_TYPES58.TSTypeReference, AST_NODE_TYPES58.TSLiteralType],
|
|
14010
|
+
union: [AST_NODE_TYPES58.TSUnionType, AST_NODE_TYPES58.TSTypeReference],
|
|
14011
|
+
discriminatedUnion: [AST_NODE_TYPES58.TSUnionType, AST_NODE_TYPES58.TSTypeReference],
|
|
14012
|
+
intersection: [AST_NODE_TYPES58.TSIntersectionType, AST_NODE_TYPES58.TSTypeReference]
|
|
13853
14013
|
};
|
|
13854
14014
|
function primitiveLiteralKey(node) {
|
|
13855
|
-
if (node.type !==
|
|
14015
|
+
if (node.type !== AST_NODE_TYPES58.Literal) {
|
|
13856
14016
|
return null;
|
|
13857
14017
|
}
|
|
13858
14018
|
if (node.value === null) {
|
|
@@ -13884,13 +14044,13 @@ function staticZodDomain(leaf, call) {
|
|
|
13884
14044
|
}
|
|
13885
14045
|
if (leaf === "literal") {
|
|
13886
14046
|
const [argument] = call.arguments;
|
|
13887
|
-
if (argument === void 0 || argument.type ===
|
|
14047
|
+
if (argument === void 0 || argument.type === AST_NODE_TYPES58.SpreadElement) {
|
|
13888
14048
|
return null;
|
|
13889
14049
|
}
|
|
13890
|
-
if (argument.type ===
|
|
14050
|
+
if (argument.type === AST_NODE_TYPES58.ArrayExpression) {
|
|
13891
14051
|
return exactDomain(
|
|
13892
14052
|
argument.elements.map(
|
|
13893
|
-
(element) => element === null || element.type ===
|
|
14053
|
+
(element) => element === null || element.type === AST_NODE_TYPES58.SpreadElement ? null : primitiveLiteralKey(element)
|
|
13894
14054
|
)
|
|
13895
14055
|
);
|
|
13896
14056
|
}
|
|
@@ -13898,13 +14058,13 @@ function staticZodDomain(leaf, call) {
|
|
|
13898
14058
|
}
|
|
13899
14059
|
if (leaf === "enum") {
|
|
13900
14060
|
const [argument] = call.arguments;
|
|
13901
|
-
if (argument === void 0 || argument.type ===
|
|
14061
|
+
if (argument === void 0 || argument.type === AST_NODE_TYPES58.SpreadElement) {
|
|
13902
14062
|
return null;
|
|
13903
14063
|
}
|
|
13904
|
-
if (argument.type ===
|
|
14064
|
+
if (argument.type === AST_NODE_TYPES58.ArrayExpression) {
|
|
13905
14065
|
return exactDomain(
|
|
13906
14066
|
argument.elements.map((element) => {
|
|
13907
|
-
if (element === null || element.type ===
|
|
14067
|
+
if (element === null || element.type === AST_NODE_TYPES58.SpreadElement) {
|
|
13908
14068
|
return null;
|
|
13909
14069
|
}
|
|
13910
14070
|
const key = primitiveLiteralKey(element);
|
|
@@ -13912,10 +14072,10 @@ function staticZodDomain(leaf, call) {
|
|
|
13912
14072
|
})
|
|
13913
14073
|
);
|
|
13914
14074
|
}
|
|
13915
|
-
if (argument.type ===
|
|
14075
|
+
if (argument.type === AST_NODE_TYPES58.ObjectExpression) {
|
|
13916
14076
|
return exactDomain(
|
|
13917
14077
|
argument.properties.map((property) => {
|
|
13918
|
-
if (property.type !==
|
|
14078
|
+
if (property.type !== AST_NODE_TYPES58.Property || property.computed || property.kind !== "init" || property.method || property.shorthand) {
|
|
13919
14079
|
return null;
|
|
13920
14080
|
}
|
|
13921
14081
|
const key = primitiveLiteralKey(property.value);
|
|
@@ -13942,15 +14102,15 @@ function sameDomain(left, right) {
|
|
|
13942
14102
|
return true;
|
|
13943
14103
|
}
|
|
13944
14104
|
function isExportedDeclaration(node) {
|
|
13945
|
-
return node.parent?.type ===
|
|
14105
|
+
return node.parent?.type === AST_NODE_TYPES58.ExportNamedDeclaration;
|
|
13946
14106
|
}
|
|
13947
14107
|
function isModuleLevelConst(node) {
|
|
13948
14108
|
const declaration = node.parent;
|
|
13949
|
-
if (declaration.type !==
|
|
14109
|
+
if (declaration.type !== AST_NODE_TYPES58.VariableDeclaration || declaration.kind !== "const") {
|
|
13950
14110
|
return false;
|
|
13951
14111
|
}
|
|
13952
14112
|
const container = declaration.parent;
|
|
13953
|
-
return container.type ===
|
|
14113
|
+
return container.type === AST_NODE_TYPES58.Program || container.type === AST_NODE_TYPES58.ExportNamedDeclaration && container.parent.type === AST_NODE_TYPES58.Program;
|
|
13954
14114
|
}
|
|
13955
14115
|
function normalizeSchemaName(name) {
|
|
13956
14116
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -13959,20 +14119,20 @@ function normalizeTypeName(name) {
|
|
|
13959
14119
|
return name.replace(/Type$/, "").toLowerCase();
|
|
13960
14120
|
}
|
|
13961
14121
|
function unwrapNullish(annotation) {
|
|
13962
|
-
if (annotation.type !==
|
|
14122
|
+
if (annotation.type !== AST_NODE_TYPES58.TSUnionType) {
|
|
13963
14123
|
return {
|
|
13964
14124
|
core: annotation,
|
|
13965
|
-
nullable: annotation.type ===
|
|
14125
|
+
nullable: annotation.type === AST_NODE_TYPES58.TSNullKeyword
|
|
13966
14126
|
};
|
|
13967
14127
|
}
|
|
13968
14128
|
const rest = [];
|
|
13969
14129
|
let nullable = false;
|
|
13970
14130
|
for (const member of annotation.types) {
|
|
13971
|
-
if (member.type ===
|
|
14131
|
+
if (member.type === AST_NODE_TYPES58.TSNullKeyword) {
|
|
13972
14132
|
nullable = true;
|
|
13973
14133
|
continue;
|
|
13974
14134
|
}
|
|
13975
|
-
if (member.type ===
|
|
14135
|
+
if (member.type === AST_NODE_TYPES58.TSUndefinedKeyword) {
|
|
13976
14136
|
continue;
|
|
13977
14137
|
}
|
|
13978
14138
|
rest.push(member);
|
|
@@ -14006,18 +14166,18 @@ function leafAgrees(field, annotation) {
|
|
|
14006
14166
|
return null;
|
|
14007
14167
|
}
|
|
14008
14168
|
if (leaf === "date") {
|
|
14009
|
-
return core.type ===
|
|
14169
|
+
return core.type === AST_NODE_TYPES58.TSTypeReference && core.typeName.type === AST_NODE_TYPES58.Identifier && core.typeName.name === "Date";
|
|
14010
14170
|
}
|
|
14011
14171
|
return expected.includes(core.type);
|
|
14012
14172
|
}
|
|
14013
14173
|
function typeLiteralDomain(annotation) {
|
|
14014
|
-
const members = annotation.type ===
|
|
14174
|
+
const members = annotation.type === AST_NODE_TYPES58.TSUnionType ? annotation.types : [annotation];
|
|
14015
14175
|
const keys = [];
|
|
14016
14176
|
for (const member of members) {
|
|
14017
|
-
if (member.type ===
|
|
14177
|
+
if (member.type === AST_NODE_TYPES58.TSNullKeyword) {
|
|
14018
14178
|
continue;
|
|
14019
14179
|
}
|
|
14020
|
-
if (member.type !==
|
|
14180
|
+
if (member.type !== AST_NODE_TYPES58.TSLiteralType) {
|
|
14021
14181
|
return null;
|
|
14022
14182
|
}
|
|
14023
14183
|
keys.push(primitiveLiteralKey(member.literal));
|
|
@@ -14025,11 +14185,11 @@ function typeLiteralDomain(annotation) {
|
|
|
14025
14185
|
return exactDomain(keys);
|
|
14026
14186
|
}
|
|
14027
14187
|
function staticStringUnionDomain(node) {
|
|
14028
|
-
if (node.type !==
|
|
14188
|
+
if (node.type !== AST_NODE_TYPES58.TSUnionType) {
|
|
14029
14189
|
return null;
|
|
14030
14190
|
}
|
|
14031
14191
|
const keys = node.types.map((member) => {
|
|
14032
|
-
if (member.type !==
|
|
14192
|
+
if (member.type !== AST_NODE_TYPES58.TSLiteralType) {
|
|
14033
14193
|
return null;
|
|
14034
14194
|
}
|
|
14035
14195
|
const key = primitiveLiteralKey(member.literal);
|
|
@@ -14097,14 +14257,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
14097
14257
|
function zodCallChain(node) {
|
|
14098
14258
|
const chain = [];
|
|
14099
14259
|
let current = node;
|
|
14100
|
-
while (current.type ===
|
|
14260
|
+
while (current.type === AST_NODE_TYPES58.CallExpression) {
|
|
14101
14261
|
const callee = current.callee;
|
|
14102
|
-
if (callee.type !==
|
|
14262
|
+
if (callee.type !== AST_NODE_TYPES58.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES58.Identifier) {
|
|
14103
14263
|
return null;
|
|
14104
14264
|
}
|
|
14105
14265
|
chain.push(current);
|
|
14106
14266
|
const receiver = callee.object;
|
|
14107
|
-
if (receiver.type ===
|
|
14267
|
+
if (receiver.type === AST_NODE_TYPES58.Identifier) {
|
|
14108
14268
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
14109
14269
|
}
|
|
14110
14270
|
current = receiver;
|
|
@@ -14113,14 +14273,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
14113
14273
|
}
|
|
14114
14274
|
function methodName2(call) {
|
|
14115
14275
|
const callee = call.callee;
|
|
14116
|
-
return callee.type ===
|
|
14276
|
+
return callee.type === AST_NODE_TYPES58.MemberExpression && callee.property.type === AST_NODE_TYPES58.Identifier ? callee.property.name : "";
|
|
14117
14277
|
}
|
|
14118
14278
|
function recordZodImport(node) {
|
|
14119
14279
|
if (!isZodModule(node.source.value)) {
|
|
14120
14280
|
return;
|
|
14121
14281
|
}
|
|
14122
14282
|
for (const specifier of node.specifiers) {
|
|
14123
|
-
if (specifier.type ===
|
|
14283
|
+
if (specifier.type === AST_NODE_TYPES58.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES58.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES58.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES58.Identifier && specifier.imported.name === "z") {
|
|
14124
14284
|
zodNamespaces.add(specifier.local.name);
|
|
14125
14285
|
}
|
|
14126
14286
|
}
|
|
@@ -14130,13 +14290,13 @@ var prefer_zod_infer_default = createRule({
|
|
|
14130
14290
|
let current = node;
|
|
14131
14291
|
let leaf = null;
|
|
14132
14292
|
let leafCall = null;
|
|
14133
|
-
while (current.type ===
|
|
14293
|
+
while (current.type === AST_NODE_TYPES58.CallExpression) {
|
|
14134
14294
|
const callee = current.callee;
|
|
14135
|
-
if (callee.type !==
|
|
14295
|
+
if (callee.type !== AST_NODE_TYPES58.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES58.Identifier) {
|
|
14136
14296
|
break;
|
|
14137
14297
|
}
|
|
14138
14298
|
const receiver = callee.object;
|
|
14139
|
-
if (receiver.type ===
|
|
14299
|
+
if (receiver.type === AST_NODE_TYPES58.Identifier && zodNamespaces.has(receiver.name)) {
|
|
14140
14300
|
leaf = callee.property.name;
|
|
14141
14301
|
leafCall = current;
|
|
14142
14302
|
break;
|
|
@@ -14167,20 +14327,20 @@ var prefer_zod_infer_default = createRule({
|
|
|
14167
14327
|
return domain instanceof Set && domain.size >= 2 ? domain : null;
|
|
14168
14328
|
}
|
|
14169
14329
|
function inferredSchemaName(node) {
|
|
14170
|
-
if (node.type !==
|
|
14330
|
+
if (node.type !== AST_NODE_TYPES58.TSTypeReference || node.typeName.type !== AST_NODE_TYPES58.TSQualifiedName || node.typeName.left.type !== AST_NODE_TYPES58.Identifier || !zodNamespaces.has(node.typeName.left.name) || node.typeName.right.name !== "infer") {
|
|
14171
14331
|
return null;
|
|
14172
14332
|
}
|
|
14173
14333
|
const arguments_ = node.typeArguments?.params ?? [];
|
|
14174
14334
|
const [argument] = arguments_;
|
|
14175
|
-
return arguments_.length === 1 && argument?.type ===
|
|
14335
|
+
return arguments_.length === 1 && argument?.type === AST_NODE_TYPES58.TSTypeQuery && argument.exprName.type === AST_NODE_TYPES58.Identifier ? argument.exprName.name : null;
|
|
14176
14336
|
}
|
|
14177
14337
|
function recordLiteralUnions(members, owner, ownerName, exported) {
|
|
14178
14338
|
for (const member of members) {
|
|
14179
|
-
if (member.type !==
|
|
14339
|
+
if (member.type !== AST_NODE_TYPES58.TSPropertySignature || member.computed || member.optional || member.readonly || member.typeAnnotation === void 0) {
|
|
14180
14340
|
continue;
|
|
14181
14341
|
}
|
|
14182
14342
|
const key = member.key;
|
|
14183
|
-
const propertyName5 = key.type ===
|
|
14343
|
+
const propertyName5 = key.type === AST_NODE_TYPES58.Identifier ? key.name : key.type === AST_NODE_TYPES58.Literal && typeof key.value === "string" ? key.value : null;
|
|
14184
14344
|
if (propertyName5 === null) {
|
|
14185
14345
|
continue;
|
|
14186
14346
|
}
|
|
@@ -14190,7 +14350,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
14190
14350
|
}
|
|
14191
14351
|
const annotation = member.typeAnnotation.typeAnnotation;
|
|
14192
14352
|
const domain = staticStringUnionDomain(annotation);
|
|
14193
|
-
if (domain === null || annotation.type !==
|
|
14353
|
+
if (domain === null || annotation.type !== AST_NODE_TYPES58.TSUnionType) {
|
|
14194
14354
|
continue;
|
|
14195
14355
|
}
|
|
14196
14356
|
literalUnionOccurrences.push({
|
|
@@ -14221,16 +14381,16 @@ var prefer_zod_infer_default = createRule({
|
|
|
14221
14381
|
return null;
|
|
14222
14382
|
}
|
|
14223
14383
|
const shape = base.arguments[0];
|
|
14224
|
-
if (shape === void 0 || shape.type !==
|
|
14384
|
+
if (shape === void 0 || shape.type !== AST_NODE_TYPES58.ObjectExpression) {
|
|
14225
14385
|
return null;
|
|
14226
14386
|
}
|
|
14227
14387
|
const fields = /* @__PURE__ */ new Map();
|
|
14228
14388
|
for (const property of shape.properties) {
|
|
14229
|
-
if (property.type !==
|
|
14389
|
+
if (property.type !== AST_NODE_TYPES58.Property || property.computed) {
|
|
14230
14390
|
return null;
|
|
14231
14391
|
}
|
|
14232
14392
|
const { key } = property;
|
|
14233
|
-
const name = key.type ===
|
|
14393
|
+
const name = key.type === AST_NODE_TYPES58.Identifier ? key.name : key.type === AST_NODE_TYPES58.Literal && typeof key.value === "string" ? key.value : null;
|
|
14234
14394
|
if (name === null) {
|
|
14235
14395
|
return null;
|
|
14236
14396
|
}
|
|
@@ -14241,11 +14401,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
14241
14401
|
function typeMembers(members) {
|
|
14242
14402
|
const result = /* @__PURE__ */ new Map();
|
|
14243
14403
|
for (const member of members) {
|
|
14244
|
-
if (member.type !==
|
|
14404
|
+
if (member.type !== AST_NODE_TYPES58.TSPropertySignature || member.computed) {
|
|
14245
14405
|
return null;
|
|
14246
14406
|
}
|
|
14247
14407
|
const { key } = member;
|
|
14248
|
-
const name = key.type ===
|
|
14408
|
+
const name = key.type === AST_NODE_TYPES58.Identifier ? key.name : key.type === AST_NODE_TYPES58.Literal && typeof key.value === "string" ? key.value : null;
|
|
14249
14409
|
if (name === null) {
|
|
14250
14410
|
return null;
|
|
14251
14411
|
}
|
|
@@ -14260,8 +14420,8 @@ var prefer_zod_infer_default = createRule({
|
|
|
14260
14420
|
return result.size === 0 ? null : result;
|
|
14261
14421
|
}
|
|
14262
14422
|
function collectConstrainedNames(node) {
|
|
14263
|
-
if (node.type ===
|
|
14264
|
-
if (node.typeName.type ===
|
|
14423
|
+
if (node.type === AST_NODE_TYPES58.TSTypeReference) {
|
|
14424
|
+
if (node.typeName.type === AST_NODE_TYPES58.Identifier) {
|
|
14265
14425
|
constrainedTypeNames.add(node.typeName.name);
|
|
14266
14426
|
}
|
|
14267
14427
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -14269,11 +14429,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
14269
14429
|
}
|
|
14270
14430
|
return;
|
|
14271
14431
|
}
|
|
14272
|
-
if (node.type ===
|
|
14432
|
+
if (node.type === AST_NODE_TYPES58.TSArrayType) {
|
|
14273
14433
|
collectConstrainedNames(node.elementType);
|
|
14274
14434
|
return;
|
|
14275
14435
|
}
|
|
14276
|
-
if (node.type ===
|
|
14436
|
+
if (node.type === AST_NODE_TYPES58.TSUnionType || node.type === AST_NODE_TYPES58.TSIntersectionType) {
|
|
14277
14437
|
for (const member of node.types) {
|
|
14278
14438
|
collectConstrainedNames(member);
|
|
14279
14439
|
}
|
|
@@ -14317,7 +14477,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
14317
14477
|
return {
|
|
14318
14478
|
Program(node) {
|
|
14319
14479
|
for (const statement of node.body) {
|
|
14320
|
-
if (statement.type ===
|
|
14480
|
+
if (statement.type === AST_NODE_TYPES58.ImportDeclaration) {
|
|
14321
14481
|
recordZodImport(statement);
|
|
14322
14482
|
}
|
|
14323
14483
|
}
|
|
@@ -14326,7 +14486,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
14326
14486
|
recordZodImport(node);
|
|
14327
14487
|
},
|
|
14328
14488
|
VariableDeclarator(node) {
|
|
14329
|
-
if (node.id.type !==
|
|
14489
|
+
if (node.id.type !== AST_NODE_TYPES58.Identifier || node.init == null) {
|
|
14330
14490
|
return;
|
|
14331
14491
|
}
|
|
14332
14492
|
const fields = schemaFields(node.init);
|
|
@@ -14343,14 +14503,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
14343
14503
|
},
|
|
14344
14504
|
/** Records `XSchema.transform(...)` and equivalent module-level reshaping. */
|
|
14345
14505
|
"MemberExpression[computed=false]"(node) {
|
|
14346
|
-
if (node.object.type ===
|
|
14506
|
+
if (node.object.type === AST_NODE_TYPES58.Identifier && node.property.type === AST_NODE_TYPES58.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
14347
14507
|
reshapedSchemaNames.add(node.object.name);
|
|
14348
14508
|
}
|
|
14349
14509
|
},
|
|
14350
14510
|
/** Records every type argument carried by a Zod constraint. */
|
|
14351
14511
|
TSTypeReference(node) {
|
|
14352
14512
|
const { typeName } = node;
|
|
14353
|
-
const referenced = typeName.type ===
|
|
14513
|
+
const referenced = typeName.type === AST_NODE_TYPES58.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES58.TSQualifiedName && typeName.right.type === AST_NODE_TYPES58.Identifier ? typeName.right.name : null;
|
|
14354
14514
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
14355
14515
|
return;
|
|
14356
14516
|
}
|
|
@@ -14382,7 +14542,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
14382
14542
|
typeName: node.id.name
|
|
14383
14543
|
});
|
|
14384
14544
|
}
|
|
14385
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
14545
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== AST_NODE_TYPES58.TSTypeLiteral) {
|
|
14386
14546
|
return;
|
|
14387
14547
|
}
|
|
14388
14548
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -14482,10 +14642,10 @@ var prefer_zod_infer_default = createRule({
|
|
|
14482
14642
|
|
|
14483
14643
|
// src/rules/require-assert-never.ts
|
|
14484
14644
|
import {
|
|
14485
|
-
ESLintUtils as
|
|
14486
|
-
AST_NODE_TYPES as
|
|
14645
|
+
ESLintUtils as ESLintUtils7,
|
|
14646
|
+
AST_NODE_TYPES as AST_NODE_TYPES59
|
|
14487
14647
|
} from "@typescript-eslint/utils";
|
|
14488
|
-
import
|
|
14648
|
+
import ts5 from "typescript";
|
|
14489
14649
|
var REQUIRE_ASSERT_NEVER_DOCUMENTATION = {
|
|
14490
14650
|
summary: "Require an empty switch default to call `assertNever` so discriminated unions remain exhaustive at compile time.",
|
|
14491
14651
|
rationale: "An empty default silently accepts new union members instead of making the compiler identify the missing case.",
|
|
@@ -14497,14 +14657,14 @@ var REQUIRE_ASSERT_NEVER_DOCUMENTATION = {
|
|
|
14497
14657
|
]
|
|
14498
14658
|
};
|
|
14499
14659
|
var isRuntimeHandlingStatement = (statement) => {
|
|
14500
|
-
if (statement.type ===
|
|
14501
|
-
if (statement.type ===
|
|
14660
|
+
if (statement.type === AST_NODE_TYPES59.EmptyStatement) return false;
|
|
14661
|
+
if (statement.type === AST_NODE_TYPES59.BreakStatement) {
|
|
14502
14662
|
return statement.label !== null;
|
|
14503
14663
|
}
|
|
14504
|
-
if (statement.type ===
|
|
14664
|
+
if (statement.type === AST_NODE_TYPES59.TSTypeAliasDeclaration || statement.type === AST_NODE_TYPES59.TSInterfaceDeclaration) {
|
|
14505
14665
|
return false;
|
|
14506
14666
|
}
|
|
14507
|
-
if (statement.type ===
|
|
14667
|
+
if (statement.type === AST_NODE_TYPES59.BlockStatement) {
|
|
14508
14668
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
14509
14669
|
}
|
|
14510
14670
|
return true;
|
|
@@ -14520,7 +14680,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
14520
14680
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
14521
14681
|
}
|
|
14522
14682
|
const only = defaultCase.consequent[0];
|
|
14523
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
14683
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === AST_NODE_TYPES59.BlockStatement && !only.body.some(isRuntimeHandlingStatement)) {
|
|
14524
14684
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
14525
14685
|
}
|
|
14526
14686
|
return false;
|
|
@@ -14532,7 +14692,7 @@ function isExhaustiveFiniteSwitch(node, services) {
|
|
|
14532
14692
|
const constituents = discriminantType.isUnion() ? discriminantType.types : [discriminantType];
|
|
14533
14693
|
if (!discriminantType.isUnion() || constituents.length < 2) return false;
|
|
14534
14694
|
if (constituents.every(
|
|
14535
|
-
(constituent) => (constituent.flags &
|
|
14695
|
+
(constituent) => (constituent.flags & ts5.TypeFlags.BooleanLiteral) !== 0
|
|
14536
14696
|
)) {
|
|
14537
14697
|
return false;
|
|
14538
14698
|
}
|
|
@@ -14556,7 +14716,7 @@ function isExhaustiveFiniteSwitch(node, services) {
|
|
|
14556
14716
|
return [...expected].every((key) => handled.has(key));
|
|
14557
14717
|
}
|
|
14558
14718
|
function finiteTypeKey(type, checker) {
|
|
14559
|
-
const finiteFlags =
|
|
14719
|
+
const finiteFlags = ts5.TypeFlags.StringLiteral | ts5.TypeFlags.NumberLiteral | ts5.TypeFlags.BooleanLiteral | ts5.TypeFlags.EnumLiteral | ts5.TypeFlags.UniqueESSymbol | ts5.TypeFlags.Null | ts5.TypeFlags.Undefined;
|
|
14560
14720
|
return (type.flags & finiteFlags) !== 0 ? checker.typeToString(type) : null;
|
|
14561
14721
|
}
|
|
14562
14722
|
var require_assert_never_default = createRule({
|
|
@@ -14576,7 +14736,7 @@ var require_assert_never_default = createRule({
|
|
|
14576
14736
|
create(context) {
|
|
14577
14737
|
let services;
|
|
14578
14738
|
try {
|
|
14579
|
-
services =
|
|
14739
|
+
services = ESLintUtils7.getParserServices(context);
|
|
14580
14740
|
} catch {
|
|
14581
14741
|
services = null;
|
|
14582
14742
|
}
|
|
@@ -14603,7 +14763,7 @@ var require_assert_never_default = createRule({
|
|
|
14603
14763
|
});
|
|
14604
14764
|
|
|
14605
14765
|
// src/rules/require-fetch-timeout.ts
|
|
14606
|
-
import { AST_NODE_TYPES as
|
|
14766
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES60, ASTUtils as ASTUtils19 } from "@typescript-eslint/utils";
|
|
14607
14767
|
var REQUIRE_FETCH_TIMEOUT_DOCUMENTATION = {
|
|
14608
14768
|
summary: "Require an abort `signal` (e.g. `AbortSignal.timeout(ms)`) on global `fetch()` calls so stalled upstreams cannot hang the caller forever.",
|
|
14609
14769
|
rationale: "An unbounded request can occupy work indefinitely when an upstream stalls.",
|
|
@@ -14629,14 +14789,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
14629
14789
|
return false;
|
|
14630
14790
|
}
|
|
14631
14791
|
function initProvablyLacksSignal(init) {
|
|
14632
|
-
if (init.type !==
|
|
14792
|
+
if (init.type !== AST_NODE_TYPES60.ObjectExpression) {
|
|
14633
14793
|
return false;
|
|
14634
14794
|
}
|
|
14635
14795
|
for (const prop of init.properties) {
|
|
14636
|
-
if (prop.type ===
|
|
14796
|
+
if (prop.type === AST_NODE_TYPES60.SpreadElement) {
|
|
14637
14797
|
return false;
|
|
14638
14798
|
}
|
|
14639
|
-
if (prop.key.type ===
|
|
14799
|
+
if (prop.key.type === AST_NODE_TYPES60.Identifier && prop.key.name === "signal" || prop.key.type === AST_NODE_TYPES60.Literal && prop.key.value === "signal") {
|
|
14640
14800
|
return false;
|
|
14641
14801
|
}
|
|
14642
14802
|
if (prop.computed) {
|
|
@@ -14646,7 +14806,7 @@ function initProvablyLacksSignal(init) {
|
|
|
14646
14806
|
return true;
|
|
14647
14807
|
}
|
|
14648
14808
|
function isInlineUrl(node, resolvesToGlobal) {
|
|
14649
|
-
return node.type ===
|
|
14809
|
+
return node.type === AST_NODE_TYPES60.Literal && typeof node.value === "string" || node.type === AST_NODE_TYPES60.TemplateLiteral || node.type === AST_NODE_TYPES60.NewExpression && node.callee.type === AST_NODE_TYPES60.Identifier && node.callee.name === "URL" && resolvesToGlobal(node.callee);
|
|
14650
14810
|
}
|
|
14651
14811
|
var require_fetch_timeout_default = createRule({
|
|
14652
14812
|
name: "require-fetch-timeout",
|
|
@@ -14684,30 +14844,30 @@ var require_fetch_timeout_default = createRule({
|
|
|
14684
14844
|
}
|
|
14685
14845
|
function resolvesToGlobal(identifier) {
|
|
14686
14846
|
const scope = context.sourceCode.getScope(identifier);
|
|
14687
|
-
const variable =
|
|
14847
|
+
const variable = ASTUtils19.findVariable(scope, identifier.name);
|
|
14688
14848
|
return variable === null || variable.defs.length === 0;
|
|
14689
14849
|
}
|
|
14690
14850
|
function isGlobalFetchCall2(callee) {
|
|
14691
|
-
if (callee.type ===
|
|
14851
|
+
if (callee.type === AST_NODE_TYPES60.Identifier) {
|
|
14692
14852
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
14693
14853
|
}
|
|
14694
|
-
return callee.type ===
|
|
14854
|
+
return callee.type === AST_NODE_TYPES60.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES60.Identifier && callee.property.name === "fetch" && callee.object.type === AST_NODE_TYPES60.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
14695
14855
|
}
|
|
14696
14856
|
function localConstInitProvablyLacksSignal(identifier) {
|
|
14697
|
-
const variable =
|
|
14857
|
+
const variable = ASTUtils19.findVariable(
|
|
14698
14858
|
context.sourceCode.getScope(identifier),
|
|
14699
14859
|
identifier.name
|
|
14700
14860
|
);
|
|
14701
14861
|
if (variable?.defs.length !== 1) return false;
|
|
14702
14862
|
const definition = variable.defs[0];
|
|
14703
|
-
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !==
|
|
14863
|
+
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !== AST_NODE_TYPES60.ObjectExpression || !initProvablyLacksSignal(definition.node.init)) {
|
|
14704
14864
|
return false;
|
|
14705
14865
|
}
|
|
14706
14866
|
for (const reference of variable.references) {
|
|
14707
14867
|
const ref = reference.identifier;
|
|
14708
14868
|
if (ref === identifier || ref === definition.name) continue;
|
|
14709
14869
|
const member = ref.parent;
|
|
14710
|
-
if (member.type !==
|
|
14870
|
+
if (member.type !== AST_NODE_TYPES60.MemberExpression || member.object !== ref || member.computed || member.property.type !== AST_NODE_TYPES60.Identifier || member.property.name === "signal" || member.parent.type !== AST_NODE_TYPES60.AssignmentExpression || member.parent.left !== member) {
|
|
14711
14871
|
return false;
|
|
14712
14872
|
}
|
|
14713
14873
|
}
|
|
@@ -14722,7 +14882,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
14722
14882
|
if (node.arguments.length === 1 && first !== void 0 && !isInlineUrl(first, resolvesToGlobal)) {
|
|
14723
14883
|
return;
|
|
14724
14884
|
}
|
|
14725
|
-
if (init === void 0 || initProvablyLacksSignal(init) || init.type ===
|
|
14885
|
+
if (init === void 0 || initProvablyLacksSignal(init) || init.type === AST_NODE_TYPES60.Identifier && localConstInitProvablyLacksSignal(init)) {
|
|
14726
14886
|
context.report({ node, messageId: "missingSignal" });
|
|
14727
14887
|
}
|
|
14728
14888
|
}
|
|
@@ -14731,7 +14891,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
14731
14891
|
});
|
|
14732
14892
|
|
|
14733
14893
|
// src/rules/require-port-for-service.ts
|
|
14734
|
-
import { AST_NODE_TYPES as
|
|
14894
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES61 } from "@typescript-eslint/utils";
|
|
14735
14895
|
var REQUIRE_PORT_FOR_SERVICE_DOCUMENTATION = {
|
|
14736
14896
|
summary: "Advise when an exported service with injected collaborators has public methods not covered by its declared ports.",
|
|
14737
14897
|
rationale: "A declared port keeps consumers coupled to the service capability instead of its concrete implementation.",
|
|
@@ -14756,45 +14916,45 @@ var ROUTER_FACTORY_NAME = "Router";
|
|
|
14756
14916
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
14757
14917
|
var STORAGE_ASSIGNMENT_OPERATORS = /* @__PURE__ */ new Set(["=", "&&=", "??=", "||="]);
|
|
14758
14918
|
var staticMemberName6 = (member) => {
|
|
14759
|
-
if (member.property.type ===
|
|
14760
|
-
if (!member.computed && member.property.type ===
|
|
14761
|
-
return member.computed && member.property.type ===
|
|
14919
|
+
if (member.property.type === AST_NODE_TYPES61.PrivateIdentifier) return `#${member.property.name}`;
|
|
14920
|
+
if (!member.computed && member.property.type === AST_NODE_TYPES61.Identifier) return member.property.name;
|
|
14921
|
+
return member.computed && member.property.type === AST_NODE_TYPES61.Literal && typeof member.property.value === "string" ? member.property.value : null;
|
|
14762
14922
|
};
|
|
14763
14923
|
var detachedValueExports = (program) => {
|
|
14764
14924
|
const names = /* @__PURE__ */ new Set();
|
|
14765
14925
|
for (const statement of program.body) {
|
|
14766
|
-
if (statement.type ===
|
|
14926
|
+
if (statement.type === AST_NODE_TYPES61.ExportNamedDeclaration && statement.declaration === null && statement.source === null && statement.exportKind !== "type") {
|
|
14767
14927
|
for (const specifier of statement.specifiers) {
|
|
14768
14928
|
if (specifier.exportKind !== "type") names.add(specifier.local.name);
|
|
14769
14929
|
}
|
|
14770
|
-
} else if (statement.type ===
|
|
14930
|
+
} else if (statement.type === AST_NODE_TYPES61.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES61.Identifier) {
|
|
14771
14931
|
names.add(statement.declaration.name);
|
|
14772
|
-
} else if (statement.type ===
|
|
14932
|
+
} else if (statement.type === AST_NODE_TYPES61.TSExportAssignment && statement.expression.type === AST_NODE_TYPES61.Identifier) {
|
|
14773
14933
|
names.add(statement.expression.name);
|
|
14774
14934
|
}
|
|
14775
14935
|
}
|
|
14776
14936
|
return names;
|
|
14777
14937
|
};
|
|
14778
|
-
var isExportedClass2 = (node, detached) => node.parent.type ===
|
|
14938
|
+
var isExportedClass2 = (node, detached) => node.parent.type === AST_NODE_TYPES61.ExportNamedDeclaration || node.parent.type === AST_NODE_TYPES61.ExportDefaultDeclaration || node.id !== null && detached.has(node.id.name);
|
|
14779
14939
|
var readTypeReference = (annotation) => {
|
|
14780
|
-
if (annotation?.type ===
|
|
14940
|
+
if (annotation?.type === AST_NODE_TYPES61.TSUnionType) {
|
|
14781
14941
|
const members = annotation.types.filter(
|
|
14782
|
-
(member) => member.type !==
|
|
14942
|
+
(member) => member.type !== AST_NODE_TYPES61.TSUndefinedKeyword && member.type !== AST_NODE_TYPES61.TSNullKeyword
|
|
14783
14943
|
);
|
|
14784
14944
|
annotation = members.length === 1 ? members[0] : void 0;
|
|
14785
14945
|
}
|
|
14786
|
-
if (annotation === void 0 || annotation.type !==
|
|
14946
|
+
if (annotation === void 0 || annotation.type !== AST_NODE_TYPES61.TSTypeReference) return null;
|
|
14787
14947
|
const { typeName } = annotation;
|
|
14788
|
-
const rightmost = typeName.type ===
|
|
14948
|
+
const rightmost = typeName.type === AST_NODE_TYPES61.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES61.TSQualifiedName ? typeName.right.name : null;
|
|
14789
14949
|
if (rightmost === null) return null;
|
|
14790
14950
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
14791
14951
|
};
|
|
14792
|
-
var qualifiedName = (name) => name.type ===
|
|
14952
|
+
var qualifiedName = (name) => name.type === AST_NODE_TYPES61.Identifier ? name.name : name.type === AST_NODE_TYPES61.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
14793
14953
|
var propertySignatureTypes = (members) => {
|
|
14794
14954
|
const types = /* @__PURE__ */ new Map();
|
|
14795
14955
|
for (const member of members) {
|
|
14796
|
-
if (member.type !==
|
|
14797
|
-
if (member.computed || member.key.type !==
|
|
14956
|
+
if (member.type !== AST_NODE_TYPES61.TSPropertySignature) continue;
|
|
14957
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES61.Identifier) continue;
|
|
14798
14958
|
const reference = readTypeReference(member.typeAnnotation?.typeAnnotation);
|
|
14799
14959
|
if (reference === null) continue;
|
|
14800
14960
|
types.set(member.key.name, reference);
|
|
@@ -14805,18 +14965,18 @@ var fileTypeIndex = (program) => {
|
|
|
14805
14965
|
const objects = /* @__PURE__ */ new Map();
|
|
14806
14966
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
14807
14967
|
for (const statement of program.body) {
|
|
14808
|
-
const declaration = statement.type ===
|
|
14809
|
-
if (declaration?.type ===
|
|
14968
|
+
const declaration = statement.type === AST_NODE_TYPES61.ExportNamedDeclaration ? statement.declaration : statement;
|
|
14969
|
+
if (declaration?.type === AST_NODE_TYPES61.TSInterfaceDeclaration) {
|
|
14810
14970
|
objects.set(declaration.id.name, propertySignatureTypes(declaration.body.body));
|
|
14811
14971
|
continue;
|
|
14812
14972
|
}
|
|
14813
|
-
if (declaration?.type !==
|
|
14973
|
+
if (declaration?.type !== AST_NODE_TYPES61.TSTypeAliasDeclaration) continue;
|
|
14814
14974
|
const aliased = declaration.typeAnnotation;
|
|
14815
|
-
if (aliased.type ===
|
|
14975
|
+
if (aliased.type === AST_NODE_TYPES61.TSFunctionType || aliased.type === AST_NODE_TYPES61.TSConstructorType) {
|
|
14816
14976
|
functionAliases.add(declaration.id.name);
|
|
14817
14977
|
continue;
|
|
14818
14978
|
}
|
|
14819
|
-
const literals = aliased.type ===
|
|
14979
|
+
const literals = aliased.type === AST_NODE_TYPES61.TSTypeLiteral ? [aliased] : aliased.type === AST_NODE_TYPES61.TSIntersectionType ? aliased.types.filter((part) => part.type === AST_NODE_TYPES61.TSTypeLiteral) : [];
|
|
14820
14980
|
if (literals.length === 0) continue;
|
|
14821
14981
|
const merged = /* @__PURE__ */ new Map();
|
|
14822
14982
|
for (const literal of literals) {
|
|
@@ -14845,10 +15005,10 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
14845
15005
|
while (pending.length > 0) {
|
|
14846
15006
|
const current = pending.pop();
|
|
14847
15007
|
if (current === void 0) break;
|
|
14848
|
-
if (current.type ===
|
|
14849
|
-
const expression = current.type ===
|
|
14850
|
-
const storedField = expression?.type ===
|
|
14851
|
-
if (expression?.type !==
|
|
15008
|
+
if (current.type === AST_NODE_TYPES61.ArrowFunctionExpression || current.type === AST_NODE_TYPES61.FunctionExpression || current.type === AST_NODE_TYPES61.FunctionDeclaration || current.type === AST_NODE_TYPES61.ClassExpression || current.type === AST_NODE_TYPES61.ClassDeclaration) continue;
|
|
15009
|
+
const expression = current.type === AST_NODE_TYPES61.ExpressionStatement ? current.expression : null;
|
|
15010
|
+
const storedField = expression?.type === AST_NODE_TYPES61.AssignmentExpression && expression.left.type === AST_NODE_TYPES61.MemberExpression && expression.left.object.type === AST_NODE_TYPES61.ThisExpression ? staticMemberName6(expression.left) : null;
|
|
15011
|
+
if (expression?.type !== AST_NODE_TYPES61.AssignmentExpression || !STORAGE_ASSIGNMENT_OPERATORS.has(expression.operator) || expression.left.type !== AST_NODE_TYPES61.MemberExpression || expression.left.object.type !== AST_NODE_TYPES61.ThisExpression || storedField === null) {
|
|
14852
15012
|
for (const key of Object.keys(current)) {
|
|
14853
15013
|
if (key === "parent") continue;
|
|
14854
15014
|
const value = current[key];
|
|
@@ -14861,14 +15021,14 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
14861
15021
|
continue;
|
|
14862
15022
|
}
|
|
14863
15023
|
let source = expression.right;
|
|
14864
|
-
while (source.type ===
|
|
14865
|
-
if (source.type ===
|
|
15024
|
+
while (source.type === AST_NODE_TYPES61.TSNonNullExpression || source.type === AST_NODE_TYPES61.TSAsExpression || source.type === AST_NODE_TYPES61.TSSatisfiesExpression || source.type === AST_NODE_TYPES61.TSTypeAssertion) source = source.expression;
|
|
15025
|
+
if (source.type === AST_NODE_TYPES61.NewExpression) {
|
|
14866
15026
|
constructedFields += 1;
|
|
14867
|
-
} else if (source.type ===
|
|
15027
|
+
} else if (source.type === AST_NODE_TYPES61.Identifier) {
|
|
14868
15028
|
const fields = storedFieldsFrom.get(source.name) ?? /* @__PURE__ */ new Set();
|
|
14869
15029
|
fields.add(storedField);
|
|
14870
15030
|
storedFieldsFrom.set(source.name, fields);
|
|
14871
|
-
} else if (source.type ===
|
|
15031
|
+
} else if (source.type === AST_NODE_TYPES61.MemberExpression && source.object.type === AST_NODE_TYPES61.Identifier) {
|
|
14872
15032
|
const fields = storedFieldsFrom.get(source.object.name) ?? /* @__PURE__ */ new Set();
|
|
14873
15033
|
fields.add(storedField);
|
|
14874
15034
|
storedFieldsFrom.set(source.object.name, fields);
|
|
@@ -14886,7 +15046,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
14886
15046
|
const collaborators = [];
|
|
14887
15047
|
for (const parameter of ctor.value.params) {
|
|
14888
15048
|
for (const reference of parameterCollaborators(parameter, declared, storedMemberFieldsFrom)) {
|
|
14889
|
-
const fields = parameter.type ===
|
|
15049
|
+
const fields = parameter.type === AST_NODE_TYPES61.TSParameterProperty ? [reference.name] : reference.fields.length > 0 ? reference.fields : [...storedFieldsFrom.get(reference.name) ?? []];
|
|
14890
15050
|
if (fields.length === 0) continue;
|
|
14891
15051
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
14892
15052
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -14901,8 +15061,8 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
14901
15061
|
};
|
|
14902
15062
|
var parameterCollaborators = (parameter, declared, storedMemberFieldsFrom) => {
|
|
14903
15063
|
let target = parameter;
|
|
14904
|
-
if (target.type ===
|
|
14905
|
-
if (target.type ===
|
|
15064
|
+
if (target.type === AST_NODE_TYPES61.AssignmentPattern) target = target.left;
|
|
15065
|
+
if (target.type === AST_NODE_TYPES61.ObjectPattern) {
|
|
14906
15066
|
return objectPatternCollaborators(target, declared);
|
|
14907
15067
|
}
|
|
14908
15068
|
const named2 = namedParameterCollaborator(parameter);
|
|
@@ -14911,9 +15071,9 @@ var parameterCollaborators = (parameter, declared, storedMemberFieldsFrom) => {
|
|
|
14911
15071
|
};
|
|
14912
15072
|
var namedBagCollaborators = (annotated, declared, storedMemberFieldsFrom) => {
|
|
14913
15073
|
let target = annotated;
|
|
14914
|
-
if (target.type ===
|
|
14915
|
-
if (target.type ===
|
|
14916
|
-
if (target.type !==
|
|
15074
|
+
if (target.type === AST_NODE_TYPES61.TSParameterProperty) target = target.parameter;
|
|
15075
|
+
if (target.type === AST_NODE_TYPES61.AssignmentPattern) target = target.left;
|
|
15076
|
+
if (target.type !== AST_NODE_TYPES61.Identifier) return [];
|
|
14917
15077
|
const members = bagMemberTypes(target.typeAnnotation?.typeAnnotation, declared);
|
|
14918
15078
|
if (members === null) return [];
|
|
14919
15079
|
const storedMembers = storedMemberFieldsFrom.get(target.name);
|
|
@@ -14929,9 +15089,9 @@ var namedBagCollaborators = (annotated, declared, storedMemberFieldsFrom) => {
|
|
|
14929
15089
|
};
|
|
14930
15090
|
var namedParameterCollaborator = (annotated) => {
|
|
14931
15091
|
let target = annotated;
|
|
14932
|
-
if (target.type ===
|
|
14933
|
-
if (target.type ===
|
|
14934
|
-
if (target.type !==
|
|
15092
|
+
if (target.type === AST_NODE_TYPES61.TSParameterProperty) target = target.parameter;
|
|
15093
|
+
if (target.type === AST_NODE_TYPES61.AssignmentPattern) target = target.left;
|
|
15094
|
+
if (target.type !== AST_NODE_TYPES61.Identifier) return null;
|
|
14935
15095
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
14936
15096
|
if (reference === null) return null;
|
|
14937
15097
|
return { name: target.name, ...reference, fields: [] };
|
|
@@ -14943,11 +15103,11 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
14943
15103
|
if (members === null) return [];
|
|
14944
15104
|
const collaborators = [];
|
|
14945
15105
|
for (const property of pattern.properties) {
|
|
14946
|
-
if (property.type !==
|
|
14947
|
-
if (property.key.type !==
|
|
15106
|
+
if (property.type !== AST_NODE_TYPES61.Property || property.computed) continue;
|
|
15107
|
+
if (property.key.type !== AST_NODE_TYPES61.Identifier) continue;
|
|
14948
15108
|
const key = property.key.name;
|
|
14949
|
-
const bound = property.value.type ===
|
|
14950
|
-
if (bound.type !==
|
|
15109
|
+
const bound = property.value.type === AST_NODE_TYPES61.AssignmentPattern ? property.value.left : property.value;
|
|
15110
|
+
if (bound.type !== AST_NODE_TYPES61.Identifier) continue;
|
|
14951
15111
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
14952
15112
|
const reference = members.get(key);
|
|
14953
15113
|
if (reference === void 0) continue;
|
|
@@ -14957,21 +15117,21 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
14957
15117
|
};
|
|
14958
15118
|
var bagMemberTypes = (annotation, declared) => {
|
|
14959
15119
|
if (annotation === void 0) return null;
|
|
14960
|
-
if (annotation.type ===
|
|
15120
|
+
if (annotation.type === AST_NODE_TYPES61.TSTypeLiteral) {
|
|
14961
15121
|
return propertySignatureTypes(annotation.members);
|
|
14962
15122
|
}
|
|
14963
|
-
if (annotation.type !==
|
|
15123
|
+
if (annotation.type !== AST_NODE_TYPES61.TSTypeReference || annotation.typeName.type !== AST_NODE_TYPES61.Identifier) {
|
|
14964
15124
|
return null;
|
|
14965
15125
|
}
|
|
14966
15126
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
14967
15127
|
};
|
|
14968
15128
|
var isFrameworkWiring = (body2) => subtreeHas(body2, (node) => {
|
|
14969
|
-
if (node.type ===
|
|
15129
|
+
if (node.type === AST_NODE_TYPES61.CallExpression) {
|
|
14970
15130
|
const { callee } = node;
|
|
14971
|
-
if (callee.type ===
|
|
14972
|
-
return callee.type ===
|
|
15131
|
+
if (callee.type === AST_NODE_TYPES61.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
15132
|
+
return callee.type === AST_NODE_TYPES61.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES61.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
14973
15133
|
}
|
|
14974
|
-
return node.type ===
|
|
15134
|
+
return node.type === AST_NODE_TYPES61.TSTypeReference && node.typeName.type === AST_NODE_TYPES61.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
14975
15135
|
});
|
|
14976
15136
|
var subtreeHas = (root, found) => {
|
|
14977
15137
|
let hit = false;
|
|
@@ -14998,19 +15158,19 @@ var invokedInstanceField = (call) => {
|
|
|
14998
15158
|
const direct = instanceField(call.callee);
|
|
14999
15159
|
if (direct !== null) return direct;
|
|
15000
15160
|
let callee = call.callee;
|
|
15001
|
-
while (callee.type ===
|
|
15002
|
-
return callee.type ===
|
|
15161
|
+
while (callee.type === AST_NODE_TYPES61.ChainExpression || callee.type === AST_NODE_TYPES61.TSAsExpression || callee.type === AST_NODE_TYPES61.TSNonNullExpression || callee.type === AST_NODE_TYPES61.TSSatisfiesExpression || callee.type === AST_NODE_TYPES61.TSTypeAssertion) callee = callee.expression;
|
|
15162
|
+
return callee.type === AST_NODE_TYPES61.MemberExpression ? instanceField(callee.object) : null;
|
|
15003
15163
|
};
|
|
15004
15164
|
var instanceField = (candidate2) => {
|
|
15005
15165
|
let node = candidate2;
|
|
15006
|
-
while (node.type ===
|
|
15007
|
-
return node.type ===
|
|
15166
|
+
while (node.type === AST_NODE_TYPES61.ChainExpression || node.type === AST_NODE_TYPES61.TSAsExpression || node.type === AST_NODE_TYPES61.TSNonNullExpression || node.type === AST_NODE_TYPES61.TSSatisfiesExpression || node.type === AST_NODE_TYPES61.TSTypeAssertion) node = node.expression;
|
|
15167
|
+
return node.type === AST_NODE_TYPES61.MemberExpression && node.object.type === AST_NODE_TYPES61.ThisExpression ? staticMemberName6(node) : null;
|
|
15008
15168
|
};
|
|
15009
15169
|
var behaviorallyInvokedFields = (body2) => {
|
|
15010
15170
|
const invoked = /* @__PURE__ */ new Set();
|
|
15011
15171
|
const visit = (current) => {
|
|
15012
|
-
if (current.type ===
|
|
15013
|
-
if (current.type ===
|
|
15172
|
+
if (current.type === AST_NODE_TYPES61.ClassDeclaration || current.type === AST_NODE_TYPES61.ClassExpression || current.type === AST_NODE_TYPES61.FunctionDeclaration || current.type === AST_NODE_TYPES61.FunctionExpression) return;
|
|
15173
|
+
if (current.type === AST_NODE_TYPES61.CallExpression) {
|
|
15014
15174
|
const field = invokedInstanceField(current);
|
|
15015
15175
|
if (field !== null) invoked.add(field);
|
|
15016
15176
|
}
|
|
@@ -15023,14 +15183,14 @@ var behaviorallyInvokedFields = (body2) => {
|
|
|
15023
15183
|
}
|
|
15024
15184
|
};
|
|
15025
15185
|
for (const member of body2.body) {
|
|
15026
|
-
if (member.type ===
|
|
15027
|
-
if (member.type ===
|
|
15186
|
+
if (member.type === AST_NODE_TYPES61.StaticBlock || member.static) continue;
|
|
15187
|
+
if (member.type === AST_NODE_TYPES61.MethodDefinition) {
|
|
15028
15188
|
if (member.value.body !== null && member.value.body !== void 0) visit(member.value.body);
|
|
15029
15189
|
continue;
|
|
15030
15190
|
}
|
|
15031
|
-
if (member.type !==
|
|
15191
|
+
if (member.type !== AST_NODE_TYPES61.PropertyDefinition || member.value === null) continue;
|
|
15032
15192
|
visit(
|
|
15033
|
-
member.value.type ===
|
|
15193
|
+
member.value.type === AST_NODE_TYPES61.ArrowFunctionExpression ? member.value.body : member.value
|
|
15034
15194
|
);
|
|
15035
15195
|
}
|
|
15036
15196
|
return invoked;
|
|
@@ -15050,25 +15210,25 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
15050
15210
|
var fileInterfaceNames = (program) => {
|
|
15051
15211
|
const names = [];
|
|
15052
15212
|
for (const statement of program.body) {
|
|
15053
|
-
const declaration = statement.type ===
|
|
15054
|
-
if (declaration?.type ===
|
|
15213
|
+
const declaration = statement.type === AST_NODE_TYPES61.ExportNamedDeclaration ? statement.declaration : statement;
|
|
15214
|
+
if (declaration?.type === AST_NODE_TYPES61.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
15055
15215
|
}
|
|
15056
15216
|
return names;
|
|
15057
15217
|
};
|
|
15058
15218
|
var publicMethodNames = (body2, functionAliases) => {
|
|
15059
15219
|
const names = [];
|
|
15060
15220
|
for (const member of body2.body) {
|
|
15061
|
-
if (member.type ===
|
|
15221
|
+
if (member.type === AST_NODE_TYPES61.PropertyDefinition) {
|
|
15062
15222
|
if (member.static || member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
15063
|
-
if (member.value?.type !==
|
|
15064
|
-
names.push(member.key.type ===
|
|
15223
|
+
if (member.value?.type !== AST_NODE_TYPES61.ArrowFunctionExpression && member.value?.type !== AST_NODE_TYPES61.FunctionExpression && member.typeAnnotation?.typeAnnotation.type !== AST_NODE_TYPES61.TSFunctionType && !(member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES61.TSTypeReference && member.typeAnnotation.typeAnnotation.typeName.type === AST_NODE_TYPES61.Identifier && functionAliases.has(member.typeAnnotation.typeAnnotation.typeName.name))) continue;
|
|
15224
|
+
names.push(member.key.type === AST_NODE_TYPES61.Identifier ? member.key.name : "\u2026");
|
|
15065
15225
|
continue;
|
|
15066
15226
|
}
|
|
15067
|
-
if (member.type !==
|
|
15227
|
+
if (member.type !== AST_NODE_TYPES61.MethodDefinition) continue;
|
|
15068
15228
|
if (member.kind !== "method" || member.static) continue;
|
|
15069
15229
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
15070
|
-
if (member.key.type ===
|
|
15071
|
-
if (member.key.type ===
|
|
15230
|
+
if (member.key.type === AST_NODE_TYPES61.PrivateIdentifier) continue;
|
|
15231
|
+
if (member.key.type === AST_NODE_TYPES61.Identifier) names.push(member.key.name);
|
|
15072
15232
|
else names.push("\u2026");
|
|
15073
15233
|
}
|
|
15074
15234
|
return names;
|
|
@@ -15076,13 +15236,13 @@ var publicMethodNames = (body2, functionAliases) => {
|
|
|
15076
15236
|
var isFluentConstructionObject = (node, getText) => {
|
|
15077
15237
|
if (node.id === null) return false;
|
|
15078
15238
|
const methods = node.body.body.filter(
|
|
15079
|
-
(member) => member.type ===
|
|
15239
|
+
(member) => member.type === AST_NODE_TYPES61.MethodDefinition && member.kind === "method" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.value.body !== null
|
|
15080
15240
|
);
|
|
15081
15241
|
if (methods.length === 0) return false;
|
|
15082
15242
|
return methods.every((member) => {
|
|
15083
15243
|
const result = member.value.returnType?.typeAnnotation;
|
|
15084
15244
|
if (result === void 0) return false;
|
|
15085
|
-
const returnsOwnType = result.type ===
|
|
15245
|
+
const returnsOwnType = result.type === AST_NODE_TYPES61.TSTypeReference && result.typeName.type === AST_NODE_TYPES61.Identifier && result.typeName.name === node.id?.name;
|
|
15086
15246
|
return returnsOwnType || FLUENT_BUILDER_NAME_RE.test(node.id?.name ?? "") && FLUENT_RESULT_TYPE_RE.test(getText(result));
|
|
15087
15247
|
});
|
|
15088
15248
|
};
|
|
@@ -15090,10 +15250,10 @@ function localClassAbstractness(program) {
|
|
|
15090
15250
|
const classes = /* @__PURE__ */ new Map();
|
|
15091
15251
|
const parents = /* @__PURE__ */ new Map();
|
|
15092
15252
|
for (const statement of program.body) {
|
|
15093
|
-
const declaration = statement.type ===
|
|
15094
|
-
if (declaration?.type ===
|
|
15253
|
+
const declaration = statement.type === AST_NODE_TYPES61.ExportNamedDeclaration || statement.type === AST_NODE_TYPES61.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
15254
|
+
if (declaration?.type === AST_NODE_TYPES61.ClassDeclaration && declaration.id !== null) {
|
|
15095
15255
|
classes.set(declaration.id.name, declaration.abstract === true);
|
|
15096
|
-
if (declaration.superClass?.type ===
|
|
15256
|
+
if (declaration.superClass?.type === AST_NODE_TYPES61.Identifier) {
|
|
15097
15257
|
parents.set(declaration.id.name, declaration.superClass.name);
|
|
15098
15258
|
}
|
|
15099
15259
|
}
|
|
@@ -15115,43 +15275,43 @@ function localInterfaceSurfaces(program) {
|
|
|
15115
15275
|
const parents = /* @__PURE__ */ new Map();
|
|
15116
15276
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
15117
15277
|
for (const statement of program.body) {
|
|
15118
|
-
const declaration = statement.type ===
|
|
15119
|
-
if (declaration?.type ===
|
|
15278
|
+
const declaration = statement.type === AST_NODE_TYPES61.ExportNamedDeclaration ? statement.declaration : statement;
|
|
15279
|
+
if (declaration?.type === AST_NODE_TYPES61.TSTypeAliasDeclaration && (declaration.typeAnnotation.type === AST_NODE_TYPES61.TSFunctionType || declaration.typeAnnotation.type === AST_NODE_TYPES61.TSConstructorType)) functionAliases.add(declaration.id.name);
|
|
15120
15280
|
}
|
|
15121
15281
|
for (const statement of program.body) {
|
|
15122
|
-
const declaration = statement.type ===
|
|
15123
|
-
if (declaration?.type ===
|
|
15282
|
+
const declaration = statement.type === AST_NODE_TYPES61.ExportNamedDeclaration ? statement.declaration : statement;
|
|
15283
|
+
if (declaration?.type === AST_NODE_TYPES61.TSTypeAliasDeclaration) {
|
|
15124
15284
|
const callables2 = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
15125
|
-
const parts = declaration.typeAnnotation.type ===
|
|
15285
|
+
const parts = declaration.typeAnnotation.type === AST_NODE_TYPES61.TSIntersectionType ? declaration.typeAnnotation.types : [declaration.typeAnnotation];
|
|
15126
15286
|
const inherited = parents.get(declaration.id.name) ?? [];
|
|
15127
15287
|
for (const part of parts) {
|
|
15128
|
-
if (part.type ===
|
|
15288
|
+
if (part.type === AST_NODE_TYPES61.TSTypeReference && part.typeName.type === AST_NODE_TYPES61.Identifier) {
|
|
15129
15289
|
inherited.push(part.typeName.name);
|
|
15130
15290
|
continue;
|
|
15131
15291
|
}
|
|
15132
|
-
if (part.type !==
|
|
15292
|
+
if (part.type !== AST_NODE_TYPES61.TSTypeLiteral) continue;
|
|
15133
15293
|
for (const member of part.members) {
|
|
15134
|
-
if (member.type !==
|
|
15135
|
-
if (member.computed || member.key.type !==
|
|
15136
|
-
if (member.type ===
|
|
15294
|
+
if (member.type !== AST_NODE_TYPES61.TSMethodSignature && member.type !== AST_NODE_TYPES61.TSPropertySignature) continue;
|
|
15295
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES61.Identifier) continue;
|
|
15296
|
+
if (member.type === AST_NODE_TYPES61.TSMethodSignature) {
|
|
15137
15297
|
callables2.add(member.key.name);
|
|
15138
15298
|
continue;
|
|
15139
15299
|
}
|
|
15140
|
-
if (member.type !==
|
|
15300
|
+
if (member.type !== AST_NODE_TYPES61.TSPropertySignature) continue;
|
|
15141
15301
|
const annotation = member.typeAnnotation?.typeAnnotation;
|
|
15142
|
-
if (annotation?.type ===
|
|
15302
|
+
if (annotation?.type === AST_NODE_TYPES61.TSFunctionType || annotation?.type === AST_NODE_TYPES61.TSTypeReference && annotation.typeName.type === AST_NODE_TYPES61.Identifier && functionAliases.has(annotation.typeName.name)) callables2.add(member.key.name);
|
|
15143
15303
|
}
|
|
15144
15304
|
}
|
|
15145
15305
|
interfaces.set(declaration.id.name, callables2);
|
|
15146
15306
|
parents.set(declaration.id.name, inherited);
|
|
15147
15307
|
continue;
|
|
15148
15308
|
}
|
|
15149
|
-
if (declaration?.type !==
|
|
15309
|
+
if (declaration?.type !== AST_NODE_TYPES61.TSInterfaceDeclaration) continue;
|
|
15150
15310
|
const callables = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
15151
15311
|
for (const member of declaration.body.body) {
|
|
15152
|
-
if (member.type !==
|
|
15153
|
-
if (member.computed || member.key.type !==
|
|
15154
|
-
if (member.type ===
|
|
15312
|
+
if (member.type !== AST_NODE_TYPES61.TSMethodSignature && member.type !== AST_NODE_TYPES61.TSPropertySignature) continue;
|
|
15313
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES61.Identifier) continue;
|
|
15314
|
+
if (member.type === AST_NODE_TYPES61.TSMethodSignature || member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES61.TSFunctionType || member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES61.TSTypeReference && member.typeAnnotation.typeAnnotation.typeName.type === AST_NODE_TYPES61.Identifier && functionAliases.has(member.typeAnnotation.typeAnnotation.typeName.name)) callables.add(member.key.name);
|
|
15155
15315
|
}
|
|
15156
15316
|
interfaces.set(declaration.id.name, callables);
|
|
15157
15317
|
parents.set(
|
|
@@ -15159,7 +15319,7 @@ function localInterfaceSurfaces(program) {
|
|
|
15159
15319
|
[
|
|
15160
15320
|
...parents.get(declaration.id.name) ?? [],
|
|
15161
15321
|
...declaration.extends.flatMap(
|
|
15162
|
-
(heritage) => heritage.expression.type ===
|
|
15322
|
+
(heritage) => heritage.expression.type === AST_NODE_TYPES61.Identifier ? [heritage.expression.name] : ["*"]
|
|
15163
15323
|
)
|
|
15164
15324
|
]
|
|
15165
15325
|
);
|
|
@@ -15186,7 +15346,7 @@ function localInterfaceSurfaces(program) {
|
|
|
15186
15346
|
}
|
|
15187
15347
|
function hasServicePort(node, methods, classes, interfaces) {
|
|
15188
15348
|
if (node.superClass !== null) {
|
|
15189
|
-
if (node.superClass.type !==
|
|
15349
|
+
if (node.superClass.type !== AST_NODE_TYPES61.Identifier) return true;
|
|
15190
15350
|
const localAbstract = classes.get(node.superClass.name);
|
|
15191
15351
|
if (localAbstract === void 0 || localAbstract) return true;
|
|
15192
15352
|
}
|
|
@@ -15198,7 +15358,7 @@ function hasServicePort(node, methods, classes, interfaces) {
|
|
|
15198
15358
|
if (node.implements.length === 0) return false;
|
|
15199
15359
|
const combined = /* @__PURE__ */ new Set();
|
|
15200
15360
|
for (const implementation of node.implements) {
|
|
15201
|
-
if (implementation.expression.type !==
|
|
15361
|
+
if (implementation.expression.type !== AST_NODE_TYPES61.Identifier) return true;
|
|
15202
15362
|
const name = implementation.expression.name;
|
|
15203
15363
|
const localAbstract = classes.get(name);
|
|
15204
15364
|
if (localAbstract === true) return true;
|
|
@@ -15241,7 +15401,7 @@ var require_port_for_service_default = createRule({
|
|
|
15241
15401
|
if (node.abstract === true) return;
|
|
15242
15402
|
if (node.decorators.length > 0) return;
|
|
15243
15403
|
const ctor = node.body.body.find(
|
|
15244
|
-
(member) => member.type ===
|
|
15404
|
+
(member) => member.type === AST_NODE_TYPES61.MethodDefinition && member.kind === "constructor" && member.value.body !== null && member.value.body !== void 0
|
|
15245
15405
|
);
|
|
15246
15406
|
if (ctor === void 0) return;
|
|
15247
15407
|
const constructorFacts = readConstructor(
|
|
@@ -15276,7 +15436,7 @@ var require_port_for_service_default = createRule({
|
|
|
15276
15436
|
});
|
|
15277
15437
|
|
|
15278
15438
|
// src/rules/require-static-next-matcher.ts
|
|
15279
|
-
import { AST_NODE_TYPES as
|
|
15439
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES62 } from "@typescript-eslint/utils";
|
|
15280
15440
|
var REQUIRE_STATIC_NEXT_MATCHER_DOCUMENTATION = {
|
|
15281
15441
|
summary: "Require Next.js middleware and proxy matcher configuration to contain only build-time literals.",
|
|
15282
15442
|
rationale: "Next.js must statically analyze matcher values at build time; computed values are ignored.",
|
|
@@ -15289,34 +15449,34 @@ var REQUIRE_STATIC_NEXT_MATCHER_DOCUMENTATION = {
|
|
|
15289
15449
|
};
|
|
15290
15450
|
var NEXT_ENTRY_FILE = /(?:^|[/\\])(?:middleware|proxy)\.[cm]?[jt]sx?$/u;
|
|
15291
15451
|
function unwrapExpression3(node) {
|
|
15292
|
-
if (node.type ===
|
|
15452
|
+
if (node.type === AST_NODE_TYPES62.TSAsExpression || node.type === AST_NODE_TYPES62.TSSatisfiesExpression || node.type === AST_NODE_TYPES62.TSNonNullExpression || node.type === AST_NODE_TYPES62.TSTypeAssertion) {
|
|
15293
15453
|
return unwrapExpression3(node.expression);
|
|
15294
15454
|
}
|
|
15295
15455
|
return node;
|
|
15296
15456
|
}
|
|
15297
15457
|
function isStaticValue(node) {
|
|
15298
15458
|
const value = unwrapExpression3(node);
|
|
15299
|
-
if (value.type ===
|
|
15459
|
+
if (value.type === AST_NODE_TYPES62.Literal) {
|
|
15300
15460
|
return true;
|
|
15301
15461
|
}
|
|
15302
|
-
if (value.type ===
|
|
15462
|
+
if (value.type === AST_NODE_TYPES62.TemplateLiteral) {
|
|
15303
15463
|
return value.expressions.length === 0;
|
|
15304
15464
|
}
|
|
15305
|
-
if (value.type ===
|
|
15465
|
+
if (value.type === AST_NODE_TYPES62.ArrayExpression) {
|
|
15306
15466
|
return value.elements.every(
|
|
15307
|
-
(element) => element !== null && element.type !==
|
|
15467
|
+
(element) => element !== null && element.type !== AST_NODE_TYPES62.SpreadElement && isStaticValue(element)
|
|
15308
15468
|
);
|
|
15309
15469
|
}
|
|
15310
|
-
if (value.type ===
|
|
15470
|
+
if (value.type === AST_NODE_TYPES62.ObjectExpression) {
|
|
15311
15471
|
return value.properties.every(
|
|
15312
|
-
(property) => property.type ===
|
|
15472
|
+
(property) => property.type === AST_NODE_TYPES62.Property && property.kind === "init" && !property.computed && property.value.type !== AST_NODE_TYPES62.AssignmentPattern && isStaticValue(property.value)
|
|
15313
15473
|
);
|
|
15314
15474
|
}
|
|
15315
15475
|
return false;
|
|
15316
15476
|
}
|
|
15317
15477
|
function propertyName4(property) {
|
|
15318
15478
|
if (property.computed) return null;
|
|
15319
|
-
if (property.key.type ===
|
|
15479
|
+
if (property.key.type === AST_NODE_TYPES62.Identifier) return property.key.name;
|
|
15320
15480
|
return typeof property.key.value === "string" ? property.key.value : null;
|
|
15321
15481
|
}
|
|
15322
15482
|
var require_static_next_matcher_default = createRule({
|
|
@@ -15339,19 +15499,19 @@ var require_static_next_matcher_default = createRule({
|
|
|
15339
15499
|
}
|
|
15340
15500
|
return {
|
|
15341
15501
|
ExportNamedDeclaration(node) {
|
|
15342
|
-
if (node.declaration?.type !==
|
|
15502
|
+
if (node.declaration?.type !== AST_NODE_TYPES62.VariableDeclaration) {
|
|
15343
15503
|
return;
|
|
15344
15504
|
}
|
|
15345
15505
|
for (const declaration of node.declaration.declarations) {
|
|
15346
|
-
if (declaration.id.type !==
|
|
15506
|
+
if (declaration.id.type !== AST_NODE_TYPES62.Identifier || declaration.id.name !== "config" || declaration.init === null) {
|
|
15347
15507
|
continue;
|
|
15348
15508
|
}
|
|
15349
15509
|
const config = unwrapExpression3(declaration.init);
|
|
15350
|
-
if (config.type !==
|
|
15510
|
+
if (config.type !== AST_NODE_TYPES62.ObjectExpression) {
|
|
15351
15511
|
continue;
|
|
15352
15512
|
}
|
|
15353
15513
|
for (const property of config.properties) {
|
|
15354
|
-
if (property.type !==
|
|
15514
|
+
if (property.type !== AST_NODE_TYPES62.Property || propertyName4(property) !== "matcher" || property.value.type === AST_NODE_TYPES62.AssignmentPattern) {
|
|
15355
15515
|
continue;
|
|
15356
15516
|
}
|
|
15357
15517
|
if (!isStaticValue(property.value)) {
|
|
@@ -15365,7 +15525,7 @@ var require_static_next_matcher_default = createRule({
|
|
|
15365
15525
|
});
|
|
15366
15526
|
|
|
15367
15527
|
// src/rules/require-use-form-default-values.ts
|
|
15368
|
-
import { ASTUtils as
|
|
15528
|
+
import { ASTUtils as ASTUtils20 } from "@typescript-eslint/utils";
|
|
15369
15529
|
var REQUIRE_USE_FORM_DEFAULT_VALUES_DOCUMENTATION = {
|
|
15370
15530
|
summary: "react-hook-form useForm call without defaultValues",
|
|
15371
15531
|
rationale: "Without an explicit initial value, fields can change from uncontrolled to controlled as data arrives, reset behavior becomes ambiguous, and the form's initial shape no longer documents the values users can edit.",
|
|
@@ -15419,13 +15579,13 @@ var require_use_form_default_values_default = createRule({
|
|
|
15419
15579
|
if (node.source.value !== "react-hook-form") return;
|
|
15420
15580
|
for (const specifier of node.specifiers) {
|
|
15421
15581
|
if (specifier.type !== "ImportSpecifier" || (specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value) !== "useForm") continue;
|
|
15422
|
-
const variable =
|
|
15582
|
+
const variable = ASTUtils20.findVariable(context.sourceCode.getScope(specifier.local), specifier.local.name);
|
|
15423
15583
|
if (variable) importedHooks.add(variable);
|
|
15424
15584
|
}
|
|
15425
15585
|
},
|
|
15426
15586
|
CallExpression(node) {
|
|
15427
15587
|
if (node.callee.type !== "Identifier") return;
|
|
15428
|
-
const variable =
|
|
15588
|
+
const variable = ASTUtils20.findVariable(context.sourceCode.getScope(node.callee), node.callee.name);
|
|
15429
15589
|
const options = node.arguments[0];
|
|
15430
15590
|
if (!variable || !importedHooks.has(variable) || options !== void 0 && options.type !== "ObjectExpression" || hasDefaultValues(options)) return;
|
|
15431
15591
|
context.report({ node, messageId: "requireUseFormDefaultValues" });
|
|
@@ -15502,8 +15662,8 @@ var require_use_server_in_actions_file_default = createRule({
|
|
|
15502
15662
|
|
|
15503
15663
|
// src/rules/require-zod-form-validation.ts
|
|
15504
15664
|
import {
|
|
15505
|
-
AST_NODE_TYPES as
|
|
15506
|
-
ASTUtils as
|
|
15665
|
+
AST_NODE_TYPES as AST_NODE_TYPES63,
|
|
15666
|
+
ASTUtils as ASTUtils21
|
|
15507
15667
|
} from "@typescript-eslint/utils";
|
|
15508
15668
|
var REQUIRE_ZOD_FORM_VALIDATION_DOCUMENTATION = {
|
|
15509
15669
|
summary: "Require Zod validation (`Schema.parse(...)` / `Schema.safeParse(...)`) when reading values out of a `FormData` object.",
|
|
@@ -15529,14 +15689,14 @@ var FORM_VALUE_METHODS = /* @__PURE__ */ new Set(["get", "getAll"]);
|
|
|
15529
15689
|
var zodReceiverRoot = (node) => {
|
|
15530
15690
|
let current = node;
|
|
15531
15691
|
while (true) {
|
|
15532
|
-
if (current.type ===
|
|
15692
|
+
if (current.type === AST_NODE_TYPES63.Identifier) {
|
|
15533
15693
|
return current;
|
|
15534
15694
|
}
|
|
15535
|
-
if (current.type ===
|
|
15695
|
+
if (current.type === AST_NODE_TYPES63.CallExpression) {
|
|
15536
15696
|
current = current.callee;
|
|
15537
15697
|
continue;
|
|
15538
15698
|
}
|
|
15539
|
-
if (current.type ===
|
|
15699
|
+
if (current.type === AST_NODE_TYPES63.MemberExpression) {
|
|
15540
15700
|
current = current.object;
|
|
15541
15701
|
continue;
|
|
15542
15702
|
}
|
|
@@ -15545,12 +15705,12 @@ var zodReceiverRoot = (node) => {
|
|
|
15545
15705
|
};
|
|
15546
15706
|
var isFormDataMethodCall = (node) => {
|
|
15547
15707
|
let current = node;
|
|
15548
|
-
if (current.type ===
|
|
15708
|
+
if (current.type === AST_NODE_TYPES63.AwaitExpression) {
|
|
15549
15709
|
current = current.argument;
|
|
15550
15710
|
}
|
|
15551
|
-
if (current.type !==
|
|
15711
|
+
if (current.type !== AST_NODE_TYPES63.CallExpression) return false;
|
|
15552
15712
|
const callee = current.callee;
|
|
15553
|
-
return callee.type ===
|
|
15713
|
+
return callee.type === AST_NODE_TYPES63.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES63.Identifier && callee.property.name === "formData";
|
|
15554
15714
|
};
|
|
15555
15715
|
var require_zod_form_validation_default = createRule({
|
|
15556
15716
|
name: "require-zod-form-validation",
|
|
@@ -15571,7 +15731,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
15571
15731
|
return {};
|
|
15572
15732
|
}
|
|
15573
15733
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
15574
|
-
const resolvedBinding = (identifier) =>
|
|
15734
|
+
const resolvedBinding = (identifier) => ASTUtils21.findVariable(
|
|
15575
15735
|
context.sourceCode.getScope(identifier),
|
|
15576
15736
|
identifier.name
|
|
15577
15737
|
);
|
|
@@ -15581,16 +15741,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
15581
15741
|
return false;
|
|
15582
15742
|
}
|
|
15583
15743
|
const definition = binding.defs[0];
|
|
15584
|
-
if (definition?.type !== "Variable" || definition.node.type !==
|
|
15744
|
+
if (definition?.type !== "Variable" || definition.node.type !== AST_NODE_TYPES63.VariableDeclarator) {
|
|
15585
15745
|
return false;
|
|
15586
15746
|
}
|
|
15587
15747
|
const init = definition.node.init;
|
|
15588
|
-
return init?.type ===
|
|
15748
|
+
return init?.type === AST_NODE_TYPES63.ObjectExpression || init?.type === AST_NODE_TYPES63.ArrayExpression || init?.type === AST_NODE_TYPES63.Literal || init?.type === AST_NODE_TYPES63.ArrowFunctionExpression || init?.type === AST_NODE_TYPES63.FunctionExpression;
|
|
15589
15749
|
};
|
|
15590
15750
|
const isZodParseCall = (node) => {
|
|
15591
|
-
if (node.type !==
|
|
15751
|
+
if (node.type !== AST_NODE_TYPES63.CallExpression) return false;
|
|
15592
15752
|
const callee = node.callee;
|
|
15593
|
-
if (callee.type !==
|
|
15753
|
+
if (callee.type !== AST_NODE_TYPES63.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES63.Identifier || !ZOD_PARSE_METHODS.has(callee.property.name)) {
|
|
15594
15754
|
return false;
|
|
15595
15755
|
}
|
|
15596
15756
|
const root = zodReceiverRoot(callee.object);
|
|
@@ -15599,14 +15759,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
15599
15759
|
return binding !== null && zodBindings.has(binding) || (root.name === "z" || ZOD_SCHEMA_NAME_RE.test(root.name)) && !isProvablyNonZodLocal(root);
|
|
15600
15760
|
};
|
|
15601
15761
|
const isFormSourceIdentifier = (node) => {
|
|
15602
|
-
if (node.type !==
|
|
15762
|
+
if (node.type !== AST_NODE_TYPES63.Identifier) return false;
|
|
15603
15763
|
const conventionalName = /formdata/i.test(node.name);
|
|
15604
15764
|
let scope = context.sourceCode.getScope(node);
|
|
15605
15765
|
while (scope !== null) {
|
|
15606
15766
|
const variable = scope.set.get(node.name);
|
|
15607
15767
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
15608
15768
|
const def = variable.defs[0];
|
|
15609
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
15769
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === AST_NODE_TYPES63.VariableDeclarator && def.node.init !== null) {
|
|
15610
15770
|
return isFormDataMethodCall(def.node.init);
|
|
15611
15771
|
}
|
|
15612
15772
|
return def?.type === "Parameter" && conventionalName;
|
|
@@ -15617,8 +15777,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
15617
15777
|
};
|
|
15618
15778
|
const isFormDataGetCall = (node) => {
|
|
15619
15779
|
const callee = node.callee;
|
|
15620
|
-
if (callee.type !==
|
|
15621
|
-
if (callee.property.type !==
|
|
15780
|
+
if (callee.type !== AST_NODE_TYPES63.MemberExpression) return false;
|
|
15781
|
+
if (callee.property.type !== AST_NODE_TYPES63.Identifier || !FORM_VALUE_METHODS.has(callee.property.name)) {
|
|
15622
15782
|
return false;
|
|
15623
15783
|
}
|
|
15624
15784
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -15634,16 +15794,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
15634
15794
|
const hasZodParseAncestor = (node) => zodParseAncestor(node) !== null;
|
|
15635
15795
|
const isInstanceofNarrowing = (node) => {
|
|
15636
15796
|
const parent = node.parent;
|
|
15637
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
15797
|
+
return parent !== null && parent !== void 0 && parent.type === AST_NODE_TYPES63.BinaryExpression && parent.operator === "instanceof" && parent.left === node && parent.right.type === AST_NODE_TYPES63.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
15638
15798
|
};
|
|
15639
15799
|
const boundDeclarator = (node) => {
|
|
15640
15800
|
let current = node;
|
|
15641
15801
|
let parent = current.parent;
|
|
15642
|
-
while ((parent.type ===
|
|
15802
|
+
while ((parent.type === AST_NODE_TYPES63.TSAsExpression || parent.type === AST_NODE_TYPES63.TSSatisfiesExpression || parent.type === AST_NODE_TYPES63.TSNonNullExpression || parent.type === AST_NODE_TYPES63.ChainExpression) && parent.expression === current) {
|
|
15643
15803
|
current = parent;
|
|
15644
15804
|
parent = current.parent;
|
|
15645
15805
|
}
|
|
15646
|
-
if (parent.type ===
|
|
15806
|
+
if (parent.type === AST_NODE_TYPES63.VariableDeclarator && parent.init === current && parent.id.type === AST_NODE_TYPES63.Identifier) {
|
|
15647
15807
|
return parent;
|
|
15648
15808
|
}
|
|
15649
15809
|
return null;
|
|
@@ -15652,7 +15812,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
15652
15812
|
let current = node;
|
|
15653
15813
|
while (current.parent !== void 0) {
|
|
15654
15814
|
const parent = current.parent;
|
|
15655
|
-
if (parent.type ===
|
|
15815
|
+
if (parent.type === AST_NODE_TYPES63.BlockStatement || parent.type === AST_NODE_TYPES63.Program) {
|
|
15656
15816
|
return current;
|
|
15657
15817
|
}
|
|
15658
15818
|
current = parent;
|
|
@@ -15661,12 +15821,12 @@ var require_zod_form_validation_default = createRule({
|
|
|
15661
15821
|
};
|
|
15662
15822
|
const zodParseMethod = (call) => {
|
|
15663
15823
|
const callee = call.callee;
|
|
15664
|
-
return callee.type ===
|
|
15824
|
+
return callee.type === AST_NODE_TYPES63.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES63.Identifier ? callee.property.name : null;
|
|
15665
15825
|
};
|
|
15666
15826
|
const hasConditionalAncestorBeforeStatement = (node, statement) => {
|
|
15667
15827
|
let current = node.parent;
|
|
15668
15828
|
while (current !== void 0 && current !== statement) {
|
|
15669
|
-
if (current.type ===
|
|
15829
|
+
if (current.type === AST_NODE_TYPES63.LogicalExpression || current.type === AST_NODE_TYPES63.ConditionalExpression) {
|
|
15670
15830
|
return true;
|
|
15671
15831
|
}
|
|
15672
15832
|
current = current.parent;
|
|
@@ -15676,7 +15836,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
15676
15836
|
const isAwaitedBeforeStatement = (node, statement) => {
|
|
15677
15837
|
let current = node.parent;
|
|
15678
15838
|
while (current !== void 0 && current !== statement) {
|
|
15679
|
-
if (current.type ===
|
|
15839
|
+
if (current.type === AST_NODE_TYPES63.AwaitExpression) return true;
|
|
15680
15840
|
current = current.parent;
|
|
15681
15841
|
}
|
|
15682
15842
|
return false;
|
|
@@ -15689,7 +15849,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
15689
15849
|
if (declarationStatement === null || validationStatement === null || declarationStatement.parent !== validationStatement.parent || validationStatement.range[0] <= declarationStatement.range[1] || hasConditionalAncestorBeforeStatement(parse2, validationStatement)) {
|
|
15690
15850
|
return null;
|
|
15691
15851
|
}
|
|
15692
|
-
if (validationStatement.type !==
|
|
15852
|
+
if (validationStatement.type !== AST_NODE_TYPES63.VariableDeclaration && validationStatement.type !== AST_NODE_TYPES63.ExpressionStatement) {
|
|
15693
15853
|
return null;
|
|
15694
15854
|
}
|
|
15695
15855
|
const method = zodParseMethod(parse2);
|
|
@@ -15701,16 +15861,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
15701
15861
|
};
|
|
15702
15862
|
const isSafePrevalidationInspection = (identifier) => {
|
|
15703
15863
|
const parent = identifier.parent;
|
|
15704
|
-
if (parent.type ===
|
|
15864
|
+
if (parent.type === AST_NODE_TYPES63.UnaryExpression && parent.operator === "typeof") {
|
|
15705
15865
|
return true;
|
|
15706
15866
|
}
|
|
15707
|
-
if (parent.type !==
|
|
15867
|
+
if (parent.type !== AST_NODE_TYPES63.BinaryExpression || parent.left !== identifier) {
|
|
15708
15868
|
return false;
|
|
15709
15869
|
}
|
|
15710
15870
|
if (parent.operator === "instanceof") {
|
|
15711
|
-
return parent.right.type ===
|
|
15871
|
+
return parent.right.type === AST_NODE_TYPES63.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
15712
15872
|
}
|
|
15713
|
-
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type ===
|
|
15873
|
+
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type === AST_NODE_TYPES63.Literal && parent.right.value === null || parent.right.type === AST_NODE_TYPES63.Identifier && parent.right.name === "undefined");
|
|
15714
15874
|
};
|
|
15715
15875
|
const isDescendantOf = (node, ancestor) => {
|
|
15716
15876
|
let current = node;
|
|
@@ -15721,23 +15881,23 @@ var require_zod_form_validation_default = createRule({
|
|
|
15721
15881
|
return false;
|
|
15722
15882
|
};
|
|
15723
15883
|
const blockTerminates = (node) => {
|
|
15724
|
-
if (node.type ===
|
|
15884
|
+
if (node.type === AST_NODE_TYPES63.ReturnStatement || node.type === AST_NODE_TYPES63.ThrowStatement) {
|
|
15725
15885
|
return true;
|
|
15726
15886
|
}
|
|
15727
|
-
if (node.type !==
|
|
15887
|
+
if (node.type !== AST_NODE_TYPES63.BlockStatement || node.body.length === 0) return false;
|
|
15728
15888
|
const last = node.body.at(-1);
|
|
15729
15889
|
return last !== void 0 && blockTerminates(last);
|
|
15730
15890
|
};
|
|
15731
15891
|
const narrowingIf = (identifier) => {
|
|
15732
15892
|
const comparison = identifier.parent;
|
|
15733
|
-
if (comparison?.type !==
|
|
15893
|
+
if (comparison?.type !== AST_NODE_TYPES63.BinaryExpression || comparison.operator !== "instanceof" || comparison.left !== identifier || comparison.right.type !== AST_NODE_TYPES63.Identifier || comparison.right.name !== "File" && comparison.right.name !== "Blob") {
|
|
15734
15894
|
return null;
|
|
15735
15895
|
}
|
|
15736
15896
|
const maybeNegation = comparison.parent;
|
|
15737
|
-
const negated = maybeNegation?.type ===
|
|
15897
|
+
const negated = maybeNegation?.type === AST_NODE_TYPES63.UnaryExpression && maybeNegation.operator === "!";
|
|
15738
15898
|
const test = negated ? maybeNegation : comparison;
|
|
15739
15899
|
const branch = test.parent;
|
|
15740
|
-
return branch?.type ===
|
|
15900
|
+
return branch?.type === AST_NODE_TYPES63.IfStatement && branch.test === test ? { branch, positive: !negated } : null;
|
|
15741
15901
|
};
|
|
15742
15902
|
const useDominatedByNarrowing = (use, narrowings) => narrowings.some(({ branch, positive }) => {
|
|
15743
15903
|
if (positive) return isDescendantOf(use, branch.consequent);
|
|
@@ -15757,7 +15917,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
15757
15917
|
const variable = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
15758
15918
|
if (variable === void 0) return false;
|
|
15759
15919
|
const references = variable.references.filter((reference) => !reference.isWriteOnly()).map((reference) => reference.identifier).filter(
|
|
15760
|
-
(identifier) => identifier.type ===
|
|
15920
|
+
(identifier) => identifier.type === AST_NODE_TYPES63.Identifier
|
|
15761
15921
|
);
|
|
15762
15922
|
if (references.length === 0) return false;
|
|
15763
15923
|
const narrowings = references.map(narrowingIf).filter(
|
|
@@ -15783,7 +15943,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
15783
15943
|
ImportDeclaration(node) {
|
|
15784
15944
|
if (!isZodModule(node.source.value)) return;
|
|
15785
15945
|
for (const specifier of node.specifiers) {
|
|
15786
|
-
if (specifier.type ===
|
|
15946
|
+
if (specifier.type === AST_NODE_TYPES63.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES63.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES63.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES63.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
15787
15947
|
const binding = resolvedBinding(specifier.local);
|
|
15788
15948
|
if (binding !== null) zodBindings.add(binding);
|
|
15789
15949
|
}
|
|
@@ -15868,7 +16028,7 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
15868
16028
|
});
|
|
15869
16029
|
|
|
15870
16030
|
// src/rules/stepdown.ts
|
|
15871
|
-
import { AST_NODE_TYPES as
|
|
16031
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES64, ASTUtils as ASTUtils22 } from "@typescript-eslint/utils";
|
|
15872
16032
|
var STEPDOWN_DOCUMENTATION = {
|
|
15873
16033
|
summary: "Place a private helper below its sole direct same-scope caller.",
|
|
15874
16034
|
rationale: "Caller-first ordering lets a reader follow the main flow before descending into implementation details.",
|
|
@@ -15888,7 +16048,7 @@ var STEPDOWN_DOCUMENTATION = {
|
|
|
15888
16048
|
]
|
|
15889
16049
|
};
|
|
15890
16050
|
function isFunction(node) {
|
|
15891
|
-
return node.type ===
|
|
16051
|
+
return node.type === AST_NODE_TYPES64.ArrowFunctionExpression || node.type === AST_NODE_TYPES64.FunctionDeclaration || node.type === AST_NODE_TYPES64.FunctionExpression;
|
|
15892
16052
|
}
|
|
15893
16053
|
function reportMisordered(context, candidates, scopeDefinitions, calls, pinned, canMove = () => true, makeFix) {
|
|
15894
16054
|
const byName = new Map(scopeDefinitions.map((definition) => [definition.name, definition]));
|
|
@@ -15985,8 +16145,8 @@ function moduleScope(context, program) {
|
|
|
15985
16145
|
for (const node of declarations) counts.set(node.name, (counts.get(node.name) ?? 0) + 1);
|
|
15986
16146
|
const overloadNames = new Set(
|
|
15987
16147
|
program.body.flatMap((statement) => {
|
|
15988
|
-
const node = statement.type ===
|
|
15989
|
-
return node?.type ===
|
|
16148
|
+
const node = statement.type === AST_NODE_TYPES64.ExportNamedDeclaration ? statement.declaration : statement;
|
|
16149
|
+
return node?.type === AST_NODE_TYPES64.TSDeclareFunction && node.id !== null ? [node.id.name] : [];
|
|
15990
16150
|
})
|
|
15991
16151
|
);
|
|
15992
16152
|
const exported = exportedNames(program);
|
|
@@ -16010,7 +16170,7 @@ function moduleScope(context, program) {
|
|
|
16010
16170
|
const nearestFunction2 = [...ancestors].reverse().find(isFunction);
|
|
16011
16171
|
const parent = identifier.parent;
|
|
16012
16172
|
const callerDefinition = nearestFunction2 === void 0 ? void 0 : byFunction.get(nearestFunction2);
|
|
16013
|
-
if (callerDefinition === void 0 || parent.type !==
|
|
16173
|
+
if (callerDefinition === void 0 || parent.type !== AST_NODE_TYPES64.CallExpression || parent.callee !== identifier) {
|
|
16014
16174
|
pinned.add(definition.name);
|
|
16015
16175
|
continue;
|
|
16016
16176
|
}
|
|
@@ -16025,38 +16185,38 @@ function moduleScope(context, program) {
|
|
|
16025
16185
|
function exportedNames(program) {
|
|
16026
16186
|
const names = /* @__PURE__ */ new Set();
|
|
16027
16187
|
for (const statement of program.body) {
|
|
16028
|
-
if (statement.type !==
|
|
16029
|
-
if (statement.declaration?.type ===
|
|
16188
|
+
if (statement.type !== AST_NODE_TYPES64.ExportNamedDeclaration || statement.exportKind === "type" || statement.source !== null) continue;
|
|
16189
|
+
if (statement.declaration?.type === AST_NODE_TYPES64.FunctionDeclaration && statement.declaration.id !== null) {
|
|
16030
16190
|
names.add(statement.declaration.id.name);
|
|
16031
16191
|
}
|
|
16032
|
-
if (statement.declaration?.type ===
|
|
16192
|
+
if (statement.declaration?.type === AST_NODE_TYPES64.VariableDeclaration) {
|
|
16033
16193
|
for (const declarator of statement.declaration.declarations) {
|
|
16034
|
-
if (declarator.id.type ===
|
|
16194
|
+
if (declarator.id.type === AST_NODE_TYPES64.Identifier) names.add(declarator.id.name);
|
|
16035
16195
|
}
|
|
16036
16196
|
}
|
|
16037
16197
|
for (const specifier of statement.specifiers) {
|
|
16038
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
16198
|
+
if (specifier.exportKind !== "type" && specifier.local.type === AST_NODE_TYPES64.Identifier) {
|
|
16039
16199
|
names.add(specifier.local.name);
|
|
16040
16200
|
}
|
|
16041
16201
|
}
|
|
16042
16202
|
}
|
|
16043
16203
|
for (const statement of program.body) {
|
|
16044
|
-
if (statement.type ===
|
|
16045
|
-
if (statement.type ===
|
|
16204
|
+
if (statement.type === AST_NODE_TYPES64.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES64.Identifier) names.add(statement.declaration.name);
|
|
16205
|
+
if (statement.type === AST_NODE_TYPES64.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES64.FunctionDeclaration && statement.declaration.id !== null) names.add(statement.declaration.id.name);
|
|
16046
16206
|
}
|
|
16047
16207
|
return names;
|
|
16048
16208
|
}
|
|
16049
16209
|
function moduleDefinitions(program) {
|
|
16050
16210
|
const definitions = [];
|
|
16051
16211
|
for (const statement of program.body) {
|
|
16052
|
-
const node = statement.type ===
|
|
16053
|
-
if (node?.type ===
|
|
16212
|
+
const node = statement.type === AST_NODE_TYPES64.ExportNamedDeclaration || statement.type === AST_NODE_TYPES64.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
16213
|
+
if (node?.type === AST_NODE_TYPES64.FunctionDeclaration && node.id !== null && node.body !== null) {
|
|
16054
16214
|
definitions.push({ name: node.id.name, node, functionNode: node, bindingNode: node });
|
|
16055
16215
|
continue;
|
|
16056
16216
|
}
|
|
16057
|
-
if (node?.type !==
|
|
16217
|
+
if (node?.type !== AST_NODE_TYPES64.VariableDeclaration || node.kind !== "const") continue;
|
|
16058
16218
|
for (const declarator of node.declarations) {
|
|
16059
|
-
if (declarator.id.type ===
|
|
16219
|
+
if (declarator.id.type === AST_NODE_TYPES64.Identifier && declarator.init !== null && isFunction(declarator.init)) {
|
|
16060
16220
|
definitions.push({
|
|
16061
16221
|
name: declarator.id.name,
|
|
16062
16222
|
node: declarator,
|
|
@@ -16069,21 +16229,21 @@ function moduleDefinitions(program) {
|
|
|
16069
16229
|
return definitions;
|
|
16070
16230
|
}
|
|
16071
16231
|
function methodName(node) {
|
|
16072
|
-
if (node.key.type ===
|
|
16073
|
-
return !node.computed && node.key.type ===
|
|
16232
|
+
if (node.key.type === AST_NODE_TYPES64.PrivateIdentifier) return `#${node.key.name}`;
|
|
16233
|
+
return !node.computed && node.key.type === AST_NODE_TYPES64.Identifier ? node.key.name : null;
|
|
16074
16234
|
}
|
|
16075
16235
|
function referencedMethod(context, node, classVariables) {
|
|
16076
|
-
const objectVariable = node.object.type ===
|
|
16236
|
+
const objectVariable = node.object.type === AST_NODE_TYPES64.Identifier ? ASTUtils22.findVariable(context.sourceCode.getScope(node.object), node.object.name) : null;
|
|
16077
16237
|
const isClassReference = objectVariable !== null && classVariables.has(objectVariable);
|
|
16078
|
-
if (node.object.type !==
|
|
16079
|
-
if (node.property.type ===
|
|
16080
|
-
if (!node.computed && node.property.type ===
|
|
16081
|
-
return node.computed && node.property.type ===
|
|
16238
|
+
if (node.object.type !== AST_NODE_TYPES64.ThisExpression && !isClassReference) return null;
|
|
16239
|
+
if (node.property.type === AST_NODE_TYPES64.PrivateIdentifier) return `#${node.property.name}`;
|
|
16240
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES64.Identifier) return node.property.name;
|
|
16241
|
+
return node.computed && node.property.type === AST_NODE_TYPES64.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
16082
16242
|
}
|
|
16083
16243
|
function referencedPropertyName(node) {
|
|
16084
|
-
if (node.property.type ===
|
|
16085
|
-
if (!node.computed && node.property.type ===
|
|
16086
|
-
return node.computed && node.property.type ===
|
|
16244
|
+
if (node.property.type === AST_NODE_TYPES64.PrivateIdentifier) return `#${node.property.name}`;
|
|
16245
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES64.Identifier) return node.property.name;
|
|
16246
|
+
return node.computed && node.property.type === AST_NODE_TYPES64.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
16087
16247
|
}
|
|
16088
16248
|
function walk2(node, visitorKeys, visit, nestedFunction = false) {
|
|
16089
16249
|
visit(node, nestedFunction);
|
|
@@ -16099,7 +16259,7 @@ function walk2(node, visitorKeys, visit, nestedFunction = false) {
|
|
|
16099
16259
|
}
|
|
16100
16260
|
function classScope(context, node, computedReferenceNames) {
|
|
16101
16261
|
const methods = node.body.body.filter(
|
|
16102
|
-
(member) => member.type ===
|
|
16262
|
+
(member) => member.type === AST_NODE_TYPES64.MethodDefinition
|
|
16103
16263
|
);
|
|
16104
16264
|
const counts = /* @__PURE__ */ new Map();
|
|
16105
16265
|
for (const method of methods) {
|
|
@@ -16107,8 +16267,8 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
16107
16267
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
16108
16268
|
}
|
|
16109
16269
|
for (const member of node.body.body) {
|
|
16110
|
-
if (member.type !==
|
|
16111
|
-
const name = !member.computed && member.key.type ===
|
|
16270
|
+
if (member.type !== AST_NODE_TYPES64.TSAbstractMethodDefinition) continue;
|
|
16271
|
+
const name = !member.computed && member.key.type === AST_NODE_TYPES64.Identifier ? member.key.name : null;
|
|
16112
16272
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
16113
16273
|
}
|
|
16114
16274
|
const scopeDefinitions = methods.flatMap((method) => {
|
|
@@ -16117,7 +16277,7 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
16117
16277
|
});
|
|
16118
16278
|
const definitions = methods.flatMap((method) => {
|
|
16119
16279
|
const name = methodName(method);
|
|
16120
|
-
const isPrivate = method.accessibility === "private" || method.key.type ===
|
|
16280
|
+
const isPrivate = method.accessibility === "private" || method.key.type === AST_NODE_TYPES64.PrivateIdentifier;
|
|
16121
16281
|
return name !== null && isPrivate && counts.get(name) === 1 && method.decorators.length === 0 ? [{ name, node: method }] : [];
|
|
16122
16282
|
});
|
|
16123
16283
|
if (definitions.length === 0) return;
|
|
@@ -16126,11 +16286,11 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
16126
16286
|
const pinned = /* @__PURE__ */ new Set();
|
|
16127
16287
|
const classVariables = /* @__PURE__ */ new Set();
|
|
16128
16288
|
if (node.id !== null) {
|
|
16129
|
-
const internal =
|
|
16289
|
+
const internal = ASTUtils22.findVariable(context.sourceCode.getScope(node), node.id.name);
|
|
16130
16290
|
if (internal !== null) classVariables.add(internal);
|
|
16131
16291
|
}
|
|
16132
|
-
if (node.type ===
|
|
16133
|
-
const outer =
|
|
16292
|
+
if (node.type === AST_NODE_TYPES64.ClassExpression && node.parent.type === AST_NODE_TYPES64.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES64.Identifier) {
|
|
16293
|
+
const outer = ASTUtils22.findVariable(context.sourceCode.getScope(node.parent), node.parent.id.name);
|
|
16134
16294
|
if (outer !== null) classVariables.add(outer);
|
|
16135
16295
|
}
|
|
16136
16296
|
for (const method of methods) {
|
|
@@ -16146,27 +16306,27 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
16146
16306
|
}
|
|
16147
16307
|
const thisValue = (value) => {
|
|
16148
16308
|
let current = value;
|
|
16149
|
-
while (current?.type ===
|
|
16150
|
-
return current?.type ===
|
|
16309
|
+
while (current?.type === AST_NODE_TYPES64.TSAsExpression || current?.type === AST_NODE_TYPES64.TSSatisfiesExpression || current?.type === AST_NODE_TYPES64.TSNonNullExpression) current = current.expression;
|
|
16310
|
+
return current?.type === AST_NODE_TYPES64.ThisExpression;
|
|
16151
16311
|
};
|
|
16152
16312
|
const collectAlias = (current, nestedFunction) => {
|
|
16153
|
-
if (nestedFunction || current.type !==
|
|
16154
|
-
if (current.type ===
|
|
16155
|
-
const binding = current.type ===
|
|
16156
|
-
const value = current.type ===
|
|
16313
|
+
if (nestedFunction || current.type !== AST_NODE_TYPES64.VariableDeclarator && current.type !== AST_NODE_TYPES64.AssignmentPattern) return;
|
|
16314
|
+
if (current.type === AST_NODE_TYPES64.VariableDeclarator && (current.parent.type !== AST_NODE_TYPES64.VariableDeclaration || current.parent.kind !== "const")) return;
|
|
16315
|
+
const binding = current.type === AST_NODE_TYPES64.VariableDeclarator ? current.id : current.left;
|
|
16316
|
+
const value = current.type === AST_NODE_TYPES64.VariableDeclarator ? current.init : current.right;
|
|
16157
16317
|
if (!thisValue(value)) return;
|
|
16158
|
-
if (binding.type ===
|
|
16318
|
+
if (binding.type === AST_NODE_TYPES64.ObjectPattern) {
|
|
16159
16319
|
for (const property of binding.properties) {
|
|
16160
|
-
if (property.type ===
|
|
16320
|
+
if (property.type === AST_NODE_TYPES64.RestElement) {
|
|
16161
16321
|
for (const name of privateNames) pinned.add(name);
|
|
16162
|
-
} else if (property.key.type ===
|
|
16322
|
+
} else if (property.key.type === AST_NODE_TYPES64.Identifier && privateNames.has(property.key.name)) {
|
|
16163
16323
|
pinned.add(property.key.name);
|
|
16164
16324
|
}
|
|
16165
16325
|
}
|
|
16166
16326
|
return;
|
|
16167
16327
|
}
|
|
16168
|
-
if (binding.type !==
|
|
16169
|
-
const variable =
|
|
16328
|
+
if (binding.type !== AST_NODE_TYPES64.Identifier) return;
|
|
16329
|
+
const variable = ASTUtils22.findVariable(context.sourceCode.getScope(binding), binding.name);
|
|
16170
16330
|
if (variable !== null) {
|
|
16171
16331
|
methodClassVariables.add(variable);
|
|
16172
16332
|
methodAliases.add(variable);
|
|
@@ -16179,16 +16339,16 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
16179
16339
|
walk2(statement, context.sourceCode.visitorKeys, collectAlias);
|
|
16180
16340
|
}
|
|
16181
16341
|
const visitCall = (current, nestedFunction) => {
|
|
16182
|
-
if (current.type ===
|
|
16342
|
+
if (current.type === AST_NODE_TYPES64.VariableDeclarator && current.id.type === AST_NODE_TYPES64.ObjectPattern && thisValue(current.init)) {
|
|
16183
16343
|
for (const property of current.id.properties) {
|
|
16184
|
-
if (property.type ===
|
|
16344
|
+
if (property.type === AST_NODE_TYPES64.RestElement) {
|
|
16185
16345
|
for (const name of privateNames) pinned.add(name);
|
|
16186
16346
|
continue;
|
|
16187
16347
|
}
|
|
16188
|
-
if (property.type ===
|
|
16348
|
+
if (property.type === AST_NODE_TYPES64.Property && property.key.type === AST_NODE_TYPES64.Identifier && privateNames.has(property.key.name)) pinned.add(property.key.name);
|
|
16189
16349
|
}
|
|
16190
16350
|
}
|
|
16191
|
-
if (current.type !==
|
|
16351
|
+
if (current.type !== AST_NODE_TYPES64.MemberExpression) return;
|
|
16192
16352
|
const target = referencedMethod(context, current, methodClassVariables);
|
|
16193
16353
|
if (target === null) {
|
|
16194
16354
|
const possibleTarget = referencedPropertyName(current);
|
|
@@ -16196,12 +16356,12 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
16196
16356
|
return;
|
|
16197
16357
|
}
|
|
16198
16358
|
if (!privateNames.has(target)) return;
|
|
16199
|
-
const objectVariable = current.object.type ===
|
|
16359
|
+
const objectVariable = current.object.type === AST_NODE_TYPES64.Identifier ? ASTUtils22.findVariable(context.sourceCode.getScope(current.object), current.object.name) : null;
|
|
16200
16360
|
if (objectVariable !== null && methodAliases.has(objectVariable)) {
|
|
16201
16361
|
pinned.add(target);
|
|
16202
16362
|
return;
|
|
16203
16363
|
}
|
|
16204
|
-
if (current.computed || nestedFunction || parameterDecoratorNodes.has(current) || current.parent.type !==
|
|
16364
|
+
if (current.computed || nestedFunction || parameterDecoratorNodes.has(current) || current.parent.type !== AST_NODE_TYPES64.CallExpression || current.parent.callee !== current) {
|
|
16205
16365
|
pinned.add(target);
|
|
16206
16366
|
return;
|
|
16207
16367
|
}
|
|
@@ -16221,9 +16381,9 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
16221
16381
|
}
|
|
16222
16382
|
}
|
|
16223
16383
|
for (const member of node.body.body) {
|
|
16224
|
-
if (member.type ===
|
|
16384
|
+
if (member.type === AST_NODE_TYPES64.MethodDefinition || member.type === AST_NODE_TYPES64.TSAbstractMethodDefinition) continue;
|
|
16225
16385
|
walk2(member, context.sourceCode.visitorKeys, (current) => {
|
|
16226
|
-
if (current.type !==
|
|
16386
|
+
if (current.type !== AST_NODE_TYPES64.MemberExpression) return;
|
|
16227
16387
|
const target = referencedMethod(context, current, classVariables);
|
|
16228
16388
|
const possibleTarget = target ?? referencedPropertyName(current);
|
|
16229
16389
|
if (possibleTarget !== null && privateNames.has(possibleTarget)) pinned.add(possibleTarget);
|
|
@@ -16275,12 +16435,12 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
16275
16435
|
}
|
|
16276
16436
|
function isClassRuntimeBarrier(member) {
|
|
16277
16437
|
switch (member.type) {
|
|
16278
|
-
case
|
|
16438
|
+
case AST_NODE_TYPES64.StaticBlock:
|
|
16279
16439
|
return true;
|
|
16280
|
-
case
|
|
16281
|
-
case
|
|
16440
|
+
case AST_NODE_TYPES64.PropertyDefinition:
|
|
16441
|
+
case AST_NODE_TYPES64.AccessorProperty:
|
|
16282
16442
|
return member.static || member.computed || member.decorators.length > 0 || member.value !== null;
|
|
16283
|
-
case
|
|
16443
|
+
case AST_NODE_TYPES64.MethodDefinition:
|
|
16284
16444
|
return member.computed || member.decorators.length > 0;
|
|
16285
16445
|
default:
|
|
16286
16446
|
return false;
|
|
@@ -16313,7 +16473,7 @@ var stepdown_default = createRule({
|
|
|
16313
16473
|
moduleScope(context, program);
|
|
16314
16474
|
const computedReferenceNames = /* @__PURE__ */ new Set();
|
|
16315
16475
|
walk2(program, context.sourceCode.visitorKeys, (node) => {
|
|
16316
|
-
if (node.type ===
|
|
16476
|
+
if (node.type === AST_NODE_TYPES64.MemberExpression && node.computed && node.property.type === AST_NODE_TYPES64.Literal && typeof node.property.value === "string") computedReferenceNames.add(node.property.value);
|
|
16317
16477
|
});
|
|
16318
16478
|
for (const node of classes) classScope(context, node, computedReferenceNames);
|
|
16319
16479
|
}
|
|
@@ -16322,7 +16482,7 @@ var stepdown_default = createRule({
|
|
|
16322
16482
|
});
|
|
16323
16483
|
|
|
16324
16484
|
// src/rules/source-coupled-test.ts
|
|
16325
|
-
import { AST_NODE_TYPES as
|
|
16485
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES65 } from "@typescript-eslint/utils";
|
|
16326
16486
|
var GENERAL_SOURCE_SUFFIX_RE = /\.(?:bash|sh|ya?ml|jsonc|py|[cm]?[jt]s)$/iu;
|
|
16327
16487
|
var FS_MODULES = /* @__PURE__ */ new Set(["fs", "node:fs", "fs/promises", "node:fs/promises"]);
|
|
16328
16488
|
var FS_READERS = /* @__PURE__ */ new Set(["readFile", "readFileSync"]);
|
|
@@ -16391,20 +16551,20 @@ var SOURCE_COUPLED_TEST_DOCUMENTATION = {
|
|
|
16391
16551
|
]
|
|
16392
16552
|
};
|
|
16393
16553
|
function staticMemberName7(node) {
|
|
16394
|
-
if (!node.computed && node.property.type ===
|
|
16395
|
-
if (node.computed && node.property.type ===
|
|
16554
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES65.Identifier) return node.property.name;
|
|
16555
|
+
if (node.computed && node.property.type === AST_NODE_TYPES65.Literal && typeof node.property.value === "string") return node.property.value;
|
|
16396
16556
|
return null;
|
|
16397
16557
|
}
|
|
16398
16558
|
function unwrap5(node) {
|
|
16399
|
-
if (node.type ===
|
|
16400
|
-
if (node.type ===
|
|
16401
|
-
if (node.type ===
|
|
16559
|
+
if (node.type === AST_NODE_TYPES65.AwaitExpression) return unwrap5(node.argument);
|
|
16560
|
+
if (node.type === AST_NODE_TYPES65.ChainExpression) return unwrap5(node.expression);
|
|
16561
|
+
if (node.type === AST_NODE_TYPES65.TSAsExpression || node.type === AST_NODE_TYPES65.TSNonNullExpression || node.type === AST_NODE_TYPES65.TSTypeAssertion) return unwrap5(node.expression);
|
|
16402
16562
|
return node;
|
|
16403
16563
|
}
|
|
16404
16564
|
function stringValue(node) {
|
|
16405
16565
|
const current = unwrap5(node);
|
|
16406
|
-
if (current.type ===
|
|
16407
|
-
if (current.type ===
|
|
16566
|
+
if (current.type === AST_NODE_TYPES65.Literal && typeof current.value === "string") return current.value;
|
|
16567
|
+
if (current.type === AST_NODE_TYPES65.TemplateLiteral && current.expressions.length === 0) return current.quasis[0]?.value.cooked ?? null;
|
|
16408
16568
|
return null;
|
|
16409
16569
|
}
|
|
16410
16570
|
function importSource(node) {
|
|
@@ -16412,7 +16572,7 @@ function importSource(node) {
|
|
|
16412
16572
|
}
|
|
16413
16573
|
function requireSource(node) {
|
|
16414
16574
|
const current = unwrap5(node);
|
|
16415
|
-
if (current.type !==
|
|
16575
|
+
if (current.type !== AST_NODE_TYPES65.CallExpression || current.callee.type !== AST_NODE_TYPES65.Identifier || current.callee.name !== "require" || current.arguments.length !== 1 || current.arguments[0]?.type === AST_NODE_TYPES65.SpreadElement) return null;
|
|
16416
16576
|
return stringValue(current.arguments[0]);
|
|
16417
16577
|
}
|
|
16418
16578
|
function newScope() {
|
|
@@ -16452,38 +16612,38 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
16452
16612
|
const current = unwrap5(node);
|
|
16453
16613
|
const value = stringValue(current);
|
|
16454
16614
|
if (value !== null) return sourceSuffixRe.test(value);
|
|
16455
|
-
if (current.type ===
|
|
16456
|
-
if (current.type ===
|
|
16615
|
+
if (current.type === AST_NODE_TYPES65.Identifier) return visible("paths", current.name);
|
|
16616
|
+
if (current.type === AST_NODE_TYPES65.BinaryExpression && current.operator === "+") {
|
|
16457
16617
|
return sourcePath(current.left) || sourcePath(current.right);
|
|
16458
16618
|
}
|
|
16459
|
-
if (current.type ===
|
|
16460
|
-
if (current.type ===
|
|
16461
|
-
return current.arguments.some((argument) => argument.type !==
|
|
16619
|
+
if (current.type === AST_NODE_TYPES65.TemplateLiteral) return current.expressions.some(sourcePath);
|
|
16620
|
+
if (current.type === AST_NODE_TYPES65.CallExpression || current.type === AST_NODE_TYPES65.NewExpression) {
|
|
16621
|
+
return current.arguments.some((argument) => argument.type !== AST_NODE_TYPES65.SpreadElement && sourcePath(argument));
|
|
16462
16622
|
}
|
|
16463
|
-
if (current.type ===
|
|
16623
|
+
if (current.type === AST_NODE_TYPES65.MemberExpression) return sourcePath(current.object);
|
|
16464
16624
|
return false;
|
|
16465
16625
|
};
|
|
16466
16626
|
const rawRead = (node) => {
|
|
16467
16627
|
const current = unwrap5(node);
|
|
16468
|
-
if (current.type !==
|
|
16628
|
+
if (current.type !== AST_NODE_TYPES65.CallExpression || current.arguments.length === 0) return false;
|
|
16469
16629
|
const callee = unwrap5(current.callee);
|
|
16470
|
-
if (callee.type ===
|
|
16630
|
+
if (callee.type === AST_NODE_TYPES65.Identifier) {
|
|
16471
16631
|
return visible("fsReaders", callee.name) && sourcePath(current.arguments[0]);
|
|
16472
16632
|
}
|
|
16473
|
-
if (callee.type !==
|
|
16633
|
+
if (callee.type !== AST_NODE_TYPES65.MemberExpression) return false;
|
|
16474
16634
|
const name2 = staticMemberName7(callee);
|
|
16475
16635
|
const object = unwrap5(callee.object);
|
|
16476
|
-
return name2 !== null && FS_READERS.has(name2) && object.type ===
|
|
16636
|
+
return name2 !== null && FS_READERS.has(name2) && object.type === AST_NODE_TYPES65.Identifier && visible("fsObjects", object.name) && sourcePath(current.arguments[0]);
|
|
16477
16637
|
};
|
|
16478
16638
|
const rawOrigins = (node) => {
|
|
16479
16639
|
const current = unwrap5(node);
|
|
16480
|
-
if (current.type ===
|
|
16640
|
+
if (current.type === AST_NODE_TYPES65.Identifier) return visibleRawOrigins(current.name);
|
|
16481
16641
|
if (rawRead(current)) return /* @__PURE__ */ new Set([`${current.range[0]}:${current.range[1]}`]);
|
|
16482
|
-
if (current.type ===
|
|
16483
|
-
if (current.type ===
|
|
16484
|
-
if (current.type !==
|
|
16642
|
+
if (current.type === AST_NODE_TYPES65.BinaryExpression && current.operator === "+") return /* @__PURE__ */ new Set([...rawOrigins(current.left), ...rawOrigins(current.right)]);
|
|
16643
|
+
if (current.type === AST_NODE_TYPES65.MemberExpression && staticMemberName7(current) === "length") return rawOrigins(current.object);
|
|
16644
|
+
if (current.type !== AST_NODE_TYPES65.CallExpression) return /* @__PURE__ */ new Set();
|
|
16485
16645
|
const callee = unwrap5(current.callee);
|
|
16486
|
-
if (callee.type !==
|
|
16646
|
+
if (callee.type !== AST_NODE_TYPES65.MemberExpression) return /* @__PURE__ */ new Set();
|
|
16487
16647
|
const name2 = staticMemberName7(callee);
|
|
16488
16648
|
return name2 !== null && TEXT_TRANSFORMS.has(name2) ? rawOrigins(callee.object) : /* @__PURE__ */ new Set();
|
|
16489
16649
|
};
|
|
@@ -16491,38 +16651,38 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
16491
16651
|
const current = unwrap5(node);
|
|
16492
16652
|
const direct = rawOrigins(current);
|
|
16493
16653
|
if (direct.size > 0) return direct;
|
|
16494
|
-
if (current.type ===
|
|
16495
|
-
if (current.type ===
|
|
16496
|
-
if (current.type !==
|
|
16654
|
+
if (current.type === AST_NODE_TYPES65.BinaryExpression || current.type === AST_NODE_TYPES65.LogicalExpression) return /* @__PURE__ */ new Set([...evidenceOrigins(current.left), ...evidenceOrigins(current.right)]);
|
|
16655
|
+
if (current.type === AST_NODE_TYPES65.UnaryExpression) return evidenceOrigins(current.argument);
|
|
16656
|
+
if (current.type !== AST_NODE_TYPES65.CallExpression) return /* @__PURE__ */ new Set();
|
|
16497
16657
|
const callee = unwrap5(current.callee);
|
|
16498
|
-
if (callee.type !==
|
|
16658
|
+
if (callee.type !== AST_NODE_TYPES65.MemberExpression) return /* @__PURE__ */ new Set();
|
|
16499
16659
|
const name2 = staticMemberName7(callee);
|
|
16500
16660
|
if (name2 !== null && TEXT_PREDICATES.has(name2)) return rawOrigins(callee.object);
|
|
16501
|
-
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type ===
|
|
16661
|
+
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES65.SpreadElement ? [] : [...rawOrigins(argument)]));
|
|
16502
16662
|
return /* @__PURE__ */ new Set();
|
|
16503
16663
|
};
|
|
16504
16664
|
const rawAssertionOrigins = (node) => {
|
|
16505
16665
|
const callee = unwrap5(node.callee);
|
|
16506
|
-
if (callee.type ===
|
|
16507
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
16666
|
+
if (callee.type === AST_NODE_TYPES65.Identifier && callee.name === "assert") {
|
|
16667
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES65.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
16508
16668
|
}
|
|
16509
|
-
if (callee.type !==
|
|
16669
|
+
if (callee.type !== AST_NODE_TYPES65.MemberExpression) return /* @__PURE__ */ new Set();
|
|
16510
16670
|
const matcher = staticMemberName7(callee);
|
|
16511
16671
|
if (matcher === null) return /* @__PURE__ */ new Set();
|
|
16512
16672
|
let receiver = unwrap5(callee.object);
|
|
16513
|
-
while (receiver.type ===
|
|
16514
|
-
if (receiver.type ===
|
|
16673
|
+
while (receiver.type === AST_NODE_TYPES65.MemberExpression && EXPECT_MODIFIERS2.has(staticMemberName7(receiver) ?? "")) receiver = unwrap5(receiver.object);
|
|
16674
|
+
if (receiver.type === AST_NODE_TYPES65.CallExpression && receiver.callee.type === AST_NODE_TYPES65.Identifier && receiver.callee.name === "expect") {
|
|
16515
16675
|
if (!EXPECT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
16516
|
-
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type ===
|
|
16676
|
+
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type === AST_NODE_TYPES65.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
16517
16677
|
}
|
|
16518
|
-
if (receiver.type !==
|
|
16519
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
16678
|
+
if (receiver.type !== AST_NODE_TYPES65.Identifier || receiver.name !== "assert" || !ASSERT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
16679
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES65.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
16520
16680
|
};
|
|
16521
16681
|
const rawRegexExtractionOrigins = (node) => {
|
|
16522
16682
|
const callee = unwrap5(node.callee);
|
|
16523
|
-
if (callee.type !==
|
|
16683
|
+
if (callee.type !== AST_NODE_TYPES65.MemberExpression || staticMemberName7(callee) !== "matchAll" || node.arguments.length !== 1) return /* @__PURE__ */ new Set();
|
|
16524
16684
|
const argument = node.arguments[0];
|
|
16525
|
-
if (argument?.type !==
|
|
16685
|
+
if (argument?.type !== AST_NODE_TYPES65.Literal || !(argument.value instanceof RegExp)) return /* @__PURE__ */ new Set();
|
|
16526
16686
|
return rawOrigins(callee.object);
|
|
16527
16687
|
};
|
|
16528
16688
|
const declare = (name2, state) => {
|
|
@@ -16543,15 +16703,15 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
16543
16703
|
};
|
|
16544
16704
|
const sourceCollection = (node) => {
|
|
16545
16705
|
const current = unwrap5(node);
|
|
16546
|
-
return current.type ===
|
|
16706
|
+
return current.type === AST_NODE_TYPES65.ArrayExpression && current.elements.length > 0 && current.elements.every((element) => element !== null && element.type !== AST_NODE_TYPES65.SpreadElement && sourcePath(element));
|
|
16547
16707
|
};
|
|
16548
16708
|
const declaredNames2 = (node) => {
|
|
16549
16709
|
const current = unwrap5(node);
|
|
16550
|
-
if (current.type ===
|
|
16551
|
-
if (current.type ===
|
|
16552
|
-
if (current.type ===
|
|
16553
|
-
if (current.type ===
|
|
16554
|
-
if (current.type ===
|
|
16710
|
+
if (current.type === AST_NODE_TYPES65.Identifier) return [current.name];
|
|
16711
|
+
if (current.type === AST_NODE_TYPES65.AssignmentPattern) return declaredNames2(current.left);
|
|
16712
|
+
if (current.type === AST_NODE_TYPES65.RestElement) return declaredNames2(current.argument);
|
|
16713
|
+
if (current.type === AST_NODE_TYPES65.ArrayPattern) return current.elements.flatMap((element) => element === null ? [] : declaredNames2(element));
|
|
16714
|
+
if (current.type === AST_NODE_TYPES65.ObjectPattern) return current.properties.flatMap((property) => property.type === AST_NODE_TYPES65.RestElement ? declaredNames2(property.argument) : declaredNames2(property.value));
|
|
16555
16715
|
return [];
|
|
16556
16716
|
};
|
|
16557
16717
|
const enterFunction = (node) => {
|
|
@@ -16566,8 +16726,8 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
16566
16726
|
const source = importSource(node);
|
|
16567
16727
|
if (source === null || !FS_MODULES.has(source)) return;
|
|
16568
16728
|
for (const specifier of node.specifiers) {
|
|
16569
|
-
if (specifier.type ===
|
|
16570
|
-
const imported = specifier.imported.type ===
|
|
16729
|
+
if (specifier.type === AST_NODE_TYPES65.ImportSpecifier) {
|
|
16730
|
+
const imported = specifier.imported.type === AST_NODE_TYPES65.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
16571
16731
|
if (FS_READERS.has(imported)) declare(specifier.local.name, { fsReader: true });
|
|
16572
16732
|
} else {
|
|
16573
16733
|
declare(specifier.local.name, { fsObject: true });
|
|
@@ -16579,29 +16739,29 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
16579
16739
|
VariableDeclarator(node) {
|
|
16580
16740
|
if (node.init === null) return;
|
|
16581
16741
|
const required = requireSource(node.init);
|
|
16582
|
-
if (required !== null && FS_MODULES.has(required) && node.id.type ===
|
|
16742
|
+
if (required !== null && FS_MODULES.has(required) && node.id.type === AST_NODE_TYPES65.Identifier) {
|
|
16583
16743
|
declare(node.id.name, { fsObject: true });
|
|
16584
16744
|
return;
|
|
16585
16745
|
}
|
|
16586
|
-
if (node.id.type ===
|
|
16746
|
+
if (node.id.type === AST_NODE_TYPES65.ObjectPattern && required !== null && FS_MODULES.has(required)) {
|
|
16587
16747
|
for (const property of node.id.properties) {
|
|
16588
|
-
if (property.type !==
|
|
16589
|
-
const key = property.key.type ===
|
|
16748
|
+
if (property.type !== AST_NODE_TYPES65.Property || property.value.type !== AST_NODE_TYPES65.Identifier) continue;
|
|
16749
|
+
const key = property.key.type === AST_NODE_TYPES65.Identifier ? property.key.name : property.key.type === AST_NODE_TYPES65.Literal ? String(property.key.value) : "";
|
|
16590
16750
|
if (FS_READERS.has(key)) declare(property.value.name, { fsReader: true });
|
|
16591
16751
|
}
|
|
16592
16752
|
return;
|
|
16593
16753
|
}
|
|
16594
|
-
if (node.id.type !==
|
|
16754
|
+
if (node.id.type !== AST_NODE_TYPES65.Identifier) return;
|
|
16595
16755
|
declare(node.id.name, { collection: sourceCollection(node.init), path: sourcePath(node.init), rawOrigins: rawOrigins(node.init) });
|
|
16596
16756
|
},
|
|
16597
16757
|
AssignmentExpression(node) {
|
|
16598
|
-
if (node.left.type ===
|
|
16758
|
+
if (node.left.type === AST_NODE_TYPES65.Identifier) declare(node.left.name, { path: sourcePath(node.right), rawOrigins: rawOrigins(node.right) });
|
|
16599
16759
|
},
|
|
16600
16760
|
ForOfStatement(node) {
|
|
16601
16761
|
const right = unwrap5(node.right);
|
|
16602
|
-
const collection = right.type ===
|
|
16603
|
-
const left = node.left.type ===
|
|
16604
|
-
if (collection && left?.type ===
|
|
16762
|
+
const collection = right.type === AST_NODE_TYPES65.Identifier && visible("collections", right.name);
|
|
16763
|
+
const left = node.left.type === AST_NODE_TYPES65.VariableDeclaration ? node.left.declarations[0]?.id : node.left;
|
|
16764
|
+
if (collection && left?.type === AST_NODE_TYPES65.Identifier) declare(left.name, { path: true });
|
|
16605
16765
|
},
|
|
16606
16766
|
CallExpression(node) {
|
|
16607
16767
|
const origins = /* @__PURE__ */ new Set([
|
|
@@ -16662,8 +16822,8 @@ var iac_source_coupled_test_default = createSourceCoupledRule(
|
|
|
16662
16822
|
|
|
16663
16823
|
// src/rules/require-pascal-case-zod-schema-name.ts
|
|
16664
16824
|
import {
|
|
16665
|
-
AST_NODE_TYPES as
|
|
16666
|
-
ASTUtils as
|
|
16825
|
+
AST_NODE_TYPES as AST_NODE_TYPES66,
|
|
16826
|
+
ASTUtils as ASTUtils23
|
|
16667
16827
|
} from "@typescript-eslint/utils";
|
|
16668
16828
|
var REQUIRE_PASCAL_CASE_ZOD_SCHEMA_NAME_DOCUMENTATION = {
|
|
16669
16829
|
summary: "Require confirmed module-level Zod schema contracts to use PascalCase with a `Schema` suffix.",
|
|
@@ -16796,18 +16956,18 @@ var SCHEMA_RETURNING_METHODS = /* @__PURE__ */ new Set([
|
|
|
16796
16956
|
"superRefine",
|
|
16797
16957
|
"transform"
|
|
16798
16958
|
]);
|
|
16799
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
16959
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === AST_NODE_TYPES66.Identifier ? callee.property.name : null;
|
|
16800
16960
|
var calleeChainRoot = (node) => {
|
|
16801
16961
|
let current = node;
|
|
16802
16962
|
for (; ; ) {
|
|
16803
|
-
if (current.type ===
|
|
16963
|
+
if (current.type === AST_NODE_TYPES66.Identifier) {
|
|
16804
16964
|
return current;
|
|
16805
16965
|
}
|
|
16806
|
-
if (current.type ===
|
|
16966
|
+
if (current.type === AST_NODE_TYPES66.MemberExpression) {
|
|
16807
16967
|
current = current.object;
|
|
16808
16968
|
continue;
|
|
16809
16969
|
}
|
|
16810
|
-
if (current.type ===
|
|
16970
|
+
if (current.type === AST_NODE_TYPES66.CallExpression) {
|
|
16811
16971
|
current = current.callee;
|
|
16812
16972
|
continue;
|
|
16813
16973
|
}
|
|
@@ -16818,13 +16978,13 @@ var chainMemberNames = (node) => {
|
|
|
16818
16978
|
const names = [];
|
|
16819
16979
|
let current = node;
|
|
16820
16980
|
for (; ; ) {
|
|
16821
|
-
if (current.type ===
|
|
16822
|
-
if (current.computed || current.property.type !==
|
|
16981
|
+
if (current.type === AST_NODE_TYPES66.MemberExpression) {
|
|
16982
|
+
if (current.computed || current.property.type !== AST_NODE_TYPES66.Identifier) return [];
|
|
16823
16983
|
names.push(current.property.name);
|
|
16824
16984
|
current = current.object;
|
|
16825
16985
|
continue;
|
|
16826
16986
|
}
|
|
16827
|
-
if (current.type ===
|
|
16987
|
+
if (current.type === AST_NODE_TYPES66.CallExpression) {
|
|
16828
16988
|
current = current.callee;
|
|
16829
16989
|
continue;
|
|
16830
16990
|
}
|
|
@@ -16835,16 +16995,16 @@ var chainMemberNames = (node) => {
|
|
|
16835
16995
|
};
|
|
16836
16996
|
var unwrapExpression4 = (node) => {
|
|
16837
16997
|
let current = node;
|
|
16838
|
-
while (current.type ===
|
|
16998
|
+
while (current.type === AST_NODE_TYPES66.TSAsExpression || current.type === AST_NODE_TYPES66.TSSatisfiesExpression || current.type === AST_NODE_TYPES66.TSNonNullExpression || current.type === AST_NODE_TYPES66.TSTypeAssertion) {
|
|
16839
16999
|
current = current.expression;
|
|
16840
17000
|
}
|
|
16841
17001
|
return current;
|
|
16842
17002
|
};
|
|
16843
17003
|
var isModuleDeclarator = (node) => {
|
|
16844
17004
|
const declaration = node.parent;
|
|
16845
|
-
if (declaration.type !==
|
|
17005
|
+
if (declaration.type !== AST_NODE_TYPES66.VariableDeclaration) return false;
|
|
16846
17006
|
const owner = declaration.parent;
|
|
16847
|
-
return owner.type ===
|
|
17007
|
+
return owner.type === AST_NODE_TYPES66.Program || owner.type === AST_NODE_TYPES66.ExportNamedDeclaration && owner.parent.type === AST_NODE_TYPES66.Program;
|
|
16848
17008
|
};
|
|
16849
17009
|
var require_pascal_case_zod_schema_name_default = createRule({
|
|
16850
17010
|
name: "require-pascal-case-zod-schema-name",
|
|
@@ -16864,7 +17024,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
16864
17024
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
16865
17025
|
const schemaBindings = /* @__PURE__ */ new Set();
|
|
16866
17026
|
function resolvedBinding(identifier) {
|
|
16867
|
-
return
|
|
17027
|
+
return ASTUtils23.findVariable(
|
|
16868
17028
|
context.sourceCode.getScope(identifier),
|
|
16869
17029
|
identifier.name
|
|
16870
17030
|
);
|
|
@@ -16885,8 +17045,8 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
16885
17045
|
}
|
|
16886
17046
|
function isConfirmedSchema(expression) {
|
|
16887
17047
|
const init = unwrapExpression4(expression);
|
|
16888
|
-
if (init.type ===
|
|
16889
|
-
if (init.type !==
|
|
17048
|
+
if (init.type === AST_NODE_TYPES66.Identifier) return isSchemaBinding(init);
|
|
17049
|
+
if (init.type !== AST_NODE_TYPES66.CallExpression || init.callee.type !== AST_NODE_TYPES66.MemberExpression) {
|
|
16890
17050
|
return false;
|
|
16891
17051
|
}
|
|
16892
17052
|
const terminal = terminalMethodName(init.callee);
|
|
@@ -16906,7 +17066,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
16906
17066
|
ImportDeclaration(node) {
|
|
16907
17067
|
if (!isZodModule(node.source.value)) return;
|
|
16908
17068
|
for (const specifier of node.specifiers) {
|
|
16909
|
-
if (specifier.type ===
|
|
17069
|
+
if (specifier.type === AST_NODE_TYPES66.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES66.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES66.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES66.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
16910
17070
|
recordZodBinding(specifier.local);
|
|
16911
17071
|
}
|
|
16912
17072
|
}
|
|
@@ -16915,7 +17075,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
16915
17075
|
if (!isModuleDeclarator(node)) return;
|
|
16916
17076
|
const init = node.init;
|
|
16917
17077
|
if (init === null || init === void 0) return;
|
|
16918
|
-
if (node.id.type !==
|
|
17078
|
+
if (node.id.type !== AST_NODE_TYPES66.Identifier) return;
|
|
16919
17079
|
if (!isConfirmedSchema(init)) return;
|
|
16920
17080
|
const binding = resolvedBinding(node.id);
|
|
16921
17081
|
if (binding !== null) schemaBindings.add(binding);
|
|
@@ -17075,6 +17235,7 @@ var RULES = {
|
|
|
17075
17235
|
"prefer-module-level-schema": prefer_module_level_schema_default,
|
|
17076
17236
|
"prefer-native-random-uuid": prefer_native_random_uuid_default,
|
|
17077
17237
|
"prefer-non-nullable-collection": prefer_non_nullable_collection_default,
|
|
17238
|
+
"prefer-nullish-filter-predicate": prefer_nullish_filter_predicate_default,
|
|
17078
17239
|
"prefer-await-in-async-return": prefer_await_in_async_return_default,
|
|
17079
17240
|
"prefer-schema-for-api-payload": prefer_schema_for_api_payload_default,
|
|
17080
17241
|
"prefer-semantic-colors": prefer_semantic_colors_default,
|
|
@@ -17094,7 +17255,7 @@ var RULES = {
|
|
|
17094
17255
|
};
|
|
17095
17256
|
var meta = {
|
|
17096
17257
|
name: "@sarj/eslint-plugin",
|
|
17097
|
-
version: "15.
|
|
17258
|
+
version: "15.14.0"
|
|
17098
17259
|
};
|
|
17099
17260
|
var APPLICATION_ONLY_RULES = [
|
|
17100
17261
|
"no-restricted-library-load",
|
|
@@ -17156,6 +17317,7 @@ var RECOMMENDED_RULES = {
|
|
|
17156
17317
|
"@sarj/prefer-module-level-constant": "error",
|
|
17157
17318
|
"@sarj/prefer-module-level-schema": "error",
|
|
17158
17319
|
"@sarj/prefer-non-nullable-collection": "error",
|
|
17320
|
+
"@sarj/prefer-nullish-filter-predicate": "error",
|
|
17159
17321
|
"@sarj/prefer-await-in-async-return": "error",
|
|
17160
17322
|
"@sarj/prefer-schema-for-api-payload": "error",
|
|
17161
17323
|
"@sarj/prefer-semantic-colors": ["error", { requireSemanticTokens: true }],
|
|
@@ -17234,6 +17396,7 @@ var STRICT_RULES = {
|
|
|
17234
17396
|
"@sarj/prefer-module-level-constant": "error",
|
|
17235
17397
|
"@sarj/prefer-module-level-schema": "error",
|
|
17236
17398
|
"@sarj/prefer-non-nullable-collection": "error",
|
|
17399
|
+
"@sarj/prefer-nullish-filter-predicate": "error",
|
|
17237
17400
|
"@sarj/prefer-await-in-async-return": "error",
|
|
17238
17401
|
"@sarj/prefer-schema-for-api-payload": "error",
|
|
17239
17402
|
"@sarj/prefer-semantic-colors": ["error", { requireSemanticTokens: true }],
|