diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 27c78dde65..3fd167c5b8 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -16,6 +16,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( - `removeSemicolons()` no longer removes semicolons inside dollar-slashy strings (`$/ ... /$`), after escaped triple quotes in multiline strings, or in multi-line `for (init; cond; update)` headers. ([#2780](https://github.com/diffplug/spotless/issues/2780)) - `removeUnusedImports()` and `googleJavaFormat()` no longer remove imports that are only used by links in Markdown doc comments (`///`, JDK 23+). ([#3161](https://github.com/diffplug/spotless/issues/3161)) - `forbidWildcardImports` no longer reports import statements inside Java text blocks or comments. ([#2997](https://github.com/diffplug/spotless/issues/2997)) +- `spotlessCheck` no longer fails with `There were 0 lint error(s)` when `spotless-clean` only contains stale files which already match the source on disk. ([#2992](https://github.com/diffplug/spotless/issues/2992)) ## [8.11.0] - 2026-11-02 ### Added diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessCheck.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessCheck.java index a8b715cbf9..1bd3d779a4 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessCheck.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessCheck.java @@ -80,12 +80,15 @@ private void performAction(boolean isTest) throws IOException { getEncoding().get()) .problemFiles(unformattedFiles) .getMessage()); - } else { + } else if (!lintsFiles.isEmpty()) { // We only show lints if there are no unformatted files. // This is because lint line numbers are relative to the // formatted content, and formatting often fixes lints. boolean detailed = false; throw new GradleException(super.allLintsErrorMsgDetailed(lintsFiles, detailed)); + } else { + // the clean files are stale copies of what is already on disk (see getUncleanFiles) + getState().setDidWork(sourceDidWork()); } } } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PaddedCellTaskTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PaddedCellTaskTest.java index 0b13dd6475..fb061078f8 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PaddedCellTaskTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PaddedCellTaskTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2025 DiffPlug + * Copyright 2016-2026 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -170,6 +170,17 @@ void paddedCellApplyCheck() throws Exception { diverge.check(); } + @Test + void checkPassesWhenCleanFileMatchesDisk() throws Exception { + Bundle wellbehaved = wellbehaved(); + wellbehaved.format(); + setFile("src/test.wellbehaved").toContent("42"); + assertFile(wellbehaved.outputFile.get()).hasContent("42"); + + // a stale clean file without lints must not fail the check (#2992) + wellbehaved.check.get().performActionTest(); + } + @Test void diagnose() throws Exception { wellbehaved().diagnose();