eslint-plugin-zod 4.9.0 → 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.
Files changed (46) hide show
  1. package/README.md +1 -0
  2. package/dist/index.cjs +2 -0
  3. package/dist/index.mjs +2 -0
  4. package/dist/rules/array-style.cjs +37 -46
  5. package/dist/rules/array-style.mjs +38 -47
  6. package/dist/rules/no-native-enum.cjs +2 -21
  7. package/dist/rules/no-native-enum.mjs +3 -22
  8. package/dist/rules/no-number-schema-with-finite.cjs +8 -9
  9. package/dist/rules/no-number-schema-with-finite.mjs +9 -10
  10. package/dist/rules/no-number-schema-with-int.cjs +5 -8
  11. package/dist/rules/no-number-schema-with-int.mjs +6 -9
  12. package/dist/rules/no-number-schema-with-is-finite.cjs +7 -19
  13. package/dist/rules/no-number-schema-with-is-finite.mjs +8 -20
  14. package/dist/rules/no-number-schema-with-is-int.cjs +7 -19
  15. package/dist/rules/no-number-schema-with-is-int.mjs +8 -20
  16. package/dist/rules/no-number-schema-with-safe.cjs +9 -13
  17. package/dist/rules/no-number-schema-with-safe.mjs +10 -14
  18. package/dist/rules/no-number-schema-with-step.cjs +10 -14
  19. package/dist/rules/no-number-schema-with-step.mjs +11 -15
  20. package/dist/rules/no-optional-and-default-together.cjs +23 -28
  21. package/dist/rules/no-optional-and-default-together.mjs +24 -29
  22. package/dist/rules/no-promise-schema.cjs +2 -14
  23. package/dist/rules/no-promise-schema.mjs +3 -15
  24. package/dist/rules/no-schema-with-is-nullable.cjs +6 -19
  25. package/dist/rules/no-schema-with-is-nullable.mjs +7 -20
  26. package/dist/rules/no-schema-with-is-optional.cjs +6 -19
  27. package/dist/rules/no-schema-with-is-optional.mjs +7 -20
  28. package/dist/rules/no-string-schema-with-uuid.cjs +5 -8
  29. package/dist/rules/no-string-schema-with-uuid.mjs +6 -9
  30. package/dist/rules/prefer-loose-object.cjs +8 -32
  31. package/dist/rules/prefer-loose-object.mjs +9 -33
  32. package/dist/rules/prefer-meta-last.cjs +23 -28
  33. package/dist/rules/prefer-meta-last.mjs +24 -29
  34. package/dist/rules/prefer-meta.cjs +13 -19
  35. package/dist/rules/prefer-meta.mjs +14 -20
  36. package/dist/rules/prefer-strict-object.cjs +8 -32
  37. package/dist/rules/prefer-strict-object.mjs +9 -33
  38. package/dist/rules/prefer-string-length-over-min-max.cjs +23 -0
  39. package/dist/rules/prefer-string-length-over-min-max.mjs +23 -0
  40. package/dist/rules/prefer-string-schema-with-trim.cjs +11 -14
  41. package/dist/rules/prefer-string-schema-with-trim.mjs +12 -15
  42. package/dist/rules/prefer-top-level-string-formats.cjs +12 -123
  43. package/dist/rules/prefer-top-level-string-formats.mjs +14 -124
  44. package/dist/rules/prefer-trim-before-string-length-checks.cjs +8 -11
  45. package/dist/rules/prefer-trim-before-string-length-checks.mjs +9 -12
  46. package/package.json +8 -10
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,9 +1,5 @@
1
1
  const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
