Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: validate plugin options with Yup #2878

Closed
slorber opened this issue Jun 4, 2020 · 2 comments
Closed

RFC: validate plugin options with Yup #2878

slorber opened this issue Jun 4, 2020 · 2 comments
Labels
proposal This issue is a proposal, usually non-trivial change

Comments

@slorber
Copy link
Collaborator

slorber commented Jun 4, 2020

💥 Proposal

The client-redirects plugin uses Yup to validate user inputs.

In case user options do not match what's expected by the plugin (and the TypeScript types), it fails fast with an actionable error message.

@lex111 mentioned here that this is not really consistent with the behavior of the other plugins that do not really validate the user options, and maybe we should revisit the development process of plugins to follow what has been done in the client redirects plugin.

I discussed this with @yangshun, and he liked the idea to validate user inputs early with Yup.

He proposed a validateOptions() plugin lifecycle, where the user could just provide a Yup schema.

We also need to think about "option normalization", ie the process of transforming partial user-provided options into a convenient option type (ie, often adding default values to "complete" the user object)


What do you think of this idea of generalizing user input validation everywhere?

@slorber slorber added proposal This issue is a proposal, usually non-trivial change status: needs triage This issue has not been triaged by maintainers labels Jun 4, 2020
@lex111
Copy link
Contributor

lex111 commented Jun 4, 2020

I completely agree with this, maybe we should draw up some guidelines for the development of plugins (and not only for them).

@slorber slorber added RFC and removed status: needs triage This issue has not been triaged by maintainers labels Jun 4, 2020
@slorber
Copy link
Collaborator Author

slorber commented Jun 4, 2020

It could also help validate the site config.

For example, during a v1->v2 migration, I got bitten by migrating incorrectly the headerLinks to the new format. The site did work but the links didn't appear anywhere because i forgot to add position left/right. That could be prevented with validation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue is a proposal, usually non-trivial change
Projects
None yet
Development

No branches or pull requests

2 participants