eslint-plugin-zod 4.3.0 → 4.4.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 CHANGED
@@ -50,6 +50,7 @@ Find out more about [Oxlint's `jsPLugins`](https://oxc.rs/docs/guide/usage/linte
50
50
  | [no-number-schema-with-safe](docs/rules/no-number-schema-with-safe.md) | Disallow deprecated `z.number().safe()`. Use `z.int()`; `.safe()` is now identical to `.int()`. | ✅ | 🔧 | | |
51
51
  | [no-number-schema-with-step](docs/rules/no-number-schema-with-step.md) | Disallow deprecated `z.number().step()`. Use `.multipleOf()` instead. | ✅ | 🔧 | | |
52
52
  | [no-optional-and-default-together](docs/rules/no-optional-and-default-together.md) | Disallow using both `.optional()` and `.default()` on the same Zod schema | ✅ | 🔧 | | |
53
+ | [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. | ✅ | | | |
53
54
  | [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. | ✅ | | | |
54
55
  | [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 | ✅ | 🔧 | | ❌ |
55
56
  | [no-throw-in-refine](docs/rules/no-throw-in-refine.md) | Disallow throwing errors directly inside Zod refine callbacks | ✅ | | | |
package/dist/index.cjs CHANGED
@@ -15,6 +15,7 @@ const require_no_number_schema_with_is_int = require("./rules/no-number-schema-w
15
15
  const require_no_number_schema_with_safe = require("./rules/no-number-schema-with-safe.cjs");
16
16
  const require_no_number_schema_with_step = require("./rules/no-number-schema-with-step.cjs");
17
17
  const require_no_optional_and_default_together = require("./rules/no-optional-and-default-together.cjs");
18
+ const require_no_schema_with_is_nullable = require("./rules/no-schema-with-is-nullable.cjs");
18
19
  const require_no_schema_with_is_optional = require("./rules/no-schema-with-is-optional.cjs");
19
20
  const require_no_string_schema_with_uuid = require("./rules/no-string-schema-with-uuid.cjs");
20
21
  const require_no_throw_in_refine = require("./rules/no-throw-in-refine.cjs");
@@ -55,6 +56,7 @@ const eslintPluginZod = {
55
56
  "no-number-schema-with-step": require_no_number_schema_with_step.noNumberSchemaWithStep,
56
57
  "no-string-schema-with-uuid": require_no_string_schema_with_uuid.noStringSchemaWithUuid,
57
58
  "no-optional-and-default-together": require_no_optional_and_default_together.noOptionalAndDefaultTogether,
59
+ "no-schema-with-is-nullable": require_no_schema_with_is_nullable.noSchemaWithIsNullable,
58
60
  "no-schema-with-is-optional": require_no_schema_with_is_optional.noSchemaWithIsOptional,
59
61
  "no-throw-in-refine": require_no_throw_in_refine.noThrowInRefine,
60
62
  "no-transform-in-record-key": require_no_transform_in_record_key.noTransformInRecordKey,
@@ -91,6 +93,7 @@ const recommendedConfig = {
91
93
  "zod/no-number-schema-with-step": "error",
92
94
  "zod/no-string-schema-with-uuid": "error",
93
95
  "zod/no-optional-and-default-together": "error",
96
+ "zod/no-schema-with-is-nullable": "error",
94
97
  "zod/no-schema-with-is-optional": "error",
95
98
  "zod/no-throw-in-refine": "error",
96
99
  "zod/prefer-enum-over-literal-union": "error",
package/dist/index.mjs CHANGED
@@ -15,6 +15,7 @@ import { noNumberSchemaWithIsInt } from "./rules/no-number-schema-with-is-int.mj
15
15
  import { noNumberSchemaWithSafe } from "./rules/no-number-schema-with-safe.mjs";
16
16
  import { noNumberSchemaWithStep } from "./rules/no-number-schema-with-step.mjs";
17
17
  import { noOptionalAndDefaultTogether } from "./rules/no-optional-and-default-together.mjs";
18
+ import { noSchemaWithIsNullable } from "./rules/no-schema-with-is-nullable.mjs";
18
19
  import { noSchemaWithIsOptional } from "./rules/no-schema-with-is-optional.mjs";
19
20
  import { noStringSchemaWithUuid } from "./rules/no-string-schema-with-uuid.mjs";
20
21
  import { noThrowInRefine } from "./rules/no-throw-in-refine.mjs";
@@ -55,6 +56,7 @@ const eslintPluginZod = {
55
56
  "no-number-schema-with-step": noNumberSchemaWithStep,
56
57
  "no-string-schema-with-uuid": noStringSchemaWithUuid,
57
58
  "no-optional-and-default-together": noOptionalAndDefaultTogether,
59
+ "no-schema-with-is-nullable": noSchemaWithIsNullable,
58
60
  "no-schema-with-is-optional": noSchemaWithIsOptional,
59
61
  "no-throw-in-refine": noThrowInRefine,
60
62
  "no-transform-in-record-key": noTransformInRecordKey,
@@ -91,6 +93,7 @@ const recommendedConfig = {
91
93
  "zod/no-number-schema-with-step": "error",
92
94
  "zod/no-string-schema-with-uuid": "error",
93
95
  "zod/no-optional-and-default-together": "error",
96
+ "zod/no-schema-with-is-nullable": "error",
94
97
  "zod/no-schema-with-is-optional": "error",
95
98
  "zod/no-throw-in-refine": "error",
96
99
  "zod/prefer-enum-over-literal-union": "error",
@@ -0,0 +1,35 @@
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
+ //#region src/rules/no-schema-with-is-nullable.ts
5
+ const { trackZodSchemaImports } = (0, _eslint_zod_utils.createZodSchemaImportTrack)(_eslint_zod_utils.zodImportScope);
6
+ const noSchemaWithIsNullable = require_create_plugin_rule.createZodPluginRule({
7
+ name: "no-schema-with-is-nullable",
8
+ meta: {
9
+ type: "problem",
10
+ docs: { description: "Disallow deprecated `.isNullable()` on a Zod schema; use `safeParse(null).success` instead." },
11
+ messages: { useSafeParse: "`.isNullable()` is deprecated. Try `schema.safeParse(null).success` instead." },
12
+ schema: []
13
+ },
14
+ defaultOptions: [],
15
+ create(context) {
16
+ const { importDeclarationListener, detectZodSchemaRootNode } = trackZodSchemaImports();
17
+ return {
18
+ ImportDeclaration: importDeclarationListener,
19
+ CallExpression(node) {
20
+ const zodSchemaMeta = detectZodSchemaRootNode(node);
21
+ if (!zodSchemaMeta) return;
22
+ const { methods } = zodSchemaMeta;
23
+ const isNullableIndex = methods.findIndex((it) => it === "isNullable");
24
+ if (isNullableIndex === -1) return;
25
+ if (methods.slice(0, isNullableIndex).some((method) => _eslint_zod_utils.ZOD_NON_SCHEMA_PRODUCING_METHODS.includes(method))) return;
26
+ context.report({
27
+ node,
28
+ messageId: "useSafeParse"
29
+ });
30
+ }
31
+ };
32
+ }
33
+ });
34
+ //#endregion
35
+ exports.noSchemaWithIsNullable = noSchemaWithIsNullable;
@@ -0,0 +1,34 @@
1
+ import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
2
+ import { ZOD_NON_SCHEMA_PRODUCING_METHODS, createZodSchemaImportTrack, zodImportScope } from "@eslint-zod/utils";
3
+ //#region src/rules/no-schema-with-is-nullable.ts
4
+ const { trackZodSchemaImports } = createZodSchemaImportTrack(zodImportScope);
5
+ const noSchemaWithIsNullable = createZodPluginRule({
6
+ name: "no-schema-with-is-nullable",
7
+ meta: {
8
+ type: "problem",
9
+ docs: { description: "Disallow deprecated `.isNullable()` on a Zod schema; use `safeParse(null).success` instead." },
10
+ messages: { useSafeParse: "`.isNullable()` is deprecated. Try `schema.safeParse(null).success` instead." },
11
+ schema: []
12
+ },
13
+ defaultOptions: [],
14
+ create(context) {
15
+ const { importDeclarationListener, detectZodSchemaRootNode } = trackZodSchemaImports();
16
+ return {
17
+ ImportDeclaration: importDeclarationListener,
18
+ CallExpression(node) {
19
+ const zodSchemaMeta = detectZodSchemaRootNode(node);
20
+ if (!zodSchemaMeta) return;
21
+ const { methods } = zodSchemaMeta;
22
+ const isNullableIndex = methods.findIndex((it) => it === "isNullable");
23
+ if (isNullableIndex === -1) return;
24
+ if (methods.slice(0, isNullableIndex).some((method) => ZOD_NON_SCHEMA_PRODUCING_METHODS.includes(method))) return;
25
+ context.report({
26
+ node,
27
+ messageId: "useSafeParse"
28
+ });
29
+ }
30
+ };
31
+ }
32
+ });
33
+ //#endregion
34
+ export { noSchemaWithIsNullable };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-zod",
3
- "version": "4.3.0",
3
+ "version": "4.4.0",
4
4
  "description": "ESLint plugin that adds custom linting rules to enforce best practices when using Zod",
5
5
  "keywords": [
6
6
  "eslint",