@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.js
CHANGED
|
@@ -4679,11 +4679,11 @@ var no_offset_pagination_default = createRule({
|
|
|
4679
4679
|
// src/rules/no-positional-tuple-return.ts
|
|
4680
4680
|
import { AST_NODE_TYPES as AST_NODE_TYPES18 } from "@typescript-eslint/utils";
|
|
4681
4681
|
var noPositionalTupleReturnDocumentation = {
|
|
4682
|
-
summary: "Disallow returning a multi-field tuple from
|
|
4683
|
-
rationale: "
|
|
4682
|
+
summary: "Disallow returning a multi-field tuple from a named function; return a named object so call sites cannot mismatch slots.",
|
|
4683
|
+
rationale: "Tuple fields are identified only by position, so reordering can preserve types while changing meaning.",
|
|
4684
4684
|
remediation: "Return an object whose property names describe each value.",
|
|
4685
4685
|
category: "maintainability",
|
|
4686
|
-
limitations: ["
|
|
4686
|
+
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."],
|
|
4687
4687
|
examples: [
|
|
4688
4688
|
{ 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 },
|
|
4689
4689
|
{ 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 }
|
|
@@ -4721,6 +4721,16 @@ function tupleReturnType(node, aliases, resolving = /* @__PURE__ */ new Set()) {
|
|
|
4721
4721
|
}
|
|
4722
4722
|
return null;
|
|
4723
4723
|
}
|
|
4724
|
+
function tupleExpression(node, aliases) {
|
|
4725
|
+
if (node.type !== AST_NODE_TYPES18.TSAsExpression && node.type !== AST_NODE_TYPES18.TSSatisfiesExpression) {
|
|
4726
|
+
return null;
|
|
4727
|
+
}
|
|
4728
|
+
if (node.expression.type !== AST_NODE_TYPES18.ArrayExpression || node.expression.elements.length < MIN_ELEMENTS) {
|
|
4729
|
+
return null;
|
|
4730
|
+
}
|
|
4731
|
+
if (node.type === AST_NODE_TYPES18.TSAsExpression && node.typeAnnotation.type === AST_NODE_TYPES18.TSTypeReference && node.typeAnnotation.typeName.type === AST_NODE_TYPES18.Identifier && node.typeAnnotation.typeName.name === "const") return node.expression;
|
|
4732
|
+
return tupleReturnType(node.typeAnnotation, aliases) === null ? null : node.expression;
|
|
4733
|
+
}
|
|
4724
4734
|
function functionName(node) {
|
|
4725
4735
|
if (node.type === AST_NODE_TYPES18.FunctionDeclaration) {
|
|
4726
4736
|
if (node.id !== null) return node.id.name;
|
|
@@ -4736,60 +4746,25 @@ function functionName(node) {
|
|
|
4736
4746
|
return parent.id.name;
|
|
4737
4747
|
}
|
|
4738
4748
|
if ((parent?.type === AST_NODE_TYPES18.MethodDefinition || parent?.type === AST_NODE_TYPES18.TSAbstractMethodDefinition || parent?.type === AST_NODE_TYPES18.PropertyDefinition || parent?.type === AST_NODE_TYPES18.Property) && parent.key.type === AST_NODE_TYPES18.Identifier) {
|
|
4739
|
-
if ((parent.type === AST_NODE_TYPES18.MethodDefinition || parent.type === AST_NODE_TYPES18.TSAbstractMethodDefinition || parent.type === AST_NODE_TYPES18.PropertyDefinition) && (parent.accessibility === "private" || parent.accessibility === "protected")) return null;
|
|
4740
4749
|
return parent.key.name;
|
|
4741
4750
|
}
|
|
4742
4751
|
return null;
|
|
4743
4752
|
}
|
|
4744
|
-
function
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
return false;
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
}
|
|
4759
|
-
if (current.parent?.type !== AST_NODE_TYPES18.Program) {
|
|
4760
|
-
return null;
|
|
4761
|
-
}
|
|
4762
|
-
let topLevel = current;
|
|
4763
|
-
if (current.type === AST_NODE_TYPES18.ExportNamedDeclaration || current.type === AST_NODE_TYPES18.ExportDefaultDeclaration) {
|
|
4764
|
-
topLevel = current.declaration;
|
|
4765
|
-
}
|
|
4766
|
-
if (topLevel === null) return null;
|
|
4767
|
-
if (topLevel.type === AST_NODE_TYPES18.FunctionDeclaration) {
|
|
4768
|
-
if (topLevel !== node) return null;
|
|
4769
|
-
return topLevel.id?.name ?? (current.type === AST_NODE_TYPES18.ExportDefaultDeclaration ? "default" : null);
|
|
4770
|
-
}
|
|
4771
|
-
if ((topLevel.type === AST_NODE_TYPES18.ArrowFunctionExpression || topLevel.type === AST_NODE_TYPES18.FunctionExpression) && topLevel === node && current.type === AST_NODE_TYPES18.ExportDefaultDeclaration) {
|
|
4772
|
-
return "default";
|
|
4773
|
-
}
|
|
4774
|
-
if (topLevel.type === AST_NODE_TYPES18.ClassDeclaration) {
|
|
4775
|
-
let owner = node.parent;
|
|
4776
|
-
while (owner != null && owner.parent !== topLevel.body) owner = owner.parent;
|
|
4777
|
-
return (owner?.type === AST_NODE_TYPES18.MethodDefinition || owner?.type === AST_NODE_TYPES18.TSAbstractMethodDefinition || owner?.type === AST_NODE_TYPES18.PropertyDefinition) && owner.value === node ? topLevel.id?.name ?? (current.type === AST_NODE_TYPES18.ExportDefaultDeclaration ? "default" : null) : null;
|
|
4778
|
-
}
|
|
4779
|
-
if (topLevel.type === AST_NODE_TYPES18.VariableDeclaration) {
|
|
4780
|
-
for (const declarator of topLevel.declarations) {
|
|
4781
|
-
let initializer = declarator.init;
|
|
4782
|
-
while (initializer?.type === AST_NODE_TYPES18.TSAsExpression || initializer?.type === AST_NODE_TYPES18.TSSatisfiesExpression || initializer?.type === AST_NODE_TYPES18.TSNonNullExpression) initializer = initializer.expression;
|
|
4783
|
-
if (declarator.id.type === AST_NODE_TYPES18.Identifier && initializer === node) return declarator.id.name;
|
|
4784
|
-
if (declarator.id.type === AST_NODE_TYPES18.Identifier && (initializer?.type === AST_NODE_TYPES18.ClassExpression || initializer?.type === AST_NODE_TYPES18.ObjectExpression)) {
|
|
4785
|
-
let owner = node.parent;
|
|
4786
|
-
const container = initializer.type === AST_NODE_TYPES18.ClassExpression ? initializer.body : initializer;
|
|
4787
|
-
while (owner != null && owner.parent !== container) owner = owner.parent;
|
|
4788
|
-
if ((owner?.type === AST_NODE_TYPES18.MethodDefinition || owner?.type === AST_NODE_TYPES18.PropertyDefinition || owner?.type === AST_NODE_TYPES18.Property) && owner.value === node) return declarator.id.name;
|
|
4789
|
-
}
|
|
4790
|
-
}
|
|
4791
|
-
}
|
|
4792
|
-
return null;
|
|
4753
|
+
function isQueryKeyFactory(node) {
|
|
4754
|
+
let wrapped = node;
|
|
4755
|
+
while ((wrapped.parent?.type === AST_NODE_TYPES18.TSAsExpression || wrapped.parent?.type === AST_NODE_TYPES18.TSSatisfiesExpression || wrapped.parent?.type === AST_NODE_TYPES18.TSNonNullExpression) && wrapped.parent.expression === wrapped) wrapped = wrapped.parent;
|
|
4756
|
+
const property = wrapped.parent;
|
|
4757
|
+
if (property?.type !== AST_NODE_TYPES18.Property || property.value !== wrapped) return false;
|
|
4758
|
+
const object = property.parent;
|
|
4759
|
+
if (object.type !== AST_NODE_TYPES18.ObjectExpression) return false;
|
|
4760
|
+
const assertion = object.parent;
|
|
4761
|
+
if (assertion.type !== AST_NODE_TYPES18.TSAsExpression || assertion.expression !== object || assertion.typeAnnotation.type !== AST_NODE_TYPES18.TSTypeReference || assertion.typeAnnotation.typeName.type !== AST_NODE_TYPES18.Identifier || assertion.typeAnnotation.typeName.name !== "const") return false;
|
|
4762
|
+
const declarator = assertion.parent;
|
|
4763
|
+
if (declarator.type !== AST_NODE_TYPES18.VariableDeclarator || declarator.id.type !== AST_NODE_TYPES18.Identifier || !/Keys$/i.test(declarator.id.name) || declarator.parent.type !== AST_NODE_TYPES18.VariableDeclaration || declarator.parent.kind !== "const") return false;
|
|
4764
|
+
return object.properties.some((candidate) => {
|
|
4765
|
+
if (candidate.type !== AST_NODE_TYPES18.Property || staticMemberName3(candidate.key) !== "all") return false;
|
|
4766
|
+
return candidate.value.type === AST_NODE_TYPES18.TSAsExpression && candidate.value.expression.type === AST_NODE_TYPES18.ArrayExpression && candidate.value.typeAnnotation.type === AST_NODE_TYPES18.TSTypeReference && candidate.value.typeAnnotation.typeName.type === AST_NODE_TYPES18.Identifier && candidate.value.typeAnnotation.typeName.name === "const";
|
|
4767
|
+
});
|
|
4793
4768
|
}
|
|
4794
4769
|
function specifierExportedNames(program) {
|
|
4795
4770
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -4898,18 +4873,52 @@ function isExportedClass(node, specifierExports) {
|
|
|
4898
4873
|
if (node.parent.type === AST_NODE_TYPES18.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES18.Identifier) return specifierExports.has(node.parent.id.name) || isInlineExported(node);
|
|
4899
4874
|
return false;
|
|
4900
4875
|
}
|
|
4901
|
-
function
|
|
4902
|
-
|
|
4876
|
+
function isInlineExported(node) {
|
|
4877
|
+
if (moduleScopeBindingName(node) === null) return false;
|
|
4878
|
+
for (let current = node; current != null; current = current.parent) {
|
|
4879
|
+
const parent = current.parent;
|
|
4880
|
+
if (parent?.type === AST_NODE_TYPES18.ExportNamedDeclaration || parent?.type === AST_NODE_TYPES18.ExportDefaultDeclaration) {
|
|
4881
|
+
return true;
|
|
4882
|
+
}
|
|
4883
|
+
}
|
|
4884
|
+
return false;
|
|
4903
4885
|
}
|
|
4904
|
-
function
|
|
4905
|
-
|
|
4906
|
-
|
|
4886
|
+
function moduleScopeBindingName(node) {
|
|
4887
|
+
let current = node;
|
|
4888
|
+
while (current.parent != null && current.parent.type !== AST_NODE_TYPES18.Program) {
|
|
4889
|
+
current = current.parent;
|
|
4907
4890
|
}
|
|
4908
|
-
if (
|
|
4909
|
-
|
|
4891
|
+
if (current.parent?.type !== AST_NODE_TYPES18.Program) return null;
|
|
4892
|
+
let topLevel = current;
|
|
4893
|
+
if (current.type === AST_NODE_TYPES18.ExportNamedDeclaration || current.type === AST_NODE_TYPES18.ExportDefaultDeclaration) topLevel = current.declaration;
|
|
4894
|
+
if (topLevel === null) return null;
|
|
4895
|
+
if (topLevel.type === AST_NODE_TYPES18.FunctionDeclaration) {
|
|
4896
|
+
if (topLevel !== node) return null;
|
|
4897
|
+
return topLevel.id?.name ?? (current.type === AST_NODE_TYPES18.ExportDefaultDeclaration ? "default" : null);
|
|
4910
4898
|
}
|
|
4911
|
-
|
|
4912
|
-
|
|
4899
|
+
if ((topLevel.type === AST_NODE_TYPES18.ArrowFunctionExpression || topLevel.type === AST_NODE_TYPES18.FunctionExpression) && topLevel === node && current.type === AST_NODE_TYPES18.ExportDefaultDeclaration) return "default";
|
|
4900
|
+
if (topLevel.type === AST_NODE_TYPES18.ClassDeclaration) {
|
|
4901
|
+
let owner = node.parent;
|
|
4902
|
+
while (owner != null && owner.parent !== topLevel.body) owner = owner.parent;
|
|
4903
|
+
return (owner?.type === AST_NODE_TYPES18.MethodDefinition || owner?.type === AST_NODE_TYPES18.TSAbstractMethodDefinition || owner?.type === AST_NODE_TYPES18.PropertyDefinition) && owner.value === node ? topLevel.id?.name ?? (current.type === AST_NODE_TYPES18.ExportDefaultDeclaration ? "default" : null) : null;
|
|
4904
|
+
}
|
|
4905
|
+
if (topLevel.type === AST_NODE_TYPES18.VariableDeclaration) {
|
|
4906
|
+
for (const declarator of topLevel.declarations) {
|
|
4907
|
+
let initializer = declarator.init;
|
|
4908
|
+
while (initializer?.type === AST_NODE_TYPES18.TSAsExpression || initializer?.type === AST_NODE_TYPES18.TSSatisfiesExpression || initializer?.type === AST_NODE_TYPES18.TSNonNullExpression) initializer = initializer.expression;
|
|
4909
|
+
if (declarator.id.type === AST_NODE_TYPES18.Identifier && initializer === node) return declarator.id.name;
|
|
4910
|
+
if (declarator.id.type === AST_NODE_TYPES18.Identifier && (initializer?.type === AST_NODE_TYPES18.ClassExpression || initializer?.type === AST_NODE_TYPES18.ObjectExpression)) {
|
|
4911
|
+
let owner = node.parent;
|
|
4912
|
+
const container = initializer.type === AST_NODE_TYPES18.ClassExpression ? initializer.body : initializer;
|
|
4913
|
+
while (owner != null && owner.parent !== container) owner = owner.parent;
|
|
4914
|
+
if ((owner?.type === AST_NODE_TYPES18.MethodDefinition || owner?.type === AST_NODE_TYPES18.PropertyDefinition || owner?.type === AST_NODE_TYPES18.Property) && owner.value === node) return declarator.id.name;
|
|
4915
|
+
}
|
|
4916
|
+
}
|
|
4917
|
+
}
|
|
4918
|
+
return null;
|
|
4919
|
+
}
|
|
4920
|
+
function isExportedInterface(node, exports) {
|
|
4921
|
+
return node.parent.type === AST_NODE_TYPES18.ExportNamedDeclaration || node.parent.type === AST_NODE_TYPES18.ExportDefaultDeclaration || node.parent.type === AST_NODE_TYPES18.Program && exports.has(node.id.name);
|
|
4913
4922
|
}
|
|
4914
4923
|
var no_positional_tuple_return_default = createRule({
|
|
4915
4924
|
name: "no-positional-tuple-return",
|
|
@@ -4917,11 +4926,11 @@ var no_positional_tuple_return_default = createRule({
|
|
|
4917
4926
|
meta: {
|
|
4918
4927
|
type: "suggestion",
|
|
4919
4928
|
docs: {
|
|
4920
|
-
description: "Disallow returning a multi-field tuple from
|
|
4929
|
+
description: "Disallow returning a multi-field tuple from a named function; return a named object so call sites cannot mismatch slots."
|
|
4921
4930
|
},
|
|
4922
4931
|
schema: [],
|
|
4923
4932
|
messages: {
|
|
4924
|
-
noPositionalTupleReturn: "
|
|
4933
|
+
noPositionalTupleReturn: "`{{name}}` returns a {{count}}-field tuple, so callers depend on positional slots that can be reordered silently. Return a named object instead."
|
|
4925
4934
|
}
|
|
4926
4935
|
},
|
|
4927
4936
|
defaultOptions: [],
|
|
@@ -4933,6 +4942,8 @@ var no_positional_tuple_return_default = createRule({
|
|
|
4933
4942
|
exportedTypeNames(context.sourceCode.ast)
|
|
4934
4943
|
);
|
|
4935
4944
|
const aliases = typeAliases(context.sourceCode.ast);
|
|
4945
|
+
const reportedFunctions = /* @__PURE__ */ new WeakSet();
|
|
4946
|
+
const functionStack = [];
|
|
4936
4947
|
const report = (annotation, name) => {
|
|
4937
4948
|
const tuple = tupleReturnType(annotation, aliases);
|
|
4938
4949
|
if (tuple === null || tuple.elementTypes.length < MIN_ELEMENTS) return;
|
|
@@ -4942,25 +4953,54 @@ var no_positional_tuple_return_default = createRule({
|
|
|
4942
4953
|
data: { name, count: String(tuple.elementTypes.length) }
|
|
4943
4954
|
});
|
|
4944
4955
|
};
|
|
4956
|
+
const reportExpression = (node, expression) => {
|
|
4957
|
+
if (reportedFunctions.has(node)) return;
|
|
4958
|
+
const tuple = tupleExpression(expression, aliases);
|
|
4959
|
+
const name = functionName(node);
|
|
4960
|
+
if (tuple === null || name === null) return;
|
|
4961
|
+
reportedFunctions.add(node);
|
|
4962
|
+
context.report({
|
|
4963
|
+
node: tuple,
|
|
4964
|
+
messageId: "noPositionalTupleReturn",
|
|
4965
|
+
data: { name, count: String(tuple.elements.length) }
|
|
4966
|
+
});
|
|
4967
|
+
};
|
|
4945
4968
|
const check = (node) => {
|
|
4969
|
+
if (isQueryKeyFactory(node)) return;
|
|
4946
4970
|
const annotation = node.returnType?.typeAnnotation;
|
|
4947
4971
|
if (annotation === void 0) {
|
|
4972
|
+
if (node.type === AST_NODE_TYPES18.ArrowFunctionExpression && node.expression) {
|
|
4973
|
+
reportExpression(node, node.body);
|
|
4974
|
+
}
|
|
4948
4975
|
return;
|
|
4949
4976
|
}
|
|
4950
4977
|
const name = functionName(node);
|
|
4951
4978
|
if (name === null) {
|
|
4952
4979
|
return;
|
|
4953
4980
|
}
|
|
4954
|
-
if (!isExported(node, specifierExports)) {
|
|
4955
|
-
return;
|
|
4956
|
-
}
|
|
4957
4981
|
report(annotation, name);
|
|
4958
4982
|
};
|
|
4983
|
+
const enterFunction = (node) => {
|
|
4984
|
+
functionStack.push(node);
|
|
4985
|
+
check(node);
|
|
4986
|
+
};
|
|
4987
|
+
const exitFunction = () => {
|
|
4988
|
+
functionStack.pop();
|
|
4989
|
+
};
|
|
4959
4990
|
return {
|
|
4960
|
-
FunctionDeclaration:
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
4991
|
+
FunctionDeclaration: enterFunction,
|
|
4992
|
+
"FunctionDeclaration:exit": exitFunction,
|
|
4993
|
+
FunctionExpression: enterFunction,
|
|
4994
|
+
"FunctionExpression:exit": exitFunction,
|
|
4995
|
+
ArrowFunctionExpression: enterFunction,
|
|
4996
|
+
"ArrowFunctionExpression:exit": exitFunction,
|
|
4997
|
+
TSEmptyBodyFunctionExpression: enterFunction,
|
|
4998
|
+
"TSEmptyBodyFunctionExpression:exit": exitFunction,
|
|
4999
|
+
ReturnStatement(node) {
|
|
5000
|
+
const owner = functionStack.at(-1);
|
|
5001
|
+
if (owner === void 0 || owner.returnType !== void 0 || node.argument === null) return;
|
|
5002
|
+
reportExpression(owner, node.argument);
|
|
5003
|
+
},
|
|
4964
5004
|
TSDeclareFunction(node) {
|
|
4965
5005
|
if (node.id === null || node.returnType === void 0 || node.parent.type !== AST_NODE_TYPES18.ExportNamedDeclaration && node.parent.type !== AST_NODE_TYPES18.ExportDefaultDeclaration && !specifierExports.has(node.id.name)) return;
|
|
4966
5006
|
report(node.returnType.typeAnnotation, node.id.name);
|
|
@@ -9305,8 +9345,98 @@ function unwrapExpression(node) {
|
|
|
9305
9345
|
return node;
|
|
9306
9346
|
}
|
|
9307
9347
|
|
|
9308
|
-
// src/rules/
|
|
9348
|
+
// src/rules/test-phase-label-comment.ts
|
|
9309
9349
|
import { AST_NODE_TYPES as AST_NODE_TYPES37 } from "@typescript-eslint/utils";
|
|
9350
|
+
var PHASE_WORD = String.raw`arrange|act|assert(?:ion)?s?|given|when|then|exercise|execute|verif(?:y|ication)|cleanup|prepare|sanity(?:\s+check)?`;
|
|
9351
|
+
var PHASE_RE = new RegExp(
|
|
9352
|
+
String.raw`^[-=~*_#.\s]{0,40}(?:${PHASE_WORD})(?:\s*(?:[/&+,|]|->|and)\s*(?:${PHASE_WORD}))*[-=~*_#.\s:;!–—]{0,40}$`,
|
|
9353
|
+
"iu"
|
|
9354
|
+
);
|
|
9355
|
+
var testPhaseLabelCommentDocumentation = {
|
|
9356
|
+
summary: "Tests must not use bare Arrange, Act, Assert, Given, When, or Then phase comments.",
|
|
9357
|
+
rationale: "Phase labels narrate test structure without explaining behavior and often hide unclear names or oversized tests.",
|
|
9358
|
+
remediation: "Delete the label; if the phases remain hard to follow, extract a named helper or split the test.",
|
|
9359
|
+
category: "testing",
|
|
9360
|
+
autofix: "safe",
|
|
9361
|
+
limitations: [
|
|
9362
|
+
"Only standalone line comments in recognized test files are checked.",
|
|
9363
|
+
"Comments inside bracketed expressions or containing words outside the bounded phase grammar are preserved."
|
|
9364
|
+
],
|
|
9365
|
+
examples: [
|
|
9366
|
+
{
|
|
9367
|
+
id: "behavioral-comment",
|
|
9368
|
+
title: "Behavioral consequence is retained",
|
|
9369
|
+
outcome: "no-match",
|
|
9370
|
+
files: [{ path: "widget.test.ts", source: "// Then the retry loop would spin forever.\nexpect(run()).toBe(true);" }],
|
|
9371
|
+
focusPath: "widget.test.ts",
|
|
9372
|
+
expectedCount: 0,
|
|
9373
|
+
public: true
|
|
9374
|
+
},
|
|
9375
|
+
{
|
|
9376
|
+
id: "bare-phase-label",
|
|
9377
|
+
title: "Bare phase label is removed",
|
|
9378
|
+
outcome: "match",
|
|
9379
|
+
files: [{ path: "widget.test.ts", source: "// Arrange\nconst widget = makeWidget();" }],
|
|
9380
|
+
focusPath: "widget.test.ts",
|
|
9381
|
+
expectedCount: 1,
|
|
9382
|
+
fixedFiles: [{ path: "widget.test.ts", source: "const widget = makeWidget();" }],
|
|
9383
|
+
public: true
|
|
9384
|
+
}
|
|
9385
|
+
]
|
|
9386
|
+
};
|
|
9387
|
+
function insideExpression(sourceCode, comment) {
|
|
9388
|
+
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
9389
|
+
if (token === null) return false;
|
|
9390
|
+
let node = sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
9391
|
+
while (node != null && node.type !== AST_NODE_TYPES37.Program) {
|
|
9392
|
+
if (node.type === AST_NODE_TYPES37.ArrayExpression || node.type === AST_NODE_TYPES37.ObjectExpression || node.type === AST_NODE_TYPES37.CallExpression || node.type === AST_NODE_TYPES37.NewExpression) return node.loc.start.line < comment.loc.start.line;
|
|
9393
|
+
if (/Statement$/u.test(node.type) || /Declaration$/u.test(node.type)) return false;
|
|
9394
|
+
node = node.parent;
|
|
9395
|
+
}
|
|
9396
|
+
return false;
|
|
9397
|
+
}
|
|
9398
|
+
function continuesProseRun(comments, index) {
|
|
9399
|
+
const comment = comments[index];
|
|
9400
|
+
if (comment?.type !== "Line") return false;
|
|
9401
|
+
return [comments[index - 1], comments[index + 1]].some(
|
|
9402
|
+
(neighbor) => neighbor?.type === "Line" && Math.abs(neighbor.loc.start.line - comment.loc.start.line) === 1 && !PHASE_RE.test(neighbor.value.trim())
|
|
9403
|
+
);
|
|
9404
|
+
}
|
|
9405
|
+
var test_phase_label_comment_default = createRule({
|
|
9406
|
+
name: "test-phase-label-comment",
|
|
9407
|
+
documentation: testPhaseLabelCommentDocumentation,
|
|
9408
|
+
meta: {
|
|
9409
|
+
type: "suggestion",
|
|
9410
|
+
fixable: "code",
|
|
9411
|
+
docs: { description: testPhaseLabelCommentDocumentation.summary },
|
|
9412
|
+
schema: [],
|
|
9413
|
+
messages: { removeLabel: "Bare test phase label \u2014 delete it and let the test names and helpers carry the structure." }
|
|
9414
|
+
},
|
|
9415
|
+
defaultOptions: [],
|
|
9416
|
+
create(context) {
|
|
9417
|
+
if (!isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text)) return {};
|
|
9418
|
+
return {
|
|
9419
|
+
Program() {
|
|
9420
|
+
const comments = context.sourceCode.getAllComments();
|
|
9421
|
+
for (const [index, comment] of comments.entries()) {
|
|
9422
|
+
if (comment.type !== "Line" || !PHASE_RE.test(comment.value.trim())) continue;
|
|
9423
|
+
const removal = wholeLineRemovalRange(context.sourceCode.text, comment);
|
|
9424
|
+
if (removal === null || insideExpression(context.sourceCode, comment) || continuesProseRun(comments, index)) {
|
|
9425
|
+
continue;
|
|
9426
|
+
}
|
|
9427
|
+
context.report({
|
|
9428
|
+
node: comment,
|
|
9429
|
+
messageId: "removeLabel",
|
|
9430
|
+
fix: (fixer) => fixer.removeRange(removal.range)
|
|
9431
|
+
});
|
|
9432
|
+
}
|
|
9433
|
+
}
|
|
9434
|
+
};
|
|
9435
|
+
}
|
|
9436
|
+
});
|
|
9437
|
+
|
|
9438
|
+
// src/rules/prefer-constant-time-secret-compare.ts
|
|
9439
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES38 } from "@typescript-eslint/utils";
|
|
9310
9440
|
var preferConstantTimeSecretCompareDocumentation = {
|
|
9311
9441
|
summary: "Disallow `===`/`!==` on a secret-like value; short-circuiting comparison leaks the secret through timing. Use a constant-time compare.",
|
|
9312
9442
|
rationale: "Ordinary equality stops at the first differing byte, allowing repeated measurements to reveal secret material.",
|
|
@@ -9325,14 +9455,14 @@ var SENTINEL_PREFIX_RE = /^(skip|sentinel|empty|none|missing|unset|placeholder|d
|
|
|
9325
9455
|
var AST_NODE_TYPE_RE = /^(?:TS|JSX)?[A-Z][A-Za-z]*(?:Signature|Keyword|Expression|Declaration|Element|Literal|Identifier)$/;
|
|
9326
9456
|
function isExcludedOperand(node) {
|
|
9327
9457
|
switch (node.type) {
|
|
9328
|
-
case
|
|
9458
|
+
case AST_NODE_TYPES38.Literal:
|
|
9329
9459
|
return true;
|
|
9330
|
-
case
|
|
9460
|
+
case AST_NODE_TYPES38.TemplateLiteral:
|
|
9331
9461
|
return node.expressions.length === 0;
|
|
9332
|
-
case
|
|
9462
|
+
case AST_NODE_TYPES38.Identifier:
|
|
9333
9463
|
return SENTINEL_IDENTIFIERS.has(node.name) || SENTINEL_PREFIX_RE.test(node.name) || isConstantReference(node.name);
|
|
9334
|
-
case
|
|
9335
|
-
return !node.computed && node.property.type ===
|
|
9464
|
+
case AST_NODE_TYPES38.MemberExpression:
|
|
9465
|
+
return !node.computed && node.property.type === AST_NODE_TYPES38.Identifier && (SENTINEL_PREFIX_RE.test(node.property.name) || isConstantReference(node.property.name));
|
|
9336
9466
|
default:
|
|
9337
9467
|
return false;
|
|
9338
9468
|
}
|
|
@@ -9343,23 +9473,23 @@ function isConstantReference(identifier) {
|
|
|
9343
9473
|
return identifier === identifier.toUpperCase() && /[A-Za-z]/.test(identifier);
|
|
9344
9474
|
}
|
|
9345
9475
|
function operandName(node) {
|
|
9346
|
-
if (node.type ===
|
|
9476
|
+
if (node.type === AST_NODE_TYPES38.Identifier) {
|
|
9347
9477
|
return node.name;
|
|
9348
9478
|
}
|
|
9349
|
-
if (node.type ===
|
|
9479
|
+
if (node.type === AST_NODE_TYPES38.MemberExpression && !node.computed && node.property.type === AST_NODE_TYPES38.Identifier) {
|
|
9350
9480
|
return node.property.name;
|
|
9351
9481
|
}
|
|
9352
9482
|
return null;
|
|
9353
9483
|
}
|
|
9354
9484
|
function isSecretOperand(node) {
|
|
9355
|
-
if (node.type ===
|
|
9485
|
+
if (node.type === AST_NODE_TYPES38.TemplateLiteral) {
|
|
9356
9486
|
return node.expressions.some((expression) => isSecretOperand(expression));
|
|
9357
9487
|
}
|
|
9358
9488
|
const name = operandName(node);
|
|
9359
9489
|
return name !== null && isAuthSecretName(name);
|
|
9360
9490
|
}
|
|
9361
9491
|
function secretNameOf(node) {
|
|
9362
|
-
if (node.type ===
|
|
9492
|
+
if (node.type === AST_NODE_TYPES38.TemplateLiteral) {
|
|
9363
9493
|
for (const expression of node.expressions) {
|
|
9364
9494
|
const nested = secretNameOf(expression);
|
|
9365
9495
|
if (nested !== null) {
|
|
@@ -9413,7 +9543,7 @@ var prefer_constant_time_secret_compare_default = createRule({
|
|
|
9413
9543
|
|
|
9414
9544
|
// src/rules/prefer-discriminated-union.ts
|
|
9415
9545
|
import "@typescript-eslint/utils";
|
|
9416
|
-
import { AST_NODE_TYPES as
|
|
9546
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES39 } from "@typescript-eslint/utils";
|
|
9417
9547
|
var preferDiscriminatedUnionDocumentation = {
|
|
9418
9548
|
summary: "Flag flat result objects with a required positive boolean status and optional success/failure payloads.",
|
|
9419
9549
|
rationale: "A boolean status plus optional branch data permits contradictory and incomplete states.",
|
|
@@ -9445,13 +9575,13 @@ var SUCCESS_PAYLOAD_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
|
9445
9575
|
]);
|
|
9446
9576
|
var REQUIRED_STATUS_MEMBER_COUNT = 1;
|
|
9447
9577
|
var FUNCTION_RETURN_OWNER_TYPES = /* @__PURE__ */ new Set([
|
|
9448
|
-
|
|
9449
|
-
|
|
9450
|
-
|
|
9451
|
-
|
|
9452
|
-
|
|
9453
|
-
|
|
9454
|
-
|
|
9578
|
+
AST_NODE_TYPES39.ArrowFunctionExpression,
|
|
9579
|
+
AST_NODE_TYPES39.FunctionDeclaration,
|
|
9580
|
+
AST_NODE_TYPES39.FunctionExpression,
|
|
9581
|
+
AST_NODE_TYPES39.TSDeclareFunction,
|
|
9582
|
+
AST_NODE_TYPES39.TSEmptyBodyFunctionExpression,
|
|
9583
|
+
AST_NODE_TYPES39.TSFunctionType,
|
|
9584
|
+
AST_NODE_TYPES39.TSMethodSignature
|
|
9455
9585
|
]);
|
|
9456
9586
|
function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
9457
9587
|
let statusMemberCount = 0;
|
|
@@ -9459,7 +9589,7 @@ function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
|
9459
9589
|
let hasSuccessPayload = false;
|
|
9460
9590
|
let hasUnrecognizedMember = false;
|
|
9461
9591
|
for (const member of typeLiteral.members) {
|
|
9462
|
-
if (member.type !==
|
|
9592
|
+
if (member.type !== AST_NODE_TYPES39.TSPropertySignature) {
|
|
9463
9593
|
hasUnrecognizedMember = true;
|
|
9464
9594
|
continue;
|
|
9465
9595
|
}
|
|
@@ -9483,26 +9613,26 @@ function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
|
9483
9613
|
return statusMemberCount === REQUIRED_STATUS_MEMBER_COUNT && hasFailurePayload && (hasSuccessPayload || !hasUnrecognizedMember);
|
|
9484
9614
|
}
|
|
9485
9615
|
function getMemberName(member) {
|
|
9486
|
-
if (member.type !==
|
|
9616
|
+
if (member.type !== AST_NODE_TYPES39.TSPropertySignature) {
|
|
9487
9617
|
return null;
|
|
9488
9618
|
}
|
|
9489
9619
|
const { key } = member;
|
|
9490
|
-
if (key.type ===
|
|
9620
|
+
if (key.type === AST_NODE_TYPES39.Identifier) {
|
|
9491
9621
|
return key.name;
|
|
9492
9622
|
}
|
|
9493
|
-
if (key.type ===
|
|
9623
|
+
if (key.type === AST_NODE_TYPES39.Literal && typeof key.value === "string") {
|
|
9494
9624
|
return key.value;
|
|
9495
9625
|
}
|
|
9496
9626
|
return null;
|
|
9497
9627
|
}
|
|
9498
9628
|
function isBooleanTyped(member) {
|
|
9499
|
-
return member.typeAnnotation?.typeAnnotation.type ===
|
|
9629
|
+
return member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES39.TSBooleanKeyword;
|
|
9500
9630
|
}
|
|
9501
9631
|
function inlineReturnTypeLiteral(node) {
|
|
9502
9632
|
let annotation = null;
|
|
9503
|
-
if (node.parent.type ===
|
|
9633
|
+
if (node.parent.type === AST_NODE_TYPES39.TSTypeAnnotation) {
|
|
9504
9634
|
annotation = node.parent;
|
|
9505
|
-
} else if (node.parent.type ===
|
|
9635
|
+
} else if (node.parent.type === AST_NODE_TYPES39.TSTypeParameterInstantiation && node.parent.params.length === 1 && node.parent.params[0] === node && node.parent.parent.type === AST_NODE_TYPES39.TSTypeReference && node.parent.parent.typeName.type === AST_NODE_TYPES39.Identifier && node.parent.parent.typeName.name === "Promise" && node.parent.parent.parent.type === AST_NODE_TYPES39.TSTypeAnnotation) {
|
|
9506
9636
|
annotation = node.parent.parent.parent;
|
|
9507
9637
|
}
|
|
9508
9638
|
if (annotation === null) return null;
|
|
@@ -9542,7 +9672,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
9542
9672
|
}
|
|
9543
9673
|
const synthetic = {
|
|
9544
9674
|
...node.body,
|
|
9545
|
-
type:
|
|
9675
|
+
type: AST_NODE_TYPES39.TSTypeLiteral,
|
|
9546
9676
|
members: node.body.body
|
|
9547
9677
|
};
|
|
9548
9678
|
checkTypeLiteral(synthetic, node);
|
|
@@ -9559,7 +9689,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
9559
9689
|
});
|
|
9560
9690
|
|
|
9561
9691
|
// src/rules/prefer-input-group-search.ts
|
|
9562
|
-
import { AST_NODE_TYPES as
|
|
9692
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES40 } from "@typescript-eslint/utils";
|
|
9563
9693
|
var preferInputGroupSearchDocumentation = {
|
|
9564
9694
|
summary: "Require search icons and shared Input controls in the same visual wrapper to use InputGroup.",
|
|
9565
9695
|
rationale: "The shared compound control provides consistent spacing, focus behavior, and accessible composition.",
|
|
@@ -9580,15 +9710,15 @@ var MAX_JSX_DISTANCE = 2;
|
|
|
9580
9710
|
var SEARCH_EXPORTS = ["Search", "SearchIcon", "LucideSearch"];
|
|
9581
9711
|
function localNamedImports(node, importedName4) {
|
|
9582
9712
|
return node.specifiers.filter(
|
|
9583
|
-
(specifier) => specifier.type ===
|
|
9713
|
+
(specifier) => specifier.type === AST_NODE_TYPES40.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES40.Identifier ? specifier.imported.name : specifier.imported.value) === importedName4
|
|
9584
9714
|
).map((specifier) => specifier.local.name);
|
|
9585
9715
|
}
|
|
9586
9716
|
function elementName(node) {
|
|
9587
|
-
return node.name.type ===
|
|
9717
|
+
return node.name.type === AST_NODE_TYPES40.JSXIdentifier ? node.name.name : null;
|
|
9588
9718
|
}
|
|
9589
9719
|
function jsxAncestors(occurrence) {
|
|
9590
9720
|
return occurrence.ancestors.filter(
|
|
9591
|
-
(ancestor) => ancestor.type ===
|
|
9721
|
+
(ancestor) => ancestor.type === AST_NODE_TYPES40.JSXElement
|
|
9592
9722
|
);
|
|
9593
9723
|
}
|
|
9594
9724
|
function isWithinInputGroup(occurrence, inputGroupNames) {
|
|
@@ -9701,7 +9831,7 @@ var prefer_input_group_search_default = createRule({
|
|
|
9701
9831
|
});
|
|
9702
9832
|
|
|
9703
9833
|
// src/rules/prefer-immutable-module-constant.ts
|
|
9704
|
-
import { AST_NODE_TYPES as
|
|
9834
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES41, ASTUtils as ASTUtils11 } from "@typescript-eslint/utils";
|
|
9705
9835
|
var preferImmutableModuleConstantDocumentation = {
|
|
9706
9836
|
summary: "Require module-level constant collections to expose readonly state.",
|
|
9707
9837
|
rationale: "A const binding prevents reassignment but does not stop callers from mutating its array, object, Set, or Map contents.",
|
|
@@ -9749,59 +9879,59 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
|
9749
9879
|
"unshift"
|
|
9750
9880
|
]);
|
|
9751
9881
|
function isAsConst(node, sourceText) {
|
|
9752
|
-
if (node.type ===
|
|
9882
|
+
if (node.type === AST_NODE_TYPES41.TSSatisfiesExpression || node.type === AST_NODE_TYPES41.TSNonNullExpression) {
|
|
9753
9883
|
return isAsConst(node.expression, sourceText);
|
|
9754
9884
|
}
|
|
9755
|
-
if (node.type !==
|
|
9885
|
+
if (node.type !== AST_NODE_TYPES41.TSAsExpression) return false;
|
|
9756
9886
|
return sourceText(node.typeAnnotation).trim() === "const";
|
|
9757
9887
|
}
|
|
9758
9888
|
function unwrapExpression2(node) {
|
|
9759
|
-
if (node.type ===
|
|
9889
|
+
if (node.type === AST_NODE_TYPES41.TSAsExpression || node.type === AST_NODE_TYPES41.TSSatisfiesExpression || node.type === AST_NODE_TYPES41.TSNonNullExpression) {
|
|
9760
9890
|
return unwrapExpression2(node.expression);
|
|
9761
9891
|
}
|
|
9762
9892
|
return node;
|
|
9763
9893
|
}
|
|
9764
9894
|
function isObjectFreeze(node, isUnshadowedGlobal) {
|
|
9765
9895
|
const inner = unwrapExpression2(node);
|
|
9766
|
-
if (inner.type ===
|
|
9896
|
+
if (inner.type === AST_NODE_TYPES41.CallExpression && inner.callee.type === AST_NODE_TYPES41.MemberExpression && !inner.callee.computed && inner.callee.object.type === AST_NODE_TYPES41.Identifier && inner.callee.object.name === "Object" && isUnshadowedGlobal(inner.callee.object) && inner.callee.property.type === AST_NODE_TYPES41.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1) {
|
|
9767
9897
|
const argument = inner.arguments[0];
|
|
9768
|
-
return argument !== void 0 && argument.type !==
|
|
9898
|
+
return argument !== void 0 && argument.type !== AST_NODE_TYPES41.SpreadElement && collectionKind(argument, isUnshadowedGlobal) === "literal";
|
|
9769
9899
|
}
|
|
9770
9900
|
return false;
|
|
9771
9901
|
}
|
|
9772
9902
|
function collectionKind(node, isUnshadowedGlobal) {
|
|
9773
9903
|
const inner = unwrapExpression2(node);
|
|
9774
|
-
if (inner.type ===
|
|
9904
|
+
if (inner.type === AST_NODE_TYPES41.CallExpression && inner.callee.type === AST_NODE_TYPES41.MemberExpression && !inner.callee.computed && inner.callee.object.type === AST_NODE_TYPES41.Identifier && inner.callee.object.name === "Object" && isUnshadowedGlobal(inner.callee.object) && inner.callee.property.type === AST_NODE_TYPES41.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== AST_NODE_TYPES41.SpreadElement) {
|
|
9775
9905
|
return collectionKind(inner.arguments[0], isUnshadowedGlobal);
|
|
9776
9906
|
}
|
|
9777
|
-
if (inner.type ===
|
|
9907
|
+
if (inner.type === AST_NODE_TYPES41.ArrayExpression || inner.type === AST_NODE_TYPES41.ObjectExpression) {
|
|
9778
9908
|
return "literal";
|
|
9779
9909
|
}
|
|
9780
|
-
if (inner.type ===
|
|
9910
|
+
if (inner.type === AST_NODE_TYPES41.NewExpression && inner.callee.type === AST_NODE_TYPES41.Identifier && (inner.callee.name === "Set" || inner.callee.name === "Map") && isUnshadowedGlobal(inner.callee)) {
|
|
9781
9911
|
return inner.callee.name;
|
|
9782
9912
|
}
|
|
9783
9913
|
return null;
|
|
9784
9914
|
}
|
|
9785
9915
|
function declaredReadonlyType(node, kind, aliases) {
|
|
9786
|
-
const annotation = node.id.type ===
|
|
9916
|
+
const annotation = node.id.type === AST_NODE_TYPES41.Identifier ? node.id.typeAnnotation : void 0;
|
|
9787
9917
|
if (annotation !== void 0 && isReadonlyTypeResolved(annotation.typeAnnotation, kind, aliases)) {
|
|
9788
9918
|
return true;
|
|
9789
9919
|
}
|
|
9790
|
-
return node.init?.type ===
|
|
9920
|
+
return node.init?.type === AST_NODE_TYPES41.TSAsExpression && isReadonlyTypeResolved(node.init.typeAnnotation, kind, aliases);
|
|
9791
9921
|
}
|
|
9792
9922
|
function isReadonlyTypeResolved(node, kind, aliases, seen = /* @__PURE__ */ new Set()) {
|
|
9793
9923
|
if (isReadonlyType(node, kind)) return true;
|
|
9794
|
-
if (node.type !==
|
|
9924
|
+
if (node.type !== AST_NODE_TYPES41.TSTypeReference || node.typeName.type !== AST_NODE_TYPES41.Identifier) return false;
|
|
9795
9925
|
const name = node.typeName.name;
|
|
9796
9926
|
const target = aliases.get(name);
|
|
9797
9927
|
if (target === void 0 || seen.has(name)) return false;
|
|
9798
9928
|
return isReadonlyTypeResolved(target, kind, aliases, /* @__PURE__ */ new Set([...seen, name]));
|
|
9799
9929
|
}
|
|
9800
9930
|
function isReadonlyType(node, kind) {
|
|
9801
|
-
if (node.type ===
|
|
9931
|
+
if (node.type === AST_NODE_TYPES41.TSTypeOperator && node.operator === "readonly") {
|
|
9802
9932
|
return true;
|
|
9803
9933
|
}
|
|
9804
|
-
if (node.type !==
|
|
9934
|
+
if (node.type !== AST_NODE_TYPES41.TSTypeReference || node.typeName.type !== AST_NODE_TYPES41.Identifier) {
|
|
9805
9935
|
return false;
|
|
9806
9936
|
}
|
|
9807
9937
|
if (node.typeName.name === "Readonly") {
|
|
@@ -9810,31 +9940,31 @@ function isReadonlyType(node, kind) {
|
|
|
9810
9940
|
return kind === "literal" ? node.typeName.name === "ReadonlyArray" : node.typeName.name === `Readonly${kind}`;
|
|
9811
9941
|
}
|
|
9812
9942
|
function hasUnknownExplicitType(node, aliases) {
|
|
9813
|
-
const annotation = node.id.type ===
|
|
9943
|
+
const annotation = node.id.type === AST_NODE_TYPES41.Identifier ? node.id.typeAnnotation?.typeAnnotation : void 0;
|
|
9814
9944
|
if (annotation === void 0) return false;
|
|
9815
|
-
if (annotation.type ===
|
|
9816
|
-
if (annotation.type !==
|
|
9945
|
+
if (annotation.type === AST_NODE_TYPES41.TSArrayType || annotation.type === AST_NODE_TYPES41.TSTypeOperator) return false;
|
|
9946
|
+
if (annotation.type !== AST_NODE_TYPES41.TSTypeReference || annotation.typeName.type !== AST_NODE_TYPES41.Identifier) return true;
|
|
9817
9947
|
return !aliases.has(annotation.typeName.name) && !["Array", "Map", "Readonly", "ReadonlyArray", "ReadonlyMap", "ReadonlySet", "Set"].includes(annotation.typeName.name);
|
|
9818
9948
|
}
|
|
9819
9949
|
function referenceMutates(identifier, isUnshadowedGlobal) {
|
|
9820
9950
|
let member = identifier.parent;
|
|
9821
|
-
if (member?.type !==
|
|
9822
|
-
return member?.type ===
|
|
9951
|
+
if (member?.type !== AST_NODE_TYPES41.MemberExpression || member.object !== identifier) {
|
|
9952
|
+
return member?.type === AST_NODE_TYPES41.CallExpression && member.arguments[0] === identifier && member.callee.type === AST_NODE_TYPES41.MemberExpression && !member.callee.computed && member.callee.object.type === AST_NODE_TYPES41.Identifier && member.callee.object.name === "Object" && isUnshadowedGlobal(member.callee.object) && member.callee.property.type === AST_NODE_TYPES41.Identifier && member.callee.property.name === "assign";
|
|
9823
9953
|
}
|
|
9824
|
-
while (member.parent.type ===
|
|
9954
|
+
while (member.parent.type === AST_NODE_TYPES41.MemberExpression && member.parent.object === member) {
|
|
9825
9955
|
member = member.parent;
|
|
9826
9956
|
}
|
|
9827
9957
|
const parent = member.parent;
|
|
9828
|
-
if (parent?.type ===
|
|
9958
|
+
if (parent?.type === AST_NODE_TYPES41.AssignmentExpression && parent.left === member) {
|
|
9829
9959
|
return true;
|
|
9830
9960
|
}
|
|
9831
|
-
if (parent?.type ===
|
|
9961
|
+
if (parent?.type === AST_NODE_TYPES41.UpdateExpression && parent.argument === member) {
|
|
9832
9962
|
return true;
|
|
9833
9963
|
}
|
|
9834
|
-
if (parent?.type ===
|
|
9964
|
+
if (parent?.type === AST_NODE_TYPES41.UnaryExpression && parent.operator === "delete" && parent.argument === member) {
|
|
9835
9965
|
return true;
|
|
9836
9966
|
}
|
|
9837
|
-
return parent?.type ===
|
|
9967
|
+
return parent?.type === AST_NODE_TYPES41.CallExpression && parent.callee === member && (member.property.type === AST_NODE_TYPES41.Identifier && !member.computed || member.property.type === AST_NODE_TYPES41.Literal && typeof member.property.value === "string") && MUTATING_METHODS.has(member.property.type === AST_NODE_TYPES41.Identifier ? member.property.name : member.property.value);
|
|
9838
9968
|
}
|
|
9839
9969
|
var prefer_immutable_module_constant_default = createRule({
|
|
9840
9970
|
name: "prefer-immutable-module-constant",
|
|
@@ -9871,10 +10001,10 @@ var prefer_immutable_module_constant_default = createRule({
|
|
|
9871
10001
|
seen.add(variable);
|
|
9872
10002
|
for (const reference of variable.references) {
|
|
9873
10003
|
const identifier = reference.identifier;
|
|
9874
|
-
if (identifier.type !==
|
|
10004
|
+
if (identifier.type !== AST_NODE_TYPES41.Identifier) continue;
|
|
9875
10005
|
if (referenceMutates(identifier, isUnshadowedGlobal)) return true;
|
|
9876
10006
|
const declarator = identifier.parent;
|
|
9877
|
-
if (declarator.type !==
|
|
10007
|
+
if (declarator.type !== AST_NODE_TYPES41.VariableDeclarator || declarator.init !== identifier || declarator.id.type !== AST_NODE_TYPES41.Identifier || declarator.parent.type !== AST_NODE_TYPES41.VariableDeclaration || declarator.parent.kind !== "const") {
|
|
9878
10008
|
continue;
|
|
9879
10009
|
}
|
|
9880
10010
|
const alias = sourceCode.getDeclaredVariables(declarator)[0];
|
|
@@ -9886,32 +10016,32 @@ var prefer_immutable_module_constant_default = createRule({
|
|
|
9886
10016
|
return {
|
|
9887
10017
|
Program(node) {
|
|
9888
10018
|
for (const statement of node.body) {
|
|
9889
|
-
const declaration = statement.type ===
|
|
9890
|
-
if (declaration?.type ===
|
|
10019
|
+
const declaration = statement.type === AST_NODE_TYPES41.ExportNamedDeclaration ? statement.declaration : statement;
|
|
10020
|
+
if (declaration?.type === AST_NODE_TYPES41.TSTypeAliasDeclaration) {
|
|
9891
10021
|
typeAliases2.set(declaration.id.name, declaration.typeAnnotation);
|
|
9892
10022
|
}
|
|
9893
|
-
if (statement.type ===
|
|
10023
|
+
if (statement.type === AST_NODE_TYPES41.ExportNamedDeclaration) {
|
|
9894
10024
|
if (statement.source !== null || statement.exportKind === "type") continue;
|
|
9895
10025
|
for (const specifier of statement.specifiers) {
|
|
9896
|
-
if (specifier.type ===
|
|
10026
|
+
if (specifier.type === AST_NODE_TYPES41.ExportSpecifier && specifier.exportKind !== "type" && specifier.local.type === AST_NODE_TYPES41.Identifier) {
|
|
9897
10027
|
exportedNames2.add(specifier.local.name);
|
|
9898
10028
|
}
|
|
9899
10029
|
}
|
|
9900
|
-
} else if (statement.type ===
|
|
10030
|
+
} else if (statement.type === AST_NODE_TYPES41.ExportDefaultDeclaration && unwrapTransparentExport(statement.declaration)?.type === AST_NODE_TYPES41.Identifier) {
|
|
9901
10031
|
exportedNames2.add(unwrapTransparentExport(statement.declaration).name);
|
|
9902
10032
|
}
|
|
9903
10033
|
}
|
|
9904
10034
|
},
|
|
9905
10035
|
VariableDeclarator(node) {
|
|
9906
10036
|
const declaration = node.parent;
|
|
9907
|
-
if (declaration.type !==
|
|
10037
|
+
if (declaration.type !== AST_NODE_TYPES41.VariableDeclaration || declaration.kind !== "const" || node.id.type !== AST_NODE_TYPES41.Identifier || node.init === null) {
|
|
9908
10038
|
return;
|
|
9909
10039
|
}
|
|
9910
10040
|
const container = declaration.parent;
|
|
9911
|
-
if (container.type !==
|
|
10041
|
+
if (container.type !== AST_NODE_TYPES41.Program && !(container.type === AST_NODE_TYPES41.ExportNamedDeclaration && container.parent.type === AST_NODE_TYPES41.Program)) {
|
|
9912
10042
|
return;
|
|
9913
10043
|
}
|
|
9914
|
-
const directlyExported = container.type ===
|
|
10044
|
+
const directlyExported = container.type === AST_NODE_TYPES41.ExportNamedDeclaration;
|
|
9915
10045
|
if (!CONSTANT_NAME.test(node.id.name) && !directlyExported && !exportedNames2.has(node.id.name)) {
|
|
9916
10046
|
return;
|
|
9917
10047
|
}
|
|
@@ -9936,14 +10066,14 @@ var prefer_immutable_module_constant_default = createRule({
|
|
|
9936
10066
|
}
|
|
9937
10067
|
});
|
|
9938
10068
|
function unwrapTransparentExport(node) {
|
|
9939
|
-
if (node.type ===
|
|
10069
|
+
if (node.type === AST_NODE_TYPES41.TSSatisfiesExpression || node.type === AST_NODE_TYPES41.TSNonNullExpression) {
|
|
9940
10070
|
return unwrapTransparentExport(node.expression);
|
|
9941
10071
|
}
|
|
9942
10072
|
return node;
|
|
9943
10073
|
}
|
|
9944
10074
|
|
|
9945
10075
|
// src/rules/prefer-shadcn-primitives.ts
|
|
9946
|
-
import { AST_NODE_TYPES as
|
|
10076
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES42 } from "@typescript-eslint/utils";
|
|
9947
10077
|
var preferShadcnPrimitivesDocumentation = {
|
|
9948
10078
|
summary: "Require visible raw JSX controls to use the corresponding shared shadcn primitive.",
|
|
9949
10079
|
rationale: "Shared primitives centralize interaction, accessibility, and visual behavior across the product.",
|
|
@@ -9988,16 +10118,16 @@ var AMBIGUOUS_INPUT_TYPES = /* @__PURE__ */ new Set([
|
|
|
9988
10118
|
"submit"
|
|
9989
10119
|
]);
|
|
9990
10120
|
function rawElementName(node) {
|
|
9991
|
-
if (node.name.type !==
|
|
10121
|
+
if (node.name.type !== AST_NODE_TYPES42.JSXIdentifier) return null;
|
|
9992
10122
|
const name = node.name.name;
|
|
9993
10123
|
return Object.hasOwn(SHADCN_PRIMITIVES, name) ? name : null;
|
|
9994
10124
|
}
|
|
9995
10125
|
function effectiveAttribute(node, attributeName) {
|
|
9996
10126
|
for (const attribute of node.attributes.toReversed()) {
|
|
9997
|
-
if (attribute.type ===
|
|
10127
|
+
if (attribute.type === AST_NODE_TYPES42.JSXSpreadAttribute) {
|
|
9998
10128
|
return { kind: "unknown" };
|
|
9999
10129
|
}
|
|
10000
|
-
if (attribute.name.type !==
|
|
10130
|
+
if (attribute.name.type !== AST_NODE_TYPES42.JSXIdentifier || attribute.name.name !== attributeName) {
|
|
10001
10131
|
continue;
|
|
10002
10132
|
}
|
|
10003
10133
|
const value = staticString(attribute.value);
|
|
@@ -10006,17 +10136,17 @@ function effectiveAttribute(node, attributeName) {
|
|
|
10006
10136
|
return { kind: "missing" };
|
|
10007
10137
|
}
|
|
10008
10138
|
function staticString(value) {
|
|
10009
|
-
if (value?.type ===
|
|
10139
|
+
if (value?.type === AST_NODE_TYPES42.Literal) {
|
|
10010
10140
|
return typeof value.value === "string" ? value.value : null;
|
|
10011
10141
|
}
|
|
10012
|
-
if (value?.type !==
|
|
10142
|
+
if (value?.type !== AST_NODE_TYPES42.JSXExpressionContainer) return null;
|
|
10013
10143
|
return staticExpressionString(value.expression);
|
|
10014
10144
|
}
|
|
10015
10145
|
function staticExpressionString(expression) {
|
|
10016
|
-
if (expression.type ===
|
|
10146
|
+
if (expression.type === AST_NODE_TYPES42.Literal) {
|
|
10017
10147
|
return typeof expression.value === "string" ? expression.value : null;
|
|
10018
10148
|
}
|
|
10019
|
-
if (expression.type ===
|
|
10149
|
+
if (expression.type === AST_NODE_TYPES42.TemplateLiteral) {
|
|
10020
10150
|
let value = expression.quasis[0]?.value.cooked ?? "";
|
|
10021
10151
|
for (const [index, substitution] of expression.expressions.entries()) {
|
|
10022
10152
|
const staticSubstitution = staticExpressionString(substitution);
|
|
@@ -10026,13 +10156,13 @@ function staticExpressionString(expression) {
|
|
|
10026
10156
|
}
|
|
10027
10157
|
return value;
|
|
10028
10158
|
}
|
|
10029
|
-
if (expression.type ===
|
|
10159
|
+
if (expression.type === AST_NODE_TYPES42.TSAsExpression || expression.type === AST_NODE_TYPES42.TSNonNullExpression || expression.type === AST_NODE_TYPES42.TSSatisfiesExpression || expression.type === AST_NODE_TYPES42.TSTypeAssertion) {
|
|
10030
10160
|
return staticExpressionString(expression.expression);
|
|
10031
10161
|
}
|
|
10032
10162
|
return null;
|
|
10033
10163
|
}
|
|
10034
10164
|
function isLabelableElement(node) {
|
|
10035
|
-
if (node.openingElement.name.type !==
|
|
10165
|
+
if (node.openingElement.name.type !== AST_NODE_TYPES42.JSXIdentifier) {
|
|
10036
10166
|
return false;
|
|
10037
10167
|
}
|
|
10038
10168
|
const name = node.openingElement.name.name;
|
|
@@ -10044,10 +10174,10 @@ function isLabelableElement(node) {
|
|
|
10044
10174
|
}
|
|
10045
10175
|
function containsLabelableElement(node) {
|
|
10046
10176
|
return node.children.some((child) => {
|
|
10047
|
-
if (child.type ===
|
|
10177
|
+
if (child.type === AST_NODE_TYPES42.JSXElement) {
|
|
10048
10178
|
return isLabelableElement(child) || containsLabelableElement(child);
|
|
10049
10179
|
}
|
|
10050
|
-
if (child.type ===
|
|
10180
|
+
if (child.type === AST_NODE_TYPES42.JSXFragment) {
|
|
10051
10181
|
return containsLabelableElement(child);
|
|
10052
10182
|
}
|
|
10053
10183
|
return false;
|
|
@@ -10056,7 +10186,7 @@ function containsLabelableElement(node) {
|
|
|
10056
10186
|
function isStaticallyAssociatedLabel(node) {
|
|
10057
10187
|
const htmlFor = effectiveAttribute(node, "htmlFor");
|
|
10058
10188
|
if (htmlFor.kind === "known" && htmlFor.value.trim().length > 0) return true;
|
|
10059
|
-
return node.parent.type ===
|
|
10189
|
+
return node.parent.type === AST_NODE_TYPES42.JSXElement && containsLabelableElement(node.parent);
|
|
10060
10190
|
}
|
|
10061
10191
|
function replacementFor(node, element) {
|
|
10062
10192
|
if (element !== "input") return SHADCN_PRIMITIVES[element];
|
|
@@ -10127,7 +10257,7 @@ var prefer_shadcn_primitives_default = createRule({
|
|
|
10127
10257
|
});
|
|
10128
10258
|
|
|
10129
10259
|
// src/rules/prefer-module-level-constant.ts
|
|
10130
|
-
import { AST_NODE_TYPES as
|
|
10260
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES43 } from "@typescript-eslint/utils";
|
|
10131
10261
|
var preferModuleLevelConstantDocumentation = {
|
|
10132
10262
|
summary: "Hoist literal-only constant collections and regexes out of function bodies to module scope so they are allocated once.",
|
|
10133
10263
|
rationale: "Recreating immutable lookup data on every call wastes allocations and obscures its constant nature.",
|
|
@@ -10167,9 +10297,9 @@ var MUTATING_METHODS2 = /* @__PURE__ */ new Set([
|
|
|
10167
10297
|
"assign"
|
|
10168
10298
|
]);
|
|
10169
10299
|
var FUNCTION_TYPES7 = /* @__PURE__ */ new Set([
|
|
10170
|
-
|
|
10171
|
-
|
|
10172
|
-
|
|
10300
|
+
AST_NODE_TYPES43.FunctionDeclaration,
|
|
10301
|
+
AST_NODE_TYPES43.FunctionExpression,
|
|
10302
|
+
AST_NODE_TYPES43.ArrowFunctionExpression
|
|
10173
10303
|
]);
|
|
10174
10304
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
10175
10305
|
function isIgnoredFile2(filename, sourceText) {
|
|
@@ -10182,14 +10312,14 @@ function isLocalFixtureFile(filename) {
|
|
|
10182
10312
|
return isTestFile(filename) || isStoryFile(filename);
|
|
10183
10313
|
}
|
|
10184
10314
|
function unwrap3(node) {
|
|
10185
|
-
if (node.type ===
|
|
10315
|
+
if (node.type === AST_NODE_TYPES43.TSAsExpression || node.type === AST_NODE_TYPES43.TSSatisfiesExpression || node.type === AST_NODE_TYPES43.TSNonNullExpression) {
|
|
10186
10316
|
return unwrap3(node.expression);
|
|
10187
10317
|
}
|
|
10188
10318
|
return node;
|
|
10189
10319
|
}
|
|
10190
10320
|
var HAS_STATEFUL_FLAG_RE = /[gy]/;
|
|
10191
10321
|
function isRegexLiteral(node) {
|
|
10192
|
-
return node.type ===
|
|
10322
|
+
return node.type === AST_NODE_TYPES43.Literal && "regex" in node && node.regex !== void 0;
|
|
10193
10323
|
}
|
|
10194
10324
|
function isLiteralOnly(node, depth) {
|
|
10195
10325
|
if (depth > MAX_LITERAL_DEPTH) {
|
|
@@ -10197,29 +10327,29 @@ function isLiteralOnly(node, depth) {
|
|
|
10197
10327
|
}
|
|
10198
10328
|
const inner = unwrap3(node);
|
|
10199
10329
|
switch (inner.type) {
|
|
10200
|
-
case
|
|
10330
|
+
case AST_NODE_TYPES43.Literal: {
|
|
10201
10331
|
return !(isRegexLiteral(inner) && HAS_STATEFUL_FLAG_RE.test(inner.regex.flags));
|
|
10202
10332
|
}
|
|
10203
|
-
case
|
|
10333
|
+
case AST_NODE_TYPES43.TemplateLiteral: {
|
|
10204
10334
|
return inner.expressions.length === 0;
|
|
10205
10335
|
}
|
|
10206
|
-
case
|
|
10207
|
-
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type ===
|
|
10336
|
+
case AST_NODE_TYPES43.UnaryExpression: {
|
|
10337
|
+
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type === AST_NODE_TYPES43.Literal && typeof inner.argument.value === "number";
|
|
10208
10338
|
}
|
|
10209
|
-
case
|
|
10339
|
+
case AST_NODE_TYPES43.ArrayExpression: {
|
|
10210
10340
|
return inner.elements.every(
|
|
10211
|
-
(el) => el !== null && el.type !==
|
|
10341
|
+
(el) => el !== null && el.type !== AST_NODE_TYPES43.SpreadElement && isLiteralOnly(el, depth + 1)
|
|
10212
10342
|
);
|
|
10213
10343
|
}
|
|
10214
|
-
case
|
|
10344
|
+
case AST_NODE_TYPES43.ObjectExpression: {
|
|
10215
10345
|
return inner.properties.every((prop) => {
|
|
10216
|
-
if (prop.type !==
|
|
10346
|
+
if (prop.type !== AST_NODE_TYPES43.Property) {
|
|
10217
10347
|
return false;
|
|
10218
10348
|
}
|
|
10219
10349
|
if (prop.shorthand || prop.method || prop.kind !== "init") {
|
|
10220
10350
|
return false;
|
|
10221
10351
|
}
|
|
10222
|
-
if (prop.computed && prop.key.type !==
|
|
10352
|
+
if (prop.computed && prop.key.type !== AST_NODE_TYPES43.Literal) {
|
|
10223
10353
|
return false;
|
|
10224
10354
|
}
|
|
10225
10355
|
return isLiteralOnly(prop.value, depth + 1);
|
|
@@ -10241,19 +10371,19 @@ function classify(init, checkRegex) {
|
|
|
10241
10371
|
}
|
|
10242
10372
|
return { kind: "regex", size: 1 };
|
|
10243
10373
|
}
|
|
10244
|
-
if (node.type ===
|
|
10374
|
+
if (node.type === AST_NODE_TYPES43.ArrayExpression) {
|
|
10245
10375
|
return isLiteralOnly(node, 0) ? { kind: "array", size: node.elements.length } : null;
|
|
10246
10376
|
}
|
|
10247
|
-
if (node.type ===
|
|
10377
|
+
if (node.type === AST_NODE_TYPES43.ObjectExpression) {
|
|
10248
10378
|
return isLiteralOnly(node, 0) ? { kind: "object", size: node.properties.length } : null;
|
|
10249
10379
|
}
|
|
10250
|
-
if (node.type ===
|
|
10380
|
+
if (node.type === AST_NODE_TYPES43.NewExpression && node.callee.type === AST_NODE_TYPES43.Identifier && COLLECTION_CONSTRUCTORS.has(node.callee.name)) {
|
|
10251
10381
|
const arg = node.arguments[0];
|
|
10252
|
-
if (node.arguments.length !== 1 || arg === void 0 || arg.type ===
|
|
10382
|
+
if (node.arguments.length !== 1 || arg === void 0 || arg.type === AST_NODE_TYPES43.SpreadElement) {
|
|
10253
10383
|
return null;
|
|
10254
10384
|
}
|
|
10255
10385
|
const entries = unwrap3(arg);
|
|
10256
|
-
if (entries.type !==
|
|
10386
|
+
if (entries.type !== AST_NODE_TYPES43.ArrayExpression) {
|
|
10257
10387
|
return null;
|
|
10258
10388
|
}
|
|
10259
10389
|
return isLiteralOnly(entries, 0) ? { kind: node.callee.name === "Set" ? "Set" : "Map", size: entries.elements.length } : null;
|
|
@@ -10262,7 +10392,7 @@ function classify(init, checkRegex) {
|
|
|
10262
10392
|
}
|
|
10263
10393
|
function unwrapObjectFreeze(node) {
|
|
10264
10394
|
const inner = unwrap3(node);
|
|
10265
|
-
if (inner.type ===
|
|
10395
|
+
if (inner.type === AST_NODE_TYPES43.CallExpression && inner.callee.type === AST_NODE_TYPES43.MemberExpression && !inner.callee.computed && inner.callee.object.type === AST_NODE_TYPES43.Identifier && inner.callee.object.name === "Object" && inner.callee.property.type === AST_NODE_TYPES43.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== AST_NODE_TYPES43.SpreadElement) {
|
|
10266
10396
|
return unwrap3(inner.arguments[0]);
|
|
10267
10397
|
}
|
|
10268
10398
|
return inner;
|
|
@@ -10289,48 +10419,48 @@ var NON_RETAINING_BUILTINS = /* @__PURE__ */ new Map(
|
|
|
10289
10419
|
);
|
|
10290
10420
|
function isSafeRead(identifier) {
|
|
10291
10421
|
const parent = identifier.parent;
|
|
10292
|
-
if (parent.type ===
|
|
10422
|
+
if (parent.type === AST_NODE_TYPES43.MemberExpression) {
|
|
10293
10423
|
if (parent.object !== identifier) {
|
|
10294
10424
|
return true;
|
|
10295
10425
|
}
|
|
10296
10426
|
const grandparent = parent.parent;
|
|
10297
|
-
if (grandparent.type ===
|
|
10427
|
+
if (grandparent.type === AST_NODE_TYPES43.AssignmentExpression && grandparent.left === parent) {
|
|
10298
10428
|
return false;
|
|
10299
10429
|
}
|
|
10300
|
-
if (grandparent.type ===
|
|
10430
|
+
if (grandparent.type === AST_NODE_TYPES43.UpdateExpression) {
|
|
10301
10431
|
return false;
|
|
10302
10432
|
}
|
|
10303
|
-
if (grandparent.type ===
|
|
10433
|
+
if (grandparent.type === AST_NODE_TYPES43.UnaryExpression && grandparent.operator === "delete") {
|
|
10304
10434
|
return false;
|
|
10305
10435
|
}
|
|
10306
|
-
if (!parent.computed && parent.property.type ===
|
|
10436
|
+
if (!parent.computed && parent.property.type === AST_NODE_TYPES43.Identifier && MUTATING_METHODS2.has(parent.property.name) && grandparent.type === AST_NODE_TYPES43.CallExpression && grandparent.callee === parent) {
|
|
10307
10437
|
return false;
|
|
10308
10438
|
}
|
|
10309
10439
|
return true;
|
|
10310
10440
|
}
|
|
10311
|
-
if (parent.type ===
|
|
10441
|
+
if (parent.type === AST_NODE_TYPES43.ForOfStatement && parent.right === identifier) {
|
|
10312
10442
|
return true;
|
|
10313
10443
|
}
|
|
10314
|
-
if (parent.type ===
|
|
10444
|
+
if (parent.type === AST_NODE_TYPES43.SpreadElement) {
|
|
10315
10445
|
return true;
|
|
10316
10446
|
}
|
|
10317
|
-
if (parent.type ===
|
|
10447
|
+
if (parent.type === AST_NODE_TYPES43.BinaryExpression) {
|
|
10318
10448
|
return true;
|
|
10319
10449
|
}
|
|
10320
|
-
if (parent.type ===
|
|
10450
|
+
if (parent.type === AST_NODE_TYPES43.CallExpression && parent.arguments.includes(identifier) && isNonRetainingBuiltinCall(parent, identifier)) {
|
|
10321
10451
|
return true;
|
|
10322
10452
|
}
|
|
10323
|
-
if (parent.type ===
|
|
10453
|
+
if (parent.type === AST_NODE_TYPES43.UnaryExpression && parent.operator !== "delete") {
|
|
10324
10454
|
return true;
|
|
10325
10455
|
}
|
|
10326
10456
|
return false;
|
|
10327
10457
|
}
|
|
10328
10458
|
function isNonRetainingBuiltinCall(node, argument) {
|
|
10329
10459
|
const callee = node.callee;
|
|
10330
|
-
if (callee.type ===
|
|
10460
|
+
if (callee.type === AST_NODE_TYPES43.Identifier && callee.name === "structuredClone") {
|
|
10331
10461
|
return true;
|
|
10332
10462
|
}
|
|
10333
|
-
if (callee.type !==
|
|
10463
|
+
if (callee.type !== AST_NODE_TYPES43.MemberExpression || callee.computed || callee.object.type !== AST_NODE_TYPES43.Identifier || callee.property.type !== AST_NODE_TYPES43.Identifier) {
|
|
10334
10464
|
return false;
|
|
10335
10465
|
}
|
|
10336
10466
|
const members = NON_RETAINING_BUILTINS.get(callee.object.name);
|
|
@@ -10393,7 +10523,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
10393
10523
|
if (reference.isWrite()) {
|
|
10394
10524
|
return false;
|
|
10395
10525
|
}
|
|
10396
|
-
if (reference.identifier.type !==
|
|
10526
|
+
if (reference.identifier.type !== AST_NODE_TYPES43.Identifier) {
|
|
10397
10527
|
return false;
|
|
10398
10528
|
}
|
|
10399
10529
|
if (!isSafeRead(reference.identifier)) {
|
|
@@ -10405,10 +10535,10 @@ var prefer_module_level_constant_default = createRule({
|
|
|
10405
10535
|
return {
|
|
10406
10536
|
VariableDeclarator(node) {
|
|
10407
10537
|
const declaration = node.parent;
|
|
10408
|
-
if (declaration.type !==
|
|
10538
|
+
if (declaration.type !== AST_NODE_TYPES43.VariableDeclaration || declaration.kind !== "const" || declaration.declare === true) {
|
|
10409
10539
|
return;
|
|
10410
10540
|
}
|
|
10411
|
-
if (node.id.type !==
|
|
10541
|
+
if (node.id.type !== AST_NODE_TYPES43.Identifier || node.init === null) {
|
|
10412
10542
|
return;
|
|
10413
10543
|
}
|
|
10414
10544
|
if (enclosingFunction2(node) === null) {
|
|
@@ -10435,7 +10565,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
10435
10565
|
});
|
|
10436
10566
|
|
|
10437
10567
|
// src/rules/prefer-module-level-schema.ts
|
|
10438
|
-
import { AST_NODE_TYPES as
|
|
10568
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES44 } from "@typescript-eslint/utils";
|
|
10439
10569
|
var preferModuleLevelSchemaDocumentation = {
|
|
10440
10570
|
summary: "Declare a Zod schema at module scope when it closes over nothing in the enclosing function",
|
|
10441
10571
|
rationale: "A closed schema created inside a function is rebuilt on every call and cannot be reused or exported for inference.",
|
|
@@ -10502,9 +10632,9 @@ var I18N_RECEIVER_NAMES = /* @__PURE__ */ new Set([
|
|
|
10502
10632
|
"intl"
|
|
10503
10633
|
]);
|
|
10504
10634
|
var FUNCTION_TYPES8 = /* @__PURE__ */ new Set([
|
|
10505
|
-
|
|
10506
|
-
|
|
10507
|
-
|
|
10635
|
+
AST_NODE_TYPES44.ArrowFunctionExpression,
|
|
10636
|
+
AST_NODE_TYPES44.FunctionDeclaration,
|
|
10637
|
+
AST_NODE_TYPES44.FunctionExpression
|
|
10508
10638
|
]);
|
|
10509
10639
|
function schemaExpression(node) {
|
|
10510
10640
|
let current = node;
|
|
@@ -10513,10 +10643,10 @@ function schemaExpression(node) {
|
|
|
10513
10643
|
if (parent === void 0) {
|
|
10514
10644
|
return current;
|
|
10515
10645
|
}
|
|
10516
|
-
if (parent.type ===
|
|
10646
|
+
if (parent.type === AST_NODE_TYPES44.MemberExpression && parent.object === current && !parent.computed && parent.property.type === AST_NODE_TYPES44.Identifier && TERMINAL_METHODS.has(parent.property.name)) {
|
|
10517
10647
|
return current;
|
|
10518
10648
|
}
|
|
10519
|
-
if (parent.type ===
|
|
10649
|
+
if (parent.type === AST_NODE_TYPES44.MemberExpression && parent.object === current || parent.type === AST_NODE_TYPES44.CallExpression && parent.callee === current || parent.type === AST_NODE_TYPES44.TSAsExpression && parent.expression === current || parent.type === AST_NODE_TYPES44.TSNonNullExpression && parent.expression === current) {
|
|
10520
10650
|
current = parent;
|
|
10521
10651
|
continue;
|
|
10522
10652
|
}
|
|
@@ -10567,22 +10697,22 @@ function subtreeSome(root, predicate) {
|
|
|
10567
10697
|
function readsReceiver(node) {
|
|
10568
10698
|
return subtreeSome(
|
|
10569
10699
|
node,
|
|
10570
|
-
(inner) => inner.type ===
|
|
10700
|
+
(inner) => inner.type === AST_NODE_TYPES44.ThisExpression || inner.type === AST_NODE_TYPES44.Super || inner.type === AST_NODE_TYPES44.Identifier && inner.name === "arguments"
|
|
10571
10701
|
);
|
|
10572
10702
|
}
|
|
10573
10703
|
function buildsLocalizedText(node) {
|
|
10574
10704
|
return subtreeSome(node, (inner) => {
|
|
10575
|
-
if (inner.type ===
|
|
10705
|
+
if (inner.type === AST_NODE_TYPES44.TaggedTemplateExpression) {
|
|
10576
10706
|
return true;
|
|
10577
10707
|
}
|
|
10578
|
-
if (inner.type !==
|
|
10708
|
+
if (inner.type !== AST_NODE_TYPES44.CallExpression) {
|
|
10579
10709
|
return false;
|
|
10580
10710
|
}
|
|
10581
10711
|
const { callee } = inner;
|
|
10582
|
-
if (callee.type ===
|
|
10712
|
+
if (callee.type === AST_NODE_TYPES44.Identifier) {
|
|
10583
10713
|
return I18N_CALLEE_NAMES.has(callee.name);
|
|
10584
10714
|
}
|
|
10585
|
-
return callee.type ===
|
|
10715
|
+
return callee.type === AST_NODE_TYPES44.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES44.Identifier && I18N_RECEIVER_NAMES.has(callee.object.name);
|
|
10586
10716
|
});
|
|
10587
10717
|
}
|
|
10588
10718
|
function collectReferences(scope, out) {
|
|
@@ -10646,15 +10776,15 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10646
10776
|
}
|
|
10647
10777
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
10648
10778
|
function isZodCall(node) {
|
|
10649
|
-
return node.type ===
|
|
10779
|
+
return node.type === AST_NODE_TYPES44.CallExpression && node.callee.type === AST_NODE_TYPES44.MemberExpression && !node.callee.computed && node.callee.object.type === AST_NODE_TYPES44.Identifier && zodNamespaces.has(node.callee.object.name);
|
|
10650
10780
|
}
|
|
10651
10781
|
function isCovered(node) {
|
|
10652
10782
|
let current = node.parent ?? void 0;
|
|
10653
10783
|
while (current !== void 0) {
|
|
10654
|
-
if (current !== node && isZodCall(current) && current.callee.type ===
|
|
10784
|
+
if (current !== node && isZodCall(current) && current.callee.type === AST_NODE_TYPES44.MemberExpression && current.callee.property.type === AST_NODE_TYPES44.Identifier && factories.has(current.callee.property.name)) {
|
|
10655
10785
|
return true;
|
|
10656
10786
|
}
|
|
10657
|
-
if (current.type ===
|
|
10787
|
+
if (current.type === AST_NODE_TYPES44.CallExpression && (current.callee.type === AST_NODE_TYPES44.Identifier && memoCallees.has(current.callee.name) || current.callee.type === AST_NODE_TYPES44.MemberExpression && !current.callee.computed && current.callee.property.type === AST_NODE_TYPES44.Identifier && memoCallees.has(current.callee.property.name))) {
|
|
10658
10788
|
return true;
|
|
10659
10789
|
}
|
|
10660
10790
|
current = current.parent ?? void 0;
|
|
@@ -10669,11 +10799,11 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10669
10799
|
if (parent === void 0) {
|
|
10670
10800
|
return confirmed;
|
|
10671
10801
|
}
|
|
10672
|
-
if (parent.type ===
|
|
10802
|
+
if (parent.type === AST_NODE_TYPES44.Property && parent.value === current || parent.type === AST_NODE_TYPES44.ObjectExpression || parent.type === AST_NODE_TYPES44.ArrayExpression) {
|
|
10673
10803
|
current = parent;
|
|
10674
10804
|
continue;
|
|
10675
10805
|
}
|
|
10676
|
-
if (parent.type ===
|
|
10806
|
+
if (parent.type === AST_NODE_TYPES44.CallExpression && parent.arguments.includes(current) && isSchemaComposition(parent)) {
|
|
10677
10807
|
current = schemaExpression(parent);
|
|
10678
10808
|
confirmed = current;
|
|
10679
10809
|
continue;
|
|
@@ -10683,7 +10813,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10683
10813
|
}
|
|
10684
10814
|
function isSchemaComposition(node) {
|
|
10685
10815
|
const { callee } = node;
|
|
10686
|
-
const isCombinator = callee.type ===
|
|
10816
|
+
const isCombinator = callee.type === AST_NODE_TYPES44.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES44.Identifier && ZOD_COMBINATOR_METHODS.has(callee.property.name);
|
|
10687
10817
|
return isCombinator || isZodCall(node);
|
|
10688
10818
|
}
|
|
10689
10819
|
function closesOverNothing(node, enclosing) {
|
|
@@ -10703,12 +10833,12 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10703
10833
|
for (const definition of resolved.defs) {
|
|
10704
10834
|
if (definition.type === "ImportBinding") {
|
|
10705
10835
|
const parent = reference.identifier.parent;
|
|
10706
|
-
if (parent?.type ===
|
|
10836
|
+
if (parent?.type === AST_NODE_TYPES44.CallExpression && parent.callee === reference.identifier && !zodNamespaces.has(reference.identifier.name)) {
|
|
10707
10837
|
return false;
|
|
10708
10838
|
}
|
|
10709
10839
|
continue;
|
|
10710
10840
|
}
|
|
10711
|
-
if (definition.node.type ===
|
|
10841
|
+
if (definition.node.type === AST_NODE_TYPES44.VariableDeclarator && definition.node.parent.type === AST_NODE_TYPES44.VariableDeclaration && definition.node.parent.kind !== "const") {
|
|
10712
10842
|
return false;
|
|
10713
10843
|
}
|
|
10714
10844
|
const [defStart, defEnd] = definition.node.range;
|
|
@@ -10724,13 +10854,13 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10724
10854
|
}
|
|
10725
10855
|
function ownerName(enclosing) {
|
|
10726
10856
|
const parent = enclosing.parent ?? void 0;
|
|
10727
|
-
if (enclosing.type ===
|
|
10857
|
+
if (enclosing.type === AST_NODE_TYPES44.FunctionDeclaration && enclosing.id !== null) {
|
|
10728
10858
|
return enclosing.id.name;
|
|
10729
10859
|
}
|
|
10730
|
-
if (parent !== void 0 && parent.type ===
|
|
10860
|
+
if (parent !== void 0 && parent.type === AST_NODE_TYPES44.VariableDeclarator && parent.id.type === AST_NODE_TYPES44.Identifier) {
|
|
10731
10861
|
return parent.id.name;
|
|
10732
10862
|
}
|
|
10733
|
-
if (parent !== void 0 && (parent.type ===
|
|
10863
|
+
if (parent !== void 0 && (parent.type === AST_NODE_TYPES44.MethodDefinition || parent.type === AST_NODE_TYPES44.Property) && parent.key.type === AST_NODE_TYPES44.Identifier) {
|
|
10734
10864
|
return parent.key.name;
|
|
10735
10865
|
}
|
|
10736
10866
|
return "this function";
|
|
@@ -10741,7 +10871,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10741
10871
|
return;
|
|
10742
10872
|
}
|
|
10743
10873
|
for (const specifier of node.specifiers) {
|
|
10744
|
-
if (specifier.type ===
|
|
10874
|
+
if (specifier.type === AST_NODE_TYPES44.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES44.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES44.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES44.Identifier && specifier.imported.name === "z") {
|
|
10745
10875
|
zodNamespaces.add(specifier.local.name);
|
|
10746
10876
|
}
|
|
10747
10877
|
}
|
|
@@ -10751,7 +10881,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10751
10881
|
return;
|
|
10752
10882
|
}
|
|
10753
10883
|
const callee = node.callee;
|
|
10754
|
-
if (callee.property.type !==
|
|
10884
|
+
if (callee.property.type !== AST_NODE_TYPES44.Identifier) {
|
|
10755
10885
|
return;
|
|
10756
10886
|
}
|
|
10757
10887
|
const factory = callee.property.name;
|
|
@@ -10766,7 +10896,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10766
10896
|
return;
|
|
10767
10897
|
}
|
|
10768
10898
|
const shape = node.arguments[0];
|
|
10769
|
-
if (shape !== void 0 && shape.type ===
|
|
10899
|
+
if (shape !== void 0 && shape.type === AST_NODE_TYPES44.ObjectExpression && shape.properties.length < minProperties) {
|
|
10770
10900
|
return;
|
|
10771
10901
|
}
|
|
10772
10902
|
const expression = schemaExpression(node);
|
|
@@ -10794,7 +10924,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
10794
10924
|
});
|
|
10795
10925
|
|
|
10796
10926
|
// src/rules/prefer-native-random-uuid.ts
|
|
10797
|
-
import { AST_NODE_TYPES as
|
|
10927
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES45, ASTUtils as ASTUtils12 } from "@typescript-eslint/utils";
|
|
10798
10928
|
var preferNativeRandomUuidDocumentation = {
|
|
10799
10929
|
summary: "Prefer `globalThis.crypto.randomUUID()` over resolved zero-argument UUID v4 bindings from the `uuid` package.",
|
|
10800
10930
|
rationale: "The platform implementation avoids an unnecessary dependency for standard random UUID generation.",
|
|
@@ -10808,7 +10938,7 @@ var preferNativeRandomUuidDocumentation = {
|
|
|
10808
10938
|
]
|
|
10809
10939
|
};
|
|
10810
10940
|
function requireUuid(node) {
|
|
10811
|
-
return node?.type ===
|
|
10941
|
+
return node?.type === AST_NODE_TYPES45.CallExpression && node.callee.type === AST_NODE_TYPES45.Identifier && node.callee.name === "require" && node.arguments.length === 1 && node.arguments[0]?.type === AST_NODE_TYPES45.Literal && node.arguments[0].value === "uuid";
|
|
10812
10942
|
}
|
|
10813
10943
|
var prefer_native_random_uuid_default = createRule({
|
|
10814
10944
|
name: "prefer-native-random-uuid",
|
|
@@ -10852,37 +10982,37 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
10852
10982
|
ImportDeclaration(node) {
|
|
10853
10983
|
if (node.source.value !== "uuid") return;
|
|
10854
10984
|
for (const specifier of node.specifiers) {
|
|
10855
|
-
if (specifier.type ===
|
|
10985
|
+
if (specifier.type === AST_NODE_TYPES45.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES45.Identifier ? specifier.imported.name === "v4" : specifier.imported.value === "v4")) {
|
|
10856
10986
|
record(specifier.local, directBindings);
|
|
10857
|
-
} else if (specifier.type ===
|
|
10987
|
+
} else if (specifier.type === AST_NODE_TYPES45.ImportNamespaceSpecifier) {
|
|
10858
10988
|
record(specifier.local, namespaceBindings);
|
|
10859
10989
|
}
|
|
10860
10990
|
}
|
|
10861
10991
|
},
|
|
10862
10992
|
VariableDeclarator(node) {
|
|
10863
10993
|
if (node.parent.kind !== "const" || !requireUuid(node.init)) return;
|
|
10864
|
-
if (node.init?.type !==
|
|
10994
|
+
if (node.init?.type !== AST_NODE_TYPES45.CallExpression || node.init.callee.type !== AST_NODE_TYPES45.Identifier || (resolve(node.init.callee)?.defs.length ?? 0) > 0) {
|
|
10865
10995
|
return;
|
|
10866
10996
|
}
|
|
10867
|
-
if (node.id.type ===
|
|
10997
|
+
if (node.id.type === AST_NODE_TYPES45.Identifier) {
|
|
10868
10998
|
record(node.id, namespaceBindings);
|
|
10869
10999
|
return;
|
|
10870
11000
|
}
|
|
10871
|
-
if (node.id.type !==
|
|
11001
|
+
if (node.id.type !== AST_NODE_TYPES45.ObjectPattern) return;
|
|
10872
11002
|
for (const property of node.id.properties) {
|
|
10873
|
-
if (property.type ===
|
|
11003
|
+
if (property.type === AST_NODE_TYPES45.Property && !property.computed && (property.key.type === AST_NODE_TYPES45.Identifier && property.key.name === "v4" || property.key.type === AST_NODE_TYPES45.Literal && property.key.value === "v4") && property.value.type === AST_NODE_TYPES45.Identifier) {
|
|
10874
11004
|
record(property.value, directBindings);
|
|
10875
11005
|
}
|
|
10876
11006
|
}
|
|
10877
11007
|
},
|
|
10878
11008
|
"CallExpression:exit"(node) {
|
|
10879
11009
|
if (node.arguments.length !== 0) return;
|
|
10880
|
-
if (node.callee.type ===
|
|
11010
|
+
if (node.callee.type === AST_NODE_TYPES45.Identifier) {
|
|
10881
11011
|
const variable2 = resolve(node.callee);
|
|
10882
11012
|
if (variable2 !== null && directBindings.has(variable2)) report(node);
|
|
10883
11013
|
return;
|
|
10884
11014
|
}
|
|
10885
|
-
if (node.callee.type !==
|
|
11015
|
+
if (node.callee.type !== AST_NODE_TYPES45.MemberExpression || node.callee.computed || node.callee.object.type !== AST_NODE_TYPES45.Identifier || node.callee.property.type !== AST_NODE_TYPES45.Identifier || node.callee.property.name !== "v4") {
|
|
10886
11016
|
return;
|
|
10887
11017
|
}
|
|
10888
11018
|
const variable = resolve(node.callee.object);
|
|
@@ -10893,7 +11023,7 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
10893
11023
|
});
|
|
10894
11024
|
|
|
10895
11025
|
// src/rules/prefer-non-nullable-collection.ts
|
|
10896
|
-
import { AST_NODE_TYPES as
|
|
11026
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES46, ASTUtils as ASTUtils13 } from "@typescript-eslint/utils";
|
|
10897
11027
|
var preferNonNullableCollectionDocumentation = {
|
|
10898
11028
|
summary: "Suggest non-null arrays only when local control flow proves the nullish state is equivalent to an empty collection.",
|
|
10899
11029
|
rationale: "A redundant nullish collection state spreads defaults and guards through consumers without carrying information.",
|
|
@@ -10909,33 +11039,33 @@ var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
|
10909
11039
|
function propertyName(node) {
|
|
10910
11040
|
const key = node.key;
|
|
10911
11041
|
if (node.computed) return null;
|
|
10912
|
-
if (key.type ===
|
|
10913
|
-
if (key.type ===
|
|
11042
|
+
if (key.type === AST_NODE_TYPES46.Identifier) return key.name;
|
|
11043
|
+
if (key.type === AST_NODE_TYPES46.Literal && typeof key.value === "string") return key.value;
|
|
10914
11044
|
return null;
|
|
10915
11045
|
}
|
|
10916
11046
|
function isArrayType(node) {
|
|
10917
|
-
if (node.type ===
|
|
10918
|
-
return node.type ===
|
|
11047
|
+
if (node.type === AST_NODE_TYPES46.TSArrayType) return true;
|
|
11048
|
+
return node.type === AST_NODE_TYPES46.TSTypeReference && node.typeName.type === AST_NODE_TYPES46.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
10919
11049
|
}
|
|
10920
11050
|
function nullableProperty(node) {
|
|
10921
11051
|
if (node.optional) return null;
|
|
10922
11052
|
const name = propertyName(node);
|
|
10923
11053
|
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
10924
|
-
if (name === null || annotation?.type !==
|
|
11054
|
+
if (name === null || annotation?.type !== AST_NODE_TYPES46.TSUnionType) return null;
|
|
10925
11055
|
const concrete = annotation.types.filter(
|
|
10926
|
-
(member) => member.type !==
|
|
11056
|
+
(member) => member.type !== AST_NODE_TYPES46.TSNullKeyword && member.type !== AST_NODE_TYPES46.TSUndefinedKeyword
|
|
10927
11057
|
);
|
|
10928
11058
|
if (concrete.length === 0 || !concrete.every(isArrayType)) return null;
|
|
10929
|
-
const acceptsNull = annotation.types.some((member) => member.type ===
|
|
11059
|
+
const acceptsNull = annotation.types.some((member) => member.type === AST_NODE_TYPES46.TSNullKeyword);
|
|
10930
11060
|
const acceptsUndefined = annotation.types.some(
|
|
10931
|
-
(member) => member.type ===
|
|
11061
|
+
(member) => member.type === AST_NODE_TYPES46.TSUndefinedKeyword
|
|
10932
11062
|
);
|
|
10933
11063
|
if (!acceptsNull && !acceptsUndefined) return null;
|
|
10934
11064
|
return { name, node, acceptsNull, acceptsUndefined };
|
|
10935
11065
|
}
|
|
10936
11066
|
function shapeProperties(members) {
|
|
10937
11067
|
return members.flatMap((member) => {
|
|
10938
|
-
if (member.type !==
|
|
11068
|
+
if (member.type !== AST_NODE_TYPES46.TSPropertySignature) return [];
|
|
10939
11069
|
const property = nullableProperty(member);
|
|
10940
11070
|
return property === null ? [] : [property];
|
|
10941
11071
|
});
|
|
@@ -10943,14 +11073,14 @@ function shapeProperties(members) {
|
|
|
10943
11073
|
function typeIndex(program) {
|
|
10944
11074
|
const index = /* @__PURE__ */ new Map();
|
|
10945
11075
|
for (const statement of program.body) {
|
|
10946
|
-
const exported = statement.type ===
|
|
11076
|
+
const exported = statement.type === AST_NODE_TYPES46.ExportNamedDeclaration;
|
|
10947
11077
|
const declaration = exported ? statement.declaration : statement;
|
|
10948
|
-
if (declaration?.type ===
|
|
11078
|
+
if (declaration?.type === AST_NODE_TYPES46.TSInterfaceDeclaration) {
|
|
10949
11079
|
index.set(declaration.id.name, {
|
|
10950
11080
|
exported,
|
|
10951
11081
|
properties: shapeProperties(declaration.body.body)
|
|
10952
11082
|
});
|
|
10953
|
-
} else if (declaration?.type ===
|
|
11083
|
+
} else if (declaration?.type === AST_NODE_TYPES46.TSTypeAliasDeclaration && declaration.typeAnnotation.type === AST_NODE_TYPES46.TSTypeLiteral) {
|
|
10954
11084
|
index.set(declaration.id.name, {
|
|
10955
11085
|
exported,
|
|
10956
11086
|
properties: shapeProperties(declaration.typeAnnotation.members)
|
|
@@ -10960,42 +11090,42 @@ function typeIndex(program) {
|
|
|
10960
11090
|
return index;
|
|
10961
11091
|
}
|
|
10962
11092
|
function emptyArray(node) {
|
|
10963
|
-
return node.type ===
|
|
11093
|
+
return node.type === AST_NODE_TYPES46.ArrayExpression && node.elements.length === 0;
|
|
10964
11094
|
}
|
|
10965
11095
|
function sameAccess(node, access) {
|
|
10966
11096
|
if (access.kind === "identifier") {
|
|
10967
|
-
return node.type ===
|
|
11097
|
+
return node.type === AST_NODE_TYPES46.Identifier && node.name === access.name;
|
|
10968
11098
|
}
|
|
10969
|
-
return node.type ===
|
|
11099
|
+
return node.type === AST_NODE_TYPES46.MemberExpression && !node.computed && node.object.type === AST_NODE_TYPES46.Identifier && node.object.name === access.object && node.property.type === AST_NODE_TYPES46.Identifier && node.property.name === access.property;
|
|
10970
11100
|
}
|
|
10971
11101
|
function isNullGuard(node, access) {
|
|
10972
|
-
if (node.type ===
|
|
10973
|
-
if (node.type !==
|
|
11102
|
+
if (node.type === AST_NODE_TYPES46.UnaryExpression && node.operator === "!" && (sameAccess(node.argument, access) || optionalMemberLengthOf(node.argument, access))) return true;
|
|
11103
|
+
if (node.type !== AST_NODE_TYPES46.BinaryExpression || !["==", "==="].includes(node.operator)) {
|
|
10974
11104
|
return false;
|
|
10975
11105
|
}
|
|
10976
|
-
const nullish = (value) => value.type ===
|
|
11106
|
+
const nullish = (value) => value.type === AST_NODE_TYPES46.Literal && value.value === null || value.type === AST_NODE_TYPES46.Identifier && value.name === "undefined";
|
|
10977
11107
|
return sameAccess(node.left, access) && nullish(node.right) || sameAccess(node.right, access) && nullish(node.left);
|
|
10978
11108
|
}
|
|
10979
11109
|
function isEmptyGuard(node, access) {
|
|
10980
|
-
if (node.type ===
|
|
10981
|
-
if (node.type !==
|
|
11110
|
+
if (node.type === AST_NODE_TYPES46.UnaryExpression && node.operator === "!" && memberLengthOf(node.argument, access)) return true;
|
|
11111
|
+
if (node.type !== AST_NODE_TYPES46.BinaryExpression || !["==", "===", "<="].includes(node.operator)) {
|
|
10982
11112
|
return false;
|
|
10983
11113
|
}
|
|
10984
|
-
const zero = (value) => value.type ===
|
|
11114
|
+
const zero = (value) => value.type === AST_NODE_TYPES46.Literal && value.value === 0;
|
|
10985
11115
|
return memberLengthOf(node.left, access) && zero(node.right) || memberLengthOf(node.right, access) && zero(node.left);
|
|
10986
11116
|
}
|
|
10987
11117
|
function memberLengthOf(node, access) {
|
|
10988
|
-
const target = node.type ===
|
|
10989
|
-
return target.type ===
|
|
11118
|
+
const target = node.type === AST_NODE_TYPES46.ChainExpression ? node.expression : node;
|
|
11119
|
+
return target.type === AST_NODE_TYPES46.MemberExpression && !target.computed && target.property.type === AST_NODE_TYPES46.Identifier && target.property.name === "length" && sameAccess(target.object, access);
|
|
10990
11120
|
}
|
|
10991
11121
|
function optionalMemberLengthOf(node, access) {
|
|
10992
|
-
return node.type ===
|
|
11122
|
+
return node.type === AST_NODE_TYPES46.ChainExpression && node.expression.type === AST_NODE_TYPES46.MemberExpression && node.expression.optional && memberLengthOf(node, access);
|
|
10993
11123
|
}
|
|
10994
11124
|
function hasEquivalentLeadingGuard(fn, access, visitorKeys) {
|
|
10995
|
-
if (fn.body.type !==
|
|
11125
|
+
if (fn.body.type !== AST_NODE_TYPES46.BlockStatement) return false;
|
|
10996
11126
|
const first = fn.body.body[0];
|
|
10997
|
-
if (first?.type !==
|
|
10998
|
-
const terminating = first.consequent.type ===
|
|
11127
|
+
if (first?.type !== AST_NODE_TYPES46.IfStatement) return false;
|
|
11128
|
+
const terminating = first.consequent.type === AST_NODE_TYPES46.ReturnStatement || first.consequent.type === AST_NODE_TYPES46.ThrowStatement || first.consequent.type === AST_NODE_TYPES46.BlockStatement && first.consequent.body.length === 1 && (first.consequent.body[0]?.type === AST_NODE_TYPES46.ReturnStatement || first.consequent.body[0]?.type === AST_NODE_TYPES46.ThrowStatement);
|
|
10999
11129
|
if (!terminating) return false;
|
|
11000
11130
|
if (contains(first.consequent, visitorKeys, (node) => sameAccess(node, access))) return false;
|
|
11001
11131
|
return contains(first.test, visitorKeys, (node) => isNullGuard(node, access)) && contains(first.test, visitorKeys, (node) => isEmptyGuard(node, access));
|
|
@@ -11013,14 +11143,14 @@ function contains(node, visitorKeys, predicate) {
|
|
|
11013
11143
|
function belongsToFunction(node, fn) {
|
|
11014
11144
|
let current = node;
|
|
11015
11145
|
while (current !== void 0 && current !== fn) {
|
|
11016
|
-
if (current !== node && (current.type ===
|
|
11146
|
+
if (current !== node && (current.type === AST_NODE_TYPES46.ArrowFunctionExpression || current.type === AST_NODE_TYPES46.FunctionDeclaration || current.type === AST_NODE_TYPES46.FunctionExpression)) return false;
|
|
11017
11147
|
current = current.parent;
|
|
11018
11148
|
}
|
|
11019
11149
|
return current === fn;
|
|
11020
11150
|
}
|
|
11021
11151
|
function directlyCoalesced(node) {
|
|
11022
11152
|
const parent = node.parent;
|
|
11023
|
-
return parent?.type ===
|
|
11153
|
+
return parent?.type === AST_NODE_TYPES46.LogicalExpression && parent.left === node && (parent.operator === "??" || parent.operator === "||") && emptyArray(parent.right);
|
|
11024
11154
|
}
|
|
11025
11155
|
function identifierIsOnlyCoalesced(context, binding, fn) {
|
|
11026
11156
|
const variable = ASTUtils13.findVariable(context.sourceCode.getScope(binding), binding.name);
|
|
@@ -11035,7 +11165,7 @@ function memberIsOnlyCoalesced(context, object, property, fn) {
|
|
|
11035
11165
|
const accesses = variable.references.flatMap((reference) => {
|
|
11036
11166
|
if (!belongsToFunction(reference.identifier, fn)) return [null];
|
|
11037
11167
|
const parent = reference.identifier.parent;
|
|
11038
|
-
if (parent?.type ===
|
|
11168
|
+
if (parent?.type === AST_NODE_TYPES46.MemberExpression && !parent.computed && parent.object === reference.identifier && parent.property.type === AST_NODE_TYPES46.Identifier && parent.property.name === property) return [parent];
|
|
11039
11169
|
return [];
|
|
11040
11170
|
});
|
|
11041
11171
|
return accesses.length > 0 && accesses.every((access) => access !== null && directlyCoalesced(access));
|
|
@@ -11061,8 +11191,8 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
11061
11191
|
let shapes = /* @__PURE__ */ new Map();
|
|
11062
11192
|
const evidence = /* @__PURE__ */ new Map();
|
|
11063
11193
|
function propertiesFor(annotation) {
|
|
11064
|
-
if (annotation?.type ===
|
|
11065
|
-
if (annotation?.type ===
|
|
11194
|
+
if (annotation?.type === AST_NODE_TYPES46.TSTypeLiteral) return shapeProperties(annotation.members);
|
|
11195
|
+
if (annotation?.type === AST_NODE_TYPES46.TSTypeReference && annotation.typeName.type === AST_NODE_TYPES46.Identifier) {
|
|
11066
11196
|
const shape = shapes.get(annotation.typeName.name);
|
|
11067
11197
|
return shape?.exported === false ? shape.properties : [];
|
|
11068
11198
|
}
|
|
@@ -11075,21 +11205,21 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
11075
11205
|
}
|
|
11076
11206
|
function checkFunction(fn) {
|
|
11077
11207
|
for (const rawParameter of fn.params) {
|
|
11078
|
-
const parameter = rawParameter.type ===
|
|
11079
|
-
if (parameter.type ===
|
|
11208
|
+
const parameter = rawParameter.type === AST_NODE_TYPES46.AssignmentPattern ? rawParameter.left : rawParameter;
|
|
11209
|
+
if (parameter.type === AST_NODE_TYPES46.ObjectPattern) {
|
|
11080
11210
|
const properties2 = propertiesFor(parameter.typeAnnotation?.typeAnnotation);
|
|
11081
11211
|
for (const property of properties2) {
|
|
11082
11212
|
const bindingProperty = parameter.properties.find(
|
|
11083
|
-
(entry) => entry.type ===
|
|
11213
|
+
(entry) => entry.type === AST_NODE_TYPES46.Property && !entry.computed && entry.key.type === AST_NODE_TYPES46.Identifier && entry.key.name === property.name
|
|
11084
11214
|
);
|
|
11085
11215
|
if (bindingProperty === void 0) continue;
|
|
11086
11216
|
const value = bindingProperty.value;
|
|
11087
|
-
const binding = value.type ===
|
|
11088
|
-
if (binding.type !==
|
|
11217
|
+
const binding = value.type === AST_NODE_TYPES46.AssignmentPattern ? value.left : value;
|
|
11218
|
+
if (binding.type !== AST_NODE_TYPES46.Identifier) {
|
|
11089
11219
|
record(property, false);
|
|
11090
11220
|
continue;
|
|
11091
11221
|
}
|
|
11092
|
-
if (value.type ===
|
|
11222
|
+
if (value.type === AST_NODE_TYPES46.AssignmentPattern && emptyArray(value.right) && property.acceptsUndefined && !property.acceptsNull) {
|
|
11093
11223
|
record(property, true);
|
|
11094
11224
|
continue;
|
|
11095
11225
|
}
|
|
@@ -11101,7 +11231,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
11101
11231
|
}
|
|
11102
11232
|
continue;
|
|
11103
11233
|
}
|
|
11104
|
-
if (parameter.type !==
|
|
11234
|
+
if (parameter.type !== AST_NODE_TYPES46.Identifier) continue;
|
|
11105
11235
|
const properties = propertiesFor(parameter.typeAnnotation?.typeAnnotation);
|
|
11106
11236
|
for (const property of properties) {
|
|
11107
11237
|
const access = {
|
|
@@ -11139,8 +11269,9 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
11139
11269
|
|
|
11140
11270
|
// src/rules/prefer-await-in-async-return.ts
|
|
11141
11271
|
import {
|
|
11272
|
+
ASTUtils as ASTUtils14,
|
|
11142
11273
|
ESLintUtils as ESLintUtils3,
|
|
11143
|
-
AST_NODE_TYPES as
|
|
11274
|
+
AST_NODE_TYPES as AST_NODE_TYPES47
|
|
11144
11275
|
} from "@typescript-eslint/utils";
|
|
11145
11276
|
import * as ts2 from "typescript";
|
|
11146
11277
|
var preferAwaitInAsyncReturnDocumentation = {
|
|
@@ -11151,7 +11282,8 @@ var preferAwaitInAsyncReturnDocumentation = {
|
|
|
11151
11282
|
since: "15.6.3",
|
|
11152
11283
|
limitations: [
|
|
11153
11284
|
"Only a single directly returned `.then` call with an inline callback is checked.",
|
|
11154
|
-
"The receiver must be proven Promise-like by TypeScript; untyped files and larger chains are intentionally ignored."
|
|
11285
|
+
"The receiver must be proven Promise-like by TypeScript; untyped files and larger chains are intentionally ignored.",
|
|
11286
|
+
"Direct loader callbacks passed to resolved `React.lazy` and `next/dynamic` imports are excluded because returning the module Promise is their framework contract."
|
|
11155
11287
|
],
|
|
11156
11288
|
examples: [
|
|
11157
11289
|
{
|
|
@@ -11180,30 +11312,30 @@ var preferAwaitInAsyncReturnDocumentation = {
|
|
|
11180
11312
|
}
|
|
11181
11313
|
]
|
|
11182
11314
|
};
|
|
11183
|
-
function
|
|
11315
|
+
function directAsyncReturnOwner(node) {
|
|
11184
11316
|
const parent = node.parent;
|
|
11185
|
-
if (parent.type ===
|
|
11186
|
-
return parent.async && !parent.generator;
|
|
11317
|
+
if (parent.type === AST_NODE_TYPES47.ArrowFunctionExpression && parent.body === node) {
|
|
11318
|
+
return parent.async && !parent.generator ? parent : null;
|
|
11187
11319
|
}
|
|
11188
|
-
if (parent.type !==
|
|
11189
|
-
return
|
|
11320
|
+
if (parent.type !== AST_NODE_TYPES47.ReturnStatement || parent.argument !== node) {
|
|
11321
|
+
return null;
|
|
11190
11322
|
}
|
|
11191
11323
|
let owner = parent.parent;
|
|
11192
11324
|
while (owner !== void 0 && !isRuntimeFunction(owner)) {
|
|
11193
11325
|
owner = owner.parent;
|
|
11194
11326
|
}
|
|
11195
|
-
return owner !== void 0 && owner.async && !owner.generator;
|
|
11327
|
+
return owner !== void 0 && owner.async && !owner.generator ? owner : null;
|
|
11196
11328
|
}
|
|
11197
11329
|
function isRuntimeFunction(node) {
|
|
11198
|
-
return node.type ===
|
|
11330
|
+
return node.type === AST_NODE_TYPES47.ArrowFunctionExpression || node.type === AST_NODE_TYPES47.FunctionDeclaration || node.type === AST_NODE_TYPES47.FunctionExpression;
|
|
11199
11331
|
}
|
|
11200
11332
|
function promiseThenReceiver(node) {
|
|
11201
11333
|
const callee = node.callee;
|
|
11202
|
-
if (callee.type !==
|
|
11334
|
+
if (callee.type !== AST_NODE_TYPES47.MemberExpression || callee.computed || callee.optional || callee.property.type !== AST_NODE_TYPES47.Identifier || callee.property.name !== "then" || node.optional || node.arguments.length !== 1) {
|
|
11203
11335
|
return null;
|
|
11204
11336
|
}
|
|
11205
11337
|
const callback = node.arguments[0];
|
|
11206
|
-
if (callback === void 0 || callback.type !==
|
|
11338
|
+
if (callback === void 0 || callback.type !== AST_NODE_TYPES47.ArrowFunctionExpression && callback.type !== AST_NODE_TYPES47.FunctionExpression) {
|
|
11207
11339
|
return null;
|
|
11208
11340
|
}
|
|
11209
11341
|
return callee.object;
|
|
@@ -11249,9 +11381,33 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
11249
11381
|
services = null;
|
|
11250
11382
|
}
|
|
11251
11383
|
if (services === null) return {};
|
|
11384
|
+
const frameworkLoaders = /* @__PURE__ */ new Set();
|
|
11385
|
+
const rememberFrameworkLoader = (identifier) => {
|
|
11386
|
+
const variable = ASTUtils14.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
11387
|
+
if (variable !== null) frameworkLoaders.add(variable);
|
|
11388
|
+
};
|
|
11389
|
+
const isFrameworkLoaderCallback = (owner) => {
|
|
11390
|
+
const parent = owner.parent;
|
|
11391
|
+
if (parent.type !== AST_NODE_TYPES47.CallExpression || parent.arguments[0] !== owner || parent.callee.type !== AST_NODE_TYPES47.Identifier) return false;
|
|
11392
|
+
const variable = ASTUtils14.findVariable(context.sourceCode.getScope(parent.callee), parent.callee.name);
|
|
11393
|
+
return variable !== null && frameworkLoaders.has(variable);
|
|
11394
|
+
};
|
|
11252
11395
|
return {
|
|
11396
|
+
ImportDeclaration(node) {
|
|
11397
|
+
if (node.source.value === "react") {
|
|
11398
|
+
for (const specifier of node.specifiers) {
|
|
11399
|
+
if (specifier.type === AST_NODE_TYPES47.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES47.Identifier ? specifier.imported.name : specifier.imported.value) === "lazy") rememberFrameworkLoader(specifier.local);
|
|
11400
|
+
}
|
|
11401
|
+
}
|
|
11402
|
+
if (node.source.value === "next/dynamic") {
|
|
11403
|
+
for (const specifier of node.specifiers) {
|
|
11404
|
+
if (specifier.type === AST_NODE_TYPES47.ImportDefaultSpecifier) rememberFrameworkLoader(specifier.local);
|
|
11405
|
+
}
|
|
11406
|
+
}
|
|
11407
|
+
},
|
|
11253
11408
|
CallExpression(node) {
|
|
11254
|
-
|
|
11409
|
+
const owner = directAsyncReturnOwner(node);
|
|
11410
|
+
if (owner === null || isFrameworkLoaderCallback(owner)) return;
|
|
11255
11411
|
const receiver = promiseThenReceiver(node);
|
|
11256
11412
|
if (receiver === null || !isProvenPromiseLike(receiver, services)) {
|
|
11257
11413
|
return;
|
|
@@ -11263,7 +11419,7 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
11263
11419
|
});
|
|
11264
11420
|
|
|
11265
11421
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
11266
|
-
import { AST_NODE_TYPES as
|
|
11422
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES48 } from "@typescript-eslint/utils";
|
|
11267
11423
|
var preferSchemaForApiPayloadDocumentation = {
|
|
11268
11424
|
summary: "Require Zod (or similar) schema validation on `response.json()` / `JSON.parse()` results before property access.",
|
|
11269
11425
|
rationale: "External JSON is untrusted at runtime even when its expected TypeScript shape is known statically.",
|
|
@@ -11278,9 +11434,9 @@ var preferSchemaForApiPayloadDocumentation = {
|
|
|
11278
11434
|
var unwrap4 = (node) => {
|
|
11279
11435
|
let current = node;
|
|
11280
11436
|
while (current !== null && current !== void 0) {
|
|
11281
|
-
if (current.type ===
|
|
11437
|
+
if (current.type === AST_NODE_TYPES48.TSAsExpression || current.type === AST_NODE_TYPES48.TSTypeAssertion || current.type === AST_NODE_TYPES48.TSNonNullExpression || current.type === AST_NODE_TYPES48.TSSatisfiesExpression) {
|
|
11282
11438
|
current = current.expression;
|
|
11283
|
-
} else if (current.type ===
|
|
11439
|
+
} else if (current.type === AST_NODE_TYPES48.ChainExpression) {
|
|
11284
11440
|
current = current.expression;
|
|
11285
11441
|
} else {
|
|
11286
11442
|
break;
|
|
@@ -11295,23 +11451,23 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
11295
11451
|
]);
|
|
11296
11452
|
var isSchemaParseReference = (node) => {
|
|
11297
11453
|
const inner = unwrap4(node);
|
|
11298
|
-
return inner !== null && inner.type ===
|
|
11454
|
+
return inner !== null && inner.type === AST_NODE_TYPES48.MemberExpression && !inner.computed && inner.property.type === AST_NODE_TYPES48.Identifier && (inner.property.name === "parse" || inner.property.name === "safeParse");
|
|
11299
11455
|
};
|
|
11300
11456
|
var isRawPayloadSource = (node, isKnownLocalText) => {
|
|
11301
11457
|
let current = unwrap4(node);
|
|
11302
11458
|
if (current === null) return false;
|
|
11303
|
-
if (current.type ===
|
|
11459
|
+
if (current.type === AST_NODE_TYPES48.AwaitExpression) {
|
|
11304
11460
|
current = unwrap4(current.argument);
|
|
11305
11461
|
}
|
|
11306
|
-
if (current === null || current.type !==
|
|
11462
|
+
if (current === null || current.type !== AST_NODE_TYPES48.CallExpression) {
|
|
11307
11463
|
return false;
|
|
11308
11464
|
}
|
|
11309
11465
|
const callee = unwrap4(current.callee);
|
|
11310
|
-
if (callee === null || callee.type !==
|
|
11466
|
+
if (callee === null || callee.type !== AST_NODE_TYPES48.MemberExpression) {
|
|
11311
11467
|
return false;
|
|
11312
11468
|
}
|
|
11313
11469
|
const property = unwrap4(callee.property);
|
|
11314
|
-
if (property === null || property.type !==
|
|
11470
|
+
if (property === null || property.type !== AST_NODE_TYPES48.Identifier) {
|
|
11315
11471
|
return false;
|
|
11316
11472
|
}
|
|
11317
11473
|
if (property.name === "json") {
|
|
@@ -11321,17 +11477,17 @@ var isRawPayloadSource = (node, isKnownLocalText) => {
|
|
|
11321
11477
|
return !current.arguments.some(isSchemaParseReference) && isRawPayloadSource(callee.object);
|
|
11322
11478
|
}
|
|
11323
11479
|
const object = unwrap4(callee.object);
|
|
11324
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
11480
|
+
return property.name === "parse" && object !== null && object.type === AST_NODE_TYPES48.Identifier && object.name === "JSON" && !isLocalFileRead(current.arguments[0]) && isKnownLocalText?.(current.arguments[0]) !== true;
|
|
11325
11481
|
};
|
|
11326
11482
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
11327
11483
|
var isDirectLocalFileRead = (node) => {
|
|
11328
11484
|
let current = unwrap4(node);
|
|
11329
|
-
if (current?.type ===
|
|
11485
|
+
if (current?.type === AST_NODE_TYPES48.AwaitExpression) {
|
|
11330
11486
|
current = unwrap4(current.argument);
|
|
11331
11487
|
}
|
|
11332
|
-
if (current?.type !==
|
|
11488
|
+
if (current?.type !== AST_NODE_TYPES48.CallExpression) return false;
|
|
11333
11489
|
const callee = unwrap4(current.callee);
|
|
11334
|
-
const name = callee?.type ===
|
|
11490
|
+
const name = callee?.type === AST_NODE_TYPES48.Identifier ? callee.name : callee?.type === AST_NODE_TYPES48.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES48.Identifier ? callee.property.name : null;
|
|
11335
11491
|
return name !== null && FILE_READ_RE.test(name);
|
|
11336
11492
|
};
|
|
11337
11493
|
var isLocalFileRead = (node) => {
|
|
@@ -11358,15 +11514,15 @@ var isLocalFileRead = (node) => {
|
|
|
11358
11514
|
var ASSERTION_CALLEE_RE = /^(expect|assert|should|invariant)$/;
|
|
11359
11515
|
var isInsideAssertion = (node) => {
|
|
11360
11516
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11361
|
-
if (current.type !==
|
|
11517
|
+
if (current.type !== AST_NODE_TYPES48.CallExpression) continue;
|
|
11362
11518
|
let callee = current.callee;
|
|
11363
|
-
while (callee.type ===
|
|
11519
|
+
while (callee.type === AST_NODE_TYPES48.MemberExpression) {
|
|
11364
11520
|
callee = callee.object;
|
|
11365
11521
|
}
|
|
11366
|
-
if (callee.type ===
|
|
11522
|
+
if (callee.type === AST_NODE_TYPES48.CallExpression) {
|
|
11367
11523
|
callee = callee.callee;
|
|
11368
11524
|
}
|
|
11369
|
-
if (callee.type ===
|
|
11525
|
+
if (callee.type === AST_NODE_TYPES48.Identifier && ASSERTION_CALLEE_RE.test(callee.name)) {
|
|
11370
11526
|
return true;
|
|
11371
11527
|
}
|
|
11372
11528
|
}
|
|
@@ -11385,22 +11541,22 @@ var GUARD_NAME_RE = /^(?:is|validate|parse|assert|decode|coerce)[A-Z]/;
|
|
|
11385
11541
|
var isValidationRead = (node) => {
|
|
11386
11542
|
let current = node;
|
|
11387
11543
|
let parent = current.parent;
|
|
11388
|
-
while (parent !== null && parent !== void 0 && (parent.type ===
|
|
11544
|
+
while (parent !== null && parent !== void 0 && (parent.type === AST_NODE_TYPES48.TSAsExpression || parent.type === AST_NODE_TYPES48.TSTypeAssertion || parent.type === AST_NODE_TYPES48.TSNonNullExpression || parent.type === AST_NODE_TYPES48.TSSatisfiesExpression || parent.type === AST_NODE_TYPES48.ChainExpression)) {
|
|
11389
11545
|
current = parent;
|
|
11390
11546
|
parent = parent.parent;
|
|
11391
11547
|
}
|
|
11392
11548
|
if (parent === null || parent === void 0) return false;
|
|
11393
|
-
if (parent.type ===
|
|
11549
|
+
if (parent.type === AST_NODE_TYPES48.UnaryExpression && parent.operator === "typeof" && parent.argument === current) {
|
|
11394
11550
|
return true;
|
|
11395
11551
|
}
|
|
11396
|
-
if (parent.type !==
|
|
11552
|
+
if (parent.type !== AST_NODE_TYPES48.CallExpression || !parent.arguments.some((arg) => arg === current)) {
|
|
11397
11553
|
return false;
|
|
11398
11554
|
}
|
|
11399
11555
|
const callee = parent.callee;
|
|
11400
|
-
if (callee.type ===
|
|
11556
|
+
if (callee.type === AST_NODE_TYPES48.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES48.Identifier && callee.object.name === "Array" && callee.property.type === AST_NODE_TYPES48.Identifier && callee.property.name === "isArray") {
|
|
11401
11557
|
return parent.arguments.length === 1;
|
|
11402
11558
|
}
|
|
11403
|
-
return callee.type ===
|
|
11559
|
+
return callee.type === AST_NODE_TYPES48.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
11404
11560
|
};
|
|
11405
11561
|
var PRIMITIVE_TYPEOF_RESULTS = /* @__PURE__ */ new Set([
|
|
11406
11562
|
"bigint",
|
|
@@ -11411,13 +11567,13 @@ var PRIMITIVE_TYPEOF_RESULTS = /* @__PURE__ */ new Set([
|
|
|
11411
11567
|
"undefined"
|
|
11412
11568
|
]);
|
|
11413
11569
|
var bindingValidationPolarity = (test, bindingName) => {
|
|
11414
|
-
if (test.type ===
|
|
11570
|
+
if (test.type === AST_NODE_TYPES48.UnaryExpression && test.operator === "!") {
|
|
11415
11571
|
const inner = bindingValidationPolarity(test.argument, bindingName);
|
|
11416
11572
|
return inner === "valid-when-true" ? "valid-when-false" : inner === "valid-when-false" ? "valid-when-true" : null;
|
|
11417
11573
|
}
|
|
11418
|
-
if (test.type ===
|
|
11419
|
-
const typeofName = (node) => node.type ===
|
|
11420
|
-
const literalType = (node) => node.type ===
|
|
11574
|
+
if (test.type === AST_NODE_TYPES48.BinaryExpression) {
|
|
11575
|
+
const typeofName = (node) => node.type === AST_NODE_TYPES48.UnaryExpression && node.operator === "typeof" && node.argument.type === AST_NODE_TYPES48.Identifier ? node.argument.name : null;
|
|
11576
|
+
const literalType = (node) => node.type === AST_NODE_TYPES48.Literal && typeof node.value === "string" && PRIMITIVE_TYPEOF_RESULTS.has(node.value) ? node.value : null;
|
|
11421
11577
|
const matches = typeofName(test.left) === bindingName && literalType(test.right) !== null || typeofName(test.right) === bindingName && literalType(test.left) !== null;
|
|
11422
11578
|
if (!matches) return null;
|
|
11423
11579
|
if (test.operator === "===" || test.operator === "==") {
|
|
@@ -11425,9 +11581,9 @@ var bindingValidationPolarity = (test, bindingName) => {
|
|
|
11425
11581
|
}
|
|
11426
11582
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
11427
11583
|
}
|
|
11428
|
-
return test.type ===
|
|
11584
|
+
return test.type === AST_NODE_TYPES48.CallExpression && test.arguments.length === 1 && test.arguments[0]?.type === AST_NODE_TYPES48.Identifier && test.arguments[0].name === bindingName && test.callee.type === AST_NODE_TYPES48.MemberExpression && !test.callee.computed && test.callee.object.type === AST_NODE_TYPES48.Identifier && test.callee.object.name === "Array" && test.callee.property.type === AST_NODE_TYPES48.Identifier && test.callee.property.name === "isArray" ? "valid-when-true" : null;
|
|
11429
11585
|
};
|
|
11430
|
-
var plainMemberAccess = (node) => node.type ===
|
|
11586
|
+
var plainMemberAccess = (node) => node.type === AST_NODE_TYPES48.MemberExpression && !node.computed && node.object.type === AST_NODE_TYPES48.Identifier && node.property.type === AST_NODE_TYPES48.Identifier ? { object: node.object.name, property: node.property.name } : null;
|
|
11431
11587
|
var isSamePlainMember = (node, access) => {
|
|
11432
11588
|
const candidate = plainMemberAccess(node);
|
|
11433
11589
|
return candidate !== null && candidate.object === access.object && candidate.property === access.property;
|
|
@@ -11435,19 +11591,19 @@ var isSamePlainMember = (node, access) => {
|
|
|
11435
11591
|
var nodeWithin2 = (node, container) => node.range[0] >= container.range[0] && node.range[1] <= container.range[1];
|
|
11436
11592
|
var isUseWithinValidatedBranch = (node, bindingName) => {
|
|
11437
11593
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11438
|
-
if (current.type ===
|
|
11594
|
+
if (current.type === AST_NODE_TYPES48.ConditionalExpression) {
|
|
11439
11595
|
const polarity = bindingValidationPolarity(current.test, bindingName);
|
|
11440
11596
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && nodeWithin2(node, current.alternate)) {
|
|
11441
11597
|
return true;
|
|
11442
11598
|
}
|
|
11443
11599
|
}
|
|
11444
|
-
if (current.type ===
|
|
11600
|
+
if (current.type === AST_NODE_TYPES48.IfStatement) {
|
|
11445
11601
|
const polarity = bindingValidationPolarity(current.test, bindingName);
|
|
11446
11602
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && current.alternate !== null && nodeWithin2(node, current.alternate)) {
|
|
11447
11603
|
return true;
|
|
11448
11604
|
}
|
|
11449
11605
|
}
|
|
11450
|
-
if (current.type ===
|
|
11606
|
+
if (current.type === AST_NODE_TYPES48.FunctionDeclaration || current.type === AST_NODE_TYPES48.FunctionExpression || current.type === AST_NODE_TYPES48.ArrowFunctionExpression) {
|
|
11451
11607
|
return false;
|
|
11452
11608
|
}
|
|
11453
11609
|
}
|
|
@@ -11455,32 +11611,32 @@ var isUseWithinValidatedBranch = (node, bindingName) => {
|
|
|
11455
11611
|
};
|
|
11456
11612
|
var isMemberUseWithinValidatedBranch = (node, access) => {
|
|
11457
11613
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11458
|
-
if (current.type ===
|
|
11614
|
+
if (current.type === AST_NODE_TYPES48.ConditionalExpression) {
|
|
11459
11615
|
const polarity = memberValidationPolarity(current.test, access);
|
|
11460
11616
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && nodeWithin2(node, current.alternate)) {
|
|
11461
11617
|
return true;
|
|
11462
11618
|
}
|
|
11463
11619
|
}
|
|
11464
|
-
if (current.type ===
|
|
11620
|
+
if (current.type === AST_NODE_TYPES48.IfStatement) {
|
|
11465
11621
|
const polarity = memberValidationPolarity(current.test, access);
|
|
11466
11622
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && current.alternate !== null && nodeWithin2(node, current.alternate)) {
|
|
11467
11623
|
return true;
|
|
11468
11624
|
}
|
|
11469
11625
|
}
|
|
11470
|
-
if (current.type ===
|
|
11626
|
+
if (current.type === AST_NODE_TYPES48.FunctionDeclaration || current.type === AST_NODE_TYPES48.FunctionExpression || current.type === AST_NODE_TYPES48.ArrowFunctionExpression) {
|
|
11471
11627
|
return false;
|
|
11472
11628
|
}
|
|
11473
11629
|
}
|
|
11474
11630
|
return false;
|
|
11475
11631
|
};
|
|
11476
11632
|
var memberValidationPolarity = (test, access) => {
|
|
11477
|
-
if (test.type ===
|
|
11633
|
+
if (test.type === AST_NODE_TYPES48.UnaryExpression && test.operator === "!") {
|
|
11478
11634
|
const inner = memberValidationPolarity(test.argument, access);
|
|
11479
11635
|
return inner === "valid-when-true" ? "valid-when-false" : inner === "valid-when-false" ? "valid-when-true" : null;
|
|
11480
11636
|
}
|
|
11481
|
-
if (test.type ===
|
|
11482
|
-
const isMatchingTypeof = (node) => node.type ===
|
|
11483
|
-
const isPrimitiveType = (node) => node.type ===
|
|
11637
|
+
if (test.type === AST_NODE_TYPES48.BinaryExpression) {
|
|
11638
|
+
const isMatchingTypeof = (node) => node.type === AST_NODE_TYPES48.UnaryExpression && node.operator === "typeof" && isSamePlainMember(node.argument, access);
|
|
11639
|
+
const isPrimitiveType = (node) => node.type === AST_NODE_TYPES48.Literal && typeof node.value === "string" && PRIMITIVE_TYPEOF_RESULTS.has(node.value);
|
|
11484
11640
|
if (!(isMatchingTypeof(test.left) && isPrimitiveType(test.right) || isMatchingTypeof(test.right) && isPrimitiveType(test.left))) {
|
|
11485
11641
|
return null;
|
|
11486
11642
|
}
|
|
@@ -11489,15 +11645,15 @@ var memberValidationPolarity = (test, access) => {
|
|
|
11489
11645
|
}
|
|
11490
11646
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
11491
11647
|
}
|
|
11492
|
-
return test.type ===
|
|
11648
|
+
return test.type === AST_NODE_TYPES48.CallExpression && test.arguments.length === 1 && test.arguments[0] !== void 0 && test.arguments[0].type !== AST_NODE_TYPES48.SpreadElement && isSamePlainMember(test.arguments[0], access) && test.callee.type === AST_NODE_TYPES48.MemberExpression && !test.callee.computed && test.callee.object.type === AST_NODE_TYPES48.Identifier && test.callee.object.name === "Array" && test.callee.property.type === AST_NODE_TYPES48.Identifier && test.callee.property.name === "isArray" ? "valid-when-true" : null;
|
|
11493
11649
|
};
|
|
11494
11650
|
var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
11495
11651
|
const isValidationReference = (identifier) => {
|
|
11496
11652
|
for (let current = identifier.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11497
|
-
if ((current.type ===
|
|
11653
|
+
if ((current.type === AST_NODE_TYPES48.BinaryExpression || current.type === AST_NODE_TYPES48.CallExpression || current.type === AST_NODE_TYPES48.UnaryExpression) && bindingValidationPolarity(current, identifier.name) !== null) {
|
|
11498
11654
|
return true;
|
|
11499
11655
|
}
|
|
11500
|
-
if (current.type !==
|
|
11656
|
+
if (current.type !== AST_NODE_TYPES48.UnaryExpression && current.type !== AST_NODE_TYPES48.MemberExpression && current.type !== AST_NODE_TYPES48.CallExpression) {
|
|
11501
11657
|
return false;
|
|
11502
11658
|
}
|
|
11503
11659
|
}
|
|
@@ -11505,7 +11661,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11505
11661
|
};
|
|
11506
11662
|
const isGuardedUse = (identifier) => {
|
|
11507
11663
|
for (let current = identifier.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
11508
|
-
if (current.type ===
|
|
11664
|
+
if (current.type === AST_NODE_TYPES48.ConditionalExpression) {
|
|
11509
11665
|
const polarity = bindingValidationPolarity(current.test, identifier.name);
|
|
11510
11666
|
if (polarity === "valid-when-true" && nodeWithin2(identifier, current.consequent)) {
|
|
11511
11667
|
return true;
|
|
@@ -11514,7 +11670,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11514
11670
|
return true;
|
|
11515
11671
|
}
|
|
11516
11672
|
}
|
|
11517
|
-
if (current.type ===
|
|
11673
|
+
if (current.type === AST_NODE_TYPES48.IfStatement) {
|
|
11518
11674
|
const polarity = bindingValidationPolarity(current.test, identifier.name);
|
|
11519
11675
|
if (polarity === "valid-when-true" && nodeWithin2(identifier, current.consequent)) {
|
|
11520
11676
|
return true;
|
|
@@ -11523,14 +11679,14 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11523
11679
|
return true;
|
|
11524
11680
|
}
|
|
11525
11681
|
}
|
|
11526
|
-
if (current.type ===
|
|
11682
|
+
if (current.type === AST_NODE_TYPES48.FunctionDeclaration || current.type === AST_NODE_TYPES48.FunctionExpression || current.type === AST_NODE_TYPES48.ArrowFunctionExpression) {
|
|
11527
11683
|
return false;
|
|
11528
11684
|
}
|
|
11529
11685
|
}
|
|
11530
11686
|
return false;
|
|
11531
11687
|
};
|
|
11532
11688
|
const declarator = member.parent;
|
|
11533
|
-
if (declarator.type !==
|
|
11689
|
+
if (declarator.type !== AST_NODE_TYPES48.VariableDeclarator || declarator.init !== member || declarator.id.type !== AST_NODE_TYPES48.Identifier || declarator.parent.type !== AST_NODE_TYPES48.VariableDeclaration || declarator.parent.kind !== "const") {
|
|
11534
11690
|
return false;
|
|
11535
11691
|
}
|
|
11536
11692
|
const extracted = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
@@ -11538,7 +11694,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
11538
11694
|
let hasValueUse = false;
|
|
11539
11695
|
for (const reference of extracted.references) {
|
|
11540
11696
|
const identifier = reference.identifier;
|
|
11541
|
-
if (identifier.type !==
|
|
11697
|
+
if (identifier.type !== AST_NODE_TYPES48.Identifier) return false;
|
|
11542
11698
|
if (nodeWithin2(identifier, declarator)) continue;
|
|
11543
11699
|
if (isValidationReference(identifier)) continue;
|
|
11544
11700
|
hasValueUse = true;
|
|
@@ -11551,17 +11707,17 @@ var isGuardTestPosition = (node) => {
|
|
|
11551
11707
|
let parent = current.parent;
|
|
11552
11708
|
while (parent !== void 0 && parent !== null) {
|
|
11553
11709
|
switch (parent.type) {
|
|
11554
|
-
case
|
|
11555
|
-
case
|
|
11556
|
-
case
|
|
11710
|
+
case AST_NODE_TYPES48.UnaryExpression:
|
|
11711
|
+
case AST_NODE_TYPES48.LogicalExpression:
|
|
11712
|
+
case AST_NODE_TYPES48.ChainExpression:
|
|
11557
11713
|
current = parent;
|
|
11558
11714
|
parent = parent.parent;
|
|
11559
11715
|
continue;
|
|
11560
|
-
case
|
|
11561
|
-
case
|
|
11562
|
-
case
|
|
11563
|
-
case
|
|
11564
|
-
case
|
|
11716
|
+
case AST_NODE_TYPES48.IfStatement:
|
|
11717
|
+
case AST_NODE_TYPES48.ConditionalExpression:
|
|
11718
|
+
case AST_NODE_TYPES48.WhileStatement:
|
|
11719
|
+
case AST_NODE_TYPES48.DoWhileStatement:
|
|
11720
|
+
case AST_NODE_TYPES48.ForStatement:
|
|
11565
11721
|
return parent.test === current;
|
|
11566
11722
|
default:
|
|
11567
11723
|
return false;
|
|
@@ -11571,7 +11727,7 @@ var isGuardTestPosition = (node) => {
|
|
|
11571
11727
|
};
|
|
11572
11728
|
var unvalidatedVariableRef = (node, scope, tracked) => {
|
|
11573
11729
|
const unwrapped = unwrap4(node);
|
|
11574
|
-
if (unwrapped === null || unwrapped.type !==
|
|
11730
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES48.Identifier) {
|
|
11575
11731
|
return null;
|
|
11576
11732
|
}
|
|
11577
11733
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -11600,7 +11756,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11600
11756
|
const localFileTextVariables = /* @__PURE__ */ new Set();
|
|
11601
11757
|
const localFileTextRef = (node, scope) => {
|
|
11602
11758
|
const unwrapped = unwrap4(node);
|
|
11603
|
-
if (unwrapped?.type !==
|
|
11759
|
+
if (unwrapped?.type !== AST_NODE_TYPES48.Identifier) return null;
|
|
11604
11760
|
const variable = findVariable2(scope, unwrapped.name);
|
|
11605
11761
|
return variable !== null && localFileTextVariables.has(variable) ? variable : null;
|
|
11606
11762
|
};
|
|
@@ -11669,7 +11825,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11669
11825
|
return {
|
|
11670
11826
|
VariableDeclarator(node) {
|
|
11671
11827
|
const scope = context.sourceCode.getScope(node);
|
|
11672
|
-
if (node.id.type ===
|
|
11828
|
+
if (node.id.type === AST_NODE_TYPES48.Identifier) {
|
|
11673
11829
|
const variable = context.sourceCode.getDeclaredVariables(node)[0];
|
|
11674
11830
|
if (variable !== void 0) {
|
|
11675
11831
|
updateLocalFileText(variable, node.init, scope);
|
|
@@ -11677,7 +11833,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11677
11833
|
trackInitializer(node, scope);
|
|
11678
11834
|
return;
|
|
11679
11835
|
}
|
|
11680
|
-
if (node.id.type ===
|
|
11836
|
+
if (node.id.type === AST_NODE_TYPES48.ObjectPattern || node.id.type === AST_NODE_TYPES48.ArrayPattern) {
|
|
11681
11837
|
if (isRawPayloadSource(
|
|
11682
11838
|
node.init,
|
|
11683
11839
|
(candidate) => localFileTextRef(candidate, scope) !== null
|
|
@@ -11694,7 +11850,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11694
11850
|
},
|
|
11695
11851
|
AssignmentExpression(node) {
|
|
11696
11852
|
const scope = context.sourceCode.getScope(node);
|
|
11697
|
-
if (node.left.type ===
|
|
11853
|
+
if (node.left.type === AST_NODE_TYPES48.Identifier) {
|
|
11698
11854
|
const variable = findVariable2(scope, node.left.name);
|
|
11699
11855
|
if (variable === null) return;
|
|
11700
11856
|
const isLocalText = (candidate) => localFileTextRef(candidate, scope) !== null;
|
|
@@ -11708,7 +11864,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11708
11864
|
}
|
|
11709
11865
|
return;
|
|
11710
11866
|
}
|
|
11711
|
-
if (node.left.type ===
|
|
11867
|
+
if (node.left.type === AST_NODE_TYPES48.ObjectPattern || node.left.type === AST_NODE_TYPES48.ArrayPattern) {
|
|
11712
11868
|
if (isRawPayloadSource(
|
|
11713
11869
|
node.right,
|
|
11714
11870
|
(candidate) => localFileTextRef(candidate, scope) !== null
|
|
@@ -11728,15 +11884,15 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11728
11884
|
}
|
|
11729
11885
|
},
|
|
11730
11886
|
CallExpression(node) {
|
|
11731
|
-
if (node.callee.type !==
|
|
11887
|
+
if (node.callee.type !== AST_NODE_TYPES48.Identifier) return;
|
|
11732
11888
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
11733
11889
|
return;
|
|
11734
11890
|
}
|
|
11735
11891
|
const scope = context.sourceCode.getScope(node);
|
|
11736
11892
|
for (const arg of node.arguments) {
|
|
11737
|
-
if (arg.type ===
|
|
11893
|
+
if (arg.type === AST_NODE_TYPES48.SpreadElement) continue;
|
|
11738
11894
|
const unwrapped = unwrap4(arg);
|
|
11739
|
-
if (unwrapped === null || unwrapped.type !==
|
|
11895
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES48.Identifier) {
|
|
11740
11896
|
continue;
|
|
11741
11897
|
}
|
|
11742
11898
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -11753,14 +11909,14 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11753
11909
|
(candidate) => localFileTextRef(candidate, scope) !== null
|
|
11754
11910
|
)) {
|
|
11755
11911
|
const parent = node.parent;
|
|
11756
|
-
if (parent.type ===
|
|
11912
|
+
if (parent.type === AST_NODE_TYPES48.CallExpression && parent.callee === node && node.property.type === AST_NODE_TYPES48.Identifier && (node.property.name === "parse" || node.property.name === "safeParse" || PROMISE_CHAIN_METHODS.has(node.property.name))) {
|
|
11757
11913
|
return;
|
|
11758
11914
|
}
|
|
11759
11915
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
11760
11916
|
return;
|
|
11761
11917
|
}
|
|
11762
|
-
const variable = obj?.type ===
|
|
11763
|
-
if (variable !== null && obj?.type ===
|
|
11918
|
+
const variable = obj?.type === AST_NODE_TYPES48.Identifier ? unvalidatedVariableRef(obj, scope, unvalidatedVariables) : null;
|
|
11919
|
+
if (variable !== null && obj?.type === AST_NODE_TYPES48.Identifier) {
|
|
11764
11920
|
if (isUseWithinValidatedBranch(node, obj.name)) {
|
|
11765
11921
|
return;
|
|
11766
11922
|
}
|
|
@@ -11780,7 +11936,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
11780
11936
|
});
|
|
11781
11937
|
|
|
11782
11938
|
// src/rules/prefer-semantic-colors.ts
|
|
11783
|
-
import { AST_NODE_TYPES as
|
|
11939
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES49 } from "@typescript-eslint/utils";
|
|
11784
11940
|
import { existsSync, readdirSync, readFileSync } from "fs";
|
|
11785
11941
|
import { dirname, join, parse } from "path";
|
|
11786
11942
|
|
|
@@ -11892,7 +12048,7 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
11892
12048
|
var isInsideSvg = (node) => {
|
|
11893
12049
|
let current = node.parent;
|
|
11894
12050
|
while (current !== void 0 && current !== null) {
|
|
11895
|
-
if (current.type ===
|
|
12051
|
+
if (current.type === AST_NODE_TYPES49.JSXElement) {
|
|
11896
12052
|
const name = jsxElementName(current);
|
|
11897
12053
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
11898
12054
|
}
|
|
@@ -11902,8 +12058,8 @@ var isInsideSvg = (node) => {
|
|
|
11902
12058
|
};
|
|
11903
12059
|
function jsxElementName(node) {
|
|
11904
12060
|
const name = node.openingElement.name;
|
|
11905
|
-
if (name.type ===
|
|
11906
|
-
if (name.type ===
|
|
12061
|
+
if (name.type === AST_NODE_TYPES49.JSXIdentifier) return name.name;
|
|
12062
|
+
if (name.type === AST_NODE_TYPES49.JSXMemberExpression && name.property.type === AST_NODE_TYPES49.JSXIdentifier) {
|
|
11907
12063
|
return name.property.name;
|
|
11908
12064
|
}
|
|
11909
12065
|
return null;
|
|
@@ -11929,7 +12085,7 @@ function isSvgLikeElementName(name) {
|
|
|
11929
12085
|
var isInsideIconFactoryPath = (node) => {
|
|
11930
12086
|
let current = node.parent;
|
|
11931
12087
|
while (current !== void 0 && current !== null) {
|
|
11932
|
-
if (current.type ===
|
|
12088
|
+
if (current.type === AST_NODE_TYPES49.Property && propName(current.key) === "path" && current.parent.type === AST_NODE_TYPES49.ObjectExpression && current.parent.parent.type === AST_NODE_TYPES49.CallExpression && current.parent.parent.callee.type === AST_NODE_TYPES49.Identifier && current.parent.parent.callee.name === "createIcon") {
|
|
11933
12089
|
return true;
|
|
11934
12090
|
}
|
|
11935
12091
|
current = current.parent;
|
|
@@ -12063,12 +12219,12 @@ var expandWorkspaceGlob = (root, glob) => {
|
|
|
12063
12219
|
return readdirSync(parent, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => join(parent, entry.name));
|
|
12064
12220
|
};
|
|
12065
12221
|
var propName = (key) => {
|
|
12066
|
-
if (key.type ===
|
|
12067
|
-
if (key.type ===
|
|
12222
|
+
if (key.type === AST_NODE_TYPES49.Identifier) return key.name;
|
|
12223
|
+
if (key.type === AST_NODE_TYPES49.Literal && typeof key.value === "string") return key.value;
|
|
12068
12224
|
return null;
|
|
12069
12225
|
};
|
|
12070
12226
|
var staticallyImportsEmailOrPdfRenderer = (program) => program.body.some((statement) => {
|
|
12071
|
-
if (statement.type !==
|
|
12227
|
+
if (statement.type !== AST_NODE_TYPES49.ImportDeclaration && statement.type !== AST_NODE_TYPES49.ExportNamedDeclaration && statement.type !== AST_NODE_TYPES49.ExportAllDeclaration) {
|
|
12072
12228
|
return false;
|
|
12073
12229
|
}
|
|
12074
12230
|
return statement.source !== null && typeof statement.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(statement.source.value);
|
|
@@ -12121,27 +12277,27 @@ var prefer_semantic_colors_default = createRule({
|
|
|
12121
12277
|
const checkClassNode = (node) => {
|
|
12122
12278
|
if (node === null) return;
|
|
12123
12279
|
switch (node.type) {
|
|
12124
|
-
case
|
|
12280
|
+
case AST_NODE_TYPES49.Literal:
|
|
12125
12281
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
12126
12282
|
break;
|
|
12127
|
-
case
|
|
12283
|
+
case AST_NODE_TYPES49.TemplateLiteral:
|
|
12128
12284
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
12129
12285
|
break;
|
|
12130
|
-
case
|
|
12286
|
+
case AST_NODE_TYPES49.ArrayExpression:
|
|
12131
12287
|
for (const element of node.elements) {
|
|
12132
|
-
if (element !== null && element.type !==
|
|
12288
|
+
if (element !== null && element.type !== AST_NODE_TYPES49.SpreadElement) checkClassNode(element);
|
|
12133
12289
|
}
|
|
12134
12290
|
break;
|
|
12135
|
-
case
|
|
12291
|
+
case AST_NODE_TYPES49.ObjectExpression:
|
|
12136
12292
|
for (const property of node.properties) {
|
|
12137
|
-
if (property.type ===
|
|
12293
|
+
if (property.type === AST_NODE_TYPES49.Property) checkClassNode(property.value);
|
|
12138
12294
|
}
|
|
12139
12295
|
break;
|
|
12140
|
-
case
|
|
12296
|
+
case AST_NODE_TYPES49.ConditionalExpression:
|
|
12141
12297
|
checkClassNode(node.consequent);
|
|
12142
12298
|
checkClassNode(node.alternate);
|
|
12143
12299
|
break;
|
|
12144
|
-
case
|
|
12300
|
+
case AST_NODE_TYPES49.LogicalExpression:
|
|
12145
12301
|
checkClassNode(node.right);
|
|
12146
12302
|
break;
|
|
12147
12303
|
default:
|
|
@@ -12149,32 +12305,32 @@ var prefer_semantic_colors_default = createRule({
|
|
|
12149
12305
|
}
|
|
12150
12306
|
};
|
|
12151
12307
|
const checkColorValueNode = (node) => {
|
|
12152
|
-
if (node.type ===
|
|
12308
|
+
if (node.type === AST_NODE_TYPES49.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value) && !CSS_VAR_REFERENCE_RE.test(node.value)) {
|
|
12153
12309
|
report(node, "inlineColor", { value: node.value });
|
|
12154
12310
|
}
|
|
12155
12311
|
};
|
|
12156
12312
|
return {
|
|
12157
12313
|
"JSXAttribute[name.name='className']"(node) {
|
|
12158
12314
|
if (node.value === null) return;
|
|
12159
|
-
if (node.value.type ===
|
|
12160
|
-
else if (node.value.type ===
|
|
12161
|
-
if (node.value.expression.type !==
|
|
12315
|
+
if (node.value.type === AST_NODE_TYPES49.Literal) checkClassNode(node.value);
|
|
12316
|
+
else if (node.value.type === AST_NODE_TYPES49.JSXExpressionContainer) {
|
|
12317
|
+
if (node.value.expression.type !== AST_NODE_TYPES49.JSXEmptyExpression) {
|
|
12162
12318
|
checkClassNode(node.value.expression);
|
|
12163
12319
|
}
|
|
12164
12320
|
}
|
|
12165
12321
|
},
|
|
12166
12322
|
CallExpression(node) {
|
|
12167
|
-
if (node.callee.type ===
|
|
12323
|
+
if (node.callee.type === AST_NODE_TYPES49.Identifier && node.callee.name === "require" && node.arguments[0]?.type === AST_NODE_TYPES49.Literal && typeof node.arguments[0].value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.arguments[0].value)) {
|
|
12168
12324
|
importsEmailOrPdfRenderer = true;
|
|
12169
12325
|
}
|
|
12170
|
-
if (node.callee.type ===
|
|
12326
|
+
if (node.callee.type === AST_NODE_TYPES49.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
12171
12327
|
for (const arg of node.arguments) {
|
|
12172
|
-
if (arg.type !==
|
|
12328
|
+
if (arg.type !== AST_NODE_TYPES49.SpreadElement) checkClassNode(arg);
|
|
12173
12329
|
}
|
|
12174
12330
|
}
|
|
12175
12331
|
},
|
|
12176
12332
|
VariableDeclarator(node) {
|
|
12177
|
-
if (node.id.type ===
|
|
12333
|
+
if (node.id.type === AST_NODE_TYPES49.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
12178
12334
|
checkClassNode(node.init);
|
|
12179
12335
|
}
|
|
12180
12336
|
},
|
|
@@ -12184,9 +12340,9 @@ var prefer_semantic_colors_default = createRule({
|
|
|
12184
12340
|
},
|
|
12185
12341
|
// SVG artwork colors are exempt; component presentation colors still report.
|
|
12186
12342
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
12187
|
-
if (node.value?.type !==
|
|
12343
|
+
if (node.value?.type !== AST_NODE_TYPES49.Literal) return;
|
|
12188
12344
|
const owner = node.parent.name;
|
|
12189
|
-
if (owner.type ===
|
|
12345
|
+
if (owner.type === AST_NODE_TYPES49.JSXIdentifier && SVG_SHAPE_PRIMITIVES.has(owner.name)) {
|
|
12190
12346
|
return;
|
|
12191
12347
|
}
|
|
12192
12348
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
@@ -12200,7 +12356,7 @@ var prefer_semantic_colors_default = createRule({
|
|
|
12200
12356
|
if (name !== null && STYLE_COLOR_PROPS.has(name)) checkColorValueNode(node.value);
|
|
12201
12357
|
},
|
|
12202
12358
|
ImportExpression(node) {
|
|
12203
|
-
if (node.source.type ===
|
|
12359
|
+
if (node.source.type === AST_NODE_TYPES49.Literal && typeof node.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.source.value)) {
|
|
12204
12360
|
importsEmailOrPdfRenderer = true;
|
|
12205
12361
|
}
|
|
12206
12362
|
},
|
|
@@ -12402,7 +12558,7 @@ var prefer_server_actions_default = createRule({
|
|
|
12402
12558
|
});
|
|
12403
12559
|
|
|
12404
12560
|
// src/rules/prefer-whole-object-assertion.ts
|
|
12405
|
-
import { AST_NODE_TYPES as
|
|
12561
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES50 } from "@typescript-eslint/utils";
|
|
12406
12562
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
12407
12563
|
var SYNTHETIC_LITERAL_MATCHERS = /* @__PURE__ */ new Map([
|
|
12408
12564
|
["toBeNull", "null"],
|
|
@@ -12427,11 +12583,11 @@ var preferWholeObjectAssertionDocumentation = {
|
|
|
12427
12583
|
};
|
|
12428
12584
|
function literalText(node, getText) {
|
|
12429
12585
|
switch (node.type) {
|
|
12430
|
-
case
|
|
12586
|
+
case AST_NODE_TYPES50.Literal:
|
|
12431
12587
|
return "regex" in node ? null : getText(node);
|
|
12432
|
-
case
|
|
12588
|
+
case AST_NODE_TYPES50.TemplateLiteral:
|
|
12433
12589
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
12434
|
-
case
|
|
12590
|
+
case AST_NODE_TYPES50.UnaryExpression:
|
|
12435
12591
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
12436
12592
|
default:
|
|
12437
12593
|
return null;
|
|
@@ -12439,15 +12595,15 @@ function literalText(node, getText) {
|
|
|
12439
12595
|
}
|
|
12440
12596
|
function isPureReceiver(node) {
|
|
12441
12597
|
switch (node.type) {
|
|
12442
|
-
case
|
|
12443
|
-
case
|
|
12598
|
+
case AST_NODE_TYPES50.Identifier:
|
|
12599
|
+
case AST_NODE_TYPES50.ThisExpression:
|
|
12444
12600
|
return true;
|
|
12445
|
-
case
|
|
12601
|
+
case AST_NODE_TYPES50.MemberExpression:
|
|
12446
12602
|
if (node.optional) {
|
|
12447
12603
|
return false;
|
|
12448
12604
|
}
|
|
12449
12605
|
if (node.computed) {
|
|
12450
|
-
return node.property.type ===
|
|
12606
|
+
return node.property.type === AST_NODE_TYPES50.Literal && isPureReceiver(node.object);
|
|
12451
12607
|
}
|
|
12452
12608
|
return isPureReceiver(node.object);
|
|
12453
12609
|
default:
|
|
@@ -12455,11 +12611,21 @@ function isPureReceiver(node) {
|
|
|
12455
12611
|
}
|
|
12456
12612
|
}
|
|
12457
12613
|
function literalIndex(node) {
|
|
12458
|
-
if (node.type !==
|
|
12614
|
+
if (node.type !== AST_NODE_TYPES50.Literal || typeof node.value !== "number") {
|
|
12459
12615
|
return null;
|
|
12460
12616
|
}
|
|
12461
12617
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
12462
12618
|
}
|
|
12619
|
+
function propertyAccess(node) {
|
|
12620
|
+
const path = [];
|
|
12621
|
+
let current = node;
|
|
12622
|
+
while (current.type === AST_NODE_TYPES50.MemberExpression && !current.computed && !current.optional) {
|
|
12623
|
+
if (current.property.type !== AST_NODE_TYPES50.Identifier || COLLECTION_PROPERTIES.has(current.property.name) || LITERAL_KEY_HAZARDS.has(current.property.name)) return null;
|
|
12624
|
+
path.unshift(current.property.name);
|
|
12625
|
+
current = current.object;
|
|
12626
|
+
}
|
|
12627
|
+
return path.length > 0 && isPureReceiver(current) ? { receiver: current, path } : null;
|
|
12628
|
+
}
|
|
12463
12629
|
var prefer_whole_object_assertion_default = createRule({
|
|
12464
12630
|
name: "prefer-whole-object-assertion",
|
|
12465
12631
|
documentation: preferWholeObjectAssertionDocumentation,
|
|
@@ -12482,57 +12648,59 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
12482
12648
|
}
|
|
12483
12649
|
const { sourceCode } = context;
|
|
12484
12650
|
function parseAssertion(statement) {
|
|
12485
|
-
if (statement.type !==
|
|
12651
|
+
if (statement.type !== AST_NODE_TYPES50.ExpressionStatement) {
|
|
12486
12652
|
return null;
|
|
12487
12653
|
}
|
|
12488
12654
|
const call = statement.expression;
|
|
12489
|
-
if (call.type !==
|
|
12655
|
+
if (call.type !== AST_NODE_TYPES50.CallExpression) {
|
|
12490
12656
|
return null;
|
|
12491
12657
|
}
|
|
12492
12658
|
const callee = call.callee;
|
|
12493
|
-
if (callee.type !==
|
|
12659
|
+
if (callee.type !== AST_NODE_TYPES50.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES50.Identifier) {
|
|
12494
12660
|
return null;
|
|
12495
12661
|
}
|
|
12496
12662
|
const matcher = callee.property.name;
|
|
12497
12663
|
const expectCall = callee.object;
|
|
12498
|
-
if (expectCall.type !==
|
|
12664
|
+
if (expectCall.type !== AST_NODE_TYPES50.CallExpression || expectCall.callee.type !== AST_NODE_TYPES50.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
12499
12665
|
return null;
|
|
12500
12666
|
}
|
|
12501
12667
|
const actual = expectCall.arguments[0];
|
|
12502
|
-
if (actual === void 0 || actual.type !==
|
|
12668
|
+
if (actual === void 0 || actual.type !== AST_NODE_TYPES50.MemberExpression || actual.optional) {
|
|
12503
12669
|
return null;
|
|
12504
12670
|
}
|
|
12505
12671
|
if (!isPureReceiver(actual.object)) {
|
|
12506
12672
|
return null;
|
|
12507
12673
|
}
|
|
12508
12674
|
let key;
|
|
12675
|
+
let receiver;
|
|
12509
12676
|
if (actual.computed) {
|
|
12510
12677
|
const index = literalIndex(actual.property);
|
|
12511
12678
|
if (index === null) {
|
|
12512
12679
|
return null;
|
|
12513
12680
|
}
|
|
12514
12681
|
key = { kind: "index", index };
|
|
12682
|
+
receiver = actual.object;
|
|
12515
12683
|
} else {
|
|
12516
|
-
|
|
12517
|
-
|
|
12518
|
-
}
|
|
12519
|
-
|
|
12684
|
+
const access = propertyAccess(actual);
|
|
12685
|
+
if (access === null) return null;
|
|
12686
|
+
key = { kind: "property", path: access.path };
|
|
12687
|
+
receiver = access.receiver;
|
|
12520
12688
|
}
|
|
12521
12689
|
const synthetic = SYNTHETIC_LITERAL_MATCHERS.get(matcher);
|
|
12522
12690
|
if (synthetic !== void 0 && call.arguments.length === 0) {
|
|
12523
|
-
return { statement, receiver
|
|
12691
|
+
return { statement, receiver, key, matcher, expectedText: synthetic, expectedIsLiteral: true };
|
|
12524
12692
|
}
|
|
12525
12693
|
if (!MERGEABLE_MATCHERS.has(matcher)) {
|
|
12526
12694
|
return null;
|
|
12527
12695
|
}
|
|
12528
12696
|
const expected = call.arguments[0];
|
|
12529
|
-
if (call.arguments.length !== 1 || expected === void 0 || expected.type ===
|
|
12697
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === AST_NODE_TYPES50.SpreadElement) {
|
|
12530
12698
|
return null;
|
|
12531
12699
|
}
|
|
12532
12700
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
12533
12701
|
return {
|
|
12534
12702
|
statement,
|
|
12535
|
-
receiver
|
|
12703
|
+
receiver,
|
|
12536
12704
|
key,
|
|
12537
12705
|
matcher,
|
|
12538
12706
|
expectedText: literal ?? sourceCode.getText(expected),
|
|
@@ -12545,7 +12713,8 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
12545
12713
|
);
|
|
12546
12714
|
}
|
|
12547
12715
|
function reportPropertyRun(run) {
|
|
12548
|
-
const
|
|
12716
|
+
const tree = /* @__PURE__ */ new Map();
|
|
12717
|
+
const paths = [];
|
|
12549
12718
|
for (const assertion of run) {
|
|
12550
12719
|
if (assertion.key.kind !== "property" || !assertion.expectedIsLiteral) {
|
|
12551
12720
|
return;
|
|
@@ -12553,19 +12722,44 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
12553
12722
|
if (!MERGEABLE_MATCHERS.has(assertion.matcher) && !SYNTHETIC_LITERAL_MATCHERS.has(assertion.matcher)) {
|
|
12554
12723
|
return;
|
|
12555
12724
|
}
|
|
12556
|
-
|
|
12557
|
-
|
|
12725
|
+
paths.push([...assertion.key.path]);
|
|
12726
|
+
}
|
|
12727
|
+
const commonPrefix = [];
|
|
12728
|
+
for (let index = 0; ; index += 1) {
|
|
12729
|
+
const candidate = paths[0]?.[index];
|
|
12730
|
+
if (candidate === void 0 || paths.some((path) => path[index] !== candidate || path.length === index + 1)) {
|
|
12731
|
+
break;
|
|
12732
|
+
}
|
|
12733
|
+
commonPrefix.push(candidate);
|
|
12734
|
+
}
|
|
12735
|
+
for (const [assertionIndex, assertion] of run.entries()) {
|
|
12736
|
+
if (assertion.key.kind !== "property") return;
|
|
12737
|
+
let branch = tree;
|
|
12738
|
+
const relativePath = paths[assertionIndex]?.slice(commonPrefix.length) ?? [];
|
|
12739
|
+
for (const [index, name] of relativePath.entries()) {
|
|
12740
|
+
const leaf = index === relativePath.length - 1;
|
|
12741
|
+
const existing = branch.get(name);
|
|
12742
|
+
if (leaf) {
|
|
12743
|
+
if (existing !== void 0) return;
|
|
12744
|
+
branch.set(name, assertion.expectedText);
|
|
12745
|
+
} else if (existing === void 0) {
|
|
12746
|
+
const nested = /* @__PURE__ */ new Map();
|
|
12747
|
+
branch.set(name, nested);
|
|
12748
|
+
branch = nested;
|
|
12749
|
+
} else if (existing instanceof Map) {
|
|
12750
|
+
branch = existing;
|
|
12751
|
+
} else {
|
|
12752
|
+
return;
|
|
12753
|
+
}
|
|
12558
12754
|
}
|
|
12559
|
-
names.add(assertion.key.name);
|
|
12560
12755
|
}
|
|
12561
12756
|
const first = run[0];
|
|
12562
12757
|
if (first === void 0) {
|
|
12563
12758
|
return;
|
|
12564
12759
|
}
|
|
12565
|
-
const receiverText = sourceCode.getText(first.receiver)
|
|
12566
|
-
const
|
|
12567
|
-
|
|
12568
|
-
).join(", ");
|
|
12760
|
+
const receiverText = `${sourceCode.getText(first.receiver)}${commonPrefix.map((name) => `.${name}`).join("")}`;
|
|
12761
|
+
const renderTree = (value) => [...value.entries()].map(([name, child]) => `${name}: ${child instanceof Map ? `{ ${renderTree(child)} }` : child}`).join(", ");
|
|
12762
|
+
const properties = renderTree(tree);
|
|
12569
12763
|
context.report({
|
|
12570
12764
|
node: first.statement,
|
|
12571
12765
|
messageId: "combineAssertions",
|
|
@@ -12641,7 +12835,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
12641
12835
|
});
|
|
12642
12836
|
|
|
12643
12837
|
// src/rules/repeated-static-call-cases.ts
|
|
12644
|
-
import { AST_NODE_TYPES as
|
|
12838
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES51, ASTUtils as ASTUtils15 } from "@typescript-eslint/utils";
|
|
12645
12839
|
var repeatedStaticCallCasesDocumentation = {
|
|
12646
12840
|
summary: "Report three or more consecutive literal call assertions that should be independently named test cases.",
|
|
12647
12841
|
rationale: "Copy-pasted cases obscure the input table and stop later cases from being reported after the first failure.",
|
|
@@ -12662,67 +12856,67 @@ var EXPECT_MODIFIERS = /* @__PURE__ */ new Set(["not", "rejects", "resolves"]);
|
|
|
12662
12856
|
var SNAPSHOT_MATCHERS = /snapshot/iu;
|
|
12663
12857
|
var MIN_CASES2 = 3;
|
|
12664
12858
|
function staticMemberName5(node) {
|
|
12665
|
-
if (!node.computed && node.property.type ===
|
|
12666
|
-
if (node.computed && node.property.type ===
|
|
12859
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES51.Identifier) return node.property.name;
|
|
12860
|
+
if (node.computed && node.property.type === AST_NODE_TYPES51.Literal && typeof node.property.value === "string") return node.property.value;
|
|
12667
12861
|
return null;
|
|
12668
12862
|
}
|
|
12669
12863
|
function importedName3(identifier, context, modules) {
|
|
12670
|
-
const variable =
|
|
12864
|
+
const variable = ASTUtils15.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
12671
12865
|
if (variable === null || variable.defs.length === 0) return identifier.name;
|
|
12672
12866
|
for (const definition of variable.defs) {
|
|
12673
|
-
if (definition.node.type !==
|
|
12867
|
+
if (definition.node.type !== AST_NODE_TYPES51.ImportSpecifier) continue;
|
|
12674
12868
|
const declaration = definition.node.parent;
|
|
12675
|
-
if (declaration.type !==
|
|
12869
|
+
if (declaration.type !== AST_NODE_TYPES51.ImportDeclaration || typeof declaration.source.value !== "string" || !modules.has(declaration.source.value)) continue;
|
|
12676
12870
|
const imported = definition.node.imported;
|
|
12677
|
-
return imported.type ===
|
|
12871
|
+
return imported.type === AST_NODE_TYPES51.Identifier ? imported.name : String(imported.value);
|
|
12678
12872
|
}
|
|
12679
12873
|
return null;
|
|
12680
12874
|
}
|
|
12681
12875
|
function isDirectTestCallback2(node, context) {
|
|
12682
|
-
if (node.type !==
|
|
12876
|
+
if (node.type !== AST_NODE_TYPES51.ArrowFunctionExpression && node.type !== AST_NODE_TYPES51.FunctionExpression) return false;
|
|
12683
12877
|
const call = node.parent;
|
|
12684
|
-
if (call?.type !==
|
|
12878
|
+
if (call?.type !== AST_NODE_TYPES51.CallExpression || !call.arguments.includes(node)) return false;
|
|
12685
12879
|
const root = testRoot2(call.callee);
|
|
12686
12880
|
return root !== null && TEST_NAMES2.has(importedName3(root, context, TEST_MODULES4) ?? "");
|
|
12687
12881
|
}
|
|
12688
12882
|
function testRoot2(callee) {
|
|
12689
|
-
if (callee.type ===
|
|
12690
|
-
if (callee.type !==
|
|
12883
|
+
if (callee.type === AST_NODE_TYPES51.Identifier) return callee;
|
|
12884
|
+
if (callee.type !== AST_NODE_TYPES51.MemberExpression) return null;
|
|
12691
12885
|
const modifier = staticMemberName5(callee);
|
|
12692
12886
|
return modifier !== null && TEST_MODIFIERS4.has(modifier) ? testRoot2(callee.object) : null;
|
|
12693
12887
|
}
|
|
12694
12888
|
function isStatic(node) {
|
|
12695
|
-
if (node.type ===
|
|
12889
|
+
if (node.type === AST_NODE_TYPES51.TSAsExpression || node.type === AST_NODE_TYPES51.TSTypeAssertion || node.type === AST_NODE_TYPES51.TSSatisfiesExpression || node.type === AST_NODE_TYPES51.TSNonNullExpression) return isStatic(node.expression);
|
|
12696
12890
|
switch (node.type) {
|
|
12697
|
-
case
|
|
12891
|
+
case AST_NODE_TYPES51.Literal:
|
|
12698
12892
|
return true;
|
|
12699
|
-
case
|
|
12893
|
+
case AST_NODE_TYPES51.TemplateLiteral:
|
|
12700
12894
|
return node.expressions.length === 0;
|
|
12701
|
-
case
|
|
12895
|
+
case AST_NODE_TYPES51.UnaryExpression:
|
|
12702
12896
|
return (node.operator === "+" || node.operator === "-") && isStatic(node.argument);
|
|
12703
|
-
case
|
|
12704
|
-
return node.elements.every((item) => item !== null && item.type !==
|
|
12705
|
-
case
|
|
12706
|
-
return node.properties.every((property) => property.type ===
|
|
12897
|
+
case AST_NODE_TYPES51.ArrayExpression:
|
|
12898
|
+
return node.elements.every((item) => item !== null && item.type !== AST_NODE_TYPES51.SpreadElement && isStatic(item));
|
|
12899
|
+
case AST_NODE_TYPES51.ObjectExpression:
|
|
12900
|
+
return node.properties.every((property) => property.type === AST_NODE_TYPES51.Property && !property.computed && property.kind === "init" && property.value.type !== AST_NODE_TYPES51.AssignmentPattern && isStatic(property.value));
|
|
12707
12901
|
default:
|
|
12708
12902
|
return false;
|
|
12709
12903
|
}
|
|
12710
12904
|
}
|
|
12711
12905
|
function staticShape(node) {
|
|
12712
|
-
if (node.type ===
|
|
12906
|
+
if (node.type === AST_NODE_TYPES51.TSAsExpression || node.type === AST_NODE_TYPES51.TSTypeAssertion || node.type === AST_NODE_TYPES51.TSSatisfiesExpression || node.type === AST_NODE_TYPES51.TSNonNullExpression) return staticShape(node.expression);
|
|
12713
12907
|
switch (node.type) {
|
|
12714
|
-
case
|
|
12908
|
+
case AST_NODE_TYPES51.Literal:
|
|
12715
12909
|
return `literal:${typeof node.value}`;
|
|
12716
|
-
case
|
|
12910
|
+
case AST_NODE_TYPES51.TemplateLiteral:
|
|
12717
12911
|
return "template";
|
|
12718
|
-
case
|
|
12912
|
+
case AST_NODE_TYPES51.UnaryExpression:
|
|
12719
12913
|
return `unary:${node.operator}:${staticShape(node.argument)}`;
|
|
12720
|
-
case
|
|
12721
|
-
return `array(${node.elements.map((item) => item === null || item.type ===
|
|
12722
|
-
case
|
|
12914
|
+
case AST_NODE_TYPES51.ArrayExpression:
|
|
12915
|
+
return `array(${node.elements.map((item) => item === null || item.type === AST_NODE_TYPES51.SpreadElement ? "invalid" : staticShape(item)).join(",")})`;
|
|
12916
|
+
case AST_NODE_TYPES51.ObjectExpression:
|
|
12723
12917
|
return `object(${node.properties.map((property) => {
|
|
12724
|
-
if (property.type !==
|
|
12725
|
-
const key = property.key.type ===
|
|
12918
|
+
if (property.type !== AST_NODE_TYPES51.Property || property.computed || property.value.type === AST_NODE_TYPES51.AssignmentPattern) return "invalid";
|
|
12919
|
+
const key = property.key.type === AST_NODE_TYPES51.Identifier ? property.key.name : String(property.key.value);
|
|
12726
12920
|
return `${key}:${staticShape(property.value)}`;
|
|
12727
12921
|
}).join(",")})`;
|
|
12728
12922
|
default:
|
|
@@ -12730,16 +12924,16 @@ function staticShape(node) {
|
|
|
12730
12924
|
}
|
|
12731
12925
|
}
|
|
12732
12926
|
function assertionShape(statement, context) {
|
|
12733
|
-
if (statement.type !==
|
|
12927
|
+
if (statement.type !== AST_NODE_TYPES51.ExpressionStatement || statement.expression.type !== AST_NODE_TYPES51.CallExpression) return null;
|
|
12734
12928
|
const matcherCall = statement.expression;
|
|
12735
|
-
if (matcherCall.callee.type !==
|
|
12929
|
+
if (matcherCall.callee.type !== AST_NODE_TYPES51.MemberExpression || matcherCall.callee.computed || matcherCall.callee.property.type !== AST_NODE_TYPES51.Identifier || matcherCall.arguments.length !== 1) return null;
|
|
12736
12930
|
const matcher = matcherCall.callee.property.name;
|
|
12737
12931
|
if (SNAPSHOT_MATCHERS.test(matcher)) return null;
|
|
12738
12932
|
const chain = expectCallFromMatcher(matcherCall.callee);
|
|
12739
|
-
if (chain === null || chain.call.callee.type !==
|
|
12933
|
+
if (chain === null || chain.call.callee.type !== AST_NODE_TYPES51.Identifier || importedName3(chain.call.callee, context, ASSERTION_MODULES3) !== "expect" || chain.call.arguments.length !== 1) return null;
|
|
12740
12934
|
const observed = chain.call.arguments[0];
|
|
12741
12935
|
const expected = matcherCall.arguments[0];
|
|
12742
|
-
if (observed?.type !==
|
|
12936
|
+
if (observed?.type !== AST_NODE_TYPES51.CallExpression || observed.callee.type !== AST_NODE_TYPES51.Identifier || observed.arguments.length === 0 || observed.arguments.some((arg) => arg.type === AST_NODE_TYPES51.SpreadElement || !isStatic(arg)) || expected?.type === AST_NODE_TYPES51.SpreadElement || expected === void 0 || !isStatic(expected)) return null;
|
|
12743
12937
|
const skeleton = `${observed.callee.name}/${observed.arguments.map((item) => staticShape(item)).join(",")}/${chain.modifiers.join(".")}/${matcher}/${staticShape(expected)}`;
|
|
12744
12938
|
const values = [...observed.arguments, expected].map((item) => context.sourceCode.getText(item)).join("\0");
|
|
12745
12939
|
return { statement, skeleton, values };
|
|
@@ -12747,13 +12941,13 @@ function assertionShape(statement, context) {
|
|
|
12747
12941
|
function expectCallFromMatcher(node) {
|
|
12748
12942
|
const modifiers = [];
|
|
12749
12943
|
let receiver = node.object;
|
|
12750
|
-
while (receiver.type ===
|
|
12944
|
+
while (receiver.type === AST_NODE_TYPES51.MemberExpression) {
|
|
12751
12945
|
const modifier = staticMemberName5(receiver);
|
|
12752
12946
|
if (modifier === null || !EXPECT_MODIFIERS.has(modifier)) return null;
|
|
12753
12947
|
modifiers.unshift(modifier);
|
|
12754
12948
|
receiver = receiver.object;
|
|
12755
12949
|
}
|
|
12756
|
-
return receiver.type ===
|
|
12950
|
+
return receiver.type === AST_NODE_TYPES51.CallExpression ? { call: receiver, modifiers } : null;
|
|
12757
12951
|
}
|
|
12758
12952
|
var repeated_static_call_cases_default = createRule({
|
|
12759
12953
|
name: "repeated-static-call-cases",
|
|
@@ -12773,7 +12967,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
12773
12967
|
return {
|
|
12774
12968
|
"CallExpression > ArrowFunctionExpression, CallExpression > FunctionExpression"(node) {
|
|
12775
12969
|
const call = node.parent;
|
|
12776
|
-
if (call?.type ===
|
|
12970
|
+
if (call?.type === AST_NODE_TYPES51.CallExpression) {
|
|
12777
12971
|
const duplicate = duplicateTestBodyCandidate(call, sourceCode);
|
|
12778
12972
|
if (duplicate !== null && duplicate.body === node) {
|
|
12779
12973
|
const groups = duplicateGroups.get(duplicate.container) ?? /* @__PURE__ */ new Map();
|
|
@@ -12783,7 +12977,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
12783
12977
|
duplicateGroups.set(duplicate.container, groups);
|
|
12784
12978
|
}
|
|
12785
12979
|
}
|
|
12786
|
-
if (!isDirectTestCallback2(node, context) || node.body.type !==
|
|
12980
|
+
if (!isDirectTestCallback2(node, context) || node.body.type !== AST_NODE_TYPES51.BlockStatement) return;
|
|
12787
12981
|
let run = [];
|
|
12788
12982
|
const flush = () => {
|
|
12789
12983
|
if (run.length >= MIN_CASES2 && new Set(run.map((item) => item.values)).size > 1) {
|
|
@@ -12824,7 +13018,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
12824
13018
|
});
|
|
12825
13019
|
|
|
12826
13020
|
// src/rules/prefer-zod-infer.ts
|
|
12827
|
-
import { AST_NODE_TYPES as
|
|
13021
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES52 } from "@typescript-eslint/utils";
|
|
12828
13022
|
var preferZodInferDocumentation = {
|
|
12829
13023
|
summary: "Derive a type from its Zod schema with `z.infer` instead of hand-writing a twin declaration beside it.",
|
|
12830
13024
|
rationale: "A derived type stays synchronized when the runtime schema changes.",
|
|
@@ -12877,47 +13071,47 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
12877
13071
|
"Schema"
|
|
12878
13072
|
]);
|
|
12879
13073
|
var LEAF_NODE_TYPES = {
|
|
12880
|
-
string: [
|
|
12881
|
-
email: [
|
|
12882
|
-
url: [
|
|
12883
|
-
uuid: [
|
|
12884
|
-
ulid: [
|
|
12885
|
-
cuid: [
|
|
12886
|
-
cuid2: [
|
|
12887
|
-
nanoid: [
|
|
12888
|
-
iso: [
|
|
12889
|
-
number: [
|
|
12890
|
-
int: [
|
|
12891
|
-
float32: [
|
|
12892
|
-
float64: [
|
|
12893
|
-
boolean: [
|
|
12894
|
-
bigint: [
|
|
12895
|
-
symbol: [
|
|
12896
|
-
any: [
|
|
12897
|
-
unknown: [
|
|
12898
|
-
never: [
|
|
12899
|
-
void: [
|
|
12900
|
-
null: [
|
|
12901
|
-
undefined: [
|
|
12902
|
-
literal: [
|
|
12903
|
-
date: [
|
|
12904
|
-
array: [
|
|
12905
|
-
tuple: [
|
|
12906
|
-
object: [
|
|
12907
|
-
strictObject: [
|
|
12908
|
-
looseObject: [
|
|
12909
|
-
record: [
|
|
12910
|
-
map: [
|
|
12911
|
-
set: [
|
|
12912
|
-
promise: [
|
|
12913
|
-
enum: [
|
|
12914
|
-
nativeEnum: [
|
|
12915
|
-
union: [
|
|
12916
|
-
discriminatedUnion: [
|
|
12917
|
-
intersection: [
|
|
13074
|
+
string: [AST_NODE_TYPES52.TSStringKeyword],
|
|
13075
|
+
email: [AST_NODE_TYPES52.TSStringKeyword],
|
|
13076
|
+
url: [AST_NODE_TYPES52.TSStringKeyword],
|
|
13077
|
+
uuid: [AST_NODE_TYPES52.TSStringKeyword],
|
|
13078
|
+
ulid: [AST_NODE_TYPES52.TSStringKeyword],
|
|
13079
|
+
cuid: [AST_NODE_TYPES52.TSStringKeyword],
|
|
13080
|
+
cuid2: [AST_NODE_TYPES52.TSStringKeyword],
|
|
13081
|
+
nanoid: [AST_NODE_TYPES52.TSStringKeyword],
|
|
13082
|
+
iso: [AST_NODE_TYPES52.TSStringKeyword],
|
|
13083
|
+
number: [AST_NODE_TYPES52.TSNumberKeyword],
|
|
13084
|
+
int: [AST_NODE_TYPES52.TSNumberKeyword],
|
|
13085
|
+
float32: [AST_NODE_TYPES52.TSNumberKeyword],
|
|
13086
|
+
float64: [AST_NODE_TYPES52.TSNumberKeyword],
|
|
13087
|
+
boolean: [AST_NODE_TYPES52.TSBooleanKeyword],
|
|
13088
|
+
bigint: [AST_NODE_TYPES52.TSBigIntKeyword],
|
|
13089
|
+
symbol: [AST_NODE_TYPES52.TSSymbolKeyword],
|
|
13090
|
+
any: [AST_NODE_TYPES52.TSAnyKeyword],
|
|
13091
|
+
unknown: [AST_NODE_TYPES52.TSUnknownKeyword],
|
|
13092
|
+
never: [AST_NODE_TYPES52.TSNeverKeyword],
|
|
13093
|
+
void: [AST_NODE_TYPES52.TSVoidKeyword],
|
|
13094
|
+
null: [AST_NODE_TYPES52.TSNullKeyword],
|
|
13095
|
+
undefined: [AST_NODE_TYPES52.TSUndefinedKeyword],
|
|
13096
|
+
literal: [AST_NODE_TYPES52.TSLiteralType],
|
|
13097
|
+
date: [AST_NODE_TYPES52.TSTypeReference],
|
|
13098
|
+
array: [AST_NODE_TYPES52.TSArrayType, AST_NODE_TYPES52.TSTypeReference],
|
|
13099
|
+
tuple: [AST_NODE_TYPES52.TSTupleType],
|
|
13100
|
+
object: [AST_NODE_TYPES52.TSTypeLiteral, AST_NODE_TYPES52.TSTypeReference],
|
|
13101
|
+
strictObject: [AST_NODE_TYPES52.TSTypeLiteral, AST_NODE_TYPES52.TSTypeReference],
|
|
13102
|
+
looseObject: [AST_NODE_TYPES52.TSTypeLiteral, AST_NODE_TYPES52.TSTypeReference],
|
|
13103
|
+
record: [AST_NODE_TYPES52.TSTypeReference, AST_NODE_TYPES52.TSTypeLiteral],
|
|
13104
|
+
map: [AST_NODE_TYPES52.TSTypeReference],
|
|
13105
|
+
set: [AST_NODE_TYPES52.TSTypeReference],
|
|
13106
|
+
promise: [AST_NODE_TYPES52.TSTypeReference],
|
|
13107
|
+
enum: [AST_NODE_TYPES52.TSUnionType, AST_NODE_TYPES52.TSTypeReference, AST_NODE_TYPES52.TSLiteralType],
|
|
13108
|
+
nativeEnum: [AST_NODE_TYPES52.TSUnionType, AST_NODE_TYPES52.TSTypeReference, AST_NODE_TYPES52.TSLiteralType],
|
|
13109
|
+
union: [AST_NODE_TYPES52.TSUnionType, AST_NODE_TYPES52.TSTypeReference],
|
|
13110
|
+
discriminatedUnion: [AST_NODE_TYPES52.TSUnionType, AST_NODE_TYPES52.TSTypeReference],
|
|
13111
|
+
intersection: [AST_NODE_TYPES52.TSIntersectionType, AST_NODE_TYPES52.TSTypeReference]
|
|
12918
13112
|
};
|
|
12919
13113
|
function primitiveLiteralKey(node) {
|
|
12920
|
-
if (node.type !==
|
|
13114
|
+
if (node.type !== AST_NODE_TYPES52.Literal) {
|
|
12921
13115
|
return null;
|
|
12922
13116
|
}
|
|
12923
13117
|
if (node.value === null) {
|
|
@@ -12949,13 +13143,13 @@ function staticZodDomain(leaf, call) {
|
|
|
12949
13143
|
}
|
|
12950
13144
|
if (leaf === "literal") {
|
|
12951
13145
|
const [argument] = call.arguments;
|
|
12952
|
-
if (argument === void 0 || argument.type ===
|
|
13146
|
+
if (argument === void 0 || argument.type === AST_NODE_TYPES52.SpreadElement) {
|
|
12953
13147
|
return null;
|
|
12954
13148
|
}
|
|
12955
|
-
if (argument.type ===
|
|
13149
|
+
if (argument.type === AST_NODE_TYPES52.ArrayExpression) {
|
|
12956
13150
|
return exactDomain(
|
|
12957
13151
|
argument.elements.map(
|
|
12958
|
-
(element) => element === null || element.type ===
|
|
13152
|
+
(element) => element === null || element.type === AST_NODE_TYPES52.SpreadElement ? null : primitiveLiteralKey(element)
|
|
12959
13153
|
)
|
|
12960
13154
|
);
|
|
12961
13155
|
}
|
|
@@ -12963,13 +13157,13 @@ function staticZodDomain(leaf, call) {
|
|
|
12963
13157
|
}
|
|
12964
13158
|
if (leaf === "enum") {
|
|
12965
13159
|
const [argument] = call.arguments;
|
|
12966
|
-
if (argument === void 0 || argument.type ===
|
|
13160
|
+
if (argument === void 0 || argument.type === AST_NODE_TYPES52.SpreadElement) {
|
|
12967
13161
|
return null;
|
|
12968
13162
|
}
|
|
12969
|
-
if (argument.type ===
|
|
13163
|
+
if (argument.type === AST_NODE_TYPES52.ArrayExpression) {
|
|
12970
13164
|
return exactDomain(
|
|
12971
13165
|
argument.elements.map((element) => {
|
|
12972
|
-
if (element === null || element.type ===
|
|
13166
|
+
if (element === null || element.type === AST_NODE_TYPES52.SpreadElement) {
|
|
12973
13167
|
return null;
|
|
12974
13168
|
}
|
|
12975
13169
|
const key = primitiveLiteralKey(element);
|
|
@@ -12977,10 +13171,10 @@ function staticZodDomain(leaf, call) {
|
|
|
12977
13171
|
})
|
|
12978
13172
|
);
|
|
12979
13173
|
}
|
|
12980
|
-
if (argument.type ===
|
|
13174
|
+
if (argument.type === AST_NODE_TYPES52.ObjectExpression) {
|
|
12981
13175
|
return exactDomain(
|
|
12982
13176
|
argument.properties.map((property) => {
|
|
12983
|
-
if (property.type !==
|
|
13177
|
+
if (property.type !== AST_NODE_TYPES52.Property || property.computed || property.kind !== "init" || property.method || property.shorthand) {
|
|
12984
13178
|
return null;
|
|
12985
13179
|
}
|
|
12986
13180
|
const key = primitiveLiteralKey(property.value);
|
|
@@ -13007,15 +13201,15 @@ function sameDomain(left, right) {
|
|
|
13007
13201
|
return true;
|
|
13008
13202
|
}
|
|
13009
13203
|
function isExportedDeclaration(node) {
|
|
13010
|
-
return node.parent?.type ===
|
|
13204
|
+
return node.parent?.type === AST_NODE_TYPES52.ExportNamedDeclaration;
|
|
13011
13205
|
}
|
|
13012
13206
|
function isModuleLevelConst(node) {
|
|
13013
13207
|
const declaration = node.parent;
|
|
13014
|
-
if (declaration.type !==
|
|
13208
|
+
if (declaration.type !== AST_NODE_TYPES52.VariableDeclaration || declaration.kind !== "const") {
|
|
13015
13209
|
return false;
|
|
13016
13210
|
}
|
|
13017
13211
|
const container = declaration.parent;
|
|
13018
|
-
return container.type ===
|
|
13212
|
+
return container.type === AST_NODE_TYPES52.Program || container.type === AST_NODE_TYPES52.ExportNamedDeclaration && container.parent.type === AST_NODE_TYPES52.Program;
|
|
13019
13213
|
}
|
|
13020
13214
|
function normalizeSchemaName(name) {
|
|
13021
13215
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -13024,20 +13218,20 @@ function normalizeTypeName(name) {
|
|
|
13024
13218
|
return name.replace(/Type$/, "").toLowerCase();
|
|
13025
13219
|
}
|
|
13026
13220
|
function unwrapNullish(annotation) {
|
|
13027
|
-
if (annotation.type !==
|
|
13221
|
+
if (annotation.type !== AST_NODE_TYPES52.TSUnionType) {
|
|
13028
13222
|
return {
|
|
13029
13223
|
core: annotation,
|
|
13030
|
-
nullable: annotation.type ===
|
|
13224
|
+
nullable: annotation.type === AST_NODE_TYPES52.TSNullKeyword
|
|
13031
13225
|
};
|
|
13032
13226
|
}
|
|
13033
13227
|
const rest = [];
|
|
13034
13228
|
let nullable = false;
|
|
13035
13229
|
for (const member of annotation.types) {
|
|
13036
|
-
if (member.type ===
|
|
13230
|
+
if (member.type === AST_NODE_TYPES52.TSNullKeyword) {
|
|
13037
13231
|
nullable = true;
|
|
13038
13232
|
continue;
|
|
13039
13233
|
}
|
|
13040
|
-
if (member.type ===
|
|
13234
|
+
if (member.type === AST_NODE_TYPES52.TSUndefinedKeyword) {
|
|
13041
13235
|
continue;
|
|
13042
13236
|
}
|
|
13043
13237
|
rest.push(member);
|
|
@@ -13071,18 +13265,18 @@ function leafAgrees(field, annotation) {
|
|
|
13071
13265
|
return null;
|
|
13072
13266
|
}
|
|
13073
13267
|
if (leaf === "date") {
|
|
13074
|
-
return core.type ===
|
|
13268
|
+
return core.type === AST_NODE_TYPES52.TSTypeReference && core.typeName.type === AST_NODE_TYPES52.Identifier && core.typeName.name === "Date";
|
|
13075
13269
|
}
|
|
13076
13270
|
return expected.includes(core.type);
|
|
13077
13271
|
}
|
|
13078
13272
|
function typeLiteralDomain(annotation) {
|
|
13079
|
-
const members = annotation.type ===
|
|
13273
|
+
const members = annotation.type === AST_NODE_TYPES52.TSUnionType ? annotation.types : [annotation];
|
|
13080
13274
|
const keys = [];
|
|
13081
13275
|
for (const member of members) {
|
|
13082
|
-
if (member.type ===
|
|
13276
|
+
if (member.type === AST_NODE_TYPES52.TSNullKeyword) {
|
|
13083
13277
|
continue;
|
|
13084
13278
|
}
|
|
13085
|
-
if (member.type !==
|
|
13279
|
+
if (member.type !== AST_NODE_TYPES52.TSLiteralType) {
|
|
13086
13280
|
return null;
|
|
13087
13281
|
}
|
|
13088
13282
|
keys.push(primitiveLiteralKey(member.literal));
|
|
@@ -13090,11 +13284,11 @@ function typeLiteralDomain(annotation) {
|
|
|
13090
13284
|
return exactDomain(keys);
|
|
13091
13285
|
}
|
|
13092
13286
|
function staticStringUnionDomain(node) {
|
|
13093
|
-
if (node.type !==
|
|
13287
|
+
if (node.type !== AST_NODE_TYPES52.TSUnionType) {
|
|
13094
13288
|
return null;
|
|
13095
13289
|
}
|
|
13096
13290
|
const keys = node.types.map((member) => {
|
|
13097
|
-
if (member.type !==
|
|
13291
|
+
if (member.type !== AST_NODE_TYPES52.TSLiteralType) {
|
|
13098
13292
|
return null;
|
|
13099
13293
|
}
|
|
13100
13294
|
const key = primitiveLiteralKey(member.literal);
|
|
@@ -13162,14 +13356,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
13162
13356
|
function zodCallChain(node) {
|
|
13163
13357
|
const chain = [];
|
|
13164
13358
|
let current = node;
|
|
13165
|
-
while (current.type ===
|
|
13359
|
+
while (current.type === AST_NODE_TYPES52.CallExpression) {
|
|
13166
13360
|
const callee = current.callee;
|
|
13167
|
-
if (callee.type !==
|
|
13361
|
+
if (callee.type !== AST_NODE_TYPES52.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES52.Identifier) {
|
|
13168
13362
|
return null;
|
|
13169
13363
|
}
|
|
13170
13364
|
chain.push(current);
|
|
13171
13365
|
const receiver = callee.object;
|
|
13172
|
-
if (receiver.type ===
|
|
13366
|
+
if (receiver.type === AST_NODE_TYPES52.Identifier) {
|
|
13173
13367
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
13174
13368
|
}
|
|
13175
13369
|
current = receiver;
|
|
@@ -13178,14 +13372,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
13178
13372
|
}
|
|
13179
13373
|
function methodName2(call) {
|
|
13180
13374
|
const callee = call.callee;
|
|
13181
|
-
return callee.type ===
|
|
13375
|
+
return callee.type === AST_NODE_TYPES52.MemberExpression && callee.property.type === AST_NODE_TYPES52.Identifier ? callee.property.name : "";
|
|
13182
13376
|
}
|
|
13183
13377
|
function recordZodImport(node) {
|
|
13184
13378
|
if (!isZodModule(node.source.value)) {
|
|
13185
13379
|
return;
|
|
13186
13380
|
}
|
|
13187
13381
|
for (const specifier of node.specifiers) {
|
|
13188
|
-
if (specifier.type ===
|
|
13382
|
+
if (specifier.type === AST_NODE_TYPES52.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES52.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES52.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES52.Identifier && specifier.imported.name === "z") {
|
|
13189
13383
|
zodNamespaces.add(specifier.local.name);
|
|
13190
13384
|
}
|
|
13191
13385
|
}
|
|
@@ -13195,13 +13389,13 @@ var prefer_zod_infer_default = createRule({
|
|
|
13195
13389
|
let current = node;
|
|
13196
13390
|
let leaf = null;
|
|
13197
13391
|
let leafCall = null;
|
|
13198
|
-
while (current.type ===
|
|
13392
|
+
while (current.type === AST_NODE_TYPES52.CallExpression) {
|
|
13199
13393
|
const callee = current.callee;
|
|
13200
|
-
if (callee.type !==
|
|
13394
|
+
if (callee.type !== AST_NODE_TYPES52.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES52.Identifier) {
|
|
13201
13395
|
break;
|
|
13202
13396
|
}
|
|
13203
13397
|
const receiver = callee.object;
|
|
13204
|
-
if (receiver.type ===
|
|
13398
|
+
if (receiver.type === AST_NODE_TYPES52.Identifier && zodNamespaces.has(receiver.name)) {
|
|
13205
13399
|
leaf = callee.property.name;
|
|
13206
13400
|
leafCall = current;
|
|
13207
13401
|
break;
|
|
@@ -13232,20 +13426,20 @@ var prefer_zod_infer_default = createRule({
|
|
|
13232
13426
|
return domain instanceof Set && domain.size >= 2 ? domain : null;
|
|
13233
13427
|
}
|
|
13234
13428
|
function inferredSchemaName(node) {
|
|
13235
|
-
if (node.type !==
|
|
13429
|
+
if (node.type !== AST_NODE_TYPES52.TSTypeReference || node.typeName.type !== AST_NODE_TYPES52.TSQualifiedName || node.typeName.left.type !== AST_NODE_TYPES52.Identifier || !zodNamespaces.has(node.typeName.left.name) || node.typeName.right.name !== "infer") {
|
|
13236
13430
|
return null;
|
|
13237
13431
|
}
|
|
13238
13432
|
const arguments_ = node.typeArguments?.params ?? [];
|
|
13239
13433
|
const [argument] = arguments_;
|
|
13240
|
-
return arguments_.length === 1 && argument?.type ===
|
|
13434
|
+
return arguments_.length === 1 && argument?.type === AST_NODE_TYPES52.TSTypeQuery && argument.exprName.type === AST_NODE_TYPES52.Identifier ? argument.exprName.name : null;
|
|
13241
13435
|
}
|
|
13242
13436
|
function recordLiteralUnions(members, owner, ownerName, exported) {
|
|
13243
13437
|
for (const member of members) {
|
|
13244
|
-
if (member.type !==
|
|
13438
|
+
if (member.type !== AST_NODE_TYPES52.TSPropertySignature || member.computed || member.optional || member.readonly || member.typeAnnotation === void 0) {
|
|
13245
13439
|
continue;
|
|
13246
13440
|
}
|
|
13247
13441
|
const key = member.key;
|
|
13248
|
-
const propertyName3 = key.type ===
|
|
13442
|
+
const propertyName3 = key.type === AST_NODE_TYPES52.Identifier ? key.name : key.type === AST_NODE_TYPES52.Literal && typeof key.value === "string" ? key.value : null;
|
|
13249
13443
|
if (propertyName3 === null) {
|
|
13250
13444
|
continue;
|
|
13251
13445
|
}
|
|
@@ -13255,7 +13449,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
13255
13449
|
}
|
|
13256
13450
|
const annotation = member.typeAnnotation.typeAnnotation;
|
|
13257
13451
|
const domain = staticStringUnionDomain(annotation);
|
|
13258
|
-
if (domain === null || annotation.type !==
|
|
13452
|
+
if (domain === null || annotation.type !== AST_NODE_TYPES52.TSUnionType) {
|
|
13259
13453
|
continue;
|
|
13260
13454
|
}
|
|
13261
13455
|
literalUnionOccurrences.push({
|
|
@@ -13286,16 +13480,16 @@ var prefer_zod_infer_default = createRule({
|
|
|
13286
13480
|
return null;
|
|
13287
13481
|
}
|
|
13288
13482
|
const shape = base.arguments[0];
|
|
13289
|
-
if (shape === void 0 || shape.type !==
|
|
13483
|
+
if (shape === void 0 || shape.type !== AST_NODE_TYPES52.ObjectExpression) {
|
|
13290
13484
|
return null;
|
|
13291
13485
|
}
|
|
13292
13486
|
const fields = /* @__PURE__ */ new Map();
|
|
13293
13487
|
for (const property of shape.properties) {
|
|
13294
|
-
if (property.type !==
|
|
13488
|
+
if (property.type !== AST_NODE_TYPES52.Property || property.computed) {
|
|
13295
13489
|
return null;
|
|
13296
13490
|
}
|
|
13297
13491
|
const { key } = property;
|
|
13298
|
-
const name = key.type ===
|
|
13492
|
+
const name = key.type === AST_NODE_TYPES52.Identifier ? key.name : key.type === AST_NODE_TYPES52.Literal && typeof key.value === "string" ? key.value : null;
|
|
13299
13493
|
if (name === null) {
|
|
13300
13494
|
return null;
|
|
13301
13495
|
}
|
|
@@ -13306,11 +13500,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
13306
13500
|
function typeMembers(members) {
|
|
13307
13501
|
const result = /* @__PURE__ */ new Map();
|
|
13308
13502
|
for (const member of members) {
|
|
13309
|
-
if (member.type !==
|
|
13503
|
+
if (member.type !== AST_NODE_TYPES52.TSPropertySignature || member.computed) {
|
|
13310
13504
|
return null;
|
|
13311
13505
|
}
|
|
13312
13506
|
const { key } = member;
|
|
13313
|
-
const name = key.type ===
|
|
13507
|
+
const name = key.type === AST_NODE_TYPES52.Identifier ? key.name : key.type === AST_NODE_TYPES52.Literal && typeof key.value === "string" ? key.value : null;
|
|
13314
13508
|
if (name === null) {
|
|
13315
13509
|
return null;
|
|
13316
13510
|
}
|
|
@@ -13325,8 +13519,8 @@ var prefer_zod_infer_default = createRule({
|
|
|
13325
13519
|
return result.size === 0 ? null : result;
|
|
13326
13520
|
}
|
|
13327
13521
|
function collectConstrainedNames(node) {
|
|
13328
|
-
if (node.type ===
|
|
13329
|
-
if (node.typeName.type ===
|
|
13522
|
+
if (node.type === AST_NODE_TYPES52.TSTypeReference) {
|
|
13523
|
+
if (node.typeName.type === AST_NODE_TYPES52.Identifier) {
|
|
13330
13524
|
constrainedTypeNames.add(node.typeName.name);
|
|
13331
13525
|
}
|
|
13332
13526
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -13334,11 +13528,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
13334
13528
|
}
|
|
13335
13529
|
return;
|
|
13336
13530
|
}
|
|
13337
|
-
if (node.type ===
|
|
13531
|
+
if (node.type === AST_NODE_TYPES52.TSArrayType) {
|
|
13338
13532
|
collectConstrainedNames(node.elementType);
|
|
13339
13533
|
return;
|
|
13340
13534
|
}
|
|
13341
|
-
if (node.type ===
|
|
13535
|
+
if (node.type === AST_NODE_TYPES52.TSUnionType || node.type === AST_NODE_TYPES52.TSIntersectionType) {
|
|
13342
13536
|
for (const member of node.types) {
|
|
13343
13537
|
collectConstrainedNames(member);
|
|
13344
13538
|
}
|
|
@@ -13382,7 +13576,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
13382
13576
|
return {
|
|
13383
13577
|
Program(node) {
|
|
13384
13578
|
for (const statement of node.body) {
|
|
13385
|
-
if (statement.type ===
|
|
13579
|
+
if (statement.type === AST_NODE_TYPES52.ImportDeclaration) {
|
|
13386
13580
|
recordZodImport(statement);
|
|
13387
13581
|
}
|
|
13388
13582
|
}
|
|
@@ -13391,7 +13585,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
13391
13585
|
recordZodImport(node);
|
|
13392
13586
|
},
|
|
13393
13587
|
VariableDeclarator(node) {
|
|
13394
|
-
if (node.id.type !==
|
|
13588
|
+
if (node.id.type !== AST_NODE_TYPES52.Identifier || node.init == null) {
|
|
13395
13589
|
return;
|
|
13396
13590
|
}
|
|
13397
13591
|
const fields = schemaFields(node.init);
|
|
@@ -13408,14 +13602,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
13408
13602
|
},
|
|
13409
13603
|
/** Records `XSchema.transform(...)` and equivalent module-level reshaping. */
|
|
13410
13604
|
"MemberExpression[computed=false]"(node) {
|
|
13411
|
-
if (node.object.type ===
|
|
13605
|
+
if (node.object.type === AST_NODE_TYPES52.Identifier && node.property.type === AST_NODE_TYPES52.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
13412
13606
|
reshapedSchemaNames.add(node.object.name);
|
|
13413
13607
|
}
|
|
13414
13608
|
},
|
|
13415
13609
|
/** Records every type argument carried by a Zod constraint. */
|
|
13416
13610
|
TSTypeReference(node) {
|
|
13417
13611
|
const { typeName } = node;
|
|
13418
|
-
const referenced = typeName.type ===
|
|
13612
|
+
const referenced = typeName.type === AST_NODE_TYPES52.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES52.TSQualifiedName && typeName.right.type === AST_NODE_TYPES52.Identifier ? typeName.right.name : null;
|
|
13419
13613
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
13420
13614
|
return;
|
|
13421
13615
|
}
|
|
@@ -13447,7 +13641,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
13447
13641
|
typeName: node.id.name
|
|
13448
13642
|
});
|
|
13449
13643
|
}
|
|
13450
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
13644
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== AST_NODE_TYPES52.TSTypeLiteral) {
|
|
13451
13645
|
return;
|
|
13452
13646
|
}
|
|
13453
13647
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -13548,7 +13742,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
13548
13742
|
// src/rules/require-assert-never.ts
|
|
13549
13743
|
import {
|
|
13550
13744
|
ESLintUtils as ESLintUtils4,
|
|
13551
|
-
AST_NODE_TYPES as
|
|
13745
|
+
AST_NODE_TYPES as AST_NODE_TYPES53
|
|
13552
13746
|
} from "@typescript-eslint/utils";
|
|
13553
13747
|
import ts3 from "typescript";
|
|
13554
13748
|
var requireAssertNeverDocumentation = {
|
|
@@ -13562,14 +13756,14 @@ var requireAssertNeverDocumentation = {
|
|
|
13562
13756
|
]
|
|
13563
13757
|
};
|
|
13564
13758
|
var isRuntimeHandlingStatement = (statement) => {
|
|
13565
|
-
if (statement.type ===
|
|
13566
|
-
if (statement.type ===
|
|
13759
|
+
if (statement.type === AST_NODE_TYPES53.EmptyStatement) return false;
|
|
13760
|
+
if (statement.type === AST_NODE_TYPES53.BreakStatement) {
|
|
13567
13761
|
return statement.label !== null;
|
|
13568
13762
|
}
|
|
13569
|
-
if (statement.type ===
|
|
13763
|
+
if (statement.type === AST_NODE_TYPES53.TSTypeAliasDeclaration || statement.type === AST_NODE_TYPES53.TSInterfaceDeclaration) {
|
|
13570
13764
|
return false;
|
|
13571
13765
|
}
|
|
13572
|
-
if (statement.type ===
|
|
13766
|
+
if (statement.type === AST_NODE_TYPES53.BlockStatement) {
|
|
13573
13767
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
13574
13768
|
}
|
|
13575
13769
|
return true;
|
|
@@ -13585,7 +13779,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
13585
13779
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
13586
13780
|
}
|
|
13587
13781
|
const only = defaultCase.consequent[0];
|
|
13588
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
13782
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === AST_NODE_TYPES53.BlockStatement && !only.body.some(isRuntimeHandlingStatement)) {
|
|
13589
13783
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
13590
13784
|
}
|
|
13591
13785
|
return false;
|
|
@@ -13668,7 +13862,7 @@ var require_assert_never_default = createRule({
|
|
|
13668
13862
|
});
|
|
13669
13863
|
|
|
13670
13864
|
// src/rules/require-fetch-timeout.ts
|
|
13671
|
-
import { AST_NODE_TYPES as
|
|
13865
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES54, ASTUtils as ASTUtils16 } from "@typescript-eslint/utils";
|
|
13672
13866
|
var requireFetchTimeoutDocumentation = {
|
|
13673
13867
|
summary: "Require an abort `signal` (e.g. `AbortSignal.timeout(ms)`) on global `fetch()` calls so stalled upstreams cannot hang the caller forever.",
|
|
13674
13868
|
rationale: "An unbounded request can occupy work indefinitely when an upstream stalls.",
|
|
@@ -13694,14 +13888,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
13694
13888
|
return false;
|
|
13695
13889
|
}
|
|
13696
13890
|
function initProvablyLacksSignal(init) {
|
|
13697
|
-
if (init.type !==
|
|
13891
|
+
if (init.type !== AST_NODE_TYPES54.ObjectExpression) {
|
|
13698
13892
|
return false;
|
|
13699
13893
|
}
|
|
13700
13894
|
for (const prop of init.properties) {
|
|
13701
|
-
if (prop.type ===
|
|
13895
|
+
if (prop.type === AST_NODE_TYPES54.SpreadElement) {
|
|
13702
13896
|
return false;
|
|
13703
13897
|
}
|
|
13704
|
-
if (prop.key.type ===
|
|
13898
|
+
if (prop.key.type === AST_NODE_TYPES54.Identifier && prop.key.name === "signal" || prop.key.type === AST_NODE_TYPES54.Literal && prop.key.value === "signal") {
|
|
13705
13899
|
return false;
|
|
13706
13900
|
}
|
|
13707
13901
|
if (prop.computed) {
|
|
@@ -13711,7 +13905,7 @@ function initProvablyLacksSignal(init) {
|
|
|
13711
13905
|
return true;
|
|
13712
13906
|
}
|
|
13713
13907
|
function isInlineUrl(node, resolvesToGlobal) {
|
|
13714
|
-
return node.type ===
|
|
13908
|
+
return node.type === AST_NODE_TYPES54.Literal && typeof node.value === "string" || node.type === AST_NODE_TYPES54.TemplateLiteral || node.type === AST_NODE_TYPES54.NewExpression && node.callee.type === AST_NODE_TYPES54.Identifier && node.callee.name === "URL" && resolvesToGlobal(node.callee);
|
|
13715
13909
|
}
|
|
13716
13910
|
var require_fetch_timeout_default = createRule({
|
|
13717
13911
|
name: "require-fetch-timeout",
|
|
@@ -13749,30 +13943,30 @@ var require_fetch_timeout_default = createRule({
|
|
|
13749
13943
|
}
|
|
13750
13944
|
function resolvesToGlobal(identifier) {
|
|
13751
13945
|
const scope = context.sourceCode.getScope(identifier);
|
|
13752
|
-
const variable =
|
|
13946
|
+
const variable = ASTUtils16.findVariable(scope, identifier.name);
|
|
13753
13947
|
return variable === null || variable.defs.length === 0;
|
|
13754
13948
|
}
|
|
13755
13949
|
function isGlobalFetchCall2(callee) {
|
|
13756
|
-
if (callee.type ===
|
|
13950
|
+
if (callee.type === AST_NODE_TYPES54.Identifier) {
|
|
13757
13951
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
13758
13952
|
}
|
|
13759
|
-
return callee.type ===
|
|
13953
|
+
return callee.type === AST_NODE_TYPES54.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES54.Identifier && callee.property.name === "fetch" && callee.object.type === AST_NODE_TYPES54.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
13760
13954
|
}
|
|
13761
13955
|
function localConstInitProvablyLacksSignal(identifier) {
|
|
13762
|
-
const variable =
|
|
13956
|
+
const variable = ASTUtils16.findVariable(
|
|
13763
13957
|
context.sourceCode.getScope(identifier),
|
|
13764
13958
|
identifier.name
|
|
13765
13959
|
);
|
|
13766
13960
|
if (variable?.defs.length !== 1) return false;
|
|
13767
13961
|
const definition = variable.defs[0];
|
|
13768
|
-
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !==
|
|
13962
|
+
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !== AST_NODE_TYPES54.ObjectExpression || !initProvablyLacksSignal(definition.node.init)) {
|
|
13769
13963
|
return false;
|
|
13770
13964
|
}
|
|
13771
13965
|
for (const reference of variable.references) {
|
|
13772
13966
|
const ref = reference.identifier;
|
|
13773
13967
|
if (ref === identifier || ref === definition.name) continue;
|
|
13774
13968
|
const member = ref.parent;
|
|
13775
|
-
if (member.type !==
|
|
13969
|
+
if (member.type !== AST_NODE_TYPES54.MemberExpression || member.object !== ref || member.computed || member.property.type !== AST_NODE_TYPES54.Identifier || member.property.name === "signal" || member.parent.type !== AST_NODE_TYPES54.AssignmentExpression || member.parent.left !== member) {
|
|
13776
13970
|
return false;
|
|
13777
13971
|
}
|
|
13778
13972
|
}
|
|
@@ -13787,7 +13981,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
13787
13981
|
if (node.arguments.length === 1 && first !== void 0 && !isInlineUrl(first, resolvesToGlobal)) {
|
|
13788
13982
|
return;
|
|
13789
13983
|
}
|
|
13790
|
-
if (init === void 0 || initProvablyLacksSignal(init) || init.type ===
|
|
13984
|
+
if (init === void 0 || initProvablyLacksSignal(init) || init.type === AST_NODE_TYPES54.Identifier && localConstInitProvablyLacksSignal(init)) {
|
|
13791
13985
|
context.report({ node, messageId: "missingSignal" });
|
|
13792
13986
|
}
|
|
13793
13987
|
}
|
|
@@ -13796,7 +13990,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
13796
13990
|
});
|
|
13797
13991
|
|
|
13798
13992
|
// src/rules/require-port-for-service.ts
|
|
13799
|
-
import { AST_NODE_TYPES as
|
|
13993
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES55 } from "@typescript-eslint/utils";
|
|
13800
13994
|
var requirePortForServiceDocumentation = {
|
|
13801
13995
|
summary: "Advise when an exported service with injected collaborators has public methods not covered by its declared ports.",
|
|
13802
13996
|
rationale: "A declared port keeps consumers coupled to the service capability instead of its concrete implementation.",
|
|
@@ -13821,45 +14015,45 @@ var ROUTER_FACTORY_NAME = "Router";
|
|
|
13821
14015
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
13822
14016
|
var STORAGE_ASSIGNMENT_OPERATORS = /* @__PURE__ */ new Set(["=", "&&=", "??=", "||="]);
|
|
13823
14017
|
var staticMemberName6 = (member) => {
|
|
13824
|
-
if (member.property.type ===
|
|
13825
|
-
if (!member.computed && member.property.type ===
|
|
13826
|
-
return member.computed && member.property.type ===
|
|
14018
|
+
if (member.property.type === AST_NODE_TYPES55.PrivateIdentifier) return `#${member.property.name}`;
|
|
14019
|
+
if (!member.computed && member.property.type === AST_NODE_TYPES55.Identifier) return member.property.name;
|
|
14020
|
+
return member.computed && member.property.type === AST_NODE_TYPES55.Literal && typeof member.property.value === "string" ? member.property.value : null;
|
|
13827
14021
|
};
|
|
13828
14022
|
var detachedValueExports = (program) => {
|
|
13829
14023
|
const names = /* @__PURE__ */ new Set();
|
|
13830
14024
|
for (const statement of program.body) {
|
|
13831
|
-
if (statement.type ===
|
|
14025
|
+
if (statement.type === AST_NODE_TYPES55.ExportNamedDeclaration && statement.declaration === null && statement.source === null && statement.exportKind !== "type") {
|
|
13832
14026
|
for (const specifier of statement.specifiers) {
|
|
13833
14027
|
if (specifier.exportKind !== "type") names.add(specifier.local.name);
|
|
13834
14028
|
}
|
|
13835
|
-
} else if (statement.type ===
|
|
14029
|
+
} else if (statement.type === AST_NODE_TYPES55.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES55.Identifier) {
|
|
13836
14030
|
names.add(statement.declaration.name);
|
|
13837
|
-
} else if (statement.type ===
|
|
14031
|
+
} else if (statement.type === AST_NODE_TYPES55.TSExportAssignment && statement.expression.type === AST_NODE_TYPES55.Identifier) {
|
|
13838
14032
|
names.add(statement.expression.name);
|
|
13839
14033
|
}
|
|
13840
14034
|
}
|
|
13841
14035
|
return names;
|
|
13842
14036
|
};
|
|
13843
|
-
var isExportedClass2 = (node, detached) => node.parent.type ===
|
|
14037
|
+
var isExportedClass2 = (node, detached) => node.parent.type === AST_NODE_TYPES55.ExportNamedDeclaration || node.parent.type === AST_NODE_TYPES55.ExportDefaultDeclaration || node.id !== null && detached.has(node.id.name);
|
|
13844
14038
|
var readTypeReference = (annotation) => {
|
|
13845
|
-
if (annotation?.type ===
|
|
14039
|
+
if (annotation?.type === AST_NODE_TYPES55.TSUnionType) {
|
|
13846
14040
|
const members = annotation.types.filter(
|
|
13847
|
-
(member) => member.type !==
|
|
14041
|
+
(member) => member.type !== AST_NODE_TYPES55.TSUndefinedKeyword && member.type !== AST_NODE_TYPES55.TSNullKeyword
|
|
13848
14042
|
);
|
|
13849
14043
|
annotation = members.length === 1 ? members[0] : void 0;
|
|
13850
14044
|
}
|
|
13851
|
-
if (annotation === void 0 || annotation.type !==
|
|
14045
|
+
if (annotation === void 0 || annotation.type !== AST_NODE_TYPES55.TSTypeReference) return null;
|
|
13852
14046
|
const { typeName } = annotation;
|
|
13853
|
-
const rightmost = typeName.type ===
|
|
14047
|
+
const rightmost = typeName.type === AST_NODE_TYPES55.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES55.TSQualifiedName ? typeName.right.name : null;
|
|
13854
14048
|
if (rightmost === null) return null;
|
|
13855
14049
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
13856
14050
|
};
|
|
13857
|
-
var qualifiedName = (name) => name.type ===
|
|
14051
|
+
var qualifiedName = (name) => name.type === AST_NODE_TYPES55.Identifier ? name.name : name.type === AST_NODE_TYPES55.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
13858
14052
|
var propertySignatureTypes = (members) => {
|
|
13859
14053
|
const types = /* @__PURE__ */ new Map();
|
|
13860
14054
|
for (const member of members) {
|
|
13861
|
-
if (member.type !==
|
|
13862
|
-
if (member.computed || member.key.type !==
|
|
14055
|
+
if (member.type !== AST_NODE_TYPES55.TSPropertySignature) continue;
|
|
14056
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES55.Identifier) continue;
|
|
13863
14057
|
const reference = readTypeReference(member.typeAnnotation?.typeAnnotation);
|
|
13864
14058
|
if (reference === null) continue;
|
|
13865
14059
|
types.set(member.key.name, reference);
|
|
@@ -13870,18 +14064,18 @@ var fileTypeIndex = (program) => {
|
|
|
13870
14064
|
const objects = /* @__PURE__ */ new Map();
|
|
13871
14065
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
13872
14066
|
for (const statement of program.body) {
|
|
13873
|
-
const declaration = statement.type ===
|
|
13874
|
-
if (declaration?.type ===
|
|
14067
|
+
const declaration = statement.type === AST_NODE_TYPES55.ExportNamedDeclaration ? statement.declaration : statement;
|
|
14068
|
+
if (declaration?.type === AST_NODE_TYPES55.TSInterfaceDeclaration) {
|
|
13875
14069
|
objects.set(declaration.id.name, propertySignatureTypes(declaration.body.body));
|
|
13876
14070
|
continue;
|
|
13877
14071
|
}
|
|
13878
|
-
if (declaration?.type !==
|
|
14072
|
+
if (declaration?.type !== AST_NODE_TYPES55.TSTypeAliasDeclaration) continue;
|
|
13879
14073
|
const aliased = declaration.typeAnnotation;
|
|
13880
|
-
if (aliased.type ===
|
|
14074
|
+
if (aliased.type === AST_NODE_TYPES55.TSFunctionType || aliased.type === AST_NODE_TYPES55.TSConstructorType) {
|
|
13881
14075
|
functionAliases.add(declaration.id.name);
|
|
13882
14076
|
continue;
|
|
13883
14077
|
}
|
|
13884
|
-
const literals = aliased.type ===
|
|
14078
|
+
const literals = aliased.type === AST_NODE_TYPES55.TSTypeLiteral ? [aliased] : aliased.type === AST_NODE_TYPES55.TSIntersectionType ? aliased.types.filter((part) => part.type === AST_NODE_TYPES55.TSTypeLiteral) : [];
|
|
13885
14079
|
if (literals.length === 0) continue;
|
|
13886
14080
|
const merged = /* @__PURE__ */ new Map();
|
|
13887
14081
|
for (const literal of literals) {
|
|
@@ -13909,10 +14103,10 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
13909
14103
|
while (pending.length > 0) {
|
|
13910
14104
|
const current = pending.pop();
|
|
13911
14105
|
if (current === void 0) break;
|
|
13912
|
-
if (current.type ===
|
|
13913
|
-
const expression = current.type ===
|
|
13914
|
-
const storedField = expression?.type ===
|
|
13915
|
-
if (expression?.type !==
|
|
14106
|
+
if (current.type === AST_NODE_TYPES55.ArrowFunctionExpression || current.type === AST_NODE_TYPES55.FunctionExpression || current.type === AST_NODE_TYPES55.FunctionDeclaration || current.type === AST_NODE_TYPES55.ClassExpression || current.type === AST_NODE_TYPES55.ClassDeclaration) continue;
|
|
14107
|
+
const expression = current.type === AST_NODE_TYPES55.ExpressionStatement ? current.expression : null;
|
|
14108
|
+
const storedField = expression?.type === AST_NODE_TYPES55.AssignmentExpression && expression.left.type === AST_NODE_TYPES55.MemberExpression && expression.left.object.type === AST_NODE_TYPES55.ThisExpression ? staticMemberName6(expression.left) : null;
|
|
14109
|
+
if (expression?.type !== AST_NODE_TYPES55.AssignmentExpression || !STORAGE_ASSIGNMENT_OPERATORS.has(expression.operator) || expression.left.type !== AST_NODE_TYPES55.MemberExpression || expression.left.object.type !== AST_NODE_TYPES55.ThisExpression || storedField === null) {
|
|
13916
14110
|
for (const key of Object.keys(current)) {
|
|
13917
14111
|
if (key === "parent") continue;
|
|
13918
14112
|
const value = current[key];
|
|
@@ -13925,14 +14119,14 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
13925
14119
|
continue;
|
|
13926
14120
|
}
|
|
13927
14121
|
let source = expression.right;
|
|
13928
|
-
while (source.type ===
|
|
13929
|
-
if (source.type ===
|
|
14122
|
+
while (source.type === AST_NODE_TYPES55.TSNonNullExpression || source.type === AST_NODE_TYPES55.TSAsExpression || source.type === AST_NODE_TYPES55.TSSatisfiesExpression || source.type === AST_NODE_TYPES55.TSTypeAssertion) source = source.expression;
|
|
14123
|
+
if (source.type === AST_NODE_TYPES55.NewExpression) {
|
|
13930
14124
|
constructedFields += 1;
|
|
13931
|
-
} else if (source.type ===
|
|
14125
|
+
} else if (source.type === AST_NODE_TYPES55.Identifier) {
|
|
13932
14126
|
const fields = storedFieldsFrom.get(source.name) ?? /* @__PURE__ */ new Set();
|
|
13933
14127
|
fields.add(storedField);
|
|
13934
14128
|
storedFieldsFrom.set(source.name, fields);
|
|
13935
|
-
} else if (source.type ===
|
|
14129
|
+
} else if (source.type === AST_NODE_TYPES55.MemberExpression && source.object.type === AST_NODE_TYPES55.Identifier) {
|
|
13936
14130
|
const fields = storedFieldsFrom.get(source.object.name) ?? /* @__PURE__ */ new Set();
|
|
13937
14131
|
fields.add(storedField);
|
|
13938
14132
|
storedFieldsFrom.set(source.object.name, fields);
|
|
@@ -13942,7 +14136,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
13942
14136
|
const collaborators = [];
|
|
13943
14137
|
for (const parameter of ctor.value.params) {
|
|
13944
14138
|
for (const reference of parameterCollaborators(parameter, declared)) {
|
|
13945
|
-
const fields = parameter.type ===
|
|
14139
|
+
const fields = parameter.type === AST_NODE_TYPES55.TSParameterProperty ? [reference.name] : [...storedFieldsFrom.get(reference.name) ?? []];
|
|
13946
14140
|
if (fields.length === 0) continue;
|
|
13947
14141
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
13948
14142
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -13957,8 +14151,8 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
13957
14151
|
};
|
|
13958
14152
|
var parameterCollaborators = (parameter, declared) => {
|
|
13959
14153
|
let target = parameter;
|
|
13960
|
-
if (target.type ===
|
|
13961
|
-
if (target.type ===
|
|
14154
|
+
if (target.type === AST_NODE_TYPES55.AssignmentPattern) target = target.left;
|
|
14155
|
+
if (target.type === AST_NODE_TYPES55.ObjectPattern) {
|
|
13962
14156
|
return objectPatternCollaborators(target, declared);
|
|
13963
14157
|
}
|
|
13964
14158
|
const named2 = namedParameterCollaborator(parameter);
|
|
@@ -13966,9 +14160,9 @@ var parameterCollaborators = (parameter, declared) => {
|
|
|
13966
14160
|
};
|
|
13967
14161
|
var namedParameterCollaborator = (annotated) => {
|
|
13968
14162
|
let target = annotated;
|
|
13969
|
-
if (target.type ===
|
|
13970
|
-
if (target.type ===
|
|
13971
|
-
if (target.type !==
|
|
14163
|
+
if (target.type === AST_NODE_TYPES55.TSParameterProperty) target = target.parameter;
|
|
14164
|
+
if (target.type === AST_NODE_TYPES55.AssignmentPattern) target = target.left;
|
|
14165
|
+
if (target.type !== AST_NODE_TYPES55.Identifier) return null;
|
|
13972
14166
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
13973
14167
|
if (reference === null) return null;
|
|
13974
14168
|
return { name: target.name, ...reference, fields: [] };
|
|
@@ -13980,11 +14174,11 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
13980
14174
|
if (members === null) return [];
|
|
13981
14175
|
const collaborators = [];
|
|
13982
14176
|
for (const property of pattern.properties) {
|
|
13983
|
-
if (property.type !==
|
|
13984
|
-
if (property.key.type !==
|
|
14177
|
+
if (property.type !== AST_NODE_TYPES55.Property || property.computed) continue;
|
|
14178
|
+
if (property.key.type !== AST_NODE_TYPES55.Identifier) continue;
|
|
13985
14179
|
const key = property.key.name;
|
|
13986
|
-
const bound = property.value.type ===
|
|
13987
|
-
if (bound.type !==
|
|
14180
|
+
const bound = property.value.type === AST_NODE_TYPES55.AssignmentPattern ? property.value.left : property.value;
|
|
14181
|
+
if (bound.type !== AST_NODE_TYPES55.Identifier) continue;
|
|
13988
14182
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
13989
14183
|
const reference = members.get(key);
|
|
13990
14184
|
if (reference === void 0) continue;
|
|
@@ -13993,21 +14187,21 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
13993
14187
|
return collaborators;
|
|
13994
14188
|
};
|
|
13995
14189
|
var bagMemberTypes = (annotation, declared) => {
|
|
13996
|
-
if (annotation.type ===
|
|
14190
|
+
if (annotation.type === AST_NODE_TYPES55.TSTypeLiteral) {
|
|
13997
14191
|
return propertySignatureTypes(annotation.members);
|
|
13998
14192
|
}
|
|
13999
|
-
if (annotation.type !==
|
|
14193
|
+
if (annotation.type !== AST_NODE_TYPES55.TSTypeReference || annotation.typeName.type !== AST_NODE_TYPES55.Identifier) {
|
|
14000
14194
|
return null;
|
|
14001
14195
|
}
|
|
14002
14196
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
14003
14197
|
};
|
|
14004
14198
|
var isFrameworkWiring = (body2) => subtreeHas(body2, (node) => {
|
|
14005
|
-
if (node.type ===
|
|
14199
|
+
if (node.type === AST_NODE_TYPES55.CallExpression) {
|
|
14006
14200
|
const { callee } = node;
|
|
14007
|
-
if (callee.type ===
|
|
14008
|
-
return callee.type ===
|
|
14201
|
+
if (callee.type === AST_NODE_TYPES55.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
14202
|
+
return callee.type === AST_NODE_TYPES55.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES55.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
14009
14203
|
}
|
|
14010
|
-
return node.type ===
|
|
14204
|
+
return node.type === AST_NODE_TYPES55.TSTypeReference && node.typeName.type === AST_NODE_TYPES55.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
14011
14205
|
});
|
|
14012
14206
|
var subtreeHas = (root, found) => {
|
|
14013
14207
|
let hit = false;
|
|
@@ -14034,19 +14228,19 @@ var invokedInstanceField = (call) => {
|
|
|
14034
14228
|
const direct = instanceField(call.callee);
|
|
14035
14229
|
if (direct !== null) return direct;
|
|
14036
14230
|
let callee = call.callee;
|
|
14037
|
-
while (callee.type ===
|
|
14038
|
-
return callee.type ===
|
|
14231
|
+
while (callee.type === AST_NODE_TYPES55.ChainExpression || callee.type === AST_NODE_TYPES55.TSAsExpression || callee.type === AST_NODE_TYPES55.TSNonNullExpression || callee.type === AST_NODE_TYPES55.TSSatisfiesExpression || callee.type === AST_NODE_TYPES55.TSTypeAssertion) callee = callee.expression;
|
|
14232
|
+
return callee.type === AST_NODE_TYPES55.MemberExpression ? instanceField(callee.object) : null;
|
|
14039
14233
|
};
|
|
14040
14234
|
var instanceField = (candidate) => {
|
|
14041
14235
|
let node = candidate;
|
|
14042
|
-
while (node.type ===
|
|
14043
|
-
return node.type ===
|
|
14236
|
+
while (node.type === AST_NODE_TYPES55.ChainExpression || node.type === AST_NODE_TYPES55.TSAsExpression || node.type === AST_NODE_TYPES55.TSNonNullExpression || node.type === AST_NODE_TYPES55.TSSatisfiesExpression || node.type === AST_NODE_TYPES55.TSTypeAssertion) node = node.expression;
|
|
14237
|
+
return node.type === AST_NODE_TYPES55.MemberExpression && node.object.type === AST_NODE_TYPES55.ThisExpression ? staticMemberName6(node) : null;
|
|
14044
14238
|
};
|
|
14045
14239
|
var behaviorallyInvokedFields = (body2) => {
|
|
14046
14240
|
const invoked = /* @__PURE__ */ new Set();
|
|
14047
14241
|
const visit = (current) => {
|
|
14048
|
-
if (current.type ===
|
|
14049
|
-
if (current.type ===
|
|
14242
|
+
if (current.type === AST_NODE_TYPES55.ClassDeclaration || current.type === AST_NODE_TYPES55.ClassExpression || current.type === AST_NODE_TYPES55.FunctionDeclaration || current.type === AST_NODE_TYPES55.FunctionExpression) return;
|
|
14243
|
+
if (current.type === AST_NODE_TYPES55.CallExpression) {
|
|
14050
14244
|
const field = invokedInstanceField(current);
|
|
14051
14245
|
if (field !== null) invoked.add(field);
|
|
14052
14246
|
}
|
|
@@ -14059,14 +14253,14 @@ var behaviorallyInvokedFields = (body2) => {
|
|
|
14059
14253
|
}
|
|
14060
14254
|
};
|
|
14061
14255
|
for (const member of body2.body) {
|
|
14062
|
-
if (member.type ===
|
|
14063
|
-
if (member.type ===
|
|
14256
|
+
if (member.type === AST_NODE_TYPES55.StaticBlock || member.static) continue;
|
|
14257
|
+
if (member.type === AST_NODE_TYPES55.MethodDefinition) {
|
|
14064
14258
|
if (member.value.body !== null && member.value.body !== void 0) visit(member.value.body);
|
|
14065
14259
|
continue;
|
|
14066
14260
|
}
|
|
14067
|
-
if (member.type !==
|
|
14261
|
+
if (member.type !== AST_NODE_TYPES55.PropertyDefinition || member.value === null) continue;
|
|
14068
14262
|
visit(
|
|
14069
|
-
member.value.type ===
|
|
14263
|
+
member.value.type === AST_NODE_TYPES55.ArrowFunctionExpression ? member.value.body : member.value
|
|
14070
14264
|
);
|
|
14071
14265
|
}
|
|
14072
14266
|
return invoked;
|
|
@@ -14086,25 +14280,25 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
14086
14280
|
var fileInterfaceNames = (program) => {
|
|
14087
14281
|
const names = [];
|
|
14088
14282
|
for (const statement of program.body) {
|
|
14089
|
-
const declaration = statement.type ===
|
|
14090
|
-
if (declaration?.type ===
|
|
14283
|
+
const declaration = statement.type === AST_NODE_TYPES55.ExportNamedDeclaration ? statement.declaration : statement;
|
|
14284
|
+
if (declaration?.type === AST_NODE_TYPES55.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
14091
14285
|
}
|
|
14092
14286
|
return names;
|
|
14093
14287
|
};
|
|
14094
14288
|
var publicMethodNames = (body2, functionAliases) => {
|
|
14095
14289
|
const names = [];
|
|
14096
14290
|
for (const member of body2.body) {
|
|
14097
|
-
if (member.type ===
|
|
14291
|
+
if (member.type === AST_NODE_TYPES55.PropertyDefinition) {
|
|
14098
14292
|
if (member.static || member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
14099
|
-
if (member.value?.type !==
|
|
14100
|
-
names.push(member.key.type ===
|
|
14293
|
+
if (member.value?.type !== AST_NODE_TYPES55.ArrowFunctionExpression && member.value?.type !== AST_NODE_TYPES55.FunctionExpression && member.typeAnnotation?.typeAnnotation.type !== AST_NODE_TYPES55.TSFunctionType && !(member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES55.TSTypeReference && member.typeAnnotation.typeAnnotation.typeName.type === AST_NODE_TYPES55.Identifier && functionAliases.has(member.typeAnnotation.typeAnnotation.typeName.name))) continue;
|
|
14294
|
+
names.push(member.key.type === AST_NODE_TYPES55.Identifier ? member.key.name : "\u2026");
|
|
14101
14295
|
continue;
|
|
14102
14296
|
}
|
|
14103
|
-
if (member.type !==
|
|
14297
|
+
if (member.type !== AST_NODE_TYPES55.MethodDefinition) continue;
|
|
14104
14298
|
if (member.kind !== "method" || member.static) continue;
|
|
14105
14299
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
14106
|
-
if (member.key.type ===
|
|
14107
|
-
if (member.key.type ===
|
|
14300
|
+
if (member.key.type === AST_NODE_TYPES55.PrivateIdentifier) continue;
|
|
14301
|
+
if (member.key.type === AST_NODE_TYPES55.Identifier) names.push(member.key.name);
|
|
14108
14302
|
else names.push("\u2026");
|
|
14109
14303
|
}
|
|
14110
14304
|
return names;
|
|
@@ -14112,13 +14306,13 @@ var publicMethodNames = (body2, functionAliases) => {
|
|
|
14112
14306
|
var isFluentConstructionObject = (node, getText) => {
|
|
14113
14307
|
if (node.id === null) return false;
|
|
14114
14308
|
const methods = node.body.body.filter(
|
|
14115
|
-
(member) => member.type ===
|
|
14309
|
+
(member) => member.type === AST_NODE_TYPES55.MethodDefinition && member.kind === "method" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.value.body !== null
|
|
14116
14310
|
);
|
|
14117
14311
|
if (methods.length === 0) return false;
|
|
14118
14312
|
return methods.every((member) => {
|
|
14119
14313
|
const result = member.value.returnType?.typeAnnotation;
|
|
14120
14314
|
if (result === void 0) return false;
|
|
14121
|
-
const returnsOwnType = result.type ===
|
|
14315
|
+
const returnsOwnType = result.type === AST_NODE_TYPES55.TSTypeReference && result.typeName.type === AST_NODE_TYPES55.Identifier && result.typeName.name === node.id?.name;
|
|
14122
14316
|
return returnsOwnType || FLUENT_BUILDER_NAME_RE.test(node.id?.name ?? "") && FLUENT_RESULT_TYPE_RE.test(getText(result));
|
|
14123
14317
|
});
|
|
14124
14318
|
};
|
|
@@ -14126,10 +14320,10 @@ function localClassAbstractness(program) {
|
|
|
14126
14320
|
const classes = /* @__PURE__ */ new Map();
|
|
14127
14321
|
const parents = /* @__PURE__ */ new Map();
|
|
14128
14322
|
for (const statement of program.body) {
|
|
14129
|
-
const declaration = statement.type ===
|
|
14130
|
-
if (declaration?.type ===
|
|
14323
|
+
const declaration = statement.type === AST_NODE_TYPES55.ExportNamedDeclaration || statement.type === AST_NODE_TYPES55.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
14324
|
+
if (declaration?.type === AST_NODE_TYPES55.ClassDeclaration && declaration.id !== null) {
|
|
14131
14325
|
classes.set(declaration.id.name, declaration.abstract === true);
|
|
14132
|
-
if (declaration.superClass?.type ===
|
|
14326
|
+
if (declaration.superClass?.type === AST_NODE_TYPES55.Identifier) {
|
|
14133
14327
|
parents.set(declaration.id.name, declaration.superClass.name);
|
|
14134
14328
|
}
|
|
14135
14329
|
}
|
|
@@ -14151,43 +14345,43 @@ function localInterfaceSurfaces(program) {
|
|
|
14151
14345
|
const parents = /* @__PURE__ */ new Map();
|
|
14152
14346
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
14153
14347
|
for (const statement of program.body) {
|
|
14154
|
-
const declaration = statement.type ===
|
|
14155
|
-
if (declaration?.type ===
|
|
14348
|
+
const declaration = statement.type === AST_NODE_TYPES55.ExportNamedDeclaration ? statement.declaration : statement;
|
|
14349
|
+
if (declaration?.type === AST_NODE_TYPES55.TSTypeAliasDeclaration && (declaration.typeAnnotation.type === AST_NODE_TYPES55.TSFunctionType || declaration.typeAnnotation.type === AST_NODE_TYPES55.TSConstructorType)) functionAliases.add(declaration.id.name);
|
|
14156
14350
|
}
|
|
14157
14351
|
for (const statement of program.body) {
|
|
14158
|
-
const declaration = statement.type ===
|
|
14159
|
-
if (declaration?.type ===
|
|
14352
|
+
const declaration = statement.type === AST_NODE_TYPES55.ExportNamedDeclaration ? statement.declaration : statement;
|
|
14353
|
+
if (declaration?.type === AST_NODE_TYPES55.TSTypeAliasDeclaration) {
|
|
14160
14354
|
const callables2 = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
14161
|
-
const parts = declaration.typeAnnotation.type ===
|
|
14355
|
+
const parts = declaration.typeAnnotation.type === AST_NODE_TYPES55.TSIntersectionType ? declaration.typeAnnotation.types : [declaration.typeAnnotation];
|
|
14162
14356
|
const inherited = parents.get(declaration.id.name) ?? [];
|
|
14163
14357
|
for (const part of parts) {
|
|
14164
|
-
if (part.type ===
|
|
14358
|
+
if (part.type === AST_NODE_TYPES55.TSTypeReference && part.typeName.type === AST_NODE_TYPES55.Identifier) {
|
|
14165
14359
|
inherited.push(part.typeName.name);
|
|
14166
14360
|
continue;
|
|
14167
14361
|
}
|
|
14168
|
-
if (part.type !==
|
|
14362
|
+
if (part.type !== AST_NODE_TYPES55.TSTypeLiteral) continue;
|
|
14169
14363
|
for (const member of part.members) {
|
|
14170
|
-
if (member.type !==
|
|
14171
|
-
if (member.computed || member.key.type !==
|
|
14172
|
-
if (member.type ===
|
|
14364
|
+
if (member.type !== AST_NODE_TYPES55.TSMethodSignature && member.type !== AST_NODE_TYPES55.TSPropertySignature) continue;
|
|
14365
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES55.Identifier) continue;
|
|
14366
|
+
if (member.type === AST_NODE_TYPES55.TSMethodSignature) {
|
|
14173
14367
|
callables2.add(member.key.name);
|
|
14174
14368
|
continue;
|
|
14175
14369
|
}
|
|
14176
|
-
if (member.type !==
|
|
14370
|
+
if (member.type !== AST_NODE_TYPES55.TSPropertySignature) continue;
|
|
14177
14371
|
const annotation = member.typeAnnotation?.typeAnnotation;
|
|
14178
|
-
if (annotation?.type ===
|
|
14372
|
+
if (annotation?.type === AST_NODE_TYPES55.TSFunctionType || annotation?.type === AST_NODE_TYPES55.TSTypeReference && annotation.typeName.type === AST_NODE_TYPES55.Identifier && functionAliases.has(annotation.typeName.name)) callables2.add(member.key.name);
|
|
14179
14373
|
}
|
|
14180
14374
|
}
|
|
14181
14375
|
interfaces.set(declaration.id.name, callables2);
|
|
14182
14376
|
parents.set(declaration.id.name, inherited);
|
|
14183
14377
|
continue;
|
|
14184
14378
|
}
|
|
14185
|
-
if (declaration?.type !==
|
|
14379
|
+
if (declaration?.type !== AST_NODE_TYPES55.TSInterfaceDeclaration) continue;
|
|
14186
14380
|
const callables = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
14187
14381
|
for (const member of declaration.body.body) {
|
|
14188
|
-
if (member.type !==
|
|
14189
|
-
if (member.computed || member.key.type !==
|
|
14190
|
-
if (member.type ===
|
|
14382
|
+
if (member.type !== AST_NODE_TYPES55.TSMethodSignature && member.type !== AST_NODE_TYPES55.TSPropertySignature) continue;
|
|
14383
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES55.Identifier) continue;
|
|
14384
|
+
if (member.type === AST_NODE_TYPES55.TSMethodSignature || member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES55.TSFunctionType || member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES55.TSTypeReference && member.typeAnnotation.typeAnnotation.typeName.type === AST_NODE_TYPES55.Identifier && functionAliases.has(member.typeAnnotation.typeAnnotation.typeName.name)) callables.add(member.key.name);
|
|
14191
14385
|
}
|
|
14192
14386
|
interfaces.set(declaration.id.name, callables);
|
|
14193
14387
|
parents.set(
|
|
@@ -14195,7 +14389,7 @@ function localInterfaceSurfaces(program) {
|
|
|
14195
14389
|
[
|
|
14196
14390
|
...parents.get(declaration.id.name) ?? [],
|
|
14197
14391
|
...declaration.extends.flatMap(
|
|
14198
|
-
(heritage) => heritage.expression.type ===
|
|
14392
|
+
(heritage) => heritage.expression.type === AST_NODE_TYPES55.Identifier ? [heritage.expression.name] : ["*"]
|
|
14199
14393
|
)
|
|
14200
14394
|
]
|
|
14201
14395
|
);
|
|
@@ -14222,7 +14416,7 @@ function localInterfaceSurfaces(program) {
|
|
|
14222
14416
|
}
|
|
14223
14417
|
function hasServicePort(node, methods, classes, interfaces) {
|
|
14224
14418
|
if (node.superClass !== null) {
|
|
14225
|
-
if (node.superClass.type !==
|
|
14419
|
+
if (node.superClass.type !== AST_NODE_TYPES55.Identifier) return true;
|
|
14226
14420
|
const localAbstract = classes.get(node.superClass.name);
|
|
14227
14421
|
if (localAbstract === void 0 || localAbstract) return true;
|
|
14228
14422
|
}
|
|
@@ -14234,7 +14428,7 @@ function hasServicePort(node, methods, classes, interfaces) {
|
|
|
14234
14428
|
if (node.implements.length === 0) return false;
|
|
14235
14429
|
const combined = /* @__PURE__ */ new Set();
|
|
14236
14430
|
for (const implementation of node.implements) {
|
|
14237
|
-
if (implementation.expression.type !==
|
|
14431
|
+
if (implementation.expression.type !== AST_NODE_TYPES55.Identifier) return true;
|
|
14238
14432
|
const name = implementation.expression.name;
|
|
14239
14433
|
const localAbstract = classes.get(name);
|
|
14240
14434
|
if (localAbstract === true) return true;
|
|
@@ -14277,7 +14471,7 @@ var require_port_for_service_default = createRule({
|
|
|
14277
14471
|
if (node.abstract === true) return;
|
|
14278
14472
|
if (node.decorators.length > 0) return;
|
|
14279
14473
|
const ctor = node.body.body.find(
|
|
14280
|
-
(member) => member.type ===
|
|
14474
|
+
(member) => member.type === AST_NODE_TYPES55.MethodDefinition && member.kind === "constructor" && member.value.body !== null && member.value.body !== void 0
|
|
14281
14475
|
);
|
|
14282
14476
|
if (ctor === void 0) return;
|
|
14283
14477
|
const constructorFacts = readConstructor(
|
|
@@ -14312,7 +14506,7 @@ var require_port_for_service_default = createRule({
|
|
|
14312
14506
|
});
|
|
14313
14507
|
|
|
14314
14508
|
// src/rules/require-static-next-matcher.ts
|
|
14315
|
-
import { AST_NODE_TYPES as
|
|
14509
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES56 } from "@typescript-eslint/utils";
|
|
14316
14510
|
var requireStaticNextMatcherDocumentation = {
|
|
14317
14511
|
summary: "Require Next.js middleware and proxy matcher configuration to contain only build-time literals.",
|
|
14318
14512
|
rationale: "Next.js must statically analyze matcher values at build time; computed values are ignored.",
|
|
@@ -14325,34 +14519,34 @@ var requireStaticNextMatcherDocumentation = {
|
|
|
14325
14519
|
};
|
|
14326
14520
|
var NEXT_ENTRY_FILE = /(?:^|[/\\])(?:middleware|proxy)\.[cm]?[jt]sx?$/u;
|
|
14327
14521
|
function unwrapExpression3(node) {
|
|
14328
|
-
if (node.type ===
|
|
14522
|
+
if (node.type === AST_NODE_TYPES56.TSAsExpression || node.type === AST_NODE_TYPES56.TSSatisfiesExpression || node.type === AST_NODE_TYPES56.TSNonNullExpression || node.type === AST_NODE_TYPES56.TSTypeAssertion) {
|
|
14329
14523
|
return unwrapExpression3(node.expression);
|
|
14330
14524
|
}
|
|
14331
14525
|
return node;
|
|
14332
14526
|
}
|
|
14333
14527
|
function isStaticValue(node) {
|
|
14334
14528
|
const value = unwrapExpression3(node);
|
|
14335
|
-
if (value.type ===
|
|
14529
|
+
if (value.type === AST_NODE_TYPES56.Literal) {
|
|
14336
14530
|
return true;
|
|
14337
14531
|
}
|
|
14338
|
-
if (value.type ===
|
|
14532
|
+
if (value.type === AST_NODE_TYPES56.TemplateLiteral) {
|
|
14339
14533
|
return value.expressions.length === 0;
|
|
14340
14534
|
}
|
|
14341
|
-
if (value.type ===
|
|
14535
|
+
if (value.type === AST_NODE_TYPES56.ArrayExpression) {
|
|
14342
14536
|
return value.elements.every(
|
|
14343
|
-
(element) => element !== null && element.type !==
|
|
14537
|
+
(element) => element !== null && element.type !== AST_NODE_TYPES56.SpreadElement && isStaticValue(element)
|
|
14344
14538
|
);
|
|
14345
14539
|
}
|
|
14346
|
-
if (value.type ===
|
|
14540
|
+
if (value.type === AST_NODE_TYPES56.ObjectExpression) {
|
|
14347
14541
|
return value.properties.every(
|
|
14348
|
-
(property) => property.type ===
|
|
14542
|
+
(property) => property.type === AST_NODE_TYPES56.Property && property.kind === "init" && !property.computed && property.value.type !== AST_NODE_TYPES56.AssignmentPattern && isStaticValue(property.value)
|
|
14349
14543
|
);
|
|
14350
14544
|
}
|
|
14351
14545
|
return false;
|
|
14352
14546
|
}
|
|
14353
14547
|
function propertyName2(property) {
|
|
14354
14548
|
if (property.computed) return null;
|
|
14355
|
-
if (property.key.type ===
|
|
14549
|
+
if (property.key.type === AST_NODE_TYPES56.Identifier) return property.key.name;
|
|
14356
14550
|
return typeof property.key.value === "string" ? property.key.value : null;
|
|
14357
14551
|
}
|
|
14358
14552
|
var require_static_next_matcher_default = createRule({
|
|
@@ -14375,19 +14569,19 @@ var require_static_next_matcher_default = createRule({
|
|
|
14375
14569
|
}
|
|
14376
14570
|
return {
|
|
14377
14571
|
ExportNamedDeclaration(node) {
|
|
14378
|
-
if (node.declaration?.type !==
|
|
14572
|
+
if (node.declaration?.type !== AST_NODE_TYPES56.VariableDeclaration) {
|
|
14379
14573
|
return;
|
|
14380
14574
|
}
|
|
14381
14575
|
for (const declaration of node.declaration.declarations) {
|
|
14382
|
-
if (declaration.id.type !==
|
|
14576
|
+
if (declaration.id.type !== AST_NODE_TYPES56.Identifier || declaration.id.name !== "config" || declaration.init === null) {
|
|
14383
14577
|
continue;
|
|
14384
14578
|
}
|
|
14385
14579
|
const config = unwrapExpression3(declaration.init);
|
|
14386
|
-
if (config.type !==
|
|
14580
|
+
if (config.type !== AST_NODE_TYPES56.ObjectExpression) {
|
|
14387
14581
|
continue;
|
|
14388
14582
|
}
|
|
14389
14583
|
for (const property of config.properties) {
|
|
14390
|
-
if (property.type !==
|
|
14584
|
+
if (property.type !== AST_NODE_TYPES56.Property || propertyName2(property) !== "matcher" || property.value.type === AST_NODE_TYPES56.AssignmentPattern) {
|
|
14391
14585
|
continue;
|
|
14392
14586
|
}
|
|
14393
14587
|
if (!isStaticValue(property.value)) {
|
|
@@ -14402,8 +14596,8 @@ var require_static_next_matcher_default = createRule({
|
|
|
14402
14596
|
|
|
14403
14597
|
// src/rules/require-zod-form-validation.ts
|
|
14404
14598
|
import {
|
|
14405
|
-
AST_NODE_TYPES as
|
|
14406
|
-
ASTUtils as
|
|
14599
|
+
AST_NODE_TYPES as AST_NODE_TYPES57,
|
|
14600
|
+
ASTUtils as ASTUtils17
|
|
14407
14601
|
} from "@typescript-eslint/utils";
|
|
14408
14602
|
var requireZodFormValidationDocumentation = {
|
|
14409
14603
|
summary: "Require Zod validation (`Schema.parse(...)` / `Schema.safeParse(...)`) when reading values out of a `FormData` object.",
|
|
@@ -14429,14 +14623,14 @@ var FORM_VALUE_METHODS = /* @__PURE__ */ new Set(["get", "getAll"]);
|
|
|
14429
14623
|
var zodReceiverRoot = (node) => {
|
|
14430
14624
|
let current = node;
|
|
14431
14625
|
while (true) {
|
|
14432
|
-
if (current.type ===
|
|
14626
|
+
if (current.type === AST_NODE_TYPES57.Identifier) {
|
|
14433
14627
|
return current;
|
|
14434
14628
|
}
|
|
14435
|
-
if (current.type ===
|
|
14629
|
+
if (current.type === AST_NODE_TYPES57.CallExpression) {
|
|
14436
14630
|
current = current.callee;
|
|
14437
14631
|
continue;
|
|
14438
14632
|
}
|
|
14439
|
-
if (current.type ===
|
|
14633
|
+
if (current.type === AST_NODE_TYPES57.MemberExpression) {
|
|
14440
14634
|
current = current.object;
|
|
14441
14635
|
continue;
|
|
14442
14636
|
}
|
|
@@ -14445,12 +14639,12 @@ var zodReceiverRoot = (node) => {
|
|
|
14445
14639
|
};
|
|
14446
14640
|
var isFormDataMethodCall = (node) => {
|
|
14447
14641
|
let current = node;
|
|
14448
|
-
if (current.type ===
|
|
14642
|
+
if (current.type === AST_NODE_TYPES57.AwaitExpression) {
|
|
14449
14643
|
current = current.argument;
|
|
14450
14644
|
}
|
|
14451
|
-
if (current.type !==
|
|
14645
|
+
if (current.type !== AST_NODE_TYPES57.CallExpression) return false;
|
|
14452
14646
|
const callee = current.callee;
|
|
14453
|
-
return callee.type ===
|
|
14647
|
+
return callee.type === AST_NODE_TYPES57.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES57.Identifier && callee.property.name === "formData";
|
|
14454
14648
|
};
|
|
14455
14649
|
var require_zod_form_validation_default = createRule({
|
|
14456
14650
|
name: "require-zod-form-validation",
|
|
@@ -14471,7 +14665,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14471
14665
|
return {};
|
|
14472
14666
|
}
|
|
14473
14667
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
14474
|
-
const resolvedBinding = (identifier) =>
|
|
14668
|
+
const resolvedBinding = (identifier) => ASTUtils17.findVariable(
|
|
14475
14669
|
context.sourceCode.getScope(identifier),
|
|
14476
14670
|
identifier.name
|
|
14477
14671
|
);
|
|
@@ -14481,16 +14675,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
14481
14675
|
return false;
|
|
14482
14676
|
}
|
|
14483
14677
|
const definition = binding.defs[0];
|
|
14484
|
-
if (definition?.type !== "Variable" || definition.node.type !==
|
|
14678
|
+
if (definition?.type !== "Variable" || definition.node.type !== AST_NODE_TYPES57.VariableDeclarator) {
|
|
14485
14679
|
return false;
|
|
14486
14680
|
}
|
|
14487
14681
|
const init = definition.node.init;
|
|
14488
|
-
return init?.type ===
|
|
14682
|
+
return init?.type === AST_NODE_TYPES57.ObjectExpression || init?.type === AST_NODE_TYPES57.ArrayExpression || init?.type === AST_NODE_TYPES57.Literal || init?.type === AST_NODE_TYPES57.ArrowFunctionExpression || init?.type === AST_NODE_TYPES57.FunctionExpression;
|
|
14489
14683
|
};
|
|
14490
14684
|
const isZodParseCall = (node) => {
|
|
14491
|
-
if (node.type !==
|
|
14685
|
+
if (node.type !== AST_NODE_TYPES57.CallExpression) return false;
|
|
14492
14686
|
const callee = node.callee;
|
|
14493
|
-
if (callee.type !==
|
|
14687
|
+
if (callee.type !== AST_NODE_TYPES57.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES57.Identifier || !ZOD_PARSE_METHODS.has(callee.property.name)) {
|
|
14494
14688
|
return false;
|
|
14495
14689
|
}
|
|
14496
14690
|
const root = zodReceiverRoot(callee.object);
|
|
@@ -14499,14 +14693,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
14499
14693
|
return binding !== null && zodBindings.has(binding) || (root.name === "z" || ZOD_SCHEMA_NAME_RE.test(root.name)) && !isProvablyNonZodLocal(root);
|
|
14500
14694
|
};
|
|
14501
14695
|
const isFormSourceIdentifier = (node) => {
|
|
14502
|
-
if (node.type !==
|
|
14696
|
+
if (node.type !== AST_NODE_TYPES57.Identifier) return false;
|
|
14503
14697
|
const conventionalName = /formdata/i.test(node.name);
|
|
14504
14698
|
let scope = context.sourceCode.getScope(node);
|
|
14505
14699
|
while (scope !== null) {
|
|
14506
14700
|
const variable = scope.set.get(node.name);
|
|
14507
14701
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
14508
14702
|
const def = variable.defs[0];
|
|
14509
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
14703
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === AST_NODE_TYPES57.VariableDeclarator && def.node.init !== null) {
|
|
14510
14704
|
return isFormDataMethodCall(def.node.init);
|
|
14511
14705
|
}
|
|
14512
14706
|
return def?.type === "Parameter" && conventionalName;
|
|
@@ -14517,8 +14711,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
14517
14711
|
};
|
|
14518
14712
|
const isFormDataGetCall = (node) => {
|
|
14519
14713
|
const callee = node.callee;
|
|
14520
|
-
if (callee.type !==
|
|
14521
|
-
if (callee.property.type !==
|
|
14714
|
+
if (callee.type !== AST_NODE_TYPES57.MemberExpression) return false;
|
|
14715
|
+
if (callee.property.type !== AST_NODE_TYPES57.Identifier || !FORM_VALUE_METHODS.has(callee.property.name)) {
|
|
14522
14716
|
return false;
|
|
14523
14717
|
}
|
|
14524
14718
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -14534,16 +14728,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
14534
14728
|
const hasZodParseAncestor = (node) => zodParseAncestor(node) !== null;
|
|
14535
14729
|
const isInstanceofNarrowing = (node) => {
|
|
14536
14730
|
const parent = node.parent;
|
|
14537
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
14731
|
+
return parent !== null && parent !== void 0 && parent.type === AST_NODE_TYPES57.BinaryExpression && parent.operator === "instanceof" && parent.left === node && parent.right.type === AST_NODE_TYPES57.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
14538
14732
|
};
|
|
14539
14733
|
const boundDeclarator = (node) => {
|
|
14540
14734
|
let current = node;
|
|
14541
14735
|
let parent = current.parent;
|
|
14542
|
-
while ((parent.type ===
|
|
14736
|
+
while ((parent.type === AST_NODE_TYPES57.TSAsExpression || parent.type === AST_NODE_TYPES57.TSSatisfiesExpression || parent.type === AST_NODE_TYPES57.TSNonNullExpression || parent.type === AST_NODE_TYPES57.ChainExpression) && parent.expression === current) {
|
|
14543
14737
|
current = parent;
|
|
14544
14738
|
parent = current.parent;
|
|
14545
14739
|
}
|
|
14546
|
-
if (parent.type ===
|
|
14740
|
+
if (parent.type === AST_NODE_TYPES57.VariableDeclarator && parent.init === current && parent.id.type === AST_NODE_TYPES57.Identifier) {
|
|
14547
14741
|
return parent;
|
|
14548
14742
|
}
|
|
14549
14743
|
return null;
|
|
@@ -14552,7 +14746,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14552
14746
|
let current = node;
|
|
14553
14747
|
while (current.parent !== void 0) {
|
|
14554
14748
|
const parent = current.parent;
|
|
14555
|
-
if (parent.type ===
|
|
14749
|
+
if (parent.type === AST_NODE_TYPES57.BlockStatement || parent.type === AST_NODE_TYPES57.Program) {
|
|
14556
14750
|
return current;
|
|
14557
14751
|
}
|
|
14558
14752
|
current = parent;
|
|
@@ -14561,12 +14755,12 @@ var require_zod_form_validation_default = createRule({
|
|
|
14561
14755
|
};
|
|
14562
14756
|
const zodParseMethod = (call) => {
|
|
14563
14757
|
const callee = call.callee;
|
|
14564
|
-
return callee.type ===
|
|
14758
|
+
return callee.type === AST_NODE_TYPES57.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES57.Identifier ? callee.property.name : null;
|
|
14565
14759
|
};
|
|
14566
14760
|
const hasConditionalAncestorBeforeStatement = (node, statement) => {
|
|
14567
14761
|
let current = node.parent;
|
|
14568
14762
|
while (current !== void 0 && current !== statement) {
|
|
14569
|
-
if (current.type ===
|
|
14763
|
+
if (current.type === AST_NODE_TYPES57.LogicalExpression || current.type === AST_NODE_TYPES57.ConditionalExpression) {
|
|
14570
14764
|
return true;
|
|
14571
14765
|
}
|
|
14572
14766
|
current = current.parent;
|
|
@@ -14576,7 +14770,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14576
14770
|
const isAwaitedBeforeStatement = (node, statement) => {
|
|
14577
14771
|
let current = node.parent;
|
|
14578
14772
|
while (current !== void 0 && current !== statement) {
|
|
14579
|
-
if (current.type ===
|
|
14773
|
+
if (current.type === AST_NODE_TYPES57.AwaitExpression) return true;
|
|
14580
14774
|
current = current.parent;
|
|
14581
14775
|
}
|
|
14582
14776
|
return false;
|
|
@@ -14589,7 +14783,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14589
14783
|
if (declarationStatement === null || validationStatement === null || declarationStatement.parent !== validationStatement.parent || validationStatement.range[0] <= declarationStatement.range[1] || hasConditionalAncestorBeforeStatement(parse2, validationStatement)) {
|
|
14590
14784
|
return null;
|
|
14591
14785
|
}
|
|
14592
|
-
if (validationStatement.type !==
|
|
14786
|
+
if (validationStatement.type !== AST_NODE_TYPES57.VariableDeclaration && validationStatement.type !== AST_NODE_TYPES57.ExpressionStatement) {
|
|
14593
14787
|
return null;
|
|
14594
14788
|
}
|
|
14595
14789
|
const method = zodParseMethod(parse2);
|
|
@@ -14601,16 +14795,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
14601
14795
|
};
|
|
14602
14796
|
const isSafePrevalidationInspection = (identifier) => {
|
|
14603
14797
|
const parent = identifier.parent;
|
|
14604
|
-
if (parent.type ===
|
|
14798
|
+
if (parent.type === AST_NODE_TYPES57.UnaryExpression && parent.operator === "typeof") {
|
|
14605
14799
|
return true;
|
|
14606
14800
|
}
|
|
14607
|
-
if (parent.type !==
|
|
14801
|
+
if (parent.type !== AST_NODE_TYPES57.BinaryExpression || parent.left !== identifier) {
|
|
14608
14802
|
return false;
|
|
14609
14803
|
}
|
|
14610
14804
|
if (parent.operator === "instanceof") {
|
|
14611
|
-
return parent.right.type ===
|
|
14805
|
+
return parent.right.type === AST_NODE_TYPES57.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
14612
14806
|
}
|
|
14613
|
-
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type ===
|
|
14807
|
+
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type === AST_NODE_TYPES57.Literal && parent.right.value === null || parent.right.type === AST_NODE_TYPES57.Identifier && parent.right.name === "undefined");
|
|
14614
14808
|
};
|
|
14615
14809
|
const isDescendantOf = (node, ancestor) => {
|
|
14616
14810
|
let current = node;
|
|
@@ -14621,23 +14815,23 @@ var require_zod_form_validation_default = createRule({
|
|
|
14621
14815
|
return false;
|
|
14622
14816
|
};
|
|
14623
14817
|
const blockTerminates = (node) => {
|
|
14624
|
-
if (node.type ===
|
|
14818
|
+
if (node.type === AST_NODE_TYPES57.ReturnStatement || node.type === AST_NODE_TYPES57.ThrowStatement) {
|
|
14625
14819
|
return true;
|
|
14626
14820
|
}
|
|
14627
|
-
if (node.type !==
|
|
14821
|
+
if (node.type !== AST_NODE_TYPES57.BlockStatement || node.body.length === 0) return false;
|
|
14628
14822
|
const last = node.body.at(-1);
|
|
14629
14823
|
return last !== void 0 && blockTerminates(last);
|
|
14630
14824
|
};
|
|
14631
14825
|
const narrowingIf = (identifier) => {
|
|
14632
14826
|
const comparison = identifier.parent;
|
|
14633
|
-
if (comparison?.type !==
|
|
14827
|
+
if (comparison?.type !== AST_NODE_TYPES57.BinaryExpression || comparison.operator !== "instanceof" || comparison.left !== identifier || comparison.right.type !== AST_NODE_TYPES57.Identifier || comparison.right.name !== "File" && comparison.right.name !== "Blob") {
|
|
14634
14828
|
return null;
|
|
14635
14829
|
}
|
|
14636
14830
|
const maybeNegation = comparison.parent;
|
|
14637
|
-
const negated = maybeNegation?.type ===
|
|
14831
|
+
const negated = maybeNegation?.type === AST_NODE_TYPES57.UnaryExpression && maybeNegation.operator === "!";
|
|
14638
14832
|
const test = negated ? maybeNegation : comparison;
|
|
14639
14833
|
const branch = test.parent;
|
|
14640
|
-
return branch?.type ===
|
|
14834
|
+
return branch?.type === AST_NODE_TYPES57.IfStatement && branch.test === test ? { branch, positive: !negated } : null;
|
|
14641
14835
|
};
|
|
14642
14836
|
const useDominatedByNarrowing = (use, narrowings) => narrowings.some(({ branch, positive }) => {
|
|
14643
14837
|
if (positive) return isDescendantOf(use, branch.consequent);
|
|
@@ -14657,7 +14851,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14657
14851
|
const variable = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
14658
14852
|
if (variable === void 0) return false;
|
|
14659
14853
|
const references = variable.references.filter((reference) => !reference.isWriteOnly()).map((reference) => reference.identifier).filter(
|
|
14660
|
-
(identifier) => identifier.type ===
|
|
14854
|
+
(identifier) => identifier.type === AST_NODE_TYPES57.Identifier
|
|
14661
14855
|
);
|
|
14662
14856
|
if (references.length === 0) return false;
|
|
14663
14857
|
const narrowings = references.map(narrowingIf).filter(
|
|
@@ -14683,7 +14877,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
14683
14877
|
ImportDeclaration(node) {
|
|
14684
14878
|
if (!isZodModule(node.source.value)) return;
|
|
14685
14879
|
for (const specifier of node.specifiers) {
|
|
14686
|
-
if (specifier.type ===
|
|
14880
|
+
if (specifier.type === AST_NODE_TYPES57.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES57.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES57.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES57.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
14687
14881
|
const binding = resolvedBinding(specifier.local);
|
|
14688
14882
|
if (binding !== null) zodBindings.add(binding);
|
|
14689
14883
|
}
|
|
@@ -14768,7 +14962,7 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
14768
14962
|
});
|
|
14769
14963
|
|
|
14770
14964
|
// src/rules/stepdown.ts
|
|
14771
|
-
import { AST_NODE_TYPES as
|
|
14965
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES58, ASTUtils as ASTUtils18 } from "@typescript-eslint/utils";
|
|
14772
14966
|
var stepdownDocumentation = {
|
|
14773
14967
|
summary: "Place a private helper below its sole direct same-scope caller.",
|
|
14774
14968
|
rationale: "Caller-first ordering lets a reader follow the main flow before descending into implementation details.",
|
|
@@ -14785,7 +14979,7 @@ var stepdownDocumentation = {
|
|
|
14785
14979
|
]
|
|
14786
14980
|
};
|
|
14787
14981
|
function isFunction(node) {
|
|
14788
|
-
return node.type ===
|
|
14982
|
+
return node.type === AST_NODE_TYPES58.ArrowFunctionExpression || node.type === AST_NODE_TYPES58.FunctionDeclaration || node.type === AST_NODE_TYPES58.FunctionExpression;
|
|
14789
14983
|
}
|
|
14790
14984
|
function reportMisordered(context, candidates, scopeDefinitions, calls, pinned, canMove = () => true) {
|
|
14791
14985
|
const byName = new Map(scopeDefinitions.map((definition) => [definition.name, definition]));
|
|
@@ -14880,8 +15074,8 @@ function moduleScope(context, program) {
|
|
|
14880
15074
|
for (const node of declarations) counts.set(node.name, (counts.get(node.name) ?? 0) + 1);
|
|
14881
15075
|
const overloadNames = new Set(
|
|
14882
15076
|
program.body.flatMap((statement) => {
|
|
14883
|
-
const node = statement.type ===
|
|
14884
|
-
return node?.type ===
|
|
15077
|
+
const node = statement.type === AST_NODE_TYPES58.ExportNamedDeclaration ? statement.declaration : statement;
|
|
15078
|
+
return node?.type === AST_NODE_TYPES58.TSDeclareFunction && node.id !== null ? [node.id.name] : [];
|
|
14885
15079
|
})
|
|
14886
15080
|
);
|
|
14887
15081
|
const exported = exportedNames(program);
|
|
@@ -14905,7 +15099,7 @@ function moduleScope(context, program) {
|
|
|
14905
15099
|
const nearestFunction2 = [...ancestors].reverse().find(isFunction);
|
|
14906
15100
|
const parent = identifier.parent;
|
|
14907
15101
|
const callerDefinition = nearestFunction2 === void 0 ? void 0 : byFunction.get(nearestFunction2);
|
|
14908
|
-
if (callerDefinition === void 0 || parent.type !==
|
|
15102
|
+
if (callerDefinition === void 0 || parent.type !== AST_NODE_TYPES58.CallExpression || parent.callee !== identifier) {
|
|
14909
15103
|
pinned.add(definition.name);
|
|
14910
15104
|
continue;
|
|
14911
15105
|
}
|
|
@@ -14920,38 +15114,38 @@ function moduleScope(context, program) {
|
|
|
14920
15114
|
function exportedNames(program) {
|
|
14921
15115
|
const names = /* @__PURE__ */ new Set();
|
|
14922
15116
|
for (const statement of program.body) {
|
|
14923
|
-
if (statement.type !==
|
|
14924
|
-
if (statement.declaration?.type ===
|
|
15117
|
+
if (statement.type !== AST_NODE_TYPES58.ExportNamedDeclaration || statement.exportKind === "type" || statement.source !== null) continue;
|
|
15118
|
+
if (statement.declaration?.type === AST_NODE_TYPES58.FunctionDeclaration && statement.declaration.id !== null) {
|
|
14925
15119
|
names.add(statement.declaration.id.name);
|
|
14926
15120
|
}
|
|
14927
|
-
if (statement.declaration?.type ===
|
|
15121
|
+
if (statement.declaration?.type === AST_NODE_TYPES58.VariableDeclaration) {
|
|
14928
15122
|
for (const declarator of statement.declaration.declarations) {
|
|
14929
|
-
if (declarator.id.type ===
|
|
15123
|
+
if (declarator.id.type === AST_NODE_TYPES58.Identifier) names.add(declarator.id.name);
|
|
14930
15124
|
}
|
|
14931
15125
|
}
|
|
14932
15126
|
for (const specifier of statement.specifiers) {
|
|
14933
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
15127
|
+
if (specifier.exportKind !== "type" && specifier.local.type === AST_NODE_TYPES58.Identifier) {
|
|
14934
15128
|
names.add(specifier.local.name);
|
|
14935
15129
|
}
|
|
14936
15130
|
}
|
|
14937
15131
|
}
|
|
14938
15132
|
for (const statement of program.body) {
|
|
14939
|
-
if (statement.type ===
|
|
14940
|
-
if (statement.type ===
|
|
15133
|
+
if (statement.type === AST_NODE_TYPES58.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES58.Identifier) names.add(statement.declaration.name);
|
|
15134
|
+
if (statement.type === AST_NODE_TYPES58.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES58.FunctionDeclaration && statement.declaration.id !== null) names.add(statement.declaration.id.name);
|
|
14941
15135
|
}
|
|
14942
15136
|
return names;
|
|
14943
15137
|
}
|
|
14944
15138
|
function moduleDefinitions(program) {
|
|
14945
15139
|
const definitions = [];
|
|
14946
15140
|
for (const statement of program.body) {
|
|
14947
|
-
const node = statement.type ===
|
|
14948
|
-
if (node?.type ===
|
|
15141
|
+
const node = statement.type === AST_NODE_TYPES58.ExportNamedDeclaration || statement.type === AST_NODE_TYPES58.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
15142
|
+
if (node?.type === AST_NODE_TYPES58.FunctionDeclaration && node.id !== null && node.body !== null) {
|
|
14949
15143
|
definitions.push({ name: node.id.name, node, functionNode: node, bindingNode: node });
|
|
14950
15144
|
continue;
|
|
14951
15145
|
}
|
|
14952
|
-
if (node?.type !==
|
|
15146
|
+
if (node?.type !== AST_NODE_TYPES58.VariableDeclaration || node.kind !== "const") continue;
|
|
14953
15147
|
for (const declarator of node.declarations) {
|
|
14954
|
-
if (declarator.id.type ===
|
|
15148
|
+
if (declarator.id.type === AST_NODE_TYPES58.Identifier && declarator.init !== null && isFunction(declarator.init)) {
|
|
14955
15149
|
definitions.push({
|
|
14956
15150
|
name: declarator.id.name,
|
|
14957
15151
|
node: declarator,
|
|
@@ -14964,21 +15158,21 @@ function moduleDefinitions(program) {
|
|
|
14964
15158
|
return definitions;
|
|
14965
15159
|
}
|
|
14966
15160
|
function methodName(node) {
|
|
14967
|
-
if (node.key.type ===
|
|
14968
|
-
return !node.computed && node.key.type ===
|
|
15161
|
+
if (node.key.type === AST_NODE_TYPES58.PrivateIdentifier) return `#${node.key.name}`;
|
|
15162
|
+
return !node.computed && node.key.type === AST_NODE_TYPES58.Identifier ? node.key.name : null;
|
|
14969
15163
|
}
|
|
14970
15164
|
function referencedMethod(context, node, classVariables) {
|
|
14971
|
-
const objectVariable = node.object.type ===
|
|
15165
|
+
const objectVariable = node.object.type === AST_NODE_TYPES58.Identifier ? ASTUtils18.findVariable(context.sourceCode.getScope(node.object), node.object.name) : null;
|
|
14972
15166
|
const isClassReference = objectVariable !== null && classVariables.has(objectVariable);
|
|
14973
|
-
if (node.object.type !==
|
|
14974
|
-
if (node.property.type ===
|
|
14975
|
-
if (!node.computed && node.property.type ===
|
|
14976
|
-
return node.computed && node.property.type ===
|
|
15167
|
+
if (node.object.type !== AST_NODE_TYPES58.ThisExpression && !isClassReference) return null;
|
|
15168
|
+
if (node.property.type === AST_NODE_TYPES58.PrivateIdentifier) return `#${node.property.name}`;
|
|
15169
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES58.Identifier) return node.property.name;
|
|
15170
|
+
return node.computed && node.property.type === AST_NODE_TYPES58.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
14977
15171
|
}
|
|
14978
15172
|
function referencedPropertyName(node) {
|
|
14979
|
-
if (node.property.type ===
|
|
14980
|
-
if (!node.computed && node.property.type ===
|
|
14981
|
-
return node.computed && node.property.type ===
|
|
15173
|
+
if (node.property.type === AST_NODE_TYPES58.PrivateIdentifier) return `#${node.property.name}`;
|
|
15174
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES58.Identifier) return node.property.name;
|
|
15175
|
+
return node.computed && node.property.type === AST_NODE_TYPES58.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
14982
15176
|
}
|
|
14983
15177
|
function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
14984
15178
|
visit(node, nestedFunction);
|
|
@@ -14994,7 +15188,7 @@ function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
|
14994
15188
|
}
|
|
14995
15189
|
function classScope(context, node, computedReferenceNames) {
|
|
14996
15190
|
const methods = node.body.body.filter(
|
|
14997
|
-
(member) => member.type ===
|
|
15191
|
+
(member) => member.type === AST_NODE_TYPES58.MethodDefinition
|
|
14998
15192
|
);
|
|
14999
15193
|
const counts = /* @__PURE__ */ new Map();
|
|
15000
15194
|
for (const method of methods) {
|
|
@@ -15002,8 +15196,8 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15002
15196
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
15003
15197
|
}
|
|
15004
15198
|
for (const member of node.body.body) {
|
|
15005
|
-
if (member.type !==
|
|
15006
|
-
const name = !member.computed && member.key.type ===
|
|
15199
|
+
if (member.type !== AST_NODE_TYPES58.TSAbstractMethodDefinition) continue;
|
|
15200
|
+
const name = !member.computed && member.key.type === AST_NODE_TYPES58.Identifier ? member.key.name : null;
|
|
15007
15201
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
15008
15202
|
}
|
|
15009
15203
|
const scopeDefinitions = methods.flatMap((method) => {
|
|
@@ -15012,7 +15206,7 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15012
15206
|
});
|
|
15013
15207
|
const definitions = methods.flatMap((method) => {
|
|
15014
15208
|
const name = methodName(method);
|
|
15015
|
-
const isPrivate = method.accessibility === "private" || method.key.type ===
|
|
15209
|
+
const isPrivate = method.accessibility === "private" || method.key.type === AST_NODE_TYPES58.PrivateIdentifier;
|
|
15016
15210
|
return name !== null && isPrivate && counts.get(name) === 1 && method.decorators.length === 0 ? [{ name, node: method }] : [];
|
|
15017
15211
|
});
|
|
15018
15212
|
if (definitions.length === 0) return;
|
|
@@ -15021,11 +15215,11 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15021
15215
|
const pinned = /* @__PURE__ */ new Set();
|
|
15022
15216
|
const classVariables = /* @__PURE__ */ new Set();
|
|
15023
15217
|
if (node.id !== null) {
|
|
15024
|
-
const internal =
|
|
15218
|
+
const internal = ASTUtils18.findVariable(context.sourceCode.getScope(node), node.id.name);
|
|
15025
15219
|
if (internal !== null) classVariables.add(internal);
|
|
15026
15220
|
}
|
|
15027
|
-
if (node.type ===
|
|
15028
|
-
const outer =
|
|
15221
|
+
if (node.type === AST_NODE_TYPES58.ClassExpression && node.parent.type === AST_NODE_TYPES58.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES58.Identifier) {
|
|
15222
|
+
const outer = ASTUtils18.findVariable(context.sourceCode.getScope(node.parent), node.parent.id.name);
|
|
15029
15223
|
if (outer !== null) classVariables.add(outer);
|
|
15030
15224
|
}
|
|
15031
15225
|
for (const method of methods) {
|
|
@@ -15041,27 +15235,27 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15041
15235
|
}
|
|
15042
15236
|
const thisValue = (value) => {
|
|
15043
15237
|
let current = value;
|
|
15044
|
-
while (current?.type ===
|
|
15045
|
-
return current?.type ===
|
|
15238
|
+
while (current?.type === AST_NODE_TYPES58.TSAsExpression || current?.type === AST_NODE_TYPES58.TSSatisfiesExpression || current?.type === AST_NODE_TYPES58.TSNonNullExpression) current = current.expression;
|
|
15239
|
+
return current?.type === AST_NODE_TYPES58.ThisExpression;
|
|
15046
15240
|
};
|
|
15047
15241
|
const collectAlias = (current, nestedFunction) => {
|
|
15048
|
-
if (nestedFunction || current.type !==
|
|
15049
|
-
if (current.type ===
|
|
15050
|
-
const binding = current.type ===
|
|
15051
|
-
const value = current.type ===
|
|
15242
|
+
if (nestedFunction || current.type !== AST_NODE_TYPES58.VariableDeclarator && current.type !== AST_NODE_TYPES58.AssignmentPattern) return;
|
|
15243
|
+
if (current.type === AST_NODE_TYPES58.VariableDeclarator && (current.parent.type !== AST_NODE_TYPES58.VariableDeclaration || current.parent.kind !== "const")) return;
|
|
15244
|
+
const binding = current.type === AST_NODE_TYPES58.VariableDeclarator ? current.id : current.left;
|
|
15245
|
+
const value = current.type === AST_NODE_TYPES58.VariableDeclarator ? current.init : current.right;
|
|
15052
15246
|
if (!thisValue(value)) return;
|
|
15053
|
-
if (binding.type ===
|
|
15247
|
+
if (binding.type === AST_NODE_TYPES58.ObjectPattern) {
|
|
15054
15248
|
for (const property of binding.properties) {
|
|
15055
|
-
if (property.type ===
|
|
15249
|
+
if (property.type === AST_NODE_TYPES58.RestElement) {
|
|
15056
15250
|
for (const name of privateNames) pinned.add(name);
|
|
15057
|
-
} else if (property.key.type ===
|
|
15251
|
+
} else if (property.key.type === AST_NODE_TYPES58.Identifier && privateNames.has(property.key.name)) {
|
|
15058
15252
|
pinned.add(property.key.name);
|
|
15059
15253
|
}
|
|
15060
15254
|
}
|
|
15061
15255
|
return;
|
|
15062
15256
|
}
|
|
15063
|
-
if (binding.type !==
|
|
15064
|
-
const variable =
|
|
15257
|
+
if (binding.type !== AST_NODE_TYPES58.Identifier) return;
|
|
15258
|
+
const variable = ASTUtils18.findVariable(context.sourceCode.getScope(binding), binding.name);
|
|
15065
15259
|
if (variable !== null) {
|
|
15066
15260
|
methodClassVariables.add(variable);
|
|
15067
15261
|
methodAliases.add(variable);
|
|
@@ -15074,16 +15268,16 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15074
15268
|
walk(statement, context.sourceCode.visitorKeys, collectAlias);
|
|
15075
15269
|
}
|
|
15076
15270
|
const visitCall = (current, nestedFunction) => {
|
|
15077
|
-
if (current.type ===
|
|
15271
|
+
if (current.type === AST_NODE_TYPES58.VariableDeclarator && current.id.type === AST_NODE_TYPES58.ObjectPattern && thisValue(current.init)) {
|
|
15078
15272
|
for (const property of current.id.properties) {
|
|
15079
|
-
if (property.type ===
|
|
15273
|
+
if (property.type === AST_NODE_TYPES58.RestElement) {
|
|
15080
15274
|
for (const name of privateNames) pinned.add(name);
|
|
15081
15275
|
continue;
|
|
15082
15276
|
}
|
|
15083
|
-
if (property.type ===
|
|
15277
|
+
if (property.type === AST_NODE_TYPES58.Property && property.key.type === AST_NODE_TYPES58.Identifier && privateNames.has(property.key.name)) pinned.add(property.key.name);
|
|
15084
15278
|
}
|
|
15085
15279
|
}
|
|
15086
|
-
if (current.type !==
|
|
15280
|
+
if (current.type !== AST_NODE_TYPES58.MemberExpression) return;
|
|
15087
15281
|
const target = referencedMethod(context, current, methodClassVariables);
|
|
15088
15282
|
if (target === null) {
|
|
15089
15283
|
const possibleTarget = referencedPropertyName(current);
|
|
@@ -15091,12 +15285,12 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15091
15285
|
return;
|
|
15092
15286
|
}
|
|
15093
15287
|
if (!privateNames.has(target)) return;
|
|
15094
|
-
const objectVariable = current.object.type ===
|
|
15288
|
+
const objectVariable = current.object.type === AST_NODE_TYPES58.Identifier ? ASTUtils18.findVariable(context.sourceCode.getScope(current.object), current.object.name) : null;
|
|
15095
15289
|
if (objectVariable !== null && methodAliases.has(objectVariable)) {
|
|
15096
15290
|
pinned.add(target);
|
|
15097
15291
|
return;
|
|
15098
15292
|
}
|
|
15099
|
-
if (current.computed || nestedFunction || parameterDecoratorNodes.has(current) || current.parent.type !==
|
|
15293
|
+
if (current.computed || nestedFunction || parameterDecoratorNodes.has(current) || current.parent.type !== AST_NODE_TYPES58.CallExpression || current.parent.callee !== current) {
|
|
15100
15294
|
pinned.add(target);
|
|
15101
15295
|
return;
|
|
15102
15296
|
}
|
|
@@ -15116,9 +15310,9 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15116
15310
|
}
|
|
15117
15311
|
}
|
|
15118
15312
|
for (const member of node.body.body) {
|
|
15119
|
-
if (member.type ===
|
|
15313
|
+
if (member.type === AST_NODE_TYPES58.MethodDefinition || member.type === AST_NODE_TYPES58.TSAbstractMethodDefinition) continue;
|
|
15120
15314
|
walk(member, context.sourceCode.visitorKeys, (current) => {
|
|
15121
|
-
if (current.type !==
|
|
15315
|
+
if (current.type !== AST_NODE_TYPES58.MemberExpression) return;
|
|
15122
15316
|
const target = referencedMethod(context, current, classVariables);
|
|
15123
15317
|
const possibleTarget = target ?? referencedPropertyName(current);
|
|
15124
15318
|
if (possibleTarget !== null && privateNames.has(possibleTarget)) pinned.add(possibleTarget);
|
|
@@ -15128,14 +15322,14 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15128
15322
|
const accessibility = new Map(
|
|
15129
15323
|
scopeDefinitions.map((definition) => {
|
|
15130
15324
|
const method = definition.node;
|
|
15131
|
-
const accessibility2 = method.key.type ===
|
|
15325
|
+
const accessibility2 = method.key.type === AST_NODE_TYPES58.PrivateIdentifier ? "private" : method.accessibility ?? "public";
|
|
15132
15326
|
return [definition.name, accessibility2];
|
|
15133
15327
|
})
|
|
15134
15328
|
);
|
|
15135
15329
|
const methodByName = new Map(scopeDefinitions.map((definition) => [definition.name, definition.node]));
|
|
15136
15330
|
for (const [caller, callees] of calls) {
|
|
15137
15331
|
const callerMethod = methodByName.get(caller);
|
|
15138
|
-
if (accessibility.get(caller) === "private" && callerMethod?.type ===
|
|
15332
|
+
if (accessibility.get(caller) === "private" && callerMethod?.type === AST_NODE_TYPES58.MethodDefinition && callerMethod.decorators.length === 0) continue;
|
|
15139
15333
|
for (const callee of callees) pinned.add(callee);
|
|
15140
15334
|
}
|
|
15141
15335
|
const memberIndexes = new Map(node.body.body.map((member, index) => [member, index]));
|
|
@@ -15152,12 +15346,12 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
15152
15346
|
}
|
|
15153
15347
|
function isClassRuntimeBarrier(member) {
|
|
15154
15348
|
switch (member.type) {
|
|
15155
|
-
case
|
|
15349
|
+
case AST_NODE_TYPES58.StaticBlock:
|
|
15156
15350
|
return true;
|
|
15157
|
-
case
|
|
15158
|
-
case
|
|
15351
|
+
case AST_NODE_TYPES58.PropertyDefinition:
|
|
15352
|
+
case AST_NODE_TYPES58.AccessorProperty:
|
|
15159
15353
|
return member.static || member.computed || member.decorators.length > 0 || member.value !== null;
|
|
15160
|
-
case
|
|
15354
|
+
case AST_NODE_TYPES58.MethodDefinition:
|
|
15161
15355
|
return member.computed || member.decorators.length > 0;
|
|
15162
15356
|
default:
|
|
15163
15357
|
return false;
|
|
@@ -15189,7 +15383,7 @@ var stepdown_default = createRule({
|
|
|
15189
15383
|
moduleScope(context, program);
|
|
15190
15384
|
const computedReferenceNames = /* @__PURE__ */ new Set();
|
|
15191
15385
|
walk(program, context.sourceCode.visitorKeys, (node) => {
|
|
15192
|
-
if (node.type ===
|
|
15386
|
+
if (node.type === AST_NODE_TYPES58.MemberExpression && node.computed && node.property.type === AST_NODE_TYPES58.Literal && typeof node.property.value === "string") computedReferenceNames.add(node.property.value);
|
|
15193
15387
|
});
|
|
15194
15388
|
for (const node of classes) classScope(context, node, computedReferenceNames);
|
|
15195
15389
|
}
|
|
@@ -15198,8 +15392,8 @@ var stepdown_default = createRule({
|
|
|
15198
15392
|
});
|
|
15199
15393
|
|
|
15200
15394
|
// src/rules/source-coupled-test.ts
|
|
15201
|
-
import { AST_NODE_TYPES as
|
|
15202
|
-
var GENERAL_SOURCE_SUFFIX_RE = /\.(?:bash|sh|ya?ml|py|[cm]?[jt]s)$/iu;
|
|
15395
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES59 } from "@typescript-eslint/utils";
|
|
15396
|
+
var GENERAL_SOURCE_SUFFIX_RE = /\.(?:bash|sh|ya?ml|jsonc|py|[cm]?[jt]s)$/iu;
|
|
15203
15397
|
var FS_MODULES = /* @__PURE__ */ new Set(["fs", "node:fs", "fs/promises", "node:fs/promises"]);
|
|
15204
15398
|
var FS_READERS = /* @__PURE__ */ new Set(["readFile", "readFileSync"]);
|
|
15205
15399
|
var TEXT_TRANSFORMS = /* @__PURE__ */ new Set([
|
|
@@ -15267,20 +15461,20 @@ var sourceCoupledTestDocumentation = {
|
|
|
15267
15461
|
]
|
|
15268
15462
|
};
|
|
15269
15463
|
function staticMemberName7(node) {
|
|
15270
|
-
if (!node.computed && node.property.type ===
|
|
15271
|
-
if (node.computed && node.property.type ===
|
|
15464
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES59.Identifier) return node.property.name;
|
|
15465
|
+
if (node.computed && node.property.type === AST_NODE_TYPES59.Literal && typeof node.property.value === "string") return node.property.value;
|
|
15272
15466
|
return null;
|
|
15273
15467
|
}
|
|
15274
15468
|
function unwrap5(node) {
|
|
15275
|
-
if (node.type ===
|
|
15276
|
-
if (node.type ===
|
|
15277
|
-
if (node.type ===
|
|
15469
|
+
if (node.type === AST_NODE_TYPES59.AwaitExpression) return unwrap5(node.argument);
|
|
15470
|
+
if (node.type === AST_NODE_TYPES59.ChainExpression) return unwrap5(node.expression);
|
|
15471
|
+
if (node.type === AST_NODE_TYPES59.TSAsExpression || node.type === AST_NODE_TYPES59.TSNonNullExpression || node.type === AST_NODE_TYPES59.TSTypeAssertion) return unwrap5(node.expression);
|
|
15278
15472
|
return node;
|
|
15279
15473
|
}
|
|
15280
15474
|
function stringValue(node) {
|
|
15281
15475
|
const current = unwrap5(node);
|
|
15282
|
-
if (current.type ===
|
|
15283
|
-
if (current.type ===
|
|
15476
|
+
if (current.type === AST_NODE_TYPES59.Literal && typeof current.value === "string") return current.value;
|
|
15477
|
+
if (current.type === AST_NODE_TYPES59.TemplateLiteral && current.expressions.length === 0) return current.quasis[0]?.value.cooked ?? null;
|
|
15284
15478
|
return null;
|
|
15285
15479
|
}
|
|
15286
15480
|
function importSource(node) {
|
|
@@ -15288,7 +15482,7 @@ function importSource(node) {
|
|
|
15288
15482
|
}
|
|
15289
15483
|
function requireSource(node) {
|
|
15290
15484
|
const current = unwrap5(node);
|
|
15291
|
-
if (current.type !==
|
|
15485
|
+
if (current.type !== AST_NODE_TYPES59.CallExpression || current.callee.type !== AST_NODE_TYPES59.Identifier || current.callee.name !== "require" || current.arguments.length !== 1 || current.arguments[0]?.type === AST_NODE_TYPES59.SpreadElement) return null;
|
|
15292
15486
|
return stringValue(current.arguments[0]);
|
|
15293
15487
|
}
|
|
15294
15488
|
function newScope() {
|
|
@@ -15328,38 +15522,38 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
15328
15522
|
const current = unwrap5(node);
|
|
15329
15523
|
const value = stringValue(current);
|
|
15330
15524
|
if (value !== null) return sourceSuffixRe.test(value);
|
|
15331
|
-
if (current.type ===
|
|
15332
|
-
if (current.type ===
|
|
15525
|
+
if (current.type === AST_NODE_TYPES59.Identifier) return visible("paths", current.name);
|
|
15526
|
+
if (current.type === AST_NODE_TYPES59.BinaryExpression && current.operator === "+") {
|
|
15333
15527
|
return sourcePath(current.left) || sourcePath(current.right);
|
|
15334
15528
|
}
|
|
15335
|
-
if (current.type ===
|
|
15336
|
-
if (current.type ===
|
|
15337
|
-
return current.arguments.some((argument) => argument.type !==
|
|
15529
|
+
if (current.type === AST_NODE_TYPES59.TemplateLiteral) return current.expressions.some(sourcePath);
|
|
15530
|
+
if (current.type === AST_NODE_TYPES59.CallExpression || current.type === AST_NODE_TYPES59.NewExpression) {
|
|
15531
|
+
return current.arguments.some((argument) => argument.type !== AST_NODE_TYPES59.SpreadElement && sourcePath(argument));
|
|
15338
15532
|
}
|
|
15339
|
-
if (current.type ===
|
|
15533
|
+
if (current.type === AST_NODE_TYPES59.MemberExpression) return sourcePath(current.object);
|
|
15340
15534
|
return false;
|
|
15341
15535
|
};
|
|
15342
15536
|
const rawRead = (node) => {
|
|
15343
15537
|
const current = unwrap5(node);
|
|
15344
|
-
if (current.type !==
|
|
15538
|
+
if (current.type !== AST_NODE_TYPES59.CallExpression || current.arguments.length === 0) return false;
|
|
15345
15539
|
const callee = unwrap5(current.callee);
|
|
15346
|
-
if (callee.type ===
|
|
15540
|
+
if (callee.type === AST_NODE_TYPES59.Identifier) {
|
|
15347
15541
|
return visible("fsReaders", callee.name) && sourcePath(current.arguments[0]);
|
|
15348
15542
|
}
|
|
15349
|
-
if (callee.type !==
|
|
15543
|
+
if (callee.type !== AST_NODE_TYPES59.MemberExpression) return false;
|
|
15350
15544
|
const name2 = staticMemberName7(callee);
|
|
15351
15545
|
const object = unwrap5(callee.object);
|
|
15352
|
-
return name2 !== null && FS_READERS.has(name2) && object.type ===
|
|
15546
|
+
return name2 !== null && FS_READERS.has(name2) && object.type === AST_NODE_TYPES59.Identifier && visible("fsObjects", object.name) && sourcePath(current.arguments[0]);
|
|
15353
15547
|
};
|
|
15354
15548
|
const rawOrigins = (node) => {
|
|
15355
15549
|
const current = unwrap5(node);
|
|
15356
|
-
if (current.type ===
|
|
15550
|
+
if (current.type === AST_NODE_TYPES59.Identifier) return visibleRawOrigins(current.name);
|
|
15357
15551
|
if (rawRead(current)) return /* @__PURE__ */ new Set([`${current.range[0]}:${current.range[1]}`]);
|
|
15358
|
-
if (current.type ===
|
|
15359
|
-
if (current.type ===
|
|
15360
|
-
if (current.type !==
|
|
15552
|
+
if (current.type === AST_NODE_TYPES59.BinaryExpression && current.operator === "+") return /* @__PURE__ */ new Set([...rawOrigins(current.left), ...rawOrigins(current.right)]);
|
|
15553
|
+
if (current.type === AST_NODE_TYPES59.MemberExpression && staticMemberName7(current) === "length") return rawOrigins(current.object);
|
|
15554
|
+
if (current.type !== AST_NODE_TYPES59.CallExpression) return /* @__PURE__ */ new Set();
|
|
15361
15555
|
const callee = unwrap5(current.callee);
|
|
15362
|
-
if (callee.type !==
|
|
15556
|
+
if (callee.type !== AST_NODE_TYPES59.MemberExpression) return /* @__PURE__ */ new Set();
|
|
15363
15557
|
const name2 = staticMemberName7(callee);
|
|
15364
15558
|
return name2 !== null && TEXT_TRANSFORMS.has(name2) ? rawOrigins(callee.object) : /* @__PURE__ */ new Set();
|
|
15365
15559
|
};
|
|
@@ -15367,32 +15561,39 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
15367
15561
|
const current = unwrap5(node);
|
|
15368
15562
|
const direct = rawOrigins(current);
|
|
15369
15563
|
if (direct.size > 0) return direct;
|
|
15370
|
-
if (current.type ===
|
|
15371
|
-
if (current.type ===
|
|
15372
|
-
if (current.type !==
|
|
15564
|
+
if (current.type === AST_NODE_TYPES59.BinaryExpression || current.type === AST_NODE_TYPES59.LogicalExpression) return /* @__PURE__ */ new Set([...evidenceOrigins(current.left), ...evidenceOrigins(current.right)]);
|
|
15565
|
+
if (current.type === AST_NODE_TYPES59.UnaryExpression) return evidenceOrigins(current.argument);
|
|
15566
|
+
if (current.type !== AST_NODE_TYPES59.CallExpression) return /* @__PURE__ */ new Set();
|
|
15373
15567
|
const callee = unwrap5(current.callee);
|
|
15374
|
-
if (callee.type !==
|
|
15568
|
+
if (callee.type !== AST_NODE_TYPES59.MemberExpression) return /* @__PURE__ */ new Set();
|
|
15375
15569
|
const name2 = staticMemberName7(callee);
|
|
15376
15570
|
if (name2 !== null && TEXT_PREDICATES.has(name2)) return rawOrigins(callee.object);
|
|
15377
|
-
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type ===
|
|
15571
|
+
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES59.SpreadElement ? [] : [...rawOrigins(argument)]));
|
|
15378
15572
|
return /* @__PURE__ */ new Set();
|
|
15379
15573
|
};
|
|
15380
15574
|
const rawAssertionOrigins = (node) => {
|
|
15381
15575
|
const callee = unwrap5(node.callee);
|
|
15382
|
-
if (callee.type ===
|
|
15383
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
15576
|
+
if (callee.type === AST_NODE_TYPES59.Identifier && callee.name === "assert") {
|
|
15577
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES59.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
15384
15578
|
}
|
|
15385
|
-
if (callee.type !==
|
|
15579
|
+
if (callee.type !== AST_NODE_TYPES59.MemberExpression) return /* @__PURE__ */ new Set();
|
|
15386
15580
|
const matcher = staticMemberName7(callee);
|
|
15387
15581
|
if (matcher === null) return /* @__PURE__ */ new Set();
|
|
15388
15582
|
let receiver = unwrap5(callee.object);
|
|
15389
|
-
while (receiver.type ===
|
|
15390
|
-
if (receiver.type ===
|
|
15583
|
+
while (receiver.type === AST_NODE_TYPES59.MemberExpression && EXPECT_MODIFIERS2.has(staticMemberName7(receiver) ?? "")) receiver = unwrap5(receiver.object);
|
|
15584
|
+
if (receiver.type === AST_NODE_TYPES59.CallExpression && receiver.callee.type === AST_NODE_TYPES59.Identifier && receiver.callee.name === "expect") {
|
|
15391
15585
|
if (!EXPECT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
15392
|
-
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type ===
|
|
15586
|
+
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type === AST_NODE_TYPES59.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
15393
15587
|
}
|
|
15394
|
-
if (receiver.type !==
|
|
15395
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
15588
|
+
if (receiver.type !== AST_NODE_TYPES59.Identifier || receiver.name !== "assert" || !ASSERT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
15589
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES59.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
15590
|
+
};
|
|
15591
|
+
const rawRegexExtractionOrigins = (node) => {
|
|
15592
|
+
const callee = unwrap5(node.callee);
|
|
15593
|
+
if (callee.type !== AST_NODE_TYPES59.MemberExpression || staticMemberName7(callee) !== "matchAll" || node.arguments.length !== 1) return /* @__PURE__ */ new Set();
|
|
15594
|
+
const argument = node.arguments[0];
|
|
15595
|
+
if (argument?.type !== AST_NODE_TYPES59.Literal || !(argument.value instanceof RegExp)) return /* @__PURE__ */ new Set();
|
|
15596
|
+
return rawOrigins(callee.object);
|
|
15396
15597
|
};
|
|
15397
15598
|
const declare = (name2, state) => {
|
|
15398
15599
|
const scope = currentScope();
|
|
@@ -15412,15 +15613,15 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
15412
15613
|
};
|
|
15413
15614
|
const sourceCollection = (node) => {
|
|
15414
15615
|
const current = unwrap5(node);
|
|
15415
|
-
return current.type ===
|
|
15616
|
+
return current.type === AST_NODE_TYPES59.ArrayExpression && current.elements.length > 0 && current.elements.every((element) => element !== null && element.type !== AST_NODE_TYPES59.SpreadElement && sourcePath(element));
|
|
15416
15617
|
};
|
|
15417
15618
|
const declaredNames2 = (node) => {
|
|
15418
15619
|
const current = unwrap5(node);
|
|
15419
|
-
if (current.type ===
|
|
15420
|
-
if (current.type ===
|
|
15421
|
-
if (current.type ===
|
|
15422
|
-
if (current.type ===
|
|
15423
|
-
if (current.type ===
|
|
15620
|
+
if (current.type === AST_NODE_TYPES59.Identifier) return [current.name];
|
|
15621
|
+
if (current.type === AST_NODE_TYPES59.AssignmentPattern) return declaredNames2(current.left);
|
|
15622
|
+
if (current.type === AST_NODE_TYPES59.RestElement) return declaredNames2(current.argument);
|
|
15623
|
+
if (current.type === AST_NODE_TYPES59.ArrayPattern) return current.elements.flatMap((element) => element === null ? [] : declaredNames2(element));
|
|
15624
|
+
if (current.type === AST_NODE_TYPES59.ObjectPattern) return current.properties.flatMap((property) => property.type === AST_NODE_TYPES59.RestElement ? declaredNames2(property.argument) : declaredNames2(property.value));
|
|
15424
15625
|
return [];
|
|
15425
15626
|
};
|
|
15426
15627
|
const enterFunction = (node) => {
|
|
@@ -15435,8 +15636,8 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
15435
15636
|
const source = importSource(node);
|
|
15436
15637
|
if (source === null || !FS_MODULES.has(source)) return;
|
|
15437
15638
|
for (const specifier of node.specifiers) {
|
|
15438
|
-
if (specifier.type ===
|
|
15439
|
-
const imported = specifier.imported.type ===
|
|
15639
|
+
if (specifier.type === AST_NODE_TYPES59.ImportSpecifier) {
|
|
15640
|
+
const imported = specifier.imported.type === AST_NODE_TYPES59.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
15440
15641
|
if (FS_READERS.has(imported)) declare(specifier.local.name, { fsReader: true });
|
|
15441
15642
|
} else {
|
|
15442
15643
|
declare(specifier.local.name, { fsObject: true });
|
|
@@ -15448,32 +15649,35 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
15448
15649
|
VariableDeclarator(node) {
|
|
15449
15650
|
if (node.init === null) return;
|
|
15450
15651
|
const required = requireSource(node.init);
|
|
15451
|
-
if (required !== null && FS_MODULES.has(required) && node.id.type ===
|
|
15652
|
+
if (required !== null && FS_MODULES.has(required) && node.id.type === AST_NODE_TYPES59.Identifier) {
|
|
15452
15653
|
declare(node.id.name, { fsObject: true });
|
|
15453
15654
|
return;
|
|
15454
15655
|
}
|
|
15455
|
-
if (node.id.type ===
|
|
15656
|
+
if (node.id.type === AST_NODE_TYPES59.ObjectPattern && required !== null && FS_MODULES.has(required)) {
|
|
15456
15657
|
for (const property of node.id.properties) {
|
|
15457
|
-
if (property.type !==
|
|
15458
|
-
const key = property.key.type ===
|
|
15658
|
+
if (property.type !== AST_NODE_TYPES59.Property || property.value.type !== AST_NODE_TYPES59.Identifier) continue;
|
|
15659
|
+
const key = property.key.type === AST_NODE_TYPES59.Identifier ? property.key.name : property.key.type === AST_NODE_TYPES59.Literal ? String(property.key.value) : "";
|
|
15459
15660
|
if (FS_READERS.has(key)) declare(property.value.name, { fsReader: true });
|
|
15460
15661
|
}
|
|
15461
15662
|
return;
|
|
15462
15663
|
}
|
|
15463
|
-
if (node.id.type !==
|
|
15664
|
+
if (node.id.type !== AST_NODE_TYPES59.Identifier) return;
|
|
15464
15665
|
declare(node.id.name, { collection: sourceCollection(node.init), path: sourcePath(node.init), rawOrigins: rawOrigins(node.init) });
|
|
15465
15666
|
},
|
|
15466
15667
|
AssignmentExpression(node) {
|
|
15467
|
-
if (node.left.type ===
|
|
15668
|
+
if (node.left.type === AST_NODE_TYPES59.Identifier) declare(node.left.name, { path: sourcePath(node.right), rawOrigins: rawOrigins(node.right) });
|
|
15468
15669
|
},
|
|
15469
15670
|
ForOfStatement(node) {
|
|
15470
15671
|
const right = unwrap5(node.right);
|
|
15471
|
-
const collection = right.type ===
|
|
15472
|
-
const left = node.left.type ===
|
|
15473
|
-
if (collection && left?.type ===
|
|
15672
|
+
const collection = right.type === AST_NODE_TYPES59.Identifier && visible("collections", right.name);
|
|
15673
|
+
const left = node.left.type === AST_NODE_TYPES59.VariableDeclaration ? node.left.declarations[0]?.id : node.left;
|
|
15674
|
+
if (collection && left?.type === AST_NODE_TYPES59.Identifier) declare(left.name, { path: true });
|
|
15474
15675
|
},
|
|
15475
15676
|
CallExpression(node) {
|
|
15476
|
-
const origins =
|
|
15677
|
+
const origins = /* @__PURE__ */ new Set([
|
|
15678
|
+
...rawAssertionOrigins(node),
|
|
15679
|
+
...rawRegexExtractionOrigins(node)
|
|
15680
|
+
]);
|
|
15477
15681
|
if (origins.size === 0 || [...origins].every((origin) => reportedOrigins.has(origin))) return;
|
|
15478
15682
|
for (const origin of origins) reportedOrigins.add(origin);
|
|
15479
15683
|
context.report({ node, messageId: "rawSourceOracle" });
|
|
@@ -15528,8 +15732,8 @@ var iac_source_coupled_test_default = createSourceCoupledRule(
|
|
|
15528
15732
|
|
|
15529
15733
|
// src/rules/zod-naming-convention.ts
|
|
15530
15734
|
import {
|
|
15531
|
-
AST_NODE_TYPES as
|
|
15532
|
-
ASTUtils as
|
|
15735
|
+
AST_NODE_TYPES as AST_NODE_TYPES60,
|
|
15736
|
+
ASTUtils as ASTUtils19
|
|
15533
15737
|
} from "@typescript-eslint/utils";
|
|
15534
15738
|
var zodNamingConventionDocumentation = {
|
|
15535
15739
|
summary: "Enforce a consistent Zod schema naming convention \u2014 a `Z` prefix (`ZUser`) or a `Schema` suffix (`userSchema`); both are accepted by default.",
|
|
@@ -15571,18 +15775,18 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
15571
15775
|
"prettifyError",
|
|
15572
15776
|
"treeifyError"
|
|
15573
15777
|
]);
|
|
15574
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
15778
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === AST_NODE_TYPES60.Identifier ? callee.property.name : null;
|
|
15575
15779
|
var calleeChainRoot = (node) => {
|
|
15576
15780
|
let current = node;
|
|
15577
15781
|
for (; ; ) {
|
|
15578
|
-
if (current.type ===
|
|
15782
|
+
if (current.type === AST_NODE_TYPES60.Identifier) {
|
|
15579
15783
|
return current;
|
|
15580
15784
|
}
|
|
15581
|
-
if (current.type ===
|
|
15785
|
+
if (current.type === AST_NODE_TYPES60.MemberExpression) {
|
|
15582
15786
|
current = current.object;
|
|
15583
15787
|
continue;
|
|
15584
15788
|
}
|
|
15585
|
-
if (current.type ===
|
|
15789
|
+
if (current.type === AST_NODE_TYPES60.CallExpression) {
|
|
15586
15790
|
current = current.callee;
|
|
15587
15791
|
continue;
|
|
15588
15792
|
}
|
|
@@ -15622,7 +15826,7 @@ var zod_naming_convention_default = createRule({
|
|
|
15622
15826
|
const acceptsSchemaWord = convention !== "prefix";
|
|
15623
15827
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
15624
15828
|
function resolvedBinding(identifier) {
|
|
15625
|
-
return
|
|
15829
|
+
return ASTUtils19.findVariable(
|
|
15626
15830
|
context.sourceCode.getScope(identifier),
|
|
15627
15831
|
identifier.name
|
|
15628
15832
|
);
|
|
@@ -15644,7 +15848,7 @@ var zod_naming_convention_default = createRule({
|
|
|
15644
15848
|
ImportDeclaration(node) {
|
|
15645
15849
|
if (!isZodModule(node.source.value)) return;
|
|
15646
15850
|
for (const specifier of node.specifiers) {
|
|
15647
|
-
if (specifier.type ===
|
|
15851
|
+
if (specifier.type === AST_NODE_TYPES60.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES60.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES60.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES60.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
15648
15852
|
recordZodBinding(specifier.local);
|
|
15649
15853
|
}
|
|
15650
15854
|
}
|
|
@@ -15652,13 +15856,13 @@ var zod_naming_convention_default = createRule({
|
|
|
15652
15856
|
VariableDeclarator(node) {
|
|
15653
15857
|
const init = node.init;
|
|
15654
15858
|
if (init === null || init === void 0) return;
|
|
15655
|
-
if (init.type !==
|
|
15859
|
+
if (init.type !== AST_NODE_TYPES60.CallExpression) return;
|
|
15656
15860
|
const callee = init.callee;
|
|
15657
|
-
if (callee.type !==
|
|
15861
|
+
if (callee.type !== AST_NODE_TYPES60.MemberExpression) return;
|
|
15658
15862
|
if (!isZodChain(callee)) return;
|
|
15659
15863
|
const terminal = terminalMethodName(callee);
|
|
15660
15864
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
15661
|
-
if (node.id.type !==
|
|
15865
|
+
if (node.id.type !== AST_NODE_TYPES60.Identifier) return;
|
|
15662
15866
|
if (test.test(node.id.name)) return;
|
|
15663
15867
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
15664
15868
|
context.report({
|
|
@@ -15796,6 +16000,7 @@ var rules = {
|
|
|
15796
16000
|
"no-unsafe-mock-casting": no_unsafe_mock_casting_default,
|
|
15797
16001
|
"no-zod-native-enum": no_zod_native_enum_default,
|
|
15798
16002
|
"test-loops-over-literal-cases": test_loops_over_literal_cases_default,
|
|
16003
|
+
"test-phase-label-comment": test_phase_label_comment_default,
|
|
15799
16004
|
"prefer-constant-time-secret-compare": prefer_constant_time_secret_compare_default,
|
|
15800
16005
|
"prefer-discriminated-union": prefer_discriminated_union_default,
|
|
15801
16006
|
"prefer-input-group-search": prefer_input_group_search_default,
|
|
@@ -15824,7 +16029,7 @@ var rules = {
|
|
|
15824
16029
|
};
|
|
15825
16030
|
var meta = {
|
|
15826
16031
|
name: "@sarj/eslint-plugin",
|
|
15827
|
-
version: "15.
|
|
16032
|
+
version: "15.10.0"
|
|
15828
16033
|
};
|
|
15829
16034
|
var applicationOnlyRules = [
|
|
15830
16035
|
"no-restricted-library-load",
|
|
@@ -15835,7 +16040,8 @@ var advisoryRules = [
|
|
|
15835
16040
|
"no-bare-return-from-test-catch",
|
|
15836
16041
|
"iac-source-coupled-test",
|
|
15837
16042
|
"repeated-static-call-cases",
|
|
15838
|
-
"source-coupled-test"
|
|
16043
|
+
"source-coupled-test",
|
|
16044
|
+
"test-phase-label-comment"
|
|
15839
16045
|
];
|
|
15840
16046
|
var recommendedRules = {
|
|
15841
16047
|
"@sarj/iac-source-coupled-test": "warn",
|
|
@@ -15899,6 +16105,7 @@ var recommendedRules = {
|
|
|
15899
16105
|
"@sarj/store-insert-requires-on-conflict": "error",
|
|
15900
16106
|
"@sarj/stepdown": "error",
|
|
15901
16107
|
"@sarj/source-coupled-test": "warn",
|
|
16108
|
+
"@sarj/test-phase-label-comment": "warn",
|
|
15902
16109
|
"@sarj/zod-naming-convention": "error"
|
|
15903
16110
|
};
|
|
15904
16111
|
var strictRules = {
|
|
@@ -15967,6 +16174,7 @@ var strictRules = {
|
|
|
15967
16174
|
"@sarj/store-insert-requires-on-conflict": "error",
|
|
15968
16175
|
"@sarj/stepdown": "error",
|
|
15969
16176
|
"@sarj/source-coupled-test": "warn",
|
|
16177
|
+
"@sarj/test-phase-label-comment": "warn",
|
|
15970
16178
|
"@sarj/zod-naming-convention": "error"
|
|
15971
16179
|
};
|
|
15972
16180
|
var plugin = {
|