eslint-plugin-zod 4.0.0 → 4.0.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.
Files changed (64) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +23 -0
  2. package/dist/index.cjs +102 -0
  3. package/dist/index.d.cts +22 -0
  4. package/dist/index.d.mts +23 -0
  5. package/dist/index.mjs +102 -0
  6. package/dist/meta.cjs +11 -0
  7. package/dist/meta.mjs +8 -0
  8. package/dist/rules/array-style.cjs +87 -0
  9. package/dist/rules/array-style.mjs +86 -0
  10. package/dist/rules/consistent-import-source.cjs +58 -0
  11. package/dist/rules/consistent-import-source.mjs +57 -0
  12. package/dist/rules/consistent-import.cjs +107 -0
  13. package/dist/rules/consistent-import.mjs +106 -0
  14. package/dist/rules/consistent-object-schema-type.cjs +79 -0
  15. package/dist/rules/consistent-object-schema-type.mjs +78 -0
  16. package/dist/rules/consistent-schema-output-type-style.cjs +67 -0
  17. package/dist/rules/consistent-schema-output-type-style.mjs +66 -0
  18. package/dist/rules/consistent-schema-var-name.cjs +54 -0
  19. package/dist/rules/consistent-schema-var-name.mjs +53 -0
  20. package/dist/rules/no-any-schema.cjs +60 -0
  21. package/dist/rules/no-any-schema.mjs +59 -0
  22. package/dist/rules/no-empty-custom-schema.cjs +34 -0
  23. package/dist/rules/no-empty-custom-schema.mjs +33 -0
  24. package/dist/rules/no-number-schema-with-finite.cjs +41 -0
  25. package/dist/rules/no-number-schema-with-finite.mjs +40 -0
  26. package/dist/rules/no-number-schema-with-int.cjs +54 -0
  27. package/dist/rules/no-number-schema-with-int.mjs +53 -0
  28. package/dist/rules/no-number-schema-with-is-finite.cjs +35 -0
  29. package/dist/rules/no-number-schema-with-is-finite.mjs +34 -0
  30. package/dist/rules/no-number-schema-with-is-int.cjs +35 -0
  31. package/dist/rules/no-number-schema-with-is-int.mjs +34 -0
  32. package/dist/rules/no-number-schema-with-safe.cjs +54 -0
  33. package/dist/rules/no-number-schema-with-safe.mjs +53 -0
  34. package/dist/rules/no-number-schema-with-step.cjs +40 -0
  35. package/dist/rules/no-number-schema-with-step.mjs +39 -0
  36. package/dist/rules/no-optional-and-default-together.cjs +69 -0
  37. package/dist/rules/no-optional-and-default-together.mjs +68 -0
  38. package/dist/rules/no-string-schema-with-uuid.cjs +57 -0
  39. package/dist/rules/no-string-schema-with-uuid.mjs +56 -0
  40. package/dist/rules/no-throw-in-refine.cjs +67 -0
  41. package/dist/rules/no-throw-in-refine.mjs +66 -0
  42. package/dist/rules/no-transform-in-record-key.cjs +51 -0
  43. package/dist/rules/no-transform-in-record-key.mjs +50 -0
  44. package/dist/rules/no-unknown-schema.cjs +29 -0
  45. package/dist/rules/no-unknown-schema.mjs +28 -0
  46. package/dist/rules/prefer-enum-over-literal-union.cjs +61 -0
  47. package/dist/rules/prefer-enum-over-literal-union.mjs +60 -0
  48. package/dist/rules/prefer-meta-last.cjs +47 -0
  49. package/dist/rules/prefer-meta-last.mjs +46 -0
  50. package/dist/rules/prefer-meta.cjs +38 -0
  51. package/dist/rules/prefer-meta.mjs +37 -0
  52. package/dist/rules/prefer-string-schema-with-trim.cjs +49 -0
  53. package/dist/rules/prefer-string-schema-with-trim.mjs +48 -0
  54. package/dist/rules/prefer-trim-before-string-length-checks.cjs +60 -0
  55. package/dist/rules/prefer-trim-before-string-length-checks.mjs +59 -0
  56. package/dist/rules/require-brand-type-parameter.cjs +47 -0
  57. package/dist/rules/require-brand-type-parameter.mjs +46 -0
  58. package/dist/rules/require-error-message.cjs +82 -0
  59. package/dist/rules/require-error-message.mjs +81 -0
  60. package/dist/rules/schema-error-property-style.cjs +93 -0
  61. package/dist/rules/schema-error-property-style.mjs +91 -0
  62. package/dist/utils/create-plugin-rule.cjs +6 -0
  63. package/dist/utils/create-plugin-rule.mjs +6 -0
  64. package/package.json +2 -2
