overridden_fields
Don’t override fields.
This rule is available as of Dart 2.0.0.
Rule sets: recommended, flutter
Details
DON’T override fields.
Overriding fields is almost always done unintentionally. Regardless, it is a bad practice to do so.
BAD:
class Base {
Object field = 'lorem';
Object something = 'change';
}
class Bad1 extends Base {
@override
final field = 'ipsum'; // LINT
}
class Bad2 extends Base {
@override
Object something = 'done'; // LINT
}
GOOD:
class Base {
Object field = 'lorem';
Object something = 'change';
}
class Ok extends Base {
Object newField; // OK
final Object newFinal = 'ignore'; // OK
}
GOOD:
abstract class BaseLoggingHandler {
Base transformer;
}
class LogPrintHandler implements BaseLoggingHandler {
@override
Derived transformer; // OK
}
Usage
To enable the overridden_fields
rule,
add overridden_fields
under linter > rules in your
analysis_options.yaml
file:
linter:
rules:
- overridden_fields