After having given that more thought, I think it would make sense to simply reuse an existing formatter. It seems people are keen to align with a more traditional code style, so I see two possibilities: * palantir java format [1], a 120 column, 4 spaces indent formatter, well supported in Intellij IDEA * google code style [2], a 100 column, 2 spaces indent code style, with support for IntelliJ and Eclipse
I would have a stylistic preference on palantir, but I think the google one has better integration. I also agree with @elharo that this should be fully automated so that the formatter can be completely enforced. Anything else will make a developer's life more complicated with no benefits. Especially with the google one, as I think it always performs a *full* reformat. I don't have any problem with adding a profile to just check and not reformat though, but I don't see any benefit, so I'll do that only if people really want. Guillaume [1] https://github.com/palantir/palantir-java-format [2] https://google.github.io/styleguide/javaguide.html Le mer. 12 oct. 2022 à 18:23, Guillaume Nodet <gno...@apache.org> a écrit : > Related to the discussion about automatically formatting and sorting > imports, I think it would be nice, given the big reformat commits if those > PRs are to be merged, to eventually discuss some changes to those code > style. In particular, I found out that the code is very sparse and my > screen is more wide than height, which means I can usually only see 30-40 > lines of code, where sometime half of them do not really carry any semantic > (open braces, or things like close brace + else + open brace on 3 lines). > This makes me scroll a lot even on quite small methods to be able to read > the full code, and that's a pain imho. > So I'd like to propose the following changes that would make maven code > more readable imho (and also closer to the usual java coding style) : > * move open braces to the end of the previous line on all places > * allow the else keyword to be directly following a closing brace to > allow "} else {" to be on the same line > * eventually relax a bit the checkstyle line length as described in > https://github.com/gnodet/maven-shared-resources/pull/2. This has not > much effect, as the formatter will automatically format the lines and wrap > them at 120. However, in certain cases, the formatter can find in difficult > to wrap the line (for example with a variable declaration and cast with a > fully qualified name) and there is either a need to manually force the wrap > (using an end of line comment for example) or disabling the check with a > @SuppressWarning( "checkstyle:LineLength" ) annotation. This change only > removes the checks so that in those rare cases, the formatter can be left > without any need to force things. > > If this is to be accepted, I'd amend the PRs from the other thread to > follow those changes. > > Cheers, > Guillaume > > > > -- ------------------------ Guillaume Nodet