Skip to main content

avoid-renaming-representation-getters

added in: 1.15.0
🛠
Dart 3.3+

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

bool get isNotEmpty => this._value.isEmpty; // LINT
}

extension type ET2(String public) {
bool get isEmpty => public.isNotEmpty; // LINT

bool get isNotEmpty => public.isNotEmpty;
}

✅ Good:

extension type ET(String _value) implements String {

bool get isEmpty => _value.isEmpty;


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