Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong formatting (missing whitespace) in Java instanceof type pattern with method calls on the left side #1046

Closed
6 tasks done
krusche opened this issue Dec 23, 2021 · 6 comments
Labels

Comments

@krusche
Copy link

krusche commented Dec 23, 2021

If 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

@krusche
Copy link
Author

krusche commented Dec 23, 2021

I just played around with different versions, it seems that this issue is introduced in 5.15.1 due to the following update:

Added support and bump Eclipse formatter default versions to 4.20

I was just able to update to the latest version of com.diffplug.spotless 6.0.5 when still using 4.19.0 for the Eclipse formatter.
So this might be an issue on the Eclipse side. If someone has a hint, if the configuration needs to be changed, this would be great. Thank you!

@nedtwigg nedtwigg added the bug label Dec 23, 2021
@nedtwigg
Copy link
Member

Seems like a bug in eclipse 4.20.0, glad that eclipse('4.19.0') fixes it for you. Hopefully this gets fixed in 4.22.0, but I'm not sure when we'll add support for that in Spotless.

@krusche
Copy link
Author

krusche commented Dec 23, 2021

Thanks for the fast feedback, @nedtwigg
Do you know if the Eclipse developers are already aware of this issue?
Or should we open an issue in their bug tracking system?

@nedtwigg
Copy link
Member

Do you know if the Eclipse developers are already aware of this issue? Or should we open an issue in their bug tracking system?

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.

@nedtwigg
Copy link
Member

nedtwigg commented Jan 6, 2022

Looks like this will get fixed when #1059 gets fixed.

@nedtwigg
Copy link
Member

Has been fixed for a long time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants