For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt, and this page is available as Markdown at https://rslint.rs/rules/unicorn/numeric-separators-style.md.
close

numeric-separators-style

Unreleased

Configuration

rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/numeric-separators-style': 'error',
    },
  },
]);

Rule details

Enforce consistent _ separators in numeric and BigInt literals. The rule can automatically regroup digits while preserving the value and notation of each literal.

Examples of incorrect code for this rule

const total = 1_23_4444;
const fraction = 1_234.567_89;
const mask = 0xAB_C_D_EF;
const count = 1294287712n;

Examples of correct code for this rule

const total = 1_234_444;
const fraction = 1234.56789;
const mask = 0xAB_CD_EF;
const count = 1_294_287_712n;

Options

The rule accepts binary, octal, hexadecimal, and number option objects.

Option objectminimumDigitsgroupLengthfractionGroupLength
binary04—
octal04—
hexadecimal02—
number53Ungrouped

minimumDigits sets the digit count at which grouping starts. For decimals, it applies independently to the integer, fractional, and exponent parts. groupLength groups digits from the right. number.fractionGroupLength groups fractional digits from the decimal point toward the right.

onlyIfContainsSeparator defaults to false. Set it to true to check only literals that already contain _. Each option object can override the top-level setting.

export default [
  {
    plugins: ['unicorn'],
    rules: {
      'unicorn/numeric-separators-style': [
        'error',
        { number: { fractionGroupLength: 5 } },
      ],
    },
  },
];

Differences from upstream

Rslint checks JavaScript and TypeScript files. Use the upstream rule to check TOML and SOML files.

Legacy literals such as 099999.12 and 0777777 produce a syntax error in scripts. Write them as 99999.12 and 0o777777 to check their grouping.

With languageOptions.ecmaVersion set to 2020 or earlier, 12345 still gets a diagnostic. The rule withholds the autofix to 12_345 because that syntax requires ES2021.

Original documentation