Skip to content

prefer-shared-zod-enum

Give repeated literal Zod enum domains one reusable module-level schema.

Why

Repeated literal domains hide a shared contract and allow equivalent fields to drift independently.

Fix

Declare a module-level named Zod enum schema and reuse it at each field or contract site.

Examples

Before — flagged Do not repeat an inline enum domain
src/provider.ts
import { z } from "zod";
const JobSchema = z.object({ provider: z.enum(["agy", "claude", "sol"]) });
const StatusSchema = z.object({
provider: z.enum(["agy", "claude", "sol"]).optional(),
});
After — preferred Reuse a named enum schema
src/provider.ts
import { z } from "zod";
const ProviderSchema = z.enum(["agy", "claude", "sol"]);
const JobSchema = z.object({ provider: ProviderSchema });
const StatusSchema = z.object({ provider: ProviderSchema.optional() });