Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lombok checkstyle VisibilityModifier error

I have the following code which uses lombok @Value for generating a immutable class:

@Value
public class InputDTO {
    String field;
}

but unfortunately it doesn't agree with checkstyle visibility modifier checks which complains with this error:

Variable 'field' must be private and have accessor methods. (18:10) [VisibilityModifier]

I have found a workaround suppressing the check like this:

@SuppressWarnings("checkstyle:VisibilityModifier")

But is there a way to make checkstyle validate lombok's generated code rather than the plain original code?

like image 250
Fede Garcia Avatar asked Apr 15 '20 20:04

Fede Garcia


1 Answers

There is a way to disable this violation in checkstyle.xml config once rather than using @SuppressWarnings in every file and pollute your production code.

With the SuppressionXpathSingleFilter you can do:

<module name="TreeWalker">
    <module name="SuppressionXpathSingleFilter">
        <property name="checks" value="VisibilityModifier"/>
        <property name="query" value="//*[MODIFIERS//*[@text = 'Value']]/descendant-or-self::node()"/>
    </module>
</module>
like image 83
pavelicii Avatar answered Sep 22 '22 22:09

pavelicii