Hello,
Given the example:
"foo" match {
case bar if bar.isEmpty => bar
case _ => "empty"
}
Scalastyle will complain that the case statement identifier bar is lowercase and should therefore be either:
- uppercased (which violates http://docs.scala-lang.org/style/naming-conventions.html - variable names should be in lower camel case),
- replaced with _ (which cannot be done due to the conditional comparison),
- explicitly typed as Any (which causes the conditional comparison to fail at compile time)
Therefore I think that the documentation should be updated to explicitly state that uppercase should only be used for stable identifiers that are constants and that the type used to strongly type the variable with should be the type of the input value to avoid breaking conditionals.
In addition, my understanding of the issue around lowercase pattern matches purely revolves around avoiding suspicious shadowing of stable identifiers in the outer scope, which is recommended to be avoided by either using backticks for variables or uppercase for constants - see
http://www.scala-lang.org/files/archive/spec/2.11/08-pattern-matching.html. Therefore should this checker just check that the variable name doesn't shadow an outer scope variable and allow untyped lowercase variables? Or is there another source of potential confusion that I am missing?