Merge pull request #3 from kemitix/levels

Split ruleset into Levels
This commit is contained in:
Paul Campbell 2017-01-10 23:05:51 +00:00 committed by GitHub
commit 0169b1d608
199 changed files with 6732 additions and 569 deletions

5
.travis.yml Normal file
View file

@ -0,0 +1,5 @@
language: java
jdk:
- oraclejdk8
after_success:
- mvn --projects builder clean test jacoco:report coveralls:report

View file

@ -1,4 +1,4 @@
/*
The MIT License (MIT)
Copyright (c) 2016 Paul Campbell
@ -20,3 +20,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

745
README.md

File diff suppressed because it is too large Load diff

23
builder/LICENSE.txt Normal file
View file

@ -0,0 +1,23 @@
/*
The MIT License (MIT)
Copyright (c) 2016 Paul Campbell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

130
builder/pom.xml Normal file
View file

@ -0,0 +1,130 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.kemitix</groupId>
<artifactId>kemitix-spring-parent</artifactId>
<version>2.2.0</version>
<relativePath/>
</parent>
<artifactId>kemitix-checkstyle-ruleset-builder</artifactId>
<version>2.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Kemitix Checkstyle Ruleset Builder</name>
<description>Builder for the Kemitix Checkstyle Ruleset</description>
<issueManagement>
<url>https://github.com/kemitix/kemitix-checkstyle-ruleset/issues</url>
<system>GitHub Issues</system>
</issueManagement>
<scm>
<connection>scm:git:git@github.com:kemitix/kemitix-checkstyle-ruleset.git</connection>
<developerConnection>scm:git:git@github.com:kemitix/kemitix-checkstyle-ruleset.git</developerConnection>
<url>git@github.com:kemitix/kemitix-checkstyle-ruleset.git</url>
</scm>
<url>https://github.com/kemitix/kemitix-checkstyle-ruleset</url>
<inceptionYear>2016</inceptionYear>
<properties>
<spring-boot.version>1.4.3.RELEASE</spring-boot.version>
<kemitix-checkstyle-ruleset.version>2.0.0-SNAPSHOT</kemitix-checkstyle-ruleset.version>
<kemitix-checkstyle-ruleset.level>5-complexity</kemitix-checkstyle-ruleset.level>
<assertj.version>3.6.1</assertj.version>
<mapstream.version>2.3.4</mapstream.version>
<mapbuilder.version>1.0.0</mapbuilder.version>
<coveralls-maven-plugin.version>4.3.0</coveralls-maven-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.speedment.common</groupId>
<artifactId>mapstream</artifactId>
<version>${mapstream.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
</dependency>
<dependency>
<groupId>me.andrz</groupId>
<artifactId>map-builder</artifactId>
<version>${mapbuilder.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven.checkstyle.plugin.version}</version>
<configuration>
<configLocation>net/kemitix/checkstyle-${kemitix-checkstyle-ruleset.level}.xml</configLocation>
</configuration>
</plugin><!-- maven-checkstyle-plugin -->
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<!--<configuration>-->
<!--<executable>true</executable>-->
<!--</configuration>-->
<!--<executions>-->
<!--<execution>-->
<!--<goals>-->
<!--<goal>-->
<!--repackage-->
<!--</goal>-->
<!--</goals>-->
<!--</execution>-->
<!--</executions>-->
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>${coveralls-maven-plugin.version}</version>
</plugin>
</plugins>
</build>
</project>

View file

@ -0,0 +1,52 @@
/*
The MIT License (MIT)
Copyright (c) 2016 Paul Campbell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package net.kemitix.checkstyle.ruleset.builder;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
/**
* Creates the checkstyle ruleset files.
*
* <p>This application is intended to only to be used by the developer to create the actual checkstyle xml files that
* this module provides.</p>
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
@EnableConfigurationProperties({RulesProperties.class, OutputProperties.class})
@SpringBootApplication
@SuppressWarnings("hideutilityclassconstructor")
public class CheckstyleRulesetBuilderApplication {
/**
* Main methods.
*
* @param args Command line arguments.
*/
public static void main(final String[] args) {
SpringApplication.run(CheckstyleRulesetBuilderApplication.class, args);
}
}

View file

@ -0,0 +1,119 @@
/*
The MIT License (MIT)
Copyright (c) 2016 Paul Campbell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package net.kemitix.checkstyle.ruleset.builder;
import com.speedment.common.mapstream.MapStream;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Writes the Checkstyle XML files.
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
@Slf4j
@Component
@RequiredArgsConstructor
class CheckstyleWriter implements CommandLineRunner {
private static final String NEWLINE = "\n";
private final OutputProperties outputProperties;
private final TemplateProperties templateProperties;
private final RulesProperties rulesProperties;
@Override
public void run(final String... args) throws Exception {
Stream.of(RuleLevel.values())
.filter(level -> !level.equals(RuleLevel.UNSPECIFIED))
.forEach(this::writeCheckstyleFile);
}
private void writeCheckstyleFile(@NonNull final RuleLevel ruleLevel) {
val xmlFile = outputProperties.getDirectory()
.resolve(outputProperties.getRulesetFiles()
.get(ruleLevel));
val checkerRules = rulesProperties.getRules()
.stream()
.filter(Rule::isEnabled)
.filter(rule -> RuleParent.CHECKER.equals(rule.getParent()))
.filter(rule -> ruleLevel.compareTo(rule.getLevel()) >= 0)
.map(this::formatRuleAsModule)
.collect(Collectors.joining(NEWLINE));
val treeWalkerRules = rulesProperties.getRules()
.stream()
.filter(Rule::isEnabled)
.filter(rule -> RuleParent.TREEWALKER.equals(rule.getParent()))
.filter(rule -> ruleLevel.compareTo(rule.getLevel()) >= 0)
.map(this::formatRuleAsModule)
.collect(Collectors.joining(NEWLINE));
try {
val checkstyleXmlTemplate = templateProperties.getCheckstyleXml();
if (checkstyleXmlTemplate.toFile()
.exists()) {
val bytes = Files.readAllBytes(checkstyleXmlTemplate);
val template = new String(bytes, StandardCharsets.UTF_8);
val output = Arrays.asList(String.format(template, checkerRules, treeWalkerRules)
.split(NEWLINE));
log.info("Writing xmlFile: {}", xmlFile);
Files.write(xmlFile, output, StandardCharsets.UTF_8);
} else {
throw new IOException("Missing template: " + checkstyleXmlTemplate.toString());
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private String formatRuleAsModule(final Rule rule) {
if (rule.getProperties()
.isEmpty()) {
return String.format("<module name=\"%s\"/>", rule.getName());
}
return String.format("<module name=\"%s\">%n %s%n</module>", rule.getName(),
formatProperties(rule.getProperties())
);
}
private String formatProperties(final Map<String, String> properties) {
return MapStream.of(properties)
.map((k, v) -> String.format("<property name=\"%s\" value=\"%s\"/>", k, v))
.collect(Collectors.joining(NEWLINE));
}
}

View file

@ -0,0 +1,104 @@
/*
The MIT License (MIT)
Copyright (c) 2016 Paul Campbell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package net.kemitix.checkstyle.ruleset.builder;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import java.util.Comparator;
import java.util.Locale;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* Default Rule Index Builder.
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
@Component
@RequiredArgsConstructor
public class DefaultReadmeIndexBuilder implements ReadmeIndexBuilder {
private static final String NEWLINE = "\n";
private static final Locale LOCALE = Locale.ENGLISH;
private final RulesProperties rulesProperties;
@Override
public final String build() {
return rulesProperties.getRules()
.stream()
.sorted(Comparator.comparing(lowerCaseRuleName()))
.map(this::formatRuleRow)
.collect(Collectors.joining(NEWLINE));
}
private Function<Rule, String> lowerCaseRuleName() {
return this::getLowerCaseRuleName;
}
private String getLowerCaseRuleName(final Rule rule) {
return rule.getName()
.toLowerCase(LOCALE);
}
private String formatRuleRow(final Rule rule) {
return String.format(
"%s|%s|%s|%s|%s", link(rule), level(rule), source(rule), enabled(rule), suppressible(rule));
}
private String suppressible(final Rule rule) {
if (rule.isInsuppressible()) {
return "No";
}
return "";
}
private String enabled(final Rule rule) {
if (rule.isEnabled()) {
return "Yes";
}
return "";
}
private String source(final Rule rule) {
return rule.getSource()
.toString()
.toLowerCase(LOCALE);
}
private String link(final Rule rule) {
return String.format("[%s](#%s)", rule.getName(), getLowerCaseRuleName(rule));
}
private String level(final Rule rule) {
return Optional.ofNullable(rule.getLevel())
.orElse(RuleLevel.UNSPECIFIED)
.toString()
.toLowerCase(LOCALE);
}
}

View file

@ -0,0 +1,67 @@
/*
The MIT License (MIT)
Copyright (c) 2016 Paul Campbell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package net.kemitix.checkstyle.ruleset.builder;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Stream;
/**
* Default README fragment loader.
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
@Slf4j
@Component
@RequiredArgsConstructor
class DefaultRuleReadmeLoader implements RuleReadmeLoader {
private final TemplateProperties templateProperties;
@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);
try {
return Stream.concat(Stream.of(formatRuleHeader(rule)), Files.lines(resolve));
} catch (IOException e) {
throw new ReadmeFragmentNotFoundException(rule.getName(), e);
}
} else {
return Stream.of(formatRuleHeader(rule), "", rule.getReason());
}
}
private String formatRuleHeader(final Rule rule) {
return String.format("#### [%s](%s)", rule.getName(), rule.getUri());
}
}

View file

@ -0,0 +1,60 @@
/*
The MIT License (MIT)
Copyright (c) 2016 Paul Campbell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package net.kemitix.checkstyle.ruleset.builder;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import java.nio.file.Path;
import java.util.Map;
/**
* Properties defining the output files.
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
@Setter
@Getter
@Configuration
@ConfigurationProperties(prefix = "output")
class OutputProperties {
/**
* The directory to create the output files in.
*/
private Path directory;
/**
* Checkstyle XML files to create for each ruleset level.
*/
private Map<RuleLevel, String> rulesetFiles;
/**
* The README.md file.
*/
private Path readme;
}

View file

@ -0,0 +1,43 @@
/*
The MIT License (MIT)
Copyright (c) 2016 Paul Campbell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package net.kemitix.checkstyle.ruleset.builder;
/**
* Exception raised when a README documentation fragment can't be found for a rule.
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
class ReadmeFragmentNotFoundException extends RuntimeException {
/**
* Constructor.
*
* @param ruleName The name of the Rule.
* @param cause The cause.
*/
ReadmeFragmentNotFoundException(final String ruleName, final Throwable cause) {
super(ruleName, cause);
}
}

View file

@ -0,0 +1,40 @@
/*
The MIT License (MIT)
Copyright (c) 2016 Paul Campbell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package net.kemitix.checkstyle.ruleset.builder;
/**
* Creates the Rule Index for README.md in Markdown Format.
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
public interface ReadmeIndexBuilder {
/**
* Builds the Rule Index in Markdown Format.
*
* @return The rule index.
*/
String build();
}

