-
Notifications
You must be signed in to change notification settings - Fork 56
Description
booleansInConditions is very strict, which is great and all (kind of the point of this project), but makes it a bit of a pain to enable in a large legacy codebase -- I believe (and may well be wrong) that should be possible to accept a significantly wider variety of inputs and still be equally correct - specifically: allowing non-booleans so long as only one of the types in the union can be false-y, eg
MyClass|null-if($var)is checking for object vs null, that's okbool|null-if($var)is ambiguous if we're checking forfalseornull, rejectarray-if($var)can only be checking for empty-array vs non-empty-array, allowarray|null- is ambiguous, rejectnon-empty-array|null-if($var)can only mean one thing, allow0|1- allowed0|1|false- 0 and false are meaningfully different, we should reject and force the dev to handle it- etc
(I currently have booleansInConditions disabled because it makes a lot of noise in my large legacy project, and nearly all the instances that it flags are cases that I would personally consider to be false-positives -- but I just got bitten by a bug where I was handling a bool|null and forgot to handle the false and null cases separately... FWIW my gut says it's weird that I'm willing to accept multiple-potential-truths but want my linter to reject multiple-potential-falseys - but scanning my codebases, "multiple potential truths" is always fine in practice and "multiple false-y types all being treated the same" is nearly-always a bug, so maybe a rule like this would be broadly valuable?)