Skip to content

Commit

Permalink
fix: fix more floating promise eslint issues (#3640)
Browse files Browse the repository at this point in the history
For some reason eslint is passing on master, but fails
after the yarn lock was updating when adding madge. This PR
cherry-picks a commit fixing the lint errors from the
abhi/circular-dep branch
  • Loading branch information
AbhiPrasad authored Jun 2, 2021
1 parent 6ae95a4 commit 172e478
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 42 deletions.
2 changes: 1 addition & 1 deletion packages/browser/src/transports/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class FetchTransport extends BaseTransport {

return this._buffer.add(
new SyncPromise<Response>((resolve, reject) => {
this._fetch(sentryRequest.url, options)
void this._fetch(sentryRequest.url, options)
.then(response => {
const headers = {
'x-sentry-rate-limits': response.headers.get('X-Sentry-Rate-Limits'),
Expand Down
8 changes: 4 additions & 4 deletions packages/integrations/src/offline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class Offline implements Integration {

if ('addEventListener' in this.global) {
this.global.addEventListener('online', () => {
this._sendEvents().catch(() => {
void this._sendEvents().catch(() => {
logger.warn('could not send cached events');
});
});
Expand All @@ -79,7 +79,7 @@ export class Offline implements Integration {
if (this.hub && this.hub.getIntegration(Offline)) {
// cache if we are positively offline
if ('navigator' in this.global && 'onLine' in this.global.navigator && !this.global.navigator.onLine) {
this._cacheEvent(event)
void this._cacheEvent(event)
.then((_event: Event): Promise<void> => this._enforceMaxEvents())
.catch((_error): void => {
logger.warn('could not cache event while offline');
Expand All @@ -95,7 +95,7 @@ export class Offline implements Integration {

// if online now, send any events stored in a previous offline session
if ('navigator' in this.global && 'onLine' in this.global.navigator && this.global.navigator.onLine) {
this._sendEvents().catch(() => {
void this._sendEvents().catch(() => {
logger.warn('could not send cached events');
});
}
Expand Down Expand Up @@ -159,7 +159,7 @@ export class Offline implements Integration {
if (this.hub) {
this.hub.captureEvent(event);

this._purgeEvent(cacheKey).catch((_error): void => {
void this._purgeEvent(cacheKey).catch((_error): void => {
logger.warn('could not purge event from cache');
});
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class NodeBackend extends BaseBackend<NodeOptions> {
return new SyncPromise<Event>(resolve => {
if (this._options.attachStacktrace && hint && hint.syntheticException) {
const stack = hint.syntheticException ? extractStackFromError(hint.syntheticException) : [];
parseStack(stack, this._options)
void parseStack(stack, this._options)
.then(frames => {
event.stacktrace = {
frames: prepareFramesForEvent(frames),
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ export function requestHandler(
// eslint-disable-next-line @typescript-eslint/unbound-method
const _end = res.end;
res.end = function(chunk?: any | (() => void), encoding?: string | (() => void), cb?: () => void): void {
flush(options.flushTimeout)
void flush(options.flushTimeout)
.then(() => {
_end.call(this, chunk, encoding, cb);
})
Expand Down
6 changes: 3 additions & 3 deletions packages/node/src/integrations/linkederrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class LinkedErrors implements Integration {
}

return new SyncPromise<Event>(resolve => {
this._walkErrorTree(hint.originalException as Error, this._key)
void this._walkErrorTree(hint.originalException as Error, this._key)
.then((linkedErrors: Exception[]) => {
if (event && event.exception && event.exception.values) {
event.exception.values = [...linkedErrors, ...event.exception.values];
Expand All @@ -81,9 +81,9 @@ export class LinkedErrors implements Integration {
return SyncPromise.resolve(stack);
}
return new SyncPromise<Exception[]>((resolve, reject) => {
getExceptionFromError(error[key])
void getExceptionFromError(error[key])
.then((exception: Exception) => {
this._walkErrorTree(error[key], key, [exception, ...stack])
void this._walkErrorTree(error[key], key, [exception, ...stack])
.then(resolve)
.then(null, () => {
reject();
Expand Down
10 changes: 5 additions & 5 deletions packages/node/test/parsers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ describe('parsers.ts', () => {
test('parseStack with same file', done => {
expect.assertions(1);
let mockCalls = 0;
Parsers.parseStack(frames)
void Parsers.parseStack(frames)
.then(_ => {
mockCalls = spy.mock.calls.length;
Parsers.parseStack(frames)
void Parsers.parseStack(frames)
.then(_1 => {
// Calls to readFile shouldn't increase if there isn't a new error
expect(spy).toHaveBeenCalledTimes(mockCalls);
Expand Down Expand Up @@ -63,14 +63,14 @@ describe('parsers.ts', () => {
expect.assertions(2);
let mockCalls = 0;
let newErrorCalls = 0;
Parsers.parseStack(frames)
void Parsers.parseStack(frames)
.then(_ => {
mockCalls = spy.mock.calls.length;
Parsers.parseStack(stacktrace.parse(getError()))
void Parsers.parseStack(stacktrace.parse(getError()))
.then(_1 => {
newErrorCalls = spy.mock.calls.length;
expect(newErrorCalls).toBeGreaterThan(mockCalls);
Parsers.parseStack(stacktrace.parse(getError()))
void Parsers.parseStack(stacktrace.parse(getError()))
.then(_2 => {
expect(spy).toHaveBeenCalledTimes(newErrorCalls);
done();
Expand Down
2 changes: 1 addition & 1 deletion packages/serverless/src/gcpfunction/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function _wrapHttpFunction(fn: HttpFunction, wrapOptions: Partial<HttpFunctionWr
transaction.setHttpStatus(res.statusCode);
transaction.finish();

flush(options.flushTimeout)
void flush(options.flushTimeout)
.then(() => {
_end.call(this, chunk, encoding, cb);
})
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function forget(promise: PromiseLike<any>): void {
promise.then(null, e => {
void promise.then(null, e => {
// TODO: Use a better logging mechanism
// eslint-disable-next-line no-console
console.error(e);
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/src/promisebuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class PromiseBuffer<T> {
if (this._buffer.indexOf(task) === -1) {
this._buffer.push(task);
}
task
void task
.then(() => this.remove(task))
.then(null, () =>
this.remove(task).then(null, () => {
Expand Down Expand Up @@ -70,7 +70,7 @@ export class PromiseBuffer<T> {
resolve(false);
}
}, timeout);
SyncPromise.all(this._buffer)
void SyncPromise.all(this._buffer)
.then(() => {
clearTimeout(capturedSetTimeout);
resolve(true);
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/src/syncpromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class SyncPromise<T> implements PromiseLike<T> {
const resolvedCollection: U[] = [];

collection.forEach((item, index) => {
SyncPromise.resolve(item)
void SyncPromise.resolve(item)
.then(value => {
resolvedCollection[index] = value;
counter -= 1;
Expand Down Expand Up @@ -184,7 +184,7 @@ class SyncPromise<T> implements PromiseLike<T> {
}

if (isThenable(value)) {
(value as PromiseLike<T>).then(this._resolve, this._reject);
void (value as PromiseLike<T>).then(this._resolve, this._reject);
return;
}

Expand Down
50 changes: 29 additions & 21 deletions packages/utils/test/syncpromise.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ describe('SyncPromise', () => {

const fp = async (s: PromiseLike<string>, prepend: string) =>
new Promise<string>(resolve => {
s.then(val => {
resolve(prepend + val);
}).then(null, _ => {
// bla
});
void s
.then(val => {
resolve(prepend + val);
})
.then(null, _ => {
// bla
});
});

const res = await cp
Expand All @@ -70,11 +72,13 @@ describe('SyncPromise', () => {

const f = (s: SyncPromise<string>, prepend: string) =>
new SyncPromise<string>(resolve => {
s.then(val => {
resolve(prepend + val);
}).then(null, () => {
// no-empty
});
void s
.then(val => {
resolve(prepend + val);
})
.then(null, () => {
// no-empty
});
});

return (
Expand Down Expand Up @@ -103,7 +107,7 @@ describe('SyncPromise', () => {
expect.assertions(2);

return new SyncPromise<number>(done => {
new Promise<number>(resolve => {
void new Promise<number>(resolve => {
expect(true).toBe(true);
resolve(41);
})
Expand Down Expand Up @@ -152,17 +156,21 @@ describe('SyncPromise', () => {
resolve(2);
}),
);
qp.then(value => {
expect(value).toEqual(2);
}).then(null, () => {
// no-empty
});
void qp
.then(value => {
expect(value).toEqual(2);
})
.then(null, () => {
// no-empty
});
expect(qp).not.toHaveProperty('_value');
qp.then(value => {
expect(value).toEqual(2);
}).then(null, () => {
// no-empty
});
void qp
.then(value => {
expect(value).toEqual(2);
})
.then(null, () => {
// no-empty
});
jest.runAllTimers();
expect(qp).toHaveProperty('_value');
});
Expand Down

0 comments on commit 172e478

Please sign in to comment.