-
-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comment section moved between two import declarations #372
Comments
When the java code is parsed, the comment section is added as leading comment to the java.lang.Util import line. When the import are sorted by printer-utils.sortImports, this import with its leading comment line is set at the second place. In my use case, the comment contains the license section generated by the license-maven-plugin. That's why, setting this comment as child of the import element could be seen as an error. So here are my questions:
According to you, what solution would be the best solution? |
I'll have a look this week ! |
Thanks Clément. |
This issue is due on how we process the comments in prettier-java, the comments are always attached to the closest node. We tried multiple ways of attaching comments but we have not figured out the best one. @MSaguer For the time being, I think you can either remove the sort function or force your comment to be attached to the right expression (Since it attach to the closest node, you can add newline to create a gap, but I don't recommend this one since if you prettify twice, it won't be stable) |
Sorry, I was very busy last week because of work. I am also a bit sceptic with the sorting of imports, I noticed it caused some issues with Intellij. @jhipster/developers WDYT ? |
My $0.02 is that sorting imports feels within scope for prettier-java, and we really like having it |
is it really usefull ? |
I agree with jahber that sorting is required. Some devs may add it manually even if it is strange. I propose a quick solution that I could implement next week
|
I also think prettier-java should sort imports. |
I agree with @murdos on sorting imports. The example is a bit weird too, and may not happen very often (I may not fully understand the motivation behind putting a comment in such a place though). |
Prettier-Java 0.7.0
Launched through prettier-maven-plugin 0.7.0 without any option.
In the following case, the comment section is moved between two import lines.
This bugs depends on import declaration order. If "com.me.Util" is declared first, the generated file is OK.
Input:
Output:
Expected behavior:
The text was updated successfully, but these errors were encountered: