From 9369da8639329d28283550452fc702f7f25f3124 Mon Sep 17 00:00:00 2001 From: Sebastiaan Speck <12570668+sebastiaanspeck@users.noreply.github.com> Date: Mon, 18 Nov 2024 08:49:16 +0100 Subject: [PATCH] Respect DisabledByDefault for a check which is not explicitly enabled (#131) --- .../nl/ramsolutions/sw/magik/checks/CheckList.java | 11 ----------- .../sw/magik/checks/MagikChecksConfiguration.java | 12 +++++++++--- .../ramsolutions/sw/magik/typedchecks/CheckList.java | 12 ------------ 3 files changed, 9 insertions(+), 26 deletions(-) diff --git a/magik-checks/src/main/java/nl/ramsolutions/sw/magik/checks/CheckList.java b/magik-checks/src/main/java/nl/ramsolutions/sw/magik/checks/CheckList.java index ed7224cf9..34bbd8293 100644 --- a/magik-checks/src/main/java/nl/ramsolutions/sw/magik/checks/CheckList.java +++ b/magik-checks/src/main/java/nl/ramsolutions/sw/magik/checks/CheckList.java @@ -110,15 +110,4 @@ public static List> 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> getDisabledByDefaultChecks() { - return getChecks().stream() - .filter(checkClass -> checkClass.getAnnotation(DisabledByDefault.class) != null) - .toList(); - } } diff --git a/magik-checks/src/main/java/nl/ramsolutions/sw/magik/checks/MagikChecksConfiguration.java b/magik-checks/src/main/java/nl/ramsolutions/sw/magik/checks/MagikChecksConfiguration.java index 7e1c30415..ea20b9c4c 100644 --- a/magik-checks/src/main/java/nl/ramsolutions/sw/magik/checks/MagikChecksConfiguration.java +++ b/magik-checks/src/main/java/nl/ramsolutions/sw/magik/checks/MagikChecksConfiguration.java @@ -49,9 +49,15 @@ public List 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 parameters = diff --git a/magik-typed-checks/src/main/java/nl/ramsolutions/sw/magik/typedchecks/CheckList.java b/magik-typed-checks/src/main/java/nl/ramsolutions/sw/magik/typedchecks/CheckList.java index 3e50fbc7a..157e6e110 100644 --- a/magik-typed-checks/src/main/java/nl/ramsolutions/sw/magik/typedchecks/CheckList.java +++ b/magik-typed-checks/src/main/java/nl/ramsolutions/sw/magik/typedchecks/CheckList.java @@ -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; @@ -58,15 +57,4 @@ public static List> 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> getDisabledByDefaultChecks() { - return getChecks().stream() - .filter(checkClass -> checkClass.getAnnotation(DisabledByDefault.class) != null) - .toList(); - } }