π Enforce proper case for numeric literals.
πΌ This rule is enabled in the following configs: β
recommended, βοΈ unopinionated.
π§ This rule is automatically fixable by the --fix CLI option.
Differentiating the casing of the identifier and value clearly separates them and makes your code more readable.
- Lowercase radix identifier
0x0o0bforNumberandBigInt. - Uppercase or lowercase hexadecimal value for
NumberandBigInt. - Lowercase
efor exponential notation.
// β
const foo = 0XFF;
// β
const foo = 0xff;
// β
const foo = 0Xff;
// β
const foo = 0xFF;// β
const foo = 0Xffn;
// β
const foo = 0xFFn;// β
const foo = 0B10;
// β
const foo = 0b10;// β
const foo = 0B10n;
// β
const foo = 0b10n;// β
const foo = 0O76;
// β
const foo = 0o76;// β
const foo = 0O76n;
// β
const foo = 0o76n;// β
const foo = 2E-5;
// β
const foo = 2e-5;// β
const foo = 2E+5;
// β
const foo = 2e+5;// β
const foo = 2E5;
// β
const foo = 2e5;Type: object
Type: 'uppercase' | 'lowercase'
Default: 'uppercase'
Specify whether the hexadecimal number value (ABCDEF) should be in uppercase or lowercase.
Note: 0x is always lowercase and not controlled by this option to maintain readable code.
Example:
{
'unicorn/number-literal-case': [
'error',
{
hexadecimalValue: 'lowercase',
}
]
}// β
const foo = 0XFF;
const foo = 0xFF;
const foo = 0XFFn;
const foo = 0xFFn;
// β
const foo = 0xff;
const foo = 0xffn;