Skip to content

Add checkstyle to build logic #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
insert_final_newline = true
tab_width = 4

[*.java]
ij_continuation_indent_size = 8
ij_java_class_count_to_use_import_on_demand = 999
ij_java_imports_layout = *,|,com.mojang.**,net.minecraft.**,|,cpw.mods.**,net.fabricmc.**,net.minecraftforge.**,net.neoforged.**,|,com.llamalad7.mixinextras.**,org.spongepowered.**,|,top.hendrixshen.magiclib.**,|,java.**,javax.**,|,$*
ij_java_replace_instanceof_and_cast = true
ij_java_replace_null_check = true
ij_java_replace_sum_lambda_with_method_ref = true
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Auto detect text files and perform LF normalization
* text=auto
* text=auto eol=lf
*.bat text eol=crlf
19 changes: 19 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,39 @@ jobs:
prepare_action_info:
if: ${{ !startsWith(github.event.ref, 'refs/tags/') }}
uses: ./.github/workflows/prepare_action_info.yml
cache:
if: ${{ !contains(github.event.head_commit.message, '[build skip]') }}
uses: ./.github/workflows/cache.yml
secrets: inherit
needs:
- prepare_action_info
with:
build_version_type: ${{ needs.prepare_action_info.outputs.build_version_type }}
build:
if: ${{ !contains(github.event.head_commit.message, '[build skip]') }}
uses: ./.github/workflows/build.yml
secrets: inherit
needs:
- cache
- prepare_action_info
with:
build_publish: ${{ fromJSON(needs.prepare_action_info.outputs.build_publish) }}
build_version_type: ${{ needs.prepare_action_info.outputs.build_version_type }}
checkstyle:
if: ${{ !contains(github.event.head_commit.message, '[build skip]') }}
uses: ./.github/workflows/checkstyle.yml
secrets: inherit
needs:
- cache
- prepare_action_info
with:
build_version_type: ${{ needs.prepare_action_info.outputs.build_version_type }}
publish:
if: ${{ fromJSON(needs.prepare_action_info.outputs.publish_enable) }}
uses: ./.github/workflows/publish.yml
secrets: inherit
needs:
- checkstyle
- build
- prepare_action_info
with:
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ jobs:
- name: Validate gradle wrapper
uses: gradle/actions/wrapper-validation@v4
- name: Cache gradle files
uses: actions/cache@v4
uses: actions/cache/restore@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
./.gradle/loom-cache
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle', '**/gradle.properties', '**/*.accesswidener', 'settings.json') }}
restore-keys: |
${{ runner.os }}-gradle-
# TODO: Remove in next major version
- name: Preprocess Resources
run: |
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: _step.cache
on:
workflow_call:
inputs:
build_version_type:
type: string
default: 'DEV'
required: false
jobs:
cache:
runs-on: ubuntu-24.04
steps:
- name: Checkout the sources
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 21
- name: Validate gradle wrapper
uses: gradle/actions/wrapper-validation@v4
- name: Cache gradle files
uses: actions/cache@v4
id: cache
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
./.gradle/loom-cache
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle', '**/gradle.properties', '**/*.accesswidener', 'settings.json') }}
restore-keys: |
${{ runner.os }}-gradle-
lookup-only: true
- name: Init with gradle
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
run: |
chmod +x gradlew
./gradlew
env:
BUILD_TYPE: ${{ inputs.build_version_type }}
49 changes: 49 additions & 0 deletions .github/workflows/checkstyle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: _step.checkstyle
on:
workflow_call:
inputs:
build_version_type:
type: string
default: 'DEV'
required: false
jobs:
checkstyle:
runs-on: ubuntu-24.04
steps:
- name: Checkout the sources
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 21
- name: Validate gradle wrapper
uses: gradle/actions/wrapper-validation@v4
- name: Cache gradle files
uses: actions/cache/restore@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
./.gradle/loom-cache
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle', '**/gradle.properties', '**/*.accesswidener', 'settings.json') }}
# TODO: Remove in next major version
- name: Preprocess Resources
run: |
chmod +x gradlew
./gradlew preprocessResources
env:
BUILD_TYPE: ${{ inputs.build_version_type }}
- name: Checkstyle with gradle
run: |
./gradlew checkstyleMain -x test --stacktrace
env:
BUILD_TYPE: ${{ inputs.build_version_type }}
- name: Publish Checkstyle report
uses: Juuxel/publish-checkstyle-report@v1
if: ${{ failure() }}
with:
reports: |
*/**/build/reports/checkstyle/*.xml
200 changes: 200 additions & 0 deletions checkstyle-light.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">
<property name="charset" value="UTF-8"/>
<property name="fileExtensions" value="java"/>
<property name="localeLanguage" value="en"/>
<property name="localeCountry" value="US"/>
<property name="tabWidth" value="4"/>

<module name="NewlineAtEndOfFile"/>

<!-- Enforce spaces -->
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>

<!-- disallow trailing whitespace -->
<module name="RegexpSingleline">
<property name="format" value="\s+$"/>
<property name="message" value="trailing whitespace"/>
</module>

<!-- note: RegexpMultiline shows nicer messages than Regexp, but has to be outside TreeWalker -->
<!-- disallow multiple consecutive blank lines -->
<module name="RegexpMultiline">
<property name="format" value="\n[\t ]*\r?\n[\t ]*\r?\n"/>
<property name="message" value="adjacent blank lines"/>
</module>

<!-- disallow blank after { -->
<module name="RegexpMultiline">
<property name="format" value="\{[\t ]*\r?\n[\t ]*\r?\n"/>
<property name="message" value="blank line after '{'"/>
</module>

<!-- disallow blank before } -->
<module name="RegexpMultiline">
<property name="format" value="\n[\t ]*\r?\n[\t ]*\}"/>
<property name="message" value="blank line before '}'"/>
</module>

<!-- require blank before { in the same indentation level -->
<module name="RegexpMultiline">
<!-- the regex works as follows:
It matches (=fails) for \n<indentation><something>\n<same indentation><control statement>[...]{\n
while <something> is a single line comment, it'll look for a blank line one line earlier
if <something> is a space, indicating a formatting error or ' */', it'll ignore the instance
if <something> is a tab, indicating a continued line, it'll ignore the instance
<control statement> is 'if', 'do', 'while', 'for', 'try' or nothing (instance initializer block)

