Naming Rules ("rulesets/naming.xml")

AbstractClassName Rule

Verifies that the name of an abstract class matches the regular expression specified in the regex property. If that property is null or empty, then this rule is not applied (i.e., it does nothing). It defaults to null, so this rule must be explicitly configured to be active. This rule ignores interfaces and is applied only to abstract classes.

Property Description Default Value
regex Specifies the regular expression used to validate the abstract
class name. If null or empty, then this rule does nothing.
null

ClassName Rule

Verifies that the name of a class matches a regular expression. By default it checks that the class name starts with an uppercase letter and is followed by zero or more word characters (letters, numbers or underscores).

Property Description Default Value
regex Specifies the regular expression used to validate the class
name. It is required and cannot be null or empty.
/[A-Z]\w*/

FieldName Rule

Verifies that the name of each field matches a regular expression. By default it checks that non-final field names start with a lowercase letter and contains only letters or numbers. By default, final field names start with an uppercase letter and contain only uppercase letters, numbers and underscores.

NOTE: This rule checks only regular fields of a class, not properties. In Groovy, properties are fields declared with no access modifier (public, protected, private). Thus, this rule only checks fields that specify an access modifier. For naming of properties, see PropertyNameRule.

Property Description Default Value
regex Specifies the default regular expression used to validate the
field name. It is required and cannot be null or empty.
/[a-z][a-zA-Z0-9]*/
finalRegex Specifies the regular expression used to validate final
field names. It is optional. If not set, then final
fields that are non-static are validated using regex.
/[A-Z][A-Z0-9_]*/
staticRegex Specifies the regular expression used to validate static
field names. It is optional. If not set, then static
fields that are non-final are validated using regex.
null
staticFinalRegex Specifies the regular expression used to validate
static final field names. It is optional. If not set,
then static final fields are validated using
finalRegex, staticRegex or regex.
null
ignoreFieldNames Specifies one or more (comma-separated) field names that
should be ignored (i.e., that should not cause a rule
violation). The names may optionally contain wildcards (*,?).
null

The order of precedence for the regular expression properties is: staticFinalRegex, finalRegex, staticRegex and finally regex. In other words, the first regex in that list matching the modifiers for the field is the one that is applied for the field name validation.

InterfaceName Rule

Verifies that the name of an interface matches the regular expression specified in the regex property. If that property is null or empty, then this rule is not applied (i.e., it does nothing). It defaults to null, so this rule must be explicitly configured to be active.

Property Description Default Value
regex Specifies the regular expression used to validate the name of
an interface. If null or empty, then this rule does nothing.
null

MethodName Rule

Verifies that the name of each method matches a regular expression. By default it checks that the method name starts with a lowercase letter. Implicit method names are ignored (i.e., 'main' and 'run' methods automatically created for Groovy scripts).

Property Description Default Value
regex Specifies the regular expression used to validate the method
name. It is required and cannot be null or empty.
/[a-z]\w*/
ignoreMethodNames Specifies one or more (comma-separated) method names that
should be ignored (i.e., that should not cause a rule
violation). The names may optionally contain wildcards (*,?).
null

PackageName Rule

Verifies that the package name of a class matches a regular expression. By default it checks that the package name consists of only lowercase letters and numbers, separated by periods.

Property Description Default Value
regex Specifies the regular expression used to validate the package
name. It is required and cannot be null or empty.
/[a-z]+(\.[a-z0-9]+)*/
packageNameRequired Indicates whether a package name declaration is required for
all classes.
false

ParameterName Rule

Verifies that the name of each parameter matches a regular expression. This rule applies to method parameters, constructor parameters and closure parameters. By default it checks that parameter names start with a lowercase letter and contains only letters or numbers.

Property Description Default Value
regex Specifies the regular expression used to validate the parameter
name. It is required and cannot be null or empty.
/[a-z][a-zA-Z0-9]*/
ignoreParameterNames Specifies one or more (comma-separated) parameter names that
should be ignored (i.e., that should not cause a rule
violation). The names may optionally contain wildcards (*,?).
null

PropertyName Rule

Verifies that the name of each property matches a regular expression. By default it checks that property names (other than static final) start with a lowercase letter and contains only letters or numbers. By default, static final property names start with an uppercase letter and contain only uppercase letters, numbers and underscores.

NOTE: This rule checks only properties of a class, not regular fields. In Groovy, properties are fields declared with no access modifier (public, protected, private). For naming of regular fields, see FieldNameRule.

Property Description Default Value
regex Specifies the default regular expression used to validate the
property name. It is required and cannot be null or empty.
/[a-z][a-zA-Z0-9]*/
finalRegex Specifies the regular expression used to validate final
property names. It is optional. If not set, then final
properties that are non-static are validated using regex.
null
staticRegex Specifies the regular expression used to validate static
property names. It is optional. If not set, then static
properties that are non-final are validated using regex.
null
staticFinalRegex Specifies the regular expression used to validate
static final property names. It is optional. If not set,
then static final property are validated using
finalRegex, staticRegex or regex.
/[A-Z][A-Z0-9_]*/
ignorePropertyNames Specifies one or more (comma-separated) property names that
should be ignored (i.e., that should not cause a rule
violation). The names may optionally contain wildcards (*,?).
null

The order of precedence for the regular expression properties is: staticFinalRegex, finalRegex, staticRegex and finally regex. In other words, the first regex in that list matching the modifiers for the property is the one that is applied for the field name validation.

VariableName Rule

Verifies that the name of each variable matches a regular expression. By default it checks that non-final variable names start with a lowercase letter and contains only letters or numbers. By default, final variable names start with an uppercase letter and contain only uppercase letters, numbers and underscores.

Property Description Default Value
regex Specifies the default regular expression used to validate the
variable name. It is required and cannot be null or empty.
/[a-z][a-zA-Z0-9]*/
finalRegex Specifies the regular expression used to validate final
variable names. It is optional. If not set, then regex is
used to validate final variable names.
/[A-Z][A-Z0-9_]*/
ignoreVariableNames Specifies one or more (comma-separated) variable names that
should be ignored (i.e., that should not cause a rule
violation). The names may optionally contain wildcards (*,?).
null