match-getter-setter-field-names
- Group
- Correctness
- Path
lint/correctness/match-getter-setter-field-names- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 259 of 512
Detect likely copy-paste errors in trivial accessors when a different field matching the accessor name is declared. Inherited contracts and computed accessors are conservatively excluded.
Invalid
class State {
int _count = 0;
String _name = '';
int _total = 0;
int _size = 0;
int _amount = 0;
int _quantity = 0;
String _title = '';
String _label = '';
int get total => _count;
int get size { return this._count; }
set amount(int value) => _count = value;
set quantity(int value) { this._count = value; }
String get title => _name;
set label(String value) { _name = value; }
} String _label = ''; int get total => _count; int get total => _count; int get size { return this._count; } int get size { return this._count; } set amount(int value) => _count = value; set amount(int value) => _count = value; set quantity(int value) { this._count = value; } set quantity(int value) { this._count = value; } String get title => _name; String get title => _name; set label(String value) { _name = value; }Valid
class State {
int _count = 0;
int get count => _count;
set count(int value) => _count = value;
int get doubled => _count * 2;
set positive(int value) { if (value > 0) _count = value; }
int get constant => 42;
int get externalValue => unknown;
set checked(int value) { print(value); _count = value; }
set parameter(int _count) => _count = _count;
}
class Other {
int _size = 0;
int get size { return this._size; }
}
int unknown = 0;
class Aliases {
bool _enabled = false;
bool get isEnabled => _enabled;
int _count = 0;
int get size => _count;
int get length => _count;
int __value = 0;
int get value => __value;
}
abstract class Contract {
int get value;
}
class Inherited implements Contract {
int _count = 0;
int _value = 1;
int get value => _count;
}Configure match-getter-setter-field-names
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"match-getter-setter-field-names": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/match-getter-setter-field-names: <reason>More correctness rules
- missing-test-assertionrecommendedtest
Reports inline test callbacks that contain no recognized assertion calls.
- no-adjacent-strings-in-list
no_adjacent_strings_in_listrecommendedFlags adjacent string literals used as an element of a list or set literal.
- no-import-cyclescross-file
Report mutually dependent components of imported or exported library files.
- no-logic-in-create-state
no_logic_in_create_staterecommendedflutterRequire
StatefulWidget.createStateto return only a fresh zero-argument FlutterStateconstruction. - no-self-assignments
no_self_assignmentsrecommendedFlags assignments of a variable to itself, such as
x = x;. - null-check-on-nullable-type-parameter
null_check_on_nullable_type_parameterrecommendedFlags a null assertion
x!on a nullable type parameterT?whose expected type isTorT?for a potentially nullableT, and null-assert patterns whose matched value is a nullable type parameter. - null-closures
null_closuresrecommendedReject literal
nullin the closure slots of curated SDK APIs. - prefer-correct-json-casts
Decode JSON containers using their actual runtime generic types.