Naming convention checks

CC4M has several checks on the casing of names of certain aspects in the code. There is a separate check for each aspect, which means that every casing check can have their own parameter values.

Code aspect name checkedName of the checkExemption tagNote
VariablescheckVariableCasing%@ok<CVARI>
User-defined functionscheckUserDefinedFunctionCasing%@ok<CUDFU>1
Structure fieldscheckStructFieldCasing%@ok<CSFIE>2
MethodscheckMethodCasing%@ok<CMETH>3
Name-value pairs in arguments blockscheckNameValuePairCasing%@ok<CNVPC>4
ClassescheckClassCasing%@ok<CCLAS>
Class propertiescheckPropertyCasing%@ok<CPROP>
PackagescheckPackageCasing%@ok<CPACK>
EventscheckEventCasing%@ok<CEVEN>
Enumeration memberscheckEnumMemberCasing%@ok<CENME>
Constant propertiescheckNamedConstantCasing-5
1

checkUserDefinedFunctionCasing only checks the names of user-defined functions that are not methods. The names of methods are checked elsewhere. Furthermore, when this check is used in combination with checkFunctionPrefix, prefixes are subtracted before checking if the functions are cased according to the configured values.

2

the checkStructFieldCasing check suffers from the same limitation as checkStructFieldNaming: casing of dynamically assigned field names will not be checked.

3

checkMethodCasing does not report declarations of methods that are incorrectly cased if their functionality is specified in a separate function file. Additionally, getter and setter methods are ignored in this check, because their names are derived from property names that have a separate check. Constructor names are ignored during this check because they are named after the class. Finally, methods that overload a method of a superclass, are not checked here because those method names are not defined by the checked classdef file. Note, if a superclass has its own superclass(es), this is not taken into account.

4

The arguments block was introduced in MATLAB R2019b.

5

Constant properties may be subject to different casing rules. This is made available with checkNamedConstantCasing. This casing check behaves different from the other casing checks:

  • Constant properties are not required to be cased as specified in the parameters of the check on named constant casing. They are still allowed to be cased like any other property.
  • The check does not have its own results table in the report.
  • When this check is enabled and a constant property does not satisfy the coding standards of regular properties or those of constant properties, the property is listed in the results table of checkPropertyCasing.

Configurable parameters

The parameters for each of the casing checks are:

  • Casing (string): Sets the type of casing that needs to be checked. This value can be either UpperCamelCasing, lowerCamelCasing, snake_casing, SCREAMING_SNAKE_CASING or lowercasing.

  • MaxConsecUpper (double): The allowed maximum number of upper case characters in a row. This value can be increased to allow acronyms in upper case. The value must be between 0 and 50.

  • MaxConsecLower (double): The allowed maximum number of lower case characters in a row. This value can be decreased to be able to detect names that lack upper case characters where needed. The value must be between 0 and 50.

  • AllowNumbers (boolean): Set this to true to allow numbers in the name.

These parameters combined are used to check the casing of names as follows:

  • UpperCamelCasing: One or more repetitions of: between one and MaxConsecUpper upper case characters followed by between one and MaxConsecLower lower case characters. The name is allowed to end with upper case characters. Only letters are allowed. If AllowNumbers is true, any number of numbers is allowed in the name.

  • lowerCamelCasing: Between one and MaxConsecLower lower case characters in a row followed by one or more repetitions of: between one and MaxConsecUpper upper case characters followed by between one and MaxConsecLower lower case characters. The variable name is allowed to end with upper case characters. Only letters are allowed. If AllowNumbers is true, any number of numbers is allowed in the name.

  • snake_casing: Starts with between one and MaxConsecLower lower case characters followed by one or more repetitions of: an underscore followed by between one and MaxConsecLower lower case characters. If AllowNumbers is true, any number of numerical characters is allowed. Note: this does not allow a name to end in an underscore, and it does not allow for multiple consecutive underscores.

  • SCREAMING_SNAKE_CASING: Starts with between one and MaxConsecUpper upper case characters followed by one or more repititions of: an underscore followed by between one and more MaxConsecUpper upper case characters. If AllowNumbers is true, any number of numerical characters is allowed. Note: this does not allow a name to end in an underscore, and it does not allow for multiple consecutive underscores.

  • lowercasing: Can only contain lower case characters (so no underscores) and -optionally- numbers.

Upon a rule violation, the casing checks provide the same information as the other checks do: A path to the checked file, the part of the code violating the coding standards, the scope (if appliccable), and a feedback message.

Other checks