Skip to content

Loosen promise/catch-or-return and promise/param-names rules#384

Merged
Mrtenz merged 1 commit intomainfrom
mrtenz/loosen-promise-rules
Feb 19, 2025
Merged

Loosen promise/catch-or-return and promise/param-names rules#384
Mrtenz merged 1 commit intomainfrom
mrtenz/loosen-promise-rules

Conversation

@Mrtenz
Copy link
Copy Markdown
Member

@Mrtenz Mrtenz commented Feb 19, 2025

promise/catch-or-return and promise/param-names are too strict by default. This changes the configuration slightly to loosen these rules. The exact reasons are explained in a comment below.

Comment on lines +421 to +426
'promise/catch-or-return': [
'error',
{
allowFinally: true,
},
],
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, allowFinally is set to false, meaning that this is not allowed unless returned.

someFunction().catch(() => { /* ... */ }).finally(() => { /* ... */ });

While this is allowed:

someFunction().catch(() => { /* ... */ });

or

return someFunction().catch(() => { /* ... */ }).finally(() => { /* ... */ });

After this change, the first example is allowed as well.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a strange default. What does finally have to do with remembering to catch? Bizarre.

Comment on lines +427 to +433
'promise/param-names': [
'error',
{
resolvePattern: '^_?resolve',
rejectPattern: '^_?reject',
},
],
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolvePattern and rejectPattern are set to ^_?resolve$ and ^_?reject$ by default respectively, meaning that the parameters passed to a Promise constructor function must be named exactly resolve, reject, or _resolve, _reject.

This change allows for an optional suffix after resolve and reject, for example resolvePromise or rejectPromise, which can be useful when promises are nested.

@Mrtenz Mrtenz marked this pull request as ready for review February 19, 2025 13:12
@Mrtenz Mrtenz requested review from a team as code owners February 19, 2025 13:12
Copy link
Copy Markdown
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Mrtenz Mrtenz force-pushed the mrtenz/loosen-promise-rules branch from 59545e5 to 0b4fb83 Compare February 19, 2025 14:32
@Mrtenz Mrtenz merged commit f654fe6 into main Feb 19, 2025
20 checks passed
@Mrtenz Mrtenz deleted the mrtenz/loosen-promise-rules branch February 19, 2025 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants