enum-constants-ordering

Group
Style
Path
lint/style/enum-constants-ordering
Default
Off, opt in
Origin
Falcon
Rule
232 of 512

Flags enum constants whose declared names violate the configured order.

Set order to "ascending" or "descending" to compare names lexicographically and case-sensitively. Without a valid explicit order, this rule is inactive. Constructor arguments and enum members do not affect the comparison.

Invalid

example.dartdart
enum Fruit { zebra, apple }
enum Color { red, blue }
enum Enhanced { zebra(1), apple(2); const Enhanced(this.value); final int value; }
enum Named { zebra.x(), apple.x(); const Named.x(); }
enum Middle { apple, zebra, berry }
Reorder named entries to follow the configured order.
1enum Fruit { zebra, apple }
Reorder named entries to follow the configured order.
1enum Fruit { zebra, apple }
2enum Color { red, blue }
Reorder named entries to follow the configured order.
2enum Color { red, blue }
3enum Enhanced { zebra(1), apple(2); const Enhanced(this.value); final int value; }
Reorder named entries to follow the configured order.
3enum Enhanced { zebra(1), apple(2); const Enhanced(this.value); final int value; }
4enum Named { zebra.x(), apple.x(); const Named.x(); }
Reorder named entries to follow the configured order.
4enum Named { zebra.x(), apple.x(); const Named.x(); }
5enum Middle { apple, zebra, berry }

Valid

example.dartdart
enum Fruit { apple, zebra }
enum Color { blue, red }
enum Enhanced { apple(1), zebra(2); const Enhanced(this.value); final int value; }
enum Single { apple }
enum Named { apple.x(), zebra.x(); const Named.x(); }

Configure enum-constants-ordering

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "enum-constants-ordering": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/style/enum-constants-ordering: <reason>
  • eol-at-end-of-fileeol_at_end_of_filerecommended

    Flags a non-empty file that does not end with exactly one line break.

  • extend-equatableequatable

    Require Equatable semantics for configured class/file name patterns.

  • file-namesfile_namesrecommended

    Enforces lowercase_with_underscores for source file names.

  • flutter-style-todosflutter_style_todos

    Flags TODO comments that do not follow the Flutter style // TODO(username): message, https://URL-to-issue.

  • format-commentformat-comment

    Flags comments that are not formatted as complete sentences.

  • implicit-call-tearoffsimplicit_call_tearoffs

    Explicitly tear off callable objects' call methods.

  • initializers-ordering

    Requires field initializers to follow their containing type's field declaration order by default.

  • leading-newlines-in-multiline-stringsleading_newlines_in_multiline_strings

    Flags a multiline string spanning several lines whose text does not start with a line break right after the opening quotes.