Skip to content

Commit f333f50

Browse files
committed
fix code for eslint (attempt 2)
1 parent f707934 commit f333f50

File tree

8 files changed

+263
-272
lines changed

8 files changed

+263
-272
lines changed

__test__/diffFiles.test.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,23 @@ const expectFormatJson = readFile('expectDiffFormatJson.txt');
1717
const expectFormatPlain = readFile('expectDiffFormatPlain.txt');
1818
const expectFormatStylish = readFile('expectDiffFormatStylish.txt');
1919

20+
const file1Json = '__fixtures__/file1.json';
21+
const file2Json = '__fixtures__/file2.json';
22+
const file1Yaml = '__fixtures__/file1.yaml';
23+
const file2Yaml = '__fixtures__/file2.yaml';
24+
2025
test('compareFilesJsonFormatStylish', () => {
21-
expect(genDiff('__fixtures__/file1.json', '__fixtures__/file2.json')).toEqual(
22-
expectFormatStylish
23-
);
26+
expect(genDiff(file1Json, file2Json)).toEqual(expectFormatStylish);
2427
});
2528

2629
test('compareFilesYamlFormatStylish', () => {
27-
expect(
28-
genDiff('__fixtures__/file1.yaml', '__fixtures__/file2.yaml', 'stylish')
29-
).toEqual(expectFormatStylish);
30+
expect(genDiff(file1Yaml, file2Yaml, 'stylish')).toEqual(expectFormatStylish);
3031
});
3132

3233
test('compareFilesJsonFormatPlain', () => {
33-
expect(
34-
genDiff('__fixtures__/file1.yaml', '__fixtures__/file2.json', 'plain')
35-
).toEqual(expectFormatPlain);
34+
expect(genDiff(file1Yaml, file2Json, 'plain')).toEqual(expectFormatPlain);
3635
});
3736

3837
test('compareFilesFormatJson', () => {
39-
expect(
40-
genDiff('__fixtures__/file1.yaml', '__fixtures__/file2.yaml', 'json')
41-
).toEqual(expectFormatJson);
38+
expect(genDiff(file1Yaml, file2Yaml, 'json')).toEqual(expectFormatJson);
4239
});
Lines changed: 66 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,84 @@
1-
21
var jumpToCode = (function init() {
3-
// Classes of code we would like to highlight in the file view
4-
var missingCoverageClasses = ['.cbranch-no', '.cstat-no', '.fstat-no'];
2+
// Classes of code we would like to highlight in the file view
3+
var missingCoverageClasses = ['.cbranch-no', '.cstat-no', '.fstat-no'];
54

6-
// Elements to highlight in the file listing view
7-
var fileListingElements = ['td.pct.low'];
5+
// Elements to highlight in the file listing view
6+
var fileListingElements = ['td.pct.low'];
87

9-
// We don't want to select elements that are direct descendants of another match
10-
var notSelector = ':not(' + missingCoverageClasses.join('):not(') + ') > '; // becomes `:not(a):not(b) > `
8+
// 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) > `
1110

12-
// Selecter that finds elements on the page to which we can jump
13-
var selector =
14-
fileListingElements.join(', ') +
15-
', ' +
16-
notSelector +
17-
missingCoverageClasses.join(', ' + notSelector); // becomes `:not(a):not(b) > a, :not(a):not(b) > b`
11+
// 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`
1817

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

22-
var currentIndex;
21+
var currentIndex;
2322

24-
function toggleClass(index) {
25-
missingCoverageElements
26-
.item(currentIndex)
27-
.classList.remove('highlighted');
28-
missingCoverageElements.item(index).classList.add('highlighted');
29-
}
30-
31-
function makeCurrent(index) {
32-
toggleClass(index);
33-
currentIndex = index;
34-
missingCoverageElements.item(index).scrollIntoView({
35-
behavior: 'smooth',
36-
block: 'center',
37-
inline: 'center'
38-
});
39-
}
23+
function toggleClass(index) {
24+
missingCoverageElements.item(currentIndex).classList.remove('highlighted');
25+
missingCoverageElements.item(index).classList.add('highlighted');
26+
}
4027

41-
function goToPrevious() {
42-
var nextIndex = 0;
43-
if (typeof currentIndex !== 'number' || currentIndex === 0) {
44-
nextIndex = missingCoverageElements.length - 1;
45-
} else if (missingCoverageElements.length > 1) {
46-
nextIndex = currentIndex - 1;
47-
}
28+
function makeCurrent(index) {
29+
toggleClass(index);
30+
currentIndex = index;
31+
missingCoverageElements.item(index).scrollIntoView({
32+
behavior: 'smooth',
33+
block: 'center',
34+
inline: 'center',
35+
});
36+
}
4837

49-
makeCurrent(nextIndex);
38+
function goToPrevious() {
39+
var nextIndex = 0;
40+
if (typeof currentIndex !== 'number' || currentIndex === 0) {
41+
nextIndex = missingCoverageElements.length - 1;
42+
} else if (missingCoverageElements.length > 1) {
43+
nextIndex = currentIndex - 1;
5044
}
5145

52-
function goToNext() {
53-
var nextIndex = 0;
46+
makeCurrent(nextIndex);
47+
}
5448

55-
if (
56-
typeof currentIndex === 'number' &&
57-
currentIndex < missingCoverageElements.length - 1
58-
) {
59-
nextIndex = currentIndex + 1;
60-
}
49+
function goToNext() {
50+
var nextIndex = 0;
6151

62-
makeCurrent(nextIndex);
52+
if (
53+
typeof currentIndex === 'number' &&
54+
currentIndex < missingCoverageElements.length - 1
55+
) {
56+
nextIndex = currentIndex + 1;
6357
}
6458

65-
return function jump(event) {
66-
if (
67-
document.getElementById('fileSearch') === document.activeElement &&
68-
document.activeElement != null
69-
) {
70-
// if we're currently focused on the search input, we don't want to navigate
71-
return;
72-
}
59+
makeCurrent(nextIndex);
60+
}
7361

74-
switch (event.which) {
75-
case 78: // n
76-
case 74: // j
77-
goToNext();
78-
break;
79-
case 66: // b
80-
case 75: // k
81-
case 80: // p
82-
goToPrevious();
83-
break;
84-
}
85-
};
62+
return function jump(event) {
63+
if (
64+
document.getElementById('fileSearch') === document.activeElement &&
65+
document.activeElement != null
66+
) {
67+
// if we're currently focused on the search input, we don't want to navigate
68+
return;
69+
}
70+
71+
switch (event.which) {
72+
case 78: // n
73+
case 74: // j
74+
goToNext();
75+
break;
76+
case 66: // b
77+
case 75: // k
78+
case 80: // p
79+
goToPrevious();
80+
break;
81+
}
82+
};
8683
})();
8784
window.addEventListener('keydown', jumpToCode);

0 commit comments

Comments
 (0)