如何更改 Checkstyle 中注释数组初始化子项允许的缩进级别?

Bal*_*sök 6 java annotations indentation checkstyle maven

在我从事的一个项目中,我们通过maven-checkstyle-plugin. 我们还使用springdoc-openapi-ui,因此在控制器上我们使用@ApiReponses注释。它的语法相当复杂,但效果很好,所以我在控制器上写了这样的东西:

@ApiResponses(value = {
        @ApiResponse(description = "foo",
                content = {
                        @Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                                schema = @Schema(implementation = UgyTableDataResponse.class)),
                        @Content(mediaType = MediaType.APPLICATION_XML_VALUE,
                                schema = @Schema(implementation = UgyTableDataResponse.class))
                })
})
Run Code Online (Sandbox Code Playgroud)

然而,@ApiResponse@Content注释均由 Checkstyle 标记为Checkstyle: 'annotation array iteration' child 的缩进级别为 12,预期级别应为 8。

我想更改 Checkstyle 设置,以便可以将注释保持在这种易于阅读的格式中。

我的缩进设置checkstyle.xml是:

<module name="Indentation">
        <property name="basicOffset" value="4"/>
        <property name="braceAdjustment" value="0"/>
        <property name="caseIndent" value="4"/>
        <property name="throwsIndent" value="4"/>
        <property name="lineWrappingIndentation" value="4"/>
        <property name="arrayInitIndent" value="4"/>
    </module>
Run Code Online (Sandbox Code Playgroud)

POM中的插件依赖是:

@ApiResponses(value = {
        @ApiResponse(description = "foo",
                content = {
                        @Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                                schema = @Schema(implementation = UgyTableDataResponse.class)),
                        @Content(mediaType = MediaType.APPLICATION_XML_VALUE,
                                schema = @Schema(implementation = UgyTableDataResponse.class))
                })
})
Run Code Online (Sandbox Code Playgroud)

mle*_*edy 1

您可以将arrayInitIndent配置中的选项更改为 8(因为您的代码使用 8 个空格缩进),也可以将代码中的缩进级别更改为 4。

@ApiResponses(value = {
    @ApiResponse(description = "foo",
        content = {
            @Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                schema = @Schema(implementation = UgyTableDataResponse.class)),
            @Content(mediaType = MediaType.APPLICATION_XML_VALUE,
                schema = @Schema(implementation = UgyTableDataResponse.class))
        })
})
Run Code Online (Sandbox Code Playgroud)