Skip to content

Commit

Permalink
Add checkstyle maven plugin with basic config (#399)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver-Loeffler authored Sep 2, 2021
1 parent 487965e commit 3d04752
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ jobs:
echo 123456 | vncpasswd -f > /home/runner/.vnc/passwd
chmod -v 600 /home/runner/.vnc/passwd
vncserver :90 -localhost -nolisten tcp
mvn clean verify -X
mvn clean verify checkstyle:checkstyle --no-transfer-progress -X
vncserver -kill :90
- name: Run Tests (MacOS / Windows)
if: runner.os != 'Linux'
run: |
mvn clean verify
mvn clean verify checkstyle:checkstyle --no-transfer-progress
- name: Draft release
if: github.ref == 'refs/heads/master'
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,23 @@ You can add it as a regular dependency to the build of your app:
<version>$version</version>
</dependency>
```

## Code Style

To ensure that new code formatting matches the requirements for Pull Requests,
the Maven Checkstyle plugin can be used to create a report listing possibly coding
style violations.

Contributors can check for code-style violations in their code by running the Checkstyle Maven goal. The checkstyle configuration is currently in a very early stage and only checks for empty blocks, extra white space, padding and empty lines.

To run the plugin:

```
mvn checkstyle:checkstyle
```

There will be a report for each sub-project, one for `app` and one for `kit`.

* Kit: `kit/target/site/checkstyle.html`
* App: `kit/target/site/checkstyle.html`

84 changes: 84 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?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">
<property name="cacheFile" value="${checkstyle.cache.file}" />
<property name="severity" value="warning" />
<property name="fileExtensions" value="java, properties, xml, fxml" />

<!-- BeforeExecutionFileFilters is required for sources that are based on java9 -->
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern"
value="module\-info\.java$" />
</module>

<module name="FileTabCharacter">
<property name="eachLine" value="false" />
</module>

<module name="TreeWalker">
<property name="tabWidth" value="4"/>

<module name="GenericWhitespace"/>
<module name="EmptyForInitializerPad"/>
<module name="EmptyForIteratorPad"/>

<module name="NoWhitespaceBefore"/>
<module name="NoWhitespaceBeforeCaseDefaultColon"/>
<module name="NoWhitespaceBefore">
<property name="tokens" value="DOT"/>
<property name="tokens" value="METHOD_REF"/>
<property name="allowLineBreaks" value="true"/>
</module>

<module name="SingleSpaceSeparator">
<property name="validateComments" value="false"/>
</module>
<module name="TypecastParenPad"/>

<module name="EmptyLineSeparator">
<property name="tokens" value="IMPORT"/>
<property name="tokens" value="STATIC_IMPORT"/>
<property name="tokens" value="INTERFACE_DEF"/>
<property name="tokens" value="INSTANCE_INIT"/>
<property name="tokens" value="RECORD_DEF"/>
<property name="allowNoEmptyLineBetweenFields" value="false"/>
<property name="allowMultipleEmptyLinesInsideClassMembers" value="true"/>
</module>

<module name="NoWhitespaceAfter">
<property name="tokens" value="ARRAY_INIT"/>
<property name="tokens" value="AT"/>
<property name="tokens" value="BNOT"/>
<property name="tokens" value="DEC"/>
<property name="tokens" value="DOT"/>
<property name="tokens" value="INC"/>
<property name="tokens" value="LNOT"/>
<property name="tokens" value="UNARY_MINUS"/>
<property name="tokens" value="UNARY_PLUS"/>
<property name="tokens" value="ARRAY_DECLARATOR"/>
<property name="tokens" value="INDEX_OP"/>
<property name="tokens" value="METHOD_REF"/>
</module>

<module name="EmptyBlock">
<property name="tokens" value="LITERAL_CATCH"/>
<property name="tokens" value="LITERAL_DEFAULT"/>
<property name="tokens" value="LITERAL_CASE"/>
<property name="tokens" value="INSTANCE_INIT"/>
<property name="tokens" value="STATIC_INIT"/>
<property name="tokens" value="LITERAL_DO"/>
<property name="tokens" value="LITERAL_ELSE"/>
<property name="tokens" value="LITERAL_FINALLY"/>
<property name="tokens" value="LITERAL_FOR"/>
<property name="tokens" value="LITERAL_IF"/>
<property name="tokens" value="LITERAL_SWITCH"/>
<property name="tokens" value="LITERAL_TRY"/>
<property name="tokens" value="LITERAL_SYNCHRONIZED"/>
<property name="tokens" value="LITERAL_WHILE"/>
<property name="option" value="text"/>
</module>
</module>
</module>
29 changes: 29 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@
</configuration>
<inherited>false</inherited>
</plugin>

<!-- Enforce code formatting and style -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
</configuration>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.45.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
Expand Down Expand Up @@ -129,4 +149,13 @@
</repository>
</distributionManagement>

<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
</plugin>
</plugins>
</reporting>
</project>

0 comments on commit 3d04752

Please sign in to comment.