diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..196244c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: java +jdk: + - oraclejdk8 +after_success: + - mvn --projects builder clean test jacoco:report coveralls:report diff --git a/LICENSE.md b/LICENSE.txt similarity index 99% rename from LICENSE.md rename to LICENSE.txt index a012f4a..00c515a 100644 --- a/LICENSE.md +++ b/LICENSE.txt @@ -1,4 +1,4 @@ - +/* The MIT License (MIT) Copyright (c) 2016 Paul Campbell @@ -20,3 +20,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ diff --git a/README.md b/README.md index 096d9b6..919171e 100644 --- a/README.md +++ b/README.md @@ -26,263 +26,280 @@ To use this ruleset in your `maven-checkstyle-plugin` configuration add `checkst 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. + ```` - 7.0 - 1.21.0 - 0.1.1 + 2.17 + 7.3 + 1.22.0 + 2.0.0 + 5-complexity - + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${maven.checkstyle.plugin.version} + + + com.puppycrawl.tools + checkstyle + ${checkstyle.version} + + + com.github.sevntu.checkstyle + sevntu-checkstyle-maven-plugin + ${sevntu-checkstyle-maven-plugin.version} + + + net.kemitix + kemitix-checkstyle-ruleset + ${kemitix-checkstyle-ruleset.version} + + + + net/kemitix/checkstyle-${kemitix-checkstyle-ruleset.level}.xml + + + + org.apache.maven.plugins maven-checkstyle-plugin - - - com.puppycrawl.tools - checkstyle - ${checkstyle.version} - - - com.github.sevntu.checkstyle - sevntu-checkstyle-maven-plugin - ${sevntu-checkstyle-maven-plugin.version} - - - net.kemitix - kemitix-checkstyle-ruleset - ${kemitix-checkstyle-ruleset.version} - - - net/kemitix/checkstyle.xml - - + + + validate + validate + + check + checkstyle + + + - - - - org.apache.maven.plugins - maven-checkstyle-plugin - - - validate - validate - - check - checkstyle - - - - - + + + + sevntu-maven + sevntu-maven + http://sevntu-checkstyle.github.io/sevntu.checkstyle/maven2 + + ```` ## All Checks -* [AbbreviationAsWordInName](#abbreviationaswordinname) - checkstyle - enabled -* [AbstractClassName](#abstractclassname) - checkstyle - enabled -* [AnnotationLocation](#annotationlocation) - checkstyle - enabled -* [AnnotationUseStyle](#annotationusestyle) - checkstyle - enabled -* [AnonInnerLength](#anoninnerlength) - checkstyle - enabled -* [ArrayTrailingComma](#arraytrailingcomma) - checkstyle - disabled -* [ArrayTypeStyle](#arraytypestyle) - checkstyle - enabled -* [AtclauseOrder](#atclauseorder) - checkstyle - enabled -* [AvoidConditionInversion](#avoidconditioninversion) - sevntu - disabled -* [AvoidConstantAsFirstOperandInCondition](#avoidconstantasfirstoperandincondition) - sevntu - enabled -* [AvoidDefaultSerializableInInnerClasses](#avoiddefaultserializableininnerclasses) - sevntu - disabled -* [AvoidEscapedUnicodeCharacters](#avoidescapedunicodecharacters) - checkstyle - enabled -* [AvoidHidingCauseException](#avoidhidingcauseexception) - sevntu - enabled -* [AvoidInlineConditionals](#avoidinlineconditionals) - checkstyle - enabled -* [AvoidModifiersForTypes](#avoidmodifiersfortypes) - sevntu - disabled -* [AvoidNestedBlocks](#avoidnestedblocks) - checkstyle - enabled -* [AvoidNotShortCircuitOperatorsForBoolean](#avoidnotshortcircuitoperatorsforboolean) - sevntu - enabled -* [AvoidStarImport](#avoidstarimport) - checkstyle - enabled -* [AvoidStaticImport](#avoidstaticimport) - checkstyle - enabled -* [BooleanExpressionComplexity](#booleanexpressioncomplexity) - checkstyle - enabled -* [CatchParameterName](#catchparametername) - checkstyle - enabled -* [CauseParameterInException](#causeparameterinexception) - sevntu - disabled -* [ChildBlockLength](#childblocklength) - sevntu - disabled -* [ClassDataAbstractionCoupling](#classdataabstractioncoupling) - checkstyle - enabled -* [ClassFanOutComplexity](#classfanoutcomplexity) - checkstyle - enabled -* [ClassTypeParameterName](#classtypeparametername) - checkstyle - enabled -* [CommentsIndentation](#commentsindentation) - checkstyle - enabled -* [ConfusingCondition](#confusingcondition) - sevntu - enabled -* [ConstantName](#constantname) - checkstyle - enabled - insuppressible -* [ConstructorWithoutParams](#constructorwithoutparams) - sevntu - enabled -* [CovariantEquals](#covariantequals) - checkstyle - enabled - insuppressible -* [CustomDeclarationOrder](#customdeclarationorder) - sevntu - disabled -* [CyclomaticComplexity](#cyclomaticcomplexity) - checkstyle - enabled -* [DeclarationOrder](#declarationorder) - checkstyle - enabled -* [DefaultComesLast](#defaultcomeslast) - checkstyle - enabled -* [DesignForExtension](#designforextension) - checkstyle - enabled -* [DiamondOperatorForVariableDefinition](#diamondoperatorforvariabledefinition) - sevntu - enabled -* [EitherLogOrThrow](#eitherlogorthrow) - sevntu - enabled -* [EmptyBlock](#emptyblock) - checkstyle - enabled -* [EmptyCatchBlock](#emptycatchblock) - checkstyle - enabled -* [EmptyForInitializerPad](#emptyforinitializerpad) - checkstyle - enabled -* [EmptyForIteratorPad](#emptyforiteratorpad) - checkstyle - enabled -* [EmptyLineSeparator](#emptylineseparator) - checkstyle - enabled -* [EmptyPublicCtorInClass](#emptypublicctorinclass) - sevntu - disabled -* [EmptyStatement](#emptystatement) - checkstyle - enabled -* [EnumValueName](#enumvaluename) - sevntu - enabled -* [EqualsAvoidNull](#equalsavoidnull) - checkstyle - enabled -* [EqualsHashCode](#equalshashcode) - checkstyle - enabled - insuppressible -* [ExecutableStatementCount](#executablestatementcount) - checkstyle - enabled -* [ExplicitInitialization](#explicitinitialization) - checkstyle - enabled -* [FallThrough](#fallthrough) - checkstyle - enabled -* [FileLength](#filelength) - checkstyle - enabled -* [FileTabCharacter](#filetabcharacter) - checkstyle - enabled -* [FinalClass](#finalclass) - checkstyle - enabled -* [FinalizeImplementation](#finalizeimplementation) - sevntu - disabled -* [FinalLocalVariable](#finallocalvariable) - checkstyle - disabled -* [FinalParameters](#finalparameters) - checkstyle - enabled -* [ForbidAnnotation](#forbidannotation) - sevntu - disabled -* [ForbidCCommentsInMethods](#forbidccommentsinmethods) - sevntu - enabled -* [ForbidCertainImports](#forbidcertainimports) - sevntu - disabled -* [ForbidInstantiation](#forbidinstantiation) - sevntu - disabled -* [ForbidReturnInFinallyBlock](#forbidreturninfinallyblock) - sevntu - enabled -* [ForbidThrowAnonymousExceptions](#forbidthrowanonymousexceptions) - sevntu - disabled -* [ForbidWildcardAsReturnType](#forbidwildcardasreturntype) - sevntu - enabled -* [GenericWhitespace](#genericwhitespace) - checkstyle - enabled -* [Header](#header) - checkstyle - disabled -* [HiddenField](#hiddenfield) - checkstyle - enabled -* [HideUtilityClassConstructor](#hideutilityclassconstructor) - checkstyle - enabled -* [HideUtilityClassConstructor](#hideutilityclassconstructor-1) - sevntu - disabled -* [IllegalCatchExtended](#illegalcatchextended) - sevntu - disabled -* [IllegalCatch](#illegalcatch) - checkstyle - enabled -* [IllegalImport](#illegalimport) - checkstyle - enabled -* [IllegalInstantiation](#illegalinstantiation) - checkstyle - disabled -* [IllegalThrows](#illegalthrows) - checkstyle - enabled -* [IllegalToken](#illegaltoken) - checkstyle - enabled -* [IllegalTokenText](#illegaltokentext) - checkstyle - disabled -* [IllegalType](#illegaltype) - checkstyle - enabled -* [ImportControl](#importcontrol) - checkstyle - disabled -* [ImportOrder](#importorder) - checkstyle - disabled -* [Indentation](#indentation) - checkstyle - disabled -* [InnerAssignment](#innerassignment) - checkstyle - enabled -* [InnerClass](#innerclass) - sevntu - disabled -* [InnerTypeLast](#innertypelast) - checkstyle - enabled -* [InterfaceIsType](#interfaceistype) - checkstyle - enabled -* [InterfaceTypeParameterName](#interfacetypeparametername) - checkstyle - enabled -* [InterfaceTypeParameterName](#interfacetypeparametername-1) - sevntu - disabled -* [JavadocMethod](#javadocmethod) - checkstyle - enabled -* [JavadocPackage](#javadocpackage) - checkstyle - enabled -* [JavadocParagraph](#javadocparagraph) - checkstyle - enabled -* [JavadocStyle](#javadocstyle) - checkstyle - enabled -* [JavadocTagContinuationIndentation](#javadoctagcontinuationindentation) - checkstyle - disabled -* [JavadocType](#javadoctype) - checkstyle - enabled -* [JavadocVariable](#javadocvariable) - checkstyle - disabled -* [JavaNCSS](#javancss) - checkstyle - enabled -* [LeftCurly](#leftcurly) - checkstyle - enabled -* [LineLengthExtended](#linelengthextended) - sevntu - disabled -* [LineLength](#linelength) - checkstyle - enabled -* [LocalFinalVariableName](#localfinalvariablename) - checkstyle - enabled -* [LocalVariableName](#localvariablename) - checkstyle - enabled -* [LogicConditionNeedOptimization](#logicconditionneedoptimization) - sevntu - enabled -* [MagicNumber](#magicnumber) - checkstyle - enabled -* [MapIterationInForEachLoop](#mapiterationinforeachloop) - sevntu - enabled -* [MemberName](#membername) - checkstyle - enabled -* [MethodCount](#methodcount) - checkstyle - enabled -* [MethodLength](#methodlength) - checkstyle - enabled -* [MethodName](#methodname) - checkstyle - enabled -* [MethodParamPad](#methodparampad) - checkstyle - enabled -* [MethodTypeParameterName](#methodtypeparametername) - checkstyle - enabled -* [MissingCtor](#missingctor) - checkstyle - disabled -* [MissingDeprecated](#missingdeprecated) - checkstyle - enabled -* [MissingOverride](#missingoverride) - checkstyle - disabled -* [MissingSwitchDefault](#missingswitchdefault) - checkstyle - enabled -* [ModifiedControlVariable](#modifiedcontrolvariable) - checkstyle - enabled -* [ModifierOrder](#modifierorder) - checkstyle - enabled -* [MultipleStringLiterals](#multiplestringliterals) - checkstyle - enabled -* [MultipleStringLiteralsExtended](#multiplestringliteralsextended) - sevntu - disabled -* [MultipleVariableDeclarations](#multiplevariabledeclarations) - checkstyle - enabled -* [MultipleVariableDeclarationsExtended](#multiplevariabledeclarationsextended) - sevntu - disabled -* [MutableException](#mutableexception) - checkstyle - enabled -* [NameConventionForJunit4TestClasses](#nameconventionforjunit4testclasses) - sevntu - enabled -* [NeedBraces](#needbraces) - checkstyle - enabled -* [NestedForDepth](#nestedfordepth) - checkstyle - enabled -* [NestedIfDepth](#nestedifdepth) - checkstyle - enabled -* [NestedSwitch](#nestedswitch) - sevntu - enabled -* [NestedTryDepth](#nestedtrydepth) - checkstyle - enabled -* [NewlineAtEndOfFile](#newlineatendoffile) - checkstyle - enabled -* [NoClone](#noclone) - checkstyle - enabled - insuppressible -* [NoFinalizer](#nofinalizer) - checkstyle - enabled -* [NoLineWrap](#nolinewrap) - checkstyle - enabled -* [NoMainMethodInAbstractClass](#nomainmethodinabstractclass) - sevntu - enabled -* [NonEmptyAtclauseDescription](#nonemptyatclausedescription) - checkstyle - enabled -* [NoWhitespaceAfter](#nowhitespaceafter) - checkstyle - enabled -* [NoWhitespaceBefore](#nowhitespacebefore) - checkstyle - enabled -* [NPathComplexity](#npathcomplexity) - checkstyle - enabled -* [NumericLiteralNeedsUnderscore](#numericliteralneedsunderscore) - sevntu - enabled -* [OneStatementPerLine](#onestatementperline) - checkstyle - enabled -* [OneTopLevelClass](#onetoplevelclass) - checkstyle - enabled - insuppressible -* [OperatorWrap](#operatorwrap) - checkstyle - enabled -* [OuterTypeFilename](#outertypefilename) - checkstyle - enabled - insuppressible -* [OuterTypeNumber](#outertypenumber) - checkstyle - disabled -* [OverloadMethodsDeclarationOrder](#overloadmethodsdeclarationorder) - checkstyle - enabled -* [OverridableMethodInConstructor](#overridablemethodinconstructor) - sevntu - enabled -* [PackageAnnotation](#packageannotation) - checkstyle - enabled -* [PackageDeclaration](#packagedeclaration) - checkstyle - enabled - insuppressible -* [PackageName](#packagename) - checkstyle - enabled -* [ParameterAssignment](#parameterassignment) - checkstyle - disabled -* [ParameterName](#parametername) - checkstyle - enabled -* [ParameterNumber](#parameternumber) - checkstyle - enabled -* [ParenPad](#parenpad) - checkstyle - enabled -* [PublicReferenceToPrivateType](#publicreferencetoprivatetype) - sevntu - enabled -* [RedundantImport](#redundantimport) - checkstyle - disabled -* [RedundantModifier](#redundantmodifier) - checkstyle - enabled -* [RedundantReturn](#redundantreturn) - sevntu - enabled -* [Regexp](#regexp) - checkstyle - disabled -* [RegexpHeader](#regexpheader) - checkstyle - disabled -* [RegexpMultiline](#regexpmultiline) - checkstyle - disabled -* [RegexpOnFilename](#regexponfilename) - checkstyle - disabled -* [RegexpSingleline](#regexpsingleline) - checkstyle - disabled -* [RegexpSinglelineJava](#regexpsinglelinejava) - checkstyle - disabled -* [RequiredParameterForAnnotation](#requiredparameterforannotation) - sevntu - disabled -* [RequireThis](#requirethis) - checkstyle - enabled -* [ReturnBooleanFromTernary](#returnbooleanfromternary) - sevntu - enabled -* [ReturnCount](#returncount) - checkstyle - enabled -* [ReturnCountExtended](#returncountextended) - sevntu - disabled -* [ReturnNullInsteadOfBoolean](#returnnullinsteadofboolean) - sevntu - enabled -* [RightCurly](#rightcurly) - checkstyle - enabled -* [SeparatorWrap](#separatorwrap) - checkstyle - enabled -* [SimpleAccessorNameNotation](#simpleaccessornamenotation) - sevntu - enabled -* [SimplifyBooleanExpression](#simplifybooleanexpression) - checkstyle - enabled -* [SimplifyBooleanReturn](#simplifybooleanreturn) - checkstyle - enabled -* [SingleBreakOrContinue](#singlebreakorcontinue) - sevntu - enabled -* [SingleLineJavadoc](#singlelinejavadoc) - checkstyle - disabled -* [SingleSpaceSeparator](#singlespaceseparator) - checkstyle - enabled -* [StaticMethodCandidate](#staticmethodcandidate) - sevntu - disabled -* [StaticVariableName](#staticvariablename) - checkstyle - enabled -* [StringLiteralEquality](#stringliteralequality) - checkstyle - enabled -* [SummaryJavadoc](#summaryjavadoc) - checkstyle - disabled -* [SuperClone](#superclone) - checkstyle - disabled -* [SuperFinalize](#superfinalize) - checkstyle - disabled -* [SuppressWarnings](#suppresswarnings) - checkstyle - enabled -* [SuppressWarningsHolder](#suppresswarningsholder) - checkstyle - enabled -* [TernaryPerExpressionCount](#ternaryperexpressioncount) - sevntu - enabled -* [ThrowsCount](#throwscount) - checkstyle - enabled -* [TodoComment](#todocomment) - checkstyle - enabled -* [TrailingComment](#trailingcomment) - checkstyle - enabled -* [Translation](#translation) - checkstyle - enabled -* [TypecastParenPad](#typecastparenpad) - checkstyle - enabled -* [TypeName](#typename) - checkstyle - enabled - insuppressible -* [UncommentedMain](#uncommentedmain) - checkstyle - enabled -* [UniformEnumConstantName](#uniformenumconstantname) - sevntu - enabled -* [UniqueProperties](#uniqueproperties) - checkstyle - enabled -* [UnnecessaryParentheses](#unnecessaryparentheses) - checkstyle - enabled -* [UnnecessaryParenthesesExtended](#unnecessaryparenthesesextended) - sevntu - disabled -* [UnusedImports](#unusedimports) - checkstyle - enabled -* [UpperEll](#upperell) - checkstyle - enabled -* [UselessSingleCatch](#uselesssinglecatch) - sevntu - enabled -* [UselessSuperCtorCall](#uselesssuperctorcall) - sevntu - enabled -* [VariableDeclarationUsageDistance](#variabledeclarationusagedistance) - checkstyle - enabled -* [VisibilityModifier](#visibilitymodifier) - checkstyle - enabled - insuppressible -* [WhitespaceAfter](#whitespaceafter) - checkstyle - enabled -* [WhitespaceAround](#whitespacearound) - checkstyle - enabled -* [WhitespaceBeforeArrayInitializer](#whitespacebeforearrayinitializer) - sevntu - disabled -* [WriteTag](#writetag) - checkstyle - disabled +Rule|Level|Source|Enabled|Suppressable +----|-----|------|-------|------------ +[AbbreviationAsWordInName](#abbreviationaswordinname)|naming|checkstyle|Yes| +[AbstractClassName](#abstractclassname)|naming|checkstyle|Yes| +[AnnotationLocation](#annotationlocation)|layout|checkstyle|Yes| +[AnnotationUseStyle](#annotationusestyle)|layout|checkstyle|Yes| +[AnonInnerLength](#anoninnerlength)|complexity|checkstyle|Yes| +[ArrayTrailingComma](#arraytrailingcomma)|unspecified|checkstyle|| +[ArrayTypeStyle](#arraytypestyle)|layout|checkstyle|Yes| +[AtclauseOrder](#atclauseorder)|javadoc|checkstyle|Yes| +[AvoidConditionInversion](#avoidconditioninversion)|complexity|sevntu|| +[AvoidConstantAsFirstOperandInCondition](#avoidconstantasfirstoperandincondition)|tweaks|sevntu|Yes| +[AvoidDefaultSerializableInInnerClasses](#avoiddefaultserializableininnerclasses)|complexity|sevntu|| +[AvoidEscapedUnicodeCharacters](#avoidescapedunicodecharacters)|tweaks|checkstyle|Yes| +[AvoidHidingCauseException](#avoidhidingcauseexception)|tweaks|sevntu|Yes| +[AvoidInlineConditionals](#avoidinlineconditionals)|complexity|checkstyle|Yes| +[AvoidModifiersForTypes](#avoidmodifiersfortypes)|unspecified|sevntu|| +[AvoidNestedBlocks](#avoidnestedblocks)|complexity|checkstyle|Yes| +[AvoidNotShortCircuitOperatorsForBoolean](#avoidnotshortcircuitoperatorsforboolean)|tweaks|sevntu|Yes| +[AvoidStarImport](#avoidstarimport)|layout|checkstyle|Yes| +[AvoidStaticImport](#avoidstaticimport)|complexity|checkstyle|Yes| +[BooleanExpressionComplexity](#booleanexpressioncomplexity)|complexity|checkstyle|Yes| +[CatchParameterName](#catchparametername)|naming|checkstyle|Yes| +[CauseParameterInException](#causeparameterinexception)|tweaks|sevntu|| +[ChildBlockLength](#childblocklength)|complexity|sevntu|| +[ClassDataAbstractionCoupling](#classdataabstractioncoupling)|complexity|checkstyle|Yes| +[ClassFanOutComplexity](#classfanoutcomplexity)|complexity|checkstyle|Yes| +[ClassTypeParameterName](#classtypeparametername)|naming|checkstyle|Yes| +[CommentsIndentation](#commentsindentation)|layout|checkstyle|Yes| +[ConfusingCondition](#confusingcondition)|complexity|sevntu|Yes| +[ConstantName](#constantname)|naming|checkstyle|Yes|No +[ConstructorWithoutParams](#constructorwithoutparams)|complexity|sevntu|Yes| +[CovariantEquals](#covariantequals)|complexity|checkstyle|Yes|No +[CustomDeclarationOrder](#customdeclarationorder)|layout|sevntu|| +[CyclomaticComplexity](#cyclomaticcomplexity)|complexity|checkstyle|Yes| +[DeclarationOrder](#declarationorder)|layout|checkstyle|Yes| +[DefaultComesLast](#defaultcomeslast)|tweaks|checkstyle|Yes| +[DesignForExtension](#designforextension)|complexity|checkstyle|Yes| +[DiamondOperatorForVariableDefinition](#diamondoperatorforvariabledefinition)|tweaks|sevntu|Yes| +[EitherLogOrThrow](#eitherlogorthrow)|tweaks|sevntu|Yes| +[EmptyBlock](#emptyblock)|tweaks|checkstyle|Yes| +[EmptyCatchBlock](#emptycatchblock)|tweaks|checkstyle|Yes| +[EmptyForInitializerPad](#emptyforinitializerpad)|layout|checkstyle|Yes| +[EmptyForIteratorPad](#emptyforiteratorpad)|layout|checkstyle|Yes| +[EmptyLineSeparator](#emptylineseparator)|layout|checkstyle|Yes| +[EmptyPublicCtorInClass](#emptypublicctorinclass)|tweaks|sevntu|| +[EmptyStatement](#emptystatement)|layout|checkstyle|Yes| +[EnumValueName](#enumvaluename)|naming|sevntu|Yes| +[EqualsAvoidNull](#equalsavoidnull)|tweaks|checkstyle|Yes| +[EqualsHashCode](#equalshashcode)|complexity|checkstyle|Yes|No +[ExecutableStatementCount](#executablestatementcount)|complexity|checkstyle|Yes| +[ExplicitInitialization](#explicitinitialization)|tweaks|checkstyle|Yes| +[FallThrough](#fallthrough)|javadoc|checkstyle|Yes| +[FileLength](#filelength)|complexity|checkstyle|Yes| +[FileTabCharacter](#filetabcharacter)|layout|checkstyle|Yes| +[FinalClass](#finalclass)|complexity|checkstyle|Yes| +[FinalizeImplementation](#finalizeimplementation)|unspecified|sevntu|| +[FinalLocalVariable](#finallocalvariable)|unspecified|checkstyle|| +[FinalParameters](#finalparameters)|tweaks|checkstyle|Yes| +[ForbidAnnotation](#forbidannotation)|unspecified|sevntu|| +[ForbidCCommentsInMethods](#forbidccommentsinmethods)|layout|sevntu|Yes| +[ForbidCertainImports](#forbidcertainimports)|unspecified|sevntu|| +[ForbidInstantiation](#forbidinstantiation)|unspecified|sevntu|| +[ForbidReturnInFinallyBlock](#forbidreturninfinallyblock)|complexity|sevntu|Yes| +[ForbidThrowAnonymousExceptions](#forbidthrowanonymousexceptions)|tweaks|sevntu|| +[ForbidWildcardAsReturnType](#forbidwildcardasreturntype)|complexity|sevntu|Yes| +[GenericWhitespace](#genericwhitespace)|layout|checkstyle|Yes| +[Header](#header)|layout|checkstyle|Yes| +[HiddenField](#hiddenfield)|tweaks|checkstyle|Yes| +[HideUtilityClassConstructor](#hideutilityclassconstructor)|tweaks|checkstyle|Yes| +[IllegalCatch](#illegalcatch)|tweaks|checkstyle|Yes| +[IllegalImport](#illegalimport)|tweaks|checkstyle|Yes| +[IllegalInstantiation](#illegalinstantiation)|unspecified|checkstyle|| +[IllegalThrows](#illegalthrows)|tweaks|checkstyle|Yes| +[IllegalToken](#illegaltoken)|tweaks|checkstyle|Yes| +[IllegalTokenText](#illegaltokentext)|unspecified|checkstyle|| +[IllegalType](#illegaltype)|tweaks|checkstyle|Yes| +[ImportControl](#importcontrol)|unspecified|checkstyle|| +[ImportOrder](#importorder)|layout|checkstyle|| +[Indentation](#indentation)|layout|checkstyle|| +[InnerAssignment](#innerassignment)|tweaks|checkstyle|Yes| +[InnerTypeLast](#innertypelast)|tweaks|checkstyle|Yes| +[InterfaceIsType](#interfaceistype)|complexity|checkstyle|Yes| +[InterfaceTypeParameterName](#interfacetypeparametername)|naming|checkstyle|Yes| +[JavadocMethod](#javadocmethod)|javadoc|checkstyle|Yes| +[JavadocPackage](#javadocpackage)|javadoc|checkstyle|Yes| +[JavadocParagraph](#javadocparagraph)|javadoc|checkstyle|Yes| +[JavadocStyle](#javadocstyle)|javadoc|checkstyle|Yes| +[JavadocTagContinuationIndentation](#javadoctagcontinuationindentation)|layout|checkstyle|| +[JavadocType](#javadoctype)|javadoc|checkstyle|Yes| +[JavadocVariable](#javadocvariable)|javadoc|checkstyle|| +[JavaNCSS](#javancss)|complexity|checkstyle|Yes| +[LeftCurly](#leftcurly)|layout|checkstyle|Yes| +[LineLength](#linelength)|layout|checkstyle|Yes| +[LocalFinalVariableName](#localfinalvariablename)|naming|checkstyle|Yes| +[LocalVariableName](#localvariablename)|naming|checkstyle|Yes| +[LogicConditionNeedOptimization](#logicconditionneedoptimization)|tweaks|sevntu|Yes| +[MagicNumber](#magicnumber)|naming|checkstyle|Yes| +[MapIterationInForEachLoop](#mapiterationinforeachloop)|complexity|sevntu|Yes| +[MemberName](#membername)|naming|checkstyle|Yes| +[MethodCount](#methodcount)|complexity|checkstyle|Yes| +[MethodLength](#methodlength)|complexity|checkstyle|Yes| +[MethodName](#methodname)|naming|checkstyle|Yes| +[MethodParamPad](#methodparampad)|layout|checkstyle|Yes| +[MethodTypeParameterName](#methodtypeparametername)|naming|checkstyle|Yes| +[MissingCtor](#missingctor)|tweaks|checkstyle|| +[MissingDeprecated](#missingdeprecated)|javadoc|checkstyle|Yes| +[MissingOverride](#missingoverride)|tweaks|checkstyle|| +[MissingSwitchDefault](#missingswitchdefault)|tweaks|checkstyle|Yes| +[ModifiedControlVariable](#modifiedcontrolvariable)|tweaks|checkstyle|Yes| +[ModifierOrder](#modifierorder)|naming|checkstyle|Yes| +[MultipleStringLiterals](#multiplestringliterals)|naming|checkstyle|Yes| +[MultipleVariableDeclarations](#multiplevariabledeclarations)|naming|checkstyle|Yes| +[MutableException](#mutableexception)|tweaks|checkstyle|Yes| +[NameConventionForJunit4TestClasses](#nameconventionforjunit4testclasses)|naming|sevntu|Yes| +[NeedBraces](#needbraces)|naming|checkstyle|Yes| +[NestedForDepth](#nestedfordepth)|complexity|checkstyle|Yes| +[NestedIfDepth](#nestedifdepth)|complexity|checkstyle|Yes| +[NestedSwitch](#nestedswitch)|complexity|sevntu|Yes| +[NestedTryDepth](#nestedtrydepth)|complexity|checkstyle|Yes| +[NewlineAtEndOfFile](#newlineatendoffile)|layout|checkstyle|Yes| +[NoClone](#noclone)|tweaks|checkstyle|Yes|No +[NoFinalizer](#nofinalizer)|tweaks|checkstyle|Yes| +[NoLineWrap](#nolinewrap)|layout|checkstyle|Yes| +[NoMainMethodInAbstractClass](#nomainmethodinabstractclass)|tweaks|sevntu|Yes| +[NonEmptyAtclauseDescription](#nonemptyatclausedescription)|javadoc|checkstyle|Yes| +[NoWhitespaceAfter](#nowhitespaceafter)|layout|checkstyle|Yes| +[NoWhitespaceBefore](#nowhitespacebefore)|layout|checkstyle|Yes| +[NPathComplexity](#npathcomplexity)|complexity|checkstyle|Yes| +[NumericLiteralNeedsUnderscore](#numericliteralneedsunderscore)|naming|sevntu|Yes| +[OneStatementPerLine](#onestatementperline)|layout|checkstyle|Yes| +[OneTopLevelClass](#onetoplevelclass)|tweaks|checkstyle|Yes|No +[OperatorWrap](#operatorwrap)|layout|checkstyle|Yes| +[OuterTypeFilename](#outertypefilename)|tweaks|checkstyle|Yes|No +[OuterTypeNumber](#outertypenumber)|tweaks|checkstyle|| +[OverloadMethodsDeclarationOrder](#overloadmethodsdeclarationorder)|layout|checkstyle|Yes| +[OverridableMethodInConstructor](#overridablemethodinconstructor)|tweaks|sevntu|Yes| +[PackageAnnotation](#packageannotation)|tweaks|checkstyle|Yes| +[PackageDeclaration](#packagedeclaration)|javadoc|checkstyle|Yes|No +[PackageName](#packagename)|naming|checkstyle|Yes| +[ParameterAssignment](#parameterassignment)|tweaks|checkstyle|| +[ParameterName](#parametername)|naming|checkstyle|Yes| +[ParameterNumber](#parameternumber)|complexity|checkstyle|Yes| +[ParenPad](#parenpad)|layout|checkstyle|Yes| +[PublicReferenceToPrivateType](#publicreferencetoprivatetype)|tweaks|sevntu|Yes| +[RedundantImport](#redundantimport)|layout|checkstyle|| +[RedundantModifier](#redundantmodifier)|tweaks|checkstyle|Yes| +[RedundantReturn](#redundantreturn)|tweaks|sevntu|Yes| +[Regexp](#regexp)|unspecified|checkstyle|| +[RegexpHeader](#regexpheader)|unspecified|checkstyle|| +[RegexpMultiline](#regexpmultiline)|unspecified|checkstyle|| +[RegexpOnFilename](#regexponfilename)|unspecified|checkstyle|| +[RegexpSingleline](#regexpsingleline)|unspecified|checkstyle|| +[RegexpSinglelineJava](#regexpsinglelinejava)|unspecified|checkstyle|| +[RequiredParameterForAnnotation](#requiredparameterforannotation)|unspecified|sevntu|| +[RequireThis](#requirethis)|tweaks|checkstyle|Yes| +[ReturnBooleanFromTernary](#returnbooleanfromternary)|tweaks|sevntu|Yes| +[ReturnCount](#returncount)|complexity|checkstyle|Yes| +[ReturnNullInsteadOfBoolean](#returnnullinsteadofboolean)|tweaks|sevntu|Yes| +[RightCurly](#rightcurly)|layout|checkstyle|Yes| +[SeparatorWrap](#separatorwrap)|layout|checkstyle|Yes| +[SimpleAccessorNameNotation](#simpleaccessornamenotation)|naming|sevntu|Yes| +[SimplifyBooleanExpression](#simplifybooleanexpression)|complexity|checkstyle|Yes| +[SimplifyBooleanReturn](#simplifybooleanreturn)|complexity|checkstyle|Yes| +[SingleBreakOrContinue](#singlebreakorcontinue)|tweaks|sevntu|Yes| +[SingleLineJavadoc](#singlelinejavadoc)|javadoc|checkstyle|| +[SingleSpaceSeparator](#singlespaceseparator)|layout|checkstyle|Yes| +[StaticMethodCandidate](#staticmethodcandidate)|unspecified|sevntu|| +[StaticVariableName](#staticvariablename)|naming|checkstyle|Yes| +[StringLiteralEquality](#stringliteralequality)|tweaks|checkstyle|Yes| +[SummaryJavadoc](#summaryjavadoc)|javadoc|checkstyle|| +[SuperClone](#superclone)|tweaks|checkstyle|| +[SuperFinalize](#superfinalize)|tweaks|checkstyle|| +[SuppressWarnings](#suppresswarnings)|naming|checkstyle|Yes| +[SuppressWarningsFilter](#suppresswarningsfilter)|naming|checkstyle|Yes| +[SuppressWarningsHolder](#suppresswarningsholder)|naming|checkstyle|Yes| +[TernaryPerExpressionCount](#ternaryperexpressioncount)|tweaks|sevntu|Yes| +[ThrowsCount](#throwscount)|complexity|checkstyle|Yes| +[TodoComment](#todocomment)|javadoc|checkstyle|Yes| +[TrailingComment](#trailingcomment)|layout|checkstyle|Yes| +[Translation](#translation)|javadoc|checkstyle|Yes| +[TypecastParenPad](#typecastparenpad)|layout|checkstyle|Yes| +[TypeName](#typename)|naming|checkstyle|Yes|No +[UncommentedMain](#uncommentedmain)|javadoc|checkstyle|Yes| +[UniformEnumConstantName](#uniformenumconstantname)|naming|sevntu|Yes| +[UniqueProperties](#uniqueproperties)|javadoc|checkstyle|Yes| +[UnnecessaryParentheses](#unnecessaryparentheses)|layout|checkstyle|Yes| +[UnusedImports](#unusedimports)|layout|checkstyle|Yes| +[UpperEll](#upperell)|layout|checkstyle|Yes| +[UselessSingleCatch](#uselesssinglecatch)|tweaks|sevntu|Yes| +[UselessSuperCtorCall](#uselesssuperctorcall)|tweaks|sevntu|Yes| +[VariableDeclarationUsageDistance](#variabledeclarationusagedistance)|tweaks|checkstyle|Yes| +[VisibilityModifier](#visibilitymodifier)|tweaks|checkstyle|Yes|No +[WhitespaceAfter](#whitespaceafter)|layout|checkstyle|Yes| +[WhitespaceAround](#whitespacearound)|layout|checkstyle|Yes| +[WhitespaceBeforeArrayInitializer](#whitespacebeforearrayinitializer)|layout|sevntu|| +[WriteTag](#writetag)|unspecified|checkstyle|| ## Enabled Checks @@ -305,7 +322,6 @@ Invalid: ```` class DAOManager {} ```` - #### [AbstractClassName](http://checkstyle.sourceforge.net/config_naming.html#AbstractClassName) The name of an `abstract` class must start with `Abstract`. Classes that start with `Abstract` must be `abstract`. @@ -319,7 +335,6 @@ Invalid: ```` abstract class BaseCardHand implements CardHand {} ```` - #### [AnnotationLocation](http://checkstyle.sourceforge.net/config_annotation.html#AnnotationLocation) Annotations must be on a line by themselves unless annotating a method parameter or among class modifiers. @@ -341,7 +356,6 @@ Invalid: @Component @Qualifier("Red") class RedStick implements Stick {} ```` - #### [AnnotationUseStyle](http://checkstyle.sourceforge.net/config_annotation.html#AnnotationUseStyle) 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. @@ -358,11 +372,9 @@ Invalid: @Entity() @Table(value = "names") ```` - #### [AnonInnerLength](http://checkstyle.sourceforge.net/config_sizes.html#AnonInnerLength) Anonymous inner classes should be no more than 20 lines. - #### [ArrayTypeStyle](http://checkstyle.sourceforge.net/config_misc.html#ArrayTypeStyle) Enforces Java style arrays. @@ -376,7 +388,6 @@ Invalid: ```` public static void main(String args[]) {} ```` - #### [AtclauseOrder](http://checkstyle.sourceforge.net/config_javadoc.html#AtclauseOrder) Javadoc `@` clauses must be in the order: @@ -398,7 +409,6 @@ Javadoc `@` clauses must be in the order: * @deprecated ... */ ```` - #### [AvoidEscapedUnicodeCharacters](http://checkstyle.sourceforge.net/config_misc.html#AvoidEscapedUnicodeCharacters) Prevents use of obscure escape codes (e.g. `\u221e`). However, non-printable/control characters are still permitted. @@ -413,11 +423,9 @@ Invalid: ```` String unitAbbrev = "\u03bcs"; ```` - #### [AvoidInlineConditionals](http://checkstyle.sourceforge.net/config_coding.html#AvoidInlineConditionals) Prevents use of the `?:` operators. - #### [AvoidNestedBlocks](http://checkstyle.sourceforge.net/config_blocks.html#AvoidNestedBlocks) Avoid unnecessary blocks. @@ -436,7 +444,6 @@ Invalid: // ... } ```` - #### [AvoidStarImport](http://checkstyle.sourceforge.net/config_imports.html#AvoidStarImport) Prevents the use of the star import. @@ -448,7 +455,6 @@ import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; ```` - #### [AvoidStaticImport](http://checkstyle.sourceforge.net/config_imports.html#AvoidStaticImport) Prevents importing static members, unless they are one of the following: @@ -469,7 +475,6 @@ Invalid: ```` import static java.nio.charset.StandardCharsets.UTF_8; ```` - #### [BooleanExpressionComplexity](http://checkstyle.sourceforge.net/config_metrics.html#BooleanExpressionComplexity) Restrict the number of number of &&, ||, &, | and ^ in an expression to 2. @@ -483,7 +488,6 @@ Invalid: ```` if (a > b || b > c || c == a || d > a) {} ```` - #### [CatchParameterName](http://checkstyle.sourceforge.net/config_naming.html#CatchParameterName) Checks that catch parameter names conform to the following characteristic: @@ -514,7 +518,6 @@ catch(Exception pExceptions) {} catch(Exception gh) {} catch(Exception e_x) {} ```` - #### [ClassDataAbstractionCoupling](http://checkstyle.sourceforge.net/config_metrics.html#ClassDataAbstractionCoupling) Restricts to 7 the number of different classes instantiated within a class when that class is instantiated. @@ -546,13 +549,11 @@ class Invalid { private final ItemH i8 = new ItemH(); } ```` - #### [ClassFanOutComplexity](http://checkstyle.sourceforge.net/config_metrics.html#ClassFanOutComplexity) 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. - #### [ClassTypeParameterName](http://checkstyle.sourceforge.net/config_naming.html#ClassTypeParameterName) Restricts class generics parameters to be a single uppercase letter. @@ -568,7 +569,6 @@ class Invalidator {} class Invalidator {} class Invalidator {} ```` - #### [CommentsIndentation](http://checkstyle.sourceforge.net/config_misc.html#CommentsIndentation) Requires the indentation of comments to match the surrounding code. @@ -615,7 +615,6 @@ public void foo11() { // this is NOT okay } ```` - #### [ConstantName](http://checkstyle.sourceforge.net/config_naming.html#ConstantName) > This check cannot be suppressed. @@ -632,7 +631,6 @@ Invalid: private static final int ace_card = 1; private static final int 12_CARD = 12; ```` - #### [CovariantEquals](http://checkstyle.sourceforge.net/config_coding.html#CovariantEquals) > This check cannot be suppressed. @@ -660,7 +658,6 @@ class Test { } } ```` - #### [CyclomaticComplexity](http://checkstyle.sourceforge.net/config_metrics.html#CyclomaticComplexity) Restricts the cyclomatic complexity of a method to 5. The cyclomatic complexity is a measure of the number of decision points in a method. @@ -698,7 +695,6 @@ void isInvalid(int a, int b, int c) { } } ```` - #### [DeclarationOrder](http://checkstyle.sourceforge.net/config_coding.html#DeclarationOrder) Ensure class elements appear in the correct order. @@ -745,7 +741,6 @@ class Invalid { int g; } ```` - #### [DefaultComesLast](http://checkstyle.sourceforge.net/config_coding.html#DefaultComesLast) Check that the `default` is after all the `case`s in a `switch` statement. @@ -773,7 +768,6 @@ switch (a) { break; } ```` - #### [DesignForExtension](http://checkstyle.sourceforge.net/config_design.html#DesignForExtension) Judicous use of `@SuppressWarnings("designdorextension")` is recommended for this check. @@ -786,7 +780,6 @@ Classes that are deemed by their designer to be 'designed for extension', must t * 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. - #### [EmptyBlock](http://checkstyle.sourceforge.net/config_blocks.html#EmptyBlock) Checks for empty blocks. @@ -803,7 +796,6 @@ Invalid: if (a > b) { } ```` - #### [EmptyCatchBlock](http://checkstyle.sourceforge.net/config_blocks.html#EmptyCatchBlock) Checks that `catch` blocks are not empty, or are commented with the word `expected` or `ignore`. @@ -825,7 +817,6 @@ try { // do nothing } ```` - #### [EmptyForInitializerPad](http://checkstyle.sourceforge.net/config_whitespace.html#EmptyForInitializerPad) Checks that there is no padding in an empty `for` loop **initialiser**. @@ -839,7 +830,6 @@ Invalid: ```` for ( ; i < j ; i++) {} ```` - #### [EmptyForIteratorPad](http://checkstyle.sourceforge.net/config_whitespace.html#EmptyForIteratorPad) Checks that there is no padding in an empty `for` loop **iterator**. @@ -853,7 +843,6 @@ Invalid: ```` for (Iterator i = list.getIterator(); i.hasNext() ; ) {} ```` - #### [EmptyLineSeparator](http://checkstyle.sourceforge.net/config_whitespace.html#EmptyLineSeparator) Checks that there are blank lines between header, package, import blocks, field, constructors, methods, nested classes, static initialisers and instance initialisers. @@ -907,7 +896,6 @@ class Foo { } } ```` - #### [EmptyStatement](http://checkstyle.sourceforge.net/config_coding.html#EmptyStatement) Checks for empty statements. An empty statement is a standalone semicolon (;). @@ -921,7 +909,6 @@ Invalid: ```` doSomething();; ```` - #### [EqualsAvoidNull](http://checkstyle.sourceforge.net/config_coding.html#EqualsAvoidNull) Checks that string literals are on the left side in an `equals()` comparison. @@ -937,17 +924,14 @@ Invalid: String nullString = null; nullString.equals("value"); ```` - #### [EqualsHashCode](http://checkstyle.sourceforge.net/config_coding.html#EqualsHashCode) > This check cannot be suppressed. Checks that when a class overrides the `equals()` method, that it also overrides the `hashCode()` method. - #### [ExecutableStatementCount](http://checkstyle.sourceforge.net/config_sizes.html#ExecutableStatementCount) Limits the number of executable statements in a method to 30. - #### [ExplicitInitialization](http://checkstyle.sourceforge.net/config_coding.html#ExplicitInitialization) Checks that fields are not being explicitly initialised to their already default value. @@ -971,7 +955,6 @@ class Invalid { private Object bar = null; } ```` - #### [FallThrough](http://checkstyle.sourceforge.net/config_coding.html#FallThrough) 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. @@ -1015,15 +998,12 @@ switch (i) { break; } ```` - #### [FileLength](http://checkstyle.sourceforge.net/config_sizes.html#FileLength) Checks that each file has no more than 2000 lines. - #### [FileTabCharacter](http://checkstyle.sourceforge.net/config_whitespace.html#FileTabCharacter) Checks that there are no tab characters in the source files. - #### [FinalClass](http://checkstyle.sourceforge.net/config_design.html#FinalClass) 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. @@ -1043,7 +1023,6 @@ class Invalid { private Invalid() {} } ```` - #### [FinalParameters](http://checkstyle.sourceforge.net/config_misc.html#FinalParameters) Parameters to a method must be `final`. @@ -1057,7 +1036,6 @@ Invalid: ```` void foo(int a) {} ```` - #### [GenericWhitespace](http://checkstyle.sourceforge.net/config_whitespace.html#GenericWhitespace) Checks that the angle brackets around Generics parameters have the correct whitespace padding: @@ -1072,11 +1050,9 @@ Pair p1 = new Pair<>(1, "apple"); List list = ImmutableList.Builder::new; sort(list, Comparable::compareTo); ```` - #### [Header](http://checkstyle.sourceforge.net/config_header.html#Header) Checks that all `*.java` source files begin with the contents of the `LICENSE.txt` file. - #### [HiddenField](http://checkstyle.sourceforge.net/config_coding.html#HiddenField) 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. @@ -1108,7 +1084,6 @@ class Bar { } } ```` - #### [HideUtilityClassConstructor](http://checkstyle.sourceforge.net/config_design.html#HideUtilityClassConstructor) Classes that only have static fields or methods should not have a public constructor. This includes the default constructor. @@ -1139,7 +1114,6 @@ class StringUtils { private static int count(chat c, String s) {} } ```` - #### [IllegalCatch](http://checkstyle.sourceforge.net/config_coding.html#IllegalCatch) Prevent the following types from being in a `catch` statement: @@ -1165,7 +1139,6 @@ try { // log } ```` - #### [IllegalImport](http://checkstyle.sourceforge.net/config_imports.html#IllegalImport) Prevent `import`ing from the `sun.*` packages. @@ -1174,7 +1147,6 @@ Invalid: ```` import sun.security.provider.Sun; ```` - #### [IllegalThrows](http://checkstyle.sourceforge.net/config_coding.html#IllegalThrows) Prevent the following types from being `throw`n: @@ -1192,11 +1164,9 @@ Invalid: ```` throw new RuntimeException("boom!"); ```` - #### [IllegalToken](http://checkstyle.sourceforge.net/config_coding.html#IllegalToken) Checks that labels are not used. - #### [IllegalType](http://checkstyle.sourceforge.net/config_coding.html#IllegalType) Prevents use of implementation classes as variables, parameters or method returns. Use the interfaces instead. @@ -1226,7 +1196,6 @@ Invalid: ```` HashSet getNames(); ```` - #### [InnerAssignment](http://checkstyle.sourceforge.net/config_coding.html#InnerAssignment) Checks for assignments within an expressions. However, it still allows assignment in a while loop clause. @@ -1241,11 +1210,9 @@ Invalid: ```` String s = Integer.toString(i = 2); ```` - #### [InnerTypeLast](http://checkstyle.sourceforge.net/config_design.html#InnerTypeLast) Inner classes must appear at the bottom of a class, below fields and methods. - #### [InterfaceIsType](http://checkstyle.sourceforge.net/config_design.html#InterfaceIsType) An `interface` must define methods, not just constants. @@ -1267,7 +1234,6 @@ interface Foo { static final String "Foo!!"; } ```` - #### [InterfaceTypeParameterName](http://checkstyle.sourceforge.net/config_naming.html#InterfaceTypeParameterName) Checks that the type parameters for an interface are a single uppercase letter. @@ -1281,33 +1247,26 @@ Invalid: ```` interface Portable {} ```` - #### [JavadocMethod](http://checkstyle.sourceforge.net/config_javadoc.html#JavadocMethod) 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. - #### [JavadocPackage](http://checkstyle.sourceforge.net/config_javadoc.html#JavadocPackage) Checks that each package has a `package-info.java` file. - #### [JavadocParagraph](http://checkstyle.sourceforge.net/config_javadoc.html#JavadocParagraph) Checks that paragraphs in Javadoc blocks are wrapped in `

