Skip to content

[POC] Modernize codebase - Automatically fix Checkstyle violations #2300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

Pankraz76
Copy link
Contributor

@Pankraz76 Pankraz76 commented May 7, 2025

Pankraz76 pushed a commit to Pankraz76/maven that referenced this pull request May 7, 2025
@Pankraz76 Pankraz76 force-pushed the functional-DefaultModelProcessor_checkstyle branch from 19cf86c to 192b9a2 Compare May 7, 2025 10:45
@Pankraz76 Pankraz76 changed the title Automatically fix Checkstyle violations Pull apache#2300: Modernize codebase - Automatically fix Checkstyle violations May 7, 2025
@gnodet
Copy link
Contributor

gnodet commented May 7, 2025

Ah, now, you enable the tooling. That's becoming interesting...

@Pankraz76 Pankraz76 changed the title Pull apache#2300: Modernize codebase - Automatically fix Checkstyle violations Modernize codebase - Automatically fix Checkstyle violations May 9, 2025
@olamy
Copy link
Member

olamy commented May 11, 2025

Not sure I understand here. As we are using spotless already for the code, what is this PR providing?

@gnodet
Copy link
Contributor

gnodet commented May 11, 2025

Not sure I understand here. As we are using spotless already for the code, what is this PR providing?

We still use checkstyle for things other than code formatting.

@gnodet
Copy link
Contributor

gnodet commented May 11, 2025

Not sure I understand here. As we are using spotless already for the code, what is this PR providing?

We still use checkstyle for things other than code formatting.

But I'm quite bored with rules that fail. I'd much rather have tooling that fixes things automatically (or at least is able to do so, same as spotless).

@gnodet
Copy link
Contributor

gnodet commented May 11, 2025

Not sure I understand here. As we are using spotless already for the code, what is this PR providing?

We still use checkstyle for things other than code formatting.

But I'm quite bored with rules that fail. I'd much rather have tooling that fixes things automatically (or at least is able to do so, same as spotless).

So the workflow would rather be: run openrewrite rules and make sure there's no changes.

@olamy
Copy link
Member

olamy commented May 11, 2025

Not sure I understand here. As we are using spotless already for the code, what is this PR providing?

We still use checkstyle for things other than code formatting.

But I'm quite bored with rules that fail. I'd much rather have tooling that fixes things automatically (or at least is able to do so, same as spotless).

So the workflow would rather be: run openrewrite rules and make sure there's no changes.

Right. So it might be better to have this in the maven-parent?

@gnodet
Copy link
Contributor

gnodet commented May 11, 2025

Not sure I understand here. As we are using spotless already for the code, what is this PR providing?

We still use checkstyle for things other than code formatting.

But I'm quite bored with rules that fail. I'd much rather have tooling that fixes things automatically (or at least is able to do so, same as spotless).

So the workflow would rather be: run openrewrite rules and make sure there's no changes.

Right. So it might be better to have this in the maven-parent?

@Pankraz76 do you want to focus on that, rather than not-enforced checkstyle rules and results of openrewrite recipes ?

@Pankraz76
Copy link
Contributor Author

Not sure I understand here. As we are using spotless already for the code, what is this PR providing?

We still use checkstyle for things other than code formatting.

But I'm quite bored with rules that fail. I'd much rather have tooling that fixes things automatically (or at least is able to do so, same as spotless).

So the workflow would rather be: run openrewrite rules and make sure there's no changes.

Right. So it might be better to have this in the maven-parent?

@Pankraz76 do you want to focus on that, rather than not-enforced checkstyle rules and results of openrewrite recipes ?

yes good idea. Thanks

@Pankraz76
Copy link
Contributor Author

Pankraz76 commented May 11, 2025

already for the code

yes its very nice, but still not fully automated, kind of demanding .editorconfig, to fix issues before they occur, thus promote the nice tool spotless, to an second layer:

Editorconfig has autofix as well but not for custom IDE specs like this tool really plays out its cards.

Just giving you my noob exp upfront. Its fixing itself, like magic, but not for imports, failing the build.

ij_java_names_count_to_use_import_on_demand = 999

this issue unsolved to me. 1 LOC will fix for all: ij_java_names_count_to_use_import_on_demand = 999

image

@gnodet
Copy link
Contributor

gnodet commented May 11, 2025

already for the code

