From 9e26504c676b66835e2cebb5e51092a27e5babb9 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 6 Jan 2017 16:38:41 +0000 Subject: [PATCH] builder: meet level 5 complexity * DefaultReadmeIndexBuilder: final build() method * DefaultReadmeIndexBuilder: avoid inline conditionals * DefaultRuleReadmeLoader: reduce returns in load method --- builder/pom.xml | 2 +- .../ruleset/builder/DefaultReadmeIndexBuilder.java | 12 +++++++++--- .../ruleset/builder/DefaultRuleReadmeLoader.java | 12 +++++++----- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/builder/pom.xml b/builder/pom.xml index 7fde516..8fc61d1 100644 --- a/builder/pom.xml +++ b/builder/pom.xml @@ -25,7 +25,7 @@ 7.3 1.22.0 2.0.0-SNAPSHOT - 4-tweaks + 5-complexity diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultReadmeIndexBuilder.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultReadmeIndexBuilder.java index 517ffd9..d903376 100644 --- a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultReadmeIndexBuilder.java +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultReadmeIndexBuilder.java @@ -53,7 +53,7 @@ public class DefaultReadmeIndexBuilder implements ReadmeIndexBuilder { private final RulesProperties rulesProperties; @Override - public String build() { + public final String build() { return HEADERROW + SEPARATOR + rulesProperties.getRules() .stream() .sorted(Comparator.comparing(lowerCaseRuleName())) @@ -76,11 +76,17 @@ public class DefaultReadmeIndexBuilder implements ReadmeIndexBuilder { } private String suppressible(final Rule rule) { - return rule.isInsuppressible() ? "No" : ""; + if (rule.isInsuppressible()) { + return "No"; + } + return ""; } private String enabled(final Rule rule) { - return rule.isEnabled() ? "Yes" : ""; + if (rule.isEnabled()) { + return "Yes"; + } + return ""; } private String source(final Rule rule) { diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleReadmeLoader.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleReadmeLoader.java index e2e12da..888a847 100644 --- a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleReadmeLoader.java +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleReadmeLoader.java @@ -48,14 +48,16 @@ class DefaultRuleReadmeLoader implements RuleReadmeLoader { @Override public Stream load(final Rule rule) { if (rule.isEnabled()) { + final Path resolve = templateProperties.getReadmeFragments() + .resolve(rule.getName() + ".md"); + log.info("Loading fragment: {}", resolve); + Stream result = Stream.empty(); try { - final Path resolve = templateProperties.getReadmeFragments() - .resolve(rule.getName() + ".md"); - log.info("Loading fragment: {}", resolve); - return Stream.concat(Stream.of(formatRuleHeader(rule)), Files.lines(resolve)); + result = Stream.concat(Stream.of(formatRuleHeader(rule)), Files.lines(resolve)); } catch (IOException e) { - return Stream.empty(); + log.error("Failed to load fragment: {}", resolve); } + return result; } else { return Stream.of(formatRuleHeader(rule), "", rule.getReason()); }