Reports incorrect Error subclass definitions that don't follow best practices.
✅ This rule is included in the ts logicalStrict presets.
When creating custom error classes that extend Error, there are several conventions that should be followed to ensure the errors work correctly and are easy to debug.
This rule reports:
- Invalid class names: should be capitalized and end with
Error
- Missing
name property: required for proper error identification
- Using
this.constructor.name: won’t work after minification
- Mismatched
name values: should match the class name
- Redundant
this.message assignments: already set by super()
AEcla5<3 sp ansty="le--0:#FFCB8B;--1:#1111">11f3 sp>5<3 sp ansty="le--0:#C792EA;--1:#8844">AEexten3 sp>5<3 sp ansty="le--0:#C5E478;--1:#3B61">B0Err3 sp>53< {d ivclassNa="meec-li">nt< sp ansty="le--0:#82AAFF;--1:#3B61">B0construct sp>1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53messa1(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:#D6DEEB;--1:#403F">531)sp> {d>< {d ivclassNa="meec-li">nt < sp ansty="le--0:#7FDBCA;--1:#096E">72sup sp>53(message {d><);d ivclassNa="meec-li">nt < sp ansty="le--0:#7FDBCA;--1:#096E">72th sp>A72na5<3 sp ansty="le--0:#C792EA;--1:#8844">A3 sp>5<3 sp ansty="le--0:#D9F5DD;--1:#1111">13 sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Df1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">51"sp>);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> 44AEc31111FooE344AEext361B0E3F<53 {divclass="Nameec-">de61B0constru1<111( spans="tyle--0:#D7DBE0;--1:#40">3F53mes111(>6361B0st1<111) spans="tyle--0:#D6DEEB;--1:#40">3F111)>53 ><53 {divclass="Nameec-">dent< spans="tyle--0:#7FDBCA;--1:#09">6E72s >3F53(messa53 >dent< spans="tyle--0:#7FDBCA;--1:#09">6E72 >4<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E724AE.>34<4AE= spans="tyle--0:#D6DEEB;--1:#40">34AE=>1<111" spans="tyle--0:#ECC48D;--1:#98">4E4DFooE111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3111">3F<53 spans="tyle--0:#D6DEEB;--1:#40">353 >3< }> }>
AEcla5<3 sp ansty="le--0:#FFCB8B;--1:#1111">11CustomErr3 sp>5<3 sp ansty="le--0:#C792EA;--1:#8844">AEexten3 sp>5<3 sp ansty="le--0:#C5E478;--1:#3B61">B0Err3 sp>53< {d ivclassNa="meec-li">nt< sp ansty="le--0:#82AAFF;--1:#3B61">B0construct sp>1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53messa1(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:#D6DEEB;--1:#403F">531)sp> {d>< {d ivclassNa="meec-li">nt < sp ansty="le--0:#7FDBCA;--1:#096E">72sup sp>53(message {d><);d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">5 sp>);d><3}d ivclassNa="meec-li">53}d><3}d ivclassNa="meco"><}d>}d>3}d> 44AEc31111CustomE344AEext361B0E3F<53 {divclass="Nameec-">de61B0constru1<111( spans="tyle--0:#D7DBE0;--1:#40">3F53mes111(>6361B0st1<111) spans="tyle--0:#D6DEEB;--1:#40">3F111)>53 ><53 {divclass="Nameec-">dent< spans="tyle--0:#7FDBCA;--1:#09">6E72s >3F53(messa53 >dent< spans="tyle--0:#7FDBCA;--1:#09">6E72 >4<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E724AE.>34<4AE= spans="tyle--0:#D6DEEB;--1:#40">34AE=>1<111" spans="tyle--0:#ECC48D;--1:#98">4E4DCustomE111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3111">3F<53 spans="tyle--0:#D6DEEB;--1:#40">353 >3< }> }>
AEcla5<3 sp ansty="le--0:#FFCB8B;--1:#1111">11CustomErr3 sp>5<3 sp ansty="le--0:#C792EA;--1:#8844">AEexten3 sp>5<3 sp ansty="le--0:#C5E478;--1:#3B61">B0Err3 sp>53< {d ivclassNa="meec-li">nt< sp ansty="le--0:#82AAFF;--1:#3B61">B0construct sp>1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53messa1(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:#D6DEEB;--1:#403F">531)sp> {d>< {d ivclassNa="meec-li">nt < sp ansty="le--0:#7FDBCA;--1:#096E">72sup sp>53(message {d><);d ivclassNa="meec-li">nt < sp ansty="le--0:#7FDBCA;--1:#096E">72th sp>A72na5<3 sp ansty="le--0:#C792EA;--1:#8844">A3 sp>5<3 sp ansty="le--0:#7FDBCA;--1:#096E">72th3 sp>A72constructA72na5);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> 44AEc31111CustomE344AEext361B0E3F<53 {divclass="Nameec-">de61B0constru1<111( spans="tyle--0:#D7DBE0;--1:#40">3F53mes111(>6361B0st1<111) spans="tyle--0:#D6DEEB;--1:#40">3F111)>53 ><53 {divclass="Nameec-">dent< spans="tyle--0:#7FDBCA;--1:#09">6E72s >3F53(messa53 >dent< spans="tyle--0:#7FDBCA;--1:#09">6E72 >4<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E724AE.>34<4AE= spans="tyle--0:#D6DEEB;--1:#40">34AE=>1<111" spans="tyle--0:#ECC48D;--1:#98">4E4DCustomE111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3111">3F<53 spans="tyle--0:#D6DEEB;--1:#40">353 >3< }> }>
AEcla5<3 sp ansty="le--0:#FFCB8B;--1:#1111">11CustomErr3 sp>5<3 sp ansty="le--0:#C792EA;--1:#8844">AEexten3 sp>5<3 sp ansty="le--0:#C5E478;--1:#3B61">B0Err3 sp>53< {d ivclassNa="meec-li">nt< sp ansty="le--0:#82AAFF;--1:#3B61">B0construct sp>1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53messa1(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:#D6DEEB;--1:#403F">531)sp> {d>< {d ivclassNa="meec-li">nt < sp ansty="le--0:#7FDBCA;--1:#096E">72sup sp>53(message {d><);d ivclassNa="meec-li">nt < sp ansty="le--0:#7FDBCA;--1:#096E">72th sp>A72messa5<3 sp ansty="le--0:#C792EA;--1:#8844">A3 sp>53 messag);d>nt < sp ansty="le--0:#7FDBCA;--1:#096E">72th sp>A72na5<3 sp ansty="le--0:#C792EA;--1:#8844">A3 sp>5<3 sp ansty="le--0:#D9F5DD;--1:#1111">13 sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4DCustomErr1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">51"sp><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> 44AEc31111CustomE344AEext361B0E3F<53 {divclass="Nameec-">de61B0constru1<111( spans="tyle--0:#D7DBE0;--1:#40">3F53mes111(>6361B0st1<111) spans="tyle--0:#D6DEEB;--1:#40">3F111)>53 ><53 {divclass="Nameec-">dent< spans="tyle--0:#7FDBCA;--1:#09">6E72s >3F53(messa53 >dent< spans="tyle--0:#7FDBCA;--1:#09">6E72 >4<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E724AE.>34<4AE= spans="tyle--0:#D6DEEB;--1:#40">34AE=>1<111" spans="tyle--0:#ECC48D;--1:#98">4E4DCustomE111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3111">3F<53 spans="tyle--0:#D6DEEB;--1:#40">353 >3< }> }>
This rule is not configurable.
If you have a specific naming convention for errors that doesn’t follow the standard pattern, or if you’re working with legacy code that can’t be easily refactored, you may need to disable this rule.