oxc-project/oxc · warning · OxcDiagnostic

Don't use a dangling dot in the number.

Error message

Don't use a dangling dot in the number.

What it means

Diagnostic from the oxlint rule `unicorn/no-zero-fractions` (style, autofixable). This variant (`dangling_dot`) fires on a numeric literal that ends with a bare decimal point: `1.`, `+1.`, `-1.`, `0.`, and scientific forms like `1.e10` or `-1.e+10`. The dangling dot is valid JavaScript but adds nothing over `1`, so the rule flags it for consistency. The fixer removes the dot (and rewrites `1.e10` to `1e10`), adding parentheses or spaces where token boundaries require them.

Source

Thrown at crates/oxc_linter/src/rules/unicorn/no_zero_fractions.rs:16

use oxc_ast::AstKind;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use oxc_syntax::identifier::is_identifier_part;

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

fn zero_fraction(span: Span, lit: &str) -> OxcDiagnostic {
    OxcDiagnostic::warn("Don't use a zero fraction in the number.")
        .with_help(format!("Replace the number literal with `{lit}`"))
        .with_label(span)
}

fn dangling_dot(span: Span, lit: &str) -> OxcDiagnostic {
    OxcDiagnostic::warn("Don't use a dangling dot in the number.")
        .with_help(format!("Replace the number literal with `{lit}`"))
        .with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct NoZeroFractions;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Prevents the use of zero fractions.
    ///
    /// ### Why is this bad?
    ///
    /// There is no difference in JavaScript between, for example, `1`, `1.0` and `1.`, so prefer the former for consistency and brevity.
    ///
    /// ### Examples
    ///

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Remove the dangling dot: `const foo = 1.;` -> `const foo = 1;`, `1.e10` -> `1e10`.
  2. Run `oxlint --fix` to apply the safe rewrite, including member-access cases like `(1.).toString()` -> `(1).toString()`.
  3. Add the missing digits if you actually meant a fraction (`1.5`).
  4. Disable inline for generated code where the form is not under your control.

Example fix

// before
const foo = 1.;
const bar = -1.e+10;

// after
const foo = 1;
const bar = -1e+10;
Defensive patterns

Strategy: validation

Validate before calling

# detect dangling-dot number literals
rg -n --type js '\d\.\s*(?:[,;)]|$|\.|e|E)' src/ | rg -v '\d\.\d'

Prevention

When it happens

Trigger: `const foo = 1.;`, `const foo = -1.;`, `const foo = 1.e10;`, `const foo = +1.e-10;`, `(1.).toString()`, `Test(0.)`. Not fired for normal fractions (`1.1`), strings containing `'1.'`, or integers.

Common situations: Typing shortcuts and minified/hand-trimmed code, or numbers edited down from `1.0`. Appears with the oxlint style category enabled.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/e407367f06205057. Report an issue: GitHub.