avoid-renaming-representation-getters
preset: recommended
Warns when an extension type exposes a member that renames an existing representation field member.
info
This rule is different from annotate_redeclares.
It only works for getters (for extension types with and without implements
) and does not rely on the @redeclare
annotation.
Example
❌ Bad:
extension type ET(String _value) implements String {
bool get isEmpty => _value.isNotEmpty; // LINT: Avoid renaming representation getters as it can introduce additional confusion. Try using the original name instead.
bool get isNotEmpty => this._value.isEmpty; // LINT: Avoid renaming representation getters as it can introduce additional confusion. Try using the original name instead.
}
extension type ET2(String public) {
bool get isEmpty => public.isNotEmpty; // LINT: Avoid renaming representation getters as it can introduce additional confusion. Try using the original name instead.
bool get isNotEmpty => public.isNotEmpty;
}
✅ Good:
extension type ET(String _value) implements String {
bool get isEmpty => _value.isEmpty;
bool get isNotEmpty => this._value.isNotEmpty;
}