Rules / Style / empty-constructor-bodies
empty-constructor-bodies
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
example.dartdart
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() {}
}
Empty constructor body — use `;` instead of `{}`
Empty constructor body — use `;` instead of `{}`
6 final int x;
7 B(this.x) {}
∙
Empty constructor body — use `;` instead of `{}`
10class C {
11 C.named() {}
∙
Empty constructor body — use `;` instead of `{}`
15 int y = 0;
16 D() : y = 1 {}
∙
Empty constructor body — use `;` instead of `{}`
19class E {
20 E.first() {}
∙
Empty constructor body — use `;` instead of `{}`
20 E.first() {}
21 E.second() {}
∙
Valid
example.dartdart
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);
}
}
How to configure
Set the severity of empty-constructor-bodies in your falcon.json:
falcon.jsonjson
{
"linter": {
"rules": {
"style": {
"empty-constructor-bodies": "error"
}
}
}
}