Skip to content

Conversation

@optionsome
Copy link
Member

@optionsome optionsome commented Sep 25, 2025

Summary

Introduce checkstyle. This could be introduced alone or preferably with something that fixes most of the issues automatically (such as openrewrite).

I haven't fixed any of the errors yet. Almost all of them can be automatically fixed with OpenRewrite.

Issue

Related to last week's conference discussions and #6913.

Unit tests

No

Documentation

TODO

Changelog

Not sure if needed

@optionsome optionsome requested a review from a team as a code owner September 25, 2025 13:14
@optionsome optionsome added the !Technical Debt Improve code quality, no functional changes. label Sep 25, 2025
@@ -292,22 +287,54 @@
</configuration>
</plugin>

<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed spotless because I thought openrewrite could do it's job. We have checks for the imports but do we want to additionally fix the issues with spotless?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please keep the plugin and have it perhaps deactivated by default? I find it super-useful to remove all unused imports with mvn spotless:apply.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to still use spotless as well? I tried to limit the number of tools we use since checkstyle/openrewrite check/fix these issues as well. Although, spotless is faster than openrewrite.

final List<FlexServiceDate> dates = new ArrayList<>();

// TODO - This code id not DRY, the same logic is in RaptorRoutingRequestTransitDataCreator
for (int d = -additionalPastSearchDays; d <= additionalFutureSearchDays; ++d) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the problem being fixed here?

Copy link
Member

@leonardehrenfried leonardehrenfried left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now I feel that the code changes in this PR are a bit too invasive. I would start a bit more carefully with a smaller set of changes. I feel that right now that OpenRewrite and Checkstyle don't interact all that well with each other.

Checkstyle

Focusses more on style issues like braces and not initializing two variables on the same line. No automatic fixes.

OpenRewrite

Focusses on directly fixing all issues but the support for style problems is weaker.

Combining them

I feel that trying to combine right now is too much complexity at the same time. I would go with one tool and see how it feels. Personally, I would focus on OpenRewrite but it might not have the support for the style issues that @optionsome cares about.

@leonardehrenfried
Copy link
Member

leonardehrenfried commented Sep 26, 2025

Now that I said it, I took another look and there is support for the braces and the double initialization:

            <plugin>
                <groupId>org.openrewrite.maven</groupId>
                <artifactId>rewrite-maven-plugin</artifactId>
                <version>6.18.0</version>
                <configuration>
                    <activeRecipes>
                        <recipe>org.openrewrite.staticanalysis.MultipleVariableDeclarations</recipe>
                        <recipe>org.openrewrite.staticanalysis.NeedBraces</recipe>
                    </activeRecipes>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.openrewrite.recipe</groupId>
                        <artifactId>rewrite-static-analysis</artifactId>
                        <version>2.18.0</version>
                    </dependency>
                </dependencies>
            </plugin>

With this clarified I would skip checkstyle and put all the effort into openrewrite. We have to enable the recipes bit by bit and figure out when it should be run because it is slower than checkstyle.

@optionsome
Copy link
Member Author

I will test it out. We should have a discussion on if we only want rules that can be automatically fixed or not.

@optionsome
Copy link
Member Author

I think the only relevant part here anymore is the checkstyle config, which we might partly use.

@optionsome optionsome marked this pull request as draft September 29, 2025 07:20
@optionsome
Copy link
Member Author

I cleaned up this pr so it now just includes checkstyle configuration. Almost all of the checkstyle rules can be automatically fixed with openrewrite (which I haven't done here at least yet). One option is that we run checkstyle as normal part of the build (it's fast) and then you have to run openrewrite to fix the issues (there are some issues that openrewrite doesn't fix even though it should). You shouldn't really get these errors often unless you are new to the project and unfamiliar with our code style.

@optionsome
Copy link
Member Author

If we decide to use checkstyle, I will add a profile to skip it if similarly as we have for prettier (if it's possible).

@optionsome optionsome changed the title Add checkstyle and run automatic code clean up with openrewrite Add checkstyle plugin Oct 3, 2025
List<String> filterByBikeParks = null;
List<String> filterByCarParks = null;

// TODO implement
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// TODO implement

for (StreetNoteModel source : sources) {
Set<StreetNoteAndMatcher> maas2 = source.getNotes(edge);
if (maas2 != null) maas.addAll(maas2);
if (maas2 != null) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we still have street notes? I was under the impression that it was some feature that we already removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked issue history and seemingly @hbruch was using it some years ago still.

// Best duration 18m,
var transitAndTransit = startWalkAndL1 + endL2AndWalk + "[0:02 0:23 21m Tₓ1]";
// Min-Duration 19m
// Best duration 18m,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Best duration 18m,

// Min-Duration 19m - this is
var flexTransferTransit = startFlexAccess + endWalkAndL3 + "[0:02 0:22 20m Tₓ1 C₁2_580]";
// Best duration 16m,
// Min-Duration 19m - this is
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Min-Duration 19m - this is

@@ -292,22 +287,54 @@
</configuration>
</plugin>

<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to still use spotless as well? I tried to limit the number of tools we use since checkstyle/openrewrite check/fix these issues as well. Although, spotless is faster than openrewrite.

@t2gran
Copy link
Member

t2gran commented Oct 13, 2025

I would like us to add the configuration without any rules in the initial PR. Then add one rule at the time with the code fixed. If we want to make sure this works adding one rule in this PR is ok, for example AvoidStarImport. The AvoidStarImport only has 2 places witch needs to be fixed - so it is good for first rule to include.

@optionsome
Copy link
Member Author

#6988 Replaces this pr. I will keep this open as draft so we can copy over some rules/recipes in follow up prs from here.

@optionsome
Copy link
Member Author

optionsome commented Oct 21, 2025

I would like us to add the configuration without any rules in the initial PR. Then add one rule at the time with the code fixed. If we want to make sure this works adding one rule in this PR is ok, for example AvoidStarImport. The AvoidStarImport only has 2 places witch needs to be fixed - so it is good for first rule to include.

I feel there would be too much process if we add the rules one by one in prs. So I grouped the import related rules in #6988 and it's easy to review as the imports either work or don't work.

@leonardehrenfried
Copy link
Member

I think this can be closed

@optionsome
Copy link
Member Author

I think this can be closed

I was planning to close this after I've added in separate prs the stuff that is in this pr.

@t2gran t2gran added this to the 2.9 (next release) milestone Nov 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

!Technical Debt Improve code quality, no functional changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants