avoid-negated-conditions
- Group
- Suspicious
- Path
lint/suspicious/avoid-negated-conditions- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 96 of 512
Prefer positive conditions when both branches can be swapped.
Checks if statements, conditional expressions, and collection/map if/else elements.
ignore-null-checks (default false) exempts comparisons with null.
Invalid
void f(bool flag, dynamic value) {
if (!flag) {} else {}
if (value != 1) {} else {}
if (value is! String) {} else {}
final a = !flag ? 1 : 2;
final b = value != null ? 1 : 2;
final c = value is! int ? 1 : 2;
final list = [if (!flag) 1 else 2];
final set = {if (value != 1) 1 else 2};
final map = {if (value is! int) 1: 2 else 3: 4};
final chained = [if (!flag) 1 else if (value != 1) 2 else 3];
}void f(bool flag, dynamic value) { if (!flag) {} else {} if (!flag) {} else {} if (value != 1) {} else {} if (value != 1) {} else {} if (value is! String) {} else {} if (value is! String) {} else {} final a = !flag ? 1 : 2; final a = !flag ? 1 : 2; final b = value != null ? 1 : 2; final b = value != null ? 1 : 2; final c = value is! int ? 1 : 2; final c = value is! int ? 1 : 2; final list = [if (!flag) 1 else 2]; final list = [if (!flag) 1 else 2]; final set = {if (value != 1) 1 else 2}; final set = {if (value != 1) 1 else 2}; final map = {if (value is! int) 1: 2 else 3: 4}; final map = {if (value is! int) 1: 2 else 3: 4}; final chained = [if (!flag) 1 else if (value != 1) 2 else 3];Valid
void f(bool flag, dynamic value) {
if (flag) {} else {}
if (!flag) return;
if (value == 1) {} else {}
if (value is String) {} else {}
final a = flag ? 1 : 2;
if (!flag) {} else if (value == 1) {}
final list = [if (flag) 1 else 2];
final set = {if (!flag) 1};
final map = {if (flag) 1: 2 else 3: 4};
final mapWithoutElse = {if (value != 1) 1: 2};
final chained = [if (!flag) 1 else if (value == 1) 2];
final chainedMap = {if (!flag) 1: 2 else if (value == 1) 3: 4};
}Configure avoid-negated-conditions
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"suspicious": {
"avoid-negated-conditions": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/suspicious/avoid-negated-conditions: <reason>More suspicious rules
- avoid-nested-assignments
Require assignments to be standalone statements, arrow bodies or loop operations.
- 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.