- first \n: with positive lookbehind (?<=\n) to move the error marker to a more reasonable place
- capture tabs for <indentation>, later referenced via \1
- remaining preceding line as a non-comment (doesn't start with '/', '//', ' ' or '\t') or multiple lines where all but the first are a single line comment with the same indentation
- new line
- <indentation> as captured earlier
- <control statement> as specified above
- { before the next new line -->
<property name="format" value="(?&lt;=\n)([\t]+)(?:[^/\r\n \t][^\r\n]*|/[^/\r\n][^\r\n]*|[^/\r\n][^\r\n]*(\r?\n\1//[^\r\n]*)+)\r?\n\1(|(if|do|while|for|try)[^\r\n]+)\{[\t ]*\r?\n"/>
<property name="message" value="missing blank line before block at same indentation level"/>
</module>

<!-- require blank after } in the same indentation level -->
<module name="RegexpMultiline">
<!-- \n<indentation>}\n<same indentation><whatever unless newline, '}' or starting with cas(e) or def(ault)> -->
<property name="format" value="(?&lt;=\n)([\t]+)\}\r?\n\1(?:[^\r\n\}cd]|c[^\r\na]|ca[^\r\ns]|d[^\r\ne]|de[^\r\nf])"/>
<property name="message" value="missing blank line after block at same indentation level"/>
</module>

<module name="TreeWalker">
<!-- Allow "//CHECKSTYLE.OFF: <InspectionName>" and "//CHECKSTYLE.ON: <InspectionName>" pairs to toggle some inspections -->
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="CHECKSTYLE.OFF\: ([\w\|]+)"/>
<property name="onCommentFormat" value="CHECKSTYLE.ON\: ([\w\|]+)"/>
<property name="checkFormat" value="$1"/>
</module>

<!-- Ensure all imports are ship shape -->
<module name="AvoidStarImport"/>
<module name="IllegalImport"/>
<module name="RedundantImport"/>
<module name="UnusedImports"/>

