目录

unnecessary_overrides

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

此规则自 Dart 2.0 版本起可用。

_规则集:core , recommended , flutter _

此规则提供 快速修复

详情

#

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.

使用方法

#

要启用 unnecessary_overrides 规则,请在你的 analysis_options.yaml 文件中,在 linter > rules 下添加 unnecessary_overrides

analysis_options.yaml
yaml
linter:
  rules:
    - unnecessary_overrides