
* DART-213 Modify rule S1161: update message details * S7055: Update description * Update rule.adoc
61 lines
1.7 KiB
Plaintext
61 lines
1.7 KiB
Plaintext
== Why is this an issue?
|
|
|
|
While not mandatory, using the https://api.dart.dev/dart-core/override-constant.html[`@override`] annotation on compliant members (methods, properties, operators) improves readability by making it explicit that members are overridden.
|
|
|
|
Unlike other languages, all methods in Dart are https://en.wikipedia.org/wiki/Virtual_function[`virtual`] by default. So, using the `@override` annotation prevents accidental overriding of a base class method in a subclass.
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,dart,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
class ParentClass {
|
|
bool doSomething(){/*...*/}
|
|
}
|
|
class FirstChildClass extends ParentClass {
|
|
bool doSomething(){/*...*/} // Noncompliant
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,dart,diff-id=1,diff-type=compliant]
|
|
----
|
|
class ParentClass {
|
|
bool doSomething(){/*...*/}
|
|
}
|
|
class FirstChildClass extends ParentClass {
|
|
@override
|
|
bool doSomething(){/*...*/} // Compliant
|
|
}
|
|
----
|
|
|
|
== Resources
|
|
|
|
* Dart Docs - https://dart.dev/tools/linter-rules/annotate_overrides[Dart Linter rule - annotate_overrides]
|
|
* Dart Docs - https://dart.dev/language/extend#overriding-members[Extend a class - Overriding members]
|
|
* Dart API Reference - https://api.dart.dev/dart-core/override-constant.html[Override top-level constant]
|
|
* Wikipedia - https://en.wikipedia.org/wiki/Virtual_function[Virtual function]
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
The member '<method name>' overrides an inherited member but isn't annotated with '@override'.
|
|
|
|
=== Highlighting
|
|
|
|
The identifier of the method, property or operator.
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::../comments-and-links.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|