@sarj/eslint-plugin 15.8.2 → 15.10.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 +1012 -805
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +1007 -799
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4718,11 +4718,11 @@ var no_offset_pagination_default = createRule({
|
|
|
4718
4718
|
// src/rules/no-positional-tuple-return.ts
|
|
4719
4719
|
var import_utils24 = require("@typescript-eslint/utils");
|
|
4720
4720
|
var noPositionalTupleReturnDocumentation = {
|
|
4721
|
-
summary: "Disallow returning a multi-field tuple from
|
|
4722
|
-
rationale: "
|
|
4721
|
+
summary: "Disallow returning a multi-field tuple from a named function; return a named object so call sites cannot mismatch slots.",
|
|
4722
|
+
rationale: "Tuple fields are identified only by position, so reordering can preserve types while changing meaning.",
|
|
4723
4723
|
remediation: "Return an object whose property names describe each value.",
|
|
4724
4724
|
category: "maintainability",
|
|
4725
|
-
limitations: ["
|
|
4725
|
+
limitations: ["Declared or syntax-proven multi-field tuple returns on named functions and public type surfaces are inspected; anonymous inline callbacks and syntax-proven TanStack Query key factories are excluded."],
|
|
4726
4726
|
examples: [
|
|
4727
4727
|
{ id: "named-object-return", title: "Return named fields", outcome: "no-match", files: [{ path: "src/download.ts", source: "export function download(): { body: string; status: number } { return impl(); }" }], focusPath: "src/download.ts", expectedCount: 0, public: true },
|
|
4728
4728
|
{ id: "tuple-return", title: "Do not expose positional fields", outcome: "match", files: [{ path: "src/download.ts", source: "export function download(): [string, number] { return impl(); }" }], focusPath: "src/download.ts", expectedCount: 1, public: true }
|
|
@@ -4760,6 +4760,16 @@ function tupleReturnType(node, aliases, resolving = /* @__PURE__ */ new Set()) {
|
|
|
4760
4760
|
}
|
|
4761
4761
|
return null;
|
|
4762
4762
|
}
|
|
4763
|
+
function tupleExpression(node, aliases) {
|
|
4764
|
+
if (node.type !== import_utils24.AST_NODE_TYPES.TSAsExpression && node.type !== import_utils24.AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
4765
|
+
return null;
|
|
4766
|
+
}
|
|
4767
|
+
if (node.expression.type !== import_utils24.AST_NODE_TYPES.ArrayExpression || node.expression.elements.length < MIN_ELEMENTS) {
|
|
4768
|
+
return null;
|
|
4769
|
+
}
|
|
4770
|
+
if (node.type === import_utils24.AST_NODE_TYPES.TSAsExpression && node.typeAnnotation.type === import_utils24.AST_NODE_TYPES.TSTypeReference && node.typeAnnotation.typeName.type === import_utils24.AST_NODE_TYPES.Identifier && node.typeAnnotation.typeName.name === "const") return node.expression;
|
|
4771
|
+
return tupleReturnType(node.typeAnnotation, aliases) === null ? null : node.expression;
|
|
4772
|
+
}
|
|
4763
4773
|
function functionName(node) {
|
|
4764
4774
|
if (node.type === import_utils24.AST_NODE_TYPES.FunctionDeclaration) {
|
|
4765
4775
|
if (node.id !== null) return node.id.name;
|
|
@@ -4775,60 +4785,25 @@ function functionName(node) {
|
|
|
4775
4785
|
return parent.id.name;
|
|
4776
4786
|
}
|
|
4777
4787
|
if ((parent?.type === import_utils24.AST_NODE_TYPES.MethodDefinition || parent?.type === import_utils24.AST_NODE_TYPES.TSAbstractMethodDefinition || parent?.type === import_utils24.AST_NODE_TYPES.PropertyDefinition || parent?.type === import_utils24.AST_NODE_TYPES.Property) && parent.key.type === import_utils24.AST_NODE_TYPES.Identifier) {
|
|
4778
|
-
if ((parent.type === import_utils24.AST_NODE_TYPES.MethodDefinition || parent.type === import_utils24.AST_NODE_TYPES.TSAbstractMethodDefinition || parent.type === import_utils24.AST_NODE_TYPES.PropertyDefinition) && (parent.accessibility === "private" || parent.accessibility === "protected")) return null;
|
|
4779
4788
|
return parent.key.name;
|
|
4780
4789
|
}
|
|
4781
4790
|
return null;
|
|
4782
4791
|
}
|
|
4783
|
-
function
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
return false;
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
}
|
|
4798
|
-
if (current.parent?.type !== import_utils24.AST_NODE_TYPES.Program) {
|
|
4799
|
-
return null;
|
|
4800
|
-
}
|
|
4801
|
-
let topLevel = current;
|
|
4802
|
-
if (current.type === import_utils24.AST_NODE_TYPES.ExportNamedDeclaration || current.type === import_utils24.AST_NODE_TYPES.ExportDefaultDeclaration) {
|
|
4803
|
-
topLevel = current.declaration;
|
|
4804
|
-
}
|
|
4805
|
-
if (topLevel === null) return null;
|
|
4806
|
-
if (topLevel.type === import_utils24.AST_NODE_TYPES.FunctionDeclaration) {
|
|
4807
|
-
if (topLevel !== node) return null;
|
|
4808
|
-
return topLevel.id?.name ?? (current.type === import_utils24.AST_NODE_TYPES.ExportDefaultDeclaration ? "default" : null);
|
|
4809
|
-
}
|
|
4810
|
-
if ((topLevel.type === import_utils24.AST_NODE_TYPES.ArrowFunctionExpression || topLevel.type === import_utils24.AST_NODE_TYPES.FunctionExpression) && topLevel === node && current.type === import_utils24.AST_NODE_TYPES.ExportDefaultDeclaration) {
|
|
4811
|
-
return "default";
|
|
4812
|
-
}
|
|
4813
|
-
if (topLevel.type === import_utils24.AST_NODE_TYPES.ClassDeclaration) {
|
|
4814
|
-
let owner = node.parent;
|
|
4815
|
-
while (owner != null && owner.parent !== topLevel.body) owner = owner.parent;
|
|
4816
|
-
return (owner?.type === import_utils24.AST_NODE_TYPES.MethodDefinition || owner?.type === import_utils24.AST_NODE_TYPES.TSAbstractMethodDefinition || owner?.type === import_utils24.AST_NODE_TYPES.PropertyDefinition) && owner.value === node ? topLevel.id?.name ?? (current.type === import_utils24.AST_NODE_TYPES.ExportDefaultDeclaration ? "default" : null) : null;
|
|
4817
|
-
}
|
|
4818
|
-
if (topLevel.type === import_utils24.AST_NODE_TYPES.VariableDeclaration) {
|
|
4819
|
-
for (const declarator of topLevel.declarations) {
|
|
4820
|
-
let initializer = declarator.init;
|
|
4821
|
-
while (initializer?.type === import_utils24.AST_NODE_TYPES.TSAsExpression || initializer?.type === import_utils24.AST_NODE_TYPES.TSSatisfiesExpression || initializer?.type === import_utils24.AST_NODE_TYPES.TSNonNullExpression) initializer = initializer.expression;
|
|
4822
|
-
if (declarator.id.type === import_utils24.AST_NODE_TYPES.Identifier && initializer === node) return declarator.id.name;
|
|
4823
|
-
if (declarator.id.type === import_utils24.AST_NODE_TYPES.Identifier && (initializer?.type === import_utils24.AST_NODE_TYPES.ClassExpression || initializer?.type === import_utils24.AST_NODE_TYPES.ObjectExpression)) {
|
|
4824
|
-
let owner = node.parent;
|
|
4825
|
-
const container = initializer.type === import_utils24.AST_NODE_TYPES.ClassExpression ? initializer.body : initializer;
|
|
4826
|
-
while (owner != null && owner.parent !== container) owner = owner.parent;
|
|
4827
|
-
if ((owner?.type === import_utils24.AST_NODE_TYPES.MethodDefinition || owner?.type === import_utils24.AST_NODE_TYPES.PropertyDefinition || owner?.type === import_utils24.AST_NODE_TYPES.Property) && owner.value === node) return declarator.id.name;
|
|
4828
|
-
}
|
|
4829
|
-
}
|
|
4830
|
-
}
|
|
4831
|
-
return null;
|
|
4792
|
+
function isQueryKeyFactory(node) {
|
|
4793
|
+
let wrapped = node;
|
|
4794
|
+
while ((wrapped.parent?.type === import_utils24.AST_NODE_TYPES.TSAsExpression || wrapped.parent?.type === import_utils24.AST_NODE_TYPES.TSSatisfiesExpression || wrapped.parent?.type === import_utils24.AST_NODE_TYPES.TSNonNullExpression) && wrapped.parent.expression === wrapped) wrapped = wrapped.parent;
|
|
4795
|
+
const property = wrapped.parent;
|
|
4796
|
+
if (property?.type !== import_utils24.AST_NODE_TYPES.Property || property.value !== wrapped) return false;
|
|
4797
|
+
const object = property.parent;
|
|
4798
|
+
if (object.type !== import_utils24.AST_NODE_TYPES.ObjectExpression) return false;
|
|
4799
|
+
const assertion = object.parent;
|
|
4800
|
+
if (assertion.type !== import_utils24.AST_NODE_TYPES.TSAsExpression || assertion.expression !== object || assertion.typeAnnotation.type !== import_utils24.AST_NODE_TYPES.TSTypeReference || assertion.typeAnnotation.typeName.type !== import_utils24.AST_NODE_TYPES.Identifier || assertion.typeAnnotation.typeName.name !== "const") return false;
|
|
4801
|
+
const declarator = assertion.parent;
|
|
4802
|
+
if (declarator.type !== import_utils24.AST_NODE_TYPES.VariableDeclarator || declarator.id.type !== import_utils24.AST_NODE_TYPES.Identifier || !/Keys$/i.test(declarator.id.name) || declarator.parent.type !== import_utils24.AST_NODE_TYPES.VariableDeclaration || declarator.parent.kind !== "const") return false;
|
|
4803
|
+
return object.properties.some((candidate) => {
|
|
4804
|
+
if (candidate.type !== import_utils24.AST_NODE_TYPES.Property || staticMemberName3(candidate.key) !== "all") return false;
|
|
4805
|
+
return candidate.value.type === import_utils24.AST_NODE_TYPES.TSAsExpression && candidate.value.expression.type === import_utils24.AST_NODE_TYPES.ArrayExpression && candidate.value.typeAnnotation.type === import_utils24.AST_NODE_TYPES.TSTypeReference && candidate.value.typeAnnotation.typeName.type === import_utils24.AST_NODE_TYPES.Identifier && candidate.value.typeAnnotation.typeName.name === "const";
|
|
4806
|
+
});
|
|
4832
4807
|
}
|
|
4833
4808
|
function specifierExportedNames(program) {
|
|
4834
4809
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -4937,18 +4912,52 @@ function isExportedClass(node, specifierExports) {
|
|
|
4937
4912
|
if (node.parent.type === import_utils24.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === import_utils24.AST_NODE_TYPES.Identifier) return specifierExports.has(node.parent.id.name) || isInlineExported(node);
|
|
4938
4913
|
return false;
|
|
4939
4914
|
}
|
|
4940
|
-
function
|
|
4941
|
-
|
|
4915
|
+
function isInlineExported(node) {
|
|
4916
|
+
if (moduleScopeBindingName(node) === null) return false;
|
|
4917
|
+
for (let current = node; current != null; current = current.parent) {
|
|
4918
|
+
const parent = current.parent;
|
|
4919
|
+
if (parent?.type === import_utils24.AST_NODE_TYPES.ExportNamedDeclaration || parent?.type === import_utils24.AST_NODE_TYPES.ExportDefaultDeclaration) {
|
|
4920
|
+
return true;
|
|
4921
|
+
}
|
|
4922
|
+
}
|
|
4923
|
+
return false;
|
|
4942
4924
|
}
|
|
4943
|
-
function
|
|
4944
|
-
|
|
4945
|
-
|
|
4925
|
+
function moduleScopeBindingName(node) {
|
|
4926
|
+
let current = node;
|
|
4927
|
+
while (current.parent != null && current.parent.type !== import_utils24.AST_NODE_TYPES.Program) {
|
|
4928
|
+
current = current.parent;
|
|
4946
4929
|
}
|
|
4947
|
-
if (
|
|
4948
|
-
|
|
4930
|
+
if (current.parent?.type !== import_utils24.AST_NODE_TYPES.Program) return null;
|
|
4931
|
+
let topLevel = current;
|
|
4932
|
+
if (current.type === import_utils24.AST_NODE_TYPES.ExportNamedDeclaration || current.type === import_utils24.AST_NODE_TYPES.ExportDefaultDeclaration) topLevel = current.declaration;
|
|
4933
|
+
if (topLevel === null) return null;
|
|
4934
|
+
if (topLevel.type === import_utils24.AST_NODE_TYPES.FunctionDeclaration) {
|
|
4935
|
+
if (topLevel !== node) return null;
|
|
4936
|
+
return topLevel.id?.name ?? (current.type === import_utils24.AST_NODE_TYPES.ExportDefaultDeclaration ? "default" : null);
|
|
4937
|
+
}
|
|
4938
|
+
if ((topLevel.type === import_utils24.AST_NODE_TYPES.ArrowFunctionExpression || topLevel.type === import_utils24.AST_NODE_TYPES.FunctionExpression) && topLevel === node && current.type === import_utils24.AST_NODE_TYPES.ExportDefaultDeclaration) return "default";
|
|
4939
|
+
if (topLevel.type === import_utils24.AST_NODE_TYPES.ClassDeclaration) {
|
|
4940
|
+
let owner = node.parent;
|
|
4941
|
+
while (owner != null && owner.parent !== topLevel.body) owner = owner.parent;
|
|
4942
|
+
return (owner?.type === import_utils24.AST_NODE_TYPES.MethodDefinition || owner?.type === import_utils24.AST_NODE_TYPES.TSAbstractMethodDefinition || owner?.type === import_utils24.AST_NODE_TYPES.PropertyDefinition) && owner.value === node ? topLevel.id?.name ?? (current.type === import_utils24.AST_NODE_TYPES.ExportDefaultDeclaration ? "default" : null) : null;
|
|
4949
4943
|
}
|
|
4950
|
-
|
|
4951
|
-
|
|
4944
|
+
if (topLevel.type === import_utils24.AST_NODE_TYPES.VariableDeclaration) {
|
|
4945
|
+
for (const declarator of topLevel.declarations) {
|
|
4946
|
+
let initializer = declarator.init;
|
|
4947
|
+
while (initializer?.type === import_utils24.AST_NODE_TYPES.TSAsExpression || initializer?.type === import_utils24.AST_NODE_TYPES.TSSatisfiesExpression || initializer?.type === import_utils24.AST_NODE_TYPES.TSNonNullExpression) initializer = initializer.expression;
|
|
4948
|
+
if (declarator.id.type === import_utils24.AST_NODE_TYPES.Identifier && initializer === node) return declarator.id.name;
|
|
4949
|
+
if (declarator.id.type === import_utils24.AST_NODE_TYPES.Identifier && (initializer?.type === import_utils24.AST_NODE_TYPES.ClassExpression || initializer?.type === import_utils24.AST_NODE_TYPES.ObjectExpression)) {
|
|
4950
|
+
let owner = node.parent;
|
|
4951
|
+
const container = initializer.type === import_utils24.AST_NODE_TYPES.ClassExpression ? initializer.body : initializer;
|
|
4952
|
+
while (owner != null && owner.parent !== container) owner = owner.parent;
|
|
4953
|
+
if ((owner?.type === import_utils24.AST_NODE_TYPES.MethodDefinition || owner?.type === import_utils24.AST_NODE_TYPES.PropertyDefinition || owner?.type === import_utils24.AST_NODE_TYPES.Property) && owner.value === node) return declarator.id.name;
|
|
4954
|
+
}
|
|
4955
|
+
}
|
|
4956
|
+
}
|
|
4957
|
+
return null;
|
|
4958
|
+
}
|
|
4959
|
+
function isExportedInterface(node, exports2) {
|
|
4960
|
+
return node.parent.type === import_utils24.AST_NODE_TYPES.ExportNamedDeclaration || node.parent.type === import_utils24.AST_NODE_TYPES.ExportDefaultDeclaration || node.parent.type === import_utils24.AST_NODE_TYPES.Program && exports2.has(node.id.name);
|
|
4952
4961
|
}
|
|
4953
4962
|
var no_positional_tuple_return_default = createRule({
|
|
4954
4963
|
name: "no-positional-tuple-return",
|
|
@@ -4956,11 +4965,11 @@ var no_positional_tuple_return_default = createRule({
|
|
|
4956
4965
|
meta: {
|
|
4957
4966
|
type: "suggestion",
|
|
4958
4967
|
docs: {
|
|
4959
|
-
description: "Disallow returning a multi-field tuple from
|
|
4968
|
+
description: "Disallow returning a multi-field tuple from a named function; return a named object so call sites cannot mismatch slots."
|
|
4960
4969
|
},
|
|
4961
4970
|
schema: [],
|
|
4962
4971
|
messages: {
|
|
4963
|
-
noPositionalTupleReturn: "
|
|
4972
|
+
noPositionalTupleReturn: "`{{name}}` returns a {{count}}-field tuple, so callers depend on positional slots that can be reordered silently. Return a named object instead."
|
|
4964
4973
|
}
|
|
4965
4974
|
},
|
|
4966
4975
|
defaultOptions: [],
|
|
@@ -4972,6 +4981,8 @@ var no_positional_tuple_return_default = createRule({
|
|
|
4972
4981
|
exportedTypeNames(context.sourceCode.ast)
|
|
4973
4982
|
);
|
|
4974
4983
|
const aliases = typeAliases(context.sourceCode.ast);
|
|
4984
|
+
const reportedFunctions = /* @__PURE__ */ new WeakSet();
|
|
4985
|
+
const functionStack = [];
|
|
4975
4986
|
const report = (annotation, name) => {
|
|
4976
4987
|
const tuple = tupleReturnType(annotation, aliases);
|
|
4977
4988
|
if (tuple === null || tuple.elementTypes.length < MIN_ELEMENTS) return;
|
|
@@ -4981,25 +4992,54 @@ var no_positional_tuple_return_default = createRule({
|
|
|
4981
4992
|
data: { name, count: String(tuple.elementTypes.length) }
|
|
4982
4993
|
});
|
|
4983
4994
|
};
|
|
4995
|
+
const reportExpression = (node, expression) => {
|
|
4996
|
+
if (reportedFunctions.has(node)) return;
|
|
4997
|
+
const tuple = tupleExpression(expression, aliases);
|
|
4998
|
+
const name = functionName(node);
|
|
4999
|
+
if (tuple === null || name === null) return;
|
|
5000
|
+
reportedFunctions.add(node);
|
|
5001
|
+
context.report({
|
|
5002
|
+
node: tuple,
|
|
5003
|
+
messageId: "noPositionalTupleReturn",
|
|
5004
|
+
data: { name, count: String(tuple.elements.length) }
|
|
5005
|
+
});
|
|
5006
|
+
};
|
|
4984
5007
|
const check = (node) => {
|
|
5008
|
+
if (isQueryKeyFactory(node)) return;
|
|
4985
5009
|
const annotation = node.returnType?.typeAnnotation;
|
|
4986
5010
|
if (annotation === void 0) {
|
|
5011
|
+
if (node.type === import_utils24.AST_NODE_TYPES.ArrowFunctionExpression && node.expression) {
|
|
5012
|
+
reportExpression(node, node.body);
|
|
5013
|
+
}
|
|
4987
5014
|
return;
|
|
4988
5015
|
}
|
|
4989
5016
|
const name = functionName(node);
|
|
4990
5017
|
if (name === null) {
|
|
4991
5018
|
return;
|
|
4992
5019
|
}
|
|
4993
|
-
if (!isExported(node, specifierExports)) {
|
|
4994
|
-
return;
|
|
4995
|
-
}
|
|
4996
5020
|
report(annotation, name);
|
|
4997
5021
|
};
|
|
5022
|
+
const enterFunction = (node) => {
|
|
5023
|
+
functionStack.push(node);
|
|
5024
|
+
check(node);
|
|
5025
|
+
};
|
|
5026
|
+
const exitFunction = () => {
|
|
5027
|
+
functionStack.pop();
|
|
5028
|
+
};
|
|
4998
5029
|
return {
|
|
4999
|
-
FunctionDeclaration:
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5030
|
+
FunctionDeclaration: enterFunction,
|
|
5031
|
+
"FunctionDeclaration:exit": exitFunction,
|
|
5032
|
+
FunctionExpression: enterFunction,
|
|
5033
|
+
"FunctionExpression:exit": exitFunction,
|
|
5034
|
+
ArrowFunctionExpression: enterFunction,
|
|
5035
|
+
"ArrowFunctionExpression:exit": exitFunction,
|
|
5036
|
+
TSEmptyBodyFunctionExpression: enterFunction,
|
|
5037
|
+
"TSEmptyBodyFunctionExpression:exit": exitFunction,
|
|
5038
|
+
ReturnStatement(node) {
|
|
5039
|
+
const owner = functionStack.at(-1);
|
|
5040
|
+
if (owner === void 0 || owner.returnType !== void 0 || node.argument === null) return;
|
|
5041
|
+
reportExpression(owner, node.argument);
|
|
5042
|
+
},
|
|
5003
5043
|
TSDeclareFunction(node) {
|
|
5004
5044
|
if (node.id === null || node.returnType === void 0 || node.parent.type !== import_utils24.AST_NODE_TYPES.ExportNamedDeclaration && node.parent.type !== import_utils24.AST_NODE_TYPES.ExportDefaultDeclaration && !specifierExports.has(node.id.name)) return;
|
|
5005
5045
|
report(node.returnType.typeAnnotation, node.id.name);
|
|
@@ -9337,8 +9377,98 @@ function unwrapExpression(node) {
|
|
|
9337
9377
|
return node;
|
|
9338
9378
|
}
|
|
9339
9379
|
|
|
9340
|
-
// src/rules/
|
|
9380
|
+
// src/rules/test-phase-label-comment.ts
|
|
9341
9381
|
var import_utils49 = require("@typescript-eslint/utils");
|
|
9382
|
+
var PHASE_WORD = String.raw`arrange|act|assert(?:ion)?s?|given|when|then|exercise|execute|verif(?:y|ication)|cleanup|prepare|sanity(?:\s+check)?`;
|
|
9383
|
+
var PHASE_RE = new RegExp(
|
|
9384
|
+
String.raw`^[-=~*_#.\s]{0,40}(?:${PHASE_WORD})(?:\s*(?:[/&+,|]|->|and)\s*(?:${PHASE_WORD}))*[-=~*_#.\s:;!–—]{0,40}$`,
|
|
9385
|
+
"iu"
|
|
9386
|
+
);
|
|
9387
|
+
var testPhaseLabelCommentDocumentation = {
|
|
9388
|
+
summary: "Tests must not use bare Arrange, Act, Assert, Given, When, or Then phase comments.",
|
|
9389
|
+
rationale: "Phase labels narrate test structure without explaining behavior and often hide unclear names or oversized tests.",
|
|
9390
|
+
remediation: "Delete the label; if the phases remain hard to follow, extract a named helper or split the test.",
|
|
9391
|
+
category: "testing",
|
|
9392
|
+
autofix: "safe",
|
|
9393
|
+
limitations: [
|
|
9394
|
+
"Only standalone line comments in recognized test files are checked.",
|
|
9395
|
+
"Comments inside bracketed expressions or containing words outside the bounded phase grammar are preserved."
|
|
9396
|
+
],
|
|
9397
|
+
examples: [
|
|
9398
|
+
{
|
|
9399
|
+
id: "behavioral-comment",
|
|
9400
|
+
title: "Behavioral consequence is retained",
|
|
9401
|
+
outcome: "no-match",
|
|
9402
|
+
files: [{ path: "widget.test.ts", source: "// Then the retry loop would spin forever.\nexpect(run()).toBe(true);" }],
|
|
9403
|
+
focusPath: "widget.test.ts",
|
|
9404
|
+
expectedCount: 0,
|
|
9405
|
+
public: true
|
|
9406
|
+
},
|
|
9407
|
+
{
|
|
9408
|
+
id: "bare-phase-label",
|
|
9409
|
+
title: "Bare phase label is removed",
|
|
9410
|
+
outcome: "match",
|
|
9411
|
+
files: [{ path: "widget.test.ts", source: "// Arrange\nconst widget = makeWidget();" }],
|
|
9412
|
+
focusPath: "widget.test.ts",
|
|
9413
|
+
expectedCount: 1,
|
|
9414
|
+
fixedFiles: [{ path: "widget.test.ts", source: "const widget = makeWidget();" }],
|
|
9415
|
+
public: true
|
|
9416
|
+
}
|
|
9417
|
+
]
|
|
9418
|
+
};
|
|
9419
|
+
function insideExpression(sourceCode, comment) {
|
|
9420
|
+
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
9421
|
+
if (token === null) return false;
|
|
9422
|
+
let node = sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
9423
|
+
while (node != null && node.type !== import_utils49.AST_NODE_TYPES.Program) {
|
|
9424
|
+
if (node.type === import_utils49.AST_NODE_TYPES.ArrayExpression || node.type === import_utils49.AST_NODE_TYPES.ObjectExpression || node.type === import_utils49.AST_NODE_TYPES.CallExpression || node.type === import_utils49.AST_NODE_TYPES.NewExpression) return node.loc.start.line < comment.loc.start.line;
|
|
9425
|
+
if (/Statement$/u.test(node.type) || /Declaration$/u.test(node.type)) return false;
|
|
9426
|
+
node = node.parent;
|
|
9427
|
+
}
|
|
9428
|
+
return false;
|
|
9429
|
+
}
|
|
9430
|
+
function continuesProseRun(comments, index) {
|
|
9431
|
+
const comment = comments[index];
|
|
9432
|
+
if (comment?.type !== "Line") return false;
|
|
9433
|
+
return [comments[index - 1], comments[index + 1]].some(
|
|
9434
|
+
(neighbor) => neighbor?.type === "Line" && Math.abs(neighbor.loc.start.line - comment.loc.start.line) === 1 && !PHASE_RE.test(neighbor.value.trim())
|
|
9435
|
+
);
|
|
9436
|
+
}
|
|
9437
|
+
var test_phase_label_comment_default = createRule({
|
|
9438
|
+
name: "test-phase-label-comment",
|
|
9439
|
+
documentation: testPhaseLabelCommentDocumentation,
|
|
9440
|
+
meta: {
|
|
9441
|
+
type: "suggestion",
|
|
9442
|
+
fixable: "code",
|
|
9443
|
+
docs: { description: testPhaseLabelCommentDocumentation.summary },
|
|
9444
|
+
schema: [],
|
|
9445
|
+
messages: { removeLabel: "Bare test phase label \u2014 delete it and let the test names and helpers carry the structure." }
|
|
9446
|
+
},
|
|
9447
|
+
defaultOptions: [],
|
|
9448
|
+
create(context) {
|
|
9449
|
+
if (!isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text)) return {};
|
|
9450
|
+
return {
|
|
9451
|
+
Program() {
|
|
9452
|
+
const comments = context.sourceCode.getAllComments();
|
|
9453
|
+
for (const [index, comment] of comments.entries()) {
|
|
9454
|
+
if (comment.type !== "Line" || !PHASE_RE.test(comment.value.trim())) continue;
|
|
9455
|
+
const removal = wholeLineRemovalRange(context.sourceCode.text, comment);
|
|
9456
|
+
if (removal === null || insideExpression(context.sourceCode, comment) || continuesProseRun(comments, index)) {
|
|
9457
|
+
continue;
|
|
9458
|
+
}
|
|
9459
|
+
context.report({
|
|
9460
|
+
node: comment,
|
|
9461
|
+
messageId: "removeLabel",
|
|
9462
|
+
fix: (fixer) => fixer.removeRange(removal.range)
|
|
9463
|
+
});
|
|
9464
|
+
}
|
|
9465
|
+
}
|
|
9466
|
+
};
|
|
9467
|
+
}
|
|
9468
|
+
});
|
|
9469
|
+
|
|
9470
|
+
// src/rules/prefer-constant-time-secret-compare.ts
|
|
9471
|
+
var import_utils50 = require("@typescript-eslint/utils");
|
|
9342
9472
|
var preferConstantTimeSecretCompareDocumentation = {
|
|
9343
9473
|
summary: "Disallow `===`/`!==` on a secret-like value; short-circuiting comparison leaks the secret through timing. Use a constant-time compare.",
|
|
9344
9474
|
rationale: "Ordinary equality stops at the first differing byte, allowing repeated measurements to reveal secret material.",
|
|
@@ -9357,14 +9487,14 @@ var SENTINEL_PREFIX_RE = /^(skip|sentinel|empty|none|missing|unset|placeholder|d
|
|
|
9357
9487
|
var AST_NODE_TYPE_RE = /^(?:TS|JSX)?[A-Z][A-Za-z]*(?:Signature|Keyword|Expression|Declaration|Element|Literal|Identifier)$/;
|
|
9358
9488
|
function isExcludedOperand(node) {
|
|
9359
9489
|
switch (node.type) {
|
|
9360
|
-
case
|
|
9490
|
+
case import_utils50.AST_NODE_TYPES.Literal:
|
|
9361
9491
|
return true;
|
|
9362
|
-
case
|
|
9492
|
+
case import_utils50.AST_NODE_TYPES.TemplateLiteral:
|
|
9363
9493
|
return node.expressions.length === 0;
|
|
9364
|
-
case
|
|
9494
|
+
case import_utils50.AST_NODE_TYPES.Identifier:
|
|
9365
9495
|
return SENTINEL_IDENTIFIERS.has(node.name) || SENTINEL_PREFIX_RE.test(node.name) || isConstantReference(node.name);
|
|
9366
|
-
case
|
|
9367
|
-
return !node.computed && node.property.type ===
|
|
9496
|
+
case import_utils50.AST_NODE_TYPES.MemberExpression:
|
|
9497
|
+
return !node.computed && node.property.type === import_utils50.AST_NODE_TYPES.Identifier && (SENTINEL_PREFIX_RE.test(node.property.name) || isConstantReference(node.property.name));
|
|
9368
9498
|
default:
|
|
9369
9499
|
return false;
|
|
9370
9500
|
}
|
|
@@ -9375,23 +9505,23 @@ function isConstantReference(identifier) {
|
|
|
9375
9505
|
return identifier === identifier.toUpperCase() && /[A-Za-z]/.test(identifier);
|
|
9376
9506
|
}
|
|
9377
9507
|
function operandName(node) {
|
|
9378
|
-
if (node.type ===
|
|
9508
|
+
if (node.type === import_utils50.AST_NODE_TYPES.Identifier) {
|
|
9379
9509
|
return node.name;
|
|
9380
9510
|
}
|
|
9381
|
-
if (node.type ===
|
|
9511
|
+
if (node.type === import_utils50.AST_NODE_TYPES.MemberExpression && !node.computed && node.property.type === import_utils50.AST_NODE_TYPES.Identifier) {
|
|
9382
9512
|
return node.property.name;
|
|
9383
9513
|
}
|
|
9384
9514
|
return null;
|
|
9385
9515
|
}
|
|
9386
9516
|
function isSecretOperand(node) {
|
|
9387
|
-
if (node.type ===
|
|
9517
|
+
if (node.type === import_utils50.AST_NODE_TYPES.TemplateLiteral) {
|
|
9388
9518
|
return node.expressions.some((expression) => isSecretOperand(expression));
|
|
9389
9519
|
}
|
|
9390
9520
|
const name = operandName(node);
|
|
9391
9521
|
return name !== null && isAuthSecretName(name);
|
|
9392
9522
|
}
|
|
9393
9523
|
function secretNameOf(node) {
|
|
9394
|
-
if (node.type ===
|
|
9524
|
+
if (node.type === import_utils50.AST_NODE_TYPES.TemplateLiteral) {
|
|
9395
9525
|
for (const expression of node.expressions) {
|
|
9396
9526
|
const nested = secretNameOf(expression);
|
|
9397
9527
|
if (nested !== null) {
|
|
@@ -9444,8 +9574,8 @@ var prefer_constant_time_secret_compare_default = createRule({
|
|
|
9444
9574
|
});
|
|
9445
9575
|
|
|
9446
9576
|
// src/rules/prefer-discriminated-union.ts
|
|
9447
|
-
var import_utils50 = require("@typescript-eslint/utils");
|
|
9448
9577
|
var import_utils51 = require("@typescript-eslint/utils");
|
|
9578
|
+
var import_utils52 = require("@typescript-eslint/utils");
|
|
9449
9579
|
var preferDiscriminatedUnionDocumentation = {
|
|
9450
9580
|
summary: "Flag flat result objects with a required positive boolean status and optional success/failure payloads.",
|
|
9451
9581
|
rationale: "A boolean status plus optional branch data permits contradictory and incomplete states.",
|
|
@@ -9477,13 +9607,13 @@ var SUCCESS_PAYLOAD_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
|
9477
9607
|
]);
|
|
9478
9608
|
var REQUIRED_STATUS_MEMBER_COUNT = 1;
|
|
9479
9609
|
var FUNCTION_RETURN_OWNER_TYPES = /* @__PURE__ */ new Set([
|
|
9480
|
-
|
|
9481
|
-
|
|
9482
|
-
|
|
9483
|
-
|
|
9484
|
-
|
|
9485
|
-
|
|
9486
|
-
|
|
9610
|
+
import_utils52.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
9611
|
+
import_utils52.AST_NODE_TYPES.FunctionDeclaration,
|
|
9612
|
+
import_utils52.AST_NODE_TYPES.FunctionExpression,
|
|
9613
|
+
import_utils52.AST_NODE_TYPES.TSDeclareFunction,
|
|
9614
|
+
import_utils52.AST_NODE_TYPES.TSEmptyBodyFunctionExpression,
|
|
9615
|
+
import_utils52.AST_NODE_TYPES.TSFunctionType,
|
|
9616
|
+
import_utils52.AST_NODE_TYPES.TSMethodSignature
|
|
9487
9617
|
]);
|
|
9488
9618
|
function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
9489
9619
|
let statusMemberCount = 0;
|
|
@@ -9491,7 +9621,7 @@ function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
|
9491
9621
|
let hasSuccessPayload = false;
|
|
9492
9622
|
let hasUnrecognizedMember = false;
|
|
9493
9623
|
for (const member of typeLiteral.members) {
|
|
9494
|
-
if (member.type !==
|
|
9624
|
+
if (member.type !== import_utils52.AST_NODE_TYPES.TSPropertySignature) {
|
|
9495
9625
|
hasUnrecognizedMember = true;
|
|
9496
9626
|
continue;
|
|
9497
9627
|
}
|
|
@@ -9515,26 +9645,26 @@ function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
|
9515
9645
|
return statusMemberCount === REQUIRED_STATUS_MEMBER_COUNT && hasFailurePayload && (hasSuccessPayload || !hasUnrecognizedMember);
|
|
9516
9646
|
}
|
|
9517
9647
|
function getMemberName(member) {
|
|
9518
|
-
if (member.type !==
|
|
9648
|
+
if (member.type !== import_utils52.AST_NODE_TYPES.TSPropertySignature) {
|
|
9519
9649
|
return null;
|
|
9520
9650
|
}
|
|
9521
9651
|
const { key } = member;
|
|
9522
|
-
if (key.type ===
|
|
9652
|
+
if (key.type === import_utils52.AST_NODE_TYPES.Identifier) {
|
|
9523
9653
|
return key.name;
|
|
9524
9654
|
}
|
|
9525
|
-
if (key.type ===
|
|
9655
|
+
if (key.type === import_utils52.AST_NODE_TYPES.Literal && typeof key.value === "string") {
|
|
9526
9656
|
return key.value;
|
|
9527
9657
|
}
|
|
9528
9658
|
return null;
|
|
9529
9659
|
}
|
|
9530
9660
|
function isBooleanTyped(member) {
|
|
9531
|
-
return member.typeAnnotation?.typeAnnotation.type ===
|
|
9661
|
+
return member.typeAnnotation?.typeAnnotation.type === import_utils52.AST_NODE_TYPES.TSBooleanKeyword;
|
|
9532
9662
|
}
|
|
9533
9663
|
function inlineReturnTypeLiteral(node) {
|
|
9534
9664
|
let annotation = null;
|
|
9535
|
-
if (node.parent.type ===
|
|
9665
|
+
if (node.parent.type === import_utils52.AST_NODE_TYPES.TSTypeAnnotation) {
|
|
9536
9666
|
annotation = node.parent;
|
|
9537
|
-
} else if (node.parent.type ===
|
|
9667
|
+
} else if (node.parent.type === import_utils52.AST_NODE_TYPES.TSTypeParameterInstantiation && node.parent.params.length === 1 && node.parent.params[0] === node && node.parent.parent.type === import_utils52.AST_NODE_TYPES.TSTypeReference && node.parent.parent.typeName.type === import_utils52.AST_NODE_TYPES.Identifier && node.parent.parent.typeName.name === "Promise" && node.parent.parent.parent.type === import_utils52.AST_NODE_TYPES.TSTypeAnnotation) {
|
|
9538
9668
|
annotation = node.parent.parent.parent;
|
|
9539
9669
|
}
|
|
9540
9670
|
if (annotation === null) return null;
|
|
@@ -9574,7 +9704,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
9574
9704
|
}
|
|
9575
9705
|
const synthetic = {
|
|
9576
9706
|
...node.body,
|
|
9577
|
-
type:
|
|
9707
|
+
type: import_utils52.AST_NODE_TYPES.TSTypeLiteral,
|
|
9578
9708
|
members: node.body.body
|
|
9579
9709
|
};
|
|
9580
9710
|
checkTypeLiteral(synthetic, node);
|
|
@@ -9591,7 +9721,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
9591
9721
|
});
|
|
9592
9722
|
|
|
9593
9723
|
// src/rules/prefer-input-group-search.ts
|
|
9594
|
-
var
|
|
9724
|
+
var import_utils53 = require("@typescript-eslint/utils");
|
|
9595
9725
|
var preferInputGroupSearchDocumentation = {
|
|
9596
9726
|
summary: "Require search icons and shared Input controls in the same visual wrapper to use InputGroup.",
|
|
9597
9727
|
rationale: "The shared compound control provides consistent spacing, focus behavior, and accessible composition.",
|
|
@@ -9612,15 +9742,15 @@ var MAX_JSX_DISTANCE = 2;
|
|
|
9612
9742
|
var SEARCH_EXPORTS = ["Search", "SearchIcon", "LucideSearch"];
|
|
9613
9743
|
function localNamedImports(node, importedName4) {
|
|
9614
9744
|
return node.specifiers.filter(
|
|
9615
|
-
(specifier) => specifier.type ===
|
|
9745
|
+
(specifier) => specifier.type === import_utils53.AST_NODE_TYPES.ImportSpecifier && (specifier.imported.type === import_utils53.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value) === importedName4
|
|
9616
9746
|
).map((specifier) => specifier.local.name);
|
|
9617
9747
|
}
|
|
9618
9748
|
function elementName(node) {
|
|
9619
|
-
return node.name.type ===
|
|
9749
|
+
return node.name.type === import_utils53.AST_NODE_TYPES.JSXIdentifier ? node.name.name : null;
|
|
9620
9750
|
}
|
|
9621
9751
|
function jsxAncestors(occurrence) {
|
|
9622
9752
|
return occurrence.ancestors.filter(
|
|
9623
|
-
(ancestor) => ancestor.type ===
|
|
9753
|
+
(ancestor) => ancestor.type === import_utils53.AST_NODE_TYPES.JSXElement
|
|
9624
9754
|
);
|
|
9625
9755
|
}
|
|
9626
9756
|
function isWithinInputGroup(occurrence, inputGroupNames) {
|
|
@@ -9733,7 +9863,7 @@ var prefer_input_group_search_default = createRule({
|
|
|
9733
9863
|
});
|
|
9734
9864
|
|
|
9735
9865
|
// src/rules/prefer-immutable-module-constant.ts
|
|
9736
|
-
var
|
|
9866
|
+
var import_utils54 = require("@typescript-eslint/utils");
|
|
9737
9867
|
var preferImmutableModuleConstantDocumentation = {
|
|
9738
9868
|
summary: "Require module-level constant collections to expose readonly state.",
|
|
9739
9869
|
rationale: "A const binding prevents reassignment but does not stop callers from mutating its array, object, Set, or Map contents.",
|
|
@@ -9781,59 +9911,59 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
|
9781
9911
|
"unshift"
|
|
9782
9912
|
]);
|
|
9783
9913
|
function isAsConst(node, sourceText) {
|
|
9784
|
-
if (node.type ===
|
|
9914
|
+
if (node.type === import_utils54.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils54.AST_NODE_TYPES.TSNonNullExpression) {
|
|
9785
9915
|
return isAsConst(node.expression, sourceText);
|
|
9786
9916
|
}
|
|
9787
|
-
if (node.type !==
|
|
9917
|
+
if (node.type !== import_utils54.AST_NODE_TYPES.TSAsExpression) return false;
|
|
9788
9918
|
return sourceText(node.typeAnnotation).trim() === "const";
|
|
9789
9919
|
}
|
|
9790
9920
|
function unwrapExpression2(node) {
|
|
9791
|
-
if (node.type ===
|
|
9921
|
+
if (node.type === import_utils54.AST_NODE_TYPES.TSAsExpression || node.type === import_utils54.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils54.AST_NODE_TYPES.TSNonNullExpression) {
|
|
9792
9922
|
return unwrapExpression2(node.expression);
|
|
9793
9923
|
}
|
|
9794
9924
|
return node;
|
|
9795
9925
|
}
|
|
9796
9926
|
function isObjectFreeze(node, isUnshadowedGlobal) {
|
|
9797
9927
|
const inner = unwrapExpression2(node);
|
|
9798
|
-
if (inner.type ===
|
|
9928
|
+
if (inner.type === import_utils54.AST_NODE_TYPES.CallExpression && inner.callee.type === import_utils54.AST_NODE_TYPES.MemberExpression && !inner.callee.computed && inner.callee.object.type === import_utils54.AST_NODE_TYPES.Identifier && inner.callee.object.name === "Object" && isUnshadowedGlobal(inner.callee.object) && inner.callee.property.type === import_utils54.AST_NODE_TYPES.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1) {
|
|
9799
9929
|
const argument = inner.arguments[0];
|
|
9800
|
-
return argument !== void 0 && argument.type !==
|
|
9930
|
+
return argument !== void 0 && argument.type !== import_utils54.AST_NODE_TYPES.SpreadElement && collectionKind(argument, isUnshadowedGlobal) === "literal";
|
|
9801
9931
|
}
|
|
9802
9932
|
return false;
|
|
9803
9933
|
}
|
|
9804
9934
|
function collectionKind(node, isUnshadowedGlobal) {
|
|
9805
9935
|
const inner = unwrapExpression2(node);
|
|
9806
|
-
if (inner.type ===
|
|
9936
|
+
if (inner.type === import_utils54.AST_NODE_TYPES.CallExpression && inner.callee.type === import_utils54.AST_NODE_TYPES.MemberExpression && !inner.callee.computed && inner.callee.object.type === import_utils54.AST_NODE_TYPES.Identifier && inner.callee.object.name === "Object" && isUnshadowedGlobal(inner.callee.object) && inner.callee.property.type === import_utils54.AST_NODE_TYPES.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== import_utils54.AST_NODE_TYPES.SpreadElement) {
|
|
9807
9937
|
return collectionKind(inner.arguments[0], isUnshadowedGlobal);
|
|
9808
9938
|
}
|
|
9809
|
-
if (inner.type ===
|
|
9939
|
+
if (inner.type === import_utils54.AST_NODE_TYPES.ArrayExpression || inner.type === import_utils54.AST_NODE_TYPES.ObjectExpression) {
|
|
9810
9940
|
return "literal";
|
|
9811
9941
|
}
|
|
9812
|
-
if (inner.type ===
|
|
9942
|
+
if (inner.type === import_utils54.AST_NODE_TYPES.NewExpression && inner.callee.type === import_utils54.AST_NODE_TYPES.Identifier && (inner.callee.name === "Set" || inner.callee.name === "Map") && isUnshadowedGlobal(inner.callee)) {
|
|
9813
9943
|
return inner.callee.name;
|
|
9814
9944
|
}
|
|
9815
9945
|
return null;
|
|
9816
9946
|
}
|
|
9817
9947
|
function declaredReadonlyType(node, kind, aliases) {
|
|
9818
|
-
const annotation = node.id.type ===
|
|
9948
|
+
const annotation = node.id.type === import_utils54.AST_NODE_TYPES.Identifier ? node.id.typeAnnotation : void 0;
|
|
9819
9949
|
if (annotation !== void 0 && isReadonlyTypeResolved(annotation.typeAnnotation, kind, aliases)) {
|
|
9820
9950
|
return true;
|
|
9821
9951
|
}
|
|
9822
|
-
return node.init?.type ===
|
|
9952
|
+
return node.init?.type === import_utils54.AST_NODE_TYPES.TSAsExpression && isReadonlyTypeResolved(node.init.typeAnnotation, kind, aliases);
|
|
9823
9953
|
}
|
|
9824
9954
|
function isReadonlyTypeResolved(node, kind, aliases, seen = /* @__PURE__ */ new Set()) {
|
|
9825
9955
|
if (isReadonlyType(node, kind)) return true;
|
|
9826
|
-
if (node.type !==
|
|
9956
|
+
if (node.type !== import_utils54.AST_NODE_TYPES.TSTypeReference || node.typeName.type !== import_utils54.AST_NODE_TYPES.Identifier) return false;
|
|
9827
9957
|
const name = node.typeName.name;
|
|
9828
9958
|
const target = aliases.get(name);
|
|
9829
9959
|
if (target === void 0 || seen.has(name)) return false;
|
|
9830
9960
|
return isReadonlyTypeResolved(target, kind, aliases, /* @__PURE__ */ new Set([...seen, name]));
|
|
9831
9961
|
}
|
|
9832
9962
|
function isReadonlyType(node, kind) {
|
|
9833
|
-
if (node.type ===
|
|
9963
|
+
if (node.type === import_utils54.AST_NODE_TYPES.TSTypeOperator && node.operator === "readonly") {
|
|
9834
9964
|
return true;
|
|
9835
9965
|
}
|
|
9836
|
-
if (node.type !==
|
|
9966
|
+
if (node.type !== import_utils54.AST_NODE_TYPES.TSTypeReference || node.typeName.type !== import_utils54.AST_NODE_TYPES.Identifier) {
|
|
9837
9967
|
return false;
|
|
9838
9968
|
}
|
|
9839
9969
|
if (node.typeName.name === "Readonly") {
|
|
@@ -9842,31 +9972,31 @@ function isReadonlyType(node, kind) {
|
|
|
9842
9972
|
return kind === "literal" ? node.typeName.name === "ReadonlyArray" : node.typeName.name === `Readonly${kind}`;
|
|
9843
9973
|
}
|
|
9844
9974
|
function hasUnknownExplicitType(node, aliases) {
|
|
9845
|
-
const annotation = node.id.type ===
|
|
9975
|
+
const annotation = node.id.type === import_utils54.AST_NODE_TYPES.Identifier ? node.id.typeAnnotation?.typeAnnotation : void 0;
|
|
9846
9976
|
if (annotation === void 0) return false;
|
|
9847
|
-
if (annotation.type ===
|
|
9848
|
-
if (annotation.type !==
|
|
9977
|
+
if (annotation.type === import_utils54.AST_NODE_TYPES.TSArrayType || annotation.type === import_utils54.AST_NODE_TYPES.TSTypeOperator) return false;
|
|
9978
|
+
if (annotation.type !== import_utils54.AST_NODE_TYPES.TSTypeReference || annotation.typeName.type !== import_utils54.AST_NODE_TYPES.Identifier) return true;
|
|
9849
9979
|
return !aliases.has(annotation.typeName.name) && !["Array", "Map", "Readonly", "ReadonlyArray", "ReadonlyMap", "ReadonlySet", "Set"].includes(annotation.typeName.name);
|
|
9850
9980
|
}
|
|
9851
9981
|
function referenceMutates(identifier, isUnshadowedGlobal) {
|
|
9852
9982
|
let member = identifier.parent;
|
|
9853
|
-
if (member?.type !==
|
|
9854
|
-
return member?.type ===
|
|
9983
|
+
if (member?.type !== import_utils54.AST_NODE_TYPES.MemberExpression || member.object !== identifier) {
|
|
9984
|
+
return member?.type === import_utils54.AST_NODE_TYPES.CallExpression && member.arguments[0] === identifier && member.callee.type === import_utils54.AST_NODE_TYPES.MemberExpression && !member.callee.computed && member.callee.object.type === import_utils54.AST_NODE_TYPES.Identifier && member.callee.object.name === "Object" && isUnshadowedGlobal(member.callee.object) && member.callee.property.type === import_utils54.AST_NODE_TYPES.Identifier && member.callee.property.name === "assign";
|
|
9855
9985
|
}
|
|
9856
|
-
while (member.parent.type ===
|
|
9986
|
+
while (member.parent.type === import_utils54.AST_NODE_TYPES.MemberExpression && member.parent.object === member) {
|
|
9857
9987
|
member = member.parent;
|
|
9858
9988
|
}
|
|
9859
9989
|
const parent = member.parent;
|
|
9860
|
-
if (parent?.type ===
|
|
9990
|
+
if (parent?.type === import_utils54.AST_NODE_TYPES.AssignmentExpression && parent.left === member) {
|
|
9861
9991
|
return true;
|
|
9862
9992
|
}
|
|
9863
|
-
if (parent?.type ===
|
|
9993
|
+
if (parent?.type === import_utils54.AST_NODE_TYPES.UpdateExpression && parent.argument === member) {
|
|
9864
9994
|
return true;
|
|
9865
9995
|
}
|
|
9866
|
-
if (parent?.type ===
|
|
9996
|
+
if (parent?.type === import_utils54.AST_NODE_TYPES.UnaryExpression && parent.operator === "delete" && parent.argument === member) {
|
|
9867
9997
|
return true;
|
|
9868
9998
|
}
|
|
9869
|
-
return parent?.type ===
|
|
9999
|
+
return parent?.type === import_utils54.AST_NODE_TYPES.CallExpression && parent.callee === member && (member.property.type === import_utils54.AST_NODE_TYPES.Identifier && !member.computed || member.property.type === import_utils54.AST_NODE_TYPES.Literal && typeof member.property.value === "string") && MUTATING_METHODS.has(member.property.type === import_utils54.AST_NODE_TYPES.Identifier ? member.property.name : member.property.value);
|
|
9870
10000
|
}
|
|
9871
10001
|
var prefer_immutable_module_constant_default = createRule({
|
|
9872
10002
|
name: "prefer-immutable-module-constant",
|
|
@@ -9886,7 +10016,7 @@ var prefer_immutable_module_constant_default = createRule({
|
|
|
9886
10016
|
create(context) {
|
|
9887
10017
|
const sourceCode = context.sourceCode;
|
|
9888
10018
|
const isUnshadowedGlobal = (identifier) => {
|
|
9889
|
-
const variable =
|
|
10019
|
+
const variable = import_utils54.ASTUtils.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
9890
10020
|
return variable === null || variable.defs.length === 0;
|
|
9891
10021
|
};
|
|
9892
10022
|
if (JAVASCRIPT_FILE_RE.test(context.filename) || isTestFile(context.filename) || isGeneratedFile(context.filename, sourceCode.getText())) {
|
|
@@ -9903,10 +10033,10 @@ var prefer_immutable_module_constant_default = createRule({
|
|
|
9903
10033
|
seen.add(variable);
|
|
9904
10034
|
for (const reference of variable.references) {
|
|
9905
10035
|
const identifier = reference.identifier;
|
|
9906
|
-
if (identifier.type !==
|
|
10036
|
+
if (identifier.type !== import_utils54.AST_NODE_TYPES.Identifier) continue;
|
|
9907
10037
|
if (referenceMutates(identifier, isUnshadowedGlobal)) return true;
|
|
9908
10038
|
const declarator = identifier.parent;
|
|
9909
|
-
if (declarator.type !==
|
|
10039
|
+
if (declarator.type !== import_utils54.AST_NODE_TYPES.VariableDeclarator || declarator.init !== identifier || declarator.id.type !== import_utils54.AST_NODE_TYPES.Identifier || declarator.parent.type !== import_utils54.AST_NODE_TYPES.VariableDeclaration || declarator.parent.kind !== "const") {
|
|
9910
10040
|
continue;
|
|
9911
10041
|
}
|
|
9912
10042
|
const alias = sourceCode.getDeclaredVariables(declarator)[0];
|
|
@@ -9918,32 +10048,32 @@ var prefer_immutable_module_constant_default = createRule({
|
|
|
9918
10048
|
return {
|
|
9919
10049
|
Program(node) {
|
|
9920
10050
|
for (const statement of node.body) {
|
|
9921
|
-
const declaration = statement.type ===
|
|
9922
|
-
if (declaration?.type ===
|
|
10051
|
+
const declaration = statement.type === import_utils54.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
10052
|
+
if (declaration?.type === import_utils54.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
9923
10053
|
typeAliases2.set(declaration.id.name, declaration.typeAnnotation);
|
|
9924
10054
|
}
|
|
9925
|
-
if (statement.type ===
|
|
10055
|
+
if (statement.type === import_utils54.AST_NODE_TYPES.ExportNamedDeclaration) {
|
|
9926
10056
|
if (statement.source !== null || statement.exportKind === "type") continue;
|
|
9927
10057
|
for (const specifier of statement.specifiers) {
|
|
9928
|
-
if (specifier.type ===
|
|
10058
|
+
if (specifier.type === import_utils54.AST_NODE_TYPES.ExportSpecifier && specifier.exportKind !== "type" && specifier.local.type === import_utils54.AST_NODE_TYPES.Identifier) {
|
|
9929
10059
|
exportedNames2.add(specifier.local.name);
|
|
9930
10060
|
}
|
|
9931
10061
|
}
|
|
9932
|
-
} else if (statement.type ===
|
|
10062
|
+
} else if (statement.type === import_utils54.AST_NODE_TYPES.ExportDefaultDeclaration && unwrapTransparentExport(statement.declaration)?.type === import_utils54.AST_NODE_TYPES.Identifier) {
|
|
9933
10063
|
exportedNames2.add(unwrapTransparentExport(statement.declaration).name);
|
|
9934
10064
|
}
|
|
9935
10065
|
}
|
|
9936
10066
|
},
|
|
9937
10067
|
VariableDeclarator(node) {
|
|
9938
10068
|
const declaration = node.parent;
|
|
9939
|
-
if (declaration.type !==
|
|
10069
|
+
if (declaration.type !== import_utils54.AST_NODE_TYPES.VariableDeclaration || declaration.kind !== "const" || node.id.type !== import_utils54.AST_NODE_TYPES.Identifier || node.init === null) {
|
|
9940
10070
|
return;
|
|
9941
10071
|
}
|
|
9942
10072
|
const container = declaration.parent;
|
|
9943
|
-
if (container.type !==
|
|
10073
|
+
if (container.type !== import_utils54.AST_NODE_TYPES.Program && !(container.type === import_utils54.AST_NODE_TYPES.ExportNamedDeclaration && container.parent.type === import_utils54.AST_NODE_TYPES.Program)) {
|
|
9944
10074
|
return;
|
|
9945
10075
|
}
|
|
9946
|
-
const directlyExported = container.type ===
|
|
10076
|
+
const directlyExported = container.type === import_utils54.AST_NODE_TYPES.ExportNamedDeclaration;
|
|
9947
10077
|
if (!CONSTANT_NAME.test(node.id.name) && !directlyExported && !exportedNames2.has(node.id.name)) {
|
|
9948
10078
|
return;
|
|
9949
10079
|
}
|
|
@@ -9968,14 +10098,14 @@ var prefer_immutable_module_constant_default = createRule({
|
|
|
9968
10098
|
}
|
|
9969
10099
|
});
|
|
9970
10100
|
function unwrapTransparentExport(node) {
|
|
9971
|
-
if (node.type ===
|
|
10101
|
+
if (node.type === import_utils54.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils54.AST_NODE_TYPES.TSNonNullExpression) {
|
|
9972
10102
|
return unwrapTransparentExport(node.expression);
|
|
9973
10103
|
}
|
|
9974
10104
|
return node;
|
|
9975
10105
|
}
|
|
9976
10106
|
|
|
9977
10107
|
// src/rules/prefer-shadcn-primitives.ts
|
|
9978
|
-
var
|
|
10108
|
+
var import_utils55 = require("@typescript-eslint/utils");
|
|
9979
10109
|
var preferShadcnPrimitivesDocumentation = {
|
|
9980
10110
|
summary: "Require visible raw JSX controls to use the corresponding shared shadcn primitive.",
|
|
9981
10111
|
rationale: "Shared primitives centralize interaction, accessibility, and visual behavior across the product.",
|
|
@@ -10020,16 +10150,16 @@ var AMBIGUOUS_INPUT_TYPES = /* @__PURE__ */ new Set([
|
|
|
10020
10150
|
"submit"
|
|
10021
10151
|
]);
|
|
10022
10152
|
function rawElementName(node) {
|
|
10023
|
-
if (node.name.type !==
|
|
10153
|
+
if (node.name.type !== import_utils55.AST_NODE_TYPES.JSXIdentifier) return null;
|
|
10024
10154
|
const name = node.name.name;
|
|
10025
10155
|
return Object.hasOwn(SHADCN_PRIMITIVES, name) ? name : null;
|
|
10026
10156
|
}
|
|
10027
10157
|
function effectiveAttribute(node, attributeName) {
|
|
10028
10158
|
for (const attribute of node.attributes.toReversed()) {
|
|
10029
|
-
if (attribute.type ===
|
|
10159
|
+
if (attribute.type === import_utils55.AST_NODE_TYPES.JSXSpreadAttribute) {
|
|
10030
10160
|
return { kind: "unknown" };
|
|
10031
10161
|
}
|
|
10032
|
-
if (attribute.name.type !==
|
|
10162
|
+
if (attribute.name.type !== import_utils55.AST_NODE_TYPES.JSXIdentifier || attribute.name.name !== attributeName) {
|
|
10033
10163
|
continue;
|
|
10034
10164
|
}
|
|
10035
10165
|
const value = staticString(attribute.value);
|
|
@@ -10038,17 +10168,17 @@ function effectiveAttribute(node, attributeName) {
|
|
|
10038
10168
|
return { kind: "missing" };
|
|
10039
10169
|
}
|
|
10040
10170
|
function staticString(value) {
|
|
10041
|
-
if (value?.type ===
|
|
10171
|
+
if (value?.type === import_utils55.AST_NODE_TYPES.Literal) {
|
|
10042
10172
|
return typeof value.value === "string" ? value.value : null;
|
|
10043
10173
|
}
|
|
10044
|
-
if (value?.type !==
|
|
10174
|
+
if (value?.type !== import_utils55.AST_NODE_TYPES.JSXExpressionContainer) return null;
|
|
10045
10175
|
return staticExpressionString(value.expression);
|
|
10046
10176
|
}
|
|
10047
10177
|
function staticExpressionString(expression) {
|
|
10048
|
-
if (expression.type ===
|
|
10178
|
+
if (expression.type === import_utils55.AST_NODE_TYPES.Literal) {
|
|
10049
10179
|
return typeof expression.value === "string" ? expression.value : null;
|
|
10050
10180
|
}
|
|
10051
|
-
if (expression.type ===
|
|
10181
|
+
if (expression.type === import_utils55.AST_NODE_TYPES.TemplateLiteral) {
|
|
10052
10182
|
let value = expression.quasis[0]?.value.cooked ?? "";
|
|
10053
10183
|
for (const [index, substitution] of expression.expressions.entries()) {
|
|
10054
10184
|
const staticSubstitution = staticExpressionString(substitution);
|
|
@@ -10058,13 +10188,13 @@ function staticExpressionString(expression) {
|
|
|
10058
10188
|
}
|
|
10059
10189
|
return value;
|
|
10060
10190
|
}
|
|
10061
|
-
if (expression.type ===
|
|
10191
|
+
if (expression.type === import_utils55.AST_NODE_TYPES.TSAsExpression || expression.type === import_utils55.AST_NODE_TYPES.TSNonNullExpression || expression.type === import_utils55.AST_NODE_TYPES.TSSatisfiesExpression || expression.type === import_utils55.AST_NODE_TYPES.TSTypeAssertion) {
|
|
10062
10192
|
return staticExpressionString(expression.expression);
|
|
10063
10193
|
}
|
|
10064
10194
|
return null;
|
|
10065
10195
|
}
|
|
10066
10196
|
function isLabelableElement(node) {
|
|
10067
|
-
if (node.openingElement.name.type !==
|
|
10197
|
+
if (node.openingElement.name.type !== import_utils55.AST_NODE_TYPES.JSXIdentifier) {
|
|
10068
10198
|
return false;
|
|
10069
10199
|
}
|
|
10070
10200
|
const name = node.openingElement.name.name;
|
|
@@ -10076,10 +10206,10 @@ function isLabelableElement(node) {
|
|
|
10076
10206
|
}
|
|
10077
10207
|
function containsLabelableElement(node) {
|
|
10078
10208
|
return node.children.some((child) => {
|
|
10079
|
-
if (child.type ===
|
|
10209
|
+
if (child.type === import_utils55.AST_NODE_TYPES.JSXElement) {
|
|
10080
10210
|
return isLabelableElement(child) || containsLabelableElement(child);
|
|
10081
10211
|
}
|
|
10082
|
-
if (child.type ===
|
|
10212
|
+
if (child.type === import_utils55.AST_NODE_TYPES.JSXFragment) {
|
|
10083
10213
|
return containsLabelableElement(child);
|
|
10084
10214
|
}
|
|
10085
10215
|
return false;
|
|
@@ -10088,7 +10218,7 @@ function containsLabelableElement(node) {
|
|
|
10088
10218
|
function isStaticallyAssociatedLabel(node) {
|
|
10089
10219
|
const htmlFor = effectiveAttribute(node, "htmlFor");
|
|
10090
10220
|
if (htmlFor.kind === "known" && htmlFor.value.trim().length > 0) return true;
|
|
10091
|
-
return node.parent.type ===
|
|
10221
|
+
return node.parent.type === import_utils55.AST_NODE_TYPES.JSXElement && containsLabelableElement(node.parent);
|
|
10092
10222
|
}
|
|
10093
10223
|
function replacementFor(node, element) {
|
|
10094
10224
|
if (element !== "input") return SHADCN_PRIMITIVES[element];
|
|
@@ -10159,7 +10289,7 @@ var prefer_shadcn_primitives_default = createRule({
|
|
|
10159
10289
|
});
|
|
10160
10290
|
|
|
10161
10291
|
// src/rules/prefer-module-level-constant.ts
|
|
10162
|
-
var
|
|
10292
|
+
var import_utils56 = require("@typescript-eslint/utils");
|
|
10163
10293
|
var preferModuleLevelConstantDocumentation = {
|
|
10164
10294
|
summary: "Hoist literal-only constant collections and regexes out of function bodies to module scope so they are allocated once.",
|
|
10165
10295
|
rationale: "Recreating immutable lookup data on every call wastes allocations and obscures its constant nature.",
|
|
@@ -10199,9 +10329,9 @@ var MUTATING_METHODS2 = /* @__PURE__ */ new Set([
|
|
|
10199
10329
|
"assign"
|
|
10200
10330
|
]);
|
|
10201
10331
|
var FUNCTION_TYPES7 = /* @__PURE__ */ new Set([
|
|
10202
|
-
|
|
10203
|
-
|
|
10204
|
-
|
|
10332
|
+
import_utils56.AST_NODE_TYPES.FunctionDeclaration,
|
|
10333
|
+
import_utils56.AST_NODE_TYPES.FunctionExpression,
|
|
10334
|
+
import_utils56.AST_NODE_TYPES.ArrowFunctionExpression
|
|
10205
10335
|
]);
|
|
10206
10336
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
10207
10337
|
function isIgnoredFile2(filename, sourceText) {
|
|
@@ -10214,14 +10344,14 @@ function isLocalFixtureFile(filename) {
|
|
|
10214
10344
|
return isTestFile(filename) || isStoryFile(filename);
|
|
10215
10345
|
}
|
|
10216
10346
|
function unwrap3(node) {
|
|
10217
|
-
if (node.type ===
|
|
10347
|
+
if (node.type === import_utils56.AST_NODE_TYPES.TSAsExpression || node.type === import_utils56.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils56.AST_NODE_TYPES.TSNonNullExpression) {
|
|
10218
10348
|
return unwrap3(node.expression);
|
|
10219
10349
|
}
|
|
10220
10350
|
return node;
|
|
10221
10351
|
}
|
|
10222
10352
|
var HAS_STATEFUL_FLAG_RE = /[gy]/;
|
|
10223
10353
|
function isRegexLiteral(node) {
|
|
10224
|
-
return node.type ===
|
|
10354
|
+
return node.type === import_utils56.AST_NODE_TYPES.Literal && "regex" in node && node.regex !== void 0;
|
|
10225
10355
|
}
|
|
10226
10356
|
function isLiteralOnly(node, depth) {
|
|
10227
10357
|
if (depth > MAX_LITERAL_DEPTH) {
|
|
@@ -10229,29 +10359,29 @@ function isLiteralOnly(node, depth) {
|
|
|
10229
10359
|
}
|
|
10230
10360
|
const inner = unwrap3(node);
|
|
10231
10361
|
switch (inner.type) {
|
|
10232
|
-
case
|
|
10362
|
+
case import_utils56.AST_NODE_TYPES.Literal: {
|
|
10233
10363
|
return !(isRegexLiteral(inner) && HAS_STATEFUL_FLAG_RE.test(inner.regex.flags));
|
|
10234
10364
|
}
|
|
10235
|
-
case
|
|
10365
|
+
case import_utils56.AST_NODE_TYPES.TemplateLiteral: {
|
|
10236
10366
|
return inner.expressions.length === 0;
|
|
10237
10367
|
}
|
|
10238
|
-
case
|
|
10239
|
-
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type ===
|
|
10368
|
+
case import_utils56.AST_NODE_TYPES.UnaryExpression: {
|
|
10369
|
+
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type === import_utils56.AST_NODE_TYPES.Literal && typeof inner.argument.value === "number";
|
|
10240
10370
|
}
|
|
10241
|
-
case
|
|
10371
|
+
case import_utils56.AST_NODE_TYPES.ArrayExpression: {
|
|
10242
10372
|
return inner.elements.every(
|
|
10243
|
-
(el) => el !== null && el.type !==
|
|
10373
|
+
(el) => el !== null && el.type !== import_utils56.AST_NODE_TYPES.SpreadElement && isLiteralOnly(el, depth + 1)
|
|
10244
10374
|
);
|
|
10245
10375
|
}
|
|
10246
|
-
case
|
|
10376
|
+
case import_utils56.AST_NODE_TYPES.ObjectExpression: {
|
|
10247
10377
|
return inner.properties.every((prop) => {
|
|
10248
|
-
if (prop.type !==
|
|
10378
|
+
if (prop.type !== import_utils56.AST_NODE_TYPES.Property) {
|
|
10249
10379
|
return false;
|
|
10250
10380
|
}
|
|
10251
10381
|
if (prop.shorthand || prop.method || prop.kind !== "init") {
|
|
10252
10382
|
return false;
|
|
10253
10383
|
}
|
|
10254
|
-
if (prop.computed && prop.key.type !==
|
|
10384
|
+
if (prop.computed && prop.key.type !== import_utils56.AST_NODE_TYPES.Literal) {
|
|
10255
10385
|
return false;
|
|
10256
10386
|
}
|
|
10257
10387
|
return isLiteralOnly(prop.value, depth + 1);
|
|
@@ -10273,19 +10403,19 @@ function classify(init, checkRegex) {
|
|
|
10273
10403
|
}
|
|
10274
10404
|
return { kind: "regex", size: 1 };
|
|
10275
10405
|
}
|
|
10276
|
-
if (node.type ===
|
|
10406
|
+
if (node.type === import_utils56.AST_NODE_TYPES.ArrayExpression) {
|
|
10277
10407
|
return isLiteralOnly(node, 0) ? { kind: "array", size: node.elements.length } : null;
|
|
10278
10408
|
}
|
|
10279
|
-
if (node.type ===
|
|
10409
|
+
if (node.type === import_utils56.AST_NODE_TYPES.ObjectExpression) {
|
|
10280
10410
|
return isLiteralOnly(node, 0) ? { kind: "object", size: node.properties.length } : null;
|
|
10281
10411
|
}
|
|
10282
|
-
if (node.type ===
|
|
10412
|
+
if (node.type === import_utils56.AST_NODE_TYPES.NewExpression && node.callee.type === import_utils56.AST_NODE_TYPES.Identifier && COLLECTION_CONSTRUCTORS.has(node.callee.name)) {
|
|
10283
10413
|
const arg = node.arguments[0];
|
|
10284
|
-
if (node.arguments.length !== 1 || arg === void 0 || arg.type ===
|
|
10414
|
+
if (node.arguments.length !== 1 || arg === void 0 || arg.type === import_utils56.AST_NODE_TYPES.SpreadElement) {
|
|
10285
10415
|
return null;
|
|
10286
10416
|
}
|
|
10287
10417
|
const entries = unwrap3(arg);
|
|
10288
|
-
if (entries.type !==
|
|
10418
|
+
if (entries.type !== import_utils56.AST_NODE_TYPES.ArrayExpression) {
|
|
10289
10419
|
return null;
|
|
10290
10420
|
}
|
|
10291
10421
|
return isLiteralOnly(entries, 0) ? { kind: node.callee.name === "Set" ? "Set" : "Map", size: entries.elements.length } : null;
|
|
@@ -10294,7 +10424,7 @@ function classify(init, checkRegex) {
|
|
|
10294
10424
|
}
|
|
10295
10425
|
function unwrapObjectFreeze(node) {
|
|
10296
10426
|
const inner = unwrap3(node);
|
|
10297
|
-
if (inner.type ===
|
|
10427
|
+
if (inner.type === import_utils56.AST_NODE_TYPES.CallExpression && inner.callee.type === import_utils56.AST_NODE_TYPES.MemberExpression && !inner.callee.computed && inner.callee.object.type === import_utils56.AST_NODE_TYPES.Identifier && inner.callee.object.name === "Object" && inner.callee.property.type === import_utils56.AST_NODE_TYPES.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== import_utils56.AST_NODE_TYPES.SpreadElement) {
|
|
10298
10428
|
return unwrap3(inner.arguments[0]);
|
|
10299
10429
|
}
|
|
10300
10430
|
return inner;
|
|
@@ -10321,48 +10451,48 @@ var NON_RETAINING_BUILTINS = /* @__PURE__ */ new Map(
|
|
|
10321
10451
|
);
|
|
10322
10452
|
function isSafeRead(identifier) {
|
|
10323
10453
|
const parent = identifier.parent;
|
|
10324
|
-
if (parent.type ===
|
|
10454
|
+
if (parent.type === import_utils56.AST_NODE_TYPES.MemberExpression) {
|
|
10325
10455
|
if (parent.object !== identifier) {
|
|
10326
10456
|
return true;
|
|
10327
10457
|
}
|
|
10328
10458
|
const grandparent = parent.parent;
|
|
10329
|
-
if (grandparent.type ===
|
|
10459
|
+
if (grandparent.type === import_utils56.AST_NODE_TYPES.AssignmentExpression && grandparent.left === parent) {
|
|
10330
10460
|
return false;
|
|
10331
10461
|
}
|
|
10332
|
-
if (grandparent.type ===
|
|
10462
|
+
if (grandparent.type === import_utils56.AST_NODE_TYPES.UpdateExpression) {
|
|
10333
10463
|
return false;
|
|
10334
10464
|
}
|
|
10335
|
-
if (grandparent.type ===
|
|
10465
|
+
if (grandparent.type === import_utils56.AST_NODE_TYPES.UnaryExpression && grandparent.operator === "delete") {
|
|
10336
10466
|
return false;
|
|
10337
10467
|
}
|
|
10338
|
-
if (!parent.computed && parent.property.type ===
|
|
10468
|
+
if (!parent.computed && parent.property.type === import_utils56.AST_NODE_TYPES.Identifier && MUTATING_METHODS2.has(parent.property.name) && grandparent.type === import_utils56.AST_NODE_TYPES.CallExpression && grandparent.callee === parent) {
|
|
10339
10469
|
return false;
|
|
10340
10470
|
}
|
|
10341
10471
|
return true;
|
|
10342
10472
|
}
|
|
10343
|
-
if (parent.type ===
|
|
10473
|
+
if (parent.type === import_utils56.AST_NODE_TYPES.ForOfStatement && parent.right === identifier) {
|
|
10344
10474
|
return true;
|
|
10345
10475
|
}
|
|
10346
|
-
if (parent.type ===
|
|
10476
|
+
if (parent.type === import_utils56.AST_NODE_TYPES.SpreadElement) {
|
|
10347
10477
|
return true;
|
|
10348
10478
|
}
|
|
10349
|
-
if (parent.type ===
|
|
10479
|
+
if (parent.type === import_utils56.AST_NODE_TYPES.BinaryExpression) {
|
|
10350
10480
|
return true;
|
|
10351
10481
|
}
|
|
10352
|
-
if (parent.type ===
|
|
10482
|
+
if (parent.type === import_utils56.AST_NODE_TYPES.CallExpression && parent.arguments.includes(identifier) && isNonRetainingBuiltinCall(parent, identifier)) {
|
|
10353
10483
|
return true;
|
|
10354
10484
|
}
|
|
10355
|
-
if (parent.type ===
|
|
10485
|
+
if (parent.type === import_utils56.AST_NODE_TYPES.UnaryExpression && parent.operator !== "delete") {
|
|
10356
10486
|
return true;
|
|
10357
10487
|
}
|
|
10358
10488
|
return false;
|
|
10359
10489
|
}
|
|
10360
10490
|
function isNonRetainingBuiltinCall(node, argument) {
|
|
10361
10491
|
const callee = node.callee;
|
|
10362
|
-
if (callee.type ===
|
|
10492
|
+
if (callee.type === import_utils56.AST_NODE_TYPES.Identifier && callee.name === "structuredClone") {
|
|
10363
10493
|
return true;
|
|
10364
10494
|
}
|
|
10365
|
-
if (callee.type !==
|
|
10495
|
+
if (callee.type !== import_utils56.AST_NODE_TYPES.MemberExpression || callee.computed || callee.object.type !== import_utils56.AST_NODE_TYPES.Identifier || callee.property.type !== import_utils56.AST_NODE_TYPES.Identifier) {
|
|
10366
10496
|
return false;
|
|
10367
10497
|
}
|
|
10368
10498
|
const members = NON_RETAINING_BUILTINS.get(callee.object.name);
|
|
@@ -10425,7 +10555,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
10425
10555
|
if (reference.isWrite()) {
|
|
10426
10556
|
return false;
|
|
10427
10557
|
}
|
|
10428
|
-
if (reference.identifier.type !==
|
|
10558
|
+
if (reference.identifier.type !== import_utils56.AST_NODE_TYPES.Identifier) {
|
|
10429
10559
|
return false;
|
|
10430
10560
|
}
|
|
10431
10561
|
if (!isSafeRead(reference.identifier)) {
|
|
@@ -10437,10 +10567,10 @@ var prefer_module_level_constant_default = createRule({
|
|
|
10437
10567
|
return {
|
|
10438
10568
|
VariableDeclarator(node) {
|
|
10439
10569
|
const declaration = node.parent;
|
|
10440
|
-
if (declaration.type !==
|
|
10570
|
+
if (declaration.type !== import_utils56.AST_NODE_TYPES.VariableDeclaration || declaration.kind !== "const" || declaration.declare === true) {
|
|
10441
10571
|
return;
|
|
10442
10572
|
}
|
|
10443
|
-
if (node.id.type !==
|
|
10573
|
+
if (node.id.type !== import_utils56.AST_NODE_TYPES.Identifier || node.init === null) {
|
|
10444
10574
|
return;
|
|
10445
10575
|
}
|
|
10446
10576
|
if (enclosingFunction2(node) === null) {
|
|
@@ -10467,7 +10597,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
10467
10597
|
});
|
|
10468
10598
|
|
|
10469
10599
|
// src/rules/prefer-module-level-schema.ts
|
|
10470
|
-
var
|
|
10600
|
+
var import_utils57 = require("@typescript-eslint/utils");
|
|
10471
10601
|
var preferModuleLevelSchemaDocumentation = {
|
|
10472
10602
|
summary: "Declare a Zod schema at module scope when it closes over nothing in the enclosing function",
|
|
10473
10603
|
rationale: "A closed schema created inside a function is rebuilt on every call and cannot be reused or exported for inference.",
|
|
@@ -10534,9 +10664,9 @@ var I18N_RECEIVER_NAMES = /* @__PURE__ */ new Set([
|
|
|
10534
10664
|
"intl"
|
|
10535
10665
|
]);
|
|
10536
10666
|
var FUNCTION_TYPES8 = /* @__PURE__ */ new Set([
|
|
10537
|
-
|
|
10538
|
-
|
|
10539
|
-
|
|
10667
|
+
import_utils57.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
10668
|
+
import_utils57.AST_NODE_TYPES.FunctionDeclaration,
|
|
10669
|
+
import_utils57.AST_NODE_TYPES.FunctionExpression
|
|
10540
10670
|
]);
|
|
10541
10671
|
function schemaExpression(node) {
|
|
10542
10672
|
let current = node;
|
|
@@ -10545,10 +10675,10 @@ function schemaExpression(node) {
|
|
|
10545
10675
|
if (parent === void 0) {
|
|
10546
10676
|
return current;
|
|
10547
10677
|
}
|
|
10548
|
-
if (parent.type ===
|
|
10678
|
+
if (parent.type === import_utils57.AST_NODE_TYPES.MemberExpression && parent.object === current && !parent.computed && parent.property.type === import_utils57.AST_NODE_TYPES.Identifier && TERMINAL_METHODS.has(parent.property.name)) {
|
|
10549
10679
|
return current;
|
|
10550
10680
|
}
|
|
10551
|
-
if (parent.type ===
|
|
10681
|
+
if (parent.type === import_utils57.AST_NODE_TYPES.MemberExpression && parent.object === current || parent.type === import_utils57.AST_NODE_TYPES.CallExpression && parent.callee === current || parent.type === import_utils57.AST_NODE_TYPES.TSAsExpression && parent.expression === current || parent.type === import_utils57.AST_NODE_TYPES.TSNonNullExpression && parent.expression === current) {
|
|
10552
10682
|
current = parent;
|
|
10553
10683
|
continue;
|
|
10554
10684
|
}
|
|
@@ -10599,22 +10729,22 @@ function subtreeSome(root, predicate) {
|
|
|
10599
10729
|
function readsReceiver(node) {
|
|
10600
10730
|
return subtreeSome(
|
|
10601
10731
|
node,
|
|
10602
|
-
(inner) => inner.type ===
|
|
10732
|
+
(inner) => inner.type === import_utils57.AST_NODE_TYPES.ThisExpression || inner.type === import_utils57.AST_NODE_TYPES.Super || inner.type === import_utils57.AST_NODE_TYPES.Identifier && inner.name === "arguments"
|
|
10603
10733
|
);
|
|
10604
10734
|
}
|
|
10605
10735
|
function buildsLocalizedText(node) {
|
|
10606
10736
|
return subtreeSome(node, (inner) => {
|
|
10607
|
-
if (inner.type ===
|
|
10737
|
+
if (inner.type === import_utils57.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
10608
10738
|
return true;
|
|
10609
10739
|
}
|
|
10610
|
-
if (inner.type !==
|
|
10740
|
+
if (inner.type !== import_utils57.AST_NODE_TYPES.CallExpression) {
|
|
10611
10741
|
return false;
|
|
10612
10742
|
}
|
|
10613
10743
|
const { callee } = inner;
|
|
10614
|
-
if (callee.type ===
|
|
10744
|
+
if (callee.type === import_utils57.AST_NODE_TYPES.Identifier) {
|
|
10615
10745
|
return I18N_CALLEE_NAMES.has(callee.name);
|
|
10616
10746
|
}
|
|
10617
|
-
return callee.type ===
|
|
10747
|
+
return callee.type === import_utils57.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.object.type === import_utils57.AST_NODE_TYPES.Identifier && I18N_RECEIVER_NAMES.has(callee.object.name);
|
|
10618
10748
|
});
|
|
10619
10749
|
}
|
|
10620
10750
|
function collectReferences(scope, out) {
|
|
@@ -10678,15 +10808,15 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10678
10808
|
}
|
|
10679
10809
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
10680
10810
|
function isZodCall(node) {
|
|
10681
|
-
return node.type ===
|
|
10811
|
+
return node.type === import_utils57.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils57.AST_NODE_TYPES.MemberExpression && !node.callee.computed && node.callee.object.type === import_utils57.AST_NODE_TYPES.Identifier && zodNamespaces.has(node.callee.object.name);
|
|
10682
10812
|
}
|
|
10683
10813
|
function isCovered(node) {
|
|
10684
10814
|
let current = node.parent ?? void 0;
|
|
10685
10815
|
while (current !== void 0) {
|
|
10686
|
-
if (current !== node && isZodCall(current) && current.callee.type ===
|
|
10816
|
+
if (current !== node && isZodCall(current) && current.callee.type === import_utils57.AST_NODE_TYPES.MemberExpression && current.callee.property.type === import_utils57.AST_NODE_TYPES.Identifier && factories.has(current.callee.property.name)) {
|
|
10687
10817
|
return true;
|
|
10688
10818
|
}
|
|
10689
|
-
if (current.type ===
|
|
10819
|
+
if (current.type === import_utils57.AST_NODE_TYPES.CallExpression && (current.callee.type === import_utils57.AST_NODE_TYPES.Identifier && memoCallees.has(current.callee.name) || current.callee.type === import_utils57.AST_NODE_TYPES.MemberExpression && !current.callee.computed && current.callee.property.type === import_utils57.AST_NODE_TYPES.Identifier && memoCallees.has(current.callee.property.name))) {
|
|
10690
10820
|
return true;
|
|
10691
10821
|
}
|
|
10692
10822
|
current = current.parent ?? void 0;
|
|
@@ -10701,11 +10831,11 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10701
10831
|
if (parent === void 0) {
|
|
10702
10832
|
return confirmed;
|
|
10703
10833
|
}
|
|
10704
|
-
if (parent.type ===
|
|
10834
|
+
if (parent.type === import_utils57.AST_NODE_TYPES.Property && parent.value === current || parent.type === import_utils57.AST_NODE_TYPES.ObjectExpression || parent.type === import_utils57.AST_NODE_TYPES.ArrayExpression) {
|
|
10705
10835
|
current = parent;
|
|
10706
10836
|
continue;
|
|
10707
10837
|
}
|
|
10708
|
-
if (parent.type ===
|
|
10838
|
+
if (parent.type === import_utils57.AST_NODE_TYPES.CallExpression && parent.arguments.includes(current) && isSchemaComposition(parent)) {
|
|
10709
10839
|
current = schemaExpression(parent);
|
|
10710
10840
|
confirmed = current;
|
|
10711
10841
|
continue;
|
|
@@ -10715,7 +10845,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10715
10845
|
}
|
|
10716
10846
|
function isSchemaComposition(node) {
|
|
10717
10847
|
const { callee } = node;
|
|
10718
|
-
const isCombinator = callee.type ===
|
|
10848
|
+
const isCombinator = callee.type === import_utils57.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils57.AST_NODE_TYPES.Identifier && ZOD_COMBINATOR_METHODS.has(callee.property.name);
|
|
10719
10849
|
return isCombinator || isZodCall(node);
|
|
10720
10850
|
}
|
|
10721
10851
|
function closesOverNothing(node, enclosing) {
|
|
@@ -10735,12 +10865,12 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10735
10865
|
for (const definition of resolved.defs) {
|
|
10736
10866
|
if (definition.type === "ImportBinding") {
|
|
10737
10867
|
const parent = reference.identifier.parent;
|
|
10738
|
-
if (parent?.type ===
|
|
10868
|
+
if (parent?.type === import_utils57.AST_NODE_TYPES.CallExpression && parent.callee === reference.identifier && !zodNamespaces.has(reference.identifier.name)) {
|
|
10739
10869
|
return false;
|
|
10740
10870
|
}
|
|
10741
10871
|
continue;
|
|
10742
10872
|
}
|
|
10743
|
-
if (definition.node.type ===
|
|
10873
|
+
if (definition.node.type === import_utils57.AST_NODE_TYPES.VariableDeclarator && definition.node.parent.type === import_utils57.AST_NODE_TYPES.VariableDeclaration && definition.node.parent.kind !== "const") {
|
|
10744
10874
|
return false;
|
|
10745
10875
|
}
|
|
10746
10876
|
const [defStart, defEnd] = definition.node.range;
|
|
@@ -10756,13 +10886,13 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10756
10886
|
}
|
|
10757
10887
|
function ownerName(enclosing) {
|
|
10758
10888
|
const parent = enclosing.parent ?? void 0;
|
|
10759
|
-
if (enclosing.type ===
|
|
10889
|
+
if (enclosing.type === import_utils57.AST_NODE_TYPES.FunctionDeclaration && enclosing.id !== null) {
|
|
10760
10890
|
return enclosing.id.name;
|
|
10761
10891
|
}
|
|
10762
|
-
if (parent !== void 0 && parent.type ===
|
|
10892
|
+
if (parent !== void 0 && parent.type === import_utils57.AST_NODE_TYPES.VariableDeclarator && parent.id.type === import_utils57.AST_NODE_TYPES.Identifier) {
|
|
10763
10893
|
return parent.id.name;
|
|
10764
10894
|
}
|
|
10765
|
-
if (parent !== void 0 && (parent.type ===
|
|
10895
|
+
if (parent !== void 0 && (parent.type === import_utils57.AST_NODE_TYPES.MethodDefinition || parent.type === import_utils57.AST_NODE_TYPES.Property) && parent.key.type === import_utils57.AST_NODE_TYPES.Identifier) {
|
|
10766
10896
|
return parent.key.name;
|
|
10767
10897
|
}
|
|
10768
10898
|
return "this function";
|
|
@@ -10773,7 +10903,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10773
10903
|
return;
|
|
10774
10904
|
}
|
|
10775
10905
|
for (const specifier of node.specifiers) {
|
|
10776
|
-
if (specifier.type ===
|
|
10906
|
+
if (specifier.type === import_utils57.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils57.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils57.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils57.AST_NODE_TYPES.Identifier && specifier.imported.name === "z") {
|
|
10777
10907
|
zodNamespaces.add(specifier.local.name);
|
|
10778
10908
|
}
|
|
10779
10909
|
}
|
|
@@ -10783,7 +10913,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10783
10913
|
return;
|
|
10784
10914
|
}
|
|
10785
10915
|
const callee = node.callee;
|
|
10786
|
-
if (callee.property.type !==
|
|
10916
|
+
if (callee.property.type !== import_utils57.AST_NODE_TYPES.Identifier) {
|
|
10787
10917
|
return;
|
|
10788
10918
|
}
|
|
10789
10919
|
const factory = callee.property.name;
|
|
@@ -10798,7 +10928,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10798
10928
|
return;
|
|
10799
10929
|
}
|
|
10800
10930
|
const shape = node.arguments[0];
|
|
10801
|
-
if (shape !== void 0 && shape.type ===
|
|
10931
|
+
if (shape !== void 0 && shape.type === import_utils57.AST_NODE_TYPES.ObjectExpression && shape.properties.length < minProperties) {
|
|
10802
10932
|
return;
|
|
10803
10933
|
}
|
|
10804
10934
|
const expression = schemaExpression(node);
|
|
@@ -10826,7 +10956,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10826
10956
|
});
|
|
10827
10957
|
|
|
10828
10958
|
// src/rules/prefer-native-random-uuid.ts
|
|
10829
|
-
var
|
|
10959
|
+
var import_utils58 = require("@typescript-eslint/utils");
|
|
10830
10960
|
var preferNativeRandomUuidDocumentation = {
|
|
10831
10961
|
summary: "Prefer `globalThis.crypto.randomUUID()` over resolved zero-argument UUID v4 bindings from the `uuid` package.",
|
|
10832
10962
|
rationale: "The platform implementation avoids an unnecessary dependency for standard random UUID generation.",
|
|
@@ -10840,7 +10970,7 @@ var preferNativeRandomUuidDocumentation = {
|
|
|
10840
10970
|
]
|
|
10841
10971
|
};
|
|
10842
10972
|
function requireUuid(node) {
|
|
10843
|
-
return node?.type ===
|
|
10973
|
+
return node?.type === import_utils58.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils58.AST_NODE_TYPES.Identifier && node.callee.name === "require" && node.arguments.length === 1 && node.arguments[0]?.type === import_utils58.AST_NODE_TYPES.Literal && node.arguments[0].value === "uuid";
|
|
10844
10974
|
}
|
|
10845
10975
|
var prefer_native_random_uuid_default = createRule({
|
|
10846
10976
|
name: "prefer-native-random-uuid",
|
|
@@ -10862,7 +10992,7 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
10862
10992
|
const directBindings = /* @__PURE__ */ new Set();
|
|
10863
10993
|
const namespaceBindings = /* @__PURE__ */ new Set();
|
|
10864
10994
|
function resolve(identifier) {
|
|
10865
|
-
return
|
|
10995
|
+
return import_utils58.ASTUtils.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
10866
10996
|
}
|
|
10867
10997
|
function record(identifier, destination) {
|
|
10868
10998
|
const variable = resolve(identifier);
|
|
@@ -10884,37 +11014,37 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
10884
11014
|
ImportDeclaration(node) {
|
|
10885
11015
|
if (node.source.value !== "uuid") return;
|
|
10886
11016
|
for (const specifier of node.specifiers) {
|
|
10887
|
-
if (specifier.type ===
|
|
11017
|
+
if (specifier.type === import_utils58.AST_NODE_TYPES.ImportSpecifier && (specifier.imported.type === import_utils58.AST_NODE_TYPES.Identifier ? specifier.imported.name === "v4" : specifier.imported.value === "v4")) {
|
|
10888
11018
|
record(specifier.local, directBindings);
|
|
10889
|
-
} else if (specifier.type ===
|
|
11019
|
+
} else if (specifier.type === import_utils58.AST_NODE_TYPES.ImportNamespaceSpecifier) {
|
|
10890
11020
|
record(specifier.local, namespaceBindings);
|
|
10891
11021
|
}
|
|
10892
11022
|
}
|
|
10893
11023
|
},
|
|
10894
11024
|
VariableDeclarator(node) {
|
|
10895
11025
|
if (node.parent.kind !== "const" || !requireUuid(node.init)) return;
|
|
10896
|
-
if (node.init?.type !==
|
|
11026
|
+
if (node.init?.type !== import_utils58.AST_NODE_TYPES.CallExpression || node.init.callee.type !== import_utils58.AST_NODE_TYPES.Identifier || (resolve(node.init.callee)?.defs.length ?? 0) > 0) {
|
|
10897
11027
|
return;
|
|
10898
11028
|
}
|
|
10899
|
-
if (node.id.type ===
|
|
11029
|
+
if (node.id.type === import_utils58.AST_NODE_TYPES.Identifier) {
|
|
10900
11030
|
record(node.id, namespaceBindings);
|
|
10901
11031
|
return;
|
|
10902
11032
|
}
|
|
10903
|
-
if (node.id.type !==
|
|
11033
|
+
if (node.id.type !== import_utils58.AST_NODE_TYPES.ObjectPattern) return;
|
|
10904
11034
|
for (const property of node.id.properties) {
|
|
10905
|
-
if (property.type ===
|
|
11035
|
+
if (property.type === import_utils58.AST_NODE_TYPES.Property && !property.computed && (property.key.type === import_utils58.AST_NODE_TYPES.Identifier && property.key.name === "v4" || property.key.type === import_utils58.AST_NODE_TYPES.Literal && property.key.value === "v4") && property.value.type === import_utils58.AST_NODE_TYPES.Identifier) {
|
|
10906
11036
|
record(property.value, directBindings);
|
|
10907
11037
|
}
|
|
10908
11038
|
}
|
|
10909
11039
|
},
|
|
10910
11040
|
"CallExpression:exit"(node) {
|
|
10911
11041
|
if (node.arguments.length !== 0) return;
|
|
10912
|
-
if (node.callee.type ===
|
|
11042
|
+
if (node.callee.type === import_utils58.AST_NODE_TYPES.Identifier) {
|
|
10913
11043
|
const variable2 = resolve(node.callee);
|
|
10914
11044
|
if (variable2 !== null && directBindings.has(variable2)) report(node);
|
|
10915
11045
|
return;
|
|
10916
11046
|
}
|
|
10917
|
-
if (node.callee.type !==
|
|
11047
|
+
if (node.callee.type !== import_utils58.AST_NODE_TYPES.MemberExpression || node.callee.computed || node.callee.object.type !== import_utils58.AST_NODE_TYPES.Identifier || node.callee.property.type !== import_utils58.AST_NODE_TYPES.Identifier || node.callee.property.name !== "v4") {
|
|
10918
11048
|
return;
|
|
10919
11049
|
}
|
|
10920
11050
|
const variable = resolve(node.callee.object);
|
|
@@ -10925,7 +11055,7 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
10925
11055
|
});
|
|
10926
11056
|
|
|
10927
11057
|
// src/rules/prefer-non-nullable-collection.ts
|
|
10928
|
-
var
|
|
11058
|
+
var import_utils59 = require("@typescript-eslint/utils");
|
|
10929
11059
|
var preferNonNullableCollectionDocumentation = {
|
|
10930
11060
|
summary: "Suggest non-null arrays only when local control flow proves the nullish state is equivalent to an empty collection.",
|
|
10931
11061
|
rationale: "A redundant nullish collection state spreads defaults and guards through consumers without carrying information.",
|
|
@@ -10941,33 +11071,33 @@ var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
|
10941
11071
|
function propertyName(node) {
|
|
10942
11072
|
const key = node.key;
|
|
10943
11073
|
if (node.computed) return null;
|
|
10944
|
-
if (key.type ===
|
|
10945
|
-
if (key.type ===
|
|
11074
|
+
if (key.type === import_utils59.AST_NODE_TYPES.Identifier) return key.name;
|
|
11075
|
+
if (key.type === import_utils59.AST_NODE_TYPES.Literal && typeof key.value === "string") return key.value;
|
|
10946
11076
|
return null;
|
|
10947
11077
|
}
|
|
10948
11078
|
function isArrayType(node) {
|
|
10949
|
-
if (node.type ===
|
|
10950
|
-
return node.type ===
|
|
11079
|
+
if (node.type === import_utils59.AST_NODE_TYPES.TSArrayType) return true;
|
|
11080
|
+
return node.type === import_utils59.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils59.AST_NODE_TYPES.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
10951
11081
|
}
|
|
10952
11082
|
function nullableProperty(node) {
|
|
10953
11083
|
if (node.optional) return null;
|
|
10954
11084
|
const name = propertyName(node);
|
|
10955
11085
|
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
10956
|
-
if (name === null || annotation?.type !==
|
|
11086
|
+
if (name === null || annotation?.type !== import_utils59.AST_NODE_TYPES.TSUnionType) return null;
|
|
10957
11087
|
const concrete = annotation.types.filter(
|
|
10958
|
-
(member) => member.type !==
|
|
11088
|
+
(member) => member.type !== import_utils59.AST_NODE_TYPES.TSNullKeyword && member.type !== import_utils59.AST_NODE_TYPES.TSUndefinedKeyword
|
|
10959
11089
|
);
|
|
10960
11090
|
if (concrete.length === 0 || !concrete.every(isArrayType)) return null;
|
|
10961
|
-
const acceptsNull = annotation.types.some((member) => member.type ===
|
|
11091
|
+
const acceptsNull = annotation.types.some((member) => member.type === import_utils59.AST_NODE_TYPES.TSNullKeyword);
|
|
10962
11092
|
const acceptsUndefined = annotation.types.some(
|
|
10963
|
-
(member) => member.type ===
|
|
11093
|
+
(member) => member.type === import_utils59.AST_NODE_TYPES.TSUndefinedKeyword
|
|
10964
11094
|
);
|
|
10965
11095
|
if (!acceptsNull && !acceptsUndefined) return null;
|
|
10966
11096
|
return { name, node, acceptsNull, acceptsUndefined };
|
|
10967
11097
|
}
|
|
10968
11098
|
function shapeProperties(members) {
|
|
10969
11099
|
return members.flatMap((member) => {
|
|
10970
|
-
if (member.type !==
|
|
11100
|
+
if (member.type !== import_utils59.AST_NODE_TYPES.TSPropertySignature) return [];
|
|
10971
11101
|
const property = nullableProperty(member);
|
|
10972
11102
|
return property === null ? [] : [property];
|
|
10973
11103
|
});
|
|
@@ -10975,14 +11105,14 @@ function shapeProperties(members) {
|
|
|
10975
11105
|
function typeIndex(program) {
|
|
10976
11106
|
const index = /* @__PURE__ */ new Map();
|
|
10977
11107
|
for (const statement of program.body) {
|
|
10978
|
-
const exported = statement.type ===
|
|
11108
|
+
const exported = statement.type === import_utils59.AST_NODE_TYPES.ExportNamedDeclaration;
|
|
10979
11109
|
const declaration = exported ? statement.declaration : statement;
|
|
10980
|
-
if (declaration?.type ===
|
|
11110
|
+
if (declaration?.type === import_utils59.AST_NODE_TYPES.TSInterfaceDeclaration) {
|
|
10981
11111
|
index.set(declaration.id.name, {
|
|
10982
11112
|
exported,
|
|
10983
11113
|
properties: shapeProperties(declaration.body.body)
|
|
10984
11114
|
});
|
|
10985
|
-
} else if (declaration?.type ===
|
|
11115
|
+
} else if (declaration?.type === import_utils59.AST_NODE_TYPES.TSTypeAliasDeclaration && declaration.typeAnnotation.type === import_utils59.AST_NODE_TYPES.TSTypeLiteral) {
|
|
10986
11116
|
index.set(declaration.id.name, {
|
|
10987
11117
|
exported,
|
|
10988
11118
|
properties: shapeProperties(declaration.typeAnnotation.members)
|
|
@@ -10992,42 +11122,42 @@ function typeIndex(program) {
|
|
|
10992
11122
|
return index;
|
|
10993
11123
|
}
|
|
10994
11124
|
function emptyArray(node) {
|
|
10995
|
-
return node.type ===
|
|
11125
|
+
return node.type === import_utils59.AST_NODE_TYPES.ArrayExpression && node.elements.length === 0;
|
|
10996
11126
|
}
|
|
10997
11127
|
function sameAccess(node, access) {
|
|
10998
11128
|
if (access.kind === "identifier") {
|
|
10999
|
-
return node.type ===
|
|
11129
|
+
return node.type === import_utils59.AST_NODE_TYPES.Identifier && node.name === access.name;
|
|
11000
11130
|
}
|
|
11001
|
-
return node.type ===
|
|
11131
|
+
return node.type === import_utils59.AST_NODE_TYPES.MemberExpression && !node.computed && node.object.type === import_utils59.AST_NODE_TYPES.Identifier && node.object.name === access.object && node.property.type === import_utils59.AST_NODE_TYPES.Identifier && node.property.name === access.property;
|
|
11002
11132
|
}
|
|
11003
11133
|
function isNullGuard(node, access) {
|
|
11004
|
-
if (node.type ===
|
|
11005
|
-
if (node.type !==
|
|
11134
|
+
if (node.type === import_utils59.AST_NODE_TYPES.UnaryExpression && node.operator === "!" && (sameAccess(node.argument, access) || optionalMemberLengthOf(node.argument, access))) return true;
|
|
11135
|
+
if (node.type !== import_utils59.AST_NODE_TYPES.BinaryExpression || !["==", "==="].includes(node.operator)) {
|
|
11006
11136
|
return false;
|
|
11007
11137
|
}
|
|
11008
|
-
const nullish = (value) => value.type ===
|
|
11138
|
+
const nullish = (value) => value.type === import_utils59.AST_NODE_TYPES.Literal && value.value === null || value.type === import_utils59.AST_NODE_TYPES.Identifier && value.name === "undefined";
|
|
11009
11139
|
return sameAccess(node.left, access) && nullish(node.right) || sameAccess(node.right, access) && nullish(node.left);
|
|
11010
11140
|
}
|
|
11011
11141
|
function isEmptyGuard(node, access) {
|
|
11012
|
-
if (node.type ===
|
|
11013
|
-
if (node.type !==
|
|
11142
|
+
if (node.type === import_utils59.AST_NODE_TYPES.UnaryExpression && node.operator === "!" && memberLengthOf(node.argument, access)) return true;
|
|
11143
|
+
if (node.type !== import_utils59.AST_NODE_TYPES.BinaryExpression || !["==", "===", "<="].includes(node.operator)) {
|
|
11014
11144
|
return false;
|
|
11015
11145
|
}
|
|
11016
|
-
const zero = (value) => value.type ===
|
|
11146
|
+
const zero = (value) => value.type === import_utils59.AST_NODE_TYPES.Literal && value.value === 0;
|
|
11017
11147
|
return memberLengthOf(node.left, access) && zero(node.right) || memberLengthOf(node.right, access) && zero(node.left);
|
|
11018
11148
|
}
|
|
11019
11149
|
function memberLengthOf(node, access) {
|
|
11020
|
-
const target = node.type ===
|
|
11021
|
-
return target.type ===
|
|
11150
|
+
const target = node.type === import_utils59.AST_NODE_TYPES.ChainExpression ? node.expression : node;
|
|
11151
|
+
return target.type === import_utils59.AST_NODE_TYPES.MemberExpression && !target.computed && target.property.type === import_utils59.AST_NODE_TYPES.Identifier && target.property.name === "length" && sameAccess(target.object, access);
|
|
11022
11152
|
}
|
|
11023
11153
|
function optionalMemberLengthOf(node, access) {
|
|
11024
|
-
return node.type ===
|
|
11154
|
+
return node.type === import_utils59.AST_NODE_TYPES.ChainExpression && node.expression.type === import_utils59.AST_NODE_TYPES.MemberExpression && node.expression.optional && memberLengthOf(node, access);
|
|
11025
11155
|
}
|
|
11026
11156
|
function hasEquivalentLeadingGuard(fn, access, visitorKeys) {
|
|
11027
|
-
if (fn.body.type !==
|
|
11157
|
+
if (fn.body.type !== import_utils59.AST_NODE_TYPES.BlockStatement) return false;
|
|
11028
11158
|
const first = fn.body.body[0];
|
|
11029
|
-
if (first?.type !==
|
|
11030
|
-
const terminating = first.consequent.type ===
|
|
11159
|
+
if (first?.type !== import_utils59.AST_NODE_TYPES.IfStatement) return false;
|
|
11160
|
+
const terminating = first.consequent.type === import_utils59.AST_NODE_TYPES.ReturnStatement || first.consequent.type === import_utils59.AST_NODE_TYPES.ThrowStatement || first.consequent.type === import_utils59.AST_NODE_TYPES.BlockStatement && first.consequent.body.length === 1 && (first.consequent.body[0]?.type === import_utils59.AST_NODE_TYPES.ReturnStatement || first.consequent.body[0]?.type === import_utils59.AST_NODE_TYPES.ThrowStatement);
|
|
11031
11161
|
if (!terminating) return false;
|
|
11032
11162
|
if (contains(first.consequent, visitorKeys, (node) => sameAccess(node, access))) return false;
|
|
11033
11163
|
return contains(first.test, visitorKeys, (node) => isNullGuard(node, access)) && contains(first.test, visitorKeys, (node) => isEmptyGuard(node, access));
|
|
@@ -11045,29 +11175,29 @@ function contains(node, visitorKeys, predicate) {
|
|
|
11045
11175
|
function belongsToFunction(node, fn) {
|
|
11046
11176
|
let current = node;
|
|
11047
11177
|
while (current !== void 0 && current !== fn) {
|
|
11048
|
-
if (current !== node && (current.type ===
|
|
11178
|
+
if (current !== node && (current.type === import_utils59.AST_NODE_TYPES.ArrowFunctionExpression || current.type === import_utils59.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils59.AST_NODE_TYPES.FunctionExpression)) return false;
|
|
11049
11179
|
current = current.parent;
|
|
11050
11180
|
}
|
|
11051
11181
|
return current === fn;
|
|
11052
11182
|
}
|
|
11053
11183
|
function directlyCoalesced(node) {
|
|
11054
11184
|
const parent = node.parent;
|
|
11055
|
-
return parent?.type ===
|
|
11185
|
+
return parent?.type === import_utils59.AST_NODE_TYPES.LogicalExpression && parent.left === node && (parent.operator === "??" || parent.operator === "||") && emptyArray(parent.right);
|
|
11056
11186
|
}
|
|
11057
11187
|
function identifierIsOnlyCoalesced(context, binding, fn) {
|
|
11058
|
-
const variable =
|
|
11188
|
+
const variable = import_utils59.ASTUtils.findVariable(context.sourceCode.getScope(binding), binding.name);
|
|
11059
11189
|
if (variable === null || variable.references.length === 0) return false;
|
|
11060
11190
|
return variable.references.every(
|
|
11061
11191
|
(reference) => belongsToFunction(reference.identifier, fn) && directlyCoalesced(reference.identifier)
|
|
11062
11192
|
);
|
|
11063
11193
|
}
|
|
11064
11194
|
function memberIsOnlyCoalesced(context, object, property, fn) {
|
|
11065
|
-
const variable =
|
|
11195
|
+
const variable = import_utils59.ASTUtils.findVariable(context.sourceCode.getScope(object), object.name);
|
|
11066
11196
|
if (variable === null) return false;
|
|
11067
11197
|
const accesses = variable.references.flatMap((reference) => {
|
|
11068
11198
|
if (!belongsToFunction(reference.identifier, fn)) return [null];
|
|
11069
11199
|
const parent = reference.identifier.parent;
|
|
11070
|
-
if (parent?.type ===
|
|
11200
|
+
if (parent?.type === import_utils59.AST_NODE_TYPES.MemberExpression && !parent.computed && parent.object === reference.identifier && parent.property.type === import_utils59.AST_NODE_TYPES.Identifier && parent.property.name === property) return [parent];
|
|
11071
11201
|
return [];
|
|
11072
11202
|
});
|
|
11073
11203
|
return accesses.length > 0 && accesses.every((access) => access !== null && directlyCoalesced(access));
|
|
@@ -11093,8 +11223,8 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
11093
11223
|
let shapes = /* @__PURE__ */ new Map();
|
|
11094
11224
|
const evidence = /* @__PURE__ */ new Map();
|
|
11095
11225
|
function propertiesFor(annotation) {
|
|
11096
|
-
if (annotation?.type ===
|
|
11097
|
-
if (annotation?.type ===
|
|
11226
|
+
if (annotation?.type === import_utils59.AST_NODE_TYPES.TSTypeLiteral) return shapeProperties(annotation.members);
|
|
11227
|
+
if (annotation?.type === import_utils59.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils59.AST_NODE_TYPES.Identifier) {
|
|
11098
11228
|
const shape = shapes.get(annotation.typeName.name);
|
|
11099
11229
|
return shape?.exported === false ? shape.properties : [];
|
|
11100
11230
|
}
|
|
@@ -11107,21 +11237,21 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
11107
11237
|
}
|
|
11108
11238
|
function checkFunction(fn) {
|
|
11109
11239
|
for (const rawParameter of fn.params) {
|
|
11110
|
-
const parameter = rawParameter.type ===
|
|
11111
|
-
if (parameter.type ===
|
|
11240
|
+
const parameter = rawParameter.type === import_utils59.AST_NODE_TYPES.AssignmentPattern ? rawParameter.left : rawParameter;
|
|
11241
|
+
if (parameter.type === import_utils59.AST_NODE_TYPES.ObjectPattern) {
|
|
11112
11242
|
const properties2 = propertiesFor(parameter.typeAnnotation?.typeAnnotation);
|
|
11113
11243
|
for (const property of properties2) {
|
|
11114
11244
|
const bindingProperty = parameter.properties.find(
|
|
11115
|
-
(entry) => entry.type ===
|
|
11245
|
+
(entry) => entry.type === import_utils59.AST_NODE_TYPES.Property && !entry.computed && entry.key.type === import_utils59.AST_NODE_TYPES.Identifier && entry.key.name === property.name
|
|
11116
11246
|
);
|
|
11117
11247
|
if (bindingProperty === void 0) continue;
|
|
11118
11248
|
const value = bindingProperty.value;
|
|
11119
|
-
const binding = value.type ===
|
|
11120
|
-
if (binding.type !==
|
|
11249
|
+
const binding = value.type === import_utils59.AST_NODE_TYPES.AssignmentPattern ? value.left : value;
|
|
11250
|
+
if (binding.type !== import_utils59.AST_NODE_TYPES.Identifier) {
|
|
11121
11251
|
record(property, false);
|
|
11122
11252
|
continue;
|
|
11123
11253
|
}
|
|
11124
|
-
if (value.type ===
|
|
11254
|
+
if (value.type === import_utils59.AST_NODE_TYPES.AssignmentPattern && emptyArray(value.right) && property.acceptsUndefined && !property.acceptsNull) {
|
|
11125
11255
|
record(property, true);
|
|
11126
11256
|
continue;
|
|
11127
11257
|
}
|
|
@@ -11133,7 +11263,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
11133
11263
|
}
|
|
11134
11264
|
continue;
|
|
11135
11265
|
}
|
|
11136
|
-
if (parameter.type !==
|
|
11266
|
+
if (parameter.type !== import_utils59.AST_NODE_TYPES.Identifier) continue;
|
|
11137
11267
|
const properties = propertiesFor(parameter.typeAnnotation?.typeAnnotation);
|
|
11138
11268
|
for (const property of properties) {
|
|
11139
11269
|
const access = {
|
|
@@ -11170,7 +11300,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
11170
11300
|
});
|
|
11171
11301
|
|
|
11172
11302
|
// src/rules/prefer-await-in-async-return.ts
|
|
11173
|
-
var
|
|
11303
|
+
var import_utils60 = require("@typescript-eslint/utils");
|
|
11174
11304
|
var ts2 = __toESM(require("typescript"), 1);
|
|
11175
11305
|
var preferAwaitInAsyncReturnDocumentation = {
|
|
11176
11306
|
summary: "Prefer explicit `await` when an async function directly returns one typed Promise `.then` transform.",
|
|
@@ -11180,7 +11310,8 @@ var preferAwaitInAsyncReturnDocumentation = {
|
|
|
11180
11310
|
since: "15.6.3",
|
|
11181
11311
|
limitations: [
|
|
11182
11312
|
"Only a single directly returned `.then` call with an inline callback is checked.",
|
|
11183
|
-
"The receiver must be proven Promise-like by TypeScript; untyped files and larger chains are intentionally ignored."
|
|
11313
|
+
"The receiver must be proven Promise-like by TypeScript; untyped files and larger chains are intentionally ignored.",
|
|
11314
|
+
"Direct loader callbacks passed to resolved `React.lazy` and `next/dynamic` imports are excluded because returning the module Promise is their framework contract."
|
|
11184
11315
|
],
|
|
11185
11316
|
examples: [
|
|
11186
11317
|
{
|
|
@@ -11209,30 +11340,30 @@ var preferAwaitInAsyncReturnDocumentation = {
|
|
|
11209
11340
|
}
|
|
11210
11341
|
]
|
|
11211
11342
|
};
|
|
11212
|
-
function
|
|
11343
|
+
function directAsyncReturnOwner(node) {
|
|
11213
11344
|
const parent = node.parent;
|
|
11214
|
-
if (parent.type ===
|
|
11215
|
-
return parent.async && !parent.generator;
|
|
11345
|
+
if (parent.type === import_utils60.AST_NODE_TYPES.ArrowFunctionExpression && parent.body === node) {
|
|
11346
|
+
return parent.async && !parent.generator ? parent : null;
|
|
11216
11347
|
}
|
|
11217
|
-
if (parent.type !==
|
|
11218
|
-
return
|
|
11348
|
+
if (parent.type !== import_utils60.AST_NODE_TYPES.ReturnStatement || parent.argument !== node) {
|
|
11349
|
+
return null;
|
|
11219
11350
|
}
|
|
11220
11351
|
let owner = parent.parent;
|
|
11221
11352
|
while (owner !== void 0 && !isRuntimeFunction(owner)) {
|
|
11222
11353
|
owner = owner.parent;
|
|
11223
11354
|
}
|
|
11224
|
-
return owner !== void 0 && owner.async && !owner.generator;
|
|
11355
|
+
return owner !== void 0 && owner.async && !owner.generator ? owner : null;
|
|
11225
11356
|
}
|
|
11226
11357
|
function isRuntimeFunction(node) {
|
|
11227
|
-
return node.type ===
|
|
11358
|
+
return node.type === import_utils60.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils60.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils60.AST_NODE_TYPES.FunctionExpression;
|
|
11228
11359
|
}
|
|
11229
11360
|
function promiseThenReceiver(node) {
|
|
11230
11361
|
const callee = node.callee;
|
|
11231
|
-
if (callee.type !==
|
|
11362
|
+
if (callee.type !== import_utils60.AST_NODE_TYPES.MemberExpression || callee.computed || callee.optional || callee.property.type !== import_utils60.AST_NODE_TYPES.Identifier || callee.property.name !== "then" || node.optional || node.arguments.length !== 1) {
|
|
11232
11363
|
return null;
|
|
11233
11364
|
}
|
|
11234
11365
|
const callback = node.arguments[0];
|
|
11235
|
-
if (callback === void 0 || callback.type !==
|
|
11366
|
+
if (callback === void 0 || callback.type !== import_utils60.AST_NODE_TYPES.ArrowFunctionExpression && callback.type !== import_utils60.AST_NODE_TYPES.FunctionExpression) {
|
|
11236
11367
|
return null;
|
|
11237
11368
|
}
|
|
11238
11369
|
return callee.object;
|
|
@@ -11273,14 +11404,38 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
11273
11404
|
create(context) {
|
|
11274
11405
|
let services;
|
|
11275
11406
|
try {
|
|
11276
|
-
services =
|
|
11407
|
+
services = import_utils60.ESLintUtils.getParserServices(context);
|
|
11277
11408
|
} catch {
|
|
11278
11409
|
services = null;
|
|
11279
11410
|
}
|
|
11280
11411
|
if (services === null) return {};
|
|
11412
|
+
const frameworkLoaders = /* @__PURE__ */ new Set();
|
|
11413
|
+
const rememberFrameworkLoader = (identifier) => {
|
|
11414
|
+
const variable = import_utils60.ASTUtils.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
11415
|
+
if (variable !== null) frameworkLoaders.add(variable);
|
|
11416
|
+
};
|
|
11417
|
+
const isFrameworkLoaderCallback = (owner) => {
|
|
11418
|
+
const parent = owner.parent;
|
|
11419
|
+
if (parent.type !== import_utils60.AST_NODE_TYPES.CallExpression || parent.arguments[0] !== owner || parent.callee.type !== import_utils60.AST_NODE_TYPES.Identifier) return false;
|
|
11420
|
+
const variable = import_utils60.ASTUtils.findVariable(context.sourceCode.getScope(parent.callee), parent.callee.name);
|
|
11421
|
+
return variable !== null && frameworkLoaders.has(variable);
|
|
11422
|
+
};
|
|
11281
11423
|
return {
|
|
11424
|
+
ImportDeclaration(node) {
|
|
11425
|
+
if (node.source.value === "react") {
|
|
11426
|
+
for (const specifier of node.specifiers) {
|
|
11427
|
+
if (specifier.type === import_utils60.AST_NODE_TYPES.ImportSpecifier && (specifier.imported.type === import_utils60.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value) === "lazy") rememberFrameworkLoader(specifier.local);
|
|
11428
|
+
}
|
|
11429
|
+
}
|
|
11430
|
+
if (node.source.value === "next/dynamic") {
|
|
11431
|
+
for (const specifier of node.specifiers) {
|
|
11432
|
+
if (specifier.type === import_utils60.AST_NODE_TYPES.ImportDefaultSpecifier) rememberFrameworkLoader(specifier.local);
|
|
11433
|
+
}
|
|
11434
|
+
}
|
|
11435
|
+
},
|
|
11282
11436
|
CallExpression(node) {
|
|
11283
|
-
|
|
11437
|
+
const owner = directAsyncReturnOwner(node);
|
|
11438
|
+
if (owner === null || isFrameworkLoaderCallback(owner)) return;
|
|
11284
11439
|
const receiver = promiseThenReceiver(node);
|
|
11285
11440
|
if (receiver === null || !isProvenPromiseLike(receiver, services)) {
|
|
11286
11441
|
return;
|
|
@@ -11292,7 +11447,7 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
11292
11447
|
});
|
|
11293
11448
|
|
|
11294
11449
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
11295
|
-
var
|
|
11450
|
+
var import_utils61 = require("@typescript-eslint/utils");
|
|
11296
11451
|
var preferSchemaForApiPayloadDocumentation = {
|
|
11297
11452
|
summary: "Require Zod (or similar) schema validation on `response.json()` / `JSON.parse()` results before property access.",
|
|
11298
11453
|
rationale: "External JSON is untrusted at runtime even when its expected TypeScript shape is known statically.",
|
|
@@ -11307,9 +11462,9 @@ var preferSchemaForApiPayloadDocumentation = {
|
|
|
11307
11462
|
var unwrap4 = (node) => {
|
|
11308
11463
|
let current = node;
|
|
11309
11464
|
while (current !== null && current !== void 0) {
|
|
11310
|
-
if (current.type ===
|
|
11465
|
+
if (current.type === import_utils61.AST_NODE_TYPES.TSAsExpression || current.type === import_utils61.AST_NODE_TYPES.TSTypeAssertion || current.type === import_utils61.AST_NODE_TYPES.TSNonNullExpression || current.type === import_utils61.AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
11311
11466
|
current = current.expression;
|
|
11312
|
-
} else if (current.type ===
|
|
11467
|
+
} else if (current.type === import_utils61.AST_NODE_TYPES.ChainExpression) {
|
|
11313
11468
|
current = current.expression;
|
|
11314
11469
|
} else {
|
|
11315
11470
|
break;
|
|
@@ -11324,23 +11479,23 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
11324
11479
|
]);
|
|
11325
11480
|
var isSchemaParseReference = (node) => {
|
|
11326
11481
|
const inner = unwrap4(node);
|
|
11327
|
-
return inner !== null && inner.type ===
|
|
11482
|
+
return inner !== null && inner.type === import_utils61.AST_NODE_TYPES.MemberExpression && !inner.computed && inner.property.type === import_utils61.AST_NODE_TYPES.Identifier && (inner.property.name === "parse" || inner.property.name === "safeParse");
|
|
11328
11483
|
};
|
|
11329
11484
|
var isRawPayloadSource = (node, isKnownLocalText) => {
|
|
11330
11485
|
let current = unwrap4(node);
|
|
11331
11486
|
if (current === null) return false;
|
|
11332
|
-
if (current.type ===
|
|
11487
|
+
if (current.type === import_utils61.AST_NODE_TYPES.AwaitExpression) {
|
|
11333
11488
|
current = unwrap4(current.argument);
|
|
11334
11489
|
}
|
|
11335
|
-
if (current === null || current.type !==
|
|
11490
|
+
if (current === null || current.type !== import_utils61.AST_NODE_TYPES.CallExpression) {
|
|
11336
11491
|
return false;
|
|
11337
11492
|
}
|
|
11338
11493
|
const callee = unwrap4(current.callee);
|
|
11339
|
-
if (callee === null || callee.type !==
|
|
11494
|
+
if (callee === null || callee.type !== import_utils61.AST_NODE_TYPES.MemberExpression) {
|
|
11340
11495
|
return false;
|
|
11341
11496
|
}
|
|
11342
11497
|
const property = unwrap4(callee.property);
|
|
11343
|
-
if (property === null || property.type !==
|
|
11498
|
+
if (property === null || property.type !== import_utils61.AST_NODE_TYPES.Identifier) {
|
|
11344
11499
|
return false;
|
|
11345
11500
|
}
|
|
11346
11501
|
if (property.name === "json") {
|
|
@@ -11350,17 +11505,17 @@ var isRawPayloadSource = (node, isKnownLocalText) => {
|
|
|
11350
11505
|
return !current.arguments.some(isSchemaParseReference) && isRawPayloadSource(callee.object);
|
|
11351
11506
|
}
|
|
11352
11507
|
const object = unwrap4(callee.object);
|
|
11353
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
11508
|
+
return property.name === "parse" && object !== null && object.type === import_utils61.AST_NODE_TYPES.Identifier && object.name === "JSON" && !isLocalFileRead(current.arguments[0]) && isKnownLocalText?.(current.arguments[0]) !== true;
|
|
11354
11509
|
};
|
|
11355
11510
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
11356
11511
|
var isDirectLocalFileRead = (node) => {
|
|
11357
11512
|
let current = unwrap4(node);
|
|
11358
|
-
if (current?.type ===
|
|
11513
|
+
if (current?.type === import_utils61.AST_NODE_TYPES.AwaitExpression) {
|
|
11359
11514
|
current = unwrap4(current.argument);
|
|
11360
11515
|
}
|
|
11361
|
-
if (current?.type !==
|
|
11516
|
+
if (current?.type !== import_utils61.AST_NODE_TYPES.CallExpression) return false;
|
|
11362
11517
|
const callee = unwrap4(current.callee);
|
|
11363
|
-
const name = callee?.type ===
|
|
11518
|
+
const name = callee?.type === import_utils61.AST_NODE_TYPES.Identifier ? callee.name : callee?.type === import_utils61.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils61.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
11364
11519
|
return name !== null && FILE_READ_RE.test(name);
|
|
11365
11520
|
};
|
|
11366
11521
|
var isLocalFileRead = (node) => {
|
|
@@ -11387,15 +11542,15 @@ var isLocalFileRead = (node) => {
|
|
|
11387
11542
|
var ASSERTION_CALLEE_RE = /^(expect|assert|should|invariant)$/;
|
|
11388
11543
|
var isInsideAssertion = (node) => {
|
|
11389
11544
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11390
|
-
if (current.type !==
|
|
11545
|
+
if (current.type !== import_utils61.AST_NODE_TYPES.CallExpression) continue;
|
|
11391
11546
|
let callee = current.callee;
|
|
11392
|
-
while (callee.type ===
|
|
11547
|
+
while (callee.type === import_utils61.AST_NODE_TYPES.MemberExpression) {
|
|
11393
11548
|
callee = callee.object;
|
|
11394
11549
|
}
|
|
11395
|
-
if (callee.type ===
|
|
11550
|
+
if (callee.type === import_utils61.AST_NODE_TYPES.CallExpression) {
|
|
11396
11551
|
callee = callee.callee;
|
|
11397
11552
|
}
|
|
11398
|
-
if (callee.type ===
|
|
11553
|
+
if (callee.type === import_utils61.AST_NODE_TYPES.Identifier && ASSERTION_CALLEE_RE.test(callee.name)) {
|
|
11399
11554
|
return true;
|
|
11400
11555
|
}
|
|
11401
11556
|
}
|
|
@@ -11414,22 +11569,22 @@ var GUARD_NAME_RE = /^(?:is|validate|parse|assert|decode|coerce)[A-Z]/;
|
|
|
11414
11569
|
var isValidationRead = (node) => {
|
|
11415
11570
|
let current = node;
|
|
11416
11571
|
let parent = current.parent;
|
|
11417
|
-
while (parent !== null && parent !== void 0 && (parent.type ===
|
|
11572
|
+
while (parent !== null && parent !== void 0 && (parent.type === import_utils61.AST_NODE_TYPES.TSAsExpression || parent.type === import_utils61.AST_NODE_TYPES.TSTypeAssertion || parent.type === import_utils61.AST_NODE_TYPES.TSNonNullExpression || parent.type === import_utils61.AST_NODE_TYPES.TSSatisfiesExpression || parent.type === import_utils61.AST_NODE_TYPES.ChainExpression)) {
|
|
11418
11573
|
current = parent;
|
|
11419
11574
|
parent = parent.parent;
|
|
11420
11575
|
}
|
|
11421
11576
|
if (parent === null || parent === void 0) return false;
|
|
11422
|
-
if (parent.type ===
|
|
11577
|
+
if (parent.type === import_utils61.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof" && parent.argument === current) {
|
|
11423
11578
|
return true;
|
|
11424
11579
|
}
|
|
11425
|
-
if (parent.type !==
|
|
11580
|
+
if (parent.type !== import_utils61.AST_NODE_TYPES.CallExpression || !parent.arguments.some((arg) => arg === current)) {
|
|
11426
11581
|
return false;
|
|
11427
11582
|
}
|
|
11428
11583
|
const callee = parent.callee;
|
|
11429
|
-
if (callee.type ===
|
|
11584
|
+
if (callee.type === import_utils61.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.object.type === import_utils61.AST_NODE_TYPES.Identifier && callee.object.name === "Array" && callee.property.type === import_utils61.AST_NODE_TYPES.Identifier && callee.property.name === "isArray") {
|
|
11430
11585
|
return parent.arguments.length === 1;
|
|
11431
11586
|
}
|
|
11432
|
-
return callee.type ===
|
|
11587
|
+
return callee.type === import_utils61.AST_NODE_TYPES.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
11433
11588
|
};
|
|
11434
11589
|
var PRIMITIVE_TYPEOF_RESULTS = /* @__PURE__ */ new Set([
|
|
11435
11590
|
"bigint",
|
|
@@ -11440,13 +11595,13 @@ var PRIMITIVE_TYPEOF_RESULTS = /* @__PURE__ */ new Set([
|
|
|
11440
11595
|
"undefined"
|
|
11441
11596
|
]);
|
|
11442
11597
|
var bindingValidationPolarity = (test, bindingName) => {
|
|
11443
|
-
if (test.type ===
|
|
11598
|
+
if (test.type === import_utils61.AST_NODE_TYPES.UnaryExpression && test.operator === "!") {
|
|
11444
11599
|
const inner = bindingValidationPolarity(test.argument, bindingName);
|
|
11445
11600
|
return inner === "valid-when-true" ? "valid-when-false" : inner === "valid-when-false" ? "valid-when-true" : null;
|
|
11446
11601
|
}
|
|
11447
|
-
if (test.type ===
|
|
11448
|
-
const typeofName = (node) => node.type ===
|
|
11449
|
-
const literalType = (node) => node.type ===
|
|
11602
|
+
if (test.type === import_utils61.AST_NODE_TYPES.BinaryExpression) {
|
|
11603
|
+
const typeofName = (node) => node.type === import_utils61.AST_NODE_TYPES.UnaryExpression && node.operator === "typeof" && node.argument.type === import_utils61.AST_NODE_TYPES.Identifier ? node.argument.name : null;
|
|
11604
|
+
const literalType = (node) => node.type === import_utils61.AST_NODE_TYPES.Literal && typeof node.value === "string" && PRIMITIVE_TYPEOF_RESULTS.has(node.value) ? node.value : null;
|
|
11450
11605
|
const matches = typeofName(test.left) === bindingName && literalType(test.right) !== null || typeofName(test.right) === bindingName && literalType(test.left) !== null;
|
|
11451
11606
|
if (!matches) return null;
|
|
11452
11607
|
if (test.operator === "===" || test.operator === "==") {
|
|
@@ -11454,9 +11609,9 @@ var bindingValidationPolarity = (test, bindingName) => {
|
|
|
11454
11609
|
}
|
|
11455
11610
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
11456
11611
|
}
|
|
11457
|
-
return test.type ===
|
|
11612
|
+
return test.type === import_utils61.AST_NODE_TYPES.CallExpression && test.arguments.length === 1 && test.arguments[0]?.type === import_utils61.AST_NODE_TYPES.Identifier && test.arguments[0].name === bindingName && test.callee.type === import_utils61.AST_NODE_TYPES.MemberExpression && !test.callee.computed && test.callee.object.type === import_utils61.AST_NODE_TYPES.Identifier && test.callee.object.name === "Array" && test.callee.property.type === import_utils61.AST_NODE_TYPES.Identifier && test.callee.property.name === "isArray" ? "valid-when-true" : null;
|
|
11458
11613
|
};
|
|
11459
|
-
var plainMemberAccess = (node) => node.type ===
|
|
11614
|
+
var plainMemberAccess = (node) => node.type === import_utils61.AST_NODE_TYPES.MemberExpression && !node.computed && node.object.type === import_utils61.AST_NODE_TYPES.Identifier && node.property.type === import_utils61.AST_NODE_TYPES.Identifier ? { object: node.object.name, property: node.property.name } : null;
|
|
11460
11615
|
var isSamePlainMember = (node, access) => {
|
|
11461
11616
|
const candidate = plainMemberAccess(node);
|
|
11462
11617
|
return candidate !== null && candidate.object === access.object && candidate.property === access.property;
|
|
@@ -11464,19 +11619,19 @@ var isSamePlainMember = (node, access) => {
|
|
|
11464
11619
|
var nodeWithin2 = (node, container) => node.range[0] >= container.range[0] && node.range[1] <= container.range[1];
|
|
11465
11620
|
var isUseWithinValidatedBranch = (node, bindingName) => {
|
|
11466
11621
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11467
|
-
if (current.type ===
|
|
11622
|
+
if (current.type === import_utils61.AST_NODE_TYPES.ConditionalExpression) {
|
|
11468
11623
|
const polarity = bindingValidationPolarity(current.test, bindingName);
|
|
11469
11624
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && nodeWithin2(node, current.alternate)) {
|
|
11470
11625
|
return true;
|
|
11471
11626
|
}
|
|
11472
11627
|
}
|
|
11473
|
-
if (current.type ===
|
|
11628
|
+
if (current.type === import_utils61.AST_NODE_TYPES.IfStatement) {
|
|
11474
11629
|
const polarity = bindingValidationPolarity(current.test, bindingName);
|
|
11475
11630
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && current.alternate !== null && nodeWithin2(node, current.alternate)) {
|
|
11476
11631
|
return true;
|
|
11477
11632
|
}
|
|
11478
11633
|
}
|
|
11479
|
-
if (current.type ===
|
|
11634
|
+
if (current.type === import_utils61.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils61.AST_NODE_TYPES.FunctionExpression || current.type === import_utils61.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
11480
11635
|
return false;
|
|
11481
11636
|
}
|
|
11482
11637
|
}
|
|
@@ -11484,32 +11639,32 @@ var isUseWithinValidatedBranch = (node, bindingName) => {
|
|
|
11484
11639
|
};
|
|
11485
11640
|
var isMemberUseWithinValidatedBranch = (node, access) => {
|
|
11486
11641
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11487
|
-
if (current.type ===
|
|
11642
|
+
if (current.type === import_utils61.AST_NODE_TYPES.ConditionalExpression) {
|
|
11488
11643
|
const polarity = memberValidationPolarity(current.test, access);
|
|
11489
11644
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && nodeWithin2(node, current.alternate)) {
|
|
11490
11645
|
return true;
|
|
11491
11646
|
}
|
|
11492
11647
|
}
|
|
11493
|
-
if (current.type ===
|
|
11648
|
+
if (current.type === import_utils61.AST_NODE_TYPES.IfStatement) {
|
|
11494
11649
|
const polarity = memberValidationPolarity(current.test, access);
|
|
11495
11650
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && current.alternate !== null && nodeWithin2(node, current.alternate)) {
|
|
11496
11651
|
return true;
|
|
11497
11652
|
}
|
|
11498
11653
|
}
|
|
11499
|
-
if (current.type ===
|
|
11654
|
+
if (current.type === import_utils61.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils61.AST_NODE_TYPES.FunctionExpression || current.type === import_utils61.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
11500
11655
|
return false;
|
|
11501
11656
|
}
|
|
11502
11657
|
}
|
|
11503
11658
|
return false;
|
|
11504
11659
|
};
|
|
11505
11660
|
var memberValidationPolarity = (test, access) => {
|
|
11506
|
-
if (test.type ===
|
|
11661
|
+
if (test.type === import_utils61.AST_NODE_TYPES.UnaryExpression && test.operator === "!") {
|
|
11507
11662
|
const inner = memberValidationPolarity(test.argument, access);
|
|
11508
11663
|
return inner === "valid-when-true" ? "valid-when-false" : inner === "valid-when-false" ? "valid-when-true" : null;
|
|
11509
11664
|
}
|
|
11510
|
-
if (test.type ===
|
|
11511
|
-
const isMatchingTypeof = (node) => node.type ===
|
|
11512
|
-
const isPrimitiveType = (node) => node.type ===
|
|
11665
|
+
if (test.type === import_utils61.AST_NODE_TYPES.BinaryExpression) {
|
|
11666
|
+
const isMatchingTypeof = (node) => node.type === import_utils61.AST_NODE_TYPES.UnaryExpression && node.operator === "typeof" && isSamePlainMember(node.argument, access);
|
|
11667
|
+
const isPrimitiveType = (node) => node.type === import_utils61.AST_NODE_TYPES.Literal && typeof node.value === "string" && PRIMITIVE_TYPEOF_RESULTS.has(node.value);
|
|
11513
11668
|
if (!(isMatchingTypeof(test.left) && isPrimitiveType(test.right) || isMatchingTypeof(test.right) && isPrimitiveType(test.left))) {
|
|
11514
11669
|
return null;
|
|
11515
11670
|
}
|
|
@@ -11518,15 +11673,15 @@ var memberValidationPolarity = (test, access) => {
|
|
|
11518
11673
|
}
|
|
11519
11674
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
11520
11675
|
}
|
|
11521
|
-
return test.type ===
|
|
11676
|
+
return test.type === import_utils61.AST_NODE_TYPES.CallExpression && test.arguments.length === 1 && test.arguments[0] !== void 0 && test.arguments[0].type !== import_utils61.AST_NODE_TYPES.SpreadElement && isSamePlainMember(test.arguments[0], access) && test.callee.type === import_utils61.AST_NODE_TYPES.MemberExpression && !test.callee.computed && test.callee.object.type === import_utils61.AST_NODE_TYPES.Identifier && test.callee.object.name === "Array" && test.callee.property.type === import_utils61.AST_NODE_TYPES.Identifier && test.callee.property.name === "isArray" ? "valid-when-true" : null;
|
|
11522
11677
|
};
|
|
11523
11678
|
var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
11524
11679
|
const isValidationReference = (identifier) => {
|
|
11525
11680
|
for (let current = identifier.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11526
|
-
if ((current.type ===
|
|
11681
|
+
if ((current.type === import_utils61.AST_NODE_TYPES.BinaryExpression || current.type === import_utils61.AST_NODE_TYPES.CallExpression || current.type === import_utils61.AST_NODE_TYPES.UnaryExpression) && bindingValidationPolarity(current, identifier.name) !== null) {
|
|
11527
11682
|
return true;
|
|
11528
11683
|
}
|
|
11529
|
-
if (current.type !==
|
|
11684
|
+
if (current.type !== import_utils61.AST_NODE_TYPES.UnaryExpression && current.type !== import_utils61.AST_NODE_TYPES.MemberExpression && current.type !== import_utils61.AST_NODE_TYPES.CallExpression) {
|
|
11530
11685
|
return false;
|
|
11531
11686
|
}
|
|
11532
11687
|
}
|
|
@@ -11534,7 +11689,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11534
11689
|
};
|
|
11535
11690
|
const isGuardedUse = (identifier) => {
|
|
11536
11691
|
for (let current = identifier.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11537
|
-
if (current.type ===
|
|
11692
|
+
if (current.type === import_utils61.AST_NODE_TYPES.ConditionalExpression) {
|
|
11538
11693
|
const polarity = bindingValidationPolarity(current.test, identifier.name);
|
|
11539
11694
|
if (polarity === "valid-when-true" && nodeWithin2(identifier, current.consequent)) {
|
|
11540
11695
|
return true;
|
|
@@ -11543,7 +11698,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11543
11698
|
return true;
|
|
11544
11699
|
}
|
|
11545
11700
|
}
|
|
11546
|
-
if (current.type ===
|
|
11701
|
+
if (current.type === import_utils61.AST_NODE_TYPES.IfStatement) {
|
|
11547
11702
|
const polarity = bindingValidationPolarity(current.test, identifier.name);
|
|
11548
11703
|
if (polarity === "valid-when-true" && nodeWithin2(identifier, current.consequent)) {
|
|
11549
11704
|
return true;
|
|
@@ -11552,14 +11707,14 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11552
11707
|
return true;
|
|
11553
11708
|
}
|
|
11554
11709
|
}
|
|
11555
|
-
if (current.type ===
|
|
11710
|
+
if (current.type === import_utils61.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils61.AST_NODE_TYPES.FunctionExpression || current.type === import_utils61.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
11556
11711
|
return false;
|
|
11557
11712
|
}
|
|
11558
11713
|
}
|
|
11559
11714
|
return false;
|
|
11560
11715
|
};
|
|
11561
11716
|
const declarator = member.parent;
|
|
11562
|
-
if (declarator.type !==
|
|
11717
|
+
if (declarator.type !== import_utils61.AST_NODE_TYPES.VariableDeclarator || declarator.init !== member || declarator.id.type !== import_utils61.AST_NODE_TYPES.Identifier || declarator.parent.type !== import_utils61.AST_NODE_TYPES.VariableDeclaration || declarator.parent.kind !== "const") {
|
|
11563
11718
|
return false;
|
|
11564
11719
|
}
|
|
11565
11720
|
const extracted = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
@@ -11567,7 +11722,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11567
11722
|
let hasValueUse = false;
|
|
11568
11723
|
for (const reference of extracted.references) {
|
|
11569
11724
|
const identifier = reference.identifier;
|
|
11570
|
-
if (identifier.type !==
|
|
11725
|
+
if (identifier.type !== import_utils61.AST_NODE_TYPES.Identifier) return false;
|
|
11571
11726
|
if (nodeWithin2(identifier, declarator)) continue;
|
|
11572
11727
|
if (isValidationReference(identifier)) continue;
|
|
11573
11728
|
hasValueUse = true;
|
|
@@ -11580,17 +11735,17 @@ var isGuardTestPosition = (node) => {
|
|
|
11580
11735
|
let parent = current.parent;
|
|
11581
11736
|
while (parent !== void 0 && parent !== null) {
|
|
11582
11737
|
switch (parent.type) {
|
|
11583
|
-
case
|
|
11584
|
-
case
|
|
11585
|
-
case
|
|
11738
|
+
case import_utils61.AST_NODE_TYPES.UnaryExpression:
|
|
11739
|
+
case import_utils61.AST_NODE_TYPES.LogicalExpression:
|
|
11740
|
+
case import_utils61.AST_NODE_TYPES.ChainExpression:
|
|
11586
11741
|
current = parent;
|
|
11587
11742
|
parent = parent.parent;
|
|
11588
11743
|
continue;
|
|
11589
|
-
case
|
|
11590
|
-
case
|
|
11591
|
-
case
|
|
11592
|
-
case
|
|
11593
|
-
case
|
|
11744
|
+
case import_utils61.AST_NODE_TYPES.IfStatement:
|
|
11745
|
+
case import_utils61.AST_NODE_TYPES.ConditionalExpression:
|
|
11746
|
+
case import_utils61.AST_NODE_TYPES.WhileStatement:
|
|
11747
|
+
case import_utils61.AST_NODE_TYPES.DoWhileStatement:
|
|
11748
|
+
case import_utils61.AST_NODE_TYPES.ForStatement:
|
|
11594
11749
|
return parent.test === current;
|
|
11595
11750
|
default:
|
|
11596
11751
|
return false;
|
|
@@ -11600,7 +11755,7 @@ var isGuardTestPosition = (node) => {
|
|
|
11600
11755
|
};
|
|
11601
11756
|
var unvalidatedVariableRef = (node, scope, tracked) => {
|
|
11602
11757
|
const unwrapped = unwrap4(node);
|
|
11603
|
-
if (unwrapped === null || unwrapped.type !==
|
|
11758
|
+
if (unwrapped === null || unwrapped.type !== import_utils61.AST_NODE_TYPES.Identifier) {
|
|
11604
11759
|
return null;
|
|
11605
11760
|
}
|
|
11606
11761
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -11629,7 +11784,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11629
11784
|
const localFileTextVariables = /* @__PURE__ */ new Set();
|
|
11630
11785
|
const localFileTextRef = (node, scope) => {
|
|
11631
11786
|
const unwrapped = unwrap4(node);
|
|
11632
|
-
if (unwrapped?.type !==
|
|
11787
|
+
if (unwrapped?.type !== import_utils61.AST_NODE_TYPES.Identifier) return null;
|
|
11633
11788
|
const variable = findVariable2(scope, unwrapped.name);
|
|
11634
11789
|
return variable !== null && localFileTextVariables.has(variable) ? variable : null;
|
|
11635
11790
|
};
|
|
@@ -11698,7 +11853,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11698
11853
|
return {
|
|
11699
11854
|
VariableDeclarator(node) {
|
|
11700
11855
|
const scope = context.sourceCode.getScope(node);
|
|
11701
|
-
if (node.id.type ===
|
|
11856
|
+
if (node.id.type === import_utils61.AST_NODE_TYPES.Identifier) {
|
|
11702
11857
|
const variable = context.sourceCode.getDeclaredVariables(node)[0];
|
|
11703
11858
|
if (variable !== void 0) {
|
|
11704
11859
|
updateLocalFileText(variable, node.init, scope);
|
|
@@ -11706,7 +11861,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11706
11861
|
trackInitializer(node, scope);
|
|
11707
11862
|
return;
|
|
11708
11863
|
}
|
|
11709
|
-
if (node.id.type ===
|
|
11864
|
+
if (node.id.type === import_utils61.AST_NODE_TYPES.ObjectPattern || node.id.type === import_utils61.AST_NODE_TYPES.ArrayPattern) {
|
|
11710
11865
|
if (isRawPayloadSource(
|
|
11711
11866
|
node.init,
|
|
11712
11867
|
(candidate) => localFileTextRef(candidate, scope) !== null
|
|
@@ -11723,7 +11878,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11723
11878
|
},
|
|
11724
11879
|
AssignmentExpression(node) {
|
|
11725
11880
|
const scope = context.sourceCode.getScope(node);
|
|
11726
|
-
if (node.left.type ===
|
|
11881
|
+
if (node.left.type === import_utils61.AST_NODE_TYPES.Identifier) {
|
|
11727
11882
|
const variable = findVariable2(scope, node.left.name);
|
|
11728
11883
|
if (variable === null) return;
|
|
11729
11884
|
const isLocalText = (candidate) => localFileTextRef(candidate, scope) !== null;
|
|
@@ -11737,7 +11892,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11737
11892
|
}
|
|
11738
11893
|
return;
|
|
11739
11894
|
}
|
|
11740
|
-
if (node.left.type ===
|
|
11895
|
+
if (node.left.type === import_utils61.AST_NODE_TYPES.ObjectPattern || node.left.type === import_utils61.AST_NODE_TYPES.ArrayPattern) {
|
|
11741
11896
|
if (isRawPayloadSource(
|
|
11742
11897
|
node.right,
|
|
11743
11898
|
(candidate) => localFileTextRef(candidate, scope) !== null
|
|
@@ -11757,15 +11912,15 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11757
11912
|
}
|
|
11758
11913
|
},
|
|
11759
11914
|
CallExpression(node) {
|
|
11760
|
-
if (node.callee.type !==
|
|
11915
|
+
if (node.callee.type !== import_utils61.AST_NODE_TYPES.Identifier) return;
|
|
11761
11916
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
11762
11917
|
return;
|
|
11763
11918
|
}
|
|
11764
11919
|
const scope = context.sourceCode.getScope(node);
|
|
11765
11920
|
for (const arg of node.arguments) {
|
|
11766
|
-
if (arg.type ===
|
|
11921
|
+
if (arg.type === import_utils61.AST_NODE_TYPES.SpreadElement) continue;
|
|
11767
11922
|
const unwrapped = unwrap4(arg);
|
|
11768
|
-
if (unwrapped === null || unwrapped.type !==
|
|
11923
|
+
if (unwrapped === null || unwrapped.type !== import_utils61.AST_NODE_TYPES.Identifier) {
|
|
11769
11924
|
continue;
|
|
11770
11925
|
}
|
|
11771
11926
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -11782,14 +11937,14 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11782
11937
|
(candidate) => localFileTextRef(candidate, scope) !== null
|
|
11783
11938
|
)) {
|
|
11784
11939
|
const parent = node.parent;
|
|
11785
|
-
if (parent.type ===
|
|
11940
|
+
if (parent.type === import_utils61.AST_NODE_TYPES.CallExpression && parent.callee === node && node.property.type === import_utils61.AST_NODE_TYPES.Identifier && (node.property.name === "parse" || node.property.name === "safeParse" || PROMISE_CHAIN_METHODS.has(node.property.name))) {
|
|
11786
11941
|
return;
|
|
11787
11942
|
}
|
|
11788
11943
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
11789
11944
|
return;
|
|
11790
11945
|
}
|
|
11791
|
-
const variable = obj?.type ===
|
|
11792
|
-
if (variable !== null && obj?.type ===
|
|
11946
|
+
const variable = obj?.type === import_utils61.AST_NODE_TYPES.Identifier ? unvalidatedVariableRef(obj, scope, unvalidatedVariables) : null;
|
|
11947
|
+
if (variable !== null && obj?.type === import_utils61.AST_NODE_TYPES.Identifier) {
|
|
11793
11948
|
if (isUseWithinValidatedBranch(node, obj.name)) {
|
|
11794
11949
|
return;
|
|
11795
11950
|
}
|
|
@@ -11809,7 +11964,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11809
11964
|
});
|
|
11810
11965
|
|
|
11811
11966
|
// src/rules/prefer-semantic-colors.ts
|
|
11812
|
-
var
|
|
11967
|
+
var import_utils62 = require("@typescript-eslint/utils");
|
|
11813
11968
|
var import_fs = require("fs");
|
|
11814
11969
|
var import_path = require("path");
|
|
11815
11970
|
|
|
@@ -11921,7 +12076,7 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
11921
12076
|
var isInsideSvg = (node) => {
|
|
11922
12077
|
let current = node.parent;
|
|
11923
12078
|
while (current !== void 0 && current !== null) {
|
|
11924
|
-
if (current.type ===
|
|
12079
|
+
if (current.type === import_utils62.AST_NODE_TYPES.JSXElement) {
|
|
11925
12080
|
const name = jsxElementName(current);
|
|
11926
12081
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
11927
12082
|
}
|
|
@@ -11931,8 +12086,8 @@ var isInsideSvg = (node) => {
|
|
|
11931
12086
|
};
|
|
11932
12087
|
function jsxElementName(node) {
|
|
11933
12088
|
const name = node.openingElement.name;
|
|
11934
|
-
if (name.type ===
|
|
11935
|
-
if (name.type ===
|
|
12089
|
+
if (name.type === import_utils62.AST_NODE_TYPES.JSXIdentifier) return name.name;
|
|
12090
|
+
if (name.type === import_utils62.AST_NODE_TYPES.JSXMemberExpression && name.property.type === import_utils62.AST_NODE_TYPES.JSXIdentifier) {
|
|
11936
12091
|
return name.property.name;
|
|
11937
12092
|
}
|
|
11938
12093
|
return null;
|
|
@@ -11958,7 +12113,7 @@ function isSvgLikeElementName(name) {
|
|
|
11958
12113
|
var isInsideIconFactoryPath = (node) => {
|
|
11959
12114
|
let current = node.parent;
|
|
11960
12115
|
while (current !== void 0 && current !== null) {
|
|
11961
|
-
if (current.type ===
|
|
12116
|
+
if (current.type === import_utils62.AST_NODE_TYPES.Property && propName(current.key) === "path" && current.parent.type === import_utils62.AST_NODE_TYPES.ObjectExpression && current.parent.parent.type === import_utils62.AST_NODE_TYPES.CallExpression && current.parent.parent.callee.type === import_utils62.AST_NODE_TYPES.Identifier && current.parent.parent.callee.name === "createIcon") {
|
|
11962
12117
|
return true;
|
|
11963
12118
|
}
|
|
11964
12119
|
current = current.parent;
|
|
@@ -12092,12 +12247,12 @@ var expandWorkspaceGlob = (root, glob) => {
|
|
|
12092
12247
|
return (0, import_fs.readdirSync)(parent, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => (0, import_path.join)(parent, entry.name));
|
|
12093
12248
|
};
|
|
12094
12249
|
var propName = (key) => {
|
|
12095
|
-
if (key.type ===
|
|
12096
|
-
if (key.type ===
|
|
12250
|
+
if (key.type === import_utils62.AST_NODE_TYPES.Identifier) return key.name;
|
|
12251
|
+
if (key.type === import_utils62.AST_NODE_TYPES.Literal && typeof key.value === "string") return key.value;
|
|
12097
12252
|
return null;
|
|
12098
12253
|
};
|
|
12099
12254
|
var staticallyImportsEmailOrPdfRenderer = (program) => program.body.some((statement) => {
|
|
12100
|
-
if (statement.type !==
|
|
12255
|
+
if (statement.type !== import_utils62.AST_NODE_TYPES.ImportDeclaration && statement.type !== import_utils62.AST_NODE_TYPES.ExportNamedDeclaration && statement.type !== import_utils62.AST_NODE_TYPES.ExportAllDeclaration) {
|
|
12101
12256
|
return false;
|
|
12102
12257
|
}
|
|
12103
12258
|
return statement.source !== null && typeof statement.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(statement.source.value);
|
|
@@ -12150,27 +12305,27 @@ var prefer_semantic_colors_default = createRule({
|
|
|
12150
12305
|
const checkClassNode = (node) => {
|
|
12151
12306
|
if (node === null) return;
|
|
12152
12307
|
switch (node.type) {
|
|
12153
|
-
case
|
|
12308
|
+
case import_utils62.AST_NODE_TYPES.Literal:
|
|
12154
12309
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
12155
12310
|
break;
|
|
12156
|
-
case
|
|
12311
|
+
case import_utils62.AST_NODE_TYPES.TemplateLiteral:
|
|
12157
12312
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
12158
12313
|
break;
|
|
12159
|
-
case
|
|
12314
|
+
case import_utils62.AST_NODE_TYPES.ArrayExpression:
|
|
12160
12315
|
for (const element of node.elements) {
|
|
12161
|
-
if (element !== null && element.type !==
|
|
12316
|
+
if (element !== null && element.type !== import_utils62.AST_NODE_TYPES.SpreadElement) checkClassNode(element);
|
|
12162
12317
|
}
|
|
12163
12318
|
break;
|
|
12164
|
-
case
|
|
12319
|
+
case import_utils62.AST_NODE_TYPES.ObjectExpression:
|
|
12165
12320
|
for (const property of node.properties) {
|
|
12166
|
-
if (property.type ===
|
|
12321
|
+
if (property.type === import_utils62.AST_NODE_TYPES.Property) checkClassNode(property.value);
|
|
12167
12322
|
}
|
|
12168
12323
|
break;
|
|
12169
|
-
case
|
|
12324
|
+
case import_utils62.AST_NODE_TYPES.ConditionalExpression:
|
|
12170
12325
|
checkClassNode(node.consequent);
|
|
12171
12326
|
checkClassNode(node.alternate);
|
|
12172
12327
|
break;
|
|
12173
|
-
case
|
|
12328
|
+
case import_utils62.AST_NODE_TYPES.LogicalExpression:
|
|
12174
12329
|
checkClassNode(node.right);
|
|
12175
12330
|
break;
|
|
12176
12331
|
default:
|
|
@@ -12178,32 +12333,32 @@ var prefer_semantic_colors_default = createRule({
|
|
|
12178
12333
|
}
|
|
12179
12334
|
};
|
|
12180
12335
|
const checkColorValueNode = (node) => {
|
|
12181
|
-
if (node.type ===
|
|
12336
|
+
if (node.type === import_utils62.AST_NODE_TYPES.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value) && !CSS_VAR_REFERENCE_RE.test(node.value)) {
|
|
12182
12337
|
report(node, "inlineColor", { value: node.value });
|
|
12183
12338
|
}
|
|
12184
12339
|
};
|
|
12185
12340
|
return {
|
|
12186
12341
|
"JSXAttribute[name.name='className']"(node) {
|
|
12187
12342
|
if (node.value === null) return;
|
|
12188
|
-
if (node.value.type ===
|
|
12189
|
-
else if (node.value.type ===
|
|
12190
|
-
if (node.value.expression.type !==
|
|
12343
|
+
if (node.value.type === import_utils62.AST_NODE_TYPES.Literal) checkClassNode(node.value);
|
|
12344
|
+
else if (node.value.type === import_utils62.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
12345
|
+
if (node.value.expression.type !== import_utils62.AST_NODE_TYPES.JSXEmptyExpression) {
|
|
12191
12346
|
checkClassNode(node.value.expression);
|
|
12192
12347
|
}
|
|
12193
12348
|
}
|
|
12194
12349
|
},
|
|
12195
12350
|
CallExpression(node) {
|
|
12196
|
-
if (node.callee.type ===
|
|
12351
|
+
if (node.callee.type === import_utils62.AST_NODE_TYPES.Identifier && node.callee.name === "require" && node.arguments[0]?.type === import_utils62.AST_NODE_TYPES.Literal && typeof node.arguments[0].value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.arguments[0].value)) {
|
|
12197
12352
|
importsEmailOrPdfRenderer = true;
|
|
12198
12353
|
}
|
|
12199
|
-
if (node.callee.type ===
|
|
12354
|
+
if (node.callee.type === import_utils62.AST_NODE_TYPES.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
12200
12355
|
for (const arg of node.arguments) {
|
|
12201
|
-
if (arg.type !==
|
|
12356
|
+
if (arg.type !== import_utils62.AST_NODE_TYPES.SpreadElement) checkClassNode(arg);
|
|
12202
12357
|
}
|
|
12203
12358
|
}
|
|
12204
12359
|
},
|
|
12205
12360
|
VariableDeclarator(node) {
|
|
12206
|
-
if (node.id.type ===
|
|
12361
|
+
if (node.id.type === import_utils62.AST_NODE_TYPES.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
12207
12362
|
checkClassNode(node.init);
|
|
12208
12363
|
}
|
|
12209
12364
|
},
|
|
@@ -12213,9 +12368,9 @@ var prefer_semantic_colors_default = createRule({
|
|
|
12213
12368
|
},
|
|
12214
12369
|
// SVG artwork colors are exempt; component presentation colors still report.
|
|
12215
12370
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
12216
|
-
if (node.value?.type !==
|
|
12371
|
+
if (node.value?.type !== import_utils62.AST_NODE_TYPES.Literal) return;
|
|
12217
12372
|
const owner = node.parent.name;
|
|
12218
|
-
if (owner.type ===
|
|
12373
|
+
if (owner.type === import_utils62.AST_NODE_TYPES.JSXIdentifier && SVG_SHAPE_PRIMITIVES.has(owner.name)) {
|
|
12219
12374
|
return;
|
|
12220
12375
|
}
|
|
12221
12376
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
@@ -12229,7 +12384,7 @@ var prefer_semantic_colors_default = createRule({
|
|
|
12229
12384
|
if (name !== null && STYLE_COLOR_PROPS.has(name)) checkColorValueNode(node.value);
|
|
12230
12385
|
},
|
|
12231
12386
|
ImportExpression(node) {
|
|
12232
|
-
if (node.source.type ===
|
|
12387
|
+
if (node.source.type === import_utils62.AST_NODE_TYPES.Literal && typeof node.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.source.value)) {
|
|
12233
12388
|
importsEmailOrPdfRenderer = true;
|
|
12234
12389
|
}
|
|
12235
12390
|
},
|
|
@@ -12242,7 +12397,7 @@ var prefer_semantic_colors_default = createRule({
|
|
|
12242
12397
|
});
|
|
12243
12398
|
|
|
12244
12399
|
// src/rules/prefer-server-actions.ts
|
|
12245
|
-
var
|
|
12400
|
+
var import_utils63 = require("@typescript-eslint/utils");
|
|
12246
12401
|
var preferServerActionsDocumentation = {
|
|
12247
12402
|
summary: "Prefer Next.js Server Actions over /api/* mutations.",
|
|
12248
12403
|
rationale: "Server Actions preserve typed application calls and avoid an internal JSON request-response boundary.",
|
|
@@ -12431,7 +12586,7 @@ var prefer_server_actions_default = createRule({
|
|
|
12431
12586
|
});
|
|
12432
12587
|
|
|
12433
12588
|
// src/rules/prefer-whole-object-assertion.ts
|
|
12434
|
-
var
|
|
12589
|
+
var import_utils64 = require("@typescript-eslint/utils");
|
|
12435
12590
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
12436
12591
|
var SYNTHETIC_LITERAL_MATCHERS = /* @__PURE__ */ new Map([
|
|
12437
12592
|
["toBeNull", "null"],
|
|
@@ -12456,11 +12611,11 @@ var preferWholeObjectAssertionDocumentation = {
|
|
|
12456
12611
|
};
|
|
12457
12612
|
function literalText(node, getText) {
|
|
12458
12613
|
switch (node.type) {
|
|
12459
|
-
case
|
|
12614
|
+
case import_utils64.AST_NODE_TYPES.Literal:
|
|
12460
12615
|
return "regex" in node ? null : getText(node);
|
|
12461
|
-
case
|
|
12616
|
+
case import_utils64.AST_NODE_TYPES.TemplateLiteral:
|
|
12462
12617
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
12463
|
-
case
|
|
12618
|
+
case import_utils64.AST_NODE_TYPES.UnaryExpression:
|
|
12464
12619
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
12465
12620
|
default:
|
|
12466
12621
|
return null;
|
|
@@ -12468,15 +12623,15 @@ function literalText(node, getText) {
|
|
|
12468
12623
|
}
|
|
12469
12624
|
function isPureReceiver(node) {
|
|
12470
12625
|
switch (node.type) {
|
|
12471
|
-
case
|
|
12472
|
-
case
|
|
12626
|
+
case import_utils64.AST_NODE_TYPES.Identifier:
|
|
12627
|
+
case import_utils64.AST_NODE_TYPES.ThisExpression:
|
|
12473
12628
|
return true;
|
|
12474
|
-
case
|
|
12629
|
+
case import_utils64.AST_NODE_TYPES.MemberExpression:
|
|
12475
12630
|
if (node.optional) {
|
|
12476
12631
|
return false;
|
|
12477
12632
|
}
|
|
12478
12633
|
if (node.computed) {
|
|
12479
|
-
return node.property.type ===
|
|
12634
|
+
return node.property.type === import_utils64.AST_NODE_TYPES.Literal && isPureReceiver(node.object);
|
|
12480
12635
|
}
|
|
12481
12636
|
return isPureReceiver(node.object);
|
|
12482
12637
|
default:
|
|
@@ -12484,11 +12639,21 @@ function isPureReceiver(node) {
|
|
|
12484
12639
|
}
|
|
12485
12640
|
}
|
|
12486
12641
|
function literalIndex(node) {
|
|
12487
|
-
if (node.type !==
|
|
12642
|
+
if (node.type !== import_utils64.AST_NODE_TYPES.Literal || typeof node.value !== "number") {
|
|
12488
12643
|
return null;
|
|
12489
12644
|
}
|
|
12490
12645
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
12491
12646
|
}
|
|
12647
|
+
function propertyAccess(node) {
|
|
12648
|
+
const path = [];
|
|
12649
|
+
let current = node;
|
|
12650
|
+
while (current.type === import_utils64.AST_NODE_TYPES.MemberExpression && !current.computed && !current.optional) {
|
|
12651
|
+
if (current.property.type !== import_utils64.AST_NODE_TYPES.Identifier || COLLECTION_PROPERTIES.has(current.property.name) || LITERAL_KEY_HAZARDS.has(current.property.name)) return null;
|
|
12652
|
+
path.unshift(current.property.name);
|
|
12653
|
+
current = current.object;
|
|
12654
|
+
}
|
|
12655
|
+
return path.length > 0 && isPureReceiver(current) ? { receiver: current, path } : null;
|
|
12656
|
+
}
|
|
12492
12657
|
var prefer_whole_object_assertion_default = createRule({
|
|
12493
12658
|
name: "prefer-whole-object-assertion",
|
|
12494
12659
|
documentation: preferWholeObjectAssertionDocumentation,
|
|
@@ -12511,57 +12676,59 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
12511
12676
|
}
|
|
12512
12677
|
const { sourceCode } = context;
|
|
12513
12678
|
function parseAssertion(statement) {
|
|
12514
|
-
if (statement.type !==
|
|
12679
|
+
if (statement.type !== import_utils64.AST_NODE_TYPES.ExpressionStatement) {
|
|
12515
12680
|
return null;
|
|
12516
12681
|
}
|
|
12517
12682
|
const call = statement.expression;
|
|
12518
|
-
if (call.type !==
|
|
12683
|
+
if (call.type !== import_utils64.AST_NODE_TYPES.CallExpression) {
|
|
12519
12684
|
return null;
|
|
12520
12685
|
}
|
|
12521
12686
|
const callee = call.callee;
|
|
12522
|
-
if (callee.type !==
|
|
12687
|
+
if (callee.type !== import_utils64.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils64.AST_NODE_TYPES.Identifier) {
|
|
12523
12688
|
return null;
|
|
12524
12689
|
}
|
|
12525
12690
|
const matcher = callee.property.name;
|
|
12526
12691
|
const expectCall = callee.object;
|
|
12527
|
-
if (expectCall.type !==
|
|
12692
|
+
if (expectCall.type !== import_utils64.AST_NODE_TYPES.CallExpression || expectCall.callee.type !== import_utils64.AST_NODE_TYPES.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
12528
12693
|
return null;
|
|
12529
12694
|
}
|
|
12530
12695
|
const actual = expectCall.arguments[0];
|
|
12531
|
-
if (actual === void 0 || actual.type !==
|
|
12696
|
+
if (actual === void 0 || actual.type !== import_utils64.AST_NODE_TYPES.MemberExpression || actual.optional) {
|
|
12532
12697
|
return null;
|
|
12533
12698
|
}
|
|
12534
12699
|
if (!isPureReceiver(actual.object)) {
|
|
12535
12700
|
return null;
|
|
12536
12701
|
}
|
|
12537
12702
|
let key;
|
|
12703
|
+
let receiver;
|
|
12538
12704
|
if (actual.computed) {
|
|
12539
12705
|
const index = literalIndex(actual.property);
|
|
12540
12706
|
if (index === null) {
|
|
12541
12707
|
return null;
|
|
12542
12708
|
}
|
|
12543
12709
|
key = { kind: "index", index };
|
|
12710
|
+
receiver = actual.object;
|
|
12544
12711
|
} else {
|
|
12545
|
-
|
|
12546
|
-
|
|
12547
|
-
}
|
|
12548
|
-
|
|
12712
|
+
const access = propertyAccess(actual);
|
|
12713
|
+
if (access === null) return null;
|
|
12714
|
+
key = { kind: "property", path: access.path };
|
|
12715
|
+
receiver = access.receiver;
|
|
12549
12716
|
}
|
|
12550
12717
|
const synthetic = SYNTHETIC_LITERAL_MATCHERS.get(matcher);
|
|
12551
12718
|
if (synthetic !== void 0 && call.arguments.length === 0) {
|
|
12552
|
-
return { statement, receiver
|
|
12719
|
+
return { statement, receiver, key, matcher, expectedText: synthetic, expectedIsLiteral: true };
|
|
12553
12720
|
}
|
|
12554
12721
|
if (!MERGEABLE_MATCHERS.has(matcher)) {
|
|
12555
12722
|
return null;
|
|
12556
12723
|
}
|
|
12557
12724
|
const expected = call.arguments[0];
|
|
12558
|
-
if (call.arguments.length !== 1 || expected === void 0 || expected.type ===
|
|
12725
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === import_utils64.AST_NODE_TYPES.SpreadElement) {
|
|
12559
12726
|
return null;
|
|
12560
12727
|
}
|
|
12561
12728
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
12562
12729
|
return {
|
|
12563
12730
|
statement,
|
|
12564
|
-
receiver
|
|
12731
|
+
receiver,
|
|
12565
12732
|
key,
|
|
12566
12733
|
matcher,
|
|
12567
12734
|
expectedText: literal ?? sourceCode.getText(expected),
|
|
@@ -12574,7 +12741,8 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
12574
12741
|
);
|
|
12575
12742
|
}
|
|
12576
12743
|
function reportPropertyRun(run) {
|
|
12577
|
-
const
|
|
12744
|
+
const tree = /* @__PURE__ */ new Map();
|
|
12745
|
+
const paths = [];
|
|
12578
12746
|
for (const assertion of run) {
|
|
12579
12747
|
if (assertion.key.kind !== "property" || !assertion.expectedIsLiteral) {
|
|
12580
12748
|
return;
|
|
@@ -12582,19 +12750,44 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
12582
12750
|
if (!MERGEABLE_MATCHERS.has(assertion.matcher) && !SYNTHETIC_LITERAL_MATCHERS.has(assertion.matcher)) {
|
|
12583
12751
|
return;
|
|
12584
12752
|
}
|
|
12585
|
-
|
|
12586
|
-
|
|
12753
|
+
paths.push([...assertion.key.path]);
|
|
12754
|
+
}
|
|
12755
|
+
const commonPrefix = [];
|
|
12756
|
+
for (let index = 0; ; index += 1) {
|
|
12757
|
+
const candidate = paths[0]?.[index];
|
|
12758
|
+
if (candidate === void 0 || paths.some((path) => path[index] !== candidate || path.length === index + 1)) {
|
|
12759
|
+
break;
|
|
12760
|
+
}
|
|
12761
|
+
commonPrefix.push(candidate);
|
|
12762
|
+
}
|
|
12763
|
+
for (const [assertionIndex, assertion] of run.entries()) {
|
|
12764
|
+
if (assertion.key.kind !== "property") return;
|
|
12765
|
+
let branch = tree;
|
|
12766
|
+
const relativePath = paths[assertionIndex]?.slice(commonPrefix.length) ?? [];
|
|
12767
|
+
for (const [index, name] of relativePath.entries()) {
|
|
12768
|
+
const leaf = index === relativePath.length - 1;
|
|
12769
|
+
const existing = branch.get(name);
|
|
12770
|
+
if (leaf) {
|
|
12771
|
+
if (existing !== void 0) return;
|
|
12772
|
+
branch.set(name, assertion.expectedText);
|
|
12773
|
+
} else if (existing === void 0) {
|
|
12774
|
+
const nested = /* @__PURE__ */ new Map();
|
|
12775
|
+
branch.set(name, nested);
|
|
12776
|
+
branch = nested;
|
|
12777
|
+
} else if (existing instanceof Map) {
|
|
12778
|
+
branch = existing;
|
|
12779
|
+
} else {
|
|
12780
|
+
return;
|
|
12781
|
+
}
|
|
12587
12782
|
}
|
|
12588
|
-
names.add(assertion.key.name);
|
|
12589
12783
|
}
|
|
12590
12784
|
const first = run[0];
|
|
12591
12785
|
if (first === void 0) {
|
|
12592
12786
|
return;
|
|
12593
12787
|
}
|
|
12594
|
-
const receiverText = sourceCode.getText(first.receiver)
|
|
12595
|
-
const
|
|
12596
|
-
|
|
12597
|
-
).join(", ");
|
|
12788
|
+
const receiverText = `${sourceCode.getText(first.receiver)}${commonPrefix.map((name) => `.${name}`).join("")}`;
|
|
12789
|
+
const renderTree = (value) => [...value.entries()].map(([name, child]) => `${name}: ${child instanceof Map ? `{ ${renderTree(child)} }` : child}`).join(", ");
|
|
12790
|
+
const properties = renderTree(tree);
|
|
12598
12791
|
context.report({
|
|
12599
12792
|
node: first.statement,
|
|
12600
12793
|
messageId: "combineAssertions",
|
|
@@ -12670,7 +12863,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
12670
12863
|
});
|
|
12671
12864
|
|
|
12672
12865
|
// src/rules/repeated-static-call-cases.ts
|
|
12673
|
-
var
|
|
12866
|
+
var import_utils65 = require("@typescript-eslint/utils");
|
|
12674
12867
|
var repeatedStaticCallCasesDocumentation = {
|
|
12675
12868
|
summary: "Report three or more consecutive literal call assertions that should be independently named test cases.",
|
|
12676
12869
|
rationale: "Copy-pasted cases obscure the input table and stop later cases from being reported after the first failure.",
|
|
@@ -12691,67 +12884,67 @@ var EXPECT_MODIFIERS = /* @__PURE__ */ new Set(["not", "rejects", "resolves"]);
|
|
|
12691
12884
|
var SNAPSHOT_MATCHERS = /snapshot/iu;
|
|
12692
12885
|
var MIN_CASES2 = 3;
|
|
12693
12886
|
function staticMemberName5(node) {
|
|
12694
|
-
if (!node.computed && node.property.type ===
|
|
12695
|
-
if (node.computed && node.property.type ===
|
|
12887
|
+
if (!node.computed && node.property.type === import_utils65.AST_NODE_TYPES.Identifier) return node.property.name;
|
|
12888
|
+
if (node.computed && node.property.type === import_utils65.AST_NODE_TYPES.Literal && typeof node.property.value === "string") return node.property.value;
|
|
12696
12889
|
return null;
|
|
12697
12890
|
}
|
|
12698
12891
|
function importedName3(identifier, context, modules) {
|
|
12699
|
-
const variable =
|
|
12892
|
+
const variable = import_utils65.ASTUtils.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
12700
12893
|
if (variable === null || variable.defs.length === 0) return identifier.name;
|
|
12701
12894
|
for (const definition of variable.defs) {
|
|
12702
|
-
if (definition.node.type !==
|
|
12895
|
+
if (definition.node.type !== import_utils65.AST_NODE_TYPES.ImportSpecifier) continue;
|
|
12703
12896
|
const declaration = definition.node.parent;
|
|
12704
|
-
if (declaration.type !==
|
|
12897
|
+
if (declaration.type !== import_utils65.AST_NODE_TYPES.ImportDeclaration || typeof declaration.source.value !== "string" || !modules.has(declaration.source.value)) continue;
|
|
12705
12898
|
const imported = definition.node.imported;
|
|
12706
|
-
return imported.type ===
|
|
12899
|
+
return imported.type === import_utils65.AST_NODE_TYPES.Identifier ? imported.name : String(imported.value);
|
|
12707
12900
|
}
|
|
12708
12901
|
return null;
|
|
12709
12902
|
}
|
|
12710
12903
|
function isDirectTestCallback2(node, context) {
|
|
12711
|
-
if (node.type !==
|
|
12904
|
+
if (node.type !== import_utils65.AST_NODE_TYPES.ArrowFunctionExpression && node.type !== import_utils65.AST_NODE_TYPES.FunctionExpression) return false;
|
|
12712
12905
|
const call = node.parent;
|
|
12713
|
-
if (call?.type !==
|
|
12906
|
+
if (call?.type !== import_utils65.AST_NODE_TYPES.CallExpression || !call.arguments.includes(node)) return false;
|
|
12714
12907
|
const root = testRoot2(call.callee);
|
|
12715
12908
|
return root !== null && TEST_NAMES2.has(importedName3(root, context, TEST_MODULES4) ?? "");
|
|
12716
12909
|
}
|
|
12717
12910
|
function testRoot2(callee) {
|
|
12718
|
-
if (callee.type ===
|
|
12719
|
-
if (callee.type !==
|
|
12911
|
+
if (callee.type === import_utils65.AST_NODE_TYPES.Identifier) return callee;
|
|
12912
|
+
if (callee.type !== import_utils65.AST_NODE_TYPES.MemberExpression) return null;
|
|
12720
12913
|
const modifier = staticMemberName5(callee);
|
|
12721
12914
|
return modifier !== null && TEST_MODIFIERS4.has(modifier) ? testRoot2(callee.object) : null;
|
|
12722
12915
|
}
|
|
12723
12916
|
function isStatic(node) {
|
|
12724
|
-
if (node.type ===
|
|
12917
|
+
if (node.type === import_utils65.AST_NODE_TYPES.TSAsExpression || node.type === import_utils65.AST_NODE_TYPES.TSTypeAssertion || node.type === import_utils65.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils65.AST_NODE_TYPES.TSNonNullExpression) return isStatic(node.expression);
|
|
12725
12918
|
switch (node.type) {
|
|
12726
|
-
case
|
|
12919
|
+
case import_utils65.AST_NODE_TYPES.Literal:
|
|
12727
12920
|
return true;
|
|
12728
|
-
case
|
|
12921
|
+
case import_utils65.AST_NODE_TYPES.TemplateLiteral:
|
|
12729
12922
|
return node.expressions.length === 0;
|
|
12730
|
-
case
|
|
12923
|
+
case import_utils65.AST_NODE_TYPES.UnaryExpression:
|
|
12731
12924
|
return (node.operator === "+" || node.operator === "-") && isStatic(node.argument);
|
|
12732
|
-
case
|
|
12733
|
-
return node.elements.every((item) => item !== null && item.type !==
|
|
12734
|
-
case
|
|
12735
|
-
return node.properties.every((property) => property.type ===
|
|
12925
|
+
case import_utils65.AST_NODE_TYPES.ArrayExpression:
|
|
12926
|
+
return node.elements.every((item) => item !== null && item.type !== import_utils65.AST_NODE_TYPES.SpreadElement && isStatic(item));
|
|
12927
|
+
case import_utils65.AST_NODE_TYPES.ObjectExpression:
|
|
12928
|
+
return node.properties.every((property) => property.type === import_utils65.AST_NODE_TYPES.Property && !property.computed && property.kind === "init" && property.value.type !== import_utils65.AST_NODE_TYPES.AssignmentPattern && isStatic(property.value));
|
|
12736
12929
|
default:
|
|
12737
12930
|
return false;
|
|
12738
12931
|
}
|
|
12739
12932
|
}
|
|
12740
12933
|
function staticShape(node) {
|
|
12741
|
-
if (node.type ===
|
|
12934
|
+
if (node.type === import_utils65.AST_NODE_TYPES.TSAsExpression || node.type === import_utils65.AST_NODE_TYPES.TSTypeAssertion || node.type === import_utils65.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils65.AST_NODE_TYPES.TSNonNullExpression) return staticShape(node.expression);
|
|
12742
12935
|
switch (node.type) {
|
|
12743
|
-
case
|
|
12936
|
+
case import_utils65.AST_NODE_TYPES.Literal:
|
|
12744
12937
|
return `literal:${typeof node.value}`;
|
|
12745
|
-
case
|
|
12938
|
+
case import_utils65.AST_NODE_TYPES.TemplateLiteral:
|
|
12746
12939
|
return "template";
|
|
12747
|
-
case
|
|
12940
|
+
case import_utils65.AST_NODE_TYPES.UnaryExpression:
|
|
12748
12941
|
return `unary:${node.operator}:${staticShape(node.argument)}`;
|
|
12749
|
-
case
|
|
12750
|
-
return `array(${node.elements.map((item) => item === null || item.type ===
|
|
12751
|
-
case
|
|
12942
|
+
case import_utils65.AST_NODE_TYPES.ArrayExpression:
|
|
12943
|
+
return `array(${node.elements.map((item) => item === null || item.type === import_utils65.AST_NODE_TYPES.SpreadElement ? "invalid" : staticShape(item)).join(",")})`;
|
|
12944
|
+
case import_utils65.AST_NODE_TYPES.ObjectExpression:
|
|
12752
12945
|
return `object(${node.properties.map((property) => {
|
|
12753
|
-
if (property.type !==
|
|
12754
|
-
const key = property.key.type ===
|
|
12946
|
+
if (property.type !== import_utils65.AST_NODE_TYPES.Property || property.computed || property.value.type === import_utils65.AST_NODE_TYPES.AssignmentPattern) return "invalid";
|
|
12947
|
+
const key = property.key.type === import_utils65.AST_NODE_TYPES.Identifier ? property.key.name : String(property.key.value);
|
|
12755
12948
|
return `${key}:${staticShape(property.value)}`;
|
|
12756
12949
|
}).join(",")})`;
|
|
12757
12950
|
default:
|
|
@@ -12759,16 +12952,16 @@ function staticShape(node) {
|
|
|
12759
12952
|
}
|
|
12760
12953
|
}
|
|
12761
12954
|
function assertionShape(statement, context) {
|
|
12762
|
-
if (statement.type !==
|
|
12955
|
+
if (statement.type !== import_utils65.AST_NODE_TYPES.ExpressionStatement || statement.expression.type !== import_utils65.AST_NODE_TYPES.CallExpression) return null;
|
|
12763
12956
|
const matcherCall = statement.expression;
|
|
12764
|
-
if (matcherCall.callee.type !==
|
|
12957
|
+
if (matcherCall.callee.type !== import_utils65.AST_NODE_TYPES.MemberExpression || matcherCall.callee.computed || matcherCall.callee.property.type !== import_utils65.AST_NODE_TYPES.Identifier || matcherCall.arguments.length !== 1) return null;
|
|
12765
12958
|
const matcher = matcherCall.callee.property.name;
|
|
12766
12959
|
if (SNAPSHOT_MATCHERS.test(matcher)) return null;
|
|
12767
12960
|
const chain = expectCallFromMatcher(matcherCall.callee);
|
|
12768
|
-
if (chain === null || chain.call.callee.type !==
|
|
12961
|
+
if (chain === null || chain.call.callee.type !== import_utils65.AST_NODE_TYPES.Identifier || importedName3(chain.call.callee, context, ASSERTION_MODULES3) !== "expect" || chain.call.arguments.length !== 1) return null;
|
|
12769
12962
|
const observed = chain.call.arguments[0];
|
|
12770
12963
|
const expected = matcherCall.arguments[0];
|
|
12771
|
-
if (observed?.type !==
|
|
12964
|
+
if (observed?.type !== import_utils65.AST_NODE_TYPES.CallExpression || observed.callee.type !== import_utils65.AST_NODE_TYPES.Identifier || observed.arguments.length === 0 || observed.arguments.some((arg) => arg.type === import_utils65.AST_NODE_TYPES.SpreadElement || !isStatic(arg)) || expected?.type === import_utils65.AST_NODE_TYPES.SpreadElement || expected === void 0 || !isStatic(expected)) return null;
|
|
12772
12965
|
const skeleton = `${observed.callee.name}/${observed.arguments.map((item) => staticShape(item)).join(",")}/${chain.modifiers.join(".")}/${matcher}/${staticShape(expected)}`;
|
|
12773
12966
|
const values = [...observed.arguments, expected].map((item) => context.sourceCode.getText(item)).join("\0");
|
|
12774
12967
|
return { statement, skeleton, values };
|
|
@@ -12776,13 +12969,13 @@ function assertionShape(statement, context) {
|
|
|
12776
12969
|
function expectCallFromMatcher(node) {
|
|
12777
12970
|
const modifiers = [];
|
|
12778
12971
|
let receiver = node.object;
|
|
12779
|
-
while (receiver.type ===
|
|
12972
|
+
while (receiver.type === import_utils65.AST_NODE_TYPES.MemberExpression) {
|
|
12780
12973
|
const modifier = staticMemberName5(receiver);
|
|
12781
12974
|
if (modifier === null || !EXPECT_MODIFIERS.has(modifier)) return null;
|
|
12782
12975
|
modifiers.unshift(modifier);
|
|
12783
12976
|
receiver = receiver.object;
|
|
12784
12977
|
}
|
|
12785
|
-
return receiver.type ===
|
|
12978
|
+
return receiver.type === import_utils65.AST_NODE_TYPES.CallExpression ? { call: receiver, modifiers } : null;
|
|
12786
12979
|
}
|
|
12787
12980
|
var repeated_static_call_cases_default = createRule({
|
|
12788
12981
|
name: "repeated-static-call-cases",
|
|
@@ -12802,7 +12995,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
12802
12995
|
return {
|
|
12803
12996
|
"CallExpression > ArrowFunctionExpression, CallExpression > FunctionExpression"(node) {
|
|
12804
12997
|
const call = node.parent;
|
|
12805
|
-
if (call?.type ===
|
|
12998
|
+
if (call?.type === import_utils65.AST_NODE_TYPES.CallExpression) {
|
|
12806
12999
|
const duplicate = duplicateTestBodyCandidate(call, sourceCode);
|
|
12807
13000
|
if (duplicate !== null && duplicate.body === node) {
|
|
12808
13001
|
const groups = duplicateGroups.get(duplicate.container) ?? /* @__PURE__ */ new Map();
|
|
@@ -12812,7 +13005,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
12812
13005
|
duplicateGroups.set(duplicate.container, groups);
|
|
12813
13006
|
}
|
|
12814
13007
|
}
|
|
12815
|
-
if (!isDirectTestCallback2(node, context) || node.body.type !==
|
|
13008
|
+
if (!isDirectTestCallback2(node, context) || node.body.type !== import_utils65.AST_NODE_TYPES.BlockStatement) return;
|
|
12816
13009
|
let run = [];
|
|
12817
13010
|
const flush = () => {
|
|
12818
13011
|
if (run.length >= MIN_CASES2 && new Set(run.map((item) => item.values)).size > 1) {
|
|
@@ -12853,7 +13046,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
12853
13046
|
});
|
|
12854
13047
|
|
|
12855
13048
|
// src/rules/prefer-zod-infer.ts
|
|
12856
|
-
var
|
|
13049
|
+
var import_utils66 = require("@typescript-eslint/utils");
|
|
12857
13050
|
var preferZodInferDocumentation = {
|
|
12858
13051
|
summary: "Derive a type from its Zod schema with `z.infer` instead of hand-writing a twin declaration beside it.",
|
|
12859
13052
|
rationale: "A derived type stays synchronized when the runtime schema changes.",
|
|
@@ -12906,47 +13099,47 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
12906
13099
|
"Schema"
|
|
12907
13100
|
]);
|
|
12908
13101
|
var LEAF_NODE_TYPES = {
|
|
12909
|
-
string: [
|
|
12910
|
-
email: [
|
|
12911
|
-
url: [
|
|
12912
|
-
uuid: [
|
|
12913
|
-
ulid: [
|
|
12914
|
-
cuid: [
|
|
12915
|
-
cuid2: [
|
|
12916
|
-
nanoid: [
|
|
12917
|
-
iso: [
|
|
12918
|
-
number: [
|
|
12919
|
-
int: [
|
|
12920
|
-
float32: [
|
|
12921
|
-
float64: [
|
|
12922
|
-
boolean: [
|
|
12923
|
-
bigint: [
|
|
12924
|
-
symbol: [
|
|
12925
|
-
any: [
|
|
12926
|
-
unknown: [
|
|
12927
|
-
never: [
|
|
12928
|
-
void: [
|
|
12929
|
-
null: [
|
|
12930
|
-
undefined: [
|
|
12931
|
-
literal: [
|
|
12932
|
-
date: [
|
|
12933
|
-
array: [
|
|
12934
|
-
tuple: [
|
|
12935
|
-
object: [
|
|
12936
|
-
strictObject: [
|
|
12937
|
-
looseObject: [
|
|
12938
|
-
record: [
|
|
12939
|
-
map: [
|
|
12940
|
-
set: [
|
|
12941
|
-
promise: [
|
|
12942
|
-
enum: [
|
|
12943
|
-
nativeEnum: [
|
|
12944
|
-
union: [
|
|
12945
|
-
discriminatedUnion: [
|
|
12946
|
-
intersection: [
|
|
13102
|
+
string: [import_utils66.AST_NODE_TYPES.TSStringKeyword],
|
|
13103
|
+
email: [import_utils66.AST_NODE_TYPES.TSStringKeyword],
|
|
13104
|
+
url: [import_utils66.AST_NODE_TYPES.TSStringKeyword],
|
|
13105
|
+
uuid: [import_utils66.AST_NODE_TYPES.TSStringKeyword],
|
|
13106
|
+
ulid: [import_utils66.AST_NODE_TYPES.TSStringKeyword],
|
|
13107
|
+
cuid: [import_utils66.AST_NODE_TYPES.TSStringKeyword],
|
|
13108
|
+
cuid2: [import_utils66.AST_NODE_TYPES.TSStringKeyword],
|
|
13109
|
+
nanoid: [import_utils66.AST_NODE_TYPES.TSStringKeyword],
|
|
13110
|
+
iso: [import_utils66.AST_NODE_TYPES.TSStringKeyword],
|
|
13111
|
+
number: [import_utils66.AST_NODE_TYPES.TSNumberKeyword],
|
|
13112
|
+
int: [import_utils66.AST_NODE_TYPES.TSNumberKeyword],
|
|
13113
|
+
float32: [import_utils66.AST_NODE_TYPES.TSNumberKeyword],
|
|
13114
|
+
float64: [import_utils66.AST_NODE_TYPES.TSNumberKeyword],
|
|
13115
|
+
boolean: [import_utils66.AST_NODE_TYPES.TSBooleanKeyword],
|
|
13116
|
+
bigint: [import_utils66.AST_NODE_TYPES.TSBigIntKeyword],
|
|
13117
|
+
symbol: [import_utils66.AST_NODE_TYPES.TSSymbolKeyword],
|
|
13118
|
+
any: [import_utils66.AST_NODE_TYPES.TSAnyKeyword],
|
|
13119
|
+
unknown: [import_utils66.AST_NODE_TYPES.TSUnknownKeyword],
|
|
13120
|
+
never: [import_utils66.AST_NODE_TYPES.TSNeverKeyword],
|
|
13121
|
+
void: [import_utils66.AST_NODE_TYPES.TSVoidKeyword],
|
|
13122
|
+
null: [import_utils66.AST_NODE_TYPES.TSNullKeyword],
|
|
13123
|
+
undefined: [import_utils66.AST_NODE_TYPES.TSUndefinedKeyword],
|
|
13124
|
+
literal: [import_utils66.AST_NODE_TYPES.TSLiteralType],
|
|
13125
|
+
date: [import_utils66.AST_NODE_TYPES.TSTypeReference],
|
|
13126
|
+
array: [import_utils66.AST_NODE_TYPES.TSArrayType, import_utils66.AST_NODE_TYPES.TSTypeReference],
|
|
13127
|
+
tuple: [import_utils66.AST_NODE_TYPES.TSTupleType],
|
|
13128
|
+
object: [import_utils66.AST_NODE_TYPES.TSTypeLiteral, import_utils66.AST_NODE_TYPES.TSTypeReference],
|
|
13129
|
+
strictObject: [import_utils66.AST_NODE_TYPES.TSTypeLiteral, import_utils66.AST_NODE_TYPES.TSTypeReference],
|
|
13130
|
+
looseObject: [import_utils66.AST_NODE_TYPES.TSTypeLiteral, import_utils66.AST_NODE_TYPES.TSTypeReference],
|
|
13131
|
+
record: [import_utils66.AST_NODE_TYPES.TSTypeReference, import_utils66.AST_NODE_TYPES.TSTypeLiteral],
|
|
13132
|
+
map: [import_utils66.AST_NODE_TYPES.TSTypeReference],
|
|
13133
|
+
set: [import_utils66.AST_NODE_TYPES.TSTypeReference],
|
|
13134
|
+
promise: [import_utils66.AST_NODE_TYPES.TSTypeReference],
|
|
13135
|
+
enum: [import_utils66.AST_NODE_TYPES.TSUnionType, import_utils66.AST_NODE_TYPES.TSTypeReference, import_utils66.AST_NODE_TYPES.TSLiteralType],
|
|
13136
|
+
nativeEnum: [import_utils66.AST_NODE_TYPES.TSUnionType, import_utils66.AST_NODE_TYPES.TSTypeReference, import_utils66.AST_NODE_TYPES.TSLiteralType],
|
|
13137
|
+
union: [import_utils66.AST_NODE_TYPES.TSUnionType, import_utils66.AST_NODE_TYPES.TSTypeReference],
|
|
13138
|
+
discriminatedUnion: [import_utils66.AST_NODE_TYPES.TSUnionType, import_utils66.AST_NODE_TYPES.TSTypeReference],
|
|
13139
|
+
intersection: [import_utils66.AST_NODE_TYPES.TSIntersectionType, import_utils66.AST_NODE_TYPES.TSTypeReference]
|
|
12947
13140
|
};
|
|
12948
13141
|
function primitiveLiteralKey(node) {
|
|
12949
|
-
if (node.type !==
|
|
13142
|
+
if (node.type !== import_utils66.AST_NODE_TYPES.Literal) {
|
|
12950
13143
|
return null;
|
|
12951
13144
|
}
|
|
12952
13145
|
if (node.value === null) {
|
|
@@ -12978,13 +13171,13 @@ function staticZodDomain(leaf, call) {
|
|
|
12978
13171
|
}
|
|
12979
13172
|
if (leaf === "literal") {
|
|
12980
13173
|
const [argument] = call.arguments;
|
|
12981
|
-
if (argument === void 0 || argument.type ===
|
|
13174
|
+
if (argument === void 0 || argument.type === import_utils66.AST_NODE_TYPES.SpreadElement) {
|
|
12982
13175
|
return null;
|
|
12983
13176
|
}
|
|
12984
|
-
if (argument.type ===
|
|
13177
|
+
if (argument.type === import_utils66.AST_NODE_TYPES.ArrayExpression) {
|
|
12985
13178
|
return exactDomain(
|
|
12986
13179
|
argument.elements.map(
|
|
12987
|
-
(element) => element === null || element.type ===
|
|
13180
|
+
(element) => element === null || element.type === import_utils66.AST_NODE_TYPES.SpreadElement ? null : primitiveLiteralKey(element)
|
|
12988
13181
|
)
|
|
12989
13182
|
);
|
|
12990
13183
|
}
|
|
@@ -12992,13 +13185,13 @@ function staticZodDomain(leaf, call) {
|
|
|
12992
13185
|
}
|
|
12993
13186
|
if (leaf === "enum") {
|
|
12994
13187
|
const [argument] = call.arguments;
|
|
12995
|
-
if (argument === void 0 || argument.type ===
|
|
13188
|
+
if (argument === void 0 || argument.type === import_utils66.AST_NODE_TYPES.SpreadElement) {
|
|
12996
13189
|
return null;
|
|
12997
13190
|
}
|
|
12998
|
-
if (argument.type ===
|
|
13191
|
+
if (argument.type === import_utils66.AST_NODE_TYPES.ArrayExpression) {
|
|
12999
13192
|
return exactDomain(
|
|
13000
13193
|
argument.elements.map((element) => {
|
|
13001
|
-
if (element === null || element.type ===
|
|
13194
|
+
if (element === null || element.type === import_utils66.AST_NODE_TYPES.SpreadElement) {
|
|
13002
13195
|
return null;
|
|
13003
13196
|
}
|
|
13004
13197
|
const key = primitiveLiteralKey(element);
|
|
@@ -13006,10 +13199,10 @@ function staticZodDomain(leaf, call) {
|
|
|
13006
13199
|
})
|
|
13007
13200
|
);
|
|
13008
13201
|
}
|
|
13009
|
-
if (argument.type ===
|
|
13202
|
+
if (argument.type === import_utils66.AST_NODE_TYPES.ObjectExpression) {
|
|
13010
13203
|
return exactDomain(
|
|
13011
13204
|
argument.properties.map((property) => {
|
|
13012
|
-
if (property.type !==
|
|
13205
|
+
if (property.type !== import_utils66.AST_NODE_TYPES.Property || property.computed || property.kind !== "init" || property.method || property.shorthand) {
|
|
13013
13206
|
return null;
|
|
13014
13207
|
}
|
|
13015
13208
|
const key = primitiveLiteralKey(property.value);
|
|
@@ -13036,15 +13229,15 @@ function sameDomain(left, right) {
|
|
|
13036
13229
|
return true;
|
|
13037
13230
|
}
|
|
13038
13231
|
function isExportedDeclaration(node) {
|
|
13039
|
-
return node.parent?.type ===
|
|
13232
|
+
return node.parent?.type === import_utils66.AST_NODE_TYPES.ExportNamedDeclaration;
|
|
13040
13233
|
}
|
|
13041
13234
|
function isModuleLevelConst(node) {
|
|
13042
13235
|
const declaration = node.parent;
|
|
13043
|
-
if (declaration.type !==
|
|
13236
|
+
if (declaration.type !== import_utils66.AST_NODE_TYPES.VariableDeclaration || declaration.kind !== "const") {
|
|
13044
13237
|
return false;
|
|
13045
13238
|
}
|
|
13046
13239
|
const container = declaration.parent;
|
|
13047
|
-
return container.type ===
|
|
13240
|
+
return container.type === import_utils66.AST_NODE_TYPES.Program || container.type === import_utils66.AST_NODE_TYPES.ExportNamedDeclaration && container.parent.type === import_utils66.AST_NODE_TYPES.Program;
|
|
13048
13241
|
}
|
|
13049
13242
|
function normalizeSchemaName(name) {
|
|
13050
13243
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -13053,20 +13246,20 @@ function normalizeTypeName(name) {
|
|
|
13053
13246
|
return name.replace(/Type$/, "").toLowerCase();
|
|
13054
13247
|
}
|
|
13055
13248
|
function unwrapNullish(annotation) {
|
|
13056
|
-
if (annotation.type !==
|
|
13249
|
+
if (annotation.type !== import_utils66.AST_NODE_TYPES.TSUnionType) {
|
|
13057
13250
|
return {
|
|
13058
13251
|
core: annotation,
|
|
13059
|
-
nullable: annotation.type ===
|
|
13252
|
+
nullable: annotation.type === import_utils66.AST_NODE_TYPES.TSNullKeyword
|
|
13060
13253
|
};
|
|
13061
13254
|
}
|
|
13062
13255
|
const rest = [];
|
|
13063
13256
|
let nullable = false;
|
|
13064
13257
|
for (const member of annotation.types) {
|
|
13065
|
-
if (member.type ===
|
|
13258
|
+
if (member.type === import_utils66.AST_NODE_TYPES.TSNullKeyword) {
|
|
13066
13259
|
nullable = true;
|
|
13067
13260
|
continue;
|
|
13068
13261
|
}
|
|
13069
|
-
if (member.type ===
|
|
13262
|
+
if (member.type === import_utils66.AST_NODE_TYPES.TSUndefinedKeyword) {
|
|
13070
13263
|
continue;
|
|
13071
13264
|
}
|
|
13072
13265
|
rest.push(member);
|
|
@@ -13100,18 +13293,18 @@ function leafAgrees(field, annotation) {
|
|
|
13100
13293
|
return null;
|
|
13101
13294
|
}
|
|
13102
13295
|
if (leaf === "date") {
|
|
13103
|
-
return core.type ===
|
|
13296
|
+
return core.type === import_utils66.AST_NODE_TYPES.TSTypeReference && core.typeName.type === import_utils66.AST_NODE_TYPES.Identifier && core.typeName.name === "Date";
|
|
13104
13297
|
}
|
|
13105
13298
|
return expected.includes(core.type);
|
|
13106
13299
|
}
|
|
13107
13300
|
function typeLiteralDomain(annotation) {
|
|
13108
|
-
const members = annotation.type ===
|
|
13301
|
+
const members = annotation.type === import_utils66.AST_NODE_TYPES.TSUnionType ? annotation.types : [annotation];
|
|
13109
13302
|
const keys = [];
|
|
13110
13303
|
for (const member of members) {
|
|
13111
|
-
if (member.type ===
|
|
13304
|
+
if (member.type === import_utils66.AST_NODE_TYPES.TSNullKeyword) {
|
|
13112
13305
|
continue;
|
|
13113
13306
|
}
|
|
13114
|
-
if (member.type !==
|
|
13307
|
+
if (member.type !== import_utils66.AST_NODE_TYPES.TSLiteralType) {
|
|
13115
13308
|
return null;
|
|
13116
13309
|
}
|
|
13117
13310
|
keys.push(primitiveLiteralKey(member.literal));
|
|
@@ -13119,11 +13312,11 @@ function typeLiteralDomain(annotation) {
|
|
|
13119
13312
|
return exactDomain(keys);
|
|
13120
13313
|
}
|
|
13121
13314
|
function staticStringUnionDomain(node) {
|
|
13122
|
-
if (node.type !==
|
|
13315
|
+
if (node.type !== import_utils66.AST_NODE_TYPES.TSUnionType) {
|
|
13123
13316
|
return null;
|
|
13124
13317
|
}
|
|
13125
13318
|
const keys = node.types.map((member) => {
|
|
13126
|
-
if (member.type !==
|
|
13319
|
+
if (member.type !== import_utils66.AST_NODE_TYPES.TSLiteralType) {
|
|
13127
13320
|
return null;
|
|
13128
13321
|
}
|
|
13129
13322
|
const key = primitiveLiteralKey(member.literal);
|
|
@@ -13191,14 +13384,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
13191
13384
|
function zodCallChain(node) {
|
|
13192
13385
|
const chain = [];
|
|
13193
13386
|
let current = node;
|
|
13194
|
-
while (current.type ===
|
|
13387
|
+
while (current.type === import_utils66.AST_NODE_TYPES.CallExpression) {
|
|
13195
13388
|
const callee = current.callee;
|
|
13196
|
-
if (callee.type !==
|
|
13389
|
+
if (callee.type !== import_utils66.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils66.AST_NODE_TYPES.Identifier) {
|
|
13197
13390
|
return null;
|
|
13198
13391
|
}
|
|
13199
13392
|
chain.push(current);
|
|
13200
13393
|
const receiver = callee.object;
|
|
13201
|
-
if (receiver.type ===
|
|
13394
|
+
if (receiver.type === import_utils66.AST_NODE_TYPES.Identifier) {
|
|
13202
13395
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
13203
13396
|
}
|
|
13204
13397
|
current = receiver;
|
|
@@ -13207,14 +13400,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
13207
13400
|
}
|
|
13208
13401
|
function methodName2(call) {
|
|
13209
13402
|
const callee = call.callee;
|
|
13210
|
-
return callee.type ===
|
|
13403
|
+
return callee.type === import_utils66.AST_NODE_TYPES.MemberExpression && callee.property.type === import_utils66.AST_NODE_TYPES.Identifier ? callee.property.name : "";
|
|
13211
13404
|
}
|
|
13212
13405
|
function recordZodImport(node) {
|
|
13213
13406
|
if (!isZodModule(node.source.value)) {
|
|
13214
13407
|
return;
|
|
13215
13408
|
}
|
|
13216
13409
|
for (const specifier of node.specifiers) {
|
|
13217
|
-
if (specifier.type ===
|
|
13410
|
+
if (specifier.type === import_utils66.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils66.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils66.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils66.AST_NODE_TYPES.Identifier && specifier.imported.name === "z") {
|
|
13218
13411
|
zodNamespaces.add(specifier.local.name);
|
|
13219
13412
|
}
|
|
13220
13413
|
}
|
|
@@ -13224,13 +13417,13 @@ var prefer_zod_infer_default = createRule({
|
|
|
13224
13417
|
let current = node;
|
|
13225
13418
|
let leaf = null;
|
|
13226
13419
|
let leafCall = null;
|
|
13227
|
-
while (current.type ===
|
|
13420
|
+
while (current.type === import_utils66.AST_NODE_TYPES.CallExpression) {
|
|
13228
13421
|
const callee = current.callee;
|
|
13229
|
-
if (callee.type !==
|
|
13422
|
+
if (callee.type !== import_utils66.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils66.AST_NODE_TYPES.Identifier) {
|
|
13230
13423
|
break;
|
|
13231
13424
|
}
|
|
13232
13425
|
const receiver = callee.object;
|
|
13233
|
-
if (receiver.type ===
|
|
13426
|
+
if (receiver.type === import_utils66.AST_NODE_TYPES.Identifier && zodNamespaces.has(receiver.name)) {
|
|
13234
13427
|
leaf = callee.property.name;
|
|
13235
13428
|
leafCall = current;
|
|
13236
13429
|
break;
|
|
@@ -13261,20 +13454,20 @@ var prefer_zod_infer_default = createRule({
|
|
|
13261
13454
|
return domain instanceof Set && domain.size >= 2 ? domain : null;
|
|
13262
13455
|
}
|
|
13263
13456
|
function inferredSchemaName(node) {
|
|
13264
|
-
if (node.type !==
|
|
13457
|
+
if (node.type !== import_utils66.AST_NODE_TYPES.TSTypeReference || node.typeName.type !== import_utils66.AST_NODE_TYPES.TSQualifiedName || node.typeName.left.type !== import_utils66.AST_NODE_TYPES.Identifier || !zodNamespaces.has(node.typeName.left.name) || node.typeName.right.name !== "infer") {
|
|
13265
13458
|
return null;
|
|
13266
13459
|
}
|
|
13267
13460
|
const arguments_ = node.typeArguments?.params ?? [];
|
|
13268
13461
|
const [argument] = arguments_;
|
|
13269
|
-
return arguments_.length === 1 && argument?.type ===
|
|
13462
|
+
return arguments_.length === 1 && argument?.type === import_utils66.AST_NODE_TYPES.TSTypeQuery && argument.exprName.type === import_utils66.AST_NODE_TYPES.Identifier ? argument.exprName.name : null;
|
|
13270
13463
|
}
|
|
13271
13464
|
function recordLiteralUnions(members, owner, ownerName, exported) {
|
|
13272
13465
|
for (const member of members) {
|
|
13273
|
-
if (member.type !==
|
|
13466
|
+
if (member.type !== import_utils66.AST_NODE_TYPES.TSPropertySignature || member.computed || member.optional || member.readonly || member.typeAnnotation === void 0) {
|
|
13274
13467
|
continue;
|
|
13275
13468
|
}
|
|
13276
13469
|
const key = member.key;
|
|
13277
|
-
const propertyName3 = key.type ===
|
|
13470
|
+
const propertyName3 = key.type === import_utils66.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils66.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
13278
13471
|
if (propertyName3 === null) {
|
|
13279
13472
|
continue;
|
|
13280
13473
|
}
|
|
@@ -13284,7 +13477,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
13284
13477
|
}
|
|
13285
13478
|
const annotation = member.typeAnnotation.typeAnnotation;
|
|
13286
13479
|
const domain = staticStringUnionDomain(annotation);
|
|
13287
|
-
if (domain === null || annotation.type !==
|
|
13480
|
+
if (domain === null || annotation.type !== import_utils66.AST_NODE_TYPES.TSUnionType) {
|
|
13288
13481
|
continue;
|
|
13289
13482
|
}
|
|
13290
13483
|
literalUnionOccurrences.push({
|
|
@@ -13315,16 +13508,16 @@ var prefer_zod_infer_default = createRule({
|
|
|
13315
13508
|
return null;
|
|
13316
13509
|
}
|
|
13317
13510
|
const shape = base.arguments[0];
|
|
13318
|
-
if (shape === void 0 || shape.type !==
|
|
13511
|
+
if (shape === void 0 || shape.type !== import_utils66.AST_NODE_TYPES.ObjectExpression) {
|
|
13319
13512
|
return null;
|
|
13320
13513
|
}
|
|
13321
13514
|
const fields = /* @__PURE__ */ new Map();
|
|
13322
13515
|
for (const property of shape.properties) {
|
|
13323
|
-
if (property.type !==
|
|
13516
|
+
if (property.type !== import_utils66.AST_NODE_TYPES.Property || property.computed) {
|
|
13324
13517
|
return null;
|
|
13325
13518
|
}
|
|
13326
13519
|
const { key } = property;
|
|
13327
|
-
const name = key.type ===
|
|
13520
|
+
const name = key.type === import_utils66.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils66.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
13328
13521
|
if (name === null) {
|
|
13329
13522
|
return null;
|
|
13330
13523
|
}
|
|
@@ -13335,11 +13528,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
13335
13528
|
function typeMembers(members) {
|
|
13336
13529
|
const result = /* @__PURE__ */ new Map();
|
|
13337
13530
|
for (const member of members) {
|
|
13338
|
-
if (member.type !==
|
|
13531
|
+
if (member.type !== import_utils66.AST_NODE_TYPES.TSPropertySignature || member.computed) {
|
|
13339
13532
|
return null;
|
|
13340
13533
|
}
|
|
13341
13534
|
const { key } = member;
|
|
13342
|
-
const name = key.type ===
|
|
13535
|
+
const name = key.type === import_utils66.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils66.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
13343
13536
|
if (name === null) {
|
|
13344
13537
|
return null;
|
|
13345
13538
|
}
|
|
@@ -13354,8 +13547,8 @@ var prefer_zod_infer_default = createRule({
|
|
|
13354
13547
|
return result.size === 0 ? null : result;
|
|
13355
13548
|
}
|
|
13356
13549
|
function collectConstrainedNames(node) {
|
|
13357
|
-
if (node.type ===
|
|
13358
|
-
if (node.typeName.type ===
|
|
13550
|
+
if (node.type === import_utils66.AST_NODE_TYPES.TSTypeReference) {
|
|
13551
|
+
if (node.typeName.type === import_utils66.AST_NODE_TYPES.Identifier) {
|
|
13359
13552
|
constrainedTypeNames.add(node.typeName.name);
|
|
13360
13553
|
}
|
|
13361
13554
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -13363,11 +13556,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
13363
13556
|
}
|
|
13364
13557
|
return;
|
|
13365
13558
|
}
|
|
13366
|
-
if (node.type ===
|
|
13559
|
+
if (node.type === import_utils66.AST_NODE_TYPES.TSArrayType) {
|
|
13367
13560
|
collectConstrainedNames(node.elementType);
|
|
13368
13561
|
return;
|
|
13369
13562
|
}
|
|
13370
|
-
if (node.type ===
|
|
13563
|
+
if (node.type === import_utils66.AST_NODE_TYPES.TSUnionType || node.type === import_utils66.AST_NODE_TYPES.TSIntersectionType) {
|
|
13371
13564
|
for (const member of node.types) {
|
|
13372
13565
|
collectConstrainedNames(member);
|
|
13373
13566
|
}
|
|
@@ -13411,7 +13604,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
13411
13604
|
return {
|
|
13412
13605
|
Program(node) {
|
|
13413
13606
|
for (const statement of node.body) {
|
|
13414
|
-
if (statement.type ===
|
|
13607
|
+
if (statement.type === import_utils66.AST_NODE_TYPES.ImportDeclaration) {
|
|
13415
13608
|
recordZodImport(statement);
|
|
13416
13609
|
}
|
|
13417
13610
|
}
|
|
@@ -13420,7 +13613,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
13420
13613
|
recordZodImport(node);
|
|
13421
13614
|
},
|
|
13422
13615
|
VariableDeclarator(node) {
|
|
13423
|
-
if (node.id.type !==
|
|
13616
|
+
if (node.id.type !== import_utils66.AST_NODE_TYPES.Identifier || node.init == null) {
|
|
13424
13617
|
return;
|
|
13425
13618
|
}
|
|
13426
13619
|
const fields = schemaFields(node.init);
|
|
@@ -13437,14 +13630,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
13437
13630
|
},
|
|
13438
13631
|
/** Records `XSchema.transform(...)` and equivalent module-level reshaping. */
|
|
13439
13632
|
"MemberExpression[computed=false]"(node) {
|
|
13440
|
-
if (node.object.type ===
|
|
13633
|
+
if (node.object.type === import_utils66.AST_NODE_TYPES.Identifier && node.property.type === import_utils66.AST_NODE_TYPES.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
13441
13634
|
reshapedSchemaNames.add(node.object.name);
|
|
13442
13635
|
}
|
|
13443
13636
|
},
|
|
13444
13637
|
/** Records every type argument carried by a Zod constraint. */
|
|
13445
13638
|
TSTypeReference(node) {
|
|
13446
13639
|
const { typeName } = node;
|
|
13447
|
-
const referenced = typeName.type ===
|
|
13640
|
+
const referenced = typeName.type === import_utils66.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils66.AST_NODE_TYPES.TSQualifiedName && typeName.right.type === import_utils66.AST_NODE_TYPES.Identifier ? typeName.right.name : null;
|
|
13448
13641
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
13449
13642
|
return;
|
|
13450
13643
|
}
|
|
@@ -13476,7 +13669,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
13476
13669
|
typeName: node.id.name
|
|
13477
13670
|
});
|
|
13478
13671
|
}
|
|
13479
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
13672
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== import_utils66.AST_NODE_TYPES.TSTypeLiteral) {
|
|
13480
13673
|
return;
|
|
13481
13674
|
}
|
|
13482
13675
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -13575,7 +13768,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
13575
13768
|
});
|
|
13576
13769
|
|
|
13577
13770
|
// src/rules/require-assert-never.ts
|
|
13578
|
-
var
|
|
13771
|
+
var import_utils67 = require("@typescript-eslint/utils");
|
|
13579
13772
|
var import_typescript = __toESM(require("typescript"), 1);
|
|
13580
13773
|
var requireAssertNeverDocumentation = {
|
|
13581
13774
|
summary: "Require an empty switch default to call `assertNever` so discriminated unions remain exhaustive at compile time.",
|
|
@@ -13588,14 +13781,14 @@ var requireAssertNeverDocumentation = {
|
|
|
13588
13781
|
]
|
|
13589
13782
|
};
|
|
13590
13783
|
var isRuntimeHandlingStatement = (statement) => {
|
|
13591
|
-
if (statement.type ===
|
|
13592
|
-
if (statement.type ===
|
|
13784
|
+
if (statement.type === import_utils67.AST_NODE_TYPES.EmptyStatement) return false;
|
|
13785
|
+
if (statement.type === import_utils67.AST_NODE_TYPES.BreakStatement) {
|
|
13593
13786
|
return statement.label !== null;
|
|
13594
13787
|
}
|
|
13595
|
-
if (statement.type ===
|
|
13788
|
+
if (statement.type === import_utils67.AST_NODE_TYPES.TSTypeAliasDeclaration || statement.type === import_utils67.AST_NODE_TYPES.TSInterfaceDeclaration) {
|
|
13596
13789
|
return false;
|
|
13597
13790
|
}
|
|
13598
|
-
if (statement.type ===
|
|
13791
|
+
if (statement.type === import_utils67.AST_NODE_TYPES.BlockStatement) {
|
|
13599
13792
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
13600
13793
|
}
|
|
13601
13794
|
return true;
|
|
@@ -13611,7 +13804,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
13611
13804
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
13612
13805
|
}
|
|
13613
13806
|
const only = defaultCase.consequent[0];
|
|
13614
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
13807
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === import_utils67.AST_NODE_TYPES.BlockStatement && !only.body.some(isRuntimeHandlingStatement)) {
|
|
13615
13808
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
13616
13809
|
}
|
|
13617
13810
|
return false;
|
|
@@ -13667,7 +13860,7 @@ var require_assert_never_default = createRule({
|
|
|
13667
13860
|
create(context) {
|
|
13668
13861
|
let services;
|
|
13669
13862
|
try {
|
|
13670
|
-
services =
|
|
13863
|
+
services = import_utils67.ESLintUtils.getParserServices(context);
|
|
13671
13864
|
} catch {
|
|
13672
13865
|
services = null;
|
|
13673
13866
|
}
|
|
@@ -13694,7 +13887,7 @@ var require_assert_never_default = createRule({
|
|
|
13694
13887
|
});
|
|
13695
13888
|
|
|
13696
13889
|
// src/rules/require-fetch-timeout.ts
|
|
13697
|
-
var
|
|
13890
|
+
var import_utils68 = require("@typescript-eslint/utils");
|
|
13698
13891
|
var requireFetchTimeoutDocumentation = {
|
|
13699
13892
|
summary: "Require an abort `signal` (e.g. `AbortSignal.timeout(ms)`) on global `fetch()` calls so stalled upstreams cannot hang the caller forever.",
|
|
13700
13893
|
rationale: "An unbounded request can occupy work indefinitely when an upstream stalls.",
|
|
@@ -13720,14 +13913,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
13720
13913
|
return false;
|
|
13721
13914
|
}
|
|
13722
13915
|
function initProvablyLacksSignal(init) {
|
|
13723
|
-
if (init.type !==
|
|
13916
|
+
if (init.type !== import_utils68.AST_NODE_TYPES.ObjectExpression) {
|
|
13724
13917
|
return false;
|
|
13725
13918
|
}
|
|
13726
13919
|
for (const prop of init.properties) {
|
|
13727
|
-
if (prop.type ===
|
|
13920
|
+
if (prop.type === import_utils68.AST_NODE_TYPES.SpreadElement) {
|
|
13728
13921
|
return false;
|
|
13729
13922
|
}
|
|
13730
|
-
if (prop.key.type ===
|
|
13923
|
+
if (prop.key.type === import_utils68.AST_NODE_TYPES.Identifier && prop.key.name === "signal" || prop.key.type === import_utils68.AST_NODE_TYPES.Literal && prop.key.value === "signal") {
|
|
13731
13924
|
return false;
|
|
13732
13925
|
}
|
|
13733
13926
|
if (prop.computed) {
|
|
@@ -13737,7 +13930,7 @@ function initProvablyLacksSignal(init) {
|
|
|
13737
13930
|
return true;
|
|
13738
13931
|
}
|
|
13739
13932
|
function isInlineUrl(node, resolvesToGlobal) {
|
|
13740
|
-
return node.type ===
|
|
13933
|
+
return node.type === import_utils68.AST_NODE_TYPES.Literal && typeof node.value === "string" || node.type === import_utils68.AST_NODE_TYPES.TemplateLiteral || node.type === import_utils68.AST_NODE_TYPES.NewExpression && node.callee.type === import_utils68.AST_NODE_TYPES.Identifier && node.callee.name === "URL" && resolvesToGlobal(node.callee);
|
|
13741
13934
|
}
|
|
13742
13935
|
var require_fetch_timeout_default = createRule({
|
|
13743
13936
|
name: "require-fetch-timeout",
|
|
@@ -13775,30 +13968,30 @@ var require_fetch_timeout_default = createRule({
|
|
|
13775
13968
|
}
|
|
13776
13969
|
function resolvesToGlobal(identifier) {
|
|
13777
13970
|
const scope = context.sourceCode.getScope(identifier);
|
|
13778
|
-
const variable =
|
|
13971
|
+
const variable = import_utils68.ASTUtils.findVariable(scope, identifier.name);
|
|
13779
13972
|
return variable === null || variable.defs.length === 0;
|
|
13780
13973
|
}
|
|
13781
13974
|
function isGlobalFetchCall2(callee) {
|
|
13782
|
-
if (callee.type ===
|
|
13975
|
+
if (callee.type === import_utils68.AST_NODE_TYPES.Identifier) {
|
|
13783
13976
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
13784
13977
|
}
|
|
13785
|
-
return callee.type ===
|
|
13978
|
+
return callee.type === import_utils68.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils68.AST_NODE_TYPES.Identifier && callee.property.name === "fetch" && callee.object.type === import_utils68.AST_NODE_TYPES.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
13786
13979
|
}
|
|
13787
13980
|
function localConstInitProvablyLacksSignal(identifier) {
|
|
13788
|
-
const variable =
|
|
13981
|
+
const variable = import_utils68.ASTUtils.findVariable(
|
|
13789
13982
|
context.sourceCode.getScope(identifier),
|
|
13790
13983
|
identifier.name
|
|
13791
13984
|
);
|
|
13792
13985
|
if (variable?.defs.length !== 1) return false;
|
|
13793
13986
|
const definition = variable.defs[0];
|
|
13794
|
-
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !==
|
|
13987
|
+
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !== import_utils68.AST_NODE_TYPES.ObjectExpression || !initProvablyLacksSignal(definition.node.init)) {
|
|
13795
13988
|
return false;
|
|
13796
13989
|
}
|
|
13797
13990
|
for (const reference of variable.references) {
|
|
13798
13991
|
const ref = reference.identifier;
|
|
13799
13992
|
if (ref === identifier || ref === definition.name) continue;
|
|
13800
13993
|
const member = ref.parent;
|
|
13801
|
-
if (member.type !==
|
|
13994
|
+
if (member.type !== import_utils68.AST_NODE_TYPES.MemberExpression || member.object !== ref || member.computed || member.property.type !== import_utils68.AST_NODE_TYPES.Identifier || member.property.name === "signal" || member.parent.type !== import_utils68.AST_NODE_TYPES.AssignmentExpression || member.parent.left !== member) {
|
|
13802
13995
|
return false;
|
|
13803
13996
|
}
|
|
13804
13997
|
}
|
|
@@ -13813,7 +14006,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
13813
14006
|
if (node.arguments.length === 1 && first !== void 0 && !isInlineUrl(first, resolvesToGlobal)) {
|
|
13814
14007
|
return;
|
|
13815
14008
|
}
|
|
13816
|
-
if (init === void 0 || initProvablyLacksSignal(init) || init.type ===
|
|
14009
|
+
if (init === void 0 || initProvablyLacksSignal(init) || init.type === import_utils68.AST_NODE_TYPES.Identifier && localConstInitProvablyLacksSignal(init)) {
|
|
13817
14010
|
context.report({ node, messageId: "missingSignal" });
|
|
13818
14011
|
}
|
|
13819
14012
|
}
|
|
@@ -13822,7 +14015,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
13822
14015
|
});
|
|
13823
14016
|
|
|
13824
14017
|
// src/rules/require-port-for-service.ts
|
|
13825
|
-
var
|
|
14018
|
+
var import_utils69 = require("@typescript-eslint/utils");
|
|
13826
14019
|
var requirePortForServiceDocumentation = {
|
|
13827
14020
|
summary: "Advise when an exported service with injected collaborators has public methods not covered by its declared ports.",
|
|
13828
14021
|
rationale: "A declared port keeps consumers coupled to the service capability instead of its concrete implementation.",
|
|
@@ -13847,45 +14040,45 @@ var ROUTER_FACTORY_NAME = "Router";
|
|
|
13847
14040
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
13848
14041
|
var STORAGE_ASSIGNMENT_OPERATORS = /* @__PURE__ */ new Set(["=", "&&=", "??=", "||="]);
|
|
13849
14042
|
var staticMemberName6 = (member) => {
|
|
13850
|
-
if (member.property.type ===
|
|
13851
|
-
if (!member.computed && member.property.type ===
|
|
13852
|
-
return member.computed && member.property.type ===
|
|
14043
|
+
if (member.property.type === import_utils69.AST_NODE_TYPES.PrivateIdentifier) return `#${member.property.name}`;
|
|
14044
|
+
if (!member.computed && member.property.type === import_utils69.AST_NODE_TYPES.Identifier) return member.property.name;
|
|
14045
|
+
return member.computed && member.property.type === import_utils69.AST_NODE_TYPES.Literal && typeof member.property.value === "string" ? member.property.value : null;
|
|
13853
14046
|
};
|
|
13854
14047
|
var detachedValueExports = (program) => {
|
|
13855
14048
|
const names = /* @__PURE__ */ new Set();
|
|
13856
14049
|
for (const statement of program.body) {
|
|
13857
|
-
if (statement.type ===
|
|
14050
|
+
if (statement.type === import_utils69.AST_NODE_TYPES.ExportNamedDeclaration && statement.declaration === null && statement.source === null && statement.exportKind !== "type") {
|
|
13858
14051
|
for (const specifier of statement.specifiers) {
|
|
13859
14052
|
if (specifier.exportKind !== "type") names.add(specifier.local.name);
|
|
13860
14053
|
}
|
|
13861
|
-
} else if (statement.type ===
|
|
14054
|
+
} else if (statement.type === import_utils69.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils69.AST_NODE_TYPES.Identifier) {
|
|
13862
14055
|
names.add(statement.declaration.name);
|
|
13863
|
-
} else if (statement.type ===
|
|
14056
|
+
} else if (statement.type === import_utils69.AST_NODE_TYPES.TSExportAssignment && statement.expression.type === import_utils69.AST_NODE_TYPES.Identifier) {
|
|
13864
14057
|
names.add(statement.expression.name);
|
|
13865
14058
|
}
|
|
13866
14059
|
}
|
|
13867
14060
|
return names;
|
|
13868
14061
|
};
|
|
13869
|
-
var isExportedClass2 = (node, detached) => node.parent.type ===
|
|
14062
|
+
var isExportedClass2 = (node, detached) => node.parent.type === import_utils69.AST_NODE_TYPES.ExportNamedDeclaration || node.parent.type === import_utils69.AST_NODE_TYPES.ExportDefaultDeclaration || node.id !== null && detached.has(node.id.name);
|
|
13870
14063
|
var readTypeReference = (annotation) => {
|
|
13871
|
-
if (annotation?.type ===
|
|
14064
|
+
if (annotation?.type === import_utils69.AST_NODE_TYPES.TSUnionType) {
|
|
13872
14065
|
const members = annotation.types.filter(
|
|
13873
|
-
(member) => member.type !==
|
|
14066
|
+
(member) => member.type !== import_utils69.AST_NODE_TYPES.TSUndefinedKeyword && member.type !== import_utils69.AST_NODE_TYPES.TSNullKeyword
|
|
13874
14067
|
);
|
|
13875
14068
|
annotation = members.length === 1 ? members[0] : void 0;
|
|
13876
14069
|
}
|
|
13877
|
-
if (annotation === void 0 || annotation.type !==
|
|
14070
|
+
if (annotation === void 0 || annotation.type !== import_utils69.AST_NODE_TYPES.TSTypeReference) return null;
|
|
13878
14071
|
const { typeName } = annotation;
|
|
13879
|
-
const rightmost = typeName.type ===
|
|
14072
|
+
const rightmost = typeName.type === import_utils69.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils69.AST_NODE_TYPES.TSQualifiedName ? typeName.right.name : null;
|
|
13880
14073
|
if (rightmost === null) return null;
|
|
13881
14074
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
13882
14075
|
};
|
|
13883
|
-
var qualifiedName = (name) => name.type ===
|
|
14076
|
+
var qualifiedName = (name) => name.type === import_utils69.AST_NODE_TYPES.Identifier ? name.name : name.type === import_utils69.AST_NODE_TYPES.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
13884
14077
|
var propertySignatureTypes = (members) => {
|
|
13885
14078
|
const types = /* @__PURE__ */ new Map();
|
|
13886
14079
|
for (const member of members) {
|
|
13887
|
-
if (member.type !==
|
|
13888
|
-
if (member.computed || member.key.type !==
|
|
14080
|
+
if (member.type !== import_utils69.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
14081
|
+
if (member.computed || member.key.type !== import_utils69.AST_NODE_TYPES.Identifier) continue;
|
|
13889
14082
|
const reference = readTypeReference(member.typeAnnotation?.typeAnnotation);
|
|
13890
14083
|
if (reference === null) continue;
|
|
13891
14084
|
types.set(member.key.name, reference);
|
|
@@ -13896,18 +14089,18 @@ var fileTypeIndex = (program) => {
|
|
|
13896
14089
|
const objects = /* @__PURE__ */ new Map();
|
|
13897
14090
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
13898
14091
|
for (const statement of program.body) {
|
|
13899
|
-
const declaration = statement.type ===
|
|
13900
|
-
if (declaration?.type ===
|
|
14092
|
+
const declaration = statement.type === import_utils69.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
14093
|
+
if (declaration?.type === import_utils69.AST_NODE_TYPES.TSInterfaceDeclaration) {
|
|
13901
14094
|
objects.set(declaration.id.name, propertySignatureTypes(declaration.body.body));
|
|
13902
14095
|
continue;
|
|
13903
14096
|
}
|
|
13904
|
-
if (declaration?.type !==
|
|
14097
|
+
if (declaration?.type !== import_utils69.AST_NODE_TYPES.TSTypeAliasDeclaration) continue;
|
|
13905
14098
|
const aliased = declaration.typeAnnotation;
|
|
13906
|
-
if (aliased.type ===
|
|
14099
|
+
if (aliased.type === import_utils69.AST_NODE_TYPES.TSFunctionType || aliased.type === import_utils69.AST_NODE_TYPES.TSConstructorType) {
|
|
13907
14100
|
functionAliases.add(declaration.id.name);
|
|
13908
14101
|
continue;
|
|
13909
14102
|
}
|
|
13910
|
-
const literals = aliased.type ===
|
|
14103
|
+
const literals = aliased.type === import_utils69.AST_NODE_TYPES.TSTypeLiteral ? [aliased] : aliased.type === import_utils69.AST_NODE_TYPES.TSIntersectionType ? aliased.types.filter((part) => part.type === import_utils69.AST_NODE_TYPES.TSTypeLiteral) : [];
|
|
13911
14104
|
if (literals.length === 0) continue;
|
|
13912
14105
|
const merged = /* @__PURE__ */ new Map();
|
|
13913
14106
|
for (const literal of literals) {
|
|
@@ -13935,10 +14128,10 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
13935
14128
|
while (pending.length > 0) {
|
|
13936
14129
|
const current = pending.pop();
|
|
13937
14130
|
if (current === void 0) break;
|
|
13938
|
-
if (current.type ===
|
|
13939
|
-
const expression = current.type ===
|
|
13940
|
-
const storedField = expression?.type ===
|
|
13941
|
-
if (expression?.type !==
|
|
14131
|
+
if (current.type === import_utils69.AST_NODE_TYPES.ArrowFunctionExpression || current.type === import_utils69.AST_NODE_TYPES.FunctionExpression || current.type === import_utils69.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils69.AST_NODE_TYPES.ClassExpression || current.type === import_utils69.AST_NODE_TYPES.ClassDeclaration) continue;
|
|
14132
|
+
const expression = current.type === import_utils69.AST_NODE_TYPES.ExpressionStatement ? current.expression : null;
|
|
14133
|
+
const storedField = expression?.type === import_utils69.AST_NODE_TYPES.AssignmentExpression && expression.left.type === import_utils69.AST_NODE_TYPES.MemberExpression && expression.left.object.type === import_utils69.AST_NODE_TYPES.ThisExpression ? staticMemberName6(expression.left) : null;
|
|
14134
|
+
if (expression?.type !== import_utils69.AST_NODE_TYPES.AssignmentExpression || !STORAGE_ASSIGNMENT_OPERATORS.has(expression.operator) || expression.left.type !== import_utils69.AST_NODE_TYPES.MemberExpression || expression.left.object.type !== import_utils69.AST_NODE_TYPES.ThisExpression || storedField === null) {
|
|
13942
14135
|
for (const key of Object.keys(current)) {
|
|
13943
14136
|
if (key === "parent") continue;
|
|
13944
14137
|
const value = current[key];
|
|
@@ -13951,14 +14144,14 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
13951
14144
|
continue;
|
|
13952
14145
|
}
|
|
13953
14146
|
let source = expression.right;
|
|
13954
|
-
while (source.type ===
|
|
13955
|
-
if (source.type ===
|
|
14147
|
+
while (source.type === import_utils69.AST_NODE_TYPES.TSNonNullExpression || source.type === import_utils69.AST_NODE_TYPES.TSAsExpression || source.type === import_utils69.AST_NODE_TYPES.TSSatisfiesExpression || source.type === import_utils69.AST_NODE_TYPES.TSTypeAssertion) source = source.expression;
|
|
14148
|
+
if (source.type === import_utils69.AST_NODE_TYPES.NewExpression) {
|
|
13956
14149
|
constructedFields += 1;
|
|
13957
|
-
} else if (source.type ===
|
|
14150
|
+
} else if (source.type === import_utils69.AST_NODE_TYPES.Identifier) {
|
|
13958
14151
|
const fields = storedFieldsFrom.get(source.name) ?? /* @__PURE__ */ new Set();
|
|
13959
14152
|
fields.add(storedField);
|
|
13960
14153
|
storedFieldsFrom.set(source.name, fields);
|
|
13961
|
-
} else if (source.type ===
|
|
14154
|
+
} else if (source.type === import_utils69.AST_NODE_TYPES.MemberExpression && source.object.type === import_utils69.AST_NODE_TYPES.Identifier) {
|
|
13962
14155
|
const fields = storedFieldsFrom.get(source.object.name) ?? /* @__PURE__ */ new Set();
|
|
13963
14156
|
fields.add(storedField);
|
|
13964
14157
|
storedFieldsFrom.set(source.object.name, fields);
|
|
@@ -13968,7 +14161,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
13968
14161
|
const collaborators = [];
|
|
13969
14162
|
for (const parameter of ctor.value.params) {
|
|
13970
14163
|
for (const reference of parameterCollaborators(parameter, declared)) {
|
|
13971
|
-
const fields = parameter.type ===
|
|
14164
|
+
const fields = parameter.type === import_utils69.AST_NODE_TYPES.TSParameterProperty ? [reference.name] : [...storedFieldsFrom.get(reference.name) ?? []];
|
|
13972
14165
|
if (fields.length === 0) continue;
|
|
13973
14166
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
13974
14167
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -13983,8 +14176,8 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
13983
14176
|
};
|
|
13984
14177
|
var parameterCollaborators = (parameter, declared) => {
|
|
13985
14178
|
let target = parameter;
|
|
13986
|
-
if (target.type ===
|
|
13987
|
-
if (target.type ===
|
|
14179
|
+
if (target.type === import_utils69.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
14180
|
+
if (target.type === import_utils69.AST_NODE_TYPES.ObjectPattern) {
|
|
13988
14181
|
return objectPatternCollaborators(target, declared);
|
|
13989
14182
|
}
|
|
13990
14183
|
const named2 = namedParameterCollaborator(parameter);
|
|
@@ -13992,9 +14185,9 @@ var parameterCollaborators = (parameter, declared) => {
|
|
|
13992
14185
|
};
|
|
13993
14186
|
var namedParameterCollaborator = (annotated) => {
|
|
13994
14187
|
let target = annotated;
|
|
13995
|
-
if (target.type ===
|
|
13996
|
-
if (target.type ===
|
|
13997
|
-
if (target.type !==
|
|
14188
|
+
if (target.type === import_utils69.AST_NODE_TYPES.TSParameterProperty) target = target.parameter;
|
|
14189
|
+
if (target.type === import_utils69.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
14190
|
+
if (target.type !== import_utils69.AST_NODE_TYPES.Identifier) return null;
|
|
13998
14191
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
13999
14192
|
if (reference === null) return null;
|
|
14000
14193
|
return { name: target.name, ...reference, fields: [] };
|
|
@@ -14006,11 +14199,11 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
14006
14199
|
if (members === null) return [];
|
|
14007
14200
|
const collaborators = [];
|
|
14008
14201
|
for (const property of pattern.properties) {
|
|
14009
|
-
if (property.type !==
|
|
14010
|
-
if (property.key.type !==
|
|
14202
|
+
if (property.type !== import_utils69.AST_NODE_TYPES.Property || property.computed) continue;
|
|
14203
|
+
if (property.key.type !== import_utils69.AST_NODE_TYPES.Identifier) continue;
|
|
14011
14204
|
const key = property.key.name;
|
|
14012
|
-
const bound = property.value.type ===
|
|
14013
|
-
if (bound.type !==
|
|
14205
|
+
const bound = property.value.type === import_utils69.AST_NODE_TYPES.AssignmentPattern ? property.value.left : property.value;
|
|
14206
|
+
if (bound.type !== import_utils69.AST_NODE_TYPES.Identifier) continue;
|
|
14014
14207
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
14015
14208
|
const reference = members.get(key);
|
|
14016
14209
|
if (reference === void 0) continue;
|
|
@@ -14019,21 +14212,21 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
14019
14212
|
return collaborators;
|
|
14020
14213
|
};
|
|
14021
14214
|
var bagMemberTypes = (annotation, declared) => {
|
|
14022
|
-
if (annotation.type ===
|
|
14215
|
+
if (annotation.type === import_utils69.AST_NODE_TYPES.TSTypeLiteral) {
|
|
14023
14216
|
return propertySignatureTypes(annotation.members);
|
|
14024
14217
|
}
|
|
14025
|
-
if (annotation.type !==
|
|
14218
|
+
if (annotation.type !== import_utils69.AST_NODE_TYPES.TSTypeReference || annotation.typeName.type !== import_utils69.AST_NODE_TYPES.Identifier) {
|
|
14026
14219
|
return null;
|
|
14027
14220
|
}
|
|
14028
14221
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
14029
14222
|
};
|
|
14030
14223
|
var isFrameworkWiring = (body2) => subtreeHas(body2, (node) => {
|
|
14031
|
-
if (node.type ===
|
|
14224
|
+
if (node.type === import_utils69.AST_NODE_TYPES.CallExpression) {
|
|
14032
14225
|
const { callee } = node;
|
|
14033
|
-
if (callee.type ===
|
|
14034
|
-
return callee.type ===
|
|
14226
|
+
if (callee.type === import_utils69.AST_NODE_TYPES.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
14227
|
+
return callee.type === import_utils69.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils69.AST_NODE_TYPES.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
14035
14228
|
}
|
|
14036
|
-
return node.type ===
|
|
14229
|
+
return node.type === import_utils69.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils69.AST_NODE_TYPES.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
14037
14230
|
});
|
|
14038
14231
|
var subtreeHas = (root, found) => {
|
|
14039
14232
|
let hit = false;
|
|
@@ -14060,19 +14253,19 @@ var invokedInstanceField = (call) => {
|
|
|
14060
14253
|
const direct = instanceField(call.callee);
|
|
14061
14254
|
if (direct !== null) return direct;
|
|
14062
14255
|
let callee = call.callee;
|
|
14063
|
-
while (callee.type ===
|
|
14064
|
-
return callee.type ===
|
|
14256
|
+
while (callee.type === import_utils69.AST_NODE_TYPES.ChainExpression || callee.type === import_utils69.AST_NODE_TYPES.TSAsExpression || callee.type === import_utils69.AST_NODE_TYPES.TSNonNullExpression || callee.type === import_utils69.AST_NODE_TYPES.TSSatisfiesExpression || callee.type === import_utils69.AST_NODE_TYPES.TSTypeAssertion) callee = callee.expression;
|
|
14257
|
+
return callee.type === import_utils69.AST_NODE_TYPES.MemberExpression ? instanceField(callee.object) : null;
|
|
14065
14258
|
};
|
|
14066
14259
|
var instanceField = (candidate) => {
|
|
14067
14260
|
let node = candidate;
|
|
14068
|
-
while (node.type ===
|
|
14069
|
-
return node.type ===
|
|
14261
|
+
while (node.type === import_utils69.AST_NODE_TYPES.ChainExpression || node.type === import_utils69.AST_NODE_TYPES.TSAsExpression || node.type === import_utils69.AST_NODE_TYPES.TSNonNullExpression || node.type === import_utils69.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils69.AST_NODE_TYPES.TSTypeAssertion) node = node.expression;
|
|
14262
|
+
return node.type === import_utils69.AST_NODE_TYPES.MemberExpression && node.object.type === import_utils69.AST_NODE_TYPES.ThisExpression ? staticMemberName6(node) : null;
|
|
14070
14263
|
};
|
|
14071
14264
|
var behaviorallyInvokedFields = (body2) => {
|
|
14072
14265
|
const invoked = /* @__PURE__ */ new Set();
|
|
14073
14266
|
const visit = (current) => {
|
|
14074
|
-
if (current.type ===
|
|
14075
|
-
if (current.type ===
|
|
14267
|
+
if (current.type === import_utils69.AST_NODE_TYPES.ClassDeclaration || current.type === import_utils69.AST_NODE_TYPES.ClassExpression || current.type === import_utils69.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils69.AST_NODE_TYPES.FunctionExpression) return;
|
|
14268
|
+
if (current.type === import_utils69.AST_NODE_TYPES.CallExpression) {
|
|
14076
14269
|
const field = invokedInstanceField(current);
|
|
14077
14270
|
if (field !== null) invoked.add(field);
|
|
14078
14271
|
}
|
|
@@ -14085,14 +14278,14 @@ var behaviorallyInvokedFields = (body2) => {
|
|
|
14085
14278
|
}
|
|
14086
14279
|
};
|
|
14087
14280
|
for (const member of body2.body) {
|
|
14088
|
-
if (member.type ===
|
|
14089
|
-
if (member.type ===
|
|
14281
|
+
if (member.type === import_utils69.AST_NODE_TYPES.StaticBlock || member.static) continue;
|
|
14282
|
+
if (member.type === import_utils69.AST_NODE_TYPES.MethodDefinition) {
|
|
14090
14283
|
if (member.value.body !== null && member.value.body !== void 0) visit(member.value.body);
|
|
14091
14284
|
continue;
|
|
14092
14285
|
}
|
|
14093
|
-
if (member.type !==
|
|
14286
|
+
if (member.type !== import_utils69.AST_NODE_TYPES.PropertyDefinition || member.value === null) continue;
|
|
14094
14287
|
visit(
|
|
14095
|
-
member.value.type ===
|
|
14288
|
+
member.value.type === import_utils69.AST_NODE_TYPES.ArrowFunctionExpression ? member.value.body : member.value
|
|
14096
14289
|
);
|
|
14097
14290
|
}
|
|
14098
14291
|
return invoked;
|
|
@@ -14112,25 +14305,25 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
14112
14305
|
var fileInterfaceNames = (program) => {
|
|
14113
14306
|
const names = [];
|
|
14114
14307
|
for (const statement of program.body) {
|
|
14115
|
-
const declaration = statement.type ===
|
|
14116
|
-
if (declaration?.type ===
|
|
14308
|
+
const declaration = statement.type === import_utils69.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
14309
|
+
if (declaration?.type === import_utils69.AST_NODE_TYPES.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
14117
14310
|
}
|
|
14118
14311
|
return names;
|
|
14119
14312
|
};
|
|
14120
14313
|
var publicMethodNames = (body2, functionAliases) => {
|
|
14121
14314
|
const names = [];
|
|
14122
14315
|
for (const member of body2.body) {
|
|
14123
|
-
if (member.type ===
|
|
14316
|
+
if (member.type === import_utils69.AST_NODE_TYPES.PropertyDefinition) {
|
|
14124
14317
|
if (member.static || member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
14125
|
-
if (member.value?.type !==
|
|
14126
|
-
names.push(member.key.type ===
|
|
14318
|
+
if (member.value?.type !== import_utils69.AST_NODE_TYPES.ArrowFunctionExpression && member.value?.type !== import_utils69.AST_NODE_TYPES.FunctionExpression && member.typeAnnotation?.typeAnnotation.type !== import_utils69.AST_NODE_TYPES.TSFunctionType && !(member.typeAnnotation?.typeAnnotation.type === import_utils69.AST_NODE_TYPES.TSTypeReference && member.typeAnnotation.typeAnnotation.typeName.type === import_utils69.AST_NODE_TYPES.Identifier && functionAliases.has(member.typeAnnotation.typeAnnotation.typeName.name))) continue;
|
|
14319
|
+
names.push(member.key.type === import_utils69.AST_NODE_TYPES.Identifier ? member.key.name : "\u2026");
|
|
14127
14320
|
continue;
|
|
14128
14321
|
}
|
|
14129
|
-
if (member.type !==
|
|
14322
|
+
if (member.type !== import_utils69.AST_NODE_TYPES.MethodDefinition) continue;
|
|
14130
14323
|
if (member.kind !== "method" || member.static) continue;
|
|
14131
14324
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
14132
|
-
if (member.key.type ===
|
|
14133
|
-
if (member.key.type ===
|
|
14325
|
+
if (member.key.type === import_utils69.AST_NODE_TYPES.PrivateIdentifier) continue;
|
|
14326
|
+
if (member.key.type === import_utils69.AST_NODE_TYPES.Identifier) names.push(member.key.name);
|
|
14134
14327
|
else names.push("\u2026");
|
|
14135
14328
|
}
|
|
14136
14329
|
return names;
|
|
@@ -14138,13 +14331,13 @@ var publicMethodNames = (body2, functionAliases) => {
|
|
|
14138
14331
|
var isFluentConstructionObject = (node, getText) => {
|
|
14139
14332
|
if (node.id === null) return false;
|
|
14140
14333
|
const methods = node.body.body.filter(
|
|
14141
|
-
(member) => member.type ===
|
|
14334
|
+
(member) => member.type === import_utils69.AST_NODE_TYPES.MethodDefinition && member.kind === "method" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.value.body !== null
|
|
14142
14335
|
);
|
|
14143
14336
|
if (methods.length === 0) return false;
|
|
14144
14337
|
return methods.every((member) => {
|
|
14145
14338
|
const result = member.value.returnType?.typeAnnotation;
|
|
14146
14339
|
if (result === void 0) return false;
|
|
14147
|
-
const returnsOwnType = result.type ===
|
|
14340
|
+
const returnsOwnType = result.type === import_utils69.AST_NODE_TYPES.TSTypeReference && result.typeName.type === import_utils69.AST_NODE_TYPES.Identifier && result.typeName.name === node.id?.name;
|
|
14148
14341
|
return returnsOwnType || FLUENT_BUILDER_NAME_RE.test(node.id?.name ?? "") && FLUENT_RESULT_TYPE_RE.test(getText(result));
|
|
14149
14342
|
});
|
|
14150
14343
|
};
|
|
@@ -14152,10 +14345,10 @@ function localClassAbstractness(program) {
|
|
|
14152
14345
|
const classes = /* @__PURE__ */ new Map();
|
|
14153
14346
|
const parents = /* @__PURE__ */ new Map();
|
|
14154
14347
|
for (const statement of program.body) {
|
|
14155
|
-
const declaration = statement.type ===
|
|
14156
|
-
if (declaration?.type ===
|
|
14348
|
+
const declaration = statement.type === import_utils69.AST_NODE_TYPES.ExportNamedDeclaration || statement.type === import_utils69.AST_NODE_TYPES.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
14349
|
+
if (declaration?.type === import_utils69.AST_NODE_TYPES.ClassDeclaration && declaration.id !== null) {
|
|
14157
14350
|
classes.set(declaration.id.name, declaration.abstract === true);
|
|
14158
|
-
if (declaration.superClass?.type ===
|
|
14351
|
+
if (declaration.superClass?.type === import_utils69.AST_NODE_TYPES.Identifier) {
|
|
14159
14352
|
parents.set(declaration.id.name, declaration.superClass.name);
|
|
14160
14353
|
}
|
|
14161
14354
|
}
|
|
@@ -14177,43 +14370,43 @@ function localInterfaceSurfaces(program) {
|
|
|
14177
14370
|
const parents = /* @__PURE__ */ new Map();
|
|
14178
14371
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
14179
14372
|
for (const statement of program.body) {
|
|
14180
|
-
const declaration = statement.type ===
|
|
14181
|
-
if (declaration?.type ===
|
|
14373
|
+
const declaration = statement.type === import_utils69.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
14374
|
+
if (declaration?.type === import_utils69.AST_NODE_TYPES.TSTypeAliasDeclaration && (declaration.typeAnnotation.type === import_utils69.AST_NODE_TYPES.TSFunctionType || declaration.typeAnnotation.type === import_utils69.AST_NODE_TYPES.TSConstructorType)) functionAliases.add(declaration.id.name);
|
|
14182
14375
|
}
|
|
14183
14376
|
for (const statement of program.body) {
|
|
14184
|
-
const declaration = statement.type ===
|
|
14185
|
-
if (declaration?.type ===
|
|
14377
|
+
const declaration = statement.type === import_utils69.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
14378
|
+
if (declaration?.type === import_utils69.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
14186
14379
|
const callables2 = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
14187
|
-
const parts = declaration.typeAnnotation.type ===
|
|
14380
|
+
const parts = declaration.typeAnnotation.type === import_utils69.AST_NODE_TYPES.TSIntersectionType ? declaration.typeAnnotation.types : [declaration.typeAnnotation];
|
|
14188
14381
|
const inherited = parents.get(declaration.id.name) ?? [];
|
|
14189
14382
|
for (const part of parts) {
|
|
14190
|
-
if (part.type ===
|
|
14383
|
+
if (part.type === import_utils69.AST_NODE_TYPES.TSTypeReference && part.typeName.type === import_utils69.AST_NODE_TYPES.Identifier) {
|
|
14191
14384
|
inherited.push(part.typeName.name);
|
|
14192
14385
|
continue;
|
|
14193
14386
|
}
|
|
14194
|
-
if (part.type !==
|
|
14387
|
+
if (part.type !== import_utils69.AST_NODE_TYPES.TSTypeLiteral) continue;
|
|
14195
14388
|
for (const member of part.members) {
|
|
14196
|
-
if (member.type !==
|
|
14197
|
-
if (member.computed || member.key.type !==
|
|
14198
|
-
if (member.type ===
|
|
14389
|
+
if (member.type !== import_utils69.AST_NODE_TYPES.TSMethodSignature && member.type !== import_utils69.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
14390
|
+
if (member.computed || member.key.type !== import_utils69.AST_NODE_TYPES.Identifier) continue;
|
|
14391
|
+
if (member.type === import_utils69.AST_NODE_TYPES.TSMethodSignature) {
|
|
14199
14392
|
callables2.add(member.key.name);
|
|
14200
14393
|
continue;
|
|
14201
14394
|
}
|
|
14202
|
-
if (member.type !==
|
|
14395
|
+
if (member.type !== import_utils69.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
14203
14396
|
const annotation = member.typeAnnotation?.typeAnnotation;
|
|
14204
|
-
if (annotation?.type ===
|
|
14397
|
+
if (annotation?.type === import_utils69.AST_NODE_TYPES.TSFunctionType || annotation?.type === import_utils69.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils69.AST_NODE_TYPES.Identifier && functionAliases.has(annotation.typeName.name)) callables2.add(member.key.name);
|
|
14205
14398
|
}
|
|
14206
14399
|
}
|
|
14207
14400
|
interfaces.set(declaration.id.name, callables2);
|
|
14208
14401
|
parents.set(declaration.id.name, inherited);
|
|
14209
14402
|
continue;
|
|
14210
14403
|
}
|
|
14211
|
-
if (declaration?.type !==
|
|
14404
|
+
if (declaration?.type !== import_utils69.AST_NODE_TYPES.TSInterfaceDeclaration) continue;
|
|
14212
14405
|
const callables = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
14213
14406
|
for (const member of declaration.body.body) {
|
|
14214
|
-
if (member.type !==
|
|
14215
|
-
if (member.computed || member.key.type !==
|
|
14216
|
-
if (member.type ===
|
|
14407
|
+
if (member.type !== import_utils69.AST_NODE_TYPES.TSMethodSignature && member.type !== import_utils69.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
14408
|
+
if (member.computed || member.key.type !== import_utils69.AST_NODE_TYPES.Identifier) continue;
|
|
14409
|
+
if (member.type === import_utils69.AST_NODE_TYPES.TSMethodSignature || member.typeAnnotation?.typeAnnotation.type === import_utils69.AST_NODE_TYPES.TSFunctionType || member.typeAnnotation?.typeAnnotation.type === import_utils69.AST_NODE_TYPES.TSTypeReference && member.typeAnnotation.typeAnnotation.typeName.type === import_utils69.AST_NODE_TYPES.Identifier && functionAliases.has(member.typeAnnotation.typeAnnotation.typeName.name)) callables.add(member.key.name);
|
|
14217
14410
|
}
|
|
14218
14411
|
interfaces.set(declaration.id.name, callables);
|
|
14219
14412
|
parents.set(
|
|
@@ -14221,7 +14414,7 @@ function localInterfaceSurfaces(program) {
|
|
|
14221
14414
|
[
|
|
14222
14415
|
...parents.get(declaration.id.name) ?? [],
|
|
14223
14416
|
...declaration.extends.flatMap(
|
|
14224
|
-
(heritage) => heritage.expression.type ===
|
|
14417
|
+
(heritage) => heritage.expression.type === import_utils69.AST_NODE_TYPES.Identifier ? [heritage.expression.name] : ["*"]
|
|
14225
14418
|
)
|
|
14226
14419
|
]
|
|
14227
14420
|
);
|
|
@@ -14248,7 +14441,7 @@ function localInterfaceSurfaces(program) {
|
|
|
14248
14441
|
}
|
|
14249
14442
|
function hasServicePort(node, methods, classes, interfaces) {
|
|
14250
14443
|
if (node.superClass !== null) {
|
|
14251
|
-
if (node.superClass.type !==
|
|
14444
|
+
if (node.superClass.type !== import_utils69.AST_NODE_TYPES.Identifier) return true;
|
|
14252
14445
|
const localAbstract = classes.get(node.superClass.name);
|
|
14253
14446
|
if (localAbstract === void 0 || localAbstract) return true;
|
|
14254
14447
|
}
|
|
@@ -14260,7 +14453,7 @@ function hasServicePort(node, methods, classes, interfaces) {
|
|
|
14260
14453
|
if (node.implements.length === 0) return false;
|
|
14261
14454
|
const combined = /* @__PURE__ */ new Set();
|
|
14262
14455
|
for (const implementation of node.implements) {
|
|
14263
|
-
if (implementation.expression.type !==
|
|
14456
|
+
if (implementation.expression.type !== import_utils69.AST_NODE_TYPES.Identifier) return true;
|
|
14264
14457
|
const name = implementation.expression.name;
|
|
14265
14458
|
const localAbstract = classes.get(name);
|
|
14266
14459
|
if (localAbstract === true) return true;
|
|
@@ -14303,7 +14496,7 @@ var require_port_for_service_default = createRule({
|
|
|
14303
14496
|
if (node.abstract === true) return;
|
|
14304
14497
|
if (node.decorators.length > 0) return;
|
|
14305
14498
|
const ctor = node.body.body.find(
|
|
14306
|
-
(member) => member.type ===
|
|
14499
|
+
(member) => member.type === import_utils69.AST_NODE_TYPES.MethodDefinition && member.kind === "constructor" && member.value.body !== null && member.value.body !== void 0
|
|
14307
14500
|
);
|
|
14308
14501
|
if (ctor === void 0) return;
|
|
14309
14502
|
const constructorFacts = readConstructor(
|
|
@@ -14338,7 +14531,7 @@ var require_port_for_service_default = createRule({
|
|
|
14338
14531
|
});
|
|
14339
14532
|
|
|
14340
14533
|
// src/rules/require-static-next-matcher.ts
|
|
14341
|
-
var
|
|
14534
|
+
var import_utils70 = require("@typescript-eslint/utils");
|
|
14342
14535
|
var requireStaticNextMatcherDocumentation = {
|
|
14343
14536
|
summary: "Require Next.js middleware and proxy matcher configuration to contain only build-time literals.",
|
|
14344
14537
|
rationale: "Next.js must statically analyze matcher values at build time; computed values are ignored.",
|
|
@@ -14351,34 +14544,34 @@ var requireStaticNextMatcherDocumentation = {
|
|
|
14351
14544
|
};
|
|
14352
14545
|
var NEXT_ENTRY_FILE = /(?:^|[/\\])(?:middleware|proxy)\.[cm]?[jt]sx?$/u;
|
|
14353
14546
|
function unwrapExpression3(node) {
|
|
14354
|
-
if (node.type ===
|
|
14547
|
+
if (node.type === import_utils70.AST_NODE_TYPES.TSAsExpression || node.type === import_utils70.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils70.AST_NODE_TYPES.TSNonNullExpression || node.type === import_utils70.AST_NODE_TYPES.TSTypeAssertion) {
|
|
14355
14548
|
return unwrapExpression3(node.expression);
|
|
14356
14549
|
}
|
|
14357
14550
|
return node;
|
|
14358
14551
|
}
|
|
14359
14552
|
function isStaticValue(node) {
|
|
14360
14553
|
const value = unwrapExpression3(node);
|
|
14361
|
-
if (value.type ===
|
|
14554
|
+
if (value.type === import_utils70.AST_NODE_TYPES.Literal) {
|
|
14362
14555
|
return true;
|
|
14363
14556
|
}
|
|
14364
|
-
if (value.type ===
|
|
14557
|
+
if (value.type === import_utils70.AST_NODE_TYPES.TemplateLiteral) {
|
|
14365
14558
|
return value.expressions.length === 0;
|
|
14366
14559
|
}
|
|
14367
|
-
if (value.type ===
|
|
14560
|
+
if (value.type === import_utils70.AST_NODE_TYPES.ArrayExpression) {
|
|
14368
14561
|
return value.elements.every(
|
|
14369
|
-
(element) => element !== null && element.type !==
|
|
14562
|
+
(element) => element !== null && element.type !== import_utils70.AST_NODE_TYPES.SpreadElement && isStaticValue(element)
|
|
14370
14563
|
);
|
|
14371
14564
|
}
|
|
14372
|
-
if (value.type ===
|
|
14565
|
+
if (value.type === import_utils70.AST_NODE_TYPES.ObjectExpression) {
|
|
14373
14566
|
return value.properties.every(
|
|
14374
|
-
(property) => property.type ===
|
|
14567
|
+
(property) => property.type === import_utils70.AST_NODE_TYPES.Property && property.kind === "init" && !property.computed && property.value.type !== import_utils70.AST_NODE_TYPES.AssignmentPattern && isStaticValue(property.value)
|
|
14375
14568
|
);
|
|
14376
14569
|
}
|
|
14377
14570
|
return false;
|
|
14378
14571
|
}
|
|
14379
14572
|
function propertyName2(property) {
|
|
14380
14573
|
if (property.computed) return null;
|
|
14381
|
-
if (property.key.type ===
|
|
14574
|
+
if (property.key.type === import_utils70.AST_NODE_TYPES.Identifier) return property.key.name;
|
|
14382
14575
|
return typeof property.key.value === "string" ? property.key.value : null;
|
|
14383
14576
|
}
|
|
14384
14577
|
var require_static_next_matcher_default = createRule({
|
|
@@ -14401,19 +14594,19 @@ var require_static_next_matcher_default = createRule({
|
|
|
14401
14594
|
}
|
|
14402
14595
|
return {
|
|
14403
14596
|
ExportNamedDeclaration(node) {
|
|
14404
|
-
if (node.declaration?.type !==
|
|
14597
|
+
if (node.declaration?.type !== import_utils70.AST_NODE_TYPES.VariableDeclaration) {
|
|
14405
14598
|
return;
|
|
14406
14599
|
}
|
|
14407
14600
|
for (const declaration of node.declaration.declarations) {
|
|
14408
|
-
if (declaration.id.type !==
|
|
14601
|
+
if (declaration.id.type !== import_utils70.AST_NODE_TYPES.Identifier || declaration.id.name !== "config" || declaration.init === null) {
|
|
14409
14602
|
continue;
|
|
14410
14603
|
}
|
|
14411
14604
|
const config = unwrapExpression3(declaration.init);
|
|
14412
|
-
if (config.type !==
|
|
14605
|
+
if (config.type !== import_utils70.AST_NODE_TYPES.ObjectExpression) {
|
|
14413
14606
|
continue;
|
|
14414
14607
|
}
|
|
14415
14608
|
for (const property of config.properties) {
|
|
14416
|
-
if (property.type !==
|
|
14609
|
+
if (property.type !== import_utils70.AST_NODE_TYPES.Property || propertyName2(property) !== "matcher" || property.value.type === import_utils70.AST_NODE_TYPES.AssignmentPattern) {
|
|
14417
14610
|
continue;
|
|
14418
14611
|
}
|
|
14419
14612
|
if (!isStaticValue(property.value)) {
|
|
@@ -14427,7 +14620,7 @@ var require_static_next_matcher_default = createRule({
|
|
|
14427
14620
|
});
|
|
14428
14621
|
|
|
14429
14622
|
// src/rules/require-zod-form-validation.ts
|
|
14430
|
-
var
|
|
14623
|
+
var import_utils71 = require("@typescript-eslint/utils");
|
|
14431
14624
|
var requireZodFormValidationDocumentation = {
|
|
14432
14625
|
summary: "Require Zod validation (`Schema.parse(...)` / `Schema.safeParse(...)`) when reading values out of a `FormData` object.",
|
|
14433
14626
|
rationale: "FormData values are untrusted strings or files and need runtime validation before use.",
|
|
@@ -14452,14 +14645,14 @@ var FORM_VALUE_METHODS = /* @__PURE__ */ new Set(["get", "getAll"]);
|
|
|
14452
14645
|
var zodReceiverRoot = (node) => {
|
|
14453
14646
|
let current = node;
|
|
14454
14647
|
while (true) {
|
|
14455
|
-
if (current.type ===
|
|
14648
|
+
if (current.type === import_utils71.AST_NODE_TYPES.Identifier) {
|
|
14456
14649
|
return current;
|
|
14457
14650
|
}
|
|
14458
|
-
if (current.type ===
|
|
14651
|
+
if (current.type === import_utils71.AST_NODE_TYPES.CallExpression) {
|
|
14459
14652
|
current = current.callee;
|
|
14460
14653
|
continue;
|
|
14461
14654
|
}
|
|
14462
|
-
if (current.type ===
|
|
14655
|
+
if (current.type === import_utils71.AST_NODE_TYPES.MemberExpression) {
|
|
14463
14656
|
current = current.object;
|
|
14464
14657
|
continue;
|
|
14465
14658
|
}
|
|
@@ -14468,12 +14661,12 @@ var zodReceiverRoot = (node) => {
|
|
|
14468
14661
|
};
|
|
14469
14662
|
var isFormDataMethodCall = (node) => {
|
|
14470
14663
|
let current = node;
|
|
14471
|
-
if (current.type ===
|
|
14664
|
+
if (current.type === import_utils71.AST_NODE_TYPES.AwaitExpression) {
|
|
14472
14665
|
current = current.argument;
|
|
14473
14666
|
}
|
|
14474
|
-
if (current.type !==
|
|
14667
|
+
if (current.type !== import_utils71.AST_NODE_TYPES.CallExpression) return false;
|
|
14475
14668
|
const callee = current.callee;
|
|
14476
|
-
return callee.type ===
|
|
14669
|
+
return callee.type === import_utils71.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils71.AST_NODE_TYPES.Identifier && callee.property.name === "formData";
|
|
14477
14670
|
};
|
|
14478
14671
|
var require_zod_form_validation_default = createRule({
|
|
14479
14672
|
name: "require-zod-form-validation",
|
|
@@ -14494,7 +14687,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14494
14687
|
return {};
|
|
14495
14688
|
}
|
|
14496
14689
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
14497
|
-
const resolvedBinding = (identifier) =>
|
|
14690
|
+
const resolvedBinding = (identifier) => import_utils71.ASTUtils.findVariable(
|
|
14498
14691
|
context.sourceCode.getScope(identifier),
|
|
14499
14692
|
identifier.name
|
|
14500
14693
|
);
|
|
@@ -14504,16 +14697,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
14504
14697
|
return false;
|
|
14505
14698
|
}
|
|
14506
14699
|
const definition = binding.defs[0];
|
|
14507
|
-
if (definition?.type !== "Variable" || definition.node.type !==
|
|
14700
|
+
if (definition?.type !== "Variable" || definition.node.type !== import_utils71.AST_NODE_TYPES.VariableDeclarator) {
|
|
14508
14701
|
return false;
|
|
14509
14702
|
}
|
|
14510
14703
|
const init = definition.node.init;
|
|
14511
|
-
return init?.type ===
|
|
14704
|
+
return init?.type === import_utils71.AST_NODE_TYPES.ObjectExpression || init?.type === import_utils71.AST_NODE_TYPES.ArrayExpression || init?.type === import_utils71.AST_NODE_TYPES.Literal || init?.type === import_utils71.AST_NODE_TYPES.ArrowFunctionExpression || init?.type === import_utils71.AST_NODE_TYPES.FunctionExpression;
|
|
14512
14705
|
};
|
|
14513
14706
|
const isZodParseCall = (node) => {
|
|
14514
|
-
if (node.type !==
|
|
14707
|
+
if (node.type !== import_utils71.AST_NODE_TYPES.CallExpression) return false;
|
|
14515
14708
|
const callee = node.callee;
|
|
14516
|
-
if (callee.type !==
|
|
14709
|
+
if (callee.type !== import_utils71.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils71.AST_NODE_TYPES.Identifier || !ZOD_PARSE_METHODS.has(callee.property.name)) {
|
|
14517
14710
|
return false;
|
|
14518
14711
|
}
|
|
14519
14712
|
const root = zodReceiverRoot(callee.object);
|
|
@@ -14522,14 +14715,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
14522
14715
|
return binding !== null && zodBindings.has(binding) || (root.name === "z" || ZOD_SCHEMA_NAME_RE.test(root.name)) && !isProvablyNonZodLocal(root);
|
|
14523
14716
|
};
|
|
14524
14717
|
const isFormSourceIdentifier = (node) => {
|
|
14525
|
-
if (node.type !==
|
|
14718
|
+
if (node.type !== import_utils71.AST_NODE_TYPES.Identifier) return false;
|
|
14526
14719
|
const conventionalName = /formdata/i.test(node.name);
|
|
14527
14720
|
let scope = context.sourceCode.getScope(node);
|
|
14528
14721
|
while (scope !== null) {
|
|
14529
14722
|
const variable = scope.set.get(node.name);
|
|
14530
14723
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
14531
14724
|
const def = variable.defs[0];
|
|
14532
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
14725
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === import_utils71.AST_NODE_TYPES.VariableDeclarator && def.node.init !== null) {
|
|
14533
14726
|
return isFormDataMethodCall(def.node.init);
|
|
14534
14727
|
}
|
|
14535
14728
|
return def?.type === "Parameter" && conventionalName;
|
|
@@ -14540,8 +14733,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
14540
14733
|
};
|
|
14541
14734
|
const isFormDataGetCall = (node) => {
|
|
14542
14735
|
const callee = node.callee;
|
|
14543
|
-
if (callee.type !==
|
|
14544
|
-
if (callee.property.type !==
|
|
14736
|
+
if (callee.type !== import_utils71.AST_NODE_TYPES.MemberExpression) return false;
|
|
14737
|
+
if (callee.property.type !== import_utils71.AST_NODE_TYPES.Identifier || !FORM_VALUE_METHODS.has(callee.property.name)) {
|
|
14545
14738
|
return false;
|
|
14546
14739
|
}
|
|
14547
14740
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -14557,16 +14750,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
14557
14750
|
const hasZodParseAncestor = (node) => zodParseAncestor(node) !== null;
|
|
14558
14751
|
const isInstanceofNarrowing = (node) => {
|
|
14559
14752
|
const parent = node.parent;
|
|
14560
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
14753
|
+
return parent !== null && parent !== void 0 && parent.type === import_utils71.AST_NODE_TYPES.BinaryExpression && parent.operator === "instanceof" && parent.left === node && parent.right.type === import_utils71.AST_NODE_TYPES.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
14561
14754
|
};
|
|
14562
14755
|
const boundDeclarator = (node) => {
|
|
14563
14756
|
let current = node;
|
|
14564
14757
|
let parent = current.parent;
|
|
14565
|
-
while ((parent.type ===
|
|
14758
|
+
while ((parent.type === import_utils71.AST_NODE_TYPES.TSAsExpression || parent.type === import_utils71.AST_NODE_TYPES.TSSatisfiesExpression || parent.type === import_utils71.AST_NODE_TYPES.TSNonNullExpression || parent.type === import_utils71.AST_NODE_TYPES.ChainExpression) && parent.expression === current) {
|
|
14566
14759
|
current = parent;
|
|
14567
14760
|
parent = current.parent;
|
|
14568
14761
|
}
|
|
14569
|
-
if (parent.type ===
|
|
14762
|
+
if (parent.type === import_utils71.AST_NODE_TYPES.VariableDeclarator && parent.init === current && parent.id.type === import_utils71.AST_NODE_TYPES.Identifier) {
|
|
14570
14763
|
return parent;
|
|
14571
14764
|
}
|
|
14572
14765
|
return null;
|
|
@@ -14575,7 +14768,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14575
14768
|
let current = node;
|
|
14576
14769
|
while (current.parent !== void 0) {
|
|
14577
14770
|
const parent = current.parent;
|
|
14578
|
-
if (parent.type ===
|
|
14771
|
+
if (parent.type === import_utils71.AST_NODE_TYPES.BlockStatement || parent.type === import_utils71.AST_NODE_TYPES.Program) {
|
|
14579
14772
|
return current;
|
|
14580
14773
|
}
|
|
14581
14774
|
current = parent;
|
|
@@ -14584,12 +14777,12 @@ var require_zod_form_validation_default = createRule({
|
|
|
14584
14777
|
};
|
|
14585
14778
|
const zodParseMethod = (call) => {
|
|
14586
14779
|
const callee = call.callee;
|
|
14587
|
-
return callee.type ===
|
|
14780
|
+
return callee.type === import_utils71.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils71.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
14588
14781
|
};
|
|
14589
14782
|
const hasConditionalAncestorBeforeStatement = (node, statement) => {
|
|
14590
14783
|
let current = node.parent;
|
|
14591
14784
|
while (current !== void 0 && current !== statement) {
|
|
14592
|
-
if (current.type ===
|
|
14785
|
+
if (current.type === import_utils71.AST_NODE_TYPES.LogicalExpression || current.type === import_utils71.AST_NODE_TYPES.ConditionalExpression) {
|
|
14593
14786
|
return true;
|
|
14594
14787
|
}
|
|
14595
14788
|
current = current.parent;
|
|
@@ -14599,7 +14792,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14599
14792
|
const isAwaitedBeforeStatement = (node, statement) => {
|
|
14600
14793
|
let current = node.parent;
|
|
14601
14794
|
while (current !== void 0 && current !== statement) {
|
|
14602
|
-
if (current.type ===
|
|
14795
|
+
if (current.type === import_utils71.AST_NODE_TYPES.AwaitExpression) return true;
|
|
14603
14796
|
current = current.parent;
|
|
14604
14797
|
}
|
|
14605
14798
|
return false;
|
|
@@ -14612,7 +14805,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14612
14805
|
if (declarationStatement === null || validationStatement === null || declarationStatement.parent !== validationStatement.parent || validationStatement.range[0] <= declarationStatement.range[1] || hasConditionalAncestorBeforeStatement(parse2, validationStatement)) {
|
|
14613
14806
|
return null;
|
|
14614
14807
|
}
|
|
14615
|
-
if (validationStatement.type !==
|
|
14808
|
+
if (validationStatement.type !== import_utils71.AST_NODE_TYPES.VariableDeclaration && validationStatement.type !== import_utils71.AST_NODE_TYPES.ExpressionStatement) {
|
|
14616
14809
|
return null;
|
|
14617
14810
|
}
|
|
14618
14811
|
const method = zodParseMethod(parse2);
|
|
@@ -14624,16 +14817,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
14624
14817
|
};
|
|
14625
14818
|
const isSafePrevalidationInspection = (identifier) => {
|
|
14626
14819
|
const parent = identifier.parent;
|
|
14627
|
-
if (parent.type ===
|
|
14820
|
+
if (parent.type === import_utils71.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof") {
|
|
14628
14821
|
return true;
|
|
14629
14822
|
}
|
|
14630
|
-
if (parent.type !==
|
|
14823
|
+
if (parent.type !== import_utils71.AST_NODE_TYPES.BinaryExpression || parent.left !== identifier) {
|
|
14631
14824
|
return false;
|
|
14632
14825
|
}
|
|
14633
14826
|
if (parent.operator === "instanceof") {
|
|
14634
|
-
return parent.right.type ===
|
|
14827
|
+
return parent.right.type === import_utils71.AST_NODE_TYPES.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
14635
14828
|
}
|
|
14636
|
-
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type ===
|
|
14829
|
+
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type === import_utils71.AST_NODE_TYPES.Literal && parent.right.value === null || parent.right.type === import_utils71.AST_NODE_TYPES.Identifier && parent.right.name === "undefined");
|
|
14637
14830
|
};
|
|
14638
14831
|
const isDescendantOf = (node, ancestor) => {
|
|
14639
14832
|
let current = node;
|
|
@@ -14644,23 +14837,23 @@ var require_zod_form_validation_default = createRule({
|
|
|
14644
14837
|
return false;
|
|
14645
14838
|
};
|
|
14646
14839
|
const blockTerminates = (node) => {
|
|
14647
|
-
if (node.type ===
|
|
14840
|
+
if (node.type === import_utils71.AST_NODE_TYPES.ReturnStatement || node.type === import_utils71.AST_NODE_TYPES.ThrowStatement) {
|
|
14648
14841
|
return true;
|
|
14649
14842
|
}
|
|
14650
|
-
if (node.type !==
|
|
14843
|
+
if (node.type !== import_utils71.AST_NODE_TYPES.BlockStatement || node.body.length === 0) return false;
|
|
14651
14844
|
const last = node.body.at(-1);
|
|
14652
14845
|
return last !== void 0 && blockTerminates(last);
|
|
14653
14846
|
};
|
|
14654
14847
|
const narrowingIf = (identifier) => {
|
|
14655
14848
|
const comparison = identifier.parent;
|
|
14656
|
-
if (comparison?.type !==
|
|
14849
|
+
if (comparison?.type !== import_utils71.AST_NODE_TYPES.BinaryExpression || comparison.operator !== "instanceof" || comparison.left !== identifier || comparison.right.type !== import_utils71.AST_NODE_TYPES.Identifier || comparison.right.name !== "File" && comparison.right.name !== "Blob") {
|
|
14657
14850
|
return null;
|
|
14658
14851
|
}
|
|
14659
14852
|
const maybeNegation = comparison.parent;
|
|
14660
|
-
const negated = maybeNegation?.type ===
|
|
14853
|
+
const negated = maybeNegation?.type === import_utils71.AST_NODE_TYPES.UnaryExpression && maybeNegation.operator === "!";
|
|
14661
14854
|
const test = negated ? maybeNegation : comparison;
|
|
14662
14855
|
const branch = test.parent;
|
|
14663
|
-
return branch?.type ===
|
|
14856
|
+
return branch?.type === import_utils71.AST_NODE_TYPES.IfStatement && branch.test === test ? { branch, positive: !negated } : null;
|
|
14664
14857
|
};
|
|
14665
14858
|
const useDominatedByNarrowing = (use, narrowings) => narrowings.some(({ branch, positive }) => {
|
|
14666
14859
|
if (positive) return isDescendantOf(use, branch.consequent);
|
|
@@ -14680,7 +14873,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14680
14873
|
const variable = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
14681
14874
|
if (variable === void 0) return false;
|
|
14682
14875
|
const references = variable.references.filter((reference) => !reference.isWriteOnly()).map((reference) => reference.identifier).filter(
|
|
14683
|
-
(identifier) => identifier.type ===
|
|
14876
|
+
(identifier) => identifier.type === import_utils71.AST_NODE_TYPES.Identifier
|
|
14684
14877
|
);
|
|
14685
14878
|
if (references.length === 0) return false;
|
|
14686
14879
|
const narrowings = references.map(narrowingIf).filter(
|
|
@@ -14706,7 +14899,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14706
14899
|
ImportDeclaration(node) {
|
|
14707
14900
|
if (!isZodModule(node.source.value)) return;
|
|
14708
14901
|
for (const specifier of node.specifiers) {
|
|
14709
|
-
if (specifier.type ===
|
|
14902
|
+
if (specifier.type === import_utils71.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils71.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils71.AST_NODE_TYPES.ImportSpecifier && (specifier.imported.type === import_utils71.AST_NODE_TYPES.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
14710
14903
|
const binding = resolvedBinding(specifier.local);
|
|
14711
14904
|
if (binding !== null) zodBindings.add(binding);
|
|
14712
14905
|
}
|
|
@@ -14727,7 +14920,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14727
14920
|
});
|
|
14728
14921
|
|
|
14729
14922
|
// src/rules/store-insert-requires-on-conflict.ts
|
|
14730
|
-
var
|
|
14923
|
+
var import_utils72 = require("@typescript-eslint/utils");
|
|
14731
14924
|
var storeInsertRequiresOnConflictDocumentation = {
|
|
14732
14925
|
summary: "Require embedded inserts in explicitly replayable callables to carry conflict handling.",
|
|
14733
14926
|
rationale: "A callable named as an enqueue, seed, migration, schedule, ensure, or upsert promises replay safety.",
|
|
@@ -14791,7 +14984,7 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
14791
14984
|
});
|
|
14792
14985
|
|
|
14793
14986
|
// src/rules/stepdown.ts
|
|
14794
|
-
var
|
|
14987
|
+
var import_utils73 = require("@typescript-eslint/utils");
|
|
14795
14988
|
var stepdownDocumentation = {
|
|
14796
14989
|
summary: "Place a private helper below its sole direct same-scope caller.",
|
|
14797
14990
|
rationale: "Caller-first ordering lets a reader follow the main flow before descending into implementation details.",
|
|
@@ -14808,7 +15001,7 @@ var stepdownDocumentation = {
|
|
|
14808
15001
|
]
|
|
14809
15002
|
};
|
|
14810
15003
|
function isFunction(node) {
|
|
14811
|
-
return node.type ===
|
|
15004
|
+
return node.type === import_utils73.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils73.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils73.AST_NODE_TYPES.FunctionExpression;
|
|
14812
15005
|
}
|
|
14813
15006
|
function reportMisordered(context, candidates, scopeDefinitions, calls, pinned, canMove = () => true) {
|
|
14814
15007
|
const byName = new Map(scopeDefinitions.map((definition) => [definition.name, definition]));
|
|
@@ -14903,8 +15096,8 @@ function moduleScope(context, program) {
|
|
|
14903
15096
|
for (const node of declarations) counts.set(node.name, (counts.get(node.name) ?? 0) + 1);
|
|
14904
15097
|
const overloadNames = new Set(
|
|
14905
15098
|
program.body.flatMap((statement) => {
|
|
14906
|
-
const node = statement.type ===
|
|
14907
|
-
return node?.type ===
|
|
15099
|
+
const node = statement.type === import_utils73.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
15100
|
+
return node?.type === import_utils73.AST_NODE_TYPES.TSDeclareFunction && node.id !== null ? [node.id.name] : [];
|
|
14908
15101
|
})
|
|
14909
15102
|
);
|
|
14910
15103
|
const exported = exportedNames(program);
|
|
@@ -14928,7 +15121,7 @@ function moduleScope(context, program) {
|
|
|
14928
15121
|
const nearestFunction2 = [...ancestors].reverse().find(isFunction);
|
|
14929
15122
|
const parent = identifier.parent;
|
|
14930
15123
|
const callerDefinition = nearestFunction2 === void 0 ? void 0 : byFunction.get(nearestFunction2);
|
|
14931
|
-
if (callerDefinition === void 0 || parent.type !==
|
|
15124
|
+
if (callerDefinition === void 0 || parent.type !== import_utils73.AST_NODE_TYPES.CallExpression || parent.callee !== identifier) {
|
|
14932
15125
|
pinned.add(definition.name);
|
|
14933
15126
|
continue;
|
|
14934
15127
|
}
|
|
@@ -14943,38 +15136,38 @@ function moduleScope(context, program) {
|
|
|
14943
15136
|
function exportedNames(program) {
|
|
14944
15137
|
const names = /* @__PURE__ */ new Set();
|
|
14945
15138
|
for (const statement of program.body) {
|
|
14946
|
-
if (statement.type !==
|
|
14947
|
-
if (statement.declaration?.type ===
|
|
15139
|
+
if (statement.type !== import_utils73.AST_NODE_TYPES.ExportNamedDeclaration || statement.exportKind === "type" || statement.source !== null) continue;
|
|
15140
|
+
if (statement.declaration?.type === import_utils73.AST_NODE_TYPES.FunctionDeclaration && statement.declaration.id !== null) {
|
|
14948
15141
|
names.add(statement.declaration.id.name);
|
|
14949
15142
|
}
|
|
14950
|
-
if (statement.declaration?.type ===
|
|
15143
|
+
if (statement.declaration?.type === import_utils73.AST_NODE_TYPES.VariableDeclaration) {
|
|
14951
15144
|
for (const declarator of statement.declaration.declarations) {
|
|
14952
|
-
if (declarator.id.type ===
|
|
15145
|
+
if (declarator.id.type === import_utils73.AST_NODE_TYPES.Identifier) names.add(declarator.id.name);
|
|
14953
15146
|
}
|
|
14954
15147
|
}
|
|
14955
15148
|
for (const specifier of statement.specifiers) {
|
|
14956
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
15149
|
+
if (specifier.exportKind !== "type" && specifier.local.type === import_utils73.AST_NODE_TYPES.Identifier) {
|
|
14957
15150
|
names.add(specifier.local.name);
|
|
14958
15151
|
}
|
|
14959
15152
|
}
|
|
14960
15153
|
}
|
|
14961
15154
|
for (const statement of program.body) {
|
|
14962
|
-
if (statement.type ===
|
|
14963
|
-
if (statement.type ===
|
|
15155
|
+
if (statement.type === import_utils73.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils73.AST_NODE_TYPES.Identifier) names.add(statement.declaration.name);
|
|
15156
|
+
if (statement.type === import_utils73.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils73.AST_NODE_TYPES.FunctionDeclaration && statement.declaration.id !== null) names.add(statement.declaration.id.name);
|
|
14964
15157
|
}
|
|
14965
15158
|
return names;
|
|
14966
15159
|
}
|
|
14967
15160
|
function moduleDefinitions(program) {
|
|
14968
15161
|
const definitions = [];
|
|
14969
15162
|
for (const statement of program.body) {
|
|
14970
|
-
const node = statement.type ===
|
|
14971
|
-
if (node?.type ===
|
|
15163
|
+
const node = statement.type === import_utils73.AST_NODE_TYPES.ExportNamedDeclaration || statement.type === import_utils73.AST_NODE_TYPES.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
15164
|
+
if (node?.type === import_utils73.AST_NODE_TYPES.FunctionDeclaration && node.id !== null && node.body !== null) {
|
|
14972
15165
|
definitions.push({ name: node.id.name, node, functionNode: node, bindingNode: node });
|
|
14973
15166
|
continue;
|
|
14974
15167
|
}
|
|
14975
|
-
if (node?.type !==
|
|
15168
|
+
if (node?.type !== import_utils73.AST_NODE_TYPES.VariableDeclaration || node.kind !== "const") continue;
|
|
14976
15169
|
for (const declarator of node.declarations) {
|
|
14977
|
-
if (declarator.id.type ===
|
|
15170
|
+
if (declarator.id.type === import_utils73.AST_NODE_TYPES.Identifier && declarator.init !== null && isFunction(declarator.init)) {
|
|
14978
15171
|
definitions.push({
|
|
14979
15172
|
name: declarator.id.name,
|
|
14980
15173
|
node: declarator,
|
|
@@ -14987,21 +15180,21 @@ function moduleDefinitions(program) {
|
|
|
14987
15180
|
return definitions;
|
|
14988
15181
|
}
|
|
14989
15182
|
function methodName(node) {
|
|
14990
|
-
if (node.key.type ===
|
|
14991
|
-
return !node.computed && node.key.type ===
|
|
15183
|
+
if (node.key.type === import_utils73.AST_NODE_TYPES.PrivateIdentifier) return `#${node.key.name}`;
|
|
15184
|
+
return !node.computed && node.key.type === import_utils73.AST_NODE_TYPES.Identifier ? node.key.name : null;
|
|
14992
15185
|
}
|
|
14993
15186
|
function referencedMethod(context, node, classVariables) {
|
|
14994
|
-
const objectVariable = node.object.type ===
|
|
15187
|
+
const objectVariable = node.object.type === import_utils73.AST_NODE_TYPES.Identifier ? import_utils73.ASTUtils.findVariable(context.sourceCode.getScope(node.object), node.object.name) : null;
|
|
14995
15188
|
const isClassReference = objectVariable !== null && classVariables.has(objectVariable);
|
|
14996
|
-
if (node.object.type !==
|
|
14997
|
-
if (node.property.type ===
|
|
14998
|
-
if (!node.computed && node.property.type ===
|
|
14999
|
-
return node.computed && node.property.type ===
|
|
15189
|
+
if (node.object.type !== import_utils73.AST_NODE_TYPES.ThisExpression && !isClassReference) return null;
|
|
15190
|
+
if (node.property.type === import_utils73.AST_NODE_TYPES.PrivateIdentifier) return `#${node.property.name}`;
|
|
15191
|
+
if (!node.computed && node.property.type === import_utils73.AST_NODE_TYPES.Identifier) return node.property.name;
|
|
15192
|
+
return node.computed && node.property.type === import_utils73.AST_NODE_TYPES.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
15000
15193
|
}
|
|
15001
15194
|
function referencedPropertyName(node) {
|
|
15002
|
-
if (node.property.type ===
|
|
15003
|
-
if (!node.computed && node.property.type ===
|
|
15004
|
-
return node.computed && node.property.type ===
|
|
15195
|
+
if (node.property.type === import_utils73.AST_NODE_TYPES.PrivateIdentifier) return `#${node.property.name}`;
|
|
15196
|
+
if (!node.computed && node.property.type === import_utils73.AST_NODE_TYPES.Identifier) return node.property.name;
|
|
15197
|
+
return node.computed && node.property.type === import_utils73.AST_NODE_TYPES.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
15005
15198
|
}
|
|
15006
15199
|
function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
15007
15200
|
visit(node, nestedFunction);
|
|
@@ -15017,7 +15210,7 @@ function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
|
15017
15210
|
}
|
|
15018
15211
|
function classScope(context, node, computedReferenceNames) {
|
|
15019
15212
|
const methods = node.body.body.filter(
|
|
15020
|
-
(member) => member.type ===
|
|
15213
|
+
(member) => member.type === import_utils73.AST_NODE_TYPES.MethodDefinition
|
|
15021
15214
|
);
|
|
15022
15215
|
const counts = /* @__PURE__ */ new Map();
|
|
15023
15216
|
for (const method of methods) {
|
|
@@ -15025,8 +15218,8 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15025
15218
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
15026
15219
|
}
|
|
15027
15220
|
for (const member of node.body.body) {
|
|
15028
|
-
if (member.type !==
|
|
15029
|
-
const name = !member.computed && member.key.type ===
|
|
15221
|
+
if (member.type !== import_utils73.AST_NODE_TYPES.TSAbstractMethodDefinition) continue;
|
|
15222
|
+
const name = !member.computed && member.key.type === import_utils73.AST_NODE_TYPES.Identifier ? member.key.name : null;
|
|
15030
15223
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
15031
15224
|
}
|
|
15032
15225
|
const scopeDefinitions = methods.flatMap((method) => {
|
|
@@ -15035,7 +15228,7 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15035
15228
|
});
|
|
15036
15229
|
const definitions = methods.flatMap((method) => {
|
|
15037
15230
|
const name = methodName(method);
|
|
15038
|
-
const isPrivate = method.accessibility === "private" || method.key.type ===
|
|
15231
|
+
const isPrivate = method.accessibility === "private" || method.key.type === import_utils73.AST_NODE_TYPES.PrivateIdentifier;
|
|
15039
15232
|
return name !== null && isPrivate && counts.get(name) === 1 && method.decorators.length === 0 ? [{ name, node: method }] : [];
|
|
15040
15233
|
});
|
|
15041
15234
|
if (definitions.length === 0) return;
|
|
@@ -15044,11 +15237,11 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15044
15237
|
const pinned = /* @__PURE__ */ new Set();
|
|
15045
15238
|
const classVariables = /* @__PURE__ */ new Set();
|
|
15046
15239
|
if (node.id !== null) {
|
|
15047
|
-
const internal =
|
|
15240
|
+
const internal = import_utils73.ASTUtils.findVariable(context.sourceCode.getScope(node), node.id.name);
|
|
15048
15241
|
if (internal !== null) classVariables.add(internal);
|
|
15049
15242
|
}
|
|
15050
|
-
if (node.type ===
|
|
15051
|
-
const outer =
|
|
15243
|
+
if (node.type === import_utils73.AST_NODE_TYPES.ClassExpression && node.parent.type === import_utils73.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === import_utils73.AST_NODE_TYPES.Identifier) {
|
|
15244
|
+
const outer = import_utils73.ASTUtils.findVariable(context.sourceCode.getScope(node.parent), node.parent.id.name);
|
|
15052
15245
|
if (outer !== null) classVariables.add(outer);
|
|
15053
15246
|
}
|
|
15054
15247
|
for (const method of methods) {
|
|
@@ -15064,27 +15257,27 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15064
15257
|
}
|
|
15065
15258
|
const thisValue = (value) => {
|
|
15066
15259
|
let current = value;
|
|
15067
|
-
while (current?.type ===
|
|
15068
|
-
return current?.type ===
|
|
15260
|
+
while (current?.type === import_utils73.AST_NODE_TYPES.TSAsExpression || current?.type === import_utils73.AST_NODE_TYPES.TSSatisfiesExpression || current?.type === import_utils73.AST_NODE_TYPES.TSNonNullExpression) current = current.expression;
|
|
15261
|
+
return current?.type === import_utils73.AST_NODE_TYPES.ThisExpression;
|
|
15069
15262
|
};
|
|
15070
15263
|
const collectAlias = (current, nestedFunction) => {
|
|
15071
|
-
if (nestedFunction || current.type !==
|
|
15072
|
-
if (current.type ===
|
|
15073
|
-
const binding = current.type ===
|
|
15074
|
-
const value = current.type ===
|
|
15264
|
+
if (nestedFunction || current.type !== import_utils73.AST_NODE_TYPES.VariableDeclarator && current.type !== import_utils73.AST_NODE_TYPES.AssignmentPattern) return;
|
|
15265
|
+
if (current.type === import_utils73.AST_NODE_TYPES.VariableDeclarator && (current.parent.type !== import_utils73.AST_NODE_TYPES.VariableDeclaration || current.parent.kind !== "const")) return;
|
|
15266
|
+
const binding = current.type === import_utils73.AST_NODE_TYPES.VariableDeclarator ? current.id : current.left;
|
|
15267
|
+
const value = current.type === import_utils73.AST_NODE_TYPES.VariableDeclarator ? current.init : current.right;
|
|
15075
15268
|
if (!thisValue(value)) return;
|
|
15076
|
-
if (binding.type ===
|
|
15269
|
+
if (binding.type === import_utils73.AST_NODE_TYPES.ObjectPattern) {
|
|
15077
15270
|
for (const property of binding.properties) {
|
|
15078
|
-
if (property.type ===
|
|
15271
|
+
if (property.type === import_utils73.AST_NODE_TYPES.RestElement) {
|
|
15079
15272
|
for (const name of privateNames) pinned.add(name);
|
|
15080
|
-
} else if (property.key.type ===
|
|
15273
|
+
} else if (property.key.type === import_utils73.AST_NODE_TYPES.Identifier && privateNames.has(property.key.name)) {
|
|
15081
15274
|
pinned.add(property.key.name);
|
|
15082
15275
|
}
|
|
15083
15276
|
}
|
|
15084
15277
|
return;
|
|
15085
15278
|
}
|
|
15086
|
-
if (binding.type !==
|
|
15087
|
-
const variable =
|
|
15279
|
+
if (binding.type !== import_utils73.AST_NODE_TYPES.Identifier) return;
|
|
15280
|
+
const variable = import_utils73.ASTUtils.findVariable(context.sourceCode.getScope(binding), binding.name);
|
|
15088
15281
|
if (variable !== null) {
|
|
15089
15282
|
methodClassVariables.add(variable);
|
|
15090
15283
|
methodAliases.add(variable);
|
|
@@ -15097,16 +15290,16 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15097
15290
|
walk(statement, context.sourceCode.visitorKeys, collectAlias);
|
|
15098
15291
|
}
|
|
15099
15292
|
const visitCall = (current, nestedFunction) => {
|
|
15100
|
-
if (current.type ===
|
|
15293
|
+
if (current.type === import_utils73.AST_NODE_TYPES.VariableDeclarator && current.id.type === import_utils73.AST_NODE_TYPES.ObjectPattern && thisValue(current.init)) {
|
|
15101
15294
|
for (const property of current.id.properties) {
|
|
15102
|
-
if (property.type ===
|
|
15295
|
+
if (property.type === import_utils73.AST_NODE_TYPES.RestElement) {
|
|
15103
15296
|
for (const name of privateNames) pinned.add(name);
|
|
15104
15297
|
continue;
|
|
15105
15298
|
}
|
|
15106
|
-
if (property.type ===
|
|
15299
|
+
if (property.type === import_utils73.AST_NODE_TYPES.Property && property.key.type === import_utils73.AST_NODE_TYPES.Identifier && privateNames.has(property.key.name)) pinned.add(property.key.name);
|
|
15107
15300
|
}
|
|
15108
15301
|
}
|
|
15109
|
-
if (current.type !==
|
|
15302
|
+
if (current.type !== import_utils73.AST_NODE_TYPES.MemberExpression) return;
|
|
15110
15303
|
const target = referencedMethod(context, current, methodClassVariables);
|
|
15111
15304
|
if (target === null) {
|
|
15112
15305
|
const possibleTarget = referencedPropertyName(current);
|
|
@@ -15114,12 +15307,12 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15114
15307
|
return;
|
|
15115
15308
|
}
|
|
15116
15309
|
if (!privateNames.has(target)) return;
|
|
15117
|
-
const objectVariable = current.object.type ===
|
|
15310
|
+
const objectVariable = current.object.type === import_utils73.AST_NODE_TYPES.Identifier ? import_utils73.ASTUtils.findVariable(context.sourceCode.getScope(current.object), current.object.name) : null;
|
|
15118
15311
|
if (objectVariable !== null && methodAliases.has(objectVariable)) {
|
|
15119
15312
|
pinned.add(target);
|
|
15120
15313
|
return;
|
|
15121
15314
|
}
|
|
15122
|
-
if (current.computed || nestedFunction || parameterDecoratorNodes.has(current) || current.parent.type !==
|
|
15315
|
+
if (current.computed || nestedFunction || parameterDecoratorNodes.has(current) || current.parent.type !== import_utils73.AST_NODE_TYPES.CallExpression || current.parent.callee !== current) {
|
|
15123
15316
|
pinned.add(target);
|
|
15124
15317
|
return;
|
|
15125
15318
|
}
|
|
@@ -15139,9 +15332,9 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15139
15332
|
}
|
|
15140
15333
|
}
|
|
15141
15334
|
for (const member of node.body.body) {
|
|
15142
|
-
if (member.type ===
|
|
15335
|
+
if (member.type === import_utils73.AST_NODE_TYPES.MethodDefinition || member.type === import_utils73.AST_NODE_TYPES.TSAbstractMethodDefinition) continue;
|
|
15143
15336
|
walk(member, context.sourceCode.visitorKeys, (current) => {
|
|
15144
|
-
if (current.type !==
|
|
15337
|
+
if (current.type !== import_utils73.AST_NODE_TYPES.MemberExpression) return;
|
|
15145
15338
|
const target = referencedMethod(context, current, classVariables);
|
|
15146
15339
|
const possibleTarget = target ?? referencedPropertyName(current);
|
|
15147
15340
|
if (possibleTarget !== null && privateNames.has(possibleTarget)) pinned.add(possibleTarget);
|
|
@@ -15151,14 +15344,14 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15151
15344
|
const accessibility = new Map(
|
|
15152
15345
|
scopeDefinitions.map((definition) => {
|
|
15153
15346
|
const method = definition.node;
|
|
15154
|
-
const accessibility2 = method.key.type ===
|
|
15347
|
+
const accessibility2 = method.key.type === import_utils73.AST_NODE_TYPES.PrivateIdentifier ? "private" : method.accessibility ?? "public";
|
|
15155
15348
|
return [definition.name, accessibility2];
|
|
15156
15349
|
})
|
|
15157
15350
|
);
|
|
15158
15351
|
const methodByName = new Map(scopeDefinitions.map((definition) => [definition.name, definition.node]));
|
|
15159
15352
|
for (const [caller, callees] of calls) {
|
|
15160
15353
|
const callerMethod = methodByName.get(caller);
|
|
15161
|
-
if (accessibility.get(caller) === "private" && callerMethod?.type ===
|
|
15354
|
+
if (accessibility.get(caller) === "private" && callerMethod?.type === import_utils73.AST_NODE_TYPES.MethodDefinition && callerMethod.decorators.length === 0) continue;
|
|
15162
15355
|
for (const callee of callees) pinned.add(callee);
|
|
15163
15356
|
}
|
|
15164
15357
|
const memberIndexes = new Map(node.body.body.map((member, index) => [member, index]));
|
|
@@ -15175,12 +15368,12 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15175
15368
|
}
|
|
15176
15369
|
function isClassRuntimeBarrier(member) {
|
|
15177
15370
|
switch (member.type) {
|
|
15178
|
-
case
|
|
15371
|
+
case import_utils73.AST_NODE_TYPES.StaticBlock:
|
|
15179
15372
|
return true;
|
|
15180
|
-
case
|
|
15181
|
-
case
|
|
15373
|
+
case import_utils73.AST_NODE_TYPES.PropertyDefinition:
|
|
15374
|
+
case import_utils73.AST_NODE_TYPES.AccessorProperty:
|
|
15182
15375
|
return member.static || member.computed || member.decorators.length > 0 || member.value !== null;
|
|
15183
|
-
case
|
|
15376
|
+
case import_utils73.AST_NODE_TYPES.MethodDefinition:
|
|
15184
15377
|
return member.computed || member.decorators.length > 0;
|
|
15185
15378
|
default:
|
|
15186
15379
|
return false;
|
|
@@ -15212,7 +15405,7 @@ var stepdown_default = createRule({
|
|
|
15212
15405
|
moduleScope(context, program);
|
|
15213
15406
|
const computedReferenceNames = /* @__PURE__ */ new Set();
|
|
15214
15407
|
walk(program, context.sourceCode.visitorKeys, (node) => {
|
|
15215
|
-
if (node.type ===
|
|
15408
|
+
if (node.type === import_utils73.AST_NODE_TYPES.MemberExpression && node.computed && node.property.type === import_utils73.AST_NODE_TYPES.Literal && typeof node.property.value === "string") computedReferenceNames.add(node.property.value);
|
|
15216
15409
|
});
|
|
15217
15410
|
for (const node of classes) classScope(context, node, computedReferenceNames);
|
|
15218
15411
|
}
|
|
@@ -15221,8 +15414,8 @@ var stepdown_default = createRule({
|
|
|
15221
15414
|
});
|
|
15222
15415
|
|
|
15223
15416
|
// src/rules/source-coupled-test.ts
|
|
15224
|
-
var
|
|
15225
|
-
var GENERAL_SOURCE_SUFFIX_RE = /\.(?:bash|sh|ya?ml|py|[cm]?[jt]s)$/iu;
|
|
15417
|
+
var import_utils74 = require("@typescript-eslint/utils");
|
|
15418
|
+
var GENERAL_SOURCE_SUFFIX_RE = /\.(?:bash|sh|ya?ml|jsonc|py|[cm]?[jt]s)$/iu;
|
|
15226
15419
|
var FS_MODULES = /* @__PURE__ */ new Set(["fs", "node:fs", "fs/promises", "node:fs/promises"]);
|
|
15227
15420
|
var FS_READERS = /* @__PURE__ */ new Set(["readFile", "readFileSync"]);
|
|
15228
15421
|
var TEXT_TRANSFORMS = /* @__PURE__ */ new Set([
|
|
@@ -15290,20 +15483,20 @@ var sourceCoupledTestDocumentation = {
|
|
|
15290
15483
|
]
|
|
15291
15484
|
};
|
|
15292
15485
|
function staticMemberName7(node) {
|
|
15293
|
-
if (!node.computed && node.property.type ===
|
|
15294
|
-
if (node.computed && node.property.type ===
|
|
15486
|
+
if (!node.computed && node.property.type === import_utils74.AST_NODE_TYPES.Identifier) return node.property.name;
|
|
15487
|
+
if (node.computed && node.property.type === import_utils74.AST_NODE_TYPES.Literal && typeof node.property.value === "string") return node.property.value;
|
|
15295
15488
|
return null;
|
|
15296
15489
|
}
|
|
15297
15490
|
function unwrap5(node) {
|
|
15298
|
-
if (node.type ===
|
|
15299
|
-
if (node.type ===
|
|
15300
|
-
if (node.type ===
|
|
15491
|
+
if (node.type === import_utils74.AST_NODE_TYPES.AwaitExpression) return unwrap5(node.argument);
|
|
15492
|
+
if (node.type === import_utils74.AST_NODE_TYPES.ChainExpression) return unwrap5(node.expression);
|
|
15493
|
+
if (node.type === import_utils74.AST_NODE_TYPES.TSAsExpression || node.type === import_utils74.AST_NODE_TYPES.TSNonNullExpression || node.type === import_utils74.AST_NODE_TYPES.TSTypeAssertion) return unwrap5(node.expression);
|
|
15301
15494
|
return node;
|
|
15302
15495
|
}
|
|
15303
15496
|
function stringValue(node) {
|
|
15304
15497
|
const current = unwrap5(node);
|
|
15305
|
-
if (current.type ===
|
|
15306
|
-
if (current.type ===
|
|
15498
|
+
if (current.type === import_utils74.AST_NODE_TYPES.Literal && typeof current.value === "string") return current.value;
|
|
15499
|
+
if (current.type === import_utils74.AST_NODE_TYPES.TemplateLiteral && current.expressions.length === 0) return current.quasis[0]?.value.cooked ?? null;
|
|
15307
15500
|
return null;
|
|
15308
15501
|
}
|
|
15309
15502
|
function importSource(node) {
|
|
@@ -15311,7 +15504,7 @@ function importSource(node) {
|
|
|
15311
15504
|
}
|
|
15312
15505
|
function requireSource(node) {
|
|
15313
15506
|
const current = unwrap5(node);
|
|
15314
|
-
if (current.type !==
|
|
15507
|
+
if (current.type !== import_utils74.AST_NODE_TYPES.CallExpression || current.callee.type !== import_utils74.AST_NODE_TYPES.Identifier || current.callee.name !== "require" || current.arguments.length !== 1 || current.arguments[0]?.type === import_utils74.AST_NODE_TYPES.SpreadElement) return null;
|
|
15315
15508
|
return stringValue(current.arguments[0]);
|
|
15316
15509
|
}
|
|
15317
15510
|
function newScope() {
|
|
@@ -15351,38 +15544,38 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
15351
15544
|
const current = unwrap5(node);
|
|
15352
15545
|
const value = stringValue(current);
|
|
15353
15546
|
if (value !== null) return sourceSuffixRe.test(value);
|
|
15354
|
-
if (current.type ===
|
|
15355
|
-
if (current.type ===
|
|
15547
|
+
if (current.type === import_utils74.AST_NODE_TYPES.Identifier) return visible("paths", current.name);
|
|
15548
|
+
if (current.type === import_utils74.AST_NODE_TYPES.BinaryExpression && current.operator === "+") {
|
|
15356
15549
|
return sourcePath(current.left) || sourcePath(current.right);
|
|
15357
15550
|
}
|
|
15358
|
-
if (current.type ===
|
|
15359
|
-
if (current.type ===
|
|
15360
|
-
return current.arguments.some((argument) => argument.type !==
|
|
15551
|
+
if (current.type === import_utils74.AST_NODE_TYPES.TemplateLiteral) return current.expressions.some(sourcePath);
|
|
15552
|
+
if (current.type === import_utils74.AST_NODE_TYPES.CallExpression || current.type === import_utils74.AST_NODE_TYPES.NewExpression) {
|
|
15553
|
+
return current.arguments.some((argument) => argument.type !== import_utils74.AST_NODE_TYPES.SpreadElement && sourcePath(argument));
|
|
15361
15554
|
}
|
|
15362
|
-
if (current.type ===
|
|
15555
|
+
if (current.type === import_utils74.AST_NODE_TYPES.MemberExpression) return sourcePath(current.object);
|
|
15363
15556
|
return false;
|
|
15364
15557
|
};
|
|
15365
15558
|
const rawRead = (node) => {
|
|
15366
15559
|
const current = unwrap5(node);
|
|
15367
|
-
if (current.type !==
|
|
15560
|
+
if (current.type !== import_utils74.AST_NODE_TYPES.CallExpression || current.arguments.length === 0) return false;
|
|
15368
15561
|
const callee = unwrap5(current.callee);
|
|
15369
|
-
if (callee.type ===
|
|
15562
|
+
if (callee.type === import_utils74.AST_NODE_TYPES.Identifier) {
|
|
15370
15563
|
return visible("fsReaders", callee.name) && sourcePath(current.arguments[0]);
|
|
15371
15564
|
}
|
|
15372
|
-
if (callee.type !==
|
|
15565
|
+
if (callee.type !== import_utils74.AST_NODE_TYPES.MemberExpression) return false;
|
|
15373
15566
|
const name2 = staticMemberName7(callee);
|
|
15374
15567
|
const object = unwrap5(callee.object);
|
|
15375
|
-
return name2 !== null && FS_READERS.has(name2) && object.type ===
|
|
15568
|
+
return name2 !== null && FS_READERS.has(name2) && object.type === import_utils74.AST_NODE_TYPES.Identifier && visible("fsObjects", object.name) && sourcePath(current.arguments[0]);
|
|
15376
15569
|
};
|
|
15377
15570
|
const rawOrigins = (node) => {
|
|
15378
15571
|
const current = unwrap5(node);
|
|
15379
|
-
if (current.type ===
|
|
15572
|
+
if (current.type === import_utils74.AST_NODE_TYPES.Identifier) return visibleRawOrigins(current.name);
|
|
15380
15573
|
if (rawRead(current)) return /* @__PURE__ */ new Set([`${current.range[0]}:${current.range[1]}`]);
|
|
15381
|
-
if (current.type ===
|
|
15382
|
-
if (current.type ===
|
|
15383
|
-
if (current.type !==
|
|
15574
|
+
if (current.type === import_utils74.AST_NODE_TYPES.BinaryExpression && current.operator === "+") return /* @__PURE__ */ new Set([...rawOrigins(current.left), ...rawOrigins(current.right)]);
|
|
15575
|
+
if (current.type === import_utils74.AST_NODE_TYPES.MemberExpression && staticMemberName7(current) === "length") return rawOrigins(current.object);
|
|
15576
|
+
if (current.type !== import_utils74.AST_NODE_TYPES.CallExpression) return /* @__PURE__ */ new Set();
|
|
15384
15577
|
const callee = unwrap5(current.callee);
|
|
15385
|
-
if (callee.type !==
|
|
15578
|
+
if (callee.type !== import_utils74.AST_NODE_TYPES.MemberExpression) return /* @__PURE__ */ new Set();
|
|
15386
15579
|
const name2 = staticMemberName7(callee);
|
|
15387
15580
|
return name2 !== null && TEXT_TRANSFORMS.has(name2) ? rawOrigins(callee.object) : /* @__PURE__ */ new Set();
|
|
15388
15581
|
};
|
|
@@ -15390,32 +15583,39 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
15390
15583
|
const current = unwrap5(node);
|
|
15391
15584
|
const direct = rawOrigins(current);
|
|
15392
15585
|
if (direct.size > 0) return direct;
|
|
15393
|
-
if (current.type ===
|
|
15394
|
-
if (current.type ===
|
|
15395
|
-
if (current.type !==
|
|
15586
|
+
if (current.type === import_utils74.AST_NODE_TYPES.BinaryExpression || current.type === import_utils74.AST_NODE_TYPES.LogicalExpression) return /* @__PURE__ */ new Set([...evidenceOrigins(current.left), ...evidenceOrigins(current.right)]);
|
|
15587
|
+
if (current.type === import_utils74.AST_NODE_TYPES.UnaryExpression) return evidenceOrigins(current.argument);
|
|
15588
|
+
if (current.type !== import_utils74.AST_NODE_TYPES.CallExpression) return /* @__PURE__ */ new Set();
|
|
15396
15589
|
const callee = unwrap5(current.callee);
|
|
15397
|
-
if (callee.type !==
|
|
15590
|
+
if (callee.type !== import_utils74.AST_NODE_TYPES.MemberExpression) return /* @__PURE__ */ new Set();
|
|
15398
15591
|
const name2 = staticMemberName7(callee);
|
|
15399
15592
|
if (name2 !== null && TEXT_PREDICATES.has(name2)) return rawOrigins(callee.object);
|
|
15400
|
-
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type ===
|
|
15593
|
+
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type === import_utils74.AST_NODE_TYPES.SpreadElement ? [] : [...rawOrigins(argument)]));
|
|
15401
15594
|
return /* @__PURE__ */ new Set();
|
|
15402
15595
|
};
|
|
15403
15596
|
const rawAssertionOrigins = (node) => {
|
|
15404
15597
|
const callee = unwrap5(node.callee);
|
|
15405
|
-
if (callee.type ===
|
|
15406
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
15598
|
+
if (callee.type === import_utils74.AST_NODE_TYPES.Identifier && callee.name === "assert") {
|
|
15599
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === import_utils74.AST_NODE_TYPES.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
15407
15600
|
}
|
|
15408
|
-
if (callee.type !==
|
|
15601
|
+
if (callee.type !== import_utils74.AST_NODE_TYPES.MemberExpression) return /* @__PURE__ */ new Set();
|
|
15409
15602
|
const matcher = staticMemberName7(callee);
|
|
15410
15603
|
if (matcher === null) return /* @__PURE__ */ new Set();
|
|
15411
15604
|
let receiver = unwrap5(callee.object);
|
|
15412
|
-
while (receiver.type ===
|
|
15413
|
-
if (receiver.type ===
|
|
15605
|
+
while (receiver.type === import_utils74.AST_NODE_TYPES.MemberExpression && EXPECT_MODIFIERS2.has(staticMemberName7(receiver) ?? "")) receiver = unwrap5(receiver.object);
|
|
15606
|
+
if (receiver.type === import_utils74.AST_NODE_TYPES.CallExpression && receiver.callee.type === import_utils74.AST_NODE_TYPES.Identifier && receiver.callee.name === "expect") {
|
|
15414
15607
|
if (!EXPECT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
15415
|
-
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type ===
|
|
15608
|
+
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type === import_utils74.AST_NODE_TYPES.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
15416
15609
|
}
|
|
15417
|
-
if (receiver.type !==
|
|
15418
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
15610
|
+
if (receiver.type !== import_utils74.AST_NODE_TYPES.Identifier || receiver.name !== "assert" || !ASSERT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
15611
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === import_utils74.AST_NODE_TYPES.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
15612
|
+
};
|
|
15613
|
+
const rawRegexExtractionOrigins = (node) => {
|
|
15614
|
+
const callee = unwrap5(node.callee);
|
|
15615
|
+
if (callee.type !== import_utils74.AST_NODE_TYPES.MemberExpression || staticMemberName7(callee) !== "matchAll" || node.arguments.length !== 1) return /* @__PURE__ */ new Set();
|
|
15616
|
+
const argument = node.arguments[0];
|
|
15617
|
+
if (argument?.type !== import_utils74.AST_NODE_TYPES.Literal || !(argument.value instanceof RegExp)) return /* @__PURE__ */ new Set();
|
|
15618
|
+
return rawOrigins(callee.object);
|
|
15419
15619
|
};
|
|
15420
15620
|
const declare = (name2, state) => {
|
|
15421
15621
|
const scope = currentScope();
|
|
@@ -15435,15 +15635,15 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
15435
15635
|
};
|
|
15436
15636
|
const sourceCollection = (node) => {
|
|
15437
15637
|
const current = unwrap5(node);
|
|
15438
|
-
return current.type ===
|
|
15638
|
+
return current.type === import_utils74.AST_NODE_TYPES.ArrayExpression && current.elements.length > 0 && current.elements.every((element) => element !== null && element.type !== import_utils74.AST_NODE_TYPES.SpreadElement && sourcePath(element));
|
|
15439
15639
|
};
|
|
15440
15640
|
const declaredNames2 = (node) => {
|
|
15441
15641
|
const current = unwrap5(node);
|
|
15442
|
-
if (current.type ===
|
|
15443
|
-
if (current.type ===
|
|
15444
|
-
if (current.type ===
|
|
15445
|
-
if (current.type ===
|
|
15446
|
-
if (current.type ===
|
|
15642
|
+
if (current.type === import_utils74.AST_NODE_TYPES.Identifier) return [current.name];
|
|
15643
|
+
if (current.type === import_utils74.AST_NODE_TYPES.AssignmentPattern) return declaredNames2(current.left);
|
|
15644
|
+
if (current.type === import_utils74.AST_NODE_TYPES.RestElement) return declaredNames2(current.argument);
|
|
15645
|
+
if (current.type === import_utils74.AST_NODE_TYPES.ArrayPattern) return current.elements.flatMap((element) => element === null ? [] : declaredNames2(element));
|
|
15646
|
+
if (current.type === import_utils74.AST_NODE_TYPES.ObjectPattern) return current.properties.flatMap((property) => property.type === import_utils74.AST_NODE_TYPES.RestElement ? declaredNames2(property.argument) : declaredNames2(property.value));
|
|
15447
15647
|
return [];
|
|
15448
15648
|
};
|
|
15449
15649
|
const enterFunction = (node) => {
|
|
@@ -15458,8 +15658,8 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
15458
15658
|
const source = importSource(node);
|
|
15459
15659
|
if (source === null || !FS_MODULES.has(source)) return;
|
|
15460
15660
|
for (const specifier of node.specifiers) {
|
|
15461
|
-
if (specifier.type ===
|
|
15462
|
-
const imported = specifier.imported.type ===
|
|
15661
|
+
if (specifier.type === import_utils74.AST_NODE_TYPES.ImportSpecifier) {
|
|
15662
|
+
const imported = specifier.imported.type === import_utils74.AST_NODE_TYPES.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
15463
15663
|
if (FS_READERS.has(imported)) declare(specifier.local.name, { fsReader: true });
|
|
15464
15664
|
} else {
|
|
15465
15665
|
declare(specifier.local.name, { fsObject: true });
|
|
@@ -15471,32 +15671,35 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
15471
15671
|
VariableDeclarator(node) {
|
|
15472
15672
|
if (node.init === null) return;
|
|
15473
15673
|
const required = requireSource(node.init);
|
|
15474
|
-
if (required !== null && FS_MODULES.has(required) && node.id.type ===
|
|
15674
|
+
if (required !== null && FS_MODULES.has(required) && node.id.type === import_utils74.AST_NODE_TYPES.Identifier) {
|
|
15475
15675
|
declare(node.id.name, { fsObject: true });
|
|
15476
15676
|
return;
|
|
15477
15677
|
}
|
|
15478
|
-
if (node.id.type ===
|
|
15678
|
+
if (node.id.type === import_utils74.AST_NODE_TYPES.ObjectPattern && required !== null && FS_MODULES.has(required)) {
|
|
15479
15679
|
for (const property of node.id.properties) {
|
|
15480
|
-
if (property.type !==
|
|
15481
|
-
const key = property.key.type ===
|
|
15680
|
+
if (property.type !== import_utils74.AST_NODE_TYPES.Property || property.value.type !== import_utils74.AST_NODE_TYPES.Identifier) continue;
|
|
15681
|
+
const key = property.key.type === import_utils74.AST_NODE_TYPES.Identifier ? property.key.name : property.key.type === import_utils74.AST_NODE_TYPES.Literal ? String(property.key.value) : "";
|
|
15482
15682
|
if (FS_READERS.has(key)) declare(property.value.name, { fsReader: true });
|
|
15483
15683
|
}
|
|
15484
15684
|
return;
|
|
15485
15685
|
}
|
|
15486
|
-
if (node.id.type !==
|
|
15686
|
+
if (node.id.type !== import_utils74.AST_NODE_TYPES.Identifier) return;
|
|
15487
15687
|
declare(node.id.name, { collection: sourceCollection(node.init), path: sourcePath(node.init), rawOrigins: rawOrigins(node.init) });
|
|
15488
15688
|
},
|
|
15489
15689
|
AssignmentExpression(node) {
|
|
15490
|
-
if (node.left.type ===
|
|
15690
|
+
if (node.left.type === import_utils74.AST_NODE_TYPES.Identifier) declare(node.left.name, { path: sourcePath(node.right), rawOrigins: rawOrigins(node.right) });
|
|
15491
15691
|
},
|
|
15492
15692
|
ForOfStatement(node) {
|
|
15493
15693
|
const right = unwrap5(node.right);
|
|
15494
|
-
const collection = right.type ===
|
|
15495
|
-
const left = node.left.type ===
|
|
15496
|
-
if (collection && left?.type ===
|
|
15694
|
+
const collection = right.type === import_utils74.AST_NODE_TYPES.Identifier && visible("collections", right.name);
|
|
15695
|
+
const left = node.left.type === import_utils74.AST_NODE_TYPES.VariableDeclaration ? node.left.declarations[0]?.id : node.left;
|
|
15696
|
+
if (collection && left?.type === import_utils74.AST_NODE_TYPES.Identifier) declare(left.name, { path: true });
|
|
15497
15697
|
},
|
|
15498
15698
|
CallExpression(node) {
|
|
15499
|
-
const origins =
|
|
15699
|
+
const origins = /* @__PURE__ */ new Set([
|
|
15700
|
+
...rawAssertionOrigins(node),
|
|
15701
|
+
...rawRegexExtractionOrigins(node)
|
|
15702
|
+
]);
|
|
15500
15703
|
if (origins.size === 0 || [...origins].every((origin) => reportedOrigins.has(origin))) return;
|
|
15501
15704
|
for (const origin of origins) reportedOrigins.add(origin);
|
|
15502
15705
|
context.report({ node, messageId: "rawSourceOracle" });
|
|
@@ -15550,7 +15753,7 @@ var iac_source_coupled_test_default = createSourceCoupledRule(
|
|
|
15550
15753
|
);
|
|
15551
15754
|
|
|
15552
15755
|
// src/rules/zod-naming-convention.ts
|
|
15553
|
-
var
|
|
15756
|
+
var import_utils75 = require("@typescript-eslint/utils");
|
|
15554
15757
|
var zodNamingConventionDocumentation = {
|
|
15555
15758
|
summary: "Enforce a consistent Zod schema naming convention \u2014 a `Z` prefix (`ZUser`) or a `Schema` suffix (`userSchema`); both are accepted by default.",
|
|
15556
15759
|
rationale: "A recognizable schema name distinguishes runtime validators from ordinary values at each use site.",
|
|
@@ -15591,18 +15794,18 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
15591
15794
|
"prettifyError",
|
|
15592
15795
|
"treeifyError"
|
|
15593
15796
|
]);
|
|
15594
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
15797
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === import_utils75.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
15595
15798
|
var calleeChainRoot = (node) => {
|
|
15596
15799
|
let current = node;
|
|
15597
15800
|
for (; ; ) {
|
|
15598
|
-
if (current.type ===
|
|
15801
|
+
if (current.type === import_utils75.AST_NODE_TYPES.Identifier) {
|
|
15599
15802
|
return current;
|
|
15600
15803
|
}
|
|
15601
|
-
if (current.type ===
|
|
15804
|
+
if (current.type === import_utils75.AST_NODE_TYPES.MemberExpression) {
|
|
15602
15805
|
current = current.object;
|
|
15603
15806
|
continue;
|
|
15604
15807
|
}
|
|
15605
|
-
if (current.type ===
|
|
15808
|
+
if (current.type === import_utils75.AST_NODE_TYPES.CallExpression) {
|
|
15606
15809
|
current = current.callee;
|
|
15607
15810
|
continue;
|
|
15608
15811
|
}
|
|
@@ -15642,7 +15845,7 @@ var zod_naming_convention_default = createRule({
|
|
|
15642
15845
|
const acceptsSchemaWord = convention !== "prefix";
|
|
15643
15846
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
15644
15847
|
function resolvedBinding(identifier) {
|
|
15645
|
-
return
|
|
15848
|
+
return import_utils75.ASTUtils.findVariable(
|
|
15646
15849
|
context.sourceCode.getScope(identifier),
|
|
15647
15850
|
identifier.name
|
|
15648
15851
|
);
|
|
@@ -15664,7 +15867,7 @@ var zod_naming_convention_default = createRule({
|
|
|
15664
15867
|
ImportDeclaration(node) {
|
|
15665
15868
|
if (!isZodModule(node.source.value)) return;
|
|
15666
15869
|
for (const specifier of node.specifiers) {
|
|
15667
|
-
if (specifier.type ===
|
|
15870
|
+
if (specifier.type === import_utils75.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils75.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils75.AST_NODE_TYPES.ImportSpecifier && (specifier.imported.type === import_utils75.AST_NODE_TYPES.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
15668
15871
|
recordZodBinding(specifier.local);
|
|
15669
15872
|
}
|
|
15670
15873
|
}
|
|
@@ -15672,13 +15875,13 @@ var zod_naming_convention_default = createRule({
|
|
|
15672
15875
|
VariableDeclarator(node) {
|
|
15673
15876
|
const init = node.init;
|
|
15674
15877
|
if (init === null || init === void 0) return;
|
|
15675
|
-
if (init.type !==
|
|
15878
|
+
if (init.type !== import_utils75.AST_NODE_TYPES.CallExpression) return;
|
|
15676
15879
|
const callee = init.callee;
|
|
15677
|
-
if (callee.type !==
|
|
15880
|
+
if (callee.type !== import_utils75.AST_NODE_TYPES.MemberExpression) return;
|
|
15678
15881
|
if (!isZodChain(callee)) return;
|
|
15679
15882
|
const terminal = terminalMethodName(callee);
|
|
15680
15883
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
15681
|
-
if (node.id.type !==
|
|
15884
|
+
if (node.id.type !== import_utils75.AST_NODE_TYPES.Identifier) return;
|
|
15682
15885
|
if (test.test(node.id.name)) return;
|
|
15683
15886
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
15684
15887
|
context.report({
|
|
@@ -15816,6 +16019,7 @@ var rules = {
|
|
|
15816
16019
|
"no-unsafe-mock-casting": no_unsafe_mock_casting_default,
|
|
15817
16020
|
"no-zod-native-enum": no_zod_native_enum_default,
|
|
15818
16021
|
"test-loops-over-literal-cases": test_loops_over_literal_cases_default,
|
|
16022
|
+
"test-phase-label-comment": test_phase_label_comment_default,
|
|
15819
16023
|
"prefer-constant-time-secret-compare": prefer_constant_time_secret_compare_default,
|
|
15820
16024
|
"prefer-discriminated-union": prefer_discriminated_union_default,
|
|
15821
16025
|
"prefer-input-group-search": prefer_input_group_search_default,
|
|
@@ -15844,7 +16048,7 @@ var rules = {
|
|
|
15844
16048
|
};
|
|
15845
16049
|
var meta = {
|
|
15846
16050
|
name: "@sarj/eslint-plugin",
|
|
15847
|
-
version: "15.
|
|
16051
|
+
version: "15.10.0"
|
|
15848
16052
|
};
|
|
15849
16053
|
var applicationOnlyRules = [
|
|
15850
16054
|
"no-restricted-library-load",
|
|
@@ -15855,7 +16059,8 @@ var advisoryRules = [
|
|
|
15855
16059
|
"no-bare-return-from-test-catch",
|
|
15856
16060
|
"iac-source-coupled-test",
|
|
15857
16061
|
"repeated-static-call-cases",
|
|
15858
|
-
"source-coupled-test"
|
|
16062
|
+
"source-coupled-test",
|
|
16063
|
+
"test-phase-label-comment"
|
|
15859
16064
|
];
|
|
15860
16065
|
var recommendedRules = {
|
|
15861
16066
|
"@sarj/iac-source-coupled-test": "warn",
|
|
@@ -15919,6 +16124,7 @@ var recommendedRules = {
|
|
|
15919
16124
|
"@sarj/store-insert-requires-on-conflict": "error",
|
|
15920
16125
|
"@sarj/stepdown": "error",
|
|
15921
16126
|
"@sarj/source-coupled-test": "warn",
|
|
16127
|
+
"@sarj/test-phase-label-comment": "warn",
|
|
15922
16128
|
"@sarj/zod-naming-convention": "error"
|
|
15923
16129
|
};
|
|
15924
16130
|
var strictRules = {
|
|
@@ -15987,6 +16193,7 @@ var strictRules = {
|
|
|
15987
16193
|
"@sarj/store-insert-requires-on-conflict": "error",
|
|
15988
16194
|
"@sarj/stepdown": "error",
|
|
15989
16195
|
"@sarj/source-coupled-test": "warn",
|
|
16196
|
+
"@sarj/test-phase-label-comment": "warn",
|
|
15990
16197
|
"@sarj/zod-naming-convention": "error"
|
|
15991
16198
|
};
|
|
15992
16199
|
var plugin = {
|