-
Notifications
You must be signed in to change notification settings - Fork 395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ESLint Config Migration: Fixing consistent-return linter warnings #1075
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -695,6 +695,8 @@ export default class App { | |
} catch (error) { | ||
this.logger.warn('Authorization of incoming event did not succeed. No listeners will be called.'); | ||
error.code = 'slack_bolt_authorization_error'; | ||
// disabling due to https://github.com/typescript-eslint/typescript-eslint/issues/1277 | ||
// eslint-disable-next-line consistent-return | ||
return this.handleError(error); | ||
} | ||
|
||
|
@@ -860,22 +862,23 @@ export default class App { | |
// Don't process the last item in the listenerMiddleware array - it shouldn't get a next fn | ||
const listener = listenerMiddleware.pop(); | ||
|
||
if (listener !== undefined) { | ||
return processMiddleware( | ||
listenerMiddleware, | ||
listenerArgs as AnyMiddlewareArgs, | ||
if (listener === undefined) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this part, we have to explicitly, instead of implicitly, return undefined in the case the listener is undefined. I like to nest/indent the exceptional case and return right away, which allows me to do further processing below this conditional nested one indent less. So that's what I did here. 🤷 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is fine. |
||
return undefined; | ||
} | ||
return processMiddleware( | ||
listenerMiddleware, | ||
listenerArgs as AnyMiddlewareArgs, | ||
context, | ||
client, | ||
this.logger, | ||
// When the listener middleware chain is done processing, call the listener without a next fn | ||
async () => listener({ | ||
...(listenerArgs as AnyMiddlewareArgs), | ||
context, | ||
client, | ||
this.logger, | ||
// When the listener middleware chain is done processing, call the listener without a next fn | ||
async () => listener({ | ||
...(listenerArgs as AnyMiddlewareArgs), | ||
context, | ||
client, | ||
logger: this.logger, | ||
}), | ||
); | ||
} | ||
logger: this.logger, | ||
}), | ||
); | ||
}); | ||
|
||
const settledListenerResults = await allSettled(listenerResults); | ||
|
@@ -890,6 +893,8 @@ export default class App { | |
}, | ||
); | ||
} catch (error) { | ||
// disabling due to https://github.com/typescript-eslint/typescript-eslint/issues/1277 | ||
// eslint-disable-next-line consistent-return | ||
return this.handleError(error); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -327,25 +327,25 @@ export default class ExpressReceiver implements Receiver { | |
return reject(new ReceiverInconsistentStateError(missingServerErrorDescription)); | ||
} | ||
|
||
resolve(this.server); | ||
return resolve(this.server); | ||
}); | ||
}); | ||
} | ||
|
||
// TODO: the arguments should be defined as the arguments to close() (which happen to be none), but for sake of | ||
// generic types | ||
public stop(): Promise<void> { | ||
if (this.server === undefined) { | ||
return Promise.reject(new ReceiverInconsistentStateError('The receiver cannot be stopped because it was not started.')); | ||
} | ||
return new Promise((resolve, reject) => { | ||
if (this.server === undefined) { | ||
return reject(new ReceiverInconsistentStateError('The receiver cannot be stopped because it was not started.')); | ||
} | ||
this.server.close((error) => { | ||
this.server?.close((error) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm. I assume There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @misscoded so if I remove the
... which is silly, since we have a check for If anyone has suggestions how to avoid this, I'd love to learn! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm.. ok! No suggestions here at the moment |
||
if (error !== undefined) { | ||
return reject(error); | ||
} | ||
|
||
this.server = undefined; | ||
resolve(); | ||
return resolve(); | ||
}); | ||
}); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -242,25 +242,25 @@ export default class HTTPReceiver implements Receiver { | |
return reject(new ReceiverInconsistentStateError(missingServerErrorDescription)); | ||
} | ||
|
||
resolve(this.server); | ||
return resolve(this.server); | ||
}); | ||
}); | ||
} | ||
|
||
// TODO: the arguments should be defined as the arguments to close() (which happen to be none), but for sake of | ||
// generic types | ||
public stop(): Promise<void> { | ||
if (this.server === undefined) { | ||
return Promise.reject(new ReceiverInconsistentStateError('The receiver cannot be stopped because it was not started.')); | ||
} | ||
return new Promise((resolve, reject) => { | ||
if (this.server === undefined) { | ||
return reject(new ReceiverInconsistentStateError('The receiver cannot be stopped because it was not started.')); | ||
} | ||
this.server.close((error) => { | ||
this.server?.close((error) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment/question as |
||
if (error !== undefined) { | ||
return reject(error); | ||
} | ||
|
||
this.server = undefined; | ||
resolve(); | ||
return resolve(); | ||
}); | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TL;DR typescript-eslint/typescript-eslint#1277 core eslint consistent-return is not type aware, and typescript-eslint has not implemented an extension to avoid this issue (functions that return
Promise<void>
are not honoured in terms of return type)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The clear comment about the reason here is really nice 👍