Skip to content

Prevent equality checks as statements #59028

Closed
@jonmountjoy

Description

@jonmountjoy

Describe the rule you'd like to see added and to what rule set
I'd like to prevent this kind of bug:

...
itemState.learningAspect == LearningAspect.learnNumber;
...

In other words, I have a statement, and that statement is an equality check, the value of which I'm discarding.

It's almost always an error (for me, it's always an error), because what I invariably want to write is:

itemState.learningAspect = LearningAspect.learnNumber;

In other words, I've used an equality check (copy pasta or finger slip or whatever) instead of an assignment.

I can't imagine a scenario when anyone would want to write that kind of statement, but I guess it's possible. In other contexts (embedded as an expression), types would usually catch the error. But as a standalone statement, the type system is quite happy. I imagine at run time it performs the equality check and discards the boolean result.

In some ways I think it's similar to unawaited_futures. I wouldn't mind an "unused_boolean" - it would cover me in this situation and force me to think more about my other methods too.

Thoughts?

(thanks!)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestdevexp-linterIssues with the analyzer's support for the linter packagelegacy-area-analyzerUse area-devexp instead.type-questionA question about expected behavior or functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions