@sarj/eslint-plugin 16.4.7 → 16.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +880 -420
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +1111 -651
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,122 @@
|
|
|
1
|
+
// package.json
|
|
2
|
+
var package_default = {
|
|
3
|
+
name: "@sarj/eslint-plugin",
|
|
4
|
+
version: "16.5.0",
|
|
5
|
+
packageManager: "npm@12.1.0",
|
|
6
|
+
description: "Custom ESLint rules for hypermodern TypeScript / React / Next.js projects",
|
|
7
|
+
type: "module",
|
|
8
|
+
main: "./dist/index.cjs",
|
|
9
|
+
module: "./dist/index.js",
|
|
10
|
+
types: "./dist/index.d.ts",
|
|
11
|
+
exports: {
|
|
12
|
+
".": {
|
|
13
|
+
types: "./dist/index.d.ts",
|
|
14
|
+
import: "./dist/index.js",
|
|
15
|
+
require: "./dist/index.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
files: [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
publishConfig: {
|
|
24
|
+
access: "public"
|
|
25
|
+
},
|
|
26
|
+
sideEffects: false,
|
|
27
|
+
repository: {
|
|
28
|
+
type: "git",
|
|
29
|
+
url: "git+https://github.com/sarj-ai/code-standards.git",
|
|
30
|
+
directory: "packages/typescript"
|
|
31
|
+
},
|
|
32
|
+
homepage: "https://code-standards.sarj.ai/rules/eslint/",
|
|
33
|
+
bugs: {
|
|
34
|
+
url: "https://github.com/sarj-ai/code-standards/issues"
|
|
35
|
+
},
|
|
36
|
+
scripts: {
|
|
37
|
+
build: "tsup",
|
|
38
|
+
dogfood: "npm run build && npm run dogfood:built",
|
|
39
|
+
lint: "eslint . ../../.github/scripts ../standards/src ../standards/eslint.config.mjs --max-warnings 0",
|
|
40
|
+
prepack: "npm run build && npm run verify-package",
|
|
41
|
+
test: "vitest run",
|
|
42
|
+
typecheck: "tsc --noEmit",
|
|
43
|
+
"verify-package": `node -e "const fs=require('node:fs'),p=require('./package.json'),walk=x=>typeof x==='string'?[x]:x&&typeof x==='object'?Object.values(x).flatMap(walk):[];for(const file of new Set([p.main,p.module,p.types,...walk(p.exports)].filter(Boolean).map(x=>x.startsWith('./')?x.slice(2):x))){if(!file.startsWith('dist/'))throw new Error('export must live under dist: '+file);const stat=fs.statSync(file);if(!stat.isFile()||stat.size===0)throw new Error('missing or empty export: '+file)}"`,
|
|
44
|
+
"dogfood:built": `eslint --config eslint.dogfood.config.mjs src tests eslint.config.mjs eslint.dogfood.config.mjs module-constant-naming-options.mjs tsup.config.ts vitest.config.ts --max-warnings 0 && node -e "import('./dist/index.js').then(({default:p}) => console.log('dogfood: '+Object.keys(p.rules).length+' TypeScript rules, 0 diagnostics'))"`
|
|
45
|
+
},
|
|
46
|
+
keywords: [
|
|
47
|
+
"eslint",
|
|
48
|
+
"eslintplugin",
|
|
49
|
+
"eslint-plugin",
|
|
50
|
+
"sarj",
|
|
51
|
+
"react",
|
|
52
|
+
"nextjs",
|
|
53
|
+
"zod"
|
|
54
|
+
],
|
|
55
|
+
author: "sarj-ai",
|
|
56
|
+
license: "MIT",
|
|
57
|
+
dependencies: {
|
|
58
|
+
"@typescript-eslint/typescript-estree": "^8.70.1",
|
|
59
|
+
"@typescript-eslint/utils": "^8.70.1",
|
|
60
|
+
"jsonc-parser": "^3.3.1"
|
|
61
|
+
},
|
|
62
|
+
devDependencies: {
|
|
63
|
+
"@eslint-community/eslint-plugin-eslint-comments": "^4.8.1",
|
|
64
|
+
"@eslint/compat": "^2.1.1",
|
|
65
|
+
"@eslint/js": "10.0.1",
|
|
66
|
+
"@shadcn/lint": "0.2.0",
|
|
67
|
+
"@types/node": "26.6.2",
|
|
68
|
+
"@typescript-eslint/parser": "8.70.1",
|
|
69
|
+
"@typescript-eslint/rule-tester": "8.70.1",
|
|
70
|
+
"@typescript-eslint/utils": "8.70.1",
|
|
71
|
+
"@typescript/native": "npm:typescript@7.0.2",
|
|
72
|
+
"@vitest/eslint-plugin": "1.6.27",
|
|
73
|
+
eslint: "10.11.0",
|
|
74
|
+
"eslint-node-test": "0.4.0",
|
|
75
|
+
"eslint-plugin-better-tailwindcss": "^4.7.0",
|
|
76
|
+
"eslint-plugin-jest": "29.16.6",
|
|
77
|
+
"eslint-plugin-jsdoc": "64.5.4",
|
|
78
|
+
"eslint-plugin-n": "^18.3.0",
|
|
79
|
+
"eslint-plugin-perfectionist": "5.12.1",
|
|
80
|
+
"eslint-plugin-playwright": "2.12.0",
|
|
81
|
+
"eslint-plugin-promise": "^7.3.0",
|
|
82
|
+
"eslint-plugin-react": "^7.37.5",
|
|
83
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
84
|
+
"eslint-plugin-simple-import-sort": "^14.0.0",
|
|
85
|
+
"eslint-plugin-testing-library": "7.16.2",
|
|
86
|
+
"eslint-plugin-unicorn": "^76.0.0",
|
|
87
|
+
"eslint-plugin-zod": "^4.14.2",
|
|
88
|
+
globals: "15.15.0",
|
|
89
|
+
tsup: "latest",
|
|
90
|
+
typescript: "npm:@typescript/typescript6@6.0.2",
|
|
91
|
+
"typescript-eslint": "^8.70.1",
|
|
92
|
+
vitest: "5.0.1"
|
|
93
|
+
},
|
|
94
|
+
peerDependencies: {
|
|
95
|
+
eslint: ">=9.39.4",
|
|
96
|
+
typescript: ">=5.0.0"
|
|
97
|
+
},
|
|
98
|
+
engines: {
|
|
99
|
+
node: ">=22.22.2"
|
|
100
|
+
},
|
|
101
|
+
allowScripts: {
|
|
102
|
+
"esbuild@0.28.2": true,
|
|
103
|
+
"fsevents@2.3.3": true
|
|
104
|
+
},
|
|
105
|
+
peerDependenciesMeta: {
|
|
106
|
+
typescript: {
|
|
107
|
+
optional: true
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
overrides: {
|
|
111
|
+
"brace-expansion@^5.0.0": "5.0.9",
|
|
112
|
+
esbuild: "0.28.2",
|
|
113
|
+
"nanoid@<3.3.18": "3.3.18",
|
|
114
|
+
"eslint-plugin-react": {
|
|
115
|
+
eslint: "$eslint"
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
1
120
|
// src/rules/require-explicit-contract-implementation.ts
|
|
2
121
|
import { AST_NODE_TYPES, ESLintUtils as ESLintUtils2 } from "@typescript-eslint/utils";
|
|
3
122
|
import * as ts from "typescript";
|
|
@@ -4748,16 +4867,51 @@ var no_cors_wildcard_with_credentials_default = createRule({
|
|
|
4748
4867
|
});
|
|
4749
4868
|
|
|
4750
4869
|
// src/rules/no-duplicate-lifecycle-refresh-listeners.ts
|
|
4751
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES28, ASTUtils as
|
|
4870
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES28, ASTUtils as ASTUtils9 } from "@typescript-eslint/utils";
|
|
4752
4871
|
|
|
4753
4872
|
// src/rules/_static-string.ts
|
|
4754
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES27 } from "@typescript-eslint/utils";
|
|
4873
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES27, ASTUtils as ASTUtils8 } from "@typescript-eslint/utils";
|
|
4755
4874
|
function staticString(node) {
|
|
4756
4875
|
if (node === void 0) return null;
|
|
4757
4876
|
const value = unwrapExpression(node);
|
|
4758
4877
|
if (value.type === AST_NODE_TYPES27.Literal && typeof value.value === "string") return value.value;
|
|
4759
4878
|
return value.type === AST_NODE_TYPES27.TemplateLiteral && value.expressions.length === 0 ? value.quasis[0]?.value.cooked ?? null : null;
|
|
4760
4879
|
}
|
|
4880
|
+
var SCOPED_STRING_VALUES = /* @__PURE__ */ new WeakMap();
|
|
4881
|
+
function scopedStaticString(node, sourceCode) {
|
|
4882
|
+
let value = unwrapExpression(node);
|
|
4883
|
+
if (value.type !== AST_NODE_TYPES27.Identifier) return staticString(value);
|
|
4884
|
+
let values = SCOPED_STRING_VALUES.get(sourceCode);
|
|
4885
|
+
if (values === void 0) {
|
|
4886
|
+
values = /* @__PURE__ */ new WeakMap();
|
|
4887
|
+
SCOPED_STRING_VALUES.set(sourceCode, values);
|
|
4888
|
+
}
|
|
4889
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4890
|
+
const pending = [];
|
|
4891
|
+
let result = null;
|
|
4892
|
+
while (value.type === AST_NODE_TYPES27.Identifier) {
|
|
4893
|
+
const binding = ASTUtils8.findVariable(sourceCode.getScope(value), value.name);
|
|
4894
|
+
if (binding === null || seen.has(binding)) break;
|
|
4895
|
+
if (values.has(binding)) {
|
|
4896
|
+
result = values.get(binding) ?? null;
|
|
4897
|
+
break;
|
|
4898
|
+
}
|
|
4899
|
+
seen.add(binding);
|
|
4900
|
+
pending.push(binding);
|
|
4901
|
+
const definition = binding.defs.length === 1 ? binding.defs[0] : void 0;
|
|
4902
|
+
if (definition?.type !== "Variable" || definition.node.id.type !== AST_NODE_TYPES27.Identifier || definition.node.init === null || binding.references.some((reference) => reference.isWrite() && reference.init !== true)) break;
|
|
4903
|
+
value = unwrapExpression(definition.node.init);
|
|
4904
|
+
if (value.type !== AST_NODE_TYPES27.Identifier) result = staticString(value);
|
|
4905
|
+
}
|
|
4906
|
+
for (const binding of pending) values.set(binding, result);
|
|
4907
|
+
return result;
|
|
4908
|
+
}
|
|
4909
|
+
function staticPropertyName(node, sourceCode) {
|
|
4910
|
+
const direct = ASTUtils8.getPropertyName(node);
|
|
4911
|
+
if (direct !== null || !node.computed) return direct;
|
|
4912
|
+
const key = node.type === AST_NODE_TYPES27.MemberExpression ? node.property : node.key;
|
|
4913
|
+
return key.type === AST_NODE_TYPES27.Identifier ? scopedStaticString(key, sourceCode) : null;
|
|
4914
|
+
}
|
|
4761
4915
|
|
|
4762
4916
|
// src/rules/no-duplicate-lifecycle-refresh-listeners.ts
|
|
4763
4917
|
var NO_DUPLICATE_LIFECYCLE_REFRESH_LISTENERS_DOCUMENTATION = {
|
|
@@ -4777,19 +4931,19 @@ function importedName(node) {
|
|
|
4777
4931
|
function registration(sourceCode, node) {
|
|
4778
4932
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
4779
4933
|
const receiver = unwrappedNodeCallee.type === AST_NODE_TYPES28.MemberExpression ? unwrapExpression(unwrappedNodeCallee.object) : unwrappedNodeCallee;
|
|
4780
|
-
if (unwrappedNodeCallee.type !== AST_NODE_TYPES28.MemberExpression || receiver.type !== AST_NODE_TYPES28.Identifier || !isUnshadowedGlobal(sourceCode, receiver) ||
|
|
4934
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES28.MemberExpression || receiver.type !== AST_NODE_TYPES28.Identifier || !isUnshadowedGlobal(sourceCode, receiver) || ASTUtils9.getPropertyName(unwrappedNodeCallee) === null || (ASTUtils9.getPropertyName(unwrappedNodeCallee) ?? "") !== "addEventListener" && (ASTUtils9.getPropertyName(unwrappedNodeCallee) ?? "") !== "removeEventListener" || node.arguments.length < 2) return null;
|
|
4781
4935
|
const event = node.arguments[0] === void 0 ? void 0 : unwrapExpression(node.arguments[0]);
|
|
4782
4936
|
const callback = node.arguments[1] === void 0 ? void 0 : unwrapExpression(node.arguments[1]);
|
|
4783
4937
|
if (event === void 0 || callback === void 0) return null;
|
|
4784
4938
|
const eventName = staticString(event);
|
|
4785
4939
|
if (eventName === null || callback.type !== AST_NODE_TYPES28.Identifier) return null;
|
|
4786
|
-
const operation = (
|
|
4940
|
+
const operation = (ASTUtils9.getPropertyName(unwrappedNodeCallee) ?? "") === "addEventListener" ? "add" : "remove";
|
|
4787
4941
|
if (receiver.name === "window" && eventName === "focus") return { operation, event: "focus", callback };
|
|
4788
4942
|
if (receiver.name === "document" && eventName === "visibilitychange") return { operation, event: "visibilitychange", callback };
|
|
4789
4943
|
return null;
|
|
4790
4944
|
}
|
|
4791
4945
|
function isUnshadowedGlobal(sourceCode, node) {
|
|
4792
|
-
const variable =
|
|
4946
|
+
const variable = ASTUtils9.findVariable(sourceCode.getScope(node), node.name);
|
|
4793
4947
|
return variable === null || variable.defs.length === 0;
|
|
4794
4948
|
}
|
|
4795
4949
|
function statementContainer(node) {
|
|
@@ -4828,7 +4982,7 @@ var no_duplicate_lifecycle_refresh_listeners_default = createRule({
|
|
|
4828
4982
|
if (node.source.value !== "next/navigation") return;
|
|
4829
4983
|
for (const specifier of node.specifiers) {
|
|
4830
4984
|
if (specifier.type === AST_NODE_TYPES28.ImportSpecifier && importedName(specifier) === "useRouter") {
|
|
4831
|
-
const variable =
|
|
4985
|
+
const variable = ASTUtils9.findVariable(context.sourceCode.getScope(specifier.local), specifier.local.name);
|
|
4832
4986
|
if (variable !== null) routerHooks.add(variable);
|
|
4833
4987
|
}
|
|
4834
4988
|
}
|
|
@@ -4836,7 +4990,7 @@ var no_duplicate_lifecycle_refresh_listeners_default = createRule({
|
|
|
4836
4990
|
VariableDeclarator(node) {
|
|
4837
4991
|
const initializer = node.init === null ? null : unwrapExpression(node.init);
|
|
4838
4992
|
if (node.id.type !== AST_NODE_TYPES28.Identifier) return;
|
|
4839
|
-
const variable =
|
|
4993
|
+
const variable = ASTUtils9.findVariable(context.sourceCode.getScope(node.id), node.id.name);
|
|
4840
4994
|
if (variable === null || variable.references.some((reference) => reference.isWrite() && !reference.init)) return;
|
|
4841
4995
|
if (initializer?.type === AST_NODE_TYPES28.ArrowFunctionExpression || initializer?.type === AST_NODE_TYPES28.FunctionExpression) {
|
|
4842
4996
|
functionCallbacks.set(initializer, variable);
|
|
@@ -4844,19 +4998,19 @@ var no_duplicate_lifecycle_refresh_listeners_default = createRule({
|
|
|
4844
4998
|
if (initializer?.type !== AST_NODE_TYPES28.CallExpression) return;
|
|
4845
4999
|
const hookCallee = unwrapExpression(initializer.callee);
|
|
4846
5000
|
if (hookCallee.type !== AST_NODE_TYPES28.Identifier) return;
|
|
4847
|
-
const hook =
|
|
5001
|
+
const hook = ASTUtils9.findVariable(context.sourceCode.getScope(hookCallee), hookCallee.name);
|
|
4848
5002
|
if (hook !== null && routerHooks.has(hook)) routers.add(variable);
|
|
4849
5003
|
},
|
|
4850
5004
|
FunctionDeclaration(node) {
|
|
4851
5005
|
if (node.id === null) return;
|
|
4852
|
-
const variable =
|
|
5006
|
+
const variable = ASTUtils9.findVariable(context.sourceCode.getScope(node.id), node.id.name);
|
|
4853
5007
|
if (variable !== null && !variable.references.some((reference) => reference.isWrite() && !reference.init)) functionCallbacks.set(node, variable);
|
|
4854
5008
|
},
|
|
4855
5009
|
CallExpression(node) {
|
|
4856
5010
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
4857
5011
|
const item = registration(context.sourceCode, node);
|
|
4858
5012
|
if (item !== null) {
|
|
4859
|
-
const callback2 =
|
|
5013
|
+
const callback2 = ASTUtils9.findVariable(context.sourceCode.getScope(item.callback), item.callback.name);
|
|
4860
5014
|
const container = statementContainer(node);
|
|
4861
5015
|
if (callback2 !== null && container !== null) {
|
|
4862
5016
|
const callbacks = registrations.get(container) ?? /* @__PURE__ */ new Map();
|
|
@@ -4868,8 +5022,8 @@ var no_duplicate_lifecycle_refresh_listeners_default = createRule({
|
|
|
4868
5022
|
}
|
|
4869
5023
|
}
|
|
4870
5024
|
const receiver = unwrappedNodeCallee.type === AST_NODE_TYPES28.MemberExpression ? unwrapExpression(unwrappedNodeCallee.object) : unwrappedNodeCallee;
|
|
4871
|
-
if (unwrappedNodeCallee.type !== AST_NODE_TYPES28.MemberExpression || receiver.type !== AST_NODE_TYPES28.Identifier ||
|
|
4872
|
-
const router =
|
|
5025
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES28.MemberExpression || receiver.type !== AST_NODE_TYPES28.Identifier || ASTUtils9.getPropertyName(unwrappedNodeCallee) === null || (ASTUtils9.getPropertyName(unwrappedNodeCallee) ?? "") !== "refresh") return;
|
|
5026
|
+
const router = ASTUtils9.findVariable(context.sourceCode.getScope(receiver), receiver.name);
|
|
4873
5027
|
if (router === null || !routers.has(router)) return;
|
|
4874
5028
|
const fn = enclosingFunction(context.sourceCode, node);
|
|
4875
5029
|
if (fn === null) return;
|
|
@@ -4891,14 +5045,14 @@ var no_duplicate_lifecycle_refresh_listeners_default = createRule({
|
|
|
4891
5045
|
});
|
|
4892
5046
|
|
|
4893
5047
|
// src/rules/_exported-next-config-property.ts
|
|
4894
|
-
import { ASTUtils as
|
|
5048
|
+
import { ASTUtils as ASTUtils10 } from "@typescript-eslint/utils";
|
|
4895
5049
|
function exportedNextConfigProperty(sourceCode, path) {
|
|
4896
5050
|
const resolve2 = (input, seen = /* @__PURE__ */ new Set()) => {
|
|
4897
5051
|
const node = unwrapExpression(input);
|
|
4898
5052
|
if (node.type !== "Identifier") return node;
|
|
4899
5053
|
if (seen.has(node)) return null;
|
|
4900
5054
|
seen.add(node);
|
|
4901
|
-
const binding =
|
|
5055
|
+
const binding = ASTUtils10.findVariable(sourceCode.getScope(node), node.name);
|
|
4902
5056
|
const definition = binding?.defs.length === 1 ? binding.defs[0] : void 0;
|
|
4903
5057
|
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init === null || binding?.references.some((reference) => reference.identifier !== node && reference.init !== true)) return null;
|
|
4904
5058
|
return resolve2(definition.node.init, seen);
|
|
@@ -4908,7 +5062,7 @@ function exportedNextConfigProperty(sourceCode, path) {
|
|
|
4908
5062
|
let current = resolve2(exported);
|
|
4909
5063
|
let selected = null;
|
|
4910
5064
|
for (const name of path) {
|
|
4911
|
-
if (current?.type !== "ObjectExpression" || current.properties.some((property) => property.type !== "Property" ||
|
|
5065
|
+
if (current?.type !== "ObjectExpression" || current.properties.some((property) => property.type !== "Property" || ASTUtils10.getPropertyName(property) === null || property.kind !== "init")) return null;
|
|
4912
5066
|
selected = objectProperty(current, name);
|
|
4913
5067
|
if (selected === null) return null;
|
|
4914
5068
|
current = resolve2(selected.value);
|
|
@@ -4923,7 +5077,7 @@ function exportedConfig(sourceCode) {
|
|
|
4923
5077
|
const assignment = statement.expression;
|
|
4924
5078
|
const left = assignment.left;
|
|
4925
5079
|
if (left.type !== "MemberExpression" || left.computed || left.object.type !== "Identifier" || left.object.name !== "module" || left.property.type !== "Identifier" || left.property.name !== "exports") continue;
|
|
4926
|
-
const binding =
|
|
5080
|
+
const binding = ASTUtils10.findVariable(sourceCode.getScope(left.object), "module");
|
|
4927
5081
|
if (binding === null || binding.defs.length === 0) exported = assignment.right;
|
|
4928
5082
|
}
|
|
4929
5083
|
return exported;
|
|
@@ -4932,7 +5086,7 @@ function objectProperty(node, name) {
|
|
|
4932
5086
|
let selected = null;
|
|
4933
5087
|
for (const property of node.properties) {
|
|
4934
5088
|
if (property.type !== "Property") continue;
|
|
4935
|
-
const key =
|
|
5089
|
+
const key = ASTUtils10.getPropertyName(property);
|
|
4936
5090
|
if (key === name) selected = property;
|
|
4937
5091
|
}
|
|
4938
5092
|
return selected;
|
|
@@ -5014,7 +5168,7 @@ var no_dangerously_allow_svg_default = createRule({
|
|
|
5014
5168
|
});
|
|
5015
5169
|
|
|
5016
5170
|
// src/rules/no-dynamic-sql.ts
|
|
5017
|
-
import { ASTUtils as
|
|
5171
|
+
import { ASTUtils as ASTUtils11, AST_NODE_TYPES as AST_NODE_TYPES30 } from "@typescript-eslint/utils";
|
|
5018
5172
|
|
|
5019
5173
|
// src/rules/_sql.ts
|
|
5020
5174
|
import { AST_NODE_TYPES as AST_NODE_TYPES29 } from "@typescript-eslint/utils";
|
|
@@ -5253,8 +5407,8 @@ function isStaticFragment(expression) {
|
|
|
5253
5407
|
if (expression.type === AST_NODE_TYPES30.Identifier) {
|
|
5254
5408
|
return CONSTANT_CASE_RE.test(expression.name);
|
|
5255
5409
|
}
|
|
5256
|
-
if (expression.type === AST_NODE_TYPES30.MemberExpression &&
|
|
5257
|
-
return CONSTANT_CASE_RE.test(
|
|
5410
|
+
if (expression.type === AST_NODE_TYPES30.MemberExpression && ASTUtils11.getPropertyName(expression) !== null) {
|
|
5411
|
+
return CONSTANT_CASE_RE.test(ASTUtils11.getPropertyName(expression) ?? "");
|
|
5258
5412
|
}
|
|
5259
5413
|
if (expression.type === AST_NODE_TYPES30.Literal) {
|
|
5260
5414
|
return typeof expression.value === "string";
|
|
@@ -5353,10 +5507,10 @@ function staticStatementText(node) {
|
|
|
5353
5507
|
}
|
|
5354
5508
|
function statementMethodName(node, methods) {
|
|
5355
5509
|
const callee = unwrapExpression(node.callee);
|
|
5356
|
-
if (callee.type !== AST_NODE_TYPES30.MemberExpression ||
|
|
5510
|
+
if (callee.type !== AST_NODE_TYPES30.MemberExpression || ASTUtils11.getPropertyName(callee) === null) {
|
|
5357
5511
|
return null;
|
|
5358
5512
|
}
|
|
5359
|
-
const name =
|
|
5513
|
+
const name = ASTUtils11.getPropertyName(callee) ?? "";
|
|
5360
5514
|
return methods.has(name) ? name : null;
|
|
5361
5515
|
}
|
|
5362
5516
|
var no_dynamic_sql_default = createRule({
|
|
@@ -6074,7 +6228,7 @@ var no_fat_try_blocks_default = createRule({
|
|
|
6074
6228
|
});
|
|
6075
6229
|
|
|
6076
6230
|
// src/rules/no-hand-rolled-sleep.ts
|
|
6077
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES33, ASTUtils as
|
|
6231
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES33, ASTUtils as ASTUtils12 } from "@typescript-eslint/utils";
|
|
6078
6232
|
var NO_HAND_ROLLED_SLEEP_DOCUMENTATION = {
|
|
6079
6233
|
summary: "Disallow uncancellable promisified timers and timeout arms.",
|
|
6080
6234
|
rationale: "A timer that outlives an aborted operation or a lost promise race retains work and can keep the process alive until it fires.",
|
|
@@ -6234,7 +6388,7 @@ var no_hand_rolled_sleep_default = createRule({
|
|
|
6234
6388
|
return {};
|
|
6235
6389
|
}
|
|
6236
6390
|
const checkClientModules = optionsArg?.checkClientModules ?? false;
|
|
6237
|
-
const bindingOf = (identifier) =>
|
|
6391
|
+
const bindingOf = (identifier) => ASTUtils12.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
6238
6392
|
const isGlobal = (identifier) => (bindingOf(identifier)?.defs.length ?? 0) === 0;
|
|
6239
6393
|
const isBuiltinTimer = (callee) => {
|
|
6240
6394
|
callee = unwrapExpression(callee);
|
|
@@ -6401,7 +6555,7 @@ var no_hand_rolled_spinner_default = createRule({
|
|
|
6401
6555
|
});
|
|
6402
6556
|
|
|
6403
6557
|
// src/rules/no-insecure-random-id.ts
|
|
6404
|
-
import { ASTUtils as
|
|
6558
|
+
import { ASTUtils as ASTUtils13 } from "@typescript-eslint/utils";
|
|
6405
6559
|
var NO_INSECURE_RANDOM_ID_DOCUMENTATION = {
|
|
6406
6560
|
summary: "Disallow using `Math.random()` to generate identifiers, tokens, or secrets; use `crypto.randomUUID()` or `crypto.getRandomValues(...)` instead.",
|
|
6407
6561
|
rationale: "Math.random is predictable and lacks the entropy required for security-sensitive values.",
|
|
@@ -6476,7 +6630,7 @@ function isMathRandomCall(node) {
|
|
|
6476
6630
|
return false;
|
|
6477
6631
|
}
|
|
6478
6632
|
const object = unwrapExpression(callee.object);
|
|
6479
|
-
return object.type === "Identifier" && object.name === "Math" &&
|
|
6633
|
+
return object.type === "Identifier" && object.name === "Math" && ASTUtils13.getPropertyName(callee) === "random";
|
|
6480
6634
|
}
|
|
6481
6635
|
function findEnclosingNames(node) {
|
|
6482
6636
|
const names = [];
|
|
@@ -6541,7 +6695,7 @@ function climbValueChain(node) {
|
|
|
6541
6695
|
let current = node;
|
|
6542
6696
|
let parent = current.parent;
|
|
6543
6697
|
while (parent) {
|
|
6544
|
-
if (parent.type === "MemberExpression" && parent.object === current &&
|
|
6698
|
+
if (parent.type === "MemberExpression" && parent.object === current && ASTUtils13.getPropertyName(parent) !== null) {
|
|
6545
6699
|
current = parent;
|
|
6546
6700
|
parent = current.parent;
|
|
6547
6701
|
continue;
|
|
@@ -6594,7 +6748,7 @@ var no_insecure_random_id_default = createRule({
|
|
|
6594
6748
|
if (!isMathRandomCall(node)) {
|
|
6595
6749
|
return;
|
|
6596
6750
|
}
|
|
6597
|
-
if ((
|
|
6751
|
+
if ((ASTUtils13.findVariable(context.sourceCode.getScope(node), "Math")?.defs.length ?? 0) > 0) return;
|
|
6598
6752
|
const names = findEnclosingNames(node);
|
|
6599
6753
|
if (names.some(isStrongSecurityName)) {
|
|
6600
6754
|
context.report({ node, messageId: "insecureRandomId" });
|
|
@@ -6617,8 +6771,8 @@ function appendPropertyName(property, names) {
|
|
|
6617
6771
|
}
|
|
6618
6772
|
function appendAssignedName(assignment, directBinding, names) {
|
|
6619
6773
|
if (directBinding && assignment.left.type === "Identifier") names.push(assignment.left.name);
|
|
6620
|
-
if (directBinding && assignment.left.type === "MemberExpression" &&
|
|
6621
|
-
names.push(
|
|
6774
|
+
if (directBinding && assignment.left.type === "MemberExpression" && ASTUtils13.getPropertyName(assignment.left) !== null) {
|
|
6775
|
+
names.push(ASTUtils13.getPropertyName(assignment.left) ?? "");
|
|
6622
6776
|
}
|
|
6623
6777
|
}
|
|
6624
6778
|
function appendDirectBindingName(id, directBinding, names) {
|
|
@@ -6628,7 +6782,7 @@ function appendDirectBindingName(id, directBinding, names) {
|
|
|
6628
6782
|
// src/rules/no-detached-global-fetch.ts
|
|
6629
6783
|
import {
|
|
6630
6784
|
AST_NODE_TYPES as AST_NODE_TYPES35,
|
|
6631
|
-
ASTUtils as
|
|
6785
|
+
ASTUtils as ASTUtils14
|
|
6632
6786
|
} from "@typescript-eslint/utils";
|
|
6633
6787
|
var NO_DETACHED_GLOBAL_FETCH_DOCUMENTATION = {
|
|
6634
6788
|
summary: "Keep the ambient global fetch receiver-safe when storing or explicitly rebinding it.",
|
|
@@ -6689,7 +6843,7 @@ var no_detached_global_fetch_default = createRule({
|
|
|
6689
6843
|
if (isTestFile(context.filename) || isScriptFile(context.filename) || isGeneratedFile(context.filename, sourceCode.text)) return {};
|
|
6690
6844
|
const aliases = /* @__PURE__ */ new Set();
|
|
6691
6845
|
function bindingOf(identifier) {
|
|
6692
|
-
return
|
|
6846
|
+
return ASTUtils14.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
6693
6847
|
}
|
|
6694
6848
|
function resolvesToGlobal(identifier) {
|
|
6695
6849
|
const variable = bindingOf(identifier);
|
|
@@ -6794,37 +6948,32 @@ var no_detached_global_fetch_default = createRule({
|
|
|
6794
6948
|
});
|
|
6795
6949
|
|
|
6796
6950
|
// src/rules/no-json-stringify-error.ts
|
|
6797
|
-
import { ASTUtils as
|
|
6951
|
+
import { ASTUtils as ASTUtils15 } from "@typescript-eslint/utils";
|
|
6798
6952
|
var NO_JSON_STRINGIFY_ERROR_DOCUMENTATION = {
|
|
6799
6953
|
summary: "Avoid generic JSON serialization that can omit native Error details.",
|
|
6800
6954
|
rationale: "Native Error details are non-enumerable, so generic JSON serialization discards diagnostic information.",
|
|
6801
6955
|
remediation: "Serialize explicit error fields or use an error-aware serializer.",
|
|
6802
6956
|
category: "correctness",
|
|
6803
|
-
limitations: ["The rule uses stable local catch bindings and unshadowed built-in constructors, not runtime type information. Custom replacers are left to their serializer contract; a catch value is not guaranteed to be an Error."],
|
|
6957
|
+
limitations: ["The rule uses stable local catch bindings and unshadowed built-in constructors, not runtime type information. Custom replacers and explicit toJSON hooks are left to their serializer contract; a catch value is not guaranteed to be an Error. Member values, including cause, do not inherit the base Error's provenance; even an Error-valued member requires explicit value/dataflow proof outside this rule. Known literal __proto__ initializer chains preserve native hook inheritance and own toJSON precedence; computed __proto__ keys remain data. Unknown prototype expressions, hook values/spreads and deferred hook writes conservatively lose default serializer proof. Explicit writes invalidate constructor provenance except a later, separate top-level statement; deferred functions, loops, and unknown property keys conservatively lose constructor proof. Statically owned global/property writes and native Reflect.set/Reflect.defineProperty/Object.defineProperty/Object.defineProperties calls are tracked. Mutator aliases, replaced Reflect/Object methods, external calls, and runtime-only property names are not resolved; uncertain ordering conservatively loses proof."],
|
|
6804
6958
|
examples: [
|
|
6805
6959
|
{ id: "explicit-error-message", title: "Narrow an unknown catch value before selecting fields", outcome: "no-match", files: [{ path: "src/report.ts", source: "try { f(); } catch (err) { JSON.stringify({ error: err instanceof Error ? err.message : String(err) }); }" }], focusPath: "src/report.ts", expectedCount: 0, public: true },
|
|
6806
6960
|
{ id: "stringified-error", title: "Do not stringify an Error object", outcome: "match", files: [{ path: "src/report.ts", source: "try { f(); } catch (err) { JSON.stringify({ error: err }); }" }], focusPath: "src/report.ts", expectedCount: 1, public: true },
|
|
6807
6961
|
{ id: "shadowed-error-binding", scenarioId: "binding-provenance", title: "Keep native binding provenance", outcome: "match", files: [{ path: "src/error.ts", source: 'function probe(){try{throw {id:1};}catch(err){if(err instanceof Error)return err.message;{const err=new Error("lost");return JSON.stringify(err);}}}\nconsole.log(probe());' }], focusPath: "src/error.ts", expectedCount: 1, public: true },
|
|
6808
|
-
{ id: "escaped-fallback-binding", scenarioId: "binding-provenance", title: "Keep native binding provenance", outcome: "no-match", files: [{ path: "src/error.ts", source: "function probe(){try{throw {id:1};}catch(err){if(err instanceof Error)return err.message;return JSON.stringify(\\u0065rr);}}\nconsole.log(probe());" }], focusPath: "src/error.ts", expectedCount: 0, public: true }
|
|
6962
|
+
{ id: "escaped-fallback-binding", scenarioId: "binding-provenance", title: "Keep native binding provenance", outcome: "no-match", files: [{ path: "src/error.ts", source: "function probe(){try{throw {id:1};}catch(err){if(err instanceof Error)return err.message;return JSON.stringify(\\u0065rr);}}\nconsole.log(probe());" }], focusPath: "src/error.ts", expectedCount: 0, public: true },
|
|
6963
|
+
{ id: "constructor-before-write", scenarioId: "explicit-constructor-write", title: "A later write does not change an already constructed native Error", outcome: "match", files: [{ path: "src/error.js", source: "const value=new Error('lost');Error=class Other{message='kept'};JSON.stringify(value);" }], focusPath: "src/error.js", expectedCount: 1, public: true },
|
|
6964
|
+
{ id: "constructor-after-write", scenarioId: "explicit-constructor-write", title: "A replaced constructor does not prove a native Error", outcome: "no-match", files: [{ path: "src/error.js", source: "Error=class Other{message='kept'};const value=new Error();JSON.stringify(value);" }], focusPath: "src/error.js", expectedCount: 0, public: true },
|
|
6965
|
+
{ "id": "native-serializer-before-write", "scenarioId": "explicit-serializer-write", "title": "A later write does not change an earlier native serialization", "outcome": "match", "files": [{ "path": "src/error.js", "source": "const result=JSON.stringify(new Error('lost'));JSON.stringify=value=>'kept:'+value.message;" }], "focusPath": "src/error.js", "expectedCount": 1, "public": true },
|
|
6966
|
+
{ "id": "native-serializer-after-write", "scenarioId": "explicit-serializer-write", "title": "A replaced serializer owns its error-field contract", "outcome": "no-match", "files": [{ "path": "src/error.js", "source": "JSON.stringify=value=>'kept:'+value.message;JSON.stringify(new Error('lost'));" }], "focusPath": "src/error.js", "expectedCount": 0, "public": true },
|
|
6967
|
+
{ "id": "static-serializer-key", "scenarioId": "static-property-provenance", "title": "A constant computed serializer still loses native Error details", "outcome": "match", "files": [{ "path": "src/error.js", "source": "const key='stringify';JSON[key](new Error('lost'));" }], "focusPath": "src/error.js", "expectedCount": 1, "public": true },
|
|
6968
|
+
{ "id": "static-error-field", "scenarioId": "static-property-provenance", "title": "A constant message field selects the explicit string escape hatch", "outcome": "no-match", "files": [{ "path": "src/error.js", "source": "const key='message';const error=new Error('lost');JSON.stringify(error[key]);" }], "focusPath": "src/error.js", "expectedCount": 0, "public": true },
|
|
6969
|
+
{ "id": "scalar-cause", "scenarioId": "member-value-provenance", "title": "Native Error cause can be a string value", "outcome": "no-match", "files": [{ "path": "src/error.js", "source": "const error=new Error('lost',{cause:'kept'});JSON.stringify(error.cause);" }], "focusPath": "src/error.js", "expectedCount": 0, "public": true },
|
|
6970
|
+
{ "id": "whole-error-with-cause", "scenarioId": "member-value-provenance", "title": "Serializing the whole Error still loses its native details", "outcome": "match", "files": [{ "path": "src/error.js", "source": "const error=new Error('lost',{cause:'kept'});JSON.stringify(error);" }], "focusPath": "src/error.js", "expectedCount": 1, "public": true },
|
|
6971
|
+
{ "id": "explicit-to-json-hook", "scenarioId": "custom-serializer-contract", "title": "An explicit callable toJSON owns its serialization contract", "outcome": "no-match", "files": [{ "path": "src/error.js", "source": "JSON.stringify({error:new Error('lost'),toJSON(){return {message:'kept'};}});" }], "focusPath": "src/error.js", "expectedCount": 0, "public": true },
|
|
6972
|
+
{ "id": "noncallable-to-json", "scenarioId": "custom-serializer-contract", "title": "A noncallable toJSON does not replace native serialization", "outcome": "match", "files": [{ "path": "src/error.js", "source": "JSON.stringify({error:new Error('lost'),toJSON:42});" }], "focusPath": "src/error.js", "expectedCount": 1, "public": true },
|
|
6973
|
+
{ "id": "literal-prototype-hook", "scenarioId": "native-prototype-serializer", "title": "A literal prototype hook owns the payload serializer contract", "outcome": "no-match", "files": [{ "path": "src/error.js", "source": "JSON.stringify({error:new Error('lost'),__proto__:{toJSON(){return {message:'kept'};}}});" }], "focusPath": "src/error.js", "expectedCount": 0, "public": true },
|
|
6974
|
+
{ "id": "computed-prototype-data", "scenarioId": "native-prototype-serializer", "title": "A computed prototype name remains ordinary serialized data", "outcome": "match", "files": [{ "path": "src/error.js", "source": "JSON.stringify({error:new Error('lost'),['__proto__']:{toJSON(){return {message:'kept'};}}});" }], "focusPath": "src/error.js", "expectedCount": 1, "public": true }
|
|
6809
6975
|
]
|
|
6810
6976
|
};
|
|
6811
|
-
var SAFE_STRING_PROPS = /* @__PURE__ */ new Set(["message", "stack", "name"]);
|
|
6812
|
-
var PAYLOAD_PROPS = /* @__PURE__ */ new Set([
|
|
6813
|
-
"data",
|
|
6814
|
-
"status",
|
|
6815
|
-
"statuscode",
|
|
6816
|
-
"statustext",
|
|
6817
|
-
"code",
|
|
6818
|
-
"issues",
|
|
6819
|
-
"details",
|
|
6820
|
-
"body",
|
|
6821
|
-
"payload",
|
|
6822
|
-
"response",
|
|
6823
|
-
"info",
|
|
6824
|
-
"meta",
|
|
6825
|
-
"metadata",
|
|
6826
|
-
"context"
|
|
6827
|
-
]);
|
|
6828
6977
|
var BUILTIN_ERROR_CONSTRUCTORS = /* @__PURE__ */ new Set([
|
|
6829
6978
|
"AggregateError",
|
|
6830
6979
|
"Error",
|
|
@@ -6835,17 +6984,203 @@ var BUILTIN_ERROR_CONSTRUCTORS = /* @__PURE__ */ new Set([
|
|
|
6835
6984
|
"TypeError",
|
|
6836
6985
|
"URIError"
|
|
6837
6986
|
]);
|
|
6838
|
-
|
|
6839
|
-
|
|
6840
|
-
|
|
6841
|
-
const
|
|
6842
|
-
if (
|
|
6843
|
-
if (
|
|
6844
|
-
|
|
6845
|
-
|
|
6987
|
+
var TRACKED_BUILTINS = /* @__PURE__ */ new Set([...BUILTIN_ERROR_CONSTRUCTORS, "JSON", "JSON.stringify"]);
|
|
6988
|
+
function nativeObjectName(expression, sourceCode) {
|
|
6989
|
+
const value = unwrapExpression(expression);
|
|
6990
|
+
const scope = sourceCode.getScope(value);
|
|
6991
|
+
if (value.type === "Identifier" && (value.name === "globalThis" || value.name === "JSON") && isGlobalIdentifier(value.name, scope)) return value.name;
|
|
6992
|
+
if (value.type === "MemberExpression" && nativeObjectName(value.object, sourceCode) === "globalThis" && staticPropertyName(value, sourceCode) === "JSON") return "JSON";
|
|
6993
|
+
return null;
|
|
6994
|
+
}
|
|
6995
|
+
function globalBuiltinName(expression, sourceCode) {
|
|
6996
|
+
const value = unwrapExpression(expression);
|
|
6997
|
+
const scope = sourceCode.getScope(value);
|
|
6998
|
+
if (value.type === "Identifier") return TRACKED_BUILTINS.has(value.name) && isGlobalIdentifier(value.name, scope) ? value.name : null;
|
|
6999
|
+
if (value.type !== "MemberExpression") return null;
|
|
7000
|
+
const receiver = nativeObjectName(value.object, sourceCode);
|
|
7001
|
+
const name = staticPropertyName(value, sourceCode);
|
|
7002
|
+
if (receiver === "JSON") return name === "stringify" ? "JSON.stringify" : null;
|
|
7003
|
+
return receiver === "globalThis" && name !== null && name !== "JSON.stringify" && TRACKED_BUILTINS.has(name) ? name : null;
|
|
7004
|
+
}
|
|
7005
|
+
function writePreservesBuiltin(target, sourceCode) {
|
|
7006
|
+
const assignment = target.parent;
|
|
7007
|
+
if (assignment?.type !== "AssignmentExpression" || assignment.left !== target) return false;
|
|
7008
|
+
const name = globalBuiltinName(target, sourceCode);
|
|
7009
|
+
if (name === null) return false;
|
|
7010
|
+
if (assignment.operator === "||=" || assignment.operator === "??=") return true;
|
|
7011
|
+
return (assignment.operator === "=" || assignment.operator === "&&=") && globalBuiltinName(assignment.right, sourceCode) === name;
|
|
7012
|
+
}
|
|
7013
|
+
function mayBeCallable(value) {
|
|
7014
|
+
return !["Literal", "TemplateLiteral", "ObjectExpression", "ArrayExpression"].includes(value.type);
|
|
7015
|
+
}
|
|
7016
|
+
var BUILTIN_WRITES = /* @__PURE__ */ new WeakMap();
|
|
7017
|
+
function directProgramStatement(node) {
|
|
7018
|
+
let current = node;
|
|
7019
|
+
while (current.parent !== void 0) {
|
|
7020
|
+
if (current.parent.type === "Program") return current;
|
|
7021
|
+
if (["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression", "ClassBody", "StaticBlock", "ForStatement", "ForInStatement", "ForOfStatement", "WhileStatement", "DoWhileStatement"].includes(current.parent.type)) return null;
|
|
7022
|
+
current = current.parent;
|
|
7023
|
+
}
|
|
7024
|
+
return null;
|
|
7025
|
+
}
|
|
7026
|
+
function hasUnchangedBuiltin(name, read, sourceCode) {
|
|
7027
|
+
const summary = builtinWrites(sourceCode).get(name);
|
|
7028
|
+
if (summary === void 0) return true;
|
|
7029
|
+
const statement = directProgramStatement(read);
|
|
7030
|
+
return !summary.unknownOrder && statement !== null && statement.range[1] <= summary.earliestStatementStart;
|
|
7031
|
+
}
|
|
7032
|
+
function builtinWrites(sourceCode) {
|
|
7033
|
+
const cached = BUILTIN_WRITES.get(sourceCode);
|
|
7034
|
+
if (cached !== void 0) return cached;
|
|
7035
|
+
const writes = /* @__PURE__ */ new Map();
|
|
7036
|
+
const record = (name, node) => {
|
|
7037
|
+
const statement = directProgramStatement(node);
|
|
7038
|
+
const existing = writes.get(name);
|
|
7039
|
+
writes.set(name, { earliestStatementStart: Math.min(existing?.earliestStatementStart ?? Infinity, statement?.range[0] ?? Infinity), unknownOrder: (existing?.unknownOrder ?? false) || statement === null });
|
|
7040
|
+
};
|
|
7041
|
+
for (const scope of sourceCode.scopeManager?.scopes ?? []) {
|
|
7042
|
+
for (const reference of scope.references) {
|
|
7043
|
+
const name = reference.identifier.name;
|
|
7044
|
+
if (reference.identifier.type === "Identifier" && reference.isWrite() && TRACKED_BUILTINS.has(name) && (reference.resolved === null || reference.resolved.defs.length === 0) && !writePreservesBuiltin(reference.identifier, sourceCode)) record(name, reference.identifier);
|
|
7045
|
+
}
|
|
7046
|
+
}
|
|
7047
|
+
const propertyReceiver = (expression) => {
|
|
7048
|
+
const native = nativeObjectName(expression, sourceCode);
|
|
7049
|
+
if (native !== null) return native;
|
|
7050
|
+
const value = unwrapExpression(expression);
|
|
7051
|
+
if (value.type === "Identifier") return ASTUtils15.findVariable(sourceCode.getScope(value), value.name);
|
|
7052
|
+
if (value.type === "MemberExpression" && staticPropertyName(value, sourceCode) === "prototype") {
|
|
7053
|
+
const constructor = globalBuiltinName(value.object, sourceCode);
|
|
7054
|
+
if (constructor !== null && BUILTIN_ERROR_CONSTRUCTORS.has(constructor)) return constructor + ".prototype";
|
|
7055
|
+
}
|
|
7056
|
+
return null;
|
|
7057
|
+
};
|
|
7058
|
+
const propertyWrite = (receiver, name, node) => {
|
|
7059
|
+
if (receiver === "JSON") {
|
|
7060
|
+
if (name === null || name === "stringify") record("JSON.stringify", node);
|
|
7061
|
+
} else if (receiver === "globalThis") {
|
|
7062
|
+
if (name === null) {
|
|
7063
|
+
for (const builtin of TRACKED_BUILTINS) record(builtin, node);
|
|
7064
|
+
} else if (name !== "JSON.stringify" && TRACKED_BUILTINS.has(name)) record(name, node);
|
|
7065
|
+
} else if (name === null || name === "toJSON") record(receiver, node);
|
|
7066
|
+
};
|
|
7067
|
+
const visit = (node) => {
|
|
7068
|
+
if (node.type === "AssignmentExpression") propertyTarget(node.left);
|
|
7069
|
+
else if (node.type === "UpdateExpression") propertyTarget(node.argument);
|
|
7070
|
+
else if (node.type === "ForInStatement" || node.type === "ForOfStatement") propertyTarget(node.left);
|
|
7071
|
+
else if (node.type === "UnaryExpression" && node.operator === "delete") propertyTarget(node.argument);
|
|
7072
|
+
else if (node.type === "CallExpression") mutationCall(node);
|
|
7073
|
+
forEachAstChild(node, sourceCode.visitorKeys, visit);
|
|
7074
|
+
};
|
|
7075
|
+
function propertyTarget(target) {
|
|
7076
|
+
if (target.type === "MemberExpression") {
|
|
7077
|
+
memberPropertyWrite(target);
|
|
7078
|
+
return;
|
|
7079
|
+
}
|
|
7080
|
+
switch (target.type) {
|
|
7081
|
+
case "ObjectPattern":
|
|
7082
|
+
for (const property of target.properties) propertyTarget(property.type === "RestElement" ? property.argument : property.value);
|
|
7083
|
+
return;
|
|
7084
|
+
case "ArrayPattern":
|
|
7085
|
+
for (const element of target.elements) if (element !== null) propertyTarget(element);
|
|
7086
|
+
return;
|
|
7087
|
+
case "AssignmentPattern":
|
|
7088
|
+
propertyTarget(target.left);
|
|
7089
|
+
return;
|
|
7090
|
+
case "RestElement":
|
|
7091
|
+
propertyTarget(target.argument);
|
|
7092
|
+
}
|
|
7093
|
+
}
|
|
7094
|
+
function memberPropertyWrite(target) {
|
|
7095
|
+
const receiver = propertyReceiver(target.object);
|
|
7096
|
+
if (receiver === null || writePreservesBuiltin(target, sourceCode)) return;
|
|
7097
|
+
const name = staticPropertyName(target, sourceCode);
|
|
7098
|
+
if (name === "toJSON") {
|
|
7099
|
+
const assignment = target.parent;
|
|
7100
|
+
if (assignment?.type === "UnaryExpression" && assignment.operator === "delete") return;
|
|
7101
|
+
if (assignment?.type === "AssignmentExpression" && assignment.operator === "=" && !mayBeCallable(assignment.right)) return;
|
|
7102
|
+
}
|
|
7103
|
+
propertyWrite(receiver, name, target);
|
|
7104
|
+
}
|
|
7105
|
+
function mutationCall(node) {
|
|
7106
|
+
const callee = unwrapExpression(node.callee);
|
|
7107
|
+
if (callee.type !== "MemberExpression" || callee.object.type !== "Identifier") return;
|
|
7108
|
+
const owner = callee.object.name;
|
|
7109
|
+
if (!["Reflect", "Object"].includes(owner) || !isGlobalIdentifier(owner, sourceCode.getScope(callee))) return;
|
|
7110
|
+
const method = staticPropertyName(callee, sourceCode);
|
|
7111
|
+
const [target, key, value, receiver] = node.arguments;
|
|
7112
|
+
if (target === void 0 || target.type === "SpreadElement" || key === void 0) return;
|
|
7113
|
+
const object = propertyReceiver(target);
|
|
7114
|
+
if (object === null) return;
|
|
7115
|
+
switch (method) {
|
|
7116
|
+
case "set":
|
|
7117
|
+
if (owner === "Reflect") reflectSet(object, scopedStaticString(key, sourceCode), value, receiver, node);
|
|
7118
|
+
return;
|
|
7119
|
+
case "defineProperty":
|
|
7120
|
+
descriptorWrite(object, scopedStaticString(key, sourceCode), value, node);
|
|
7121
|
+
return;
|
|
7122
|
+
case "defineProperties":
|
|
7123
|
+
if (owner === "Object") descriptorBatch(object, key, node);
|
|
7124
|
+
}
|
|
7125
|
+
}
|
|
7126
|
+
function reflectSet(object, name, value, receiver, node) {
|
|
7127
|
+
if (receiver !== void 0 && receiver.type !== "SpreadElement" && ["ObjectExpression", "ArrayExpression", "Literal"].includes(unwrapExpression(receiver).type)) return;
|
|
7128
|
+
const builtin = builtinPropertyName(object, name);
|
|
7129
|
+
if (value !== void 0 && value.type !== "SpreadElement" && builtin !== null && globalBuiltinName(value, sourceCode) === builtin) return;
|
|
7130
|
+
if (name === "toJSON" && value !== void 0 && !mayBeCallable(value)) return;
|
|
7131
|
+
propertyWrite(object, name, node);
|
|
7132
|
+
}
|
|
7133
|
+
function descriptorBatch(object, descriptors, node) {
|
|
7134
|
+
if (descriptors.type !== "ObjectExpression") {
|
|
7135
|
+
propertyWrite(object, null, node);
|
|
7136
|
+
return;
|
|
7137
|
+
}
|
|
7138
|
+
for (const property of descriptors.properties) {
|
|
7139
|
+
if (property.type !== "Property") {
|
|
7140
|
+
propertyWrite(object, null, node);
|
|
7141
|
+
continue;
|
|
7142
|
+
}
|
|
7143
|
+
descriptorWrite(object, staticPropertyName(property, sourceCode), property.value, node);
|
|
7144
|
+
}
|
|
7145
|
+
}
|
|
7146
|
+
function descriptorWrite(object, name, descriptor, node) {
|
|
7147
|
+
if (descriptor !== void 0 && !descriptorChangesValue(descriptor, builtinPropertyName(object, name))) return;
|
|
7148
|
+
propertyWrite(object, name, node);
|
|
7149
|
+
}
|
|
7150
|
+
function descriptorChangesValue(descriptor, name) {
|
|
7151
|
+
if (descriptor.type !== "ObjectExpression") return true;
|
|
7152
|
+
return descriptor.properties.some((property) => {
|
|
7153
|
+
if (property.type !== "Property") return true;
|
|
7154
|
+
const key = staticPropertyName(property, sourceCode);
|
|
7155
|
+
if (key === "value" && name === "toJSON" && !mayBeCallable(property.value)) return false;
|
|
7156
|
+
if (key === "value" && property.value.type !== "AssignmentPattern" && property.value.type !== "ArrayPattern" && property.value.type !== "ObjectPattern" && property.value.type !== "TSEmptyBodyFunctionExpression") return name === null || globalBuiltinName(property.value, sourceCode) !== name;
|
|
7157
|
+
return key === null || key === "get" || key === "set";
|
|
7158
|
+
});
|
|
7159
|
+
}
|
|
7160
|
+
function builtinPropertyName(object, name) {
|
|
7161
|
+
return object === "JSON" && name === "stringify" ? "JSON.stringify" : name;
|
|
7162
|
+
}
|
|
7163
|
+
visit(sourceCode.ast);
|
|
7164
|
+
BUILTIN_WRITES.set(sourceCode, writes);
|
|
7165
|
+
return writes;
|
|
7166
|
+
}
|
|
7167
|
+
function hasDefaultErrorSerialization(expression, call, sourceCode) {
|
|
7168
|
+
let constructor = null;
|
|
7169
|
+
if (expression.type === "Identifier") {
|
|
7170
|
+
const variable = ASTUtils15.findVariable(sourceCode.getScope(expression), expression.name);
|
|
7171
|
+
if (variable !== null && !hasUnchangedBuiltin(variable, call, sourceCode)) return false;
|
|
7172
|
+
const definition = variable?.defs[0];
|
|
7173
|
+
const initializer = definition?.type === "Variable" ? definition.node.init : null;
|
|
7174
|
+
if (initializer?.type === "NewExpression" && initializer.callee.type === "Identifier") constructor = initializer.callee.name;
|
|
7175
|
+
} else if (expression.type === "NewExpression" && expression.callee.type === "Identifier") constructor = expression.callee.name;
|
|
7176
|
+
const families = constructor === null ? BUILTIN_ERROR_CONSTRUCTORS : ["Error", constructor];
|
|
7177
|
+
return [...families].every((name) => hasUnchangedBuiltin(name + ".prototype", call, sourceCode));
|
|
7178
|
+
}
|
|
7179
|
+
function isBuiltinErrorConstructor(identifier, sourceCode) {
|
|
7180
|
+
return sourceCode.scopeManager !== null && BUILTIN_ERROR_CONSTRUCTORS.has(identifier.name) && isGlobalIdentifier(identifier.name, sourceCode.getScope(identifier)) && hasUnchangedBuiltin(identifier.name, identifier, sourceCode);
|
|
6846
7181
|
}
|
|
6847
7182
|
function isGlobalIdentifier(name, scope) {
|
|
6848
|
-
const binding =
|
|
7183
|
+
const binding = ASTUtils15.findVariable(scope, name);
|
|
6849
7184
|
return binding === null || binding.defs.length === 0;
|
|
6850
7185
|
}
|
|
6851
7186
|
function positiveErrorSubject(test, sourceCode) {
|
|
@@ -6853,7 +7188,7 @@ function positiveErrorSubject(test, sourceCode) {
|
|
|
6853
7188
|
}
|
|
6854
7189
|
var TYPE_GUARD_PATTERN = /^(is|has)[A-Z]/;
|
|
6855
7190
|
function instanceofErrorSubject(test, sourceCode) {
|
|
6856
|
-
if (test.type === "BinaryExpression" && test.operator === "instanceof" && test.right.type === "Identifier" && test.right.name === "Error" &&
|
|
7191
|
+
if (test.type === "BinaryExpression" && test.operator === "instanceof" && test.right.type === "Identifier" && test.right.name === "Error" && isBuiltinErrorConstructor(test.right, sourceCode)) {
|
|
6857
7192
|
return test.left;
|
|
6858
7193
|
}
|
|
6859
7194
|
return null;
|
|
@@ -6913,24 +7248,25 @@ function sameSubjectBinding(subject, value, sourceCode) {
|
|
|
6913
7248
|
const left = unwrapExpression(subject);
|
|
6914
7249
|
const right = unwrapExpression(value);
|
|
6915
7250
|
if (left.type === "Identifier" && right.type === "Identifier") {
|
|
6916
|
-
const binding =
|
|
6917
|
-
return binding !== null && binding ===
|
|
7251
|
+
const binding = ASTUtils15.findVariable(sourceCode.getScope(left), left.name);
|
|
7252
|
+
return binding !== null && binding === ASTUtils15.findVariable(sourceCode.getScope(right), right.name);
|
|
6918
7253
|
}
|
|
6919
7254
|
return sourceCode.getText(subject) === sourceCode.getText(value);
|
|
6920
7255
|
}
|
|
6921
7256
|
function nodeWithin(node, container) {
|
|
6922
7257
|
return container !== null && node.range[0] >= container.range[0] && node.range[1] <= container.range[1];
|
|
6923
7258
|
}
|
|
6924
|
-
function isJsonStringify(callee) {
|
|
7259
|
+
function isJsonStringify(callee, sourceCode) {
|
|
6925
7260
|
if (callee.type !== "MemberExpression") return false;
|
|
6926
7261
|
const receiver = unwrapExpression(callee.object);
|
|
6927
|
-
return callee.type === "MemberExpression" && receiver.type === "Identifier" && receiver.name === "JSON" &&
|
|
7262
|
+
return callee.type === "MemberExpression" && receiver.type === "Identifier" && receiver.name === "JSON" && staticPropertyName(callee, sourceCode) === "stringify";
|
|
6928
7263
|
}
|
|
6929
|
-
function directLiteralValues(argument) {
|
|
7264
|
+
function directLiteralValues(argument, sourceCode) {
|
|
6930
7265
|
argument = unwrapExpression(argument);
|
|
6931
7266
|
if (argument.type === "ObjectExpression") {
|
|
7267
|
+
if (literalHasSerializer(argument, sourceCode)) return [];
|
|
6932
7268
|
return argument.properties.flatMap((property) => {
|
|
6933
|
-
if (property.type !== "Property" ||
|
|
7269
|
+
if (property.type !== "Property" || staticPropertyName(property, sourceCode) === null) return [];
|
|
6934
7270
|
const value = property.value;
|
|
6935
7271
|
if (value.type === "AssignmentPattern" || value.type === "ArrayPattern" || value.type === "ObjectPattern" || value.type === "TSEmptyBodyFunctionExpression") {
|
|
6936
7272
|
return [];
|
|
@@ -6945,6 +7281,20 @@ function directLiteralValues(argument) {
|
|
|
6945
7281
|
}
|
|
6946
7282
|
return argument.type === "SpreadElement" ? [] : [argument];
|
|
6947
7283
|
}
|
|
7284
|
+
function literalHasSerializer(argument, sourceCode) {
|
|
7285
|
+
for (const property of argument.properties.toReversed()) {
|
|
7286
|
+
if (property.type !== "Property") return true;
|
|
7287
|
+
const key = staticPropertyName(property, sourceCode);
|
|
7288
|
+
if (key === null) return true;
|
|
7289
|
+
if (key === "toJSON") return mayBeCallable(property.value);
|
|
7290
|
+
}
|
|
7291
|
+
for (const property of argument.properties) {
|
|
7292
|
+
if (property.type !== "Property" || property.computed || property.method || property.shorthand || property.kind !== "init" || staticPropertyName(property, sourceCode) !== "__proto__") continue;
|
|
7293
|
+
const prototype = property.value;
|
|
7294
|
+
return prototype.type === "ObjectExpression" ? literalHasSerializer(prototype, sourceCode) : prototype.type !== "Literal" || "regex" in prototype && prototype.regex !== void 0;
|
|
7295
|
+
}
|
|
7296
|
+
return false;
|
|
7297
|
+
}
|
|
6948
7298
|
function expressionSuggestsError(expression, sourceCode) {
|
|
6949
7299
|
expression = unwrapExpression(expression);
|
|
6950
7300
|
const unwrappedExpressionCallee = expression.type === "CallExpression" || expression.type === "NewExpression" ? unwrapExpression(expression.callee) : null;
|
|
@@ -6952,23 +7302,19 @@ function expressionSuggestsError(expression, sourceCode) {
|
|
|
6952
7302
|
return identifierIsProvenError(expression, sourceCode);
|
|
6953
7303
|
}
|
|
6954
7304
|
if (expression.type === "NewExpression" && unwrappedExpressionCallee?.type === "Identifier") {
|
|
6955
|
-
return
|
|
6956
|
-
}
|
|
6957
|
-
return expression.type === "MemberExpression" && memberSuggestsError(expression, sourceCode);
|
|
6958
|
-
}
|
|
6959
|
-
function memberSuggestsError(member, sourceCode) {
|
|
6960
|
-
const propName2 = ASTUtils14.getPropertyName(member);
|
|
6961
|
-
const base = member.object;
|
|
6962
|
-
const baseSuggestsError = base.type === "Identifier" && identifierIsProvenError(base, sourceCode);
|
|
6963
|
-
if (baseSuggestsError) {
|
|
6964
|
-
if (propName2 === null) {
|
|
6965
|
-
return true;
|
|
6966
|
-
}
|
|
6967
|
-
const lowered = propName2.toLowerCase();
|
|
6968
|
-
return !SAFE_STRING_PROPS.has(lowered) && !PAYLOAD_PROPS.has(lowered);
|
|
7305
|
+
return isBuiltinErrorConstructor(unwrappedExpressionCallee, sourceCode);
|
|
6969
7306
|
}
|
|
6970
7307
|
return false;
|
|
6971
7308
|
}
|
|
7309
|
+
function identifierIsProvenError(identifier, sourceCode) {
|
|
7310
|
+
const variable = ASTUtils15.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
7311
|
+
if (variable === null || variable.defs.length !== 1 || variable.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
7312
|
+
const definition = variable.defs[0];
|
|
7313
|
+
if (definition?.type === "CatchClause") return true;
|
|
7314
|
+
if (definition?.type !== "Variable") return false;
|
|
7315
|
+
const initializer = definition.node.init;
|
|
7316
|
+
return initializer?.type === "NewExpression" && initializer.callee.type === "Identifier" && isBuiltinErrorConstructor(initializer.callee, sourceCode);
|
|
7317
|
+
}
|
|
6972
7318
|
var no_json_stringify_error_default = createRule({
|
|
6973
7319
|
name: "no-json-stringify-error",
|
|
6974
7320
|
documentation: NO_JSON_STRINGIFY_ERROR_DOCUMENTATION,
|
|
@@ -6987,7 +7333,7 @@ var no_json_stringify_error_default = createRule({
|
|
|
6987
7333
|
return {
|
|
6988
7334
|
CallExpression(node) {
|
|
6989
7335
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
6990
|
-
if (!isJsonStringify(unwrappedNodeCallee)) {
|
|
7336
|
+
if (!isJsonStringify(unwrappedNodeCallee, context.sourceCode)) {
|
|
6991
7337
|
return;
|
|
6992
7338
|
}
|
|
6993
7339
|
const firstArg = node.arguments[0];
|
|
@@ -6995,11 +7341,11 @@ var no_json_stringify_error_default = createRule({
|
|
|
6995
7341
|
return;
|
|
6996
7342
|
}
|
|
6997
7343
|
const scope = context.sourceCode.getScope(firstArg);
|
|
6998
|
-
if (!isGlobalIdentifier("JSON", scope)) return;
|
|
7344
|
+
if (!isGlobalIdentifier("JSON", scope) || !hasUnchangedBuiltin("JSON", node, context.sourceCode) || !hasUnchangedBuiltin("JSON.stringify", node, context.sourceCode)) return;
|
|
6999
7345
|
const replacer = node.arguments[1] === void 0 ? void 0 : unwrapExpression(node.arguments[1]);
|
|
7000
7346
|
if (replacer !== void 0 && !(replacer.type === "Literal" && replacer.value === null) && !(replacer.type === "Identifier" && replacer.name === "undefined" && isGlobalIdentifier("undefined", scope))) return;
|
|
7001
|
-
const unsafeValue = directLiteralValues(firstArg).find(
|
|
7002
|
-
(value) => expressionSuggestsError(value, context.sourceCode) && !isGuardedByInstanceofError(node, value, context.sourceCode) && !isNarrowedByEarlyReturn(node, value, context.sourceCode)
|
|
7347
|
+
const unsafeValue = directLiteralValues(firstArg, context.sourceCode).find(
|
|
7348
|
+
(value) => expressionSuggestsError(value, context.sourceCode) && hasDefaultErrorSerialization(unwrapExpression(value), node, context.sourceCode) && !isGuardedByInstanceofError(node, value, context.sourceCode) && !isNarrowedByEarlyReturn(node, value, context.sourceCode)
|
|
7003
7349
|
);
|
|
7004
7350
|
if (unsafeValue === void 0) {
|
|
7005
7351
|
return;
|
|
@@ -7035,7 +7381,7 @@ function branchTerminates(branch) {
|
|
|
7035
7381
|
// src/rules/no-json-stringify-object-equality.ts
|
|
7036
7382
|
import {
|
|
7037
7383
|
AST_NODE_TYPES as AST_NODE_TYPES36,
|
|
7038
|
-
ASTUtils as
|
|
7384
|
+
ASTUtils as ASTUtils16,
|
|
7039
7385
|
ESLintUtils as ESLintUtils7
|
|
7040
7386
|
} from "@typescript-eslint/utils";
|
|
7041
7387
|
import ts6 from "typescript";
|
|
@@ -7086,10 +7432,10 @@ function jsonStringifyArgument(node, sourceCode) {
|
|
|
7086
7432
|
if (expression.type !== AST_NODE_TYPES36.CallExpression) return null;
|
|
7087
7433
|
const callee = unwrapExpression(expression.callee);
|
|
7088
7434
|
const calleeReceiver = callee.type === AST_NODE_TYPES36.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
7089
|
-
if (callee.type !== AST_NODE_TYPES36.MemberExpression || calleeReceiver.type !== AST_NODE_TYPES36.Identifier || calleeReceiver.name !== "JSON" ||
|
|
7435
|
+
if (callee.type !== AST_NODE_TYPES36.MemberExpression || calleeReceiver.type !== AST_NODE_TYPES36.Identifier || calleeReceiver.name !== "JSON" || ASTUtils16.getPropertyName(callee) !== "stringify") {
|
|
7090
7436
|
return null;
|
|
7091
7437
|
}
|
|
7092
|
-
const variable =
|
|
7438
|
+
const variable = ASTUtils16.findVariable(sourceCode.getScope(calleeReceiver), "JSON");
|
|
7093
7439
|
if (variable !== null && variable.defs.length > 0) return null;
|
|
7094
7440
|
const argument = expression.arguments[0];
|
|
7095
7441
|
return argument !== void 0 && argument.type !== AST_NODE_TYPES36.SpreadElement ? argument : null;
|
|
@@ -7175,7 +7521,7 @@ var no_json_stringify_object_equality_default = createRule({
|
|
|
7175
7521
|
|
|
7176
7522
|
// src/rules/no-impossible-zod-literal-bounds.ts
|
|
7177
7523
|
import {
|
|
7178
|
-
ASTUtils as
|
|
7524
|
+
ASTUtils as ASTUtils17,
|
|
7179
7525
|
AST_NODE_TYPES as AST_NODE_TYPES37
|
|
7180
7526
|
} from "@typescript-eslint/utils";
|
|
7181
7527
|
|
|
@@ -7327,7 +7673,7 @@ var no_impossible_zod_literal_bounds_default = createRule({
|
|
|
7327
7673
|
if (callee.type !== AST_NODE_TYPES37.MemberExpression || calleeReceiver.type !== AST_NODE_TYPES37.CallExpression) {
|
|
7328
7674
|
return null;
|
|
7329
7675
|
}
|
|
7330
|
-
const method =
|
|
7676
|
+
const method = ASTUtils17.getPropertyName(callee);
|
|
7331
7677
|
if (method === null) return null;
|
|
7332
7678
|
calls.push({ method, node: current });
|
|
7333
7679
|
current = calleeReceiver;
|
|
@@ -7342,7 +7688,7 @@ var no_impossible_zod_literal_bounds_default = createRule({
|
|
|
7342
7688
|
if (callee.type !== AST_NODE_TYPES37.MemberExpression || calleeReceiver.type !== AST_NODE_TYPES37.Identifier || !namespaces.has(calleeReceiver.name) || !resolvesToTrackedImport(calleeReceiver)) {
|
|
7343
7689
|
return null;
|
|
7344
7690
|
}
|
|
7345
|
-
const name =
|
|
7691
|
+
const name = ASTUtils17.getPropertyName(callee);
|
|
7346
7692
|
return name !== null && KINDS.has(name) ? name : null;
|
|
7347
7693
|
}
|
|
7348
7694
|
function isInsideReshapingCall(node) {
|
|
@@ -7352,7 +7698,7 @@ var no_impossible_zod_literal_bounds_default = createRule({
|
|
|
7352
7698
|
if (parent.type === AST_NODE_TYPES37.CallExpression) {
|
|
7353
7699
|
const callee = unwrapExpression(parent.callee);
|
|
7354
7700
|
const calleeReceiver = callee.type === AST_NODE_TYPES37.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
7355
|
-
if (callee.type === AST_NODE_TYPES37.MemberExpression && RESHAPING_METHODS.has(
|
|
7701
|
+
if (callee.type === AST_NODE_TYPES37.MemberExpression && RESHAPING_METHODS.has(ASTUtils17.getPropertyName(callee) ?? "") && (calleeReceiver.type === AST_NODE_TYPES37.CallExpression || calleeReceiver.type === AST_NODE_TYPES37.Identifier && namespaces.has(calleeReceiver.name) && resolvesToTrackedImport(calleeReceiver))) {
|
|
7356
7702
|
return true;
|
|
7357
7703
|
}
|
|
7358
7704
|
if (callee.type === AST_NODE_TYPES37.Identifier && preprocessors.has(callee.name) && resolvesToTrackedImport(callee)) {
|
|
@@ -7563,7 +7909,7 @@ var no_in_operator_on_built_in_collections_default = createRule({
|
|
|
7563
7909
|
|
|
7564
7910
|
// src/rules/no-redundant-optional-array-default.ts
|
|
7565
7911
|
import {
|
|
7566
|
-
ASTUtils as
|
|
7912
|
+
ASTUtils as ASTUtils18,
|
|
7567
7913
|
AST_NODE_TYPES as AST_NODE_TYPES38
|
|
7568
7914
|
} from "@typescript-eslint/utils";
|
|
7569
7915
|
var NO_REDUNDANT_OPTIONAL_ARRAY_DEFAULT_DOCUMENTATION = {
|
|
@@ -7701,7 +8047,7 @@ var no_redundant_optional_array_default_default = createRule({
|
|
|
7701
8047
|
return arrayConstructors.has(callee.name) && resolvesToTrackedImport(callee);
|
|
7702
8048
|
}
|
|
7703
8049
|
if (callee.type !== AST_NODE_TYPES38.MemberExpression) return false;
|
|
7704
|
-
const method =
|
|
8050
|
+
const method = ASTUtils18.getPropertyName(callee);
|
|
7705
8051
|
if (method === "array" && (calleeReceiver.type === AST_NODE_TYPES38.Identifier ? namespaces.has(calleeReceiver.name) && resolvesToTrackedImport(calleeReceiver) : isZodSchemaExpression(calleeReceiver))) {
|
|
7706
8052
|
return true;
|
|
7707
8053
|
}
|
|
@@ -7744,13 +8090,13 @@ var no_redundant_optional_array_default_default = createRule({
|
|
|
7744
8090
|
CallExpression(node) {
|
|
7745
8091
|
const defaultCallee = unwrapExpression(node.callee);
|
|
7746
8092
|
const defaultCalleeReceiver = defaultCallee.type === AST_NODE_TYPES38.MemberExpression ? unwrapExpression(defaultCallee.object) : defaultCallee;
|
|
7747
|
-
if (defaultCallee.type !== AST_NODE_TYPES38.MemberExpression ||
|
|
8093
|
+
if (defaultCallee.type !== AST_NODE_TYPES38.MemberExpression || ASTUtils18.getPropertyName(defaultCallee) !== "default" || !hasArrayFallback(node) || defaultCalleeReceiver.type !== AST_NODE_TYPES38.CallExpression) {
|
|
7748
8094
|
return;
|
|
7749
8095
|
}
|
|
7750
8096
|
const optionalCall = defaultCalleeReceiver;
|
|
7751
8097
|
const optionalCallee = unwrapExpression(optionalCall.callee);
|
|
7752
8098
|
const optionalCalleeReceiver = optionalCallee.type === AST_NODE_TYPES38.MemberExpression ? unwrapExpression(optionalCallee.object) : optionalCallee;
|
|
7753
|
-
if (optionalCallee.type !== AST_NODE_TYPES38.MemberExpression ||
|
|
8099
|
+
if (optionalCallee.type !== AST_NODE_TYPES38.MemberExpression || ASTUtils18.getPropertyName(optionalCallee) !== "optional" || optionalCall.arguments.length !== 0 || !isArraySchemaExpression(optionalCalleeReceiver) || sourceCode.getCommentsInside(optionalCall).length > 0) {
|
|
7754
8100
|
return;
|
|
7755
8101
|
}
|
|
7756
8102
|
context.report({
|
|
@@ -7889,10 +8235,10 @@ var interface_contract_members_private_default = createRule({
|
|
|
7889
8235
|
});
|
|
7890
8236
|
|
|
7891
8237
|
// src/rules/no-log-only-catch.ts
|
|
7892
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES42, ASTUtils as
|
|
8238
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES42, ASTUtils as ASTUtils20 } from "@typescript-eslint/utils";
|
|
7893
8239
|
|
|
7894
8240
|
// src/rules/_logging.ts
|
|
7895
|
-
import { ASTUtils as
|
|
8241
|
+
import { ASTUtils as ASTUtils19, AST_NODE_TYPES as AST_NODE_TYPES41 } from "@typescript-eslint/utils";
|
|
7896
8242
|
var LOG_METHODS = /* @__PURE__ */ new Set([
|
|
7897
8243
|
"debug",
|
|
7898
8244
|
"info",
|
|
@@ -7929,7 +8275,7 @@ function calleeName2(callee) {
|
|
|
7929
8275
|
if (callee.type === "Identifier") {
|
|
7930
8276
|
return callee.name;
|
|
7931
8277
|
}
|
|
7932
|
-
return callee.type === "MemberExpression" ?
|
|
8278
|
+
return callee.type === "MemberExpression" ? ASTUtils19.getPropertyName(callee) : null;
|
|
7933
8279
|
}
|
|
7934
8280
|
function createLogMatcher(options = {}) {
|
|
7935
8281
|
const loggerNames = /* @__PURE__ */ new Set([
|
|
@@ -7944,7 +8290,7 @@ function createLogMatcher(options = {}) {
|
|
|
7944
8290
|
return loggerNames.has(expr.name.toLowerCase());
|
|
7945
8291
|
case "MemberExpression": {
|
|
7946
8292
|
const { object } = expr;
|
|
7947
|
-
const property =
|
|
8293
|
+
const property = ASTUtils19.getPropertyName(expr);
|
|
7948
8294
|
if (property !== null) {
|
|
7949
8295
|
const lowered = property.toLowerCase();
|
|
7950
8296
|
if (loggerNames.has(lowered) || LOGGER_FACTORIES.has(lowered)) {
|
|
@@ -7955,7 +8301,7 @@ function createLogMatcher(options = {}) {
|
|
|
7955
8301
|
}
|
|
7956
8302
|
case "CallExpression": {
|
|
7957
8303
|
const callee = unwrapExpression(expr.callee);
|
|
7958
|
-
const name = callee.type === "MemberExpression" ?
|
|
8304
|
+
const name = callee.type === "MemberExpression" ? ASTUtils19.getPropertyName(callee) : null;
|
|
7959
8305
|
if (name !== null && LOGGER_FACTORIES.has(name.toLowerCase())) {
|
|
7960
8306
|
return true;
|
|
7961
8307
|
}
|
|
@@ -7986,7 +8332,7 @@ function createLogMatcher(options = {}) {
|
|
|
7986
8332
|
const callee = unwrapExpression(expr.callee);
|
|
7987
8333
|
const calleeReceiver = callee.type === AST_NODE_TYPES41.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
7988
8334
|
if (callee.type !== "MemberExpression") return false;
|
|
7989
|
-
const name =
|
|
8335
|
+
const name = ASTUtils19.getPropertyName(callee);
|
|
7990
8336
|
return name !== null && LOG_METHODS.has(name.toLowerCase()) && isLoggerReceiver(calleeReceiver);
|
|
7991
8337
|
}
|
|
7992
8338
|
return { isLoggerReceiver, isLogFunctionCall, isLoggingCall };
|
|
@@ -8060,7 +8406,7 @@ function seededFallbackHandled(tryStatement, scope) {
|
|
|
8060
8406
|
if (previous.declarations.length !== 1 || declarator === void 0) return false;
|
|
8061
8407
|
if (declarator.id.type !== AST_NODE_TYPES42.Identifier) return false;
|
|
8062
8408
|
if (declarator.init == null || !isSeedValue(declarator.init)) return false;
|
|
8063
|
-
const variable =
|
|
8409
|
+
const variable = ASTUtils20.findVariable(scope, declarator.id.name);
|
|
8064
8410
|
if (variable === null) return false;
|
|
8065
8411
|
const [tryStart, tryEnd] = tryStatement.block.range;
|
|
8066
8412
|
let writtenInTry = false;
|
|
@@ -8122,9 +8468,9 @@ var no_log_only_catch_default = createRule({
|
|
|
8122
8468
|
if (left.type !== AST_NODE_TYPES42.MemberExpression || left.computed || left.object.type !== AST_NODE_TYPES42.Identifier || right.type !== AST_NODE_TYPES42.CallExpression || right.optional || right.callee.type !== AST_NODE_TYPES42.Identifier || !["String", "Number", "Boolean", "BigInt"].includes(right.callee.name) || right.arguments.length !== 1) return false;
|
|
8123
8469
|
const argument = right.arguments[0];
|
|
8124
8470
|
if (argument === void 0 || sourceCode.getText(left) !== sourceCode.getText(argument)) return false;
|
|
8125
|
-
const global =
|
|
8471
|
+
const global = ASTUtils20.findVariable(sourceCode.getScope(right.callee), right.callee.name);
|
|
8126
8472
|
if (global !== null && global.defs.length > 0) return false;
|
|
8127
|
-
const root =
|
|
8473
|
+
const root = ASTUtils20.findVariable(sourceCode.getScope(left.object), left.object.name);
|
|
8128
8474
|
if (root === null || root.references.some((reference) => reference.isWrite() && !reference.init)) return false;
|
|
8129
8475
|
return hasFollowingCoercionCheck(owner, left, right.callee.name);
|
|
8130
8476
|
}
|
|
@@ -8195,7 +8541,7 @@ var no_log_only_catch_default = createRule({
|
|
|
8195
8541
|
});
|
|
8196
8542
|
|
|
8197
8543
|
// src/rules/no-bare-return-from-test-catch.ts
|
|
8198
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES43, ASTUtils as
|
|
8544
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES43, ASTUtils as ASTUtils21 } from "@typescript-eslint/utils";
|
|
8199
8545
|
var NO_BARE_RETURN_FROM_TEST_CATCH_DOCUMENTATION = {
|
|
8200
8546
|
summary: "Disallow a bare return from a test catch block when it skips a later assertion.",
|
|
8201
8547
|
rationale: "An unasserted catch return can swallow a failure and skip later assertions; the complete test result also depends on other assertions and hooks.",
|
|
@@ -8292,7 +8638,7 @@ var no_bare_return_from_test_catch_default = createRule({
|
|
|
8292
8638
|
const parameter = catchClause.param;
|
|
8293
8639
|
const returnBlock = node.parent;
|
|
8294
8640
|
if (parameter?.type === AST_NODE_TYPES43.Identifier && returnBlock?.type === AST_NODE_TYPES43.BlockStatement) {
|
|
8295
|
-
const errorBinding =
|
|
8641
|
+
const errorBinding = ASTUtils21.findVariable(context.sourceCode.getScope(parameter), parameter.name);
|
|
8296
8642
|
const assertedError = returnBlock.body.some((statement) => {
|
|
8297
8643
|
if (statement.range[1] >= node.range[0] || statement.type !== AST_NODE_TYPES43.ExpressionStatement) return false;
|
|
8298
8644
|
const expression = statement.expression;
|
|
@@ -8316,7 +8662,7 @@ var no_bare_return_from_test_catch_default = createRule({
|
|
|
8316
8662
|
});
|
|
8317
8663
|
|
|
8318
8664
|
// src/rules/no-bespoke-api-case-conversion.ts
|
|
8319
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES44, ASTUtils as
|
|
8665
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES44, ASTUtils as ASTUtils22 } from "@typescript-eslint/utils";
|
|
8320
8666
|
var NO_BESPOKE_API_CASE_CONVERSION_DOCUMENTATION = {
|
|
8321
8667
|
defaultLevel: "warning",
|
|
8322
8668
|
summary: "Review direct snake_case/camelCase mirror mappings on explicitly API-typed adapter values.",
|
|
@@ -8369,10 +8715,10 @@ function propertyName(node) {
|
|
|
8369
8715
|
}
|
|
8370
8716
|
function memberName3(node) {
|
|
8371
8717
|
const current = unwrapExpression(node);
|
|
8372
|
-
if (current.type !== AST_NODE_TYPES44.MemberExpression ||
|
|
8718
|
+
if (current.type !== AST_NODE_TYPES44.MemberExpression || ASTUtils22.getPropertyName(current) === null) {
|
|
8373
8719
|
return null;
|
|
8374
8720
|
}
|
|
8375
|
-
return
|
|
8721
|
+
return ASTUtils22.getPropertyName(current) ?? "";
|
|
8376
8722
|
}
|
|
8377
8723
|
function isDirectCaseTranslation(left, right) {
|
|
8378
8724
|
if (SNAKE_CASE_RE2.test(left) && LOWER_CAMEL_CASE_RE.test(right)) {
|
|
@@ -8412,7 +8758,7 @@ var no_bespoke_api_case_conversion_default = createRule({
|
|
|
8412
8758
|
else break;
|
|
8413
8759
|
}
|
|
8414
8760
|
if (current.type !== AST_NODE_TYPES44.Identifier) return false;
|
|
8415
|
-
const binding =
|
|
8761
|
+
const binding = ASTUtils22.findVariable(context.sourceCode.getScope(current), current.name);
|
|
8416
8762
|
if (binding?.defs.length !== 1 || binding.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
8417
8763
|
const identifier = binding.defs[0]?.name;
|
|
8418
8764
|
if (identifier?.type !== AST_NODE_TYPES44.Identifier) return false;
|
|
@@ -8421,7 +8767,7 @@ var no_bespoke_api_case_conversion_default = createRule({
|
|
|
8421
8767
|
let typeName = annotation.typeName;
|
|
8422
8768
|
while (typeName.type === AST_NODE_TYPES44.TSQualifiedName) typeName = typeName.left;
|
|
8423
8769
|
if (typeName.type !== AST_NODE_TYPES44.Identifier) return false;
|
|
8424
|
-
const typeBinding =
|
|
8770
|
+
const typeBinding = ASTUtils22.findVariable(context.sourceCode.getScope(typeName), typeName.name);
|
|
8425
8771
|
return typeBinding?.defs.length === 1 && typeBinding.defs[0]?.type === "ImportBinding" && typeBinding.defs[0].parent.type === AST_NODE_TYPES44.ImportDeclaration && API_BOUNDARY_IMPORT_RE.test(typeBinding.defs[0].parent.source.value);
|
|
8426
8772
|
};
|
|
8427
8773
|
return {
|
|
@@ -8626,7 +8972,7 @@ var no_vague_suppression_description_default = createRule({
|
|
|
8626
8972
|
});
|
|
8627
8973
|
|
|
8628
8974
|
// src/rules/_runtime-exports.ts
|
|
8629
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES46, ASTUtils as
|
|
8975
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES46, ASTUtils as ASTUtils23 } from "@typescript-eslint/utils";
|
|
8630
8976
|
var GENERIC_MODULE_STEMS = /* @__PURE__ */ new Set([
|
|
8631
8977
|
"common",
|
|
8632
8978
|
"helper",
|
|
@@ -8748,7 +9094,7 @@ function namespaceEmission(declaration) {
|
|
|
8748
9094
|
}
|
|
8749
9095
|
function isCommonJsExportReference(node, sourceCode) {
|
|
8750
9096
|
function isGlobal(node2) {
|
|
8751
|
-
const variable =
|
|
9097
|
+
const variable = ASTUtils23.findVariable(sourceCode.getScope(node2), node2.name);
|
|
8752
9098
|
return variable === null || variable.defs.length === 0;
|
|
8753
9099
|
}
|
|
8754
9100
|
if (node.type === AST_NODE_TYPES46.MemberExpression) {
|
|
@@ -8871,7 +9217,7 @@ var no_offset_pagination_default = createRule({
|
|
|
8871
9217
|
});
|
|
8872
9218
|
|
|
8873
9219
|
// src/rules/no-positional-tuple-return.ts
|
|
8874
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES47, ASTUtils as
|
|
9220
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES47, ASTUtils as ASTUtils24 } from "@typescript-eslint/utils";
|
|
8875
9221
|
var NO_POSITIONAL_TUPLE_RETURN_DOCUMENTATION = {
|
|
8876
9222
|
summary: "Disallow returning a multi-field tuple from a named function; return a named object so call sites cannot mismatch slots.",
|
|
8877
9223
|
rationale: "Tuple fields are identified only by position, so reordering can preserve types while changing meaning.",
|
|
@@ -9005,7 +9351,7 @@ function typeAliases(sourceCode) {
|
|
|
9005
9351
|
get(identifier) {
|
|
9006
9352
|
const declaration = aliases.get(identifier.name);
|
|
9007
9353
|
if (declaration === void 0) return void 0;
|
|
9008
|
-
const binding =
|
|
9354
|
+
const binding = ASTUtils24.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
9009
9355
|
return binding?.defs.length === 1 && binding.defs[0]?.node === declaration ? declaration.typeAnnotation : void 0;
|
|
9010
9356
|
}
|
|
9011
9357
|
};
|
|
@@ -9316,7 +9662,7 @@ var no_production_browser_source_maps_default = createRule({
|
|
|
9316
9662
|
});
|
|
9317
9663
|
|
|
9318
9664
|
// src/rules/no-raw-env.ts
|
|
9319
|
-
import { ASTUtils as
|
|
9665
|
+
import { ASTUtils as ASTUtils25, AST_NODE_TYPES as AST_NODE_TYPES48 } from "@typescript-eslint/utils";
|
|
9320
9666
|
var NO_RAW_ENV_DOCUMENTATION = {
|
|
9321
9667
|
summary: "Disallow direct `process.env` and `import.meta.env` reads outside validated boundaries.",
|
|
9322
9668
|
rationale: "Raw environment reads are untyped and defer invalid configuration failures until use.",
|
|
@@ -9332,15 +9678,15 @@ var CONFIG_FILE_RE = /(^|[\\/])[\w.-]+\.config\.[cm]?[jt]sx?$/;
|
|
|
9332
9678
|
var ENV_BOUNDARY_FILE_RE = /(^|[\\/])(?:env|client-env|server-env|client-settings|server-settings)\.[cm]?[jt]sx?$/;
|
|
9333
9679
|
function isProcessEnv(node, context) {
|
|
9334
9680
|
const receiver = unwrapExpression(node.object);
|
|
9335
|
-
if (receiver.type !== "Identifier" ||
|
|
9336
|
-
const binding =
|
|
9681
|
+
if (receiver.type !== "Identifier" || ASTUtils25.getPropertyName(node) !== "env") return false;
|
|
9682
|
+
const binding = ASTUtils25.findVariable(context.sourceCode.getScope(receiver), receiver.name);
|
|
9337
9683
|
if (binding === null || binding.defs.length === 0) return receiver.name === "process";
|
|
9338
9684
|
return binding.defs.every(
|
|
9339
9685
|
(definition) => definition.type === "ImportBinding" && definition.parent.type === "ImportDeclaration" && definition.parent.importKind !== "type" && ["node:process", "process"].includes(definition.parent.source.value) && ["ImportDefaultSpecifier", "ImportNamespaceSpecifier"].includes(definition.node.type)
|
|
9340
9686
|
);
|
|
9341
9687
|
}
|
|
9342
9688
|
function isImportMetaEnv(node) {
|
|
9343
|
-
return
|
|
9689
|
+
return ASTUtils25.getPropertyName(node) === "env" && node.object.type === "MetaProperty" && node.object.meta.name === "import" && node.object.property.name === "meta";
|
|
9344
9690
|
}
|
|
9345
9691
|
var BUILD_TIME_CONSTANTS = /* @__PURE__ */ new Set([
|
|
9346
9692
|
"NODE_ENV",
|
|
@@ -9358,7 +9704,7 @@ var PLATFORM_MARKERS = /* @__PURE__ */ new Set([
|
|
|
9358
9704
|
function isExemptVariableAccess(node) {
|
|
9359
9705
|
const parent = node.parent;
|
|
9360
9706
|
if (parent.type !== "MemberExpression" || parent.object !== node) return false;
|
|
9361
|
-
const name =
|
|
9707
|
+
const name = ASTUtils25.getPropertyName(parent);
|
|
9362
9708
|
return name !== null && (BUILD_TIME_CONSTANTS.has(name) || PLATFORM_MARKERS.has(name));
|
|
9363
9709
|
}
|
|
9364
9710
|
function isWriteTarget(node) {
|
|
@@ -9406,7 +9752,7 @@ var no_raw_env_default = createRule({
|
|
|
9406
9752
|
if (callee.type === "Identifier" && callee.name === "createEnv") {
|
|
9407
9753
|
hasValidationCall = true;
|
|
9408
9754
|
} else if (callee.type === "MemberExpression") {
|
|
9409
|
-
const name =
|
|
9755
|
+
const name = ASTUtils25.getPropertyName(callee);
|
|
9410
9756
|
if (name === "parse" || name === "safeParse" || name === "object" && calleeReceiver.type === "Identifier" && calleeReceiver.name === "z") {
|
|
9411
9757
|
hasValidationCall = true;
|
|
9412
9758
|
}
|
|
@@ -9426,7 +9772,7 @@ var no_raw_env_default = createRule({
|
|
|
9426
9772
|
});
|
|
9427
9773
|
|
|
9428
9774
|
// src/rules/no-raw-fetch-outside-clients.ts
|
|
9429
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES49, ASTUtils as
|
|
9775
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES49, ASTUtils as ASTUtils26 } from "@typescript-eslint/utils";
|
|
9430
9776
|
var NO_RAW_FETCH_OUTSIDE_CLIENTS_DOCUMENTATION = {
|
|
9431
9777
|
summary: "Disallow calling the global `fetch` outside the client layer; route outbound HTTP through a client module that owns retry, timeout and status handling.",
|
|
9432
9778
|
rationale: "Scattered fetch calls bypass shared transport policy and are harder to stub and observe consistently.",
|
|
@@ -9615,7 +9961,7 @@ var no_raw_fetch_outside_clients_default = createRule({
|
|
|
9615
9961
|
internalApiPrefixes.push(`${options.basePath}/api`);
|
|
9616
9962
|
}
|
|
9617
9963
|
function resolvesToGlobal(identifier) {
|
|
9618
|
-
const variable =
|
|
9964
|
+
const variable = ASTUtils26.findVariable(
|
|
9619
9965
|
context.sourceCode.getScope(identifier),
|
|
9620
9966
|
identifier.name
|
|
9621
9967
|
);
|
|
@@ -9624,7 +9970,7 @@ var no_raw_fetch_outside_clients_default = createRule({
|
|
|
9624
9970
|
function resolveNode2(node) {
|
|
9625
9971
|
if (node === void 0) return null;
|
|
9626
9972
|
if (node.type !== AST_NODE_TYPES49.Identifier) return node;
|
|
9627
|
-
const variable =
|
|
9973
|
+
const variable = ASTUtils26.findVariable(
|
|
9628
9974
|
context.sourceCode.getScope(node),
|
|
9629
9975
|
node.name
|
|
9630
9976
|
);
|
|
@@ -9704,7 +10050,7 @@ var no_raw_fetch_outside_clients_default = createRule({
|
|
|
9704
10050
|
});
|
|
9705
10051
|
|
|
9706
10052
|
// src/rules/no-restricted-library-load.ts
|
|
9707
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES50, ASTUtils as
|
|
10053
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES50, ASTUtils as ASTUtils27 } from "@typescript-eslint/utils";
|
|
9708
10054
|
var NO_RESTRICTED_LIBRARY_LOAD_DOCUMENTATION = {
|
|
9709
10055
|
summary: "Apply configured library restrictions to literal runtime loads and CommonJS resolution references.",
|
|
9710
10056
|
rationale: "Dynamic imports, CommonJS loads, and package resolution checks can bypass library restrictions enforced for static imports.",
|
|
@@ -9790,7 +10136,7 @@ var no_restricted_library_load_default = createRule({
|
|
|
9790
10136
|
});
|
|
9791
10137
|
}
|
|
9792
10138
|
function isUnshadowedRequire(node) {
|
|
9793
|
-
const variable =
|
|
10139
|
+
const variable = ASTUtils27.findVariable(
|
|
9794
10140
|
context.sourceCode.getScope(node),
|
|
9795
10141
|
node.name
|
|
9796
10142
|
);
|
|
@@ -9824,7 +10170,7 @@ var no_restricted_library_load_default = createRule({
|
|
|
9824
10170
|
});
|
|
9825
10171
|
|
|
9826
10172
|
// src/rules/no-router-refresh-polling.ts
|
|
9827
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES51, ASTUtils as
|
|
10173
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES51, ASTUtils as ASTUtils28 } from "@typescript-eslint/utils";
|
|
9828
10174
|
var NO_ROUTER_REFRESH_POLLING_DOCUMENTATION = {
|
|
9829
10175
|
summary: "Do not poll by calling a Next.js router's refresh method from a timer.",
|
|
9830
10176
|
rationale: "A route refresh refetches and rerenders the whole route on every tick instead of loading the named resource that changed.",
|
|
@@ -9852,10 +10198,10 @@ function enclosingIntervalCallback(sourceCode, node) {
|
|
|
9852
10198
|
}
|
|
9853
10199
|
function isIntervalCallee(sourceCode, node) {
|
|
9854
10200
|
node = unwrapExpression(node);
|
|
9855
|
-
return node.type === AST_NODE_TYPES51.Identifier && node.name === "setInterval" && isUnshadowedGlobal2(sourceCode, node) || node.type === AST_NODE_TYPES51.MemberExpression && node.object.type === AST_NODE_TYPES51.Identifier && (node.object.name === "window" || node.object.name === "globalThis") && isUnshadowedGlobal2(sourceCode, node.object) &&
|
|
10201
|
+
return node.type === AST_NODE_TYPES51.Identifier && node.name === "setInterval" && isUnshadowedGlobal2(sourceCode, node) || node.type === AST_NODE_TYPES51.MemberExpression && node.object.type === AST_NODE_TYPES51.Identifier && (node.object.name === "window" || node.object.name === "globalThis") && isUnshadowedGlobal2(sourceCode, node.object) && ASTUtils28.getPropertyName(node) === "setInterval";
|
|
9856
10202
|
}
|
|
9857
10203
|
function isUnshadowedGlobal2(sourceCode, node) {
|
|
9858
|
-
const variable =
|
|
10204
|
+
const variable = ASTUtils28.findVariable(sourceCode.getScope(node), node.name);
|
|
9859
10205
|
return variable === null || variable.defs.length === 0;
|
|
9860
10206
|
}
|
|
9861
10207
|
var no_router_refresh_polling_default = createRule({
|
|
@@ -9878,7 +10224,7 @@ var no_router_refresh_polling_default = createRule({
|
|
|
9878
10224
|
if (node.source.value !== "next/navigation") return;
|
|
9879
10225
|
for (const specifier of node.specifiers) {
|
|
9880
10226
|
if (specifier.type === AST_NODE_TYPES51.ImportSpecifier && importedName4(specifier) === "useRouter") {
|
|
9881
|
-
const variable =
|
|
10227
|
+
const variable = ASTUtils28.findVariable(context.sourceCode.getScope(specifier.local), specifier.local.name);
|
|
9882
10228
|
if (variable !== null) routerHooks.add(variable);
|
|
9883
10229
|
}
|
|
9884
10230
|
}
|
|
@@ -9888,16 +10234,16 @@ var no_router_refresh_polling_default = createRule({
|
|
|
9888
10234
|
if (node.id.type === AST_NODE_TYPES51.Identifier && initializer?.type === AST_NODE_TYPES51.CallExpression) {
|
|
9889
10235
|
const hookCallee = unwrapExpression(initializer.callee);
|
|
9890
10236
|
if (hookCallee.type !== AST_NODE_TYPES51.Identifier) return;
|
|
9891
|
-
const hook =
|
|
9892
|
-
const router =
|
|
10237
|
+
const hook = ASTUtils28.findVariable(context.sourceCode.getScope(hookCallee), hookCallee.name);
|
|
10238
|
+
const router = ASTUtils28.findVariable(context.sourceCode.getScope(node.id), node.id.name);
|
|
9893
10239
|
if (hook !== null && router !== null && routerHooks.has(hook)) routers.add(router);
|
|
9894
10240
|
}
|
|
9895
10241
|
},
|
|
9896
10242
|
CallExpression(node) {
|
|
9897
10243
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
9898
10244
|
const receiver = unwrappedNodeCallee.type === AST_NODE_TYPES51.MemberExpression ? unwrapExpression(unwrappedNodeCallee.object) : unwrappedNodeCallee;
|
|
9899
|
-
if (unwrappedNodeCallee.type !== AST_NODE_TYPES51.MemberExpression || receiver.type !== AST_NODE_TYPES51.Identifier ||
|
|
9900
|
-
const router =
|
|
10245
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES51.MemberExpression || receiver.type !== AST_NODE_TYPES51.Identifier || ASTUtils28.getPropertyName(unwrappedNodeCallee) === null || (ASTUtils28.getPropertyName(unwrappedNodeCallee) ?? "") !== "refresh") return;
|
|
10246
|
+
const router = ASTUtils28.findVariable(
|
|
9901
10247
|
context.sourceCode.getScope(receiver),
|
|
9902
10248
|
receiver.name
|
|
9903
10249
|
);
|
|
@@ -10460,7 +10806,7 @@ function proseTokens(text) {
|
|
|
10460
10806
|
}
|
|
10461
10807
|
|
|
10462
10808
|
// src/rules/no-secret-in-log.ts
|
|
10463
|
-
import { ASTUtils as
|
|
10809
|
+
import { ASTUtils as ASTUtils29 } from "@typescript-eslint/utils";
|
|
10464
10810
|
|
|
10465
10811
|
// src/rules/_secret-names.ts
|
|
10466
10812
|
var SECRET_WORDS = /* @__PURE__ */ new Set([
|
|
@@ -10683,7 +11029,7 @@ function hasRedactionMarker(name) {
|
|
|
10683
11029
|
}
|
|
10684
11030
|
function valueName(node) {
|
|
10685
11031
|
if (node.type === "Identifier") return node.name;
|
|
10686
|
-
return node.type === "MemberExpression" ?
|
|
11032
|
+
return node.type === "MemberExpression" ? ASTUtils29.getPropertyName(node) : null;
|
|
10687
11033
|
}
|
|
10688
11034
|
function isRawSecretValue(prop) {
|
|
10689
11035
|
if (prop.shorthand) {
|
|
@@ -10734,11 +11080,11 @@ function rawBlobValueName(value) {
|
|
|
10734
11080
|
return isRawBlobName(value.name) ? value.name : null;
|
|
10735
11081
|
}
|
|
10736
11082
|
if (value.type === "MemberExpression") {
|
|
10737
|
-
const name =
|
|
11083
|
+
const name = ASTUtils29.getPropertyName(value);
|
|
10738
11084
|
return name !== null && isRawBlobName(name) ? name : null;
|
|
10739
11085
|
}
|
|
10740
11086
|
if (value.type === "CallExpression" && value.arguments.length === 0 && unwrappedValueCallee?.type === "MemberExpression" && unwrappedValueCallee.object.type === "Identifier" && /^(?:res|response|\w+Response)$/.test(unwrappedValueCallee.object.name)) {
|
|
10741
|
-
const name =
|
|
11087
|
+
const name = ASTUtils29.getPropertyName(unwrappedValueCallee);
|
|
10742
11088
|
return name === "json" || name === "text" ? `${unwrappedValueCallee.object.name}.${name}()` : null;
|
|
10743
11089
|
}
|
|
10744
11090
|
return null;
|
|
@@ -11046,7 +11392,7 @@ var no_select_star_default = createRule({
|
|
|
11046
11392
|
});
|
|
11047
11393
|
|
|
11048
11394
|
// src/rules/no-sentinel-return-on-catch.ts
|
|
11049
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES55, ASTUtils as
|
|
11395
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES55, ASTUtils as ASTUtils30 } from "@typescript-eslint/utils";
|
|
11050
11396
|
var NO_SENTINEL_RETURN_ON_CATCH_DOCUMENTATION = {
|
|
11051
11397
|
summary: "Disallow swallowing a caught error by returning an empty sentinel unless the error is handled or the sentinel is part of the function contract.",
|
|
11052
11398
|
rationale: "An unreported fallback makes operational failure indistinguishable from a legitimate empty result.",
|
|
@@ -11200,8 +11546,8 @@ function argsIncludeBinding(args, caughtName) {
|
|
|
11200
11546
|
}
|
|
11201
11547
|
function isParseShapedNode(node) {
|
|
11202
11548
|
const unwrappedNodeCallee = node.type === "CallExpression" || node.type === "NewExpression" ? unwrapExpression(node.callee) : null;
|
|
11203
|
-
if (node.type === AST_NODE_TYPES55.CallExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES55.MemberExpression &&
|
|
11204
|
-
return (
|
|
11549
|
+
if (node.type === AST_NODE_TYPES55.CallExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES55.MemberExpression && ASTUtils30.getPropertyName(unwrappedNodeCallee) !== null) {
|
|
11550
|
+
return (ASTUtils30.getPropertyName(unwrappedNodeCallee) ?? "") === "parse";
|
|
11205
11551
|
}
|
|
11206
11552
|
if (node.type === AST_NODE_TYPES55.NewExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES55.Identifier) {
|
|
11207
11553
|
return SAFE_PARSE_CONSTRUCTORS.has(unwrappedNodeCallee.name);
|
|
@@ -11215,21 +11561,21 @@ var SAFE_PARSE_CONSTRUCTORS = /* @__PURE__ */ new Set([
|
|
|
11215
11561
|
]);
|
|
11216
11562
|
function isBodyDecodeNode(node) {
|
|
11217
11563
|
const unwrappedNodeCallee = node.type === "CallExpression" || node.type === "NewExpression" ? unwrapExpression(node.callee) : null;
|
|
11218
|
-
return node.type === AST_NODE_TYPES55.CallExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES55.MemberExpression &&
|
|
11564
|
+
return node.type === AST_NODE_TYPES55.CallExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES55.MemberExpression && ASTUtils30.getPropertyName(unwrappedNodeCallee) !== null && BODY_DECODE_METHODS.has(ASTUtils30.getPropertyName(unwrappedNodeCallee) ?? "");
|
|
11219
11565
|
}
|
|
11220
11566
|
function isSafeParseSupportCall(node) {
|
|
11221
11567
|
const callee = unwrapExpression(node.callee);
|
|
11222
|
-
if (callee.type !== AST_NODE_TYPES55.MemberExpression ||
|
|
11568
|
+
if (callee.type !== AST_NODE_TYPES55.MemberExpression || ASTUtils30.getPropertyName(callee) === null) {
|
|
11223
11569
|
return false;
|
|
11224
11570
|
}
|
|
11225
|
-
if ((
|
|
11571
|
+
if ((ASTUtils30.getPropertyName(callee) ?? "") === "isArray" && callee.object.type === AST_NODE_TYPES55.Identifier && callee.object.name === "Array") {
|
|
11226
11572
|
return true;
|
|
11227
11573
|
}
|
|
11228
|
-
if ((
|
|
11574
|
+
if ((ASTUtils30.getPropertyName(callee) ?? "") !== "getItem") return false;
|
|
11229
11575
|
if (callee.object.type === AST_NODE_TYPES55.Identifier && (callee.object.name === "localStorage" || callee.object.name === "sessionStorage")) {
|
|
11230
11576
|
return true;
|
|
11231
11577
|
}
|
|
11232
|
-
return callee.object.type === AST_NODE_TYPES55.MemberExpression && callee.object.object.type === AST_NODE_TYPES55.Identifier && (callee.object.object.name === "window" || callee.object.object.name === "globalThis") &&
|
|
11578
|
+
return callee.object.type === AST_NODE_TYPES55.MemberExpression && callee.object.object.type === AST_NODE_TYPES55.Identifier && (callee.object.object.name === "window" || callee.object.object.name === "globalThis") && ASTUtils30.getPropertyName(callee.object) !== null && ((ASTUtils30.getPropertyName(callee.object) ?? "") === "localStorage" || (ASTUtils30.getPropertyName(callee.object) ?? "") === "sessionStorage");
|
|
11233
11579
|
}
|
|
11234
11580
|
var BODY_DECODE_METHODS = /* @__PURE__ */ new Set([
|
|
11235
11581
|
"json",
|
|
@@ -11441,7 +11787,7 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
11441
11787
|
return;
|
|
11442
11788
|
}
|
|
11443
11789
|
const returned = unwrapSentinelExpression(last.argument);
|
|
11444
|
-
if (returned?.type === AST_NODE_TYPES55.Identifier && returned.name === "undefined" && (
|
|
11790
|
+
if (returned?.type === AST_NODE_TYPES55.Identifier && returned.name === "undefined" && (ASTUtils30.findVariable(context.sourceCode.getScope(returned), returned.name)?.defs.length ?? 0) > 0) return;
|
|
11445
11791
|
if (containsThrow(node.body)) {
|
|
11446
11792
|
return;
|
|
11447
11793
|
}
|
|
@@ -11484,16 +11830,18 @@ function isNonReadingProperty(current, key) {
|
|
|
11484
11830
|
}
|
|
11485
11831
|
|
|
11486
11832
|
// src/rules/no-silent-promise-catch.ts
|
|
11487
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES56, ASTUtils as
|
|
11833
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES56, ASTUtils as ASTUtils31 } from "@typescript-eslint/utils";
|
|
11488
11834
|
var NO_SILENT_PROMISE_CATCH_DOCUMENTATION = {
|
|
11489
11835
|
summary: "Disallow `.catch()` and second-argument `.then()` handlers that silently swallow a rejection; log, rethrow, or handle the error.",
|
|
11490
11836
|
rationale: "A swallowed rejection hides failures and gives callers an indistinguishable fallback value.",
|
|
11491
11837
|
remediation: "Log, rethrow, or explicitly recover from the rejection; explain intentional teardown suppression.",
|
|
11492
11838
|
category: "correctness",
|
|
11493
|
-
limitations: ["Test files, teardown calls, explanatory comments, non-function handlers, and handlers that consume or report the error are excluded.", "Recognized imported Zod construction chains and their stable local aliases are excluded. Other untyped catch-like APIs are not proven to be Promises."],
|
|
11839
|
+
limitations: ["Test files, teardown calls, explanatory comments, non-function handlers, and handlers that consume or report the error are excluded.", "Recognized imported Zod construction chains and their stable local aliases are excluded. Other untyped catch-like APIs are not proven to be Promises.", "Computed methods resolve literal syntax and stable local string aliases in lexical scope. Function-derived, object-derived and mutated computed keys remain unproven."],
|
|
11494
11840
|
examples: [
|
|
11495
11841
|
{ id: "reported-rejection", title: "Report the rejection", outcome: "no-match", files: [{ path: "src/load.ts", source: "load().catch((error) => logger.error({ error }, 'load failed'));" }], focusPath: "src/load.ts", expectedCount: 0, public: true },
|
|
11496
|
-
{ id: "silent-rejection", title: "Do not swallow the rejection", outcome: "match", files: [{ path: "src/load.ts", source: "load().catch(() => null);" }], focusPath: "src/load.ts", expectedCount: 1, public: true }
|
|
11842
|
+
{ id: "silent-rejection", title: "Do not swallow the rejection", outcome: "match", files: [{ path: "src/load.ts", source: "load().catch(() => null);" }], focusPath: "src/load.ts", expectedCount: 1, public: true },
|
|
11843
|
+
{ id: "stable-computed-catch", scenarioId: "computed-method-scope", title: "Report a rejection through a stable computed method", outcome: "match", files: [{ path: "src/load.ts", source: "const method = 'catch'; Promise.reject(new Error('lost'))[method](() => null);" }], focusPath: "src/load.ts", expectedCount: 1, public: true },
|
|
11844
|
+
{ id: "stable-computed-body-parser", scenarioId: "computed-method-scope", title: "Preserve a recognized optional body parse fallback", outcome: "no-match", files: [{ path: "src/load.ts", source: "const method = 'json'; new Response('')[method]().catch(() => null);" }], focusPath: "src/load.ts", expectedCount: 0, public: true }
|
|
11497
11845
|
]
|
|
11498
11846
|
};
|
|
11499
11847
|
var BODY_PARSE_METHODS = /* @__PURE__ */ new Set([
|
|
@@ -11541,9 +11889,11 @@ var ZOD_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
11541
11889
|
"superRefine",
|
|
11542
11890
|
"transform"
|
|
11543
11891
|
]);
|
|
11544
|
-
function isBodyParseCall(node) {
|
|
11892
|
+
function isBodyParseCall(node, sourceCode) {
|
|
11545
11893
|
const unwrappedNodeCallee = node.type === "CallExpression" || node.type === "NewExpression" ? unwrapExpression(node.callee) : null;
|
|
11546
|
-
|
|
11894
|
+
if (node.type !== AST_NODE_TYPES56.CallExpression || node.arguments.length !== 0 || unwrappedNodeCallee?.type !== AST_NODE_TYPES56.MemberExpression) return false;
|
|
11895
|
+
const method = staticPropertyName(unwrappedNodeCallee, sourceCode);
|
|
11896
|
+
return method !== null && BODY_PARSE_METHODS.has(method);
|
|
11547
11897
|
}
|
|
11548
11898
|
var TEARDOWN_METHODS = /* @__PURE__ */ new Set([
|
|
11549
11899
|
"cancel",
|
|
@@ -11557,13 +11907,15 @@ var TEARDOWN_METHODS = /* @__PURE__ */ new Set([
|
|
|
11557
11907
|
]);
|
|
11558
11908
|
var DIRECTIVE_COMMENT_RE = /^\s*(eslint-|@ts-|prettier-ignore|biome-ignore|c8 |v8 |istanbul )/;
|
|
11559
11909
|
var isExplanatory = (comment) => !DIRECTIVE_COMMENT_RE.test(comment.value);
|
|
11560
|
-
function isTeardownCall(node) {
|
|
11910
|
+
function isTeardownCall(node, sourceCode) {
|
|
11561
11911
|
const unwrappedNodeCallee = node.type === "CallExpression" || node.type === "NewExpression" ? unwrapExpression(node.callee) : null;
|
|
11562
|
-
|
|
11912
|
+
if (node.type !== AST_NODE_TYPES56.CallExpression || unwrappedNodeCallee?.type !== AST_NODE_TYPES56.MemberExpression) return false;
|
|
11913
|
+
const method = staticPropertyName(unwrappedNodeCallee, sourceCode);
|
|
11914
|
+
return method !== null && TEARDOWN_METHODS.has(method);
|
|
11563
11915
|
}
|
|
11564
|
-
function isCancelledWebShare(node) {
|
|
11916
|
+
function isCancelledWebShare(node, sourceCode) {
|
|
11565
11917
|
const unwrappedNodeCallee = node.type === "CallExpression" || node.type === "NewExpression" ? unwrapExpression(node.callee) : null;
|
|
11566
|
-
return node.type === AST_NODE_TYPES56.CallExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES56.MemberExpression && unwrappedNodeCallee.object.type === AST_NODE_TYPES56.Identifier && unwrappedNodeCallee.object.name === "navigator" &&
|
|
11918
|
+
return node.type === AST_NODE_TYPES56.CallExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES56.MemberExpression && unwrappedNodeCallee.object.type === AST_NODE_TYPES56.Identifier && unwrappedNodeCallee.object.name === "navigator" && staticPropertyName(unwrappedNodeCallee, sourceCode) === "share";
|
|
11567
11919
|
}
|
|
11568
11920
|
function isSilentHandler(handler) {
|
|
11569
11921
|
const body2 = handler.body;
|
|
@@ -11622,16 +11974,16 @@ var no_silent_promise_catch_default = createRule({
|
|
|
11622
11974
|
if (seen.has(node)) return false;
|
|
11623
11975
|
seen.add(node);
|
|
11624
11976
|
if (node.type === AST_NODE_TYPES56.Identifier) {
|
|
11625
|
-
const binding =
|
|
11977
|
+
const binding = ASTUtils31.findVariable(context.sourceCode.getScope(node), node.name);
|
|
11626
11978
|
if (binding === null || binding.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
11627
11979
|
const [definition] = binding.defs;
|
|
11628
11980
|
return binding.defs.length === 1 && definition?.node.type === AST_NODE_TYPES56.VariableDeclarator && definition.node.init !== null && isZodSchema(definition.node.init, seen);
|
|
11629
11981
|
}
|
|
11630
|
-
if (node.type !== AST_NODE_TYPES56.CallExpression || unwrappedNodeCallee?.type !== AST_NODE_TYPES56.MemberExpression
|
|
11982
|
+
if (node.type !== AST_NODE_TYPES56.CallExpression || unwrappedNodeCallee?.type !== AST_NODE_TYPES56.MemberExpression) return false;
|
|
11631
11983
|
const { object } = unwrappedNodeCallee;
|
|
11632
|
-
const method =
|
|
11984
|
+
const method = staticPropertyName(unwrappedNodeCallee, context.sourceCode);
|
|
11633
11985
|
if (object.type === AST_NODE_TYPES56.Identifier && method !== null && ZOD_CONSTRUCTORS.has(method)) {
|
|
11634
|
-
const binding =
|
|
11986
|
+
const binding = ASTUtils31.findVariable(context.sourceCode.getScope(object), object.name);
|
|
11635
11987
|
if (binding?.defs.some((definition) => {
|
|
11636
11988
|
const specifier = definition.node;
|
|
11637
11989
|
return (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.parent.type === AST_NODE_TYPES56.ImportDeclaration && isZodModule(String(specifier.parent.source.value));
|
|
@@ -11658,23 +12010,23 @@ var no_silent_promise_catch_default = createRule({
|
|
|
11658
12010
|
return {
|
|
11659
12011
|
CallExpression(node) {
|
|
11660
12012
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
11661
|
-
if (unwrappedNodeCallee.type !== AST_NODE_TYPES56.MemberExpression
|
|
12013
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES56.MemberExpression) {
|
|
11662
12014
|
return;
|
|
11663
12015
|
}
|
|
11664
|
-
const method =
|
|
12016
|
+
const method = staticPropertyName(unwrappedNodeCallee, context.sourceCode);
|
|
11665
12017
|
const handlerIndex = method === "catch" ? 0 : method === "then" ? 1 : null;
|
|
11666
12018
|
if (handlerIndex === null) return;
|
|
11667
12019
|
if (method === "catch" && isZodSchema(unwrappedNodeCallee.object)) return;
|
|
11668
|
-
if (isBodyParseCall(unwrappedNodeCallee.object)) {
|
|
12020
|
+
if (isBodyParseCall(unwrappedNodeCallee.object, context.sourceCode)) {
|
|
11669
12021
|
return;
|
|
11670
12022
|
}
|
|
11671
|
-
if (isTeardownCall(unwrappedNodeCallee.object)) {
|
|
12023
|
+
if (isTeardownCall(unwrappedNodeCallee.object, context.sourceCode)) {
|
|
11672
12024
|
return;
|
|
11673
12025
|
}
|
|
11674
|
-
if (isCancelledWebShare(unwrappedNodeCallee.object)) {
|
|
12026
|
+
if (isCancelledWebShare(unwrappedNodeCallee.object, context.sourceCode)) {
|
|
11675
12027
|
return;
|
|
11676
12028
|
}
|
|
11677
|
-
if (node.parent.type === AST_NODE_TYPES56.MemberExpression && node.parent.object === node &&
|
|
12029
|
+
if (node.parent.type === AST_NODE_TYPES56.MemberExpression && node.parent.object === node && staticPropertyName(node.parent, context.sourceCode) === "then") {
|
|
11678
12030
|
return;
|
|
11679
12031
|
}
|
|
11680
12032
|
const expectedArguments = method === "catch" ? 1 : 2;
|
|
@@ -11699,7 +12051,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
11699
12051
|
});
|
|
11700
12052
|
|
|
11701
12053
|
// src/rules/no-sleep-in-test-body.ts
|
|
11702
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES57, ASTUtils as
|
|
12054
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES57, ASTUtils as ASTUtils32 } from "@typescript-eslint/utils";
|
|
11703
12055
|
var NO_SLEEP_IN_TEST_BODY_DOCUMENTATION = {
|
|
11704
12056
|
summary: "Avoid fixed timed sleeps directly in test bodies; synchronize on observable behavior or use controlled timers.",
|
|
11705
12057
|
rationale: "Wall-clock delays make test correctness depend on scheduler and machine speed.",
|
|
@@ -11786,7 +12138,7 @@ function testCallerName(callee, source) {
|
|
|
11786
12138
|
return name !== null && TEST_CALLERS2.has(name) ? name : null;
|
|
11787
12139
|
}
|
|
11788
12140
|
if (callee.type === AST_NODE_TYPES57.MemberExpression) {
|
|
11789
|
-
const member =
|
|
12141
|
+
const member = ASTUtils32.getPropertyName(callee);
|
|
11790
12142
|
return member !== null && TEST_MODIFIERS3.has(member) ? testCallerName(callee.object, source) : null;
|
|
11791
12143
|
}
|
|
11792
12144
|
if (callee.type === AST_NODE_TYPES57.CallExpression) return testCallerName(callee.callee, source);
|
|
@@ -11824,8 +12176,8 @@ var no_sleep_in_test_body_default = createRule({
|
|
|
11824
12176
|
return {
|
|
11825
12177
|
NewExpression(node) {
|
|
11826
12178
|
if (isPromiseSleep(node)) {
|
|
11827
|
-
const constructor =
|
|
11828
|
-
const timer =
|
|
12179
|
+
const constructor = ASTUtils32.findVariable(context.sourceCode.getScope(node), "Promise");
|
|
12180
|
+
const timer = ASTUtils32.findVariable(context.sourceCode.getScope(node), "setTimeout");
|
|
11829
12181
|
if ((constructor?.defs.length ?? 0) > 0 || (timer?.defs.length ?? 0) > 0) return;
|
|
11830
12182
|
report2(node);
|
|
11831
12183
|
}
|
|
@@ -11834,7 +12186,7 @@ var no_sleep_in_test_body_default = createRule({
|
|
|
11834
12186
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
11835
12187
|
if (isHelperSleep(node)) {
|
|
11836
12188
|
if (unwrappedNodeCallee.type !== AST_NODE_TYPES57.Identifier) return;
|
|
11837
|
-
const variable =
|
|
12189
|
+
const variable = ASTUtils32.findVariable(context.sourceCode.getScope(node), unwrappedNodeCallee.name);
|
|
11838
12190
|
if (variable?.defs.some((definition) => definition.type !== "ImportBinding")) return;
|
|
11839
12191
|
report2(node);
|
|
11840
12192
|
}
|
|
@@ -11844,7 +12196,7 @@ var no_sleep_in_test_body_default = createRule({
|
|
|
11844
12196
|
});
|
|
11845
12197
|
|
|
11846
12198
|
// src/rules/no-storage-in-stateless-modules.ts
|
|
11847
|
-
import { ASTUtils as
|
|
12199
|
+
import { ASTUtils as ASTUtils33, AST_NODE_TYPES as AST_NODE_TYPES58 } from "@typescript-eslint/utils";
|
|
11848
12200
|
var DEFAULT_METHODS2 = [
|
|
11849
12201
|
"prepare",
|
|
11850
12202
|
"put",
|
|
@@ -11879,7 +12231,7 @@ function storageMethodName(node, methods) {
|
|
|
11879
12231
|
const callee = unwrapExpression(node.callee);
|
|
11880
12232
|
const calleeReceiver = callee.type === AST_NODE_TYPES58.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
11881
12233
|
if (callee.type !== AST_NODE_TYPES58.MemberExpression) return null;
|
|
11882
|
-
const name =
|
|
12234
|
+
const name = ASTUtils33.getPropertyName(callee);
|
|
11883
12235
|
if (name === null || !methods.has(name)) {
|
|
11884
12236
|
return null;
|
|
11885
12237
|
}
|
|
@@ -11900,7 +12252,7 @@ function isStorageLikeReceiver(node) {
|
|
|
11900
12252
|
if (node.type !== AST_NODE_TYPES58.MemberExpression) {
|
|
11901
12253
|
return false;
|
|
11902
12254
|
}
|
|
11903
|
-
const name =
|
|
12255
|
+
const name = ASTUtils33.getPropertyName(node);
|
|
11904
12256
|
if (name !== null && isStorageIdentifier(name)) {
|
|
11905
12257
|
return true;
|
|
11906
12258
|
}
|
|
@@ -11979,7 +12331,7 @@ function hasSqlPreparationEvidence(node, callee) {
|
|
|
11979
12331
|
if (!/^\s*(?:SELECT|WITH|INSERT|UPDATE|DELETE|REPLACE|CREATE|ALTER|DROP|PRAGMA|EXPLAIN)\b/iu.test(stripSqlNoise(text))) return false;
|
|
11980
12332
|
} else {
|
|
11981
12333
|
const receiver = callee.object;
|
|
11982
|
-
const receiverName = receiver.type === AST_NODE_TYPES58.Identifier ? receiver.name : receiver.type === AST_NODE_TYPES58.MemberExpression ?
|
|
12334
|
+
const receiverName = receiver.type === AST_NODE_TYPES58.Identifier ? receiver.name : receiver.type === AST_NODE_TYPES58.MemberExpression ? ASTUtils33.getPropertyName(receiver) ?? "" : "";
|
|
11983
12335
|
if (!/^(?:db|database|connection)$/iu.test(receiverName)) return false;
|
|
11984
12336
|
}
|
|
11985
12337
|
return true;
|
|
@@ -12242,7 +12594,7 @@ var no_string_concat_in_loop_default = createRule({
|
|
|
12242
12594
|
});
|
|
12243
12595
|
|
|
12244
12596
|
// src/rules/no-duplicate-test-case.ts
|
|
12245
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES59, ASTUtils as
|
|
12597
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES59, ASTUtils as ASTUtils34 } from "@typescript-eslint/utils";
|
|
12246
12598
|
var TEST_MODULES = /* @__PURE__ */ new Set(["vitest", "@jest/globals", "bun:test"]);
|
|
12247
12599
|
var TEST_NAMES2 = /* @__PURE__ */ new Set(["it", "test"]);
|
|
12248
12600
|
var MODIFIERS = /* @__PURE__ */ new Set(["only", "skip", "concurrent", "fails", "failing", "todo"]);
|
|
@@ -12264,15 +12616,15 @@ var NO_DUPLICATE_TEST_CASE_DOCUMENTATION = {
|
|
|
12264
12616
|
};
|
|
12265
12617
|
function frameworkEach(node, sourceCode) {
|
|
12266
12618
|
let callee = unwrapExpression(node.callee);
|
|
12267
|
-
if (callee.type !== AST_NODE_TYPES59.MemberExpression ||
|
|
12619
|
+
if (callee.type !== AST_NODE_TYPES59.MemberExpression || ASTUtils34.getPropertyName(callee) !== "each") return false;
|
|
12268
12620
|
callee = unwrapExpression(callee.object);
|
|
12269
12621
|
while (callee.type === AST_NODE_TYPES59.MemberExpression) {
|
|
12270
|
-
const name =
|
|
12622
|
+
const name = ASTUtils34.getPropertyName(callee);
|
|
12271
12623
|
if (name === null || !MODIFIERS.has(name)) return false;
|
|
12272
12624
|
callee = unwrapExpression(callee.object);
|
|
12273
12625
|
}
|
|
12274
12626
|
if (callee.type !== AST_NODE_TYPES59.Identifier) return false;
|
|
12275
|
-
const variable =
|
|
12627
|
+
const variable = ASTUtils34.findVariable(sourceCode.getScope(callee), callee.name);
|
|
12276
12628
|
if (variable === null || variable.defs.length === 0) return TEST_NAMES2.has(callee.name);
|
|
12277
12629
|
return variable.defs.length === 1 && variable.defs.every((definition) => {
|
|
12278
12630
|
if (definition.node.type !== AST_NODE_TYPES59.ImportSpecifier) return false;
|
|
@@ -12285,7 +12637,7 @@ function table(node, sourceCode) {
|
|
|
12285
12637
|
node = unwrapExpression(node);
|
|
12286
12638
|
if (node.type === AST_NODE_TYPES59.ArrayExpression) return node;
|
|
12287
12639
|
if (node.type !== AST_NODE_TYPES59.Identifier) return null;
|
|
12288
|
-
const variable =
|
|
12640
|
+
const variable = ASTUtils34.findVariable(sourceCode.getScope(node), node.name);
|
|
12289
12641
|
const definition = variable?.defs[0];
|
|
12290
12642
|
if (variable?.defs.length !== 1 || definition?.node.type !== AST_NODE_TYPES59.VariableDeclarator || definition.node.id.type !== AST_NODE_TYPES59.Identifier || definition.node.parent.kind !== "const" || definition.node.init === null || definition.node.init.range[1] > node.range[0]) return null;
|
|
12291
12643
|
if (!variable.references.every((reference) => {
|
|
@@ -12366,7 +12718,7 @@ var no_duplicate_test_case_default = createRule({
|
|
|
12366
12718
|
});
|
|
12367
12719
|
|
|
12368
12720
|
// src/rules/no-tautological-expect.ts
|
|
12369
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES60, ASTUtils as
|
|
12721
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES60, ASTUtils as ASTUtils35 } from "@typescript-eslint/utils";
|
|
12370
12722
|
var NO_TAUTOLOGICAL_EXPECT_DOCUMENTATION = {
|
|
12371
12723
|
summary: "Disallow supported assertions known to pass from literals or immutable scalar setup.",
|
|
12372
12724
|
rationale: "An assertion determined entirely by literals does not observe the code under test and can keep passing after that code is removed.",
|
|
@@ -12433,7 +12785,7 @@ function resolveLiteral(node, sourceCode, seen = /* @__PURE__ */ new Set()) {
|
|
|
12433
12785
|
if (isLiteral(node)) return node;
|
|
12434
12786
|
if (node.type !== AST_NODE_TYPES60.Identifier || seen.has(node)) return null;
|
|
12435
12787
|
seen.add(node);
|
|
12436
|
-
const variable =
|
|
12788
|
+
const variable = ASTUtils35.findVariable(sourceCode.getScope(node), node.name);
|
|
12437
12789
|
if (variable?.defs.length !== 1) return null;
|
|
12438
12790
|
const definition = variable.defs[0];
|
|
12439
12791
|
if (definition?.node.type !== AST_NODE_TYPES60.VariableDeclarator || definition.node.id.type !== AST_NODE_TYPES60.Identifier || definition.node.parent.kind !== "const" || definition.node.init === null || definition.node.init.range[1] > node.range[0] || variable.references.some((reference) => reference.isWrite() && !reference.init)) return null;
|
|
@@ -12533,13 +12885,13 @@ var no_tautological_expect_default = createRule({
|
|
|
12533
12885
|
CallExpression(node) {
|
|
12534
12886
|
const callee = unwrapExpression(node.callee);
|
|
12535
12887
|
if (callee.type !== AST_NODE_TYPES60.MemberExpression) return;
|
|
12536
|
-
const matcher =
|
|
12888
|
+
const matcher = ASTUtils35.getPropertyName(callee);
|
|
12537
12889
|
if (matcher === null) return;
|
|
12538
12890
|
const receiver = unwrapExpression(callee.object);
|
|
12539
12891
|
if (receiver.type !== AST_NODE_TYPES60.CallExpression) return;
|
|
12540
12892
|
const expectIdentifier = unwrapExpression(receiver.callee);
|
|
12541
12893
|
if (expectIdentifier.type !== AST_NODE_TYPES60.Identifier) return;
|
|
12542
|
-
const variable =
|
|
12894
|
+
const variable = ASTUtils35.findVariable(context.sourceCode.getScope(expectIdentifier), expectIdentifier.name);
|
|
12543
12895
|
if (variable !== null && variable.defs.some((definition) => {
|
|
12544
12896
|
if (definition.node.type !== AST_NODE_TYPES60.ImportSpecifier) return true;
|
|
12545
12897
|
const declaration = definition.node.parent;
|
|
@@ -13789,7 +14141,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
13789
14141
|
// src/rules/no-unsafe-mock-casting.ts
|
|
13790
14142
|
import {
|
|
13791
14143
|
AST_NODE_TYPES as AST_NODE_TYPES66,
|
|
13792
|
-
ASTUtils as
|
|
14144
|
+
ASTUtils as ASTUtils36
|
|
13793
14145
|
} from "@typescript-eslint/utils";
|
|
13794
14146
|
var MOCK_TYPE_NAMES = /* @__PURE__ */ new Set([
|
|
13795
14147
|
"Mock",
|
|
@@ -13856,7 +14208,7 @@ var no_unsafe_mock_casting_default = createRule({
|
|
|
13856
14208
|
const directBindings = /* @__PURE__ */ new Set();
|
|
13857
14209
|
const namespaceBindings = /* @__PURE__ */ new Set();
|
|
13858
14210
|
function resolve2(identifier) {
|
|
13859
|
-
return
|
|
14211
|
+
return ASTUtils36.findVariable(
|
|
13860
14212
|
context.sourceCode.getScope(identifier),
|
|
13861
14213
|
identifier.name
|
|
13862
14214
|
);
|
|
@@ -13903,7 +14255,7 @@ var no_unsafe_mock_casting_default = createRule({
|
|
|
13903
14255
|
});
|
|
13904
14256
|
|
|
13905
14257
|
// src/rules/no-unsafe-test-double-cast.ts
|
|
13906
|
-
import { ASTUtils as
|
|
14258
|
+
import { ASTUtils as ASTUtils37, AST_NODE_TYPES as AST_NODE_TYPES67 } from "@typescript-eslint/utils";
|
|
13907
14259
|
var NO_UNSAFE_TEST_DOUBLE_CAST_DOCUMENTATION = {
|
|
13908
14260
|
summary: "Disallow mock-backed test doubles that bypass collaborator contracts through double assertions.",
|
|
13909
14261
|
rationale: "Casting a partial object through unknown hides missing or stale collaborator members, so production interface changes can compile while the test double silently drifts.",
|
|
@@ -13933,7 +14285,7 @@ function isMockFactory(node, source) {
|
|
|
13933
14285
|
const unwrappedNodeCallee = node.type === "CallExpression" || node.type === "NewExpression" ? unwrapExpression(node.callee) : null;
|
|
13934
14286
|
if (node.type !== AST_NODE_TYPES67.CallExpression || unwrappedNodeCallee?.type !== AST_NODE_TYPES67.MemberExpression) return false;
|
|
13935
14287
|
const receiver = unwrapExpression(unwrappedNodeCallee.object);
|
|
13936
|
-
return node.type === AST_NODE_TYPES67.CallExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES67.MemberExpression && receiver.type === AST_NODE_TYPES67.Identifier && (importedTestMockNamespace(source, receiver) !== null || isUnshadowedTestMockGlobal(source, receiver)) &&
|
|
14288
|
+
return node.type === AST_NODE_TYPES67.CallExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES67.MemberExpression && receiver.type === AST_NODE_TYPES67.Identifier && (importedTestMockNamespace(source, receiver) !== null || isUnshadowedTestMockGlobal(source, receiver)) && ASTUtils37.getPropertyName(unwrappedNodeCallee) !== null && ["fn", "spyOn"].includes(ASTUtils37.getPropertyName(unwrappedNodeCallee) ?? "");
|
|
13937
14289
|
}
|
|
13938
14290
|
var no_unsafe_test_double_cast_default = createRule({
|
|
13939
14291
|
name: "no-unsafe-test-double-cast",
|
|
@@ -13959,7 +14311,7 @@ var no_unsafe_test_double_cast_default = createRule({
|
|
|
13959
14311
|
});
|
|
13960
14312
|
|
|
13961
14313
|
// src/rules/no-first-party-module-mock.ts
|
|
13962
|
-
import { ASTUtils as
|
|
14314
|
+
import { ASTUtils as ASTUtils38, AST_NODE_TYPES as AST_NODE_TYPES68 } from "@typescript-eslint/utils";
|
|
13963
14315
|
var NO_FIRST_PARTY_MODULE_MOCK_DOCUMENTATION = {
|
|
13964
14316
|
summary: "Prefer injected collaborators over mocking maintained first-party modules in tests.",
|
|
13965
14317
|
rationale: "Replacing an owned module couples tests to its lookup path and can verify mock wiring while bypassing the real implementation contract.",
|
|
@@ -13990,7 +14342,7 @@ var no_first_party_module_mock_default = createRule({
|
|
|
13990
14342
|
CallExpression(node) {
|
|
13991
14343
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
13992
14344
|
const receiver = unwrappedNodeCallee.type === AST_NODE_TYPES68.MemberExpression ? unwrapExpression(unwrappedNodeCallee.object) : unwrappedNodeCallee;
|
|
13993
|
-
if (unwrappedNodeCallee.type !== AST_NODE_TYPES68.MemberExpression || receiver.type !== AST_NODE_TYPES68.Identifier ||
|
|
14345
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES68.MemberExpression || receiver.type !== AST_NODE_TYPES68.Identifier || ASTUtils38.getPropertyName(unwrappedNodeCallee) === null || !["mock", "doMock"].includes(ASTUtils38.getPropertyName(unwrappedNodeCallee) ?? "")) return;
|
|
13994
14346
|
const framework = importedTestMockNamespace(context.sourceCode, receiver);
|
|
13995
14347
|
if (framework === null || framework === "jest" && mayBeVirtual(node.arguments[2])) return;
|
|
13996
14348
|
const argument = node.arguments[0] === void 0 ? void 0 : unwrapExpression(node.arguments[0]);
|
|
@@ -14016,7 +14368,7 @@ function mayBeVirtual(options) {
|
|
|
14016
14368
|
import {
|
|
14017
14369
|
ESLintUtils as ESLintUtils10,
|
|
14018
14370
|
AST_NODE_TYPES as AST_NODE_TYPES69,
|
|
14019
|
-
ASTUtils as
|
|
14371
|
+
ASTUtils as ASTUtils39
|
|
14020
14372
|
} from "@typescript-eslint/utils";
|
|
14021
14373
|
import * as ts9 from "typescript";
|
|
14022
14374
|
var NO_ZOD_NATIVE_ENUM_DOCUMENTATION = {
|
|
@@ -14123,7 +14475,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
14123
14475
|
const zodImportedBindings = /* @__PURE__ */ new Map();
|
|
14124
14476
|
const zodNamespaceBindings = /* @__PURE__ */ new Set();
|
|
14125
14477
|
function resolvedBinding(identifier) {
|
|
14126
|
-
return
|
|
14478
|
+
return ASTUtils39.findVariable(
|
|
14127
14479
|
sourceCode.getScope(identifier),
|
|
14128
14480
|
identifier.name
|
|
14129
14481
|
);
|
|
@@ -14131,7 +14483,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
14131
14483
|
function isZodMemberCall(node, api) {
|
|
14132
14484
|
const callee = unwrapExpression(node.callee);
|
|
14133
14485
|
const calleeReceiver = callee.type === AST_NODE_TYPES69.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
14134
|
-
if (callee.type === AST_NODE_TYPES69.MemberExpression && calleeReceiver.type === AST_NODE_TYPES69.Identifier &&
|
|
14486
|
+
if (callee.type === AST_NODE_TYPES69.MemberExpression && calleeReceiver.type === AST_NODE_TYPES69.Identifier && ASTUtils39.getPropertyName(callee) === api) {
|
|
14135
14487
|
const binding = resolvedBinding(calleeReceiver);
|
|
14136
14488
|
return binding !== null && zodNamespaceBindings.has(binding);
|
|
14137
14489
|
}
|
|
@@ -14190,7 +14542,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
14190
14542
|
});
|
|
14191
14543
|
|
|
14192
14544
|
// src/rules/test-loops-over-literal-cases.ts
|
|
14193
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES70, ASTUtils as
|
|
14545
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES70, ASTUtils as ASTUtils40 } from "@typescript-eslint/utils";
|
|
14194
14546
|
var TEST_LOOPS_OVER_LITERAL_CASES_DOCUMENTATION = {
|
|
14195
14547
|
summary: "Disallow assertions over an inline literal case loop in a test; parameterization reports and names every case independently.",
|
|
14196
14548
|
rationale: "A loop is reported as one test, so failures hide the individual case name and may stop later cases from running.",
|
|
@@ -14343,7 +14695,7 @@ var test_loops_over_literal_cases_default = createRule({
|
|
|
14343
14695
|
}
|
|
14344
14696
|
const capturesSetup = walkOwnScope2(node.body, (current) => {
|
|
14345
14697
|
if (current.type !== AST_NODE_TYPES70.Identifier) return false;
|
|
14346
|
-
const variable =
|
|
14698
|
+
const variable = ASTUtils40.findVariable(context.sourceCode.getScope(current), current.name);
|
|
14347
14699
|
if (variable === null || !variable.references.some((reference) => reference.identifier === current)) return false;
|
|
14348
14700
|
return variable.defs.some((definition) => {
|
|
14349
14701
|
const declaration = definition.name;
|
|
@@ -14797,7 +15149,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
14797
15149
|
});
|
|
14798
15150
|
|
|
14799
15151
|
// src/rules/prefer-input-group-search.ts
|
|
14800
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES75, ASTUtils as
|
|
15152
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES75, ASTUtils as ASTUtils41 } from "@typescript-eslint/utils";
|
|
14801
15153
|
var PREFER_INPUT_GROUP_SEARCH_DOCUMENTATION = {
|
|
14802
15154
|
summary: "Require search icons and shared Input controls in the same visual wrapper to use InputGroup.",
|
|
14803
15155
|
rationale: "The shared compound control provides consistent spacing, focus behavior, and accessible composition.",
|
|
@@ -14921,7 +15273,7 @@ var prefer_input_group_search_default = createRule({
|
|
|
14921
15273
|
JSXOpeningElement(node) {
|
|
14922
15274
|
const name = elementName(node);
|
|
14923
15275
|
if (name === null) return;
|
|
14924
|
-
const binding =
|
|
15276
|
+
const binding = ASTUtils41.findVariable(context.sourceCode.getScope(node), name);
|
|
14925
15277
|
if (binding?.defs.length !== 1 || binding.defs[0]?.node.type !== AST_NODE_TYPES75.ImportSpecifier || binding.defs[0].node.importKind === "type") return;
|
|
14926
15278
|
const occurrence = {
|
|
14927
15279
|
ancestors: context.sourceCode.getAncestors(node),
|
|
@@ -14961,7 +15313,7 @@ var prefer_input_group_search_default = createRule({
|
|
|
14961
15313
|
|
|
14962
15314
|
// src/rules/prefer-millisecond-control-duration-schema.ts
|
|
14963
15315
|
import {
|
|
14964
|
-
ASTUtils as
|
|
15316
|
+
ASTUtils as ASTUtils42,
|
|
14965
15317
|
AST_NODE_TYPES as AST_NODE_TYPES77
|
|
14966
15318
|
} from "@typescript-eslint/utils";
|
|
14967
15319
|
|
|
@@ -15040,7 +15392,7 @@ var prefer_millisecond_control_duration_schema_default = createRule({
|
|
|
15040
15392
|
const objectFactories = /* @__PURE__ */ new Set();
|
|
15041
15393
|
const numberFactories = /* @__PURE__ */ new Set();
|
|
15042
15394
|
function binding(identifier) {
|
|
15043
|
-
return
|
|
15395
|
+
return ASTUtils42.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
15044
15396
|
}
|
|
15045
15397
|
function record(target, identifier) {
|
|
15046
15398
|
const variable = binding(identifier);
|
|
@@ -15053,7 +15405,7 @@ var prefer_millisecond_control_duration_schema_default = createRule({
|
|
|
15053
15405
|
const variable2 = binding(callee);
|
|
15054
15406
|
return variable2 !== null && objectFactories.has(variable2);
|
|
15055
15407
|
}
|
|
15056
|
-
if (callee.type !== AST_NODE_TYPES77.MemberExpression || calleeReceiver.type !== AST_NODE_TYPES77.Identifier ||
|
|
15408
|
+
if (callee.type !== AST_NODE_TYPES77.MemberExpression || calleeReceiver.type !== AST_NODE_TYPES77.Identifier || ASTUtils42.getPropertyName(callee) === null || (ASTUtils42.getPropertyName(callee) ?? "") !== "object" && (ASTUtils42.getPropertyName(callee) ?? "") !== "strictObject") {
|
|
15057
15409
|
return false;
|
|
15058
15410
|
}
|
|
15059
15411
|
const variable = binding(calleeReceiver);
|
|
@@ -15068,12 +15420,12 @@ var prefer_millisecond_control_duration_schema_default = createRule({
|
|
|
15068
15420
|
const variable = binding(callee);
|
|
15069
15421
|
return variable !== null && numberFactories.has(variable);
|
|
15070
15422
|
}
|
|
15071
|
-
if (callee.type !== AST_NODE_TYPES77.MemberExpression ||
|
|
15423
|
+
if (callee.type !== AST_NODE_TYPES77.MemberExpression || ASTUtils42.getPropertyName(callee) === null) return false;
|
|
15072
15424
|
if (calleeReceiver.type === AST_NODE_TYPES77.Identifier) {
|
|
15073
15425
|
const variable = binding(calleeReceiver);
|
|
15074
|
-
return (
|
|
15426
|
+
return (ASTUtils42.getPropertyName(callee) ?? "") === "number" && variable !== null && zodNamespaces.has(variable);
|
|
15075
15427
|
}
|
|
15076
|
-
return ["int", "min", "max", "positive", "nonnegative", "finite", "multipleOf", "optional", "nullable", "nullish", "default", "describe", "brand", "readonly"].includes(
|
|
15428
|
+
return ["int", "min", "max", "positive", "nonnegative", "finite", "multipleOf", "optional", "nullable", "nullish", "default", "describe", "brand", "readonly"].includes(ASTUtils42.getPropertyName(callee) ?? "") && isNumericSchema(calleeReceiver);
|
|
15077
15429
|
}
|
|
15078
15430
|
return {
|
|
15079
15431
|
ImportDeclaration(node) {
|
|
@@ -15106,7 +15458,7 @@ var prefer_millisecond_control_duration_schema_default = createRule({
|
|
|
15106
15458
|
});
|
|
15107
15459
|
|
|
15108
15460
|
// src/rules/prefer-immutable-module-constant.ts
|
|
15109
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES78, ASTUtils as
|
|
15461
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES78, ASTUtils as ASTUtils43 } from "@typescript-eslint/utils";
|
|
15110
15462
|
var PREFER_IMMUTABLE_MODULE_CONSTANT_DOCUMENTATION = {
|
|
15111
15463
|
summary: "Require module-level constant collections to expose readonly state.",
|
|
15112
15464
|
rationale: "A const binding prevents reassignment but does not stop callers from mutating its array, object, Set, or Map contents.",
|
|
@@ -15325,15 +15677,15 @@ var prefer_immutable_module_constant_default = createRule({
|
|
|
15325
15677
|
create(context) {
|
|
15326
15678
|
const sourceCode = context.sourceCode;
|
|
15327
15679
|
const isUnshadowedGlobal3 = (identifier) => {
|
|
15328
|
-
const variable =
|
|
15680
|
+
const variable = ASTUtils43.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
15329
15681
|
return variable === null || variable.defs.length === 0;
|
|
15330
15682
|
};
|
|
15331
15683
|
const isUnshadowedType = (identifier) => {
|
|
15332
|
-
const variable =
|
|
15684
|
+
const variable = ASTUtils43.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
15333
15685
|
return variable === null || !variable.defs.some((definition) => definition.isTypeDefinition);
|
|
15334
15686
|
};
|
|
15335
15687
|
const resolveLocalType = (identifier) => {
|
|
15336
|
-
const variable =
|
|
15688
|
+
const variable = ASTUtils43.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
15337
15689
|
const definitions = variable?.defs.filter((definition) => definition.isTypeDefinition) ?? [];
|
|
15338
15690
|
const declaration = definitions.length === 1 ? definitions[0]?.node : void 0;
|
|
15339
15691
|
return declaration?.type === AST_NODE_TYPES78.TSTypeAliasDeclaration || declaration?.type === AST_NODE_TYPES78.TSTypeParameter ? declaration : void 0;
|
|
@@ -15827,7 +16179,7 @@ function matchingAliasTargets(paths, alias) {
|
|
|
15827
16179
|
}
|
|
15828
16180
|
|
|
15829
16181
|
// src/rules/prefer-module-level-constant.ts
|
|
15830
|
-
import { ASTUtils as
|
|
16182
|
+
import { ASTUtils as ASTUtils44, AST_NODE_TYPES as AST_NODE_TYPES80 } from "@typescript-eslint/utils";
|
|
15831
16183
|
var PREFER_MODULE_LEVEL_CONSTANT_DOCUMENTATION = {
|
|
15832
16184
|
summary: "Hoist literal-only constant collections and regexes out of function bodies to module scope so they are allocated once.",
|
|
15833
16185
|
rationale: "Recreating immutable lookup data on every call wastes allocations and obscures its constant nature.",
|
|
@@ -15955,7 +16307,7 @@ function classify(init, checkRegex, sourceCode) {
|
|
|
15955
16307
|
function unwrapObjectFreeze(node, sourceCode) {
|
|
15956
16308
|
const inner = unwrap3(node);
|
|
15957
16309
|
const callee = inner.type === AST_NODE_TYPES80.CallExpression ? unwrapExpression(inner.callee) : null;
|
|
15958
|
-
if (inner.type === AST_NODE_TYPES80.CallExpression && callee?.type === AST_NODE_TYPES80.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES80.Identifier && callee.object.name === "Object" && (
|
|
16310
|
+
if (inner.type === AST_NODE_TYPES80.CallExpression && callee?.type === AST_NODE_TYPES80.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES80.Identifier && callee.object.name === "Object" && (ASTUtils44.findVariable(sourceCode.getScope(callee.object), "Object")?.defs.length ?? 0) === 0 && callee.property.type === AST_NODE_TYPES80.Identifier && callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== AST_NODE_TYPES80.SpreadElement) {
|
|
15959
16311
|
return unwrap3(inner.arguments[0]);
|
|
15960
16312
|
}
|
|
15961
16313
|
return inner;
|
|
@@ -16154,14 +16506,14 @@ function isSafeMemberRead(identifier, parent) {
|
|
|
16154
16506
|
if (grandparent.type === AST_NODE_TYPES80.UnaryExpression && grandparent.operator === "delete") {
|
|
16155
16507
|
return false;
|
|
16156
16508
|
}
|
|
16157
|
-
if (grandparent.type === AST_NODE_TYPES80.CallExpression && grandparent.callee === usage && (
|
|
16509
|
+
if (grandparent.type === AST_NODE_TYPES80.CallExpression && grandparent.callee === usage && (ASTUtils44.getPropertyName(parent) === null || MUTATING_METHODS2.has(ASTUtils44.getPropertyName(parent) ?? ""))) {
|
|
16158
16510
|
return false;
|
|
16159
16511
|
}
|
|
16160
16512
|
return true;
|
|
16161
16513
|
}
|
|
16162
16514
|
|
|
16163
16515
|
// src/rules/prefer-module-level-schema.ts
|
|
16164
|
-
import { ASTUtils as
|
|
16516
|
+
import { ASTUtils as ASTUtils45, AST_NODE_TYPES as AST_NODE_TYPES81 } from "@typescript-eslint/utils";
|
|
16165
16517
|
var PREFER_MODULE_LEVEL_SCHEMA_DOCUMENTATION = {
|
|
16166
16518
|
summary: "Declare a Zod schema at module scope when it closes over nothing in the enclosing function",
|
|
16167
16519
|
rationale: "A schema created inside a function is rebuilt on each call. Module scope can enable reuse across callers; local schemas already support local type inference.",
|
|
@@ -16269,7 +16621,7 @@ function schemaExpression(node) {
|
|
|
16269
16621
|
if (parent === void 0) {
|
|
16270
16622
|
return current;
|
|
16271
16623
|
}
|
|
16272
|
-
if (parent.type === AST_NODE_TYPES81.MemberExpression && parent.object === current &&
|
|
16624
|
+
if (parent.type === AST_NODE_TYPES81.MemberExpression && parent.object === current && ASTUtils45.getPropertyName(parent) !== null && TERMINAL_METHODS.has(ASTUtils45.getPropertyName(parent) ?? "")) {
|
|
16273
16625
|
return current;
|
|
16274
16626
|
}
|
|
16275
16627
|
if (parent.type === AST_NODE_TYPES81.MemberExpression && parent.object === current || parent.type === AST_NODE_TYPES81.CallExpression && parent.callee === current || parent.type === AST_NODE_TYPES81.TSAsExpression && parent.expression === current || parent.type === AST_NODE_TYPES81.TSNonNullExpression && parent.expression === current) {
|
|
@@ -16407,14 +16759,14 @@ var prefer_module_level_schema_default = createRule({
|
|
|
16407
16759
|
const unwrappedNodeCallee = node.type === "CallExpression" || node.type === "NewExpression" ? unwrapExpression(node.callee) : null;
|
|
16408
16760
|
if (node.type !== AST_NODE_TYPES81.CallExpression || unwrappedNodeCallee?.type !== AST_NODE_TYPES81.MemberExpression) return false;
|
|
16409
16761
|
const receiver = unwrapExpression(unwrappedNodeCallee.object);
|
|
16410
|
-
return node.type === AST_NODE_TYPES81.CallExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES81.MemberExpression &&
|
|
16762
|
+
return node.type === AST_NODE_TYPES81.CallExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES81.MemberExpression && ASTUtils45.getPropertyName(unwrappedNodeCallee) !== null && receiver.type === AST_NODE_TYPES81.Identifier && zodNamespaces.has(receiver.name);
|
|
16411
16763
|
}
|
|
16412
16764
|
function isSchemaConstruction(node) {
|
|
16413
16765
|
const callee = unwrapExpression(node.callee);
|
|
16414
16766
|
const calleeReceiver = callee.type === AST_NODE_TYPES81.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
16415
|
-
if (callee.type !== AST_NODE_TYPES81.MemberExpression ||
|
|
16767
|
+
if (callee.type !== AST_NODE_TYPES81.MemberExpression || ASTUtils45.getPropertyName(callee) === null || TERMINAL_METHODS.has(ASTUtils45.getPropertyName(callee) ?? "")) return false;
|
|
16416
16768
|
if (calleeReceiver.type === AST_NODE_TYPES81.CallExpression) return isSchemaConstruction(calleeReceiver);
|
|
16417
|
-
return isZodCall(node) && CONSTRUCTION_FACTORIES.has(
|
|
16769
|
+
return isZodCall(node) && CONSTRUCTION_FACTORIES.has(ASTUtils45.getPropertyName(callee) ?? "");
|
|
16418
16770
|
}
|
|
16419
16771
|
function hasEagerComputation(node) {
|
|
16420
16772
|
return subtreeSome(node, (inner) => inner.type === AST_NODE_TYPES81.NewExpression || inner.type === AST_NODE_TYPES81.TaggedTemplateExpression || inner.type === AST_NODE_TYPES81.CallExpression && !isSchemaConstruction(inner), true);
|
|
@@ -16422,10 +16774,10 @@ var prefer_module_level_schema_default = createRule({
|
|
|
16422
16774
|
function isCovered(node) {
|
|
16423
16775
|
let current = node.parent ?? void 0;
|
|
16424
16776
|
while (current !== void 0) {
|
|
16425
|
-
if (current !== node && isZodCall(current) && current.callee.type === AST_NODE_TYPES81.MemberExpression &&
|
|
16777
|
+
if (current !== node && isZodCall(current) && current.callee.type === AST_NODE_TYPES81.MemberExpression && ASTUtils45.getPropertyName(current.callee) !== null && factories.has(ASTUtils45.getPropertyName(current.callee) ?? "")) {
|
|
16426
16778
|
return true;
|
|
16427
16779
|
}
|
|
16428
|
-
if (current.type === AST_NODE_TYPES81.CallExpression && (current.callee.type === AST_NODE_TYPES81.Identifier && memoCallees.has(current.callee.name) || current.callee.type === AST_NODE_TYPES81.MemberExpression &&
|
|
16780
|
+
if (current.type === AST_NODE_TYPES81.CallExpression && (current.callee.type === AST_NODE_TYPES81.Identifier && memoCallees.has(current.callee.name) || current.callee.type === AST_NODE_TYPES81.MemberExpression && ASTUtils45.getPropertyName(current.callee) !== null && memoCallees.has(ASTUtils45.getPropertyName(current.callee) ?? ""))) {
|
|
16429
16781
|
return true;
|
|
16430
16782
|
}
|
|
16431
16783
|
current = current.parent ?? void 0;
|
|
@@ -16454,7 +16806,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
16454
16806
|
}
|
|
16455
16807
|
function isSchemaComposition(node) {
|
|
16456
16808
|
const callee = unwrapExpression(node.callee);
|
|
16457
|
-
const isCombinator = callee.type === AST_NODE_TYPES81.MemberExpression &&
|
|
16809
|
+
const isCombinator = callee.type === AST_NODE_TYPES81.MemberExpression && ASTUtils45.getPropertyName(callee) !== null && ZOD_COMBINATOR_METHODS.has(ASTUtils45.getPropertyName(callee) ?? "");
|
|
16458
16810
|
return isCombinator || isZodCall(node);
|
|
16459
16811
|
}
|
|
16460
16812
|
function closesOverNothing(node, enclosing) {
|
|
@@ -16527,10 +16879,10 @@ var prefer_module_level_schema_default = createRule({
|
|
|
16527
16879
|
return;
|
|
16528
16880
|
}
|
|
16529
16881
|
const callee = unwrappedNodeCallee;
|
|
16530
|
-
if (
|
|
16882
|
+
if (ASTUtils45.getPropertyName(callee) === null) {
|
|
16531
16883
|
return;
|
|
16532
16884
|
}
|
|
16533
|
-
const factory =
|
|
16885
|
+
const factory = ASTUtils45.getPropertyName(callee) ?? "";
|
|
16534
16886
|
if (!factories.has(factory)) {
|
|
16535
16887
|
return;
|
|
16536
16888
|
}
|
|
@@ -16573,7 +16925,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
16573
16925
|
// src/rules/prefer-module-level-refined-schema.ts
|
|
16574
16926
|
import {
|
|
16575
16927
|
AST_NODE_TYPES as AST_NODE_TYPES82,
|
|
16576
|
-
ASTUtils as
|
|
16928
|
+
ASTUtils as ASTUtils46
|
|
16577
16929
|
} from "@typescript-eslint/utils";
|
|
16578
16930
|
var BENCHMARK_PATH_RE = /(^|[/\\])(?:benchmarks?|bench)[/\\]/;
|
|
16579
16931
|
var FACTORIES = /* @__PURE__ */ new Set([
|
|
@@ -16800,9 +17152,9 @@ function chainMemberNames(node) {
|
|
|
16800
17152
|
for (; ; ) {
|
|
16801
17153
|
current = unwrapExpression(current);
|
|
16802
17154
|
if (current.type === AST_NODE_TYPES82.MemberExpression) {
|
|
16803
|
-
if (
|
|
17155
|
+
if (ASTUtils46.getPropertyName(current) === null)
|
|
16804
17156
|
return [];
|
|
16805
|
-
names.push(
|
|
17157
|
+
names.push(ASTUtils46.getPropertyName(current) ?? "");
|
|
16806
17158
|
current = current.object;
|
|
16807
17159
|
continue;
|
|
16808
17160
|
}
|
|
@@ -16819,8 +17171,8 @@ function schemaExpression2(node) {
|
|
|
16819
17171
|
let current = node;
|
|
16820
17172
|
for (; ; ) {
|
|
16821
17173
|
const parent = current.parent ?? void 0;
|
|
16822
|
-
if (parent?.type === AST_NODE_TYPES82.MemberExpression && parent.object === current &&
|
|
16823
|
-
if (NON_SCHEMA_TERMINALS.has(
|
|
17174
|
+
if (parent?.type === AST_NODE_TYPES82.MemberExpression && parent.object === current && ASTUtils46.getPropertyName(parent) !== null && parent.parent?.type === AST_NODE_TYPES82.CallExpression && parent.parent.callee === parent) {
|
|
17175
|
+
if (NON_SCHEMA_TERMINALS.has(ASTUtils46.getPropertyName(parent) ?? "")) return current;
|
|
16824
17176
|
current = parent.parent;
|
|
16825
17177
|
continue;
|
|
16826
17178
|
}
|
|
@@ -16850,7 +17202,7 @@ var prefer_module_level_refined_schema_default = createRule({
|
|
|
16850
17202
|
return {};
|
|
16851
17203
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
16852
17204
|
function resolvedBinding(identifier) {
|
|
16853
|
-
return
|
|
17205
|
+
return ASTUtils46.findVariable(
|
|
16854
17206
|
context.sourceCode.getScope(identifier),
|
|
16855
17207
|
identifier.name
|
|
16856
17208
|
);
|
|
@@ -16876,7 +17228,7 @@ var prefer_module_level_refined_schema_default = createRule({
|
|
|
16876
17228
|
function isSchemaConstruction(node) {
|
|
16877
17229
|
const callee = unwrapExpression(node.callee);
|
|
16878
17230
|
const calleeReceiver = callee.type === AST_NODE_TYPES82.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
16879
|
-
if (callee.type !== AST_NODE_TYPES82.MemberExpression ||
|
|
17231
|
+
if (callee.type !== AST_NODE_TYPES82.MemberExpression || ASTUtils46.getPropertyName(callee) === null || NON_SCHEMA_TERMINALS.has(ASTUtils46.getPropertyName(callee) ?? "")) return false;
|
|
16880
17232
|
if (calleeReceiver.type === AST_NODE_TYPES82.CallExpression) return isSchemaConstruction(calleeReceiver);
|
|
16881
17233
|
return factoryName(node, FACTORIES) !== null || factoryName(node, COMPOSITE_FACTORIES) !== null;
|
|
16882
17234
|
}
|
|
@@ -16903,7 +17255,7 @@ var prefer_module_level_refined_schema_default = createRule({
|
|
|
16903
17255
|
function isMemoized(node) {
|
|
16904
17256
|
let current = node.parent ?? void 0;
|
|
16905
17257
|
while (current !== void 0) {
|
|
16906
|
-
if (current.type === AST_NODE_TYPES82.CallExpression && (current.callee.type === AST_NODE_TYPES82.Identifier && MEMO_CALLEES2.has(current.callee.name) || current.callee.type === AST_NODE_TYPES82.MemberExpression &&
|
|
17258
|
+
if (current.type === AST_NODE_TYPES82.CallExpression && (current.callee.type === AST_NODE_TYPES82.Identifier && MEMO_CALLEES2.has(current.callee.name) || current.callee.type === AST_NODE_TYPES82.MemberExpression && ASTUtils46.getPropertyName(current.callee) !== null && MEMO_CALLEES2.has(ASTUtils46.getPropertyName(current.callee) ?? "")))
|
|
16907
17259
|
return true;
|
|
16908
17260
|
current = current.parent ?? void 0;
|
|
16909
17261
|
}
|
|
@@ -16966,7 +17318,7 @@ var prefer_module_level_refined_schema_default = createRule({
|
|
|
16966
17318
|
// src/rules/prefer-multi-value-zod-literal.ts
|
|
16967
17319
|
import {
|
|
16968
17320
|
AST_NODE_TYPES as AST_NODE_TYPES83,
|
|
16969
|
-
ASTUtils as
|
|
17321
|
+
ASTUtils as ASTUtils47
|
|
16970
17322
|
} from "@typescript-eslint/utils";
|
|
16971
17323
|
var PREFER_MULTI_VALUE_ZOD_LITERAL_DOCUMENTATION = {
|
|
16972
17324
|
defaultLevel: "warning",
|
|
@@ -17015,7 +17367,7 @@ function isStaticPrimitive(node, context) {
|
|
|
17015
17367
|
if (node.type === AST_NODE_TYPES83.TemplateLiteral && node.expressions.length === 0)
|
|
17016
17368
|
return true;
|
|
17017
17369
|
if (node.type === AST_NODE_TYPES83.Identifier && node.name === "undefined") {
|
|
17018
|
-
const binding =
|
|
17370
|
+
const binding = ASTUtils47.findVariable(
|
|
17019
17371
|
context.sourceCode.getScope(node),
|
|
17020
17372
|
node.name
|
|
17021
17373
|
);
|
|
@@ -17053,7 +17405,7 @@ var prefer_multi_value_zod_literal_default = createRule({
|
|
|
17053
17405
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
17054
17406
|
const zod4Bindings = /* @__PURE__ */ new Set();
|
|
17055
17407
|
function resolvedBinding(identifier) {
|
|
17056
|
-
return
|
|
17408
|
+
return ASTUtils47.findVariable(
|
|
17057
17409
|
context.sourceCode.getScope(identifier),
|
|
17058
17410
|
identifier.name
|
|
17059
17411
|
);
|
|
@@ -17061,7 +17413,7 @@ var prefer_multi_value_zod_literal_default = createRule({
|
|
|
17061
17413
|
function directMemberCall(node, binding, method) {
|
|
17062
17414
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
17063
17415
|
const receiver = unwrappedNodeCallee.type === AST_NODE_TYPES83.MemberExpression ? unwrapExpression(unwrappedNodeCallee.object) : unwrappedNodeCallee;
|
|
17064
|
-
if (unwrappedNodeCallee.type !== AST_NODE_TYPES83.MemberExpression || receiver.type !== AST_NODE_TYPES83.Identifier ||
|
|
17416
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES83.MemberExpression || receiver.type !== AST_NODE_TYPES83.Identifier || ASTUtils47.getPropertyName(unwrappedNodeCallee) === null || (ASTUtils47.getPropertyName(unwrappedNodeCallee) ?? "") !== method)
|
|
17065
17417
|
return false;
|
|
17066
17418
|
return resolvedBinding(receiver) === binding;
|
|
17067
17419
|
}
|
|
@@ -17111,7 +17463,7 @@ var prefer_multi_value_zod_literal_default = createRule({
|
|
|
17111
17463
|
});
|
|
17112
17464
|
|
|
17113
17465
|
// src/rules/prefer-nominal-id-types.ts
|
|
17114
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES84, ASTUtils as
|
|
17466
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES84, ASTUtils as ASTUtils48 } from "@typescript-eslint/utils";
|
|
17115
17467
|
var OPERATIONAL_ROLES = /* @__PURE__ */ new Set([
|
|
17116
17468
|
"request",
|
|
17117
17469
|
"trace",
|
|
@@ -17149,7 +17501,7 @@ function isNullish(node) {
|
|
|
17149
17501
|
}
|
|
17150
17502
|
function referenceCarrier(node, context, depth) {
|
|
17151
17503
|
if (node.typeName.type !== AST_NODE_TYPES84.Identifier) return void 0;
|
|
17152
|
-
const variable =
|
|
17504
|
+
const variable = ASTUtils48.findVariable(context.sourceCode.getScope(node), node.typeName.name);
|
|
17153
17505
|
const definitions = variable?.defs ?? [];
|
|
17154
17506
|
const args = node.typeArguments?.params;
|
|
17155
17507
|
if (definitions.length === 0 && ["Array", "ReadonlyArray"].includes(node.typeName.name) && args?.length === 1) {
|
|
@@ -17347,7 +17699,7 @@ var prefer_named_complex_return_type_default = createRule({
|
|
|
17347
17699
|
});
|
|
17348
17700
|
|
|
17349
17701
|
// src/rules/prefer-native-random-uuid.ts
|
|
17350
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES87, ASTUtils as
|
|
17702
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES87, ASTUtils as ASTUtils49 } from "@typescript-eslint/utils";
|
|
17351
17703
|
var PREFER_NATIVE_RANDOM_UUID_DOCUMENTATION = {
|
|
17352
17704
|
summary: "Prefer `globalThis.crypto.randomUUID()` over resolved zero-argument UUID v4 bindings from the `uuid` package.",
|
|
17353
17705
|
rationale: "The platform implementation avoids an unnecessary dependency for standard random UUID generation.",
|
|
@@ -17383,14 +17735,14 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
17383
17735
|
const directBindings = /* @__PURE__ */ new Set();
|
|
17384
17736
|
const namespaceBindings = /* @__PURE__ */ new Set();
|
|
17385
17737
|
function resolve2(identifier) {
|
|
17386
|
-
return
|
|
17738
|
+
return ASTUtils49.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
17387
17739
|
}
|
|
17388
17740
|
function record(identifier, destination) {
|
|
17389
17741
|
const variable = resolve2(identifier);
|
|
17390
17742
|
if (variable !== null) destination.add(variable);
|
|
17391
17743
|
}
|
|
17392
17744
|
function report2(node) {
|
|
17393
|
-
const globalBinding =
|
|
17745
|
+
const globalBinding = ASTUtils49.findVariable(context.sourceCode.getScope(node), "globalThis");
|
|
17394
17746
|
const canSuggest = (globalBinding?.defs.length ?? 0) === 0 && context.sourceCode.getCommentsInside(node).length === 0;
|
|
17395
17747
|
context.report({
|
|
17396
17748
|
node,
|
|
@@ -17449,7 +17801,7 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
17449
17801
|
});
|
|
17450
17802
|
|
|
17451
17803
|
// src/rules/prefer-node-crypto-hash.ts
|
|
17452
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES88, ASTUtils as
|
|
17804
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES88, ASTUtils as ASTUtils50 } from "@typescript-eslint/utils";
|
|
17453
17805
|
var PREFER_NODE_CRYPTO_HASH_DOCUMENTATION = {
|
|
17454
17806
|
defaultLevel: "warning",
|
|
17455
17807
|
summary: "Prefer the modern one-shot node:crypto hash API when streaming state is unnecessary.",
|
|
@@ -17477,7 +17829,7 @@ function isCryptoLoader(node, resolve2) {
|
|
|
17477
17829
|
if (unwrappedNodeCallee?.type === AST_NODE_TYPES88.Identifier) {
|
|
17478
17830
|
return unwrappedNodeCallee.name === "require" && isUnshadowedBuiltinIdentifier(unwrappedNodeCallee, resolve2);
|
|
17479
17831
|
}
|
|
17480
|
-
return unwrappedNodeCallee?.type === AST_NODE_TYPES88.MemberExpression && unwrappedNodeCallee.object.type === AST_NODE_TYPES88.Identifier && unwrappedNodeCallee.object.name === "process" && isUnshadowedBuiltinIdentifier(unwrappedNodeCallee.object, resolve2) &&
|
|
17832
|
+
return unwrappedNodeCallee?.type === AST_NODE_TYPES88.MemberExpression && unwrappedNodeCallee.object.type === AST_NODE_TYPES88.Identifier && unwrappedNodeCallee.object.name === "process" && isUnshadowedBuiltinIdentifier(unwrappedNodeCallee.object, resolve2) && ASTUtils50.getPropertyName(unwrappedNodeCallee) === "getBuiltinModule";
|
|
17481
17833
|
}
|
|
17482
17834
|
function isCryptoSpecifier(node) {
|
|
17483
17835
|
return node.type === AST_NODE_TYPES88.Literal && (node.value === "crypto" || node.value === "node:crypto");
|
|
@@ -17502,7 +17854,7 @@ var prefer_node_crypto_hash_default = createRule({
|
|
|
17502
17854
|
const directBindings = /* @__PURE__ */ new Set();
|
|
17503
17855
|
const namespaceBindings = /* @__PURE__ */ new Set();
|
|
17504
17856
|
function resolve2(identifier) {
|
|
17505
|
-
return
|
|
17857
|
+
return ASTUtils50.findVariable(
|
|
17506
17858
|
context.sourceCode.getScope(identifier),
|
|
17507
17859
|
identifier.name
|
|
17508
17860
|
);
|
|
@@ -17564,7 +17916,7 @@ function importedName5(node) {
|
|
|
17564
17916
|
}
|
|
17565
17917
|
function isMemberCall(node, name) {
|
|
17566
17918
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
17567
|
-
return unwrappedNodeCallee.type === AST_NODE_TYPES88.MemberExpression &&
|
|
17919
|
+
return unwrappedNodeCallee.type === AST_NODE_TYPES88.MemberExpression && ASTUtils50.getPropertyName(unwrappedNodeCallee) === name;
|
|
17568
17920
|
}
|
|
17569
17921
|
function isCreateHashCall(node, directBindings, namespaceBindings, resolve2) {
|
|
17570
17922
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
@@ -17572,7 +17924,7 @@ function isCreateHashCall(node, directBindings, namespaceBindings, resolve2) {
|
|
|
17572
17924
|
const variable2 = resolve2(unwrappedNodeCallee);
|
|
17573
17925
|
return variable2 !== null && directBindings.has(variable2);
|
|
17574
17926
|
}
|
|
17575
|
-
if (unwrappedNodeCallee.type !== AST_NODE_TYPES88.MemberExpression ||
|
|
17927
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES88.MemberExpression || ASTUtils50.getPropertyName(unwrappedNodeCallee) !== "createHash") {
|
|
17576
17928
|
return false;
|
|
17577
17929
|
}
|
|
17578
17930
|
if (isCryptoLoader(unwrappedNodeCallee.object, resolve2)) return true;
|
|
@@ -17582,7 +17934,7 @@ function isCreateHashCall(node, directBindings, namespaceBindings, resolve2) {
|
|
|
17582
17934
|
}
|
|
17583
17935
|
|
|
17584
17936
|
// src/rules/prefer-node-fs-promises.ts
|
|
17585
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES89, ASTUtils as
|
|
17937
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES89, ASTUtils as ASTUtils51 } from "@typescript-eslint/utils";
|
|
17586
17938
|
var PREFER_NODE_FS_PROMISES_DOCUMENTATION = {
|
|
17587
17939
|
defaultLevel: "warning",
|
|
17588
17940
|
summary: "Prefer promise-based Node.js filesystem APIs over synchronous calls in production modules.",
|
|
@@ -17644,7 +17996,7 @@ var prefer_node_fs_promises_default = createRule({
|
|
|
17644
17996
|
if (isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text) || normalizedFilename.includes("src/rules/"))
|
|
17645
17997
|
return {};
|
|
17646
17998
|
const namespaces = /* @__PURE__ */ new Set();
|
|
17647
|
-
const bindingOf = (node) =>
|
|
17999
|
+
const bindingOf = (node) => ASTUtils51.findVariable(context.sourceCode.getScope(node), node.name);
|
|
17648
18000
|
const isGlobal = (node) => {
|
|
17649
18001
|
const binding = bindingOf(node);
|
|
17650
18002
|
return binding === null || binding.defs.length === 0;
|
|
@@ -17710,7 +18062,7 @@ var prefer_node_fs_promises_default = createRule({
|
|
|
17710
18062
|
});
|
|
17711
18063
|
|
|
17712
18064
|
// src/rules/prefer-non-nullable-collection.ts
|
|
17713
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES90, ASTUtils as
|
|
18065
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES90, ASTUtils as ASTUtils52 } from "@typescript-eslint/utils";
|
|
17714
18066
|
var PREFER_NON_NULLABLE_COLLECTION_DOCUMENTATION = {
|
|
17715
18067
|
summary: "Suggest reviewing nullish arrays that use local empty-array defaults or a shared null-or-empty guard.",
|
|
17716
18068
|
rationale: "A redundant nullish collection state spreads defaults and guards through consumers without carrying information.",
|
|
@@ -17835,14 +18187,14 @@ function directlyCoalesced(node) {
|
|
|
17835
18187
|
return parent?.type === AST_NODE_TYPES90.LogicalExpression && parent.left === node && (parent.operator === "??" || parent.operator === "||") && emptyArray(parent.right);
|
|
17836
18188
|
}
|
|
17837
18189
|
function identifierIsOnlyCoalesced(context, binding, fn) {
|
|
17838
|
-
const variable =
|
|
18190
|
+
const variable = ASTUtils52.findVariable(context.sourceCode.getScope(binding), binding.name);
|
|
17839
18191
|
if (variable === null || variable.references.length === 0) return false;
|
|
17840
18192
|
return variable.references.every(
|
|
17841
18193
|
(reference) => belongsToFunction(reference.identifier, fn) && directlyCoalesced(reference.identifier)
|
|
17842
18194
|
);
|
|
17843
18195
|
}
|
|
17844
18196
|
function memberIsOnlyCoalesced(context, object, property, fn) {
|
|
17845
|
-
const variable =
|
|
18197
|
+
const variable = ASTUtils52.findVariable(context.sourceCode.getScope(object), object.name);
|
|
17846
18198
|
if (variable === null) return false;
|
|
17847
18199
|
const accesses = variable.references.flatMap((reference) => {
|
|
17848
18200
|
if (!belongsToFunction(reference.identifier, fn)) return [null];
|
|
@@ -17910,7 +18262,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
17910
18262
|
function checkDestructuredProperties(parameter, properties) {
|
|
17911
18263
|
for (const property of properties) {
|
|
17912
18264
|
const bindingProperty = parameter.properties.find(
|
|
17913
|
-
(entry) => entry.type === AST_NODE_TYPES90.Property && !entry.computed &&
|
|
18265
|
+
(entry) => entry.type === AST_NODE_TYPES90.Property && !entry.computed && ASTUtils52.getPropertyName(entry) === property.name
|
|
17914
18266
|
);
|
|
17915
18267
|
if (bindingProperty === void 0) continue;
|
|
17916
18268
|
const value = bindingProperty.value;
|
|
@@ -17958,7 +18310,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
17958
18310
|
// src/rules/prefer-nullish-filter-predicate.ts
|
|
17959
18311
|
import {
|
|
17960
18312
|
AST_NODE_TYPES as AST_NODE_TYPES91,
|
|
17961
|
-
ASTUtils as
|
|
18313
|
+
ASTUtils as ASTUtils53,
|
|
17962
18314
|
ESLintUtils as ESLintUtils12
|
|
17963
18315
|
} from "@typescript-eslint/utils";
|
|
17964
18316
|
import ts10 from "typescript";
|
|
@@ -18004,7 +18356,7 @@ var PREFER_NULLISH_FILTER_PREDICATE_DOCUMENTATION = {
|
|
|
18004
18356
|
]
|
|
18005
18357
|
};
|
|
18006
18358
|
function isUnshadowedBoolean(node, context) {
|
|
18007
|
-
const variable =
|
|
18359
|
+
const variable = ASTUtils53.findVariable(context.sourceCode.getScope(node), node.name);
|
|
18008
18360
|
return variable === null || variable.defs.length === 0;
|
|
18009
18361
|
}
|
|
18010
18362
|
function isBuiltinArrayFilter(node, services) {
|
|
@@ -18063,7 +18415,7 @@ function isProvablyTruthy(type, checker) {
|
|
|
18063
18415
|
}
|
|
18064
18416
|
function availableParameterName(node, context) {
|
|
18065
18417
|
for (const name of ["value", "item", "element", "candidate"]) {
|
|
18066
|
-
if (
|
|
18418
|
+
if (ASTUtils53.findVariable(context.sourceCode.getScope(node), name) === null) return name;
|
|
18067
18419
|
}
|
|
18068
18420
|
return null;
|
|
18069
18421
|
}
|
|
@@ -18094,7 +18446,7 @@ var prefer_nullish_filter_predicate_default = createRule({
|
|
|
18094
18446
|
CallExpression(node) {
|
|
18095
18447
|
const callee = unwrapExpression(node.callee);
|
|
18096
18448
|
const callback = node.arguments[0] === void 0 ? void 0 : unwrapExpression(node.arguments[0]);
|
|
18097
|
-
if (node.arguments.length !== 1 || callback?.type !== AST_NODE_TYPES91.Identifier || callback.name !== "Boolean" || callee.type !== AST_NODE_TYPES91.MemberExpression ||
|
|
18449
|
+
if (node.arguments.length !== 1 || callback?.type !== AST_NODE_TYPES91.Identifier || callback.name !== "Boolean" || callee.type !== AST_NODE_TYPES91.MemberExpression || ASTUtils53.getPropertyName(callee) === null || (ASTUtils53.getPropertyName(callee) ?? "") !== "filter" || !isUnshadowedBoolean(callback, context) || !isBuiltinArrayFilter(callee, services)) return;
|
|
18098
18450
|
const elementType = arrayElementType(callee.object, services);
|
|
18099
18451
|
const checker = services.program.getTypeChecker();
|
|
18100
18452
|
if (elementType === null || !isNullishPlusTruthy(elementType, checker)) return;
|
|
@@ -18117,7 +18469,7 @@ var prefer_nullish_filter_predicate_default = createRule({
|
|
|
18117
18469
|
|
|
18118
18470
|
// src/rules/prefer-await-in-async-return.ts
|
|
18119
18471
|
import {
|
|
18120
|
-
ASTUtils as
|
|
18472
|
+
ASTUtils as ASTUtils54,
|
|
18121
18473
|
ESLintUtils as ESLintUtils13,
|
|
18122
18474
|
AST_NODE_TYPES as AST_NODE_TYPES92
|
|
18123
18475
|
} from "@typescript-eslint/utils";
|
|
@@ -18180,7 +18532,7 @@ function isRuntimeFunction(node) {
|
|
|
18180
18532
|
}
|
|
18181
18533
|
function promiseThenReceiver(node) {
|
|
18182
18534
|
const callee = unwrapExpression(node.callee);
|
|
18183
|
-
if (callee.type !== AST_NODE_TYPES92.MemberExpression || callee.optional ||
|
|
18535
|
+
if (callee.type !== AST_NODE_TYPES92.MemberExpression || callee.optional || ASTUtils54.getPropertyName(callee) === null || (ASTUtils54.getPropertyName(callee) ?? "") !== "then" || node.optional || node.arguments.length !== 1) {
|
|
18184
18536
|
return null;
|
|
18185
18537
|
}
|
|
18186
18538
|
const argument = node.arguments[0];
|
|
@@ -18250,7 +18602,7 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
18250
18602
|
if (services === null) return {};
|
|
18251
18603
|
const frameworkLoaders = /* @__PURE__ */ new Set();
|
|
18252
18604
|
const rememberFrameworkLoader = (identifier) => {
|
|
18253
|
-
const variable =
|
|
18605
|
+
const variable = ASTUtils54.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
18254
18606
|
if (variable !== null) frameworkLoaders.add(variable);
|
|
18255
18607
|
};
|
|
18256
18608
|
const isFrameworkLoaderCallback = (owner) => {
|
|
@@ -18258,7 +18610,7 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
18258
18610
|
if (parent === null || parent.arguments[0] !== outerExpression(owner)) return false;
|
|
18259
18611
|
const callee = unwrapExpression(parent.callee);
|
|
18260
18612
|
if (callee.type !== AST_NODE_TYPES92.Identifier) return false;
|
|
18261
|
-
const variable =
|
|
18613
|
+
const variable = ASTUtils54.findVariable(context.sourceCode.getScope(callee), callee.name);
|
|
18262
18614
|
return variable !== null && frameworkLoaders.has(variable);
|
|
18263
18615
|
};
|
|
18264
18616
|
return {
|
|
@@ -18295,7 +18647,7 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
18295
18647
|
});
|
|
18296
18648
|
|
|
18297
18649
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
18298
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES93, ASTUtils as
|
|
18650
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES93, ASTUtils as ASTUtils55 } from "@typescript-eslint/utils";
|
|
18299
18651
|
var PREFER_SCHEMA_FOR_API_PAYLOAD_DOCUMENTATION = {
|
|
18300
18652
|
summary: "Require Zod (or similar) schema validation on `response.json()` / `JSON.parse()` results before property access.",
|
|
18301
18653
|
rationale: "External JSON is untrusted at runtime even when its expected TypeScript shape is known statically.",
|
|
@@ -18332,7 +18684,7 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
18332
18684
|
]);
|
|
18333
18685
|
var isSchemaParseReference = (node) => {
|
|
18334
18686
|
const inner = unwrap5(node);
|
|
18335
|
-
return inner !== null && inner.type === AST_NODE_TYPES93.MemberExpression &&
|
|
18687
|
+
return inner !== null && inner.type === AST_NODE_TYPES93.MemberExpression && ASTUtils55.getPropertyName(inner) !== null && ((ASTUtils55.getPropertyName(inner) ?? "") === "parse" || (ASTUtils55.getPropertyName(inner) ?? "") === "safeParse");
|
|
18336
18688
|
};
|
|
18337
18689
|
var isRawPayloadSource = (node, context, isKnownLocalText) => {
|
|
18338
18690
|
let current = unwrap5(node);
|
|
@@ -18347,7 +18699,7 @@ var isRawPayloadSource = (node, context, isKnownLocalText) => {
|
|
|
18347
18699
|
if (callee === null || callee.type !== AST_NODE_TYPES93.MemberExpression) {
|
|
18348
18700
|
return false;
|
|
18349
18701
|
}
|
|
18350
|
-
const property =
|
|
18702
|
+
const property = ASTUtils55.getPropertyName(callee);
|
|
18351
18703
|
if (property === null) {
|
|
18352
18704
|
return false;
|
|
18353
18705
|
}
|
|
@@ -18359,19 +18711,19 @@ var isRawPayloadSource = (node, context, isKnownLocalText) => {
|
|
|
18359
18711
|
}
|
|
18360
18712
|
const object = unwrap5(callee.object);
|
|
18361
18713
|
const input = unwrap5(current.arguments[0]);
|
|
18362
|
-
if (input?.type === AST_NODE_TYPES93.CallExpression && input.arguments.length === 1 && input.callee.type === AST_NODE_TYPES93.MemberExpression && input.callee.object.type === AST_NODE_TYPES93.Identifier && input.callee.object.name === "JSON" &&
|
|
18363
|
-
return property === "parse" && object !== null && object.type === AST_NODE_TYPES93.Identifier && object.name === "JSON" && (
|
|
18714
|
+
if (input?.type === AST_NODE_TYPES93.CallExpression && input.arguments.length === 1 && input.callee.type === AST_NODE_TYPES93.MemberExpression && input.callee.object.type === AST_NODE_TYPES93.Identifier && input.callee.object.name === "JSON" && ASTUtils55.getPropertyName(input.callee) === "stringify" && (ASTUtils55.findVariable(context.sourceCode.getScope(input.callee.object), "JSON")?.defs.length ?? 0) === 0) return false;
|
|
18715
|
+
return property === "parse" && object !== null && object.type === AST_NODE_TYPES93.Identifier && object.name === "JSON" && (ASTUtils55.findVariable(context.sourceCode.getScope(object), "JSON")?.defs.length ?? 0) === 0 && !isLocalFileRead(current.arguments[0]) && isKnownLocalText?.(current.arguments[0]) !== true;
|
|
18364
18716
|
};
|
|
18365
18717
|
var isResponseSource = (node, context, seen = /* @__PURE__ */ new Set()) => {
|
|
18366
18718
|
let current = unwrap5(node);
|
|
18367
18719
|
if (current?.type === AST_NODE_TYPES93.AwaitExpression) current = unwrap5(current.argument);
|
|
18368
18720
|
if (current === null || seen.has(current)) return false;
|
|
18369
18721
|
seen.add(current);
|
|
18370
|
-
const isGlobal = (identifier) => (
|
|
18722
|
+
const isGlobal = (identifier) => (ASTUtils55.findVariable(context.sourceCode.getScope(identifier), identifier.name)?.defs.length ?? 0) === 0;
|
|
18371
18723
|
if (current.type === AST_NODE_TYPES93.CallExpression) return current.callee.type === AST_NODE_TYPES93.Identifier && current.callee.name === "fetch" && isGlobal(current.callee);
|
|
18372
18724
|
if (current.type === AST_NODE_TYPES93.NewExpression) return current.callee.type === AST_NODE_TYPES93.Identifier && ["Request", "Response"].includes(current.callee.name) && isGlobal(current.callee);
|
|
18373
18725
|
if (current.type !== AST_NODE_TYPES93.Identifier) return false;
|
|
18374
|
-
const binding =
|
|
18726
|
+
const binding = ASTUtils55.findVariable(context.sourceCode.getScope(current), current.name);
|
|
18375
18727
|
if (binding?.defs.length !== 1 || binding.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
18376
18728
|
const definition = binding.defs[0];
|
|
18377
18729
|
const annotation = definition?.name.type === AST_NODE_TYPES93.Identifier ? definition.name.typeAnnotation?.typeAnnotation : void 0;
|
|
@@ -18386,7 +18738,7 @@ var isDirectLocalFileRead = (node) => {
|
|
|
18386
18738
|
}
|
|
18387
18739
|
if (current?.type !== AST_NODE_TYPES93.CallExpression) return false;
|
|
18388
18740
|
const callee = unwrap5(current.callee);
|
|
18389
|
-
const name = callee?.type === AST_NODE_TYPES93.Identifier ? callee.name : callee?.type === AST_NODE_TYPES93.MemberExpression &&
|
|
18741
|
+
const name = callee?.type === AST_NODE_TYPES93.Identifier ? callee.name : callee?.type === AST_NODE_TYPES93.MemberExpression && ASTUtils55.getPropertyName(callee) !== null ? ASTUtils55.getPropertyName(callee) ?? "" : null;
|
|
18390
18742
|
return name !== null && FILE_READ_RE.test(name);
|
|
18391
18743
|
};
|
|
18392
18744
|
var isLocalFileRead = (node) => {
|
|
@@ -18447,7 +18799,7 @@ var isValidationRead = (node) => {
|
|
|
18447
18799
|
return false;
|
|
18448
18800
|
}
|
|
18449
18801
|
const callee = parent.callee;
|
|
18450
|
-
if (callee.type === AST_NODE_TYPES93.MemberExpression && callee.object.type === AST_NODE_TYPES93.Identifier && callee.object.name === "Array" &&
|
|
18802
|
+
if (callee.type === AST_NODE_TYPES93.MemberExpression && callee.object.type === AST_NODE_TYPES93.Identifier && callee.object.name === "Array" && ASTUtils55.getPropertyName(callee) === "isArray") {
|
|
18451
18803
|
return parent.arguments.length === 1;
|
|
18452
18804
|
}
|
|
18453
18805
|
return callee.type === AST_NODE_TYPES93.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
@@ -18475,11 +18827,11 @@ var bindingValidationPolarity = (test, bindingName) => {
|
|
|
18475
18827
|
}
|
|
18476
18828
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
18477
18829
|
}
|
|
18478
|
-
return test.type === AST_NODE_TYPES93.CallExpression && test.arguments.length === 1 && test.arguments[0]?.type === AST_NODE_TYPES93.Identifier && test.arguments[0].name === bindingName && test.callee.type === AST_NODE_TYPES93.MemberExpression && test.callee.object.type === AST_NODE_TYPES93.Identifier && test.callee.object.name === "Array" &&
|
|
18830
|
+
return test.type === AST_NODE_TYPES93.CallExpression && test.arguments.length === 1 && test.arguments[0]?.type === AST_NODE_TYPES93.Identifier && test.arguments[0].name === bindingName && test.callee.type === AST_NODE_TYPES93.MemberExpression && test.callee.object.type === AST_NODE_TYPES93.Identifier && test.callee.object.name === "Array" && ASTUtils55.getPropertyName(test.callee) === "isArray" ? "valid-when-true" : null;
|
|
18479
18831
|
};
|
|
18480
18832
|
var plainMemberAccess = (node) => {
|
|
18481
18833
|
if (node.type !== AST_NODE_TYPES93.MemberExpression || node.object.type !== AST_NODE_TYPES93.Identifier) return null;
|
|
18482
|
-
const property =
|
|
18834
|
+
const property = ASTUtils55.getPropertyName(node);
|
|
18483
18835
|
return property === null ? null : { object: node.object.name, property };
|
|
18484
18836
|
};
|
|
18485
18837
|
var isSamePlainMember = (node, access) => {
|
|
@@ -18543,7 +18895,7 @@ var memberValidationPolarity = (test, access) => {
|
|
|
18543
18895
|
}
|
|
18544
18896
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
18545
18897
|
}
|
|
18546
|
-
return test.type === AST_NODE_TYPES93.CallExpression && test.arguments.length === 1 && test.arguments[0] !== void 0 && test.arguments[0].type !== AST_NODE_TYPES93.SpreadElement && isSamePlainMember(test.arguments[0], access) && test.callee.type === AST_NODE_TYPES93.MemberExpression && test.callee.object.type === AST_NODE_TYPES93.Identifier && test.callee.object.name === "Array" &&
|
|
18898
|
+
return test.type === AST_NODE_TYPES93.CallExpression && test.arguments.length === 1 && test.arguments[0] !== void 0 && test.arguments[0].type !== AST_NODE_TYPES93.SpreadElement && isSamePlainMember(test.arguments[0], access) && test.callee.type === AST_NODE_TYPES93.MemberExpression && test.callee.object.type === AST_NODE_TYPES93.Identifier && test.callee.object.name === "Array" && ASTUtils55.getPropertyName(test.callee) === "isArray" ? "valid-when-true" : null;
|
|
18547
18899
|
};
|
|
18548
18900
|
var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
18549
18901
|
const isValidationReference = (identifier) => {
|
|
@@ -18826,7 +19178,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
18826
19178
|
(candidate2) => localFileTextRef(candidate2, scope) !== null
|
|
18827
19179
|
)) {
|
|
18828
19180
|
const parent = node.parent;
|
|
18829
|
-
const method =
|
|
19181
|
+
const method = ASTUtils55.getPropertyName(node);
|
|
18830
19182
|
if (parent.type === AST_NODE_TYPES93.CallExpression && parent.callee === node && method !== null && (method === "parse" || method === "safeParse" || PROMISE_CHAIN_METHODS.has(method))) {
|
|
18831
19183
|
return;
|
|
18832
19184
|
}
|
|
@@ -18879,7 +19231,7 @@ function ifGuardDominates(use, branch, positive) {
|
|
|
18879
19231
|
}
|
|
18880
19232
|
|
|
18881
19233
|
// src/rules/prefer-shared-zod-enum.ts
|
|
18882
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES94, ASTUtils as
|
|
19234
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES94, ASTUtils as ASTUtils56 } from "@typescript-eslint/utils";
|
|
18883
19235
|
var PREFER_SHARED_ZOD_ENUM_DOCUMENTATION = {
|
|
18884
19236
|
defaultLevel: "warning",
|
|
18885
19237
|
summary: "Give repeated literal Zod enum domains one reusable module-level schema.",
|
|
@@ -18929,7 +19281,7 @@ var prefer_shared_zod_enum_default = createRule({
|
|
|
18929
19281
|
create(context) {
|
|
18930
19282
|
if (isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text)) return {};
|
|
18931
19283
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
18932
|
-
const bindingOf = (node) =>
|
|
19284
|
+
const bindingOf = (node) => ASTUtils56.findVariable(context.sourceCode.getScope(node), node.name);
|
|
18933
19285
|
const candidates = /* @__PURE__ */ new Map();
|
|
18934
19286
|
return {
|
|
18935
19287
|
ImportDeclaration(node) {
|
|
@@ -18944,7 +19296,7 @@ var prefer_shared_zod_enum_default = createRule({
|
|
|
18944
19296
|
CallExpression(node) {
|
|
18945
19297
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
18946
19298
|
const receiver = unwrappedNodeCallee.type === AST_NODE_TYPES94.MemberExpression ? unwrapExpression(unwrappedNodeCallee.object) : unwrappedNodeCallee;
|
|
18947
|
-
if (unwrappedNodeCallee.type !== AST_NODE_TYPES94.MemberExpression || receiver.type !== AST_NODE_TYPES94.Identifier ||
|
|
19299
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES94.MemberExpression || receiver.type !== AST_NODE_TYPES94.Identifier || ASTUtils56.getPropertyName(unwrappedNodeCallee) === null || (ASTUtils56.getPropertyName(unwrappedNodeCallee) ?? "") !== "enum") return;
|
|
18948
19300
|
const binding = bindingOf(receiver);
|
|
18949
19301
|
if (binding === null || !zodBindings.has(binding)) return;
|
|
18950
19302
|
const domain = literalDomain(node);
|
|
@@ -19566,7 +19918,7 @@ function packageWorkspaceGlobs(parsed) {
|
|
|
19566
19918
|
}
|
|
19567
19919
|
|
|
19568
19920
|
// src/rules/prefer-server-actions.ts
|
|
19569
|
-
import { ASTUtils as
|
|
19921
|
+
import { ASTUtils as ASTUtils57 } from "@typescript-eslint/utils";
|
|
19570
19922
|
var PREFER_SERVER_ACTIONS_DOCUMENTATION = {
|
|
19571
19923
|
summary: "Prefer Next.js Server Actions over same-origin API mutations.",
|
|
19572
19924
|
rationale: "Server Actions can remove a hand-written internal API wrapper while retaining typed application calls. Client invocations still cross a network and serialization boundary.",
|
|
@@ -19599,7 +19951,7 @@ function resolveNode(node, context) {
|
|
|
19599
19951
|
node = node == null ? node : unwrapExpression(node);
|
|
19600
19952
|
if (!node) return null;
|
|
19601
19953
|
if (node.type !== "Identifier") return node;
|
|
19602
|
-
const variable =
|
|
19954
|
+
const variable = ASTUtils57.findVariable(getScope(context, node), node.name);
|
|
19603
19955
|
const definition = variable?.defs.length === 1 ? variable.defs[0] : void 0;
|
|
19604
19956
|
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init === null || variable?.references.some((reference) => reference.isWrite() && reference.init !== true)) return node;
|
|
19605
19957
|
if (definition.node.init.type === "ObjectExpression" && variable?.references.some((reference) => reference.identifier !== node && reference.init !== true)) return node;
|
|
@@ -19608,7 +19960,7 @@ function resolveNode(node, context) {
|
|
|
19608
19960
|
function isAxiosClient(node, context, seen = /* @__PURE__ */ new Set()) {
|
|
19609
19961
|
if (node.type !== "Identifier" || seen.has(node)) return false;
|
|
19610
19962
|
seen.add(node);
|
|
19611
|
-
const variable =
|
|
19963
|
+
const variable = ASTUtils57.findVariable(getScope(context, node), node.name);
|
|
19612
19964
|
const definition = variable?.defs.length === 1 ? variable.defs[0] : void 0;
|
|
19613
19965
|
if (definition === void 0 || variable?.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
19614
19966
|
if (variable?.references.some((reference) => {
|
|
@@ -19692,10 +20044,10 @@ function isFunctionArgument(node, context) {
|
|
|
19692
20044
|
}
|
|
19693
20045
|
function getPropertyNode(objNode, propName2) {
|
|
19694
20046
|
if (!objNode || objNode.type !== "ObjectExpression") return null;
|
|
19695
|
-
if (objNode.properties.some((property) => property.type === "SpreadElement" ||
|
|
20047
|
+
if (objNode.properties.some((property) => property.type === "SpreadElement" || ASTUtils57.getPropertyName(property) === null)) return null;
|
|
19696
20048
|
for (const prop of [...objNode.properties].reverse()) {
|
|
19697
20049
|
if (prop.type !== "Property") continue;
|
|
19698
|
-
const keyName =
|
|
20050
|
+
const keyName = ASTUtils57.getPropertyName(prop);
|
|
19699
20051
|
if (keyName === propName2) {
|
|
19700
20052
|
if (prop.value.type === "AssignmentPattern" || prop.value.type === "ArrayPattern" || prop.value.type === "ObjectPattern") {
|
|
19701
20053
|
return null;
|
|
@@ -19819,7 +20171,7 @@ var prefer_server_actions_default = createRule({
|
|
|
19819
20171
|
});
|
|
19820
20172
|
|
|
19821
20173
|
// src/rules/prefer-whole-object-assertion.ts
|
|
19822
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES97, ASTUtils as
|
|
20174
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES97, ASTUtils as ASTUtils58 } from "@typescript-eslint/utils";
|
|
19823
20175
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
19824
20176
|
var SYNTHETIC_LITERAL_MATCHERS = /* @__PURE__ */ new Map([
|
|
19825
20177
|
["toBeNull", "null"]
|
|
@@ -19884,7 +20236,7 @@ function propertyAccess(node) {
|
|
|
19884
20236
|
const path = [];
|
|
19885
20237
|
let current = node;
|
|
19886
20238
|
while (current.type === AST_NODE_TYPES97.MemberExpression && !current.optional) {
|
|
19887
|
-
const name =
|
|
20239
|
+
const name = ASTUtils58.getPropertyName(current);
|
|
19888
20240
|
if (name === null || COLLECTION_PROPERTIES.has(name) || LITERAL_KEY_HAZARDS.has(name)) return null;
|
|
19889
20241
|
path.unshift(name);
|
|
19890
20242
|
current = unwrapExpression(current.object);
|
|
@@ -20031,7 +20383,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
20031
20383
|
const callee = unwrapExpression(call.callee);
|
|
20032
20384
|
const calleeReceiver = callee.type === AST_NODE_TYPES97.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
20033
20385
|
if (callee.type !== AST_NODE_TYPES97.MemberExpression) return null;
|
|
20034
|
-
const matcher =
|
|
20386
|
+
const matcher = ASTUtils58.getPropertyName(callee);
|
|
20035
20387
|
if (matcher === null) return null;
|
|
20036
20388
|
const expectCall = calleeReceiver;
|
|
20037
20389
|
const expectCallee = expectCall.type === AST_NODE_TYPES97.CallExpression ? unwrapExpression(expectCall.callee) : null;
|
|
@@ -20061,7 +20413,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
20061
20413
|
return assertionExpectation(statement, call, receiver, key, matcher);
|
|
20062
20414
|
}
|
|
20063
20415
|
function isTestExpect(callee) {
|
|
20064
|
-
const variable =
|
|
20416
|
+
const variable = ASTUtils58.findVariable(sourceCode.getScope(callee), callee.name);
|
|
20065
20417
|
if (variable !== null && variable.defs.some((definition) => {
|
|
20066
20418
|
if (definition.node.type !== AST_NODE_TYPES97.ImportSpecifier) return true;
|
|
20067
20419
|
const declaration = definition.node.parent;
|
|
@@ -20104,7 +20456,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
20104
20456
|
});
|
|
20105
20457
|
|
|
20106
20458
|
// src/rules/repeated-static-call-cases.ts
|
|
20107
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES98, ASTUtils as
|
|
20459
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES98, ASTUtils as ASTUtils59 } from "@typescript-eslint/utils";
|
|
20108
20460
|
var REPEATED_STATIC_CALL_CASES_DOCUMENTATION = {
|
|
20109
20461
|
summary: "Review three or more consecutive static-input call assertions as potential named cases.",
|
|
20110
20462
|
rationale: "Copy-pasted cases obscure the input table, and a thrown assertion can stop later cases from being reported.",
|
|
@@ -20125,7 +20477,7 @@ var EXPECT_MODIFIERS = /* @__PURE__ */ new Set(["not", "rejects", "resolves"]);
|
|
|
20125
20477
|
var SNAPSHOT_MATCHERS = /snapshot/iu;
|
|
20126
20478
|
var MIN_CASES2 = 3;
|
|
20127
20479
|
function importedName6(identifier, context, modules) {
|
|
20128
|
-
const variable =
|
|
20480
|
+
const variable = ASTUtils59.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
20129
20481
|
if (variable === null || variable.defs.length === 0) return identifier.name;
|
|
20130
20482
|
for (const definition of variable.defs) {
|
|
20131
20483
|
if (definition.node.type !== AST_NODE_TYPES98.ImportSpecifier) continue;
|
|
@@ -20147,7 +20499,7 @@ function testRoot2(callee) {
|
|
|
20147
20499
|
callee = unwrapExpression(callee);
|
|
20148
20500
|
if (callee.type === AST_NODE_TYPES98.Identifier) return callee;
|
|
20149
20501
|
if (callee.type !== AST_NODE_TYPES98.MemberExpression) return null;
|
|
20150
|
-
const modifier =
|
|
20502
|
+
const modifier = ASTUtils59.getPropertyName(callee);
|
|
20151
20503
|
return modifier !== null && TEST_MODIFIERS5.has(modifier) ? testRoot2(callee.object) : null;
|
|
20152
20504
|
}
|
|
20153
20505
|
function isStatic(input) {
|
|
@@ -20193,8 +20545,8 @@ function assertionShape(statement, context, callback) {
|
|
|
20193
20545
|
const matcherCall = unwrapExpression(statement.expression);
|
|
20194
20546
|
if (matcherCall.type !== AST_NODE_TYPES98.CallExpression) return null;
|
|
20195
20547
|
const matcherCallee = unwrapExpression(matcherCall.callee);
|
|
20196
|
-
if (matcherCallee.type !== AST_NODE_TYPES98.MemberExpression ||
|
|
20197
|
-
const matcher =
|
|
20548
|
+
if (matcherCallee.type !== AST_NODE_TYPES98.MemberExpression || ASTUtils59.getPropertyName(matcherCallee) === null || matcherCall.arguments.length !== 1) return null;
|
|
20549
|
+
const matcher = ASTUtils59.getPropertyName(matcherCallee) ?? "";
|
|
20198
20550
|
if (SNAPSHOT_MATCHERS.test(matcher)) return null;
|
|
20199
20551
|
const chain = expectCallFromMatcher(matcherCallee);
|
|
20200
20552
|
const expectCallee = chain === null ? null : unwrapExpression(chain.call.callee);
|
|
@@ -20204,7 +20556,7 @@ function assertionShape(statement, context, callback) {
|
|
|
20204
20556
|
const observedCallee = observed?.type === AST_NODE_TYPES98.CallExpression ? unwrapExpression(observed.callee) : null;
|
|
20205
20557
|
if (observed?.type !== AST_NODE_TYPES98.CallExpression || observedCallee?.type !== AST_NODE_TYPES98.Identifier || observed.arguments.length === 0 || observed.arguments.some((arg) => arg.type === AST_NODE_TYPES98.SpreadElement || !isStatic(arg)) || expected?.type === AST_NODE_TYPES98.SpreadElement || expected === void 0 || !isStatic(expected)) return null;
|
|
20206
20558
|
const skeleton = `${observedCallee.name}/${observed.arguments.map((item) => staticShape(item)).join(",")}/${chain.modifiers.join(".")}/${matcher}/${staticShape(expected)}`;
|
|
20207
|
-
const binding =
|
|
20559
|
+
const binding = ASTUtils59.findVariable(context.sourceCode.getScope(observedCallee), observedCallee.name);
|
|
20208
20560
|
if (binding?.defs.some(
|
|
20209
20561
|
(definition) => definition.node.range[0] >= callback.range[0] && definition.node.range[1] <= callback.range[1]
|
|
20210
20562
|
)) return null;
|
|
@@ -20215,7 +20567,7 @@ function expectCallFromMatcher(node) {
|
|
|
20215
20567
|
const modifiers = [];
|
|
20216
20568
|
let receiver = node.object;
|
|
20217
20569
|
while (receiver.type === AST_NODE_TYPES98.MemberExpression) {
|
|
20218
|
-
const modifier =
|
|
20570
|
+
const modifier = ASTUtils59.getPropertyName(receiver);
|
|
20219
20571
|
if (modifier === null || !EXPECT_MODIFIERS.has(modifier)) return null;
|
|
20220
20572
|
modifiers.unshift(modifier);
|
|
20221
20573
|
receiver = receiver.object;
|
|
@@ -20291,7 +20643,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
20291
20643
|
});
|
|
20292
20644
|
|
|
20293
20645
|
// src/rules/prefer-zod-infer.ts
|
|
20294
|
-
import { ASTUtils as
|
|
20646
|
+
import { ASTUtils as ASTUtils60, AST_NODE_TYPES as AST_NODE_TYPES99 } from "@typescript-eslint/utils";
|
|
20295
20647
|
var PREFER_ZOD_INFER_DOCUMENTATION = {
|
|
20296
20648
|
summary: "Derive a type from its Zod schema with `z.infer` instead of hand-writing a twin declaration beside it.",
|
|
20297
20649
|
rationale: "A derived type stays synchronized when the runtime schema changes.",
|
|
@@ -20609,7 +20961,7 @@ function twinCallChain(node, zodNamespaces) {
|
|
|
20609
20961
|
while (current.type === AST_NODE_TYPES99.CallExpression) {
|
|
20610
20962
|
const callee = unwrapExpression(current.callee);
|
|
20611
20963
|
const calleeReceiver = callee.type === AST_NODE_TYPES99.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
20612
|
-
if (callee.type !== AST_NODE_TYPES99.MemberExpression ||
|
|
20964
|
+
if (callee.type !== AST_NODE_TYPES99.MemberExpression || ASTUtils60.getPropertyName(callee) === null) {
|
|
20613
20965
|
return null;
|
|
20614
20966
|
}
|
|
20615
20967
|
chain.push(current);
|
|
@@ -20622,7 +20974,7 @@ function twinCallChain(node, zodNamespaces) {
|
|
|
20622
20974
|
}
|
|
20623
20975
|
function twinMethodName(call) {
|
|
20624
20976
|
const callee = unwrapExpression(call.callee);
|
|
20625
|
-
return callee.type === AST_NODE_TYPES99.MemberExpression &&
|
|
20977
|
+
return callee.type === AST_NODE_TYPES99.MemberExpression && ASTUtils60.getPropertyName(callee) !== null ? ASTUtils60.getPropertyName(callee) ?? "" : "";
|
|
20626
20978
|
}
|
|
20627
20979
|
function twinSchemaFields(initializer, zodNamespaces) {
|
|
20628
20980
|
const chain = twinCallChain(initializer, zodNamespaces);
|
|
@@ -20637,7 +20989,7 @@ function twinSchemaFields(initializer, zodNamespaces) {
|
|
|
20637
20989
|
const fields = /* @__PURE__ */ new Map();
|
|
20638
20990
|
for (const property of shape.properties) {
|
|
20639
20991
|
if (property.type !== AST_NODE_TYPES99.Property) return null;
|
|
20640
|
-
const name =
|
|
20992
|
+
const name = ASTUtils60.getPropertyName(property);
|
|
20641
20993
|
if (name === null) return null;
|
|
20642
20994
|
fields.set(name, twinSchemaField(property.value, zodNamespaces));
|
|
20643
20995
|
}
|
|
@@ -20651,16 +21003,16 @@ function twinSchemaField(node, zodNamespaces) {
|
|
|
20651
21003
|
while (current.type === AST_NODE_TYPES99.CallExpression) {
|
|
20652
21004
|
const callee = unwrapExpression(current.callee);
|
|
20653
21005
|
const calleeReceiver = callee.type === AST_NODE_TYPES99.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
20654
|
-
if (callee.type !== AST_NODE_TYPES99.MemberExpression ||
|
|
21006
|
+
if (callee.type !== AST_NODE_TYPES99.MemberExpression || ASTUtils60.getPropertyName(callee) === null) {
|
|
20655
21007
|
break;
|
|
20656
21008
|
}
|
|
20657
21009
|
const receiver = calleeReceiver;
|
|
20658
21010
|
if (receiver.type === AST_NODE_TYPES99.Identifier && zodNamespaces.has(receiver.name)) {
|
|
20659
|
-
leaf =
|
|
21011
|
+
leaf = ASTUtils60.getPropertyName(callee) ?? "";
|
|
20660
21012
|
leafCall = current;
|
|
20661
21013
|
break;
|
|
20662
21014
|
}
|
|
20663
|
-
modifiers.push(
|
|
21015
|
+
modifiers.push(ASTUtils60.getPropertyName(callee) ?? "");
|
|
20664
21016
|
current = receiver;
|
|
20665
21017
|
}
|
|
20666
21018
|
return {
|
|
@@ -20863,7 +21215,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
20863
21215
|
},
|
|
20864
21216
|
/** Records `XSchema.transform(...)` and equivalent module-level reshaping. */
|
|
20865
21217
|
"MemberExpression"(node) {
|
|
20866
|
-
if (node.object.type === AST_NODE_TYPES99.Identifier &&
|
|
21218
|
+
if (node.object.type === AST_NODE_TYPES99.Identifier && ASTUtils60.getPropertyName(node) !== null && isPreferZodInferModuleReshaper(ASTUtils60.getPropertyName(node) ?? "")) {
|
|
20867
21219
|
reshapedSchemaNames.add(node.object.name);
|
|
20868
21220
|
}
|
|
20869
21221
|
},
|
|
@@ -21019,10 +21371,114 @@ function staticFieldName(key) {
|
|
|
21019
21371
|
return key.type === AST_NODE_TYPES99.Identifier ? key.name : key.type === AST_NODE_TYPES99.Literal && typeof key.value === "string" ? key.value : null;
|
|
21020
21372
|
}
|
|
21021
21373
|
|
|
21374
|
+
// src/rules/named-child-schema-type.ts
|
|
21375
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES100, ASTUtils as ASTUtils61 } from "@typescript-eslint/utils";
|
|
21376
|
+
var UNRESOLVED_TYPE_NODES = /* @__PURE__ */ new Set([
|
|
21377
|
+
AST_NODE_TYPES100.TSTypeQuery,
|
|
21378
|
+
AST_NODE_TYPES100.TSImportType,
|
|
21379
|
+
AST_NODE_TYPES100.TSTypeParameter,
|
|
21380
|
+
AST_NODE_TYPES100.TSAnyKeyword,
|
|
21381
|
+
AST_NODE_TYPES100.TSUnknownKeyword
|
|
21382
|
+
]);
|
|
21383
|
+
var NAMED_CHILD_SCHEMA_TYPE_DOCUMENTATION = {
|
|
21384
|
+
defaultLevel: "warning",
|
|
21385
|
+
summary: "Reference a named Zod record child's complete schema type instead of repeating its explicit annotation.",
|
|
21386
|
+
rationale: "Repeating a child schema's generic contract creates a second maintained declaration even though the record already uses that child at runtime.",
|
|
21387
|
+
remediation: "Replace only the matching record type argument with `typeof ChildSchema`; retain the outer annotation required by isolatedDeclarations and every runtime schema operation.",
|
|
21388
|
+
category: "maintainability",
|
|
21389
|
+
autofix: "none",
|
|
21390
|
+
limitations: [
|
|
21391
|
+
"Only direct module-level const z.record calls with two arguments, a ZodRecord annotation, and an earlier local const child with a complete explicit Zod type are inspected.",
|
|
21392
|
+
"The entire generic child annotation must match token for token; input/output, defaults, transforms, readonly modifiers and brands are never compared by output shape alone.",
|
|
21393
|
+
"Bare leaf types, broad ZodType constraints, type queries, imported or unqualified type references, annotation cycles, comments on the repeated argument, mutable bindings and generated files are excluded.",
|
|
21394
|
+
"Import aliases and namespace imports resolve through scope bindings. Independent public contract pins require review; this warning does not remove annotations or change runtime validation."
|
|
21395
|
+
],
|
|
21396
|
+
examples: [
|
|
21397
|
+
{ id: "named-child", title: "Reference the named child contract", outcome: "no-match", files: [{ path: "src/record.ts", source: 'import { z } from "zod"; const KeySchema: z.ZodEnum<{ a: "a"; b: "b" }> = z.enum(["a", "b"]); export const RecordSchema: z.ZodRecord<typeof KeySchema, z.ZodString> = z.record(KeySchema, z.string());' }], focusPath: "src/record.ts", expectedCount: 0, public: true },
|
|
21398
|
+
{ id: "copied-child", title: "Do not repeat the complete child annotation", outcome: "match", files: [{ path: "src/record.ts", source: 'import { z } from "zod"; const KeySchema: z.ZodEnum<{ a: "a"; b: "b" }> = z.enum(["a", "b"]); export const RecordSchema: z.ZodRecord<z.ZodEnum<{ a: "a"; b: "b" }>, z.ZodString> = z.record(KeySchema, z.string());' }], focusPath: "src/record.ts", expectedCount: 1, public: true }
|
|
21399
|
+
]
|
|
21400
|
+
};
|
|
21401
|
+
function isModuleConst(node) {
|
|
21402
|
+
if (node.parent.kind !== "const" || node.id.type !== AST_NODE_TYPES100.Identifier) return false;
|
|
21403
|
+
const parent = node.parent.parent;
|
|
21404
|
+
return parent.type === AST_NODE_TYPES100.Program || parent.type === AST_NODE_TYPES100.ExportNamedDeclaration && parent.parent.type === AST_NODE_TYPES100.Program;
|
|
21405
|
+
}
|
|
21406
|
+
var named_child_schema_type_default = createRule({
|
|
21407
|
+
name: "named-child-schema-type",
|
|
21408
|
+
documentation: NAMED_CHILD_SCHEMA_TYPE_DOCUMENTATION,
|
|
21409
|
+
meta: {
|
|
21410
|
+
type: "suggestion",
|
|
21411
|
+
docs: { description: NAMED_CHILD_SCHEMA_TYPE_DOCUMENTATION.summary },
|
|
21412
|
+
schema: [],
|
|
21413
|
+
messages: { namedChildType: "Use `typeof {{name}}` for this exact child contract; keep the outer schema annotation and runtime operations." }
|
|
21414
|
+
},
|
|
21415
|
+
defaultOptions: [],
|
|
21416
|
+
create(context) {
|
|
21417
|
+
const source = context.sourceCode;
|
|
21418
|
+
if (isGeneratedFile(context.filename, source.text)) return {};
|
|
21419
|
+
const namespaces = /* @__PURE__ */ new Set();
|
|
21420
|
+
const bindingOf = (node) => ASTUtils61.findVariable(source.getScope(node), node.name);
|
|
21421
|
+
function namespaceOf(type) {
|
|
21422
|
+
if (type.typeName.type !== AST_NODE_TYPES100.TSQualifiedName || type.typeName.left.type !== AST_NODE_TYPES100.Identifier) return null;
|
|
21423
|
+
const binding = bindingOf(type.typeName.left);
|
|
21424
|
+
return binding !== null && namespaces.has(binding) ? binding : null;
|
|
21425
|
+
}
|
|
21426
|
+
function closedType(node, namespace) {
|
|
21427
|
+
if (UNRESOLVED_TYPE_NODES.has(node.type)) return false;
|
|
21428
|
+
if (node.type === AST_NODE_TYPES100.TSTypeReference && namespaceOf(node) !== namespace) return false;
|
|
21429
|
+
return !forEachOwnAstChild(node, (child) => !closedType(child, namespace));
|
|
21430
|
+
}
|
|
21431
|
+
function inspectChild(argument, repeated, namespace, parent) {
|
|
21432
|
+
if (argument.type !== AST_NODE_TYPES100.Identifier || repeated.type !== AST_NODE_TYPES100.TSTypeReference || repeated.typeArguments === void 0) return;
|
|
21433
|
+
if (repeated.typeName.type !== AST_NODE_TYPES100.TSQualifiedName || /^(?:ZodType|ZodSchema|ZodTypeAny)$/u.test(repeated.typeName.right.name)) return;
|
|
21434
|
+
const variable = bindingOf(argument);
|
|
21435
|
+
const definition = variable?.defs.length === 1 ? variable.defs[0] : void 0;
|
|
21436
|
+
if (definition?.type !== "Variable" || !isModuleConst(definition.node)) return;
|
|
21437
|
+
const child = definition.node;
|
|
21438
|
+
if (child.id.type !== AST_NODE_TYPES100.Identifier || child.init === null || child.range[0] >= parent.range[0]) return;
|
|
21439
|
+
const annotation = child.id.typeAnnotation?.typeAnnotation;
|
|
21440
|
+
if (annotation === void 0 || factoryNamespace(child.init) !== namespace || !closedType(annotation, namespace)) return;
|
|
21441
|
+
if (source.getCommentsInside(repeated).length > 0 || source.getCommentsBefore(repeated).length > 0) return;
|
|
21442
|
+
const expected = source.getTokens(annotation);
|
|
21443
|
+
const actual = source.getTokens(repeated);
|
|
21444
|
+
if (expected.length !== actual.length || expected.some((token, index) => token.type !== actual[index]?.type || token.value !== actual[index]?.value)) return;
|
|
21445
|
+
context.report({ node: repeated, messageId: "namedChildType", data: { name: argument.name } });
|
|
21446
|
+
}
|
|
21447
|
+
function factoryNamespace(expression) {
|
|
21448
|
+
if (expression.type !== AST_NODE_TYPES100.CallExpression || expression.callee.type !== AST_NODE_TYPES100.MemberExpression) return null;
|
|
21449
|
+
const object = expression.callee.object;
|
|
21450
|
+
return object.type === AST_NODE_TYPES100.Identifier ? bindingOf(object) : factoryNamespace(object);
|
|
21451
|
+
}
|
|
21452
|
+
return {
|
|
21453
|
+
ImportDeclaration(node) {
|
|
21454
|
+
if (node.importKind === "type" || !isZodModule(node.source.value)) return;
|
|
21455
|
+
for (const specifier of node.specifiers) {
|
|
21456
|
+
if (specifier.type !== AST_NODE_TYPES100.ImportNamespaceSpecifier && (specifier.type !== AST_NODE_TYPES100.ImportSpecifier || specifier.importKind === "type" || importSpecifierName(specifier) !== "z")) continue;
|
|
21457
|
+
const binding = bindingOf(specifier.local);
|
|
21458
|
+
if (binding !== null) namespaces.add(binding);
|
|
21459
|
+
}
|
|
21460
|
+
},
|
|
21461
|
+
VariableDeclarator(node) {
|
|
21462
|
+
if (!isModuleConst(node) || node.id.type !== AST_NODE_TYPES100.Identifier || node.init?.type !== AST_NODE_TYPES100.CallExpression) return;
|
|
21463
|
+
const call = node.init;
|
|
21464
|
+
if (call.arguments.length !== 2 || call.callee.type !== AST_NODE_TYPES100.MemberExpression || call.callee.object.type !== AST_NODE_TYPES100.Identifier || ASTUtils61.getPropertyName(call.callee) !== "record") return;
|
|
21465
|
+
const annotation = node.id.typeAnnotation?.typeAnnotation;
|
|
21466
|
+
if (annotation?.type !== AST_NODE_TYPES100.TSTypeReference || annotation.typeName.type !== AST_NODE_TYPES100.TSQualifiedName || annotation.typeName.right.name !== "ZodRecord") return;
|
|
21467
|
+
const namespace = namespaceOf(annotation);
|
|
21468
|
+
if (namespace === null || bindingOf(call.callee.object) !== namespace || annotation.typeArguments?.params.length !== 2) return;
|
|
21469
|
+
for (const [index, argument] of call.arguments.entries()) {
|
|
21470
|
+
const repeated = annotation.typeArguments.params[index];
|
|
21471
|
+
if (repeated !== void 0) inspectChild(argument, repeated, namespace, node);
|
|
21472
|
+
}
|
|
21473
|
+
}
|
|
21474
|
+
};
|
|
21475
|
+
}
|
|
21476
|
+
});
|
|
21477
|
+
|
|
21022
21478
|
// src/rules/prefer-zod-parse-output-type.ts
|
|
21023
21479
|
import {
|
|
21024
|
-
ASTUtils as
|
|
21025
|
-
AST_NODE_TYPES as
|
|
21480
|
+
ASTUtils as ASTUtils62,
|
|
21481
|
+
AST_NODE_TYPES as AST_NODE_TYPES101,
|
|
21026
21482
|
ESLintUtils as ESLintUtils14
|
|
21027
21483
|
} from "@typescript-eslint/utils";
|
|
21028
21484
|
import ts12 from "typescript";
|
|
@@ -21080,22 +21536,22 @@ var PREFER_ZOD_PARSE_OUTPUT_TYPE_DOCUMENTATION = {
|
|
|
21080
21536
|
};
|
|
21081
21537
|
function isModuleLevelConst2(node) {
|
|
21082
21538
|
const declaration = node.parent;
|
|
21083
|
-
if (declaration.type !==
|
|
21539
|
+
if (declaration.type !== AST_NODE_TYPES101.VariableDeclaration || declaration.kind !== "const") {
|
|
21084
21540
|
return false;
|
|
21085
21541
|
}
|
|
21086
21542
|
const container = declaration.parent;
|
|
21087
|
-
return container.type ===
|
|
21543
|
+
return container.type === AST_NODE_TYPES101.Program || container.type === AST_NODE_TYPES101.ExportNamedDeclaration && container.parent.type === AST_NODE_TYPES101.Program;
|
|
21088
21544
|
}
|
|
21089
21545
|
function isLocalZodObjectSchema(node, namespaces) {
|
|
21090
21546
|
let current = node;
|
|
21091
|
-
while (current.type ===
|
|
21547
|
+
while (current.type === AST_NODE_TYPES101.CallExpression) {
|
|
21092
21548
|
const callee = unwrapExpression(current.callee);
|
|
21093
|
-
const calleeReceiver = callee.type ===
|
|
21094
|
-
if (callee.type !==
|
|
21549
|
+
const calleeReceiver = callee.type === AST_NODE_TYPES101.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
21550
|
+
if (callee.type !== AST_NODE_TYPES101.MemberExpression || ASTUtils62.getPropertyName(callee) === null) {
|
|
21095
21551
|
return false;
|
|
21096
21552
|
}
|
|
21097
|
-
if (calleeReceiver.type ===
|
|
21098
|
-
return namespaces.has(calleeReceiver.name) && ((
|
|
21553
|
+
if (calleeReceiver.type === AST_NODE_TYPES101.Identifier) {
|
|
21554
|
+
return namespaces.has(calleeReceiver.name) && ((ASTUtils62.getPropertyName(callee) ?? "") === "object" || (ASTUtils62.getPropertyName(callee) ?? "") === "strictObject");
|
|
21099
21555
|
}
|
|
21100
21556
|
current = calleeReceiver;
|
|
21101
21557
|
}
|
|
@@ -21103,11 +21559,11 @@ function isLocalZodObjectSchema(node, namespaces) {
|
|
|
21103
21559
|
}
|
|
21104
21560
|
function zodParseCall(node) {
|
|
21105
21561
|
const callee = unwrapExpression(node.callee);
|
|
21106
|
-
const calleeReceiver = callee.type ===
|
|
21107
|
-
if (callee.type !==
|
|
21562
|
+
const calleeReceiver = callee.type === AST_NODE_TYPES101.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
21563
|
+
if (callee.type !== AST_NODE_TYPES101.MemberExpression || calleeReceiver.type !== AST_NODE_TYPES101.Identifier || ASTUtils62.getPropertyName(callee) === null) {
|
|
21108
21564
|
return null;
|
|
21109
21565
|
}
|
|
21110
|
-
const method =
|
|
21566
|
+
const method = ASTUtils62.getPropertyName(callee);
|
|
21111
21567
|
if (method !== "parse" && method !== "safeParse") return null;
|
|
21112
21568
|
return {
|
|
21113
21569
|
call: node,
|
|
@@ -21121,7 +21577,7 @@ function returnedOutputCandidate(parsed, output) {
|
|
|
21121
21577
|
const annotation = owner?.returnType?.typeAnnotation;
|
|
21122
21578
|
if (annotation === void 0) return null;
|
|
21123
21579
|
const typeReference = returnContractReference(annotation);
|
|
21124
|
-
if (typeReference === null || typeReference.typeName.type !==
|
|
21580
|
+
if (typeReference === null || typeReference.typeName.type !== AST_NODE_TYPES101.Identifier) {
|
|
21125
21581
|
return null;
|
|
21126
21582
|
}
|
|
21127
21583
|
return {
|
|
@@ -21138,7 +21594,7 @@ function directParseReturnCandidate(node) {
|
|
|
21138
21594
|
return parsed?.method === "parse" ? returnedOutputCandidate(parsed, node) : null;
|
|
21139
21595
|
}
|
|
21140
21596
|
function localParseReturnCandidates(node, sourceCode) {
|
|
21141
|
-
if (node.id.type !==
|
|
21597
|
+
if (node.id.type !== AST_NODE_TYPES101.Identifier || node.init?.type !== AST_NODE_TYPES101.CallExpression || node.parent.type !== AST_NODE_TYPES101.VariableDeclaration || node.parent.kind !== "const" || enclosingFunction4(node.init) === null) {
|
|
21142
21598
|
return [];
|
|
21143
21599
|
}
|
|
21144
21600
|
const parsed = zodParseCall(node.init);
|
|
@@ -21149,7 +21605,7 @@ function localParseReturnCandidates(node, sourceCode) {
|
|
|
21149
21605
|
for (const reference of variable.references) {
|
|
21150
21606
|
const identifier = reference.identifier;
|
|
21151
21607
|
const parent = identifier.parent;
|
|
21152
|
-
const output = parsed.method === "parse" ? identifier : parent.type ===
|
|
21608
|
+
const output = parsed.method === "parse" ? identifier : parent.type === AST_NODE_TYPES101.MemberExpression && parent.object === identifier && ASTUtils62.getPropertyName(parent) !== null && (ASTUtils62.getPropertyName(parent) ?? "") === "data" ? parent : null;
|
|
21153
21609
|
if (output === null) continue;
|
|
21154
21610
|
const candidate2 = returnedOutputCandidate(parsed, output);
|
|
21155
21611
|
if (candidate2 !== null) candidates.push(candidate2);
|
|
@@ -21160,17 +21616,17 @@ function directReturnOwner(node) {
|
|
|
21160
21616
|
let current = node;
|
|
21161
21617
|
while (current.parent !== void 0) {
|
|
21162
21618
|
const parent = current.parent;
|
|
21163
|
-
if (parent.type ===
|
|
21619
|
+
if (parent.type === AST_NODE_TYPES101.ReturnStatement) {
|
|
21164
21620
|
return parent.argument === current ? enclosingFunction4(parent) : null;
|
|
21165
21621
|
}
|
|
21166
|
-
if (parent.type ===
|
|
21622
|
+
if (parent.type === AST_NODE_TYPES101.ArrowFunctionExpression && parent.expression && parent.body === current) {
|
|
21167
21623
|
return parent;
|
|
21168
21624
|
}
|
|
21169
|
-
if (parent.type ===
|
|
21625
|
+
if (parent.type === AST_NODE_TYPES101.AwaitExpression && parent.argument === current) {
|
|
21170
21626
|
current = parent;
|
|
21171
21627
|
continue;
|
|
21172
21628
|
}
|
|
21173
|
-
if (parent.type ===
|
|
21629
|
+
if (parent.type === AST_NODE_TYPES101.ConditionalExpression) {
|
|
21174
21630
|
const parsedWhenTrue = parent.consequent === current && isNullishExpression(parent.alternate);
|
|
21175
21631
|
const parsedWhenFalse = parent.alternate === current && isNullishExpression(parent.consequent);
|
|
21176
21632
|
if (parsedWhenTrue || parsedWhenFalse) {
|
|
@@ -21183,12 +21639,12 @@ function directReturnOwner(node) {
|
|
|
21183
21639
|
return null;
|
|
21184
21640
|
}
|
|
21185
21641
|
function isNullishExpression(node) {
|
|
21186
|
-
return node.type ===
|
|
21642
|
+
return node.type === AST_NODE_TYPES101.Literal && node.value === null || node.type === AST_NODE_TYPES101.Identifier && node.name === "undefined";
|
|
21187
21643
|
}
|
|
21188
21644
|
function enclosingFunction4(node) {
|
|
21189
21645
|
let current = node.parent;
|
|
21190
21646
|
while (current != null) {
|
|
21191
|
-
if (current.type ===
|
|
21647
|
+
if (current.type === AST_NODE_TYPES101.ArrowFunctionExpression || current.type === AST_NODE_TYPES101.FunctionDeclaration || current.type === AST_NODE_TYPES101.FunctionExpression) {
|
|
21192
21648
|
return current;
|
|
21193
21649
|
}
|
|
21194
21650
|
current = current.parent;
|
|
@@ -21196,45 +21652,45 @@ function enclosingFunction4(node) {
|
|
|
21196
21652
|
return null;
|
|
21197
21653
|
}
|
|
21198
21654
|
function returnContractReference(node) {
|
|
21199
|
-
if (node.type ===
|
|
21655
|
+
if (node.type === AST_NODE_TYPES101.TSUnionType) {
|
|
21200
21656
|
const substantive = node.types.filter(
|
|
21201
|
-
(member) => member.type !==
|
|
21657
|
+
(member) => member.type !== AST_NODE_TYPES101.TSNullKeyword && member.type !== AST_NODE_TYPES101.TSUndefinedKeyword
|
|
21202
21658
|
);
|
|
21203
21659
|
const [only] = substantive;
|
|
21204
21660
|
return substantive.length === 1 && only !== void 0 ? returnContractReference(only) : null;
|
|
21205
21661
|
}
|
|
21206
|
-
if (node.type ===
|
|
21662
|
+
if (node.type === AST_NODE_TYPES101.TSTypeReference && node.typeName.type === AST_NODE_TYPES101.Identifier && node.typeName.name === "Promise") {
|
|
21207
21663
|
const parameters = node.typeArguments?.params ?? [];
|
|
21208
21664
|
const [only] = parameters;
|
|
21209
21665
|
return parameters.length === 1 && only !== void 0 ? returnContractReference(only) : null;
|
|
21210
21666
|
}
|
|
21211
|
-
return node.type ===
|
|
21667
|
+
return node.type === AST_NODE_TYPES101.TSTypeReference && node.typeName.type === AST_NODE_TYPES101.Identifier && (node.typeArguments?.params.length ?? 0) === 0 ? node : null;
|
|
21212
21668
|
}
|
|
21213
21669
|
function recordZodNamespaces(node, namespaces) {
|
|
21214
21670
|
for (const statement of node.body) {
|
|
21215
|
-
if (statement.type !==
|
|
21671
|
+
if (statement.type !== AST_NODE_TYPES101.ImportDeclaration || !isZodModule(statement.source.value)) {
|
|
21216
21672
|
continue;
|
|
21217
21673
|
}
|
|
21218
21674
|
for (const specifier of statement.specifiers) {
|
|
21219
|
-
if (specifier.type ===
|
|
21675
|
+
if (specifier.type === AST_NODE_TYPES101.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES101.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES101.ImportSpecifier && importSpecifierName(specifier) === "z") {
|
|
21220
21676
|
namespaces.add(specifier.local.name);
|
|
21221
21677
|
}
|
|
21222
21678
|
}
|
|
21223
21679
|
}
|
|
21224
21680
|
}
|
|
21225
21681
|
function collectConstrainedNames(node, names) {
|
|
21226
|
-
if (node.type ===
|
|
21227
|
-
if (node.typeName.type ===
|
|
21682
|
+
if (node.type === AST_NODE_TYPES101.TSTypeReference) {
|
|
21683
|
+
if (node.typeName.type === AST_NODE_TYPES101.Identifier) names.add(node.typeName.name);
|
|
21228
21684
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
21229
21685
|
collectConstrainedNames(argument, names);
|
|
21230
21686
|
}
|
|
21231
21687
|
return;
|
|
21232
21688
|
}
|
|
21233
|
-
if (node.type ===
|
|
21689
|
+
if (node.type === AST_NODE_TYPES101.TSArrayType) {
|
|
21234
21690
|
collectConstrainedNames(node.elementType, names);
|
|
21235
21691
|
return;
|
|
21236
21692
|
}
|
|
21237
|
-
if (node.type ===
|
|
21693
|
+
if (node.type === AST_NODE_TYPES101.TSUnionType || node.type === AST_NODE_TYPES101.TSIntersectionType) {
|
|
21238
21694
|
for (const member of node.types) collectConstrainedNames(member, names);
|
|
21239
21695
|
}
|
|
21240
21696
|
}
|
|
@@ -21268,7 +21724,7 @@ function reportCandidates(context, services, schemas, candidates, zodNamespaces,
|
|
|
21268
21724
|
if (constrained) return;
|
|
21269
21725
|
if (declaration.getSourceFile() === tsSchema.getSourceFile()) {
|
|
21270
21726
|
const estreeDeclaration = services.tsNodeToESTreeNodeMap.get(declaration);
|
|
21271
|
-
if ((estreeDeclaration.type ===
|
|
21727
|
+
if ((estreeDeclaration.type === AST_NODE_TYPES101.TSInterfaceDeclaration || estreeDeclaration.type === AST_NODE_TYPES101.TSTypeAliasDeclaration) && preferZodInferOwnsDefaultTwin({
|
|
21272
21728
|
constrained,
|
|
21273
21729
|
declaration: estreeDeclaration,
|
|
21274
21730
|
initializer: schema.initializer,
|
|
@@ -21373,7 +21829,7 @@ var prefer_zod_parse_output_type_default = createRule({
|
|
|
21373
21829
|
recordZodNamespaces(node, namespaces);
|
|
21374
21830
|
},
|
|
21375
21831
|
VariableDeclarator(node) {
|
|
21376
|
-
if (node.id.type ===
|
|
21832
|
+
if (node.id.type === AST_NODE_TYPES101.Identifier && node.init !== null && isModuleLevelConst2(node) && isLocalZodObjectSchema(node.init, namespaces)) {
|
|
21377
21833
|
schemas.push({ identifier: node.id, initializer: node.init, name: node.id.name });
|
|
21378
21834
|
}
|
|
21379
21835
|
candidates.push(...localParseReturnCandidates(node, context.sourceCode));
|
|
@@ -21383,13 +21839,13 @@ var prefer_zod_parse_output_type_default = createRule({
|
|
|
21383
21839
|
if (candidate2 !== null) candidates.push(candidate2);
|
|
21384
21840
|
},
|
|
21385
21841
|
"MemberExpression"(node) {
|
|
21386
|
-
if (node.object.type ===
|
|
21842
|
+
if (node.object.type === AST_NODE_TYPES101.Identifier && node.property.type === AST_NODE_TYPES101.Identifier && isPreferZodInferModuleReshaper(node.property.name)) {
|
|
21387
21843
|
reshapedSchemas.add(node.object.name);
|
|
21388
21844
|
}
|
|
21389
21845
|
},
|
|
21390
21846
|
TSTypeReference(node) {
|
|
21391
21847
|
const { typeName } = node;
|
|
21392
|
-
const name = typeName.type ===
|
|
21848
|
+
const name = typeName.type === AST_NODE_TYPES101.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES101.TSQualifiedName && typeName.right.type === AST_NODE_TYPES101.Identifier ? typeName.right.name : null;
|
|
21393
21849
|
if (name === null || !isPreferZodInferTypeConstraintName(name)) return;
|
|
21394
21850
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
21395
21851
|
collectConstrainedNames(argument, constrainedTypeNames);
|
|
@@ -21413,7 +21869,7 @@ var prefer_zod_parse_output_type_default = createRule({
|
|
|
21413
21869
|
// src/rules/require-assert-never.ts
|
|
21414
21870
|
import {
|
|
21415
21871
|
ESLintUtils as ESLintUtils15,
|
|
21416
|
-
AST_NODE_TYPES as
|
|
21872
|
+
AST_NODE_TYPES as AST_NODE_TYPES102
|
|
21417
21873
|
} from "@typescript-eslint/utils";
|
|
21418
21874
|
import ts13 from "typescript";
|
|
21419
21875
|
var REQUIRE_ASSERT_NEVER_DOCUMENTATION = {
|
|
@@ -21428,14 +21884,14 @@ var REQUIRE_ASSERT_NEVER_DOCUMENTATION = {
|
|
|
21428
21884
|
]
|
|
21429
21885
|
};
|
|
21430
21886
|
var isRuntimeHandlingStatement = (statement) => {
|
|
21431
|
-
if (statement.type ===
|
|
21432
|
-
if (statement.type ===
|
|
21887
|
+
if (statement.type === AST_NODE_TYPES102.EmptyStatement) return false;
|
|
21888
|
+
if (statement.type === AST_NODE_TYPES102.BreakStatement) {
|
|
21433
21889
|
return statement.label !== null;
|
|
21434
21890
|
}
|
|
21435
|
-
if (statement.type ===
|
|
21891
|
+
if (statement.type === AST_NODE_TYPES102.TSTypeAliasDeclaration || statement.type === AST_NODE_TYPES102.TSInterfaceDeclaration) {
|
|
21436
21892
|
return false;
|
|
21437
21893
|
}
|
|
21438
|
-
if (statement.type ===
|
|
21894
|
+
if (statement.type === AST_NODE_TYPES102.BlockStatement) {
|
|
21439
21895
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
21440
21896
|
}
|
|
21441
21897
|
return true;
|
|
@@ -21451,7 +21907,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
21451
21907
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
21452
21908
|
}
|
|
21453
21909
|
const only = defaultCase.consequent[0];
|
|
21454
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
21910
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === AST_NODE_TYPES102.BlockStatement && !only.body.some(isRuntimeHandlingStatement)) {
|
|
21455
21911
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
21456
21912
|
}
|
|
21457
21913
|
return false;
|
|
@@ -21532,7 +21988,7 @@ var require_assert_never_default = createRule({
|
|
|
21532
21988
|
});
|
|
21533
21989
|
|
|
21534
21990
|
// src/rules/require-fetch-timeout.ts
|
|
21535
|
-
import { AST_NODE_TYPES as
|
|
21991
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES103, ASTUtils as ASTUtils63 } from "@typescript-eslint/utils";
|
|
21536
21992
|
var REQUIRE_FETCH_TIMEOUT_DOCUMENTATION = {
|
|
21537
21993
|
summary: "Require an explicit abort signal on locally analyzable global fetch calls.",
|
|
21538
21994
|
rationale: "An unbounded request can occupy work indefinitely when an upstream stalls.",
|
|
@@ -21559,18 +22015,18 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
21559
22015
|
return false;
|
|
21560
22016
|
}
|
|
21561
22017
|
function initProvablyLacksSignal(init, resolvesToGlobal) {
|
|
21562
|
-
if (init.type !==
|
|
22018
|
+
if (init.type !== AST_NODE_TYPES103.ObjectExpression) return false;
|
|
21563
22019
|
let lacksSignal = true;
|
|
21564
22020
|
for (const prop of init.properties) {
|
|
21565
|
-
if (prop.type ===
|
|
22021
|
+
if (prop.type === AST_NODE_TYPES103.SpreadElement) {
|
|
21566
22022
|
lacksSignal = false;
|
|
21567
22023
|
continue;
|
|
21568
22024
|
}
|
|
21569
|
-
const isSignal = !prop.computed && prop.key.type ===
|
|
22025
|
+
const isSignal = !prop.computed && prop.key.type === AST_NODE_TYPES103.Identifier && prop.key.name === "signal" || prop.key.type === AST_NODE_TYPES103.Literal && prop.key.value === "signal";
|
|
21570
22026
|
if (isSignal) {
|
|
21571
22027
|
const value = prop.value;
|
|
21572
|
-
lacksSignal = prop.kind === "init" && !prop.method && (value.type ===
|
|
21573
|
-
} else if (prop.computed && prop.key.type !==
|
|
22028
|
+
lacksSignal = prop.kind === "init" && !prop.method && (value.type === AST_NODE_TYPES103.Literal && value.value === null || value.type === AST_NODE_TYPES103.Identifier && value.name === "undefined" && resolvesToGlobal(value) || value.type === AST_NODE_TYPES103.UnaryExpression && value.operator === "void" && value.argument.type === AST_NODE_TYPES103.Literal && value.argument.value === 0);
|
|
22029
|
+
} else if (prop.computed && prop.key.type !== AST_NODE_TYPES103.Literal) {
|
|
21574
22030
|
lacksSignal = false;
|
|
21575
22031
|
}
|
|
21576
22032
|
}
|
|
@@ -21578,7 +22034,7 @@ function initProvablyLacksSignal(init, resolvesToGlobal) {
|
|
|
21578
22034
|
}
|
|
21579
22035
|
function isInlineUrl(node, resolvesToGlobal) {
|
|
21580
22036
|
node = unwrapExpression(node);
|
|
21581
|
-
return node.type ===
|
|
22037
|
+
return node.type === AST_NODE_TYPES103.Literal && typeof node.value === "string" || node.type === AST_NODE_TYPES103.TemplateLiteral || node.type === AST_NODE_TYPES103.NewExpression && node.callee.type === AST_NODE_TYPES103.Identifier && node.callee.name === "URL" && resolvesToGlobal(node.callee);
|
|
21582
22038
|
}
|
|
21583
22039
|
var require_fetch_timeout_default = createRule({
|
|
21584
22040
|
name: "require-fetch-timeout",
|
|
@@ -21616,30 +22072,30 @@ var require_fetch_timeout_default = createRule({
|
|
|
21616
22072
|
}
|
|
21617
22073
|
function resolvesToGlobal(identifier) {
|
|
21618
22074
|
const scope = context.sourceCode.getScope(identifier);
|
|
21619
|
-
const variable =
|
|
22075
|
+
const variable = ASTUtils63.findVariable(scope, identifier.name);
|
|
21620
22076
|
return variable === null || variable.defs.length === 0;
|
|
21621
22077
|
}
|
|
21622
22078
|
function isGlobalFetchCall2(callee) {
|
|
21623
|
-
if (callee.type ===
|
|
22079
|
+
if (callee.type === AST_NODE_TYPES103.Identifier) {
|
|
21624
22080
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
21625
22081
|
}
|
|
21626
|
-
return callee.type ===
|
|
22082
|
+
return callee.type === AST_NODE_TYPES103.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES103.Identifier && callee.property.name === "fetch" && callee.object.type === AST_NODE_TYPES103.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
21627
22083
|
}
|
|
21628
22084
|
function localConstInitProvablyLacksSignal(identifier) {
|
|
21629
|
-
const variable =
|
|
22085
|
+
const variable = ASTUtils63.findVariable(
|
|
21630
22086
|
context.sourceCode.getScope(identifier),
|
|
21631
22087
|
identifier.name
|
|
21632
22088
|
);
|
|
21633
22089
|
if (variable?.defs.length !== 1) return false;
|
|
21634
22090
|
const definition = variable.defs[0];
|
|
21635
|
-
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !==
|
|
22091
|
+
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !== AST_NODE_TYPES103.ObjectExpression || !initProvablyLacksSignal(definition.node.init, resolvesToGlobal)) {
|
|
21636
22092
|
return false;
|
|
21637
22093
|
}
|
|
21638
22094
|
for (const reference of variable.references) {
|
|
21639
22095
|
const ref = reference.identifier;
|
|
21640
22096
|
if (ref === identifier || ref === definition.name) continue;
|
|
21641
22097
|
const member = ref.parent;
|
|
21642
|
-
if (member.type !==
|
|
22098
|
+
if (member.type !== AST_NODE_TYPES103.MemberExpression || member.object !== ref || member.computed || member.property.type !== AST_NODE_TYPES103.Identifier || member.property.name === "signal" || member.parent.type !== AST_NODE_TYPES103.AssignmentExpression || member.parent.left !== member) {
|
|
21643
22099
|
return false;
|
|
21644
22100
|
}
|
|
21645
22101
|
}
|
|
@@ -21647,13 +22103,13 @@ var require_fetch_timeout_default = createRule({
|
|
|
21647
22103
|
}
|
|
21648
22104
|
function isForwardedRequest(argument) {
|
|
21649
22105
|
let value = argument;
|
|
21650
|
-
if (value.type ===
|
|
21651
|
-
const binding =
|
|
22106
|
+
if (value.type === AST_NODE_TYPES103.Identifier) {
|
|
22107
|
+
const binding = ASTUtils63.findVariable(context.sourceCode.getScope(value), value.name);
|
|
21652
22108
|
const definition = binding?.defs.length === 1 ? binding.defs[0] : void 0;
|
|
21653
22109
|
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init === null || binding?.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
21654
22110
|
value = definition.node.init;
|
|
21655
22111
|
}
|
|
21656
|
-
return value.type ===
|
|
22112
|
+
return value.type === AST_NODE_TYPES103.NewExpression && value.callee.type === AST_NODE_TYPES103.Identifier && value.callee.name === "Request" && resolvesToGlobal(value.callee);
|
|
21657
22113
|
}
|
|
21658
22114
|
return {
|
|
21659
22115
|
CallExpression(node) {
|
|
@@ -21665,7 +22121,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
21665
22121
|
if (first !== void 0 && (node.arguments.length === 1 && !isInlineUrl(first, resolvesToGlobal) || isForwardedRequest(first))) {
|
|
21666
22122
|
return;
|
|
21667
22123
|
}
|
|
21668
|
-
if (init === void 0 || initProvablyLacksSignal(init, resolvesToGlobal) || init.type ===
|
|
22124
|
+
if (init === void 0 || initProvablyLacksSignal(init, resolvesToGlobal) || init.type === AST_NODE_TYPES103.Identifier && localConstInitProvablyLacksSignal(init)) {
|
|
21669
22125
|
context.report({ node, messageId: "missingSignal" });
|
|
21670
22126
|
}
|
|
21671
22127
|
}
|
|
@@ -21674,7 +22130,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
21674
22130
|
});
|
|
21675
22131
|
|
|
21676
22132
|
// src/rules/require-interface-for-exported-class.ts
|
|
21677
|
-
import { AST_NODE_TYPES as
|
|
22133
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES104 } from "@typescript-eslint/utils";
|
|
21678
22134
|
var REQUIRE_INTERFACE_FOR_EXPORTED_CLASS_DOCUMENTATION = {
|
|
21679
22135
|
defaultLevel: "warning",
|
|
21680
22136
|
summary: "Require exported concrete classes with public behavior to declare a contract.",
|
|
@@ -21721,23 +22177,23 @@ var REQUIRE_INTERFACE_FOR_EXPORTED_CLASS_DOCUMENTATION = {
|
|
|
21721
22177
|
};
|
|
21722
22178
|
function hasPublicInstanceBehavior(node) {
|
|
21723
22179
|
return node.body.body.some((member) => {
|
|
21724
|
-
if (member.type ===
|
|
21725
|
-
return member.kind !== "constructor" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.key.type !==
|
|
22180
|
+
if (member.type === AST_NODE_TYPES104.MethodDefinition) {
|
|
22181
|
+
return member.kind !== "constructor" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.key.type !== AST_NODE_TYPES104.PrivateIdentifier;
|
|
21726
22182
|
}
|
|
21727
|
-
if (member.type !==
|
|
22183
|
+
if (member.type !== AST_NODE_TYPES104.PropertyDefinition || member.static)
|
|
21728
22184
|
return false;
|
|
21729
|
-
if (member.accessibility === "private" || member.accessibility === "protected" || member.key.type ===
|
|
21730
|
-
return member.value?.type ===
|
|
22185
|
+
if (member.accessibility === "private" || member.accessibility === "protected" || member.key.type === AST_NODE_TYPES104.PrivateIdentifier) return false;
|
|
22186
|
+
return member.value?.type === AST_NODE_TYPES104.ArrowFunctionExpression || member.value?.type === AST_NODE_TYPES104.FunctionExpression || member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES104.TSFunctionType;
|
|
21731
22187
|
});
|
|
21732
22188
|
}
|
|
21733
22189
|
function classBindings(statement) {
|
|
21734
|
-
const declaration = statement.type ===
|
|
21735
|
-
if (declaration?.type ===
|
|
22190
|
+
const declaration = statement.type === AST_NODE_TYPES104.ExportNamedDeclaration ? statement.declaration : statement;
|
|
22191
|
+
if (declaration?.type === AST_NODE_TYPES104.ClassDeclaration) {
|
|
21736
22192
|
return declaration.id === null ? [] : [{ declaration, name: declaration.id.name }];
|
|
21737
22193
|
}
|
|
21738
|
-
if (declaration?.type !==
|
|
22194
|
+
if (declaration?.type !== AST_NODE_TYPES104.VariableDeclaration) return [];
|
|
21739
22195
|
return declaration.declarations.flatMap(
|
|
21740
|
-
(item) => item.id.type ===
|
|
22196
|
+
(item) => item.id.type === AST_NODE_TYPES104.Identifier && item.init?.type === AST_NODE_TYPES104.ClassExpression ? [{ declaration: item.init, name: item.id.name }] : []
|
|
21741
22197
|
);
|
|
21742
22198
|
}
|
|
21743
22199
|
var require_interface_for_exported_class_default = createRule({
|
|
@@ -21771,7 +22227,7 @@ var require_interface_for_exported_class_default = createRule({
|
|
|
21771
22227
|
}
|
|
21772
22228
|
const exported = exportedClasses(program, classes);
|
|
21773
22229
|
for (const [declaration, exportedName] of exported) {
|
|
21774
|
-
const extendsLocalAbstractBase = declaration.superClass?.type ===
|
|
22230
|
+
const extendsLocalAbstractBase = declaration.superClass?.type === AST_NODE_TYPES104.Identifier && abstractBases.has(declaration.superClass.name);
|
|
21775
22231
|
if (declaration.abstract || declaration.implements.length > 0 || extendsLocalAbstractBase || !hasPublicInstanceBehavior(declaration)) continue;
|
|
21776
22232
|
context.report({
|
|
21777
22233
|
node: declaration.id ?? declaration,
|
|
@@ -21786,7 +22242,7 @@ var require_interface_for_exported_class_default = createRule({
|
|
|
21786
22242
|
function exportedClasses(program, classes) {
|
|
21787
22243
|
const exported = /* @__PURE__ */ new Map();
|
|
21788
22244
|
function collectExportedClass(statement) {
|
|
21789
|
-
if (statement.type ===
|
|
22245
|
+
if (statement.type === AST_NODE_TYPES104.ExportNamedDeclaration) {
|
|
21790
22246
|
for (const binding of classBindings(statement)) {
|
|
21791
22247
|
exported.set(binding.declaration, binding.name);
|
|
21792
22248
|
}
|
|
@@ -21794,13 +22250,13 @@ function exportedClasses(program, classes) {
|
|
|
21794
22250
|
collectClassSpecifiers(statement);
|
|
21795
22251
|
return;
|
|
21796
22252
|
}
|
|
21797
|
-
if (statement.type !==
|
|
21798
|
-
if (statement.declaration.type ===
|
|
22253
|
+
if (statement.type !== AST_NODE_TYPES104.ExportDefaultDeclaration) return;
|
|
22254
|
+
if (statement.declaration.type === AST_NODE_TYPES104.ClassDeclaration || statement.declaration.type === AST_NODE_TYPES104.ClassExpression) {
|
|
21799
22255
|
exported.set(
|
|
21800
22256
|
statement.declaration,
|
|
21801
22257
|
statement.declaration.id?.name ?? "default"
|
|
21802
22258
|
);
|
|
21803
|
-
} else if (statement.declaration.type ===
|
|
22259
|
+
} else if (statement.declaration.type === AST_NODE_TYPES104.Identifier) {
|
|
21804
22260
|
const candidate2 = classes.get(statement.declaration.name);
|
|
21805
22261
|
if (candidate2 !== void 0) {
|
|
21806
22262
|
exported.set(candidate2, statement.declaration.name);
|
|
@@ -21812,7 +22268,7 @@ function exportedClasses(program, classes) {
|
|
|
21812
22268
|
if (specifier.exportKind === "type") continue;
|
|
21813
22269
|
const candidate2 = classes.get(specifier.local.name);
|
|
21814
22270
|
if (candidate2 === void 0) continue;
|
|
21815
|
-
const exportedName = specifier.exported.type ===
|
|
22271
|
+
const exportedName = specifier.exported.type === AST_NODE_TYPES104.Identifier ? specifier.exported.name : specifier.exported.value;
|
|
21816
22272
|
exported.set(candidate2, exportedName);
|
|
21817
22273
|
}
|
|
21818
22274
|
}
|
|
@@ -21823,7 +22279,7 @@ function exportedClasses(program, classes) {
|
|
|
21823
22279
|
}
|
|
21824
22280
|
|
|
21825
22281
|
// src/rules/require-sql-access-class.ts
|
|
21826
|
-
import { AST_NODE_TYPES as
|
|
22282
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES105, ASTUtils as ASTUtils64 } from "@typescript-eslint/utils";
|
|
21827
22283
|
var DIRECT_EXECUTION_METHODS = /* @__PURE__ */ new Set([
|
|
21828
22284
|
"all",
|
|
21829
22285
|
"batch",
|
|
@@ -21927,80 +22383,80 @@ function isDatabaseOperation(method, receiver) {
|
|
|
21927
22383
|
}
|
|
21928
22384
|
function databaseReceiver(node) {
|
|
21929
22385
|
node = unwrapExpression(node);
|
|
21930
|
-
if (node.type ===
|
|
22386
|
+
if (node.type === AST_NODE_TYPES105.Identifier)
|
|
21931
22387
|
return DATABASE_NAMES.test(node.name);
|
|
21932
|
-
if (node.type !==
|
|
21933
|
-
const name =
|
|
22388
|
+
if (node.type !== AST_NODE_TYPES105.MemberExpression) return false;
|
|
22389
|
+
const name = ASTUtils64.getPropertyName(node);
|
|
21934
22390
|
return name === "DB" || name !== null && DATABASE_NAMES.test(name);
|
|
21935
22391
|
}
|
|
21936
22392
|
function databaseRootMember(node) {
|
|
21937
22393
|
let current = node;
|
|
21938
22394
|
for (; ; ) {
|
|
21939
22395
|
current = unwrapExpression(current);
|
|
21940
|
-
if (current.type ===
|
|
22396
|
+
if (current.type === AST_NODE_TYPES105.ChainExpression) {
|
|
21941
22397
|
current = current.expression;
|
|
21942
22398
|
continue;
|
|
21943
22399
|
}
|
|
21944
|
-
if (current.type ===
|
|
21945
|
-
if (current.callee.type !==
|
|
22400
|
+
if (current.type === AST_NODE_TYPES105.CallExpression) {
|
|
22401
|
+
if (current.callee.type !== AST_NODE_TYPES105.MemberExpression) return null;
|
|
21946
22402
|
current = current.callee.object;
|
|
21947
22403
|
continue;
|
|
21948
22404
|
}
|
|
21949
|
-
if (current.type ===
|
|
21950
|
-
if (current.object.type ===
|
|
21951
|
-
return
|
|
22405
|
+
if (current.type === AST_NODE_TYPES105.MemberExpression) {
|
|
22406
|
+
if (current.object.type === AST_NODE_TYPES105.ThisExpression)
|
|
22407
|
+
return ASTUtils64.getPropertyName(current);
|
|
21952
22408
|
current = current.object;
|
|
21953
22409
|
continue;
|
|
21954
22410
|
}
|
|
21955
|
-
return current.type ===
|
|
22411
|
+
return current.type === AST_NODE_TYPES105.Identifier ? current.name : null;
|
|
21956
22412
|
}
|
|
21957
22413
|
}
|
|
21958
22414
|
function expressionHasDatabaseMarker(node) {
|
|
21959
22415
|
let current = node;
|
|
21960
22416
|
for (; ; ) {
|
|
21961
22417
|
current = unwrapExpression(current);
|
|
21962
|
-
if (current.type ===
|
|
22418
|
+
if (current.type === AST_NODE_TYPES105.ChainExpression) {
|
|
21963
22419
|
current = current.expression;
|
|
21964
22420
|
continue;
|
|
21965
22421
|
}
|
|
21966
|
-
if (current.type ===
|
|
21967
|
-
if (current.callee.type !==
|
|
22422
|
+
if (current.type === AST_NODE_TYPES105.CallExpression) {
|
|
22423
|
+
if (current.callee.type !== AST_NODE_TYPES105.MemberExpression) return false;
|
|
21968
22424
|
current = current.callee.object;
|
|
21969
22425
|
continue;
|
|
21970
22426
|
}
|
|
21971
|
-
if (current.type ===
|
|
21972
|
-
const name =
|
|
22427
|
+
if (current.type === AST_NODE_TYPES105.MemberExpression) {
|
|
22428
|
+
const name = ASTUtils64.getPropertyName(current);
|
|
21973
22429
|
if (name === "DB" || name !== null && DATABASE_NAMES.test(name))
|
|
21974
22430
|
return true;
|
|
21975
22431
|
current = current.object;
|
|
21976
22432
|
continue;
|
|
21977
22433
|
}
|
|
21978
|
-
return current.type ===
|
|
22434
|
+
return current.type === AST_NODE_TYPES105.Identifier && DATABASE_NAMES.test(current.name);
|
|
21979
22435
|
}
|
|
21980
22436
|
}
|
|
21981
22437
|
function expressionCallsBuilder(node) {
|
|
21982
22438
|
let current = node;
|
|
21983
22439
|
for (; ; ) {
|
|
21984
22440
|
current = unwrapExpression(current);
|
|
21985
|
-
if (current.type ===
|
|
22441
|
+
if (current.type === AST_NODE_TYPES105.ChainExpression) {
|
|
21986
22442
|
current = current.expression;
|
|
21987
22443
|
continue;
|
|
21988
22444
|
}
|
|
21989
|
-
if (current.type ===
|
|
21990
|
-
if (current.callee.type !==
|
|
21991
|
-
const name =
|
|
22445
|
+
if (current.type === AST_NODE_TYPES105.CallExpression) {
|
|
22446
|
+
if (current.callee.type !== AST_NODE_TYPES105.MemberExpression) return false;
|
|
22447
|
+
const name = ASTUtils64.getPropertyName(current.callee);
|
|
21992
22448
|
if (name !== null && BUILDER_METHODS.has(name)) return true;
|
|
21993
22449
|
current = current.callee.object;
|
|
21994
22450
|
continue;
|
|
21995
22451
|
}
|
|
21996
|
-
if (current.type !==
|
|
22452
|
+
if (current.type !== AST_NODE_TYPES105.MemberExpression) return false;
|
|
21997
22453
|
current = current.object;
|
|
21998
22454
|
}
|
|
21999
22455
|
}
|
|
22000
22456
|
function owningClass2(node) {
|
|
22001
22457
|
let current = node.parent;
|
|
22002
22458
|
while (current != null) {
|
|
22003
|
-
if (current.type ===
|
|
22459
|
+
if (current.type === AST_NODE_TYPES105.ClassDeclaration || current.type === AST_NODE_TYPES105.ClassExpression)
|
|
22004
22460
|
return current;
|
|
22005
22461
|
current = current.parent;
|
|
22006
22462
|
}
|
|
@@ -22009,25 +22465,25 @@ function owningClass2(node) {
|
|
|
22009
22465
|
function injectedMembers(owner) {
|
|
22010
22466
|
const injected = /* @__PURE__ */ new Set();
|
|
22011
22467
|
const constructor = owner.body.body.find(
|
|
22012
|
-
(member) => member.type ===
|
|
22468
|
+
(member) => member.type === AST_NODE_TYPES105.MethodDefinition && member.kind === "constructor"
|
|
22013
22469
|
);
|
|
22014
22470
|
if (constructor === void 0) return injected;
|
|
22015
22471
|
const parameters = /* @__PURE__ */ new Set();
|
|
22016
22472
|
for (const parameter of constructor.value.params) {
|
|
22017
22473
|
for (const name of parameterNames(parameter)) parameters.add(name);
|
|
22018
|
-
if (parameter.type !==
|
|
22019
|
-
const value = parameter.parameter.type ===
|
|
22020
|
-
if (value.type ===
|
|
22474
|
+
if (parameter.type !== AST_NODE_TYPES105.TSParameterProperty) continue;
|
|
22475
|
+
const value = parameter.parameter.type === AST_NODE_TYPES105.AssignmentPattern ? parameter.parameter.left : parameter.parameter;
|
|
22476
|
+
if (value.type === AST_NODE_TYPES105.Identifier) injected.add(value.name);
|
|
22021
22477
|
}
|
|
22022
22478
|
const body2 = constructor.value.body;
|
|
22023
22479
|
if (body2 === null) return injected;
|
|
22024
22480
|
function collectInjectedMember(statement) {
|
|
22025
|
-
if (statement.type !==
|
|
22481
|
+
if (statement.type !== AST_NODE_TYPES105.ExpressionStatement || statement.expression.type !== AST_NODE_TYPES105.AssignmentExpression || statement.expression.operator !== "=") return;
|
|
22026
22482
|
const { left, right } = statement.expression;
|
|
22027
|
-
if (left.type !==
|
|
22483
|
+
if (left.type !== AST_NODE_TYPES105.MemberExpression) return;
|
|
22028
22484
|
const target = thisRootMember(left);
|
|
22029
22485
|
if (target === null) return;
|
|
22030
|
-
const source = right.type ===
|
|
22486
|
+
const source = right.type === AST_NODE_TYPES105.Identifier ? right.name : right.type === AST_NODE_TYPES105.MemberExpression && right.object.type === AST_NODE_TYPES105.Identifier ? right.object.name : null;
|
|
22031
22487
|
if (source !== null && parameters.has(source)) injected.add(target);
|
|
22032
22488
|
}
|
|
22033
22489
|
for (const statement of body2.body) {
|
|
@@ -22038,26 +22494,26 @@ function injectedMembers(owner) {
|
|
|
22038
22494
|
function thisRootMember(node) {
|
|
22039
22495
|
let current = node;
|
|
22040
22496
|
let root = null;
|
|
22041
|
-
while (current.type ===
|
|
22042
|
-
const name =
|
|
22497
|
+
while (current.type === AST_NODE_TYPES105.MemberExpression) {
|
|
22498
|
+
const name = ASTUtils64.getPropertyName(current);
|
|
22043
22499
|
if (name === null) return null;
|
|
22044
22500
|
root = name;
|
|
22045
22501
|
current = current.object;
|
|
22046
22502
|
}
|
|
22047
|
-
return current.type ===
|
|
22503
|
+
return current.type === AST_NODE_TYPES105.ThisExpression ? root : null;
|
|
22048
22504
|
}
|
|
22049
22505
|
function parameterNames(parameter) {
|
|
22050
22506
|
let value = parameter;
|
|
22051
|
-
if (value.type ===
|
|
22052
|
-
if (value.type ===
|
|
22053
|
-
if (value.type ===
|
|
22054
|
-
if (value.type !==
|
|
22507
|
+
if (value.type === AST_NODE_TYPES105.TSParameterProperty) value = value.parameter;
|
|
22508
|
+
if (value.type === AST_NODE_TYPES105.AssignmentPattern) value = value.left;
|
|
22509
|
+
if (value.type === AST_NODE_TYPES105.Identifier) return /* @__PURE__ */ new Set([value.name]);
|
|
22510
|
+
if (value.type !== AST_NODE_TYPES105.ObjectPattern) return /* @__PURE__ */ new Set();
|
|
22055
22511
|
return new Set(
|
|
22056
22512
|
value.properties.flatMap((property) => {
|
|
22057
|
-
if (property.type ===
|
|
22058
|
-
return property.argument.type ===
|
|
22059
|
-
const target = property.value.type ===
|
|
22060
|
-
return target.type ===
|
|
22513
|
+
if (property.type === AST_NODE_TYPES105.RestElement)
|
|
22514
|
+
return property.argument.type === AST_NODE_TYPES105.Identifier ? [property.argument.name] : [];
|
|
22515
|
+
const target = property.value.type === AST_NODE_TYPES105.AssignmentPattern ? property.value.left : property.value;
|
|
22516
|
+
return target.type === AST_NODE_TYPES105.Identifier ? [target.name] : [];
|
|
22061
22517
|
})
|
|
22062
22518
|
);
|
|
22063
22519
|
}
|
|
@@ -22082,20 +22538,20 @@ var require_sql_access_class_default = createRule({
|
|
|
22082
22538
|
const unwrappedNodeCallee = node.type === "CallExpression" || node.type === "NewExpression" ? unwrapExpression(node.callee) : null;
|
|
22083
22539
|
if (seen.has(node)) return false;
|
|
22084
22540
|
seen.add(node);
|
|
22085
|
-
if (node.type ===
|
|
22086
|
-
const binding =
|
|
22541
|
+
if (node.type === AST_NODE_TYPES105.Identifier) {
|
|
22542
|
+
const binding = ASTUtils64.findVariable(context.sourceCode.getScope(node), node.name);
|
|
22087
22543
|
if (binding?.defs.length !== 1 || binding.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
22088
22544
|
const definition = binding.defs[0];
|
|
22089
22545
|
return definition?.type === "Variable" && definition.node.init !== null && knownNonDatabase(definition.node.init, seen);
|
|
22090
22546
|
}
|
|
22091
|
-
return node.type ===
|
|
22547
|
+
return node.type === AST_NODE_TYPES105.NewExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES105.Identifier && ["Map", "WeakMap", "URLSearchParams"].includes(unwrappedNodeCallee.name) && (ASTUtils64.findVariable(context.sourceCode.getScope(unwrappedNodeCallee), unwrappedNodeCallee.name)?.defs.length ?? 0) === 0;
|
|
22092
22548
|
}
|
|
22093
22549
|
return {
|
|
22094
22550
|
CallExpression(node) {
|
|
22095
22551
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
22096
|
-
if (unwrappedNodeCallee.type !==
|
|
22552
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES105.MemberExpression)
|
|
22097
22553
|
return;
|
|
22098
|
-
const method =
|
|
22554
|
+
const method = ASTUtils64.getPropertyName(unwrappedNodeCallee);
|
|
22099
22555
|
if (knownNonDatabase(unwrappedNodeCallee.object)) return;
|
|
22100
22556
|
if (method === null || !isDatabaseOperation(method, unwrappedNodeCallee.object))
|
|
22101
22557
|
return;
|
|
@@ -22111,7 +22567,7 @@ var require_sql_access_class_default = createRule({
|
|
|
22111
22567
|
});
|
|
22112
22568
|
|
|
22113
22569
|
// src/rules/require-static-next-matcher.ts
|
|
22114
|
-
import { AST_NODE_TYPES as
|
|
22570
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES106 } from "@typescript-eslint/utils";
|
|
22115
22571
|
var REQUIRE_STATIC_NEXT_MATCHER_DOCUMENTATION = {
|
|
22116
22572
|
summary: "Require Next.js middleware and proxy matcher configuration to contain only build-time literals.",
|
|
22117
22573
|
rationale: "Next.js must statically analyze matcher values at build time; computed values are ignored.",
|
|
@@ -22127,27 +22583,27 @@ var REQUIRE_STATIC_NEXT_MATCHER_DOCUMENTATION = {
|
|
|
22127
22583
|
var NEXT_ENTRY_FILE = /(?:^|[/\\])(?:middleware|proxy)\.[cm]?[jt]sx?$/u;
|
|
22128
22584
|
function isStaticValue(node) {
|
|
22129
22585
|
const value = unwrapExpression(node);
|
|
22130
|
-
if (value.type ===
|
|
22586
|
+
if (value.type === AST_NODE_TYPES106.Literal) {
|
|
22131
22587
|
return true;
|
|
22132
22588
|
}
|
|
22133
|
-
if (value.type ===
|
|
22589
|
+
if (value.type === AST_NODE_TYPES106.TemplateLiteral) {
|
|
22134
22590
|
return value.expressions.length === 0;
|
|
22135
22591
|
}
|
|
22136
|
-
if (value.type ===
|
|
22592
|
+
if (value.type === AST_NODE_TYPES106.ArrayExpression) {
|
|
22137
22593
|
return value.elements.every(
|
|
22138
|
-
(element) => element !== null && element.type !==
|
|
22594
|
+
(element) => element !== null && element.type !== AST_NODE_TYPES106.SpreadElement && isStaticValue(element)
|
|
22139
22595
|
);
|
|
22140
22596
|
}
|
|
22141
|
-
if (value.type ===
|
|
22597
|
+
if (value.type === AST_NODE_TYPES106.ObjectExpression) {
|
|
22142
22598
|
return value.properties.every(
|
|
22143
|
-
(property) => property.type ===
|
|
22599
|
+
(property) => property.type === AST_NODE_TYPES106.Property && property.kind === "init" && !property.computed && property.value.type !== AST_NODE_TYPES106.AssignmentPattern && isStaticValue(property.value)
|
|
22144
22600
|
);
|
|
22145
22601
|
}
|
|
22146
22602
|
return false;
|
|
22147
22603
|
}
|
|
22148
22604
|
function propertyName5(property) {
|
|
22149
|
-
if (!property.computed && property.key.type ===
|
|
22150
|
-
return property.key.type ===
|
|
22605
|
+
if (!property.computed && property.key.type === AST_NODE_TYPES106.Identifier) return property.key.name;
|
|
22606
|
+
return property.key.type === AST_NODE_TYPES106.Literal && typeof property.key.value === "string" ? property.key.value : null;
|
|
22151
22607
|
}
|
|
22152
22608
|
var require_static_next_matcher_default = createRule({
|
|
22153
22609
|
name: "require-static-next-matcher",
|
|
@@ -22169,19 +22625,19 @@ var require_static_next_matcher_default = createRule({
|
|
|
22169
22625
|
}
|
|
22170
22626
|
return {
|
|
22171
22627
|
ExportNamedDeclaration(node) {
|
|
22172
|
-
if (node.declaration?.type !==
|
|
22628
|
+
if (node.declaration?.type !== AST_NODE_TYPES106.VariableDeclaration) {
|
|
22173
22629
|
return;
|
|
22174
22630
|
}
|
|
22175
22631
|
for (const declaration of node.declaration.declarations) {
|
|
22176
|
-
if (declaration.id.type !==
|
|
22632
|
+
if (declaration.id.type !== AST_NODE_TYPES106.Identifier || declaration.id.name !== "config" || declaration.init === null) {
|
|
22177
22633
|
continue;
|
|
22178
22634
|
}
|
|
22179
22635
|
const config = unwrapExpression(declaration.init);
|
|
22180
|
-
if (config.type !==
|
|
22636
|
+
if (config.type !== AST_NODE_TYPES106.ObjectExpression) {
|
|
22181
22637
|
continue;
|
|
22182
22638
|
}
|
|
22183
22639
|
for (const property of config.properties) {
|
|
22184
|
-
if (property.type !==
|
|
22640
|
+
if (property.type !== AST_NODE_TYPES106.Property || propertyName5(property) !== "matcher" || property.value.type === AST_NODE_TYPES106.AssignmentPattern) {
|
|
22185
22641
|
continue;
|
|
22186
22642
|
}
|
|
22187
22643
|
if (!isStaticValue(property.value)) {
|
|
@@ -22195,7 +22651,7 @@ var require_static_next_matcher_default = createRule({
|
|
|
22195
22651
|
});
|
|
22196
22652
|
|
|
22197
22653
|
// src/rules/require-use-form-default-values.ts
|
|
22198
|
-
import { AST_NODE_TYPES as
|
|
22654
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES107, ASTUtils as ASTUtils65 } from "@typescript-eslint/utils";
|
|
22199
22655
|
var REQUIRE_USE_FORM_DEFAULT_VALUES_DOCUMENTATION = {
|
|
22200
22656
|
summary: "Require explicit form-level initialization or a field default for directly bound Controller fields.",
|
|
22201
22657
|
rationale: "React Hook Form exposes form-level defaultValues/values and field-level defaultValue as its explicit initialization mechanisms. A directly bound controlled field should not omit both mechanisms.",
|
|
@@ -22226,10 +22682,10 @@ var REQUIRE_USE_FORM_DEFAULT_VALUES_DOCUMENTATION = {
|
|
|
22226
22682
|
}
|
|
22227
22683
|
]
|
|
22228
22684
|
};
|
|
22229
|
-
function
|
|
22685
|
+
function staticPropertyName2(property) {
|
|
22230
22686
|
if (property.computed) return null;
|
|
22231
|
-
if (property.key.type ===
|
|
22232
|
-
if (property.key.type ===
|
|
22687
|
+
if (property.key.type === AST_NODE_TYPES107.Identifier) return property.key.name;
|
|
22688
|
+
if (property.key.type === AST_NODE_TYPES107.Literal && typeof property.key.value === "string") return property.key.value;
|
|
22233
22689
|
return null;
|
|
22234
22690
|
}
|
|
22235
22691
|
var require_use_form_default_values_default = createRule({
|
|
@@ -22246,7 +22702,7 @@ var require_use_form_default_values_default = createRule({
|
|
|
22246
22702
|
const imported = /* @__PURE__ */ new Map();
|
|
22247
22703
|
const uninitializedForms = /* @__PURE__ */ new Set();
|
|
22248
22704
|
const uninitializedControls = /* @__PURE__ */ new Set();
|
|
22249
|
-
const bindingNamed = (node, name) =>
|
|
22705
|
+
const bindingNamed = (node, name) => ASTUtils65.findVariable(context.sourceCode.getScope(node), name);
|
|
22250
22706
|
const bindingOf = (node) => bindingNamed(node, node.name);
|
|
22251
22707
|
const stable = (variable) => !variable.references.some((reference) => reference.isWrite() && reference.init !== true);
|
|
22252
22708
|
const importedKind = (node) => {
|
|
@@ -22259,49 +22715,49 @@ var require_use_form_default_values_default = createRule({
|
|
|
22259
22715
|
};
|
|
22260
22716
|
const isDefinitelyUndefined = (node) => {
|
|
22261
22717
|
const value = unwrapExpression(node);
|
|
22262
|
-
return value.type ===
|
|
22718
|
+
return value.type === AST_NODE_TYPES107.UnaryExpression && value.operator === "void" || value.type === AST_NODE_TYPES107.Identifier && value.name === "undefined" && (bindingOf(value)?.defs.length ?? 0) === 0;
|
|
22263
22719
|
};
|
|
22264
22720
|
const uninitializedUseFormCall = (node) => {
|
|
22265
22721
|
node = unwrapExpression(node);
|
|
22266
22722
|
const unwrappedNodeCallee = node.type === "CallExpression" || node.type === "NewExpression" ? unwrapExpression(node.callee) : null;
|
|
22267
|
-
if (node.type !==
|
|
22723
|
+
if (node.type !== AST_NODE_TYPES107.CallExpression || unwrappedNodeCallee?.type !== AST_NODE_TYPES107.Identifier || importedKind(unwrappedNodeCallee) !== "useForm") return false;
|
|
22268
22724
|
const options = node.arguments[0];
|
|
22269
|
-
return options?.type !==
|
|
22725
|
+
return options?.type !== AST_NODE_TYPES107.SpreadElement && initializationState(options) === "uninitialized";
|
|
22270
22726
|
};
|
|
22271
22727
|
const initializationState = (node) => {
|
|
22272
22728
|
if (node === void 0) return "uninitialized";
|
|
22273
|
-
if (node.type !==
|
|
22729
|
+
if (node.type !== AST_NODE_TYPES107.ObjectExpression) return "unknown";
|
|
22274
22730
|
const initialization = /* @__PURE__ */ new Map();
|
|
22275
22731
|
for (const property of node.properties) {
|
|
22276
|
-
if (property.type ===
|
|
22277
|
-
if (property.type !==
|
|
22278
|
-
const name =
|
|
22732
|
+
if (property.type === AST_NODE_TYPES107.SpreadElement || property.computed) return "unknown";
|
|
22733
|
+
if (property.type !== AST_NODE_TYPES107.Property) continue;
|
|
22734
|
+
const name = staticPropertyName2(property);
|
|
22279
22735
|
if (name === "defaultValues" || name === "values") initialization.set(name, !isDefinitelyUndefined(property.value));
|
|
22280
22736
|
}
|
|
22281
22737
|
return [...initialization.values()].some(Boolean) ? "initialized" : "uninitialized";
|
|
22282
22738
|
};
|
|
22283
22739
|
const isUninitializedForm = (node) => {
|
|
22284
22740
|
node = unwrapExpression(node);
|
|
22285
|
-
if (node.type !==
|
|
22741
|
+
if (node.type !== AST_NODE_TYPES107.Identifier) return false;
|
|
22286
22742
|
const variable = bindingOf(node);
|
|
22287
22743
|
return variable !== null && stable(variable) && uninitializedForms.has(variable);
|
|
22288
22744
|
};
|
|
22289
22745
|
const isUninitializedControl = (node) => {
|
|
22290
22746
|
node = unwrapExpression(node);
|
|
22291
|
-
if (node.type ===
|
|
22747
|
+
if (node.type === AST_NODE_TYPES107.Identifier) {
|
|
22292
22748
|
const variable = bindingOf(node);
|
|
22293
22749
|
return variable !== null && stable(variable) && uninitializedControls.has(variable);
|
|
22294
22750
|
}
|
|
22295
|
-
return node.type ===
|
|
22751
|
+
return node.type === AST_NODE_TYPES107.MemberExpression && ASTUtils65.getPropertyName(node) !== null && (ASTUtils65.getPropertyName(node) ?? "") === "control" && isUninitializedForm(node.object);
|
|
22296
22752
|
};
|
|
22297
22753
|
const fieldOptionsNeedDefault = (node) => {
|
|
22298
|
-
if (node?.type !==
|
|
22754
|
+
if (node?.type !== AST_NODE_TYPES107.ObjectExpression) return false;
|
|
22299
22755
|
let control = null;
|
|
22300
22756
|
let hasDefault = false;
|
|
22301
22757
|
for (const property of node.properties) {
|
|
22302
|
-
if (property.type ===
|
|
22303
|
-
if (property.type !==
|
|
22304
|
-
const name =
|
|
22758
|
+
if (property.type === AST_NODE_TYPES107.SpreadElement || property.computed) return false;
|
|
22759
|
+
if (property.type !== AST_NODE_TYPES107.Property) continue;
|
|
22760
|
+
const name = staticPropertyName2(property);
|
|
22305
22761
|
if (name === "control") control = property.value;
|
|
22306
22762
|
if (name === "defaultValue") hasDefault = !isDefinitelyUndefined(property.value);
|
|
22307
22763
|
}
|
|
@@ -22310,14 +22766,14 @@ var require_use_form_default_values_default = createRule({
|
|
|
22310
22766
|
const jsxAttribute = (node, name) => {
|
|
22311
22767
|
let result = null;
|
|
22312
22768
|
for (const attribute of node.attributes) {
|
|
22313
|
-
if (attribute.type ===
|
|
22314
|
-
if (attribute.name.type ===
|
|
22769
|
+
if (attribute.type === AST_NODE_TYPES107.JSXSpreadAttribute) return null;
|
|
22770
|
+
if (attribute.name.type === AST_NODE_TYPES107.JSXIdentifier && attribute.name.name === name) result = attribute;
|
|
22315
22771
|
}
|
|
22316
22772
|
return result;
|
|
22317
22773
|
};
|
|
22318
22774
|
const trackDestructuredControl = (pattern) => {
|
|
22319
22775
|
for (const property of pattern.properties) {
|
|
22320
|
-
if (property.type !==
|
|
22776
|
+
if (property.type !== AST_NODE_TYPES107.Property || staticPropertyName2(property) !== "control" || property.value.type !== AST_NODE_TYPES107.Identifier) continue;
|
|
22321
22777
|
const variable = bindingOf(property.value);
|
|
22322
22778
|
if (variable !== null) uninitializedControls.add(variable);
|
|
22323
22779
|
}
|
|
@@ -22326,8 +22782,8 @@ var require_use_form_default_values_default = createRule({
|
|
|
22326
22782
|
ImportDeclaration(node) {
|
|
22327
22783
|
if (node.source.value !== "react-hook-form") return;
|
|
22328
22784
|
for (const specifier of node.specifiers) {
|
|
22329
|
-
if (specifier.type !==
|
|
22330
|
-
const name = specifier.imported.type ===
|
|
22785
|
+
if (specifier.type !== AST_NODE_TYPES107.ImportSpecifier) continue;
|
|
22786
|
+
const name = specifier.imported.type === AST_NODE_TYPES107.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
22331
22787
|
if (name !== "Controller" && name !== "useController" && name !== "useForm") continue;
|
|
22332
22788
|
const variable = bindingOf(specifier.local);
|
|
22333
22789
|
if (variable !== null) imported.set(variable, name);
|
|
@@ -22336,35 +22792,35 @@ var require_use_form_default_values_default = createRule({
|
|
|
22336
22792
|
VariableDeclarator(node) {
|
|
22337
22793
|
if (node.init === null) return;
|
|
22338
22794
|
if (uninitializedUseFormCall(node.init)) {
|
|
22339
|
-
if (node.id.type ===
|
|
22795
|
+
if (node.id.type === AST_NODE_TYPES107.Identifier) {
|
|
22340
22796
|
const variable = bindingOf(node.id);
|
|
22341
22797
|
if (variable !== null) uninitializedForms.add(variable);
|
|
22342
|
-
} else if (node.id.type ===
|
|
22798
|
+
} else if (node.id.type === AST_NODE_TYPES107.ObjectPattern) {
|
|
22343
22799
|
trackDestructuredControl(node.id);
|
|
22344
22800
|
}
|
|
22345
22801
|
return;
|
|
22346
22802
|
}
|
|
22347
|
-
if (node.id.type ===
|
|
22803
|
+
if (node.id.type === AST_NODE_TYPES107.ObjectPattern && isUninitializedForm(node.init)) {
|
|
22348
22804
|
trackDestructuredControl(node.id);
|
|
22349
22805
|
return;
|
|
22350
22806
|
}
|
|
22351
|
-
if (node.id.type ===
|
|
22807
|
+
if (node.id.type === AST_NODE_TYPES107.Identifier && node.init.type === AST_NODE_TYPES107.MemberExpression && ASTUtils65.getPropertyName(node.init) !== null && (ASTUtils65.getPropertyName(node.init) ?? "") === "control" && isUninitializedForm(node.init.object)) {
|
|
22352
22808
|
const variable = bindingOf(node.id);
|
|
22353
22809
|
if (variable !== null) uninitializedControls.add(variable);
|
|
22354
22810
|
}
|
|
22355
22811
|
},
|
|
22356
22812
|
CallExpression(node) {
|
|
22357
22813
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
22358
|
-
if (unwrappedNodeCallee.type !==
|
|
22814
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES107.Identifier || importedKind(unwrappedNodeCallee) !== "useController" || !fieldOptionsNeedDefault(node.arguments[0]?.type === AST_NODE_TYPES107.SpreadElement ? void 0 : node.arguments[0])) return;
|
|
22359
22815
|
context.report({ node, messageId: "requireUseFormDefaultValues" });
|
|
22360
22816
|
},
|
|
22361
22817
|
JSXOpeningElement(node) {
|
|
22362
|
-
if (node.name.type !==
|
|
22363
|
-
if (node.attributes.some((attribute) => attribute.type ===
|
|
22818
|
+
if (node.name.type !== AST_NODE_TYPES107.JSXIdentifier || importedJsxKind(node.name) !== "Controller") return;
|
|
22819
|
+
if (node.attributes.some((attribute) => attribute.type === AST_NODE_TYPES107.JSXSpreadAttribute)) return;
|
|
22364
22820
|
const control = jsxAttribute(node, "control");
|
|
22365
|
-
if (control?.value?.type !==
|
|
22821
|
+
if (control?.value?.type !== AST_NODE_TYPES107.JSXExpressionContainer || control.value.expression.type === AST_NODE_TYPES107.JSXEmptyExpression || !isUninitializedControl(control.value.expression)) return;
|
|
22366
22822
|
const defaultValue = jsxAttribute(node, "defaultValue");
|
|
22367
|
-
if (defaultValue !== null && (defaultValue.value === null || defaultValue.value.type !==
|
|
22823
|
+
if (defaultValue !== null && (defaultValue.value === null || defaultValue.value.type !== AST_NODE_TYPES107.JSXExpressionContainer || defaultValue.value.expression.type !== AST_NODE_TYPES107.JSXEmptyExpression && !isDefinitelyUndefined(defaultValue.value.expression))) return;
|
|
22368
22824
|
context.report({ node, messageId: "requireUseFormDefaultValues" });
|
|
22369
22825
|
}
|
|
22370
22826
|
};
|
|
@@ -22440,8 +22896,8 @@ var require_use_server_in_actions_file_default = createRule({
|
|
|
22440
22896
|
|
|
22441
22897
|
// src/rules/require-zod-form-validation.ts
|
|
22442
22898
|
import {
|
|
22443
|
-
AST_NODE_TYPES as
|
|
22444
|
-
ASTUtils as
|
|
22899
|
+
AST_NODE_TYPES as AST_NODE_TYPES108,
|
|
22900
|
+
ASTUtils as ASTUtils66
|
|
22445
22901
|
} from "@typescript-eslint/utils";
|
|
22446
22902
|
var REQUIRE_ZOD_FORM_VALIDATION_DOCUMENTATION = {
|
|
22447
22903
|
summary: "Require Zod validation (`Schema.parse(...)` / `Schema.safeParse(...)`) when reading values out of a `FormData` object.",
|
|
@@ -22468,14 +22924,14 @@ var FORM_VALUE_METHODS = /* @__PURE__ */ new Set(["get", "getAll"]);
|
|
|
22468
22924
|
var zodReceiverRoot = (node) => {
|
|
22469
22925
|
let current = node;
|
|
22470
22926
|
while (true) {
|
|
22471
|
-
if (current.type ===
|
|
22927
|
+
if (current.type === AST_NODE_TYPES108.Identifier) {
|
|
22472
22928
|
return current;
|
|
22473
22929
|
}
|
|
22474
|
-
if (current.type ===
|
|
22930
|
+
if (current.type === AST_NODE_TYPES108.CallExpression) {
|
|
22475
22931
|
current = current.callee;
|
|
22476
22932
|
continue;
|
|
22477
22933
|
}
|
|
22478
|
-
if (current.type ===
|
|
22934
|
+
if (current.type === AST_NODE_TYPES108.MemberExpression) {
|
|
22479
22935
|
current = current.object;
|
|
22480
22936
|
continue;
|
|
22481
22937
|
}
|
|
@@ -22484,12 +22940,12 @@ var zodReceiverRoot = (node) => {
|
|
|
22484
22940
|
};
|
|
22485
22941
|
var isFormDataMethodCall = (node) => {
|
|
22486
22942
|
let current = node;
|
|
22487
|
-
if (current.type ===
|
|
22943
|
+
if (current.type === AST_NODE_TYPES108.AwaitExpression) {
|
|
22488
22944
|
current = current.argument;
|
|
22489
22945
|
}
|
|
22490
|
-
if (current.type !==
|
|
22946
|
+
if (current.type !== AST_NODE_TYPES108.CallExpression) return false;
|
|
22491
22947
|
const callee = unwrapExpression(current.callee);
|
|
22492
|
-
return callee.type ===
|
|
22948
|
+
return callee.type === AST_NODE_TYPES108.MemberExpression && ASTUtils66.getPropertyName(callee) === "formData";
|
|
22493
22949
|
};
|
|
22494
22950
|
var require_zod_form_validation_default = createRule({
|
|
22495
22951
|
name: "require-zod-form-validation",
|
|
@@ -22510,29 +22966,29 @@ var require_zod_form_validation_default = createRule({
|
|
|
22510
22966
|
return {};
|
|
22511
22967
|
}
|
|
22512
22968
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
22513
|
-
const resolvedBinding = (identifier) =>
|
|
22969
|
+
const resolvedBinding = (identifier) => ASTUtils66.findVariable(
|
|
22514
22970
|
context.sourceCode.getScope(identifier),
|
|
22515
22971
|
identifier.name
|
|
22516
22972
|
);
|
|
22517
22973
|
const isFormDataGetCall = (node) => {
|
|
22518
22974
|
const callee = unwrapExpression(node.callee);
|
|
22519
|
-
const calleeReceiver = callee.type ===
|
|
22520
|
-
if (callee.type !==
|
|
22521
|
-
if (
|
|
22975
|
+
const calleeReceiver = callee.type === AST_NODE_TYPES108.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
22976
|
+
if (callee.type !== AST_NODE_TYPES108.MemberExpression) return false;
|
|
22977
|
+
if (ASTUtils66.getPropertyName(callee) === null || !FORM_VALUE_METHODS.has(ASTUtils66.getPropertyName(callee) ?? "")) {
|
|
22522
22978
|
return false;
|
|
22523
22979
|
}
|
|
22524
22980
|
return isFormSourceIdentifier(calleeReceiver);
|
|
22525
22981
|
};
|
|
22526
22982
|
const isFormSourceIdentifier = (node) => {
|
|
22527
22983
|
node = unwrapExpression(node);
|
|
22528
|
-
if (node.type !==
|
|
22984
|
+
if (node.type !== AST_NODE_TYPES108.Identifier) return false;
|
|
22529
22985
|
const conventionalName = /formdata/i.test(node.name);
|
|
22530
22986
|
let scope = context.sourceCode.getScope(node);
|
|
22531
22987
|
while (scope !== null) {
|
|
22532
22988
|
const variable = scope.set.get(node.name);
|
|
22533
22989
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
22534
22990
|
const def = variable.defs[0];
|
|
22535
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
22991
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === AST_NODE_TYPES108.VariableDeclarator && def.node.init !== null) {
|
|
22536
22992
|
return isFormDataMethodCall(def.node.init);
|
|
22537
22993
|
}
|
|
22538
22994
|
return def?.type === "Parameter" && conventionalName;
|
|
@@ -22545,24 +23001,24 @@ var require_zod_form_validation_default = createRule({
|
|
|
22545
23001
|
let parent = node.parent;
|
|
22546
23002
|
while (parent !== null && parent !== void 0) {
|
|
22547
23003
|
if (isZodParseCall(parent)) return parent;
|
|
22548
|
-
if (parent.type ===
|
|
23004
|
+
if (parent.type === AST_NODE_TYPES108.CallExpression && parent.callee.type === AST_NODE_TYPES108.Identifier && ["Number", "String", "Boolean"].includes(parent.callee.name) && parent.arguments.length === 1 && (resolvedBinding(parent.callee)?.defs.length ?? 0) === 0) {
|
|
22549
23005
|
parent = parent.parent;
|
|
22550
23006
|
continue;
|
|
22551
23007
|
}
|
|
22552
|
-
if (parent.type ===
|
|
23008
|
+
if (parent.type === AST_NODE_TYPES108.CallExpression && parent.callee.type === AST_NODE_TYPES108.MemberExpression && parent.callee.object.type === AST_NODE_TYPES108.Identifier && parent.callee.object.name === "Object" && ASTUtils66.getPropertyName(parent.callee) === "fromEntries" && (resolvedBinding(parent.callee.object)?.defs.length ?? 0) === 0) {
|
|
22553
23009
|
parent = parent.parent;
|
|
22554
23010
|
continue;
|
|
22555
23011
|
}
|
|
22556
|
-
if (parent.type ===
|
|
23012
|
+
if (parent.type === AST_NODE_TYPES108.CallExpression || parent.type === AST_NODE_TYPES108.NewExpression || parent.type === AST_NODE_TYPES108.TaggedTemplateExpression || parent.type === AST_NODE_TYPES108.ArrowFunctionExpression || parent.type === AST_NODE_TYPES108.FunctionExpression || parent.type === AST_NODE_TYPES108.FunctionDeclaration) return null;
|
|
22557
23013
|
parent = parent.parent;
|
|
22558
23014
|
}
|
|
22559
23015
|
return null;
|
|
22560
23016
|
};
|
|
22561
23017
|
const isZodParseCall = (node) => {
|
|
22562
|
-
if (node.type !==
|
|
23018
|
+
if (node.type !== AST_NODE_TYPES108.CallExpression) return false;
|
|
22563
23019
|
const callee = unwrapExpression(node.callee);
|
|
22564
|
-
const calleeReceiver = callee.type ===
|
|
22565
|
-
if (callee.type !==
|
|
23020
|
+
const calleeReceiver = callee.type === AST_NODE_TYPES108.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
23021
|
+
if (callee.type !== AST_NODE_TYPES108.MemberExpression || ASTUtils66.getPropertyName(callee) === null || !ZOD_PARSE_METHODS.has(ASTUtils66.getPropertyName(callee) ?? "")) {
|
|
22566
23022
|
return false;
|
|
22567
23023
|
}
|
|
22568
23024
|
const root = zodReceiverRoot(calleeReceiver);
|
|
@@ -22576,25 +23032,25 @@ var require_zod_form_validation_default = createRule({
|
|
|
22576
23032
|
return false;
|
|
22577
23033
|
}
|
|
22578
23034
|
const definition = binding.defs[0];
|
|
22579
|
-
if (definition?.type !== "Variable" || definition.node.type !==
|
|
23035
|
+
if (definition?.type !== "Variable" || definition.node.type !== AST_NODE_TYPES108.VariableDeclarator) {
|
|
22580
23036
|
return false;
|
|
22581
23037
|
}
|
|
22582
23038
|
const init = definition.node.init;
|
|
22583
|
-
return init?.type ===
|
|
23039
|
+
return init?.type === AST_NODE_TYPES108.ObjectExpression || init?.type === AST_NODE_TYPES108.ArrayExpression || init?.type === AST_NODE_TYPES108.Literal || init?.type === AST_NODE_TYPES108.ArrowFunctionExpression || init?.type === AST_NODE_TYPES108.FunctionExpression;
|
|
22584
23040
|
};
|
|
22585
23041
|
const hasZodParseAncestor = (node) => zodParseAncestor(node) !== null;
|
|
22586
23042
|
const isInstanceofNarrowing = (node) => {
|
|
22587
23043
|
const parent = node.parent;
|
|
22588
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
23044
|
+
return parent !== null && parent !== void 0 && parent.type === AST_NODE_TYPES108.BinaryExpression && parent.operator === "instanceof" && parent.left === node && parent.right.type === AST_NODE_TYPES108.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
22589
23045
|
};
|
|
22590
23046
|
const boundDeclarator = (node) => {
|
|
22591
23047
|
let current = node;
|
|
22592
23048
|
let parent = current.parent;
|
|
22593
|
-
while ((parent.type ===
|
|
23049
|
+
while ((parent.type === AST_NODE_TYPES108.TSAsExpression || parent.type === AST_NODE_TYPES108.TSSatisfiesExpression || parent.type === AST_NODE_TYPES108.TSNonNullExpression || parent.type === AST_NODE_TYPES108.ChainExpression) && parent.expression === current) {
|
|
22594
23050
|
current = parent;
|
|
22595
23051
|
parent = current.parent;
|
|
22596
23052
|
}
|
|
22597
|
-
if (parent.type ===
|
|
23053
|
+
if (parent.type === AST_NODE_TYPES108.VariableDeclarator && parent.init === current && parent.id.type === AST_NODE_TYPES108.Identifier) {
|
|
22598
23054
|
return parent;
|
|
22599
23055
|
}
|
|
22600
23056
|
return null;
|
|
@@ -22603,7 +23059,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
22603
23059
|
let current = node;
|
|
22604
23060
|
while (current.parent !== void 0) {
|
|
22605
23061
|
const parent = current.parent;
|
|
22606
|
-
if (parent.type ===
|
|
23062
|
+
if (parent.type === AST_NODE_TYPES108.BlockStatement || parent.type === AST_NODE_TYPES108.Program) {
|
|
22607
23063
|
return current;
|
|
22608
23064
|
}
|
|
22609
23065
|
current = parent;
|
|
@@ -22618,7 +23074,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
22618
23074
|
if (declarationStatement === null || validationStatement === null || declarationStatement.parent !== validationStatement.parent || validationStatement.range[0] <= declarationStatement.range[1] || hasConditionalAncestorBeforeStatement(parse2, validationStatement)) {
|
|
22619
23075
|
return null;
|
|
22620
23076
|
}
|
|
22621
|
-
if (validationStatement.type !==
|
|
23077
|
+
if (validationStatement.type !== AST_NODE_TYPES108.VariableDeclaration && validationStatement.type !== AST_NODE_TYPES108.ExpressionStatement) {
|
|
22622
23078
|
return null;
|
|
22623
23079
|
}
|
|
22624
23080
|
const method = zodParseMethod(parse2);
|
|
@@ -22631,7 +23087,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
22631
23087
|
const isAwaitedBeforeStatement = (node, statement) => {
|
|
22632
23088
|
let current = node.parent;
|
|
22633
23089
|
while (current !== void 0 && current !== statement) {
|
|
22634
|
-
if (current.type ===
|
|
23090
|
+
if (current.type === AST_NODE_TYPES108.AwaitExpression) return true;
|
|
22635
23091
|
current = current.parent;
|
|
22636
23092
|
}
|
|
22637
23093
|
return false;
|
|
@@ -22639,7 +23095,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
22639
23095
|
const hasConditionalAncestorBeforeStatement = (node, statement) => {
|
|
22640
23096
|
let current = node.parent;
|
|
22641
23097
|
while (current !== void 0 && current !== statement) {
|
|
22642
|
-
if (current.type ===
|
|
23098
|
+
if (current.type === AST_NODE_TYPES108.LogicalExpression || current.type === AST_NODE_TYPES108.ConditionalExpression) {
|
|
22643
23099
|
return true;
|
|
22644
23100
|
}
|
|
22645
23101
|
current = current.parent;
|
|
@@ -22648,20 +23104,20 @@ var require_zod_form_validation_default = createRule({
|
|
|
22648
23104
|
};
|
|
22649
23105
|
const zodParseMethod = (call) => {
|
|
22650
23106
|
const callee = unwrapExpression(call.callee);
|
|
22651
|
-
return callee.type ===
|
|
23107
|
+
return callee.type === AST_NODE_TYPES108.MemberExpression && ASTUtils66.getPropertyName(callee) !== null ? ASTUtils66.getPropertyName(callee) ?? "" : null;
|
|
22652
23108
|
};
|
|
22653
23109
|
const isSafePrevalidationInspection = (identifier) => {
|
|
22654
23110
|
const parent = identifier.parent;
|
|
22655
|
-
if (parent.type ===
|
|
23111
|
+
if (parent.type === AST_NODE_TYPES108.UnaryExpression && parent.operator === "typeof") {
|
|
22656
23112
|
return true;
|
|
22657
23113
|
}
|
|
22658
|
-
if (parent.type !==
|
|
23114
|
+
if (parent.type !== AST_NODE_TYPES108.BinaryExpression || parent.left !== identifier) {
|
|
22659
23115
|
return false;
|
|
22660
23116
|
}
|
|
22661
23117
|
if (parent.operator === "instanceof") {
|
|
22662
|
-
return parent.right.type ===
|
|
23118
|
+
return parent.right.type === AST_NODE_TYPES108.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
22663
23119
|
}
|
|
22664
|
-
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type ===
|
|
23120
|
+
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type === AST_NODE_TYPES108.Literal && parent.right.value === null || parent.right.type === AST_NODE_TYPES108.Identifier && parent.right.name === "undefined");
|
|
22665
23121
|
};
|
|
22666
23122
|
const isDescendantOf = (node, ancestor) => {
|
|
22667
23123
|
let current = node;
|
|
@@ -22672,23 +23128,23 @@ var require_zod_form_validation_default = createRule({
|
|
|
22672
23128
|
return false;
|
|
22673
23129
|
};
|
|
22674
23130
|
const blockTerminates = (node) => {
|
|
22675
|
-
if (node.type ===
|
|
23131
|
+
if (node.type === AST_NODE_TYPES108.ReturnStatement || node.type === AST_NODE_TYPES108.ThrowStatement) {
|
|
22676
23132
|
return true;
|
|
22677
23133
|
}
|
|
22678
|
-
if (node.type !==
|
|
23134
|
+
if (node.type !== AST_NODE_TYPES108.BlockStatement || node.body.length === 0) return false;
|
|
22679
23135
|
const last = node.body.at(-1);
|
|
22680
23136
|
return last !== void 0 && blockTerminates(last);
|
|
22681
23137
|
};
|
|
22682
23138
|
const narrowingIf = (identifier) => {
|
|
22683
23139
|
const comparison = identifier.parent;
|
|
22684
|
-
if (comparison?.type !==
|
|
23140
|
+
if (comparison?.type !== AST_NODE_TYPES108.BinaryExpression || comparison.operator !== "instanceof" || comparison.left !== identifier || comparison.right.type !== AST_NODE_TYPES108.Identifier || comparison.right.name !== "File" && comparison.right.name !== "Blob") {
|
|
22685
23141
|
return null;
|
|
22686
23142
|
}
|
|
22687
23143
|
const maybeNegation = comparison.parent;
|
|
22688
|
-
const negated = maybeNegation?.type ===
|
|
23144
|
+
const negated = maybeNegation?.type === AST_NODE_TYPES108.UnaryExpression && maybeNegation.operator === "!";
|
|
22689
23145
|
const test = negated ? maybeNegation : comparison;
|
|
22690
23146
|
const branch = test.parent;
|
|
22691
|
-
return branch?.type ===
|
|
23147
|
+
return branch?.type === AST_NODE_TYPES108.IfStatement && branch.test === test ? { branch, positive: !negated } : null;
|
|
22692
23148
|
};
|
|
22693
23149
|
const useDominatedByNarrowing = (use, narrowings) => narrowings.some(({ branch, positive }) => {
|
|
22694
23150
|
if (positive) return isDescendantOf(use, branch.consequent);
|
|
@@ -22708,7 +23164,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
22708
23164
|
const variable = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
22709
23165
|
if (variable === void 0) return false;
|
|
22710
23166
|
const references = variable.references.filter((reference) => !reference.isWriteOnly()).map((reference) => reference.identifier).filter(
|
|
22711
|
-
(identifier) => identifier.type ===
|
|
23167
|
+
(identifier) => identifier.type === AST_NODE_TYPES108.Identifier
|
|
22712
23168
|
);
|
|
22713
23169
|
if (references.length === 0) return false;
|
|
22714
23170
|
const narrowings = references.map(narrowingIf).filter(
|
|
@@ -22734,7 +23190,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
22734
23190
|
ImportDeclaration(node) {
|
|
22735
23191
|
if (!isZodModule(node.source.value)) return;
|
|
22736
23192
|
for (const specifier of node.specifiers) {
|
|
22737
|
-
if (specifier.type ===
|
|
23193
|
+
if (specifier.type === AST_NODE_TYPES108.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES108.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES108.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES108.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
22738
23194
|
const binding = resolvedBinding(specifier.local);
|
|
22739
23195
|
if (binding !== null) zodBindings.add(binding);
|
|
22740
23196
|
}
|
|
@@ -22824,7 +23280,7 @@ function expressionCallableName(current) {
|
|
|
22824
23280
|
}
|
|
22825
23281
|
|
|
22826
23282
|
// src/rules/stepdown.ts
|
|
22827
|
-
import { AST_NODE_TYPES as
|
|
23283
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES109, ASTUtils as ASTUtils67 } from "@typescript-eslint/utils";
|
|
22828
23284
|
var STEPDOWN_DOCUMENTATION = {
|
|
22829
23285
|
summary: "Place a private helper below its sole direct same-scope caller.",
|
|
22830
23286
|
rationale: "Caller-first ordering lets a reader follow the main flow before descending into implementation details.",
|
|
@@ -22842,7 +23298,7 @@ var STEPDOWN_DOCUMENTATION = {
|
|
|
22842
23298
|
]
|
|
22843
23299
|
};
|
|
22844
23300
|
function isFunction(node) {
|
|
22845
|
-
return node.type ===
|
|
23301
|
+
return node.type === AST_NODE_TYPES109.ArrowFunctionExpression || node.type === AST_NODE_TYPES109.FunctionDeclaration || node.type === AST_NODE_TYPES109.FunctionExpression;
|
|
22846
23302
|
}
|
|
22847
23303
|
function reportMisordered(context, candidates, scopeDefinitions, calls, pinned, canMove = () => true) {
|
|
22848
23304
|
const byName = new Map(scopeDefinitions.map((definition) => [definition.key, definition]));
|
|
@@ -22938,7 +23394,7 @@ function cycleComponents(graph) {
|
|
|
22938
23394
|
return components;
|
|
22939
23395
|
}
|
|
22940
23396
|
function isErasedExpression2(node) {
|
|
22941
|
-
return node.type ===
|
|
23397
|
+
return node.type === AST_NODE_TYPES109.TSAsExpression || node.type === AST_NODE_TYPES109.TSTypeAssertion || node.type === AST_NODE_TYPES109.TSSatisfiesExpression || node.type === AST_NODE_TYPES109.TSNonNullExpression || node.type === AST_NODE_TYPES109.TSInstantiationExpression;
|
|
22942
23398
|
}
|
|
22943
23399
|
function unwrapExpression4(node) {
|
|
22944
23400
|
let current = node;
|
|
@@ -22962,11 +23418,11 @@ function localCallCount(context, node, owner) {
|
|
|
22962
23418
|
if (current === void 0 || enclosingFunction5(context, current) !== owner) return null;
|
|
22963
23419
|
const expression = wrappedExpression(current);
|
|
22964
23420
|
const parent = expression.parent;
|
|
22965
|
-
if (parent?.type ===
|
|
23421
|
+
if (parent?.type === AST_NODE_TYPES109.CallExpression && parent.callee === expression) {
|
|
22966
23422
|
count += 1;
|
|
22967
23423
|
continue;
|
|
22968
23424
|
}
|
|
22969
|
-
if (parent?.type !==
|
|
23425
|
+
if (parent?.type !== AST_NODE_TYPES109.VariableDeclarator || parent.init !== expression || parent.id.type !== AST_NODE_TYPES109.Identifier || parent.parent.type !== AST_NODE_TYPES109.VariableDeclaration || parent.parent.kind !== "const") return null;
|
|
22970
23426
|
const variable = context.sourceCode.getDeclaredVariables(parent)[0];
|
|
22971
23427
|
if (variable === void 0 || seen.has(variable) || !stableVariable(variable)) return null;
|
|
22972
23428
|
seen.add(variable);
|
|
@@ -22981,11 +23437,11 @@ function declarationScope(context, program) {
|
|
|
22981
23437
|
for (const node of declarations) counts.set(node.name, (counts.get(node.name) ?? 0) + 1);
|
|
22982
23438
|
const overloadNames = new Set(
|
|
22983
23439
|
program.body.flatMap((statement) => {
|
|
22984
|
-
const node = statement.type ===
|
|
22985
|
-
return node?.type ===
|
|
23440
|
+
const node = statement.type === AST_NODE_TYPES109.ExportNamedDeclaration ? statement.declaration : statement;
|
|
23441
|
+
return node?.type === AST_NODE_TYPES109.TSDeclareFunction && node.id !== null ? [node.id.name] : [];
|
|
22986
23442
|
})
|
|
22987
23443
|
);
|
|
22988
|
-
const exported = program.type ===
|
|
23444
|
+
const exported = program.type === AST_NODE_TYPES109.Program ? exportedNames(program) : /* @__PURE__ */ new Set();
|
|
22989
23445
|
const scopeDefinitions = declarations.filter((node) => counts.get(node.name) === 1);
|
|
22990
23446
|
const definitions = scopeDefinitions.filter(
|
|
22991
23447
|
(definition) => !exported.has(definition.name) && !overloadNames.has(definition.name)
|
|
@@ -22997,7 +23453,7 @@ function declarationScope(context, program) {
|
|
|
22997
23453
|
runtimeBarrierPrefix.push((runtimeBarrierPrefix.at(-1) ?? 0) + (isDeferredModuleStatement(statement) ? 0 : 1));
|
|
22998
23454
|
}
|
|
22999
23455
|
const canMove = (helper, caller) => {
|
|
23000
|
-
if (helper.node.type ===
|
|
23456
|
+
if (helper.node.type === AST_NODE_TYPES109.FunctionDeclaration) return true;
|
|
23001
23457
|
const helperIndex = statementIndex(helper);
|
|
23002
23458
|
const callerIndex = statementIndex(caller);
|
|
23003
23459
|
return helperIndex !== void 0 && callerIndex !== void 0 && runtimeBarrierPrefix[callerIndex + 1] === runtimeBarrierPrefix[helperIndex + 1];
|
|
@@ -23039,26 +23495,26 @@ function moduleCallGraph(context, scopeDefinitions) {
|
|
|
23039
23495
|
return { calls, pinned };
|
|
23040
23496
|
}
|
|
23041
23497
|
function isDeferredModuleStatement(statement) {
|
|
23042
|
-
const node = statement.type ===
|
|
23043
|
-
if (node === null || node.type ===
|
|
23044
|
-
return node.type ===
|
|
23045
|
-
(declaration) => declaration.id.type ===
|
|
23498
|
+
const node = statement.type === AST_NODE_TYPES109.ExportNamedDeclaration || statement.type === AST_NODE_TYPES109.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
23499
|
+
if (node === null || node.type === AST_NODE_TYPES109.FunctionDeclaration || node.type === AST_NODE_TYPES109.TSDeclareFunction || node.type === AST_NODE_TYPES109.TSInterfaceDeclaration || node.type === AST_NODE_TYPES109.TSTypeAliasDeclaration || node.type === AST_NODE_TYPES109.ImportDeclaration || node.type === AST_NODE_TYPES109.ExportAllDeclaration || node.type === AST_NODE_TYPES109.EmptyStatement) return true;
|
|
23500
|
+
return node.type === AST_NODE_TYPES109.VariableDeclaration && node.declarations.every(
|
|
23501
|
+
(declaration) => declaration.id.type === AST_NODE_TYPES109.Identifier && declaration.init !== null && isFunction(unwrapExpression4(declaration.init))
|
|
23046
23502
|
);
|
|
23047
23503
|
}
|
|
23048
23504
|
function exportedNames(program) {
|
|
23049
23505
|
const names = /* @__PURE__ */ new Set();
|
|
23050
23506
|
function collectNamedExports(statement) {
|
|
23051
|
-
if (statement.type !==
|
|
23052
|
-
if (statement.declaration?.type ===
|
|
23507
|
+
if (statement.type !== AST_NODE_TYPES109.ExportNamedDeclaration || statement.exportKind === "type" || statement.source !== null) return;
|
|
23508
|
+
if (statement.declaration?.type === AST_NODE_TYPES109.FunctionDeclaration && statement.declaration.id !== null) {
|
|
23053
23509
|
names.add(statement.declaration.id.name);
|
|
23054
23510
|
}
|
|
23055
|
-
if (statement.declaration?.type ===
|
|
23511
|
+
if (statement.declaration?.type === AST_NODE_TYPES109.VariableDeclaration) {
|
|
23056
23512
|
for (const declarator of statement.declaration.declarations) {
|
|
23057
|
-
if (declarator.id.type ===
|
|
23513
|
+
if (declarator.id.type === AST_NODE_TYPES109.Identifier) names.add(declarator.id.name);
|
|
23058
23514
|
}
|
|
23059
23515
|
}
|
|
23060
23516
|
for (const specifier of statement.specifiers) {
|
|
23061
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
23517
|
+
if (specifier.exportKind !== "type" && specifier.local.type === AST_NODE_TYPES109.Identifier) {
|
|
23062
23518
|
names.add(specifier.local.name);
|
|
23063
23519
|
}
|
|
23064
23520
|
}
|
|
@@ -23067,23 +23523,23 @@ function exportedNames(program) {
|
|
|
23067
23523
|
collectNamedExports(statement);
|
|
23068
23524
|
}
|
|
23069
23525
|
for (const statement of program.body) {
|
|
23070
|
-
if (statement.type ===
|
|
23071
|
-
if (statement.type ===
|
|
23526
|
+
if (statement.type === AST_NODE_TYPES109.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES109.Identifier) names.add(statement.declaration.name);
|
|
23527
|
+
if (statement.type === AST_NODE_TYPES109.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES109.FunctionDeclaration && statement.declaration.id !== null) names.add(statement.declaration.id.name);
|
|
23072
23528
|
}
|
|
23073
23529
|
return names;
|
|
23074
23530
|
}
|
|
23075
23531
|
function moduleDefinitions(program) {
|
|
23076
23532
|
const definitions = [];
|
|
23077
23533
|
for (const statement of program.body) {
|
|
23078
|
-
const node = statement.type ===
|
|
23079
|
-
if (node?.type ===
|
|
23534
|
+
const node = statement.type === AST_NODE_TYPES109.ExportNamedDeclaration || statement.type === AST_NODE_TYPES109.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
23535
|
+
if (node?.type === AST_NODE_TYPES109.FunctionDeclaration && node.id !== null && node.body !== null) {
|
|
23080
23536
|
definitions.push({ key: node.id.name, name: node.id.name, node, functionNode: node, bindingNode: node });
|
|
23081
23537
|
continue;
|
|
23082
23538
|
}
|
|
23083
|
-
if (node?.type !==
|
|
23539
|
+
if (node?.type !== AST_NODE_TYPES109.VariableDeclaration || node.kind !== "const" || node.declarations.length !== 1) continue;
|
|
23084
23540
|
for (const declarator of node.declarations) {
|
|
23085
23541
|
const initializer = declarator.init === null ? null : unwrapExpression4(declarator.init);
|
|
23086
|
-
if (declarator.id.type ===
|
|
23542
|
+
if (declarator.id.type === AST_NODE_TYPES109.Identifier && initializer !== null && isFunction(initializer)) {
|
|
23087
23543
|
definitions.push({
|
|
23088
23544
|
key: declarator.id.name,
|
|
23089
23545
|
name: declarator.id.name,
|
|
@@ -23097,25 +23553,25 @@ function moduleDefinitions(program) {
|
|
|
23097
23553
|
return definitions;
|
|
23098
23554
|
}
|
|
23099
23555
|
function methodName(node) {
|
|
23100
|
-
if (node.key.type ===
|
|
23101
|
-
if (!node.computed && node.key.type ===
|
|
23102
|
-
return node.key.type ===
|
|
23556
|
+
if (node.key.type === AST_NODE_TYPES109.PrivateIdentifier) return `#${node.key.name}`;
|
|
23557
|
+
if (!node.computed && node.key.type === AST_NODE_TYPES109.Identifier) return node.key.name;
|
|
23558
|
+
return node.key.type === AST_NODE_TYPES109.Literal && typeof node.key.value === "string" ? node.key.value : null;
|
|
23103
23559
|
}
|
|
23104
23560
|
function methodKey(name, isStatic2) {
|
|
23105
23561
|
return `${isStatic2 ? "static" : "instance"}:${name}`;
|
|
23106
23562
|
}
|
|
23107
23563
|
function receiverDomain(context, object, receivers, thisIsStatic) {
|
|
23108
23564
|
const unwrapped = unwrapExpression4(object);
|
|
23109
|
-
if (unwrapped.type ===
|
|
23565
|
+
if (unwrapped.type === AST_NODE_TYPES109.ThisExpression) return thisIsStatic;
|
|
23110
23566
|
return externalReceiverDomain(context, unwrapped, receivers);
|
|
23111
23567
|
}
|
|
23112
23568
|
function externalReceiverDomain(context, object, receivers) {
|
|
23113
23569
|
const origin = receiverOrigin(context, object, receivers);
|
|
23114
23570
|
if (origin === null || typeof origin === "boolean") return origin;
|
|
23115
|
-
if (origin.type ===
|
|
23571
|
+
if (origin.type === AST_NODE_TYPES109.NewExpression) {
|
|
23116
23572
|
return receiverOrigin(context, origin.callee, receivers) === true ? false : null;
|
|
23117
23573
|
}
|
|
23118
|
-
if (origin.type ===
|
|
23574
|
+
if (origin.type === AST_NODE_TYPES109.ObjectExpression || origin.type === AST_NODE_TYPES109.ArrayExpression || origin.type === AST_NODE_TYPES109.Literal || origin.type === AST_NODE_TYPES109.ArrowFunctionExpression || origin.type === AST_NODE_TYPES109.FunctionExpression) return "unrelated";
|
|
23119
23575
|
return null;
|
|
23120
23576
|
}
|
|
23121
23577
|
function receiverOrigin(context, object, receivers) {
|
|
@@ -23123,8 +23579,8 @@ function receiverOrigin(context, object, receivers) {
|
|
|
23123
23579
|
const seen = /* @__PURE__ */ new Set();
|
|
23124
23580
|
while (true) {
|
|
23125
23581
|
const unwrapped = unwrapExpression4(current);
|
|
23126
|
-
if (unwrapped.type !==
|
|
23127
|
-
const variable =
|
|
23582
|
+
if (unwrapped.type !== AST_NODE_TYPES109.Identifier) return unwrapped;
|
|
23583
|
+
const variable = ASTUtils67.findVariable(context.sourceCode.getScope(unwrapped), unwrapped.name);
|
|
23128
23584
|
if (variable === null) return null;
|
|
23129
23585
|
const known = receivers.get(variable);
|
|
23130
23586
|
if (known !== void 0) return known;
|
|
@@ -23137,25 +23593,25 @@ function immutableInitializer(variable, seen) {
|
|
|
23137
23593
|
if (seen.has(variable) || !stableVariable(variable) || variable.defs.length !== 1) return null;
|
|
23138
23594
|
seen.add(variable);
|
|
23139
23595
|
const definition = variable.defs[0];
|
|
23140
|
-
if (definition?.node.type !==
|
|
23596
|
+
if (definition?.node.type !== AST_NODE_TYPES109.VariableDeclarator || definition.node.parent.type !== AST_NODE_TYPES109.VariableDeclaration || definition.node.parent.kind !== "const") return null;
|
|
23141
23597
|
return definition.node.init;
|
|
23142
23598
|
}
|
|
23143
23599
|
function stableVariable(variable) {
|
|
23144
23600
|
return !variable.references.some((reference) => reference.isWrite() && reference.init !== true);
|
|
23145
23601
|
}
|
|
23146
23602
|
function referencedPropertyName(node) {
|
|
23147
|
-
if (node.property.type ===
|
|
23148
|
-
if (!node.computed && node.property.type ===
|
|
23149
|
-
return node.computed && node.property.type ===
|
|
23603
|
+
if (node.property.type === AST_NODE_TYPES109.PrivateIdentifier) return `#${node.property.name}`;
|
|
23604
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES109.Identifier) return node.property.name;
|
|
23605
|
+
return node.computed && node.property.type === AST_NODE_TYPES109.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
23150
23606
|
}
|
|
23151
23607
|
function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
23152
23608
|
visit(node, nestedFunction);
|
|
23153
|
-
const nested = nestedFunction || isFunction(node) || node.type ===
|
|
23609
|
+
const nested = nestedFunction || isFunction(node) || node.type === AST_NODE_TYPES109.ClassDeclaration || node.type === AST_NODE_TYPES109.ClassExpression;
|
|
23154
23610
|
forEachAstChild(node, visitorKeys, (child) => walk(child, visitorKeys, visit, nested));
|
|
23155
23611
|
}
|
|
23156
23612
|
function classScope(context, node, computedReferences) {
|
|
23157
23613
|
const methods = node.body.body.filter(
|
|
23158
|
-
(member) => member.type ===
|
|
23614
|
+
(member) => member.type === AST_NODE_TYPES109.MethodDefinition
|
|
23159
23615
|
);
|
|
23160
23616
|
const counts = classMethodCounts(node.body, methods);
|
|
23161
23617
|
const implementations = methods.filter((method) => isFunction(method.value));
|
|
@@ -23166,7 +23622,7 @@ function classScope(context, node, computedReferences) {
|
|
|
23166
23622
|
return name !== null && key !== null && implementationCounts.get(key) === 1 ? [{ key, name, node: method }] : [];
|
|
23167
23623
|
});
|
|
23168
23624
|
const definitions = scopeDefinitions.filter(
|
|
23169
|
-
({ key, node: method }) => (method.accessibility === "private" || method.key.type ===
|
|
23625
|
+
({ key, node: method }) => (method.accessibility === "private" || method.key.type === AST_NODE_TYPES109.PrivateIdentifier) && counts.get(key) === 1 && method.decorators.length === 0 && !method.computed && method.kind === "method"
|
|
23170
23626
|
);
|
|
23171
23627
|
if (definitions.length === 0) return;
|
|
23172
23628
|
const methodKeys = new Set(scopeDefinitions.map((definition) => definition.key));
|
|
@@ -23182,11 +23638,11 @@ function classScope(context, node, computedReferences) {
|
|
|
23182
23638
|
};
|
|
23183
23639
|
function pinDestructuredMembers(binding, domain) {
|
|
23184
23640
|
for (const property of binding.properties) {
|
|
23185
|
-
if (property.type ===
|
|
23641
|
+
if (property.type === AST_NODE_TYPES109.RestElement || property.computed) {
|
|
23186
23642
|
pinNames(null, domain);
|
|
23187
|
-
} else if (property.key.type ===
|
|
23643
|
+
} else if (property.key.type === AST_NODE_TYPES109.Identifier) {
|
|
23188
23644
|
pinNames(property.key.name, domain);
|
|
23189
|
-
} else if (property.key.type ===
|
|
23645
|
+
} else if (property.key.type === AST_NODE_TYPES109.Literal && typeof property.key.value === "string") {
|
|
23190
23646
|
pinNames(property.key.value, domain);
|
|
23191
23647
|
}
|
|
23192
23648
|
}
|
|
@@ -23208,15 +23664,15 @@ function classScope(context, node, computedReferences) {
|
|
|
23208
23664
|
}
|
|
23209
23665
|
}
|
|
23210
23666
|
const collectAlias = (current, nestedFunction) => {
|
|
23211
|
-
if (nestedFunction || current.type !==
|
|
23667
|
+
if (nestedFunction || current.type !== AST_NODE_TYPES109.VariableDeclarator || current.init === null) return;
|
|
23212
23668
|
const domain = receiverDomain(context, current.init, receivers, method.static);
|
|
23213
23669
|
if (domain === null || domain === "unrelated") return;
|
|
23214
|
-
if (current.id.type ===
|
|
23670
|
+
if (current.id.type === AST_NODE_TYPES109.ObjectPattern) {
|
|
23215
23671
|
pinDestructuredMembers(current.id, domain);
|
|
23216
23672
|
return;
|
|
23217
23673
|
}
|
|
23218
|
-
if (current.id.type !==
|
|
23219
|
-
if (current.parent.type !==
|
|
23674
|
+
if (current.id.type !== AST_NODE_TYPES109.Identifier) return;
|
|
23675
|
+
if (current.parent.type !== AST_NODE_TYPES109.VariableDeclaration || current.parent.kind !== "const") {
|
|
23220
23676
|
pinNames(null, domain);
|
|
23221
23677
|
return;
|
|
23222
23678
|
}
|
|
@@ -23225,7 +23681,7 @@ function classScope(context, node, computedReferences) {
|
|
|
23225
23681
|
const local = variable.references.every((reference) => {
|
|
23226
23682
|
if (!reference.isRead()) return true;
|
|
23227
23683
|
const expression = wrappedExpression(reference.identifier);
|
|
23228
|
-
return enclosingFunction5(context, reference.identifier) === methodFunction && expression.parent?.type ===
|
|
23684
|
+
return enclosingFunction5(context, reference.identifier) === methodFunction && expression.parent?.type === AST_NODE_TYPES109.MemberExpression && expression.parent.object === expression;
|
|
23229
23685
|
});
|
|
23230
23686
|
if (local) receivers.set(variable, domain);
|
|
23231
23687
|
else pinNames(null, domain);
|
|
@@ -23237,7 +23693,7 @@ function classScope(context, node, computedReferences) {
|
|
|
23237
23693
|
const domain2 = receiverDomain(context, destructuring.value, receivers, method.static);
|
|
23238
23694
|
if (domain2 !== "unrelated") pinDestructuredMembers(destructuring.binding, domain2);
|
|
23239
23695
|
}
|
|
23240
|
-
if (current.type !==
|
|
23696
|
+
if (current.type !== AST_NODE_TYPES109.MemberExpression) return;
|
|
23241
23697
|
const domain = receiverDomain(context, current.object, receivers, method.static);
|
|
23242
23698
|
const targetName = referencedPropertyName(current);
|
|
23243
23699
|
if (domain === "unrelated") return;
|
|
@@ -23271,9 +23727,9 @@ function classScope(context, node, computedReferences) {
|
|
|
23271
23727
|
}
|
|
23272
23728
|
for (const method of methods) collectMethodCalls(method);
|
|
23273
23729
|
for (const member of node.body.body) {
|
|
23274
|
-
if (member.type ===
|
|
23730
|
+
if (member.type === AST_NODE_TYPES109.MethodDefinition || member.type === AST_NODE_TYPES109.TSAbstractMethodDefinition) continue;
|
|
23275
23731
|
walk(member, context.sourceCode.visitorKeys, (current) => {
|
|
23276
|
-
if (current.type !==
|
|
23732
|
+
if (current.type !== AST_NODE_TYPES109.MemberExpression) return;
|
|
23277
23733
|
if (externalReceiverDomain(context, current.object, classReceivers) === "unrelated") return;
|
|
23278
23734
|
pinNames(referencedPropertyName(current));
|
|
23279
23735
|
});
|
|
@@ -23305,32 +23761,32 @@ function classScope(context, node, computedReferences) {
|
|
|
23305
23761
|
function classReceiverBindings(context, node) {
|
|
23306
23762
|
const classReceivers = /* @__PURE__ */ new Map();
|
|
23307
23763
|
if (node.id !== null) {
|
|
23308
|
-
const internal =
|
|
23764
|
+
const internal = ASTUtils67.findVariable(context.sourceCode.getScope(node), node.id.name);
|
|
23309
23765
|
if (internal !== null && stableVariable(internal)) classReceivers.set(internal, true);
|
|
23310
23766
|
}
|
|
23311
|
-
if (node.type ===
|
|
23312
|
-
const outer =
|
|
23767
|
+
if (node.type === AST_NODE_TYPES109.ClassExpression && node.parent.type === AST_NODE_TYPES109.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES109.Identifier && node.parent.parent.type === AST_NODE_TYPES109.VariableDeclaration && node.parent.parent.kind === "const") {
|
|
23768
|
+
const outer = ASTUtils67.findVariable(context.sourceCode.getScope(node.parent), node.parent.id.name);
|
|
23313
23769
|
if (outer !== null && stableVariable(outer)) classReceivers.set(outer, true);
|
|
23314
23770
|
}
|
|
23315
23771
|
return classReceivers;
|
|
23316
23772
|
}
|
|
23317
23773
|
function receiverDestructuring(node) {
|
|
23318
|
-
if (node.type ===
|
|
23774
|
+
if (node.type === AST_NODE_TYPES109.VariableDeclarator && node.id.type === AST_NODE_TYPES109.ObjectPattern && node.init !== null) {
|
|
23319
23775
|
return { binding: node.id, value: node.init };
|
|
23320
23776
|
}
|
|
23321
|
-
if ((node.type ===
|
|
23777
|
+
if ((node.type === AST_NODE_TYPES109.AssignmentPattern || node.type === AST_NODE_TYPES109.AssignmentExpression) && node.left.type === AST_NODE_TYPES109.ObjectPattern) {
|
|
23322
23778
|
return { binding: node.left, value: node.right };
|
|
23323
23779
|
}
|
|
23324
23780
|
return null;
|
|
23325
23781
|
}
|
|
23326
23782
|
function isClassRuntimeBarrier(member) {
|
|
23327
23783
|
switch (member.type) {
|
|
23328
|
-
case
|
|
23784
|
+
case AST_NODE_TYPES109.StaticBlock:
|
|
23329
23785
|
return true;
|
|
23330
|
-
case
|
|
23331
|
-
case
|
|
23786
|
+
case AST_NODE_TYPES109.PropertyDefinition:
|
|
23787
|
+
case AST_NODE_TYPES109.AccessorProperty:
|
|
23332
23788
|
return member.static || member.computed || member.decorators.length > 0 || member.value !== null;
|
|
23333
|
-
case
|
|
23789
|
+
case AST_NODE_TYPES109.MethodDefinition:
|
|
23334
23790
|
return member.computed || member.decorators.length > 0;
|
|
23335
23791
|
default:
|
|
23336
23792
|
return false;
|
|
@@ -23360,14 +23816,14 @@ var stepdown_default = createRule({
|
|
|
23360
23816
|
classes.push(node);
|
|
23361
23817
|
},
|
|
23362
23818
|
"FunctionDeclaration, FunctionExpression, ArrowFunctionExpression": (node) => {
|
|
23363
|
-
if (isFunction(node) && node.body?.type ===
|
|
23819
|
+
if (isFunction(node) && node.body?.type === AST_NODE_TYPES109.BlockStatement) functionBodies.push(node.body);
|
|
23364
23820
|
},
|
|
23365
23821
|
"Program:exit": (program) => {
|
|
23366
23822
|
declarationScope(context, program);
|
|
23367
23823
|
for (const body2 of functionBodies) declarationScope(context, body2);
|
|
23368
23824
|
const computedReferences = [];
|
|
23369
23825
|
walk(program, context.sourceCode.visitorKeys, (node) => {
|
|
23370
|
-
if (node.type ===
|
|
23826
|
+
if (node.type === AST_NODE_TYPES109.MemberExpression && node.computed) computedReferences.push(node);
|
|
23371
23827
|
});
|
|
23372
23828
|
for (const node of classes) classScope(context, node, computedReferences);
|
|
23373
23829
|
}
|
|
@@ -23384,8 +23840,8 @@ function classMethodCounts(body2, methods) {
|
|
|
23384
23840
|
}
|
|
23385
23841
|
}
|
|
23386
23842
|
for (const member of body2.body) {
|
|
23387
|
-
if (member.type !==
|
|
23388
|
-
const name = !member.computed && member.key.type ===
|
|
23843
|
+
if (member.type !== AST_NODE_TYPES109.TSAbstractMethodDefinition) continue;
|
|
23844
|
+
const name = !member.computed && member.key.type === AST_NODE_TYPES109.Identifier ? member.key.name : null;
|
|
23389
23845
|
if (name !== null) {
|
|
23390
23846
|
const key = methodKey(name, member.static);
|
|
23391
23847
|
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
@@ -23395,7 +23851,7 @@ function classMethodCounts(body2, methods) {
|
|
|
23395
23851
|
}
|
|
23396
23852
|
|
|
23397
23853
|
// src/rules/source-coupled-test.ts
|
|
23398
|
-
import { AST_NODE_TYPES as
|
|
23854
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES110, ASTUtils as ASTUtils68 } from "@typescript-eslint/utils";
|
|
23399
23855
|
var GENERAL_SOURCE_SUFFIX_RE = /\.(?:bash|sh|ya?ml|jsonc?|toml|py|[cm]?[jt]s)$/iu;
|
|
23400
23856
|
var FS_MODULES = /* @__PURE__ */ new Set(["fs", "node:fs", "fs/promises", "node:fs/promises"]);
|
|
23401
23857
|
var FS_READERS = /* @__PURE__ */ new Set(["readFile", "readFileSync"]);
|
|
@@ -23469,16 +23925,16 @@ var SOURCE_COUPLED_TEST_DOCUMENTATION = {
|
|
|
23469
23925
|
function unwrap6(node) {
|
|
23470
23926
|
for (; ; ) {
|
|
23471
23927
|
node = unwrapExpression(node);
|
|
23472
|
-
if (node.type ===
|
|
23473
|
-
else if (node.type ===
|
|
23928
|
+
if (node.type === AST_NODE_TYPES110.AwaitExpression) node = node.argument;
|
|
23929
|
+
else if (node.type === AST_NODE_TYPES110.ChainExpression) node = node.expression;
|
|
23474
23930
|
else return node;
|
|
23475
23931
|
}
|
|
23476
23932
|
}
|
|
23477
23933
|
function stringValue(node) {
|
|
23478
23934
|
const current = unwrap6(node);
|
|
23479
|
-
if (current.type ===
|
|
23480
|
-
if (current.type ===
|
|
23481
|
-
if (current.type ===
|
|
23935
|
+
if (current.type === AST_NODE_TYPES110.Literal && typeof current.value === "string") return current.value;
|
|
23936
|
+
if (current.type === AST_NODE_TYPES110.TemplateLiteral && current.expressions.length === 0) return current.quasis[0]?.value.cooked ?? null;
|
|
23937
|
+
if (current.type === AST_NODE_TYPES110.BinaryExpression && current.operator === "+") {
|
|
23482
23938
|
const left = stringValue(current.left);
|
|
23483
23939
|
const right = stringValue(current.right);
|
|
23484
23940
|
return left === null || right === null ? null : left + right;
|
|
@@ -23490,7 +23946,7 @@ function importSource(node) {
|
|
|
23490
23946
|
}
|
|
23491
23947
|
function requireSource(node) {
|
|
23492
23948
|
const current = unwrap6(node);
|
|
23493
|
-
if (current.type !==
|
|
23949
|
+
if (current.type !== AST_NODE_TYPES110.CallExpression || current.callee.type !== AST_NODE_TYPES110.Identifier || current.callee.name !== "require" || current.arguments.length !== 1 || current.arguments[0]?.type === AST_NODE_TYPES110.SpreadElement) return null;
|
|
23494
23950
|
return stringValue(current.arguments[0]);
|
|
23495
23951
|
}
|
|
23496
23952
|
function newScope() {
|
|
@@ -23512,7 +23968,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
23512
23968
|
const scopes = [newScope()];
|
|
23513
23969
|
const reportedOrigins = /* @__PURE__ */ new Set();
|
|
23514
23970
|
const currentScope = () => scopes.at(-1) ?? scopes[0];
|
|
23515
|
-
const bindingOf = (node) =>
|
|
23971
|
+
const bindingOf = (node) => ASTUtils68.findVariable(context.sourceCode.getScope(node), node.name);
|
|
23516
23972
|
const assertionKind = (node) => {
|
|
23517
23973
|
const binding = bindingOf(node);
|
|
23518
23974
|
if (binding === null || binding.defs.length === 0) {
|
|
@@ -23546,75 +24002,75 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
23546
24002
|
const current = unwrap6(node);
|
|
23547
24003
|
const value = stringValue(current);
|
|
23548
24004
|
if (value !== null) return sourceSuffixRe.test(value);
|
|
23549
|
-
if (current.type ===
|
|
23550
|
-
if (current.type ===
|
|
24005
|
+
if (current.type === AST_NODE_TYPES110.Identifier) return visible("paths", current);
|
|
24006
|
+
if (current.type === AST_NODE_TYPES110.CallExpression || current.type === AST_NODE_TYPES110.NewExpression) {
|
|
23551
24007
|
const callee = unwrapExpression(current.callee);
|
|
23552
24008
|
const first = current.arguments[0];
|
|
23553
|
-
if (first === void 0 || first.type ===
|
|
23554
|
-
if (current.type ===
|
|
23555
|
-
if (callee.type ===
|
|
24009
|
+
if (first === void 0 || first.type === AST_NODE_TYPES110.SpreadElement) return false;
|
|
24010
|
+
if (current.type === AST_NODE_TYPES110.NewExpression && callee.type === AST_NODE_TYPES110.Identifier && callee.name === "URL" && (bindingOf(callee)?.defs.length ?? 0) === 0) return sourcePath(first);
|
|
24011
|
+
if (callee.type === AST_NODE_TYPES110.Identifier && bindingOf(callee)?.defs.some((definition) => definition.node.type === AST_NODE_TYPES110.ImportSpecifier && definition.node.imported.type === AST_NODE_TYPES110.Identifier && definition.node.imported.name === "fileURLToPath" && definition.node.parent.type === AST_NODE_TYPES110.ImportDeclaration && ["node:url", "url"].includes(String(definition.node.parent.source.value)))) return sourcePath(first);
|
|
23556
24012
|
}
|
|
23557
24013
|
return false;
|
|
23558
24014
|
};
|
|
23559
24015
|
const rawRead = (node) => {
|
|
23560
24016
|
const current = unwrap6(node);
|
|
23561
|
-
if (current.type !==
|
|
24017
|
+
if (current.type !== AST_NODE_TYPES110.CallExpression || current.arguments.length === 0) return false;
|
|
23562
24018
|
const callee = unwrap6(current.callee);
|
|
23563
|
-
const calleeReceiver = callee.type ===
|
|
23564
|
-
if (callee.type ===
|
|
24019
|
+
const calleeReceiver = callee.type === AST_NODE_TYPES110.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
24020
|
+
if (callee.type === AST_NODE_TYPES110.Identifier) {
|
|
23565
24021
|
return visible("fsReaders", callee) && sourcePath(current.arguments[0]);
|
|
23566
24022
|
}
|
|
23567
|
-
if (callee.type !==
|
|
23568
|
-
const name2 =
|
|
24023
|
+
if (callee.type !== AST_NODE_TYPES110.MemberExpression) return false;
|
|
24024
|
+
const name2 = ASTUtils68.getPropertyName(callee);
|
|
23569
24025
|
const object = unwrap6(calleeReceiver);
|
|
23570
|
-
return name2 !== null && FS_READERS.has(name2) && object.type ===
|
|
24026
|
+
return name2 !== null && FS_READERS.has(name2) && object.type === AST_NODE_TYPES110.Identifier && visible("fsObjects", object) && sourcePath(current.arguments[0]);
|
|
23571
24027
|
};
|
|
23572
24028
|
const rawOrigins = (node) => {
|
|
23573
24029
|
const current = unwrap6(node);
|
|
23574
|
-
if (current.type ===
|
|
24030
|
+
if (current.type === AST_NODE_TYPES110.Identifier) return visibleRawOrigins(current);
|
|
23575
24031
|
if (rawRead(current)) return /* @__PURE__ */ new Set([`${current.range[0]}:${current.range[1]}`]);
|
|
23576
|
-
if (current.type ===
|
|
23577
|
-
if (current.type ===
|
|
23578
|
-
if (current.type !==
|
|
24032
|
+
if (current.type === AST_NODE_TYPES110.BinaryExpression && current.operator === "+") return /* @__PURE__ */ new Set([...rawOrigins(current.left), ...rawOrigins(current.right)]);
|
|
24033
|
+
if (current.type === AST_NODE_TYPES110.MemberExpression && ASTUtils68.getPropertyName(current) === "length") return rawOrigins(current.object);
|
|
24034
|
+
if (current.type !== AST_NODE_TYPES110.CallExpression) return /* @__PURE__ */ new Set();
|
|
23579
24035
|
const callee = unwrap6(current.callee);
|
|
23580
|
-
const calleeReceiver = callee.type ===
|
|
23581
|
-
if (callee.type !==
|
|
23582
|
-
const name2 =
|
|
24036
|
+
const calleeReceiver = callee.type === AST_NODE_TYPES110.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
24037
|
+
if (callee.type !== AST_NODE_TYPES110.MemberExpression) return /* @__PURE__ */ new Set();
|
|
24038
|
+
const name2 = ASTUtils68.getPropertyName(callee);
|
|
23583
24039
|
return name2 !== null && TEXT_TRANSFORMS.has(name2) ? rawOrigins(calleeReceiver) : /* @__PURE__ */ new Set();
|
|
23584
24040
|
};
|
|
23585
24041
|
const evidenceOrigins = (node) => {
|
|
23586
24042
|
const current = unwrap6(node);
|
|
23587
24043
|
const direct = rawOrigins(current);
|
|
23588
24044
|
if (direct.size > 0) return direct;
|
|
23589
|
-
if (current.type ===
|
|
23590
|
-
if (current.type ===
|
|
23591
|
-
if (current.type !==
|
|
24045
|
+
if (current.type === AST_NODE_TYPES110.BinaryExpression || current.type === AST_NODE_TYPES110.LogicalExpression) return /* @__PURE__ */ new Set([...evidenceOrigins(current.left), ...evidenceOrigins(current.right)]);
|
|
24046
|
+
if (current.type === AST_NODE_TYPES110.UnaryExpression) return evidenceOrigins(current.argument);
|
|
24047
|
+
if (current.type !== AST_NODE_TYPES110.CallExpression) return /* @__PURE__ */ new Set();
|
|
23592
24048
|
const callee = unwrap6(current.callee);
|
|
23593
|
-
const calleeReceiver = callee.type ===
|
|
23594
|
-
if (callee.type !==
|
|
23595
|
-
const name2 =
|
|
24049
|
+
const calleeReceiver = callee.type === AST_NODE_TYPES110.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
24050
|
+
if (callee.type !== AST_NODE_TYPES110.MemberExpression) return /* @__PURE__ */ new Set();
|
|
24051
|
+
const name2 = ASTUtils68.getPropertyName(callee);
|
|
23596
24052
|
if (name2 !== null && TEXT_PREDICATES.has(name2)) return rawOrigins(calleeReceiver);
|
|
23597
|
-
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type ===
|
|
24053
|
+
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES110.SpreadElement ? [] : [...rawOrigins(argument)]));
|
|
23598
24054
|
return /* @__PURE__ */ new Set();
|
|
23599
24055
|
};
|
|
23600
24056
|
const rawAssertionOrigins = (node) => {
|
|
23601
24057
|
const callee = unwrap6(node.callee);
|
|
23602
|
-
const calleeReceiver = callee.type ===
|
|
23603
|
-
if (callee.type ===
|
|
23604
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
24058
|
+
const calleeReceiver = callee.type === AST_NODE_TYPES110.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
24059
|
+
if (callee.type === AST_NODE_TYPES110.Identifier && assertionKind(callee) === "assert") {
|
|
24060
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES110.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
23605
24061
|
}
|
|
23606
|
-
if (callee.type !==
|
|
23607
|
-
const matcher =
|
|
24062
|
+
if (callee.type !== AST_NODE_TYPES110.MemberExpression) return /* @__PURE__ */ new Set();
|
|
24063
|
+
const matcher = ASTUtils68.getPropertyName(callee);
|
|
23608
24064
|
if (matcher === null) return /* @__PURE__ */ new Set();
|
|
23609
24065
|
let receiver = unwrap6(calleeReceiver);
|
|
23610
|
-
while (receiver.type ===
|
|
23611
|
-
const expectCallee = receiver.type ===
|
|
23612
|
-
if (receiver.type ===
|
|
24066
|
+
while (receiver.type === AST_NODE_TYPES110.MemberExpression && EXPECT_MODIFIERS2.has(ASTUtils68.getPropertyName(receiver) ?? "")) receiver = unwrap6(receiver.object);
|
|
24067
|
+
const expectCallee = receiver.type === AST_NODE_TYPES110.CallExpression ? unwrapExpression(receiver.callee) : null;
|
|
24068
|
+
if (receiver.type === AST_NODE_TYPES110.CallExpression && expectCallee?.type === AST_NODE_TYPES110.Identifier && assertionKind(expectCallee) === "expect") {
|
|
23613
24069
|
if (!EXPECT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
23614
|
-
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type ===
|
|
24070
|
+
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type === AST_NODE_TYPES110.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
23615
24071
|
}
|
|
23616
|
-
if (receiver.type !==
|
|
23617
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
24072
|
+
if (receiver.type !== AST_NODE_TYPES110.Identifier || assertionKind(receiver) !== "assert" || !ASSERT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
24073
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES110.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
23618
24074
|
};
|
|
23619
24075
|
const declare = (node, state) => {
|
|
23620
24076
|
const name2 = bindingOf(node);
|
|
@@ -23636,7 +24092,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
23636
24092
|
};
|
|
23637
24093
|
const sourceCollection = (node) => {
|
|
23638
24094
|
const current = unwrap6(node);
|
|
23639
|
-
return current.type ===
|
|
24095
|
+
return current.type === AST_NODE_TYPES110.ArrayExpression && current.elements.length > 0 && current.elements.every((element) => element !== null && element.type !== AST_NODE_TYPES110.SpreadElement && sourcePath(element));
|
|
23640
24096
|
};
|
|
23641
24097
|
const enterFunction = () => {
|
|
23642
24098
|
scopes.push(newScope());
|
|
@@ -23646,8 +24102,8 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
23646
24102
|
};
|
|
23647
24103
|
function declareFsReaders(pattern) {
|
|
23648
24104
|
for (const property of pattern.properties) {
|
|
23649
|
-
if (property.type !==
|
|
23650
|
-
const key = property.key.type ===
|
|
24105
|
+
if (property.type !== AST_NODE_TYPES110.Property || property.value.type !== AST_NODE_TYPES110.Identifier) continue;
|
|
24106
|
+
const key = property.key.type === AST_NODE_TYPES110.Identifier ? property.key.name : property.key.type === AST_NODE_TYPES110.Literal ? String(property.key.value) : "";
|
|
23651
24107
|
if (FS_READERS.has(key)) declare(property.value, { fsReader: true });
|
|
23652
24108
|
}
|
|
23653
24109
|
}
|
|
@@ -23656,8 +24112,8 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
23656
24112
|
const source = importSource(node);
|
|
23657
24113
|
if (source === null || !FS_MODULES.has(source)) return;
|
|
23658
24114
|
for (const specifier of node.specifiers) {
|
|
23659
|
-
if (specifier.type ===
|
|
23660
|
-
const imported = specifier.imported.type ===
|
|
24115
|
+
if (specifier.type === AST_NODE_TYPES110.ImportSpecifier) {
|
|
24116
|
+
const imported = specifier.imported.type === AST_NODE_TYPES110.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
23661
24117
|
if (FS_READERS.has(imported)) declare(specifier.local, { fsReader: true });
|
|
23662
24118
|
} else {
|
|
23663
24119
|
declare(specifier.local, { fsObject: true });
|
|
@@ -23670,26 +24126,26 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
23670
24126
|
if (node.init === null) return;
|
|
23671
24127
|
const required = requireSource(node.init);
|
|
23672
24128
|
const initializer = unwrap6(node.init);
|
|
23673
|
-
if (required !== null && initializer.type ===
|
|
23674
|
-
if (required !== null && FS_MODULES.has(required) && node.id.type ===
|
|
24129
|
+
if (required !== null && initializer.type === AST_NODE_TYPES110.CallExpression && initializer.callee.type === AST_NODE_TYPES110.Identifier && (bindingOf(initializer.callee)?.defs.length ?? 0) > 0) return;
|
|
24130
|
+
if (required !== null && FS_MODULES.has(required) && node.id.type === AST_NODE_TYPES110.Identifier) {
|
|
23675
24131
|
declare(node.id, { fsObject: true });
|
|
23676
24132
|
return;
|
|
23677
24133
|
}
|
|
23678
|
-
if (node.id.type ===
|
|
24134
|
+
if (node.id.type === AST_NODE_TYPES110.ObjectPattern && required !== null && FS_MODULES.has(required)) {
|
|
23679
24135
|
declareFsReaders(node.id);
|
|
23680
24136
|
return;
|
|
23681
24137
|
}
|
|
23682
|
-
if (node.id.type !==
|
|
24138
|
+
if (node.id.type !== AST_NODE_TYPES110.Identifier) return;
|
|
23683
24139
|
declare(node.id, { collection: sourceCollection(node.init), path: sourcePath(node.init), rawOrigins: rawOrigins(node.init) });
|
|
23684
24140
|
},
|
|
23685
24141
|
AssignmentExpression(node) {
|
|
23686
|
-
if (node.left.type ===
|
|
24142
|
+
if (node.left.type === AST_NODE_TYPES110.Identifier) declare(node.left, {});
|
|
23687
24143
|
},
|
|
23688
24144
|
ForOfStatement(node) {
|
|
23689
24145
|
const right = unwrap6(node.right);
|
|
23690
|
-
const collection = right.type ===
|
|
23691
|
-
const left = node.left.type ===
|
|
23692
|
-
if (collection && left?.type ===
|
|
24146
|
+
const collection = right.type === AST_NODE_TYPES110.Identifier && visible("collections", right);
|
|
24147
|
+
const left = node.left.type === AST_NODE_TYPES110.VariableDeclaration ? node.left.declarations[0]?.id : node.left;
|
|
24148
|
+
if (collection && left?.type === AST_NODE_TYPES110.Identifier) declare(left, { path: true });
|
|
23693
24149
|
},
|
|
23694
24150
|
CallExpression(node) {
|
|
23695
24151
|
const origins = rawAssertionOrigins(node);
|
|
@@ -23707,22 +24163,22 @@ var source_coupled_test_default = createSourceCoupledRule(
|
|
|
23707
24163
|
GENERAL_SOURCE_SUFFIX_RE
|
|
23708
24164
|
);
|
|
23709
24165
|
function importedAssertionKind(specifier) {
|
|
23710
|
-
if (specifier.type !==
|
|
24166
|
+
if (specifier.type !== AST_NODE_TYPES110.ImportSpecifier && specifier.type !== AST_NODE_TYPES110.ImportDefaultSpecifier && specifier.type !== AST_NODE_TYPES110.ImportNamespaceSpecifier || specifier.parent.type !== AST_NODE_TYPES110.ImportDeclaration) return null;
|
|
23711
24167
|
const source = importSource(specifier.parent);
|
|
23712
24168
|
if (source !== null && ASSERT_MODULES.has(source)) {
|
|
23713
|
-
if (specifier.type !==
|
|
23714
|
-
const imported2 = specifier.imported.type ===
|
|
24169
|
+
if (specifier.type !== AST_NODE_TYPES110.ImportSpecifier) return "assert";
|
|
24170
|
+
const imported2 = specifier.imported.type === AST_NODE_TYPES110.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
23715
24171
|
if (imported2 === "strict" || ASSERT_MATCHERS.has(imported2)) return "assert";
|
|
23716
24172
|
return null;
|
|
23717
24173
|
}
|
|
23718
|
-
if (source === null || !EXPECT_MODULES.has(source) || specifier.type !==
|
|
23719
|
-
const imported = specifier.imported.type ===
|
|
24174
|
+
if (source === null || !EXPECT_MODULES.has(source) || specifier.type !== AST_NODE_TYPES110.ImportSpecifier) return null;
|
|
24175
|
+
const imported = specifier.imported.type === AST_NODE_TYPES110.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
23720
24176
|
if (imported === "assert" || imported === "expect") return imported;
|
|
23721
24177
|
return null;
|
|
23722
24178
|
}
|
|
23723
24179
|
|
|
23724
24180
|
// src/rules/sole-export-matches-filename.ts
|
|
23725
|
-
import { AST_NODE_TYPES as
|
|
24181
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES111 } from "@typescript-eslint/utils";
|
|
23726
24182
|
|
|
23727
24183
|
// src/rules/_is-framework-entrypoint.ts
|
|
23728
24184
|
import { readFileSync as readFileSync3 } from "fs";
|
|
@@ -23838,7 +24294,7 @@ var sole_export_matches_filename_default = createRule({
|
|
|
23838
24294
|
if (only === void 0) return;
|
|
23839
24295
|
if (isFrameworkEntrypoint(normalizedFilename, only.key)) return;
|
|
23840
24296
|
if (only.name === "onRouterTransitionStart" && /(?:^|\/)instrumentation-client\.[jt]s$/u.test(normalizedFilename)) return;
|
|
23841
|
-
if (only.name === "collections" && /(?:^|\/)src\/content\.config\.(?:ts|js|mjs)$/u.test(normalizedFilename) && program.body.some((statement) => statement.type ===
|
|
24297
|
+
if (only.name === "collections" && /(?:^|\/)src\/content\.config\.(?:ts|js|mjs)$/u.test(normalizedFilename) && program.body.some((statement) => statement.type === AST_NODE_TYPES111.ImportDeclaration && statement.source.value === "astro:content")) return;
|
|
23842
24298
|
const exportedStem = kebabCase(only.name);
|
|
23843
24299
|
if (exportedStem === "") return;
|
|
23844
24300
|
const expected = `${fileStem.startsWith("_") ? "_" : ""}${exportedStem}`;
|
|
@@ -23889,8 +24345,8 @@ var iac_source_coupled_test_default = createSourceCoupledRule(
|
|
|
23889
24345
|
|
|
23890
24346
|
// src/rules/require-pascal-case-zod-schema-name.ts
|
|
23891
24347
|
import {
|
|
23892
|
-
AST_NODE_TYPES as
|
|
23893
|
-
ASTUtils as
|
|
24348
|
+
AST_NODE_TYPES as AST_NODE_TYPES112,
|
|
24349
|
+
ASTUtils as ASTUtils69
|
|
23894
24350
|
} from "@typescript-eslint/utils";
|
|
23895
24351
|
var REQUIRE_PASCAL_CASE_ZOD_SCHEMA_NAME_DOCUMENTATION = {
|
|
23896
24352
|
summary: "Require confirmed module-level Zod schema contracts to use PascalCase with a `Schema` suffix.",
|
|
@@ -24023,19 +24479,19 @@ var SCHEMA_RETURNING_METHODS = /* @__PURE__ */ new Set([
|
|
|
24023
24479
|
"superRefine",
|
|
24024
24480
|
"transform"
|
|
24025
24481
|
]);
|
|
24026
|
-
var terminalMethodName = (callee) =>
|
|
24482
|
+
var terminalMethodName = (callee) => ASTUtils69.getPropertyName(callee) !== null ? ASTUtils69.getPropertyName(callee) ?? "" : null;
|
|
24027
24483
|
var calleeChainRoot2 = (node) => {
|
|
24028
24484
|
let current = node;
|
|
24029
24485
|
for (; ; ) {
|
|
24030
24486
|
current = unwrapExpression(current);
|
|
24031
|
-
if (current.type ===
|
|
24487
|
+
if (current.type === AST_NODE_TYPES112.Identifier) {
|
|
24032
24488
|
return current;
|
|
24033
24489
|
}
|
|
24034
|
-
if (current.type ===
|
|
24490
|
+
if (current.type === AST_NODE_TYPES112.MemberExpression) {
|
|
24035
24491
|
current = current.object;
|
|
24036
24492
|
continue;
|
|
24037
24493
|
}
|
|
24038
|
-
if (current.type ===
|
|
24494
|
+
if (current.type === AST_NODE_TYPES112.CallExpression) {
|
|
24039
24495
|
current = unwrapExpression(current.callee);
|
|
24040
24496
|
continue;
|
|
24041
24497
|
}
|
|
@@ -24047,13 +24503,13 @@ var chainMemberNames2 = (node) => {
|
|
|
24047
24503
|
let current = node;
|
|
24048
24504
|
for (; ; ) {
|
|
24049
24505
|
current = unwrapExpression(current);
|
|
24050
|
-
if (current.type ===
|
|
24051
|
-
if (
|
|
24052
|
-
names.push(
|
|
24506
|
+
if (current.type === AST_NODE_TYPES112.MemberExpression) {
|
|
24507
|
+
if (ASTUtils69.getPropertyName(current) === null) return [];
|
|
24508
|
+
names.push(ASTUtils69.getPropertyName(current) ?? "");
|
|
24053
24509
|
current = current.object;
|
|
24054
24510
|
continue;
|
|
24055
24511
|
}
|
|
24056
|
-
if (current.type ===
|
|
24512
|
+
if (current.type === AST_NODE_TYPES112.CallExpression) {
|
|
24057
24513
|
current = unwrapExpression(current.callee);
|
|
24058
24514
|
continue;
|
|
24059
24515
|
}
|
|
@@ -24064,9 +24520,9 @@ var chainMemberNames2 = (node) => {
|
|
|
24064
24520
|
};
|
|
24065
24521
|
var isModuleDeclarator = (node) => {
|
|
24066
24522
|
const declaration = node.parent;
|
|
24067
|
-
if (declaration.type !==
|
|
24523
|
+
if (declaration.type !== AST_NODE_TYPES112.VariableDeclaration) return false;
|
|
24068
24524
|
const owner = declaration.parent;
|
|
24069
|
-
return owner.type ===
|
|
24525
|
+
return owner.type === AST_NODE_TYPES112.Program || owner.type === AST_NODE_TYPES112.ExportNamedDeclaration && owner.parent.type === AST_NODE_TYPES112.Program;
|
|
24070
24526
|
};
|
|
24071
24527
|
var require_pascal_case_zod_schema_name_default = createRule({
|
|
24072
24528
|
name: "require-pascal-case-zod-schema-name",
|
|
@@ -24086,7 +24542,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
24086
24542
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
24087
24543
|
const schemaBindings = /* @__PURE__ */ new Set();
|
|
24088
24544
|
function resolvedBinding(identifier) {
|
|
24089
|
-
return
|
|
24545
|
+
return ASTUtils69.findVariable(
|
|
24090
24546
|
context.sourceCode.getScope(identifier),
|
|
24091
24547
|
identifier.name
|
|
24092
24548
|
);
|
|
@@ -24097,10 +24553,10 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
24097
24553
|
}
|
|
24098
24554
|
function isConfirmedSchema(expression) {
|
|
24099
24555
|
const init = unwrapExpression(expression);
|
|
24100
|
-
if (init.type ===
|
|
24101
|
-
if (init.type !==
|
|
24556
|
+
if (init.type === AST_NODE_TYPES112.Identifier) return isSchemaBinding(init);
|
|
24557
|
+
if (init.type !== AST_NODE_TYPES112.CallExpression) return false;
|
|
24102
24558
|
const callee = unwrapExpression(init.callee);
|
|
24103
|
-
if (callee.type !==
|
|
24559
|
+
if (callee.type !== AST_NODE_TYPES112.MemberExpression) {
|
|
24104
24560
|
return false;
|
|
24105
24561
|
}
|
|
24106
24562
|
const terminal = terminalMethodName(callee);
|
|
@@ -24130,7 +24586,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
24130
24586
|
ImportDeclaration(node) {
|
|
24131
24587
|
if (!isZodModule(node.source.value)) return;
|
|
24132
24588
|
for (const specifier of node.specifiers) {
|
|
24133
|
-
if (specifier.type ===
|
|
24589
|
+
if (specifier.type === AST_NODE_TYPES112.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES112.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES112.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES112.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
24134
24590
|
recordZodBinding(specifier.local);
|
|
24135
24591
|
}
|
|
24136
24592
|
}
|
|
@@ -24139,7 +24595,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
24139
24595
|
if (!isModuleDeclarator(node)) return;
|
|
24140
24596
|
const init = node.init;
|
|
24141
24597
|
if (init === null || init === void 0) return;
|
|
24142
|
-
if (node.id.type !==
|
|
24598
|
+
if (node.id.type !== AST_NODE_TYPES112.Identifier) return;
|
|
24143
24599
|
if (!isConfirmedSchema(init)) return;
|
|
24144
24600
|
const binding = resolvedBinding(node.id);
|
|
24145
24601
|
if (binding !== null) schemaBindings.add(binding);
|
|
@@ -24341,6 +24797,7 @@ var RULES = {
|
|
|
24341
24797
|
"prefer-whole-object-assertion": prefer_whole_object_assertion_default,
|
|
24342
24798
|
"repeated-static-call-cases": repeated_static_call_cases_default,
|
|
24343
24799
|
"prefer-zod-infer": prefer_zod_infer_default,
|
|
24800
|
+
"named-child-schema-type": named_child_schema_type_default,
|
|
24344
24801
|
"prefer-zod-parse-output-type": prefer_zod_parse_output_type_default,
|
|
24345
24802
|
"require-assert-never": require_assert_never_default,
|
|
24346
24803
|
"require-fetch-timeout": require_fetch_timeout_default,
|
|
@@ -24357,7 +24814,7 @@ var RULES = {
|
|
|
24357
24814
|
};
|
|
24358
24815
|
var meta = {
|
|
24359
24816
|
name: "@sarj/eslint-plugin",
|
|
24360
|
-
version:
|
|
24817
|
+
version: package_default.version
|
|
24361
24818
|
};
|
|
24362
24819
|
var APPLICATION_ONLY_RULES = [];
|
|
24363
24820
|
var LIBRARY_IMPORT_POLICY = ["error", {
|
|
@@ -24366,6 +24823,7 @@ var LIBRARY_IMPORT_POLICY = ["error", {
|
|
|
24366
24823
|
}];
|
|
24367
24824
|
var ADVISORY_RULES = [
|
|
24368
24825
|
"@sarj/excessive-commentary",
|
|
24826
|
+
"@sarj/named-child-schema-type",
|
|
24369
24827
|
"@sarj/no-bespoke-api-case-conversion",
|
|
24370
24828
|
"@sarj/no-duplicate-test-case",
|
|
24371
24829
|
"@sarj/no-json-stringify-object-equality",
|
|
@@ -24388,6 +24846,7 @@ var ADVISORY_RULES = [
|
|
|
24388
24846
|
"@sarj/require-sql-access-class"
|
|
24389
24847
|
];
|
|
24390
24848
|
var RECOMMENDED_RULES = {
|
|
24849
|
+
"@sarj/named-child-schema-type": "warn",
|
|
24391
24850
|
"@sarj/no-conditional-empty-object-spread": "error",
|
|
24392
24851
|
"@sarj/prefer-typed-reflection": "error",
|
|
24393
24852
|
"@sarj/no-broad-return-type": "error",
|
|
@@ -24505,6 +24964,7 @@ var RECOMMENDED_RULES = {
|
|
|
24505
24964
|
"@sarj/require-pascal-case-zod-schema-name": "error"
|
|
24506
24965
|
};
|
|
24507
24966
|
var STRICT_RULES = {
|
|
24967
|
+
"@sarj/named-child-schema-type": "warn",
|
|
24508
24968
|
"@sarj/no-conditional-empty-object-spread": "error",
|
|
24509
24969
|
"@sarj/prefer-typed-reflection": "error",
|
|
24510
24970
|
"@sarj/no-broad-return-type": "error",
|