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

chore: enable eslint:no-shadow #4089

Merged
merged 7 commits into from
Jul 14, 2023
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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module.exports = {
'dot-notation': 2,
'no-new-func': 0,
'no-new-wrappers': 0,
'no-shadow': 2,
'no-restricted-syntax': [
'error',
{
Expand Down
42 changes: 21 additions & 21 deletions build/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ 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);
options.getFiles = false;
buildManual(grunt, options, commons, function (result) {
buildManual(grunt, options, commons, function (build) {
var metadata = {
rules: {},
checks: {}
Expand Down Expand Up @@ -96,8 +96,8 @@ function buildRules(grunt, options, commons, callback) {
.join('\n');

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

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

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

Expand Down Expand Up @@ -151,8 +151,8 @@ function buildRules(grunt, options, commons, callback) {
}

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

function findCheck(checks, id) {
return checks.filter(function (check) {
function findCheck(checkCollection, id) {
return checkCollection.filter(function (check) {
if (check.id === id) {
return true;
}
Expand Down Expand Up @@ -336,21 +336,21 @@ function buildRules(grunt, options, commons, callback) {
metadata.rules[rule.id] = parseMetaData(rule, 'rules'); // Translate rules
}

var rules;
var result;
if (rule.tags.includes('deprecated')) {
rules = descriptions.deprecated.rules;
result = descriptions.deprecated.rules;
} else if (rule.tags.includes('experimental')) {
rules = descriptions.experimental.rules;
result = descriptions.experimental.rules;
} else if (rule.tags.find(tag => tag.includes('aaa'))) {
rules = descriptions.wcag2aaa.rules;
result = descriptions.wcag2aaa.rules;
} else if (rule.tags.includes('best-practice')) {
rules = descriptions.bestPractice.rules;
result = descriptions.bestPractice.rules;
} else if (rule.tags.find(tag => tag.startsWith('wcag2a'))) {
rules = descriptions.wcag20.rules;
result = descriptions.wcag20.rules;
} else if (rule.tags.find(tag => tag.startsWith('wcag21a'))) {
rules = descriptions.wcag21.rules;
result = descriptions.wcag21.rules;
} else {
rules = descriptions.wcag22.rules;
result = descriptions.wcag22.rules;
}

var issueType = [];
Expand All @@ -363,7 +363,7 @@ function buildRules(grunt, options, commons, callback) {

var actLinks = createActLinksForRule(rule);

rules.push([
result.push([
`[${rule.id}](https://dequeuniversity.com/rules/axe/${axeVersion}/${rule.id}?application=RuleDescription)`,
entities.encode(rule.metadata.description),
impact,
Expand Down Expand Up @@ -408,8 +408,8 @@ ${TOC}
${ruleTables}`;

// Translate failureSummaries
metadata.failureSummaries = createFailureSummaryObject(result.misc);
metadata.incompleteFallbackMessage = getIncompleteMsg(result.misc);
metadata.failureSummaries = createFailureSummaryObject(build.misc);
metadata.incompleteFallbackMessage = getIncompleteMsg(build.misc);

callback({
auto: replaceFunctions(
Expand Down
6 changes: 3 additions & 3 deletions build/tasks/add-locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = function (grunt) {
var commons = file.src[0];

buildManual(grunt, options, commons, function (result) {
var out = {
var locale = {
lang: options.lang,
rules: result.rules.reduce(function (out, rule) {
out[rule.id] = rule.metadata;
Expand Down Expand Up @@ -74,10 +74,10 @@ module.exports = function (grunt) {
var oldMessages = grunt.file.readJSON(localeFile);

// mergeMessages mutates out
mergeMessages(out, oldMessages);
mergeMessages(locale, oldMessages);
}

grunt.file.write(file.dest, JSON.stringify(out, null, ' '));
grunt.file.write(file.dest, JSON.stringify(locale, null, ' '));
console.log('created file at', file.dest);
});
});
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/chrome-debugging-protocol/axe-cdp.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const example = async url => {
// its value (`results.result.value` is undefined). By
// `JSON.stringify()`ing it, we can `JSON.parse()` it later on
// and return a valid results set.
.then(results => JSON.stringify(results))
.then(res => JSON.stringify(res))
.then(resolve)
.catch(reject);
});
Expand Down
26 changes: 9 additions & 17 deletions doc/examples/puppeteer/axe-puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const isValidURL = input => {
return u.protocol && u.host;
};

// node axe-puppeteer.js <url>
const url = process.argv[2];
assert(isValidURL(url), 'Invalid URL');
(async () => {
// node axe-puppeteer.js <url>
const url = process.argv[2];
assert(isValidURL(url), 'Invalid URL');

const main = async url => {
let browser;
let results;
try {
Expand All @@ -34,6 +34,8 @@ const main = async url => {

// Get the results from `axe.run()`.
results = await handle.jsonValue();
console.log(results);

// Destroy the handle & return axe results.
await handle.dispose();
} catch (err) {
Expand All @@ -42,19 +44,9 @@ const main = async url => {
await browser.close();
}

// Re-throw
throw err;
console.error('Error running axe-core:', err.message);
process.exit(1);
}

await browser.close();
return results;
};

main(url)
.then(results => {
console.log(results);
})
.catch(err => {
console.error('Error running axe-core:', err.message);
process.exit(1);
});
})();
12 changes: 5 additions & 7 deletions lib/checks/aria/aria-errormessage-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import { isVisibleToScreenReaders } from '../../commons/dom';
* @memberof checks
* @return {Mixed} True if aria-errormessage references an existing element that uses a supported technique. Undefined if it does not reference an existing element. False otherwise.
*/
function ariaErrormessageEvaluate(node, options, virtualNode) {
export default function ariaErrormessageEvaluate(node, options, virtualNode) {
Copy link
Member

Choose a reason for hiding this comment

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

What is the motivation behind this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Follows our coding guidelines.

If you encounter any code that we maintain that does not put the default export at the top, you should update the file to do so.

Copy link
Member

Choose a reason for hiding this comment

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

What is the motivation behind putting the default export at the top?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ensures that when you open the file the main code path is the first thing you read.

options = Array.isArray(options) ? options : [];

const attr = virtualNode.attr('aria-errormessage');
const errorMessage = virtualNode.attr('aria-errormessage');
straker marked this conversation as resolved.
Show resolved Hide resolved
const hasAttr = virtualNode.hasAttr('aria-errormessage');
const invaid = virtualNode.attr('aria-invalid');
const hasInvallid = virtualNode.hasAttr('aria-invalid');
Expand Down Expand Up @@ -74,12 +74,10 @@ function ariaErrormessageEvaluate(node, options, virtualNode) {
}

// limit results to elements that actually have this attribute
if (options.indexOf(attr) === -1 && hasAttr) {
this.data(tokenList(attr));
return validateAttrValue.call(this, attr);
if (options.indexOf(errorMessage) === -1 && hasAttr) {
this.data(tokenList(errorMessage));
return validateAttrValue.call(this, errorMessage);
straker marked this conversation as resolved.
Show resolved Hide resolved
}

return true;
}

export default ariaErrormessageEvaluate;
15 changes: 5 additions & 10 deletions lib/checks/aria/aria-required-children-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export default function ariaRequiredChildrenEvaluate(
) {
const reviewEmpty =
options && Array.isArray(options.reviewEmpty) ? options.reviewEmpty : [];
const role = getExplicitRole(virtualNode, { dpub: true });
const required = requiredOwned(role);
const explicitRole = getExplicitRole(virtualNode, { dpub: true });
const required = requiredOwned(explicitRole);
if (required === null) {
return true;
}
Expand All @@ -51,20 +51,15 @@ export default function ariaRequiredChildrenEvaluate(
return false;
}

const missing = missingRequiredChildren(
virtualNode,
role,
required,
ownedRoles
);
const missing = missingRequiredChildren(virtualNode, required, ownedRoles);
if (!missing) {
return true;
}

this.data(missing);

// Only review empty nodes when a node is both empty and does not have an aria-owns relationship
if (reviewEmpty.includes(role) && !ownedElements.some(isContent)) {
if (reviewEmpty.includes(explicitRole) && !ownedElements.some(isContent)) {
return undefined;
}

Expand Down Expand Up @@ -117,7 +112,7 @@ function getOwnedRoles(virtualNode, required) {
/**
* Get missing children roles
*/
function missingRequiredChildren(virtualNode, role, required, ownedRoles) {
function missingRequiredChildren(virtualNode, required, ownedRoles) {
for (let i = 0; i < ownedRoles.length; i++) {
const { role } = ownedRoles[i];

Expand Down
10 changes: 4 additions & 6 deletions lib/checks/lists/only-dlitems-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import { getRole, getExplicitRole } from '../../commons/aria';
/**
* @deprecated
*/
function onlyDlitemsEvaluate(node, options, virtualNode) {
export default function onlyDlitemsEvaluate(node, options, virtualNode) {
const ALLOWED_ROLES = ['definition', 'term', 'list'];
const base = {
badNodes: [],
hasNonEmptyTextNode: false
};

const content = virtualNode.children.reduce((content, child) => {
const content = virtualNode.children.reduce((vNodes, child) => {
const { actualNode } = child;
if (
actualNode.nodeName.toUpperCase() === 'DIV' &&
getRole(actualNode) === null
) {
return content.concat(child.children);
return vNodes.concat(child.children);
}
return content.concat(child);
return vNodes.concat(child);
}, []);

const result = content.reduce((out, childNode) => {
Expand Down Expand Up @@ -50,5 +50,3 @@ function onlyDlitemsEvaluate(node, options, virtualNode) {

return !!result.badNodes.length || result.hasNonEmptyTextNode;
}

export default onlyDlitemsEvaluate;
13 changes: 4 additions & 9 deletions lib/checks/tables/td-headers-attr-evaluate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { tokenList } from '../../core/utils';
import { isVisibleToScreenReaders } from '../../commons/dom';

function tdHeadersAttrEvaluate(node) {
export default function tdHeadersAttrEvaluate(node) {
const cells = [];
const reviewCells = [];
const badCells = [];
Expand All @@ -14,12 +14,9 @@ function tdHeadersAttrEvaluate(node) {
}
}

const ids = cells.reduce((ids, cell) => {
if (cell.getAttribute('id')) {
ids.push(cell.getAttribute('id'));
}
return ids;
}, []);
const ids = cells
.filter(cell => cell.getAttribute('id'))
.map(cell => cell.getAttribute('id'));
Comment on lines +17 to +19
Copy link
Member

Choose a reason for hiding this comment

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

This is much easier to read/understand 👍


cells.forEach(cell => {
let isSelf = false;
Expand Down Expand Up @@ -64,5 +61,3 @@ function tdHeadersAttrEvaluate(node) {

return true;
}

export default tdHeadersAttrEvaluate;
8 changes: 4 additions & 4 deletions lib/commons/color/stacking-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ import flattenColors from './flatten-colors';
* @return {Object}
*/
export function getStackingContext(elm, elmStack) {
const vNode = getNodeFromTree(elm);
if (vNode._stackingContext) {
return vNode._stackingContext;
const virtualNode = getNodeFromTree(elm);
if (virtualNode._stackingContext) {
return virtualNode._stackingContext;
}

const stackingContext = [];
Expand Down Expand Up @@ -108,7 +108,7 @@ export function getStackingContext(elm, elmStack) {
context.bgColor = bgColor;
});

vNode._stackingContext = stackingContext;
virtualNode._stackingContext = stackingContext;
return stackingContext;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/commons/dom/create-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ function findScrollRegionParent(vNode, parentVNode) {
// cache result of parent scroll region so we don't have to look up the entire
// tree again for a child node
checkedNodes.forEach(
vNode => (vNode._scrollRegionParent = scrollRegionParent)
virtualNode => (virtualNode._scrollRegionParent = scrollRegionParent)
);
return scrollRegionParent;
}
Expand Down
8 changes: 3 additions & 5 deletions lib/commons/matches/condition.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
* ```
*
* @param {any} argument
* @param {Function|Null|undefined} condition
* @param {Function|Null|undefined} matcher
* @returns {Boolean}
*/
function condition(arg, condition) {
return !!condition(arg);
export default function condition(arg, matcher) {
return !!matcher(arg);
}

export default condition;
4 changes: 2 additions & 2 deletions lib/commons/math/split-rects.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
export default function splitRects(outerRect, overlapRects) {
let uniqueRects = [outerRect];
for (const overlapRect of overlapRects) {
uniqueRects = uniqueRects.reduce((uniqueRects, inputRect) => {
return uniqueRects.concat(splitRect(inputRect, overlapRect));
uniqueRects = uniqueRects.reduce((rects, inputRect) => {
return rects.concat(splitRect(inputRect, overlapRect));
}, []);
}
return uniqueRects;
Expand Down
Loading