Skip to content
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

CI: Add Auto-Format GitHub Actions to automatically format Java Files #2429

Open
SaptarshiSarkar12 opened this issue Nov 25, 2023 · 7 comments

Comments

@SaptarshiSarkar12
Copy link

SaptarshiSarkar12 commented Nov 25, 2023

Is your feature request related to a problem? Please describe.

This project has a code style defined in the athenz-checkstyle.xml file. Checking whether the code in the Pull Requests or branches follows the project's code style and applying fixes accordingly is a tedious work.

Describe the solution you'd like

I want to use OpenRewrite's Maven Plugin to automatically format the Java files using the Checkstyle configuration. I would also like to create a GitHub Actions to automatically run the formatter and push the changes to the branches or the PRs.

Additional context

I have implemented this feature in an Open-Source project - Drifty and the GitHub Action also pushes the formatted files to the branches or PRs as you can see below 👇
Screenshot from 2023-11-25 08-22-24
If this issue seems good to the maintainers and can add some value to the project, then, I would like to work on this issue.

@SaptarshiSarkar12
Copy link
Author

@havetisyan Does this issue seem good to you? If yes, then, I am willing to work on this.

@havetisyan
Copy link
Collaborator

@SaptarshiSarkar12 I'm not sure what value this provides? Why would we allow files to be checked in in the first place that do not conform to our check style guidelines? This might be useful for some project that didn't have check style configured from day one and now they want to impose it, but I'm not sure what value it provides for our project.

@SaptarshiSarkar12
Copy link
Author

@havetisyan The OpenRewrite Maven plugin modifies the java files in such a way that they do not violate the checkstyle configuration. So, the automated code style of the project removes the burden of checking whether the modified files in Pull Requests, conform with the checkstyle configuration.
Does that make sense?

@sriramnrn
Copy link

sriramnrn commented Nov 28, 2023 via email

@SaptarshiSarkar12
Copy link
Author

@sriramnrn We can set up git hooks to trigger the mvn rewrite:run command just before commit, so that the Java code gets aligned with the code style of the project. Can we do this?

@havetisyan
Copy link
Collaborator

Right now in our setup check style plugin runs before we even compile the code. So you cannot compile any code if it does not conform to the requirements. You need to fix your code before you can compile and run test, etc. There is no need for git hooks or additional plugins.

@SaptarshiSarkar12
Copy link
Author

@havetisyan Okay, I see. But, can the OpenRewrite plugin run before checkstyle plugin to format the files so that most (if not all) of the checkstyle violations get resolved?

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

No branches or pull requests

3 participants