How to prevent Spotless/Eclipse from joining lines?
Asked Answered
C

1

7

I have a project that uses Spotless with the Eclipse formatter to check and format the source code.

Now one problem is that the formatter creates some absurdly long lines such as the following:

    @ApiModelProperty(value = "This is a placeholder text but the real text is just as long as this.", required = true, example = "811769e0-69f8-11e6-91aa-02000ab20f88")

That’s 170 characters, and I got eye-strain and SonarQube complaining. When I break the line, Spotless/Eclipse insist on joining the lines together. The configuration file has lines such as:

<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="150"/>

The file is picked up fine, but the formatter still joins these wrapped lines and would never split them. There seems to be a related ancient (and closed) issue 338916 in the Eclipse bug tracker. This is probably not a Spotless configuration issue, since it delegates everything to the Ecplipse plugin. Which magic configuration key will persuate the Eclipse formatter to behave as advertised?

Cindycine answered 15/3, 2021 at 14:57 Comment(1)
Did you ever find out?Congregation
T
1

I used similar spotless eclipse formatter settings and still ran into the same issue with the formatter joining wrapped API documentation lines into a single long line. What I ended up doing was enabling toggle comments and putting them around the lines I didn't want joined. Wrapped lines that are surrounded by the toggle comments remain wrapped. Sample below:

    // spotless:off
    @Operation(summary = "getImagePullCount",
               description = "Generates the docker pulls badge",
               responses = @ApiResponse(description = "An XML representing the SVG docker pulls badge",
                                        content = @Content(mediaType = CONTENT_TYPE_BADGE,
                                        schema = @Schema(implementation = String.class))))
    public String getImagePullCount(@Parameter(in = ParameterIn.QUERY,
                                               description = ApiSpecConstants.API_DESC_PARAM_PACKAGE,
                                               example = ApiSpecConstants.EXAMPLE_PARAM_PACKAGE)
                                    @QueryValue("package") String packageName,
                                    @Parameter(in = ParameterIn.QUERY,
                                               description = ApiSpecConstants.API_DESC_PARAM_LABEL)
                                    @QueryValue(value = "label", defaultValue = "docker pulls") String badgeLabel) {
    // spotless:on
Tadzhik answered 20/7, 2023 at 1:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.