Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkstyle issuing an indentation warning on an annotation?

I have an annotation like:

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

And a Checkstyle configuration of:

<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 an error stating "assign child at indentation level 2 not at correct indentation, 4". This is referencing line 5 of my code example above, i.e. the closing parenthetical for the basePackages property.

What configuration change to Checkstyle would I need to make for this annotation to validate correctly?

like image 910
James Sumners Avatar asked Nov 01 '22 09:11

James Sumners


1 Answers

It's a known issue in checkstyle: github.com/checkstyle/checkstyle/issues/553

As a workaround you can set lineWrappingIndentation property to zero:

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

But in this case you will also need to remove extra indentations after line breaks, e.g.

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

instead of

return getCalculator(). 
        calculate(...);
like image 161
Yury Kisliak Avatar answered Nov 13 '22 04:11

Yury Kisliak