diff --git a/CHANGELOG b/CHANGELOG index ceba5c7..cd8bd3e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,3 +5,24 @@ CHANGELOG ------ * Initial Release + +1.0.0 +------ + +* LineLength: allow lines up to 120 characters +* AtclauseOrder: use order forced by IntelliJ +* JavadocMethod: now required on protected and package methods +* JavadocType: require @author tag in name (email) format +* JavaNCSS: restrict limits another 20% +* MethodLength: reduced to max 40 lines +* ModifiedControlVariable: don't apply to enhanced for loops +* NestedTryDepth: prevent any nesting of try blocks +* NoWhiteSpaceAfter: prevent dot separator (.) from being the last character on line +* NPathComplexity: reduce to 5 to match CyclomaticComplexity +* PackageName: restrict to lowercase letters and numbers +* ParameterNumber: don't apply to @Overridden methods +* EitherLogOrThrow: support java.util.logging.Logger +* TodoComment: only match against comments +* IllegalType: recognise more classes from Collections +* Remove checks: RedundantImport, ForbidThrowAnonymousExceptions, AvoidConditionInversionCheck and FinalLocalVariable +* Added checks: AvoidInlineConditionals, EqualsAvoidNull, FinalLocalVariable, Header, IllegalToken, InterfaceTypeParameterName, MethodTypeParameterName, NoFinalizer, NoLineWrap, PackageAnnotation, RequireThis, SuppressWarnings, Translation, UncommentedMain and UniqueProperties diff --git a/README.md b/README.md index a7cf69f..6292a06 100644 --- a/README.md +++ b/README.md @@ -30,30 +30,52 @@ You need to include `checkstyle` as the version bundled with the `maven-checksty 7.0 1.21.0 - 1.0.0 + 0.1.1 + + + + 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 + + + + + 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} - - + + + validate + validate + + check + checkstyle + + + + ```` ## All Checks @@ -71,7 +93,7 @@ You need to include `checkstyle` as the version bundled with the `maven-checksty * [AvoidDefaultSerializableInInnerClasses](#avoiddefaultserializableininnerclasses) - sevntu - disabled * [AvoidEscapedUnicodeCharacters](#avoidescapedunicodecharacters) - checkstyle - enabled * [AvoidHidingCauseException](#avoidhidingcauseexception) - sevntu - enabled -* [AvoidInlineConditionals](#avoidinlineconditionals) - checkstyle - disabled +* [AvoidInlineConditionals](#avoidinlineconditionals) - checkstyle - enabled * [AvoidModifiersForTypes](#avoidmodifiersfortypes) - sevntu - disabled * [AvoidNestedBlocks](#avoidnestedblocks) - checkstyle - enabled * [AvoidNotShortCircuitOperatorsForBoolean](#avoidnotshortcircuitoperatorsforboolean) - sevntu - enabled @@ -86,9 +108,9 @@ You need to include `checkstyle` as the version bundled with the `maven-checksty * [ClassTypeParameterName](#classtypeparametername) - checkstyle - enabled * [CommentsIndentation](#commentsindentation) - checkstyle - enabled * [ConfusingCondition](#confusingcondition) - sevntu - enabled -* [ConstantName](#constantname) - checkstyle - enabled +* [ConstantName](#constantname) - checkstyle - enabled - insuppressible * [ConstructorWithoutParams](#constructorwithoutparams) - sevntu - enabled -* [CovariantEquals](#covariantequals) - checkstyle - enabled +* [CovariantEquals](#covariantequals) - checkstyle - enabled - insuppressible * [CustomDeclarationOrder](#customdeclarationorder) - sevntu - disabled * [CyclomaticComplexity](#cyclomaticcomplexity) - checkstyle - enabled * [DeclarationOrder](#declarationorder) - checkstyle - enabled @@ -104,8 +126,8 @@ You need to include `checkstyle` as the version bundled with the `maven-checksty * [EmptyPublicCtorInClass](#emptypublicctorinclass) - sevntu - disabled * [EmptyStatement](#emptystatement) - checkstyle - enabled * [EnumValueName](#enumvaluename) - sevntu - enabled -* [EqualsAvoidNull](#equalsavoidnull) - checkstyle - disabled -* [EqualsHashCode](#equalshashcode) - checkstyle - enabled +* [EqualsAvoidNull](#equalsavoidnull) - checkstyle - enabled +* [EqualsHashCode](#equalshashcode) - checkstyle - enabled - insuppressible * [ExecutableStatementCount](#executablestatementcount) - checkstyle - enabled * [ExplicitInitialization](#explicitinitialization) - checkstyle - enabled * [FallThrough](#fallthrough) - checkstyle - enabled @@ -120,7 +142,7 @@ You need to include `checkstyle` as the version bundled with the `maven-checksty * [ForbidCertainImports](#forbidcertainimports) - sevntu - disabled * [ForbidInstantiation](#forbidinstantiation) - sevntu - disabled * [ForbidReturnInFinallyBlock](#forbidreturninfinallyblock) - sevntu - enabled -* [ForbidThrowAnonymousExceptions](#forbidthrowanonymousexceptions) - sevntu - enabled +* [ForbidThrowAnonymousExceptions](#forbidthrowanonymousexceptions) - sevntu - disabled * [ForbidWildcardAsReturnType](#forbidwildcardasreturntype) - sevntu - enabled * [GenericWhitespace](#genericwhitespace) - checkstyle - enabled * [Header](#header) - checkstyle - disabled @@ -132,7 +154,7 @@ You need to include `checkstyle` as the version bundled with the `maven-checksty * [IllegalImport](#illegalimport) - checkstyle - enabled * [IllegalInstantiation](#illegalinstantiation) - checkstyle - disabled * [IllegalThrows](#illegalthrows) - checkstyle - enabled -* [IllegalToken](#illegaltoken) - checkstyle - disabled +* [IllegalToken](#illegaltoken) - checkstyle - enabled * [IllegalTokenText](#illegaltokentext) - checkstyle - disabled * [IllegalType](#illegaltype) - checkstyle - enabled * [ImportControl](#importcontrol) - checkstyle - disabled @@ -142,7 +164,7 @@ You need to include `checkstyle` as the version bundled with the `maven-checksty * [InnerClass](#innerclass) - sevntu - disabled * [InnerTypeLast](#innertypelast) - checkstyle - enabled * [InterfaceIsType](#interfaceistype) - checkstyle - enabled -* [InterfaceTypeParameterName](#interfacetypeparametername) - checkstyle - disabled +* [InterfaceTypeParameterName](#interfacetypeparametername) - checkstyle - enabled * [InterfaceTypeParameterName](#interfacetypeparametername-1) - sevntu - disabled * [JavadocMethod](#javadocmethod) - checkstyle - enabled * [JavadocPackage](#javadocpackage) - checkstyle - enabled @@ -165,7 +187,7 @@ You need to include `checkstyle` as the version bundled with the `maven-checksty * [MethodLength](#methodlength) - checkstyle - enabled * [MethodName](#methodname) - checkstyle - enabled * [MethodParamPad](#methodparampad) - checkstyle - enabled -* [MethodTypeParameterName](#methodtypeparametername) - checkstyle - disabled +* [MethodTypeParameterName](#methodtypeparametername) - checkstyle - enabled * [MissingCtor](#missingctor) - checkstyle - disabled * [MissingDeprecated](#missingdeprecated) - checkstyle - enabled * [MissingOverride](#missingoverride) - checkstyle - disabled @@ -184,9 +206,9 @@ You need to include `checkstyle` as the version bundled with the `maven-checksty * [NestedSwitch](#nestedswitch) - sevntu - enabled * [NestedTryDepth](#nestedtrydepth) - checkstyle - enabled * [NewlineAtEndOfFile](#newlineatendoffile) - checkstyle - enabled -* [NoClone](#noclone) - checkstyle - enabled -* [NoFinalizer](#nofinalizer) - checkstyle - disabled -* [NoLineWrap](#nolinewrap) - checkstyle - disabled +* [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 @@ -194,21 +216,21 @@ You need to include `checkstyle` as the version bundled with the `maven-checksty * [NPathComplexity](#npathcomplexity) - checkstyle - enabled * [NumericLiteralNeedsUnderscore](#numericliteralneedsunderscore) - sevntu - enabled * [OneStatementPerLine](#onestatementperline) - checkstyle - enabled -* [OneTopLevelClass](#onetoplevelclass) - checkstyle - enabled +* [OneTopLevelClass](#onetoplevelclass) - checkstyle - enabled - insuppressible * [OperatorWrap](#operatorwrap) - checkstyle - enabled -* [OuterTypeFilename](#outertypefilename) - checkstyle - enabled +* [OuterTypeFilename](#outertypefilename) - checkstyle - enabled - insuppressible * [OuterTypeNumber](#outertypenumber) - checkstyle - disabled * [OverloadMethodsDeclarationOrder](#overloadmethodsdeclarationorder) - checkstyle - enabled * [OverridableMethodInConstructor](#overridablemethodinconstructor) - sevntu - enabled -* [PackageAnnotation](#packageannotation) - checkstyle - disabled -* [PackageDeclaration](#packagedeclaration) - checkstyle - 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 - enabled +* [RedundantImport](#redundantimport) - checkstyle - disabled * [RedundantModifier](#redundantmodifier) - checkstyle - enabled * [RedundantReturn](#redundantreturn) - sevntu - enabled * [Regexp](#regexp) - checkstyle - disabled @@ -218,7 +240,7 @@ You need to include `checkstyle` as the version bundled with the `maven-checksty * [RegexpSingleline](#regexpsingleline) - checkstyle - disabled * [RegexpSinglelineJava](#regexpsinglelinejava) - checkstyle - disabled * [RequiredParameterForAnnotation](#requiredparameterforannotation) - sevntu - disabled -* [RequireThis](#requirethis) - checkstyle - disabled +* [RequireThis](#requirethis) - checkstyle - enabled * [ReturnBooleanFromTernary](#returnbooleanfromternary) - sevntu - enabled * [ReturnCount](#returncount) - checkstyle - enabled * [ReturnCountExtended](#returncountextended) - sevntu - disabled @@ -237,18 +259,18 @@ You need to include `checkstyle` as the version bundled with the `maven-checksty * [SummaryJavadoc](#summaryjavadoc) - checkstyle - disabled * [SuperClone](#superclone) - checkstyle - disabled * [SuperFinalize](#superfinalize) - checkstyle - disabled +* [SuppressWarnings](#suppresswarnings) - checkstyle - enabled * [SuppressWarningsHolder](#suppresswarningsholder) - checkstyle - enabled -* [SuppressWarnings](#suppresswarnings) - checkstyle - disabled * [TernaryPerExpressionCount](#ternaryperexpressioncount) - sevntu - enabled * [ThrowsCount](#throwscount) - checkstyle - enabled * [TodoComment](#todocomment) - checkstyle - enabled * [TrailingComment](#trailingcomment) - checkstyle - enabled -* [Translation](#translation) - checkstyle - disabled +* [Translation](#translation) - checkstyle - enabled * [TypecastParenPad](#typecastparenpad) - checkstyle - enabled -* [TypeName](#typename) - checkstyle - enabled -* [UncommentedMain](#uncommentedmain) - checkstyle - disabled +* [TypeName](#typename) - checkstyle - enabled - insuppressible +* [UncommentedMain](#uncommentedmain) - checkstyle - enabled * [UniformEnumConstantName](#uniformenumconstantname) - sevntu - enabled -* [UniqueProperties](#uniqueproperties) - checkstyle - disabled +* [UniqueProperties](#uniqueproperties) - checkstyle - enabled * [UnnecessaryParentheses](#unnecessaryparentheses) - checkstyle - enabled * [UnnecessaryParenthesesExtended](#unnecessaryparenthesesextended) - sevntu - disabled * [UnusedImports](#unusedimports) - checkstyle - enabled @@ -256,7 +278,7 @@ You need to include `checkstyle` as the version bundled with the `maven-checksty * [UselessSingleCatch](#uselesssinglecatch) - sevntu - enabled * [UselessSuperCtorCall](#uselesssuperctorcall) - sevntu - enabled * [VariableDeclarationUsageDistance](#variabledeclarationusagedistance) - checkstyle - enabled -* [VisibilityModifier](#visibilitymodifier) - checkstyle - enabled +* [VisibilityModifier](#visibilitymodifier) - checkstyle - enabled - insuppressible * [WhitespaceAfter](#whitespaceafter) - checkstyle - enabled * [WhitespaceAround](#whitespacearound) - checkstyle - enabled * [WhitespaceBeforeArrayInitializer](#whitespacebeforearrayinitializer) - sevntu - disabled @@ -272,9 +294,7 @@ Rules are listed in alphabetical order. #### [AbbreviationAsWordInName](http://checkstyle.sourceforge.net/config_naming.html#AbbreviationAsWordInName) -Enforces proper `CamelCase` and avoids sequences of consecutive uppercase characters in identifiers. Does not apply to final or static variables, or @Overridden methods. - -> TODO: enable for final and static variables. +Enforces proper `CamelCase` and avoids sequences of consecutive uppercase characters in identifiers. Does not apply to @Overridden methods. Valid: ```` @@ -364,17 +384,17 @@ Javadoc `@` clauses must be in the order: ```` /** * + * @param ... * @author ... * @version ... - * @param ... + * @serial ... * @return ... * @throws ... * @exception ... + * @serialData ... + * @serialField ... * @see ... * @since ... - * @serial ... - * @serialField ... - * @serialData ... * @deprecated ... */ ```` @@ -394,6 +414,10 @@ 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. @@ -594,6 +618,8 @@ public void foo11() { #### [ConstantName](http://checkstyle.sourceforge.net/config_naming.html#ConstantName) +> 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: @@ -609,6 +635,8 @@ private static final int 12_CARD = 12; #### [CovariantEquals](http://checkstyle.sourceforge.net/config_coding.html#CovariantEquals) +> This check cannot be suppressed. + Checks that classes which define a covariant equals() method also override method equals(Object). Valid: @@ -894,8 +922,26 @@ Invalid: doSomething();; ```` +#### [EqualsAvoidNull](http://checkstyle.sourceforge.net/config_coding.html#EqualsAvoidNull) + +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"); +```` + #### [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) @@ -1027,6 +1073,10 @@ 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. @@ -1143,18 +1193,29 @@ 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 variables, parameters and method returns from being one of the following: +Prevents use of implementation classes as variables, parameters or method returns. Use the interfaces instead. -* java.util.HashSet +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.TreeSet +* java.util.LinkedList +* java.util.PriorityQueue * java.util.TreeMap - -> TODO: add more classes from Collections +* java.util.TreeSet Valid: ```` @@ -1207,15 +1268,23 @@ interface Foo { } ```` +#### [InterfaceTypeParameterName](http://checkstyle.sourceforge.net/config_naming.html#InterfaceTypeParameterName) + +Checks that the type parameters for an interface are a single uppercase letter. + +Valid: +```` +interface Portable {} +```` + +Invalid: +```` +interface Portable {} +```` + #### [JavadocMethod](http://checkstyle.sourceforge.net/config_javadoc.html#JavadocMethod) -Checks that all public methods have a Javadoc block. - -> TODO: scope = private (reset to default) - will require lots of new javadoc blocks - -> TODO: validateThrows = true - -> TODO: allowMissingPropertyJavadoc = true +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) @@ -1231,22 +1300,14 @@ Checks the formatting of the Javadoc blocks. See the official [Checkstyle docume #### [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. - -> TODO: authorFormat = "^.+ (\S+@[\S.]+)$" - name followed by email in brackets +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 50, 1500 and 2000 respectively. The NCSS score is a measure of the number of statements within a scope. +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. -> TODO: methodMaximum = 40 - reduce by 20% - -> TODO: classMaximum = 1200 - -> TODO: fileMaximum = 1600 - #### [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. @@ -1267,12 +1328,10 @@ class Bar #### [LineLength](http://checkstyle.sourceforge.net/config_sizes.html#LineLength) -Limits the line length to 80 characters. +Limits the line length to 120 characters. Doesn't check package or import lines. -> TODO: ignorePattern = "^\s\\* .+" exclude javadoc blocks - #### [LocalFinalVariableName](http://checkstyle.sourceforge.net/config_naming.html#LocalFinalVariableName) Checks the format of local, `final` variable names, including `catch` parameters. @@ -1316,8 +1375,6 @@ Restricts the number of methods in a type to 30. 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. -> TODO: max = 40 - #### [MethodName](http://checkstyle.sourceforge.net/config_naming.html#MethodName) Checks the format of method names. @@ -1341,6 +1398,22 @@ void getValue (); ```` +#### [MethodTypeParameterName](http://checkstyle.sourceforge.net/config_naming.html#MethodTypeParameterName) + +Restricts method generics parameters to be a single uppercase letter. + +Valid: +```` +List getItems() {} +```` + +Invalid: +```` +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. @@ -1413,8 +1486,6 @@ for (int i = 0; i < 1; i++) { } ```` -> TODO: skipEnhancesForLoopVariable = true - #### [ModifierOrder](http://checkstyle.sourceforge.net/config_modifier.html#ModifierOrder) Check that modifiers are in the following order: @@ -1551,19 +1622,17 @@ if (isValid()) { // depth 0 #### [NestedTryDepth](http://checkstyle.sourceforge.net/config_coding.html#NestedTryDepth) -Checks that `try` blocks are not nested more than 1 deep. +Checks that `try` blocks are not nested. Valid: ```` try { doSomething(); - try { - doSomeOtherThing(); - } catch (OtherExceptions oe) { - // handle it - } + doSomeOtherThing(); } catch (SomeException se) { // handle it +} catch (OtherExceptions oe) { + // handle it } ```` @@ -1581,18 +1650,28 @@ try { } ```` -> TODO: max = 0 - don't nest try blocks - #### [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. + 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. @@ -1647,8 +1726,6 @@ int[ ] a; int d = a[ 2]; ```` -> TODO: tokens = DOT & allowLineBreaks = false - #### [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 ('--'). @@ -1671,9 +1748,7 @@ 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 200. This is similar to [Cyclomatic Complexity](#cyclomaticcomplexity). - -> TODO: max = 5 - same as cyclomatic complexity +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) @@ -1692,6 +1767,8 @@ 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) @@ -1712,23 +1789,29 @@ int answer = getTheAnswerToLife() + getTheAnswerToTheUniverse() + #### [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. +Checks the format of package names. Only lowercase letters, no initial numbers or any underscores. -Identifiers must match `^[a-z]+(\.[a-zA-Z_][a-zA-Z0-9_]*)*$`. - -> TODO: format = `^[a-z]+(\.[a-z]+)*$` - only lowercase letters, no numbers or underscores +Identifiers must match `^[a-z]+(\.[a-z][a-z0-9]+)*$`. #### [ParameterName](http://checkstyle.sourceforge.net/config_naming.html#ParameterName) @@ -1738,9 +1821,7 @@ 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. - -> TODO: ignoreOverriddenMethods = true +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) @@ -1759,12 +1840,6 @@ doSomethingElse( 5); doSomethingElse(5 ); ```` -#### [RedundantImport](http://checkstyle.sourceforge.net/config_imports.html#RedundantImport) - -Checks for redundant `import`s. Checks for duplicates, imports from the `java.lang` package or from the current package. - -> TODO: remove - [UnusedImports](#unusedimports) performs all the same checks and more - #### [RedundantModifier](http://checkstyle.sourceforge.net/config_modifier.html#RedundantModifier) Checks for redundant modifiers. Checks for: @@ -1775,6 +1850,10 @@ Checks for redundant modifiers. Checks for: * 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. @@ -1958,6 +2037,20 @@ Invalid: if (x == "something") {} ```` +#### [SuppressWarnings](http://checkstyle.sourceforge.net/config_annotation.html#SuppressWarnings) + +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) + #### [SuppressWarningsHolder](http://checkstyle.sourceforge.net/config_annotation.html#SuppressWarningsHolder) Used by Checkstyle to hold the checks to be suppressed from `@SuppressWarnings(...)` annotations. @@ -1985,8 +2078,6 @@ void doSomething() throws IllegalStateException, Checks for remaining `TODO` and `FIXME` comments left in code. Their presence indicates that the program isn't finished yet. -> TODO: format = "(//\*).*((TODO)|(FIXME))" - only where in comments - #### [TrailingComment](http://checkstyle.sourceforge.net/config_misc.html#TrailingComment) Checks for comments at the end of lines. @@ -2015,6 +2106,10 @@ int[] a = new int[2]( ); ```` +#### [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. @@ -2033,10 +2128,20 @@ String s = ( String ) list.get(2); #### [TypeName](http://checkstyle.sourceforge.net/config_naming.html#TypeName) +> This check cannot be suppressed. + 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. @@ -2085,6 +2190,8 @@ See the official [Checkstyle documentation](http://checkstyle.sourceforge.net/co #### [VisibilityModifier](http://checkstyle.sourceforge.net/config_design.html#VisibilityModifier) +> 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`: @@ -2273,7 +2380,7 @@ Map idTable = new HashMap(); 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. -> TODO: loggingMethodNames: add 'log' +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) @@ -2313,7 +2420,7 @@ enum InvalidClassLike { private String name; - ValidClassLike(String name) { + InvalidClassLike(String name) { this.name = name; } } @@ -2352,10 +2459,6 @@ try { } ```` -#### [ForbidThrowAnonymousExceptions](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/ForbidThrowAnonymousExceptionsCheck.html) - -TODO: remove - [IllegalThrows](#illegalthrows) performs a similar check. - #### [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. @@ -2633,34 +2736,16 @@ These checks are not enabled. Notes are included for each explaining why. Couldn't get my IDE's (IntelliJ) code style to match. -#### [AvoidInlineConditionals](http://checkstyle.sourceforge.net/config_coding.html#AvoidInlineConditionals) - -> TODO: enable - -#### [EqualsAvoidNull](http://checkstyle.sourceforge.net/config_coding.html#EqualsAvoidNull) - -> TODO: enable - #### [FinalLocalVariable](http://checkstyle.sourceforge.net/config_coding.html#FinalLocalVariable) -> TODO: enable +Doesn't recognise Lombok's `val` as being `final`. -#### [Header](http://checkstyle.sourceforge.net/config_header.html#Header) - -> TODO: enable - -> TODO: headerFile = LICENSE.txt - -> TODO: fileExtensions = java +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. -#### [IllegalToken](http://checkstyle.sourceforge.net/config_coding.html#IllegalToken) - -> TODO: enable - #### [IllegalTokenText](http://checkstyle.sourceforge.net/config_coding.html#IllegalTokenText) Generic rule; doesn't embody a 'quality' check. @@ -2677,10 +2762,6 @@ Generic rule; doesn't embody a 'quality' check. Couldn't get my IDE's (IntelliJ) code style to match. -#### [InterfaceTypeParameterName](http://checkstyle.sourceforge.net/config_naming.html#InterfaceTypeParameterName) - -> TODO: enable - #### [JavadocTagContinuationIndentation](http://checkstyle.sourceforge.net/config_javadoc.html#JavadocTagContinuationIndentation) Couldn't get my IDE's (IntelliJ) code style to match. @@ -2689,37 +2770,27 @@ Couldn't get my IDE's (IntelliJ) code style to match. Member variables should usually be named such that it is clear what they are. Comments for clarification should be the exception. -#### [MethodTypeParameterName](http://checkstyle.sourceforge.net/config_naming.html#MethodTypeParameterName) - -> TODO: enable - #### [MissingCtor](http://checkstyle.sourceforge.net/config_coding.html#MissingCtor) -> TODO: enable +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. -#### [NoFinalizer](http://checkstyle.sourceforge.net/config_coding.html#NoFinalizer) - -> TODO: enable - -#### [NoLineWrap](http://checkstyle.sourceforge.net/config_whitespace.html#NoLineWrap) - -> TODO: enable - #### [OuterTypeNumber](http://checkstyle.sourceforge.net/config_sizes.html#OuterTypeNumber) Already covered by the [OneTopLevelClass](#onetoplevelclass) check. -#### [PackageAnnotation](http://checkstyle.sourceforge.net/config_annotation.html#PackageAnnotation) - -> TODO: enable - #### [ParameterAssignment](http://checkstyle.sourceforge.net/config_coding.html#ParameterAssignment) -> TODO: enable +[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) @@ -2745,12 +2816,6 @@ Generic rule; doesn't embody a 'quality' check. Generic rule; doesn't embody a 'quality' check. -#### [RequireThis](http://checkstyle.sourceforge.net/config_coding.html#RequireThis) - -> TODO: enable - -> TODO: checkMethods = false - #### [SingleLineJavadoc](http://checkstyle.sourceforge.net/config_javadoc.html#SingleLineJavadoc) I don't use single line javadoc blocks. @@ -2765,27 +2830,7 @@ Overridding the `clone()` method is not allowed by the [NoClone](#noclone) check #### [SuperFinalize](http://checkstyle.sourceforge.net/config_coding.html#SuperFinalize) -> TODO: enable - -#### [SuppressWarnings](http://checkstyle.sourceforge.net/config_annotation.html#SuppressWarnings) - -> TODO: enable - -> TODO: format = ^constantname|covariantequals|equalshashcode|noclone|onetoplevelclass|outertypefilename|packagedeclaration|typename|visibilitymodifier$ - -#### [Translation](http://checkstyle.sourceforge.net/config_misc.html#Translation) - -> TODO: enable - -#### [UncommentedMain](http://checkstyle.sourceforge.net/config_misc.html#UncommentedMain) - -> TODO: enable - -> TODO: excludedClasses = "Main$" - -#### [UniqueProperties](http://checkstyle.sourceforge.net/config_misc.html#UniqueProperties) - -> TODO: enable +[NoFinalizer](#nofinalizer) prevents use of `finalize()`. #### [WriteTag](http://checkstyle.sourceforge.net/config_javadoc.html#WriteTag) @@ -2799,8 +2844,6 @@ As the sevntu check are considered experimental not all those that are not enabl Should already be covered by [SimplifyBooleanExpression](simplifybooleanexpression). -> TODO: disable - #### [AvoidDefaultSerializableInInnerClasses](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/AvoidDefaultSerializableInInnerClassesCheck.html) > TODO: enable @@ -2841,6 +2884,10 @@ Generic rule; doesn't embody a 'quality' check. 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). diff --git a/pom.xml b/pom.xml index 276c4b7..43eaa15 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.kemitix kemitix-checkstyle-ruleset - 0.1.1 + 1.0.0 jar Kemitix Checkstyle Ruleset @@ -131,4 +131,4 @@ - \ No newline at end of file + diff --git a/src/main/resources/net/kemitix/checkstyle.xml b/src/main/resources/net/kemitix/checkstyle.xml index c9be749..997c29e 100644 --- a/src/main/resources/net/kemitix/checkstyle.xml +++ b/src/main/resources/net/kemitix/checkstyle.xml @@ -15,24 +15,35 @@ + + + + + + - + + - + + + + @@ -67,6 +78,7 @@ + @@ -86,21 +98,35 @@ - + + + + + - + + + - - + + + + + + + + - + + + @@ -110,13 +136,16 @@ - + + - + + + @@ -125,13 +154,21 @@ - + + + + + + + + + - + @@ -140,14 +177,21 @@ + - + + + - + + + - + + + @@ -164,16 +208,24 @@ + + + - + + + + + @@ -192,9 +244,12 @@ + + + + - @@ -210,7 +265,6 @@ -