use-existing-destructuring
- Group
- Style
- Path
lint/style/use-existing-destructuring- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 488 of 512
Reuse or extend an existing record destructuring instead of rereading a field. Records have immutable built-in fields. Object getters and list/map indexing can execute user code or change value and are intentionally not candidates.
Invalid
int a((int, int) pair) {
final (first, second) = pair;
return pair.$1;
}
int b((int, int) pair) {
final (first, second) = pair;
return pair.$2;
}
String c(({String name}) person) {
final (:name) = person;
return person.name;
}
int d(({int count}) record) {
final (count: total) = record;
return record.count;
}
int e() {
final pair = (1, 2);
var (first, second) = pair;
print(pair.$1);
return first;
}
int extendPositional((int, int) pair) {
final (first, _) = pair;
return pair.$2;
}
int extendNamed(({int first, int second}) pair) {
final (:first) = pair;
return pair.second;
} final (first, second) = pair; return pair.$1; final (first, second) = pair; return pair.$2; final (:name) = person; return person.name; final (count: total) = record; return record.count; var (first, second) = pair; print(pair.$1); final (first, _) = pair; return pair.$2; final (:first) = pair; return pair.second;Valid
int mutation((int, int) pair) {
var (first, second) = pair;
first = 3;
return pair.$1;
}
int sourceMutation((int, int) pair) {
final (first, second) = pair;
pair = (3, 4);
return pair.$1;
}
int otherSource((int, int) pair, (int, int) other) {
final (first, second) = pair;
return other.$1;
}
int scoped((int, int) pair) {
{ final (first, second) = pair; }
return pair.$1;
}
int list(List<int> values) {
final [first, ...rest] = values;
return values[0];
}
class C { int get value => DateTime.now().second; }
int getter(C object) {
final C(:value) = object;
return object.value;
}
int captured((int, int) pair) {
var (first, second) = pair;
void change() { first++; }
return pair.$1;
}Configure use-existing-destructuring
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"use-existing-destructuring": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/use-existing-destructuring: <reason>More style rules
- use-existing-variable
Reuse a local for stable SDK arithmetic and String.length/int parity getters.
- use-full-hex-values-for-flutter-colors
use_full_hex_values_for_flutter_colorsrecommendedflutterRequire an eight-digit hexadecimal integer for the canonical Flutter Color default constructor.
- use-function-type-syntax-for-parameters
use_function_type_syntax_for_parametersrecommendedFlags an old-style function-typed parameter written with inline parameter syntax.
- use-if-null-to-convert-nulls-to-bools
use_if_null_to_convert_nulls_to_boolsrecommendedPrefers
??to comparing a nullableboolagainst a boolean literal. - use-late-for-private-fields-and-variables
use_late_for_private_fields_and_variablesFlags a private nullable field or top-level variable that is only ever assigned non-null values and read through
!, so it could belatewith a non-nullable type. - use-named-constants
use_named_constantsrecommendedPrefers a class's predefined static constant to constructing an equal constant.
- use-raw-strings
use_raw_stringsFlags string literals whose only escapes are
\\and\$, which a raw string would express without any backslash. - use-setters-to-change-properties
use_setters_to_change_propertiesFlags one-parameter
voidmethods that only assign that parameter to a field.