-
Notifications
You must be signed in to change notification settings - Fork 742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: deprecate the use doT.js for messages #1938
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9ad8c62
feat: dont use doT.js for messages
straker 31448da
fix test
straker fc4e10c
const
straker 760ad1e
conditional dot based on message
straker d541b47
fix test
straker c239d1e
test
straker 58cc8ea
more fixes
straker f388798
revert ja
straker 6c24f51
use messageKey to determine object message
straker d1bdac3
Merge branch 'develop' into noDot
straker bf267df
add docs
straker File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# Check Message Template | ||
|
||
Axe-core uses a custom template to handle dynamic check messages (messages that use the `data` property to output values or to determine which message to display). The structure for the messages is as follows: | ||
|
||
## Simple Message | ||
|
||
A simple message is just a string that doesn't use the `data` property. Most checks uses this format. | ||
|
||
```json | ||
{ | ||
"messages": { | ||
"pass": "Simple message for a passing check" | ||
} | ||
} | ||
``` | ||
|
||
## Message with Data | ||
|
||
A message can also use the `data` property to output information from the check. If `data` is a String, Boolean, or Number, you can use the syntax `${data}` to have the message output the value of the `data` property. | ||
|
||
```js | ||
// check.js | ||
this.data(10); | ||
|
||
// check.json | ||
{ | ||
"messages": { | ||
"pass": "Passed with a value of ${data}" | ||
// => "Passed with a value of 10" | ||
} | ||
} | ||
``` | ||
|
||
If `data` is an object, you can access properties of the object using the syntax `${data.propName}`. | ||
|
||
```js | ||
// check.js | ||
this.data({ | ||
contrast: '3:1', | ||
fontSize: '12px' | ||
}); | ||
|
||
// check.json | ||
{ | ||
"messages": { | ||
"fail": "Color-contrast failed with a contrast of ${data.contrast} and font size of ${data.fontSize}" | ||
// => "Color-contrast failed with a contrast of 3:1 and font size of 12px" | ||
} | ||
} | ||
``` | ||
|
||
## Singular and Plural Messages | ||
|
||
If the message needs to to know how many items are in the `data` property to determine the type of language to use (singular or plural), you can structure the message to use `singular` and `plural` properties. Use the syntax `${data.values}` to have the message output a comma-separated list of the items (`data.values` is provided by the template code for you). | ||
|
||
```js | ||
// check.js | ||
this.data(['item1', 'item2']); | ||
|
||
// check.json | ||
{ | ||
"messages": { | ||
"fail": { | ||
"singular": "Attribute ${data.values} is not allowed", | ||
"plural": "Attributes: ${data.values} are not allowed" | ||
} | ||
// => Attributes: item1, item2 are not allowed | ||
} | ||
} | ||
``` | ||
|
||
## Message Determined by Data | ||
|
||
Lastly, a message can use the `data` property to determine which message to display. Structure the message to use properties whose keys are the possible values of `data.messageKey`. You should also provide a `default` message that will be displayed if `messageKey` is not set. | ||
|
||
```js | ||
// check.js | ||
this.data({ | ||
messageKey: 'imgNode' | ||
}); | ||
|
||
// check.json | ||
{ | ||
"messages": { | ||
"incomplete": { | ||
"default": "Color-contrast could not be determined" | ||
"bgImage": "Element's background color could not be determined due to a background image", | ||
"imgNode": "Element's background color could not be determined because element contains an image node" | ||
} | ||
// => Element's background color could not be determined because element contains an image node | ||
} | ||
} | ||
``` | ||
|
||
The messages can still use the syntax `${data.propName}` to access other properties on the `data` property. | ||
|
||
## Migrating From doT.js Template in Translations | ||
|
||
Axe-core use to use doT.js for it's temple library. To migrate from doT.js in a translation file, do the following: | ||
|
||
- If the message used `{{=it.data}}` or `{{=it.data.propName}}`, change the message to use the syntax `${data}` or `${data.propName}`. | ||
|
||
```diff | ||
{ | ||
"messages": { | ||
- "incomplete": "Check that the <label> does not need be part of the ARIA {{=it.data}} field's name" | ||
+ "incomplete": "Check that the <label> does not need be part of the ARIA ${data} field's name" | ||
} | ||
} | ||
``` | ||
|
||
- If the message used `{{=it.data && it.data.length` to determine using singular or plural language, change the message structure of the message to instead use the `singular` and `plural` properties. Replace `{{=it.data.join(', ')}}` with `${data.values}`. | ||
|
||
```diff | ||
{ | ||
"messages": { | ||
- "fail": "Attribute{{=it.data && it.data.length > 1 ? 's' : ''}} {{=it.data.join(', ')}} {{=it.data && it.data.length > 1 ? 'are' : ' is'}} not allowed | ||
+ "fail": { | ||
+ "singular": "Attribute ${data.values} is not allowed", | ||
+ "plural": "Attributes: ${data.values} are not allowed" | ||
+ } | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,10 @@ | |
"impact": "critical", | ||
"messages": { | ||
"pass": "ARIA attributes are used correctly for the defined role", | ||
"fail": "ARIA attribute{{=it.data && it.data.length > 1 ? 's are' : ' is'}} not allowed:{{~it.data:value}} {{=value}}{{~}}" | ||
"fail": { | ||
"singular": "ARIA attribute is not allowed: ${data.values}", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is 1,000,000x easier to read/follow ❤️ |
||
"plural": "ARIA attributes are not allowed: ${data.values}" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think I'm familiar with a
.+?
in regex, what does that do?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
?
makes the.+
not greedy. So instead of{{foo bar}} {{foo}}
matching the entire string, it will stop at the first set of}}
so you get 2 matches. Not that it really matters in this case but I'm use to making things not greedy.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh, didn't know that. Cool