From ea55fc57786ec505b5ddbb400b1a60b12aaf5e38 Mon Sep 17 00:00:00 2001 From: Philippe Charles Date: Fri, 5 Apr 2024 15:28:08 +0200 Subject: [PATCH] Code cleanup --- .../src/main/java/internal/heylogs/ExtendedRules.java | 2 ++ .../src/main/java/internal/heylogs/GuidingPrinciples.java | 2 ++ heylogs-api/src/main/java/internal/heylogs/JsonFormat.java | 2 ++ .../src/main/java/internal/heylogs/StylishFormat.java | 2 ++ .../src/main/java/internal/heylogs/github/GitHubRules.java | 2 ++ .../src/main/java/internal/heylogs/semver/SemVerRule.java | 2 ++ .../src/test/java/internal/heylogs/ExtendedRulesTest.java | 5 ++--- .../test/java/internal/heylogs/GuidingPrinciplesTest.java | 5 ++--- .../src/test/java/internal/heylogs/JsonFormatTest.java | 7 +++++++ .../src/test/java/internal/heylogs/StylishFormatTest.java | 7 +++++++ .../test/java/internal/heylogs/github/GitHubRulesTest.java | 5 ++--- .../test/java/internal/heylogs/semver/SemVerRuleTest.java | 4 ++-- 12 files changed, 34 insertions(+), 11 deletions(-) diff --git a/heylogs-api/src/main/java/internal/heylogs/ExtendedRules.java b/heylogs-api/src/main/java/internal/heylogs/ExtendedRules.java index 360ff7e..138e767 100644 --- a/heylogs-api/src/main/java/internal/heylogs/ExtendedRules.java +++ b/heylogs-api/src/main/java/internal/heylogs/ExtendedRules.java @@ -5,6 +5,7 @@ import com.vladsch.flexmark.util.ast.Document; import com.vladsch.flexmark.util.ast.Node; import lombok.NonNull; +import nbbrd.design.DirectImpl; import nbbrd.design.MightBeGenerated; import nbbrd.design.VisibleForTesting; import nbbrd.heylogs.Nodes; @@ -104,6 +105,7 @@ static RuleIssue validateConsistentSeparator(Document doc) { } @SuppressWarnings("unused") + @DirectImpl @MightBeGenerated @ServiceProvider public static final class Batch implements RuleBatch { diff --git a/heylogs-api/src/main/java/internal/heylogs/GuidingPrinciples.java b/heylogs-api/src/main/java/internal/heylogs/GuidingPrinciples.java index 7dbd077..ba511c3 100644 --- a/heylogs-api/src/main/java/internal/heylogs/GuidingPrinciples.java +++ b/heylogs-api/src/main/java/internal/heylogs/GuidingPrinciples.java @@ -7,6 +7,7 @@ import com.vladsch.flexmark.util.ast.Document; import com.vladsch.flexmark.util.ast.Node; import lombok.NonNull; +import nbbrd.design.DirectImpl; import nbbrd.design.MightBeGenerated; import nbbrd.design.VisibleForTesting; import nbbrd.heylogs.Changelog; @@ -264,6 +265,7 @@ private static T getFirstUnsortedItem(List list, Comparator comparator } @SuppressWarnings("unused") + @DirectImpl @MightBeGenerated @ServiceProvider public static final class Batch implements RuleBatch { diff --git a/heylogs-api/src/main/java/internal/heylogs/JsonFormat.java b/heylogs-api/src/main/java/internal/heylogs/JsonFormat.java index ba8ba14..e4c2448 100644 --- a/heylogs-api/src/main/java/internal/heylogs/JsonFormat.java +++ b/heylogs-api/src/main/java/internal/heylogs/JsonFormat.java @@ -2,6 +2,7 @@ import com.google.gson.*; import lombok.NonNull; +import nbbrd.design.DirectImpl; import nbbrd.design.MightBeGenerated; import nbbrd.heylogs.*; import nbbrd.heylogs.spi.Format; @@ -19,6 +20,7 @@ import static java.util.stream.Collectors.toList; +@DirectImpl @ServiceProvider public final class JsonFormat implements Format { diff --git a/heylogs-api/src/main/java/internal/heylogs/StylishFormat.java b/heylogs-api/src/main/java/internal/heylogs/StylishFormat.java index a0ef619..51f70b9 100644 --- a/heylogs-api/src/main/java/internal/heylogs/StylishFormat.java +++ b/heylogs-api/src/main/java/internal/heylogs/StylishFormat.java @@ -1,6 +1,7 @@ package internal.heylogs; import lombok.NonNull; +import nbbrd.design.DirectImpl; import nbbrd.design.MightBePromoted; import nbbrd.heylogs.*; import nbbrd.heylogs.spi.Format; @@ -19,6 +20,7 @@ import static java.util.Locale.ROOT; // https://eslint.org/docs/latest/user-guide/formatters/#stylish +@DirectImpl @ServiceProvider public final class StylishFormat implements Format { diff --git a/heylogs-api/src/main/java/internal/heylogs/github/GitHubRules.java b/heylogs-api/src/main/java/internal/heylogs/github/GitHubRules.java index 300c6c4..6f17ad8 100644 --- a/heylogs-api/src/main/java/internal/heylogs/github/GitHubRules.java +++ b/heylogs-api/src/main/java/internal/heylogs/github/GitHubRules.java @@ -4,6 +4,7 @@ import internal.heylogs.GitHostRef; import internal.heylogs.GitHostRefRuleSupport; import lombok.NonNull; +import nbbrd.design.DirectImpl; import nbbrd.design.VisibleForTesting; import nbbrd.heylogs.spi.Rule; import nbbrd.heylogs.spi.RuleBatch; @@ -11,6 +12,7 @@ import java.util.stream.Stream; +@DirectImpl @ServiceProvider public final class GitHubRules implements RuleBatch { diff --git a/heylogs-api/src/main/java/internal/heylogs/semver/SemVerRule.java b/heylogs-api/src/main/java/internal/heylogs/semver/SemVerRule.java index 50d5b2f..6190ef4 100644 --- a/heylogs-api/src/main/java/internal/heylogs/semver/SemVerRule.java +++ b/heylogs-api/src/main/java/internal/heylogs/semver/SemVerRule.java @@ -3,6 +3,7 @@ import com.vladsch.flexmark.ast.Heading; import com.vladsch.flexmark.util.ast.Node; import lombok.NonNull; +import nbbrd.design.DirectImpl; import nbbrd.design.VisibleForTesting; import nbbrd.heylogs.Version; import nbbrd.heylogs.spi.Rule; @@ -11,6 +12,7 @@ import nbbrd.service.ServiceProvider; import org.semver4j.Semver; +@DirectImpl @ServiceProvider public final class SemVerRule implements Rule { diff --git a/heylogs-api/src/test/java/internal/heylogs/ExtendedRulesTest.java b/heylogs-api/src/test/java/internal/heylogs/ExtendedRulesTest.java index 0fcff1a..e99c17d 100644 --- a/heylogs-api/src/test/java/internal/heylogs/ExtendedRulesTest.java +++ b/heylogs-api/src/test/java/internal/heylogs/ExtendedRulesTest.java @@ -6,12 +6,11 @@ import nbbrd.heylogs.Nodes; import nbbrd.heylogs.spi.Rule; import nbbrd.heylogs.spi.RuleIssue; -import nbbrd.service.ServiceId; +import nbbrd.heylogs.spi.RuleLoader; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.util.Objects; -import java.util.regex.Pattern; import static _test.Sample.using; import static internal.heylogs.ExtendedRules.NO_RULE_ISSUE; @@ -26,7 +25,7 @@ public class ExtendedRulesTest { public void testIdPattern() { assertThat(ExtendedRules.values()) .extracting(Rule::getRuleId) - .allMatch(Pattern.compile(ServiceId.KEBAB_CASE).asPredicate()); + .allMatch(RuleLoader.ID_PATTERN.asPredicate()); } @Test diff --git a/heylogs-api/src/test/java/internal/heylogs/GuidingPrinciplesTest.java b/heylogs-api/src/test/java/internal/heylogs/GuidingPrinciplesTest.java index ea7da75..6fc1328 100644 --- a/heylogs-api/src/test/java/internal/heylogs/GuidingPrinciplesTest.java +++ b/heylogs-api/src/test/java/internal/heylogs/GuidingPrinciplesTest.java @@ -4,11 +4,10 @@ import com.vladsch.flexmark.util.ast.Node; import nbbrd.heylogs.spi.Rule; import nbbrd.heylogs.spi.RuleIssue; -import nbbrd.service.ServiceId; +import nbbrd.heylogs.spi.RuleLoader; import org.junit.jupiter.api.Test; import java.util.Objects; -import java.util.regex.Pattern; import static _test.Sample.using; import static internal.heylogs.GuidingPrinciples.validateForHumans; @@ -23,7 +22,7 @@ public class GuidingPrinciplesTest { public void testIdPattern() { assertThat(GuidingPrinciples.values()) .extracting(Rule::getRuleId) - .allMatch(Pattern.compile(ServiceId.KEBAB_CASE).asPredicate()); + .allMatch(RuleLoader.ID_PATTERN.asPredicate()); } @Test diff --git a/heylogs-api/src/test/java/internal/heylogs/JsonFormatTest.java b/heylogs-api/src/test/java/internal/heylogs/JsonFormatTest.java index 8daa5e4..e28d629 100644 --- a/heylogs-api/src/test/java/internal/heylogs/JsonFormatTest.java +++ b/heylogs-api/src/test/java/internal/heylogs/JsonFormatTest.java @@ -1,6 +1,7 @@ package internal.heylogs; import nbbrd.heylogs.spi.Format; +import nbbrd.heylogs.spi.FormatLoader; import org.junit.jupiter.api.Test; import static _test.Sample.*; @@ -11,6 +12,12 @@ class JsonFormatTest { + @Test + public void testIdPattern() { + assertThat(new JsonFormat().getFormatId()) + .matches(FormatLoader.ID_PATTERN); + } + @Test public void testFormatProblems() { Format x = new JsonFormat(); diff --git a/heylogs-api/src/test/java/internal/heylogs/StylishFormatTest.java b/heylogs-api/src/test/java/internal/heylogs/StylishFormatTest.java index eaa6964..59f9fb8 100644 --- a/heylogs-api/src/test/java/internal/heylogs/StylishFormatTest.java +++ b/heylogs-api/src/test/java/internal/heylogs/StylishFormatTest.java @@ -1,6 +1,7 @@ package internal.heylogs; import nbbrd.heylogs.spi.Format; +import nbbrd.heylogs.spi.FormatLoader; import nbbrd.heylogs.spi.FormatType; import org.junit.jupiter.api.Test; @@ -12,6 +13,12 @@ class StylishFormatTest { + @Test + public void testIdPattern() { + assertThat(new StylishFormat().getFormatId()) + .matches(FormatLoader.ID_PATTERN); + } + @Test public void testSupportedTypes() { Format x = new StylishFormat(); diff --git a/heylogs-api/src/test/java/internal/heylogs/github/GitHubRulesTest.java b/heylogs-api/src/test/java/internal/heylogs/github/GitHubRulesTest.java index 19371ff..7c5e256 100644 --- a/heylogs-api/src/test/java/internal/heylogs/github/GitHubRulesTest.java +++ b/heylogs-api/src/test/java/internal/heylogs/github/GitHubRulesTest.java @@ -6,11 +6,10 @@ import nbbrd.heylogs.Nodes; import nbbrd.heylogs.spi.Rule; import nbbrd.heylogs.spi.RuleIssue; -import nbbrd.service.ServiceId; +import nbbrd.heylogs.spi.RuleLoader; import org.junit.jupiter.api.Test; import java.util.Objects; -import java.util.regex.Pattern; import static _test.Sample.using; import static internal.heylogs.github.GitHubRules.*; @@ -25,7 +24,7 @@ public class GitHubRulesTest { public void testIdPattern() { assertThat(new GitHubRules().getProviders()) .extracting(Rule::getRuleId) - .allMatch(Pattern.compile(ServiceId.KEBAB_CASE).asPredicate()); + .allMatch(RuleLoader.ID_PATTERN.asPredicate()); } @Test diff --git a/heylogs-api/src/test/java/internal/heylogs/semver/SemVerRuleTest.java b/heylogs-api/src/test/java/internal/heylogs/semver/SemVerRuleTest.java index 886fb33..be2a271 100644 --- a/heylogs-api/src/test/java/internal/heylogs/semver/SemVerRuleTest.java +++ b/heylogs-api/src/test/java/internal/heylogs/semver/SemVerRuleTest.java @@ -3,7 +3,7 @@ import com.vladsch.flexmark.ast.Heading; import com.vladsch.flexmark.util.ast.Node; import nbbrd.heylogs.spi.RuleIssue; -import nbbrd.service.ServiceId; +import nbbrd.heylogs.spi.RuleLoader; import org.junit.jupiter.api.Test; import java.util.Objects; @@ -17,7 +17,7 @@ public class SemVerRuleTest { @Test public void testIdPattern() { assertThat(new SemVerRule().getRuleId()) - .matches(ServiceId.KEBAB_CASE); + .matches(RuleLoader.ID_PATTERN); } @Test