@sarj/eslint-plugin 15.6.2 → 15.6.4
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 +625 -435
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +623 -430
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1011,20 +1011,20 @@ var noCommentCruftDocumentation = {
|
|
|
1011
1011
|
],
|
|
1012
1012
|
examples: [
|
|
1013
1013
|
{
|
|
1014
|
-
id: "
|
|
1015
|
-
title: "A
|
|
1014
|
+
id: "owned-context",
|
|
1015
|
+
title: "A reference records why the counter changes",
|
|
1016
1016
|
outcome: "no-match",
|
|
1017
|
-
files: [{ path: "src/
|
|
1018
|
-
focusPath: "src/
|
|
1017
|
+
files: [{ path: "src/counter.ts", source: "// increment the counter for PLT-812\ncounter += 1;" }],
|
|
1018
|
+
focusPath: "src/counter.ts",
|
|
1019
1019
|
expectedCount: 0,
|
|
1020
1020
|
public: true
|
|
1021
1021
|
},
|
|
1022
1022
|
{
|
|
1023
|
-
id: "
|
|
1024
|
-
title: "A
|
|
1023
|
+
id: "redundant-narration",
|
|
1024
|
+
title: "A comment repeats the statement below",
|
|
1025
1025
|
outcome: "match",
|
|
1026
|
-
files: [{ path: "src/
|
|
1027
|
-
focusPath: "src/
|
|
1026
|
+
files: [{ path: "src/counter.ts", source: "// increment the counter\ncounter += 1;" }],
|
|
1027
|
+
focusPath: "src/counter.ts",
|
|
1028
1028
|
expectedCount: 1,
|
|
1029
1029
|
public: true
|
|
1030
1030
|
}
|
|
@@ -2517,6 +2517,25 @@ var hasThrowingCallOrNew = (node) => subtreeMatches(
|
|
|
2517
2517
|
function isBareCallStatement(stmt) {
|
|
2518
2518
|
return stmt.type === AST_NODE_TYPES9.ExpressionStatement && unwrap(stmt.expression).type === AST_NODE_TYPES9.CallExpression;
|
|
2519
2519
|
}
|
|
2520
|
+
function isSimpleCatchFinallyOrchestration(node) {
|
|
2521
|
+
const handler = node.handler;
|
|
2522
|
+
const finalizer = node.finalizer;
|
|
2523
|
+
return handler !== null && handler.param === null && isSingleSimpleCall(handler.body.body) && finalizer !== null && isSingleSimpleCall(finalizer.body);
|
|
2524
|
+
}
|
|
2525
|
+
function isSingleSimpleCall(body2) {
|
|
2526
|
+
const statement = body2[0];
|
|
2527
|
+
return body2.length === 1 && statement !== void 0 && isSimpleBareCallStatement(statement);
|
|
2528
|
+
}
|
|
2529
|
+
function isSimpleBareCallStatement(stmt) {
|
|
2530
|
+
if (!isBareCallStatement(stmt)) {
|
|
2531
|
+
return false;
|
|
2532
|
+
}
|
|
2533
|
+
return !subtreeMatches(
|
|
2534
|
+
stmt,
|
|
2535
|
+
(node) => node.type === AST_NODE_TYPES9.ArrowFunctionExpression || node.type === AST_NODE_TYPES9.FunctionExpression || node.type === AST_NODE_TYPES9.AssignmentExpression || node.type === AST_NODE_TYPES9.UpdateExpression || node.type === AST_NODE_TYPES9.AwaitExpression,
|
|
2536
|
+
true
|
|
2537
|
+
);
|
|
2538
|
+
}
|
|
2520
2539
|
function handlerRethrows(handler) {
|
|
2521
2540
|
if (handler === null) {
|
|
2522
2541
|
return false;
|
|
@@ -2688,6 +2707,9 @@ var no_fat_try_blocks_default = createRule({
|
|
|
2688
2707
|
if (handlerRethrows(node.handler)) {
|
|
2689
2708
|
return;
|
|
2690
2709
|
}
|
|
2710
|
+
if (isSimpleCatchFinallyOrchestration(node)) {
|
|
2711
|
+
return;
|
|
2712
|
+
}
|
|
2691
2713
|
if (isTerminalErrorBoundary(node)) {
|
|
2692
2714
|
return;
|
|
2693
2715
|
}
|
|
@@ -4141,8 +4163,51 @@ var noLongCommentDocumentation = {
|
|
|
4141
4163
|
category: "maintainability",
|
|
4142
4164
|
limitations: ["Only JSDoc blocks are inspected; structured API docs, tests, scripts, generated files, and versioned dependencies are excluded."],
|
|
4143
4165
|
examples: [
|
|
4144
|
-
{
|
|
4145
|
-
|
|
4166
|
+
{
|
|
4167
|
+
id: "structured-jsdoc",
|
|
4168
|
+
title: "Paragraphs separate a component's durable constraints",
|
|
4169
|
+
outcome: "no-match",
|
|
4170
|
+
files: [{
|
|
4171
|
+
path: "src/composer.ts",
|
|
4172
|
+
source: [
|
|
4173
|
+
"/**",
|
|
4174
|
+
" * Shared composer.",
|
|
4175
|
+
" *",
|
|
4176
|
+
" * It serves the room. It serves task comments. It stays visually calm. It accepts attachments.",
|
|
4177
|
+
" *",
|
|
4178
|
+
" * The `tone` prop supplies task styling. The `leadingTools` prop supplies controls.",
|
|
4179
|
+
" * The parent owns uploads. The component owns focus.",
|
|
4180
|
+
" */",
|
|
4181
|
+
"",
|
|
4182
|
+
"export const Composer = forwardRef(function Composer() { return null; });"
|
|
4183
|
+
].join("\n")
|
|
4184
|
+
}],
|
|
4185
|
+
focusPath: "src/composer.ts",
|
|
4186
|
+
expectedCount: 0,
|
|
4187
|
+
public: true
|
|
4188
|
+
},
|
|
4189
|
+
{
|
|
4190
|
+
id: "prose-wall",
|
|
4191
|
+
title: "One paragraph narrates a chart's design history",
|
|
4192
|
+
outcome: "match",
|
|
4193
|
+
files: [{
|
|
4194
|
+
path: "src/chart.ts",
|
|
4195
|
+
source: `/**
|
|
4196
|
+
* The ports chart shows arrivals and departures across the network.
|
|
4197
|
+
* It was originally a line chart, but the lines crossed too often.
|
|
4198
|
+
* Bars make adjacent ports easier to compare at a glance.
|
|
4199
|
+
* The axis starts at zero so visual differences stay proportional.
|
|
4200
|
+
* A single series uses the site navy for brand consistency.
|
|
4201
|
+
* Empty ports use a neutral ink so missing traffic remains visible.
|
|
4202
|
+
* Tooltip values repeat the units shown on the vertical axis.
|
|
4203
|
+
* The chart intentionally keeps labels horizontal on wide screens.
|
|
4204
|
+
*/
|
|
4205
|
+
export function PortBars() { return null; }`
|
|
4206
|
+
}],
|
|
4207
|
+
focusPath: "src/chart.ts",
|
|
4208
|
+
expectedCount: 1,
|
|
4209
|
+
public: true
|
|
4210
|
+
}
|
|
4146
4211
|
]
|
|
4147
4212
|
};
|
|
4148
4213
|
var EXCESSIVE_SENTENCE_COUNT = 8;
|
|
@@ -7426,10 +7491,10 @@ var noTypedDocSectionsDocumentation = {
|
|
|
7426
7491
|
public: true
|
|
7427
7492
|
},
|
|
7428
7493
|
{
|
|
7429
|
-
id: "
|
|
7430
|
-
title: "Do not
|
|
7494
|
+
id: "restated-parameter",
|
|
7495
|
+
title: "Do not expand a typed parameter's name",
|
|
7431
7496
|
outcome: "match",
|
|
7432
|
-
files: [{ path: "src/client.ts", source: "/** @param
|
|
7497
|
+
files: [{ path: "src/client.ts", source: "/** @param userId the user identifier */\nexport function fetchValue(userId: string): number { return 1; }" }],
|
|
7433
7498
|
focusPath: "src/client.ts",
|
|
7434
7499
|
expectedCount: 1,
|
|
7435
7500
|
public: true
|
|
@@ -10820,8 +10885,133 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
10820
10885
|
}
|
|
10821
10886
|
});
|
|
10822
10887
|
|
|
10888
|
+
// src/rules/prefer-await-in-async-return.ts
|
|
10889
|
+
import {
|
|
10890
|
+
ESLintUtils as ESLintUtils3,
|
|
10891
|
+
AST_NODE_TYPES as AST_NODE_TYPES45
|
|
10892
|
+
} from "@typescript-eslint/utils";
|
|
10893
|
+
import * as ts2 from "typescript";
|
|
10894
|
+
var preferAwaitInAsyncReturnDocumentation = {
|
|
10895
|
+
summary: "Prefer explicit `await` when an async function directly returns one typed Promise `.then` transform.",
|
|
10896
|
+
rationale: "Mixing a directly returned Promise callback into otherwise async control flow makes sequencing and failures harder to read.",
|
|
10897
|
+
remediation: "Await the Promise, then return the transformed value with ordinary async statements.",
|
|
10898
|
+
category: "maintainability",
|
|
10899
|
+
since: "15.6.3",
|
|
10900
|
+
limitations: [
|
|
10901
|
+
"Only a single directly returned `.then` call with an inline callback is checked.",
|
|
10902
|
+
"The receiver must be proven Promise-like by TypeScript; untyped files and larger chains are intentionally ignored."
|
|
10903
|
+
],
|
|
10904
|
+
examples: [
|
|
10905
|
+
{
|
|
10906
|
+
id: "explicit-async-transform",
|
|
10907
|
+
title: "Use explicit async control flow",
|
|
10908
|
+
outcome: "no-match",
|
|
10909
|
+
files: [{
|
|
10910
|
+
path: "src/load.ts",
|
|
10911
|
+
source: "async function load() { const value = await Promise.resolve(1); return value + 1; }"
|
|
10912
|
+
}],
|
|
10913
|
+
focusPath: "src/load.ts",
|
|
10914
|
+
expectedCount: 0,
|
|
10915
|
+
public: true
|
|
10916
|
+
},
|
|
10917
|
+
{
|
|
10918
|
+
id: "returned-then-transform",
|
|
10919
|
+
title: "Do not directly return a Promise callback chain from async code",
|
|
10920
|
+
outcome: "match",
|
|
10921
|
+
files: [{
|
|
10922
|
+
path: "src/load.ts",
|
|
10923
|
+
source: "async function load() { return Promise.resolve(1).then((value) => value + 1); }"
|
|
10924
|
+
}],
|
|
10925
|
+
focusPath: "src/load.ts",
|
|
10926
|
+
expectedCount: 1,
|
|
10927
|
+
public: true
|
|
10928
|
+
}
|
|
10929
|
+
]
|
|
10930
|
+
};
|
|
10931
|
+
function isDirectAsyncReturn(node) {
|
|
10932
|
+
const parent = node.parent;
|
|
10933
|
+
if (parent.type === AST_NODE_TYPES45.ArrowFunctionExpression && parent.body === node) {
|
|
10934
|
+
return parent.async && !parent.generator;
|
|
10935
|
+
}
|
|
10936
|
+
if (parent.type !== AST_NODE_TYPES45.ReturnStatement || parent.argument !== node) {
|
|
10937
|
+
return false;
|
|
10938
|
+
}
|
|
10939
|
+
let owner = parent.parent;
|
|
10940
|
+
while (owner !== void 0 && !isRuntimeFunction(owner)) {
|
|
10941
|
+
owner = owner.parent;
|
|
10942
|
+
}
|
|
10943
|
+
return owner !== void 0 && owner.async && !owner.generator;
|
|
10944
|
+
}
|
|
10945
|
+
function isRuntimeFunction(node) {
|
|
10946
|
+
return node.type === AST_NODE_TYPES45.ArrowFunctionExpression || node.type === AST_NODE_TYPES45.FunctionDeclaration || node.type === AST_NODE_TYPES45.FunctionExpression;
|
|
10947
|
+
}
|
|
10948
|
+
function promiseThenReceiver(node) {
|
|
10949
|
+
const callee = node.callee;
|
|
10950
|
+
if (callee.type !== AST_NODE_TYPES45.MemberExpression || callee.computed || callee.optional || callee.property.type !== AST_NODE_TYPES45.Identifier || callee.property.name !== "then" || node.optional || node.arguments.length !== 1) {
|
|
10951
|
+
return null;
|
|
10952
|
+
}
|
|
10953
|
+
const callback = node.arguments[0];
|
|
10954
|
+
if (callback === void 0 || callback.type !== AST_NODE_TYPES45.ArrowFunctionExpression && callback.type !== AST_NODE_TYPES45.FunctionExpression) {
|
|
10955
|
+
return null;
|
|
10956
|
+
}
|
|
10957
|
+
return callee.object;
|
|
10958
|
+
}
|
|
10959
|
+
function isProvenPromiseLike(node, services) {
|
|
10960
|
+
const checker = services.program.getTypeChecker();
|
|
10961
|
+
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
|
10962
|
+
const receiverType = checker.getTypeAtLocation(tsNode);
|
|
10963
|
+
if ((receiverType.flags & (ts2.TypeFlags.Any | ts2.TypeFlags.Unknown | ts2.TypeFlags.Never)) !== 0) {
|
|
10964
|
+
return false;
|
|
10965
|
+
}
|
|
10966
|
+
const thenSymbol = checker.getPropertyOfType(receiverType, "then");
|
|
10967
|
+
const hasBuiltInPromiseDeclaration = thenSymbol?.declarations?.some(
|
|
10968
|
+
(declaration) => {
|
|
10969
|
+
let owner = declaration.parent;
|
|
10970
|
+
while (owner !== void 0 && !ts2.isInterfaceDeclaration(owner)) {
|
|
10971
|
+
owner = owner.parent;
|
|
10972
|
+
}
|
|
10973
|
+
return owner !== void 0 && (owner.name.text === "Promise" || owner.name.text === "PromiseLike") && services.program.isSourceFileDefaultLibrary(owner.getSourceFile());
|
|
10974
|
+
}
|
|
10975
|
+
) ?? false;
|
|
10976
|
+
return hasBuiltInPromiseDeclaration;
|
|
10977
|
+
}
|
|
10978
|
+
var prefer_await_in_async_return_default = createRule({
|
|
10979
|
+
name: "prefer-await-in-async-return",
|
|
10980
|
+
documentation: preferAwaitInAsyncReturnDocumentation,
|
|
10981
|
+
meta: {
|
|
10982
|
+
type: "suggestion",
|
|
10983
|
+
docs: {
|
|
10984
|
+
description: "Prefer explicit `await` when an async function directly returns one typed Promise `.then` transform."
|
|
10985
|
+
},
|
|
10986
|
+
schema: [],
|
|
10987
|
+
messages: {
|
|
10988
|
+
preferAwait: "This async function directly returns a Promise `.then` transform. Await the Promise, then return the transformed value with explicit async control flow."
|
|
10989
|
+
}
|
|
10990
|
+
},
|
|
10991
|
+
defaultOptions: [],
|
|
10992
|
+
create(context) {
|
|
10993
|
+
let services;
|
|
10994
|
+
try {
|
|
10995
|
+
services = ESLintUtils3.getParserServices(context);
|
|
10996
|
+
} catch {
|
|
10997
|
+
services = null;
|
|
10998
|
+
}
|
|
10999
|
+
if (services === null) return {};
|
|
11000
|
+
return {
|
|
11001
|
+
CallExpression(node) {
|
|
11002
|
+
if (!isDirectAsyncReturn(node)) return;
|
|
11003
|
+
const receiver = promiseThenReceiver(node);
|
|
11004
|
+
if (receiver === null || !isProvenPromiseLike(receiver, services)) {
|
|
11005
|
+
return;
|
|
11006
|
+
}
|
|
11007
|
+
context.report({ node, messageId: "preferAwait" });
|
|
11008
|
+
}
|
|
11009
|
+
};
|
|
11010
|
+
}
|
|
11011
|
+
});
|
|
11012
|
+
|
|
10823
11013
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
10824
|
-
import { AST_NODE_TYPES as
|
|
11014
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES46 } from "@typescript-eslint/utils";
|
|
10825
11015
|
var preferSchemaForApiPayloadDocumentation = {
|
|
10826
11016
|
summary: "Require Zod (or similar) schema validation on `response.json()` / `JSON.parse()` results before property access.",
|
|
10827
11017
|
rationale: "External JSON is untrusted at runtime even when its expected TypeScript shape is known statically.",
|
|
@@ -10836,9 +11026,9 @@ var preferSchemaForApiPayloadDocumentation = {
|
|
|
10836
11026
|
var unwrap4 = (node) => {
|
|
10837
11027
|
let current = node;
|
|
10838
11028
|
while (current !== null && current !== void 0) {
|
|
10839
|
-
if (current.type ===
|
|
11029
|
+
if (current.type === AST_NODE_TYPES46.TSAsExpression || current.type === AST_NODE_TYPES46.TSTypeAssertion || current.type === AST_NODE_TYPES46.TSNonNullExpression || current.type === AST_NODE_TYPES46.TSSatisfiesExpression) {
|
|
10840
11030
|
current = current.expression;
|
|
10841
|
-
} else if (current.type ===
|
|
11031
|
+
} else if (current.type === AST_NODE_TYPES46.ChainExpression) {
|
|
10842
11032
|
current = current.expression;
|
|
10843
11033
|
} else {
|
|
10844
11034
|
break;
|
|
@@ -10853,23 +11043,23 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
10853
11043
|
]);
|
|
10854
11044
|
var isSchemaParseReference = (node) => {
|
|
10855
11045
|
const inner = unwrap4(node);
|
|
10856
|
-
return inner !== null && inner.type ===
|
|
11046
|
+
return inner !== null && inner.type === AST_NODE_TYPES46.MemberExpression && !inner.computed && inner.property.type === AST_NODE_TYPES46.Identifier && (inner.property.name === "parse" || inner.property.name === "safeParse");
|
|
10857
11047
|
};
|
|
10858
11048
|
var isRawPayloadSource = (node, isKnownLocalText) => {
|
|
10859
11049
|
let current = unwrap4(node);
|
|
10860
11050
|
if (current === null) return false;
|
|
10861
|
-
if (current.type ===
|
|
11051
|
+
if (current.type === AST_NODE_TYPES46.AwaitExpression) {
|
|
10862
11052
|
current = unwrap4(current.argument);
|
|
10863
11053
|
}
|
|
10864
|
-
if (current === null || current.type !==
|
|
11054
|
+
if (current === null || current.type !== AST_NODE_TYPES46.CallExpression) {
|
|
10865
11055
|
return false;
|
|
10866
11056
|
}
|
|
10867
11057
|
const callee = unwrap4(current.callee);
|
|
10868
|
-
if (callee === null || callee.type !==
|
|
11058
|
+
if (callee === null || callee.type !== AST_NODE_TYPES46.MemberExpression) {
|
|
10869
11059
|
return false;
|
|
10870
11060
|
}
|
|
10871
11061
|
const property = unwrap4(callee.property);
|
|
10872
|
-
if (property === null || property.type !==
|
|
11062
|
+
if (property === null || property.type !== AST_NODE_TYPES46.Identifier) {
|
|
10873
11063
|
return false;
|
|
10874
11064
|
}
|
|
10875
11065
|
if (property.name === "json") {
|
|
@@ -10879,17 +11069,17 @@ var isRawPayloadSource = (node, isKnownLocalText) => {
|
|
|
10879
11069
|
return !current.arguments.some(isSchemaParseReference) && isRawPayloadSource(callee.object);
|
|
10880
11070
|
}
|
|
10881
11071
|
const object = unwrap4(callee.object);
|
|
10882
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
11072
|
+
return property.name === "parse" && object !== null && object.type === AST_NODE_TYPES46.Identifier && object.name === "JSON" && !isLocalFileRead(current.arguments[0]) && isKnownLocalText?.(current.arguments[0]) !== true;
|
|
10883
11073
|
};
|
|
10884
11074
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
10885
11075
|
var isDirectLocalFileRead = (node) => {
|
|
10886
11076
|
let current = unwrap4(node);
|
|
10887
|
-
if (current?.type ===
|
|
11077
|
+
if (current?.type === AST_NODE_TYPES46.AwaitExpression) {
|
|
10888
11078
|
current = unwrap4(current.argument);
|
|
10889
11079
|
}
|
|
10890
|
-
if (current?.type !==
|
|
11080
|
+
if (current?.type !== AST_NODE_TYPES46.CallExpression) return false;
|
|
10891
11081
|
const callee = unwrap4(current.callee);
|
|
10892
|
-
const name = callee?.type ===
|
|
11082
|
+
const name = callee?.type === AST_NODE_TYPES46.Identifier ? callee.name : callee?.type === AST_NODE_TYPES46.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES46.Identifier ? callee.property.name : null;
|
|
10893
11083
|
return name !== null && FILE_READ_RE.test(name);
|
|
10894
11084
|
};
|
|
10895
11085
|
var isLocalFileRead = (node) => {
|
|
@@ -10916,15 +11106,15 @@ var isLocalFileRead = (node) => {
|
|
|
10916
11106
|
var ASSERTION_CALLEE_RE = /^(expect|assert|should|invariant)$/;
|
|
10917
11107
|
var isInsideAssertion = (node) => {
|
|
10918
11108
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
10919
|
-
if (current.type !==
|
|
11109
|
+
if (current.type !== AST_NODE_TYPES46.CallExpression) continue;
|
|
10920
11110
|
let callee = current.callee;
|
|
10921
|
-
while (callee.type ===
|
|
11111
|
+
while (callee.type === AST_NODE_TYPES46.MemberExpression) {
|
|
10922
11112
|
callee = callee.object;
|
|
10923
11113
|
}
|
|
10924
|
-
if (callee.type ===
|
|
11114
|
+
if (callee.type === AST_NODE_TYPES46.CallExpression) {
|
|
10925
11115
|
callee = callee.callee;
|
|
10926
11116
|
}
|
|
10927
|
-
if (callee.type ===
|
|
11117
|
+
if (callee.type === AST_NODE_TYPES46.Identifier && ASSERTION_CALLEE_RE.test(callee.name)) {
|
|
10928
11118
|
return true;
|
|
10929
11119
|
}
|
|
10930
11120
|
}
|
|
@@ -10943,22 +11133,22 @@ var GUARD_NAME_RE = /^(?:is|validate|parse|assert|decode|coerce)[A-Z]/;
|
|
|
10943
11133
|
var isValidationRead = (node) => {
|
|
10944
11134
|
let current = node;
|
|
10945
11135
|
let parent = current.parent;
|
|
10946
|
-
while (parent !== null && parent !== void 0 && (parent.type ===
|
|
11136
|
+
while (parent !== null && parent !== void 0 && (parent.type === AST_NODE_TYPES46.TSAsExpression || parent.type === AST_NODE_TYPES46.TSTypeAssertion || parent.type === AST_NODE_TYPES46.TSNonNullExpression || parent.type === AST_NODE_TYPES46.TSSatisfiesExpression || parent.type === AST_NODE_TYPES46.ChainExpression)) {
|
|
10947
11137
|
current = parent;
|
|
10948
11138
|
parent = parent.parent;
|
|
10949
11139
|
}
|
|
10950
11140
|
if (parent === null || parent === void 0) return false;
|
|
10951
|
-
if (parent.type ===
|
|
11141
|
+
if (parent.type === AST_NODE_TYPES46.UnaryExpression && parent.operator === "typeof" && parent.argument === current) {
|
|
10952
11142
|
return true;
|
|
10953
11143
|
}
|
|
10954
|
-
if (parent.type !==
|
|
11144
|
+
if (parent.type !== AST_NODE_TYPES46.CallExpression || !parent.arguments.some((arg) => arg === current)) {
|
|
10955
11145
|
return false;
|
|
10956
11146
|
}
|
|
10957
11147
|
const callee = parent.callee;
|
|
10958
|
-
if (callee.type ===
|
|
11148
|
+
if (callee.type === AST_NODE_TYPES46.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES46.Identifier && callee.object.name === "Array" && callee.property.type === AST_NODE_TYPES46.Identifier && callee.property.name === "isArray") {
|
|
10959
11149
|
return parent.arguments.length === 1;
|
|
10960
11150
|
}
|
|
10961
|
-
return callee.type ===
|
|
11151
|
+
return callee.type === AST_NODE_TYPES46.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
10962
11152
|
};
|
|
10963
11153
|
var PRIMITIVE_TYPEOF_RESULTS = /* @__PURE__ */ new Set([
|
|
10964
11154
|
"bigint",
|
|
@@ -10969,13 +11159,13 @@ var PRIMITIVE_TYPEOF_RESULTS = /* @__PURE__ */ new Set([
|
|
|
10969
11159
|
"undefined"
|
|
10970
11160
|
]);
|
|
10971
11161
|
var bindingValidationPolarity = (test, bindingName) => {
|
|
10972
|
-
if (test.type ===
|
|
11162
|
+
if (test.type === AST_NODE_TYPES46.UnaryExpression && test.operator === "!") {
|
|
10973
11163
|
const inner = bindingValidationPolarity(test.argument, bindingName);
|
|
10974
11164
|
return inner === "valid-when-true" ? "valid-when-false" : inner === "valid-when-false" ? "valid-when-true" : null;
|
|
10975
11165
|
}
|
|
10976
|
-
if (test.type ===
|
|
10977
|
-
const typeofName = (node) => node.type ===
|
|
10978
|
-
const literalType = (node) => node.type ===
|
|
11166
|
+
if (test.type === AST_NODE_TYPES46.BinaryExpression) {
|
|
11167
|
+
const typeofName = (node) => node.type === AST_NODE_TYPES46.UnaryExpression && node.operator === "typeof" && node.argument.type === AST_NODE_TYPES46.Identifier ? node.argument.name : null;
|
|
11168
|
+
const literalType = (node) => node.type === AST_NODE_TYPES46.Literal && typeof node.value === "string" && PRIMITIVE_TYPEOF_RESULTS.has(node.value) ? node.value : null;
|
|
10979
11169
|
const matches = typeofName(test.left) === bindingName && literalType(test.right) !== null || typeofName(test.right) === bindingName && literalType(test.left) !== null;
|
|
10980
11170
|
if (!matches) return null;
|
|
10981
11171
|
if (test.operator === "===" || test.operator === "==") {
|
|
@@ -10983,9 +11173,9 @@ var bindingValidationPolarity = (test, bindingName) => {
|
|
|
10983
11173
|
}
|
|
10984
11174
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
10985
11175
|
}
|
|
10986
|
-
return test.type ===
|
|
11176
|
+
return test.type === AST_NODE_TYPES46.CallExpression && test.arguments.length === 1 && test.arguments[0]?.type === AST_NODE_TYPES46.Identifier && test.arguments[0].name === bindingName && test.callee.type === AST_NODE_TYPES46.MemberExpression && !test.callee.computed && test.callee.object.type === AST_NODE_TYPES46.Identifier && test.callee.object.name === "Array" && test.callee.property.type === AST_NODE_TYPES46.Identifier && test.callee.property.name === "isArray" ? "valid-when-true" : null;
|
|
10987
11177
|
};
|
|
10988
|
-
var plainMemberAccess = (node) => node.type ===
|
|
11178
|
+
var plainMemberAccess = (node) => node.type === AST_NODE_TYPES46.MemberExpression && !node.computed && node.object.type === AST_NODE_TYPES46.Identifier && node.property.type === AST_NODE_TYPES46.Identifier ? { object: node.object.name, property: node.property.name } : null;
|
|
10989
11179
|
var isSamePlainMember = (node, access) => {
|
|
10990
11180
|
const candidate = plainMemberAccess(node);
|
|
10991
11181
|
return candidate !== null && candidate.object === access.object && candidate.property === access.property;
|
|
@@ -10993,19 +11183,19 @@ var isSamePlainMember = (node, access) => {
|
|
|
10993
11183
|
var nodeWithin2 = (node, container) => node.range[0] >= container.range[0] && node.range[1] <= container.range[1];
|
|
10994
11184
|
var isUseWithinValidatedBranch = (node, bindingName) => {
|
|
10995
11185
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
10996
|
-
if (current.type ===
|
|
11186
|
+
if (current.type === AST_NODE_TYPES46.ConditionalExpression) {
|
|
10997
11187
|
const polarity = bindingValidationPolarity(current.test, bindingName);
|
|
10998
11188
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && nodeWithin2(node, current.alternate)) {
|
|
10999
11189
|
return true;
|
|
11000
11190
|
}
|
|
11001
11191
|
}
|
|
11002
|
-
if (current.type ===
|
|
11192
|
+
if (current.type === AST_NODE_TYPES46.IfStatement) {
|
|
11003
11193
|
const polarity = bindingValidationPolarity(current.test, bindingName);
|
|
11004
11194
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && current.alternate !== null && nodeWithin2(node, current.alternate)) {
|
|
11005
11195
|
return true;
|
|
11006
11196
|
}
|
|
11007
11197
|
}
|
|
11008
|
-
if (current.type ===
|
|
11198
|
+
if (current.type === AST_NODE_TYPES46.FunctionDeclaration || current.type === AST_NODE_TYPES46.FunctionExpression || current.type === AST_NODE_TYPES46.ArrowFunctionExpression) {
|
|
11009
11199
|
return false;
|
|
11010
11200
|
}
|
|
11011
11201
|
}
|
|
@@ -11013,32 +11203,32 @@ var isUseWithinValidatedBranch = (node, bindingName) => {
|
|
|
11013
11203
|
};
|
|
11014
11204
|
var isMemberUseWithinValidatedBranch = (node, access) => {
|
|
11015
11205
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11016
|
-
if (current.type ===
|
|
11206
|
+
if (current.type === AST_NODE_TYPES46.ConditionalExpression) {
|
|
11017
11207
|
const polarity = memberValidationPolarity(current.test, access);
|
|
11018
11208
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && nodeWithin2(node, current.alternate)) {
|
|
11019
11209
|
return true;
|
|
11020
11210
|
}
|
|
11021
11211
|
}
|
|
11022
|
-
if (current.type ===
|
|
11212
|
+
if (current.type === AST_NODE_TYPES46.IfStatement) {
|
|
11023
11213
|
const polarity = memberValidationPolarity(current.test, access);
|
|
11024
11214
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && current.alternate !== null && nodeWithin2(node, current.alternate)) {
|
|
11025
11215
|
return true;
|
|
11026
11216
|
}
|
|
11027
11217
|
}
|
|
11028
|
-
if (current.type ===
|
|
11218
|
+
if (current.type === AST_NODE_TYPES46.FunctionDeclaration || current.type === AST_NODE_TYPES46.FunctionExpression || current.type === AST_NODE_TYPES46.ArrowFunctionExpression) {
|
|
11029
11219
|
return false;
|
|
11030
11220
|
}
|
|
11031
11221
|
}
|
|
11032
11222
|
return false;
|
|
11033
11223
|
};
|
|
11034
11224
|
var memberValidationPolarity = (test, access) => {
|
|
11035
|
-
if (test.type ===
|
|
11225
|
+
if (test.type === AST_NODE_TYPES46.UnaryExpression && test.operator === "!") {
|
|
11036
11226
|
const inner = memberValidationPolarity(test.argument, access);
|
|
11037
11227
|
return inner === "valid-when-true" ? "valid-when-false" : inner === "valid-when-false" ? "valid-when-true" : null;
|
|
11038
11228
|
}
|
|
11039
|
-
if (test.type ===
|
|
11040
|
-
const isMatchingTypeof = (node) => node.type ===
|
|
11041
|
-
const isPrimitiveType = (node) => node.type ===
|
|
11229
|
+
if (test.type === AST_NODE_TYPES46.BinaryExpression) {
|
|
11230
|
+
const isMatchingTypeof = (node) => node.type === AST_NODE_TYPES46.UnaryExpression && node.operator === "typeof" && isSamePlainMember(node.argument, access);
|
|
11231
|
+
const isPrimitiveType = (node) => node.type === AST_NODE_TYPES46.Literal && typeof node.value === "string" && PRIMITIVE_TYPEOF_RESULTS.has(node.value);
|
|
11042
11232
|
if (!(isMatchingTypeof(test.left) && isPrimitiveType(test.right) || isMatchingTypeof(test.right) && isPrimitiveType(test.left))) {
|
|
11043
11233
|
return null;
|
|
11044
11234
|
}
|
|
@@ -11047,15 +11237,15 @@ var memberValidationPolarity = (test, access) => {
|
|
|
11047
11237
|
}
|
|
11048
11238
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
11049
11239
|
}
|
|
11050
|
-
return test.type ===
|
|
11240
|
+
return test.type === AST_NODE_TYPES46.CallExpression && test.arguments.length === 1 && test.arguments[0] !== void 0 && test.arguments[0].type !== AST_NODE_TYPES46.SpreadElement && isSamePlainMember(test.arguments[0], access) && test.callee.type === AST_NODE_TYPES46.MemberExpression && !test.callee.computed && test.callee.object.type === AST_NODE_TYPES46.Identifier && test.callee.object.name === "Array" && test.callee.property.type === AST_NODE_TYPES46.Identifier && test.callee.property.name === "isArray" ? "valid-when-true" : null;
|
|
11051
11241
|
};
|
|
11052
11242
|
var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
11053
11243
|
const isValidationReference = (identifier) => {
|
|
11054
11244
|
for (let current = identifier.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11055
|
-
if ((current.type ===
|
|
11245
|
+
if ((current.type === AST_NODE_TYPES46.BinaryExpression || current.type === AST_NODE_TYPES46.CallExpression || current.type === AST_NODE_TYPES46.UnaryExpression) && bindingValidationPolarity(current, identifier.name) !== null) {
|
|
11056
11246
|
return true;
|
|
11057
11247
|
}
|
|
11058
|
-
if (current.type !==
|
|
11248
|
+
if (current.type !== AST_NODE_TYPES46.UnaryExpression && current.type !== AST_NODE_TYPES46.MemberExpression && current.type !== AST_NODE_TYPES46.CallExpression) {
|
|
11059
11249
|
return false;
|
|
11060
11250
|
}
|
|
11061
11251
|
}
|
|
@@ -11063,7 +11253,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11063
11253
|
};
|
|
11064
11254
|
const isGuardedUse = (identifier) => {
|
|
11065
11255
|
for (let current = identifier.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11066
|
-
if (current.type ===
|
|
11256
|
+
if (current.type === AST_NODE_TYPES46.ConditionalExpression) {
|
|
11067
11257
|
const polarity = bindingValidationPolarity(current.test, identifier.name);
|
|
11068
11258
|
if (polarity === "valid-when-true" && nodeWithin2(identifier, current.consequent)) {
|
|
11069
11259
|
return true;
|
|
@@ -11072,7 +11262,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11072
11262
|
return true;
|
|
11073
11263
|
}
|
|
11074
11264
|
}
|
|
11075
|
-
if (current.type ===
|
|
11265
|
+
if (current.type === AST_NODE_TYPES46.IfStatement) {
|
|
11076
11266
|
const polarity = bindingValidationPolarity(current.test, identifier.name);
|
|
11077
11267
|
if (polarity === "valid-when-true" && nodeWithin2(identifier, current.consequent)) {
|
|
11078
11268
|
return true;
|
|
@@ -11081,14 +11271,14 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11081
11271
|
return true;
|
|
11082
11272
|
}
|
|
11083
11273
|
}
|
|
11084
|
-
if (current.type ===
|
|
11274
|
+
if (current.type === AST_NODE_TYPES46.FunctionDeclaration || current.type === AST_NODE_TYPES46.FunctionExpression || current.type === AST_NODE_TYPES46.ArrowFunctionExpression) {
|
|
11085
11275
|
return false;
|
|
11086
11276
|
}
|
|
11087
11277
|
}
|
|
11088
11278
|
return false;
|
|
11089
11279
|
};
|
|
11090
11280
|
const declarator = member.parent;
|
|
11091
|
-
if (declarator.type !==
|
|
11281
|
+
if (declarator.type !== AST_NODE_TYPES46.VariableDeclarator || declarator.init !== member || declarator.id.type !== AST_NODE_TYPES46.Identifier || declarator.parent.type !== AST_NODE_TYPES46.VariableDeclaration || declarator.parent.kind !== "const") {
|
|
11092
11282
|
return false;
|
|
11093
11283
|
}
|
|
11094
11284
|
const extracted = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
@@ -11096,7 +11286,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11096
11286
|
let hasValueUse = false;
|
|
11097
11287
|
for (const reference of extracted.references) {
|
|
11098
11288
|
const identifier = reference.identifier;
|
|
11099
|
-
if (identifier.type !==
|
|
11289
|
+
if (identifier.type !== AST_NODE_TYPES46.Identifier) return false;
|
|
11100
11290
|
if (nodeWithin2(identifier, declarator)) continue;
|
|
11101
11291
|
if (isValidationReference(identifier)) continue;
|
|
11102
11292
|
hasValueUse = true;
|
|
@@ -11109,17 +11299,17 @@ var isGuardTestPosition = (node) => {
|
|
|
11109
11299
|
let parent = current.parent;
|
|
11110
11300
|
while (parent !== void 0 && parent !== null) {
|
|
11111
11301
|
switch (parent.type) {
|
|
11112
|
-
case
|
|
11113
|
-
case
|
|
11114
|
-
case
|
|
11302
|
+
case AST_NODE_TYPES46.UnaryExpression:
|
|
11303
|
+
case AST_NODE_TYPES46.LogicalExpression:
|
|
11304
|
+
case AST_NODE_TYPES46.ChainExpression:
|
|
11115
11305
|
current = parent;
|
|
11116
11306
|
parent = parent.parent;
|
|
11117
11307
|
continue;
|
|
11118
|
-
case
|
|
11119
|
-
case
|
|
11120
|
-
case
|
|
11121
|
-
case
|
|
11122
|
-
case
|
|
11308
|
+
case AST_NODE_TYPES46.IfStatement:
|
|
11309
|
+
case AST_NODE_TYPES46.ConditionalExpression:
|
|
11310
|
+
case AST_NODE_TYPES46.WhileStatement:
|
|
11311
|
+
case AST_NODE_TYPES46.DoWhileStatement:
|
|
11312
|
+
case AST_NODE_TYPES46.ForStatement:
|
|
11123
11313
|
return parent.test === current;
|
|
11124
11314
|
default:
|
|
11125
11315
|
return false;
|
|
@@ -11129,7 +11319,7 @@ var isGuardTestPosition = (node) => {
|
|
|
11129
11319
|
};
|
|
11130
11320
|
var unvalidatedVariableRef = (node, scope, tracked) => {
|
|
11131
11321
|
const unwrapped = unwrap4(node);
|
|
11132
|
-
if (unwrapped === null || unwrapped.type !==
|
|
11322
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES46.Identifier) {
|
|
11133
11323
|
return null;
|
|
11134
11324
|
}
|
|
11135
11325
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -11158,7 +11348,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11158
11348
|
const localFileTextVariables = /* @__PURE__ */ new Set();
|
|
11159
11349
|
const localFileTextRef = (node, scope) => {
|
|
11160
11350
|
const unwrapped = unwrap4(node);
|
|
11161
|
-
if (unwrapped?.type !==
|
|
11351
|
+
if (unwrapped?.type !== AST_NODE_TYPES46.Identifier) return null;
|
|
11162
11352
|
const variable = findVariable2(scope, unwrapped.name);
|
|
11163
11353
|
return variable !== null && localFileTextVariables.has(variable) ? variable : null;
|
|
11164
11354
|
};
|
|
@@ -11227,7 +11417,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11227
11417
|
return {
|
|
11228
11418
|
VariableDeclarator(node) {
|
|
11229
11419
|
const scope = context.sourceCode.getScope(node);
|
|
11230
|
-
if (node.id.type ===
|
|
11420
|
+
if (node.id.type === AST_NODE_TYPES46.Identifier) {
|
|
11231
11421
|
const variable = context.sourceCode.getDeclaredVariables(node)[0];
|
|
11232
11422
|
if (variable !== void 0) {
|
|
11233
11423
|
updateLocalFileText(variable, node.init, scope);
|
|
@@ -11235,7 +11425,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11235
11425
|
trackInitializer(node, scope);
|
|
11236
11426
|
return;
|
|
11237
11427
|
}
|
|
11238
|
-
if (node.id.type ===
|
|
11428
|
+
if (node.id.type === AST_NODE_TYPES46.ObjectPattern || node.id.type === AST_NODE_TYPES46.ArrayPattern) {
|
|
11239
11429
|
if (isRawPayloadSource(
|
|
11240
11430
|
node.init,
|
|
11241
11431
|
(candidate) => localFileTextRef(candidate, scope) !== null
|
|
@@ -11252,7 +11442,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11252
11442
|
},
|
|
11253
11443
|
AssignmentExpression(node) {
|
|
11254
11444
|
const scope = context.sourceCode.getScope(node);
|
|
11255
|
-
if (node.left.type ===
|
|
11445
|
+
if (node.left.type === AST_NODE_TYPES46.Identifier) {
|
|
11256
11446
|
const variable = findVariable2(scope, node.left.name);
|
|
11257
11447
|
if (variable === null) return;
|
|
11258
11448
|
const isLocalText = (candidate) => localFileTextRef(candidate, scope) !== null;
|
|
@@ -11266,7 +11456,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11266
11456
|
}
|
|
11267
11457
|
return;
|
|
11268
11458
|
}
|
|
11269
|
-
if (node.left.type ===
|
|
11459
|
+
if (node.left.type === AST_NODE_TYPES46.ObjectPattern || node.left.type === AST_NODE_TYPES46.ArrayPattern) {
|
|
11270
11460
|
if (isRawPayloadSource(
|
|
11271
11461
|
node.right,
|
|
11272
11462
|
(candidate) => localFileTextRef(candidate, scope) !== null
|
|
@@ -11286,15 +11476,15 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11286
11476
|
}
|
|
11287
11477
|
},
|
|
11288
11478
|
CallExpression(node) {
|
|
11289
|
-
if (node.callee.type !==
|
|
11479
|
+
if (node.callee.type !== AST_NODE_TYPES46.Identifier) return;
|
|
11290
11480
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
11291
11481
|
return;
|
|
11292
11482
|
}
|
|
11293
11483
|
const scope = context.sourceCode.getScope(node);
|
|
11294
11484
|
for (const arg of node.arguments) {
|
|
11295
|
-
if (arg.type ===
|
|
11485
|
+
if (arg.type === AST_NODE_TYPES46.SpreadElement) continue;
|
|
11296
11486
|
const unwrapped = unwrap4(arg);
|
|
11297
|
-
if (unwrapped === null || unwrapped.type !==
|
|
11487
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES46.Identifier) {
|
|
11298
11488
|
continue;
|
|
11299
11489
|
}
|
|
11300
11490
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -11311,14 +11501,14 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11311
11501
|
(candidate) => localFileTextRef(candidate, scope) !== null
|
|
11312
11502
|
)) {
|
|
11313
11503
|
const parent = node.parent;
|
|
11314
|
-
if (parent.type ===
|
|
11504
|
+
if (parent.type === AST_NODE_TYPES46.CallExpression && parent.callee === node && node.property.type === AST_NODE_TYPES46.Identifier && (node.property.name === "parse" || node.property.name === "safeParse" || PROMISE_CHAIN_METHODS.has(node.property.name))) {
|
|
11315
11505
|
return;
|
|
11316
11506
|
}
|
|
11317
11507
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
11318
11508
|
return;
|
|
11319
11509
|
}
|
|
11320
|
-
const variable = obj?.type ===
|
|
11321
|
-
if (variable !== null && obj?.type ===
|
|
11510
|
+
const variable = obj?.type === AST_NODE_TYPES46.Identifier ? unvalidatedVariableRef(obj, scope, unvalidatedVariables) : null;
|
|
11511
|
+
if (variable !== null && obj?.type === AST_NODE_TYPES46.Identifier) {
|
|
11322
11512
|
if (isUseWithinValidatedBranch(node, obj.name)) {
|
|
11323
11513
|
return;
|
|
11324
11514
|
}
|
|
@@ -11338,7 +11528,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11338
11528
|
});
|
|
11339
11529
|
|
|
11340
11530
|
// src/rules/prefer-semantic-colors.ts
|
|
11341
|
-
import { AST_NODE_TYPES as
|
|
11531
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES47 } from "@typescript-eslint/utils";
|
|
11342
11532
|
import { existsSync, readdirSync, readFileSync } from "fs";
|
|
11343
11533
|
import { dirname, join, parse } from "path";
|
|
11344
11534
|
|
|
@@ -11450,7 +11640,7 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
11450
11640
|
var isInsideSvg = (node) => {
|
|
11451
11641
|
let current = node.parent;
|
|
11452
11642
|
while (current !== void 0 && current !== null) {
|
|
11453
|
-
if (current.type ===
|
|
11643
|
+
if (current.type === AST_NODE_TYPES47.JSXElement) {
|
|
11454
11644
|
const name = jsxElementName(current);
|
|
11455
11645
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
11456
11646
|
}
|
|
@@ -11460,8 +11650,8 @@ var isInsideSvg = (node) => {
|
|
|
11460
11650
|
};
|
|
11461
11651
|
function jsxElementName(node) {
|
|
11462
11652
|
const name = node.openingElement.name;
|
|
11463
|
-
if (name.type ===
|
|
11464
|
-
if (name.type ===
|
|
11653
|
+
if (name.type === AST_NODE_TYPES47.JSXIdentifier) return name.name;
|
|
11654
|
+
if (name.type === AST_NODE_TYPES47.JSXMemberExpression && name.property.type === AST_NODE_TYPES47.JSXIdentifier) {
|
|
11465
11655
|
return name.property.name;
|
|
11466
11656
|
}
|
|
11467
11657
|
return null;
|
|
@@ -11487,7 +11677,7 @@ function isSvgLikeElementName(name) {
|
|
|
11487
11677
|
var isInsideIconFactoryPath = (node) => {
|
|
11488
11678
|
let current = node.parent;
|
|
11489
11679
|
while (current !== void 0 && current !== null) {
|
|
11490
|
-
if (current.type ===
|
|
11680
|
+
if (current.type === AST_NODE_TYPES47.Property && propName(current.key) === "path" && current.parent.type === AST_NODE_TYPES47.ObjectExpression && current.parent.parent.type === AST_NODE_TYPES47.CallExpression && current.parent.parent.callee.type === AST_NODE_TYPES47.Identifier && current.parent.parent.callee.name === "createIcon") {
|
|
11491
11681
|
return true;
|
|
11492
11682
|
}
|
|
11493
11683
|
current = current.parent;
|
|
@@ -11621,12 +11811,12 @@ var expandWorkspaceGlob = (root, glob) => {
|
|
|
11621
11811
|
return readdirSync(parent, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => join(parent, entry.name));
|
|
11622
11812
|
};
|
|
11623
11813
|
var propName = (key) => {
|
|
11624
|
-
if (key.type ===
|
|
11625
|
-
if (key.type ===
|
|
11814
|
+
if (key.type === AST_NODE_TYPES47.Identifier) return key.name;
|
|
11815
|
+
if (key.type === AST_NODE_TYPES47.Literal && typeof key.value === "string") return key.value;
|
|
11626
11816
|
return null;
|
|
11627
11817
|
};
|
|
11628
11818
|
var staticallyImportsEmailOrPdfRenderer = (program) => program.body.some((statement) => {
|
|
11629
|
-
if (statement.type !==
|
|
11819
|
+
if (statement.type !== AST_NODE_TYPES47.ImportDeclaration && statement.type !== AST_NODE_TYPES47.ExportNamedDeclaration && statement.type !== AST_NODE_TYPES47.ExportAllDeclaration) {
|
|
11630
11820
|
return false;
|
|
11631
11821
|
}
|
|
11632
11822
|
return statement.source !== null && typeof statement.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(statement.source.value);
|
|
@@ -11679,27 +11869,27 @@ var prefer_semantic_colors_default = createRule({
|
|
|
11679
11869
|
const checkClassNode = (node) => {
|
|
11680
11870
|
if (node === null) return;
|
|
11681
11871
|
switch (node.type) {
|
|
11682
|
-
case
|
|
11872
|
+
case AST_NODE_TYPES47.Literal:
|
|
11683
11873
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
11684
11874
|
break;
|
|
11685
|
-
case
|
|
11875
|
+
case AST_NODE_TYPES47.TemplateLiteral:
|
|
11686
11876
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
11687
11877
|
break;
|
|
11688
|
-
case
|
|
11878
|
+
case AST_NODE_TYPES47.ArrayExpression:
|
|
11689
11879
|
for (const element of node.elements) {
|
|
11690
|
-
if (element !== null && element.type !==
|
|
11880
|
+
if (element !== null && element.type !== AST_NODE_TYPES47.SpreadElement) checkClassNode(element);
|
|
11691
11881
|
}
|
|
11692
11882
|
break;
|
|
11693
|
-
case
|
|
11883
|
+
case AST_NODE_TYPES47.ObjectExpression:
|
|
11694
11884
|
for (const property of node.properties) {
|
|
11695
|
-
if (property.type ===
|
|
11885
|
+
if (property.type === AST_NODE_TYPES47.Property) checkClassNode(property.value);
|
|
11696
11886
|
}
|
|
11697
11887
|
break;
|
|
11698
|
-
case
|
|
11888
|
+
case AST_NODE_TYPES47.ConditionalExpression:
|
|
11699
11889
|
checkClassNode(node.consequent);
|
|
11700
11890
|
checkClassNode(node.alternate);
|
|
11701
11891
|
break;
|
|
11702
|
-
case
|
|
11892
|
+
case AST_NODE_TYPES47.LogicalExpression:
|
|
11703
11893
|
checkClassNode(node.right);
|
|
11704
11894
|
break;
|
|
11705
11895
|
default:
|
|
@@ -11707,32 +11897,32 @@ var prefer_semantic_colors_default = createRule({
|
|
|
11707
11897
|
}
|
|
11708
11898
|
};
|
|
11709
11899
|
const checkColorValueNode = (node) => {
|
|
11710
|
-
if (node.type ===
|
|
11900
|
+
if (node.type === AST_NODE_TYPES47.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value) && !CSS_VAR_REFERENCE_RE.test(node.value)) {
|
|
11711
11901
|
report(node, "inlineColor", { value: node.value });
|
|
11712
11902
|
}
|
|
11713
11903
|
};
|
|
11714
11904
|
return {
|
|
11715
11905
|
"JSXAttribute[name.name='className']"(node) {
|
|
11716
11906
|
if (node.value === null) return;
|
|
11717
|
-
if (node.value.type ===
|
|
11718
|
-
else if (node.value.type ===
|
|
11719
|
-
if (node.value.expression.type !==
|
|
11907
|
+
if (node.value.type === AST_NODE_TYPES47.Literal) checkClassNode(node.value);
|
|
11908
|
+
else if (node.value.type === AST_NODE_TYPES47.JSXExpressionContainer) {
|
|
11909
|
+
if (node.value.expression.type !== AST_NODE_TYPES47.JSXEmptyExpression) {
|
|
11720
11910
|
checkClassNode(node.value.expression);
|
|
11721
11911
|
}
|
|
11722
11912
|
}
|
|
11723
11913
|
},
|
|
11724
11914
|
CallExpression(node) {
|
|
11725
|
-
if (node.callee.type ===
|
|
11915
|
+
if (node.callee.type === AST_NODE_TYPES47.Identifier && node.callee.name === "require" && node.arguments[0]?.type === AST_NODE_TYPES47.Literal && typeof node.arguments[0].value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.arguments[0].value)) {
|
|
11726
11916
|
importsEmailOrPdfRenderer = true;
|
|
11727
11917
|
}
|
|
11728
|
-
if (node.callee.type ===
|
|
11918
|
+
if (node.callee.type === AST_NODE_TYPES47.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
11729
11919
|
for (const arg of node.arguments) {
|
|
11730
|
-
if (arg.type !==
|
|
11920
|
+
if (arg.type !== AST_NODE_TYPES47.SpreadElement) checkClassNode(arg);
|
|
11731
11921
|
}
|
|
11732
11922
|
}
|
|
11733
11923
|
},
|
|
11734
11924
|
VariableDeclarator(node) {
|
|
11735
|
-
if (node.id.type ===
|
|
11925
|
+
if (node.id.type === AST_NODE_TYPES47.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
11736
11926
|
checkClassNode(node.init);
|
|
11737
11927
|
}
|
|
11738
11928
|
},
|
|
@@ -11742,9 +11932,9 @@ var prefer_semantic_colors_default = createRule({
|
|
|
11742
11932
|
},
|
|
11743
11933
|
// SVG artwork colors are exempt; component presentation colors still report.
|
|
11744
11934
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
11745
|
-
if (node.value?.type !==
|
|
11935
|
+
if (node.value?.type !== AST_NODE_TYPES47.Literal) return;
|
|
11746
11936
|
const owner = node.parent.name;
|
|
11747
|
-
if (owner.type ===
|
|
11937
|
+
if (owner.type === AST_NODE_TYPES47.JSXIdentifier && SVG_SHAPE_PRIMITIVES.has(owner.name)) {
|
|
11748
11938
|
return;
|
|
11749
11939
|
}
|
|
11750
11940
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
@@ -11758,7 +11948,7 @@ var prefer_semantic_colors_default = createRule({
|
|
|
11758
11948
|
if (name !== null && STYLE_COLOR_PROPS.has(name)) checkColorValueNode(node.value);
|
|
11759
11949
|
},
|
|
11760
11950
|
ImportExpression(node) {
|
|
11761
|
-
if (node.source.type ===
|
|
11951
|
+
if (node.source.type === AST_NODE_TYPES47.Literal && typeof node.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.source.value)) {
|
|
11762
11952
|
importsEmailOrPdfRenderer = true;
|
|
11763
11953
|
}
|
|
11764
11954
|
},
|
|
@@ -11960,7 +12150,7 @@ var prefer_server_actions_default = createRule({
|
|
|
11960
12150
|
});
|
|
11961
12151
|
|
|
11962
12152
|
// src/rules/prefer-whole-object-assertion.ts
|
|
11963
|
-
import { AST_NODE_TYPES as
|
|
12153
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES48 } from "@typescript-eslint/utils";
|
|
11964
12154
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
11965
12155
|
var SYNTHETIC_LITERAL_MATCHERS = /* @__PURE__ */ new Map([
|
|
11966
12156
|
["toBeNull", "null"],
|
|
@@ -11985,11 +12175,11 @@ var preferWholeObjectAssertionDocumentation = {
|
|
|
11985
12175
|
};
|
|
11986
12176
|
function literalText(node, getText) {
|
|
11987
12177
|
switch (node.type) {
|
|
11988
|
-
case
|
|
12178
|
+
case AST_NODE_TYPES48.Literal:
|
|
11989
12179
|
return "regex" in node ? null : getText(node);
|
|
11990
|
-
case
|
|
12180
|
+
case AST_NODE_TYPES48.TemplateLiteral:
|
|
11991
12181
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
11992
|
-
case
|
|
12182
|
+
case AST_NODE_TYPES48.UnaryExpression:
|
|
11993
12183
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
11994
12184
|
default:
|
|
11995
12185
|
return null;
|
|
@@ -11997,15 +12187,15 @@ function literalText(node, getText) {
|
|
|
11997
12187
|
}
|
|
11998
12188
|
function isPureReceiver(node) {
|
|
11999
12189
|
switch (node.type) {
|
|
12000
|
-
case
|
|
12001
|
-
case
|
|
12190
|
+
case AST_NODE_TYPES48.Identifier:
|
|
12191
|
+
case AST_NODE_TYPES48.ThisExpression:
|
|
12002
12192
|
return true;
|
|
12003
|
-
case
|
|
12193
|
+
case AST_NODE_TYPES48.MemberExpression:
|
|
12004
12194
|
if (node.optional) {
|
|
12005
12195
|
return false;
|
|
12006
12196
|
}
|
|
12007
12197
|
if (node.computed) {
|
|
12008
|
-
return node.property.type ===
|
|
12198
|
+
return node.property.type === AST_NODE_TYPES48.Literal && isPureReceiver(node.object);
|
|
12009
12199
|
}
|
|
12010
12200
|
return isPureReceiver(node.object);
|
|
12011
12201
|
default:
|
|
@@ -12013,7 +12203,7 @@ function isPureReceiver(node) {
|
|
|
12013
12203
|
}
|
|
12014
12204
|
}
|
|
12015
12205
|
function literalIndex(node) {
|
|
12016
|
-
if (node.type !==
|
|
12206
|
+
if (node.type !== AST_NODE_TYPES48.Literal || typeof node.value !== "number") {
|
|
12017
12207
|
return null;
|
|
12018
12208
|
}
|
|
12019
12209
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
@@ -12040,24 +12230,24 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
12040
12230
|
}
|
|
12041
12231
|
const { sourceCode } = context;
|
|
12042
12232
|
function parseAssertion(statement) {
|
|
12043
|
-
if (statement.type !==
|
|
12233
|
+
if (statement.type !== AST_NODE_TYPES48.ExpressionStatement) {
|
|
12044
12234
|
return null;
|
|
12045
12235
|
}
|
|
12046
12236
|
const call = statement.expression;
|
|
12047
|
-
if (call.type !==
|
|
12237
|
+
if (call.type !== AST_NODE_TYPES48.CallExpression) {
|
|
12048
12238
|
return null;
|
|
12049
12239
|
}
|
|
12050
12240
|
const callee = call.callee;
|
|
12051
|
-
if (callee.type !==
|
|
12241
|
+
if (callee.type !== AST_NODE_TYPES48.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES48.Identifier) {
|
|
12052
12242
|
return null;
|
|
12053
12243
|
}
|
|
12054
12244
|
const matcher = callee.property.name;
|
|
12055
12245
|
const expectCall = callee.object;
|
|
12056
|
-
if (expectCall.type !==
|
|
12246
|
+
if (expectCall.type !== AST_NODE_TYPES48.CallExpression || expectCall.callee.type !== AST_NODE_TYPES48.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
12057
12247
|
return null;
|
|
12058
12248
|
}
|
|
12059
12249
|
const actual = expectCall.arguments[0];
|
|
12060
|
-
if (actual === void 0 || actual.type !==
|
|
12250
|
+
if (actual === void 0 || actual.type !== AST_NODE_TYPES48.MemberExpression || actual.optional) {
|
|
12061
12251
|
return null;
|
|
12062
12252
|
}
|
|
12063
12253
|
if (!isPureReceiver(actual.object)) {
|
|
@@ -12071,7 +12261,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
12071
12261
|
}
|
|
12072
12262
|
key = { kind: "index", index };
|
|
12073
12263
|
} else {
|
|
12074
|
-
if (actual.property.type !==
|
|
12264
|
+
if (actual.property.type !== AST_NODE_TYPES48.Identifier || COLLECTION_PROPERTIES.has(actual.property.name) || LITERAL_KEY_HAZARDS.has(actual.property.name)) {
|
|
12075
12265
|
return null;
|
|
12076
12266
|
}
|
|
12077
12267
|
key = { kind: "property", name: actual.property.name };
|
|
@@ -12084,7 +12274,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
12084
12274
|
return null;
|
|
12085
12275
|
}
|
|
12086
12276
|
const expected = call.arguments[0];
|
|
12087
|
-
if (call.arguments.length !== 1 || expected === void 0 || expected.type ===
|
|
12277
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === AST_NODE_TYPES48.SpreadElement) {
|
|
12088
12278
|
return null;
|
|
12089
12279
|
}
|
|
12090
12280
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
@@ -12199,7 +12389,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
12199
12389
|
});
|
|
12200
12390
|
|
|
12201
12391
|
// src/rules/prefer-zod-infer.ts
|
|
12202
|
-
import { AST_NODE_TYPES as
|
|
12392
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES49 } from "@typescript-eslint/utils";
|
|
12203
12393
|
var preferZodInferDocumentation = {
|
|
12204
12394
|
summary: "Derive a type from its Zod schema with `z.infer` instead of hand-writing a twin declaration beside it.",
|
|
12205
12395
|
rationale: "A derived type stays synchronized when the runtime schema changes.",
|
|
@@ -12252,47 +12442,47 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
12252
12442
|
"Schema"
|
|
12253
12443
|
]);
|
|
12254
12444
|
var LEAF_NODE_TYPES = {
|
|
12255
|
-
string: [
|
|
12256
|
-
email: [
|
|
12257
|
-
url: [
|
|
12258
|
-
uuid: [
|
|
12259
|
-
ulid: [
|
|
12260
|
-
cuid: [
|
|
12261
|
-
cuid2: [
|
|
12262
|
-
nanoid: [
|
|
12263
|
-
iso: [
|
|
12264
|
-
number: [
|
|
12265
|
-
int: [
|
|
12266
|
-
float32: [
|
|
12267
|
-
float64: [
|
|
12268
|
-
boolean: [
|
|
12269
|
-
bigint: [
|
|
12270
|
-
symbol: [
|
|
12271
|
-
any: [
|
|
12272
|
-
unknown: [
|
|
12273
|
-
never: [
|
|
12274
|
-
void: [
|
|
12275
|
-
null: [
|
|
12276
|
-
undefined: [
|
|
12277
|
-
literal: [
|
|
12278
|
-
date: [
|
|
12279
|
-
array: [
|
|
12280
|
-
tuple: [
|
|
12281
|
-
object: [
|
|
12282
|
-
strictObject: [
|
|
12283
|
-
looseObject: [
|
|
12284
|
-
record: [
|
|
12285
|
-
map: [
|
|
12286
|
-
set: [
|
|
12287
|
-
promise: [
|
|
12288
|
-
enum: [
|
|
12289
|
-
nativeEnum: [
|
|
12290
|
-
union: [
|
|
12291
|
-
discriminatedUnion: [
|
|
12292
|
-
intersection: [
|
|
12445
|
+
string: [AST_NODE_TYPES49.TSStringKeyword],
|
|
12446
|
+
email: [AST_NODE_TYPES49.TSStringKeyword],
|
|
12447
|
+
url: [AST_NODE_TYPES49.TSStringKeyword],
|
|
12448
|
+
uuid: [AST_NODE_TYPES49.TSStringKeyword],
|
|
12449
|
+
ulid: [AST_NODE_TYPES49.TSStringKeyword],
|
|
12450
|
+
cuid: [AST_NODE_TYPES49.TSStringKeyword],
|
|
12451
|
+
cuid2: [AST_NODE_TYPES49.TSStringKeyword],
|
|
12452
|
+
nanoid: [AST_NODE_TYPES49.TSStringKeyword],
|
|
12453
|
+
iso: [AST_NODE_TYPES49.TSStringKeyword],
|
|
12454
|
+
number: [AST_NODE_TYPES49.TSNumberKeyword],
|
|
12455
|
+
int: [AST_NODE_TYPES49.TSNumberKeyword],
|
|
12456
|
+
float32: [AST_NODE_TYPES49.TSNumberKeyword],
|
|
12457
|
+
float64: [AST_NODE_TYPES49.TSNumberKeyword],
|
|
12458
|
+
boolean: [AST_NODE_TYPES49.TSBooleanKeyword],
|
|
12459
|
+
bigint: [AST_NODE_TYPES49.TSBigIntKeyword],
|
|
12460
|
+
symbol: [AST_NODE_TYPES49.TSSymbolKeyword],
|
|
12461
|
+
any: [AST_NODE_TYPES49.TSAnyKeyword],
|
|
12462
|
+
unknown: [AST_NODE_TYPES49.TSUnknownKeyword],
|
|
12463
|
+
never: [AST_NODE_TYPES49.TSNeverKeyword],
|
|
12464
|
+
void: [AST_NODE_TYPES49.TSVoidKeyword],
|
|
12465
|
+
null: [AST_NODE_TYPES49.TSNullKeyword],
|
|
12466
|
+
undefined: [AST_NODE_TYPES49.TSUndefinedKeyword],
|
|
12467
|
+
literal: [AST_NODE_TYPES49.TSLiteralType],
|
|
12468
|
+
date: [AST_NODE_TYPES49.TSTypeReference],
|
|
12469
|
+
array: [AST_NODE_TYPES49.TSArrayType, AST_NODE_TYPES49.TSTypeReference],
|
|
12470
|
+
tuple: [AST_NODE_TYPES49.TSTupleType],
|
|
12471
|
+
object: [AST_NODE_TYPES49.TSTypeLiteral, AST_NODE_TYPES49.TSTypeReference],
|
|
12472
|
+
strictObject: [AST_NODE_TYPES49.TSTypeLiteral, AST_NODE_TYPES49.TSTypeReference],
|
|
12473
|
+
looseObject: [AST_NODE_TYPES49.TSTypeLiteral, AST_NODE_TYPES49.TSTypeReference],
|
|
12474
|
+
record: [AST_NODE_TYPES49.TSTypeReference, AST_NODE_TYPES49.TSTypeLiteral],
|
|
12475
|
+
map: [AST_NODE_TYPES49.TSTypeReference],
|
|
12476
|
+
set: [AST_NODE_TYPES49.TSTypeReference],
|
|
12477
|
+
promise: [AST_NODE_TYPES49.TSTypeReference],
|
|
12478
|
+
enum: [AST_NODE_TYPES49.TSUnionType, AST_NODE_TYPES49.TSTypeReference, AST_NODE_TYPES49.TSLiteralType],
|
|
12479
|
+
nativeEnum: [AST_NODE_TYPES49.TSUnionType, AST_NODE_TYPES49.TSTypeReference, AST_NODE_TYPES49.TSLiteralType],
|
|
12480
|
+
union: [AST_NODE_TYPES49.TSUnionType, AST_NODE_TYPES49.TSTypeReference],
|
|
12481
|
+
discriminatedUnion: [AST_NODE_TYPES49.TSUnionType, AST_NODE_TYPES49.TSTypeReference],
|
|
12482
|
+
intersection: [AST_NODE_TYPES49.TSIntersectionType, AST_NODE_TYPES49.TSTypeReference]
|
|
12293
12483
|
};
|
|
12294
12484
|
function primitiveLiteralKey(node) {
|
|
12295
|
-
if (node.type !==
|
|
12485
|
+
if (node.type !== AST_NODE_TYPES49.Literal) {
|
|
12296
12486
|
return null;
|
|
12297
12487
|
}
|
|
12298
12488
|
if (node.value === null) {
|
|
@@ -12324,13 +12514,13 @@ function staticZodDomain(leaf, call) {
|
|
|
12324
12514
|
}
|
|
12325
12515
|
if (leaf === "literal") {
|
|
12326
12516
|
const [argument] = call.arguments;
|
|
12327
|
-
if (argument === void 0 || argument.type ===
|
|
12517
|
+
if (argument === void 0 || argument.type === AST_NODE_TYPES49.SpreadElement) {
|
|
12328
12518
|
return null;
|
|
12329
12519
|
}
|
|
12330
|
-
if (argument.type ===
|
|
12520
|
+
if (argument.type === AST_NODE_TYPES49.ArrayExpression) {
|
|
12331
12521
|
return exactDomain(
|
|
12332
12522
|
argument.elements.map(
|
|
12333
|
-
(element) => element === null || element.type ===
|
|
12523
|
+
(element) => element === null || element.type === AST_NODE_TYPES49.SpreadElement ? null : primitiveLiteralKey(element)
|
|
12334
12524
|
)
|
|
12335
12525
|
);
|
|
12336
12526
|
}
|
|
@@ -12338,13 +12528,13 @@ function staticZodDomain(leaf, call) {
|
|
|
12338
12528
|
}
|
|
12339
12529
|
if (leaf === "enum") {
|
|
12340
12530
|
const [argument] = call.arguments;
|
|
12341
|
-
if (argument === void 0 || argument.type ===
|
|
12531
|
+
if (argument === void 0 || argument.type === AST_NODE_TYPES49.SpreadElement) {
|
|
12342
12532
|
return null;
|
|
12343
12533
|
}
|
|
12344
|
-
if (argument.type ===
|
|
12534
|
+
if (argument.type === AST_NODE_TYPES49.ArrayExpression) {
|
|
12345
12535
|
return exactDomain(
|
|
12346
12536
|
argument.elements.map((element) => {
|
|
12347
|
-
if (element === null || element.type ===
|
|
12537
|
+
if (element === null || element.type === AST_NODE_TYPES49.SpreadElement) {
|
|
12348
12538
|
return null;
|
|
12349
12539
|
}
|
|
12350
12540
|
const key = primitiveLiteralKey(element);
|
|
@@ -12352,10 +12542,10 @@ function staticZodDomain(leaf, call) {
|
|
|
12352
12542
|
})
|
|
12353
12543
|
);
|
|
12354
12544
|
}
|
|
12355
|
-
if (argument.type ===
|
|
12545
|
+
if (argument.type === AST_NODE_TYPES49.ObjectExpression) {
|
|
12356
12546
|
return exactDomain(
|
|
12357
12547
|
argument.properties.map((property) => {
|
|
12358
|
-
if (property.type !==
|
|
12548
|
+
if (property.type !== AST_NODE_TYPES49.Property || property.computed || property.kind !== "init" || property.method || property.shorthand) {
|
|
12359
12549
|
return null;
|
|
12360
12550
|
}
|
|
12361
12551
|
const key = primitiveLiteralKey(property.value);
|
|
@@ -12382,15 +12572,15 @@ function sameDomain(left, right) {
|
|
|
12382
12572
|
return true;
|
|
12383
12573
|
}
|
|
12384
12574
|
function isExportedDeclaration(node) {
|
|
12385
|
-
return node.parent?.type ===
|
|
12575
|
+
return node.parent?.type === AST_NODE_TYPES49.ExportNamedDeclaration;
|
|
12386
12576
|
}
|
|
12387
12577
|
function isModuleLevelConst(node) {
|
|
12388
12578
|
const declaration = node.parent;
|
|
12389
|
-
if (declaration.type !==
|
|
12579
|
+
if (declaration.type !== AST_NODE_TYPES49.VariableDeclaration || declaration.kind !== "const") {
|
|
12390
12580
|
return false;
|
|
12391
12581
|
}
|
|
12392
12582
|
const container = declaration.parent;
|
|
12393
|
-
return container.type ===
|
|
12583
|
+
return container.type === AST_NODE_TYPES49.Program || container.type === AST_NODE_TYPES49.ExportNamedDeclaration && container.parent.type === AST_NODE_TYPES49.Program;
|
|
12394
12584
|
}
|
|
12395
12585
|
function normalizeSchemaName(name) {
|
|
12396
12586
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -12399,20 +12589,20 @@ function normalizeTypeName(name) {
|
|
|
12399
12589
|
return name.replace(/Type$/, "").toLowerCase();
|
|
12400
12590
|
}
|
|
12401
12591
|
function unwrapNullish(annotation) {
|
|
12402
|
-
if (annotation.type !==
|
|
12592
|
+
if (annotation.type !== AST_NODE_TYPES49.TSUnionType) {
|
|
12403
12593
|
return {
|
|
12404
12594
|
core: annotation,
|
|
12405
|
-
nullable: annotation.type ===
|
|
12595
|
+
nullable: annotation.type === AST_NODE_TYPES49.TSNullKeyword
|
|
12406
12596
|
};
|
|
12407
12597
|
}
|
|
12408
12598
|
const rest = [];
|
|
12409
12599
|
let nullable = false;
|
|
12410
12600
|
for (const member of annotation.types) {
|
|
12411
|
-
if (member.type ===
|
|
12601
|
+
if (member.type === AST_NODE_TYPES49.TSNullKeyword) {
|
|
12412
12602
|
nullable = true;
|
|
12413
12603
|
continue;
|
|
12414
12604
|
}
|
|
12415
|
-
if (member.type ===
|
|
12605
|
+
if (member.type === AST_NODE_TYPES49.TSUndefinedKeyword) {
|
|
12416
12606
|
continue;
|
|
12417
12607
|
}
|
|
12418
12608
|
rest.push(member);
|
|
@@ -12446,18 +12636,18 @@ function leafAgrees(field, annotation) {
|
|
|
12446
12636
|
return null;
|
|
12447
12637
|
}
|
|
12448
12638
|
if (leaf === "date") {
|
|
12449
|
-
return core.type ===
|
|
12639
|
+
return core.type === AST_NODE_TYPES49.TSTypeReference && core.typeName.type === AST_NODE_TYPES49.Identifier && core.typeName.name === "Date";
|
|
12450
12640
|
}
|
|
12451
12641
|
return expected.includes(core.type);
|
|
12452
12642
|
}
|
|
12453
12643
|
function typeLiteralDomain(annotation) {
|
|
12454
|
-
const members = annotation.type ===
|
|
12644
|
+
const members = annotation.type === AST_NODE_TYPES49.TSUnionType ? annotation.types : [annotation];
|
|
12455
12645
|
const keys = [];
|
|
12456
12646
|
for (const member of members) {
|
|
12457
|
-
if (member.type ===
|
|
12647
|
+
if (member.type === AST_NODE_TYPES49.TSNullKeyword) {
|
|
12458
12648
|
continue;
|
|
12459
12649
|
}
|
|
12460
|
-
if (member.type !==
|
|
12650
|
+
if (member.type !== AST_NODE_TYPES49.TSLiteralType) {
|
|
12461
12651
|
return null;
|
|
12462
12652
|
}
|
|
12463
12653
|
keys.push(primitiveLiteralKey(member.literal));
|
|
@@ -12465,11 +12655,11 @@ function typeLiteralDomain(annotation) {
|
|
|
12465
12655
|
return exactDomain(keys);
|
|
12466
12656
|
}
|
|
12467
12657
|
function staticStringUnionDomain(node) {
|
|
12468
|
-
if (node.type !==
|
|
12658
|
+
if (node.type !== AST_NODE_TYPES49.TSUnionType) {
|
|
12469
12659
|
return null;
|
|
12470
12660
|
}
|
|
12471
12661
|
const keys = node.types.map((member) => {
|
|
12472
|
-
if (member.type !==
|
|
12662
|
+
if (member.type !== AST_NODE_TYPES49.TSLiteralType) {
|
|
12473
12663
|
return null;
|
|
12474
12664
|
}
|
|
12475
12665
|
const key = primitiveLiteralKey(member.literal);
|
|
@@ -12537,14 +12727,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
12537
12727
|
function zodCallChain(node) {
|
|
12538
12728
|
const chain = [];
|
|
12539
12729
|
let current = node;
|
|
12540
|
-
while (current.type ===
|
|
12730
|
+
while (current.type === AST_NODE_TYPES49.CallExpression) {
|
|
12541
12731
|
const callee = current.callee;
|
|
12542
|
-
if (callee.type !==
|
|
12732
|
+
if (callee.type !== AST_NODE_TYPES49.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES49.Identifier) {
|
|
12543
12733
|
return null;
|
|
12544
12734
|
}
|
|
12545
12735
|
chain.push(current);
|
|
12546
12736
|
const receiver = callee.object;
|
|
12547
|
-
if (receiver.type ===
|
|
12737
|
+
if (receiver.type === AST_NODE_TYPES49.Identifier) {
|
|
12548
12738
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
12549
12739
|
}
|
|
12550
12740
|
current = receiver;
|
|
@@ -12553,14 +12743,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
12553
12743
|
}
|
|
12554
12744
|
function methodName2(call) {
|
|
12555
12745
|
const callee = call.callee;
|
|
12556
|
-
return callee.type ===
|
|
12746
|
+
return callee.type === AST_NODE_TYPES49.MemberExpression && callee.property.type === AST_NODE_TYPES49.Identifier ? callee.property.name : "";
|
|
12557
12747
|
}
|
|
12558
12748
|
function recordZodImport(node) {
|
|
12559
12749
|
if (!isZodModule(node.source.value)) {
|
|
12560
12750
|
return;
|
|
12561
12751
|
}
|
|
12562
12752
|
for (const specifier of node.specifiers) {
|
|
12563
|
-
if (specifier.type ===
|
|
12753
|
+
if (specifier.type === AST_NODE_TYPES49.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES49.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES49.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES49.Identifier && specifier.imported.name === "z") {
|
|
12564
12754
|
zodNamespaces.add(specifier.local.name);
|
|
12565
12755
|
}
|
|
12566
12756
|
}
|
|
@@ -12570,13 +12760,13 @@ var prefer_zod_infer_default = createRule({
|
|
|
12570
12760
|
let current = node;
|
|
12571
12761
|
let leaf = null;
|
|
12572
12762
|
let leafCall = null;
|
|
12573
|
-
while (current.type ===
|
|
12763
|
+
while (current.type === AST_NODE_TYPES49.CallExpression) {
|
|
12574
12764
|
const callee = current.callee;
|
|
12575
|
-
if (callee.type !==
|
|
12765
|
+
if (callee.type !== AST_NODE_TYPES49.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES49.Identifier) {
|
|
12576
12766
|
break;
|
|
12577
12767
|
}
|
|
12578
12768
|
const receiver = callee.object;
|
|
12579
|
-
if (receiver.type ===
|
|
12769
|
+
if (receiver.type === AST_NODE_TYPES49.Identifier && zodNamespaces.has(receiver.name)) {
|
|
12580
12770
|
leaf = callee.property.name;
|
|
12581
12771
|
leafCall = current;
|
|
12582
12772
|
break;
|
|
@@ -12607,20 +12797,20 @@ var prefer_zod_infer_default = createRule({
|
|
|
12607
12797
|
return domain instanceof Set && domain.size >= 2 ? domain : null;
|
|
12608
12798
|
}
|
|
12609
12799
|
function inferredSchemaName(node) {
|
|
12610
|
-
if (node.type !==
|
|
12800
|
+
if (node.type !== AST_NODE_TYPES49.TSTypeReference || node.typeName.type !== AST_NODE_TYPES49.TSQualifiedName || node.typeName.left.type !== AST_NODE_TYPES49.Identifier || !zodNamespaces.has(node.typeName.left.name) || node.typeName.right.name !== "infer") {
|
|
12611
12801
|
return null;
|
|
12612
12802
|
}
|
|
12613
12803
|
const arguments_ = node.typeArguments?.params ?? [];
|
|
12614
12804
|
const [argument] = arguments_;
|
|
12615
|
-
return arguments_.length === 1 && argument?.type ===
|
|
12805
|
+
return arguments_.length === 1 && argument?.type === AST_NODE_TYPES49.TSTypeQuery && argument.exprName.type === AST_NODE_TYPES49.Identifier ? argument.exprName.name : null;
|
|
12616
12806
|
}
|
|
12617
12807
|
function recordLiteralUnions(members, owner, ownerName, exported) {
|
|
12618
12808
|
for (const member of members) {
|
|
12619
|
-
if (member.type !==
|
|
12809
|
+
if (member.type !== AST_NODE_TYPES49.TSPropertySignature || member.computed || member.optional || member.readonly || member.typeAnnotation === void 0) {
|
|
12620
12810
|
continue;
|
|
12621
12811
|
}
|
|
12622
12812
|
const key = member.key;
|
|
12623
|
-
const propertyName3 = key.type ===
|
|
12813
|
+
const propertyName3 = key.type === AST_NODE_TYPES49.Identifier ? key.name : key.type === AST_NODE_TYPES49.Literal && typeof key.value === "string" ? key.value : null;
|
|
12624
12814
|
if (propertyName3 === null) {
|
|
12625
12815
|
continue;
|
|
12626
12816
|
}
|
|
@@ -12630,7 +12820,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
12630
12820
|
}
|
|
12631
12821
|
const annotation = member.typeAnnotation.typeAnnotation;
|
|
12632
12822
|
const domain = staticStringUnionDomain(annotation);
|
|
12633
|
-
if (domain === null || annotation.type !==
|
|
12823
|
+
if (domain === null || annotation.type !== AST_NODE_TYPES49.TSUnionType) {
|
|
12634
12824
|
continue;
|
|
12635
12825
|
}
|
|
12636
12826
|
literalUnionOccurrences.push({
|
|
@@ -12661,16 +12851,16 @@ var prefer_zod_infer_default = createRule({
|
|
|
12661
12851
|
return null;
|
|
12662
12852
|
}
|
|
12663
12853
|
const shape = base.arguments[0];
|
|
12664
|
-
if (shape === void 0 || shape.type !==
|
|
12854
|
+
if (shape === void 0 || shape.type !== AST_NODE_TYPES49.ObjectExpression) {
|
|
12665
12855
|
return null;
|
|
12666
12856
|
}
|
|
12667
12857
|
const fields = /* @__PURE__ */ new Map();
|
|
12668
12858
|
for (const property of shape.properties) {
|
|
12669
|
-
if (property.type !==
|
|
12859
|
+
if (property.type !== AST_NODE_TYPES49.Property || property.computed) {
|
|
12670
12860
|
return null;
|
|
12671
12861
|
}
|
|
12672
12862
|
const { key } = property;
|
|
12673
|
-
const name = key.type ===
|
|
12863
|
+
const name = key.type === AST_NODE_TYPES49.Identifier ? key.name : key.type === AST_NODE_TYPES49.Literal && typeof key.value === "string" ? key.value : null;
|
|
12674
12864
|
if (name === null) {
|
|
12675
12865
|
return null;
|
|
12676
12866
|
}
|
|
@@ -12681,11 +12871,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
12681
12871
|
function typeMembers(members) {
|
|
12682
12872
|
const result = /* @__PURE__ */ new Map();
|
|
12683
12873
|
for (const member of members) {
|
|
12684
|
-
if (member.type !==
|
|
12874
|
+
if (member.type !== AST_NODE_TYPES49.TSPropertySignature || member.computed) {
|
|
12685
12875
|
return null;
|
|
12686
12876
|
}
|
|
12687
12877
|
const { key } = member;
|
|
12688
|
-
const name = key.type ===
|
|
12878
|
+
const name = key.type === AST_NODE_TYPES49.Identifier ? key.name : key.type === AST_NODE_TYPES49.Literal && typeof key.value === "string" ? key.value : null;
|
|
12689
12879
|
if (name === null) {
|
|
12690
12880
|
return null;
|
|
12691
12881
|
}
|
|
@@ -12700,8 +12890,8 @@ var prefer_zod_infer_default = createRule({
|
|
|
12700
12890
|
return result.size === 0 ? null : result;
|
|
12701
12891
|
}
|
|
12702
12892
|
function collectConstrainedNames(node) {
|
|
12703
|
-
if (node.type ===
|
|
12704
|
-
if (node.typeName.type ===
|
|
12893
|
+
if (node.type === AST_NODE_TYPES49.TSTypeReference) {
|
|
12894
|
+
if (node.typeName.type === AST_NODE_TYPES49.Identifier) {
|
|
12705
12895
|
constrainedTypeNames.add(node.typeName.name);
|
|
12706
12896
|
}
|
|
12707
12897
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -12709,11 +12899,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
12709
12899
|
}
|
|
12710
12900
|
return;
|
|
12711
12901
|
}
|
|
12712
|
-
if (node.type ===
|
|
12902
|
+
if (node.type === AST_NODE_TYPES49.TSArrayType) {
|
|
12713
12903
|
collectConstrainedNames(node.elementType);
|
|
12714
12904
|
return;
|
|
12715
12905
|
}
|
|
12716
|
-
if (node.type ===
|
|
12906
|
+
if (node.type === AST_NODE_TYPES49.TSUnionType || node.type === AST_NODE_TYPES49.TSIntersectionType) {
|
|
12717
12907
|
for (const member of node.types) {
|
|
12718
12908
|
collectConstrainedNames(member);
|
|
12719
12909
|
}
|
|
@@ -12757,7 +12947,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
12757
12947
|
return {
|
|
12758
12948
|
Program(node) {
|
|
12759
12949
|
for (const statement of node.body) {
|
|
12760
|
-
if (statement.type ===
|
|
12950
|
+
if (statement.type === AST_NODE_TYPES49.ImportDeclaration) {
|
|
12761
12951
|
recordZodImport(statement);
|
|
12762
12952
|
}
|
|
12763
12953
|
}
|
|
@@ -12766,7 +12956,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
12766
12956
|
recordZodImport(node);
|
|
12767
12957
|
},
|
|
12768
12958
|
VariableDeclarator(node) {
|
|
12769
|
-
if (node.id.type !==
|
|
12959
|
+
if (node.id.type !== AST_NODE_TYPES49.Identifier || node.init == null) {
|
|
12770
12960
|
return;
|
|
12771
12961
|
}
|
|
12772
12962
|
const fields = schemaFields(node.init);
|
|
@@ -12783,14 +12973,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
12783
12973
|
},
|
|
12784
12974
|
/** Records `XSchema.transform(...)` and equivalent module-level reshaping. */
|
|
12785
12975
|
"MemberExpression[computed=false]"(node) {
|
|
12786
|
-
if (node.object.type ===
|
|
12976
|
+
if (node.object.type === AST_NODE_TYPES49.Identifier && node.property.type === AST_NODE_TYPES49.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
12787
12977
|
reshapedSchemaNames.add(node.object.name);
|
|
12788
12978
|
}
|
|
12789
12979
|
},
|
|
12790
12980
|
/** Records every type argument carried by a Zod constraint. */
|
|
12791
12981
|
TSTypeReference(node) {
|
|
12792
12982
|
const { typeName } = node;
|
|
12793
|
-
const referenced = typeName.type ===
|
|
12983
|
+
const referenced = typeName.type === AST_NODE_TYPES49.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES49.TSQualifiedName && typeName.right.type === AST_NODE_TYPES49.Identifier ? typeName.right.name : null;
|
|
12794
12984
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
12795
12985
|
return;
|
|
12796
12986
|
}
|
|
@@ -12822,7 +13012,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
12822
13012
|
typeName: node.id.name
|
|
12823
13013
|
});
|
|
12824
13014
|
}
|
|
12825
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
13015
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== AST_NODE_TYPES49.TSTypeLiteral) {
|
|
12826
13016
|
return;
|
|
12827
13017
|
}
|
|
12828
13018
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -12922,10 +13112,10 @@ var prefer_zod_infer_default = createRule({
|
|
|
12922
13112
|
|
|
12923
13113
|
// src/rules/require-assert-never.ts
|
|
12924
13114
|
import {
|
|
12925
|
-
ESLintUtils as
|
|
12926
|
-
AST_NODE_TYPES as
|
|
13115
|
+
ESLintUtils as ESLintUtils4,
|
|
13116
|
+
AST_NODE_TYPES as AST_NODE_TYPES50
|
|
12927
13117
|
} from "@typescript-eslint/utils";
|
|
12928
|
-
import
|
|
13118
|
+
import ts3 from "typescript";
|
|
12929
13119
|
var requireAssertNeverDocumentation = {
|
|
12930
13120
|
summary: "Require an empty switch default to call `assertNever` so discriminated unions remain exhaustive at compile time.",
|
|
12931
13121
|
rationale: "An empty default silently accepts new union members instead of making the compiler identify the missing case.",
|
|
@@ -12937,14 +13127,14 @@ var requireAssertNeverDocumentation = {
|
|
|
12937
13127
|
]
|
|
12938
13128
|
};
|
|
12939
13129
|
var isRuntimeHandlingStatement = (statement) => {
|
|
12940
|
-
if (statement.type ===
|
|
12941
|
-
if (statement.type ===
|
|
13130
|
+
if (statement.type === AST_NODE_TYPES50.EmptyStatement) return false;
|
|
13131
|
+
if (statement.type === AST_NODE_TYPES50.BreakStatement) {
|
|
12942
13132
|
return statement.label !== null;
|
|
12943
13133
|
}
|
|
12944
|
-
if (statement.type ===
|
|
13134
|
+
if (statement.type === AST_NODE_TYPES50.TSTypeAliasDeclaration || statement.type === AST_NODE_TYPES50.TSInterfaceDeclaration) {
|
|
12945
13135
|
return false;
|
|
12946
13136
|
}
|
|
12947
|
-
if (statement.type ===
|
|
13137
|
+
if (statement.type === AST_NODE_TYPES50.BlockStatement) {
|
|
12948
13138
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
12949
13139
|
}
|
|
12950
13140
|
return true;
|
|
@@ -12960,7 +13150,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
12960
13150
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
12961
13151
|
}
|
|
12962
13152
|
const only = defaultCase.consequent[0];
|
|
12963
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
13153
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === AST_NODE_TYPES50.BlockStatement && !only.body.some(isRuntimeHandlingStatement)) {
|
|
12964
13154
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
12965
13155
|
}
|
|
12966
13156
|
return false;
|
|
@@ -12972,7 +13162,7 @@ function isExhaustiveFiniteSwitch(node, services) {
|
|
|
12972
13162
|
const constituents = discriminantType.isUnion() ? discriminantType.types : [discriminantType];
|
|
12973
13163
|
if (!discriminantType.isUnion() || constituents.length < 2) return false;
|
|
12974
13164
|
if (constituents.every(
|
|
12975
|
-
(constituent) => (constituent.flags &
|
|
13165
|
+
(constituent) => (constituent.flags & ts3.TypeFlags.BooleanLiteral) !== 0
|
|
12976
13166
|
)) {
|
|
12977
13167
|
return false;
|
|
12978
13168
|
}
|
|
@@ -12996,7 +13186,7 @@ function isExhaustiveFiniteSwitch(node, services) {
|
|
|
12996
13186
|
return [...expected].every((key) => handled.has(key));
|
|
12997
13187
|
}
|
|
12998
13188
|
function finiteTypeKey(type, checker) {
|
|
12999
|
-
const finiteFlags =
|
|
13189
|
+
const finiteFlags = ts3.TypeFlags.StringLiteral | ts3.TypeFlags.NumberLiteral | ts3.TypeFlags.BooleanLiteral | ts3.TypeFlags.EnumLiteral | ts3.TypeFlags.UniqueESSymbol | ts3.TypeFlags.Null | ts3.TypeFlags.Undefined;
|
|
13000
13190
|
return (type.flags & finiteFlags) !== 0 ? checker.typeToString(type) : null;
|
|
13001
13191
|
}
|
|
13002
13192
|
var require_assert_never_default = createRule({
|
|
@@ -13016,7 +13206,7 @@ var require_assert_never_default = createRule({
|
|
|
13016
13206
|
create(context) {
|
|
13017
13207
|
let services;
|
|
13018
13208
|
try {
|
|
13019
|
-
services =
|
|
13209
|
+
services = ESLintUtils4.getParserServices(context);
|
|
13020
13210
|
} catch {
|
|
13021
13211
|
services = null;
|
|
13022
13212
|
}
|
|
@@ -13043,7 +13233,7 @@ var require_assert_never_default = createRule({
|
|
|
13043
13233
|
});
|
|
13044
13234
|
|
|
13045
13235
|
// src/rules/require-fetch-timeout.ts
|
|
13046
|
-
import { AST_NODE_TYPES as
|
|
13236
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES51, ASTUtils as ASTUtils13 } from "@typescript-eslint/utils";
|
|
13047
13237
|
var requireFetchTimeoutDocumentation = {
|
|
13048
13238
|
summary: "Require an abort `signal` (e.g. `AbortSignal.timeout(ms)`) on global `fetch()` calls so stalled upstreams cannot hang the caller forever.",
|
|
13049
13239
|
rationale: "An unbounded request can occupy work indefinitely when an upstream stalls.",
|
|
@@ -13069,14 +13259,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
13069
13259
|
return false;
|
|
13070
13260
|
}
|
|
13071
13261
|
function initProvablyLacksSignal(init) {
|
|
13072
|
-
if (init.type !==
|
|
13262
|
+
if (init.type !== AST_NODE_TYPES51.ObjectExpression) {
|
|
13073
13263
|
return false;
|
|
13074
13264
|
}
|
|
13075
13265
|
for (const prop of init.properties) {
|
|
13076
|
-
if (prop.type ===
|
|
13266
|
+
if (prop.type === AST_NODE_TYPES51.SpreadElement) {
|
|
13077
13267
|
return false;
|
|
13078
13268
|
}
|
|
13079
|
-
if (prop.key.type ===
|
|
13269
|
+
if (prop.key.type === AST_NODE_TYPES51.Identifier && prop.key.name === "signal" || prop.key.type === AST_NODE_TYPES51.Literal && prop.key.value === "signal") {
|
|
13080
13270
|
return false;
|
|
13081
13271
|
}
|
|
13082
13272
|
if (prop.computed) {
|
|
@@ -13086,7 +13276,7 @@ function initProvablyLacksSignal(init) {
|
|
|
13086
13276
|
return true;
|
|
13087
13277
|
}
|
|
13088
13278
|
function isInlineUrl(node, resolvesToGlobal) {
|
|
13089
|
-
return node.type ===
|
|
13279
|
+
return node.type === AST_NODE_TYPES51.Literal && typeof node.value === "string" || node.type === AST_NODE_TYPES51.TemplateLiteral || node.type === AST_NODE_TYPES51.NewExpression && node.callee.type === AST_NODE_TYPES51.Identifier && node.callee.name === "URL" && resolvesToGlobal(node.callee);
|
|
13090
13280
|
}
|
|
13091
13281
|
var require_fetch_timeout_default = createRule({
|
|
13092
13282
|
name: "require-fetch-timeout",
|
|
@@ -13128,10 +13318,10 @@ var require_fetch_timeout_default = createRule({
|
|
|
13128
13318
|
return variable === null || variable.defs.length === 0;
|
|
13129
13319
|
}
|
|
13130
13320
|
function isGlobalFetchCall2(callee) {
|
|
13131
|
-
if (callee.type ===
|
|
13321
|
+
if (callee.type === AST_NODE_TYPES51.Identifier) {
|
|
13132
13322
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
13133
13323
|
}
|
|
13134
|
-
return callee.type ===
|
|
13324
|
+
return callee.type === AST_NODE_TYPES51.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES51.Identifier && callee.property.name === "fetch" && callee.object.type === AST_NODE_TYPES51.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
13135
13325
|
}
|
|
13136
13326
|
function localConstInitProvablyLacksSignal(identifier) {
|
|
13137
13327
|
const variable = ASTUtils13.findVariable(
|
|
@@ -13140,14 +13330,14 @@ var require_fetch_timeout_default = createRule({
|
|
|
13140
13330
|
);
|
|
13141
13331
|
if (variable?.defs.length !== 1) return false;
|
|
13142
13332
|
const definition = variable.defs[0];
|
|
13143
|
-
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !==
|
|
13333
|
+
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !== AST_NODE_TYPES51.ObjectExpression || !initProvablyLacksSignal(definition.node.init)) {
|
|
13144
13334
|
return false;
|
|
13145
13335
|
}
|
|
13146
13336
|
for (const reference of variable.references) {
|
|
13147
13337
|
const ref = reference.identifier;
|
|
13148
13338
|
if (ref === identifier || ref === definition.name) continue;
|
|
13149
13339
|
const member = ref.parent;
|
|
13150
|
-
if (member.type !==
|
|
13340
|
+
if (member.type !== AST_NODE_TYPES51.MemberExpression || member.object !== ref || member.computed || member.property.type !== AST_NODE_TYPES51.Identifier || member.property.name === "signal" || member.parent.type !== AST_NODE_TYPES51.AssignmentExpression || member.parent.left !== member) {
|
|
13151
13341
|
return false;
|
|
13152
13342
|
}
|
|
13153
13343
|
}
|
|
@@ -13162,7 +13352,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
13162
13352
|
if (node.arguments.length === 1 && first !== void 0 && !isInlineUrl(first, resolvesToGlobal)) {
|
|
13163
13353
|
return;
|
|
13164
13354
|
}
|
|
13165
|
-
if (init === void 0 || initProvablyLacksSignal(init) || init.type ===
|
|
13355
|
+
if (init === void 0 || initProvablyLacksSignal(init) || init.type === AST_NODE_TYPES51.Identifier && localConstInitProvablyLacksSignal(init)) {
|
|
13166
13356
|
context.report({ node, messageId: "missingSignal" });
|
|
13167
13357
|
}
|
|
13168
13358
|
}
|
|
@@ -13171,7 +13361,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
13171
13361
|
});
|
|
13172
13362
|
|
|
13173
13363
|
// src/rules/require-port-for-service.ts
|
|
13174
|
-
import { AST_NODE_TYPES as
|
|
13364
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES52 } from "@typescript-eslint/utils";
|
|
13175
13365
|
var requirePortForServiceDocumentation = {
|
|
13176
13366
|
summary: "Advise when an exported service with injected collaborators has public methods not covered by its declared ports.",
|
|
13177
13367
|
rationale: "A declared port keeps consumers coupled to the service capability instead of its concrete implementation.",
|
|
@@ -13196,45 +13386,45 @@ var ROUTER_FACTORY_NAME = "Router";
|
|
|
13196
13386
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
13197
13387
|
var STORAGE_ASSIGNMENT_OPERATORS = /* @__PURE__ */ new Set(["=", "&&=", "??=", "||="]);
|
|
13198
13388
|
var staticMemberName4 = (member) => {
|
|
13199
|
-
if (member.property.type ===
|
|
13200
|
-
if (!member.computed && member.property.type ===
|
|
13201
|
-
return member.computed && member.property.type ===
|
|
13389
|
+
if (member.property.type === AST_NODE_TYPES52.PrivateIdentifier) return `#${member.property.name}`;
|
|
13390
|
+
if (!member.computed && member.property.type === AST_NODE_TYPES52.Identifier) return member.property.name;
|
|
13391
|
+
return member.computed && member.property.type === AST_NODE_TYPES52.Literal && typeof member.property.value === "string" ? member.property.value : null;
|
|
13202
13392
|
};
|
|
13203
13393
|
var detachedValueExports = (program) => {
|
|
13204
13394
|
const names = /* @__PURE__ */ new Set();
|
|
13205
13395
|
for (const statement of program.body) {
|
|
13206
|
-
if (statement.type ===
|
|
13396
|
+
if (statement.type === AST_NODE_TYPES52.ExportNamedDeclaration && statement.declaration === null && statement.source === null && statement.exportKind !== "type") {
|
|
13207
13397
|
for (const specifier of statement.specifiers) {
|
|
13208
13398
|
if (specifier.exportKind !== "type") names.add(specifier.local.name);
|
|
13209
13399
|
}
|
|
13210
|
-
} else if (statement.type ===
|
|
13400
|
+
} else if (statement.type === AST_NODE_TYPES52.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES52.Identifier) {
|
|
13211
13401
|
names.add(statement.declaration.name);
|
|
13212
|
-
} else if (statement.type ===
|
|
13402
|
+
} else if (statement.type === AST_NODE_TYPES52.TSExportAssignment && statement.expression.type === AST_NODE_TYPES52.Identifier) {
|
|
13213
13403
|
names.add(statement.expression.name);
|
|
13214
13404
|
}
|
|
13215
13405
|
}
|
|
13216
13406
|
return names;
|
|
13217
13407
|
};
|
|
13218
|
-
var isExportedClass2 = (node, detached) => node.parent.type ===
|
|
13408
|
+
var isExportedClass2 = (node, detached) => node.parent.type === AST_NODE_TYPES52.ExportNamedDeclaration || node.parent.type === AST_NODE_TYPES52.ExportDefaultDeclaration || node.id !== null && detached.has(node.id.name);
|
|
13219
13409
|
var readTypeReference = (annotation) => {
|
|
13220
|
-
if (annotation?.type ===
|
|
13410
|
+
if (annotation?.type === AST_NODE_TYPES52.TSUnionType) {
|
|
13221
13411
|
const members = annotation.types.filter(
|
|
13222
|
-
(member) => member.type !==
|
|
13412
|
+
(member) => member.type !== AST_NODE_TYPES52.TSUndefinedKeyword && member.type !== AST_NODE_TYPES52.TSNullKeyword
|
|
13223
13413
|
);
|
|
13224
13414
|
annotation = members.length === 1 ? members[0] : void 0;
|
|
13225
13415
|
}
|
|
13226
|
-
if (annotation === void 0 || annotation.type !==
|
|
13416
|
+
if (annotation === void 0 || annotation.type !== AST_NODE_TYPES52.TSTypeReference) return null;
|
|
13227
13417
|
const { typeName } = annotation;
|
|
13228
|
-
const rightmost = typeName.type ===
|
|
13418
|
+
const rightmost = typeName.type === AST_NODE_TYPES52.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES52.TSQualifiedName ? typeName.right.name : null;
|
|
13229
13419
|
if (rightmost === null) return null;
|
|
13230
13420
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
13231
13421
|
};
|
|
13232
|
-
var qualifiedName = (name) => name.type ===
|
|
13422
|
+
var qualifiedName = (name) => name.type === AST_NODE_TYPES52.Identifier ? name.name : name.type === AST_NODE_TYPES52.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
13233
13423
|
var propertySignatureTypes = (members) => {
|
|
13234
13424
|
const types = /* @__PURE__ */ new Map();
|
|
13235
13425
|
for (const member of members) {
|
|
13236
|
-
if (member.type !==
|
|
13237
|
-
if (member.computed || member.key.type !==
|
|
13426
|
+
if (member.type !== AST_NODE_TYPES52.TSPropertySignature) continue;
|
|
13427
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES52.Identifier) continue;
|
|
13238
13428
|
const reference = readTypeReference(member.typeAnnotation?.typeAnnotation);
|
|
13239
13429
|
if (reference === null) continue;
|
|
13240
13430
|
types.set(member.key.name, reference);
|
|
@@ -13245,18 +13435,18 @@ var fileTypeIndex = (program) => {
|
|
|
13245
13435
|
const objects = /* @__PURE__ */ new Map();
|
|
13246
13436
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
13247
13437
|
for (const statement of program.body) {
|
|
13248
|
-
const declaration = statement.type ===
|
|
13249
|
-
if (declaration?.type ===
|
|
13438
|
+
const declaration = statement.type === AST_NODE_TYPES52.ExportNamedDeclaration ? statement.declaration : statement;
|
|
13439
|
+
if (declaration?.type === AST_NODE_TYPES52.TSInterfaceDeclaration) {
|
|
13250
13440
|
objects.set(declaration.id.name, propertySignatureTypes(declaration.body.body));
|
|
13251
13441
|
continue;
|
|
13252
13442
|
}
|
|
13253
|
-
if (declaration?.type !==
|
|
13443
|
+
if (declaration?.type !== AST_NODE_TYPES52.TSTypeAliasDeclaration) continue;
|
|
13254
13444
|
const aliased = declaration.typeAnnotation;
|
|
13255
|
-
if (aliased.type ===
|
|
13445
|
+
if (aliased.type === AST_NODE_TYPES52.TSFunctionType || aliased.type === AST_NODE_TYPES52.TSConstructorType) {
|
|
13256
13446
|
functionAliases.add(declaration.id.name);
|
|
13257
13447
|
continue;
|
|
13258
13448
|
}
|
|
13259
|
-
const literals = aliased.type ===
|
|
13449
|
+
const literals = aliased.type === AST_NODE_TYPES52.TSTypeLiteral ? [aliased] : aliased.type === AST_NODE_TYPES52.TSIntersectionType ? aliased.types.filter((part) => part.type === AST_NODE_TYPES52.TSTypeLiteral) : [];
|
|
13260
13450
|
if (literals.length === 0) continue;
|
|
13261
13451
|
const merged = /* @__PURE__ */ new Map();
|
|
13262
13452
|
for (const literal of literals) {
|
|
@@ -13284,10 +13474,10 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
13284
13474
|
while (pending.length > 0) {
|
|
13285
13475
|
const current = pending.pop();
|
|
13286
13476
|
if (current === void 0) break;
|
|
13287
|
-
if (current.type ===
|
|
13288
|
-
const expression = current.type ===
|
|
13289
|
-
const storedField = expression?.type ===
|
|
13290
|
-
if (expression?.type !==
|
|
13477
|
+
if (current.type === AST_NODE_TYPES52.ArrowFunctionExpression || current.type === AST_NODE_TYPES52.FunctionExpression || current.type === AST_NODE_TYPES52.FunctionDeclaration || current.type === AST_NODE_TYPES52.ClassExpression || current.type === AST_NODE_TYPES52.ClassDeclaration) continue;
|
|
13478
|
+
const expression = current.type === AST_NODE_TYPES52.ExpressionStatement ? current.expression : null;
|
|
13479
|
+
const storedField = expression?.type === AST_NODE_TYPES52.AssignmentExpression && expression.left.type === AST_NODE_TYPES52.MemberExpression && expression.left.object.type === AST_NODE_TYPES52.ThisExpression ? staticMemberName4(expression.left) : null;
|
|
13480
|
+
if (expression?.type !== AST_NODE_TYPES52.AssignmentExpression || !STORAGE_ASSIGNMENT_OPERATORS.has(expression.operator) || expression.left.type !== AST_NODE_TYPES52.MemberExpression || expression.left.object.type !== AST_NODE_TYPES52.ThisExpression || storedField === null) {
|
|
13291
13481
|
for (const key of Object.keys(current)) {
|
|
13292
13482
|
if (key === "parent") continue;
|
|
13293
13483
|
const value = current[key];
|
|
@@ -13300,14 +13490,14 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
13300
13490
|
continue;
|
|
13301
13491
|
}
|
|
13302
13492
|
let source = expression.right;
|
|
13303
|
-
while (source.type ===
|
|
13304
|
-
if (source.type ===
|
|
13493
|
+
while (source.type === AST_NODE_TYPES52.TSNonNullExpression || source.type === AST_NODE_TYPES52.TSAsExpression || source.type === AST_NODE_TYPES52.TSSatisfiesExpression || source.type === AST_NODE_TYPES52.TSTypeAssertion) source = source.expression;
|
|
13494
|
+
if (source.type === AST_NODE_TYPES52.NewExpression) {
|
|
13305
13495
|
constructedFields += 1;
|
|
13306
|
-
} else if (source.type ===
|
|
13496
|
+
} else if (source.type === AST_NODE_TYPES52.Identifier) {
|
|
13307
13497
|
const fields = storedFieldsFrom.get(source.name) ?? /* @__PURE__ */ new Set();
|
|
13308
13498
|
fields.add(storedField);
|
|
13309
13499
|
storedFieldsFrom.set(source.name, fields);
|
|
13310
|
-
} else if (source.type ===
|
|
13500
|
+
} else if (source.type === AST_NODE_TYPES52.MemberExpression && source.object.type === AST_NODE_TYPES52.Identifier) {
|
|
13311
13501
|
const fields = storedFieldsFrom.get(source.object.name) ?? /* @__PURE__ */ new Set();
|
|
13312
13502
|
fields.add(storedField);
|
|
13313
13503
|
storedFieldsFrom.set(source.object.name, fields);
|
|
@@ -13317,7 +13507,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
13317
13507
|
const collaborators = [];
|
|
13318
13508
|
for (const parameter of ctor.value.params) {
|
|
13319
13509
|
for (const reference of parameterCollaborators(parameter, declared)) {
|
|
13320
|
-
const fields = parameter.type ===
|
|
13510
|
+
const fields = parameter.type === AST_NODE_TYPES52.TSParameterProperty ? [reference.name] : [...storedFieldsFrom.get(reference.name) ?? []];
|
|
13321
13511
|
if (fields.length === 0) continue;
|
|
13322
13512
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
13323
13513
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -13332,8 +13522,8 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
13332
13522
|
};
|
|
13333
13523
|
var parameterCollaborators = (parameter, declared) => {
|
|
13334
13524
|
let target = parameter;
|
|
13335
|
-
if (target.type ===
|
|
13336
|
-
if (target.type ===
|
|
13525
|
+
if (target.type === AST_NODE_TYPES52.AssignmentPattern) target = target.left;
|
|
13526
|
+
if (target.type === AST_NODE_TYPES52.ObjectPattern) {
|
|
13337
13527
|
return objectPatternCollaborators(target, declared);
|
|
13338
13528
|
}
|
|
13339
13529
|
const named2 = namedParameterCollaborator(parameter);
|
|
@@ -13341,9 +13531,9 @@ var parameterCollaborators = (parameter, declared) => {
|
|
|
13341
13531
|
};
|
|
13342
13532
|
var namedParameterCollaborator = (annotated) => {
|
|
13343
13533
|
let target = annotated;
|
|
13344
|
-
if (target.type ===
|
|
13345
|
-
if (target.type ===
|
|
13346
|
-
if (target.type !==
|
|
13534
|
+
if (target.type === AST_NODE_TYPES52.TSParameterProperty) target = target.parameter;
|
|
13535
|
+
if (target.type === AST_NODE_TYPES52.AssignmentPattern) target = target.left;
|
|
13536
|
+
if (target.type !== AST_NODE_TYPES52.Identifier) return null;
|
|
13347
13537
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
13348
13538
|
if (reference === null) return null;
|
|
13349
13539
|
return { name: target.name, ...reference, fields: [] };
|
|
@@ -13355,11 +13545,11 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
13355
13545
|
if (members === null) return [];
|
|
13356
13546
|
const collaborators = [];
|
|
13357
13547
|
for (const property of pattern.properties) {
|
|
13358
|
-
if (property.type !==
|
|
13359
|
-
if (property.key.type !==
|
|
13548
|
+
if (property.type !== AST_NODE_TYPES52.Property || property.computed) continue;
|
|
13549
|
+
if (property.key.type !== AST_NODE_TYPES52.Identifier) continue;
|
|
13360
13550
|
const key = property.key.name;
|
|
13361
|
-
const bound = property.value.type ===
|
|
13362
|
-
if (bound.type !==
|
|
13551
|
+
const bound = property.value.type === AST_NODE_TYPES52.AssignmentPattern ? property.value.left : property.value;
|
|
13552
|
+
if (bound.type !== AST_NODE_TYPES52.Identifier) continue;
|
|
13363
13553
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
13364
13554
|
const reference = members.get(key);
|
|
13365
13555
|
if (reference === void 0) continue;
|
|
@@ -13368,21 +13558,21 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
13368
13558
|
return collaborators;
|
|
13369
13559
|
};
|
|
13370
13560
|
var bagMemberTypes = (annotation, declared) => {
|
|
13371
|
-
if (annotation.type ===
|
|
13561
|
+
if (annotation.type === AST_NODE_TYPES52.TSTypeLiteral) {
|
|
13372
13562
|
return propertySignatureTypes(annotation.members);
|
|
13373
13563
|
}
|
|
13374
|
-
if (annotation.type !==
|
|
13564
|
+
if (annotation.type !== AST_NODE_TYPES52.TSTypeReference || annotation.typeName.type !== AST_NODE_TYPES52.Identifier) {
|
|
13375
13565
|
return null;
|
|
13376
13566
|
}
|
|
13377
13567
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
13378
13568
|
};
|
|
13379
13569
|
var isFrameworkWiring = (body2) => subtreeHas(body2, (node) => {
|
|
13380
|
-
if (node.type ===
|
|
13570
|
+
if (node.type === AST_NODE_TYPES52.CallExpression) {
|
|
13381
13571
|
const { callee } = node;
|
|
13382
|
-
if (callee.type ===
|
|
13383
|
-
return callee.type ===
|
|
13572
|
+
if (callee.type === AST_NODE_TYPES52.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
13573
|
+
return callee.type === AST_NODE_TYPES52.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES52.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
13384
13574
|
}
|
|
13385
|
-
return node.type ===
|
|
13575
|
+
return node.type === AST_NODE_TYPES52.TSTypeReference && node.typeName.type === AST_NODE_TYPES52.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
13386
13576
|
});
|
|
13387
13577
|
var subtreeHas = (root, found) => {
|
|
13388
13578
|
let hit = false;
|
|
@@ -13409,19 +13599,19 @@ var invokedInstanceField = (call) => {
|
|
|
13409
13599
|
const direct = instanceField(call.callee);
|
|
13410
13600
|
if (direct !== null) return direct;
|
|
13411
13601
|
let callee = call.callee;
|
|
13412
|
-
while (callee.type ===
|
|
13413
|
-
return callee.type ===
|
|
13602
|
+
while (callee.type === AST_NODE_TYPES52.ChainExpression || callee.type === AST_NODE_TYPES52.TSAsExpression || callee.type === AST_NODE_TYPES52.TSNonNullExpression || callee.type === AST_NODE_TYPES52.TSSatisfiesExpression || callee.type === AST_NODE_TYPES52.TSTypeAssertion) callee = callee.expression;
|
|
13603
|
+
return callee.type === AST_NODE_TYPES52.MemberExpression ? instanceField(callee.object) : null;
|
|
13414
13604
|
};
|
|
13415
13605
|
var instanceField = (candidate) => {
|
|
13416
13606
|
let node = candidate;
|
|
13417
|
-
while (node.type ===
|
|
13418
|
-
return node.type ===
|
|
13607
|
+
while (node.type === AST_NODE_TYPES52.ChainExpression || node.type === AST_NODE_TYPES52.TSAsExpression || node.type === AST_NODE_TYPES52.TSNonNullExpression || node.type === AST_NODE_TYPES52.TSSatisfiesExpression || node.type === AST_NODE_TYPES52.TSTypeAssertion) node = node.expression;
|
|
13608
|
+
return node.type === AST_NODE_TYPES52.MemberExpression && node.object.type === AST_NODE_TYPES52.ThisExpression ? staticMemberName4(node) : null;
|
|
13419
13609
|
};
|
|
13420
13610
|
var behaviorallyInvokedFields = (body2) => {
|
|
13421
13611
|
const invoked = /* @__PURE__ */ new Set();
|
|
13422
13612
|
const visit = (current) => {
|
|
13423
|
-
if (current.type ===
|
|
13424
|
-
if (current.type ===
|
|
13613
|
+
if (current.type === AST_NODE_TYPES52.ClassDeclaration || current.type === AST_NODE_TYPES52.ClassExpression || current.type === AST_NODE_TYPES52.FunctionDeclaration || current.type === AST_NODE_TYPES52.FunctionExpression) return;
|
|
13614
|
+
if (current.type === AST_NODE_TYPES52.CallExpression) {
|
|
13425
13615
|
const field = invokedInstanceField(current);
|
|
13426
13616
|
if (field !== null) invoked.add(field);
|
|
13427
13617
|
}
|
|
@@ -13434,14 +13624,14 @@ var behaviorallyInvokedFields = (body2) => {
|
|
|
13434
13624
|
}
|
|
13435
13625
|
};
|
|
13436
13626
|
for (const member of body2.body) {
|
|
13437
|
-
if (member.type ===
|
|
13438
|
-
if (member.type ===
|
|
13627
|
+
if (member.type === AST_NODE_TYPES52.StaticBlock || member.static) continue;
|
|
13628
|
+
if (member.type === AST_NODE_TYPES52.MethodDefinition) {
|
|
13439
13629
|
if (member.value.body !== null && member.value.body !== void 0) visit(member.value.body);
|
|
13440
13630
|
continue;
|
|
13441
13631
|
}
|
|
13442
|
-
if (member.type !==
|
|
13632
|
+
if (member.type !== AST_NODE_TYPES52.PropertyDefinition || member.value === null) continue;
|
|
13443
13633
|
visit(
|
|
13444
|
-
member.value.type ===
|
|
13634
|
+
member.value.type === AST_NODE_TYPES52.ArrowFunctionExpression ? member.value.body : member.value
|
|
13445
13635
|
);
|
|
13446
13636
|
}
|
|
13447
13637
|
return invoked;
|
|
@@ -13461,25 +13651,25 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
13461
13651
|
var fileInterfaceNames = (program) => {
|
|
13462
13652
|
const names = [];
|
|
13463
13653
|
for (const statement of program.body) {
|
|
13464
|
-
const declaration = statement.type ===
|
|
13465
|
-
if (declaration?.type ===
|
|
13654
|
+
const declaration = statement.type === AST_NODE_TYPES52.ExportNamedDeclaration ? statement.declaration : statement;
|
|
13655
|
+
if (declaration?.type === AST_NODE_TYPES52.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
13466
13656
|
}
|
|
13467
13657
|
return names;
|
|
13468
13658
|
};
|
|
13469
13659
|
var publicMethodNames = (body2, functionAliases) => {
|
|
13470
13660
|
const names = [];
|
|
13471
13661
|
for (const member of body2.body) {
|
|
13472
|
-
if (member.type ===
|
|
13662
|
+
if (member.type === AST_NODE_TYPES52.PropertyDefinition) {
|
|
13473
13663
|
if (member.static || member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
13474
|
-
if (member.value?.type !==
|
|
13475
|
-
names.push(member.key.type ===
|
|
13664
|
+
if (member.value?.type !== AST_NODE_TYPES52.ArrowFunctionExpression && member.value?.type !== AST_NODE_TYPES52.FunctionExpression && member.typeAnnotation?.typeAnnotation.type !== AST_NODE_TYPES52.TSFunctionType && !(member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES52.TSTypeReference && member.typeAnnotation.typeAnnotation.typeName.type === AST_NODE_TYPES52.Identifier && functionAliases.has(member.typeAnnotation.typeAnnotation.typeName.name))) continue;
|
|
13665
|
+
names.push(member.key.type === AST_NODE_TYPES52.Identifier ? member.key.name : "\u2026");
|
|
13476
13666
|
continue;
|
|
13477
13667
|
}
|
|
13478
|
-
if (member.type !==
|
|
13668
|
+
if (member.type !== AST_NODE_TYPES52.MethodDefinition) continue;
|
|
13479
13669
|
if (member.kind !== "method" || member.static) continue;
|
|
13480
13670
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
13481
|
-
if (member.key.type ===
|
|
13482
|
-
if (member.key.type ===
|
|
13671
|
+
if (member.key.type === AST_NODE_TYPES52.PrivateIdentifier) continue;
|
|
13672
|
+
if (member.key.type === AST_NODE_TYPES52.Identifier) names.push(member.key.name);
|
|
13483
13673
|
else names.push("\u2026");
|
|
13484
13674
|
}
|
|
13485
13675
|
return names;
|
|
@@ -13487,13 +13677,13 @@ var publicMethodNames = (body2, functionAliases) => {
|
|
|
13487
13677
|
var isFluentConstructionObject = (node, getText) => {
|
|
13488
13678
|
if (node.id === null) return false;
|
|
13489
13679
|
const methods = node.body.body.filter(
|
|
13490
|
-
(member) => member.type ===
|
|
13680
|
+
(member) => member.type === AST_NODE_TYPES52.MethodDefinition && member.kind === "method" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.value.body !== null
|
|
13491
13681
|
);
|
|
13492
13682
|
if (methods.length === 0) return false;
|
|
13493
13683
|
return methods.every((member) => {
|
|
13494
13684
|
const result = member.value.returnType?.typeAnnotation;
|
|
13495
13685
|
if (result === void 0) return false;
|
|
13496
|
-
const returnsOwnType = result.type ===
|
|
13686
|
+
const returnsOwnType = result.type === AST_NODE_TYPES52.TSTypeReference && result.typeName.type === AST_NODE_TYPES52.Identifier && result.typeName.name === node.id?.name;
|
|
13497
13687
|
return returnsOwnType || FLUENT_BUILDER_NAME_RE.test(node.id?.name ?? "") && FLUENT_RESULT_TYPE_RE.test(getText(result));
|
|
13498
13688
|
});
|
|
13499
13689
|
};
|
|
@@ -13501,10 +13691,10 @@ function localClassAbstractness(program) {
|
|
|
13501
13691
|
const classes = /* @__PURE__ */ new Map();
|
|
13502
13692
|
const parents = /* @__PURE__ */ new Map();
|
|
13503
13693
|
for (const statement of program.body) {
|
|
13504
|
-
const declaration = statement.type ===
|
|
13505
|
-
if (declaration?.type ===
|
|
13694
|
+
const declaration = statement.type === AST_NODE_TYPES52.ExportNamedDeclaration || statement.type === AST_NODE_TYPES52.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
13695
|
+
if (declaration?.type === AST_NODE_TYPES52.ClassDeclaration && declaration.id !== null) {
|
|
13506
13696
|
classes.set(declaration.id.name, declaration.abstract === true);
|
|
13507
|
-
if (declaration.superClass?.type ===
|
|
13697
|
+
if (declaration.superClass?.type === AST_NODE_TYPES52.Identifier) {
|
|
13508
13698
|
parents.set(declaration.id.name, declaration.superClass.name);
|
|
13509
13699
|
}
|
|
13510
13700
|
}
|
|
@@ -13526,43 +13716,43 @@ function localInterfaceSurfaces(program) {
|
|
|
13526
13716
|
const parents = /* @__PURE__ */ new Map();
|
|
13527
13717
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
13528
13718
|
for (const statement of program.body) {
|
|
13529
|
-
const declaration = statement.type ===
|
|
13530
|
-
if (declaration?.type ===
|
|
13719
|
+
const declaration = statement.type === AST_NODE_TYPES52.ExportNamedDeclaration ? statement.declaration : statement;
|
|
13720
|
+
if (declaration?.type === AST_NODE_TYPES52.TSTypeAliasDeclaration && (declaration.typeAnnotation.type === AST_NODE_TYPES52.TSFunctionType || declaration.typeAnnotation.type === AST_NODE_TYPES52.TSConstructorType)) functionAliases.add(declaration.id.name);
|
|
13531
13721
|
}
|
|
13532
13722
|
for (const statement of program.body) {
|
|
13533
|
-
const declaration = statement.type ===
|
|
13534
|
-
if (declaration?.type ===
|
|
13723
|
+
const declaration = statement.type === AST_NODE_TYPES52.ExportNamedDeclaration ? statement.declaration : statement;
|
|
13724
|
+
if (declaration?.type === AST_NODE_TYPES52.TSTypeAliasDeclaration) {
|
|
13535
13725
|
const callables2 = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
13536
|
-
const parts = declaration.typeAnnotation.type ===
|
|
13726
|
+
const parts = declaration.typeAnnotation.type === AST_NODE_TYPES52.TSIntersectionType ? declaration.typeAnnotation.types : [declaration.typeAnnotation];
|
|
13537
13727
|
const inherited = parents.get(declaration.id.name) ?? [];
|
|
13538
13728
|
for (const part of parts) {
|
|
13539
|
-
if (part.type ===
|
|
13729
|
+
if (part.type === AST_NODE_TYPES52.TSTypeReference && part.typeName.type === AST_NODE_TYPES52.Identifier) {
|
|
13540
13730
|
inherited.push(part.typeName.name);
|
|
13541
13731
|
continue;
|
|
13542
13732
|
}
|
|
13543
|
-
if (part.type !==
|
|
13733
|
+
if (part.type !== AST_NODE_TYPES52.TSTypeLiteral) continue;
|
|
13544
13734
|
for (const member of part.members) {
|
|
13545
|
-
if (member.type !==
|
|
13546
|
-
if (member.computed || member.key.type !==
|
|
13547
|
-
if (member.type ===
|
|
13735
|
+
if (member.type !== AST_NODE_TYPES52.TSMethodSignature && member.type !== AST_NODE_TYPES52.TSPropertySignature) continue;
|
|
13736
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES52.Identifier) continue;
|
|
13737
|
+
if (member.type === AST_NODE_TYPES52.TSMethodSignature) {
|
|
13548
13738
|
callables2.add(member.key.name);
|
|
13549
13739
|
continue;
|
|
13550
13740
|
}
|
|
13551
|
-
if (member.type !==
|
|
13741
|
+
if (member.type !== AST_NODE_TYPES52.TSPropertySignature) continue;
|
|
13552
13742
|
const annotation = member.typeAnnotation?.typeAnnotation;
|
|
13553
|
-
if (annotation?.type ===
|
|
13743
|
+
if (annotation?.type === AST_NODE_TYPES52.TSFunctionType || annotation?.type === AST_NODE_TYPES52.TSTypeReference && annotation.typeName.type === AST_NODE_TYPES52.Identifier && functionAliases.has(annotation.typeName.name)) callables2.add(member.key.name);
|
|
13554
13744
|
}
|
|
13555
13745
|
}
|
|
13556
13746
|
interfaces.set(declaration.id.name, callables2);
|
|
13557
13747
|
parents.set(declaration.id.name, inherited);
|
|
13558
13748
|
continue;
|
|
13559
13749
|
}
|
|
13560
|
-
if (declaration?.type !==
|
|
13750
|
+
if (declaration?.type !== AST_NODE_TYPES52.TSInterfaceDeclaration) continue;
|
|
13561
13751
|
const callables = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
13562
13752
|
for (const member of declaration.body.body) {
|
|
13563
|
-
if (member.type !==
|
|
13564
|
-
if (member.computed || member.key.type !==
|
|
13565
|
-
if (member.type ===
|
|
13753
|
+
if (member.type !== AST_NODE_TYPES52.TSMethodSignature && member.type !== AST_NODE_TYPES52.TSPropertySignature) continue;
|
|
13754
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES52.Identifier) continue;
|
|
13755
|
+
if (member.type === AST_NODE_TYPES52.TSMethodSignature || member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES52.TSFunctionType || member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES52.TSTypeReference && member.typeAnnotation.typeAnnotation.typeName.type === AST_NODE_TYPES52.Identifier && functionAliases.has(member.typeAnnotation.typeAnnotation.typeName.name)) callables.add(member.key.name);
|
|
13566
13756
|
}
|
|
13567
13757
|
interfaces.set(declaration.id.name, callables);
|
|
13568
13758
|
parents.set(
|
|
@@ -13570,7 +13760,7 @@ function localInterfaceSurfaces(program) {
|
|
|
13570
13760
|
[
|
|
13571
13761
|
...parents.get(declaration.id.name) ?? [],
|
|
13572
13762
|
...declaration.extends.flatMap(
|
|
13573
|
-
(heritage) => heritage.expression.type ===
|
|
13763
|
+
(heritage) => heritage.expression.type === AST_NODE_TYPES52.Identifier ? [heritage.expression.name] : ["*"]
|
|
13574
13764
|
)
|
|
13575
13765
|
]
|
|
13576
13766
|
);
|
|
@@ -13597,7 +13787,7 @@ function localInterfaceSurfaces(program) {
|
|
|
13597
13787
|
}
|
|
13598
13788
|
function hasServicePort(node, methods, classes, interfaces) {
|
|
13599
13789
|
if (node.superClass !== null) {
|
|
13600
|
-
if (node.superClass.type !==
|
|
13790
|
+
if (node.superClass.type !== AST_NODE_TYPES52.Identifier) return true;
|
|
13601
13791
|
const localAbstract = classes.get(node.superClass.name);
|
|
13602
13792
|
if (localAbstract === void 0 || localAbstract) return true;
|
|
13603
13793
|
}
|
|
@@ -13609,7 +13799,7 @@ function hasServicePort(node, methods, classes, interfaces) {
|
|
|
13609
13799
|
if (node.implements.length === 0) return false;
|
|
13610
13800
|
const combined = /* @__PURE__ */ new Set();
|
|
13611
13801
|
for (const implementation of node.implements) {
|
|
13612
|
-
if (implementation.expression.type !==
|
|
13802
|
+
if (implementation.expression.type !== AST_NODE_TYPES52.Identifier) return true;
|
|
13613
13803
|
const name = implementation.expression.name;
|
|
13614
13804
|
const localAbstract = classes.get(name);
|
|
13615
13805
|
if (localAbstract === true) return true;
|
|
@@ -13652,7 +13842,7 @@ var require_port_for_service_default = createRule({
|
|
|
13652
13842
|
if (node.abstract === true) return;
|
|
13653
13843
|
if (node.decorators.length > 0) return;
|
|
13654
13844
|
const ctor = node.body.body.find(
|
|
13655
|
-
(member) => member.type ===
|
|
13845
|
+
(member) => member.type === AST_NODE_TYPES52.MethodDefinition && member.kind === "constructor" && member.value.body !== null && member.value.body !== void 0
|
|
13656
13846
|
);
|
|
13657
13847
|
if (ctor === void 0) return;
|
|
13658
13848
|
const constructorFacts = readConstructor(
|
|
@@ -13687,7 +13877,7 @@ var require_port_for_service_default = createRule({
|
|
|
13687
13877
|
});
|
|
13688
13878
|
|
|
13689
13879
|
// src/rules/require-static-next-matcher.ts
|
|
13690
|
-
import { AST_NODE_TYPES as
|
|
13880
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES53 } from "@typescript-eslint/utils";
|
|
13691
13881
|
var requireStaticNextMatcherDocumentation = {
|
|
13692
13882
|
summary: "Require Next.js middleware and proxy matcher configuration to contain only build-time literals.",
|
|
13693
13883
|
rationale: "Next.js must statically analyze matcher values at build time; computed values are ignored.",
|
|
@@ -13700,34 +13890,34 @@ var requireStaticNextMatcherDocumentation = {
|
|
|
13700
13890
|
};
|
|
13701
13891
|
var NEXT_ENTRY_FILE = /(?:^|[/\\])(?:middleware|proxy)\.[cm]?[jt]sx?$/u;
|
|
13702
13892
|
function unwrapExpression3(node) {
|
|
13703
|
-
if (node.type ===
|
|
13893
|
+
if (node.type === AST_NODE_TYPES53.TSAsExpression || node.type === AST_NODE_TYPES53.TSSatisfiesExpression || node.type === AST_NODE_TYPES53.TSNonNullExpression || node.type === AST_NODE_TYPES53.TSTypeAssertion) {
|
|
13704
13894
|
return unwrapExpression3(node.expression);
|
|
13705
13895
|
}
|
|
13706
13896
|
return node;
|
|
13707
13897
|
}
|
|
13708
13898
|
function isStaticValue(node) {
|
|
13709
13899
|
const value = unwrapExpression3(node);
|
|
13710
|
-
if (value.type ===
|
|
13900
|
+
if (value.type === AST_NODE_TYPES53.Literal) {
|
|
13711
13901
|
return true;
|
|
13712
13902
|
}
|
|
13713
|
-
if (value.type ===
|
|
13903
|
+
if (value.type === AST_NODE_TYPES53.TemplateLiteral) {
|
|
13714
13904
|
return value.expressions.length === 0;
|
|
13715
13905
|
}
|
|
13716
|
-
if (value.type ===
|
|
13906
|
+
if (value.type === AST_NODE_TYPES53.ArrayExpression) {
|
|
13717
13907
|
return value.elements.every(
|
|
13718
|
-
(element) => element !== null && element.type !==
|
|
13908
|
+
(element) => element !== null && element.type !== AST_NODE_TYPES53.SpreadElement && isStaticValue(element)
|
|
13719
13909
|
);
|
|
13720
13910
|
}
|
|
13721
|
-
if (value.type ===
|
|
13911
|
+
if (value.type === AST_NODE_TYPES53.ObjectExpression) {
|
|
13722
13912
|
return value.properties.every(
|
|
13723
|
-
(property) => property.type ===
|
|
13913
|
+
(property) => property.type === AST_NODE_TYPES53.Property && property.kind === "init" && !property.computed && property.value.type !== AST_NODE_TYPES53.AssignmentPattern && isStaticValue(property.value)
|
|
13724
13914
|
);
|
|
13725
13915
|
}
|
|
13726
13916
|
return false;
|
|
13727
13917
|
}
|
|
13728
13918
|
function propertyName2(property) {
|
|
13729
13919
|
if (property.computed) return null;
|
|
13730
|
-
if (property.key.type ===
|
|
13920
|
+
if (property.key.type === AST_NODE_TYPES53.Identifier) return property.key.name;
|
|
13731
13921
|
return typeof property.key.value === "string" ? property.key.value : null;
|
|
13732
13922
|
}
|
|
13733
13923
|
var require_static_next_matcher_default = createRule({
|
|
@@ -13750,19 +13940,19 @@ var require_static_next_matcher_default = createRule({
|
|
|
13750
13940
|
}
|
|
13751
13941
|
return {
|
|
13752
13942
|
ExportNamedDeclaration(node) {
|
|
13753
|
-
if (node.declaration?.type !==
|
|
13943
|
+
if (node.declaration?.type !== AST_NODE_TYPES53.VariableDeclaration) {
|
|
13754
13944
|
return;
|
|
13755
13945
|
}
|
|
13756
13946
|
for (const declaration of node.declaration.declarations) {
|
|
13757
|
-
if (declaration.id.type !==
|
|
13947
|
+
if (declaration.id.type !== AST_NODE_TYPES53.Identifier || declaration.id.name !== "config" || declaration.init === null) {
|
|
13758
13948
|
continue;
|
|
13759
13949
|
}
|
|
13760
13950
|
const config = unwrapExpression3(declaration.init);
|
|
13761
|
-
if (config.type !==
|
|
13951
|
+
if (config.type !== AST_NODE_TYPES53.ObjectExpression) {
|
|
13762
13952
|
continue;
|
|
13763
13953
|
}
|
|
13764
13954
|
for (const property of config.properties) {
|
|
13765
|
-
if (property.type !==
|
|
13955
|
+
if (property.type !== AST_NODE_TYPES53.Property || propertyName2(property) !== "matcher" || property.value.type === AST_NODE_TYPES53.AssignmentPattern) {
|
|
13766
13956
|
continue;
|
|
13767
13957
|
}
|
|
13768
13958
|
if (!isStaticValue(property.value)) {
|
|
@@ -13777,7 +13967,7 @@ var require_static_next_matcher_default = createRule({
|
|
|
13777
13967
|
|
|
13778
13968
|
// src/rules/require-zod-form-validation.ts
|
|
13779
13969
|
import {
|
|
13780
|
-
AST_NODE_TYPES as
|
|
13970
|
+
AST_NODE_TYPES as AST_NODE_TYPES54,
|
|
13781
13971
|
ASTUtils as ASTUtils14
|
|
13782
13972
|
} from "@typescript-eslint/utils";
|
|
13783
13973
|
var requireZodFormValidationDocumentation = {
|
|
@@ -13804,14 +13994,14 @@ var FORM_VALUE_METHODS = /* @__PURE__ */ new Set(["get", "getAll"]);
|
|
|
13804
13994
|
var zodReceiverRoot = (node) => {
|
|
13805
13995
|
let current = node;
|
|
13806
13996
|
while (true) {
|
|
13807
|
-
if (current.type ===
|
|
13997
|
+
if (current.type === AST_NODE_TYPES54.Identifier) {
|
|
13808
13998
|
return current;
|
|
13809
13999
|
}
|
|
13810
|
-
if (current.type ===
|
|
14000
|
+
if (current.type === AST_NODE_TYPES54.CallExpression) {
|
|
13811
14001
|
current = current.callee;
|
|
13812
14002
|
continue;
|
|
13813
14003
|
}
|
|
13814
|
-
if (current.type ===
|
|
14004
|
+
if (current.type === AST_NODE_TYPES54.MemberExpression) {
|
|
13815
14005
|
current = current.object;
|
|
13816
14006
|
continue;
|
|
13817
14007
|
}
|
|
@@ -13820,12 +14010,12 @@ var zodReceiverRoot = (node) => {
|
|
|
13820
14010
|
};
|
|
13821
14011
|
var isFormDataMethodCall = (node) => {
|
|
13822
14012
|
let current = node;
|
|
13823
|
-
if (current.type ===
|
|
14013
|
+
if (current.type === AST_NODE_TYPES54.AwaitExpression) {
|
|
13824
14014
|
current = current.argument;
|
|
13825
14015
|
}
|
|
13826
|
-
if (current.type !==
|
|
14016
|
+
if (current.type !== AST_NODE_TYPES54.CallExpression) return false;
|
|
13827
14017
|
const callee = current.callee;
|
|
13828
|
-
return callee.type ===
|
|
14018
|
+
return callee.type === AST_NODE_TYPES54.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES54.Identifier && callee.property.name === "formData";
|
|
13829
14019
|
};
|
|
13830
14020
|
var require_zod_form_validation_default = createRule({
|
|
13831
14021
|
name: "require-zod-form-validation",
|
|
@@ -13856,16 +14046,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
13856
14046
|
return false;
|
|
13857
14047
|
}
|
|
13858
14048
|
const definition = binding.defs[0];
|
|
13859
|
-
if (definition?.type !== "Variable" || definition.node.type !==
|
|
14049
|
+
if (definition?.type !== "Variable" || definition.node.type !== AST_NODE_TYPES54.VariableDeclarator) {
|
|
13860
14050
|
return false;
|
|
13861
14051
|
}
|
|
13862
14052
|
const init = definition.node.init;
|
|
13863
|
-
return init?.type ===
|
|
14053
|
+
return init?.type === AST_NODE_TYPES54.ObjectExpression || init?.type === AST_NODE_TYPES54.ArrayExpression || init?.type === AST_NODE_TYPES54.Literal || init?.type === AST_NODE_TYPES54.ArrowFunctionExpression || init?.type === AST_NODE_TYPES54.FunctionExpression;
|
|
13864
14054
|
};
|
|
13865
14055
|
const isZodParseCall = (node) => {
|
|
13866
|
-
if (node.type !==
|
|
14056
|
+
if (node.type !== AST_NODE_TYPES54.CallExpression) return false;
|
|
13867
14057
|
const callee = node.callee;
|
|
13868
|
-
if (callee.type !==
|
|
14058
|
+
if (callee.type !== AST_NODE_TYPES54.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES54.Identifier || !ZOD_PARSE_METHODS.has(callee.property.name)) {
|
|
13869
14059
|
return false;
|
|
13870
14060
|
}
|
|
13871
14061
|
const root = zodReceiverRoot(callee.object);
|
|
@@ -13874,14 +14064,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
13874
14064
|
return binding !== null && zodBindings.has(binding) || (root.name === "z" || ZOD_SCHEMA_NAME_RE.test(root.name)) && !isProvablyNonZodLocal(root);
|
|
13875
14065
|
};
|
|
13876
14066
|
const isFormSourceIdentifier = (node) => {
|
|
13877
|
-
if (node.type !==
|
|
14067
|
+
if (node.type !== AST_NODE_TYPES54.Identifier) return false;
|
|
13878
14068
|
const conventionalName = /formdata/i.test(node.name);
|
|
13879
14069
|
let scope = context.sourceCode.getScope(node);
|
|
13880
14070
|
while (scope !== null) {
|
|
13881
14071
|
const variable = scope.set.get(node.name);
|
|
13882
14072
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
13883
14073
|
const def = variable.defs[0];
|
|
13884
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
14074
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === AST_NODE_TYPES54.VariableDeclarator && def.node.init !== null) {
|
|
13885
14075
|
return isFormDataMethodCall(def.node.init);
|
|
13886
14076
|
}
|
|
13887
14077
|
return def?.type === "Parameter" && conventionalName;
|
|
@@ -13892,8 +14082,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
13892
14082
|
};
|
|
13893
14083
|
const isFormDataGetCall = (node) => {
|
|
13894
14084
|
const callee = node.callee;
|
|
13895
|
-
if (callee.type !==
|
|
13896
|
-
if (callee.property.type !==
|
|
14085
|
+
if (callee.type !== AST_NODE_TYPES54.MemberExpression) return false;
|
|
14086
|
+
if (callee.property.type !== AST_NODE_TYPES54.Identifier || !FORM_VALUE_METHODS.has(callee.property.name)) {
|
|
13897
14087
|
return false;
|
|
13898
14088
|
}
|
|
13899
14089
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -13909,16 +14099,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
13909
14099
|
const hasZodParseAncestor = (node) => zodParseAncestor(node) !== null;
|
|
13910
14100
|
const isInstanceofNarrowing = (node) => {
|
|
13911
14101
|
const parent = node.parent;
|
|
13912
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
14102
|
+
return parent !== null && parent !== void 0 && parent.type === AST_NODE_TYPES54.BinaryExpression && parent.operator === "instanceof" && parent.left === node && parent.right.type === AST_NODE_TYPES54.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
13913
14103
|
};
|
|
13914
14104
|
const boundDeclarator = (node) => {
|
|
13915
14105
|
let current = node;
|
|
13916
14106
|
let parent = current.parent;
|
|
13917
|
-
while ((parent.type ===
|
|
14107
|
+
while ((parent.type === AST_NODE_TYPES54.TSAsExpression || parent.type === AST_NODE_TYPES54.TSSatisfiesExpression || parent.type === AST_NODE_TYPES54.TSNonNullExpression || parent.type === AST_NODE_TYPES54.ChainExpression) && parent.expression === current) {
|
|
13918
14108
|
current = parent;
|
|
13919
14109
|
parent = current.parent;
|
|
13920
14110
|
}
|
|
13921
|
-
if (parent.type ===
|
|
14111
|
+
if (parent.type === AST_NODE_TYPES54.VariableDeclarator && parent.init === current && parent.id.type === AST_NODE_TYPES54.Identifier) {
|
|
13922
14112
|
return parent;
|
|
13923
14113
|
}
|
|
13924
14114
|
return null;
|
|
@@ -13927,7 +14117,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
13927
14117
|
let current = node;
|
|
13928
14118
|
while (current.parent !== void 0) {
|
|
13929
14119
|
const parent = current.parent;
|
|
13930
|
-
if (parent.type ===
|
|
14120
|
+
if (parent.type === AST_NODE_TYPES54.BlockStatement || parent.type === AST_NODE_TYPES54.Program) {
|
|
13931
14121
|
return current;
|
|
13932
14122
|
}
|
|
13933
14123
|
current = parent;
|
|
@@ -13936,12 +14126,12 @@ var require_zod_form_validation_default = createRule({
|
|
|
13936
14126
|
};
|
|
13937
14127
|
const zodParseMethod = (call) => {
|
|
13938
14128
|
const callee = call.callee;
|
|
13939
|
-
return callee.type ===
|
|
14129
|
+
return callee.type === AST_NODE_TYPES54.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES54.Identifier ? callee.property.name : null;
|
|
13940
14130
|
};
|
|
13941
14131
|
const hasConditionalAncestorBeforeStatement = (node, statement) => {
|
|
13942
14132
|
let current = node.parent;
|
|
13943
14133
|
while (current !== void 0 && current !== statement) {
|
|
13944
|
-
if (current.type ===
|
|
14134
|
+
if (current.type === AST_NODE_TYPES54.LogicalExpression || current.type === AST_NODE_TYPES54.ConditionalExpression) {
|
|
13945
14135
|
return true;
|
|
13946
14136
|
}
|
|
13947
14137
|
current = current.parent;
|
|
@@ -13951,7 +14141,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
13951
14141
|
const isAwaitedBeforeStatement = (node, statement) => {
|
|
13952
14142
|
let current = node.parent;
|
|
13953
14143
|
while (current !== void 0 && current !== statement) {
|
|
13954
|
-
if (current.type ===
|
|
14144
|
+
if (current.type === AST_NODE_TYPES54.AwaitExpression) return true;
|
|
13955
14145
|
current = current.parent;
|
|
13956
14146
|
}
|
|
13957
14147
|
return false;
|
|
@@ -13964,7 +14154,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
13964
14154
|
if (declarationStatement === null || validationStatement === null || declarationStatement.parent !== validationStatement.parent || validationStatement.range[0] <= declarationStatement.range[1] || hasConditionalAncestorBeforeStatement(parse2, validationStatement)) {
|
|
13965
14155
|
return null;
|
|
13966
14156
|
}
|
|
13967
|
-
if (validationStatement.type !==
|
|
14157
|
+
if (validationStatement.type !== AST_NODE_TYPES54.VariableDeclaration && validationStatement.type !== AST_NODE_TYPES54.ExpressionStatement) {
|
|
13968
14158
|
return null;
|
|
13969
14159
|
}
|
|
13970
14160
|
const method = zodParseMethod(parse2);
|
|
@@ -13976,16 +14166,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
13976
14166
|
};
|
|
13977
14167
|
const isSafePrevalidationInspection = (identifier) => {
|
|
13978
14168
|
const parent = identifier.parent;
|
|
13979
|
-
if (parent.type ===
|
|
14169
|
+
if (parent.type === AST_NODE_TYPES54.UnaryExpression && parent.operator === "typeof") {
|
|
13980
14170
|
return true;
|
|
13981
14171
|
}
|
|
13982
|
-
if (parent.type !==
|
|
14172
|
+
if (parent.type !== AST_NODE_TYPES54.BinaryExpression || parent.left !== identifier) {
|
|
13983
14173
|
return false;
|
|
13984
14174
|
}
|
|
13985
14175
|
if (parent.operator === "instanceof") {
|
|
13986
|
-
return parent.right.type ===
|
|
14176
|
+
return parent.right.type === AST_NODE_TYPES54.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
13987
14177
|
}
|
|
13988
|
-
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type ===
|
|
14178
|
+
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type === AST_NODE_TYPES54.Literal && parent.right.value === null || parent.right.type === AST_NODE_TYPES54.Identifier && parent.right.name === "undefined");
|
|
13989
14179
|
};
|
|
13990
14180
|
const isDescendantOf = (node, ancestor) => {
|
|
13991
14181
|
let current = node;
|
|
@@ -13996,23 +14186,23 @@ var require_zod_form_validation_default = createRule({
|
|
|
13996
14186
|
return false;
|
|
13997
14187
|
};
|
|
13998
14188
|
const blockTerminates = (node) => {
|
|
13999
|
-
if (node.type ===
|
|
14189
|
+
if (node.type === AST_NODE_TYPES54.ReturnStatement || node.type === AST_NODE_TYPES54.ThrowStatement) {
|
|
14000
14190
|
return true;
|
|
14001
14191
|
}
|
|
14002
|
-
if (node.type !==
|
|
14192
|
+
if (node.type !== AST_NODE_TYPES54.BlockStatement || node.body.length === 0) return false;
|
|
14003
14193
|
const last = node.body.at(-1);
|
|
14004
14194
|
return last !== void 0 && blockTerminates(last);
|
|
14005
14195
|
};
|
|
14006
14196
|
const narrowingIf = (identifier) => {
|
|
14007
14197
|
const comparison = identifier.parent;
|
|
14008
|
-
if (comparison?.type !==
|
|
14198
|
+
if (comparison?.type !== AST_NODE_TYPES54.BinaryExpression || comparison.operator !== "instanceof" || comparison.left !== identifier || comparison.right.type !== AST_NODE_TYPES54.Identifier || comparison.right.name !== "File" && comparison.right.name !== "Blob") {
|
|
14009
14199
|
return null;
|
|
14010
14200
|
}
|
|
14011
14201
|
const maybeNegation = comparison.parent;
|
|
14012
|
-
const negated = maybeNegation?.type ===
|
|
14202
|
+
const negated = maybeNegation?.type === AST_NODE_TYPES54.UnaryExpression && maybeNegation.operator === "!";
|
|
14013
14203
|
const test = negated ? maybeNegation : comparison;
|
|
14014
14204
|
const branch = test.parent;
|
|
14015
|
-
return branch?.type ===
|
|
14205
|
+
return branch?.type === AST_NODE_TYPES54.IfStatement && branch.test === test ? { branch, positive: !negated } : null;
|
|
14016
14206
|
};
|
|
14017
14207
|
const useDominatedByNarrowing = (use, narrowings) => narrowings.some(({ branch, positive }) => {
|
|
14018
14208
|
if (positive) return isDescendantOf(use, branch.consequent);
|
|
@@ -14032,7 +14222,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14032
14222
|
const variable = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
14033
14223
|
if (variable === void 0) return false;
|
|
14034
14224
|
const references = variable.references.filter((reference) => !reference.isWriteOnly()).map((reference) => reference.identifier).filter(
|
|
14035
|
-
(identifier) => identifier.type ===
|
|
14225
|
+
(identifier) => identifier.type === AST_NODE_TYPES54.Identifier
|
|
14036
14226
|
);
|
|
14037
14227
|
if (references.length === 0) return false;
|
|
14038
14228
|
const narrowings = references.map(narrowingIf).filter(
|
|
@@ -14058,7 +14248,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14058
14248
|
ImportDeclaration(node) {
|
|
14059
14249
|
if (!isZodModule(node.source.value)) return;
|
|
14060
14250
|
for (const specifier of node.specifiers) {
|
|
14061
|
-
if (specifier.type ===
|
|
14251
|
+
if (specifier.type === AST_NODE_TYPES54.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES54.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES54.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES54.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
14062
14252
|
const binding = resolvedBinding(specifier.local);
|
|
14063
14253
|
if (binding !== null) zodBindings.add(binding);
|
|
14064
14254
|
}
|
|
@@ -14143,7 +14333,7 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
14143
14333
|
});
|
|
14144
14334
|
|
|
14145
14335
|
// src/rules/stepdown.ts
|
|
14146
|
-
import { AST_NODE_TYPES as
|
|
14336
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES55, ASTUtils as ASTUtils15 } from "@typescript-eslint/utils";
|
|
14147
14337
|
var stepdownDocumentation = {
|
|
14148
14338
|
summary: "Place a private helper below its sole direct same-scope caller.",
|
|
14149
14339
|
rationale: "Caller-first ordering lets a reader follow the main flow before descending into implementation details.",
|
|
@@ -14160,7 +14350,7 @@ var stepdownDocumentation = {
|
|
|
14160
14350
|
]
|
|
14161
14351
|
};
|
|
14162
14352
|
function isFunction(node) {
|
|
14163
|
-
return node.type ===
|
|
14353
|
+
return node.type === AST_NODE_TYPES55.ArrowFunctionExpression || node.type === AST_NODE_TYPES55.FunctionDeclaration || node.type === AST_NODE_TYPES55.FunctionExpression;
|
|
14164
14354
|
}
|
|
14165
14355
|
function reportMisordered(context, candidates, scopeDefinitions, calls, pinned, canMove = () => true) {
|
|
14166
14356
|
const byName = new Map(scopeDefinitions.map((definition) => [definition.name, definition]));
|
|
@@ -14255,8 +14445,8 @@ function moduleScope(context, program) {
|
|
|
14255
14445
|
for (const node of declarations) counts.set(node.name, (counts.get(node.name) ?? 0) + 1);
|
|
14256
14446
|
const overloadNames = new Set(
|
|
14257
14447
|
program.body.flatMap((statement) => {
|
|
14258
|
-
const node = statement.type ===
|
|
14259
|
-
return node?.type ===
|
|
14448
|
+
const node = statement.type === AST_NODE_TYPES55.ExportNamedDeclaration ? statement.declaration : statement;
|
|
14449
|
+
return node?.type === AST_NODE_TYPES55.TSDeclareFunction && node.id !== null ? [node.id.name] : [];
|
|
14260
14450
|
})
|
|
14261
14451
|
);
|
|
14262
14452
|
const exported = exportedNames(program);
|
|
@@ -14280,7 +14470,7 @@ function moduleScope(context, program) {
|
|
|
14280
14470
|
const nearestFunction = [...ancestors].reverse().find(isFunction);
|
|
14281
14471
|
const parent = identifier.parent;
|
|
14282
14472
|
const callerDefinition = nearestFunction === void 0 ? void 0 : byFunction.get(nearestFunction);
|
|
14283
|
-
if (callerDefinition === void 0 || parent.type !==
|
|
14473
|
+
if (callerDefinition === void 0 || parent.type !== AST_NODE_TYPES55.CallExpression || parent.callee !== identifier) {
|
|
14284
14474
|
pinned.add(definition.name);
|
|
14285
14475
|
continue;
|
|
14286
14476
|
}
|
|
@@ -14295,38 +14485,38 @@ function moduleScope(context, program) {
|
|
|
14295
14485
|
function exportedNames(program) {
|
|
14296
14486
|
const names = /* @__PURE__ */ new Set();
|
|
14297
14487
|
for (const statement of program.body) {
|
|
14298
|
-
if (statement.type !==
|
|
14299
|
-
if (statement.declaration?.type ===
|
|
14488
|
+
if (statement.type !== AST_NODE_TYPES55.ExportNamedDeclaration || statement.exportKind === "type" || statement.source !== null) continue;
|
|
14489
|
+
if (statement.declaration?.type === AST_NODE_TYPES55.FunctionDeclaration && statement.declaration.id !== null) {
|
|
14300
14490
|
names.add(statement.declaration.id.name);
|
|
14301
14491
|
}
|
|
14302
|
-
if (statement.declaration?.type ===
|
|
14492
|
+
if (statement.declaration?.type === AST_NODE_TYPES55.VariableDeclaration) {
|
|
14303
14493
|
for (const declarator of statement.declaration.declarations) {
|
|
14304
|
-
if (declarator.id.type ===
|
|
14494
|
+
if (declarator.id.type === AST_NODE_TYPES55.Identifier) names.add(declarator.id.name);
|
|
14305
14495
|
}
|
|
14306
14496
|
}
|
|
14307
14497
|
for (const specifier of statement.specifiers) {
|
|
14308
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
14498
|
+
if (specifier.exportKind !== "type" && specifier.local.type === AST_NODE_TYPES55.Identifier) {
|
|
14309
14499
|
names.add(specifier.local.name);
|
|
14310
14500
|
}
|
|
14311
14501
|
}
|
|
14312
14502
|
}
|
|
14313
14503
|
for (const statement of program.body) {
|
|
14314
|
-
if (statement.type ===
|
|
14315
|
-
if (statement.type ===
|
|
14504
|
+
if (statement.type === AST_NODE_TYPES55.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES55.Identifier) names.add(statement.declaration.name);
|
|
14505
|
+
if (statement.type === AST_NODE_TYPES55.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES55.FunctionDeclaration && statement.declaration.id !== null) names.add(statement.declaration.id.name);
|
|
14316
14506
|
}
|
|
14317
14507
|
return names;
|
|
14318
14508
|
}
|
|
14319
14509
|
function moduleDefinitions(program) {
|
|
14320
14510
|
const definitions = [];
|
|
14321
14511
|
for (const statement of program.body) {
|
|
14322
|
-
const node = statement.type ===
|
|
14323
|
-
if (node?.type ===
|
|
14512
|
+
const node = statement.type === AST_NODE_TYPES55.ExportNamedDeclaration || statement.type === AST_NODE_TYPES55.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
14513
|
+
if (node?.type === AST_NODE_TYPES55.FunctionDeclaration && node.id !== null && node.body !== null) {
|
|
14324
14514
|
definitions.push({ name: node.id.name, node, functionNode: node, bindingNode: node });
|
|
14325
14515
|
continue;
|
|
14326
14516
|
}
|
|
14327
|
-
if (node?.type !==
|
|
14517
|
+
if (node?.type !== AST_NODE_TYPES55.VariableDeclaration || node.kind !== "const") continue;
|
|
14328
14518
|
for (const declarator of node.declarations) {
|
|
14329
|
-
if (declarator.id.type ===
|
|
14519
|
+
if (declarator.id.type === AST_NODE_TYPES55.Identifier && declarator.init !== null && isFunction(declarator.init)) {
|
|
14330
14520
|
definitions.push({
|
|
14331
14521
|
name: declarator.id.name,
|
|
14332
14522
|
node: declarator,
|
|
@@ -14339,21 +14529,21 @@ function moduleDefinitions(program) {
|
|
|
14339
14529
|
return definitions;
|
|
14340
14530
|
}
|
|
14341
14531
|
function methodName(node) {
|
|
14342
|
-
if (node.key.type ===
|
|
14343
|
-
return !node.computed && node.key.type ===
|
|
14532
|
+
if (node.key.type === AST_NODE_TYPES55.PrivateIdentifier) return `#${node.key.name}`;
|
|
14533
|
+
return !node.computed && node.key.type === AST_NODE_TYPES55.Identifier ? node.key.name : null;
|
|
14344
14534
|
}
|
|
14345
14535
|
function referencedMethod(context, node, classVariables) {
|
|
14346
|
-
const objectVariable = node.object.type ===
|
|
14536
|
+
const objectVariable = node.object.type === AST_NODE_TYPES55.Identifier ? ASTUtils15.findVariable(context.sourceCode.getScope(node.object), node.object.name) : null;
|
|
14347
14537
|
const isClassReference = objectVariable !== null && classVariables.has(objectVariable);
|
|
14348
|
-
if (node.object.type !==
|
|
14349
|
-
if (node.property.type ===
|
|
14350
|
-
if (!node.computed && node.property.type ===
|
|
14351
|
-
return node.computed && node.property.type ===
|
|
14538
|
+
if (node.object.type !== AST_NODE_TYPES55.ThisExpression && !isClassReference) return null;
|
|
14539
|
+
if (node.property.type === AST_NODE_TYPES55.PrivateIdentifier) return `#${node.property.name}`;
|
|
14540
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES55.Identifier) return node.property.name;
|
|
14541
|
+
return node.computed && node.property.type === AST_NODE_TYPES55.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
14352
14542
|
}
|
|
14353
14543
|
function referencedPropertyName(node) {
|
|
14354
|
-
if (node.property.type ===
|
|
14355
|
-
if (!node.computed && node.property.type ===
|
|
14356
|
-
return node.computed && node.property.type ===
|
|
14544
|
+
if (node.property.type === AST_NODE_TYPES55.PrivateIdentifier) return `#${node.property.name}`;
|
|
14545
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES55.Identifier) return node.property.name;
|
|
14546
|
+
return node.computed && node.property.type === AST_NODE_TYPES55.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
14357
14547
|
}
|
|
14358
14548
|
function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
14359
14549
|
visit(node, nestedFunction);
|
|
@@ -14369,7 +14559,7 @@ function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
|
14369
14559
|
}
|
|
14370
14560
|
function classScope(context, node, computedReferenceNames) {
|
|
14371
14561
|
const methods = node.body.body.filter(
|
|
14372
|
-
(member) => member.type ===
|
|
14562
|
+
(member) => member.type === AST_NODE_TYPES55.MethodDefinition
|
|
14373
14563
|
);
|
|
14374
14564
|
const counts = /* @__PURE__ */ new Map();
|
|
14375
14565
|
for (const method of methods) {
|
|
@@ -14377,8 +14567,8 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
14377
14567
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
14378
14568
|
}
|
|
14379
14569
|
for (const member of node.body.body) {
|
|
14380
|
-
if (member.type !==
|
|
14381
|
-
const name = !member.computed && member.key.type ===
|
|
14570
|
+
if (member.type !== AST_NODE_TYPES55.TSAbstractMethodDefinition) continue;
|
|
14571
|
+
const name = !member.computed && member.key.type === AST_NODE_TYPES55.Identifier ? member.key.name : null;
|
|
14382
14572
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
14383
14573
|
}
|
|
14384
14574
|
const scopeDefinitions = methods.flatMap((method) => {
|
|
@@ -14387,7 +14577,7 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
14387
14577
|
});
|
|
14388
14578
|
const definitions = methods.flatMap((method) => {
|
|
14389
14579
|
const name = methodName(method);
|
|
14390
|
-
const isPrivate = method.accessibility === "private" || method.key.type ===
|
|
14580
|
+
const isPrivate = method.accessibility === "private" || method.key.type === AST_NODE_TYPES55.PrivateIdentifier;
|
|
14391
14581
|
return name !== null && isPrivate && counts.get(name) === 1 && method.decorators.length === 0 ? [{ name, node: method }] : [];
|
|
14392
14582
|
});
|
|
14393
14583
|
if (definitions.length === 0) return;
|
|
@@ -14399,7 +14589,7 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
14399
14589
|
const internal = ASTUtils15.findVariable(context.sourceCode.getScope(node), node.id.name);
|
|
14400
14590
|
if (internal !== null) classVariables.add(internal);
|
|
14401
14591
|
}
|
|
14402
|
-
if (node.type ===
|
|
14592
|
+
if (node.type === AST_NODE_TYPES55.ClassExpression && node.parent.type === AST_NODE_TYPES55.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES55.Identifier) {
|
|
14403
14593
|
const outer = ASTUtils15.findVariable(context.sourceCode.getScope(node.parent), node.parent.id.name);
|
|
14404
14594
|
if (outer !== null) classVariables.add(outer);
|
|
14405
14595
|
}
|
|
@@ -14416,26 +14606,26 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
14416
14606
|
}
|
|
14417
14607
|
const thisValue = (value) => {
|
|
14418
14608
|
let current = value;
|
|
14419
|
-
while (current?.type ===
|
|
14420
|
-
return current?.type ===
|
|
14609
|
+
while (current?.type === AST_NODE_TYPES55.TSAsExpression || current?.type === AST_NODE_TYPES55.TSSatisfiesExpression || current?.type === AST_NODE_TYPES55.TSNonNullExpression) current = current.expression;
|
|
14610
|
+
return current?.type === AST_NODE_TYPES55.ThisExpression;
|
|
14421
14611
|
};
|
|
14422
14612
|
const collectAlias = (current, nestedFunction) => {
|
|
14423
|
-
if (nestedFunction || current.type !==
|
|
14424
|
-
if (current.type ===
|
|
14425
|
-
const binding = current.type ===
|
|
14426
|
-
const value = current.type ===
|
|
14613
|
+
if (nestedFunction || current.type !== AST_NODE_TYPES55.VariableDeclarator && current.type !== AST_NODE_TYPES55.AssignmentPattern) return;
|
|
14614
|
+
if (current.type === AST_NODE_TYPES55.VariableDeclarator && (current.parent.type !== AST_NODE_TYPES55.VariableDeclaration || current.parent.kind !== "const")) return;
|
|
14615
|
+
const binding = current.type === AST_NODE_TYPES55.VariableDeclarator ? current.id : current.left;
|
|
14616
|
+
const value = current.type === AST_NODE_TYPES55.VariableDeclarator ? current.init : current.right;
|
|
14427
14617
|
if (!thisValue(value)) return;
|
|
14428
|
-
if (binding.type ===
|
|
14618
|
+
if (binding.type === AST_NODE_TYPES55.ObjectPattern) {
|
|
14429
14619
|
for (const property of binding.properties) {
|
|
14430
|
-
if (property.type ===
|
|
14620
|
+
if (property.type === AST_NODE_TYPES55.RestElement) {
|
|
14431
14621
|
for (const name of privateNames) pinned.add(name);
|
|
14432
|
-
} else if (property.key.type ===
|
|
14622
|
+
} else if (property.key.type === AST_NODE_TYPES55.Identifier && privateNames.has(property.key.name)) {
|
|
14433
14623
|
pinned.add(property.key.name);
|
|
14434
14624
|
}
|
|
14435
14625
|
}
|
|
14436
14626
|
return;
|
|
14437
14627
|
}
|
|
14438
|
-
if (binding.type !==
|
|
14628
|
+
if (binding.type !== AST_NODE_TYPES55.Identifier) return;
|
|
14439
14629
|
const variable = ASTUtils15.findVariable(context.sourceCode.getScope(binding), binding.name);
|
|
14440
14630
|
if (variable !== null) {
|
|
14441
14631
|
methodClassVariables.add(variable);
|
|
@@ -14449,16 +14639,16 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
14449
14639
|
walk(statement, context.sourceCode.visitorKeys, collectAlias);
|
|
14450
14640
|
}
|
|
14451
14641
|
const visitCall = (current, nestedFunction) => {
|
|
14452
|
-
if (current.type ===
|
|
14642
|
+
if (current.type === AST_NODE_TYPES55.VariableDeclarator && current.id.type === AST_NODE_TYPES55.ObjectPattern && thisValue(current.init)) {
|
|
14453
14643
|
for (const property of current.id.properties) {
|
|
14454
|
-
if (property.type ===
|
|
14644
|
+
if (property.type === AST_NODE_TYPES55.RestElement) {
|
|
14455
14645
|
for (const name of privateNames) pinned.add(name);
|
|
14456
14646
|
continue;
|
|
14457
14647
|
}
|
|
14458
|
-
if (property.type ===
|
|
14648
|
+
if (property.type === AST_NODE_TYPES55.Property && property.key.type === AST_NODE_TYPES55.Identifier && privateNames.has(property.key.name)) pinned.add(property.key.name);
|
|
14459
14649
|
}
|
|
14460
14650
|
}
|
|
14461
|
-
if (current.type !==
|
|
14651
|
+
if (current.type !== AST_NODE_TYPES55.MemberExpression) return;
|
|
14462
14652
|
const target = referencedMethod(context, current, methodClassVariables);
|
|
14463
14653
|
if (target === null) {
|
|
14464
14654
|
const possibleTarget = referencedPropertyName(current);
|
|
@@ -14466,12 +14656,12 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
14466
14656
|
return;
|
|
14467
14657
|
}
|
|
14468
14658
|
if (!privateNames.has(target)) return;
|
|
14469
|
-
const objectVariable = current.object.type ===
|
|
14659
|
+
const objectVariable = current.object.type === AST_NODE_TYPES55.Identifier ? ASTUtils15.findVariable(context.sourceCode.getScope(current.object), current.object.name) : null;
|
|
14470
14660
|
if (objectVariable !== null && methodAliases.has(objectVariable)) {
|
|
14471
14661
|
pinned.add(target);
|
|
14472
14662
|
return;
|
|
14473
14663
|
}
|
|
14474
|
-
if (current.computed || nestedFunction || parameterDecoratorNodes.has(current) || current.parent.type !==
|
|
14664
|
+
if (current.computed || nestedFunction || parameterDecoratorNodes.has(current) || current.parent.type !== AST_NODE_TYPES55.CallExpression || current.parent.callee !== current) {
|
|
14475
14665
|
pinned.add(target);
|
|
14476
14666
|
return;
|
|
14477
14667
|
}
|
|
@@ -14491,9 +14681,9 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
14491
14681
|
}
|
|
14492
14682
|
}
|
|
14493
14683
|
for (const member of node.body.body) {
|
|
14494
|
-
if (member.type ===
|
|
14684
|
+
if (member.type === AST_NODE_TYPES55.MethodDefinition || member.type === AST_NODE_TYPES55.TSAbstractMethodDefinition) continue;
|
|
14495
14685
|
walk(member, context.sourceCode.visitorKeys, (current) => {
|
|
14496
|
-
if (current.type !==
|
|
14686
|
+
if (current.type !== AST_NODE_TYPES55.MemberExpression) return;
|
|
14497
14687
|
const target = referencedMethod(context, current, classVariables);
|
|
14498
14688
|
const possibleTarget = target ?? referencedPropertyName(current);
|
|
14499
14689
|
if (possibleTarget !== null && privateNames.has(possibleTarget)) pinned.add(possibleTarget);
|
|
@@ -14503,14 +14693,14 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
14503
14693
|
const accessibility = new Map(
|
|
14504
14694
|
scopeDefinitions.map((definition) => {
|
|
14505
14695
|
const method = definition.node;
|
|
14506
|
-
const accessibility2 = method.key.type ===
|
|
14696
|
+
const accessibility2 = method.key.type === AST_NODE_TYPES55.PrivateIdentifier ? "private" : method.accessibility ?? "public";
|
|
14507
14697
|
return [definition.name, accessibility2];
|
|
14508
14698
|
})
|
|
14509
14699
|
);
|
|
14510
14700
|
const methodByName = new Map(scopeDefinitions.map((definition) => [definition.name, definition.node]));
|
|
14511
14701
|
for (const [caller, callees] of calls) {
|
|
14512
14702
|
const callerMethod = methodByName.get(caller);
|
|
14513
|
-
if (accessibility.get(caller) === "private" && callerMethod?.type ===
|
|
14703
|
+
if (accessibility.get(caller) === "private" && callerMethod?.type === AST_NODE_TYPES55.MethodDefinition && callerMethod.decorators.length === 0) continue;
|
|
14514
14704
|
for (const callee of callees) pinned.add(callee);
|
|
14515
14705
|
}
|
|
14516
14706
|
const memberIndexes = new Map(node.body.body.map((member, index) => [member, index]));
|
|
@@ -14527,12 +14717,12 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
14527
14717
|
}
|
|
14528
14718
|
function isClassRuntimeBarrier(member) {
|
|
14529
14719
|
switch (member.type) {
|
|
14530
|
-
case
|
|
14720
|
+
case AST_NODE_TYPES55.StaticBlock:
|
|
14531
14721
|
return true;
|
|
14532
|
-
case
|
|
14533
|
-
case
|
|
14722
|
+
case AST_NODE_TYPES55.PropertyDefinition:
|
|
14723
|
+
case AST_NODE_TYPES55.AccessorProperty:
|
|
14534
14724
|
return member.static || member.computed || member.decorators.length > 0 || member.value !== null;
|
|
14535
|
-
case
|
|
14725
|
+
case AST_NODE_TYPES55.MethodDefinition:
|
|
14536
14726
|
return member.computed || member.decorators.length > 0;
|
|
14537
14727
|
default:
|
|
14538
14728
|
return false;
|
|
@@ -14564,7 +14754,7 @@ var stepdown_default = createRule({
|
|
|
14564
14754
|
moduleScope(context, program);
|
|
14565
14755
|
const computedReferenceNames = /* @__PURE__ */ new Set();
|
|
14566
14756
|
walk(program, context.sourceCode.visitorKeys, (node) => {
|
|
14567
|
-
if (node.type ===
|
|
14757
|
+
if (node.type === AST_NODE_TYPES55.MemberExpression && node.computed && node.property.type === AST_NODE_TYPES55.Literal && typeof node.property.value === "string") computedReferenceNames.add(node.property.value);
|
|
14568
14758
|
});
|
|
14569
14759
|
for (const node of classes) classScope(context, node, computedReferenceNames);
|
|
14570
14760
|
}
|
|
@@ -14574,7 +14764,7 @@ var stepdown_default = createRule({
|
|
|
14574
14764
|
|
|
14575
14765
|
// src/rules/zod-naming-convention.ts
|
|
14576
14766
|
import {
|
|
14577
|
-
AST_NODE_TYPES as
|
|
14767
|
+
AST_NODE_TYPES as AST_NODE_TYPES56,
|
|
14578
14768
|
ASTUtils as ASTUtils16
|
|
14579
14769
|
} from "@typescript-eslint/utils";
|
|
14580
14770
|
var zodNamingConventionDocumentation = {
|
|
@@ -14617,18 +14807,18 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
14617
14807
|
"prettifyError",
|
|
14618
14808
|
"treeifyError"
|
|
14619
14809
|
]);
|
|
14620
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
14810
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === AST_NODE_TYPES56.Identifier ? callee.property.name : null;
|
|
14621
14811
|
var calleeChainRoot = (node) => {
|
|
14622
14812
|
let current = node;
|
|
14623
14813
|
for (; ; ) {
|
|
14624
|
-
if (current.type ===
|
|
14814
|
+
if (current.type === AST_NODE_TYPES56.Identifier) {
|
|
14625
14815
|
return current;
|
|
14626
14816
|
}
|
|
14627
|
-
if (current.type ===
|
|
14817
|
+
if (current.type === AST_NODE_TYPES56.MemberExpression) {
|
|
14628
14818
|
current = current.object;
|
|
14629
14819
|
continue;
|
|
14630
14820
|
}
|
|
14631
|
-
if (current.type ===
|
|
14821
|
+
if (current.type === AST_NODE_TYPES56.CallExpression) {
|
|
14632
14822
|
current = current.callee;
|
|
14633
14823
|
continue;
|
|
14634
14824
|
}
|
|
@@ -14690,7 +14880,7 @@ var zod_naming_convention_default = createRule({
|
|
|
14690
14880
|
ImportDeclaration(node) {
|
|
14691
14881
|
if (!isZodModule(node.source.value)) return;
|
|
14692
14882
|
for (const specifier of node.specifiers) {
|
|
14693
|
-
if (specifier.type ===
|
|
14883
|
+
if (specifier.type === AST_NODE_TYPES56.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES56.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES56.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES56.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
14694
14884
|
recordZodBinding(specifier.local);
|
|
14695
14885
|
}
|
|
14696
14886
|
}
|
|
@@ -14698,13 +14888,13 @@ var zod_naming_convention_default = createRule({
|
|
|
14698
14888
|
VariableDeclarator(node) {
|
|
14699
14889
|
const init = node.init;
|
|
14700
14890
|
if (init === null || init === void 0) return;
|
|
14701
|
-
if (init.type !==
|
|
14891
|
+
if (init.type !== AST_NODE_TYPES56.CallExpression) return;
|
|
14702
14892
|
const callee = init.callee;
|
|
14703
|
-
if (callee.type !==
|
|
14893
|
+
if (callee.type !== AST_NODE_TYPES56.MemberExpression) return;
|
|
14704
14894
|
if (!isZodChain(callee)) return;
|
|
14705
14895
|
const terminal = terminalMethodName(callee);
|
|
14706
14896
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
14707
|
-
if (node.id.type !==
|
|
14897
|
+
if (node.id.type !== AST_NODE_TYPES56.Identifier) return;
|
|
14708
14898
|
if (test.test(node.id.name)) return;
|
|
14709
14899
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
14710
14900
|
context.report({
|
|
@@ -14848,6 +15038,7 @@ var rules = {
|
|
|
14848
15038
|
"prefer-module-level-schema": prefer_module_level_schema_default,
|
|
14849
15039
|
"prefer-native-random-uuid": prefer_native_random_uuid_default,
|
|
14850
15040
|
"prefer-non-nullable-collection": prefer_non_nullable_collection_default,
|
|
15041
|
+
"prefer-await-in-async-return": prefer_await_in_async_return_default,
|
|
14851
15042
|
"prefer-schema-for-api-payload": prefer_schema_for_api_payload_default,
|
|
14852
15043
|
"prefer-semantic-colors": prefer_semantic_colors_default,
|
|
14853
15044
|
"prefer-server-actions": prefer_server_actions_default,
|
|
@@ -14864,7 +15055,7 @@ var rules = {
|
|
|
14864
15055
|
};
|
|
14865
15056
|
var meta = {
|
|
14866
15057
|
name: "@sarj/eslint-plugin",
|
|
14867
|
-
version: "15.6.
|
|
15058
|
+
version: "15.6.4"
|
|
14868
15059
|
};
|
|
14869
15060
|
var applicationOnlyRules = [
|
|
14870
15061
|
"no-restricted-library-load",
|
|
@@ -14915,6 +15106,7 @@ var recommendedRules = {
|
|
|
14915
15106
|
"@sarj/prefer-module-level-constant": "error",
|
|
14916
15107
|
"@sarj/prefer-module-level-schema": "error",
|
|
14917
15108
|
"@sarj/prefer-non-nullable-collection": "error",
|
|
15109
|
+
"@sarj/prefer-await-in-async-return": "error",
|
|
14918
15110
|
"@sarj/prefer-schema-for-api-payload": "error",
|
|
14919
15111
|
"@sarj/prefer-semantic-colors": ["error", { requireSemanticTokens: true }],
|
|
14920
15112
|
"@sarj/prefer-server-actions": "error",
|
|
@@ -14977,6 +15169,7 @@ var strictRules = {
|
|
|
14977
15169
|
"@sarj/prefer-module-level-constant": "error",
|
|
14978
15170
|
"@sarj/prefer-module-level-schema": "error",
|
|
14979
15171
|
"@sarj/prefer-non-nullable-collection": "error",
|
|
15172
|
+
"@sarj/prefer-await-in-async-return": "error",
|
|
14980
15173
|
"@sarj/prefer-schema-for-api-payload": "error",
|
|
14981
15174
|
"@sarj/prefer-semantic-colors": ["error", { requireSemanticTokens: true }],
|
|
14982
15175
|
"@sarj/prefer-server-actions": "error",
|