Reputation: 39
I would like create a checkstyle rule for constants. My problem is how I can set the scope in this rule. Let see it:
I have this code:
public class foo {
//all are memeberName for checkstyle
private final int NUMBER = 10; // violation is member
private int mNumber = 3;
private void bar(){
final String text = "foo"; // violation is final
String txt = "example";
}
}
checkstyle.xml
<!-- final var -->
<module name="LocalFinalVariableName">
<property name="format" value="^[A-Z0-9][A-Z0-9\_]*$" />
<message key="name.invalidPattern"
value="violation is final." />
</module>
<module name="MemberName">
<property name="format" value="^[m][A-Z][a-zA-Z0-9]*$" />
<message key="name.invalidPattern"
value="violation is member." />
</module>
How could I use member rule excet final var and add this rule to class constants?
This is my checkstyle dependence: checkstyle 'com.puppycrawl.tools:checkstyle:8.26'
thanks
Upvotes: 0
Views: 141
Reputation: 669
May be this check is the one you are looking for https://checkstyle.sourceforge.io/apidocs/com/puppycrawl/tools/checkstyle/checks/naming/ConstantNameCheck.html
Upvotes: 1