Does Checkstyle give you a backtrack warning in annotations?

I have an annotation:

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

And the Checkstyle configuration:

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

When I run my project through Checkstyle, I get the error message "Assign child at indentation level 2 not on the correct indentation, 4". This is a link to line 5 of my sample code above, i.e. The closing bracket for the property basePackages.

What configuration change do I need for Checkstyle so that this annotation is validated correctly?

+4
source share
1 answer

This is a known issue in checkstyle: github.com/checkstyle/checkstyle/issues/553

As a workaround, you can set the lineWrappingIndentation property to zero:

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

, .

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

return getCalculator(). 
        calculate(...);
+1

All Articles