no-numeric-search-param-coercion
Parse numeric URL search parameters with a schema instead of parseInt or Number.
Why
parseInt, parseFloat and Number accept a missing or malformed query value and return NaN or a truncated number (parseInt("10abc") is 10), which then reaches queries and pagination unchecked.
Fix
Parse the value with a schema that states the contract, for example z.coerce.number().int().positive().default(10).parse(params.get("page") ?? undefined).
Examples
export function page(params: URLSearchParams): number { return parseInt(params.get("page") ?? "1", 10);}declare const z: { coerce: { number(): { parse(value: unknown): number } } };export function page(params: URLSearchParams): number { return z.coerce.number().parse(params.get("page") ?? undefined);}