initializers-ordering
- Group
- Style
- Path
lint/style/initializers-ordering- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 246 of 512
Requires field initializers to follow their containing type's field declaration
order by default. Explicit order: ascending or descending selects
alphabetical ordering. Only literal values and constructor-parameter reads
can be reordered because initializer expressions evaluate in written order.
Other expressions, assertions, and super/this constructor calls keep their
positions and break ordering runs; unknown fields also break declaration-order
runs rather than guessing their order.
Invalid
class Example {
final int zebra;
final int alpha;
Example() : alpha = 1, zebra = 2;
Example.values(int a, int z)
: alpha = a, zebra = z;
}
class Words {
final String zebra, alpha;
Words() : alpha = 'a', zebra = 'z';
}
class WithBoundary {
final int zebra;
final int alpha;
WithBoundary()
: assert(true),
alpha = 1,
zebra = 2;
}
enum EnumFields {
value;
final int zebra;
final int alpha;
const EnumFields()
: alpha = 1, zebra = 2;
} final int alpha; Example() : alpha = 1, zebra = 2; Example.values(int a, int z) : alpha = a, zebra = z; final String zebra, alpha; Words() : alpha = 'a', zebra = 'z'; alpha = 1, zebra = 2; const EnumFields() : alpha = 1, zebra = 2;Valid
int next() => 1;
class Example {
final int zebra;
final int alpha;
Example() : zebra = 2, alpha = 1;
Example.values(int a, int z) : zebra = z, alpha = a;
Example.withAssert() : alpha = 1, assert(true), zebra = 2;
Example.withEffects() : zebra = next(), alpha = next();
Example.withUnknownValue() : zebra = next(), alpha = 1;
Example.reversedEffects() : alpha = next(), zebra = next();
Example.reversedUnknownValue() : alpha = next(), zebra = 1;
Example.redirect() : this();
}
class Parent {
Parent();
}
class Child extends Parent {
final int zebra;
final int alpha;
Child() : zebra = 2, alpha = 1, super();
Child.withAssert() : alpha = 1, assert(true), zebra = 2, super();
}
class Words {
final String zebra, alpha;
Words() : zebra = 'z', alpha = 'a';
Words.withInterpolation() : zebra = '${next()}', alpha = 'a';
Words.reversedInterpolation() : alpha = '${next()}', zebra = 'z';
}
// Each containing class has its own declaration order.
class Opposite {
final int alpha;
final int zebra;
Opposite() : alpha = 1, zebra = 2;
}
enum EnumFields {
value;
final int zebra;
final int alpha;
const EnumFields() : zebra = 2, alpha = 1;
}Configure initializers-ordering
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"initializers-ordering": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/initializers-ordering: <reason>More style rules
- leading-newlines-in-multiline-strings
leading_newlines_in_multiline_stringsFlags a multiline string spanning several lines whose text does not start with a line break right after the opening quotes.
- library-annotations
library_annotationsrecommendedRequires library-targeted metadata to attach to a
librarydirective. - library-names
library_namesrecommendedFlags a library name that is not
lowercase_with_underscores. - library-prefixes
library_prefixesrecommendedFlags import prefixes that are not
lower_case_with_underscores. - lines-longer-than-80-chars
lines_longer_than_80_charsFlags source lines longer than 80 characters.
- map-keys-ordering
Flags literal string map keys that violate the configured order.
- matching-super-parameters
matching_super_parametersFlags positional super parameters named differently from the super constructor's corresponding parameter.
- member-ordering
member-orderingFlags class members declared out of the configured order.