RecordComponentName

Since Checkstyle 8.40

Description

Checks that record component names conform to a specified pattern.

Properties

name description type default value since
format Sets the pattern to match valid identifiers. Pattern "^[a-z][a-zA-Z0-9]*$" 8.40

Examples

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]+$"
        

Example of Usage

Violation Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.naming

Parent Module

TreeWalker