From 4988103c06c8b1dacb314a1b68d2fae17336458c Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sat, 21 Oct 2023 11:44:15 +0200 Subject: [PATCH 1/2] Split Java code style checks --- .github/workflows/tests.yml | 59 +++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7578854d6a9..c2bb9245fad 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,7 +23,7 @@ concurrency: jobs: checkstyle: - name: Code style check + name: Checkstyle runs-on: ubuntu-latest steps: - name: Checkout source @@ -52,6 +52,7 @@ jobs: with: message: > Your code currently does not meet JabRef's code guidelines. + We use [Checkstyle](https://checkstyle.sourceforge.io/) to identify issues. The tool reviewdog already placed comments on GitHub to indicate the places. See the tab "Files" in you PR. Please carefully follow [the setup guide for the codestyle](https://devdocs.jabref.org/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/intellij-13-code-style.html). Afterwards, please run checkstyle locally and fix the issues. @@ -59,15 +60,69 @@ jobs: More information on code quality in JabRef is available at . comment_tag: checkstyle - reactions: eyes + openrewrite: + name: OpenRewrite + runs-on: ubuntu-latest + steps: + - name: Checkout source + uses: actions/checkout@v4 + with: + submodules: 'true' + show-progress: 'false' + - name: Set up JDK + uses: actions/setup-java@v3 + with: + java-version: 21.0.1 + distribution: 'liberica' + cache: 'gradle' - name: Run OpenRewrite run: | ./gradlew rewriteDryRun + - name: Add comment on pull request + if: ${{ failure() }} + uses: thollander/actions-comment-pull-request@v2 + with: + message: > + Your code currently does not meet JabRef's code guidelines. + We use [OpenRewrite](https://docs.openrewrite.org/) to ensure "modern" Java coding practices. + The issues found can be **automatically fixed**. + Please execute the gradle task *`rewriteRun`*, check the results, commit, and push. + + + You can check the detailed error output at the tab "Checks", section "Tests" (on the left), subsection "OpenRewrite". + comment_tag: openrewrite + modernizer: + name: Modernizer + runs-on: ubuntu-latest + steps: + - name: Checkout source + uses: actions/checkout@v4 + with: + submodules: 'true' + show-progress: 'false' + - name: Set up JDK + uses: actions/setup-java@v3 + with: + java-version: 21.0.1 + distribution: 'liberica' + cache: 'gradle' - name: Run modernizer run: | # enable failing of this task if modernizer complains sed -i "s/failOnViolations = false/failOnViolations = true/" build.gradle ./gradlew modernizer + - name: Add comment on pull request + if: ${{ failure() }} + uses: thollander/actions-comment-pull-request@v2 + with: + message: > + Your code currently does not meet JabRef's code guidelines. + We use [Gradle Modernizer Plugin](https://github.com/andygoossens/gradle-modernizer-plugin#gradle-modernizer-plugin) to ensure "modern" Java coding practices. + Please fix the detected errors, commit, and push. + + + You can check the detailed error output at the tab "Checks", section "Tests" (on the left), subsection "Modernizer". + comment_tag: modernizer markdown-checks: name: Markdown style check runs-on: ubuntu-latest From 2d2408831eb7bf6d63fa937c5478fd4e8e3f7515 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sat, 21 Oct 2023 11:56:31 +0200 Subject: [PATCH 2/2] Add text on Code style checkers --- .vscode/ltex.dictionary.en-US.txt | 4 +++- docs/code-howtos/code-quality.md | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.vscode/ltex.dictionary.en-US.txt b/.vscode/ltex.dictionary.en-US.txt index e674b7db451..1345f479d73 100644 --- a/.vscode/ltex.dictionary.en-US.txt +++ b/.vscode/ltex.dictionary.en-US.txt @@ -1,3 +1,5 @@ +Checkstyle +CouchDB JabDrive JabRef -CouchDB +OpenRewrite diff --git a/docs/code-howtos/code-quality.md b/docs/code-howtos/code-quality.md index 755b0e1d500..b78df2a5775 100644 --- a/docs/code-howtos/code-quality.md +++ b/docs/code-howtos/code-quality.md @@ -3,12 +3,26 @@ parent: Code Howtos --- # Code Quality +## Code style checkers + +JabRef has three code style checkers in place: + +* [Checkstyle](https://checkstyle.sourceforge.io/) for basic checks, such as wrong import order. +* [Gradle Modernizer Plugin](https://github.com/andygoossens/gradle-modernizer-plugin#gradle-modernizer-plugin) for Java library usage checks. It ensures that "modern" Java concepts are used (e.g., [one should use `Deque` instead of `Stack`](https://stackoverflow.com/a/73021741/873282)). +* [OpenRewrite](https://docs.openrewrite.org/) for advanced rules. OpenRewrite can also automatically fix issues. JabRef's CI toolchain does NOT automatically rewrite the source code, but checks whether OpenRewrite would rewrite something. As developer, one can execute `./gradlew rewriteRun` to fix the issues. + +In case a check fails, [the CI](https://github.com/JabRef/jabref/blob/main/.github/workflows/tests.yml#L24C6-L24C6) automatically adds a comment on the pull request. + +## Monitoring + We monitor the general source code quality at three places: * [codacy](https://www.codacy.com) is a hosted service to monitor code quality. It thereby combines the results of available open source code quality checkers such as [Checkstyle](https://checkstyle.sourceforge.io) or [PMD](https://pmd.github.io). The code quality analysis for JabRef is available at [https://app.codacy.com/gh/JabRef/jabref/dashboard](https://app.codacy.com/gh/JabRef/jabref/dashboard), especially the [list of open issues](https://app.codacy.com/gh/JabRef/jabref/issues/index). In case a rule feels wrong, it is most likely a PMD rule. The JabRef team can change the configuration at [https://app.codacy.com/p/306789/patterns/list?engine=9ed24812-b6ee-4a58-9004-0ed183c45b8f](https://app.codacy.com/p/306789/patterns/list?engine=9ed24812-b6ee-4a58-9004-0ed183c45b8f). * [codecov](https://codecov.io) is a solution to check code coverage of test cases. The code coverage metrics for JabRef are available at [https://codecov.io/github/JabRef/jabref](https://codecov.io/github/JabRef/jabref). * [Teamscale](https://www.cqse.eu/en/teamscale/overview/) is a popular German product analyzing code quality. The analysis results are available at . +## Background literature + We strongly recommend reading following two books on code quality: * [Java by Comparison](http://java.by-comparison.com) is a book by three JabRef developers which focuses on code improvements close to single statements. It is fast to read and one gains much information from each recommendation discussed in the book.