Formatting inconsistent when both <tabs> and <spaces> indentation rules are present

Open
#2,480 2 comments 0 reactions 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
Mostly clear
Activity status
Stale
Tech stack
java
Domain
build-system

Research direction

Start by reproducing the behavior with the Maven plugin configuration in the issue, focusing on the two Java blocks and the src/main/java//*.java and src/test/java//*.java includes. Inspect how the Maven configuration handles multiple indentation rules; done means Java files are formatted consistently when both rules are present, with the up-to-date debug message behaving as expected.

Written by the indexing model from the issue text.

Description

I'm encountering inconsistent formatting behavior when both blocks — one tabs true and another with spaces true — are defined under the Spotless configuration in a Maven project.

Some Java files are formatted, some are skipped, and others show partial formatting. When I remove one of the two blocks, the behavior becomes consistent.
I keep getting this debug log
[DEBUG] Spotless will not format an up-to-date file:

<plugin>
        <groupId>com.diffplug.spotless</groupId>
        <artifactId>spotless-maven-plugin</artifactId>
        <version>2.43.0</version>
        <configuration>
          <java>
            <includes>
              <include>src/main/java/**/*.java</include>
              <include>src/test/java/**/*.java</include>
            </includes>
            <trimTrailingWhitespace/>
            <removeUnusedImports/>
            <indent>
              <tabs>true</tabs>
              <spacesPerTab>2</spacesPerTab>
            </indent>
            <indent>
              <spaces>true</spaces>
              <spacesPerTab>4</spacesPerTab>
            </indent>
            <googleJavaFormat>
              <version>1.17.0</version>
            </googleJavaFormat>
          </java>
          <pom>
            <includes>
              <include>pom.xml</include>
            </includes>
            <sortPom>
              <expandEmptyElements>false</expandEmptyElements>
            </sortPom>
          </pom>
          <markdown>
            <excludes>
              <exclude>**/node/**</exclude>
              <exclude>**/node_modules/**</exclude>
            </excludes>
            <includes>
              <include>**/*.md</include>
            </includes>
            <flexmark/>
          </markdown>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>check</goal>
            </goals>
            <phase>validate</phase>
          </execution>
        </executions>
      </plugin>
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.