` elements and have blank lines between paragraphs. This first paragraph does not need the `

` elements. - #### [JavadocStyle](http://checkstyle.sourceforge.net/config_javadoc.html#JavadocStyle) 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. - #### [JavadocType](http://checkstyle.sourceforge.net/config_javadoc.html#JavadocType) 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. - #### [JavaNCSS](http://checkstyle.sourceforge.net/config_metrics.html#JavaNCSS) 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. - #### [LeftCurly](http://checkstyle.sourceforge.net/config_blocks.html#LeftCurly) Checks that the left curly brace ('{') is placed at the end of the line. Does not check enums. @@ -1325,25 +1284,21 @@ class Bar } ```` - #### [LineLength](http://checkstyle.sourceforge.net/config_sizes.html#LineLength) Limits the line length to 120 characters. Doesn't check package or import lines. - #### [LocalFinalVariableName](http://checkstyle.sourceforge.net/config_naming.html#LocalFinalVariableName) Checks the format of local, `final` variable names, including `catch` parameters. Identifiers must match `^[a-z][a-zA-Z0-9]*$`. - #### [LocalVariableName](http://checkstyle.sourceforge.net/config_naming.html#LocalVariableName) Checks the format of local, non-`final` variable names. Identifiers must match `^[a-z][a-zA-Z0-9]*$`. - #### [MagicNumber](http://checkstyle.sourceforge.net/config_coding.html#MagicNumber) Checks that numeric literals are defined as constants. Being constants they then have a name that aids in making them non-magical. @@ -1360,27 +1315,22 @@ Invalid ```` String item = getItem(200); ```` - #### [MemberName](http://checkstyle.sourceforge.net/config_naming.html#MemberName) Checks the format of non-static field names. Identifiers must match `^[a-z][a-zA-Z0-9]*$`. - #### [MethodCount](http://checkstyle.sourceforge.net/config_sizes.html#MethodCount) Restricts the number of methods in a type to 30. - #### [MethodLength](http://checkstyle.sourceforge.net/config_sizes.html#MethodLength) Restricts the number of lines in a method to 60. Include blank lines and single line comments. You should be able to see an entire method without needing to scroll. - #### [MethodName](http://checkstyle.sourceforge.net/config_naming.html#MethodName) Checks the format of method names. Identifiers must match `^[a-z][a-zA-Z0-9]*$`. - #### [MethodParamPad](http://checkstyle.sourceforge.net/config_whitespace.html#MethodParamPad) Checks that the padding between the method identifier and the left parenthesis is on the same line and doesn't have a space in-between. @@ -1397,7 +1347,6 @@ void getInstance (); void getValue (); ```` - #### [MethodTypeParameterName](http://checkstyle.sourceforge.net/config_naming.html#MethodTypeParameterName) Restricts method generics parameters to be a single uppercase letter. @@ -1413,7 +1362,6 @@ List getItems() {} List getItems() {} List getItems() {} ```` - #### [MissingDeprecated](http://checkstyle.sourceforge.net/config_annotation.html#MissingDeprecated) Both the `@Deprecated` annotation and the Javadoc tag `@deprecated` must be used in pairs. @@ -1444,7 +1392,6 @@ void foo() {} */ void bar() {} ```` - #### [MissingSwitchDefault](http://checkstyle.sourceforge.net/config_coding.html#MissingSwitchDefault) Checks that `switch` statement has a `default` case. @@ -1474,7 +1421,6 @@ switch (foo) { break; } ```` - #### [ModifiedControlVariable](http://checkstyle.sourceforge.net/config_coding.html#ModifiedControlVariable) Checks that the control variable in a `for` loop is not modified inside the loop. @@ -1485,7 +1431,6 @@ for (int i = 0; i < 1; i++) { i++; } ```` - #### [ModifierOrder](http://checkstyle.sourceforge.net/config_modifier.html#ModifierOrder) Check that modifiers are in the following order: @@ -1503,7 +1448,6 @@ Check that modifiers are in the following order: * `strictfp` Type annotations are ignored. - #### [MultipleStringLiterals](http://checkstyle.sourceforge.net/config_coding.html#MultipleStringLiterals) Checks for multiple occurrences of the same string literal within a single file. Does not apply to empty strings (""). @@ -1512,7 +1456,6 @@ Invalid: ```` String fooFoo = "foo" + "foo"; ```` - #### [MultipleVariableDeclarations](http://checkstyle.sourceforge.net/config_coding.html#MultipleVariableDeclarations) Checks that each variable is declared in its own statement and line. @@ -1527,7 +1470,6 @@ Invalid: ```` int a, b; ```` - #### [MutableException](http://checkstyle.sourceforge.net/config_design.html#MutableException) Checks that `Exception` classes are immutable. However, you can still call `setStackTrace`. @@ -1537,7 +1479,6 @@ Classes checked are those whose name ends with the following. Or that the class * `Exception` * `Error` * `Throwable` - #### [NeedBraces](http://checkstyle.sourceforge.net/config_blocks.html#NeedBraces) Check that code blocks are surrounded by braces. @@ -1571,7 +1512,6 @@ do this.notify(); while (o != null); for (int i = 0; ;) this.notify(); ```` - #### [NestedForDepth](http://checkstyle.sourceforge.net/config_coding.html#NestedForDepth) Checks that `for` loops are not nested more than 1 deep. @@ -1595,7 +1535,6 @@ for (int i = 0; i < 1; i++) { // depth 0 } } ```` - #### [NestedIfDepth](http://checkstyle.sourceforge.net/config_coding.html#NestedIfDepth) Checks that `if` blocks are not nested more than 1 deep. @@ -1619,7 +1558,6 @@ if (isValid()) { // depth 0 } } ```` - #### [NestedTryDepth](http://checkstyle.sourceforge.net/config_coding.html#NestedTryDepth) Checks that `try` blocks are not nested. @@ -1649,11 +1587,9 @@ try { // handle it } ```` - #### [NewlineAtEndOfFile](http://checkstyle.sourceforge.net/config_misc.html#NewlineAtEndOfFile) Checks that files end with a line-feed character, (i.e. unix-style line ending). - #### [NoClone](http://checkstyle.sourceforge.net/config_coding.html#NoClone) > This check cannot be suppressed. @@ -1661,17 +1597,14 @@ Checks that files end with a line-feed character, (i.e. unix-style line ending). Checks that the `clone()` method from `Object` has not been overridden. Use a copy constructor, or better yet, a static factory method. > See [Effective Java], 2nd Edition by Josh Bloch: Item 11: Override clone judiciously. - #### [NoFinalizer](http://checkstyle.sourceforge.net/config_coding.html#NoFinalizer) Checks that the `finalize()` method from `Object` has not been overridden. > See [Effective Java], 2nd Edition by Josh Bloch: Item 7: Avoid finalizers. - #### [NoLineWrap](http://checkstyle.sourceforge.net/config_whitespace.html#NoLineWrap) Prevents wrapping of `package` and `import` statements. - #### [NonEmptyAtclauseDescription](http://checkstyle.sourceforge.net/config_javadoc.html#NonEmptyAtclauseDescription) Checks that the Javadoc clauses `@param`, `@return`, `@throws` and `@deprecated` all have descriptions. @@ -1693,7 +1626,6 @@ Invalid: * @returns */ ```` - #### [NoWhitespaceAfter](http://checkstyle.sourceforge.net/config_whitespace.html#NoWhitespaceAfter) Checks that there is no whitespace after the array init ('{'), prefix increment ('++'), prefix decrement ('--'), bitwise complement ('~'), logical complement ('!'), array declaration ('[' in `int[] a;`) or array index operator ('[' in `a[2]`). @@ -1725,7 +1657,6 @@ int b = o. getValue(); int[ ] a; int d = a[ 2]; ```` - #### [NoWhitespaceBefore](http://checkstyle.sourceforge.net/config_whitespace.html#NoWhitespaceBefore) Checks that there is no whitespace before the comma operator (','), statement terminator (';'), postfix increment ('++') or postfix decrement ('--'). @@ -1745,11 +1676,9 @@ doSomething() ; i ++; i --; ```` - #### [NPathComplexity](http://checkstyle.sourceforge.net/config_metrics.html#NPathComplexity) Checks that the NPATH score (number of paths) through a method is no more than 5. This is similar to [Cyclomatic Complexity](#cyclomaticcomplexity). - #### [OneStatementPerLine](http://checkstyle.sourceforge.net/config_coding.html#OneStatementPerLine) Checks that there is only one statement per line. @@ -1764,13 +1693,11 @@ Invalid: ```` doSomething(); doSomethingElse(); ```` - #### [OneTopLevelClass](http://checkstyle.sourceforge.net/config_design.html#OneTopLevelClass) > This check cannot be suppressed. Checks that each source file contains only one top-level class, interface or enum. - #### [OperatorWrap](http://checkstyle.sourceforge.net/config_whitespace.html#OperatorWrap) Checks that when wrapping a line on an operator that the operator appears on the new line. @@ -1786,43 +1713,35 @@ Invalid: int answer = getTheAnswerToLife() + getTheAnswerToTheUniverse() + getTheAnswerToEverything(); ```` - #### [OuterTypeFilename](http://checkstyle.sourceforge.net/config_misc.html#OuterTypeFilename) > This check cannot be suppressed. Checks that the source filename matches the name of the top-level class. e.g. `class Foo {}` is in file `Foo.java`. - #### [OverloadMethodsDeclarationOrder](http://checkstyle.sourceforge.net/config_coding.html#OverloadMethodsDeclarationOrder) Checks that overload methods are grouped together in the source file. - #### [PackageAnnotation](http://checkstyle.sourceforge.net/config_annotation.html#PackageAnnotation) Checks that package level annotations are in the `package-info.java` file. - #### [PackageDeclaration](http://checkstyle.sourceforge.net/config_coding.html#PackageDeclaration) > This check cannot be suppressed. Checks that the class has a `package` definition. - #### [PackageName](http://checkstyle.sourceforge.net/config_naming.html#PackageName) Checks the format of package names. Only lowercase letters, no initial numbers or any underscores. Identifiers must match `^[a-z]+(\.[a-z][a-z0-9]+)*$`. - #### [ParameterName](http://checkstyle.sourceforge.net/config_naming.html#ParameterName) Checks the format of method parameter names, including `catch` parameters. Identifiers must match `^[a-z][a-zA-Z0-9]*$`. - #### [ParameterNumber](http://checkstyle.sourceforge.net/config_sizes.html#ParameterNumber) Restricts the number of parameters in a method or constructor to 7. Overridden methods are not checked as there may be no access to change the super method. - #### [ParenPad](http://checkstyle.sourceforge.net/config_whitespace.html#ParenPad) Checks that there are no spaces padding parentheses. @@ -1839,7 +1758,6 @@ doSomething( ); doSomethingElse( 5); doSomethingElse(5 ); ```` - #### [RedundantModifier](http://checkstyle.sourceforge.net/config_modifier.html#RedundantModifier) Checks for redundant modifiers. Checks for: @@ -1849,11 +1767,9 @@ Checks for redundant modifiers. Checks for: * Inner interface declarations that are declared as static. * Class constructors. * Nested enum definitions that are declared as static. - #### [RequireThis](http://checkstyle.sourceforge.net/config_coding.html#RequireThis) Checks that references to instance fields where a parameter name overlaps are qualified by `this.`. - #### [ReturnCount](http://checkstyle.sourceforge.net/config_coding.html#ReturnCount) Restricts methods to have at most 2 `return` statements in non-void methods, and at most 1 in void methods. @@ -1895,7 +1811,6 @@ void getName(int a) { return "default"; } ```` - #### [RightCurly](http://checkstyle.sourceforge.net/config_blocks.html#RightCurly) Checks that the right curly brace ('}') is placed on the same line as the next part of a multi-block statement (e.g. try-catch-finally, if-then-else). @@ -1942,7 +1857,6 @@ if (a > 0) { public long getId() {return id;} ```` - #### [SeparatorWrap](http://checkstyle.sourceforge.net/config_whitespace.html#SeparatorWrap) Checks the line wrapping around separators. @@ -1965,7 +1879,6 @@ doSomething(alpha, beta doSomethingElse().stream(). forEach(System.out::println); ```` - #### [SimplifyBooleanExpression](http://checkstyle.sourceforge.net/config_coding.html#SimplifyBooleanExpression) Checks for overly complicated boolean expressions. Checks for code like `b == true`, `b || true`, `!false`, etc. @@ -1982,7 +1895,6 @@ if (b == true) {} if (b || true) {} if (!false) {} ```` - #### [SimplifyBooleanReturn](http://checkstyle.sourceforge.net/config_coding.html#SimplifyBooleanReturn) Checks for overly complicated boolean `return` statements. @@ -2000,7 +1912,6 @@ if (valid()) { return true; } ```` - #### [SingleSpaceSeparator](http://checkstyle.sourceforge.net/config_whitespace.html#SingleSpaceSeparator) Checks that non-whitespace characters on the same line are separated by no more than one whitespace. @@ -2016,13 +1927,11 @@ Invalid: if (a < 0) {} public long toNanos(long d) { return d; }; ```` - #### [StaticVariableName](http://checkstyle.sourceforge.net/config_naming.html#StaticVariableName) Checks the format of `static`, non-`final` variable names. Identifiers must match `^[a-z][a-zA-Z0-9]*$`. - #### [StringLiteralEquality](http://checkstyle.sourceforge.net/config_coding.html#StringLiteralEquality) Checks that string literals are not used with `==` or `!=`. @@ -2036,7 +1945,6 @@ Invalid: ```` if (x == "something") {} ```` - #### [SuppressWarnings](http://checkstyle.sourceforge.net/config_annotation.html#SuppressWarnings) Prevents the use of `@SuppressWarnings` for the following checks: @@ -2050,11 +1958,12 @@ Prevents the use of `@SuppressWarnings` for the following checks: * [PackageDeclaration](#packagedeclaration) * [TypeName](#typename) * [VisibilityModifier](#visibilitymodifier) - #### [SuppressWarningsHolder](http://checkstyle.sourceforge.net/config_annotation.html#SuppressWarningsHolder) Used by Checkstyle to hold the checks to be suppressed from `@SuppressWarnings(...)` annotations. +#### [SuppressWarningsFilter](http://checkstyle.sourceforge.net/config_annotation.html#SuppressWarningsFilter) +Allows the use of the `@SuppressWarnings` annotation. #### [ThrowsCount](http://checkstyle.sourceforge.net/config_design.html#ThrowsCount) Restricts non-private methods to only `throws` 4 distinct Exception types. Exceptions should be hierarchical to allow catching suitable root Exceptions. @@ -2073,11 +1982,9 @@ void doSomething() throws IllegalStateException, DowsingNotPermittedException, DowsingServiceNotReadyException, BalancedBudgetException, ManagementInterferanceException {} ```` - #### [TodoComment](http://checkstyle.sourceforge.net/config_misc.html#TodoComment) Checks for remaining `TODO` and `FIXME` comments left in code. Their presence indicates that the program isn't finished yet. - #### [TrailingComment](http://checkstyle.sourceforge.net/config_misc.html#TrailingComment) Checks for comments at the end of lines. @@ -2105,11 +2012,9 @@ int[] a = new int[2]( 2 // second value - also invalid comment ); ```` - #### [Translation](http://checkstyle.sourceforge.net/config_misc.html#Translation) Checks that all `messages*.properties` files all have the same set of keys. - #### [TypecastParenPad](http://checkstyle.sourceforge.net/config_whitespace.html#TypecastParenPad) Checks that there are no spaces within the typecasting parentheses. @@ -2125,7 +2030,6 @@ String s = (String ) list.get(2); String s = ( String) list.get(2); String s = ( String ) list.get(2); ```` - #### [TypeName](http://checkstyle.sourceforge.net/config_naming.html#TypeName) > This check cannot be suppressed. @@ -2133,15 +2037,12 @@ String s = ( String ) list.get(2); Checks the format of `class`, `interface`, `enum` identifiers, including annotations. Identifiers must match `^[A-Z][a-zA-Z0-9]*$`. - #### [UncommentedMain](http://checkstyle.sourceforge.net/config_misc.html#UncommentedMain) Checks for `public static void main()` methods that may have been left over from testing. Allowed in classes whose names end in `Main` or `Application`. - #### [UniqueProperties](http://checkstyle.sourceforge.net/config_misc.html#UniqueProperties) Checks `*.properties` files for duplicate property keys. - #### [UnnecessaryParentheses](http://checkstyle.sourceforge.net/config_coding.html#UnnecessaryParentheses) Checks for the use of unnecessary parentheses. @@ -2155,7 +2056,6 @@ Invalid: ```` if ((a < 1)) {} ```` - #### [UnusedImports](http://checkstyle.sourceforge.net/config_imports.html#UnusedImports) Checks for unused imports. Does not inspect wildcard imports, which should be blocked by [AvoidStarImport](#avoidstarimport) anyway. @@ -2167,7 +2067,6 @@ Imports are unused if: * It import from the `java.lang` package. * It imports a class from the same package. * It is only references from the Javadoc. - #### [UpperEll](http://checkstyle.sourceforge.net/config_misc.html#UpperEll) Checks that `long` numeric literal values are marked by an upper-case ell ('L'). The lower-case ell ('l') can be mistaken for the numeral one ('1'). @@ -2181,13 +2080,11 @@ Invalid: ```` long id = 12345l; ```` - #### [VariableDeclarationUsageDistance](http://checkstyle.sourceforge.net/config_coding.html#VariableDeclarationUsageDistance) Checks that a variable declaration and its first usage are not more than 3 lines. Blocks of initialisation methods don't count toward this total. See the official [Checkstyle documentation](http://checkstyle.sourceforge.net/config_coding.html#VariableDeclarationUsageDistance) for examples. - #### [VisibilityModifier](http://checkstyle.sourceforge.net/config_design.html#VisibilityModifier) > This check cannot be suppressed. @@ -2261,7 +2158,6 @@ class Foo { } } ```` - #### [WhitespaceAfter](http://checkstyle.sourceforge.net/config_whitespace.html#WhitespaceAfter) Checks that commas (','), statement terminators (';') and typecasts are all followed by a space. @@ -2279,7 +2175,6 @@ doSomething(1,2,3); if (a > 1) { return true;} String name = (String)list.get(9); ```` - #### [WhitespaceAround](http://checkstyle.sourceforge.net/config_whitespace.html#WhitespaceAround) Checks that tokens are surrounded by whitespace. @@ -2299,7 +2194,6 @@ Invalid: ```` if (12 == a) {} ```` - #### [AvoidHidingCauseException](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/AvoidHidingCauseExceptionCheck.html) Ensures that an exception is re-thrown properly and is not swallowed by a `catch` block. @@ -2321,7 +2215,6 @@ try { throw new MyOtherException(); } ```` - #### [AvoidNotShortCircuitOperatorsForBoolean](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/AvoidNotShortCircuitOperatorsForBooleanCheck.html) Prevents the use of boolean operators that don't allow short-circuiting the expression. (e.g. '|', '&', '|=' and '&=') @@ -2335,7 +2228,6 @@ Invalid: ```` if ((a < b) | (b > getExpensiveValue())) {} ```` - #### [ConfusingCondition](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/ConfusingConditionCheck.html) Checks that the expression with the `if` condition in an `if-then-else` statement is not negated. @@ -2357,11 +2249,9 @@ if (!isValid()) { handleValidCondition(); } ```` - #### [ConstructorWithoutParams](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/design/ConstructorWithoutParamsCheck.html) Exception class constructors must accept parameters for message and/or cause. This check is applied to classes whose name ends with `Exception`. - #### [DiamondOperatorForVariableDefinition](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/DiamondOperatorForVariableDefinitionCheck.html) Checks that the diamond operator is used where possible. @@ -2375,13 +2265,11 @@ Invalid: ```` Map idTable = new HashMap(); ```` - #### [EitherLogOrThrow](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/EitherLogOrThrowCheck.html) 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`. - #### [EnumValueName](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/naming/EnumValueNameCheck.html) 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. @@ -2432,7 +2320,6 @@ enum InvalidClassLike { } } ```` - #### [ForbidCCommentsInMethods](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/ForbidCCommentsInMethodsCheck.html) Prevents the use of `/* C-style */` comments inside methods. @@ -2450,7 +2337,6 @@ void doSomething() { /* invalid */ } ```` - #### [ForbidReturnInFinallyBlock](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/ForbidReturnInFinallyBlockCheck.html) Prevent the use of a `return` statement in the `finally` block. @@ -2465,7 +2351,6 @@ try { return true; // invalid } ```` - #### [ForbidWildcardAsReturnType](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/design/ForbidWildcardAsReturnTypeCheck.html) Prevents declaring a method from returning a wildcard type as its return value. @@ -2479,7 +2364,6 @@ Invalid: ```` List getList() {} ```` - #### [LogicConditionNeedOptimization](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/LogicConditionNeedOptimizationCheck.html) Prevent the placement of variables or fields after methods in an expression. @@ -2493,17 +2377,14 @@ Invalid: ```` if (getProperty() && property) {} ```` - #### [MapIterationInForEachLoop](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/MapIterationInForEachLoopCheck.html) Checks for unoptimised iterations over `Map`s. Check use of `map.values()`, `map.keySet()` and `map.entrySet()` against the use of the iterator produced to verify if another could be better. - #### [NameConventionForJunit4TestClasses](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/NameConventionForJunit4TestClassesCheck.html) Checks the names of JUnit test classes. Classes checked are those that have at least one method annotated with `Test` or `org.junit.Test`. Test class names must match: `.+Test\\d*|.+Tests\\d*|Test.+|Tests.+|.+IT|.+ITs|.+TestCase\\d*|.+TestCases\\d*` - #### [NestedSwitch](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/design/NestedSwitchCheck.html) Checks that `switch` statements are not nested within one another. @@ -2552,11 +2433,9 @@ void doSomething(int a, int b) { } } ```` - #### [NoMainMethodInAbstractClass](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/design/NoMainMethodInAbstractClassCheck.html) Prevents a `main` method from existing in an `abstract` class. - #### [NumericLiteralNeedsUnderscore](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/NumericLiteralNeedsUnderscoreCheck.html) Checks that numeric literals use underscores ('_') if over a certain length. @@ -2575,7 +2454,6 @@ Checks that numeric literals use underscores ('_') if over a certain length. * 9 or more digits must use the underscore * No more than 8 digits between underscores - #### [OverridableMethodInConstructor](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/OverridableMethodInConstructorCheck.html) Prevents calls to overridable methods from constuctors including other methods that perform the same functions. (i.e. `Cloneable.clone()` and `Serializable.readObject()`) @@ -2598,7 +2476,6 @@ class Child extends Base { } new Child(42); // prints "0" ```` - #### [PublicReferenceToPrivateType](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/design/PublicReferenceToPrivateTypeCheck.html) Checks that a type is not exposed outside its declared scope. @@ -2614,7 +2491,6 @@ public class OuterClass { } class SiblingClass {} ```` - #### [RedundantReturn](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/RedundantReturnCheck.html) Checks for redundant return statements. @@ -2630,7 +2506,6 @@ void doStuff() { return; } ```` - #### [ReturnBooleanFromTernary](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/ReturnBooleanFromTernaryCheck.html) Ternary statements shouldn't have `Boolean` values as results. @@ -2646,7 +2521,6 @@ Invalid: Boolean set = isSet(); Boolean notReady = !isReady(); ```` - #### [ReturnNullInsteadOfBoolean](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/ReturnNullInsteadOfBooleanCheck.html) The `Boolean` type is meant to only represent a binary state: TRUE or FALSE. It is not a ternary value: TRUE, FALSE, null. @@ -2666,11 +2540,9 @@ Boolean isEnabled() { #### [SimpleAccessorNameNotation](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/SimpleAccessorNameNotationCheck.html) Checks that setters and getters follow the normal setField(), getField() and isField() pattern, where 'Field' is the name of the field being accessed. - #### [SingleBreakOrContinue](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/SingleBreakOrContinueCheck.html) Checks that there is at most one `continue` or `break` statement within a looping block (e.g. `for`, `while`, ...) - #### [TernaryPerExpressionCount](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/TernaryPerExpressionCountCheck.html) Checks that there is at most one ternary statments (`?:`) within an expression. @@ -2679,7 +2551,6 @@ Invalid: ```` String x = value != null ? "A" : "B" + value == null ? "C" : "D" ```` - #### [UniformEnumConstantName](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/naming/UniformEnumConstantNameCheck.html) Checks that all the values of an `enum` follow the same naming pattern. @@ -2701,7 +2572,6 @@ public enum EnumThree { FirstElement, SECOND_ELEMENT, ThirdElement; } ```` - #### [UselessSingleCatch](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/UselessSingleCatchCheck.html) Checks for catch blocks that are useless. i.e. that catch al exceptions and then just rethrow them. @@ -2714,7 +2584,6 @@ try { throw e; } ```` - #### [UselessSuperCtorCall](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/UselessSuperCtorCallCheck.html) Checks for useless calls the the `super()` method in constructors. @@ -2742,103 +2611,75 @@ These checks are not enabled. Notes are included for each explaining why. #### [ArrayTrailingComma](http://checkstyle.sourceforge.net/config_coding.html#ArrayTrailingComma) Couldn't get my IDE's (IntelliJ) code style to match. - #### [FinalLocalVariable](http://checkstyle.sourceforge.net/config_coding.html#FinalLocalVariable) Doesn't recognise Lombok's `val` as being `final`. - -Checks that local variables are `final` if they are never modified after declaration. - #### [IllegalInstantiation](http://checkstyle.sourceforge.net/config_coding.html#IllegalInstantiation) Not really suitable for a template ruleset as it requires an explicit list of classes to apply to. - #### [IllegalTokenText](http://checkstyle.sourceforge.net/config_coding.html#IllegalTokenText) Generic rule; doesn't embody a 'quality' check. - #### [ImportControl](http://checkstyle.sourceforge.net/config_imports.html#ImportControl) Generic rule; doesn't embody a 'quality' check. - #### [ImportOrder](http://checkstyle.sourceforge.net/config_imports.html#ImportOrder) Generic rule; doesn't embody a 'quality' check. - #### [Indentation](http://checkstyle.sourceforge.net/config_misc.html#Indentation) Couldn't get my IDE's (IntelliJ) code style to match. - #### [JavadocTagContinuationIndentation](http://checkstyle.sourceforge.net/config_javadoc.html#JavadocTagContinuationIndentation) Couldn't get my IDE's (IntelliJ) code style to match. - #### [JavadocVariable](http://checkstyle.sourceforge.net/config_javadoc.html#JavadocVariable) Member variables should usually be named such that it is clear what they are. Comments for clarification should be the exception. - #### [MissingCtor](http://checkstyle.sourceforge.net/config_coding.html#MissingCtor) Would not see constructors created using Lombok's `@NoArgsConstructor`. - #### [MissingOverride](http://checkstyle.sourceforge.net/config_annotation.html#MissingOverride) The javadoc compiler automatically inherits the javadoc from the overridden method, it doesn't need to be told to do so. - #### [OuterTypeNumber](http://checkstyle.sourceforge.net/config_sizes.html#OuterTypeNumber) Already covered by the [OneTopLevelClass](#onetoplevelclass) check. - #### [ParameterAssignment](http://checkstyle.sourceforge.net/config_coding.html#ParameterAssignment) [FinalParameters](#finalparameters) already protects against assigning values to parameters. - #### [RedundantImport](http://checkstyle.sourceforge.net/config_imports.html#RedundantImport) [UnusedImports](#unusedimports) performs all the same checks and more. - -Checks for redundant `import`s. Checks for duplicates, imports from the `java.lang` package or from the current package. - #### [Regexp](http://checkstyle.sourceforge.net/config_regexp.html#Regexp) Generic rule; doesn't embody a 'quality' check. - #### [RegexpHeader](http://checkstyle.sourceforge.net/config_header.html#RegexpHeader) Generic rule; doesn't embody a 'quality' check. - #### [RegexpMultiline](http://checkstyle.sourceforge.net/config_regexp.html#RegexpMultiline) Generic rule; doesn't embody a 'quality' check. - #### [RegexpOnFilename](http://checkstyle.sourceforge.net/config_regexp.html#RegexpOnFilename) Generic rule; doesn't embody a 'quality' check. - #### [RegexpSingleline](http://checkstyle.sourceforge.net/config_regexp.html#RegexpSingleline) Generic rule; doesn't embody a 'quality' check. - -#### [RegexpSingleline](http://checkstyle.sourceforge.net/config_regexp.html#c) +#### [RegexpSinglelineJava](http://checkstyle.sourceforge.net/config_regexp.html#RegexpSinglelineJava) Generic rule; doesn't embody a 'quality' check. - #### [SingleLineJavadoc](http://checkstyle.sourceforge.net/config_javadoc.html#SingleLineJavadoc) I don't use single line javadoc blocks. - #### [SummaryJavadoc](http://checkstyle.sourceforge.net/config_javadoc.html#SummaryJavadoc) Generic rule; doesn't embody a 'quality' check. - #### [SuperClone](http://checkstyle.sourceforge.net/config_coding.html#SuperClone) Overridding the `clone()` method is not allowed by the [NoClone](#noclone) check. - #### [SuperFinalize](http://checkstyle.sourceforge.net/config_coding.html#SuperFinalize) [NoFinalizer](#nofinalizer) prevents use of `finalize()`. - #### [WriteTag](http://checkstyle.sourceforge.net/config_javadoc.html#WriteTag) Generic rule; doesn't embody a 'quality' check. @@ -2850,97 +2691,47 @@ As the sevntu check are considered experimental not all those that are not enabl #### [AvoidConditionInversion](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/design/AvoidConditionInversionCheck.html) Should already be covered by [SimplifyBooleanExpression](simplifybooleanexpression). - #### [AvoidDefaultSerializableInInnerClasses](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/AvoidDefaultSerializableInInnerClassesCheck.html) -> TODO: enable - +TODO: enable #### [AvoidModifiersForTypes](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/AvoidModifiersForTypesCheck.html) Generic rule; doesn't embody a 'quality' check. - #### [CauseParameterInException](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/design/CauseParameterInExceptionCheck.html) Should already be covered by [AvoidHidingCauseException](#avoidhidingcauseexception). - #### [ChildBlockLength](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/design/ChildBlockLengthCheck.html) Appears to be broken as of `1.21.0`. - #### [CustomDeclarationOrder](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/CustomDeclarationOrderCheck.html) The [DeclarationOrder](#declarationorder) check already imposes an order for class elements. - #### [EmptyPublicCtorInClass](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/EmptyPublicCtorInClassCheck.html) -> TODO: enable - +TODO: enable #### [FinalizeImplementation](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/FinalizeImplementationCheck.html) -> TODO: enable - +TODO: enable #### [ForbidAnnotation](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/annotation/ForbidAnnotationCheck.html) Generic rule; doesn't embody a 'quality' check. - #### [ForbidCertainImports](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/ForbidCertainImportsCheck.html) Generic rule; doesn't embody a 'quality' check. - #### [ForbidInstantiation](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/ForbidInstantiationCheck.html) Generic rule; doesn't embody a 'quality' check. - #### [ForbidThrowAnonymousExceptions](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/ForbidThrowAnonymousExceptionsCheck.html) [IllegalThrows](#illegalthrows) performs a similar check. - -#### [HideUtilityClassConstructor](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/design/HideUtilityClassConstructorCheck.html) - -See [HideUtilityClassConstructor](#hideutilityclassconstructor). - -#### [IllegalCatchExtended](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/IllegalCatchExtendedCheck.html) - -See [IllegalCatch](#illegalcatch). - -#### [InnerClass](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/design/InnerClassCheck.html) - -See [InnerTypeLast](#innertypelast). - -#### [InterfaceTypeParameterName](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/naming/InterfaceTypeParameterNameCheck.html) - -See [InterfaceTypeParameterName](#interfacetypeparametername). - -#### [LineLengthExtended](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/sizes/LineLengthExtendedCheck.html) - -See [LineLength](#linelength) - -#### [MultipleStringLiteralsExtended](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/MultipleStringLiteralsExtendedCheck.html) - -See [MultipleStringLiteralsExtended](#multiplestringliteralsextended). - -#### [MultipleVariableDeclarationsExtended](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/MultipleVariableDeclarationsExtendedCheck.html) - -See [MultipleVariableDeclarations](#multiplevariabledeclarations). - #### [RequiredParameterForAnnotation](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/annotation/RequiredParameterForAnnotationCheck.html) Generic rule; doesn't embody a 'quality' check. - -#### [ReturnCountExtended](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/ReturnCountExtendedCheck.html) - -See [ReturnCount](#returncount). - #### [StaticMethodCandidate](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/design/StaticMethodCandidateCheck.html) Can't handle private methods called by reflection, which may cause issues with Spring and other DI frameworks. - -#### [UnnecessaryParenthesesExtended](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/UnnecessaryParenthesesExtendedCheck.html) - -See [UnnecessaryParentheses](#unnecessaryparentheses). - #### [WhitespaceBeforeArrayInitializer](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/WhitespaceBeforeArrayInitializerCheck.html) -> TODO: enable +TODO: enable -[Effective Java]: http://amzn.to/2aSz6GE +[Effective Java]: http://amzn.to/2aSz6GE \ No newline at end of file diff --git a/builder/LICENSE.txt b/builder/LICENSE.txt new file mode 100644 index 0000000..00c515a --- /dev/null +++ b/builder/LICENSE.txt @@ -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. +*/ diff --git a/builder/pom.xml b/builder/pom.xml new file mode 100644 index 0000000..e7c2116 --- /dev/null +++ b/builder/pom.xml @@ -0,0 +1,130 @@ + + + 4.0.0 + + + net.kemitix + kemitix-spring-parent + 2.2.0 + + + + kemitix-checkstyle-ruleset-builder + 2.0.0-SNAPSHOT + jar + + Kemitix Checkstyle Ruleset Builder + Builder for the Kemitix Checkstyle Ruleset + + + https://github.com/kemitix/kemitix-checkstyle-ruleset/issues + GitHub Issues + + + + scm:git:git@github.com:kemitix/kemitix-checkstyle-ruleset.git + scm:git:git@github.com:kemitix/kemitix-checkstyle-ruleset.git + git@github.com:kemitix/kemitix-checkstyle-ruleset.git + + + https://github.com/kemitix/kemitix-checkstyle-ruleset + + 2016 + + + 1.4.3.RELEASE + 2.0.0-SNAPSHOT + 5-complexity + 3.6.1 + 2.3.4 + 1.0.0 + 4.3.0 + + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-logging + + + + + org.springframework.boot + spring-boot-starter-log4j2 + + + org.springframework.boot + spring-boot-configuration-processor + true + + + org.projectlombok + lombok + + + com.speedment.common + mapstream + ${mapstream.version} + + + org.springframework.boot + spring-boot-starter-test + test + + + org.assertj + assertj-core + ${assertj.version} + + + me.andrz + map-builder + ${mapbuilder.version} + test + + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${maven.checkstyle.plugin.version} + + net/kemitix/checkstyle-${kemitix-checkstyle-ruleset.level}.xml + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + + + + + + + + + + + + + + org.eluder.coveralls + coveralls-maven-plugin + ${coveralls-maven-plugin.version} + + + + diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleRulesetBuilderApplication.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleRulesetBuilderApplication.java new file mode 100644 index 0000000..e095897 --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleRulesetBuilderApplication.java @@ -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. + * + *

