unnecessary_ overrides
Learn about the unnecessary_overrides linter rule.
Don't override a method to do a super method invocation with the same parameters.
Details
#DON'T override a method to do a super method invocation with same parameters.
BAD:
class A extends B {
@override
void foo() {
super.foo();
}
}
GOOD:
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
covariantkeyword 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.
Enable
#
To enable the unnecessary_overrides rule, add
unnecessary_overrides under
linter > rules in your
analysis_options.yaml
file:
linter:
rules:
- unnecessary_overrides
If you're instead using the YAML map syntax to configure
linter rules, add
unnecessary_overrides: true under
linter > rules:
linter:
rules:
unnecessary_overrides: true
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.