You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The comma operator (,) evaluates its operands, from left to right, and returns the second one. That's useful in some situations, but just wrong in a switchcase. You may think you're compactly handling multiple values in the case, but only the last one in the comma-list will ever be handled. The rest will fall through to the default.
Similarly, the logical OR operator (||) will not work in a switchcase, only the first argument will be considered at execution time.
Noncompliant Code Example
switcha{case1,2: // Noncompliant; only 2 is ever handled by this casedoTheThing(a);case3||4: // Noncompliant; only '3' is handleddoThatThing(a);
case 5:
doTheOtherThing(a);
default:
console.log("Neener, neener!");// this happens when a==1 or a == 4}
Compliant Solution
switcha{
case 1:
case 2:
doTheThing(a);
case 3:
case 4:
doThatThing(a);
case 5:
doTheOtherThing(a);
default:
console.log("Neener, neener!");}
The comma operator (
,
) evaluates its operands, from left to right, and returns the second one. That's useful in some situations, but just wrong in aswitch
case
. You may think you're compactly handling multiple values in the case, but only the last one in the comma-list will ever be handled. The rest will fall through to the default.Similarly, the logical OR operator (
||
) will not work in aswitch
case
, only the first argument will be considered at execution time.Noncompliant Code Example
Compliant Solution
wazuh-api/helpers/logger.js
Lines 41 to 59 in 7cd5ef1
The text was updated successfully, but these errors were encountered: