Skip to content

Commit

Permalink
add checkstyle (fixes #15)
Browse files Browse the repository at this point in the history
  • Loading branch information
ix0rai committed Mar 10, 2024
1 parent 1ec1b95 commit b1fe79d
Show file tree
Hide file tree
Showing 39 changed files with 354 additions and 115 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
distribution: "temurin"
java-version: 17
- uses: gradle/wrapper-validation-action@v1
- run: ./gradlew build publish --stacktrace
- run: ./gradlew build checkstyleMain publish --stacktrace
env:
MAVEN_URL: ${{ secrets.MAVEN_URL }}
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
distribution: "temurin"
java-version: ${{ matrix.java }}
- uses: gradle/wrapper-validation-action@v1
- run: ./gradlew build test publishToMavenLocal --stacktrace
- run: ./gradlew build checkstyleMain test publishToMavenLocal --stacktrace
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'java'
id 'maven-publish'
id 'checkstyle'
id 'org.quiltmc.gradle.licenser' version '1.+'
}

Expand Down
167 changes: 167 additions & 0 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?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"/>

<!-- 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 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">
<property name="excludes" value="org.hamcrest.Matchers"/>
</module>
<module name="IllegalImport"/>
<module name="RedundantImport"/>
<module name="UnusedImports"/>

<module name="ImportOrder">
<property name="groups" value="*,/java|javax/"/>
<property name="ordered" value="false"/><!-- the plugin orders alphabetically without considering separators.. -->
<property name="separated" value="true"/>
<property name="option" value="bottom"/>
<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"/>

<property name="allowEmptyConstructors" value="true" />
<property name="allowEmptyMethods" value="true" />
<property name="allowEmptyTypes" value="true" />
<property name="allowEmptyLoops" value="true" />
<property name="allowEmptyLambdas" value="true" />
</module>
<module name="SingleSpaceSeparator"/>
<module name="GenericWhitespace"/>
<module name="CommentsIndentation"/>

<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"/>

<!-- Require the use of the "this" keyword -->
<module name="RequireThis">
<property name="validateOnlyOverlapping" value="false"/>
</module>

<!-- Enforce tabs -->
<module name="RegexpSinglelineJava">
<property name="format" value="^\t* ([^*]|\*[^ /])"/>
<property name="message" value="non-tab indentation"/>
</module>

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

<!--<module name="InvalidJavadocPosition"/>-->
<module name="JavadocParagraph">
<property name="allowNewlineParagraph" value="false"/>
</module>
<module name="AtclauseOrder">
<property name="tagOrder" value="@param,@return,@throws,@deprecated"/>
</module>
</module>
</module>
25 changes: 13 additions & 12 deletions src/main/java/org/quiltmc/config/api/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
import org.quiltmc.config.api.metadata.MetadataContainer;
import org.quiltmc.config.api.metadata.MetadataContainerBuilder;
import org.quiltmc.config.api.metadata.MetadataType;
import org.quiltmc.config.api.values.*;
import org.quiltmc.config.api.values.TrackedValue;
import org.quiltmc.config.api.values.ValueKey;
import org.quiltmc.config.api.values.ValueList;
import org.quiltmc.config.api.values.ValueMap;
import org.quiltmc.config.api.values.ValueTreeNode;
import org.quiltmc.config.impl.ConfigImpl;

