avoid-return-types-on-setters
Same as avoid_return_types_on_setters in Dart lints
- Group
- Style
- Path
lint/style/avoid-return-types-on-setters- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 130 of 512
Flags setters declared with an explicit return type.
A setter never returns a value, so annotating one with a return type — even
void — is redundant and can mislead readers into thinking the result is
usable. Drop the return type and write set foo(int v). Both top-level
setters and setters declared in classes, mixins, enums, and extensions are
checked.
Invalid
// Setters never return a value, so any return type is redundant.
class A {
int _v = 0;
void set value(int v) { _v = v; }
int _w = 0;
int set width(int v) { _w = v; }
}
class B {
String _n = '';
String set name(String v) { _n = v; }
static void set flag(bool v) {}
external void set ext(int v);
}
mixin M {
void set data(int v) {}
} int _v = 0; void set value(int v) { _v = v; } int _w = 0; int set width(int v) { _w = v; } String _n = ''; String set name(String v) { _n = v; } String set name(String v) { _n = v; } static void set flag(bool v) {} static void set flag(bool v) {} external void set ext(int v);mixin M { void set data(int v) {}Valid
// Setters declared without a return type — the correct form.
class A {
int _v = 0;
set value(int v) { _v = v; }
int _w = 0;
set width(int v) => _w = v;
static set flag(bool v) {}
external set ext(int v);
// Comments between modifiers are not return types.
static /* cached */ set cached(int v) {}
set /* note */ noted(int v) {}
static // trailing note
set commented(int v) {}
}
mixin M {
set data(int v) {}
}
class B {
int getValue() => 1;
void doThing() {}
}Configure avoid-return-types-on-setters
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"avoid-return-types-on-setters": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/avoid-return-types-on-setters: <reason>More style rules
- avoid-returning-this
avoid_returning_thisFlags methods that return
thisonly to enable a fluent interface. - avoid-setters-without-getters
avoid_setters_without_gettersFlags a setter that has no corresponding getter.
- avoid-single-cascade-in-expression-statements
avoid_single_cascade_in_expression_statementsrecommendedFlags an expression statement that is a cascade with a single section.
- avoid-single-child-column-or-row
avoid_single_child_column_or_rowflutterFlags a
Column,Row, orFlexwidget built with a single child. - avoid-top-level-member-access
Flags mutable global state: non-
const, non-finaltop-level variables and static fields, plus every read of mutable top-level variables. - avoid-types-on-closure-parameters
avoid_types_on_closure_parametersFlags type annotations on closure parameters whose types come from context.
- avoid-unnecessary-block
Flags standalone nested blocks that introduce no lexical declarations.
- avoid-unnecessary-call
Prefer direct invocation of functions and resolved callable instances.