spoon icon indicating copy to clipboard operation
spoon copied to clipboard

Spotless for imports

Open MartinWitt opened this issue 10 months ago • 8 comments

Currently, our import ordering in spoon is a bit messy. This leads to an unpleasant time with IntelliJ trying to sort the imports in a more normal order. Why don't we use spotless-maven-plugin to sort all our imports in a fixed sorting? This also helps to reduce diffs in the future for PRs. The benefit compared to checkstyle is that we can do the sorting automatic. See https://github.com/diffplug/spotless/tree/main/plugin-maven#java for an example.

MartinWitt avatar Apr 06 '24 17:04 MartinWitt

We need to add

          <java>
            <importOrder />
          </java>

Any wishes for the order? <order>java|javax,org,com,com.diffplug,,\#com.diffplug,\#</order> <semanticSort>false</semanticSort> <wildcardsLast>false</wildcardsLast>

MartinWitt avatar Apr 20 '24 16:04 MartinWitt

I don't care as long as IJ can follow the same order and I don't need to run spotless :^)

I-Al-Istannen avatar Apr 20 '24 17:04 I-Al-Istannen

Can we please add a good-first-issue label here? We can then ask new contributors to work on this :)

algomaster99 avatar Sep 04 '24 20:09 algomaster99

done

monperrus avatar Sep 05 '24 15:09 monperrus

Hello, I would like to try to contribute on this issue.

I noticed that Spotless is applied to the files included in src/test/java/spoon/testing/assertions/**/*.java. I plan to accept all the Java files excepted the resources (example: **/resources/**). But, there will be a lot of changes due to the initial Plantir format usage on src/test/java/spoon/testing/assertions/**/*.java (around 1550 Java files impacted). May I remove this particular format?

I suggest also to add <removeUnusedImports />. There are 29 files impacted. By using only <importOrder />, there are 735 files impacted.

I guess it is better to do a PR only about the pom.xml change and another one about the spotless:apply.

micka-lama avatar Sep 30 '24 20:09 micka-lama

Hi @micka-lama ! We would want to be similar to IJ style guide. @I-Al-Istannen do you use the formatted in IJ with default configurations? We could then configure spotless accordingly.

algomaster99 avatar Sep 30 '24 21:09 algomaster99

Yea, just the defaults (except forbidding star imports). static imports are split and placed after the normal imports:

non-static
<blank>
static javax
static java
<blank>
static *

I-Al-Istannen avatar Oct 01 '24 09:10 I-Al-Istannen

@micka-lama we look forward to your PR that configures spotless following two rules:

  1. Sticking to IJ style guide.
  2. Configure the style guide for imports like @I-Al-Istannen said. You can also include configuration for IntelliJ workspace so that they don't contradict with spotless.

algomaster99 avatar Oct 01 '24 12:10 algomaster99