member-ordering
Same as member-ordering in Dart Code Metrics
- Group
- Style
- Path
lint/style/member-ordering- Default
- Off, opt in
- Origin
- Dart Code Metrics
- Rule
- 267 of 512
Flags class members declared out of the configured order.
A predictable member layout makes classes easier to navigate. Without
options the built-in order applies: static constants, static fields, instance
fields, constructors, static methods, then instance methods. Members are
ranked by category and any pair out of sequence is reported. For Flutter
State subclasses, a separate lifecycle ordering can be enforced with
widgets-order.
Options
order (list of category tokens, default: the built-in order above) — the
required member sequence. Supported tokens are public-fields,
private-fields, fields, static-fields, constructors,
named-constructors, static-methods, private-methods, public-methods,
methods, getters, and setters. A member is ranked by the earliest
token it qualifies for; members matching no token are ignored.
widgets-order (list of lifecycle tokens, default: none) — for a class that
extends State, orders lifecycle members by this list. Supported tokens:
constructor, init-state, did-change-dependencies, did-update-widget,
dispose, build, and overridden-methods.
Invalid
// Test cases for member-ordering rule
// Expected order: static const → static fields → instance fields → constructors → static methods → instance methods
// Instance field after instance method: field is flagged (cat 2 < max 5)
class BadOrderExample1 {
void instanceMethod() {
print("method before field");
}
final int instanceField = 42;
}
// Static const after instance field: constant is flagged (cat 0 < max 2)
class BadOrderExample2 {
final int field = 10;
static const String constant = "const";
}
// Instance field after static method: field is flagged (cat 2 < max 4)
class BadOrderExample3 {
static void staticMethod() {
print("static method before instance field");
}
final int instanceField = 5;
}
// Instance field after constructor: field is flagged (cat 2 < max 3)
class BadOrderExample4 {
int field1 = 1;
BadOrderExample4();
int field2 = 2;
}
// Static const and instance field after instance method: both flagged
class BadOrderExample5 {
void method1() {
print("method");
}
static const int constant = 42;
final int field = 100;
}
// Constructor after instance method: constructor is flagged (cat 3 < max 5)
class BadOrderExample6 {
void doSomething() {
print("do");
}
BadOrderExample6() {
print("constructor");
}
final String name = "test";
}
// Static const after instance method: constant is flagged (cat 0 < max 5)
class BadOrderExample7 {
static int staticField = 10;
static void staticMethod() {
print("static method");
}
void instanceMethod() {
print("instance method");
}
static const int constant = 5;
} final int instanceField = 42; static const String constant = "const"; final int instanceField = 5; int field2 = 2; static const int constant = 42; final int field = 100; BadOrderExample6() { final String name = "test"; static const int constant = 5;Valid
// Good examples for member-ordering rule
// Correct order: static const → static fields → instance fields → constructors → static methods → instance methods
class WellOrderedExample1 {
static const String constant = "const";
static int staticField = 10;
final int instanceField = 42;
WellOrderedExample1() {
print("constructor");
}
static void staticMethod() {
print("static method");
}
void instanceMethod() {
print("instance method");
}
}
class WellOrderedExample2 {
static const int maxSize = 100;
int count = 0;
String name = "test";
WellOrderedExample2() {
count = 0;
}
static int defaultValue() {
return 42;
}
void increment() {
count++;
}
void reset() {
count = 0;
}
}
class WellOrderedExample3 {
static const List<String> defaults = [];
static bool enabled = true;
final String id;
late String value;
WellOrderedExample3(this.id) {
value = id.toUpperCase();
}
WellOrderedExample3.named(String name) {
id = name;
value = name;
}
static void logDefaults() {
print("defaults");
}
void process() {
print(value);
}
@override
String toString() => id;
}
class SimpleClass {
static const String defaultName = "default";
String name;
SimpleClass([this.name = defaultName]);
static String getDefault() => defaultName;
void changeName(String newName) {
name = newName;
}
}Configure member-ordering
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"member-ordering": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/member-ordering: <reason>More style rules
- missing-whitespace-between-adjacent-strings
missing_whitespace_between_adjacent_stringsrecommendedFlags adjacent string literals that join two words without a space between them.
- newline-before-break
Requires a blank line before a break that follows another statement.
- newline-before-case
Requires a blank line between successive switch statement case clauses.
- newline-before-constructor
Requires a blank line before constructors following another member.
- newline-before-continue
Requires a blank line before a continue that follows another statement.
- newline-before-method
Requires a blank line before method declarations following another member.
- newline-before-return
newline-before-returnFlags
returnstatements that are not preceded by a blank line. - newline-before-throw
Requires a blank line before a throw that follows another statement.