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?
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With