-
Notifications
You must be signed in to change notification settings - Fork 200
How to make a rule that disables implicit truthy conversion from function to boolean #112
Comments
This would be quite a nice rule. A couple things to consider:
We could make this rule, but honestly it would miss about 95% of the violations. That isn't much safety. |
Thanks for the fast reply! I forked and modified the And indeed, we found some bugs in our large code base :-) But I'm pretty sure the Personally I hate automatic |
I don’t think it would hurt to submit the idea on the TS project and see what they think. Personally I’d love to see this as part of a TSStrictMode option where the devs could tell the compiler to be much more pedantic about potential issues From: Peter Verswyvelen [mailto:[email protected]] Thanks for the fast reply! I forked and modified the Typescript compiler for checking this. I was amazed how cleanly it was written, so it was very easy to hack, it took less than 2 hours!. And indeed, we found some bugs in our large code base :-) But I'm pretty sure the Typescript team will not want this kind of checks, as they deviate too much from Javascript? Personally I hate automatic truthy and falsy conversions in large projects, the comfort they bring does not outweigh the dangers. — |
This is covered in palantir/tslint#253 |
Great! However, the feedback I got from @HamletDRC seems to indicate that in most cases this is useless since the node type will be infered to be |
@ziriax and @joshbw ,Hang in there. Implementation of that new Tsllint rule not easy than hack of tsc-complier. (a) TSLint use TSC-Complier with "compilerOptions.noResolve = true". for (a); I have been challenged to workaround, performance has become very bad. for (b);TSLint-Contributors says that No-Good "search" for the many file, and tsconfig.json read in TSLint-task, to be compiles. I hope that the better solution is created. |
I am closing this issue here because it will be part of TSLint when they start linting entire programs as a whole. |
We have a large typescript application, and sometimes we have code like
if (shouldFireNuclearMissiles)...
while we should have written
if (shouldFireNuclearMissiles())...
(pun intended).
So forgetting to evaluate a function results in a truthy value.
Is it possible to write a rule that forbids this kind of implicit function-to-boolean conversions?
Or does this require forking typescript?
Thanks,
Peter
The text was updated successfully, but these errors were encountered: