Skip to content

Commit

Permalink
Sync checkstyle configuration with upstream (Checkstyle's own linting…
Browse files Browse the repository at this point in the history
… configuration to run on itself) and split strict checkstyle profiles.
  • Loading branch information
motlin committed Apr 14, 2024
1 parent 774f8e5 commit ec7d210
Show file tree
Hide file tree
Showing 8 changed files with 777 additions and 293 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,42 @@ jobs:
- name: 'Clean Maven cache'
run: rm -rf ~/.m2/repository/io/liftwizard

checkstyle-semantics-strict:
name: checkstyle xml (semantics strict)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- uses: actions/cache@v4
with:
key: checkstyle-${{ hashFiles('**/pom.xml') }}
path: ~/.m2/repository
restore-keys: |
${{ runner.os }}-maven-
- uses: actions/setup-java@v4
with:
java-version-file: .tool-versions
distribution: oracle

- name: 'Install liftwizard-checkstyle module'
run: ./mvnw install --projects liftwizard-utility/liftwizard-checkstyle


- name: 'Produce Checkstyle XML: Strict Semantics'
run: ./mvnw checkstyle:check --activate-profiles 'checkstyle-semantics-strict' -Dcheckstyle.failOnViolation=false -Dcheckstyle.failsOnError=false -Dcheckstyle.output.format=xml

- name: 'Checkstyle GitHub Annotations: Strict Semantics'
uses: lcollins/checkstyle-github-action@v2.0.0
with:
name: 'checkstyle annotations (semantics strict)'
path: '**/checkstyle-result.xml'

- name: 'Clean Maven cache'
run: rm -rf ~/.m2/repository/io/liftwizard

checkstyle-formatting:
name: checkstyle xml (formatting)
runs-on: ubuntu-latest
Expand Down Expand Up @@ -168,6 +204,41 @@ jobs:
- name: 'Clean Maven cache'
run: rm -rf ~/.m2/repository/io/liftwizard

checkstyle-formatting-strict:
name: checkstyle xml (formatting strict)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- uses: actions/cache@v4
with:
key: checkstyle-${{ hashFiles('**/pom.xml') }}
path: ~/.m2/repository
restore-keys: |
${{ runner.os }}-maven-
- uses: actions/setup-java@v4
with:
java-version-file: .tool-versions
distribution: oracle

- name: 'Install liftwizard-checkstyle module'
run: ./mvnw install --projects liftwizard-utility/liftwizard-checkstyle

- name: 'Produce Checkstyle XML: Strict Formatting'
run: ./mvnw checkstyle:check --activate-profiles 'checkstyle-formatting-strict' -Dcheckstyle.failOnViolation=false -Dcheckstyle.failsOnError=false -Dcheckstyle.output.format=xml

- name: 'Checkstyle GitHub Annotations: Strict Formatting'
uses: lcollins/checkstyle-github-action@v2.0.0
with:
name: 'checkstyle annotations (formatting strict)'
path: '**/checkstyle-result.xml'

- name: 'Clean Maven cache'
run: rm -rf ~/.m2/repository/io/liftwizard

rewrite:
runs-on: ubuntu-latest
steps:
Expand Down
28 changes: 28 additions & 0 deletions checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0"?>
<!--
~ Copyright 2024 Craig Motlin
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">

<suppressions>

<suppress files="[\\/]generated-sources[\\/]" checks="[a-zA-Z0-9]*" />
<suppress files="Bundle.java$" checks="AbstractClassName" />
<suppress files=".*" id="singleLineCommentStartWithSpace" />

</suppressions>
76 changes: 69 additions & 7 deletions liftwizard-maven-build/liftwizard-parent-build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<version>3.3.1</version>
<configuration>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<suppressionsLocation>${maven.multiModuleProjectDirectory}/checkstyle-suppressions.xml</suppressionsLocation>
</configuration>
<dependencies>
<dependency>
Expand Down Expand Up @@ -399,20 +400,51 @@
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.1</version>
<dependencies>
<dependency>
<groupId>io.liftwizard</groupId>
<artifactId>liftwizard-checkstyle</artifactId>
<version>2.1.7-SNAPSHOT</version>
</dependency>
</dependencies>
<configuration>
<configLocation>checkstyle-configuration-liftwizard-semantics.xml</configLocation>
<suppressionsLocation>checkstyle-suppressions-liftwizard.xml</suppressionsLocation>
</configuration>
<executions>
<execution>
<id>checkstyle:check semantics</id>
<goals>
<goal>check</goal>
</goals>
<phase>prepare-package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>checkstyle-semantics-strict</id>

