Skip to main content

avoid-unnecessary-conditionals

added in: 1.6.0
🛠
Pro+
preset: recommended

Checks for unnecessary conditional expressions.

Example

❌ Bad:

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

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

✅ Good:

bool baz() => foo;

bool bar() => !foo;