Skip to content

returnAssignments

Reports using assignment expressions in return statements.

✅ This rule is included in the ts stylistic and stylisticStrict presets.

Using assignments in return statements can make code harder to read and can lead to confusion about whether the assignment or the returned value is the primary intent. Assignment expressions return the assigned value, but mixing assignment with return makes the control flow less clear.

AEfuncti5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0getVal11<()sp ansty="le--0:#D6DEEB;--1:#403F">53< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEle53valunt< sp ansty="le--0:#C792EA;--1:#8844">AEretu53 (valuA5<3 sp ansty="le--0:#F78C6C;--1:#AA09">8<21sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>AEfuncti5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0proce11<()sp ansty="le--0:#D6DEEB;--1:#403F">53< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEle53resulnt< sp ansty="le--0:#C792EA;--1:#8844">AEretu53 (resulA5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0calcula53()<);d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>AEconsB0arrAE <= sp ansty="le--0:#D9F5DD;--1:#1111">11<()sp ansty="le--0:#C792EA;--1:#8844">AE =<> sp ansty="le--0:#D6DEEB;--1:#403F">53(val sp>AE <= sp ansty="le--0:#F78C6C;--1:#AA09">82<42sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>AEfuncti5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0compou11<()sp ansty="le--0:#D6DEEB;--1:#403F">53< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEle53counnt< sp ansty="le--0:#C792EA;--1:#8844">AEretu53 (counAE<+=sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#F78C6C;--1:#AA09">8<25sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>
44AEfunc361B0getV11<11() spans="tyle--0:#D6DEEB;--1:#40">3F<53 {divclass="Nameec-">de44AE3F53v44A0<9821 spans="tyle--0:#D6DEEB;--1:#40">3de44AEre3F53 va3<}di vdivclass="Nameexpressive-">44AEfunc361B0pro11<11() spans="tyle--0:#D6DEEB;--1:#40">3F<53 {divclass="Nameec-">de44AE3F53re44A61B0calcu3F5<3() ;divclass="Nameec-">de44AEre3F53 res3<}di vdivclass="Nameexpressive-">44AEco61B0a44A11<11() spans="tyle--0:#C792EA;--1:#88">44AE <=> {divclass="Nameec-">4444AEco61B0v44A09<8242 spans="tyle--0:#C792EA;--1:#88">4 ><4AE ;divclass="Nameec-">4444AEret3F53v4<4AE ;divclass="Nameec-">4<4AE} spans="tyle--0:#D6DEEB;--1:#40">3<;}><;di vdivclass="Nameexpressive-">44AEfunc361B0comp11<11() spans="tyle--0:#D6DEEB;--1:#40">3F<53 {divclass="Nameec-">de44AE3F53c44A0<9820 spans="tyle--0:#D6DEEB;--1:#40">33F<53 spans="tyle--0:#D6DEEB;--1:#40">3F53co4430<9825 spans="tyle--0:#D6DEEB;--1:#40">3de44AEre3F53 co3

This rule is not configurable.

If your codebase uses assignments in return statements as a common idiom and you find them readable, you might choose to disable this rule. However, separating assignments from return statements generally improves code clarity and reduces potential for confusion.