avoid-setters-without-getters
Same as avoid_setters_without_getters in Dart lints
- Group
- Style
- Path
lint/style/avoid-setters-without-getters- Default
- Off, opt in
- Origin
- Dart lints
- Rule
- 135 of 512
Flags a setter that has no corresponding getter.
A property that can be written but not read is surprising: a.x = 1;
compiles, but a.x does not. Each setter of a class, enum, or extension
type needs a getter of the same name, declared alongside it (a getter or a
field) or, except for extension types, inherited from a superclass:
class A {
set width(int value) {} // flagged
int get height => 0;
set height(int value) {} // fine
}
Setters that override an inherited setter are not reported. Only concrete inherited getters count as a corresponding getter.
Invalid
class A {
set width(int value) {}
static set registry(Object value) {}
}
enum Mode {
on, off;
set label(String value) {}
}
extension type Wrapper(int raw) {
set doubled(int value) {}
}
class Base {
int get height => 0;
}
class Sub extends Base {
set depth(int value) {}
}
class WithMethod {
void size() {}
set length(int value) {}
}
abstract class Readable {
int get width;
}
class WriteOnly implements Readable {
set width(int value) {}
}
class Remote extends SomeUnknownBase {
set port(int value) {}
}class A { set width(int value) {} static set registry(Object value) {} set label(String value) {}extension type Wrapper(int raw) { set doubled(int value) {}class Sub extends Base { set depth(int value) {} void size() {} set length(int value) {}class WriteOnly implements Readable { set width(int value) {}class Remote extends SomeUnknownBase { set port(int value) {}Valid
class A {
int get height => 0;
set height(int value) {}
int width = 0;
static int get count => 0;
static set count(int value) {}
}
class Base {
int get depth => 0;
set name(String value) {}
String get name => '';
}
class Sub extends Base {
// Inherits the getter.
set depth(int value) {}
// Overrides an inherited setter.
@override
set name(String value) {}
}
class Mixed with M {
set fromMixin(int value) {}
}
mixin M {
int get fromMixin => 0;
}
// Mixins and extensions are not checked.
mixin OnlySetter {
set value(int v) {}
}
extension Ext on int {
set setterOnly(int v) {}
}Configure avoid-setters-without-getters
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"avoid-setters-without-getters": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/avoid-setters-without-getters: <reason>More style rules
- 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.
- avoid-unnecessary-continue
Flags an unlabeled continue at the end of a loop body or its final branch.
- avoid-unnecessary-getter
Flags a getter that only exposes a private final field.