Skip to content
Browse files
Improved: Use ‘checkstyle’ linting tool

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

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.


Thanks: Taher Alkhateeb and Jacques Le Roux for their feedback

git-svn-id: 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Oct 18, 2019
1 parent 406cd08 commit 5363a7773a75777d5bfc9be80cbff8d7f46f3611
Showing with 124 additions and 0 deletions.
  1. +14 −0 build.gradle
  2. +110 −0 config/checkstyle/checkstyle.xml
@@ -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'
@@ -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
@@ -0,0 +1,110 @@
<?xml version="1.0"?>
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
<!-- 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$"/>
<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 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"/>

<!-- Checks for Size Violations -->
<module name="LineLength">
<property name="max" value="120"/>
<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"
<property name="option" value="eol"/>
<module name="SeparatorWrap">
<property name="tokens" value="DOT,METHOD_REF,ELLIPSIS,AT"/>
<property name="option" value="nl"/>
<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"/>

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

0 comments on commit 5363a77

Please sign in to comment.