eslint-plugin-zod 1.3.0 → 3.0.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.
Files changed (104) hide show
  1. package/LICENSE +19 -22
  2. package/README.md +84 -56
  3. package/dist/index.cjs +71 -0
  4. package/dist/index.d.cts +21 -0
  5. package/dist/index.d.ts +21 -0
  6. package/dist/index.js +68 -0
  7. package/dist/meta.cjs +13 -0
  8. package/dist/meta.d.cts +3 -0
  9. package/dist/meta.d.ts +3 -0
  10. package/dist/meta.js +8 -0
  11. package/dist/rules/array-style.cjs +99 -0
  12. package/dist/rules/array-style.d.cts +10 -0
  13. package/dist/rules/array-style.d.ts +10 -0
  14. package/dist/rules/array-style.js +96 -0
  15. package/dist/rules/consistent-import-source.cjs +73 -0
  16. package/dist/rules/consistent-import-source.d.cts +10 -0
  17. package/dist/rules/consistent-import-source.d.ts +10 -0
  18. package/dist/rules/consistent-import-source.js +70 -0
  19. package/dist/rules/consistent-object-schema-type.cjs +83 -0
  20. package/dist/rules/consistent-object-schema-type.d.cts +11 -0
  21. package/dist/rules/consistent-object-schema-type.d.ts +11 -0
  22. package/dist/rules/consistent-object-schema-type.js +80 -0
  23. package/dist/rules/no-any-schema.cjs +66 -0
  24. package/dist/rules/no-any-schema.d.cts +4 -0
  25. package/dist/rules/no-any-schema.d.ts +4 -0
  26. package/dist/rules/no-any-schema.js +63 -0
  27. package/dist/rules/no-empty-custom-schema.cjs +40 -0
  28. package/dist/rules/no-empty-custom-schema.d.cts +4 -0
  29. package/dist/rules/no-empty-custom-schema.d.ts +4 -0
  30. package/dist/rules/no-empty-custom-schema.js +37 -0
  31. package/dist/rules/no-number-schema-with-int.cjs +78 -0
  32. package/dist/rules/no-number-schema-with-int.d.cts +4 -0
  33. package/dist/rules/no-number-schema-with-int.d.ts +4 -0
  34. package/dist/rules/no-number-schema-with-int.js +75 -0
  35. package/dist/rules/no-optional-and-default-together.cjs +80 -0
  36. package/dist/rules/no-optional-and-default-together.d.cts +11 -0
  37. package/dist/rules/no-optional-and-default-together.d.ts +11 -0
  38. package/dist/rules/no-optional-and-default-together.js +77 -0
  39. package/dist/rules/no-throw-in-refine.cjs +84 -0
  40. package/dist/rules/no-throw-in-refine.d.cts +4 -0
  41. package/dist/rules/no-throw-in-refine.d.ts +4 -0
  42. package/dist/rules/no-throw-in-refine.js +81 -0
  43. package/dist/rules/no-unknown-schema.cjs +35 -0
  44. package/dist/rules/no-unknown-schema.d.cts +4 -0
  45. package/dist/rules/no-unknown-schema.d.ts +4 -0
  46. package/dist/rules/no-unknown-schema.js +32 -0
  47. package/dist/rules/prefer-enum-over-literal-union.cjs +72 -0
  48. package/dist/rules/prefer-enum-over-literal-union.d.cts +4 -0
  49. package/dist/rules/prefer-enum-over-literal-union.d.ts +4 -0
  50. package/dist/rules/prefer-enum-over-literal-union.js +69 -0
  51. package/dist/rules/prefer-meta-last.cjs +71 -0
  52. package/dist/rules/prefer-meta-last.d.cts +4 -0
  53. package/dist/rules/prefer-meta-last.d.ts +4 -0
  54. package/dist/rules/prefer-meta-last.js +68 -0
  55. package/dist/rules/prefer-meta.cjs +48 -0
  56. package/dist/rules/prefer-meta.d.cts +4 -0
  57. package/dist/rules/prefer-meta.d.ts +4 -0
  58. package/dist/rules/prefer-meta.js +45 -0
  59. package/dist/rules/prefer-namespace-import.cjs +145 -0
  60. package/dist/rules/prefer-namespace-import.d.cts +4 -0
  61. package/dist/rules/prefer-namespace-import.d.ts +4 -0
  62. package/dist/rules/prefer-namespace-import.js +142 -0
  63. package/dist/rules/require-brand-type-parameter.cjs +60 -0
  64. package/dist/rules/require-brand-type-parameter.d.cts +4 -0
  65. package/dist/rules/require-brand-type-parameter.d.ts +4 -0
  66. package/dist/rules/require-brand-type-parameter.js +57 -0
  67. package/dist/rules/require-error-message.cjs +101 -0
  68. package/dist/rules/require-error-message.d.cts +4 -0
  69. package/dist/rules/require-error-message.d.ts +4 -0
  70. package/dist/rules/require-error-message.js +98 -0
  71. package/dist/rules/require-schema-suffix.cjs +73 -0
  72. package/dist/rules/require-schema-suffix.d.cts +8 -0
  73. package/dist/rules/require-schema-suffix.d.ts +8 -0
  74. package/dist/rules/require-schema-suffix.js +70 -0
  75. package/dist/rules/schema-error-property-style.cjs +106 -0
  76. package/dist/rules/schema-error-property-style.d.cts +9 -0
  77. package/dist/rules/schema-error-property-style.d.ts +9 -0
  78. package/dist/rules/schema-error-property-style.js +100 -0
  79. package/dist/utils/detect-zod-schema-root-node.cjs +104 -0
  80. package/dist/utils/detect-zod-schema-root-node.d.cts +10 -0
  81. package/dist/utils/detect-zod-schema-root-node.d.ts +10 -0
  82. package/dist/utils/detect-zod-schema-root-node.js +101 -0
  83. package/dist/utils/get-outermost-call.cjs +14 -0
  84. package/dist/utils/get-outermost-call.d.cts +2 -0
  85. package/dist/utils/get-outermost-call.d.ts +2 -0
  86. package/dist/utils/get-outermost-call.js +11 -0
  87. package/dist/utils/is-zod-expression.cjs +14 -0
  88. package/dist/utils/is-zod-expression.d.cts +2 -0
  89. package/dist/utils/is-zod-expression.d.ts +2 -0
  90. package/dist/utils/is-zod-expression.js +11 -0
  91. package/dist/utils/is-zod-import-source.cjs +6 -0
  92. package/dist/utils/is-zod-import-source.d.cts +1 -0
  93. package/dist/utils/is-zod-import-source.d.ts +1 -0
  94. package/dist/utils/is-zod-import-source.js +3 -0
  95. package/dist/utils/track-zod-schema-imports.cjs +61 -0
  96. package/dist/utils/track-zod-schema-imports.d.cts +13 -0
  97. package/dist/utils/track-zod-schema-imports.d.ts +13 -0
  98. package/dist/utils/track-zod-schema-imports.js +58 -0
  99. package/package.json +82 -38
  100. package/dist/src/index.d.ts +0 -31
  101. package/dist/src/index.js +0 -14
  102. package/dist/src/rules/requireStrict.d.ts +0 -24
  103. package/dist/src/rules/requireStrict.js +0 -69
  104. package/tsconfig.json +0 -28
