Skip to content

no-duplicate-case

Reports an arm of a switch, match, when or case whose test is the same as the test of an earlier arm of the same statement (case 1: twice). The second arm is reported, the first is shown as related.

Only the first arm with that test can run, so the second is dead code. It is usually a copy that should have had another value, and the case it was meant for is then unhandled.

To fix, change the test to the value it was meant for, or merge the two arms.

Reported
switch (a) { case 1: break; case 1: break; case "x": break; case 'x': break; case b + 1: break; case b+1: break; default: }
...
c:
lint:
rules:
no-duplicate-case: warn # off, warn (default), error
cpp:
lint:
rules:
no-duplicate-case: warn # off, warn (default), error
csharp:
lint:
rules:
no-duplicate-case: warn # off, warn (default), error
java:
lint:
rules:
no-duplicate-case: warn # off, warn (default), error
js:
lint:
rules:
no-duplicate-case: warn # off, warn (default), error
kotlin:
lint:
rules:
no-duplicate-case: warn # off, warn (default), error
php:
lint:
rules:
no-duplicate-case: warn # off, warn (default), error
python:
lint:
rules:
no-duplicate-case: warn # off, warn (default), error
ruby:
lint:
rules:
no-duplicate-case: warn # off, warn (default), error
sql:
lint:
rules:
no-duplicate-case: warn # off, warn (default), error

Enabled by the presets: js/eslint-recommended, js/biome-recommended, js/oxlint.

Suppress one line with sudsy-disable-next-line no-duplicate-case in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
eslint no-duplicate-case full