{"record":{"id":"73cb572a796a7445","repo":"oxc-project/oxc","slug":"invalid-group-length-in-numeric-value","errorCode":null,"errorMessage":"Invalid group length in numeric value.","messagePattern":"Invalid group length in numeric value\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/numeric_separators_style.rs","lineNumber":15,"sourceCode":"use cow_utils::CowUtils;\nuse oxc_ast::{\n    AstKind,\n    ast::{BigIntLiteral, BigintBase, NumberBase, NumericLiteral},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse schemars::{JsonSchema, SchemaGenerator, schema::Schema};\nuse serde::{Deserialize, Serialize};\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn numeric_separators_style_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Invalid group length in numeric value.\")\n        .with_help(\"Group digits with numeric separators (_) so longer numbers are easier to read.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize)]\npub struct NumericSeparatorsStyle(Box<NumericSeparatorsStyleConfig>);\n\n#[derive(Debug, Clone, PartialEq, Eq, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NumericSeparatorsStyleConfig {\n    /// Only enforce the rule when the numeric literal already contains a separator (`_`).\n    ///\n    /// When `true`, numbers without separators are left as-is; when `false` (default),\n    /// grouping will be enforced for eligible numbers even if they don't include separators yet.\n    only_if_contains_separator: bool,\n    /// Configuration for hexadecimal literals (e.g. `0xAB_CD`, `0Xab_cd`, and bigint variants).\n    /// Controls how digits are grouped and when separators are applied.\n    #[schemars(schema_with = \"NumericBaseConfig::schema_with_defaults::<2, 0>\")]","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/oxc-project/oxc/blob/1f902a69625cd14e6d8dc58feca94da099d2d251/crates/oxc_linter/src/rules/unicorn/numeric_separators_style.rs#L1-L33","documentation":"Lint diagnostic from oxlint's `unicorn/numeric-separators-style` rule. It enforces how numeric separators (`_`) group digits: by default decimal digits in groups of 3, hex in groups of 2, and binary/octal in groups of 4 (configurable via `groupLength`, `minimumDigits`, `onlyIfContainsSeparator` per base). This message fires when a literal's separator grouping violates the configured style — wrong group length or a long number that should be grouped.","triggerScenarios":"Literals such as `const n = 1234567;` (no grouping despite 7 digits), `0xAABBCC` (hex groups of 2 expected -> `0xAA_BB_CC`), `0b1010_0001` is fine but `0b10_100001` is not, `1_0000.000_1` style mismatches. Also fires when config sets `groupLength: 4` but code uses `1_000_000`. Triggered during oxlint runs on numeric literals.","commonSituations":"Config mistakes: teams copy the ESLint unicorn config with custom `groupLength`/`minimumDigits` that differ from the code's existing style. Version changes: upgrading oxlint brought the rule in via the unicorn category and legacy constants (bit masks, protocol IDs) suddenly fail. Refactoring numbers across bases (dec -> hex) without regrouping separators.","solutions":["Regroup the literal to match the rule defaults: `1234567` -> `1_234_567`, `0xAABBCC` -> `0xAA_BB_CC`, `0b10100001` -> `0b1010_0001`.","If your project uses different group sizes, configure the rule in `.oxlintrc.json` under `rules` with `\"unicorn/numeric-separators-style\": [\"error\", {\"hexadecimal\": {\"groupLength\": 4}}]` etc.","Set `\"onlyIfContainsSeparator\": true` to leave numbers without `_` untouched if you only want consistency among already-separated numbers.","Run `oxlint --fix` for an automatic rewrite, then eyeball diffs on long constants."],"exampleFix":"// before\nconst million = 1000000;\nconst rgb = 0xFF00FF;\nconst flags = 0b11110000;\n\n// after\nconst million = 1_000_000;\nconst rgb = 0xFF_00_FF;\nconst flags = 0b1111_0000;","handlingStrategy":"validation","validationCode":"// Check config before enabling: put group lengths in .oxlintrc.json, e.g.\n// \"unicorn/numeric-separators-style\": [\"error\", {\n//   \"hexadecimal\": {\"groupLength\": 4},\n//   \"number\": {\"groupLength\": 3, \"minimumDigits\": 5}\n// }]\n// Then: oxlint --fix .","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Decide group sizes per base once in `.oxlintrc.json` so rule and codebase agree.","Set `onlyIfContainsSeparator: true` if you only want consistency, not forced grouping of legacy constants.","Run `oxlint --fix` in CI after enabling the rule to migrate literals in one reviewed PR."],"tags":["oxlint","unicorn","style","numeric-separators","readability","autofix"],"backgroundTag":"lint-rule-violation","analyzedSha":"1f902a69625cd14e6d8dc58feca94da099d2d251","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}