From db6647f6dd89ebfd02224a929f0aef5b8b92d231 Mon Sep 17 00:00:00 2001 From: jkodu Date: Tue, 22 Jan 2019 17:21:43 +0000 Subject: [PATCH 1/3] fix: deprecate axe.commons.utils namespace --- build/tasks/langs.js | 2 +- lib/checks/aria/required-children.js | 2 +- lib/checks/aria/required-parent.js | 2 +- lib/checks/forms/fieldset.js | 8 +++--- lib/checks/forms/group-labelledby.js | 4 +-- lib/checks/label/explicit.js | 2 +- lib/checks/label/hidden-explicit-label.js | 2 +- lib/checks/label/multiple-label.js | 2 +- lib/checks/language/valid-lang.js | 6 ++--- lib/checks/language/xml-lang-mismatch.js | 2 +- lib/checks/parsing/duplicate-id.js | 2 +- lib/commons/text/label-virtual.js | 4 +-- lib/commons/utils/index.js | 10 ------- lib/{commons => core}/utils/get-base-lang.js | 3 +-- .../utils/is-html-element.js | 2 +- lib/{commons => core}/utils/token-list.js | 3 +-- .../utils/valid-input-type.js | 4 +-- lib/{commons => core}/utils/valid-langs.js | 5 ++-- lib/rules/color-contrast-matches.js | 2 +- lib/rules/xml-lang-mismatch-matches.js | 2 +- test/commons/utils/index.js | 21 --------------- test/commons/utils/token-list.js | 25 ----------------- test/{commons => core}/utils/get-base-lang.js | 16 +++++------ .../utils/is-html-element.js | 2 +- test/core/utils/token-list.js | 27 +++++++++++++++++++ 25 files changed, 61 insertions(+), 99 deletions(-) delete mode 100644 lib/commons/utils/index.js rename lib/{commons => core}/utils/get-base-lang.js (88%) rename lib/{commons => core}/utils/is-html-element.js (97%) rename lib/{commons => core}/utils/token-list.js (84%) rename lib/{commons => core}/utils/valid-input-type.js (91%) rename lib/{commons => core}/utils/valid-langs.js (99%) delete mode 100644 test/commons/utils/index.js delete mode 100644 test/commons/utils/token-list.js rename test/{commons => core}/utils/get-base-lang.js (60%) rename test/{commons => core}/utils/is-html-element.js (95%) create mode 100644 test/core/utils/token-list.js diff --git a/build/tasks/langs.js b/build/tasks/langs.js index 3e7668c9d1..32b55980bb 100644 --- a/build/tasks/langs.js +++ b/build/tasks/langs.js @@ -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} Valid language codes\n', ' */\n', diff --git a/lib/checks/aria/required-children.js b/lib/checks/aria/required-children.js index 1eb68c1871..dbf02413c3 100644 --- a/lib/checks/aria/required-children.js +++ b/lib/checks/aria/required-children.js @@ -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 : []; diff --git a/lib/checks/aria/required-parent.js b/lib/checks/aria/required-parent.js index 13c37577c5..45d1a646c7 100644 --- a/lib/checks/aria/required-parent.js +++ b/lib/checks/aria/required-parent.js @@ -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) { diff --git a/lib/checks/forms/fieldset.js b/lib/checks/forms/fieldset.js index 202f0c99ef..a2b9fa49b4 100644 --- a/lib/checks/forms/fieldset.js +++ b/lib/checks/forms/fieldset.js @@ -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 + @@ -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 + '"]' diff --git a/lib/checks/forms/group-labelledby.js b/lib/checks/forms/group-labelledby.js index 2612cb9455..753304e939 100644 --- a/lib/checks/forms/group-labelledby.js +++ b/lib/checks/forms/group-labelledby.js @@ -6,9 +6,9 @@ this.data({ var doc = axe.commons.dom.getRootNode(node); var matchingNodes = doc.querySelectorAll( 'input[type="' + - axe.commons.utils.escapeSelector(node.type) + + axe.utils.escapeSelector(node.type) + '"][name="' + - axe.commons.utils.escapeSelector(node.name) + + axe.utils.escapeSelector(node.name) + '"]' ); if (matchingNodes.length <= 1) { diff --git a/lib/checks/label/explicit.js b/lib/checks/label/explicit.js index dc314576ea..f49de6c663 100644 --- a/lib/checks/label/explicit.js +++ b/lib/checks/label/explicit.js @@ -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) { diff --git a/lib/checks/label/hidden-explicit-label.js b/lib/checks/label/hidden-explicit-label.js index 8d7013bbca..5a8ba2390a 100644 --- a/lib/checks/label/hidden-explicit-label.js +++ b/lib/checks/label/hidden-explicit-label.js @@ -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)) { diff --git a/lib/checks/label/multiple-label.js b/lib/checks/label/multiple-label.js index 94b121124b..67dd91ae7c 100644 --- a/lib/checks/label/multiple-label.js +++ b/lib/checks/label/multiple-label.js @@ -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; diff --git a/lib/checks/language/valid-lang.js b/lib/checks/language/valid-lang.js index 31e12b95c9..c9b6d2e613 100644 --- a/lib/checks/language/valid-lang.js +++ b/lib/checks/language/valid-lang.js @@ -1,8 +1,6 @@ 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); @@ -10,7 +8,7 @@ invalid = ['lang', 'xml:lang'].reduce(function(invalid, langAttr) { 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 diff --git a/lib/checks/language/xml-lang-mismatch.js b/lib/checks/language/xml-lang-mismatch.js index d431a8828c..0d84c95851 100644 --- a/lib/checks/language/xml-lang-mismatch.js +++ b/lib/checks/language/xml-lang-mismatch.js @@ -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')); diff --git a/lib/checks/parsing/duplicate-id.js b/lib/checks/parsing/duplicate-id.js index fa0e3ed141..5c8a366ba1 100644 --- a/lib/checks/parsing/duplicate-id.js +++ b/lib/checks/parsing/duplicate-id.js @@ -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) { diff --git a/lib/commons/text/label-virtual.js b/lib/commons/text/label-virtual.js index c177ad6e6b..10a5b5f9fb 100644 --- a/lib/commons/text/label-virtual.js +++ b/lib/commons/text/label-virtual.js @@ -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); diff --git a/lib/commons/utils/index.js b/lib/commons/utils/index.js deleted file mode 100644 index d3c3d49662..0000000000 --- a/lib/commons/utils/index.js +++ /dev/null @@ -1,10 +0,0 @@ -/* exported utils */ -/* global axe */ -/*eslint no-unused-vars: 0*/ -/** - * Namespace for general utilities. - * @namespace utils - * @memberof axe.commons - */ - -var utils = (commons.utils = axe.utils); diff --git a/lib/commons/utils/get-base-lang.js b/lib/core/utils/get-base-lang.js similarity index 88% rename from lib/commons/utils/get-base-lang.js rename to lib/core/utils/get-base-lang.js index 0b6110f42c..f9f15b8402 100644 --- a/lib/commons/utils/get-base-lang.js +++ b/lib/core/utils/get-base-lang.js @@ -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} diff --git a/lib/commons/utils/is-html-element.js b/lib/core/utils/is-html-element.js similarity index 97% rename from lib/commons/utils/is-html-element.js rename to lib/core/utils/is-html-element.js index 5532b6377c..f857627958 100644 --- a/lib/commons/utils/is-html-element.js +++ b/lib/core/utils/is-html-element.js @@ -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 diff --git a/lib/commons/utils/token-list.js b/lib/core/utils/token-list.js similarity index 84% rename from lib/commons/utils/token-list.js rename to lib/core/utils/token-list.js index ecdd6538a0..73b7332e73 100644 --- a/lib/commons/utils/token-list.js +++ b/lib/core/utils/token-list.js @@ -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} diff --git a/lib/commons/utils/valid-input-type.js b/lib/core/utils/valid-input-type.js similarity index 91% rename from lib/commons/utils/valid-input-type.js rename to lib/core/utils/valid-input-type.js index fae153ea04..5775ae83c2 100644 --- a/lib/commons/utils/valid-input-type.js +++ b/lib/core/utils/valid-input-type.js @@ -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} */ diff --git a/lib/commons/utils/valid-langs.js b/lib/core/utils/valid-langs.js similarity index 99% rename from lib/commons/utils/valid-langs.js rename to lib/core/utils/valid-langs.js index bdf20b6dd8..925d5f627b 100644 --- a/lib/commons/utils/valid-langs.js +++ b/lib/core/utils/valid-langs.js @@ -1,6 +1,5 @@ -/* global axe */ /*eslint quotes: 0*/ -var langs = [ +const langs = [ 'aa', 'ab', 'ae', @@ -8144,7 +8143,7 @@ var langs = [ /** * Returns array of valid language codes * @method validLangs - * @memberof axe.commons.utils + * @memberof axe.utils * @instance * @return {Array} Valid language codes */ diff --git a/lib/rules/color-contrast-matches.js b/lib/rules/color-contrast-matches.js index 6575968393..f5045aa459 100644 --- a/lib/rules/color-contrast-matches.js +++ b/lib/rules/color-contrast-matches.js @@ -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) { diff --git a/lib/rules/xml-lang-mismatch-matches.js b/lib/rules/xml-lang-mismatch-matches.js index 6818db0b5a..3e84d943f1 100644 --- a/lib/rules/xml-lang-mismatch-matches.js +++ b/lib/rules/xml-lang-mismatch-matches.js @@ -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')); diff --git a/test/commons/utils/index.js b/test/commons/utils/index.js deleted file mode 100644 index 841fadef84..0000000000 --- a/test/commons/utils/index.js +++ /dev/null @@ -1,21 +0,0 @@ -describe('utils.escapeSelector', function() { - 'use strict'; - - it('should be a function', function() { - assert.isFunction(axe.commons.utils.escapeSelector); - }); -}); -describe('utils.matchesSelector', function() { - 'use strict'; - - it('should be a function', function() { - assert.isFunction(axe.commons.utils.matchesSelector); - }); -}); -describe('utils.clone', function() { - 'use strict'; - - it('should be a function', function() { - assert.isFunction(axe.commons.utils.clone); - }); -}); diff --git a/test/commons/utils/token-list.js b/test/commons/utils/token-list.js deleted file mode 100644 index 2ef4b09455..0000000000 --- a/test/commons/utils/token-list.js +++ /dev/null @@ -1,25 +0,0 @@ -describe('utils.tokenList', function() { - 'use strict'; - - it('should split by space', function() { - assert.deepEqual(axe.commons.utils.tokenList('bananas monkeys 42'), [ - 'bananas', - 'monkeys', - '42' - ]); - }); - - it('should trim first', function() { - assert.deepEqual( - axe.commons.utils.tokenList(' \r bananas monkeys 42 \n '), - ['bananas', 'monkeys', '42'] - ); - }); - - it('should collapse whitespace', function() { - assert.deepEqual( - axe.commons.utils.tokenList(' \r bananas \r \n monkeys 42 \n '), - ['bananas', 'monkeys', '42'] - ); - }); -}); diff --git a/test/commons/utils/get-base-lang.js b/test/core/utils/get-base-lang.js similarity index 60% rename from test/commons/utils/get-base-lang.js rename to test/core/utils/get-base-lang.js index 7fe7607e0d..2f663a5835 100644 --- a/test/commons/utils/get-base-lang.js +++ b/test/core/utils/get-base-lang.js @@ -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, ''); diff --git a/test/commons/utils/is-html-element.js b/test/core/utils/is-html-element.js similarity index 95% rename from test/commons/utils/is-html-element.js rename to test/core/utils/is-html-element.js index 2ba50e554f..e4202f3ea3 100644 --- a/test/commons/utils/is-html-element.js +++ b/test/core/utils/is-html-element.js @@ -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)); diff --git a/test/core/utils/token-list.js b/test/core/utils/token-list.js new file mode 100644 index 0000000000..b546fd5807 --- /dev/null +++ b/test/core/utils/token-list.js @@ -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' + ]); + }); +}); From 00026c0a05fad6fd188a7df05bdd3db7ce3d5ccb Mon Sep 17 00:00:00 2001 From: jkodu Date: Thu, 24 Jan 2019 13:38:18 +0000 Subject: [PATCH 2/3] fix: utils refeerences --- lib/checks/forms/group-labelledby.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/checks/forms/group-labelledby.js b/lib/checks/forms/group-labelledby.js index e4186f2eb7..d9213216fe 100644 --- a/lib/checks/forms/group-labelledby.js +++ b/lib/checks/forms/group-labelledby.js @@ -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, From c5cc19af8521ed9c10922f5bdeb5aa7e77e817d7 Mon Sep 17 00:00:00 2001 From: jkodu Date: Fri, 25 Jan 2019 12:04:19 +0000 Subject: [PATCH 3/3] fix: reintroduce commons utils namespace --- lib/commons/utils/index.js | 10 ++++++++++ test/commons/utils/index.js | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 lib/commons/utils/index.js create mode 100644 test/commons/utils/index.js diff --git a/lib/commons/utils/index.js b/lib/commons/utils/index.js new file mode 100644 index 0000000000..d3c3d49662 --- /dev/null +++ b/lib/commons/utils/index.js @@ -0,0 +1,10 @@ +/* exported utils */ +/* global axe */ +/*eslint no-unused-vars: 0*/ +/** + * Namespace for general utilities. + * @namespace utils + * @memberof axe.commons + */ + +var utils = (commons.utils = axe.utils); diff --git a/test/commons/utils/index.js b/test/commons/utils/index.js new file mode 100644 index 0000000000..841fadef84 --- /dev/null +++ b/test/commons/utils/index.js @@ -0,0 +1,21 @@ +describe('utils.escapeSelector', function() { + 'use strict'; + + it('should be a function', function() { + assert.isFunction(axe.commons.utils.escapeSelector); + }); +}); +describe('utils.matchesSelector', function() { + 'use strict'; + + it('should be a function', function() { + assert.isFunction(axe.commons.utils.matchesSelector); + }); +}); +describe('utils.clone', function() { + 'use strict'; + + it('should be a function', function() { + assert.isFunction(axe.commons.utils.clone); + }); +});