<module name="ImportOrder">
<!-- import order:
// 1. other
import *;
// 2. Minecraft related
import com.mojang.*;
import net.minecraft.*;
// 3. ModLoader related
import cpw.mods.*;
import net.fabricmc.*;
import net.minecraftforge;
import net.neoforged.*;
// 4. Mixin related
import com.llamalad7.mixinextras;
import org.spongepowered.*
// 5. magiclib related
import top.hendrixshen.magiclib.*;
// 6. java related
import java.*;
import javax.*; -->
<property name="groups" value="*,/^(com\.mojang|net\.minecraft)\./,/^(cpw\.mods|net\.(fabricmc|minecraftforge|neoforged))\./,/^(com\.llamalad7\.mixinextras|org\.spongepowered)\./,top.hendrixshen.magiclib,/^javax?\./"/>
<property name="ordered" value="true"/>
<property name="separated" value="true"/>
<property name="option" value="top"/>
<property name="sortStaticImportsAlphabetically" value="true"/>
</module>

<!-- Ensures braces are at the end of a line -->
<module name="LeftCurly"/>
<module name="RightCurly"/>

<!-- single line statements on one line, -->
<module name="NeedBraces">
<property name="tokens" value="LITERAL_IF,LITERAL_FOR,LITERAL_WHILE"/>
<property name="allowSingleLineStatement" value="true"/>
</module>
<module name="NeedBraces">
<property name="tokens" value="LITERAL_ELSE,LITERAL_DO"/>
<property name="allowSingleLineStatement" value="false"/>
</module>

<module name="EmptyLineSeparator">
<property name="allowNoEmptyLineBetweenFields" value="true"/>
<property name="allowMultipleEmptyLines" value="false"/>
<!-- exclude METHOD_DEF and VARIABLE_DEF -->
<property name="tokens" value="PACKAGE_DEF,IMPORT,STATIC_IMPORT,CLASS_DEF,INTERFACE_DEF,ENUM_DEF,STATIC_INIT,INSTANCE_INIT,CTOR_DEF"/>
</module>

<module name="OperatorWrap"/>
<module name="SeparatorWrap">
<property name="tokens" value="DOT,ELLIPSIS,AT"/>
<property name="option" value="nl"/>
</module>
<module name="SeparatorWrap">
<property name="tokens" value="COMMA,SEMI"/>
<property name="option" value="eol"/>
</module>

<module name="Indentation">
<property name="basicOffset" value="4"/>
<property name="caseIndent" value="4"/>
<property name="throwsIndent" value="4"/>
<property name="arrayInitIndent" value="4"/>
<property name="lineWrappingIndentation" value="8"/>
</module>

<module name="ParenPad"/>
<module name="NoWhitespaceBefore"/>
<module name="NoWhitespaceAfter">
<!-- allow ARRAY_INIT -->
<property name="tokens" value="AT,INC,DEC,UNARY_MINUS,UNARY_PLUS,BNOT,LNOT,DOT,ARRAY_DECLARATOR,INDEX_OP"/>
</module>
<module name="WhitespaceAfter"/>
<module name="WhitespaceAround">
<!-- Allow PLUS, MINUS, MUL, DIV as they may be more readable without spaces in some cases -->
<property name="tokens" value="ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,COLON,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_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS_ASSIGN,QUESTION,RCURLY,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,LITERAL_ASSERT,TYPE_EXTENSION_AND"/>
</module>
<module name="SingleSpaceSeparator"/>
<module name="GenericWhitespace"/>

<module name="ArrayTypeStyle"/>
<module name="DefaultComesLast">
<property name="skipIfLastAndSharedWithCase" value="true"/>
</module>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<module name="StringLiteralEquality"/>

<module name="ModifierOrder"/>
<module name="RedundantModifier"/>

<module name="AnnotationLocation"/>
<module name="MissingOverride"/>

<!-- By default this allows catch blocks with only comments -->
<module name="EmptyCatchBlock"/>

<module name="OuterTypeFilename"/>
<module name="PackageDeclaration"/>

<!--<module name="InvalidJavadocPosition"/>-->
<module name="JavadocParagraph"/>
<module name="JavadocStyle"/>
<module name="AtclauseOrder">
<property name="tagOrder" value="@param,@return,@throws,@deprecated"/>
</module>

<!-- Prevent var for all cases other than new instance creation -->
<module name="MatchXpath">
<property name="query" value="//VARIABLE_DEF[./TYPE/IDENT[@text='var'] and not(./ASSIGN/EXPR/LITERAL_NEW)]"/>
</module>

<!-- Prevent public records in API packages -->
<module name="MatchXpath">
<property name="query" value="//RECORD_DEF[./MODIFIERS/LITERAL_PUBLIC][//PACKAGE_DEF//DOT/IDENT[@text='api']]"/>
</module>
</module>
</module>
Loading