Constant name does not start with an upper-case letter
ID |
scala.maintainability.naming_constant |
Severity |
info |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Naming |
Language |
Scala |
Description
Reports a final val whose name begins with a lower-case letter. Scala names constants in UpperCamelCase; the rule accepts the UPPER_SNAKE_CASE form as well, since interoperating code commonly keeps it.
Rationale
A capitalised name is what tells the reader - and the pattern matcher - that the identifier is a fixed value rather than a local binding. In a case clause a lower-case identifier binds a new variable, so a lower-case constant used as a pattern silently matches everything instead of comparing against the constant, which is a defect the compiler does not report.
The following code illustrates the pattern detected by this rule:
object NamingConstant {
// FLAGGED: Constant name does not start with an upper-case letter
final val maxRetries = 3
}