ben-eb/css-values

Implement property specific validation messages

Open

#26 建立於 2016年8月31日

在 GitHub 查看
 (3 留言) (0 反應) (0 負責人)JavaScript (3 fork)github user discovery
enhancementhelp wantedquestion

倉庫指標

Star
 (64 star)
PR 合併指標
 (PR 指標待抓取)

描述

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. 😄

貢獻者指南