2
2
  let _eslint_zod_utils = require("@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 } = (0, _eslint_zod_utils.createZodSchemaImportTrack)(_eslint_zod_utils.zodImportScope);
7
3
  const arrayStyle = require_create_plugin_rule.createZodPluginRule({
8
4
  name: "array-style",
9
5
  meta: {
@@ -19,67 +15,62 @@ const arrayStyle = require_create_plugin_rule.createZodPluginRule({
19
15
  properties: { style: {
20
16
  description: "Decides which style for zod array function",
21
17
  type: "string",
22
- enum: ZOD_ARRAY_STYLES
18
+ enum: ["function", "method"]
23
19
  } },
24
20
  additionalProperties: false
25
21
  }]
26
22
  },
27
- defaultOptions: [defaultOptions],
23
+ defaultOptions: [{ style: "function" }],
28
24
  create(context, [{ style }]) {
29
25
  const { sourceCode } = context;
30
- const { importDeclarationListener, detectZodSchemaRootNode, collectZodChainMethods } = trackZodSchemaImports();
31
- return {
32
- ImportDeclaration: importDeclarationListener,
33
- CallExpression(node) {
34
- const zodSchemaMeta = detectZodSchemaRootNode(node);
35
- if (!zodSchemaMeta) return;
36
- const { schemaDecl, schemaType } = zodSchemaMeta;
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;
26
+ const { createSchemaVisitor, collectZodChainMethods } = _eslint_zod_utils.zodImportScope.createTracker();
27
+ return createSchemaVisitor({ onSchema(node, zodSchemaMeta) {
28
+ const { schemaDecl, schemaType } = zodSchemaMeta;
29
+ if (style === "method") {
30
+ if (schemaType === "array") {
64
31
  if (schemaDecl === "namespace") {
65
32
  context.report({
66
33
  node,
67
- messageId: "useFunction",
34
+ messageId: "useMethod",
68
35
  fix(fixer) {
69
- const callee = arrayNode.callee;
70
- const objText = sourceCode.getText(callee.object);
71
- return fixer.replaceText(arrayNode, `z.array(${objText})`);
36
+ const arrayCall = collectZodChainMethods(node).find((c) => c.name === "array");
37
+ if (!arrayCall) return null;
38
+ const arg = arrayCall.node.arguments.at(0);
39
+ if (!arg) return null;
40
+ const argText = sourceCode.getText(arg);
41
+ return fixer.replaceText(arrayCall.node, `${argText}.array()`);
72
42
  }
73
43
  });
74
44
  return;
75
45
  }
76
46
  context.report({
77
47
  node,
78
- messageId: "useFunction"
48
+ messageId: "useMethod"
79
49
  });
80
50
  }
51
+ return;
52
+ }
53
+ const arrayMethod = collectZodChainMethods(node).find((it) => it.name === "array" && it.node.arguments.length === 0);
54
+ if (arrayMethod) {
55
+ const arrayNode = arrayMethod.node;
56
+ if (schemaDecl === "namespace") {
57
+ context.report({
58
+ node,
59
+ messageId: "useFunction",
60
+ fix(fixer) {
61
+ const callee = arrayNode.callee;
62
+ const objText = sourceCode.getText(callee.object);
63
+ return fixer.replaceText(arrayNode, `z.array(${objText})`);
64
+ }
65
+ });
66
+ return;
67
+ }
68
+ context.report({
69
+ node,
70
+ messageId: "useFunction"
71
+ });
81
72
  }
82
- };
73
+ } });
83
74
  }
84
75
  });
85
76
  //#endregion
@@ -1,9 +1,5 @@
1
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);
2
+ import { zodImportScope } from "@eslint-zod/utils";
7
3
  const arrayStyle = createZodPluginRule({
8
4
  name: "array-style",
9
5
  meta: {
@@ -19,67 +15,62 @@ const arrayStyle = createZodPluginRule({
19
15
  properties: { style: {
20
16
  description: "Decides which style for zod array function",
21
17
  type: "string",
22
- enum: ZOD_ARRAY_STYLES
18
+ enum: ["function", "method"]
23
19
  } },
24
20
  additionalProperties: false
25
21
  }]
26
22
  },
27
- defaultOptions: [defaultOptions],
23
+ defaultOptions: [{ style: "function" }],
28
24
  create(context, [{ style }]) {
29
25
  const { sourceCode } = context;
30
- const { importDeclarationListener, detectZodSchemaRootNode, collectZodChainMethods } = trackZodSchemaImports();
31
- return {
32
- ImportDeclaration: importDeclarationListener,
33
- CallExpression(node) {
34
- const zodSchemaMeta = detectZodSchemaRootNode(node);
35
- if (!zodSchemaMeta) return;
36
- const { schemaDecl, schemaType } = zodSchemaMeta;
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;
26
+ const { createSchemaVisitor, collectZodChainMethods } = zodImportScope.createTracker();
27
+ return createSchemaVisitor({ onSchema(node, zodSchemaMeta) {
28
+ const { schemaDecl, schemaType } = zodSchemaMeta;
29
+ if (style === "method") {
30
+ if (schemaType === "array") {
64
31
  if (schemaDecl === "namespace") {
65
32
  context.report({
66
33
  node,
67
- messageId: "useFunction",
34
+ messageId: "useMethod",
68
35
  fix(fixer) {
69
- const callee = arrayNode.callee;
70
- const objText = sourceCode.getText(callee.object);
71
- return fixer.replaceText(arrayNode, `z.array(${objText})`);
36
+ const arrayCall = collectZodChainMethods(node).find((c) => c.name === "array");
37
+ if (!arrayCall) return null;
38
+ const arg = arrayCall.node.arguments.at(0);
39
+ if (!arg) return null;
40
+ const argText = sourceCode.getText(arg);
41
+ return fixer.replaceText(arrayCall.node, `${argText}.array()`);
72
42
  }
73
43
  });
74
44
  return;
75
45
  }
76
46
  context.report({
77
47
  node,
78
- messageId: "useFunction"
48
+ messageId: "useMethod"
79
49
  });
80
50
  }
51
+ return;
52
+ }
53
+ const arrayMethod = collectZodChainMethods(node).find((it) => it.name === "array" && it.node.arguments.length === 0);
54
+ if (arrayMethod) {
55
+ const arrayNode = arrayMethod.node;
56
+ if (schemaDecl === "namespace") {
57
+ context.report({
58
+ node,
59
+ messageId: "useFunction",
60
+ fix(fixer) {
61
+ const callee = arrayNode.callee;
62
+ const objText = sourceCode.getText(callee.object);
63
+ return fixer.replaceText(arrayNode, `z.array(${objText})`);
64
+ }
65
+ });
66
+ return;
67
+ }
68
+ context.report({
69
+ node,
70
+ messageId: "useFunction"
71
+ });
81
72
  }
82
- };
73
+ } });
83
74
  }
84
75
  });
85
76
  //#endregion
@@ -1,8 +1,7 @@
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 _typescript_eslint_utils = require("@typescript-eslint/utils");
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
- const { trackZodSchemaImports } = (0, _eslint_zod_utils.createZodSchemaImportTrack)(_eslint_zod_utils.zodImportScope);
6
5
  const noNativeEnum = require_create_plugin_rule.createZodPluginRule({
7
6
  name: "no-native-enum",
8
7
  meta: {
@@ -13,25 +12,7 @@ const noNativeEnum = require_create_plugin_rule.createZodPluginRule({
13
12
  schema: []
14
13
  },
15
14
  defaultOptions: [],
16
- create(context) {
17
- const { importDeclarationListener, detectZodSchemaRootNode, collectZodChainMethods } = trackZodSchemaImports();
18
- return {
19
- ImportDeclaration: importDeclarationListener,
20
- CallExpression(node) {
21
- const zodSchemaMeta = detectZodSchemaRootNode(node);
22
- if (zodSchemaMeta?.schemaType !== "nativeEnum") return;
23
- const [{ node: rootMethodNode }] = collectZodChainMethods(zodSchemaMeta.node);
24
- context.report({
25
- node,
26
- messageId: "useEnum",
27
- fix(fixer) {
28
- if (rootMethodNode.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return null;
29
- return fixer.replaceText(rootMethodNode.callee.property, "enum");
30
- }
31
- });
32
- }
33
- };
34
- }
15
+ create: (0, _eslint_zod_utils_rule_builders_no_native_enum.buildNoNativeEnumCreate)(_eslint_zod_utils.zodImportScope)
35
16
  });
36
17
  //#endregion
37
18
  exports.noNativeEnum = noNativeEnum;
@@ -1,8 +1,7 @@
1
1
  import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
2
- import { createZodSchemaImportTrack, zodImportScope } from "@eslint-zod/utils";
3
- import { AST_NODE_TYPES } from "@typescript-eslint/utils";
2
+ import { zodImportScope } from "@eslint-zod/utils";
3
+ import { buildNoNativeEnumCreate } from "@eslint-zod/utils/rule-builders/no-native-enum";
4
4
  //#region src/rules/no-native-enum.ts
5
- const { trackZodSchemaImports } = createZodSchemaImportTrack(zodImportScope);
6
5
  const noNativeEnum = createZodPluginRule({
7
6
  name: "no-native-enum",
8
7
  meta: {
@@ -13,25 +12,7 @@ const noNativeEnum = createZodPluginRule({
13
12
  schema: []
14
13
  },
15
14
  defaultOptions: [],
16
- create(context) {
17
- const { importDeclarationListener, detectZodSchemaRootNode, collectZodChainMethods } = trackZodSchemaImports();
18
- return {
19
- ImportDeclaration: importDeclarationListener,
20
- CallExpression(node) {
21
- const zodSchemaMeta = detectZodSchemaRootNode(node);
22
- if (zodSchemaMeta?.schemaType !== "nativeEnum") return;
23
- const [{ node: rootMethodNode }] = collectZodChainMethods(zodSchemaMeta.node);
24
- context.report({
25
- node,
26
- messageId: "useEnum",
27
- fix(fixer) {
28
- if (rootMethodNode.callee.type !== AST_NODE_TYPES.MemberExpression) return null;
29
- return fixer.replaceText(rootMethodNode.callee.property, "enum");
30
- }
31
- });
32
- }
33
- };
34
- }
15
+ create: buildNoNativeEnumCreate(zodImportScope)
35
16
  });
36
17
  //#endregion
37
18
  export { noNativeEnum };
@@ -1,7 +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
3
  //#region src/rules/no-number-schema-with-finite.ts
4
- const { trackZodSchemaImports } = (0, _eslint_zod_utils.createZodSchemaImportTrack)(_eslint_zod_utils.zodImportScope);
5
4
  const noNumberSchemaWithFinite = require_create_plugin_rule.createZodPluginRule({
6
5
  name: "no-number-schema-with-finite",
7
6
  meta: {
@@ -13,18 +12,18 @@ const noNumberSchemaWithFinite = require_create_plugin_rule.createZodPluginRule(
13
12
  },
14
13
  defaultOptions: [],
15
14
  create(context) {
16
- const { importDeclarationListener, detectZodSchemaRootNode, collectZodChainMethods } = trackZodSchemaImports();
17
- return {
18
- ImportDeclaration: importDeclarationListener,
19
- CallExpression(node) {
20
- if (detectZodSchemaRootNode(node)?.schemaType !== "number") return;
15
+ const { createSchemaVisitor, collectZodChainMethods } = _eslint_zod_utils.zodImportScope.createTracker();
16
+ return createSchemaVisitor({
17
+ schemaType: "number",
18
+ onSchema(node, zodSchemaMeta) {
19
+ if (!(0, _eslint_zod_utils.getZodChainedMethodNames)(zodSchemaMeta).includes("finite")) return;
21
20
  const methods = collectZodChainMethods(node);
22
- const finiteIndex = methods.findIndex((m) => m.name === "finite" && m.node === node);
23
- if (finiteIndex === -1) return;
21
+ const finiteIndex = methods.findIndex((m, index) => index > 0 && m.name === "finite");
24
22
  context.report({
25
23
  node,
26
24
  messageId: "removeFinite",
27
25
  fix(fixer) {
26
+ if (finiteIndex === -1) return null;
28
27
  return (0, _eslint_zod_utils.buildZodChainRemoveMethodFix)({
29
28
  fixer,
30
29
  methods,
@@ -33,7 +32,7 @@ const noNumberSchemaWithFinite = require_create_plugin_rule.createZodPluginRule(
33
32
  }
34
33
  });
35
34
  }
36
- };
35
+ });
37
36
  }
38
37
  });
39
38
  //#endregion
@@ -1,7 +1,6 @@
1
1
  import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
2
- import { buildZodChainRemoveMethodFix, createZodSchemaImportTrack, zodImportScope } from "@eslint-zod/utils";
2
+ import { buildZodChainRemoveMethodFix, getZodChainedMethodNames, zodImportScope } from "@eslint-zod/utils";
3
3
  //#region src/rules/no-number-schema-with-finite.ts
4
- const { trackZodSchemaImports } = createZodSchemaImportTrack(zodImportScope);
5
4
  const noNumberSchemaWithFinite = createZodPluginRule({
6
5
  name: "no-number-schema-with-finite",
7
6
  meta: {
@@ -13,18 +12,18 @@ const noNumberSchemaWithFinite = createZodPluginRule({
13
12
  },
14
13
  defaultOptions: [],
15
14
  create(context) {
16
- const { importDeclarationListener, detectZodSchemaRootNode, collectZodChainMethods } = trackZodSchemaImports();
17
- return {
18
- ImportDeclaration: importDeclarationListener,
19
- CallExpression(node) {
20
- if (detectZodSchemaRootNode(node)?.schemaType !== "number") return;
15
+ const { createSchemaVisitor, collectZodChainMethods } = zodImportScope.createTracker();
16
+ return createSchemaVisitor({
17
+ schemaType: "number",
18
+ onSchema(node, zodSchemaMeta) {
19
+ if (!getZodChainedMethodNames(zodSchemaMeta).includes("finite")) return;
21
20
  const methods = collectZodChainMethods(node);
22
- const finiteIndex = methods.findIndex((m) => m.name === "finite" && m.node === node);
23
- if (finiteIndex === -1) return;
21
+ const finiteIndex = methods.findIndex((m, index) => index > 0 && m.name === "finite");
24
22
  context.report({
25
23
  node,
26
24
  messageId: "removeFinite",
27
25
  fix(fixer) {
26
+ if (finiteIndex === -1) return null;
28
27
  return buildZodChainRemoveMethodFix({
29
28
  fixer,
30
29
  methods,
@@ -33,7 +32,7 @@ const noNumberSchemaWithFinite = createZodPluginRule({
33
32
  }
34
33
  });
35
34
  }
36
- };
35
+ });
37
36
  }
38
37
  });
39
38
  //#endregion
@@ -1,7 +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
3
  //#region src/rules/no-number-schema-with-int.ts
4
- const { trackZodSchemaImports } = (0, _eslint_zod_utils.createZodSchemaImportTrack)(_eslint_zod_utils.zodImportScope);
5
4
  const noNumberSchemaWithInt = require_create_plugin_rule.createZodPluginRule({
6
5
  name: "no-number-schema-with-int",
7
6
  meta: {
@@ -14,12 +13,10 @@ const noNumberSchemaWithInt = require_create_plugin_rule.createZodPluginRule({
14
13
  defaultOptions: [],
15
14
  create(context) {
16
15
  const { sourceCode } = context;
17
- const { importDeclarationListener, detectZodSchemaRootNode, collectZodChainMethods } = trackZodSchemaImports();
18
- return {
19
- ImportDeclaration: importDeclarationListener,
20
- CallExpression(node) {
21
- const zodSchemaMeta = detectZodSchemaRootNode(node);
22
- if (zodSchemaMeta?.schemaType !== "number") return;
16
+ const { createSchemaVisitor, collectZodChainMethods } = _eslint_zod_utils.zodImportScope.createTracker();
17
+ return createSchemaVisitor({
18
+ schemaType: "number",
19
+ onSchema(node, zodSchemaMeta) {
23
20
  const methods = collectZodChainMethods(node);
24
21
  const intIndex = methods.findIndex((m) => m.name === "int");
25
22
  if (intIndex === -1) return;
@@ -40,7 +37,7 @@ const noNumberSchemaWithInt = require_create_plugin_rule.createZodPluginRule({
40
37
  }
41
38
  });
42
39
  }
43
- };
40
+ });
44
41
  }
45
42
  });
46
43
  //#endregion
@@ -1,7 +1,6 @@
1
1
  import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
2
- import { buildZodChainReplacementFix, createZodSchemaImportTrack, zodImportScope } from "@eslint-zod/utils";
2
+ import { buildZodChainReplacementFix, zodImportScope } from "@eslint-zod/utils";
3
3
  //#region src/rules/no-number-schema-with-int.ts
4
- const { trackZodSchemaImports } = createZodSchemaImportTrack(zodImportScope);
5
4
  const noNumberSchemaWithInt = createZodPluginRule({
6
5
  name: "no-number-schema-with-int",
7
6
  meta: {
@@ -14,12 +13,10 @@ const noNumberSchemaWithInt = createZodPluginRule({
14
13
  defaultOptions: [],
15
14
  create(context) {
16
15
  const { sourceCode } = context;
17
- const { importDeclarationListener, detectZodSchemaRootNode, collectZodChainMethods } = trackZodSchemaImports();
18
- return {
19
- ImportDeclaration: importDeclarationListener,
20
- CallExpression(node) {
21
- const zodSchemaMeta = detectZodSchemaRootNode(node);
22
- if (zodSchemaMeta?.schemaType !== "number") return;
16
+ const { createSchemaVisitor, collectZodChainMethods } = zodImportScope.createTracker();
17
+ return createSchemaVisitor({
18
+ schemaType: "number",
19
+ onSchema(node, zodSchemaMeta) {
23
20
  const methods = collectZodChainMethods(node);
24
21
  const intIndex = methods.findIndex((m) => m.name === "int");
25
22
  if (intIndex === -1) return;
@@ -40,7 +37,7 @@ const noNumberSchemaWithInt = createZodPluginRule({
40
37
  }
41
38
  });
42
39
  }
43
- };
40
+ });
44
41
  }
45
42
  });
46
43
  //#endregion
@@ -1,8 +1,7 @@
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 _typescript_eslint_utils = require("@typescript-eslint/utils");
3
+ let _eslint_zod_utils_rule_patterns_deprecated_schema_property = require("@eslint-zod/utils/rule-patterns/deprecated-schema-property");
4
4
  //#region src/rules/no-number-schema-with-is-finite.ts
5
- const { trackZodSchemaImports } = (0, _eslint_zod_utils.createZodSchemaImportTrack)(_eslint_zod_utils.zodImportScope);
6
5
  const noNumberSchemaWithIsFinite = require_create_plugin_rule.createZodPluginRule({
7
6
  name: "no-number-schema-with-is-finite",
8
7
  meta: {
@@ -12,23 +11,12 @@ const noNumberSchemaWithIsFinite = require_create_plugin_rule.createZodPluginRul
12
11
  schema: []
13
12
  },
14
13
  defaultOptions: [],
15
- create(context) {
16
- const { importDeclarationListener, isZodNumberSchemaCallExpression } = trackZodSchemaImports();
17
- return {
18
- ImportDeclaration: importDeclarationListener,
19
- MemberExpression(node) {
20
- if (node.computed) return;
21
- if (node.property.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return;
22
- if (node.property.name !== "isFinite") return;
23
- if (node.object.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
24
- if (!isZodNumberSchemaCallExpression(node.object)) return;
25
- context.report({
26
- node,
27
- messageId: "deprecated"
28
- });
29
- }
30
- };
31
- }
14
+ create: (0, _eslint_zod_utils_rule_patterns_deprecated_schema_property.buildDeprecatedSchemaPropertyCreate)({
15
+ scope: _eslint_zod_utils.zodImportScope,
16
+ schemaType: "number",
17
+ propertyName: "isFinite",
18
+ messageId: "deprecated"
19
+ })
32
20
  });
33
21
  //#endregion
34
22
  exports.noNumberSchemaWithIsFinite = noNumberSchemaWithIsFinite;
@@ -1,8 +1,7 @@
1
1
  import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
2
- import { createZodSchemaImportTrack, zodImportScope } from "@eslint-zod/utils";
3
- import { AST_NODE_TYPES } from "@typescript-eslint/utils";
2
+ import { zodImportScope } from "@eslint-zod/utils";
3
+ import { buildDeprecatedSchemaPropertyCreate } from "@eslint-zod/utils/rule-patterns/deprecated-schema-property";
4
4
  //#region src/rules/no-number-schema-with-is-finite.ts
5
- const { trackZodSchemaImports } = createZodSchemaImportTrack(zodImportScope);
6
5
  const noNumberSchemaWithIsFinite = createZodPluginRule({
7
6
  name: "no-number-schema-with-is-finite",
8
7
  meta: {
@@ -12,23 +11,12 @@ const noNumberSchemaWithIsFinite = createZodPluginRule({
12
11
  schema: []
13
12
  },
14
13
  defaultOptions: [],
15
- create(context) {
16
- const { importDeclarationListener, isZodNumberSchemaCallExpression } = trackZodSchemaImports();
17
- return {
18
- ImportDeclaration: importDeclarationListener,
19
- MemberExpression(node) {
20
- if (node.computed) return;
21
- if (node.property.type !== AST_NODE_TYPES.Identifier) return;
22
- if (node.property.name !== "isFinite") return;
23
- if (node.object.type !== AST_NODE_TYPES.CallExpression) return;
24
- if (!isZodNumberSchemaCallExpression(node.object)) return;
25
- context.report({
26
- node,
27
- messageId: "deprecated"
28
- });
29
- }
30
- };
31
- }
14
+ create: buildDeprecatedSchemaPropertyCreate({
15
+ scope: zodImportScope,
16
+ schemaType: "number",
17
+ propertyName: "isFinite",
18
+ messageId: "deprecated"
19
+ })
32
20
  });
33
21
  //#endregion
34
22
  export { noNumberSchemaWithIsFinite };
@@ -1,8 +1,7 @@
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 _typescript_eslint_utils = require("@typescript-eslint/utils");
3
+ let _eslint_zod_utils_rule_patterns_deprecated_schema_property = require("@eslint-zod/utils/rule-patterns/deprecated-schema-property");
4
4
  //#region src/rules/no-number-schema-with-is-int.ts
5
- const { trackZodSchemaImports } = (0, _eslint_zod_utils.createZodSchemaImportTrack)(_eslint_zod_utils.zodImportScope);
6
5
  const noNumberSchemaWithIsInt = require_create_plugin_rule.createZodPluginRule({
7
6
  name: "no-number-schema-with-is-int",
8
7
  meta: {
@@ -12,23 +11,12 @@ const noNumberSchemaWithIsInt = require_create_plugin_rule.createZodPluginRule({
12
11
  schema: []
13
12
  },
14
13
  defaultOptions: [],
15
- create(context) {
16
- const { importDeclarationListener, isZodNumberSchemaCallExpression } = trackZodSchemaImports();
17
- return {
18
- ImportDeclaration: importDeclarationListener,
19
- MemberExpression(node) {
20
- if (node.computed) return;
21
- if (node.property.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return;
22
- if (node.property.name !== "isInt") return;
23
- if (node.object.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
24
- if (!isZodNumberSchemaCallExpression(node.object)) return;
25
- context.report({
26
- node,
27
- messageId: "useFormat"
28
- });
29
- }
30
- };
31
- }
14
+ create: (0, _eslint_zod_utils_rule_patterns_deprecated_schema_property.buildDeprecatedSchemaPropertyCreate)({
15
+ scope: _eslint_zod_utils.zodImportScope,
16
+ schemaType: "number",
17
+ propertyName: "isInt",
18
+ messageId: "useFormat"
19
+ })
32
20
  });
33
21
  //#endregion
34
22
  exports.noNumberSchemaWithIsInt = noNumberSchemaWithIsInt;