palantir-java-format
palantir-java-format copied to clipboard
Formatter generates switch expression incompatible with baseline checkstyle
What happened?
The formatter will format
public void initialize(SchedulerBackend newBackend) {
this.backend = newBackend;
schedulableBuilder = switch (schedulingMode) {
case FIFO -> new ReFifoSchedulableBuilder(rootPool);
case FAIR -> new ReFairSchedulableBuilder(rootPool, sc);
default -> throw new SafeIllegalArgumentException(
"Unsupported scheduler mode", SafeArg.of("schedulingMode", schedulingMode));
};
schedulableBuilder.buildPools();
}
To
public void initialize(SchedulerBackend newBackend) {
this.backend = newBackend;
schedulableBuilder = switch (schedulingMode) {
case FIFO -> new ReFifoSchedulableBuilder(rootPool);
case FAIR -> new ReFairSchedulableBuilder(rootPool, sc);
default -> throw new SafeIllegalArgumentException(
"Unsupported scheduler mode", SafeArg.of("schedulingMode", schedulingMode));};
schedulableBuilder.buildPools();
}
which violates checkstyle rules.
What did you want to happen?
In that specific case, the formatter should have been a no-op.
I just hit this problem as well. The formatter produces the following (note the weird trailing curly):
this.environmentReadStore = switch (readMode) {
case OLD_TABLES -> new AaaaEnvironmentReadStore(
environmentTable, environmentRidByDeploymentIdTable, recommendationV5StatusTable);
case NEW_TABLES -> new AaaaEnvironmentV2ReadStore(
environmentV2Table, environmentV2IndexTable, recommendationV5StatusTable);};
And then I get the following error:
> Task :my-project:checkstyleMain
[ant:checkstyle] [ERROR] /Volumes/git/...../FooClass.java:80:94: ';' is not followed by whitespace. [WhitespaceAfter]
This happens with gradle-palantir-java-format 2.26.0
Adding yield
keyword still has the weird dense curly:
this.environmentReadStore = switch (readMode) {
case OLD_TABLES -> {
yield new AaaaEnvironmentReadStore(
environmentTable, environmentRidByDeploymentIdTable, recommendationV5StatusTable);
}
case NEW_TABLES -> {
yield new AaaaEnvironmentV2ReadStore(
environmentV2Table, environmentV2IndexTable, recommendationV5StatusTable);
}};
This is still happening and took me by surprise when it happened, is there interest from the project in changing it?
Looks like it was fixed in #1069