Skip to content

Commit d464058

Browse files
authored
Fix eslint errors (#1384)
* Fix eslint errors Related to #1362. Signed-off-by: Denis Golovin <dgolovin@redhat.com>
1 parent 76fced1 commit d464058

File tree

7 files changed

+38
-60
lines changed

7 files changed

+38
-60
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"import/no-duplicates": ["error"],
6363
"import/prefer-default-export": 0,
6464
"max-nested-callbacks": [1, 4],
65+
"max-classes-per-file": [0],
6566
"no-alert": 2,
6667
"no-caller": 2,
6768
"no-console": 2,

src/util/archive.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class Archive {
2626
.then(resolve)
2727
.catch(reject);
2828
} else {
29-
reject(`Unsupported extension for '${zipFile}'`);
29+
reject(Error(`Unsupported extension for '${zipFile}'`));
3030
}
3131
});
3232
}
@@ -47,7 +47,13 @@ export class Archive {
4747
src: zipFile,
4848
dest: extractTo,
4949
tar: {
50-
map: (header) => prefix && header.name.startsWith(prefix) ? (header.name = header.name.substring(prefix.length), header) : header
50+
map: (header: { name: string; }): { name: string; } => {
51+
const result = header;
52+
if (prefix && header.name.startsWith(prefix)) {
53+
result.name = header.name.substring(prefix.length);
54+
}
55+
return result;
56+
}
5157
}
5258
});
5359
}

src/util/async.ts

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ export interface Task<T> {
1818
(): T;
1919
}
2020

21-
// export interface IDisposable {
22-
// dispose(): void;
23-
// }
24-
2521
export class Delayer<T> {
2622

2723
private timeout: any;
@@ -30,29 +26,27 @@ export class Delayer<T> {
3026

3127
private doResolve: ((value?: any | Promise<any>) => void) | null;
3228

33-
private doReject: (err: any) => void;
34-
3529
private task: Task<T | Promise<T>> | null;
3630

3731
constructor(public defaultDelay: number) {
3832
this.timeout = null;
3933
this.completionPromise = null;
4034
this.doResolve = null;
41-
this.doReject;
4235
this.task = null;
4336
}
4437

4538
trigger(task: Task<T | Promise<T>>, delay: number = this.defaultDelay): Promise<T> {
4639
this.task = task;
4740
this.cancelTimeout();
4841

42+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
4943
if (!this.completionPromise) {
5044
this.completionPromise = new Promise((c, e) => {
5145
this.doResolve = c;
52-
this.doReject = e;
5346
}).then(() => {
5447
this.completionPromise = null;
5548
this.doResolve = null;
49+
// eslint-disable-next-line no-shadow
5650
const {task} = this;
5751
this.task = null;
5852

@@ -68,27 +62,10 @@ export class Delayer<T> {
6862
return this.completionPromise;
6963
}
7064

71-
// isTriggered(): boolean {
72-
// return this.timeout !== null;
73-
// }
74-
75-
// cancel(): void {
76-
// this.cancelTimeout();
77-
78-
// if (this.completionPromise) {
79-
// this.doReject(Error('Canceled'));
80-
// this.completionPromise = null;
81-
// }
82-
// }
83-
8465
private cancelTimeout(): void {
8566
if (this.timeout !== null) {
8667
clearTimeout(this.timeout);
8768
this.timeout = null;
8869
}
8970
}
90-
91-
// dispose(): void {
92-
// this.cancelTimeout();
93-
// }
94-
}
71+
}

src/util/download.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,20 @@ export class DownloadUtil {
1616

1717
static async downloadFile(fromUrl: string, toFile: string, progressCb?: (current: number, increment: number) => void, throttle = 250): Promise<void> {
1818
const dls = got.stream(fromUrl);
19-
let previous = 0;
20-
// Process progress event from 'got'
21-
const progress = fromEvent(dls, 'downloadProgress').pipe(throttleTime(throttle)).subscribe((progress: { percent: number }) => {
22-
const current = Math.round(progress.percent * 100);
23-
current !== previous && progressCb && progressCb(current, current - previous);
24-
previous = current;
25-
});
26-
// process end event from 'got'
27-
const end = fromEvent(dls, 'end').subscribe(() => {
28-
progressCb && progressCb(100, 100 - previous);
29-
});
30-
// Pipe url to file
31-
try {
32-
await pipeline(dls, fs.createWriteStream(toFile));
33-
} finally {
34-
// Unsubscribe form 'downloadProgress' and 'end' events
35-
// Is it really required?
36-
progress.unsubscribe();
37-
end.unsubscribe();
19+
if (progressCb) {
20+
let previous = 0;
21+
// Process progress event from 'got'
22+
fromEvent(dls, 'downloadProgress').pipe(throttleTime(throttle)).subscribe((progress: { percent: number }) => {
23+
const current = Math.round(progress.percent * 100);
24+
progressCb(current, current - previous);
25+
previous = current;
26+
});
27+
// process end event from 'got'
28+
fromEvent(dls, 'end').subscribe(() => {
29+
progressCb(100, 100 - previous);
30+
});
3831
}
32+
// Pipe url to file
33+
await pipeline(dls, fs.createWriteStream(toFile));
3934
}
4035
}

src/util/refs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ export class Refs {
2727

2828
static async fetchTag(input: string): Promise<Map<string, Ref>> {
2929
return new Promise((resolve, reject) => {
30-
input = input.replace(/^(?!(?:https|git):\/\/)/, 'https://');
30+
const gitUrl = input.replace(/^(?!(?:https|git):\/\/)/, 'https://');
3131

3232
const tcp = net.connect({
33-
host: url.parse(input).host,
33+
host: url.parse(gitUrl).host,
3434
port: 9418
3535
});
36-
const client = gitClient(input);
36+
const client = gitClient(gitUrl);
3737
const tags = new Map<string, Ref>();
3838

3939
client.refs.on('data', (ref: { name: string; hash: string }) => {

src/util/watch.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,15 @@ export class WatchUtil {
2121
if (timer) {
2222
clearTimeout(timer);
2323
}
24-
25-
timer = setTimeout(async () => {
24+
timer = setTimeout(() => {
2625
timer = undefined;
27-
const newContext = await WatchUtil.grep(path.join(location, filename), /current-context:.*/);
28-
if (context !== newContext) {
29-
emitter.emit('file-changed');
30-
context = newContext;
31-
}
26+
WatchUtil.grep(path.join(location, filename), /current-context:.*/).then((newContext: string)=> {
27+
if (context !== newContext) {
28+
emitter.emit('file-changed');
29+
context = newContext;
30+
}
31+
});
3232
}, 500);
33-
3433
}
3534
});
3635
return { watcher, emitter };

test/unit/util/archive.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ suite('Archive Utility', () => {
106106
try {
107107
await Archive.extract('file.whatever', extractTo);
108108
} catch (err) {
109-
expect(err).equals(`Unsupported extension for '${file}'`);
109+
expect(err.message).equals(`Unsupported extension for '${file}'`);
110110
}
111111
});
112-
});
112+
});

0 commit comments

Comments
 (0)