-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(eslint-plugin): [no-floating-promises] finally should be transparent to unhandled promises #7092
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
fix(eslint-plugin): [no-floating-promises] finally should be transparent to unhandled promises #7092
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 |
---|---|---|
|
@@ -31,7 +31,6 @@ async function test() { | |
.catch(() => {}) | ||
.finally(() => {}); | ||
Promise.resolve('value').catch(() => {}); | ||
Promise.resolve('value').finally(() => {}); | ||
return Promise.resolve('value'); | ||
} | ||
`, | ||
|
@@ -58,7 +57,6 @@ async function test() { | |
.catch(() => {}) | ||
.finally(() => {}); | ||
Promise.reject(new Error('message')).catch(() => {}); | ||
Promise.reject(new Error('message')).finally(() => {}); | ||
return Promise.reject(new Error('message')); | ||
} | ||
`, | ||
|
@@ -77,7 +75,6 @@ async function test() { | |
.catch(() => {}) | ||
.finally(() => {}); | ||
(async () => true)().catch(() => {}); | ||
(async () => true)().finally(() => {}); | ||
return (async () => true)(); | ||
} | ||
`, | ||
|
@@ -97,7 +94,6 @@ async function test() { | |
.catch(() => {}) | ||
.finally(() => {}); | ||
returnsPromise().catch(() => {}); | ||
returnsPromise().finally(() => {}); | ||
return returnsPromise(); | ||
} | ||
`, | ||
|
@@ -106,7 +102,6 @@ async function test() { | |
const x = Promise.resolve(); | ||
const y = x.then(() => {}); | ||
y.catch(() => {}); | ||
y.finally(() => {}); | ||
} | ||
`, | ||
` | ||
|
@@ -117,7 +112,6 @@ async function test() { | |
` | ||
async function test() { | ||
Promise.resolve().catch(() => {}), 123; | ||
Promise.resolve().finally(() => {}), 123; | ||
123, | ||
Promise.resolve().then( | ||
() => {}, | ||
|
@@ -160,7 +154,6 @@ async function test() { | |
.catch(() => {}) | ||
.finally(() => {}); | ||
promiseValue.catch(() => {}); | ||
promiseValue.finally(() => {}); | ||
return promiseValue; | ||
} | ||
`, | ||
|
@@ -193,12 +186,7 @@ async function test() { | |
() => {}, | ||
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. [Non-actionable] Aside: the |
||
); | ||
promiseIntersection.then(() => {}).catch(() => {}); | ||
promiseIntersection | ||
.then(() => {}) | ||
.catch(() => {}) | ||
.finally(() => {}); | ||
promiseIntersection.catch(() => {}); | ||
promiseIntersection.finally(() => {}); | ||
return promiseIntersection; | ||
} | ||
`, | ||
|
@@ -218,7 +206,6 @@ async function test() { | |
.catch(() => {}) | ||
.finally(() => {}); | ||
canThen.catch(() => {}); | ||
canThen.finally(() => {}); | ||
return canThen; | ||
} | ||
`, | ||
|
@@ -315,7 +302,6 @@ async function test() { | |
.catch(() => {}) | ||
.finally(() => {}); | ||
promise.catch(() => {}); | ||
promise.finally(() => {}); | ||
return promise; | ||
} | ||
`, | ||
|
@@ -333,7 +319,6 @@ async function test() { | |
?.then(() => {}) | ||
?.catch(() => {}); | ||
returnsPromise()?.catch(() => {}); | ||
returnsPromise()?.finally(() => {}); | ||
return returnsPromise(); | ||
} | ||
`, | ||
|
@@ -465,6 +450,31 @@ Promise.reject().catch(definitelyCallable); | |
`, | ||
options: [{ ignoreVoid: false }], | ||
}, | ||
{ | ||
code: ` | ||
Promise.reject() | ||
.catch(() => {}) | ||
.finally(() => {}); | ||
`, | ||
}, | ||
{ | ||
code: ` | ||
Promise.reject() | ||
.catch(() => {}) | ||
.finally(() => {}) | ||
.finally(() => {}); | ||
`, | ||
options: [{ ignoreVoid: false }], | ||
}, | ||
{ | ||
code: ` | ||
Promise.reject() | ||
.catch(() => {}) | ||
.finally(() => {}) | ||
.finally(() => {}) | ||
.finally(() => {}); | ||
`, | ||
}, | ||
JoshuaKGoldberg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
], | ||
|
||
invalid: [ | ||
|
@@ -612,7 +622,6 @@ async function test() { | |
(async () => true)(); | ||
(async () => true)().then(() => {}); | ||
(async () => true)().catch(); | ||
(async () => true)().finally(); | ||
} | ||
`, | ||
errors: [ | ||
|
@@ -628,10 +637,6 @@ async function test() { | |
line: 5, | ||
messageId: 'floatingVoid', | ||
}, | ||
{ | ||
line: 6, | ||
messageId: 'floatingVoid', | ||
}, | ||
], | ||
}, | ||
{ | ||
|
@@ -940,7 +945,6 @@ async function test() { | |
promiseIntersection; | ||
promiseIntersection.then(() => {}); | ||
promiseIntersection.catch(); | ||
promiseIntersection.finally(); | ||
} | ||
`, | ||
errors: [ | ||
|
@@ -956,10 +960,6 @@ async function test() { | |
line: 7, | ||
messageId: 'floatingVoid', | ||
}, | ||
{ | ||
line: 8, | ||
messageId: 'floatingVoid', | ||
}, | ||
], | ||
}, | ||
{ | ||
|
@@ -1587,5 +1587,69 @@ Promise.reject() || 3; | |
}, | ||
], | ||
}, | ||
{ | ||
code: ` | ||
Promise.reject().finally(() => {}); | ||
`, | ||
errors: [{ line: 2, messageId: 'floatingVoid' }], | ||
}, | ||
{ | ||
code: ` | ||
Promise.reject() | ||
.finally(() => {}) | ||
.finally(() => {}); | ||
`, | ||
options: [{ ignoreVoid: false }], | ||
errors: [{ line: 2, messageId: 'floating' }], | ||
}, | ||
{ | ||
code: ` | ||
Promise.reject() | ||
.finally(() => {}) | ||
.finally(() => {}) | ||
.finally(() => {}); | ||
`, | ||
errors: [{ line: 2, messageId: 'floatingVoid' }], | ||
}, | ||
{ | ||
code: ` | ||
Promise.reject() | ||
.then(() => {}) | ||
.finally(() => {}); | ||
`, | ||
errors: [{ line: 2, messageId: 'floatingVoid' }], | ||
}, | ||
{ | ||
code: ` | ||
declare const returnsPromise: () => Promise<void> | null; | ||
returnsPromise()?.finally(() => {}); | ||
`, | ||
errors: [{ line: 3, messageId: 'floatingVoid' }], | ||
}, | ||
{ | ||
code: ` | ||
const promiseIntersection: Promise<number> & number; | ||
promiseIntersection.finally(() => {}); | ||
`, | ||
errors: [{ line: 3, messageId: 'floatingVoid' }], | ||
}, | ||
{ | ||
code: ` | ||
Promise.resolve().finally(() => {}), 123; | ||
`, | ||
errors: [{ line: 2, messageId: 'floatingVoid' }], | ||
}, | ||
{ | ||
code: ` | ||
(async () => true)().finally(); | ||
`, | ||
errors: [{ line: 2, messageId: 'floatingVoid' }], | ||
}, | ||
{ | ||
code: ` | ||
Promise.reject(new Error('message')).finally(() => {}); | ||
`, | ||
errors: [{ line: 2, messageId: 'floatingVoid' }], | ||
}, | ||
], | ||
}); |
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.
[Praise] This second line was very helpful for understanding the code :) great comment!