angeloashmore / gatsby-plugin-local-search

Gatsby plugin for providing client-side search for data available in Gatsby's GraphQL layer using a variety of engines
MIT License
51 stars 29 forks source link

Use gatsby plugins options validation #40

Open jooola opened 3 years ago

jooola commented 3 years ago

Hey, I propose to setup the Gatsby plugin options validation tool in this plugin.

This will bring few things:

See an example in the gatsby wordpress plugin https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-wordpress/src/steps/declare-plugin-options-schema.ts

angeloashmore commented 3 years ago

Hey @jooola, this would be great! I'll leave this issue open for someone to submit a PR. Would you be interested in submitting one?

The types that we would want to validate can be seen here: https://github.com/angeloashmore/gatsby-plugin-local-search/blob/cb2ecab03f388dd2fa9a9359728a464d53dac9d4/src/types.ts#L32-L41

For the normalizer function, I don't think there's much we could do to validate besides checking that we're receiving a function of arity one. Calling the function to check its output wouldn't be ideal since the function could have side-effects (e.g. logging).