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