Skip to content

Commit

Permalink
add checkstyle github action
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-james committed May 31, 2024
1 parent acc3858 commit 073ff4a
Show file tree
Hide file tree
Showing 4 changed files with 249 additions and 24 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Checkstyle

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
checkstyle:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'

- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Apply Checkstyle
run: ./gradlew checkstyleMain checkstyleTest

- name: Upload Checkstyle reports
uses: actions/upload-artifact@v3
with:
name: checkstyle-reports
path: build/reports/checkstyle/
26 changes: 2 additions & 24 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: Java CI with Gradle

on:
Expand All @@ -28,25 +21,12 @@ jobs:
java-version: '17'
distribution: 'temurin'

# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5

- name: Build with Gradle Wrapper
run: ./gradlew build

# NOTE: The Gradle Wrapper is the default and recommended way to run Gradle (https://docs.gradle.org/current/userguide/gradle_wrapper.html).
# If your project does not have the Gradle Wrapper configured, you can use the following configuration to run Gradle with a specified version.
#
# - name: Setup Gradle
# uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
# with:
# gradle-version: '8.5'
#
# - name: Build with Gradle 8.5
# run: gradle build

dependency-submission:

runs-on: ubuntu-latest
Expand All @@ -61,7 +41,5 @@ jobs:
java-version: '17'
distribution: 'temurin'

# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies.
# See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md
- name: Generate and submit dependency graph
uses: gradle/actions/dependency-submission@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
uses: gradle/actions/dependency-submission@417ae3ccd767c252f5661f1ace9f835f9654f2b5
13 changes: 13 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'java'
id 'checkstyle'
}

group = 'com.lmax'
Expand Down Expand Up @@ -44,6 +45,11 @@ sourceSets {
}
}

checkstyle {
toolVersion = '8.45'
configFile = file('config/checkstyle/checkstyle.xml')
}