yes its very nice, but still not fully automated, kind of demanding .editorconfig, to fix issues before they occur, thus promote the nice tool spotless, to an second layer:

Editorconfig has autofix as well but not for custom IDE specs like this tool really plays out its cards.

Just giving you my noob exp upfront. Its fixing itself, like magic, but not for imports, failing the build.

ij_java_names_count_to_use_import_on_demand = 999

Integration in IDE is nice to have, but more importantly refactoring at build time using a maven plugin in a profile.

@Pankraz76 Pankraz76 changed the title Modernize codebase - Automatically fix Checkstyle violations [POC] Modernize codebase - Automatically fix Checkstyle violations May 11, 2025
@Pankraz76
Copy link
Contributor Author

run

image

Would be nice to have it in place running like rewrite, via github actions:

openrewrite/rewrite-static-analysis#497 (comment)

Its nifty that we have outdated stuff gone in

, but its not banned and fixed on the long run; still causing friction, needed to be automated.

As local run is optional, but the way to do. We would add all wanted styles and make like spotless. Then after clean install code would be fixed, but not forces to be pushed again.

Checkstyle will ensure spotless violations, but not rewrite recipes (e.g. unused methods). Would need to add rewrite checks and auto apply them, or kind of prevent merge, until resolved to solve this. feels wierd.

Whats your advice, how to fix this on the long run? @timtebeek

image

@gnodet
Copy link
Contributor

gnodet commented May 11, 2025

run

image

Would be nice to have it in place running like rewrite, via github actions:

openrewrite/rewrite-static-analysis#497 (comment)

Its nifty that we have outdated stuff gone in

, but its not banned and fixed on the long run; still causing friction, needed to be automated.

As local run is optional, but the way to do. We would add all wanted styles and make like spotless. Then after clean install code would be fixed, but not forces to be pushed again.

Checkstyle will ensure spotless violations, but not rewrite recipes (e.g. unused methods). Would need to add rewrite checks and auto apply them, or kind of prevent merge, until resolved to solve this. feels wierd.

Whats your advice, how to fix this on the long run? @timtebeek

image

I don't think changing the code in an action would be a good idea. I'd really favor the same behavior we use with spotless, i.e. a profile (activated by default) which fails the build if a rule cannot be validated (in the case of open rewrite, if a rule would actually apply and change the code) and a profile which would actually apply the rules.

@Pankraz76
Copy link
Contributor Author

Pankraz76 commented May 11, 2025

Not sure I understand here. As we are using spotless already for the code, what is this PR providing?

might be not configured nor supported; this seems to be a gap in project setup, as despite nice tooling, still having misaligned code:

assuming our project dont require spiked line endings like PMD and Check to pass build.

#2321 (comment)

@gnodet
Copy link
Contributor

gnodet commented May 12, 2025

The OpenRewrite maven plugin seems a much better way to fix the problems imho:
https://docs.openrewrite.org/reference/rewrite-maven-plugin

The rewrite:dryRun goal with <failOnDryRunResults>true</failOnDryRunResults> directly addresses the need by checking for potential changes and failing the build if any are found, giving confidence that the codebase is in the desired state.

@Pankraz76 could you please close all the PRs about refactoring that use openrewrite and focus on adding the plugin in the build instead ?

@Pankraz76
Copy link
Contributor Author

actually done:

failOnDryRunResults is what we need. Thanks

Comment on lines +819 to +826
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<configLocation>http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-checkstyle-plugin/src/main/resources/config/maven_checks.xml</configLocation>
</configuration>
</plugin>
Copy link
Member

Choose a reason for hiding this comment

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

we already have a checkstyle configuration in parent pom ..... and rules have a different source

@Pankraz76
Copy link
Contributor Author

successor: #2322

@Pankraz76 Pankraz76 closed this May 12, 2025
@timtebeek
Copy link
Contributor

At OpenRewrite, and others like Langchain4j, we run recipes that suggest fix comments on PRs as documented here:https://www.moderne.ai/blog/stop-breaking-ci-annotate-prs-with-openrewrite-recipe-fixes-as-quality-gate
Happy to help set that up in a couple weeks when in back from my travels. I think those code suggestions on PRs are more helpful than breaking the build.

@Pankraz76
Copy link
Contributor Author

suggestions

we need strict leadership on our suggestions enforcing them like good cop, bad cop.

@Pankraz76
Copy link
Contributor Author

travels

enjoy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants