public_representation_field
Reports a public representation field of a public extension type. Make the field private, and declare the members callers need.
- Tier
- advisory
- Scope
- Dart
- Lowest preset
- strict
- Fix
- none
What it reports
Section titled “What it reports”The representation field of a public extension type, when the field is public: value in extension type UserId(String value) {}. The violation covers the field’s name.
It does not report:
- a private representation field, or a private extension type;
- an extension type that implements its representation type, or a supertype of it other than
Object(implements String,implements num,implements Comparable<String>). Such a type shows the members of its value on purpose.
An extension type gives a value a type of its own, with only the members the type declares. A public representation field hands the wrapped value to every caller, so code reaches around those members. Once it does, the type can no longer change what it wraps.
Example
Section titled “Example”extension type UserId(String value) {}extension type UserId(String _value) { bool get isGuest => _value.isEmpty;}Rule parameters
Section titled “Rule parameters”Set under the assay: key of the project’s root analysis_options.yaml.
| Rule parameter | Default | Effect |
|---|---|---|
enabled |
true |
false switches the rule off for the whole project. |
exclude |
[] |
Path globs where the rule is silent. |
Suppressing it
Section titled “Suppressing it”Write why on the line directly above the suppression:
// Why it stays as written here.// ignore: public_representation_field// ignore_for_file: assay/public_representation_field silences it in a whole file, and the prefixed // ignore: assay/public_representation_field works too. See Suppressions.