Reports lexical declarations in case clauses without wrapping them in blocks.
✅ This rule is included in the ts javascript presets.
Lexical declarations (let, const, function, class) in case and default clauses are scoped to the entire switch statement block, not just to the individual clause where they appear.
This can lead to unexpected behavior when multiple clauses attempt to declare variables with the same name, resulting in syntax errors or unintended variable shadowing.
Wrapping the contents of case clauses in curly braces creates a proper block scope, preventing these issues.
AEfuncti5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0processVal3 sp>1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53val1(sp>7<2:sp ansty="le--0:#D6DEEB;--1:#403F">52:sp><3 sp ansty="le--0:#C5E478;--1:#3B61">B0numb3 sp>1<1)sp ansty="le--0:#7FDBCA;--1:#096E">71)sp><2:sp ansty="le--0:#D6DEEB;--1:#403F">52:sp><3 sp ansty="le--0:#C5E478;--1:#3B61">B0stri3 sp>53< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEswit sp>53 (value) {d>< {d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEca sp>5<3 sp ansty="le--0:#F78C6C;--1:#AA09">83 sp><21sp ansty="le--0:#D6DEEB;--1:#403F">521sp> {d><3:d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEle sp>53resuAE <= sp ansty="le--0:#D9F5DD;--1:#1111">1= sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Do1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">51"sp>3:d><3;d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEretu sp>53 resul3;d>nt < sp ansty="le--0:#C792EA;--1:#8844">AEca sp>5<3 sp ansty="le--0:#F78C6C;--1:#AA09">83 sp><22sp ansty="le--0:#D6DEEB;--1:#403F">522sp><3:d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEle sp>53resuAE <= sp ansty="le--0:#D9F5DD;--1:#1111">1= sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Dt1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">51"sp>3:d><3;d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEretu sp>53 resul3;d>nt < sp ansty="le--0:#C792EA;--1:#8844">AEdefau sp>5<3:d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEle sp>53resuAE <= sp ansty="le--0:#D9F5DD;--1:#1111">1= sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Doth1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">51"sp>3:d><3;d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEretu sp>53 resul3;d>53< sp ansty="le--0:#D6DEEB;--1:#403F">5 sp><3}d ivclassNa="meec-li">53}d><3}d ivclassNa="meec-li">d3}d>AEfuncti5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0handleTy3 sp>1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53ty1(sp>7<2:sp ansty="le--0:#D6DEEB;--1:#403F">52:sp><3 sp ansty="le--0:#C5E478;--1:#3B61">B0stri3 sp>1<1)sp ansty="le--0:#7FDBCA;--1:#096E">71)sp><2:sp ansty="le--0:#D6DEEB;--1:#403F">52:sp><3 sp ansty="le--0:#C5E478;--1:#3B61">B0vo3 sp>53< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEswit sp>53 (type) {d>< {d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEca sp>5<3 sp ansty="le--0:#D9F5DD;--1:#1111">13 sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Dus1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">51"sp> {d><3:d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEcons sp>B0daAE <= sp ansty="le--0:#82AAFF;--1:#3B61">B0fetchUserDa= sp>53(3:d><);d ivclassNa="meec-li">nt < sp ansty="le--0:#82AAFF;--1:#3B61">B0processDa sp>53(data);d><);d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEbre sp>5);d><3;d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEca sp>5<3 sp ansty="le--0:#D9F5DD;--1:#1111">13 sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Dadm1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">51"sp>3;d><3:d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEcons sp>B0daAE <= sp ansty="le--0:#82AAFF;--1:#3B61">B0fetchAdminDa= sp>53(3:d><);d ivclassNa="meec-li">nt < sp ansty="le--0:#82AAFF;--1:#3B61">B0processDa sp>53(data);d><);d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEbre sp>5);d><3;d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">5 sp>3;d><3}d ivclassNa="meec-li">53}d><3}d ivclassNa="meco"><}d>}d>3}d> 44AEfunc361B0processV1<111( spans="tyle--0:#D7DBE0;--1:#40">3F53v111(>6361B0nu1<111) spans="tyle--0:#7FDBCA;--1:#09">6111)>361B0st3F<53 {divclass="Nameec-">de44AEsw3F53 (valu53 >dent< spans="tyle--0:#C792EA;--1:#88">44AE >30<9821 spans="tyle--0:#D6DEEB;--1:#40">3F59821><3: {divclass="Nameec-">dent < spans="tyle--0:#C792EA;--1:#88">44AE >3F53re44A1<111" spans="tyle--0:#ECC48D;--1:#98">4E4111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3111">3: >dent < spans="tyle--0:#C792EA;--1:#88">44AEre >3F53 res3F53< spans="tyle--0:#D6DEEB;--1:#40">3 >dent< spans="tyle--0:#C792EA;--1:#88">44AE >30<9822 spans="tyle--0:#D6DEEB;--1:#40">3F59822><3: {divclass="Nameec-">dent < spans="tyle--0:#C792EA;--1:#88">44AE >3F53re44A1<111" spans="tyle--0:#ECC48D;--1:#98">4E4111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3111">3: >dent < spans="tyle--0:#C792EA;--1:#88">44AEre >3F53 res3F53< spans="tyle--0:#D6DEEB;--1:#40">3 >dent< spans="tyle--0:#C792EA;--1:#88">44AEdef >3F5<3: {divclass="Nameec-">dent < spans="tyle--0:#C792EA;--1:#88">44AE >3F53re44A1<111" spans="tyle--0:#ECC48D;--1:#98">4E4Do111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3111">3: >dent < spans="tyle--0:#C792EA;--1:#88">44AEre >3F53 res3F53< spans="tyle--0:#D6DEEB;--1:#40">3 >3F<53 spans="tyle--0:#D6DEEB;--1:#40">353 >3c44AEfunc361B0handle1<111( spans="tyle--0:#D7DBE0;--1:#40">3F53111(>6361B0st1<111) spans="tyle--0:#7FDBCA;--1:#09">6111)>361B03F<53 {divclass="Nameec-">de44AEsw3F53 (typ53 >dent< spans="tyle--0:#C792EA;--1:#88">44AE >31<111" spans="tyle--0:#ECC48D;--1:#98">4E4D111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F5111"><3: {divclass="Nameec-">dent < spans="tyle--0:#C792EA;--1:#88">44AEco >61B044A61B0fetchUser3F53: ><3() ;divclass="Nameec-">dent < spans="tyle--0:#82AAFF;--1:#3B">61B0process >3F53(da3()>dent < spans="tyle--0:#C792EA;--1:#88">44AEb >33F53< spans="tyle--0:#D6DEEB;--1:#40">3 >dent< spans="tyle--0:#C792EA;--1:#88">44AE >31<111" spans="tyle--0:#ECC48D;--1:#98">4E4Da111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F5111"><3: {divclass="Nameec-">dent < spans="tyle--0:#C792EA;--1:#88">44AEco >61B044A61B0fetchAdmin3F53: ><3() ;divclass="Nameec-">dent < spans="tyle--0:#82AAFF;--1:#3B">61B0process >3F53(da3()>dent < spans="tyle--0:#C792EA;--1:#88">44AEb >33F53< spans="tyle--0:#D6DEEB;--1:#40">3 >3F<53 spans="tyle--0:#D6DEEB;--1:#40">353 >3< }> }>
This rule is not configurable.
If you are certain that you will never have variable name conflicts between case clauses and you understand the scoping implications, you might choose to disable this rule.
However, using block scopes in case clauses is a best practice that prevents potential bugs and makes the code’s intent clearer.