prefer-module-level-schema
Declare a Zod schema at module scope when it closes over nothing in the enclosing function
Why
A schema created inside a function is rebuilt on each call. Module scope can enable reuse across callers; local schemas already support local type inference.
Fix
Move the closed schema declaration to module scope and reference it from the function.
Examples
import { z } from "zod";export function handle(raw: unknown) { const ZBody = z.object({ id: z.string(), name: z.string() }); return ZBody.parse(raw);}import { z } from "zod";const ZBody = z.object({ id: z.string(), name: z.string() });export function handle(raw: unknown) { return ZBody.parse(raw);}