Implement property specific validation messages
- Dominant language
- JavaScript
- Stars
- 64
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
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`](https://github.com/ben-eb/css-values/blob/de4168a0fef9c23f2c38e07b4c5c8d82b56dfacc/src/validators/isLength.js) 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:
``` js
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. 😄
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.