Skip to content

caseDuplicates

Reports switch statements with duplicate case clause test expressions.

✅ This rule is included in the ts logical preset.

Duplicate case clauses in a switch statement represent a logic error where the second occurrence of a case will never be executed. When multiple case clauses have identical test expressions, only the first matching case is executed, making subsequent duplicates unreachable code. This typically indicates a copy-paste error or incomplete refactoring.

function getStatus(code: number): string {
switch (code) {
case 200:
return "OK";
case 404:
return "Not Found";
case 200:
return "Success"; // This case will never be reached
}
}
function handleInput(value: string): void {
switch (value) {
case "start":
console.log("Starting process");
break;
case "stop":
console.log("Stopping process");
break;
case "start":
console.log("Begin operation"); // This case will never be reached
break;
}
}

This rule is not configurable.

If your project uses control flow structures that create confusing side effects, such as dynamic getters that modify state, you might not be able to enable this rule. Consider refactoring to more predictable control flow structures.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.