View file

@ -0,0 +1,103 @@
/*
The MIT License (MIT)
Copyright (c) 2016 Paul Campbell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package net.kemitix.checkstyle.ruleset.builder;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
* Writes the README file.
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
@Component
@RequiredArgsConstructor
class ReadmeWriter implements CommandLineRunner {
private static final String NEWLINE = "\n";
private final TemplateProperties templateProperties;
private final OutputProperties outputProperties;
private final RulesProperties rulesProperties;
private final RuleReadmeLoader ruleReadmeLoader;
private final ReadmeIndexBuilder indexBuilder;
@Override
public void run(final String... args) throws Exception {
final String readmeTemplate = readFile(templateProperties.getReadmeTemplate());
final String enabledCheckstyle = readmeRules(this::isEnabledCheckstyleRule);
final String enabledSevntu = readmeRules(this::isEnabledSevntuRule);
final String disabledCheckstyle = readmeRules(this::isDisabledCheckstyleRule);
final String disabledSevntu = readmeRules(this::isDisabledSevntuRule);
final byte[] readme = String.format(readmeTemplate, indexBuilder.build(), enabledCheckstyle, enabledSevntu,
disabledCheckstyle, disabledSevntu
)
.getBytes(StandardCharsets.UTF_8);
Files.write(outputProperties.getReadme(), readme, StandardOpenOption.TRUNCATE_EXISTING);
}
private boolean isEnabledSevntuRule(final Rule rule) {
return rule.isEnabled() && RuleSource.SEVNTU.equals(rule.getSource());
}
private boolean isEnabledCheckstyleRule(final Rule rule) {
return rule.isEnabled() && RuleSource.CHECKSTYLE.equals(rule.getSource());
}
private boolean isDisabledSevntuRule(final Rule rule) {
return !rule.isEnabled() && RuleSource.SEVNTU.equals(rule.getSource());
}
private boolean isDisabledCheckstyleRule(final Rule rule) {
return !rule.isEnabled() && RuleSource.CHECKSTYLE.equals(rule.getSource());
}
private String readmeRules(final Predicate<Rule> predicate) {
return rulesProperties.getRules()
.stream()
.filter(predicate)
.flatMap(ruleReadmeLoader::load)
.collect(Collectors.joining(NEWLINE));
}
private String readFile(final Path file) throws IOException {
return Files.lines(file, StandardCharsets.UTF_8)
.collect(Collectors.joining(NEWLINE));
}
}

View file

@ -0,0 +1,87 @@
/*
The MIT License (MIT)
Copyright (c) 2016 Paul Campbell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package net.kemitix.checkstyle.ruleset.builder;
import lombok.Getter;
import lombok.Setter;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
/**
* A single Checkstyle Check.
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
@Setter
@Getter
public class Rule {
/**
* The name of the rule's Check class.
*/
private String name;
/**
* The parent module.
*/
private RuleParent parent;
/**
* The first level the rule is enabled on.
*/
private RuleLevel level;
/**
* Whether the rule is enabled.
*/
private boolean enabled;
/**
* The source of the rule.
*/
private RuleSource source;
/**
* URI for full official documentation.
*/
private URI uri;
/**
* Flag to indicate rules that can not be suppressed (via {@code @SuppressWarnings}.
*/
private boolean insuppressible;
/**
* The reason a rule has been disabled.
*/
private String reason;
/**
* Configuration properties.
*/
private final Map<String, String> properties = new HashMap<>();
}

View file

@ -0,0 +1,40 @@
/*
The MIT License (MIT)
Copyright (c) 2016 Paul Campbell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package net.kemitix.checkstyle.ruleset.builder;
/**
* Ruleset levels.
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
public enum RuleLevel {
LAYOUT,
NAMING,
JAVADOC,
TWEAKS,
COMPLEXITY,
UNSPECIFIED,
}

View file

@ -0,0 +1,36 @@
/*
The MIT License (MIT)
Copyright (c) 2016 Paul Campbell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package net.kemitix.checkstyle.ruleset.builder;
/**
* Module parent to contain a rule.
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
public enum RuleParent {
CHECKER,
TREEWALKER;
}

View file

@ -0,0 +1,45 @@
/*
The MIT License (MIT)
Copyright (c) 2016 Paul Campbell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package net.kemitix.checkstyle.ruleset.builder;
import java.util.stream.Stream;
/**
* Loads README fragment for rule.
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
@FunctionalInterface
interface RuleReadmeLoader {
/**
* Loads the README fragment for rule.
*
* @param rule The Rule.
*
* @return A Stream of the readme fragment.
*/
Stream<String> load(Rule rule);
}

View file

@ -0,0 +1,36 @@
/*
The MIT License (MIT)
Copyright (c) 2016 Paul Campbell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package net.kemitix.checkstyle.ruleset.builder;
/**
* The origin of the rule.
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
public enum RuleSource {
CHECKSTYLE,
SEVNTU,
}

View file

@ -0,0 +1,50 @@
/*
The MIT License (MIT)
Copyright (c) 2016 Paul Campbell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package net.kemitix.checkstyle.ruleset.builder;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import java.util.ArrayList;
import java.util.List;
/**
* Properties defining the enabled rules for each level.
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
@Slf4j
@Getter
@Configuration
@ConfigurationProperties
class RulesProperties {
/**
* The Checkstyle checks.
*/
private List<Rule> rules = new ArrayList<>();
}

View file

