Skip to content

Feat: Use JBang-fmt to format sources#1945

Merged
netomi merged 15 commits into
eclipse-openvsx:mainfrom
cstamas:jbang-fmt
Jul 20, 2026
Merged

Feat: Use JBang-fmt to format sources#1945
netomi merged 15 commits into
eclipse-openvsx:mainfrom
cstamas:jbang-fmt

Conversation

@cstamas

@cstamas cstamas commented Jul 6, 2026

Copy link
Copy Markdown
Member

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.

Git integration doco:
https://github.com/jbangdev/jbang-fmt#git-integration

cstamas and others added 3 commits July 6, 2026 11:50
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.
@netomi
netomi marked this pull request as ready for review July 15, 2026 12:17
@netomi

netomi commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

I did update the used format to a custom eclipse format with some modifications that I would prefer.
Please take a look, there is a script in server/scripts/format.sh to format the sources.

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 server/scripts/format.sh and do a git diff

@netomi

netomi commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

this format is as close as possible to the existing formatting that is currently used afaict.

@cstamas

cstamas commented Jul 15, 2026

Copy link
Copy Markdown
Member Author

I like it! And make it applied as soon as possible!

@netomi

netomi commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

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:

// Import order: java/javax first, then everything else, then org.eclipse.openvsx,
// then static imports, each group separated by a blank line.
"java|javax", "", "org.eclipse.openvsx", "\\#"

@netomi

netomi commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

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
@netomi

netomi commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

I pushed some more change to add also the spotless plugin to support 2 ways to format the source in an identical way:

  • using scripts/format.sh for quick formatting in a git hook without running a gradle build
  • using spotless gradle plugin for IDE integration to format the source file while editing it

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.

netomi added 2 commits July 16, 2026 10:53
Signed-off-by: Thomas Neidhart <thomas.neidhart@eclipse-foundation.org>
@netomi

netomi commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

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.

@cstamas

cstamas commented Jul 16, 2026

Copy link
Copy Markdown
Member Author

Looks good!

@autumnfound

Copy link
Copy Markdown
Contributor

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

        mockMvc.perform(
                post(
                        "/admin/namespace/{namespace}/change-member?user={user}&role={role}",
                        "foobar",
                        "other_user",
                        "remove"
                )
                        .with(user("admin_user").authorities(new SimpleGrantedAuthority(("ROLE_ADMIN"))))
                        .with(csrf().asHeader())
        )
                .andExpect(status().isOk())
                .andExpect(content().json(successJson("Removed other_user from namespace foobar.")));

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

        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;

old

        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

Also not a huge fan of mixing 4 and 8 space indenting, but that seems to be an intentional choice here.

@netomi

netomi commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

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.

@netomi

netomi commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

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.

@brianking

Copy link
Copy Markdown

Might be a good idea to standardize / document these coding rules across the whole codebase?

@autumnfound

Copy link
Copy Markdown
Contributor

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.

+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?

At some point I tried a continuation of 4, but that also looked ugly in some occasions imho.

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.

@cstamas

cstamas commented Jul 16, 2026

Copy link
Copy Markdown
Member Author

Yes, braces should be there always, is superb for readability.

@netomi

netomi commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

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.

@netomi

netomi commented Jul 16, 2026

Copy link
Copy Markdown
Contributor
  • braces are now added
  • chained method execution looks now more sane -> the downside is I had to remove that the closing bracket of a method invocation is on a new line if wrapped, but that is acceptable imho
  • added already a pre-commit hook to check that this works reliable, this PR has ofc many violations as the source is not yet fixed

@netomi
netomi merged commit 0a5cc35 into eclipse-openvsx:main Jul 20, 2026
4 of 5 checks passed
@cstamas
cstamas deleted the jbang-fmt branch July 20, 2026 12:23
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.

4 participants