Skip to content

Lint to check that assert does not do assignment #58546

@dnfield

Description

@dnfield

BAD:

assert(foo = true); // Always evaluates to true, and will always pass.
assert(bar = false); // Always evaluates to false, and will always fail.

GOOD:

assert(foo == true);
assert(bar == false);

// Intentionally set foo to true when asserts are enabled.
assert(() {
  foo = true;
  return true;
}());

This has definitely caused problems for Flutter before - maybe @jonahwilliams remembers what, but I seem to remember him finding an assertion written like this that, when corrected, failed so often it had to just be disabled.

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-proposaltype-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