You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Eclipse formatter 4.20 and 4.21 are broken for records #951
Each time a new version of an existing formatter comes out and we bump our default version, there is a chance that formatting will change. One way to avoid this is to pin the formatter version (as you have done with eclipse('4.19.0'), and another way is to use ratcheting to make sure that the formatter changes only affect files that are changing anyway.
Our general philosophy for handling the changing of these defaults is laid out here.
However, the case you are describing is quite extreme, and it sure looks like the eclipse formatter is just plain broken for java record classes starting with 4.20
It could be that we need to make some changes to this line
I am afraid it seems a Spotless error. Only quickly checked the formatting with Eclipse 2021-06 (4.20.0). I will see what I can achieve on the weekend. Help is always welcome 😄
@nedtwigg Thanks for the hint. There seems also a bug in the format statement, but that should only affect module-info. We need to extend the interface for the spotless-eclipse-jdt. It should detect a module-info by filename.
#957 proves the correct integration of the JDT formatter into Eclipse.
The erroneous formatting reported within this issue is caused by the configuration used by TJ-Bot.
Formatting with default Eclipse configuration (build.gradle):
spotless {
java {
// Excludes build folder since it contains generated java classes.
targetExclude("build/**")
eclipse('4.21.0')
}
}
Results in formatter/src/main/java/org/togetherjava/formatter/tokenizer/Token.java:
importjava.util.Set;
/** * Class representing a Token with a given content and a type * * @author illuminator3 */publicrecordToken(Stringcontent, TokenTypetype) {
privatestaticfinalSet<TokenType> displayTypes = Set.of(TokenType.IDENTIFIER, TokenType.UNKNOWN, TokenType.STRING,
TokenType.COMMENT);
@OverridepublicStringtoString() {
returntype().name() + formatForDisplay();
}
/** * Returns a non-empty string if this token has something to display * * @return the displayed value * @author illuminator3 */privateStringformatForDisplay() {
if (displayTypes.contains(type())) {
return"(" + content() + ")";
}
return"";
}
}
@marko-radosavljevic Please check your Eclipse configuration. Seems it causes conflicts using latter formatter versions.
We ran into the same problem in a java 17 maven project. We used eclipse-java-google-style out of the box. Here's the plugin configuration from our pom.xml:
Activity
[-]Updating spotless to 5.15.1 breaks formatting[/-][+]Eclipse formatter 4.20 and 4.21 are broken for records[/+]nedtwigg commentedon Sep 29, 2021
Each time a new version of an existing formatter comes out and we bump our default version, there is a chance that formatting will change. One way to avoid this is to pin the formatter version (as you have done with
eclipse('4.19.0'), and another way is to use ratcheting to make sure that the formatter changes only affect files that are changing anyway.Our general philosophy for handling the changing of these defaults is laid out here.
However, the case you are describing is quite extreme, and it sure looks like the eclipse formatter is just plain broken for java record classes starting with 4.20
It could be that we need to make some changes to this line
spotless/_ext/eclipse-jdt/src/main/java/com/diffplug/spotless/extra/eclipse/java/EclipseJdtFormatterStepImpl.java
Line 57 in a9e8357
@fvgh is the expert here, but it may be the case that this will just be broken until Eclipse 4.22 or later.
fvgh commentedon Sep 29, 2021
I am afraid it seems a Spotless error. Only quickly checked the formatting with Eclipse 2021-06 (4.20.0). I will see what I can achieve on the weekend. Help is always welcome 😄
@nedtwigg Thanks for the hint. There seems also a bug in the
formatstatement, but that should only affect module-info. We need to extend the interface for thespotless-eclipse-jdt. It should detect a module-info by filename.fvgh commentedon Oct 3, 2021
#957 proves the correct integration of the JDT formatter into Eclipse.
The erroneous formatting reported within this issue is caused by the configuration used by TJ-Bot.
Formatting with default Eclipse configuration (build.gradle):
spotless { java { // Excludes build folder since it contains generated java classes. targetExclude("build/**") eclipse('4.21.0') } }Results in
formatter/src/main/java/org/togetherjava/formatter/tokenizer/Token.java:@marko-radosavljevic Please check your Eclipse configuration. Seems it causes conflicts using latter formatter versions.
fvgh commentedon Oct 10, 2021
@marko-radosavljevic Closing this issue since I found no problems on Spotless side. Feel free to reopen if you have more input I should look into.
marko-radosavljevic commentedon Oct 12, 2021
Thanks a lot for the help, I really appreciate it. ^^
I will further investigate our eclipse configuration and make it compatible with newer formatter versions.
moritz-tiedje commentedon Sep 18, 2024
We ran into the same problem in a java 17 maven project. We used eclipse-java-google-style out of the box. Here's the plugin configuration from our pom.xml:
The problem was not on the Spotless side. We fixed it by removing the following lines from
eclipse-java-google-style.xml:chore: DH-21421: Update Java style guide for record formatting (#7576)