Skip to content

Commit

Permalink
chore: simplify ARIA options usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcy Sutton committed Jan 18, 2018
1 parent 86fd5bf commit a51514d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
8 changes: 2 additions & 6 deletions lib/checks/aria/allowed-attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ if (!role) {

allowed = axe.commons.aria.allowedAttr(role);

if (Object.keys(options).length) {
for (var roleOption in options) {
if (roleOption === role) {
allowed = axe.utils.uniqueArray(options[role].concat(allowed));
}
}
if (Array.isArray(options[role])) {
allowed = axe.utils.uniqueArray(options[role].concat(allowed));
}

if (role && allowed) {
Expand Down
8 changes: 2 additions & 6 deletions lib/checks/aria/required-attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ if (node.hasAttributes()) {
role = node.getAttribute('role'),
required = axe.commons.aria.requiredAttr(role);

if (Object.keys(options).length) {
for (var roleOption in options) {
if (roleOption === role) {
required = axe.utils.uniqueArray(options[role].concat(required));
}
}
if (Array.isArray(options[role])) {
required = axe.utils.uniqueArray(options[role], required);
}
if (role && required) {
for (var i = 0, l = required.length; i < l; i++) {
Expand Down
9 changes: 5 additions & 4 deletions lib/core/utils/to-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ axe.utils.toArray = function (thing) {


/**
* Creates an array without duplicate values
* @param {Array} arrArg Array to filter
* Creates an array without duplicate values from 2 array inputs
* @param {Array} arr1 First array
* @param {Array} arr2 Second array
* @return {Array}
*/
axe.utils.uniqueArray = (arrArg) => {
return arrArg.filter((elem, pos, arr) => {
axe.utils.uniqueArray = (arr1, arr2) => {
return arr1.concat(arr2).filter((elem, pos, arr) => {
return arr.indexOf(elem) === pos;
});
};
2 changes: 1 addition & 1 deletion test/core/utils/to-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('axe.utils.uniqueArray', function () {
var array1 = [1, 2, 3, 4, 5];
var array2 = [1, 3, 7];

var result = axe.utils.uniqueArray(array1.concat(array2));
var result = axe.utils.uniqueArray(array1, array2);
assert.isArray(result);
assert.includeMembers(result, [1, 2, 3, 4, 5, 7]);
});
Expand Down

0 comments on commit a51514d

Please sign in to comment.