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

style: var -> let and const codemod #4444

Closed
wants to merge 9 commits into from
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ doc/api/*
doc/examples/jest_react/*.js

lib/core/imports/*.js
lib/core/utils/uuid.js
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really our code, maybe belongs in a vendor file? Felt weird touching it.

axe.js
axe.min.js
axe.min.js
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module.exports = {
'no-new-func': 0,
'no-new-wrappers': 0,
'no-shadow': 2,
'no-var': 'error',
'no-restricted-syntax': [
'error',
{
Expand Down
6 changes: 3 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var execSync = require('child_process').execSync;
let execSync = require('child_process').execSync;

/*eslint
camelcase: ["error", {"properties": "never"}]
Expand All @@ -14,14 +14,14 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-bytesize');
grunt.loadTasks('build/tasks');

var langs;
let langs;
if (grunt.option('lang')) {
langs = (grunt.option('lang') || '').split(/[,;]/g).map(function (lang) {
lang = lang.trim();
return lang !== 'en' ? '.' + lang : '';
});
} else if (grunt.option('all-lang')) {
var localeFiles = require('fs').readdirSync('./locales');
let localeFiles = require('fs').readdirSync('./locales');
langs = localeFiles.map(function (file) {
return '.' + file.replace('.json', '');
});
Expand Down
10 changes: 5 additions & 5 deletions build/build-manual.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*eslint-env node */
'use strict';

var path = require('path');
var templates = require('./templates');
let path = require('path');
let templates = require('./templates');

