Rules for checkstyle. Share rules among projects.
The rules are based on the default Sun checks, with some modifications.
You can configure the maven-checkstyle-plugin in this way:
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.45.1</version>
</dependency>
<dependency>
<groupId>com.github.ngeor</groupId>
<artifactId>checkstyle-rules</artifactId>
<version>4.9.3</version>
</dependency>
</dependencies>
<configuration>
<configLocation>com/github/ngeor/checkstyle.xml</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
</plugin>
</build>
Rule | Status |
---|---|
AnnotationLocation | Not Used |
AnnotationOnSameLine | Not Used |
AnnotationUseStyle | Not Used |
MissingDeprecated | Not Used |
MissingOverride | Not Used |
PackageAnnotation | Not Used |
SuppressWarnings | Not Used |
SuppressWarningsHolder | Used |
Rule | Status |
---|---|
AvoidNestedBlocks | Used |
EmptyBlock | Used |
EmptyCatchBlock | Not Used |
LeftCurly | Used |
NeedBraces | Used |
RightCurly | Used |
Rule | Status |
---|---|
DesignForExtension | Disabled |
FinalClass | Used |
HideUtilityClassConstructor | Used |
InnerTypeLast | Not Used |
InterfaceIsType | Used |
MutableException | Not Used |
OneTopLevelClass | Enabled |
ThrowsCount | Not Used |
VisibilityModifier | Used |
Rule | Status |
---|---|
ArrayTrailingComma | Not Used |
AvoidInlineConditionals | Disabled |
CovariantEquals | Enabled |
DeclarationOrder | Enabled |
DefaultComesLast | Enabled |
EmptyStatement | Used |
EqualsAvoidNull | Enabled |
EqualsHashCode | Used |
ExplicitInitialization | Enabled |
FallThrough | Enabled |
FinalLocalVariable | Not Used |
HiddenField | Altered |
IllegalCatch | Enabled |
IllegalInstantiation | Used |
IllegalThrows | Enabled |
IllegalToken | Not Used |
IllegalTokenText | Not Used |
IllegalType | Enabled |
InnerAssignment | Used |
MagicNumber | Altered |
MissingCtor | Not Used |
MissingSwitchDefault | Used |
ModifiedControlVariable | Enabled |
MultipleStringLiterals | Not Used |
MultipleVariableDeclarations | Enabled |
NestedForDepth | Enabled |
NestedIfDepth | Enabled |
NestedTryDepth | Enabled |
NoClone | Enabled |
NoFinalizer | Enabled |
OneStatementPerLine | Enabled |
OverloadMethodsDeclarationOrder | Enabled |
PackageDeclaration | Enabled |
ParameterAssignment | Enabled |
RequireThis | Not Used |
ReturnCount | Not Used |
SimplifyBooleanExpression | Used |
SimplifyBooleanReturn | Used |
StringLiteralEquality | Enabled |
SuperClone | Not Used |
SuperFinalize | Not Used |
UnnecessaryParentheses | Enabled |
UnnecessarySemicolonAfterTypeMemberDeclaration | Not Used |
UnnecessarySemicolonInEnumeration | Not Used |
UnnecessarySemicolonInTryWithResources | Not Used |
VariableDeclarationUsageDistance | Not Used |
HiddenField
- ignoreConstructorParameter set to true
- ignoreSetter set to true
Allows magic numbers in hash code, field declarations and annotations.
Rule | Status |
---|---|
Header | Disabled |
RegexpHeader | Not Used |
Rule | Status |
---|---|
AvoidStarImport | Not Used |
AvoidStaticImport | Not Used |
CustomImportOrder | Not Used |
IllegalImport | Used |
ImportControl | Not Used |
ImportOrder | Altered |
RedundantImport | Used |
UnusedImports | Used |
Matches Palantir style:
- All static imports in one group, alphabetically sorted
- One line separator
- All non-static imports in one group, alphabetically sorted
Rule | Status |
---|---|
AtclauseOrder | Not Used |
InvalidJavadocPosition | Not Used |
JavadocBlockTagLocation | Not Used |
JavadocMethod | Not Used |
JavadocPackage | Not Used |
JavadocParagraph | Not Used |
JavadocStyle | Used |
JavadocTagContinuationIndentation | Not Used |
JavadocType | Not Used |
JavadocVariable | Not Used |
MissingJavadocMethod | Not Used |
MissingJavadocPackage | Not Used |
MissingJavadocType | Not Used |
NonEmptyAtclauseDescription | Not Used |
SingleLineJavadoc | Not Used |
SummaryJavadoc | Not Used |
WriteTag | Not Used |
Rule | Status |
---|---|
BooleanExpressionComplexity | Not Used |
ClassDataAbstractionCoupling | Not Used |
ClassFanOutComplexity | Not Used |
CyclomaticComplexity | Not Used |
JavaNCSS | Not Used |
NPathComplexity | Not Used |
Rule | Status |
---|---|
ArrayTypeStyle | Used |
AvoidEscapedUnicodeCharacters | Not Used |
CommentsIndentation | Enabled |
DescendantToken | Not Used |
FinalParameters | Disabled |
Indentation | Enabled |
NewlineAtEndOfFile | Used |
OrderedProperties | Not Used |
OuterTypeFilename | Enabled |
TodoComment | Disabled |
TrailingComment | Not Used |
Translation | Used |
UncommentedMain | Not Used |
UniqueProperties | Not Used |
UpperEll | Used |
Rule | Status |
---|---|
ClassMemberImpliedModifier | Not Used |
InterfaceMemberImpliedModifier | Not Used |
ModifierOrder | Used |
RedundantModifier | Used |
Rule | Status |
---|---|
AbbreviationAsWordInName | Not Used |
AbstractClassName | Not Used |
CatchParameterName | Not Used |
ClassTypeParameterName | Not Used |
ConstantName | Used |
InterfaceTypeParameterName | Not Used |
LambdaParameterName | Not Used |
LocalFinalVariableName | Used |
LocalVariableName | Used |
MemberName | Used |
MethodName | Altered |
MethodTypeParameterName | Not Used |
PackageName | Altered |
ParameterName | Used |
StaticVariableName | Used |
TypeName | Used |
Using Google flavor to permit underscore in test method names:
^[a-z][a-z0-9][a-zA-Z0-9_]*$"
Limited to lowercase letters and numbers: ^[a-z]+(\.[a-z][a-z0-9]*)*$
Rule | Status |
---|---|
Regexp | Not Used |
RegexpMultiline | Not Used |
RegexpOnFilename | Not Used |
RegexpSingleline | Altered |
RegexpSinglelineJava | Not Used |
Verifies that lines do not have trailing spaces.
Rule | Status |
---|---|
AnonInnerLength | Not Used |
ExecutableStatementCount | Not Used |
FileLength | Used |
LineLength | Altered increased to 120 characters |
MethodCount | Not Used |
MethodLength | Used |
OuterTypeNumber | Not Used |
ParameterNumber | Used |
Rule | Status |
---|---|
EmptyForInitializerPad | Not Used |
EmptyForIteratorPad | Used |
EmptyLineSeparator | Altered |
FileTabCharacter | Used |
GenericWhitespace | Used |
MethodParamPad | Used |
NoLineWrap | Not Used |
NoWhitespaceAfter | Used |
NoWhitespaceBefore | Used |
OperatorWrap | Used |
ParenPad | Used |
SeparatorWrap | Not Used |
SingleSpaceSeparator | Not Used |
TypecastParenPad | Used |
WhitespaceAfter | Used |
WhitespaceAround | Altered |
- allowNoEmptyLineBetweenFields set to true
- allowMultipleEmptyLines set to false
- allows empty constructor bodies
- allows empty methods
- allows empty class, interface and enum bodies
It is possible to specify an
XML file with suppressions.
The file is optional and it needs to be in checkstyle/suppressions.xml
.
Example file to ignore magic numbers and multiple string literals in unit tests:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.0//EN"
"http://checkstyle.sourceforge.net/dtds/suppressions_1_0.dtd">
<suppressions>
<suppress files="Test.java$" checks="MagicNumber" />
<suppress files="Test.java$" checks="MultipleStringLiterals" />
</suppressions>
It is also possible to suppress violations using the @SuppressWarnings
annotation.