eslint-plugin-zod-mini 1.0.1 → 1.0.2

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.
@@ -1,7 +1,6 @@
1
1
  require("../_virtual/_rolldown/runtime.cjs");
2
2
  const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
3
3
  let _eslint_zod_utils = require("@eslint-zod/utils");
4
- let _typescript_eslint_utils = require("@typescript-eslint/utils");
5
4
  //#region src/rules/prefer-meta.ts
6
5
  const { trackZodSchemaImports } = (0, _eslint_zod_utils.createZodSchemaImportTrack)(_eslint_zod_utils.zodMiniImportScope);
7
6
  const preferMeta = require_create_plugin_rule.createZodMiniPluginRule({
@@ -15,25 +14,21 @@ const preferMeta = require_create_plugin_rule.createZodMiniPluginRule({
15
14
  },
16
15
  defaultOptions: [],
17
16
  create(context) {
18
- const { importDeclarationListener, isZodNamespace, getNamedImportOriginal } = trackZodSchemaImports();
17
+ const { importDeclarationListener, detectZodSchemaRootNode } = trackZodSchemaImports();
19
18
  return {
20
19
  ImportDeclaration: importDeclarationListener,
21
20
  CallExpression(node) {
22
- const { callee } = node;
23
- if (callee.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression && callee.property.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && callee.property.name === "describe" && callee.object.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && isZodNamespace(callee.object.name)) {
24
- const [describeArg] = node.arguments;
25
- context.report({
26
- node,
27
- messageId: "preferMeta",
28
- fix(fixer) {
29
- return [fixer.replaceText(callee.property, "meta"), fixer.replaceText(describeArg, `{ description: ${context.sourceCode.getText(describeArg)} }`)];
30
- }
31
- });
32
- return;
33
- }
34
- if (callee.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && getNamedImportOriginal(callee.name) === "describe") context.report({
21
+ const zodSchemaMeta = detectZodSchemaRootNode(node);
22
+ if (zodSchemaMeta?.schemaType !== "describe") return;
23
+ context.report({
35
24
  node,
36
- messageId: "preferMeta"
25
+ messageId: "preferMeta",
26
+ fix(fixer) {
27
+ if (zodSchemaMeta.schemaDecl === "named") return null;
28
+ const { callee } = node;
29
+ const [describeArg] = node.arguments;
30
+ return [fixer.replaceText(callee.property, "meta"), fixer.replaceText(describeArg, `{ description: ${context.sourceCode.getText(describeArg)} }`)];
31
+ }
37
32
  });
38
33
  }
39
34
  };
@@ -1,6 +1,5 @@
1
1
  import { createZodMiniPluginRule } from "../utils/create-plugin-rule.mjs";
2
2
  import { createZodSchemaImportTrack, zodMiniImportScope } from "@eslint-zod/utils";
3
- import { AST_NODE_TYPES } from "@typescript-eslint/utils";
4
3
  //#region src/rules/prefer-meta.ts
5
4
  const { trackZodSchemaImports } = createZodSchemaImportTrack(zodMiniImportScope);
6
5
  const preferMeta = createZodMiniPluginRule({
@@ -14,25 +13,21 @@ const preferMeta = createZodMiniPluginRule({
14
13
  },
15
14
  defaultOptions: [],
16
15
  create(context) {
17
- const { importDeclarationListener, isZodNamespace, getNamedImportOriginal } = trackZodSchemaImports();
16
+ const { importDeclarationListener, detectZodSchemaRootNode } = trackZodSchemaImports();
18
17
  return {
19
18
  ImportDeclaration: importDeclarationListener,
20
19
  CallExpression(node) {
21
- const { callee } = node;
22
- if (callee.type === AST_NODE_TYPES.MemberExpression && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "describe" && callee.object.type === AST_NODE_TYPES.Identifier && isZodNamespace(callee.object.name)) {
23
- const [describeArg] = node.arguments;
24
- context.report({
25
- node,
26
- messageId: "preferMeta",
27
- fix(fixer) {
28
- return [fixer.replaceText(callee.property, "meta"), fixer.replaceText(describeArg, `{ description: ${context.sourceCode.getText(describeArg)} }`)];
29
- }
30
- });
31
- return;
32
- }
33
- if (callee.type === AST_NODE_TYPES.Identifier && getNamedImportOriginal(callee.name) === "describe") context.report({
20
+ const zodSchemaMeta = detectZodSchemaRootNode(node);
21
+ if (zodSchemaMeta?.schemaType !== "describe") return;
22
+ context.report({
34
23
  node,
35
- messageId: "preferMeta"
24
+ messageId: "preferMeta",
25
+ fix(fixer) {
26
+ if (zodSchemaMeta.schemaDecl === "named") return null;
27
+ const { callee } = node;
28
+ const [describeArg] = node.arguments;
29
+ return [fixer.replaceText(callee.property, "meta"), fixer.replaceText(describeArg, `{ description: ${context.sourceCode.getText(describeArg)} }`)];
30
+ }
36
31
  });
37
32
  }
38
33
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-zod-mini",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "ESLint plugin that adds custom linting rules to enforce best practices when using Zod Mini",
5
5
  "keywords": [
6
6
  "eslint",
@@ -40,7 +40,7 @@
40
40
  "dependencies": {
41
41
  "@typescript-eslint/utils": "^8.57.0",
42
42
  "esquery": "^1.6.0",
43
- "@eslint-zod/utils": "1.0.1"
43
+ "@eslint-zod/utils": "1.1.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@marcalexiei/prettier-config": "1.1.4",