-
Notifications
You must be signed in to change notification settings - Fork 458
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
ImportSorter eats comments #558
Comments
If a comment is to the right of an import, it's clear who it should get sorted with. But for your example, should it count as above its target or below? One possible option: importSorter(COMMENT_SORTWITH_ABOVE)
importSorter(COMMENT_SORTWITH_BELOW)
importSorter(COMMENT_REMOVE) // the current behavior
importSorter(COMMENT_ERROR) // a safer default IMO "no comments in the imports" is a reasonable styleguide. Our importsorter has several issues, but I wonder how Eclipse or IntelliJ handle this. Happy to take a PR to improve this behavior, but it's extremely low on my todo list. |
Yes, I can see how one would consider comments in between import statements bad style or practice, but in our case, we need them as markers during code generation. package org.example;
import java.util.List;
import java.util.Set;
// begin user-defined imports
import java.util.ArrayList;
import org.example.PersonUtilities;
// end user-defined imports
public class Test {
....
} Just treating the comments as a two-line import statement and using the regular import sorting won't help because it would move the
I can imaging us helping with a PR if we settle on a desired solution. |
This is very easy, just one piece missing. If we make this method public: spotless/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java Line 217 in 608af5c
then you could do this:
Should probably rename "configure" to "format".
COMMENT_NOOP is a good idea - easier to implement than COMMENT_SORTWITH_ABOVE/SORTWITH_BELOW.
I think it would be better to just copy-paste the existing sorter and modify to make a custom formatter step, rather than burden the import sorter with a public API to maintain for a very niche usecase. A PR for any viable solution is welcome. |
This issue is no longer relevant to us, so feel free to close it. |
The
ImportSorter
removes comments inside the imports block, i.e.:before:
after:
The text was updated successfully, but these errors were encountered: