eslint-plugin-zod 4.6.0 → 4.7.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 +2 -1
- package/dist/index.cjs +3 -1
- package/dist/index.mjs +3 -1
- 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 +1 -0
- package/dist/rules/no-duplicate-schema-methods.mjs +1 -0
- package/dist/rules/prefer-top-level-string-formats.cjs +1 -0
- package/dist/rules/prefer-top-level-string-formats.mjs +1 -1
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -41,6 +41,7 @@ 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`. | ✅ | | 💡 | |
|
|
44
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 | ✅ | | | |
|
|
45
46
|
| [no-empty-custom-schema](docs/rules/no-empty-custom-schema.md) | Disallow usage of `z.custom()` without arguments | ✅ | | | |
|
|
46
47
|
| [no-native-enum](docs/rules/no-native-enum.md) | Disallow deprecated `z.nativeEnum()` in favor of `z.enum()`. | ✅ | 🔧 | | |
|
|
@@ -54,7 +55,7 @@ Find out more about [Oxlint's `jsPLugins`](https://oxc.rs/docs/guide/usage/linte
|
|
|
54
55
|
| [no-promise-schema](docs/rules/no-promise-schema.md) | Disallow deprecated `z.promise()` schemas. | ✅ | | | |
|
|
55
56
|
| [no-schema-with-is-nullable](docs/rules/no-schema-with-is-nullable.md) | Disallow deprecated `.isNullable()` on a Zod schema; use `safeParse(null).success` instead. | ✅ | | | |
|
|
56
57
|
| [no-schema-with-is-optional](docs/rules/no-schema-with-is-optional.md) | Disallow deprecated `.isOptional()` on a Zod schema; use `safeParse(undefined).success` instead. | ✅ | | | |
|
|
57
|
-
| [no-string-schema-with-uuid](docs/rules/no-string-schema-with-uuid.md) | Disallow usage of `z.string().uuid()` in favor of the dedicated `z.uuid()` schema |
|
|
58
|
+
| [no-string-schema-with-uuid](docs/rules/no-string-schema-with-uuid.md) | Disallow usage of `z.string().uuid()` in favor of the dedicated `z.uuid()` schema | | 🔧 | | ❌ |
|
|
58
59
|
| [no-throw-in-refine](docs/rules/no-throw-in-refine.md) | Disallow throwing errors directly inside Zod refine callbacks | ✅ | | | |
|
|
59
60
|
| [no-transform-in-record-key](docs/rules/no-transform-in-record-key.md) | Disallow transforms in z.record() key schemas, which can cause silent key mutations and data loss through key collisions | | | | |
|
|
60
61
|
| [no-unknown-schema](docs/rules/no-unknown-schema.md) | Disallow usage of `z.unknown()` in Zod schemas | | | | |
|
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,7 @@ 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");
|
|
9
10
|
const require_no_duplicate_schema_methods = require("./rules/no-duplicate-schema-methods.cjs");
|
|
10
11
|
const require_no_empty_custom_schema = require("./rules/no-empty-custom-schema.cjs");
|
|
11
12
|
const require_no_native_enum = require("./rules/no-native-enum.cjs");
|
|
@@ -48,6 +49,7 @@ const eslintPluginZod = {
|
|
|
48
49
|
"consistent-schema-var-name": require_consistent_schema_var_name.consistentSchemaVarName,
|
|
49
50
|
"consistent-schema-output-type-style": require_consistent_schema_output_type_style.consistentSchemaOutputTypeStyle,
|
|
50
51
|
"no-any-schema": require_no_any_schema.noAnySchema,
|
|
52
|
+
"no-coerce-boolean": require_no_coerce_boolean.noCoerceBoolean,
|
|
51
53
|
"no-duplicate-schema-methods": require_no_duplicate_schema_methods.noDuplicateSchemaMethods,
|
|
52
54
|
"no-empty-custom-schema": require_no_empty_custom_schema.noEmptyCustomSchema,
|
|
53
55
|
"no-native-enum": require_no_native_enum.noNativeEnum,
|
|
@@ -87,6 +89,7 @@ const recommendedConfig = {
|
|
|
87
89
|
"zod/consistent-import": "error",
|
|
88
90
|
"zod/consistent-schema-var-name": "error",
|
|
89
91
|
"zod/no-any-schema": "error",
|
|
92
|
+
"zod/no-coerce-boolean": "error",
|
|
90
93
|
"zod/no-duplicate-schema-methods": "error",
|
|
91
94
|
"zod/no-empty-custom-schema": "error",
|
|
92
95
|
"zod/no-native-enum": "error",
|
|
@@ -96,7 +99,6 @@ const recommendedConfig = {
|
|
|
96
99
|
"zod/no-number-schema-with-is-int": "error",
|
|
97
100
|
"zod/no-number-schema-with-safe": "error",
|
|
98
101
|
"zod/no-number-schema-with-step": "error",
|
|
99
|
-
"zod/no-string-schema-with-uuid": "error",
|
|
100
102
|
"zod/no-optional-and-default-together": "error",
|
|
101
103
|
"zod/no-promise-schema": "error",
|
|
102
104
|
"zod/no-schema-with-is-nullable": "error",
|
package/dist/index.mjs
CHANGED
|
@@ -6,6 +6,7 @@ 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";
|
|
9
10
|
import { noDuplicateSchemaMethods } from "./rules/no-duplicate-schema-methods.mjs";
|
|
10
11
|
import { noEmptyCustomSchema } from "./rules/no-empty-custom-schema.mjs";
|
|
11
12
|
import { noNativeEnum } from "./rules/no-native-enum.mjs";
|
|
@@ -48,6 +49,7 @@ const eslintPluginZod = {
|
|
|
48
49
|
"consistent-schema-var-name": consistentSchemaVarName,
|
|
49
50
|
"consistent-schema-output-type-style": consistentSchemaOutputTypeStyle,
|
|
50
51
|
"no-any-schema": noAnySchema,
|
|
52
|
+
"no-coerce-boolean": noCoerceBoolean,
|
|
51
53
|
"no-duplicate-schema-methods": noDuplicateSchemaMethods,
|
|
52
54
|
"no-empty-custom-schema": noEmptyCustomSchema,
|
|
53
55
|
"no-native-enum": noNativeEnum,
|
|
@@ -87,6 +89,7 @@ const recommendedConfig = {
|
|
|
87
89
|
"zod/consistent-import": "error",
|
|
88
90
|
"zod/consistent-schema-var-name": "error",
|
|
89
91
|
"zod/no-any-schema": "error",
|
|
92
|
+
"zod/no-coerce-boolean": "error",
|
|
90
93
|
"zod/no-duplicate-schema-methods": "error",
|
|
91
94
|
"zod/no-empty-custom-schema": "error",
|
|
92
95
|
"zod/no-native-enum": "error",
|
|
@@ -96,7 +99,6 @@ const recommendedConfig = {
|
|
|
96
99
|
"zod/no-number-schema-with-is-int": "error",
|
|
97
100
|
"zod/no-number-schema-with-safe": "error",
|
|
98
101
|
"zod/no-number-schema-with-step": "error",
|
|
99
|
-
"zod/no-string-schema-with-uuid": "error",
|
|
100
102
|
"zod/no-optional-and-default-together": "error",
|
|
101
103
|
"zod/no-promise-schema": "error",
|
|
102
104
|
"zod/no-schema-with-is-nullable": "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 };
|
|
@@ -13,6 +13,7 @@ const noDuplicateSchemaMethods = require_create_plugin_rule.createZodPluginRule(
|
|
|
13
13
|
defaultOptions: [],
|
|
14
14
|
create: (0, _eslint_zod_utils_rule_builders_no_duplicate_schema_methods.buildNoDuplicateSchemaMethodsCreate)(_eslint_zod_utils.zodImportScope, [
|
|
15
15
|
"and",
|
|
16
|
+
"array",
|
|
16
17
|
"check",
|
|
17
18
|
"or",
|
|
18
19
|
"pipe",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-zod",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.1",
|
|
4
4
|
"description": "ESLint plugin that adds custom linting rules to enforce best practices when using Zod",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -38,17 +38,18 @@
|
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@typescript-eslint/utils": "^8.
|
|
42
|
-
"@eslint-zod/utils": "2.
|
|
41
|
+
"@typescript-eslint/utils": "^8.62.0",
|
|
42
|
+
"@eslint-zod/utils": "2.3.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@marcalexiei/prettier-config": "2.0.0",
|
|
46
|
-
"@typescript-eslint/rule-tester": "8.
|
|
46
|
+
"@typescript-eslint/rule-tester": "8.62.1",
|
|
47
47
|
"dedent": "1.7.2",
|
|
48
48
|
"eslint-doc-generator": "3.6.0",
|
|
49
|
-
"prettier": "3.
|
|
50
|
-
"tsdown": "0.22.
|
|
51
|
-
"vitest": "4.1.
|
|
49
|
+
"prettier": "3.9.4",
|
|
50
|
+
"tsdown": "0.22.3",
|
|
51
|
+
"vitest": "4.1.9",
|
|
52
|
+
"@eslint-zod/test-utils": "0.0.0"
|
|
52
53
|
},
|
|
53
54
|
"peerDependencies": {
|
|
54
55
|
"eslint": "^9 || ^10",
|