Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

[Rule Request] no-promise-in-boolean-expressions #3804

Closed
danielberndt opened this issue Apr 2, 2018 · 5 comments
Closed

[Rule Request] no-promise-in-boolean-expressions #3804

danielberndt opened this issue Apr 2, 2018 · 5 comments

Comments

@danielberndt
Copy link

We're working with a lot of async/await in our backend code, and the most frequent source of mistake I found in our code base has this shape:

if (user.pictures.exists()) doX()

whereas it should be

if (await user.pictures.exists()) doX()

I'm aware of the strict-boolean-expressions rule, but its ruleset is too strict for our code. So I'm suggesting to create a softer version which allows anything but promises in boolean expressions.

@JoshuaKGoldberg
Copy link
Contributor

but its ruleset is too strict for our code

Specifically which parts? Maybe the rule could have options added that would allow it to be flexible enough for you?

@oleg-codaio
Copy link
Contributor

+1 to the strictness of that rule. We have a lot of code that looks like this:

let maybeObj: SomeObject | undefined = getObj();

if (maybeObj) {
  // do something
}

If this logic was put into that rule, I'd want a rule like "allow-all-unions-except": <symbols> where <symbols> is an array of classes that cannot be in a boolean expression. To handles promises correctly, I'd set that to ["Promise", "Bluebird"] in our codebase.

@oleg-codaio
Copy link
Contributor

I did find something like this elsewhere: https://github.com/wwwouter/tslint-contrib but unfortunately it doesn't support blacklisting additional classes like "Bluebird".

@JoshuaKGoldberg
Copy link
Contributor

Looks like discussion continued a bit deeper in #3983 for a very similar idea. Closing this issue as duplicate; let's continue talking there.

@wclr
Copy link

wclr commented Nov 19, 2018

Right, this is a common bug.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants