annotate_overrides

Stable
Recommended
Fix available

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