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 = 0XUnexpected number literal prefix in uppercase.FF;
const color = 0xff8800Unexpected hexadecimal digits in lowercase.;
const flags = 0BUnexpected number literal prefix in uppercase.1010;
const mode = 0OUnexpected number literal prefix in uppercase.755;
const big = 1.5EUnexpected exponential notation in uppercase.9;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.