@sarj/eslint-plugin 16.11.0 → 16.13.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 +2178 -1914
- package/dist/index.d.cts +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +904 -643
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// package.json
|
|
2
2
|
var package_default = {
|
|
3
3
|
name: "@sarj/eslint-plugin",
|
|
4
|
-
version: "16.
|
|
4
|
+
version: "16.13.0",
|
|
5
5
|
packageManager: "npm@12.2.0",
|
|
6
6
|
description: "Custom ESLint rules for hypermodern TypeScript / React / Next.js projects",
|
|
7
7
|
type: "module",
|
|
@@ -4754,274 +4754,308 @@ var no_comment_cruft_default = createRule({
|
|
|
4754
4754
|
});
|
|
4755
4755
|
|
|
4756
4756
|
// src/rules/no-cors-wildcard-with-credentials.ts
|
|
4757
|
-
import {
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4757
|
+
import { ASTUtils as ASTUtils7 } from "@typescript-eslint/utils";
|
|
4758
|
+
var ACAO_HEADER = "access-control-allow-origin";
|
|
4759
|
+
var ACAC_HEADER = "access-control-allow-credentials";
|
|
4760
|
+
var HEADER_METHODS = /* @__PURE__ */ new Set(["set", "setHeader", "append", "delete", "removeHeader"]);
|
|
4761
|
+
var CONTROL_STATEMENTS = /* @__PURE__ */ new Set([
|
|
4762
|
+
"BlockStatement",
|
|
4763
|
+
"IfStatement",
|
|
4764
|
+
"SwitchStatement",
|
|
4765
|
+
"TryStatement",
|
|
4766
|
+
"ForStatement",
|
|
4767
|
+
"ForInStatement",
|
|
4768
|
+
"ForOfStatement",
|
|
4769
|
+
"WhileStatement",
|
|
4770
|
+
"DoWhileStatement",
|
|
4771
|
+
"WithStatement",
|
|
4772
|
+
"LabeledStatement"
|
|
4773
|
+
]);
|
|
4761
4774
|
var NO_CORS_WILDCARD_WITH_CREDENTIALS_DOCUMENTATION = {
|
|
4762
|
-
summary: "
|
|
4763
|
-
rationale: "
|
|
4764
|
-
remediation: "
|
|
4765
|
-
category: "
|
|
4775
|
+
summary: "Review wildcard CORS origins combined with an explicit credentials opt-in.",
|
|
4776
|
+
rationale: "Browsers do not expose credentialed cross-origin responses when Access-Control-Allow-Origin is '*'. Credentialless requests can still use a wildcard even when Access-Control-Allow-Credentials is emitted, so review the intended caller contract.",
|
|
4777
|
+
remediation: "Use a trusted explicit origin for credentialed callers, or omit the credentials opt-in for a credentialless wildcard endpoint.",
|
|
4778
|
+
category: "correctness",
|
|
4779
|
+
defaultLevel: "warning",
|
|
4780
|
+
autofix: "none",
|
|
4781
|
+
references: ["https://fetch.spec.whatwg.org/#cors-protocol-and-credentials"],
|
|
4766
4782
|
limitations: [
|
|
4767
|
-
"
|
|
4783
|
+
"Options require a stable official cors default import or hono/cors named or namespace import, one literal object argument, literal origin '*', and credentials true. Custom bindings, callbacks, arrays, conditional origins and dynamic options are excluded.",
|
|
4784
|
+
"Literal header maps use effective case-sensitive JavaScript property writes followed by native Headers combination of differently-cased header names. Unknown values/spreads/computed keys, accessors and non-null prototypes lose proof; literals used only inside object spreads are not reported independently.",
|
|
4785
|
+
"Manual set/setHeader/delete/removeHeader calls use direct identifier receivers and literal arguments in straight-line program or function bodies. Control-flow bodies, member receivers, aliases and unknown operations are excluded. Append requires a proven empty native Headers constructor or a preceding known write/removal.",
|
|
4786
|
+
"The rule reviews a local configuration contract, not actual request credentials or a data disclosure. Runtime patches, custom header method implementations, interprocedural mutation and later consumers are not resolved. No autofix."
|
|
4768
4787
|
],
|
|
4769
4788
|
examples: [
|
|
4770
4789
|
{
|
|
4771
4790
|
id: "trusted-origin-with-credentials",
|
|
4772
|
-
title: "
|
|
4791
|
+
title: "Use a trusted origin for credentialed callers",
|
|
4773
4792
|
outcome: "no-match",
|
|
4774
|
-
files: [{ path: "src/server.ts", source: "
|
|
4793
|
+
files: [{ path: "src/server.ts", source: "import cors from 'cors'; cors({ origin: 'https://app.example.com', credentials: true });" }],
|
|
4775
4794
|
focusPath: "src/server.ts",
|
|
4776
4795
|
expectedCount: 0,
|
|
4777
4796
|
public: true
|
|
4778
4797
|
},
|
|
4779
4798
|
{
|
|
4780
4799
|
id: "wildcard-origin-with-credentials",
|
|
4781
|
-
title: "
|
|
4800
|
+
title: "Review a wildcard that blocks access to credentialed responses",
|
|
4782
4801
|
outcome: "match",
|
|
4783
|
-
files: [{ path: "src/server.ts", source: "
|
|
4802
|
+
files: [{ path: "src/server.ts", source: "import cors from 'cors'; cors({ origin: '*', credentials: true });" }],
|
|
4784
4803
|
focusPath: "src/server.ts",
|
|
4785
4804
|
expectedCount: 1,
|
|
4786
4805
|
public: true
|
|
4787
4806
|
}
|
|
4788
4807
|
]
|
|
4789
4808
|
};
|
|
4790
|
-
var ACAO_HEADER = "access-control-allow-origin";
|
|
4791
|
-
var ACAC_HEADER = "access-control-allow-credentials";
|
|
4792
|
-
var HEADER_SET_METHODS = /* @__PURE__ */ new Set(["setheader", "set", "append"]);
|
|
4793
|
-
function isCredentialsTrueValue(node) {
|
|
4794
|
-
node = unwrapExpression(node);
|
|
4795
|
-
if (node.type === "Literal") {
|
|
4796
|
-
if (node.value === true) {
|
|
4797
|
-
return true;
|
|
4798
|
-
}
|
|
4799
|
-
if (typeof node.value === "string") {
|
|
4800
|
-
return node.value.trim().toLowerCase() === "true";
|
|
4801
|
-
}
|
|
4802
|
-
}
|
|
4803
|
-
return false;
|
|
4804
|
-
}
|
|
4805
|
-
function isStarLiteral(node) {
|
|
4806
|
-
return node.type === "Literal" && node.value === "*";
|
|
4807
|
-
}
|
|
4808
|
-
function propertyKeyName(prop) {
|
|
4809
|
-
return ASTUtils7.getPropertyName(prop) ?? void 0;
|
|
4810
|
-
}
|
|
4811
|
-
function isCorsWildcardCredentialsCall(node) {
|
|
4812
|
-
const name = calleeName(node);
|
|
4813
|
-
if (name === void 0 || name.toLowerCase() !== "cors") {
|
|
4814
|
-
return false;
|
|
4815
|
-
}
|
|
4816
|
-
const options = node.arguments.map(unwrapExpression).find(
|
|
4817
|
-
(arg) => arg.type === "ObjectExpression"
|
|
4818
|
-
);
|
|
4819
|
-
if (options === void 0) {
|
|
4820
|
-
return false;
|
|
4821
|
-
}
|
|
4822
|
-
let hasCredentials = false;
|
|
4823
|
-
let hasWildcardOrigin = false;
|
|
4824
|
-
for (const prop of options.properties) {
|
|
4825
|
-
if (prop.type !== "Property") {
|
|
4826
|
-
continue;
|
|
4827
|
-
}
|
|
4828
|
-
const key = propertyKeyName(prop);
|
|
4829
|
-
if (key === "credentials" && isTrueLiteral(prop.value)) {
|
|
4830
|
-
hasCredentials = true;
|
|
4831
|
-
} else if (key === "origin" && subtreeContainsStarLiteral(prop.value)) {
|
|
4832
|
-
hasWildcardOrigin = true;
|
|
4833
|
-
}
|
|
4834
|
-
}
|
|
4835
|
-
return hasCredentials && hasWildcardOrigin;
|
|
4836
|
-
}
|
|
4837
|
-
function isTrueLiteral(node) {
|
|
4838
|
-
node = unwrapExpression(node);
|
|
4839
|
-
return node.type === "Literal" && node.value === true;
|
|
4840
|
-
}
|
|
4841
|
-
function subtreeContainsStarLiteral(node) {
|
|
4842
|
-
if (isStarLiteral(node)) {
|
|
4843
|
-
return true;
|
|
4844
|
-
}
|
|
4845
|
-
return forEachOwnAstChild(
|
|
4846
|
-
node,
|
|
4847
|
-
subtreeContainsStarLiteral,
|
|
4848
|
-
(key) => key !== "loc" && key !== "range"
|
|
4849
|
-
);
|
|
4850
|
-
}
|
|
4851
|
-
function calleeName(node) {
|
|
4852
|
-
const callee = unwrapExpression(node.callee);
|
|
4853
|
-
if (callee.type === "Identifier") {
|
|
4854
|
-
return callee.name;
|
|
4855
|
-
}
|
|
4856
|
-
if (callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier") {
|
|
4857
|
-
return callee.property.name;
|
|
4858
|
-
}
|
|
4859
|
-
return void 0;
|
|
4860
|
-
}
|
|
4861
|
-
function isWildcardCredentialsHeaderObject(node) {
|
|
4862
|
-
let wildcardOrigin = false;
|
|
4863
|
-
let credentialsTrue = false;
|
|
4864
|
-
for (const prop of node.properties) {
|
|
4865
|
-
if (prop.type !== "Property") {
|
|
4866
|
-
continue;
|
|
4867
|
-
}
|
|
4868
|
-
const key = propertyKeyName(prop);
|
|
4869
|
-
if (key === void 0) {
|
|
4870
|
-
continue;
|
|
4871
|
-
}
|
|
4872
|
-
const header = key.toLowerCase();
|
|
4873
|
-
if (header === ACAO_HEADER && isStarLiteral(prop.value)) {
|
|
4874
|
-
wildcardOrigin = true;
|
|
4875
|
-
} else if (header === ACAC_HEADER && isCredentialsTrueValue(prop.value)) {
|
|
4876
|
-
credentialsTrue = true;
|
|
4877
|
-
}
|
|
4878
|
-
}
|
|
4879
|
-
return wildcardOrigin && credentialsTrue;
|
|
4880
|
-
}
|
|
4881
|
-
function classifyHeaderSetCall(node) {
|
|
4882
|
-
const callee = unwrapExpression(node.callee);
|
|
4883
|
-
if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier" || !HEADER_SET_METHODS.has(callee.property.name.toLowerCase())) {
|
|
4884
|
-
return void 0;
|
|
4885
|
-
}
|
|
4886
|
-
const [nameArg, valueArg] = node.arguments;
|
|
4887
|
-
if (nameArg === void 0 || valueArg === void 0 || nameArg.type !== "Literal" || typeof nameArg.value !== "string") {
|
|
4888
|
-
return void 0;
|
|
4889
|
-
}
|
|
4890
|
-
const header = nameArg.value.toLowerCase();
|
|
4891
|
-
if (header === ACAO_HEADER && isStarLiteral(valueArg)) {
|
|
4892
|
-
return "origin";
|
|
4893
|
-
}
|
|
4894
|
-
if (header === ACAC_HEADER && isCredentialsTrueValue(valueArg)) {
|
|
4895
|
-
return "credentials";
|
|
4896
|
-
}
|
|
4897
|
-
return void 0;
|
|
4898
|
-
}
|
|
4899
|
-
function enclosingScope(node) {
|
|
4900
|
-
let current = node.parent;
|
|
4901
|
-
while (current) {
|
|
4902
|
-
if (current.type === "FunctionDeclaration" || current.type === "FunctionExpression" || current.type === "ArrowFunctionExpression") {
|
|
4903
|
-
return current;
|
|
4904
|
-
}
|
|
4905
|
-
current = current.parent;
|
|
4906
|
-
}
|
|
4907
|
-
return void 0;
|
|
4908
|
-
}
|
|
4909
4809
|
var no_cors_wildcard_with_credentials_default = createRule({
|
|
4910
4810
|
name: "no-cors-wildcard-with-credentials",
|
|
4911
4811
|
documentation: NO_CORS_WILDCARD_WITH_CREDENTIALS_DOCUMENTATION,
|
|
4912
4812
|
meta: {
|
|
4913
4813
|
type: "problem",
|
|
4914
|
-
docs: {
|
|
4915
|
-
description: "Disallow wildcard CORS origins when credentials are enabled."
|
|
4916
|
-
},
|
|
4814
|
+
docs: { description: NO_CORS_WILDCARD_WITH_CREDENTIALS_DOCUMENTATION.summary },
|
|
4917
4815
|
schema: [],
|
|
4918
4816
|
messages: {
|
|
4919
|
-
corsWildcardWithCredentials:
|
|
4817
|
+
corsWildcardWithCredentials: "A wildcard CORS origin blocks browser access to credentialed responses. Review the intended contract: use a trusted explicit origin for credentialed callers, or omit the credentials opt-in for a credentialless endpoint."
|
|
4920
4818
|
}
|
|
4921
4819
|
},
|
|
4922
4820
|
defaultOptions: [],
|
|
4923
4821
|
create(context) {
|
|
4924
|
-
const
|
|
4925
|
-
const
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
const
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
scopeHeaderSets.set(key, receivers);
|
|
4937
|
-
}
|
|
4938
|
-
let entry = receivers.get(receiver);
|
|
4939
|
-
if (entry === void 0) {
|
|
4940
|
-
entry = { originNodes: [], credentialsNodes: [] };
|
|
4941
|
-
receivers.set(receiver, entry);
|
|
4942
|
-
}
|
|
4943
|
-
if (kind === "origin") {
|
|
4944
|
-
entry.originNodes.push(node);
|
|
4945
|
-
} else {
|
|
4946
|
-
entry.credentialsNodes.push(node);
|
|
4822
|
+
const sourceCode = context.sourceCode;
|
|
4823
|
+
const importedCors = /* @__PURE__ */ new Set();
|
|
4824
|
+
const importedNamespaces = /* @__PURE__ */ new Set();
|
|
4825
|
+
const receiverProof = /* @__PURE__ */ new Map();
|
|
4826
|
+
function binding(node) {
|
|
4827
|
+
return ASTUtils7.findVariable(sourceCode.getScope(node), node.name);
|
|
4828
|
+
}
|
|
4829
|
+
function officialCors(node) {
|
|
4830
|
+
const value = unwrapExpression(node);
|
|
4831
|
+
if (value.type === "Identifier") {
|
|
4832
|
+
const variable2 = binding(value);
|
|
4833
|
+
return variable2 !== null && importedCors.has(variable2);
|
|
4947
4834
|
}
|
|
4835
|
+
if (value.type !== "MemberExpression" || value.optional || value.computed || value.property.type !== "Identifier" || value.property.name !== "cors" || value.object.type !== "Identifier") return false;
|
|
4836
|
+
const variable = binding(value.object);
|
|
4837
|
+
return variable !== null && importedNamespaces.has(variable);
|
|
4948
4838
|
}
|
|
4949
|
-
function
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
context.sourceCode.getScope(node),
|
|
4953
|
-
node.name
|
|
4954
|
-
);
|
|
4955
|
-
return variable === null ? `global:${node.name}` : `variable:${variableId(variable)}`;
|
|
4839
|
+
function recordImports(node) {
|
|
4840
|
+
for (const statement of node.body) {
|
|
4841
|
+
if (statement.type === "ImportDeclaration" && statement.importKind !== "type") recordImport(statement);
|
|
4956
4842
|
}
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
|
|
4843
|
+
}
|
|
4844
|
+
function recordImport(node) {
|
|
4845
|
+
for (const specifier of node.specifiers) {
|
|
4846
|
+
const role = importRole(specifier, node.source.value);
|
|
4847
|
+
if (role === null) continue;
|
|
4848
|
+
const variable = binding(specifier.local);
|
|
4849
|
+
if (variable === null || variable.references.some((reference) => reference.isWrite())) continue;
|
|
4850
|
+
(role === "namespace" ? importedNamespaces : importedCors).add(variable);
|
|
4851
|
+
}
|
|
4852
|
+
}
|
|
4853
|
+
function inspectSequence(node) {
|
|
4854
|
+
if (node.body.some((statement) => CONTROL_STATEMENTS.has(statement.type))) return;
|
|
4855
|
+
const states = /* @__PURE__ */ new Map();
|
|
4856
|
+
for (const statement of node.body) {
|
|
4857
|
+
if (statement.type === "ImportDeclaration" || statement.type === "FunctionDeclaration") continue;
|
|
4858
|
+
if (statement.type === "VariableDeclaration") {
|
|
4859
|
+
recordHeaderDeclaration(statement, states);
|
|
4860
|
+
continue;
|
|
4861
|
+
}
|
|
4862
|
+
const expression = statement.type === "ExpressionStatement" ? unwrapExpression(statement.expression) : null;
|
|
4863
|
+
if (expression?.type !== "CallExpression" || !applyHeaderWrite(expression, states)) states.clear();
|
|
4864
|
+
}
|
|
4865
|
+
for (const state of states.values()) {
|
|
4866
|
+
if (state.values[ACAO_HEADER] === "*" && state.values[ACAC_HEADER] === "true" && state.origin !== null) {
|
|
4867
|
+
context.report({ node: state.origin, messageId: "corsWildcardWithCredentials" });
|
|
4868
|
+
}
|
|
4869
|
+
}
|
|
4870
|
+
}
|
|
4871
|
+
function recordHeaderDeclaration(node, states) {
|
|
4872
|
+
for (const declaration of node.declarations) {
|
|
4873
|
+
if (declaration.id.type === "Identifier" && declaration.init !== null && freshHeaders(declaration.init)) {
|
|
4874
|
+
const key = receiverKey(declaration.id);
|
|
4875
|
+
if (key !== null) states.set(key, { values: { [ACAO_HEADER]: null, [ACAC_HEADER]: null }, origin: null });
|
|
4876
|
+
} else if (declaration.id.type !== "Identifier" || declaration.init !== null && unwrapExpression(declaration.init).type !== "Literal") states.clear();
|
|
4961
4877
|
}
|
|
4962
|
-
return null;
|
|
4963
4878
|
}
|
|
4964
|
-
function
|
|
4965
|
-
const
|
|
4966
|
-
if (
|
|
4967
|
-
const
|
|
4968
|
-
|
|
4969
|
-
|
|
4879
|
+
function freshHeaders(node) {
|
|
4880
|
+
const value = unwrapExpression(node);
|
|
4881
|
+
if (value.type !== "NewExpression" || value.arguments.length !== 0) return false;
|
|
4882
|
+
const callee = unwrapExpression(value.callee);
|
|
4883
|
+
return callee.type === "Identifier" && callee.name === "Headers" && !binding(callee)?.defs.length;
|
|
4884
|
+
}
|
|
4885
|
+
function applyHeaderWrite(node, states) {
|
|
4886
|
+
const callee = unwrapExpression(node.callee);
|
|
4887
|
+
if (node.optional || callee.type !== "MemberExpression" || callee.optional || callee.computed || callee.property.type !== "Identifier" || !HEADER_METHODS.has(callee.property.name) || callee.object.type !== "Identifier") return false;
|
|
4888
|
+
const method = callee.property.name;
|
|
4889
|
+
const removal = method === "delete" || method === "removeHeader";
|
|
4890
|
+
if (node.arguments.length !== (removal ? 1 : 2)) return false;
|
|
4891
|
+
const name = literalString(node.arguments[0]);
|
|
4892
|
+
const value = removal ? null : headerValue(node.arguments[1]);
|
|
4893
|
+
if (name === null || !removal && value === null) return false;
|
|
4894
|
+
const key = receiverKey(callee.object);
|
|
4895
|
+
if (key === null) return false;
|
|
4896
|
+
let state = states.get(key);
|
|
4897
|
+
if (state === void 0) {
|
|
4898
|
+
state = { values: { [ACAO_HEADER]: void 0, [ACAC_HEADER]: void 0 }, origin: null };
|
|
4899
|
+
states.set(key, state);
|
|
4900
|
+
}
|
|
4901
|
+
const header = name.toLowerCase();
|
|
4902
|
+
if (header !== ACAO_HEADER && header !== ACAC_HEADER) return true;
|
|
4903
|
+
state.values[header] = method === "append" ? appendValue(state.values[header], value) : value;
|
|
4904
|
+
if (header === ACAO_HEADER) state.origin = node;
|
|
4905
|
+
return true;
|
|
4906
|
+
}
|
|
4907
|
+
function receiverKey(node) {
|
|
4908
|
+
const variable = binding(node);
|
|
4909
|
+
const key = variable ?? node.name;
|
|
4910
|
+
const cached = receiverProof.get(key);
|
|
4911
|
+
if (cached !== void 0) return cached ? key : null;
|
|
4912
|
+
const references = variable?.references ?? sourceCode.scopeManager?.globalScope?.through.filter((reference) => reference.identifier.name === node.name) ?? [];
|
|
4913
|
+
const unaliased = !variable?.defs.some(aliasDefinition) && references.every(headerReceiverReference);
|
|
4914
|
+
receiverProof.set(key, unaliased);
|
|
4915
|
+
return unaliased ? key : null;
|
|
4970
4916
|
}
|
|
4971
4917
|
return {
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4918
|
+
Program(node) {
|
|
4919
|
+
recordImports(node);
|
|
4920
|
+
inspectSequence(node);
|
|
4921
|
+
},
|
|
4922
|
+
BlockStatement(node) {
|
|
4923
|
+
if (["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression"].includes(node.parent.type)) inspectSequence(node);
|
|
4976
4924
|
},
|
|
4977
4925
|
CallExpression(node) {
|
|
4978
|
-
if (
|
|
4926
|
+
if (node.optional || node.arguments.length !== 1 || !officialCors(node.callee)) return;
|
|
4927
|
+
const argument = node.arguments[0];
|
|
4928
|
+
const options = argument === void 0 ? void 0 : unwrapExpression(argument);
|
|
4929
|
+
if (options?.type !== "ObjectExpression") return;
|
|
4930
|
+
const properties = effectiveProperties(options);
|
|
4931
|
+
const origin = properties?.get("origin");
|
|
4932
|
+
const credentials = properties?.get("credentials");
|
|
4933
|
+
const value = credentials === void 0 ? void 0 : unwrapExpression(credentials.value);
|
|
4934
|
+
if (origin !== void 0 && literalString(origin.value) === "*" && value?.type === "Literal" && value.value === true) {
|
|
4979
4935
|
context.report({ node, messageId: "corsWildcardWithCredentials" });
|
|
4980
|
-
return;
|
|
4981
|
-
}
|
|
4982
|
-
const kind = classifyHeaderSetCall(node);
|
|
4983
|
-
if (kind !== void 0) {
|
|
4984
|
-
recordHeaderSet(node, kind);
|
|
4985
4936
|
}
|
|
4986
4937
|
},
|
|
4987
4938
|
ObjectExpression(node) {
|
|
4988
|
-
if (
|
|
4939
|
+
if (spreadOnly(node)) return;
|
|
4940
|
+
const properties = effectiveProperties(node);
|
|
4941
|
+
if (properties === null) return;
|
|
4942
|
+
const headers = /* @__PURE__ */ new Map();
|
|
4943
|
+
for (const [key, property] of properties) {
|
|
4944
|
+
const value = headerValue(property.value);
|
|
4945
|
+
if (value === null) return;
|
|
4946
|
+
const name = key.toLowerCase();
|
|
4947
|
+
if (name !== ACAO_HEADER && name !== ACAC_HEADER) continue;
|
|
4948
|
+
const previous = headers.get(name);
|
|
4949
|
+
headers.set(name, previous === void 0 ? value : previous + ", " + value);
|
|
4950
|
+
}
|
|
4951
|
+
if (headers.get(ACAO_HEADER) === "*" && headers.get(ACAC_HEADER) === "true") {
|
|
4989
4952
|
context.report({ node, messageId: "corsWildcardWithCredentials" });
|
|
4990
4953
|
}
|
|
4991
|
-
},
|
|
4992
|
-
"Program:exit"() {
|
|
4993
|
-
for (const receivers of scopeHeaderSets.values()) {
|
|
4994
|
-
for (const { originNodes, credentialsNodes } of receivers.values()) {
|
|
4995
|
-
if (originNodes.length > 0 && credentialsNodes.length > 0) {
|
|
4996
|
-
for (const node of originNodes) {
|
|
4997
|
-
context.report({
|
|
4998
|
-
node,
|
|
4999
|
-
messageId: "corsWildcardWithCredentials"
|
|
5000
|
-
});
|
|
5001
|
-
}
|
|
5002
|
-
}
|
|
5003
|
-
}
|
|
5004
|
-
}
|
|
5005
4954
|
}
|
|
5006
4955
|
};
|
|
5007
4956
|
}
|
|
5008
4957
|
});
|
|
4958
|
+
function importRole(specifier, module) {
|
|
4959
|
+
if (module === "hono/cors" && specifier.type === "ImportNamespaceSpecifier") return "namespace";
|
|
4960
|
+
if (module === "cors" && specifier.type === "ImportDefaultSpecifier") return "function";
|
|
4961
|
+
if (specifier.type !== "ImportSpecifier" || specifier.importKind === "type") return null;
|
|
4962
|
+
const name = specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
|
|
4963
|
+
return module === "cors" && name === "default" || module === "hono/cors" && name === "cors" ? "function" : null;
|
|
4964
|
+
}
|
|
4965
|
+
function aliasDefinition(definition) {
|
|
4966
|
+
if (definition.type !== "Variable") return false;
|
|
4967
|
+
if (definition.node.id.type !== "Identifier") return true;
|
|
4968
|
+
const initializer = definition.node.init;
|
|
4969
|
+
return initializer !== null && ["Identifier", "MemberExpression", "AssignmentExpression", "ConditionalExpression", "LogicalExpression", "SequenceExpression"].includes(unwrapExpression(initializer).type);
|
|
4970
|
+
}
|
|
4971
|
+
function headerReceiverReference(reference) {
|
|
4972
|
+
let typeName = reference.identifier;
|
|
4973
|
+
while (typeName.parent.type === "TSQualifiedName") typeName = typeName.parent;
|
|
4974
|
+
if (reference.isValueReference === false || typeName.parent.type === "TSTypeQuery") return true;
|
|
4975
|
+
if (reference.isWrite()) return reference.init === true;
|
|
4976
|
+
const member = reference.identifier.parent;
|
|
4977
|
+
if (member.type !== "MemberExpression" || member.object !== reference.identifier || member.computed || member.optional || member.property.type !== "Identifier" || !HEADER_METHODS.has(member.property.name)) return false;
|
|
4978
|
+
return member.parent.type === "CallExpression" && member.parent.callee === member && !member.parent.optional;
|
|
4979
|
+
}
|
|
4980
|
+
function appendValue(previous, value) {
|
|
4981
|
+
if (previous === void 0) return void 0;
|
|
4982
|
+
return previous === null ? value : previous + ", " + value;
|
|
4983
|
+
}
|
|
4984
|
+
function literalString(node) {
|
|
4985
|
+
const value = node === void 0 ? void 0 : unwrapExpression(node);
|
|
4986
|
+
return value?.type === "Literal" && typeof value.value === "string" ? value.value : null;
|
|
4987
|
+
}
|
|
4988
|
+
function headerValue(node) {
|
|
4989
|
+
const value = node === void 0 ? void 0 : unwrapExpression(node);
|
|
4990
|
+
if (value?.type !== "Literal" || !["string", "boolean", "number"].includes(typeof value.value)) return null;
|
|
4991
|
+
return String(value.value).replace(/^[\t\n\r ]+|[\t\n\r ]+$/g, "");
|
|
4992
|
+
}
|
|
4993
|
+
function effectiveProperties(node) {
|
|
4994
|
+
const properties = /* @__PURE__ */ new Map();
|
|
4995
|
+
for (const entry of node.properties) {
|
|
4996
|
+
const entries = propertyEntries(entry);
|
|
4997
|
+
if (entries === null) return null;
|
|
4998
|
+
for (const [key, property] of entries) properties.set(key, property);
|
|
4999
|
+
}
|
|
5000
|
+
return properties;
|
|
5001
|
+
}
|
|
5002
|
+
function propertyEntries(entry) {
|
|
5003
|
+
if (entry.type === "SpreadElement") {
|
|
5004
|
+
const value = unwrapExpression(entry.argument);
|
|
5005
|
+
return value.type === "ObjectExpression" ? effectiveProperties(value) : null;
|
|
5006
|
+
}
|
|
5007
|
+
if (entry.kind !== "init" || entry.method) return null;
|
|
5008
|
+
const key = entry.computed ? literalPropertyKey(entry.key) : ASTUtils7.getPropertyName(entry);
|
|
5009
|
+
if (key === null) return null;
|
|
5010
|
+
if (key === "__proto__" && !entry.computed) {
|
|
5011
|
+
const value = unwrapExpression(entry.value);
|
|
5012
|
+
return value.type === "Literal" && value.value === null ? [] : null;
|
|
5013
|
+
}
|
|
5014
|
+
return [[key, entry]];
|
|
5015
|
+
}
|
|
5016
|
+
function literalPropertyKey(node) {
|
|
5017
|
+
const value = unwrapExpression(node);
|
|
5018
|
+
const literal = literalString(value);
|
|
5019
|
+
if (literal !== null) return literal;
|
|
5020
|
+
if (value.type !== "TemplateLiteral" || value.expressions.length !== 0) return null;
|
|
5021
|
+
return value.quasis[0]?.value.cooked ?? null;
|
|
5022
|
+
}
|
|
5023
|
+
function spreadOnly(node) {
|
|
5024
|
+
let current = outerExpression(node);
|
|
5025
|
+
while (current.parent !== void 0) {
|
|
5026
|
+
const parent = current.parent;
|
|
5027
|
+
if (parent.type === "SpreadElement") return parent.parent.type === "ObjectExpression";
|
|
5028
|
+
if (![
|
|
5029
|
+
"Property",
|
|
5030
|
+
"ObjectExpression",
|
|
5031
|
+
"ConditionalExpression",
|
|
5032
|
+
"LogicalExpression",
|
|
5033
|
+
"SequenceExpression",
|
|
5034
|
+
"TSAsExpression",
|
|
5035
|
+
"TSSatisfiesExpression",
|
|
5036
|
+
"TSNonNullExpression",
|
|
5037
|
+
"TSTypeAssertion"
|
|
5038
|
+
].includes(parent.type)) return false;
|
|
5039
|
+
current = parent;
|
|
5040
|
+
}
|
|
5041
|
+
return false;
|
|
5042
|
+
}
|
|
5009
5043
|
|
|
5010
5044
|
// src/rules/no-duplicate-lifecycle-refresh-listeners.ts
|
|
5011
|
-
import { AST_NODE_TYPES as
|
|
5045
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES27, ASTUtils as ASTUtils9 } from "@typescript-eslint/utils";
|
|
5012
5046
|
|
|
5013
5047
|
// src/rules/_static-string.ts
|
|
5014
|
-
import { AST_NODE_TYPES as
|
|
5048
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES26, ASTUtils as ASTUtils8 } from "@typescript-eslint/utils";
|
|
5015
5049
|
function staticString(node) {
|
|
5016
5050
|
if (node === void 0) return null;
|
|
5017
5051
|
const value = unwrapExpression(node);
|
|
5018
|
-
if (value.type ===
|
|
5019
|
-
return value.type ===
|
|
5052
|
+
if (value.type === AST_NODE_TYPES26.Literal && typeof value.value === "string") return value.value;
|
|
5053
|
+
return value.type === AST_NODE_TYPES26.TemplateLiteral && value.expressions.length === 0 ? value.quasis[0]?.value.cooked ?? null : null;
|
|
5020
5054
|
}
|
|
5021
5055
|
var SCOPED_STRING_VALUES = /* @__PURE__ */ new WeakMap();
|
|
5022
5056
|
function scopedStaticString(node, sourceCode) {
|
|
5023
5057
|
let value = unwrapExpression(node);
|
|
5024
|
-
if (value.type !==
|
|
5058
|
+
if (value.type !== AST_NODE_TYPES26.Identifier) return staticString(value);
|
|
5025
5059
|
let values = SCOPED_STRING_VALUES.get(sourceCode);
|
|
5026
5060
|
if (values === void 0) {
|
|
5027
5061
|
values = /* @__PURE__ */ new WeakMap();
|
|
@@ -5030,7 +5064,7 @@ function scopedStaticString(node, sourceCode) {
|
|
|
5030
5064
|
const seen = /* @__PURE__ */ new Set();
|
|
5031
5065
|
const pending = [];
|
|
5032
5066
|
let result = null;
|
|
5033
|
-
while (value.type ===
|
|
5067
|
+
while (value.type === AST_NODE_TYPES26.Identifier) {
|
|
5034
5068
|
const binding = ASTUtils8.findVariable(sourceCode.getScope(value), value.name);
|
|
5035
5069
|
if (binding === null || seen.has(binding)) break;
|
|
5036
5070
|
if (values.has(binding)) {
|
|
@@ -5040,9 +5074,9 @@ function scopedStaticString(node, sourceCode) {
|
|
|
5040
5074
|
seen.add(binding);
|
|
5041
5075
|
pending.push(binding);
|
|
5042
5076
|
const definition = binding.defs.length === 1 ? binding.defs[0] : void 0;
|
|
5043
|
-
if (definition?.type !== "Variable" || definition.node.id.type !==
|
|
5077
|
+
if (definition?.type !== "Variable" || definition.node.id.type !== AST_NODE_TYPES26.Identifier || definition.node.init === null || binding.references.some((reference) => reference.isWrite() && reference.init !== true)) break;
|
|
5044
5078
|
value = unwrapExpression(definition.node.init);
|
|
5045
|
-
if (value.type !==
|
|
5079
|
+
if (value.type !== AST_NODE_TYPES26.Identifier) result = staticString(value);
|
|
5046
5080
|
}
|
|
5047
5081
|
for (const binding of pending) values.set(binding, result);
|
|
5048
5082
|
return result;
|
|
@@ -5050,8 +5084,8 @@ function scopedStaticString(node, sourceCode) {
|
|
|
5050
5084
|
function staticPropertyName(node, sourceCode) {
|
|
5051
5085
|
const direct = ASTUtils8.getPropertyName(node);
|
|
5052
5086
|
if (direct !== null || !node.computed) return direct;
|
|
5053
|
-
const key = node.type ===
|
|
5054
|
-
return key.type ===
|
|
5087
|
+
const key = node.type === AST_NODE_TYPES26.MemberExpression ? node.property : node.key;
|
|
5088
|
+
return key.type === AST_NODE_TYPES26.Identifier ? scopedStaticString(key, sourceCode) : null;
|
|
5055
5089
|
}
|
|
5056
5090
|
|
|
5057
5091
|
// src/rules/no-duplicate-lifecycle-refresh-listeners.ts
|
|
@@ -5067,17 +5101,17 @@ var NO_DUPLICATE_LIFECYCLE_REFRESH_LISTENERS_DOCUMENTATION = {
|
|
|
5067
5101
|
]
|
|
5068
5102
|
};
|
|
5069
5103
|
function importedName(node) {
|
|
5070
|
-
return node.imported.type ===
|
|
5104
|
+
return node.imported.type === AST_NODE_TYPES27.Identifier ? node.imported.name : String(node.imported.value);
|
|
5071
5105
|
}
|
|
5072
5106
|
function registration(sourceCode, node) {
|
|
5073
5107
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
5074
|
-
const receiver = unwrappedNodeCallee.type ===
|
|
5075
|
-
if (unwrappedNodeCallee.type !==
|
|
5108
|
+
const receiver = unwrappedNodeCallee.type === AST_NODE_TYPES27.MemberExpression ? unwrapExpression(unwrappedNodeCallee.object) : unwrappedNodeCallee;
|
|
5109
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES27.MemberExpression || receiver.type !== AST_NODE_TYPES27.Identifier || !isUnshadowedGlobal(sourceCode, receiver) || ASTUtils9.getPropertyName(unwrappedNodeCallee) === null || (ASTUtils9.getPropertyName(unwrappedNodeCallee) ?? "") !== "addEventListener" && (ASTUtils9.getPropertyName(unwrappedNodeCallee) ?? "") !== "removeEventListener" || node.arguments.length < 2) return null;
|
|
5076
5110
|
const event = node.arguments[0] === void 0 ? void 0 : unwrapExpression(node.arguments[0]);
|
|
5077
5111
|
const callback = node.arguments[1] === void 0 ? void 0 : unwrapExpression(node.arguments[1]);
|
|
5078
5112
|
if (event === void 0 || callback === void 0) return null;
|
|
5079
5113
|
const eventName = staticString(event);
|
|
5080
|
-
if (eventName === null || callback.type !==
|
|
5114
|
+
if (eventName === null || callback.type !== AST_NODE_TYPES27.Identifier) return null;
|
|
5081
5115
|
const operation = (ASTUtils9.getPropertyName(unwrappedNodeCallee) ?? "") === "addEventListener" ? "add" : "remove";
|
|
5082
5116
|
if (receiver.name === "window" && eventName === "focus") return { operation, event: "focus", callback };
|
|
5083
5117
|
if (receiver.name === "document" && eventName === "visibilitychange") return { operation, event: "visibilitychange", callback };
|
|
@@ -5089,15 +5123,15 @@ function isUnshadowedGlobal(sourceCode, node) {
|
|
|
5089
5123
|
}
|
|
5090
5124
|
function statementContainer(node) {
|
|
5091
5125
|
const statement = outerExpression(node).parent;
|
|
5092
|
-
if (statement.type !==
|
|
5126
|
+
if (statement.type !== AST_NODE_TYPES27.ExpressionStatement) return null;
|
|
5093
5127
|
const container = statement.parent;
|
|
5094
|
-
return container.type ===
|
|
5128
|
+
return container.type === AST_NODE_TYPES27.Program || container.type === AST_NODE_TYPES27.BlockStatement ? container : null;
|
|
5095
5129
|
}
|
|
5096
5130
|
function enclosingFunction(sourceCode, node) {
|
|
5097
5131
|
const ancestors = sourceCode.getAncestors(node);
|
|
5098
5132
|
for (let index = ancestors.length - 1; index >= 0; index -= 1) {
|
|
5099
5133
|
const ancestor = ancestors[index];
|
|
5100
|
-
if (ancestor?.type ===
|
|
5134
|
+
if (ancestor?.type === AST_NODE_TYPES27.ArrowFunctionExpression || ancestor?.type === AST_NODE_TYPES27.FunctionExpression || ancestor?.type === AST_NODE_TYPES27.FunctionDeclaration) return ancestor;
|
|
5101
5135
|
}
|
|
5102
5136
|
return null;
|
|
5103
5137
|
}
|
|
@@ -5122,7 +5156,7 @@ var no_duplicate_lifecycle_refresh_listeners_default = createRule({
|
|
|
5122
5156
|
ImportDeclaration(node) {
|
|
5123
5157
|
if (node.source.value !== "next/navigation") return;
|
|
5124
5158
|
for (const specifier of node.specifiers) {
|
|
5125
|
-
if (specifier.type ===
|
|
5159
|
+
if (specifier.type === AST_NODE_TYPES27.ImportSpecifier && importedName(specifier) === "useRouter") {
|
|
5126
5160
|
const variable = ASTUtils9.findVariable(context.sourceCode.getScope(specifier.local), specifier.local.name);
|
|
5127
5161
|
if (variable !== null) routerHooks.add(variable);
|
|
5128
5162
|
}
|
|
@@ -5130,15 +5164,15 @@ var no_duplicate_lifecycle_refresh_listeners_default = createRule({
|
|
|
5130
5164
|
},
|
|
5131
5165
|
VariableDeclarator(node) {
|
|
5132
5166
|
const initializer = node.init === null ? null : unwrapExpression(node.init);
|
|
5133
|
-
if (node.id.type !==
|
|
5167
|
+
if (node.id.type !== AST_NODE_TYPES27.Identifier) return;
|
|
5134
5168
|
const variable = ASTUtils9.findVariable(context.sourceCode.getScope(node.id), node.id.name);
|
|
5135
5169
|
if (variable === null || variable.references.some((reference) => reference.isWrite() && !reference.init)) return;
|
|
5136
|
-
if (initializer?.type ===
|
|
5170
|
+
if (initializer?.type === AST_NODE_TYPES27.ArrowFunctionExpression || initializer?.type === AST_NODE_TYPES27.FunctionExpression) {
|
|
5137
5171
|
functionCallbacks.set(initializer, variable);
|
|
5138
5172
|
}
|
|
5139
|
-
if (initializer?.type !==
|
|
5173
|
+
if (initializer?.type !== AST_NODE_TYPES27.CallExpression) return;
|
|
5140
5174
|
const hookCallee = unwrapExpression(initializer.callee);
|
|
5141
|
-
if (hookCallee.type !==
|
|
5175
|
+
if (hookCallee.type !== AST_NODE_TYPES27.Identifier) return;
|
|
5142
5176
|
const hook = ASTUtils9.findVariable(context.sourceCode.getScope(hookCallee), hookCallee.name);
|
|
5143
5177
|
if (hook !== null && routerHooks.has(hook)) routers.add(variable);
|
|
5144
5178
|
},
|
|
@@ -5162,8 +5196,8 @@ var no_duplicate_lifecycle_refresh_listeners_default = createRule({
|
|
|
5162
5196
|
registrations.set(container, callbacks);
|
|
5163
5197
|
}
|
|
5164
5198
|
}
|
|
5165
|
-
const receiver = unwrappedNodeCallee.type ===
|
|
5166
|
-
if (unwrappedNodeCallee.type !==
|
|
5199
|
+
const receiver = unwrappedNodeCallee.type === AST_NODE_TYPES27.MemberExpression ? unwrapExpression(unwrappedNodeCallee.object) : unwrappedNodeCallee;
|
|
5200
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES27.MemberExpression || receiver.type !== AST_NODE_TYPES27.Identifier || ASTUtils9.getPropertyName(unwrappedNodeCallee) === null || (ASTUtils9.getPropertyName(unwrappedNodeCallee) ?? "") !== "refresh") return;
|
|
5167
5201
|
const router = ASTUtils9.findVariable(context.sourceCode.getScope(receiver), receiver.name);
|
|
5168
5202
|
if (router === null || !routers.has(router)) return;
|
|
5169
5203
|
const fn = enclosingFunction(context.sourceCode, node);
|
|
@@ -5264,7 +5298,7 @@ var NO_DANGEROUSLY_ALLOW_SVG_DOCUMENTATION = {
|
|
|
5264
5298
|
}
|
|
5265
5299
|
]
|
|
5266
5300
|
};
|
|
5267
|
-
function
|
|
5301
|
+
function literalString2(node) {
|
|
5268
5302
|
if (node?.value.type === "Literal" && typeof node.value.value === "string") return node.value.value;
|
|
5269
5303
|
if (node?.value.type === "TemplateLiteral" && node.value.expressions.length === 0) return node.value.quasis[0]?.value.cooked ?? null;
|
|
5270
5304
|
return null;
|
|
@@ -5296,10 +5330,10 @@ var no_dangerously_allow_svg_default = createRule({
|
|
|
5296
5330
|
const node = exportedNextConfigProperty(context.sourceCode, ["images", "dangerouslyAllowSVG"]);
|
|
5297
5331
|
if (node !== null && node.value.type === "Literal" && node.value.value === true) {
|
|
5298
5332
|
const disposition = exportedNextConfigProperty(context.sourceCode, ["images", "contentDispositionType"]);
|
|
5299
|
-
const policy =
|
|
5333
|
+
const policy = literalString2(
|
|
5300
5334
|
exportedNextConfigProperty(context.sourceCode, ["images", "contentSecurityPolicy"])
|
|
5301
5335
|
);
|
|
5302
|
-
const attachmentDisposition = disposition === null ||
|
|
5336
|
+
const attachmentDisposition = disposition === null || literalString2(disposition) === "attachment";
|
|
5303
5337
|
if (attachmentDisposition && policy !== null && hasHardenedSvgPolicy(policy)) return;
|
|
5304
5338
|
context.report({ node, messageId: "noDangerouslyAllowSvg" });
|
|
5305
5339
|
}
|
|
@@ -5309,10 +5343,10 @@ var no_dangerously_allow_svg_default = createRule({
|
|
|
5309
5343
|
});
|
|
5310
5344
|
|
|
5311
5345
|
// src/rules/no-dynamic-sql.ts
|
|
5312
|
-
import { ASTUtils as ASTUtils11, AST_NODE_TYPES as
|
|
5346
|
+
import { ASTUtils as ASTUtils11, AST_NODE_TYPES as AST_NODE_TYPES29 } from "@typescript-eslint/utils";
|
|
5313
5347
|
|
|
5314
5348
|
// src/rules/_sql.ts
|
|
5315
|
-
import { AST_NODE_TYPES as
|
|
5349
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES28 } from "@typescript-eslint/utils";
|
|
5316
5350
|
function stripSqlNoise(text) {
|
|
5317
5351
|
return scanSqlNoise(text);
|
|
5318
5352
|
}
|
|
@@ -5406,13 +5440,13 @@ function maskSqlRange(text, out, start, end) {
|
|
|
5406
5440
|
var SUBSTITUTION_MARKER = "?";
|
|
5407
5441
|
function sqlTextOf(node) {
|
|
5408
5442
|
switch (node.type) {
|
|
5409
|
-
case
|
|
5443
|
+
case AST_NODE_TYPES28.Literal:
|
|
5410
5444
|
return typeof node.value === "string" ? node.value : null;
|
|
5411
|
-
case
|
|
5445
|
+
case AST_NODE_TYPES28.TemplateLiteral:
|
|
5412
5446
|
return node.quasis.map((q) => q.value.cooked ?? q.value.raw).join(SUBSTITUTION_MARKER);
|
|
5413
|
-
case
|
|
5447
|
+
case AST_NODE_TYPES28.TaggedTemplateExpression:
|
|
5414
5448
|
return sqlTextOf(node.quasi);
|
|
5415
|
-
case
|
|
5449
|
+
case AST_NODE_TYPES28.BinaryExpression: {
|
|
5416
5450
|
if (node.operator !== "+") {
|
|
5417
5451
|
return null;
|
|
5418
5452
|
}
|
|
@@ -5420,7 +5454,7 @@ function sqlTextOf(node) {
|
|
|
5420
5454
|
const right = sqlTextOf(node.right);
|
|
5421
5455
|
return left !== null && right !== null ? left + right : null;
|
|
5422
5456
|
}
|
|
5423
|
-
case
|
|
5457
|
+
case AST_NODE_TYPES28.ArrayExpression: {
|
|
5424
5458
|
const parts = [];
|
|
5425
5459
|
for (const element of node.elements) {
|
|
5426
5460
|
if (element === null) {
|
|
@@ -5440,7 +5474,7 @@ function sqlTextOf(node) {
|
|
|
5440
5474
|
}
|
|
5441
5475
|
function isJoinedFragmentArray(node) {
|
|
5442
5476
|
const parent = node.parent;
|
|
5443
|
-
return parent?.type ===
|
|
5477
|
+
return parent?.type === AST_NODE_TYPES28.MemberExpression && parent.object === node && !parent.computed && parent.property.type === AST_NODE_TYPES28.Identifier && parent.property.name === "join" && parent.parent?.type === AST_NODE_TYPES28.CallExpression;
|
|
5444
5478
|
}
|
|
5445
5479
|
function markConsumed(node, consumed) {
|
|
5446
5480
|
consumed.add(node);
|
|
@@ -5480,12 +5514,12 @@ function isDiscardedSqlText(node) {
|
|
|
5480
5514
|
let current = node;
|
|
5481
5515
|
let parent = current.parent;
|
|
5482
5516
|
while (parent !== void 0 && parent !== null) {
|
|
5483
|
-
if (unwrapExpression(parent) === current || parent.type ===
|
|
5517
|
+
if (unwrapExpression(parent) === current || parent.type === AST_NODE_TYPES28.BinaryExpression && parent.operator === "+") {
|
|
5484
5518
|
current = parent;
|
|
5485
5519
|
parent = current.parent;
|
|
5486
5520
|
continue;
|
|
5487
5521
|
}
|
|
5488
|
-
return parent.type ===
|
|
5522
|
+
return parent.type === AST_NODE_TYPES28.UnaryExpression && parent.operator === "void";
|
|
5489
5523
|
}
|
|
5490
5524
|
return false;
|
|
5491
5525
|
}
|
|
@@ -5545,16 +5579,16 @@ var NO_DYNAMIC_SQL_DOCUMENTATION = {
|
|
|
5545
5579
|
var DEFAULT_METHODS = ["prepare", "exec", "query"];
|
|
5546
5580
|
var CONSTANT_CASE_RE = /^[A-Z][A-Z0-9_]*$/;
|
|
5547
5581
|
function isStaticFragment(expression) {
|
|
5548
|
-
if (expression.type ===
|
|
5582
|
+
if (expression.type === AST_NODE_TYPES29.Identifier) {
|
|
5549
5583
|
return CONSTANT_CASE_RE.test(expression.name);
|
|
5550
5584
|
}
|
|
5551
|
-
if (expression.type ===
|
|
5585
|
+
if (expression.type === AST_NODE_TYPES29.MemberExpression && ASTUtils11.getPropertyName(expression) !== null) {
|
|
5552
5586
|
return CONSTANT_CASE_RE.test(ASTUtils11.getPropertyName(expression) ?? "");
|
|
5553
5587
|
}
|
|
5554
|
-
if (expression.type ===
|
|
5588
|
+
if (expression.type === AST_NODE_TYPES29.Literal) {
|
|
5555
5589
|
return typeof expression.value === "string";
|
|
5556
5590
|
}
|
|
5557
|
-
if (expression.type ===
|
|
5591
|
+
if (expression.type === AST_NODE_TYPES29.TemplateLiteral) {
|
|
5558
5592
|
return expression.expressions.length === 0;
|
|
5559
5593
|
}
|
|
5560
5594
|
return false;
|
|
@@ -5586,21 +5620,21 @@ function startsWithSqlQuote(text) {
|
|
|
5586
5620
|
return /^\s*'/u.test(text);
|
|
5587
5621
|
}
|
|
5588
5622
|
function staticLiteralText(node) {
|
|
5589
|
-
if (node.type ===
|
|
5623
|
+
if (node.type === AST_NODE_TYPES29.Literal && typeof node.value === "string") {
|
|
5590
5624
|
return node.value;
|
|
5591
5625
|
}
|
|
5592
|
-
if (node.type ===
|
|
5626
|
+
if (node.type === AST_NODE_TYPES29.TemplateLiteral && node.expressions.length === 0) {
|
|
5593
5627
|
return node.quasis[0]?.value.raw;
|
|
5594
5628
|
}
|
|
5595
5629
|
return void 0;
|
|
5596
5630
|
}
|
|
5597
5631
|
function runtimeConcatOperands(node) {
|
|
5598
|
-
if (node.type !==
|
|
5632
|
+
if (node.type !== AST_NODE_TYPES29.BinaryExpression || node.operator !== "+") {
|
|
5599
5633
|
return [];
|
|
5600
5634
|
}
|
|
5601
5635
|
const operands = concatOperands(node);
|
|
5602
5636
|
const hasStringLiteral = operands.some(
|
|
5603
|
-
(operand) => operand.type ===
|
|
5637
|
+
(operand) => operand.type === AST_NODE_TYPES29.Literal && typeof operand.value === "string" || operand.type === AST_NODE_TYPES29.TemplateLiteral && operand.expressions.length === 0
|
|
5604
5638
|
);
|
|
5605
5639
|
if (!hasStringLiteral) {
|
|
5606
5640
|
return [];
|
|
@@ -5624,7 +5658,7 @@ function runtimeConcatOperands(node) {
|
|
|
5624
5658
|
});
|
|
5625
5659
|
}
|
|
5626
5660
|
function concatOperands(node) {
|
|
5627
|
-
if (node.type ===
|
|
5661
|
+
if (node.type === AST_NODE_TYPES29.BinaryExpression && node.operator === "+") {
|
|
5628
5662
|
return [...concatOperands(node.left), ...concatOperands(node.right)];
|
|
5629
5663
|
}
|
|
5630
5664
|
return [node];
|
|
@@ -5635,20 +5669,20 @@ function looksLikeSql(node) {
|
|
|
5635
5669
|
return SQL_STATEMENT_RE.test(stripSqlNoise(staticStatementText(node)));
|
|
5636
5670
|
}
|
|
5637
5671
|
function staticStatementText(node) {
|
|
5638
|
-
if (node.type ===
|
|
5672
|
+
if (node.type === AST_NODE_TYPES29.TemplateLiteral) {
|
|
5639
5673
|
return node.quasis.map((quasi) => quasi.value.cooked ?? quasi.value.raw).join(RUNTIME_MARKER);
|
|
5640
5674
|
}
|
|
5641
|
-
if (node.type ===
|
|
5675
|
+
if (node.type === AST_NODE_TYPES29.Literal) {
|
|
5642
5676
|
return typeof node.value === "string" ? node.value : RUNTIME_MARKER;
|
|
5643
5677
|
}
|
|
5644
|
-
if (node.type ===
|
|
5678
|
+
if (node.type === AST_NODE_TYPES29.BinaryExpression && node.operator === "+") {
|
|
5645
5679
|
return staticStatementText(node.left) + staticStatementText(node.right);
|
|
5646
5680
|
}
|
|
5647
5681
|
return RUNTIME_MARKER;
|
|
5648
5682
|
}
|
|
5649
5683
|
function statementMethodName(node, methods) {
|
|
5650
5684
|
const callee = unwrapExpression(node.callee);
|
|
5651
|
-
if (callee.type !==
|
|
5685
|
+
if (callee.type !== AST_NODE_TYPES29.MemberExpression || ASTUtils11.getPropertyName(callee) === null) {
|
|
5652
5686
|
return null;
|
|
5653
5687
|
}
|
|
5654
5688
|
const name = ASTUtils11.getPropertyName(callee) ?? "";
|
|
@@ -5693,7 +5727,7 @@ var no_dynamic_sql_default = createRule({
|
|
|
5693
5727
|
if (statement === void 0 || !looksLikeSql(statement)) {
|
|
5694
5728
|
return;
|
|
5695
5729
|
}
|
|
5696
|
-
const offenders = statement.type ===
|
|
5730
|
+
const offenders = statement.type === AST_NODE_TYPES29.TemplateLiteral ? runtimeInterpolations(statement) : runtimeConcatOperands(statement);
|
|
5697
5731
|
for (const offender of offenders) {
|
|
5698
5732
|
context.report({
|
|
5699
5733
|
node: offender.expression,
|
|
@@ -5794,7 +5828,7 @@ var no_enum_default = createRule({
|
|
|
5794
5828
|
});
|
|
5795
5829
|
|
|
5796
5830
|
// src/rules/no-excessive-cognitive-complexity.ts
|
|
5797
|
-
import { AST_NODE_TYPES as
|
|
5831
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES30 } from "@typescript-eslint/utils";
|
|
5798
5832
|
var ERROR_COMPLEXITY = 20;
|
|
5799
5833
|
var MAX_CONTRIBUTORS = 3;
|
|
5800
5834
|
var NO_EXCESSIVE_COGNITIVE_COMPLEXITY_DOCUMENTATION = {
|
|
@@ -5829,7 +5863,7 @@ function functionComplexity(fn, visitorKeys) {
|
|
|
5829
5863
|
visit(branch.test, nesting);
|
|
5830
5864
|
visit(branch.consequent, nesting + 1);
|
|
5831
5865
|
const alternate = branch.alternate;
|
|
5832
|
-
if (alternate?.type ===
|
|
5866
|
+
if (alternate?.type === AST_NODE_TYPES30.IfStatement) {
|
|
5833
5867
|
add(alternate, 0, "else if");
|
|
5834
5868
|
branch = alternate;
|
|
5835
5869
|
} else {
|
|
@@ -5843,58 +5877,58 @@ function functionComplexity(fn, visitorKeys) {
|
|
|
5843
5877
|
}
|
|
5844
5878
|
function visit(node, nesting) {
|
|
5845
5879
|
switch (node.type) {
|
|
5846
|
-
case
|
|
5847
|
-
case
|
|
5848
|
-
case
|
|
5849
|
-
case
|
|
5850
|
-
case
|
|
5880
|
+
case AST_NODE_TYPES30.FunctionDeclaration:
|
|
5881
|
+
case AST_NODE_TYPES30.FunctionExpression:
|
|
5882
|
+
case AST_NODE_TYPES30.ArrowFunctionExpression:
|
|
5883
|
+
case AST_NODE_TYPES30.ClassDeclaration:
|
|
5884
|
+
case AST_NODE_TYPES30.ClassExpression:
|
|
5851
5885
|
return;
|
|
5852
|
-
case
|
|
5886
|
+
case AST_NODE_TYPES30.IfStatement:
|
|
5853
5887
|
conditional(node, nesting);
|
|
5854
5888
|
return;
|
|
5855
|
-
case
|
|
5889
|
+
case AST_NODE_TYPES30.ForStatement:
|
|
5856
5890
|
add(node, nesting, "loop");
|
|
5857
5891
|
if (node.init !== null) visit(node.init, nesting);
|
|
5858
5892
|
if (node.test !== null) visit(node.test, nesting);
|
|
5859
5893
|
if (node.update !== null) visit(node.update, nesting);
|
|
5860
5894
|
visit(node.body, nesting + 1);
|
|
5861
5895
|
return;
|
|
5862
|
-
case
|
|
5863
|
-
case
|
|
5896
|
+
case AST_NODE_TYPES30.ForInStatement:
|
|
5897
|
+
case AST_NODE_TYPES30.ForOfStatement:
|
|
5864
5898
|
add(node, nesting, "loop");
|
|
5865
5899
|
visit(node.left, nesting);
|
|
5866
5900
|
visit(node.right, nesting);
|
|
5867
5901
|
visit(node.body, nesting + 1);
|
|
5868
5902
|
return;
|
|
5869
|
-
case
|
|
5870
|
-
case
|
|
5903
|
+
case AST_NODE_TYPES30.WhileStatement:
|
|
5904
|
+
case AST_NODE_TYPES30.DoWhileStatement:
|
|
5871
5905
|
add(node, nesting, "loop");
|
|
5872
5906
|
visit(node.test, nesting);
|
|
5873
5907
|
visit(node.body, nesting + 1);
|
|
5874
5908
|
return;
|
|
5875
|
-
case
|
|
5909
|
+
case AST_NODE_TYPES30.CatchClause:
|
|
5876
5910
|
add(node, nesting, "catch");
|
|
5877
5911
|
visit(node.body, nesting + 1);
|
|
5878
5912
|
return;
|
|
5879
|
-
case
|
|
5913
|
+
case AST_NODE_TYPES30.SwitchStatement:
|
|
5880
5914
|
add(node, nesting, "switch");
|
|
5881
5915
|
visit(node.discriminant, nesting);
|
|
5882
5916
|
for (const branch of node.cases) visit(branch, nesting + 1);
|
|
5883
5917
|
return;
|
|
5884
|
-
case
|
|
5918
|
+
case AST_NODE_TYPES30.ConditionalExpression:
|
|
5885
5919
|
add(node, nesting, "conditional");
|
|
5886
5920
|
visit(node.test, nesting);
|
|
5887
5921
|
visit(node.consequent, nesting + 1);
|
|
5888
5922
|
visit(node.alternate, nesting + 1);
|
|
5889
5923
|
return;
|
|
5890
|
-
case
|
|
5924
|
+
case AST_NODE_TYPES30.LogicalExpression:
|
|
5891
5925
|
if (node.operator !== "??") {
|
|
5892
5926
|
logical(node, nesting);
|
|
5893
5927
|
return;
|
|
5894
5928
|
}
|
|
5895
5929
|
break;
|
|
5896
|
-
case
|
|
5897
|
-
case
|
|
5930
|
+
case AST_NODE_TYPES30.BreakStatement:
|
|
5931
|
+
case AST_NODE_TYPES30.ContinueStatement:
|
|
5898
5932
|
if (node.label !== null) add(node, 0, "labeled jump");
|
|
5899
5933
|
return;
|
|
5900
5934
|
}
|
|
@@ -5903,7 +5937,7 @@ function functionComplexity(fn, visitorKeys) {
|
|
|
5903
5937
|
function logical(node, nesting) {
|
|
5904
5938
|
let previous;
|
|
5905
5939
|
function flatten(expression) {
|
|
5906
|
-
if (expression.type !==
|
|
5940
|
+
if (expression.type !== AST_NODE_TYPES30.LogicalExpression || expression.operator === "??") {
|
|
5907
5941
|
visit(expression, nesting);
|
|
5908
5942
|
return;
|
|
5909
5943
|
}
|
|
@@ -5946,7 +5980,7 @@ var no_excessive_cognitive_complexity_default = createRule({
|
|
|
5946
5980
|
});
|
|
5947
5981
|
|
|
5948
5982
|
// src/rules/no-fat-try-blocks.ts
|
|
5949
|
-
import { AST_NODE_TYPES as
|
|
5983
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES31 } from "@typescript-eslint/utils";
|
|
5950
5984
|
var NO_FAT_TRY_BLOCKS_DOCUMENTATION = {
|
|
5951
5985
|
summary: "Review try blocks exceeding the configured count of syntactically selected operations.",
|
|
5952
5986
|
rationale: "A broad `try` block obscures which operation failed and encourages one catch clause to recover from unrelated errors.",
|
|
@@ -5984,9 +6018,9 @@ var NO_FAT_TRY_BLOCKS_DOCUMENTATION = {
|
|
|
5984
6018
|
};
|
|
5985
6019
|
var MAX_TRY_BODY_STATEMENTS = 3;
|
|
5986
6020
|
var NESTED_FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
6021
|
+
AST_NODE_TYPES31.FunctionDeclaration,
|
|
6022
|
+
AST_NODE_TYPES31.FunctionExpression,
|
|
6023
|
+
AST_NODE_TYPES31.ArrowFunctionExpression
|
|
5990
6024
|
]);
|
|
5991
6025
|
var PURE_METHODS = /* @__PURE__ */ new Set([
|
|
5992
6026
|
"map",
|
|
@@ -6086,30 +6120,30 @@ var PURE_CONSTRUCTORS = /* @__PURE__ */ new Set([
|
|
|
6086
6120
|
]);
|
|
6087
6121
|
function isPureCall(node) {
|
|
6088
6122
|
const callee = node.callee;
|
|
6089
|
-
if (callee.type !==
|
|
6123
|
+
if (callee.type !== AST_NODE_TYPES31.MemberExpression) {
|
|
6090
6124
|
return false;
|
|
6091
6125
|
}
|
|
6092
6126
|
const property = callee.property;
|
|
6093
|
-
if (property.type !==
|
|
6127
|
+
if (property.type !== AST_NODE_TYPES31.Identifier) {
|
|
6094
6128
|
return false;
|
|
6095
6129
|
}
|
|
6096
|
-
if (callee.object.type ===
|
|
6130
|
+
if (callee.object.type === AST_NODE_TYPES31.Identifier && PURE_NAMESPACES.has(callee.object.name)) {
|
|
6097
6131
|
return !IMPURE_NAMESPACE_METHODS.has(`${callee.object.name}.${property.name}`);
|
|
6098
6132
|
}
|
|
6099
6133
|
return PURE_METHODS.has(property.name) && (!SYNC_CALLBACK_METHODS.has(property.name) || !synchronousCallbackCanThrow(node));
|
|
6100
6134
|
}
|
|
6101
6135
|
function synchronousCallbackCanThrow(node) {
|
|
6102
6136
|
return node.arguments.some((argument) => {
|
|
6103
|
-
if (argument.type !==
|
|
6137
|
+
if (argument.type !== AST_NODE_TYPES31.ArrowFunctionExpression && argument.type !== AST_NODE_TYPES31.FunctionExpression) return false;
|
|
6104
6138
|
if (argument.async) return false;
|
|
6105
6139
|
return subtreeMatches(
|
|
6106
6140
|
argument.body,
|
|
6107
|
-
(current) => current.type ===
|
|
6141
|
+
(current) => current.type === AST_NODE_TYPES31.ThrowStatement || current.type === AST_NODE_TYPES31.CallExpression && current.callee.type === AST_NODE_TYPES31.MemberExpression && !current.callee.computed && current.callee.object.type === AST_NODE_TYPES31.Identifier && current.callee.object.name === "JSON" && current.callee.property.type === AST_NODE_TYPES31.Identifier && current.callee.property.name === "parse"
|
|
6108
6142
|
);
|
|
6109
6143
|
});
|
|
6110
6144
|
}
|
|
6111
6145
|
function isPureNew(node) {
|
|
6112
|
-
return node.callee.type ===
|
|
6146
|
+
return node.callee.type === AST_NODE_TYPES31.Identifier && PURE_CONSTRUCTORS.has(node.callee.name);
|
|
6113
6147
|
}
|
|
6114
6148
|
function subtreeMatches(stmt, predicate, descendIntoFunctions = false) {
|
|
6115
6149
|
let found = false;
|
|
@@ -6128,7 +6162,7 @@ function subtreeMatches(stmt, predicate, descendIntoFunctions = false) {
|
|
|
6128
6162
|
}
|
|
6129
6163
|
function unwrap(expr) {
|
|
6130
6164
|
let current = expr;
|
|
6131
|
-
while (current.type ===
|
|
6165
|
+
while (current.type === AST_NODE_TYPES31.ChainExpression || current.type === AST_NODE_TYPES31.TSNonNullExpression) {
|
|
6132
6166
|
current = current.expression;
|
|
6133
6167
|
}
|
|
6134
6168
|
return current;
|
|
@@ -6140,21 +6174,21 @@ function canThrow(stmt) {
|
|
|
6140
6174
|
if (isBareCallStatement(stmt)) {
|
|
6141
6175
|
return false;
|
|
6142
6176
|
}
|
|
6143
|
-
if (stmt.type ===
|
|
6177
|
+
if (stmt.type === AST_NODE_TYPES31.BlockStatement) {
|
|
6144
6178
|
return stmt.body.some(canThrow);
|
|
6145
6179
|
}
|
|
6146
|
-
if (stmt.type ===
|
|
6180
|
+
if (stmt.type === AST_NODE_TYPES31.IfStatement) {
|
|
6147
6181
|
return hasThrowingCallOrNew(stmt.test) || canThrow(stmt.consequent) || stmt.alternate !== null && canThrow(stmt.alternate);
|
|
6148
6182
|
}
|
|
6149
6183
|
return hasThrowingCallOrNew(stmt);
|
|
6150
6184
|
}
|
|
6151
|
-
var hasAwait = (node) => subtreeMatches(node, (n) => n.type ===
|
|
6185
|
+
var hasAwait = (node) => subtreeMatches(node, (n) => n.type === AST_NODE_TYPES31.AwaitExpression);
|
|
6152
6186
|
var hasThrowingCallOrNew = (node) => subtreeMatches(
|
|
6153
6187
|
node,
|
|
6154
|
-
(n) => n.type ===
|
|
6188
|
+
(n) => n.type === AST_NODE_TYPES31.CallExpression && !isPureCall(n) || n.type === AST_NODE_TYPES31.NewExpression && !isPureNew(n)
|
|
6155
6189
|
);
|
|
6156
6190
|
function isBareCallStatement(stmt) {
|
|
6157
|
-
return stmt.type ===
|
|
6191
|
+
return stmt.type === AST_NODE_TYPES31.ExpressionStatement && unwrap(stmt.expression).type === AST_NODE_TYPES31.CallExpression;
|
|
6158
6192
|
}
|
|
6159
6193
|
function isSimpleCatchFinallyOrchestration(node) {
|
|
6160
6194
|
const handler = node.handler;
|
|
@@ -6171,7 +6205,7 @@ function isSimpleBareCallStatement(stmt) {
|
|
|
6171
6205
|
}
|
|
6172
6206
|
return !subtreeMatches(
|
|
6173
6207
|
stmt,
|
|
6174
|
-
(node) => node.type ===
|
|
6208
|
+
(node) => node.type === AST_NODE_TYPES31.ArrowFunctionExpression || node.type === AST_NODE_TYPES31.FunctionExpression || node.type === AST_NODE_TYPES31.AssignmentExpression || node.type === AST_NODE_TYPES31.UpdateExpression || node.type === AST_NODE_TYPES31.AwaitExpression,
|
|
6175
6209
|
true
|
|
6176
6210
|
);
|
|
6177
6211
|
}
|
|
@@ -6181,42 +6215,42 @@ function handlerRethrows(handler) {
|
|
|
6181
6215
|
}
|
|
6182
6216
|
const body2 = handler.body.body;
|
|
6183
6217
|
const last = body2[body2.length - 1];
|
|
6184
|
-
return last !== void 0 && last.type ===
|
|
6218
|
+
return last !== void 0 && last.type === AST_NODE_TYPES31.ThrowStatement;
|
|
6185
6219
|
}
|
|
6186
6220
|
var PASS_THROUGH_PARENTS = /* @__PURE__ */ new Set([
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
|
|
6221
|
+
AST_NODE_TYPES31.IfStatement,
|
|
6222
|
+
AST_NODE_TYPES31.TryStatement,
|
|
6223
|
+
AST_NODE_TYPES31.CatchClause,
|
|
6224
|
+
AST_NODE_TYPES31.LabeledStatement
|
|
6191
6225
|
]);
|
|
6192
6226
|
function isPropertyName(node) {
|
|
6193
6227
|
const parent = node.parent;
|
|
6194
|
-
if (parent.type ===
|
|
6228
|
+
if (parent.type === AST_NODE_TYPES31.MemberExpression) {
|
|
6195
6229
|
return parent.property === node && !parent.computed;
|
|
6196
6230
|
}
|
|
6197
|
-
if (parent.type ===
|
|
6231
|
+
if (parent.type === AST_NODE_TYPES31.Property) {
|
|
6198
6232
|
return parent.key === node && !parent.computed;
|
|
6199
6233
|
}
|
|
6200
6234
|
return false;
|
|
6201
6235
|
}
|
|
6202
6236
|
function isSuccessShapedValue(expr) {
|
|
6203
6237
|
let current = expr;
|
|
6204
|
-
while (current.type ===
|
|
6238
|
+
while (current.type === AST_NODE_TYPES31.TSAsExpression || current.type === AST_NODE_TYPES31.TSNonNullExpression) {
|
|
6205
6239
|
current = current.expression;
|
|
6206
6240
|
}
|
|
6207
|
-
if (current.type ===
|
|
6241
|
+
if (current.type === AST_NODE_TYPES31.Literal) {
|
|
6208
6242
|
return current.value === null || current.value === false;
|
|
6209
6243
|
}
|
|
6210
|
-
if (current.type ===
|
|
6244
|
+
if (current.type === AST_NODE_TYPES31.Identifier) {
|
|
6211
6245
|
return current.name === "undefined";
|
|
6212
6246
|
}
|
|
6213
|
-
if (current.type ===
|
|
6247
|
+
if (current.type === AST_NODE_TYPES31.UnaryExpression) {
|
|
6214
6248
|
return current.operator === "void";
|
|
6215
6249
|
}
|
|
6216
|
-
if (current.type ===
|
|
6250
|
+
if (current.type === AST_NODE_TYPES31.ArrayExpression) {
|
|
6217
6251
|
return current.elements.length === 0;
|
|
6218
6252
|
}
|
|
6219
|
-
if (current.type ===
|
|
6253
|
+
if (current.type === AST_NODE_TYPES31.ObjectExpression) {
|
|
6220
6254
|
return current.properties.length === 0;
|
|
6221
6255
|
}
|
|
6222
6256
|
return false;
|
|
@@ -6229,11 +6263,11 @@ function isTerminalInFunction(node) {
|
|
|
6229
6263
|
let current = node;
|
|
6230
6264
|
let parent = current.parent;
|
|
6231
6265
|
while (parent !== void 0) {
|
|
6232
|
-
if (parent.type ===
|
|
6266
|
+
if (parent.type === AST_NODE_TYPES31.BlockStatement) {
|
|
6233
6267
|
if (parent.body[parent.body.length - 1] !== current) {
|
|
6234
6268
|
return false;
|
|
6235
6269
|
}
|
|
6236
|
-
} else if (parent.type ===
|
|
6270
|
+
} else if (parent.type === AST_NODE_TYPES31.Program) {
|
|
6237
6271
|
return parent.body[parent.body.length - 1] === current;
|
|
6238
6272
|
} else if (NESTED_FUNCTION_TYPES.has(parent.type)) {
|
|
6239
6273
|
return true;
|
|
@@ -6251,14 +6285,14 @@ function handlerEndsByHandingOff(handler) {
|
|
|
6251
6285
|
if (last === void 0) {
|
|
6252
6286
|
return false;
|
|
6253
6287
|
}
|
|
6254
|
-
if (last.type ===
|
|
6288
|
+
if (last.type === AST_NODE_TYPES31.ReturnStatement || last.type === AST_NODE_TYPES31.ThrowStatement) {
|
|
6255
6289
|
return true;
|
|
6256
6290
|
}
|
|
6257
|
-
return last.type ===
|
|
6291
|
+
return last.type === AST_NODE_TYPES31.ExpressionStatement && unwrapAwait(last.expression).type === AST_NODE_TYPES31.CallExpression;
|
|
6258
6292
|
}
|
|
6259
6293
|
function unwrapAwait(expr) {
|
|
6260
6294
|
const inner = unwrap(expr);
|
|
6261
|
-
return inner.type ===
|
|
6295
|
+
return inner.type === AST_NODE_TYPES31.AwaitExpression ? unwrap(inner.argument) : inner;
|
|
6262
6296
|
}
|
|
6263
6297
|
function handlerMentionsCaughtBinding(handler) {
|
|
6264
6298
|
const names = caughtBindingNames(handler);
|
|
@@ -6267,7 +6301,7 @@ function handlerMentionsCaughtBinding(handler) {
|
|
|
6267
6301
|
}
|
|
6268
6302
|
return subtreeMatches(
|
|
6269
6303
|
handler.body,
|
|
6270
|
-
(n) => n.type ===
|
|
6304
|
+
(n) => n.type === AST_NODE_TYPES31.Identifier && names.has(n.name) && !isPropertyName(n),
|
|
6271
6305
|
true
|
|
6272
6306
|
);
|
|
6273
6307
|
}
|
|
@@ -6279,20 +6313,20 @@ function caughtBindingNames(handler) {
|
|
|
6279
6313
|
return names;
|
|
6280
6314
|
}
|
|
6281
6315
|
function collectBindingNames(pattern, names) {
|
|
6282
|
-
if (pattern.type ===
|
|
6316
|
+
if (pattern.type === AST_NODE_TYPES31.Identifier) {
|
|
6283
6317
|
names.add(pattern.name);
|
|
6284
6318
|
return;
|
|
6285
6319
|
}
|
|
6286
|
-
if (pattern.type ===
|
|
6320
|
+
if (pattern.type === AST_NODE_TYPES31.ObjectPattern) {
|
|
6287
6321
|
for (const property of pattern.properties) {
|
|
6288
6322
|
collectBindingNames(
|
|
6289
|
-
property.type ===
|
|
6323
|
+
property.type === AST_NODE_TYPES31.RestElement ? property.argument : property.value,
|
|
6290
6324
|
names
|
|
6291
6325
|
);
|
|
6292
6326
|
}
|
|
6293
6327
|
return;
|
|
6294
6328
|
}
|
|
6295
|
-
if (pattern.type ===
|
|
6329
|
+
if (pattern.type === AST_NODE_TYPES31.ArrayPattern) {
|
|
6296
6330
|
for (const element of pattern.elements) {
|
|
6297
6331
|
if (element !== null) {
|
|
6298
6332
|
collectBindingNames(element, names);
|
|
@@ -6300,16 +6334,16 @@ function collectBindingNames(pattern, names) {
|
|
|
6300
6334
|
}
|
|
6301
6335
|
return;
|
|
6302
6336
|
}
|
|
6303
|
-
if (pattern.type ===
|
|
6337
|
+
if (pattern.type === AST_NODE_TYPES31.AssignmentPattern || pattern.type === AST_NODE_TYPES31.RestElement) {
|
|
6304
6338
|
collectBindingNames(
|
|
6305
|
-
pattern.type ===
|
|
6339
|
+
pattern.type === AST_NODE_TYPES31.AssignmentPattern ? pattern.left : pattern.argument,
|
|
6306
6340
|
names
|
|
6307
6341
|
);
|
|
6308
6342
|
}
|
|
6309
6343
|
}
|
|
6310
6344
|
var handlerReturnsSuccessShaped = (handler) => subtreeMatches(
|
|
6311
6345
|
handler.body,
|
|
6312
|
-
(n) => n.type ===
|
|
6346
|
+
(n) => n.type === AST_NODE_TYPES31.ReturnStatement && n.argument !== null && isSuccessShapedValue(n.argument)
|
|
6313
6347
|
);
|
|
6314
6348
|
var no_fat_try_blocks_default = createRule({
|
|
6315
6349
|
name: "no-fat-try-blocks",
|
|
@@ -6369,7 +6403,7 @@ var no_fat_try_blocks_default = createRule({
|
|
|
6369
6403
|
});
|
|
6370
6404
|
|
|
6371
6405
|
// src/rules/no-hand-rolled-sleep.ts
|
|
6372
|
-
import { AST_NODE_TYPES as
|
|
6406
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES32, ASTUtils as ASTUtils12 } from "@typescript-eslint/utils";
|
|
6373
6407
|
var NO_HAND_ROLLED_SLEEP_DOCUMENTATION = {
|
|
6374
6408
|
summary: "Disallow uncancellable promisified timers and timeout arms.",
|
|
6375
6409
|
rationale: "A timer that outlives an aborted operation or a lost promise race retains work and can keep the process alive until it fires.",
|
|
@@ -6422,71 +6456,71 @@ function matchesAnyPattern2(filename, patterns) {
|
|
|
6422
6456
|
}
|
|
6423
6457
|
function isSetTimeoutCallee(callee) {
|
|
6424
6458
|
callee = unwrapExpression(callee);
|
|
6425
|
-
if (callee.type ===
|
|
6459
|
+
if (callee.type === AST_NODE_TYPES32.Identifier) {
|
|
6426
6460
|
return callee.name === "setTimeout";
|
|
6427
6461
|
}
|
|
6428
|
-
return callee.type ===
|
|
6462
|
+
return callee.type === AST_NODE_TYPES32.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES32.Identifier && callee.property.name === "setTimeout" && callee.object.type === AST_NODE_TYPES32.Identifier && GLOBAL_OBJECTS.has(callee.object.name);
|
|
6429
6463
|
}
|
|
6430
6464
|
function soleCall(fn) {
|
|
6431
|
-
if (fn.body.type !==
|
|
6465
|
+
if (fn.body.type !== AST_NODE_TYPES32.BlockStatement) {
|
|
6432
6466
|
const body2 = unwrapExpression(fn.body);
|
|
6433
|
-
return body2.type ===
|
|
6467
|
+
return body2.type === AST_NODE_TYPES32.CallExpression ? body2 : null;
|
|
6434
6468
|
}
|
|
6435
6469
|
if (fn.body.body.length !== 1) {
|
|
6436
6470
|
return null;
|
|
6437
6471
|
}
|
|
6438
6472
|
const [only] = fn.body.body;
|
|
6439
|
-
if (only?.type !==
|
|
6473
|
+
if (only?.type !== AST_NODE_TYPES32.ExpressionStatement) {
|
|
6440
6474
|
return null;
|
|
6441
6475
|
}
|
|
6442
6476
|
const expression = unwrapExpression(only.expression);
|
|
6443
|
-
return expression.type ===
|
|
6477
|
+
return expression.type === AST_NODE_TYPES32.CallExpression ? expression : null;
|
|
6444
6478
|
}
|
|
6445
6479
|
function isTimedDelay(delay) {
|
|
6446
6480
|
if (delay === void 0) {
|
|
6447
6481
|
return false;
|
|
6448
6482
|
}
|
|
6449
6483
|
delay = unwrapExpression(delay);
|
|
6450
|
-
if (delay.type ===
|
|
6484
|
+
if (delay.type === AST_NODE_TYPES32.Literal && typeof delay.value === "number") {
|
|
6451
6485
|
return delay.value !== 0;
|
|
6452
6486
|
}
|
|
6453
6487
|
return true;
|
|
6454
6488
|
}
|
|
6455
6489
|
function settlesWithoutValue(callback, name) {
|
|
6456
6490
|
callback = unwrapExpression(callback);
|
|
6457
|
-
if (callback.type ===
|
|
6491
|
+
if (callback.type === AST_NODE_TYPES32.Identifier) {
|
|
6458
6492
|
return callback.name === name;
|
|
6459
6493
|
}
|
|
6460
|
-
if (callback.type !==
|
|
6494
|
+
if (callback.type !== AST_NODE_TYPES32.ArrowFunctionExpression && callback.type !== AST_NODE_TYPES32.FunctionExpression) {
|
|
6461
6495
|
return false;
|
|
6462
6496
|
}
|
|
6463
6497
|
const call = soleCall(callback);
|
|
6464
6498
|
const callee = call === null ? null : unwrapExpression(call.callee);
|
|
6465
|
-
return call !== null && call.arguments.length === 0 && callee?.type ===
|
|
6499
|
+
return call !== null && call.arguments.length === 0 && callee?.type === AST_NODE_TYPES32.Identifier && callee.name === name;
|
|
6466
6500
|
}
|
|
6467
6501
|
function rejectsInCallback(callback, name) {
|
|
6468
6502
|
callback = unwrapExpression(callback);
|
|
6469
|
-
if (callback.type ===
|
|
6503
|
+
if (callback.type === AST_NODE_TYPES32.Identifier) {
|
|
6470
6504
|
return callback.name === name;
|
|
6471
6505
|
}
|
|
6472
|
-
if (callback.type !==
|
|
6506
|
+
if (callback.type !== AST_NODE_TYPES32.ArrowFunctionExpression && callback.type !== AST_NODE_TYPES32.FunctionExpression) {
|
|
6473
6507
|
return false;
|
|
6474
6508
|
}
|
|
6475
6509
|
const call = soleCall(callback);
|
|
6476
6510
|
const callee = call === null ? null : unwrapExpression(call.callee);
|
|
6477
|
-
return call !== null && callee?.type ===
|
|
6511
|
+
return call !== null && callee?.type === AST_NODE_TYPES32.Identifier && callee.name === name;
|
|
6478
6512
|
}
|
|
6479
6513
|
function parameterName(fn, index) {
|
|
6480
6514
|
const parameter = fn.params[index];
|
|
6481
|
-
return parameter?.type ===
|
|
6515
|
+
return parameter?.type === AST_NODE_TYPES32.Identifier ? parameter.name : null;
|
|
6482
6516
|
}
|
|
6483
6517
|
function isRaceArm(node) {
|
|
6484
6518
|
const array = node.parent;
|
|
6485
|
-
if (array?.type !==
|
|
6519
|
+
if (array?.type !== AST_NODE_TYPES32.ArrayExpression) {
|
|
6486
6520
|
return false;
|
|
6487
6521
|
}
|
|
6488
6522
|
const call = array.parent;
|
|
6489
|
-
return call?.type ===
|
|
6523
|
+
return call?.type === AST_NODE_TYPES32.CallExpression && call.arguments[0] === array && call.callee.type === AST_NODE_TYPES32.MemberExpression && !call.callee.computed && call.callee.object.type === AST_NODE_TYPES32.Identifier && call.callee.object.name === "Promise" && call.callee.property.type === AST_NODE_TYPES32.Identifier && RACE_METHODS.has(call.callee.property.name);
|
|
6490
6524
|
}
|
|
6491
6525
|
var no_hand_rolled_sleep_default = createRule({
|
|
6492
6526
|
name: "no-hand-rolled-sleep",
|
|
@@ -6534,17 +6568,17 @@ var no_hand_rolled_sleep_default = createRule({
|
|
|
6534
6568
|
const isBuiltinTimer = (callee) => {
|
|
6535
6569
|
callee = unwrapExpression(callee);
|
|
6536
6570
|
if (!isSetTimeoutCallee(callee)) return false;
|
|
6537
|
-
if (callee.type ===
|
|
6538
|
-
if (callee.type !==
|
|
6571
|
+
if (callee.type === AST_NODE_TYPES32.MemberExpression && callee.object.type === AST_NODE_TYPES32.Identifier) return isGlobal(callee.object);
|
|
6572
|
+
if (callee.type !== AST_NODE_TYPES32.Identifier) return false;
|
|
6539
6573
|
const binding = bindingOf(callee);
|
|
6540
|
-
return binding === null || binding.defs.length === 0 || binding.defs.every((definition) => definition.node.type ===
|
|
6574
|
+
return binding === null || binding.defs.length === 0 || binding.defs.every((definition) => definition.node.type === AST_NODE_TYPES32.ImportSpecifier && definition.node.imported.type === AST_NODE_TYPES32.Identifier && definition.node.imported.name === "setTimeout" && definition.node.parent.type === AST_NODE_TYPES32.ImportDeclaration && ["node:timers", "timers"].includes(String(definition.node.parent.source.value)));
|
|
6541
6575
|
};
|
|
6542
6576
|
const settlesParameter = (callback, executor, index) => {
|
|
6543
6577
|
callback = unwrapExpression(callback);
|
|
6544
6578
|
const parameter = executor.params[index];
|
|
6545
|
-
if (parameter?.type !==
|
|
6546
|
-
const callee = callback.type ===
|
|
6547
|
-
return callee?.type ===
|
|
6579
|
+
if (parameter?.type !== AST_NODE_TYPES32.Identifier) return false;
|
|
6580
|
+
const callee = callback.type === AST_NODE_TYPES32.Identifier ? callback : callback.type === AST_NODE_TYPES32.ArrowFunctionExpression || callback.type === AST_NODE_TYPES32.FunctionExpression ? soleCall(callback)?.callee : null;
|
|
6581
|
+
return callee?.type === AST_NODE_TYPES32.Identifier && bindingOf(callee) === bindingOf(parameter);
|
|
6548
6582
|
};
|
|
6549
6583
|
let clientModule = null;
|
|
6550
6584
|
const reportsSleepHere = () => {
|
|
@@ -6560,10 +6594,10 @@ var no_hand_rolled_sleep_default = createRule({
|
|
|
6560
6594
|
}
|
|
6561
6595
|
const program = sourceCode.ast;
|
|
6562
6596
|
for (const statement of program.body) {
|
|
6563
|
-
if (statement.type ===
|
|
6597
|
+
if (statement.type === AST_NODE_TYPES32.ExpressionStatement && statement.expression.type === AST_NODE_TYPES32.Literal && statement.expression.value === "use client") {
|
|
6564
6598
|
return true;
|
|
6565
6599
|
}
|
|
6566
|
-
if (statement.type ===
|
|
6600
|
+
if (statement.type === AST_NODE_TYPES32.ImportDeclaration && typeof statement.source.value === "string" && CLIENT_ONLY_MODULES.test(statement.source.value)) {
|
|
6567
6601
|
return true;
|
|
6568
6602
|
}
|
|
6569
6603
|
}
|
|
@@ -6572,11 +6606,11 @@ var no_hand_rolled_sleep_default = createRule({
|
|
|
6572
6606
|
return {
|
|
6573
6607
|
NewExpression(node) {
|
|
6574
6608
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
6575
|
-
if (unwrappedNodeCallee?.type !==
|
|
6609
|
+
if (unwrappedNodeCallee?.type !== AST_NODE_TYPES32.Identifier || unwrappedNodeCallee.name !== "Promise" || !isGlobal(unwrappedNodeCallee)) {
|
|
6576
6610
|
return;
|
|
6577
6611
|
}
|
|
6578
6612
|
const executor = node.arguments[0];
|
|
6579
|
-
if (executor?.type !==
|
|
6613
|
+
if (executor?.type !== AST_NODE_TYPES32.ArrowFunctionExpression && executor?.type !== AST_NODE_TYPES32.FunctionExpression) {
|
|
6580
6614
|
return;
|
|
6581
6615
|
}
|
|
6582
6616
|
const call = soleCall(executor);
|
|
@@ -6604,7 +6638,7 @@ var no_hand_rolled_sleep_default = createRule({
|
|
|
6604
6638
|
});
|
|
6605
6639
|
|
|
6606
6640
|
// src/rules/no-hand-rolled-spinner.ts
|
|
6607
|
-
import { AST_NODE_TYPES as
|
|
6641
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES33 } from "@typescript-eslint/utils";
|
|
6608
6642
|
var NO_HAND_ROLLED_SPINNER_DOCUMENTATION = {
|
|
6609
6643
|
summary: "Disallow intrinsic elements styled as Tailwind border-ring spinners outside the design-system implementation.",
|
|
6610
6644
|
rationale: "One-off loading indicators duplicate a shared primitive and let accessibility and styling diverge.",
|
|
@@ -6642,13 +6676,13 @@ function hasSpinnerInVariant(classes, variant) {
|
|
|
6642
6676
|
}
|
|
6643
6677
|
function staticClassName(attribute) {
|
|
6644
6678
|
const value = attribute.value;
|
|
6645
|
-
if (value?.type ===
|
|
6679
|
+
if (value?.type === AST_NODE_TYPES33.Literal && typeof value.value === "string") {
|
|
6646
6680
|
return value.value;
|
|
6647
6681
|
}
|
|
6648
|
-
if (value?.type ===
|
|
6682
|
+
if (value?.type === AST_NODE_TYPES33.JSXExpressionContainer && value.expression.type === AST_NODE_TYPES33.Literal && typeof value.expression.value === "string") {
|
|
6649
6683
|
return value.expression.value;
|
|
6650
6684
|
}
|
|
6651
|
-
if (value?.type ===
|
|
6685
|
+
if (value?.type === AST_NODE_TYPES33.JSXExpressionContainer && value.expression.type === AST_NODE_TYPES33.TemplateLiteral && value.expression.expressions.length === 0) {
|
|
6652
6686
|
return value.expression.quasis[0]?.value.cooked ?? null;
|
|
6653
6687
|
}
|
|
6654
6688
|
return null;
|
|
@@ -6673,13 +6707,13 @@ var no_hand_rolled_spinner_default = createRule({
|
|
|
6673
6707
|
}
|
|
6674
6708
|
return {
|
|
6675
6709
|
JSXOpeningElement(node) {
|
|
6676
|
-
if (node.name.type !==
|
|
6710
|
+
if (node.name.type !== AST_NODE_TYPES33.JSXIdentifier || node.name.name !== "div" && node.name.name !== "span") {
|
|
6677
6711
|
return;
|
|
6678
6712
|
}
|
|
6679
6713
|
const classNameAttribute = node.attributes.toReversed().find(
|
|
6680
|
-
(attribute) => attribute.type ===
|
|
6714
|
+
(attribute) => attribute.type === AST_NODE_TYPES33.JSXSpreadAttribute || attribute.type === AST_NODE_TYPES33.JSXAttribute && attribute.name.type === AST_NODE_TYPES33.JSXIdentifier && attribute.name.name === "className"
|
|
6681
6715
|
);
|
|
6682
|
-
if (classNameAttribute?.type !==
|
|
6716
|
+
if (classNameAttribute?.type !== AST_NODE_TYPES33.JSXAttribute) return;
|
|
6683
6717
|
const className = staticClassName(classNameAttribute);
|
|
6684
6718
|
if (className === null) return;
|
|
6685
6719
|
const classes = className.split(/\s+/u).filter(Boolean).map((token) => ({
|
|
@@ -6922,7 +6956,7 @@ function appendDirectBindingName(id, directBinding, names) {
|
|
|
6922
6956
|
|
|
6923
6957
|
// src/rules/no-detached-global-fetch.ts
|
|
6924
6958
|
import {
|
|
6925
|
-
AST_NODE_TYPES as
|
|
6959
|
+
AST_NODE_TYPES as AST_NODE_TYPES34,
|
|
6926
6960
|
ASTUtils as ASTUtils14
|
|
6927
6961
|
} from "@typescript-eslint/utils";
|
|
6928
6962
|
var NO_DETACHED_GLOBAL_FETCH_DOCUMENTATION = {
|
|
@@ -6962,7 +6996,7 @@ var EXPLICIT_RECEIVER_METHODS = /* @__PURE__ */ new Set(["apply", "bind", "call"
|
|
|
6962
6996
|
var STORAGE_ASSIGNMENT_OPERATORS2 = /* @__PURE__ */ new Set(["=", "&&=", "??=", "||="]);
|
|
6963
6997
|
function unwrapExpression2(node) {
|
|
6964
6998
|
let current = node;
|
|
6965
|
-
while (current.type ===
|
|
6999
|
+
while (current.type === AST_NODE_TYPES34.ChainExpression || current.type === AST_NODE_TYPES34.TSAsExpression || current.type === AST_NODE_TYPES34.TSNonNullExpression || current.type === AST_NODE_TYPES34.TSTypeAssertion) {
|
|
6966
7000
|
current = current.expression;
|
|
6967
7001
|
}
|
|
6968
7002
|
return current;
|
|
@@ -6991,7 +7025,7 @@ var no_detached_global_fetch_default = createRule({
|
|
|
6991
7025
|
return variable === null || variable.defs.length === 0;
|
|
6992
7026
|
}
|
|
6993
7027
|
function isGlobalReceiver(node) {
|
|
6994
|
-
return node.type ===
|
|
7028
|
+
return node.type === AST_NODE_TYPES34.Identifier && GLOBAL_RECEIVERS.has(node.name) && resolvesToGlobal(node);
|
|
6995
7029
|
}
|
|
6996
7030
|
function isStableAlias(variable) {
|
|
6997
7031
|
return !variable.references.some(
|
|
@@ -7004,27 +7038,27 @@ var no_detached_global_fetch_default = createRule({
|
|
|
7004
7038
|
}
|
|
7005
7039
|
function staticMemberName7(node) {
|
|
7006
7040
|
if (!node.computed) {
|
|
7007
|
-
return node.property.type ===
|
|
7041
|
+
return node.property.type === AST_NODE_TYPES34.Identifier ? node.property.name : null;
|
|
7008
7042
|
}
|
|
7009
|
-
return node.property.type ===
|
|
7043
|
+
return node.property.type === AST_NODE_TYPES34.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
7010
7044
|
}
|
|
7011
7045
|
function mayBeRawFetch(node) {
|
|
7012
7046
|
const expression = unwrapExpression2(node);
|
|
7013
|
-
if (expression.type ===
|
|
7047
|
+
if (expression.type === AST_NODE_TYPES34.Identifier) {
|
|
7014
7048
|
if (expression.name === "fetch" && resolvesToGlobal(expression)) return true;
|
|
7015
7049
|
const variable = bindingOf(expression);
|
|
7016
7050
|
return variable !== null && aliases.has(variable) && isStableAlias(variable);
|
|
7017
7051
|
}
|
|
7018
|
-
if (expression.type ===
|
|
7052
|
+
if (expression.type === AST_NODE_TYPES34.MemberExpression) {
|
|
7019
7053
|
return isGlobalFetchMember(expression);
|
|
7020
7054
|
}
|
|
7021
|
-
if (expression.type ===
|
|
7055
|
+
if (expression.type === AST_NODE_TYPES34.LogicalExpression) {
|
|
7022
7056
|
return expression.operator === "&&" ? mayBeRawFetch(expression.right) : mayBeRawFetch(expression.left) || mayBeRawFetch(expression.right);
|
|
7023
7057
|
}
|
|
7024
|
-
if (expression.type ===
|
|
7058
|
+
if (expression.type === AST_NODE_TYPES34.ConditionalExpression) {
|
|
7025
7059
|
return mayBeRawFetch(expression.consequent) || mayBeRawFetch(expression.alternate);
|
|
7026
7060
|
}
|
|
7027
|
-
if (expression.type ===
|
|
7061
|
+
if (expression.type === AST_NODE_TYPES34.SequenceExpression) {
|
|
7028
7062
|
const last = expression.expressions.at(-1);
|
|
7029
7063
|
return last !== void 0 && mayBeRawFetch(last);
|
|
7030
7064
|
}
|
|
@@ -7033,9 +7067,9 @@ var no_detached_global_fetch_default = createRule({
|
|
|
7033
7067
|
function isGlobalFetchMember(node) {
|
|
7034
7068
|
if (!isGlobalReceiver(node.object)) return false;
|
|
7035
7069
|
if (!node.computed) {
|
|
7036
|
-
return node.property.type ===
|
|
7070
|
+
return node.property.type === AST_NODE_TYPES34.Identifier && node.property.name === "fetch";
|
|
7037
7071
|
}
|
|
7038
|
-
return node.property.type ===
|
|
7072
|
+
return node.property.type === AST_NODE_TYPES34.Literal && node.property.value === "fetch";
|
|
7039
7073
|
}
|
|
7040
7074
|
function recordAliasFromValue(identifier, value) {
|
|
7041
7075
|
if (mayBeRawFetch(value)) recordAlias(identifier);
|
|
@@ -7044,28 +7078,28 @@ var no_detached_global_fetch_default = createRule({
|
|
|
7044
7078
|
if (mayBeRawFetch(node)) context.report({ node, messageId: "detachedGlobalFetch" });
|
|
7045
7079
|
}
|
|
7046
7080
|
function isCompatibleReceiver(node) {
|
|
7047
|
-
if (node === void 0 || node.type ===
|
|
7048
|
-
if (node.type !==
|
|
7081
|
+
if (node === void 0 || node.type === AST_NODE_TYPES34.SpreadElement) return false;
|
|
7082
|
+
if (node.type !== AST_NODE_TYPES34.Identifier || !resolvesToGlobal(node)) return false;
|
|
7049
7083
|
return GLOBAL_RECEIVERS.has(node.name) || node.name === "undefined";
|
|
7050
7084
|
}
|
|
7051
7085
|
return {
|
|
7052
7086
|
AssignmentExpression(node) {
|
|
7053
|
-
if (STORAGE_ASSIGNMENT_OPERATORS2.has(node.operator) && node.left.type ===
|
|
7087
|
+
if (STORAGE_ASSIGNMENT_OPERATORS2.has(node.operator) && node.left.type === AST_NODE_TYPES34.MemberExpression) {
|
|
7054
7088
|
reportStored(node.right);
|
|
7055
7089
|
}
|
|
7056
7090
|
},
|
|
7057
7091
|
AssignmentPattern(node) {
|
|
7058
|
-
if (node.left.type !==
|
|
7092
|
+
if (node.left.type !== AST_NODE_TYPES34.Identifier) return;
|
|
7059
7093
|
recordAliasFromValue(node.left, node.right);
|
|
7060
|
-
if (node.parent.type ===
|
|
7094
|
+
if (node.parent.type === AST_NODE_TYPES34.TSParameterProperty) reportStored(node.right);
|
|
7061
7095
|
},
|
|
7062
7096
|
CallExpression(node) {
|
|
7063
7097
|
const callee = unwrapExpression2(node.callee);
|
|
7064
|
-
if (callee.type !==
|
|
7098
|
+
if (callee.type !== AST_NODE_TYPES34.MemberExpression || !EXPLICIT_RECEIVER_METHODS.has(staticMemberName7(callee) ?? "") || !mayBeRawFetch(callee.object) || isCompatibleReceiver(node.arguments[0])) return;
|
|
7065
7099
|
context.report({ node: callee.object, messageId: "detachedGlobalFetch" });
|
|
7066
7100
|
},
|
|
7067
7101
|
Property(node) {
|
|
7068
|
-
if (node.parent.type ===
|
|
7102
|
+
if (node.parent.type === AST_NODE_TYPES34.ObjectPattern || node.method || node.value.type === AST_NODE_TYPES34.AssignmentPattern || node.value.type === AST_NODE_TYPES34.TSEmptyBodyFunctionExpression) return;
|
|
7069
7103
|
reportStored(node.value);
|
|
7070
7104
|
},
|
|
7071
7105
|
PropertyDefinition(node) {
|
|
@@ -7073,15 +7107,237 @@ var no_detached_global_fetch_default = createRule({
|
|
|
7073
7107
|
},
|
|
7074
7108
|
VariableDeclarator(node) {
|
|
7075
7109
|
if (node.init === null) return;
|
|
7076
|
-
if (node.id.type ===
|
|
7110
|
+
if (node.id.type === AST_NODE_TYPES34.Identifier) {
|
|
7077
7111
|
recordAliasFromValue(node.id, node.init);
|
|
7078
7112
|
return;
|
|
7079
7113
|
}
|
|
7080
|
-
if (node.id.type !==
|
|
7114
|
+
if (node.id.type !== AST_NODE_TYPES34.ObjectPattern || !isGlobalReceiver(unwrapExpression2(node.init))) return;
|
|
7081
7115
|
for (const property of node.id.properties) {
|
|
7082
|
-
if (property.type !==
|
|
7083
|
-
const value = property.value.type ===
|
|
7084
|
-
if (value.type ===
|
|
7116
|
+
if (property.type !== AST_NODE_TYPES34.Property || property.computed || property.key.type !== AST_NODE_TYPES34.Identifier || property.key.name !== "fetch") continue;
|
|
7117
|
+
const value = property.value.type === AST_NODE_TYPES34.AssignmentPattern ? property.value.left : property.value;
|
|
7118
|
+
if (value.type === AST_NODE_TYPES34.Identifier) recordAlias(value);
|
|
7119
|
+
}
|
|
7120
|
+
}
|
|
7121
|
+
};
|
|
7122
|
+
}
|
|
7123
|
+
});
|
|
7124
|
+
|
|
7125
|
+
// src/rules/no-exception-text-in-5xx-response.ts
|
|
7126
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES35, ASTUtils as ASTUtils15 } from "@typescript-eslint/utils";
|
|
7127
|
+
var NO_EXCEPTION_TEXT_IN_5XX_RESPONSE_DOCUMENTATION = {
|
|
7128
|
+
summary: "Keep caught exception messages and stacks out of returned 5xx JSON responses.",
|
|
7129
|
+
rationale: "Exception details can contain database, provider, filesystem or credential information that belongs in server-side diagnostics rather than a client response.",
|
|
7130
|
+
remediation: "Return a generic public error and retain diagnostic details in server-side logs. Keep intentional public domain errors in their reviewed client-error contract.",
|
|
7131
|
+
category: "security",
|
|
7132
|
+
defaultLevel: "warning",
|
|
7133
|
+
autofix: "none",
|
|
7134
|
+
references: ["https://cheatsheetseries.owasp.org/cheatsheets/Error_Handling_Cheat_Sheet.html", "https://nextjs.org/docs/app/api-reference/functions/next-response"],
|
|
7135
|
+
limitations: [
|
|
7136
|
+
"Only directly returned Response.json calls and named NextResponse imports from next/server, with an explicit literal integer 500\u2013599 status, are inspected.",
|
|
7137
|
+
"Caught message/stack fields are followed through literal objects, arrays, interpolation and conditional expressions. Mutable or escaped catch values, shadowed factories and local factory/serializer overrides are excluded.",
|
|
7138
|
+
"Client errors, dynamic status codes, aliases, response wrappers, custom sanitizer calls, spreads, uncertain properties or serialization hooks, tests and generated files are excluded. Interprocedural mutations and runtime monkeypatches are not resolved.",
|
|
7139
|
+
"A warning requests review; syntax does not prove the exception contains a secret. There is no automatic replacement for an application's public error contract."
|
|
7140
|
+
],
|
|
7141
|
+
examples: [
|
|
7142
|
+
{
|
|
7143
|
+
id: "generic-server-error",
|
|
7144
|
+
title: "Keep internal failure details server-side",
|
|
7145
|
+
outcome: "no-match",
|
|
7146
|
+
files: [{ path: "src/route.ts", source: "function handle() { try { run(); } catch (error) { return Response.json({ error: 'Internal server error' }, { status: 500 }); } }" }],
|
|
7147
|
+
focusPath: "src/route.ts",
|
|
7148
|
+
expectedCount: 0,
|
|
7149
|
+
public: true
|
|
7150
|
+
},
|
|
7151
|
+
{
|
|
7152
|
+
id: "caught-message-in-server-error",
|
|
7153
|
+
title: "Do not return a caught message as a server error",
|
|
7154
|
+
outcome: "match",
|
|
7155
|
+
files: [{ path: "src/route.ts", source: "function handle() { try { run(); } catch (error) { return Response.json({ error: error instanceof Error ? error.message : 'Internal server error' }, { status: 500 }); } }" }],
|
|
7156
|
+
focusPath: "src/route.ts",
|
|
7157
|
+
expectedCount: 1,
|
|
7158
|
+
public: true
|
|
7159
|
+
}
|
|
7160
|
+
]
|
|
7161
|
+
};
|
|
7162
|
+
var no_exception_text_in_5xx_response_default = createRule({
|
|
7163
|
+
name: "no-exception-text-in-5xx-response",
|
|
7164
|
+
documentation: NO_EXCEPTION_TEXT_IN_5XX_RESPONSE_DOCUMENTATION,
|
|
7165
|
+
meta: {
|
|
7166
|
+
type: "problem",
|
|
7167
|
+
docs: { description: NO_EXCEPTION_TEXT_IN_5XX_RESPONSE_DOCUMENTATION.summary },
|
|
7168
|
+
schema: [],
|
|
7169
|
+
messages: {
|
|
7170
|
+
exceptionText: "Caught exception text enters a returned 5xx JSON response. Return a generic public message and retain details in server-side logs."
|
|
7171
|
+
}
|
|
7172
|
+
},
|
|
7173
|
+
defaultOptions: [],
|
|
7174
|
+
create(context) {
|
|
7175
|
+
const sourceCode = context.sourceCode;
|
|
7176
|
+
if (isTestFile(context.filename) || isGeneratedFile(context.filename, sourceCode.text)) return {};
|
|
7177
|
+
const candidates = [];
|
|
7178
|
+
const changedErrors = /* @__PURE__ */ new Set();
|
|
7179
|
+
const stableBindings = /* @__PURE__ */ new WeakMap();
|
|
7180
|
+
const referenceIdentifiers = new WeakSet(sourceCode.scopeManager?.scopes.flatMap((scope) => scope.references.filter((reference) => reference.isValueReference !== false).map((reference) => reference.identifier)) ?? []);
|
|
7181
|
+
let uncertainSerialization = false;
|
|
7182
|
+
function binding(identifier) {
|
|
7183
|
+
return ASTUtils15.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
7184
|
+
}
|
|
7185
|
+
function stable(variable) {
|
|
7186
|
+
const cached = stableBindings.get(variable);
|
|
7187
|
+
if (cached !== void 0) return cached;
|
|
7188
|
+
const result = !variable.references.some((reference) => reference.isWrite() && reference.init !== true);
|
|
7189
|
+
stableBindings.set(variable, result);
|
|
7190
|
+
return result;
|
|
7191
|
+
}
|
|
7192
|
+
function ambientGlobal(node) {
|
|
7193
|
+
const value = unwrapExpression(node);
|
|
7194
|
+
if (value.type !== AST_NODE_TYPES35.Identifier || value.name !== "globalThis") return false;
|
|
7195
|
+
const variable = binding(value);
|
|
7196
|
+
return variable === null || variable.defs.length === 0;
|
|
7197
|
+
}
|
|
7198
|
+
function caughtValue(node) {
|
|
7199
|
+
const value = unwrapExpression(node);
|
|
7200
|
+
if (value.type !== AST_NODE_TYPES35.Identifier) return null;
|
|
7201
|
+
const variable = binding(value);
|
|
7202
|
+
const definition = variable?.defs.length === 1 ? variable.defs[0] : void 0;
|
|
7203
|
+
return definition?.type === "CatchClause" && definition.node.param?.type === AST_NODE_TYPES35.Identifier && variable !== null && stable(variable) ? variable : null;
|
|
7204
|
+
}
|
|
7205
|
+
function responseFactory(node) {
|
|
7206
|
+
const value = unwrapExpression(node);
|
|
7207
|
+
if (value.type !== AST_NODE_TYPES35.Identifier) return false;
|
|
7208
|
+
const variable = binding(value);
|
|
7209
|
+
if (value.name === "Response" && (variable === null || variable.defs.length === 0)) {
|
|
7210
|
+
return variable === null || stable(variable);
|
|
7211
|
+
}
|
|
7212
|
+
const definition = variable?.defs.length === 1 ? variable.defs[0] : void 0;
|
|
7213
|
+
return definition?.type === "ImportBinding" && definition.node.type === AST_NODE_TYPES35.ImportSpecifier && definition.node.imported.type === AST_NODE_TYPES35.Identifier && definition.node.imported.name === "NextResponse" && definition.parent.type === AST_NODE_TYPES35.ImportDeclaration && definition.parent.source.value === "next/server" && variable !== null && stable(variable);
|
|
7214
|
+
}
|
|
7215
|
+
function properties(node) {
|
|
7216
|
+
const value = unwrapExpression(node);
|
|
7217
|
+
if (value.type !== AST_NODE_TYPES35.ObjectExpression) return null;
|
|
7218
|
+
const fields = /* @__PURE__ */ new Map();
|
|
7219
|
+
for (const property of value.properties) {
|
|
7220
|
+
if (property.type !== AST_NODE_TYPES35.Property || property.method || property.kind !== "init") return null;
|
|
7221
|
+
const name = staticPropertyName(property, sourceCode);
|
|
7222
|
+
if (name === null || name === "toJSON" || name === "__proto__") return null;
|
|
7223
|
+
fields.set(name, property.value);
|
|
7224
|
+
}
|
|
7225
|
+
return fields;
|
|
7226
|
+
}
|
|
7227
|
+
function serverError(node) {
|
|
7228
|
+
const field = properties(node)?.get("status");
|
|
7229
|
+
const status = field === void 0 ? void 0 : unwrapExpression(field);
|
|
7230
|
+
return status?.type === AST_NODE_TYPES35.Literal && typeof status.value === "number" && Number.isInteger(status.value) && status.value >= 500 && status.value <= 599;
|
|
7231
|
+
}
|
|
7232
|
+
function payloadErrors(node) {
|
|
7233
|
+
const value = unwrapExpression(node);
|
|
7234
|
+
switch (value.type) {
|
|
7235
|
+
case AST_NODE_TYPES35.ChainExpression:
|
|
7236
|
+
return payloadErrors(value.expression);
|
|
7237
|
+
case AST_NODE_TYPES35.MemberExpression: {
|
|
7238
|
+
const name = staticPropertyName(value, sourceCode);
|
|
7239
|
+
const variable = name === "message" || name === "stack" ? caughtValue(value.object) : null;
|
|
7240
|
+
return variable === null ? [] : [variable];
|
|
7241
|
+
}
|
|
7242
|
+
case AST_NODE_TYPES35.ObjectExpression:
|
|
7243
|
+
return [...properties(value)?.values() ?? []].flatMap(payloadErrors);
|
|
7244
|
+
case AST_NODE_TYPES35.ArrayExpression:
|
|
7245
|
+
return value.elements.some((element) => element?.type === AST_NODE_TYPES35.SpreadElement) ? [] : value.elements.flatMap((element) => element === null ? [] : payloadErrors(element));
|
|
7246
|
+
case AST_NODE_TYPES35.TemplateLiteral:
|
|
7247
|
+
return value.expressions.flatMap(payloadErrors);
|
|
7248
|
+
case AST_NODE_TYPES35.ConditionalExpression:
|
|
7249
|
+
case AST_NODE_TYPES35.LogicalExpression:
|
|
7250
|
+
return branchValues(value).flatMap(payloadErrors);
|
|
7251
|
+
case AST_NODE_TYPES35.BinaryExpression:
|
|
7252
|
+
return value.operator === "+" ? [...payloadErrors(value.left), ...payloadErrors(value.right)] : [];
|
|
7253
|
+
default:
|
|
7254
|
+
return [];
|
|
7255
|
+
}
|
|
7256
|
+
}
|
|
7257
|
+
function branchValues(value) {
|
|
7258
|
+
if (value.type === AST_NODE_TYPES35.ConditionalExpression) {
|
|
7259
|
+
const test = ASTUtils15.getStaticValue(unwrapExpression(value.test), sourceCode.getScope(value.test));
|
|
7260
|
+
return test === null ? [value.consequent, value.alternate] : [test.value ? value.consequent : value.alternate];
|
|
7261
|
+
}
|
|
7262
|
+
const left = ASTUtils15.getStaticValue(unwrapExpression(value.left), sourceCode.getScope(value.left));
|
|
7263
|
+
if (left === null) return value.operator === "&&" ? [value.right] : [value.left, value.right];
|
|
7264
|
+
const useRight = value.operator === "??" ? left.value == null : value.operator === "&&" ? Boolean(left.value) : !left.value;
|
|
7265
|
+
return useRight ? [value.right] : [];
|
|
7266
|
+
}
|
|
7267
|
+
function directlyReturned(node) {
|
|
7268
|
+
let current = node;
|
|
7269
|
+
while (current.parent !== void 0 && (current.parent.type === AST_NODE_TYPES35.AwaitExpression || current.parent.type === AST_NODE_TYPES35.ChainExpression || unwrapExpression(current.parent) === current)) {
|
|
7270
|
+
current = current.parent;
|
|
7271
|
+
}
|
|
7272
|
+
return current.parent?.type === AST_NODE_TYPES35.ReturnStatement || current.parent?.type === AST_NODE_TYPES35.ArrowFunctionExpression && current.parent.body === current;
|
|
7273
|
+
}
|
|
7274
|
+
function recordWrite(target) {
|
|
7275
|
+
const value = unwrapExpression(target);
|
|
7276
|
+
if (value.type === AST_NODE_TYPES35.ObjectPattern) {
|
|
7277
|
+
for (const property of value.properties) recordWrite(property.type === AST_NODE_TYPES35.RestElement ? property.argument : property.value);
|
|
7278
|
+
} else if (value.type === AST_NODE_TYPES35.ArrayPattern) {
|
|
7279
|
+
for (const element of value.elements) if (element !== null) recordWrite(element);
|
|
7280
|
+
} else if (value.type === AST_NODE_TYPES35.AssignmentPattern) recordWrite(value.left);
|
|
7281
|
+
else if (value.type === AST_NODE_TYPES35.RestElement) recordWrite(value.argument);
|
|
7282
|
+
if (value.type !== AST_NODE_TYPES35.MemberExpression) return;
|
|
7283
|
+
if (responseFactory(value.object) || staticPropertyName(value, sourceCode) === "toJSON" || ambientGlobal(value.object) && (staticPropertyName(value, sourceCode) === "Response" || value.computed)) {
|
|
7284
|
+
uncertainSerialization = true;
|
|
7285
|
+
}
|
|
7286
|
+
const error = caughtValue(value.object);
|
|
7287
|
+
if (error !== null) changedErrors.add(error);
|
|
7288
|
+
}
|
|
7289
|
+
return {
|
|
7290
|
+
Identifier(node) {
|
|
7291
|
+
if (!referenceIdentifiers.has(node)) return;
|
|
7292
|
+
let typeName = node;
|
|
7293
|
+
while (typeName.parent?.type === AST_NODE_TYPES35.TSQualifiedName) typeName = typeName.parent;
|
|
7294
|
+
if (typeName.parent?.type === AST_NODE_TYPES35.TSTypeQuery) return;
|
|
7295
|
+
const error = caughtValue(node);
|
|
7296
|
+
const factory = error === null && responseFactory(node);
|
|
7297
|
+
if (error === null && !factory) return;
|
|
7298
|
+
const value = outerExpression(node);
|
|
7299
|
+
const parent = value.parent;
|
|
7300
|
+
if (parent.type === AST_NODE_TYPES35.CatchClause && parent.param === value || parent.type === AST_NODE_TYPES35.ImportSpecifier || parent.type === AST_NODE_TYPES35.MemberExpression && parent.object === value || parent.type === AST_NODE_TYPES35.BinaryExpression && parent.operator === "instanceof" && parent.left === value || parent.type === AST_NODE_TYPES35.UnaryExpression && parent.operator === "typeof") return;
|
|
7301
|
+
if (error !== null) changedErrors.add(error);
|
|
7302
|
+
else uncertainSerialization = true;
|
|
7303
|
+
},
|
|
7304
|
+
AssignmentExpression(node) {
|
|
7305
|
+
recordWrite(node.left);
|
|
7306
|
+
},
|
|
7307
|
+
UpdateExpression(node) {
|
|
7308
|
+
recordWrite(node.argument);
|
|
7309
|
+
},
|
|
7310
|
+
UnaryExpression(node) {
|
|
7311
|
+
if (node.operator === "delete") recordWrite(node.argument);
|
|
7312
|
+
},
|
|
7313
|
+
ForInStatement(node) {
|
|
7314
|
+
recordWrite(node.left);
|
|
7315
|
+
},
|
|
7316
|
+
ForOfStatement(node) {
|
|
7317
|
+
recordWrite(node.left);
|
|
7318
|
+
},
|
|
7319
|
+
CallExpression(node) {
|
|
7320
|
+
for (const argument of node.arguments) {
|
|
7321
|
+
const value = unwrapExpression(argument);
|
|
7322
|
+
if (responseFactory(value) || ambientGlobal(value) || value.type === AST_NODE_TYPES35.MemberExpression && staticPropertyName(value, sourceCode) === "prototype") uncertainSerialization = true;
|
|
7323
|
+
}
|
|
7324
|
+
const callee = unwrapExpression(node.callee);
|
|
7325
|
+
if (callee.type === AST_NODE_TYPES35.MemberExpression) {
|
|
7326
|
+
const error = caughtValue(callee.object);
|
|
7327
|
+
if (error !== null) changedErrors.add(error);
|
|
7328
|
+
}
|
|
7329
|
+
if (callee.type !== AST_NODE_TYPES35.MemberExpression || !responseFactory(callee.object) || staticPropertyName(callee, sourceCode) !== "json" || node.arguments.length !== 2 || !directlyReturned(node)) return;
|
|
7330
|
+
const [payload, options] = node.arguments;
|
|
7331
|
+
if (payload === void 0 || options === void 0 || !serverError(options)) return;
|
|
7332
|
+
const errors = payloadErrors(payload);
|
|
7333
|
+
if (errors.length > 0) candidates.push({ node, errors });
|
|
7334
|
+
},
|
|
7335
|
+
"Program:exit"() {
|
|
7336
|
+
if (uncertainSerialization) return;
|
|
7337
|
+
for (const candidate2 of candidates) {
|
|
7338
|
+
if (candidate2.errors.some((error) => !changedErrors.has(error))) {
|
|
7339
|
+
context.report({ node: candidate2.node, messageId: "exceptionText" });
|
|
7340
|
+
}
|
|
7085
7341
|
}
|
|
7086
7342
|
}
|
|
7087
7343
|
};
|
|
@@ -7089,7 +7345,7 @@ var no_detached_global_fetch_default = createRule({
|
|
|
7089
7345
|
});
|
|
7090
7346
|
|
|
7091
7347
|
// src/rules/no-json-stringify-error.ts
|
|
7092
|
-
import { ASTUtils as
|
|
7348
|
+
import { ASTUtils as ASTUtils16 } from "@typescript-eslint/utils";
|
|
7093
7349
|
var NO_JSON_STRINGIFY_ERROR_DOCUMENTATION = {
|
|
7094
7350
|
summary: "Avoid generic JSON serialization that can omit native Error details.",
|
|
7095
7351
|
rationale: "Native Error details are non-enumerable, so generic JSON serialization discards diagnostic information.",
|
|
@@ -7190,7 +7446,7 @@ function builtinWrites(sourceCode) {
|
|
|
7190
7446
|
const native = nativeObjectName(expression, sourceCode);
|
|
7191
7447
|
if (native !== null) return native;
|
|
7192
7448
|
const value = unwrapExpression(expression);
|
|
7193
|
-
if (value.type === "Identifier") return
|
|
7449
|
+
if (value.type === "Identifier") return ASTUtils16.findVariable(sourceCode.getScope(value), value.name);
|
|
7194
7450
|
if (value.type === "MemberExpression" && staticPropertyName(value, sourceCode) === "prototype") {
|
|
7195
7451
|
const constructor = globalBuiltinName(value.object, sourceCode);
|
|
7196
7452
|
if (constructor !== null && BUILTIN_ERROR_CONSTRUCTORS.has(constructor)) return constructor + ".prototype";
|
|
@@ -7309,7 +7565,7 @@ function builtinWrites(sourceCode) {
|
|
|
7309
7565
|
function hasDefaultErrorSerialization(expression, call, sourceCode) {
|
|
7310
7566
|
let constructor = null;
|
|
7311
7567
|
if (expression.type === "Identifier") {
|
|
7312
|
-
const variable =
|
|
7568
|
+
const variable = ASTUtils16.findVariable(sourceCode.getScope(expression), expression.name);
|
|
7313
7569
|
if (variable !== null && !hasUnchangedBuiltin(variable, call, sourceCode)) return false;
|
|
7314
7570
|
const definition = variable?.defs[0];
|
|
7315
7571
|
const initializer = definition?.type === "Variable" ? definition.node.init : null;
|
|
@@ -7322,7 +7578,7 @@ function isBuiltinErrorConstructor(identifier, sourceCode) {
|
|
|
7322
7578
|
return sourceCode.scopeManager !== null && BUILTIN_ERROR_CONSTRUCTORS.has(identifier.name) && isGlobalIdentifier(identifier.name, sourceCode.getScope(identifier)) && hasUnchangedBuiltin(identifier.name, identifier, sourceCode);
|
|
7323
7579
|
}
|
|
7324
7580
|
function isGlobalIdentifier(name, scope) {
|
|
7325
|
-
const binding =
|
|
7581
|
+
const binding = ASTUtils16.findVariable(scope, name);
|
|
7326
7582
|
return binding === null || binding.defs.length === 0;
|
|
7327
7583
|
}
|
|
7328
7584
|
function positiveErrorSubject(test, sourceCode) {
|
|
@@ -7390,8 +7646,8 @@ function sameSubjectBinding(subject, value, sourceCode) {
|
|
|
7390
7646
|
const left = unwrapExpression(subject);
|
|
7391
7647
|
const right = unwrapExpression(value);
|
|
7392
7648
|
if (left.type === "Identifier" && right.type === "Identifier") {
|
|
7393
|
-
const binding =
|
|
7394
|
-
return binding !== null && binding ===
|
|
7649
|
+
const binding = ASTUtils16.findVariable(sourceCode.getScope(left), left.name);
|
|
7650
|
+
return binding !== null && binding === ASTUtils16.findVariable(sourceCode.getScope(right), right.name);
|
|
7395
7651
|
}
|
|
7396
7652
|
return sourceCode.getText(subject) === sourceCode.getText(value);
|
|
7397
7653
|
}
|
|
@@ -7449,7 +7705,7 @@ function expressionSuggestsError(expression, sourceCode) {
|
|
|
7449
7705
|
return false;
|
|
7450
7706
|
}
|
|
7451
7707
|
function identifierIsProvenError(identifier, sourceCode) {
|
|
7452
|
-
const variable =
|
|
7708
|
+
const variable = ASTUtils16.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
7453
7709
|
if (variable === null || variable.defs.length !== 1 || variable.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
7454
7710
|
const definition = variable.defs[0];
|
|
7455
7711
|
if (definition?.type === "CatchClause") return true;
|
|
@@ -7523,7 +7779,7 @@ function branchTerminates(branch) {
|
|
|
7523
7779
|
// src/rules/no-json-stringify-object-equality.ts
|
|
7524
7780
|
import {
|
|
7525
7781
|
AST_NODE_TYPES as AST_NODE_TYPES36,
|
|
7526
|
-
ASTUtils as
|
|
7782
|
+
ASTUtils as ASTUtils17,
|
|
7527
7783
|
ESLintUtils as ESLintUtils7
|
|
7528
7784
|
} from "@typescript-eslint/utils";
|
|
7529
7785
|
import ts6 from "typescript";
|
|
@@ -7574,10 +7830,10 @@ function jsonStringifyArgument(node, sourceCode) {
|
|
|
7574
7830
|
if (expression.type !== AST_NODE_TYPES36.CallExpression) return null;
|
|
7575
7831
|
const callee = unwrapExpression(expression.callee);
|
|
7576
7832
|
const calleeReceiver = callee.type === AST_NODE_TYPES36.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
7577
|
-
if (callee.type !== AST_NODE_TYPES36.MemberExpression || calleeReceiver.type !== AST_NODE_TYPES36.Identifier || calleeReceiver.name !== "JSON" ||
|
|
7833
|
+
if (callee.type !== AST_NODE_TYPES36.MemberExpression || calleeReceiver.type !== AST_NODE_TYPES36.Identifier || calleeReceiver.name !== "JSON" || ASTUtils17.getPropertyName(callee) !== "stringify") {
|
|
7578
7834
|
return null;
|
|
7579
7835
|
}
|
|
7580
|
-
const variable =
|
|
7836
|
+
const variable = ASTUtils17.findVariable(sourceCode.getScope(calleeReceiver), "JSON");
|
|
7581
7837
|
if (variable !== null && variable.defs.length > 0) return null;
|
|
7582
7838
|
const argument = expression.arguments[0];
|
|
7583
7839
|
return argument !== void 0 && argument.type !== AST_NODE_TYPES36.SpreadElement ? argument : null;
|
|
@@ -7663,7 +7919,7 @@ var no_json_stringify_object_equality_default = createRule({
|
|
|
7663
7919
|
|
|
7664
7920
|
// src/rules/no-impossible-zod-literal-bounds.ts
|
|
7665
7921
|
import {
|
|
7666
|
-
ASTUtils as
|
|
7922
|
+
ASTUtils as ASTUtils18,
|
|
7667
7923
|
AST_NODE_TYPES as AST_NODE_TYPES37
|
|
7668
7924
|
} from "@typescript-eslint/utils";
|
|
7669
7925
|
|
|
@@ -7855,7 +8111,7 @@ var no_impossible_zod_literal_bounds_default = createRule({
|
|
|
7855
8111
|
if (callee.type !== AST_NODE_TYPES37.MemberExpression || calleeReceiver.type !== AST_NODE_TYPES37.CallExpression) {
|
|
7856
8112
|
return null;
|
|
7857
8113
|
}
|
|
7858
|
-
const method =
|
|
8114
|
+
const method = ASTUtils18.getPropertyName(callee);
|
|
7859
8115
|
if (method === null) return null;
|
|
7860
8116
|
calls.push({ method, node: current });
|
|
7861
8117
|
current = calleeReceiver;
|
|
@@ -7870,7 +8126,7 @@ var no_impossible_zod_literal_bounds_default = createRule({
|
|
|
7870
8126
|
if (callee.type !== AST_NODE_TYPES37.MemberExpression || calleeReceiver.type !== AST_NODE_TYPES37.Identifier || !namespaces.has(calleeReceiver.name) || !resolvesToTrackedImport(calleeReceiver)) {
|
|
7871
8127
|
return null;
|
|
7872
8128
|
}
|
|
7873
|
-
const name =
|
|
8129
|
+
const name = ASTUtils18.getPropertyName(callee);
|
|
7874
8130
|
return name === null ? null : KINDS.get(name) ?? null;
|
|
7875
8131
|
}
|
|
7876
8132
|
function isInsideReshapingCall(node) {
|
|
@@ -7880,7 +8136,7 @@ var no_impossible_zod_literal_bounds_default = createRule({
|
|
|
7880
8136
|
if (parent.type === AST_NODE_TYPES37.CallExpression) {
|
|
7881
8137
|
const callee = unwrapExpression(parent.callee);
|
|
7882
8138
|
const calleeReceiver = callee.type === AST_NODE_TYPES37.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
7883
|
-
if (callee.type === AST_NODE_TYPES37.MemberExpression && RESHAPING_METHODS.has(
|
|
8139
|
+
if (callee.type === AST_NODE_TYPES37.MemberExpression && RESHAPING_METHODS.has(ASTUtils18.getPropertyName(callee) ?? "") && (calleeReceiver.type === AST_NODE_TYPES37.CallExpression || calleeReceiver.type === AST_NODE_TYPES37.Identifier && namespaces.has(calleeReceiver.name) && resolvesToTrackedImport(calleeReceiver))) {
|
|
7884
8140
|
return true;
|
|
7885
8141
|
}
|
|
7886
8142
|
if (callee.type === AST_NODE_TYPES37.Identifier && preprocessors.has(callee.name) && resolvesToTrackedImport(callee)) {
|
|
@@ -8122,7 +8378,7 @@ var no_in_operator_on_built_in_collections_default = createRule({
|
|
|
8122
8378
|
|
|
8123
8379
|
// src/rules/no-redundant-optional-array-default.ts
|
|
8124
8380
|
import {
|
|
8125
|
-
ASTUtils as
|
|
8381
|
+
ASTUtils as ASTUtils19,
|
|
8126
8382
|
AST_NODE_TYPES as AST_NODE_TYPES38
|
|
8127
8383
|
} from "@typescript-eslint/utils";
|
|
8128
8384
|
var NO_REDUNDANT_OPTIONAL_ARRAY_DEFAULT_DOCUMENTATION = {
|
|
@@ -8260,7 +8516,7 @@ var no_redundant_optional_array_default_default = createRule({
|
|
|
8260
8516
|
return arrayConstructors.has(callee.name) && resolvesToTrackedImport(callee);
|
|
8261
8517
|
}
|
|
8262
8518
|
if (callee.type !== AST_NODE_TYPES38.MemberExpression) return false;
|
|
8263
|
-
const method =
|
|
8519
|
+
const method = ASTUtils19.getPropertyName(callee);
|
|
8264
8520
|
if (method === "array" && (calleeReceiver.type === AST_NODE_TYPES38.Identifier ? namespaces.has(calleeReceiver.name) && resolvesToTrackedImport(calleeReceiver) : isZodSchemaExpression(calleeReceiver))) {
|
|
8265
8521
|
return true;
|
|
8266
8522
|
}
|
|
@@ -8303,13 +8559,13 @@ var no_redundant_optional_array_default_default = createRule({
|
|
|
8303
8559
|
CallExpression(node) {
|
|
8304
8560
|
const defaultCallee = unwrapExpression(node.callee);
|
|
8305
8561
|
const defaultCalleeReceiver = defaultCallee.type === AST_NODE_TYPES38.MemberExpression ? unwrapExpression(defaultCallee.object) : defaultCallee;
|
|
8306
|
-
if (defaultCallee.type !== AST_NODE_TYPES38.MemberExpression ||
|
|
8562
|
+
if (defaultCallee.type !== AST_NODE_TYPES38.MemberExpression || ASTUtils19.getPropertyName(defaultCallee) !== "default" || !hasArrayFallback(node) || defaultCalleeReceiver.type !== AST_NODE_TYPES38.CallExpression) {
|
|
8307
8563
|
return;
|
|
8308
8564
|
}
|
|
8309
8565
|
const optionalCall = defaultCalleeReceiver;
|
|
8310
8566
|
const optionalCallee = unwrapExpression(optionalCall.callee);
|
|
8311
8567
|
const optionalCalleeReceiver = optionalCallee.type === AST_NODE_TYPES38.MemberExpression ? unwrapExpression(optionalCallee.object) : optionalCallee;
|
|
8312
|
-
if (optionalCallee.type !== AST_NODE_TYPES38.MemberExpression ||
|
|
8568
|
+
if (optionalCallee.type !== AST_NODE_TYPES38.MemberExpression || ASTUtils19.getPropertyName(optionalCallee) !== "optional" || optionalCall.arguments.length !== 0 || !isArraySchemaExpression(optionalCalleeReceiver) || sourceCode.getCommentsInside(optionalCall).length > 0) {
|
|
8313
8569
|
return;
|
|
8314
8570
|
}
|
|
8315
8571
|
context.report({
|
|
@@ -8448,10 +8704,10 @@ var interface_contract_members_private_default = createRule({
|
|
|
8448
8704
|
});
|
|
8449
8705
|
|
|
8450
8706
|
// src/rules/no-log-only-catch.ts
|
|
8451
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES42, ASTUtils as
|
|
8707
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES42, ASTUtils as ASTUtils21 } from "@typescript-eslint/utils";
|
|
8452
8708
|
|
|
8453
8709
|
// src/rules/_logging.ts
|
|
8454
|
-
import { ASTUtils as
|
|
8710
|
+
import { ASTUtils as ASTUtils20, AST_NODE_TYPES as AST_NODE_TYPES41 } from "@typescript-eslint/utils";
|
|
8455
8711
|
var LOG_METHODS = /* @__PURE__ */ new Set([
|
|
8456
8712
|
"debug",
|
|
8457
8713
|
"info",
|
|
@@ -8483,12 +8739,12 @@ var LOGGING_OPTION_PROPERTIES = {
|
|
|
8483
8739
|
loggerNames: { type: "array", items: { type: "string" } },
|
|
8484
8740
|
logFunctions: { type: "array", items: { type: "string" } }
|
|
8485
8741
|
};
|
|
8486
|
-
function
|
|
8742
|
+
function calleeName(callee) {
|
|
8487
8743
|
callee = unwrapExpression(callee);
|
|
8488
8744
|
if (callee.type === "Identifier") {
|
|
8489
8745
|
return callee.name;
|
|
8490
8746
|
}
|
|
8491
|
-
return callee.type === "MemberExpression" ?
|
|
8747
|
+
return callee.type === "MemberExpression" ? ASTUtils20.getPropertyName(callee) : null;
|
|
8492
8748
|
}
|
|
8493
8749
|
function createLogMatcher(options = {}) {
|
|
8494
8750
|
const loggerNames = /* @__PURE__ */ new Set([
|
|
@@ -8503,7 +8759,7 @@ function createLogMatcher(options = {}) {
|
|
|
8503
8759
|
return loggerNames.has(expr.name.toLowerCase());
|
|
8504
8760
|
case "MemberExpression": {
|
|
8505
8761
|
const { object } = expr;
|
|
8506
|
-
const property =
|
|
8762
|
+
const property = ASTUtils20.getPropertyName(expr);
|
|
8507
8763
|
if (property !== null) {
|
|
8508
8764
|
const lowered = property.toLowerCase();
|
|
8509
8765
|
if (loggerNames.has(lowered) || LOGGER_FACTORIES.has(lowered)) {
|
|
@@ -8514,7 +8770,7 @@ function createLogMatcher(options = {}) {
|
|
|
8514
8770
|
}
|
|
8515
8771
|
case "CallExpression": {
|
|
8516
8772
|
const callee = unwrapExpression(expr.callee);
|
|
8517
|
-
const name = callee.type === "MemberExpression" ?
|
|
8773
|
+
const name = callee.type === "MemberExpression" ? ASTUtils20.getPropertyName(callee) : null;
|
|
8518
8774
|
if (name !== null && LOGGER_FACTORIES.has(name.toLowerCase())) {
|
|
8519
8775
|
return true;
|
|
8520
8776
|
}
|
|
@@ -8531,7 +8787,7 @@ function createLogMatcher(options = {}) {
|
|
|
8531
8787
|
if (expr.type !== "CallExpression" || logFunctions.size === 0) {
|
|
8532
8788
|
return false;
|
|
8533
8789
|
}
|
|
8534
|
-
const name =
|
|
8790
|
+
const name = calleeName(expr.callee);
|
|
8535
8791
|
return name !== null && logFunctions.has(name);
|
|
8536
8792
|
}
|
|
8537
8793
|
function isLoggingCall(expr) {
|
|
@@ -8545,7 +8801,7 @@ function createLogMatcher(options = {}) {
|
|
|
8545
8801
|
const callee = unwrapExpression(expr.callee);
|
|
8546
8802
|
const calleeReceiver = callee.type === AST_NODE_TYPES41.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
8547
8803
|
if (callee.type !== "MemberExpression") return false;
|
|
8548
|
-
const name =
|
|
8804
|
+
const name = ASTUtils20.getPropertyName(callee);
|
|
8549
8805
|
return name !== null && LOG_METHODS.has(name.toLowerCase()) && isLoggerReceiver(calleeReceiver);
|
|
8550
8806
|
}
|
|
8551
8807
|
return { isLoggerReceiver, isLogFunctionCall, isLoggingCall };
|
|
@@ -8619,7 +8875,7 @@ function seededFallbackHandled(tryStatement, scope) {
|
|
|
8619
8875
|
if (previous.declarations.length !== 1 || declarator === void 0) return false;
|
|
8620
8876
|
if (declarator.id.type !== AST_NODE_TYPES42.Identifier) return false;
|
|
8621
8877
|
if (declarator.init == null || !isSeedValue(declarator.init)) return false;
|
|
8622
|
-
const variable =
|
|
8878
|
+
const variable = ASTUtils21.findVariable(scope, declarator.id.name);
|
|
8623
8879
|
if (variable === null) return false;
|
|
8624
8880
|
const [tryStart, tryEnd] = tryStatement.block.range;
|
|
8625
8881
|
let writtenInTry = false;
|
|
@@ -8681,9 +8937,9 @@ var no_log_only_catch_default = createRule({
|
|
|
8681
8937
|
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;
|
|
8682
8938
|
const argument = right.arguments[0];
|
|
8683
8939
|
if (argument === void 0 || sourceCode.getText(left) !== sourceCode.getText(argument)) return false;
|
|
8684
|
-
const global =
|
|
8940
|
+
const global = ASTUtils21.findVariable(sourceCode.getScope(right.callee), right.callee.name);
|
|
8685
8941
|
if (global !== null && global.defs.length > 0) return false;
|
|
8686
|
-
const root =
|
|
8942
|
+
const root = ASTUtils21.findVariable(sourceCode.getScope(left.object), left.object.name);
|
|
8687
8943
|
if (root === null || root.references.some((reference) => reference.isWrite() && !reference.init)) return false;
|
|
8688
8944
|
return hasFollowingCoercionCheck(owner, left, right.callee.name);
|
|
8689
8945
|
}
|
|
@@ -8754,7 +9010,7 @@ var no_log_only_catch_default = createRule({
|
|
|
8754
9010
|
});
|
|
8755
9011
|
|
|
8756
9012
|
// src/rules/no-bare-return-from-test-catch.ts
|
|
8757
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES43, ASTUtils as
|
|
9013
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES43, ASTUtils as ASTUtils22 } from "@typescript-eslint/utils";
|
|
8758
9014
|
var NO_BARE_RETURN_FROM_TEST_CATCH_DOCUMENTATION = {
|
|
8759
9015
|
summary: "Disallow a bare return from a test catch block when it skips a later assertion.",
|
|
8760
9016
|
rationale: "An unasserted catch return can swallow a failure and skip later assertions; the complete test result also depends on other assertions and hooks.",
|
|
@@ -8851,7 +9107,7 @@ var no_bare_return_from_test_catch_default = createRule({
|
|
|
8851
9107
|
const parameter = catchClause.param;
|
|
8852
9108
|
const returnBlock = node.parent;
|
|
8853
9109
|
if (parameter?.type === AST_NODE_TYPES43.Identifier && returnBlock?.type === AST_NODE_TYPES43.BlockStatement) {
|
|
8854
|
-
const errorBinding =
|
|
9110
|
+
const errorBinding = ASTUtils22.findVariable(context.sourceCode.getScope(parameter), parameter.name);
|
|
8855
9111
|
const assertedError = returnBlock.body.some((statement) => {
|
|
8856
9112
|
if (statement.range[1] >= node.range[0] || statement.type !== AST_NODE_TYPES43.ExpressionStatement) return false;
|
|
8857
9113
|
const expression = statement.expression;
|
|
@@ -8875,7 +9131,7 @@ var no_bare_return_from_test_catch_default = createRule({
|
|
|
8875
9131
|
});
|
|
8876
9132
|
|
|
8877
9133
|
// src/rules/no-bespoke-api-case-conversion.ts
|
|
8878
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES44, ASTUtils as
|
|
9134
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES44, ASTUtils as ASTUtils23 } from "@typescript-eslint/utils";
|
|
8879
9135
|
var NO_BESPOKE_API_CASE_CONVERSION_DOCUMENTATION = {
|
|
8880
9136
|
defaultLevel: "warning",
|
|
8881
9137
|
summary: "Review direct snake_case/camelCase mirror mappings on explicitly API-typed adapter values.",
|
|
@@ -8928,10 +9184,10 @@ function propertyName(node) {
|
|
|
8928
9184
|
}
|
|
8929
9185
|
function memberName3(node) {
|
|
8930
9186
|
const current = unwrapExpression(node);
|
|
8931
|
-
if (current.type !== AST_NODE_TYPES44.MemberExpression ||
|
|
9187
|
+
if (current.type !== AST_NODE_TYPES44.MemberExpression || ASTUtils23.getPropertyName(current) === null) {
|
|
8932
9188
|
return null;
|
|
8933
9189
|
}
|
|
8934
|
-
return
|
|
9190
|
+
return ASTUtils23.getPropertyName(current) ?? "";
|
|
8935
9191
|
}
|
|
8936
9192
|
function isDirectCaseTranslation(left, right) {
|
|
8937
9193
|
if (SNAKE_CASE_RE2.test(left) && LOWER_CAMEL_CASE_RE.test(right)) {
|
|
@@ -8971,7 +9227,7 @@ var no_bespoke_api_case_conversion_default = createRule({
|
|
|
8971
9227
|
else break;
|
|
8972
9228
|
}
|
|
8973
9229
|
if (current.type !== AST_NODE_TYPES44.Identifier) return false;
|
|
8974
|
-
const binding =
|
|
9230
|
+
const binding = ASTUtils23.findVariable(context.sourceCode.getScope(current), current.name);
|
|
8975
9231
|
if (binding?.defs.length !== 1 || binding.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
8976
9232
|
const identifier = binding.defs[0]?.name;
|
|
8977
9233
|
if (identifier?.type !== AST_NODE_TYPES44.Identifier) return false;
|
|
@@ -8980,7 +9236,7 @@ var no_bespoke_api_case_conversion_default = createRule({
|
|
|
8980
9236
|
let typeName = annotation.typeName;
|
|
8981
9237
|
while (typeName.type === AST_NODE_TYPES44.TSQualifiedName) typeName = typeName.left;
|
|
8982
9238
|
if (typeName.type !== AST_NODE_TYPES44.Identifier) return false;
|
|
8983
|
-
const typeBinding =
|
|
9239
|
+
const typeBinding = ASTUtils23.findVariable(context.sourceCode.getScope(typeName), typeName.name);
|
|
8984
9240
|
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);
|
|
8985
9241
|
};
|
|
8986
9242
|
return {
|
|
@@ -9185,7 +9441,7 @@ var no_vague_suppression_description_default = createRule({
|
|
|
9185
9441
|
});
|
|
9186
9442
|
|
|
9187
9443
|
// src/rules/_runtime-exports.ts
|
|
9188
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES46, ASTUtils as
|
|
9444
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES46, ASTUtils as ASTUtils24 } from "@typescript-eslint/utils";
|
|
9189
9445
|
var GENERIC_MODULE_STEMS = /* @__PURE__ */ new Set([
|
|
9190
9446
|
"common",
|
|
9191
9447
|
"helper",
|
|
@@ -9307,7 +9563,7 @@ function namespaceEmission(declaration) {
|
|
|
9307
9563
|
}
|
|
9308
9564
|
function isCommonJsExportReference(node, sourceCode) {
|
|
9309
9565
|
function isGlobal(node2) {
|
|
9310
|
-
const variable =
|
|
9566
|
+
const variable = ASTUtils24.findVariable(sourceCode.getScope(node2), node2.name);
|
|
9311
9567
|
return variable === null || variable.defs.length === 0;
|
|
9312
9568
|
}
|
|
9313
9569
|
if (node.type === AST_NODE_TYPES46.MemberExpression) {
|
|
@@ -9430,7 +9686,7 @@ var no_offset_pagination_default = createRule({
|
|
|
9430
9686
|
});
|
|
9431
9687
|
|
|
9432
9688
|
// src/rules/no-positional-tuple-return.ts
|
|
9433
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES47, ASTUtils as
|
|
9689
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES47, ASTUtils as ASTUtils25 } from "@typescript-eslint/utils";
|
|
9434
9690
|
var NO_POSITIONAL_TUPLE_RETURN_DOCUMENTATION = {
|
|
9435
9691
|
summary: "Disallow returning a multi-field tuple from a named function; return a named object so call sites cannot mismatch slots.",
|
|
9436
9692
|
rationale: "Tuple fields are identified only by position, so reordering can preserve types while changing meaning.",
|
|
@@ -9564,7 +9820,7 @@ function typeAliases(sourceCode) {
|
|
|
9564
9820
|
get(identifier) {
|
|
9565
9821
|
const declaration = aliases.get(identifier.name);
|
|
9566
9822
|
if (declaration === void 0) return void 0;
|
|
9567
|
-
const binding =
|
|
9823
|
+
const binding = ASTUtils25.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
9568
9824
|
return binding?.defs.length === 1 && binding.defs[0]?.node === declaration ? declaration.typeAnnotation : void 0;
|
|
9569
9825
|
}
|
|
9570
9826
|
};
|
|
@@ -9875,7 +10131,7 @@ var no_production_browser_source_maps_default = createRule({
|
|
|
9875
10131
|
});
|
|
9876
10132
|
|
|
9877
10133
|
// src/rules/no-raw-env.ts
|
|
9878
|
-
import { ASTUtils as
|
|
10134
|
+
import { ASTUtils as ASTUtils26, AST_NODE_TYPES as AST_NODE_TYPES48 } from "@typescript-eslint/utils";
|
|
9879
10135
|
var NO_RAW_ENV_DOCUMENTATION = {
|
|
9880
10136
|
summary: "Disallow direct `process.env` and `import.meta.env` reads outside validated boundaries.",
|
|
9881
10137
|
rationale: "Raw environment reads are untyped and defer invalid configuration failures until use.",
|
|
@@ -9891,15 +10147,15 @@ var CONFIG_FILE_RE = /(^|[\\/])[\w.-]+\.config\.[cm]?[jt]sx?$/;
|
|
|
9891
10147
|
var ENV_BOUNDARY_FILE_RE = /(^|[\\/])(?:env|client-env|server-env|client-settings|server-settings)\.[cm]?[jt]sx?$/;
|
|
9892
10148
|
function isProcessEnv(node, context) {
|
|
9893
10149
|
const receiver = unwrapExpression(node.object);
|
|
9894
|
-
if (receiver.type !== "Identifier" ||
|
|
9895
|
-
const binding =
|
|
10150
|
+
if (receiver.type !== "Identifier" || ASTUtils26.getPropertyName(node) !== "env") return false;
|
|
10151
|
+
const binding = ASTUtils26.findVariable(context.sourceCode.getScope(receiver), receiver.name);
|
|
9896
10152
|
if (binding === null || binding.defs.length === 0) return receiver.name === "process";
|
|
9897
10153
|
return binding.defs.every(
|
|
9898
10154
|
(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)
|
|
9899
10155
|
);
|
|
9900
10156
|
}
|
|
9901
10157
|
function isImportMetaEnv(node) {
|
|
9902
|
-
return
|
|
10158
|
+
return ASTUtils26.getPropertyName(node) === "env" && node.object.type === "MetaProperty" && node.object.meta.name === "import" && node.object.property.name === "meta";
|
|
9903
10159
|
}
|
|
9904
10160
|
var BUILD_TIME_CONSTANTS = /* @__PURE__ */ new Set([
|
|
9905
10161
|
"NODE_ENV",
|
|
@@ -9917,7 +10173,7 @@ var PLATFORM_MARKERS = /* @__PURE__ */ new Set([
|
|
|
9917
10173
|
function isExemptVariableAccess(node) {
|
|
9918
10174
|
const parent = node.parent;
|
|
9919
10175
|
if (parent.type !== "MemberExpression" || parent.object !== node) return false;
|
|
9920
|
-
const name =
|
|
10176
|
+
const name = ASTUtils26.getPropertyName(parent);
|
|
9921
10177
|
return name !== null && (BUILD_TIME_CONSTANTS.has(name) || PLATFORM_MARKERS.has(name));
|
|
9922
10178
|
}
|
|
9923
10179
|
function isWriteTarget(node) {
|
|
@@ -9965,7 +10221,7 @@ var no_raw_env_default = createRule({
|
|
|
9965
10221
|
if (callee.type === "Identifier" && callee.name === "createEnv") {
|
|
9966
10222
|
hasValidationCall = true;
|
|
9967
10223
|
} else if (callee.type === "MemberExpression") {
|
|
9968
|
-
const name =
|
|
10224
|
+
const name = ASTUtils26.getPropertyName(callee);
|
|
9969
10225
|
if (name === "parse" || name === "safeParse" || name === "object" && calleeReceiver.type === "Identifier" && calleeReceiver.name === "z") {
|
|
9970
10226
|
hasValidationCall = true;
|
|
9971
10227
|
}
|
|
@@ -9985,7 +10241,7 @@ var no_raw_env_default = createRule({
|
|
|
9985
10241
|
});
|
|
9986
10242
|
|
|
9987
10243
|
// src/rules/no-raw-fetch-outside-clients.ts
|
|
9988
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES49, ASTUtils as
|
|
10244
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES49, ASTUtils as ASTUtils27 } from "@typescript-eslint/utils";
|
|
9989
10245
|
var NO_RAW_FETCH_OUTSIDE_CLIENTS_DOCUMENTATION = {
|
|
9990
10246
|
summary: "Disallow calling the global `fetch` outside the client layer; route outbound HTTP through a client module that owns retry, timeout and status handling.",
|
|
9991
10247
|
rationale: "Scattered fetch calls bypass shared transport policy and are harder to stub and observe consistently.",
|
|
@@ -10174,7 +10430,7 @@ var no_raw_fetch_outside_clients_default = createRule({
|
|
|
10174
10430
|
internalApiPrefixes.push(`${options.basePath}/api`);
|
|
10175
10431
|
}
|
|
10176
10432
|
function resolvesToGlobal(identifier) {
|
|
10177
|
-
const variable =
|
|
10433
|
+
const variable = ASTUtils27.findVariable(
|
|
10178
10434
|
context.sourceCode.getScope(identifier),
|
|
10179
10435
|
identifier.name
|
|
10180
10436
|
);
|
|
@@ -10183,7 +10439,7 @@ var no_raw_fetch_outside_clients_default = createRule({
|
|
|
10183
10439
|
function resolveNode2(node) {
|
|
10184
10440
|
if (node === void 0) return null;
|
|
10185
10441
|
if (node.type !== AST_NODE_TYPES49.Identifier) return node;
|
|
10186
|
-
const variable =
|
|
10442
|
+
const variable = ASTUtils27.findVariable(
|
|
10187
10443
|
context.sourceCode.getScope(node),
|
|
10188
10444
|
node.name
|
|
10189
10445
|
);
|
|
@@ -10263,7 +10519,7 @@ var no_raw_fetch_outside_clients_default = createRule({
|
|
|
10263
10519
|
});
|
|
10264
10520
|
|
|
10265
10521
|
// src/rules/no-restricted-library-load.ts
|
|
10266
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES50, ASTUtils as
|
|
10522
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES50, ASTUtils as ASTUtils28 } from "@typescript-eslint/utils";
|
|
10267
10523
|
var NO_RESTRICTED_LIBRARY_LOAD_DOCUMENTATION = {
|
|
10268
10524
|
summary: "Apply configured library restrictions to literal runtime loads and CommonJS resolution references.",
|
|
10269
10525
|
rationale: "Dynamic imports, CommonJS loads, and package resolution checks can bypass library restrictions enforced for static imports.",
|
|
@@ -10349,7 +10605,7 @@ var no_restricted_library_load_default = createRule({
|
|
|
10349
10605
|
});
|
|
10350
10606
|
}
|
|
10351
10607
|
function isUnshadowedRequire(node) {
|
|
10352
|
-
const variable =
|
|
10608
|
+
const variable = ASTUtils28.findVariable(
|
|
10353
10609
|
context.sourceCode.getScope(node),
|
|
10354
10610
|
node.name
|
|
10355
10611
|
);
|
|
@@ -10383,7 +10639,7 @@ var no_restricted_library_load_default = createRule({
|
|
|
10383
10639
|
});
|
|
10384
10640
|
|
|
10385
10641
|
// src/rules/no-router-refresh-polling.ts
|
|
10386
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES51, ASTUtils as
|
|
10642
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES51, ASTUtils as ASTUtils29 } from "@typescript-eslint/utils";
|
|
10387
10643
|
var NO_ROUTER_REFRESH_POLLING_DOCUMENTATION = {
|
|
10388
10644
|
summary: "Do not poll by calling a Next.js router's refresh method from a timer.",
|
|
10389
10645
|
rationale: "A route refresh refetches and rerenders the whole route on every tick instead of loading the named resource that changed.",
|
|
@@ -10411,10 +10667,10 @@ function enclosingIntervalCallback(sourceCode, node) {
|
|
|
10411
10667
|
}
|
|
10412
10668
|
function isIntervalCallee(sourceCode, node) {
|
|
10413
10669
|
node = unwrapExpression(node);
|
|
10414
|
-
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) &&
|
|
10670
|
+
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) && ASTUtils29.getPropertyName(node) === "setInterval";
|
|
10415
10671
|
}
|
|
10416
10672
|
function isUnshadowedGlobal2(sourceCode, node) {
|
|
10417
|
-
const variable =
|
|
10673
|
+
const variable = ASTUtils29.findVariable(sourceCode.getScope(node), node.name);
|
|
10418
10674
|
return variable === null || variable.defs.length === 0;
|
|
10419
10675
|
}
|
|
10420
10676
|
var no_router_refresh_polling_default = createRule({
|
|
@@ -10437,7 +10693,7 @@ var no_router_refresh_polling_default = createRule({
|
|
|
10437
10693
|
if (node.source.value !== "next/navigation") return;
|
|
10438
10694
|
for (const specifier of node.specifiers) {
|
|
10439
10695
|
if (specifier.type === AST_NODE_TYPES51.ImportSpecifier && importedName4(specifier) === "useRouter") {
|
|
10440
|
-
const variable =
|
|
10696
|
+
const variable = ASTUtils29.findVariable(context.sourceCode.getScope(specifier.local), specifier.local.name);
|
|
10441
10697
|
if (variable !== null) routerHooks.add(variable);
|
|
10442
10698
|
}
|
|
10443
10699
|
}
|
|
@@ -10447,16 +10703,16 @@ var no_router_refresh_polling_default = createRule({
|
|
|
10447
10703
|
if (node.id.type === AST_NODE_TYPES51.Identifier && initializer?.type === AST_NODE_TYPES51.CallExpression) {
|
|
10448
10704
|
const hookCallee = unwrapExpression(initializer.callee);
|
|
10449
10705
|
if (hookCallee.type !== AST_NODE_TYPES51.Identifier) return;
|
|
10450
|
-
const hook =
|
|
10451
|
-
const router =
|
|
10706
|
+
const hook = ASTUtils29.findVariable(context.sourceCode.getScope(hookCallee), hookCallee.name);
|
|
10707
|
+
const router = ASTUtils29.findVariable(context.sourceCode.getScope(node.id), node.id.name);
|
|
10452
10708
|
if (hook !== null && router !== null && routerHooks.has(hook)) routers.add(router);
|
|
10453
10709
|
}
|
|
10454
10710
|
},
|
|
10455
10711
|
CallExpression(node) {
|
|
10456
10712
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
10457
10713
|
const receiver = unwrappedNodeCallee.type === AST_NODE_TYPES51.MemberExpression ? unwrapExpression(unwrappedNodeCallee.object) : unwrappedNodeCallee;
|
|
10458
|
-
if (unwrappedNodeCallee.type !== AST_NODE_TYPES51.MemberExpression || receiver.type !== AST_NODE_TYPES51.Identifier ||
|
|
10459
|
-
const router =
|
|
10714
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES51.MemberExpression || receiver.type !== AST_NODE_TYPES51.Identifier || ASTUtils29.getPropertyName(unwrappedNodeCallee) === null || (ASTUtils29.getPropertyName(unwrappedNodeCallee) ?? "") !== "refresh") return;
|
|
10715
|
+
const router = ASTUtils29.findVariable(
|
|
10460
10716
|
context.sourceCode.getScope(receiver),
|
|
10461
10717
|
receiver.name
|
|
10462
10718
|
);
|
|
@@ -11019,7 +11275,7 @@ function proseTokens(text) {
|
|
|
11019
11275
|
}
|
|
11020
11276
|
|
|
11021
11277
|
// src/rules/no-secret-in-log.ts
|
|
11022
|
-
import { ASTUtils as
|
|
11278
|
+
import { ASTUtils as ASTUtils30 } from "@typescript-eslint/utils";
|
|
11023
11279
|
|
|
11024
11280
|
// src/rules/_secret-names.ts
|
|
11025
11281
|
var SECRET_WORDS = /* @__PURE__ */ new Set([
|
|
@@ -11242,7 +11498,7 @@ function hasRedactionMarker(name) {
|
|
|
11242
11498
|
}
|
|
11243
11499
|
function valueName(node) {
|
|
11244
11500
|
if (node.type === "Identifier") return node.name;
|
|
11245
|
-
return node.type === "MemberExpression" ?
|
|
11501
|
+
return node.type === "MemberExpression" ? ASTUtils30.getPropertyName(node) : null;
|
|
11246
11502
|
}
|
|
11247
11503
|
function isRawSecretValue(prop) {
|
|
11248
11504
|
if (prop.shorthand) {
|
|
@@ -11293,11 +11549,11 @@ function rawBlobValueName(value) {
|
|
|
11293
11549
|
return isRawBlobName(value.name) ? value.name : null;
|
|
11294
11550
|
}
|
|
11295
11551
|
if (value.type === "MemberExpression") {
|
|
11296
|
-
const name =
|
|
11552
|
+
const name = ASTUtils30.getPropertyName(value);
|
|
11297
11553
|
return name !== null && isRawBlobName(name) ? name : null;
|
|
11298
11554
|
}
|
|
11299
11555
|
if (value.type === "CallExpression" && value.arguments.length === 0 && unwrappedValueCallee?.type === "MemberExpression" && unwrappedValueCallee.object.type === "Identifier" && /^(?:res|response|\w+Response)$/.test(unwrappedValueCallee.object.name)) {
|
|
11300
|
-
const name =
|
|
11556
|
+
const name = ASTUtils30.getPropertyName(unwrappedValueCallee);
|
|
11301
11557
|
return name === "json" || name === "text" ? `${unwrappedValueCallee.object.name}.${name}()` : null;
|
|
11302
11558
|
}
|
|
11303
11559
|
return null;
|
|
@@ -11317,7 +11573,7 @@ function isRawBlobName(name) {
|
|
|
11317
11573
|
const last = tokens.at(-1);
|
|
11318
11574
|
return last !== void 0 && RAW_BLOB_WORDS.has(last);
|
|
11319
11575
|
}
|
|
11320
|
-
function
|
|
11576
|
+
function propertyKeyName(prop) {
|
|
11321
11577
|
if (prop.computed) {
|
|
11322
11578
|
return null;
|
|
11323
11579
|
}
|
|
@@ -11388,12 +11644,12 @@ var no_secret_in_log_default = createRule({
|
|
|
11388
11644
|
continue;
|
|
11389
11645
|
}
|
|
11390
11646
|
for (const property of literalProperties(entry.argument)) {
|
|
11391
|
-
const key2 =
|
|
11647
|
+
const key2 = propertyKeyName(property);
|
|
11392
11648
|
if (key2 !== null) effective.set(key2, property);
|
|
11393
11649
|
}
|
|
11394
11650
|
continue;
|
|
11395
11651
|
}
|
|
11396
|
-
const key =
|
|
11652
|
+
const key = propertyKeyName(entry);
|
|
11397
11653
|
if (key === null) {
|
|
11398
11654
|
effective.clear();
|
|
11399
11655
|
continue;
|
|
@@ -11414,7 +11670,7 @@ var no_secret_in_log_default = createRule({
|
|
|
11414
11670
|
return false;
|
|
11415
11671
|
}
|
|
11416
11672
|
function reportSecretProperty(prop) {
|
|
11417
|
-
const keyName =
|
|
11673
|
+
const keyName = propertyKeyName(prop);
|
|
11418
11674
|
const value = valueName(prop.value);
|
|
11419
11675
|
if (value !== null && hasRedactionMarker(value)) return false;
|
|
11420
11676
|
const name = value !== null && isSecretKeyword(value) ? value : keyName;
|
|
@@ -11605,7 +11861,7 @@ var no_select_star_default = createRule({
|
|
|
11605
11861
|
});
|
|
11606
11862
|
|
|
11607
11863
|
// src/rules/no-sentinel-return-on-catch.ts
|
|
11608
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES55, ASTUtils as
|
|
11864
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES55, ASTUtils as ASTUtils31 } from "@typescript-eslint/utils";
|
|
11609
11865
|
var NO_SENTINEL_RETURN_ON_CATCH_DOCUMENTATION = {
|
|
11610
11866
|
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.",
|
|
11611
11867
|
rationale: "An unreported fallback makes operational failure indistinguishable from a legitimate empty result.",
|
|
@@ -11759,8 +12015,8 @@ function argsIncludeBinding(args, caughtName) {
|
|
|
11759
12015
|
}
|
|
11760
12016
|
function isParseShapedNode(node) {
|
|
11761
12017
|
const unwrappedNodeCallee = node.type === "CallExpression" || node.type === "NewExpression" ? unwrapExpression(node.callee) : null;
|
|
11762
|
-
if (node.type === AST_NODE_TYPES55.CallExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES55.MemberExpression &&
|
|
11763
|
-
return (
|
|
12018
|
+
if (node.type === AST_NODE_TYPES55.CallExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES55.MemberExpression && ASTUtils31.getPropertyName(unwrappedNodeCallee) !== null) {
|
|
12019
|
+
return (ASTUtils31.getPropertyName(unwrappedNodeCallee) ?? "") === "parse";
|
|
11764
12020
|
}
|
|
11765
12021
|
if (node.type === AST_NODE_TYPES55.NewExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES55.Identifier) {
|
|
11766
12022
|
return SAFE_PARSE_CONSTRUCTORS.has(unwrappedNodeCallee.name);
|
|
@@ -11774,21 +12030,21 @@ var SAFE_PARSE_CONSTRUCTORS = /* @__PURE__ */ new Set([
|
|
|
11774
12030
|
]);
|
|
11775
12031
|
function isBodyDecodeNode(node) {
|
|
11776
12032
|
const unwrappedNodeCallee = node.type === "CallExpression" || node.type === "NewExpression" ? unwrapExpression(node.callee) : null;
|
|
11777
|
-
return node.type === AST_NODE_TYPES55.CallExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES55.MemberExpression &&
|
|
12033
|
+
return node.type === AST_NODE_TYPES55.CallExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES55.MemberExpression && ASTUtils31.getPropertyName(unwrappedNodeCallee) !== null && BODY_DECODE_METHODS.has(ASTUtils31.getPropertyName(unwrappedNodeCallee) ?? "");
|
|
11778
12034
|
}
|
|
11779
12035
|
function isSafeParseSupportCall(node) {
|
|
11780
12036
|
const callee = unwrapExpression(node.callee);
|
|
11781
|
-
if (callee.type !== AST_NODE_TYPES55.MemberExpression ||
|
|
12037
|
+
if (callee.type !== AST_NODE_TYPES55.MemberExpression || ASTUtils31.getPropertyName(callee) === null) {
|
|
11782
12038
|
return false;
|
|
11783
12039
|
}
|
|
11784
|
-
if ((
|
|
12040
|
+
if ((ASTUtils31.getPropertyName(callee) ?? "") === "isArray" && callee.object.type === AST_NODE_TYPES55.Identifier && callee.object.name === "Array") {
|
|
11785
12041
|
return true;
|
|
11786
12042
|
}
|
|
11787
|
-
if ((
|
|
12043
|
+
if ((ASTUtils31.getPropertyName(callee) ?? "") !== "getItem") return false;
|
|
11788
12044
|
if (callee.object.type === AST_NODE_TYPES55.Identifier && (callee.object.name === "localStorage" || callee.object.name === "sessionStorage")) {
|
|
11789
12045
|
return true;
|
|
11790
12046
|
}
|
|
11791
|
-
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") &&
|
|
12047
|
+
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") && ASTUtils31.getPropertyName(callee.object) !== null && ((ASTUtils31.getPropertyName(callee.object) ?? "") === "localStorage" || (ASTUtils31.getPropertyName(callee.object) ?? "") === "sessionStorage");
|
|
11792
12048
|
}
|
|
11793
12049
|
var BODY_DECODE_METHODS = /* @__PURE__ */ new Set([
|
|
11794
12050
|
"json",
|
|
@@ -11982,7 +12238,7 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
11982
12238
|
if (matcher.isLoggingCall(current)) {
|
|
11983
12239
|
return caughtName === null || argsIncludeBinding(current.arguments, caughtName);
|
|
11984
12240
|
}
|
|
11985
|
-
const name =
|
|
12241
|
+
const name = calleeName(current.callee);
|
|
11986
12242
|
return name !== null && REPORT_NAME_RE.test(name) && (caughtName === null || argsIncludeBinding(current.arguments, caughtName));
|
|
11987
12243
|
});
|
|
11988
12244
|
}
|
|
@@ -12000,7 +12256,7 @@ var no_sentinel_return_on_catch_default = createRule({
|
|
|
12000
12256
|
return;
|
|
12001
12257
|
}
|
|
12002
12258
|
const returned = unwrapSentinelExpression(last.argument);
|
|
12003
|
-
if (returned?.type === AST_NODE_TYPES55.Identifier && returned.name === "undefined" && (
|
|
12259
|
+
if (returned?.type === AST_NODE_TYPES55.Identifier && returned.name === "undefined" && (ASTUtils31.findVariable(context.sourceCode.getScope(returned), returned.name)?.defs.length ?? 0) > 0) return;
|
|
12004
12260
|
if (containsThrow(node.body)) {
|
|
12005
12261
|
return;
|
|
12006
12262
|
}
|
|
@@ -12043,7 +12299,7 @@ function isNonReadingProperty(current, key) {
|
|
|
12043
12299
|
}
|
|
12044
12300
|
|
|
12045
12301
|
// src/rules/no-silent-promise-catch.ts
|
|
12046
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES56, ASTUtils as
|
|
12302
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES56, ASTUtils as ASTUtils32 } from "@typescript-eslint/utils";
|
|
12047
12303
|
var NO_SILENT_PROMISE_CATCH_DOCUMENTATION = {
|
|
12048
12304
|
summary: "Disallow `.catch()` and second-argument `.then()` handlers that silently swallow a rejection; log, rethrow, or handle the error.",
|
|
12049
12305
|
rationale: "A swallowed rejection hides failures and gives callers an indistinguishable fallback value.",
|
|
@@ -12188,7 +12444,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
12188
12444
|
if (seen.has(node)) return false;
|
|
12189
12445
|
seen.add(node);
|
|
12190
12446
|
if (node.type === AST_NODE_TYPES56.Identifier) {
|
|
12191
|
-
const binding =
|
|
12447
|
+
const binding = ASTUtils32.findVariable(context.sourceCode.getScope(node), node.name);
|
|
12192
12448
|
if (binding === null || binding.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
12193
12449
|
const [definition] = binding.defs;
|
|
12194
12450
|
return binding.defs.length === 1 && definition?.node.type === AST_NODE_TYPES56.VariableDeclarator && definition.node.init !== null && isZodSchema(definition.node.init, seen);
|
|
@@ -12198,7 +12454,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
12198
12454
|
const method = staticPropertyName(unwrappedNodeCallee, context.sourceCode);
|
|
12199
12455
|
if (object.type === AST_NODE_TYPES56.MemberExpression && staticPropertyName(object, context.sourceCode) === "coerce" && method !== null && ["bigint", "boolean", "number", "string"].includes(method)) object = object.object;
|
|
12200
12456
|
if (object.type === AST_NODE_TYPES56.Identifier && method !== null && ZOD_CONSTRUCTORS.has(method)) {
|
|
12201
|
-
const binding =
|
|
12457
|
+
const binding = ASTUtils32.findVariable(context.sourceCode.getScope(object), object.name);
|
|
12202
12458
|
if (binding?.defs.some((definition) => {
|
|
12203
12459
|
const specifier = definition.node;
|
|
12204
12460
|
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));
|
|
@@ -12266,7 +12522,7 @@ var no_silent_promise_catch_default = createRule({
|
|
|
12266
12522
|
});
|
|
12267
12523
|
|
|
12268
12524
|
// src/rules/no-sleep-in-test-body.ts
|
|
12269
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES57, ASTUtils as
|
|
12525
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES57, ASTUtils as ASTUtils33 } from "@typescript-eslint/utils";
|
|
12270
12526
|
var NO_SLEEP_IN_TEST_BODY_DOCUMENTATION = {
|
|
12271
12527
|
summary: "Avoid fixed timed sleeps directly in test bodies; synchronize on observable behavior or use controlled timers.",
|
|
12272
12528
|
rationale: "Wall-clock delays make test correctness depend on scheduler and machine speed.",
|
|
@@ -12353,7 +12609,7 @@ function testCallerName(callee, source) {
|
|
|
12353
12609
|
return name !== null && TEST_CALLERS2.has(name) ? name : null;
|
|
12354
12610
|
}
|
|
12355
12611
|
if (callee.type === AST_NODE_TYPES57.MemberExpression) {
|
|
12356
|
-
const member =
|
|
12612
|
+
const member = ASTUtils33.getPropertyName(callee);
|
|
12357
12613
|
return member !== null && TEST_MODIFIERS3.has(member) ? testCallerName(callee.object, source) : null;
|
|
12358
12614
|
}
|
|
12359
12615
|
if (callee.type === AST_NODE_TYPES57.CallExpression) return testCallerName(callee.callee, source);
|
|
@@ -12391,8 +12647,8 @@ var no_sleep_in_test_body_default = createRule({
|
|
|
12391
12647
|
return {
|
|
12392
12648
|
NewExpression(node) {
|
|
12393
12649
|
if (isPromiseSleep(node)) {
|
|
12394
|
-
const constructor =
|
|
12395
|
-
const timer =
|
|
12650
|
+
const constructor = ASTUtils33.findVariable(context.sourceCode.getScope(node), "Promise");
|
|
12651
|
+
const timer = ASTUtils33.findVariable(context.sourceCode.getScope(node), "setTimeout");
|
|
12396
12652
|
if ((constructor?.defs.length ?? 0) > 0 || (timer?.defs.length ?? 0) > 0) return;
|
|
12397
12653
|
report2(node);
|
|
12398
12654
|
}
|
|
@@ -12401,7 +12657,7 @@ var no_sleep_in_test_body_default = createRule({
|
|
|
12401
12657
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
12402
12658
|
if (isHelperSleep(node)) {
|
|
12403
12659
|
if (unwrappedNodeCallee.type !== AST_NODE_TYPES57.Identifier) return;
|
|
12404
|
-
const variable =
|
|
12660
|
+
const variable = ASTUtils33.findVariable(context.sourceCode.getScope(node), unwrappedNodeCallee.name);
|
|
12405
12661
|
if (variable?.defs.some((definition) => definition.type !== "ImportBinding")) return;
|
|
12406
12662
|
report2(node);
|
|
12407
12663
|
}
|
|
@@ -12411,7 +12667,7 @@ var no_sleep_in_test_body_default = createRule({
|
|
|
12411
12667
|
});
|
|
12412
12668
|
|
|
12413
12669
|
// src/rules/no-storage-in-stateless-modules.ts
|
|
12414
|
-
import { ASTUtils as
|
|
12670
|
+
import { ASTUtils as ASTUtils34, AST_NODE_TYPES as AST_NODE_TYPES58 } from "@typescript-eslint/utils";
|
|
12415
12671
|
var DEFAULT_METHODS2 = [
|
|
12416
12672
|
"prepare",
|
|
12417
12673
|
"put",
|
|
@@ -12446,7 +12702,7 @@ function storageMethodName(node, methods) {
|
|
|
12446
12702
|
const callee = unwrapExpression(node.callee);
|
|
12447
12703
|
const calleeReceiver = callee.type === AST_NODE_TYPES58.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
12448
12704
|
if (callee.type !== AST_NODE_TYPES58.MemberExpression) return null;
|
|
12449
|
-
const name =
|
|
12705
|
+
const name = ASTUtils34.getPropertyName(callee);
|
|
12450
12706
|
if (name === null || !methods.has(name)) {
|
|
12451
12707
|
return null;
|
|
12452
12708
|
}
|
|
@@ -12467,7 +12723,7 @@ function isStorageLikeReceiver(node) {
|
|
|
12467
12723
|
if (node.type !== AST_NODE_TYPES58.MemberExpression) {
|
|
12468
12724
|
return false;
|
|
12469
12725
|
}
|
|
12470
|
-
const name =
|
|
12726
|
+
const name = ASTUtils34.getPropertyName(node);
|
|
12471
12727
|
if (name !== null && isStorageIdentifier(name)) {
|
|
12472
12728
|
return true;
|
|
12473
12729
|
}
|
|
@@ -12546,7 +12802,7 @@ function hasSqlPreparationEvidence(node, callee) {
|
|
|
12546
12802
|
if (!/^\s*(?:SELECT|WITH|INSERT|UPDATE|DELETE|REPLACE|CREATE|ALTER|DROP|PRAGMA|EXPLAIN)\b/iu.test(stripSqlNoise(text))) return false;
|
|
12547
12803
|
} else {
|
|
12548
12804
|
const receiver = callee.object;
|
|
12549
|
-
const receiverName = receiver.type === AST_NODE_TYPES58.Identifier ? receiver.name : receiver.type === AST_NODE_TYPES58.MemberExpression ?
|
|
12805
|
+
const receiverName = receiver.type === AST_NODE_TYPES58.Identifier ? receiver.name : receiver.type === AST_NODE_TYPES58.MemberExpression ? ASTUtils34.getPropertyName(receiver) ?? "" : "";
|
|
12550
12806
|
if (!/^(?:db|database|connection)$/iu.test(receiverName)) return false;
|
|
12551
12807
|
}
|
|
12552
12808
|
return true;
|
|
@@ -12809,7 +13065,7 @@ var no_string_concat_in_loop_default = createRule({
|
|
|
12809
13065
|
});
|
|
12810
13066
|
|
|
12811
13067
|
// src/rules/no-duplicate-test-case.ts
|
|
12812
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES59, ASTUtils as
|
|
13068
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES59, ASTUtils as ASTUtils35 } from "@typescript-eslint/utils";
|
|
12813
13069
|
var TEST_MODULES = /* @__PURE__ */ new Set(["vitest", "@jest/globals", "bun:test"]);
|
|
12814
13070
|
var TEST_NAMES2 = /* @__PURE__ */ new Set(["it", "test"]);
|
|
12815
13071
|
var MODIFIERS = /* @__PURE__ */ new Set(["only", "skip", "concurrent", "fails", "failing", "todo"]);
|
|
@@ -12831,15 +13087,15 @@ var NO_DUPLICATE_TEST_CASE_DOCUMENTATION = {
|
|
|
12831
13087
|
};
|
|
12832
13088
|
function frameworkEach(node, sourceCode) {
|
|
12833
13089
|
let callee = unwrapExpression(node.callee);
|
|
12834
|
-
if (callee.type !== AST_NODE_TYPES59.MemberExpression ||
|
|
13090
|
+
if (callee.type !== AST_NODE_TYPES59.MemberExpression || ASTUtils35.getPropertyName(callee) !== "each") return false;
|
|
12835
13091
|
callee = unwrapExpression(callee.object);
|
|
12836
13092
|
while (callee.type === AST_NODE_TYPES59.MemberExpression) {
|
|
12837
|
-
const name =
|
|
13093
|
+
const name = ASTUtils35.getPropertyName(callee);
|
|
12838
13094
|
if (name === null || !MODIFIERS.has(name)) return false;
|
|
12839
13095
|
callee = unwrapExpression(callee.object);
|
|
12840
13096
|
}
|
|
12841
13097
|
if (callee.type !== AST_NODE_TYPES59.Identifier) return false;
|
|
12842
|
-
const variable =
|
|
13098
|
+
const variable = ASTUtils35.findVariable(sourceCode.getScope(callee), callee.name);
|
|
12843
13099
|
if (variable === null || variable.defs.length === 0) return TEST_NAMES2.has(callee.name);
|
|
12844
13100
|
return variable.defs.length === 1 && variable.defs.every((definition) => {
|
|
12845
13101
|
if (definition.node.type !== AST_NODE_TYPES59.ImportSpecifier) return false;
|
|
@@ -12852,7 +13108,7 @@ function table(node, sourceCode) {
|
|
|
12852
13108
|
node = unwrapExpression(node);
|
|
12853
13109
|
if (node.type === AST_NODE_TYPES59.ArrayExpression) return node;
|
|
12854
13110
|
if (node.type !== AST_NODE_TYPES59.Identifier) return null;
|
|
12855
|
-
const variable =
|
|
13111
|
+
const variable = ASTUtils35.findVariable(sourceCode.getScope(node), node.name);
|
|
12856
13112
|
const definition = variable?.defs[0];
|
|
12857
13113
|
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;
|
|
12858
13114
|
if (!variable.references.every((reference) => {
|
|
@@ -12933,7 +13189,7 @@ var no_duplicate_test_case_default = createRule({
|
|
|
12933
13189
|
});
|
|
12934
13190
|
|
|
12935
13191
|
// src/rules/no-tautological-expect.ts
|
|
12936
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES60, ASTUtils as
|
|
13192
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES60, ASTUtils as ASTUtils36 } from "@typescript-eslint/utils";
|
|
12937
13193
|
var NO_TAUTOLOGICAL_EXPECT_DOCUMENTATION = {
|
|
12938
13194
|
summary: "Disallow supported assertions known to pass from literals or immutable scalar setup.",
|
|
12939
13195
|
rationale: "An assertion determined entirely by literals does not observe the code under test and can keep passing after that code is removed.",
|
|
@@ -13001,7 +13257,7 @@ function resolveLiteral(node, sourceCode, seen = /* @__PURE__ */ new Set()) {
|
|
|
13001
13257
|
if (isLiteral(node)) return node;
|
|
13002
13258
|
if (node.type !== AST_NODE_TYPES60.Identifier || seen.has(node)) return null;
|
|
13003
13259
|
seen.add(node);
|
|
13004
|
-
const variable =
|
|
13260
|
+
const variable = ASTUtils36.findVariable(sourceCode.getScope(node), node.name);
|
|
13005
13261
|
if (variable?.defs.length !== 1) return null;
|
|
13006
13262
|
const definition = variable.defs[0];
|
|
13007
13263
|
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;
|
|
@@ -13101,13 +13357,13 @@ var no_tautological_expect_default = createRule({
|
|
|
13101
13357
|
CallExpression(node) {
|
|
13102
13358
|
const callee = unwrapExpression(node.callee);
|
|
13103
13359
|
if (callee.type !== AST_NODE_TYPES60.MemberExpression) return;
|
|
13104
|
-
const matcher =
|
|
13360
|
+
const matcher = ASTUtils36.getPropertyName(callee);
|
|
13105
13361
|
if (matcher === null) return;
|
|
13106
13362
|
const receiver = unwrapExpression(callee.object);
|
|
13107
13363
|
if (receiver.type !== AST_NODE_TYPES60.CallExpression) return;
|
|
13108
13364
|
const expectIdentifier = unwrapExpression(receiver.callee);
|
|
13109
13365
|
if (expectIdentifier.type !== AST_NODE_TYPES60.Identifier) return;
|
|
13110
|
-
const variable =
|
|
13366
|
+
const variable = ASTUtils36.findVariable(context.sourceCode.getScope(expectIdentifier), expectIdentifier.name);
|
|
13111
13367
|
if (variable !== null && variable.defs.some((definition) => {
|
|
13112
13368
|
if (definition.node.type !== AST_NODE_TYPES60.ImportSpecifier) return true;
|
|
13113
13369
|
const declaration = definition.node.parent;
|
|
@@ -14357,7 +14613,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
14357
14613
|
// src/rules/no-unsafe-mock-casting.ts
|
|
14358
14614
|
import {
|
|
14359
14615
|
AST_NODE_TYPES as AST_NODE_TYPES66,
|
|
14360
|
-
ASTUtils as
|
|
14616
|
+
ASTUtils as ASTUtils37
|
|
14361
14617
|
} from "@typescript-eslint/utils";
|
|
14362
14618
|
var MOCK_TYPE_NAMES = /* @__PURE__ */ new Set([
|
|
14363
14619
|
"Mock",
|
|
@@ -14424,7 +14680,7 @@ var no_unsafe_mock_casting_default = createRule({
|
|
|
14424
14680
|
const directBindings = /* @__PURE__ */ new Set();
|
|
14425
14681
|
const namespaceBindings = /* @__PURE__ */ new Set();
|
|
14426
14682
|
function resolve2(identifier) {
|
|
14427
|
-
return
|
|
14683
|
+
return ASTUtils37.findVariable(
|
|
14428
14684
|
context.sourceCode.getScope(identifier),
|
|
14429
14685
|
identifier.name
|
|
14430
14686
|
);
|
|
@@ -14471,7 +14727,7 @@ var no_unsafe_mock_casting_default = createRule({
|
|
|
14471
14727
|
});
|
|
14472
14728
|
|
|
14473
14729
|
// src/rules/no-unsafe-test-double-cast.ts
|
|
14474
|
-
import { ASTUtils as
|
|
14730
|
+
import { ASTUtils as ASTUtils38, AST_NODE_TYPES as AST_NODE_TYPES67 } from "@typescript-eslint/utils";
|
|
14475
14731
|
var NO_UNSAFE_TEST_DOUBLE_CAST_DOCUMENTATION = {
|
|
14476
14732
|
summary: "Disallow mock-backed test doubles that bypass collaborator contracts through double assertions.",
|
|
14477
14733
|
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.",
|
|
@@ -14501,7 +14757,7 @@ function isMockFactory(node, source) {
|
|
|
14501
14757
|
const unwrappedNodeCallee = node.type === "CallExpression" || node.type === "NewExpression" ? unwrapExpression(node.callee) : null;
|
|
14502
14758
|
if (node.type !== AST_NODE_TYPES67.CallExpression || unwrappedNodeCallee?.type !== AST_NODE_TYPES67.MemberExpression) return false;
|
|
14503
14759
|
const receiver = unwrapExpression(unwrappedNodeCallee.object);
|
|
14504
|
-
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)) &&
|
|
14760
|
+
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)) && ASTUtils38.getPropertyName(unwrappedNodeCallee) !== null && ["fn", "spyOn"].includes(ASTUtils38.getPropertyName(unwrappedNodeCallee) ?? "");
|
|
14505
14761
|
}
|
|
14506
14762
|
var no_unsafe_test_double_cast_default = createRule({
|
|
14507
14763
|
name: "no-unsafe-test-double-cast",
|
|
@@ -14527,7 +14783,7 @@ var no_unsafe_test_double_cast_default = createRule({
|
|
|
14527
14783
|
});
|
|
14528
14784
|
|
|
14529
14785
|
// src/rules/no-first-party-module-mock.ts
|
|
14530
|
-
import { ASTUtils as
|
|
14786
|
+
import { ASTUtils as ASTUtils39, AST_NODE_TYPES as AST_NODE_TYPES68 } from "@typescript-eslint/utils";
|
|
14531
14787
|
var NO_FIRST_PARTY_MODULE_MOCK_DOCUMENTATION = {
|
|
14532
14788
|
summary: "Prefer injected collaborators over mocking maintained first-party modules in tests.",
|
|
14533
14789
|
rationale: "Replacing an owned module couples tests to its lookup path and can verify mock wiring while bypassing the real implementation contract.",
|
|
@@ -14558,7 +14814,7 @@ var no_first_party_module_mock_default = createRule({
|
|
|
14558
14814
|
CallExpression(node) {
|
|
14559
14815
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
14560
14816
|
const receiver = unwrappedNodeCallee.type === AST_NODE_TYPES68.MemberExpression ? unwrapExpression(unwrappedNodeCallee.object) : unwrappedNodeCallee;
|
|
14561
|
-
if (unwrappedNodeCallee.type !== AST_NODE_TYPES68.MemberExpression || receiver.type !== AST_NODE_TYPES68.Identifier ||
|
|
14817
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES68.MemberExpression || receiver.type !== AST_NODE_TYPES68.Identifier || ASTUtils39.getPropertyName(unwrappedNodeCallee) === null || !["mock", "doMock"].includes(ASTUtils39.getPropertyName(unwrappedNodeCallee) ?? "")) return;
|
|
14562
14818
|
const framework = importedTestMockNamespace(context.sourceCode, receiver);
|
|
14563
14819
|
if (framework === null || framework === "jest" && mayBeVirtual(node.arguments[2])) return;
|
|
14564
14820
|
const argument = node.arguments[0] === void 0 ? void 0 : unwrapExpression(node.arguments[0]);
|
|
@@ -14584,7 +14840,7 @@ function mayBeVirtual(options) {
|
|
|
14584
14840
|
import {
|
|
14585
14841
|
ESLintUtils as ESLintUtils10,
|
|
14586
14842
|
AST_NODE_TYPES as AST_NODE_TYPES69,
|
|
14587
|
-
ASTUtils as
|
|
14843
|
+
ASTUtils as ASTUtils40
|
|
14588
14844
|
} from "@typescript-eslint/utils";
|
|
14589
14845
|
import * as ts9 from "typescript";
|
|
14590
14846
|
var NO_ZOD_NATIVE_ENUM_DOCUMENTATION = {
|
|
@@ -14691,7 +14947,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
14691
14947
|
const zodImportedBindings = /* @__PURE__ */ new Map();
|
|
14692
14948
|
const zodNamespaceBindings = /* @__PURE__ */ new Set();
|
|
14693
14949
|
function resolvedBinding(identifier) {
|
|
14694
|
-
return
|
|
14950
|
+
return ASTUtils40.findVariable(
|
|
14695
14951
|
sourceCode.getScope(identifier),
|
|
14696
14952
|
identifier.name
|
|
14697
14953
|
);
|
|
@@ -14699,7 +14955,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
14699
14955
|
function isZodMemberCall(node, api) {
|
|
14700
14956
|
const callee = unwrapExpression(node.callee);
|
|
14701
14957
|
const calleeReceiver = callee.type === AST_NODE_TYPES69.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
14702
|
-
if (callee.type === AST_NODE_TYPES69.MemberExpression && calleeReceiver.type === AST_NODE_TYPES69.Identifier &&
|
|
14958
|
+
if (callee.type === AST_NODE_TYPES69.MemberExpression && calleeReceiver.type === AST_NODE_TYPES69.Identifier && ASTUtils40.getPropertyName(callee) === api) {
|
|
14703
14959
|
const binding = resolvedBinding(calleeReceiver);
|
|
14704
14960
|
return binding !== null && zodNamespaceBindings.has(binding);
|
|
14705
14961
|
}
|
|
@@ -14758,7 +15014,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
14758
15014
|
});
|
|
14759
15015
|
|
|
14760
15016
|
// src/rules/test-loops-over-literal-cases.ts
|
|
14761
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES70, ASTUtils as
|
|
15017
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES70, ASTUtils as ASTUtils41 } from "@typescript-eslint/utils";
|
|
14762
15018
|
var TEST_LOOPS_OVER_LITERAL_CASES_DOCUMENTATION = {
|
|
14763
15019
|
summary: "Disallow assertions over an inline literal case loop in a test; parameterization reports and names every case independently.",
|
|
14764
15020
|
rationale: "A loop is reported as one test, so failures hide the individual case name and may stop later cases from running.",
|
|
@@ -14911,7 +15167,7 @@ var test_loops_over_literal_cases_default = createRule({
|
|
|
14911
15167
|
}
|
|
14912
15168
|
const capturesSetup = walkOwnScope2(node.body, (current) => {
|
|
14913
15169
|
if (current.type !== AST_NODE_TYPES70.Identifier) return false;
|
|
14914
|
-
const variable =
|
|
15170
|
+
const variable = ASTUtils41.findVariable(context.sourceCode.getScope(current), current.name);
|
|
14915
15171
|
if (variable === null || !variable.references.some((reference) => reference.identifier === current)) return false;
|
|
14916
15172
|
return variable.defs.some((definition) => {
|
|
14917
15173
|
const declaration = definition.name;
|
|
@@ -15365,7 +15621,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
15365
15621
|
});
|
|
15366
15622
|
|
|
15367
15623
|
// src/rules/prefer-input-group-search.ts
|
|
15368
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES75, ASTUtils as
|
|
15624
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES75, ASTUtils as ASTUtils42 } from "@typescript-eslint/utils";
|
|
15369
15625
|
var PREFER_INPUT_GROUP_SEARCH_DOCUMENTATION = {
|
|
15370
15626
|
summary: "Require search icons and shared Input controls in the same visual wrapper to use InputGroup.",
|
|
15371
15627
|
rationale: "The shared compound control provides consistent spacing, focus behavior, and accessible composition.",
|
|
@@ -15489,7 +15745,7 @@ var prefer_input_group_search_default = createRule({
|
|
|
15489
15745
|
JSXOpeningElement(node) {
|
|
15490
15746
|
const name = elementName(node);
|
|
15491
15747
|
if (name === null) return;
|
|
15492
|
-
const binding =
|
|
15748
|
+
const binding = ASTUtils42.findVariable(context.sourceCode.getScope(node), name);
|
|
15493
15749
|
if (binding?.defs.length !== 1 || binding.defs[0]?.node.type !== AST_NODE_TYPES75.ImportSpecifier || binding.defs[0].node.importKind === "type") return;
|
|
15494
15750
|
const occurrence = {
|
|
15495
15751
|
ancestors: context.sourceCode.getAncestors(node),
|
|
@@ -15529,7 +15785,7 @@ var prefer_input_group_search_default = createRule({
|
|
|
15529
15785
|
|
|
15530
15786
|
// src/rules/prefer-millisecond-control-duration-schema.ts
|
|
15531
15787
|
import {
|
|
15532
|
-
ASTUtils as
|
|
15788
|
+
ASTUtils as ASTUtils43,
|
|
15533
15789
|
AST_NODE_TYPES as AST_NODE_TYPES77
|
|
15534
15790
|
} from "@typescript-eslint/utils";
|
|
15535
15791
|
|
|
@@ -15608,7 +15864,7 @@ var prefer_millisecond_control_duration_schema_default = createRule({
|
|
|
15608
15864
|
const objectFactories = /* @__PURE__ */ new Set();
|
|
15609
15865
|
const numberFactories = /* @__PURE__ */ new Set();
|
|
15610
15866
|
function binding(identifier) {
|
|
15611
|
-
return
|
|
15867
|
+
return ASTUtils43.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
15612
15868
|
}
|
|
15613
15869
|
function record(target, identifier) {
|
|
15614
15870
|
const variable = binding(identifier);
|
|
@@ -15621,7 +15877,7 @@ var prefer_millisecond_control_duration_schema_default = createRule({
|
|
|
15621
15877
|
const variable2 = binding(callee);
|
|
15622
15878
|
return variable2 !== null && objectFactories.has(variable2);
|
|
15623
15879
|
}
|
|
15624
|
-
if (callee.type !== AST_NODE_TYPES77.MemberExpression || calleeReceiver.type !== AST_NODE_TYPES77.Identifier ||
|
|
15880
|
+
if (callee.type !== AST_NODE_TYPES77.MemberExpression || calleeReceiver.type !== AST_NODE_TYPES77.Identifier || ASTUtils43.getPropertyName(callee) === null || (ASTUtils43.getPropertyName(callee) ?? "") !== "object" && (ASTUtils43.getPropertyName(callee) ?? "") !== "strictObject") {
|
|
15625
15881
|
return false;
|
|
15626
15882
|
}
|
|
15627
15883
|
const variable = binding(calleeReceiver);
|
|
@@ -15636,12 +15892,12 @@ var prefer_millisecond_control_duration_schema_default = createRule({
|
|
|
15636
15892
|
const variable = binding(callee);
|
|
15637
15893
|
return variable !== null && numberFactories.has(variable);
|
|
15638
15894
|
}
|
|
15639
|
-
if (callee.type !== AST_NODE_TYPES77.MemberExpression ||
|
|
15895
|
+
if (callee.type !== AST_NODE_TYPES77.MemberExpression || ASTUtils43.getPropertyName(callee) === null) return false;
|
|
15640
15896
|
if (calleeReceiver.type === AST_NODE_TYPES77.Identifier) {
|
|
15641
15897
|
const variable = binding(calleeReceiver);
|
|
15642
|
-
return (
|
|
15898
|
+
return (ASTUtils43.getPropertyName(callee) ?? "") === "number" && variable !== null && zodNamespaces.has(variable);
|
|
15643
15899
|
}
|
|
15644
|
-
return ["int", "min", "max", "positive", "nonnegative", "finite", "multipleOf", "optional", "nullable", "nullish", "default", "describe", "brand", "readonly"].includes(
|
|
15900
|
+
return ["int", "min", "max", "positive", "nonnegative", "finite", "multipleOf", "optional", "nullable", "nullish", "default", "describe", "brand", "readonly"].includes(ASTUtils43.getPropertyName(callee) ?? "") && isNumericSchema(calleeReceiver);
|
|
15645
15901
|
}
|
|
15646
15902
|
return {
|
|
15647
15903
|
ImportDeclaration(node) {
|
|
@@ -15674,7 +15930,7 @@ var prefer_millisecond_control_duration_schema_default = createRule({
|
|
|
15674
15930
|
});
|
|
15675
15931
|
|
|
15676
15932
|
// src/rules/prefer-immutable-module-constant.ts
|
|
15677
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES78, ASTUtils as
|
|
15933
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES78, ASTUtils as ASTUtils44 } from "@typescript-eslint/utils";
|
|
15678
15934
|
var PREFER_IMMUTABLE_MODULE_CONSTANT_DOCUMENTATION = {
|
|
15679
15935
|
summary: "Require module-level constant collections to expose readonly state.",
|
|
15680
15936
|
rationale: "A const binding prevents reassignment but does not stop callers from mutating its array, object, Set, or Map contents.",
|
|
@@ -15893,15 +16149,15 @@ var prefer_immutable_module_constant_default = createRule({
|
|
|
15893
16149
|
create(context) {
|
|
15894
16150
|
const sourceCode = context.sourceCode;
|
|
15895
16151
|
const isUnshadowedGlobal3 = (identifier) => {
|
|
15896
|
-
const variable =
|
|
16152
|
+
const variable = ASTUtils44.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
15897
16153
|
return variable === null || variable.defs.length === 0;
|
|
15898
16154
|
};
|
|
15899
16155
|
const isUnshadowedType = (identifier) => {
|
|
15900
|
-
const variable =
|
|
16156
|
+
const variable = ASTUtils44.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
15901
16157
|
return variable === null || !variable.defs.some((definition) => definition.isTypeDefinition);
|
|
15902
16158
|
};
|
|
15903
16159
|
const resolveLocalType = (identifier) => {
|
|
15904
|
-
const variable =
|
|
16160
|
+
const variable = ASTUtils44.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
15905
16161
|
const definitions = variable?.defs.filter((definition) => definition.isTypeDefinition) ?? [];
|
|
15906
16162
|
const declaration = definitions.length === 1 ? definitions[0]?.node : void 0;
|
|
15907
16163
|
return declaration?.type === AST_NODE_TYPES78.TSTypeAliasDeclaration || declaration?.type === AST_NODE_TYPES78.TSTypeParameter ? declaration : void 0;
|
|
@@ -16395,7 +16651,7 @@ function matchingAliasTargets(paths, alias) {
|
|
|
16395
16651
|
}
|
|
16396
16652
|
|
|
16397
16653
|
// src/rules/prefer-module-level-constant.ts
|
|
16398
|
-
import { ASTUtils as
|
|
16654
|
+
import { ASTUtils as ASTUtils45, AST_NODE_TYPES as AST_NODE_TYPES80 } from "@typescript-eslint/utils";
|
|
16399
16655
|
var PREFER_MODULE_LEVEL_CONSTANT_DOCUMENTATION = {
|
|
16400
16656
|
summary: "Hoist literal-only constant collections and regexes out of function bodies to module scope so they are allocated once.",
|
|
16401
16657
|
rationale: "Recreating immutable lookup data on every call wastes allocations and obscures its constant nature.",
|
|
@@ -16523,7 +16779,7 @@ function classify(init, checkRegex, sourceCode) {
|
|
|
16523
16779
|
function unwrapObjectFreeze(node, sourceCode) {
|
|
16524
16780
|
const inner = unwrap3(node);
|
|
16525
16781
|
const callee = inner.type === AST_NODE_TYPES80.CallExpression ? unwrapExpression(inner.callee) : null;
|
|
16526
|
-
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" && (
|
|
16782
|
+
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" && (ASTUtils45.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) {
|
|
16527
16783
|
return unwrap3(inner.arguments[0]);
|
|
16528
16784
|
}
|
|
16529
16785
|
return inner;
|
|
@@ -16722,14 +16978,14 @@ function isSafeMemberRead(identifier, parent) {
|
|
|
16722
16978
|
if (grandparent.type === AST_NODE_TYPES80.UnaryExpression && grandparent.operator === "delete") {
|
|
16723
16979
|
return false;
|
|
16724
16980
|
}
|
|
16725
|
-
if (grandparent.type === AST_NODE_TYPES80.CallExpression && grandparent.callee === usage && (
|
|
16981
|
+
if (grandparent.type === AST_NODE_TYPES80.CallExpression && grandparent.callee === usage && (ASTUtils45.getPropertyName(parent) === null || MUTATING_METHODS2.has(ASTUtils45.getPropertyName(parent) ?? ""))) {
|
|
16726
16982
|
return false;
|
|
16727
16983
|
}
|
|
16728
16984
|
return true;
|
|
16729
16985
|
}
|
|
16730
16986
|
|
|
16731
16987
|
// src/rules/prefer-module-level-schema.ts
|
|
16732
|
-
import { ASTUtils as
|
|
16988
|
+
import { ASTUtils as ASTUtils46, AST_NODE_TYPES as AST_NODE_TYPES81 } from "@typescript-eslint/utils";
|
|
16733
16989
|
var PREFER_MODULE_LEVEL_SCHEMA_DOCUMENTATION = {
|
|
16734
16990
|
summary: "Declare a Zod schema at module scope when it closes over nothing in the enclosing function",
|
|
16735
16991
|
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.",
|
|
@@ -16837,7 +17093,7 @@ function schemaExpression(node) {
|
|
|
16837
17093
|
if (parent === void 0) {
|
|
16838
17094
|
return current;
|
|
16839
17095
|
}
|
|
16840
|
-
if (parent.type === AST_NODE_TYPES81.MemberExpression && parent.object === current &&
|
|
17096
|
+
if (parent.type === AST_NODE_TYPES81.MemberExpression && parent.object === current && ASTUtils46.getPropertyName(parent) !== null && TERMINAL_METHODS.has(ASTUtils46.getPropertyName(parent) ?? "")) {
|
|
16841
17097
|
return current;
|
|
16842
17098
|
}
|
|
16843
17099
|
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) {
|
|
@@ -16975,14 +17231,14 @@ var prefer_module_level_schema_default = createRule({
|
|
|
16975
17231
|
const unwrappedNodeCallee = node.type === "CallExpression" || node.type === "NewExpression" ? unwrapExpression(node.callee) : null;
|
|
16976
17232
|
if (node.type !== AST_NODE_TYPES81.CallExpression || unwrappedNodeCallee?.type !== AST_NODE_TYPES81.MemberExpression) return false;
|
|
16977
17233
|
const receiver = unwrapExpression(unwrappedNodeCallee.object);
|
|
16978
|
-
return node.type === AST_NODE_TYPES81.CallExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES81.MemberExpression &&
|
|
17234
|
+
return node.type === AST_NODE_TYPES81.CallExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES81.MemberExpression && ASTUtils46.getPropertyName(unwrappedNodeCallee) !== null && receiver.type === AST_NODE_TYPES81.Identifier && zodNamespaces.has(receiver.name);
|
|
16979
17235
|
}
|
|
16980
17236
|
function isSchemaConstruction(node) {
|
|
16981
17237
|
const callee = unwrapExpression(node.callee);
|
|
16982
17238
|
const calleeReceiver = callee.type === AST_NODE_TYPES81.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
16983
|
-
if (callee.type !== AST_NODE_TYPES81.MemberExpression ||
|
|
17239
|
+
if (callee.type !== AST_NODE_TYPES81.MemberExpression || ASTUtils46.getPropertyName(callee) === null || TERMINAL_METHODS.has(ASTUtils46.getPropertyName(callee) ?? "")) return false;
|
|
16984
17240
|
if (calleeReceiver.type === AST_NODE_TYPES81.CallExpression) return isSchemaConstruction(calleeReceiver);
|
|
16985
|
-
return isZodCall(node) && CONSTRUCTION_FACTORIES.has(
|
|
17241
|
+
return isZodCall(node) && CONSTRUCTION_FACTORIES.has(ASTUtils46.getPropertyName(callee) ?? "");
|
|
16986
17242
|
}
|
|
16987
17243
|
function hasEagerComputation(node) {
|
|
16988
17244
|
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);
|
|
@@ -16990,10 +17246,10 @@ var prefer_module_level_schema_default = createRule({
|
|
|
16990
17246
|
function isCovered(node) {
|
|
16991
17247
|
let current = node.parent ?? void 0;
|
|
16992
17248
|
while (current !== void 0) {
|
|
16993
|
-
if (current !== node && isZodCall(current) && current.callee.type === AST_NODE_TYPES81.MemberExpression &&
|
|
17249
|
+
if (current !== node && isZodCall(current) && current.callee.type === AST_NODE_TYPES81.MemberExpression && ASTUtils46.getPropertyName(current.callee) !== null && factories.has(ASTUtils46.getPropertyName(current.callee) ?? "")) {
|
|
16994
17250
|
return true;
|
|
16995
17251
|
}
|
|
16996
|
-
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 &&
|
|
17252
|
+
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 && ASTUtils46.getPropertyName(current.callee) !== null && memoCallees.has(ASTUtils46.getPropertyName(current.callee) ?? ""))) {
|
|
16997
17253
|
return true;
|
|
16998
17254
|
}
|
|
16999
17255
|
current = current.parent ?? void 0;
|
|
@@ -17022,7 +17278,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
17022
17278
|
}
|
|
17023
17279
|
function isSchemaComposition(node) {
|
|
17024
17280
|
const callee = unwrapExpression(node.callee);
|
|
17025
|
-
const isCombinator = callee.type === AST_NODE_TYPES81.MemberExpression &&
|
|
17281
|
+
const isCombinator = callee.type === AST_NODE_TYPES81.MemberExpression && ASTUtils46.getPropertyName(callee) !== null && ZOD_COMBINATOR_METHODS.has(ASTUtils46.getPropertyName(callee) ?? "");
|
|
17026
17282
|
return isCombinator || isZodCall(node);
|
|
17027
17283
|
}
|
|
17028
17284
|
function closesOverNothing(node, enclosing) {
|
|
@@ -17095,10 +17351,10 @@ var prefer_module_level_schema_default = createRule({
|
|
|
17095
17351
|
return;
|
|
17096
17352
|
}
|
|
17097
17353
|
const callee = unwrappedNodeCallee;
|
|
17098
|
-
if (
|
|
17354
|
+
if (ASTUtils46.getPropertyName(callee) === null) {
|
|
17099
17355
|
return;
|
|
17100
17356
|
}
|
|
17101
|
-
const factory =
|
|
17357
|
+
const factory = ASTUtils46.getPropertyName(callee) ?? "";
|
|
17102
17358
|
if (!factories.has(factory)) {
|
|
17103
17359
|
return;
|
|
17104
17360
|
}
|
|
@@ -17141,7 +17397,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
17141
17397
|
// src/rules/prefer-module-level-refined-schema.ts
|
|
17142
17398
|
import {
|
|
17143
17399
|
AST_NODE_TYPES as AST_NODE_TYPES82,
|
|
17144
|
-
ASTUtils as
|
|
17400
|
+
ASTUtils as ASTUtils47
|
|
17145
17401
|
} from "@typescript-eslint/utils";
|
|
17146
17402
|
var BENCHMARK_PATH_RE = /(^|[/\\])(?:benchmarks?|bench)[/\\]/;
|
|
17147
17403
|
var FACTORIES = /* @__PURE__ */ new Set([
|
|
@@ -17368,9 +17624,9 @@ function chainMemberNames(node) {
|
|
|
17368
17624
|
for (; ; ) {
|
|
17369
17625
|
current = unwrapExpression(current);
|
|
17370
17626
|
if (current.type === AST_NODE_TYPES82.MemberExpression) {
|
|
17371
|
-
if (
|
|
17627
|
+
if (ASTUtils47.getPropertyName(current) === null)
|
|
17372
17628
|
return [];
|
|
17373
|
-
names.push(
|
|
17629
|
+
names.push(ASTUtils47.getPropertyName(current) ?? "");
|
|
17374
17630
|
current = current.object;
|
|
17375
17631
|
continue;
|
|
17376
17632
|
}
|
|
@@ -17387,8 +17643,8 @@ function schemaExpression2(node) {
|
|
|
17387
17643
|
let current = node;
|
|
17388
17644
|
for (; ; ) {
|
|
17389
17645
|
const parent = current.parent ?? void 0;
|
|
17390
|
-
if (parent?.type === AST_NODE_TYPES82.MemberExpression && parent.object === current &&
|
|
17391
|
-
if (NON_SCHEMA_TERMINALS.has(
|
|
17646
|
+
if (parent?.type === AST_NODE_TYPES82.MemberExpression && parent.object === current && ASTUtils47.getPropertyName(parent) !== null && parent.parent?.type === AST_NODE_TYPES82.CallExpression && parent.parent.callee === parent) {
|
|
17647
|
+
if (NON_SCHEMA_TERMINALS.has(ASTUtils47.getPropertyName(parent) ?? "")) return current;
|
|
17392
17648
|
current = parent.parent;
|
|
17393
17649
|
continue;
|
|
17394
17650
|
}
|
|
@@ -17418,7 +17674,7 @@ var prefer_module_level_refined_schema_default = createRule({
|
|
|
17418
17674
|
return {};
|
|
17419
17675
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
17420
17676
|
function resolvedBinding(identifier) {
|
|
17421
|
-
return
|
|
17677
|
+
return ASTUtils47.findVariable(
|
|
17422
17678
|
context.sourceCode.getScope(identifier),
|
|
17423
17679
|
identifier.name
|
|
17424
17680
|
);
|
|
@@ -17444,7 +17700,7 @@ var prefer_module_level_refined_schema_default = createRule({
|
|
|
17444
17700
|
function isSchemaConstruction(node) {
|
|
17445
17701
|
const callee = unwrapExpression(node.callee);
|
|
17446
17702
|
const calleeReceiver = callee.type === AST_NODE_TYPES82.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
17447
|
-
if (callee.type !== AST_NODE_TYPES82.MemberExpression ||
|
|
17703
|
+
if (callee.type !== AST_NODE_TYPES82.MemberExpression || ASTUtils47.getPropertyName(callee) === null || NON_SCHEMA_TERMINALS.has(ASTUtils47.getPropertyName(callee) ?? "")) return false;
|
|
17448
17704
|
if (calleeReceiver.type === AST_NODE_TYPES82.CallExpression) return isSchemaConstruction(calleeReceiver);
|
|
17449
17705
|
return factoryName(node, FACTORIES) !== null || factoryName(node, COMPOSITE_FACTORIES) !== null;
|
|
17450
17706
|
}
|
|
@@ -17471,7 +17727,7 @@ var prefer_module_level_refined_schema_default = createRule({
|
|
|
17471
17727
|
function isMemoized(node) {
|
|
17472
17728
|
let current = node.parent ?? void 0;
|
|
17473
17729
|
while (current !== void 0) {
|
|
17474
|
-
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 &&
|
|
17730
|
+
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 && ASTUtils47.getPropertyName(current.callee) !== null && MEMO_CALLEES2.has(ASTUtils47.getPropertyName(current.callee) ?? "")))
|
|
17475
17731
|
return true;
|
|
17476
17732
|
current = current.parent ?? void 0;
|
|
17477
17733
|
}
|
|
@@ -17534,7 +17790,7 @@ var prefer_module_level_refined_schema_default = createRule({
|
|
|
17534
17790
|
// src/rules/prefer-multi-value-zod-literal.ts
|
|
17535
17791
|
import {
|
|
17536
17792
|
AST_NODE_TYPES as AST_NODE_TYPES83,
|
|
17537
|
-
ASTUtils as
|
|
17793
|
+
ASTUtils as ASTUtils48
|
|
17538
17794
|
} from "@typescript-eslint/utils";
|
|
17539
17795
|
var PREFER_MULTI_VALUE_ZOD_LITERAL_DOCUMENTATION = {
|
|
17540
17796
|
defaultLevel: "error",
|
|
@@ -17583,7 +17839,7 @@ function isStaticPrimitive(node, context) {
|
|
|
17583
17839
|
if (node.type === AST_NODE_TYPES83.TemplateLiteral && node.expressions.length === 0)
|
|
17584
17840
|
return true;
|
|
17585
17841
|
if (node.type === AST_NODE_TYPES83.Identifier && node.name === "undefined") {
|
|
17586
|
-
const binding =
|
|
17842
|
+
const binding = ASTUtils48.findVariable(
|
|
17587
17843
|
context.sourceCode.getScope(node),
|
|
17588
17844
|
node.name
|
|
17589
17845
|
);
|
|
@@ -17621,7 +17877,7 @@ var prefer_multi_value_zod_literal_default = createRule({
|
|
|
17621
17877
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
17622
17878
|
const zod4Bindings = /* @__PURE__ */ new Set();
|
|
17623
17879
|
function resolvedBinding(identifier) {
|
|
17624
|
-
return
|
|
17880
|
+
return ASTUtils48.findVariable(
|
|
17625
17881
|
context.sourceCode.getScope(identifier),
|
|
17626
17882
|
identifier.name
|
|
17627
17883
|
);
|
|
@@ -17629,7 +17885,7 @@ var prefer_multi_value_zod_literal_default = createRule({
|
|
|
17629
17885
|
function directMemberCall(node, binding, method) {
|
|
17630
17886
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
17631
17887
|
const receiver = unwrappedNodeCallee.type === AST_NODE_TYPES83.MemberExpression ? unwrapExpression(unwrappedNodeCallee.object) : unwrappedNodeCallee;
|
|
17632
|
-
if (unwrappedNodeCallee.type !== AST_NODE_TYPES83.MemberExpression || receiver.type !== AST_NODE_TYPES83.Identifier ||
|
|
17888
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES83.MemberExpression || receiver.type !== AST_NODE_TYPES83.Identifier || ASTUtils48.getPropertyName(unwrappedNodeCallee) === null || (ASTUtils48.getPropertyName(unwrappedNodeCallee) ?? "") !== method)
|
|
17633
17889
|
return false;
|
|
17634
17890
|
return resolvedBinding(receiver) === binding;
|
|
17635
17891
|
}
|
|
@@ -17679,7 +17935,7 @@ var prefer_multi_value_zod_literal_default = createRule({
|
|
|
17679
17935
|
});
|
|
17680
17936
|
|
|
17681
17937
|
// src/rules/prefer-nominal-id-types.ts
|
|
17682
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES84, ASTUtils as
|
|
17938
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES84, ASTUtils as ASTUtils49 } from "@typescript-eslint/utils";
|
|
17683
17939
|
var OPERATIONAL_ROLES = /* @__PURE__ */ new Set([
|
|
17684
17940
|
"request",
|
|
17685
17941
|
"trace",
|
|
@@ -17717,7 +17973,7 @@ function isNullish(node) {
|
|
|
17717
17973
|
}
|
|
17718
17974
|
function referenceCarrier(node, context, depth) {
|
|
17719
17975
|
if (node.typeName.type !== AST_NODE_TYPES84.Identifier) return void 0;
|
|
17720
|
-
const variable =
|
|
17976
|
+
const variable = ASTUtils49.findVariable(context.sourceCode.getScope(node), node.typeName.name);
|
|
17721
17977
|
const definitions = variable?.defs ?? [];
|
|
17722
17978
|
const args = node.typeArguments?.params;
|
|
17723
17979
|
if (definitions.length === 0 && ["Array", "ReadonlyArray"].includes(node.typeName.name) && args?.length === 1) {
|
|
@@ -17918,7 +18174,7 @@ var prefer_named_complex_return_type_default = createRule({
|
|
|
17918
18174
|
});
|
|
17919
18175
|
|
|
17920
18176
|
// src/rules/prefer-native-random-uuid.ts
|
|
17921
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES87, ASTUtils as
|
|
18177
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES87, ASTUtils as ASTUtils50 } from "@typescript-eslint/utils";
|
|
17922
18178
|
var PREFER_NATIVE_RANDOM_UUID_DOCUMENTATION = {
|
|
17923
18179
|
summary: "Prefer `globalThis.crypto.randomUUID()` over resolved zero-argument UUID v4 bindings from the `uuid` package.",
|
|
17924
18180
|
rationale: "The platform implementation avoids an unnecessary dependency for standard random UUID generation.",
|
|
@@ -17954,14 +18210,14 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
17954
18210
|
const directBindings = /* @__PURE__ */ new Set();
|
|
17955
18211
|
const namespaceBindings = /* @__PURE__ */ new Set();
|
|
17956
18212
|
function resolve2(identifier) {
|
|
17957
|
-
return
|
|
18213
|
+
return ASTUtils50.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
17958
18214
|
}
|
|
17959
18215
|
function record(identifier, destination) {
|
|
17960
18216
|
const variable = resolve2(identifier);
|
|
17961
18217
|
if (variable !== null) destination.add(variable);
|
|
17962
18218
|
}
|
|
17963
18219
|
function report2(node) {
|
|
17964
|
-
const globalBinding =
|
|
18220
|
+
const globalBinding = ASTUtils50.findVariable(context.sourceCode.getScope(node), "globalThis");
|
|
17965
18221
|
const canSuggest = (globalBinding?.defs.length ?? 0) === 0 && context.sourceCode.getCommentsInside(node).length === 0;
|
|
17966
18222
|
context.report({
|
|
17967
18223
|
node,
|
|
@@ -18020,7 +18276,7 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
18020
18276
|
});
|
|
18021
18277
|
|
|
18022
18278
|
// src/rules/prefer-node-crypto-hash.ts
|
|
18023
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES88, ASTUtils as
|
|
18279
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES88, ASTUtils as ASTUtils51 } from "@typescript-eslint/utils";
|
|
18024
18280
|
var PREFER_NODE_CRYPTO_HASH_DOCUMENTATION = {
|
|
18025
18281
|
defaultLevel: "warning",
|
|
18026
18282
|
summary: "Prefer the modern one-shot node:crypto hash API when streaming state is unnecessary.",
|
|
@@ -18048,7 +18304,7 @@ function isCryptoLoader(node, resolve2) {
|
|
|
18048
18304
|
if (unwrappedNodeCallee?.type === AST_NODE_TYPES88.Identifier) {
|
|
18049
18305
|
return unwrappedNodeCallee.name === "require" && isUnshadowedBuiltinIdentifier(unwrappedNodeCallee, resolve2);
|
|
18050
18306
|
}
|
|
18051
|
-
return unwrappedNodeCallee?.type === AST_NODE_TYPES88.MemberExpression && unwrappedNodeCallee.object.type === AST_NODE_TYPES88.Identifier && unwrappedNodeCallee.object.name === "process" && isUnshadowedBuiltinIdentifier(unwrappedNodeCallee.object, resolve2) &&
|
|
18307
|
+
return unwrappedNodeCallee?.type === AST_NODE_TYPES88.MemberExpression && unwrappedNodeCallee.object.type === AST_NODE_TYPES88.Identifier && unwrappedNodeCallee.object.name === "process" && isUnshadowedBuiltinIdentifier(unwrappedNodeCallee.object, resolve2) && ASTUtils51.getPropertyName(unwrappedNodeCallee) === "getBuiltinModule";
|
|
18052
18308
|
}
|
|
18053
18309
|
function isCryptoSpecifier(node) {
|
|
18054
18310
|
return node.type === AST_NODE_TYPES88.Literal && (node.value === "crypto" || node.value === "node:crypto");
|
|
@@ -18073,7 +18329,7 @@ var prefer_node_crypto_hash_default = createRule({
|
|
|
18073
18329
|
const directBindings = /* @__PURE__ */ new Set();
|
|
18074
18330
|
const namespaceBindings = /* @__PURE__ */ new Set();
|
|
18075
18331
|
function resolve2(identifier) {
|
|
18076
|
-
return
|
|
18332
|
+
return ASTUtils51.findVariable(
|
|
18077
18333
|
context.sourceCode.getScope(identifier),
|
|
18078
18334
|
identifier.name
|
|
18079
18335
|
);
|
|
@@ -18135,7 +18391,7 @@ function importedName5(node) {
|
|
|
18135
18391
|
}
|
|
18136
18392
|
function isMemberCall(node, name) {
|
|
18137
18393
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
18138
|
-
return unwrappedNodeCallee.type === AST_NODE_TYPES88.MemberExpression &&
|
|
18394
|
+
return unwrappedNodeCallee.type === AST_NODE_TYPES88.MemberExpression && ASTUtils51.getPropertyName(unwrappedNodeCallee) === name;
|
|
18139
18395
|
}
|
|
18140
18396
|
function isCreateHashCall(node, directBindings, namespaceBindings, resolve2) {
|
|
18141
18397
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
@@ -18143,7 +18399,7 @@ function isCreateHashCall(node, directBindings, namespaceBindings, resolve2) {
|
|
|
18143
18399
|
const variable2 = resolve2(unwrappedNodeCallee);
|
|
18144
18400
|
return variable2 !== null && directBindings.has(variable2);
|
|
18145
18401
|
}
|
|
18146
|
-
if (unwrappedNodeCallee.type !== AST_NODE_TYPES88.MemberExpression ||
|
|
18402
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES88.MemberExpression || ASTUtils51.getPropertyName(unwrappedNodeCallee) !== "createHash") {
|
|
18147
18403
|
return false;
|
|
18148
18404
|
}
|
|
18149
18405
|
if (isCryptoLoader(unwrappedNodeCallee.object, resolve2)) return true;
|
|
@@ -18153,7 +18409,7 @@ function isCreateHashCall(node, directBindings, namespaceBindings, resolve2) {
|
|
|
18153
18409
|
}
|
|
18154
18410
|
|
|
18155
18411
|
// src/rules/prefer-node-fs-promises.ts
|
|
18156
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES89, ASTUtils as
|
|
18412
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES89, ASTUtils as ASTUtils52 } from "@typescript-eslint/utils";
|
|
18157
18413
|
var PREFER_NODE_FS_PROMISES_DOCUMENTATION = {
|
|
18158
18414
|
defaultLevel: "warning",
|
|
18159
18415
|
summary: "Prefer promise-based Node.js filesystem APIs over synchronous calls in production modules.",
|
|
@@ -18215,7 +18471,7 @@ var prefer_node_fs_promises_default = createRule({
|
|
|
18215
18471
|
if (isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text) || normalizedFilename.includes("src/rules/"))
|
|
18216
18472
|
return {};
|
|
18217
18473
|
const namespaces = /* @__PURE__ */ new Set();
|
|
18218
|
-
const bindingOf = (node) =>
|
|
18474
|
+
const bindingOf = (node) => ASTUtils52.findVariable(context.sourceCode.getScope(node), node.name);
|
|
18219
18475
|
const isGlobal = (node) => {
|
|
18220
18476
|
const binding = bindingOf(node);
|
|
18221
18477
|
return binding === null || binding.defs.length === 0;
|
|
@@ -18281,7 +18537,7 @@ var prefer_node_fs_promises_default = createRule({
|
|
|
18281
18537
|
});
|
|
18282
18538
|
|
|
18283
18539
|
// src/rules/prefer-non-nullable-collection.ts
|
|
18284
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES90, ASTUtils as
|
|
18540
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES90, ASTUtils as ASTUtils53 } from "@typescript-eslint/utils";
|
|
18285
18541
|
var PREFER_NON_NULLABLE_COLLECTION_DOCUMENTATION = {
|
|
18286
18542
|
summary: "Suggest reviewing nullish arrays that use local empty-array defaults or a shared null-or-empty guard.",
|
|
18287
18543
|
rationale: "A redundant nullish collection state spreads defaults and guards through consumers without carrying information.",
|
|
@@ -18406,14 +18662,14 @@ function directlyCoalesced(node) {
|
|
|
18406
18662
|
return parent?.type === AST_NODE_TYPES90.LogicalExpression && parent.left === node && (parent.operator === "??" || parent.operator === "||") && emptyArray(parent.right);
|
|
18407
18663
|
}
|
|
18408
18664
|
function identifierIsOnlyCoalesced(context, binding, fn) {
|
|
18409
|
-
const variable =
|
|
18665
|
+
const variable = ASTUtils53.findVariable(context.sourceCode.getScope(binding), binding.name);
|
|
18410
18666
|
if (variable === null || variable.references.length === 0) return false;
|
|
18411
18667
|
return variable.references.every(
|
|
18412
18668
|
(reference) => belongsToFunction(reference.identifier, fn) && directlyCoalesced(reference.identifier)
|
|
18413
18669
|
);
|
|
18414
18670
|
}
|
|
18415
18671
|
function memberIsOnlyCoalesced(context, object, property, fn) {
|
|
18416
|
-
const variable =
|
|
18672
|
+
const variable = ASTUtils53.findVariable(context.sourceCode.getScope(object), object.name);
|
|
18417
18673
|
if (variable === null) return false;
|
|
18418
18674
|
const accesses = variable.references.flatMap((reference) => {
|
|
18419
18675
|
if (!belongsToFunction(reference.identifier, fn)) return [null];
|
|
@@ -18481,7 +18737,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
18481
18737
|
function checkDestructuredProperties(parameter, properties) {
|
|
18482
18738
|
for (const property of properties) {
|
|
18483
18739
|
const bindingProperty = parameter.properties.find(
|
|
18484
|
-
(entry) => entry.type === AST_NODE_TYPES90.Property && !entry.computed &&
|
|
18740
|
+
(entry) => entry.type === AST_NODE_TYPES90.Property && !entry.computed && ASTUtils53.getPropertyName(entry) === property.name
|
|
18485
18741
|
);
|
|
18486
18742
|
if (bindingProperty === void 0) continue;
|
|
18487
18743
|
const value = bindingProperty.value;
|
|
@@ -18529,7 +18785,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
18529
18785
|
// src/rules/prefer-nullish-filter-predicate.ts
|
|
18530
18786
|
import {
|
|
18531
18787
|
AST_NODE_TYPES as AST_NODE_TYPES91,
|
|
18532
|
-
ASTUtils as
|
|
18788
|
+
ASTUtils as ASTUtils54,
|
|
18533
18789
|
ESLintUtils as ESLintUtils12
|
|
18534
18790
|
} from "@typescript-eslint/utils";
|
|
18535
18791
|
import ts10 from "typescript";
|
|
@@ -18575,7 +18831,7 @@ var PREFER_NULLISH_FILTER_PREDICATE_DOCUMENTATION = {
|
|
|
18575
18831
|
]
|
|
18576
18832
|
};
|
|
18577
18833
|
function isUnshadowedBoolean(node, context) {
|
|
18578
|
-
const variable =
|
|
18834
|
+
const variable = ASTUtils54.findVariable(context.sourceCode.getScope(node), node.name);
|
|
18579
18835
|
return variable === null || variable.defs.length === 0;
|
|
18580
18836
|
}
|
|
18581
18837
|
function isBuiltinArrayFilter(node, services) {
|
|
@@ -18634,7 +18890,7 @@ function isProvablyTruthy(type, checker) {
|
|
|
18634
18890
|
}
|
|
18635
18891
|
function availableParameterName(node, context) {
|
|
18636
18892
|
for (const name of ["value", "item", "element", "candidate"]) {
|
|
18637
|
-
if (
|
|
18893
|
+
if (ASTUtils54.findVariable(context.sourceCode.getScope(node), name) === null) return name;
|
|
18638
18894
|
}
|
|
18639
18895
|
return null;
|
|
18640
18896
|
}
|
|
@@ -18665,7 +18921,7 @@ var prefer_nullish_filter_predicate_default = createRule({
|
|
|
18665
18921
|
CallExpression(node) {
|
|
18666
18922
|
const callee = unwrapExpression(node.callee);
|
|
18667
18923
|
const callback = node.arguments[0] === void 0 ? void 0 : unwrapExpression(node.arguments[0]);
|
|
18668
|
-
if (node.arguments.length !== 1 || callback?.type !== AST_NODE_TYPES91.Identifier || callback.name !== "Boolean" || callee.type !== AST_NODE_TYPES91.MemberExpression ||
|
|
18924
|
+
if (node.arguments.length !== 1 || callback?.type !== AST_NODE_TYPES91.Identifier || callback.name !== "Boolean" || callee.type !== AST_NODE_TYPES91.MemberExpression || ASTUtils54.getPropertyName(callee) === null || (ASTUtils54.getPropertyName(callee) ?? "") !== "filter" || !isUnshadowedBoolean(callback, context) || !isBuiltinArrayFilter(callee, services)) return;
|
|
18669
18925
|
const elementType = arrayElementType(callee.object, services);
|
|
18670
18926
|
const checker = services.program.getTypeChecker();
|
|
18671
18927
|
if (elementType === null || !isNullishPlusTruthy(elementType, checker)) return;
|
|
@@ -18688,7 +18944,7 @@ var prefer_nullish_filter_predicate_default = createRule({
|
|
|
18688
18944
|
|
|
18689
18945
|
// src/rules/prefer-await-in-async-return.ts
|
|
18690
18946
|
import {
|
|
18691
|
-
ASTUtils as
|
|
18947
|
+
ASTUtils as ASTUtils55,
|
|
18692
18948
|
ESLintUtils as ESLintUtils13,
|
|
18693
18949
|
AST_NODE_TYPES as AST_NODE_TYPES92
|
|
18694
18950
|
} from "@typescript-eslint/utils";
|
|
@@ -18751,7 +19007,7 @@ function isRuntimeFunction(node) {
|
|
|
18751
19007
|
}
|
|
18752
19008
|
function promiseThenReceiver(node) {
|
|
18753
19009
|
const callee = unwrapExpression(node.callee);
|
|
18754
|
-
if (callee.type !== AST_NODE_TYPES92.MemberExpression || callee.optional ||
|
|
19010
|
+
if (callee.type !== AST_NODE_TYPES92.MemberExpression || callee.optional || ASTUtils55.getPropertyName(callee) === null || (ASTUtils55.getPropertyName(callee) ?? "") !== "then" || node.optional || node.arguments.length !== 1) {
|
|
18755
19011
|
return null;
|
|
18756
19012
|
}
|
|
18757
19013
|
const argument = node.arguments[0];
|
|
@@ -18821,7 +19077,7 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
18821
19077
|
if (services === null) return {};
|
|
18822
19078
|
const frameworkLoaders = /* @__PURE__ */ new Set();
|
|
18823
19079
|
const rememberFrameworkLoader = (identifier) => {
|
|
18824
|
-
const variable =
|
|
19080
|
+
const variable = ASTUtils55.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
18825
19081
|
if (variable !== null) frameworkLoaders.add(variable);
|
|
18826
19082
|
};
|
|
18827
19083
|
const isFrameworkLoaderCallback = (owner) => {
|
|
@@ -18829,7 +19085,7 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
18829
19085
|
if (parent === null || parent.arguments[0] !== outerExpression(owner)) return false;
|
|
18830
19086
|
const callee = unwrapExpression(parent.callee);
|
|
18831
19087
|
if (callee.type !== AST_NODE_TYPES92.Identifier) return false;
|
|
18832
|
-
const variable =
|
|
19088
|
+
const variable = ASTUtils55.findVariable(context.sourceCode.getScope(callee), callee.name);
|
|
18833
19089
|
return variable !== null && frameworkLoaders.has(variable);
|
|
18834
19090
|
};
|
|
18835
19091
|
return {
|
|
@@ -18866,7 +19122,7 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
18866
19122
|
});
|
|
18867
19123
|
|
|
18868
19124
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
18869
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES93, ASTUtils as
|
|
19125
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES93, ASTUtils as ASTUtils56 } from "@typescript-eslint/utils";
|
|
18870
19126
|
var PREFER_SCHEMA_FOR_API_PAYLOAD_DOCUMENTATION = {
|
|
18871
19127
|
summary: "Require Zod (or similar) schema validation on `response.json()` / `JSON.parse()` results before property access.",
|
|
18872
19128
|
rationale: "External JSON is untrusted at runtime even when its expected TypeScript shape is known statically.",
|
|
@@ -18903,7 +19159,7 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
18903
19159
|
]);
|
|
18904
19160
|
var isSchemaParseReference = (node) => {
|
|
18905
19161
|
const inner = unwrap5(node);
|
|
18906
|
-
return inner !== null && inner.type === AST_NODE_TYPES93.MemberExpression &&
|
|
19162
|
+
return inner !== null && inner.type === AST_NODE_TYPES93.MemberExpression && ASTUtils56.getPropertyName(inner) !== null && ((ASTUtils56.getPropertyName(inner) ?? "") === "parse" || (ASTUtils56.getPropertyName(inner) ?? "") === "safeParse");
|
|
18907
19163
|
};
|
|
18908
19164
|
var isRawPayloadSource = (node, context, isKnownLocalText) => {
|
|
18909
19165
|
let current = unwrap5(node);
|
|
@@ -18918,7 +19174,7 @@ var isRawPayloadSource = (node, context, isKnownLocalText) => {
|
|
|
18918
19174
|
if (callee === null || callee.type !== AST_NODE_TYPES93.MemberExpression) {
|
|
18919
19175
|
return false;
|
|
18920
19176
|
}
|
|
18921
|
-
const property =
|
|
19177
|
+
const property = ASTUtils56.getPropertyName(callee);
|
|
18922
19178
|
if (property === null) {
|
|
18923
19179
|
return false;
|
|
18924
19180
|
}
|
|
@@ -18930,19 +19186,19 @@ var isRawPayloadSource = (node, context, isKnownLocalText) => {
|
|
|
18930
19186
|
}
|
|
18931
19187
|
const object = unwrap5(callee.object);
|
|
18932
19188
|
const input = unwrap5(current.arguments[0]);
|
|
18933
|
-
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" &&
|
|
18934
|
-
return property === "parse" && object !== null && object.type === AST_NODE_TYPES93.Identifier && object.name === "JSON" && (
|
|
19189
|
+
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" && ASTUtils56.getPropertyName(input.callee) === "stringify" && (ASTUtils56.findVariable(context.sourceCode.getScope(input.callee.object), "JSON")?.defs.length ?? 0) === 0) return false;
|
|
19190
|
+
return property === "parse" && object !== null && object.type === AST_NODE_TYPES93.Identifier && object.name === "JSON" && (ASTUtils56.findVariable(context.sourceCode.getScope(object), "JSON")?.defs.length ?? 0) === 0 && !isLocalFileRead(current.arguments[0]) && isKnownLocalText?.(current.arguments[0]) !== true;
|
|
18935
19191
|
};
|
|
18936
19192
|
var isResponseSource = (node, context, seen = /* @__PURE__ */ new Set()) => {
|
|
18937
19193
|
let current = unwrap5(node);
|
|
18938
19194
|
if (current?.type === AST_NODE_TYPES93.AwaitExpression) current = unwrap5(current.argument);
|
|
18939
19195
|
if (current === null || seen.has(current)) return false;
|
|
18940
19196
|
seen.add(current);
|
|
18941
|
-
const isGlobal = (identifier) => (
|
|
19197
|
+
const isGlobal = (identifier) => (ASTUtils56.findVariable(context.sourceCode.getScope(identifier), identifier.name)?.defs.length ?? 0) === 0;
|
|
18942
19198
|
if (current.type === AST_NODE_TYPES93.CallExpression) return current.callee.type === AST_NODE_TYPES93.Identifier && current.callee.name === "fetch" && isGlobal(current.callee);
|
|
18943
19199
|
if (current.type === AST_NODE_TYPES93.NewExpression) return current.callee.type === AST_NODE_TYPES93.Identifier && ["Request", "Response"].includes(current.callee.name) && isGlobal(current.callee);
|
|
18944
19200
|
if (current.type !== AST_NODE_TYPES93.Identifier) return false;
|
|
18945
|
-
const binding =
|
|
19201
|
+
const binding = ASTUtils56.findVariable(context.sourceCode.getScope(current), current.name);
|
|
18946
19202
|
if (binding?.defs.length !== 1 || binding.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
18947
19203
|
const definition = binding.defs[0];
|
|
18948
19204
|
const annotation = definition?.name.type === AST_NODE_TYPES93.Identifier ? definition.name.typeAnnotation?.typeAnnotation : void 0;
|
|
@@ -18957,7 +19213,7 @@ var isDirectLocalFileRead = (node) => {
|
|
|
18957
19213
|
}
|
|
18958
19214
|
if (current?.type !== AST_NODE_TYPES93.CallExpression) return false;
|
|
18959
19215
|
const callee = unwrap5(current.callee);
|
|
18960
|
-
const name = callee?.type === AST_NODE_TYPES93.Identifier ? callee.name : callee?.type === AST_NODE_TYPES93.MemberExpression &&
|
|
19216
|
+
const name = callee?.type === AST_NODE_TYPES93.Identifier ? callee.name : callee?.type === AST_NODE_TYPES93.MemberExpression && ASTUtils56.getPropertyName(callee) !== null ? ASTUtils56.getPropertyName(callee) ?? "" : null;
|
|
18961
19217
|
return name !== null && FILE_READ_RE.test(name);
|
|
18962
19218
|
};
|
|
18963
19219
|
var isLocalFileRead = (node) => {
|
|
@@ -19018,7 +19274,7 @@ var isValidationRead = (node) => {
|
|
|
19018
19274
|
return false;
|
|
19019
19275
|
}
|
|
19020
19276
|
const callee = parent.callee;
|
|
19021
|
-
if (callee.type === AST_NODE_TYPES93.MemberExpression && callee.object.type === AST_NODE_TYPES93.Identifier && callee.object.name === "Array" &&
|
|
19277
|
+
if (callee.type === AST_NODE_TYPES93.MemberExpression && callee.object.type === AST_NODE_TYPES93.Identifier && callee.object.name === "Array" && ASTUtils56.getPropertyName(callee) === "isArray") {
|
|
19022
19278
|
return parent.arguments.length === 1;
|
|
19023
19279
|
}
|
|
19024
19280
|
return callee.type === AST_NODE_TYPES93.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
@@ -19046,11 +19302,11 @@ var bindingValidationPolarity = (test, bindingName) => {
|
|
|
19046
19302
|
}
|
|
19047
19303
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
19048
19304
|
}
|
|
19049
|
-
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" &&
|
|
19305
|
+
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" && ASTUtils56.getPropertyName(test.callee) === "isArray" ? "valid-when-true" : null;
|
|
19050
19306
|
};
|
|
19051
19307
|
var plainMemberAccess = (node) => {
|
|
19052
19308
|
if (node.type !== AST_NODE_TYPES93.MemberExpression || node.object.type !== AST_NODE_TYPES93.Identifier) return null;
|
|
19053
|
-
const property =
|
|
19309
|
+
const property = ASTUtils56.getPropertyName(node);
|
|
19054
19310
|
return property === null ? null : { object: node.object.name, property };
|
|
19055
19311
|
};
|
|
19056
19312
|
var isSamePlainMember = (node, access) => {
|
|
@@ -19114,7 +19370,7 @@ var memberValidationPolarity = (test, access) => {
|
|
|
19114
19370
|
}
|
|
19115
19371
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
19116
19372
|
}
|
|
19117
|
-
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" &&
|
|
19373
|
+
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" && ASTUtils56.getPropertyName(test.callee) === "isArray" ? "valid-when-true" : null;
|
|
19118
19374
|
};
|
|
19119
19375
|
var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
19120
19376
|
const isValidationReference = (identifier) => {
|
|
@@ -19397,7 +19653,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
19397
19653
|
(candidate2) => localFileTextRef(candidate2, scope) !== null
|
|
19398
19654
|
)) {
|
|
19399
19655
|
const parent = node.parent;
|
|
19400
|
-
const method =
|
|
19656
|
+
const method = ASTUtils56.getPropertyName(node);
|
|
19401
19657
|
if (parent.type === AST_NODE_TYPES93.CallExpression && parent.callee === node && method !== null && (method === "parse" || method === "safeParse" || PROMISE_CHAIN_METHODS.has(method))) {
|
|
19402
19658
|
return;
|
|
19403
19659
|
}
|
|
@@ -19450,7 +19706,7 @@ function ifGuardDominates(use, branch, positive) {
|
|
|
19450
19706
|
}
|
|
19451
19707
|
|
|
19452
19708
|
// src/rules/prefer-shared-zod-enum.ts
|
|
19453
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES94, ASTUtils as
|
|
19709
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES94, ASTUtils as ASTUtils57 } from "@typescript-eslint/utils";
|
|
19454
19710
|
var PREFER_SHARED_ZOD_ENUM_DOCUMENTATION = {
|
|
19455
19711
|
defaultLevel: "warning",
|
|
19456
19712
|
summary: "Give repeated literal Zod enum domains one reusable module-level schema.",
|
|
@@ -19500,7 +19756,7 @@ var prefer_shared_zod_enum_default = createRule({
|
|
|
19500
19756
|
create(context) {
|
|
19501
19757
|
if (isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text)) return {};
|
|
19502
19758
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
19503
|
-
const bindingOf = (node) =>
|
|
19759
|
+
const bindingOf = (node) => ASTUtils57.findVariable(context.sourceCode.getScope(node), node.name);
|
|
19504
19760
|
const candidates = /* @__PURE__ */ new Map();
|
|
19505
19761
|
return {
|
|
19506
19762
|
ImportDeclaration(node) {
|
|
@@ -19515,7 +19771,7 @@ var prefer_shared_zod_enum_default = createRule({
|
|
|
19515
19771
|
CallExpression(node) {
|
|
19516
19772
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
19517
19773
|
const receiver = unwrappedNodeCallee.type === AST_NODE_TYPES94.MemberExpression ? unwrapExpression(unwrappedNodeCallee.object) : unwrappedNodeCallee;
|
|
19518
|
-
if (unwrappedNodeCallee.type !== AST_NODE_TYPES94.MemberExpression || receiver.type !== AST_NODE_TYPES94.Identifier ||
|
|
19774
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES94.MemberExpression || receiver.type !== AST_NODE_TYPES94.Identifier || ASTUtils57.getPropertyName(unwrappedNodeCallee) === null || (ASTUtils57.getPropertyName(unwrappedNodeCallee) ?? "") !== "enum") return;
|
|
19519
19775
|
const binding = bindingOf(receiver);
|
|
19520
19776
|
if (binding === null || !zodBindings.has(binding)) return;
|
|
19521
19777
|
const domain = literalDomain(node);
|
|
@@ -19540,7 +19796,7 @@ var prefer_shared_zod_enum_default = createRule({
|
|
|
19540
19796
|
});
|
|
19541
19797
|
|
|
19542
19798
|
// src/rules/prefer-switch-for-repeated-equality.ts
|
|
19543
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES95, ASTUtils as
|
|
19799
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES95, ASTUtils as ASTUtils58 } from "@typescript-eslint/utils";
|
|
19544
19800
|
var PREFER_SWITCH_FOR_REPEATED_EQUALITY_DOCUMENTATION = {
|
|
19545
19801
|
defaultLevel: "error",
|
|
19546
19802
|
summary: "Prefer switch over long if/else-if chains that compare one value for strict equality.",
|
|
@@ -19592,7 +19848,7 @@ var prefer_switch_for_repeated_equality_default = createRule({
|
|
|
19592
19848
|
if (node.parent.type === AST_NODE_TYPES95.IfStatement && node.parent.alternate === node) return;
|
|
19593
19849
|
const first = discriminantName(node.test);
|
|
19594
19850
|
if (first === null) return;
|
|
19595
|
-
const binding =
|
|
19851
|
+
const binding = ASTUtils58.findVariable(context.sourceCode.getScope(node), first);
|
|
19596
19852
|
if (binding === null || binding.defs.length !== 1 || binding.scope.type === "global") return;
|
|
19597
19853
|
const [definition] = binding.defs;
|
|
19598
19854
|
if (definition?.type !== "Parameter" && definition?.type !== "Variable") return;
|
|
@@ -20139,7 +20395,7 @@ function packageWorkspaceGlobs(parsed) {
|
|
|
20139
20395
|
}
|
|
20140
20396
|
|
|
20141
20397
|
// src/rules/prefer-server-actions.ts
|
|
20142
|
-
import { ASTUtils as
|
|
20398
|
+
import { ASTUtils as ASTUtils59 } from "@typescript-eslint/utils";
|
|
20143
20399
|
var PREFER_SERVER_ACTIONS_DOCUMENTATION = {
|
|
20144
20400
|
summary: "Prefer Next.js Server Actions over same-origin API mutations.",
|
|
20145
20401
|
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.",
|
|
@@ -20172,7 +20428,7 @@ function resolveNode(node, context) {
|
|
|
20172
20428
|
node = node == null ? node : unwrapExpression(node);
|
|
20173
20429
|
if (!node) return null;
|
|
20174
20430
|
if (node.type !== "Identifier") return node;
|
|
20175
|
-
const variable =
|
|
20431
|
+
const variable = ASTUtils59.findVariable(getScope(context, node), node.name);
|
|
20176
20432
|
const definition = variable?.defs.length === 1 ? variable.defs[0] : void 0;
|
|
20177
20433
|
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init === null || variable?.references.some((reference) => reference.isWrite() && reference.init !== true)) return node;
|
|
20178
20434
|
if (definition.node.init.type === "ObjectExpression" && variable?.references.some((reference) => reference.identifier !== node && reference.init !== true)) return node;
|
|
@@ -20181,7 +20437,7 @@ function resolveNode(node, context) {
|
|
|
20181
20437
|
function isAxiosClient(node, context, seen = /* @__PURE__ */ new Set()) {
|
|
20182
20438
|
if (node.type !== "Identifier" || seen.has(node)) return false;
|
|
20183
20439
|
seen.add(node);
|
|
20184
|
-
const variable =
|
|
20440
|
+
const variable = ASTUtils59.findVariable(getScope(context, node), node.name);
|
|
20185
20441
|
const definition = variable?.defs.length === 1 ? variable.defs[0] : void 0;
|
|
20186
20442
|
if (definition === void 0 || variable?.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
20187
20443
|
if (variable?.references.some((reference) => {
|
|
@@ -20265,10 +20521,10 @@ function isFunctionArgument(node, context) {
|
|
|
20265
20521
|
}
|
|
20266
20522
|
function getPropertyNode(objNode, propName2) {
|
|
20267
20523
|
if (!objNode || objNode.type !== "ObjectExpression") return null;
|
|
20268
|
-
if (objNode.properties.some((property) => property.type === "SpreadElement" ||
|
|
20524
|
+
if (objNode.properties.some((property) => property.type === "SpreadElement" || ASTUtils59.getPropertyName(property) === null)) return null;
|
|
20269
20525
|
for (const prop of [...objNode.properties].reverse()) {
|
|
20270
20526
|
if (prop.type !== "Property") continue;
|
|
20271
|
-
const keyName =
|
|
20527
|
+
const keyName = ASTUtils59.getPropertyName(prop);
|
|
20272
20528
|
if (keyName === propName2) {
|
|
20273
20529
|
if (prop.value.type === "AssignmentPattern" || prop.value.type === "ArrayPattern" || prop.value.type === "ObjectPattern") {
|
|
20274
20530
|
return null;
|
|
@@ -20392,7 +20648,7 @@ var prefer_server_actions_default = createRule({
|
|
|
20392
20648
|
});
|
|
20393
20649
|
|
|
20394
20650
|
// src/rules/prefer-whole-object-assertion.ts
|
|
20395
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES97, ASTUtils as
|
|
20651
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES97, ASTUtils as ASTUtils60 } from "@typescript-eslint/utils";
|
|
20396
20652
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
20397
20653
|
var SYNTHETIC_LITERAL_MATCHERS = /* @__PURE__ */ new Map([
|
|
20398
20654
|
["toBeNull", "null"]
|
|
@@ -20457,7 +20713,7 @@ function propertyAccess(node) {
|
|
|
20457
20713
|
const path = [];
|
|
20458
20714
|
let current = node;
|
|
20459
20715
|
while (current.type === AST_NODE_TYPES97.MemberExpression && !current.optional) {
|
|
20460
|
-
const name =
|
|
20716
|
+
const name = ASTUtils60.getPropertyName(current);
|
|
20461
20717
|
if (name === null || COLLECTION_PROPERTIES.has(name) || LITERAL_KEY_HAZARDS.has(name)) return null;
|
|
20462
20718
|
path.unshift(name);
|
|
20463
20719
|
current = unwrapExpression(current.object);
|
|
@@ -20604,7 +20860,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
20604
20860
|
const callee = unwrapExpression(call.callee);
|
|
20605
20861
|
const calleeReceiver = callee.type === AST_NODE_TYPES97.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
20606
20862
|
if (callee.type !== AST_NODE_TYPES97.MemberExpression) return null;
|
|
20607
|
-
const matcher =
|
|
20863
|
+
const matcher = ASTUtils60.getPropertyName(callee);
|
|
20608
20864
|
if (matcher === null) return null;
|
|
20609
20865
|
const expectCall = calleeReceiver;
|
|
20610
20866
|
const expectCallee = expectCall.type === AST_NODE_TYPES97.CallExpression ? unwrapExpression(expectCall.callee) : null;
|
|
@@ -20634,7 +20890,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
20634
20890
|
return assertionExpectation(statement, call, receiver, key, matcher);
|
|
20635
20891
|
}
|
|
20636
20892
|
function isTestExpect(callee) {
|
|
20637
|
-
const variable =
|
|
20893
|
+
const variable = ASTUtils60.findVariable(sourceCode.getScope(callee), callee.name);
|
|
20638
20894
|
if (variable !== null && variable.defs.some((definition) => {
|
|
20639
20895
|
if (definition.node.type !== AST_NODE_TYPES97.ImportSpecifier) return true;
|
|
20640
20896
|
const declaration = definition.node.parent;
|
|
@@ -20677,7 +20933,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
20677
20933
|
});
|
|
20678
20934
|
|
|
20679
20935
|
// src/rules/repeated-static-call-cases.ts
|
|
20680
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES98, ASTUtils as
|
|
20936
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES98, ASTUtils as ASTUtils61 } from "@typescript-eslint/utils";
|
|
20681
20937
|
var REPEATED_STATIC_CALL_CASES_DOCUMENTATION = {
|
|
20682
20938
|
summary: "Review three or more consecutive static-input call assertions as potential named cases.",
|
|
20683
20939
|
rationale: "Copy-pasted cases obscure the input table, and a thrown assertion can stop later cases from being reported.",
|
|
@@ -20698,7 +20954,7 @@ var EXPECT_MODIFIERS = /* @__PURE__ */ new Set(["not", "rejects", "resolves"]);
|
|
|
20698
20954
|
var SNAPSHOT_MATCHERS = /snapshot/iu;
|
|
20699
20955
|
var MIN_CASES2 = 3;
|
|
20700
20956
|
function importedName6(identifier, context, modules) {
|
|
20701
|
-
const variable =
|
|
20957
|
+
const variable = ASTUtils61.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
20702
20958
|
if (variable === null || variable.defs.length === 0) return identifier.name;
|
|
20703
20959
|
for (const definition of variable.defs) {
|
|
20704
20960
|
if (definition.node.type !== AST_NODE_TYPES98.ImportSpecifier) continue;
|
|
@@ -20720,7 +20976,7 @@ function testRoot2(callee) {
|
|
|
20720
20976
|
callee = unwrapExpression(callee);
|
|
20721
20977
|
if (callee.type === AST_NODE_TYPES98.Identifier) return callee;
|
|
20722
20978
|
if (callee.type !== AST_NODE_TYPES98.MemberExpression) return null;
|
|
20723
|
-
const modifier =
|
|
20979
|
+
const modifier = ASTUtils61.getPropertyName(callee);
|
|
20724
20980
|
return modifier !== null && TEST_MODIFIERS5.has(modifier) ? testRoot2(callee.object) : null;
|
|
20725
20981
|
}
|
|
20726
20982
|
function isStatic(input) {
|
|
@@ -20766,8 +21022,8 @@ function assertionShape(statement, context, callback) {
|
|
|
20766
21022
|
const matcherCall = unwrapExpression(statement.expression);
|
|
20767
21023
|
if (matcherCall.type !== AST_NODE_TYPES98.CallExpression) return null;
|
|
20768
21024
|
const matcherCallee = unwrapExpression(matcherCall.callee);
|
|
20769
|
-
if (matcherCallee.type !== AST_NODE_TYPES98.MemberExpression ||
|
|
20770
|
-
const matcher =
|
|
21025
|
+
if (matcherCallee.type !== AST_NODE_TYPES98.MemberExpression || ASTUtils61.getPropertyName(matcherCallee) === null || matcherCall.arguments.length !== 1) return null;
|
|
21026
|
+
const matcher = ASTUtils61.getPropertyName(matcherCallee) ?? "";
|
|
20771
21027
|
if (SNAPSHOT_MATCHERS.test(matcher)) return null;
|
|
20772
21028
|
const chain = expectCallFromMatcher(matcherCallee);
|
|
20773
21029
|
const expectCallee = chain === null ? null : unwrapExpression(chain.call.callee);
|
|
@@ -20777,7 +21033,7 @@ function assertionShape(statement, context, callback) {
|
|
|
20777
21033
|
const observedCallee = observed?.type === AST_NODE_TYPES98.CallExpression ? unwrapExpression(observed.callee) : null;
|
|
20778
21034
|
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;
|
|
20779
21035
|
const skeleton = `${observedCallee.name}/${observed.arguments.map((item) => staticShape(item)).join(",")}/${chain.modifiers.join(".")}/${matcher}/${staticShape(expected)}`;
|
|
20780
|
-
const binding =
|
|
21036
|
+
const binding = ASTUtils61.findVariable(context.sourceCode.getScope(observedCallee), observedCallee.name);
|
|
20781
21037
|
if (binding?.defs.some(
|
|
20782
21038
|
(definition) => definition.node.range[0] >= callback.range[0] && definition.node.range[1] <= callback.range[1]
|
|
20783
21039
|
)) return null;
|
|
@@ -20788,7 +21044,7 @@ function expectCallFromMatcher(node) {
|
|
|
20788
21044
|
const modifiers = [];
|
|
20789
21045
|
let receiver = node.object;
|
|
20790
21046
|
while (receiver.type === AST_NODE_TYPES98.MemberExpression) {
|
|
20791
|
-
const modifier =
|
|
21047
|
+
const modifier = ASTUtils61.getPropertyName(receiver);
|
|
20792
21048
|
if (modifier === null || !EXPECT_MODIFIERS.has(modifier)) return null;
|
|
20793
21049
|
modifiers.unshift(modifier);
|
|
20794
21050
|
receiver = receiver.object;
|
|
@@ -20864,7 +21120,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
20864
21120
|
});
|
|
20865
21121
|
|
|
20866
21122
|
// src/rules/prefer-zod-infer.ts
|
|
20867
|
-
import { ASTUtils as
|
|
21123
|
+
import { ASTUtils as ASTUtils62, AST_NODE_TYPES as AST_NODE_TYPES99 } from "@typescript-eslint/utils";
|
|
20868
21124
|
var PREFER_ZOD_INFER_DOCUMENTATION = {
|
|
20869
21125
|
summary: "Derive a type from its Zod schema with `z.infer` instead of hand-writing a twin declaration beside it.",
|
|
20870
21126
|
rationale: "A derived type stays synchronized when the runtime schema changes.",
|
|
@@ -21182,7 +21438,7 @@ function twinCallChain(node, zodNamespaces) {
|
|
|
21182
21438
|
while (current.type === AST_NODE_TYPES99.CallExpression) {
|
|
21183
21439
|
const callee = unwrapExpression(current.callee);
|
|
21184
21440
|
const calleeReceiver = callee.type === AST_NODE_TYPES99.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
21185
|
-
if (callee.type !== AST_NODE_TYPES99.MemberExpression ||
|
|
21441
|
+
if (callee.type !== AST_NODE_TYPES99.MemberExpression || ASTUtils62.getPropertyName(callee) === null) {
|
|
21186
21442
|
return null;
|
|
21187
21443
|
}
|
|
21188
21444
|
chain.push(current);
|
|
@@ -21195,7 +21451,7 @@ function twinCallChain(node, zodNamespaces) {
|
|
|
21195
21451
|
}
|
|
21196
21452
|
function twinMethodName(call) {
|
|
21197
21453
|
const callee = unwrapExpression(call.callee);
|
|
21198
|
-
return callee.type === AST_NODE_TYPES99.MemberExpression &&
|
|
21454
|
+
return callee.type === AST_NODE_TYPES99.MemberExpression && ASTUtils62.getPropertyName(callee) !== null ? ASTUtils62.getPropertyName(callee) ?? "" : "";
|
|
21199
21455
|
}
|
|
21200
21456
|
function twinSchemaFields(initializer, zodNamespaces) {
|
|
21201
21457
|
const chain = twinCallChain(initializer, zodNamespaces);
|
|
@@ -21210,7 +21466,7 @@ function twinSchemaFields(initializer, zodNamespaces) {
|
|
|
21210
21466
|
const fields = /* @__PURE__ */ new Map();
|
|
21211
21467
|
for (const property of shape.properties) {
|
|
21212
21468
|
if (property.type !== AST_NODE_TYPES99.Property) return null;
|
|
21213
|
-
const name =
|
|
21469
|
+
const name = ASTUtils62.getPropertyName(property);
|
|
21214
21470
|
if (name === null) return null;
|
|
21215
21471
|
fields.set(name, twinSchemaField(property.value, zodNamespaces));
|
|
21216
21472
|
}
|
|
@@ -21224,16 +21480,16 @@ function twinSchemaField(node, zodNamespaces) {
|
|
|
21224
21480
|
while (current.type === AST_NODE_TYPES99.CallExpression) {
|
|
21225
21481
|
const callee = unwrapExpression(current.callee);
|
|
21226
21482
|
const calleeReceiver = callee.type === AST_NODE_TYPES99.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
21227
|
-
if (callee.type !== AST_NODE_TYPES99.MemberExpression ||
|
|
21483
|
+
if (callee.type !== AST_NODE_TYPES99.MemberExpression || ASTUtils62.getPropertyName(callee) === null) {
|
|
21228
21484
|
break;
|
|
21229
21485
|
}
|
|
21230
21486
|
const receiver = calleeReceiver;
|
|
21231
21487
|
if (receiver.type === AST_NODE_TYPES99.Identifier && zodNamespaces.has(receiver.name)) {
|
|
21232
|
-
leaf =
|
|
21488
|
+
leaf = ASTUtils62.getPropertyName(callee) ?? "";
|
|
21233
21489
|
leafCall = current;
|
|
21234
21490
|
break;
|
|
21235
21491
|
}
|
|
21236
|
-
modifiers.push(
|
|
21492
|
+
modifiers.push(ASTUtils62.getPropertyName(callee) ?? "");
|
|
21237
21493
|
current = receiver;
|
|
21238
21494
|
}
|
|
21239
21495
|
return {
|
|
@@ -21436,7 +21692,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
21436
21692
|
},
|
|
21437
21693
|
/** Records `XSchema.transform(...)` and equivalent module-level reshaping. */
|
|
21438
21694
|
"MemberExpression"(node) {
|
|
21439
|
-
if (node.object.type === AST_NODE_TYPES99.Identifier &&
|
|
21695
|
+
if (node.object.type === AST_NODE_TYPES99.Identifier && ASTUtils62.getPropertyName(node) !== null && isPreferZodInferModuleReshaper(ASTUtils62.getPropertyName(node) ?? "")) {
|
|
21440
21696
|
reshapedSchemaNames.add(node.object.name);
|
|
21441
21697
|
}
|
|
21442
21698
|
},
|
|
@@ -21593,7 +21849,7 @@ function staticFieldName(key) {
|
|
|
21593
21849
|
}
|
|
21594
21850
|
|
|
21595
21851
|
// src/rules/named-child-schema-type.ts
|
|
21596
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES100, ASTUtils as
|
|
21852
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES100, ASTUtils as ASTUtils63 } from "@typescript-eslint/utils";
|
|
21597
21853
|
var UNRESOLVED_TYPE_NODES = /* @__PURE__ */ new Set([
|
|
21598
21854
|
AST_NODE_TYPES100.TSTypeQuery,
|
|
21599
21855
|
AST_NODE_TYPES100.TSImportType,
|
|
@@ -21638,7 +21894,7 @@ var named_child_schema_type_default = createRule({
|
|
|
21638
21894
|
const source = context.sourceCode;
|
|
21639
21895
|
if (isGeneratedFile(context.filename, source.text)) return {};
|
|
21640
21896
|
const namespaces = /* @__PURE__ */ new Set();
|
|
21641
|
-
const bindingOf = (node) =>
|
|
21897
|
+
const bindingOf = (node) => ASTUtils63.findVariable(source.getScope(node), node.name);
|
|
21642
21898
|
function namespaceOf(type) {
|
|
21643
21899
|
if (type.typeName.type !== AST_NODE_TYPES100.TSQualifiedName || type.typeName.left.type !== AST_NODE_TYPES100.Identifier) return null;
|
|
21644
21900
|
const binding = bindingOf(type.typeName.left);
|
|
@@ -21682,7 +21938,7 @@ var named_child_schema_type_default = createRule({
|
|
|
21682
21938
|
VariableDeclarator(node) {
|
|
21683
21939
|
if (!isModuleConst(node) || node.id.type !== AST_NODE_TYPES100.Identifier || node.init?.type !== AST_NODE_TYPES100.CallExpression) return;
|
|
21684
21940
|
const call = node.init;
|
|
21685
|
-
if (call.arguments.length !== 2 || call.callee.type !== AST_NODE_TYPES100.MemberExpression || call.callee.object.type !== AST_NODE_TYPES100.Identifier ||
|
|
21941
|
+
if (call.arguments.length !== 2 || call.callee.type !== AST_NODE_TYPES100.MemberExpression || call.callee.object.type !== AST_NODE_TYPES100.Identifier || ASTUtils63.getPropertyName(call.callee) !== "record") return;
|
|
21686
21942
|
const annotation = node.id.typeAnnotation?.typeAnnotation;
|
|
21687
21943
|
if (annotation?.type !== AST_NODE_TYPES100.TSTypeReference || annotation.typeName.type !== AST_NODE_TYPES100.TSQualifiedName || annotation.typeName.right.name !== "ZodRecord") return;
|
|
21688
21944
|
const namespace = namespaceOf(annotation);
|
|
@@ -21698,7 +21954,7 @@ var named_child_schema_type_default = createRule({
|
|
|
21698
21954
|
|
|
21699
21955
|
// src/rules/prefer-zod-parse-output-type.ts
|
|
21700
21956
|
import {
|
|
21701
|
-
ASTUtils as
|
|
21957
|
+
ASTUtils as ASTUtils64,
|
|
21702
21958
|
AST_NODE_TYPES as AST_NODE_TYPES101,
|
|
21703
21959
|
ESLintUtils as ESLintUtils14
|
|
21704
21960
|
} from "@typescript-eslint/utils";
|
|
@@ -21768,11 +22024,11 @@ function isLocalZodObjectSchema(node, namespaces) {
|
|
|
21768
22024
|
while (current.type === AST_NODE_TYPES101.CallExpression) {
|
|
21769
22025
|
const callee = unwrapExpression(current.callee);
|
|
21770
22026
|
const calleeReceiver = callee.type === AST_NODE_TYPES101.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
21771
|
-
if (callee.type !== AST_NODE_TYPES101.MemberExpression ||
|
|
22027
|
+
if (callee.type !== AST_NODE_TYPES101.MemberExpression || ASTUtils64.getPropertyName(callee) === null) {
|
|
21772
22028
|
return false;
|
|
21773
22029
|
}
|
|
21774
22030
|
if (calleeReceiver.type === AST_NODE_TYPES101.Identifier) {
|
|
21775
|
-
return namespaces.has(calleeReceiver.name) && ((
|
|
22031
|
+
return namespaces.has(calleeReceiver.name) && ((ASTUtils64.getPropertyName(callee) ?? "") === "object" || (ASTUtils64.getPropertyName(callee) ?? "") === "strictObject");
|
|
21776
22032
|
}
|
|
21777
22033
|
current = calleeReceiver;
|
|
21778
22034
|
}
|
|
@@ -21781,10 +22037,10 @@ function isLocalZodObjectSchema(node, namespaces) {
|
|
|
21781
22037
|
function zodParseCall(node) {
|
|
21782
22038
|
const callee = unwrapExpression(node.callee);
|
|
21783
22039
|
const calleeReceiver = callee.type === AST_NODE_TYPES101.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
21784
|
-
if (callee.type !== AST_NODE_TYPES101.MemberExpression || calleeReceiver.type !== AST_NODE_TYPES101.Identifier ||
|
|
22040
|
+
if (callee.type !== AST_NODE_TYPES101.MemberExpression || calleeReceiver.type !== AST_NODE_TYPES101.Identifier || ASTUtils64.getPropertyName(callee) === null) {
|
|
21785
22041
|
return null;
|
|
21786
22042
|
}
|
|
21787
|
-
const method =
|
|
22043
|
+
const method = ASTUtils64.getPropertyName(callee);
|
|
21788
22044
|
if (method !== "parse" && method !== "safeParse") return null;
|
|
21789
22045
|
return {
|
|
21790
22046
|
call: node,
|
|
@@ -21826,7 +22082,7 @@ function localParseReturnCandidates(node, sourceCode) {
|
|
|
21826
22082
|
for (const reference of variable.references) {
|
|
21827
22083
|
const identifier = reference.identifier;
|
|
21828
22084
|
const parent = identifier.parent;
|
|
21829
|
-
const output = parsed.method === "parse" ? identifier : parent.type === AST_NODE_TYPES101.MemberExpression && parent.object === identifier &&
|
|
22085
|
+
const output = parsed.method === "parse" ? identifier : parent.type === AST_NODE_TYPES101.MemberExpression && parent.object === identifier && ASTUtils64.getPropertyName(parent) !== null && (ASTUtils64.getPropertyName(parent) ?? "") === "data" ? parent : null;
|
|
21830
22086
|
if (output === null) continue;
|
|
21831
22087
|
const candidate2 = returnedOutputCandidate(parsed, output);
|
|
21832
22088
|
if (candidate2 !== null) candidates.push(candidate2);
|
|
@@ -22211,7 +22467,7 @@ var require_assert_never_default = createRule({
|
|
|
22211
22467
|
// src/rules/require-fetch-timeout.ts
|
|
22212
22468
|
import {
|
|
22213
22469
|
AST_NODE_TYPES as AST_NODE_TYPES103,
|
|
22214
|
-
ASTUtils as
|
|
22470
|
+
ASTUtils as ASTUtils65
|
|
22215
22471
|
} from "@typescript-eslint/utils";
|
|
22216
22472
|
var REQUIRE_FETCH_TIMEOUT_DOCUMENTATION = {
|
|
22217
22473
|
summary: "Require an explicit abort signal on locally analyzable global fetch calls.",
|
|
@@ -22293,7 +22549,7 @@ function initSignalState(init, resolvesToGlobal) {
|
|
|
22293
22549
|
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";
|
|
22294
22550
|
if (isSignal) {
|
|
22295
22551
|
state = !prop.method ? emptySignal(prop.value, resolvesToGlobal) ?? "unknown" : "unknown";
|
|
22296
|
-
} else if (!prop.computed &&
|
|
22552
|
+
} else if (!prop.computed && ASTUtils65.getPropertyName(prop) === "__proto__" && state === "absent") {
|
|
22297
22553
|
state = "unknown";
|
|
22298
22554
|
} else if (prop.computed && prop.key.type !== AST_NODE_TYPES103.Literal) {
|
|
22299
22555
|
state = "unknown";
|
|
@@ -22302,14 +22558,14 @@ function initSignalState(init, resolvesToGlobal) {
|
|
|
22302
22558
|
return state;
|
|
22303
22559
|
}
|
|
22304
22560
|
function hasUnprovedPrototype(property) {
|
|
22305
|
-
if (property.computed || property.method || property.shorthand ||
|
|
22561
|
+
if (property.computed || property.method || property.shorthand || ASTUtils65.getPropertyName(property) !== "__proto__")
|
|
22306
22562
|
return false;
|
|
22307
22563
|
const prototype = unwrapExpression(property.value);
|
|
22308
22564
|
if (prototype.type === AST_NODE_TYPES103.Literal && prototype.value === null)
|
|
22309
22565
|
return false;
|
|
22310
22566
|
if (prototype.type !== AST_NODE_TYPES103.ObjectExpression) return true;
|
|
22311
22567
|
return prototype.properties.some(
|
|
22312
|
-
(member) => member.type === AST_NODE_TYPES103.SpreadElement || member.kind !== "init" || !member.computed &&
|
|
22568
|
+
(member) => member.type === AST_NODE_TYPES103.SpreadElement || member.kind !== "init" || !member.computed && ASTUtils65.getPropertyName(member) === "__proto__" || member.computed && member.key.type !== AST_NODE_TYPES103.Literal
|
|
22313
22569
|
);
|
|
22314
22570
|
}
|
|
22315
22571
|
function isInlineUrl(node, resolvesToGlobal) {
|
|
@@ -22352,7 +22608,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
22352
22608
|
}
|
|
22353
22609
|
function resolvesToGlobal(identifier) {
|
|
22354
22610
|
const scope = context.sourceCode.getScope(identifier);
|
|
22355
|
-
const variable =
|
|
22611
|
+
const variable = ASTUtils65.findVariable(scope, identifier.name);
|
|
22356
22612
|
return variable === null || variable.defs.length === 0;
|
|
22357
22613
|
}
|
|
22358
22614
|
function isGlobalFetchCall2(callee) {
|
|
@@ -22361,10 +22617,10 @@ var require_fetch_timeout_default = createRule({
|
|
|
22361
22617
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
22362
22618
|
}
|
|
22363
22619
|
const receiver = callee.type === AST_NODE_TYPES103.MemberExpression ? unwrapExpression(callee.object) : null;
|
|
22364
|
-
return callee.type === AST_NODE_TYPES103.MemberExpression &&
|
|
22620
|
+
return callee.type === AST_NODE_TYPES103.MemberExpression && ASTUtils65.getPropertyName(callee) === "fetch" && receiver?.type === AST_NODE_TYPES103.Identifier && GLOBAL_OBJECTS2.has(receiver.name) && resolvesToGlobal(receiver);
|
|
22365
22621
|
}
|
|
22366
22622
|
function localConstInitSignalState(identifier) {
|
|
22367
|
-
const variable =
|
|
22623
|
+
const variable = ASTUtils65.findVariable(
|
|
22368
22624
|
context.sourceCode.getScope(identifier),
|
|
22369
22625
|
identifier.name
|
|
22370
22626
|
);
|
|
@@ -22386,7 +22642,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
22386
22642
|
function isForwardedRequest(argument) {
|
|
22387
22643
|
let value = unwrapExpression(argument);
|
|
22388
22644
|
if (value.type === AST_NODE_TYPES103.Identifier) {
|
|
22389
|
-
const binding =
|
|
22645
|
+
const binding = ASTUtils65.findVariable(
|
|
22390
22646
|
context.sourceCode.getScope(value),
|
|
22391
22647
|
value.name
|
|
22392
22648
|
);
|
|
@@ -22571,7 +22827,7 @@ function exportedClasses(program, classes) {
|
|
|
22571
22827
|
}
|
|
22572
22828
|
|
|
22573
22829
|
// src/rules/require-sql-access-class.ts
|
|
22574
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES105, ASTUtils as
|
|
22830
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES105, ASTUtils as ASTUtils66 } from "@typescript-eslint/utils";
|
|
22575
22831
|
var DIRECT_EXECUTION_METHODS = /* @__PURE__ */ new Set([
|
|
22576
22832
|
"all",
|
|
22577
22833
|
"batch",
|
|
@@ -22678,7 +22934,7 @@ function databaseReceiver(node) {
|
|
|
22678
22934
|
if (node.type === AST_NODE_TYPES105.Identifier)
|
|
22679
22935
|
return DATABASE_NAMES.test(node.name);
|
|
22680
22936
|
if (node.type !== AST_NODE_TYPES105.MemberExpression) return false;
|
|
22681
|
-
const name =
|
|
22937
|
+
const name = ASTUtils66.getPropertyName(node);
|
|
22682
22938
|
return name === "DB" || name !== null && DATABASE_NAMES.test(name);
|
|
22683
22939
|
}
|
|
22684
22940
|
function databaseRootMember(node) {
|
|
@@ -22696,7 +22952,7 @@ function databaseRootMember(node) {
|
|
|
22696
22952
|
}
|
|
22697
22953
|
if (current.type === AST_NODE_TYPES105.MemberExpression) {
|
|
22698
22954
|
if (current.object.type === AST_NODE_TYPES105.ThisExpression)
|
|
22699
|
-
return
|
|
22955
|
+
return ASTUtils66.getPropertyName(current);
|
|
22700
22956
|
current = current.object;
|
|
22701
22957
|
continue;
|
|
22702
22958
|
}
|
|
@@ -22717,7 +22973,7 @@ function expressionHasDatabaseMarker(node) {
|
|
|
22717
22973
|
continue;
|
|
22718
22974
|
}
|
|
22719
22975
|
if (current.type === AST_NODE_TYPES105.MemberExpression) {
|
|
22720
|
-
const name =
|
|
22976
|
+
const name = ASTUtils66.getPropertyName(current);
|
|
22721
22977
|
if (name === "DB" || name !== null && DATABASE_NAMES.test(name))
|
|
22722
22978
|
return true;
|
|
22723
22979
|
current = current.object;
|
|
@@ -22736,7 +22992,7 @@ function expressionCallsBuilder(node) {
|
|
|
22736
22992
|
}
|
|
22737
22993
|
if (current.type === AST_NODE_TYPES105.CallExpression) {
|
|
22738
22994
|
if (current.callee.type !== AST_NODE_TYPES105.MemberExpression) return false;
|
|
22739
|
-
const name =
|
|
22995
|
+
const name = ASTUtils66.getPropertyName(current.callee);
|
|
22740
22996
|
if (name !== null && BUILDER_METHODS.has(name)) return true;
|
|
22741
22997
|
current = current.callee.object;
|
|
22742
22998
|
continue;
|
|
@@ -22787,7 +23043,7 @@ function thisRootMember(node) {
|
|
|
22787
23043
|
let current = node;
|
|
22788
23044
|
let root = null;
|
|
22789
23045
|
while (current.type === AST_NODE_TYPES105.MemberExpression) {
|
|
22790
|
-
const name =
|
|
23046
|
+
const name = ASTUtils66.getPropertyName(current);
|
|
22791
23047
|
if (name === null) return null;
|
|
22792
23048
|
root = name;
|
|
22793
23049
|
current = current.object;
|
|
@@ -22831,19 +23087,19 @@ var require_sql_access_class_default = createRule({
|
|
|
22831
23087
|
if (seen.has(node)) return false;
|
|
22832
23088
|
seen.add(node);
|
|
22833
23089
|
if (node.type === AST_NODE_TYPES105.Identifier) {
|
|
22834
|
-
const binding =
|
|
23090
|
+
const binding = ASTUtils66.findVariable(context.sourceCode.getScope(node), node.name);
|
|
22835
23091
|
if (binding?.defs.length !== 1 || binding.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
22836
23092
|
const definition = binding.defs[0];
|
|
22837
23093
|
return definition?.type === "Variable" && definition.node.init !== null && knownNonDatabase(definition.node.init, seen);
|
|
22838
23094
|
}
|
|
22839
|
-
return node.type === AST_NODE_TYPES105.NewExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES105.Identifier && ["Map", "WeakMap", "URLSearchParams"].includes(unwrappedNodeCallee.name) && (
|
|
23095
|
+
return node.type === AST_NODE_TYPES105.NewExpression && unwrappedNodeCallee?.type === AST_NODE_TYPES105.Identifier && ["Map", "WeakMap", "URLSearchParams"].includes(unwrappedNodeCallee.name) && (ASTUtils66.findVariable(context.sourceCode.getScope(unwrappedNodeCallee), unwrappedNodeCallee.name)?.defs.length ?? 0) === 0;
|
|
22840
23096
|
}
|
|
22841
23097
|
return {
|
|
22842
23098
|
CallExpression(node) {
|
|
22843
23099
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
22844
23100
|
if (unwrappedNodeCallee.type !== AST_NODE_TYPES105.MemberExpression)
|
|
22845
23101
|
return;
|
|
22846
|
-
const method =
|
|
23102
|
+
const method = ASTUtils66.getPropertyName(unwrappedNodeCallee);
|
|
22847
23103
|
if (knownNonDatabase(unwrappedNodeCallee.object)) return;
|
|
22848
23104
|
if (method === null || !isDatabaseOperation(method, unwrappedNodeCallee.object))
|
|
22849
23105
|
return;
|
|
@@ -22943,7 +23199,7 @@ var require_static_next_matcher_default = createRule({
|
|
|
22943
23199
|
});
|
|
22944
23200
|
|
|
22945
23201
|
// src/rules/require-use-form-default-values.ts
|
|
22946
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES107, ASTUtils as
|
|
23202
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES107, ASTUtils as ASTUtils67 } from "@typescript-eslint/utils";
|
|
22947
23203
|
var REQUIRE_USE_FORM_DEFAULT_VALUES_DOCUMENTATION = {
|
|
22948
23204
|
summary: "Require explicit form-level initialization or a field default for directly bound Controller fields.",
|
|
22949
23205
|
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.",
|
|
@@ -22994,7 +23250,7 @@ var require_use_form_default_values_default = createRule({
|
|
|
22994
23250
|
const imported = /* @__PURE__ */ new Map();
|
|
22995
23251
|
const uninitializedForms = /* @__PURE__ */ new Set();
|
|
22996
23252
|
const uninitializedControls = /* @__PURE__ */ new Set();
|
|
22997
|
-
const bindingNamed = (node, name) =>
|
|
23253
|
+
const bindingNamed = (node, name) => ASTUtils67.findVariable(context.sourceCode.getScope(node), name);
|
|
22998
23254
|
const bindingOf = (node) => bindingNamed(node, node.name);
|
|
22999
23255
|
const stable = (variable) => !variable.references.some((reference) => reference.isWrite() && reference.init !== true);
|
|
23000
23256
|
const importedKind = (node) => {
|
|
@@ -23040,7 +23296,7 @@ var require_use_form_default_values_default = createRule({
|
|
|
23040
23296
|
const variable = bindingOf(node);
|
|
23041
23297
|
return variable !== null && stable(variable) && uninitializedControls.has(variable);
|
|
23042
23298
|
}
|
|
23043
|
-
return node.type === AST_NODE_TYPES107.MemberExpression &&
|
|
23299
|
+
return node.type === AST_NODE_TYPES107.MemberExpression && ASTUtils67.getPropertyName(node) !== null && (ASTUtils67.getPropertyName(node) ?? "") === "control" && isUninitializedForm(node.object);
|
|
23044
23300
|
};
|
|
23045
23301
|
const fieldOptionsNeedDefault = (node) => {
|
|
23046
23302
|
if (node?.type !== AST_NODE_TYPES107.ObjectExpression) return false;
|
|
@@ -23096,7 +23352,7 @@ var require_use_form_default_values_default = createRule({
|
|
|
23096
23352
|
trackDestructuredControl(node.id);
|
|
23097
23353
|
return;
|
|
23098
23354
|
}
|
|
23099
|
-
if (node.id.type === AST_NODE_TYPES107.Identifier && node.init.type === AST_NODE_TYPES107.MemberExpression &&
|
|
23355
|
+
if (node.id.type === AST_NODE_TYPES107.Identifier && node.init.type === AST_NODE_TYPES107.MemberExpression && ASTUtils67.getPropertyName(node.init) !== null && (ASTUtils67.getPropertyName(node.init) ?? "") === "control" && isUninitializedForm(node.init.object)) {
|
|
23100
23356
|
const variable = bindingOf(node.id);
|
|
23101
23357
|
if (variable !== null) uninitializedControls.add(variable);
|
|
23102
23358
|
}
|
|
@@ -23189,7 +23445,7 @@ var require_use_server_in_actions_file_default = createRule({
|
|
|
23189
23445
|
// src/rules/require-zod-form-validation.ts
|
|
23190
23446
|
import {
|
|
23191
23447
|
AST_NODE_TYPES as AST_NODE_TYPES108,
|
|
23192
|
-
ASTUtils as
|
|
23448
|
+
ASTUtils as ASTUtils68
|
|
23193
23449
|
} from "@typescript-eslint/utils";
|
|
23194
23450
|
var REQUIRE_ZOD_FORM_VALIDATION_DOCUMENTATION = {
|
|
23195
23451
|
summary: "Require Zod validation (`Schema.parse(...)` / `Schema.safeParse(...)`) when reading values out of a `FormData` object.",
|
|
@@ -23237,7 +23493,7 @@ var isFormDataMethodCall = (node) => {
|
|
|
23237
23493
|
}
|
|
23238
23494
|
if (current.type !== AST_NODE_TYPES108.CallExpression) return false;
|
|
23239
23495
|
const callee = unwrapExpression(current.callee);
|
|
23240
|
-
return callee.type === AST_NODE_TYPES108.MemberExpression &&
|
|
23496
|
+
return callee.type === AST_NODE_TYPES108.MemberExpression && ASTUtils68.getPropertyName(callee) === "formData";
|
|
23241
23497
|
};
|
|
23242
23498
|
var require_zod_form_validation_default = createRule({
|
|
23243
23499
|
name: "require-zod-form-validation",
|
|
@@ -23258,7 +23514,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
23258
23514
|
return {};
|
|
23259
23515
|
}
|
|
23260
23516
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
23261
|
-
const resolvedBinding = (identifier) =>
|
|
23517
|
+
const resolvedBinding = (identifier) => ASTUtils68.findVariable(
|
|
23262
23518
|
context.sourceCode.getScope(identifier),
|
|
23263
23519
|
identifier.name
|
|
23264
23520
|
);
|
|
@@ -23266,7 +23522,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
23266
23522
|
const callee = unwrapExpression(node.callee);
|
|
23267
23523
|
const calleeReceiver = callee.type === AST_NODE_TYPES108.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
23268
23524
|
if (callee.type !== AST_NODE_TYPES108.MemberExpression) return false;
|
|
23269
|
-
if (
|
|
23525
|
+
if (ASTUtils68.getPropertyName(callee) === null || !FORM_VALUE_METHODS.has(ASTUtils68.getPropertyName(callee) ?? "")) {
|
|
23270
23526
|
return false;
|
|
23271
23527
|
}
|
|
23272
23528
|
return isFormSourceIdentifier(calleeReceiver);
|
|
@@ -23297,7 +23553,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
23297
23553
|
parent = parent.parent;
|
|
23298
23554
|
continue;
|
|
23299
23555
|
}
|
|
23300
|
-
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" &&
|
|
23556
|
+
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" && ASTUtils68.getPropertyName(parent.callee) === "fromEntries" && (resolvedBinding(parent.callee.object)?.defs.length ?? 0) === 0) {
|
|
23301
23557
|
parent = parent.parent;
|
|
23302
23558
|
continue;
|
|
23303
23559
|
}
|
|
@@ -23310,7 +23566,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
23310
23566
|
if (node.type !== AST_NODE_TYPES108.CallExpression) return false;
|
|
23311
23567
|
const callee = unwrapExpression(node.callee);
|
|
23312
23568
|
const calleeReceiver = callee.type === AST_NODE_TYPES108.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
23313
|
-
if (callee.type !== AST_NODE_TYPES108.MemberExpression ||
|
|
23569
|
+
if (callee.type !== AST_NODE_TYPES108.MemberExpression || ASTUtils68.getPropertyName(callee) === null || !ZOD_PARSE_METHODS.has(ASTUtils68.getPropertyName(callee) ?? "")) {
|
|
23314
23570
|
return false;
|
|
23315
23571
|
}
|
|
23316
23572
|
const root = zodReceiverRoot(calleeReceiver);
|
|
@@ -23396,7 +23652,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
23396
23652
|
};
|
|
23397
23653
|
const zodParseMethod = (call) => {
|
|
23398
23654
|
const callee = unwrapExpression(call.callee);
|
|
23399
|
-
return callee.type === AST_NODE_TYPES108.MemberExpression &&
|
|
23655
|
+
return callee.type === AST_NODE_TYPES108.MemberExpression && ASTUtils68.getPropertyName(callee) !== null ? ASTUtils68.getPropertyName(callee) ?? "" : null;
|
|
23400
23656
|
};
|
|
23401
23657
|
const isSafePrevalidationInspection = (identifier) => {
|
|
23402
23658
|
const parent = identifier.parent;
|
|
@@ -23572,7 +23828,7 @@ function expressionCallableName(current) {
|
|
|
23572
23828
|
}
|
|
23573
23829
|
|
|
23574
23830
|
// src/rules/stepdown.ts
|
|
23575
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES109, ASTUtils as
|
|
23831
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES109, ASTUtils as ASTUtils69 } from "@typescript-eslint/utils";
|
|
23576
23832
|
var STEPDOWN_DOCUMENTATION = {
|
|
23577
23833
|
summary: "Place a private helper below its sole direct same-scope caller.",
|
|
23578
23834
|
rationale: "Caller-first ordering lets a reader follow the main flow before descending into implementation details.",
|
|
@@ -23872,7 +24128,7 @@ function receiverOrigin(context, object, receivers) {
|
|
|
23872
24128
|
while (true) {
|
|
23873
24129
|
const unwrapped = unwrapExpression4(current);
|
|
23874
24130
|
if (unwrapped.type !== AST_NODE_TYPES109.Identifier) return unwrapped;
|
|
23875
|
-
const variable =
|
|
24131
|
+
const variable = ASTUtils69.findVariable(context.sourceCode.getScope(unwrapped), unwrapped.name);
|
|
23876
24132
|
if (variable === null) return null;
|
|
23877
24133
|
const known = receivers.get(variable);
|
|
23878
24134
|
if (known !== void 0) return known;
|
|
@@ -24053,11 +24309,11 @@ function classScope(context, node, computedReferences) {
|
|
|
24053
24309
|
function classReceiverBindings(context, node) {
|
|
24054
24310
|
const classReceivers = /* @__PURE__ */ new Map();
|
|
24055
24311
|
if (node.id !== null) {
|
|
24056
|
-
const internal =
|
|
24312
|
+
const internal = ASTUtils69.findVariable(context.sourceCode.getScope(node), node.id.name);
|
|
24057
24313
|
if (internal !== null && stableVariable(internal)) classReceivers.set(internal, true);
|
|
24058
24314
|
}
|
|
24059
24315
|
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") {
|
|
24060
|
-
const outer =
|
|
24316
|
+
const outer = ASTUtils69.findVariable(context.sourceCode.getScope(node.parent), node.parent.id.name);
|
|
24061
24317
|
if (outer !== null && stableVariable(outer)) classReceivers.set(outer, true);
|
|
24062
24318
|
}
|
|
24063
24319
|
return classReceivers;
|
|
@@ -24143,7 +24399,7 @@ function classMethodCounts(body2, methods) {
|
|
|
24143
24399
|
}
|
|
24144
24400
|
|
|
24145
24401
|
// src/rules/source-coupled-test.ts
|
|
24146
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES110, ASTUtils as
|
|
24402
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES110, ASTUtils as ASTUtils70 } from "@typescript-eslint/utils";
|
|
24147
24403
|
var GENERAL_SOURCE_SUFFIX_RE = /\.(?:bash|sh|ya?ml|jsonc?|toml|py|[cm]?[jt]s)$/iu;
|
|
24148
24404
|
var FS_MODULES = /* @__PURE__ */ new Set(["fs", "node:fs", "fs/promises", "node:fs/promises"]);
|
|
24149
24405
|
var FS_READERS = /* @__PURE__ */ new Set(["readFile", "readFileSync"]);
|
|
@@ -24260,7 +24516,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
24260
24516
|
const scopes = [newScope()];
|
|
24261
24517
|
const reportedOrigins = /* @__PURE__ */ new Set();
|
|
24262
24518
|
const currentScope = () => scopes.at(-1) ?? scopes[0];
|
|
24263
|
-
const bindingOf = (node) =>
|
|
24519
|
+
const bindingOf = (node) => ASTUtils70.findVariable(context.sourceCode.getScope(node), node.name);
|
|
24264
24520
|
const assertionKind = (node) => {
|
|
24265
24521
|
const binding = bindingOf(node);
|
|
24266
24522
|
if (binding === null || binding.defs.length === 0) {
|
|
@@ -24313,7 +24569,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
24313
24569
|
return visible("fsReaders", callee) && sourcePath(current.arguments[0]);
|
|
24314
24570
|
}
|
|
24315
24571
|
if (callee.type !== AST_NODE_TYPES110.MemberExpression) return false;
|
|
24316
|
-
const name2 =
|
|
24572
|
+
const name2 = ASTUtils70.getPropertyName(callee);
|
|
24317
24573
|
const object = unwrap6(calleeReceiver);
|
|
24318
24574
|
return name2 !== null && FS_READERS.has(name2) && object.type === AST_NODE_TYPES110.Identifier && visible("fsObjects", object) && sourcePath(current.arguments[0]);
|
|
24319
24575
|
};
|
|
@@ -24322,12 +24578,12 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
24322
24578
|
if (current.type === AST_NODE_TYPES110.Identifier) return visibleRawOrigins(current);
|
|
24323
24579
|
if (rawRead(current)) return /* @__PURE__ */ new Set([`${current.range[0]}:${current.range[1]}`]);
|
|
24324
24580
|
if (current.type === AST_NODE_TYPES110.BinaryExpression && current.operator === "+") return /* @__PURE__ */ new Set([...rawOrigins(current.left), ...rawOrigins(current.right)]);
|
|
24325
|
-
if (current.type === AST_NODE_TYPES110.MemberExpression &&
|
|
24581
|
+
if (current.type === AST_NODE_TYPES110.MemberExpression && ASTUtils70.getPropertyName(current) === "length") return rawOrigins(current.object);
|
|
24326
24582
|
if (current.type !== AST_NODE_TYPES110.CallExpression) return /* @__PURE__ */ new Set();
|
|
24327
24583
|
const callee = unwrap6(current.callee);
|
|
24328
24584
|
const calleeReceiver = callee.type === AST_NODE_TYPES110.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
24329
24585
|
if (callee.type !== AST_NODE_TYPES110.MemberExpression) return /* @__PURE__ */ new Set();
|
|
24330
|
-
const name2 =
|
|
24586
|
+
const name2 = ASTUtils70.getPropertyName(callee);
|
|
24331
24587
|
return name2 !== null && TEXT_TRANSFORMS.has(name2) ? rawOrigins(calleeReceiver) : /* @__PURE__ */ new Set();
|
|
24332
24588
|
};
|
|
24333
24589
|
const evidenceOrigins = (node) => {
|
|
@@ -24340,7 +24596,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
24340
24596
|
const callee = unwrap6(current.callee);
|
|
24341
24597
|
const calleeReceiver = callee.type === AST_NODE_TYPES110.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
24342
24598
|
if (callee.type !== AST_NODE_TYPES110.MemberExpression) return /* @__PURE__ */ new Set();
|
|
24343
|
-
const name2 =
|
|
24599
|
+
const name2 = ASTUtils70.getPropertyName(callee);
|
|
24344
24600
|
if (name2 !== null && TEXT_PREDICATES.has(name2)) return rawOrigins(calleeReceiver);
|
|
24345
24601
|
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES110.SpreadElement ? [] : [...rawOrigins(argument)]));
|
|
24346
24602
|
return /* @__PURE__ */ new Set();
|
|
@@ -24352,10 +24608,10 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
24352
24608
|
return new Set(node.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES110.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
24353
24609
|
}
|
|
24354
24610
|
if (callee.type !== AST_NODE_TYPES110.MemberExpression) return /* @__PURE__ */ new Set();
|
|
24355
|
-
const matcher =
|
|
24611
|
+
const matcher = ASTUtils70.getPropertyName(callee);
|
|
24356
24612
|
if (matcher === null) return /* @__PURE__ */ new Set();
|
|
24357
24613
|
let receiver = unwrap6(calleeReceiver);
|
|
24358
|
-
while (receiver.type === AST_NODE_TYPES110.MemberExpression && EXPECT_MODIFIERS2.has(
|
|
24614
|
+
while (receiver.type === AST_NODE_TYPES110.MemberExpression && EXPECT_MODIFIERS2.has(ASTUtils70.getPropertyName(receiver) ?? "")) receiver = unwrap6(receiver.object);
|
|
24359
24615
|
const expectCallee = receiver.type === AST_NODE_TYPES110.CallExpression ? unwrapExpression(receiver.callee) : null;
|
|
24360
24616
|
if (receiver.type === AST_NODE_TYPES110.CallExpression && expectCallee?.type === AST_NODE_TYPES110.Identifier && assertionKind(expectCallee) === "expect") {
|
|
24361
24617
|
if (!EXPECT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
@@ -24638,7 +24894,7 @@ var iac_source_coupled_test_default = createSourceCoupledRule(
|
|
|
24638
24894
|
// src/rules/require-pascal-case-zod-schema-name.ts
|
|
24639
24895
|
import {
|
|
24640
24896
|
AST_NODE_TYPES as AST_NODE_TYPES112,
|
|
24641
|
-
ASTUtils as
|
|
24897
|
+
ASTUtils as ASTUtils71
|
|
24642
24898
|
} from "@typescript-eslint/utils";
|
|
24643
24899
|
var REQUIRE_PASCAL_CASE_ZOD_SCHEMA_NAME_DOCUMENTATION = {
|
|
24644
24900
|
summary: "Require confirmed module-level Zod schema contracts to use PascalCase with a `Schema` suffix.",
|
|
@@ -24771,7 +25027,7 @@ var SCHEMA_RETURNING_METHODS = /* @__PURE__ */ new Set([
|
|
|
24771
25027
|
"superRefine",
|
|
24772
25028
|
"transform"
|
|
24773
25029
|
]);
|
|
24774
|
-
var terminalMethodName = (callee) =>
|
|
25030
|
+
var terminalMethodName = (callee) => ASTUtils71.getPropertyName(callee) !== null ? ASTUtils71.getPropertyName(callee) ?? "" : null;
|
|
24775
25031
|
var calleeChainRoot2 = (node) => {
|
|
24776
25032
|
let current = node;
|
|
24777
25033
|
for (; ; ) {
|
|
@@ -24796,8 +25052,8 @@ var chainMemberNames2 = (node) => {
|
|
|
24796
25052
|
for (; ; ) {
|
|
24797
25053
|
current = unwrapExpression(current);
|
|
24798
25054
|
if (current.type === AST_NODE_TYPES112.MemberExpression) {
|
|
24799
|
-
if (
|
|
24800
|
-
names.push(
|
|
25055
|
+
if (ASTUtils71.getPropertyName(current) === null) return [];
|
|
25056
|
+
names.push(ASTUtils71.getPropertyName(current) ?? "");
|
|
24801
25057
|
current = current.object;
|
|
24802
25058
|
continue;
|
|
24803
25059
|
}
|
|
@@ -24834,7 +25090,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
24834
25090
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
24835
25091
|
const schemaBindings = /* @__PURE__ */ new Set();
|
|
24836
25092
|
function resolvedBinding(identifier) {
|
|
24837
|
-
return
|
|
25093
|
+
return ASTUtils71.findVariable(
|
|
24838
25094
|
context.sourceCode.getScope(identifier),
|
|
24839
25095
|
identifier.name
|
|
24840
25096
|
);
|
|
@@ -25015,6 +25271,7 @@ var RULES = {
|
|
|
25015
25271
|
"no-hand-rolled-spinner": no_hand_rolled_spinner_default,
|
|
25016
25272
|
"no-insecure-random-id": no_insecure_random_id_default,
|
|
25017
25273
|
"no-detached-global-fetch": no_detached_global_fetch_default,
|
|
25274
|
+
"no-exception-text-in-5xx-response": no_exception_text_in_5xx_response_default,
|
|
25018
25275
|
"no-json-stringify-error": no_json_stringify_error_default,
|
|
25019
25276
|
"no-json-stringify-object-equality": no_json_stringify_object_equality_default,
|
|
25020
25277
|
"no-impossible-zod-literal-bounds": no_impossible_zod_literal_bounds_default,
|
|
@@ -25116,6 +25373,8 @@ var LIBRARY_IMPORT_POLICY = ["error", {
|
|
|
25116
25373
|
var ADVISORY_RULES = [
|
|
25117
25374
|
"@sarj/excessive-commentary",
|
|
25118
25375
|
"@sarj/no-bespoke-api-case-conversion",
|
|
25376
|
+
"@sarj/no-cors-wildcard-with-credentials",
|
|
25377
|
+
"@sarj/no-exception-text-in-5xx-response",
|
|
25119
25378
|
"@sarj/no-restated-comment",
|
|
25120
25379
|
"@sarj/no-restated-jsdoc",
|
|
25121
25380
|
"@sarj/prefer-millisecond-control-duration-schema",
|
|
@@ -25152,12 +25411,13 @@ var RECOMMENDED_RULES = {
|
|
|
25152
25411
|
"@sarj/enforce-file-structure": "error",
|
|
25153
25412
|
"@sarj/no-client-side-data-fetching": "error",
|
|
25154
25413
|
"@sarj/no-comment-cruft": "error",
|
|
25155
|
-
"@sarj/no-cors-wildcard-with-credentials": "
|
|
25414
|
+
"@sarj/no-cors-wildcard-with-credentials": "warn",
|
|
25156
25415
|
"@sarj/no-dynamic-sql": "error",
|
|
25157
25416
|
"@sarj/no-fat-try-blocks": ["error", { max: 5 }],
|
|
25158
25417
|
"@sarj/no-hand-rolled-sleep": "error",
|
|
25159
25418
|
"@sarj/no-hand-rolled-spinner": "error",
|
|
25160
25419
|
"@sarj/no-insecure-random-id": "error",
|
|
25420
|
+
"@sarj/no-exception-text-in-5xx-response": "warn",
|
|
25161
25421
|
"@sarj/no-json-stringify-error": "error",
|
|
25162
25422
|
"@sarj/no-impossible-zod-literal-bounds": "error",
|
|
25163
25423
|
"@sarj/no-in-operator-on-built-in-collections": "error",
|
|
@@ -25270,13 +25530,14 @@ var STRICT_RULES = {
|
|
|
25270
25530
|
"@sarj/enforce-file-structure": "error",
|
|
25271
25531
|
"@sarj/no-client-side-data-fetching": "error",
|
|
25272
25532
|
"@sarj/no-comment-cruft": "error",
|
|
25273
|
-
"@sarj/no-cors-wildcard-with-credentials": "
|
|
25533
|
+
"@sarj/no-cors-wildcard-with-credentials": "warn",
|
|
25274
25534
|
"@sarj/no-dynamic-sql": "error",
|
|
25275
25535
|
"@sarj/no-enum": "error",
|
|
25276
25536
|
"@sarj/no-fat-try-blocks": ["error", { max: 5 }],
|
|
25277
25537
|
"@sarj/no-hand-rolled-sleep": "error",
|
|
25278
25538
|
"@sarj/no-hand-rolled-spinner": "error",
|
|
25279
25539
|
"@sarj/no-insecure-random-id": "error",
|
|
25540
|
+
"@sarj/no-exception-text-in-5xx-response": "warn",
|
|
25280
25541
|
"@sarj/no-json-stringify-error": "error",
|
|
25281
25542
|
"@sarj/no-impossible-zod-literal-bounds": "error",
|
|
25282
25543
|
"@sarj/no-in-operator-on-built-in-collections": "error",
|