module.exports = function build(grunt, options, commons, callback) {
options.getFiles = options.hasOwnProperty('getFiles')
? options.getFiles
: true;

function parseObject(src) {
var files = grunt.file.expand(src);
let files = grunt.file.expand(src);
return files.map(function (file) {
var json = grunt.file.readJSON(file);
var dirname = path.dirname(file);
let json = grunt.file.readJSON(file);
let dirname = path.dirname(file);
Object.keys(templates).forEach(function (templateName) {
if (json[templateName] && json[templateName].endsWith('.js')) {
json[templateName] = path.resolve(dirname, json[templateName]);
Expand Down
94 changes: 47 additions & 47 deletions build/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
/*eslint max-len: off */
'use strict';

var clone = require('clone');
var doT = require('@deque/dot');
var templates = require('./templates');
var buildManual = require('./build-manual');
var { encode } = require('html-entities');
var packageJSON = require('../package.json');
var doTRegex = /\{\{.+?\}\}/g;

var axeVersion = packageJSON.version.substring(
let clone = require('clone');
let doT = require('@deque/dot');
let templates = require('./templates');
let buildManual = require('./build-manual');
let { encode } = require('html-entities');
let packageJSON = require('../package.json');
let doTRegex = /\{\{.+?\}\}/g;

let axeVersion = packageJSON.version.substring(
0,
packageJSON.version.lastIndexOf('.')
);

var descriptionTableHeader =
let descriptionTableHeader =
'| Rule ID | Description | Impact | Tags | Issue Type | ACT Rules |\n| :------- | :------- | :------- | :------- | :------- | :------- |\n';

// prevent striping newline characters from strings (e.g. failure
// summaries). must be synced with lib/core/imports/index.js
doT.templateSettings.strip = false;

function getLocale(grunt, options) {
var localeFile;
let localeFile;
if (options.locale) {
localeFile = './locales/' + options.locale + '.json';
}
Expand All @@ -38,15 +38,15 @@ function makeHeaderLink(title) {
}

function buildRules(grunt, options, commons, callback) {
var axeImpact = Object.freeze(['minor', 'moderate', 'serious', 'critical']); // TODO: require('../axe') does not work if grunt configure is moved after uglify, npm test breaks with undefined. Complicated grunt concurrency issue.
var locale = getLocale(grunt, options);
let axeImpact = Object.freeze(['minor', 'moderate', 'serious', 'critical']); // TODO: require('../axe') does not work if grunt configure is moved after uglify, npm test breaks with undefined. Complicated grunt concurrency issue.
let locale = getLocale(grunt, options);
options.getFiles = false;
buildManual(grunt, options, commons, function (build) {
var metadata = {
let metadata = {
rules: {},
checks: {}
};
var descriptions = {
let descriptions = {
wcag20: {
title: 'WCAG 2.0 Level A & AA Rules',
rules: []
Expand Down Expand Up @@ -87,17 +87,17 @@ function buildRules(grunt, options, commons, callback) {
}
};

var TOC = Object.keys(descriptions)
let TOC = Object.keys(descriptions)
.map(key => {
return `- [${descriptions[key].title}](#${makeHeaderLink(
descriptions[key].title
)})`;
})
.join('\n');

var tags = options.tags ? options.tags.split(/\s*,\s*/) : [];
var rules = build.rules;
var checks = build.checks;
let tags = options.tags ? options.tags.split(/\s*,\s*/) : [];
let rules = build.rules;
let checks = build.checks;

// Translate checks before parsing them so that translations
// get applied to the metadata object
Expand All @@ -112,12 +112,12 @@ function buildRules(grunt, options, commons, callback) {
parseChecks(checks);

function parseMetaData(source, propType) {
var data = source.metadata;
var id = source.id || source.type;
let data = source.metadata;
let id = source.id || source.type;
if (id && locale && locale[propType] && propType !== 'checks') {
data = locale[propType][id] || data;
}
var result = clone(data) || {};
let result = clone(data) || {};

if (result.messages) {
Object.keys(result.messages).forEach(function (key) {
Expand All @@ -141,7 +141,7 @@ function buildRules(grunt, options, commons, callback) {
}

function createFailureSummaryObject(summaries) {
var result = {};
let result = {};
summaries.forEach(function (summary) {
if (summary.type) {
result[summary.type] = parseMetaData(summary, 'failureSummaries');
Expand All @@ -151,7 +151,7 @@ function buildRules(grunt, options, commons, callback) {
}

function getIncompleteMsg(summaries) {
var summary = summaries.find(function (element) {
let summary = summaries.find(function (element) {
return typeof element.incompleteFallbackMessage === 'string';
});
return summary ? summary.incompleteFallbackMessage : '';
Expand Down Expand Up @@ -201,9 +201,9 @@ function buildRules(grunt, options, commons, callback) {

function parseChecks(collection) {
return collection.map(function (check) {
var c = {};
var id = typeof check === 'string' ? check : check.id;
var definition = clone(findCheck(checks, id));
let c = {};
let id = typeof check === 'string' ? check : check.id;
let definition = clone(findCheck(checks, id));
if (!definition) {
grunt.log.error('check ' + id + ' not found');
}
Expand All @@ -220,8 +220,8 @@ function buildRules(grunt, options, commons, callback) {

function traverseChecks(checkCollection, predicate, startValue) {
return checkCollection.reduce(function (out, check) {
var id = typeof check === 'string' ? check : check.id;
var definition = clone(findCheck(checks, id));
let id = typeof check === 'string' ? check : check.id;
let definition = clone(findCheck(checks, id));
if (!definition) {
grunt.log.error('check ' + id + ' not found');
}
Expand All @@ -245,14 +245,14 @@ function buildRules(grunt, options, commons, callback) {

function getImpactScores(definition, out) {
if (definition && definition.metadata && definition.metadata.impact) {
var impactScore = axeImpact.indexOf(definition.metadata.impact);
let impactScore = axeImpact.indexOf(definition.metadata.impact);
out.push(impactScore);
}
return out;
}

function getScore(checkCollection, onlyHighestScore) {
var scores = traverseChecks(checkCollection, getImpactScores, []);
let scores = traverseChecks(checkCollection, getImpactScores, []);
if (scores && scores.length) {
return onlyHighestScore
? [Math.max.apply(null, scores)]
Expand All @@ -262,13 +262,13 @@ function buildRules(grunt, options, commons, callback) {
}
}

var highestImpactForRuleTypeAny = getScore(rule.any, true);
var allUniqueImpactsForRuleTypeAll = getScore(rule.all, false);
var allUniqueImpactsForRuleTypeNone = getScore(rule.none, false);
var cumulativeImpacts = highestImpactForRuleTypeAny
let highestImpactForRuleTypeAny = getScore(rule.any, true);
let allUniqueImpactsForRuleTypeAll = getScore(rule.all, false);
let allUniqueImpactsForRuleTypeNone = getScore(rule.none, false);
let cumulativeImpacts = highestImpactForRuleTypeAny
.concat(allUniqueImpactsForRuleTypeAll)
.concat(allUniqueImpactsForRuleTypeNone);
var cumulativeScores = getUniqueArr(cumulativeImpacts).sort(); //order lowest to highest
let cumulativeScores = getUniqueArr(cumulativeImpacts).sort(); //order lowest to highest

return cumulativeScores.reduce(function (out, cV) {
return out.length
Expand Down Expand Up @@ -316,18 +316,18 @@ function buildRules(grunt, options, commons, callback) {
}

function createActLinksForRule(rule) {
var actIds = rule.actIds || [];
var actLinks = [];
let actIds = rule.actIds || [];
let actLinks = [];
actIds.forEach(id =>
actLinks.push(`[${id}](https://act-rules.github.io/rules/${id})`)
);
return actLinks.join(', ');
}

rules.map(function (rule) {
var impact = parseImpactForRule(rule);
var canFail = parseFailureForRule(rule);
var canIncomplete = parseIncompleteForRule(rule);
let impact = parseImpactForRule(rule);
let canFail = parseFailureForRule(rule);
let canIncomplete = parseIncompleteForRule(rule);

rule.any = parseChecks(rule.any);
rule.all = parseChecks(rule.all);
Expand All @@ -336,7 +336,7 @@ function buildRules(grunt, options, commons, callback) {
metadata.rules[rule.id] = parseMetaData(rule, 'rules'); // Translate rules
}

var result;
let result;
if (rule.tags.includes('deprecated')) {
result = descriptions.deprecated.rules;
} else if (rule.tags.includes('experimental')) {
Expand All @@ -353,15 +353,15 @@ function buildRules(grunt, options, commons, callback) {
result = descriptions.wcag22.rules;
}

var issueType = [];
let issueType = [];
if (canFail) {
issueType.push('failure');
}
if (canIncomplete) {
issueType.push('needs review');
}

var actLinks = createActLinksForRule(rule);
let actLinks = createActLinksForRule(rule);

result.push([
`[${rule.id}](https://dequeuniversity.com/rules/axe/${axeVersion}/${rule.id}?application=RuleDescription)`,
Expand All @@ -379,9 +379,9 @@ function buildRules(grunt, options, commons, callback) {
return rule;
});

var ruleTables = Object.keys(descriptions)
let ruleTables = Object.keys(descriptions)
.map(key => {
var description = descriptions[key];
let description = descriptions[key];

return `
## ${description.title}
Expand All @@ -400,7 +400,7 @@ ${
})
.join('\n\n');

var descriptions = `
descriptions = `
<!--- This file is automatically generated using build/configure.js --->

# Rule Descriptions
Expand Down
22 changes: 11 additions & 11 deletions build/sri-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,32 @@
* update sri-history.json with the SRIs of axe{.*}.js.
* @deprecated
*/
var path = require('path');
var fs = require('fs');
var sriToolbox = require('sri-toolbox');
let path = require('path');
let fs = require('fs');
let sriToolbox = require('sri-toolbox');

// Check if we should be validating or updating
var validate = process.argv.some(function (arg) {
let validate = process.argv.some(function (arg) {
return arg === '--validate';
});

var root = path.join(__dirname, '..');
var axeVersion = require('../package.json').version;
var axeHistory = require('../sri-history.json');
let root = path.join(__dirname, '..');
let axeVersion = require('../package.json').version;
let axeHistory = require('../sri-history.json');

if (typeof axeHistory[axeVersion] !== 'object') {
axeHistory[axeVersion] = {};
}
var versionSRIs = axeHistory[axeVersion];
let versionSRIs = axeHistory[axeVersion];

// List all axe files (including minified and localized axe files)
var axeFiles = fs.readdirSync(root).filter(function (file) {
let axeFiles = fs.readdirSync(root).filter(function (file) {
return file.match(/^axe(\.[a-z.-]+)?\.js$/);
});

axeFiles.forEach(function (axeFile) {
var axeSource = fs.readFileSync(path.join(root, axeFile), 'utf-8');
var axeIntegrity = sriToolbox.generate({ algorithms: ['sha256'] }, axeSource);
let axeSource = fs.readFileSync(path.join(root, axeFile), 'utf-8');
let axeIntegrity = sriToolbox.generate({ algorithms: ['sha256'] }, axeSource);

if (!validate) {
// Update SRI
Expand Down
Loading
Loading