@sarj/eslint-plugin 15.16.1 → 15.17.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 +1005 -733
- package/dist/index.d.cts +22 -2
- package/dist/index.d.ts +22 -2
- package/dist/index.js +980 -708
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11664,8 +11664,268 @@ var prefer_module_level_schema_default = createRule({
|
|
|
11664
11664
|
}
|
|
11665
11665
|
});
|
|
11666
11666
|
|
|
11667
|
-
// src/rules/prefer-
|
|
11667
|
+
// src/rules/prefer-module-level-refined-schema.ts
|
|
11668
11668
|
import { AST_NODE_TYPES as AST_NODE_TYPES50 } from "@typescript-eslint/utils";
|
|
11669
|
+
var FACTORIES = /* @__PURE__ */ new Set([
|
|
11670
|
+
"array",
|
|
11671
|
+
"bigint",
|
|
11672
|
+
"boolean",
|
|
11673
|
+
"date",
|
|
11674
|
+
"number",
|
|
11675
|
+
"string"
|
|
11676
|
+
]);
|
|
11677
|
+
var REFINEMENTS = /* @__PURE__ */ new Set([
|
|
11678
|
+
"brand",
|
|
11679
|
+
"check",
|
|
11680
|
+
"email",
|
|
11681
|
+
"finite",
|
|
11682
|
+
"int",
|
|
11683
|
+
"length",
|
|
11684
|
+
"max",
|
|
11685
|
+
"min",
|
|
11686
|
+
"multipleOf",
|
|
11687
|
+
"nonempty",
|
|
11688
|
+
"positive",
|
|
11689
|
+
"regex",
|
|
11690
|
+
"refine",
|
|
11691
|
+
"safe",
|
|
11692
|
+
"superRefine",
|
|
11693
|
+
"transform",
|
|
11694
|
+
"trim",
|
|
11695
|
+
"url",
|
|
11696
|
+
"uuid"
|
|
11697
|
+
]);
|
|
11698
|
+
var PREFER_MODULE_LEVEL_REFINED_SCHEMA_DOCUMENTATION = {
|
|
11699
|
+
summary: "Declare closed, refined Zod scalar and array schemas at module scope.",
|
|
11700
|
+
rationale: "A closed validation pipeline created inside a function is rebuilt on every invocation and obscures a reusable constraint.",
|
|
11701
|
+
remediation: "Move the validation schema to module scope and call parse on the shared schema.",
|
|
11702
|
+
category: "performance",
|
|
11703
|
+
limitations: ["Only direct Zod scalar/array chains with at least two refinement methods and no non-literal arguments are reported."],
|
|
11704
|
+
examples: [
|
|
11705
|
+
{ id: "module-refinement", title: "Share the validation schema", outcome: "no-match", files: [{ path: "src/options.ts", source: "import { z } from 'zod'; const BatchSize = z.number().int().min(1).max(1000); export function parse(value: unknown) { return BatchSize.parse(value); }" }], focusPath: "src/options.ts", expectedCount: 0, public: true },
|
|
11706
|
+
{ id: "local-refinement", title: "Do not rebuild a closed validation chain", outcome: "match", files: [{ path: "src/options.ts", source: "import { z } from 'zod'; export function parse(value: unknown) { return z.number().int().min(1).max(1000).parse(value); }" }], focusPath: "src/options.ts", expectedCount: 1, public: true }
|
|
11707
|
+
]
|
|
11708
|
+
};
|
|
11709
|
+
function enclosingFunction4(node) {
|
|
11710
|
+
let current = node.parent ?? void 0;
|
|
11711
|
+
while (current !== void 0) {
|
|
11712
|
+
if ([AST_NODE_TYPES50.ArrowFunctionExpression, AST_NODE_TYPES50.FunctionDeclaration, AST_NODE_TYPES50.FunctionExpression].includes(current.type)) return current;
|
|
11713
|
+
current = current.parent ?? void 0;
|
|
11714
|
+
}
|
|
11715
|
+
return void 0;
|
|
11716
|
+
}
|
|
11717
|
+
function collectReferences2(scope, output) {
|
|
11718
|
+
output.push(...scope.references);
|
|
11719
|
+
for (const child of scope.childScopes) collectReferences2(child, output);
|
|
11720
|
+
}
|
|
11721
|
+
var prefer_module_level_refined_schema_default = createRule({
|
|
11722
|
+
name: "prefer-module-level-refined-schema",
|
|
11723
|
+
documentation: PREFER_MODULE_LEVEL_REFINED_SCHEMA_DOCUMENTATION,
|
|
11724
|
+
meta: { type: "suggestion", docs: { description: "Declare closed, refined Zod scalar and array schemas at module scope." }, schema: [], messages: { hoistRefinedSchema: "Move this closed refined Zod schema to module scope and reuse it for parsing." } },
|
|
11725
|
+
defaultOptions: [],
|
|
11726
|
+
create(context) {
|
|
11727
|
+
if (isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text)) return {};
|
|
11728
|
+
const namespaces = /* @__PURE__ */ new Set();
|
|
11729
|
+
return {
|
|
11730
|
+
ImportDeclaration(node) {
|
|
11731
|
+
if (!isZodModule(node.source.value)) return;
|
|
11732
|
+
for (const specifier of node.specifiers) if (specifier.type === AST_NODE_TYPES50.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES50.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES50.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES50.Identifier && specifier.imported.name === "z") namespaces.add(specifier.local.name);
|
|
11733
|
+
},
|
|
11734
|
+
CallExpression(node) {
|
|
11735
|
+
const enclosing = enclosingFunction4(node);
|
|
11736
|
+
if (enclosing === void 0 || node.parent?.type !== AST_NODE_TYPES50.MemberExpression || node.parent.object !== node) return;
|
|
11737
|
+
if (node.callee.type !== AST_NODE_TYPES50.MemberExpression || node.callee.computed || node.callee.object.type !== AST_NODE_TYPES50.Identifier || !namespaces.has(node.callee.object.name) || node.callee.property.type !== AST_NODE_TYPES50.Identifier || !FACTORIES.has(node.callee.property.name)) return;
|
|
11738
|
+
let current = node;
|
|
11739
|
+
let refinements = 0;
|
|
11740
|
+
while (current.parent?.type === AST_NODE_TYPES50.MemberExpression && current.parent.object === current && !current.parent.computed && current.parent.property.type === AST_NODE_TYPES50.Identifier && current.parent.parent?.type === AST_NODE_TYPES50.CallExpression && current.parent.parent.callee === current.parent) {
|
|
11741
|
+
const call = current.parent.parent;
|
|
11742
|
+
if (["parse", "parseAsync", "safeParse", "safeParseAsync"].includes(current.parent.property.name)) break;
|
|
11743
|
+
if (REFINEMENTS.has(current.parent.property.name)) refinements += 1;
|
|
11744
|
+
current = call;
|
|
11745
|
+
}
|
|
11746
|
+
if (refinements < 2) return;
|
|
11747
|
+
const references = [];
|
|
11748
|
+
collectReferences2(context.sourceCode.getScope(current), references);
|
|
11749
|
+
const [start, end] = current.range;
|
|
11750
|
+
const [functionStart, functionEnd] = enclosing.range;
|
|
11751
|
+
for (const reference of references) {
|
|
11752
|
+
const [referenceStart] = reference.identifier.range;
|
|
11753
|
+
if (referenceStart < start || referenceStart >= end || reference.resolved === null) continue;
|
|
11754
|
+
for (const definition of reference.resolved.defs) {
|
|
11755
|
+
if (definition.type === "ImportBinding") continue;
|
|
11756
|
+
if (definition.node.type === AST_NODE_TYPES50.VariableDeclarator && definition.node.parent.type === AST_NODE_TYPES50.VariableDeclaration && definition.node.parent.kind !== "const") return;
|
|
11757
|
+
const [definitionStart, definitionEnd] = definition.node.range;
|
|
11758
|
+
if (definitionStart >= start && definitionEnd <= end) continue;
|
|
11759
|
+
if (definitionStart >= functionStart && definitionEnd <= functionEnd) return;
|
|
11760
|
+
}
|
|
11761
|
+
}
|
|
11762
|
+
context.report({ node, messageId: "hoistRefinedSchema" });
|
|
11763
|
+
}
|
|
11764
|
+
};
|
|
11765
|
+
}
|
|
11766
|
+
});
|
|
11767
|
+
|
|
11768
|
+
// src/rules/prefer-multi-value-zod-literal.ts
|
|
11769
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES51 } from "@typescript-eslint/utils";
|
|
11770
|
+
var PREFER_MULTI_VALUE_ZOD_LITERAL_DOCUMENTATION = {
|
|
11771
|
+
summary: "Use the Zod 4 multi-value literal API instead of a union of literal schemas.",
|
|
11772
|
+
rationale: "One multi-value literal expresses the same closed value domain without repeated schema wrappers.",
|
|
11773
|
+
remediation: "Replace the union with z.literal([value1, value2, ...]).",
|
|
11774
|
+
category: "maintainability",
|
|
11775
|
+
limitations: [
|
|
11776
|
+
"Bare `zod` imports are analyzed only when the rule option explicitly declares `zodMajorVersion: 4`; `zod/v4` imports are self-declaring."
|
|
11777
|
+
],
|
|
11778
|
+
examples: [
|
|
11779
|
+
{
|
|
11780
|
+
id: "multi-value",
|
|
11781
|
+
title: "Use one multi-value literal",
|
|
11782
|
+
outcome: "no-match",
|
|
11783
|
+
files: [
|
|
11784
|
+
{
|
|
11785
|
+
path: "src/schema.ts",
|
|
11786
|
+
source: "import { z } from 'zod'; export const Version = z.literal([1, 2, 3]);"
|
|
11787
|
+
}
|
|
11788
|
+
],
|
|
11789
|
+
focusPath: "src/schema.ts",
|
|
11790
|
+
expectedCount: 0,
|
|
11791
|
+
public: true
|
|
11792
|
+
},
|
|
11793
|
+
{
|
|
11794
|
+
id: "literal-union",
|
|
11795
|
+
title: "Avoid repeated literal wrappers",
|
|
11796
|
+
outcome: "match",
|
|
11797
|
+
files: [
|
|
11798
|
+
{
|
|
11799
|
+
path: "src/schema.ts",
|
|
11800
|
+
source: "import { z } from 'zod'; export const Version = z.union([z.literal(1), z.literal(2), z.literal(3)]);"
|
|
11801
|
+
}
|
|
11802
|
+
],
|
|
11803
|
+
focusPath: "src/schema.ts",
|
|
11804
|
+
expectedCount: 1,
|
|
11805
|
+
public: true
|
|
11806
|
+
}
|
|
11807
|
+
]
|
|
11808
|
+
};
|
|
11809
|
+
function memberCall(node, object, method) {
|
|
11810
|
+
return node.callee.type === AST_NODE_TYPES51.MemberExpression && !node.callee.computed && node.callee.object.type === AST_NODE_TYPES51.Identifier && node.callee.object.name === object && node.callee.property.type === AST_NODE_TYPES51.Identifier && node.callee.property.name === method;
|
|
11811
|
+
}
|
|
11812
|
+
var prefer_multi_value_zod_literal_default = createRule({
|
|
11813
|
+
name: "prefer-multi-value-zod-literal",
|
|
11814
|
+
documentation: PREFER_MULTI_VALUE_ZOD_LITERAL_DOCUMENTATION,
|
|
11815
|
+
meta: {
|
|
11816
|
+
type: "suggestion",
|
|
11817
|
+
docs: {
|
|
11818
|
+
description: "Use the Zod 4 multi-value literal API instead of a union of literal schemas."
|
|
11819
|
+
},
|
|
11820
|
+
schema: [
|
|
11821
|
+
{
|
|
11822
|
+
type: "object",
|
|
11823
|
+
additionalProperties: false,
|
|
11824
|
+
properties: {
|
|
11825
|
+
zodMajorVersion: { type: "integer", minimum: 4, maximum: 4 }
|
|
11826
|
+
}
|
|
11827
|
+
}
|
|
11828
|
+
],
|
|
11829
|
+
messages: {
|
|
11830
|
+
useMultiValueLiteral: "Replace this literal-schema union with `{{zod}}.literal([\u2026])`."
|
|
11831
|
+
}
|
|
11832
|
+
},
|
|
11833
|
+
defaultOptions: [{}],
|
|
11834
|
+
create(context, [options]) {
|
|
11835
|
+
if (isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text))
|
|
11836
|
+
return {};
|
|
11837
|
+
const namespaces = /* @__PURE__ */ new Set();
|
|
11838
|
+
const zod4Namespaces = /* @__PURE__ */ new Set();
|
|
11839
|
+
return {
|
|
11840
|
+
ImportDeclaration(node) {
|
|
11841
|
+
if (!isZodModule(node.source.value)) return;
|
|
11842
|
+
for (const specifier of node.specifiers) {
|
|
11843
|
+
if (specifier.type === AST_NODE_TYPES51.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES51.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES51.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES51.Identifier && specifier.imported.name === "z") {
|
|
11844
|
+
namespaces.add(specifier.local.name);
|
|
11845
|
+
if (node.source.value === "zod/v4" || node.source.value.startsWith("zod/v4/"))
|
|
11846
|
+
zod4Namespaces.add(specifier.local.name);
|
|
11847
|
+
}
|
|
11848
|
+
}
|
|
11849
|
+
},
|
|
11850
|
+
CallExpression(node) {
|
|
11851
|
+
const namespace = [...namespaces].find(
|
|
11852
|
+
(name) => memberCall(node, name, "union")
|
|
11853
|
+
);
|
|
11854
|
+
if (namespace === void 0 || options?.zodMajorVersion !== 4 && !zod4Namespaces.has(namespace) || node.arguments.length !== 1)
|
|
11855
|
+
return;
|
|
11856
|
+
const [argument] = node.arguments;
|
|
11857
|
+
if (argument?.type !== AST_NODE_TYPES51.ArrayExpression || argument.elements.length < 3 || argument.elements.some((element) => {
|
|
11858
|
+
if (element === null || element.type !== AST_NODE_TYPES51.CallExpression || !memberCall(element, namespace, "literal") || element.arguments.length !== 1)
|
|
11859
|
+
return true;
|
|
11860
|
+
const [value] = element.arguments;
|
|
11861
|
+
return value === void 0 || value.type === AST_NODE_TYPES51.SpreadElement || ![
|
|
11862
|
+
AST_NODE_TYPES51.Literal,
|
|
11863
|
+
AST_NODE_TYPES51.TemplateLiteral
|
|
11864
|
+
].includes(value.type);
|
|
11865
|
+
}))
|
|
11866
|
+
return;
|
|
11867
|
+
context.report({
|
|
11868
|
+
node,
|
|
11869
|
+
messageId: "useMultiValueLiteral",
|
|
11870
|
+
data: { zod: namespace }
|
|
11871
|
+
});
|
|
11872
|
+
}
|
|
11873
|
+
};
|
|
11874
|
+
}
|
|
11875
|
+
});
|
|
11876
|
+
|
|
11877
|
+
// src/rules/prefer-named-callback-domain.ts
|
|
11878
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES52 } from "@typescript-eslint/utils";
|
|
11879
|
+
var PREFER_NAMED_CALLBACK_DOMAIN_DOCUMENTATION = {
|
|
11880
|
+
summary: "Name literal-union domains used by callbacks in exported contracts.",
|
|
11881
|
+
rationale: "An inline callback domain hides a reusable vocabulary at the point where callers and implementations must agree.",
|
|
11882
|
+
remediation: "Extract the literal union to a named type and use that type in the callback parameter.",
|
|
11883
|
+
category: "maintainability",
|
|
11884
|
+
limitations: ["Only callback types nested in an exported type alias or exported interface are reported."],
|
|
11885
|
+
examples: [
|
|
11886
|
+
{ id: "named-domain", title: "Name the callback domain", outcome: "no-match", files: [{ path: "src/options.ts", source: "export type Boundary = 'seeded' | 'queued'; export interface Options { done?: (boundary: Boundary) => void; }" }], focusPath: "src/options.ts", expectedCount: 0, public: true },
|
|
11887
|
+
{ id: "inline-domain", title: "Do not inline a public callback domain", outcome: "match", files: [{ path: "src/options.ts", source: "export interface Options { done?: (boundary: 'seeded' | 'queued') => void; }" }], focusPath: "src/options.ts", expectedCount: 1, public: true }
|
|
11888
|
+
]
|
|
11889
|
+
};
|
|
11890
|
+
function isLiteralUnion(node) {
|
|
11891
|
+
return node.type === AST_NODE_TYPES52.TSUnionType && node.types.length >= 2 && node.types.every((part) => part.type === AST_NODE_TYPES52.TSLiteralType);
|
|
11892
|
+
}
|
|
11893
|
+
function exportedContract(node) {
|
|
11894
|
+
let current = node;
|
|
11895
|
+
while (current !== void 0) {
|
|
11896
|
+
if (current.type === AST_NODE_TYPES52.ExportNamedDeclaration) return true;
|
|
11897
|
+
if (current.type === AST_NODE_TYPES52.Program) return false;
|
|
11898
|
+
current = current.parent ?? void 0;
|
|
11899
|
+
}
|
|
11900
|
+
return false;
|
|
11901
|
+
}
|
|
11902
|
+
var prefer_named_callback_domain_default = createRule({
|
|
11903
|
+
name: "prefer-named-callback-domain",
|
|
11904
|
+
documentation: PREFER_NAMED_CALLBACK_DOMAIN_DOCUMENTATION,
|
|
11905
|
+
meta: {
|
|
11906
|
+
type: "suggestion",
|
|
11907
|
+
docs: { description: "Name literal-union domains used by callbacks in exported contracts." },
|
|
11908
|
+
schema: [],
|
|
11909
|
+
messages: { nameCallbackDomain: "Extract this inline callback literal union to a named domain type." }
|
|
11910
|
+
},
|
|
11911
|
+
defaultOptions: [],
|
|
11912
|
+
create(context) {
|
|
11913
|
+
if (isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text)) return {};
|
|
11914
|
+
return {
|
|
11915
|
+
TSFunctionType(node) {
|
|
11916
|
+
if (!exportedContract(node)) return;
|
|
11917
|
+
for (const parameter of node.params) {
|
|
11918
|
+
if (parameter.type !== AST_NODE_TYPES52.TSParameterProperty && parameter.typeAnnotation !== void 0 && isLiteralUnion(parameter.typeAnnotation.typeAnnotation)) {
|
|
11919
|
+
context.report({ node: parameter.typeAnnotation.typeAnnotation, messageId: "nameCallbackDomain" });
|
|
11920
|
+
}
|
|
11921
|
+
}
|
|
11922
|
+
}
|
|
11923
|
+
};
|
|
11924
|
+
}
|
|
11925
|
+
});
|
|
11926
|
+
|
|
11927
|
+
// src/rules/prefer-named-complex-return-type.ts
|
|
11928
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES53 } from "@typescript-eslint/utils";
|
|
11669
11929
|
var PREFER_NAMED_COMPLEX_RETURN_TYPE_DOCUMENTATION = {
|
|
11670
11930
|
summary: "Prefer a named contract for structurally complex function return types.",
|
|
11671
11931
|
rationale: "A large inline return annotation hides a reusable domain concept and makes signatures difficult to scan.",
|
|
@@ -11681,7 +11941,7 @@ var PREFER_NAMED_COMPLEX_RETURN_TYPE_DOCUMENTATION = {
|
|
|
11681
11941
|
]
|
|
11682
11942
|
};
|
|
11683
11943
|
function unwrap4(node) {
|
|
11684
|
-
if (node.type ===
|
|
11944
|
+
if (node.type === AST_NODE_TYPES53.TSTypeReference && node.typeArguments?.params.length === 1) {
|
|
11685
11945
|
const [inner] = node.typeArguments.params;
|
|
11686
11946
|
if (inner !== void 0) return unwrap4(inner);
|
|
11687
11947
|
}
|
|
@@ -11695,9 +11955,9 @@ function report(context, node) {
|
|
|
11695
11955
|
}
|
|
11696
11956
|
function isComplex(node) {
|
|
11697
11957
|
const type = unwrap4(node);
|
|
11698
|
-
if (type.type ===
|
|
11699
|
-
if (type.type !==
|
|
11700
|
-
return type.types.every((member) => unwrap4(member).type ===
|
|
11958
|
+
if (type.type === AST_NODE_TYPES53.TSTypeLiteral) return type.members.length >= 3;
|
|
11959
|
+
if (type.type !== AST_NODE_TYPES53.TSUnionType || type.types.length < 3) return false;
|
|
11960
|
+
return type.types.every((member) => unwrap4(member).type === AST_NODE_TYPES53.TSTypeLiteral);
|
|
11701
11961
|
}
|
|
11702
11962
|
var prefer_named_complex_return_type_default = createRule({
|
|
11703
11963
|
name: "prefer-named-complex-return-type",
|
|
@@ -11724,7 +11984,7 @@ var prefer_named_complex_return_type_default = createRule({
|
|
|
11724
11984
|
});
|
|
11725
11985
|
|
|
11726
11986
|
// src/rules/prefer-native-random-uuid.ts
|
|
11727
|
-
import { AST_NODE_TYPES as
|
|
11987
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES54, ASTUtils as ASTUtils14 } from "@typescript-eslint/utils";
|
|
11728
11988
|
var PREFER_NATIVE_RANDOM_UUID_DOCUMENTATION = {
|
|
11729
11989
|
summary: "Prefer `globalThis.crypto.randomUUID()` over resolved zero-argument UUID v4 bindings from the `uuid` package.",
|
|
11730
11990
|
rationale: "The platform implementation avoids an unnecessary dependency for standard random UUID generation.",
|
|
@@ -11738,7 +11998,7 @@ var PREFER_NATIVE_RANDOM_UUID_DOCUMENTATION = {
|
|
|
11738
11998
|
]
|
|
11739
11999
|
};
|
|
11740
12000
|
function requireUuid(node) {
|
|
11741
|
-
return node?.type ===
|
|
12001
|
+
return node?.type === AST_NODE_TYPES54.CallExpression && node.callee.type === AST_NODE_TYPES54.Identifier && node.callee.name === "require" && node.arguments.length === 1 && node.arguments[0]?.type === AST_NODE_TYPES54.Literal && node.arguments[0].value === "uuid";
|
|
11742
12002
|
}
|
|
11743
12003
|
var prefer_native_random_uuid_default = createRule({
|
|
11744
12004
|
name: "prefer-native-random-uuid",
|
|
@@ -11782,37 +12042,37 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
11782
12042
|
ImportDeclaration(node) {
|
|
11783
12043
|
if (node.source.value !== "uuid") return;
|
|
11784
12044
|
for (const specifier of node.specifiers) {
|
|
11785
|
-
if (specifier.type ===
|
|
12045
|
+
if (specifier.type === AST_NODE_TYPES54.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES54.Identifier ? specifier.imported.name === "v4" : specifier.imported.value === "v4")) {
|
|
11786
12046
|
record(specifier.local, directBindings);
|
|
11787
|
-
} else if (specifier.type ===
|
|
12047
|
+
} else if (specifier.type === AST_NODE_TYPES54.ImportNamespaceSpecifier) {
|
|
11788
12048
|
record(specifier.local, namespaceBindings);
|
|
11789
12049
|
}
|
|
11790
12050
|
}
|
|
11791
12051
|
},
|
|
11792
12052
|
VariableDeclarator(node) {
|
|
11793
12053
|
if (node.parent.kind !== "const" || !requireUuid(node.init)) return;
|
|
11794
|
-
if (node.init?.type !==
|
|
12054
|
+
if (node.init?.type !== AST_NODE_TYPES54.CallExpression || node.init.callee.type !== AST_NODE_TYPES54.Identifier || (resolve(node.init.callee)?.defs.length ?? 0) > 0) {
|
|
11795
12055
|
return;
|
|
11796
12056
|
}
|
|
11797
|
-
if (node.id.type ===
|
|
12057
|
+
if (node.id.type === AST_NODE_TYPES54.Identifier) {
|
|
11798
12058
|
record(node.id, namespaceBindings);
|
|
11799
12059
|
return;
|
|
11800
12060
|
}
|
|
11801
|
-
if (node.id.type !==
|
|
12061
|
+
if (node.id.type !== AST_NODE_TYPES54.ObjectPattern) return;
|
|
11802
12062
|
for (const property of node.id.properties) {
|
|
11803
|
-
if (property.type ===
|
|
12063
|
+
if (property.type === AST_NODE_TYPES54.Property && !property.computed && (property.key.type === AST_NODE_TYPES54.Identifier && property.key.name === "v4" || property.key.type === AST_NODE_TYPES54.Literal && property.key.value === "v4") && property.value.type === AST_NODE_TYPES54.Identifier) {
|
|
11804
12064
|
record(property.value, directBindings);
|
|
11805
12065
|
}
|
|
11806
12066
|
}
|
|
11807
12067
|
},
|
|
11808
12068
|
"CallExpression:exit"(node) {
|
|
11809
12069
|
if (node.arguments.length !== 0) return;
|
|
11810
|
-
if (node.callee.type ===
|
|
12070
|
+
if (node.callee.type === AST_NODE_TYPES54.Identifier) {
|
|
11811
12071
|
const variable2 = resolve(node.callee);
|
|
11812
12072
|
if (variable2 !== null && directBindings.has(variable2)) report2(node);
|
|
11813
12073
|
return;
|
|
11814
12074
|
}
|
|
11815
|
-
if (node.callee.type !==
|
|
12075
|
+
if (node.callee.type !== AST_NODE_TYPES54.MemberExpression || node.callee.computed || node.callee.object.type !== AST_NODE_TYPES54.Identifier || node.callee.property.type !== AST_NODE_TYPES54.Identifier || node.callee.property.name !== "v4") {
|
|
11816
12076
|
return;
|
|
11817
12077
|
}
|
|
11818
12078
|
const variable = resolve(node.callee.object);
|
|
@@ -11823,7 +12083,7 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
11823
12083
|
});
|
|
11824
12084
|
|
|
11825
12085
|
// src/rules/prefer-node-crypto-hash.ts
|
|
11826
|
-
import { AST_NODE_TYPES as
|
|
12086
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES55, ASTUtils as ASTUtils15 } from "@typescript-eslint/utils";
|
|
11827
12087
|
var PREFER_NODE_CRYPTO_HASH_DOCUMENTATION = {
|
|
11828
12088
|
summary: "Prefer the modern one-shot node:crypto hash API when streaming state is unnecessary.",
|
|
11829
12089
|
rationale: "A createHash-update-digest chain allocates mutable streaming state for a single in-memory value; Node's built-in hash function expresses the one-shot operation directly and can use its optimized fast path.",
|
|
@@ -11839,33 +12099,33 @@ var PREFER_NODE_CRYPTO_HASH_DOCUMENTATION = {
|
|
|
11839
12099
|
]
|
|
11840
12100
|
};
|
|
11841
12101
|
function memberName3(node) {
|
|
11842
|
-
if (!node.computed && node.property.type ===
|
|
11843
|
-
if (node.computed && node.property.type ===
|
|
12102
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES55.Identifier) return node.property.name;
|
|
12103
|
+
if (node.computed && node.property.type === AST_NODE_TYPES55.Literal && typeof node.property.value === "string") {
|
|
11844
12104
|
return node.property.value;
|
|
11845
12105
|
}
|
|
11846
12106
|
return null;
|
|
11847
12107
|
}
|
|
11848
12108
|
function isCryptoLoader(node, resolve) {
|
|
11849
|
-
if (node.type !==
|
|
12109
|
+
if (node.type !== AST_NODE_TYPES55.CallExpression || node.arguments.length !== 1) return false;
|
|
11850
12110
|
const [argument] = node.arguments;
|
|
11851
|
-
if (argument === void 0 || argument.type ===
|
|
12111
|
+
if (argument === void 0 || argument.type === AST_NODE_TYPES55.SpreadElement || !isCryptoSpecifier(argument)) {
|
|
11852
12112
|
return false;
|
|
11853
12113
|
}
|
|
11854
|
-
if (node.callee.type ===
|
|
12114
|
+
if (node.callee.type === AST_NODE_TYPES55.Identifier) {
|
|
11855
12115
|
return node.callee.name === "require" && isUnshadowedBuiltinIdentifier(node.callee, resolve);
|
|
11856
12116
|
}
|
|
11857
|
-
return node.callee.type ===
|
|
12117
|
+
return node.callee.type === AST_NODE_TYPES55.MemberExpression && node.callee.object.type === AST_NODE_TYPES55.Identifier && node.callee.object.name === "process" && isUnshadowedBuiltinIdentifier(node.callee.object, resolve) && memberName3(node.callee) === "getBuiltinModule";
|
|
11858
12118
|
}
|
|
11859
12119
|
function isCryptoSpecifier(node) {
|
|
11860
|
-
return node.type ===
|
|
12120
|
+
return node.type === AST_NODE_TYPES55.Literal && (node.value === "crypto" || node.value === "node:crypto");
|
|
11861
12121
|
}
|
|
11862
12122
|
function isUnshadowedBuiltinIdentifier(identifier, resolve) {
|
|
11863
12123
|
const variable = resolve(identifier);
|
|
11864
12124
|
return variable === null || variable.defs.length === 0;
|
|
11865
12125
|
}
|
|
11866
12126
|
function propertyName3(node) {
|
|
11867
|
-
if (!node.computed && node.key.type ===
|
|
11868
|
-
if (node.key.type ===
|
|
12127
|
+
if (!node.computed && node.key.type === AST_NODE_TYPES55.Identifier) return node.key.name;
|
|
12128
|
+
if (node.key.type === AST_NODE_TYPES55.Literal && typeof node.key.value === "string") {
|
|
11869
12129
|
return node.key.value;
|
|
11870
12130
|
}
|
|
11871
12131
|
return null;
|
|
@@ -11892,9 +12152,9 @@ var prefer_node_crypto_hash_default = createRule({
|
|
|
11892
12152
|
ImportDeclaration(node) {
|
|
11893
12153
|
if (node.source.value !== "crypto" && node.source.value !== "node:crypto") return;
|
|
11894
12154
|
for (const specifier of node.specifiers) {
|
|
11895
|
-
if (specifier.type ===
|
|
12155
|
+
if (specifier.type === AST_NODE_TYPES55.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES55.ImportDefaultSpecifier) {
|
|
11896
12156
|
record(specifier.local, namespaceBindings);
|
|
11897
|
-
} else if (specifier.type ===
|
|
12157
|
+
} else if (specifier.type === AST_NODE_TYPES55.ImportSpecifier && importedName5(specifier.imported) === "createHash") {
|
|
11898
12158
|
record(specifier.local, directBindings);
|
|
11899
12159
|
}
|
|
11900
12160
|
}
|
|
@@ -11903,13 +12163,13 @@ var prefer_node_crypto_hash_default = createRule({
|
|
|
11903
12163
|
if (node.parent.kind !== "const" || node.init === null || !isCryptoLoader(node.init, resolve)) {
|
|
11904
12164
|
return;
|
|
11905
12165
|
}
|
|
11906
|
-
if (node.id.type ===
|
|
12166
|
+
if (node.id.type === AST_NODE_TYPES55.Identifier) {
|
|
11907
12167
|
record(node.id, namespaceBindings);
|
|
11908
12168
|
return;
|
|
11909
12169
|
}
|
|
11910
|
-
if (node.id.type !==
|
|
12170
|
+
if (node.id.type !== AST_NODE_TYPES55.ObjectPattern) return;
|
|
11911
12171
|
for (const property of node.id.properties) {
|
|
11912
|
-
if (property.type ===
|
|
12172
|
+
if (property.type === AST_NODE_TYPES55.Property && propertyName3(property) === "createHash" && property.value.type === AST_NODE_TYPES55.Identifier) {
|
|
11913
12173
|
record(property.value, directBindings);
|
|
11914
12174
|
}
|
|
11915
12175
|
}
|
|
@@ -11917,10 +12177,10 @@ var prefer_node_crypto_hash_default = createRule({
|
|
|
11917
12177
|
CallExpression(node) {
|
|
11918
12178
|
if (!isMemberCall(node, "digest")) return;
|
|
11919
12179
|
const update = node.callee.object;
|
|
11920
|
-
if (update.type !==
|
|
12180
|
+
if (update.type !== AST_NODE_TYPES55.CallExpression || update.arguments.length !== 1 || !isMemberCall(update, "update"))
|
|
11921
12181
|
return;
|
|
11922
12182
|
const create = update.callee.object;
|
|
11923
|
-
if (create.type !==
|
|
12183
|
+
if (create.type !== AST_NODE_TYPES55.CallExpression || create.arguments.length !== 1 || create.arguments[0]?.type !== AST_NODE_TYPES55.Literal || typeof create.arguments[0].value !== "string" || !isCreateHashCall(
|
|
11924
12184
|
create,
|
|
11925
12185
|
directBindings,
|
|
11926
12186
|
namespaceBindings,
|
|
@@ -11933,27 +12193,27 @@ var prefer_node_crypto_hash_default = createRule({
|
|
|
11933
12193
|
}
|
|
11934
12194
|
});
|
|
11935
12195
|
function importedName5(node) {
|
|
11936
|
-
return node.type ===
|
|
12196
|
+
return node.type === AST_NODE_TYPES55.Identifier ? node.name : node.value;
|
|
11937
12197
|
}
|
|
11938
12198
|
function isMemberCall(node, name) {
|
|
11939
|
-
return node.callee.type ===
|
|
12199
|
+
return node.callee.type === AST_NODE_TYPES55.MemberExpression && memberName3(node.callee) === name;
|
|
11940
12200
|
}
|
|
11941
12201
|
function isCreateHashCall(node, directBindings, namespaceBindings, resolve) {
|
|
11942
|
-
if (node.callee.type ===
|
|
12202
|
+
if (node.callee.type === AST_NODE_TYPES55.Identifier) {
|
|
11943
12203
|
const variable2 = resolve(node.callee);
|
|
11944
12204
|
return variable2 !== null && directBindings.has(variable2);
|
|
11945
12205
|
}
|
|
11946
|
-
if (node.callee.type !==
|
|
12206
|
+
if (node.callee.type !== AST_NODE_TYPES55.MemberExpression || memberName3(node.callee) !== "createHash") {
|
|
11947
12207
|
return false;
|
|
11948
12208
|
}
|
|
11949
12209
|
if (isCryptoLoader(node.callee.object, resolve)) return true;
|
|
11950
|
-
if (node.callee.object.type !==
|
|
12210
|
+
if (node.callee.object.type !== AST_NODE_TYPES55.Identifier) return false;
|
|
11951
12211
|
const variable = resolve(node.callee.object);
|
|
11952
12212
|
return variable !== null && namespaceBindings.has(variable);
|
|
11953
12213
|
}
|
|
11954
12214
|
|
|
11955
12215
|
// src/rules/prefer-node-fs-promises.ts
|
|
11956
|
-
import { AST_NODE_TYPES as
|
|
12216
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES56 } from "@typescript-eslint/utils";
|
|
11957
12217
|
var PREFER_NODE_FS_PROMISES_DOCUMENTATION = {
|
|
11958
12218
|
summary: "Prefer promise-based Node.js filesystem APIs over synchronous calls in production modules.",
|
|
11959
12219
|
rationale: "Synchronous filesystem work blocks the event loop and can stall unrelated daemon, server, and worker tasks.",
|
|
@@ -11970,30 +12230,30 @@ var PREFER_NODE_FS_PROMISES_DOCUMENTATION = {
|
|
|
11970
12230
|
]
|
|
11971
12231
|
};
|
|
11972
12232
|
function memberName4(node) {
|
|
11973
|
-
if (!node.computed && node.property.type ===
|
|
11974
|
-
if (node.computed && node.property.type ===
|
|
12233
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES56.Identifier) return node.property.name;
|
|
12234
|
+
if (node.computed && node.property.type === AST_NODE_TYPES56.Literal && typeof node.property.value === "string") {
|
|
11975
12235
|
return node.property.value;
|
|
11976
12236
|
}
|
|
11977
12237
|
return null;
|
|
11978
12238
|
}
|
|
11979
12239
|
function unwrapAwait2(node) {
|
|
11980
|
-
return node.type ===
|
|
12240
|
+
return node.type === AST_NODE_TYPES56.AwaitExpression ? node.argument : node;
|
|
11981
12241
|
}
|
|
11982
12242
|
function isFsLoader(node) {
|
|
11983
12243
|
const expression = unwrapAwait2(node);
|
|
11984
|
-
if (expression.type ===
|
|
11985
|
-
if (expression.type !==
|
|
12244
|
+
if (expression.type === AST_NODE_TYPES56.ImportExpression) return isFsSpecifier(expression.source);
|
|
12245
|
+
if (expression.type !== AST_NODE_TYPES56.CallExpression || expression.arguments.length !== 1) return false;
|
|
11986
12246
|
const [argument] = expression.arguments;
|
|
11987
|
-
if (argument === void 0 || argument.type ===
|
|
11988
|
-
if (expression.callee.type ===
|
|
11989
|
-
return expression.callee.type ===
|
|
12247
|
+
if (argument === void 0 || argument.type === AST_NODE_TYPES56.SpreadElement || !isFsSpecifier(argument)) return false;
|
|
12248
|
+
if (expression.callee.type === AST_NODE_TYPES56.Identifier) return expression.callee.name === "require";
|
|
12249
|
+
return expression.callee.type === AST_NODE_TYPES56.MemberExpression && expression.callee.object.type === AST_NODE_TYPES56.Identifier && expression.callee.object.name === "process" && memberName4(expression.callee) === "getBuiltinModule";
|
|
11990
12250
|
}
|
|
11991
12251
|
function isFsSpecifier(node) {
|
|
11992
|
-
return node.type ===
|
|
12252
|
+
return node.type === AST_NODE_TYPES56.Literal && (node.value === "node:fs" || node.value === "fs");
|
|
11993
12253
|
}
|
|
11994
12254
|
function propertyName4(node) {
|
|
11995
|
-
if (!node.computed && node.key.type ===
|
|
11996
|
-
if (node.key.type ===
|
|
12255
|
+
if (!node.computed && node.key.type === AST_NODE_TYPES56.Identifier) return node.key.name;
|
|
12256
|
+
if (node.key.type === AST_NODE_TYPES56.Literal && typeof node.key.value === "string") return node.key.value;
|
|
11997
12257
|
return null;
|
|
11998
12258
|
}
|
|
11999
12259
|
var prefer_node_fs_promises_default = createRule({
|
|
@@ -12018,11 +12278,11 @@ var prefer_node_fs_promises_default = createRule({
|
|
|
12018
12278
|
if (node.source.value !== "node:fs" && node.source.value !== "fs") return;
|
|
12019
12279
|
const synchronousImports = [];
|
|
12020
12280
|
for (const specifier of node.specifiers) {
|
|
12021
|
-
if (specifier.type ===
|
|
12281
|
+
if (specifier.type === AST_NODE_TYPES56.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES56.ImportDefaultSpecifier) {
|
|
12022
12282
|
namespaces.add(specifier.local.name);
|
|
12023
12283
|
continue;
|
|
12024
12284
|
}
|
|
12025
|
-
if (specifier.type ===
|
|
12285
|
+
if (specifier.type === AST_NODE_TYPES56.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES56.Identifier && specifier.imported.name.endsWith("Sync")) synchronousImports.push(specifier.imported.name);
|
|
12026
12286
|
}
|
|
12027
12287
|
if (synchronousImports.length > 0) {
|
|
12028
12288
|
context.report({
|
|
@@ -12033,15 +12293,15 @@ var prefer_node_fs_promises_default = createRule({
|
|
|
12033
12293
|
}
|
|
12034
12294
|
},
|
|
12035
12295
|
VariableDeclarator(node) {
|
|
12036
|
-
if (node.init === null || !isFsLoader(node.init) && (node.init.type !==
|
|
12296
|
+
if (node.init === null || !isFsLoader(node.init) && (node.init.type !== AST_NODE_TYPES56.Identifier || !namespaces.has(node.init.name)))
|
|
12037
12297
|
return;
|
|
12038
|
-
if (node.id.type ===
|
|
12298
|
+
if (node.id.type === AST_NODE_TYPES56.Identifier) {
|
|
12039
12299
|
namespaces.add(node.id.name);
|
|
12040
12300
|
return;
|
|
12041
12301
|
}
|
|
12042
|
-
if (node.id.type !==
|
|
12302
|
+
if (node.id.type !== AST_NODE_TYPES56.ObjectPattern) return;
|
|
12043
12303
|
const synchronousImports = node.id.properties.flatMap((property) => {
|
|
12044
|
-
if (property.type !==
|
|
12304
|
+
if (property.type !== AST_NODE_TYPES56.Property) return [];
|
|
12045
12305
|
const name = propertyName4(property);
|
|
12046
12306
|
return name?.endsWith("Sync") === true ? [name] : [];
|
|
12047
12307
|
});
|
|
@@ -12057,7 +12317,7 @@ var prefer_node_fs_promises_default = createRule({
|
|
|
12057
12317
|
const name = memberName4(node);
|
|
12058
12318
|
if (name?.endsWith("Sync") !== true) return;
|
|
12059
12319
|
const object = unwrapAwait2(node.object);
|
|
12060
|
-
if (object.type ===
|
|
12320
|
+
if (object.type === AST_NODE_TYPES56.Identifier && namespaces.has(object.name) || isFsLoader(object)) {
|
|
12061
12321
|
context.report({ node, messageId: "preferAsyncFs", data: { name } });
|
|
12062
12322
|
}
|
|
12063
12323
|
}
|
|
@@ -12066,7 +12326,7 @@ var prefer_node_fs_promises_default = createRule({
|
|
|
12066
12326
|
});
|
|
12067
12327
|
|
|
12068
12328
|
// src/rules/prefer-non-nullable-collection.ts
|
|
12069
|
-
import { AST_NODE_TYPES as
|
|
12329
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES57, ASTUtils as ASTUtils16 } from "@typescript-eslint/utils";
|
|
12070
12330
|
var PREFER_NON_NULLABLE_COLLECTION_DOCUMENTATION = {
|
|
12071
12331
|
summary: "Suggest non-null arrays only when local control flow proves the nullish state is equivalent to an empty collection.",
|
|
12072
12332
|
rationale: "A redundant nullish collection state spreads defaults and guards through consumers without carrying information.",
|
|
@@ -12082,33 +12342,33 @@ var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
|
12082
12342
|
function propertyName5(node) {
|
|
12083
12343
|
const key = node.key;
|
|
12084
12344
|
if (node.computed) return null;
|
|
12085
|
-
if (key.type ===
|
|
12086
|
-
if (key.type ===
|
|
12345
|
+
if (key.type === AST_NODE_TYPES57.Identifier) return key.name;
|
|
12346
|
+
if (key.type === AST_NODE_TYPES57.Literal && typeof key.value === "string") return key.value;
|
|
12087
12347
|
return null;
|
|
12088
12348
|
}
|
|
12089
12349
|
function isArrayType(node) {
|
|
12090
|
-
if (node.type ===
|
|
12091
|
-
return node.type ===
|
|
12350
|
+
if (node.type === AST_NODE_TYPES57.TSArrayType) return true;
|
|
12351
|
+
return node.type === AST_NODE_TYPES57.TSTypeReference && node.typeName.type === AST_NODE_TYPES57.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
12092
12352
|
}
|
|
12093
12353
|
function nullableProperty(node) {
|
|
12094
12354
|
if (node.optional) return null;
|
|
12095
12355
|
const name = propertyName5(node);
|
|
12096
12356
|
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
12097
|
-
if (name === null || annotation?.type !==
|
|
12357
|
+
if (name === null || annotation?.type !== AST_NODE_TYPES57.TSUnionType) return null;
|
|
12098
12358
|
const concrete = annotation.types.filter(
|
|
12099
|
-
(member) => member.type !==
|
|
12359
|
+
(member) => member.type !== AST_NODE_TYPES57.TSNullKeyword && member.type !== AST_NODE_TYPES57.TSUndefinedKeyword
|
|
12100
12360
|
);
|
|
12101
12361
|
if (concrete.length === 0 || !concrete.every(isArrayType)) return null;
|
|
12102
|
-
const acceptsNull = annotation.types.some((member) => member.type ===
|
|
12362
|
+
const acceptsNull = annotation.types.some((member) => member.type === AST_NODE_TYPES57.TSNullKeyword);
|
|
12103
12363
|
const acceptsUndefined = annotation.types.some(
|
|
12104
|
-
(member) => member.type ===
|
|
12364
|
+
(member) => member.type === AST_NODE_TYPES57.TSUndefinedKeyword
|
|
12105
12365
|
);
|
|
12106
12366
|
if (!acceptsNull && !acceptsUndefined) return null;
|
|
12107
12367
|
return { name, node, acceptsNull, acceptsUndefined };
|
|
12108
12368
|
}
|
|
12109
12369
|
function shapeProperties(members) {
|
|
12110
12370
|
return members.flatMap((member) => {
|
|
12111
|
-
if (member.type !==
|
|
12371
|
+
if (member.type !== AST_NODE_TYPES57.TSPropertySignature) return [];
|
|
12112
12372
|
const property = nullableProperty(member);
|
|
12113
12373
|
return property === null ? [] : [property];
|
|
12114
12374
|
});
|
|
@@ -12116,14 +12376,14 @@ function shapeProperties(members) {
|
|
|
12116
12376
|
function typeIndex(program) {
|
|
12117
12377
|
const index = /* @__PURE__ */ new Map();
|
|
12118
12378
|
for (const statement of program.body) {
|
|
12119
|
-
const exported = statement.type ===
|
|
12379
|
+
const exported = statement.type === AST_NODE_TYPES57.ExportNamedDeclaration;
|
|
12120
12380
|
const declaration = exported ? statement.declaration : statement;
|
|
12121
|
-
if (declaration?.type ===
|
|
12381
|
+
if (declaration?.type === AST_NODE_TYPES57.TSInterfaceDeclaration) {
|
|
12122
12382
|
index.set(declaration.id.name, {
|
|
12123
12383
|
exported,
|
|
12124
12384
|
properties: shapeProperties(declaration.body.body)
|
|
12125
12385
|
});
|
|
12126
|
-
} else if (declaration?.type ===
|
|
12386
|
+
} else if (declaration?.type === AST_NODE_TYPES57.TSTypeAliasDeclaration && declaration.typeAnnotation.type === AST_NODE_TYPES57.TSTypeLiteral) {
|
|
12127
12387
|
index.set(declaration.id.name, {
|
|
12128
12388
|
exported,
|
|
12129
12389
|
properties: shapeProperties(declaration.typeAnnotation.members)
|
|
@@ -12133,42 +12393,42 @@ function typeIndex(program) {
|
|
|
12133
12393
|
return index;
|
|
12134
12394
|
}
|
|
12135
12395
|
function emptyArray(node) {
|
|
12136
|
-
return node.type ===
|
|
12396
|
+
return node.type === AST_NODE_TYPES57.ArrayExpression && node.elements.length === 0;
|
|
12137
12397
|
}
|
|
12138
12398
|
function sameAccess(node, access) {
|
|
12139
12399
|
if (access.kind === "identifier") {
|
|
12140
|
-
return node.type ===
|
|
12400
|
+
return node.type === AST_NODE_TYPES57.Identifier && node.name === access.name;
|
|
12141
12401
|
}
|
|
12142
|
-
return node.type ===
|
|
12402
|
+
return node.type === AST_NODE_TYPES57.MemberExpression && !node.computed && node.object.type === AST_NODE_TYPES57.Identifier && node.object.name === access.object && node.property.type === AST_NODE_TYPES57.Identifier && node.property.name === access.property;
|
|
12143
12403
|
}
|
|
12144
12404
|
function isNullGuard(node, access) {
|
|
12145
|
-
if (node.type ===
|
|
12146
|
-
if (node.type !==
|
|
12405
|
+
if (node.type === AST_NODE_TYPES57.UnaryExpression && node.operator === "!" && (sameAccess(node.argument, access) || optionalMemberLengthOf(node.argument, access))) return true;
|
|
12406
|
+
if (node.type !== AST_NODE_TYPES57.BinaryExpression || !["==", "==="].includes(node.operator)) {
|
|
12147
12407
|
return false;
|
|
12148
12408
|
}
|
|
12149
|
-
const nullish = (value) => value.type ===
|
|
12409
|
+
const nullish = (value) => value.type === AST_NODE_TYPES57.Literal && value.value === null || value.type === AST_NODE_TYPES57.Identifier && value.name === "undefined";
|
|
12150
12410
|
return sameAccess(node.left, access) && nullish(node.right) || sameAccess(node.right, access) && nullish(node.left);
|
|
12151
12411
|
}
|
|
12152
12412
|
function isEmptyGuard(node, access) {
|
|
12153
|
-
if (node.type ===
|
|
12154
|
-
if (node.type !==
|
|
12413
|
+
if (node.type === AST_NODE_TYPES57.UnaryExpression && node.operator === "!" && memberLengthOf(node.argument, access)) return true;
|
|
12414
|
+
if (node.type !== AST_NODE_TYPES57.BinaryExpression || !["==", "===", "<="].includes(node.operator)) {
|
|
12155
12415
|
return false;
|
|
12156
12416
|
}
|
|
12157
|
-
const zero = (value) => value.type ===
|
|
12417
|
+
const zero = (value) => value.type === AST_NODE_TYPES57.Literal && value.value === 0;
|
|
12158
12418
|
return memberLengthOf(node.left, access) && zero(node.right) || memberLengthOf(node.right, access) && zero(node.left);
|
|
12159
12419
|
}
|
|
12160
12420
|
function memberLengthOf(node, access) {
|
|
12161
|
-
const target = node.type ===
|
|
12162
|
-
return target.type ===
|
|
12421
|
+
const target = node.type === AST_NODE_TYPES57.ChainExpression ? node.expression : node;
|
|
12422
|
+
return target.type === AST_NODE_TYPES57.MemberExpression && !target.computed && target.property.type === AST_NODE_TYPES57.Identifier && target.property.name === "length" && sameAccess(target.object, access);
|
|
12163
12423
|
}
|
|
12164
12424
|
function optionalMemberLengthOf(node, access) {
|
|
12165
|
-
return node.type ===
|
|
12425
|
+
return node.type === AST_NODE_TYPES57.ChainExpression && node.expression.type === AST_NODE_TYPES57.MemberExpression && node.expression.optional && memberLengthOf(node, access);
|
|
12166
12426
|
}
|
|
12167
12427
|
function hasEquivalentLeadingGuard(fn, access, visitorKeys) {
|
|
12168
|
-
if (fn.body.type !==
|
|
12428
|
+
if (fn.body.type !== AST_NODE_TYPES57.BlockStatement) return false;
|
|
12169
12429
|
const first = fn.body.body[0];
|
|
12170
|
-
if (first?.type !==
|
|
12171
|
-
const terminating = first.consequent.type ===
|
|
12430
|
+
if (first?.type !== AST_NODE_TYPES57.IfStatement) return false;
|
|
12431
|
+
const terminating = first.consequent.type === AST_NODE_TYPES57.ReturnStatement || first.consequent.type === AST_NODE_TYPES57.ThrowStatement || first.consequent.type === AST_NODE_TYPES57.BlockStatement && first.consequent.body.length === 1 && (first.consequent.body[0]?.type === AST_NODE_TYPES57.ReturnStatement || first.consequent.body[0]?.type === AST_NODE_TYPES57.ThrowStatement);
|
|
12172
12432
|
if (!terminating) return false;
|
|
12173
12433
|
if (contains(first.consequent, visitorKeys, (node) => sameAccess(node, access))) return false;
|
|
12174
12434
|
return contains(first.test, visitorKeys, (node) => isNullGuard(node, access)) && contains(first.test, visitorKeys, (node) => isEmptyGuard(node, access));
|
|
@@ -12186,14 +12446,14 @@ function contains(node, visitorKeys, predicate) {
|
|
|
12186
12446
|
function belongsToFunction(node, fn) {
|
|
12187
12447
|
let current = node;
|
|
12188
12448
|
while (current !== void 0 && current !== fn) {
|
|
12189
|
-
if (current !== node && (current.type ===
|
|
12449
|
+
if (current !== node && (current.type === AST_NODE_TYPES57.ArrowFunctionExpression || current.type === AST_NODE_TYPES57.FunctionDeclaration || current.type === AST_NODE_TYPES57.FunctionExpression)) return false;
|
|
12190
12450
|
current = current.parent;
|
|
12191
12451
|
}
|
|
12192
12452
|
return current === fn;
|
|
12193
12453
|
}
|
|
12194
12454
|
function directlyCoalesced(node) {
|
|
12195
12455
|
const parent = node.parent;
|
|
12196
|
-
return parent?.type ===
|
|
12456
|
+
return parent?.type === AST_NODE_TYPES57.LogicalExpression && parent.left === node && (parent.operator === "??" || parent.operator === "||") && emptyArray(parent.right);
|
|
12197
12457
|
}
|
|
12198
12458
|
function identifierIsOnlyCoalesced(context, binding, fn) {
|
|
12199
12459
|
const variable = ASTUtils16.findVariable(context.sourceCode.getScope(binding), binding.name);
|
|
@@ -12208,7 +12468,7 @@ function memberIsOnlyCoalesced(context, object, property, fn) {
|
|
|
12208
12468
|
const accesses = variable.references.flatMap((reference) => {
|
|
12209
12469
|
if (!belongsToFunction(reference.identifier, fn)) return [null];
|
|
12210
12470
|
const parent = reference.identifier.parent;
|
|
12211
|
-
if (parent?.type ===
|
|
12471
|
+
if (parent?.type === AST_NODE_TYPES57.MemberExpression && !parent.computed && parent.object === reference.identifier && parent.property.type === AST_NODE_TYPES57.Identifier && parent.property.name === property) return [parent];
|
|
12212
12472
|
return [];
|
|
12213
12473
|
});
|
|
12214
12474
|
return accesses.length > 0 && accesses.every((access) => access !== null && directlyCoalesced(access));
|
|
@@ -12234,8 +12494,8 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
12234
12494
|
let shapes = /* @__PURE__ */ new Map();
|
|
12235
12495
|
const evidence = /* @__PURE__ */ new Map();
|
|
12236
12496
|
function propertiesFor(annotation) {
|
|
12237
|
-
if (annotation?.type ===
|
|
12238
|
-
if (annotation?.type ===
|
|
12497
|
+
if (annotation?.type === AST_NODE_TYPES57.TSTypeLiteral) return shapeProperties(annotation.members);
|
|
12498
|
+
if (annotation?.type === AST_NODE_TYPES57.TSTypeReference && annotation.typeName.type === AST_NODE_TYPES57.Identifier) {
|
|
12239
12499
|
const shape = shapes.get(annotation.typeName.name);
|
|
12240
12500
|
return shape?.exported === false ? shape.properties : [];
|
|
12241
12501
|
}
|
|
@@ -12248,21 +12508,21 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
12248
12508
|
}
|
|
12249
12509
|
function checkFunction(fn) {
|
|
12250
12510
|
for (const rawParameter of fn.params) {
|
|
12251
|
-
const parameter = rawParameter.type ===
|
|
12252
|
-
if (parameter.type ===
|
|
12511
|
+
const parameter = rawParameter.type === AST_NODE_TYPES57.AssignmentPattern ? rawParameter.left : rawParameter;
|
|
12512
|
+
if (parameter.type === AST_NODE_TYPES57.ObjectPattern) {
|
|
12253
12513
|
const properties2 = propertiesFor(parameter.typeAnnotation?.typeAnnotation);
|
|
12254
12514
|
for (const property of properties2) {
|
|
12255
12515
|
const bindingProperty = parameter.properties.find(
|
|
12256
|
-
(entry) => entry.type ===
|
|
12516
|
+
(entry) => entry.type === AST_NODE_TYPES57.Property && !entry.computed && entry.key.type === AST_NODE_TYPES57.Identifier && entry.key.name === property.name
|
|
12257
12517
|
);
|
|
12258
12518
|
if (bindingProperty === void 0) continue;
|
|
12259
12519
|
const value = bindingProperty.value;
|
|
12260
|
-
const binding = value.type ===
|
|
12261
|
-
if (binding.type !==
|
|
12520
|
+
const binding = value.type === AST_NODE_TYPES57.AssignmentPattern ? value.left : value;
|
|
12521
|
+
if (binding.type !== AST_NODE_TYPES57.Identifier) {
|
|
12262
12522
|
record(property, false);
|
|
12263
12523
|
continue;
|
|
12264
12524
|
}
|
|
12265
|
-
if (value.type ===
|
|
12525
|
+
if (value.type === AST_NODE_TYPES57.AssignmentPattern && emptyArray(value.right) && property.acceptsUndefined && !property.acceptsNull) {
|
|
12266
12526
|
record(property, true);
|
|
12267
12527
|
continue;
|
|
12268
12528
|
}
|
|
@@ -12274,7 +12534,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
12274
12534
|
}
|
|
12275
12535
|
continue;
|
|
12276
12536
|
}
|
|
12277
|
-
if (parameter.type !==
|
|
12537
|
+
if (parameter.type !== AST_NODE_TYPES57.Identifier) continue;
|
|
12278
12538
|
const properties = propertiesFor(parameter.typeAnnotation?.typeAnnotation);
|
|
12279
12539
|
for (const property of properties) {
|
|
12280
12540
|
const access = {
|
|
@@ -12312,7 +12572,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
12312
12572
|
|
|
12313
12573
|
// src/rules/prefer-nullish-filter-predicate.ts
|
|
12314
12574
|
import {
|
|
12315
|
-
AST_NODE_TYPES as
|
|
12575
|
+
AST_NODE_TYPES as AST_NODE_TYPES58,
|
|
12316
12576
|
ASTUtils as ASTUtils17,
|
|
12317
12577
|
ESLintUtils as ESLintUtils5
|
|
12318
12578
|
} from "@typescript-eslint/utils";
|
|
@@ -12449,7 +12709,7 @@ var prefer_nullish_filter_predicate_default = createRule({
|
|
|
12449
12709
|
CallExpression(node) {
|
|
12450
12710
|
const callee = node.callee;
|
|
12451
12711
|
const callback = node.arguments[0];
|
|
12452
|
-
if (node.arguments.length !== 1 || callback?.type !==
|
|
12712
|
+
if (node.arguments.length !== 1 || callback?.type !== AST_NODE_TYPES58.Identifier || callback.name !== "Boolean" || callee.type !== AST_NODE_TYPES58.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES58.Identifier || callee.property.name !== "filter" || !isUnshadowedBoolean(callback, context) || !isBuiltinArrayFilter(callee, services)) return;
|
|
12453
12713
|
const elementType = arrayElementType(callee.object, services);
|
|
12454
12714
|
const checker = services.program.getTypeChecker();
|
|
12455
12715
|
if (elementType === null || !isNullishPlusTruthy(elementType, checker)) return;
|
|
@@ -12474,7 +12734,7 @@ var prefer_nullish_filter_predicate_default = createRule({
|
|
|
12474
12734
|
import {
|
|
12475
12735
|
ASTUtils as ASTUtils18,
|
|
12476
12736
|
ESLintUtils as ESLintUtils6,
|
|
12477
|
-
AST_NODE_TYPES as
|
|
12737
|
+
AST_NODE_TYPES as AST_NODE_TYPES59
|
|
12478
12738
|
} from "@typescript-eslint/utils";
|
|
12479
12739
|
import * as ts4 from "typescript";
|
|
12480
12740
|
var PREFER_AWAIT_IN_ASYNC_RETURN_DOCUMENTATION = {
|
|
@@ -12517,10 +12777,10 @@ var PREFER_AWAIT_IN_ASYNC_RETURN_DOCUMENTATION = {
|
|
|
12517
12777
|
};
|
|
12518
12778
|
function directAsyncReturnOwner(node) {
|
|
12519
12779
|
const parent = node.parent;
|
|
12520
|
-
if (parent.type ===
|
|
12780
|
+
if (parent.type === AST_NODE_TYPES59.ArrowFunctionExpression && parent.body === node) {
|
|
12521
12781
|
return parent.async && !parent.generator ? parent : null;
|
|
12522
12782
|
}
|
|
12523
|
-
if (parent.type !==
|
|
12783
|
+
if (parent.type !== AST_NODE_TYPES59.ReturnStatement || parent.argument !== node) {
|
|
12524
12784
|
return null;
|
|
12525
12785
|
}
|
|
12526
12786
|
let owner = parent.parent;
|
|
@@ -12530,15 +12790,15 @@ function directAsyncReturnOwner(node) {
|
|
|
12530
12790
|
return owner !== void 0 && owner.async && !owner.generator ? owner : null;
|
|
12531
12791
|
}
|
|
12532
12792
|
function isRuntimeFunction(node) {
|
|
12533
|
-
return node.type ===
|
|
12793
|
+
return node.type === AST_NODE_TYPES59.ArrowFunctionExpression || node.type === AST_NODE_TYPES59.FunctionDeclaration || node.type === AST_NODE_TYPES59.FunctionExpression;
|
|
12534
12794
|
}
|
|
12535
12795
|
function promiseThenReceiver(node) {
|
|
12536
12796
|
const callee = node.callee;
|
|
12537
|
-
if (callee.type !==
|
|
12797
|
+
if (callee.type !== AST_NODE_TYPES59.MemberExpression || callee.computed || callee.optional || callee.property.type !== AST_NODE_TYPES59.Identifier || callee.property.name !== "then" || node.optional || node.arguments.length !== 1) {
|
|
12538
12798
|
return null;
|
|
12539
12799
|
}
|
|
12540
12800
|
const callback = node.arguments[0];
|
|
12541
|
-
if (callback === void 0 || callback.type !==
|
|
12801
|
+
if (callback === void 0 || callback.type !== AST_NODE_TYPES59.ArrowFunctionExpression && callback.type !== AST_NODE_TYPES59.FunctionExpression) {
|
|
12542
12802
|
return null;
|
|
12543
12803
|
}
|
|
12544
12804
|
return callee.object;
|
|
@@ -12591,7 +12851,7 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
12591
12851
|
};
|
|
12592
12852
|
const isFrameworkLoaderCallback = (owner) => {
|
|
12593
12853
|
const parent = owner.parent;
|
|
12594
|
-
if (parent.type !==
|
|
12854
|
+
if (parent.type !== AST_NODE_TYPES59.CallExpression || parent.arguments[0] !== owner || parent.callee.type !== AST_NODE_TYPES59.Identifier) return false;
|
|
12595
12855
|
const variable = ASTUtils18.findVariable(context.sourceCode.getScope(parent.callee), parent.callee.name);
|
|
12596
12856
|
return variable !== null && frameworkLoaders.has(variable);
|
|
12597
12857
|
};
|
|
@@ -12599,12 +12859,12 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
12599
12859
|
ImportDeclaration(node) {
|
|
12600
12860
|
if (node.source.value === "react") {
|
|
12601
12861
|
for (const specifier of node.specifiers) {
|
|
12602
|
-
if (specifier.type ===
|
|
12862
|
+
if (specifier.type === AST_NODE_TYPES59.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES59.Identifier ? specifier.imported.name : specifier.imported.value) === "lazy") rememberFrameworkLoader(specifier.local);
|
|
12603
12863
|
}
|
|
12604
12864
|
}
|
|
12605
12865
|
if (node.source.value === "next/dynamic") {
|
|
12606
12866
|
for (const specifier of node.specifiers) {
|
|
12607
|
-
if (specifier.type ===
|
|
12867
|
+
if (specifier.type === AST_NODE_TYPES59.ImportDefaultSpecifier) rememberFrameworkLoader(specifier.local);
|
|
12608
12868
|
}
|
|
12609
12869
|
}
|
|
12610
12870
|
},
|
|
@@ -12622,7 +12882,7 @@ var prefer_await_in_async_return_default = createRule({
|
|
|
12622
12882
|
});
|
|
12623
12883
|
|
|
12624
12884
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
12625
|
-
import { AST_NODE_TYPES as
|
|
12885
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES60 } from "@typescript-eslint/utils";
|
|
12626
12886
|
var PREFER_SCHEMA_FOR_API_PAYLOAD_DOCUMENTATION = {
|
|
12627
12887
|
summary: "Require Zod (or similar) schema validation on `response.json()` / `JSON.parse()` results before property access.",
|
|
12628
12888
|
rationale: "External JSON is untrusted at runtime even when its expected TypeScript shape is known statically.",
|
|
@@ -12637,9 +12897,9 @@ var PREFER_SCHEMA_FOR_API_PAYLOAD_DOCUMENTATION = {
|
|
|
12637
12897
|
var unwrap5 = (node) => {
|
|
12638
12898
|
let current = node;
|
|
12639
12899
|
while (current !== null && current !== void 0) {
|
|
12640
|
-
if (current.type ===
|
|
12900
|
+
if (current.type === AST_NODE_TYPES60.TSAsExpression || current.type === AST_NODE_TYPES60.TSTypeAssertion || current.type === AST_NODE_TYPES60.TSNonNullExpression || current.type === AST_NODE_TYPES60.TSSatisfiesExpression) {
|
|
12641
12901
|
current = current.expression;
|
|
12642
|
-
} else if (current.type ===
|
|
12902
|
+
} else if (current.type === AST_NODE_TYPES60.ChainExpression) {
|
|
12643
12903
|
current = current.expression;
|
|
12644
12904
|
} else {
|
|
12645
12905
|
break;
|
|
@@ -12654,23 +12914,23 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
12654
12914
|
]);
|
|
12655
12915
|
var isSchemaParseReference = (node) => {
|
|
12656
12916
|
const inner = unwrap5(node);
|
|
12657
|
-
return inner !== null && inner.type ===
|
|
12917
|
+
return inner !== null && inner.type === AST_NODE_TYPES60.MemberExpression && !inner.computed && inner.property.type === AST_NODE_TYPES60.Identifier && (inner.property.name === "parse" || inner.property.name === "safeParse");
|
|
12658
12918
|
};
|
|
12659
12919
|
var isRawPayloadSource = (node, isKnownLocalText) => {
|
|
12660
12920
|
let current = unwrap5(node);
|
|
12661
12921
|
if (current === null) return false;
|
|
12662
|
-
if (current.type ===
|
|
12922
|
+
if (current.type === AST_NODE_TYPES60.AwaitExpression) {
|
|
12663
12923
|
current = unwrap5(current.argument);
|
|
12664
12924
|
}
|
|
12665
|
-
if (current === null || current.type !==
|
|
12925
|
+
if (current === null || current.type !== AST_NODE_TYPES60.CallExpression) {
|
|
12666
12926
|
return false;
|
|
12667
12927
|
}
|
|
12668
12928
|
const callee = unwrap5(current.callee);
|
|
12669
|
-
if (callee === null || callee.type !==
|
|
12929
|
+
if (callee === null || callee.type !== AST_NODE_TYPES60.MemberExpression) {
|
|
12670
12930
|
return false;
|
|
12671
12931
|
}
|
|
12672
12932
|
const property = unwrap5(callee.property);
|
|
12673
|
-
if (property === null || property.type !==
|
|
12933
|
+
if (property === null || property.type !== AST_NODE_TYPES60.Identifier) {
|
|
12674
12934
|
return false;
|
|
12675
12935
|
}
|
|
12676
12936
|
if (property.name === "json") {
|
|
@@ -12680,17 +12940,17 @@ var isRawPayloadSource = (node, isKnownLocalText) => {
|
|
|
12680
12940
|
return !current.arguments.some(isSchemaParseReference) && isRawPayloadSource(callee.object);
|
|
12681
12941
|
}
|
|
12682
12942
|
const object = unwrap5(callee.object);
|
|
12683
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
12943
|
+
return property.name === "parse" && object !== null && object.type === AST_NODE_TYPES60.Identifier && object.name === "JSON" && !isLocalFileRead(current.arguments[0]) && isKnownLocalText?.(current.arguments[0]) !== true;
|
|
12684
12944
|
};
|
|
12685
12945
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
12686
12946
|
var isDirectLocalFileRead = (node) => {
|
|
12687
12947
|
let current = unwrap5(node);
|
|
12688
|
-
if (current?.type ===
|
|
12948
|
+
if (current?.type === AST_NODE_TYPES60.AwaitExpression) {
|
|
12689
12949
|
current = unwrap5(current.argument);
|
|
12690
12950
|
}
|
|
12691
|
-
if (current?.type !==
|
|
12951
|
+
if (current?.type !== AST_NODE_TYPES60.CallExpression) return false;
|
|
12692
12952
|
const callee = unwrap5(current.callee);
|
|
12693
|
-
const name = callee?.type ===
|
|
12953
|
+
const name = callee?.type === AST_NODE_TYPES60.Identifier ? callee.name : callee?.type === AST_NODE_TYPES60.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES60.Identifier ? callee.property.name : null;
|
|
12694
12954
|
return name !== null && FILE_READ_RE.test(name);
|
|
12695
12955
|
};
|
|
12696
12956
|
var isLocalFileRead = (node) => {
|
|
@@ -12717,15 +12977,15 @@ var isLocalFileRead = (node) => {
|
|
|
12717
12977
|
var ASSERTION_CALLEE_RE = /^(expect|assert|should|invariant)$/;
|
|
12718
12978
|
var isInsideAssertion = (node) => {
|
|
12719
12979
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
12720
|
-
if (current.type !==
|
|
12980
|
+
if (current.type !== AST_NODE_TYPES60.CallExpression) continue;
|
|
12721
12981
|
let callee = current.callee;
|
|
12722
|
-
while (callee.type ===
|
|
12982
|
+
while (callee.type === AST_NODE_TYPES60.MemberExpression) {
|
|
12723
12983
|
callee = callee.object;
|
|
12724
12984
|
}
|
|
12725
|
-
if (callee.type ===
|
|
12985
|
+
if (callee.type === AST_NODE_TYPES60.CallExpression) {
|
|
12726
12986
|
callee = callee.callee;
|
|
12727
12987
|
}
|
|
12728
|
-
if (callee.type ===
|
|
12988
|
+
if (callee.type === AST_NODE_TYPES60.Identifier && ASSERTION_CALLEE_RE.test(callee.name)) {
|
|
12729
12989
|
return true;
|
|
12730
12990
|
}
|
|
12731
12991
|
}
|
|
@@ -12744,22 +13004,22 @@ var GUARD_NAME_RE = /^(?:is|validate|parse|assert|decode|coerce)[A-Z]/;
|
|
|
12744
13004
|
var isValidationRead = (node) => {
|
|
12745
13005
|
let current = node;
|
|
12746
13006
|
let parent = current.parent;
|
|
12747
|
-
while (parent !== null && parent !== void 0 && (parent.type ===
|
|
13007
|
+
while (parent !== null && parent !== void 0 && (parent.type === AST_NODE_TYPES60.TSAsExpression || parent.type === AST_NODE_TYPES60.TSTypeAssertion || parent.type === AST_NODE_TYPES60.TSNonNullExpression || parent.type === AST_NODE_TYPES60.TSSatisfiesExpression || parent.type === AST_NODE_TYPES60.ChainExpression)) {
|
|
12748
13008
|
current = parent;
|
|
12749
13009
|
parent = parent.parent;
|
|
12750
13010
|
}
|
|
12751
13011
|
if (parent === null || parent === void 0) return false;
|
|
12752
|
-
if (parent.type ===
|
|
13012
|
+
if (parent.type === AST_NODE_TYPES60.UnaryExpression && parent.operator === "typeof" && parent.argument === current) {
|
|
12753
13013
|
return true;
|
|
12754
13014
|
}
|
|
12755
|
-
if (parent.type !==
|
|
13015
|
+
if (parent.type !== AST_NODE_TYPES60.CallExpression || !parent.arguments.some((arg) => arg === current)) {
|
|
12756
13016
|
return false;
|
|
12757
13017
|
}
|
|
12758
13018
|
const callee = parent.callee;
|
|
12759
|
-
if (callee.type ===
|
|
13019
|
+
if (callee.type === AST_NODE_TYPES60.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES60.Identifier && callee.object.name === "Array" && callee.property.type === AST_NODE_TYPES60.Identifier && callee.property.name === "isArray") {
|
|
12760
13020
|
return parent.arguments.length === 1;
|
|
12761
13021
|
}
|
|
12762
|
-
return callee.type ===
|
|
13022
|
+
return callee.type === AST_NODE_TYPES60.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
12763
13023
|
};
|
|
12764
13024
|
var PRIMITIVE_TYPEOF_RESULTS = /* @__PURE__ */ new Set([
|
|
12765
13025
|
"bigint",
|
|
@@ -12770,13 +13030,13 @@ var PRIMITIVE_TYPEOF_RESULTS = /* @__PURE__ */ new Set([
|
|
|
12770
13030
|
"undefined"
|
|
12771
13031
|
]);
|
|
12772
13032
|
var bindingValidationPolarity = (test, bindingName) => {
|
|
12773
|
-
if (test.type ===
|
|
13033
|
+
if (test.type === AST_NODE_TYPES60.UnaryExpression && test.operator === "!") {
|
|
12774
13034
|
const inner = bindingValidationPolarity(test.argument, bindingName);
|
|
12775
13035
|
return inner === "valid-when-true" ? "valid-when-false" : inner === "valid-when-false" ? "valid-when-true" : null;
|
|
12776
13036
|
}
|
|
12777
|
-
if (test.type ===
|
|
12778
|
-
const typeofName = (node) => node.type ===
|
|
12779
|
-
const literalType = (node) => node.type ===
|
|
13037
|
+
if (test.type === AST_NODE_TYPES60.BinaryExpression) {
|
|
13038
|
+
const typeofName = (node) => node.type === AST_NODE_TYPES60.UnaryExpression && node.operator === "typeof" && node.argument.type === AST_NODE_TYPES60.Identifier ? node.argument.name : null;
|
|
13039
|
+
const literalType = (node) => node.type === AST_NODE_TYPES60.Literal && typeof node.value === "string" && PRIMITIVE_TYPEOF_RESULTS.has(node.value) ? node.value : null;
|
|
12780
13040
|
const matches = typeofName(test.left) === bindingName && literalType(test.right) !== null || typeofName(test.right) === bindingName && literalType(test.left) !== null;
|
|
12781
13041
|
if (!matches) return null;
|
|
12782
13042
|
if (test.operator === "===" || test.operator === "==") {
|
|
@@ -12784,9 +13044,9 @@ var bindingValidationPolarity = (test, bindingName) => {
|
|
|
12784
13044
|
}
|
|
12785
13045
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
12786
13046
|
}
|
|
12787
|
-
return test.type ===
|
|
13047
|
+
return test.type === AST_NODE_TYPES60.CallExpression && test.arguments.length === 1 && test.arguments[0]?.type === AST_NODE_TYPES60.Identifier && test.arguments[0].name === bindingName && test.callee.type === AST_NODE_TYPES60.MemberExpression && !test.callee.computed && test.callee.object.type === AST_NODE_TYPES60.Identifier && test.callee.object.name === "Array" && test.callee.property.type === AST_NODE_TYPES60.Identifier && test.callee.property.name === "isArray" ? "valid-when-true" : null;
|
|
12788
13048
|
};
|
|
12789
|
-
var plainMemberAccess = (node) => node.type ===
|
|
13049
|
+
var plainMemberAccess = (node) => node.type === AST_NODE_TYPES60.MemberExpression && !node.computed && node.object.type === AST_NODE_TYPES60.Identifier && node.property.type === AST_NODE_TYPES60.Identifier ? { object: node.object.name, property: node.property.name } : null;
|
|
12790
13050
|
var isSamePlainMember = (node, access) => {
|
|
12791
13051
|
const candidate2 = plainMemberAccess(node);
|
|
12792
13052
|
return candidate2 !== null && candidate2.object === access.object && candidate2.property === access.property;
|
|
@@ -12794,19 +13054,19 @@ var isSamePlainMember = (node, access) => {
|
|
|
12794
13054
|
var nodeWithin2 = (node, container) => node.range[0] >= container.range[0] && node.range[1] <= container.range[1];
|
|
12795
13055
|
var isUseWithinValidatedBranch = (node, bindingName) => {
|
|
12796
13056
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
12797
|
-
if (current.type ===
|
|
13057
|
+
if (current.type === AST_NODE_TYPES60.ConditionalExpression) {
|
|
12798
13058
|
const polarity = bindingValidationPolarity(current.test, bindingName);
|
|
12799
13059
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && nodeWithin2(node, current.alternate)) {
|
|
12800
13060
|
return true;
|
|
12801
13061
|
}
|
|
12802
13062
|
}
|
|
12803
|
-
if (current.type ===
|
|
13063
|
+
if (current.type === AST_NODE_TYPES60.IfStatement) {
|
|
12804
13064
|
const polarity = bindingValidationPolarity(current.test, bindingName);
|
|
12805
13065
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && current.alternate !== null && nodeWithin2(node, current.alternate)) {
|
|
12806
13066
|
return true;
|
|
12807
13067
|
}
|
|
12808
13068
|
}
|
|
12809
|
-
if (current.type ===
|
|
13069
|
+
if (current.type === AST_NODE_TYPES60.FunctionDeclaration || current.type === AST_NODE_TYPES60.FunctionExpression || current.type === AST_NODE_TYPES60.ArrowFunctionExpression) {
|
|
12810
13070
|
return false;
|
|
12811
13071
|
}
|
|
12812
13072
|
}
|
|
@@ -12814,32 +13074,32 @@ var isUseWithinValidatedBranch = (node, bindingName) => {
|
|
|
12814
13074
|
};
|
|
12815
13075
|
var isMemberUseWithinValidatedBranch = (node, access) => {
|
|
12816
13076
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
12817
|
-
if (current.type ===
|
|
13077
|
+
if (current.type === AST_NODE_TYPES60.ConditionalExpression) {
|
|
12818
13078
|
const polarity = memberValidationPolarity(current.test, access);
|
|
12819
13079
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && nodeWithin2(node, current.alternate)) {
|
|
12820
13080
|
return true;
|
|
12821
13081
|
}
|
|
12822
13082
|
}
|
|
12823
|
-
if (current.type ===
|
|
13083
|
+
if (current.type === AST_NODE_TYPES60.IfStatement) {
|
|
12824
13084
|
const polarity = memberValidationPolarity(current.test, access);
|
|
12825
13085
|
if (polarity === "valid-when-true" && nodeWithin2(node, current.consequent) || polarity === "valid-when-false" && current.alternate !== null && nodeWithin2(node, current.alternate)) {
|
|
12826
13086
|
return true;
|
|
12827
13087
|
}
|
|
12828
13088
|
}
|
|
12829
|
-
if (current.type ===
|
|
13089
|
+
if (current.type === AST_NODE_TYPES60.FunctionDeclaration || current.type === AST_NODE_TYPES60.FunctionExpression || current.type === AST_NODE_TYPES60.ArrowFunctionExpression) {
|
|
12830
13090
|
return false;
|
|
12831
13091
|
}
|
|
12832
13092
|
}
|
|
12833
13093
|
return false;
|
|
12834
13094
|
};
|
|
12835
13095
|
var memberValidationPolarity = (test, access) => {
|
|
12836
|
-
if (test.type ===
|
|
13096
|
+
if (test.type === AST_NODE_TYPES60.UnaryExpression && test.operator === "!") {
|
|
12837
13097
|
const inner = memberValidationPolarity(test.argument, access);
|
|
12838
13098
|
return inner === "valid-when-true" ? "valid-when-false" : inner === "valid-when-false" ? "valid-when-true" : null;
|
|
12839
13099
|
}
|
|
12840
|
-
if (test.type ===
|
|
12841
|
-
const isMatchingTypeof = (node) => node.type ===
|
|
12842
|
-
const isPrimitiveType = (node) => node.type ===
|
|
13100
|
+
if (test.type === AST_NODE_TYPES60.BinaryExpression) {
|
|
13101
|
+
const isMatchingTypeof = (node) => node.type === AST_NODE_TYPES60.UnaryExpression && node.operator === "typeof" && isSamePlainMember(node.argument, access);
|
|
13102
|
+
const isPrimitiveType = (node) => node.type === AST_NODE_TYPES60.Literal && typeof node.value === "string" && PRIMITIVE_TYPEOF_RESULTS.has(node.value);
|
|
12843
13103
|
if (!(isMatchingTypeof(test.left) && isPrimitiveType(test.right) || isMatchingTypeof(test.right) && isPrimitiveType(test.left))) {
|
|
12844
13104
|
return null;
|
|
12845
13105
|
}
|
|
@@ -12848,15 +13108,15 @@ var memberValidationPolarity = (test, access) => {
|
|
|
12848
13108
|
}
|
|
12849
13109
|
return test.operator === "!==" || test.operator === "!=" ? "valid-when-false" : null;
|
|
12850
13110
|
}
|
|
12851
|
-
return test.type ===
|
|
13111
|
+
return test.type === AST_NODE_TYPES60.CallExpression && test.arguments.length === 1 && test.arguments[0] !== void 0 && test.arguments[0].type !== AST_NODE_TYPES60.SpreadElement && isSamePlainMember(test.arguments[0], access) && test.callee.type === AST_NODE_TYPES60.MemberExpression && !test.callee.computed && test.callee.object.type === AST_NODE_TYPES60.Identifier && test.callee.object.name === "Array" && test.callee.property.type === AST_NODE_TYPES60.Identifier && test.callee.property.name === "isArray" ? "valid-when-true" : null;
|
|
12852
13112
|
};
|
|
12853
13113
|
var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
12854
13114
|
const isValidationReference = (identifier) => {
|
|
12855
13115
|
for (let current = identifier.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
12856
|
-
if ((current.type ===
|
|
13116
|
+
if ((current.type === AST_NODE_TYPES60.BinaryExpression || current.type === AST_NODE_TYPES60.CallExpression || current.type === AST_NODE_TYPES60.UnaryExpression) && bindingValidationPolarity(current, identifier.name) !== null) {
|
|
12857
13117
|
return true;
|
|
12858
13118
|
}
|
|
12859
|
-
if (current.type !==
|
|
13119
|
+
if (current.type !== AST_NODE_TYPES60.UnaryExpression && current.type !== AST_NODE_TYPES60.MemberExpression && current.type !== AST_NODE_TYPES60.CallExpression) {
|
|
12860
13120
|
return false;
|
|
12861
13121
|
}
|
|
12862
13122
|
}
|
|
@@ -12864,7 +13124,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
12864
13124
|
};
|
|
12865
13125
|
const isGuardedUse = (identifier) => {
|
|
12866
13126
|
for (let current = identifier.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
12867
|
-
if (current.type ===
|
|
13127
|
+
if (current.type === AST_NODE_TYPES60.ConditionalExpression) {
|
|
12868
13128
|
const polarity = bindingValidationPolarity(current.test, identifier.name);
|
|
12869
13129
|
if (polarity === "valid-when-true" && nodeWithin2(identifier, current.consequent)) {
|
|
12870
13130
|
return true;
|
|
@@ -12873,7 +13133,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
12873
13133
|
return true;
|
|
12874
13134
|
}
|
|
12875
13135
|
}
|
|
12876
|
-
if (current.type ===
|
|
13136
|
+
if (current.type === AST_NODE_TYPES60.IfStatement) {
|
|
12877
13137
|
const polarity = bindingValidationPolarity(current.test, identifier.name);
|
|
12878
13138
|
if (polarity === "valid-when-true" && nodeWithin2(identifier, current.consequent)) {
|
|
12879
13139
|
return true;
|
|
@@ -12882,14 +13142,14 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
12882
13142
|
return true;
|
|
12883
13143
|
}
|
|
12884
13144
|
}
|
|
12885
|
-
if (current.type ===
|
|
13145
|
+
if (current.type === AST_NODE_TYPES60.FunctionDeclaration || current.type === AST_NODE_TYPES60.FunctionExpression || current.type === AST_NODE_TYPES60.ArrowFunctionExpression) {
|
|
12886
13146
|
return false;
|
|
12887
13147
|
}
|
|
12888
13148
|
}
|
|
12889
13149
|
return false;
|
|
12890
13150
|
};
|
|
12891
13151
|
const declarator = member.parent;
|
|
12892
|
-
if (declarator.type !==
|
|
13152
|
+
if (declarator.type !== AST_NODE_TYPES60.VariableDeclarator || declarator.init !== member || declarator.id.type !== AST_NODE_TYPES60.Identifier || declarator.parent.type !== AST_NODE_TYPES60.VariableDeclaration || declarator.parent.kind !== "const") {
|
|
12893
13153
|
return false;
|
|
12894
13154
|
}
|
|
12895
13155
|
const extracted = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
@@ -12897,7 +13157,7 @@ var isFullyValidatedExtractedBinding = (member, source, context) => {
|
|
|
12897
13157
|
let hasValueUse = false;
|
|
12898
13158
|
for (const reference of extracted.references) {
|
|
12899
13159
|
const identifier = reference.identifier;
|
|
12900
|
-
if (identifier.type !==
|
|
13160
|
+
if (identifier.type !== AST_NODE_TYPES60.Identifier) return false;
|
|
12901
13161
|
if (nodeWithin2(identifier, declarator)) continue;
|
|
12902
13162
|
if (isValidationReference(identifier)) continue;
|
|
12903
13163
|
hasValueUse = true;
|
|
@@ -12910,17 +13170,17 @@ var isGuardTestPosition = (node) => {
|
|
|
12910
13170
|
let parent = current.parent;
|
|
12911
13171
|
while (parent !== void 0 && parent !== null) {
|
|
12912
13172
|
switch (parent.type) {
|
|
12913
|
-
case
|
|
12914
|
-
case
|
|
12915
|
-
case
|
|
13173
|
+
case AST_NODE_TYPES60.UnaryExpression:
|
|
13174
|
+
case AST_NODE_TYPES60.LogicalExpression:
|
|
13175
|
+
case AST_NODE_TYPES60.ChainExpression:
|
|
12916
13176
|
current = parent;
|
|
12917
13177
|
parent = parent.parent;
|
|
12918
13178
|
continue;
|
|
12919
|
-
case
|
|
12920
|
-
case
|
|
12921
|
-
case
|
|
12922
|
-
case
|
|
12923
|
-
case
|
|
13179
|
+
case AST_NODE_TYPES60.IfStatement:
|
|
13180
|
+
case AST_NODE_TYPES60.ConditionalExpression:
|
|
13181
|
+
case AST_NODE_TYPES60.WhileStatement:
|
|
13182
|
+
case AST_NODE_TYPES60.DoWhileStatement:
|
|
13183
|
+
case AST_NODE_TYPES60.ForStatement:
|
|
12924
13184
|
return parent.test === current;
|
|
12925
13185
|
default:
|
|
12926
13186
|
return false;
|
|
@@ -12930,7 +13190,7 @@ var isGuardTestPosition = (node) => {
|
|
|
12930
13190
|
};
|
|
12931
13191
|
var unvalidatedVariableRef = (node, scope, tracked) => {
|
|
12932
13192
|
const unwrapped = unwrap5(node);
|
|
12933
|
-
if (unwrapped === null || unwrapped.type !==
|
|
13193
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES60.Identifier) {
|
|
12934
13194
|
return null;
|
|
12935
13195
|
}
|
|
12936
13196
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -12959,7 +13219,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
12959
13219
|
const localFileTextVariables = /* @__PURE__ */ new Set();
|
|
12960
13220
|
const localFileTextRef = (node, scope) => {
|
|
12961
13221
|
const unwrapped = unwrap5(node);
|
|
12962
|
-
if (unwrapped?.type !==
|
|
13222
|
+
if (unwrapped?.type !== AST_NODE_TYPES60.Identifier) return null;
|
|
12963
13223
|
const variable = findVariable2(scope, unwrapped.name);
|
|
12964
13224
|
return variable !== null && localFileTextVariables.has(variable) ? variable : null;
|
|
12965
13225
|
};
|
|
@@ -13028,7 +13288,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
13028
13288
|
return {
|
|
13029
13289
|
VariableDeclarator(node) {
|
|
13030
13290
|
const scope = context.sourceCode.getScope(node);
|
|
13031
|
-
if (node.id.type ===
|
|
13291
|
+
if (node.id.type === AST_NODE_TYPES60.Identifier) {
|
|
13032
13292
|
const variable = context.sourceCode.getDeclaredVariables(node)[0];
|
|
13033
13293
|
if (variable !== void 0) {
|
|
13034
13294
|
updateLocalFileText(variable, node.init, scope);
|
|
@@ -13036,7 +13296,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
13036
13296
|
trackInitializer(node, scope);
|
|
13037
13297
|
return;
|
|
13038
13298
|
}
|
|
13039
|
-
if (node.id.type ===
|
|
13299
|
+
if (node.id.type === AST_NODE_TYPES60.ObjectPattern || node.id.type === AST_NODE_TYPES60.ArrayPattern) {
|
|
13040
13300
|
if (isRawPayloadSource(
|
|
13041
13301
|
node.init,
|
|
13042
13302
|
(candidate2) => localFileTextRef(candidate2, scope) !== null
|
|
@@ -13053,7 +13313,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
13053
13313
|
},
|
|
13054
13314
|
AssignmentExpression(node) {
|
|
13055
13315
|
const scope = context.sourceCode.getScope(node);
|
|
13056
|
-
if (node.left.type ===
|
|
13316
|
+
if (node.left.type === AST_NODE_TYPES60.Identifier) {
|
|
13057
13317
|
const variable = findVariable2(scope, node.left.name);
|
|
13058
13318
|
if (variable === null) return;
|
|
13059
13319
|
const isLocalText = (candidate2) => localFileTextRef(candidate2, scope) !== null;
|
|
@@ -13067,7 +13327,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
13067
13327
|
}
|
|
13068
13328
|
return;
|
|
13069
13329
|
}
|
|
13070
|
-
if (node.left.type ===
|
|
13330
|
+
if (node.left.type === AST_NODE_TYPES60.ObjectPattern || node.left.type === AST_NODE_TYPES60.ArrayPattern) {
|
|
13071
13331
|
if (isRawPayloadSource(
|
|
13072
13332
|
node.right,
|
|
13073
13333
|
(candidate2) => localFileTextRef(candidate2, scope) !== null
|
|
@@ -13087,15 +13347,15 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
13087
13347
|
}
|
|
13088
13348
|
},
|
|
13089
13349
|
CallExpression(node) {
|
|
13090
|
-
if (node.callee.type !==
|
|
13350
|
+
if (node.callee.type !== AST_NODE_TYPES60.Identifier) return;
|
|
13091
13351
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
13092
13352
|
return;
|
|
13093
13353
|
}
|
|
13094
13354
|
const scope = context.sourceCode.getScope(node);
|
|
13095
13355
|
for (const arg of node.arguments) {
|
|
13096
|
-
if (arg.type ===
|
|
13356
|
+
if (arg.type === AST_NODE_TYPES60.SpreadElement) continue;
|
|
13097
13357
|
const unwrapped = unwrap5(arg);
|
|
13098
|
-
if (unwrapped === null || unwrapped.type !==
|
|
13358
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES60.Identifier) {
|
|
13099
13359
|
continue;
|
|
13100
13360
|
}
|
|
13101
13361
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -13112,14 +13372,14 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
13112
13372
|
(candidate2) => localFileTextRef(candidate2, scope) !== null
|
|
13113
13373
|
)) {
|
|
13114
13374
|
const parent = node.parent;
|
|
13115
|
-
if (parent.type ===
|
|
13375
|
+
if (parent.type === AST_NODE_TYPES60.CallExpression && parent.callee === node && node.property.type === AST_NODE_TYPES60.Identifier && (node.property.name === "parse" || node.property.name === "safeParse" || PROMISE_CHAIN_METHODS.has(node.property.name))) {
|
|
13116
13376
|
return;
|
|
13117
13377
|
}
|
|
13118
13378
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
13119
13379
|
return;
|
|
13120
13380
|
}
|
|
13121
|
-
const variable = obj?.type ===
|
|
13122
|
-
if (variable !== null && obj?.type ===
|
|
13381
|
+
const variable = obj?.type === AST_NODE_TYPES60.Identifier ? unvalidatedVariableRef(obj, scope, unvalidatedVariables) : null;
|
|
13382
|
+
if (variable !== null && obj?.type === AST_NODE_TYPES60.Identifier) {
|
|
13123
13383
|
if (isUseWithinValidatedBranch(node, obj.name)) {
|
|
13124
13384
|
return;
|
|
13125
13385
|
}
|
|
@@ -13139,7 +13399,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
13139
13399
|
});
|
|
13140
13400
|
|
|
13141
13401
|
// src/rules/prefer-shared-zod-enum.ts
|
|
13142
|
-
import { AST_NODE_TYPES as
|
|
13402
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES61 } from "@typescript-eslint/utils";
|
|
13143
13403
|
var PREFER_SHARED_ZOD_ENUM_DOCUMENTATION = {
|
|
13144
13404
|
summary: "Give literal Zod enum domains one reusable module-level schema.",
|
|
13145
13405
|
rationale: "Inline or repeated literal domains hide a reusable contract and allow equivalent fields to drift independently.",
|
|
@@ -13153,24 +13413,24 @@ var PREFER_SHARED_ZOD_ENUM_DOCUMENTATION = {
|
|
|
13153
13413
|
};
|
|
13154
13414
|
function literalDomain(node) {
|
|
13155
13415
|
const [argument] = node.arguments;
|
|
13156
|
-
if (argument?.type !==
|
|
13416
|
+
if (argument?.type !== AST_NODE_TYPES61.ArrayExpression || argument.elements.length < 2) return null;
|
|
13157
13417
|
const values = [];
|
|
13158
13418
|
for (const element of argument.elements) {
|
|
13159
|
-
if (element?.type !==
|
|
13419
|
+
if (element?.type !== AST_NODE_TYPES61.Literal || typeof element.value !== "string") return null;
|
|
13160
13420
|
values.push(element.value);
|
|
13161
13421
|
}
|
|
13162
13422
|
return values;
|
|
13163
13423
|
}
|
|
13164
13424
|
function isModuleLevelNamedSchema(node) {
|
|
13165
13425
|
let current = node;
|
|
13166
|
-
while (current.parent?.type ===
|
|
13426
|
+
while (current.parent?.type === AST_NODE_TYPES61.MemberExpression && current.parent.object === current) {
|
|
13167
13427
|
current = current.parent;
|
|
13168
|
-
if (current.parent?.type ===
|
|
13428
|
+
if (current.parent?.type === AST_NODE_TYPES61.CallExpression && current.parent.callee === current) current = current.parent;
|
|
13169
13429
|
}
|
|
13170
13430
|
const declarator = current.parent;
|
|
13171
|
-
if (declarator?.type !==
|
|
13431
|
+
if (declarator?.type !== AST_NODE_TYPES61.VariableDeclarator || declarator.init !== current || declarator.id.type !== AST_NODE_TYPES61.Identifier || declarator.parent.type !== AST_NODE_TYPES61.VariableDeclaration) return false;
|
|
13172
13432
|
const declarationParent = declarator.parent.parent;
|
|
13173
|
-
return declarationParent.type ===
|
|
13433
|
+
return declarationParent.type === AST_NODE_TYPES61.Program || declarationParent.type === AST_NODE_TYPES61.ExportNamedDeclaration && declarationParent.parent.type === AST_NODE_TYPES61.Program;
|
|
13174
13434
|
}
|
|
13175
13435
|
var prefer_shared_zod_enum_default = createRule({
|
|
13176
13436
|
name: "prefer-shared-zod-enum",
|
|
@@ -13192,11 +13452,11 @@ var prefer_shared_zod_enum_default = createRule({
|
|
|
13192
13452
|
ImportDeclaration(node) {
|
|
13193
13453
|
if (!isZodModule(node.source.value)) return;
|
|
13194
13454
|
for (const specifier of node.specifiers) {
|
|
13195
|
-
if (specifier.type ===
|
|
13455
|
+
if (specifier.type === AST_NODE_TYPES61.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES61.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES61.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES61.Identifier && specifier.imported.name === "z") zodBindings.add(specifier.local.name);
|
|
13196
13456
|
}
|
|
13197
13457
|
},
|
|
13198
13458
|
CallExpression(node) {
|
|
13199
|
-
if (node.callee.type !==
|
|
13459
|
+
if (node.callee.type !== AST_NODE_TYPES61.MemberExpression || node.callee.computed || node.callee.object.type !== AST_NODE_TYPES61.Identifier || !zodBindings.has(node.callee.object.name) || node.callee.property.type !== AST_NODE_TYPES61.Identifier || node.callee.property.name !== "enum") return;
|
|
13200
13460
|
const domain = literalDomain(node);
|
|
13201
13461
|
if (domain === null) return;
|
|
13202
13462
|
const key = JSON.stringify(domain);
|
|
@@ -13210,7 +13470,7 @@ var prefer_shared_zod_enum_default = createRule({
|
|
|
13210
13470
|
});
|
|
13211
13471
|
|
|
13212
13472
|
// src/rules/prefer-switch-for-repeated-equality.ts
|
|
13213
|
-
import { AST_NODE_TYPES as
|
|
13473
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES62 } from "@typescript-eslint/utils";
|
|
13214
13474
|
var PREFER_SWITCH_FOR_REPEATED_EQUALITY_DOCUMENTATION = {
|
|
13215
13475
|
summary: "Prefer switch over long if/else-if chains that compare one value for strict equality.",
|
|
13216
13476
|
rationale: "A switch makes finite dispatch cases visually uniform and easier to extend without duplicating the discriminant.",
|
|
@@ -13227,17 +13487,17 @@ var PREFER_SWITCH_FOR_REPEATED_EQUALITY_DOCUMENTATION = {
|
|
|
13227
13487
|
]
|
|
13228
13488
|
};
|
|
13229
13489
|
function discriminantText(sourceCode, test) {
|
|
13230
|
-
if (test.type !==
|
|
13490
|
+
if (test.type !== AST_NODE_TYPES62.BinaryExpression || test.operator !== "===") return null;
|
|
13231
13491
|
const leftIsCase = isCaseValue(test.left);
|
|
13232
13492
|
const rightIsCase = isCaseValue(test.right);
|
|
13233
13493
|
if (leftIsCase === rightIsCase) return null;
|
|
13234
13494
|
return sourceCode.getText(leftIsCase ? test.right : test.left);
|
|
13235
13495
|
}
|
|
13236
13496
|
function isCaseValue(node) {
|
|
13237
|
-
if (node.type ===
|
|
13238
|
-
if (node.type ===
|
|
13239
|
-
if (node.type !==
|
|
13240
|
-
return node.property.type ===
|
|
13497
|
+
if (node.type === AST_NODE_TYPES62.Literal) return true;
|
|
13498
|
+
if (node.type === AST_NODE_TYPES62.Identifier) return /^[A-Z][A-Z0-9_]*$/u.test(node.name);
|
|
13499
|
+
if (node.type !== AST_NODE_TYPES62.MemberExpression || node.computed) return false;
|
|
13500
|
+
return node.property.type === AST_NODE_TYPES62.Identifier && (node.object.type === AST_NODE_TYPES62.Identifier || isCaseValue(node.object));
|
|
13241
13501
|
}
|
|
13242
13502
|
var prefer_switch_for_repeated_equality_default = createRule({
|
|
13243
13503
|
name: "prefer-switch-for-repeated-equality",
|
|
@@ -13254,12 +13514,12 @@ var prefer_switch_for_repeated_equality_default = createRule({
|
|
|
13254
13514
|
create(context) {
|
|
13255
13515
|
return {
|
|
13256
13516
|
IfStatement(node) {
|
|
13257
|
-
if (node.parent.type ===
|
|
13517
|
+
if (node.parent.type === AST_NODE_TYPES62.IfStatement && node.parent.alternate === node) return;
|
|
13258
13518
|
const first = discriminantText(context.sourceCode, node.test);
|
|
13259
13519
|
if (first === null) return;
|
|
13260
13520
|
let count = 1;
|
|
13261
13521
|
let current = node.alternate;
|
|
13262
|
-
while (current?.type ===
|
|
13522
|
+
while (current?.type === AST_NODE_TYPES62.IfStatement) {
|
|
13263
13523
|
if (discriminantText(context.sourceCode, current.test) !== first) return;
|
|
13264
13524
|
count += 1;
|
|
13265
13525
|
current = current.alternate;
|
|
@@ -13273,7 +13533,7 @@ var prefer_switch_for_repeated_equality_default = createRule({
|
|
|
13273
13533
|
});
|
|
13274
13534
|
|
|
13275
13535
|
// src/rules/prefer-semantic-colors.ts
|
|
13276
|
-
import { AST_NODE_TYPES as
|
|
13536
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES63 } from "@typescript-eslint/utils";
|
|
13277
13537
|
import { existsSync, readdirSync, readFileSync } from "fs";
|
|
13278
13538
|
import { dirname, join, parse } from "path";
|
|
13279
13539
|
|
|
@@ -13385,7 +13645,7 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
13385
13645
|
var isInsideSvg = (node) => {
|
|
13386
13646
|
let current = node.parent;
|
|
13387
13647
|
while (current !== void 0 && current !== null) {
|
|
13388
|
-
if (current.type ===
|
|
13648
|
+
if (current.type === AST_NODE_TYPES63.JSXElement) {
|
|
13389
13649
|
const name = jsxElementName(current);
|
|
13390
13650
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
13391
13651
|
}
|
|
@@ -13395,8 +13655,8 @@ var isInsideSvg = (node) => {
|
|
|
13395
13655
|
};
|
|
13396
13656
|
function jsxElementName(node) {
|
|
13397
13657
|
const name = node.openingElement.name;
|
|
13398
|
-
if (name.type ===
|
|
13399
|
-
if (name.type ===
|
|
13658
|
+
if (name.type === AST_NODE_TYPES63.JSXIdentifier) return name.name;
|
|
13659
|
+
if (name.type === AST_NODE_TYPES63.JSXMemberExpression && name.property.type === AST_NODE_TYPES63.JSXIdentifier) {
|
|
13400
13660
|
return name.property.name;
|
|
13401
13661
|
}
|
|
13402
13662
|
return null;
|
|
@@ -13422,7 +13682,7 @@ function isSvgLikeElementName(name) {
|
|
|
13422
13682
|
var isInsideIconFactoryPath = (node) => {
|
|
13423
13683
|
let current = node.parent;
|
|
13424
13684
|
while (current !== void 0 && current !== null) {
|
|
13425
|
-
if (current.type ===
|
|
13685
|
+
if (current.type === AST_NODE_TYPES63.Property && propName(current.key) === "path" && current.parent.type === AST_NODE_TYPES63.ObjectExpression && current.parent.parent.type === AST_NODE_TYPES63.CallExpression && current.parent.parent.callee.type === AST_NODE_TYPES63.Identifier && current.parent.parent.callee.name === "createIcon") {
|
|
13426
13686
|
return true;
|
|
13427
13687
|
}
|
|
13428
13688
|
current = current.parent;
|
|
@@ -13556,12 +13816,12 @@ var expandWorkspaceGlob = (root, glob) => {
|
|
|
13556
13816
|
return readdirSync(parent, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => join(parent, entry.name));
|
|
13557
13817
|
};
|
|
13558
13818
|
var propName = (key) => {
|
|
13559
|
-
if (key.type ===
|
|
13560
|
-
if (key.type ===
|
|
13819
|
+
if (key.type === AST_NODE_TYPES63.Identifier) return key.name;
|
|
13820
|
+
if (key.type === AST_NODE_TYPES63.Literal && typeof key.value === "string") return key.value;
|
|
13561
13821
|
return null;
|
|
13562
13822
|
};
|
|
13563
13823
|
var staticallyImportsEmailOrPdfRenderer = (program) => program.body.some((statement) => {
|
|
13564
|
-
if (statement.type !==
|
|
13824
|
+
if (statement.type !== AST_NODE_TYPES63.ImportDeclaration && statement.type !== AST_NODE_TYPES63.ExportNamedDeclaration && statement.type !== AST_NODE_TYPES63.ExportAllDeclaration) {
|
|
13565
13825
|
return false;
|
|
13566
13826
|
}
|
|
13567
13827
|
return statement.source !== null && typeof statement.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(statement.source.value);
|
|
@@ -13614,27 +13874,27 @@ var prefer_semantic_colors_default = createRule({
|
|
|
13614
13874
|
const checkClassNode = (node) => {
|
|
13615
13875
|
if (node === null) return;
|
|
13616
13876
|
switch (node.type) {
|
|
13617
|
-
case
|
|
13877
|
+
case AST_NODE_TYPES63.Literal:
|
|
13618
13878
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
13619
13879
|
break;
|
|
13620
|
-
case
|
|
13880
|
+
case AST_NODE_TYPES63.TemplateLiteral:
|
|
13621
13881
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
13622
13882
|
break;
|
|
13623
|
-
case
|
|
13883
|
+
case AST_NODE_TYPES63.ArrayExpression:
|
|
13624
13884
|
for (const element of node.elements) {
|
|
13625
|
-
if (element !== null && element.type !==
|
|
13885
|
+
if (element !== null && element.type !== AST_NODE_TYPES63.SpreadElement) checkClassNode(element);
|
|
13626
13886
|
}
|
|
13627
13887
|
break;
|
|
13628
|
-
case
|
|
13888
|
+
case AST_NODE_TYPES63.ObjectExpression:
|
|
13629
13889
|
for (const property of node.properties) {
|
|
13630
|
-
if (property.type ===
|
|
13890
|
+
if (property.type === AST_NODE_TYPES63.Property) checkClassNode(property.value);
|
|
13631
13891
|
}
|
|
13632
13892
|
break;
|
|
13633
|
-
case
|
|
13893
|
+
case AST_NODE_TYPES63.ConditionalExpression:
|
|
13634
13894
|
checkClassNode(node.consequent);
|
|
13635
13895
|
checkClassNode(node.alternate);
|
|
13636
13896
|
break;
|
|
13637
|
-
case
|
|
13897
|
+
case AST_NODE_TYPES63.LogicalExpression:
|
|
13638
13898
|
checkClassNode(node.right);
|
|
13639
13899
|
break;
|
|
13640
13900
|
default:
|
|
@@ -13642,32 +13902,32 @@ var prefer_semantic_colors_default = createRule({
|
|
|
13642
13902
|
}
|
|
13643
13903
|
};
|
|
13644
13904
|
const checkColorValueNode = (node) => {
|
|
13645
|
-
if (node.type ===
|
|
13905
|
+
if (node.type === AST_NODE_TYPES63.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value) && !CSS_VAR_REFERENCE_RE.test(node.value)) {
|
|
13646
13906
|
report2(node, "inlineColor", { value: node.value });
|
|
13647
13907
|
}
|
|
13648
13908
|
};
|
|
13649
13909
|
return {
|
|
13650
13910
|
"JSXAttribute[name.name='className']"(node) {
|
|
13651
13911
|
if (node.value === null) return;
|
|
13652
|
-
if (node.value.type ===
|
|
13653
|
-
else if (node.value.type ===
|
|
13654
|
-
if (node.value.expression.type !==
|
|
13912
|
+
if (node.value.type === AST_NODE_TYPES63.Literal) checkClassNode(node.value);
|
|
13913
|
+
else if (node.value.type === AST_NODE_TYPES63.JSXExpressionContainer) {
|
|
13914
|
+
if (node.value.expression.type !== AST_NODE_TYPES63.JSXEmptyExpression) {
|
|
13655
13915
|
checkClassNode(node.value.expression);
|
|
13656
13916
|
}
|
|
13657
13917
|
}
|
|
13658
13918
|
},
|
|
13659
13919
|
CallExpression(node) {
|
|
13660
|
-
if (node.callee.type ===
|
|
13920
|
+
if (node.callee.type === AST_NODE_TYPES63.Identifier && node.callee.name === "require" && node.arguments[0]?.type === AST_NODE_TYPES63.Literal && typeof node.arguments[0].value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.arguments[0].value)) {
|
|
13661
13921
|
importsEmailOrPdfRenderer = true;
|
|
13662
13922
|
}
|
|
13663
|
-
if (node.callee.type ===
|
|
13923
|
+
if (node.callee.type === AST_NODE_TYPES63.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
13664
13924
|
for (const arg of node.arguments) {
|
|
13665
|
-
if (arg.type !==
|
|
13925
|
+
if (arg.type !== AST_NODE_TYPES63.SpreadElement) checkClassNode(arg);
|
|
13666
13926
|
}
|
|
13667
13927
|
}
|
|
13668
13928
|
},
|
|
13669
13929
|
VariableDeclarator(node) {
|
|
13670
|
-
if (node.id.type ===
|
|
13930
|
+
if (node.id.type === AST_NODE_TYPES63.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
13671
13931
|
checkClassNode(node.init);
|
|
13672
13932
|
}
|
|
13673
13933
|
},
|
|
@@ -13677,9 +13937,9 @@ var prefer_semantic_colors_default = createRule({
|
|
|
13677
13937
|
},
|
|
13678
13938
|
// SVG artwork colors are exempt; component presentation colors still report.
|
|
13679
13939
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
13680
|
-
if (node.value?.type !==
|
|
13940
|
+
if (node.value?.type !== AST_NODE_TYPES63.Literal) return;
|
|
13681
13941
|
const owner = node.parent.name;
|
|
13682
|
-
if (owner.type ===
|
|
13942
|
+
if (owner.type === AST_NODE_TYPES63.JSXIdentifier && SVG_SHAPE_PRIMITIVES.has(owner.name)) {
|
|
13683
13943
|
return;
|
|
13684
13944
|
}
|
|
13685
13945
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
@@ -13693,7 +13953,7 @@ var prefer_semantic_colors_default = createRule({
|
|
|
13693
13953
|
if (name !== null && STYLE_COLOR_PROPS.has(name)) checkColorValueNode(node.value);
|
|
13694
13954
|
},
|
|
13695
13955
|
ImportExpression(node) {
|
|
13696
|
-
if (node.source.type ===
|
|
13956
|
+
if (node.source.type === AST_NODE_TYPES63.Literal && typeof node.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.source.value)) {
|
|
13697
13957
|
importsEmailOrPdfRenderer = true;
|
|
13698
13958
|
}
|
|
13699
13959
|
},
|
|
@@ -13895,7 +14155,7 @@ var prefer_server_actions_default = createRule({
|
|
|
13895
14155
|
});
|
|
13896
14156
|
|
|
13897
14157
|
// src/rules/prefer-whole-object-assertion.ts
|
|
13898
|
-
import { AST_NODE_TYPES as
|
|
14158
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES64 } from "@typescript-eslint/utils";
|
|
13899
14159
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
13900
14160
|
var SYNTHETIC_LITERAL_MATCHERS = /* @__PURE__ */ new Map([
|
|
13901
14161
|
["toBeNull", "null"],
|
|
@@ -13920,11 +14180,11 @@ var PREFER_WHOLE_OBJECT_ASSERTION_DOCUMENTATION = {
|
|
|
13920
14180
|
};
|
|
13921
14181
|
function literalText(node, getText) {
|
|
13922
14182
|
switch (node.type) {
|
|
13923
|
-
case
|
|
14183
|
+
case AST_NODE_TYPES64.Literal:
|
|
13924
14184
|
return "regex" in node ? null : getText(node);
|
|
13925
|
-
case
|
|
14185
|
+
case AST_NODE_TYPES64.TemplateLiteral:
|
|
13926
14186
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
13927
|
-
case
|
|
14187
|
+
case AST_NODE_TYPES64.UnaryExpression:
|
|
13928
14188
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
13929
14189
|
default:
|
|
13930
14190
|
return null;
|
|
@@ -13932,15 +14192,15 @@ function literalText(node, getText) {
|
|
|
13932
14192
|
}
|
|
13933
14193
|
function isPureReceiver(node) {
|
|
13934
14194
|
switch (node.type) {
|
|
13935
|
-
case
|
|
13936
|
-
case
|
|
14195
|
+
case AST_NODE_TYPES64.Identifier:
|
|
14196
|
+
case AST_NODE_TYPES64.ThisExpression:
|
|
13937
14197
|
return true;
|
|
13938
|
-
case
|
|
14198
|
+
case AST_NODE_TYPES64.MemberExpression:
|
|
13939
14199
|
if (node.optional) {
|
|
13940
14200
|
return false;
|
|
13941
14201
|
}
|
|
13942
14202
|
if (node.computed) {
|
|
13943
|
-
return node.property.type ===
|
|
14203
|
+
return node.property.type === AST_NODE_TYPES64.Literal && isPureReceiver(node.object);
|
|
13944
14204
|
}
|
|
13945
14205
|
return isPureReceiver(node.object);
|
|
13946
14206
|
default:
|
|
@@ -13948,7 +14208,7 @@ function isPureReceiver(node) {
|
|
|
13948
14208
|
}
|
|
13949
14209
|
}
|
|
13950
14210
|
function literalIndex(node) {
|
|
13951
|
-
if (node.type !==
|
|
14211
|
+
if (node.type !== AST_NODE_TYPES64.Literal || typeof node.value !== "number") {
|
|
13952
14212
|
return null;
|
|
13953
14213
|
}
|
|
13954
14214
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
@@ -13956,8 +14216,8 @@ function literalIndex(node) {
|
|
|
13956
14216
|
function propertyAccess(node) {
|
|
13957
14217
|
const path = [];
|
|
13958
14218
|
let current = node;
|
|
13959
|
-
while (current.type ===
|
|
13960
|
-
if (current.property.type !==
|
|
14219
|
+
while (current.type === AST_NODE_TYPES64.MemberExpression && !current.computed && !current.optional) {
|
|
14220
|
+
if (current.property.type !== AST_NODE_TYPES64.Identifier || COLLECTION_PROPERTIES.has(current.property.name) || LITERAL_KEY_HAZARDS.has(current.property.name)) return null;
|
|
13961
14221
|
path.unshift(current.property.name);
|
|
13962
14222
|
current = current.object;
|
|
13963
14223
|
}
|
|
@@ -13985,24 +14245,24 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
13985
14245
|
}
|
|
13986
14246
|
const { sourceCode } = context;
|
|
13987
14247
|
function parseAssertion(statement) {
|
|
13988
|
-
if (statement.type !==
|
|
14248
|
+
if (statement.type !== AST_NODE_TYPES64.ExpressionStatement) {
|
|
13989
14249
|
return null;
|
|
13990
14250
|
}
|
|
13991
14251
|
const call = statement.expression;
|
|
13992
|
-
if (call.type !==
|
|
14252
|
+
if (call.type !== AST_NODE_TYPES64.CallExpression) {
|
|
13993
14253
|
return null;
|
|
13994
14254
|
}
|
|
13995
14255
|
const callee = call.callee;
|
|
13996
|
-
if (callee.type !==
|
|
14256
|
+
if (callee.type !== AST_NODE_TYPES64.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES64.Identifier) {
|
|
13997
14257
|
return null;
|
|
13998
14258
|
}
|
|
13999
14259
|
const matcher = callee.property.name;
|
|
14000
14260
|
const expectCall = callee.object;
|
|
14001
|
-
if (expectCall.type !==
|
|
14261
|
+
if (expectCall.type !== AST_NODE_TYPES64.CallExpression || expectCall.callee.type !== AST_NODE_TYPES64.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
14002
14262
|
return null;
|
|
14003
14263
|
}
|
|
14004
14264
|
const actual = expectCall.arguments[0];
|
|
14005
|
-
if (actual === void 0 || actual.type !==
|
|
14265
|
+
if (actual === void 0 || actual.type !== AST_NODE_TYPES64.MemberExpression || actual.optional) {
|
|
14006
14266
|
return null;
|
|
14007
14267
|
}
|
|
14008
14268
|
if (!isPureReceiver(actual.object)) {
|
|
@@ -14031,7 +14291,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
14031
14291
|
return null;
|
|
14032
14292
|
}
|
|
14033
14293
|
const expected = call.arguments[0];
|
|
14034
|
-
if (call.arguments.length !== 1 || expected === void 0 || expected.type ===
|
|
14294
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === AST_NODE_TYPES64.SpreadElement) {
|
|
14035
14295
|
return null;
|
|
14036
14296
|
}
|
|
14037
14297
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
@@ -14172,7 +14432,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
14172
14432
|
});
|
|
14173
14433
|
|
|
14174
14434
|
// src/rules/repeated-static-call-cases.ts
|
|
14175
|
-
import { AST_NODE_TYPES as
|
|
14435
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES65, ASTUtils as ASTUtils19 } from "@typescript-eslint/utils";
|
|
14176
14436
|
var REPEATED_STATIC_CALL_CASES_DOCUMENTATION = {
|
|
14177
14437
|
summary: "Report three or more consecutive literal call assertions that should be independently named test cases.",
|
|
14178
14438
|
rationale: "Copy-pasted cases obscure the input table and stop later cases from being reported after the first failure.",
|
|
@@ -14193,67 +14453,67 @@ var EXPECT_MODIFIERS = /* @__PURE__ */ new Set(["not", "rejects", "resolves"]);
|
|
|
14193
14453
|
var SNAPSHOT_MATCHERS = /snapshot/iu;
|
|
14194
14454
|
var MIN_CASES2 = 3;
|
|
14195
14455
|
function staticMemberName5(node) {
|
|
14196
|
-
if (!node.computed && node.property.type ===
|
|
14197
|
-
if (node.computed && node.property.type ===
|
|
14456
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES65.Identifier) return node.property.name;
|
|
14457
|
+
if (node.computed && node.property.type === AST_NODE_TYPES65.Literal && typeof node.property.value === "string") return node.property.value;
|
|
14198
14458
|
return null;
|
|
14199
14459
|
}
|
|
14200
14460
|
function importedName6(identifier, context, modules) {
|
|
14201
14461
|
const variable = ASTUtils19.findVariable(context.sourceCode.getScope(identifier), identifier.name);
|
|
14202
14462
|
if (variable === null || variable.defs.length === 0) return identifier.name;
|
|
14203
14463
|
for (const definition of variable.defs) {
|
|
14204
|
-
if (definition.node.type !==
|
|
14464
|
+
if (definition.node.type !== AST_NODE_TYPES65.ImportSpecifier) continue;
|
|
14205
14465
|
const declaration = definition.node.parent;
|
|
14206
|
-
if (declaration.type !==
|
|
14466
|
+
if (declaration.type !== AST_NODE_TYPES65.ImportDeclaration || typeof declaration.source.value !== "string" || !modules.has(declaration.source.value)) continue;
|
|
14207
14467
|
const imported = definition.node.imported;
|
|
14208
|
-
return imported.type ===
|
|
14468
|
+
return imported.type === AST_NODE_TYPES65.Identifier ? imported.name : String(imported.value);
|
|
14209
14469
|
}
|
|
14210
14470
|
return null;
|
|
14211
14471
|
}
|
|
14212
14472
|
function isDirectTestCallback2(node, context) {
|
|
14213
|
-
if (node.type !==
|
|
14473
|
+
if (node.type !== AST_NODE_TYPES65.ArrowFunctionExpression && node.type !== AST_NODE_TYPES65.FunctionExpression) return false;
|
|
14214
14474
|
const call = node.parent;
|
|
14215
|
-
if (call?.type !==
|
|
14475
|
+
if (call?.type !== AST_NODE_TYPES65.CallExpression || !call.arguments.includes(node)) return false;
|
|
14216
14476
|
const root = testRoot2(call.callee);
|
|
14217
14477
|
return root !== null && TEST_NAMES2.has(importedName6(root, context, TEST_MODULES4) ?? "");
|
|
14218
14478
|
}
|
|
14219
14479
|
function testRoot2(callee) {
|
|
14220
|
-
if (callee.type ===
|
|
14221
|
-
if (callee.type !==
|
|
14480
|
+
if (callee.type === AST_NODE_TYPES65.Identifier) return callee;
|
|
14481
|
+
if (callee.type !== AST_NODE_TYPES65.MemberExpression) return null;
|
|
14222
14482
|
const modifier = staticMemberName5(callee);
|
|
14223
14483
|
return modifier !== null && TEST_MODIFIERS4.has(modifier) ? testRoot2(callee.object) : null;
|
|
14224
14484
|
}
|
|
14225
14485
|
function isStatic(node) {
|
|
14226
|
-
if (node.type ===
|
|
14486
|
+
if (node.type === AST_NODE_TYPES65.TSAsExpression || node.type === AST_NODE_TYPES65.TSTypeAssertion || node.type === AST_NODE_TYPES65.TSSatisfiesExpression || node.type === AST_NODE_TYPES65.TSNonNullExpression) return isStatic(node.expression);
|
|
14227
14487
|
switch (node.type) {
|
|
14228
|
-
case
|
|
14488
|
+
case AST_NODE_TYPES65.Literal:
|
|
14229
14489
|
return true;
|
|
14230
|
-
case
|
|
14490
|
+
case AST_NODE_TYPES65.TemplateLiteral:
|
|
14231
14491
|
return node.expressions.length === 0;
|
|
14232
|
-
case
|
|
14492
|
+
case AST_NODE_TYPES65.UnaryExpression:
|
|
14233
14493
|
return (node.operator === "+" || node.operator === "-") && isStatic(node.argument);
|
|
14234
|
-
case
|
|
14235
|
-
return node.elements.every((item) => item !== null && item.type !==
|
|
14236
|
-
case
|
|
14237
|
-
return node.properties.every((property) => property.type ===
|
|
14494
|
+
case AST_NODE_TYPES65.ArrayExpression:
|
|
14495
|
+
return node.elements.every((item) => item !== null && item.type !== AST_NODE_TYPES65.SpreadElement && isStatic(item));
|
|
14496
|
+
case AST_NODE_TYPES65.ObjectExpression:
|
|
14497
|
+
return node.properties.every((property) => property.type === AST_NODE_TYPES65.Property && !property.computed && property.kind === "init" && property.value.type !== AST_NODE_TYPES65.AssignmentPattern && isStatic(property.value));
|
|
14238
14498
|
default:
|
|
14239
14499
|
return false;
|
|
14240
14500
|
}
|
|
14241
14501
|
}
|
|
14242
14502
|
function staticShape(node) {
|
|
14243
|
-
if (node.type ===
|
|
14503
|
+
if (node.type === AST_NODE_TYPES65.TSAsExpression || node.type === AST_NODE_TYPES65.TSTypeAssertion || node.type === AST_NODE_TYPES65.TSSatisfiesExpression || node.type === AST_NODE_TYPES65.TSNonNullExpression) return staticShape(node.expression);
|
|
14244
14504
|
switch (node.type) {
|
|
14245
|
-
case
|
|
14505
|
+
case AST_NODE_TYPES65.Literal:
|
|
14246
14506
|
return `literal:${typeof node.value}`;
|
|
14247
|
-
case
|
|
14507
|
+
case AST_NODE_TYPES65.TemplateLiteral:
|
|
14248
14508
|
return "template";
|
|
14249
|
-
case
|
|
14509
|
+
case AST_NODE_TYPES65.UnaryExpression:
|
|
14250
14510
|
return `unary:${node.operator}:${staticShape(node.argument)}`;
|
|
14251
|
-
case
|
|
14252
|
-
return `array(${node.elements.map((item) => item === null || item.type ===
|
|
14253
|
-
case
|
|
14511
|
+
case AST_NODE_TYPES65.ArrayExpression:
|
|
14512
|
+
return `array(${node.elements.map((item) => item === null || item.type === AST_NODE_TYPES65.SpreadElement ? "invalid" : staticShape(item)).join(",")})`;
|
|
14513
|
+
case AST_NODE_TYPES65.ObjectExpression:
|
|
14254
14514
|
return `object(${node.properties.map((property) => {
|
|
14255
|
-
if (property.type !==
|
|
14256
|
-
const key = property.key.type ===
|
|
14515
|
+
if (property.type !== AST_NODE_TYPES65.Property || property.computed || property.value.type === AST_NODE_TYPES65.AssignmentPattern) return "invalid";
|
|
14516
|
+
const key = property.key.type === AST_NODE_TYPES65.Identifier ? property.key.name : String(property.key.value);
|
|
14257
14517
|
return `${key}:${staticShape(property.value)}`;
|
|
14258
14518
|
}).join(",")})`;
|
|
14259
14519
|
default:
|
|
@@ -14261,16 +14521,16 @@ function staticShape(node) {
|
|
|
14261
14521
|
}
|
|
14262
14522
|
}
|
|
14263
14523
|
function assertionShape(statement, context) {
|
|
14264
|
-
if (statement.type !==
|
|
14524
|
+
if (statement.type !== AST_NODE_TYPES65.ExpressionStatement || statement.expression.type !== AST_NODE_TYPES65.CallExpression) return null;
|
|
14265
14525
|
const matcherCall = statement.expression;
|
|
14266
|
-
if (matcherCall.callee.type !==
|
|
14526
|
+
if (matcherCall.callee.type !== AST_NODE_TYPES65.MemberExpression || matcherCall.callee.computed || matcherCall.callee.property.type !== AST_NODE_TYPES65.Identifier || matcherCall.arguments.length !== 1) return null;
|
|
14267
14527
|
const matcher = matcherCall.callee.property.name;
|
|
14268
14528
|
if (SNAPSHOT_MATCHERS.test(matcher)) return null;
|
|
14269
14529
|
const chain = expectCallFromMatcher(matcherCall.callee);
|
|
14270
|
-
if (chain === null || chain.call.callee.type !==
|
|
14530
|
+
if (chain === null || chain.call.callee.type !== AST_NODE_TYPES65.Identifier || importedName6(chain.call.callee, context, ASSERTION_MODULES3) !== "expect" || chain.call.arguments.length !== 1) return null;
|
|
14271
14531
|
const observed = chain.call.arguments[0];
|
|
14272
14532
|
const expected = matcherCall.arguments[0];
|
|
14273
|
-
if (observed?.type !==
|
|
14533
|
+
if (observed?.type !== AST_NODE_TYPES65.CallExpression || observed.callee.type !== AST_NODE_TYPES65.Identifier || observed.arguments.length === 0 || observed.arguments.some((arg) => arg.type === AST_NODE_TYPES65.SpreadElement || !isStatic(arg)) || expected?.type === AST_NODE_TYPES65.SpreadElement || expected === void 0 || !isStatic(expected)) return null;
|
|
14274
14534
|
const skeleton = `${observed.callee.name}/${observed.arguments.map((item) => staticShape(item)).join(",")}/${chain.modifiers.join(".")}/${matcher}/${staticShape(expected)}`;
|
|
14275
14535
|
const values = [...observed.arguments, expected].map((item) => context.sourceCode.getText(item)).join("\0");
|
|
14276
14536
|
return { statement, skeleton, values };
|
|
@@ -14278,13 +14538,13 @@ function assertionShape(statement, context) {
|
|
|
14278
14538
|
function expectCallFromMatcher(node) {
|
|
14279
14539
|
const modifiers = [];
|
|
14280
14540
|
let receiver = node.object;
|
|
14281
|
-
while (receiver.type ===
|
|
14541
|
+
while (receiver.type === AST_NODE_TYPES65.MemberExpression) {
|
|
14282
14542
|
const modifier = staticMemberName5(receiver);
|
|
14283
14543
|
if (modifier === null || !EXPECT_MODIFIERS.has(modifier)) return null;
|
|
14284
14544
|
modifiers.unshift(modifier);
|
|
14285
14545
|
receiver = receiver.object;
|
|
14286
14546
|
}
|
|
14287
|
-
return receiver.type ===
|
|
14547
|
+
return receiver.type === AST_NODE_TYPES65.CallExpression ? { call: receiver, modifiers } : null;
|
|
14288
14548
|
}
|
|
14289
14549
|
var repeated_static_call_cases_default = createRule({
|
|
14290
14550
|
name: "repeated-static-call-cases",
|
|
@@ -14304,7 +14564,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
14304
14564
|
return {
|
|
14305
14565
|
"CallExpression > ArrowFunctionExpression, CallExpression > FunctionExpression"(node) {
|
|
14306
14566
|
const call = node.parent;
|
|
14307
|
-
if (call?.type ===
|
|
14567
|
+
if (call?.type === AST_NODE_TYPES65.CallExpression) {
|
|
14308
14568
|
const duplicate = duplicateTestBodyCandidate(call, sourceCode);
|
|
14309
14569
|
if (duplicate !== null && duplicate.body === node) {
|
|
14310
14570
|
const groups = duplicateGroups.get(duplicate.container) ?? /* @__PURE__ */ new Map();
|
|
@@ -14314,7 +14574,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
14314
14574
|
duplicateGroups.set(duplicate.container, groups);
|
|
14315
14575
|
}
|
|
14316
14576
|
}
|
|
14317
|
-
if (!isDirectTestCallback2(node, context) || node.body.type !==
|
|
14577
|
+
if (!isDirectTestCallback2(node, context) || node.body.type !== AST_NODE_TYPES65.BlockStatement) return;
|
|
14318
14578
|
let run = [];
|
|
14319
14579
|
const flush = () => {
|
|
14320
14580
|
if (run.length >= MIN_CASES2 && new Set(run.map((item) => item.values)).size > 1) {
|
|
@@ -14355,7 +14615,7 @@ var repeated_static_call_cases_default = createRule({
|
|
|
14355
14615
|
});
|
|
14356
14616
|
|
|
14357
14617
|
// src/rules/prefer-zod-infer.ts
|
|
14358
|
-
import { AST_NODE_TYPES as
|
|
14618
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES66 } from "@typescript-eslint/utils";
|
|
14359
14619
|
var PREFER_ZOD_INFER_DOCUMENTATION = {
|
|
14360
14620
|
summary: "Derive a type from its Zod schema with `z.infer` instead of hand-writing a twin declaration beside it.",
|
|
14361
14621
|
rationale: "A derived type stays synchronized when the runtime schema changes.",
|
|
@@ -14408,47 +14668,47 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
14408
14668
|
"Schema"
|
|
14409
14669
|
]);
|
|
14410
14670
|
var LEAF_NODE_TYPES = {
|
|
14411
|
-
string: [
|
|
14412
|
-
email: [
|
|
14413
|
-
url: [
|
|
14414
|
-
uuid: [
|
|
14415
|
-
ulid: [
|
|
14416
|
-
cuid: [
|
|
14417
|
-
cuid2: [
|
|
14418
|
-
nanoid: [
|
|
14419
|
-
iso: [
|
|
14420
|
-
number: [
|
|
14421
|
-
int: [
|
|
14422
|
-
float32: [
|
|
14423
|
-
float64: [
|
|
14424
|
-
boolean: [
|
|
14425
|
-
bigint: [
|
|
14426
|
-
symbol: [
|
|
14427
|
-
any: [
|
|
14428
|
-
unknown: [
|
|
14429
|
-
never: [
|
|
14430
|
-
void: [
|
|
14431
|
-
null: [
|
|
14432
|
-
undefined: [
|
|
14433
|
-
literal: [
|
|
14434
|
-
date: [
|
|
14435
|
-
array: [
|
|
14436
|
-
tuple: [
|
|
14437
|
-
object: [
|
|
14438
|
-
strictObject: [
|
|
14439
|
-
looseObject: [
|
|
14440
|
-
record: [
|
|
14441
|
-
map: [
|
|
14442
|
-
set: [
|
|
14443
|
-
promise: [
|
|
14444
|
-
enum: [
|
|
14445
|
-
nativeEnum: [
|
|
14446
|
-
union: [
|
|
14447
|
-
discriminatedUnion: [
|
|
14448
|
-
intersection: [
|
|
14671
|
+
string: [AST_NODE_TYPES66.TSStringKeyword],
|
|
14672
|
+
email: [AST_NODE_TYPES66.TSStringKeyword],
|
|
14673
|
+
url: [AST_NODE_TYPES66.TSStringKeyword],
|
|
14674
|
+
uuid: [AST_NODE_TYPES66.TSStringKeyword],
|
|
14675
|
+
ulid: [AST_NODE_TYPES66.TSStringKeyword],
|
|
14676
|
+
cuid: [AST_NODE_TYPES66.TSStringKeyword],
|
|
14677
|
+
cuid2: [AST_NODE_TYPES66.TSStringKeyword],
|
|
14678
|
+
nanoid: [AST_NODE_TYPES66.TSStringKeyword],
|
|
14679
|
+
iso: [AST_NODE_TYPES66.TSStringKeyword],
|
|
14680
|
+
number: [AST_NODE_TYPES66.TSNumberKeyword],
|
|
14681
|
+
int: [AST_NODE_TYPES66.TSNumberKeyword],
|
|
14682
|
+
float32: [AST_NODE_TYPES66.TSNumberKeyword],
|
|
14683
|
+
float64: [AST_NODE_TYPES66.TSNumberKeyword],
|
|
14684
|
+
boolean: [AST_NODE_TYPES66.TSBooleanKeyword],
|
|
14685
|
+
bigint: [AST_NODE_TYPES66.TSBigIntKeyword],
|
|
14686
|
+
symbol: [AST_NODE_TYPES66.TSSymbolKeyword],
|
|
14687
|
+
any: [AST_NODE_TYPES66.TSAnyKeyword],
|
|
14688
|
+
unknown: [AST_NODE_TYPES66.TSUnknownKeyword],
|
|
14689
|
+
never: [AST_NODE_TYPES66.TSNeverKeyword],
|
|
14690
|
+
void: [AST_NODE_TYPES66.TSVoidKeyword],
|
|
14691
|
+
null: [AST_NODE_TYPES66.TSNullKeyword],
|
|
14692
|
+
undefined: [AST_NODE_TYPES66.TSUndefinedKeyword],
|
|
14693
|
+
literal: [AST_NODE_TYPES66.TSLiteralType],
|
|
14694
|
+
date: [AST_NODE_TYPES66.TSTypeReference],
|
|
14695
|
+
array: [AST_NODE_TYPES66.TSArrayType, AST_NODE_TYPES66.TSTypeReference],
|
|
14696
|
+
tuple: [AST_NODE_TYPES66.TSTupleType],
|
|
14697
|
+
object: [AST_NODE_TYPES66.TSTypeLiteral, AST_NODE_TYPES66.TSTypeReference],
|
|
14698
|
+
strictObject: [AST_NODE_TYPES66.TSTypeLiteral, AST_NODE_TYPES66.TSTypeReference],
|
|
14699
|
+
looseObject: [AST_NODE_TYPES66.TSTypeLiteral, AST_NODE_TYPES66.TSTypeReference],
|
|
14700
|
+
record: [AST_NODE_TYPES66.TSTypeReference, AST_NODE_TYPES66.TSTypeLiteral],
|
|
14701
|
+
map: [AST_NODE_TYPES66.TSTypeReference],
|
|
14702
|
+
set: [AST_NODE_TYPES66.TSTypeReference],
|
|
14703
|
+
promise: [AST_NODE_TYPES66.TSTypeReference],
|
|
14704
|
+
enum: [AST_NODE_TYPES66.TSUnionType, AST_NODE_TYPES66.TSTypeReference, AST_NODE_TYPES66.TSLiteralType],
|
|
14705
|
+
nativeEnum: [AST_NODE_TYPES66.TSUnionType, AST_NODE_TYPES66.TSTypeReference, AST_NODE_TYPES66.TSLiteralType],
|
|
14706
|
+
union: [AST_NODE_TYPES66.TSUnionType, AST_NODE_TYPES66.TSTypeReference],
|
|
14707
|
+
discriminatedUnion: [AST_NODE_TYPES66.TSUnionType, AST_NODE_TYPES66.TSTypeReference],
|
|
14708
|
+
intersection: [AST_NODE_TYPES66.TSIntersectionType, AST_NODE_TYPES66.TSTypeReference]
|
|
14449
14709
|
};
|
|
14450
14710
|
function primitiveLiteralKey(node) {
|
|
14451
|
-
if (node.type !==
|
|
14711
|
+
if (node.type !== AST_NODE_TYPES66.Literal) {
|
|
14452
14712
|
return null;
|
|
14453
14713
|
}
|
|
14454
14714
|
if (node.value === null) {
|
|
@@ -14480,13 +14740,13 @@ function staticZodDomain(leaf, call) {
|
|
|
14480
14740
|
}
|
|
14481
14741
|
if (leaf === "literal") {
|
|
14482
14742
|
const [argument] = call.arguments;
|
|
14483
|
-
if (argument === void 0 || argument.type ===
|
|
14743
|
+
if (argument === void 0 || argument.type === AST_NODE_TYPES66.SpreadElement) {
|
|
14484
14744
|
return null;
|
|
14485
14745
|
}
|
|
14486
|
-
if (argument.type ===
|
|
14746
|
+
if (argument.type === AST_NODE_TYPES66.ArrayExpression) {
|
|
14487
14747
|
return exactDomain(
|
|
14488
14748
|
argument.elements.map(
|
|
14489
|
-
(element) => element === null || element.type ===
|
|
14749
|
+
(element) => element === null || element.type === AST_NODE_TYPES66.SpreadElement ? null : primitiveLiteralKey(element)
|
|
14490
14750
|
)
|
|
14491
14751
|
);
|
|
14492
14752
|
}
|
|
@@ -14494,13 +14754,13 @@ function staticZodDomain(leaf, call) {
|
|
|
14494
14754
|
}
|
|
14495
14755
|
if (leaf === "enum") {
|
|
14496
14756
|
const [argument] = call.arguments;
|
|
14497
|
-
if (argument === void 0 || argument.type ===
|
|
14757
|
+
if (argument === void 0 || argument.type === AST_NODE_TYPES66.SpreadElement) {
|
|
14498
14758
|
return null;
|
|
14499
14759
|
}
|
|
14500
|
-
if (argument.type ===
|
|
14760
|
+
if (argument.type === AST_NODE_TYPES66.ArrayExpression) {
|
|
14501
14761
|
return exactDomain(
|
|
14502
14762
|
argument.elements.map((element) => {
|
|
14503
|
-
if (element === null || element.type ===
|
|
14763
|
+
if (element === null || element.type === AST_NODE_TYPES66.SpreadElement) {
|
|
14504
14764
|
return null;
|
|
14505
14765
|
}
|
|
14506
14766
|
const key = primitiveLiteralKey(element);
|
|
@@ -14508,10 +14768,10 @@ function staticZodDomain(leaf, call) {
|
|
|
14508
14768
|
})
|
|
14509
14769
|
);
|
|
14510
14770
|
}
|
|
14511
|
-
if (argument.type ===
|
|
14771
|
+
if (argument.type === AST_NODE_TYPES66.ObjectExpression) {
|
|
14512
14772
|
return exactDomain(
|
|
14513
14773
|
argument.properties.map((property) => {
|
|
14514
|
-
if (property.type !==
|
|
14774
|
+
if (property.type !== AST_NODE_TYPES66.Property || property.computed || property.kind !== "init" || property.method || property.shorthand) {
|
|
14515
14775
|
return null;
|
|
14516
14776
|
}
|
|
14517
14777
|
const key = primitiveLiteralKey(property.value);
|
|
@@ -14538,15 +14798,15 @@ function sameDomain(left, right) {
|
|
|
14538
14798
|
return true;
|
|
14539
14799
|
}
|
|
14540
14800
|
function isExportedDeclaration(node) {
|
|
14541
|
-
return node.parent?.type ===
|
|
14801
|
+
return node.parent?.type === AST_NODE_TYPES66.ExportNamedDeclaration;
|
|
14542
14802
|
}
|
|
14543
14803
|
function isModuleLevelConst(node) {
|
|
14544
14804
|
const declaration = node.parent;
|
|
14545
|
-
if (declaration.type !==
|
|
14805
|
+
if (declaration.type !== AST_NODE_TYPES66.VariableDeclaration || declaration.kind !== "const") {
|
|
14546
14806
|
return false;
|
|
14547
14807
|
}
|
|
14548
14808
|
const container = declaration.parent;
|
|
14549
|
-
return container.type ===
|
|
14809
|
+
return container.type === AST_NODE_TYPES66.Program || container.type === AST_NODE_TYPES66.ExportNamedDeclaration && container.parent.type === AST_NODE_TYPES66.Program;
|
|
14550
14810
|
}
|
|
14551
14811
|
function normalizeSchemaName(name) {
|
|
14552
14812
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -14555,20 +14815,20 @@ function normalizeTypeName(name) {
|
|
|
14555
14815
|
return name.replace(/Type$/, "").toLowerCase();
|
|
14556
14816
|
}
|
|
14557
14817
|
function unwrapNullish(annotation) {
|
|
14558
|
-
if (annotation.type !==
|
|
14818
|
+
if (annotation.type !== AST_NODE_TYPES66.TSUnionType) {
|
|
14559
14819
|
return {
|
|
14560
14820
|
core: annotation,
|
|
14561
|
-
nullable: annotation.type ===
|
|
14821
|
+
nullable: annotation.type === AST_NODE_TYPES66.TSNullKeyword
|
|
14562
14822
|
};
|
|
14563
14823
|
}
|
|
14564
14824
|
const rest = [];
|
|
14565
14825
|
let nullable = false;
|
|
14566
14826
|
for (const member of annotation.types) {
|
|
14567
|
-
if (member.type ===
|
|
14827
|
+
if (member.type === AST_NODE_TYPES66.TSNullKeyword) {
|
|
14568
14828
|
nullable = true;
|
|
14569
14829
|
continue;
|
|
14570
14830
|
}
|
|
14571
|
-
if (member.type ===
|
|
14831
|
+
if (member.type === AST_NODE_TYPES66.TSUndefinedKeyword) {
|
|
14572
14832
|
continue;
|
|
14573
14833
|
}
|
|
14574
14834
|
rest.push(member);
|
|
@@ -14602,18 +14862,18 @@ function leafAgrees(field, annotation) {
|
|
|
14602
14862
|
return null;
|
|
14603
14863
|
}
|
|
14604
14864
|
if (leaf === "date") {
|
|
14605
|
-
return core.type ===
|
|
14865
|
+
return core.type === AST_NODE_TYPES66.TSTypeReference && core.typeName.type === AST_NODE_TYPES66.Identifier && core.typeName.name === "Date";
|
|
14606
14866
|
}
|
|
14607
14867
|
return expected.includes(core.type);
|
|
14608
14868
|
}
|
|
14609
14869
|
function typeLiteralDomain(annotation) {
|
|
14610
|
-
const members = annotation.type ===
|
|
14870
|
+
const members = annotation.type === AST_NODE_TYPES66.TSUnionType ? annotation.types : [annotation];
|
|
14611
14871
|
const keys = [];
|
|
14612
14872
|
for (const member of members) {
|
|
14613
|
-
if (member.type ===
|
|
14873
|
+
if (member.type === AST_NODE_TYPES66.TSNullKeyword) {
|
|
14614
14874
|
continue;
|
|
14615
14875
|
}
|
|
14616
|
-
if (member.type !==
|
|
14876
|
+
if (member.type !== AST_NODE_TYPES66.TSLiteralType) {
|
|
14617
14877
|
return null;
|
|
14618
14878
|
}
|
|
14619
14879
|
keys.push(primitiveLiteralKey(member.literal));
|
|
@@ -14621,11 +14881,11 @@ function typeLiteralDomain(annotation) {
|
|
|
14621
14881
|
return exactDomain(keys);
|
|
14622
14882
|
}
|
|
14623
14883
|
function staticStringUnionDomain(node) {
|
|
14624
|
-
if (node.type !==
|
|
14884
|
+
if (node.type !== AST_NODE_TYPES66.TSUnionType) {
|
|
14625
14885
|
return null;
|
|
14626
14886
|
}
|
|
14627
14887
|
const keys = node.types.map((member) => {
|
|
14628
|
-
if (member.type !==
|
|
14888
|
+
if (member.type !== AST_NODE_TYPES66.TSLiteralType) {
|
|
14629
14889
|
return null;
|
|
14630
14890
|
}
|
|
14631
14891
|
const key = primitiveLiteralKey(member.literal);
|
|
@@ -14693,14 +14953,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
14693
14953
|
function zodCallChain(node) {
|
|
14694
14954
|
const chain = [];
|
|
14695
14955
|
let current = node;
|
|
14696
|
-
while (current.type ===
|
|
14956
|
+
while (current.type === AST_NODE_TYPES66.CallExpression) {
|
|
14697
14957
|
const callee = current.callee;
|
|
14698
|
-
if (callee.type !==
|
|
14958
|
+
if (callee.type !== AST_NODE_TYPES66.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES66.Identifier) {
|
|
14699
14959
|
return null;
|
|
14700
14960
|
}
|
|
14701
14961
|
chain.push(current);
|
|
14702
14962
|
const receiver = callee.object;
|
|
14703
|
-
if (receiver.type ===
|
|
14963
|
+
if (receiver.type === AST_NODE_TYPES66.Identifier) {
|
|
14704
14964
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
14705
14965
|
}
|
|
14706
14966
|
current = receiver;
|
|
@@ -14709,14 +14969,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
14709
14969
|
}
|
|
14710
14970
|
function methodName2(call) {
|
|
14711
14971
|
const callee = call.callee;
|
|
14712
|
-
return callee.type ===
|
|
14972
|
+
return callee.type === AST_NODE_TYPES66.MemberExpression && callee.property.type === AST_NODE_TYPES66.Identifier ? callee.property.name : "";
|
|
14713
14973
|
}
|
|
14714
14974
|
function recordZodImport(node) {
|
|
14715
14975
|
if (!isZodModule(node.source.value)) {
|
|
14716
14976
|
return;
|
|
14717
14977
|
}
|
|
14718
14978
|
for (const specifier of node.specifiers) {
|
|
14719
|
-
if (specifier.type ===
|
|
14979
|
+
if (specifier.type === AST_NODE_TYPES66.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES66.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES66.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES66.Identifier && specifier.imported.name === "z") {
|
|
14720
14980
|
zodNamespaces.add(specifier.local.name);
|
|
14721
14981
|
}
|
|
14722
14982
|
}
|
|
@@ -14726,13 +14986,13 @@ var prefer_zod_infer_default = createRule({
|
|
|
14726
14986
|
let current = node;
|
|
14727
14987
|
let leaf = null;
|
|
14728
14988
|
let leafCall = null;
|
|
14729
|
-
while (current.type ===
|
|
14989
|
+
while (current.type === AST_NODE_TYPES66.CallExpression) {
|
|
14730
14990
|
const callee = current.callee;
|
|
14731
|
-
if (callee.type !==
|
|
14991
|
+
if (callee.type !== AST_NODE_TYPES66.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES66.Identifier) {
|
|
14732
14992
|
break;
|
|
14733
14993
|
}
|
|
14734
14994
|
const receiver = callee.object;
|
|
14735
|
-
if (receiver.type ===
|
|
14995
|
+
if (receiver.type === AST_NODE_TYPES66.Identifier && zodNamespaces.has(receiver.name)) {
|
|
14736
14996
|
leaf = callee.property.name;
|
|
14737
14997
|
leafCall = current;
|
|
14738
14998
|
break;
|
|
@@ -14763,20 +15023,20 @@ var prefer_zod_infer_default = createRule({
|
|
|
14763
15023
|
return domain instanceof Set && domain.size >= 2 ? domain : null;
|
|
14764
15024
|
}
|
|
14765
15025
|
function inferredSchemaName(node) {
|
|
14766
|
-
if (node.type !==
|
|
15026
|
+
if (node.type !== AST_NODE_TYPES66.TSTypeReference || node.typeName.type !== AST_NODE_TYPES66.TSQualifiedName || node.typeName.left.type !== AST_NODE_TYPES66.Identifier || !zodNamespaces.has(node.typeName.left.name) || node.typeName.right.name !== "infer") {
|
|
14767
15027
|
return null;
|
|
14768
15028
|
}
|
|
14769
15029
|
const arguments_ = node.typeArguments?.params ?? [];
|
|
14770
15030
|
const [argument] = arguments_;
|
|
14771
|
-
return arguments_.length === 1 && argument?.type ===
|
|
15031
|
+
return arguments_.length === 1 && argument?.type === AST_NODE_TYPES66.TSTypeQuery && argument.exprName.type === AST_NODE_TYPES66.Identifier ? argument.exprName.name : null;
|
|
14772
15032
|
}
|
|
14773
15033
|
function recordLiteralUnions(members, owner, ownerName, exported) {
|
|
14774
15034
|
for (const member of members) {
|
|
14775
|
-
if (member.type !==
|
|
15035
|
+
if (member.type !== AST_NODE_TYPES66.TSPropertySignature || member.computed || member.optional || member.readonly || member.typeAnnotation === void 0) {
|
|
14776
15036
|
continue;
|
|
14777
15037
|
}
|
|
14778
15038
|
const key = member.key;
|
|
14779
|
-
const propertyName7 = key.type ===
|
|
15039
|
+
const propertyName7 = key.type === AST_NODE_TYPES66.Identifier ? key.name : key.type === AST_NODE_TYPES66.Literal && typeof key.value === "string" ? key.value : null;
|
|
14780
15040
|
if (propertyName7 === null) {
|
|
14781
15041
|
continue;
|
|
14782
15042
|
}
|
|
@@ -14786,7 +15046,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
14786
15046
|
}
|
|
14787
15047
|
const annotation = member.typeAnnotation.typeAnnotation;
|
|
14788
15048
|
const domain = staticStringUnionDomain(annotation);
|
|
14789
|
-
if (domain === null || annotation.type !==
|
|
15049
|
+
if (domain === null || annotation.type !== AST_NODE_TYPES66.TSUnionType) {
|
|
14790
15050
|
continue;
|
|
14791
15051
|
}
|
|
14792
15052
|
literalUnionOccurrences.push({
|
|
@@ -14817,16 +15077,16 @@ var prefer_zod_infer_default = createRule({
|
|
|
14817
15077
|
return null;
|
|
14818
15078
|
}
|
|
14819
15079
|
const shape = base.arguments[0];
|
|
14820
|
-
if (shape === void 0 || shape.type !==
|
|
15080
|
+
if (shape === void 0 || shape.type !== AST_NODE_TYPES66.ObjectExpression) {
|
|
14821
15081
|
return null;
|
|
14822
15082
|
}
|
|
14823
15083
|
const fields = /* @__PURE__ */ new Map();
|
|
14824
15084
|
for (const property of shape.properties) {
|
|
14825
|
-
if (property.type !==
|
|
15085
|
+
if (property.type !== AST_NODE_TYPES66.Property || property.computed) {
|
|
14826
15086
|
return null;
|
|
14827
15087
|
}
|
|
14828
15088
|
const { key } = property;
|
|
14829
|
-
const name = key.type ===
|
|
15089
|
+
const name = key.type === AST_NODE_TYPES66.Identifier ? key.name : key.type === AST_NODE_TYPES66.Literal && typeof key.value === "string" ? key.value : null;
|
|
14830
15090
|
if (name === null) {
|
|
14831
15091
|
return null;
|
|
14832
15092
|
}
|
|
@@ -14837,11 +15097,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
14837
15097
|
function typeMembers(members) {
|
|
14838
15098
|
const result = /* @__PURE__ */ new Map();
|
|
14839
15099
|
for (const member of members) {
|
|
14840
|
-
if (member.type !==
|
|
15100
|
+
if (member.type !== AST_NODE_TYPES66.TSPropertySignature || member.computed) {
|
|
14841
15101
|
return null;
|
|
14842
15102
|
}
|
|
14843
15103
|
const { key } = member;
|
|
14844
|
-
const name = key.type ===
|
|
15104
|
+
const name = key.type === AST_NODE_TYPES66.Identifier ? key.name : key.type === AST_NODE_TYPES66.Literal && typeof key.value === "string" ? key.value : null;
|
|
14845
15105
|
if (name === null) {
|
|
14846
15106
|
return null;
|
|
14847
15107
|
}
|
|
@@ -14856,8 +15116,8 @@ var prefer_zod_infer_default = createRule({
|
|
|
14856
15116
|
return result.size === 0 ? null : result;
|
|
14857
15117
|
}
|
|
14858
15118
|
function collectConstrainedNames(node) {
|
|
14859
|
-
if (node.type ===
|
|
14860
|
-
if (node.typeName.type ===
|
|
15119
|
+
if (node.type === AST_NODE_TYPES66.TSTypeReference) {
|
|
15120
|
+
if (node.typeName.type === AST_NODE_TYPES66.Identifier) {
|
|
14861
15121
|
constrainedTypeNames.add(node.typeName.name);
|
|
14862
15122
|
}
|
|
14863
15123
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -14865,11 +15125,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
14865
15125
|
}
|
|
14866
15126
|
return;
|
|
14867
15127
|
}
|
|
14868
|
-
if (node.type ===
|
|
15128
|
+
if (node.type === AST_NODE_TYPES66.TSArrayType) {
|
|
14869
15129
|
collectConstrainedNames(node.elementType);
|
|
14870
15130
|
return;
|
|
14871
15131
|
}
|
|
14872
|
-
if (node.type ===
|
|
15132
|
+
if (node.type === AST_NODE_TYPES66.TSUnionType || node.type === AST_NODE_TYPES66.TSIntersectionType) {
|
|
14873
15133
|
for (const member of node.types) {
|
|
14874
15134
|
collectConstrainedNames(member);
|
|
14875
15135
|
}
|
|
@@ -14913,7 +15173,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
14913
15173
|
return {
|
|
14914
15174
|
Program(node) {
|
|
14915
15175
|
for (const statement of node.body) {
|
|
14916
|
-
if (statement.type ===
|
|
15176
|
+
if (statement.type === AST_NODE_TYPES66.ImportDeclaration) {
|
|
14917
15177
|
recordZodImport(statement);
|
|
14918
15178
|
}
|
|
14919
15179
|
}
|
|
@@ -14922,7 +15182,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
14922
15182
|
recordZodImport(node);
|
|
14923
15183
|
},
|
|
14924
15184
|
VariableDeclarator(node) {
|
|
14925
|
-
if (node.id.type !==
|
|
15185
|
+
if (node.id.type !== AST_NODE_TYPES66.Identifier || node.init == null) {
|
|
14926
15186
|
return;
|
|
14927
15187
|
}
|
|
14928
15188
|
const fields = schemaFields(node.init);
|
|
@@ -14939,14 +15199,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
14939
15199
|
},
|
|
14940
15200
|
/** Records `XSchema.transform(...)` and equivalent module-level reshaping. */
|
|
14941
15201
|
"MemberExpression[computed=false]"(node) {
|
|
14942
|
-
if (node.object.type ===
|
|
15202
|
+
if (node.object.type === AST_NODE_TYPES66.Identifier && node.property.type === AST_NODE_TYPES66.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
14943
15203
|
reshapedSchemaNames.add(node.object.name);
|
|
14944
15204
|
}
|
|
14945
15205
|
},
|
|
14946
15206
|
/** Records every type argument carried by a Zod constraint. */
|
|
14947
15207
|
TSTypeReference(node) {
|
|
14948
15208
|
const { typeName } = node;
|
|
14949
|
-
const referenced = typeName.type ===
|
|
15209
|
+
const referenced = typeName.type === AST_NODE_TYPES66.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES66.TSQualifiedName && typeName.right.type === AST_NODE_TYPES66.Identifier ? typeName.right.name : null;
|
|
14950
15210
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
14951
15211
|
return;
|
|
14952
15212
|
}
|
|
@@ -14978,7 +15238,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
14978
15238
|
typeName: node.id.name
|
|
14979
15239
|
});
|
|
14980
15240
|
}
|
|
14981
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
15241
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== AST_NODE_TYPES66.TSTypeLiteral) {
|
|
14982
15242
|
return;
|
|
14983
15243
|
}
|
|
14984
15244
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -15079,7 +15339,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
15079
15339
|
// src/rules/require-assert-never.ts
|
|
15080
15340
|
import {
|
|
15081
15341
|
ESLintUtils as ESLintUtils7,
|
|
15082
|
-
AST_NODE_TYPES as
|
|
15342
|
+
AST_NODE_TYPES as AST_NODE_TYPES67
|
|
15083
15343
|
} from "@typescript-eslint/utils";
|
|
15084
15344
|
import ts5 from "typescript";
|
|
15085
15345
|
var REQUIRE_ASSERT_NEVER_DOCUMENTATION = {
|
|
@@ -15093,14 +15353,14 @@ var REQUIRE_ASSERT_NEVER_DOCUMENTATION = {
|
|
|
15093
15353
|
]
|
|
15094
15354
|
};
|
|
15095
15355
|
var isRuntimeHandlingStatement = (statement) => {
|
|
15096
|
-
if (statement.type ===
|
|
15097
|
-
if (statement.type ===
|
|
15356
|
+
if (statement.type === AST_NODE_TYPES67.EmptyStatement) return false;
|
|
15357
|
+
if (statement.type === AST_NODE_TYPES67.BreakStatement) {
|
|
15098
15358
|
return statement.label !== null;
|
|
15099
15359
|
}
|
|
15100
|
-
if (statement.type ===
|
|
15360
|
+
if (statement.type === AST_NODE_TYPES67.TSTypeAliasDeclaration || statement.type === AST_NODE_TYPES67.TSInterfaceDeclaration) {
|
|
15101
15361
|
return false;
|
|
15102
15362
|
}
|
|
15103
|
-
if (statement.type ===
|
|
15363
|
+
if (statement.type === AST_NODE_TYPES67.BlockStatement) {
|
|
15104
15364
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
15105
15365
|
}
|
|
15106
15366
|
return true;
|
|
@@ -15116,7 +15376,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
15116
15376
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
15117
15377
|
}
|
|
15118
15378
|
const only = defaultCase.consequent[0];
|
|
15119
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
15379
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === AST_NODE_TYPES67.BlockStatement && !only.body.some(isRuntimeHandlingStatement)) {
|
|
15120
15380
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
15121
15381
|
}
|
|
15122
15382
|
return false;
|
|
@@ -15199,7 +15459,7 @@ var require_assert_never_default = createRule({
|
|
|
15199
15459
|
});
|
|
15200
15460
|
|
|
15201
15461
|
// src/rules/require-fetch-timeout.ts
|
|
15202
|
-
import { AST_NODE_TYPES as
|
|
15462
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES68, ASTUtils as ASTUtils20 } from "@typescript-eslint/utils";
|
|
15203
15463
|
var REQUIRE_FETCH_TIMEOUT_DOCUMENTATION = {
|
|
15204
15464
|
summary: "Require an abort `signal` (e.g. `AbortSignal.timeout(ms)`) on global `fetch()` calls so stalled upstreams cannot hang the caller forever.",
|
|
15205
15465
|
rationale: "An unbounded request can occupy work indefinitely when an upstream stalls.",
|
|
@@ -15225,14 +15485,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
15225
15485
|
return false;
|
|
15226
15486
|
}
|
|
15227
15487
|
function initProvablyLacksSignal(init) {
|
|
15228
|
-
if (init.type !==
|
|
15488
|
+
if (init.type !== AST_NODE_TYPES68.ObjectExpression) {
|
|
15229
15489
|
return false;
|
|
15230
15490
|
}
|
|
15231
15491
|
for (const prop of init.properties) {
|
|
15232
|
-
if (prop.type ===
|
|
15492
|
+
if (prop.type === AST_NODE_TYPES68.SpreadElement) {
|
|
15233
15493
|
return false;
|
|
15234
15494
|
}
|
|
15235
|
-
if (prop.key.type ===
|
|
15495
|
+
if (prop.key.type === AST_NODE_TYPES68.Identifier && prop.key.name === "signal" || prop.key.type === AST_NODE_TYPES68.Literal && prop.key.value === "signal") {
|
|
15236
15496
|
return false;
|
|
15237
15497
|
}
|
|
15238
15498
|
if (prop.computed) {
|
|
@@ -15242,7 +15502,7 @@ function initProvablyLacksSignal(init) {
|
|
|
15242
15502
|
return true;
|
|
15243
15503
|
}
|
|
15244
15504
|
function isInlineUrl(node, resolvesToGlobal) {
|
|
15245
|
-
return node.type ===
|
|
15505
|
+
return node.type === AST_NODE_TYPES68.Literal && typeof node.value === "string" || node.type === AST_NODE_TYPES68.TemplateLiteral || node.type === AST_NODE_TYPES68.NewExpression && node.callee.type === AST_NODE_TYPES68.Identifier && node.callee.name === "URL" && resolvesToGlobal(node.callee);
|
|
15246
15506
|
}
|
|
15247
15507
|
var require_fetch_timeout_default = createRule({
|
|
15248
15508
|
name: "require-fetch-timeout",
|
|
@@ -15284,10 +15544,10 @@ var require_fetch_timeout_default = createRule({
|
|
|
15284
15544
|
return variable === null || variable.defs.length === 0;
|
|
15285
15545
|
}
|
|
15286
15546
|
function isGlobalFetchCall2(callee) {
|
|
15287
|
-
if (callee.type ===
|
|
15547
|
+
if (callee.type === AST_NODE_TYPES68.Identifier) {
|
|
15288
15548
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
15289
15549
|
}
|
|
15290
|
-
return callee.type ===
|
|
15550
|
+
return callee.type === AST_NODE_TYPES68.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES68.Identifier && callee.property.name === "fetch" && callee.object.type === AST_NODE_TYPES68.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
15291
15551
|
}
|
|
15292
15552
|
function localConstInitProvablyLacksSignal(identifier) {
|
|
15293
15553
|
const variable = ASTUtils20.findVariable(
|
|
@@ -15296,14 +15556,14 @@ var require_fetch_timeout_default = createRule({
|
|
|
15296
15556
|
);
|
|
15297
15557
|
if (variable?.defs.length !== 1) return false;
|
|
15298
15558
|
const definition = variable.defs[0];
|
|
15299
|
-
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !==
|
|
15559
|
+
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !== AST_NODE_TYPES68.ObjectExpression || !initProvablyLacksSignal(definition.node.init)) {
|
|
15300
15560
|
return false;
|
|
15301
15561
|
}
|
|
15302
15562
|
for (const reference of variable.references) {
|
|
15303
15563
|
const ref = reference.identifier;
|
|
15304
15564
|
if (ref === identifier || ref === definition.name) continue;
|
|
15305
15565
|
const member = ref.parent;
|
|
15306
|
-
if (member.type !==
|
|
15566
|
+
if (member.type !== AST_NODE_TYPES68.MemberExpression || member.object !== ref || member.computed || member.property.type !== AST_NODE_TYPES68.Identifier || member.property.name === "signal" || member.parent.type !== AST_NODE_TYPES68.AssignmentExpression || member.parent.left !== member) {
|
|
15307
15567
|
return false;
|
|
15308
15568
|
}
|
|
15309
15569
|
}
|
|
@@ -15318,7 +15578,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
15318
15578
|
if (node.arguments.length === 1 && first !== void 0 && !isInlineUrl(first, resolvesToGlobal)) {
|
|
15319
15579
|
return;
|
|
15320
15580
|
}
|
|
15321
|
-
if (init === void 0 || initProvablyLacksSignal(init) || init.type ===
|
|
15581
|
+
if (init === void 0 || initProvablyLacksSignal(init) || init.type === AST_NODE_TYPES68.Identifier && localConstInitProvablyLacksSignal(init)) {
|
|
15322
15582
|
context.report({ node, messageId: "missingSignal" });
|
|
15323
15583
|
}
|
|
15324
15584
|
}
|
|
@@ -15327,7 +15587,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
15327
15587
|
});
|
|
15328
15588
|
|
|
15329
15589
|
// src/rules/require-interface-for-exported-class.ts
|
|
15330
|
-
import { AST_NODE_TYPES as
|
|
15590
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES69 } from "@typescript-eslint/utils";
|
|
15331
15591
|
var REQUIRE_INTERFACE_FOR_EXPORTED_CLASS_DOCUMENTATION = {
|
|
15332
15592
|
summary: "Require exported concrete classes with public behavior to declare a contract.",
|
|
15333
15593
|
rationale: "Consumers coupled only to a concrete class cannot substitute implementations or state the supported public capability independently of implementation details.",
|
|
@@ -15371,23 +15631,23 @@ var REQUIRE_INTERFACE_FOR_EXPORTED_CLASS_DOCUMENTATION = {
|
|
|
15371
15631
|
};
|
|
15372
15632
|
function hasPublicInstanceBehavior(node) {
|
|
15373
15633
|
return node.body.body.some((member) => {
|
|
15374
|
-
if (member.type ===
|
|
15375
|
-
return member.kind !== "constructor" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.key.type !==
|
|
15634
|
+
if (member.type === AST_NODE_TYPES69.MethodDefinition) {
|
|
15635
|
+
return member.kind !== "constructor" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.key.type !== AST_NODE_TYPES69.PrivateIdentifier;
|
|
15376
15636
|
}
|
|
15377
|
-
if (member.type !==
|
|
15637
|
+
if (member.type !== AST_NODE_TYPES69.PropertyDefinition || member.static)
|
|
15378
15638
|
return false;
|
|
15379
|
-
if (member.accessibility === "private" || member.accessibility === "protected" || member.key.type ===
|
|
15380
|
-
return member.value?.type ===
|
|
15639
|
+
if (member.accessibility === "private" || member.accessibility === "protected" || member.key.type === AST_NODE_TYPES69.PrivateIdentifier) return false;
|
|
15640
|
+
return member.value?.type === AST_NODE_TYPES69.ArrowFunctionExpression || member.value?.type === AST_NODE_TYPES69.FunctionExpression || member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES69.TSFunctionType;
|
|
15381
15641
|
});
|
|
15382
15642
|
}
|
|
15383
15643
|
function classBindings(statement) {
|
|
15384
|
-
const declaration = statement.type ===
|
|
15385
|
-
if (declaration?.type ===
|
|
15644
|
+
const declaration = statement.type === AST_NODE_TYPES69.ExportNamedDeclaration ? statement.declaration : statement;
|
|
15645
|
+
if (declaration?.type === AST_NODE_TYPES69.ClassDeclaration) {
|
|
15386
15646
|
return declaration.id === null ? [] : [{ declaration, name: declaration.id.name }];
|
|
15387
15647
|
}
|
|
15388
|
-
if (declaration?.type !==
|
|
15648
|
+
if (declaration?.type !== AST_NODE_TYPES69.VariableDeclaration) return [];
|
|
15389
15649
|
return declaration.declarations.flatMap(
|
|
15390
|
-
(item) => item.id.type ===
|
|
15650
|
+
(item) => item.id.type === AST_NODE_TYPES69.Identifier && item.init?.type === AST_NODE_TYPES69.ClassExpression ? [{ declaration: item.init, name: item.id.name }] : []
|
|
15391
15651
|
);
|
|
15392
15652
|
}
|
|
15393
15653
|
var require_interface_for_exported_class_default = createRule({
|
|
@@ -15418,7 +15678,7 @@ var require_interface_for_exported_class_default = createRule({
|
|
|
15418
15678
|
}
|
|
15419
15679
|
const exported = /* @__PURE__ */ new Map();
|
|
15420
15680
|
for (const statement of program.body) {
|
|
15421
|
-
if (statement.type ===
|
|
15681
|
+
if (statement.type === AST_NODE_TYPES69.ExportNamedDeclaration) {
|
|
15422
15682
|
for (const binding of classBindings(statement)) {
|
|
15423
15683
|
exported.set(binding.declaration, binding.name);
|
|
15424
15684
|
}
|
|
@@ -15427,18 +15687,18 @@ var require_interface_for_exported_class_default = createRule({
|
|
|
15427
15687
|
if (specifier.exportKind === "type") continue;
|
|
15428
15688
|
const candidate2 = classes.get(specifier.local.name);
|
|
15429
15689
|
if (candidate2 === void 0) continue;
|
|
15430
|
-
const exportedName = specifier.exported.type ===
|
|
15690
|
+
const exportedName = specifier.exported.type === AST_NODE_TYPES69.Identifier ? specifier.exported.name : specifier.exported.value;
|
|
15431
15691
|
exported.set(candidate2, exportedName);
|
|
15432
15692
|
}
|
|
15433
15693
|
continue;
|
|
15434
15694
|
}
|
|
15435
|
-
if (statement.type !==
|
|
15436
|
-
if (statement.declaration.type ===
|
|
15695
|
+
if (statement.type !== AST_NODE_TYPES69.ExportDefaultDeclaration) continue;
|
|
15696
|
+
if (statement.declaration.type === AST_NODE_TYPES69.ClassDeclaration || statement.declaration.type === AST_NODE_TYPES69.ClassExpression) {
|
|
15437
15697
|
exported.set(
|
|
15438
15698
|
statement.declaration,
|
|
15439
15699
|
statement.declaration.id?.name ?? "default"
|
|
15440
15700
|
);
|
|
15441
|
-
} else if (statement.declaration.type ===
|
|
15701
|
+
} else if (statement.declaration.type === AST_NODE_TYPES69.Identifier) {
|
|
15442
15702
|
const candidate2 = classes.get(statement.declaration.name);
|
|
15443
15703
|
if (candidate2 !== void 0) {
|
|
15444
15704
|
exported.set(candidate2, statement.declaration.name);
|
|
@@ -15446,7 +15706,7 @@ var require_interface_for_exported_class_default = createRule({
|
|
|
15446
15706
|
}
|
|
15447
15707
|
}
|
|
15448
15708
|
for (const [declaration, exportedName] of exported) {
|
|
15449
|
-
const extendsLocalAbstractBase = declaration.superClass?.type ===
|
|
15709
|
+
const extendsLocalAbstractBase = declaration.superClass?.type === AST_NODE_TYPES69.Identifier && abstractBases.has(declaration.superClass.name);
|
|
15450
15710
|
if (declaration.abstract || declaration.implements.length > 0 || extendsLocalAbstractBase || !hasPublicInstanceBehavior(declaration)) continue;
|
|
15451
15711
|
context.report({
|
|
15452
15712
|
node: declaration.id ?? declaration,
|
|
@@ -15460,7 +15720,7 @@ var require_interface_for_exported_class_default = createRule({
|
|
|
15460
15720
|
});
|
|
15461
15721
|
|
|
15462
15722
|
// src/rules/require-port-for-service.ts
|
|
15463
|
-
import { AST_NODE_TYPES as
|
|
15723
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES70 } from "@typescript-eslint/utils";
|
|
15464
15724
|
var REQUIRE_PORT_FOR_SERVICE_DOCUMENTATION = {
|
|
15465
15725
|
summary: "Advise when an exported service with injected collaborators has public methods not covered by its declared ports.",
|
|
15466
15726
|
rationale: "A declared port keeps consumers coupled to the service capability instead of its concrete implementation.",
|
|
@@ -15485,45 +15745,45 @@ var ROUTER_FACTORY_NAME = "Router";
|
|
|
15485
15745
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
15486
15746
|
var STORAGE_ASSIGNMENT_OPERATORS = /* @__PURE__ */ new Set(["=", "&&=", "??=", "||="]);
|
|
15487
15747
|
var staticMemberName6 = (member) => {
|
|
15488
|
-
if (member.property.type ===
|
|
15489
|
-
if (!member.computed && member.property.type ===
|
|
15490
|
-
return member.computed && member.property.type ===
|
|
15748
|
+
if (member.property.type === AST_NODE_TYPES70.PrivateIdentifier) return `#${member.property.name}`;
|
|
15749
|
+
if (!member.computed && member.property.type === AST_NODE_TYPES70.Identifier) return member.property.name;
|
|
15750
|
+
return member.computed && member.property.type === AST_NODE_TYPES70.Literal && typeof member.property.value === "string" ? member.property.value : null;
|
|
15491
15751
|
};
|
|
15492
15752
|
var detachedValueExports = (program) => {
|
|
15493
15753
|
const names = /* @__PURE__ */ new Set();
|
|
15494
15754
|
for (const statement of program.body) {
|
|
15495
|
-
if (statement.type ===
|
|
15755
|
+
if (statement.type === AST_NODE_TYPES70.ExportNamedDeclaration && statement.declaration === null && statement.source === null && statement.exportKind !== "type") {
|
|
15496
15756
|
for (const specifier of statement.specifiers) {
|
|
15497
15757
|
if (specifier.exportKind !== "type") names.add(specifier.local.name);
|
|
15498
15758
|
}
|
|
15499
|
-
} else if (statement.type ===
|
|
15759
|
+
} else if (statement.type === AST_NODE_TYPES70.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES70.Identifier) {
|
|
15500
15760
|
names.add(statement.declaration.name);
|
|
15501
|
-
} else if (statement.type ===
|
|
15761
|
+
} else if (statement.type === AST_NODE_TYPES70.TSExportAssignment && statement.expression.type === AST_NODE_TYPES70.Identifier) {
|
|
15502
15762
|
names.add(statement.expression.name);
|
|
15503
15763
|
}
|
|
15504
15764
|
}
|
|
15505
15765
|
return names;
|
|
15506
15766
|
};
|
|
15507
|
-
var isExportedClass2 = (node, detached) => node.parent.type ===
|
|
15767
|
+
var isExportedClass2 = (node, detached) => node.parent.type === AST_NODE_TYPES70.ExportNamedDeclaration || node.parent.type === AST_NODE_TYPES70.ExportDefaultDeclaration || node.id !== null && detached.has(node.id.name);
|
|
15508
15768
|
var readTypeReference = (annotation) => {
|
|
15509
|
-
if (annotation?.type ===
|
|
15769
|
+
if (annotation?.type === AST_NODE_TYPES70.TSUnionType) {
|
|
15510
15770
|
const members = annotation.types.filter(
|
|
15511
|
-
(member) => member.type !==
|
|
15771
|
+
(member) => member.type !== AST_NODE_TYPES70.TSUndefinedKeyword && member.type !== AST_NODE_TYPES70.TSNullKeyword
|
|
15512
15772
|
);
|
|
15513
15773
|
annotation = members.length === 1 ? members[0] : void 0;
|
|
15514
15774
|
}
|
|
15515
|
-
if (annotation === void 0 || annotation.type !==
|
|
15775
|
+
if (annotation === void 0 || annotation.type !== AST_NODE_TYPES70.TSTypeReference) return null;
|
|
15516
15776
|
const { typeName } = annotation;
|
|
15517
|
-
const rightmost = typeName.type ===
|
|
15777
|
+
const rightmost = typeName.type === AST_NODE_TYPES70.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES70.TSQualifiedName ? typeName.right.name : null;
|
|
15518
15778
|
if (rightmost === null) return null;
|
|
15519
15779
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
15520
15780
|
};
|
|
15521
|
-
var qualifiedName = (name) => name.type ===
|
|
15781
|
+
var qualifiedName = (name) => name.type === AST_NODE_TYPES70.Identifier ? name.name : name.type === AST_NODE_TYPES70.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
15522
15782
|
var propertySignatureTypes = (members) => {
|
|
15523
15783
|
const types = /* @__PURE__ */ new Map();
|
|
15524
15784
|
for (const member of members) {
|
|
15525
|
-
if (member.type !==
|
|
15526
|
-
if (member.computed || member.key.type !==
|
|
15785
|
+
if (member.type !== AST_NODE_TYPES70.TSPropertySignature) continue;
|
|
15786
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES70.Identifier) continue;
|
|
15527
15787
|
const reference = readTypeReference(member.typeAnnotation?.typeAnnotation);
|
|
15528
15788
|
if (reference === null) continue;
|
|
15529
15789
|
types.set(member.key.name, reference);
|
|
@@ -15534,18 +15794,18 @@ var fileTypeIndex = (program) => {
|
|
|
15534
15794
|
const objects = /* @__PURE__ */ new Map();
|
|
15535
15795
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
15536
15796
|
for (const statement of program.body) {
|
|
15537
|
-
const declaration = statement.type ===
|
|
15538
|
-
if (declaration?.type ===
|
|
15797
|
+
const declaration = statement.type === AST_NODE_TYPES70.ExportNamedDeclaration ? statement.declaration : statement;
|
|
15798
|
+
if (declaration?.type === AST_NODE_TYPES70.TSInterfaceDeclaration) {
|
|
15539
15799
|
objects.set(declaration.id.name, propertySignatureTypes(declaration.body.body));
|
|
15540
15800
|
continue;
|
|
15541
15801
|
}
|
|
15542
|
-
if (declaration?.type !==
|
|
15802
|
+
if (declaration?.type !== AST_NODE_TYPES70.TSTypeAliasDeclaration) continue;
|
|
15543
15803
|
const aliased = declaration.typeAnnotation;
|
|
15544
|
-
if (aliased.type ===
|
|
15804
|
+
if (aliased.type === AST_NODE_TYPES70.TSFunctionType || aliased.type === AST_NODE_TYPES70.TSConstructorType) {
|
|
15545
15805
|
functionAliases.add(declaration.id.name);
|
|
15546
15806
|
continue;
|
|
15547
15807
|
}
|
|
15548
|
-
const literals = aliased.type ===
|
|
15808
|
+
const literals = aliased.type === AST_NODE_TYPES70.TSTypeLiteral ? [aliased] : aliased.type === AST_NODE_TYPES70.TSIntersectionType ? aliased.types.filter((part) => part.type === AST_NODE_TYPES70.TSTypeLiteral) : [];
|
|
15549
15809
|
if (literals.length === 0) continue;
|
|
15550
15810
|
const merged = /* @__PURE__ */ new Map();
|
|
15551
15811
|
for (const literal of literals) {
|
|
@@ -15574,10 +15834,10 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
15574
15834
|
while (pending.length > 0) {
|
|
15575
15835
|
const current = pending.pop();
|
|
15576
15836
|
if (current === void 0) break;
|
|
15577
|
-
if (current.type ===
|
|
15578
|
-
const expression = current.type ===
|
|
15579
|
-
const storedField = expression?.type ===
|
|
15580
|
-
if (expression?.type !==
|
|
15837
|
+
if (current.type === AST_NODE_TYPES70.ArrowFunctionExpression || current.type === AST_NODE_TYPES70.FunctionExpression || current.type === AST_NODE_TYPES70.FunctionDeclaration || current.type === AST_NODE_TYPES70.ClassExpression || current.type === AST_NODE_TYPES70.ClassDeclaration) continue;
|
|
15838
|
+
const expression = current.type === AST_NODE_TYPES70.ExpressionStatement ? current.expression : null;
|
|
15839
|
+
const storedField = expression?.type === AST_NODE_TYPES70.AssignmentExpression && expression.left.type === AST_NODE_TYPES70.MemberExpression && expression.left.object.type === AST_NODE_TYPES70.ThisExpression ? staticMemberName6(expression.left) : null;
|
|
15840
|
+
if (expression?.type !== AST_NODE_TYPES70.AssignmentExpression || !STORAGE_ASSIGNMENT_OPERATORS.has(expression.operator) || expression.left.type !== AST_NODE_TYPES70.MemberExpression || expression.left.object.type !== AST_NODE_TYPES70.ThisExpression || storedField === null) {
|
|
15581
15841
|
for (const key of Object.keys(current)) {
|
|
15582
15842
|
if (key === "parent") continue;
|
|
15583
15843
|
const value = current[key];
|
|
@@ -15590,14 +15850,14 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
15590
15850
|
continue;
|
|
15591
15851
|
}
|
|
15592
15852
|
let source = expression.right;
|
|
15593
|
-
while (source.type ===
|
|
15594
|
-
if (source.type ===
|
|
15853
|
+
while (source.type === AST_NODE_TYPES70.TSNonNullExpression || source.type === AST_NODE_TYPES70.TSAsExpression || source.type === AST_NODE_TYPES70.TSSatisfiesExpression || source.type === AST_NODE_TYPES70.TSTypeAssertion) source = source.expression;
|
|
15854
|
+
if (source.type === AST_NODE_TYPES70.NewExpression) {
|
|
15595
15855
|
constructedFields += 1;
|
|
15596
|
-
} else if (source.type ===
|
|
15856
|
+
} else if (source.type === AST_NODE_TYPES70.Identifier) {
|
|
15597
15857
|
const fields = storedFieldsFrom.get(source.name) ?? /* @__PURE__ */ new Set();
|
|
15598
15858
|
fields.add(storedField);
|
|
15599
15859
|
storedFieldsFrom.set(source.name, fields);
|
|
15600
|
-
} else if (source.type ===
|
|
15860
|
+
} else if (source.type === AST_NODE_TYPES70.MemberExpression && source.object.type === AST_NODE_TYPES70.Identifier) {
|
|
15601
15861
|
const fields = storedFieldsFrom.get(source.object.name) ?? /* @__PURE__ */ new Set();
|
|
15602
15862
|
fields.add(storedField);
|
|
15603
15863
|
storedFieldsFrom.set(source.object.name, fields);
|
|
@@ -15615,7 +15875,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
15615
15875
|
const collaborators = [];
|
|
15616
15876
|
for (const parameter of ctor.value.params) {
|
|
15617
15877
|
for (const reference of parameterCollaborators(parameter, declared, storedMemberFieldsFrom)) {
|
|
15618
|
-
const fields = parameter.type ===
|
|
15878
|
+
const fields = parameter.type === AST_NODE_TYPES70.TSParameterProperty ? [reference.name] : reference.fields.length > 0 ? reference.fields : [...storedFieldsFrom.get(reference.name) ?? []];
|
|
15619
15879
|
if (fields.length === 0) continue;
|
|
15620
15880
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
15621
15881
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -15630,8 +15890,8 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
15630
15890
|
};
|
|
15631
15891
|
var parameterCollaborators = (parameter, declared, storedMemberFieldsFrom) => {
|
|
15632
15892
|
let target = parameter;
|
|
15633
|
-
if (target.type ===
|
|
15634
|
-
if (target.type ===
|
|
15893
|
+
if (target.type === AST_NODE_TYPES70.AssignmentPattern) target = target.left;
|
|
15894
|
+
if (target.type === AST_NODE_TYPES70.ObjectPattern) {
|
|
15635
15895
|
return objectPatternCollaborators(target, declared);
|
|
15636
15896
|
}
|
|
15637
15897
|
const named2 = namedParameterCollaborator(parameter);
|
|
@@ -15640,9 +15900,9 @@ var parameterCollaborators = (parameter, declared, storedMemberFieldsFrom) => {
|
|
|
15640
15900
|
};
|
|
15641
15901
|
var namedBagCollaborators = (annotated, declared, storedMemberFieldsFrom) => {
|
|
15642
15902
|
let target = annotated;
|
|
15643
|
-
if (target.type ===
|
|
15644
|
-
if (target.type ===
|
|
15645
|
-
if (target.type !==
|
|
15903
|
+
if (target.type === AST_NODE_TYPES70.TSParameterProperty) target = target.parameter;
|
|
15904
|
+
if (target.type === AST_NODE_TYPES70.AssignmentPattern) target = target.left;
|
|
15905
|
+
if (target.type !== AST_NODE_TYPES70.Identifier) return [];
|
|
15646
15906
|
const members = bagMemberTypes(target.typeAnnotation?.typeAnnotation, declared);
|
|
15647
15907
|
if (members === null) return [];
|
|
15648
15908
|
const storedMembers = storedMemberFieldsFrom.get(target.name);
|
|
@@ -15658,9 +15918,9 @@ var namedBagCollaborators = (annotated, declared, storedMemberFieldsFrom) => {
|
|
|
15658
15918
|
};
|
|
15659
15919
|
var namedParameterCollaborator = (annotated) => {
|
|
15660
15920
|
let target = annotated;
|
|
15661
|
-
if (target.type ===
|
|
15662
|
-
if (target.type ===
|
|
15663
|
-
if (target.type !==
|
|
15921
|
+
if (target.type === AST_NODE_TYPES70.TSParameterProperty) target = target.parameter;
|
|
15922
|
+
if (target.type === AST_NODE_TYPES70.AssignmentPattern) target = target.left;
|
|
15923
|
+
if (target.type !== AST_NODE_TYPES70.Identifier) return null;
|
|
15664
15924
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
15665
15925
|
if (reference === null) return null;
|
|
15666
15926
|
return { name: target.name, ...reference, fields: [] };
|
|
@@ -15672,11 +15932,11 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
15672
15932
|
if (members === null) return [];
|
|
15673
15933
|
const collaborators = [];
|
|
15674
15934
|
for (const property of pattern.properties) {
|
|
15675
|
-
if (property.type !==
|
|
15676
|
-
if (property.key.type !==
|
|
15935
|
+
if (property.type !== AST_NODE_TYPES70.Property || property.computed) continue;
|
|
15936
|
+
if (property.key.type !== AST_NODE_TYPES70.Identifier) continue;
|
|
15677
15937
|
const key = property.key.name;
|
|
15678
|
-
const bound = property.value.type ===
|
|
15679
|
-
if (bound.type !==
|
|
15938
|
+
const bound = property.value.type === AST_NODE_TYPES70.AssignmentPattern ? property.value.left : property.value;
|
|
15939
|
+
if (bound.type !== AST_NODE_TYPES70.Identifier) continue;
|
|
15680
15940
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
15681
15941
|
const reference = members.get(key);
|
|
15682
15942
|
if (reference === void 0) continue;
|
|
@@ -15686,21 +15946,21 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
15686
15946
|
};
|
|
15687
15947
|
var bagMemberTypes = (annotation, declared) => {
|
|
15688
15948
|
if (annotation === void 0) return null;
|
|
15689
|
-
if (annotation.type ===
|
|
15949
|
+
if (annotation.type === AST_NODE_TYPES70.TSTypeLiteral) {
|
|
15690
15950
|
return propertySignatureTypes(annotation.members);
|
|
15691
15951
|
}
|
|
15692
|
-
if (annotation.type !==
|
|
15952
|
+
if (annotation.type !== AST_NODE_TYPES70.TSTypeReference || annotation.typeName.type !== AST_NODE_TYPES70.Identifier) {
|
|
15693
15953
|
return null;
|
|
15694
15954
|
}
|
|
15695
15955
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
15696
15956
|
};
|
|
15697
15957
|
var isFrameworkWiring = (body2) => subtreeHas(body2, (node) => {
|
|
15698
|
-
if (node.type ===
|
|
15958
|
+
if (node.type === AST_NODE_TYPES70.CallExpression) {
|
|
15699
15959
|
const { callee } = node;
|
|
15700
|
-
if (callee.type ===
|
|
15701
|
-
return callee.type ===
|
|
15960
|
+
if (callee.type === AST_NODE_TYPES70.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
15961
|
+
return callee.type === AST_NODE_TYPES70.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES70.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
15702
15962
|
}
|
|
15703
|
-
return node.type ===
|
|
15963
|
+
return node.type === AST_NODE_TYPES70.TSTypeReference && node.typeName.type === AST_NODE_TYPES70.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
15704
15964
|
});
|
|
15705
15965
|
var subtreeHas = (root, found) => {
|
|
15706
15966
|
let hit = false;
|
|
@@ -15727,19 +15987,19 @@ var invokedInstanceField = (call) => {
|
|
|
15727
15987
|
const direct = instanceField(call.callee);
|
|
15728
15988
|
if (direct !== null) return direct;
|
|
15729
15989
|
let callee = call.callee;
|
|
15730
|
-
while (callee.type ===
|
|
15731
|
-
return callee.type ===
|
|
15990
|
+
while (callee.type === AST_NODE_TYPES70.ChainExpression || callee.type === AST_NODE_TYPES70.TSAsExpression || callee.type === AST_NODE_TYPES70.TSNonNullExpression || callee.type === AST_NODE_TYPES70.TSSatisfiesExpression || callee.type === AST_NODE_TYPES70.TSTypeAssertion) callee = callee.expression;
|
|
15991
|
+
return callee.type === AST_NODE_TYPES70.MemberExpression ? instanceField(callee.object) : null;
|
|
15732
15992
|
};
|
|
15733
15993
|
var instanceField = (candidate2) => {
|
|
15734
15994
|
let node = candidate2;
|
|
15735
|
-
while (node.type ===
|
|
15736
|
-
return node.type ===
|
|
15995
|
+
while (node.type === AST_NODE_TYPES70.ChainExpression || node.type === AST_NODE_TYPES70.TSAsExpression || node.type === AST_NODE_TYPES70.TSNonNullExpression || node.type === AST_NODE_TYPES70.TSSatisfiesExpression || node.type === AST_NODE_TYPES70.TSTypeAssertion) node = node.expression;
|
|
15996
|
+
return node.type === AST_NODE_TYPES70.MemberExpression && node.object.type === AST_NODE_TYPES70.ThisExpression ? staticMemberName6(node) : null;
|
|
15737
15997
|
};
|
|
15738
15998
|
var behaviorallyInvokedFields = (body2) => {
|
|
15739
15999
|
const invoked = /* @__PURE__ */ new Set();
|
|
15740
16000
|
const visit = (current) => {
|
|
15741
|
-
if (current.type ===
|
|
15742
|
-
if (current.type ===
|
|
16001
|
+
if (current.type === AST_NODE_TYPES70.ClassDeclaration || current.type === AST_NODE_TYPES70.ClassExpression || current.type === AST_NODE_TYPES70.FunctionDeclaration || current.type === AST_NODE_TYPES70.FunctionExpression) return;
|
|
16002
|
+
if (current.type === AST_NODE_TYPES70.CallExpression) {
|
|
15743
16003
|
const field = invokedInstanceField(current);
|
|
15744
16004
|
if (field !== null) invoked.add(field);
|
|
15745
16005
|
}
|
|
@@ -15752,14 +16012,14 @@ var behaviorallyInvokedFields = (body2) => {
|
|
|
15752
16012
|
}
|
|
15753
16013
|
};
|
|
15754
16014
|
for (const member of body2.body) {
|
|
15755
|
-
if (member.type ===
|
|
15756
|
-
if (member.type ===
|
|
16015
|
+
if (member.type === AST_NODE_TYPES70.StaticBlock || member.static) continue;
|
|
16016
|
+
if (member.type === AST_NODE_TYPES70.MethodDefinition) {
|
|
15757
16017
|
if (member.value.body !== null && member.value.body !== void 0) visit(member.value.body);
|
|
15758
16018
|
continue;
|
|
15759
16019
|
}
|
|
15760
|
-
if (member.type !==
|
|
16020
|
+
if (member.type !== AST_NODE_TYPES70.PropertyDefinition || member.value === null) continue;
|
|
15761
16021
|
visit(
|
|
15762
|
-
member.value.type ===
|
|
16022
|
+
member.value.type === AST_NODE_TYPES70.ArrowFunctionExpression ? member.value.body : member.value
|
|
15763
16023
|
);
|
|
15764
16024
|
}
|
|
15765
16025
|
return invoked;
|
|
@@ -15779,26 +16039,26 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
15779
16039
|
var fileInterfaceNames = (program) => {
|
|
15780
16040
|
const names = [];
|
|
15781
16041
|
for (const statement of program.body) {
|
|
15782
|
-
const declaration = statement.type ===
|
|
15783
|
-
if (declaration?.type ===
|
|
16042
|
+
const declaration = statement.type === AST_NODE_TYPES70.ExportNamedDeclaration ? statement.declaration : statement;
|
|
16043
|
+
if (declaration?.type === AST_NODE_TYPES70.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
15784
16044
|
}
|
|
15785
16045
|
return names;
|
|
15786
16046
|
};
|
|
15787
16047
|
var publicMethodNames = (body2, functionAliases) => {
|
|
15788
16048
|
const names = [];
|
|
15789
16049
|
for (const member of body2.body) {
|
|
15790
|
-
if (member.type ===
|
|
16050
|
+
if (member.type === AST_NODE_TYPES70.PropertyDefinition) {
|
|
15791
16051
|
if (member.static || member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
15792
|
-
if (member.key.type ===
|
|
15793
|
-
if (member.value?.type !==
|
|
15794
|
-
names.push(member.key.type ===
|
|
16052
|
+
if (member.key.type === AST_NODE_TYPES70.PrivateIdentifier) continue;
|
|
16053
|
+
if (member.value?.type !== AST_NODE_TYPES70.ArrowFunctionExpression && member.value?.type !== AST_NODE_TYPES70.FunctionExpression && member.typeAnnotation?.typeAnnotation.type !== AST_NODE_TYPES70.TSFunctionType && !(member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES70.TSTypeReference && member.typeAnnotation.typeAnnotation.typeName.type === AST_NODE_TYPES70.Identifier && functionAliases.has(member.typeAnnotation.typeAnnotation.typeName.name))) continue;
|
|
16054
|
+
names.push(member.key.type === AST_NODE_TYPES70.Identifier ? member.key.name : "\u2026");
|
|
15795
16055
|
continue;
|
|
15796
16056
|
}
|
|
15797
|
-
if (member.type !==
|
|
16057
|
+
if (member.type !== AST_NODE_TYPES70.MethodDefinition) continue;
|
|
15798
16058
|
if (member.kind !== "method" || member.static) continue;
|
|
15799
16059
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
15800
|
-
if (member.key.type ===
|
|
15801
|
-
if (member.key.type ===
|
|
16060
|
+
if (member.key.type === AST_NODE_TYPES70.PrivateIdentifier) continue;
|
|
16061
|
+
if (member.key.type === AST_NODE_TYPES70.Identifier) names.push(member.key.name);
|
|
15802
16062
|
else names.push("\u2026");
|
|
15803
16063
|
}
|
|
15804
16064
|
return names;
|
|
@@ -15806,13 +16066,13 @@ var publicMethodNames = (body2, functionAliases) => {
|
|
|
15806
16066
|
var isFluentConstructionObject = (node, getText) => {
|
|
15807
16067
|
if (node.id === null) return false;
|
|
15808
16068
|
const methods = node.body.body.filter(
|
|
15809
|
-
(member) => member.type ===
|
|
16069
|
+
(member) => member.type === AST_NODE_TYPES70.MethodDefinition && member.kind === "method" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.value.body !== null
|
|
15810
16070
|
);
|
|
15811
16071
|
if (methods.length === 0) return false;
|
|
15812
16072
|
return methods.every((member) => {
|
|
15813
16073
|
const result = member.value.returnType?.typeAnnotation;
|
|
15814
16074
|
if (result === void 0) return false;
|
|
15815
|
-
const returnsOwnType = result.type ===
|
|
16075
|
+
const returnsOwnType = result.type === AST_NODE_TYPES70.TSTypeReference && result.typeName.type === AST_NODE_TYPES70.Identifier && result.typeName.name === node.id?.name;
|
|
15816
16076
|
return returnsOwnType || FLUENT_BUILDER_NAME_RE.test(node.id?.name ?? "") && FLUENT_RESULT_TYPE_RE.test(getText(result));
|
|
15817
16077
|
});
|
|
15818
16078
|
};
|
|
@@ -15820,10 +16080,10 @@ function localClassAbstractness(program) {
|
|
|
15820
16080
|
const classes = /* @__PURE__ */ new Map();
|
|
15821
16081
|
const parents = /* @__PURE__ */ new Map();
|
|
15822
16082
|
for (const statement of program.body) {
|
|
15823
|
-
const declaration = statement.type ===
|
|
15824
|
-
if (declaration?.type ===
|
|
16083
|
+
const declaration = statement.type === AST_NODE_TYPES70.ExportNamedDeclaration || statement.type === AST_NODE_TYPES70.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
16084
|
+
if (declaration?.type === AST_NODE_TYPES70.ClassDeclaration && declaration.id !== null) {
|
|
15825
16085
|
classes.set(declaration.id.name, declaration.abstract === true);
|
|
15826
|
-
if (declaration.superClass?.type ===
|
|
16086
|
+
if (declaration.superClass?.type === AST_NODE_TYPES70.Identifier) {
|
|
15827
16087
|
parents.set(declaration.id.name, declaration.superClass.name);
|
|
15828
16088
|
}
|
|
15829
16089
|
}
|
|
@@ -15845,43 +16105,43 @@ function localInterfaceSurfaces(program) {
|
|
|
15845
16105
|
const parents = /* @__PURE__ */ new Map();
|
|
15846
16106
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
15847
16107
|
for (const statement of program.body) {
|
|
15848
|
-
const declaration = statement.type ===
|
|
15849
|
-
if (declaration?.type ===
|
|
16108
|
+
const declaration = statement.type === AST_NODE_TYPES70.ExportNamedDeclaration ? statement.declaration : statement;
|
|
16109
|
+
if (declaration?.type === AST_NODE_TYPES70.TSTypeAliasDeclaration && (declaration.typeAnnotation.type === AST_NODE_TYPES70.TSFunctionType || declaration.typeAnnotation.type === AST_NODE_TYPES70.TSConstructorType)) functionAliases.add(declaration.id.name);
|
|
15850
16110
|
}
|
|
15851
16111
|
for (const statement of program.body) {
|
|
15852
|
-
const declaration = statement.type ===
|
|
15853
|
-
if (declaration?.type ===
|
|
16112
|
+
const declaration = statement.type === AST_NODE_TYPES70.ExportNamedDeclaration ? statement.declaration : statement;
|
|
16113
|
+
if (declaration?.type === AST_NODE_TYPES70.TSTypeAliasDeclaration) {
|
|
15854
16114
|
const callables2 = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
15855
|
-
const parts = declaration.typeAnnotation.type ===
|
|
16115
|
+
const parts = declaration.typeAnnotation.type === AST_NODE_TYPES70.TSIntersectionType ? declaration.typeAnnotation.types : [declaration.typeAnnotation];
|
|
15856
16116
|
const inherited = parents.get(declaration.id.name) ?? [];
|
|
15857
16117
|
for (const part of parts) {
|
|
15858
|
-
if (part.type ===
|
|
16118
|
+
if (part.type === AST_NODE_TYPES70.TSTypeReference && part.typeName.type === AST_NODE_TYPES70.Identifier) {
|
|
15859
16119
|
inherited.push(part.typeName.name);
|
|
15860
16120
|
continue;
|
|
15861
16121
|
}
|
|
15862
|
-
if (part.type !==
|
|
16122
|
+
if (part.type !== AST_NODE_TYPES70.TSTypeLiteral) continue;
|
|
15863
16123
|
for (const member of part.members) {
|
|
15864
|
-
if (member.type !==
|
|
15865
|
-
if (member.computed || member.key.type !==
|
|
15866
|
-
if (member.type ===
|
|
16124
|
+
if (member.type !== AST_NODE_TYPES70.TSMethodSignature && member.type !== AST_NODE_TYPES70.TSPropertySignature) continue;
|
|
16125
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES70.Identifier) continue;
|
|
16126
|
+
if (member.type === AST_NODE_TYPES70.TSMethodSignature) {
|
|
15867
16127
|
callables2.add(member.key.name);
|
|
15868
16128
|
continue;
|
|
15869
16129
|
}
|
|
15870
|
-
if (member.type !==
|
|
16130
|
+
if (member.type !== AST_NODE_TYPES70.TSPropertySignature) continue;
|
|
15871
16131
|
const annotation = member.typeAnnotation?.typeAnnotation;
|
|
15872
|
-
if (annotation?.type ===
|
|
16132
|
+
if (annotation?.type === AST_NODE_TYPES70.TSFunctionType || annotation?.type === AST_NODE_TYPES70.TSTypeReference && annotation.typeName.type === AST_NODE_TYPES70.Identifier && functionAliases.has(annotation.typeName.name)) callables2.add(member.key.name);
|
|
15873
16133
|
}
|
|
15874
16134
|
}
|
|
15875
16135
|
interfaces.set(declaration.id.name, callables2);
|
|
15876
16136
|
parents.set(declaration.id.name, inherited);
|
|
15877
16137
|
continue;
|
|
15878
16138
|
}
|
|
15879
|
-
if (declaration?.type !==
|
|
16139
|
+
if (declaration?.type !== AST_NODE_TYPES70.TSInterfaceDeclaration) continue;
|
|
15880
16140
|
const callables = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
15881
16141
|
for (const member of declaration.body.body) {
|
|
15882
|
-
if (member.type !==
|
|
15883
|
-
if (member.computed || member.key.type !==
|
|
15884
|
-
if (member.type ===
|
|
16142
|
+
if (member.type !== AST_NODE_TYPES70.TSMethodSignature && member.type !== AST_NODE_TYPES70.TSPropertySignature) continue;
|
|
16143
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES70.Identifier) continue;
|
|
16144
|
+
if (member.type === AST_NODE_TYPES70.TSMethodSignature || member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES70.TSFunctionType || member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES70.TSTypeReference && member.typeAnnotation.typeAnnotation.typeName.type === AST_NODE_TYPES70.Identifier && functionAliases.has(member.typeAnnotation.typeAnnotation.typeName.name)) callables.add(member.key.name);
|
|
15885
16145
|
}
|
|
15886
16146
|
interfaces.set(declaration.id.name, callables);
|
|
15887
16147
|
parents.set(
|
|
@@ -15889,7 +16149,7 @@ function localInterfaceSurfaces(program) {
|
|
|
15889
16149
|
[
|
|
15890
16150
|
...parents.get(declaration.id.name) ?? [],
|
|
15891
16151
|
...declaration.extends.flatMap(
|
|
15892
|
-
(heritage) => heritage.expression.type ===
|
|
16152
|
+
(heritage) => heritage.expression.type === AST_NODE_TYPES70.Identifier ? [heritage.expression.name] : ["*"]
|
|
15893
16153
|
)
|
|
15894
16154
|
]
|
|
15895
16155
|
);
|
|
@@ -15916,7 +16176,7 @@ function localInterfaceSurfaces(program) {
|
|
|
15916
16176
|
}
|
|
15917
16177
|
function hasServicePort(node, methods, classes, interfaces) {
|
|
15918
16178
|
if (node.superClass !== null) {
|
|
15919
|
-
if (node.superClass.type !==
|
|
16179
|
+
if (node.superClass.type !== AST_NODE_TYPES70.Identifier) return true;
|
|
15920
16180
|
const localAbstract = classes.get(node.superClass.name);
|
|
15921
16181
|
if (localAbstract === void 0 || localAbstract) return true;
|
|
15922
16182
|
}
|
|
@@ -15928,7 +16188,7 @@ function hasServicePort(node, methods, classes, interfaces) {
|
|
|
15928
16188
|
if (node.implements.length === 0) return false;
|
|
15929
16189
|
const combined = /* @__PURE__ */ new Set();
|
|
15930
16190
|
for (const implementation of node.implements) {
|
|
15931
|
-
if (implementation.expression.type !==
|
|
16191
|
+
if (implementation.expression.type !== AST_NODE_TYPES70.Identifier) return true;
|
|
15932
16192
|
const name = implementation.expression.name;
|
|
15933
16193
|
const localAbstract = classes.get(name);
|
|
15934
16194
|
if (localAbstract === true) return true;
|
|
@@ -15971,7 +16231,7 @@ var require_port_for_service_default = createRule({
|
|
|
15971
16231
|
if (node.abstract === true) return;
|
|
15972
16232
|
if (node.decorators.length > 0) return;
|
|
15973
16233
|
const ctor = node.body.body.find(
|
|
15974
|
-
(member) => member.type ===
|
|
16234
|
+
(member) => member.type === AST_NODE_TYPES70.MethodDefinition && member.kind === "constructor" && member.value.body !== null && member.value.body !== void 0
|
|
15975
16235
|
);
|
|
15976
16236
|
if (ctor === void 0) return;
|
|
15977
16237
|
const constructorFacts = readConstructor(
|
|
@@ -16006,7 +16266,7 @@ var require_port_for_service_default = createRule({
|
|
|
16006
16266
|
});
|
|
16007
16267
|
|
|
16008
16268
|
// src/rules/require-sql-access-class.ts
|
|
16009
|
-
import { AST_NODE_TYPES as
|
|
16269
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES71 } from "@typescript-eslint/utils";
|
|
16010
16270
|
var DIRECT_EXECUTION_METHODS = /* @__PURE__ */ new Set([
|
|
16011
16271
|
"all",
|
|
16012
16272
|
"batch",
|
|
@@ -16100,9 +16360,9 @@ var REQUIRE_SQL_ACCESS_CLASS_DOCUMENTATION = {
|
|
|
16100
16360
|
]
|
|
16101
16361
|
};
|
|
16102
16362
|
function memberName5(node) {
|
|
16103
|
-
if (!node.computed && node.property.type ===
|
|
16363
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES71.Identifier)
|
|
16104
16364
|
return node.property.name;
|
|
16105
|
-
if (node.computed && node.property.type ===
|
|
16365
|
+
if (node.computed && node.property.type === AST_NODE_TYPES71.Literal && typeof node.property.value === "string")
|
|
16106
16366
|
return node.property.value;
|
|
16107
16367
|
return null;
|
|
16108
16368
|
}
|
|
@@ -16114,89 +16374,89 @@ function isDatabaseOperation(method, receiver) {
|
|
|
16114
16374
|
return BUILDER_SHORT_TERMINALS.has(method) && expressionCallsBuilder(receiver);
|
|
16115
16375
|
}
|
|
16116
16376
|
function databaseReceiver(node) {
|
|
16117
|
-
if (node.type ===
|
|
16377
|
+
if (node.type === AST_NODE_TYPES71.Identifier)
|
|
16118
16378
|
return DATABASE_NAMES.test(node.name);
|
|
16119
|
-
if (node.type !==
|
|
16379
|
+
if (node.type !== AST_NODE_TYPES71.MemberExpression) return false;
|
|
16120
16380
|
const name = memberName5(node);
|
|
16121
16381
|
return name === "DB" || name !== null && DATABASE_NAMES.test(name);
|
|
16122
16382
|
}
|
|
16123
16383
|
function databaseRootMember(node) {
|
|
16124
16384
|
let current = node;
|
|
16125
16385
|
for (; ; ) {
|
|
16126
|
-
if (current.type ===
|
|
16386
|
+
if (current.type === AST_NODE_TYPES71.ChainExpression) {
|
|
16127
16387
|
current = current.expression;
|
|
16128
16388
|
continue;
|
|
16129
16389
|
}
|
|
16130
|
-
if (current.type ===
|
|
16390
|
+
if (current.type === AST_NODE_TYPES71.TSAsExpression || current.type === AST_NODE_TYPES71.TSNonNullExpression || current.type === AST_NODE_TYPES71.TSTypeAssertion) {
|
|
16131
16391
|
current = current.expression;
|
|
16132
16392
|
continue;
|
|
16133
16393
|
}
|
|
16134
|
-
if (current.type ===
|
|
16135
|
-
if (current.callee.type !==
|
|
16394
|
+
if (current.type === AST_NODE_TYPES71.CallExpression) {
|
|
16395
|
+
if (current.callee.type !== AST_NODE_TYPES71.MemberExpression) return null;
|
|
16136
16396
|
current = current.callee.object;
|
|
16137
16397
|
continue;
|
|
16138
16398
|
}
|
|
16139
|
-
if (current.type ===
|
|
16140
|
-
if (current.object.type ===
|
|
16399
|
+
if (current.type === AST_NODE_TYPES71.MemberExpression) {
|
|
16400
|
+
if (current.object.type === AST_NODE_TYPES71.ThisExpression)
|
|
16141
16401
|
return memberName5(current);
|
|
16142
16402
|
current = current.object;
|
|
16143
16403
|
continue;
|
|
16144
16404
|
}
|
|
16145
|
-
return current.type ===
|
|
16405
|
+
return current.type === AST_NODE_TYPES71.Identifier ? current.name : null;
|
|
16146
16406
|
}
|
|
16147
16407
|
}
|
|
16148
16408
|
function expressionHasDatabaseMarker(node) {
|
|
16149
16409
|
let current = node;
|
|
16150
16410
|
for (; ; ) {
|
|
16151
|
-
if (current.type ===
|
|
16411
|
+
if (current.type === AST_NODE_TYPES71.ChainExpression) {
|
|
16152
16412
|
current = current.expression;
|
|
16153
16413
|
continue;
|
|
16154
16414
|
}
|
|
16155
|
-
if (current.type ===
|
|
16415
|
+
if (current.type === AST_NODE_TYPES71.TSAsExpression || current.type === AST_NODE_TYPES71.TSNonNullExpression || current.type === AST_NODE_TYPES71.TSTypeAssertion) {
|
|
16156
16416
|
current = current.expression;
|
|
16157
16417
|
continue;
|
|
16158
16418
|
}
|
|
16159
|
-
if (current.type ===
|
|
16160
|
-
if (current.callee.type !==
|
|
16419
|
+
if (current.type === AST_NODE_TYPES71.CallExpression) {
|
|
16420
|
+
if (current.callee.type !== AST_NODE_TYPES71.MemberExpression) return false;
|
|
16161
16421
|
current = current.callee.object;
|
|
16162
16422
|
continue;
|
|
16163
16423
|
}
|
|
16164
|
-
if (current.type ===
|
|
16424
|
+
if (current.type === AST_NODE_TYPES71.MemberExpression) {
|
|
16165
16425
|
const name = memberName5(current);
|
|
16166
16426
|
if (name === "DB" || name !== null && DATABASE_NAMES.test(name))
|
|
16167
16427
|
return true;
|
|
16168
16428
|
current = current.object;
|
|
16169
16429
|
continue;
|
|
16170
16430
|
}
|
|
16171
|
-
return current.type ===
|
|
16431
|
+
return current.type === AST_NODE_TYPES71.Identifier && DATABASE_NAMES.test(current.name);
|
|
16172
16432
|
}
|
|
16173
16433
|
}
|
|
16174
16434
|
function expressionCallsBuilder(node) {
|
|
16175
16435
|
let current = node;
|
|
16176
16436
|
for (; ; ) {
|
|
16177
|
-
if (current.type ===
|
|
16437
|
+
if (current.type === AST_NODE_TYPES71.ChainExpression) {
|
|
16178
16438
|
current = current.expression;
|
|
16179
16439
|
continue;
|
|
16180
16440
|
}
|
|
16181
|
-
if (current.type ===
|
|
16441
|
+
if (current.type === AST_NODE_TYPES71.TSAsExpression || current.type === AST_NODE_TYPES71.TSNonNullExpression || current.type === AST_NODE_TYPES71.TSTypeAssertion) {
|
|
16182
16442
|
current = current.expression;
|
|
16183
16443
|
continue;
|
|
16184
16444
|
}
|
|
16185
|
-
if (current.type ===
|
|
16186
|
-
if (current.callee.type !==
|
|
16445
|
+
if (current.type === AST_NODE_TYPES71.CallExpression) {
|
|
16446
|
+
if (current.callee.type !== AST_NODE_TYPES71.MemberExpression) return false;
|
|
16187
16447
|
const name = memberName5(current.callee);
|
|
16188
16448
|
if (name !== null && BUILDER_METHODS.has(name)) return true;
|
|
16189
16449
|
current = current.callee.object;
|
|
16190
16450
|
continue;
|
|
16191
16451
|
}
|
|
16192
|
-
if (current.type !==
|
|
16452
|
+
if (current.type !== AST_NODE_TYPES71.MemberExpression) return false;
|
|
16193
16453
|
current = current.object;
|
|
16194
16454
|
}
|
|
16195
16455
|
}
|
|
16196
16456
|
function owningClass2(node) {
|
|
16197
16457
|
let current = node.parent;
|
|
16198
16458
|
while (current != null) {
|
|
16199
|
-
if (current.type ===
|
|
16459
|
+
if (current.type === AST_NODE_TYPES71.ClassDeclaration || current.type === AST_NODE_TYPES71.ClassExpression)
|
|
16200
16460
|
return current;
|
|
16201
16461
|
current = current.parent;
|
|
16202
16462
|
}
|
|
@@ -16205,25 +16465,25 @@ function owningClass2(node) {
|
|
|
16205
16465
|
function injectedMembers(owner) {
|
|
16206
16466
|
const injected = /* @__PURE__ */ new Set();
|
|
16207
16467
|
const constructor = owner.body.body.find(
|
|
16208
|
-
(member) => member.type ===
|
|
16468
|
+
(member) => member.type === AST_NODE_TYPES71.MethodDefinition && member.kind === "constructor"
|
|
16209
16469
|
);
|
|
16210
16470
|
if (constructor === void 0) return injected;
|
|
16211
16471
|
const parameters = /* @__PURE__ */ new Set();
|
|
16212
16472
|
for (const parameter of constructor.value.params) {
|
|
16213
16473
|
for (const name of parameterNames(parameter)) parameters.add(name);
|
|
16214
|
-
if (parameter.type !==
|
|
16215
|
-
const value = parameter.parameter.type ===
|
|
16216
|
-
if (value.type ===
|
|
16474
|
+
if (parameter.type !== AST_NODE_TYPES71.TSParameterProperty) continue;
|
|
16475
|
+
const value = parameter.parameter.type === AST_NODE_TYPES71.AssignmentPattern ? parameter.parameter.left : parameter.parameter;
|
|
16476
|
+
if (value.type === AST_NODE_TYPES71.Identifier) injected.add(value.name);
|
|
16217
16477
|
}
|
|
16218
16478
|
const body2 = constructor.value.body;
|
|
16219
16479
|
if (body2 === null) return injected;
|
|
16220
16480
|
for (const statement of body2.body) {
|
|
16221
|
-
if (statement.type !==
|
|
16481
|
+
if (statement.type !== AST_NODE_TYPES71.ExpressionStatement || statement.expression.type !== AST_NODE_TYPES71.AssignmentExpression || statement.expression.operator !== "=") continue;
|
|
16222
16482
|
const { left, right } = statement.expression;
|
|
16223
|
-
if (left.type !==
|
|
16483
|
+
if (left.type !== AST_NODE_TYPES71.MemberExpression) continue;
|
|
16224
16484
|
const target = thisRootMember(left);
|
|
16225
16485
|
if (target === null) continue;
|
|
16226
|
-
const source = right.type ===
|
|
16486
|
+
const source = right.type === AST_NODE_TYPES71.Identifier ? right.name : right.type === AST_NODE_TYPES71.MemberExpression && right.object.type === AST_NODE_TYPES71.Identifier ? right.object.name : null;
|
|
16227
16487
|
if (source !== null && parameters.has(source)) injected.add(target);
|
|
16228
16488
|
}
|
|
16229
16489
|
return injected;
|
|
@@ -16231,26 +16491,26 @@ function injectedMembers(owner) {
|
|
|
16231
16491
|
function thisRootMember(node) {
|
|
16232
16492
|
let current = node;
|
|
16233
16493
|
let root = null;
|
|
16234
|
-
while (current.type ===
|
|
16494
|
+
while (current.type === AST_NODE_TYPES71.MemberExpression) {
|
|
16235
16495
|
const name = memberName5(current);
|
|
16236
16496
|
if (name === null) return null;
|
|
16237
16497
|
root = name;
|
|
16238
16498
|
current = current.object;
|
|
16239
16499
|
}
|
|
16240
|
-
return current.type ===
|
|
16500
|
+
return current.type === AST_NODE_TYPES71.ThisExpression ? root : null;
|
|
16241
16501
|
}
|
|
16242
16502
|
function parameterNames(parameter) {
|
|
16243
16503
|
let value = parameter;
|
|
16244
|
-
if (value.type ===
|
|
16245
|
-
if (value.type ===
|
|
16246
|
-
if (value.type ===
|
|
16247
|
-
if (value.type !==
|
|
16504
|
+
if (value.type === AST_NODE_TYPES71.TSParameterProperty) value = value.parameter;
|
|
16505
|
+
if (value.type === AST_NODE_TYPES71.AssignmentPattern) value = value.left;
|
|
16506
|
+
if (value.type === AST_NODE_TYPES71.Identifier) return /* @__PURE__ */ new Set([value.name]);
|
|
16507
|
+
if (value.type !== AST_NODE_TYPES71.ObjectPattern) return /* @__PURE__ */ new Set();
|
|
16248
16508
|
return new Set(
|
|
16249
16509
|
value.properties.flatMap((property) => {
|
|
16250
|
-
if (property.type ===
|
|
16251
|
-
return property.argument.type ===
|
|
16252
|
-
const target = property.value.type ===
|
|
16253
|
-
return target.type ===
|
|
16510
|
+
if (property.type === AST_NODE_TYPES71.RestElement)
|
|
16511
|
+
return property.argument.type === AST_NODE_TYPES71.Identifier ? [property.argument.name] : [];
|
|
16512
|
+
const target = property.value.type === AST_NODE_TYPES71.AssignmentPattern ? property.value.left : property.value;
|
|
16513
|
+
return target.type === AST_NODE_TYPES71.Identifier ? [target.name] : [];
|
|
16254
16514
|
})
|
|
16255
16515
|
);
|
|
16256
16516
|
}
|
|
@@ -16273,7 +16533,7 @@ var require_sql_access_class_default = createRule({
|
|
|
16273
16533
|
return {};
|
|
16274
16534
|
return {
|
|
16275
16535
|
CallExpression(node) {
|
|
16276
|
-
if (node.callee.type !==
|
|
16536
|
+
if (node.callee.type !== AST_NODE_TYPES71.MemberExpression)
|
|
16277
16537
|
return;
|
|
16278
16538
|
const method = memberName5(node.callee);
|
|
16279
16539
|
if (method === null || !isDatabaseOperation(method, node.callee.object))
|
|
@@ -16290,7 +16550,7 @@ var require_sql_access_class_default = createRule({
|
|
|
16290
16550
|
});
|
|
16291
16551
|
|
|
16292
16552
|
// src/rules/require-static-next-matcher.ts
|
|
16293
|
-
import { AST_NODE_TYPES as
|
|
16553
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES72 } from "@typescript-eslint/utils";
|
|
16294
16554
|
var REQUIRE_STATIC_NEXT_MATCHER_DOCUMENTATION = {
|
|
16295
16555
|
summary: "Require Next.js middleware and proxy matcher configuration to contain only build-time literals.",
|
|
16296
16556
|
rationale: "Next.js must statically analyze matcher values at build time; computed values are ignored.",
|
|
@@ -16303,34 +16563,34 @@ var REQUIRE_STATIC_NEXT_MATCHER_DOCUMENTATION = {
|
|
|
16303
16563
|
};
|
|
16304
16564
|
var NEXT_ENTRY_FILE = /(?:^|[/\\])(?:middleware|proxy)\.[cm]?[jt]sx?$/u;
|
|
16305
16565
|
function unwrapExpression3(node) {
|
|
16306
|
-
if (node.type ===
|
|
16566
|
+
if (node.type === AST_NODE_TYPES72.TSAsExpression || node.type === AST_NODE_TYPES72.TSSatisfiesExpression || node.type === AST_NODE_TYPES72.TSNonNullExpression || node.type === AST_NODE_TYPES72.TSTypeAssertion) {
|
|
16307
16567
|
return unwrapExpression3(node.expression);
|
|
16308
16568
|
}
|
|
16309
16569
|
return node;
|
|
16310
16570
|
}
|
|
16311
16571
|
function isStaticValue(node) {
|
|
16312
16572
|
const value = unwrapExpression3(node);
|
|
16313
|
-
if (value.type ===
|
|
16573
|
+
if (value.type === AST_NODE_TYPES72.Literal) {
|
|
16314
16574
|
return true;
|
|
16315
16575
|
}
|
|
16316
|
-
if (value.type ===
|
|
16576
|
+
if (value.type === AST_NODE_TYPES72.TemplateLiteral) {
|
|
16317
16577
|
return value.expressions.length === 0;
|
|
16318
16578
|
}
|
|
16319
|
-
if (value.type ===
|
|
16579
|
+
if (value.type === AST_NODE_TYPES72.ArrayExpression) {
|
|
16320
16580
|
return value.elements.every(
|
|
16321
|
-
(element) => element !== null && element.type !==
|
|
16581
|
+
(element) => element !== null && element.type !== AST_NODE_TYPES72.SpreadElement && isStaticValue(element)
|
|
16322
16582
|
);
|
|
16323
16583
|
}
|
|
16324
|
-
if (value.type ===
|
|
16584
|
+
if (value.type === AST_NODE_TYPES72.ObjectExpression) {
|
|
16325
16585
|
return value.properties.every(
|
|
16326
|
-
(property) => property.type ===
|
|
16586
|
+
(property) => property.type === AST_NODE_TYPES72.Property && property.kind === "init" && !property.computed && property.value.type !== AST_NODE_TYPES72.AssignmentPattern && isStaticValue(property.value)
|
|
16327
16587
|
);
|
|
16328
16588
|
}
|
|
16329
16589
|
return false;
|
|
16330
16590
|
}
|
|
16331
16591
|
function propertyName6(property) {
|
|
16332
16592
|
if (property.computed) return null;
|
|
16333
|
-
if (property.key.type ===
|
|
16593
|
+
if (property.key.type === AST_NODE_TYPES72.Identifier) return property.key.name;
|
|
16334
16594
|
return typeof property.key.value === "string" ? property.key.value : null;
|
|
16335
16595
|
}
|
|
16336
16596
|
var require_static_next_matcher_default = createRule({
|
|
@@ -16353,19 +16613,19 @@ var require_static_next_matcher_default = createRule({
|
|
|
16353
16613
|
}
|
|
16354
16614
|
return {
|
|
16355
16615
|
ExportNamedDeclaration(node) {
|
|
16356
|
-
if (node.declaration?.type !==
|
|
16616
|
+
if (node.declaration?.type !== AST_NODE_TYPES72.VariableDeclaration) {
|
|
16357
16617
|
return;
|
|
16358
16618
|
}
|
|
16359
16619
|
for (const declaration of node.declaration.declarations) {
|
|
16360
|
-
if (declaration.id.type !==
|
|
16620
|
+
if (declaration.id.type !== AST_NODE_TYPES72.Identifier || declaration.id.name !== "config" || declaration.init === null) {
|
|
16361
16621
|
continue;
|
|
16362
16622
|
}
|
|
16363
16623
|
const config = unwrapExpression3(declaration.init);
|
|
16364
|
-
if (config.type !==
|
|
16624
|
+
if (config.type !== AST_NODE_TYPES72.ObjectExpression) {
|
|
16365
16625
|
continue;
|
|
16366
16626
|
}
|
|
16367
16627
|
for (const property of config.properties) {
|
|
16368
|
-
if (property.type !==
|
|
16628
|
+
if (property.type !== AST_NODE_TYPES72.Property || propertyName6(property) !== "matcher" || property.value.type === AST_NODE_TYPES72.AssignmentPattern) {
|
|
16369
16629
|
continue;
|
|
16370
16630
|
}
|
|
16371
16631
|
if (!isStaticValue(property.value)) {
|
|
@@ -16516,7 +16776,7 @@ var require_use_server_in_actions_file_default = createRule({
|
|
|
16516
16776
|
|
|
16517
16777
|
// src/rules/require-zod-form-validation.ts
|
|
16518
16778
|
import {
|
|
16519
|
-
AST_NODE_TYPES as
|
|
16779
|
+
AST_NODE_TYPES as AST_NODE_TYPES73,
|
|
16520
16780
|
ASTUtils as ASTUtils22
|
|
16521
16781
|
} from "@typescript-eslint/utils";
|
|
16522
16782
|
var REQUIRE_ZOD_FORM_VALIDATION_DOCUMENTATION = {
|
|
@@ -16543,14 +16803,14 @@ var FORM_VALUE_METHODS = /* @__PURE__ */ new Set(["get", "getAll"]);
|
|
|
16543
16803
|
var zodReceiverRoot = (node) => {
|
|
16544
16804
|
let current = node;
|
|
16545
16805
|
while (true) {
|
|
16546
|
-
if (current.type ===
|
|
16806
|
+
if (current.type === AST_NODE_TYPES73.Identifier) {
|
|
16547
16807
|
return current;
|
|
16548
16808
|
}
|
|
16549
|
-
if (current.type ===
|
|
16809
|
+
if (current.type === AST_NODE_TYPES73.CallExpression) {
|
|
16550
16810
|
current = current.callee;
|
|
16551
16811
|
continue;
|
|
16552
16812
|
}
|
|
16553
|
-
if (current.type ===
|
|
16813
|
+
if (current.type === AST_NODE_TYPES73.MemberExpression) {
|
|
16554
16814
|
current = current.object;
|
|
16555
16815
|
continue;
|
|
16556
16816
|
}
|
|
@@ -16559,12 +16819,12 @@ var zodReceiverRoot = (node) => {
|
|
|
16559
16819
|
};
|
|
16560
16820
|
var isFormDataMethodCall = (node) => {
|
|
16561
16821
|
let current = node;
|
|
16562
|
-
if (current.type ===
|
|
16822
|
+
if (current.type === AST_NODE_TYPES73.AwaitExpression) {
|
|
16563
16823
|
current = current.argument;
|
|
16564
16824
|
}
|
|
16565
|
-
if (current.type !==
|
|
16825
|
+
if (current.type !== AST_NODE_TYPES73.CallExpression) return false;
|
|
16566
16826
|
const callee = current.callee;
|
|
16567
|
-
return callee.type ===
|
|
16827
|
+
return callee.type === AST_NODE_TYPES73.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES73.Identifier && callee.property.name === "formData";
|
|
16568
16828
|
};
|
|
16569
16829
|
var require_zod_form_validation_default = createRule({
|
|
16570
16830
|
name: "require-zod-form-validation",
|
|
@@ -16595,16 +16855,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
16595
16855
|
return false;
|
|
16596
16856
|
}
|
|
16597
16857
|
const definition = binding.defs[0];
|
|
16598
|
-
if (definition?.type !== "Variable" || definition.node.type !==
|
|
16858
|
+
if (definition?.type !== "Variable" || definition.node.type !== AST_NODE_TYPES73.VariableDeclarator) {
|
|
16599
16859
|
return false;
|
|
16600
16860
|
}
|
|
16601
16861
|
const init = definition.node.init;
|
|
16602
|
-
return init?.type ===
|
|
16862
|
+
return init?.type === AST_NODE_TYPES73.ObjectExpression || init?.type === AST_NODE_TYPES73.ArrayExpression || init?.type === AST_NODE_TYPES73.Literal || init?.type === AST_NODE_TYPES73.ArrowFunctionExpression || init?.type === AST_NODE_TYPES73.FunctionExpression;
|
|
16603
16863
|
};
|
|
16604
16864
|
const isZodParseCall = (node) => {
|
|
16605
|
-
if (node.type !==
|
|
16865
|
+
if (node.type !== AST_NODE_TYPES73.CallExpression) return false;
|
|
16606
16866
|
const callee = node.callee;
|
|
16607
|
-
if (callee.type !==
|
|
16867
|
+
if (callee.type !== AST_NODE_TYPES73.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES73.Identifier || !ZOD_PARSE_METHODS.has(callee.property.name)) {
|
|
16608
16868
|
return false;
|
|
16609
16869
|
}
|
|
16610
16870
|
const root = zodReceiverRoot(callee.object);
|
|
@@ -16613,14 +16873,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
16613
16873
|
return binding !== null && zodBindings.has(binding) || (root.name === "z" || ZOD_SCHEMA_NAME_RE.test(root.name)) && !isProvablyNonZodLocal(root);
|
|
16614
16874
|
};
|
|
16615
16875
|
const isFormSourceIdentifier = (node) => {
|
|
16616
|
-
if (node.type !==
|
|
16876
|
+
if (node.type !== AST_NODE_TYPES73.Identifier) return false;
|
|
16617
16877
|
const conventionalName = /formdata/i.test(node.name);
|
|
16618
16878
|
let scope = context.sourceCode.getScope(node);
|
|
16619
16879
|
while (scope !== null) {
|
|
16620
16880
|
const variable = scope.set.get(node.name);
|
|
16621
16881
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
16622
16882
|
const def = variable.defs[0];
|
|
16623
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
16883
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === AST_NODE_TYPES73.VariableDeclarator && def.node.init !== null) {
|
|
16624
16884
|
return isFormDataMethodCall(def.node.init);
|
|
16625
16885
|
}
|
|
16626
16886
|
return def?.type === "Parameter" && conventionalName;
|
|
@@ -16631,8 +16891,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
16631
16891
|
};
|
|
16632
16892
|
const isFormDataGetCall = (node) => {
|
|
16633
16893
|
const callee = node.callee;
|
|
16634
|
-
if (callee.type !==
|
|
16635
|
-
if (callee.property.type !==
|
|
16894
|
+
if (callee.type !== AST_NODE_TYPES73.MemberExpression) return false;
|
|
16895
|
+
if (callee.property.type !== AST_NODE_TYPES73.Identifier || !FORM_VALUE_METHODS.has(callee.property.name)) {
|
|
16636
16896
|
return false;
|
|
16637
16897
|
}
|
|
16638
16898
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -16648,16 +16908,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
16648
16908
|
const hasZodParseAncestor = (node) => zodParseAncestor(node) !== null;
|
|
16649
16909
|
const isInstanceofNarrowing = (node) => {
|
|
16650
16910
|
const parent = node.parent;
|
|
16651
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
16911
|
+
return parent !== null && parent !== void 0 && parent.type === AST_NODE_TYPES73.BinaryExpression && parent.operator === "instanceof" && parent.left === node && parent.right.type === AST_NODE_TYPES73.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
16652
16912
|
};
|
|
16653
16913
|
const boundDeclarator = (node) => {
|
|
16654
16914
|
let current = node;
|
|
16655
16915
|
let parent = current.parent;
|
|
16656
|
-
while ((parent.type ===
|
|
16916
|
+
while ((parent.type === AST_NODE_TYPES73.TSAsExpression || parent.type === AST_NODE_TYPES73.TSSatisfiesExpression || parent.type === AST_NODE_TYPES73.TSNonNullExpression || parent.type === AST_NODE_TYPES73.ChainExpression) && parent.expression === current) {
|
|
16657
16917
|
current = parent;
|
|
16658
16918
|
parent = current.parent;
|
|
16659
16919
|
}
|
|
16660
|
-
if (parent.type ===
|
|
16920
|
+
if (parent.type === AST_NODE_TYPES73.VariableDeclarator && parent.init === current && parent.id.type === AST_NODE_TYPES73.Identifier) {
|
|
16661
16921
|
return parent;
|
|
16662
16922
|
}
|
|
16663
16923
|
return null;
|
|
@@ -16666,7 +16926,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
16666
16926
|
let current = node;
|
|
16667
16927
|
while (current.parent !== void 0) {
|
|
16668
16928
|
const parent = current.parent;
|
|
16669
|
-
if (parent.type ===
|
|
16929
|
+
if (parent.type === AST_NODE_TYPES73.BlockStatement || parent.type === AST_NODE_TYPES73.Program) {
|
|
16670
16930
|
return current;
|
|
16671
16931
|
}
|
|
16672
16932
|
current = parent;
|
|
@@ -16675,12 +16935,12 @@ var require_zod_form_validation_default = createRule({
|
|
|
16675
16935
|
};
|
|
16676
16936
|
const zodParseMethod = (call) => {
|
|
16677
16937
|
const callee = call.callee;
|
|
16678
|
-
return callee.type ===
|
|
16938
|
+
return callee.type === AST_NODE_TYPES73.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES73.Identifier ? callee.property.name : null;
|
|
16679
16939
|
};
|
|
16680
16940
|
const hasConditionalAncestorBeforeStatement = (node, statement) => {
|
|
16681
16941
|
let current = node.parent;
|
|
16682
16942
|
while (current !== void 0 && current !== statement) {
|
|
16683
|
-
if (current.type ===
|
|
16943
|
+
if (current.type === AST_NODE_TYPES73.LogicalExpression || current.type === AST_NODE_TYPES73.ConditionalExpression) {
|
|
16684
16944
|
return true;
|
|
16685
16945
|
}
|
|
16686
16946
|
current = current.parent;
|
|
@@ -16690,7 +16950,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
16690
16950
|
const isAwaitedBeforeStatement = (node, statement) => {
|
|
16691
16951
|
let current = node.parent;
|
|
16692
16952
|
while (current !== void 0 && current !== statement) {
|
|
16693
|
-
if (current.type ===
|
|
16953
|
+
if (current.type === AST_NODE_TYPES73.AwaitExpression) return true;
|
|
16694
16954
|
current = current.parent;
|
|
16695
16955
|
}
|
|
16696
16956
|
return false;
|
|
@@ -16703,7 +16963,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
16703
16963
|
if (declarationStatement === null || validationStatement === null || declarationStatement.parent !== validationStatement.parent || validationStatement.range[0] <= declarationStatement.range[1] || hasConditionalAncestorBeforeStatement(parse2, validationStatement)) {
|
|
16704
16964
|
return null;
|
|
16705
16965
|
}
|
|
16706
|
-
if (validationStatement.type !==
|
|
16966
|
+
if (validationStatement.type !== AST_NODE_TYPES73.VariableDeclaration && validationStatement.type !== AST_NODE_TYPES73.ExpressionStatement) {
|
|
16707
16967
|
return null;
|
|
16708
16968
|
}
|
|
16709
16969
|
const method = zodParseMethod(parse2);
|
|
@@ -16715,16 +16975,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
16715
16975
|
};
|
|
16716
16976
|
const isSafePrevalidationInspection = (identifier) => {
|
|
16717
16977
|
const parent = identifier.parent;
|
|
16718
|
-
if (parent.type ===
|
|
16978
|
+
if (parent.type === AST_NODE_TYPES73.UnaryExpression && parent.operator === "typeof") {
|
|
16719
16979
|
return true;
|
|
16720
16980
|
}
|
|
16721
|
-
if (parent.type !==
|
|
16981
|
+
if (parent.type !== AST_NODE_TYPES73.BinaryExpression || parent.left !== identifier) {
|
|
16722
16982
|
return false;
|
|
16723
16983
|
}
|
|
16724
16984
|
if (parent.operator === "instanceof") {
|
|
16725
|
-
return parent.right.type ===
|
|
16985
|
+
return parent.right.type === AST_NODE_TYPES73.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
16726
16986
|
}
|
|
16727
|
-
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type ===
|
|
16987
|
+
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type === AST_NODE_TYPES73.Literal && parent.right.value === null || parent.right.type === AST_NODE_TYPES73.Identifier && parent.right.name === "undefined");
|
|
16728
16988
|
};
|
|
16729
16989
|
const isDescendantOf = (node, ancestor) => {
|
|
16730
16990
|
let current = node;
|
|
@@ -16735,23 +16995,23 @@ var require_zod_form_validation_default = createRule({
|
|
|
16735
16995
|
return false;
|
|
16736
16996
|
};
|
|
16737
16997
|
const blockTerminates = (node) => {
|
|
16738
|
-
if (node.type ===
|
|
16998
|
+
if (node.type === AST_NODE_TYPES73.ReturnStatement || node.type === AST_NODE_TYPES73.ThrowStatement) {
|
|
16739
16999
|
return true;
|
|
16740
17000
|
}
|
|
16741
|
-
if (node.type !==
|
|
17001
|
+
if (node.type !== AST_NODE_TYPES73.BlockStatement || node.body.length === 0) return false;
|
|
16742
17002
|
const last = node.body.at(-1);
|
|
16743
17003
|
return last !== void 0 && blockTerminates(last);
|
|
16744
17004
|
};
|
|
16745
17005
|
const narrowingIf = (identifier) => {
|
|
16746
17006
|
const comparison = identifier.parent;
|
|
16747
|
-
if (comparison?.type !==
|
|
17007
|
+
if (comparison?.type !== AST_NODE_TYPES73.BinaryExpression || comparison.operator !== "instanceof" || comparison.left !== identifier || comparison.right.type !== AST_NODE_TYPES73.Identifier || comparison.right.name !== "File" && comparison.right.name !== "Blob") {
|
|
16748
17008
|
return null;
|
|
16749
17009
|
}
|
|
16750
17010
|
const maybeNegation = comparison.parent;
|
|
16751
|
-
const negated = maybeNegation?.type ===
|
|
17011
|
+
const negated = maybeNegation?.type === AST_NODE_TYPES73.UnaryExpression && maybeNegation.operator === "!";
|
|
16752
17012
|
const test = negated ? maybeNegation : comparison;
|
|
16753
17013
|
const branch = test.parent;
|
|
16754
|
-
return branch?.type ===
|
|
17014
|
+
return branch?.type === AST_NODE_TYPES73.IfStatement && branch.test === test ? { branch, positive: !negated } : null;
|
|
16755
17015
|
};
|
|
16756
17016
|
const useDominatedByNarrowing = (use, narrowings) => narrowings.some(({ branch, positive }) => {
|
|
16757
17017
|
if (positive) return isDescendantOf(use, branch.consequent);
|
|
@@ -16771,7 +17031,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
16771
17031
|
const variable = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
16772
17032
|
if (variable === void 0) return false;
|
|
16773
17033
|
const references = variable.references.filter((reference) => !reference.isWriteOnly()).map((reference) => reference.identifier).filter(
|
|
16774
|
-
(identifier) => identifier.type ===
|
|
17034
|
+
(identifier) => identifier.type === AST_NODE_TYPES73.Identifier
|
|
16775
17035
|
);
|
|
16776
17036
|
if (references.length === 0) return false;
|
|
16777
17037
|
const narrowings = references.map(narrowingIf).filter(
|
|
@@ -16797,7 +17057,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
16797
17057
|
ImportDeclaration(node) {
|
|
16798
17058
|
if (!isZodModule(node.source.value)) return;
|
|
16799
17059
|
for (const specifier of node.specifiers) {
|
|
16800
|
-
if (specifier.type ===
|
|
17060
|
+
if (specifier.type === AST_NODE_TYPES73.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES73.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES73.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES73.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
16801
17061
|
const binding = resolvedBinding(specifier.local);
|
|
16802
17062
|
if (binding !== null) zodBindings.add(binding);
|
|
16803
17063
|
}
|
|
@@ -16882,7 +17142,7 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
16882
17142
|
});
|
|
16883
17143
|
|
|
16884
17144
|
// src/rules/stepdown.ts
|
|
16885
|
-
import { AST_NODE_TYPES as
|
|
17145
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES74, ASTUtils as ASTUtils23 } from "@typescript-eslint/utils";
|
|
16886
17146
|
var STEPDOWN_DOCUMENTATION = {
|
|
16887
17147
|
summary: "Place a private helper below its sole direct same-scope caller.",
|
|
16888
17148
|
rationale: "Caller-first ordering lets a reader follow the main flow before descending into implementation details.",
|
|
@@ -16902,7 +17162,7 @@ var STEPDOWN_DOCUMENTATION = {
|
|
|
16902
17162
|
]
|
|
16903
17163
|
};
|
|
16904
17164
|
function isFunction(node) {
|
|
16905
|
-
return node.type ===
|
|
17165
|
+
return node.type === AST_NODE_TYPES74.ArrowFunctionExpression || node.type === AST_NODE_TYPES74.FunctionDeclaration || node.type === AST_NODE_TYPES74.FunctionExpression;
|
|
16906
17166
|
}
|
|
16907
17167
|
function reportMisordered(context, candidates, scopeDefinitions, calls, pinned, canMove = () => true, makeFix) {
|
|
16908
17168
|
const byName = new Map(scopeDefinitions.map((definition) => [definition.name, definition]));
|
|
@@ -16999,8 +17259,8 @@ function moduleScope(context, program) {
|
|
|
16999
17259
|
for (const node of declarations) counts.set(node.name, (counts.get(node.name) ?? 0) + 1);
|
|
17000
17260
|
const overloadNames = new Set(
|
|
17001
17261
|
program.body.flatMap((statement) => {
|
|
17002
|
-
const node = statement.type ===
|
|
17003
|
-
return node?.type ===
|
|
17262
|
+
const node = statement.type === AST_NODE_TYPES74.ExportNamedDeclaration ? statement.declaration : statement;
|
|
17263
|
+
return node?.type === AST_NODE_TYPES74.TSDeclareFunction && node.id !== null ? [node.id.name] : [];
|
|
17004
17264
|
})
|
|
17005
17265
|
);
|
|
17006
17266
|
const exported = exportedNames(program);
|
|
@@ -17024,7 +17284,7 @@ function moduleScope(context, program) {
|
|
|
17024
17284
|
const nearestFunction2 = [...ancestors].reverse().find(isFunction);
|
|
17025
17285
|
const parent = identifier.parent;
|
|
17026
17286
|
const callerDefinition = nearestFunction2 === void 0 ? void 0 : byFunction.get(nearestFunction2);
|
|
17027
|
-
if (callerDefinition === void 0 || parent.type !==
|
|
17287
|
+
if (callerDefinition === void 0 || parent.type !== AST_NODE_TYPES74.CallExpression || parent.callee !== identifier) {
|
|
17028
17288
|
pinned.add(definition.name);
|
|
17029
17289
|
continue;
|
|
17030
17290
|
}
|
|
@@ -17039,38 +17299,38 @@ function moduleScope(context, program) {
|
|
|
17039
17299
|
function exportedNames(program) {
|
|
17040
17300
|
const names = /* @__PURE__ */ new Set();
|
|
17041
17301
|
for (const statement of program.body) {
|
|
17042
|
-
if (statement.type !==
|
|
17043
|
-
if (statement.declaration?.type ===
|
|
17302
|
+
if (statement.type !== AST_NODE_TYPES74.ExportNamedDeclaration || statement.exportKind === "type" || statement.source !== null) continue;
|
|
17303
|
+
if (statement.declaration?.type === AST_NODE_TYPES74.FunctionDeclaration && statement.declaration.id !== null) {
|
|
17044
17304
|
names.add(statement.declaration.id.name);
|
|
17045
17305
|
}
|
|
17046
|
-
if (statement.declaration?.type ===
|
|
17306
|
+
if (statement.declaration?.type === AST_NODE_TYPES74.VariableDeclaration) {
|
|
17047
17307
|
for (const declarator of statement.declaration.declarations) {
|
|
17048
|
-
if (declarator.id.type ===
|
|
17308
|
+
if (declarator.id.type === AST_NODE_TYPES74.Identifier) names.add(declarator.id.name);
|
|
17049
17309
|
}
|
|
17050
17310
|
}
|
|
17051
17311
|
for (const specifier of statement.specifiers) {
|
|
17052
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
17312
|
+
if (specifier.exportKind !== "type" && specifier.local.type === AST_NODE_TYPES74.Identifier) {
|
|
17053
17313
|
names.add(specifier.local.name);
|
|
17054
17314
|
}
|
|
17055
17315
|
}
|
|
17056
17316
|
}
|
|
17057
17317
|
for (const statement of program.body) {
|
|
17058
|
-
if (statement.type ===
|
|
17059
|
-
if (statement.type ===
|
|
17318
|
+
if (statement.type === AST_NODE_TYPES74.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES74.Identifier) names.add(statement.declaration.name);
|
|
17319
|
+
if (statement.type === AST_NODE_TYPES74.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES74.FunctionDeclaration && statement.declaration.id !== null) names.add(statement.declaration.id.name);
|
|
17060
17320
|
}
|
|
17061
17321
|
return names;
|
|
17062
17322
|
}
|
|
17063
17323
|
function moduleDefinitions(program) {
|
|
17064
17324
|
const definitions = [];
|
|
17065
17325
|
for (const statement of program.body) {
|
|
17066
|
-
const node = statement.type ===
|
|
17067
|
-
if (node?.type ===
|
|
17326
|
+
const node = statement.type === AST_NODE_TYPES74.ExportNamedDeclaration || statement.type === AST_NODE_TYPES74.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
17327
|
+
if (node?.type === AST_NODE_TYPES74.FunctionDeclaration && node.id !== null && node.body !== null) {
|
|
17068
17328
|
definitions.push({ name: node.id.name, node, functionNode: node, bindingNode: node });
|
|
17069
17329
|
continue;
|
|
17070
17330
|
}
|
|
17071
|
-
if (node?.type !==
|
|
17331
|
+
if (node?.type !== AST_NODE_TYPES74.VariableDeclaration || node.kind !== "const") continue;
|
|
17072
17332
|
for (const declarator of node.declarations) {
|
|
17073
|
-
if (declarator.id.type ===
|
|
17333
|
+
if (declarator.id.type === AST_NODE_TYPES74.Identifier && declarator.init !== null && isFunction(declarator.init)) {
|
|
17074
17334
|
definitions.push({
|
|
17075
17335
|
name: declarator.id.name,
|
|
17076
17336
|
node: declarator,
|
|
@@ -17083,21 +17343,21 @@ function moduleDefinitions(program) {
|
|
|
17083
17343
|
return definitions;
|
|
17084
17344
|
}
|
|
17085
17345
|
function methodName(node) {
|
|
17086
|
-
if (node.key.type ===
|
|
17087
|
-
return !node.computed && node.key.type ===
|
|
17346
|
+
if (node.key.type === AST_NODE_TYPES74.PrivateIdentifier) return `#${node.key.name}`;
|
|
17347
|
+
return !node.computed && node.key.type === AST_NODE_TYPES74.Identifier ? node.key.name : null;
|
|
17088
17348
|
}
|
|
17089
17349
|
function referencedMethod(context, node, classVariables) {
|
|
17090
|
-
const objectVariable = node.object.type ===
|
|
17350
|
+
const objectVariable = node.object.type === AST_NODE_TYPES74.Identifier ? ASTUtils23.findVariable(context.sourceCode.getScope(node.object), node.object.name) : null;
|
|
17091
17351
|
const isClassReference = objectVariable !== null && classVariables.has(objectVariable);
|
|
17092
|
-
if (node.object.type !==
|
|
17093
|
-
if (node.property.type ===
|
|
17094
|
-
if (!node.computed && node.property.type ===
|
|
17095
|
-
return node.computed && node.property.type ===
|
|
17352
|
+
if (node.object.type !== AST_NODE_TYPES74.ThisExpression && !isClassReference) return null;
|
|
17353
|
+
if (node.property.type === AST_NODE_TYPES74.PrivateIdentifier) return `#${node.property.name}`;
|
|
17354
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES74.Identifier) return node.property.name;
|
|
17355
|
+
return node.computed && node.property.type === AST_NODE_TYPES74.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
17096
17356
|
}
|
|
17097
17357
|
function referencedPropertyName(node) {
|
|
17098
|
-
if (node.property.type ===
|
|
17099
|
-
if (!node.computed && node.property.type ===
|
|
17100
|
-
return node.computed && node.property.type ===
|
|
17358
|
+
if (node.property.type === AST_NODE_TYPES74.PrivateIdentifier) return `#${node.property.name}`;
|
|
17359
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES74.Identifier) return node.property.name;
|
|
17360
|
+
return node.computed && node.property.type === AST_NODE_TYPES74.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
17101
17361
|
}
|
|
17102
17362
|
function walk2(node, visitorKeys, visit, nestedFunction = false) {
|
|
17103
17363
|
visit(node, nestedFunction);
|
|
@@ -17113,7 +17373,7 @@ function walk2(node, visitorKeys, visit, nestedFunction = false) {
|
|
|
17113
17373
|
}
|
|
17114
17374
|
function classScope(context, node, computedReferenceNames) {
|
|
17115
17375
|
const methods = node.body.body.filter(
|
|
17116
|
-
(member) => member.type ===
|
|
17376
|
+
(member) => member.type === AST_NODE_TYPES74.MethodDefinition
|
|
17117
17377
|
);
|
|
17118
17378
|
const counts = /* @__PURE__ */ new Map();
|
|
17119
17379
|
for (const method of methods) {
|
|
@@ -17121,8 +17381,8 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
17121
17381
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
17122
17382
|
}
|
|
17123
17383
|
for (const member of node.body.body) {
|
|
17124
|
-
if (member.type !==
|
|
17125
|
-
const name = !member.computed && member.key.type ===
|
|
17384
|
+
if (member.type !== AST_NODE_TYPES74.TSAbstractMethodDefinition) continue;
|
|
17385
|
+
const name = !member.computed && member.key.type === AST_NODE_TYPES74.Identifier ? member.key.name : null;
|
|
17126
17386
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
17127
17387
|
}
|
|
17128
17388
|
const scopeDefinitions = methods.flatMap((method) => {
|
|
@@ -17131,7 +17391,7 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
17131
17391
|
});
|
|
17132
17392
|
const definitions = methods.flatMap((method) => {
|
|
17133
17393
|
const name = methodName(method);
|
|
17134
|
-
const isPrivate = method.accessibility === "private" || method.key.type ===
|
|
17394
|
+
const isPrivate = method.accessibility === "private" || method.key.type === AST_NODE_TYPES74.PrivateIdentifier;
|
|
17135
17395
|
return name !== null && isPrivate && counts.get(name) === 1 && method.decorators.length === 0 ? [{ name, node: method }] : [];
|
|
17136
17396
|
});
|
|
17137
17397
|
if (definitions.length === 0) return;
|
|
@@ -17143,7 +17403,7 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
17143
17403
|
const internal = ASTUtils23.findVariable(context.sourceCode.getScope(node), node.id.name);
|
|
17144
17404
|
if (internal !== null) classVariables.add(internal);
|
|
17145
17405
|
}
|
|
17146
|
-
if (node.type ===
|
|
17406
|
+
if (node.type === AST_NODE_TYPES74.ClassExpression && node.parent.type === AST_NODE_TYPES74.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES74.Identifier) {
|
|
17147
17407
|
const outer = ASTUtils23.findVariable(context.sourceCode.getScope(node.parent), node.parent.id.name);
|
|
17148
17408
|
if (outer !== null) classVariables.add(outer);
|
|
17149
17409
|
}
|
|
@@ -17160,26 +17420,26 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
17160
17420
|
}
|
|
17161
17421
|
const thisValue = (value) => {
|
|
17162
17422
|
let current = value;
|
|
17163
|
-
while (current?.type ===
|
|
17164
|
-
return current?.type ===
|
|
17423
|
+
while (current?.type === AST_NODE_TYPES74.TSAsExpression || current?.type === AST_NODE_TYPES74.TSSatisfiesExpression || current?.type === AST_NODE_TYPES74.TSNonNullExpression) current = current.expression;
|
|
17424
|
+
return current?.type === AST_NODE_TYPES74.ThisExpression;
|
|
17165
17425
|
};
|
|
17166
17426
|
const collectAlias = (current, nestedFunction) => {
|
|
17167
|
-
if (nestedFunction || current.type !==
|
|
17168
|
-
if (current.type ===
|
|
17169
|
-
const binding = current.type ===
|
|
17170
|
-
const value = current.type ===
|
|
17427
|
+
if (nestedFunction || current.type !== AST_NODE_TYPES74.VariableDeclarator && current.type !== AST_NODE_TYPES74.AssignmentPattern) return;
|
|
17428
|
+
if (current.type === AST_NODE_TYPES74.VariableDeclarator && (current.parent.type !== AST_NODE_TYPES74.VariableDeclaration || current.parent.kind !== "const")) return;
|
|
17429
|
+
const binding = current.type === AST_NODE_TYPES74.VariableDeclarator ? current.id : current.left;
|
|
17430
|
+
const value = current.type === AST_NODE_TYPES74.VariableDeclarator ? current.init : current.right;
|
|
17171
17431
|
if (!thisValue(value)) return;
|
|
17172
|
-
if (binding.type ===
|
|
17432
|
+
if (binding.type === AST_NODE_TYPES74.ObjectPattern) {
|
|
17173
17433
|
for (const property of binding.properties) {
|
|
17174
|
-
if (property.type ===
|
|
17434
|
+
if (property.type === AST_NODE_TYPES74.RestElement) {
|
|
17175
17435
|
for (const name of privateNames) pinned.add(name);
|
|
17176
|
-
} else if (property.key.type ===
|
|
17436
|
+
} else if (property.key.type === AST_NODE_TYPES74.Identifier && privateNames.has(property.key.name)) {
|
|
17177
17437
|
pinned.add(property.key.name);
|
|
17178
17438
|
}
|
|
17179
17439
|
}
|
|
17180
17440
|
return;
|
|
17181
17441
|
}
|
|
17182
|
-
if (binding.type !==
|
|
17442
|
+
if (binding.type !== AST_NODE_TYPES74.Identifier) return;
|
|
17183
17443
|
const variable = ASTUtils23.findVariable(context.sourceCode.getScope(binding), binding.name);
|
|
17184
17444
|
if (variable !== null) {
|
|
17185
17445
|
methodClassVariables.add(variable);
|
|
@@ -17193,16 +17453,16 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
17193
17453
|
walk2(statement, context.sourceCode.visitorKeys, collectAlias);
|
|
17194
17454
|
}
|
|
17195
17455
|
const visitCall = (current, nestedFunction) => {
|
|
17196
|
-
if (current.type ===
|
|
17456
|
+
if (current.type === AST_NODE_TYPES74.VariableDeclarator && current.id.type === AST_NODE_TYPES74.ObjectPattern && thisValue(current.init)) {
|
|
17197
17457
|
for (const property of current.id.properties) {
|
|
17198
|
-
if (property.type ===
|
|
17458
|
+
if (property.type === AST_NODE_TYPES74.RestElement) {
|
|
17199
17459
|
for (const name of privateNames) pinned.add(name);
|
|
17200
17460
|
continue;
|
|
17201
17461
|
}
|
|
17202
|
-
if (property.type ===
|
|
17462
|
+
if (property.type === AST_NODE_TYPES74.Property && property.key.type === AST_NODE_TYPES74.Identifier && privateNames.has(property.key.name)) pinned.add(property.key.name);
|
|
17203
17463
|
}
|
|
17204
17464
|
}
|
|
17205
|
-
if (current.type !==
|
|
17465
|
+
if (current.type !== AST_NODE_TYPES74.MemberExpression) return;
|
|
17206
17466
|
const target = referencedMethod(context, current, methodClassVariables);
|
|
17207
17467
|
if (target === null) {
|
|
17208
17468
|
const possibleTarget = referencedPropertyName(current);
|
|
@@ -17210,12 +17470,12 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
17210
17470
|
return;
|
|
17211
17471
|
}
|
|
17212
17472
|
if (!privateNames.has(target)) return;
|
|
17213
|
-
const objectVariable = current.object.type ===
|
|
17473
|
+
const objectVariable = current.object.type === AST_NODE_TYPES74.Identifier ? ASTUtils23.findVariable(context.sourceCode.getScope(current.object), current.object.name) : null;
|
|
17214
17474
|
if (objectVariable !== null && methodAliases.has(objectVariable)) {
|
|
17215
17475
|
pinned.add(target);
|
|
17216
17476
|
return;
|
|
17217
17477
|
}
|
|
17218
|
-
if (current.computed || nestedFunction || parameterDecoratorNodes.has(current) || current.parent.type !==
|
|
17478
|
+
if (current.computed || nestedFunction || parameterDecoratorNodes.has(current) || current.parent.type !== AST_NODE_TYPES74.CallExpression || current.parent.callee !== current) {
|
|
17219
17479
|
pinned.add(target);
|
|
17220
17480
|
return;
|
|
17221
17481
|
}
|
|
@@ -17235,9 +17495,9 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
17235
17495
|
}
|
|
17236
17496
|
}
|
|
17237
17497
|
for (const member of node.body.body) {
|
|
17238
|
-
if (member.type ===
|
|
17498
|
+
if (member.type === AST_NODE_TYPES74.MethodDefinition || member.type === AST_NODE_TYPES74.TSAbstractMethodDefinition) continue;
|
|
17239
17499
|
walk2(member, context.sourceCode.visitorKeys, (current) => {
|
|
17240
|
-
if (current.type !==
|
|
17500
|
+
if (current.type !== AST_NODE_TYPES74.MemberExpression) return;
|
|
17241
17501
|
const target = referencedMethod(context, current, classVariables);
|
|
17242
17502
|
const possibleTarget = target ?? referencedPropertyName(current);
|
|
17243
17503
|
if (possibleTarget !== null && privateNames.has(possibleTarget)) pinned.add(possibleTarget);
|
|
@@ -17289,12 +17549,12 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
17289
17549
|
}
|
|
17290
17550
|
function isClassRuntimeBarrier(member) {
|
|
17291
17551
|
switch (member.type) {
|
|
17292
|
-
case
|
|
17552
|
+
case AST_NODE_TYPES74.StaticBlock:
|
|
17293
17553
|
return true;
|
|
17294
|
-
case
|
|
17295
|
-
case
|
|
17554
|
+
case AST_NODE_TYPES74.PropertyDefinition:
|
|
17555
|
+
case AST_NODE_TYPES74.AccessorProperty:
|
|
17296
17556
|
return member.static || member.computed || member.decorators.length > 0 || member.value !== null;
|
|
17297
|
-
case
|
|
17557
|
+
case AST_NODE_TYPES74.MethodDefinition:
|
|
17298
17558
|
return member.computed || member.decorators.length > 0;
|
|
17299
17559
|
default:
|
|
17300
17560
|
return false;
|
|
@@ -17327,7 +17587,7 @@ var stepdown_default = createRule({
|
|
|
17327
17587
|
moduleScope(context, program);
|
|
17328
17588
|
const computedReferenceNames = /* @__PURE__ */ new Set();
|
|
17329
17589
|
walk2(program, context.sourceCode.visitorKeys, (node) => {
|
|
17330
|
-
if (node.type ===
|
|
17590
|
+
if (node.type === AST_NODE_TYPES74.MemberExpression && node.computed && node.property.type === AST_NODE_TYPES74.Literal && typeof node.property.value === "string") computedReferenceNames.add(node.property.value);
|
|
17331
17591
|
});
|
|
17332
17592
|
for (const node of classes) classScope(context, node, computedReferenceNames);
|
|
17333
17593
|
}
|
|
@@ -17336,7 +17596,7 @@ var stepdown_default = createRule({
|
|
|
17336
17596
|
});
|
|
17337
17597
|
|
|
17338
17598
|
// src/rules/source-coupled-test.ts
|
|
17339
|
-
import { AST_NODE_TYPES as
|
|
17599
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES75 } from "@typescript-eslint/utils";
|
|
17340
17600
|
var GENERAL_SOURCE_SUFFIX_RE = /\.(?:bash|sh|ya?ml|jsonc|py|[cm]?[jt]s)$/iu;
|
|
17341
17601
|
var FS_MODULES = /* @__PURE__ */ new Set(["fs", "node:fs", "fs/promises", "node:fs/promises"]);
|
|
17342
17602
|
var FS_READERS = /* @__PURE__ */ new Set(["readFile", "readFileSync"]);
|
|
@@ -17405,20 +17665,20 @@ var SOURCE_COUPLED_TEST_DOCUMENTATION = {
|
|
|
17405
17665
|
]
|
|
17406
17666
|
};
|
|
17407
17667
|
function staticMemberName7(node) {
|
|
17408
|
-
if (!node.computed && node.property.type ===
|
|
17409
|
-
if (node.computed && node.property.type ===
|
|
17668
|
+
if (!node.computed && node.property.type === AST_NODE_TYPES75.Identifier) return node.property.name;
|
|
17669
|
+
if (node.computed && node.property.type === AST_NODE_TYPES75.Literal && typeof node.property.value === "string") return node.property.value;
|
|
17410
17670
|
return null;
|
|
17411
17671
|
}
|
|
17412
17672
|
function unwrap6(node) {
|
|
17413
|
-
if (node.type ===
|
|
17414
|
-
if (node.type ===
|
|
17415
|
-
if (node.type ===
|
|
17673
|
+
if (node.type === AST_NODE_TYPES75.AwaitExpression) return unwrap6(node.argument);
|
|
17674
|
+
if (node.type === AST_NODE_TYPES75.ChainExpression) return unwrap6(node.expression);
|
|
17675
|
+
if (node.type === AST_NODE_TYPES75.TSAsExpression || node.type === AST_NODE_TYPES75.TSNonNullExpression || node.type === AST_NODE_TYPES75.TSTypeAssertion) return unwrap6(node.expression);
|
|
17416
17676
|
return node;
|
|
17417
17677
|
}
|
|
17418
17678
|
function stringValue(node) {
|
|
17419
17679
|
const current = unwrap6(node);
|
|
17420
|
-
if (current.type ===
|
|
17421
|
-
if (current.type ===
|
|
17680
|
+
if (current.type === AST_NODE_TYPES75.Literal && typeof current.value === "string") return current.value;
|
|
17681
|
+
if (current.type === AST_NODE_TYPES75.TemplateLiteral && current.expressions.length === 0) return current.quasis[0]?.value.cooked ?? null;
|
|
17422
17682
|
return null;
|
|
17423
17683
|
}
|
|
17424
17684
|
function importSource(node) {
|
|
@@ -17426,7 +17686,7 @@ function importSource(node) {
|
|
|
17426
17686
|
}
|
|
17427
17687
|
function requireSource(node) {
|
|
17428
17688
|
const current = unwrap6(node);
|
|
17429
|
-
if (current.type !==
|
|
17689
|
+
if (current.type !== AST_NODE_TYPES75.CallExpression || current.callee.type !== AST_NODE_TYPES75.Identifier || current.callee.name !== "require" || current.arguments.length !== 1 || current.arguments[0]?.type === AST_NODE_TYPES75.SpreadElement) return null;
|
|
17430
17690
|
return stringValue(current.arguments[0]);
|
|
17431
17691
|
}
|
|
17432
17692
|
function newScope() {
|
|
@@ -17466,38 +17726,38 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
17466
17726
|
const current = unwrap6(node);
|
|
17467
17727
|
const value = stringValue(current);
|
|
17468
17728
|
if (value !== null) return sourceSuffixRe.test(value);
|
|
17469
|
-
if (current.type ===
|
|
17470
|
-
if (current.type ===
|
|
17729
|
+
if (current.type === AST_NODE_TYPES75.Identifier) return visible("paths", current.name);
|
|
17730
|
+
if (current.type === AST_NODE_TYPES75.BinaryExpression && current.operator === "+") {
|
|
17471
17731
|
return sourcePath(current.left) || sourcePath(current.right);
|
|
17472
17732
|
}
|
|
17473
|
-
if (current.type ===
|
|
17474
|
-
if (current.type ===
|
|
17475
|
-
return current.arguments.some((argument) => argument.type !==
|
|
17733
|
+
if (current.type === AST_NODE_TYPES75.TemplateLiteral) return current.expressions.some(sourcePath);
|
|
17734
|
+
if (current.type === AST_NODE_TYPES75.CallExpression || current.type === AST_NODE_TYPES75.NewExpression) {
|
|
17735
|
+
return current.arguments.some((argument) => argument.type !== AST_NODE_TYPES75.SpreadElement && sourcePath(argument));
|
|
17476
17736
|
}
|
|
17477
|
-
if (current.type ===
|
|
17737
|
+
if (current.type === AST_NODE_TYPES75.MemberExpression) return sourcePath(current.object);
|
|
17478
17738
|
return false;
|
|
17479
17739
|
};
|
|
17480
17740
|
const rawRead = (node) => {
|
|
17481
17741
|
const current = unwrap6(node);
|
|
17482
|
-
if (current.type !==
|
|
17742
|
+
if (current.type !== AST_NODE_TYPES75.CallExpression || current.arguments.length === 0) return false;
|
|
17483
17743
|
const callee = unwrap6(current.callee);
|
|
17484
|
-
if (callee.type ===
|
|
17744
|
+
if (callee.type === AST_NODE_TYPES75.Identifier) {
|
|
17485
17745
|
return visible("fsReaders", callee.name) && sourcePath(current.arguments[0]);
|
|
17486
17746
|
}
|
|
17487
|
-
if (callee.type !==
|
|
17747
|
+
if (callee.type !== AST_NODE_TYPES75.MemberExpression) return false;
|
|
17488
17748
|
const name2 = staticMemberName7(callee);
|
|
17489
17749
|
const object = unwrap6(callee.object);
|
|
17490
|
-
return name2 !== null && FS_READERS.has(name2) && object.type ===
|
|
17750
|
+
return name2 !== null && FS_READERS.has(name2) && object.type === AST_NODE_TYPES75.Identifier && visible("fsObjects", object.name) && sourcePath(current.arguments[0]);
|
|
17491
17751
|
};
|
|
17492
17752
|
const rawOrigins = (node) => {
|
|
17493
17753
|
const current = unwrap6(node);
|
|
17494
|
-
if (current.type ===
|
|
17754
|
+
if (current.type === AST_NODE_TYPES75.Identifier) return visibleRawOrigins(current.name);
|
|
17495
17755
|
if (rawRead(current)) return /* @__PURE__ */ new Set([`${current.range[0]}:${current.range[1]}`]);
|
|
17496
|
-
if (current.type ===
|
|
17497
|
-
if (current.type ===
|
|
17498
|
-
if (current.type !==
|
|
17756
|
+
if (current.type === AST_NODE_TYPES75.BinaryExpression && current.operator === "+") return /* @__PURE__ */ new Set([...rawOrigins(current.left), ...rawOrigins(current.right)]);
|
|
17757
|
+
if (current.type === AST_NODE_TYPES75.MemberExpression && staticMemberName7(current) === "length") return rawOrigins(current.object);
|
|
17758
|
+
if (current.type !== AST_NODE_TYPES75.CallExpression) return /* @__PURE__ */ new Set();
|
|
17499
17759
|
const callee = unwrap6(current.callee);
|
|
17500
|
-
if (callee.type !==
|
|
17760
|
+
if (callee.type !== AST_NODE_TYPES75.MemberExpression) return /* @__PURE__ */ new Set();
|
|
17501
17761
|
const name2 = staticMemberName7(callee);
|
|
17502
17762
|
return name2 !== null && TEXT_TRANSFORMS.has(name2) ? rawOrigins(callee.object) : /* @__PURE__ */ new Set();
|
|
17503
17763
|
};
|
|
@@ -17505,38 +17765,38 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
17505
17765
|
const current = unwrap6(node);
|
|
17506
17766
|
const direct = rawOrigins(current);
|
|
17507
17767
|
if (direct.size > 0) return direct;
|
|
17508
|
-
if (current.type ===
|
|
17509
|
-
if (current.type ===
|
|
17510
|
-
if (current.type !==
|
|
17768
|
+
if (current.type === AST_NODE_TYPES75.BinaryExpression || current.type === AST_NODE_TYPES75.LogicalExpression) return /* @__PURE__ */ new Set([...evidenceOrigins(current.left), ...evidenceOrigins(current.right)]);
|
|
17769
|
+
if (current.type === AST_NODE_TYPES75.UnaryExpression) return evidenceOrigins(current.argument);
|
|
17770
|
+
if (current.type !== AST_NODE_TYPES75.CallExpression) return /* @__PURE__ */ new Set();
|
|
17511
17771
|
const callee = unwrap6(current.callee);
|
|
17512
|
-
if (callee.type !==
|
|
17772
|
+
if (callee.type !== AST_NODE_TYPES75.MemberExpression) return /* @__PURE__ */ new Set();
|
|
17513
17773
|
const name2 = staticMemberName7(callee);
|
|
17514
17774
|
if (name2 !== null && TEXT_PREDICATES.has(name2)) return rawOrigins(callee.object);
|
|
17515
|
-
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type ===
|
|
17775
|
+
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES75.SpreadElement ? [] : [...rawOrigins(argument)]));
|
|
17516
17776
|
return /* @__PURE__ */ new Set();
|
|
17517
17777
|
};
|
|
17518
17778
|
const rawAssertionOrigins = (node) => {
|
|
17519
17779
|
const callee = unwrap6(node.callee);
|
|
17520
|
-
if (callee.type ===
|
|
17521
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
17780
|
+
if (callee.type === AST_NODE_TYPES75.Identifier && callee.name === "assert") {
|
|
17781
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES75.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
17522
17782
|
}
|
|
17523
|
-
if (callee.type !==
|
|
17783
|
+
if (callee.type !== AST_NODE_TYPES75.MemberExpression) return /* @__PURE__ */ new Set();
|
|
17524
17784
|
const matcher = staticMemberName7(callee);
|
|
17525
17785
|
if (matcher === null) return /* @__PURE__ */ new Set();
|
|
17526
17786
|
let receiver = unwrap6(callee.object);
|
|
17527
|
-
while (receiver.type ===
|
|
17528
|
-
if (receiver.type ===
|
|
17787
|
+
while (receiver.type === AST_NODE_TYPES75.MemberExpression && EXPECT_MODIFIERS2.has(staticMemberName7(receiver) ?? "")) receiver = unwrap6(receiver.object);
|
|
17788
|
+
if (receiver.type === AST_NODE_TYPES75.CallExpression && receiver.callee.type === AST_NODE_TYPES75.Identifier && receiver.callee.name === "expect") {
|
|
17529
17789
|
if (!EXPECT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
17530
|
-
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type ===
|
|
17790
|
+
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type === AST_NODE_TYPES75.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
17531
17791
|
}
|
|
17532
|
-
if (receiver.type !==
|
|
17533
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
17792
|
+
if (receiver.type !== AST_NODE_TYPES75.Identifier || receiver.name !== "assert" || !ASSERT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
17793
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === AST_NODE_TYPES75.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
17534
17794
|
};
|
|
17535
17795
|
const rawRegexExtractionOrigins = (node) => {
|
|
17536
17796
|
const callee = unwrap6(node.callee);
|
|
17537
|
-
if (callee.type !==
|
|
17797
|
+
if (callee.type !== AST_NODE_TYPES75.MemberExpression || staticMemberName7(callee) !== "matchAll" || node.arguments.length !== 1) return /* @__PURE__ */ new Set();
|
|
17538
17798
|
const argument = node.arguments[0];
|
|
17539
|
-
if (argument?.type !==
|
|
17799
|
+
if (argument?.type !== AST_NODE_TYPES75.Literal || !(argument.value instanceof RegExp)) return /* @__PURE__ */ new Set();
|
|
17540
17800
|
return rawOrigins(callee.object);
|
|
17541
17801
|
};
|
|
17542
17802
|
const declare = (name2, state) => {
|
|
@@ -17557,15 +17817,15 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
17557
17817
|
};
|
|
17558
17818
|
const sourceCollection = (node) => {
|
|
17559
17819
|
const current = unwrap6(node);
|
|
17560
|
-
return current.type ===
|
|
17820
|
+
return current.type === AST_NODE_TYPES75.ArrayExpression && current.elements.length > 0 && current.elements.every((element) => element !== null && element.type !== AST_NODE_TYPES75.SpreadElement && sourcePath(element));
|
|
17561
17821
|
};
|
|
17562
17822
|
const declaredNames2 = (node) => {
|
|
17563
17823
|
const current = unwrap6(node);
|
|
17564
|
-
if (current.type ===
|
|
17565
|
-
if (current.type ===
|
|
17566
|
-
if (current.type ===
|
|
17567
|
-
if (current.type ===
|
|
17568
|
-
if (current.type ===
|
|
17824
|
+
if (current.type === AST_NODE_TYPES75.Identifier) return [current.name];
|
|
17825
|
+
if (current.type === AST_NODE_TYPES75.AssignmentPattern) return declaredNames2(current.left);
|
|
17826
|
+
if (current.type === AST_NODE_TYPES75.RestElement) return declaredNames2(current.argument);
|
|
17827
|
+
if (current.type === AST_NODE_TYPES75.ArrayPattern) return current.elements.flatMap((element) => element === null ? [] : declaredNames2(element));
|
|
17828
|
+
if (current.type === AST_NODE_TYPES75.ObjectPattern) return current.properties.flatMap((property) => property.type === AST_NODE_TYPES75.RestElement ? declaredNames2(property.argument) : declaredNames2(property.value));
|
|
17569
17829
|
return [];
|
|
17570
17830
|
};
|
|
17571
17831
|
const enterFunction = (node) => {
|
|
@@ -17580,8 +17840,8 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
17580
17840
|
const source = importSource(node);
|
|
17581
17841
|
if (source === null || !FS_MODULES.has(source)) return;
|
|
17582
17842
|
for (const specifier of node.specifiers) {
|
|
17583
|
-
if (specifier.type ===
|
|
17584
|
-
const imported = specifier.imported.type ===
|
|
17843
|
+
if (specifier.type === AST_NODE_TYPES75.ImportSpecifier) {
|
|
17844
|
+
const imported = specifier.imported.type === AST_NODE_TYPES75.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
17585
17845
|
if (FS_READERS.has(imported)) declare(specifier.local.name, { fsReader: true });
|
|
17586
17846
|
} else {
|
|
17587
17847
|
declare(specifier.local.name, { fsObject: true });
|
|
@@ -17593,29 +17853,29 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
17593
17853
|
VariableDeclarator(node) {
|
|
17594
17854
|
if (node.init === null) return;
|
|
17595
17855
|
const required = requireSource(node.init);
|
|
17596
|
-
if (required !== null && FS_MODULES.has(required) && node.id.type ===
|
|
17856
|
+
if (required !== null && FS_MODULES.has(required) && node.id.type === AST_NODE_TYPES75.Identifier) {
|
|
17597
17857
|
declare(node.id.name, { fsObject: true });
|
|
17598
17858
|
return;
|
|
17599
17859
|
}
|
|
17600
|
-
if (node.id.type ===
|
|
17860
|
+
if (node.id.type === AST_NODE_TYPES75.ObjectPattern && required !== null && FS_MODULES.has(required)) {
|
|
17601
17861
|
for (const property of node.id.properties) {
|
|
17602
|
-
if (property.type !==
|
|
17603
|
-
const key = property.key.type ===
|
|
17862
|
+
if (property.type !== AST_NODE_TYPES75.Property || property.value.type !== AST_NODE_TYPES75.Identifier) continue;
|
|
17863
|
+
const key = property.key.type === AST_NODE_TYPES75.Identifier ? property.key.name : property.key.type === AST_NODE_TYPES75.Literal ? String(property.key.value) : "";
|
|
17604
17864
|
if (FS_READERS.has(key)) declare(property.value.name, { fsReader: true });
|
|
17605
17865
|
}
|
|
17606
17866
|
return;
|
|
17607
17867
|
}
|
|
17608
|
-
if (node.id.type !==
|
|
17868
|
+
if (node.id.type !== AST_NODE_TYPES75.Identifier) return;
|
|
17609
17869
|
declare(node.id.name, { collection: sourceCollection(node.init), path: sourcePath(node.init), rawOrigins: rawOrigins(node.init) });
|
|
17610
17870
|
},
|
|
17611
17871
|
AssignmentExpression(node) {
|
|
17612
|
-
if (node.left.type ===
|
|
17872
|
+
if (node.left.type === AST_NODE_TYPES75.Identifier) declare(node.left.name, { path: sourcePath(node.right), rawOrigins: rawOrigins(node.right) });
|
|
17613
17873
|
},
|
|
17614
17874
|
ForOfStatement(node) {
|
|
17615
17875
|
const right = unwrap6(node.right);
|
|
17616
|
-
const collection = right.type ===
|
|
17617
|
-
const left = node.left.type ===
|
|
17618
|
-
if (collection && left?.type ===
|
|
17876
|
+
const collection = right.type === AST_NODE_TYPES75.Identifier && visible("collections", right.name);
|
|
17877
|
+
const left = node.left.type === AST_NODE_TYPES75.VariableDeclaration ? node.left.declarations[0]?.id : node.left;
|
|
17878
|
+
if (collection && left?.type === AST_NODE_TYPES75.Identifier) declare(left.name, { path: true });
|
|
17619
17879
|
},
|
|
17620
17880
|
CallExpression(node) {
|
|
17621
17881
|
const origins = /* @__PURE__ */ new Set([
|
|
@@ -17637,7 +17897,7 @@ var source_coupled_test_default = createSourceCoupledRule(
|
|
|
17637
17897
|
);
|
|
17638
17898
|
|
|
17639
17899
|
// src/rules/sole-export-matches-filename.ts
|
|
17640
|
-
import { AST_NODE_TYPES as
|
|
17900
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES76 } from "@typescript-eslint/utils";
|
|
17641
17901
|
var SOLE_EXPORT_MATCHES_FILENAME_DOCUMENTATION = {
|
|
17642
17902
|
summary: "Match a module filename to its sole named public runtime export.",
|
|
17643
17903
|
rationale: "When a module owns one runtime responsibility, matching names make that responsibility directly discoverable.",
|
|
@@ -17680,10 +17940,10 @@ function kebabCase(name) {
|
|
|
17680
17940
|
function declarationExport(statement) {
|
|
17681
17941
|
const declaration = statement.declaration;
|
|
17682
17942
|
if (declaration === null || declaration.declare === true) return [];
|
|
17683
|
-
if (declaration.type ===
|
|
17684
|
-
if (declaration.type !==
|
|
17943
|
+
if (declaration.type === AST_NODE_TYPES76.ClassDeclaration || declaration.type === AST_NODE_TYPES76.FunctionDeclaration || declaration.type === AST_NODE_TYPES76.TSEnumDeclaration) return declaration.id === null ? [] : [{ name: declaration.id.name, node: declaration }];
|
|
17944
|
+
if (declaration.type !== AST_NODE_TYPES76.VariableDeclaration) return [];
|
|
17685
17945
|
return declaration.declarations.flatMap(
|
|
17686
|
-
(item) => item.id.type ===
|
|
17946
|
+
(item) => item.id.type === AST_NODE_TYPES76.Identifier ? [{ name: item.id.name, node: item }] : []
|
|
17687
17947
|
);
|
|
17688
17948
|
}
|
|
17689
17949
|
var sole_export_matches_filename_default = createRule({
|
|
@@ -17707,31 +17967,31 @@ var sole_export_matches_filename_default = createRule({
|
|
|
17707
17967
|
const exports = [];
|
|
17708
17968
|
const publicExports = /* @__PURE__ */ new Set();
|
|
17709
17969
|
for (const statement of program.body) {
|
|
17710
|
-
if (statement.type ===
|
|
17711
|
-
if (statement.type ===
|
|
17970
|
+
if (statement.type === AST_NODE_TYPES76.ExportAllDeclaration || statement.type === AST_NODE_TYPES76.ExportNamedDeclaration && statement.source !== null) return;
|
|
17971
|
+
if (statement.type === AST_NODE_TYPES76.ExportDefaultDeclaration) {
|
|
17712
17972
|
publicExports.add("default");
|
|
17713
17973
|
const declaration2 = statement.declaration;
|
|
17714
|
-
if ((declaration2.type ===
|
|
17974
|
+
if ((declaration2.type === AST_NODE_TYPES76.ClassDeclaration || declaration2.type === AST_NODE_TYPES76.FunctionDeclaration) && declaration2.id !== null) exports.push({ name: declaration2.id.name, node: declaration2 });
|
|
17715
17975
|
else return;
|
|
17716
17976
|
}
|
|
17717
|
-
if (statement.type !==
|
|
17977
|
+
if (statement.type !== AST_NODE_TYPES76.ExportNamedDeclaration) continue;
|
|
17718
17978
|
const declaration = statement.declaration;
|
|
17719
|
-
if (declaration !== null && "id" in declaration && declaration.id?.type ===
|
|
17979
|
+
if (declaration !== null && "id" in declaration && declaration.id?.type === AST_NODE_TYPES76.Identifier) {
|
|
17720
17980
|
publicExports.add(declaration.id.name);
|
|
17721
17981
|
}
|
|
17722
|
-
if (declaration?.type ===
|
|
17982
|
+
if (declaration?.type === AST_NODE_TYPES76.VariableDeclaration) {
|
|
17723
17983
|
for (const item of declaration.declarations) {
|
|
17724
|
-
if (item.id.type ===
|
|
17984
|
+
if (item.id.type === AST_NODE_TYPES76.Identifier) publicExports.add(item.id.name);
|
|
17725
17985
|
}
|
|
17726
17986
|
}
|
|
17727
17987
|
for (const specifier of statement.specifiers) {
|
|
17728
|
-
const exported = specifier.exported.type ===
|
|
17988
|
+
const exported = specifier.exported.type === AST_NODE_TYPES76.Identifier ? specifier.exported.name : specifier.exported.value;
|
|
17729
17989
|
publicExports.add(String(exported));
|
|
17730
17990
|
}
|
|
17731
17991
|
if (statement.exportKind === "type") continue;
|
|
17732
17992
|
exports.push(...declarationExport(statement));
|
|
17733
17993
|
for (const specifier of statement.specifiers) {
|
|
17734
|
-
const exported = specifier.exported.type ===
|
|
17994
|
+
const exported = specifier.exported.type === AST_NODE_TYPES76.Identifier ? specifier.exported.name : specifier.exported.value;
|
|
17735
17995
|
publicExports.add(String(exported));
|
|
17736
17996
|
if (specifier.exportKind === "type") continue;
|
|
17737
17997
|
if (exported === "default") exports.push({ name: specifier.local.name, node: specifier });
|
|
@@ -17790,7 +18050,7 @@ var iac_source_coupled_test_default = createSourceCoupledRule(
|
|
|
17790
18050
|
|
|
17791
18051
|
// src/rules/require-pascal-case-zod-schema-name.ts
|
|
17792
18052
|
import {
|
|
17793
|
-
AST_NODE_TYPES as
|
|
18053
|
+
AST_NODE_TYPES as AST_NODE_TYPES77,
|
|
17794
18054
|
ASTUtils as ASTUtils24
|
|
17795
18055
|
} from "@typescript-eslint/utils";
|
|
17796
18056
|
var REQUIRE_PASCAL_CASE_ZOD_SCHEMA_NAME_DOCUMENTATION = {
|
|
@@ -17924,18 +18184,18 @@ var SCHEMA_RETURNING_METHODS = /* @__PURE__ */ new Set([
|
|
|
17924
18184
|
"superRefine",
|
|
17925
18185
|
"transform"
|
|
17926
18186
|
]);
|
|
17927
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
18187
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === AST_NODE_TYPES77.Identifier ? callee.property.name : null;
|
|
17928
18188
|
var calleeChainRoot = (node) => {
|
|
17929
18189
|
let current = node;
|
|
17930
18190
|
for (; ; ) {
|
|
17931
|
-
if (current.type ===
|
|
18191
|
+
if (current.type === AST_NODE_TYPES77.Identifier) {
|
|
17932
18192
|
return current;
|
|
17933
18193
|
}
|
|
17934
|
-
if (current.type ===
|
|
18194
|
+
if (current.type === AST_NODE_TYPES77.MemberExpression) {
|
|
17935
18195
|
current = current.object;
|
|
17936
18196
|
continue;
|
|
17937
18197
|
}
|
|
17938
|
-
if (current.type ===
|
|
18198
|
+
if (current.type === AST_NODE_TYPES77.CallExpression) {
|
|
17939
18199
|
current = current.callee;
|
|
17940
18200
|
continue;
|
|
17941
18201
|
}
|
|
@@ -17946,13 +18206,13 @@ var chainMemberNames = (node) => {
|
|
|
17946
18206
|
const names = [];
|
|
17947
18207
|
let current = node;
|
|
17948
18208
|
for (; ; ) {
|
|
17949
|
-
if (current.type ===
|
|
17950
|
-
if (current.computed || current.property.type !==
|
|
18209
|
+
if (current.type === AST_NODE_TYPES77.MemberExpression) {
|
|
18210
|
+
if (current.computed || current.property.type !== AST_NODE_TYPES77.Identifier) return [];
|
|
17951
18211
|
names.push(current.property.name);
|
|
17952
18212
|
current = current.object;
|
|
17953
18213
|
continue;
|
|
17954
18214
|
}
|
|
17955
|
-
if (current.type ===
|
|
18215
|
+
if (current.type === AST_NODE_TYPES77.CallExpression) {
|
|
17956
18216
|
current = current.callee;
|
|
17957
18217
|
continue;
|
|
17958
18218
|
}
|
|
@@ -17963,16 +18223,16 @@ var chainMemberNames = (node) => {
|
|
|
17963
18223
|
};
|
|
17964
18224
|
var unwrapExpression4 = (node) => {
|
|
17965
18225
|
let current = node;
|
|
17966
|
-
while (current.type ===
|
|
18226
|
+
while (current.type === AST_NODE_TYPES77.TSAsExpression || current.type === AST_NODE_TYPES77.TSSatisfiesExpression || current.type === AST_NODE_TYPES77.TSNonNullExpression || current.type === AST_NODE_TYPES77.TSTypeAssertion) {
|
|
17967
18227
|
current = current.expression;
|
|
17968
18228
|
}
|
|
17969
18229
|
return current;
|
|
17970
18230
|
};
|
|
17971
18231
|
var isModuleDeclarator = (node) => {
|
|
17972
18232
|
const declaration = node.parent;
|
|
17973
|
-
if (declaration.type !==
|
|
18233
|
+
if (declaration.type !== AST_NODE_TYPES77.VariableDeclaration) return false;
|
|
17974
18234
|
const owner = declaration.parent;
|
|
17975
|
-
return owner.type ===
|
|
18235
|
+
return owner.type === AST_NODE_TYPES77.Program || owner.type === AST_NODE_TYPES77.ExportNamedDeclaration && owner.parent.type === AST_NODE_TYPES77.Program;
|
|
17976
18236
|
};
|
|
17977
18237
|
var require_pascal_case_zod_schema_name_default = createRule({
|
|
17978
18238
|
name: "require-pascal-case-zod-schema-name",
|
|
@@ -18013,8 +18273,8 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
18013
18273
|
}
|
|
18014
18274
|
function isConfirmedSchema(expression) {
|
|
18015
18275
|
const init = unwrapExpression4(expression);
|
|
18016
|
-
if (init.type ===
|
|
18017
|
-
if (init.type !==
|
|
18276
|
+
if (init.type === AST_NODE_TYPES77.Identifier) return isSchemaBinding(init);
|
|
18277
|
+
if (init.type !== AST_NODE_TYPES77.CallExpression || init.callee.type !== AST_NODE_TYPES77.MemberExpression) {
|
|
18018
18278
|
return false;
|
|
18019
18279
|
}
|
|
18020
18280
|
const terminal = terminalMethodName(init.callee);
|
|
@@ -18034,7 +18294,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
18034
18294
|
ImportDeclaration(node) {
|
|
18035
18295
|
if (!isZodModule(node.source.value)) return;
|
|
18036
18296
|
for (const specifier of node.specifiers) {
|
|
18037
|
-
if (specifier.type ===
|
|
18297
|
+
if (specifier.type === AST_NODE_TYPES77.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES77.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES77.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES77.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
18038
18298
|
recordZodBinding(specifier.local);
|
|
18039
18299
|
}
|
|
18040
18300
|
}
|
|
@@ -18043,7 +18303,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
18043
18303
|
if (!isModuleDeclarator(node)) return;
|
|
18044
18304
|
const init = node.init;
|
|
18045
18305
|
if (init === null || init === void 0) return;
|
|
18046
|
-
if (node.id.type !==
|
|
18306
|
+
if (node.id.type !== AST_NODE_TYPES77.Identifier) return;
|
|
18047
18307
|
if (!isConfirmedSchema(init)) return;
|
|
18048
18308
|
const binding = resolvedBinding(node.id);
|
|
18049
18309
|
if (binding !== null) schemaBindings.add(binding);
|
|
@@ -18201,6 +18461,9 @@ var RULES = {
|
|
|
18201
18461
|
"prefer-shadcn-primitives": prefer_shadcn_primitives_default,
|
|
18202
18462
|
"prefer-module-level-constant": prefer_module_level_constant_default,
|
|
18203
18463
|
"prefer-module-level-schema": prefer_module_level_schema_default,
|
|
18464
|
+
"prefer-module-level-refined-schema": prefer_module_level_refined_schema_default,
|
|
18465
|
+
"prefer-multi-value-zod-literal": prefer_multi_value_zod_literal_default,
|
|
18466
|
+
"prefer-named-callback-domain": prefer_named_callback_domain_default,
|
|
18204
18467
|
"prefer-named-complex-return-type": prefer_named_complex_return_type_default,
|
|
18205
18468
|
"prefer-native-random-uuid": prefer_native_random_uuid_default,
|
|
18206
18469
|
"prefer-node-crypto-hash": prefer_node_crypto_hash_default,
|
|
@@ -18224,14 +18487,14 @@ var RULES = {
|
|
|
18224
18487
|
"require-static-next-matcher": require_static_next_matcher_default,
|
|
18225
18488
|
"require-zod-form-validation": require_zod_form_validation_default,
|
|
18226
18489
|
"store-insert-requires-on-conflict": store_insert_requires_on_conflict_default,
|
|
18227
|
-
|
|
18490
|
+
stepdown: stepdown_default,
|
|
18228
18491
|
"source-coupled-test": source_coupled_test_default,
|
|
18229
18492
|
"sole-export-matches-filename": sole_export_matches_filename_default,
|
|
18230
18493
|
"require-pascal-case-zod-schema-name": require_pascal_case_zod_schema_name_default
|
|
18231
18494
|
};
|
|
18232
18495
|
var meta = {
|
|
18233
18496
|
name: "@sarj/eslint-plugin",
|
|
18234
|
-
version: "15.
|
|
18497
|
+
version: "15.17.0"
|
|
18235
18498
|
};
|
|
18236
18499
|
var APPLICATION_ONLY_RULES = [
|
|
18237
18500
|
"no-restricted-library-load",
|
|
@@ -18239,6 +18502,9 @@ var APPLICATION_ONLY_RULES = [
|
|
|
18239
18502
|
"prefer-shadcn-primitives"
|
|
18240
18503
|
];
|
|
18241
18504
|
var ADVISORY_RULES = [
|
|
18505
|
+
"@sarj/prefer-module-level-refined-schema",
|
|
18506
|
+
"@sarj/prefer-multi-value-zod-literal",
|
|
18507
|
+
"@sarj/prefer-named-callback-domain",
|
|
18242
18508
|
"@sarj/prefer-named-complex-return-type",
|
|
18243
18509
|
"@sarj/prefer-node-crypto-hash",
|
|
18244
18510
|
"@sarj/prefer-node-fs-promises",
|
|
@@ -18302,6 +18568,9 @@ var RECOMMENDED_RULES = {
|
|
|
18302
18568
|
"@sarj/prefer-immutable-module-constant": "error",
|
|
18303
18569
|
"@sarj/prefer-module-level-constant": "error",
|
|
18304
18570
|
"@sarj/prefer-module-level-schema": "error",
|
|
18571
|
+
"@sarj/prefer-module-level-refined-schema": "warn",
|
|
18572
|
+
"@sarj/prefer-multi-value-zod-literal": ["warn", { zodMajorVersion: 4 }],
|
|
18573
|
+
"@sarj/prefer-named-callback-domain": "warn",
|
|
18305
18574
|
"@sarj/prefer-named-complex-return-type": "warn",
|
|
18306
18575
|
"@sarj/prefer-node-crypto-hash": "warn",
|
|
18307
18576
|
"@sarj/prefer-node-fs-promises": "warn",
|
|
@@ -18389,6 +18658,9 @@ var STRICT_RULES = {
|
|
|
18389
18658
|
"@sarj/prefer-immutable-module-constant": "error",
|
|
18390
18659
|
"@sarj/prefer-module-level-constant": "error",
|
|
18391
18660
|
"@sarj/prefer-module-level-schema": "error",
|
|
18661
|
+
"@sarj/prefer-module-level-refined-schema": "warn",
|
|
18662
|
+
"@sarj/prefer-multi-value-zod-literal": ["warn", { zodMajorVersion: 4 }],
|
|
18663
|
+
"@sarj/prefer-named-callback-domain": "warn",
|
|
18392
18664
|
"@sarj/prefer-named-complex-return-type": "warn",
|
|
18393
18665
|
"@sarj/prefer-node-crypto-hash": "warn",
|
|
18394
18666
|
"@sarj/prefer-node-fs-promises": "warn",
|