eslint-plugin-zod 4.9.0 → 4.9.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 (41) hide show
  1. package/dist/rules/array-style.cjs +37 -46
  2. package/dist/rules/array-style.mjs +38 -47
  3. package/dist/rules/no-native-enum.cjs +7 -10
  4. package/dist/rules/no-native-enum.mjs +8 -11
  5. package/dist/rules/no-number-schema-with-finite.cjs +8 -9
  6. package/dist/rules/no-number-schema-with-finite.mjs +9 -10
  7. package/dist/rules/no-number-schema-with-int.cjs +5 -8
  8. package/dist/rules/no-number-schema-with-int.mjs +6 -9
  9. package/dist/rules/no-number-schema-with-is-finite.cjs +7 -19
  10. package/dist/rules/no-number-schema-with-is-finite.mjs +8 -20
  11. package/dist/rules/no-number-schema-with-is-int.cjs +7 -19
  12. package/dist/rules/no-number-schema-with-is-int.mjs +8 -20
  13. package/dist/rules/no-number-schema-with-safe.cjs +9 -13
  14. package/dist/rules/no-number-schema-with-safe.mjs +10 -14
  15. package/dist/rules/no-number-schema-with-step.cjs +10 -14
  16. package/dist/rules/no-number-schema-with-step.mjs +11 -15
  17. package/dist/rules/no-optional-and-default-together.cjs +23 -28
  18. package/dist/rules/no-optional-and-default-together.mjs +24 -29
  19. package/dist/rules/no-promise-schema.cjs +5 -7
  20. package/dist/rules/no-promise-schema.mjs +6 -8
  21. package/dist/rules/no-schema-with-is-nullable.cjs +6 -19
  22. package/dist/rules/no-schema-with-is-nullable.mjs +7 -20
  23. package/dist/rules/no-schema-with-is-optional.cjs +6 -19
  24. package/dist/rules/no-schema-with-is-optional.mjs +7 -20
  25. package/dist/rules/no-string-schema-with-uuid.cjs +5 -8
  26. package/dist/rules/no-string-schema-with-uuid.mjs +6 -9
  27. package/dist/rules/prefer-loose-object.cjs +8 -32
  28. package/dist/rules/prefer-loose-object.mjs +9 -33
  29. package/dist/rules/prefer-meta-last.cjs +23 -28
  30. package/dist/rules/prefer-meta-last.mjs +24 -29
  31. package/dist/rules/prefer-meta.cjs +13 -19
  32. package/dist/rules/prefer-meta.mjs +14 -20
  33. package/dist/rules/prefer-strict-object.cjs +8 -32
  34. package/dist/rules/prefer-strict-object.mjs +9 -33
  35. package/dist/rules/prefer-string-schema-with-trim.cjs +11 -14
  36. package/dist/rules/prefer-string-schema-with-trim.mjs +12 -15
  37. package/dist/rules/prefer-top-level-string-formats.cjs +12 -123
  38. package/dist/rules/prefer-top-level-string-formats.mjs +14 -124
  39. package/dist/rules/prefer-trim-before-string-length-checks.cjs +8 -11
  40. package/dist/rules/prefer-trim-before-string-length-checks.mjs +9 -12
  41. package/package.json +7 -7
@@ -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
@@ -2,7 +2,6 @@ const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
2
2
  let _eslint_zod_utils = require("@eslint-zod/utils");
3
3
  let _typescript_eslint_utils = require("@typescript-eslint/utils");
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: {
@@ -14,23 +13,21 @@ const noNativeEnum = require_create_plugin_rule.createZodPluginRule({
14
13
  },
15
14
  defaultOptions: [],
16
15
  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);
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;
24
21
  context.report({
25
22
  node,
26
23
  messageId: "useEnum",
27
24
  fix(fixer) {
28
- if (rootMethodNode.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return null;
25
+ if (rootMethodNode?.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return null;
29
26
  return fixer.replaceText(rootMethodNode.callee.property, "enum");
30
27
  }
31
28
  });
32
29
  }
33
- };
30
+ });
34
31
  }
35
32
  });
36
33
  //#endregion
@@ -1,8 +1,7 @@
1
1
  import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
2
- import { createZodSchemaImportTrack, zodImportScope } from "@eslint-zod/utils";
2
+ import { zodImportScope } from "@eslint-zod/utils";
3
3
  import { AST_NODE_TYPES } from "@typescript-eslint/utils";
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: {
@@ -14,23 +13,21 @@ const noNativeEnum = createZodPluginRule({
14
13
  },
15
14
  defaultOptions: [],
16
15
  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);
16
+ const { createSchemaVisitor, collectZodChainMethods } = zodImportScope.createTracker();
17
+ return createSchemaVisitor({
18
+ schemaType: "nativeEnum",
19
+ onSchema(node) {
20
+ const rootMethodNode = collectZodChainMethods(node).at(0)?.node;
24
21
  context.report({
25
22
  node,
26
23
  messageId: "useEnum",
27
24
  fix(fixer) {
28
- if (rootMethodNode.callee.type !== AST_NODE_TYPES.MemberExpression) return null;
25
+ if (rootMethodNode?.callee.type !== AST_NODE_TYPES.MemberExpression) return null;
29
26
  return fixer.replaceText(rootMethodNode.callee.property, "enum");
30
27
  }
31
28
  });
32
29
  }
33
- };
30
+ });
34
31
  }
35
32
  });
36
33
  //#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-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;
@@ -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-int.ts
5
- const { trackZodSchemaImports } = createZodSchemaImportTrack(zodImportScope);
6
5
  const noNumberSchemaWithIsInt = createZodPluginRule({
7
6
  name: "no-number-schema-with-is-int",
8
7
  meta: {
@@ -12,23 +11,12 @@ const noNumberSchemaWithIsInt = 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 !== "isInt") return;
23
- if (node.object.type !== 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: buildDeprecatedSchemaPropertyCreate({
15
+ scope: zodImportScope,
16
+ schemaType: "number",
17
+ propertyName: "isInt",
18
+ messageId: "useFormat"
19
+ })
32
20
  });
33
21
  //#endregion
34
22
  export { noNumberSchemaWithIsInt };