Skip to content

Commit

Permalink
style(lib/core): var -> let and const codemod (#4457)
Browse files Browse the repository at this point in the history
Just like #4451 but for
`lib/core`

This does add an `.eslintignore` line, perhaps we'd rather skip a file a
different way.

Smaller part of the full vision:
#4444
  • Loading branch information
gaiety-deque committed Jun 6, 2024
1 parent e32f803 commit 68bae74
Show file tree
Hide file tree
Showing 41 changed files with 202 additions and 188 deletions.
12 changes: 12 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
**/node_modules/*
**/tmp/*

build/tasks/aria-supported.js

doc/api/*
doc/examples/jest_react/*.js

lib/core/imports/*.js
lib/core/utils/uuid.js
axe.js
axe.min.js
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ module.exports = [
'doc/api/*',
'doc/examples/jest_react/*.js',
'lib/core/imports/*.js',
'lib/core/utils/uuid.js',
'axe.js',
'axe.min.js'
]
Expand Down
10 changes: 5 additions & 5 deletions lib/core/base/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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(
Expand All @@ -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 => {
Expand Down Expand Up @@ -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] = {};
Expand Down
2 changes: 1 addition & 1 deletion lib/core/base/context/create-frame-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/core/base/context/normalize-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down
34 changes: 17 additions & 17 deletions lib/core/base/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 => {
Expand Down
46 changes: 23 additions & 23 deletions lib/core/imports/polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand All @@ -132,7 +132,7 @@ if (!Array.prototype.includes) {
k = 0;
}
}
var currentElement;
let currentElement;
while (k < len) {
currentElement = O[k];
if (
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions lib/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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';
Expand Down
8 changes: 4 additions & 4 deletions lib/core/public/cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand All @@ -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) => {
Expand Down
3 changes: 1 addition & 2 deletions lib/core/public/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
6 changes: 3 additions & 3 deletions lib/core/public/get-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
*/
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 => {
return item.tags.indexOf(tag) !== -1;
}).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,
Expand Down
8 changes: 4 additions & 4 deletions lib/core/public/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
4 changes: 2 additions & 2 deletions lib/core/public/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/core/public/reset.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
Loading

0 comments on commit 68bae74

Please sign in to comment.