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

Enforce code formatting of changed files #230

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

obecker
Copy link
Contributor

@obecker obecker commented Sep 9, 2021

This commit introduces the maven spotless plugin to the project
that can format the source code using "mvn spotless:apply" based
on the configuration in the parent pom.xml.
Also it will perform a spotless:check during the verify phase
to ensure that all files are properly formatted.

This commit introduces the maven spotless plugin to the project
that can format the source code using "mvn spotless:apply" based
on the configuration in the parent pom.xml.
Also it will perform a spotless:check during the verify phase
to ensure that all files are properly formatted.
@obecker
Copy link
Contributor Author

obecker commented Sep 9, 2021

Hi @lincolnthree, this is a suggestion on how to enforce a proper and consistent formatting of the files in the project, no matter what kind of IDE a contributor is using. I have included the eclipse code formatter rules from https://github.com/ocpsoft/common/blob/master/ocpsoft-eclipse-code-format.xml

See https://github.com/diffplug/spotless/tree/main/plugin-maven on how to use the plugin.

The plugin is currently configured to enforce a proper formatting only for changed files.
If you remove line 149 from the pom file (<ratchetFrom>origin/master</ratchetFrom>) then the plugin will format all files in the project. You may try this and check whether the resulting formatting is what you expect. I encountered some unexpected changes, maybe the code formatter file is not complete.

Concerning the ratchet feature: I think it is reasonable to do a full re-format of the code in a single commit. After that any new changes/contributions will only show the important code changes (and not any unrelated formatting).

I have also included a license header file that will be prepended to any java file ($YEAR will be replaced by the year spotless finds in the current header, or with the current year). I'm not sure if it makes sense to automatically add your copyright and e-mail since many file have been contributed by other authors. I leave that decision (and if you want an automatic license header at all) to you.

Cheers!

@lincolnthree
Copy link
Member

Hey @obecker thanks so much! Sorry for the delay. I was on vacation (got married.)

I'll take a closer look at this when I can get a moment to breathe!!! This is awesome. Thank you.

~Lincoln

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.

2 participants