annotate_overrides
Annotate overridden members.
Details
#DO annotate overridden methods and fields.
This practice improves code readability and helps protect against unintentionally overriding superclass members.
BAD:
dart
class Cat {
int get lives => 9;
}
class Lucky extends Cat {
final int lives = 14;
}
GOOD:
dart
abstract class Dog {
String get breed;
void bark() {}
}
class Husky extends Dog {
@override
final String breed = 'Husky';
@override
void bark() {}
}
Enable
#To enable the annotate_overrides
rule, add annotate_overrides
under linter > rules in your analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- annotate_overrides
If you're instead using the YAML map syntax to configure linter rules, add annotate_overrides: true
under linter > rules:
analysis_options.yaml
yaml
linter:
rules:
annotate_overrides: true
Unless stated otherwise, the documentation on this site reflects Dart 3.6.0. Page last updated on 2025-01-27. View source or report an issue.