Skip to content

unicorn/number-literal-case Style

🛠️ An auto-fix is available for this rule.

What it does

This rule enforces proper case for numeric literals.

Why is this bad?

When both an identifier and a number literal are in lower case, it can be hard to differentiate between them.

Examples

Examples of incorrect code for this rule:

javascript
const foo = 0XFF;
const foo = 0xff;
const foo = 0Xff;
const foo = 0Xffn;

const foo = 0B10;
const foo = 0B10n;

const foo = 0O76;
const foo = 0O76n;

const foo = 2E-5;

Examples of correct code for this rule:

javascript
const foo = 0xFF;
const foo = 0b10;
const foo = 0o76;
const foo = 0xFFn;
const foo = 2e+5;

How to use

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "unicorn/number-literal-case": "error"
  }
}
bash
oxlint --deny unicorn/number-literal-case

References

Released under the MIT License.