Skip to content

Commit 03cd121

Browse files
PesekjaksovdeethEfnilite
authored
Introduction of checkstyle (#7089)
* 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]>
1 parent 19985d9 commit 03cd121

File tree

4 files changed

+144
-0
lines changed

4 files changed

+144
-0
lines changed

.github/workflows/checkstyle.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: checkstyle
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- 'dev/**'
8+
pull_request:
9+
10+
jobs:
11+
build:
12+
if: "! contains(toJSON(github.event.commits.*.message), '[ci skip]')"
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
submodules: recursive
18+
- name: validate gradle wrapper
19+
uses: gradle/wrapper-validation-action@v2
20+
- name: Set up JDK 21
21+
uses: actions/setup-java@v4
22+
with:
23+
java-version: '21'
24+
distribution: 'adopt'
25+
cache: gradle
26+
- name: Grant execute permission for gradlew
27+
run: chmod +x gradlew
28+
- name: Run checkstyle
29+
run: ./gradlew clean checkstyleMain
30+
- name: Upload checkstyle report
31+
uses: actions/upload-artifact@v4
32+
if: success()
33+
with:
34+
name: checkstyle-report
35+
path: |
36+
build/reports/checkstyle/*.xml
37+
build/reports/checkstyle/*.html

build.gradle

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ plugins {
77
id 'com.github.johnrengelman.shadow' version '8.1.1'
88
id 'maven-publish'
99
id 'java'
10+
id 'checkstyle'
1011
}
1112

1213
configurations {
@@ -42,6 +43,11 @@ dependencies {
4243
testShadow group: 'org.easymock', name: 'easymock', version: '5.4.0'
4344
}
4445

46+
checkstyle {
47+
configFile = new File("checkstyle.xml")
48+
sourceSets = [] // disables checkstyle after build task
49+
}
50+
4551
task checkAliases {
4652
description 'Checks for the existence of the aliases.'
4753
doLast {

checkstyle.xml

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
4+
"https://checkstyle.org/dtds/configuration_1_3.dtd">
5+
6+
<module name="Checker">
7+
8+
<!--Basic Settings-->
9+
<!--Warning severity so the builds do not fail because of checkstyle, this is mainly for the GitHub workflow-->
10+
<property name="severity" value="warning"/>
11+
<property name="fileExtensions" value="java"/>
12+
<module name="BeforeExecutionExclusionFileFilter">
13+
<property name="fileNamePattern" value="module\-info\.java$"/>
14+
</module>
15+
16+
<!--At most 120 characters per line-->
17+
<module name="LineLength">
18+
<property name="max" value="120"/>
19+
</module>
20+
21+
<!--New line at the end of the file-->
22+
<module name="NewlineAtEndOfFile"/>
23+
24+
<module name="TreeWalker">
25+
26+
<!--Tabs, no spaces-->
27+
<module name="RegexpSinglelineJava">
28+
<property name="format" value="^\t* "/>
29+
<property name="message" value="Indent must use tab characters"/>
30+
<property name="ignoreComments" value="true"/>
31+
</module>
32+
33+
<!--No trailing whitespace-->
34+
<module name="NoWhitespaceAfter" />
35+
36+
<!--When statements consume multiple lines, all lines but the first have two tabs of additional indentation-->
37+
<module name="Indentation">
38+
<property name="arrayInitIndent" value="8" />
39+
<property name="basicOffset" value="8" />
40+
<property name="caseIndent" value="8" />
41+
<property name="lineWrappingIndentation" value="8" />
42+
<property name="throwsIndent" value="8" />
43+
</module>
44+
45+
<!--Each class begins with an empty line-->
46+
<module name="EmptyLineSeparator">
47+
<property name="allowNoEmptyLineBetweenFields" value="true" />
48+
<property name="tokens"
49+
value="IMPORT, STATIC_IMPORT, CLASS_DEF, INTERFACE_DEF,
50+
ENUM_DEF, STATIC_INIT, INSTANCE_INIT, METHOD_DEF,
51+
CTOR_DEF, VARIABLE_DEF, RECORD_DEF, COMPACT_CTOR_DEF" />
52+
</module>
53+
54+
<module name="OneStatementPerLine"/>
55+
56+
<!--Annotations for a structure go on the line before that structure-->
57+
<module name="AnnotationLocation"/>
58+
59+
<!--When splitting Strings into multiple lines the last part of the string must be (space character included) " " +-->
60+
<module name="OperatorWrap">
61+
<property name="option" value="eol" />
62+
<property name="tokens" value="PLUS" />
63+
</module>
64+
65+
<!--Class names are written in UpperCamelCase-->
66+
<module name="TypeName"/>
67+
68+
<!--Methods named in camelCase-->
69+
<module name="MethodName"/>
70+
71+
<!--Static constant fields should be named in UPPER_SNAKE_CASE-->
72+
<module name="ConstantName"/>
73+
74+
<!--We use JetBrains Annotations for specifying null-ness-->
75+
<module name="IllegalImport">
76+
<property name="illegalClasses"
77+
value="javax.annotation.Nonnull,
78+
javax.annotation.Nullable,
79+
org.eclipse.jdt.annotation.NonNull,
80+
org.eclipse.jdt.annotation.Nullable,
81+
org.eclipse.sisu.Nullable,
82+
org.checkerframework.checker.nullness.qual.NonNull,
83+
org.checkerframework.checker.nullness.qual.Nullable" />
84+
<property name="illegalPkgs" value="" />
85+
</module>
86+
87+
<!--Modules for code improvements-->
88+
<module name="MissingOverride"/>
89+
<module name="EmptyBlock"/>
90+
<module name="HideUtilityClassConstructor"/>
91+
<module name="EmptyStatement"/>
92+
<module name="EqualsHashCode"/>
93+
<module name="SimplifyBooleanExpression"/>
94+
<module name="SimplifyBooleanReturn"/>
95+
<module name="StringLiteralEquality"/>
96+
<module name="UnusedLocalVariable"/>
97+
98+
</module>
99+
100+
</module>

code-conventions.md

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ If we need to remove or alter contributed code due to a licensing issue we will
9797
- The exception to this is breaking up conditional statements (e.g. `if (x || y)`) where the
9898
condition starts may be aligned
9999
* Each class begins with an empty line
100+
* Each Java file ends with an empty line
100101
* No squeezing of multiple lines of code on a single line
101102
* Separate method declarations with empty lines
102103
- Empty line after last method in a class is *not* required

0 commit comments

Comments
 (0)