palantir / palantir-java-format

A modern, lambda-friendly, 120 character Java formatter.
Apache License 2.0
407 stars 43 forks source link

Inconsistent/Incorrect indentation for Java `Record` object #1007

Closed Zhenye-Na closed 5 months ago

Zhenye-Na commented 5 months ago

What happened?

I have configured 4 spaces for my java project, but after the formatting, the java file of multiple Record is reindented to 8 spaces

I have attached an example of formatted class. I used numbers to represent spaces for the first member variable

public record XXXXX(

12345678@NonNull List<XXXX> XXXXX,

        @NonNull String XXXX,

        @NonNull X X) {}

What did you want to happen?

Record class should also be 4 spaces

iamdanfox commented 5 months ago

to the best of my knowledge, palantir-java-format does not have a config point to allow you to control how many spaces you want to appear. (See the current formatter CLI options).

This is an intentional design decision of the project, because we were really trying to drive homogeneity across hundreds of java projects and specifically wanted to:

See more about this intention in the README: https://github.com/palantir/palantir-java-format?tab=readme-ov-file#upsides-of-automatic-formatting

Zhenye-Na commented 5 months ago

Hello @iamdanfox

Thanks for the reply. I understood the pros and cons, thats the reason why we prefer palantir formatter to google style.

But I am not sure if my question is answered, are you saying that the issue I mentioned above is by design, which makes Record class's indentation to be 8 spaces?

Thanks

iamdanfox commented 5 months ago

At the moment, that is palantir-java-format's behaviour when it wraps arguments to a record constructor.