ben-eb/css-values

Implement property specific validation messages

Open

#26 aperta il 31 ago 2016

Vedi su GitHub
 (3 commenti) (0 reazioni) (0 assegnatari)JavaScript (3 fork)github user discovery
enhancementhelp wantedquestion

Metriche repository

Star
 (64 star)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

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

Guida contributor