Skip to content

feat: zodResolver reads a schema declared inside the component - #19

Closed
mertcanaltin wants to merge 3 commits into
feat/zod-refinefrom
feat/zod-local-const
Closed

mertcanaltin wants to merge 3 commits into
feat/zod-refinefrom
feat/zod-local-const

Conversation

@mertcanaltin

Copy link
Copy Markdown
Member

Stacked on #18; the diff here is the one commit on top of it.

A schema declared inside the component (const formSchema = z.object({ ... }) in the function body) was not read: only a constant at the top of the file was. In the corpus that was 12 of 156 calls. It is read now where the file declares that name once and the schema is made of zod and constants alone, the same rule as at the top of the file. The declaration is removed with the call replaced, as before.

One built from a prop or a translation function (z.string().min(2, t('short'))) is still not read, and the scan says which name stopped it.

Reach on the corpus (each file alone in a directory): 57 before, 62 after. Of the 94 left: 64 import the schema from a module the one-file setup does not have, 8 have a function that is not carried (a message function, superRefine, a transform), 5 use url, 4 use a value from outside, and 13 others.

Tests: a build with one schema of each kind inside two functions, the pure one replaced and held to zodResolver, the one that calls t() kept; the scan test's reason for a schema that uses a parameter. npm test: 267 tests, 265 pass, 2 skipped.

Not covered: let and var, a destructured declaration, and a name the file declares twice are not read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant