From 53e0c4419f3e5cbd054b32d07b6401c1df1049b0 Mon Sep 17 00:00:00 2001 From: Ava Gaiety W Date: Fri, 10 May 2024 13:34:08 -0500 Subject: [PATCH 1/3] style(lib/core): var -> let and const codemod continuing codemod --- .eslintignore | 5 +- lib/core/base/audit.js | 10 ++-- lib/core/base/context/create-frame-context.js | 2 +- lib/core/base/context/normalize-context.js | 3 +- lib/core/base/rule.js | 34 +++++------ lib/core/imports/polyfills.js | 46 +++++++-------- lib/core/index.js | 4 +- lib/core/public/cleanup.js | 8 +-- lib/core/public/configure.js | 3 +- lib/core/public/get-rules.js | 6 +- lib/core/public/load.js | 8 +-- lib/core/public/plugins.js | 4 +- lib/core/public/reset.js | 2 +- lib/core/public/run-rules.js | 6 +- lib/core/reporters/helpers/failure-summary.js | 4 +- lib/core/reporters/no-passes.js | 2 +- lib/core/reporters/v2.js | 2 +- lib/core/utils/aggregate-node-results.js | 4 +- lib/core/utils/aggregate-result.js | 2 +- lib/core/utils/aggregate.js | 2 +- lib/core/utils/are-styles-set.js | 6 +- lib/core/utils/collect-results-from-frames.js | 4 +- lib/core/utils/dq-element.js | 4 +- lib/core/utils/element-matches.js | 21 ++++--- lib/core/utils/escape-selector.js | 12 ++-- lib/core/utils/get-all-checks.js | 2 +- lib/core/utils/get-check-option.js | 8 +-- lib/core/utils/get-flattened-tree.js | 8 +-- lib/core/utils/get-root-node.js | 2 +- lib/core/utils/get-xpath.js | 8 +-- lib/core/utils/inject-style.js | 4 +- lib/core/utils/matches.js | 16 ++--- lib/core/utils/merge-results.js | 5 +- lib/core/utils/performance-timer.js | 13 +++-- .../utils/pollyfill-elements-from-point.js | 16 ++--- lib/core/utils/queue.js | 24 ++++---- lib/core/utils/respondable.js | 2 +- lib/core/utils/rule-should-run.js | 10 ++-- lib/core/utils/send-command-to-frame.js | 2 +- lib/core/utils/uuid.js | 58 +++++++++---------- 40 files changed, 192 insertions(+), 190 deletions(-) diff --git a/.eslintignore b/.eslintignore index ca1d987e96..39d277caf6 100644 --- a/.eslintignore +++ b/.eslintignore @@ -4,8 +4,9 @@ build/tasks/aria-supported.js doc/api/* -doc/examples/jest_react/*.js +doc/examples/**/*.js lib/core/imports/*.js +lib/core/utils/uuid.js axe.js -axe.min.js \ No newline at end of file +axe.min.js diff --git a/lib/core/base/audit.js b/lib/core/base/audit.js index 47b57f66d9..dbddcdb8f1 100644 --- a/lib/core/base/audit.js +++ b/lib/core/base/audit.js @@ -183,7 +183,7 @@ export default class Audit { * Initializes the rules and checks */ _init() { - var audit = getDefaultConfiguration(this.defaultConfig); + const audit = getDefaultConfiguration(this.defaultConfig); this.lang = audit.lang || 'en'; this.reporter = audit.reporter; this.commands = {}; @@ -366,9 +366,9 @@ export default class Audit { * @param {Mixed} options Options object to pass into rules and/or disable rules or checks */ after(results, options) { - var rules = this.rules; + const rules = this.rules; return results.map(ruleResult => { - var rule = findBy(rules, 'id', ruleResult.id); + const rule = findBy(rules, 'id', ruleResult.id); if (!rule) { // If you see this, you're probably running the Mocha tests with the axe extension installed throw new Error( @@ -393,7 +393,7 @@ export default class Audit { * @return {Object} Validated options object */ normalizeOptions(options) { - var audit = this; + const audit = this; const tags = []; const ruleIds = []; audit.rules.forEach(rule => { @@ -498,7 +498,7 @@ export default class Audit { } _constructHelpUrls(previous = null) { // TODO: es-modules-version - var version = (axe.version.match(/^[1-9][0-9]*\.[0-9]+/) || ['x.y'])[0]; + const version = (axe.version.match(/^[1-9][0-9]*\.[0-9]+/) || ['x.y'])[0]; this.rules.forEach(rule => { if (!this.data.rules[rule.id]) { this.data.rules[rule.id] = {}; diff --git a/lib/core/base/context/create-frame-context.js b/lib/core/base/context/create-frame-context.js index cbe52eb3aa..abb396ecf1 100644 --- a/lib/core/base/context/create-frame-context.js +++ b/lib/core/base/context/create-frame-context.js @@ -11,7 +11,7 @@ export function createFrameContext(frame, { focusable, page }) { } function frameFocusable(frame) { - var tabIndex = frame.getAttribute('tabindex'); + const tabIndex = frame.getAttribute('tabindex'); if (!tabIndex) { return true; } diff --git a/lib/core/base/context/normalize-context.js b/lib/core/base/context/normalize-context.js index 8187b3d64e..3eb9bea77b 100644 --- a/lib/core/base/context/normalize-context.js +++ b/lib/core/base/context/normalize-context.js @@ -159,10 +159,11 @@ function isShadowSelector(selector) { function isArrayLike(arr) { return ( + // Avoid DOM weirdness arr && typeof arr === 'object' && typeof arr.length === 'number' && - arr instanceof window.Node === false // Avoid DOM weirdness + arr instanceof window.Node === false ); } diff --git a/lib/core/base/rule.js b/lib/core/base/rule.js index a5995adfe4..37b59904fe 100644 --- a/lib/core/base/rule.js +++ b/lib/core/base/rule.js @@ -137,7 +137,7 @@ Rule.prototype.gather = function gather(context, options = {}) { performanceTimer.mark(markStart); } - var elements = select(this.selector, context); + let elements = select(this.selector, context); if (this.excludeHidden) { if (options.performanceTimer) { performanceTimer.mark(markHiddenStart); @@ -173,13 +173,13 @@ Rule.prototype.runChecks = function runChecks( resolve, reject ) { - var self = this; + const self = this; - var checkQueue = queue(); + const checkQueue = queue(); this[type].forEach(c => { - var check = self._audit.checks[c.id || c]; - var option = getCheckOption(check, self.id, options); + const check = self._audit.checks[c.id || c]; + const option = getCheckOption(check, self.id, options); checkQueue.defer((res, rej) => { check.run(node, option, context, res, rej); }); @@ -246,7 +246,7 @@ Rule.prototype.run = function run(context, options = {}, resolve, reject) { nodes.forEach(node => { q.defer((resolveNode, rejectNode) => { - var checkQueue = queue(); + const checkQueue = queue(); ['any', 'all', 'none'].forEach(type => { checkQueue.defer((res, rej) => { @@ -466,7 +466,7 @@ Rule.prototype.gatherAndMatchNodes = function gatherAndMatchNodes( function findAfterChecks(rule) { return getAllChecks(rule) .map(c => { - var check = rule._audit.checks[c.id || c]; + const check = rule._audit.checks[c.id || c]; return check && typeof check.after === 'function' ? check : null; }) .filter(Boolean); @@ -480,9 +480,9 @@ function findAfterChecks(rule) { * @return {Array} Matching CheckResults */ function findCheckResults(nodes, checkID) { - var checkResults = []; + const checkResults = []; nodes.forEach(nodeResult => { - var checks = getAllChecks(nodeResult); + const checks = getAllChecks(nodeResult); checks.forEach(checkResult => { if (checkResult.id === checkID) { checkResult.node = nodeResult.node; @@ -500,10 +500,10 @@ function filterChecks(checks) { } function sanitizeNodes(result) { - var checkTypes = ['any', 'all', 'none']; + const checkTypes = ['any', 'all', 'none']; - var nodes = result.nodes.filter(detail => { - var length = 0; + let nodes = result.nodes.filter(detail => { + let length = 0; checkTypes.forEach(type => { detail[type] = filterChecks(detail[type]); length += detail[type].length; @@ -533,13 +533,13 @@ function sanitizeNodes(result) { * @return {RuleResult} The RuleResult as filtered by after functions */ Rule.prototype.after = function after(result, options) { - var afterChecks = findAfterChecks(this); - var ruleID = this.id; + const afterChecks = findAfterChecks(this); + const ruleID = this.id; afterChecks.forEach(check => { - var beforeResults = findCheckResults(result.nodes, check.id); - var checkOption = getCheckOption(check, ruleID, options); + const beforeResults = findCheckResults(result.nodes, check.id); + const checkOption = getCheckOption(check, ruleID, options); - var afterResults = check.after(beforeResults, checkOption.options); + const afterResults = check.after(beforeResults, checkOption.options); if (this.reviewOnFail) { afterResults.forEach(checkResult => { diff --git a/lib/core/imports/polyfills.js b/lib/core/imports/polyfills.js index 7ad8adb4a1..de47772a5b 100644 --- a/lib/core/imports/polyfills.js +++ b/lib/core/imports/polyfills.js @@ -49,11 +49,11 @@ if (typeof Object.assign !== 'function') { throw new TypeError('Cannot convert undefined or null to object'); } - var output = Object(target); - for (var index = 1; index < arguments.length; index++) { - var source = arguments[index]; + let output = Object(target); + for (let index = 1; index < arguments.length; index++) { + let source = arguments[index]; if (source !== undefined && source !== null) { - for (var nextKey in source) { + for (let nextKey in source) { if (source.hasOwnProperty(nextKey)) { output[nextKey] = source[nextKey]; } @@ -74,12 +74,12 @@ if (!Array.prototype.find) { if (typeof predicate !== 'function') { throw new TypeError('predicate must be a function'); } - var list = Object(this); - var length = list.length >>> 0; - var thisArg = arguments[1]; - var value; + let list = Object(this); + let length = list.length >>> 0; + let thisArg = arguments[1]; + let value; - for (var i = 0; i < length; i++) { + for (let i = 0; i < length; i++) { value = list[i]; if (predicate.call(thisArg, value, i, list)) { return value; @@ -99,11 +99,11 @@ if (!Array.prototype.findIndex) { if (typeof predicate !== 'function') { throw new TypeError('predicate must be a function'); } - var list = Object(this); - var length = list.length >>> 0; - var value; + let list = Object(this); + let length = list.length >>> 0; + let value; - for (var i = 0; i < length; i++) { + for (let i = 0; i < length; i++) { value = list[i]; if (predicate.call(thisArg, value, i, list)) { return i; @@ -117,13 +117,13 @@ if (!Array.prototype.findIndex) { if (!Array.prototype.includes) { Object.defineProperty(Array.prototype, 'includes', { value: function (searchElement) { - var O = Object(this); - var len = parseInt(O.length, 10) || 0; + let O = Object(this); + let len = parseInt(O.length, 10) || 0; if (len === 0) { return false; } - var n = parseInt(arguments[1], 10) || 0; - var k; + let n = parseInt(arguments[1], 10) || 0; + let k; if (n >= 0) { k = n; } else { @@ -132,7 +132,7 @@ if (!Array.prototype.includes) { k = 0; } } - var currentElement; + let currentElement; while (k < len) { currentElement = O[k]; if ( @@ -162,11 +162,11 @@ if (!Array.prototype.some) { throw new TypeError(); } - var t = Object(this); - var len = t.length >>> 0; + let t = Object(this); + let len = t.length >>> 0; - var thisArg = arguments.length >= 2 ? arguments[1] : void 0; - for (var i = 0; i < len; i++) { + let thisArg = arguments.length >= 2 ? arguments[1] : void 0; + for (let i = 0; i < len; i++) { if (i in t && fun.call(thisArg, t[i], i, t)) { return true; } @@ -199,7 +199,7 @@ if (!Array.prototype.flat) { Object.defineProperty(Array.prototype, 'flat', { configurable: true, value: function flat() { - var depth = isNaN(arguments[0]) ? 1 : Number(arguments[0]); + let depth = isNaN(arguments[0]) ? 1 : Number(arguments[0]); return depth ? Array.prototype.reduce.call( diff --git a/lib/core/index.js b/lib/core/index.js index 6aa45e4880..2d15d52824 100644 --- a/lib/core/index.js +++ b/lib/core/index.js @@ -2,7 +2,7 @@ /*global axeFunction, module, define */ // exported namespace for axe /*eslint no-use-before-define: 0, no-unused-vars: 0*/ -var axe = axe || {}; +const axe = axe || {}; axe.version = '<%= pkg.version %>'; if (typeof define === 'function' && define.amd) { @@ -24,7 +24,7 @@ if (typeof window.getComputedStyle === 'function') { window.axe = axe; } // local namespace for common functions -var commons; +let commons; function SupportError(error) { this.name = 'SupportError'; diff --git a/lib/core/public/cleanup.js b/lib/core/public/cleanup.js index 76492c592a..6b5de2555e 100644 --- a/lib/core/public/cleanup.js +++ b/lib/core/public/cleanup.js @@ -6,13 +6,13 @@ function cleanup(resolve, reject) { throw new Error('No audit configured'); } - var q = axe.utils.queue(); + const q = axe.utils.queue(); // If a plugin fails it's cleanup, we still want the others to run - var cleanupErrors = []; + const cleanupErrors = []; Object.keys(axe.plugins).forEach(key => { q.defer(res => { - var rej = function rej(err) { + const rej = function rej(err) { cleanupErrors.push(err); res(); }; @@ -24,7 +24,7 @@ function cleanup(resolve, reject) { }); }); - var flattenedTree = axe.utils.getFlattenedTree(document.body); + const flattenedTree = axe.utils.getFlattenedTree(document.body); axe.utils.querySelectorAll(flattenedTree, 'iframe, frame').forEach(node => { q.defer((res, rej) => { diff --git a/lib/core/public/configure.js b/lib/core/public/configure.js index cbd6424837..afe73582b1 100644 --- a/lib/core/public/configure.js +++ b/lib/core/public/configure.js @@ -3,9 +3,8 @@ import { configureStandards } from '../../standards'; import constants from '../constants'; function configure(spec) { - var audit; + const audit = axe._audit; - audit = axe._audit; if (!audit) { throw new Error('No audit configured'); } diff --git a/lib/core/public/get-rules.js b/lib/core/public/get-rules.js index d52216f776..fa23a3b5b2 100644 --- a/lib/core/public/get-rules.js +++ b/lib/core/public/get-rules.js @@ -5,7 +5,7 @@ */ function getRules(tags) { tags = tags || []; - var matchingRules = !tags.length + const matchingRules = !tags.length ? axe._audit.rules : axe._audit.rules.filter(item => { return !!tags.filter(tag => { @@ -13,9 +13,9 @@ function getRules(tags) { }).length; }); - var ruleData = axe._audit.data.rules || {}; + const ruleData = axe._audit.data.rules || {}; return matchingRules.map(matchingRule => { - var rd = ruleData[matchingRule.id] || {}; + const rd = ruleData[matchingRule.id] || {}; return { ruleId: matchingRule.id, description: rd.description, diff --git a/lib/core/public/load.js b/lib/core/public/load.js index 124c849b12..a6dbe6972e 100644 --- a/lib/core/public/load.js +++ b/lib/core/public/load.js @@ -14,19 +14,19 @@ export default function load(audit) { } function runCommand(data, keepalive, callback) { - var resolve = callback; - var reject = function reject(err) { + const resolve = callback; + const reject = function reject(err) { if (err instanceof Error === false) { err = new Error(err); } callback(err); }; - var context = (data && data.context) || {}; + const context = (data && data.context) || {}; if (context.hasOwnProperty('include') && !context.include.length) { context.include = [document]; } - var options = (data && data.options) || {}; + const options = (data && data.options) || {}; switch (data.command) { case 'rules': diff --git a/lib/core/public/plugins.js b/lib/core/public/plugins.js index 5b20b4f8cb..4da9100d61 100644 --- a/lib/core/public/plugins.js +++ b/lib/core/public/plugins.js @@ -18,8 +18,8 @@ Plugin.prototype.collect = function collect() { }; Plugin.prototype.cleanup = function cleanup(done) { - var q = axe.utils.queue(); - var that = this; + const q = axe.utils.queue(); + const that = this; Object.keys(this._registry).forEach(key => { q.defer(_done => { that._registry[key].cleanup(_done); diff --git a/lib/core/public/reset.js b/lib/core/public/reset.js index 586224bb8e..ae33123f0d 100644 --- a/lib/core/public/reset.js +++ b/lib/core/public/reset.js @@ -1,7 +1,7 @@ import { resetStandards } from '../../standards'; function reset() { - var audit = axe._audit; + const audit = axe._audit; if (!audit) { throw new Error('No audit configured'); diff --git a/lib/core/public/run-rules.js b/lib/core/public/run-rules.js index 5eb26d7c9f..7824080821 100644 --- a/lib/core/public/run-rules.js +++ b/lib/core/public/run-rules.js @@ -29,8 +29,8 @@ export default function runRules(context, options, resolve, reject) { return reject(e); } - var q = queue(); - var audit = axe._audit; + const q = queue(); + const audit = axe._audit; if (options.performanceTimer) { performanceTimer.auditStart(); @@ -51,7 +51,7 @@ export default function runRules(context, options, resolve, reject) { } // Add wrapper object so that we may use the same "merge" function for results from inside and outside frames - var results = mergeResults( + let results = mergeResults( data.map(res => { return { results: res }; }) diff --git a/lib/core/reporters/helpers/failure-summary.js b/lib/core/reporters/helpers/failure-summary.js index a35c8554bc..19f69e8d70 100644 --- a/lib/core/reporters/helpers/failure-summary.js +++ b/lib/core/reporters/helpers/failure-summary.js @@ -4,7 +4,7 @@ * @return {String} failure messages */ function failureSummary(nodeData) { - var failingChecks = {}; + const failingChecks = {}; // combine "all" and "none" as messaging is the same failingChecks.none = nodeData.none.concat(nodeData.all); failingChecks.any = nodeData.any; @@ -15,7 +15,7 @@ function failureSummary(nodeData) { return; } - var sum = axe._audit.data.failureSummaries[key]; + const sum = axe._audit.data.failureSummaries[key]; if (sum && typeof sum.failureMessage === 'function') { return sum.failureMessage( failingChecks[key].map(check => { diff --git a/lib/core/reporters/no-passes.js b/lib/core/reporters/no-passes.js index 3cc3cbe451..8c9c41c66c 100644 --- a/lib/core/reporters/no-passes.js +++ b/lib/core/reporters/no-passes.js @@ -10,7 +10,7 @@ const noPassesReporter = (results, options, callback) => { // limit result processing to types we want to include in the output options.resultTypes = ['violations']; - var { violations } = processAggregate(results, options); + const { violations } = processAggregate(results, options); callback({ ...getEnvironmentData(environmentData), diff --git a/lib/core/reporters/v2.js b/lib/core/reporters/v2.js index f4a63333ee..4597ca109b 100644 --- a/lib/core/reporters/v2.js +++ b/lib/core/reporters/v2.js @@ -7,7 +7,7 @@ const v2Reporter = (results, options, callback) => { options = {}; } const { environmentData, ...toolOptions } = options; - var out = processAggregate(results, options); + const out = processAggregate(results, options); callback({ ...getEnvironmentData(environmentData), toolOptions, diff --git a/lib/core/utils/aggregate-node-results.js b/lib/core/utils/aggregate-node-results.js index 151880e576..d7ce70675d 100644 --- a/lib/core/utils/aggregate-node-results.js +++ b/lib/core/utils/aggregate-node-results.js @@ -40,12 +40,12 @@ function aggregateNodeResults(nodeResults) { // Fill the array with nodes nodeResults.forEach(nodeResult => { - var groupName = constants.resultGroupMap[nodeResult.result]; + const groupName = constants.resultGroupMap[nodeResult.result]; ruleResult[groupName].push(nodeResult); }); // Take the highest impact of failed or canttell rules - var impactGroup = constants.FAIL_GROUP; + let impactGroup = constants.FAIL_GROUP; if (ruleResult[impactGroup].length === 0) { impactGroup = constants.CANTTELL_GROUP; } diff --git a/lib/core/utils/aggregate-result.js b/lib/core/utils/aggregate-result.js index d60122a060..ba7356d064 100644 --- a/lib/core/utils/aggregate-result.js +++ b/lib/core/utils/aggregate-result.js @@ -1,7 +1,7 @@ import constants from '../constants'; function copyToGroup(resultObject, subResult, group) { - var resultCopy = Object.assign({}, subResult); + const resultCopy = Object.assign({}, subResult); resultCopy.nodes = (resultCopy[group] || []).concat(); constants.resultGroups.forEach(resultGroup => { delete resultCopy[resultGroup]; diff --git a/lib/core/utils/aggregate.js b/lib/core/utils/aggregate.js index bdc186e017..16fcc0c013 100644 --- a/lib/core/utils/aggregate.js +++ b/lib/core/utils/aggregate.js @@ -13,7 +13,7 @@ function aggregate(map, values, initial) { values.push(initial); } - var sorting = values.map(val => map.indexOf(val)).sort(); // Stupid NodeJS array.sort functor doesn't work!! + const sorting = values.map(val => map.indexOf(val)).sort(); // Stupid NodeJS array.sort functor doesn't work!! return map[sorting.pop()]; } diff --git a/lib/core/utils/are-styles-set.js b/lib/core/utils/are-styles-set.js index 7192a83c97..c6332041fc 100644 --- a/lib/core/utils/are-styles-set.js +++ b/lib/core/utils/are-styles-set.js @@ -1,10 +1,10 @@ function areStylesSet(el, styles, stopAt) { - var styl = window.getComputedStyle(el, null); + const styl = window.getComputedStyle(el, null); if (!styl) { return false; } - for (var i = 0; i < styles.length; ++i) { - var att = styles[i]; + for (let i = 0; i < styles.length; ++i) { + const att = styles[i]; if (styl.getPropertyValue(att.property) === att.value) { return true; } diff --git a/lib/core/utils/collect-results-from-frames.js b/lib/core/utils/collect-results-from-frames.js index be17f8ccfd..7ca5de6e17 100644 --- a/lib/core/utils/collect-results-from-frames.js +++ b/lib/core/utils/collect-results-from-frames.js @@ -22,8 +22,8 @@ export default function collectResultsFromFrames( // elementRefs can't be passed across frame boundaries options = { ...options, elementRef: false }; - var q = queue(); - var frames = parentContent.frames; + const q = queue(); + const frames = parentContent.frames; // Tell each axe running in each frame to collect results frames.forEach(({ node: frameElement, ...context }) => { diff --git a/lib/core/utils/dq-element.js b/lib/core/utils/dq-element.js index 3cf790fe1a..844ed2a201 100644 --- a/lib/core/utils/dq-element.js +++ b/lib/core/utils/dq-element.js @@ -11,7 +11,7 @@ function truncate(str, maxLength) { maxLength = maxLength || 300; if (str.length > maxLength) { - var index = str.indexOf('>'); + const index = str.indexOf('>'); str = str.substring(0, index + 1); } @@ -22,7 +22,7 @@ function getSource(element) { if (!element?.outerHTML) { return ''; } - var source = element.outerHTML; + let source = element.outerHTML; if (!source && typeof window.XMLSerializer === 'function') { source = new window.XMLSerializer().serializeToString(element); } diff --git a/lib/core/utils/element-matches.js b/lib/core/utils/element-matches.js index bad802d423..7399e59ff5 100644 --- a/lib/core/utils/element-matches.js +++ b/lib/core/utils/element-matches.js @@ -5,19 +5,18 @@ * @return {Boolean} */ const matchesSelector = (() => { - var method; + let method; function getMethod(node) { - var index, - candidate, - candidates = [ - 'matches', - 'matchesSelector', - 'mozMatchesSelector', - 'webkitMatchesSelector', - 'msMatchesSelector' - ], - length = candidates.length; + const candidates = [ + 'matches', + 'matchesSelector', + 'mozMatchesSelector', + 'webkitMatchesSelector', + 'msMatchesSelector' + ]; + const length = candidates.length; + let index, candidate; for (index = 0; index < length; index++) { candidate = candidates[index]; diff --git a/lib/core/utils/escape-selector.js b/lib/core/utils/escape-selector.js index 7add6e89b5..dc4bf0d68b 100644 --- a/lib/core/utils/escape-selector.js +++ b/lib/core/utils/escape-selector.js @@ -7,12 +7,12 @@ */ function escapeSelector(value) { /*eslint no-bitwise: 0, eqeqeq: 0, one-var: 0 */ - var string = String(value); - var length = string.length; - var index = -1; - var codeUnit; - var result = ''; - var firstCodeUnit = string.charCodeAt(0); + const string = String(value); + const length = string.length; + let index = -1; + let codeUnit; + let result = ''; + const firstCodeUnit = string.charCodeAt(0); while (++index < length) { codeUnit = string.charCodeAt(index); // Note: there’s no need to special-case astral symbols, surrogate diff --git a/lib/core/utils/get-all-checks.js b/lib/core/utils/get-all-checks.js index 4c79e8368d..78c203489a 100644 --- a/lib/core/utils/get-all-checks.js +++ b/lib/core/utils/get-all-checks.js @@ -3,7 +3,7 @@ * @param {RuleResult|Rule} rule */ function getAllChecks(object) { - var result = []; + const result = []; return result .concat(object.any || []) .concat(object.all || []) diff --git a/lib/core/utils/get-check-option.js b/lib/core/utils/get-check-option.js index e159965e87..f438d8d418 100644 --- a/lib/core/utils/get-check-option.js +++ b/lib/core/utils/get-check-option.js @@ -6,12 +6,12 @@ * @return {Object} The resolved object with `options` and `enabled` keys */ function getCheckOption(check, ruleID, options) { - var ruleCheckOption = (((options.rules && options.rules[ruleID]) || {}) + const ruleCheckOption = (((options.rules && options.rules[ruleID]) || {}) .checks || {})[check.id]; - var checkOption = (options.checks || {})[check.id]; + const checkOption = (options.checks || {})[check.id]; - var enabled = check.enabled; - var opts = check.options; + let enabled = check.enabled; + let opts = check.options; if (checkOption) { if (checkOption.hasOwnProperty('enabled')) { diff --git a/lib/core/utils/get-flattened-tree.js b/lib/core/utils/get-flattened-tree.js index 2fb869e78a..f95a6a929b 100644 --- a/lib/core/utils/get-flattened-tree.js +++ b/lib/core/utils/get-flattened-tree.js @@ -61,7 +61,7 @@ export default function getFlattenedTree( * @return Array{Nodes} */ function getSlotChildren(node) { - var retVal = []; + const retVal = []; node = node.firstChild; while (node) { @@ -96,7 +96,7 @@ function createNode(node, parent, shadowId) { */ function flattenTree(node, shadowId, parent) { // using a closure here and therefore cannot easily refactor toreduce the statements - var retVal, realArray, nodeName; + let retVal, realArray; function reduceShadowDOM(res, child, parentVNode) { const replacements = flattenTree(child, shadowId, parentVNode); if (replacements) { @@ -109,7 +109,7 @@ function flattenTree(node, shadowId, parent) { // document node = node.documentElement; } - nodeName = node.nodeName.toLowerCase(); + const nodeName = node.nodeName.toLowerCase(); if (isShadowRoot(node)) { hasShadowRoot = true; @@ -142,7 +142,7 @@ function flattenTree(node, shadowId, parent) { // fallback content realArray = getSlotChildren(node); } - var styl = window.getComputedStyle(node); + const styl = window.getComputedStyle(node); // check the display property if (false && styl.display !== 'contents') { // intentionally commented out diff --git a/lib/core/utils/get-root-node.js b/lib/core/utils/get-root-node.js index 6eaf28d08f..aaab8944a7 100644 --- a/lib/core/utils/get-root-node.js +++ b/lib/core/utils/get-root-node.js @@ -6,7 +6,7 @@ * @returns {DocumentFragment|Document} */ function getRootNode(node) { - var doc = (node.getRootNode && node.getRootNode()) || document; // this is for backwards compatibility + let doc = (node.getRootNode && node.getRootNode()) || document; // this is for backwards compatibility if (doc === node) { // disconnected node doc = document; diff --git a/lib/core/utils/get-xpath.js b/lib/core/utils/get-xpath.js index b0b66ba9c7..14298daab0 100644 --- a/lib/core/utils/get-xpath.js +++ b/lib/core/utils/get-xpath.js @@ -1,7 +1,7 @@ import escapeSelector from './escape-selector'; function getXPathArray(node, path) { - var sibling, count; + let sibling, count; // Gets an XPath for an element which describes its hierarchical location. if (!node) { return []; @@ -46,10 +46,10 @@ function getXPathArray(node, path) { } if (node.nodeType === 1) { - var element = {}; + const element = {}; element.str = node.nodeName.toLowerCase(); // add the id and the count so we can construct robust versions of the xpath - var id = node.getAttribute && escapeSelector(node.getAttribute('id')); + const id = node.getAttribute && escapeSelector(node.getAttribute('id')); if (id && node.ownerDocument.querySelectorAll('#' + id).length === 1) { element.id = node.getAttribute('id'); } @@ -77,7 +77,7 @@ function xpathToString(xpathArray) { } function getXpath(node) { - var xpathArray = getXPathArray(node); + const xpathArray = getXPathArray(node); return xpathToString(xpathArray); } diff --git a/lib/core/utils/inject-style.js b/lib/core/utils/inject-style.js index 503300648f..86ce8b03ac 100644 --- a/lib/core/utils/inject-style.js +++ b/lib/core/utils/inject-style.js @@ -1,4 +1,4 @@ -var styleSheet; +let styleSheet; function injectStyle(style) { if (styleSheet && styleSheet.parentNode) { // append the style to the existing sheet @@ -14,7 +14,7 @@ function injectStyle(style) { return; } - var head = document.head || document.getElementsByTagName('head')[0]; + const head = document.head || document.getElementsByTagName('head')[0]; styleSheet = document.createElement('style'); styleSheet.type = 'text/css'; diff --git a/lib/core/utils/matches.js b/lib/core/utils/matches.js index f49bace8f3..7bd28c6501 100644 --- a/lib/core/utils/matches.js +++ b/lib/core/utils/matches.js @@ -29,7 +29,7 @@ function matchesAttributes(vNode, exp) { return ( !exp.attributes || exp.attributes.every(att => { - var nodeAtt = vNode.attr(att.key); + const nodeAtt = vNode.attr(att.key); return nodeAtt !== null && att.test(nodeAtt); }) ); @@ -72,10 +72,10 @@ function matchExpression(vNode, expression) { ); } -var escapeRegExp = (() => { +const escapeRegExp = (() => { /*! Credit: XRegExp 0.6.1 (c) 2007-2008 Steven Levithan MIT License */ - var from = /(?=[\-\[\]{}()*+?.\\\^$|,#\s])/g; - var to = '\\'; + const from = /(?=[\-\[\]{}()*+?.\\\^$|,#\s])/g; + const to = '\\'; return string => { return string.replace(from, to); }; @@ -168,7 +168,7 @@ function convertPseudos(pseudos) { return; } return pseudos.map(p => { - var expressions; + let expressions; if (['is', 'not'].includes(p.name)) { expressions = p.value; @@ -194,8 +194,8 @@ function convertPseudos(pseudos) { */ function convertExpressions(expressions) { return expressions.map(exp => { - var newExp = []; - var rule = exp.rule; + const newExp = []; + let rule = exp.rule; while (rule) { /* eslint no-restricted-syntax: 0 */ // `.tagName` is a property coming from the `CSSSelectorParser` library @@ -221,7 +221,7 @@ function convertExpressions(expressions) { * @returns {Object[]} Array of Slick format expressions */ export function convertSelector(selector) { - var expressions = cssParser.parse(selector); + let expressions = cssParser.parse(selector); expressions = expressions.selectors ? expressions.selectors : [expressions]; return convertExpressions(expressions); } diff --git a/lib/core/utils/merge-results.js b/lib/core/utils/merge-results.js index e5c9547adf..717eeb198a 100644 --- a/lib/core/utils/merge-results.js +++ b/lib/core/utils/merge-results.js @@ -31,8 +31,9 @@ function pushFrame(resultSet, options, frameSpec) { */ function spliceNodes(target, to) { const firstFromFrame = to[0].node; + let node; for (let i = 0; i < target.length; i++) { - const node = target[i].node; + node = target[i].node; const resultSort = nodeIndexSort( node.nodeIndexes, firstFromFrame.nodeIndexes @@ -87,7 +88,7 @@ function mergeResults(frameResults, options) { pushFrame(ruleResult.nodes, options, frameSpec); } - var res = findBy(mergedResult, 'id', ruleResult.id); + const res = findBy(mergedResult, 'id', ruleResult.id); if (!res) { mergedResult.push(ruleResult); } else { diff --git a/lib/core/utils/performance-timer.js b/lib/core/utils/performance-timer.js index 78c25f4047..a66d6348be 100644 --- a/lib/core/utils/performance-timer.js +++ b/lib/core/utils/performance-timer.js @@ -17,8 +17,8 @@ const performanceTimer = (() => { return window.performance.now(); } } - var originalTime = null; - var lastRecordedTime = now(); + let originalTime = null; + let lastRecordedTime = now(); /** * @typedef {utils.performanceTimer} Public API Methods @@ -90,12 +90,13 @@ const performanceTimer = (() => { ) { // only output measures that were started after axe started, otherwise // we get measures made by the page before axe ran (which is confusing) - var axeStart = window.performance.getEntriesByName('mark_axe_start')[0]; - var measures = window.performance + const axeStart = + window.performance.getEntriesByName('mark_axe_start')[0]; + const measures = window.performance .getEntriesByType('measure') .filter(measure => measure.startTime >= axeStart.startTime); - for (var i = 0; i < measures.length; ++i) { - var req = measures[i]; + for (let i = 0; i < measures.length; ++i) { + const req = measures[i]; if (req.name === measureName) { logMeasure(req); return; diff --git a/lib/core/utils/pollyfill-elements-from-point.js b/lib/core/utils/pollyfill-elements-from-point.js index 1783f12946..b306f74ad7 100644 --- a/lib/core/utils/pollyfill-elements-from-point.js +++ b/lib/core/utils/pollyfill-elements-from-point.js @@ -3,24 +3,24 @@ export function pollyfillElementsFromPoint() { if (document.elementsFromPoint) return document.elementsFromPoint; if (document.msElementsFromPoint) return document.msElementsFromPoint; - var usePointer = (function () { - var element = document.createElement('x'); + const usePointer = (function () { + const element = document.createElement('x'); element.style.cssText = 'pointer-events:auto'; return element.style.pointerEvents === 'auto'; })(); - var cssProp = usePointer ? 'pointer-events' : 'visibility'; - var cssDisableVal = usePointer ? 'none' : 'hidden'; + const cssProp = usePointer ? 'pointer-events' : 'visibility'; + const cssDisableVal = usePointer ? 'none' : 'hidden'; - var style = document.createElement('style'); + const style = document.createElement('style'); style.innerHTML = usePointer ? '* { pointer-events: all }' : '* { visibility: visible }'; return function (x, y) { - var current, i, d; - var elements = []; - var previousPointerEvents = []; + let current, i, d; + const elements = []; + const previousPointerEvents = []; // startup document.head.appendChild(style); diff --git a/lib/core/utils/queue.js b/lib/core/utils/queue.js index 5d5e82053b..fd27e4a5d9 100644 --- a/lib/core/utils/queue.js +++ b/lib/core/utils/queue.js @@ -12,16 +12,16 @@ function funcGuard(f) { * @return {Queue} The newly generated "queue" */ function queue() { - var tasks = []; - var started = 0; - var remaining = 0; // number of tasks not yet finished - var completeQueue = noop; - var complete = false; - var err; + const tasks = []; + let started = 0; + let remaining = 0; // number of tasks not yet finished + let completeQueue = noop; + let complete = false; + let err; // By default, wait until the next tick, // if no catch was set, throw to console. - var defaultFail = e => { + const defaultFail = e => { err = e; setTimeout(() => { if (err !== undefined && err !== null) { @@ -29,7 +29,7 @@ function queue() { } }, 1); }; - var failed = defaultFail; + let failed = defaultFail; function createResolve(i) { return r => { @@ -53,9 +53,9 @@ function queue() { } function pop() { - var length = tasks.length; + const length = tasks.length; for (; started < length; started++) { - var task = tasks[started]; + const task = tasks[started]; try { task.call(null, createResolve(started), abort); @@ -65,7 +65,7 @@ function queue() { } } - var q = { + const q = { /** * Defer a function that may or may not run asynchronously. * @@ -74,7 +74,7 @@ function queue() { */ defer(fn) { if (typeof fn === 'object' && fn.then && fn.catch) { - var defer = fn; + const defer = fn; fn = (resolve, reject) => { defer.then(resolve).catch(reject); }; diff --git a/lib/core/utils/respondable.js b/lib/core/utils/respondable.js index a43a8332ba..7a1c5c4da8 100644 --- a/lib/core/utils/respondable.js +++ b/lib/core/utils/respondable.js @@ -64,7 +64,7 @@ respondable.updateMessenger = function updateMessenger({ open, post }) { closeHandler(); } - var close = open(messageListener); + const close = open(messageListener); if (close) { assert( diff --git a/lib/core/utils/rule-should-run.js b/lib/core/utils/rule-should-run.js index 70c1fef55d..38fde1fcbd 100644 --- a/lib/core/utils/rule-should-run.js +++ b/lib/core/utils/rule-should-run.js @@ -6,8 +6,8 @@ * @return {bool} */ function matchTags(rule, runOnly) { - var include, exclude, matching; - var defaultExclude = + let include, exclude; + const defaultExclude = // TODO: es-modules_audit axe._audit && axe._audit.tagExclude ? axe._audit.tagExclude : []; @@ -35,7 +35,7 @@ function matchTags(rule, runOnly) { }); } - matching = include.some(tag => { + const matching = include.some(tag => { return rule.tags.indexOf(tag) !== -1; }); if (matching || (include.length === 0 && rule.enabled !== false)) { @@ -55,8 +55,8 @@ function matchTags(rule, runOnly) { * @return {Boolean} */ function ruleShouldRun(rule, context, options) { - var runOnly = options.runOnly || {}; - var ruleOptions = (options.rules || {})[rule.id]; + const runOnly = options.runOnly || {}; + const ruleOptions = (options.rules || {})[rule.id]; // Never run page level rules if the context is not on the page if (rule.pageLevel && !context.page) { diff --git a/lib/core/utils/send-command-to-frame.js b/lib/core/utils/send-command-to-frame.js index 7d7f5b57ea..f6b13fac3f 100644 --- a/lib/core/utils/send-command-to-frame.js +++ b/lib/core/utils/send-command-to-frame.js @@ -63,7 +63,7 @@ function callAxeStart(node, parameters, resolve, reject) { } function err(message, node) { - var selector; + let selector; // TODO: es-modules_tree if (axe._tree) { selector = getSelector(node); diff --git a/lib/core/utils/uuid.js b/lib/core/utils/uuid.js index de8a9eb66e..c10369a1f0 100644 --- a/lib/core/utils/uuid.js +++ b/lib/core/utils/uuid.js @@ -3,20 +3,20 @@ // // Copyright (c) 2010-2012 Robert Kieffer // MIT License - http://opensource.org/licenses/mit-license.php -var uuid; +let uuid; // Unique ID creation requires a high quality random # generator. We feature // detect to determine the best RNG source, normalizing to a function that // returns 128-bits of randomness, since that's what's usually required -var _rng; +let _rng; // Allow for MSIE11 msCrypto -var _crypto = window.crypto || window.msCrypto; +let _crypto = window.crypto || window.msCrypto; if (!_rng && _crypto && _crypto.getRandomValues) { // WHATWG crypto-based RNG - http://wiki.whatwg.org/wiki/Crypto // // Moderately fast, high quality - var _rnds8 = new Uint8Array(16); + let _rnds8 = new Uint8Array(16); _rng = function whatwgRNG() { _crypto.getRandomValues(_rnds8); return _rnds8; @@ -28,9 +28,9 @@ if (!_rng) { // // If all else fails, use Math.random(). It's fast, but is of unspecified // quality. - var _rnds = new Array(16); + let _rnds = new Array(16); _rng = () => { - for (var i = 0, r; i < 16; i++) { + for (let i = 0, r; i < 16; i++) { if ((i & 0x03) === 0) r = Math.random() * 0x100000000; _rnds[i] = (r >>> ((i & 0x03) << 3)) & 0xff; } @@ -40,19 +40,19 @@ if (!_rng) { } // Buffer class to use -var BufferClass = typeof window.Buffer == 'function' ? window.Buffer : Array; +let BufferClass = typeof window.Buffer == 'function' ? window.Buffer : Array; // Maps for number <-> hex string conversion -var _byteToHex = []; -var _hexToByte = {}; -for (var i = 0; i < 256; i++) { +let _byteToHex = []; +let _hexToByte = {}; +for (let i = 0; i < 256; i++) { _byteToHex[i] = (i + 0x100).toString(16).substr(1); _hexToByte[_byteToHex[i]] = i; } // **`parse()` - Parse a UUID into it's component bytes** function parse(s, buf, offset) { - var i = (buf && offset) || 0, + let i = (buf && offset) || 0, ii = 0; buf = buf || []; @@ -73,7 +73,7 @@ function parse(s, buf, offset) { // **`unparse()` - Convert UUID byte array (ala parse()) into a string** function unparse(buf, offset) { - var i = offset || 0, + let i = offset || 0, bth = _byteToHex; return ( bth[buf[i++]] + @@ -105,10 +105,10 @@ function unparse(buf, offset) { // and http://docs.python.org/library/uuid.html // random #'s we need to init node and clockseq -var _seedBytes = _rng(); +let _seedBytes = _rng(); // Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1) -var _nodeId = [ +let _nodeId = [ _seedBytes[0] | 0x01, _seedBytes[1], _seedBytes[2], @@ -118,33 +118,33 @@ var _nodeId = [ ]; // Per 4.2.2, randomize (14 bit) clockseq -var _clockseq = ((_seedBytes[6] << 8) | _seedBytes[7]) & 0x3fff; +let _clockseq = ((_seedBytes[6] << 8) | _seedBytes[7]) & 0x3fff; // Previous uuid creation time -var _lastMSecs = 0, +let _lastMSecs = 0, _lastNSecs = 0; // See https://github.com/broofa/node-uuid for API details function v1(options, buf, offset) { - var i = (buf && offset) || 0; - var b = buf || []; + let i = (buf && offset) || 0; + let b = buf || []; options = options || {}; - var clockseq = options.clockseq != null ? options.clockseq : _clockseq; + let clockseq = options.clockseq != null ? options.clockseq : _clockseq; // UUID timestamps are 100 nano-second units since the Gregorian epoch, // (1582-10-15 00:00). JSNumbers aren't precise enough for this, so // time is handled internally as 'msecs' (integer milliseconds) and 'nsecs' // (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00. - var msecs = options.msecs != null ? options.msecs : new Date().getTime(); + let msecs = options.msecs != null ? options.msecs : new Date().getTime(); // Per 4.2.1.2, use count of uuid's generated during the current clock // cycle to simulate higher resolution clock - var nsecs = options.nsecs != null ? options.nsecs : _lastNSecs + 1; + let nsecs = options.nsecs != null ? options.nsecs : _lastNSecs + 1; // Time since last uuid creation (in msecs) - var dt = msecs - _lastMSecs + (nsecs - _lastNSecs) / 10000; + let dt = msecs - _lastMSecs + (nsecs - _lastNSecs) / 10000; // Per 4.2.1.2, Bump clockseq on clock regression if (dt < 0 && options.clockseq == null) { @@ -170,14 +170,14 @@ function v1(options, buf, offset) { msecs += 12219292800000; // `time_low` - var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000; + let tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000; b[i++] = (tl >>> 24) & 0xff; b[i++] = (tl >>> 16) & 0xff; b[i++] = (tl >>> 8) & 0xff; b[i++] = tl & 0xff; // `time_mid` - var tmh = ((msecs / 0x100000000) * 10000) & 0xfffffff; + let tmh = ((msecs / 0x100000000) * 10000) & 0xfffffff; b[i++] = (tmh >>> 8) & 0xff; b[i++] = tmh & 0xff; @@ -192,8 +192,8 @@ function v1(options, buf, offset) { b[i++] = clockseq & 0xff; // `node` - var node = options.node || _nodeId; - for (var n = 0; n < 6; n++) { + let node = options.node || _nodeId; + for (let n = 0; n < 6; n++) { b[i + n] = node[n]; } @@ -205,7 +205,7 @@ function v1(options, buf, offset) { // See https://github.com/broofa/node-uuid for API details function v4(options, buf, offset) { // Deprecated - 'format' argument, as supported in v1.2 - var i = (buf && offset) || 0; + let i = (buf && offset) || 0; if (typeof options == 'string') { buf = options == 'binary' ? new BufferClass(16) : null; @@ -213,7 +213,7 @@ function v4(options, buf, offset) { } options = options || {}; - var rnds = options.random || (options.rng || _rng)(); + let rnds = options.random || (options.rng || _rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved` rnds[6] = (rnds[6] & 0x0f) | 0x40; @@ -221,7 +221,7 @@ function v4(options, buf, offset) { // Copy bytes to buffer, if provided if (buf) { - for (var ii = 0; ii < 16; ii++) { + for (let ii = 0; ii < 16; ii++) { buf[i + ii] = rnds[ii]; } } From f67ed3fd3a09c603fa21e2b4c2bf9026968e1247 Mon Sep 17 00:00:00 2001 From: Ava Gaiety W Date: Fri, 10 May 2024 13:36:24 -0500 Subject: [PATCH 2/3] undoes a portion of the eslintignore change not relevant to this PR --- .eslintignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintignore b/.eslintignore index 39d277caf6..df541335e0 100644 --- a/.eslintignore +++ b/.eslintignore @@ -4,7 +4,7 @@ build/tasks/aria-supported.js doc/api/* -doc/examples/**/*.js +doc/examples/jest_react/*.js lib/core/imports/*.js lib/core/utils/uuid.js From 7131ead44f8e9a30f7ed9847db15f0738c5f02a6 Mon Sep 17 00:00:00 2001 From: Ava Gaiety W Date: Fri, 17 May 2024 12:04:00 -0500 Subject: [PATCH 3/3] fix(all-rules): fix flakey all-rules firefox test wilco and I believe marque is to blame because it is animated --- test/integration/full/all-rules/all-rules.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/full/all-rules/all-rules.html b/test/integration/full/all-rules/all-rules.html index 62eaae44e5..fc982c3fb5 100644 --- a/test/integration/full/all-rules/all-rules.html +++ b/test/integration/full/all-rules/all-rules.html @@ -94,7 +94,7 @@

Ok

Paragraph.

- This content is inside a marquee. + This content is inside a marquee.