sort-unnamed-constructors-first
Same as sort_unnamed_constructors_first in Dart lints
- Group
- Style
- Path
lint/style/sort-unnamed-constructors-first- Default
- Off, opt in
- Origin
- Dart lints
- Rule
- 439 of 512
Flags an unnamed constructor declared after a named constructor.
The unnamed constructor (C() or C.new()) is the primary way to create an
instance, so it comes before every named constructor of a class, mixin
class, enum, or extension type:
class A {
A.named();
A(); // flagged
}
Only constructors are ordered; fields and methods in between do not matter.
Invalid
class A {
A.named();
A();
}
class B {
B.a();
int x = 0;
B.new();
}
class C {
factory C.make() => C._();
C._();
C();
}
enum E {
one;
const E.named();
const E();
}
extension type Id._(int value) {
Id.zero() : value = 0;
Id(this.value);
} A.named(); A(); int x = 0; B.new(); C._(); C(); const E.named(); const E(); Id.zero() : value = 0; Id(this.value);Valid
class A {
A();
A.named();
}
class B {
int x = 0;
B.new();
B.a();
}
class C {
C.named();
}
class D {
void m() {}
D();
}
enum E {
one;
const E();
const E.named();
}Configure sort-unnamed-constructors-first
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"sort-unnamed-constructors-first": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/sort-unnamed-constructors-first: <reason>More style rules
- 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. - unnecessary-breaks
unnecessary_breaksrecommendedFlags a trailing
breakin a switch case that already ends implicitly.