@ -0,0 +1,59 @@
/*
The MIT License (MIT)
Copyright (c) 2016 Paul Campbell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package net.kemitix.checkstyle.ruleset.builder;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import java.nio.file.Path;
/**
* Properties for template files.
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
@Setter
@Getter
@Configuration
@ConfigurationProperties(prefix = "template")
class TemplateProperties {
/**
* Template for Checkstyle XML files.
*/
private Path checkstyleXml;
/**
* Template for README.md file.
*/
private Path readmeTemplate;
/**
* The directory containing the README fragments.
*/
private Path readmeFragments;
}

View file

@ -0,0 +1,31 @@
/*
The MIT License (MIT)
Copyright (c) 2016 Paul Campbell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Ruleset Builder.
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
package net.kemitix.checkstyle.ruleset.builder;

View file

@ -0,0 +1,138 @@
# kemitix-checkstyle-ruleset
Provides an extensive Checkstyle ruleset for use with Apache's `maven-checkstyle-plugin`.
The ruleset includes checks from both the core Checkstyle library and from the Sevntu-Checkstyle library.
* [Requirements](#requirements)
* [Usage](#usage)
* [All Checks](#all-checks)
* [Enabled Checks](#enabled-checks)
* [Checkstyle](#checkstyle)
* [Sevntu](#sevntu)
* [Disabled Checks](#disabled-checks)
* [Checkstyle](#checkstyle-1)
* [Sevntu](#sevntu-1)
## Requirements
* [maven-checkstyle-plugin](https://maven.apache.org/plugins/maven-checkstyle-plugin/) 2.17+
* [Checkstyle](http://checkstyle.sourceforge.net/) 7.0+
* [Sevntu-checkstyle](http://sevntu-checkstyle.github.io/sevntu.checkstyle/) 1.21.0+
## Usage
To use this ruleset in your `maven-checkstyle-plugin` configuration add `checkstyle`, `sevntu-checkstyle-maven-plugin` and `kemitix-checktyle-ruleset` as dependencies of the `maven-checkstyle-plugin`.
You need to include `checkstyle` as the version bundled with the `maven-checkstyle-plugin` is not up-to-date enough.
Select the `configLocation` for the level of strictness required:
* checkstyle-1-layout.xml
* checkstyle-2-naming.xml
* checkstyle-3-javadoc.xml
* checkstyle-4-tweaks.xml
* checkstyle-5-complexity.xml
Only specify a single `configLocation` as each increasing level includes all the rules
from the previous.
````
<properties>
<maven.checkstyle.plugin.version>2.17</maven.checkstyle.plugin.version>
<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</kemitix-checkstyle-ruleset.version>
<kemitix-checkstyle-ruleset.level>5-complexity</kemitix-checkstyle-ruleset.level>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven.checkstyle.plugin.version}</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>${checkstyle.version}</version>
</dependency>
<dependency>
<groupId>com.github.sevntu.checkstyle</groupId>
<artifactId>sevntu-checkstyle-maven-plugin</artifactId>
<version>${sevntu-checkstyle-maven-plugin.version}</version>
</dependency>
<dependency>
<groupId>net.kemitix</groupId>
<artifactId>kemitix-checkstyle-ruleset</artifactId>
<version>${kemitix-checkstyle-ruleset.version}</version>
</dependency>
</dependencies>
<configuration>
<configLocation>net/kemitix/checkstyle-${kemitix-checkstyle-ruleset.level}.xml</configLocation>
</configuration>
</plugin><!-- maven-checkstyle-plugin -->
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
<goal>checkstyle</goal>
</goals>
</execution>
</executions>
</plugin><!-- maven-checkstyle-plugin -->
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>sevntu-maven</id>
<name>sevntu-maven</name>
<url>http://sevntu-checkstyle.github.io/sevntu.checkstyle/maven2</url>
</pluginRepository>
</pluginRepositories>
````
## All Checks
Rule|Level|Source|Enabled|Suppressable
----|-----|------|-------|------------
%s
## Enabled Checks
The following is a list of each of the checks and the expectations each has on your code.
### Checkstyle
Rules are listed in alphabetical order.
%s
### Sevntu
%s
## Disabled Checks
These checks are not enabled. Notes are included for each explaining why.
### Checkstyle
%s
### Sevntu
As the sevntu check are considered experimental not all those that are not enabled are listed here. Only where they are disabled due to a conflict with my 'style' or there is another irreconcilable difference that prevents them from being enabled, will they be documented to prevent repeated investigations.
%s
[Effective Java]: http://amzn.to/2aSz6GE

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
%s
<module name="TreeWalker">
%s
</module><!-- /TreeWalker -->
</module><!-- /Checker -->

View file

@ -0,0 +1,12 @@
Enforces proper `CamelCase` and avoids sequences of consecutive uppercase characters in identifiers. Does not apply to @Overridden methods.
Valid:
````
class DaoManager {}
````
Invalid:
````
class DAOManager {}
````

View file

@ -0,0 +1,12 @@
The name of an `abstract` class must start with `Abstract`. Classes that start with `Abstract` must be `abstract`.
Valid:
````
abstract class AbstractCardHand implements CardHand {}
````
Invalid:
````
abstract class BaseCardHand implements CardHand {}
````

View file

@ -0,0 +1 @@
Anonymous inner classes should be no more than 20 lines.

View file

@ -0,0 +1,20 @@
Annotations must be on a line by themselves unless annotating a method parameter or among class modifiers.
Valid:
````
@Component
@Qualifier("Red")
class RedStick implements Stick {
public @NonNull String getLabel(@Value("${stick.length}") final int length) {
// ...
}
}
````
Invalid:
````
@Component @Qualifier("Red")
class RedStick implements Stick {}
````

View file

@ -0,0 +1,15 @@
Annotations should only use brackets and named attributes when they are needed. If only the default parameter is specified, then only the attribute value should be given. If there are no parameters, then no brackets should be given.
Valid:
````
@Entity
@Table("names")
@MyAnnotation(realm = "external")
````
Invalid:
````
@Entity()
@Table(value = "names")
````

View file

@ -0,0 +1,2 @@
Anonymous inner classes should be no more than 20 lines.

View file

@ -0,0 +1,12 @@
Enforces Java style arrays.
Valid:
````
public static void main(String[] args) {}
````
Invalid:
````
public static void main(String args[]) {}
````

View file

@ -0,0 +1,20 @@
Javadoc `@` clauses must be in the order:
````
/**
*
* @param ...
* @author ...
* @version ...
* @serial ...
* @return ...
* @throws ...
* @exception ...
* @serialData ...
* @serialField ...
* @see ...
* @since ...
* @deprecated ...
*/
````

