sort-constructors-first
Same as sort_constructors_first in Dart lints
- Group
- Style
- Path
lint/style/sort-constructors-first- Default
- Off, opt in
- Origin
- Dart lints
- Rule
- 437 of 512
Flags a constructor declared after a non-constructor member.
Constructors describe how an instance comes to be, so they lead the member list of a class, mixin class, enum, or extension type:
class A {
A();
int x = 0;
A.named(); // flagged
}
Each out-of-place constructor is reported at its name. Enum values are not
members, so they never count as preceding declarations.
Primary constructor headers do not participate in body ordering; their
explicit this bodies do, and are reported at the this keyword.
Invalid
class A {
A();
int x = 0;
A.named();
factory A.make() => A();
}
class B {
void m() {}
B();
}
enum E {
one, two;
int get value => index;
const E();
}
abstract class M {
static const k = 1;
M();
}
extension type Id(int value) {
int get doubled => value * 2;
Id.zero() : value = 0;
} int x = 0; A.named(); A.named(); factory A.make() => A(); void m() {} B(); int get value => index; const E(); static const k = 1; M(); int get doubled => value * 2; Id.zero() : value = 0;Valid
class A {
A();
A.named();
factory A.make() => A();
int x = 0;
void m() {}
}
class OnlyMembers {
int x = 0;
void m() {}
}
enum E {
one, two;
const E();
int get value => index;
}
mixin M {
int field = 0;
}
extension type Id(int value) {
Id.zero() : value = 0;
int get doubled => value * 2;
}Configure sort-constructors-first
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"sort-constructors-first": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/sort-constructors-first: <reason>More style rules
- sort-unnamed-constructors-first
sort_unnamed_constructors_firstFlags an unnamed constructor declared after a named constructor.
- tighten-type-of-initializing-formals
tighten_type_of_initializing_formalsFlags a nullable
this.xorsuper.xinitializing formal whose constructor assertsx != null. - type-annotate-public-apis
type_annotate_public_apisrecommendedRequires type annotations on public declarations.
- type-init-formals
type_init_formalsrecommendedFlags a *redundant* type annotation on an initializing formal or super parameter (
type-init-formals, adopted from package:lints). - unawaited-futures
unawaited_futuresrecommendedFutureresults inasyncbodies must be awaited or markedunawaited. - unintended-html-in-doc-comment
unintended_html_in_doc_commentrecommendedFlags angle-bracket text in doc comments that Markdown would render as an HTML tag.
- unnecessary-await-in-return
unnecessary_await_in_returnAvoid
awaiton a returnedFuturethe function's ownFuturealready covers. - unnecessary-brace-in-string-interps
unnecessary_brace_in_string_interpsrecommendedFlags
${x}string interpolations whose braces can be dropped.