overridden_fields
Don't override fields.
This rule is available as of Dart 2.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:
dart
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:
dart
class Base {
Object field = 'lorem';
Object something = 'change';
}
class Ok extends Base {
Object newField; // OK
final Object newFinal = 'ignore'; // OK
}
GOOD:
dart
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:
analysis_options.yaml
yaml
linter:
rules:
- overridden_fields
Unless stated otherwise, the documentation on this site reflects Dart 3.6.0. Page last updated on 2024-07-03. View source or report an issue.