Skip to content

caseDuplicates

Reports switch statements with duplicate case clause test expressions.

✅ This rule is included in the ts logical and logicalStrict presets.

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.

AEfuncti5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0getStat1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53co7<2:sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#C5E478;--1:#3B61">B0numb1<1)sp ansty="le--0:#7FDBCA;--1:#096E">7<2:sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#C5E478;--1:#3B61">B0stri53< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEswit53 (code)< {d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEca5<3 sp ansty="le--0:#F78C6C;--1:#AA09">822<00sp ansty="le--0:#D6DEEB;--1:#403F">5<3:d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEretu5<3 sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4D1<1"sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEca5<3 sp ansty="le--0:#F78C6C;--1:#AA09">824<04sp ansty="le--0:#D6DEEB;--1:#403F">5<3:d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEretu5<3 sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4DNot Fou1<1"sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEca5<3 sp ansty="le--0:#F78C6C;--1:#AA09">822<00sp ansty="le--0:#D6DEEB;--1:#403F">5<3:d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEretu5<3 sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4DSucce1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<; sp ansty="le--0:#919F9F;--1:#5D63">76// This case will never be reach53< sp ansty="le--0:#D6DEEB;--1:#403F">5<3}d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>AEfuncti5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0handleInp1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53val7<2:sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#C5E478;--1:#3B61">B0stri1<1)sp ansty="le--0:#7FDBCA;--1:#096E">7<2:sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#C5E478;--1:#3B61">B0vo53< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEswit53 (value)< {d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEca5<3 sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dsta1<1"sp ansty="le--0:#D6DEEB;--1:#403F">5<3:d ivclassNa="meec-li">53 < sp ansty="le--0:#D6DEEB;--1:#403F">53consoAB0l5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4DStarting proce1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEbre5<3;d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEca5<3 sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dst1<1"sp ansty="le--0:#D6DEEB;--1:#403F">5<3:d ivclassNa="meec-li">53 < sp ansty="le--0:#D6DEEB;--1:#403F">53consoAB0l5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4DStopping proce1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEbre5<3;d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEca5<3 sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dsta1<1"sp ansty="le--0:#D6DEEB;--1:#403F">5<3:d ivclassNa="meec-li">53 < sp ansty="le--0:#D6DEEB;--1:#403F">53consoAB0l5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4DBegin operati1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53)<; sp ansty="le--0:#919F9F;--1:#5D63">76// This case will never be reachnt < sp ansty="le--0:#C792EA;--1:#8844">AEbre5<3;d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">5<3}d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>
44AEfunc361B0getSt1<111( spans="tyle--0:#D7DBE0;--1:#40">3F536361B0nu1<111) spans="tyle--0:#7FDBCA;--1:#09">6361B0st3F<53 {divclass="Nameec-">de44AEsw3F53 (coddent< spans="tyle--0:#C792EA;--1:#88">44AE3098<2200 spans="tyle--0:#D6DEEB;--1:#40">3dent < spans="tyle--0:#C792EA;--1:#88">44AEre31<111" spans="tyle--0:#ECC48D;--1:#98">4E<4DOK spans="tyle--0:#D9F5DD;--1:#11">1<111" spans="tyle--0:#D6DEEB;--1:#40">3dent< spans="tyle--0:#C792EA;--1:#88">44AE3098<2201 spans="tyle--0:#D6DEEB;--1:#40">3dent < spans="tyle--0:#C792EA;--1:#88">44AEre31<111" spans="tyle--0:#ECC48D;--1:#98">4E4DCre1<111" spans="tyle--0:#D6DEEB;--1:#40">3dent< spans="tyle--0:#C792EA;--1:#88">44AE3098<2404 spans="tyle--0:#D6DEEB;--1:#40">3dent < spans="tyle--0:#C792EA;--1:#88">44AEre31<111" spans="tyle--0:#ECC48D;--1:#98">4E4DNot F1<111" spans="tyle--0:#D6DEEB;--1:#40">33F<53 spans="tyle--0:#D6DEEB;--1:#40">33< }><}di vdivclass="Nameexpressive-">44AEfunc361B0handleI1<111( spans="tyle--0:#D7DBE0;--1:#40">3F53v6361B0st1<111) spans="tyle--0:#7FDBCA;--1:#09">6361B03F<53 {divclass="Nameec-">de44AEsw3F53 (valudent< spans="tyle--0:#C792EA;--1:#88">44AE31<111" spans="tyle--0:#ECC48D;--1:#98">4E4Ds1<111" spans="tyle--0:#D6DEEB;--1:#40">33F53 < spans="tyle--0:#D6DEEB;--1:#40">3F53con4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B<0log spans="tyle--0:#D6DEEB;--1:#40">31<111" spans="tyle--0:#ECC48D;--1:#98">4E4DStarting pro1<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Nameec-">dent < spans="tyle--0:#C792EA;--1:#88">44AEb3dent< spans="tyle--0:#C792EA;--1:#88">44AE31<111" spans="tyle--0:#ECC48D;--1:#98">4E4D1<111" spans="tyle--0:#D6DEEB;--1:#40">33F53 < spans="tyle--0:#D6DEEB;--1:#40">3F53con4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B<0log spans="tyle--0:#D6DEEB;--1:#40">31<111" spans="tyle--0:#ECC48D;--1:#98">4E4DStopping pro1<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Nameec-">dent < spans="tyle--0:#C792EA;--1:#88">44AEb3dent< spans="tyle--0:#C792EA;--1:#88">44AE31<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dres1<111" spans="tyle--0:#D6DEEB;--1:#40">33F53 < spans="tyle--0:#D6DEEB;--1:#40">3F53con4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B<0log spans="tyle--0:#D6DEEB;--1:#40">31<111" spans="tyle--0:#ECC48D;--1:#98">4E4DRestarting pro1<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Nameec-">dent < spans="tyle--0:#C792EA;--1:#88">44AEb33F<53 spans="tyle--0:#D6DEEB;--1:#40">33< }>

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.