This message is misleading at best, but could easily introduce breaking changes. Had the developer followed the recommendation and removed the false, this would have broken the transaction handling and created additional runtime errors in the program. Indeed this is what had happened, except that the removal was caught by a human during PR review and was restored. The error depicted above is the result of that restoration.
A negation is already present in the form of == false. It’s not a negation operator (but it means the same thing, and there is less chance for a later reader to miss this style of negation and create a bug).
Sonar shouldn’t be suggesting what is present is wrong or worse in any way, and definitely should not be advising that it be removed.
Rule is suggesting to change if (session.hasEnded == false) by if (!session.hasEnded). I believe second option is equivalent and more conventional and faster to understand. So to me this issue is valid.
If you have different opinion you can disable the rule on your projects.
The suggestion will literally break people’s code. It’s not telling me to do what you think it suggests. It is telling me to remove the == false, not replace it with anything or make any other changes.
On the topic of redundancy, if you will be able to see if (!IsReady()) as well as if (IsReady() == false) in a few years, then good for you. I still can (for now but probably not much longer), but have worked with others whose vision was affected by age or medical condition, and there were bugs (more than one, and by multiple people) due to missing the harder to notice/read negation operator. I’d like to keep following that practice without having sonar tell me that accessibility and readability should be ignored in this case solely because it’s what most of the herd does.
So as much as we may want the part of the rule that does work, we can’t use it because of the parts that are incorrect.
Which is confusing, this whole sonar program suite is about improving quality and reducing the chance of bugs. There are rules for requiring braces on single line conditionals; using == false instead of ! is the same reasoning, but sonar has a wobbly about it.
It was probably conventional to have sidewalk aprons have a small step all the way around too, since everyone knows there is a small four inch step up that they have to navigate. Now they are required by law to have ramps. Sometimes the convention is wrong.
In this case it’s also placed in a rule that checks for redundancy when it’s not a redundant condition.