palantir / tslint

:vertical_traffic_light: An extensible linter for the TypeScript language
http://palantir.github.io/tslint/
Apache License 2.0
5.91k stars 889 forks source link

A && B with B as promise not handled do not result in error. #3942

Closed rbarros-daitan closed 4 years ago

rbarros-daitan commented 6 years ago

Bug Report

TypeScript code being linted

It seems tslint does not see a problem because when exists a "a && b" syntax (with allow-fast-null-checks in no-unused-expression rule enabled). It looks like an independent rule. "a && b" can be allowed, but if the b expression is a promise, no promise not handled is launched.

Actual behavior

Tests are ok with expression "a && b" when b is promise not handled.

Expected behavior

The "no-floating-promises" rule should fail.

sergey-su commented 6 years ago

I believe the problem occurs when expression evaluates to union type where Promise is one option such as undefined | Promise<void>. booleanExpression && promiseExpression is one example.

Another example:

function test(): Promise<void> | undefined {
    return undefined;
}

_test(); // no-floating-promises should fail, but it does not
JoshuaKGoldberg commented 5 years ago

a && b where b is a Promise

Yes, this is intentional. That is technically not a "floating" promise, as the promise is being used (as silly as that sounds). See #3983; this should be better documented per #4117.

test(): Promise<void> | undefined

Seems like that's a tricky bug with no-floating-promises. If a type union that contains a Promise is returned, then the code flow path that contains the Promise must handle it... which sounds pretty hard to do for TSLint. Marking this as accepting a bug fix, but if it ends up being hundreds of lines of code, it might not be worth it.

JoshuaKGoldberg commented 4 years ago

💀 It's time! 💀

TSLint is deprecated and no longer accepting pull requests other than security fixes. See #4534. ☠️ We recommend you instead use typescript-eslint to lint your TypeScript code with ESLint. ✅

👋 It was a pleasure open sourcing with you!

JoshuaKGoldberg commented 4 years ago

🤖 Beep boop! 👉 TSLint is deprecated 👈 (#4534) and you should switch to typescript-eslint! 🤖

🔒 This issue is being locked to prevent further unnecessary discussions. Thank you! 👋