View file

@ -0,0 +1,12 @@
Checks that condition expressions don't become less readable by attempting to use a constant on the left-hand-side of a comparison.
Valid:
````
if (a == 12) {}
````
Invalid:
````
if (12 == a) {}
````

View file

@ -0,0 +1,13 @@
Prevents use of obscure escape codes (e.g. `\u221e`). However, non-printable/control characters are still permitted.
Valid:
````
String unitAbbrev = "??s";
String byteOrdered = '\ufeff' = content;
````
Invalid:
````
String unitAbbrev = "\u03bcs";
````

View file

@ -0,0 +1,20 @@
Ensures that an exception is re-thrown properly and is not swallowed by a `catch` block.
Valid:
````
try {
doSomething();
} catch (MyException e) {
throw new MyOtherException(e);
}
````
Invalid:
````
try {
doSomething();
} catch (MyException e) {
throw new MyOtherException();
}
````

View file

@ -0,0 +1,2 @@
Prevents use of the `?:` operators.

View file

@ -0,0 +1,17 @@
Avoid unnecessary blocks.
Valid:
````
if (isDebug()) {
// ...
}
````
Invalid:
````
// if (isDebug())
{
// ...
}
````

View file

@ -0,0 +1,12 @@
Prevents the use of boolean operators that don't allow short-circuiting the expression. (e.g. '|', '&', '|=' and '&=')
Valid:
````
if ((a < b) || (b > getExpensiveValue())) {}
````
Invalid:
````
if ((a < b) | (b > getExpensiveValue())) {}
````

View file

@ -0,0 +1,10 @@
Prevents the use of the star import.
Invalid:
````
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
````

View file

@ -0,0 +1,19 @@
Prevents importing static members, unless they are one of the following:
* `org.assertj.core.api.Assertions.assertThat`
* `org.mockito.BDDMockito.given`
* `org.mockito.Mockito.*`
* `org.mockito.Matchers.*`
* `org.mockito.Mockito.*`
Valid:
````
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
````
Invalid:
````
import static java.nio.charset.StandardCharsets.UTF_8;
````

View file

@ -0,0 +1,12 @@
Restrict the number of number of &&, ||, &, | and ^ in an expression to 2.
Valid:
````
if (a || (b && c)) {}
````
Invalid:
````
if (a > b || b > c || c == a || d > a) {}
````

View file

@ -0,0 +1,29 @@
Checks that catch parameter names conform to the following characteristic:
* allows names beginning with two lowercase letters followed by at least one uppercase or lowercase letter
* allows e abbreviation (suitable for exceptions end errors)
* allows ex abbreviation (suitable for exceptions)
* allows t abbreviation (suitable for throwables)
* prohibits numbered abbreviations like e1 or t2
* prohibits one letter prefixes like pException
* prohibits two letter abbreviations like ie or ee
* prohibits any other characters than letters
Valid:
````
catch(Exception txD) {}
catch(Exception txf) {}
catch(Exception e) {}
catch(Error e) {}
catch(Exception ex) {}
catch(Throwable t) {}
````
Invalid:
````
catch(Exception e2) {}
catch(Exception pExceptions) {}
catch(Exception gh) {}
catch(Exception e_x) {}
````

View file

@ -0,0 +1,30 @@
Restricts to 7 the number of different classes instantiated within a class when that class is instantiated.
Valid:
````
class Valid {
private final Item i1 = new Item();
private final Item i2 = new Item();
private final Item i3 = new Item();
private final Item i4 = new Item();
private final Item i5 = new Item();
private final Item i6 = new Item();
private final Item i7 = new Item();
private final Item i8 = new Item();
}
````
Invalid:
````
class Invalid {
private final ItemA i1 = new ItemA();
private final ItemB i2 = new ItemB();
private final ItemC i3 = new ItemC();
private final ItemD i4 = new ItemD();
private final ItemE i5 = new ItemE();
private final ItemF i6 = new ItemF();
private final ItemG i7 = new ItemG();
private final ItemH i8 = new ItemH();
}
````

View file

@ -0,0 +1,4 @@
Restricts the number of other classes that a class can rely on to 20.
While `ClassDataAbstractionCoupling` limits the number of classes that are instantiated when the class is, this check counts all fields whether they are assigned a value or not.

View file

@ -0,0 +1,14 @@
Restricts class generics parameters to be a single uppercase letter.
Valid:
````
class Deliverator <A> {}
````
Invalid:
````
class Invalidator <a> {}
class Invalidator <BB> {}
class Invalidator <C3> {}
````

View file

@ -0,0 +1,45 @@
Requires the indentation of comments to match the surrounding code.
Valid:
````
/**
* This is okay.
*/
int size = 20;
public foo() {
super();
// this is okay
}
public void foo11() {
CheckUtils
.getFirstNode(new DetailAST())
.getFirstChild()
.getNextSibling();
// this is okay
}
````
Invalid:
````
/**
* This is NOT okay.
*/
int size = 20;
public foo() {
super();
// this is NOT okay
// this is NOT okay
}
public void foo11() {
CheckUtils
.getFirstNode(new DetailAST())
.getFirstChild()
.getNextSibling();
// this is NOT okay
}
````

View file

@ -0,0 +1,20 @@
Checks that the expression with the `if` condition in an `if-then-else` statement is not negated.
Valid:
````
if (isValid()) {
handleValidCondition();
} else {
handleInvalidCondition();
}
````
Invalid:
````
if (!isValid()) {
handleInvalidCondition();
} else {
handleValidCondition();
}
````

View file

@ -0,0 +1,15 @@
> This check cannot be suppressed.
Requires constants (static, final fields) to be all uppercase. Numbers and numbers are permitted but not as the first character.
Valid:
````
private static final int JACK_CARD = 11;
````
Invalid:
````
private static final int ace_card = 1;
private static final int 12_CARD = 12;
````

View file

@ -0,0 +1,2 @@
Exception class constructors must accept parameters for message and/or cause. This check is applied to classes whose name ends with `Exception`.

View file

@ -0,0 +1,26 @@
> This check cannot be suppressed.
Checks that classes which define a covariant equals() method also override method equals(Object).
Valid:
````
class Test {
public boolean equals(Test i) {
return false;
}
public boolean equals(Object i) {
return false;
}
}
````
Invalid:
````
class Test {
public boolean equals(Test i) {
return false;
}
}
````

View file

@ -0,0 +1,36 @@
Restricts the cyclomatic complexity of a method to 5. The cyclomatic complexity is a measure of the number of decision points in a method.
A method with no branches has a complexity of 1. For each `if`, `while`, `do`, `for`, `?:`, `catch`, `switch`, `case`, `&&` and `||` the complexity goes up by 1.
Valid:
````
void isValid(int a, int b, int c) {
// 1
if (a > b) { // +1 = 2
switch (c) { // +1 = 3
case 1: // +1 = 4
break;
case 2: // +1 = 5
break;
}
}
}
````
Invalid:
````
void isInvalid(int a, int b, int c) {
// 1
if (a > b) { // +1 = 2
switch (c) { // +1 = 3
case 1: // +1 = 4
break;
case 2: // +1 = 5
break;
case 3: // +1 = 6
break;
}
}
}
````

View file

@ -0,0 +1,45 @@
Ensure class elements appear in the correct order.
Valid:
````
class Valid {
// static
public static int a;
protected static int b;
static int c;
private static int d;
// instance
public int e;
protected int f;
int g;
private int h;
// constructors
Valid() {}
// methods
void foo() {}
}
````
Invalid:
````
class Invalid {
protected static int b;
public static int a;
private static int d;
public int e;
static int c;
protected int f;
private int h;
void foo() {}
Valid() {}
int g;
}
````

View file

@ -0,0 +1,26 @@
Check that the `default` is after all the `case`s in a `switch` statement.
Valid:
````
switch (a) {
case 1:
break;
case 2:
break;
default:
break;
}
````
Invalid:
````
switch (a) {
case 1:
break;
default:
break;
case 2:
break;
}
````

View file

