Fix zod imports with ast-grep namespace import rule
Applied ast-grep rule to convert named zod imports to namespace imports across the api-contract package for consistency. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
id: zod-namespace-import
|
||||||
|
snapshots:
|
||||||
|
? |
|
||||||
|
import { z } from "zod";
|
||||||
|
: fixed: |
|
||||||
|
import * as z from "zod"
|
||||||
|
labels:
|
||||||
|
- source: import { z } from "zod";
|
||||||
|
style: primary
|
||||||
|
start: 0
|
||||||
|
end: 24
|
||||||
|
? |
|
||||||
|
import { z, ZodError } from "zod";
|
||||||
|
: fixed: |
|
||||||
|
import * as z from "zod"
|
||||||
|
labels:
|
||||||
|
- source: import { z, ZodError } from "zod";
|
||||||
|
style: primary
|
||||||
|
start: 0
|
||||||
|
end: 34
|
||||||
13
.ast-grep/rule-tests/zod-namespace-import-test.yml
Normal file
13
.ast-grep/rule-tests/zod-namespace-import-test.yml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
id: zod-namespace-import
|
||||||
|
valid:
|
||||||
|
- |
|
||||||
|
import * as z from "zod";
|
||||||
|
- |
|
||||||
|
import * as z from "zod";
|
||||||
|
const schema = z.object({ name: z.string() });
|
||||||
|
|
||||||
|
invalid:
|
||||||
|
- |
|
||||||
|
import { z } from "zod";
|
||||||
|
- |
|
||||||
|
import { z, ZodError } from "zod";
|
||||||
11
.ast-grep/rules/zod-namespace-import.yml
Normal file
11
.ast-grep/rules/zod-namespace-import.yml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
id: zod-namespace-import
|
||||||
|
language: typescript
|
||||||
|
severity: error
|
||||||
|
message: Use namespace import for zod - `import * as z from "zod"` instead of named import
|
||||||
|
note: |
|
||||||
|
Named imports from zod (e.g., `import { z } from "zod"`) should be replaced
|
||||||
|
with namespace imports (`import * as z from "zod"`) for consistency and to
|
||||||
|
ensure all zod utilities are available under the `z` namespace.
|
||||||
|
rule:
|
||||||
|
pattern: import { $$$IMPORTS } from "zod"
|
||||||
|
fix: import * as z from "zod";
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { oc } from "@orpc/contract";
|
import { oc } from "@orpc/contract";
|
||||||
import { z } from "zod";
|
import * as z from "zod";
|
||||||
import {
|
import {
|
||||||
adminAddSiteInputSchema,
|
adminAddSiteInputSchema,
|
||||||
adminCreateOrgInputSchema,
|
adminCreateOrgInputSchema,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { z } from "zod";
|
import * as z from "zod";
|
||||||
import { emailSchema, slugSchema } from "./common.js";
|
import { emailSchema, slugSchema } from "./common.js";
|
||||||
import { orgRoleSchema } from "./org.js";
|
import { orgRoleSchema } from "./org.js";
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { z } from "zod";
|
import * as z from "zod";
|
||||||
import { emailSchema } from "./common.js";
|
import { emailSchema } from "./common.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import {
|
|||||||
isValidPhoneNumber,
|
isValidPhoneNumber,
|
||||||
parsePhoneNumberWithError,
|
parsePhoneNumberWithError,
|
||||||
} from "libphonenumber-js";
|
} from "libphonenumber-js";
|
||||||
import { z } from "zod";
|
import * as z from "zod";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Email schema - validates email format and transforms to lowercase
|
* Email schema - validates email format and transforms to lowercase
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { z } from "zod";
|
import * as z from "zod";
|
||||||
import { emailSchema, slugSchema } from "./common.js";
|
import { emailSchema, slugSchema } from "./common.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { z } from "zod";
|
import * as z from "zod";
|
||||||
import { phoneSchema } from "./common.js";
|
import { phoneSchema } from "./common.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
{
|
{
|
||||||
"extends": "@macalinao/tsconfig/tsconfig.base.json",
|
"extends": "@macalinao/tsconfig/tsconfig.base.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "./dist",
|
|
||||||
"rootDir": "./src",
|
|
||||||
"declaration": true,
|
|
||||||
"declarationMap": true,
|
|
||||||
"isolatedDeclarations": false
|
"isolatedDeclarations": false
|
||||||
},
|
}
|
||||||
"include": ["src/**/*"],
|
|
||||||
"exclude": ["node_modules", "dist"]
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user