Skip to content

Commit

Permalink
chore: Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoFiers committed May 17, 2021
1 parent 8feda5d commit 6c9bc79
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 27 deletions.
17 changes: 8 additions & 9 deletions lib/checks/aria/aria-prohibited-attr-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ import standards from '../../standards';
*/
function ariaProhibitedAttrEvaluate(node, options = {}, virtualNode) {
const { elementsAllowedAriaLabel = [] } = options;
const attrBlacklist = getAttrBlacklist(virtualNode, elementsAllowedAriaLabel);
if (!attrBlacklist) {
return false;
}
const prohibitedList = listProhibitedAttrs(virtualNode, elementsAllowedAriaLabel);

const prohibited = virtualNode.attrNames.filter(attrName => {
const attrValue = sanitize(virtualNode.attr(attrName));
return attrBlacklist.includes(attrName) && attrValue !== ''
})
const prohibited = prohibitedList.filter(attrName => {
if (!virtualNode.attrNames.includes(attrName)) {
return false;
}
return sanitize(virtualNode.attr(attrName)) !== ''
});

if (prohibited.length === 0) {
return false;
Expand All @@ -48,7 +47,7 @@ function ariaProhibitedAttrEvaluate(node, options = {}, virtualNode) {
return hasTextContent ? undefined : true;
}

function getAttrBlacklist(virtualNode, elementsAllowedAriaLabel) {
function listProhibitedAttrs(virtualNode, elementsAllowedAriaLabel) {
const role = getRole(virtualNode);
const roleSpec = standards.ariaRoles[role]
if (roleSpec) {
Expand Down
1 change: 0 additions & 1 deletion lib/checks/aria/aria-prohibited-attr.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"label",
"meter",
"object",
"span",
"svg",
"video"
]
Expand Down
4 changes: 2 additions & 2 deletions test/checks/aria/aria-prohibited-attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ describe('aria-prohibited-attr', function() {
assert.isFalse(checkEvaluate.apply(checkContext, params));
});

it('should allow whitelisted nodes to have aria-label', function () {
it('should allow `elementsAllowedAriaLabel` nodes to have aria-label', function () {
var params = checkSetup(
'<div id="target" aria-label="hello world"></div>',
{ elementsAllowedAriaLabel: ['div'] }
);
assert.isFalse(checkEvaluate.apply(checkContext, params));
});

it('should not allow whitelisted nodes with a prohibited role', function () {
it('should not allow `elementsAllowedAriaLabel` nodes with a prohibited role', function () {
var params = checkSetup(
'<div id="target" role="code" aria-label="hello world"></div>',
{ elementsAllowedAriaLabel: ['div'] }
Expand Down
2 changes: 1 addition & 1 deletion test/integration/rules/aria-allowed-attr/failures.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<div aria-label="value" id="fail23"></div>
<div aria-labelledby="value" id="fail24"></div>
<!-- technically presentation and none roles do not allow aria-label and aria-labelledby, but since those are global attributes the presentation role conflict will not resolve the roles to none or presentation -->
<em aria-label="value" id="fail25"></em>
<span aria-label="value" id="fail25"></span>
<strong aria-label="value" id="fail26"></strong>
<kbd aria-label="value" id="fail27"></kbd>
<abbr aria-label="value" id="fail28"></abbr>
Expand Down
23 changes: 11 additions & 12 deletions test/integration/rules/aria-allowed-attr/passes.html
Original file line number Diff line number Diff line change
Expand Up @@ -1910,15 +1910,14 @@
<div id="pass80" aria-labelledby=" ">Foo</div>

<audio aria-label="value" id="pass81" controls></audio>
<applet aria-label="value" id="pass83"></applet>
<canvas aria-label="value" id="pass84"></canvas>
<dl aria-label="value" id="pass85"></dl>
<embed aria-label="value" id="pass86"></embed>
<iframe aria-label="value" id="pass87" src="blank.html"></iframe>
<input aria-label="value" id="pass88"/>
<label aria-label="value" id="pass89"></label>
<meter aria-label="value" id="pass90"></meter>
<object aria-label="value" id="pass91"></object>
<span aria-label="value" id="pass92"></span>
<svg aria-label="value" id="pass93"></svg>
<video aria-label="value" id="pass82" controls></video>
<applet aria-label="value" id="pass82"></applet>
<canvas aria-label="value" id="pass83"></canvas>
<dl aria-label="value" id="pass84"></dl>
<embed aria-label="value" id="pass85"></embed>
<iframe aria-label="value" id="pass86" src="/integration/rules/aria-allowed-attr/blank.html"></iframe>
<input aria-label="value" id="pass87"/>
<label aria-label="value" id="pass88"></label>
<meter aria-label="value" id="pass89"></meter>
<object aria-label="value" id="pass90"></object>
<svg aria-label="value" id="pass91"></svg>
<video aria-label="value" id="pass92" controls></video>
3 changes: 1 addition & 2 deletions test/integration/rules/aria-allowed-attr/passes.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
["#pass89"],
["#pass90"],
["#pass91"],
["#pass92"],
["#pass93"]
["#pass92"]
]
}

0 comments on commit 6c9bc79

Please sign in to comment.