This application is intended to only to be used by the developer to create the actual checkstyle xml files that + * this module provides.

+ * + * @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); + } +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java new file mode 100644 index 0000000..c82f1f7 --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java @@ -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("", rule.getName()); + } + return String.format("%n %s%n", rule.getName(), + formatProperties(rule.getProperties()) + ); + } + + private String formatProperties(final Map properties) { + return MapStream.of(properties) + .map((k, v) -> String.format("", k, v)) + .collect(Collectors.joining(NEWLINE)); + } +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultReadmeIndexBuilder.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultReadmeIndexBuilder.java new file mode 100644 index 0000000..27eeec4 --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultReadmeIndexBuilder.java @@ -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 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); + } +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleReadmeLoader.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleReadmeLoader.java new file mode 100644 index 0000000..a819bc6 --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleReadmeLoader.java @@ -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 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()); + } +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/OutputProperties.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/OutputProperties.java new file mode 100644 index 0000000..6f21e89 --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/OutputProperties.java @@ -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 rulesetFiles; + + /** + * The README.md file. + */ + private Path readme; +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/ReadmeFragmentNotFoundException.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/ReadmeFragmentNotFoundException.java new file mode 100644 index 0000000..de18387 --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/ReadmeFragmentNotFoundException.java @@ -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); + } +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/ReadmeIndexBuilder.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/ReadmeIndexBuilder.java new file mode 100644 index 0000000..b69eb46 --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/ReadmeIndexBuilder.java @@ -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(); +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriter.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriter.java new file mode 100644 index 0000000..d33563a --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriter.java @@ -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 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)); + } + +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/Rule.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/Rule.java new file mode 100644 index 0000000..fccd941 --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/Rule.java @@ -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 properties = new HashMap<>(); +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleLevel.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleLevel.java new file mode 100644 index 0000000..b88e4a7 --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleLevel.java @@ -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, +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleParent.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleParent.java new file mode 100644 index 0000000..576023e --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleParent.java @@ -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; +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleReadmeLoader.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleReadmeLoader.java new file mode 100644 index 0000000..9e99f90 --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleReadmeLoader.java @@ -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 load(Rule rule); +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleSource.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleSource.java new file mode 100644 index 0000000..c7b2dc1 --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleSource.java @@ -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, +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RulesProperties.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RulesProperties.java new file mode 100644 index 0000000..6abb1e8 --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RulesProperties.java @@ -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 rules = new ArrayList<>(); +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/TemplateProperties.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/TemplateProperties.java new file mode 100644 index 0000000..f68e291 --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/TemplateProperties.java @@ -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; +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/package-info.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/package-info.java new file mode 100644 index 0000000..3be5c06 --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/package-info.java @@ -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; diff --git a/builder/src/main/resources/README-template.md b/builder/src/main/resources/README-template.md new file mode 100644 index 0000000..528c337 --- /dev/null +++ b/builder/src/main/resources/README-template.md @@ -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. + +```` + + 2.17 + 7.3 + 1.22.0 + 2.0.0 + 5-complexity + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${maven.checkstyle.plugin.version} + + + com.puppycrawl.tools + checkstyle + ${checkstyle.version} + + + com.github.sevntu.checkstyle + sevntu-checkstyle-maven-plugin + ${sevntu-checkstyle-maven-plugin.version} + + + net.kemitix + kemitix-checkstyle-ruleset + ${kemitix-checkstyle-ruleset.version} + + + + net/kemitix/checkstyle-${kemitix-checkstyle-ruleset.level}.xml + + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + validate + validate + + check + checkstyle + + + + + + + + + sevntu-maven + sevntu-maven + http://sevntu-checkstyle.github.io/sevntu.checkstyle/maven2 + + +```` + +## 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 diff --git a/builder/src/main/resources/application.yml b/builder/src/main/resources/application.yml new file mode 100644 index 0000000..674e39a --- /dev/null +++ b/builder/src/main/resources/application.yml @@ -0,0 +1,1490 @@ +output: + directory: ruleset/src/main/resources/net/kemitix + ruleset-files: + LAYOUT: checkstyle-1-layout.xml + NAMING: checkstyle-2-naming.xml + JAVADOC: checkstyle-3-javadoc.xml + TWEAKS: checkstyle-4-tweaks.xml + COMPLEXITY: checkstyle-5-complexity.xml + readme: README.md +template: + checkstyle-xml: builder/src/main/resources/checkstyle-template.xml + readme-template: builder/src/main/resources/README-template.md + readme-fragments: builder/src/main/resources/rules +rules: + - + name: AbbreviationAsWordInName + parent: TREEWALKER + level: NAMING + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_naming.html#AbbreviationAsWordInName + - + name: AbstractClassName + parent: TREEWALKER + level: NAMING + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_naming.html#AbstractClassName + - + name: AnnotationLocation + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_annotation.html#AnnotationLocation + - + name: AnnotationUseStyle + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_annotation.html#AnnotationUseStyle + - + name: AnonInnerLength + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_sizes.html#AnonInnerLength + - + name: ArrayTypeStyle + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_misc.html#ArrayTypeStyle + - + name: AtclauseOrder + parent: TREEWALKER + level: JAVADOC + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_javadoc.html#AtclauseOrder + properties: + tagOrder: "@param, @author, @version, @serial, @return, @throws, @exception, @serialData, @serialField, @see, @since, @deprecated" + - + name: AvoidEscapedUnicodeCharacters + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_misc.html#AvoidEscapedUnicodeCharacters + properties: + allowEscapesForControlCharacters: true + - + name: AvoidInlineConditionals + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#AvoidInlineConditionals + - + name: AvoidNestedBlocks + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_blocks.html#AvoidNestedBlocks + - + name: AvoidStarImport + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_imports.html#AvoidStarImport + - + name: AvoidStaticImport + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_imports.html#AvoidStaticImport + properties: + excludes: org.assertj.core.api.Assertions.assertThat,org.mockito.BDDMockito.given,org.mockito.Mockito.*,org.mockito.Matchers.*,org.mockito.Mockito.* + - + name: BooleanExpressionComplexity + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_metrics.html#BooleanExpressionComplexity + properties: + max: 2 + - + name: CatchParameterName + parent: TREEWALKER + level: NAMING + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_naming.html#CatchParameterName + - + name: ClassDataAbstractionCoupling + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_metrics.html#ClassDataAbstractionCoupling + - + name: ClassFanOutComplexity + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_metrics.html#ClassFanOutComplexity + - + name: ClassTypeParameterName + parent: TREEWALKER + level: NAMING + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_naming.html#ClassTypeParameterName + - + name: CommentsIndentation + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_misc.html#CommentsIndentation + - + name: ConstantName + parent: TREEWALKER + level: NAMING + enabled: true + source: CHECKSTYLE + insuppressible: true + uri: http://checkstyle.sourceforge.net/config_naming.html#ConstantName + - + name: CovariantEquals + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + insuppressible: true + uri: http://checkstyle.sourceforge.net/config_coding.html#CovariantEquals + - + name: CyclomaticComplexity + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_metrics.html#CyclomaticComplexity + properties: + max: 5 + - + name: DeclarationOrder + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#DeclarationOrder + - + name: DefaultComesLast + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#DefaultComesLast + - + name: DesignForExtension + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_design.html#DesignForExtension + - + name: EmptyBlock + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_blocks.html#EmptyBlock + - + name: EmptyCatchBlock + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_blocks.html#EmptyCatchBlock + properties: + commentFormat: expected|ignore + - + name: EmptyForInitializerPad + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_whitespace.html#EmptyForInitializerPad + - + name: EmptyForIteratorPad + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_whitespace.html#EmptyForIteratorPad + - + name: EmptyLineSeparator + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_whitespace.html#EmptyLineSeparator + - + name: EmptyStatement + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#EmptyStatement + - + name: EqualsAvoidNull + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#EqualsAvoidNull + - + name: EqualsHashCode + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + insuppressible: true + uri: http://checkstyle.sourceforge.net/config_coding.html#EqualsHashCode + - + name: ExecutableStatementCount + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_sizes.html#ExecutableStatementCount + - + name: ExplicitInitialization + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#ExplicitInitialization + - + name: FallThrough + parent: TREEWALKER + level: JAVADOC + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#FallThrough + - + name: FileLength + parent: CHECKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_sizes.html#FileLength + - + name: FileTabCharacter + parent: CHECKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_whitespace.html#FileTabCharacter + - + name: FinalClass + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_design.html#FinalClass + - + name: FinalParameters + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_misc.html#FinalParameters + - + name: GenericWhitespace + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_whitespace.html#GenericWhitespace + - + name: Header + parent: CHECKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_header.html#Header + properties: + fileExtensions: java + headerFile: LICENSE.txt + - + name: HiddenField + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#HiddenField + properties: + ignoreConstructorParameter: true + ignoreSetter: true + - + name: HideUtilityClassConstructor + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_design.html#HideUtilityClassConstructor + - + name: IllegalCatch + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#IllegalCatch + - + name: IllegalImport + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_imports.html#IllegalImport + - + name: IllegalThrows + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#IllegalThrows + - + name: IllegalToken + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#IllegalToken + - + name: IllegalType + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#IllegalType + properties: + illegalClassNames: 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 + - + name: InnerAssignment + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#InnerAssignment + - + name: InnerTypeLast + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_design.html#InnerTypeLast + - + name: InterfaceIsType + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_design.html#InterfaceIsType + - + name: InterfaceTypeParameterName + parent: TREEWALKER + level: NAMING + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_naming.html#InterfaceTypeParameterName + - + name: JavadocMethod + parent: TREEWALKER + level: JAVADOC + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_javadoc.html#JavadocMethod + properties: + allowMissingPropertyJavadoc: true + validateThrows: true + scope: package + - + name: JavadocPackage + parent: CHECKER + level: JAVADOC + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_javadoc.html#JavadocPackage + - + name: JavadocParagraph + parent: TREEWALKER + level: JAVADOC + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_javadoc.html#JavadocParagraph + - + name: JavadocStyle + parent: TREEWALKER + level: JAVADOC + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_javadoc.html#JavadocStyle + - + name: JavadocType + parent: TREEWALKER + level: JAVADOC + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_javadoc.html#JavadocType + properties: + authorFormat: ^.+ (\S+@[\S.]+)$ + - + name: JavaNCSS + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_metrics.html#JavaNCSS + properties: + classMaximum: 1200 + fileMaximum: 1600 + methodMaximum: 40 + - + name: LeftCurly + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_blocks.html#LeftCurly + - + name: LineLength + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_sizes.html#LineLength + properties: + max: 120 + - + name: LocalFinalVariableName + parent: TREEWALKER + level: NAMING + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_naming.html#LocalFinalVariableName + - + name: LocalVariableName + parent: TREEWALKER + level: NAMING + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_naming.html#LocalVariableName + - + name: MagicNumber + parent: TREEWALKER + level: NAMING + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#MagicNumber + - + name: MemberName + parent: TREEWALKER + level: NAMING + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_naming.html#MemberName + - + name: MethodCount + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_sizes.html#MethodCount + properties: + maxTotal: 30 + - + name: MethodLength + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_sizes.html#MethodLength + properties: + max: 40 + - + name: MethodName + parent: TREEWALKER + level: NAMING + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_naming.html#MethodName + - + name: MethodParamPad + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_whitespace.html#MethodParamPad + - + name: MethodTypeParameterName + parent: TREEWALKER + level: NAMING + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_naming.html#MethodTypeParameterName + - + name: MissingDeprecated + parent: TREEWALKER + level: JAVADOC + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_annotation.html#MissingDeprecated + - + name: MissingSwitchDefault + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#MissingSwitchDefault + - + name: ModifiedControlVariable + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#ModifiedControlVariable + properties: + skipEnhancedForLoopVariable: true + - + name: ModifierOrder + parent: TREEWALKER + level: NAMING + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_modifier.html#ModifierOrder + - + name: MultipleStringLiterals + parent: TREEWALKER + level: NAMING + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#MultipleStringLiterals + - + name: MultipleVariableDeclarations + parent: TREEWALKER + level: NAMING + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#MultipleVariableDeclarations + - + name: MutableException + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_design.html#MutableException + - + name: NeedBraces + parent: TREEWALKER + level: NAMING + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_blocks.html#NeedBraces + - + name: NestedForDepth + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#NestedForDepth + - + name: NestedIfDepth + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#NestedIfDepth + - + name: NestedTryDepth + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#NestedTryDepth + properties: + max: 0 + - + name: NewlineAtEndOfFile + parent: CHECKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_misc.html#NewlineAtEndOfFile + properties: + lineSeparator: lf + - + name: NoClone + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + insuppressible: true + uri: http://checkstyle.sourceforge.net/config_coding.html#NoClone + - + name: NoFinalizer + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#NoFinalizer + - + name: NoLineWrap + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_whitespace.html#NoLineWrap + - + name: NonEmptyAtclauseDescription + parent: TREEWALKER + level: JAVADOC + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_javadoc.html#NonEmptyAtclauseDescription + - + name: NoWhitespaceAfter + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_whitespace.html#NoWhitespaceAfter + properties: + tokens: DOT + allowLineBreaks: false + - + name: NoWhitespaceBefore + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_whitespace.html#NoWhitespaceBefore + - + name: NPathComplexity + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_metrics.html#NPathComplexity + properties: + max: 5 + - + name: OneStatementPerLine + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#OneStatementPerLine + - + name: OneTopLevelClass + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + insuppressible: true + uri: http://checkstyle.sourceforge.net/config_design.html#OneTopLevelClass + - + name: OperatorWrap + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_whitespace.html#OperatorWrap + - + name: OuterTypeFilename + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + insuppressible: true + uri: http://checkstyle.sourceforge.net/config_misc.html#OuterTypeFilename + - + name: OverloadMethodsDeclarationOrder + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#OverloadMethodsDeclarationOrder + - + name: PackageAnnotation + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_annotation.html#PackageAnnotation + - + name: PackageDeclaration + parent: TREEWALKER + level: JAVADOC + enabled: true + source: CHECKSTYLE + insuppressible: true + uri: http://checkstyle.sourceforge.net/config_coding.html#PackageDeclaration + - + name: PackageName + parent: TREEWALKER + level: NAMING + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_naming.html#PackageName + properties: + format: ^[a-z]+(\.[a-z][a-z0-9]+)*$ + - + name: ParameterName + parent: TREEWALKER + level: NAMING + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_naming.html#ParameterName + - + name: ParameterNumber + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_sizes.html#ParameterNumber + properties: + ignoreOverriddenMethods: true + - + name: ParenPad + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_whitespace.html#ParenPad + - + name: RedundantModifier + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_modifier.html#RedundantModifier + - + name: RequireThis + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#RequireThis + properties: + checkMethods: false + - + name: ReturnCount + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#ReturnCount + - + name: RightCurly + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_blocks.html#RightCurly + - + name: SeparatorWrap + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_whitespace.html#SeparatorWrap + properties: + tokens: DOT + option: nl + - + name: SimplifyBooleanExpression + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#SimplifyBooleanExpression + - + name: SimplifyBooleanReturn + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#SimplifyBooleanReturn + - + name: SingleSpaceSeparator + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_whitespace.html#SingleSpaceSeparator + - + name: StaticVariableName + parent: TREEWALKER + level: NAMING + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_naming.html#StaticVariableName + - + name: StringLiteralEquality + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#StringLiteralEquality + - + name: SuppressWarnings + parent: TREEWALKER + level: NAMING + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_annotation.html#SuppressWarnings + properties: + format: ^constantname|covariantequals|equalshashcode|noclone|onetoplevelclass|outertypefilename|packagedeclaration|typename|visibilitymodifier$ + - + name: SuppressWarningsHolder + parent: TREEWALKER + level: NAMING + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_annotation.html#SuppressWarningsHolder + - + name: SuppressWarningsFilter + parent: CHECKER + level: NAMING + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_annotation.html#SuppressWarningsFilter + - + name: ThrowsCount + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_design.html#ThrowsCount + - + name: TodoComment + parent: TREEWALKER + level: JAVADOC + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_misc.html#TodoComment + properties: + format: ^(\s*\*).*((TODO)|(FIXME)) + - + name: TrailingComment + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_misc.html#TrailingComment + - + name: Translation + parent: CHECKER + level: JAVADOC + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_misc.html#Translation + - + name: TypecastParenPad + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_whitespace.html#TypecastParenPad + - + name: TypeName + parent: TREEWALKER + level: NAMING + enabled: true + source: CHECKSTYLE + insuppressible: true + uri: http://checkstyle.sourceforge.net/config_naming.html#TypeName + - + name: UncommentedMain + parent: TREEWALKER + level: JAVADOC + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_misc.html#UncommentedMain + properties: + excludedClasses: (Main|Application)$ + - + name: UniqueProperties + parent: CHECKER + level: JAVADOC + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_misc.html#UniqueProperties + - + name: UnnecessaryParentheses + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#UnnecessaryParentheses + - + name: UnusedImports + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_imports.html#UnusedImports + - + name: UpperEll + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_misc.html#UpperEll + - + name: VariableDeclarationUsageDistance + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#VariableDeclarationUsageDistance + - + name: VisibilityModifier + parent: TREEWALKER + level: TWEAKS + enabled: true + source: CHECKSTYLE + insuppressible: true + uri: http://checkstyle.sourceforge.net/config_design.html#VisibilityModifier + - + name: WhitespaceAfter + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_whitespace.html#WhitespaceAfter + - + name: WhitespaceAround + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_whitespace.html#WhitespaceAround + - + name: AvoidConstantAsFirstOperandInCondition + parent: TREEWALKER + level: TWEAKS + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/AvoidConstantAsFirstOperandInConditionCheck.html + - + name: AvoidHidingCauseException + parent: TREEWALKER + level: TWEAKS + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/AvoidHidingCauseExceptionCheck.html + - + name: AvoidNotShortCircuitOperatorsForBoolean + parent: TREEWALKER + level: TWEAKS + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/AvoidNotShortCircuitOperatorsForBooleanCheck.html + - + name: ConfusingCondition + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/ConfusingConditionCheck.html + - + name: ConstructorWithoutParams + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/design/ConstructorWithoutParamsCheck.html + - + name: DiamondOperatorForVariableDefinition + parent: TREEWALKER + level: TWEAKS + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/DiamondOperatorForVariableDefinitionCheck.html + - + name: EitherLogOrThrow + parent: TREEWALKER + level: TWEAKS + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/EitherLogOrThrowCheck.html + - + name: EnumValueName + parent: TREEWALKER + level: NAMING + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/naming/EnumValueNameCheck.html + - + name: ForbidCCommentsInMethods + parent: TREEWALKER + level: LAYOUT + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/ForbidCCommentsInMethodsCheck.html + - + name: ForbidReturnInFinallyBlock + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/ForbidReturnInFinallyBlockCheck.html + - + name: ForbidWildcardAsReturnType + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/design/ForbidWildcardAsReturnTypeCheck.html + - + name: LogicConditionNeedOptimization + parent: TREEWALKER + level: TWEAKS + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/LogicConditionNeedOptimizationCheck.html + - + name: MapIterationInForEachLoop + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/MapIterationInForEachLoopCheck.html + - + name: NameConventionForJunit4TestClasses + parent: TREEWALKER + level: NAMING + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/NameConventionForJunit4TestClassesCheck.html + - + name: NestedSwitch + parent: TREEWALKER + level: COMPLEXITY + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/design/NestedSwitchCheck.html + - + name: NoMainMethodInAbstractClass + parent: TREEWALKER + level: TWEAKS + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/design/NoMainMethodInAbstractClassCheck.html + - + name: NumericLiteralNeedsUnderscore + parent: TREEWALKER + level: NAMING + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/NumericLiteralNeedsUnderscoreCheck.html + - + name: OverridableMethodInConstructor + parent: TREEWALKER + level: TWEAKS + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/OverridableMethodInConstructorCheck.html + - + name: PublicReferenceToPrivateType + parent: TREEWALKER + level: TWEAKS + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/design/PublicReferenceToPrivateTypeCheck.html + - + name: RedundantReturn + parent: TREEWALKER + level: TWEAKS + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/RedundantReturnCheck.html + - + name: ReturnBooleanFromTernary + parent: TREEWALKER + level: TWEAKS + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/ReturnBooleanFromTernaryCheck.html + - + name: ReturnNullInsteadOfBoolean + parent: TREEWALKER + level: TWEAKS + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/ReturnNullInsteadOfBooleanCheck.html + - + name: SimpleAccessorNameNotation + parent: TREEWALKER + level: NAMING + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/SimpleAccessorNameNotationCheck.html + - + name: SingleBreakOrContinue + parent: TREEWALKER + level: TWEAKS + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/SingleBreakOrContinueCheck.html + - + name: TernaryPerExpressionCount + parent: TREEWALKER + level: TWEAKS + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/TernaryPerExpressionCountCheck.html + - + name: UniformEnumConstantName + parent: TREEWALKER + level: NAMING + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/naming/UniformEnumConstantNameCheck.html + - + name: UselessSingleCatch + parent: TREEWALKER + level: TWEAKS + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/UselessSingleCatchCheck.html + - + name: UselessSuperCtorCall + parent: TREEWALKER + level: TWEAKS + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/UselessSuperCtorCallCheck.html + - + name: ArrayTrailingComma + parent: TREEWALKER + level: TWEAK + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#ArrayTrailingComma + reason: Couldn't get my IDE's (IntelliJ) code style to match. + - + name: FinalLocalVariable + parent: TREEWALKER + level: TWEAK + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#FinalLocalVariable + reason: Doesn't recognise Lombok's `val` as being `final`. + - + name: IllegalInstantiation + parent: TREEWALKER + level: + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#IllegalInstantiation + reason: Not really suitable for a template ruleset as it requires an explicit list of classes to apply to. + - + name: IllegalTokenText + parent: TREEWALKER + level: + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#IllegalTokenText + reason: Generic rule; doesn't embody a 'quality' check. + - + name: ImportControl + parent: TREEWALKER + level: + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_imports.html#ImportControl + reason: Generic rule; doesn't embody a 'quality' check. + - + name: ImportOrder + parent: TREEWALKER + level: LAYOUT + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_imports.html#ImportOrder + reason: Generic rule; doesn't embody a 'quality' check. + - + name: Indentation + parent: TREEWALKER + level: LAYOUT + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_misc.html#Indentation + reason: Couldn't get my IDE's (IntelliJ) code style to match. + - + name: JavadocTagContinuationIndentation + parent: TREEWALKER + level: LAYOUT + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_javadoc.html#JavadocTagContinuationIndentation + reason: Couldn't get my IDE's (IntelliJ) code style to match. + - + name: JavadocVariable + parent: TREEWALKER + level: JAVADOC + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_javadoc.html#JavadocVariable + reason: Member variables should usually be named such that it is clear what they are. Comments for clarification should be the exception. + - + name: MissingCtor + parent: TREEWALKER + level: TWEAKS + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#MissingCtor + reason: Would not see constructors created using Lombok's `@NoArgsConstructor`. + - + name: MissingOverride + parent: TREEWALKER + level: TWEAKS + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_annotation.html#MissingOverride + reason: The javadoc compiler automatically inherits the javadoc from the overridden method, it doesn't need to be told to do so. + - + name: OuterTypeNumber + parent: TREEWALKER + level: TWEAKS + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_sizes.html#OuterTypeNumber + reason: Already covered by the [OneTopLevelClass](#onetoplevelclass) check. + - + name: ParameterAssignment + parent: TREEWALKER + level: TWEAKS + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#ParameterAssignment + reason: "[FinalParameters](#finalparameters) already protects against assigning values to parameters." + - + name: RedundantImport + parent: TREEWALKER + level: LAYOUT + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_imports.html#RedundantImport + reason: "[UnusedImports](#unusedimports) performs all the same checks and more." + - + name: Regexp + parent: TREEWALKER + level: + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_regexp.html#Regexp + reason: Generic rule; doesn't embody a 'quality' check. + - + name: RegexpHeader + parent: TREEWALKER + level: + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_header.html#RegexpHeader + reason: Generic rule; doesn't embody a 'quality' check. + - + name: RegexpMultiline + parent: TREEWALKER + level: + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_regexp.html#RegexpMultiline + reason: Generic rule; doesn't embody a 'quality' check. + - + name: RegexpOnFilename + parent: TREEWALKER + level: + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_regexp.html#RegexpOnFilename + reason: Generic rule; doesn't embody a 'quality' check. + - + name: RegexpSingleline + parent: TREEWALKER + level: + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_regexp.html#RegexpSingleline + reason: Generic rule; doesn't embody a 'quality' check. + - + name: RegexpSinglelineJava + parent: TREEWALKER + level: + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_regexp.html#RegexpSinglelineJava + reason: Generic rule; doesn't embody a 'quality' check. + - + name: SingleLineJavadoc + parent: TREEWALKER + level: JAVADOC + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_javadoc.html#SingleLineJavadoc + reason: I don't use single line javadoc blocks. + - + name: SummaryJavadoc + parent: TREEWALKER + level: JAVADOC + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_javadoc.html#SummaryJavadoc + reason: Generic rule; doesn't embody a 'quality' check. + - + name: SuperClone + parent: TREEWALKER + level: TWEAKS + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#SuperClone + reason: Overridding the `clone()` method is not allowed by the [NoClone](#noclone) check. + - + name: SuperFinalize + parent: TREEWALKER + level: TWEAKS + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_coding.html#SuperFinalize + reason: "[NoFinalizer](#nofinalizer) prevents use of `finalize()`." + - + name: WriteTag + parent: TREEWALKER + level: + enabled: false + source: CHECKSTYLE + uri: http://checkstyle.sourceforge.net/config_javadoc.html#WriteTag + reason: Generic rule; doesn't embody a 'quality' check. + - + name: AvoidConditionInversion + parent: TREEWALKER + level: COMPLEXITY + enabled: false + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/design/AvoidConditionInversionCheck.html + reason: Should already be covered by [SimplifyBooleanExpression](simplifybooleanexpression). + - + name: AvoidDefaultSerializableInInnerClasses + parent: TREEWALKER + level: COMPLEXITY + enabled: false + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/AvoidDefaultSerializableInInnerClassesCheck.html + reason: "TODO: enable" + - + name: AvoidModifiersForTypes + parent: TREEWALKER + level: + enabled: false + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/AvoidModifiersForTypesCheck.html + reason: Generic rule; doesn't embody a 'quality' check. + - + name: CauseParameterInException + parent: TREEWALKER + level: TWEAKS + enabled: false + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/design/CauseParameterInExceptionCheck.html + reason: Should already be covered by [AvoidHidingCauseException](#avoidhidingcauseexception). + - + name: ChildBlockLength + parent: TREEWALKER + level: COMPLEXITY + enabled: false + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/design/ChildBlockLengthCheck.html + reason: Appears to be broken as of `1.21.0`. + - + name: CustomDeclarationOrder + parent: TREEWALKER + level: LAYOUT + enabled: false + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/CustomDeclarationOrderCheck.html + reason: The [DeclarationOrder](#declarationorder) check already imposes an order for class elements. + - + name: EmptyPublicCtorInClass + parent: TREEWALKER + level: TWEAKS + enabled: false + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/EmptyPublicCtorInClassCheck.html + reason: "TODO: enable" + - + name: FinalizeImplementation + parent: TREEWALKER + level: + enabled: false + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/FinalizeImplementationCheck.html + reason: "TODO: enable" + - + name: ForbidAnnotation + parent: TREEWALKER + level: + enabled: false + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/annotation/ForbidAnnotationCheck.html + reason: Generic rule; doesn't embody a 'quality' check. + - + name: ForbidCertainImports + parent: TREEWALKER + level: + enabled: false + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/ForbidCertainImportsCheck.html + reason: Generic rule; doesn't embody a 'quality' check. + - + name: ForbidInstantiation + parent: TREEWALKER + level: + enabled: false + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/ForbidInstantiationCheck.html + reason: Generic rule; doesn't embody a 'quality' check. + - + name: ForbidThrowAnonymousExceptions + parent: TREEWALKER + level: TWEAKS + enabled: false + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/ForbidThrowAnonymousExceptionsCheck.html + reason: "[IllegalThrows](#illegalthrows) performs a similar check." + - + name: RequiredParameterForAnnotation + parent: TREEWALKER + level: + enabled: false + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/annotation/RequiredParameterForAnnotationCheck.html + reason: Generic rule; doesn't embody a 'quality' check. + - + name: StaticMethodCandidate + parent: TREEWALKER + level: + enabled: false + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/design/StaticMethodCandidateCheck.html + reason: Can't handle private methods called by reflection, which may cause issues with Spring and other DI frameworks. + - + name: WhitespaceBeforeArrayInitializer + parent: TREEWALKER + level: LAYOUT + enabled: false + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/WhitespaceBeforeArrayInitializerCheck.html + reason: "TODO: enable" diff --git a/builder/src/main/resources/checkstyle-template.xml b/builder/src/main/resources/checkstyle-template.xml new file mode 100644 index 0000000..104b975 --- /dev/null +++ b/builder/src/main/resources/checkstyle-template.xml @@ -0,0 +1,15 @@ + + + + + %s + + + + %s + + + + diff --git a/builder/src/main/resources/rules/AbbreviationAsWordInName.md b/builder/src/main/resources/rules/AbbreviationAsWordInName.md new file mode 100644 index 0000000..4c699fa --- /dev/null +++ b/builder/src/main/resources/rules/AbbreviationAsWordInName.md @@ -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 {} +```` diff --git a/builder/src/main/resources/rules/AbstractClassName.md b/builder/src/main/resources/rules/AbstractClassName.md new file mode 100644 index 0000000..a53cc09 --- /dev/null +++ b/builder/src/main/resources/rules/AbstractClassName.md @@ -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 {} +```` diff --git a/builder/src/main/resources/rules/AnnonInnerLength.md b/builder/src/main/resources/rules/AnnonInnerLength.md new file mode 100644 index 0000000..ef06973 --- /dev/null +++ b/builder/src/main/resources/rules/AnnonInnerLength.md @@ -0,0 +1 @@ +Anonymous inner classes should be no more than 20 lines. diff --git a/builder/src/main/resources/rules/AnnotationLocation.md b/builder/src/main/resources/rules/AnnotationLocation.md new file mode 100644 index 0000000..6f98dfe --- /dev/null +++ b/builder/src/main/resources/rules/AnnotationLocation.md @@ -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 {} +```` diff --git a/builder/src/main/resources/rules/AnnotationUseStyle.md b/builder/src/main/resources/rules/AnnotationUseStyle.md new file mode 100644 index 0000000..1dff957 --- /dev/null +++ b/builder/src/main/resources/rules/AnnotationUseStyle.md @@ -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") +```` diff --git a/builder/src/main/resources/rules/AnonInnerLength.md b/builder/src/main/resources/rules/AnonInnerLength.md new file mode 100644 index 0000000..c80538b --- /dev/null +++ b/builder/src/main/resources/rules/AnonInnerLength.md @@ -0,0 +1,2 @@ + +Anonymous inner classes should be no more than 20 lines. diff --git a/builder/src/main/resources/rules/ArrayTypeStyle.md b/builder/src/main/resources/rules/ArrayTypeStyle.md new file mode 100644 index 0000000..c23afbd --- /dev/null +++ b/builder/src/main/resources/rules/ArrayTypeStyle.md @@ -0,0 +1,12 @@ + +Enforces Java style arrays. + +Valid: +```` +public static void main(String[] args) {} +```` + +Invalid: +```` +public static void main(String args[]) {} +```` diff --git a/builder/src/main/resources/rules/AtclauseOrder.md b/builder/src/main/resources/rules/AtclauseOrder.md new file mode 100644 index 0000000..4051fda --- /dev/null +++ b/builder/src/main/resources/rules/AtclauseOrder.md @@ -0,0 +1,20 @@ + +Javadoc `@` clauses must be in the order: + +```` +/** + * + * @param ... + * @author ... + * @version ... + * @serial ... + * @return ... + * @throws ... + * @exception ... + * @serialData ... + * @serialField ... + * @see ... + * @since ... + * @deprecated ... + */ +```` diff --git a/builder/src/main/resources/rules/AvoidConstantAsFirstOperandInCondition.md b/builder/src/main/resources/rules/AvoidConstantAsFirstOperandInCondition.md new file mode 100644 index 0000000..39fea23 --- /dev/null +++ b/builder/src/main/resources/rules/AvoidConstantAsFirstOperandInCondition.md @@ -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) {} +```` diff --git a/builder/src/main/resources/rules/AvoidEscapedUnicodeCharacters.md b/builder/src/main/resources/rules/AvoidEscapedUnicodeCharacters.md new file mode 100644 index 0000000..49a7229 --- /dev/null +++ b/builder/src/main/resources/rules/AvoidEscapedUnicodeCharacters.md @@ -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"; +```` diff --git a/builder/src/main/resources/rules/AvoidHidingCauseException.md b/builder/src/main/resources/rules/AvoidHidingCauseException.md new file mode 100644 index 0000000..a056f5c --- /dev/null +++ b/builder/src/main/resources/rules/AvoidHidingCauseException.md @@ -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(); +} +```` diff --git a/builder/src/main/resources/rules/AvoidInlineConditionals.md b/builder/src/main/resources/rules/AvoidInlineConditionals.md new file mode 100644 index 0000000..4b2aefa --- /dev/null +++ b/builder/src/main/resources/rules/AvoidInlineConditionals.md @@ -0,0 +1,2 @@ + +Prevents use of the `?:` operators. diff --git a/builder/src/main/resources/rules/AvoidNestedBlocks.md b/builder/src/main/resources/rules/AvoidNestedBlocks.md new file mode 100644 index 0000000..5d36ebe --- /dev/null +++ b/builder/src/main/resources/rules/AvoidNestedBlocks.md @@ -0,0 +1,17 @@ + +Avoid unnecessary blocks. + +Valid: +```` +if (isDebug()) { + // ... +} +```` + +Invalid: +```` +// if (isDebug()) +{ + // ... +} +```` diff --git a/builder/src/main/resources/rules/AvoidNotShortCircuitOperatorsForBoolean.md b/builder/src/main/resources/rules/AvoidNotShortCircuitOperatorsForBoolean.md new file mode 100644 index 0000000..6cb6629 --- /dev/null +++ b/builder/src/main/resources/rules/AvoidNotShortCircuitOperatorsForBoolean.md @@ -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())) {} +```` diff --git a/builder/src/main/resources/rules/AvoidStarImport.md b/builder/src/main/resources/rules/AvoidStarImport.md new file mode 100644 index 0000000..f9b1576 --- /dev/null +++ b/builder/src/main/resources/rules/AvoidStarImport.md @@ -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.*; +```` diff --git a/builder/src/main/resources/rules/AvoidStaticImport.md b/builder/src/main/resources/rules/AvoidStaticImport.md new file mode 100644 index 0000000..366f369 --- /dev/null +++ b/builder/src/main/resources/rules/AvoidStaticImport.md @@ -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; +```` diff --git a/builder/src/main/resources/rules/BooleanExpressionComplexity.md b/builder/src/main/resources/rules/BooleanExpressionComplexity.md new file mode 100644 index 0000000..d389f4d --- /dev/null +++ b/builder/src/main/resources/rules/BooleanExpressionComplexity.md @@ -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) {} +```` diff --git a/builder/src/main/resources/rules/CatchParameterName.md b/builder/src/main/resources/rules/CatchParameterName.md new file mode 100644 index 0000000..7fce706 --- /dev/null +++ b/builder/src/main/resources/rules/CatchParameterName.md @@ -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) {} +```` diff --git a/builder/src/main/resources/rules/ClassDataAbstractionCoupling.md b/builder/src/main/resources/rules/ClassDataAbstractionCoupling.md new file mode 100644 index 0000000..3943d1a --- /dev/null +++ b/builder/src/main/resources/rules/ClassDataAbstractionCoupling.md @@ -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(); +} +```` diff --git a/builder/src/main/resources/rules/ClassFanOutComplexity.md b/builder/src/main/resources/rules/ClassFanOutComplexity.md new file mode 100644 index 0000000..2e271e2 --- /dev/null +++ b/builder/src/main/resources/rules/ClassFanOutComplexity.md @@ -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. diff --git a/builder/src/main/resources/rules/ClassTypeParameterName.md b/builder/src/main/resources/rules/ClassTypeParameterName.md new file mode 100644 index 0000000..0e983e8 --- /dev/null +++ b/builder/src/main/resources/rules/ClassTypeParameterName.md @@ -0,0 +1,14 @@ + +Restricts class generics parameters to be a single uppercase letter. + +Valid: +```` +class Deliverator {} +```` + +Invalid: +```` +class Invalidator {} +class Invalidator {} +class Invalidator {} +```` diff --git a/builder/src/main/resources/rules/CommentsIndentation.md b/builder/src/main/resources/rules/CommentsIndentation.md new file mode 100644 index 0000000..fe4d440 --- /dev/null +++ b/builder/src/main/resources/rules/CommentsIndentation.md @@ -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 +} +```` diff --git a/builder/src/main/resources/rules/ConfusingCondition.md b/builder/src/main/resources/rules/ConfusingCondition.md new file mode 100644 index 0000000..7ab2a81 --- /dev/null +++ b/builder/src/main/resources/rules/ConfusingCondition.md @@ -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(); +} +```` diff --git a/builder/src/main/resources/rules/ConstantName.md b/builder/src/main/resources/rules/ConstantName.md new file mode 100644 index 0000000..5bb19c2 --- /dev/null +++ b/builder/src/main/resources/rules/ConstantName.md @@ -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; +```` diff --git a/builder/src/main/resources/rules/ConstructorWithoutParams.md b/builder/src/main/resources/rules/ConstructorWithoutParams.md new file mode 100644 index 0000000..6076c8f --- /dev/null +++ b/builder/src/main/resources/rules/ConstructorWithoutParams.md @@ -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`. diff --git a/builder/src/main/resources/rules/CovariantEquals.md b/builder/src/main/resources/rules/CovariantEquals.md new file mode 100644 index 0000000..2420464 --- /dev/null +++ b/builder/src/main/resources/rules/CovariantEquals.md @@ -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; + } +} +```` diff --git a/builder/src/main/resources/rules/CyclomaticComplexity.md b/builder/src/main/resources/rules/CyclomaticComplexity.md new file mode 100644 index 0000000..4fc7a0d --- /dev/null +++ b/builder/src/main/resources/rules/CyclomaticComplexity.md @@ -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; + } + } +} +```` diff --git a/builder/src/main/resources/rules/DeclarationOrder.md b/builder/src/main/resources/rules/DeclarationOrder.md new file mode 100644 index 0000000..32902d0 --- /dev/null +++ b/builder/src/main/resources/rules/DeclarationOrder.md @@ -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; +} +```` diff --git a/builder/src/main/resources/rules/DefaultComesLast.md b/builder/src/main/resources/rules/DefaultComesLast.md new file mode 100644 index 0000000..745f99f --- /dev/null +++ b/builder/src/main/resources/rules/DefaultComesLast.md @@ -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; +} +```` diff --git a/builder/src/main/resources/rules/DesignForExtension.md b/builder/src/main/resources/rules/DesignForExtension.md new file mode 100644 index 0000000..c22d4bf --- /dev/null +++ b/builder/src/main/resources/rules/DesignForExtension.md @@ -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. diff --git a/builder/src/main/resources/rules/DiamondOperatorForVariableDefinition.md b/builder/src/main/resources/rules/DiamondOperatorForVariableDefinition.md new file mode 100644 index 0000000..134dbf0 --- /dev/null +++ b/builder/src/main/resources/rules/DiamondOperatorForVariableDefinition.md @@ -0,0 +1,12 @@ + +Checks that the diamond operator is used where possible. + +Valid: +```` +Map idTable = new HashMap<>(); +```` + +Invalid: +```` +Map idTable = new HashMap(); +```` diff --git a/builder/src/main/resources/rules/EitherLogOrThrow.md b/builder/src/main/resources/rules/EitherLogOrThrow.md new file mode 100644 index 0000000..1633912 --- /dev/null +++ b/builder/src/main/resources/rules/EitherLogOrThrow.md @@ -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`. diff --git a/builder/src/main/resources/rules/EmptyBlock.md b/builder/src/main/resources/rules/EmptyBlock.md new file mode 100644 index 0000000..4fa7b8e --- /dev/null +++ b/builder/src/main/resources/rules/EmptyBlock.md @@ -0,0 +1,15 @@ + +Checks for empty blocks. + +Valid: +```` +if (a >b) { + doSomething(); +} +```` + +Invalid: +```` +if (a > b) { +} +```` diff --git a/builder/src/main/resources/rules/EmptyCatchBlock.md b/builder/src/main/resources/rules/EmptyCatchBlock.md new file mode 100644 index 0000000..1e24e57 --- /dev/null +++ b/builder/src/main/resources/rules/EmptyCatchBlock.md @@ -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 +} +```` diff --git a/builder/src/main/resources/rules/EmptyForInitializerPad.md b/builder/src/main/resources/rules/EmptyForInitializerPad.md new file mode 100644 index 0000000..e9c2158 --- /dev/null +++ b/builder/src/main/resources/rules/EmptyForInitializerPad.md @@ -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++) {} +```` diff --git a/builder/src/main/resources/rules/EmptyForIteratorPad.md b/builder/src/main/resources/rules/EmptyForIteratorPad.md new file mode 100644 index 0000000..130ba72 --- /dev/null +++ b/builder/src/main/resources/rules/EmptyForIteratorPad.md @@ -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() ; ) {} +```` diff --git a/builder/src/main/resources/rules/EmptyLineSeparator.md b/builder/src/main/resources/rules/EmptyLineSeparator.md new file mode 100644 index 0000000..c577e46 --- /dev/null +++ b/builder/src/main/resources/rules/EmptyLineSeparator.md @@ -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 { + } +} +```` diff --git a/builder/src/main/resources/rules/EmptyStatement.md b/builder/src/main/resources/rules/EmptyStatement.md new file mode 100644 index 0000000..b9b7597 --- /dev/null +++ b/builder/src/main/resources/rules/EmptyStatement.md @@ -0,0 +1,12 @@ + +Checks for empty statements. An empty statement is a standalone semicolon (;). + +Valid: +```` +doSomething(); +```` + +Invalid: +```` +doSomething();; +```` diff --git a/builder/src/main/resources/rules/EnumValueName.md b/builder/src/main/resources/rules/EnumValueName.md new file mode 100644 index 0000000..c389ed7 --- /dev/null +++ b/builder/src/main/resources/rules/EnumValueName.md @@ -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; + } +} +```` diff --git a/builder/src/main/resources/rules/EqualsAvoidNull.md b/builder/src/main/resources/rules/EqualsAvoidNull.md new file mode 100644 index 0000000..079dd17 --- /dev/null +++ b/builder/src/main/resources/rules/EqualsAvoidNull.md @@ -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"); +```` diff --git a/builder/src/main/resources/rules/EqualsHashCode.md b/builder/src/main/resources/rules/EqualsHashCode.md new file mode 100644 index 0000000..cfd3e2a --- /dev/null +++ b/builder/src/main/resources/rules/EqualsHashCode.md @@ -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. diff --git a/builder/src/main/resources/rules/ExecutableStatementCount.md b/builder/src/main/resources/rules/ExecutableStatementCount.md new file mode 100644 index 0000000..09ad91e --- /dev/null +++ b/builder/src/main/resources/rules/ExecutableStatementCount.md @@ -0,0 +1,2 @@ + +Limits the number of executable statements in a method to 30. diff --git a/builder/src/main/resources/rules/ExplicitInitialization.md b/builder/src/main/resources/rules/ExplicitInitialization.md new file mode 100644 index 0000000..62b851c --- /dev/null +++ b/builder/src/main/resources/rules/ExplicitInitialization.md @@ -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; +} +```` diff --git a/builder/src/main/resources/rules/FallThrough.md b/builder/src/main/resources/rules/FallThrough.md new file mode 100644 index 0000000..b4471bf --- /dev/null +++ b/builder/src/main/resources/rules/FallThrough.md @@ -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; +} +```` diff --git a/builder/src/main/resources/rules/FileLength.md b/builder/src/main/resources/rules/FileLength.md new file mode 100644 index 0000000..898710e --- /dev/null +++ b/builder/src/main/resources/rules/FileLength.md @@ -0,0 +1,2 @@ + +Checks that each file has no more than 2000 lines. diff --git a/builder/src/main/resources/rules/FileTabCharacter.md b/builder/src/main/resources/rules/FileTabCharacter.md new file mode 100644 index 0000000..12f1445 --- /dev/null +++ b/builder/src/main/resources/rules/FileTabCharacter.md @@ -0,0 +1,2 @@ + +Checks that there are no tab characters in the source files. diff --git a/builder/src/main/resources/rules/FinalClass.md b/builder/src/main/resources/rules/FinalClass.md new file mode 100644 index 0000000..366fb2e --- /dev/null +++ b/builder/src/main/resources/rules/FinalClass.md @@ -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() {} +} +```` diff --git a/builder/src/main/resources/rules/FinalParameters.md b/builder/src/main/resources/rules/FinalParameters.md new file mode 100644 index 0000000..2a7b97c --- /dev/null +++ b/builder/src/main/resources/rules/FinalParameters.md @@ -0,0 +1,12 @@ + +Parameters to a method must be `final`. + +Valid: +```` +void foo(final int a) {} +```` + +Invalid: +```` +void foo(int a) {} +```` diff --git a/builder/src/main/resources/rules/ForbidCCommentsInMethods.md b/builder/src/main/resources/rules/ForbidCCommentsInMethods.md new file mode 100644 index 0000000..4e54250 --- /dev/null +++ b/builder/src/main/resources/rules/ForbidCCommentsInMethods.md @@ -0,0 +1,16 @@ + +Prevents the use of `/* C-style */` comments inside methods. + +Valid: +```` +void doSomething() { + // a comment +} +```` + +Invalid: +```` +void doSomething() { + /* invalid */ +} +```` diff --git a/builder/src/main/resources/rules/ForbidReturnInFinallyBlock.md b/builder/src/main/resources/rules/ForbidReturnInFinallyBlock.md new file mode 100644 index 0000000..bb3a51c --- /dev/null +++ b/builder/src/main/resources/rules/ForbidReturnInFinallyBlock.md @@ -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 +} +```` diff --git a/builder/src/main/resources/rules/ForbidWildcardAsReturnType.md b/builder/src/main/resources/rules/ForbidWildcardAsReturnType.md new file mode 100644 index 0000000..21b7112 --- /dev/null +++ b/builder/src/main/resources/rules/ForbidWildcardAsReturnType.md @@ -0,0 +1,12 @@ + +Prevents declaring a method from returning a wildcard type as its return value. + +Valid: +```` + List getList() {} +```` + +Invalid: +```` + List getList() {} +```` diff --git a/builder/src/main/resources/rules/GenericWhitespace.md b/builder/src/main/resources/rules/GenericWhitespace.md new file mode 100644 index 0000000..29a088a --- /dev/null +++ b/builder/src/main/resources/rules/GenericWhitespace.md @@ -0,0 +1,13 @@ + +Checks that the angle brackets around Generics parameters have the correct whitespace padding: + +Valid: +```` +public void boolean foo(K, V) {} +class name {} +OrderedPair> p; +boolean same = Util.compare(p1, p2); +Pair p1 = new Pair<>(1, "apple"); +List list = ImmutableList.Builder::new; +sort(list, Comparable::compareTo); +```` diff --git a/builder/src/main/resources/rules/Header.md b/builder/src/main/resources/rules/Header.md new file mode 100644 index 0000000..c02e06f --- /dev/null +++ b/builder/src/main/resources/rules/Header.md @@ -0,0 +1,2 @@ + +Checks that all `*.java` source files begin with the contents of the `LICENSE.txt` file. diff --git a/builder/src/main/resources/rules/HiddenField.md b/builder/src/main/resources/rules/HiddenField.md new file mode 100644 index 0000000..a429561 --- /dev/null +++ b/builder/src/main/resources/rules/HiddenField.md @@ -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) { + // ... + } +} +```` diff --git a/builder/src/main/resources/rules/HideUtilityClassConstructor.md b/builder/src/main/resources/rules/HideUtilityClassConstructor.md new file mode 100644 index 0000000..450ef1a --- /dev/null +++ b/builder/src/main/resources/rules/HideUtilityClassConstructor.md @@ -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) {} +} +```` diff --git a/builder/src/main/resources/rules/IllegalCatch.md b/builder/src/main/resources/rules/IllegalCatch.md new file mode 100644 index 0000000..5d81ef4 --- /dev/null +++ b/builder/src/main/resources/rules/IllegalCatch.md @@ -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 +} +```` diff --git a/builder/src/main/resources/rules/IllegalImport.md b/builder/src/main/resources/rules/IllegalImport.md new file mode 100644 index 0000000..0d04f37 --- /dev/null +++ b/builder/src/main/resources/rules/IllegalImport.md @@ -0,0 +1,7 @@ + +Prevent `import`ing from the `sun.*` packages. + +Invalid: +```` +import sun.security.provider.Sun; +```` diff --git a/builder/src/main/resources/rules/IllegalThrows.md b/builder/src/main/resources/rules/IllegalThrows.md new file mode 100644 index 0000000..7289d1a --- /dev/null +++ b/builder/src/main/resources/rules/IllegalThrows.md @@ -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!"); +```` diff --git a/builder/src/main/resources/rules/IllegalToken.md b/builder/src/main/resources/rules/IllegalToken.md new file mode 100644 index 0000000..18aea95 --- /dev/null +++ b/builder/src/main/resources/rules/IllegalToken.md @@ -0,0 +1,2 @@ + +Checks that labels are not used. diff --git a/builder/src/main/resources/rules/IllegalType.md b/builder/src/main/resources/rules/IllegalType.md new file mode 100644 index 0000000..3ad3725 --- /dev/null +++ b/builder/src/main/resources/rules/IllegalType.md @@ -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 getNames(); +```` + +Invalid: +```` +HashSet getNames(); +```` diff --git a/builder/src/main/resources/rules/InnerAssignment.md b/builder/src/main/resources/rules/InnerAssignment.md new file mode 100644 index 0000000..442bf60 --- /dev/null +++ b/builder/src/main/resources/rules/InnerAssignment.md @@ -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); +```` diff --git a/builder/src/main/resources/rules/InnerTypeLast.md b/builder/src/main/resources/rules/InnerTypeLast.md new file mode 100644 index 0000000..83b0e08 --- /dev/null +++ b/builder/src/main/resources/rules/InnerTypeLast.md @@ -0,0 +1,2 @@ + +Inner classes must appear at the bottom of a class, below fields and methods. diff --git a/builder/src/main/resources/rules/InterfaceIsType.md b/builder/src/main/resources/rules/InterfaceIsType.md new file mode 100644 index 0000000..5cd8320 --- /dev/null +++ b/builder/src/main/resources/rules/InterfaceIsType.md @@ -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!!"; +} +```` diff --git a/builder/src/main/resources/rules/InterfaceTypeParameterName.md b/builder/src/main/resources/rules/InterfaceTypeParameterName.md new file mode 100644 index 0000000..be68dac --- /dev/null +++ b/builder/src/main/resources/rules/InterfaceTypeParameterName.md @@ -0,0 +1,12 @@ + +Checks that the type parameters for an interface are a single uppercase letter. + +Valid: +```` +interface Portable {} +```` + +Invalid: +```` +interface Portable {} +```` diff --git a/builder/src/main/resources/rules/JavaNCSS.md b/builder/src/main/resources/rules/JavaNCSS.md new file mode 100644 index 0000000..c462ea6 --- /dev/null +++ b/builder/src/main/resources/rules/JavaNCSS.md @@ -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. diff --git a/builder/src/main/resources/rules/JavadocMethod.md b/builder/src/main/resources/rules/JavadocMethod.md new file mode 100644 index 0000000..dda8aa1 --- /dev/null +++ b/builder/src/main/resources/rules/JavadocMethod.md @@ -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. diff --git a/builder/src/main/resources/rules/JavadocPackage.md b/builder/src/main/resources/rules/JavadocPackage.md new file mode 100644 index 0000000..5b863ae --- /dev/null +++ b/builder/src/main/resources/rules/JavadocPackage.md @@ -0,0 +1,2 @@ + +Checks that each package has a `package-info.java` file. diff --git a/builder/src/main/resources/rules/JavadocParagraph.md b/builder/src/main/resources/rules/JavadocParagraph.md new file mode 100644 index 0000000..08d0aa1 --- /dev/null +++ b/builder/src/main/resources/rules/JavadocParagraph.md @@ -0,0 +1,2 @@ + +Checks that paragraphs in Javadoc blocks are wrapped in `

