Skip to content

Commit 5256aba

Browse files
markhbradyError Prone Team
authored andcommitted
[IfChainToSwitch] add explicit values for EnableSafe to tests
PiperOrigin-RevId: 930807392
1 parent 74546d8 commit 5256aba

2 files changed

Lines changed: 398 additions & 100 deletions

File tree

core/src/main/java/com/google/errorprone/bugpatterns/IfChainToSwitch.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,15 @@ public final class IfChainToSwitch extends BugChecker implements IfTreeMatcher {
116116
private final boolean enableMain;
117117
private final boolean enableSafe;
118118
private final int maxChainLength;
119+
private final int minChainLength;
119120
private final ConstantExpressions constantExpressions;
120121

121122
@Inject
122123
IfChainToSwitch(ErrorProneFlags flags, ConstantExpressions constantExpressions) {
123-
enableMain = flags.getBoolean("IfChainToSwitch:EnableMain").orElse(false);
124+
enableMain = flags.getBoolean("IfChainToSwitch:EnableMain").orElse(true);
124125
enableSafe = flags.getBoolean("IfChainToSwitch:EnableSafe").orElse(false);
125126
maxChainLength = flags.getInteger("IfChainToSwitch:MaxChainLength").orElse(50);
127+
minChainLength = flags.getInteger("IfChainToSwitch:MinChainLength").orElse(5);
126128
this.constantExpressions = constantExpressions;
127129
}
128130

@@ -184,7 +186,7 @@ private Description analyzeIfTree(IfTree ifTree, VisitorState state) {
184186

185187
if (!ifChainAnalysisState.validity().equals(Validity.VALID)
186188
// Exclude short if-chains, since they may be more readable as-is
187-
|| ifChainAnalysisState.depth() < 3) {
189+
|| ifChainAnalysisState.depth() < minChainLength) {
188190
return NO_MATCH;
189191
}
190192

0 commit comments

Comments
 (0)