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.
⚙️ Config
Set ignore-null-aware-assignments
(default is false
) to exclude null aware assignments.
analysis_options.yaml
dart_code_metrics:
rules:
- avoid-nested-assignments:
ignore-null-aware-assignments: false
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}!";
}