Repository navigation
Automatically organize imports with spotless - #606
Conversation
Order imports automatically in this order: external dependecies, internal org.togetherjava classes, java and static imports. Since that's the ordering we have been using so far.
|
Kudos, SonarCloud Quality Gate passed!
|
they are easy to fix so no problem to me |
Zabuzard
left a comment
There was a problem hiding this comment.
Two things to ease migration here:
- can you adjust the
meta/formatting/google-style-eclipse.xmlfile? - can you export an IntelliJ formatter settings file and/or tell us which checkboxes to check so that it conforms?
I want my IDE to conform with the setup as much as possible, to reduce the amount of stuff that Spotless changes.
We also promote such a setup, with a small guide, in our Wiki for beginners.
|
There shouldn't be much or any migration with this. It's not like we are changing code formatting, it's just imports, so workflow shouldn't be affected. You write code → IDE adds imports for you, you don't even see them because they are collapsed → you commit and push and everything is organized for the repo. So ideally, this should be completely invisible to the user. The whole idea with our fully automatic workflow was to make it beginner-friendly. So nobody has to worry about formatting and complex configuration importing in all your tooling, only to realize half of the IDEs don't even support it. Now, I understand wanting to conform to formatting of the code, since you don't want to flip-flop completely different formatting after each commit. But who cares about imports? Since currently it's wild west anyway, everyone does imports however they want or however their tooling does it. But yeah, sure, if people want to be able to import a config, and we can support it, why not! Now to answer your questions,
No, eclipse has a separate file format for ordering imports. It's a text file, and IntelliJ doesn't understand it, doubt other IDEs either.
Yeah, this should give the exact same result as our spotless import order. Since I copied our current ordering and IntelliJ default as much as possible, the difference is mostly in spacing: (Unable to resize the window, but the rest is same) It would look like this in IntelliJ XML config: <option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="false" />
<emptyLine />
<package name="org.togetherjava" withSubpackages="true" static="false" />
<emptyLine />
<package name="javax" withSubpackages="true" static="false" />
<emptyLine />
<package name="java" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="true" />
</value>
</option>Note that IntelliJ organize imports does more than just ordering, it does things like these too: Who knows what other tooling does by default, I think it's not worth it trying to align all tooling over imports. It's fine if someone uses Ordering is not that important anyway, we can drop that commit as far as I'm concerned. Just some consistency is nice, if it comes at no cost.
These two are actually important since they waste so much dev hours monthly, sonar flags them and fails the build, while they generate no changes at all. |
Zabuzard
left a comment
There was a problem hiding this comment.
feel free to hit the button @marko-radosavljevic










This PR introduces automatic import organizing with spotless, since it's a common pain point in the workflow.
You push → sonarcloud doesn't like the unused import → you have to fix the issue and push again.
So with this PR, we have automatic fixes for:
Automatically ordering imports is not necessary, but it's a nice thing to have, since everything would be always consistent.
Import are ordered like this: external dependencies, internal org.togetherjava classes, java classes and static imports. Since that's the ordering we have been using so far. There are still small changes in a lot of files, mostly new lines between categories.
Feel free to suggest new ordering, but keep in mind it would introduce heavy merge conflicts since every PR branch has import changes. ^^
Diff of the
build.gradlesince there are a lot of changes by spotless: