@sarj/eslint-plugin 15.6.2 → 15.6.3
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 +569 -422
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +567 -417
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -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
|
}
|
|
@@ -10820,8 +10842,133 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
10820
10842
|
}
|
|
10821
10843
|
});
|
|
10822
10844
|
|
|
10845
|
+
// src/rules/prefer-await-in-async-return.ts
|
|
10846
|
+
import {
|
|
10847
|
+
ESLintUtils as ESLintUtils3,
|
|
10848
|
+
AST_NODE_TYPES as AST_NODE_TYPES45
|
|
10849
|
+
} from "@typescript-eslint/utils";
|
|
10850
|
+
import * as ts2 from "typescript";
|
|
10851
|
+
var preferAwaitInAsyncReturnDocumentation = {
|
|
10852
|
+
summary: "Prefer explicit `await` when an async function directly returns one typed Promise `.then` transform.",
|
|
10853
|
+
rationale: "Mixing a directly returned Promise callback into otherwise async control flow makes sequencing and failures harder to read.",
|
|
10854
|
+
remediation: "Await the Promise, then return the transformed value with ordinary async statements.",
|
|
10855
|
+
category: "maintainability",
|
|
10856
|
+
since: "15.6.3",
|
|
10857
|
+
limitations: [
|
|
10858
|
+
"Only a single directly returned `.then` call with an inline callback is checked.",
|
|
10859
|
+
"The receiver must be proven Promise-like by TypeScript; untyped files and larger chains are intentionally ignored."
|
|
10860
|
+
],
|
|
10861
|
+
examples: [
|
|
10862
|
+
{
|
|
10863
|
+
id: "explicit-async-transform",
|
|
10864
|
+
title: "Use explicit async control flow",
|
|
10865
|
+
outcome: "no-match",
|
|
10866
|
+
files: [{
|
|
10867
|
+
path: "src/load.ts",
|
|
10868
|
+
source: "async function load() { const value = await Promise.resolve(1); return value + 1; }"
|
|
10869
|
+
}],
|
|
10870
|
+
focusPath: "src/load.ts",
|
|
10871
|
+
expectedCount: 0,
|
|
10872
|
+
public: true
|
|
10873
|
+
},
|
|
10874
|
+
{
|
|
10875
|
+
id: "returned-then-transform",
|
|
10876
|
+
title: "Do not directly return a Promise callback chain from async code",
|
|
10877
|
+
outcome: "match",
|
|
10878
|
+
files: [{
|
|
10879
|
+
path: "src/load.ts",
|
|
10880
|
+
source: "async function load() { return Promise.resolve(1).then((value) => value + 1); }"
|
|
10881
|
+
}],
|
|
10882
|
+
focusPath: "src/load.ts",
|
|
10883
|
+
expectedCount: 1,
|
|
10884
|
+
public: true
|
|
10885
|
+
}
|
|
10886
|
+
]
|
|
10887
|
+
};
|
|
10888
|
+
function isDirectAsyncReturn(node) {
|
|
10889
|
+
const parent = node.parent;
|
|
10890
|
+
if (parent.type === AST_NODE_TYPES45.ArrowFunctionExpression && parent.body === node) {
|
|
10891
|
+
return parent.async && !parent.generator;
|
|
10892
|
+
}
|
|
10893
|
+
if (parent.type !== AST_NODE_TYPES45.ReturnStatement || parent.argument !== node) {
|
|
10894
|
+
return false;
|
|
10895
|
+
}
|
|
10896
|
+
let owner = parent.parent;
|
|
10897
|
+
while (owner !== void 0 && !isRuntimeFunction(owner)) {
|
|
10898
|
+
owner = owner.parent;
|
|
10899
|
+
}
|
|
10900
|
+
return owner !== void 0 && owner.async && !owner.generator;
|
|
10901
|
+
}
|
|
10902
|
+
function isRuntimeFunction(node) {
|
|
10903
|
+
return node.type === AST_NODE_TYPES45.ArrowFunctionExpression || node.type === AST_NODE_TYPES45.FunctionDeclaration || node.type === AST_NODE_TYPES45.FunctionExpression;
|
|
10904
|
+
}
|
|
10905
|
+
function promiseThenReceiver(node) {
|
|
10906
|
+
const callee = node.callee;
|
|
10907
|
+
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) {
|
|
10908
|
+
return null;
|
|
10909
|
+
}
|
|
10910
|
+
const callback = node.arguments[0];
|
|
10911
|
+
if (callback === void 0 || callback.type !== AST_NODE_TYPES45.ArrowFunctionExpression && callback.type !== AST_NODE_TYPES45.FunctionExpression) {
|
|
10912
|
+
return null;
|
|
10913
|
+
}
|
|
10914
|
+
return callee.object;
|
|
10915
|
+
}
|
|
10916
|
+
function isProvenPromiseLike(node, services) {
|
|
10917
|
+
const checker = services.program.getTypeChecker();
|
|
10918
|
+
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
|
10919
|
+
const receiverType = checker.getTypeAtLocation(tsNode);
|
|
10920
|
+
if ((receiverType.flags & (ts2.TypeFlags.Any | ts2.TypeFlags.Unknown | ts2.TypeFlags.Never)) !== 0) {
|
|
10921
|
+
return false;
|
|
10922
|
+
}
|
|
10923
|
+
const thenSymbol = checker.getPropertyOfType(receiverType, "then");
|
|
10924
|
+
const hasBuiltInPromiseDeclaration = thenSymbol?.declarations?.some(
|
|
10925
|
+
(declaration) => {
|
|
10926
|
+
let owner = declaration.parent;
|
|
10927
|
+
while (owner !== void 0 && !ts2.isInterfaceDeclaration(owner)) {
|
|
10928
|
+
owner = owner.parent;
|
|
10929
|
+
}
|
|
10930
|
+
return owner !== void 0 && (owner.name.text === "Promise" || owner.name.text === "PromiseLike") && services.program.isSourceFileDefaultLibrary(owner.getSourceFile());
|
|
10931
|
+
}
|
|
10932
|
+
) ?? false;
|
|
10933
|
+
return hasBuiltInPromiseDeclaration;
|
|
10934
|
+
}
|
|
10935
|
+
var prefer_await_in_async_return_default = createRule({
|
|
10936
|
+
name: "prefer-await-in-async-return",
|
|
10937
|
+
documentation: preferAwaitInAsyncReturnDocumentation,
|
|
10938
|
+
meta: {
|
|
10939
|
+
type: "suggestion",
|
|
10940
|
+
docs: {
|
|
10941
|
+
description: "Prefer explicit `await` when an async function directly returns one typed Promise `.then` transform."
|
|
10942
|
+
},
|
|
10943
|
+
schema: [],
|
|
10944
|
+
messages: {
|
|
10945
|
+
preferAwait: "This async function directly returns a Promise `.then` transform. Await the Promise, then return the transformed value with explicit async control flow."
|
|
10946
|
+
}
|
|
10947
|
+
},
|
|
10948
|
+
defaultOptions: [],
|
|
10949
|
+
create(context) {
|
|
10950
|
+
let services;
|
|
10951
|
+
try {
|
|
10952
|
+
services = ESLintUtils3.getParserServices(context);
|
|
10953
|
+
} catch {
|
|
10954
|
+
services = null;
|
|
10955
|
+
}
|
|
10956
|
+
if (services === null) return {};
|
|
10957
|
+
return {
|
|
10958
|
+
CallExpression(node) {
|
|
10959
|
+
if (!isDirectAsyncReturn(node)) return;
|
|
10960
|
+
const receiver = promiseThenReceiver(node);
|
|
10961
|
+
if (receiver === null || !isProvenPromiseLike(receiver, services)) {
|
|
10962
|
+
return;
|
|
10963
|
+
}
|
|
10964
|
+
context.report({ node, messageId: "preferAwait" });
|
|
10965
|
+
}
|
|
10966
|
+
};
|
|
10967
|
+
}
|
|
10968
|
+
});
|
|
10969
|
+
|
|
10823
10970
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
10824
|
-
import { AST_NODE_TYPES as
|
|
10971
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES46 } from "@typescript-eslint/utils";
|
|
10825
10972
|
var preferSchemaForApiPayloadDocumentation = {
|
|
10826
10973
|
summary: "Require Zod (or similar) schema validation on `response.json()` / `JSON.parse()` results before property access.",
|
|
10827
10974
|
rationale: "External JSON is untrusted at runtime even when its expected TypeScript shape is known statically.",
|
|
@@ -10836,9 +10983,9 @@ var preferSchemaForApiPayloadDocumentation = {
|
|
|
10836
10983
|
var unwrap4 = (node) => {
|
|
10837
10984
|
let current = node;
|
|
10838
10985
|
while (current !== null && current !== void 0) {
|
|
10839
|
-
if (current.type ===
|
|
10986
|
+
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
10987
|
current = current.expression;
|
|
10841
|
-
} else if (current.type ===
|
|
10988
|
+
} else if (current.type === AST_NODE_TYPES46.ChainExpression) {
|
|
10842
10989
|
current = current.expression;
|
|
10843
10990
|
} else {
|
|
10844
10991
|
break;
|
|
@@ -10853,23 +11000,23 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
10853
11000
|
]);
|
|
10854
11001
|
var isSchemaParseReference = (node) => {
|
|
10855
11002
|
const inner = unwrap4(node);
|
|
10856
|
-
return inner !== null && inner.type ===
|
|
11003
|
+
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
11004
|
};
|
|
10858
11005
|
var isRawPayloadSource = (node, isKnownLocalText) => {
|
|
10859
11006
|
let current = unwrap4(node);
|
|
10860
11007
|
if (current === null) return false;
|
|
10861
|
-
if (current.type ===
|
|
11008
|
+
if (current.type === AST_NODE_TYPES46.AwaitExpression) {
|
|
10862
11009
|
current = unwrap4(current.argument);
|
|
10863
11010
|
}
|
|
10864
|
-
if (current === null || current.type !==
|
|
11011
|
+
if (current === null || current.type !== AST_NODE_TYPES46.CallExpression) {
|
|
10865
11012
|
return false;
|
|
10866
11013
|
}
|
|
10867
11014
|
const callee = unwrap4(current.callee);
|
|
10868
|
-
if (callee === null || callee.type !==
|
|
11015
|
+
if (callee === null || callee.type !== AST_NODE_TYPES46.MemberExpression) {
|
|
10869
11016
|
return false;
|
|
10870
11017
|
}
|
|
10871
11018
|
const property = unwrap4(callee.property);
|
|
10872
|
-
if (property === null || property.type !==
|
|
11019
|
+
if (property === null || property.type !== AST_NODE_TYPES46.Identifier) {
|
|
10873
11020
|
return false;
|
|
10874
11021
|
}
|
|
10875
11022
|
if (property.name === "json") {
|
|
@@ -10879,17 +11026,17 @@ var isRawPayloadSource = (node, isKnownLocalText) => {
|
|
|
10879
11026
|
return !current.arguments.some(isSchemaParseReference) && isRawPayloadSource(callee.object);
|
|
10880
11027
|
}
|
|
10881
11028
|
const object = unwrap4(callee.object);
|
|
10882
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
11029
|
+
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
11030
|
};
|
|
10884
11031
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
10885
11032
|
var isDirectLocalFileRead = (node) => {
|
|
10886
11033
|
let current = unwrap4(node);
|
|
10887
|
-
if (current?.type ===
|
|
11034
|
+
if (current?.type === AST_NODE_TYPES46.AwaitExpression) {
|
|
10888
11035
|
current = unwrap4(current.argument);
|
|
10889
11036
|
}
|
|
10890
|
-
if (current?.type !==
|
|
11037
|
+
if (current?.type !== AST_NODE_TYPES46.CallExpression) return false;
|
|
10891
11038
|
const callee = unwrap4(current.callee);
|
|
10892
|
-
const name = callee?.type ===
|
|
11039
|
+
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
11040
|
return name !== null && FILE_READ_RE.test(name);
|
|
10894
11041
|
};
|
|
10895
11042
|
var isLocalFileRead = (node) => {
|
|
@@ -10916,15 +11063,15 @@ var isLocalFileRead = (node) => {
|
|
|
10916
11063
|
var ASSERTION_CALLEE_RE = /^(expect|assert|should|invariant)$/;
|
|
10917
11064
|
var isInsideAssertion = (node) => {
|
|
10918
11065
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
10919
|
-
if (current.type !==
|
|
11066
|
+
if (current.type !== AST_NODE_TYPES46.CallExpression) continue;
|
|
10920
11067
|
let callee = current.callee;
|
|
10921
|
-
while (callee.type ===
|
|
11068
|
+
while (callee.type === AST_NODE_TYPES46.MemberExpression) {
|
|
10922
11069
|
callee = callee.object;
|
|
10923
11070
|
}
|
|
10924
|
-
if (callee.type ===
|
|
11071
|
+
if (callee.type === AST_NODE_TYPES46.CallExpression) {
|
|
10925
11072
|
callee = callee.callee;
|
|
10926
11073
|
}
|
|
10927
|
-
if (callee.type ===
|
|
11074
|
+
if (callee.type === AST_NODE_TYPES46.Identifier && ASSERTION_CALLEE_RE.test(callee.name)) {
|
|
10928
11075
|
return true;
|
|
10929
11076
|
}
|
|
10930
11077
|
}
|
|
@@ -10943,22 +11090,22 @@ var GUARD_NAME_RE = /^(?:is|validate|parse|assert|decode|coerce)[A-Z]/;
|
|
|
10943
11090
|
var isValidationRead = (node) => {
|
|
10944
11091
|
let current = node;
|
|
10945
11092
|
let parent = current.parent;
|
|
10946
|
-
while (parent !== null && parent !== void 0 && (parent.type ===
|
|
11093
|
+
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
11094
|
current = parent;
|
|
10948
11095
|
parent = parent.parent;
|
|
10949
11096
|
}
|
|
10950
11097
|
if (parent === null || parent === void 0) return false;
|
|
10951
|
-
if (parent.type ===
|
|
11098
|
+
if (parent.type === AST_NODE_TYPES46.UnaryExpression && parent.operator === "typeof" && parent.argument === current) {
|
|
10952
11099
|
return true;
|
|
10953
11100
|
}
|
|
10954
|
-
if (parent.type !==
|
|
11101
|
+
if (parent.type !== AST_NODE_TYPES46.CallExpression || !parent.arguments.some((arg) => arg === current)) {
|
|
10955
11102
|
return false;
|
|
10956
11103
|
}
|
|
10957
11104
|
const callee = parent.callee;
|
|
10958
|
-
if (callee.type ===
|
|
11105
|
+
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
11106
|
return parent.arguments.length === 1;
|
|
10960
11107
|
}
|
|
10961
|
-
return callee.type ===
|
|
11108
|
+
return callee.type === AST_NODE_TYPES46.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
10962
11109
|
};
|
|
10963
11110
|
var PRIMITIVE_TYPEOF_RESULTS = /* @__PURE__ */ new Set([
|
|
10964
11111
|
"bigint",
|
|
@@ -10969,13 +11116,13 @@ var PRIMITIVE_TYPEOF_RESULTS = /* @__PURE__ */ new Set([
|
|
|
10969
11116
|
"undefined"
|
|
10970
11117
|
]);
|
|
10971
11118
|
var bindingValidationPolarity = (test, bindingName) => {
|
|
10972
|
-
if (test.type ===
|
|
11119
|
+
if (test.type === AST_NODE_TYPES46.UnaryExpression && test.operator === "!") {
|
|
10973
11120
|
const inner = bindingValidationPolarity(test.argument, bindingName);
|
|
10974
11121
|
return inner === "valid-when-true" ? "valid-when-false" : inner === "valid-when-false" ? "valid-when-true" : null;
|
|
10975
11122
|
}
|
|
10976
|
-
if (test.type ===
|
|
10977
|
-
const typeofName = (node) => node.type ===
|
|
10978
|
-
const literalType = (node) => node.type ===
|
|
11123
|
+
if (test.type === AST_NODE_TYPES46.BinaryExpression) {
|
|
11124
|
+
const typeofName = (node) => node.type === AST_NODE_TYPES46.UnaryExpression && node.operator === "typeof" && node.argument.type === AST_NODE_TYPES46.Identifier ? node.argument.name : null;
|
|
11125
|
+
const literalType = (node) => node.type === AST_NODE_TYPES46.Literal && typeof node.value === "string" && PRIMITIVE_TYPEOF_RESULTS.has(node.value) ? node.value : null;
|
|
10979
11126
|
const matches = typeofName(test.left) === bindingName && literalType(test.right) !== null || typeofName(test.right) === bindingName && literalType(test.left) !== null;
|
|
10980
11127
|
if (!matches) return null;
|
|
10981
11128
|
if (test.operator === "===" || test.operator === "==") {
|
|
@@ -10983,9 +11130,9 @@ var bindingValidationPolarity = (test, bindingName) => {
|
|
|
10983
11130
|
}
|
|
10984
11131
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
10985
11132
|
}
|
|
10986
|
-
return test.type ===
|
|
11133
|
+
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
11134
|
};
|
|
10988
|
-
var plainMemberAccess = (node) => node.type ===
|
|
11135
|
+
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
11136
|
var isSamePlainMember = (node, access) => {
|
|
10990
11137
|
const candidate = plainMemberAccess(node);
|
|
10991
11138
|
return candidate !== null && candidate.object === access.object && candidate.property === access.property;
|
|
@@ -10993,19 +11140,19 @@ var isSamePlainMember = (node, access) => {
|
|
|
10993
11140
|
var nodeWithin2 = (node, container) => node.range[0] >= container.range[0] && node.range[1] <= container.range[1];
|
|
10994
11141
|
var isUseWithinValidatedBranch = (node, bindingName) => {
|
|
10995
11142
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
10996
|
-
if (current.type ===
|
|
11143
|
+
if (current.type === AST_NODE_TYPES46.ConditionalExpression) {
|
|
10997
11144
|
const polarity = bindingValidationPolarity(current.test, bindingName);
|
|
10998
11145
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && nodeWithin2(node, current.alternate)) {
|
|
10999
11146
|
return true;
|
|
11000
11147
|
}
|
|
11001
11148
|
}
|
|
11002
|
-
if (current.type ===
|
|
11149
|
+
if (current.type === AST_NODE_TYPES46.IfStatement) {
|
|
11003
11150
|
const polarity = bindingValidationPolarity(current.test, bindingName);
|
|
11004
11151
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && current.alternate !== null && nodeWithin2(node, current.alternate)) {
|
|
11005
11152
|
return true;
|
|
11006
11153
|
}
|
|
11007
11154
|
}
|
|
11008
|
-
if (current.type ===
|
|
11155
|
+
if (current.type === AST_NODE_TYPES46.FunctionDeclaration || current.type === AST_NODE_TYPES46.FunctionExpression || current.type === AST_NODE_TYPES46.ArrowFunctionExpression) {
|
|
11009
11156
|
return false;
|
|
11010
11157
|
}
|
|
11011
11158
|
}
|
|
@@ -11013,32 +11160,32 @@ var isUseWithinValidatedBranch = (node, bindingName) => {
|
|
|
11013
11160
|
};
|
|
11014
11161
|
var isMemberUseWithinValidatedBranch = (node, access) => {
|
|
11015
11162
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11016
|
-
if (current.type ===
|
|
11163
|
+
if (current.type === AST_NODE_TYPES46.ConditionalExpression) {
|
|
11017
11164
|
const polarity = memberValidationPolarity(current.test, access);
|
|
11018
11165
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && nodeWithin2(node, current.alternate)) {
|
|
11019
11166
|
return true;
|
|
11020
11167
|
}
|
|
11021
11168
|
}
|
|
11022
|
-
if (current.type ===
|
|
11169
|
+
if (current.type === AST_NODE_TYPES46.IfStatement) {
|
|
11023
11170
|
const polarity = memberValidationPolarity(current.test, access);
|
|
11024
11171
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && current.alternate !== null && nodeWithin2(node, current.alternate)) {
|
|
11025
11172
|
return true;
|
|
11026
11173
|
}
|
|
11027
11174
|
}
|
|
11028
|
-
if (current.type ===
|
|
11175
|
+
if (current.type === AST_NODE_TYPES46.FunctionDeclaration || current.type === AST_NODE_TYPES46.FunctionExpression || current.type === AST_NODE_TYPES46.ArrowFunctionExpression) {
|
|
11029
11176
|
return false;
|
|
11030
11177
|
}
|
|
11031
11178
|
}
|
|
11032
11179
|
return false;
|
|
11033
11180
|
};
|
|
11034
11181
|
var memberValidationPolarity = (test, access) => {
|
|
11035
|
-
if (test.type ===
|
|
11182
|
+
if (test.type === AST_NODE_TYPES46.UnaryExpression && test.operator === "!") {
|
|
11036
11183
|
const inner = memberValidationPolarity(test.argument, access);
|
|
11037
11184
|
return inner === "valid-when-true" ? "valid-when-false" : inner === "valid-when-false" ? "valid-when-true" : null;
|
|
11038
11185
|
}
|
|
11039
|
-
if (test.type ===
|
|
11040
|
-
const isMatchingTypeof = (node) => node.type ===
|
|
11041
|
-
const isPrimitiveType = (node) => node.type ===
|
|
11186
|
+
if (test.type === AST_NODE_TYPES46.BinaryExpression) {
|
|
11187
|
+
const isMatchingTypeof = (node) => node.type === AST_NODE_TYPES46.UnaryExpression && node.operator === "typeof" && isSamePlainMember(node.argument, access);
|
|
11188
|
+
const isPrimitiveType = (node) => node.type === AST_NODE_TYPES46.Literal && typeof node.value === "string" && PRIMITIVE_TYPEOF_RESULTS.has(node.value);
|
|
11042
11189
|
if (!(isMatchingTypeof(test.left) && isPrimitiveType(test.right) || isMatchingTypeof(test.right) && isPrimitiveType(test.left))) {
|
|
11043
11190
|
return null;
|
|
11044
11191
|
}
|
|
@@ -11047,15 +11194,15 @@ var memberValidationPolarity = (test, access) => {
|
|
|
11047
11194
|
}
|
|
11048
11195
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
11049
11196
|
}
|
|
11050
|
-
return test.type ===
|
|
11197
|
+
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
11198
|
};
|
|
11052
11199
|
var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
11053
11200
|
const isValidationReference = (identifier) => {
|
|
11054
11201
|
for (let current = identifier.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11055
|
-
if ((current.type ===
|
|
11202
|
+
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
11203
|
return true;
|
|
11057
11204
|
}
|
|
11058
|
-
if (current.type !==
|
|
11205
|
+
if (current.type !== AST_NODE_TYPES46.UnaryExpression && current.type !== AST_NODE_TYPES46.MemberExpression && current.type !== AST_NODE_TYPES46.CallExpression) {
|
|
11059
11206
|
return false;
|
|
11060
11207
|
}
|
|
11061
11208
|
}
|
|
@@ -11063,7 +11210,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11063
11210
|
};
|
|
11064
11211
|
const isGuardedUse = (identifier) => {
|
|
11065
11212
|
for (let current = identifier.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11066
|
-
if (current.type ===
|
|
11213
|
+
if (current.type === AST_NODE_TYPES46.ConditionalExpression) {
|
|
11067
11214
|
const polarity = bindingValidationPolarity(current.test, identifier.name);
|
|
11068
11215
|
if (polarity === "valid-when-true" && nodeWithin2(identifier, current.consequent)) {
|
|
11069
11216
|
return true;
|
|
@@ -11072,7 +11219,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11072
11219
|
return true;
|
|
11073
11220
|
}
|
|
11074
11221
|
}
|
|
11075
|
-
if (current.type ===
|
|
11222
|
+
if (current.type === AST_NODE_TYPES46.IfStatement) {
|
|
11076
11223
|
const polarity = bindingValidationPolarity(current.test, identifier.name);
|
|
11077
11224
|
if (polarity === "valid-when-true" && nodeWithin2(identifier, current.consequent)) {
|
|
11078
11225
|
return true;
|
|
@@ -11081,14 +11228,14 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11081
11228
|
return true;
|
|
11082
11229
|
}
|
|
11083
11230
|
}
|
|
11084
|
-
if (current.type ===
|
|
11231
|
+
if (current.type === AST_NODE_TYPES46.FunctionDeclaration || current.type === AST_NODE_TYPES46.FunctionExpression || current.type === AST_NODE_TYPES46.ArrowFunctionExpression) {
|
|
11085
11232
|
return false;
|
|
11086
11233
|
}
|
|
11087
11234
|
}
|
|
11088
11235
|
return false;
|
|
11089
11236
|
};
|
|
11090
11237
|
const declarator = member.parent;
|
|
11091
|
-
if (declarator.type !==
|
|
11238
|
+
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
11239
|
return false;
|
|
11093
11240
|
}
|
|
11094
11241
|
const extracted = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
@@ -11096,7 +11243,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11096
11243
|
let hasValueUse = false;
|
|
11097
11244
|
for (const reference of extracted.references) {
|
|
11098
11245
|
const identifier = reference.identifier;
|
|
11099
|
-
if (identifier.type !==
|
|
11246
|
+
if (identifier.type !== AST_NODE_TYPES46.Identifier) return false;
|
|
11100
11247
|
if (nodeWithin2(identifier, declarator)) continue;
|
|
11101
11248
|
if (isValidationReference(identifier)) continue;
|
|
11102
11249
|
hasValueUse = true;
|
|
@@ -11109,17 +11256,17 @@ var isGuardTestPosition = (node) => {
|
|
|
11109
11256
|
let parent = current.parent;
|
|
11110
11257
|
while (parent !== void 0 && parent !== null) {
|
|
11111
11258
|
switch (parent.type) {
|
|
11112
|
-
case
|
|
11113
|
-
case
|
|
11114
|
-
case
|
|
11259
|
+
case AST_NODE_TYPES46.UnaryExpression:
|
|
11260
|
+
case AST_NODE_TYPES46.LogicalExpression:
|
|
11261
|
+
case AST_NODE_TYPES46.ChainExpression:
|
|
11115
11262
|
current = parent;
|
|
11116
11263
|
parent = parent.parent;
|
|
11117
11264
|
continue;
|
|
11118
|
-
case
|
|
11119
|
-
case
|
|
11120
|
-
case
|
|
11121
|
-
case
|
|
11122
|
-
case
|
|
11265
|
+
case AST_NODE_TYPES46.IfStatement:
|
|
11266
|
+
case AST_NODE_TYPES46.ConditionalExpression:
|
|
11267
|
+
case AST_NODE_TYPES46.WhileStatement:
|
|
11268
|
+
case AST_NODE_TYPES46.DoWhileStatement:
|
|
11269
|
+
case AST_NODE_TYPES46.ForStatement:
|
|
11123
11270
|
return parent.test === current;
|
|
11124
11271
|
default:
|
|
11125
11272
|
return false;
|
|
@@ -11129,7 +11276,7 @@ var isGuardTestPosition = (node) => {
|
|
|
11129
11276
|
};
|
|
11130
11277
|
var unvalidatedVariableRef = (node, scope, tracked) => {
|
|
11131
11278
|
const unwrapped = unwrap4(node);
|
|
11132
|
-
if (unwrapped === null || unwrapped.type !==
|
|
11279
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES46.Identifier) {
|
|
11133
11280
|
return null;
|
|
11134
11281
|
}
|
|
11135
11282
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -11158,7 +11305,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11158
11305
|
const localFileTextVariables = /* @__PURE__ */ new Set();
|
|
11159
11306
|
const localFileTextRef = (node, scope) => {
|
|
11160
11307
|
const unwrapped = unwrap4(node);
|
|
11161
|
-
if (unwrapped?.type !==
|
|
11308
|
+
if (unwrapped?.type !== AST_NODE_TYPES46.Identifier) return null;
|
|
11162
11309
|
const variable = findVariable2(scope, unwrapped.name);
|
|
11163
11310
|
return variable !== null && localFileTextVariables.has(variable) ? variable : null;
|
|
11164
11311
|
};
|
|
@@ -11227,7 +11374,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11227
11374
|
return {
|
|
11228
11375
|
VariableDeclarator(node) {
|
|
11229
11376
|
const scope = context.sourceCode.getScope(node);
|
|
11230
|
-
if (node.id.type ===
|
|
11377
|
+
if (node.id.type === AST_NODE_TYPES46.Identifier) {
|
|
11231
11378
|
const variable = context.sourceCode.getDeclaredVariables(node)[0];
|
|
11232
11379
|
if (variable !== void 0) {
|
|
11233
11380
|
updateLocalFileText(variable, node.init, scope);
|
|
@@ -11235,7 +11382,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11235
11382
|
trackInitializer(node, scope);
|
|
11236
11383
|
return;
|
|
11237
11384
|
}
|
|
11238
|
-
if (node.id.type ===
|
|
11385
|
+
if (node.id.type === AST_NODE_TYPES46.ObjectPattern || node.id.type === AST_NODE_TYPES46.ArrayPattern) {
|
|
11239
11386
|
if (isRawPayloadSource(
|
|
11240
11387
|
node.init,
|
|
11241
11388
|
(candidate) => localFileTextRef(candidate, scope) !== null
|
|
@@ -11252,7 +11399,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11252
11399
|
},
|
|
11253
11400
|
AssignmentExpression(node) {
|
|
11254
11401
|
const scope = context.sourceCode.getScope(node);
|
|
11255
|
-
if (node.left.type ===
|
|
11402
|
+
if (node.left.type === AST_NODE_TYPES46.Identifier) {
|
|
11256
11403
|
const variable = findVariable2(scope, node.left.name);
|
|
11257
11404
|
if (variable === null) return;
|
|
11258
11405
|
const isLocalText = (candidate) => localFileTextRef(candidate, scope) !== null;
|
|
@@ -11266,7 +11413,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11266
11413
|
}
|
|
11267
11414
|
return;
|
|
11268
11415
|
}
|
|
11269
|
-
if (node.left.type ===
|
|
11416
|
+
if (node.left.type === AST_NODE_TYPES46.ObjectPattern || node.left.type === AST_NODE_TYPES46.ArrayPattern) {
|
|
11270
11417
|
if (isRawPayloadSource(
|
|
11271
11418
|
node.right,
|
|
11272
11419
|
(candidate) => localFileTextRef(candidate, scope) !== null
|
|
@@ -11286,15 +11433,15 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11286
11433
|
}
|
|
11287
11434
|
},
|
|
11288
11435
|
CallExpression(node) {
|
|
11289
|
-
if (node.callee.type !==
|
|
11436
|
+
if (node.callee.type !== AST_NODE_TYPES46.Identifier) return;
|
|
11290
11437
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
11291
11438
|
return;
|
|
11292
11439
|
}
|
|
11293
11440
|
const scope = context.sourceCode.getScope(node);
|
|
11294
11441
|
for (const arg of node.arguments) {
|
|
11295
|
-
if (arg.type ===
|
|
11442
|
+
if (arg.type === AST_NODE_TYPES46.SpreadElement) continue;
|
|
11296
11443
|
const unwrapped = unwrap4(arg);
|
|
11297
|
-
if (unwrapped === null || unwrapped.type !==
|
|
11444
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES46.Identifier) {
|
|
11298
11445
|
continue;
|
|
11299
11446
|
}
|
|
11300
11447
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -11311,14 +11458,14 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11311
11458
|
(candidate) => localFileTextRef(candidate, scope) !== null
|
|
11312
11459
|
)) {
|
|
11313
11460
|
const parent = node.parent;
|
|
11314
|
-
if (parent.type ===
|
|
11461
|
+
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
11462
|
return;
|
|
11316
11463
|
}
|
|
11317
11464
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
11318
11465
|
return;
|
|
11319
11466
|
}
|
|
11320
|
-
const variable = obj?.type ===
|
|
11321
|
-
if (variable !== null && obj?.type ===
|
|
11467
|
+
const variable = obj?.type === AST_NODE_TYPES46.Identifier ? unvalidatedVariableRef(obj, scope, unvalidatedVariables) : null;
|
|
11468
|
+
if (variable !== null && obj?.type === AST_NODE_TYPES46.Identifier) {
|
|
11322
11469
|
if (isUseWithinValidatedBranch(node, obj.name)) {
|
|
11323
11470
|
return;
|
|
11324
11471
|
}
|
|
@@ -11338,7 +11485,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11338
11485
|
});
|
|
11339
11486
|
|
|
11340
11487
|
// src/rules/prefer-semantic-colors.ts
|
|
11341
|
-
import { AST_NODE_TYPES as
|
|
11488
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES47 } from "@typescript-eslint/utils";
|
|
11342
11489
|
import { existsSync, readdirSync, readFileSync } from "fs";
|
|
11343
11490
|
import { dirname, join, parse } from "path";
|
|
11344
11491
|
|
|
@@ -11450,7 +11597,7 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
11450
11597
|
var isInsideSvg = (node) => {
|
|
11451
11598
|
let current = node.parent;
|
|
11452
11599
|
while (current !== void 0 && current !== null) {
|
|
11453
|
-
if (current.type ===
|
|
11600
|
+
if (current.type === AST_NODE_TYPES47.JSXElement) {
|
|
11454
11601
|
const name = jsxElementName(current);
|
|
11455
11602
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
11456
11603
|
}
|
|
@@ -11460,8 +11607,8 @@ var isInsideSvg = (node) => {
|
|
|
11460
11607
|
};
|
|
11461
11608
|
function jsxElementName(node) {
|
|
11462
11609
|
const name = node.openingElement.name;
|
|
11463
|
-
if (name.type ===
|
|
11464
|
-
if (name.type ===
|
|
11610
|
+
if (name.type === AST_NODE_TYPES47.JSXIdentifier) return name.name;
|
|
11611
|
+
if (name.type === AST_NODE_TYPES47.JSXMemberExpression && name.property.type === AST_NODE_TYPES47.JSXIdentifier) {
|
|
11465
11612
|
return name.property.name;
|
|
11466
11613
|
}
|
|
11467
11614
|
return null;
|
|
@@ -11487,7 +11634,7 @@ function isSvgLikeElementName(name) {
|
|
|
11487
11634
|
var isInsideIconFactoryPath = (node) => {
|
|
11488
11635
|
let current = node.parent;
|
|
11489
11636
|
while (current !== void 0 && current !== null) {
|
|
11490
|
-
if (current.type ===
|
|
11637
|
+
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
11638
|
return true;
|
|
11492
11639
|
}
|
|
11493
11640
|
current = current.parent;
|
|
@@ -11621,12 +11768,12 @@ var expandWorkspaceGlob = (root, glob) => {
|
|
|
11621
11768
|
return readdirSync(parent, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => join(parent, entry.name));
|
|
11622
11769
|
};
|
|
11623
11770
|
var propName = (key) => {
|
|
11624
|
-
if (key.type ===
|
|
11625
|
-
if (key.type ===
|
|
11771
|
+
if (key.type === AST_NODE_TYPES47.Identifier) return key.name;
|
|
11772
|
+
if (key.type === AST_NODE_TYPES47.Literal && typeof key.value === "string") return key.value;
|
|
11626
11773
|
return null;
|
|
11627
11774
|
};
|
|
11628
11775
|
var staticallyImportsEmailOrPdfRenderer = (program) => program.body.some((statement) => {
|
|
11629
|
-
if (statement.type !==
|
|
11776
|
+
if (statement.type !== AST_NODE_TYPES47.ImportDeclaration && statement.type !== AST_NODE_TYPES47.ExportNamedDeclaration && statement.type !== AST_NODE_TYPES47.ExportAllDeclaration) {
|
|
11630
11777
|
return false;
|
|
11631
11778
|
}
|
|
11632
11779
|
return statement.source !== null && typeof statement.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(statement.source.value);
|
|
@@ -11679,27 +11826,27 @@ var prefer_semantic_colors_default = createRule({
|
|
|
11679
11826
|
const checkClassNode = (node) => {
|
|
11680
11827
|
if (node === null) return;
|
|
11681
11828
|
switch (node.type) {
|
|
11682
|
-
case
|
|
11829
|
+
case AST_NODE_TYPES47.Literal:
|
|
11683
11830
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
11684
11831
|
break;
|
|
11685
|
-
case
|
|
11832
|
+
case AST_NODE_TYPES47.TemplateLiteral:
|
|
11686
11833
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
11687
11834
|
break;
|
|
11688
|
-
case
|
|
11835
|
+
case AST_NODE_TYPES47.ArrayExpression:
|
|
11689
11836
|
for (const element of node.elements) {
|
|
11690
|
-
if (element !== null && element.type !==
|
|
11837
|
+
if (element !== null && element.type !== AST_NODE_TYPES47.SpreadElement) checkClassNode(element);
|
|
11691
11838
|
}
|
|
11692
11839
|
break;
|
|
11693
|
-
case
|
|
11840
|
+
case AST_NODE_TYPES47.ObjectExpression:
|
|
11694
11841
|
for (const property of node.properties) {
|
|
11695
|
-
if (property.type ===
|
|
11842
|
+
if (property.type === AST_NODE_TYPES47.Property) checkClassNode(property.value);
|
|
11696
11843
|
}
|
|
11697
11844
|
break;
|
|
11698
|
-
case
|
|
11845
|
+
case AST_NODE_TYPES47.ConditionalExpression:
|
|
11699
11846
|
checkClassNode(node.consequent);
|
|
11700
11847
|
checkClassNode(node.alternate);
|
|
11701
11848
|
break;
|
|
11702
|
-
case
|
|
11849
|
+
case AST_NODE_TYPES47.LogicalExpression:
|
|
11703
11850
|
checkClassNode(node.right);
|
|
11704
11851
|
break;
|
|
11705
11852
|
default:
|
|
@@ -11707,32 +11854,32 @@ var prefer_semantic_colors_default = createRule({
|
|
|
11707
11854
|
}
|
|
11708
11855
|
};
|
|
11709
11856
|
const checkColorValueNode = (node) => {
|
|
11710
|
-
if (node.type ===
|
|
11857
|
+
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
11858
|
report(node, "inlineColor", { value: node.value });
|
|
11712
11859
|
}
|
|
11713
11860
|
};
|
|
11714
11861
|
return {
|
|
11715
11862
|
"JSXAttribute[name.name='className']"(node) {
|
|
11716
11863
|
if (node.value === null) return;
|
|
11717
|
-
if (node.value.type ===
|
|
11718
|
-
else if (node.value.type ===
|
|
11719
|
-
if (node.value.expression.type !==
|
|
11864
|
+
if (node.value.type === AST_NODE_TYPES47.Literal) checkClassNode(node.value);
|
|
11865
|
+
else if (node.value.type === AST_NODE_TYPES47.JSXExpressionContainer) {
|
|
11866
|
+
if (node.value.expression.type !== AST_NODE_TYPES47.JSXEmptyExpression) {
|
|
11720
11867
|
checkClassNode(node.value.expression);
|
|
11721
11868
|
}
|
|
11722
11869
|
}
|
|
11723
11870
|
},
|
|
11724
11871
|
CallExpression(node) {
|
|
11725
|
-
if (node.callee.type ===
|
|
11872
|
+
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
11873
|
importsEmailOrPdfRenderer = true;
|
|
11727
11874
|
}
|
|
11728
|
-
if (node.callee.type ===
|
|
11875
|
+
if (node.callee.type === AST_NODE_TYPES47.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
11729
11876
|
for (const arg of node.arguments) {
|
|
11730
|
-
if (arg.type !==
|
|
11877
|
+
if (arg.type !== AST_NODE_TYPES47.SpreadElement) checkClassNode(arg);
|
|
11731
11878
|
}
|
|
11732
11879
|
}
|
|
11733
11880
|
},
|
|
11734
11881
|
VariableDeclarator(node) {
|
|
11735
|
-
if (node.id.type ===
|
|
11882
|
+
if (node.id.type === AST_NODE_TYPES47.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
11736
11883
|
checkClassNode(node.init);
|
|
11737
11884
|
}
|
|
11738
11885
|
},
|
|
@@ -11742,9 +11889,9 @@ var prefer_semantic_colors_default = createRule({
|
|
|
11742
11889
|
},
|
|
11743
11890
|
// SVG artwork colors are exempt; component presentation colors still report.
|
|
11744
11891
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
11745
|
-
if (node.value?.type !==
|
|
11892
|
+
if (node.value?.type !== AST_NODE_TYPES47.Literal) return;
|
|
11746
11893
|
const owner = node.parent.name;
|
|
11747
|
-
if (owner.type ===
|
|
11894
|
+
if (owner.type === AST_NODE_TYPES47.JSXIdentifier && SVG_SHAPE_PRIMITIVES.has(owner.name)) {
|
|
11748
11895
|
return;
|
|
11749
11896
|
}
|
|
11750
11897
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
@@ -11758,7 +11905,7 @@ var prefer_semantic_colors_default = createRule({
|
|
|
11758
11905
|
if (name !== null && STYLE_COLOR_PROPS.has(name)) checkColorValueNode(node.value);
|
|
11759
11906
|
},
|
|
11760
11907
|
ImportExpression(node) {
|
|
11761
|
-
if (node.source.type ===
|
|
11908
|
+
if (node.source.type === AST_NODE_TYPES47.Literal && typeof node.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.source.value)) {
|
|
11762
11909
|
importsEmailOrPdfRenderer = true;
|
|
11763
11910
|
}
|
|
11764
11911
|
},
|
|
@@ -11960,7 +12107,7 @@ var prefer_server_actions_default = createRule({
|
|
|
11960
12107
|
});
|
|
11961
12108
|
|
|
11962
12109
|
// src/rules/prefer-whole-object-assertion.ts
|
|
11963
|
-
import { AST_NODE_TYPES as
|
|
12110
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES48 } from "@typescript-eslint/utils";
|
|
11964
12111
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
11965
12112
|
var SYNTHETIC_LITERAL_MATCHERS = /* @__PURE__ */ new Map([
|
|
11966
12113
|
["toBeNull", "null"],
|
|
@@ -11985,11 +12132,11 @@ var preferWholeObjectAssertionDocumentation = {
|
|
|
11985
12132
|
};
|
|
11986
12133
|
function literalText(node, getText) {
|
|
11987
12134
|
switch (node.type) {
|
|
11988
|
-
case
|
|
12135
|
+
case AST_NODE_TYPES48.Literal:
|
|
11989
12136
|
return "regex" in node ? null : getText(node);
|
|
11990
|
-
case
|
|
12137
|
+
case AST_NODE_TYPES48.TemplateLiteral:
|
|
11991
12138
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
11992
|
-
case
|
|
12139
|
+
case AST_NODE_TYPES48.UnaryExpression:
|
|
11993
12140
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
11994
12141
|
default:
|
|
11995
12142
|
return null;
|
|
@@ -11997,15 +12144,15 @@ function literalText(node, getText) {
|
|
|
11997
12144
|
}
|
|
11998
12145
|
function isPureReceiver(node) {
|
|
11999
12146
|
switch (node.type) {
|
|
12000
|
-
case
|
|
12001
|
-
case
|
|
12147
|
+
case AST_NODE_TYPES48.Identifier:
|
|
12148
|
+
case AST_NODE_TYPES48.ThisExpression:
|
|
12002
12149
|
return true;
|
|
12003
|
-
case
|
|
12150
|
+
case AST_NODE_TYPES48.MemberExpression:
|
|
12004
12151
|
if (node.optional) {
|
|
12005
12152
|
return false;
|
|
12006
12153
|
}
|
|
12007
12154
|
if (node.computed) {
|
|
12008
|
-
return node.property.type ===
|
|
12155
|
+
return node.property.type === AST_NODE_TYPES48.Literal && isPureReceiver(node.object);
|
|
12009
12156
|
}
|
|
12010
12157
|
return isPureReceiver(node.object);
|
|
12011
12158
|
default:
|
|
@@ -12013,7 +12160,7 @@ function isPureReceiver(node) {
|
|
|
12013
12160
|
}
|
|
12014
12161
|
}
|
|
12015
12162
|
function literalIndex(node) {
|
|
12016
|
-
if (node.type !==
|
|
12163
|
+
if (node.type !== AST_NODE_TYPES48.Literal || typeof node.value !== "number") {
|
|
12017
12164
|
return null;
|
|
12018
12165
|
}
|
|
12019
12166
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
@@ -12040,24 +12187,24 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
12040
12187
|
}
|
|
12041
12188
|
const { sourceCode } = context;
|
|
12042
12189
|
function parseAssertion(statement) {
|
|
12043
|
-
if (statement.type !==
|
|
12190
|
+
if (statement.type !== AST_NODE_TYPES48.ExpressionStatement) {
|
|
12044
12191
|
return null;
|
|
12045
12192
|
}
|
|
12046
12193
|
const call = statement.expression;
|
|
12047
|
-
if (call.type !==
|
|
12194
|
+
if (call.type !== AST_NODE_TYPES48.CallExpression) {
|
|
12048
12195
|
return null;
|
|
12049
12196
|
}
|
|
12050
12197
|
const callee = call.callee;
|
|
12051
|
-
if (callee.type !==
|
|
12198
|
+
if (callee.type !== AST_NODE_TYPES48.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES48.Identifier) {
|
|
12052
12199
|
return null;
|
|
12053
12200
|
}
|
|
12054
12201
|
const matcher = callee.property.name;
|
|
12055
12202
|
const expectCall = callee.object;
|
|
12056
|
-
if (expectCall.type !==
|
|
12203
|
+
if (expectCall.type !== AST_NODE_TYPES48.CallExpression || expectCall.callee.type !== AST_NODE_TYPES48.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
12057
12204
|
return null;
|
|
12058
12205
|
}
|
|
12059
12206
|
const actual = expectCall.arguments[0];
|
|
12060
|
-
if (actual === void 0 || actual.type !==
|
|
12207
|
+
if (actual === void 0 || actual.type !== AST_NODE_TYPES48.MemberExpression || actual.optional) {
|
|
12061
12208
|
return null;
|
|
12062
12209
|
}
|
|
12063
12210
|
if (!isPureReceiver(actual.object)) {
|
|
@@ -12071,7 +12218,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
12071
12218
|
}
|
|
12072
12219
|
key = { kind: "index", index };
|
|
12073
12220
|
} else {
|
|
12074
|
-
if (actual.property.type !==
|
|
12221
|
+
if (actual.property.type !== AST_NODE_TYPES48.Identifier || COLLECTION_PROPERTIES.has(actual.property.name) || LITERAL_KEY_HAZARDS.has(actual.property.name)) {
|
|
12075
12222
|
return null;
|
|
12076
12223
|
}
|
|
12077
12224
|
key = { kind: "property", name: actual.property.name };
|
|
@@ -12084,7 +12231,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
12084
12231
|
return null;
|
|
12085
12232
|
}
|
|
12086
12233
|
const expected = call.arguments[0];
|
|
12087
|
-
if (call.arguments.length !== 1 || expected === void 0 || expected.type ===
|
|
12234
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === AST_NODE_TYPES48.SpreadElement) {
|
|
12088
12235
|
return null;
|
|
12089
12236
|
}
|
|
12090
12237
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
@@ -12199,7 +12346,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
12199
12346
|
});
|
|
12200
12347
|
|
|
12201
12348
|
// src/rules/prefer-zod-infer.ts
|
|
12202
|
-
import { AST_NODE_TYPES as
|
|
12349
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES49 } from "@typescript-eslint/utils";
|
|
12203
12350
|
var preferZodInferDocumentation = {
|
|
12204
12351
|
summary: "Derive a type from its Zod schema with `z.infer` instead of hand-writing a twin declaration beside it.",
|
|
12205
12352
|
rationale: "A derived type stays synchronized when the runtime schema changes.",
|
|
@@ -12252,47 +12399,47 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
12252
12399
|
"Schema"
|
|
12253
12400
|
]);
|
|
12254
12401
|
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: [
|
|
12402
|
+
string: [AST_NODE_TYPES49.TSStringKeyword],
|
|
12403
|
+
email: [AST_NODE_TYPES49.TSStringKeyword],
|
|
12404
|
+
url: [AST_NODE_TYPES49.TSStringKeyword],
|
|
12405
|
+
uuid: [AST_NODE_TYPES49.TSStringKeyword],
|
|
12406
|
+
ulid: [AST_NODE_TYPES49.TSStringKeyword],
|
|
12407
|
+
cuid: [AST_NODE_TYPES49.TSStringKeyword],
|
|
12408
|
+
cuid2: [AST_NODE_TYPES49.TSStringKeyword],
|
|
12409
|
+
nanoid: [AST_NODE_TYPES49.TSStringKeyword],
|
|
12410
|
+
iso: [AST_NODE_TYPES49.TSStringKeyword],
|
|
12411
|
+
number: [AST_NODE_TYPES49.TSNumberKeyword],
|
|
12412
|
+
int: [AST_NODE_TYPES49.TSNumberKeyword],
|
|
12413
|
+
float32: [AST_NODE_TYPES49.TSNumberKeyword],
|
|
12414
|
+
float64: [AST_NODE_TYPES49.TSNumberKeyword],
|
|
12415
|
+
boolean: [AST_NODE_TYPES49.TSBooleanKeyword],
|
|
12416
|
+
bigint: [AST_NODE_TYPES49.TSBigIntKeyword],
|
|
12417
|
+
symbol: [AST_NODE_TYPES49.TSSymbolKeyword],
|
|
12418
|
+
any: [AST_NODE_TYPES49.TSAnyKeyword],
|
|
12419
|
+
unknown: [AST_NODE_TYPES49.TSUnknownKeyword],
|
|
12420
|
+
never: [AST_NODE_TYPES49.TSNeverKeyword],
|
|
12421
|
+
void: [AST_NODE_TYPES49.TSVoidKeyword],
|
|
12422
|
+
null: [AST_NODE_TYPES49.TSNullKeyword],
|
|
12423
|
+
undefined: [AST_NODE_TYPES49.TSUndefinedKeyword],
|
|
12424
|
+
literal: [AST_NODE_TYPES49.TSLiteralType],
|
|
12425
|
+
date: [AST_NODE_TYPES49.TSTypeReference],
|
|
12426
|
+
array: [AST_NODE_TYPES49.TSArrayType, AST_NODE_TYPES49.TSTypeReference],
|
|
12427
|
+
tuple: [AST_NODE_TYPES49.TSTupleType],
|
|
12428
|
+
object: [AST_NODE_TYPES49.TSTypeLiteral, AST_NODE_TYPES49.TSTypeReference],
|
|
12429
|
+
strictObject: [AST_NODE_TYPES49.TSTypeLiteral, AST_NODE_TYPES49.TSTypeReference],
|
|
12430
|
+
looseObject: [AST_NODE_TYPES49.TSTypeLiteral, AST_NODE_TYPES49.TSTypeReference],
|
|
12431
|
+
record: [AST_NODE_TYPES49.TSTypeReference, AST_NODE_TYPES49.TSTypeLiteral],
|
|
12432
|
+
map: [AST_NODE_TYPES49.TSTypeReference],
|
|
12433
|
+
set: [AST_NODE_TYPES49.TSTypeReference],
|
|
12434
|
+
promise: [AST_NODE_TYPES49.TSTypeReference],
|
|
12435
|
+
enum: [AST_NODE_TYPES49.TSUnionType, AST_NODE_TYPES49.TSTypeReference, AST_NODE_TYPES49.TSLiteralType],
|
|
12436
|
+
nativeEnum: [AST_NODE_TYPES49.TSUnionType, AST_NODE_TYPES49.TSTypeReference, AST_NODE_TYPES49.TSLiteralType],
|
|
12437
|
+
union: [AST_NODE_TYPES49.TSUnionType, AST_NODE_TYPES49.TSTypeReference],
|
|
12438
|
+
discriminatedUnion: [AST_NODE_TYPES49.TSUnionType, AST_NODE_TYPES49.TSTypeReference],
|
|
12439
|
+
intersection: [AST_NODE_TYPES49.TSIntersectionType, AST_NODE_TYPES49.TSTypeReference]
|
|
12293
12440
|
};
|
|
12294
12441
|
function primitiveLiteralKey(node) {
|
|
12295
|
-
if (node.type !==
|
|
12442
|
+
if (node.type !== AST_NODE_TYPES49.Literal) {
|
|
12296
12443
|
return null;
|
|
12297
12444
|
}
|
|
12298
12445
|
if (node.value === null) {
|
|
@@ -12324,13 +12471,13 @@ function staticZodDomain(leaf, call) {
|
|
|
12324
12471
|
}
|
|
12325
12472
|
if (leaf === "literal") {
|
|
12326
12473
|
const [argument] = call.arguments;
|
|
12327
|
-
if (argument === void 0 || argument.type ===
|
|
12474
|
+
if (argument === void 0 || argument.type === AST_NODE_TYPES49.SpreadElement) {
|
|
12328
12475
|
return null;
|
|
12329
12476
|
}
|
|
12330
|
-
if (argument.type ===
|
|
12477
|
+
if (argument.type === AST_NODE_TYPES49.ArrayExpression) {
|
|
12331
12478
|
return exactDomain(
|
|
12332
12479
|
argument.elements.map(
|
|
12333
|
-
(element) => element === null || element.type ===
|
|
12480
|
+
(element) => element === null || element.type === AST_NODE_TYPES49.SpreadElement ? null : primitiveLiteralKey(element)
|
|
12334
12481
|
)
|
|
12335
12482
|
);
|
|
12336
12483
|
}
|
|
@@ -12338,13 +12485,13 @@ function staticZodDomain(leaf, call) {
|
|
|
12338
12485
|
}
|
|
12339
12486
|
if (leaf === "enum") {
|
|
12340
12487
|
const [argument] = call.arguments;
|
|
12341
|
-
if (argument === void 0 || argument.type ===
|
|
12488
|
+
if (argument === void 0 || argument.type === AST_NODE_TYPES49.SpreadElement) {
|
|
12342
12489
|
return null;
|
|
12343
12490
|
}
|
|
12344
|
-
if (argument.type ===
|
|
12491
|
+
if (argument.type === AST_NODE_TYPES49.ArrayExpression) {
|
|
12345
12492
|
return exactDomain(
|
|
12346
12493
|
argument.elements.map((element) => {
|
|
12347
|
-
if (element === null || element.type ===
|
|
12494
|
+
if (element === null || element.type === AST_NODE_TYPES49.SpreadElement) {
|
|
12348
12495
|
return null;
|
|
12349
12496
|
}
|
|
12350
12497
|
const key = primitiveLiteralKey(element);
|
|
@@ -12352,10 +12499,10 @@ function staticZodDomain(leaf, call) {
|
|
|
12352
12499
|
})
|
|
12353
12500
|
);
|
|
12354
12501
|
}
|
|
12355
|
-
if (argument.type ===
|
|
12502
|
+
if (argument.type === AST_NODE_TYPES49.ObjectExpression) {
|
|
12356
12503
|
return exactDomain(
|
|
12357
12504
|
argument.properties.map((property) => {
|
|
12358
|
-
if (property.type !==
|
|
12505
|
+
if (property.type !== AST_NODE_TYPES49.Property || property.computed || property.kind !== "init" || property.method || property.shorthand) {
|
|
12359
12506
|
return null;
|
|
12360
12507
|
}
|
|
12361
12508
|
const key = primitiveLiteralKey(property.value);
|
|
@@ -12382,15 +12529,15 @@ function sameDomain(left, right) {
|
|
|
12382
12529
|
return true;
|
|
12383
12530
|
}
|
|
12384
12531
|
function isExportedDeclaration(node) {
|
|
12385
|
-
return node.parent?.type ===
|
|
12532
|
+
return node.parent?.type === AST_NODE_TYPES49.ExportNamedDeclaration;
|
|
12386
12533
|
}
|
|
12387
12534
|
function isModuleLevelConst(node) {
|
|
12388
12535
|
const declaration = node.parent;
|
|
12389
|
-
if (declaration.type !==
|
|
12536
|
+
if (declaration.type !== AST_NODE_TYPES49.VariableDeclaration || declaration.kind !== "const") {
|
|
12390
12537
|
return false;
|
|
12391
12538
|
}
|
|
12392
12539
|
const container = declaration.parent;
|
|
12393
|
-
return container.type ===
|
|
12540
|
+
return container.type === AST_NODE_TYPES49.Program || container.type === AST_NODE_TYPES49.ExportNamedDeclaration && container.parent.type === AST_NODE_TYPES49.Program;
|
|
12394
12541
|
}
|
|
12395
12542
|
function normalizeSchemaName(name) {
|
|
12396
12543
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -12399,20 +12546,20 @@ function normalizeTypeName(name) {
|
|
|
12399
12546
|
return name.replace(/Type$/, "").toLowerCase();
|
|
12400
12547
|
}
|
|
12401
12548
|
function unwrapNullish(annotation) {
|
|
12402
|
-
if (annotation.type !==
|
|
12549
|
+
if (annotation.type !== AST_NODE_TYPES49.TSUnionType) {
|
|
12403
12550
|
return {
|
|
12404
12551
|
core: annotation,
|
|
12405
|
-
nullable: annotation.type ===
|
|
12552
|
+
nullable: annotation.type === AST_NODE_TYPES49.TSNullKeyword
|
|
12406
12553
|
};
|
|
12407
12554
|
}
|
|
12408
12555
|
const rest = [];
|
|
12409
12556
|
let nullable = false;
|
|
12410
12557
|
for (const member of annotation.types) {
|
|
12411
|
-
if (member.type ===
|
|
12558
|
+
if (member.type === AST_NODE_TYPES49.TSNullKeyword) {
|
|
12412
12559
|
nullable = true;
|
|
12413
12560
|
continue;
|
|
12414
12561
|
}
|
|
12415
|
-
if (member.type ===
|
|
12562
|
+
if (member.type === AST_NODE_TYPES49.TSUndefinedKeyword) {
|
|
12416
12563
|
continue;
|
|
12417
12564
|
}
|
|
12418
12565
|
rest.push(member);
|
|
@@ -12446,18 +12593,18 @@ function leafAgrees(field, annotation) {
|
|
|
12446
12593
|
return null;
|
|
12447
12594
|
}
|
|
12448
12595
|
if (leaf === "date") {
|
|
12449
|
-
return core.type ===
|
|
12596
|
+
return core.type === AST_NODE_TYPES49.TSTypeReference && core.typeName.type === AST_NODE_TYPES49.Identifier && core.typeName.name === "Date";
|
|
12450
12597
|
}
|
|
12451
12598
|
return expected.includes(core.type);
|
|
12452
12599
|
}
|
|
12453
12600
|
function typeLiteralDomain(annotation) {
|
|
12454
|
-
const members = annotation.type ===
|
|
12601
|
+
const members = annotation.type === AST_NODE_TYPES49.TSUnionType ? annotation.types : [annotation];
|
|
12455
12602
|
const keys = [];
|
|
12456
12603
|
for (const member of members) {
|
|
12457
|
-
if (member.type ===
|
|
12604
|
+
if (member.type === AST_NODE_TYPES49.TSNullKeyword) {
|
|
12458
12605
|
continue;
|
|
12459
12606
|
}
|
|
12460
|
-
if (member.type !==
|
|
12607
|
+
if (member.type !== AST_NODE_TYPES49.TSLiteralType) {
|
|
12461
12608
|
return null;
|
|
12462
12609
|
}
|
|
12463
12610
|
keys.push(primitiveLiteralKey(member.literal));
|
|
@@ -12465,11 +12612,11 @@ function typeLiteralDomain(annotation) {
|
|
|
12465
12612
|
return exactDomain(keys);
|
|
12466
12613
|
}
|
|
12467
12614
|
function staticStringUnionDomain(node) {
|
|
12468
|
-
if (node.type !==
|
|
12615
|
+
if (node.type !== AST_NODE_TYPES49.TSUnionType) {
|
|
12469
12616
|
return null;
|
|
12470
12617
|
}
|
|
12471
12618
|
const keys = node.types.map((member) => {
|
|
12472
|
-
if (member.type !==
|
|
12619
|
+
if (member.type !== AST_NODE_TYPES49.TSLiteralType) {
|
|
12473
12620
|
return null;
|
|
12474
12621
|
}
|
|
12475
12622
|
const key = primitiveLiteralKey(member.literal);
|
|
@@ -12537,14 +12684,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
12537
12684
|
function zodCallChain(node) {
|
|
12538
12685
|
const chain = [];
|
|
12539
12686
|
let current = node;
|
|
12540
|
-
while (current.type ===
|
|
12687
|
+
while (current.type === AST_NODE_TYPES49.CallExpression) {
|
|
12541
12688
|
const callee = current.callee;
|
|
12542
|
-
if (callee.type !==
|
|
12689
|
+
if (callee.type !== AST_NODE_TYPES49.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES49.Identifier) {
|
|
12543
12690
|
return null;
|
|
12544
12691
|
}
|
|
12545
12692
|
chain.push(current);
|
|
12546
12693
|
const receiver = callee.object;
|
|
12547
|
-
if (receiver.type ===
|
|
12694
|
+
if (receiver.type === AST_NODE_TYPES49.Identifier) {
|
|
12548
12695
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
12549
12696
|
}
|
|
12550
12697
|
current = receiver;
|
|
@@ -12553,14 +12700,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
12553
12700
|
}
|
|
12554
12701
|
function methodName2(call) {
|
|
12555
12702
|
const callee = call.callee;
|
|
12556
|
-
return callee.type ===
|
|
12703
|
+
return callee.type === AST_NODE_TYPES49.MemberExpression && callee.property.type === AST_NODE_TYPES49.Identifier ? callee.property.name : "";
|
|
12557
12704
|
}
|
|
12558
12705
|
function recordZodImport(node) {
|
|
12559
12706
|
if (!isZodModule(node.source.value)) {
|
|
12560
12707
|
return;
|
|
12561
12708
|
}
|
|
12562
12709
|
for (const specifier of node.specifiers) {
|
|
12563
|
-
if (specifier.type ===
|
|
12710
|
+
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
12711
|
zodNamespaces.add(specifier.local.name);
|
|
12565
12712
|
}
|
|
12566
12713
|
}
|
|
@@ -12570,13 +12717,13 @@ var prefer_zod_infer_default = createRule({
|
|
|
12570
12717
|
let current = node;
|
|
12571
12718
|
let leaf = null;
|
|
12572
12719
|
let leafCall = null;
|
|
12573
|
-
while (current.type ===
|
|
12720
|
+
while (current.type === AST_NODE_TYPES49.CallExpression) {
|
|
12574
12721
|
const callee = current.callee;
|
|
12575
|
-
if (callee.type !==
|
|
12722
|
+
if (callee.type !== AST_NODE_TYPES49.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES49.Identifier) {
|
|
12576
12723
|
break;
|
|
12577
12724
|
}
|
|
12578
12725
|
const receiver = callee.object;
|
|
12579
|
-
if (receiver.type ===
|
|
12726
|
+
if (receiver.type === AST_NODE_TYPES49.Identifier && zodNamespaces.has(receiver.name)) {
|
|
12580
12727
|
leaf = callee.property.name;
|
|
12581
12728
|
leafCall = current;
|
|
12582
12729
|
break;
|
|
@@ -12607,20 +12754,20 @@ var prefer_zod_infer_default = createRule({
|
|
|
12607
12754
|
return domain instanceof Set && domain.size >= 2 ? domain : null;
|
|
12608
12755
|
}
|
|
12609
12756
|
function inferredSchemaName(node) {
|
|
12610
|
-
if (node.type !==
|
|
12757
|
+
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
12758
|
return null;
|
|
12612
12759
|
}
|
|
12613
12760
|
const arguments_ = node.typeArguments?.params ?? [];
|
|
12614
12761
|
const [argument] = arguments_;
|
|
12615
|
-
return arguments_.length === 1 && argument?.type ===
|
|
12762
|
+
return arguments_.length === 1 && argument?.type === AST_NODE_TYPES49.TSTypeQuery && argument.exprName.type === AST_NODE_TYPES49.Identifier ? argument.exprName.name : null;
|
|
12616
12763
|
}
|
|
12617
12764
|
function recordLiteralUnions(members, owner, ownerName, exported) {
|
|
12618
12765
|
for (const member of members) {
|
|
12619
|
-
if (member.type !==
|
|
12766
|
+
if (member.type !== AST_NODE_TYPES49.TSPropertySignature || member.computed || member.optional || member.readonly || member.typeAnnotation === void 0) {
|
|
12620
12767
|
continue;
|
|
12621
12768
|
}
|
|
12622
12769
|
const key = member.key;
|
|
12623
|
-
const propertyName3 = key.type ===
|
|
12770
|
+
const propertyName3 = key.type === AST_NODE_TYPES49.Identifier ? key.name : key.type === AST_NODE_TYPES49.Literal && typeof key.value === "string" ? key.value : null;
|
|
12624
12771
|
if (propertyName3 === null) {
|
|
12625
12772
|
continue;
|
|
12626
12773
|
}
|
|
@@ -12630,7 +12777,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
12630
12777
|
}
|
|
12631
12778
|
const annotation = member.typeAnnotation.typeAnnotation;
|
|
12632
12779
|
const domain = staticStringUnionDomain(annotation);
|
|
12633
|
-
if (domain === null || annotation.type !==
|
|
12780
|
+
if (domain === null || annotation.type !== AST_NODE_TYPES49.TSUnionType) {
|
|
12634
12781
|
continue;
|
|
12635
12782
|
}
|
|
12636
12783
|
literalUnionOccurrences.push({
|
|
@@ -12661,16 +12808,16 @@ var prefer_zod_infer_default = createRule({
|
|
|
12661
12808
|
return null;
|
|
12662
12809
|
}
|
|
12663
12810
|
const shape = base.arguments[0];
|
|
12664
|
-
if (shape === void 0 || shape.type !==
|
|
12811
|
+
if (shape === void 0 || shape.type !== AST_NODE_TYPES49.ObjectExpression) {
|
|
12665
12812
|
return null;
|
|
12666
12813
|
}
|
|
12667
12814
|
const fields = /* @__PURE__ */ new Map();
|
|
12668
12815
|
for (const property of shape.properties) {
|
|
12669
|
-
if (property.type !==
|
|
12816
|
+
if (property.type !== AST_NODE_TYPES49.Property || property.computed) {
|
|
12670
12817
|
return null;
|
|
12671
12818
|
}
|
|
12672
12819
|
const { key } = property;
|
|
12673
|
-
const name = key.type ===
|
|
12820
|
+
const name = key.type === AST_NODE_TYPES49.Identifier ? key.name : key.type === AST_NODE_TYPES49.Literal && typeof key.value === "string" ? key.value : null;
|
|
12674
12821
|
if (name === null) {
|
|
12675
12822
|
return null;
|
|
12676
12823
|
}
|
|
@@ -12681,11 +12828,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
12681
12828
|
function typeMembers(members) {
|
|
12682
12829
|
const result = /* @__PURE__ */ new Map();
|
|
12683
12830
|
for (const member of members) {
|
|
12684
|
-
if (member.type !==
|
|
12831
|
+
if (member.type !== AST_NODE_TYPES49.TSPropertySignature || member.computed) {
|
|
12685
12832
|
return null;
|
|
12686
12833
|
}
|
|
12687
12834
|
const { key } = member;
|
|
12688
|
-
const name = key.type ===
|
|
12835
|
+
const name = key.type === AST_NODE_TYPES49.Identifier ? key.name : key.type === AST_NODE_TYPES49.Literal && typeof key.value === "string" ? key.value : null;
|
|
12689
12836
|
if (name === null) {
|
|
12690
12837
|
return null;
|
|
12691
12838
|
}
|
|
@@ -12700,8 +12847,8 @@ var prefer_zod_infer_default = createRule({
|
|
|
12700
12847
|
return result.size === 0 ? null : result;
|
|
12701
12848
|
}
|
|
12702
12849
|
function collectConstrainedNames(node) {
|
|
12703
|
-
if (node.type ===
|
|
12704
|
-
if (node.typeName.type ===
|
|
12850
|
+
if (node.type === AST_NODE_TYPES49.TSTypeReference) {
|
|
12851
|
+
if (node.typeName.type === AST_NODE_TYPES49.Identifier) {
|
|
12705
12852
|
constrainedTypeNames.add(node.typeName.name);
|
|
12706
12853
|
}
|
|
12707
12854
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -12709,11 +12856,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
12709
12856
|
}
|
|
12710
12857
|
return;
|
|
12711
12858
|
}
|
|
12712
|
-
if (node.type ===
|
|
12859
|
+
if (node.type === AST_NODE_TYPES49.TSArrayType) {
|
|
12713
12860
|
collectConstrainedNames(node.elementType);
|
|
12714
12861
|
return;
|
|
12715
12862
|
}
|
|
12716
|
-
if (node.type ===
|
|
12863
|
+
if (node.type === AST_NODE_TYPES49.TSUnionType || node.type === AST_NODE_TYPES49.TSIntersectionType) {
|
|
12717
12864
|
for (const member of node.types) {
|
|
12718
12865
|
collectConstrainedNames(member);
|
|
12719
12866
|
}
|
|
@@ -12757,7 +12904,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
12757
12904
|
return {
|
|
12758
12905
|
Program(node) {
|
|
12759
12906
|
for (const statement of node.body) {
|
|
12760
|
-
if (statement.type ===
|
|
12907
|
+
if (statement.type === AST_NODE_TYPES49.ImportDeclaration) {
|
|
12761
12908
|
recordZodImport(statement);
|
|
12762
12909
|
}
|
|
12763
12910
|
}
|
|
@@ -12766,7 +12913,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
12766
12913
|
recordZodImport(node);
|
|
12767
12914
|
},
|
|
12768
12915
|
VariableDeclarator(node) {
|
|
12769
|
-
if (node.id.type !==
|
|
12916
|
+
if (node.id.type !== AST_NODE_TYPES49.Identifier || node.init == null) {
|
|
12770
12917
|
return;
|
|
12771
12918
|
}
|
|
12772
12919
|
const fields = schemaFields(node.init);
|
|
@@ -12783,14 +12930,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
12783
12930
|
},
|
|
12784
12931
|
/** Records `XSchema.transform(...)` and equivalent module-level reshaping. */
|
|
12785
12932
|
"MemberExpression[computed=false]"(node) {
|
|
12786
|
-
if (node.object.type ===
|
|
12933
|
+
if (node.object.type === AST_NODE_TYPES49.Identifier && node.property.type === AST_NODE_TYPES49.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
12787
12934
|
reshapedSchemaNames.add(node.object.name);
|
|
12788
12935
|
}
|
|
12789
12936
|
},
|
|
12790
12937
|
/** Records every type argument carried by a Zod constraint. */
|
|
12791
12938
|
TSTypeReference(node) {
|
|
12792
12939
|
const { typeName } = node;
|
|
12793
|
-
const referenced = typeName.type ===
|
|
12940
|
+
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
12941
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
12795
12942
|
return;
|
|
12796
12943
|
}
|
|
@@ -12822,7 +12969,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
12822
12969
|
typeName: node.id.name
|
|
12823
12970
|
});
|
|
12824
12971
|
}
|
|
12825
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
12972
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== AST_NODE_TYPES49.TSTypeLiteral) {
|
|
12826
12973
|
return;
|
|
12827
12974
|
}
|
|
12828
12975
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -12922,10 +13069,10 @@ var prefer_zod_infer_default = createRule({
|
|
|
12922
13069
|
|
|
12923
13070
|
// src/rules/require-assert-never.ts
|
|
12924
13071
|
import {
|
|
12925
|
-
ESLintUtils as
|
|
12926
|
-
AST_NODE_TYPES as
|
|
13072
|
+
ESLintUtils as ESLintUtils4,
|
|
13073
|
+
AST_NODE_TYPES as AST_NODE_TYPES50
|
|
12927
13074
|
} from "@typescript-eslint/utils";
|
|
12928
|
-
import
|
|
13075
|
+
import ts3 from "typescript";
|
|
12929
13076
|
var requireAssertNeverDocumentation = {
|
|
12930
13077
|
summary: "Require an empty switch default to call `assertNever` so discriminated unions remain exhaustive at compile time.",
|
|
12931
13078
|
rationale: "An empty default silently accepts new union members instead of making the compiler identify the missing case.",
|
|
@@ -12937,14 +13084,14 @@ var requireAssertNeverDocumentation = {
|
|
|
12937
13084
|
]
|
|
12938
13085
|
};
|
|
12939
13086
|
var isRuntimeHandlingStatement = (statement) => {
|
|
12940
|
-
if (statement.type ===
|
|
12941
|
-
if (statement.type ===
|
|
13087
|
+
if (statement.type === AST_NODE_TYPES50.EmptyStatement) return false;
|
|
13088
|
+
if (statement.type === AST_NODE_TYPES50.BreakStatement) {
|
|
12942
13089
|
return statement.label !== null;
|
|
12943
13090
|
}
|
|
12944
|
-
if (statement.type ===
|
|
13091
|
+
if (statement.type === AST_NODE_TYPES50.TSTypeAliasDeclaration || statement.type === AST_NODE_TYPES50.TSInterfaceDeclaration) {
|
|
12945
13092
|
return false;
|
|
12946
13093
|
}
|
|
12947
|
-
if (statement.type ===
|
|
13094
|
+
if (statement.type === AST_NODE_TYPES50.BlockStatement) {
|
|
12948
13095
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
12949
13096
|
}
|
|
12950
13097
|
return true;
|
|
@@ -12960,7 +13107,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
12960
13107
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
12961
13108
|
}
|
|
12962
13109
|
const only = defaultCase.consequent[0];
|
|
12963
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
13110
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === AST_NODE_TYPES50.BlockStatement && !only.body.some(isRuntimeHandlingStatement)) {
|
|
12964
13111
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
12965
13112
|
}
|
|
12966
13113
|
return false;
|
|
@@ -12972,7 +13119,7 @@ function isExhaustiveFiniteSwitch(node, services) {
|
|
|
12972
13119
|
const constituents = discriminantType.isUnion() ? discriminantType.types : [discriminantType];
|
|
12973
13120
|
if (!discriminantType.isUnion() || constituents.length < 2) return false;
|
|
12974
13121
|
if (constituents.every(
|
|
12975
|
-
(constituent) => (constituent.flags &
|
|
13122
|
+
(constituent) => (constituent.flags & ts3.TypeFlags.BooleanLiteral) !== 0
|
|
12976
13123
|
)) {
|
|
12977
13124
|
return false;
|
|
12978
13125
|
}
|
|
@@ -12996,7 +13143,7 @@ function isExhaustiveFiniteSwitch(node, services) {
|
|
|
12996
13143
|
return [...expected].every((key) => handled.has(key));
|
|
12997
13144
|
}
|
|
12998
13145
|
function finiteTypeKey(type, checker) {
|
|
12999
|
-
const finiteFlags =
|
|
13146
|
+
const finiteFlags = ts3.TypeFlags.StringLiteral | ts3.TypeFlags.NumberLiteral | ts3.TypeFlags.BooleanLiteral | ts3.TypeFlags.EnumLiteral | ts3.TypeFlags.UniqueESSymbol | ts3.TypeFlags.Null | ts3.TypeFlags.Undefined;
|
|
13000
13147
|
return (type.flags & finiteFlags) !== 0 ? checker.typeToString(type) : null;
|
|
13001
13148
|
}
|
|
13002
13149
|
var require_assert_never_default = createRule({
|
|
@@ -13016,7 +13163,7 @@ var require_assert_never_default = createRule({
|
|
|
13016
13163
|
create(context) {
|
|
13017
13164
|
let services;
|
|
13018
13165
|
try {
|
|
13019
|
-
services =
|
|
13166
|
+
services = ESLintUtils4.getParserServices(context);
|
|
13020
13167
|
} catch {
|
|
13021
13168
|
services = null;
|
|
13022
13169
|
}
|
|
@@ -13043,7 +13190,7 @@ var require_assert_never_default = createRule({
|
|
|
13043
13190
|
});
|
|
13044
13191
|
|
|
13045
13192
|
// src/rules/require-fetch-timeout.ts
|
|
13046
|
-
import { AST_NODE_TYPES as
|
|
13193
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES51, ASTUtils as ASTUtils13 } from "@typescript-eslint/utils";
|
|
13047
13194
|
var requireFetchTimeoutDocumentation = {
|
|
13048
13195
|
summary: "Require an abort `signal` (e.g. `AbortSignal.timeout(ms)`) on global `fetch()` calls so stalled upstreams cannot hang the caller forever.",
|
|
13049
13196
|
rationale: "An unbounded request can occupy work indefinitely when an upstream stalls.",
|
|
@@ -13069,14 +13216,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
13069
13216
|
return false;
|
|
13070
13217
|
}
|
|
13071
13218
|
function initProvablyLacksSignal(init) {
|
|
13072
|
-
if (init.type !==
|
|
13219
|
+
if (init.type !== AST_NODE_TYPES51.ObjectExpression) {
|
|
13073
13220
|
return false;
|
|
13074
13221
|
}
|
|
13075
13222
|
for (const prop of init.properties) {
|
|
13076
|
-
if (prop.type ===
|
|
13223
|
+
if (prop.type === AST_NODE_TYPES51.SpreadElement) {
|
|
13077
13224
|
return false;
|
|
13078
13225
|
}
|
|
13079
|
-
if (prop.key.type ===
|
|
13226
|
+
if (prop.key.type === AST_NODE_TYPES51.Identifier && prop.key.name === "signal" || prop.key.type === AST_NODE_TYPES51.Literal && prop.key.value === "signal") {
|
|
13080
13227
|
return false;
|
|
13081
13228
|
}
|
|
13082
13229
|
if (prop.computed) {
|
|
@@ -13086,7 +13233,7 @@ function initProvablyLacksSignal(init) {
|
|
|
13086
13233
|
return true;
|
|
13087
13234
|
}
|
|
13088
13235
|
function isInlineUrl(node, resolvesToGlobal) {
|
|
13089
|
-
return node.type ===
|
|
13236
|
+
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
13237
|
}
|
|
13091
13238
|
var require_fetch_timeout_default = createRule({
|
|
13092
13239
|
name: "require-fetch-timeout",
|
|
@@ -13128,10 +13275,10 @@ var require_fetch_timeout_default = createRule({
|
|
|
13128
13275
|
return variable === null || variable.defs.length === 0;
|
|
13129
13276
|
}
|
|
13130
13277
|
function isGlobalFetchCall2(callee) {
|
|
13131
|
-
if (callee.type ===
|
|
13278
|
+
if (callee.type === AST_NODE_TYPES51.Identifier) {
|
|
13132
13279
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
13133
13280
|
}
|
|
13134
|
-
return callee.type ===
|
|
13281
|
+
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
13282
|
}
|
|
13136
13283
|
function localConstInitProvablyLacksSignal(identifier) {
|
|
13137
13284
|
const variable = ASTUtils13.findVariable(
|
|
@@ -13140,14 +13287,14 @@ var require_fetch_timeout_default = createRule({
|
|
|
13140
13287
|
);
|
|
13141
13288
|
if (variable?.defs.length !== 1) return false;
|
|
13142
13289
|
const definition = variable.defs[0];
|
|
13143
|
-
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !==
|
|
13290
|
+
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !== AST_NODE_TYPES51.ObjectExpression || !initProvablyLacksSignal(definition.node.init)) {
|
|
13144
13291
|
return false;
|
|
13145
13292
|
}
|
|
13146
13293
|
for (const reference of variable.references) {
|
|
13147
13294
|
const ref = reference.identifier;
|
|
13148
13295
|
if (ref === identifier || ref === definition.name) continue;
|
|
13149
13296
|
const member = ref.parent;
|
|
13150
|
-
if (member.type !==
|
|
13297
|
+
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
13298
|
return false;
|
|
13152
13299
|
}
|
|
13153
13300
|
}
|
|
@@ -13162,7 +13309,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
13162
13309
|
if (node.arguments.length === 1 && first !== void 0 && !isInlineUrl(first, resolvesToGlobal)) {
|
|
13163
13310
|
return;
|
|
13164
13311
|
}
|
|
13165
|
-
if (init === void 0 || initProvablyLacksSignal(init) || init.type ===
|
|
13312
|
+
if (init === void 0 || initProvablyLacksSignal(init) || init.type === AST_NODE_TYPES51.Identifier && localConstInitProvablyLacksSignal(init)) {
|
|
13166
13313
|
context.report({ node, messageId: "missingSignal" });
|
|
13167
13314
|
}
|
|
13168
13315
|
}
|
|
@@ -13171,7 +13318,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
13171
13318
|
});
|
|
13172
13319
|
|
|
13173
13320
|
// src/rules/require-port-for-service.ts
|
|
13174
|
-
import { AST_NODE_TYPES as
|
|
13321
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES52 } from "@typescript-eslint/utils";
|
|
13175
13322
|
var requirePortForServiceDocumentation = {
|
|
13176
13323
|
summary: "Advise when an exported service with injected collaborators has public methods not covered by its declared ports.",
|
|
13177
13324
|
rationale: "A declared port keeps consumers coupled to the service capability instead of its concrete implementation.",
|
|
@@ -13196,45 +13343,45 @@ var ROUTER_FACTORY_NAME = "Router";
|
|
|
13196
13343
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
13197
13344
|
var STORAGE_ASSIGNMENT_OPERATORS = /* @__PURE__ */ new Set(["=", "&&=", "??=", "||="]);
|
|
13198
13345
|
var staticMemberName4 = (member) => {
|
|
13199
|
-
if (member.property.type ===
|
|
13200
|
-
if (!member.computed && member.property.type ===
|
|
13201
|
-
return member.computed && member.property.type ===
|
|
13346
|
+
if (member.property.type === AST_NODE_TYPES52.PrivateIdentifier) return `#${member.property.name}`;
|
|
13347
|
+
if (!member.computed && member.property.type === AST_NODE_TYPES52.Identifier) return member.property.name;
|
|
13348
|
+
return member.computed && member.property.type === AST_NODE_TYPES52.Literal && typeof member.property.value === "string" ? member.property.value : null;
|
|
13202
13349
|
};
|
|
13203
13350
|
var detachedValueExports = (program) => {
|
|
13204
13351
|
const names = /* @__PURE__ */ new Set();
|
|
13205
13352
|
for (const statement of program.body) {
|
|
13206
|
-
if (statement.type ===
|
|
13353
|
+
if (statement.type === AST_NODE_TYPES52.ExportNamedDeclaration && statement.declaration === null && statement.source === null && statement.exportKind !== "type") {
|
|
13207
13354
|
for (const specifier of statement.specifiers) {
|
|
13208
13355
|
if (specifier.exportKind !== "type") names.add(specifier.local.name);
|
|
13209
13356
|
}
|
|
13210
|
-
} else if (statement.type ===
|
|
13357
|
+
} else if (statement.type === AST_NODE_TYPES52.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES52.Identifier) {
|
|
13211
13358
|
names.add(statement.declaration.name);
|
|
13212
|
-
} else if (statement.type ===
|
|
13359
|
+
} else if (statement.type === AST_NODE_TYPES52.TSExportAssignment && statement.expression.type === AST_NODE_TYPES52.Identifier) {
|
|
13213
13360
|
names.add(statement.expression.name);
|
|
13214
13361
|
}
|
|
13215
13362
|
}
|
|
13216
13363
|
return names;
|
|
13217
13364
|
};
|
|
13218
|
-
var isExportedClass2 = (node, detached) => node.parent.type ===
|
|
13365
|
+
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
13366
|
var readTypeReference = (annotation) => {
|
|
13220
|
-
if (annotation?.type ===
|
|
13367
|
+
if (annotation?.type === AST_NODE_TYPES52.TSUnionType) {
|
|
13221
13368
|
const members = annotation.types.filter(
|
|
13222
|
-
(member) => member.type !==
|
|
13369
|
+
(member) => member.type !== AST_NODE_TYPES52.TSUndefinedKeyword && member.type !== AST_NODE_TYPES52.TSNullKeyword
|
|
13223
13370
|
);
|
|
13224
13371
|
annotation = members.length === 1 ? members[0] : void 0;
|
|
13225
13372
|
}
|
|
13226
|
-
if (annotation === void 0 || annotation.type !==
|
|
13373
|
+
if (annotation === void 0 || annotation.type !== AST_NODE_TYPES52.TSTypeReference) return null;
|
|
13227
13374
|
const { typeName } = annotation;
|
|
13228
|
-
const rightmost = typeName.type ===
|
|
13375
|
+
const rightmost = typeName.type === AST_NODE_TYPES52.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES52.TSQualifiedName ? typeName.right.name : null;
|
|
13229
13376
|
if (rightmost === null) return null;
|
|
13230
13377
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
13231
13378
|
};
|
|
13232
|
-
var qualifiedName = (name) => name.type ===
|
|
13379
|
+
var qualifiedName = (name) => name.type === AST_NODE_TYPES52.Identifier ? name.name : name.type === AST_NODE_TYPES52.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
13233
13380
|
var propertySignatureTypes = (members) => {
|
|
13234
13381
|
const types = /* @__PURE__ */ new Map();
|
|
13235
13382
|
for (const member of members) {
|
|
13236
|
-
if (member.type !==
|
|
13237
|
-
if (member.computed || member.key.type !==
|
|
13383
|
+
if (member.type !== AST_NODE_TYPES52.TSPropertySignature) continue;
|
|
13384
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES52.Identifier) continue;
|
|
13238
13385
|
const reference = readTypeReference(member.typeAnnotation?.typeAnnotation);
|
|
13239
13386
|
if (reference === null) continue;
|
|
13240
13387
|
types.set(member.key.name, reference);
|
|
@@ -13245,18 +13392,18 @@ var fileTypeIndex = (program) => {
|
|
|
13245
13392
|
const objects = /* @__PURE__ */ new Map();
|
|
13246
13393
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
13247
13394
|
for (const statement of program.body) {
|
|
13248
|
-
const declaration = statement.type ===
|
|
13249
|
-
if (declaration?.type ===
|
|
13395
|
+
const declaration = statement.type === AST_NODE_TYPES52.ExportNamedDeclaration ? statement.declaration : statement;
|
|
13396
|
+
if (declaration?.type === AST_NODE_TYPES52.TSInterfaceDeclaration) {
|
|
13250
13397
|
objects.set(declaration.id.name, propertySignatureTypes(declaration.body.body));
|
|
13251
13398
|
continue;
|
|
13252
13399
|
}
|
|
13253
|
-
if (declaration?.type !==
|
|
13400
|
+
if (declaration?.type !== AST_NODE_TYPES52.TSTypeAliasDeclaration) continue;
|
|
13254
13401
|
const aliased = declaration.typeAnnotation;
|
|
13255
|
-
if (aliased.type ===
|
|
13402
|
+
if (aliased.type === AST_NODE_TYPES52.TSFunctionType || aliased.type === AST_NODE_TYPES52.TSConstructorType) {
|
|
13256
13403
|
functionAliases.add(declaration.id.name);
|
|
13257
13404
|
continue;
|
|
13258
13405
|
}
|
|
13259
|
-
const literals = aliased.type ===
|
|
13406
|
+
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
13407
|
if (literals.length === 0) continue;
|
|
13261
13408
|
const merged = /* @__PURE__ */ new Map();
|
|
13262
13409
|
for (const literal of literals) {
|
|
@@ -13284,10 +13431,10 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
13284
13431
|
while (pending.length > 0) {
|
|
13285
13432
|
const current = pending.pop();
|
|
13286
13433
|
if (current === void 0) break;
|
|
13287
|
-
if (current.type ===
|
|
13288
|
-
const expression = current.type ===
|
|
13289
|
-
const storedField = expression?.type ===
|
|
13290
|
-
if (expression?.type !==
|
|
13434
|
+
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;
|
|
13435
|
+
const expression = current.type === AST_NODE_TYPES52.ExpressionStatement ? current.expression : null;
|
|
13436
|
+
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;
|
|
13437
|
+
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
13438
|
for (const key of Object.keys(current)) {
|
|
13292
13439
|
if (key === "parent") continue;
|
|
13293
13440
|
const value = current[key];
|
|
@@ -13300,14 +13447,14 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
13300
13447
|
continue;
|
|
13301
13448
|
}
|
|
13302
13449
|
let source = expression.right;
|
|
13303
|
-
while (source.type ===
|
|
13304
|
-
if (source.type ===
|
|
13450
|
+
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;
|
|
13451
|
+
if (source.type === AST_NODE_TYPES52.NewExpression) {
|
|
13305
13452
|
constructedFields += 1;
|
|
13306
|
-
} else if (source.type ===
|
|
13453
|
+
} else if (source.type === AST_NODE_TYPES52.Identifier) {
|
|
13307
13454
|
const fields = storedFieldsFrom.get(source.name) ?? /* @__PURE__ */ new Set();
|
|
13308
13455
|
fields.add(storedField);
|
|
13309
13456
|
storedFieldsFrom.set(source.name, fields);
|
|
13310
|
-
} else if (source.type ===
|
|
13457
|
+
} else if (source.type === AST_NODE_TYPES52.MemberExpression && source.object.type === AST_NODE_TYPES52.Identifier) {
|
|
13311
13458
|
const fields = storedFieldsFrom.get(source.object.name) ?? /* @__PURE__ */ new Set();
|
|
13312
13459
|
fields.add(storedField);
|
|
13313
13460
|
storedFieldsFrom.set(source.object.name, fields);
|
|
@@ -13317,7 +13464,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
13317
13464
|
const collaborators = [];
|
|
13318
13465
|
for (const parameter of ctor.value.params) {
|
|
13319
13466
|
for (const reference of parameterCollaborators(parameter, declared)) {
|
|
13320
|
-
const fields = parameter.type ===
|
|
13467
|
+
const fields = parameter.type === AST_NODE_TYPES52.TSParameterProperty ? [reference.name] : [...storedFieldsFrom.get(reference.name) ?? []];
|
|
13321
13468
|
if (fields.length === 0) continue;
|
|
13322
13469
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
13323
13470
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -13332,8 +13479,8 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
13332
13479
|
};
|
|
13333
13480
|
var parameterCollaborators = (parameter, declared) => {
|
|
13334
13481
|
let target = parameter;
|
|
13335
|
-
if (target.type ===
|
|
13336
|
-
if (target.type ===
|
|
13482
|
+
if (target.type === AST_NODE_TYPES52.AssignmentPattern) target = target.left;
|
|
13483
|
+
if (target.type === AST_NODE_TYPES52.ObjectPattern) {
|
|
13337
13484
|
return objectPatternCollaborators(target, declared);
|
|
13338
13485
|
}
|
|
13339
13486
|
const named2 = namedParameterCollaborator(parameter);
|
|
@@ -13341,9 +13488,9 @@ var parameterCollaborators = (parameter, declared) => {
|
|
|
13341
13488
|
};
|
|
13342
13489
|
var namedParameterCollaborator = (annotated) => {
|
|
13343
13490
|
let target = annotated;
|
|
13344
|
-
if (target.type ===
|
|
13345
|
-
if (target.type ===
|
|
13346
|
-
if (target.type !==
|
|
13491
|
+
if (target.type === AST_NODE_TYPES52.TSParameterProperty) target = target.parameter;
|
|
13492
|
+
if (target.type === AST_NODE_TYPES52.AssignmentPattern) target = target.left;
|
|
13493
|
+
if (target.type !== AST_NODE_TYPES52.Identifier) return null;
|
|
13347
13494
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
13348
13495
|
if (reference === null) return null;
|
|
13349
13496
|
return { name: target.name, ...reference, fields: [] };
|
|
@@ -13355,11 +13502,11 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
13355
13502
|
if (members === null) return [];
|
|
13356
13503
|
const collaborators = [];
|
|
13357
13504
|
for (const property of pattern.properties) {
|
|
13358
|
-
if (property.type !==
|
|
13359
|
-
if (property.key.type !==
|
|
13505
|
+
if (property.type !== AST_NODE_TYPES52.Property || property.computed) continue;
|
|
13506
|
+
if (property.key.type !== AST_NODE_TYPES52.Identifier) continue;
|
|
13360
13507
|
const key = property.key.name;
|
|
13361
|
-
const bound = property.value.type ===
|
|
13362
|
-
if (bound.type !==
|
|
13508
|
+
const bound = property.value.type === AST_NODE_TYPES52.AssignmentPattern ? property.value.left : property.value;
|
|
13509
|
+
if (bound.type !== AST_NODE_TYPES52.Identifier) continue;
|
|
13363
13510
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
13364
13511
|
const reference = members.get(key);
|
|
13365
13512
|
if (reference === void 0) continue;
|
|
@@ -13368,21 +13515,21 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
13368
13515
|
return collaborators;
|
|
13369
13516
|
};
|
|
13370
13517
|
var bagMemberTypes = (annotation, declared) => {
|
|
13371
|
-
if (annotation.type ===
|
|
13518
|
+
if (annotation.type === AST_NODE_TYPES52.TSTypeLiteral) {
|
|
13372
13519
|
return propertySignatureTypes(annotation.members);
|
|
13373
13520
|
}
|
|
13374
|
-
if (annotation.type !==
|
|
13521
|
+
if (annotation.type !== AST_NODE_TYPES52.TSTypeReference || annotation.typeName.type !== AST_NODE_TYPES52.Identifier) {
|
|
13375
13522
|
return null;
|
|
13376
13523
|
}
|
|
13377
13524
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
13378
13525
|
};
|
|
13379
13526
|
var isFrameworkWiring = (body2) => subtreeHas(body2, (node) => {
|
|
13380
|
-
if (node.type ===
|
|
13527
|
+
if (node.type === AST_NODE_TYPES52.CallExpression) {
|
|
13381
13528
|
const { callee } = node;
|
|
13382
|
-
if (callee.type ===
|
|
13383
|
-
return callee.type ===
|
|
13529
|
+
if (callee.type === AST_NODE_TYPES52.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
13530
|
+
return callee.type === AST_NODE_TYPES52.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES52.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
13384
13531
|
}
|
|
13385
|
-
return node.type ===
|
|
13532
|
+
return node.type === AST_NODE_TYPES52.TSTypeReference && node.typeName.type === AST_NODE_TYPES52.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
13386
13533
|
});
|
|
13387
13534
|
var subtreeHas = (root, found) => {
|
|
13388
13535
|
let hit = false;
|
|
@@ -13409,19 +13556,19 @@ var invokedInstanceField = (call) => {
|
|
|
13409
13556
|
const direct = instanceField(call.callee);
|
|
13410
13557
|
if (direct !== null) return direct;
|
|
13411
13558
|
let callee = call.callee;
|
|
13412
|
-
while (callee.type ===
|
|
13413
|
-
return callee.type ===
|
|
13559
|
+
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;
|
|
13560
|
+
return callee.type === AST_NODE_TYPES52.MemberExpression ? instanceField(callee.object) : null;
|
|
13414
13561
|
};
|
|
13415
13562
|
var instanceField = (candidate) => {
|
|
13416
13563
|
let node = candidate;
|
|
13417
|
-
while (node.type ===
|
|
13418
|
-
return node.type ===
|
|
13564
|
+
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;
|
|
13565
|
+
return node.type === AST_NODE_TYPES52.MemberExpression && node.object.type === AST_NODE_TYPES52.ThisExpression ? staticMemberName4(node) : null;
|
|
13419
13566
|
};
|
|
13420
13567
|
var behaviorallyInvokedFields = (body2) => {
|
|
13421
13568
|
const invoked = /* @__PURE__ */ new Set();
|
|
13422
13569
|
const visit = (current) => {
|
|
13423
|
-
if (current.type ===
|
|
13424
|
-
if (current.type ===
|
|
13570
|
+
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;
|
|
13571
|
+
if (current.type === AST_NODE_TYPES52.CallExpression) {
|
|
13425
13572
|
const field = invokedInstanceField(current);
|
|
13426
13573
|
if (field !== null) invoked.add(field);
|
|
13427
13574
|
}
|
|
@@ -13434,14 +13581,14 @@ var behaviorallyInvokedFields = (body2) => {
|
|
|
13434
13581
|
}
|
|
13435
13582
|
};
|
|
13436
13583
|
for (const member of body2.body) {
|
|
13437
|
-
if (member.type ===
|
|
13438
|
-
if (member.type ===
|
|
13584
|
+
if (member.type === AST_NODE_TYPES52.StaticBlock || member.static) continue;
|
|
13585
|
+
if (member.type === AST_NODE_TYPES52.MethodDefinition) {
|
|
13439
13586
|
if (member.value.body !== null && member.value.body !== void 0) visit(member.value.body);
|
|
13440
13587
|
continue;
|
|
13441
13588
|
}
|
|
13442
|
-
if (member.type !==
|
|
13589
|
+
if (member.type !== AST_NODE_TYPES52.PropertyDefinition || member.value === null) continue;
|
|
13443
13590
|
visit(
|
|
13444
|
-
member.value.type ===
|
|
13591
|
+
member.value.type === AST_NODE_TYPES52.ArrowFunctionExpression ? member.value.body : member.value
|
|
13445
13592
|
);
|
|
13446
13593
|
}
|
|
13447
13594
|
return invoked;
|
|
@@ -13461,25 +13608,25 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
13461
13608
|
var fileInterfaceNames = (program) => {
|
|
13462
13609
|
const names = [];
|
|
13463
13610
|
for (const statement of program.body) {
|
|
13464
|
-
const declaration = statement.type ===
|
|
13465
|
-
if (declaration?.type ===
|
|
13611
|
+
const declaration = statement.type === AST_NODE_TYPES52.ExportNamedDeclaration ? statement.declaration : statement;
|
|
13612
|
+
if (declaration?.type === AST_NODE_TYPES52.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
13466
13613
|
}
|
|
13467
13614
|
return names;
|
|
13468
13615
|
};
|
|
13469
13616
|
var publicMethodNames = (body2, functionAliases) => {
|
|
13470
13617
|
const names = [];
|
|
13471
13618
|
for (const member of body2.body) {
|
|
13472
|
-
if (member.type ===
|
|
13619
|
+
if (member.type === AST_NODE_TYPES52.PropertyDefinition) {
|
|
13473
13620
|
if (member.static || member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
13474
|
-
if (member.value?.type !==
|
|
13475
|
-
names.push(member.key.type ===
|
|
13621
|
+
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;
|
|
13622
|
+
names.push(member.key.type === AST_NODE_TYPES52.Identifier ? member.key.name : "\u2026");
|
|
13476
13623
|
continue;
|
|
13477
13624
|
}
|
|
13478
|
-
if (member.type !==
|
|
13625
|
+
if (member.type !== AST_NODE_TYPES52.MethodDefinition) continue;
|
|
13479
13626
|
if (member.kind !== "method" || member.static) continue;
|
|
13480
13627
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
13481
|
-
if (member.key.type ===
|
|
13482
|
-
if (member.key.type ===
|
|
13628
|
+
if (member.key.type === AST_NODE_TYPES52.PrivateIdentifier) continue;
|
|
13629
|
+
if (member.key.type === AST_NODE_TYPES52.Identifier) names.push(member.key.name);
|
|
13483
13630
|
else names.push("\u2026");
|
|
13484
13631
|
}
|
|
13485
13632
|
return names;
|
|
@@ -13487,13 +13634,13 @@ var publicMethodNames = (body2, functionAliases) => {
|
|
|
13487
13634
|
var isFluentConstructionObject = (node, getText) => {
|
|
13488
13635
|
if (node.id === null) return false;
|
|
13489
13636
|
const methods = node.body.body.filter(
|
|
13490
|
-
(member) => member.type ===
|
|
13637
|
+
(member) => member.type === AST_NODE_TYPES52.MethodDefinition && member.kind === "method" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.value.body !== null
|
|
13491
13638
|
);
|
|
13492
13639
|
if (methods.length === 0) return false;
|
|
13493
13640
|
return methods.every((member) => {
|
|
13494
13641
|
const result = member.value.returnType?.typeAnnotation;
|
|
13495
13642
|
if (result === void 0) return false;
|
|
13496
|
-
const returnsOwnType = result.type ===
|
|
13643
|
+
const returnsOwnType = result.type === AST_NODE_TYPES52.TSTypeReference && result.typeName.type === AST_NODE_TYPES52.Identifier && result.typeName.name === node.id?.name;
|
|
13497
13644
|
return returnsOwnType || FLUENT_BUILDER_NAME_RE.test(node.id?.name ?? "") && FLUENT_RESULT_TYPE_RE.test(getText(result));
|
|
13498
13645
|
});
|
|
13499
13646
|
};
|
|
@@ -13501,10 +13648,10 @@ function localClassAbstractness(program) {
|
|
|
13501
13648
|
const classes = /* @__PURE__ */ new Map();
|
|
13502
13649
|
const parents = /* @__PURE__ */ new Map();
|
|
13503
13650
|
for (const statement of program.body) {
|
|
13504
|
-
const declaration = statement.type ===
|
|
13505
|
-
if (declaration?.type ===
|
|
13651
|
+
const declaration = statement.type === AST_NODE_TYPES52.ExportNamedDeclaration || statement.type === AST_NODE_TYPES52.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
13652
|
+
if (declaration?.type === AST_NODE_TYPES52.ClassDeclaration && declaration.id !== null) {
|
|
13506
13653
|
classes.set(declaration.id.name, declaration.abstract === true);
|
|
13507
|
-
if (declaration.superClass?.type ===
|
|
13654
|
+
if (declaration.superClass?.type === AST_NODE_TYPES52.Identifier) {
|
|
13508
13655
|
parents.set(declaration.id.name, declaration.superClass.name);
|
|
13509
13656
|
}
|
|
13510
13657
|
}
|
|
@@ -13526,43 +13673,43 @@ function localInterfaceSurfaces(program) {
|
|
|
13526
13673
|
const parents = /* @__PURE__ */ new Map();
|
|
13527
13674
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
13528
13675
|
for (const statement of program.body) {
|
|
13529
|
-
const declaration = statement.type ===
|
|
13530
|
-
if (declaration?.type ===
|
|
13676
|
+
const declaration = statement.type === AST_NODE_TYPES52.ExportNamedDeclaration ? statement.declaration : statement;
|
|
13677
|
+
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
13678
|
}
|
|
13532
13679
|
for (const statement of program.body) {
|
|
13533
|
-
const declaration = statement.type ===
|
|
13534
|
-
if (declaration?.type ===
|
|
13680
|
+
const declaration = statement.type === AST_NODE_TYPES52.ExportNamedDeclaration ? statement.declaration : statement;
|
|
13681
|
+
if (declaration?.type === AST_NODE_TYPES52.TSTypeAliasDeclaration) {
|
|
13535
13682
|
const callables2 = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
13536
|
-
const parts = declaration.typeAnnotation.type ===
|
|
13683
|
+
const parts = declaration.typeAnnotation.type === AST_NODE_TYPES52.TSIntersectionType ? declaration.typeAnnotation.types : [declaration.typeAnnotation];
|
|
13537
13684
|
const inherited = parents.get(declaration.id.name) ?? [];
|
|
13538
13685
|
for (const part of parts) {
|
|
13539
|
-
if (part.type ===
|
|
13686
|
+
if (part.type === AST_NODE_TYPES52.TSTypeReference && part.typeName.type === AST_NODE_TYPES52.Identifier) {
|
|
13540
13687
|
inherited.push(part.typeName.name);
|
|
13541
13688
|
continue;
|
|
13542
13689
|
}
|
|
13543
|
-
if (part.type !==
|
|
13690
|
+
if (part.type !== AST_NODE_TYPES52.TSTypeLiteral) continue;
|
|
13544
13691
|
for (const member of part.members) {
|
|
13545
|
-
if (member.type !==
|
|
13546
|
-
if (member.computed || member.key.type !==
|
|
13547
|
-
if (member.type ===
|
|
13692
|
+
if (member.type !== AST_NODE_TYPES52.TSMethodSignature && member.type !== AST_NODE_TYPES52.TSPropertySignature) continue;
|
|
13693
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES52.Identifier) continue;
|
|
13694
|
+
if (member.type === AST_NODE_TYPES52.TSMethodSignature) {
|
|
13548
13695
|
callables2.add(member.key.name);
|
|
13549
13696
|
continue;
|
|
13550
13697
|
}
|
|
13551
|
-
if (member.type !==
|
|
13698
|
+
if (member.type !== AST_NODE_TYPES52.TSPropertySignature) continue;
|
|
13552
13699
|
const annotation = member.typeAnnotation?.typeAnnotation;
|
|
13553
|
-
if (annotation?.type ===
|
|
13700
|
+
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
13701
|
}
|
|
13555
13702
|
}
|
|
13556
13703
|
interfaces.set(declaration.id.name, callables2);
|
|
13557
13704
|
parents.set(declaration.id.name, inherited);
|
|
13558
13705
|
continue;
|
|
13559
13706
|
}
|
|
13560
|
-
if (declaration?.type !==
|
|
13707
|
+
if (declaration?.type !== AST_NODE_TYPES52.TSInterfaceDeclaration) continue;
|
|
13561
13708
|
const callables = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
13562
13709
|
for (const member of declaration.body.body) {
|
|
13563
|
-
if (member.type !==
|
|
13564
|
-
if (member.computed || member.key.type !==
|
|
13565
|
-
if (member.type ===
|
|
13710
|
+
if (member.type !== AST_NODE_TYPES52.TSMethodSignature && member.type !== AST_NODE_TYPES52.TSPropertySignature) continue;
|
|
13711
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES52.Identifier) continue;
|
|
13712
|
+
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
13713
|
}
|
|
13567
13714
|
interfaces.set(declaration.id.name, callables);
|
|
13568
13715
|
parents.set(
|
|
@@ -13570,7 +13717,7 @@ function localInterfaceSurfaces(program) {
|
|
|
13570
13717
|
[
|
|
13571
13718
|
...parents.get(declaration.id.name) ?? [],
|
|
13572
13719
|
...declaration.extends.flatMap(
|
|
13573
|
-
(heritage) => heritage.expression.type ===
|
|
13720
|
+
(heritage) => heritage.expression.type === AST_NODE_TYPES52.Identifier ? [heritage.expression.name] : ["*"]
|
|
13574
13721
|
)
|
|
13575
13722
|
]
|
|
13576
13723
|
);
|
|
@@ -13597,7 +13744,7 @@ function localInterfaceSurfaces(program) {
|
|
|
13597
13744
|
}
|
|
13598
13745
|
function hasServicePort(node, methods, classes, interfaces) {
|
|
13599
13746
|
if (node.superClass !== null) {
|
|
13600
|
-
if (node.superClass.type !==
|
|
13747
|
+
if (node.superClass.type !== AST_NODE_TYPES52.Identifier) return true;
|
|
13601
13748
|
const localAbstract = classes.get(node.superClass.name);
|
|
13602
13749
|
if (localAbstract === void 0 || localAbstract) return true;
|
|
13603
13750
|
}
|
|
@@ -13609,7 +13756,7 @@ function hasServicePort(node, methods, classes, interfaces) {
|
|
|
13609
13756
|
if (node.implements.length === 0) return false;
|
|
13610
13757
|
const combined = /* @__PURE__ */ new Set();
|
|
13611
13758
|
for (const implementation of node.implements) {
|
|
13612
|
-
if (implementation.expression.type !==
|
|
13759
|
+
if (implementation.expression.type !== AST_NODE_TYPES52.Identifier) return true;
|
|
13613
13760
|
const name = implementation.expression.name;
|
|
13614
13761
|
const localAbstract = classes.get(name);
|
|
13615
13762
|
if (localAbstract === true) return true;
|
|
@@ -13652,7 +13799,7 @@ var require_port_for_service_default = createRule({
|
|
|
13652
13799
|
if (node.abstract === true) return;
|
|
13653
13800
|
if (node.decorators.length > 0) return;
|
|
13654
13801
|
const ctor = node.body.body.find(
|
|
13655
|
-
(member) => member.type ===
|
|
13802
|
+
(member) => member.type === AST_NODE_TYPES52.MethodDefinition && member.kind === "constructor" && member.value.body !== null && member.value.body !== void 0
|
|
13656
13803
|
);
|
|
13657
13804
|
if (ctor === void 0) return;
|
|
13658
13805
|
const constructorFacts = readConstructor(
|
|
@@ -13687,7 +13834,7 @@ var require_port_for_service_default = createRule({
|
|
|
13687
13834
|
});
|
|
13688
13835
|
|
|
13689
13836
|
// src/rules/require-static-next-matcher.ts
|
|
13690
|
-
import { AST_NODE_TYPES as
|
|
13837
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES53 } from "@typescript-eslint/utils";
|
|
13691
13838
|
var requireStaticNextMatcherDocumentation = {
|
|
13692
13839
|
summary: "Require Next.js middleware and proxy matcher configuration to contain only build-time literals.",
|
|
13693
13840
|
rationale: "Next.js must statically analyze matcher values at build time; computed values are ignored.",
|
|
@@ -13700,34 +13847,34 @@ var requireStaticNextMatcherDocumentation = {
|
|
|
13700
13847
|
};
|
|
13701
13848
|
var NEXT_ENTRY_FILE = /(?:^|[/\\])(?:middleware|proxy)\.[cm]?[jt]sx?$/u;
|
|
13702
13849
|
function unwrapExpression3(node) {
|
|
13703
|
-
if (node.type ===
|
|
13850
|
+
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
13851
|
return unwrapExpression3(node.expression);
|
|
13705
13852
|
}
|
|
13706
13853
|
return node;
|
|
13707
13854
|
}
|
|
13708
13855
|
function isStaticValue(node) {
|
|
13709
13856
|
const value = unwrapExpression3(node);
|
|
13710
|
-
if (value.type ===
|
|
13857
|
+
if (value.type === AST_NODE_TYPES53.Literal) {
|
|
13711
13858
|
return true;
|
|
13712
13859
|
}
|
|
13713
|
-
if (value.type ===
|
|
13860
|
+
if (value.type === AST_NODE_TYPES53.TemplateLiteral) {
|
|
13714
13861
|
return value.expressions.length === 0;
|
|
13715
13862
|
}
|
|
13716
|
-
if (value.type ===
|
|
13863
|
+
if (value.type === AST_NODE_TYPES53.ArrayExpression) {
|
|
13717
13864
|
return value.elements.every(
|
|
13718
|
-
(element) => element !== null && element.type !==
|
|
13865
|
+
(element) => element !== null && element.type !== AST_NODE_TYPES53.SpreadElement && isStaticValue(element)
|
|
13719
13866
|
);
|
|
13720
13867
|
}
|
|
13721
|
-
if (value.type ===
|
|
13868
|
+
if (value.type === AST_NODE_TYPES53.ObjectExpression) {
|
|
13722
13869
|
return value.properties.every(
|
|
13723
|
-
(property) => property.type ===
|
|
13870
|
+
(property) => property.type === AST_NODE_TYPES53.Property && property.kind === "init" && !property.computed && property.value.type !== AST_NODE_TYPES53.AssignmentPattern && isStaticValue(property.value)
|
|
13724
13871
|
);
|
|
13725
13872
|
}
|
|
13726
13873
|
return false;
|
|
13727
13874
|
}
|
|
13728
13875
|
function propertyName2(property) {
|
|
13729
13876
|
if (property.computed) return null;
|
|
13730
|
-
if (property.key.type ===
|
|
13877
|
+
if (property.key.type === AST_NODE_TYPES53.Identifier) return property.key.name;
|
|
13731
13878
|
return typeof property.key.value === "string" ? property.key.value : null;
|
|
13732
13879
|
}
|
|
13733
13880
|
var require_static_next_matcher_default = createRule({
|
|
@@ -13750,19 +13897,19 @@ var require_static_next_matcher_default = createRule({
|
|
|
13750
13897
|
}
|
|
13751
13898
|
return {
|
|
13752
13899
|
ExportNamedDeclaration(node) {
|
|
13753
|
-
if (node.declaration?.type !==
|
|
13900
|
+
if (node.declaration?.type !== AST_NODE_TYPES53.VariableDeclaration) {
|
|
13754
13901
|
return;
|
|
13755
13902
|
}
|
|
13756
13903
|
for (const declaration of node.declaration.declarations) {
|
|
13757
|
-
if (declaration.id.type !==
|
|
13904
|
+
if (declaration.id.type !== AST_NODE_TYPES53.Identifier || declaration.id.name !== "config" || declaration.init === null) {
|
|
13758
13905
|
continue;
|
|
13759
13906
|
}
|
|
13760
13907
|
const config = unwrapExpression3(declaration.init);
|
|
13761
|
-
if (config.type !==
|
|
13908
|
+
if (config.type !== AST_NODE_TYPES53.ObjectExpression) {
|
|
13762
13909
|
continue;
|
|
13763
13910
|
}
|
|
13764
13911
|
for (const property of config.properties) {
|
|
13765
|
-
if (property.type !==
|
|
13912
|
+
if (property.type !== AST_NODE_TYPES53.Property || propertyName2(property) !== "matcher" || property.value.type === AST_NODE_TYPES53.AssignmentPattern) {
|
|
13766
13913
|
continue;
|
|
13767
13914
|
}
|
|
13768
13915
|
if (!isStaticValue(property.value)) {
|
|
@@ -13777,7 +13924,7 @@ var require_static_next_matcher_default = createRule({
|
|
|
13777
13924
|
|
|
13778
13925
|
// src/rules/require-zod-form-validation.ts
|
|
13779
13926
|
import {
|
|
13780
|
-
AST_NODE_TYPES as
|
|
13927
|
+
AST_NODE_TYPES as AST_NODE_TYPES54,
|
|
13781
13928
|
ASTUtils as ASTUtils14
|
|
13782
13929
|
} from "@typescript-eslint/utils";
|
|
13783
13930
|
var requireZodFormValidationDocumentation = {
|
|
@@ -13804,14 +13951,14 @@ var FORM_VALUE_METHODS = /* @__PURE__ */ new Set(["get", "getAll"]);
|
|
|
13804
13951
|
var zodReceiverRoot = (node) => {
|
|
13805
13952
|
let current = node;
|
|
13806
13953
|
while (true) {
|
|
13807
|
-
if (current.type ===
|
|
13954
|
+
if (current.type === AST_NODE_TYPES54.Identifier) {
|
|
13808
13955
|
return current;
|
|
13809
13956
|
}
|
|
13810
|
-
if (current.type ===
|
|
13957
|
+
if (current.type === AST_NODE_TYPES54.CallExpression) {
|
|
13811
13958
|
current = current.callee;
|
|
13812
13959
|
continue;
|
|
13813
13960
|
}
|
|
13814
|
-
if (current.type ===
|
|
13961
|
+
if (current.type === AST_NODE_TYPES54.MemberExpression) {
|
|
13815
13962
|
current = current.object;
|
|
13816
13963
|
continue;
|
|
13817
13964
|
}
|
|
@@ -13820,12 +13967,12 @@ var zodReceiverRoot = (node) => {
|
|
|
13820
13967
|
};
|
|
13821
13968
|
var isFormDataMethodCall = (node) => {
|
|
13822
13969
|
let current = node;
|
|
13823
|
-
if (current.type ===
|
|
13970
|
+
if (current.type === AST_NODE_TYPES54.AwaitExpression) {
|
|
13824
13971
|
current = current.argument;
|
|
13825
13972
|
}
|
|
13826
|
-
if (current.type !==
|
|
13973
|
+
if (current.type !== AST_NODE_TYPES54.CallExpression) return false;
|
|
13827
13974
|
const callee = current.callee;
|
|
13828
|
-
return callee.type ===
|
|
13975
|
+
return callee.type === AST_NODE_TYPES54.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES54.Identifier && callee.property.name === "formData";
|
|
13829
13976
|
};
|
|
13830
13977
|
var require_zod_form_validation_default = createRule({
|
|
13831
13978
|
name: "require-zod-form-validation",
|
|
@@ -13856,16 +14003,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
13856
14003
|
return false;
|
|
13857
14004
|
}
|
|
13858
14005
|
const definition = binding.defs[0];
|
|
13859
|
-
if (definition?.type !== "Variable" || definition.node.type !==
|
|
14006
|
+
if (definition?.type !== "Variable" || definition.node.type !== AST_NODE_TYPES54.VariableDeclarator) {
|
|
13860
14007
|
return false;
|
|
13861
14008
|
}
|
|
13862
14009
|
const init = definition.node.init;
|
|
13863
|
-
return init?.type ===
|
|
14010
|
+
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
14011
|
};
|
|
13865
14012
|
const isZodParseCall = (node) => {
|
|
13866
|
-
if (node.type !==
|
|
14013
|
+
if (node.type !== AST_NODE_TYPES54.CallExpression) return false;
|
|
13867
14014
|
const callee = node.callee;
|
|
13868
|
-
if (callee.type !==
|
|
14015
|
+
if (callee.type !== AST_NODE_TYPES54.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES54.Identifier || !ZOD_PARSE_METHODS.has(callee.property.name)) {
|
|
13869
14016
|
return false;
|
|
13870
14017
|
}
|
|
13871
14018
|
const root = zodReceiverRoot(callee.object);
|
|
@@ -13874,14 +14021,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
13874
14021
|
return binding !== null && zodBindings.has(binding) || (root.name === "z" || ZOD_SCHEMA_NAME_RE.test(root.name)) && !isProvablyNonZodLocal(root);
|
|
13875
14022
|
};
|
|
13876
14023
|
const isFormSourceIdentifier = (node) => {
|
|
13877
|
-
if (node.type !==
|
|
14024
|
+
if (node.type !== AST_NODE_TYPES54.Identifier) return false;
|
|
13878
14025
|
const conventionalName = /formdata/i.test(node.name);
|
|
13879
14026
|
let scope = context.sourceCode.getScope(node);
|
|
13880
14027
|
while (scope !== null) {
|
|
13881
14028
|
const variable = scope.set.get(node.name);
|
|
13882
14029
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
13883
14030
|
const def = variable.defs[0];
|
|
13884
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
14031
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === AST_NODE_TYPES54.VariableDeclarator && def.node.init !== null) {
|
|
13885
14032
|
return isFormDataMethodCall(def.node.init);
|
|
13886
14033
|
}
|
|
13887
14034
|
return def?.type === "Parameter" && conventionalName;
|
|
@@ -13892,8 +14039,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
13892
14039
|
};
|
|
13893
14040
|
const isFormDataGetCall = (node) => {
|
|
13894
14041
|
const callee = node.callee;
|
|
13895
|
-
if (callee.type !==
|
|
13896
|
-
if (callee.property.type !==
|
|
14042
|
+
if (callee.type !== AST_NODE_TYPES54.MemberExpression) return false;
|
|
14043
|
+
if (callee.property.type !== AST_NODE_TYPES54.Identifier || !FORM_VALUE_METHODS.has(callee.property.name)) {
|
|
13897
14044
|
return false;
|
|
13898
14045
|
}
|
|
13899
14046
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -13909,16 +14056,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
13909
14056
|
const hasZodParseAncestor = (node) => zodParseAncestor(node) !== null;
|
|
13910
14057
|
const isInstanceofNarrowing = (node) => {
|
|
13911
14058
|
const parent = node.parent;
|
|
13912
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
14059
|
+
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
14060
|
};
|
|
13914
14061
|
const boundDeclarator = (node) => {
|
|
13915
14062
|
let current = node;
|
|
13916
14063
|
let parent = current.parent;
|
|
13917
|
-
while ((parent.type ===
|
|
14064
|
+
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
14065
|
current = parent;
|
|
13919
14066
|
parent = current.parent;
|
|
13920
14067
|
}
|
|
13921
|
-
if (parent.type ===
|
|
14068
|
+
if (parent.type === AST_NODE_TYPES54.VariableDeclarator && parent.init === current && parent.id.type === AST_NODE_TYPES54.Identifier) {
|
|
13922
14069
|
return parent;
|
|
13923
14070
|
}
|
|
13924
14071
|
return null;
|
|
@@ -13927,7 +14074,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
13927
14074
|
let current = node;
|
|
13928
14075
|
while (current.parent !== void 0) {
|
|
13929
14076
|
const parent = current.parent;
|
|
13930
|
-
if (parent.type ===
|
|
14077
|
+
if (parent.type === AST_NODE_TYPES54.BlockStatement || parent.type === AST_NODE_TYPES54.Program) {
|
|
13931
14078
|
return current;
|
|
13932
14079
|
}
|
|
13933
14080
|
current = parent;
|
|
@@ -13936,12 +14083,12 @@ var require_zod_form_validation_default = createRule({
|
|
|
13936
14083
|
};
|
|
13937
14084
|
const zodParseMethod = (call) => {
|
|
13938
14085
|
const callee = call.callee;
|
|
13939
|
-
return callee.type ===
|
|
14086
|
+
return callee.type === AST_NODE_TYPES54.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES54.Identifier ? callee.property.name : null;
|
|
13940
14087
|
};
|
|
13941
14088
|
const hasConditionalAncestorBeforeStatement = (node, statement) => {
|
|
13942
14089
|
let current = node.parent;
|
|
13943
14090
|
while (current !== void 0 && current !== statement) {
|
|
13944
|
-
if (current.type ===
|
|
14091
|
+
if (current.type === AST_NODE_TYPES54.LogicalExpression || current.type === AST_NODE_TYPES54.ConditionalExpression) {
|
|
13945
14092
|
return true;
|
|
13946
14093
|
}
|
|
13947
14094
|
current = current.parent;
|
|
@@ -13951,7 +14098,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
13951
14098
|
const isAwaitedBeforeStatement = (node, statement) => {
|
|
13952
14099
|
let current = node.parent;
|
|
13953
14100
|
while (current !== void 0 && current !== statement) {
|
|
13954
|
-
if (current.type ===
|
|
14101
|
+
if (current.type === AST_NODE_TYPES54.AwaitExpression) return true;
|
|
13955
14102
|
current = current.parent;
|
|
13956
14103
|
}
|
|
13957
14104
|
return false;
|
|
@@ -13964,7 +14111,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
13964
14111
|
if (declarationStatement === null || validationStatement === null || declarationStatement.parent !== validationStatement.parent || validationStatement.range[0] <= declarationStatement.range[1] || hasConditionalAncestorBeforeStatement(parse2, validationStatement)) {
|
|
13965
14112
|
return null;
|
|
13966
14113
|
}
|
|
13967
|
-
if (validationStatement.type !==
|
|
14114
|
+
if (validationStatement.type !== AST_NODE_TYPES54.VariableDeclaration && validationStatement.type !== AST_NODE_TYPES54.ExpressionStatement) {
|
|
13968
14115
|
return null;
|
|
13969
14116
|
}
|
|
13970
14117
|
const method = zodParseMethod(parse2);
|
|
@@ -13976,16 +14123,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
13976
14123
|
};
|
|
13977
14124
|
const isSafePrevalidationInspection = (identifier) => {
|
|
13978
14125
|
const parent = identifier.parent;
|
|
13979
|
-
if (parent.type ===
|
|
14126
|
+
if (parent.type === AST_NODE_TYPES54.UnaryExpression && parent.operator === "typeof") {
|
|
13980
14127
|
return true;
|
|
13981
14128
|
}
|
|
13982
|
-
if (parent.type !==
|
|
14129
|
+
if (parent.type !== AST_NODE_TYPES54.BinaryExpression || parent.left !== identifier) {
|
|
13983
14130
|
return false;
|
|
13984
14131
|
}
|
|
13985
14132
|
if (parent.operator === "instanceof") {
|
|
13986
|
-
return parent.right.type ===
|
|
14133
|
+
return parent.right.type === AST_NODE_TYPES54.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
13987
14134
|
}
|
|
13988
|
-
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type ===
|
|
14135
|
+
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
14136
|
};
|
|
13990
14137
|
const isDescendantOf = (node, ancestor) => {
|
|
13991
14138
|
let current = node;
|
|
@@ -13996,23 +14143,23 @@ var require_zod_form_validation_default = createRule({
|
|
|
13996
14143
|
return false;
|
|
13997
14144
|
};
|
|
13998
14145
|
const blockTerminates = (node) => {
|
|
13999
|
-
if (node.type ===
|
|
14146
|
+
if (node.type === AST_NODE_TYPES54.ReturnStatement || node.type === AST_NODE_TYPES54.ThrowStatement) {
|
|
14000
14147
|
return true;
|
|
14001
14148
|
}
|
|
14002
|
-
if (node.type !==
|
|
14149
|
+
if (node.type !== AST_NODE_TYPES54.BlockStatement || node.body.length === 0) return false;
|
|
14003
14150
|
const last = node.body.at(-1);
|
|
14004
14151
|
return last !== void 0 && blockTerminates(last);
|
|
14005
14152
|
};
|
|
14006
14153
|
const narrowingIf = (identifier) => {
|
|
14007
14154
|
const comparison = identifier.parent;
|
|
14008
|
-
if (comparison?.type !==
|
|
14155
|
+
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
14156
|
return null;
|
|
14010
14157
|
}
|
|
14011
14158
|
const maybeNegation = comparison.parent;
|
|
14012
|
-
const negated = maybeNegation?.type ===
|
|
14159
|
+
const negated = maybeNegation?.type === AST_NODE_TYPES54.UnaryExpression && maybeNegation.operator === "!";
|
|
14013
14160
|
const test = negated ? maybeNegation : comparison;
|
|
14014
14161
|
const branch = test.parent;
|
|
14015
|
-
return branch?.type ===
|
|
14162
|
+
return branch?.type === AST_NODE_TYPES54.IfStatement && branch.test === test ? { branch, positive: !negated } : null;
|
|
14016
14163
|
};
|
|
14017
14164
|
const useDominatedByNarrowing = (use, narrowings) => narrowings.some(({ branch, positive }) => {
|
|
14018
14165
|
if (positive) return isDescendantOf(use, branch.consequent);
|
|
@@ -14032,7 +14179,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14032
14179
|
const variable = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
14033
14180
|
if (variable === void 0) return false;
|
|
14034
14181
|
const references = variable.references.filter((reference) => !reference.isWriteOnly()).map((reference) => reference.identifier).filter(
|
|
14035
|
-
(identifier) => identifier.type ===
|
|
14182
|
+
(identifier) => identifier.type === AST_NODE_TYPES54.Identifier
|
|
14036
14183
|
);
|
|
14037
14184
|
if (references.length === 0) return false;
|
|
14038
14185
|
const narrowings = references.map(narrowingIf).filter(
|
|
@@ -14058,7 +14205,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14058
14205
|
ImportDeclaration(node) {
|
|
14059
14206
|
if (!isZodModule(node.source.value)) return;
|
|
14060
14207
|
for (const specifier of node.specifiers) {
|
|
14061
|
-
if (specifier.type ===
|
|
14208
|
+
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
14209
|
const binding = resolvedBinding(specifier.local);
|
|
14063
14210
|
if (binding !== null) zodBindings.add(binding);
|
|
14064
14211
|
}
|
|
@@ -14143,7 +14290,7 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
14143
14290
|
});
|
|
14144
14291
|
|
|
14145
14292
|
// src/rules/stepdown.ts
|
|
14146
|
-
import { AST_NODE_TYPES as
|
|
14293
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES55, ASTUtils as ASTUtils15 } from "@typescript-eslint/utils";
|
|
14147
14294
|
var stepdownDocumentation = {
|
|
14148
14295
|
summary: "Place a private helper below its sole direct same-scope caller.",
|
|
14149
14296
|
rationale: "Caller-first ordering lets a reader follow the main flow before descending into implementation details.",
|
|
@@ -14160,7 +14307,7 @@ var stepdownDocumentation = {
|
|
|
14160
14307
|
]
|
|
14161
14308
|
};
|
|
14162
14309
|
function isFunction(node) {
|
|
14163
|
-
return node.type ===
|
|
14310
|
+
return node.type === AST_NODE_TYPES55.ArrowFunctionExpression || node.type === AST_NODE_TYPES55.FunctionDeclaration || node.type === AST_NODE_TYPES55.FunctionExpression;
|
|
14164
14311
|
}
|
|
14165
14312
|
function reportMisordered(context, candidates, scopeDefinitions, calls, pinned, canMove = () => true) {
|
|
14166
14313
|
const byName = new Map(scopeDefinitions.map((definition) => [definition.name, definition]));
|
|
@@ -14255,8 +14402,8 @@ function moduleScope(context, program) {
|
|
|
14255
14402
|
for (const node of declarations) counts.set(node.name, (counts.get(node.name) ?? 0) + 1);
|
|
14256
14403
|
const overloadNames = new Set(
|
|
14257
14404
|
program.body.flatMap((statement) => {
|
|
14258
|
-
const node = statement.type ===
|
|
14259
|
-
return node?.type ===
|
|
14405
|
+
const node = statement.type === AST_NODE_TYPES55.ExportNamedDeclaration ? statement.declaration : statement;
|
|
14406
|
+
return node?.type === AST_NODE_TYPES55.TSDeclareFunction && node.id !== null ? [node.id.name] : [];
|
|
14260
14407
|
})
|
|
14261
14408
|
);
|
|
14262
14409
|
const exported = exportedNames(program);
|
|
@@ -14280,7 +14427,7 @@ function moduleScope(context, program) {
|
|
|
14280
14427
|
const nearestFunction = [...ancestors].reverse().find(isFunction);
|
|
14281
14428
|
const parent = identifier.parent;
|
|
14282
14429
|
const callerDefinition = nearestFunction === void 0 ? void 0 : byFunction.get(nearestFunction);
|
|
14283
|
-
if (callerDefinition === void 0 || parent.type !==
|
|
14430
|
+
if (callerDefinition === void 0 || parent.type !== AST_NODE_TYPES55.CallExpression || parent.callee !== identifier) {
|
|
14284
14431
|
pinned.add(definition.name);
|
|
14285
14432
|
continue;
|
|
14286
14433
|
}
|
|
@@ -14295,38 +14442,38 @@ function moduleScope(context, program) {
|
|
|
14295
14442
|
function exportedNames(program) {
|
|
14296
14443
|
const names = /* @__PURE__ */ new Set();
|
|
14297
14444
|
for (const statement of program.body) {
|
|
14298
|
-
if (statement.type !==
|
|
14299
|
-
if (statement.declaration?.type ===
|
|
14445
|
+
if (statement.type !== AST_NODE_TYPES55.ExportNamedDeclaration || statement.exportKind === "type" || statement.source !== null) continue;
|
|
14446
|
+
if (statement.declaration?.type === AST_NODE_TYPES55.FunctionDeclaration && statement.declaration.id !== null) {
|
|
14300
14447
|
names.add(statement.declaration.id.name);
|
|
14301
14448
|
}
|
|
14302
|
-
if (statement.declaration?.type ===
|
|
14449
|
+
if (statement.declaration?.type === AST_NODE_TYPES55.VariableDeclaration) {
|
|
14303
14450
|
for (const declarator of statement.declaration.declarations) {
|
|
14304
|
-
if (declarator.id.type ===
|
|
14451
|
+
if (declarator.id.type === AST_NODE_TYPES55.Identifier) names.add(declarator.id.name);
|
|
14305
14452
|
}
|
|
14306
14453
|
}
|
|
14307
14454
|
for (const specifier of statement.specifiers) {
|
|
14308
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
14455
|
+
if (specifier.exportKind !== "type" && specifier.local.type === AST_NODE_TYPES55.Identifier) {
|
|
14309
14456
|
names.add(specifier.local.name);
|
|
14310
14457
|
}
|
|
14311
14458
|
}
|
|
14312
14459
|
}
|
|
14313
14460
|
for (const statement of program.body) {
|
|
14314
|
-
if (statement.type ===
|
|
14315
|
-
if (statement.type ===
|
|
14461
|
+
if (statement.type === AST_NODE_TYPES55.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES55.Identifier) names.add(statement.declaration.name);
|
|
14462
|
+
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
14463
|
}
|
|
14317
14464
|
return names;
|
|
14318
14465
|
}
|
|
14319
14466
|
function moduleDefinitions(program) {
|
|
14320
14467
|
const definitions = [];
|
|
14321
14468
|
for (const statement of program.body) {
|
|
14322
|
-
const node = statement.type ===
|
|
14323
|
-
if (node?.type ===
|
|
14469
|
+
const node = statement.type === AST_NODE_TYPES55.ExportNamedDeclaration || statement.type === AST_NODE_TYPES55.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
14470
|
+
if (node?.type === AST_NODE_TYPES55.FunctionDeclaration && node.id !== null && node.body !== null) {
|
|
14324
14471
|
definitions.push({ name: node.id.name, node, functionNode: node, bindingNode: node });
|
|
14325
14472
|
continue;
|
|
14326
14473
|
}
|
|
14327
|
-
if (node?.type !==
|
|
14474
|
+
if (node?.type !== AST_NODE_TYPES55.VariableDeclaration || node.kind !== "const") continue;
|
|
14328
14475
|
for (const declarator of node.declarations) {
|
|
14329
|
-
if (declarator.id.type ===
|
|
14476
|
+
if (declarator.id.type === AST_NODE_TYPES55.Identifier && declarator.init !== null && isFunction(declarator.init)) {
|
|
14330
14477
|
definitions.push({
|
|
14331
14478
|
name: declarator.id.name,
|
|
14332
14479
|
node: declarator,
|
|
@@ -14339,21 +14486,21 @@ function moduleDefinitions(program) {
|
|
|
14339
14486
|
return definitions;
|
|
14340
14487
|
}
|
|
14341
14488
|
function methodName(node) {
|
|
14342
|
-
if (node.key.type ===
|
|
14343
|
-
return !node.computed && node.key.type ===
|
|
14489
|
+
if (node.key.type === AST_NODE_TYPES55.PrivateIdentifier) return `#${node.key.name}`;
|
|
14490
|
+
return !node.computed && node.key.type === AST_NODE_TYPES55.Identifier ? node.key.name : null;
|
|
14344
14491
|
}
|
|
14345
14492
|
function referencedMethod(context, node, classVariables) {
|
|
14346
|
-
const objectVariable = node.object.type ===
|
|
14493
|
+
const objectVariable = node.object.type === AST_NODE_TYPES55.Identifier ? ASTUtils15.findVariable(context.sourceCode.getScope(node.object), node.object.name) : null;
|
|
14347
14494
|
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 ===
|
|
14495
|
+
if (node.object.type !== AST_NODE_TYPES55.ThisExpression && !isClassReference) return null;
|
|
14496
|
+
if (node.property.type === AST_NODE_TYPES55.PrivateIdentifier) return `#${node.property.name}`;
|
|
14497
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES55.Identifier) return node.property.name;
|
|
14498
|
+
return node.computed && node.property.type === AST_NODE_TYPES55.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
14352
14499
|
}
|
|
14353
14500
|
function referencedPropertyName(node) {
|
|
14354
|
-
if (node.property.type ===
|
|
14355
|
-
if (!node.computed && node.property.type ===
|
|
14356
|
-
return node.computed && node.property.type ===
|
|
14501
|
+
if (node.property.type === AST_NODE_TYPES55.PrivateIdentifier) return `#${node.property.name}`;
|
|
14502
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES55.Identifier) return node.property.name;
|
|
14503
|
+
return node.computed && node.property.type === AST_NODE_TYPES55.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
14357
14504
|
}
|
|
14358
14505
|
function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
14359
14506
|
visit(node, nestedFunction);
|
|
@@ -14369,7 +14516,7 @@ function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
|
14369
14516
|
}
|
|
14370
14517
|
function classScope(context, node, computedReferenceNames) {
|
|
14371
14518
|
const methods = node.body.body.filter(
|
|
14372
|
-
(member) => member.type ===
|
|
14519
|
+
(member) => member.type === AST_NODE_TYPES55.MethodDefinition
|
|
14373
14520
|
);
|
|
14374
14521
|
const counts = /* @__PURE__ */ new Map();
|
|
14375
14522
|
for (const method of methods) {
|
|
@@ -14377,8 +14524,8 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
14377
14524
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
14378
14525
|
}
|
|
14379
14526
|
for (const member of node.body.body) {
|
|
14380
|
-
if (member.type !==
|
|
14381
|
-
const name = !member.computed && member.key.type ===
|
|
14527
|
+
if (member.type !== AST_NODE_TYPES55.TSAbstractMethodDefinition) continue;
|
|
14528
|
+
const name = !member.computed && member.key.type === AST_NODE_TYPES55.Identifier ? member.key.name : null;
|
|
14382
14529
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
14383
14530
|
}
|
|
14384
14531
|
const scopeDefinitions = methods.flatMap((method) => {
|
|
@@ -14387,7 +14534,7 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
14387
14534
|
});
|
|
14388
14535
|
const definitions = methods.flatMap((method) => {
|
|
14389
14536
|
const name = methodName(method);
|
|
14390
|
-
const isPrivate = method.accessibility === "private" || method.key.type ===
|
|
14537
|
+
const isPrivate = method.accessibility === "private" || method.key.type === AST_NODE_TYPES55.PrivateIdentifier;
|
|
14391
14538
|
return name !== null && isPrivate && counts.get(name) === 1 && method.decorators.length === 0 ? [{ name, node: method }] : [];
|
|
14392
14539
|
});
|
|
14393
14540
|
if (definitions.length === 0) return;
|
|
@@ -14399,7 +14546,7 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
14399
14546
|
const internal = ASTUtils15.findVariable(context.sourceCode.getScope(node), node.id.name);
|
|
14400
14547
|
if (internal !== null) classVariables.add(internal);
|
|
14401
14548
|
}
|
|
14402
|
-
if (node.type ===
|
|
14549
|
+
if (node.type === AST_NODE_TYPES55.ClassExpression && node.parent.type === AST_NODE_TYPES55.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES55.Identifier) {
|
|
14403
14550
|
const outer = ASTUtils15.findVariable(context.sourceCode.getScope(node.parent), node.parent.id.name);
|
|
14404
14551
|
if (outer !== null) classVariables.add(outer);
|
|
14405
14552
|
}
|
|
@@ -14416,26 +14563,26 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
14416
14563
|
}
|
|
14417
14564
|
const thisValue = (value) => {
|
|
14418
14565
|
let current = value;
|
|
14419
|
-
while (current?.type ===
|
|
14420
|
-
return current?.type ===
|
|
14566
|
+
while (current?.type === AST_NODE_TYPES55.TSAsExpression || current?.type === AST_NODE_TYPES55.TSSatisfiesExpression || current?.type === AST_NODE_TYPES55.TSNonNullExpression) current = current.expression;
|
|
14567
|
+
return current?.type === AST_NODE_TYPES55.ThisExpression;
|
|
14421
14568
|
};
|
|
14422
14569
|
const collectAlias = (current, nestedFunction) => {
|
|
14423
|
-
if (nestedFunction || current.type !==
|
|
14424
|
-
if (current.type ===
|
|
14425
|
-
const binding = current.type ===
|
|
14426
|
-
const value = current.type ===
|
|
14570
|
+
if (nestedFunction || current.type !== AST_NODE_TYPES55.VariableDeclarator && current.type !== AST_NODE_TYPES55.AssignmentPattern) return;
|
|
14571
|
+
if (current.type === AST_NODE_TYPES55.VariableDeclarator && (current.parent.type !== AST_NODE_TYPES55.VariableDeclaration || current.parent.kind !== "const")) return;
|
|
14572
|
+
const binding = current.type === AST_NODE_TYPES55.VariableDeclarator ? current.id : current.left;
|
|
14573
|
+
const value = current.type === AST_NODE_TYPES55.VariableDeclarator ? current.init : current.right;
|
|
14427
14574
|
if (!thisValue(value)) return;
|
|
14428
|
-
if (binding.type ===
|
|
14575
|
+
if (binding.type === AST_NODE_TYPES55.ObjectPattern) {
|
|
14429
14576
|
for (const property of binding.properties) {
|
|
14430
|
-
if (property.type ===
|
|
14577
|
+
if (property.type === AST_NODE_TYPES55.RestElement) {
|
|
14431
14578
|
for (const name of privateNames) pinned.add(name);
|
|
14432
|
-
} else if (property.key.type ===
|
|
14579
|
+
} else if (property.key.type === AST_NODE_TYPES55.Identifier && privateNames.has(property.key.name)) {
|
|
14433
14580
|
pinned.add(property.key.name);
|
|
14434
14581
|
}
|
|
14435
14582
|
}
|
|
14436
14583
|
return;
|
|
14437
14584
|
}
|
|
14438
|
-
if (binding.type !==
|
|
14585
|
+
if (binding.type !== AST_NODE_TYPES55.Identifier) return;
|
|
14439
14586
|
const variable = ASTUtils15.findVariable(context.sourceCode.getScope(binding), binding.name);
|
|
14440
14587
|
if (variable !== null) {
|
|
14441
14588
|
methodClassVariables.add(variable);
|
|
@@ -14449,16 +14596,16 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
14449
14596
|
walk(statement, context.sourceCode.visitorKeys, collectAlias);
|
|
14450
14597
|
}
|
|
14451
14598
|
const visitCall = (current, nestedFunction) => {
|
|
14452
|
-
if (current.type ===
|
|
14599
|
+
if (current.type === AST_NODE_TYPES55.VariableDeclarator && current.id.type === AST_NODE_TYPES55.ObjectPattern && thisValue(current.init)) {
|
|
14453
14600
|
for (const property of current.id.properties) {
|
|
14454
|
-
if (property.type ===
|
|
14601
|
+
if (property.type === AST_NODE_TYPES55.RestElement) {
|
|
14455
14602
|
for (const name of privateNames) pinned.add(name);
|
|
14456
14603
|
continue;
|
|
14457
14604
|
}
|
|
14458
|
-
if (property.type ===
|
|
14605
|
+
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
14606
|
}
|
|
14460
14607
|
}
|
|
14461
|
-
if (current.type !==
|
|
14608
|
+
if (current.type !== AST_NODE_TYPES55.MemberExpression) return;
|
|
14462
14609
|
const target = referencedMethod(context, current, methodClassVariables);
|
|
14463
14610
|
if (target === null) {
|
|
14464
14611
|
const possibleTarget = referencedPropertyName(current);
|
|
@@ -14466,12 +14613,12 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
14466
14613
|
return;
|
|
14467
14614
|
}
|
|
14468
14615
|
if (!privateNames.has(target)) return;
|
|
14469
|
-
const objectVariable = current.object.type ===
|
|
14616
|
+
const objectVariable = current.object.type === AST_NODE_TYPES55.Identifier ? ASTUtils15.findVariable(context.sourceCode.getScope(current.object), current.object.name) : null;
|
|
14470
14617
|
if (objectVariable !== null && methodAliases.has(objectVariable)) {
|
|
14471
14618
|
pinned.add(target);
|
|
14472
14619
|
return;
|
|
14473
14620
|
}
|
|
14474
|
-
if (current.computed || nestedFunction || parameterDecoratorNodes.has(current) || current.parent.type !==
|
|
14621
|
+
if (current.computed || nestedFunction || parameterDecoratorNodes.has(current) || current.parent.type !== AST_NODE_TYPES55.CallExpression || current.parent.callee !== current) {
|
|
14475
14622
|
pinned.add(target);
|
|
14476
14623
|
return;
|
|
14477
14624
|
}
|
|
@@ -14491,9 +14638,9 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
14491
14638
|
}
|
|
14492
14639
|
}
|
|
14493
14640
|
for (const member of node.body.body) {
|
|
14494
|
-
if (member.type ===
|
|
14641
|
+
if (member.type === AST_NODE_TYPES55.MethodDefinition || member.type === AST_NODE_TYPES55.TSAbstractMethodDefinition) continue;
|
|
14495
14642
|
walk(member, context.sourceCode.visitorKeys, (current) => {
|
|
14496
|
-
if (current.type !==
|
|
14643
|
+
if (current.type !== AST_NODE_TYPES55.MemberExpression) return;
|
|
14497
14644
|
const target = referencedMethod(context, current, classVariables);
|
|
14498
14645
|
const possibleTarget = target ?? referencedPropertyName(current);
|
|
14499
14646
|
if (possibleTarget !== null && privateNames.has(possibleTarget)) pinned.add(possibleTarget);
|
|
@@ -14503,14 +14650,14 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
14503
14650
|
const accessibility = new Map(
|
|
14504
14651
|
scopeDefinitions.map((definition) => {
|
|
14505
14652
|
const method = definition.node;
|
|
14506
|
-
const accessibility2 = method.key.type ===
|
|
14653
|
+
const accessibility2 = method.key.type === AST_NODE_TYPES55.PrivateIdentifier ? "private" : method.accessibility ?? "public";
|
|
14507
14654
|
return [definition.name, accessibility2];
|
|
14508
14655
|
})
|
|
14509
14656
|
);
|
|
14510
14657
|
const methodByName = new Map(scopeDefinitions.map((definition) => [definition.name, definition.node]));
|
|
14511
14658
|
for (const [caller, callees] of calls) {
|
|
14512
14659
|
const callerMethod = methodByName.get(caller);
|
|
14513
|
-
if (accessibility.get(caller) === "private" && callerMethod?.type ===
|
|
14660
|
+
if (accessibility.get(caller) === "private" && callerMethod?.type === AST_NODE_TYPES55.MethodDefinition && callerMethod.decorators.length === 0) continue;
|
|
14514
14661
|
for (const callee of callees) pinned.add(callee);
|
|
14515
14662
|
}
|
|
14516
14663
|
const memberIndexes = new Map(node.body.body.map((member, index) => [member, index]));
|
|
@@ -14527,12 +14674,12 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
14527
14674
|
}
|
|
14528
14675
|
function isClassRuntimeBarrier(member) {
|
|
14529
14676
|
switch (member.type) {
|
|
14530
|
-
case
|
|
14677
|
+
case AST_NODE_TYPES55.StaticBlock:
|
|
14531
14678
|
return true;
|
|
14532
|
-
case
|
|
14533
|
-
case
|
|
14679
|
+
case AST_NODE_TYPES55.PropertyDefinition:
|
|
14680
|
+
case AST_NODE_TYPES55.AccessorProperty:
|
|
14534
14681
|
return member.static || member.computed || member.decorators.length > 0 || member.value !== null;
|
|
14535
|
-
case
|
|
14682
|
+
case AST_NODE_TYPES55.MethodDefinition:
|
|
14536
14683
|
return member.computed || member.decorators.length > 0;
|
|
14537
14684
|
default:
|
|
14538
14685
|
return false;
|
|
@@ -14564,7 +14711,7 @@ var stepdown_default = createRule({
|
|
|
14564
14711
|
moduleScope(context, program);
|
|
14565
14712
|
const computedReferenceNames = /* @__PURE__ */ new Set();
|
|
14566
14713
|
walk(program, context.sourceCode.visitorKeys, (node) => {
|
|
14567
|
-
if (node.type ===
|
|
14714
|
+
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
14715
|
});
|
|
14569
14716
|
for (const node of classes) classScope(context, node, computedReferenceNames);
|
|
14570
14717
|
}
|
|
@@ -14574,7 +14721,7 @@ var stepdown_default = createRule({
|
|
|
14574
14721
|
|
|
14575
14722
|
// src/rules/zod-naming-convention.ts
|
|
14576
14723
|
import {
|
|
14577
|
-
AST_NODE_TYPES as
|
|
14724
|
+
AST_NODE_TYPES as AST_NODE_TYPES56,
|
|
14578
14725
|
ASTUtils as ASTUtils16
|
|
14579
14726
|
} from "@typescript-eslint/utils";
|
|
14580
14727
|
var zodNamingConventionDocumentation = {
|
|
@@ -14617,18 +14764,18 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
14617
14764
|
"prettifyError",
|
|
14618
14765
|
"treeifyError"
|
|
14619
14766
|
]);
|
|
14620
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
14767
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === AST_NODE_TYPES56.Identifier ? callee.property.name : null;
|
|
14621
14768
|
var calleeChainRoot = (node) => {
|
|
14622
14769
|
let current = node;
|
|
14623
14770
|
for (; ; ) {
|
|
14624
|
-
if (current.type ===
|
|
14771
|
+
if (current.type === AST_NODE_TYPES56.Identifier) {
|
|
14625
14772
|
return current;
|
|
14626
14773
|
}
|
|
14627
|
-
if (current.type ===
|
|
14774
|
+
if (current.type === AST_NODE_TYPES56.MemberExpression) {
|
|
14628
14775
|
current = current.object;
|
|
14629
14776
|
continue;
|
|
14630
14777
|
}
|
|
14631
|
-
if (current.type ===
|
|
14778
|
+
if (current.type === AST_NODE_TYPES56.CallExpression) {
|
|
14632
14779
|
current = current.callee;
|
|
14633
14780
|
continue;
|
|
14634
14781
|
}
|
|
@@ -14690,7 +14837,7 @@ var zod_naming_convention_default = createRule({
|
|
|
14690
14837
|
ImportDeclaration(node) {
|
|
14691
14838
|
if (!isZodModule(node.source.value)) return;
|
|
14692
14839
|
for (const specifier of node.specifiers) {
|
|
14693
|
-
if (specifier.type ===
|
|
14840
|
+
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
14841
|
recordZodBinding(specifier.local);
|
|
14695
14842
|
}
|
|
14696
14843
|
}
|
|
@@ -14698,13 +14845,13 @@ var zod_naming_convention_default = createRule({
|
|
|
14698
14845
|
VariableDeclarator(node) {
|
|
14699
14846
|
const init = node.init;
|
|
14700
14847
|
if (init === null || init === void 0) return;
|
|
14701
|
-
if (init.type !==
|
|
14848
|
+
if (init.type !== AST_NODE_TYPES56.CallExpression) return;
|
|
14702
14849
|
const callee = init.callee;
|
|
14703
|
-
if (callee.type !==
|
|
14850
|
+
if (callee.type !== AST_NODE_TYPES56.MemberExpression) return;
|
|
14704
14851
|
if (!isZodChain(callee)) return;
|
|
14705
14852
|
const terminal = terminalMethodName(callee);
|
|
14706
14853
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
14707
|
-
if (node.id.type !==
|
|
14854
|
+
if (node.id.type !== AST_NODE_TYPES56.Identifier) return;
|
|
14708
14855
|
if (test.test(node.id.name)) return;
|
|
14709
14856
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
14710
14857
|
context.report({
|
|
@@ -14848,6 +14995,7 @@ var rules = {
|
|
|
14848
14995
|
"prefer-module-level-schema": prefer_module_level_schema_default,
|
|
14849
14996
|
"prefer-native-random-uuid": prefer_native_random_uuid_default,
|
|
14850
14997
|
"prefer-non-nullable-collection": prefer_non_nullable_collection_default,
|
|
14998
|
+
"prefer-await-in-async-return": prefer_await_in_async_return_default,
|
|
14851
14999
|
"prefer-schema-for-api-payload": prefer_schema_for_api_payload_default,
|
|
14852
15000
|
"prefer-semantic-colors": prefer_semantic_colors_default,
|
|
14853
15001
|
"prefer-server-actions": prefer_server_actions_default,
|
|
@@ -14864,7 +15012,7 @@ var rules = {
|
|
|
14864
15012
|
};
|
|
14865
15013
|
var meta = {
|
|
14866
15014
|
name: "@sarj/eslint-plugin",
|
|
14867
|
-
version: "15.6.
|
|
15015
|
+
version: "15.6.3"
|
|
14868
15016
|
};
|
|
14869
15017
|
var applicationOnlyRules = [
|
|
14870
15018
|
"no-restricted-library-load",
|
|
@@ -14915,6 +15063,7 @@ var recommendedRules = {
|
|
|
14915
15063
|
"@sarj/prefer-module-level-constant": "error",
|
|
14916
15064
|
"@sarj/prefer-module-level-schema": "error",
|
|
14917
15065
|
"@sarj/prefer-non-nullable-collection": "error",
|
|
15066
|
+
"@sarj/prefer-await-in-async-return": "error",
|
|
14918
15067
|
"@sarj/prefer-schema-for-api-payload": "error",
|
|
14919
15068
|
"@sarj/prefer-semantic-colors": ["error", { requireSemanticTokens: true }],
|
|
14920
15069
|
"@sarj/prefer-server-actions": "error",
|
|
@@ -14977,6 +15126,7 @@ var strictRules = {
|
|
|
14977
15126
|
"@sarj/prefer-module-level-constant": "error",
|
|
14978
15127
|
"@sarj/prefer-module-level-schema": "error",
|
|
14979
15128
|
"@sarj/prefer-non-nullable-collection": "error",
|
|
15129
|
+
"@sarj/prefer-await-in-async-return": "error",
|
|
14980
15130
|
"@sarj/prefer-schema-for-api-payload": "error",
|
|
14981
15131
|
"@sarj/prefer-semantic-colors": ["error", { requireSemanticTokens: true }],
|
|
14982
15132
|
"@sarj/prefer-server-actions": "error",
|