eslint-plugin-zod 3.2.0 → 3.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.
Files changed (100) hide show
  1. package/README.md +33 -21
  2. package/dist/index.cjs +15 -4
  3. package/dist/index.d.cts +1 -0
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.js +15 -4
  6. package/dist/rules/array-style.cjs +5 -4
  7. package/dist/rules/array-style.d.cts +3 -2
  8. package/dist/rules/array-style.d.ts +3 -2
  9. package/dist/rules/array-style.js +5 -4
  10. package/dist/rules/consistent-import-source.cjs +5 -11
  11. package/dist/rules/consistent-import-source.d.cts +4 -3
  12. package/dist/rules/consistent-import-source.d.ts +4 -3
  13. package/dist/rules/consistent-import-source.js +4 -10
  14. package/dist/rules/consistent-import.cjs +4 -3
  15. package/dist/rules/consistent-import.d.cts +3 -2
  16. package/dist/rules/consistent-import.d.ts +3 -2
  17. package/dist/rules/consistent-import.js +5 -4
  18. package/dist/rules/consistent-object-schema-type.cjs +5 -3
  19. package/dist/rules/consistent-object-schema-type.d.cts +3 -1
  20. package/dist/rules/consistent-object-schema-type.d.ts +3 -1
  21. package/dist/rules/consistent-object-schema-type.js +6 -4
  22. package/dist/rules/no-any-schema.cjs +5 -3
  23. package/dist/rules/no-any-schema.d.cts +3 -1
  24. package/dist/rules/no-any-schema.d.ts +3 -1
  25. package/dist/rules/no-any-schema.js +6 -4
  26. package/dist/rules/no-empty-custom-schema.cjs +5 -4
  27. package/dist/rules/no-empty-custom-schema.d.cts +3 -2
  28. package/dist/rules/no-empty-custom-schema.d.ts +3 -2
  29. package/dist/rules/no-empty-custom-schema.js +5 -4
  30. package/dist/rules/no-number-schema-with-int.cjs +5 -4
  31. package/dist/rules/no-number-schema-with-int.d.cts +3 -2
  32. package/dist/rules/no-number-schema-with-int.d.ts +3 -2
  33. package/dist/rules/no-number-schema-with-int.js +5 -4
  34. package/dist/rules/no-optional-and-default-together.cjs +6 -5
  35. package/dist/rules/no-optional-and-default-together.d.cts +3 -2
  36. package/dist/rules/no-optional-and-default-together.d.ts +3 -2
  37. package/dist/rules/no-optional-and-default-together.js +7 -6
  38. package/dist/rules/no-string-schema-with-uuid.cjs +5 -4
  39. package/dist/rules/no-string-schema-with-uuid.d.cts +3 -2
  40. package/dist/rules/no-string-schema-with-uuid.d.ts +3 -2
  41. package/dist/rules/no-string-schema-with-uuid.js +5 -4
  42. package/dist/rules/no-throw-in-refine.cjs +5 -3
  43. package/dist/rules/no-throw-in-refine.d.cts +3 -2
  44. package/dist/rules/no-throw-in-refine.d.ts +3 -2
  45. package/dist/rules/no-throw-in-refine.js +6 -4
  46. package/dist/rules/no-unknown-schema.cjs +5 -4
  47. package/dist/rules/no-unknown-schema.d.cts +3 -2
  48. package/dist/rules/no-unknown-schema.d.ts +3 -2
  49. package/dist/rules/no-unknown-schema.js +5 -4
  50. package/dist/rules/prefer-enum-over-literal-union.cjs +5 -3
  51. package/dist/rules/prefer-enum-over-literal-union.d.cts +3 -2
  52. package/dist/rules/prefer-enum-over-literal-union.d.ts +3 -2
  53. package/dist/rules/prefer-enum-over-literal-union.js +6 -4
  54. package/dist/rules/prefer-meta-last.cjs +8 -5
  55. package/dist/rules/prefer-meta-last.d.cts +3 -2
  56. package/dist/rules/prefer-meta-last.d.ts +3 -2
  57. package/dist/rules/prefer-meta-last.js +8 -5
  58. package/dist/rules/prefer-meta.cjs +5 -4
  59. package/dist/rules/prefer-meta.d.cts +3 -2
  60. package/dist/rules/prefer-meta.d.ts +3 -2
  61. package/dist/rules/prefer-meta.js +5 -4
  62. package/dist/rules/prefer-namespace-import.cjs +4 -3
  63. package/dist/rules/prefer-namespace-import.d.cts +3 -2
  64. package/dist/rules/prefer-namespace-import.d.ts +3 -2
  65. package/dist/rules/prefer-namespace-import.js +5 -4
  66. package/dist/rules/prefer-string-schema-with-trim.cjs +53 -0
  67. package/dist/rules/prefer-string-schema-with-trim.d.cts +5 -0
  68. package/dist/rules/prefer-string-schema-with-trim.d.ts +5 -0
  69. package/dist/rules/prefer-string-schema-with-trim.js +50 -0
  70. package/dist/rules/require-brand-type-parameter.cjs +5 -4
  71. package/dist/rules/require-brand-type-parameter.d.cts +3 -1
  72. package/dist/rules/require-brand-type-parameter.d.ts +3 -1
  73. package/dist/rules/require-brand-type-parameter.js +5 -4
  74. package/dist/rules/require-error-message.cjs +5 -3
  75. package/dist/rules/require-error-message.d.cts +3 -2
  76. package/dist/rules/require-error-message.d.ts +3 -2
  77. package/dist/rules/require-error-message.js +6 -4
  78. package/dist/rules/require-schema-suffix.cjs +5 -3
  79. package/dist/rules/require-schema-suffix.d.cts +3 -2
  80. package/dist/rules/require-schema-suffix.d.ts +3 -2
  81. package/dist/rules/require-schema-suffix.js +6 -4
  82. package/dist/rules/schema-error-property-style.cjs +5 -3
  83. package/dist/rules/schema-error-property-style.d.cts +4 -3
  84. package/dist/rules/schema-error-property-style.d.ts +4 -3
  85. package/dist/rules/schema-error-property-style.js +6 -4
  86. package/dist/utils/build-zod-chain-replacement-fix.cjs +8 -1
  87. package/dist/utils/build-zod-chain-replacement-fix.js +8 -1
  88. package/dist/utils/create-plugin-rule.cjs +6 -0
  89. package/dist/utils/create-plugin-rule.d.cts +13 -0
  90. package/dist/utils/create-plugin-rule.d.ts +13 -0
  91. package/dist/utils/create-plugin-rule.js +3 -0
  92. package/dist/utils/is-zod-import-source.cjs +17 -2
  93. package/dist/utils/is-zod-import-source.d.cts +4 -1
  94. package/dist/utils/is-zod-import-source.d.ts +4 -1
  95. package/dist/utils/is-zod-import-source.js +16 -2
  96. package/dist/utils/track-zod-schema-imports.cjs +9 -2
  97. package/dist/utils/track-zod-schema-imports.d.cts +6 -1
  98. package/dist/utils/track-zod-schema-imports.d.ts +6 -1
  99. package/dist/utils/track-zod-schema-imports.js +8 -2
  100. package/package.json +1 -1
