Inconsistency of linting between Checkstyle and Spotless #2

Closed
opened 2026-03-15 13:36:13 +01:00 by lars.winzer · 8 comments
lars.winzer commented 2026-03-15 13:36:13 +01:00 (Migrated from git.scicore.unibas.ch)

For Spotless this code is formatted correctly.

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

Source

However, in the latest pipeline run related to this commit, Checkstyle flagged it as Extra separation in import group before 'org.junit.jupiter.api.Test' and complained about the order.

Spotless is meant to automatically format the code, to comply with Checkstyle.

This is not the case here.

For Spotless this code is formatted correctly. ```java import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; ``` [Source](https://git.scicore.unibas.ch/cs108-fs26/Gruppe-13/-/blob/ca11c135f1691844072e2e738028d655b3736ce7/src/test/java/ch/unibas/dmi/dbis/cs108/casono/server/tokenizer/StateTest.java#L5) However, in the [latest pipeline run](https://git.scicore.unibas.ch/cs108-fs26/Gruppe-13/-/jobs/57423) related to this commit, Checkstyle flagged it as `Extra separation in import group before 'org.junit.jupiter.api.Test'` and complained about the order. Spotless is meant to automatically format the code, to comply with Checkstyle. This is not the case here.
lars.winzer commented 2026-03-15 13:39:03 +01:00 (Migrated from git.scicore.unibas.ch)

mentioned in commit 08dc94b4b0

mentioned in commit 08dc94b4b09fc5552f5b9b6f47720aaa7dc636bf
lars.winzer commented 2026-03-15 13:40:56 +01:00 (Migrated from git.scicore.unibas.ch)

Furthermore the code (linted by Checkstyle before with no issues)

package ch.unibas.dmi.dbis.cs108.casono.client.ui.lobbyui;

import javafx.scene.layout.GridPane;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;

is re-formatted by Spotless to

package ch.unibas.dmi.dbis.cs108.casono.client.ui.lobbyui;

import static org.junit.jupiter.api.Assertions.*;

import javafx.scene.layout.GridPane;
import org.junit.jupiter.api.*;

As an aftermath, Checkstyle now complains

Furthermore the code (linted by Checkstyle before with no issues) ```java package ch.unibas.dmi.dbis.cs108.casono.client.ui.lobbyui; import javafx.scene.layout.GridPane; import org.junit.jupiter.api.*; import static org.junit.jupiter.api.Assertions.*; ``` is re-formatted by Spotless to ```java package ch.unibas.dmi.dbis.cs108.casono.client.ui.lobbyui; import static org.junit.jupiter.api.Assertions.*; import javafx.scene.layout.GridPane; import org.junit.jupiter.api.*; ``` As an aftermath, Checkstyle now complains
lars.winzer commented 2026-03-18 11:11:43 +01:00 (Migrated from git.scicore.unibas.ch)

assigned to @lars.winzer

assigned to @lars.winzer
lars.winzer commented 2026-03-18 11:12:26 +01:00 (Migrated from git.scicore.unibas.ch)
created branch [`issue/2-inconsistency-of-linting-between-checkstyle-and-spotless`](/cs108-fs26/Gruppe-13/-/compare/main...issue%2F2-inconsistency-of-linting-between-checkstyle-and-spotless) to address this issue
lars.winzer commented 2026-03-18 17:18:57 +01:00 (Migrated from git.scicore.unibas.ch)

Spotless follows the Google Java Style Guide while Checkstyle uses custom defined rules.

The order in which imports have to be sorted is outlined here:

3.3.3 Ordering and spacing

Imports are ordered as follows:

  1. All static imports in a single group.
  2. All non-static imports in a single group.

If there are both static and non-static imports, a single blank line separates the two groups. There are no other blank lines between imports.

Within each group the imported names appear in ASCII sort order. (Note: this is not the same as the import lines being in ASCII sort order, since '.' sorts before ';'.)

A possible solution is to change the formatting of Checkstyle to match the rules outlined by the Google Java Style Guide.

Spotless follows the [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html) while Checkstyle uses custom defined rules. The order in which imports have to be sorted is outlined [here](https://google.github.io/styleguide/javaguide.html#s3.3.3-import-ordering-and-spacing): > #### 3.3.3 Ordering and spacing > > Imports are ordered as follows: > > 1. All static imports in a single group. > 2. All non-static imports in a single group. > > If there are both static and non-static imports, a single blank line separates the two groups. There are no other blank lines between imports. > > Within each group the imported names appear in ASCII sort order. (**Note:** this is not the same as the import _lines_ being in ASCII sort order, since '.' sorts before ';'.) A possible solution is to change the formatting of Checkstyle to match the rules outlined by the Google Java Style Guide.
lars.winzer commented 2026-03-18 18:12:52 +01:00 (Migrated from git.scicore.unibas.ch)

After doing some research, I came across the following issue.

The rules defined for Checkstyle, particularly regarding indentation, differ from how Spotless calculates indentation.

One possible solution is to use an additional Checkstyle configuration file, maintained by the official Checkstyle GitHub repository, which follows the Google Java Style Guide.

The alternative would be to include Spotless as an additional job in the CI pipeline. However, this comes with the drawback that Spotless does not generate a machine-readable output, making it difficult to embed the results as a code quality report in merge requests.

There are online reports of someone managing to parse the output using a Python script, but this is not a stable solution, as the output format could change at any time. Furthermore, only the locations are specified and how they should look, not exactly which rule was violated.


Given the issues, I have decided not to make any changes to the current pipeline.

After doing some research, I came across the following issue. The rules defined for Checkstyle, particularly regarding indentation, differ from how Spotless calculates indentation. One possible solution is to use an [additional Checkstyle configuration file](https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml), maintained by the official Checkstyle GitHub repository, which follows the Google Java Style Guide. The alternative would be to include Spotless as an additional job in the CI pipeline. However, this comes with the drawback that Spotless does not generate a machine-readable output, making it difficult to embed the results as a code quality report in merge requests. There are online reports of someone managing to parse the output using a Python script, but this is not a stable solution, as the output format could change at any time. Furthermore, only the locations are specified and how they should look, not exactly which rule was violated. --- Given the issues, I have decided not to make any changes to the current pipeline.
lars.winzer commented 2026-03-18 18:22:23 +01:00 (Migrated from git.scicore.unibas.ch)

mentioned in merge request !38

mentioned in merge request !38
lars.winzer commented 2026-03-18 18:23:46 +01:00 (Migrated from git.scicore.unibas.ch)

mentioned in commit 3581406833

mentioned in commit 358140683356a058966013d714fe26c93cc659de
lars.winzer (Migrated from git.scicore.unibas.ch) closed this issue 2026-03-18 18:23:47 +01:00
This repo is archived. You cannot comment on issues.
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: University-of-Basel-Studentprojects/Programmierprojekt#2