empty-constructor-bodies
Same as empty_constructor_bodies in Dart lints
- Group
- Style
- Path
lint/style/empty-constructor-bodies- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 230 of 512
Flags constructors with an empty block body {}.
An empty {} is indistinguishable from a body someone forgot to fill in,
whereas a bare ; states plainly that the constructor does no extra work.
Prefer Foo(); over Foo() {}. Only a block body containing no statements
is reported; a constructor whose body does something is left alone.
Invalid
class A {
A() {}
}
class B {
final int x;
B(this.x) {}
}
class C {
C.named() {}
}
class D {
int y = 0;
D() : y = 1 {}
}
class E {
E.first() {}
E.second() {}
}class A { A() {} final int x; B(this.x) {}class C { C.named() {} int y = 0; D() : y = 1 {}class E { E.first() {} E.first() {} E.second() {}Valid
class A {
A();
}
class B {
final int x;
B(this.x);
}
class C {
C.named();
}
class D {
int y = 0;
D() : y = 1;
}
class E {
E() {
print('init');
}
}
class F {
final int z;
F(this.z) {
print(z);
}
}Configure empty-constructor-bodies
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"empty-constructor-bodies": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/empty-constructor-bodies: <reason>More style rules
- enum-constants-ordering
Flags enum constants whose declared names violate the configured order.
- eol-at-end-of-file
eol_at_end_of_filerecommendedFlags a non-empty file that does not end with exactly one line break.
- extend-equatableequatable
Require Equatable semantics for configured class/file name patterns.
- file-names
file_namesrecommendedEnforces
lowercase_with_underscoresfor source file names. - flutter-style-todos
flutter_style_todosFlags
TODOcomments that do not follow the Flutter style// TODO(username): message, https://URL-to-issue. - format-comment
format-commentFlags comments that are not formatted as complete sentences.
- implicit-call-tearoffs
implicit_call_tearoffsExplicitly tear off callable objects' call methods.
- initializers-ordering
Requires field initializers to follow their containing type's field declaration order by default.