<build>
<plugins>
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.1</version>
<dependencies>
<dependency>
<groupId>io.liftwizard</groupId>
<artifactId>liftwizard-checkstyle</artifactId>
<version>2.1.7-SNAPSHOT</version>
</dependency>
</dependencies>
<configuration>
<configLocation>checkstyle-configuration-liftwizard-semantics-strict.xml</configLocation>
</configuration>
<executions>
<execution>
<id>checkstyle:check semantics</id>
<id>checkstyle:check strict semantics</id>
<goals>
<goal>check</goal>
</goals>
Expand All @@ -423,9 +455,7 @@
</plugins>
</build>
</profile>
<!--endregion-->

<!--region Phase 21: verify-->
<profile>
<id>checkstyle-formatting</id>

Expand All @@ -434,20 +464,52 @@
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.1</version>
<dependencies>
<dependency>
<groupId>io.liftwizard</groupId>
<artifactId>liftwizard-checkstyle</artifactId>
<version>2.1.7-SNAPSHOT</version>
</dependency>
</dependencies>
<configuration>
<configLocation>checkstyle-configuration-liftwizard-formatting.xml</configLocation>
<suppressionsLocation>checkstyle-suppressions-liftwizard.xml</suppressionsLocation>
</configuration>
<executions>
<execution>
<id>checkstyle:check formatting</id>
<goals>
<goal>check</goal>
</goals>
<phase>prepare-package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>

</profile>

<profile>
<id>checkstyle-formatting-strict</id>

<build>
<plugins>
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.1</version>
<dependencies>
<dependency>
<groupId>io.liftwizard</groupId>
<artifactId>liftwizard-checkstyle</artifactId>
<version>2.1.7-SNAPSHOT</version>
</dependency>
</dependencies>
<configuration>
<configLocation>checkstyle-configuration-liftwizard-formatting-strict.xml</configLocation>
</configuration>
<executions>
<execution>
<id>checkstyle:check formatting</id>
<id>checkstyle:check strict formatting</id>
<goals>
<goal>check</goal>
</goals>
Expand Down Expand Up @@ -574,8 +636,8 @@
<artifactId>rewrite-maven-plugin</artifactId>
<configuration>
<activeRecipes>
<recipe>org.openrewrite.java.testing.assertj.Assertj</recipe>
<recipe>org.openrewrite.java.testing.junit5.JUnit5BestPractices</recipe>
<recipe>org.openrewrite.java.testing.assertj.Assertj</recipe>

<recipe>io.liftwizard.java.migrate.UpgradeToJava17</recipe>
</activeRecipes>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0"?>
<!--
~ Copyright 2024 Craig Motlin
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">

<!-- Adapted from https://github.com/checkstyle/checkstyle/blob/master/config/checkstyle_checks.xml -->
<module name="Checker">
<property name="severity" value="error" />

<!--region Filters-->
<module name="SeverityMatchFilter">
<!-- report all violations except ignore -->
<property name="severity" value="ignore" />
<property name="acceptOnMatch" value="false" />
</module>
<!--endregion-->

<!--region Miscellaneous-->
<!--https://checkstyle.sourceforge.io/checks/misc/index.html-->
<!--endregion-->

<!--region Regexp-->
<!--https://checkstyle.sourceforge.io/checks/regexp/index.html-->
<module name="RegexpMultiline">
<property name="format" value="\{\n\n" />
<property name="message" value="First line after opening a scope may not be blank." />
</module>
<module name="RegexpMultiline">
<property name="format" value="\n\n[ ]*\}" />
<property name="message" value="Last line before closing a scope may not be blank." />
</module>
<!--endregion-->

<!-- Whitespace -->
<!--endregion-->

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

<!--region Whitespace-->
<!--https://checkstyle.sourceforge.io/checks/whitespace/index.html-->
<module name="SingleSpaceSeparator">
<property name="validateComments" value="false" />
<property name="severity" value="warning" />
</module>

<module name="MatchXpath">
<property name="id" value="singleLineCommentStartWithSpace" />
<property name="query"
value="//SINGLE_LINE_COMMENT[./COMMENT_CONTENT[not(starts-with(@text, ' '))
and not(@text = '\n') and not(ends-with(@text, '//\n'))
and not(@text = '\r') and not(ends-with(@text, '//\r'))
and not(@text = '\r\n') and not(ends-with(@text, '//\r\n'))]]" />
<message key="matchxpath.match" value="Single line comment text should start with space." />
</module>
<!--endregion-->

<!--region Indentation-->
<!--endregion-->

<!--region Blocks-->
<!--endregion-->

</module>

</module>
Loading

0 comments on commit ec7d210

Please sign in to comment.