CodeQL documentation

Non-case label in switch statement

ID: js/label-in-switch
Kind: problem
Severity: warning
Precision: very-high
   - reliability
   - readability
Query suites:
   - javascript-security-and-quality.qls

Click to see the query in the CodeQL repository

JavaScript allows to freely mix case labels and ordinary statement labels in the body of a switch statement. However, this is confusing to read (especially if both kinds of labels have the same amount of indentation), and indeed most likely the result of a typo.


Examine the statement labels to see whether they were meant to be case labels. If not, consider wrapping them into a statement block and indent them to set them apart visually from the case labels.


In this example, the label case3 is most likely a typo for case 3 and should be fixed.

function f(x) {
	switch (x) {
	case 1:
	case 2:
		return true;
		return false;


  • Ecma International, ECMAScript Language Definition, 5.1 Edition, Section 12.11. ECMA, 2011.