Skip to content

Commit

Permalink
Improved: Use ‘checkstyle’ linting tool
Browse files Browse the repository at this point in the history
(OFBIZ-11251)

Linting [1] is a software engineering practice which make the code more
readable and maintainable by improving its consistency and avoiding
potential programming mistakes.  Gradle provides a core plugin for the
‘checkstyle’ tool [2][3] which implement a linting facility for the Java
language.

The check is done with the ‘gradlew check’ command.

There are currently a lot reported errors that will need to be fixed
incrementally in the future.  We ensure that new errors will not be
introduced by defining a global threshold of “allowed” errors
corresponding to the sum of errors found in the framework and in the
official plugins.

[1] https://en.wikipedia.org/wiki/Lint_(software)
[2] https://checkstyle.org/
[3] https://docs.gradle.org/current/userguide/checkstyle_plugin.html

Thanks: Taher Alkhateeb and Jacques Le Roux for their feedback


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1868597 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Oct 18, 2019
1 parent 406cd08 commit 5363a77
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
14 changes: 14 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ plugins {
id 'java'
id 'groovy'
id 'eclipse'
id 'checkstyle'
id 'maven-publish'
id 'at.bxm.svntools' version '2.2.1'
id 'org.asciidoctor.convert' version '2.0.0'
Expand Down Expand Up @@ -299,6 +300,19 @@ jar.manifest.attributes(
'Class-Path': getJarClasspath()
)

// Checks OFBiz Java coding conventions.
checkstyle {
// Defining a maximum number of “tolerated” errors ensures that
// this number cannot increase in the future. It corresponds to
// the sum of errors that were present before introducing the
// ‘checkstyle’ tool present in the framework and in the official
// plugins.
maxErrors = 37967
// Currently there are a lot of errors so we need to temporarily
// hide them to avoid polluting the terminal output.
showViolations = false
}

// Eclipse plugin settings
eclipse.classpath.file.whenMerged { classpath ->
/* The code inside this block removes unnecessary entries
Expand Down
110 changes: 110 additions & 0 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<!-- This configuration corresponds to the OFBiz coding conventions
which are simply “Sun Coding Standards” + “120 characters line length” -->
<module name="Checker">
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>
<property name="fileExtensions" value="java, properties, xml"/>

<!-- General file conventions -->
<module name="NewlineAtEndOfFile"/>
<module name="FileTabCharacter"/>
<module name="RegexpSingleline">
<property name="format" value="\s+$"/>
<property name="minimum" value="0"/>
<property name="maximum" value="0"/>
<property name="message" value="Line has trailing spaces."/>
</module>

<module name="TreeWalker">
<!-- Naming conventions -->
<module name="ConstantName"/>
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
<module name="MemberName"/>
<module name="MethodName"/>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<module name="TypeName"/>

<!-- Checks for imports -->
<module name="AvoidStarImport"/>
<module name="IllegalImport"/>
<module name="RedundantImport"/>
<module name="UnusedImports">
<property name="processJavadoc" value="false"/>
</module>

<!-- Checks for Size Violations -->
<module name="LineLength">
<property name="max" value="120"/>
</module>
<module name="MethodLength"/>
<module name="ParameterNumber"/>

<!-- Checks for whitespace -->
<module name="EmptyForIteratorPad"/>
<module name="GenericWhitespace"/>
<module name="MethodParamPad"/>
<module name="NoWhitespaceAfter"/>
<module name="NoWhitespaceBefore"/>
<module name="OperatorWrap"/>
<module name="SeparatorWrap">
<property name="tokens"
value="COMMA,LPAREN,RPAREN,RBRACK,ARRAY_DECLARATOR"/>
<property name="option" value="eol"/>
</module>
<module name="SeparatorWrap">
<property name="tokens" value="DOT,METHOD_REF,ELLIPSIS,AT"/>
<property name="option" value="nl"/>
</module>
<module name="ParenPad"/>
<module name="TypecastParenPad"/>
<module name="WhitespaceAfter"/>
<module name="WhitespaceAround"/>
<module name="SingleSpaceSeparator"/>

<!-- Modifier Checks -->
<module name="ModifierOrder"/>
<module name="RedundantModifier"/>

<!-- Checks for blocks. You know, those {}'s -->
<module name="AvoidNestedBlocks"/>
<module name="EmptyBlock"/>
<module name="LeftCurly"/>
<module name="NeedBraces"/>
<module name="RightCurly"/>

<!-- Checks for common coding problems -->
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="IllegalInstantiation"/>
<module name="InnerAssignment"/>
<module name="MultipleVariableDeclarations"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>

<!-- Checks for class design -->
<module name="DesignForExtension"/>
<module name="FinalClass"/>
<module name="HideUtilityClassConstructor"/>
<module name="InterfaceIsType"/>
<module name="VisibilityModifier"/>

<!-- Miscellaneous other checks -->
<module name="ArrayTypeStyle"/>
<module name="UpperEll"/>
<module name="Indentation">
<property name="caseIndent" value="0"/>
<property name="lineWrappingIndentation" value="8"/>
</module>

<!-- Checks for annotations -->
<module name="MissingOverride"/>
</module>
</module>

0 comments on commit 5363a77

Please sign in to comment.