prettier-java
prettier-java copied to clipboard
Configurable import statement ordering
Currently import statements are force set to the Google Java style guide. Unfortunately this is a deal breaker for our engineers.
Recent versions of IntelliJ support defining their import layout via an .editorconfig
file. For example, to make IntelliJ use the default import format for Eclipse:
[*.{groovy,java,gradle}]
ij_java_imports_layout = $*,|,java.**,|,javax.**,|,org.**,|,net.**,|,com.**,|,*
Where $
indicates static, |
indicates a line break, and *
as wildcard.
It would be awesome if prettier-java could be configured in a similar fashion.
Or at the very least, if there are too many opinions around this, we should be able to disable formatting of imports entirely.
Hi @jamesdh ! Thank you for opening this ticket.
One of the biggest philosophy of Prettier is to be opinionated, and to avoid having too much configuration as it would be counterproductive (https://prettier.io/docs/en/option-philosophy.html)
By far the biggest reason for adopting Prettier is to stop all the ongoing debates over styles.
So I am not sure that we want to add this kind of customization here. Disabling formatting of imports could be considered, however…
@jhipster/developers WDYT ?
Why would anyone care about import ordering at all, let alone to the point of saying that it's a dealbreaker? I would expect most IDEs to just collapse all of them by default anyway:
Agree with Clement.
On Wed, 10 Nov 2021, 6:29 pm Jonathan Haber, @.***> wrote:
Why would anyone care about import ordering at all, let alone to the point of saying that it's a dealbreaker? I would expect most IDEs to just collapses all of them anyway: [image: image] https://user-images.githubusercontent.com/611459/141162864-d98ec2e3-253e-4a17-a7c6-ea1196382c78.png
— You are receiving this because you are on a team that was mentioned. Reply to this email directly, view it on GitHub https://github.com/jhipster/prettier-java/issues/513#issuecomment-965572607, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIOKF2CW5G2SCHN22K5TNTULKTXNANCNFSM5GQ3S52A .
Agree with @clementdessoude too
But I don't think disable the order of import would help, because if you activate this option, you'll have different import order, in your team, as every developer will have specific IDE. So it would be bad!
During development, you should not care about import as the order will be done by prettier, that's why it's so nice!
@jhaber it's simply to avoid a gargantuan set of changes to our code base. Also, not all engineers share the same opinion as yours and not all engineers have their imports collapsed by default. I'm trying to find a way to introduce reasonable formatting standards to our codebase without causing too much friction for our engineers.
Thank you @clementdessoude for the input and I can understand the philosophy. We just ended up going with Spotless since it affords this kind of configuration, as well as ratcheting, etc, to avoid sudden and dramatic changes to the codebase.
Hey people, I concur when James say that it is a dealbreaker, it's not just about personal preferences, the main issue with how prettier-java deals with imports is that it does not allow to 1) prevent using wildcard imports and 2) is not able to expand wildcard imports.
And this is important because using wildcard imports is almost ALWAYS a bad practice: it's useful only for people when they were typing the imports manually, but now with IDEs it's done automatically.
Also, wildcard imports really sucks when you look at a diff in git: you have no idea what changed in terms of the dependencies of your Java file with respect to the rest of the codebase.
So for all those reasons, ideally, I would love that prettier-java expands the wildcard imports by default, but of course it's not easy, you need the class path to be available for that, and I don't think that's part of prettier-java concerns (at least not currently ;).
So the second best option is to allow disabling this check and using another tool for dealing with imports.
As James mentioned, spotless deals with this by simply running prettier-java and then running the eclipse formatter only for the imports. It works quite well but I don't know if everybody wants to use spotless…