Skip to content

Commit 972e0e8

Browse files
authored
Update xo and apply corrections (#141)
1 parent a51f0fd commit 972e0e8

File tree

5 files changed

+21
-22
lines changed

5 files changed

+21
-22
lines changed

index.d.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ declare namespace electronDl {
66
transferredBytes: number;
77
totalBytes: number;
88
}
9-
9+
1010
interface File {
11-
filename: string,
12-
path: string,
13-
fileSize: number,
14-
mimeType: string,
15-
url: string
11+
filename: string;
12+
path: string;
13+
fileSize: number;
14+
mimeType: string;
15+
url: string;
1616
}
1717

1818
interface Options {
@@ -68,10 +68,10 @@ declare namespace electronDl {
6868
Optional callback that receives an object containing information about the progress of the current download item.
6969
*/
7070
readonly onProgress?: (progress: Progress) => void;
71-
71+
7272
/**
7373
Optional callback that receives an object containing information about the combined progress of all download items done within any registered window.
74-
74+
7575
Each time a new download is started, the next callback will include it. The progress percentage could therefore become smaller again.
7676
This callback provides the same data that is used for the progress bar on the app icon.
7777
*/
@@ -81,7 +81,7 @@ declare namespace electronDl {
8181
Optional callback that receives the [download item](https://electronjs.org/docs/api/download-item) for which the download has been cancelled.
8282
*/
8383
readonly onCancel?: (item: DownloadItem) => void;
84-
84+
8585
/**
8686
Optional callback that receives an object with information about an item that has been completed. It is called for each completed item.
8787
*/
@@ -112,6 +112,7 @@ declare namespace electronDl {
112112
}
113113
}
114114

115+
// eslint-disable-next-line no-redeclare
115116
declare const electronDl: {
116117
/**
117118
Register the helper for all windows.

index.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const getFilenameFromMime = (name, mime) => {
1717

1818
const majorElectronVersion = () => {
1919
const version = process.versions.electron.split('.');
20-
return parseInt(version[0], 10);
20+
return Number.parseInt(version[0], 10);
2121
};
2222

2323
const getWindowFromBrowserView = webContents => {
@@ -75,11 +75,7 @@ function registerListener(session, options, callback = () => {}) {
7575
const filename = item.getFilename();
7676
const name = path.extname(filename) ? filename : getFilenameFromMime(filename, item.getMimeType());
7777

78-
if (options.overwrite) {
79-
filePath = path.join(directory, name);
80-
} else {
81-
filePath = unusedFilename.sync(path.join(directory, name));
82-
}
78+
filePath = options.overwrite ? path.join(directory, name) : unusedFilename.sync(path.join(directory, name));
8379
}
8480

8581
const errorMessage = options.errorMessage || 'The download of {filename} was interrupted';
@@ -147,6 +143,7 @@ function registerListener(session, options, callback = () => {}) {
147143
session.removeListener('will-download', listener);
148144
}
149145

146+
// eslint-disable-next-line unicorn/prefer-switch
150147
if (state === 'cancelled') {
151148
if (typeof options.onCancel === 'function') {
152149
options.onCancel(item);

lib/samples.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ const {v4: uuidv4} = require('uuid');
77

88
const fixtureDir = path.join(__dirname, '../mock/fixtures');
99

10-
const setup = async numFiles => {
10+
const setup = async numberFiles => {
1111
const promises = [];
1212
const files = [];
1313

14-
while (files.length < numFiles) {
14+
while (files.length < numberFiles) {
1515
const filename = `${uuidv4()}.zip`;
1616
promises.push(cpFile(path.join(fixtureDir, 'electron-master.zip'), path.join(fixtureDir, filename)));
1717
files.push(filename);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@
4141
"pify": "^4.0.1",
4242
"spectron": "^9.0.0",
4343
"tsd": "^0.17.0",
44+
"typescript": "^4.4.3",
4445
"uuid": "^8.3.2",
45-
"xo": "^0.25.3"
46+
"xo": "^0.39.0"
4647
},
4748
"xo": {
4849
"envs": [

run.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22
const electron = require('electron');
33
const minimist = require('minimist');
4-
const samples = require('./lib/samples');
5-
const server = require('./lib/server');
4+
const samples = require('./lib/samples.js');
5+
const server = require('./lib/server.js');
66
const electronDl = require('.');
77

88
electronDl();
@@ -27,8 +27,8 @@ const argv = minimist(process.argv.slice(2));
2727
downloadThroughput: 1024 * 1024
2828
});
2929

30-
const numSampleFiles = 'files' in argv ? argv.files : 5;
31-
const files = await samples.setup(numSampleFiles);
30+
const numberSampleFiles = 'files' in argv ? argv.files : 5;
31+
const files = await samples.setup(numberSampleFiles);
3232
await win.loadURL(`http://localhost:8080/index.html?files=${JSON.stringify(files)}`);
3333
})();
3434

0 commit comments

Comments
 (0)