No Numeric Literals
Use parseInt() with an explicit base instead of binary, octal, or hexadecimal literals because parseInt() makes the base visible at the call site.
Summary
The no-numeric-literals rule reports any numeric literal that uses a binary (0b), octal (0o), or hexadecimal (0x) prefix.
Regular decimal literals are not affected.
Why Use This Rule?
parseInt('FF', 16)makes the base explicit at the call site — no need to remember prefix conventions.- Keeps all non-decimal numbers in a consistent
parseInt()form. - Pairs with the
radixrule that requires the base argument inparseInt().
Examples
Configuration
Options
warning
ignoreFiles is an escape hatch for files where this rule genuinely does not apply. It is not intended for routine use.
| Option | Type | Default | Description |
|---|---|---|---|
allowBinary | boolean | false | Allow binary literals. |
allowHex | boolean | false | Allow hexadecimal literals. |
allowOctal | boolean | false | Allow octal literals. |
ignoreFiles | string[] | [] | File patterns to skip. |
Autofix
Autofix is not available for this rule. Flagged code must be updated manually.
Troubleshooting
- Decimal numbers are not flagged — Only
0b,0o, and0xprefixed literals are banned. Regular decimals like42and3.14are fine. parseIntwithout radix — Pair this rule with the built-inradixrule to ensureparseInt()always receives an explicit base argument.