@@ -1,6 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ZOD_IMPORT_SOURCES = void 0;
3
4
  exports.isZodImportSource = isZodImportSource;
4
- function isZodImportSource(source) {
5
- return source === 'zod' || source.startsWith('zod/');
5
+ exports.ZOD_IMPORT_SOURCES = [
6
+ 'zod',
7
+ 'zod/mini',
8
+ 'zod/v4',
9
+ 'zod/v4-mini',
10
+ 'zod/v3',
11
+ ];
12
+ function isZodImportSource(source, allowedSource) {
13
+ const allowedSources = [];
14
+ if (allowedSource === 'all' || allowedSource === 'zod') {
15
+ allowedSources.push('zod', 'zod/v4', 'zod/v3');
16
+ }
17
+ if (allowedSource === 'all' || allowedSource === 'zod-mini') {
18
+ allowedSources.push('zod/mini', 'zod/v4-mini');
19
+ }
20
+ return allowedSources.includes(source);
6
21
  }
@@ -1 +1,4 @@
1
- export declare function isZodImportSource(source: string): boolean;
1
+ export type ZodImportAllowedSource = 'all' | 'zod' | 'zod-mini';
2
+ export declare const ZOD_IMPORT_SOURCES: readonly ["zod", "zod/mini", "zod/v4", "zod/v4-mini", "zod/v3"];
3
+ export type ZodImportSource = (typeof ZOD_IMPORT_SOURCES)[number];
4
+ export declare function isZodImportSource(source: string, allowedSource: ZodImportAllowedSource): boolean;
@@ -1 +1,4 @@
1
- export declare function isZodImportSource(source: string): boolean;
1
+ export type ZodImportAllowedSource = 'all' | 'zod' | 'zod-mini';
2
+ export declare const ZOD_IMPORT_SOURCES: readonly ["zod", "zod/mini", "zod/v4", "zod/v4-mini", "zod/v3"];
3
+ export type ZodImportSource = (typeof ZOD_IMPORT_SOURCES)[number];
4
+ export declare function isZodImportSource(source: string, allowedSource: ZodImportAllowedSource): boolean;
@@ -1,3 +1,17 @@
1
- export function isZodImportSource(source) {
2
- return source === 'zod' || source.startsWith('zod/');
1
+ export const ZOD_IMPORT_SOURCES = [
2
+ 'zod',
3
+ 'zod/mini',
4
+ 'zod/v4',
5
+ 'zod/v4-mini',
6
+ 'zod/v3',
7
+ ];
8
+ export function isZodImportSource(source, allowedSource) {
9
+ const allowedSources = [];
10
+ if (allowedSource === 'all' || allowedSource === 'zod') {
11
+ allowedSources.push('zod', 'zod/v4', 'zod/v3');
12
+ }
13
+ if (allowedSource === 'all' || allowedSource === 'zod-mini') {
14
+ allowedSources.push('zod/mini', 'zod/v4-mini');
15
+ }
16
+ return allowedSources.includes(source);
3
17
  }
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.trackZodSchemaImports = trackZodSchemaImports;
4
+ exports.createZodSchemaImportTrack = createZodSchemaImportTrack;
4
5
  const utils_1 = require("@typescript-eslint/utils");
5
6
  const detect_zod_schema_root_node_js_1 = require("./detect-zod-schema-root-node.cjs");
6
7
  const is_zod_import_source_js_1 = require("./is-zod-import-source.cjs");
7
- function trackZodSchemaImports() {
8
+ function trackZodSchemaImports(importAllowedSource) {
8
9
  const zodNamespaces = new Set();
9
10
  const zodNamedImports = new Set();
10
11
  function collectZodChainMethods(node) {
@@ -34,7 +35,7 @@ function trackZodSchemaImports() {
34
35
  }
35
36
  const result = {
36
37
  importDeclarationListener(node) {
37
- if (!(0, is_zod_import_source_js_1.isZodImportSource)(node.source.value)) {
38
+ if (!(0, is_zod_import_source_js_1.isZodImportSource)(node.source.value, importAllowedSource)) {
38
39
  return;
39
40
  }
40
41
  for (const spec of node.specifiers) {
@@ -59,3 +60,9 @@ function trackZodSchemaImports() {
59
60
  };
60
61
  return result;
61
62
  }
63
+ function createZodSchemaImportTrack(zodImportAllowedSource) {
64
+ return {
65
+ zodImportAllowedSource,
66
+ trackZodSchemaImports: () => trackZodSchemaImports(zodImportAllowedSource),
67
+ };
68
+ }
@@ -1,5 +1,6 @@
1
1
  import type { TSESTree } from '@typescript-eslint/utils';
2
2
  import type { DetectResult } from "./detect-zod-schema-root-node.cjs";
3
+ import type { ZodImportAllowedSource } from "./is-zod-import-source.cjs";
3
4
  interface ZodChainItem {
4
5
  name: string;
5
6
  node: TSESTree.CallExpression;
@@ -9,5 +10,9 @@ interface Result {
9
10
  detectZodSchemaRootNode: (node: TSESTree.Node) => null | DetectResult;
10
11
  collectZodChainMethods: (node: TSESTree.CallExpression) => Array<ZodChainItem>;
11
12
  }
12
- export declare function trackZodSchemaImports(): Result;
13
+ export declare function trackZodSchemaImports(importAllowedSource: ZodImportAllowedSource): Result;
14
+ export declare function createZodSchemaImportTrack(zodImportAllowedSource: ZodImportAllowedSource): {
15
+ zodImportAllowedSource: ZodImportAllowedSource;
16
+ trackZodSchemaImports: () => ReturnType<typeof trackZodSchemaImports>;
17
+ };
13
18
  export {};
@@ -1,5 +1,6 @@
1
1
  import type { TSESTree } from '@typescript-eslint/utils';
2
2
  import type { DetectResult } from "./detect-zod-schema-root-node.js";
3
+ import type { ZodImportAllowedSource } from "./is-zod-import-source.js";
3
4
  interface ZodChainItem {
4
5
  name: string;
5
6
  node: TSESTree.CallExpression;
@@ -9,5 +10,9 @@ interface Result {
9
10
  detectZodSchemaRootNode: (node: TSESTree.Node) => null | DetectResult;
10
11
  collectZodChainMethods: (node: TSESTree.CallExpression) => Array<ZodChainItem>;
11
12
  }
12
- export declare function trackZodSchemaImports(): Result;
13
+ export declare function trackZodSchemaImports(importAllowedSource: ZodImportAllowedSource): Result;
14
+ export declare function createZodSchemaImportTrack(zodImportAllowedSource: ZodImportAllowedSource): {
15
+ zodImportAllowedSource: ZodImportAllowedSource;
16
+ trackZodSchemaImports: () => ReturnType<typeof trackZodSchemaImports>;
17
+ };
13
18
  export {};
@@ -1,7 +1,7 @@
1
1
  import { AST_NODE_TYPES } from '@typescript-eslint/utils';
2
2
  import { detectZodSchemaRootNode } from "./detect-zod-schema-root-node.js";
3
3
  import { isZodImportSource } from "./is-zod-import-source.js";
4
- export function trackZodSchemaImports() {
4
+ export function trackZodSchemaImports(importAllowedSource) {
5
5
  const zodNamespaces = new Set();
6
6
  const zodNamedImports = new Set();
7
7
  function collectZodChainMethods(node) {
@@ -31,7 +31,7 @@ export function trackZodSchemaImports() {
31
31
  }
32
32
  const result = {
33
33
  importDeclarationListener(node) {
34
- if (!isZodImportSource(node.source.value)) {
34
+ if (!isZodImportSource(node.source.value, importAllowedSource)) {
35
35
  return;
36
36
  }
37
37
  for (const spec of node.specifiers) {
@@ -56,3 +56,9 @@ export function trackZodSchemaImports() {
56
56
  };
57
57
  return result;
58
58
  }
59
+ export function createZodSchemaImportTrack(zodImportAllowedSource) {
60
+ return {
61
+ zodImportAllowedSource,
62
+ trackZodSchemaImports: () => trackZodSchemaImports(zodImportAllowedSource),
63
+ };
64
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-zod",
3
- "version": "3.2.0",
3
+ "version": "3.4.0",
4
4
  "type": "module",
5
5
  "description": "ESLint plugin that adds custom linting rules to enforce best practices when using Zod",
6
6
  "engines": {