$CASE(...) with no default case

objectscriptQuality release 
1.0.0
Id 
OS0047
Rule type 
Code Smell
Severity 

Major

Major
SQALE characteristic 
  • Reliability
    • Instruction
Tags 
clarity, coding-guidelines
Remediation function 
Constant/issue
Remediation cost 
15min

The $CASE function can be written without a default case, as in:

    set x = $case(someVar, "foo": val1, "bar": val2)

However, this means that if, in the above example, the value of x is neither "foo" nor "bar", the resulting value will be undefined.

While it can happen that the tested variable only has a certain set of possible values, it is preferred to always have a default case; for instance:

    set x = $case(someVar, "foo": val1, "bar": val2, : val3)

This issue may lead to false positives if the set of possible values is indeed limited; such a scenario is not detected.