@sarj/eslint-plugin 16.20.0 → 16.20.2
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 +1443 -1239
- package/dist/index.js +425 -222
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// package.json
|
|
2
2
|
var package_default = {
|
|
3
3
|
name: "@sarj/eslint-plugin",
|
|
4
|
-
version: "16.20.
|
|
4
|
+
version: "16.20.2",
|
|
5
5
|
packageManager: "npm@12.2.0",
|
|
6
6
|
description: "Custom ESLint rules for hypermodern TypeScript / React / Next.js projects",
|
|
7
7
|
type: "module",
|
|
@@ -83,16 +83,17 @@ var package_default = {
|
|
|
83
83
|
"eslint-plugin-react": "^7.37.5",
|
|
84
84
|
"eslint-plugin-react-hooks": "^7.1.1",
|
|
85
85
|
"eslint-plugin-simple-import-sort": "^14.0.0",
|
|
86
|
+
"eslint-plugin-sonarjs": "4.2.2",
|
|
86
87
|
"eslint-plugin-testing-library": "7.16.2",
|
|
87
88
|
"eslint-plugin-unicorn": "^78.0.0",
|
|
88
89
|
"eslint-plugin-zod": "^5.0.1",
|
|
89
90
|
globals: "17.13.0",
|
|
91
|
+
jiti: "2.7.0",
|
|
90
92
|
tsup: "8.5.1",
|
|
91
93
|
typescript: "npm:@typescript/typescript6@6.0.2",
|
|
92
94
|
"typescript-eslint": "^8.71.2",
|
|
93
95
|
vitest: "5.0.4",
|
|
94
|
-
zod: "4.6.7"
|
|
95
|
-
jiti: "2.7.0"
|
|
96
|
+
zod: "4.6.7"
|
|
96
97
|
},
|
|
97
98
|
peerDependencies: {
|
|
98
99
|
eslint: ">=9.39.4",
|
|
@@ -10427,8 +10428,8 @@ var no_bespoke_api_case_conversion_default = createRule({
|
|
|
10427
10428
|
let typeName = annotation.typeName;
|
|
10428
10429
|
while (typeName.type === AST_NODE_TYPES50.TSQualifiedName) typeName = typeName.left;
|
|
10429
10430
|
if (typeName.type !== AST_NODE_TYPES50.Identifier) return false;
|
|
10430
|
-
const
|
|
10431
|
-
return
|
|
10431
|
+
const typeBinding2 = ASTUtils28.findVariable(context.sourceCode.getScope(typeName), typeName.name);
|
|
10432
|
+
return typeBinding2?.defs.length === 1 && typeBinding2.defs[0]?.type === "ImportBinding" && typeBinding2.defs[0].parent.type === AST_NODE_TYPES50.ImportDeclaration && API_BOUNDARY_IMPORT_RE.test(typeBinding2.defs[0].parent.source.value);
|
|
10432
10433
|
};
|
|
10433
10434
|
return {
|
|
10434
10435
|
Property(node) {
|
|
@@ -16044,9 +16045,24 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
16044
16045
|
|
|
16045
16046
|
// src/rules/no-unsafe-mock-casting.ts
|
|
16046
16047
|
import {
|
|
16047
|
-
AST_NODE_TYPES as AST_NODE_TYPES72
|
|
16048
|
-
ASTUtils as ASTUtils42
|
|
16048
|
+
AST_NODE_TYPES as AST_NODE_TYPES72
|
|
16049
16049
|
} from "@typescript-eslint/utils";
|
|
16050
|
+
|
|
16051
|
+
// src/rules/_type-binding.ts
|
|
16052
|
+
import "@typescript-eslint/utils";
|
|
16053
|
+
function typeBinding(source, identifier) {
|
|
16054
|
+
let scope = source.getScope(identifier);
|
|
16055
|
+
while (scope !== null) {
|
|
16056
|
+
const variable = scope.set.get(identifier.name);
|
|
16057
|
+
if (variable !== void 0 && (variable.isTypeVariable || variable.defs.some((definition) => definition.isTypeDefinition))) {
|
|
16058
|
+
return variable;
|
|
16059
|
+
}
|
|
16060
|
+
scope = scope.upper;
|
|
16061
|
+
}
|
|
16062
|
+
return null;
|
|
16063
|
+
}
|
|
16064
|
+
|
|
16065
|
+
// src/rules/no-unsafe-mock-casting.ts
|
|
16050
16066
|
var MOCK_TYPE_NAMES = /* @__PURE__ */ new Set([
|
|
16051
16067
|
"Mock",
|
|
16052
16068
|
"Mocked",
|
|
@@ -16112,10 +16128,7 @@ var no_unsafe_mock_casting_default = createRule({
|
|
|
16112
16128
|
const directBindings = /* @__PURE__ */ new Set();
|
|
16113
16129
|
const namespaceBindings = /* @__PURE__ */ new Set();
|
|
16114
16130
|
function resolve2(identifier) {
|
|
16115
|
-
return
|
|
16116
|
-
context.sourceCode.getScope(identifier),
|
|
16117
|
-
identifier.name
|
|
16118
|
-
);
|
|
16131
|
+
return typeBinding(context.sourceCode, identifier);
|
|
16119
16132
|
}
|
|
16120
16133
|
function record(identifier, destination) {
|
|
16121
16134
|
const binding = resolve2(identifier);
|
|
@@ -16159,7 +16172,7 @@ var no_unsafe_mock_casting_default = createRule({
|
|
|
16159
16172
|
});
|
|
16160
16173
|
|
|
16161
16174
|
// src/rules/no-unsafe-test-double-cast.ts
|
|
16162
|
-
import { ASTUtils as
|
|
16175
|
+
import { ASTUtils as ASTUtils42, AST_NODE_TYPES as AST_NODE_TYPES73 } from "@typescript-eslint/utils";
|
|
16163
16176
|
var NO_UNSAFE_TEST_DOUBLE_CAST_DOCUMENTATION = {
|
|
16164
16177
|
summary: "Disallow mock-backed test doubles that bypass collaborator contracts through double assertions.",
|
|
16165
16178
|
rationale: "Casting a partial object through unknown hides missing or stale collaborator members, so production interface changes can compile while the test double silently drifts.",
|
|
@@ -16189,7 +16202,7 @@ function isMockFactory(node, source) {
|
|
|
16189
16202
|
const unwrappedNodeCallee = node.type === "CallExpression" || node.type === "NewExpression" ? unwrapExpression(node.callee) : null;
|
|
16190
16203
|
if (node.type !== AST_NODE_TYPES73.CallExpression || unwrappedNodeCallee?.type !== AST_NODE_TYPES73.MemberExpression) return false;
|
|
16191
16204
|
const receiver = unwrapExpression(unwrappedNodeCallee.object);
|
|
16192
|
-
return node.type === AST_NODE_TYPES73.CallExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES73.MemberExpression && receiver.type === AST_NODE_TYPES73.Identifier && (importedTestMockNamespace(source, receiver) !== null || isUnshadowedTestMockGlobal(source, receiver)) &&
|
|
16205
|
+
return node.type === AST_NODE_TYPES73.CallExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES73.MemberExpression && receiver.type === AST_NODE_TYPES73.Identifier && (importedTestMockNamespace(source, receiver) !== null || isUnshadowedTestMockGlobal(source, receiver)) && ASTUtils42.getPropertyName(unwrappedNodeCallee) !== null && ["fn", "spyOn"].includes(ASTUtils42.getPropertyName(unwrappedNodeCallee) ?? "");
|
|
16193
16206
|
}
|
|
16194
16207
|
var no_unsafe_test_double_cast_default = createRule({
|
|
16195
16208
|
name: "no-unsafe-test-double-cast",
|
|
@@ -16215,7 +16228,7 @@ var no_unsafe_test_double_cast_default = createRule({
|
|
|
16215
16228
|
});
|
|
16216
16229
|
|
|
16217
16230
|
// src/rules/no-first-party-module-mock.ts
|
|
16218
|
-
import { ASTUtils as
|
|
16231
|
+
import { ASTUtils as ASTUtils43, AST_NODE_TYPES as AST_NODE_TYPES74 } from "@typescript-eslint/utils";
|
|
16219
16232
|
var NO_FIRST_PARTY_MODULE_MOCK_DOCUMENTATION = {
|
|
16220
16233
|
summary: "Prefer injected collaborators over mocking maintained first-party modules in tests.",
|
|
16221
16234
|
rationale: "Replacing an owned module couples tests to its lookup path and can verify mock wiring while bypassing the real implementation contract.",
|
|
@@ -16246,7 +16259,7 @@ var no_first_party_module_mock_default = createRule({
|
|
|
16246
16259
|
CallExpression(node) {
|
|
16247
16260
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
16248
16261
|
const receiver = unwrappedNodeCallee.type === AST_NODE_TYPES74.MemberExpression ? unwrapExpression(unwrappedNodeCallee.object) : unwrappedNodeCallee;
|
|
16249
|
-
if (unwrappedNodeCallee.type !== AST_NODE_TYPES74.MemberExpression || receiver.type !== AST_NODE_TYPES74.Identifier ||
|
|
16262
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES74.MemberExpression || receiver.type !== AST_NODE_TYPES74.Identifier || ASTUtils43.getPropertyName(unwrappedNodeCallee) === null || !["mock", "doMock"].includes(ASTUtils43.getPropertyName(unwrappedNodeCallee) ?? "")) return;
|
|
16250
16263
|
const framework = importedTestMockNamespace(context.sourceCode, receiver);
|
|
16251
16264
|
if (framework === null || framework === "jest" && mayBeVirtual(node.arguments[2])) return;
|
|
16252
16265
|
const argument = node.arguments[0] === void 0 ? void 0 : unwrapExpression(node.arguments[0]);
|
|
@@ -16272,7 +16285,7 @@ function mayBeVirtual(options) {
|
|
|
16272
16285
|
import {
|
|
16273
16286
|
ESLintUtils as ESLintUtils15,
|
|
16274
16287
|
AST_NODE_TYPES as AST_NODE_TYPES75,
|
|
16275
|
-
ASTUtils as
|
|
16288
|
+
ASTUtils as ASTUtils44
|
|
16276
16289
|
} from "@typescript-eslint/utils";
|
|
16277
16290
|
import * as ts16 from "typescript";
|
|
16278
16291
|
var NO_ZOD_NATIVE_ENUM_DOCUMENTATION = {
|
|
@@ -16328,18 +16341,6 @@ var NO_ZOD_NATIVE_ENUM_DOCUMENTATION = {
|
|
|
16328
16341
|
}
|
|
16329
16342
|
]
|
|
16330
16343
|
};
|
|
16331
|
-
var IGNORE_PATTERNS = [
|
|
16332
|
-
/[\\/]generated[\\/]/,
|
|
16333
|
-
/\.gen\.tsx?$/,
|
|
16334
|
-
/\.generated\.tsx?$/,
|
|
16335
|
-
/\.d\.ts$/
|
|
16336
|
-
];
|
|
16337
|
-
function isIgnoredFile(filename, sourceText) {
|
|
16338
|
-
if (IGNORE_PATTERNS.some((re) => re.test(filename))) {
|
|
16339
|
-
return true;
|
|
16340
|
-
}
|
|
16341
|
-
return /@generated\b/.test(sourceText.slice(0, 1024));
|
|
16342
|
-
}
|
|
16343
16344
|
function unwrap2(node) {
|
|
16344
16345
|
if (node.type === AST_NODE_TYPES75.TSAsExpression || node.type === AST_NODE_TYPES75.TSSatisfiesExpression) {
|
|
16345
16346
|
return unwrap2(node.expression);
|
|
@@ -16389,7 +16390,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
16389
16390
|
defaultOptions: [],
|
|
16390
16391
|
create(context) {
|
|
16391
16392
|
const sourceCode = context.sourceCode;
|
|
16392
|
-
if (
|
|
16393
|
+
if (isGeneratedFile(context.filename, sourceCode.getText())) {
|
|
16393
16394
|
return {};
|
|
16394
16395
|
}
|
|
16395
16396
|
if (isTestFile(context.filename)) {
|
|
@@ -16404,7 +16405,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
16404
16405
|
const zodImportedBindings = /* @__PURE__ */ new Map();
|
|
16405
16406
|
const zodNamespaceBindings = /* @__PURE__ */ new Set();
|
|
16406
16407
|
function resolvedBinding(identifier) {
|
|
16407
|
-
return
|
|
16408
|
+
return ASTUtils44.findVariable(
|
|
16408
16409
|
sourceCode.getScope(identifier),
|
|
16409
16410
|
identifier.name
|
|
16410
16411
|
);
|
|
@@ -16412,7 +16413,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
16412
16413
|
function isZodMemberCall(node, api) {
|
|
16413
16414
|
const callee = unwrapExpression(node.callee);
|
|
16414
16415
|
const calleeReceiver = callee.type === AST_NODE_TYPES75.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
16415
|
-
if (callee.type === AST_NODE_TYPES75.MemberExpression && calleeReceiver.type === AST_NODE_TYPES75.Identifier &&
|
|
16416
|
+
if (callee.type === AST_NODE_TYPES75.MemberExpression && calleeReceiver.type === AST_NODE_TYPES75.Identifier && ASTUtils44.getPropertyName(callee) === api) {
|
|
16416
16417
|
const binding = resolvedBinding(calleeReceiver);
|
|
16417
16418
|
return binding !== null && zodNamespaceBindings.has(binding);
|
|
16418
16419
|
}
|
|
@@ -16471,7 +16472,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
16471
16472
|
});
|
|
16472
16473
|
|
|
16473
16474
|
// src/rules/test-loops-over-literal-cases.ts
|
|
16474
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES76, ASTUtils as
|
|
16475
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES76, ASTUtils as ASTUtils45 } from "@typescript-eslint/utils";
|
|
16475
16476
|
var TEST_LOOPS_OVER_LITERAL_CASES_DOCUMENTATION = {
|
|
16476
16477
|
summary: "Disallow assertions over an inline literal case loop in a test; parameterization reports and names every case independently.",
|
|
16477
16478
|
rationale: "A loop is reported as one test, so failures hide the individual case name and may stop later cases from running.",
|
|
@@ -16624,7 +16625,7 @@ var test_loops_over_literal_cases_default = createRule({
|
|
|
16624
16625
|
}
|
|
16625
16626
|
const capturesSetup = walkOwnScope2(node.body, (current) => {
|
|
16626
16627
|
if (current.type !== AST_NODE_TYPES76.Identifier) return false;
|
|
16627
|
-
const variable =
|
|
16628
|
+
const variable = ASTUtils45.findVariable(context.sourceCode.getScope(current), current.name);
|
|
16628
16629
|
if (variable === null || !variable.references.some((reference) => reference.identifier === current)) return false;
|
|
16629
16630
|
return variable.defs.some((definition) => {
|
|
16630
16631
|
const declaration = definition.name;
|
|
@@ -16733,7 +16734,7 @@ var test_phase_label_comment_default = createRule({
|
|
|
16733
16734
|
});
|
|
16734
16735
|
|
|
16735
16736
|
// src/rules/prefer-constant-time-secret-compare.ts
|
|
16736
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES78, ASTUtils as
|
|
16737
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES78, ASTUtils as ASTUtils46 } from "@typescript-eslint/utils";
|
|
16737
16738
|
var PREFER_CONSTANT_TIME_SECRET_COMPARE_DOCUMENTATION = {
|
|
16738
16739
|
summary: "Prefer a supported constant-time comparison primitive for secret-like values.",
|
|
16739
16740
|
rationale: "Ordinary equality offers no constant-time guarantee for comparing secrets.",
|
|
@@ -16819,7 +16820,7 @@ var prefer_constant_time_secret_compare_default = createRule({
|
|
|
16819
16820
|
return {};
|
|
16820
16821
|
}
|
|
16821
16822
|
const sourceCode = context.sourceCode;
|
|
16822
|
-
const variableOf = (node) =>
|
|
16823
|
+
const variableOf = (node) => ASTUtils46.findVariable(sourceCode.getScope(node), node.name);
|
|
16823
16824
|
function credentialSource(node, seen = /* @__PURE__ */ new Set()) {
|
|
16824
16825
|
if (seen.has(node) || seen.size >= 8) return false;
|
|
16825
16826
|
seen.add(node);
|
|
@@ -16833,10 +16834,10 @@ var prefer_constant_time_secret_compare_default = createRule({
|
|
|
16833
16834
|
const definition = binding.defs[0];
|
|
16834
16835
|
return definition?.type === "Variable" && definition.parent.kind === "const" && definition.node.init !== null && credentialSource(definition.node.init, seen);
|
|
16835
16836
|
}
|
|
16836
|
-
if (node.type !== AST_NODE_TYPES78.CallExpression || node.optional || node.arguments.length !== 1 || node.callee.type !== AST_NODE_TYPES78.MemberExpression || node.callee.optional ||
|
|
16837
|
+
if (node.type !== AST_NODE_TYPES78.CallExpression || node.optional || node.arguments.length !== 1 || node.callee.type !== AST_NODE_TYPES78.MemberExpression || node.callee.optional || ASTUtils46.getPropertyName(node.callee) !== "get") return false;
|
|
16837
16838
|
const receiver = node.callee.object;
|
|
16838
16839
|
const key = staticString(node.arguments[0]);
|
|
16839
|
-
if (receiver.type !== AST_NODE_TYPES78.MemberExpression || receiver.optional ||
|
|
16840
|
+
if (receiver.type !== AST_NODE_TYPES78.MemberExpression || receiver.optional || ASTUtils46.getPropertyName(receiver) !== "headers" || key === null || !isAuthSecretName(key) || !isNativeRequest(receiver.object)) return false;
|
|
16840
16841
|
const words2 = tokenize(key);
|
|
16841
16842
|
return !words2.includes("token") || words2.some((word) => AUTH_TOKEN_QUALIFIERS.has(word) || word !== "token" && SECRET_WORDS.has(word));
|
|
16842
16843
|
}
|
|
@@ -16974,7 +16975,7 @@ var prefer_ecmascript_private_members_default = createRule({
|
|
|
16974
16975
|
import "@typescript-eslint/utils";
|
|
16975
16976
|
|
|
16976
16977
|
// src/rules/_discriminated-union-returns.ts
|
|
16977
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES80, ASTUtils as
|
|
16978
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES80, ASTUtils as ASTUtils47 } from "@typescript-eslint/utils";
|
|
16978
16979
|
var MAX_PATH_VISITS = 2048;
|
|
16979
16980
|
var MAX_RETURN_OBJECTS = 256;
|
|
16980
16981
|
var MAX_PATH_DEPTH = 64;
|
|
@@ -17162,11 +17163,11 @@ function broadSwitchInput(statement, sourceCode) {
|
|
|
17162
17163
|
if (body2.type !== AST_NODE_TYPES80.BlockStatement || body2.body.length !== 1) return void 0;
|
|
17163
17164
|
const owner = body2.parent;
|
|
17164
17165
|
if (owner.type !== AST_NODE_TYPES80.FunctionDeclaration || owner.id === null) return void 0;
|
|
17165
|
-
const callable =
|
|
17166
|
+
const callable = ASTUtils47.findVariable(sourceCode.getScope(owner), owner.id.name);
|
|
17166
17167
|
if (callable?.defs.length !== 1 || callable.defs[0]?.type !== "FunctionName" || callable.defs[0].node !== owner) return void 0;
|
|
17167
17168
|
const input = statement.discriminant;
|
|
17168
17169
|
if (input.type !== AST_NODE_TYPES80.Identifier) return void 0;
|
|
17169
|
-
const binding =
|
|
17170
|
+
const binding = ASTUtils47.findVariable(sourceCode.getScope(input), input.name);
|
|
17170
17171
|
const definition = binding?.defs[0];
|
|
17171
17172
|
if (binding?.defs.length !== 1 || definition?.type !== "Parameter" || definition.node !== owner || definition.name.type !== AST_NODE_TYPES80.Identifier || binding.references.some((reference) => reference.isWrite())) return void 0;
|
|
17172
17173
|
const type = definition.name.typeAnnotation?.typeAnnotation.type;
|
|
@@ -17413,7 +17414,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
17413
17414
|
});
|
|
17414
17415
|
|
|
17415
17416
|
// src/rules/prefer-input-group-search.ts
|
|
17416
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES82, ASTUtils as
|
|
17417
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES82, ASTUtils as ASTUtils48 } from "@typescript-eslint/utils";
|
|
17417
17418
|
var PREFER_INPUT_GROUP_SEARCH_DOCUMENTATION = {
|
|
17418
17419
|
summary: "Require search icons and shared Input controls in the same visual wrapper to use InputGroup.",
|
|
17419
17420
|
rationale: "The shared compound control provides consistent spacing, focus behavior, and accessible composition.",
|
|
@@ -17537,7 +17538,7 @@ var prefer_input_group_search_default = createRule({
|
|
|
17537
17538
|
JSXOpeningElement(node) {
|
|
17538
17539
|
const name = elementName(node);
|
|
17539
17540
|
if (name === null) return;
|
|
17540
|
-
const binding =
|
|
17541
|
+
const binding = ASTUtils48.findVariable(context.sourceCode.getScope(node), name);
|
|
17541
17542
|
if (binding?.defs.length !== 1 || binding.defs[0]?.node.type !== AST_NODE_TYPES82.ImportSpecifier || binding.defs[0].node.importKind === "type") return;
|
|
17542
17543
|
const occurrence = {
|
|
17543
17544
|
ancestors: context.sourceCode.getAncestors(node),
|
|
@@ -17577,7 +17578,7 @@ var prefer_input_group_search_default = createRule({
|
|
|
17577
17578
|
|
|
17578
17579
|
// src/rules/prefer-millisecond-control-duration-schema.ts
|
|
17579
17580
|
import {
|
|
17580
|
-
ASTUtils as
|
|
17581
|
+
ASTUtils as ASTUtils49,
|
|
17581
17582
|
AST_NODE_TYPES as AST_NODE_TYPES83
|
|
17582
17583
|
} from "@typescript-eslint/utils";
|
|
17583
17584
|
var PREFER_MILLISECOND_CONTROL_DURATION_SCHEMA_DOCUMENTATION = {
|
|
@@ -17648,7 +17649,7 @@ var prefer_millisecond_control_duration_schema_default = createRule({
|
|
|
17648
17649
|
const objectFactories = /* @__PURE__ */ new Set();
|
|
17649
17650
|
const numberFactories = /* @__PURE__ */ new Set();
|
|
17650
17651
|
function binding(identifier) {
|
|
17651
|
-
return
|
|
17652
|
+
return ASTUtils49.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
17652
17653
|
}
|
|
17653
17654
|
function record(target, identifier) {
|
|
17654
17655
|
const variable = binding(identifier);
|
|
@@ -17661,7 +17662,7 @@ var prefer_millisecond_control_duration_schema_default = createRule({
|
|
|
17661
17662
|
const variable2 = binding(callee);
|
|
17662
17663
|
return variable2 !== null && objectFactories.has(variable2);
|
|
17663
17664
|
}
|
|
17664
|
-
if (callee.type !== AST_NODE_TYPES83.MemberExpression || calleeReceiver.type !== AST_NODE_TYPES83.Identifier ||
|
|
17665
|
+
if (callee.type !== AST_NODE_TYPES83.MemberExpression || calleeReceiver.type !== AST_NODE_TYPES83.Identifier || ASTUtils49.getPropertyName(callee) === null || (ASTUtils49.getPropertyName(callee) ?? "") !== "object" && (ASTUtils49.getPropertyName(callee) ?? "") !== "strictObject") {
|
|
17665
17666
|
return false;
|
|
17666
17667
|
}
|
|
17667
17668
|
const variable = binding(calleeReceiver);
|
|
@@ -17676,12 +17677,12 @@ var prefer_millisecond_control_duration_schema_default = createRule({
|
|
|
17676
17677
|
const variable = binding(callee);
|
|
17677
17678
|
return variable !== null && numberFactories.has(variable);
|
|
17678
17679
|
}
|
|
17679
|
-
if (callee.type !== AST_NODE_TYPES83.MemberExpression ||
|
|
17680
|
+
if (callee.type !== AST_NODE_TYPES83.MemberExpression || ASTUtils49.getPropertyName(callee) === null) return false;
|
|
17680
17681
|
if (calleeReceiver.type === AST_NODE_TYPES83.Identifier) {
|
|
17681
17682
|
const variable = binding(calleeReceiver);
|
|
17682
|
-
return (
|
|
17683
|
+
return (ASTUtils49.getPropertyName(callee) ?? "") === "number" && variable !== null && zodNamespaces.has(variable);
|
|
17683
17684
|
}
|
|
17684
|
-
return ["int", "min", "max", "positive", "nonnegative", "finite", "multipleOf", "optional", "nullable", "nullish", "default", "describe", "brand", "readonly"].includes(
|
|
17685
|
+
return ["int", "min", "max", "positive", "nonnegative", "finite", "multipleOf", "optional", "nullable", "nullish", "default", "describe", "brand", "readonly"].includes(ASTUtils49.getPropertyName(callee) ?? "") && isNumericSchema(calleeReceiver);
|
|
17685
17686
|
}
|
|
17686
17687
|
return {
|
|
17687
17688
|
ImportDeclaration(node) {
|
|
@@ -17714,7 +17715,7 @@ var prefer_millisecond_control_duration_schema_default = createRule({
|
|
|
17714
17715
|
});
|
|
17715
17716
|
|
|
17716
17717
|
// src/rules/prefer-immutable-module-constant.ts
|
|
17717
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES84, ASTUtils as
|
|
17718
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES84, ASTUtils as ASTUtils50 } from "@typescript-eslint/utils";
|
|
17718
17719
|
var PREFER_IMMUTABLE_MODULE_CONSTANT_DOCUMENTATION = {
|
|
17719
17720
|
summary: "Require module-level constant collections to expose readonly state.",
|
|
17720
17721
|
rationale: "A const binding prevents reassignment but does not stop callers from mutating its array, object, Set, or Map contents.",
|
|
@@ -17933,15 +17934,15 @@ var prefer_immutable_module_constant_default = createRule({
|
|
|
17933
17934
|
create(context) {
|
|
17934
17935
|
const sourceCode = context.sourceCode;
|
|
17935
17936
|
const isUnshadowedGlobal3 = (identifier) => {
|
|
17936
|
-
const variable =
|
|
17937
|
+
const variable = ASTUtils50.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
17937
17938
|
return variable === null || variable.defs.length === 0;
|
|
17938
17939
|
};
|
|
17939
17940
|
const isUnshadowedType = (identifier) => {
|
|
17940
|
-
const variable =
|
|
17941
|
+
const variable = ASTUtils50.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
17941
17942
|
return variable === null || !variable.defs.some((definition) => definition.isTypeDefinition);
|
|
17942
17943
|
};
|
|
17943
17944
|
const resolveLocalType = (identifier) => {
|
|
17944
|
-
const variable =
|
|
17945
|
+
const variable = ASTUtils50.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
17945
17946
|
const definitions2 = variable?.defs.filter((definition) => definition.isTypeDefinition) ?? [];
|
|
17946
17947
|
const declaration = definitions2.length === 1 ? definitions2[0]?.node : void 0;
|
|
17947
17948
|
return declaration?.type === AST_NODE_TYPES84.TSTypeAliasDeclaration || declaration?.type === AST_NODE_TYPES84.TSTypeParameter ? declaration : void 0;
|
|
@@ -18435,7 +18436,7 @@ function matchingAliasTargets(paths, alias) {
|
|
|
18435
18436
|
}
|
|
18436
18437
|
|
|
18437
18438
|
// src/rules/prefer-module-level-constant.ts
|
|
18438
|
-
import { ASTUtils as
|
|
18439
|
+
import { ASTUtils as ASTUtils51, AST_NODE_TYPES as AST_NODE_TYPES86 } from "@typescript-eslint/utils";
|
|
18439
18440
|
var PREFER_MODULE_LEVEL_CONSTANT_DOCUMENTATION = {
|
|
18440
18441
|
summary: "Hoist literal-only constant collections and regexes out of function bodies to module scope so they are allocated once.",
|
|
18441
18442
|
rationale: "Recreating immutable lookup data on every call wastes allocations and obscures its constant nature.",
|
|
@@ -18449,7 +18450,7 @@ var PREFER_MODULE_LEVEL_CONSTANT_DOCUMENTATION = {
|
|
|
18449
18450
|
};
|
|
18450
18451
|
var DEFAULT_MIN_ELEMENTS = 3;
|
|
18451
18452
|
var MAX_LITERAL_DEPTH = 4;
|
|
18452
|
-
var
|
|
18453
|
+
var IGNORE_PATTERNS = [
|
|
18453
18454
|
/[\\/]generated[\\/]/,
|
|
18454
18455
|
/\.gen\.tsx?$/,
|
|
18455
18456
|
/\.generated\.tsx?$/,
|
|
@@ -18480,8 +18481,8 @@ var FUNCTION_TYPES7 = /* @__PURE__ */ new Set([
|
|
|
18480
18481
|
AST_NODE_TYPES86.ArrowFunctionExpression
|
|
18481
18482
|
]);
|
|
18482
18483
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
18483
|
-
function
|
|
18484
|
-
if (
|
|
18484
|
+
function isIgnoredFile(filename, sourceText) {
|
|
18485
|
+
if (IGNORE_PATTERNS.some((re) => re.test(filename))) {
|
|
18485
18486
|
return true;
|
|
18486
18487
|
}
|
|
18487
18488
|
return /@generated\b/.test(sourceText.slice(0, 1024));
|
|
@@ -18635,7 +18636,7 @@ function isNonRetainingBuiltinCall(node, argument, sourceCode) {
|
|
|
18635
18636
|
return true;
|
|
18636
18637
|
}
|
|
18637
18638
|
function isUnshadowedBuiltin(identifier, sourceCode) {
|
|
18638
|
-
return (
|
|
18639
|
+
return (ASTUtils51.findVariable(sourceCode.getScope(identifier), identifier.name)?.defs.length ?? 0) === 0;
|
|
18639
18640
|
}
|
|
18640
18641
|
var prefer_module_level_constant_default = createRule({
|
|
18641
18642
|
name: "prefer-module-level-constant",
|
|
@@ -18669,7 +18670,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
18669
18670
|
const ignoreTestFiles = options.ignoreTestFiles ?? true;
|
|
18670
18671
|
const sourceCode = context.sourceCode;
|
|
18671
18672
|
const filename = context.filename;
|
|
18672
|
-
if (
|
|
18673
|
+
if (isIgnoredFile(filename, sourceCode.getText())) {
|
|
18673
18674
|
return {};
|
|
18674
18675
|
}
|
|
18675
18676
|
if (ignoreTestFiles && isLocalFixtureFile(filename)) {
|
|
@@ -18765,14 +18766,14 @@ function isSafeMemberRead(identifier, parent) {
|
|
|
18765
18766
|
if (grandparent.type === AST_NODE_TYPES86.UnaryExpression && grandparent.operator === "delete") {
|
|
18766
18767
|
return false;
|
|
18767
18768
|
}
|
|
18768
|
-
if (grandparent.type === AST_NODE_TYPES86.CallExpression && grandparent.callee === usage && (
|
|
18769
|
+
if (grandparent.type === AST_NODE_TYPES86.CallExpression && grandparent.callee === usage && (ASTUtils51.getPropertyName(parent) === null || MUTATING_METHODS2.has(ASTUtils51.getPropertyName(parent) ?? ""))) {
|
|
18769
18770
|
return false;
|
|
18770
18771
|
}
|
|
18771
18772
|
return true;
|
|
18772
18773
|
}
|
|
18773
18774
|
|
|
18774
18775
|
// src/rules/prefer-module-level-schema.ts
|
|
18775
|
-
import { ASTUtils as
|
|
18776
|
+
import { ASTUtils as ASTUtils52, AST_NODE_TYPES as AST_NODE_TYPES87 } from "@typescript-eslint/utils";
|
|
18776
18777
|
var PREFER_MODULE_LEVEL_SCHEMA_DOCUMENTATION = {
|
|
18777
18778
|
summary: "Declare a Zod schema at module scope when it closes over nothing in the enclosing function",
|
|
18778
18779
|
rationale: "A schema created inside a function is rebuilt on each call. Module scope can enable reuse across callers; local schemas already support local type inference.",
|
|
@@ -18880,7 +18881,7 @@ function schemaExpression(node) {
|
|
|
18880
18881
|
if (parent === void 0) {
|
|
18881
18882
|
return current;
|
|
18882
18883
|
}
|
|
18883
|
-
if (parent.type === AST_NODE_TYPES87.MemberExpression && parent.object === current &&
|
|
18884
|
+
if (parent.type === AST_NODE_TYPES87.MemberExpression && parent.object === current && ASTUtils52.getPropertyName(parent) !== null && TERMINAL_METHODS.has(ASTUtils52.getPropertyName(parent) ?? "")) {
|
|
18884
18885
|
return current;
|
|
18885
18886
|
}
|
|
18886
18887
|
if (parent.type === AST_NODE_TYPES87.MemberExpression && parent.object === current || parent.type === AST_NODE_TYPES87.CallExpression && parent.callee === current || parent.type === AST_NODE_TYPES87.TSAsExpression && parent.expression === current || parent.type === AST_NODE_TYPES87.TSNonNullExpression && parent.expression === current) {
|
|
@@ -19018,14 +19019,14 @@ var prefer_module_level_schema_default = createRule({
|
|
|
19018
19019
|
const unwrappedNodeCallee = node.type === "CallExpression" || node.type === "NewExpression" ? unwrapExpression(node.callee) : null;
|
|
19019
19020
|
if (node.type !== AST_NODE_TYPES87.CallExpression || unwrappedNodeCallee?.type !== AST_NODE_TYPES87.MemberExpression) return false;
|
|
19020
19021
|
const receiver = unwrapExpression(unwrappedNodeCallee.object);
|
|
19021
|
-
return node.type === AST_NODE_TYPES87.CallExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES87.MemberExpression &&
|
|
19022
|
+
return node.type === AST_NODE_TYPES87.CallExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES87.MemberExpression && ASTUtils52.getPropertyName(unwrappedNodeCallee) !== null && receiver.type === AST_NODE_TYPES87.Identifier && zodNamespaces.has(receiver.name);
|
|
19022
19023
|
}
|
|
19023
19024
|
function isSchemaConstruction(node) {
|
|
19024
19025
|
const callee = unwrapExpression(node.callee);
|
|
19025
19026
|
const calleeReceiver = callee.type === AST_NODE_TYPES87.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
19026
|
-
if (callee.type !== AST_NODE_TYPES87.MemberExpression ||
|
|
19027
|
+
if (callee.type !== AST_NODE_TYPES87.MemberExpression || ASTUtils52.getPropertyName(callee) === null || TERMINAL_METHODS.has(ASTUtils52.getPropertyName(callee) ?? "")) return false;
|
|
19027
19028
|
if (calleeReceiver.type === AST_NODE_TYPES87.CallExpression) return isSchemaConstruction(calleeReceiver);
|
|
19028
|
-
return isZodCall(node) && CONSTRUCTION_FACTORIES.has(
|
|
19029
|
+
return isZodCall(node) && CONSTRUCTION_FACTORIES.has(ASTUtils52.getPropertyName(callee) ?? "");
|
|
19029
19030
|
}
|
|
19030
19031
|
function hasEagerComputation(node) {
|
|
19031
19032
|
return subtreeSome(node, (inner) => inner.type === AST_NODE_TYPES87.NewExpression || inner.type === AST_NODE_TYPES87.TaggedTemplateExpression || inner.type === AST_NODE_TYPES87.CallExpression && !isSchemaConstruction(inner), true);
|
|
@@ -19033,10 +19034,10 @@ var prefer_module_level_schema_default = createRule({
|
|
|
19033
19034
|
function isCovered(node) {
|
|
19034
19035
|
let current = node.parent ?? void 0;
|
|
19035
19036
|
while (current !== void 0) {
|
|
19036
|
-
if (current !== node && isZodCall(current) && current.callee.type === AST_NODE_TYPES87.MemberExpression &&
|
|
19037
|
+
if (current !== node && isZodCall(current) && current.callee.type === AST_NODE_TYPES87.MemberExpression && ASTUtils52.getPropertyName(current.callee) !== null && factories.has(ASTUtils52.getPropertyName(current.callee) ?? "")) {
|
|
19037
19038
|
return true;
|
|
19038
19039
|
}
|
|
19039
|
-
if (current.type === AST_NODE_TYPES87.CallExpression && (current.callee.type === AST_NODE_TYPES87.Identifier && memoCallees.has(current.callee.name) || current.callee.type === AST_NODE_TYPES87.MemberExpression &&
|
|
19040
|
+
if (current.type === AST_NODE_TYPES87.CallExpression && (current.callee.type === AST_NODE_TYPES87.Identifier && memoCallees.has(current.callee.name) || current.callee.type === AST_NODE_TYPES87.MemberExpression && ASTUtils52.getPropertyName(current.callee) !== null && memoCallees.has(ASTUtils52.getPropertyName(current.callee) ?? ""))) {
|
|
19040
19041
|
return true;
|
|
19041
19042
|
}
|
|
19042
19043
|
current = current.parent ?? void 0;
|
|
@@ -19065,7 +19066,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
19065
19066
|
}
|
|
19066
19067
|
function isSchemaComposition(node) {
|
|
19067
19068
|
const callee = unwrapExpression(node.callee);
|
|
19068
|
-
const isCombinator = callee.type === AST_NODE_TYPES87.MemberExpression &&
|
|
19069
|
+
const isCombinator = callee.type === AST_NODE_TYPES87.MemberExpression && ASTUtils52.getPropertyName(callee) !== null && ZOD_COMBINATOR_METHODS.has(ASTUtils52.getPropertyName(callee) ?? "");
|
|
19069
19070
|
return isCombinator || isZodCall(node);
|
|
19070
19071
|
}
|
|
19071
19072
|
function closesOverNothing(node, enclosing) {
|
|
@@ -19138,10 +19139,10 @@ var prefer_module_level_schema_default = createRule({
|
|
|
19138
19139
|
return;
|
|
19139
19140
|
}
|
|
19140
19141
|
const callee = unwrappedNodeCallee;
|
|
19141
|
-
if (
|
|
19142
|
+
if (ASTUtils52.getPropertyName(callee) === null) {
|
|
19142
19143
|
return;
|
|
19143
19144
|
}
|
|
19144
|
-
const factory =
|
|
19145
|
+
const factory = ASTUtils52.getPropertyName(callee) ?? "";
|
|
19145
19146
|
if (!factories.has(factory)) {
|
|
19146
19147
|
return;
|
|
19147
19148
|
}
|
|
@@ -19184,7 +19185,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
19184
19185
|
// src/rules/prefer-module-level-refined-schema.ts
|
|
19185
19186
|
import {
|
|
19186
19187
|
AST_NODE_TYPES as AST_NODE_TYPES88,
|
|
19187
|
-
ASTUtils as
|
|
19188
|
+
ASTUtils as ASTUtils53
|
|
19188
19189
|
} from "@typescript-eslint/utils";
|
|
19189
19190
|
var BENCHMARK_PATH_RE = /(^|[/\\])(?:benchmarks?|bench)[/\\]/;
|
|
19190
19191
|
var FACTORIES = /* @__PURE__ */ new Set([
|
|
@@ -19411,9 +19412,9 @@ function chainMemberNames(node) {
|
|
|
19411
19412
|
for (; ; ) {
|
|
19412
19413
|
current = unwrapExpression(current);
|
|
19413
19414
|
if (current.type === AST_NODE_TYPES88.MemberExpression) {
|
|
19414
|
-
if (
|
|
19415
|
+
if (ASTUtils53.getPropertyName(current) === null)
|
|
19415
19416
|
return [];
|
|
19416
|
-
names.push(
|
|
19417
|
+
names.push(ASTUtils53.getPropertyName(current) ?? "");
|
|
19417
19418
|
current = current.object;
|
|
19418
19419
|
continue;
|
|
19419
19420
|
}
|
|
@@ -19430,8 +19431,8 @@ function schemaExpression2(node) {
|
|
|
19430
19431
|
let current = node;
|
|
19431
19432
|
for (; ; ) {
|
|
19432
19433
|
const parent = current.parent ?? void 0;
|
|
19433
|
-
if (parent?.type === AST_NODE_TYPES88.MemberExpression && parent.object === current &&
|
|
19434
|
-
if (NON_SCHEMA_TERMINALS.has(
|
|
19434
|
+
if (parent?.type === AST_NODE_TYPES88.MemberExpression && parent.object === current && ASTUtils53.getPropertyName(parent) !== null && parent.parent?.type === AST_NODE_TYPES88.CallExpression && parent.parent.callee === parent) {
|
|
19435
|
+
if (NON_SCHEMA_TERMINALS.has(ASTUtils53.getPropertyName(parent) ?? "")) return current;
|
|
19435
19436
|
current = parent.parent;
|
|
19436
19437
|
continue;
|
|
19437
19438
|
}
|
|
@@ -19461,7 +19462,7 @@ var prefer_module_level_refined_schema_default = createRule({
|
|
|
19461
19462
|
return {};
|
|
19462
19463
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
19463
19464
|
function resolvedBinding(identifier) {
|
|
19464
|
-
return
|
|
19465
|
+
return ASTUtils53.findVariable(
|
|
19465
19466
|
context.sourceCode.getScope(identifier),
|
|
19466
19467
|
identifier.name
|
|
19467
19468
|
);
|
|
@@ -19487,7 +19488,7 @@ var prefer_module_level_refined_schema_default = createRule({
|
|
|
19487
19488
|
function isSchemaConstruction(node) {
|
|
19488
19489
|
const callee = unwrapExpression(node.callee);
|
|
19489
19490
|
const calleeReceiver = callee.type === AST_NODE_TYPES88.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
19490
|
-
if (callee.type !== AST_NODE_TYPES88.MemberExpression ||
|
|
19491
|
+
if (callee.type !== AST_NODE_TYPES88.MemberExpression || ASTUtils53.getPropertyName(callee) === null || NON_SCHEMA_TERMINALS.has(ASTUtils53.getPropertyName(callee) ?? "")) return false;
|
|
19491
19492
|
if (calleeReceiver.type === AST_NODE_TYPES88.CallExpression) return isSchemaConstruction(calleeReceiver);
|
|
19492
19493
|
return factoryName(node, FACTORIES) !== null || factoryName(node, COMPOSITE_FACTORIES) !== null;
|
|
19493
19494
|
}
|
|
@@ -19514,7 +19515,7 @@ var prefer_module_level_refined_schema_default = createRule({
|
|
|
19514
19515
|
function isMemoized(node) {
|
|
19515
19516
|
let current = node.parent ?? void 0;
|
|
19516
19517
|
while (current !== void 0) {
|
|
19517
|
-
if (current.type === AST_NODE_TYPES88.CallExpression && (current.callee.type === AST_NODE_TYPES88.Identifier && MEMO_CALLEES2.has(current.callee.name) || current.callee.type === AST_NODE_TYPES88.MemberExpression &&
|
|
19518
|
+
if (current.type === AST_NODE_TYPES88.CallExpression && (current.callee.type === AST_NODE_TYPES88.Identifier && MEMO_CALLEES2.has(current.callee.name) || current.callee.type === AST_NODE_TYPES88.MemberExpression && ASTUtils53.getPropertyName(current.callee) !== null && MEMO_CALLEES2.has(ASTUtils53.getPropertyName(current.callee) ?? "")))
|
|
19518
19519
|
return true;
|
|
19519
19520
|
current = current.parent ?? void 0;
|
|
19520
19521
|
}
|
|
@@ -19577,7 +19578,7 @@ var prefer_module_level_refined_schema_default = createRule({
|
|
|
19577
19578
|
// src/rules/prefer-multi-value-zod-literal.ts
|
|
19578
19579
|
import {
|
|
19579
19580
|
AST_NODE_TYPES as AST_NODE_TYPES89,
|
|
19580
|
-
ASTUtils as
|
|
19581
|
+
ASTUtils as ASTUtils54
|
|
19581
19582
|
} from "@typescript-eslint/utils";
|
|
19582
19583
|
var PREFER_MULTI_VALUE_ZOD_LITERAL_DOCUMENTATION = {
|
|
19583
19584
|
defaultLevel: "error",
|
|
@@ -19626,7 +19627,7 @@ function isStaticPrimitive(node, context) {
|
|
|
19626
19627
|
if (node.type === AST_NODE_TYPES89.TemplateLiteral && node.expressions.length === 0)
|
|
19627
19628
|
return true;
|
|
19628
19629
|
if (node.type === AST_NODE_TYPES89.Identifier && node.name === "undefined") {
|
|
19629
|
-
const binding =
|
|
19630
|
+
const binding = ASTUtils54.findVariable(
|
|
19630
19631
|
context.sourceCode.getScope(node),
|
|
19631
19632
|
node.name
|
|
19632
19633
|
);
|
|
@@ -19664,7 +19665,7 @@ var prefer_multi_value_zod_literal_default = createRule({
|
|
|
19664
19665
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
19665
19666
|
const zod4Bindings = /* @__PURE__ */ new Set();
|
|
19666
19667
|
function resolvedBinding(identifier) {
|
|
19667
|
-
return
|
|
19668
|
+
return ASTUtils54.findVariable(
|
|
19668
19669
|
context.sourceCode.getScope(identifier),
|
|
19669
19670
|
identifier.name
|
|
19670
19671
|
);
|
|
@@ -19672,7 +19673,7 @@ var prefer_multi_value_zod_literal_default = createRule({
|
|
|
19672
19673
|
function directMemberCall(node, binding, method) {
|
|
19673
19674
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
19674
19675
|
const receiver = unwrappedNodeCallee.type === AST_NODE_TYPES89.MemberExpression ? unwrapExpression(unwrappedNodeCallee.object) : unwrappedNodeCallee;
|
|
19675
|
-
if (unwrappedNodeCallee.type !== AST_NODE_TYPES89.MemberExpression || receiver.type !== AST_NODE_TYPES89.Identifier ||
|
|
19676
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES89.MemberExpression || receiver.type !== AST_NODE_TYPES89.Identifier || ASTUtils54.getPropertyName(unwrappedNodeCallee) === null || (ASTUtils54.getPropertyName(unwrappedNodeCallee) ?? "") !== method)
|
|
19676
19677
|
return false;
|
|
19677
19678
|
return resolvedBinding(receiver) === binding;
|
|
19678
19679
|
}
|
|
@@ -19974,7 +19975,7 @@ var prefer_named_complex_return_type_default = createRule({
|
|
|
19974
19975
|
});
|
|
19975
19976
|
|
|
19976
19977
|
// src/rules/prefer-native-random-uuid.ts
|
|
19977
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES93, ASTUtils as
|
|
19978
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES93, ASTUtils as ASTUtils55 } from "@typescript-eslint/utils";
|
|
19978
19979
|
var PREFER_NATIVE_RANDOM_UUID_DOCUMENTATION = {
|
|
19979
19980
|
summary: "Prefer `globalThis.crypto.randomUUID()` over resolved zero-argument UUID v4 bindings from the `uuid` package.",
|
|
19980
19981
|
rationale: "The platform implementation avoids an unnecessary dependency for standard random UUID generation.",
|
|
@@ -20010,14 +20011,14 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
20010
20011
|
const directBindings = /* @__PURE__ */ new Set();
|
|
20011
20012
|
const namespaceBindings = /* @__PURE__ */ new Set();
|
|
20012
20013
|
function resolve2(identifier) {
|
|
20013
|
-
return
|
|
20014
|
+
return ASTUtils55.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
20014
20015
|
}
|
|
20015
20016
|
function record(identifier, destination) {
|
|
20016
20017
|
const variable = resolve2(identifier);
|
|
20017
20018
|
if (variable !== null) destination.add(variable);
|
|
20018
20019
|
}
|
|
20019
20020
|
function report2(node) {
|
|
20020
|
-
const globalBinding =
|
|
20021
|
+
const globalBinding = ASTUtils55.findVariable(context.sourceCode.getScope(node), "globalThis");
|
|
20021
20022
|
const canSuggest = (globalBinding?.defs.length ?? 0) === 0 && context.sourceCode.getCommentsInside(node).length === 0;
|
|
20022
20023
|
context.report({
|
|
20023
20024
|
node,
|
|
@@ -20076,7 +20077,7 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
20076
20077
|
});
|
|
20077
20078
|
|
|
20078
20079
|
// src/rules/prefer-node-crypto-hash.ts
|
|
20079
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES94, ASTUtils as
|
|
20080
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES94, ASTUtils as ASTUtils56 } from "@typescript-eslint/utils";
|
|
20080
20081
|
var PREFER_NODE_CRYPTO_HASH_DOCUMENTATION = {
|
|
20081
20082
|
defaultLevel: "warning",
|
|
20082
20083
|
summary: "Prefer the modern one-shot node:crypto hash API when streaming state is unnecessary.",
|
|
@@ -20104,7 +20105,7 @@ function isCryptoLoader(node, resolve2) {
|
|
|
20104
20105
|
if (unwrappedNodeCallee?.type === AST_NODE_TYPES94.Identifier) {
|
|
20105
20106
|
return unwrappedNodeCallee.name === "require" && isUnshadowedBuiltinIdentifier(unwrappedNodeCallee, resolve2);
|
|
20106
20107
|
}
|
|
20107
|
-
return unwrappedNodeCallee?.type === AST_NODE_TYPES94.MemberExpression && unwrappedNodeCallee.object.type === AST_NODE_TYPES94.Identifier && unwrappedNodeCallee.object.name === "process" && isUnshadowedBuiltinIdentifier(unwrappedNodeCallee.object, resolve2) &&
|
|
20108
|
+
return unwrappedNodeCallee?.type === AST_NODE_TYPES94.MemberExpression && unwrappedNodeCallee.object.type === AST_NODE_TYPES94.Identifier && unwrappedNodeCallee.object.name === "process" && isUnshadowedBuiltinIdentifier(unwrappedNodeCallee.object, resolve2) && ASTUtils56.getPropertyName(unwrappedNodeCallee) === "getBuiltinModule";
|
|
20108
20109
|
}
|
|
20109
20110
|
function isCryptoSpecifier(node) {
|
|
20110
20111
|
return node.type === AST_NODE_TYPES94.Literal && (node.value === "crypto" || node.value === "node:crypto");
|
|
@@ -20129,7 +20130,7 @@ var prefer_node_crypto_hash_default = createRule({
|
|
|
20129
20130
|
const directBindings = /* @__PURE__ */ new Set();
|
|
20130
20131
|
const namespaceBindings = /* @__PURE__ */ new Set();
|
|
20131
20132
|
function resolve2(identifier) {
|
|
20132
|
-
return
|
|
20133
|
+
return ASTUtils56.findVariable(
|
|
20133
20134
|
context.sourceCode.getScope(identifier),
|
|
20134
20135
|
identifier.name
|
|
20135
20136
|
);
|
|
@@ -20191,7 +20192,7 @@ function importedName5(node) {
|
|
|
20191
20192
|
}
|
|
20192
20193
|
function isMemberCall(node, name) {
|
|
20193
20194
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
20194
|
-
return unwrappedNodeCallee.type === AST_NODE_TYPES94.MemberExpression &&
|
|
20195
|
+
return unwrappedNodeCallee.type === AST_NODE_TYPES94.MemberExpression && ASTUtils56.getPropertyName(unwrappedNodeCallee) === name;
|
|
20195
20196
|
}
|
|
20196
20197
|
function isCreateHashCall(node, directBindings, namespaceBindings, resolve2) {
|
|
20197
20198
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
@@ -20199,7 +20200,7 @@ function isCreateHashCall(node, directBindings, namespaceBindings, resolve2) {
|
|
|
20199
20200
|
const variable2 = resolve2(unwrappedNodeCallee);
|
|
20200
20201
|
return variable2 !== null && directBindings.has(variable2);
|
|
20201
20202
|
}
|
|
20202
|
-
if (unwrappedNodeCallee.type !== AST_NODE_TYPES94.MemberExpression ||
|
|
20203
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES94.MemberExpression || ASTUtils56.getPropertyName(unwrappedNodeCallee) !== "createHash") {
|
|
20203
20204
|
return false;
|
|
20204
20205
|
}
|
|
20205
20206
|
if (isCryptoLoader(unwrappedNodeCallee.object, resolve2)) return true;
|
|
@@ -20209,7 +20210,7 @@ function isCreateHashCall(node, directBindings, namespaceBindings, resolve2) {
|
|
|
20209
20210
|
}
|
|
20210
20211
|
|
|
20211
20212
|
// src/rules/prefer-node-fs-promises.ts
|
|
20212
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES95, ASTUtils as
|
|
20213
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES95, ASTUtils as ASTUtils57 } from "@typescript-eslint/utils";
|
|
20213
20214
|
var PREFER_NODE_FS_PROMISES_DOCUMENTATION = {
|
|
20214
20215
|
defaultLevel: "warning",
|
|
20215
20216
|
summary: "Prefer promise-based Node.js filesystem APIs over synchronous calls in production modules.",
|
|
@@ -20271,7 +20272,7 @@ var prefer_node_fs_promises_default = createRule({
|
|
|
20271
20272
|
if (isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text) || normalizedFilename.includes("src/rules/"))
|
|
20272
20273
|
return {};
|
|
20273
20274
|
const namespaces = /* @__PURE__ */ new Set();
|
|
20274
|
-
const bindingOf = (node) =>
|
|
20275
|
+
const bindingOf = (node) => ASTUtils57.findVariable(context.sourceCode.getScope(node), node.name);
|
|
20275
20276
|
const isGlobal = (node) => {
|
|
20276
20277
|
const binding = bindingOf(node);
|
|
20277
20278
|
return binding === null || binding.defs.length === 0;
|
|
@@ -20337,16 +20338,22 @@ var prefer_node_fs_promises_default = createRule({
|
|
|
20337
20338
|
});
|
|
20338
20339
|
|
|
20339
20340
|
// src/rules/prefer-non-nullable-collection.ts
|
|
20340
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES96, ASTUtils as
|
|
20341
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES96, ASTUtils as ASTUtils58 } from "@typescript-eslint/utils";
|
|
20341
20342
|
var PREFER_NON_NULLABLE_COLLECTION_DOCUMENTATION = {
|
|
20342
20343
|
summary: "Suggest reviewing nullish arrays that use local empty-array defaults or a shared null-or-empty guard.",
|
|
20343
20344
|
rationale: "A redundant nullish collection state spreads defaults and guards through consumers without carrying information.",
|
|
20344
20345
|
remediation: "Use a non-null collection type and normalize omitted input to an empty collection at the boundary.",
|
|
20345
20346
|
category: "maintainability",
|
|
20346
|
-
limitations: [
|
|
20347
|
+
limitations: [
|
|
20348
|
+
"Recognized defaults and guards are manual modeling prompts, not proof of equivalence for every caller or later use. Recognized exported wire shapes and unknown object escapes are excluded; preserve meaningful null states and boundary compatibility.",
|
|
20349
|
+
"Only inline object types or single unmerged top-level local declarations are resolved, using the type namespace. Array and ReadonlyArray names must be unshadowed built-ins; custom and imported constructors are not inferred. Local named, default and export-assignment type exports preserve ownership of their local interface and alias dependencies; arbitrary value exports remain opaque.",
|
|
20350
|
+
"Explicit exported variable annotations and signatures of local functions or constant callable aliases preserve input ownership, including callable signatures reached by an exported typeof query. Executable bodies, arbitrary value expressions, inferred exported types, class surfaces and ambiguous callable definitions are not resolved."
|
|
20351
|
+
],
|
|
20347
20352
|
examples: [
|
|
20348
20353
|
{ id: "non-null-array", title: "Model an always-present collection", outcome: "no-match", files: [{ path: "src/search.ts", source: "interface Input { items: string[] } function search({ items }: Input) { return items.length; }" }], focusPath: "src/search.ts", expectedCount: 0, public: true },
|
|
20349
|
-
{ id: "defaulted-nullish-array", title: "Do not retain a redundant nullish state", outcome: "match", files: [{ path: "src/search.ts", source: "interface Input { items: string[] | undefined } function search({ items = [] }: Input) { return items.length; }" }], focusPath: "src/search.ts", expectedCount: 1, public: true }
|
|
20354
|
+
{ id: "defaulted-nullish-array", title: "Do not retain a redundant nullish state", outcome: "match", files: [{ path: "src/search.ts", source: "interface Input { items: string[] | undefined } function search({ items = [] }: Input) { return items.length; }" }], focusPath: "src/search.ts", expectedCount: 1, public: true },
|
|
20355
|
+
{ id: "exported-nullish-input", scenarioId: "exported-input", title: "Preserve an exported input contract", outcome: "no-match", files: [{ path: "src/search.ts", source: "interface Input { items: string[] | undefined } export type WireInput = Input; function search({ items = [] }: Input) { return items.length; }" }], focusPath: "src/search.ts", expectedCount: 0, public: true },
|
|
20356
|
+
{ id: "private-nullish-input", scenarioId: "exported-input", title: "Review a private input with an empty default", outcome: "match", files: [{ path: "src/search.ts", source: "interface Input { items: string[] | undefined } type WireInput = Input; function search({ items = [] }: Input) { return items.length; }" }], focusPath: "src/search.ts", expectedCount: 1, public: true }
|
|
20350
20357
|
]
|
|
20351
20358
|
};
|
|
20352
20359
|
var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
@@ -20357,11 +20364,11 @@ function propertyName5(node) {
|
|
|
20357
20364
|
if (key.type === AST_NODE_TYPES96.Literal && typeof key.value === "string") return key.value;
|
|
20358
20365
|
return null;
|
|
20359
20366
|
}
|
|
20360
|
-
function isArrayType(node) {
|
|
20367
|
+
function isArrayType(node, source) {
|
|
20361
20368
|
if (node.type === AST_NODE_TYPES96.TSArrayType) return true;
|
|
20362
|
-
return node.type === AST_NODE_TYPES96.TSTypeReference && node.typeName.type === AST_NODE_TYPES96.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
20369
|
+
return node.type === AST_NODE_TYPES96.TSTypeReference && node.typeName.type === AST_NODE_TYPES96.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name) && node.typeArguments?.params.length === 1 && (typeBinding(source, node.typeName)?.defs.length ?? 0) === 0;
|
|
20363
20370
|
}
|
|
20364
|
-
function nullableProperty(node) {
|
|
20371
|
+
function nullableProperty(node, source) {
|
|
20365
20372
|
if (node.optional) return null;
|
|
20366
20373
|
const name = propertyName5(node);
|
|
20367
20374
|
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
@@ -20369,7 +20376,7 @@ function nullableProperty(node) {
|
|
|
20369
20376
|
const concrete = annotation.types.filter(
|
|
20370
20377
|
(member) => member.type !== AST_NODE_TYPES96.TSNullKeyword && member.type !== AST_NODE_TYPES96.TSUndefinedKeyword
|
|
20371
20378
|
);
|
|
20372
|
-
if (concrete.length === 0 || !concrete.every(isArrayType)) return null;
|
|
20379
|
+
if (concrete.length === 0 || !concrete.every((member) => isArrayType(member, source))) return null;
|
|
20373
20380
|
const acceptsNull = annotation.types.some((member) => member.type === AST_NODE_TYPES96.TSNullKeyword);
|
|
20374
20381
|
const acceptsUndefined = annotation.types.some(
|
|
20375
20382
|
(member) => member.type === AST_NODE_TYPES96.TSUndefinedKeyword
|
|
@@ -20377,32 +20384,221 @@ function nullableProperty(node) {
|
|
|
20377
20384
|
if (!acceptsNull && !acceptsUndefined) return null;
|
|
20378
20385
|
return { name, node, acceptsNull, acceptsUndefined };
|
|
20379
20386
|
}
|
|
20380
|
-
function shapeProperties(members) {
|
|
20387
|
+
function shapeProperties(members, source) {
|
|
20381
20388
|
return members.flatMap((member) => {
|
|
20382
20389
|
if (member.type !== AST_NODE_TYPES96.TSPropertySignature) return [];
|
|
20383
|
-
const property = nullableProperty(member);
|
|
20390
|
+
const property = nullableProperty(member, source);
|
|
20384
20391
|
return property === null ? [] : [property];
|
|
20385
20392
|
});
|
|
20386
20393
|
}
|
|
20387
|
-
function typeIndex(program) {
|
|
20394
|
+
function typeIndex(program, source, exportedDeclarations) {
|
|
20388
20395
|
const index = /* @__PURE__ */ new Map();
|
|
20389
20396
|
for (const statement of program.body) {
|
|
20390
20397
|
const exported = statement.type === AST_NODE_TYPES96.ExportNamedDeclaration;
|
|
20391
20398
|
const declaration = exported ? statement.declaration : statement;
|
|
20392
20399
|
if (declaration?.type === AST_NODE_TYPES96.TSInterfaceDeclaration) {
|
|
20393
|
-
index.set(declaration
|
|
20394
|
-
exported,
|
|
20395
|
-
properties: shapeProperties(declaration.body.body)
|
|
20400
|
+
index.set(declaration, {
|
|
20401
|
+
exported: exported || exportedDeclarations.has(declaration),
|
|
20402
|
+
properties: shapeProperties(declaration.body.body, source)
|
|
20396
20403
|
});
|
|
20397
20404
|
} else if (declaration?.type === AST_NODE_TYPES96.TSTypeAliasDeclaration && declaration.typeAnnotation.type === AST_NODE_TYPES96.TSTypeLiteral) {
|
|
20398
|
-
index.set(declaration
|
|
20399
|
-
exported,
|
|
20400
|
-
properties: shapeProperties(declaration.typeAnnotation.members)
|
|
20405
|
+
index.set(declaration, {
|
|
20406
|
+
exported: exported || exportedDeclarations.has(declaration),
|
|
20407
|
+
properties: shapeProperties(declaration.typeAnnotation.members, source)
|
|
20401
20408
|
});
|
|
20402
20409
|
}
|
|
20403
20410
|
}
|
|
20404
20411
|
return index;
|
|
20405
20412
|
}
|
|
20413
|
+
function exportedOwnership(program, source) {
|
|
20414
|
+
const seeds = { identifiers: [], values: [], roots: [], callables: /* @__PURE__ */ new Set(), signatures: /* @__PURE__ */ new Set() };
|
|
20415
|
+
for (const statement of program.body) collectExportSeeds(statement, seeds);
|
|
20416
|
+
const graph = {
|
|
20417
|
+
pending: [],
|
|
20418
|
+
declarations: /* @__PURE__ */ new Set(),
|
|
20419
|
+
callables: seeds.callables,
|
|
20420
|
+
signatures: /* @__PURE__ */ new Set(),
|
|
20421
|
+
types: /* @__PURE__ */ new Set(),
|
|
20422
|
+
values: /* @__PURE__ */ new Set(),
|
|
20423
|
+
syntax: /* @__PURE__ */ new Set(),
|
|
20424
|
+
cache: /* @__PURE__ */ new Map()
|
|
20425
|
+
};
|
|
20426
|
+
for (const identifier of seeds.identifiers) graph.pending.push({ kind: "type", identifier });
|
|
20427
|
+
for (const identifier of seeds.values) graph.pending.push({ kind: "value", identifier });
|
|
20428
|
+
for (const declaration of seeds.roots) addTypeDeclaration(declaration, graph);
|
|
20429
|
+
for (const callable of seeds.callables) addSignature(callable, graph);
|
|
20430
|
+
for (const signature of seeds.signatures) addSignature(signature, graph);
|
|
20431
|
+
for (let work = graph.pending.pop(); work !== void 0; work = graph.pending.pop()) {
|
|
20432
|
+
processOwnershipWork(work, source, graph);
|
|
20433
|
+
}
|
|
20434
|
+
return { declarations: graph.declarations, callables: graph.callables };
|
|
20435
|
+
}
|
|
20436
|
+
function processOwnershipWork(work, source, graph) {
|
|
20437
|
+
if (work.kind === "syntax") processOwnershipSyntax(work.node, source, graph);
|
|
20438
|
+
else if (work.kind === "type") processOwnershipType(work.identifier, source, graph);
|
|
20439
|
+
else processOwnershipValue(work.identifier, source, graph);
|
|
20440
|
+
}
|
|
20441
|
+
function processOwnershipSyntax(node, source, graph) {
|
|
20442
|
+
if (graph.syntax.has(node)) return;
|
|
20443
|
+
graph.syntax.add(node);
|
|
20444
|
+
if (node.type === AST_NODE_TYPES96.TSTypeReference && node.typeName.type === AST_NODE_TYPES96.Identifier) {
|
|
20445
|
+
graph.pending.push({ kind: "type", identifier: node.typeName });
|
|
20446
|
+
} else if (node.type === AST_NODE_TYPES96.TSInterfaceHeritage && node.expression.type === AST_NODE_TYPES96.Identifier) {
|
|
20447
|
+
graph.pending.push({ kind: "type", identifier: node.expression });
|
|
20448
|
+
} else if (node.type === AST_NODE_TYPES96.TSTypeQuery && node.exprName.type === AST_NODE_TYPES96.Identifier) {
|
|
20449
|
+
graph.pending.push({ kind: "value", identifier: node.exprName });
|
|
20450
|
+
}
|
|
20451
|
+
forEachAstChild(node, source.visitorKeys, (child) => {
|
|
20452
|
+
graph.pending.push({ kind: "syntax", node: child });
|
|
20453
|
+
});
|
|
20454
|
+
}
|
|
20455
|
+
function processOwnershipType(identifier, source, graph) {
|
|
20456
|
+
const binding = typeBinding(source, identifier);
|
|
20457
|
+
if (binding === null || graph.types.has(binding)) return;
|
|
20458
|
+
graph.types.add(binding);
|
|
20459
|
+
for (const definition of binding.defs) {
|
|
20460
|
+
const declaration = definition.node;
|
|
20461
|
+
if (definition.isTypeDefinition && (declaration.type === AST_NODE_TYPES96.TSTypeAliasDeclaration || declaration.type === AST_NODE_TYPES96.TSInterfaceDeclaration)) addTypeDeclaration(declaration, graph);
|
|
20462
|
+
}
|
|
20463
|
+
}
|
|
20464
|
+
function processOwnershipValue(identifier, source, graph) {
|
|
20465
|
+
const binding = valueBinding(source, identifier);
|
|
20466
|
+
if (binding === null || graph.values.has(binding)) return;
|
|
20467
|
+
graph.values.add(binding);
|
|
20468
|
+
const annotation = exportedValueAnnotation(source, identifier);
|
|
20469
|
+
if (annotation !== void 0) graph.pending.push({ kind: "syntax", node: annotation });
|
|
20470
|
+
const resolved = exportedCallable(source, identifier, graph.cache);
|
|
20471
|
+
if (resolved === null) return;
|
|
20472
|
+
if (resolved.callable !== null) graph.callables.add(resolved.callable);
|
|
20473
|
+
for (const signature of resolved.signatures) addSignature(signature, graph);
|
|
20474
|
+
for (const node of resolved.annotations) graph.pending.push({ kind: "syntax", node });
|
|
20475
|
+
}
|
|
20476
|
+
function addTypeDeclaration(declaration, graph) {
|
|
20477
|
+
if (graph.declarations.has(declaration)) return;
|
|
20478
|
+
graph.declarations.add(declaration);
|
|
20479
|
+
graph.pending.push({ kind: "syntax", node: declaration });
|
|
20480
|
+
}
|
|
20481
|
+
function addSignature(signature, graph) {
|
|
20482
|
+
if (graph.signatures.has(signature)) return;
|
|
20483
|
+
graph.signatures.add(signature);
|
|
20484
|
+
for (const node of callableAnnotations(signature)) graph.pending.push({ kind: "syntax", node });
|
|
20485
|
+
}
|
|
20486
|
+
function collectExportSeeds(statement, seeds) {
|
|
20487
|
+
if (statement.type === AST_NODE_TYPES96.ExportNamedDeclaration && statement.source === null) {
|
|
20488
|
+
collectNamedExport(statement, seeds);
|
|
20489
|
+
} else if (statement.type === AST_NODE_TYPES96.TSExportAssignment) {
|
|
20490
|
+
collectExportValue(statement.expression, seeds);
|
|
20491
|
+
} else if (statement.type === AST_NODE_TYPES96.ExportDefaultDeclaration) {
|
|
20492
|
+
if (statement.declaration.type === AST_NODE_TYPES96.TSInterfaceDeclaration) seeds.roots.push(statement.declaration);
|
|
20493
|
+
else collectExportValue(statement.declaration, seeds);
|
|
20494
|
+
}
|
|
20495
|
+
}
|
|
20496
|
+
function collectNamedExport(statement, seeds) {
|
|
20497
|
+
const declaration = statement.declaration;
|
|
20498
|
+
if (declaration?.type === AST_NODE_TYPES96.TSTypeAliasDeclaration || declaration?.type === AST_NODE_TYPES96.TSInterfaceDeclaration) {
|
|
20499
|
+
seeds.roots.push(declaration);
|
|
20500
|
+
}
|
|
20501
|
+
if (isFunctionNode2(declaration)) seeds.callables.add(declaration);
|
|
20502
|
+
if (isSignatureNode(declaration)) seeds.signatures.add(declaration);
|
|
20503
|
+
if (declaration?.type === AST_NODE_TYPES96.VariableDeclaration) {
|
|
20504
|
+
for (const binding of declaration.declarations) {
|
|
20505
|
+
if (binding.id.type === AST_NODE_TYPES96.Identifier) seeds.values.push(binding.id);
|
|
20506
|
+
}
|
|
20507
|
+
}
|
|
20508
|
+
for (const specifier of statement.specifiers) {
|
|
20509
|
+
if (specifier.local.type !== AST_NODE_TYPES96.Identifier) continue;
|
|
20510
|
+
seeds.identifiers.push(specifier.local);
|
|
20511
|
+
seeds.values.push(specifier.local);
|
|
20512
|
+
}
|
|
20513
|
+
}
|
|
20514
|
+
function collectExportValue(node, seeds) {
|
|
20515
|
+
if (node.type === AST_NODE_TYPES96.Identifier) {
|
|
20516
|
+
seeds.identifiers.push(node);
|
|
20517
|
+
seeds.values.push(node);
|
|
20518
|
+
} else if (isSignatureNode(node)) {
|
|
20519
|
+
seeds.signatures.add(node);
|
|
20520
|
+
if (isFunctionNode2(node)) seeds.callables.add(node);
|
|
20521
|
+
}
|
|
20522
|
+
}
|
|
20523
|
+
function exportedValueAnnotation(source, identifier) {
|
|
20524
|
+
const definitions2 = valueBinding(source, identifier)?.defs.filter((definition) => definition.isVariableDefinition) ?? [];
|
|
20525
|
+
if (definitions2.length !== 1) return void 0;
|
|
20526
|
+
const declaration = definitions2[0]?.node;
|
|
20527
|
+
return declaration?.type === AST_NODE_TYPES96.VariableDeclarator && declaration.id.type === AST_NODE_TYPES96.Identifier ? declaration.id.typeAnnotation : void 0;
|
|
20528
|
+
}
|
|
20529
|
+
function isFunctionNode2(node) {
|
|
20530
|
+
return node?.type === AST_NODE_TYPES96.FunctionDeclaration || node?.type === AST_NODE_TYPES96.FunctionExpression || node?.type === AST_NODE_TYPES96.ArrowFunctionExpression;
|
|
20531
|
+
}
|
|
20532
|
+
function isSignatureNode(node) {
|
|
20533
|
+
return isFunctionNode2(node) || node?.type === AST_NODE_TYPES96.TSDeclareFunction;
|
|
20534
|
+
}
|
|
20535
|
+
function exportedCallable(source, identifier, cache) {
|
|
20536
|
+
const visited = /* @__PURE__ */ new Set();
|
|
20537
|
+
const annotations = [];
|
|
20538
|
+
let target = null;
|
|
20539
|
+
let current = identifier;
|
|
20540
|
+
while (current !== void 0) {
|
|
20541
|
+
const binding = valueBinding(source, current);
|
|
20542
|
+
if (binding === null || visited.has(binding)) break;
|
|
20543
|
+
if (cache.has(binding)) {
|
|
20544
|
+
target = cache.get(binding) ?? null;
|
|
20545
|
+
break;
|
|
20546
|
+
}
|
|
20547
|
+
visited.add(binding);
|
|
20548
|
+
const declared = declaredCallableTarget(binding);
|
|
20549
|
+
if (declared !== null) {
|
|
20550
|
+
target = declared;
|
|
20551
|
+
break;
|
|
20552
|
+
}
|
|
20553
|
+
const step = constantCallableStep(binding);
|
|
20554
|
+
if (step === null) break;
|
|
20555
|
+
if (step.annotation !== void 0) annotations.push(step.annotation);
|
|
20556
|
+
if (isFunctionNode2(step.target)) {
|
|
20557
|
+
target = { callable: step.target, signatures: [step.target] };
|
|
20558
|
+
break;
|
|
20559
|
+
}
|
|
20560
|
+
current = step.target?.type === AST_NODE_TYPES96.Identifier ? step.target : void 0;
|
|
20561
|
+
}
|
|
20562
|
+
for (const binding of visited) cache.set(binding, target);
|
|
20563
|
+
return target === null ? null : { ...target, annotations };
|
|
20564
|
+
}
|
|
20565
|
+
function declaredCallableTarget(binding) {
|
|
20566
|
+
const definitions2 = binding.defs.filter((definition) => definition.isVariableDefinition);
|
|
20567
|
+
const signatures = definitions2.flatMap((definition) => isSignatureNode(definition.node) ? [definition.node] : []);
|
|
20568
|
+
if (signatures.length === 0 || signatures.length !== definitions2.length) return null;
|
|
20569
|
+
const implementations = signatures.filter(isFunctionNode2);
|
|
20570
|
+
return implementations.length > 1 ? null : { callable: implementations[0] ?? null, signatures };
|
|
20571
|
+
}
|
|
20572
|
+
function constantCallableStep(binding) {
|
|
20573
|
+
const definitions2 = binding.defs.filter((definition) => definition.isVariableDefinition);
|
|
20574
|
+
if (definitions2.length !== 1) return null;
|
|
20575
|
+
const declaration = definitions2[0]?.node;
|
|
20576
|
+
if (declaration?.type !== AST_NODE_TYPES96.VariableDeclarator || declaration.parent.type !== AST_NODE_TYPES96.VariableDeclaration || declaration.parent.kind !== "const" || declaration.id.type !== AST_NODE_TYPES96.Identifier) return null;
|
|
20577
|
+
const initializer = declaration.init;
|
|
20578
|
+
return {
|
|
20579
|
+
target: isFunctionNode2(initializer) || initializer?.type === AST_NODE_TYPES96.Identifier ? initializer : null,
|
|
20580
|
+
annotation: declaration.id.typeAnnotation
|
|
20581
|
+
};
|
|
20582
|
+
}
|
|
20583
|
+
function valueBinding(source, identifier) {
|
|
20584
|
+
let scope = source.getScope(identifier);
|
|
20585
|
+
while (scope !== null) {
|
|
20586
|
+
const variable = scope.set.get(identifier.name);
|
|
20587
|
+
if (variable !== void 0 && (variable.isValueVariable || variable.defs.some((definition) => definition.isVariableDefinition))) return variable;
|
|
20588
|
+
scope = scope.upper;
|
|
20589
|
+
}
|
|
20590
|
+
return null;
|
|
20591
|
+
}
|
|
20592
|
+
function callableAnnotations(callable) {
|
|
20593
|
+
const annotations = [];
|
|
20594
|
+
if (callable.returnType !== void 0) annotations.push(callable.returnType);
|
|
20595
|
+
if (callable.typeParameters !== void 0) annotations.push(callable.typeParameters);
|
|
20596
|
+
for (const raw of callable.params) {
|
|
20597
|
+
const parameter = raw.type === AST_NODE_TYPES96.AssignmentPattern ? raw.left : raw;
|
|
20598
|
+
if ((parameter.type === AST_NODE_TYPES96.Identifier || parameter.type === AST_NODE_TYPES96.ObjectPattern || parameter.type === AST_NODE_TYPES96.ArrayPattern || parameter.type === AST_NODE_TYPES96.RestElement) && parameter.typeAnnotation !== void 0) annotations.push(parameter.typeAnnotation);
|
|
20599
|
+
}
|
|
20600
|
+
return annotations;
|
|
20601
|
+
}
|
|
20406
20602
|
function emptyArray(node) {
|
|
20407
20603
|
return node.type === AST_NODE_TYPES96.ArrayExpression && node.elements.length === 0;
|
|
20408
20604
|
}
|
|
@@ -20462,14 +20658,14 @@ function directlyCoalesced(node) {
|
|
|
20462
20658
|
return parent?.type === AST_NODE_TYPES96.LogicalExpression && parent.left === node && (parent.operator === "??" || parent.operator === "||") && emptyArray(parent.right);
|
|
20463
20659
|
}
|
|
20464
20660
|
function identifierIsOnlyCoalesced(context, binding, fn) {
|
|
20465
|
-
const variable =
|
|
20661
|
+
const variable = ASTUtils58.findVariable(context.sourceCode.getScope(binding), binding.name);
|
|
20466
20662
|
if (variable === null || variable.references.length === 0) return false;
|
|
20467
20663
|
return variable.references.every(
|
|
20468
20664
|
(reference) => belongsToFunction(reference.identifier, fn) && directlyCoalesced(reference.identifier)
|
|
20469
20665
|
);
|
|
20470
20666
|
}
|
|
20471
20667
|
function memberIsOnlyCoalesced(context, object, property, fn) {
|
|
20472
|
-
const variable =
|
|
20668
|
+
const variable = ASTUtils58.findVariable(context.sourceCode.getScope(object), object.name);
|
|
20473
20669
|
if (variable === null) return false;
|
|
20474
20670
|
const accesses = variable.references.flatMap((reference) => {
|
|
20475
20671
|
if (!belongsToFunction(reference.identifier, fn)) return [null];
|
|
@@ -20498,11 +20694,15 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
20498
20694
|
return {};
|
|
20499
20695
|
}
|
|
20500
20696
|
let shapes = /* @__PURE__ */ new Map();
|
|
20697
|
+
let publicCallables = /* @__PURE__ */ new Set();
|
|
20501
20698
|
const evidence = /* @__PURE__ */ new Map();
|
|
20502
20699
|
function propertiesFor(annotation) {
|
|
20503
|
-
if (annotation?.type === AST_NODE_TYPES96.TSTypeLiteral) return shapeProperties(annotation.members);
|
|
20700
|
+
if (annotation?.type === AST_NODE_TYPES96.TSTypeLiteral) return shapeProperties(annotation.members, context.sourceCode);
|
|
20504
20701
|
if (annotation?.type === AST_NODE_TYPES96.TSTypeReference && annotation.typeName.type === AST_NODE_TYPES96.Identifier) {
|
|
20505
|
-
const
|
|
20702
|
+
const definitions2 = typeBinding(context.sourceCode, annotation.typeName)?.defs.filter((definition) => definition.isTypeDefinition) ?? [];
|
|
20703
|
+
if (definitions2.length !== 1) return [];
|
|
20704
|
+
const declaration = definitions2[0]?.node;
|
|
20705
|
+
const shape = declaration === void 0 ? void 0 : shapes.get(declaration);
|
|
20506
20706
|
return shape?.exported === false ? shape.properties : [];
|
|
20507
20707
|
}
|
|
20508
20708
|
return [];
|
|
@@ -20513,6 +20713,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
20513
20713
|
evidence.set(property.node, values);
|
|
20514
20714
|
}
|
|
20515
20715
|
function checkFunction(fn) {
|
|
20716
|
+
if (publicCallables.has(fn)) return;
|
|
20516
20717
|
function checkParameter(rawParameter) {
|
|
20517
20718
|
const parameter = rawParameter.type === AST_NODE_TYPES96.AssignmentPattern ? rawParameter.left : rawParameter;
|
|
20518
20719
|
if (parameter.type === AST_NODE_TYPES96.ObjectPattern) {
|
|
@@ -20537,7 +20738,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
20537
20738
|
function checkDestructuredProperties(parameter, properties) {
|
|
20538
20739
|
for (const property of properties) {
|
|
20539
20740
|
const bindingProperty = parameter.properties.find(
|
|
20540
|
-
(entry) => entry.type === AST_NODE_TYPES96.Property && !entry.computed &&
|
|
20741
|
+
(entry) => entry.type === AST_NODE_TYPES96.Property && !entry.computed && ASTUtils58.getPropertyName(entry) === property.name
|
|
20541
20742
|
);
|
|
20542
20743
|
if (bindingProperty === void 0) continue;
|
|
20543
20744
|
const value = bindingProperty.value;
|
|
@@ -20563,7 +20764,9 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
20563
20764
|
}
|
|
20564
20765
|
return {
|
|
20565
20766
|
Program(node) {
|
|
20566
|
-
|
|
20767
|
+
const ownership = exportedOwnership(node, context.sourceCode);
|
|
20768
|
+
publicCallables = ownership.callables;
|
|
20769
|
+
shapes = typeIndex(node, context.sourceCode, ownership.declarations);
|
|
20567
20770
|
},
|
|
20568
20771
|
ArrowFunctionExpression: checkFunction,
|
|
20569
20772
|
FunctionDeclaration: checkFunction,
|
|
@@ -20585,7 +20788,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
20585
20788
|
// src/rules/prefer-nullish-filter-predicate.ts
|
|
20586
20789
|
import {
|
|
20587
20790
|
AST_NODE_TYPES as AST_NODE_TYPES97,
|
|
20588
|
-
ASTUtils as
|
|
20791
|
+
ASTUtils as ASTUtils59,
|
|
20589
20792
|
ESLintUtils as ESLintUtils17
|
|
20590
20793
|
} from "@typescript-eslint/utils";
|
|
20591
20794
|
import ts17 from "typescript";
|
|
@@ -20631,7 +20834,7 @@ var PREFER_NULLISH_FILTER_PREDICATE_DOCUMENTATION = {
|
|
|
20631
20834
|
]
|
|
20632
20835
|
};
|
|
20633
20836
|
function isUnshadowedBoolean(node, context) {
|
|
20634
|
-
const variable =
|
|
20837
|
+
const variable = ASTUtils59.findVariable(context.sourceCode.getScope(node), node.name);
|
|
20635
20838
|
return variable === null || variable.defs.length === 0;
|
|
20636
20839
|
}
|
|
20637
20840
|
function isBuiltinArrayFilter(node, services) {
|
|
@@ -20690,7 +20893,7 @@ function isProvablyTruthy(type, checker) {
|
|
|
20690
20893
|
}
|
|
20691
20894
|
function availableParameterName(node, context) {
|
|
20692
20895
|
for (const name of ["value", "item", "element", "candidate"]) {
|
|
20693
|
-
if (
|
|
20896
|
+
if (ASTUtils59.findVariable(context.sourceCode.getScope(node), name) === null) return name;
|
|
20694
20897
|
}
|
|
20695
20898
|
return null;
|
|
20696
20899
|
}
|
|
@@ -20721,7 +20924,7 @@ var prefer_nullish_filter_predicate_default = createRule({
|
|
|
20721
20924
|
CallExpression(node) {
|
|
20722
20925
|
const callee = unwrapExpression(node.callee);
|
|
20723
20926
|
const callback = node.arguments[0] === void 0 ? void 0 : unwrapExpression(node.arguments[0]);
|
|
20724
|
-
if (node.arguments.length !== 1 || callback?.type !== AST_NODE_TYPES97.Identifier || callback.name !== "Boolean" || callee.type !== AST_NODE_TYPES97.MemberExpression ||
|
|
20927
|
+
if (node.arguments.length !== 1 || callback?.type !== AST_NODE_TYPES97.Identifier || callback.name !== "Boolean" || callee.type !== AST_NODE_TYPES97.MemberExpression || ASTUtils59.getPropertyName(callee) === null || (ASTUtils59.getPropertyName(callee) ?? "") !== "filter" || !isUnshadowedBoolean(callback, context) || !isBuiltinArrayFilter(callee, services)) return;
|
|
20725
20928
|
const elementType = arrayElementType(callee.object, services);
|
|
20726
20929
|
const checker = services.program.getTypeChecker();
|
|
20727
20930
|
if (elementType === null || !isNullishPlusTruthy(elementType, checker)) return;
|
|
@@ -20744,7 +20947,7 @@ var prefer_nullish_filter_predicate_default = createRule({
|
|
|
20744
20947
|
|
|
20745
20948
|
// src/rules/prefer-await-in-async-return.ts
|
|
20746
20949
|
import {
|
|
20747
|
-
ASTUtils as
|
|
20950
|
+
ASTUtils as ASTUtils60,
|
|
20748
20951
|
ESLintUtils as ESLintUtils18,
|
|
20749
20952
|
AST_NODE_TYPES as AST_NODE_TYPES98
|
|
20750
20953
|
} from "@typescript-eslint/utils";
|
|
@@ -20807,7 +21010,7 @@ function isRuntimeFunction(node) {
|
|
|
20807
21010
|
}
|
|
20808
21011
|
function promiseThenReceiver(node) {
|
|
20809
21012
|
const callee = unwrapExpression(node.callee);
|
|
20810
|
-
if (callee.type !== AST_NODE_TYPES98.MemberExpression || callee.optional ||
|
|
21013
|
+
if (callee.type !== AST_NODE_TYPES98.MemberExpression || callee.optional || ASTUtils60.getPropertyName(callee) === null || (ASTUtils60.getPropertyName(callee) ?? "") !== "then" || node.optional || node.arguments.length !== 1) {
|
|
20811
21014
|
return null;
|
|
20812
21015
|
}
|
|
20813
21016
|
const argument = node.arguments[0];
|
|
@@ -20877,7 +21080,7 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
20877
21080
|
if (services === null) return {};
|
|
20878
21081
|
const frameworkLoaders = /* @__PURE__ */ new Set();
|
|
20879
21082
|
const rememberFrameworkLoader = (identifier) => {
|
|
20880
|
-
const variable =
|
|
21083
|
+
const variable = ASTUtils60.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
20881
21084
|
if (variable !== null) frameworkLoaders.add(variable);
|
|
20882
21085
|
};
|
|
20883
21086
|
const isFrameworkLoaderCallback = (owner) => {
|
|
@@ -20885,7 +21088,7 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
20885
21088
|
if (parent === null || parent.arguments[0] !== outerExpression(owner)) return false;
|
|
20886
21089
|
const callee = unwrapExpression(parent.callee);
|
|
20887
21090
|
if (callee.type !== AST_NODE_TYPES98.Identifier) return false;
|
|
20888
|
-
const variable =
|
|
21091
|
+
const variable = ASTUtils60.findVariable(context.sourceCode.getScope(callee), callee.name);
|
|
20889
21092
|
return variable !== null && frameworkLoaders.has(variable);
|
|
20890
21093
|
};
|
|
20891
21094
|
return {
|
|
@@ -20922,18 +21125,18 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
20922
21125
|
});
|
|
20923
21126
|
|
|
20924
21127
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
20925
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES100, ASTUtils as
|
|
21128
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES100, ASTUtils as ASTUtils62 } from "@typescript-eslint/utils";
|
|
20926
21129
|
|
|
20927
21130
|
// src/rules/_native-fetch-reference.ts
|
|
20928
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES99, ASTUtils as
|
|
21131
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES99, ASTUtils as ASTUtils61 } from "@typescript-eslint/utils";
|
|
20929
21132
|
var GLOBAL_RECEIVERS3 = /* @__PURE__ */ new Set(["globalThis", "self", "window"]);
|
|
20930
21133
|
function nativeFetchReference(node, sourceCode, seen = /* @__PURE__ */ new Set()) {
|
|
20931
21134
|
const expression = unwrapExpression(node);
|
|
20932
21135
|
if (expression.type === AST_NODE_TYPES99.MemberExpression) {
|
|
20933
|
-
return
|
|
21136
|
+
return ASTUtils61.getPropertyName(expression) === "fetch" && globalReceiver(expression.object, sourceCode);
|
|
20934
21137
|
}
|
|
20935
21138
|
if (expression.type !== AST_NODE_TYPES99.Identifier) return false;
|
|
20936
|
-
const binding =
|
|
21139
|
+
const binding = ASTUtils61.findVariable(sourceCode.getScope(expression), expression.name);
|
|
20937
21140
|
if (binding === null || binding.defs.length === 0) return expression.name === "fetch";
|
|
20938
21141
|
if (seen.has(binding) || seen.size >= 8 || binding.defs.length !== 1 || binding.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
20939
21142
|
seen.add(binding);
|
|
@@ -20942,11 +21145,11 @@ function nativeFetchReference(node, sourceCode, seen = /* @__PURE__ */ new Set()
|
|
|
20942
21145
|
if (definition.node.id.type === AST_NODE_TYPES99.Identifier) {
|
|
20943
21146
|
return nativeFetchReference(definition.node.init, sourceCode, seen);
|
|
20944
21147
|
}
|
|
20945
|
-
return definition.node.id.type === AST_NODE_TYPES99.ObjectPattern && globalReceiver(definition.node.init, sourceCode) && definition.node.id.properties.some((property) => property.type === AST_NODE_TYPES99.Property &&
|
|
21148
|
+
return definition.node.id.type === AST_NODE_TYPES99.ObjectPattern && globalReceiver(definition.node.init, sourceCode) && definition.node.id.properties.some((property) => property.type === AST_NODE_TYPES99.Property && ASTUtils61.getPropertyName(property) === "fetch" && property.value.type === AST_NODE_TYPES99.Identifier && ASTUtils61.findVariable(sourceCode.getScope(property.value), property.value.name) === binding);
|
|
20946
21149
|
}
|
|
20947
21150
|
function globalReceiver(node, sourceCode) {
|
|
20948
21151
|
const receiver = unwrapExpression(node);
|
|
20949
|
-
return receiver.type === AST_NODE_TYPES99.Identifier && GLOBAL_RECEIVERS3.has(receiver.name) && !
|
|
21152
|
+
return receiver.type === AST_NODE_TYPES99.Identifier && GLOBAL_RECEIVERS3.has(receiver.name) && !ASTUtils61.findVariable(sourceCode.getScope(receiver), receiver.name)?.defs.length;
|
|
20950
21153
|
}
|
|
20951
21154
|
|
|
20952
21155
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
@@ -20986,7 +21189,7 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
20986
21189
|
]);
|
|
20987
21190
|
var isSchemaParseReference = (node) => {
|
|
20988
21191
|
const inner = unwrap5(node);
|
|
20989
|
-
return inner !== null && inner.type === AST_NODE_TYPES100.MemberExpression &&
|
|
21192
|
+
return inner !== null && inner.type === AST_NODE_TYPES100.MemberExpression && ASTUtils62.getPropertyName(inner) !== null && ((ASTUtils62.getPropertyName(inner) ?? "") === "parse" || (ASTUtils62.getPropertyName(inner) ?? "") === "safeParse");
|
|
20990
21193
|
};
|
|
20991
21194
|
var isRawPayloadSource = (node, context, isKnownLocalText) => {
|
|
20992
21195
|
let current = unwrap5(node);
|
|
@@ -21001,7 +21204,7 @@ var isRawPayloadSource = (node, context, isKnownLocalText) => {
|
|
|
21001
21204
|
if (callee === null || callee.type !== AST_NODE_TYPES100.MemberExpression) {
|
|
21002
21205
|
return false;
|
|
21003
21206
|
}
|
|
21004
|
-
const property =
|
|
21207
|
+
const property = ASTUtils62.getPropertyName(callee);
|
|
21005
21208
|
if (property === null) {
|
|
21006
21209
|
return false;
|
|
21007
21210
|
}
|
|
@@ -21013,19 +21216,19 @@ var isRawPayloadSource = (node, context, isKnownLocalText) => {
|
|
|
21013
21216
|
}
|
|
21014
21217
|
const object = unwrap5(callee.object);
|
|
21015
21218
|
const input = unwrap5(current.arguments[0]);
|
|
21016
|
-
if (input?.type === AST_NODE_TYPES100.CallExpression && input.arguments.length === 1 && input.callee.type === AST_NODE_TYPES100.MemberExpression && input.callee.object.type === AST_NODE_TYPES100.Identifier && input.callee.object.name === "JSON" &&
|
|
21017
|
-
return property === "parse" && object !== null && object.type === AST_NODE_TYPES100.Identifier && object.name === "JSON" && (
|
|
21219
|
+
if (input?.type === AST_NODE_TYPES100.CallExpression && input.arguments.length === 1 && input.callee.type === AST_NODE_TYPES100.MemberExpression && input.callee.object.type === AST_NODE_TYPES100.Identifier && input.callee.object.name === "JSON" && ASTUtils62.getPropertyName(input.callee) === "stringify" && (ASTUtils62.findVariable(context.sourceCode.getScope(input.callee.object), "JSON")?.defs.length ?? 0) === 0) return false;
|
|
21220
|
+
return property === "parse" && object !== null && object.type === AST_NODE_TYPES100.Identifier && object.name === "JSON" && (ASTUtils62.findVariable(context.sourceCode.getScope(object), "JSON")?.defs.length ?? 0) === 0 && !isLocalFileRead(current.arguments[0]) && isKnownLocalText?.(current.arguments[0]) !== true;
|
|
21018
21221
|
};
|
|
21019
21222
|
var isResponseSource = (node, context, seen = /* @__PURE__ */ new Set()) => {
|
|
21020
21223
|
let current = unwrap5(node);
|
|
21021
21224
|
if (current?.type === AST_NODE_TYPES100.AwaitExpression) current = unwrap5(current.argument);
|
|
21022
21225
|
if (current === null || seen.has(current)) return false;
|
|
21023
21226
|
seen.add(current);
|
|
21024
|
-
const isGlobal = (identifier) => (
|
|
21227
|
+
const isGlobal = (identifier) => (ASTUtils62.findVariable(context.sourceCode.getScope(identifier), identifier.name)?.defs.length ?? 0) === 0;
|
|
21025
21228
|
if (current.type === AST_NODE_TYPES100.CallExpression) return nativeFetchReference(current.callee, context.sourceCode);
|
|
21026
21229
|
if (current.type === AST_NODE_TYPES100.NewExpression) return current.callee.type === AST_NODE_TYPES100.Identifier && ["Request", "Response"].includes(current.callee.name) && isGlobal(current.callee);
|
|
21027
21230
|
if (current.type !== AST_NODE_TYPES100.Identifier) return false;
|
|
21028
|
-
const binding =
|
|
21231
|
+
const binding = ASTUtils62.findVariable(context.sourceCode.getScope(current), current.name);
|
|
21029
21232
|
if (binding?.defs.length !== 1 || binding.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
21030
21233
|
const definition = binding.defs[0];
|
|
21031
21234
|
const annotation = definition?.name.type === AST_NODE_TYPES100.Identifier ? definition.name.typeAnnotation?.typeAnnotation : void 0;
|
|
@@ -21040,7 +21243,7 @@ var isDirectLocalFileRead = (node) => {
|
|
|
21040
21243
|
}
|
|
21041
21244
|
if (current?.type !== AST_NODE_TYPES100.CallExpression) return false;
|
|
21042
21245
|
const callee = unwrap5(current.callee);
|
|
21043
|
-
const name = callee?.type === AST_NODE_TYPES100.Identifier ? callee.name : callee?.type === AST_NODE_TYPES100.MemberExpression &&
|
|
21246
|
+
const name = callee?.type === AST_NODE_TYPES100.Identifier ? callee.name : callee?.type === AST_NODE_TYPES100.MemberExpression && ASTUtils62.getPropertyName(callee) !== null ? ASTUtils62.getPropertyName(callee) ?? "" : null;
|
|
21044
21247
|
return name !== null && FILE_READ_RE.test(name);
|
|
21045
21248
|
};
|
|
21046
21249
|
var isLocalFileRead = (node) => {
|
|
@@ -21101,7 +21304,7 @@ var isValidationRead = (node) => {
|
|
|
21101
21304
|
return false;
|
|
21102
21305
|
}
|
|
21103
21306
|
const callee = parent.callee;
|
|
21104
|
-
if (callee.type === AST_NODE_TYPES100.MemberExpression && callee.object.type === AST_NODE_TYPES100.Identifier && callee.object.name === "Array" &&
|
|
21307
|
+
if (callee.type === AST_NODE_TYPES100.MemberExpression && callee.object.type === AST_NODE_TYPES100.Identifier && callee.object.name === "Array" && ASTUtils62.getPropertyName(callee) === "isArray") {
|
|
21105
21308
|
return parent.arguments.length === 1;
|
|
21106
21309
|
}
|
|
21107
21310
|
return callee.type === AST_NODE_TYPES100.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
@@ -21129,11 +21332,11 @@ var bindingValidationPolarity = (test, bindingName) => {
|
|
|
21129
21332
|
}
|
|
21130
21333
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
21131
21334
|
}
|
|
21132
|
-
return test.type === AST_NODE_TYPES100.CallExpression && test.arguments.length === 1 && test.arguments[0]?.type === AST_NODE_TYPES100.Identifier && test.arguments[0].name === bindingName && test.callee.type === AST_NODE_TYPES100.MemberExpression && test.callee.object.type === AST_NODE_TYPES100.Identifier && test.callee.object.name === "Array" &&
|
|
21335
|
+
return test.type === AST_NODE_TYPES100.CallExpression && test.arguments.length === 1 && test.arguments[0]?.type === AST_NODE_TYPES100.Identifier && test.arguments[0].name === bindingName && test.callee.type === AST_NODE_TYPES100.MemberExpression && test.callee.object.type === AST_NODE_TYPES100.Identifier && test.callee.object.name === "Array" && ASTUtils62.getPropertyName(test.callee) === "isArray" ? "valid-when-true" : null;
|
|
21133
21336
|
};
|
|
21134
21337
|
var plainMemberAccess = (node) => {
|
|
21135
21338
|
if (node.type !== AST_NODE_TYPES100.MemberExpression || node.object.type !== AST_NODE_TYPES100.Identifier) return null;
|
|
21136
|
-
const property =
|
|
21339
|
+
const property = ASTUtils62.getPropertyName(node);
|
|
21137
21340
|
return property === null ? null : { object: node.object.name, property };
|
|
21138
21341
|
};
|
|
21139
21342
|
var isSamePlainMember = (node, access) => {
|
|
@@ -21197,7 +21400,7 @@ var memberValidationPolarity = (test, access) => {
|
|
|
21197
21400
|
}
|
|
21198
21401
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
21199
21402
|
}
|
|
21200
|
-
return test.type === AST_NODE_TYPES100.CallExpression && test.arguments.length === 1 && test.arguments[0] !== void 0 && test.arguments[0].type !== AST_NODE_TYPES100.SpreadElement && isSamePlainMember(test.arguments[0], access) && test.callee.type === AST_NODE_TYPES100.MemberExpression && test.callee.object.type === AST_NODE_TYPES100.Identifier && test.callee.object.name === "Array" &&
|
|
21403
|
+
return test.type === AST_NODE_TYPES100.CallExpression && test.arguments.length === 1 && test.arguments[0] !== void 0 && test.arguments[0].type !== AST_NODE_TYPES100.SpreadElement && isSamePlainMember(test.arguments[0], access) && test.callee.type === AST_NODE_TYPES100.MemberExpression && test.callee.object.type === AST_NODE_TYPES100.Identifier && test.callee.object.name === "Array" && ASTUtils62.getPropertyName(test.callee) === "isArray" ? "valid-when-true" : null;
|
|
21201
21404
|
};
|
|
21202
21405
|
var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
21203
21406
|
const isValidationReference = (identifier) => {
|
|
@@ -21480,7 +21683,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
21480
21683
|
(candidate2) => localFileTextRef(candidate2, scope) !== null
|
|
21481
21684
|
)) {
|
|
21482
21685
|
const parent = node.parent;
|
|
21483
|
-
const method =
|
|
21686
|
+
const method = ASTUtils62.getPropertyName(node);
|
|
21484
21687
|
if (parent.type === AST_NODE_TYPES100.CallExpression && parent.callee === node && method !== null && (method === "parse" || method === "safeParse" || PROMISE_CHAIN_METHODS.has(method))) {
|
|
21485
21688
|
return;
|
|
21486
21689
|
}
|
|
@@ -21533,7 +21736,7 @@ function ifGuardDominates(use, branch, positive) {
|
|
|
21533
21736
|
}
|
|
21534
21737
|
|
|
21535
21738
|
// src/rules/prefer-shared-zod-enum.ts
|
|
21536
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES101, ASTUtils as
|
|
21739
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES101, ASTUtils as ASTUtils63 } from "@typescript-eslint/utils";
|
|
21537
21740
|
var PREFER_SHARED_ZOD_ENUM_DOCUMENTATION = {
|
|
21538
21741
|
defaultLevel: "warning",
|
|
21539
21742
|
summary: "Give repeated literal Zod enum domains one reusable module-level schema.",
|
|
@@ -21584,7 +21787,7 @@ var prefer_shared_zod_enum_default = createRule({
|
|
|
21584
21787
|
create(context) {
|
|
21585
21788
|
if (isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text)) return {};
|
|
21586
21789
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
21587
|
-
const bindingOf = (node) =>
|
|
21790
|
+
const bindingOf = (node) => ASTUtils63.findVariable(context.sourceCode.getScope(node), node.name);
|
|
21588
21791
|
const candidates = /* @__PURE__ */ new Map();
|
|
21589
21792
|
return {
|
|
21590
21793
|
ImportDeclaration(node) {
|
|
@@ -21599,7 +21802,7 @@ var prefer_shared_zod_enum_default = createRule({
|
|
|
21599
21802
|
CallExpression(node) {
|
|
21600
21803
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
21601
21804
|
const receiver = unwrappedNodeCallee.type === AST_NODE_TYPES101.MemberExpression ? unwrapExpression(unwrappedNodeCallee.object) : unwrappedNodeCallee;
|
|
21602
|
-
if (unwrappedNodeCallee.type !== AST_NODE_TYPES101.MemberExpression || receiver.type !== AST_NODE_TYPES101.Identifier ||
|
|
21805
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES101.MemberExpression || receiver.type !== AST_NODE_TYPES101.Identifier || ASTUtils63.getPropertyName(unwrappedNodeCallee) === null || (ASTUtils63.getPropertyName(unwrappedNodeCallee) ?? "") !== "enum") return;
|
|
21603
21806
|
const binding = bindingOf(receiver);
|
|
21604
21807
|
if (binding === null || !zodBindings.has(binding)) return;
|
|
21605
21808
|
const domain = literalDomain(node);
|
|
@@ -21624,7 +21827,7 @@ var prefer_shared_zod_enum_default = createRule({
|
|
|
21624
21827
|
});
|
|
21625
21828
|
|
|
21626
21829
|
// src/rules/prefer-switch-for-repeated-equality.ts
|
|
21627
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES102, ASTUtils as
|
|
21830
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES102, ASTUtils as ASTUtils64 } from "@typescript-eslint/utils";
|
|
21628
21831
|
var PREFER_SWITCH_FOR_REPEATED_EQUALITY_DOCUMENTATION = {
|
|
21629
21832
|
defaultLevel: "error",
|
|
21630
21833
|
summary: "Prefer switch over long if/else-if chains that compare one value for strict equality.",
|
|
@@ -21676,7 +21879,7 @@ var prefer_switch_for_repeated_equality_default = createRule({
|
|
|
21676
21879
|
if (node.parent.type === AST_NODE_TYPES102.IfStatement && node.parent.alternate === node) return;
|
|
21677
21880
|
const first = discriminantName(node.test);
|
|
21678
21881
|
if (first === null) return;
|
|
21679
|
-
const binding =
|
|
21882
|
+
const binding = ASTUtils64.findVariable(context.sourceCode.getScope(node), first);
|
|
21680
21883
|
if (binding === null || binding.defs.length !== 1 || binding.scope.type === "global") return;
|
|
21681
21884
|
const [definition] = binding.defs;
|
|
21682
21885
|
if (definition?.type !== "Parameter" && definition?.type !== "Variable") return;
|
|
@@ -22223,7 +22426,7 @@ function packageWorkspaceGlobs(parsed) {
|
|
|
22223
22426
|
}
|
|
22224
22427
|
|
|
22225
22428
|
// src/rules/prefer-server-actions.ts
|
|
22226
|
-
import { ASTUtils as
|
|
22429
|
+
import { ASTUtils as ASTUtils65 } from "@typescript-eslint/utils";
|
|
22227
22430
|
var PREFER_SERVER_ACTIONS_DOCUMENTATION = {
|
|
22228
22431
|
summary: "Prefer Next.js Server Actions over same-origin API mutations.",
|
|
22229
22432
|
rationale: "Server Actions can remove a hand-written internal API wrapper while retaining typed application calls. Client invocations still cross a network and serialization boundary.",
|
|
@@ -22256,7 +22459,7 @@ function resolveNode(node, context) {
|
|
|
22256
22459
|
node = node == null ? node : unwrapExpression(node);
|
|
22257
22460
|
if (!node) return null;
|
|
22258
22461
|
if (node.type !== "Identifier") return node;
|
|
22259
|
-
const variable =
|
|
22462
|
+
const variable = ASTUtils65.findVariable(getScope(context, node), node.name);
|
|
22260
22463
|
const definition = variable?.defs.length === 1 ? variable.defs[0] : void 0;
|
|
22261
22464
|
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init === null || variable?.references.some((reference) => reference.isWrite() && reference.init !== true)) return node;
|
|
22262
22465
|
if (definition.node.init.type === "ObjectExpression" && variable?.references.some((reference) => reference.identifier !== node && reference.init !== true)) return node;
|
|
@@ -22265,7 +22468,7 @@ function resolveNode(node, context) {
|
|
|
22265
22468
|
function isAxiosClient(node, context, seen = /* @__PURE__ */ new Set()) {
|
|
22266
22469
|
if (node.type !== "Identifier" || seen.has(node)) return false;
|
|
22267
22470
|
seen.add(node);
|
|
22268
|
-
const variable =
|
|
22471
|
+
const variable = ASTUtils65.findVariable(getScope(context, node), node.name);
|
|
22269
22472
|
const definition = variable?.defs.length === 1 ? variable.defs[0] : void 0;
|
|
22270
22473
|
if (definition === void 0 || variable?.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
22271
22474
|
if (variable?.references.some((reference) => {
|
|
@@ -22349,10 +22552,10 @@ function isFunctionArgument(node, context) {
|
|
|
22349
22552
|
}
|
|
22350
22553
|
function getPropertyNode(objNode, propName2) {
|
|
22351
22554
|
if (!objNode || objNode.type !== "ObjectExpression") return null;
|
|
22352
|
-
if (objNode.properties.some((property) => property.type === "SpreadElement" ||
|
|
22555
|
+
if (objNode.properties.some((property) => property.type === "SpreadElement" || ASTUtils65.getPropertyName(property) === null)) return null;
|
|
22353
22556
|
for (const prop of [...objNode.properties].reverse()) {
|
|
22354
22557
|
if (prop.type !== "Property") continue;
|
|
22355
|
-
const keyName =
|
|
22558
|
+
const keyName = ASTUtils65.getPropertyName(prop);
|
|
22356
22559
|
if (keyName === propName2) {
|
|
22357
22560
|
if (prop.value.type === "AssignmentPattern" || prop.value.type === "ArrayPattern" || prop.value.type === "ObjectPattern") {
|
|
22358
22561
|
return null;
|
|
@@ -22476,7 +22679,7 @@ var prefer_server_actions_default = createRule({
|
|
|
22476
22679
|
});
|
|
22477
22680
|
|
|
22478
22681
|
// src/rules/prefer-whole-object-assertion.ts
|
|
22479
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES104, ASTUtils as
|
|
22682
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES104, ASTUtils as ASTUtils66 } from "@typescript-eslint/utils";
|
|
22480
22683
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
22481
22684
|
var SYNTHETIC_LITERAL_MATCHERS = /* @__PURE__ */ new Map([
|
|
22482
22685
|
["toBeNull", "null"]
|
|
@@ -22543,7 +22746,7 @@ function propertyAccess(node) {
|
|
|
22543
22746
|
const path = [];
|
|
22544
22747
|
let current = node;
|
|
22545
22748
|
while (current.type === AST_NODE_TYPES104.MemberExpression && !current.optional) {
|
|
22546
|
-
const name =
|
|
22749
|
+
const name = ASTUtils66.getPropertyName(current);
|
|
22547
22750
|
if (name === null || COLLECTION_PROPERTIES.has(name) || LITERAL_KEY_HAZARDS.has(name)) return null;
|
|
22548
22751
|
path.unshift(name);
|
|
22549
22752
|
current = unwrapExpression(current.object);
|
|
@@ -22693,7 +22896,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
22693
22896
|
const callee = unwrapExpression(call.callee);
|
|
22694
22897
|
const calleeReceiver = callee.type === AST_NODE_TYPES104.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
22695
22898
|
if (callee.type !== AST_NODE_TYPES104.MemberExpression) return null;
|
|
22696
|
-
const matcher =
|
|
22899
|
+
const matcher = ASTUtils66.getPropertyName(callee);
|
|
22697
22900
|
if (matcher === null) return null;
|
|
22698
22901
|
const expectCall = calleeReceiver;
|
|
22699
22902
|
const expectCallee = expectCall.type === AST_NODE_TYPES104.CallExpression ? unwrapExpression(expectCall.callee) : null;
|
|
@@ -22730,7 +22933,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
22730
22933
|
const call = statement.expression;
|
|
22731
22934
|
const callee = unwrapExpression(call.callee);
|
|
22732
22935
|
if (callee.type !== AST_NODE_TYPES104.MemberExpression || call.arguments.length !== 1) return false;
|
|
22733
|
-
const matcher =
|
|
22936
|
+
const matcher = ASTUtils66.getPropertyName(callee);
|
|
22734
22937
|
const assertion = unwrapExpression(callee.object);
|
|
22735
22938
|
if (assertion.type !== AST_NODE_TYPES104.CallExpression || assertion.arguments.length !== 1) return false;
|
|
22736
22939
|
const expect = unwrapExpression(assertion.callee);
|
|
@@ -22739,7 +22942,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
22739
22942
|
if (expected?.type !== AST_NODE_TYPES104.Literal || typeof expected.value !== "number" || !Number.isInteger(expected.value) || expected.value < 0) return false;
|
|
22740
22943
|
let actual = assertion.arguments[0] === void 0 ? void 0 : unwrapExpression(assertion.arguments[0]);
|
|
22741
22944
|
if (matcher !== "toHaveLength") {
|
|
22742
|
-
if (matcher === null || !MERGEABLE_MATCHERS.has(matcher) || actual?.type !== AST_NODE_TYPES104.MemberExpression || actual.optional ||
|
|
22945
|
+
if (matcher === null || !MERGEABLE_MATCHERS.has(matcher) || actual?.type !== AST_NODE_TYPES104.MemberExpression || actual.optional || ASTUtils66.getPropertyName(actual) !== "length") return false;
|
|
22743
22946
|
actual = unwrapExpression(actual.object);
|
|
22744
22947
|
}
|
|
22745
22948
|
return actual !== void 0 && sourceCode.getText(actual) === sourceCode.getText(receiver);
|
|
@@ -22778,7 +22981,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
22778
22981
|
});
|
|
22779
22982
|
|
|
22780
22983
|
// src/rules/repeated-static-call-cases.ts
|
|
22781
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES105, ASTUtils as
|
|
22984
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES105, ASTUtils as ASTUtils67 } from "@typescript-eslint/utils";
|
|
22782
22985
|
var REPEATED_STATIC_CALL_CASES_DOCUMENTATION = {
|
|
22783
22986
|
summary: "Review three or more consecutive static-input call assertions as potential named cases.",
|
|
22784
22987
|
rationale: "Copy-pasted cases obscure the input table, and a thrown assertion can stop later cases from being reported.",
|
|
@@ -22799,7 +23002,7 @@ var EXPECT_MODIFIERS = /* @__PURE__ */ new Set(["not", "rejects", "resolves"]);
|
|
|
22799
23002
|
var SNAPSHOT_MATCHERS = /snapshot/iu;
|
|
22800
23003
|
var MIN_CASES2 = 3;
|
|
22801
23004
|
function importedName6(identifier, context, modules) {
|
|
22802
|
-
const variable =
|
|
23005
|
+
const variable = ASTUtils67.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
22803
23006
|
if (variable === null || variable.defs.length === 0) return identifier.name;
|
|
22804
23007
|
for (const definition of variable.defs) {
|
|
22805
23008
|
if (definition.node.type !== AST_NODE_TYPES105.ImportSpecifier) continue;
|
|
@@ -22821,7 +23024,7 @@ function testRoot2(callee) {
|
|
|
22821
23024
|
callee = unwrapExpression(callee);
|
|
22822
23025
|
if (callee.type === AST_NODE_TYPES105.Identifier) return callee;
|
|
22823
23026
|
if (callee.type !== AST_NODE_TYPES105.MemberExpression) return null;
|
|
22824
|
-
const modifier =
|
|
23027
|
+
const modifier = ASTUtils67.getPropertyName(callee);
|
|
22825
23028
|
return modifier !== null && TEST_MODIFIERS5.has(modifier) ? testRoot2(callee.object) : null;
|
|
22826
23029
|
}
|
|
22827
23030
|
function isStatic(input) {
|
|
@@ -22867,8 +23070,8 @@ function assertionShape(statement, context, callback) {
|
|
|
22867
23070
|
const matcherCall = unwrapExpression(statement.expression);
|
|
22868
23071
|
if (matcherCall.type !== AST_NODE_TYPES105.CallExpression) return null;
|
|
22869
23072
|
const matcherCallee = unwrapExpression(matcherCall.callee);
|
|
22870
|
-
if (matcherCallee.type !== AST_NODE_TYPES105.MemberExpression ||
|
|
22871
|
-
const matcher =
|
|
23073
|
+
if (matcherCallee.type !== AST_NODE_TYPES105.MemberExpression || ASTUtils67.getPropertyName(matcherCallee) === null || matcherCall.arguments.length !== 1) return null;
|
|
23074
|
+
const matcher = ASTUtils67.getPropertyName(matcherCallee) ?? "";
|
|
22872
23075
|
if (SNAPSHOT_MATCHERS.test(matcher)) return null;
|
|
22873
23076
|
const chain = expectCallFromMatcher(matcherCallee);
|
|
22874
23077
|
const expectCallee = chain === null ? null : unwrapExpression(chain.call.callee);
|
|
@@ -22878,7 +23081,7 @@ function assertionShape(statement, context, callback) {
|
|
|
22878
23081
|
const observedCallee = observed?.type === AST_NODE_TYPES105.CallExpression ? unwrapExpression(observed.callee) : null;
|
|
22879
23082
|
if (observed?.type !== AST_NODE_TYPES105.CallExpression || observedCallee?.type !== AST_NODE_TYPES105.Identifier || observed.arguments.length === 0 || observed.arguments.some((arg) => arg.type === AST_NODE_TYPES105.SpreadElement || !isStatic(arg)) || expected?.type === AST_NODE_TYPES105.SpreadElement || expected === void 0 || !isStatic(expected)) return null;
|
|
22880
23083
|
const skeleton = `${observedCallee.name}/${observed.arguments.map((item) => staticShape(item)).join(",")}/${chain.modifiers.join(".")}/${matcher}/${staticShape(expected)}`;
|
|
22881
|
-
const binding =
|
|
23084
|
+
const binding = ASTUtils67.findVariable(context.sourceCode.getScope(observedCallee), observedCallee.name);
|
|
22882
23085
|
if (binding?.defs.some(
|
|
22883
23086
|
(definition) => definition.node.range[0] >= callback.range[0] && definition.node.range[1] <= callback.range[1]
|
|
22884
23087
|
)) return null;
|
|
@@ -22889,7 +23092,7 @@ function expectCallFromMatcher(node) {
|
|
|
22889
23092
|
const modifiers = [];
|
|
22890
23093
|
let receiver = node.object;
|
|
22891
23094
|
while (receiver.type === AST_NODE_TYPES105.MemberExpression) {
|
|
22892
|
-
const modifier =
|
|
23095
|
+
const modifier = ASTUtils67.getPropertyName(receiver);
|
|
22893
23096
|
if (modifier === null || !EXPECT_MODIFIERS.has(modifier)) return null;
|
|
22894
23097
|
modifiers.unshift(modifier);
|
|
22895
23098
|
receiver = receiver.object;
|
|
@@ -22965,7 +23168,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
22965
23168
|
});
|
|
22966
23169
|
|
|
22967
23170
|
// src/rules/prefer-zod-infer.ts
|
|
22968
|
-
import { ASTUtils as
|
|
23171
|
+
import { ASTUtils as ASTUtils68, AST_NODE_TYPES as AST_NODE_TYPES106 } from "@typescript-eslint/utils";
|
|
22969
23172
|
var PREFER_ZOD_INFER_DOCUMENTATION = {
|
|
22970
23173
|
summary: "Derive a type from its Zod schema with `z.infer` instead of hand-writing a twin declaration beside it.",
|
|
22971
23174
|
rationale: "A derived type stays synchronized when the runtime schema changes.",
|
|
@@ -23283,7 +23486,7 @@ function twinCallChain(node, zodNamespaces) {
|
|
|
23283
23486
|
while (current.type === AST_NODE_TYPES106.CallExpression) {
|
|
23284
23487
|
const callee = unwrapExpression(current.callee);
|
|
23285
23488
|
const calleeReceiver = callee.type === AST_NODE_TYPES106.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
23286
|
-
if (callee.type !== AST_NODE_TYPES106.MemberExpression ||
|
|
23489
|
+
if (callee.type !== AST_NODE_TYPES106.MemberExpression || ASTUtils68.getPropertyName(callee) === null) {
|
|
23287
23490
|
return null;
|
|
23288
23491
|
}
|
|
23289
23492
|
chain.push(current);
|
|
@@ -23296,7 +23499,7 @@ function twinCallChain(node, zodNamespaces) {
|
|
|
23296
23499
|
}
|
|
23297
23500
|
function twinMethodName(call) {
|
|
23298
23501
|
const callee = unwrapExpression(call.callee);
|
|
23299
|
-
return callee.type === AST_NODE_TYPES106.MemberExpression &&
|
|
23502
|
+
return callee.type === AST_NODE_TYPES106.MemberExpression && ASTUtils68.getPropertyName(callee) !== null ? ASTUtils68.getPropertyName(callee) ?? "" : "";
|
|
23300
23503
|
}
|
|
23301
23504
|
function twinSchemaFields(initializer, zodNamespaces) {
|
|
23302
23505
|
const chain = twinCallChain(initializer, zodNamespaces);
|
|
@@ -23311,7 +23514,7 @@ function twinSchemaFields(initializer, zodNamespaces) {
|
|
|
23311
23514
|
const fields = /* @__PURE__ */ new Map();
|
|
23312
23515
|
for (const property of shape.properties) {
|
|
23313
23516
|
if (property.type !== AST_NODE_TYPES106.Property) return null;
|
|
23314
|
-
const name =
|
|
23517
|
+
const name = ASTUtils68.getPropertyName(property);
|
|
23315
23518
|
if (name === null) return null;
|
|
23316
23519
|
fields.set(name, twinSchemaField(property.value, zodNamespaces));
|
|
23317
23520
|
}
|
|
@@ -23325,16 +23528,16 @@ function twinSchemaField(node, zodNamespaces) {
|
|
|
23325
23528
|
while (current.type === AST_NODE_TYPES106.CallExpression) {
|
|
23326
23529
|
const callee = unwrapExpression(current.callee);
|
|
23327
23530
|
const calleeReceiver = callee.type === AST_NODE_TYPES106.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
23328
|
-
if (callee.type !== AST_NODE_TYPES106.MemberExpression ||
|
|
23531
|
+
if (callee.type !== AST_NODE_TYPES106.MemberExpression || ASTUtils68.getPropertyName(callee) === null) {
|
|
23329
23532
|
break;
|
|
23330
23533
|
}
|
|
23331
23534
|
const receiver = calleeReceiver;
|
|
23332
23535
|
if (receiver.type === AST_NODE_TYPES106.Identifier && zodNamespaces.has(receiver.name)) {
|
|
23333
|
-
leaf =
|
|
23536
|
+
leaf = ASTUtils68.getPropertyName(callee) ?? "";
|
|
23334
23537
|
leafCall = current;
|
|
23335
23538
|
break;
|
|
23336
23539
|
}
|
|
23337
|
-
modifiers.push(
|
|
23540
|
+
modifiers.push(ASTUtils68.getPropertyName(callee) ?? "");
|
|
23338
23541
|
current = receiver;
|
|
23339
23542
|
}
|
|
23340
23543
|
return {
|
|
@@ -23537,7 +23740,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
23537
23740
|
},
|
|
23538
23741
|
/** Records `XSchema.transform(...)` and equivalent module-level reshaping. */
|
|
23539
23742
|
"MemberExpression"(node) {
|
|
23540
|
-
if (node.object.type === AST_NODE_TYPES106.Identifier &&
|
|
23743
|
+
if (node.object.type === AST_NODE_TYPES106.Identifier && ASTUtils68.getPropertyName(node) !== null && isPreferZodInferModuleReshaper(ASTUtils68.getPropertyName(node) ?? "")) {
|
|
23541
23744
|
reshapedSchemaNames.add(node.object.name);
|
|
23542
23745
|
}
|
|
23543
23746
|
},
|
|
@@ -23694,7 +23897,7 @@ function staticFieldName(key) {
|
|
|
23694
23897
|
}
|
|
23695
23898
|
|
|
23696
23899
|
// src/rules/named-child-schema-type.ts
|
|
23697
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES107, ASTUtils as
|
|
23900
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES107, ASTUtils as ASTUtils69 } from "@typescript-eslint/utils";
|
|
23698
23901
|
var UNRESOLVED_TYPE_NODES = /* @__PURE__ */ new Set([
|
|
23699
23902
|
AST_NODE_TYPES107.TSTypeQuery,
|
|
23700
23903
|
AST_NODE_TYPES107.TSImportType,
|
|
@@ -23739,7 +23942,7 @@ var named_child_schema_type_default = createRule({
|
|
|
23739
23942
|
const source = context.sourceCode;
|
|
23740
23943
|
if (isGeneratedFile(context.filename, source.text)) return {};
|
|
23741
23944
|
const namespaces = /* @__PURE__ */ new Set();
|
|
23742
|
-
const bindingOf = (node) =>
|
|
23945
|
+
const bindingOf = (node) => ASTUtils69.findVariable(source.getScope(node), node.name);
|
|
23743
23946
|
function namespaceOf(type) {
|
|
23744
23947
|
if (type.typeName.type !== AST_NODE_TYPES107.TSQualifiedName || type.typeName.left.type !== AST_NODE_TYPES107.Identifier) return null;
|
|
23745
23948
|
const binding = bindingOf(type.typeName.left);
|
|
@@ -23783,7 +23986,7 @@ var named_child_schema_type_default = createRule({
|
|
|
23783
23986
|
VariableDeclarator(node) {
|
|
23784
23987
|
if (!isModuleConst(node) || node.id.type !== AST_NODE_TYPES107.Identifier || node.init?.type !== AST_NODE_TYPES107.CallExpression) return;
|
|
23785
23988
|
const call = node.init;
|
|
23786
|
-
if (call.arguments.length !== 2 || call.callee.type !== AST_NODE_TYPES107.MemberExpression || call.callee.object.type !== AST_NODE_TYPES107.Identifier ||
|
|
23989
|
+
if (call.arguments.length !== 2 || call.callee.type !== AST_NODE_TYPES107.MemberExpression || call.callee.object.type !== AST_NODE_TYPES107.Identifier || ASTUtils69.getPropertyName(call.callee) !== "record") return;
|
|
23787
23990
|
const annotation = node.id.typeAnnotation?.typeAnnotation;
|
|
23788
23991
|
if (annotation?.type !== AST_NODE_TYPES107.TSTypeReference || annotation.typeName.type !== AST_NODE_TYPES107.TSQualifiedName || annotation.typeName.right.name !== "ZodRecord") return;
|
|
23789
23992
|
const namespace = namespaceOf(annotation);
|
|
@@ -23799,7 +24002,7 @@ var named_child_schema_type_default = createRule({
|
|
|
23799
24002
|
|
|
23800
24003
|
// src/rules/prefer-zod-parse-output-type.ts
|
|
23801
24004
|
import {
|
|
23802
|
-
ASTUtils as
|
|
24005
|
+
ASTUtils as ASTUtils70,
|
|
23803
24006
|
AST_NODE_TYPES as AST_NODE_TYPES108,
|
|
23804
24007
|
ESLintUtils as ESLintUtils19
|
|
23805
24008
|
} from "@typescript-eslint/utils";
|
|
@@ -24046,11 +24249,11 @@ function isLocalZodObjectSchema(node, namespaces) {
|
|
|
24046
24249
|
while (current.type === AST_NODE_TYPES108.CallExpression) {
|
|
24047
24250
|
const callee = unwrapExpression(current.callee);
|
|
24048
24251
|
const calleeReceiver = callee.type === AST_NODE_TYPES108.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
24049
|
-
if (callee.type !== AST_NODE_TYPES108.MemberExpression ||
|
|
24252
|
+
if (callee.type !== AST_NODE_TYPES108.MemberExpression || ASTUtils70.getPropertyName(callee) === null) {
|
|
24050
24253
|
return false;
|
|
24051
24254
|
}
|
|
24052
24255
|
if (calleeReceiver.type === AST_NODE_TYPES108.Identifier) {
|
|
24053
|
-
return namespaces.has(calleeReceiver.name) && ((
|
|
24256
|
+
return namespaces.has(calleeReceiver.name) && ((ASTUtils70.getPropertyName(callee) ?? "") === "object" || (ASTUtils70.getPropertyName(callee) ?? "") === "strictObject");
|
|
24054
24257
|
}
|
|
24055
24258
|
current = calleeReceiver;
|
|
24056
24259
|
}
|
|
@@ -24059,10 +24262,10 @@ function isLocalZodObjectSchema(node, namespaces) {
|
|
|
24059
24262
|
function zodParseCall(node) {
|
|
24060
24263
|
const callee = unwrapExpression(node.callee);
|
|
24061
24264
|
const calleeReceiver = callee.type === AST_NODE_TYPES108.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
24062
|
-
if (callee.type !== AST_NODE_TYPES108.MemberExpression || calleeReceiver.type !== AST_NODE_TYPES108.Identifier ||
|
|
24265
|
+
if (callee.type !== AST_NODE_TYPES108.MemberExpression || calleeReceiver.type !== AST_NODE_TYPES108.Identifier || ASTUtils70.getPropertyName(callee) === null) {
|
|
24063
24266
|
return null;
|
|
24064
24267
|
}
|
|
24065
|
-
const method =
|
|
24268
|
+
const method = ASTUtils70.getPropertyName(callee);
|
|
24066
24269
|
if (method !== "parse" && method !== "safeParse") return null;
|
|
24067
24270
|
return {
|
|
24068
24271
|
call: node,
|
|
@@ -24104,7 +24307,7 @@ function localParseReturnCandidates(node, sourceCode) {
|
|
|
24104
24307
|
for (const reference of variable.references) {
|
|
24105
24308
|
const identifier = reference.identifier;
|
|
24106
24309
|
const parent = identifier.parent;
|
|
24107
|
-
const output = parsed.method === "parse" ? identifier : parent.type === AST_NODE_TYPES108.MemberExpression && parent.object === identifier &&
|
|
24310
|
+
const output = parsed.method === "parse" ? identifier : parent.type === AST_NODE_TYPES108.MemberExpression && parent.object === identifier && ASTUtils70.getPropertyName(parent) !== null && (ASTUtils70.getPropertyName(parent) ?? "") === "data" ? parent : null;
|
|
24108
24311
|
if (output === null) continue;
|
|
24109
24312
|
const candidate2 = returnedOutputCandidate(parsed, output);
|
|
24110
24313
|
if (candidate2 !== null) candidates.push(candidate2);
|
|
@@ -24479,7 +24682,7 @@ var require_assert_never_default = createRule({
|
|
|
24479
24682
|
// src/rules/require-fetch-timeout.ts
|
|
24480
24683
|
import {
|
|
24481
24684
|
AST_NODE_TYPES as AST_NODE_TYPES110,
|
|
24482
|
-
ASTUtils as
|
|
24685
|
+
ASTUtils as ASTUtils71
|
|
24483
24686
|
} from "@typescript-eslint/utils";
|
|
24484
24687
|
var REQUIRE_FETCH_TIMEOUT_DOCUMENTATION = {
|
|
24485
24688
|
summary: "Require an explicit abort signal on locally analyzable global fetch calls.",
|
|
@@ -24548,7 +24751,7 @@ function initSignalState(init, resolvesToGlobal) {
|
|
|
24548
24751
|
const isSignal = !prop.computed && prop.key.type === AST_NODE_TYPES110.Identifier && prop.key.name === "signal" || prop.key.type === AST_NODE_TYPES110.Literal && prop.key.value === "signal";
|
|
24549
24752
|
if (isSignal) {
|
|
24550
24753
|
state = !prop.method ? emptySignal(prop.value, resolvesToGlobal) ?? "unknown" : "unknown";
|
|
24551
|
-
} else if (!prop.computed &&
|
|
24754
|
+
} else if (!prop.computed && ASTUtils71.getPropertyName(prop) === "__proto__" && state === "absent") {
|
|
24552
24755
|
state = "unknown";
|
|
24553
24756
|
} else if (prop.computed && prop.key.type !== AST_NODE_TYPES110.Literal) {
|
|
24554
24757
|
state = "unknown";
|
|
@@ -24557,14 +24760,14 @@ function initSignalState(init, resolvesToGlobal) {
|
|
|
24557
24760
|
return state;
|
|
24558
24761
|
}
|
|
24559
24762
|
function hasUnprovedPrototype(property) {
|
|
24560
|
-
if (property.computed || property.method || property.shorthand ||
|
|
24763
|
+
if (property.computed || property.method || property.shorthand || ASTUtils71.getPropertyName(property) !== "__proto__")
|
|
24561
24764
|
return false;
|
|
24562
24765
|
const prototype = unwrapExpression(property.value);
|
|
24563
24766
|
if (prototype.type === AST_NODE_TYPES110.Literal && prototype.value === null)
|
|
24564
24767
|
return false;
|
|
24565
24768
|
if (prototype.type !== AST_NODE_TYPES110.ObjectExpression) return true;
|
|
24566
24769
|
return prototype.properties.some(
|
|
24567
|
-
(member) => member.type === AST_NODE_TYPES110.SpreadElement || member.kind !== "init" || !member.computed &&
|
|
24770
|
+
(member) => member.type === AST_NODE_TYPES110.SpreadElement || member.kind !== "init" || !member.computed && ASTUtils71.getPropertyName(member) === "__proto__" || member.computed && member.key.type !== AST_NODE_TYPES110.Literal
|
|
24568
24771
|
);
|
|
24569
24772
|
}
|
|
24570
24773
|
function isInlineUrl(node, resolvesToGlobal) {
|
|
@@ -24607,11 +24810,11 @@ var require_fetch_timeout_default = createRule({
|
|
|
24607
24810
|
}
|
|
24608
24811
|
function resolvesToGlobal(identifier) {
|
|
24609
24812
|
const scope = context.sourceCode.getScope(identifier);
|
|
24610
|
-
const variable =
|
|
24813
|
+
const variable = ASTUtils71.findVariable(scope, identifier.name);
|
|
24611
24814
|
return variable === null || variable.defs.length === 0;
|
|
24612
24815
|
}
|
|
24613
24816
|
function localConstInitSignalState(identifier) {
|
|
24614
|
-
const variable =
|
|
24817
|
+
const variable = ASTUtils71.findVariable(
|
|
24615
24818
|
context.sourceCode.getScope(identifier),
|
|
24616
24819
|
identifier.name
|
|
24617
24820
|
);
|
|
@@ -24633,7 +24836,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
24633
24836
|
function isForwardedRequest(argument) {
|
|
24634
24837
|
let value = unwrapExpression(argument);
|
|
24635
24838
|
if (value.type === AST_NODE_TYPES110.Identifier) {
|
|
24636
|
-
const binding =
|
|
24839
|
+
const binding = ASTUtils71.findVariable(
|
|
24637
24840
|
context.sourceCode.getScope(value),
|
|
24638
24841
|
value.name
|
|
24639
24842
|
);
|
|
@@ -24818,7 +25021,7 @@ function exportedClasses(program, classes) {
|
|
|
24818
25021
|
}
|
|
24819
25022
|
|
|
24820
25023
|
// src/rules/require-sql-access-class.ts
|
|
24821
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES112, ASTUtils as
|
|
25024
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES112, ASTUtils as ASTUtils72 } from "@typescript-eslint/utils";
|
|
24822
25025
|
var DIRECT_EXECUTION_METHODS = /* @__PURE__ */ new Set([
|
|
24823
25026
|
"all",
|
|
24824
25027
|
"batch",
|
|
@@ -24925,7 +25128,7 @@ function databaseReceiver(node) {
|
|
|
24925
25128
|
if (node.type === AST_NODE_TYPES112.Identifier)
|
|
24926
25129
|
return DATABASE_NAMES.test(node.name);
|
|
24927
25130
|
if (node.type !== AST_NODE_TYPES112.MemberExpression) return false;
|
|
24928
|
-
const name =
|
|
25131
|
+
const name = ASTUtils72.getPropertyName(node);
|
|
24929
25132
|
return name === "DB" || name !== null && DATABASE_NAMES.test(name);
|
|
24930
25133
|
}
|
|
24931
25134
|
function databaseRootMember(node) {
|
|
@@ -24943,7 +25146,7 @@ function databaseRootMember(node) {
|
|
|
24943
25146
|
}
|
|
24944
25147
|
if (current.type === AST_NODE_TYPES112.MemberExpression) {
|
|
24945
25148
|
if (current.object.type === AST_NODE_TYPES112.ThisExpression)
|
|
24946
|
-
return
|
|
25149
|
+
return ASTUtils72.getPropertyName(current);
|
|
24947
25150
|
current = current.object;
|
|
24948
25151
|
continue;
|
|
24949
25152
|
}
|
|
@@ -24964,7 +25167,7 @@ function expressionHasDatabaseMarker(node) {
|
|
|
24964
25167
|
continue;
|
|
24965
25168
|
}
|
|
24966
25169
|
if (current.type === AST_NODE_TYPES112.MemberExpression) {
|
|
24967
|
-
const name =
|
|
25170
|
+
const name = ASTUtils72.getPropertyName(current);
|
|
24968
25171
|
if (name === "DB" || name !== null && DATABASE_NAMES.test(name))
|
|
24969
25172
|
return true;
|
|
24970
25173
|
current = current.object;
|
|
@@ -24983,7 +25186,7 @@ function expressionCallsBuilder(node) {
|
|
|
24983
25186
|
}
|
|
24984
25187
|
if (current.type === AST_NODE_TYPES112.CallExpression) {
|
|
24985
25188
|
if (current.callee.type !== AST_NODE_TYPES112.MemberExpression) return false;
|
|
24986
|
-
const name =
|
|
25189
|
+
const name = ASTUtils72.getPropertyName(current.callee);
|
|
24987
25190
|
if (name !== null && BUILDER_METHODS.has(name)) return true;
|
|
24988
25191
|
current = current.callee.object;
|
|
24989
25192
|
continue;
|
|
@@ -25034,7 +25237,7 @@ function thisRootMember(node) {
|
|
|
25034
25237
|
let current = node;
|
|
25035
25238
|
let root = null;
|
|
25036
25239
|
while (current.type === AST_NODE_TYPES112.MemberExpression) {
|
|
25037
|
-
const name =
|
|
25240
|
+
const name = ASTUtils72.getPropertyName(current);
|
|
25038
25241
|
if (name === null) return null;
|
|
25039
25242
|
root = name;
|
|
25040
25243
|
current = current.object;
|
|
@@ -25078,19 +25281,19 @@ var require_sql_access_class_default = createRule({
|
|
|
25078
25281
|
if (seen.has(node)) return false;
|
|
25079
25282
|
seen.add(node);
|
|
25080
25283
|
if (node.type === AST_NODE_TYPES112.Identifier) {
|
|
25081
|
-
const binding =
|
|
25284
|
+
const binding = ASTUtils72.findVariable(context.sourceCode.getScope(node), node.name);
|
|
25082
25285
|
if (binding?.defs.length !== 1 || binding.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
25083
25286
|
const definition = binding.defs[0];
|
|
25084
25287
|
return definition?.type === "Variable" && definition.node.init !== null && knownNonDatabase(definition.node.init, seen);
|
|
25085
25288
|
}
|
|
25086
|
-
return node.type === AST_NODE_TYPES112.NewExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES112.Identifier && ["Map", "WeakMap", "URLSearchParams"].includes(unwrappedNodeCallee.name) && (
|
|
25289
|
+
return node.type === AST_NODE_TYPES112.NewExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES112.Identifier && ["Map", "WeakMap", "URLSearchParams"].includes(unwrappedNodeCallee.name) && (ASTUtils72.findVariable(context.sourceCode.getScope(unwrappedNodeCallee), unwrappedNodeCallee.name)?.defs.length ?? 0) === 0;
|
|
25087
25290
|
}
|
|
25088
25291
|
return {
|
|
25089
25292
|
CallExpression(node) {
|
|
25090
25293
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
25091
25294
|
if (unwrappedNodeCallee.type !== AST_NODE_TYPES112.MemberExpression)
|
|
25092
25295
|
return;
|
|
25093
|
-
const method =
|
|
25296
|
+
const method = ASTUtils72.getPropertyName(unwrappedNodeCallee);
|
|
25094
25297
|
if (knownNonDatabase(unwrappedNodeCallee.object)) return;
|
|
25095
25298
|
if (method === null || !isDatabaseOperation(method, unwrappedNodeCallee.object))
|
|
25096
25299
|
return;
|
|
@@ -25190,7 +25393,7 @@ var require_static_next_matcher_default = createRule({
|
|
|
25190
25393
|
});
|
|
25191
25394
|
|
|
25192
25395
|
// src/rules/require-use-form-default-values.ts
|
|
25193
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES114, ASTUtils as
|
|
25396
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES114, ASTUtils as ASTUtils73 } from "@typescript-eslint/utils";
|
|
25194
25397
|
var REQUIRE_USE_FORM_DEFAULT_VALUES_DOCUMENTATION = {
|
|
25195
25398
|
summary: "Require explicit form-level initialization or a field default for directly bound Controller fields.",
|
|
25196
25399
|
rationale: "React Hook Form exposes form-level defaultValues/values and field-level defaultValue as its explicit initialization mechanisms. A directly bound controlled field should not omit both mechanisms.",
|
|
@@ -25241,7 +25444,7 @@ var require_use_form_default_values_default = createRule({
|
|
|
25241
25444
|
const imported = /* @__PURE__ */ new Map();
|
|
25242
25445
|
const uninitializedForms = /* @__PURE__ */ new Set();
|
|
25243
25446
|
const uninitializedControls = /* @__PURE__ */ new Set();
|
|
25244
|
-
const bindingNamed = (node, name) =>
|
|
25447
|
+
const bindingNamed = (node, name) => ASTUtils73.findVariable(context.sourceCode.getScope(node), name);
|
|
25245
25448
|
const bindingOf = (node) => bindingNamed(node, node.name);
|
|
25246
25449
|
const stable = (variable) => !variable.references.some((reference) => reference.isWrite() && reference.init !== true);
|
|
25247
25450
|
const importedKind = (node) => {
|
|
@@ -25287,7 +25490,7 @@ var require_use_form_default_values_default = createRule({
|
|
|
25287
25490
|
const variable = bindingOf(node);
|
|
25288
25491
|
return variable !== null && stable(variable) && uninitializedControls.has(variable);
|
|
25289
25492
|
}
|
|
25290
|
-
return node.type === AST_NODE_TYPES114.MemberExpression &&
|
|
25493
|
+
return node.type === AST_NODE_TYPES114.MemberExpression && ASTUtils73.getPropertyName(node) !== null && (ASTUtils73.getPropertyName(node) ?? "") === "control" && isUninitializedForm(node.object);
|
|
25291
25494
|
};
|
|
25292
25495
|
const fieldOptionsNeedDefault = (node) => {
|
|
25293
25496
|
if (node?.type !== AST_NODE_TYPES114.ObjectExpression) return false;
|
|
@@ -25343,7 +25546,7 @@ var require_use_form_default_values_default = createRule({
|
|
|
25343
25546
|
trackDestructuredControl(node.id);
|
|
25344
25547
|
return;
|
|
25345
25548
|
}
|
|
25346
|
-
if (node.id.type === AST_NODE_TYPES114.Identifier && node.init.type === AST_NODE_TYPES114.MemberExpression &&
|
|
25549
|
+
if (node.id.type === AST_NODE_TYPES114.Identifier && node.init.type === AST_NODE_TYPES114.MemberExpression && ASTUtils73.getPropertyName(node.init) !== null && (ASTUtils73.getPropertyName(node.init) ?? "") === "control" && isUninitializedForm(node.init.object)) {
|
|
25347
25550
|
const variable = bindingOf(node.id);
|
|
25348
25551
|
if (variable !== null) uninitializedControls.add(variable);
|
|
25349
25552
|
}
|
|
@@ -25436,7 +25639,7 @@ var require_use_server_in_actions_file_default = createRule({
|
|
|
25436
25639
|
// src/rules/require-zod-form-validation.ts
|
|
25437
25640
|
import {
|
|
25438
25641
|
AST_NODE_TYPES as AST_NODE_TYPES115,
|
|
25439
|
-
ASTUtils as
|
|
25642
|
+
ASTUtils as ASTUtils74
|
|
25440
25643
|
} from "@typescript-eslint/utils";
|
|
25441
25644
|
var REQUIRE_ZOD_FORM_VALIDATION_DOCUMENTATION = {
|
|
25442
25645
|
summary: "Require Zod validation (`Schema.parse(...)` / `Schema.safeParse(...)`) when reading values out of a `FormData` object.",
|
|
@@ -25484,7 +25687,7 @@ var isFormDataMethodCall = (node) => {
|
|
|
25484
25687
|
}
|
|
25485
25688
|
if (current.type !== AST_NODE_TYPES115.CallExpression) return false;
|
|
25486
25689
|
const callee = unwrapExpression(current.callee);
|
|
25487
|
-
return callee.type === AST_NODE_TYPES115.MemberExpression &&
|
|
25690
|
+
return callee.type === AST_NODE_TYPES115.MemberExpression && ASTUtils74.getPropertyName(callee) === "formData";
|
|
25488
25691
|
};
|
|
25489
25692
|
var require_zod_form_validation_default = createRule({
|
|
25490
25693
|
name: "require-zod-form-validation",
|
|
@@ -25505,7 +25708,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
25505
25708
|
return {};
|
|
25506
25709
|
}
|
|
25507
25710
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
25508
|
-
const resolvedBinding = (identifier) =>
|
|
25711
|
+
const resolvedBinding = (identifier) => ASTUtils74.findVariable(
|
|
25509
25712
|
context.sourceCode.getScope(identifier),
|
|
25510
25713
|
identifier.name
|
|
25511
25714
|
);
|
|
@@ -25513,7 +25716,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
25513
25716
|
const callee = unwrapExpression(node.callee);
|
|
25514
25717
|
const calleeReceiver = callee.type === AST_NODE_TYPES115.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
25515
25718
|
if (callee.type !== AST_NODE_TYPES115.MemberExpression) return false;
|
|
25516
|
-
if (
|
|
25719
|
+
if (ASTUtils74.getPropertyName(callee) === null || !FORM_VALUE_METHODS.has(ASTUtils74.getPropertyName(callee) ?? "")) {
|
|
25517
25720
|
return false;
|
|
25518
25721
|
}
|
|
25519
25722
|
return isFormSourceIdentifier(calleeReceiver);
|
|
@@ -25544,7 +25747,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
25544
25747
|
parent = parent.parent;
|
|
25545
25748
|
continue;
|
|
25546
25749
|
}
|
|
25547
|
-
if (parent.type === AST_NODE_TYPES115.CallExpression && parent.callee.type === AST_NODE_TYPES115.MemberExpression && parent.callee.object.type === AST_NODE_TYPES115.Identifier && parent.callee.object.name === "Object" &&
|
|
25750
|
+
if (parent.type === AST_NODE_TYPES115.CallExpression && parent.callee.type === AST_NODE_TYPES115.MemberExpression && parent.callee.object.type === AST_NODE_TYPES115.Identifier && parent.callee.object.name === "Object" && ASTUtils74.getPropertyName(parent.callee) === "fromEntries" && (resolvedBinding(parent.callee.object)?.defs.length ?? 0) === 0) {
|
|
25548
25751
|
parent = parent.parent;
|
|
25549
25752
|
continue;
|
|
25550
25753
|
}
|
|
@@ -25557,7 +25760,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
25557
25760
|
if (node.type !== AST_NODE_TYPES115.CallExpression) return false;
|
|
25558
25761
|
const callee = unwrapExpression(node.callee);
|
|
25559
25762
|
const calleeReceiver = callee.type === AST_NODE_TYPES115.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
25560
|
-
if (callee.type !== AST_NODE_TYPES115.MemberExpression ||
|
|
25763
|
+
if (callee.type !== AST_NODE_TYPES115.MemberExpression || ASTUtils74.getPropertyName(callee) === null || !ZOD_PARSE_METHODS.has(ASTUtils74.getPropertyName(callee) ?? "")) {
|
|
25561
25764
|
return false;
|
|
25562
25765
|
}
|
|
25563
25766
|
const root = zodReceiverRoot(calleeReceiver);
|
|
@@ -25643,7 +25846,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
25643
25846
|
};
|
|
25644
25847
|
const zodParseMethod = (call) => {
|
|
25645
25848
|
const callee = unwrapExpression(call.callee);
|
|
25646
|
-
return callee.type === AST_NODE_TYPES115.MemberExpression &&
|
|
25849
|
+
return callee.type === AST_NODE_TYPES115.MemberExpression && ASTUtils74.getPropertyName(callee) !== null ? ASTUtils74.getPropertyName(callee) ?? "" : null;
|
|
25647
25850
|
};
|
|
25648
25851
|
const isSafePrevalidationInspection = (identifier) => {
|
|
25649
25852
|
const parent = identifier.parent;
|
|
@@ -25819,7 +26022,7 @@ function expressionCallableName(current) {
|
|
|
25819
26022
|
}
|
|
25820
26023
|
|
|
25821
26024
|
// src/rules/stepdown.ts
|
|
25822
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES116, ASTUtils as
|
|
26025
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES116, ASTUtils as ASTUtils75 } from "@typescript-eslint/utils";
|
|
25823
26026
|
var STEPDOWN_DOCUMENTATION = {
|
|
25824
26027
|
summary: "Place a private helper below its sole direct same-scope caller.",
|
|
25825
26028
|
rationale: "Caller-first ordering lets a reader follow the main flow before descending into implementation details.",
|
|
@@ -26119,7 +26322,7 @@ function receiverOrigin(context, object, receivers) {
|
|
|
26119
26322
|
while (true) {
|
|
26120
26323
|
const unwrapped = unwrapExpression4(current);
|
|
26121
26324
|
if (unwrapped.type !== AST_NODE_TYPES116.Identifier) return unwrapped;
|
|
26122
|
-
const variable =
|
|
26325
|
+
const variable = ASTUtils75.findVariable(context.sourceCode.getScope(unwrapped), unwrapped.name);
|
|
26123
26326
|
if (variable === null) return null;
|
|
26124
26327
|
const known = receivers.get(variable);
|
|
26125
26328
|
if (known !== void 0) return known;
|
|
@@ -26300,11 +26503,11 @@ function classScope(context, node, computedReferences) {
|
|
|
26300
26503
|
function classReceiverBindings(context, node) {
|
|
26301
26504
|
const classReceivers = /* @__PURE__ */ new Map();
|
|
26302
26505
|
if (node.id !== null) {
|
|
26303
|
-
const internal =
|
|
26506
|
+
const internal = ASTUtils75.findVariable(context.sourceCode.getScope(node), node.id.name);
|
|
26304
26507
|
if (internal !== null && stableVariable(internal)) classReceivers.set(internal, true);
|
|
26305
26508
|
}
|
|
26306
26509
|
if (node.type === AST_NODE_TYPES116.ClassExpression && node.parent.type === AST_NODE_TYPES116.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES116.Identifier && node.parent.parent.type === AST_NODE_TYPES116.VariableDeclaration && node.parent.parent.kind === "const") {
|
|
26307
|
-
const outer =
|
|
26510
|
+
const outer = ASTUtils75.findVariable(context.sourceCode.getScope(node.parent), node.parent.id.name);
|
|
26308
26511
|
if (outer !== null && stableVariable(outer)) classReceivers.set(outer, true);
|
|
26309
26512
|
}
|
|
26310
26513
|
return classReceivers;
|
|
@@ -26390,7 +26593,7 @@ function classMethodCounts(body2, methods) {
|
|
|
26390
26593
|
}
|
|
26391
26594
|
|
|
26392
26595
|
// src/rules/source-coupled-test.ts
|
|
26393
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES117, ASTUtils as
|
|
26596
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES117, ASTUtils as ASTUtils76 } from "@typescript-eslint/utils";
|
|
26394
26597
|
var GENERAL_SOURCE_SUFFIX_RE = /\.(?:bash|sh|ya?ml|jsonc|toml|py|[cm]?[jt]s)$|(?<!\.(?:tf|tftest))\.json$/iu;
|
|
26395
26598
|
var FS_MODULES = /* @__PURE__ */ new Set(["fs", "node:fs", "fs/promises", "node:fs/promises"]);
|
|
26396
26599
|
var FS_READERS = /* @__PURE__ */ new Set(["readFile", "readFileSync"]);
|
|
@@ -26507,7 +26710,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
26507
26710
|
const scopes = [newScope()];
|
|
26508
26711
|
const reportedOrigins = /* @__PURE__ */ new Set();
|
|
26509
26712
|
const currentScope = () => scopes.at(-1) ?? scopes[0];
|
|
26510
|
-
const bindingOf = (node) =>
|
|
26713
|
+
const bindingOf = (node) => ASTUtils76.findVariable(context.sourceCode.getScope(node), node.name);
|
|
26511
26714
|
const assertionKind = (node) => {
|
|
26512
26715
|
const binding = bindingOf(node);
|
|
26513
26716
|
if (binding === null || binding.defs.length === 0) {
|
|
@@ -26560,7 +26763,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
26560
26763
|
return visible("fsReaders", callee) && sourcePath(current.arguments[0]);
|
|
26561
26764
|
}
|
|
26562
26765
|
if (callee.type !== AST_NODE_TYPES117.MemberExpression) return false;
|
|
26563
|
-
const name2 =
|
|
26766
|
+
const name2 = ASTUtils76.getPropertyName(callee);
|
|
26564
26767
|
const object = unwrap6(calleeReceiver);
|
|
26565
26768
|
return name2 !== null && FS_READERS.has(name2) && object.type === AST_NODE_TYPES117.Identifier && visible("fsObjects", object) && sourcePath(current.arguments[0]);
|
|
26566
26769
|
};
|
|
@@ -26569,12 +26772,12 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
26569
26772
|
if (current.type === AST_NODE_TYPES117.Identifier) return visibleRawOrigins(current);
|
|
26570
26773
|
if (rawRead(current)) return /* @__PURE__ */ new Set([`${current.range[0]}:${current.range[1]}`]);
|
|
26571
26774
|
if (current.type === AST_NODE_TYPES117.BinaryExpression && current.operator === "+") return /* @__PURE__ */ new Set([...rawOrigins(current.left), ...rawOrigins(current.right)]);
|
|
26572
|
-
if (current.type === AST_NODE_TYPES117.MemberExpression &&
|
|
26775
|
+
if (current.type === AST_NODE_TYPES117.MemberExpression && ASTUtils76.getPropertyName(current) === "length") return rawOrigins(current.object);
|
|
26573
26776
|
if (current.type !== AST_NODE_TYPES117.CallExpression) return /* @__PURE__ */ new Set();
|
|
26574
26777
|
const callee = unwrap6(current.callee);
|
|
26575
26778
|
const calleeReceiver = callee.type === AST_NODE_TYPES117.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
26576
26779
|
if (callee.type !== AST_NODE_TYPES117.MemberExpression) return /* @__PURE__ */ new Set();
|
|
26577
|
-
const name2 =
|
|
26780
|
+
const name2 = ASTUtils76.getPropertyName(callee);
|
|
26578
26781
|
return name2 !== null && TEXT_TRANSFORMS.has(name2) ? rawOrigins(calleeReceiver) : /* @__PURE__ */ new Set();
|
|
26579
26782
|
};
|
|
26580
26783
|
const evidenceOrigins = (node) => {
|
|
@@ -26587,7 +26790,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
26587
26790
|
const callee = unwrap6(current.callee);
|
|
26588
26791
|
const calleeReceiver = callee.type === AST_NODE_TYPES117.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
26589
26792
|
if (callee.type !== AST_NODE_TYPES117.MemberExpression) return /* @__PURE__ */ new Set();
|
|
26590
|
-
const name2 =
|
|
26793
|
+
const name2 = ASTUtils76.getPropertyName(callee);
|
|
26591
26794
|
if (name2 !== null && TEXT_PREDICATES.has(name2)) return rawOrigins(calleeReceiver);
|
|
26592
26795
|
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES117.SpreadElement ? [] : [...rawOrigins(argument)]));
|
|
26593
26796
|
return /* @__PURE__ */ new Set();
|
|
@@ -26599,10 +26802,10 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
26599
26802
|
return new Set(node.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES117.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
26600
26803
|
}
|
|
26601
26804
|
if (callee.type !== AST_NODE_TYPES117.MemberExpression) return /* @__PURE__ */ new Set();
|
|
26602
|
-
const matcher =
|
|
26805
|
+
const matcher = ASTUtils76.getPropertyName(callee);
|
|
26603
26806
|
if (matcher === null) return /* @__PURE__ */ new Set();
|
|
26604
26807
|
let receiver = unwrap6(calleeReceiver);
|
|
26605
|
-
while (receiver.type === AST_NODE_TYPES117.MemberExpression && EXPECT_MODIFIERS2.has(
|
|
26808
|
+
while (receiver.type === AST_NODE_TYPES117.MemberExpression && EXPECT_MODIFIERS2.has(ASTUtils76.getPropertyName(receiver) ?? "")) receiver = unwrap6(receiver.object);
|
|
26606
26809
|
const expectCallee = receiver.type === AST_NODE_TYPES117.CallExpression ? unwrapExpression(receiver.callee) : null;
|
|
26607
26810
|
if (receiver.type === AST_NODE_TYPES117.CallExpression && expectCallee?.type === AST_NODE_TYPES117.Identifier && assertionKind(expectCallee) === "expect") {
|
|
26608
26811
|
if (!EXPECT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
@@ -26885,7 +27088,7 @@ var iac_source_coupled_test_default = createSourceCoupledRule(
|
|
|
26885
27088
|
// src/rules/require-pascal-case-zod-schema-name.ts
|
|
26886
27089
|
import {
|
|
26887
27090
|
AST_NODE_TYPES as AST_NODE_TYPES119,
|
|
26888
|
-
ASTUtils as
|
|
27091
|
+
ASTUtils as ASTUtils77
|
|
26889
27092
|
} from "@typescript-eslint/utils";
|
|
26890
27093
|
var REQUIRE_PASCAL_CASE_ZOD_SCHEMA_NAME_DOCUMENTATION = {
|
|
26891
27094
|
summary: "Require confirmed module-level Zod schema contracts to use PascalCase with a `Schema` suffix.",
|
|
@@ -27018,7 +27221,7 @@ var SCHEMA_RETURNING_METHODS = /* @__PURE__ */ new Set([
|
|
|
27018
27221
|
"superRefine",
|
|
27019
27222
|
"transform"
|
|
27020
27223
|
]);
|
|
27021
|
-
var terminalMethodName = (callee) =>
|
|
27224
|
+
var terminalMethodName = (callee) => ASTUtils77.getPropertyName(callee) !== null ? ASTUtils77.getPropertyName(callee) ?? "" : null;
|
|
27022
27225
|
var calleeChainRoot2 = (node) => {
|
|
27023
27226
|
let current = node;
|
|
27024
27227
|
for (; ; ) {
|
|
@@ -27043,8 +27246,8 @@ var chainMemberNames2 = (node) => {
|
|
|
27043
27246
|
for (; ; ) {
|
|
27044
27247
|
current = unwrapExpression(current);
|
|
27045
27248
|
if (current.type === AST_NODE_TYPES119.MemberExpression) {
|
|
27046
|
-
if (
|
|
27047
|
-
names.push(
|
|
27249
|
+
if (ASTUtils77.getPropertyName(current) === null) return [];
|
|
27250
|
+
names.push(ASTUtils77.getPropertyName(current) ?? "");
|
|
27048
27251
|
current = current.object;
|
|
27049
27252
|
continue;
|
|
27050
27253
|
}
|
|
@@ -27081,7 +27284,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
27081
27284
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
27082
27285
|
const schemaBindings = /* @__PURE__ */ new Set();
|
|
27083
27286
|
function resolvedBinding(identifier) {
|
|
27084
|
-
return
|
|
27287
|
+
return ASTUtils77.findVariable(
|
|
27085
27288
|
context.sourceCode.getScope(identifier),
|
|
27086
27289
|
identifier.name
|
|
27087
27290
|
);
|