org.sonar.l10n.java.rules.squid.S1125.html Maven / Gradle / Ivy
Remove literal boolean values from conditional expressions to improve readability. Anything that can be tested for equality with a boolean value must itself be a boolean value, and boolean values can be tested atomically.
Noncompliant Code Example
if (booleanVariable == true) { /* ... */ }
if (booleanVariable != true) { /* ... */ }
if (booleanVariable || false) { /* ... */ }
doSomething(!false);
booleanVariable = condition ? true : exp;
booleanVariable = condition ? false : exp;
booleanVariable = condition ? exp : true;
booleanVariable = condition ? exp : false;
booleanVariable = condition ? true : false;
Compliant Solution
if (booleanVariable) { /* ... */ }
if (!booleanVariable) { /* ... */ }
if (booleanVariable) { /* ... */ }
doSomething(true);
booleanVariable = condition || exp;
booleanVariable = !condition && exp;
booleanVariable = !condition || exp;
booleanVariable = condition && exp;
booleanVariable = condition;
© 2015 - 2025 Weber Informatics LLC | Privacy Policy