Skip to content
Sarj Code Standards

prefer-zod-field-bounds

Declare a pure integer field range on its Zod field schema instead of an object refinement.

Why

An object-level refinement can hide one field's domain range from generated JSON Schema. A native field bound states the range beside the integer contract without a custom predicate.

Fix

Consider the equivalent min/gte/gt/max/lte/lt field constraint. Review error paths, issue codes and validation order before replacing the refinement; no automatic fix is offered.

Examples

Before — flagged A pure field range hidden in an object validator
src/count.ts
import { z } from "zod";
const CountSchema = z
.object({ value: z.number().int() })
.refine((row) => row.value >= 1);
After — preferred Keep the integer domain on its field
src/count.ts
import { z } from "zod";
const CountSchema = z.object({ value: z.number().int().min(1) });