avoid-nested-assignments
- Group
- Suspicious
- Path
lint/suspicious/avoid-nested-assignments- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 97 of 512
Require assignments to be standalone statements, arrow bodies or loop operations.
ignore-null-aware-assignments (default false) exempts ??=.
Conditions and chained assignments are handled by their dedicated rules.
Invalid
void f(dynamic x, dynamic y, dynamic z) {
print(x = 1);
final value = (x = 2);
returnValue(x += 3);
final message = '${x = 4}';
print(z ??= 6);
}void f(dynamic x, dynamic y, dynamic z) { print(x = 1); print(x = 1); final value = (x = 2); final value = (x = 2); returnValue(x += 3); returnValue(x += 3); final message = '${x = 4}'; final message = '${x = 4}'; print(z ??= 6);Valid
void f(dynamic x) {
x = 1;
x += 2;
(x = 3);
for (x = 0; x < 5; x = x + 1) {}
final closure = () { x = 4; };
x ??= 6;
final arrow = () => x = 7;
final lazy = () => x ??= 8;
x = (x = 9);
if ((x = true)) {}
while ((x = readLine()) != null) {}
final owner = Owner();
owner..value = x = 10;
consume(x = x = 11);
}
class Owner {
dynamic value;
set name(String input) => value = input;
dynamic get cached => value ??= Owner();
}Configure avoid-nested-assignments
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"suspicious": {
"avoid-nested-assignments": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/suspicious/avoid-nested-assignments: <reason>More suspicious rules
- avoid-non-final-exception-class-fields
Exception and Error payloads should not change after construction.
- avoid-passing-async-when-sync-expected
avoid-passing-async-when-sync-expectedrecommendedFlags an
asyncclosure passed to a proven synchronous callback parameter. - avoid-passing-bloc-to-blocbloc
Rejects direct Bloc and Cubit arguments to other blocs.
- avoid-passing-bloc-to-widgetbloc
Rejects direct Bloc and Cubit arguments to Flutter widget constructors.
- avoid-passing-build-context-to-blocsbloc
Keeps Flutter
BuildContextarguments outside Bloc and Cubit APIs. - avoid-print
avoid_printrecommendedflutterFlags calls and callback arguments resolving to
dart:core'sprint. - avoid-referencing-subclasses
Keeps base classes independent from their transitive subclasses.
- avoid-returning-null-for-void
avoid_returning_null_for_voidrecommendedFlags
return null;(and=> nullbodies) in synchronousvoidfunctions and asynchronousFuture<void>functions.