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

Open
#2,066 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
java

Research direction

Reproduce the report with the supplied spotless-maven-plugin 2.43.0 configuration, Maven 3.8.4, and the two Java examples, running spotless:check and spotless:apply. Compare the cases involving when and verify that incorrect empty-line formatting is detected and corrected consistently.

Written by the indexing model from the issue text.

Description

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);

		
		
	}
}
Dominant language
Java
Stars
5.7k
Forks
560
Avg merge
1d 13h
Merged PRs (30d)
43

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from diffplug/spotless

All issues in diffplug/spotless

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.