Repository navigation
typescript-eslint/strict-boolean-expressions lint #6546
Replies: 6 comments 1 reply
|
Yeah, i have an issue where sometimes I accidentally put a function in an if statement without calling it: |
|
It's a big problem with async functions. if (isAdmin()) ... // Fine
function isAdmin(): boolean { ... }if (isAdmin()) ... // Disaster
async function isAdmin(): Promise<boolean> { ... } |
|
+1 for this feature. Every modern language (Kotlin, Swift, Rust) has moved away from truthy/falsy values, and it requires an explicit expression that evaluates to boolean in boolean contexts. Moreover what's truthy and falsy changes from language to language, so it might not be entirely obvious what |
|
I'm happy that a first rudimentary form of this rule has landed in version 2.5.15, thank you very much for implementing it 😀 It would be really great to support the options that the ESLint rule supports though, because as it is now, Biome's rule only checks for nullable types, but the confusion coming from each language treating falsy differently still remains, so it would be super to have this rule to have an option to error out on anything that is treated as truthy/falsy and is not of type boolean. |
|
@dyc3 thanks for your PR... if/when you or someone implements options for it, I would love to just be able to turn off everything except for a simple case, accidentlly adding function (or function-like callable types like signals) to some code. |
|
Implemented: https://biomejs.dev/linter/rules/use-strict-boolean-expressions/javascript/ |
Uh oh!
There was an error while loading. Please reload this page.
I would like to be able to use this lint:
https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/strict-boolean-expressions.mdx
I could also imagine a wider lint against coercions in general.
All reactions