Skip to content

Commit

Permalink
Introduction of checkstyle (#7089)
Browse files Browse the repository at this point in the history
* added checkstyle for Skript code conventions

* removed the check for short field names and required braces for code blocks

* added GitHub workflow for checkstyle
disabled checkstyle check running after `build` task
changed severity of code violations to warning

* added information about empty lines at the end of the java files to the code conventions

* added artifact upload for the checkstyle reports

* Update code-conventions.md

Co-authored-by: Efy <[email protected]>

---------

Co-authored-by: sovdee <[email protected]>
Co-authored-by: Efy <[email protected]>
  • Loading branch information
3 people authored Sep 22, 2024
1 parent 19985d9 commit 03cd121
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/checkstyle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: checkstyle

on:
push:
branches:
- master
- 'dev/**'
pull_request:

jobs:
build:
if: "! contains(toJSON(github.event.commits.*.message), '[ci skip]')"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: validate gradle wrapper
uses: gradle/wrapper-validation-action@v2
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'adopt'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Run checkstyle
run: ./gradlew clean checkstyleMain
- name: Upload checkstyle report
uses: actions/upload-artifact@v4
if: success()
with:
name: checkstyle-report
path: |
build/reports/checkstyle/*.xml
build/reports/checkstyle/*.html
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'maven-publish'
id 'java'
id 'checkstyle'
}

configurations {
Expand Down Expand Up @@ -42,6 +43,11 @@ dependencies {
testShadow group: 'org.easymock', name: 'easymock', version: '5.4.0'
}

checkstyle {
configFile = new File("checkstyle.xml")
sourceSets = [] // disables checkstyle after build task
}

task checkAliases {
description 'Checks for the existence of the aliases.'
doLast {
Expand Down
100 changes: 100 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?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">

<!--Basic Settings-->
<!--Warning severity so the builds do not fail because of checkstyle, this is mainly for the GitHub workflow-->
<property name="severity" value="warning"/>
<property name="fileExtensions" value="java"/>
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>

<!--At most 120 characters per line-->
<module name="LineLength">
<property name="max" value="120"/>
</module>

<!--New line at the end of the file-->
<module name="NewlineAtEndOfFile"/>

<module name="TreeWalker">

<!--Tabs, no spaces-->
<module name="RegexpSinglelineJava">
<property name="format" value="^\t* "/>
<property name="message" value="Indent must use tab characters"/>
<property name="ignoreComments" value="true"/>
</module>

<!--No trailing whitespace-->
<module name="NoWhitespaceAfter" />

<!--When statements consume multiple lines, all lines but the first have two tabs of additional indentation-->
<module name="Indentation">
<property name="arrayInitIndent" value="8" />
<property name="basicOffset" value="8" />
<property name="caseIndent" value="8" />
<property name="lineWrappingIndentation" value="8" />
<property name="throwsIndent" value="8" />
</module>

<!--Each class begins with an empty line-->
<module name="EmptyLineSeparator">
<property name="allowNoEmptyLineBetweenFields" value="true" />
<property name="tokens"
value="IMPORT, STATIC_IMPORT, CLASS_DEF, INTERFACE_DEF,
ENUM_DEF, STATIC_INIT, INSTANCE_INIT, METHOD_DEF,
CTOR_DEF, VARIABLE_DEF, RECORD_DEF, COMPACT_CTOR_DEF" />
</module>

<module name="OneStatementPerLine"/>

<!--Annotations for a structure go on the line before that structure-->
<module name="AnnotationLocation"/>

<!--When splitting Strings into multiple lines the last part of the string must be (space character included) " " +-->
<module name="OperatorWrap">
<property name="option" value="eol" />
<property name="tokens" value="PLUS" />
</module>

<!--Class names are written in UpperCamelCase-->
<module name="TypeName"/>

<!--Methods named in camelCase-->
<module name="MethodName"/>

<!--Static constant fields should be named in UPPER_SNAKE_CASE-->
<module name="ConstantName"/>

<!--We use JetBrains Annotations for specifying null-ness-->
<module name="IllegalImport">
<property name="illegalClasses"
value="javax.annotation.Nonnull,
javax.annotation.Nullable,
org.eclipse.jdt.annotation.NonNull,
org.eclipse.jdt.annotation.Nullable,
org.eclipse.sisu.Nullable,
org.checkerframework.checker.nullness.qual.NonNull,
org.checkerframework.checker.nullness.qual.Nullable" />
<property name="illegalPkgs" value="" />
</module>

<!--Modules for code improvements-->
<module name="MissingOverride"/>
<module name="EmptyBlock"/>
<module name="HideUtilityClassConstructor"/>
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<module name="StringLiteralEquality"/>
<module name="UnusedLocalVariable"/>

</module>

</module>
1 change: 1 addition & 0 deletions code-conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ If we need to remove or alter contributed code due to a licensing issue we will
- The exception to this is breaking up conditional statements (e.g. `if (x || y)`) where the
condition starts may be aligned
* Each class begins with an empty line
* Each Java file ends with an empty line
* No squeezing of multiple lines of code on a single line
* Separate method declarations with empty lines
- Empty line after last method in a class is *not* required
Expand Down

0 comments on commit 03cd121

Please sign in to comment.