-
-
Notifications
You must be signed in to change notification settings - Fork 411
Open
Labels
bugtypesIssues that happen in TypeScript or that require typesIssues that happen in TypeScript or that require types
Description
Describe the bug
The rule unicorn/prefer-top-level-await
reports a false positive when using z.catch
from Zod Mini (https://github.com/colinhacks/zod). Example code:
const paramsSchema = z.catch(
z.object({
q: z.optional(z.string()),
page: z._default(z.coerce.number(), 1),
}),
{
q: undefined,
page: 1,
}
);
This triggers the error:
Prefer top-level await over using a promise chain. (unicorn/prefer-top-level-await)
However, z.catch
is not a promise chain or async code, but a schema utility from Zod. This is a false positive.
To Reproduce
- Use Zod Mini's
z.catch
in a file witheslint-plugin-unicorn
enabled. - Observe the false positive error from
unicorn/prefer-top-level-await
.
Expected behavior
No error should be reported for this usage, as it is not related to promises or async code.
Environment
- zod: ^3.25.67
- eslint: ^9.29.0
- eslint-plugin-unicorn: ^59.0.1
- Node.js: 22.16.0
akodkod
Metadata
Metadata
Assignees
Labels
bugtypesIssues that happen in TypeScript or that require typesIssues that happen in TypeScript or that require types