Skip to content

getter_renames_representation

Reports an extension type getter that only gives back the public representation field under another name. Keep one name: delete the getter, or give the field the getter’s name.

Tier
advisory
Scope
Dart
Lowest preset
strict
Fix
none

A getter of an extension type whose body only gives back the public representation field (=> value or { return value; }) under another name, with no declared type or the field’s type. The violation is on the getter’s name.

It does not report:

  • a private representation field with a public getter: extension type Id._(String _text) { String get text => _text; };
  • a getter of another type, or one that computes;
  • a getter with an annotation, such as an alias kept @Deprecated;
  • a static getter;
  • a getter whose name is declared by a type the extension type implements.

The same value then has two public names on one type, and every reader and caller has to find out that they are the same.

Violating
extension type Meters(int value) {
int get meters => value;
}
Corrected
extension type Meters(int meters) {}

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.

Write why on the line directly above the suppression:

// Why it stays as written here.
// ignore: getter_renames_representation

// ignore_for_file: assay/getter_renames_representation silences it in a whole file, and // ignore: assay/getter_renames_representation with the prefix works too. See Suppressions.