@@ -0,0 +1,100 @@
1
+ import { AST_NODE_TYPES, ESLintUtils } from '@typescript-eslint/utils';
2
+ import esquery from 'esquery';
3
+ import { getRuleURL } from "../meta.js";
4
+ import { trackZodSchemaImports } from "../utils/track-zod-schema-imports.js";
5
+ export const schemaErrorPropertyStyle = ESLintUtils.RuleCreator(getRuleURL)({
6
+ name: 'schema-error-property-style',
7
+ meta: {
8
+ type: 'suggestion',
9
+ docs: {
10
+ description: 'Enforce consistent style for error messages in Zod schema validation (using ESQuery patterns)',
11
+ },
12
+ messages: {
13
+ invalidSelector: 'Invalid ESQuery selector: "{{selector}}"',
14
+ invalidStyle: 'Error message must follow the pattern "{{selector}}" (e.g., {{example}}). Found: {{actual}}.',
15
+ },
16
+ schema: [
17
+ {
18
+ type: 'object',
19
+ properties: {
20
+ selector: {
21
+ description: 'An ESQuery string to match the required pattern',
22
+ type: 'string',
23
+ },
24
+ example: {
25
+ description: 'Example code to help the user understand the required pattern',
26
+ type: 'string',
27
+ },
28
+ },
29
+ additionalProperties: false,
30
+ },
31
+ ],
32
+ },
33
+ defaultOptions: [
34
+ { selector: 'Literal,TemplateLiteral', example: "'error message'" },
35
+ ],
36
+ create(context, [{ selector, example }]) {
37
+ const { importDeclarationListener, detectZodSchemaRootNode, collectZodChainMethods, } = trackZodSchemaImports();
38
+ try {
39
+ esquery.parse(selector);
40
+ }
41
+ catch (_a) {
42
+ context.report({
43
+ loc: { line: 1, column: 0 },
44
+ messageId: 'invalidSelector',
45
+ data: { selector },
46
+ });
47
+ return {};
48
+ }
49
+ return {
50
+ ImportDeclaration: importDeclarationListener,
51
+ CallExpression(node) {
52
+ const zodSchemaMeta = detectZodSchemaRootNode(node);
53
+ if (!zodSchemaMeta) {
54
+ return;
55
+ }
56
+ if (zodSchemaMeta.schemaType !== 'custom' &&
57
+ !collectZodChainMethods(node).some((it) => it.name === 'refine')) {
58
+ return;
59
+ }
60
+ if (node.arguments.length < 2) {
61
+ return;
62
+ }
63
+ let errorMessageNode;
64
+ const [, params] = node.arguments;
65
+ switch (params.type) {
66
+ case AST_NODE_TYPES.Literal:
67
+ case AST_NODE_TYPES.TemplateLiteral:
68
+ errorMessageNode = params;
69
+ break;
70
+ case AST_NODE_TYPES.ObjectExpression:
71
+ for (const property of params.properties) {
72
+ if (property.type === AST_NODE_TYPES.Property &&
73
+ property.key.type === AST_NODE_TYPES.Identifier &&
74
+ property.key.name === 'error') {
75
+ errorMessageNode = property.value;
76
+ break;
77
+ }
78
+ }
79
+ break;
80
+ }
81
+ if (!errorMessageNode) {
82
+ return;
83
+ }
84
+ const match = esquery.matches(errorMessageNode, esquery.parse(selector), errorMessageNode);
85
+ if (match) {
86
+ return;
87
+ }
88
+ context.report({
89
+ node,
90
+ messageId: 'invalidStyle',
91
+ data: {
92
+ selector,
93
+ example,
94
+ actual: context.sourceCode.getText(errorMessageNode),
95
+ },
96
+ });
97
+ },
98
+ };
99
+ },
100
+ });
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectZodSchemaRootNode = detectZodSchemaRootNode;
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ function getPropertyName(prop) {
6
+ if (!prop) {
7
+ return null;
8
+ }
9
+ if (prop.type === utils_1.AST_NODE_TYPES.Identifier) {
10
+ return prop.name;
11
+ }
12
+ if (prop.type === utils_1.AST_NODE_TYPES.Literal) {
13
+ return prop.value == null ? null : String(prop.value);
14
+ }
15
+ if (prop.type === utils_1.AST_NODE_TYPES.TemplateLiteral) {
16
+ if (prop.expressions.length === 0 && prop.quasis.length === 1) {
17
+ return prop.quasis[0].value.cooked;
18
+ }
19
+ return null;
20
+ }
21
+ return null;
22
+ }
23
+ function isOutermostCallExpression(node) {
24
+ const { parent } = node;
25
+ if (parent.type === utils_1.AST_NODE_TYPES.CallExpression && parent.callee === node) {
26
+ return false;
27
+ }
28
+ if (parent.type === utils_1.AST_NODE_TYPES.MemberExpression &&
29
+ parent.object === node) {
30
+ return false;
31
+ }
32
+ return true;
33
+ }
34
+ function parseZodCallExpression(call, zodNamespaces, zodNamedImports) {
35
+ var _a;
36
+ let cur = call.callee;
37
+ const methodsRightToLeft = [];
38
+ let leftmostIdentifier = null;
39
+ while (true) {
40
+ if (cur.type === utils_1.AST_NODE_TYPES.CallExpression) {
41
+ cur = cur.callee;
42
+ continue;
43
+ }
44
+ if (cur.type === utils_1.AST_NODE_TYPES.MemberExpression) {
45
+ const name = getPropertyName(cur.property);
46
+ if (!name) {
47
+ return null;
48
+ }
49
+ methodsRightToLeft.push(name);
50
+ cur = cur.object;
51
+ continue;
52
+ }
53
+ if (cur.type === utils_1.AST_NODE_TYPES.Identifier) {
54
+ leftmostIdentifier = cur.name;
55
+ break;
56
+ }
57
+ return null;
58
+ }
59
+ const methods = methodsRightToLeft.slice().reverse();
60
+ if (!leftmostIdentifier) {
61
+ return null;
62
+ }
63
+ if (zodNamespaces.has(leftmostIdentifier)) {
64
+ const factory = (_a = methods[0]) !== null && _a !== void 0 ? _a : null;
65
+ if (!factory) {
66
+ return null;
67
+ }
68
+ return {
69
+ schemaDecl: 'namespace',
70
+ schemaType: factory,
71
+ methods,
72
+ node: call,
73
+ };
74
+ }
75
+ if (zodNamedImports.has(leftmostIdentifier)) {
76
+ const factory = leftmostIdentifier;
77
+ return {
78
+ schemaDecl: 'named',
79
+ schemaType: factory,
80
+ methods,
81
+ node: call,
82
+ };
83
+ }
84
+ return null;
85
+ }
86
+ function detectZodSchemaRootNode(node, zodNamespaces, zodNamedImports) {
87
+ if (node.type !== utils_1.AST_NODE_TYPES.CallExpression) {
88
+ return null;
89
+ }
90
+ const call = node;
91
+ if (!isOutermostCallExpression(call)) {
92
+ return null;
93
+ }
94
+ const outer = parseZodCallExpression(call, zodNamespaces, zodNamedImports);
95
+ if (!outer) {
96
+ return null;
97
+ }
98
+ return {
99
+ schemaDecl: outer.schemaDecl,
100
+ schemaType: outer.schemaType,
101
+ methods: outer.methods,
102
+ node: call,
103
+ };
104
+ }
@@ -0,0 +1,10 @@
1
+ import type { TSESTree } from '@typescript-eslint/utils';
2
+ interface DetectData {
3
+ schemaDecl: 'namespace' | 'named';
4
+ schemaType: string;
5
+ methods: Array<string>;
6
+ node: TSESTree.CallExpression;
7
+ }
8
+ export type DetectResult = (DetectData & {}) | null;
9
+ export declare function detectZodSchemaRootNode(node: TSESTree.Node, zodNamespaces: Set<string>, zodNamedImports: Set<string>): DetectResult;
10
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { TSESTree } from '@typescript-eslint/utils';
2
+ interface DetectData {
3
+ schemaDecl: 'namespace' | 'named';
4
+ schemaType: string;
5
+ methods: Array<string>;
6
+ node: TSESTree.CallExpression;
7
+ }
8
+ export type DetectResult = (DetectData & {}) | null;
9
+ export declare function detectZodSchemaRootNode(node: TSESTree.Node, zodNamespaces: Set<string>, zodNamedImports: Set<string>): DetectResult;
10
+ export {};
@@ -0,0 +1,101 @@
1
+ import { AST_NODE_TYPES } from '@typescript-eslint/utils';
2
+ function getPropertyName(prop) {
3
+ if (!prop) {
4
+ return null;
5
+ }
6
+ if (prop.type === AST_NODE_TYPES.Identifier) {
7
+ return prop.name;
8
+ }
9
+ if (prop.type === AST_NODE_TYPES.Literal) {
10
+ return prop.value == null ? null : String(prop.value);
11
+ }
12
+ if (prop.type === AST_NODE_TYPES.TemplateLiteral) {
13
+ if (prop.expressions.length === 0 && prop.quasis.length === 1) {
14
+ return prop.quasis[0].value.cooked;
15
+ }
16
+ return null;
17
+ }
18
+ return null;
19
+ }
20
+ function isOutermostCallExpression(node) {
21
+ const { parent } = node;
22
+ if (parent.type === AST_NODE_TYPES.CallExpression && parent.callee === node) {
23
+ return false;
24
+ }
25
+ if (parent.type === AST_NODE_TYPES.MemberExpression &&
26
+ parent.object === node) {
27
+ return false;
28
+ }
29
+ return true;
30
+ }
31
+ function parseZodCallExpression(call, zodNamespaces, zodNamedImports) {
32
+ var _a;
33
+ let cur = call.callee;
34
+ const methodsRightToLeft = [];
35
+ let leftmostIdentifier = null;
36
+ while (true) {
37
+ if (cur.type === AST_NODE_TYPES.CallExpression) {
38
+ cur = cur.callee;
39
+ continue;
40
+ }
41
+ if (cur.type === AST_NODE_TYPES.MemberExpression) {
42
+ const name = getPropertyName(cur.property);
43
+ if (!name) {
44
+ return null;
45
+ }
46
+ methodsRightToLeft.push(name);
47
+ cur = cur.object;
48
+ continue;
49
+ }
50
+ if (cur.type === AST_NODE_TYPES.Identifier) {
51
+ leftmostIdentifier = cur.name;
52
+ break;
53
+ }
54
+ return null;
55
+ }
56
+ const methods = methodsRightToLeft.slice().reverse();
57
+ if (!leftmostIdentifier) {
58
+ return null;
59
+ }
60
+ if (zodNamespaces.has(leftmostIdentifier)) {
61
+ const factory = (_a = methods[0]) !== null && _a !== void 0 ? _a : null;
62
+ if (!factory) {
63
+ return null;
64
+ }
65
+ return {
66
+ schemaDecl: 'namespace',
67
+ schemaType: factory,
68
+ methods,
69
+ node: call,
70
+ };
71
+ }
72
+ if (zodNamedImports.has(leftmostIdentifier)) {
73
+ const factory = leftmostIdentifier;
74
+ return {
75
+ schemaDecl: 'named',
76
+ schemaType: factory,
77
+ methods,
78
+ node: call,
79
+ };
80
+ }
81
+ return null;
82
+ }
83
+ export function detectZodSchemaRootNode(node, zodNamespaces, zodNamedImports) {
84
+ if (node.type !== AST_NODE_TYPES.CallExpression) {
85
+ return null;
86
+ }
87
+ const call = node;
88
+ if (!isOutermostCallExpression(call)) {
89
+ return null;
90
+ }
91
+ const outer = parseZodCallExpression(call, zodNamespaces, zodNamedImports);
92
+ if (!outer) {
93
+ return null;
94
+ }
95
+ return {
96
+ schemaDecl: outer.schemaDecl,
97
+ schemaType: outer.schemaType,
98
+ methods: outer.methods,
99
+ node: call,
100
+ };
101
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOutermostCall = getOutermostCall;
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ function getOutermostCall(node) {
6
+ var _a;
7
+ let current = node;
8
+ while (((_a = current.parent) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.MemberExpression &&
9
+ current.parent.object === current &&
10
+ current.parent.parent.type === utils_1.AST_NODE_TYPES.CallExpression) {
11
+ current = current.parent.parent;
12
+ }
13
+ return current.type === utils_1.AST_NODE_TYPES.CallExpression ? current : null;
14
+ }
@@ -0,0 +1,2 @@
1
+ import type { TSESTree } from '@typescript-eslint/utils';
2
+ export declare function getOutermostCall(node: TSESTree.Node): TSESTree.CallExpression | null;
@@ -0,0 +1,2 @@
1
+ import type { TSESTree } from '@typescript-eslint/utils';
2
+ export declare function getOutermostCall(node: TSESTree.Node): TSESTree.CallExpression | null;
@@ -0,0 +1,11 @@
1
+ import { AST_NODE_TYPES } from '@typescript-eslint/utils';
2
+ export function getOutermostCall(node) {
3
+ var _a;
4
+ let current = node;
5
+ while (((_a = current.parent) === null || _a === void 0 ? void 0 : _a.type) === AST_NODE_TYPES.MemberExpression &&
6
+ current.parent.object === current &&
7
+ current.parent.parent.type === AST_NODE_TYPES.CallExpression) {
8
+ current = current.parent.parent;
9
+ }
10
+ return current.type === AST_NODE_TYPES.CallExpression ? current : null;
11
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isZodExpressionEndingWithMethod = isZodExpressionEndingWithMethod;
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ function isZodExpressionEndingWithMethod(node, propName) {
6
+ if (node.type !== utils_1.AST_NODE_TYPES.MemberExpression) {
7
+ return false;
8
+ }
9
+ if (node.property.type === utils_1.AST_NODE_TYPES.Identifier &&
10
+ node.property.name === propName) {
11
+ return true;
12
+ }
13
+ return false;
14
+ }
@@ -0,0 +1,2 @@
1
+ import type { TSESTree } from '@typescript-eslint/utils';
2
+ export declare function isZodExpressionEndingWithMethod(node: TSESTree.Node, propName: string): node is TSESTree.MemberExpression;
@@ -0,0 +1,2 @@
1
+ import type { TSESTree } from '@typescript-eslint/utils';
2
+ export declare function isZodExpressionEndingWithMethod(node: TSESTree.Node, propName: string): node is TSESTree.MemberExpression;
@@ -0,0 +1,11 @@
1
+ import { AST_NODE_TYPES } from '@typescript-eslint/utils';
2
+ export function isZodExpressionEndingWithMethod(node, propName) {
3
+ if (node.type !== AST_NODE_TYPES.MemberExpression) {
4
+ return false;
5
+ }
6
+ if (node.property.type === AST_NODE_TYPES.Identifier &&
7
+ node.property.name === propName) {
8
+ return true;
9
+ }
10
+ return false;
11
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isZodImportSource = isZodImportSource;
4
+ function isZodImportSource(source) {
5
+ return source === 'zod' || source.startsWith('zod/');
6
+ }
@@ -0,0 +1 @@
1
+ export declare function isZodImportSource(source: string): boolean;
@@ -0,0 +1 @@
1
+ export declare function isZodImportSource(source: string): boolean;
@@ -0,0 +1,3 @@
1
+ export function isZodImportSource(source) {
2
+ return source === 'zod' || source.startsWith('zod/');
3
+ }
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.trackZodSchemaImports = trackZodSchemaImports;
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ const detect_zod_schema_root_node_js_1 = require("./detect-zod-schema-root-node.cjs");
6
+ const is_zod_import_source_js_1 = require("./is-zod-import-source.cjs");
7
+ function trackZodSchemaImports() {
8
+ const zodNamespaces = new Set();
9
+ const zodNamedImports = new Set();
10
+ function collectZodChainMethods(node) {
11
+ const methods = [];
12
+ let current = node;
13
+ while (current.type === utils_1.AST_NODE_TYPES.CallExpression) {
14
+ const { callee } = current;
15
+ if (callee.type === utils_1.AST_NODE_TYPES.MemberExpression &&
16
+ callee.property.type === utils_1.AST_NODE_TYPES.Identifier) {
17
+ methods.unshift({
18
+ name: callee.property.name,
19
+ node: current,
20
+ });
21
+ current = callee.object;
22
+ continue;
23
+ }
24
+ if (callee.type === utils_1.AST_NODE_TYPES.Identifier) {
25
+ methods.unshift({
26
+ name: callee.name,
27
+ node: current,
28
+ });
29
+ break;
30
+ }
31
+ break;
32
+ }
33
+ return methods;
34
+ }
35
+ const result = {
36
+ importDeclarationListener(node) {
37
+ if (!(0, is_zod_import_source_js_1.isZodImportSource)(node.source.value)) {
38
+ return;
39
+ }
40
+ for (const spec of node.specifiers) {
41
+ switch (spec.type) {
42
+ case utils_1.AST_NODE_TYPES.ImportDefaultSpecifier:
43
+ case utils_1.AST_NODE_TYPES.ImportNamespaceSpecifier:
44
+ zodNamespaces.add(spec.local.name);
45
+ break;
46
+ case utils_1.AST_NODE_TYPES.ImportSpecifier:
47
+ if ('name' in spec.imported && spec.imported.name === 'z') {
48
+ zodNamespaces.add(spec.local.name);
49
+ }
50
+ else {
51
+ zodNamedImports.add(spec.local.name);
52
+ }
53
+ break;
54
+ }
55
+ }
56
+ },
57
+ detectZodSchemaRootNode: (node) => (0, detect_zod_schema_root_node_js_1.detectZodSchemaRootNode)(node, zodNamespaces, zodNamedImports),
58
+ collectZodChainMethods,
59
+ };
60
+ return result;
61
+ }
@@ -0,0 +1,13 @@
1
+ import type { TSESTree } from '@typescript-eslint/utils';
2
+ import type { DetectResult } from "./detect-zod-schema-root-node.cjs";
3
+ interface ZodChainItem {
4
+ name: string;
5
+ node: TSESTree.CallExpression;
6
+ }
7
+ interface Result {
8
+ importDeclarationListener: (node: TSESTree.ImportDeclaration) => void;
9
+ detectZodSchemaRootNode: (node: TSESTree.Node) => null | DetectResult;
10
+ collectZodChainMethods: (node: TSESTree.CallExpression) => Array<ZodChainItem>;
11
+ }
12
+ export declare function trackZodSchemaImports(): Result;
13
+ export {};
@@ -0,0 +1,13 @@
1
+ import type { TSESTree } from '@typescript-eslint/utils';
2
+ import type { DetectResult } from "./detect-zod-schema-root-node.js";
3
+ interface ZodChainItem {
4
+ name: string;
5
+ node: TSESTree.CallExpression;
6
+ }
7
+ interface Result {
8
+ importDeclarationListener: (node: TSESTree.ImportDeclaration) => void;
9
+ detectZodSchemaRootNode: (node: TSESTree.Node) => null | DetectResult;
10
+ collectZodChainMethods: (node: TSESTree.CallExpression) => Array<ZodChainItem>;
11
+ }
12
+ export declare function trackZodSchemaImports(): Result;
13
+ export {};
@@ -0,0 +1,58 @@
1
+ import { AST_NODE_TYPES } from '@typescript-eslint/utils';
2
+ import { detectZodSchemaRootNode } from "./detect-zod-schema-root-node.js";
3
+ import { isZodImportSource } from "./is-zod-import-source.js";
4
+ export function trackZodSchemaImports() {
5
+ const zodNamespaces = new Set();
6
+ const zodNamedImports = new Set();
7
+ function collectZodChainMethods(node) {
8
+ const methods = [];
9
+ let current = node;
10
+ while (current.type === AST_NODE_TYPES.CallExpression) {
11
+ const { callee } = current;
12
+ if (callee.type === AST_NODE_TYPES.MemberExpression &&
13
+ callee.property.type === AST_NODE_TYPES.Identifier) {
14
+ methods.unshift({
15
+ name: callee.property.name,
16
+ node: current,
17
+ });
18
+ current = callee.object;
19
+ continue;
20
+ }
21
+ if (callee.type === AST_NODE_TYPES.Identifier) {
22
+ methods.unshift({
23
+ name: callee.name,
24
+ node: current,
25
+ });
26
+ break;
27
+ }
28
+ break;
29
+ }
30
+ return methods;
31
+ }
32
+ const result = {
33
+ importDeclarationListener(node) {
34
+ if (!isZodImportSource(node.source.value)) {
35
+ return;
36
+ }
37
+ for (const spec of node.specifiers) {
38
+ switch (spec.type) {
39
+ case AST_NODE_TYPES.ImportDefaultSpecifier:
40
+ case AST_NODE_TYPES.ImportNamespaceSpecifier:
41
+ zodNamespaces.add(spec.local.name);
42
+ break;
43
+ case AST_NODE_TYPES.ImportSpecifier:
44
+ if ('name' in spec.imported && spec.imported.name === 'z') {
45
+ zodNamespaces.add(spec.local.name);
46
+ }
47
+ else {
48
+ zodNamedImports.add(spec.local.name);
49
+ }
50
+ break;
51
+ }
52
+ }
53
+ },
54
+ detectZodSchemaRootNode: (node) => detectZodSchemaRootNode(node, zodNamespaces, zodNamedImports),
55
+ collectZodChainMethods,
56
+ };
57
+ return result;
58
+ }