Skip to content

numericLiteralParsing

Reports parseInt calls with binary, hexadecimal, or octal strings that can be replaced with numeric literals.

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

Binary, octal, and hexadecimal numeric literals provide a more readable and direct way to represent numbers in those bases compared to using parseInt() or Number.parseInt() with a radix argument. Instead of parsing a string representation at runtime, you can use the native literal syntax (0b for binary, 0o for octal, 0x for hexadecimal) which is clearer and more performant.

AEconsB0binaAE <= sp ansty="le--0:#82AAFF;--1:#3B61">B0parseI5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4D1111101<11sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#C792EA;--1:#8844">AE<, sp ansty="le--0:#F78C6C;--1:#AA09">8<22sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>AEconsB0octAE <= sp ansty="le--0:#82AAFF;--1:#3B61">B0parseI5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4D7<67sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#C792EA;--1:#8844">AE<, sp ansty="le--0:#F78C6C;--1:#AA09">8<28sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>AEconsB0hAE <= sp ansty="le--0:#82AAFF;--1:#3B61">B0parseI5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4D11<1"sp ansty="le--0:#C792EA;--1:#8844">AE<, sp ansty="le--0:#F78C6C;--1:#AA09">82<16sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>AEconsB0valAE <= sp ansty="le--0:#D6DEEB;--1:#403F">53NumbAB0parseI5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4D1<1"sp ansty="le--0:#C792EA;--1:#8844">AE<, sp ansty="le--0:#F78C6C;--1:#AA09">82<16sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>
44AEco61B0bi44A09820b11111<0111 spans="tyle--0:#D6DEEB;--1:#40">3<111><;di vdivclass="Nameexpressive-">44AEco61B0o44A098203<767><;di vdivclass="Nameexpressive-">44AEco61B<0hex spans="tyle--0:#C792EA;--1:#88">44A098203<1f7><;di vdivclass="Nameexpressive-">44AEco61B0v44A0982<0xff spans="tyle--0:#D6DEEB;--1:#40">3

This rule is not configurable.

If your project heavily deals with literals and you want to be consistent with their parsing, this rule might not be useful for you.