Skip to main content

avoid-nested-assignments

Warns when an assignment is used inside another expression.

Assigning to a variable inside another expression can be confusing and reduce readability. Consider moving the assignment out.

Example

❌ Bad:

void fn() {
var userName = 'Someone';

// LINT: Avoid nested assignments. Try moving this assignment out.
final message = "Hello ${userName = 'Someone Else'}!";
}

✅ Good:

void fn() {
var userName = 'Someone Else';
...
final message = "Hello ${userName}!";
}