` elements and have blank lines between paragraphs. This first paragraph does not need the `

` elements. diff --git a/builder/src/main/resources/rules/JavadocStyle.md b/builder/src/main/resources/rules/JavadocStyle.md new file mode 100644 index 0000000..6dc77fd --- /dev/null +++ b/builder/src/main/resources/rules/JavadocStyle.md @@ -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. diff --git a/builder/src/main/resources/rules/JavadocType.md b/builder/src/main/resources/rules/JavadocType.md new file mode 100644 index 0000000..982268a --- /dev/null +++ b/builder/src/main/resources/rules/JavadocType.md @@ -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. diff --git a/builder/src/main/resources/rules/LeftCurly.md b/builder/src/main/resources/rules/LeftCurly.md new file mode 100644 index 0000000..7c69f72 --- /dev/null +++ b/builder/src/main/resources/rules/LeftCurly.md @@ -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 +{ + +} +```` diff --git a/builder/src/main/resources/rules/LineLength.md b/builder/src/main/resources/rules/LineLength.md new file mode 100644 index 0000000..fce37e7 --- /dev/null +++ b/builder/src/main/resources/rules/LineLength.md @@ -0,0 +1,4 @@ + +Limits the line length to 120 characters. + +Doesn't check package or import lines. diff --git a/builder/src/main/resources/rules/LocalFinalVariableName.md b/builder/src/main/resources/rules/LocalFinalVariableName.md new file mode 100644 index 0000000..831ace8 --- /dev/null +++ b/builder/src/main/resources/rules/LocalFinalVariableName.md @@ -0,0 +1,4 @@ + +Checks the format of local, `final` variable names, including `catch` parameters. + +Identifiers must match `^[a-z][a-zA-Z0-9]*$`. diff --git a/builder/src/main/resources/rules/LocalVariableName.md b/builder/src/main/resources/rules/LocalVariableName.md new file mode 100644 index 0000000..c21e293 --- /dev/null +++ b/builder/src/main/resources/rules/LocalVariableName.md @@ -0,0 +1,4 @@ + +Checks the format of local, non-`final` variable names. + +Identifiers must match `^[a-z][a-zA-Z0-9]*$`. diff --git a/builder/src/main/resources/rules/LogicConditionNeedOptimization.md b/builder/src/main/resources/rules/LogicConditionNeedOptimization.md new file mode 100644 index 0000000..50a05b3 --- /dev/null +++ b/builder/src/main/resources/rules/LogicConditionNeedOptimization.md @@ -0,0 +1,12 @@ + +Prevent the placement of variables or fields after methods in an expression. + +Valid: +```` +if (property && getProperty()) {} +```` + +Invalid: +```` +if (getProperty() && property) {} +```` diff --git a/builder/src/main/resources/rules/MagicNumber.md b/builder/src/main/resources/rules/MagicNumber.md new file mode 100644 index 0000000..4a14f33 --- /dev/null +++ b/builder/src/main/resources/rules/MagicNumber.md @@ -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); +```` diff --git a/builder/src/main/resources/rules/MapIterationInForEachLoop.md b/builder/src/main/resources/rules/MapIterationInForEachLoop.md new file mode 100644 index 0000000..359b645 --- /dev/null +++ b/builder/src/main/resources/rules/MapIterationInForEachLoop.md @@ -0,0 +1,2 @@ + +Checks for unoptimised iterations over `Map`s. Check use of `map.values()`, `map.keySet()` and `map.entrySet()` against the use of the iterator produced to verify if another could be better. diff --git a/builder/src/main/resources/rules/MemberName.md b/builder/src/main/resources/rules/MemberName.md new file mode 100644 index 0000000..763ed38 --- /dev/null +++ b/builder/src/main/resources/rules/MemberName.md @@ -0,0 +1,4 @@ + +Checks the format of non-static field names. + +Identifiers must match `^[a-z][a-zA-Z0-9]*$`. diff --git a/builder/src/main/resources/rules/MethodCount.md b/builder/src/main/resources/rules/MethodCount.md new file mode 100644 index 0000000..0140136 --- /dev/null +++ b/builder/src/main/resources/rules/MethodCount.md @@ -0,0 +1,2 @@ + +Restricts the number of methods in a type to 30. diff --git a/builder/src/main/resources/rules/MethodLength.md b/builder/src/main/resources/rules/MethodLength.md new file mode 100644 index 0000000..0f647b5 --- /dev/null +++ b/builder/src/main/resources/rules/MethodLength.md @@ -0,0 +1,2 @@ + +Restricts the number of lines in a method to 60. Include blank lines and single line comments. You should be able to see an entire method without needing to scroll. diff --git a/builder/src/main/resources/rules/MethodName.md b/builder/src/main/resources/rules/MethodName.md new file mode 100644 index 0000000..514b930 --- /dev/null +++ b/builder/src/main/resources/rules/MethodName.md @@ -0,0 +1,4 @@ + +Checks the format of method names. + +Identifiers must match `^[a-z][a-zA-Z0-9]*$`. diff --git a/builder/src/main/resources/rules/MethodParamPad.md b/builder/src/main/resources/rules/MethodParamPad.md new file mode 100644 index 0000000..b03bdf7 --- /dev/null +++ b/builder/src/main/resources/rules/MethodParamPad.md @@ -0,0 +1,15 @@ + +Checks that the padding between the method identifier and the left parenthesis is on the same line and doesn't have a space in-between. + +Valid: +```` +void getInstance(); +```` + +Invalid: +```` +void getInstance (); + +void getValue + (); +```` diff --git a/builder/src/main/resources/rules/MethodTypeParameterName.md b/builder/src/main/resources/rules/MethodTypeParameterName.md new file mode 100644 index 0000000..efb436c --- /dev/null +++ b/builder/src/main/resources/rules/MethodTypeParameterName.md @@ -0,0 +1,14 @@ + +Restricts method generics parameters to be a single uppercase letter. + +Valid: +```` +List getItems() {} +```` + +Invalid: +```` +List getItems() {} +List getItems() {} +List getItems() {} +```` diff --git a/builder/src/main/resources/rules/MissingDeprecated.md b/builder/src/main/resources/rules/MissingDeprecated.md new file mode 100644 index 0000000..9db91dc --- /dev/null +++ b/builder/src/main/resources/rules/MissingDeprecated.md @@ -0,0 +1,29 @@ + +Both the `@Deprecated` annotation and the Javadoc tag `@deprecated` must be used in pairs. + +Valid: +```` +/** + * Foo. + * + * @deprecated + */ +@Deprecated +void foo() {} +```` + +Invalid: +```` +/** + * Foo. + */ +@Deprecated +void foo() {} + +/** + * Bar. + * + * @deprecated + */ +void bar() {} +```` diff --git a/builder/src/main/resources/rules/MissingSwitchDefault.md b/builder/src/main/resources/rules/MissingSwitchDefault.md new file mode 100644 index 0000000..390c2ba --- /dev/null +++ b/builder/src/main/resources/rules/MissingSwitchDefault.md @@ -0,0 +1,28 @@ + +Checks that `switch` statement has a `default` case. + +Valid: +```` +switch (foo) { + case 1: + // + break; + case 2: + // + break; + default: + throw new IllegalStateExcetion("Foo: " + foo); +} +```` + +Invalid: +```` +switch (foo) { + case 1: + // + break; + case 2: + // + break; +} +```` diff --git a/builder/src/main/resources/rules/ModifiedControlVariable.md b/builder/src/main/resources/rules/ModifiedControlVariable.md new file mode 100644 index 0000000..a77b106 --- /dev/null +++ b/builder/src/main/resources/rules/ModifiedControlVariable.md @@ -0,0 +1,9 @@ + +Checks that the control variable in a `for` loop is not modified inside the loop. + +Invalid: +```` +for (int i = 0; i < 1; i++) { + i++; +} +```` diff --git a/builder/src/main/resources/rules/ModifierOrder.md b/builder/src/main/resources/rules/ModifierOrder.md new file mode 100644 index 0000000..ebc469c --- /dev/null +++ b/builder/src/main/resources/rules/ModifierOrder.md @@ -0,0 +1,16 @@ + +Check that modifiers are in the following order: + +* `public` +* `protected` +* `private` +* `abstract` +* `static` +* `final` +* `transient` +* `volatile` +* `synchronized` +* `native` +* `strictfp` + +Type annotations are ignored. diff --git a/builder/src/main/resources/rules/MultipleStringLiterals.md b/builder/src/main/resources/rules/MultipleStringLiterals.md new file mode 100644 index 0000000..58c3737 --- /dev/null +++ b/builder/src/main/resources/rules/MultipleStringLiterals.md @@ -0,0 +1,7 @@ + +Checks for multiple occurrences of the same string literal within a single file. Does not apply to empty strings (""). + +Invalid: +```` +String fooFoo = "foo" + "foo"; +```` diff --git a/builder/src/main/resources/rules/MultipleVariableDeclarations.md b/builder/src/main/resources/rules/MultipleVariableDeclarations.md new file mode 100644 index 0000000..efe6f25 --- /dev/null +++ b/builder/src/main/resources/rules/MultipleVariableDeclarations.md @@ -0,0 +1,13 @@ + +Checks that each variable is declared in its own statement and line. + +Valid: +```` +int a; +int b; +```` + +Invalid: +```` +int a, b; +```` diff --git a/builder/src/main/resources/rules/MutableException.md b/builder/src/main/resources/rules/MutableException.md new file mode 100644 index 0000000..704d664 --- /dev/null +++ b/builder/src/main/resources/rules/MutableException.md @@ -0,0 +1,8 @@ + +Checks that `Exception` classes are immutable. However, you can still call `setStackTrace`. + +Classes checked are those whose name ends with the following. Or that the class they extend does. + +* `Exception` +* `Error` +* `Throwable` diff --git a/builder/src/main/resources/rules/NPathComplexity.md b/builder/src/main/resources/rules/NPathComplexity.md new file mode 100644 index 0000000..e0764c7 --- /dev/null +++ b/builder/src/main/resources/rules/NPathComplexity.md @@ -0,0 +1,2 @@ + +Checks that the NPATH score (number of paths) through a method is no more than 5. This is similar to [Cyclomatic Complexity](#cyclomaticcomplexity). diff --git a/builder/src/main/resources/rules/NameConventionForJunit4TestClasses.md b/builder/src/main/resources/rules/NameConventionForJunit4TestClasses.md new file mode 100644 index 0000000..0567e37 --- /dev/null +++ b/builder/src/main/resources/rules/NameConventionForJunit4TestClasses.md @@ -0,0 +1,4 @@ + +Checks the names of JUnit test classes. Classes checked are those that have at least one method annotated with `Test` or `org.junit.Test`. + +Test class names must match: `.+Test\\d*|.+Tests\\d*|Test.+|Tests.+|.+IT|.+ITs|.+TestCase\\d*|.+TestCases\\d*` diff --git a/builder/src/main/resources/rules/NeedBraces.md b/builder/src/main/resources/rules/NeedBraces.md new file mode 100644 index 0000000..71bee0f --- /dev/null +++ b/builder/src/main/resources/rules/NeedBraces.md @@ -0,0 +1,32 @@ + +Check that code blocks are surrounded by braces. + +Valid: +```` +if (obj.isValid()) { + return true; +} + +while (obj.isValid()) { + return true; +} + +do { + this.notify(); +} while (o != null); + +for (int i = 0; ;) { + this.notify(); +} +```` + +Invalid: +```` +if (obj.isValid()) return true; + +while (obj.isValid()) return true; + +do this.notify(); while (o != null); + +for (int i = 0; ;) this.notify(); +```` diff --git a/builder/src/main/resources/rules/NestedForDepth.md b/builder/src/main/resources/rules/NestedForDepth.md new file mode 100644 index 0000000..e70236c --- /dev/null +++ b/builder/src/main/resources/rules/NestedForDepth.md @@ -0,0 +1,22 @@ + +Checks that `for` loops are not nested more than 1 deep. + +Valid: +```` +for (int i = 0; i < 1; i++) { // depth 0 + for (int j = 0; j < 1; j++) { // depth 1 + // + } +} +```` + +Invalid: +```` +for (int i = 0; i < 1; i++) { // depth 0 + for (int j = 0; j < 1; j++) { // depth 1 + for (int k = 0; j < 1; k++) { // depth 2! + // + } + } +} +```` diff --git a/builder/src/main/resources/rules/NestedIfDepth.md b/builder/src/main/resources/rules/NestedIfDepth.md new file mode 100644 index 0000000..3657433 --- /dev/null +++ b/builder/src/main/resources/rules/NestedIfDepth.md @@ -0,0 +1,22 @@ + +Checks that `if` blocks are not nested more than 1 deep. + +Valid: +```` +if (isValid()) { // depth 0 + if (isExpected()) { // depth 1 + doIt(); + } +} +```` + +Invalid: +```` +if (isValid()) { // depth 0 + if (isExpected()) { // depth 1 + if (isNecessary()) { // depth 2! + doIt(); + } + } +} +```` diff --git a/builder/src/main/resources/rules/NestedSwitch.md b/builder/src/main/resources/rules/NestedSwitch.md new file mode 100644 index 0000000..74af425 --- /dev/null +++ b/builder/src/main/resources/rules/NestedSwitch.md @@ -0,0 +1,47 @@ + +Checks that `switch` statements are not nested within one another. + +Valid: +```` +void doSomething(int a, int b) { + + switch(a) { + case 1: + doMore(b); + break; + case 2: + // .. + } + } +} + +void doMore(int b) { + + switch(b) { + case 1: + // + case 2: + // + } +} +```` + +Invalid: +```` +void doSomething(int a, int b) { + + switch(a) { + case 1: + switch(b) { + case 1: + // + case 2: + // + } + break; + case 2: + // .. + } + } +} +```` diff --git a/builder/src/main/resources/rules/NestedTryDepth.md b/builder/src/main/resources/rules/NestedTryDepth.md new file mode 100644 index 0000000..52803f3 --- /dev/null +++ b/builder/src/main/resources/rules/NestedTryDepth.md @@ -0,0 +1,28 @@ + +Checks that `try` blocks are not nested. + +Valid: +```` +try { + doSomething(); + doSomeOtherThing(); +} catch (SomeException se) { + // handle it +} catch (OtherExceptions oe) { + // handle it +} +```` + +Invalid: +```` +try { + doSomething(); + try { + doSomeOtherThing(); + } catch (OtherExceptions oe) { + // handle it + } +} catch (SomeException se) { + // handle it +} +```` diff --git a/builder/src/main/resources/rules/NewlineAtEndOfFile.md b/builder/src/main/resources/rules/NewlineAtEndOfFile.md new file mode 100644 index 0000000..4c6c176 --- /dev/null +++ b/builder/src/main/resources/rules/NewlineAtEndOfFile.md @@ -0,0 +1,2 @@ + +Checks that files end with a line-feed character, (i.e. unix-style line ending). diff --git a/builder/src/main/resources/rules/NoClone.md b/builder/src/main/resources/rules/NoClone.md new file mode 100644 index 0000000..6cf0e0a --- /dev/null +++ b/builder/src/main/resources/rules/NoClone.md @@ -0,0 +1,6 @@ + +> This check cannot be suppressed. + +Checks that the `clone()` method from `Object` has not been overridden. Use a copy constructor, or better yet, a static factory method. + +> See [Effective Java], 2nd Edition by Josh Bloch: Item 11: Override clone judiciously. diff --git a/builder/src/main/resources/rules/NoFinalizer.md b/builder/src/main/resources/rules/NoFinalizer.md new file mode 100644 index 0000000..8ca9790 --- /dev/null +++ b/builder/src/main/resources/rules/NoFinalizer.md @@ -0,0 +1,4 @@ + +Checks that the `finalize()` method from `Object` has not been overridden. + +> See [Effective Java], 2nd Edition by Josh Bloch: Item 7: Avoid finalizers. diff --git a/builder/src/main/resources/rules/NoLineWrap.md b/builder/src/main/resources/rules/NoLineWrap.md new file mode 100644 index 0000000..8304ab0 --- /dev/null +++ b/builder/src/main/resources/rules/NoLineWrap.md @@ -0,0 +1,2 @@ + +Prevents wrapping of `package` and `import` statements. diff --git a/builder/src/main/resources/rules/NoMainMethodInAbstractClass.md b/builder/src/main/resources/rules/NoMainMethodInAbstractClass.md new file mode 100644 index 0000000..912ab2a --- /dev/null +++ b/builder/src/main/resources/rules/NoMainMethodInAbstractClass.md @@ -0,0 +1,2 @@ + +Prevents a `main` method from existing in an `abstract` class. diff --git a/builder/src/main/resources/rules/NoWhitespaceAfter.md b/builder/src/main/resources/rules/NoWhitespaceAfter.md new file mode 100644 index 0000000..bdf5ee9 --- /dev/null +++ b/builder/src/main/resources/rules/NoWhitespaceAfter.md @@ -0,0 +1,30 @@ + +Checks that there is no whitespace after the array init ('{'), prefix increment ('++'), prefix decrement ('--'), bitwise complement ('~'), logical complement ('!'), array declaration ('[' in `int[] a;`) or array index operator ('[' in `a[2]`). + +Valid: +```` +int[] y = {1, 2}; +++i; +--i; +int j = -1; +int k = +1; +int l = ~2; +boolean state = !isReady(); +int b = o.getValue(); +int[] a; +int d = a[2]; +```` + +Invalid: +```` +int[] y = { 1, 2 }; +++ i; +-- i; +int j = - 1; +int k = + 1; +int l = ~ 2; +boolean state = ! isReady(); +int b = o. getValue(); +int[ ] a; +int d = a[ 2]; +```` diff --git a/builder/src/main/resources/rules/NoWhitespaceBefore.md b/builder/src/main/resources/rules/NoWhitespaceBefore.md new file mode 100644 index 0000000..0be2a07 --- /dev/null +++ b/builder/src/main/resources/rules/NoWhitespaceBefore.md @@ -0,0 +1,18 @@ + +Checks that there is no whitespace before the comma operator (','), statement terminator (';'), postfix increment ('++') or postfix decrement ('--'). + +Valid: +```` +int y = {1, 2}; +doSomething(); +i++; +i--; +```` + +Invalid: +```` +int y = {1 , 2}; +doSomething() ; +i ++; +i --; +```` diff --git a/builder/src/main/resources/rules/NonEmptyAtclauseDescription.md b/builder/src/main/resources/rules/NonEmptyAtclauseDescription.md new file mode 100644 index 0000000..74e4c3f --- /dev/null +++ b/builder/src/main/resources/rules/NonEmptyAtclauseDescription.md @@ -0,0 +1,20 @@ + +Checks that the Javadoc clauses `@param`, `@return`, `@throws` and `@deprecated` all have descriptions. + +Valid: +```` +/** + * Foo. + * + * @returns the foo + */ +```` + +Invalid: +```` +/** + * Foo. + * + * @returns + */ +```` diff --git a/builder/src/main/resources/rules/NumericLiteralNeedsUnderscore.md b/builder/src/main/resources/rules/NumericLiteralNeedsUnderscore.md new file mode 100644 index 0000000..c509c42 --- /dev/null +++ b/builder/src/main/resources/rules/NumericLiteralNeedsUnderscore.md @@ -0,0 +1,17 @@ + +Checks that numeric literals use underscores ('_') if over a certain length. + +* Decimals + + * 7 or more digits must use the underscore + * No more than 3 digits between underscores + +* Hex + + * 5 or more digits must use the underscore + * No more than 4 digits between underscores + +* Binary + + * 9 or more digits must use the underscore + * No more than 8 digits between underscores diff --git a/builder/src/main/resources/rules/OneStatementPerLine.md b/builder/src/main/resources/rules/OneStatementPerLine.md new file mode 100644 index 0000000..7ea4355 --- /dev/null +++ b/builder/src/main/resources/rules/OneStatementPerLine.md @@ -0,0 +1,13 @@ + +Checks that there is only one statement per line. + +Valid: +```` +doSomething(); +doSomethingElse(); +```` + +Invalid: +```` +doSomething(); doSomethingElse(); +```` diff --git a/builder/src/main/resources/rules/OneTopLevelClass.md b/builder/src/main/resources/rules/OneTopLevelClass.md new file mode 100644 index 0000000..eaae30e --- /dev/null +++ b/builder/src/main/resources/rules/OneTopLevelClass.md @@ -0,0 +1,4 @@ + +> This check cannot be suppressed. + +Checks that each source file contains only one top-level class, interface or enum. diff --git a/builder/src/main/resources/rules/OperatorWrap.md b/builder/src/main/resources/rules/OperatorWrap.md new file mode 100644 index 0000000..6af32fb --- /dev/null +++ b/builder/src/main/resources/rules/OperatorWrap.md @@ -0,0 +1,14 @@ + +Checks that when wrapping a line on an operator that the operator appears on the new line. + +Valid: +```` +int answer = getTheAnswerToLife() + getTheAnswerToTheUniverse() + + getTheAnswerToEverything(); +```` + +Invalid: +```` +int answer = getTheAnswerToLife() + getTheAnswerToTheUniverse() + + getTheAnswerToEverything(); +```` diff --git a/builder/src/main/resources/rules/OuterTypeFilename.md b/builder/src/main/resources/rules/OuterTypeFilename.md new file mode 100644 index 0000000..2638311 --- /dev/null +++ b/builder/src/main/resources/rules/OuterTypeFilename.md @@ -0,0 +1,4 @@ + +> This check cannot be suppressed. + +Checks that the source filename matches the name of the top-level class. e.g. `class Foo {}` is in file `Foo.java`. diff --git a/builder/src/main/resources/rules/OverloadMethodsDeclarationOrder.md b/builder/src/main/resources/rules/OverloadMethodsDeclarationOrder.md new file mode 100644 index 0000000..f521c12 --- /dev/null +++ b/builder/src/main/resources/rules/OverloadMethodsDeclarationOrder.md @@ -0,0 +1,2 @@ + +Checks that overload methods are grouped together in the source file. diff --git a/builder/src/main/resources/rules/OverridableMethodInConstructor.md b/builder/src/main/resources/rules/OverridableMethodInConstructor.md new file mode 100644 index 0000000..8c82eb6 --- /dev/null +++ b/builder/src/main/resources/rules/OverridableMethodInConstructor.md @@ -0,0 +1,21 @@ + +Prevents calls to overridable methods from constuctors including other methods that perform the same functions. (i.e. `Cloneable.clone()` and `Serializable.readObject()`) + +Invalid: +```` +abstract class Base { + Base() { + overrideMe(); + } +} +class Child extends Base { + final int x; + Child(int x) { + this.x = x; + } + void overrideMe() { + System.out.println(x); + } +} +new Child(42); // prints "0" +```` diff --git a/builder/src/main/resources/rules/PackageAnnotation.md b/builder/src/main/resources/rules/PackageAnnotation.md new file mode 100644 index 0000000..436e3ff --- /dev/null +++ b/builder/src/main/resources/rules/PackageAnnotation.md @@ -0,0 +1,2 @@ + +Checks that package level annotations are in the `package-info.java` file. diff --git a/builder/src/main/resources/rules/PackageDeclaration.md b/builder/src/main/resources/rules/PackageDeclaration.md new file mode 100644 index 0000000..8ea13e9 --- /dev/null +++ b/builder/src/main/resources/rules/PackageDeclaration.md @@ -0,0 +1,4 @@ + +> This check cannot be suppressed. + +Checks that the class has a `package` definition. diff --git a/builder/src/main/resources/rules/PackageName.md b/builder/src/main/resources/rules/PackageName.md new file mode 100644 index 0000000..11c7f62 --- /dev/null +++ b/builder/src/main/resources/rules/PackageName.md @@ -0,0 +1,4 @@ + +Checks the format of package names. Only lowercase letters, no initial numbers or any underscores. + +Identifiers must match `^[a-z]+(\.[a-z][a-z0-9]+)*$`. diff --git a/builder/src/main/resources/rules/ParameterName.md b/builder/src/main/resources/rules/ParameterName.md new file mode 100644 index 0000000..8e7a772 --- /dev/null +++ b/builder/src/main/resources/rules/ParameterName.md @@ -0,0 +1,4 @@ + +Checks the format of method parameter names, including `catch` parameters. + +Identifiers must match `^[a-z][a-zA-Z0-9]*$`. diff --git a/builder/src/main/resources/rules/ParameterNumber.md b/builder/src/main/resources/rules/ParameterNumber.md new file mode 100644 index 0000000..8e5b8e5 --- /dev/null +++ b/builder/src/main/resources/rules/ParameterNumber.md @@ -0,0 +1,2 @@ + +Restricts the number of parameters in a method or constructor to 7. Overridden methods are not checked as there may be no access to change the super method. diff --git a/builder/src/main/resources/rules/ParenPad.md b/builder/src/main/resources/rules/ParenPad.md new file mode 100644 index 0000000..eb70267 --- /dev/null +++ b/builder/src/main/resources/rules/ParenPad.md @@ -0,0 +1,15 @@ + +Checks that there are no spaces padding parentheses. + +Valid: +```` +doSomething(); +doSomethingElse(5); +```` + +Invalid: +```` +doSomething( ); +doSomethingElse( 5); +doSomethingElse(5 ); +```` diff --git a/builder/src/main/resources/rules/PublicReferenceToPrivateType.md b/builder/src/main/resources/rules/PublicReferenceToPrivateType.md new file mode 100644 index 0000000..6b78de5 --- /dev/null +++ b/builder/src/main/resources/rules/PublicReferenceToPrivateType.md @@ -0,0 +1,14 @@ + +Checks that a type is not exposed outside its declared scope. + +Invalid: +```` +public class OuterClass { + public InnerClass inner = new InnerClass(); + public SiblingClass sibling = new SiblingClass(); + public InnerClass getValue() { return new InnerClass(); } + public SiblingClass getSibling() { return new SiblingClass(); } + private class InnerClass {} +} +class SiblingClass {} +```` diff --git a/builder/src/main/resources/rules/RedundantModifier.md b/builder/src/main/resources/rules/RedundantModifier.md new file mode 100644 index 0000000..1732f35 --- /dev/null +++ b/builder/src/main/resources/rules/RedundantModifier.md @@ -0,0 +1,8 @@ + +Checks for redundant modifiers. Checks for: + +* Interface and annotation definitions. +* Final modifier on methods of final and anonymous classes. +* Inner interface declarations that are declared as static. +* Class constructors. +* Nested enum definitions that are declared as static. diff --git a/builder/src/main/resources/rules/RedundantReturn.md b/builder/src/main/resources/rules/RedundantReturn.md new file mode 100644 index 0000000..50974bf --- /dev/null +++ b/builder/src/main/resources/rules/RedundantReturn.md @@ -0,0 +1,14 @@ + +Checks for redundant return statements. + +Invalid: +```` +HelloWorld() { + doStuff(); + return; +} +void doStuff() { + doMoreStuff(); + return; +} +```` diff --git a/builder/src/main/resources/rules/RequireThis.md b/builder/src/main/resources/rules/RequireThis.md new file mode 100644 index 0000000..5eab1a6 --- /dev/null +++ b/builder/src/main/resources/rules/RequireThis.md @@ -0,0 +1,2 @@ + +Checks that references to instance fields where a parameter name overlaps are qualified by `this.`. diff --git a/builder/src/main/resources/rules/ReturnBooleanFromTernary.md b/builder/src/main/resources/rules/ReturnBooleanFromTernary.md new file mode 100644 index 0000000..2f7f7fd --- /dev/null +++ b/builder/src/main/resources/rules/ReturnBooleanFromTernary.md @@ -0,0 +1,14 @@ + +Ternary statements shouldn't have `Boolean` values as results. + +Valid: +```` +Boolean set = isSet() ? True : False; +Boolean notReady = isReady() ? False : True; +```` + +Invalid: +```` +Boolean set = isSet(); +Boolean notReady = !isReady(); +```` diff --git a/builder/src/main/resources/rules/ReturnCount.md b/builder/src/main/resources/rules/ReturnCount.md new file mode 100644 index 0000000..b5995c1 --- /dev/null +++ b/builder/src/main/resources/rules/ReturnCount.md @@ -0,0 +1,40 @@ + +Restricts methods to have at most 2 `return` statements in non-void methods, and at most 1 in void methods. + +Valid: +```` +int getNumber(int a) { + if (a > 1) { + return a; + } + return 0; +} + +void getName(int a) { + String name = "default"; + if (a > 1) { + name = "Bob"; + } + return name; +} +```` + +Invalid: +```` +int getNumber(int a) { + if (a > 1) { + return a; + } + if (a < 2) { + return a * a; + } + return 0; +} + +void getName(int a) { + if (a > 1) { + return "Bob"; + } + return "default"; +} +```` diff --git a/builder/src/main/resources/rules/ReturnNullInsteadOfBoolean.md b/builder/src/main/resources/rules/ReturnNullInsteadOfBoolean.md new file mode 100644 index 0000000..737bf38 --- /dev/null +++ b/builder/src/main/resources/rules/ReturnNullInsteadOfBoolean.md @@ -0,0 +1,15 @@ + +The `Boolean` type is meant to only represent a binary state: TRUE or FALSE. It is not a ternary value: TRUE, FALSE, null. + +Invalid: +```` +Boolean isEnabled() { + if (level > 0) { + return True; + } + if (level < 0) { + return False; + } + return null; +} +```` \ No newline at end of file diff --git a/builder/src/main/resources/rules/RightCurly.md b/builder/src/main/resources/rules/RightCurly.md new file mode 100644 index 0000000..90407db --- /dev/null +++ b/builder/src/main/resources/rules/RightCurly.md @@ -0,0 +1,45 @@ + +Checks that the right curly brace ('}') is placed on the same line as the next part of a multi-block statement (e.g. try-catch-finally, if-then-else). + +Valid: +```` +try { + // +} catch (Exception e) { + // +} finally { + // +} + +if (a > 0) { + // +} else { + // +} +```` + +Invalid: +```` +try { + // +} +catch (Exception e) { + // +} +finally { + // +} + +if (a > 0) { + // +} +else { + // +} + +if (a > 0) { + // +} a = 2; + +public long getId() {return id;} +```` diff --git a/builder/src/main/resources/rules/SeparatorWrap.md b/builder/src/main/resources/rules/SeparatorWrap.md new file mode 100644 index 0000000..1f3db49 --- /dev/null +++ b/builder/src/main/resources/rules/SeparatorWrap.md @@ -0,0 +1,21 @@ + +Checks the line wrapping around separators. + +* The comma separator (',') should be at the end of the line. +* The dot separator ('.') should be on the new line. + +Valid: +```` +doSomething(alpha, beta, + gamma); +doSomethingElse().stream() + .forEach(System.out::println); +```` + +Invalid: +```` +doSomething(alpha, beta + , gamma); +doSomethingElse().stream(). + forEach(System.out::println); +```` diff --git a/builder/src/main/resources/rules/SimpleAccessorNameNotation.md b/builder/src/main/resources/rules/SimpleAccessorNameNotation.md new file mode 100644 index 0000000..5f2212c --- /dev/null +++ b/builder/src/main/resources/rules/SimpleAccessorNameNotation.md @@ -0,0 +1,2 @@ + +Checks that setters and getters follow the normal setField(), getField() and isField() pattern, where 'Field' is the name of the field being accessed. diff --git a/builder/src/main/resources/rules/SimplifyBooleanExpression.md b/builder/src/main/resources/rules/SimplifyBooleanExpression.md new file mode 100644 index 0000000..3ab6d91 --- /dev/null +++ b/builder/src/main/resources/rules/SimplifyBooleanExpression.md @@ -0,0 +1,15 @@ + +Checks for overly complicated boolean expressions. Checks for code like `b == true`, `b || true`, `!false`, etc. + +Valid: +```` +if (b) {} +if (true) {} +```` + +Invalid: +```` +if (b == true) {} +if (b || true) {} +if (!false) {} +```` diff --git a/builder/src/main/resources/rules/SimplifyBooleanReturn.md b/builder/src/main/resources/rules/SimplifyBooleanReturn.md new file mode 100644 index 0000000..4e782dc --- /dev/null +++ b/builder/src/main/resources/rules/SimplifyBooleanReturn.md @@ -0,0 +1,16 @@ + +Checks for overly complicated boolean `return` statements. + +Valid: +```` +return !valid(); +```` + +Invalid: +```` +if (valid()) { + return false; +} else { + return true; +} +```` diff --git a/builder/src/main/resources/rules/SingleBreakOrContinue.md b/builder/src/main/resources/rules/SingleBreakOrContinue.md new file mode 100644 index 0000000..f3f8a8d --- /dev/null +++ b/builder/src/main/resources/rules/SingleBreakOrContinue.md @@ -0,0 +1,2 @@ + +Checks that there is at most one `continue` or `break` statement within a looping block (e.g. `for`, `while`, ...) diff --git a/builder/src/main/resources/rules/SingleSpaceSeparator.md b/builder/src/main/resources/rules/SingleSpaceSeparator.md new file mode 100644 index 0000000..69b6d06 --- /dev/null +++ b/builder/src/main/resources/rules/SingleSpaceSeparator.md @@ -0,0 +1,14 @@ + +Checks that non-whitespace characters on the same line are separated by no more than one whitespace. + +Valid: +```` +if (a < 0) {} +public long toNanos(long d) { return d; }; +```` + +Invalid: +```` +if (a < 0) {} +public long toNanos(long d) { return d; }; +```` diff --git a/builder/src/main/resources/rules/StaticVariableName.md b/builder/src/main/resources/rules/StaticVariableName.md new file mode 100644 index 0000000..7276bdb --- /dev/null +++ b/builder/src/main/resources/rules/StaticVariableName.md @@ -0,0 +1,4 @@ + +Checks the format of `static`, non-`final` variable names. + +Identifiers must match `^[a-z][a-zA-Z0-9]*$`. diff --git a/builder/src/main/resources/rules/StringLiteralEquality.md b/builder/src/main/resources/rules/StringLiteralEquality.md new file mode 100644 index 0000000..7909cf4 --- /dev/null +++ b/builder/src/main/resources/rules/StringLiteralEquality.md @@ -0,0 +1,12 @@ + +Checks that string literals are not used with `==` or `!=`. + +Valid: +```` +if ("something".equals(x)) {} +```` + +Invalid: +```` +if (x == "something") {} +```` diff --git a/builder/src/main/resources/rules/SuppressWarnings.md b/builder/src/main/resources/rules/SuppressWarnings.md new file mode 100644 index 0000000..0912bd2 --- /dev/null +++ b/builder/src/main/resources/rules/SuppressWarnings.md @@ -0,0 +1,12 @@ + +Prevents the use of `@SuppressWarnings` for the following checks: + +* [ConstantName](#constantname) +* [CovariantEquals](#covariantequals) +* [EqualsHashCode](#equalshashcode) +* [NoClone](#noclone) +* [OneTopLevelClass](#onetoplevelclass) +* [OuterTypeFilename](#outertypefilename) +* [PackageDeclaration](#packagedeclaration) +* [TypeName](#typename) +* [VisibilityModifier](#visibilitymodifier) diff --git a/builder/src/main/resources/rules/SuppressWarningsFilter.md b/builder/src/main/resources/rules/SuppressWarningsFilter.md new file mode 100644 index 0000000..3bc1f3e --- /dev/null +++ b/builder/src/main/resources/rules/SuppressWarningsFilter.md @@ -0,0 +1,2 @@ + +Allows the use of the `@SuppressWarnings` annotation. diff --git a/builder/src/main/resources/rules/SuppressWarningsHolder.md b/builder/src/main/resources/rules/SuppressWarningsHolder.md new file mode 100644 index 0000000..ed7fd00 --- /dev/null +++ b/builder/src/main/resources/rules/SuppressWarningsHolder.md @@ -0,0 +1,2 @@ + +Used by Checkstyle to hold the checks to be suppressed from `@SuppressWarnings(...)` annotations. diff --git a/builder/src/main/resources/rules/TernaryPerExpressionCount.md b/builder/src/main/resources/rules/TernaryPerExpressionCount.md new file mode 100644 index 0000000..97d1918 --- /dev/null +++ b/builder/src/main/resources/rules/TernaryPerExpressionCount.md @@ -0,0 +1,7 @@ + +Checks that there is at most one ternary statments (`?:`) within an expression. + +Invalid: +```` +String x = value != null ? "A" : "B" + value == null ? "C" : "D" +```` diff --git a/builder/src/main/resources/rules/ThrowsCount.md b/builder/src/main/resources/rules/ThrowsCount.md new file mode 100644 index 0000000..87018e6 --- /dev/null +++ b/builder/src/main/resources/rules/ThrowsCount.md @@ -0,0 +1,17 @@ + +Restricts non-private methods to only `throws` 4 distinct Exception types. Exceptions should be hierarchical to allow catching suitable root Exceptions. + +See [Effective Java], 2nd Edition, Chapter 9: Exceptions + +Valid: +```` +void doSomething() throws IllegalStateException, DowsingServiceException, + BalancedBudgetException, ManagementInterferanceException {} +```` + +Invalid: +```` +void doSomething() throws IllegalStateException, + DowsingNotPermittedException, DowsingServiceNotReadyException, + BalancedBudgetException, ManagementInterferanceException {} +```` diff --git a/builder/src/main/resources/rules/TodoComment.md b/builder/src/main/resources/rules/TodoComment.md new file mode 100644 index 0000000..9275789 --- /dev/null +++ b/builder/src/main/resources/rules/TodoComment.md @@ -0,0 +1,2 @@ + +Checks for remaining `TODO` and `FIXME` comments left in code. Their presence indicates that the program isn't finished yet. diff --git a/builder/src/main/resources/rules/TrailingComment.md b/builder/src/main/resources/rules/TrailingComment.md new file mode 100644 index 0000000..8ca7695 --- /dev/null +++ b/builder/src/main/resources/rules/TrailingComment.md @@ -0,0 +1,26 @@ + +Checks for comments at the end of lines. + +Valid: +```` +// comment on line by itself + // comment after white space +if (a < 1) { + // +} // comment on closing brace +int[] a = new int[2]( + 1, 2 +); // comment on closing parenthesis of statement +```` + +Invalid: +```` +int a = 1; // comment in line with statement +if (a < 1) { // comment on line with if statement + // +} +int[] a = new int[2]( + 1, // first value - invalid comment + 2 // second value - also invalid comment +); +```` diff --git a/builder/src/main/resources/rules/Translation.md b/builder/src/main/resources/rules/Translation.md new file mode 100644 index 0000000..a88a774 --- /dev/null +++ b/builder/src/main/resources/rules/Translation.md @@ -0,0 +1,2 @@ + +Checks that all `messages*.properties` files all have the same set of keys. diff --git a/builder/src/main/resources/rules/TypeName.md b/builder/src/main/resources/rules/TypeName.md new file mode 100644 index 0000000..96e51a7 --- /dev/null +++ b/builder/src/main/resources/rules/TypeName.md @@ -0,0 +1,6 @@ + +> This check cannot be suppressed. + +Checks the format of `class`, `interface`, `enum` identifiers, including annotations. + +Identifiers must match `^[A-Z][a-zA-Z0-9]*$`. diff --git a/builder/src/main/resources/rules/TypecastParenPad.md b/builder/src/main/resources/rules/TypecastParenPad.md new file mode 100644 index 0000000..f6cb182 --- /dev/null +++ b/builder/src/main/resources/rules/TypecastParenPad.md @@ -0,0 +1,14 @@ + +Checks that there are no spaces within the typecasting parentheses. + +Valid: +```` +String s = (String) list.get(2); +```` + +Invalid: +```` +String s = (String ) list.get(2); +String s = ( String) list.get(2); +String s = ( String ) list.get(2); +```` diff --git a/builder/src/main/resources/rules/UncommentedMain.md b/builder/src/main/resources/rules/UncommentedMain.md new file mode 100644 index 0000000..c49f646 --- /dev/null +++ b/builder/src/main/resources/rules/UncommentedMain.md @@ -0,0 +1,2 @@ + +Checks for `public static void main()` methods that may have been left over from testing. Allowed in classes whose names end in `Main` or `Application`. diff --git a/builder/src/main/resources/rules/UniformEnumConstantName.md b/builder/src/main/resources/rules/UniformEnumConstantName.md new file mode 100644 index 0000000..7e6a7c1 --- /dev/null +++ b/builder/src/main/resources/rules/UniformEnumConstantName.md @@ -0,0 +1,20 @@ + +Checks that all the values of an `enum` follow the same naming pattern. + +Valid: +```` +public enum EnumOne { + FirstElement, SecondElement, ThirdElement; +} + +public enum EnumTwo { + FIRST_ELEMENT, SECOND_ELEMENT, THIRD_ELEMENT; +} +```` + +Invalid: +```` +public enum EnumThree { + FirstElement, SECOND_ELEMENT, ThirdElement; +} +```` diff --git a/builder/src/main/resources/rules/UniqueProperties.md b/builder/src/main/resources/rules/UniqueProperties.md new file mode 100644 index 0000000..b05a11f --- /dev/null +++ b/builder/src/main/resources/rules/UniqueProperties.md @@ -0,0 +1,2 @@ + +Checks `*.properties` files for duplicate property keys. diff --git a/builder/src/main/resources/rules/UnnecessaryParentheses.md b/builder/src/main/resources/rules/UnnecessaryParentheses.md new file mode 100644 index 0000000..b00deb1 --- /dev/null +++ b/builder/src/main/resources/rules/UnnecessaryParentheses.md @@ -0,0 +1,12 @@ + +Checks for the use of unnecessary parentheses. + +Valid: +```` +if (a < 1) {} +```` + +Invalid: +```` +if ((a < 1)) {} +```` diff --git a/builder/src/main/resources/rules/UnusedImports.md b/builder/src/main/resources/rules/UnusedImports.md new file mode 100644 index 0000000..40bcd9e --- /dev/null +++ b/builder/src/main/resources/rules/UnusedImports.md @@ -0,0 +1,10 @@ + +Checks for unused imports. Does not inspect wildcard imports, which should be blocked by [AvoidStarImport](#avoidstarimport) anyway. + +Imports are unused if: + +* They are not referenced in the file. +* It duplicates another import. +* It import from the `java.lang` package. +* It imports a class from the same package. +* It is only references from the Javadoc. diff --git a/builder/src/main/resources/rules/UpperEll.md b/builder/src/main/resources/rules/UpperEll.md new file mode 100644 index 0000000..1d51368 --- /dev/null +++ b/builder/src/main/resources/rules/UpperEll.md @@ -0,0 +1,12 @@ + +Checks that `long` numeric literal values are marked by an upper-case ell ('L'). The lower-case ell ('l') can be mistaken for the numeral one ('1'). + +Valid: +```` +long id = 12345L; +```` + +Invalid: +```` +long id = 12345l; +```` diff --git a/builder/src/main/resources/rules/UselessSingleCatch.md b/builder/src/main/resources/rules/UselessSingleCatch.md new file mode 100644 index 0000000..671e33e --- /dev/null +++ b/builder/src/main/resources/rules/UselessSingleCatch.md @@ -0,0 +1,11 @@ + +Checks for catch blocks that are useless. i.e. that catch al exceptions and then just rethrow them. + +Invalid: +```` +try { + doSomething(); +} catch (Exception e) { + throw e; +} +```` diff --git a/builder/src/main/resources/rules/UselessSuperCtorCall.md b/builder/src/main/resources/rules/UselessSuperCtorCall.md new file mode 100644 index 0000000..7435aa9 --- /dev/null +++ b/builder/src/main/resources/rules/UselessSuperCtorCall.md @@ -0,0 +1,16 @@ + +Checks for useless calls the the `super()` method in constructors. + +Invalid: +```` +class Dummy { + Dummy() { + super(); + } +} +class Derived extends Base { + Derived() { + super(); + } +} +```` \ No newline at end of file diff --git a/builder/src/main/resources/rules/VariableDeclarationUsageDistance.md b/builder/src/main/resources/rules/VariableDeclarationUsageDistance.md new file mode 100644 index 0000000..f5d7d30 --- /dev/null +++ b/builder/src/main/resources/rules/VariableDeclarationUsageDistance.md @@ -0,0 +1,4 @@ + +Checks that a variable declaration and its first usage are not more than 3 lines. Blocks of initialisation methods don't count toward this total. + +See the official [Checkstyle documentation](http://checkstyle.sourceforge.net/config_coding.html#VariableDeclarationUsageDistance) for examples. diff --git a/builder/src/main/resources/rules/VisibilityModifier.md b/builder/src/main/resources/rules/VisibilityModifier.md new file mode 100644 index 0000000..1570456 --- /dev/null +++ b/builder/src/main/resources/rules/VisibilityModifier.md @@ -0,0 +1,72 @@ + +> This check cannot be suppressed. + +Checks the visibility of class members to help enforce encapsulation. Only `static final` fields, immutable (see list below) fields or field with special annotation (see list below), may be public. + +The following are considered immutable when `final`, and can be `public`: + +* java.lang.String +* java.lang.Integer +* java.lang.Byte +* java.lang.Character +* java.lang.Short +* java.lang.Boolean +* java.lang.Long +* java.lang.Double +* java.lang.Float +* java.lang.StackTraceElement +* java.math.BigInteger +* java.math.BigDecimal +* java.io.File +* java.util.Locale +* java.util.UUID +* java.net.URL +* java.net.URI +* java.net.Inet4Address +* java.net.Inet6Address +* java.net.InetSocketAddress + +Fields with the following annotations may be `public`: + +* org.junit.Rule +* org.junit.ClassRule +* com.google.common.annotations.VisibleForTesting + +Valid: +```` +class Foo { + + public final Long id; + + public final String name; + + private String description; + + @VisibleForTesting + public State state; + + Foo(final Long id, final String name) { + this.id = id; + this.name = name; + } +} +```` + +Invalid: +```` +class Foo { + + public Long id; + + public String name; + + private String description; + + public State state; + + Foo(final Long id, final String name) { + this.id = id; + this.name = name; + } +} +```` diff --git a/builder/src/main/resources/rules/WhitespaceAfter.md b/builder/src/main/resources/rules/WhitespaceAfter.md new file mode 100644 index 0000000..c833c04 --- /dev/null +++ b/builder/src/main/resources/rules/WhitespaceAfter.md @@ -0,0 +1,16 @@ + +Checks that commas (','), statement terminators (';') and typecasts are all followed by a space. + +Valid: +```` +doSomething(1, 2, 3); +if (a > 1) { return true; } +String name = (String) list.get(9); +```` + +Inalid: +```` +doSomething(1,2,3); +if (a > 1) { return true;} +String name = (String)list.get(9); +```` diff --git a/builder/src/main/resources/rules/WhitespaceAround.md b/builder/src/main/resources/rules/WhitespaceAround.md new file mode 100644 index 0000000..dbdfec8 --- /dev/null +++ b/builder/src/main/resources/rules/WhitespaceAround.md @@ -0,0 +1,2 @@ + +Checks that tokens are surrounded by whitespace. \ No newline at end of file diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java new file mode 100644 index 0000000..2412652 --- /dev/null +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java @@ -0,0 +1,211 @@ +package net.kemitix.checkstyle.ruleset.builder; + +import lombok.val; +import me.andrz.builder.map.MapBuilder; +import org.junit.Before; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.rules.TemporaryFolder; +import org.mockito.MockitoAnnotations; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.AbstractMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link CheckstyleWriter}. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +public class CheckstyleWriterTest { + + private static final String TEMPLATE = "C:%s\nTW:%s"; + + private CheckstyleWriter checkstyleWriter; + + private OutputProperties outputProperties; + + private TemplateProperties templateProperties; + + private RulesProperties rulesProperties; + + private String ruleName; + + private Map outputFiles; + + private Path outputDirectory; + + private Path checkstyleTemplate; + + @org.junit.Rule + public ExpectedException exception = ExpectedException.none(); + + @org.junit.Rule + public TemporaryFolder folder = new TemporaryFolder(); + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + ruleName = UUID.randomUUID() + .toString(); + outputProperties = new OutputProperties(); + outputFiles = new MapBuilder().put(getOutputFile(RuleLevel.LAYOUT)) + .put(getOutputFile(RuleLevel.NAMING)) + .put(getOutputFile(RuleLevel.JAVADOC)) + .put(getOutputFile(RuleLevel.TWEAKS)) + .put(getOutputFile(RuleLevel.COMPLEXITY)) + .build(); + outputProperties.setRulesetFiles(outputFiles); + outputDirectory = folder.newFolder() + .toPath(); + outputProperties.setDirectory(outputDirectory); + templateProperties = new TemplateProperties(); + checkstyleTemplate = folder.newFile("checkstyle-template.xml") + .toPath(); + Files.write( + checkstyleTemplate, TEMPLATE.getBytes(StandardCharsets.UTF_8), StandardOpenOption.TRUNCATE_EXISTING); + templateProperties.setCheckstyleXml(checkstyleTemplate); + rulesProperties = new RulesProperties(); + checkstyleWriter = new CheckstyleWriter(outputProperties, templateProperties, rulesProperties); + } + + // write rule that matches current level + @Test + public void writeRuleThatMatchesCurrentLevel() throws Exception { + //given + val rule = enabledRule(RuleLevel.LAYOUT, RuleParent.TREEWALKER); + rulesProperties.getRules() + .add(rule); + //when + checkstyleWriter.run(); + //then + val lines = loadOutputFile(RuleLevel.LAYOUT); + assertThat(lines).containsExactly("C:", String.format("TW:", ruleName)); + } + + // write rule that is below current level + @Test + public void writeRuleThatIsBelowCurrentLevel() throws Exception { + //given + val rule = enabledRule(RuleLevel.LAYOUT, RuleParent.TREEWALKER); + rulesProperties.getRules() + .add(rule); + //when + checkstyleWriter.run(); + //then + val lines = loadOutputFile(RuleLevel.NAMING); + assertThat(lines).containsExactly("C:", String.format("TW:", ruleName)); + } + + // write rule with checker parent + @Test + public void writeRuleWithCheckerParent() throws Exception { + //given + val rule = enabledRule(RuleLevel.LAYOUT, RuleParent.CHECKER); + rulesProperties.getRules() + .add(rule); + //when + checkstyleWriter.run(); + //then + val lines = loadOutputFile(RuleLevel.LAYOUT); + assertThat(lines).containsExactly(String.format("C:", ruleName), "TW:"); + } + + // write rule with properties + @Test + public void writeRuleWithProperties() throws Exception { + //given + val rule = enabledRule(RuleLevel.LAYOUT, RuleParent.TREEWALKER); + rule.getProperties() + .put("key", "value"); + rulesProperties.getRules() + .add(rule); + //when + checkstyleWriter.run(); + //then + val lines = loadOutputFile(RuleLevel.LAYOUT); + assertThat(lines).containsExactly("C:", String.format("TW:", ruleName), + " ", "" + ); + } + + // ignore rule that is above current level + @Test + public void ignoreRuleThatIsAboveCurrentLevel() throws Exception { + //given + val rule = enabledRule(RuleLevel.NAMING, RuleParent.TREEWALKER); + rulesProperties.getRules() + .add(rule); + //when + checkstyleWriter.run(); + //then + val lines = loadOutputFile(RuleLevel.LAYOUT); + assertThat(lines).containsExactly("C:", "TW:"); + } + + // ignore rule that has unspecified level + @Test + public void ignoreRuleThatHasUnspecifiedLevel() throws Exception { + //given + val rule = enabledRule(RuleLevel.UNSPECIFIED, RuleParent.TREEWALKER); + rulesProperties.getRules() + .add(rule); + //when + checkstyleWriter.run(); + //then + val lines = loadOutputFile(RuleLevel.LAYOUT); + assertThat(lines).containsExactly("C:", "TW:"); + } + + // throw RTE if template not found + @Test + public void throwRteIfTemplateNotFound() throws Exception { + //given + templateProperties.setCheckstyleXml(Paths.get("garbage")); + exception.expect(RuntimeException.class); + exception.expectMessage("Missing template: garbage"); + //when + checkstyleWriter.run(); + } + + // throw RTE if error writing file + @Test + public void throwRteIfErrorWritingFile() throws Exception { + //given + outputProperties.setDirectory(Paths.get("/../imaginary")); + exception.expect(RuntimeException.class); + exception.expectMessage("java.nio.file.NoSuchFileException: /../imaginary/checkstyle-LAYOUT.xml"); + //when + checkstyleWriter.run(); + } + + private Map.Entry getOutputFile(final RuleLevel level) throws IOException { + final String xmlFile = String.format("checkstyle-%s.xml", level.toString()); + return new AbstractMap.SimpleImmutableEntry<>(level, xmlFile); + } + + private List loadOutputFile(final RuleLevel level) throws IOException { + val path = outputDirectory.resolve(outputFiles.get(level)); + assertThat(path).as("Output path exists") + .exists(); + return Files.readAllLines(path, StandardCharsets.UTF_8); + } + + private Rule enabledRule(final RuleLevel level, final RuleParent parent) { + val rule = new Rule(); + rule.setName(ruleName); + rule.setEnabled(true); + rule.setLevel(level); + rule.setParent(parent); + return rule; + } +} diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultReadmeIndexBuilderTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultReadmeIndexBuilderTest.java new file mode 100644 index 0000000..535fb4d --- /dev/null +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultReadmeIndexBuilderTest.java @@ -0,0 +1,65 @@ +package net.kemitix.checkstyle.ruleset.builder; + +import lombok.val; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link DefaultReadmeIndexBuilder}. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +public class DefaultReadmeIndexBuilderTest { + + private DefaultReadmeIndexBuilder indexBuilder; + + private RulesProperties rulesProperties; + + @Before + public void setUp() throws Exception { + rulesProperties = new RulesProperties(); + indexBuilder = new DefaultReadmeIndexBuilder(rulesProperties); + } + + @Test + public void createIndex() throws Exception { + //given + final List expectedIndexItems = new ArrayList<>(6); + expectedIndexItems.add("[a](#a)|layout|checkstyle|Yes|"); + expectedIndexItems.add("[b](#b)|naming|sevntu||No"); + expectedIndexItems.add("[c](#c)|javadoc|checkstyle|Yes|"); + expectedIndexItems.add("[d](#d)|tweaks|checkstyle|Yes|"); + expectedIndexItems.add("[e](#e)|complexity|checkstyle|Yes|"); + expectedIndexItems.add("[f](#f)|unspecified|checkstyle|Yes|"); + val rules = rulesProperties.getRules(); + rules.add(rule("a", RuleLevel.LAYOUT, RuleSource.CHECKSTYLE, true, true)); + rules.add(rule("b", RuleLevel.NAMING, RuleSource.SEVNTU, false, false)); + rules.add(rule("c", RuleLevel.JAVADOC, RuleSource.CHECKSTYLE, true, true)); + rules.add(rule("d", RuleLevel.TWEAKS, RuleSource.CHECKSTYLE, true, true)); + rules.add(rule("e", RuleLevel.COMPLEXITY, RuleSource.CHECKSTYLE, true, true)); + rules.add(rule("f", RuleLevel.UNSPECIFIED, RuleSource.CHECKSTYLE, true, true)); + //when + val index = indexBuilder.build() + .split("\n"); + //then + assertThat(index).containsExactlyElementsOf(expectedIndexItems); + } + + private Rule rule( + final String name, final RuleLevel level, final RuleSource source, final boolean enabled, + final boolean supressible + ) { + val rule = new Rule(); + rule.setName(name); + rule.setLevel(level); + rule.setSource(source); + rule.setEnabled(enabled); + rule.setInsuppressible(!supressible); + return rule; + } +} diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleReadmeLoaderTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleReadmeLoaderTest.java new file mode 100644 index 0000000..708d4d2 --- /dev/null +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleReadmeLoaderTest.java @@ -0,0 +1,84 @@ +package net.kemitix.checkstyle.ruleset.builder; + +import lombok.val; +import org.junit.Before; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.rules.TemporaryFolder; + +import java.io.IOException; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link DefaultRuleReadmeLoader}. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +public class DefaultRuleReadmeLoaderTest { + + private RuleReadmeLoader loader; + + private TemplateProperties templateProperties; + + private Rule rule; + + private Path fragment; + + private Path fragments; + + @org.junit.Rule + public TemporaryFolder folder = new TemporaryFolder(); + + @org.junit.Rule + public ExpectedException exception = ExpectedException.none(); + + @Before + public void setUp() throws Exception { + templateProperties = new TemplateProperties(); + fragments = folder.newFolder("fragments") + .toPath(); + templateProperties.setReadmeFragments(fragments); + loader = new DefaultRuleReadmeLoader(templateProperties); + rule = new Rule(); + rule.setName("name"); + rule.setUri(URI.create("uri")); + } + + @Test + public void loadEnabledOkay() throws IOException { + //given + rule.setEnabled(true); + fragment = fragments.resolve("name.md"); + Files.write(fragment, Arrays.asList("", "body")); + //when + val fragment = loader.load(rule); + //then + assertThat(fragment).containsExactlyElementsOf(Arrays.asList("#### [name](uri)", "", "body")); + } + + @Test + public void loadEnabledWithMissingFragment() { + //given + rule.setEnabled(true); + exception.expect(ReadmeFragmentNotFoundException.class); + exception.expectMessage("name"); + //when + loader.load(rule); + } + + @Test + public void loadDisabled() { + //given + rule.setEnabled(false); + rule.setReason("reason"); + //when + val fragment = loader.load(rule); + //then + assertThat(fragment).containsExactlyElementsOf(Arrays.asList("#### [name](uri)", "", "reason")); + } +} diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/OutputPropertiesTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/OutputPropertiesTest.java new file mode 100644 index 0000000..8ffd97c --- /dev/null +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/OutputPropertiesTest.java @@ -0,0 +1,48 @@ +package net.kemitix.checkstyle.ruleset.builder; + +import lombok.val; +import org.assertj.core.api.SoftAssertions; +import org.junit.Before; +import org.junit.Test; + +import java.nio.file.Paths; +import java.util.HashMap; + +/** + * Tests for {@link OutputProperties}. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +public class OutputPropertiesTest { + + private OutputProperties outputProperties; + + @Before + public void setUp() throws Exception { + outputProperties = new OutputProperties(); + } + + @Test + public void setAndGet() throws Exception { + //given + val directory = Paths.get("directory"); + val rulesetFiles = new HashMap(); + val readme = Paths.get("readme.md"); + //when + outputProperties.setDirectory(directory); + outputProperties.setRulesetFiles(rulesetFiles); + outputProperties.setReadme(readme); + //then + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(outputProperties.getDirectory()) + .as("set/getDirectory()") + .isEqualTo(directory); + softly.assertThat(outputProperties.getRulesetFiles()) + .as("set/getRulesetFiles()") + .isEqualTo(rulesetFiles); + softly.assertThat(outputProperties.getReadme()) + .as("set/getReadme()") + .isEqualTo(readme); + }); + } +} diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeFragmentNotFoundExceptionTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeFragmentNotFoundExceptionTest.java new file mode 100644 index 0000000..7abfda9 --- /dev/null +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeFragmentNotFoundExceptionTest.java @@ -0,0 +1,30 @@ +package net.kemitix.checkstyle.ruleset.builder; + +import lombok.val; +import org.junit.Test; + +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link ReadmeFragmentNotFoundException}. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +public class ReadmeFragmentNotFoundExceptionTest { + + @Test + public void shouldCreateExceptionWithName() { + //given + val name = "rule name"; + val cause = new IOException(); + //when + val exception = new ReadmeFragmentNotFoundException(name, cause); + //then + assertThat(exception.getMessage()).as("rule name is message") + .isEqualTo(name); + assertThat(exception.getCause()).as("cause is caught") + .isSameAs(cause); + } +} diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java new file mode 100644 index 0000000..f64ab97 --- /dev/null +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java @@ -0,0 +1,102 @@ +package net.kemitix.checkstyle.ruleset.builder; + +import lombok.val; +import org.junit.Before; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; + +/** + * Tests for {@link ReadmeWriter}. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +public class ReadmeWriterTest { + + private ReadmeWriter readmeWriter; + + private TemplateProperties templateProperties; + + private OutputProperties outputProperties; + + private RulesProperties rulesProperties; + + @Mock + private RuleReadmeLoader ruleReadmeLoader; + + @Mock + private ReadmeIndexBuilder indexBuilder; + + private Path template; + + private Path fragments; + + private Path readme; + + @org.junit.Rule + public TemporaryFolder folder = new TemporaryFolder(); + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + template = folder.newFile("README-template.md") + .toPath(); + Files.write(template, Arrays.asList("i:%s", "ce:%s", "se:%s", "cd:%s", "sd:%s")); + fragments = folder.newFolder("fragments") + .toPath(); + readme = folder.newFile("README.md") + .toPath(); + templateProperties = new TemplateProperties(); + templateProperties.setReadmeTemplate(template); + templateProperties.setReadmeFragments(fragments); + outputProperties = new OutputProperties(); + outputProperties.setReadme(readme); + rulesProperties = new RulesProperties(); + readmeWriter = + new ReadmeWriter(templateProperties, outputProperties, rulesProperties, ruleReadmeLoader, indexBuilder); + } + + @Test + public void createReadme() throws Exception { + //given + val expected = Arrays.asList("i:index", "ce:checkstyle-enabled", "se:sevntu-enabled", "cd:checkstyle-disabled", + "sd:sevntu-disabled" + ); + val rules = rulesProperties.getRules(); + final Rule checkstyleEnabled = rule(RuleSource.CHECKSTYLE, true); + final Rule checkstyleDisabled = rule(RuleSource.CHECKSTYLE, false); + final Rule sevntuEnabled = rule(RuleSource.SEVNTU, true); + final Rule sevntuDisabled = rule(RuleSource.SEVNTU, false); + rules.add(checkstyleEnabled); + rules.add(checkstyleDisabled); + rules.add(sevntuEnabled); + rules.add(sevntuDisabled); + given(indexBuilder.build()).willReturn("index"); + given(ruleReadmeLoader.load(checkstyleEnabled)).willReturn(Stream.of("checkstyle-enabled")); + given(ruleReadmeLoader.load(checkstyleDisabled)).willReturn(Stream.of("checkstyle-disabled")); + given(ruleReadmeLoader.load(sevntuEnabled)).willReturn(Stream.of("sevntu-enabled")); + given(ruleReadmeLoader.load(sevntuDisabled)).willReturn(Stream.of("sevntu-disabled")); + //when + readmeWriter.run(); + //then + final Stream lines = Files.lines(readme, StandardCharsets.UTF_8); + assertThat(lines).containsExactlyElementsOf(expected); + } + + private Rule rule(final RuleSource source, final boolean enabled) { + val rule = new Rule(); + rule.setSource(source); + rule.setEnabled(enabled); + return rule; + } +} diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RuleParentTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RuleParentTest.java new file mode 100644 index 0000000..3684c85 --- /dev/null +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RuleParentTest.java @@ -0,0 +1,33 @@ +package net.kemitix.checkstyle.ruleset.builder; + +import lombok.val; +import org.junit.Test; + +import java.util.Arrays; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link RuleParent}. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +public class RuleParentTest { + + @Test + public void valueOf() throws Exception { + assertThat(RuleParent.valueOf("CHECKER")).isEqualTo(RuleParent.CHECKER); + assertThat(RuleParent.valueOf("TREEWALKER")).isEqualTo(RuleParent.TREEWALKER); + } + + @Test + public void values() throws Exception { + //given + val expected = Arrays.asList("CHECKER", "TREEWALKER"); + //when + val values = Arrays.stream(RuleParent.values()) + .map(RuleParent::toString); + //then + assertThat(values).containsExactlyElementsOf(expected); + } +} diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RuleSourceTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RuleSourceTest.java new file mode 100644 index 0000000..3cf5562 --- /dev/null +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RuleSourceTest.java @@ -0,0 +1,33 @@ +package net.kemitix.checkstyle.ruleset.builder; + +import lombok.val; +import org.junit.Test; + +import java.util.Arrays; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link RuleSource}. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +public class RuleSourceTest { + + @Test + public void valueOf() throws Exception { + assertThat(RuleSource.valueOf("CHECKSTYLE")).isEqualTo(RuleSource.CHECKSTYLE); + assertThat(RuleSource.valueOf("SEVNTU")).isEqualTo(RuleSource.SEVNTU); + } + + @Test + public void values() throws Exception { + //given + val expected = Arrays.asList("CHECKSTYLE", "SEVNTU"); + //when + val values = Arrays.stream(RuleSource.values()) + .map(RuleSource::toString); + //then + assertThat(values).containsExactlyElementsOf(expected); + } +} diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RuleTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RuleTest.java new file mode 100644 index 0000000..8dd535c --- /dev/null +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RuleTest.java @@ -0,0 +1,79 @@ +package net.kemitix.checkstyle.ruleset.builder; + +import lombok.val; +import org.assertj.core.api.SoftAssertions; +import org.junit.Before; +import org.junit.Test; + +import java.net.URI; + +/** + * Tests for {@link Rule}. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +public class RuleTest { + + private Rule rule; + + @Before + public void setUp() throws Exception { + rule = new Rule(); + } + + @Test + public void setAndGet() throws Exception { + //given + val name = "name"; + val parent = RuleParent.TREEWALKER; + val level = RuleLevel.LAYOUT; + val source = RuleSource.CHECKSTYLE; + val enabled = true; + val insuppressible = true; + val uri = URI.create("rule://name.md"); + val reason = "reason"; + val key = "key"; + val value = "value"; + //when + rule.setName(name); + rule.setParent(parent); + rule.setLevel(level); + rule.setSource(source); + rule.setEnabled(enabled); + rule.setInsuppressible(insuppressible); + rule.setUri(uri); + rule.setReason(reason); + rule.getProperties() + .put(key, value); + //then + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(rule.getName()) + .as("set/getName()") + .isEqualTo(name); + softly.assertThat(rule.getParent()) + .as("set/getParent()") + .isEqualTo(parent); + softly.assertThat(rule.getLevel()) + .as("set/getLevel()") + .isEqualTo(level); + softly.assertThat(rule.getSource()) + .as("set/getSource()") + .isEqualTo(source); + softly.assertThat(rule.isEnabled()) + .as("set/isEnabled()") + .isEqualTo(enabled); + softly.assertThat(rule.isInsuppressible()) + .as("set/isInsuppressible()") + .isEqualTo(insuppressible); + softly.assertThat(rule.getUri()) + .as("set/getUri()") + .isEqualTo(uri); + softly.assertThat(rule.getReason()) + .as("set/getReason()") + .isEqualTo(reason); + softly.assertThat(rule.getProperties()) + .as("getProperties()") + .containsEntry(key, value); + }); + } +} diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RulesPropertiesTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RulesPropertiesTest.java new file mode 100644 index 0000000..119ce11 --- /dev/null +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RulesPropertiesTest.java @@ -0,0 +1,35 @@ +package net.kemitix.checkstyle.ruleset.builder; + +import org.junit.Before; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link RulesProperties}. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +public class RulesPropertiesTest { + + private RulesProperties rulesProperties; + + @Before + public void setUp() throws Exception { + rulesProperties = new RulesProperties(); + } + + @Test + public void getEmpty() throws Exception { + assertThat(rulesProperties.getRules()).isEmpty(); + } + @Test + public void getContent() throws Exception { + //given + final Rule rule = new Rule(); + //when + rulesProperties.getRules().add(rule); + //then + assertThat(rulesProperties.getRules()).containsExactly(rule); + } +} diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/TemplatePropertiesTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/TemplatePropertiesTest.java new file mode 100644 index 0000000..1b4e044 --- /dev/null +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/TemplatePropertiesTest.java @@ -0,0 +1,47 @@ +package net.kemitix.checkstyle.ruleset.builder; + +import org.assertj.core.api.SoftAssertions; +import org.junit.Before; +import org.junit.Test; + +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * Tests for {@link TemplateProperties}. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +public class TemplatePropertiesTest { + + private TemplateProperties templateProperties; + + @Before + public void setUp() throws Exception { + templateProperties = new TemplateProperties(); + } + + @Test + public void setAndGet() throws Exception { + //given + final Path checkstyleXml = Paths.get("checkstyle.xml"); + final Path readmeTemplate = Paths.get("readme.md"); + final Path readmeFragments = Paths.get("readme.dir"); + //when + templateProperties.setCheckstyleXml(checkstyleXml); + templateProperties.setReadmeTemplate(readmeTemplate); + templateProperties.setReadmeFragments(readmeFragments); + //then + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(templateProperties.getCheckstyleXml()) + .as("set/getCheckstyleXml()") + .isEqualTo(checkstyleXml); + softly.assertThat(templateProperties.getReadmeTemplate()) + .as("set/getReadmeTemplate()") + .isEqualTo(readmeTemplate); + softly.assertThat(templateProperties.getReadmeFragments()) + .as("set/getReadmeFragments()") + .isEqualTo(readmeFragments); + }); + } +} diff --git a/pom.xml b/pom.xml index e1374c7..293a289 100644 --- a/pom.xml +++ b/pom.xml @@ -5,12 +5,17 @@ 4.0.0 net.kemitix - kemitix-checkstyle-ruleset - 1.1.0-SNAPSHOT - jar + kemitix-checkstyle-ruleset-parent + 2.0.0-SNAPSHOT + pom - Kemitix Checkstyle Ruleset - Checkstyle Ruleset for use by packages derived from kemitix-parent + Kemitix Checkstyle Ruleset (Parent) + Parent POM for the Kemitix Checkstyle Ruleset and it's Builder + + + builder + ruleset + https://github.com/kemitix/kemitix-checkstyle-ruleset/issues @@ -46,89 +51,4 @@ https://github.com/kemitix/ - - - 2.10.4 - 3.0.1 - 1.6 - 2.8.2 - - - - - release - - - - - org.apache.maven.plugins - maven-javadoc-plugin - ${maven-javadoc-plugin.version} - - - attach-javadocs - verify - - jar - - - - - - - org.apache.maven.plugins - maven-source-plugin - ${maven-source-plugin.version} - - - attach-sources - verify - - jar-no-fork - - - - - - - org.apache.maven.plugins - maven-gpg-plugin - ${maven-gpg-plugin.version} - - ${gpg.passphrase} - - - - sign-artifacts - verify - - sign - - - - - - - org.apache.maven.plugins - maven-deploy-plugin - ${maven-deploy-plugin.version} - - - - - - - - - sonatype-nexus-snapshots - Sonatype Nexus Snapshots - https://oss.sonatype.org/content/repositories/snapshots/ - - - sonatype-nexus-staging - Nexus Release Repository - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - diff --git a/ruleset/pom.xml b/ruleset/pom.xml new file mode 100644 index 0000000..6b6a3ea --- /dev/null +++ b/ruleset/pom.xml @@ -0,0 +1,96 @@ + + + 4.0.0 + + + net.kemitix + kemitix-checkstyle-ruleset-parent + 2.0.0-SNAPSHOT + + + kemitix-checkstyle-ruleset + 2.0.0-SNAPSHOT + jar + + Kemitix Checkstyle Ruleset + Checkstyle Ruleset for use by packages derived from kemitix-parent + + + + release + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + + attach-javadocs + verify + + jar + + + + + + + org.apache.maven.plugins + maven-source-plugin + ${maven-source-plugin.version} + + + attach-sources + verify + + jar-no-fork + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + ${maven-gpg-plugin.version} + + ${gpg.passphrase} + + + + sign-artifacts + verify + + sign + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + ${maven-deploy-plugin.version} + + + + + + + + + sonatype-nexus-snapshots + Sonatype Nexus Snapshots + https://oss.sonatype.org/content/repositories/snapshots/ + + + sonatype-nexus-staging + Nexus Release Repository + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-1-layout.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-1-layout.xml new file mode 100644 index 0000000..72c0d46 --- /dev/null +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-1-layout.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-2-naming.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-2-naming.xml new file mode 100644 index 0000000..d27be47 --- /dev/null +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-2-naming.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-3-javadoc.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-3-javadoc.xml new file mode 100644 index 0000000..1fe56af --- /dev/null +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-3-javadoc.xml @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml new file mode 100644 index 0000000..cf4ce72 --- /dev/null +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml @@ -0,0 +1,177 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml new file mode 100644 index 0000000..44de9aa --- /dev/null +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml @@ -0,0 +1,230 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/net/kemitix/checkstyle.xml b/ruleset/src/main/resources/net/kemitix/checkstyle.xml similarity index 100% rename from src/main/resources/net/kemitix/checkstyle.xml rename to ruleset/src/main/resources/net/kemitix/checkstyle.xml