Wrong formatting (missing whitespace) in Java instanceof type pattern with method calls on the left side
See original GitHub issueIf you are submitting a bug, please include the following:
- summary of problem
- gradle or maven version
- spotless version
- operating system and version
- copy-paste your full Spotless configuration block(s), and a link to a public git repo that reproduces the problem if possible
- copy-paste the full content of any console errors emitted by
gradlew spotless[Apply/Check] --stacktrace
We still use Spotless 5.15.0 because all subsequent releases introduce an issue that we are affected: a whitespace before instanceof
is removed in some cases, not all.
We use Gradle 7.3.3 and a custom Eclipse configuration: https://github.com/ls1intum/Artemis/blob/develop/artemis-spotless-style.xml (Note: In Eclipse, it seems the formatting works correctly for the example that went wrong in our repository)
Our full gradle file is here: https://github.com/ls1intum/Artemis/blob/develop/build.gradle
Here is the relevant spotless configuration:
spotless {
// allows to execute the code formatting commands ./gradlew spotlessApply and ./gradlew spotlessCheck
java {
target project.fileTree(project.rootDir) {
include "**/*.java"
exclude "**/src/main/java/de/tum/in/www1/artemis/service/connectors/BambooService.java", "**/src/main/java/de/tum/in/www1/artemis/config/SecurityConfiguration.java", "**/src/main/java/de/tum/in/www1/artemis/config/SAML2Configuration.java", "**/src/test/resources/test-data/repository-export/EncodingISO_8559_1.java", "**/node_modules/**", "**/out/**", "**/repos/**", "**/build/**", "**/src/main/generated/**", "**/src/main/resources/templates/**"
}
importOrderFile "artemis-spotless.importorder"
eclipse().configFile "artemis-spotless-style.xml"
removeUnusedImports()
}
}
When I update to the latest spotless version in line 24 of build.gradle
id "com.diffplug.spotless" version "6.0.5"
then using ./gradlew spotlessApply -x webapp
will lead to changes that are wrong:
0001-wrong-spotless-changes-git-patch.txt
Here is one simple example:
- if (discoveryHealthContributor.getContributor() instanceof HealthIndicator healthIndicator) {
+ if (discoveryHealthContributor.getContributor()instanceof HealthIndicator healthIndicator) {
Notice the removed whitespace between the method call on the left side and instanceof
.
It seems that a method call on the left side of the Java instanceof type pattern is not handled correctly, because it works correctly if the left side is a normal variable.
I went through all Eclipse Code Style settings and could not find an appropriate setting for a whitespace between a method call and instanceof.
My OS version is macOS 12.1, but it seems this is independent of the OS
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Looks like this will get fixed when #1059 gets fixed.
I don’t know if they are already aware, and if they aren’t it would be a good idea to open an issue with them. If you find anything interesting at https://bugs.eclipse.org/bugs/ feel free to post it back here. Spotless integrates with lots of formatters. We don’t take responsibility for their bugs, but we are happy to keep issues such as this open so that people can track/coordinate.