ocpsoft / prettytime

Social Style Date and Time Formatting for Java
http://ocpsoft.org/prettytime/
Apache License 2.0
1.29k stars 252 forks source link

Enforce code formatting of changed files #230

Open obecker opened 2 years ago

obecker commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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