import java.nio.file.Path;
Expand Down Expand Up @@ -106,7 +110,6 @@ public interface Config extends MetadataContainer {
* <li>ValueTreeNode.Section("gui")</li>
* <li>TrackedValue("count", 100)</li>
* </ul>
*
* iterating over children would need to be done by checking <pre>node instanceof ValueTreeNode.Section</pre>
* and iterating over that node as well, recursively.
*/
Expand Down Expand Up @@ -402,21 +405,19 @@ interface Creator {
void create(Builder builder);
}


/**
* @deprecated for removal; use {@link ReflectiveConfig.Section}
*/
@Deprecated
interface Section {

}

@ApiStatus.NonExtendable
interface Builder extends SectionBuilder {
/**
* Adds a value to this config file
* Adds a value to this config file.
*
* A field should be either:
* <p>A field should be either:
* <ul>
* <li>A basic type ({@link Integer}, {@link Long}, {@link Float}, {@link Double}, {@link Boolean}, {@link String}, or enum)</li>
* <li>A complex type (a {@link ValueList} or {@link ValueMap} of basic or complex types)</li>
Expand All @@ -433,7 +434,7 @@ interface Builder extends SectionBuilder {
Builder section(String key, Consumer<SectionBuilder> creator);

/**
* Create or configure a piece of metadata
* Create or configure a piece of metadata.
*
* @param type the type of metadata to configure
* @param builderConsumer the modifications to be made to the piece of metadata
Expand All @@ -442,17 +443,17 @@ interface Builder extends SectionBuilder {
<M, B extends MetadataType.Builder<M>> Builder metadata(MetadataType<M, B> type, Consumer<B> builderConsumer);

/**
* Adds a default listener to the resulting {@link Config} that's called whenever any of its values updated
* Adds a default listener to the resulting {@link Config} that's called whenever any of its values updated.
*
* @param callback an update listener
* @return this
*/
Builder callback(UpdateCallback callback);

/**
* Sets the default file type for the config file this config will be saved to
* Sets the default file type for the config file this config will be saved to.
*
* Note that this can be overridden by the end user with a launch parameter
* <p>Note that this can be overridden by the end user with a launch parameter
*
* @return this
*/
Expand All @@ -462,9 +463,9 @@ interface Builder extends SectionBuilder {
@ApiStatus.NonExtendable
interface SectionBuilder extends MetadataContainerBuilder<SectionBuilder> {
/**
* Adds a value to this config file
* Adds a value to this config file.
*
* A field should be either:
* <p>A field should be either:
* <ul>
* <li>A basic type ({@link Integer}, {@link Long}, {@link Float}, {@link Double}, {@link Boolean}, {@link String}, or enum)</li>
* <li>A complex type (a {@link ValueList} or {@link ValueMap} of basic or complex types)</li>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/quiltmc/config/api/Constraint.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static Constraint<String> matching(String regex) {

@Override
public Optional<String> test(String value) {
if (pattern.matcher(value).matches()) {
if (this.pattern.matcher(value).matches()) {
return Optional.empty();
} else {
return Optional.of(String.format("Value '%s' does not match pattern '%s'", value, regex));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/quiltmc/config/api/ReflectiveConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public final <T> TrackedValue<T> value(T defaultValue) {

@SafeVarargs
public final <T> TrackedValue<ValueList<T>> list(T defaultValue, T... values) {
return value(ValueList.create(defaultValue, values));
return this.value(ValueList.create(defaultValue, values));
}

public final <T> ValueMap.TrackedBuilder<T> map(T defaultValue) {
Expand All @@ -121,7 +121,7 @@ public final <T> TrackedValue<T> value(T defaultValue) {

@SafeVarargs
public final <T> TrackedValue<ValueList<T>> list(T defaultValue, T... values) {
return value(ValueList.create(defaultValue, values));
return this.value(ValueList.create(defaultValue, values));
}

public final <T> ValueMap.TrackedBuilder<T> map(T defaultValue) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/quiltmc/config/api/WrappedConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.nio.file.Path;
import java.util.Map;


/**
* @deprecated for removal: use {@link ReflectiveConfig} instead.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
final class Builder implements MetadataType.Builder<Aliases> {
private final List<String> aliases = new ArrayList<>(0);

public Builder() {
Builder() {
}

public void add(String... aliases) {
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/org/quiltmc/config/api/annotations/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@
import org.quiltmc.config.api.metadata.MetadataType;
import org.quiltmc.config.impl.CommentsImpl;

import java.lang.annotation.*;
import java.util.*;
import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
* Used to annotate fields of classes that represent config files with comments that can be saved to disk or displayed
Expand All @@ -41,7 +49,7 @@
final class Builder implements MetadataType.Builder<Comments> {
private final List<String> comments = new ArrayList<>(0);

public Builder() {
Builder() {
}

public void add(String... comments) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.quiltmc.config.impl.ConfigFieldAnnotationProcessors;

import java.lang.annotation.Annotation;
import java.util.Collections;

/**
* Converts data in an annotation on a field to metadata on a {@link TrackedValue}.
Expand All @@ -33,7 +32,6 @@ public interface ConfigFieldAnnotationProcessor<T extends Annotation> {

static <T extends Annotation> void register(Class<T> annotationClass, ConfigFieldAnnotationProcessor<T> processor) {
ConfigFieldAnnotationProcessors.register(annotationClass, processor);

}

static void applyAnnotationProcessors(Annotation annotation, MetadataContainerBuilder<?> builder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
* </ul>
*
* <h3>Examples:</h3>
*
* Tracked value:
* <pre>
* {@code
Expand All @@ -47,7 +46,7 @@
* }
* </pre>
*
* Config class:
* <p>Config class:
* <pre>
* {@code
* @Processor("processConfig")
Expand All @@ -59,7 +58,7 @@
* }
* </pre>
*
* Section:
* <p>Section:
* <pre>
* {@code
* @Processor("processCoolSection")
Expand Down
Loading

0 comments on commit b1fe79d

Please sign in to comment.