prefer-returning-condition
- Group
- Style
- Path
lint/style/prefer-returning-condition- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 400 of 512
Flags an if returning a boolean literal followed by the opposite literal.
Return the condition (or its negation) instead of spelling out both boolean
outcomes. Only adjacent statements with a plain condition, no else, and
one return in the then-branch are checked. Pattern conditions, extra branch
work, non-literal results, and equal results are left alone. Explicit else
branches are left to prefer-conditional-expressions. The fallback return
is highlighted; evaluation order and short-circuit behavior are unchanged.
Invalid
bool direct(bool value) {
if (value) return true;
return false;
}
bool inverted(bool value) {
if (value) { return false; }
return true;
}
bool parenthesized(bool value) {
if ((value)) { return (true); }
return (false);
}
class Worker {
bool check(int value) {
if (value > 0) { return true; }
return false;
}
}
void closure() {
final check = (bool value) {
if (value) return true;
return false;
};
print(check(true));
}
bool nested(bool value, bool other) {
if (other) {
if (value) return false;
return true;
}
return false;
}
bool nestedBlocks(bool value) {
if (value) {{ return true; }}
return false;
} if (value) return true; return false; if (value) { return false; } return true; if ((value)) { return (true); } return (false); if (value > 0) { return true; } return false; if (value) return true; return false; if (value) return false; return true; if (value) {{ return true; }} return false;Valid
bool direct(bool value) { return value; }
bool inverted(bool value) { return !value; }
bool extraWork(bool value) {
if (value) { print('work'); return true; }
return false;
}
bool same(bool value) {
if (value) return true;
return true;
}
bool intervening(bool value) {
if (value) return true;
print('other');
return false;
}
bool withElse(bool value) {
if (value) return true;
else return false;
}
bool pattern(Object value) {
if (value case int number when number > 0) return true;
return false;
}
int nonBoolean(bool value) {
if (value) return 1;
return 0;
}
bool arbitrary(bool value, bool result) {
if (value) return result;
return false;
}
bool separateBlock(bool value) {
if (value) return true;
{ return false; }
}Configure prefer-returning-condition
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"prefer-returning-condition": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/prefer-returning-condition: <reason>More style rules
- prefer-riverpod-notifier-suffixriverpod
Requires a
Notifiersuffix on classes extending resolved Riverpod notifiers. - prefer-riverpod-provider-suffixriverpod
Requires a Provider suffix on resolved Riverpod top-level providers and static fields.
- prefer-single-quotes
prefer_single_quotesFlags double-quoted string literals that could use single quotes without needing an escape.
- prefer-sized-box-squareflutter
Prefers SizedBox.square for an unnamed Flutter
SizedBoxwhose explicit width and height are stable variable reads or numeric literals with identical token spelling. - prefer-spread-collections
prefer_spread_collectionsrecommendedFlags an
addAllcascade on a collection literal that a spread would express. - prefer-switch-expression
Prefer switch expressions for exhaustive switches that only return or assign a value.
- prefer-test-matcherstest
Recommends Matcher expectations and direct type, equality, or ordering matchers.
- prefer-trailing-comma
prefer-trailing-commaFlags multi-line argument lists that are missing a trailing comma.