kentcdodds / webpack-validator-DEPRECATED

Use this to save yourself some time when working on a webpack configuration.
MIT License
93 stars 8 forks source link

[idea] - Use property-validator #2

Closed nettofarah closed 8 years ago

nettofarah commented 8 years ago

hey, @kentcdodds. This project sounds like an awesome idea.

I recently built a library that helps with property validation in javascript objects. (https://github.com/nettofarah/property-validator) Maybe we could use it validate the webpack config options?

Here's an idea of how it could look like:

import { validate, assert, optional, presence, isArray } from 'property-validator'

const validationResult  = validate(webpackConfig, [
  presence('entry'),
  optional(isArray('resolve.root')),
  isArray('resolve.alias')
 ...
])

or use assert

this would raise a ValidationError (my preferred option)

assert(webpackConfig, [ ... ])

validation functions are all stateless and are super easy to extend.

All you need to do is to create a function with this signature:

function(paramName) {
  return function(params) {
     return { valid: true, message: 'bla' }
  }
}
nettofarah commented 8 years ago

Let me know if you think this makes sense.

kentcdodds commented 8 years ago

I actually have built my own version of this as well (api-check) and I considered using joi. And there's nothing stopping us from using these for this project. However, I don't think that it's necessary to require it for every validator. I like the API that I've created for defining validators and I don't see a reason to change it to this (still open to talk about changes).

So I think we'll stick with the library agnostic approach for now. You might consider writing a wrapper that converts your validator's output to this tool's format.

Thanks for the idea and the interest!

nettofarah commented 8 years ago

Sure! No problem.

This is a super interesting idea, so yeah. I should send some PRs and ideas your way soon.