diagnostic_ describe_ all_ properties
DO reference all public properties in debug methods.
Details
#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
staticor overriding - not themselves
Widgets or collections ofWidgets
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));
}
}
Enable
#
To enable the diagnostic_describe_all_properties rule, add diagnostic_describe_all_properties
under
linter > rules in your analysis_options.yaml
file:
linter:
rules:
- diagnostic_describe_all_properties
If you're instead using the YAML map syntax to configure linter rules,
add diagnostic_describe_all_properties: true under linter > rules:
linter:
rules:
diagnostic_describe_all_properties: true
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Report an issue.