Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/sindresorhus/eslint-plugin-unicorn/llms.txt

Use this file to discover all available pages before exploring further.

JavaScript allows _ as a numeric separator to improve readability of long numbers, but separators can be placed arbitrarily, which defeats the purpose. This rule enforces consistent grouping so that 1_000_000 is always written that way and never as 1_0000_00 or similar.
Recommendedrecommended · ☑️ unopinionated
Fixable🔧
Suggestions
By default the rule applies to decimal numbers with 5 or more digits, and always applies to binary, octal, and hexadecimal literals regardless of length.
// Wrong group sizes (decimal)
const foo = 1_23_4444;

// Fractional part not grouped correctly
const bar = 1_234.56789;

// Hex digits not in pairs
const hex = 0xAB_C_D_EF;

// Binary not in groups of 4
const bin = 0b10_00_1111;

// Octal not in groups of 4
const oct = 0o1_0_44_21;

// BigInt with wrong grouping
const big = 1_294_28771_2n;

Configuration options

Each number type (binary, octal, hexadecimal, number) accepts its own options object with the following properties. You can also set onlyIfContainsSeparator at the top level to apply it to all types.

onlyIfContainsSeparator

Type: boolean
Default: false
When true, the rule only checks numbers that already contain a _ separator. You can set this at the top level or override it per number type.
/* eslint unicorn/numeric-separators-style: ["error", {
  "onlyIfContainsSeparator": true,
  "binary": { "onlyIfContainsSeparator": false }
}] */

const number = 100000;        // Pass — no separator, top-level flag skips it
const binary = 0b101010001;   // Fail — binary overrides to always check
const hex    = 0xD_EED_BEE_F; // Fail — has separator but incorrectly grouped

minimumDigits

Type: integer
Minimum: 0
The minimum number of digits before separator grouping is enforced. Numbers with fewer digits are always valid.

groupLength

Type: integer
Minimum: 1
The number of digits in each group. The leading group may be shorter than groupLength; all subsequent groups must be exactly groupLength digits.

Default configuration

{
  "onlyIfContainsSeparator": false,
  "binary":      { "minimumDigits": 0, "groupLength": 4 },
  "octal":       { "minimumDigits": 0, "groupLength": 4 },
  "hexadecimal": { "minimumDigits": 0, "groupLength": 2 },
  "number":      { "minimumDigits": 5, "groupLength": 3 }
}
Fractional digits are grouped left-to-right from the decimal point (e.g., 0.123_456), while integer and exponent parts are grouped right-to-left (e.g., 1_234_567). Prefixes (0x, 0b, 0o) and suffixes (n for BigInt) are not counted in the group length.

Build docs developers (and LLMs) love