Skip to main content

avoid-duplicate-initializers

added in: 1.13.0
preset: recommended

Warns when a final variable has the same initializer as another variable in scope.

Example

❌ Bad:

void fn(SomeClass param) {
final myValue = param.value.isNotEmpty;
final anotherValue = param.value.isNotEmpty; // LINT
}

✅ Good:

void fn(SomeClass param) {
final myValue = param.value.isNotEmpty;
final anotherValue = param.anotherValue;
}