Feat: Use JBang-fmt to format sources#1945
Conversation
This can be easily incorporated into git commit hooks as well. See https://github.com/jbangdev/jbang-fmt This is "bare minimum" setup, to format only main and test Java sources of server (excluding jOOQ generated ones). Once we format, initial formatting will need a "source format" commit without any other code change, and add that commit hash to `.git-blame-ignore-revs` file in repo root to fix blame.
|
I did update the used format to a custom eclipse format with some modifications that I would prefer. I am not happy with the array initializers. The closing bracket is not on a new line when wrapping, but that does not seem to be supported by the eclipse format. Either always have the closing bracket or not, there is no option to conditionally add it to a new line depending on whether it was wrapped. There are a few occurrences in the code I do not really like but it looks like 99% of the other cases are fine. wdyt @cstamas @gnugomez @autumnfound ? you can just run |
|
this format is as close as possible to the existing formatting that is currently used afaict. |
|
I like it! And make it applied as soon as possible! |
|
I also added an sort import step using spotless which is run via jbang as the eclipse formatter does not support that unfortunately. as there is no cli, claude came up with a small java file to run the ImportOrder step on all the source files that can be executed with jbang. pretty neat imho. I pefer the following order: |
|
btw. created eclipse-jdt/eclipse.jdt.core#5195 for the issue in the eclipse formatter that it can not place the closing brace of an array initializer on a new line if its wraps. |
…same output: scripts/format.sh for fast git hook and spotless for IDE integration
|
I pushed some more change to add also the spotless plugin to support 2 ways to format the source in an identical way:
For my setup that works fine, I use the Spotless Applier plugin for Intellij but there is one for VSCode as well afaict. The workaround for the closing braces fix will hopefully go away soon. |
Signed-off-by: Thomas Neidhart <thomas.neidhart@eclipse-foundation.org>
|
For me this looks really good now, the majority of the changes is for the closing braces fix, which will hopefully go away. If this also looks good for others we can integrate, then apply to the whole codebase in a separate PR and add the format to the pre-commit hook. |
|
Looks good! |
|
There's some funkiness around nested chaining that imo really doesn't look good. I'm thinking that this is due to the closing brace code that was added being a little too eager. Example from AdminAPITest Do we want to be running braceless 1 line ifs? I'm personally not a huge fan of it in general, though I think the old way is better than the new in this case. new old Also not a huge fan of mixing 4 and 8 space indenting, but that seems to be an intentional choice here. |
|
the closing brace fix is for array initializers only, I noticed this verbose formatting in some cases as well. This is the 1% I am not happy with, I can still play around with it to have it more compact though. I would prefer braces to always be present in control structures, but the existing code omits them in many places so I kept it like that for now. We might wanna change that in a second run though. |
|
the mixing of 4 and 8 spaces is due to continuation rules. The default seems to be 2x of the normal indentation. Thats also what the code uses now most of the time. As always you find cases where 4 looks better, in other 8, so I am split here. At some point I tried a continuation of 4, but that also looked ugly in some occasions imho. |
|
Might be a good idea to standardize / document these coding rules across the whole codebase? |
+1 to using explicit braces even when optional. Is there a point to doing a second sweeping set of changes if we're going to be doing something that already touches a large portion of the codebase as it is though?
Fair enough! It might just be because we're enforcing it so consistently and in the past we had cases where the continuation was 4 spaces that it's noticable. |
|
Yes, braces should be there always, is superb for readability. |
|
the braces stuff will require a step like for the import order as the eclipse formatter does not handle that, but claude is busy coming up with something. @brianking yeah the idea is to document that. So far code did not follow any styleguide so we are changing that. For the frontend we already use prettier. |
|
This can be easily incorporated into git commit hooks as well.
See https://github.com/jbangdev/jbang-fmt
This is "bare minimum" setup, to format only main and test Java sources of server (excluding jOOQ generated ones).
Once we format, initial formatting will need a "source format" commit without any other code change, and add that commit hash to
.git-blame-ignore-revsfile in repo root to fix blame.Git integration doco:
https://github.com/jbangdev/jbang-fmt#git-integration