Skip to main content

use-existing-destructuring

dart 3.0+
pro+

Warns when there is an existing class or record destructuring that can be used instead of accessing the property directly.

Example

❌ Bad:

void fn(SomeClass variable) {
// LINT: One of the patterns above uses the same initializer.
// Try updating that destructuring and use it here instead.
final SomeClass(:value) = variable;

print(variable.another);
}

void fn() {
final (left, _) = _getRecord();

// LINT: One of the patterns above uses the same initializer.
// Try updating that destructuring and use it here instead.
print(_getRecord().$2);
}

✅ Good:

void fn(SomeClass variable) {
final SomeClass(:value, :another) = variable;

print(another);
}

void fn() {
final (left, right) = _getRecord();

print(right);
}