dependencies {
// dependencies
implementation 'org.bitcoinj:bitcoinj-core:0.15'
Expand Down Expand Up @@ -105,4 +111,11 @@ tasks.processTestResources {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

tasks.withType(Checkstyle) {
reports {
xml.enabled = true
html.enabled = true
}
}

check.dependsOn integrationTest
193 changes: 193 additions & 0 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
<module name="SeverityMatchFilter">
<property name="severity" value="info"/>
<property name="acceptOnMatch" value="false"/>
</module>

<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>

<module name="SuppressionFilter">
<property name="file" value="${config_loc}/suppress.xml"/>
</module>

<module name="LineLength">
<property name="max" value="200"/>
<property name="ignorePattern" value="^[ \t]*\*.*@.*$"/>
</module>

<module name="TreeWalker">
<property name="tabWidth" value="4"/>
<property name="severity" value="error"/>

<module name="ConstantName"/>

<module name="LocalFinalVariableName"/>

<module name="LocalVariableName"/>

<module name="MemberName">
<property name="format" value="^[a-z][a-zA-Z0-9_]*$"/>
</module>

<module name="MethodName"/>

<module name="PackageName"/>

<module name="ParameterName"/>

<module name="StaticVariableName"/>

<module name="TypeName"/>

<module name="AvoidStarImport"/>
<module name="RedundantImport"/>
<module name="UnusedImports"/>

<module name="EmptyForInitializerPad"/>

<module name="MethodParamPad"/>

<module name="NoWhitespaceBefore"/>

<module name="WhitespaceAfter">
<property name="tokens"
value="COMMA, SEMI, TYPECAST, LITERAL_IF, LITERAL_ELSE,
LITERAL_WHILE, LITERAL_DO, LITERAL_FOR, DO_WHILE"/>
</module>

<module name="WhitespaceAround">
<property name="allowEmptyConstructors" value="true"/>
<property name="allowEmptyLambdas" value="true"/>
<property name="allowEmptyMethods" value="true"/>
<property name="allowEmptyTypes" value="true"/>
<property name="allowEmptyLoops" value="true"/>
<property name="ignoreEnhancedForColon" value="false"/>
<property name="tokens"
value="ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR,
BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, DO_WHILE, EQUAL, GE, GT, LAMBDA, LAND,
LCURLY, LE, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY,
LITERAL_FOR, LITERAL_IF, LITERAL_RETURN, LITERAL_SWITCH, LITERAL_SYNCHRONIZED,
LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN,
NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, RCURLY, SL, SLIST, SL_ASSIGN, SR,
SR_ASSIGN, STAR, STAR_ASSIGN, LITERAL_ASSERT, TYPE_EXTENSION_AND"/>
<message key="ws.notFollowed"
value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>
<message key="ws.notPreceded"
value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
</module>

<module name="OperatorWrap">
<property name="tokens" value="PLUS, ASSIGN"/>
<property name="option" value="eol"/>
</module>

<module name="ParenPad"/>

<module name="TypecastParenPad"/>

<module name="ModifierOrder"/>

<module name="RedundantModifier"/>

<module name="NestedTryDepth">
<property name="max" value="2"/>
</module>

<module name="CovariantEquals"/>

<module name="NeedBraces">
<property name="tokens"
value="LITERAL_DO, LITERAL_ELSE, LITERAL_FOR, LITERAL_IF, LITERAL_WHILE"/>
</module>

<module name="LeftCurly">
<property name="option" value="nl"/>
</module>

<module name="RightCurly">
<property name="option" value="alone"/>
</module>

<module name="EmptyStatement"/>

<module name="EqualsHashCode"/>

<module name="DefaultComesLast"/>

<module name="SimplifyBooleanExpression"/>

<module name="SimplifyBooleanReturn"/>

<module name="StringLiteralEquality"/>

<module name="PackageDeclaration"/>

<module name="ReturnCount">
<property name="max" value="3"/>
</module>

<module name="FallThrough"/>

<module name="FinalClass"/>

<module name="MutableException"/>

<module name="ArrayTypeStyle"/>

<module name="TodoComment">
<property name="severity" value="info"/>
<property name="format" value="TODO"/>
</module>

<module name="UpperEll"/>

<module name="IllegalType">
<property name="legalAbstractClassNames"
value="AbstractBeanDefinition, AbstractAccountEvInstruction, AbstractEmsInstruction, AbstractEvInstruction, AbstractEmsAction, AbstractInstrumentAction, AbstractEntry"/>
<property name="illegalClassNames"
value="java.util.GregorianCalendar, java.util.Hashtable, java.util.Vector"/>
</module>

<module name="DescendantToken">
<property name="tokens" value="LITERAL_ASSERT"/>
<property name="limitedTokens"
value="ASSIGN,DEC,INC,POST_DEC,POST_INC,PLUS_ASSIGN,MINUS_ASSIGN,STAR_ASSIGN,DIV_ASSIGN,MOD_ASSIGN,BSR_ASSIGN,SR_ASSIGN,SL_ASSIGN,BAND_ASSIGN,BXOR_ASSIGN,BOR_ASSIGN,METHOD_CALL"/>
<property name="maximumNumber" value="2"/>
</module>

<module name="Regexp">
<property name="format" value="[ \t]+$"/>
<property name="illegalPattern" value="true"/>
<property name="message" value="Trailing whitespace"/>
</module>

<module name="FinalParameters"/>

<module name="JavadocParagraph"/>
<module name="SingleLineJavadoc"/>
<module name="JavadocMethod">
<property name="accessModifiers" value="public"/>
</module>
<module name="JavadocType">
<property name="scope" value="public"/>
</module>
<module name="JavadocVariable">
<property name="scope" value="public"/>
</module>

<module name="IllegalInstantiation"/>
<module name="MagicNumber"/>
<module name="MissingSwitchDefault"/>
</module>

<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>
</module>

0 comments on commit 073ff4a

Please sign in to comment.