目录

unnecessary_overrides

目录

Don't override a method to do a super method invocation with the same parameters.

This rule is available as of Dart 2.0.

Rule sets: core, recommended, flutter

This rule has a quick fix available.

Details

#

DON'T override a method to do a super method invocation with same parameters.

BAD:

dart
class A extends B {
  @override
  void foo() {
    super.foo();
  }
}

GOOD:

dart
class A extends B {
  @override
  void foo() {
    doSomethingElse();
  }
}

It's valid to override a member in the following cases:

  • if a type (return type or a parameter type) is not the exactly the same as the super member,
  • if the covariant keyword is added to one of the parameters,
  • if documentation comments are present on the member,
  • if the member has annotations other than @override,
  • if the member is not annotated with @protected, and the super member is.

noSuchMethod is a special method and is not checked by this rule.

Usage

#

To enable the unnecessary_overrides rule, add unnecessary_overrides under linter > rules in your analysis_options.yaml file:

analysis_options.yaml
yaml
linter:
  rules:
    - unnecessary_overrides