eslint-plugin-zod 4.9.1 → 4.10.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 +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.mjs +2 -0
- package/dist/rules/no-native-enum.cjs +2 -18
- package/dist/rules/no-native-enum.mjs +2 -18
- package/dist/rules/no-promise-schema.cjs +2 -12
- package/dist/rules/no-promise-schema.mjs +2 -12
- package/dist/rules/prefer-string-length-over-min-max.cjs +23 -0
- package/dist/rules/prefer-string-length-over-min-max.mjs +23 -0
- package/package.json +6 -8
package/README.md
CHANGED
|
@@ -67,6 +67,7 @@ Find out more about [Oxlint's `jsPLugins`](https://oxc.rs/docs/guide/usage/linte
|
|
|
67
67
|
| [prefer-meta-last](docs/rules/prefer-meta-last.md) | Enforce `.meta()` as last method | ✅ | 🔧 | | |
|
|
68
68
|
| [prefer-nullish](docs/rules/prefer-nullish.md) | Enforce `.nullish()` instead of combining `.optional()` and `.nullable()` | ✅ | 🔧 | | |
|
|
69
69
|
| [prefer-strict-object](docs/rules/prefer-strict-object.md) | Prefer `z.strictObject()` over `z.object().strict()` | ✅ | 🔧 | | |
|
|
70
|
+
| [prefer-string-length-over-min-max](docs/rules/prefer-string-length-over-min-max.md) | Prefer `.length(n)` over `.min(n).max(n)` with the same value on a string schema | | 🔧 | | |
|
|
70
71
|
| [prefer-string-schema-with-trim](docs/rules/prefer-string-schema-with-trim.md) | Enforce `z.string().trim()` to prevent accidental leading/trailing whitespace | ✅ | 🔧 | | |
|
|
71
72
|
| [prefer-top-level-string-formats](docs/rules/prefer-top-level-string-formats.md) | Prefer top-level string format schemas over deprecated `z.string().<format>()` methods | ✅ | 🔧 | | |
|
|
72
73
|
| [prefer-trim-before-string-length-checks](docs/rules/prefer-trim-before-string-length-checks.md) | Enforce `.trim()` is called before string length checks to ensure accurate validation | ✅ | 🔧 | | |
|
package/dist/index.cjs
CHANGED
|
@@ -32,6 +32,7 @@ const require_prefer_meta_last = require("./rules/prefer-meta-last.cjs");
|
|
|
32
32
|
const require_prefer_meta = require("./rules/prefer-meta.cjs");
|
|
33
33
|
const require_prefer_nullish = require("./rules/prefer-nullish.cjs");
|
|
34
34
|
const require_prefer_strict_object = require("./rules/prefer-strict-object.cjs");
|
|
35
|
+
const require_prefer_string_length_over_min_max = require("./rules/prefer-string-length-over-min-max.cjs");
|
|
35
36
|
const require_prefer_string_schema_with_trim = require("./rules/prefer-string-schema-with-trim.cjs");
|
|
36
37
|
const require_prefer_top_level_string_formats = require("./rules/prefer-top-level-string-formats.cjs");
|
|
37
38
|
const require_prefer_trim_before_string_length_checks = require("./rules/prefer-trim-before-string-length-checks.cjs");
|
|
@@ -79,6 +80,7 @@ const eslintPluginZod = {
|
|
|
79
80
|
"prefer-meta-last": require_prefer_meta_last.preferMetaLast,
|
|
80
81
|
"prefer-nullish": require_prefer_nullish.preferNullish,
|
|
81
82
|
"prefer-strict-object": require_prefer_strict_object.preferStrictObject,
|
|
83
|
+
"prefer-string-length-over-min-max": require_prefer_string_length_over_min_max.preferStringLengthOverMinMax,
|
|
82
84
|
"prefer-top-level-string-formats": require_prefer_top_level_string_formats.preferTopLevelStringFormats,
|
|
83
85
|
"prefer-string-schema-with-trim": require_prefer_string_schema_with_trim.preferStringSchemaWithTrim,
|
|
84
86
|
"prefer-trim-before-string-length-checks": require_prefer_trim_before_string_length_checks.preferTrimBeforeStringLengthChecks,
|
package/dist/index.mjs
CHANGED
|
@@ -32,6 +32,7 @@ import { preferMetaLast } from "./rules/prefer-meta-last.mjs";
|
|
|
32
32
|
import { preferMeta } from "./rules/prefer-meta.mjs";
|
|
33
33
|
import { preferNullish } from "./rules/prefer-nullish.mjs";
|
|
34
34
|
import { preferStrictObject } from "./rules/prefer-strict-object.mjs";
|
|
35
|
+
import { preferStringLengthOverMinMax } from "./rules/prefer-string-length-over-min-max.mjs";
|
|
35
36
|
import { preferStringSchemaWithTrim } from "./rules/prefer-string-schema-with-trim.mjs";
|
|
36
37
|
import { preferTopLevelStringFormats } from "./rules/prefer-top-level-string-formats.mjs";
|
|
37
38
|
import { preferTrimBeforeStringLengthChecks } from "./rules/prefer-trim-before-string-length-checks.mjs";
|
|
@@ -79,6 +80,7 @@ const eslintPluginZod = {
|
|
|
79
80
|
"prefer-meta-last": preferMetaLast,
|
|
80
81
|
"prefer-nullish": preferNullish,
|
|
81
82
|
"prefer-strict-object": preferStrictObject,
|
|
83
|
+
"prefer-string-length-over-min-max": preferStringLengthOverMinMax,
|
|
82
84
|
"prefer-top-level-string-formats": preferTopLevelStringFormats,
|
|
83
85
|
"prefer-string-schema-with-trim": preferStringSchemaWithTrim,
|
|
84
86
|
"prefer-trim-before-string-length-checks": preferTrimBeforeStringLengthChecks,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
|
|
2
2
|
let _eslint_zod_utils = require("@eslint-zod/utils");
|
|
3
|
-
let
|
|
3
|
+
let _eslint_zod_utils_rule_builders_no_native_enum = require("@eslint-zod/utils/rule-builders/no-native-enum");
|
|
4
4
|
//#region src/rules/no-native-enum.ts
|
|
5
5
|
const noNativeEnum = require_create_plugin_rule.createZodPluginRule({
|
|
6
6
|
name: "no-native-enum",
|
|
@@ -12,23 +12,7 @@ const noNativeEnum = require_create_plugin_rule.createZodPluginRule({
|
|
|
12
12
|
schema: []
|
|
13
13
|
},
|
|
14
14
|
defaultOptions: [],
|
|
15
|
-
create(
|
|
16
|
-
const { createSchemaVisitor, collectZodChainMethods } = _eslint_zod_utils.zodImportScope.createTracker();
|
|
17
|
-
return createSchemaVisitor({
|
|
18
|
-
schemaType: "nativeEnum",
|
|
19
|
-
onSchema(node) {
|
|
20
|
-
const rootMethodNode = collectZodChainMethods(node).at(0)?.node;
|
|
21
|
-
context.report({
|
|
22
|
-
node,
|
|
23
|
-
messageId: "useEnum",
|
|
24
|
-
fix(fixer) {
|
|
25
|
-
if (rootMethodNode?.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return null;
|
|
26
|
-
return fixer.replaceText(rootMethodNode.callee.property, "enum");
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
15
|
+
create: (0, _eslint_zod_utils_rule_builders_no_native_enum.buildNoNativeEnumCreate)(_eslint_zod_utils.zodImportScope)
|
|
32
16
|
});
|
|
33
17
|
//#endregion
|
|
34
18
|
exports.noNativeEnum = noNativeEnum;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
2
|
import { zodImportScope } from "@eslint-zod/utils";
|
|
3
|
-
import {
|
|
3
|
+
import { buildNoNativeEnumCreate } from "@eslint-zod/utils/rule-builders/no-native-enum";
|
|
4
4
|
//#region src/rules/no-native-enum.ts
|
|
5
5
|
const noNativeEnum = createZodPluginRule({
|
|
6
6
|
name: "no-native-enum",
|
|
@@ -12,23 +12,7 @@ const noNativeEnum = createZodPluginRule({
|
|
|
12
12
|
schema: []
|
|
13
13
|
},
|
|
14
14
|
defaultOptions: [],
|
|
15
|
-
create(
|
|
16
|
-
const { createSchemaVisitor, collectZodChainMethods } = zodImportScope.createTracker();
|
|
17
|
-
return createSchemaVisitor({
|
|
18
|
-
schemaType: "nativeEnum",
|
|
19
|
-
onSchema(node) {
|
|
20
|
-
const rootMethodNode = collectZodChainMethods(node).at(0)?.node;
|
|
21
|
-
context.report({
|
|
22
|
-
node,
|
|
23
|
-
messageId: "useEnum",
|
|
24
|
-
fix(fixer) {
|
|
25
|
-
if (rootMethodNode?.callee.type !== AST_NODE_TYPES.MemberExpression) return null;
|
|
26
|
-
return fixer.replaceText(rootMethodNode.callee.property, "enum");
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
15
|
+
create: buildNoNativeEnumCreate(zodImportScope)
|
|
32
16
|
});
|
|
33
17
|
//#endregion
|
|
34
18
|
export { noNativeEnum };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
|
|
2
2
|
let _eslint_zod_utils = require("@eslint-zod/utils");
|
|
3
|
+
let _eslint_zod_utils_rule_builders_no_promise_schema = require("@eslint-zod/utils/rule-builders/no-promise-schema");
|
|
3
4
|
//#region src/rules/no-promise-schema.ts
|
|
4
5
|
const noPromiseSchema = require_create_plugin_rule.createZodPluginRule({
|
|
5
6
|
name: "no-promise-schema",
|
|
@@ -10,18 +11,7 @@ const noPromiseSchema = require_create_plugin_rule.createZodPluginRule({
|
|
|
10
11
|
schema: []
|
|
11
12
|
},
|
|
12
13
|
defaultOptions: [],
|
|
13
|
-
create(
|
|
14
|
-
const { createSchemaVisitor } = _eslint_zod_utils.zodImportScope.createTracker();
|
|
15
|
-
return createSchemaVisitor({
|
|
16
|
-
schemaType: "promise",
|
|
17
|
-
onSchema(node) {
|
|
18
|
-
context.report({
|
|
19
|
-
node,
|
|
20
|
-
messageId: "noPromiseSchema"
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
14
|
+
create: (0, _eslint_zod_utils_rule_builders_no_promise_schema.buildNoPromiseSchemaCreate)(_eslint_zod_utils.zodImportScope)
|
|
25
15
|
});
|
|
26
16
|
//#endregion
|
|
27
17
|
exports.noPromiseSchema = noPromiseSchema;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
2
|
import { zodImportScope } from "@eslint-zod/utils";
|
|
3
|
+
import { buildNoPromiseSchemaCreate } from "@eslint-zod/utils/rule-builders/no-promise-schema";
|
|
3
4
|
//#region src/rules/no-promise-schema.ts
|
|
4
5
|
const noPromiseSchema = createZodPluginRule({
|
|
5
6
|
name: "no-promise-schema",
|
|
@@ -10,18 +11,7 @@ const noPromiseSchema = createZodPluginRule({
|
|
|
10
11
|
schema: []
|
|
11
12
|
},
|
|
12
13
|
defaultOptions: [],
|
|
13
|
-
create(
|
|
14
|
-
const { createSchemaVisitor } = zodImportScope.createTracker();
|
|
15
|
-
return createSchemaVisitor({
|
|
16
|
-
schemaType: "promise",
|
|
17
|
-
onSchema(node) {
|
|
18
|
-
context.report({
|
|
19
|
-
node,
|
|
20
|
-
messageId: "noPromiseSchema"
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
14
|
+
create: buildNoPromiseSchemaCreate(zodImportScope)
|
|
25
15
|
});
|
|
26
16
|
//#endregion
|
|
27
17
|
export { noPromiseSchema };
|
|
@@ -0,0 +1,23 @@
|
|
|
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_patterns_collapse_equal_bounds = require("@eslint-zod/utils/rule-patterns/collapse-equal-bounds");
|
|
4
|
+
//#region src/rules/prefer-string-length-over-min-max.ts
|
|
5
|
+
const preferStringLengthOverMinMax = require_create_plugin_rule.createZodPluginRule({
|
|
6
|
+
name: "prefer-string-length-over-min-max",
|
|
7
|
+
meta: {
|
|
8
|
+
type: "suggestion",
|
|
9
|
+
fixable: "code",
|
|
10
|
+
docs: { description: "Prefer `.length(n)` over `.min(n).max(n)` with the same value on a string schema" },
|
|
11
|
+
messages: { preferStringLength: "Use `.length(n)` instead of `.min(n)` and `.max(n)` with the same value." },
|
|
12
|
+
schema: []
|
|
13
|
+
},
|
|
14
|
+
defaultOptions: [],
|
|
15
|
+
create: (0, _eslint_zod_utils_rule_patterns_collapse_equal_bounds.buildCollapseEqualBoundsCreate)({
|
|
16
|
+
scope: _eslint_zod_utils.zodImportScope,
|
|
17
|
+
baseTypes: ["string"],
|
|
18
|
+
domain: "length",
|
|
19
|
+
messageId: "preferStringLength"
|
|
20
|
+
})
|
|
21
|
+
});
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.preferStringLengthOverMinMax = preferStringLengthOverMinMax;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
|
+
import { zodImportScope } from "@eslint-zod/utils";
|
|
3
|
+
import { buildCollapseEqualBoundsCreate } from "@eslint-zod/utils/rule-patterns/collapse-equal-bounds";
|
|
4
|
+
//#region src/rules/prefer-string-length-over-min-max.ts
|
|
5
|
+
const preferStringLengthOverMinMax = createZodPluginRule({
|
|
6
|
+
name: "prefer-string-length-over-min-max",
|
|
7
|
+
meta: {
|
|
8
|
+
type: "suggestion",
|
|
9
|
+
fixable: "code",
|
|
10
|
+
docs: { description: "Prefer `.length(n)` over `.min(n).max(n)` with the same value on a string schema" },
|
|
11
|
+
messages: { preferStringLength: "Use `.length(n)` instead of `.min(n)` and `.max(n)` with the same value." },
|
|
12
|
+
schema: []
|
|
13
|
+
},
|
|
14
|
+
defaultOptions: [],
|
|
15
|
+
create: buildCollapseEqualBoundsCreate({
|
|
16
|
+
scope: zodImportScope,
|
|
17
|
+
baseTypes: ["string"],
|
|
18
|
+
domain: "length",
|
|
19
|
+
messageId: "preferStringLength"
|
|
20
|
+
})
|
|
21
|
+
});
|
|
22
|
+
//#endregion
|
|
23
|
+
export { preferStringLengthOverMinMax };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-zod",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.10.0",
|
|
4
4
|
"description": "ESLint plugin that adds custom linting rules to enforce best practices when using Zod",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -38,18 +38,16 @@
|
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@typescript-eslint/utils": "^8.
|
|
42
|
-
"@eslint-zod/utils": "3.
|
|
41
|
+
"@typescript-eslint/utils": "^8.67.0",
|
|
42
|
+
"@eslint-zod/utils": "3.1.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@
|
|
46
|
-
"@typescript-eslint/rule-tester": "8.65.0",
|
|
45
|
+
"@typescript-eslint/rule-tester": "8.67.0",
|
|
47
46
|
"dedent": "1.7.2",
|
|
48
47
|
"eslint-doc-generator": "3.7.0",
|
|
49
|
-
"prettier": "3.9.6",
|
|
50
48
|
"tsdown": "0.22.14",
|
|
51
|
-
"vitest": "4.1.
|
|
52
|
-
"@eslint-zod/
|
|
49
|
+
"vitest": "4.1.11",
|
|
50
|
+
"@eslint-zod/tooling": "0.0.0"
|
|
53
51
|
},
|
|
54
52
|
"peerDependencies": {
|
|
55
53
|
"eslint": "^9 || ^10",
|