eslint-plugin-zod 3.5.2 → 3.5.3
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.
|
@@ -15,14 +15,16 @@ const noEmptyCustomSchema = require_create_plugin_rule.createZodPluginRule({
|
|
|
15
15
|
},
|
|
16
16
|
defaultOptions: [],
|
|
17
17
|
create(context) {
|
|
18
|
-
const { importDeclarationListener, detectZodSchemaRootNode } = trackZodSchemaImports();
|
|
18
|
+
const { importDeclarationListener, detectZodSchemaRootNode, collectZodChainMethods } = trackZodSchemaImports();
|
|
19
19
|
return {
|
|
20
20
|
ImportDeclaration: importDeclarationListener,
|
|
21
21
|
CallExpression(node) {
|
|
22
22
|
const zodSchemaMeta = detectZodSchemaRootNode(node);
|
|
23
23
|
if (!zodSchemaMeta) return;
|
|
24
|
-
if (zodSchemaMeta.schemaType
|
|
25
|
-
|
|
24
|
+
if (zodSchemaMeta.schemaType !== "custom") return;
|
|
25
|
+
const customCallNode = collectZodChainMethods(node).find((method) => method.name === "custom")?.node;
|
|
26
|
+
if (customCallNode?.arguments.length === 0) context.report({
|
|
27
|
+
node: customCallNode,
|
|
26
28
|
messageId: "noEmptyCustomSchema"
|
|
27
29
|
});
|
|
28
30
|
}
|
|
@@ -16,14 +16,16 @@ const noEmptyCustomSchema = createZodPluginRule({
|
|
|
16
16
|
},
|
|
17
17
|
defaultOptions: [],
|
|
18
18
|
create(context) {
|
|
19
|
-
const { importDeclarationListener, detectZodSchemaRootNode } = trackZodSchemaImports();
|
|
19
|
+
const { importDeclarationListener, detectZodSchemaRootNode, collectZodChainMethods } = trackZodSchemaImports();
|
|
20
20
|
return {
|
|
21
21
|
ImportDeclaration: importDeclarationListener,
|
|
22
22
|
CallExpression(node) {
|
|
23
23
|
const zodSchemaMeta = detectZodSchemaRootNode(node);
|
|
24
24
|
if (!zodSchemaMeta) return;
|
|
25
|
-
if (zodSchemaMeta.schemaType
|
|
26
|
-
|
|
25
|
+
if (zodSchemaMeta.schemaType !== "custom") return;
|
|
26
|
+
const customCallNode = collectZodChainMethods(node).find((method) => method.name === "custom")?.node;
|
|
27
|
+
if (customCallNode?.arguments.length === 0) context.report({
|
|
28
|
+
node: customCallNode,
|
|
27
29
|
messageId: "noEmptyCustomSchema"
|
|
28
30
|
});
|
|
29
31
|
}
|
|
@@ -27,19 +27,20 @@ const requireErrorMessage = require_create_plugin_rule.createZodPluginRule({
|
|
|
27
27
|
ImportDeclaration: importDeclarationListener,
|
|
28
28
|
CallExpression(node) {
|
|
29
29
|
if (!detectZodSchemaRootNode(node)) return;
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
30
|
+
const refines = collectZodChainMethods(node).filter((it) => it.name === "refine" || it.name === "custom");
|
|
31
|
+
if (refines.length === 0) return;
|
|
32
|
+
for (const refine of refines) {
|
|
33
|
+
const refineNode = refine.node;
|
|
34
|
+
if (refineNode.arguments.length < 2) {
|
|
35
|
+
context.report({
|
|
36
|
+
messageId: "requireErrorMessage",
|
|
37
|
+
node: refineNode
|
|
38
|
+
});
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const [, params] = refineNode.arguments;
|
|
42
|
+
if (params.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal) continue;
|
|
43
|
+
if (params.type !== _typescript_eslint_utils.AST_NODE_TYPES.ObjectExpression) continue;
|
|
43
44
|
let errorPropertyNode;
|
|
44
45
|
let messagePropertyNode;
|
|
45
46
|
for (const property of params.properties) if (property.type === _typescript_eslint_utils.AST_NODE_TYPES.Property && property.key.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier) {
|
|
@@ -59,7 +60,7 @@ const requireErrorMessage = require_create_plugin_rule.createZodPluginRule({
|
|
|
59
60
|
return fixer.removeRange([messagePropertyNode.range[0], end]);
|
|
60
61
|
}
|
|
61
62
|
});
|
|
62
|
-
|
|
63
|
+
continue;
|
|
63
64
|
}
|
|
64
65
|
if (messagePropertyNode && !errorPropertyNode) {
|
|
65
66
|
context.report({
|
|
@@ -69,7 +70,7 @@ const requireErrorMessage = require_create_plugin_rule.createZodPluginRule({
|
|
|
69
70
|
return fixer.replaceTextRange(messagePropertyNode.key.range, "error");
|
|
70
71
|
}
|
|
71
72
|
});
|
|
72
|
-
|
|
73
|
+
continue;
|
|
73
74
|
}
|
|
74
75
|
if (!errorPropertyNode) context.report({
|
|
75
76
|
messageId: "requireErrorMessage",
|
|
@@ -26,19 +26,20 @@ const requireErrorMessage = createZodPluginRule({
|
|
|
26
26
|
ImportDeclaration: importDeclarationListener,
|
|
27
27
|
CallExpression(node) {
|
|
28
28
|
if (!detectZodSchemaRootNode(node)) return;
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
29
|
+
const refines = collectZodChainMethods(node).filter((it) => it.name === "refine" || it.name === "custom");
|
|
30
|
+
if (refines.length === 0) return;
|
|
31
|
+
for (const refine of refines) {
|
|
32
|
+
const refineNode = refine.node;
|
|
33
|
+
if (refineNode.arguments.length < 2) {
|
|
34
|
+
context.report({
|
|
35
|
+
messageId: "requireErrorMessage",
|
|
36
|
+
node: refineNode
|
|
37
|
+
});
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const [, params] = refineNode.arguments;
|
|
41
|
+
if (params.type === AST_NODE_TYPES.Literal) continue;
|
|
42
|
+
if (params.type !== AST_NODE_TYPES.ObjectExpression) continue;
|
|
42
43
|
let errorPropertyNode;
|
|
43
44
|
let messagePropertyNode;
|
|
44
45
|
for (const property of params.properties) if (property.type === AST_NODE_TYPES.Property && property.key.type === AST_NODE_TYPES.Identifier) {
|
|
@@ -58,7 +59,7 @@ const requireErrorMessage = createZodPluginRule({
|
|
|
58
59
|
return fixer.removeRange([messagePropertyNode.range[0], end]);
|
|
59
60
|
}
|
|
60
61
|
});
|
|
61
|
-
|
|
62
|
+
continue;
|
|
62
63
|
}
|
|
63
64
|
if (messagePropertyNode && !errorPropertyNode) {
|
|
64
65
|
context.report({
|
|
@@ -68,7 +69,7 @@ const requireErrorMessage = createZodPluginRule({
|
|
|
68
69
|
return fixer.replaceTextRange(messagePropertyNode.key.range, "error");
|
|
69
70
|
}
|
|
70
71
|
});
|
|
71
|
-
|
|
72
|
+
continue;
|
|
72
73
|
}
|
|
73
74
|
if (!errorPropertyNode) context.report({
|
|
74
75
|
messageId: "requireErrorMessage",
|