Skip to content

Commit

Permalink
Update formatting rules, add Spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
NebelNidas authored and sfPlayer1 committed Feb 6, 2025
1 parent 03f24c7 commit 565c421
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ tab_width = 4

[*.{gradle,java}]
ij_continuation_indent_size = 8
ij_java_imports_layout = $*,|,java.**,|,javax.**,|,*,|,net.fabricmc.**
ij_java_imports_layout = $*,|,java.**,|,javax.**,|,*,|,net.fabricmc.**,|,matcher.**
ij_java_class_count_to_use_import_on_demand = 999

[*.{yml,yaml}]
Expand Down
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* text=auto eol=lf
*.bat text eol=crlf
12 changes: 12 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id 'application'
id 'maven-publish'
id "checkstyle"
id 'com.diffplug.spotless'
id 'org.openjfx.javafxplugin'
id 'org.gradlex.extra-java-module-info'
id 'com.gradleup.shadow'
Expand Down Expand Up @@ -30,6 +31,17 @@ checkstyle {
toolVersion = project.checkstyle_version
}

spotless {
lineEndings = com.diffplug.spotless.LineEnding.UNIX

java {
removeUnusedImports()
importOrder('java.', 'javax.', '', 'net.fabricmc.', 'matcher.')
indentWithTabs()
trimTrailingWhitespace()
}
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand Down
28 changes: 19 additions & 9 deletions checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
<property name="fileExtensions" value="java"/>
<property name="localeLanguage" value="en"/>
<property name="localeCountry" value="US"/>
<property name="tabWidth" value="4"/>

<!-- Excludes all 'module-info.java' files -->
<!-- See https://checkstyle.org/config_filefilters.html -->
<!-- Exclude all 'module-info.java' files -->
<!-- See https://github.com/checkstyle/checkstyle/issues/3059 -->
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>
Expand Down Expand Up @@ -47,6 +48,7 @@
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
Expand All @@ -66,6 +68,13 @@
</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"/>
Expand All @@ -74,7 +83,7 @@

<module name="ImportOrder">
<property name="groups" value="java,javax,*,net.fabricmc,matcher"/>
<property name="ordered" value="false"/><!-- the plugin orders alphabetically without considering separators.. -->
<property name="ordered" value="true"/>
<property name="separated" value="true"/>
<property name="option" value="top"/>
<property name="sortStaticImportsAlphabetically" value="true"/>
Expand Down Expand Up @@ -112,11 +121,11 @@
</module>

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

<module name="ParenPad"/>
Expand All @@ -128,8 +137,7 @@
<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"/>
<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"/>
Expand Down Expand Up @@ -159,6 +167,8 @@
</module>

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

<!--<module name="InvalidJavadocPosition"/>-->
<module name="JavadocParagraph"/>
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
org.gradle.jvmargs=-Xmx2G

# Gradle Plugins
spotless_version = 6.25.0
javafx_plugin_version = 0.1.0
extra_java_module_info_version = 1.9
shadow_version = 8.3.5
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pluginManagement {
mavenCentral();
}
plugins {
id 'com.diffplug.spotless' version "${spotless_version}"
id 'org.openjfx.javafxplugin' version "${javafx_plugin_version}"
id 'org.gradlex.extra-java-module-info' version "${extra_java_module_info_version}"
id 'com.gradleup.shadow' version "${shadow_version}"
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/matcher/gui/menu/UidMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import matcher.type.ClassEnvironment;
import matcher.type.ClassInstance;
import matcher.type.FieldInstance;
import matcher.type.Matchable;
import matcher.type.MatchType;
import matcher.type.Matchable;
import matcher.type.MemberInstance;
import matcher.type.MethodInstance;
import matcher.type.MethodVarInstance;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/matcher/srcprocess/SrcDecorator.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

import com.github.javaparser.JavaParser;
import com.github.javaparser.JavaToken;
import com.github.javaparser.JavaToken.Kind;
import com.github.javaparser.ParseResult;
import com.github.javaparser.ParserConfiguration;
import com.github.javaparser.ParserConfiguration.LanguageLevel;
import com.github.javaparser.Position;
import com.github.javaparser.Problem;
import com.github.javaparser.Range;
import com.github.javaparser.TokenRange;
import com.github.javaparser.JavaToken.Kind;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/matcher/srcprocess/TypeResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
import com.github.javaparser.ast.type.Type;
import com.github.javaparser.ast.type.VoidType;

import matcher.type.ClassInstance;
import matcher.type.FieldInstance;
import matcher.NameType;
import matcher.type.ClassEnv;
import matcher.type.ClassInstance;
import matcher.type.FieldInstance;
import matcher.type.Matchable;
import matcher.type.MethodInstance;

Expand Down

0 comments on commit 565c421

Please sign in to comment.