Skip to content

Commit

Permalink
Respect DisabledByDefault for a check which is not explicitly enabled (
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiaanspeck authored Nov 18, 2024
1 parent a5c0aa3 commit 9369da8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,4 @@ public static List<Class<? extends MagikCheck>> getChecks() {
getFixers() {
return Map.of(FormattingCheck.class, List.of(FormattingFixer.class));
}

/**
* Get {@link MagikCheck}s which are disabled by default.
*
* @return List of {@link MagikCheck}s.
*/
public static List<Class<? extends MagikCheck>> getDisabledByDefaultChecks() {
return getChecks().stream()
.filter(checkClass -> checkClass.getAnnotation(DisabledByDefault.class) != null)
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,15 @@ public List<MagikCheckHolder> getAllChecks() {

for (final Class<?> checkClass : this.checkClasses) {
final String checkKey = MagikChecksConfiguration.checkKey(checkClass);
final boolean checkEnabled =
enableds.contains(checkKey)
|| !disableds.contains(checkKey) && !disableds.contains("all");
final boolean checkEnabled;
if (enableds.contains(checkKey)) {
checkEnabled = true;
} else if (disableds.contains(checkKey) || disableds.contains("all")) {
checkEnabled = false;
} else {
// No explicit configuration, use default state
checkEnabled = checkClass.getAnnotation(DisabledByDefault.class) == null;
}

// Gather parameters from MagikCheck, value from config.
final Set<MagikCheckHolder.Parameter> parameters =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.List;
import java.util.Map;
import nl.ramsolutions.sw.magik.checks.DisabledByDefault;
import nl.ramsolutions.sw.magik.checks.MagikCheck;
import nl.ramsolutions.sw.magik.checks.checks.TypeDocCheck;
import nl.ramsolutions.sw.magik.typedchecks.checks.ConditionalExpressionIsFalseTypedCheck;
Expand Down Expand Up @@ -58,15 +57,4 @@ public static List<Class<? extends MagikCheck>> getChecks() {
return Map.of(
TypeDocCheck.class, List.of(TypeDocParameterFixer.class, TypeDocReturnTypeFixer.class));
}

/**
* Get {@link MagikCheck}s which are disabled by default.
*
* @return List of {@link MagikCheck}s.
*/
public static List<Class<? extends MagikCheck>> getDisabledByDefaultChecks() {
return getChecks().stream()
.filter(checkClass -> checkClass.getAnnotation(DisabledByDefault.class) != null)
.toList();
}
}

0 comments on commit 9369da8

Please sign in to comment.