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

New rule to only allow boolean statements in logical expressions #253

Closed
oefirouz opened this issue Dec 18, 2014 · 9 comments
Closed

New rule to only allow boolean statements in logical expressions #253

oefirouz opened this issue Dec 18, 2014 · 9 comments

Comments

@oefirouz
Copy link

Disallow if (expr) unless expr is a boolean.

So no if (obj)... rather if (obj != null)

@ashwinr
Copy link
Contributor

ashwinr commented Dec 18, 2014

the "unless expr is a boolean" might be troublesome since we don't use the typing annotations from the compiler yet. we'll need to investigate that.

@adidahiya
Copy link
Contributor

I think the new TS APIs have support for type information about nodes. This should be doable.

@adidahiya
Copy link
Contributor

blocked on #680

@jkillian
Copy link
Contributor

See microsoft/TypeScript#9702 as well, although as far as I can tell they haven't decided to implement this yet. This shouldn't be too hard to do now on our end!

@Sammons
Copy link

Sammons commented Aug 19, 2016

I would really like this to help with not coercing promise-like types to booleans, but I think it would be really nice if we could explicitly enable certain types (strings, numbers) for coercion.

@radykov
Copy link

radykov commented Sep 20, 2016

I think the new TS APIs have support for type information about nodes. This should be doable.

Would it be able to pick up things such as x = y || z;?
I'm unfamiliar with TS APIs and what was meant by nodes

@adidahiya
Copy link
Contributor

@radykov

Would it be able to pick up things such as x = y || z;?

yes, that check should probably be incorporated into this lint rule.

@OliverJAsh
Copy link
Contributor

This would be really handy and catch so many bugs.

@adidahiya
Copy link
Contributor

fixed via #1820

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

7 participants