@@ -0,0 +1,23 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
23
+ exports.__toESM = __toESM;
package/dist/index.cjs ADDED
@@ -0,0 +1,102 @@
1
+ const require_meta = require("./meta.cjs");
2
+ const require_array_style = require("./rules/array-style.cjs");
3
+ const require_consistent_import_source = require("./rules/consistent-import-source.cjs");
4
+ const require_consistent_import = require("./rules/consistent-import.cjs");
5
+ const require_consistent_object_schema_type = require("./rules/consistent-object-schema-type.cjs");
6
+ const require_consistent_schema_output_type_style = require("./rules/consistent-schema-output-type-style.cjs");
7
+ const require_consistent_schema_var_name = require("./rules/consistent-schema-var-name.cjs");
8
+ const require_no_any_schema = require("./rules/no-any-schema.cjs");
9
+ const require_no_empty_custom_schema = require("./rules/no-empty-custom-schema.cjs");
10
+ const require_no_number_schema_with_finite = require("./rules/no-number-schema-with-finite.cjs");
11
+ const require_no_number_schema_with_int = require("./rules/no-number-schema-with-int.cjs");
12
+ const require_no_number_schema_with_is_finite = require("./rules/no-number-schema-with-is-finite.cjs");
13
+ const require_no_number_schema_with_is_int = require("./rules/no-number-schema-with-is-int.cjs");
14
+ const require_no_number_schema_with_safe = require("./rules/no-number-schema-with-safe.cjs");
15
+ const require_no_number_schema_with_step = require("./rules/no-number-schema-with-step.cjs");
16
+ const require_no_optional_and_default_together = require("./rules/no-optional-and-default-together.cjs");
17
+ const require_no_string_schema_with_uuid = require("./rules/no-string-schema-with-uuid.cjs");
18
+ const require_no_throw_in_refine = require("./rules/no-throw-in-refine.cjs");
19
+ const require_no_transform_in_record_key = require("./rules/no-transform-in-record-key.cjs");
20
+ const require_no_unknown_schema = require("./rules/no-unknown-schema.cjs");
21
+ const require_prefer_enum_over_literal_union = require("./rules/prefer-enum-over-literal-union.cjs");
22
+ const require_prefer_meta_last = require("./rules/prefer-meta-last.cjs");
23
+ const require_prefer_meta = require("./rules/prefer-meta.cjs");
24
+ const require_prefer_string_schema_with_trim = require("./rules/prefer-string-schema-with-trim.cjs");
25
+ const require_prefer_trim_before_string_length_checks = require("./rules/prefer-trim-before-string-length-checks.cjs");
26
+ const require_require_brand_type_parameter = require("./rules/require-brand-type-parameter.cjs");
27
+ const require_require_error_message = require("./rules/require-error-message.cjs");
28
+ const require_schema_error_property_style = require("./rules/schema-error-property-style.cjs");
29
+ //#region src/index.ts
30
+ const eslintPluginZod = {
31
+ meta: {
32
+ name: require_meta.PLUGIN_NAME,
33
+ version: require_meta.PLUGIN_VERSION
34
+ },
35
+ rules: {
36
+ "array-style": require_array_style.arrayStyle,
37
+ "consistent-import-source": require_consistent_import_source.consistentImportSource,
38
+ "consistent-import": require_consistent_import.consistentImport,
39
+ "consistent-object-schema-type": require_consistent_object_schema_type.consistentObjectSchemaType,
40
+ "consistent-schema-var-name": require_consistent_schema_var_name.consistentSchemaVarName,
41
+ "consistent-schema-output-type-style": require_consistent_schema_output_type_style.consistentSchemaOutputTypeStyle,
42
+ "no-any-schema": require_no_any_schema.noAnySchema,
43
+ "no-empty-custom-schema": require_no_empty_custom_schema.noEmptyCustomSchema,
44
+ "no-number-schema-with-finite": require_no_number_schema_with_finite.noNumberSchemaWithFinite,
45
+ "no-number-schema-with-int": require_no_number_schema_with_int.noNumberSchemaWithInt,
46
+ "no-number-schema-with-is-finite": require_no_number_schema_with_is_finite.noNumberSchemaWithIsFinite,
47
+ "no-number-schema-with-is-int": require_no_number_schema_with_is_int.noNumberSchemaWithIsInt,
48
+ "no-number-schema-with-safe": require_no_number_schema_with_safe.noNumberSchemaWithSafe,
49
+ "no-number-schema-with-step": require_no_number_schema_with_step.noNumberSchemaWithStep,
50
+ "no-string-schema-with-uuid": require_no_string_schema_with_uuid.noStringSchemaWithUuid,
51
+ "no-optional-and-default-together": require_no_optional_and_default_together.noOptionalAndDefaultTogether,
52
+ "no-throw-in-refine": require_no_throw_in_refine.noThrowInRefine,
53
+ "no-transform-in-record-key": require_no_transform_in_record_key.noTransformInRecordKey,
54
+ "no-unknown-schema": require_no_unknown_schema.noUnknownSchema,
55
+ "prefer-enum-over-literal-union": require_prefer_enum_over_literal_union.preferEnumOverLiteralUnion,
56
+ "prefer-meta": require_prefer_meta.preferMeta,
57
+ "prefer-meta-last": require_prefer_meta_last.preferMetaLast,
58
+ "prefer-string-schema-with-trim": require_prefer_string_schema_with_trim.preferStringSchemaWithTrim,
59
+ "prefer-trim-before-string-length-checks": require_prefer_trim_before_string_length_checks.preferTrimBeforeStringLengthChecks,
60
+ "require-brand-type-parameter": require_require_brand_type_parameter.requireBrandTypeParameter,
61
+ "require-error-message": require_require_error_message.requireErrorMessage,
62
+ "schema-error-property-style": require_schema_error_property_style.schemaErrorPropertyStyle
63
+ }
64
+ };
65
+ const recommendedConfig = {
66
+ name: `${require_meta.PLUGIN_NAME}/recommended`,
67
+ files: ["**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}"],
68
+ plugins: { zod: eslintPluginZod },
69
+ rules: {
70
+ "zod/array-style": "error",
71
+ "zod/consistent-import": "error",
72
+ "zod/consistent-schema-var-name": "error",
73
+ "zod/no-any-schema": "error",
74
+ "zod/no-empty-custom-schema": "error",
75
+ "zod/no-number-schema-with-finite": "error",
76
+ "zod/no-number-schema-with-int": "error",
77
+ "zod/no-number-schema-with-is-finite": "error",
78
+ "zod/no-number-schema-with-is-int": "error",
79
+ "zod/no-number-schema-with-safe": "error",
80
+ "zod/no-number-schema-with-step": "error",
81
+ "zod/no-string-schema-with-uuid": "error",
82
+ "zod/no-optional-and-default-together": "error",
83
+ "zod/no-throw-in-refine": "error",
84
+ "zod/prefer-enum-over-literal-union": "error",
85
+ "zod/prefer-meta": "error",
86
+ "zod/prefer-meta-last": "error",
87
+ "zod/prefer-string-schema-with-trim": "error",
88
+ "zod/prefer-trim-before-string-length-checks": "error",
89
+ "zod/require-brand-type-parameter": "error",
90
+ "zod/require-error-message": "error"
91
+ }
92
+ };
93
+ var src_default = {
94
+ ...eslintPluginZod,
95
+ configs: { recommended: recommendedConfig }
96
+ };
97
+ /**
98
+ * why `satisfies`?
99
+ * @see https://github.com/marcalexiei/eslint-zod/issues/49
100
+ */
101
+ //#endregion
102
+ module.exports = src_default;
@@ -0,0 +1,22 @@
1
+ //#region src/index.d.ts
2
+ interface CompatibleConfig {
3
+ name?: string;
4
+ rules?: object;
5
+ plugins?: Record<string, CompatiblePlugin>;
6
+ }
7
+ interface CompatiblePlugin {
8
+ meta: {
9
+ name: string;
10
+ version: string;
11
+ };
12
+ }
13
+ declare const _default: {
14
+ configs: {
15
+ recommended: CompatibleConfig;
16
+ };
17
+ meta: {
18
+ name: string;
19
+ version: string;
20
+ };
21
+ };
22
+ export = _default;
@@ -0,0 +1,23 @@
1
+ //#region src/index.d.ts
2
+ interface CompatibleConfig {
3
+ name?: string;
4
+ rules?: object;
5
+ plugins?: Record<string, CompatiblePlugin>;
6
+ }
7
+ interface CompatiblePlugin {
8
+ meta: {
9
+ name: string;
10
+ version: string;
11
+ };
12
+ }
13
+ declare const _default: {
14
+ configs: {
15
+ recommended: CompatibleConfig;
16
+ };
17
+ meta: {
18
+ name: string;
19
+ version: string;
20
+ };
21
+ };
22
+ //#endregion
23
+ export { _default as default };
package/dist/index.mjs ADDED
@@ -0,0 +1,102 @@
1
+ import { PLUGIN_NAME, PLUGIN_VERSION } from "./meta.mjs";
2
+ import { arrayStyle } from "./rules/array-style.mjs";
3
+ import { consistentImportSource } from "./rules/consistent-import-source.mjs";
4
+ import { consistentImport } from "./rules/consistent-import.mjs";
5
+ import { consistentObjectSchemaType } from "./rules/consistent-object-schema-type.mjs";
6
+ import { consistentSchemaOutputTypeStyle } from "./rules/consistent-schema-output-type-style.mjs";
7
+ import { consistentSchemaVarName } from "./rules/consistent-schema-var-name.mjs";
8
+ import { noAnySchema } from "./rules/no-any-schema.mjs";
9
+ import { noEmptyCustomSchema } from "./rules/no-empty-custom-schema.mjs";
10
+ import { noNumberSchemaWithFinite } from "./rules/no-number-schema-with-finite.mjs";
11
+ import { noNumberSchemaWithInt } from "./rules/no-number-schema-with-int.mjs";
12
+ import { noNumberSchemaWithIsFinite } from "./rules/no-number-schema-with-is-finite.mjs";
13
+ import { noNumberSchemaWithIsInt } from "./rules/no-number-schema-with-is-int.mjs";
14
+ import { noNumberSchemaWithSafe } from "./rules/no-number-schema-with-safe.mjs";
15
+ import { noNumberSchemaWithStep } from "./rules/no-number-schema-with-step.mjs";
16
+ import { noOptionalAndDefaultTogether } from "./rules/no-optional-and-default-together.mjs";
17
+ import { noStringSchemaWithUuid } from "./rules/no-string-schema-with-uuid.mjs";
18
+ import { noThrowInRefine } from "./rules/no-throw-in-refine.mjs";
19
+ import { noTransformInRecordKey } from "./rules/no-transform-in-record-key.mjs";
20
+ import { noUnknownSchema } from "./rules/no-unknown-schema.mjs";
21
+ import { preferEnumOverLiteralUnion } from "./rules/prefer-enum-over-literal-union.mjs";
22
+ import { preferMetaLast } from "./rules/prefer-meta-last.mjs";
23
+ import { preferMeta } from "./rules/prefer-meta.mjs";
24
+ import { preferStringSchemaWithTrim } from "./rules/prefer-string-schema-with-trim.mjs";
25
+ import { preferTrimBeforeStringLengthChecks } from "./rules/prefer-trim-before-string-length-checks.mjs";
26
+ import { requireBrandTypeParameter } from "./rules/require-brand-type-parameter.mjs";
27
+ import { requireErrorMessage } from "./rules/require-error-message.mjs";
28
+ import { schemaErrorPropertyStyle } from "./rules/schema-error-property-style.mjs";
29
+ //#region src/index.ts
30
+ const eslintPluginZod = {
31
+ meta: {
32
+ name: PLUGIN_NAME,
33
+ version: PLUGIN_VERSION
34
+ },
35
+ rules: {
36
+ "array-style": arrayStyle,
37
+ "consistent-import-source": consistentImportSource,
38
+ "consistent-import": consistentImport,
39
+ "consistent-object-schema-type": consistentObjectSchemaType,
40
+ "consistent-schema-var-name": consistentSchemaVarName,
41
+ "consistent-schema-output-type-style": consistentSchemaOutputTypeStyle,
42
+ "no-any-schema": noAnySchema,
43
+ "no-empty-custom-schema": noEmptyCustomSchema,
44
+ "no-number-schema-with-finite": noNumberSchemaWithFinite,
45
+ "no-number-schema-with-int": noNumberSchemaWithInt,
46
+ "no-number-schema-with-is-finite": noNumberSchemaWithIsFinite,
47
+ "no-number-schema-with-is-int": noNumberSchemaWithIsInt,
48
+ "no-number-schema-with-safe": noNumberSchemaWithSafe,
49
+ "no-number-schema-with-step": noNumberSchemaWithStep,
50
+ "no-string-schema-with-uuid": noStringSchemaWithUuid,
51
+ "no-optional-and-default-together": noOptionalAndDefaultTogether,
52
+ "no-throw-in-refine": noThrowInRefine,
53
+ "no-transform-in-record-key": noTransformInRecordKey,
54
+ "no-unknown-schema": noUnknownSchema,
55
+ "prefer-enum-over-literal-union": preferEnumOverLiteralUnion,
56
+ "prefer-meta": preferMeta,
57
+ "prefer-meta-last": preferMetaLast,
58
+ "prefer-string-schema-with-trim": preferStringSchemaWithTrim,
59
+ "prefer-trim-before-string-length-checks": preferTrimBeforeStringLengthChecks,
60
+ "require-brand-type-parameter": requireBrandTypeParameter,
61
+ "require-error-message": requireErrorMessage,
62
+ "schema-error-property-style": schemaErrorPropertyStyle
63
+ }
64
+ };
65
+ const recommendedConfig = {
66
+ name: `${PLUGIN_NAME}/recommended`,
67
+ files: ["**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}"],
68
+ plugins: { zod: eslintPluginZod },
69
+ rules: {
70
+ "zod/array-style": "error",
71
+ "zod/consistent-import": "error",
72
+ "zod/consistent-schema-var-name": "error",
73
+ "zod/no-any-schema": "error",
74
+ "zod/no-empty-custom-schema": "error",
75
+ "zod/no-number-schema-with-finite": "error",
76
+ "zod/no-number-schema-with-int": "error",
77
+ "zod/no-number-schema-with-is-finite": "error",
78
+ "zod/no-number-schema-with-is-int": "error",
79
+ "zod/no-number-schema-with-safe": "error",
80
+ "zod/no-number-schema-with-step": "error",
81
+ "zod/no-string-schema-with-uuid": "error",
82
+ "zod/no-optional-and-default-together": "error",
83
+ "zod/no-throw-in-refine": "error",
84
+ "zod/prefer-enum-over-literal-union": "error",
85
+ "zod/prefer-meta": "error",
86
+ "zod/prefer-meta-last": "error",
87
+ "zod/prefer-string-schema-with-trim": "error",
88
+ "zod/prefer-trim-before-string-length-checks": "error",
89
+ "zod/require-brand-type-parameter": "error",
90
+ "zod/require-error-message": "error"
91
+ }
92
+ };
93
+ var src_default = {
94
+ ...eslintPluginZod,
95
+ configs: { recommended: recommendedConfig }
96
+ };
97
+ /**
98
+ * why `satisfies`?
99
+ * @see https://github.com/marcalexiei/eslint-zod/issues/49
100
+ */
101
+ //#endregion
102
+ export { src_default as default };
package/dist/meta.cjs ADDED
@@ -0,0 +1,11 @@
1
+ require("./_virtual/_rolldown/runtime.cjs");
2
+ let node_fs = require("node:fs");
3
+ //#region src/meta.ts
4
+ const { name: PLUGIN_NAME, version: PLUGIN_VERSION, repository } = JSON.parse((0, node_fs.readFileSync)(new URL("../package.json", require("url").pathToFileURL(__filename).href), "utf8"));
5
+ function getRuleURL(ruleID) {
6
+ return `${repository.url}/blob/HEAD/${repository.directory}/docs/rules/${ruleID}.md`;
7
+ }
8
+ //#endregion
9
+ exports.PLUGIN_NAME = PLUGIN_NAME;
10
+ exports.PLUGIN_VERSION = PLUGIN_VERSION;
11
+ exports.getRuleURL = getRuleURL;
package/dist/meta.mjs ADDED
@@ -0,0 +1,8 @@
1
+ import { readFileSync } from "node:fs";
2
+ //#region src/meta.ts
3
+ const { name: PLUGIN_NAME, version: PLUGIN_VERSION, repository } = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
4
+ function getRuleURL(ruleID) {
5
+ return `${repository.url}/blob/HEAD/${repository.directory}/docs/rules/${ruleID}.md`;
6
+ }
7
+ //#endregion
8
+ export { PLUGIN_NAME, PLUGIN_VERSION, getRuleURL };
@@ -0,0 +1,87 @@
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/array-style.ts
5
+ const ZOD_ARRAY_STYLES = ["function", "method"];
6
+ const defaultOptions = { style: "function" };
7
+ const { trackZodSchemaImports } = (0, _eslint_zod_utils.createZodSchemaImportTrack)(_eslint_zod_utils.zodImportScope);
8
+ const arrayStyle = require_create_plugin_rule.createZodPluginRule({
9
+ name: "array-style",
10
+ meta: {
11
+ type: "suggestion",
12
+ fixable: "code",
13
+ docs: { description: "Enforce consistent Zod array style" },
14
+ messages: {
15
+ useFunction: "Use z.array(schema) instead of schema.array().",
16
+ useMethod: "Use schema.array() instead of z.array(schema)."
17
+ },
18
+ schema: [{
19
+ type: "object",
20
+ properties: { style: {
21
+ description: "Decides which style for zod array function",
22
+ type: "string",
23
+ enum: ZOD_ARRAY_STYLES
24
+ } },
25
+ additionalProperties: false
26
+ }]
27
+ },
28
+ defaultOptions: [defaultOptions],
29
+ create(context, [{ style }]) {
30
+ const { sourceCode } = context;
31
+ const { importDeclarationListener, detectZodSchemaRootNode, collectZodChainMethods } = trackZodSchemaImports();
32
+ return {
33
+ ImportDeclaration: importDeclarationListener,
34
+ CallExpression(node) {
35
+ const zodSchema = detectZodSchemaRootNode(node);
36
+ if (!zodSchema) return;
37
+ const { schemaDecl, schemaType } = zodSchema;
38
+ if (style === "method") {
39
+ if (schemaType === "array") {
40
+ if (schemaDecl === "namespace") {
41
+ context.report({
42
+ node,
43
+ messageId: "useMethod",
44
+ fix(fixer) {
45
+ const arrayCall = collectZodChainMethods(node).find((c) => c.name === "array");
46
+ if (!arrayCall) return null;
47
+ const arg = arrayCall.node.arguments.at(0);
48
+ if (!arg) return null;
49
+ const argText = sourceCode.getText(arg);
50
+ return fixer.replaceText(arrayCall.node, `${argText}.array()`);
51
+ }
52
+ });
53
+ return;
54
+ }
55
+ context.report({
56
+ node,
57
+ messageId: "useMethod"
58
+ });
59
+ }
60
+ return;
61
+ }
62
+ const arrayMethod = collectZodChainMethods(node).find((it) => it.name === "array" && it.node.arguments.length === 0);
63
+ if (arrayMethod) {
64
+ const arrayNode = arrayMethod.node;
65
+ if (schemaDecl === "namespace") {
66
+ context.report({
67
+ node,
68
+ messageId: "useFunction",
69
+ fix(fixer) {
70
+ const callee = arrayNode.callee;
71
+ const objText = sourceCode.getText(callee.object);
72
+ return fixer.replaceText(arrayNode, `z.array(${objText})`);
73
+ }
74
+ });
75
+ return;
76
+ }
77
+ context.report({
78
+ node,
79
+ messageId: "useFunction"
80
+ });
81
+ }
82
+ }
83
+ };
84
+ }
85
+ });
86
+ //#endregion
87
+ exports.arrayStyle = arrayStyle;
@@ -0,0 +1,86 @@
1
+ import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
2
+ import { createZodSchemaImportTrack, zodImportScope } from "@eslint-zod/utils";
3
+ //#region src/rules/array-style.ts
4
+ const ZOD_ARRAY_STYLES = ["function", "method"];
5
+ const defaultOptions = { style: "function" };
6
+ const { trackZodSchemaImports } = createZodSchemaImportTrack(zodImportScope);
7
+ const arrayStyle = createZodPluginRule({
8
+ name: "array-style",
9
+ meta: {
10
+ type: "suggestion",
11
+ fixable: "code",
12
+ docs: { description: "Enforce consistent Zod array style" },
13
+ messages: {
14
+ useFunction: "Use z.array(schema) instead of schema.array().",
15
+ useMethod: "Use schema.array() instead of z.array(schema)."
16
+ },
17
+ schema: [{
18
+ type: "object",
19
+ properties: { style: {
20
+ description: "Decides which style for zod array function",
21
+ type: "string",
22
+ enum: ZOD_ARRAY_STYLES
23
+ } },
24
+ additionalProperties: false
25
+ }]
26
+ },
27
+ defaultOptions: [defaultOptions],
28
+ create(context, [{ style }]) {
29
+ const { sourceCode } = context;
30
+ const { importDeclarationListener, detectZodSchemaRootNode, collectZodChainMethods } = trackZodSchemaImports();
31
+ return {
32
+ ImportDeclaration: importDeclarationListener,
33
+ CallExpression(node) {
34
+ const zodSchema = detectZodSchemaRootNode(node);
35
+ if (!zodSchema) return;
36
+ const { schemaDecl, schemaType } = zodSchema;
37
+ if (style === "method") {
38
+ if (schemaType === "array") {
39
+ if (schemaDecl === "namespace") {
40
+ context.report({
41
+ node,
42
+ messageId: "useMethod",
43
+ fix(fixer) {
44
+ const arrayCall = collectZodChainMethods(node).find((c) => c.name === "array");
45
+ if (!arrayCall) return null;
46
+ const arg = arrayCall.node.arguments.at(0);
47
+ if (!arg) return null;
48
+ const argText = sourceCode.getText(arg);
49
+ return fixer.replaceText(arrayCall.node, `${argText}.array()`);
50
+ }
51
+ });
52
+ return;
53
+ }
54
+ context.report({
55
+ node,
56
+ messageId: "useMethod"
57
+ });
58
+ }
59
+ return;
60
+ }
61
+ const arrayMethod = collectZodChainMethods(node).find((it) => it.name === "array" && it.node.arguments.length === 0);
62
+ if (arrayMethod) {
63
+ const arrayNode = arrayMethod.node;
64
+ if (schemaDecl === "namespace") {
65
+ context.report({
66
+ node,
67
+ messageId: "useFunction",
68
+ fix(fixer) {
69
+ const callee = arrayNode.callee;
70
+ const objText = sourceCode.getText(callee.object);
71
+ return fixer.replaceText(arrayNode, `z.array(${objText})`);
72
+ }
73
+ });
74
+ return;
75
+ }
76
+ context.report({
77
+ node,
78
+ messageId: "useFunction"
79
+ });
80
+ }
81
+ }
82
+ };
83
+ }
84
+ });
85
+ //#endregion
86
+ export { arrayStyle };
@@ -0,0 +1,58 @@
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/consistent-import-source.ts
5
+ const consistentImportSource = require_create_plugin_rule.createZodPluginRule({
6
+ name: "consistent-import-source",
7
+ meta: {
8
+ hasSuggestions: true,
9
+ type: "suggestion",
10
+ docs: { description: "Enforce consistent source from Zod imports" },
11
+ messages: {
12
+ sourceNotAllowed: "\"{{source}}\" is not allowed. Available values are: {{sources}}",
13
+ replaceSource: "Replace \"{{invalid}}\" with \"{{valid}}\""
14
+ },
15
+ schema: [{
16
+ type: "object",
17
+ properties: { sources: {
18
+ type: "array",
19
+ description: "An array of allowed Zod import sources.",
20
+ items: {
21
+ type: "string",
22
+ enum: [..._eslint_zod_utils.zodImportScope.sources]
23
+ },
24
+ minItems: 1,
25
+ uniqueItems: true
26
+ } },
27
+ additionalProperties: false
28
+ }]
29
+ },
30
+ defaultOptions: [{ sources: ["zod"] }],
31
+ create(context, [{ sources }]) {
32
+ return { ImportDeclaration(node) {
33
+ const sourceValue = node.source.value;
34
+ if (!_eslint_zod_utils.zodImportScope.isAllowed(sourceValue)) return;
35
+ if (sources.includes(sourceValue)) return;
36
+ context.report({
37
+ node,
38
+ messageId: "sourceNotAllowed",
39
+ data: {
40
+ source: sourceValue,
41
+ sources: sources.map((s) => `"${s}"`).join(", ")
42
+ },
43
+ suggest: sources.map((it) => ({
44
+ messageId: "replaceSource",
45
+ data: {
46
+ valid: it,
47
+ invalid: sourceValue
48
+ },
49
+ fix(fixer) {
50
+ return fixer.replaceText(node.source, node.source.raw.replace(sourceValue, it));
51
+ }
52
+ }))
53
+ });
54
+ } };
55
+ }
56
+ });
57
+ //#endregion
58
+ exports.consistentImportSource = consistentImportSource;
@@ -0,0 +1,57 @@
1
+ import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
2
+ import { zodImportScope } from "@eslint-zod/utils";
3
+ //#region src/rules/consistent-import-source.ts
4
+ const consistentImportSource = createZodPluginRule({
5
+ name: "consistent-import-source",
6
+ meta: {
7
+ hasSuggestions: true,
8
+ type: "suggestion",
9
+ docs: { description: "Enforce consistent source from Zod imports" },
10
+ messages: {
11
+ sourceNotAllowed: "\"{{source}}\" is not allowed. Available values are: {{sources}}",
12
+ replaceSource: "Replace \"{{invalid}}\" with \"{{valid}}\""
13
+ },
14
+ schema: [{
15
+ type: "object",
16
+ properties: { sources: {
17
+ type: "array",
18
+ description: "An array of allowed Zod import sources.",
19
+ items: {
20
+ type: "string",
21
+ enum: [...zodImportScope.sources]
22
+ },
23
+ minItems: 1,
24
+ uniqueItems: true
25
+ } },
26
+ additionalProperties: false
27
+ }]
28
+ },
29
+ defaultOptions: [{ sources: ["zod"] }],
30
+ create(context, [{ sources }]) {
31
+ return { ImportDeclaration(node) {
32
+ const sourceValue = node.source.value;
33
+ if (!zodImportScope.isAllowed(sourceValue)) return;
34
+ if (sources.includes(sourceValue)) return;
35
+ context.report({
36
+ node,
37
+ messageId: "sourceNotAllowed",
38
+ data: {
39
+ source: sourceValue,
40
+ sources: sources.map((s) => `"${s}"`).join(", ")
41
+ },
42
+ suggest: sources.map((it) => ({
43
+ messageId: "replaceSource",
44
+ data: {
45
+ valid: it,
46
+ invalid: sourceValue
47
+ },
48
+ fix(fixer) {
49
+ return fixer.replaceText(node.source, node.source.raw.replace(sourceValue, it));
50
+ }
51
+ }))
52
+ });
53
+ } };
54
+ }
55
+ });
56
+ //#endregion
57
+ export { consistentImportSource };