Skip to content

[linter] unnecessary_else_block suggestion #60078

@FMorschel

Description

@FMorschel

Inspired by #60008.

If you have the following code:

void f(bool c) {
  if (c) {
    // do something
    return;
  } else {
    // do something else
  }
}

The above // do something else does not need to be inside an else { ... } block.

I'm suggesting a lint that would detect this (leaving the function on earlier branches) and suggest removing the block since that could help with indentation for big lines that come after this point. Something like unnecessary_else_block.

// CC @pq

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