Skip to content

Commit

Permalink
chore: update eslint to include func-names and prefer-const (#2700)
Browse files Browse the repository at this point in the history
  • Loading branch information
straker committed Dec 17, 2020
1 parent e6dc79e commit f2a2ff6
Show file tree
Hide file tree
Showing 72 changed files with 317 additions and 320 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = {
'no-cond-assign': 0,
'no-debugger': 2,
'no-eq-null': 0,
'no-eval': 0,
'no-eval': 2,
'no-unused-expressions': 0,
'block-scoped-var': 0,
'no-iterator': 0,
Expand Down Expand Up @@ -79,6 +79,10 @@ module.exports = {
globals: {
window: true,
document: true
},
rules: {
'func-names': [2, 'as-needed'],
'prefer-const': 2
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions lib/checks/aria/aria-required-children-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ function getOwnedRoles(virtualNode, required) {
const ownedRoles = [];
const ownedElements = getOwnedVirtual(virtualNode);
for (let i = 0; i < ownedElements.length; i++) {
let ownedElement = ownedElements[i];
let role = getRole(ownedElement, { noPresentational: true });
const ownedElement = ownedElements[i];
const role = getRole(ownedElement, { noPresentational: true });

// if owned node has no role or is presentational, or if role
// allows group or rowgroup, we keep parsing the descendant tree.
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/aria/aria-required-parent-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function getAriaOwners(element) {
while (element) {
if (element.getAttribute('id')) {
const id = escapeSelector(element.getAttribute('id'));
let doc = getRootNode(element);
const doc = getRootNode(element);
o = doc.querySelector(`[aria-owns~=${id}]`);
if (o) {
owners.push(o);
Expand Down
4 changes: 2 additions & 2 deletions lib/checks/keyboard/accesskeys-after.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function accesskeysAfter(results) {
var seen = {};
return results
.filter(function(r) {
.filter(r => {
if (!r.data) {
return false;
}
Expand All @@ -14,7 +14,7 @@ function accesskeysAfter(results) {
seen[key].relatedNodes.push(r.relatedNodes[0]);
return false;
})
.map(function(r) {
.map(r => {
r.result = !!r.relatedNodes.length;
return r;
});
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/label/help-same-as-label-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function helpSameAsLabelEvaluate(node, options, virtualNode) {
if (node.getAttribute('aria-describedby')) {
var ref = idrefs(node, 'aria-describedby');
check = ref
.map(function(thing) {
.map(thing => {
return thing ? accessibleText(thing) : '';
})
.join('');
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/lists/only-dlitems-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getRole, getExplicitRole } from '../../commons/aria';

function onlyDlitemsEvaluate(node, options, virtualNode) {
const ALLOWED_ROLES = ['definition', 'term', 'list'];
let base = {
const base = {
badNodes: [],
hasNonEmptyTextNode: false
};
Expand Down
6 changes: 3 additions & 3 deletions lib/checks/lists/only-listitems-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ function onlyListitemsEvaluate(node, options, virtualNode) {
let hasNonEmptyTextNode = false;
let atLeastOneListitem = false;
let isEmpty = true;
let badNodes = [];
let badRoleNodes = [];
let badRoles = [];
const badNodes = [];
const badRoleNodes = [];
const badRoles = [];

virtualNode.children.forEach(vNode => {
const { actualNode } = vNode;
Expand Down
6 changes: 3 additions & 3 deletions lib/checks/media/frame-tested-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ function frameTestedEvaluate(node, options) {
);

// give the frame .5s to respond to 'axe.ping', else log failed response
let timer = setTimeout(function() {
let timer = setTimeout(() => {
// This double timeout is important for allowing iframes to respond
// DO NOT REMOVE
timer = setTimeout(function() {
timer = setTimeout(() => {
timer = null;
resolve(isViolation ? false : undefined);
}, 0);
}, timeout);

respondable(node.contentWindow, 'axe.ping', null, undefined, function() {
respondable(node.contentWindow, 'axe.ping', null, undefined, () => {
if (timer !== null) {
clearTimeout(timer);
resolve(true);
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/media/no-autoplay-audio-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function noAutoplayAudioEvaluate(node, options) {
* @param {String} hhMmSs time expressed in HH:MM:SS
*/
function convertHourMinSecToSeconds(hhMmSs) {
let parts = hhMmSs.split(':');
const parts = hhMmSs.split(':');
let secs = 0;
let mins = 1;

Expand Down
16 changes: 8 additions & 8 deletions lib/checks/navigation/p-as-heading-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function normalizeFontWeight(weight) {

function getTextContainer(elm) {
let nextNode = elm;
let outerText = elm.textContent.trim();
const outerText = elm.textContent.trim();
let innerText = outerText;

while (innerText === outerText && nextNode !== undefined) {
Expand All @@ -39,7 +39,7 @@ function getTextContainer(elm) {
}

function getStyleValues(node) {
let style = window.getComputedStyle(getTextContainer(node));
const style = window.getComputedStyle(getTextContainer(node));
return {
fontWeight: normalizeFontWeight(style.getPropertyValue('font-weight')),
fontSize: parseInt(style.getPropertyValue('font-size')),
Expand All @@ -60,17 +60,17 @@ function isHeaderStyle(styleA, styleB, margins) {
}

function pAsHeadingEvaluate(node, options, virtualNode) {
let siblings = Array.from(node.parentNode.children);
let currentIndex = siblings.indexOf(node);
const siblings = Array.from(node.parentNode.children);
const currentIndex = siblings.indexOf(node);

options = options || {};
let margins = options.margins || [];
const margins = options.margins || [];

let nextSibling = siblings
const nextSibling = siblings
.slice(currentIndex + 1)
.find(elm => elm.nodeName.toUpperCase() === 'P');

let prevSibling = siblings
const prevSibling = siblings
.slice(0, currentIndex)
.reverse()
.find(elm => elm.nodeName.toUpperCase() === 'P');
Expand All @@ -83,7 +83,7 @@ function pAsHeadingEvaluate(node, options, virtualNode) {
return true;
}

let blockquote = findUpVirtual(virtualNode, 'blockquote');
const blockquote = findUpVirtual(virtualNode, 'blockquote');
if (blockquote && blockquote.nodeName.toUpperCase() === 'BLOCKQUOTE') {
return undefined;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/checks/navigation/unique-frame-title-after.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function uniqueFrameTitleAfter(results) {
var titles = {};
results.forEach(function(r) {
results.forEach(r => {
titles[r.data] = titles[r.data] !== undefined ? ++titles[r.data] : 0;
});
results.forEach(function(r) {
results.forEach(r => {
r.result = !!titles[r.data];
});

Expand Down
2 changes: 1 addition & 1 deletion lib/checks/parsing/duplicate-id-after.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function duplicateIdAfter(results) {
var uniqueIds = [];
return results.filter(function(r) {
return results.filter(r => {
if (uniqueIds.indexOf(r.data) === -1) {
uniqueIds.push(r.data);
return true;
Expand Down
6 changes: 3 additions & 3 deletions lib/checks/shared/non-empty-if-present-evaluate.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function nonEmptyIfPresentEvaluate(node, options, virtualNode) {
// Check for 'default' names, which are given to reset and submit buttons
let nodeName = virtualNode.props.nodeName;
let type = (virtualNode.attr('type') || '').toLowerCase();
let label = virtualNode.attr('value');
const nodeName = virtualNode.props.nodeName;
const type = (virtualNode.attr('type') || '').toLowerCase();
const label = virtualNode.attr('value');

if (label) {
this.data({
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/tables/caption-faked-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function captionFakedEvaluate(node) {
return true;
}

return firstRow.reduce(function(out, curr, i) {
return firstRow.reduce((out, curr, i) => {
return out || (curr !== firstRow[i + 1] && firstRow[i + 1] !== undefined);
}, false);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/checks/tables/th-has-data-cells-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function thHasDataCellsEvaluate(node) {

// Get a list of all headers reffed to in this rule
let reffedHeaders = [];
cells.forEach(function(cell) {
cells.forEach(cell => {
const headers = cell.getAttribute('headers');
if (headers) {
reffedHeaders = reffedHeaders.concat(headers.split(/\s+/));
Expand All @@ -20,7 +20,7 @@ function thHasDataCellsEvaluate(node) {
});

// Get all the headers
const headers = cells.filter(function(cell) {
const headers = cells.filter(cell => {
if (sanitize(cell.textContent) === '') {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/commons/aria/label-virtual.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function labelVirtual(virtualNode) {
// aria-labelledby
ref = idrefs(virtualNode.actualNode, 'aria-labelledby');
candidate = ref
.map(function(thing) {
.map(thing => {
const vNode = getNodeFromTree(thing);
return vNode ? visibleVirtual(vNode, true) : '';
})
Expand Down
2 changes: 1 addition & 1 deletion lib/commons/aria/validate-attr-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function validateAttrValue(node, attr) {
case 'nmtokens':
list = tokenList(value);
// Check if any value isn't in the list of values
return list.reduce(function(result, token) {
return list.reduce((result, token) => {
return result && attrInfo.values.includes(token);
// Initial state, fail if the list is empty
}, list.length !== 0);
Expand Down
10 changes: 5 additions & 5 deletions lib/commons/color/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function Color(red, green, blue, alpha) {
* @instance
* @return {string}
*/
this.toHexString = function() {
this.toHexString = function toHexString() {
var redString = Math.round(this.red).toString(16);
var greenString = Math.round(this.green).toString(16);
var blueString = Math.round(this.blue).toString(16);
Expand All @@ -113,7 +113,7 @@ function Color(red, green, blue, alpha) {
* @memberof axe.commons.color.Color
* @instance
*/
this.parseString = function(colorString) {
this.parseString = function parseString(colorString) {
// IE occasionally returns named colors instead of RGB(A) values
if (standards.cssColors[colorString] || colorString === 'transparent') {
const [red, green, blue] = standards.cssColors[colorString] || [0, 0, 0];
Expand Down Expand Up @@ -144,7 +144,7 @@ function Color(red, green, blue, alpha) {
* @instance
* @param {string} rgb The string value
*/
this.parseRgbString = function(colorString) {
this.parseRgbString = function parseRgbString(colorString) {
// IE can pass transparent as value instead of rgba
if (colorString === 'transparent') {
this.red = 0;
Expand All @@ -164,7 +164,7 @@ function Color(red, green, blue, alpha) {
* @instance
* @param {string} rgb The string value
*/
this.parseHexString = function(colorString) {
this.parseHexString = function parseHexString(colorString) {
if (!colorString.match(hexRegex) || [6, 8].includes(colorString.length)) {
return;
}
Expand Down Expand Up @@ -231,7 +231,7 @@ function Color(red, green, blue, alpha) {
* @instance
* @return {number} The luminance value, ranges from 0 to 1
*/
this.getRelativeLuminance = function() {
this.getRelativeLuminance = function getRelativeLuminance() {
var rSRGB = this.red / 255;
var gSRGB = this.green / 255;
var bSRGB = this.blue / 255;
Expand Down
35 changes: 17 additions & 18 deletions lib/commons/color/element-is-distinct.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function _getFonts(style) {
return style
.getPropertyValue('font-family')
.split(/[,;]/g)
.map(function(font) {
.map(font => {
return font.trim().toLowerCase();
});
}
Expand All @@ -33,23 +33,22 @@ function elementIsDistinct(node, ancestorNode) {
}

// Check if the link has a border or outline
var hasBorder = ['border-bottom', 'border-top', 'outline'].reduce(function(
result,
edge
) {
var borderClr = new Color();
borderClr.parseString(nodeStyle.getPropertyValue(edge + '-color'));
var hasBorder = ['border-bottom', 'border-top', 'outline'].reduce(
(result, edge) => {
var borderClr = new Color();
borderClr.parseString(nodeStyle.getPropertyValue(edge + '-color'));

// Check if a border/outline was specified
return (
result ||
// or if the current border edge / outline
(nodeStyle.getPropertyValue(edge + '-style') !== 'none' &&
parseFloat(nodeStyle.getPropertyValue(edge + '-width')) > 0 &&
borderClr.alpha !== 0)
);
},
false);
// Check if a border/outline was specified
return (
result ||
// or if the current border edge / outline
(nodeStyle.getPropertyValue(edge + '-style') !== 'none' &&
parseFloat(nodeStyle.getPropertyValue(edge + '-width')) > 0 &&
borderClr.alpha !== 0)
);
},
false
);

if (hasBorder) {
return true;
Expand All @@ -67,7 +66,7 @@ function elementIsDistinct(node, ancestorNode) {
'font-weight',
'font-style',
'font-size'
].reduce(function(result, cssProp) {
].reduce((result, cssProp) => {
return (
result ||
nodeStyle.getPropertyValue(cssProp) !==
Expand Down
2 changes: 1 addition & 1 deletion lib/commons/color/filtered-rect-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function filteredRectStack(elm) {
return;
}
// if the stacks are the same, use the first one. otherwise, return null.
let rectA = rectStack[index - 1],
const rectA = rectStack[index - 1],
rectB = rectStack[index];

// if elements in clientRects are the same
Expand Down
4 changes: 2 additions & 2 deletions lib/commons/color/get-background-color.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ function elmPartiallyObscured(elm, bgElm, bgColor) {
*/
function getBackgroundColor(elm, bgElms = [], shadowOutlineEmMax = 0.1) {
let bgColors = getTextShadowColors(elm, { minRatio: shadowOutlineEmMax });
let elmStack = getBackgroundStack(elm);
const elmStack = getBackgroundStack(elm);

// Search the stack until we have an alpha === 1 background
(elmStack || []).some(bgElm => {
const bgElmStyle = window.getComputedStyle(bgElm);

// Get the background color
let bgColor = getOwnBackgroundColor(bgElmStyle);
const bgColor = getOwnBackgroundColor(bgElmStyle);

if (
// abort if a node is partially obscured and obscuring element has a background
Expand Down
Loading

0 comments on commit f2a2ff6

Please sign in to comment.