-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Now that 0.1.0 is out, I'd like to implement more specific validation messages. These should offer more insight into why the validator might yield a warning; here are some examples:
- isColor:
rgb(255, 255, 255, 1)- too many arguments, expected 3. - isColor:
rgb(255, 255)- too few arguments, expected 3. - isColor:
rgb(255, 255, 255,)- unexpected trailing comma. - isColor:
rgb(255 255 255)- expected arguments to be comma-separated.
Essentially what we have to do now is to break down the return conditions of the custom validators. Take isLength as an example. The return condition should be extracted into individual conditions that yield a message if the condition is failing. So, for example, the function checks that the value does not end with . - instead of a boolean test, we can return a message here instead:
if (!endsWith(int.number, '.')) {
return {
type: 'invalid',
message: 'At least one number should follow the decimal point.',
};
}Suggestions for types of messages to return would be very welcome, as well as pull requests that implement these new messages. 😄