recursive-getters
Same as recursive_getters in Dart lints
- Group
- Suspicious
- Path
lint/suspicious/recursive-getters- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 429 of 512
Flags a getter that unconditionally returns itself.
A body of => x (or => this.x, or return x;) inside get x calls the
getter again with no base case, recursing until the stack overflows at
runtime. It almost always means a backing field was intended — typically an
underscore-prefixed _x — but was misspelled as the getter's own name.
Return the backing field instead. Only a direct, unconditional self-reference
is reported; a getter that merely mentions its own name inside a larger
expression is left alone.
Invalid
class A {
int get x => x;
int get y => this.y;
String get label {
return label;
}
double get z {
return this.z;
}
num get w => this.w;
}
int get topLevel => topLevel;class A { int get x => x; int get y => this.y; String get label { return label; double get z { return this.z; num get w => this.w; int get topLevel => topLevel;Valid
class A {
int _x = 0;
int _count = 0;
int get x => _x;
int get y {
return _x + 1;
}
int get count => _count;
int get doubled => _x * 2;
String get label => 'label';
num get w => this._x;
}
int _g = 0;
int get topLevel => _g;Configure recursive-getters
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"suspicious": {
"recursive-getters": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/suspicious/recursive-getters: <reason>More suspicious rules
- unnecessary-null-aware-assignments
unnecessary_null_aware_assignmentsrecommendedFlags
x ??= null, which can never have an effect. - unnecessary-null-in-if-null-operators
unnecessary_null_in_if_null_operatorsrecommendedFlags
x ?? nullandnull ?? x, where thenulloperand is redundant. - use-rethrow-when-possible
use_rethrow_when_possiblerecommendedFlags
throw einside acatch (e)by matching the exception parameter's name. - avoid-accessing-other-classes-private-members
Enforces class-level encapsulation even inside one Dart library.
- avoid-assignments-as-conditions
Flags assignments evaluated inside control-flow conditions.
- avoid-banned-annotations
Ban configured dotted annotation names, without the leading
@. - avoid-banned-exports
Ban decoded export URIs, including all conditional alternatives.
- avoid-banned-names
Ban declaration names, exempting references, initializing/super formals, and
@override-annotated members and their parameters.