Skip to main content

avoid-renaming-representation-getters

dart 3.3+
has auto-fix
pro+

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 {
// LINT: Avoid renaming representation getters as it can introduce additional confusion.
// Try using the original name instead.
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;
}

extension type ET2(String public) {
// LINT: Avoid renaming representation getters as it can introduce additional confusion.
// Try using the original name instead.
bool get isEmpty => public.isNotEmpty;

bool get isNotEmpty => public.isNotEmpty;
}

✅ Good:

extension type ET(String _value) implements String {

bool get isEmpty => _value.isEmpty;


bool get isNotEmpty => this._value.isNotEmpty;
}