Checkstyle在注释上发出缩进警告?

时间:2013-12-06 14:37:56

标签: java checkstyle

我有一个注释:

@ComponentScan(
  basePackages = {
    "com.example.foo",
    "com.example.bar"
  }   // <--- false positive reported in this line
)
public class FooBar extends WebMvcConfigurerAdapter {
  ...
}

Checkstyle配置:

<module name="AnnotationUseStyle" />
<module name="Indentation">
  <property name="basicOffset" value="2" />
  <property name="braceAdjustment" value="0" />
  <property name="caseIndent" value="2" />
</module>

当我通过Checkstyle运行我的项目时,我收到一条错误,指出“在缩进级别2指定子级而不是正确的缩进,4”。这是我上面代码示例的第5行引用,即basePackages属性的结束括号。

我需要对Checkstyle进行哪些配置更改才能使此注释正确验证?

1 个答案:

答案 0 :(得分:2)

这是checkstyle中的一个已知问题:github.com/checkstyle/checkstyle/issues/553

作为一种解决方法,您可以将 lineWrappingIndentation 属性设置为零:

<module name="Indentation">
    <property name="lineWrappingIndentation" value="0"/>
</module>

但在这种情况下,您还需要在换行符后删除额外的缩进,例如

return getCalculator().
    calculate(...);

而不是

return getCalculator(). 
        calculate(...);