no_default_cases

Group: style

Maturity: experimental

Dart SDK: >= 2.9.0-12.0.dev • (Linter v0.1.116)

Since info is static, may be stale

View all Lint Rules

Using the Linter

Switches on enums and enum-like classes should not use a default clause.

Enum-like classes are defined as concrete (non-abstract) classes that have:

DO define default behavior outside switch statements.

GOOD:

  switch (testEnum) {
    case TestEnum.A:
      return '123';
    case TestEnum.B:
      return 'abc';
  }
  // Default here.
  return null;

BAD:

  switch (testEnum) {
    case TestEnum.A:
      return '123';
    case TestEnum.B:
      return 'abc';
    default:
      return null;
  }