diagnostic_describe_all_properties
DO reference all public properties in debug methods.
此规则自 Dart 2.3 版本起可用。
此规则提供 快速修复 。
详情
#DO reference all public properties in debug
method implementations.
Implementers of Diagnosticable
should reference all public properties in a debugFillProperties(...)
or debugDescribeChildren(...)
method implementation to improve debuggability at runtime.
Public properties are defined as fields and getters that are
- not package-private (e.g., prefixed with
_
) - not
static
or overriding - not themselves
Widget
s or collections ofWidget
s
In addition, the "debug" prefix is treated specially for properties in Flutter. For the purposes of diagnostics, a property foo
and a prefixed property debugFoo
are treated as effectively describing the same property and it is sufficient to refer to one or the other.
BAD:
class Absorber extends Widget {
bool get absorbing => _absorbing;
bool _absorbing;
bool get ignoringSemantics => _ignoringSemantics;
bool _ignoringSemantics;
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<bool>('absorbing', absorbing));
// Missing reference to ignoringSemantics
}
}
GOOD:
class Absorber extends Widget {
bool get absorbing => _absorbing;
bool _absorbing;
bool get ignoringSemantics => _ignoringSemantics;
bool _ignoringSemantics;
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<bool>('absorbing', absorbing));
properties.add(DiagnosticsProperty<bool>('ignoringSemantics', ignoringSemantics));
}
}
使用方法
#要启用 diagnostic_describe_all_properties
规则,请在你的 analysis_options.yaml
文件中,在 linter > rules 下添加 diagnostic_describe_all_properties
:
linter:
rules:
- diagnostic_describe_all_properties
除非另有说明,否则本网站上的文档反映的是 Dart 3.6.0。页面最后更新于 2025-02-05。 查看源代码 或 报告问题.