eslint-plugin-zod 4.1.0 → 4.2.1
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/README.md +1 -0
- package/dist/index.cjs +3 -0
- package/dist/index.mjs +3 -0
- package/dist/rules/array-style.cjs +3 -3
- package/dist/rules/array-style.mjs +3 -3
- package/dist/rules/no-native-enum.cjs +38 -0
- package/dist/rules/no-native-enum.mjs +37 -0
- package/dist/rules/no-number-schema-with-int.cjs +1 -7
- package/dist/rules/no-number-schema-with-int.mjs +1 -7
- package/dist/rules/no-number-schema-with-safe.cjs +1 -7
- package/dist/rules/no-number-schema-with-safe.mjs +1 -7
- package/dist/rules/no-string-schema-with-uuid.cjs +1 -7
- package/dist/rules/no-string-schema-with-uuid.mjs +1 -7
- package/dist/rules/prefer-enum-over-literal-union.cjs +4 -10
- package/dist/rules/prefer-enum-over-literal-union.mjs +4 -10
- package/dist/rules/prefer-string-schema-with-trim.cjs +1 -7
- package/dist/rules/prefer-string-schema-with-trim.mjs +1 -7
- package/dist/rules/prefer-top-level-string-formats.cjs +1 -11
- package/dist/rules/prefer-top-level-string-formats.mjs +1 -11
- package/dist/rules/prefer-trim-before-string-length-checks.cjs +1 -7
- package/dist/rules/prefer-trim-before-string-length-checks.mjs +1 -7
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -42,6 +42,7 @@ Find out more about [Oxlint's `jsPLugins`](https://oxc.rs/docs/guide/usage/linte
|
|
|
42
42
|
| [consistent-schema-var-name](docs/rules/consistent-schema-var-name.md) | Enforce a consistent naming convention for Zod schema variables | ✅ | | | |
|
|
43
43
|
| [no-any-schema](docs/rules/no-any-schema.md) | Disallow usage of `z.any()` in Zod schemas | ✅ | | 💡 | |
|
|
44
44
|
| [no-empty-custom-schema](docs/rules/no-empty-custom-schema.md) | Disallow usage of `z.custom()` without arguments | ✅ | | | |
|
|
45
|
+
| [no-native-enum](docs/rules/no-native-enum.md) | Disallow deprecated `z.nativeEnum()` in favor of `z.enum()`. | ✅ | 🔧 | | |
|
|
45
46
|
| [no-number-schema-with-finite](docs/rules/no-number-schema-with-finite.md) | Disallow deprecated `z.number().finite()`. In Zod 4+ number schemas do not allow infinite values by default, so it is a no-op. | ✅ | 🔧 | | |
|
|
46
47
|
| [no-number-schema-with-int](docs/rules/no-number-schema-with-int.md) | Disallow usage of `z.number().int()` as it is considered legacy | ✅ | 🔧 | | |
|
|
47
48
|
| [no-number-schema-with-is-finite](docs/rules/no-number-schema-with-is-finite.md) | Disallow using deprecated `isFinite` on a Zod number schema; in v4+ it is always `true`. | ✅ | | | |
|
package/dist/index.cjs
CHANGED
|
@@ -7,6 +7,7 @@ const require_consistent_schema_output_type_style = require("./rules/consistent-
|
|
|
7
7
|
const require_consistent_schema_var_name = require("./rules/consistent-schema-var-name.cjs");
|
|
8
8
|
const require_no_any_schema = require("./rules/no-any-schema.cjs");
|
|
9
9
|
const require_no_empty_custom_schema = require("./rules/no-empty-custom-schema.cjs");
|
|
10
|
+
const require_no_native_enum = require("./rules/no-native-enum.cjs");
|
|
10
11
|
const require_no_number_schema_with_finite = require("./rules/no-number-schema-with-finite.cjs");
|
|
11
12
|
const require_no_number_schema_with_int = require("./rules/no-number-schema-with-int.cjs");
|
|
12
13
|
const require_no_number_schema_with_is_finite = require("./rules/no-number-schema-with-is-finite.cjs");
|
|
@@ -42,6 +43,7 @@ const eslintPluginZod = {
|
|
|
42
43
|
"consistent-schema-output-type-style": require_consistent_schema_output_type_style.consistentSchemaOutputTypeStyle,
|
|
43
44
|
"no-any-schema": require_no_any_schema.noAnySchema,
|
|
44
45
|
"no-empty-custom-schema": require_no_empty_custom_schema.noEmptyCustomSchema,
|
|
46
|
+
"no-native-enum": require_no_native_enum.noNativeEnum,
|
|
45
47
|
"no-number-schema-with-finite": require_no_number_schema_with_finite.noNumberSchemaWithFinite,
|
|
46
48
|
"no-number-schema-with-int": require_no_number_schema_with_int.noNumberSchemaWithInt,
|
|
47
49
|
"no-number-schema-with-is-finite": require_no_number_schema_with_is_finite.noNumberSchemaWithIsFinite,
|
|
@@ -74,6 +76,7 @@ const recommendedConfig = {
|
|
|
74
76
|
"zod/consistent-schema-var-name": "error",
|
|
75
77
|
"zod/no-any-schema": "error",
|
|
76
78
|
"zod/no-empty-custom-schema": "error",
|
|
79
|
+
"zod/no-native-enum": "error",
|
|
77
80
|
"zod/no-number-schema-with-finite": "error",
|
|
78
81
|
"zod/no-number-schema-with-int": "error",
|
|
79
82
|
"zod/no-number-schema-with-is-finite": "error",
|
package/dist/index.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import { consistentSchemaOutputTypeStyle } from "./rules/consistent-schema-outpu
|
|
|
7
7
|
import { consistentSchemaVarName } from "./rules/consistent-schema-var-name.mjs";
|
|
8
8
|
import { noAnySchema } from "./rules/no-any-schema.mjs";
|
|
9
9
|
import { noEmptyCustomSchema } from "./rules/no-empty-custom-schema.mjs";
|
|
10
|
+
import { noNativeEnum } from "./rules/no-native-enum.mjs";
|
|
10
11
|
import { noNumberSchemaWithFinite } from "./rules/no-number-schema-with-finite.mjs";
|
|
11
12
|
import { noNumberSchemaWithInt } from "./rules/no-number-schema-with-int.mjs";
|
|
12
13
|
import { noNumberSchemaWithIsFinite } from "./rules/no-number-schema-with-is-finite.mjs";
|
|
@@ -42,6 +43,7 @@ const eslintPluginZod = {
|
|
|
42
43
|
"consistent-schema-output-type-style": consistentSchemaOutputTypeStyle,
|
|
43
44
|
"no-any-schema": noAnySchema,
|
|
44
45
|
"no-empty-custom-schema": noEmptyCustomSchema,
|
|
46
|
+
"no-native-enum": noNativeEnum,
|
|
45
47
|
"no-number-schema-with-finite": noNumberSchemaWithFinite,
|
|
46
48
|
"no-number-schema-with-int": noNumberSchemaWithInt,
|
|
47
49
|
"no-number-schema-with-is-finite": noNumberSchemaWithIsFinite,
|
|
@@ -74,6 +76,7 @@ const recommendedConfig = {
|
|
|
74
76
|
"zod/consistent-schema-var-name": "error",
|
|
75
77
|
"zod/no-any-schema": "error",
|
|
76
78
|
"zod/no-empty-custom-schema": "error",
|
|
79
|
+
"zod/no-native-enum": "error",
|
|
77
80
|
"zod/no-number-schema-with-finite": "error",
|
|
78
81
|
"zod/no-number-schema-with-int": "error",
|
|
79
82
|
"zod/no-number-schema-with-is-finite": "error",
|
|
@@ -32,9 +32,9 @@ const arrayStyle = require_create_plugin_rule.createZodPluginRule({
|
|
|
32
32
|
return {
|
|
33
33
|
ImportDeclaration: importDeclarationListener,
|
|
34
34
|
CallExpression(node) {
|
|
35
|
-
const
|
|
36
|
-
if (!
|
|
37
|
-
const { schemaDecl, schemaType } =
|
|
35
|
+
const zodSchemaMeta = detectZodSchemaRootNode(node);
|
|
36
|
+
if (!zodSchemaMeta) return;
|
|
37
|
+
const { schemaDecl, schemaType } = zodSchemaMeta;
|
|
38
38
|
if (style === "method") {
|
|
39
39
|
if (schemaType === "array") {
|
|
40
40
|
if (schemaDecl === "namespace") {
|
|
@@ -31,9 +31,9 @@ const arrayStyle = createZodPluginRule({
|
|
|
31
31
|
return {
|
|
32
32
|
ImportDeclaration: importDeclarationListener,
|
|
33
33
|
CallExpression(node) {
|
|
34
|
-
const
|
|
35
|
-
if (!
|
|
36
|
-
const { schemaDecl, schemaType } =
|
|
34
|
+
const zodSchemaMeta = detectZodSchemaRootNode(node);
|
|
35
|
+
if (!zodSchemaMeta) return;
|
|
36
|
+
const { schemaDecl, schemaType } = zodSchemaMeta;
|
|
37
37
|
if (style === "method") {
|
|
38
38
|
if (schemaType === "array") {
|
|
39
39
|
if (schemaDecl === "namespace") {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
|
|
3
|
+
let _eslint_zod_utils = require("@eslint-zod/utils");
|
|
4
|
+
let _typescript_eslint_utils = require("@typescript-eslint/utils");
|
|
5
|
+
//#region src/rules/no-native-enum.ts
|
|
6
|
+
const { trackZodSchemaImports } = (0, _eslint_zod_utils.createZodSchemaImportTrack)(_eslint_zod_utils.zodImportScope);
|
|
7
|
+
const noNativeEnum = require_create_plugin_rule.createZodPluginRule({
|
|
8
|
+
name: "no-native-enum",
|
|
9
|
+
meta: {
|
|
10
|
+
type: "problem",
|
|
11
|
+
fixable: "code",
|
|
12
|
+
docs: { description: "Disallow deprecated `z.nativeEnum()` in favor of `z.enum()`." },
|
|
13
|
+
messages: { useEnum: "`z.nativeEnum()` is deprecated in Zod 4. Use `z.enum()` instead." },
|
|
14
|
+
schema: []
|
|
15
|
+
},
|
|
16
|
+
defaultOptions: [],
|
|
17
|
+
create(context) {
|
|
18
|
+
const { importDeclarationListener, detectZodSchemaRootNode, collectZodChainMethods } = trackZodSchemaImports();
|
|
19
|
+
return {
|
|
20
|
+
ImportDeclaration: importDeclarationListener,
|
|
21
|
+
CallExpression(node) {
|
|
22
|
+
const zodSchemaMeta = detectZodSchemaRootNode(node);
|
|
23
|
+
if (zodSchemaMeta?.schemaType !== "nativeEnum") return;
|
|
24
|
+
const [{ node: rootMethodNode }] = collectZodChainMethods(zodSchemaMeta.node);
|
|
25
|
+
context.report({
|
|
26
|
+
node,
|
|
27
|
+
messageId: "useEnum",
|
|
28
|
+
fix(fixer) {
|
|
29
|
+
if (rootMethodNode.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return null;
|
|
30
|
+
return fixer.replaceText(rootMethodNode.callee.property, "enum");
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.noNativeEnum = noNativeEnum;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
|
+
import { createZodSchemaImportTrack, zodImportScope } from "@eslint-zod/utils";
|
|
3
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
4
|
+
//#region src/rules/no-native-enum.ts
|
|
5
|
+
const { trackZodSchemaImports } = createZodSchemaImportTrack(zodImportScope);
|
|
6
|
+
const noNativeEnum = createZodPluginRule({
|
|
7
|
+
name: "no-native-enum",
|
|
8
|
+
meta: {
|
|
9
|
+
type: "problem",
|
|
10
|
+
fixable: "code",
|
|
11
|
+
docs: { description: "Disallow deprecated `z.nativeEnum()` in favor of `z.enum()`." },
|
|
12
|
+
messages: { useEnum: "`z.nativeEnum()` is deprecated in Zod 4. Use `z.enum()` instead." },
|
|
13
|
+
schema: []
|
|
14
|
+
},
|
|
15
|
+
defaultOptions: [],
|
|
16
|
+
create(context) {
|
|
17
|
+
const { importDeclarationListener, detectZodSchemaRootNode, collectZodChainMethods } = trackZodSchemaImports();
|
|
18
|
+
return {
|
|
19
|
+
ImportDeclaration: importDeclarationListener,
|
|
20
|
+
CallExpression(node) {
|
|
21
|
+
const zodSchemaMeta = detectZodSchemaRootNode(node);
|
|
22
|
+
if (zodSchemaMeta?.schemaType !== "nativeEnum") return;
|
|
23
|
+
const [{ node: rootMethodNode }] = collectZodChainMethods(zodSchemaMeta.node);
|
|
24
|
+
context.report({
|
|
25
|
+
node,
|
|
26
|
+
messageId: "useEnum",
|
|
27
|
+
fix(fixer) {
|
|
28
|
+
if (rootMethodNode.callee.type !== AST_NODE_TYPES.MemberExpression) return null;
|
|
29
|
+
return fixer.replaceText(rootMethodNode.callee.property, "enum");
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
//#endregion
|
|
37
|
+
export { noNativeEnum };
|
|
@@ -25,17 +25,11 @@ const noNumberSchemaWithInt = require_create_plugin_rule.createZodPluginRule({
|
|
|
25
25
|
const intIndex = methods.findIndex((m) => m.name === "int");
|
|
26
26
|
if (intIndex === -1) return;
|
|
27
27
|
const numberIndex = methods.findIndex((m) => m.name === "number");
|
|
28
|
-
if (zodSchemaMeta.schemaDecl === "named") {
|
|
29
|
-
context.report({
|
|
30
|
-
node,
|
|
31
|
-
messageId: "removeNumber"
|
|
32
|
-
});
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
28
|
context.report({
|
|
36
29
|
node,
|
|
37
30
|
messageId: "removeNumber",
|
|
38
31
|
fix(fixer) {
|
|
32
|
+
if (zodSchemaMeta.schemaDecl === "named") return null;
|
|
39
33
|
return (0, _eslint_zod_utils.buildZodChainReplacementFix)({
|
|
40
34
|
sourceCode,
|
|
41
35
|
fixer,
|
|
@@ -24,17 +24,11 @@ const noNumberSchemaWithInt = createZodPluginRule({
|
|
|
24
24
|
const intIndex = methods.findIndex((m) => m.name === "int");
|
|
25
25
|
if (intIndex === -1) return;
|
|
26
26
|
const numberIndex = methods.findIndex((m) => m.name === "number");
|
|
27
|
-
if (zodSchemaMeta.schemaDecl === "named") {
|
|
28
|
-
context.report({
|
|
29
|
-
node,
|
|
30
|
-
messageId: "removeNumber"
|
|
31
|
-
});
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
27
|
context.report({
|
|
35
28
|
node,
|
|
36
29
|
messageId: "removeNumber",
|
|
37
30
|
fix(fixer) {
|
|
31
|
+
if (zodSchemaMeta.schemaDecl === "named") return null;
|
|
38
32
|
return buildZodChainReplacementFix({
|
|
39
33
|
sourceCode,
|
|
40
34
|
fixer,
|
|
@@ -25,17 +25,11 @@ const noNumberSchemaWithSafe = require_create_plugin_rule.createZodPluginRule({
|
|
|
25
25
|
const safeIndex = methods.findIndex((m) => m.name === "safe" && m.node === node);
|
|
26
26
|
if (safeIndex === -1) return;
|
|
27
27
|
const numberIndex = methods.findIndex((m) => m.name === "number");
|
|
28
|
-
if (zodSchemaMeta.schemaDecl === "named") {
|
|
29
|
-
context.report({
|
|
30
|
-
node,
|
|
31
|
-
messageId: "useInt"
|
|
32
|
-
});
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
28
|
context.report({
|
|
36
29
|
node,
|
|
37
30
|
messageId: "useInt",
|
|
38
31
|
fix(fixer) {
|
|
32
|
+
if (zodSchemaMeta.schemaDecl === "named") return null;
|
|
39
33
|
return (0, _eslint_zod_utils.buildZodChainReplacementFix)({
|
|
40
34
|
sourceCode,
|
|
41
35
|
fixer,
|
|
@@ -24,17 +24,11 @@ const noNumberSchemaWithSafe = createZodPluginRule({
|
|
|
24
24
|
const safeIndex = methods.findIndex((m) => m.name === "safe" && m.node === node);
|
|
25
25
|
if (safeIndex === -1) return;
|
|
26
26
|
const numberIndex = methods.findIndex((m) => m.name === "number");
|
|
27
|
-
if (zodSchemaMeta.schemaDecl === "named") {
|
|
28
|
-
context.report({
|
|
29
|
-
node,
|
|
30
|
-
messageId: "useInt"
|
|
31
|
-
});
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
27
|
context.report({
|
|
35
28
|
node,
|
|
36
29
|
messageId: "useInt",
|
|
37
30
|
fix(fixer) {
|
|
31
|
+
if (zodSchemaMeta.schemaDecl === "named") return null;
|
|
38
32
|
return buildZodChainReplacementFix({
|
|
39
33
|
sourceCode,
|
|
40
34
|
fixer,
|
|
@@ -29,17 +29,11 @@ const noStringSchemaWithUuid = require_create_plugin_rule.createZodPluginRule({
|
|
|
29
29
|
const uuidIndex = methods.findIndex((m) => m.name === "uuid");
|
|
30
30
|
if (uuidIndex === -1) return;
|
|
31
31
|
const stringIndex = methods.findIndex((m) => m.name === "string");
|
|
32
|
-
if (zodSchemaMeta.schemaDecl === "named") {
|
|
33
|
-
context.report({
|
|
34
|
-
node,
|
|
35
|
-
messageId: "useUuid"
|
|
36
|
-
});
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
32
|
context.report({
|
|
40
33
|
node,
|
|
41
34
|
messageId: "useUuid",
|
|
42
35
|
fix(fixer) {
|
|
36
|
+
if (zodSchemaMeta.schemaDecl === "named") return null;
|
|
43
37
|
return (0, _eslint_zod_utils.buildZodChainReplacementFix)({
|
|
44
38
|
sourceCode,
|
|
45
39
|
fixer,
|
|
@@ -28,17 +28,11 @@ const noStringSchemaWithUuid = createZodPluginRule({
|
|
|
28
28
|
const uuidIndex = methods.findIndex((m) => m.name === "uuid");
|
|
29
29
|
if (uuidIndex === -1) return;
|
|
30
30
|
const stringIndex = methods.findIndex((m) => m.name === "string");
|
|
31
|
-
if (zodSchemaMeta.schemaDecl === "named") {
|
|
32
|
-
context.report({
|
|
33
|
-
node,
|
|
34
|
-
messageId: "useUuid"
|
|
35
|
-
});
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
31
|
context.report({
|
|
39
32
|
node,
|
|
40
33
|
messageId: "useUuid",
|
|
41
34
|
fix(fixer) {
|
|
35
|
+
if (zodSchemaMeta.schemaDecl === "named") return null;
|
|
42
36
|
return buildZodChainReplacementFix({
|
|
43
37
|
sourceCode,
|
|
44
38
|
fixer,
|
|
@@ -19,9 +19,9 @@ const preferEnumOverLiteralUnion = require_create_plugin_rule.createZodPluginRul
|
|
|
19
19
|
return {
|
|
20
20
|
ImportDeclaration: importDeclarationListener,
|
|
21
21
|
CallExpression(node) {
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
24
|
-
const union = collectZodChainMethods(
|
|
22
|
+
const zodSchemaMeta = detectZodSchemaRootNode(node);
|
|
23
|
+
if (zodSchemaMeta?.schemaType !== "union") return;
|
|
24
|
+
const union = collectZodChainMethods(zodSchemaMeta.node).find((it) => it.name === "union");
|
|
25
25
|
if (!union) return;
|
|
26
26
|
const unionNode = union.node;
|
|
27
27
|
const unionArgument = unionNode.arguments.at(0);
|
|
@@ -39,17 +39,11 @@ const preferEnumOverLiteralUnion = require_create_plugin_rule.createZodPluginRul
|
|
|
39
39
|
return null;
|
|
40
40
|
});
|
|
41
41
|
if (zodLiteralStrings.some((it) => it === null)) return;
|
|
42
|
-
if (zodSchema.schemaDecl === "named") {
|
|
43
|
-
context.report({
|
|
44
|
-
node,
|
|
45
|
-
messageId: "useEnum"
|
|
46
|
-
});
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
42
|
context.report({
|
|
50
43
|
node,
|
|
51
44
|
messageId: "useEnum",
|
|
52
45
|
fix(fixer) {
|
|
46
|
+
if (zodSchemaMeta.schemaDecl === "named") return null;
|
|
53
47
|
return [fixer.replaceText(unionNode.callee.property, "enum"), fixer.replaceText(unionNode.arguments[0], `[${zodLiteralStrings.join(", ")}]`)];
|
|
54
48
|
}
|
|
55
49
|
});
|
|
@@ -18,9 +18,9 @@ const preferEnumOverLiteralUnion = createZodPluginRule({
|
|
|
18
18
|
return {
|
|
19
19
|
ImportDeclaration: importDeclarationListener,
|
|
20
20
|
CallExpression(node) {
|
|
21
|
-
const
|
|
22
|
-
if (
|
|
23
|
-
const union = collectZodChainMethods(
|
|
21
|
+
const zodSchemaMeta = detectZodSchemaRootNode(node);
|
|
22
|
+
if (zodSchemaMeta?.schemaType !== "union") return;
|
|
23
|
+
const union = collectZodChainMethods(zodSchemaMeta.node).find((it) => it.name === "union");
|
|
24
24
|
if (!union) return;
|
|
25
25
|
const unionNode = union.node;
|
|
26
26
|
const unionArgument = unionNode.arguments.at(0);
|
|
@@ -38,17 +38,11 @@ const preferEnumOverLiteralUnion = createZodPluginRule({
|
|
|
38
38
|
return null;
|
|
39
39
|
});
|
|
40
40
|
if (zodLiteralStrings.some((it) => it === null)) return;
|
|
41
|
-
if (zodSchema.schemaDecl === "named") {
|
|
42
|
-
context.report({
|
|
43
|
-
node,
|
|
44
|
-
messageId: "useEnum"
|
|
45
|
-
});
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
41
|
context.report({
|
|
49
42
|
node,
|
|
50
43
|
messageId: "useEnum",
|
|
51
44
|
fix(fixer) {
|
|
45
|
+
if (zodSchemaMeta.schemaDecl === "named") return null;
|
|
52
46
|
return [fixer.replaceText(unionNode.callee.property, "enum"), fixer.replaceText(unionNode.arguments[0], `[${zodLiteralStrings.join(", ")}]`)];
|
|
53
47
|
}
|
|
54
48
|
});
|
|
@@ -26,17 +26,11 @@ const preferStringSchemaWithTrim = require_create_plugin_rule.createZodPluginRul
|
|
|
26
26
|
})) return;
|
|
27
27
|
const methods = collectZodChainMethods(zodSchemaMeta.node);
|
|
28
28
|
if (methods.some((it) => it.name === "trim")) return;
|
|
29
|
-
if (zodSchemaMeta.schemaDecl === "named") {
|
|
30
|
-
context.report({
|
|
31
|
-
node,
|
|
32
|
-
messageId: "addTrim"
|
|
33
|
-
});
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
29
|
context.report({
|
|
37
30
|
node,
|
|
38
31
|
messageId: "addTrim",
|
|
39
32
|
fix(fixer) {
|
|
33
|
+
if (zodSchemaMeta.schemaDecl === "named") return null;
|
|
40
34
|
const lastMethod = methods.at(0);
|
|
41
35
|
return fixer.insertTextAfter(lastMethod.node, ".trim()");
|
|
42
36
|
}
|
|
@@ -25,17 +25,11 @@ const preferStringSchemaWithTrim = createZodPluginRule({
|
|
|
25
25
|
})) return;
|
|
26
26
|
const methods = collectZodChainMethods(zodSchemaMeta.node);
|
|
27
27
|
if (methods.some((it) => it.name === "trim")) return;
|
|
28
|
-
if (zodSchemaMeta.schemaDecl === "named") {
|
|
29
|
-
context.report({
|
|
30
|
-
node,
|
|
31
|
-
messageId: "addTrim"
|
|
32
|
-
});
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
28
|
context.report({
|
|
36
29
|
node,
|
|
37
30
|
messageId: "addTrim",
|
|
38
31
|
fix(fixer) {
|
|
32
|
+
if (zodSchemaMeta.schemaDecl === "named") return null;
|
|
39
33
|
const lastMethod = methods.at(0);
|
|
40
34
|
return fixer.insertTextAfter(lastMethod.node, ".trim()");
|
|
41
35
|
}
|
|
@@ -156,17 +156,6 @@ const preferTopLevelStringFormats = require_create_plugin_rule.createZodPluginRu
|
|
|
156
156
|
if (!formatMethod) return;
|
|
157
157
|
if (!isTopLevelStringFormatMethodName(formatMethod.name)) return;
|
|
158
158
|
const { replacementMethodName, sourceMethodName } = TOP_LEVEL_STRING_FORMATS_BY_SOURCE[formatMethod.name];
|
|
159
|
-
if (zodSchemaMeta.schemaDecl === "named") {
|
|
160
|
-
context.report({
|
|
161
|
-
node,
|
|
162
|
-
messageId: "preferTopLevelStringFormat",
|
|
163
|
-
data: {
|
|
164
|
-
replacementMethod: replacementMethodName,
|
|
165
|
-
sourceMethod: sourceMethodName
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
159
|
context.report({
|
|
171
160
|
node,
|
|
172
161
|
messageId: "preferTopLevelStringFormat",
|
|
@@ -175,6 +164,7 @@ const preferTopLevelStringFormats = require_create_plugin_rule.createZodPluginRu
|
|
|
175
164
|
sourceMethod: sourceMethodName
|
|
176
165
|
},
|
|
177
166
|
fix(fixer) {
|
|
167
|
+
if (zodSchemaMeta.schemaDecl === "named") return null;
|
|
178
168
|
return (0, _eslint_zod_utils.buildZodChainReplacementFix)({
|
|
179
169
|
sourceCode,
|
|
180
170
|
fixer,
|
|
@@ -155,17 +155,6 @@ const preferTopLevelStringFormats = createZodPluginRule({
|
|
|
155
155
|
if (!formatMethod) return;
|
|
156
156
|
if (!isTopLevelStringFormatMethodName(formatMethod.name)) return;
|
|
157
157
|
const { replacementMethodName, sourceMethodName } = TOP_LEVEL_STRING_FORMATS_BY_SOURCE[formatMethod.name];
|
|
158
|
-
if (zodSchemaMeta.schemaDecl === "named") {
|
|
159
|
-
context.report({
|
|
160
|
-
node,
|
|
161
|
-
messageId: "preferTopLevelStringFormat",
|
|
162
|
-
data: {
|
|
163
|
-
replacementMethod: replacementMethodName,
|
|
164
|
-
sourceMethod: sourceMethodName
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
158
|
context.report({
|
|
170
159
|
node,
|
|
171
160
|
messageId: "preferTopLevelStringFormat",
|
|
@@ -174,6 +163,7 @@ const preferTopLevelStringFormats = createZodPluginRule({
|
|
|
174
163
|
sourceMethod: sourceMethodName
|
|
175
164
|
},
|
|
176
165
|
fix(fixer) {
|
|
166
|
+
if (zodSchemaMeta.schemaDecl === "named") return null;
|
|
177
167
|
return buildZodChainReplacementFix({
|
|
178
168
|
sourceCode,
|
|
179
169
|
fixer,
|
|
@@ -35,17 +35,11 @@ const preferTrimBeforeStringLengthChecks = require_create_plugin_rule.createZodP
|
|
|
35
35
|
const firstLengthCheckIndex = methods.findIndex((m) => LENGTH_CHECK_METHODS.includes(m.name));
|
|
36
36
|
if (firstLengthCheckIndex === -1) return;
|
|
37
37
|
if (trimIndex < firstLengthCheckIndex) return;
|
|
38
|
-
if (zodSchemaMeta.schemaDecl === "named") {
|
|
39
|
-
context.report({
|
|
40
|
-
node,
|
|
41
|
-
messageId: "trimBeforeLengthCheck"
|
|
42
|
-
});
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
38
|
context.report({
|
|
46
39
|
node,
|
|
47
40
|
messageId: "trimBeforeLengthCheck",
|
|
48
41
|
fix(fixer) {
|
|
42
|
+
if (zodSchemaMeta.schemaDecl === "named") return null;
|
|
49
43
|
const stringMethodNode = methods[0].node;
|
|
50
44
|
const trimMethodNode = methods[trimIndex].node;
|
|
51
45
|
const trimCallee = trimMethodNode.callee;
|
|
@@ -34,17 +34,11 @@ const preferTrimBeforeStringLengthChecks = createZodPluginRule({
|
|
|
34
34
|
const firstLengthCheckIndex = methods.findIndex((m) => LENGTH_CHECK_METHODS.includes(m.name));
|
|
35
35
|
if (firstLengthCheckIndex === -1) return;
|
|
36
36
|
if (trimIndex < firstLengthCheckIndex) return;
|
|
37
|
-
if (zodSchemaMeta.schemaDecl === "named") {
|
|
38
|
-
context.report({
|
|
39
|
-
node,
|
|
40
|
-
messageId: "trimBeforeLengthCheck"
|
|
41
|
-
});
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
37
|
context.report({
|
|
45
38
|
node,
|
|
46
39
|
messageId: "trimBeforeLengthCheck",
|
|
47
40
|
fix(fixer) {
|
|
41
|
+
if (zodSchemaMeta.schemaDecl === "named") return null;
|
|
48
42
|
const stringMethodNode = methods[0].node;
|
|
49
43
|
const trimMethodNode = methods[trimIndex].node;
|
|
50
44
|
const trimCallee = trimMethodNode.callee;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-zod",
|
|
3
|
-
"version": "4.1
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "ESLint plugin that adds custom linting rules to enforce best practices when using Zod",
|
|
6
6
|
"engines": {
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@typescript-eslint/utils": "^8.57.0",
|
|
45
45
|
"esquery": "^1.6.0",
|
|
46
|
-
"@eslint-zod/utils": "1.0
|
|
46
|
+
"@eslint-zod/utils": "1.1.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"eslint": "^9 || ^10",
|