-
Notifications
You must be signed in to change notification settings - Fork 493
Description
Some formatters have idempotency bugs. Spotless has a padded cell feature which can fix them.
A long time ago, this feature was off by default. A user would get an error related to idempotency, they could run spotlessDiagnose to understand it, and then they might turn on the padded cell feature.
In 3.29.0 released May 2020 we made padded cell mandatory, so idempotency problems are always silently fixed.
The maven plugin has never had a "diagnose" task. Probably no one would notice if we removed it from the Gradle plugin also.
Here is the code:
spotless/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessDiagnoseTask.java
Lines 34 to 77 in 88c83de
| @UntrackedTask(because = "undeclared inputs/outputs") | |
| public class SpotlessDiagnoseTask extends DefaultTask { | |
| SpotlessTask source; | |
| @Internal | |
| public SpotlessTask getSource() { | |
| return source; | |
| } | |
| @TaskAction | |
| @SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") | |
| public void performAction() throws IOException { | |
| Path srcRoot = getProject().getProjectDir().toPath(); | |
| Path diagnoseRoot = getProject().getLayout().getBuildDirectory().getAsFile().get() | |
| .toPath().resolve("spotless-diagnose-" + source.formatName()); | |
| getProject().delete(diagnoseRoot.toFile()); | |
| try (Formatter formatter = source.buildFormatter()) { | |
| for (File file : source.target) { | |
| getLogger().debug("Running padded cell check on " + file); | |
| PaddedCell padded = PaddedCell.check(formatter, file); | |
| if (!padded.misbehaved()) { | |
| getLogger().debug(" well-behaved."); | |
| } else { | |
| // the file is misbehaved, so we'll write all its steps to DIAGNOSE_DIR | |
| Path relative = srcRoot.relativize(file.toPath()); | |
| Path diagnoseFile = diagnoseRoot.resolve(relative); | |
| for (int i = 0; i < padded.steps().size(); i++) { | |
| Path path = Path.of(diagnoseFile + "." + padded.type().name().toLowerCase(Locale.ROOT) + i); | |
| Files.createDirectories(path.getParent()); | |
| String version = padded.steps().get(i); | |
| Files.write(path, version.getBytes(formatter.getEncoding())); | |
| } | |
| // dump the type of the misbehavior to console | |
| getLogger().lifecycle(" " + relative + " " + padded.userMessage()); | |
| } | |
| } | |
| } | |
| if (Files.exists(diagnoseRoot)) { | |
| getLogger().lifecycle("Some formatters are misbehaving, you can see details at " + diagnoseRoot); | |
| } else { | |
| getLogger().lifecycle("All formatters are well behaved for all files."); | |
| } | |
| } | |
| } |
And here is info on some tech debt that it has accumulated. Probably better to just delete it than fix it. Anybody object?