Skip to main content

member_ordering

A lint which allows to enforce a particular class member ordering conventions.

Configuration format

The configuration uses a custom syntax for specifying members for ordering:

annotation_modifiers_membertype

Valid annotations: overridden, protected

Valid modifiers, in order of how they may appear in the final expression:

  • private / public
  • static
  • late
  • var / final / const
  • nullable
  • named
  • factory
  • fields / getters / getters_setters / setters / constructors / methods / method.

Here are some examples of valid ordering group patterns:

  • public_static_const_fields
  • private_late_fields
  • private_nullable_fields
  • public_methods
  • overridden_methods

It's also possible to specify ordering for custom-named class members:

  • my_custom_name_method
  • dispose_method

Example:

Assuming config:

custom_lint:
rules:
- member_ordering:
alphabetize: true
order:
- fields
- getters_setters
- methods

BAD:

class Example {
int get getA => a; // LINT, getters-setters should be after fields

final b = 1;
final a = 1; // LINT, non-alphabetic order
final c = 1;

void method() {}
}

GOOD:

class Example {
final a = 1;
final b = 1;
final c = 1;

int get getA => a;

void method() {}
}

Parameters

groups_order (List<MemberGroup>)

Config used for members of regular class

widgets_groups_order (List<MemberGroup>)

Config used for members of Widget subclasses

alphabetize (bool)

Boolean flag; indicates whether params should be in alphabetical order

alphabetize_by_type (bool)

Boolean flag; indicates whether params should be in alphabetical order by their static type