js-dxtools / webpack-validator

Validates your webpack config with Joi
MIT License
295 stars 29 forks source link

Swap schema and additional options or simplify otherwise? #73

Closed bebraw closed 8 years ago

bebraw commented 8 years ago

To set quiet now, you need to do something like this:

const validate = require('webpack-validator');
const schema = require('webpack-validator').schema;

...

module.exports = validate(config, schema, {
  quiet: true
});

Instead, it would be neater to make schema optional by swapping the last two parameter. Then we would get just:

const validate = require('webpack-validator');

...

module.exports = validate(config, {
  quiet: true
});

Or we could fold all this to an object:

const validate = require('webpack-validator');

...

module.exports = validate({
  config: config,
  quiet: true
});

This would be future proof (easy to add features).

The last option would be possible to implement in a backwards compatible way (check for config key).

What do you think?

jonathanglasmeyer commented 8 years ago

I'd probably go with first argument = config, second arg: options (including schema). I expect the majority of people to use it without options - in that case just wrapping the config object with a validate call seems most straight forward to me. I think lets go with a major version, but check if second arg is a joi schema, in that case give a deprecation warning, remove with version 3. I totally dig that pattern but I'm not 100 percent share if it's overkill for the scope of the library. Thoughts? (also cc @kentcdodds)

nyrosmith commented 8 years ago

Why do we need the schema Parameter at all? You can concat the existing schema or overwrite it

jonathanglasmeyer commented 8 years ago

To override the default schema. Without explicitly telling the function which schema to take it'll default to the presupplied one.

jonathanglasmeyer commented 8 years ago

Implemented in #81.