Skip to content

Commit 4ea4e51

Browse files
committed
fix code for eslint (attempt 3)
1 parent f333f50 commit 4ea4e51

File tree

11 files changed

+2497
-465
lines changed

11 files changed

+2497
-465
lines changed

__test__/diffFiles.test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ import genDiff from '../src/formatters/index.js';
77
const __filename = fileURLToPath(import.meta.url);
88
const __dirname = dirname(__filename);
99

10-
const getFixturePath = (filename) =>
11-
path.join(__dirname, '..', '__fixtures__', filename);
10+
const getFixturePath = (filename) => path.join(__dirname, '..', '__fixtures__', filename);
1211

13-
const readFile = (filename) =>
14-
fs.readFileSync(getFixturePath(filename), 'utf-8');
12+
const readFile = (filename) => fs.readFileSync(getFixturePath(filename), 'utf-8');
1513

1614
const expectFormatJson = readFile('expectDiffFormatJson.txt');
1715
const expectFormatPlain = readFile('expectDiffFormatPlain.txt');

coverage/lcov-report/block-navigation.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
var jumpToCode = (function init() {
1+
/* eslint-disable */
2+
3+
const jumpToCode = (function init() {
24
// Classes of code we would like to highlight in the file view
3-
var missingCoverageClasses = ['.cbranch-no', '.cstat-no', '.fstat-no'];
5+
const missingCoverageClasses = ['.cbranch-no', '.cstat-no', '.fstat-no'];
46

57
// Elements to highlight in the file listing view
6-
var fileListingElements = ['td.pct.low'];
8+
const fileListingElements = ['td.pct.low'];
79

810
// We don't want to select elements that are direct descendants of another match
9-
var notSelector = ':not(' + missingCoverageClasses.join('):not(') + ') > '; // becomes `:not(a):not(b) > `
11+
const notSelector = `:not(${missingCoverageClasses.join('):not(')}) > `; // becomes `:not(a):not(b) > `
1012

1113
// Selecter that finds elements on the page to which we can jump
12-
var selector =
13-
fileListingElements.join(', ') +
14-
', ' +
15-
notSelector +
16-
missingCoverageClasses.join(', ' + notSelector); // becomes `:not(a):not(b) > a, :not(a):not(b) > b`
14+
const selector = `${fileListingElements.join(', ')
15+
}, ${
16+
notSelector
17+
}${missingCoverageClasses.join(`, ${notSelector}`)}`; // becomes `:not(a):not(b) > a, :not(a):not(b) > b`
1718

1819
// The NodeList of matching elements
19-
var missingCoverageElements = document.querySelectorAll(selector);
20+
const missingCoverageElements = document.querySelectorAll(selector);
2021

21-
var currentIndex;
22+
let currentIndex;
2223

2324
function toggleClass(index) {
2425
missingCoverageElements.item(currentIndex).classList.remove('highlighted');
@@ -36,7 +37,7 @@ var jumpToCode = (function init() {
3637
}
3738

3839
function goToPrevious() {
39-
var nextIndex = 0;
40+
let nextIndex = 0;
4041
if (typeof currentIndex !== 'number' || currentIndex === 0) {
4142
nextIndex = missingCoverageElements.length - 1;
4243
} else if (missingCoverageElements.length > 1) {
@@ -47,11 +48,11 @@ var jumpToCode = (function init() {
4748
}
4849

4950
function goToNext() {
50-
var nextIndex = 0;
51+
let nextIndex = 0;
5152

5253
if (
53-
typeof currentIndex === 'number' &&
54-
currentIndex < missingCoverageElements.length - 1
54+
typeof currentIndex === 'number'
55+
&& currentIndex < missingCoverageElements.length - 1
5556
) {
5657
nextIndex = currentIndex + 1;
5758
}
@@ -61,8 +62,8 @@ var jumpToCode = (function init() {
6162

6263
return function jump(event) {
6364
if (
64-
document.getElementById('fileSearch') === document.activeElement &&
65-
document.activeElement != null
65+
document.getElementById('fileSearch') === document.activeElement
66+
&& document.activeElement != null
6667
) {
6768
// if we're currently focused on the search input, we don't want to navigate
6869
return;
@@ -80,5 +81,5 @@ var jumpToCode = (function init() {
8081
break;
8182
}
8283
};
83-
})();
84+
}());
8485
window.addEventListener('keydown', jumpToCode);

coverage/lcov-report/sorter.js

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
var addSorting = (function () {
2-
'use strict';
3-
var cols,
4-
currentSort = {
5-
index: 0,
6-
desc: false,
7-
};
1+
/* eslint-disable */
2+
3+
const addSorting = (function () {
4+
let cols;
5+
const currentSort = {
6+
index: 0,
7+
desc: false,
8+
};
89

910
// returns the summary table element
1011
function getTable() {
@@ -38,19 +39,19 @@ var addSorting = (function () {
3839

3940
// loads the search box
4041
function addSearchBox() {
41-
var template = document.getElementById('filterTemplate');
42-
var templateClone = template.content.cloneNode(true);
42+
const template = document.getElementById('filterTemplate');
43+
const templateClone = template.content.cloneNode(true);
4344
templateClone.getElementById('fileSearch').oninput = onFilterInput;
4445
template.parentElement.appendChild(templateClone);
4546
}
4647

4748
// loads all columns
4849
function loadColumns() {
49-
var colNodes = getTableHeader().querySelectorAll('th'),
50-
colNode,
51-
cols = [],
52-
col,
53-
i;
50+
const colNodes = getTableHeader().querySelectorAll('th');
51+
let colNode;
52+
const cols = [];
53+
let col;
54+
let i;
5455

5556
for (i = 0; i < colNodes.length; i += 1) {
5657
colNode = colNodes[i];
@@ -62,20 +63,20 @@ var addSorting = (function () {
6263
cols.push(col);
6364
if (col.sortable) {
6465
col.defaultDescSort = col.type === 'number';
65-
colNode.innerHTML = colNode.innerHTML + '<span class="sorter"></span>';
66+
colNode.innerHTML += '<span class="sorter"></span>';
6667
}
6768
}
6869
return cols;
6970
}
7071
// attaches a data attribute to every tr element with an object
7172
// of data values keyed by column name
7273
function loadRowData(tableRow) {
73-
var tableCols = tableRow.querySelectorAll('td'),
74-
colNode,
75-
col,
76-
data = {},
77-
i,
78-
val;
74+
const tableCols = tableRow.querySelectorAll('td');
75+
let colNode;
76+
let col;
77+
const data = {};
78+
let i;
79+
let val;
7980
for (i = 0; i < tableCols.length; i += 1) {
8081
colNode = tableCols[i];
8182
col = cols[i];
@@ -89,26 +90,26 @@ var addSorting = (function () {
8990
}
9091
// loads all row data
9192
function loadData() {
92-
var rows = getTableBody().querySelectorAll('tr'),
93-
i;
93+
const rows = getTableBody().querySelectorAll('tr');
94+
let i;
9495

9596
for (i = 0; i < rows.length; i += 1) {
9697
rows[i].data = loadRowData(rows[i]);
9798
}
9899
}
99100
// sorts the table using the data for the ith column
100101
function sortByIndex(index, desc) {
101-
var key = cols[index].key,
102-
sorter = function (a, b) {
103-
a = a.data[key];
104-
b = b.data[key];
105-
return a < b ? -1 : a > b ? 1 : 0;
106-
},
107-
finalSorter = sorter,
108-
tableBody = document.querySelector('.coverage-summary tbody'),
109-
rowNodes = tableBody.querySelectorAll('tr'),
110-
rows = [],
111-
i;
102+
const { key } = cols[index];
103+
const sorter = function (a, b) {
104+
a = a.data[key];
105+
b = b.data[key];
106+
return a < b ? -1 : a > b ? 1 : 0;
107+
};
108+
let finalSorter = sorter;
109+
const tableBody = document.querySelector('.coverage-summary tbody');
110+
const rowNodes = tableBody.querySelectorAll('tr');
111+
const rows = [];
112+
let i;
112113

113114
if (desc) {
114115
finalSorter = function (a, b) {
@@ -129,8 +130,8 @@ var addSorting = (function () {
129130
}
130131
// removes sort indicators for current column being sorted
131132
function removeSortIndicators() {
132-
var col = getNthColumn(currentSort.index),
133-
cls = col.className;
133+
const col = getNthColumn(currentSort.index);
134+
let cls = col.className;
134135

135136
cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
136137
col.className = cls;
@@ -143,24 +144,24 @@ var addSorting = (function () {
143144
}
144145
// adds event listeners for all sorter widgets
145146
function enableUI() {
146-
var i,
147-
el,
148-
ithSorter = function ithSorter(i) {
149-
var col = cols[i];
147+
let i;
148+
let el;
149+
const ithSorter = function ithSorter(i) {
150+
const col = cols[i];
150151

151-
return function () {
152-
var desc = col.defaultDescSort;
152+
return function () {
153+
let desc = col.defaultDescSort;
153154

154-
if (currentSort.index === i) {
155-
desc = !currentSort.desc;
156-
}
157-
sortByIndex(i, desc);
158-
removeSortIndicators();
159-
currentSort.index = i;
160-
currentSort.desc = desc;
161-
addSortIndicators();
162-
};
155+
if (currentSort.index === i) {
156+
desc = !currentSort.desc;
157+
}
158+
sortByIndex(i, desc);
159+
removeSortIndicators();
160+
currentSort.index = i;
161+
currentSort.desc = desc;
162+
addSortIndicators();
163163
};
164+
};
164165
for (i = 0; i < cols.length; i += 1) {
165166
if (cols[i].sortable) {
166167
// add the click event handler on the th so users

eslint.config.js

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,57 @@
11
import globals from 'globals';
2+
3+
import path from 'path';
4+
import { fileURLToPath } from 'url';
5+
import { FlatCompat } from '@eslint/eslintrc';
26
import pluginJs from '@eslint/js';
7+
import importPlugin from 'eslint-plugin-import';
8+
9+
// mimic CommonJS variables -- not needed if using CommonJS
10+
const __filename = fileURLToPath(import.meta.url);
11+
const __dirname = path.dirname(__filename);
12+
const compat = new FlatCompat({
13+
baseDirectory: __dirname,
14+
recommendedConfig: pluginJs.configs.recommended,
15+
});
316

4-
/** @type {import('eslint').Linter.Config[]} */
517
export default [
6-
{ languageOptions: { globals: globals.browser } },
7-
pluginJs.configs.recommended,
18+
{
19+
languageOptions: {
20+
globals: {
21+
...globals.node,
22+
...globals.jest,
23+
},
24+
parserOptions: {
25+
// Eslint doesn't supply ecmaVersion in `parser.js` `context.parserOptions`
26+
// This is required to avoid ecmaVersion < 2015 error or 'import' / 'export' error
27+
ecmaVersion: 'latest',
28+
sourceType: 'module',
29+
},
30+
},
31+
plugins: { import: importPlugin },
32+
rules: {
33+
...importPlugin.configs.recommended.rules,
34+
},
35+
},
36+
...compat.extends('airbnb-base'),
37+
{
38+
rules: {
39+
'no-underscore-dangle': [
40+
'error',
41+
{
42+
allow: ['__filename', '__dirname'],
43+
},
44+
],
45+
'import/extensions': [
46+
'error',
47+
{
48+
js: 'always',
49+
},
50+
],
51+
'import/no-named-as-default': 'off',
52+
'import/no-named-as-default-member': 'off',
53+
'no-console': 'off',
54+
'import/no-extraneous-dependencies': 'off',
55+
},
56+
},
857
];

0 commit comments

Comments
 (0)