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

Allow plugins to validate their options #112

Merged
merged 5 commits into from
May 7, 2021

Conversation

edsrzf
Copy link
Collaborator

@edsrzf edsrzf commented Apr 28, 2021

This introduces a new validate method to the Plugin interface so that plugins can validate their options. It also implements validate for all plugins that have options. It also adds a PluginOptionsError type to ts-migrate-server which should be thrown when validation fails.

The motivation was originally described in #74, where I proposed a configuration file format. One consequence to a configuration format is that plugins will need to be more defensive about validating their options.

Internally the validation is implemented using JSON schema, with additional JS validation where JSON schema is not expressive enough (only the member-accessibility plugin, currently).

@Rudeg
Copy link
Contributor

Rudeg commented Apr 29, 2021

Thanks for working on this!

The interface additions, including details on names and such:

  • The validate method and signature.
  • The PluginOptionsError class.

Lgtm, small nit comment about default error message.

Any thoughts on JSON schema or the json-schema package in particular

Usage of json-schema makes sense to me.

Would it make more sense to go all-in on JSON schema and expose an optionsSchema instead of the validate method? (I noticed that @typescript-eslint does this in its plugins. For example) Consider though JSON schema by itself is not expressive enough to validate the regex strings that member-accessibility accepts. Or maybe I've gone overboard with the regex validation.

With current state of the options - validate method is fine imo.

@edsrzf edsrzf force-pushed the plugin-validate branch from 14e037a to 1dc8e69 Compare May 2, 2021 02:34
@edsrzf edsrzf force-pushed the plugin-validate branch from 1dc8e69 to bc54fbe Compare May 2, 2021 02:39
@edsrzf edsrzf force-pushed the plugin-validate branch from bc54fbe to 6319866 Compare May 2, 2021 02:50
@edsrzf edsrzf marked this pull request as ready for review May 2, 2021 02:56
@edsrzf edsrzf requested a review from Rudeg May 5, 2021 06:31
@Rudeg
Copy link
Contributor

Rudeg commented May 7, 2021

@edsrzf sorry for the delay, lgtm!

@edsrzf edsrzf merged commit 45933b8 into airbnb:master May 7, 2021
@edsrzf edsrzf deleted the plugin-validate branch May 7, 2021 10:54
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.

2 participants