Skip to main content

avoid-unnecessary-conditionals

has auto-fix
pro+

Checks for unnecessary conditional expressions.

Example

❌ Bad:

// LINT: Avoid unnecessary conditional expressions. Try using the condition directly.
bool baz() => foo ? true : false;

// LINT: Avoid unnecessary conditional expressions. Try using the condition directly.
bool bar() => foo ? false : true;

✅ Good:

bool baz() => foo;

bool bar() => !foo;