Skip to content
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

fix: deprecate axe.commons.utils namespace #1330

Merged
merged 6 commits into from
Jan 25, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/tasks/langs.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = function(grunt) {
'/**\n',
' * Returns array of valid language codes\n',
' * @method validLangs\n',
' * @memberof axe.commons.utils\n',
' * @memberof axe.utils\n',
' * @instance\n',
' * @return {Array<Sting>} Valid language codes\n',
' */\n',
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/aria/required-children.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const requiredOwned = axe.commons.aria.requiredOwned;
const implicitNodes = axe.commons.aria.implicitNodes;
const matchesSelector = axe.commons.utils.matchesSelector;
const matchesSelector = axe.utils.matchesSelector;
const idrefs = axe.commons.dom.idrefs;
const reviewEmpty =
options && Array.isArray(options.reviewEmpty) ? options.reviewEmpty : [];
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/aria/required-parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function getAriaOwners(element) {

while (element) {
if (element.getAttribute('id')) {
const id = axe.commons.utils.escapeSelector(element.getAttribute('id'));
const id = axe.utils.escapeSelector(element.getAttribute('id'));
let doc = axe.commons.dom.getRootNode(element);
o = doc.querySelector(`[aria-owns~=${id}]`);
if (o) {
Expand Down
8 changes: 4 additions & 4 deletions lib/checks/forms/fieldset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var failureCode,
self = this;

function getUnrelatedElements(parent, name) {
return axe.commons.utils.toArray(
return axe.utils.toArray(
parent.querySelectorAll(
'select,textarea,button,input:not([name="' +
name +
Expand Down Expand Up @@ -58,17 +58,17 @@ function checkARIAGroup(group, name) {
}

function spliceCurrentNode(nodes, current) {
return axe.commons.utils.toArray(nodes).filter(function(candidate) {
return axe.utils.toArray(nodes).filter(function(candidate) {
return candidate !== current;
});
}

function runCheck(virtualNode) {
const name = axe.commons.utils.escapeSelector(virtualNode.actualNode.name);
const name = axe.utils.escapeSelector(virtualNode.actualNode.name);
const root = axe.commons.dom.getRootNode(virtualNode.actualNode);
const matchingNodes = root.querySelectorAll(
'input[type="' +
axe.commons.utils.escapeSelector(virtualNode.actualNode.type) +
axe.utils.escapeSelector(virtualNode.actualNode.type) +
'"][name="' +
name +
'"]'
Expand Down
6 changes: 3 additions & 3 deletions lib/checks/forms/group-labelledby.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { dom, text, utils } = axe.commons;
const { dom, text } = axe.commons;

const type = utils.escapeSelector(node.type);
const name = utils.escapeSelector(node.name);
const type = axe.utils.escapeSelector(node.type);
const name = axe.utils.escapeSelector(node.name);
const doc = dom.getRootNode(node);
const data = {
name: node.name,
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/label/explicit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if (node.getAttribute('id')) {
const root = axe.commons.dom.getRootNode(node);
const id = axe.commons.utils.escapeSelector(node.getAttribute('id'));
const id = axe.utils.escapeSelector(node.getAttribute('id'));
const label = root.querySelector(`label[for="${id}"]`);

if (label) {
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/label/hidden-explicit-label.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if (node.getAttribute('id')) {
const root = axe.commons.dom.getRootNode(node);
const id = axe.commons.utils.escapeSelector(node.getAttribute('id'));
const id = axe.utils.escapeSelector(node.getAttribute('id'));
const label = root.querySelector(`label[for="${id}"]`);

if (label && !axe.commons.dom.isVisible(label, true)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/label/multiple-label.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const id = axe.commons.utils.escapeSelector(node.getAttribute('id'));
const id = axe.utils.escapeSelector(node.getAttribute('id'));
let labels = Array.from(document.querySelectorAll(`label[for="${id}"]`));
let parent = node.parentNode;

Expand Down
6 changes: 2 additions & 4 deletions lib/checks/language/valid-lang.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
var langs, invalid;

langs = (options ? options : axe.commons.utils.validLangs()).map(
axe.commons.utils.getBaseLang
);
langs = (options ? options : axe.utils.validLangs()).map(axe.utils.getBaseLang);

invalid = ['lang', 'xml:lang'].reduce(function(invalid, langAttr) {
var langVal = node.getAttribute(langAttr);
if (typeof langVal !== 'string') {
return invalid;
}

var baselangVal = axe.commons.utils.getBaseLang(langVal);
var baselangVal = axe.utils.getBaseLang(langVal);

// Edge sets lang to an empty string when xml:lang is set
// so we need to ignore empty strings here
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/language/xml-lang-mismatch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getBaseLang } = axe.commons.utils;
const { getBaseLang } = axe.utils;
const primaryLangValue = getBaseLang(node.getAttribute('lang'));
const primaryXmlLangValue = getBaseLang(node.getAttribute('xml:lang'));

Expand Down
2 changes: 1 addition & 1 deletion lib/checks/parsing/duplicate-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if (!id) {
}
const root = axe.commons.dom.getRootNode(node);
const matchingNodes = Array.from(
root.querySelectorAll(`[id="${axe.commons.utils.escapeSelector(id)}"]`)
root.querySelectorAll(`[id="${axe.utils.escapeSelector(id)}"]`)
).filter(foundNode => foundNode !== node);

if (matchingNodes.length) {
Expand Down
4 changes: 1 addition & 3 deletions lib/commons/text/label-virtual.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ text.labelVirtual = function(node) {

// explicit label
if (node.actualNode.id) {
const id = axe.commons.utils.escapeSelector(
node.actualNode.getAttribute('id')
);
const id = axe.utils.escapeSelector(node.actualNode.getAttribute('id'));
doc = axe.commons.dom.getRootNode(node.actualNode);
ref = doc.querySelector('label[for="' + id + '"]');
candidate = ref && text.visible(ref, true);
Expand Down
10 changes: 0 additions & 10 deletions lib/commons/utils/index.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* global axe */
/**
* Convenience function to extract primary language subtag from a given value
* @method getBaseLang
* @memberof axe.commons.utils
* @memberof axe.utils
* @instance
* @param {String} value value specified as lang or xml:lang attribute
* @return {String}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const htmlTags = [
/**
* Verifies that if a given html tag is valid
* @method isHtmlElement
* @memberof axe.commons.utils
* @memberof axe.utils
* @instance
* @param htmlTag htmlTag to check if valid
* @return {Boolean} true/ false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* global axe */
/**
* Converts space delimited token list to an Array
* @method tokenList
* @memberof axe.commons.utils
* @memberof axe.utils
* @instance
* @param {String} str
* @return {Array}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* global axe */

/**
* Returns array of valid input type values
* @method validInputTypes
* @memberof axe.commons.utils
* @memberof axe.utils
* @instance
* @return {Array<Sting>}
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* global axe */
/*eslint quotes: 0*/
var langs = [
const langs = [
'aa',
'ab',
'ae',
Expand Down Expand Up @@ -8144,7 +8143,7 @@ var langs = [
/**
* Returns array of valid language codes
* @method validLangs
* @memberof axe.commons.utils
* @memberof axe.utils
* @instance
* @return {Array<Sting>} Valid language codes
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/color-contrast-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ if (nodeName === 'LABEL' || nodeParentLabel) {

// label of disabled control associated w/ aria-labelledby
if (node.getAttribute('id')) {
const id = axe.commons.utils.escapeSelector(node.getAttribute('id'));
const id = axe.utils.escapeSelector(node.getAttribute('id'));
let doc = axe.commons.dom.getRootNode(node);
var candidate = doc.querySelector('[aria-labelledby~=' + id + ']');
if (candidate && candidate.disabled) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/xml-lang-mismatch-matches.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// using -> "selector": "html[lang][xml\\:lang]" to narrow down html with lang and xml:lang attributes

// get primary base language for each of the attributes
const { getBaseLang } = axe.commons.utils;
const { getBaseLang } = axe.utils;
const primaryLangValue = getBaseLang(node.getAttribute('lang'));
const primaryXmlLangValue = getBaseLang(node.getAttribute('xml:lang'));

Expand Down
21 changes: 0 additions & 21 deletions test/commons/utils/index.js

This file was deleted.

25 changes: 0 additions & 25 deletions test/commons/utils/token-list.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
describe('utils.getBaseLang', function() {
describe('axe.utils.getBaseLang', function() {
'use strict';

it('returns base lang as peanut for argument peanut-BUTTER', function() {
var actual = axe.commons.utils.getBaseLang('peanut-BUTTER');
var actual = axe.utils.getBaseLang('peanut-BUTTER');
assert.equal(actual, 'peanut');
});

it('returns base lang as fr for argument FR-CA', function() {
var actual = axe.commons.utils.getBaseLang('FR-CA');
var actual = axe.utils.getBaseLang('FR-CA');
assert.strictEqual(actual, 'fr');
});

it('returns base lang which is the prefix string before the first - (hyphen)', function() {
var actual = axe.commons.utils.getBaseLang('en-GB');
var actual = axe.utils.getBaseLang('en-GB');
assert.equal(actual, 'en');
});

it('returns primary language subtag as base lang for multi hyphenated argument', function() {
var actual = axe.commons.utils.getBaseLang('SOME-random-lang');
var actual = axe.utils.getBaseLang('SOME-random-lang');
assert.strictEqual(actual, 'some');
});

it('returns an empty string when argument is null or undefined', function() {
var actualNull = axe.commons.utils.getBaseLang(null);
var actualUndefined = axe.commons.utils.getBaseLang(undefined);
var actualEmpty = axe.commons.utils.getBaseLang();
var actualNull = axe.utils.getBaseLang(null);
var actualUndefined = axe.utils.getBaseLang(undefined);
var actualEmpty = axe.utils.getBaseLang();
assert.strictEqual(actualNull, '');
assert.strictEqual(actualUndefined, '');
assert.strictEqual(actualEmpty, '');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global axe */
describe('utils.isHtmlElement', function() {
describe('axe.utils.isHtmlElement', function() {
it('returns true if given ul', function() {
var node = document.createElement('ul');
assert.isTrue(axe.utils.isHtmlElement(node));
Expand Down
27 changes: 27 additions & 0 deletions test/core/utils/token-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
describe('axe.utils.tokenList', function() {
'use strict';

it('should split by space', function() {
assert.deepEqual(axe.utils.tokenList('bananas monkeys 42'), [
'bananas',
'monkeys',
'42'
]);
});

it('should trim first', function() {
assert.deepEqual(axe.utils.tokenList(' \r bananas monkeys 42 \n '), [
'bananas',
'monkeys',
'42'
]);
});

it('should collapse whitespace', function() {
assert.deepEqual(axe.utils.tokenList(' \r bananas \r \n monkeys 42 \n '), [
'bananas',
'monkeys',
'42'
]);
});
});