58 lines
1.1 KiB
Plaintext
58 lines
1.1 KiB
Plaintext
== Why is this an issue?
|
|
|
|
In Dart, we use constructors to provide an initialization logic for a new object creation. Sometimes we don't need any additional logic, so the constructor is left empty. In such cases, the constructor body can be simply removed and the declaration must be terminated with a semicolon.
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,dart,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
class Person {
|
|
|
|
String name;
|
|
int age;
|
|
|
|
Person(this.name, this.age) {}
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,dart,diff-id=1,diff-type=compliant]
|
|
----
|
|
class Person {
|
|
|
|
String name;
|
|
int age;
|
|
|
|
Person(this.name, this.age);
|
|
}
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
=== Documentation
|
|
|
|
* Dart Docs - https://dart.dev/tools/linter-rules/empty_constructor_bodies[Dart Linter rule - empty_constructor_bodies]
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
* Empty constructor bodies should be written using a ';' rather than '{}'.
|
|
|
|
=== Highlighting
|
|
|
|
The empty constructor body.
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
endif::env-github,rspecator-view[]
|