spring-io / spring-javaformat

Apache License 2.0
795 stars 110 forks source link

Arguments in new line for Record #417

Closed azerafati closed 2 months ago

azerafati commented 2 months ago

Looking at how a record gets formatted for me with version 0.0.42 it makes me think it was more readable to have the arguments in new line. Can this be configured in .springjavaformatconfig or any recommendation?

Before

public record MockDataRecord(
        BigDecimal alphaValue, 
        BigDecimal betaCount,
        boolean gammaIncluded,
        MockReferral deltaReferral,
        MockProvider epsilonProvider,
        MockProvider zetaCoordinator,
        List<MockDiagnosis> etaDiagnoses,
        String thetaCode,
        LocalDate iotaEndDate,
        LocalDate kappaStartDate,
        boolean lambdaAdditional,
        boolean muDiagnosticType, 
        ZonedDateTime nuBeginTime,
        List<MockFeature> xiFeatures,
        String omicronAuthCode
) {
}

After formatting

public record MockDataRecord(BigDecimal alphaValue, BigDecimal betaCount, boolean gammaIncluded,
        MockReferral deltaReferral, MockProvider epsilonProvider, MockProvider zetaCoordinator,
        List<MockDiagnosis> etaDiagnoses, String thetaCode, LocalDate iotaEndDate, LocalDate kappaStartDate,
        boolean lambdaAdditional, boolean muDiagnosticType, ZonedDateTime nuBeginTime, List<MockFeature> xiFeatures,
        String omicronAuthCode) {
}
philwebb commented 2 months ago

It's probably a bit subjective about which looks better, but for our own use in Spring I think I prefer the existing formatted version. I'm afraid adding a config option goes against the goals of this project:

Since the aim of this project is to provide consistency, each plugin is not generally configurable. You need to change your code to match the required conventions. You can’t configure the plugin conventions to match your style!

We did make tabs/spaces configurable but I'm not keen to do more than that.

If you want to maintain your own fork, you can probably do what you want by editing https://github.com/spring-io/spring-javaformat/blob/main/spring-javaformat/spring-javaformat-formatter/src/main/resources/io/spring/javaformat/formatter/eclipse/formatter.prefs.