Skip to content

Lint for unintentional assignment in if/do/while #58547

Open
@dnfield

Description

@dnfield

Similar to #58546

BAD:

bool foo = false;

// ...

if (foo = true) {}
else if (foo = false) {}

while (foo = true) {}  // or false

do {} while (foo = true); // or false

GOOD:

bool foo = false;

// ...

if (foo == true) {}

while (foo == true) {}

do {} while (foo == true);

These lints should apply if the literal true or false is used. I'm not sure if they should apply when a const expression that evaluates to true or false is used. I think they should not apply if some non-const expression is used, e.g. while (keepGoing = checkIfIShouldKeepGoing()) would not trigger the lint.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packagelinter-lint-requesttype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions