From a9dbd9f246dba8b3ee22c71372194ef594833d0e Mon Sep 17 00:00:00 2001 From: Antonio Aversa Date: Mon, 22 Jul 2024 15:13:13 +0200 Subject: [PATCH] Modify rule S1161: "@override" should be used on overriding members (annotate_overrides) --- rules/S1161/comments-and-links.adoc | 2 ++ rules/S1161/dart/rule.adoc | 32 +++++++++++++++++++++++++++-- rules/S1161/java/rule.adoc | 3 +-- 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 rules/S1161/comments-and-links.adoc diff --git a/rules/S1161/comments-and-links.adoc b/rules/S1161/comments-and-links.adoc new file mode 100644 index 0000000000..fed60bcb6a --- /dev/null +++ b/rules/S1161/comments-and-links.adoc @@ -0,0 +1,2 @@ +=== on 29 Jul 2013, 15:51:56 Freddy Mallet wrote: +Is implemented by \http://jira.codehaus.org/browse/SONARJAVA-249 diff --git a/rules/S1161/dart/rule.adoc b/rules/S1161/dart/rule.adoc index f6cb991f24..4d8ff3cfc1 100644 --- a/rules/S1161/dart/rule.adoc +++ b/rules/S1161/dart/rule.adoc @@ -1,7 +1,8 @@ == Why is this an issue? -While not mandatory, using the `@Override` annotation on compliant members improves readability by making it explicit that members are overridden. +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 @@ -31,4 +32,31 @@ class FirstChildClass extends ParentClass { == Resources -* https://dart.dev/tools/linter-rules/annotate_overrides[Dart Lint rule] \ No newline at end of file +* 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 '' overrides an inherited member but isn't annotated with '@override'. + +If the member is a setter, the method name will end with a `=` sign, to distinguish it from the corresponding getter. + +=== 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[] diff --git a/rules/S1161/java/rule.adoc b/rules/S1161/java/rule.adoc index 71fd0ff8d7..3700732b1a 100644 --- a/rules/S1161/java/rule.adoc +++ b/rules/S1161/java/rule.adoc @@ -52,7 +52,6 @@ Add the "@Override" annotation above this method signature == Comments And Links (visible only on this page) -=== on 29 Jul 2013, 15:51:56 Freddy Mallet wrote: -Is implemented by \http://jira.codehaus.org/browse/SONARJAVA-249 +include::../comments-and-links.adoc[] endif::env-github,rspecator-view[]