eslint-plugin-zod 4.9.1 → 4.11.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 +4 -0
- package/dist/index.mjs +4 -0
- package/dist/rules/no-native-enum.cjs +2 -18
- package/dist/rules/no-native-enum.mjs +2 -18
- package/dist/rules/no-number-schema-with-int.cjs +10 -28
- package/dist/rules/no-number-schema-with-int.mjs +11 -29
- package/dist/rules/no-number-schema-with-safe.cjs +10 -27
- package/dist/rules/no-number-schema-with-safe.mjs +11 -28
- package/dist/rules/no-promise-schema.cjs +2 -12
- package/dist/rules/no-promise-schema.mjs +2 -12
- package/dist/rules/no-string-schema-with-uuid.cjs +10 -28
- package/dist/rules/no-string-schema-with-uuid.mjs +11 -29
- package/dist/rules/prefer-map-set-size-over-min-max.cjs +23 -0
- package/dist/rules/prefer-map-set-size-over-min-max.mjs +23 -0
- 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/dist/rules/prefer-top-level-string-formats.cjs +8 -37
- package/dist/rules/prefer-top-level-string-formats.mjs +9 -38
- package/package.json +6 -8
package/README.md
CHANGED
|
@@ -63,10 +63,12 @@ Find out more about [Oxlint's `jsPLugins`](https://oxc.rs/docs/guide/usage/linte
|
|
|
63
63
|
| [no-unnecessary-readonly](docs/rules/no-unnecessary-readonly.md) | Disallow `.readonly()` on schemas whose output is already immutable | | 🔧 | | |
|
|
64
64
|
| [prefer-enum-over-literal-union](docs/rules/prefer-enum-over-literal-union.md) | Prefer `z.enum()` over `z.union()` when all members are string literals. | ✅ | 🔧 | | |
|
|
65
65
|
| [prefer-loose-object](docs/rules/prefer-loose-object.md) | Prefer `z.looseObject()` over `z.object().passthrough()` and `z.object().loose()` | ✅ | 🔧 | | |
|
|
66
|
+
| [prefer-map-set-size-over-min-max](docs/rules/prefer-map-set-size-over-min-max.md) | Prefer `.size(n)` over `.min(n).max(n)` with the same value on a set or map schema | | 🔧 | | |
|
|
66
67
|
| [prefer-meta](docs/rules/prefer-meta.md) | Enforce usage of `.meta()` over `.describe()` | ✅ | 🔧 | | |
|
|
67
68
|
| [prefer-meta-last](docs/rules/prefer-meta-last.md) | Enforce `.meta()` as last method | ✅ | 🔧 | | |
|
|
68
69
|
| [prefer-nullish](docs/rules/prefer-nullish.md) | Enforce `.nullish()` instead of combining `.optional()` and `.nullable()` | ✅ | 🔧 | | |
|
|
69
70
|
| [prefer-strict-object](docs/rules/prefer-strict-object.md) | Prefer `z.strictObject()` over `z.object().strict()` | ✅ | 🔧 | | |
|
|
71
|
+
| [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
72
|
| [prefer-string-schema-with-trim](docs/rules/prefer-string-schema-with-trim.md) | Enforce `z.string().trim()` to prevent accidental leading/trailing whitespace | ✅ | 🔧 | | |
|
|
71
73
|
| [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
74
|
| [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
|
@@ -28,10 +28,12 @@ const require_no_unknown_schema = require("./rules/no-unknown-schema.cjs");
|
|
|
28
28
|
const require_no_unnecessary_readonly = require("./rules/no-unnecessary-readonly.cjs");
|
|
29
29
|
const require_prefer_enum_over_literal_union = require("./rules/prefer-enum-over-literal-union.cjs");
|
|
30
30
|
const require_prefer_loose_object = require("./rules/prefer-loose-object.cjs");
|
|
31
|
+
const require_prefer_map_set_size_over_min_max = require("./rules/prefer-map-set-size-over-min-max.cjs");
|
|
31
32
|
const require_prefer_meta_last = require("./rules/prefer-meta-last.cjs");
|
|
32
33
|
const require_prefer_meta = require("./rules/prefer-meta.cjs");
|
|
33
34
|
const require_prefer_nullish = require("./rules/prefer-nullish.cjs");
|
|
34
35
|
const require_prefer_strict_object = require("./rules/prefer-strict-object.cjs");
|
|
36
|
+
const require_prefer_string_length_over_min_max = require("./rules/prefer-string-length-over-min-max.cjs");
|
|
35
37
|
const require_prefer_string_schema_with_trim = require("./rules/prefer-string-schema-with-trim.cjs");
|
|
36
38
|
const require_prefer_top_level_string_formats = require("./rules/prefer-top-level-string-formats.cjs");
|
|
37
39
|
const require_prefer_trim_before_string_length_checks = require("./rules/prefer-trim-before-string-length-checks.cjs");
|
|
@@ -75,10 +77,12 @@ const eslintPluginZod = {
|
|
|
75
77
|
"no-unnecessary-readonly": require_no_unnecessary_readonly.noUnnecessaryReadonly,
|
|
76
78
|
"prefer-enum-over-literal-union": require_prefer_enum_over_literal_union.preferEnumOverLiteralUnion,
|
|
77
79
|
"prefer-loose-object": require_prefer_loose_object.preferLooseObject,
|
|
80
|
+
"prefer-map-set-size-over-min-max": require_prefer_map_set_size_over_min_max.preferMapSetSizeOverMinMax,
|
|
78
81
|
"prefer-meta": require_prefer_meta.preferMeta,
|
|
79
82
|
"prefer-meta-last": require_prefer_meta_last.preferMetaLast,
|
|
80
83
|
"prefer-nullish": require_prefer_nullish.preferNullish,
|
|
81
84
|
"prefer-strict-object": require_prefer_strict_object.preferStrictObject,
|
|
85
|
+
"prefer-string-length-over-min-max": require_prefer_string_length_over_min_max.preferStringLengthOverMinMax,
|
|
82
86
|
"prefer-top-level-string-formats": require_prefer_top_level_string_formats.preferTopLevelStringFormats,
|
|
83
87
|
"prefer-string-schema-with-trim": require_prefer_string_schema_with_trim.preferStringSchemaWithTrim,
|
|
84
88
|
"prefer-trim-before-string-length-checks": require_prefer_trim_before_string_length_checks.preferTrimBeforeStringLengthChecks,
|
package/dist/index.mjs
CHANGED
|
@@ -28,10 +28,12 @@ import { noUnknownSchema } from "./rules/no-unknown-schema.mjs";
|
|
|
28
28
|
import { noUnnecessaryReadonly } from "./rules/no-unnecessary-readonly.mjs";
|
|
29
29
|
import { preferEnumOverLiteralUnion } from "./rules/prefer-enum-over-literal-union.mjs";
|
|
30
30
|
import { preferLooseObject } from "./rules/prefer-loose-object.mjs";
|
|
31
|
+
import { preferMapSetSizeOverMinMax } from "./rules/prefer-map-set-size-over-min-max.mjs";
|
|
31
32
|
import { preferMetaLast } from "./rules/prefer-meta-last.mjs";
|
|
32
33
|
import { preferMeta } from "./rules/prefer-meta.mjs";
|
|
33
34
|
import { preferNullish } from "./rules/prefer-nullish.mjs";
|
|
34
35
|
import { preferStrictObject } from "./rules/prefer-strict-object.mjs";
|
|
36
|
+
import { preferStringLengthOverMinMax } from "./rules/prefer-string-length-over-min-max.mjs";
|
|
35
37
|
import { preferStringSchemaWithTrim } from "./rules/prefer-string-schema-with-trim.mjs";
|
|
36
38
|
import { preferTopLevelStringFormats } from "./rules/prefer-top-level-string-formats.mjs";
|
|
37
39
|
import { preferTrimBeforeStringLengthChecks } from "./rules/prefer-trim-before-string-length-checks.mjs";
|
|
@@ -75,10 +77,12 @@ const eslintPluginZod = {
|
|
|
75
77
|
"no-unnecessary-readonly": noUnnecessaryReadonly,
|
|
76
78
|
"prefer-enum-over-literal-union": preferEnumOverLiteralUnion,
|
|
77
79
|
"prefer-loose-object": preferLooseObject,
|
|
80
|
+
"prefer-map-set-size-over-min-max": preferMapSetSizeOverMinMax,
|
|
78
81
|
"prefer-meta": preferMeta,
|
|
79
82
|
"prefer-meta-last": preferMetaLast,
|
|
80
83
|
"prefer-nullish": preferNullish,
|
|
81
84
|
"prefer-strict-object": preferStrictObject,
|
|
85
|
+
"prefer-string-length-over-min-max": preferStringLengthOverMinMax,
|
|
82
86
|
"prefer-top-level-string-formats": preferTopLevelStringFormats,
|
|
83
87
|
"prefer-string-schema-with-trim": preferStringSchemaWithTrim,
|
|
84
88
|
"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_patterns_prefer_top_level_factory = require("@eslint-zod/utils/rule-patterns/prefer-top-level-factory");
|
|
3
4
|
//#region src/rules/no-number-schema-with-int.ts
|
|
4
5
|
const noNumberSchemaWithInt = require_create_plugin_rule.createZodPluginRule({
|
|
5
6
|
name: "no-number-schema-with-int",
|
|
@@ -11,34 +12,15 @@ const noNumberSchemaWithInt = require_create_plugin_rule.createZodPluginRule({
|
|
|
11
12
|
schema: []
|
|
12
13
|
},
|
|
13
14
|
defaultOptions: [],
|
|
14
|
-
create(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const numberIndex = methods.findIndex((m) => m.name === "number");
|
|
24
|
-
context.report({
|
|
25
|
-
node,
|
|
26
|
-
messageId: "removeNumber",
|
|
27
|
-
fix(fixer) {
|
|
28
|
-
if (zodSchemaMeta.schemaDecl === "named") return null;
|
|
29
|
-
return (0, _eslint_zod_utils.buildZodChainReplacementFix)({
|
|
30
|
-
sourceCode,
|
|
31
|
-
fixer,
|
|
32
|
-
methods,
|
|
33
|
-
fromIndex: numberIndex,
|
|
34
|
-
toIndex: intIndex,
|
|
35
|
-
toMethodName: "int"
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
15
|
+
create: (0, _eslint_zod_utils_rule_patterns_prefer_top_level_factory.buildPreferTopLevelFactoryCreate)({
|
|
16
|
+
scope: _eslint_zod_utils.zodImportScope,
|
|
17
|
+
factoryName: "number",
|
|
18
|
+
replacements: [{
|
|
19
|
+
sourceMethodName: "int",
|
|
20
|
+
replacementMethodName: "int"
|
|
21
|
+
}],
|
|
22
|
+
messageId: "removeNumber"
|
|
23
|
+
})
|
|
42
24
|
});
|
|
43
25
|
//#endregion
|
|
44
26
|
exports.noNumberSchemaWithInt = noNumberSchemaWithInt;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { zodImportScope } from "@eslint-zod/utils";
|
|
3
|
+
import { buildPreferTopLevelFactoryCreate } from "@eslint-zod/utils/rule-patterns/prefer-top-level-factory";
|
|
3
4
|
//#region src/rules/no-number-schema-with-int.ts
|
|
4
5
|
const noNumberSchemaWithInt = createZodPluginRule({
|
|
5
6
|
name: "no-number-schema-with-int",
|
|
@@ -11,34 +12,15 @@ const noNumberSchemaWithInt = createZodPluginRule({
|
|
|
11
12
|
schema: []
|
|
12
13
|
},
|
|
13
14
|
defaultOptions: [],
|
|
14
|
-
create(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const numberIndex = methods.findIndex((m) => m.name === "number");
|
|
24
|
-
context.report({
|
|
25
|
-
node,
|
|
26
|
-
messageId: "removeNumber",
|
|
27
|
-
fix(fixer) {
|
|
28
|
-
if (zodSchemaMeta.schemaDecl === "named") return null;
|
|
29
|
-
return buildZodChainReplacementFix({
|
|
30
|
-
sourceCode,
|
|
31
|
-
fixer,
|
|
32
|
-
methods,
|
|
33
|
-
fromIndex: numberIndex,
|
|
34
|
-
toIndex: intIndex,
|
|
35
|
-
toMethodName: "int"
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
15
|
+
create: buildPreferTopLevelFactoryCreate({
|
|
16
|
+
scope: zodImportScope,
|
|
17
|
+
factoryName: "number",
|
|
18
|
+
replacements: [{
|
|
19
|
+
sourceMethodName: "int",
|
|
20
|
+
replacementMethodName: "int"
|
|
21
|
+
}],
|
|
22
|
+
messageId: "removeNumber"
|
|
23
|
+
})
|
|
42
24
|
});
|
|
43
25
|
//#endregion
|
|
44
26
|
export { noNumberSchemaWithInt };
|
|
@@ -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_patterns_prefer_top_level_factory = require("@eslint-zod/utils/rule-patterns/prefer-top-level-factory");
|
|
3
4
|
//#region src/rules/no-number-schema-with-safe.ts
|
|
4
5
|
const noNumberSchemaWithSafe = require_create_plugin_rule.createZodPluginRule({
|
|
5
6
|
name: "no-number-schema-with-safe",
|
|
@@ -11,33 +12,15 @@ const noNumberSchemaWithSafe = require_create_plugin_rule.createZodPluginRule({
|
|
|
11
12
|
schema: []
|
|
12
13
|
},
|
|
13
14
|
defaultOptions: [],
|
|
14
|
-
create(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
context.report({
|
|
24
|
-
node,
|
|
25
|
-
messageId: "useInt",
|
|
26
|
-
fix(fixer) {
|
|
27
|
-
if (zodSchemaMeta.schemaDecl === "named" || safeIndex === -1) return null;
|
|
28
|
-
return (0, _eslint_zod_utils.buildZodChainReplacementFix)({
|
|
29
|
-
sourceCode,
|
|
30
|
-
fixer,
|
|
31
|
-
methods,
|
|
32
|
-
fromIndex: 0,
|
|
33
|
-
toIndex: safeIndex,
|
|
34
|
-
toMethodName: "int"
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
15
|
+
create: (0, _eslint_zod_utils_rule_patterns_prefer_top_level_factory.buildPreferTopLevelFactoryCreate)({
|
|
16
|
+
scope: _eslint_zod_utils.zodImportScope,
|
|
17
|
+
factoryName: "number",
|
|
18
|
+
replacements: [{
|
|
19
|
+
sourceMethodName: "safe",
|
|
20
|
+
replacementMethodName: "int"
|
|
21
|
+
}],
|
|
22
|
+
messageId: "useInt"
|
|
23
|
+
})
|
|
41
24
|
});
|
|
42
25
|
//#endregion
|
|
43
26
|
exports.noNumberSchemaWithSafe = noNumberSchemaWithSafe;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { zodImportScope } from "@eslint-zod/utils";
|
|
3
|
+
import { buildPreferTopLevelFactoryCreate } from "@eslint-zod/utils/rule-patterns/prefer-top-level-factory";
|
|
3
4
|
//#region src/rules/no-number-schema-with-safe.ts
|
|
4
5
|
const noNumberSchemaWithSafe = createZodPluginRule({
|
|
5
6
|
name: "no-number-schema-with-safe",
|
|
@@ -11,33 +12,15 @@ const noNumberSchemaWithSafe = createZodPluginRule({
|
|
|
11
12
|
schema: []
|
|
12
13
|
},
|
|
13
14
|
defaultOptions: [],
|
|
14
|
-
create(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
context.report({
|
|
24
|
-
node,
|
|
25
|
-
messageId: "useInt",
|
|
26
|
-
fix(fixer) {
|
|
27
|
-
if (zodSchemaMeta.schemaDecl === "named" || safeIndex === -1) return null;
|
|
28
|
-
return buildZodChainReplacementFix({
|
|
29
|
-
sourceCode,
|
|
30
|
-
fixer,
|
|
31
|
-
methods,
|
|
32
|
-
fromIndex: 0,
|
|
33
|
-
toIndex: safeIndex,
|
|
34
|
-
toMethodName: "int"
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
15
|
+
create: buildPreferTopLevelFactoryCreate({
|
|
16
|
+
scope: zodImportScope,
|
|
17
|
+
factoryName: "number",
|
|
18
|
+
replacements: [{
|
|
19
|
+
sourceMethodName: "safe",
|
|
20
|
+
replacementMethodName: "int"
|
|
21
|
+
}],
|
|
22
|
+
messageId: "useInt"
|
|
23
|
+
})
|
|
41
24
|
});
|
|
42
25
|
//#endregion
|
|
43
26
|
export { noNumberSchemaWithSafe };
|
|
@@ -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 };
|
|
@@ -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_patterns_prefer_top_level_factory = require("@eslint-zod/utils/rule-patterns/prefer-top-level-factory");
|
|
3
4
|
//#region src/rules/no-string-schema-with-uuid.ts
|
|
4
5
|
const noStringSchemaWithUuid = require_create_plugin_rule.createZodPluginRule({
|
|
5
6
|
name: "no-string-schema-with-uuid",
|
|
@@ -15,34 +16,15 @@ const noStringSchemaWithUuid = require_create_plugin_rule.createZodPluginRule({
|
|
|
15
16
|
schema: []
|
|
16
17
|
},
|
|
17
18
|
defaultOptions: [],
|
|
18
|
-
create(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const stringIndex = methods.findIndex((m) => m.name === "string");
|
|
28
|
-
context.report({
|
|
29
|
-
node,
|
|
30
|
-
messageId: "useUuid",
|
|
31
|
-
fix(fixer) {
|
|
32
|
-
if (zodSchemaMeta.schemaDecl === "named") return null;
|
|
33
|
-
return (0, _eslint_zod_utils.buildZodChainReplacementFix)({
|
|
34
|
-
sourceCode,
|
|
35
|
-
fixer,
|
|
36
|
-
methods,
|
|
37
|
-
fromIndex: stringIndex,
|
|
38
|
-
toIndex: uuidIndex,
|
|
39
|
-
toMethodName: "uuid"
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
19
|
+
create: (0, _eslint_zod_utils_rule_patterns_prefer_top_level_factory.buildPreferTopLevelFactoryCreate)({
|
|
20
|
+
scope: _eslint_zod_utils.zodImportScope,
|
|
21
|
+
factoryName: "string",
|
|
22
|
+
replacements: [{
|
|
23
|
+
sourceMethodName: "uuid",
|
|
24
|
+
replacementMethodName: "uuid"
|
|
25
|
+
}],
|
|
26
|
+
messageId: "useUuid"
|
|
27
|
+
})
|
|
46
28
|
});
|
|
47
29
|
//#endregion
|
|
48
30
|
exports.noStringSchemaWithUuid = noStringSchemaWithUuid;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { zodImportScope } from "@eslint-zod/utils";
|
|
3
|
+
import { buildPreferTopLevelFactoryCreate } from "@eslint-zod/utils/rule-patterns/prefer-top-level-factory";
|
|
3
4
|
//#region src/rules/no-string-schema-with-uuid.ts
|
|
4
5
|
const noStringSchemaWithUuid = createZodPluginRule({
|
|
5
6
|
name: "no-string-schema-with-uuid",
|
|
@@ -15,34 +16,15 @@ const noStringSchemaWithUuid = createZodPluginRule({
|
|
|
15
16
|
schema: []
|
|
16
17
|
},
|
|
17
18
|
defaultOptions: [],
|
|
18
|
-
create(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const stringIndex = methods.findIndex((m) => m.name === "string");
|
|
28
|
-
context.report({
|
|
29
|
-
node,
|
|
30
|
-
messageId: "useUuid",
|
|
31
|
-
fix(fixer) {
|
|
32
|
-
if (zodSchemaMeta.schemaDecl === "named") return null;
|
|
33
|
-
return buildZodChainReplacementFix({
|
|
34
|
-
sourceCode,
|
|
35
|
-
fixer,
|
|
36
|
-
methods,
|
|
37
|
-
fromIndex: stringIndex,
|
|
38
|
-
toIndex: uuidIndex,
|
|
39
|
-
toMethodName: "uuid"
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
19
|
+
create: buildPreferTopLevelFactoryCreate({
|
|
20
|
+
scope: zodImportScope,
|
|
21
|
+
factoryName: "string",
|
|
22
|
+
replacements: [{
|
|
23
|
+
sourceMethodName: "uuid",
|
|
24
|
+
replacementMethodName: "uuid"
|
|
25
|
+
}],
|
|
26
|
+
messageId: "useUuid"
|
|
27
|
+
})
|
|
46
28
|
});
|
|
47
29
|
//#endregion
|
|
48
30
|
export { noStringSchemaWithUuid };
|
|
@@ -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-map-set-size-over-min-max.ts
|
|
5
|
+
const preferMapSetSizeOverMinMax = require_create_plugin_rule.createZodPluginRule({
|
|
6
|
+
name: "prefer-map-set-size-over-min-max",
|
|
7
|
+
meta: {
|
|
8
|
+
type: "suggestion",
|
|
9
|
+
fixable: "code",
|
|
10
|
+
docs: { description: "Prefer `.size(n)` over `.min(n).max(n)` with the same value on a set or map schema" },
|
|
11
|
+
messages: { preferMapSetSize: "Use `.size(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: ["set", "map"],
|
|
18
|
+
domain: "size",
|
|
19
|
+
messageId: "preferMapSetSize"
|
|
20
|
+
})
|
|
21
|
+
});
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.preferMapSetSizeOverMinMax = preferMapSetSizeOverMinMax;
|
|
@@ -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-map-set-size-over-min-max.ts
|
|
5
|
+
const preferMapSetSizeOverMinMax = createZodPluginRule({
|
|
6
|
+
name: "prefer-map-set-size-over-min-max",
|
|
7
|
+
meta: {
|
|
8
|
+
type: "suggestion",
|
|
9
|
+
fixable: "code",
|
|
10
|
+
docs: { description: "Prefer `.size(n)` over `.min(n).max(n)` with the same value on a set or map schema" },
|
|
11
|
+
messages: { preferMapSetSize: "Use `.size(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: ["set", "map"],
|
|
18
|
+
domain: "size",
|
|
19
|
+
messageId: "preferMapSetSize"
|
|
20
|
+
})
|
|
21
|
+
});
|
|
22
|
+
//#endregion
|
|
23
|
+
export { preferMapSetSizeOverMinMax };
|
|
@@ -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 };
|
|
@@ -1,12 +1,9 @@
|
|
|
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_patterns_prefer_top_level_factory = require("@eslint-zod/utils/rule-patterns/prefer-top-level-factory");
|
|
3
4
|
//#region src/rules/prefer-top-level-string-formats.ts
|
|
4
5
|
const TOP_LEVEL_STRING_FORMATS_URL = "https://zod.dev/v4?id=top-level-string-formats";
|
|
5
6
|
const ZOD_STRING_FORMAT_METHOD_NAMES = _eslint_zod_utils.ZOD_STRING_FORMAT_METHODS.map(({ sourceMethodName }) => sourceMethodName);
|
|
6
|
-
const ZOD_STRING_FORMAT_METHODS_BY_SOURCE = Object.fromEntries(_eslint_zod_utils.ZOD_STRING_FORMAT_METHODS.map((format) => [format.sourceMethodName, format]));
|
|
7
|
-
function isZodStringFormatMethodName(value) {
|
|
8
|
-
return ZOD_STRING_FORMAT_METHOD_NAMES.includes(value);
|
|
9
|
-
}
|
|
10
7
|
const preferTopLevelStringFormats = require_create_plugin_rule.createZodPluginRule({
|
|
11
8
|
name: "prefer-top-level-string-formats",
|
|
12
9
|
meta: {
|
|
@@ -33,39 +30,13 @@ const preferTopLevelStringFormats = require_create_plugin_rule.createZodPluginRu
|
|
|
33
30
|
},
|
|
34
31
|
defaultOptions: [{}],
|
|
35
32
|
create(context, [{ ignore = [] }]) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const stringIndex = methods.findIndex((method) => method.name === "string");
|
|
44
|
-
if (stringIndex === -1) return;
|
|
45
|
-
const formatMethod = methods.find((method, index) => index > stringIndex && isZodStringFormatMethodName(method.name) && !ignoredMethods.has(method.name));
|
|
46
|
-
if (!formatMethod) return;
|
|
47
|
-
const { replacementMethodName, sourceMethodName } = ZOD_STRING_FORMAT_METHODS_BY_SOURCE[formatMethod.name];
|
|
48
|
-
context.report({
|
|
49
|
-
node,
|
|
50
|
-
messageId: "preferTopLevelStringFormat",
|
|
51
|
-
data: {
|
|
52
|
-
replacementMethod: replacementMethodName,
|
|
53
|
-
sourceMethod: sourceMethodName
|
|
54
|
-
},
|
|
55
|
-
fix(fixer) {
|
|
56
|
-
if (zodSchemaMeta.schemaDecl === "named") return null;
|
|
57
|
-
return (0, _eslint_zod_utils.buildZodChainReplacementFix)({
|
|
58
|
-
sourceCode,
|
|
59
|
-
fixer,
|
|
60
|
-
methods,
|
|
61
|
-
fromIndex: stringIndex,
|
|
62
|
-
toIndex: methods.indexOf(formatMethod),
|
|
63
|
-
toMethodName: replacementMethodName
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
});
|
|
33
|
+
return (0, _eslint_zod_utils_rule_patterns_prefer_top_level_factory.buildPreferTopLevelFactoryCreate)({
|
|
34
|
+
scope: _eslint_zod_utils.zodImportScope,
|
|
35
|
+
factoryName: "string",
|
|
36
|
+
replacements: _eslint_zod_utils.ZOD_STRING_FORMAT_METHODS,
|
|
37
|
+
messageId: "preferTopLevelStringFormat",
|
|
38
|
+
ignore
|
|
39
|
+
})(context);
|
|
69
40
|
}
|
|
70
41
|
});
|
|
71
42
|
//#endregion
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
|
-
import { ZOD_STRING_FORMAT_METHODS,
|
|
2
|
+
import { ZOD_STRING_FORMAT_METHODS, zodImportScope } from "@eslint-zod/utils";
|
|
3
|
+
import { buildPreferTopLevelFactoryCreate } from "@eslint-zod/utils/rule-patterns/prefer-top-level-factory";
|
|
3
4
|
//#region src/rules/prefer-top-level-string-formats.ts
|
|
4
5
|
const TOP_LEVEL_STRING_FORMATS_URL = "https://zod.dev/v4?id=top-level-string-formats";
|
|
5
6
|
const ZOD_STRING_FORMAT_METHOD_NAMES = ZOD_STRING_FORMAT_METHODS.map(({ sourceMethodName }) => sourceMethodName);
|
|
6
|
-
const ZOD_STRING_FORMAT_METHODS_BY_SOURCE = Object.fromEntries(ZOD_STRING_FORMAT_METHODS.map((format) => [format.sourceMethodName, format]));
|
|
7
|
-
function isZodStringFormatMethodName(value) {
|
|
8
|
-
return ZOD_STRING_FORMAT_METHOD_NAMES.includes(value);
|
|
9
|
-
}
|
|
10
7
|
const preferTopLevelStringFormats = createZodPluginRule({
|
|
11
8
|
name: "prefer-top-level-string-formats",
|
|
12
9
|
meta: {
|
|
@@ -33,39 +30,13 @@ const preferTopLevelStringFormats = createZodPluginRule({
|
|
|
33
30
|
},
|
|
34
31
|
defaultOptions: [{}],
|
|
35
32
|
create(context, [{ ignore = [] }]) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const stringIndex = methods.findIndex((method) => method.name === "string");
|
|
44
|
-
if (stringIndex === -1) return;
|
|
45
|
-
const formatMethod = methods.find((method, index) => index > stringIndex && isZodStringFormatMethodName(method.name) && !ignoredMethods.has(method.name));
|
|
46
|
-
if (!formatMethod) return;
|
|
47
|
-
const { replacementMethodName, sourceMethodName } = ZOD_STRING_FORMAT_METHODS_BY_SOURCE[formatMethod.name];
|
|
48
|
-
context.report({
|
|
49
|
-
node,
|
|
50
|
-
messageId: "preferTopLevelStringFormat",
|
|
51
|
-
data: {
|
|
52
|
-
replacementMethod: replacementMethodName,
|
|
53
|
-
sourceMethod: sourceMethodName
|
|
54
|
-
},
|
|
55
|
-
fix(fixer) {
|
|
56
|
-
if (zodSchemaMeta.schemaDecl === "named") return null;
|
|
57
|
-
return buildZodChainReplacementFix({
|
|
58
|
-
sourceCode,
|
|
59
|
-
fixer,
|
|
60
|
-
methods,
|
|
61
|
-
fromIndex: stringIndex,
|
|
62
|
-
toIndex: methods.indexOf(formatMethod),
|
|
63
|
-
toMethodName: replacementMethodName
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
});
|
|
33
|
+
return buildPreferTopLevelFactoryCreate({
|
|
34
|
+
scope: zodImportScope,
|
|
35
|
+
factoryName: "string",
|
|
36
|
+
replacements: ZOD_STRING_FORMAT_METHODS,
|
|
37
|
+
messageId: "preferTopLevelStringFormat",
|
|
38
|
+
ignore
|
|
39
|
+
})(context);
|
|
69
40
|
}
|
|
70
41
|
});
|
|
71
42
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-zod",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.11.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.2.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",
|