Skip to content

consider a new lint: use_switch_expressions #58862

Open
@pq

Description

@pq

We might consider a lint to encourage the use of switch-expressions.

BAD

Color shiftHue(Color color) {
  switch (color) {
    case Color.red:
      return Color.orange;
    case Color.blue:
      return Color.purple;
    case Color.green:
      throw 'Green is bad';
    case Color.yellow:
      return Color.green;
  }
}

GOOD

Color shiftHue(Color color) {
  return switch (color) {
    Color.red => Color.orange,
    Color.orange => Color.yellow,
    Color.yellow => Color.green,
    Color.green => throw 'Green is bad'
    Color.blue => Color.purple,
    Color.purple => Color.red
  };
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onarea-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-proposallinter-new-language-featurelinter-status-pendingtype-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