no-duplicate-case
C / C++C / C++C#JavaJavaScript / TypeScriptKotlinPHPPythonRubySQLsuspiciousno fixdefault: warnjs/eslint-recommendedjs/biome-recommendedjs/oxlint
What it does
Section titled “What it does”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.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”switch (a) { case 1: break; case 1: break; case "x": break; case 'x': break; case b + 1: break; case b+1: break; default: }...Configuration
Section titled “Configuration”c: lint: rules: no-duplicate-case: warn # off, warn (default), errorcpp: lint: rules: no-duplicate-case: warn # off, warn (default), errorcsharp: lint: rules: no-duplicate-case: warn # off, warn (default), errorjava: lint: rules: no-duplicate-case: warn # off, warn (default), errorjs: lint: rules: no-duplicate-case: warn # off, warn (default), errorkotlin: lint: rules: no-duplicate-case: warn # off, warn (default), errorphp: lint: rules: no-duplicate-case: warn # off, warn (default), errorpython: lint: rules: no-duplicate-case: warn # off, warn (default), errorruby: lint: rules: no-duplicate-case: warn # off, warn (default), errorsql: lint: rules: no-duplicate-case: warn # off, warn (default), errorEnabled 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.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| eslint | no-duplicate-case |
full |