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.
Examples
Section titled “Examples”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; }}
function getStatus(code: number): string { switch (code) { case 200: return "OK"; case 201: return "Created"; case 404: return "Not Found"; }}
function handleInput(value: string): void { switch (value) { case "start": console.log("Starting process"); break; case "stop": console.log("Stopping process"); break; case "restart": console.log("Restarting process"); break; }}
Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noDuplicateCase
- Deno:
no-duplicate-case
- ESLint:
no-duplicate-case
- Oxlint:
eslint/no-duplicate-case
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.