Skip to main content

avoid-multi-assignment

added in: 1.17.0

Warns when multiple assignments are placed on the same line.

Example

❌ Bad:

class SomeClass {
String someString = 'some';
String another = 'another';

void update(String str) {
someString = another = str; // LINT

final instance = SomeClass();
instance.another = someString = str; // LINT
}
}

✅ Good:

class SomeClass {
String someString = 'some';
String another = 'another';

void update(String str) {
someString = str;
another = str;
}
}