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
除非另有说明,文档之所提及适用于 Dart 3.5.4 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。