Skip to content

Commit f2a2ff6

Browse files
authored
chore: update eslint to include func-names and prefer-const (dequelabs#2700)
1 parent e6dc79e commit f2a2ff6

File tree

72 files changed

+317
-320
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+317
-320
lines changed

.eslintrc.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module.exports = {
3838
'no-cond-assign': 0,
3939
'no-debugger': 2,
4040
'no-eq-null': 0,
41-
'no-eval': 0,
41+
'no-eval': 2,
4242
'no-unused-expressions': 0,
4343
'block-scoped-var': 0,
4444
'no-iterator': 0,
@@ -79,6 +79,10 @@ module.exports = {
7979
globals: {
8080
window: true,
8181
document: true
82+
},
83+
rules: {
84+
'func-names': [2, 'as-needed'],
85+
'prefer-const': 2
8286
}
8387
},
8488
{

lib/checks/aria/aria-required-children-evaluate.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ function getOwnedRoles(virtualNode, required) {
1313
const ownedRoles = [];
1414
const ownedElements = getOwnedVirtual(virtualNode);
1515
for (let i = 0; i < ownedElements.length; i++) {
16-
let ownedElement = ownedElements[i];
17-
let role = getRole(ownedElement, { noPresentational: true });
16+
const ownedElement = ownedElements[i];
17+
const role = getRole(ownedElement, { noPresentational: true });
1818

1919
// if owned node has no role or is presentational, or if role
2020
// allows group or rowgroup, we keep parsing the descendant tree.

lib/checks/aria/aria-required-parent-evaluate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function getAriaOwners(element) {
3838
while (element) {
3939
if (element.getAttribute('id')) {
4040
const id = escapeSelector(element.getAttribute('id'));
41-
let doc = getRootNode(element);
41+
const doc = getRootNode(element);
4242
o = doc.querySelector(`[aria-owns~=${id}]`);
4343
if (o) {
4444
owners.push(o);

lib/checks/keyboard/accesskeys-after.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function accesskeysAfter(results) {
22
var seen = {};
33
return results
4-
.filter(function(r) {
4+
.filter(r => {
55
if (!r.data) {
66
return false;
77
}
@@ -14,7 +14,7 @@ function accesskeysAfter(results) {
1414
seen[key].relatedNodes.push(r.relatedNodes[0]);
1515
return false;
1616
})
17-
.map(function(r) {
17+
.map(r => {
1818
r.result = !!r.relatedNodes.length;
1919
return r;
2020
});

lib/checks/label/help-same-as-label-evaluate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function helpSameAsLabelEvaluate(node, options, virtualNode) {
1515
if (node.getAttribute('aria-describedby')) {
1616
var ref = idrefs(node, 'aria-describedby');
1717
check = ref
18-
.map(function(thing) {
18+
.map(thing => {
1919
return thing ? accessibleText(thing) : '';
2020
})
2121
.join('');

lib/checks/lists/only-dlitems-evaluate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getRole, getExplicitRole } from '../../commons/aria';
33

44
function onlyDlitemsEvaluate(node, options, virtualNode) {
55
const ALLOWED_ROLES = ['definition', 'term', 'list'];
6-
let base = {
6+
const base = {
77
badNodes: [],
88
hasNonEmptyTextNode: false
99
};

lib/checks/lists/only-listitems-evaluate.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ function onlyListitemsEvaluate(node, options, virtualNode) {
55
let hasNonEmptyTextNode = false;
66
let atLeastOneListitem = false;
77
let isEmpty = true;
8-
let badNodes = [];
9-
let badRoleNodes = [];
10-
let badRoles = [];
8+
const badNodes = [];
9+
const badRoleNodes = [];
10+
const badRoles = [];
1111

1212
virtualNode.children.forEach(vNode => {
1313
const { actualNode } = vNode;

lib/checks/media/frame-tested-evaluate.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ function frameTestedEvaluate(node, options) {
88
);
99

1010
// give the frame .5s to respond to 'axe.ping', else log failed response
11-
let timer = setTimeout(function() {
11+
let timer = setTimeout(() => {
1212
// This double timeout is important for allowing iframes to respond
1313
// DO NOT REMOVE
14-
timer = setTimeout(function() {
14+
timer = setTimeout(() => {
1515
timer = null;
1616
resolve(isViolation ? false : undefined);
1717
}, 0);
1818
}, timeout);
1919

20-
respondable(node.contentWindow, 'axe.ping', null, undefined, function() {
20+
respondable(node.contentWindow, 'axe.ping', null, undefined, () => {
2121
if (timer !== null) {
2222
clearTimeout(timer);
2323
resolve(true);

lib/checks/media/no-autoplay-audio-evaluate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function noAutoplayAudioEvaluate(node, options) {
8181
* @param {String} hhMmSs time expressed in HH:MM:SS
8282
*/
8383
function convertHourMinSecToSeconds(hhMmSs) {
84-
let parts = hhMmSs.split(':');
84+
const parts = hhMmSs.split(':');
8585
let secs = 0;
8686
let mins = 1;
8787

lib/checks/navigation/p-as-heading-evaluate.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function normalizeFontWeight(weight) {
1717

1818
function getTextContainer(elm) {
1919
let nextNode = elm;
20-
let outerText = elm.textContent.trim();
20+
const outerText = elm.textContent.trim();
2121
let innerText = outerText;
2222

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

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

6262
function pAsHeadingEvaluate(node, options, virtualNode) {
63-
let siblings = Array.from(node.parentNode.children);
64-
let currentIndex = siblings.indexOf(node);
63+
const siblings = Array.from(node.parentNode.children);
64+
const currentIndex = siblings.indexOf(node);
6565

6666
options = options || {};
67-
let margins = options.margins || [];
67+
const margins = options.margins || [];
6868

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

73-
let prevSibling = siblings
73+
const prevSibling = siblings
7474
.slice(0, currentIndex)
7575
.reverse()
7676
.find(elm => elm.nodeName.toUpperCase() === 'P');
@@ -83,7 +83,7 @@ function pAsHeadingEvaluate(node, options, virtualNode) {
8383
return true;
8484
}
8585

86-
let blockquote = findUpVirtual(virtualNode, 'blockquote');
86+
const blockquote = findUpVirtual(virtualNode, 'blockquote');
8787
if (blockquote && blockquote.nodeName.toUpperCase() === 'BLOCKQUOTE') {
8888
return undefined;
8989
}

lib/checks/navigation/unique-frame-title-after.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
function uniqueFrameTitleAfter(results) {
22
var titles = {};
3-
results.forEach(function(r) {
3+
results.forEach(r => {
44
titles[r.data] = titles[r.data] !== undefined ? ++titles[r.data] : 0;
55
});
6-
results.forEach(function(r) {
6+
results.forEach(r => {
77
r.result = !!titles[r.data];
88
});
99

lib/checks/parsing/duplicate-id-after.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function duplicateIdAfter(results) {
22
var uniqueIds = [];
3-
return results.filter(function(r) {
3+
return results.filter(r => {
44
if (uniqueIds.indexOf(r.data) === -1) {
55
uniqueIds.push(r.data);
66
return true;

lib/checks/shared/non-empty-if-present-evaluate.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
function nonEmptyIfPresentEvaluate(node, options, virtualNode) {
22
// Check for 'default' names, which are given to reset and submit buttons
3-
let nodeName = virtualNode.props.nodeName;
4-
let type = (virtualNode.attr('type') || '').toLowerCase();
5-
let label = virtualNode.attr('value');
3+
const nodeName = virtualNode.props.nodeName;
4+
const type = (virtualNode.attr('type') || '').toLowerCase();
5+
const label = virtualNode.attr('value');
66

77
if (label) {
88
this.data({

lib/checks/tables/caption-faked-evaluate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function captionFakedEvaluate(node) {
88
return true;
99
}
1010

11-
return firstRow.reduce(function(out, curr, i) {
11+
return firstRow.reduce((out, curr, i) => {
1212
return out || (curr !== firstRow[i + 1] && firstRow[i + 1] !== undefined);
1313
}, false);
1414
}

lib/checks/tables/th-has-data-cells-evaluate.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function thHasDataCellsEvaluate(node) {
77

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

2222
// Get all the headers
23-
const headers = cells.filter(function(cell) {
23+
const headers = cells.filter(cell => {
2424
if (sanitize(cell.textContent) === '') {
2525
return false;
2626
}

lib/commons/aria/label-virtual.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function labelVirtual(virtualNode) {
1919
// aria-labelledby
2020
ref = idrefs(virtualNode.actualNode, 'aria-labelledby');
2121
candidate = ref
22-
.map(function(thing) {
22+
.map(thing => {
2323
const vNode = getNodeFromTree(thing);
2424
return vNode ? visibleVirtual(vNode, true) : '';
2525
})

lib/commons/aria/validate-attr-value.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function validateAttrValue(node, attr) {
3838
case 'nmtokens':
3939
list = tokenList(value);
4040
// Check if any value isn't in the list of values
41-
return list.reduce(function(result, token) {
41+
return list.reduce((result, token) => {
4242
return result && attrInfo.values.includes(token);
4343
// Initial state, fail if the list is empty
4444
}, list.length !== 0);

lib/commons/color/color.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function Color(red, green, blue, alpha) {
9292
* @instance
9393
* @return {string}
9494
*/
95-
this.toHexString = function() {
95+
this.toHexString = function toHexString() {
9696
var redString = Math.round(this.red).toString(16);
9797
var greenString = Math.round(this.green).toString(16);
9898
var blueString = Math.round(this.blue).toString(16);
@@ -113,7 +113,7 @@ function Color(red, green, blue, alpha) {
113113
* @memberof axe.commons.color.Color
114114
* @instance
115115
*/
116-
this.parseString = function(colorString) {
116+
this.parseString = function parseString(colorString) {
117117
// IE occasionally returns named colors instead of RGB(A) values
118118
if (standards.cssColors[colorString] || colorString === 'transparent') {
119119
const [red, green, blue] = standards.cssColors[colorString] || [0, 0, 0];
@@ -144,7 +144,7 @@ function Color(red, green, blue, alpha) {
144144
* @instance
145145
* @param {string} rgb The string value
146146
*/
147-
this.parseRgbString = function(colorString) {
147+
this.parseRgbString = function parseRgbString(colorString) {
148148
// IE can pass transparent as value instead of rgba
149149
if (colorString === 'transparent') {
150150
this.red = 0;
@@ -164,7 +164,7 @@ function Color(red, green, blue, alpha) {
164164
* @instance
165165
* @param {string} rgb The string value
166166
*/
167-
this.parseHexString = function(colorString) {
167+
this.parseHexString = function parseHexString(colorString) {
168168
if (!colorString.match(hexRegex) || [6, 8].includes(colorString.length)) {
169169
return;
170170
}
@@ -231,7 +231,7 @@ function Color(red, green, blue, alpha) {
231231
* @instance
232232
* @return {number} The luminance value, ranges from 0 to 1
233233
*/
234-
this.getRelativeLuminance = function() {
234+
this.getRelativeLuminance = function getRelativeLuminance() {
235235
var rSRGB = this.red / 255;
236236
var gSRGB = this.green / 255;
237237
var bSRGB = this.blue / 255;

lib/commons/color/element-is-distinct.js

+17-18
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function _getFonts(style) {
1010
return style
1111
.getPropertyValue('font-family')
1212
.split(/[,;]/g)
13-
.map(function(font) {
13+
.map(font => {
1414
return font.trim().toLowerCase();
1515
});
1616
}
@@ -33,23 +33,22 @@ function elementIsDistinct(node, ancestorNode) {
3333
}
3434

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

43-
// Check if a border/outline was specified
44-
return (
45-
result ||
46-
// or if the current border edge / outline
47-
(nodeStyle.getPropertyValue(edge + '-style') !== 'none' &&
48-
parseFloat(nodeStyle.getPropertyValue(edge + '-width')) > 0 &&
49-
borderClr.alpha !== 0)
50-
);
51-
},
52-
false);
41+
// Check if a border/outline was specified
42+
return (
43+
result ||
44+
// or if the current border edge / outline
45+
(nodeStyle.getPropertyValue(edge + '-style') !== 'none' &&
46+
parseFloat(nodeStyle.getPropertyValue(edge + '-width')) > 0 &&
47+
borderClr.alpha !== 0)
48+
);
49+
},
50+
false
51+
);
5352

5453
if (hasBorder) {
5554
return true;
@@ -67,7 +66,7 @@ function elementIsDistinct(node, ancestorNode) {
6766
'font-weight',
6867
'font-style',
6968
'font-size'
70-
].reduce(function(result, cssProp) {
69+
].reduce((result, cssProp) => {
7170
return (
7271
result ||
7372
nodeStyle.getPropertyValue(cssProp) !==

lib/commons/color/filtered-rect-stack.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function filteredRectStack(elm) {
2525
return;
2626
}
2727
// if the stacks are the same, use the first one. otherwise, return null.
28-
let rectA = rectStack[index - 1],
28+
const rectA = rectStack[index - 1],
2929
rectB = rectStack[index];
3030

3131
// if elements in clientRects are the same

lib/commons/color/get-background-color.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ function elmPartiallyObscured(elm, bgElm, bgColor) {
3838
*/
3939
function getBackgroundColor(elm, bgElms = [], shadowOutlineEmMax = 0.1) {
4040
let bgColors = getTextShadowColors(elm, { minRatio: shadowOutlineEmMax });
41-
let elmStack = getBackgroundStack(elm);
41+
const elmStack = getBackgroundStack(elm);
4242

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

4747
// Get the background color
48-
let bgColor = getOwnBackgroundColor(bgElmStyle);
48+
const bgColor = getOwnBackgroundColor(bgElmStyle);
4949

5050
if (
5151
// abort if a node is partially obscured and obscuring element has a background

0 commit comments

Comments
 (0)