avoid-unnecessary-getter
- Group
- Style
- Path
lint/style/avoid-unnecessary-getter- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 163 of 512
Flags a getter that only exposes a private final field.
Replace the backing field and getter with a public final field. Getter/setter
pairs are covered separately by unnecessary-getters-setters. By default,
getters that upcast the field are retained; set ignore-upcast to false to
diagnose those too.
Invalid
class Arrow {
final int _value = 1;
int get value => _value;
}
class Body {
final int _other = 1;
int get other { return this._other; }
}
class Annotated {
final int _hashCode = 1;
@override
int get hashCode => _hashCode;
} final int _value = 1; int get value => _value; final int _other = 1; int get other { return this._other; } @override int get hashCode => _hashCode;Valid
class Example {
final int value = 1;
int _mutable = 1;
int get mutable => _mutable;
int get computed => value + 1;
}
class Pair {
int _value = 1;
int get value => _value;
set value(int value) { _value = value; }
}
class Annotated {
final int _value = 1;
@override
int get hashCode => _value + 1;
}
class Upcast {
final int _value = 1;
num get value => _value;
}
class Private {
final int _value = 1;
int get _alias => _value;
}
class Late {
late final int _value;
int get value => _value;
}Configure avoid-unnecessary-getter
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"avoid-unnecessary-getter": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/avoid-unnecessary-getter: <reason>More style rules
- avoid-unnecessary-if
Flags an if branch that only returns the same expression as the following return.
- avoid-unnecessary-length-check
Empty collections already skip
for-inandforEachbodies. - avoid-unnecessary-local-variable
Reports a single-use local used only to initialize the next local.
- avoid-unnecessary-negations
Simplifies negated bool literals and equality comparisons with a logical negation on both sides.
- avoid-unnecessary-overrides-in-stateflutter
Redundant Flutter State overrides that drop inherited
@protected. - avoid-unnecessary-reassignment
Reports an eager local initializer immediately overwritten without a read.
- avoid-unnecessary-return
Flags bare returns at the end of a function or its final if/block branches.
- avoid-unnecessary-super
Omit implicit
super()initializers and provably redundant member prefixes.