oxc-project/oxc · warning · OxcDiagnostic

Don't use a zero fraction in the number.

Error message

Don't use a zero fraction in the number.

What it means

Diagnostic from the oxlint rule `unicorn/no-zero-fractions` (style, autofixable). It fires on a numeric literal whose fractional part is all zeros, such as `1.0`, `1.00000`, `-1.0`, `123.11100000000` (trailing zeros), or the leading-dot form `.0`. `1`, `1.0`, and `1.` are the same number in JavaScript, so the zeros add noise. The fixer replaces the literal (wrapping it in parentheses before member access like `1.00.toFixed(2)` -> `(1).toFixed(2)`, and inserting a space after keywords like `return.0` -> `return 0`).

Source

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

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.
    ///

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Drop the zero fraction: `const foo = 1.0;` -> `const foo = 1;`, `123.11100000000` -> `123.111`, `.0` -> `0`.
  2. Run `oxlint --fix`; the fixer handles the `(1).toFixed(2)` and `return 0` spacing edge cases.
  3. If you want to signal 'this is a float', use a comment or type annotation instead of `.0`.
  4. Keep the literal and disable inline only if a parser/format downstream requires the trailing zeros (none exist in standard JS).

Example fix

// before
const foo = 1.0;
const bar = 123.11100000000;
const baz = .0;

// after
const foo = 1;
const bar = 123.111;
const baz = 0;
Defensive patterns

Strategy: validation

Validate before calling

# detect all-zero fractions and leading-dot zeros
rg -n --type js '(?:\.0+\b|\b\d+\.0+(?!\d))' src/

Prevention

When it happens

Trigger: `const foo = 1.0`, `const foo = -1.0`, `const foo = 1.00`, `const foo = 123.11100000000`, `a = .0;`, `1.00e10`, `1.00.toFixed(2)`, `function foo(){return.0}`. Not fired for string literals (`'123.1000'`), non-zero fractions (`1.1`), or plain integers.

Common situations: Code ported from languages where `1.0` marks float type (Python, C), CSV/config values pasted as floats, and scientific constants. Appears when the oxlint style category is enabled.

Related errors


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