This is an automated email from the ASF dual-hosted git repository. adityasharma pushed a commit to branch release18.12 in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
commit 6f1907785deb26677325f56656952bd6228a5eb5 Author: Aditya Sharma <adityasha...@apache.org> AuthorDate: Sat Jul 11 19:34:37 2020 +0530 Improved: Used '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 provides such facility. The lint actions are triggered when running ‘gradle check’. There are 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 currently 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 Mathieu Lirzin for the contribution and Taher Alkhateeb & Jacques Le Roux for their feedback --- build.gradle | 13 +++++ config/checkstyle/checkstyle.xml | 110 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) diff --git a/build.gradle b/build.gradle index e2ceeac..455b78b 100644 --- a/build.gradle +++ b/build.gradle @@ -39,6 +39,7 @@ apply plugin: 'eclipse' apply plugin: 'maven-publish' apply plugin: "at.bxm.svntools" apply plugin: 'org.asciidoctor.convert' +apply plugin: 'checkstyle' apply from: 'common.gradle' @@ -67,6 +68,18 @@ javadoc.options { "https://commons.apache.org/proper/commons-cli/apidocs" ) } +// 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 = 38803 + // Currently there are a lot of errors so we need to temporarily + // hide them to avoid polluting the terminal output. + showViolations = false +} sourceCompatibility = '1.8' targetCompatibility = '1.8' diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 0000000..0145c7c --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -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>