eslint-plugin-zod 4.5.4 → 4.7.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/README.md +2 -0
- package/dist/index.cjs +6 -0
- package/dist/index.mjs +6 -0
- package/dist/rules/no-coerce-boolean.cjs +21 -0
- package/dist/rules/no-coerce-boolean.mjs +21 -0
- package/dist/rules/no-duplicate-schema-methods.cjs +27 -0
- package/dist/rules/no-duplicate-schema-methods.mjs +27 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -41,6 +41,8 @@ Find out more about [Oxlint's `jsPLugins`](https://oxc.rs/docs/guide/usage/linte
|
|
|
41
41
|
| [consistent-schema-output-type-style](docs/rules/consistent-schema-output-type-style.md) | Enforce consistent use of z.infer or z.output for schema type inference | | 🔧 | | |
|
|
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
|
+
| [no-coerce-boolean](docs/rules/no-coerce-boolean.md) | Disallow `z.coerce.boolean()` because it treats any non-empty string as `true`. | ✅ | | 💡 | |
|
|
45
|
+
| [no-duplicate-schema-methods](docs/rules/no-duplicate-schema-methods.md) | Disallow calling the same schema method more than once in a single chain | ✅ | | | |
|
|
44
46
|
| [no-empty-custom-schema](docs/rules/no-empty-custom-schema.md) | Disallow usage of `z.custom()` without arguments | ✅ | | | |
|
|
45
47
|
| [no-native-enum](docs/rules/no-native-enum.md) | Disallow deprecated `z.nativeEnum()` in favor of `z.enum()`. | ✅ | 🔧 | | |
|
|
46
48
|
| [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. | ✅ | 🔧 | | |
|
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,8 @@ const require_consistent_object_schema_type = require("./rules/consistent-object
|
|
|
6
6
|
const require_consistent_schema_output_type_style = require("./rules/consistent-schema-output-type-style.cjs");
|
|
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
|
+
const require_no_coerce_boolean = require("./rules/no-coerce-boolean.cjs");
|
|
10
|
+
const require_no_duplicate_schema_methods = require("./rules/no-duplicate-schema-methods.cjs");
|
|
9
11
|
const require_no_empty_custom_schema = require("./rules/no-empty-custom-schema.cjs");
|
|
10
12
|
const require_no_native_enum = require("./rules/no-native-enum.cjs");
|
|
11
13
|
const require_no_number_schema_with_finite = require("./rules/no-number-schema-with-finite.cjs");
|
|
@@ -47,6 +49,8 @@ const eslintPluginZod = {
|
|
|
47
49
|
"consistent-schema-var-name": require_consistent_schema_var_name.consistentSchemaVarName,
|
|
48
50
|
"consistent-schema-output-type-style": require_consistent_schema_output_type_style.consistentSchemaOutputTypeStyle,
|
|
49
51
|
"no-any-schema": require_no_any_schema.noAnySchema,
|
|
52
|
+
"no-coerce-boolean": require_no_coerce_boolean.noCoerceBoolean,
|
|
53
|
+
"no-duplicate-schema-methods": require_no_duplicate_schema_methods.noDuplicateSchemaMethods,
|
|
50
54
|
"no-empty-custom-schema": require_no_empty_custom_schema.noEmptyCustomSchema,
|
|
51
55
|
"no-native-enum": require_no_native_enum.noNativeEnum,
|
|
52
56
|
"no-number-schema-with-finite": require_no_number_schema_with_finite.noNumberSchemaWithFinite,
|
|
@@ -85,6 +89,8 @@ const recommendedConfig = {
|
|
|
85
89
|
"zod/consistent-import": "error",
|
|
86
90
|
"zod/consistent-schema-var-name": "error",
|
|
87
91
|
"zod/no-any-schema": "error",
|
|
92
|
+
"zod/no-coerce-boolean": "error",
|
|
93
|
+
"zod/no-duplicate-schema-methods": "error",
|
|
88
94
|
"zod/no-empty-custom-schema": "error",
|
|
89
95
|
"zod/no-native-enum": "error",
|
|
90
96
|
"zod/no-number-schema-with-finite": "error",
|
package/dist/index.mjs
CHANGED
|
@@ -6,6 +6,8 @@ import { consistentObjectSchemaType } from "./rules/consistent-object-schema-typ
|
|
|
6
6
|
import { consistentSchemaOutputTypeStyle } from "./rules/consistent-schema-output-type-style.mjs";
|
|
7
7
|
import { consistentSchemaVarName } from "./rules/consistent-schema-var-name.mjs";
|
|
8
8
|
import { noAnySchema } from "./rules/no-any-schema.mjs";
|
|
9
|
+
import { noCoerceBoolean } from "./rules/no-coerce-boolean.mjs";
|
|
10
|
+
import { noDuplicateSchemaMethods } from "./rules/no-duplicate-schema-methods.mjs";
|
|
9
11
|
import { noEmptyCustomSchema } from "./rules/no-empty-custom-schema.mjs";
|
|
10
12
|
import { noNativeEnum } from "./rules/no-native-enum.mjs";
|
|
11
13
|
import { noNumberSchemaWithFinite } from "./rules/no-number-schema-with-finite.mjs";
|
|
@@ -47,6 +49,8 @@ const eslintPluginZod = {
|
|
|
47
49
|
"consistent-schema-var-name": consistentSchemaVarName,
|
|
48
50
|
"consistent-schema-output-type-style": consistentSchemaOutputTypeStyle,
|
|
49
51
|
"no-any-schema": noAnySchema,
|
|
52
|
+
"no-coerce-boolean": noCoerceBoolean,
|
|
53
|
+
"no-duplicate-schema-methods": noDuplicateSchemaMethods,
|
|
50
54
|
"no-empty-custom-schema": noEmptyCustomSchema,
|
|
51
55
|
"no-native-enum": noNativeEnum,
|
|
52
56
|
"no-number-schema-with-finite": noNumberSchemaWithFinite,
|
|
@@ -85,6 +89,8 @@ const recommendedConfig = {
|
|
|
85
89
|
"zod/consistent-import": "error",
|
|
86
90
|
"zod/consistent-schema-var-name": "error",
|
|
87
91
|
"zod/no-any-schema": "error",
|
|
92
|
+
"zod/no-coerce-boolean": "error",
|
|
93
|
+
"zod/no-duplicate-schema-methods": "error",
|
|
88
94
|
"zod/no-empty-custom-schema": "error",
|
|
89
95
|
"zod/no-native-enum": "error",
|
|
90
96
|
"zod/no-number-schema-with-finite": "error",
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
|
|
2
|
+
let _eslint_zod_utils = require("@eslint-zod/utils");
|
|
3
|
+
let _eslint_zod_utils_rule_builders_no_coerce_boolean = require("@eslint-zod/utils/rule-builders/no-coerce-boolean");
|
|
4
|
+
//#region src/rules/no-coerce-boolean.ts
|
|
5
|
+
const noCoerceBoolean = require_create_plugin_rule.createZodPluginRule({
|
|
6
|
+
name: "no-coerce-boolean",
|
|
7
|
+
meta: {
|
|
8
|
+
type: "problem",
|
|
9
|
+
hasSuggestions: true,
|
|
10
|
+
docs: { description: "Disallow `z.coerce.boolean()` because it treats any non-empty string as `true`." },
|
|
11
|
+
messages: {
|
|
12
|
+
noCoerceBoolean: "`z.coerce.boolean()` uses `Boolean()`, so any non-empty string (including `\"false\"`) becomes `true`. Use `z.stringbool()` or an explicit string transform such as `z.string().transform((v) => v === \"true\")` instead.",
|
|
13
|
+
useStringbool: "Replace `z.coerce.boolean()` with `z.stringbool()`"
|
|
14
|
+
},
|
|
15
|
+
schema: []
|
|
16
|
+
},
|
|
17
|
+
defaultOptions: [],
|
|
18
|
+
create: (0, _eslint_zod_utils_rule_builders_no_coerce_boolean.buildNoCoerceBooleanCreate)(_eslint_zod_utils.zodImportScope)
|
|
19
|
+
});
|
|
20
|
+
//#endregion
|
|
21
|
+
exports.noCoerceBoolean = noCoerceBoolean;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
|
+
import { zodImportScope } from "@eslint-zod/utils";
|
|
3
|
+
import { buildNoCoerceBooleanCreate } from "@eslint-zod/utils/rule-builders/no-coerce-boolean";
|
|
4
|
+
//#region src/rules/no-coerce-boolean.ts
|
|
5
|
+
const noCoerceBoolean = createZodPluginRule({
|
|
6
|
+
name: "no-coerce-boolean",
|
|
7
|
+
meta: {
|
|
8
|
+
type: "problem",
|
|
9
|
+
hasSuggestions: true,
|
|
10
|
+
docs: { description: "Disallow `z.coerce.boolean()` because it treats any non-empty string as `true`." },
|
|
11
|
+
messages: {
|
|
12
|
+
noCoerceBoolean: "`z.coerce.boolean()` uses `Boolean()`, so any non-empty string (including `\"false\"`) becomes `true`. Use `z.stringbool()` or an explicit string transform such as `z.string().transform((v) => v === \"true\")` instead.",
|
|
13
|
+
useStringbool: "Replace `z.coerce.boolean()` with `z.stringbool()`"
|
|
14
|
+
},
|
|
15
|
+
schema: []
|
|
16
|
+
},
|
|
17
|
+
defaultOptions: [],
|
|
18
|
+
create: buildNoCoerceBooleanCreate(zodImportScope)
|
|
19
|
+
});
|
|
20
|
+
//#endregion
|
|
21
|
+
export { noCoerceBoolean };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
|
|
2
|
+
let _eslint_zod_utils = require("@eslint-zod/utils");
|
|
3
|
+
let _eslint_zod_utils_rule_builders_no_duplicate_schema_methods = require("@eslint-zod/utils/rule-builders/no-duplicate-schema-methods");
|
|
4
|
+
const noDuplicateSchemaMethods = require_create_plugin_rule.createZodPluginRule({
|
|
5
|
+
name: "no-duplicate-schema-methods",
|
|
6
|
+
meta: {
|
|
7
|
+
hasSuggestions: false,
|
|
8
|
+
type: "problem",
|
|
9
|
+
docs: { description: "Disallow calling the same schema method more than once in a single chain" },
|
|
10
|
+
messages: { noDuplicateSchemaMethod: "Method `.{{method}}()` is called more than once in this schema chain." },
|
|
11
|
+
schema: []
|
|
12
|
+
},
|
|
13
|
+
defaultOptions: [],
|
|
14
|
+
create: (0, _eslint_zod_utils_rule_builders_no_duplicate_schema_methods.buildNoDuplicateSchemaMethodsCreate)(_eslint_zod_utils.zodImportScope, [
|
|
15
|
+
"and",
|
|
16
|
+
"array",
|
|
17
|
+
"check",
|
|
18
|
+
"or",
|
|
19
|
+
"pipe",
|
|
20
|
+
"refine",
|
|
21
|
+
"register",
|
|
22
|
+
"superRefine",
|
|
23
|
+
"transform"
|
|
24
|
+
])
|
|
25
|
+
});
|
|
26
|
+
//#endregion
|
|
27
|
+
exports.noDuplicateSchemaMethods = noDuplicateSchemaMethods;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
|
+
import { zodImportScope } from "@eslint-zod/utils";
|
|
3
|
+
import { buildNoDuplicateSchemaMethodsCreate } from "@eslint-zod/utils/rule-builders/no-duplicate-schema-methods";
|
|
4
|
+
const noDuplicateSchemaMethods = createZodPluginRule({
|
|
5
|
+
name: "no-duplicate-schema-methods",
|
|
6
|
+
meta: {
|
|
7
|
+
hasSuggestions: false,
|
|
8
|
+
type: "problem",
|
|
9
|
+
docs: { description: "Disallow calling the same schema method more than once in a single chain" },
|
|
10
|
+
messages: { noDuplicateSchemaMethod: "Method `.{{method}}()` is called more than once in this schema chain." },
|
|
11
|
+
schema: []
|
|
12
|
+
},
|
|
13
|
+
defaultOptions: [],
|
|
14
|
+
create: buildNoDuplicateSchemaMethodsCreate(zodImportScope, [
|
|
15
|
+
"and",
|
|
16
|
+
"array",
|
|
17
|
+
"check",
|
|
18
|
+
"or",
|
|
19
|
+
"pipe",
|
|
20
|
+
"refine",
|
|
21
|
+
"register",
|
|
22
|
+
"superRefine",
|
|
23
|
+
"transform"
|
|
24
|
+
])
|
|
25
|
+
});
|
|
26
|
+
//#endregion
|
|
27
|
+
export { noDuplicateSchemaMethods };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-zod",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.0",
|
|
4
4
|
"description": "ESLint plugin that adds custom linting rules to enforce best practices when using Zod",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@typescript-eslint/utils": "^8.57.0",
|
|
42
|
-
"@eslint-zod/utils": "2.
|
|
42
|
+
"@eslint-zod/utils": "2.3.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@marcalexiei/prettier-config": "2.0.0",
|