Skip to main content

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?

  1. parseInt('FF', 16) makes the base explicit at the call site — no need to remember prefix conventions.
  2. Keeps all non-decimal numbers in a consistent parseInt() form.
  3. Pairs with the radix rule that requires the base argument in parseInt().

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.

OptionTypeDefaultDescription
allowBinarybooleanfalseAllow binary literals.
allowHexbooleanfalseAllow hexadecimal literals.
allowOctalbooleanfalseAllow octal literals.
ignoreFilesstring[][]File names to skip. Supports a leading-* suffix (*.test.ts), an exact path, or a trailing path segment; ** globs are not supported.

Autofix

Autofix is not available for this rule. Flagged code must be updated manually.

Troubleshooting

  • Decimal numbers are not flagged — Only 0b, 0o, and 0x prefixed literals are banned. Regular decimals like 42 and 3.14 are fine.
  • BigInt literals are not flagged — Non-decimal forms with a BigInt n suffix (e.g. 0xFFn, 0b1010n, 0o755n) are skipped because the rule only inspects numeric (non-BigInt) literals.
  • parseInt without radix — Pair this rule with the built-in radix rule to ensure parseInt() always receives an explicit base argument.