bradwestfall / house-rules

Highly re-usable field/input validators
MIT License
10 stars 1 forks source link

Passing values to `validate` should output warnings when not part of the schema #2

Open iamvanja opened 7 years ago

iamvanja commented 7 years ago

Consider

const schema = new Schema({
  id: Is.numeric().positive().integer().required(),
  name: Is.string().ascii().required()
})

and then validating

schema.validate({
  id: 123,
  name: 'John',
  email: 'not.an.email'
})

This validation returns no errors. Which it should not since email is not defined in the schema and by that virtue, email is an optional, free-text value, but I think there are real-time situations where rules could be forgotten to be passed into the schema with potentially serious consequences. This also applies for schema.clone.

Shouldn't validate in this case output a warning about email not being part of the schema?

Perhaps new Schema, schema.clone and/or validate method could take an optional second argument as a configuration object where the option for this would be something like suppressWarnings: false?