svn commit: r1868597 - in /ofbiz/ofbiz-framework/trunk: build.gradle config/ config/checkstyle/ config/checkstyle/checkstyle.xml

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1868597 - in /ofbiz/ofbiz-framework/trunk: build.gradle config/ config/checkstyle/ config/checkstyle/checkstyle.xml

mthl
Author: mthl
Date: Fri Oct 18 14:56:50 2019
New Revision: 1868597

URL: http://svn.apache.org/viewvc?rev=1868597&view=rev
Log:
Improved: Use ‘checkstyle’ linting tool
(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

Added:
    ofbiz/ofbiz-framework/trunk/config/
    ofbiz/ofbiz-framework/trunk/config/checkstyle/
    ofbiz/ofbiz-framework/trunk/config/checkstyle/checkstyle.xml   (with props)
Modified:
    ofbiz/ofbiz-framework/trunk/build.gradle

Modified: ofbiz/ofbiz-framework/trunk/build.gradle
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/build.gradle?rev=1868597&r1=1868596&r2=1868597&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/build.gradle (original)
+++ ofbiz/ofbiz-framework/trunk/build.gradle Fri Oct 18 14:56:50 2019
@@ -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

Added: ofbiz/ofbiz-framework/trunk/config/checkstyle/checkstyle.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/config/checkstyle/checkstyle.xml?rev=1868597&view=auto
==============================================================================
--- ofbiz/ofbiz-framework/trunk/config/checkstyle/checkstyle.xml (added)
+++ ofbiz/ofbiz-framework/trunk/config/checkstyle/checkstyle.xml Fri Oct 18 14:56:50 2019
@@ -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>

Propchange: ofbiz/ofbiz-framework/trunk/config/checkstyle/checkstyle.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/ofbiz-framework/trunk/config/checkstyle/checkstyle.xml
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/ofbiz-framework/trunk/config/checkstyle/checkstyle.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml