Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions crates/oxc_linter/src/rules/unicorn/numeric_separators_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use oxc_ast::{
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use schemars::JsonSchema;

use crate::{AstNode, context::LintContext, rule::Rule};

Expand All @@ -18,12 +19,25 @@ fn numeric_separators_style_diagnostic(span: Span) -> OxcDiagnostic {
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct NumericSeparatorsStyle(Box<NumericSeparatorsStyleConfig>);

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "camelCase", default)]
pub struct NumericSeparatorsStyleConfig {
/// Only enforce the rule when the numeric literal already contains a separator (`_`).
///
/// When `true`, numbers without separators are left as-is; when `false` (default),
/// grouping will be enforced for eligible numbers even if they don't include separators yet.
only_if_contains_separator: bool,
/// Configuration for hexadecimal literals (e.g. `0xAB_CD`, `0Xab_cd`, and bigint variants).
/// Controls how digits are grouped and when separators are applied.
hexadecimal: NumericBaseConfig,
/// Configuration for binary literals (e.g. `0b1010_0001` and bigint variants).
/// Controls how digits are grouped and when separators are applied.
binary: NumericBaseConfig,
/// Configuration for octal literals (e.g. `0o1234_5670` and bigint variants).
/// Controls how digits are grouped and when separators are applied.
octal: NumericBaseConfig,
/// Configuration for decimal numbers (integers, fraction parts, and exponents).
/// Controls how digits are grouped and when separators are applied.
number: NumericBaseConfig,
}

Expand Down Expand Up @@ -87,7 +101,8 @@ declare_oxc_lint!(
NumericSeparatorsStyle,
unicorn,
style,
fix
fix,
config = NumericSeparatorsStyleConfig,
);

impl Rule for NumericSeparatorsStyle {
Expand Down Expand Up @@ -271,9 +286,14 @@ impl NumericSeparatorsStyle {
}
}

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "camelCase")]
struct NumericBaseConfig {
/// The number of digits per group when inserting numeric separators.
/// For example, a `groupLength` of 3 formats `1234567` as `1_234_567`.
group_length: usize,
/// The minimum number of digits required before grouping is applied.
/// Values with fewer digits than this threshold will not be grouped.
minimum_digits: usize,
}
impl NumericBaseConfig {
Expand Down
Loading