spotless icon indicating copy to clipboard operation
spotless copied to clipboard

Spotless maven plugin sometimes doesn't detect wrong java Eclipse formatting

Open pbite opened this issue 1 year ago • 1 comments

Hi,

We use maven spotless plugin for java formatting in Eclipse format. In some cases it seems spotless:check doesn't shows errors on wrong formatting and spotless:apply doesn't apply changes.

Spotless maven plugin version: 2.43.0. Maven version: 3.8.4 OS: Windows 10 Enterprise, 22H2 Spotless configuration:

<plugin>
  <groupId>com.diffplug.spotless</groupId>
  <artifactId>spotless-maven-plugin</artifactId>
  <version>${com.diffplug.spotless.plugin.version}</version>
  <configuration>
    <java>
      <eclipse></eclipse> <!-- we use formatting from the file, but same issue is with default Eclipse formatting -->
      <importOrder>
        <order>java,javax,org,com</order>
      </importOrder>
      <removeUnusedImports/>
    </java>
  </configuration>
</plugin>

Simplified java class when formatting is not applied (here are doubled empty lines that are not allowed):

package com.myproject;

import static org.mockito.Mockito.when;

class SpotlessTest {

	void test() {

		when(null);

		
		
	}
}

It seems that issue is somehow related to when, because on code below formatting is applied:

package com.myproject;

import static org.mockito.Mockito.when;

class SpotlessTest {

	void test() {

		String a = "a";
		when(null);

		
		
	}
}

pbite avatar Mar 16 '24 13:03 pbite