commit
0169b1d608
199 changed files with 6732 additions and 569 deletions
5
.travis.yml
Normal file
5
.travis.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
language: java
|
||||||
|
jdk:
|
||||||
|
- oraclejdk8
|
||||||
|
after_success:
|
||||||
|
- mvn --projects builder clean test jacoco:report coveralls:report
|
|
@ -1,4 +1,4 @@
|
||||||
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2016 Paul Campbell
|
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,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
|
*/
|
23
builder/LICENSE.txt
Normal file
23
builder/LICENSE.txt
Normal 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
130
builder/pom.xml
Normal 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>
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
|
@ -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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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<>();
|
||||||
|
}
|
|
@ -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,
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -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,
|
||||||
|
}
|
|
@ -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<>();
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
138
builder/src/main/resources/README-template.md
Normal file
138
builder/src/main/resources/README-template.md
Normal 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
|
1490
builder/src/main/resources/application.yml
Normal file
1490
builder/src/main/resources/application.yml
Normal file
File diff suppressed because it is too large
Load diff
15
builder/src/main/resources/checkstyle-template.xml
Normal file
15
builder/src/main/resources/checkstyle-template.xml
Normal 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 -->
|
12
builder/src/main/resources/rules/AbbreviationAsWordInName.md
Normal file
12
builder/src/main/resources/rules/AbbreviationAsWordInName.md
Normal 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 {}
|
||||||
|
````
|
12
builder/src/main/resources/rules/AbstractClassName.md
Normal file
12
builder/src/main/resources/rules/AbstractClassName.md
Normal 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 {}
|
||||||
|
````
|
1
builder/src/main/resources/rules/AnnonInnerLength.md
Normal file
1
builder/src/main/resources/rules/AnnonInnerLength.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Anonymous inner classes should be no more than 20 lines.
|
20
builder/src/main/resources/rules/AnnotationLocation.md
Normal file
20
builder/src/main/resources/rules/AnnotationLocation.md
Normal 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 {}
|
||||||
|
````
|
15
builder/src/main/resources/rules/AnnotationUseStyle.md
Normal file
15
builder/src/main/resources/rules/AnnotationUseStyle.md
Normal 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")
|
||||||
|
````
|
2
builder/src/main/resources/rules/AnonInnerLength.md
Normal file
2
builder/src/main/resources/rules/AnonInnerLength.md
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
Anonymous inner classes should be no more than 20 lines.
|
12
builder/src/main/resources/rules/ArrayTypeStyle.md
Normal file
12
builder/src/main/resources/rules/ArrayTypeStyle.md
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
Enforces Java style arrays.
|
||||||
|
|
||||||
|
Valid:
|
||||||
|
````
|
||||||
|
public static void main(String[] args) {}
|
||||||
|
````
|
||||||
|
|
||||||
|
Invalid:
|
||||||
|
````
|
||||||
|
public static void main(String args[]) {}
|
||||||
|
````
|
20
builder/src/main/resources/rules/AtclauseOrder.md
Normal file
20
builder/src/main/resources/rules/AtclauseOrder.md
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
|
||||||
|
Javadoc `@` clauses must be in the order:
|
||||||
|
|
||||||
|
````
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param ...
|
||||||
|
* @author ...
|
||||||
|
* @version ...
|
||||||
|
* @serial ...
|
||||||
|
* @return ...
|
||||||
|
* @throws ...
|
||||||
|
* @exception ...
|
||||||
|
* @serialData ...
|
||||||
|
* @serialField ...
|
||||||
|
* @see ...
|
||||||
|
* @since ...
|
||||||
|
* @deprecated ...
|
||||||
|
*/
|
||||||
|
````
|
|
@ -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) {}
|
||||||
|
````
|
|
@ -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";
|
||||||
|
````
|
|
@ -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();
|
||||||
|
}
|
||||||
|
````
|
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
Prevents use of the `?:` operators.
|
17
builder/src/main/resources/rules/AvoidNestedBlocks.md
Normal file
17
builder/src/main/resources/rules/AvoidNestedBlocks.md
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
|
||||||
|
Avoid unnecessary blocks.
|
||||||
|
|
||||||
|
Valid:
|
||||||
|
````
|
||||||
|
if (isDebug()) {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
````
|
||||||
|
|
||||||
|
Invalid:
|
||||||
|
````
|
||||||
|
// if (isDebug())
|
||||||
|
{
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
````
|
|
@ -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())) {}
|
||||||
|
````
|
10
builder/src/main/resources/rules/AvoidStarImport.md
Normal file
10
builder/src/main/resources/rules/AvoidStarImport.md
Normal 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.*;
|
||||||
|
````
|
19
builder/src/main/resources/rules/AvoidStaticImport.md
Normal file
19
builder/src/main/resources/rules/AvoidStaticImport.md
Normal 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;
|
||||||
|
````
|
|
@ -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) {}
|
||||||
|
````
|
29
builder/src/main/resources/rules/CatchParameterName.md
Normal file
29
builder/src/main/resources/rules/CatchParameterName.md
Normal 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) {}
|
||||||
|
````
|
|
@ -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();
|
||||||
|
}
|
||||||
|
````
|
|
@ -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.
|
14
builder/src/main/resources/rules/ClassTypeParameterName.md
Normal file
14
builder/src/main/resources/rules/ClassTypeParameterName.md
Normal 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> {}
|
||||||
|
````
|
45
builder/src/main/resources/rules/CommentsIndentation.md
Normal file
45
builder/src/main/resources/rules/CommentsIndentation.md
Normal 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
|
||||||
|
}
|
||||||
|
````
|
20
builder/src/main/resources/rules/ConfusingCondition.md
Normal file
20
builder/src/main/resources/rules/ConfusingCondition.md
Normal 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();
|
||||||
|
}
|
||||||
|
````
|
15
builder/src/main/resources/rules/ConstantName.md
Normal file
15
builder/src/main/resources/rules/ConstantName.md
Normal 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;
|
||||||
|
````
|
|
@ -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`.
|
26
builder/src/main/resources/rules/CovariantEquals.md
Normal file
26
builder/src/main/resources/rules/CovariantEquals.md
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
````
|
36
builder/src/main/resources/rules/CyclomaticComplexity.md
Normal file
36
builder/src/main/resources/rules/CyclomaticComplexity.md
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
````
|
45
builder/src/main/resources/rules/DeclarationOrder.md
Normal file
45
builder/src/main/resources/rules/DeclarationOrder.md
Normal 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;
|
||||||
|
}
|
||||||
|
````
|
26
builder/src/main/resources/rules/DefaultComesLast.md
Normal file
26
builder/src/main/resources/rules/DefaultComesLast.md
Normal 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;
|
||||||
|
}
|
||||||
|
````
|
11
builder/src/main/resources/rules/DesignForExtension.md
Normal file
11
builder/src/main/resources/rules/DesignForExtension.md
Normal 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.
|
|
@ -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>();
|
||||||
|
````
|
4
builder/src/main/resources/rules/EitherLogOrThrow.md
Normal file
4
builder/src/main/resources/rules/EitherLogOrThrow.md
Normal 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`.
|
15
builder/src/main/resources/rules/EmptyBlock.md
Normal file
15
builder/src/main/resources/rules/EmptyBlock.md
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
|
||||||
|
Checks for empty blocks.
|
||||||
|
|
||||||
|
Valid:
|
||||||
|
````
|
||||||
|
if (a >b) {
|
||||||
|
doSomething();
|
||||||
|
}
|
||||||
|
````
|
||||||
|
|
||||||
|
Invalid:
|
||||||
|
````
|
||||||
|
if (a > b) {
|
||||||
|
}
|
||||||
|
````
|
20
builder/src/main/resources/rules/EmptyCatchBlock.md
Normal file
20
builder/src/main/resources/rules/EmptyCatchBlock.md
Normal 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
|
||||||
|
}
|
||||||
|
````
|
12
builder/src/main/resources/rules/EmptyForInitializerPad.md
Normal file
12
builder/src/main/resources/rules/EmptyForInitializerPad.md
Normal 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++) {}
|
||||||
|
````
|
12
builder/src/main/resources/rules/EmptyForIteratorPad.md
Normal file
12
builder/src/main/resources/rules/EmptyForIteratorPad.md
Normal 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() ; ) {}
|
||||||
|
````
|
52
builder/src/main/resources/rules/EmptyLineSeparator.md
Normal file
52
builder/src/main/resources/rules/EmptyLineSeparator.md
Normal 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 {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
````
|
12
builder/src/main/resources/rules/EmptyStatement.md
Normal file
12
builder/src/main/resources/rules/EmptyStatement.md
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
Checks for empty statements. An empty statement is a standalone semicolon (;).
|
||||||
|
|
||||||
|
Valid:
|
||||||
|
````
|
||||||
|
doSomething();
|
||||||
|
````
|
||||||
|
|
||||||
|
Invalid:
|
||||||
|
````
|
||||||
|
doSomething();;
|
||||||
|
````
|
49
builder/src/main/resources/rules/EnumValueName.md
Normal file
49
builder/src/main/resources/rules/EnumValueName.md
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
````
|
14
builder/src/main/resources/rules/EqualsAvoidNull.md
Normal file
14
builder/src/main/resources/rules/EqualsAvoidNull.md
Normal 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");
|
||||||
|
````
|
4
builder/src/main/resources/rules/EqualsHashCode.md
Normal file
4
builder/src/main/resources/rules/EqualsHashCode.md
Normal 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.
|
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
Limits the number of executable statements in a method to 30.
|
22
builder/src/main/resources/rules/ExplicitInitialization.md
Normal file
22
builder/src/main/resources/rules/ExplicitInitialization.md
Normal 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;
|
||||||
|
}
|
||||||
|
````
|
42
builder/src/main/resources/rules/FallThrough.md
Normal file
42
builder/src/main/resources/rules/FallThrough.md
Normal 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;
|
||||||
|
}
|
||||||
|
````
|
2
builder/src/main/resources/rules/FileLength.md
Normal file
2
builder/src/main/resources/rules/FileLength.md
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
Checks that each file has no more than 2000 lines.
|
2
builder/src/main/resources/rules/FileTabCharacter.md
Normal file
2
builder/src/main/resources/rules/FileTabCharacter.md
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
Checks that there are no tab characters in the source files.
|
18
builder/src/main/resources/rules/FinalClass.md
Normal file
18
builder/src/main/resources/rules/FinalClass.md
Normal 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() {}
|
||||||
|
}
|
||||||
|
````
|
12
builder/src/main/resources/rules/FinalParameters.md
Normal file
12
builder/src/main/resources/rules/FinalParameters.md
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
Parameters to a method must be `final`.
|
||||||
|
|
||||||
|
Valid:
|
||||||
|
````
|
||||||
|
void foo(final int a) {}
|
||||||
|
````
|
||||||
|
|
||||||
|
Invalid:
|
||||||
|
````
|
||||||
|
void foo(int a) {}
|
||||||
|
````
|
16
builder/src/main/resources/rules/ForbidCCommentsInMethods.md
Normal file
16
builder/src/main/resources/rules/ForbidCCommentsInMethods.md
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
|
||||||
|
Prevents the use of `/* C-style */` comments inside methods.
|
||||||
|
|
||||||
|
Valid:
|
||||||
|
````
|
||||||
|
void doSomething() {
|
||||||
|
// a comment
|
||||||
|
}
|
||||||
|
````
|
||||||
|
|
||||||
|
Invalid:
|
||||||
|
````
|
||||||
|
void doSomething() {
|
||||||
|
/* invalid */
|
||||||
|
}
|
||||||
|
````
|
|
@ -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
|
||||||
|
}
|
||||||
|
````
|
|
@ -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() {}
|
||||||
|
````
|
13
builder/src/main/resources/rules/GenericWhitespace.md
Normal file
13
builder/src/main/resources/rules/GenericWhitespace.md
Normal 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);
|
||||||
|
````
|
2
builder/src/main/resources/rules/Header.md
Normal file
2
builder/src/main/resources/rules/Header.md
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
Checks that all `*.java` source files begin with the contents of the `LICENSE.txt` file.
|
30
builder/src/main/resources/rules/HiddenField.md
Normal file
30
builder/src/main/resources/rules/HiddenField.md
Normal 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) {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
````
|
|
@ -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) {}
|
||||||
|
}
|
||||||
|
````
|
24
builder/src/main/resources/rules/IllegalCatch.md
Normal file
24
builder/src/main/resources/rules/IllegalCatch.md
Normal 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
|
||||||
|
}
|
||||||
|
````
|
7
builder/src/main/resources/rules/IllegalImport.md
Normal file
7
builder/src/main/resources/rules/IllegalImport.md
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
|
||||||
|
Prevent `import`ing from the `sun.*` packages.
|
||||||
|
|
||||||
|
Invalid:
|
||||||
|
````
|
||||||
|
import sun.security.provider.Sun;
|
||||||
|
````
|
16
builder/src/main/resources/rules/IllegalThrows.md
Normal file
16
builder/src/main/resources/rules/IllegalThrows.md
Normal 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!");
|
||||||
|
````
|
2
builder/src/main/resources/rules/IllegalToken.md
Normal file
2
builder/src/main/resources/rules/IllegalToken.md
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
Checks that labels are not used.
|
28
builder/src/main/resources/rules/IllegalType.md
Normal file
28
builder/src/main/resources/rules/IllegalType.md
Normal 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();
|
||||||
|
````
|
13
builder/src/main/resources/rules/InnerAssignment.md
Normal file
13
builder/src/main/resources/rules/InnerAssignment.md
Normal 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);
|
||||||
|
````
|
2
builder/src/main/resources/rules/InnerTypeLast.md
Normal file
2
builder/src/main/resources/rules/InnerTypeLast.md
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
Inner classes must appear at the bottom of a class, below fields and methods.
|
20
builder/src/main/resources/rules/InterfaceIsType.md
Normal file
20
builder/src/main/resources/rules/InterfaceIsType.md
Normal 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!!";
|
||||||
|
}
|
||||||
|
````
|
|
@ -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 {}
|
||||||
|
````
|
4
builder/src/main/resources/rules/JavaNCSS.md
Normal file
4
builder/src/main/resources/rules/JavaNCSS.md
Normal 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.
|
2
builder/src/main/resources/rules/JavadocMethod.md
Normal file
2
builder/src/main/resources/rules/JavadocMethod.md
Normal 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.
|
2
builder/src/main/resources/rules/JavadocPackage.md
Normal file
2
builder/src/main/resources/rules/JavadocPackage.md
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
Checks that each package has a `package-info.java` file.
|
2
builder/src/main/resources/rules/JavadocParagraph.md
Normal file
2
builder/src/main/resources/rules/JavadocParagraph.md
Normal 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.
|
2
builder/src/main/resources/rules/JavadocStyle.md
Normal file
2
builder/src/main/resources/rules/JavadocStyle.md
Normal 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.
|
2
builder/src/main/resources/rules/JavadocType.md
Normal file
2
builder/src/main/resources/rules/JavadocType.md
Normal 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.
|
16
builder/src/main/resources/rules/LeftCurly.md
Normal file
16
builder/src/main/resources/rules/LeftCurly.md
Normal 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
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
````
|
4
builder/src/main/resources/rules/LineLength.md
Normal file
4
builder/src/main/resources/rules/LineLength.md
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
Limits the line length to 120 characters.
|
||||||
|
|
||||||
|
Doesn't check package or import lines.
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
Checks the format of local, `final` variable names, including `catch` parameters.
|
||||||
|
|
||||||
|
Identifiers must match `^[a-z][a-zA-Z0-9]*$`.
|
4
builder/src/main/resources/rules/LocalVariableName.md
Normal file
4
builder/src/main/resources/rules/LocalVariableName.md
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
Checks the format of local, non-`final` variable names.
|
||||||
|
|
||||||
|
Identifiers must match `^[a-z][a-zA-Z0-9]*$`.
|
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
Prevent the placement of variables or fields after methods in an expression.
|
||||||
|
|
||||||
|
Valid:
|
||||||
|
````
|
||||||
|
if (property && getProperty()) {}
|
||||||
|
````
|
||||||
|
|
||||||
|
Invalid:
|
||||||
|
````
|
||||||
|
if (getProperty() && property) {}
|
||||||
|
````
|
15
builder/src/main/resources/rules/MagicNumber.md
Normal file
15
builder/src/main/resources/rules/MagicNumber.md
Normal 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
Loading…
Reference in a new issue