From 1fa27f20715635279819a96ab8db8f9c307581fc Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 5 Jan 2017 23:41:45 +0000 Subject: [PATCH] builder:DefaultRuleReadmeLoader: show 'reason' instead for disabled rules --- .../builder/DefaultRuleReadmeLoader.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) 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 fb8c2e0..00dd99a 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 @@ -23,14 +23,21 @@ class DefaultRuleReadmeLoader implements RuleReadmeLoader { @Override public Stream load(final Rule rule) { - try { - final Path resolve = templateProperties.getReadmeFragments() - .resolve(rule.getName() + ".md"); - log.info("Loading fragment: {}", resolve); - return Stream.concat(Stream.of(String.format("%n#### [%s](%s)", rule.getName(), rule.getUri())), - Files.lines(resolve)); - } catch (IOException e) { - return Stream.empty(); + if (rule.isEnabled()) { + 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)); + } catch (IOException e) { + return Stream.empty(); + } + } else { + return Stream.of(formatRuleHeader(rule), "", rule.getReason()); } } + + private String formatRuleHeader(final Rule rule) { + return String.format("%n#### [%s](%s)", rule.getName(), rule.getUri()); + } }