unicorn/number-literal-case

Require lowercase prefixes and exponents, and uppercase hexadecimal digits, in numbers

fixable

0XFF, 0xff and 0xFF are the same number. This rule picks one spelling: a lowercase 0x, 0b, 0o or e, and uppercase hexadecimal digits. That way the prefix stands out from the digits.

--fix rewrites the number.

Configure#

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"unicorn/number-literal-case" = "error" # or "warn"

Examples#

example.js5 problems
const mask = 0XFF;
const color = 0xff8800;
const flags = 0B1010;
const mode = 0O755;
const big = 1.5E9;
example.jsNo problems
const mask = 0xFF;
const color = 0xFF8800;
const flags = 0b1010;
const mode = 0o755;
const big = 1.5e9;

The n at the end of a BigInt stays lowercase:

example.jsNo problems
const id = 0xABCDEFn;

When not to use it#

Some formatters, such as Prettier, write hexadecimal digits in lowercase. If yours does, the two undo each other's work, so turn this rule off.