Since Checkstyle 8.40
name | description | type | default value | since |
---|---|---|---|---|
format | Sets the pattern to match valid identifiers. | Pattern | "^[a-z][a-zA-Z0-9]*$" |
8.40 |
To configure the check:
<module name="Checker"> <module name="TreeWalker"> <module name="RecordComponentName"/> </module> </module>
Example:
record MyRecord1(String value, int otherComponentName) {} // OK record MyRecord2(String... Values) {} // violation, the record component name // should match the regular expression "^[a-z][a-zA-Z0-9]*$" record MyRecord3(double my_number) {} // violation, the record component name // should match the regular expression "^[a-z][a-zA-Z0-9]*$"
An example of how to configure the check for names that are only letters in lowercase:
Configuration:
<module name="Checker"> <module name="TreeWalker"> <module name="RecordComponentName"> <property name="format" value="^[a-z]+$"/> </module> </module> </module>
Example:
record MyRecord1(String value, int other) {} // OK record MyRecord2(String... strings) {} // OK record MyRecord3(double myNumber) {} // violation, the record component name // should match the regular expression "^[a-z]+$"
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
com.puppycrawl.tools.checkstyle.checks.naming