@ -0,0 +1,11 @@
Judicous use of `@SuppressWarnings("designdorextension")` is recommended for this check.
This check is primarily intended for use in library modules rather than applications.
Classes that are deemed by their designer to be 'designed for extension', must take steps to prevent a subclass from breaking the class's behaviour by overriding methods incorrectly. This can be done through a combination of:
* Defining 'hook' methods with empty implementations that subclasses override to add their own behaviour
* Marking methods that are non-private and non-static as abstract or final
> See the official [Checkstyle documentation](http://checkstyle.sourceforge.net/config_design.html#DesignForExtension) for more details and [Effective Java], 2nd Edition by Josh Bloch: Item 17: Design and document for inheritance or else prohibit it.

View file

@ -0,0 +1,12 @@
Checks that the diamond operator is used where possible.
Valid:
````
Map<Long, String> idTable = new HashMap<>();
````
Invalid:
````
Map<Long, String> idTable = new HashMap<Long, String>();
````

View file

@ -0,0 +1,4 @@
Checks that when an exception is caught, that if it is logged then it is not also re-thrown. Log or throw; one or the other or neither, but not both.
Accepts `java.util.logging.Logger` and `org.slf4j.Logger`.

View file

@ -0,0 +1,15 @@
Checks for empty blocks.
Valid:
````
if (a >b) {
doSomething();
}
````
Invalid:
````
if (a > b) {
}
````

View file

@ -0,0 +1,20 @@
Checks that `catch` blocks are not empty, or are commented with the word `expected` or `ignore`.
Valid:
````
try {
something();
} catch (Exception e) {
// ignore
}
````
Invalid:
````
try {
something();
} catch (Exception e) {
// do nothing
}
````

View file

@ -0,0 +1,12 @@
Checks that there is no padding in an empty `for` loop **initialiser**.
Valid:
````
for (; i < j ; i++) {}
````
Invalid:
````
for ( ; i < j ; i++) {}
````

View file

@ -0,0 +1,12 @@
Checks that there is no padding in an empty `for` loop **iterator**.
Valid:
````
for (Iterator i = list.getIterator(); i.hasNext() ;) {}
````
Invalid:
````
for (Iterator i = list.getIterator(); i.hasNext() ; ) {}
````

View file

@ -0,0 +1,52 @@
Checks that there are blank lines between header, package, import blocks, field, constructors, methods, nested classes, static initialisers and instance initialisers.
Valid:
````
/**
* Licence header.
*/
package net.kemitix.foo;
import ...;
import ...;
class Foo {
private int a;
private int b;
Foo() {}
Foo(int a, int b) {}
int getA() {}
int getB() {}
class Bar {
}
}
````
Invalid:
````
/**
* Licence header.
*/
package net.kemitix.foo;
import ...;
import ...;
class Foo {
private int a;
private int b;
Foo() {}
Foo(int a, int b) {}
int getA() {}
int getB() {}
class Bar {
}
}
````

View file

@ -0,0 +1,12 @@
Checks for empty statements. An empty statement is a standalone semicolon (;).
Valid:
````
doSomething();
````
Invalid:
````
doSomething();;
````

View file

@ -0,0 +1,49 @@
Enums are considered to be of two distinct types: 'Class' or 'Value' enumerations. The distinction being that Class Enumerations have methods (other than `toString()`) defined.
The values defined in the `enum` must match the appropriate pattern:
* Class: `^[A-Z][a-zA-Z0-9]*$`
* Value: `^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$`
The difference being that Class enumerations can't contain underscores but can include lowercase letters (after the first initial capital). Value enumerations can include underscores, but not as the first or second character.
Valid:
````
enum ValidConstants {
ALPHA, BETA;
}
enum ValidClassLike {
Alpha("a"),
Beta("b");
private String name;
ValidClassLike(String name) {
this.name = name;
}
}
````
Invalid:
````
enum InvalidConstants {
alpha, Beta, GAMMA_RAY;
}
enum InvalidClassLike {
alpha("a"),
beta("b");
private String name;
InvalidClassLike(String name) {
this.name = name;
}
}
````

View file

@ -0,0 +1,14 @@
Checks that string literals are on the left side in an `equals()` comparison.
Valid:
````
String nullString = null;
"value".equals(nullString);
````
Invalid:
````
String nullString = null;
nullString.equals("value");
````

View file

@ -0,0 +1,4 @@
> This check cannot be suppressed.
Checks that when a class overrides the `equals()` method, that it also overrides the `hashCode()` method.

View file

@ -0,0 +1,2 @@
Limits the number of executable statements in a method to 30.

View file

@ -0,0 +1,22 @@
Checks that fields are not being explicitly initialised to their already default value.
Valid:
````
class Valid {
private int foo;
private Object bar;
}
````
Invalid:
````
class Invalid {
private int foo = 0;
private Object bar = null;
}
````

View file

@ -0,0 +1,42 @@
Checks that when a `case` in a `switch` statement falls through (i.e. doesn't end with `break;`) that the fall through is documented with a comment.
Valid:
````
switch (i) {
case 0:
i++; // fall through
case 1:
i++;
// falls through
case 2:
case 3:
case 4: { i++ } // fallthrough
case 5:
i++;
/* fallthrou */
case 6:
i++;
break;
}
````
Invalid:
````
switch (i) {
case 0:
i++;
case 1:
i++;
case 2:
case 3:
case 4: { i++ }
case 5:
i++;
case 6:
i++;
break;
}
````

View file

@ -0,0 +1,2 @@
Checks that each file has no more than 2000 lines.

View file

@ -0,0 +1,2 @@
Checks that there are no tab characters in the source files.

View file

@ -0,0 +1,18 @@
Checks that classes which have only private constructors are also declared as `final`. These classes can't be extended by a subclass as they can't call `super()` from their constructors.
Valid:
````
final class Valid {
private Valid() {}
}
````
Invalid:
````
class Invalid {
private Invalid() {}
}
````

View file

@ -0,0 +1,12 @@
Parameters to a method must be `final`.
Valid:
````
void foo(final int a) {}
````
Invalid:
````
void foo(int a) {}
````

View file

@ -0,0 +1,16 @@
Prevents the use of `/* C-style */` comments inside methods.
Valid:
````
void doSomething() {
// a comment
}
````
Invalid:
````
void doSomething() {
/* invalid */
}
````

View file

@ -0,0 +1,13 @@
Prevent the use of a `return` statement in the `finally` block.
Invalid:
````
try {
doSomething();
{ catch (IOException e) {
// log error
} finally (
return true; // invalid
}
````

View file

@ -0,0 +1,12 @@
Prevents declaring a method from returning a wildcard type as its return value.
Valid:
````
<E> List<E> getList() {}
````
Invalid:
````
<E> List<? extends E> getList() {}
````

View file

@ -0,0 +1,13 @@
Checks that the angle brackets around Generics parameters have the correct whitespace padding:
Valid:
````
public void <K, V extends Number> boolean foo(K, V) {}
class name<T1, T2, ..., Tn> {}
OrderedPair<String, Box<Integer>> p;
boolean same = Util.<Integer, String>compare(p1, p2);
Pair<Integer, String> p1 = new Pair<>(1, "apple");
List<T> list = ImmutableList.Builder<T>::new;
sort(list, Comparable::<String>compareTo);
````

View file

@ -0,0 +1,2 @@
Checks that all `*.java` source files begin with the contents of the `LICENSE.txt` file.

View file

@ -0,0 +1,30 @@
Checks that a local variable or parameter in a method doesn't have the same name as a field. Doesn't apply in constructors or setters.
Valid:
````
class Foo {
private int a;
Foo(int a) {
this.a = a;
}
setA(int a) {
this.a = a;
}
}
````
Invalid:
````
class Bar {
private int b;
void baz(int b) {
// ...
}
}
````

View file

@ -0,0 +1,29 @@
Classes that only have static fields or methods should not have a public constructor. This includes the default constructor.
Valid:
````
final class StringUtils {
private Utils() {}
private static int count(chat c, String s) {}
}
class StringUtils {
protected Utils() {
throw new UnsupportedOperationException();
}
private static int count(chat c, String s) {}
}
````
Invalid:
````
class StringUtils {
private static int count(chat c, String s) {}
}
````

View file

@ -0,0 +1,24 @@
Prevent the following types from being in a `catch` statement:
* java.lang.Exception
* java.lang.Throwable
* java.lang.RuntimeException
Valid:
````
try {
doSomething();
} catch (SpecificException e) {
// log
}
````
Invalid:
````
try {
doSomething();
} catch (Exception e) {
// log
}
````

View file

@ -0,0 +1,7 @@
Prevent `import`ing from the `sun.*` packages.
Invalid:
````
import sun.security.provider.Sun;
````

View file

@ -0,0 +1,16 @@
Prevent the following types from being `throw`n:
* java.lang.Exception
* java.lang.Throwable
* java.lang.RuntimeException
Valid:
````
throw new SpecificException("error");
````
Invalid:
````
throw new RuntimeException("boom!");
````

View file

@ -0,0 +1,2 @@
Checks that labels are not used.

View file

@ -0,0 +1,28 @@
Prevents use of implementation classes as variables, parameters or method returns. Use the interfaces instead.
Prevents variables, parameters and method returns from being any of the following:
* java.util.ArrayDeque
* java.util.ArrayList
* java.util.EnumMap
* java.util.EnumSet
* java.util.HashMap
* java.util.HashSet
* java.util.IdentityHashMap
* java.util.LinkedHashMap
* java.util.LinkedHashSet
* java.util.LinkedList
* java.util.PriorityQueue
* java.util.TreeMap
* java.util.TreeSet
Valid:
````
Set<String> getNames();
````
Invalid:
````
HashSet<String> getNames();
````

View file

@ -0,0 +1,13 @@
Checks for assignments within an expressions. However, it still allows assignment in a while loop clause.
Valid:
````
while((line = reader.readLine()) != null) {
}
````
Invalid:
````
String s = Integer.toString(i = 2);
````

View file

@ -0,0 +1,2 @@
Inner classes must appear at the bottom of a class, below fields and methods.

View file

@ -0,0 +1,20 @@
An `interface` must define methods, not just constants.
Valid:
````
interface Foo {
static final String "Foo!!";
getBar();
}
````
Invalid:
````
interface Foo {
static final String "Foo!!";
}
````

View file

@ -0,0 +1,12 @@
Checks that the type parameters for an interface are a single uppercase letter.
Valid:
````
interface <T> Portable {}
````
Invalid:
````
interface <Type> Portable {}
````

View file

@ -0,0 +1,4 @@
Restricts the NCSS score for methods, classes and files to 40, 1200 and 1600 respectively. The NCSS score is a measure of the number of statements within a scope.
Too high an NCSS score suggests that the method or class is doing too much and should be decomposed into smaller units.

View file

@ -0,0 +1,2 @@
Checks that all public, protected and package methods have a Javadoc block, that all `@throws` tags are used. Basic setters and getters do not require javadoc.

View file

@ -0,0 +1,2 @@
Checks that each package has a `package-info.java` file.

View file

@ -0,0 +1,2 @@
Checks that paragraphs in Javadoc blocks are wrapped in `<p>` elements and have blank lines between paragraphs. This first paragraph does not need the `<p>` elements.

View file

@ -0,0 +1,2 @@
Checks the formatting of the Javadoc blocks. See the official [Checkstyle documentation](http://checkstyle.sourceforge.net/config_javadoc.html#JavadocStyle) for all the checks that are applied.

View file

@ -0,0 +1,2 @@
Checks the format for Javadoc for classes and enums. Javadoc must be present, not have any unknown tags and not missing any `@param` tags. The `@author` tag must have a name and, in brackets, an email address.

View file

@ -0,0 +1,16 @@
Checks that the left curly brace ('{') is placed at the end of the line. Does not check enums.
Valid:
````
class Foo {
}
````
Invalid:
````
class Bar
{
}
````

View file

@ -0,0 +1,4 @@
Limits the line length to 120 characters.
Doesn't check package or import lines.

View file

@ -0,0 +1,4 @@
Checks the format of local, `final` variable names, including `catch` parameters.
Identifiers must match `^[a-z][a-zA-Z0-9]*$`.

View file

@ -0,0 +1,4 @@
Checks the format of local, non-`final` variable names.
Identifiers must match `^[a-z][a-zA-Z0-9]*$`.

View file

@ -0,0 +1,12 @@
Prevent the placement of variables or fields after methods in an expression.
Valid:
````
if (property && getProperty()) {}
````
Invalid:
````
if (getProperty() && property) {}
````

View file

@ -0,0 +1,15 @@
Checks that numeric literals are defined as constants. Being constants they then have a name that aids in making them non-magical.
The numbers -1, 0, 1 and 2 are not considered to be magical.
Valid:
````
static final int SECONDS_PER_DAY = 24 * 60 * 60;
static final Border STANDARD_BORDER = BorderFactory.createEmptyBorder(3, 3, 3, 3);
````
Invalid
````
String item = getItem(200);
````

Some files were not shown because too many files have changed in this diff Show more