prefer-conditional-expressions
Recommends to use a conditional expression instead of assigning to the same thing or return statement in each branch of an if statement.
Bad:
int a = 0;
// LINT
if (a > 0) {
a = 1;
} else {
a = 2;
}
// LINT
if (a > 0) a = 1;
else a = 2;
int function() {
// LINT
if (a == 1) {
return 0;
} else {
return 1;
}
// LINT
if (a == 2) return 0;
else return 1;
}
Good:
int a = 0;
a = a > 0 ? 1 : 2;
int function() {
return a == 2 ? 0 : 1;
}