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

Automate Code Formatting #56

Closed
sashirestela opened this issue Feb 22, 2024 · 1 comment · Fixed by #57
Closed

Automate Code Formatting #56

sashirestela opened this issue Feb 22, 2024 · 1 comment · Fixed by #57
Assignees
Labels
enhancement New feature or request

Comments

@sashirestela
Copy link
Owner

sashirestela commented Feb 22, 2024

Automation Mechanism

We have some options to automate code formatting:

1. On Git hook pre-commit
Maven plugin for installing hooks:
https://github.com/rudikershaw/git-build-hook
This requires running a manual command to turn a bash file into an executable one.
Maven plugin for code formatting: See option 2

Options for the pre-commit hook (some complications could appear for handling staged and non-staged files):

2. On Maven build
Maven plugins for code formatting:

3. On Github pull request
Github action for code formatting:
https://github.com/marketplace/actions/google-java-format

Java Style

Regarding Java style, we have three candidates which come from the same Google family:

We could consider a fourth option:

@sashirestela sashirestela added the enhancement New feature or request label Feb 22, 2024
@sashirestela
Copy link
Owner Author

sashirestela commented Feb 23, 2024

For Automation Mechanism we are selecting On Maven Build because it is less intrusive than the others, and we are selecting the Spotless Maven plugin because it is a more mature tool than the other, and it provides support for the four Java style options.

For Java Style we are selecting Eclipse because it allows flexible customization and it is the only style used by major IDEs (IntelliJ, VSCode, Eclipse) to exchange formatting. So, Spotless will be configured to use Eclipse as a Java formatter.

Spotless comes with two Maven commands that you can run at any moment, preferably before committing your changes:

  • mvn spotless:check to verify if code is formatted correctly.
  • mvn spotless:apply to rewrite the source code in place.

In the build Github Action a new step will be added to check the code formatting, so the build will fail if the code isn't formatted correctly.

@sashirestela sashirestela linked a pull request Mar 1, 2024 that will close this issue
@sashirestela sashirestela self-assigned this Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant