Skip to content

Add failOnNotConverging() so spotlessCheck cannot pass for a file it did not check - #3218

Open
Inf1mum wants to merge 1 commit into
diffplug:mainfrom
Inf1mum:fail-on-not-converging
Open

Inf1mum wants to merge 1 commit into
diffplug:mainfrom
Inf1mum:fail-on-not-converging

Conversation

@Inf1mum

@Inf1mum Inf1mum commented Dec 1, 2026

Copy link
Copy Markdown

Resolves #3143

What is wrong

For a file whose formatting does not converge, SpotlessTaskImpl prints Skipping '<path>' because it does not converge and writes no output, and SpotlessCheck only inspects the clean/lints output directories — so the skip is invisible to the check: spotlessCheck exits 0 for a file it did not check. In CI that file is silently ungated, and a formatter bump can turn a previously-formatted file non-convergent with no signal at all (green to green).

Reproduction on current main (before this change): a custom step that appends a space never converges, and PaddedCellTaskTest's existing diverge.check() succeeds. My RED probe test asserting the opposite failed on unmodified main:

com.diffplug.gradle.spotless.PaddedCellTaskTest redProbeNonConvergingFileMustFailCheck() FAILED
7 tests completed, 1 failed

What changed (opt-in, default behavior unchanged)

  • SpotlessTask: new @Input boolean property failOnNotConverging, default false.
  • FormatExtension.failOnNotConverging(): opt-in DSL, forwarded to the format task in setupTask (covers every format type, since all typed extensions call super.setupTask).
  • SpotlessTaskImpl.processInputFile: in the existing didNotConverge branch, an opted-in build now throws with a message pointing at spotlessDiagnose / the flag; without the flag the warning-and-skip behavior is byte-for-byte what it was.
spotless {
  markdown {
    target '*.md'
    flexmark()
    failOnNotConverging() // a green spotlessCheck means every target file was actually checked
  }
}
  • Docs: new "Non-converging files" section in plugin-gradle/README.md (+ TOC entry), CHANGES.md entry.
  • Tests: FailOnNotConvergingTest (end-to-end, Gradle TestKit) and PaddedCellTaskTest.failOnNotConvergingFailsCheck.

Verification

RED (unmodified main, before the change): 7 tests completed, 1 failed — the probe asserting "check must fail for a non-converging file" failed, demonstrating the gap.

GREEN (this change), ./gradlew :plugin-gradle:test over the targeted set:

PaddedCellTaskTest (7 tests, includes failOnNotConvergingFailsCheck)  PASSED
FailOnNotConvergingTest (2 tests: skipsByDefault, failsWhenOptIn)     PASSED
FormatTaskTest, IndependentTaskTest, ErrorShouldRethrowTest,
DiffMessageFormatterTest, GradleIncrementalResolutionTest,
ConfigurationCacheTest                                                PASSED
total: 29 tests, 0 failures, 0 errors

./gradlew :plugin-gradle:spotlessCheck (self-application incl. freshmark) and :plugin-gradle:javadoc pass.

What must NOT change

  • Default behavior: without failOnNotConverging(), a non-converging file is still skipped with exactly the previous warning and spotlessCheck still passes (FailOnNotConvergingTest.skipsByDefault and the untouched paddedCellFormat / paddedCellApplyCheck pin this).
  • PaddedCell resolution for CYCLE/CONVERGE types is untouched — only the unresolvable DIVERGE path is affected.
  • The Maven plugin and lib are untouched; this change is Gradle-plugin only (the Maven plugin tracks non-converging files in its own report, separate concern).
  • spotlessDiagnose, the IDE hook, and ratcheting behavior are untouched.

…did not check (diffplug#3143)

A file whose formatting does not converge is skipped with a warning, and spotlessCheck passes even though the file was never checked - in CI such a file is silently ungated (diffplug#3143). The new opt-in failOnNotConverging() makes the format task fail on such a file instead; the default behavior (warn + skip) is unchanged.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A non-converging file is skipped with a zero exit, so spotlessCheck reports success for a file it did not check

1 participant