-
Notifications
You must be signed in to change notification settings - Fork 771
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(rule): xml-lang-mismatch #999
Merged
WilcoFiers
merged 14 commits into
develop
from
new-rule-wcag20-xml-lang-mismatch-issue-558
Aug 16, 2018
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
04022cb
feat: rule xml-lang-mismatch on body and child nodes
jeeyyy 4120f3c
test: add integration tests
jeeyyy f0ea8ff
Merge branch 'develop' into new-rule-wcag20-xml-lang-mismatch-issue-558
jeeyyy 3541c90
fix: update rule for checking lang and xml:lang on html element
jeeyyy 05e3544
Merge branch 'develop' into new-rule-wcag20-xml-lang-mismatch-issue-558
jeeyyy c909c50
Merge branch 'develop' into new-rule-wcag20-xml-lang-mismatch-issue-558
WilcoFiers 30fcefc
fix: refactor based on review
jeeyyy 0d471c8
doc: update rule description
jeeyyy 1c50f83
test: refactor and add more integration tests
jeeyyy 76b9515
refactor: rename rule id
jeeyyy 8cb1aab
Merge branch 'develop' into new-rule-wcag20-xml-lang-mismatch-issue-558
jeeyyy fbf6a54
fix: refactor based on review
jeeyyy 57c66b7
Merge branch 'develop' into new-rule-wcag20-xml-lang-mismatch-issue-558
jeeyyy 31e37e9
Merge branch 'develop' into new-rule-wcag20-xml-lang-mismatch-issue-558
WilcoFiers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: refactor based on review
- Loading branch information
commit 30fcefc6b8224bc5f1a99ea687b31ef2e5032311
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,5 @@ | ||
// construct array of language sub values specified for either lang and xml:lang attributes | ||
let langSubTagsToValidate = []; | ||
const { getBaseLang } = axe.commons.utils; | ||
const primaryLangValue = getBaseLang(node.getAttribute('lang') || ''); | ||
const primaryXmlLangValue = getBaseLang(node.getAttribute('xml:lang') || ''); | ||
|
||
// get value of lang attribute | ||
const langValue = node.getAttribute('lang'); | ||
// if no lang is specified, can't compute mismatch - return false | ||
if (!langValue) { | ||
return false; | ||
} | ||
langSubTagsToValidate.push(axe.utils.getBaseLang(langValue)); | ||
|
||
// get value of xml:lang attribute | ||
const xmlLangValue = node.getAttribute('xml:lang'); | ||
// if no xml:lang is specified, can't compute mismatch - return false | ||
if (!xmlLangValue) { | ||
return false; | ||
} | ||
langSubTagsToValidate.push(axe.utils.getBaseLang(langValue)); | ||
|
||
// unique the produced array, if identical primary subtag values were supplied, this would result in an array of length 1. | ||
// eg: if lang='en-GB' and xml:lang='en-US', the below will produce langSubTagsToValidate = ['en'] | ||
langSubTagsToValidate = axe.utils.uniqueArray(langSubTagsToValidate, []); | ||
|
||
// if the length of this array > 1 - the specified values for lang and xml:lang were different | ||
// eg: lang='en-GB' and xml:lang='fr-FR' will yeild langSubTagsToValidate = ['en', 'fr'] | ||
if (langSubTagsToValidate.length > 1) { | ||
return false; | ||
} | ||
|
||
// ensure that the lang subtag value is valid | ||
const isValid = axe.utils.validLangs().includes(langSubTagsToValidate[0]); | ||
|
||
// return | ||
return isValid; | ||
return primaryLangValue === primaryXmlLangValue; | ||
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 |
---|---|---|
@@ -1,14 +1,15 @@ | ||
{ | ||
"id": "xml-lang-mismatch", | ||
"selector": "html[lang][xml\\:lang]", | ||
"matches": "xml-lang-mismatch-matches.js", | ||
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. We could simplify the matches by offloading some of the work to the selector: |
||
"tags": [ | ||
"cat.language", | ||
"wcag2a", | ||
"wcag311" | ||
], | ||
"metadata": { | ||
"description": "Ensures that for the html element, there is no mismatch between the primary language in non-empty lang and xml:lang attributes, if both are used", | ||
"help": "The value of the primary language subtag for the lang and xml:lang attributes should be the same for the html element" | ||
"description": "Ensure that HTML elements with both valid lang and xml:lang attributes agree on the base language of the page", | ||
"help": "HTML elements with lang and xml:lang must have the same base language" | ||
}, | ||
"all": [ | ||
"xml-lang-mismatch" | ||
|
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.
This could be the cleanest looking check we've got. Great job Jey.