Rules / Complexity / unnecessary-overrides
unnecessary-overrides
Flags an @override member that does nothing but forward to super with
the same arguments.
Such an override adds visual noise and a maintenance burden without changing
behavior — delete it and the inherited implementation stays in force. The
rule is deliberately conservative: it only considers members annotated
@override (the annotation stands in for real override resolution), and it
leaves an override alone when it carries an extra annotation or declares
parameter defaults or covariant, since those signal an intentional
contract change. Forwarding methods (super.m(args)), getters (super.x),
and setters (super.x = v) are all checked; operator overrides are not.
Invalid
example.dartdart
class Base {
void foo() {}
void bar(int x) {}
int get val => 0;
set name(String s) {}
int baz(int a, int b) => 0;
void qux() {}
}
class Derived extends Base {
@override
void foo() => super.foo();
@override
void bar(int x) {
super.bar(x);
}
@override
int get val => super.val;
@override
set name(String s) => super.name = s;
@override
int baz(int a, int b) {
return super.baz(a, b);
}
@override
void qux() {
super.qux();
}
}
Unnecessary override — this member only forwards to `super` unchanged
11 @override
12 void foo() => super.foo();
∙
Unnecessary override — this member only forwards to `super` unchanged
14 @override
15 void bar(int x) {
∙
Unnecessary override — this member only forwards to `super` unchanged
19 @override
20 int get val => super.val;
∙
Unnecessary override — this member only forwards to `super` unchanged
22 @override
23 set name(String s) => super.name = s;
∙
Unnecessary override — this member only forwards to `super` unchanged
25 @override
26 int baz(int a, int b) {
∙
Unnecessary override — this member only forwards to `super` unchanged
30 @override
31 void qux() {
∙
Valid
example.dartdart
class Base {
void foo() {}
void bar(int x) {}
int get val => 0;
void baz([int x = 0]) {}
}
const protected = 'protected';
class Derived extends Base {
@override
void foo() {
print('extra');
super.foo();
}
@override
int get val => super.val + 1;
@override
void bar(int x) => super.bar(x + 1);
@override
@protected
void extraAnnotated() => superCall();
@override
void baz([int x = 0]) => super.baz(x);
void notOverride() => helper();
}
How to configure
Set the severity of unnecessary-overrides in your falcon.json:
falcon.jsonjson
{
"linter": {
"rules": {
"complexity": {
"unnecessary-overrides": "error"
}
}
}
}