builder: meet level 5 complexity
* DefaultReadmeIndexBuilder: final build() method * DefaultReadmeIndexBuilder: avoid inline conditionals * DefaultRuleReadmeLoader: reduce returns in load method
This commit is contained in:
parent
e2069b8d0d
commit
9e26504c67
3 changed files with 17 additions and 9 deletions
|
@ -25,7 +25,7 @@
|
|||
<checkstyle.version>7.3</checkstyle.version>
|
||||
<sevntu-checkstyle-maven-plugin.version>1.22.0</sevntu-checkstyle-maven-plugin.version>
|
||||
<kemitix-checkstyle-ruleset.version>2.0.0-SNAPSHOT</kemitix-checkstyle-ruleset.version>
|
||||
<kemitix-checkstyle-ruleset.level>4-tweaks</kemitix-checkstyle-ruleset.level>
|
||||
<kemitix-checkstyle-ruleset.level>5-complexity</kemitix-checkstyle-ruleset.level>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -48,14 +48,16 @@ class DefaultRuleReadmeLoader implements RuleReadmeLoader {
|
|||
@Override
|
||||
public Stream<String> load(final Rule rule) {
|
||||
if (rule.isEnabled()) {
|
||||
final Path resolve = templateProperties.getReadmeFragments()
|
||||
.resolve(rule.getName() + ".md");
|
||||
log.info("Loading fragment: {}", resolve);
|
||||
Stream<String> 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());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue