oxc-project/oxc · error · OxcDiagnostic

Unexpected newline between numerator and division operator

Error message

Unexpected newline between numerator and division operator

What it means

The `Division` variant of `no-unexpected-multiline`: the next line starts with `/`, which the parser reads as a division operator against the previous line's value instead of a regex literal or comment. The label attaches to the slash span ("this is parsed as division, which may be unintentional") and the help says to insert `;` before the slash.

Source

Thrown at crates/oxc_linter/src/rules/eslint/no_unexpected_multiline.rs:48

        DiagnosticKind::PropertyAccess { open_bracket_span } => OxcDiagnostic::warn(
            "Unexpected newline between object and open bracket of property access",
        )
        .with_label(
            open_bracket_span
                .label("this is parsed as a property access, which may be unintentional"),
        )
        .with_help("If you did not intend to access a property, insert ';' before the bracket"),
        DiagnosticKind::TaggedTemplate { backtick_span } => {
            OxcDiagnostic::warn(
                "Unexpected newline between template tag and template literal",
            )
            .with_label(backtick_span.label(
                "this is parsed as a tagged template, which may be unintentional",
            ))
            .with_help("If you did not intend for this to be a tagged template, insert ';' before the backtick")
        }
        DiagnosticKind::Division { slash_span } => {
            OxcDiagnostic::warn(
                "Unexpected newline between numerator and division operator",
            )
            .with_label(
                slash_span.label("this is parsed as division, which may be unintentional"),
            )
            .with_help("If you did not intend to divide, insert ';' before the slash")
        }
    }
}

declare_oxc_lint!(
    /// ### What it does
    ///
    /// In most cases, semicolons are not required in JavaScript in order for code to be parsed
    /// and executed as expected. Typically this occurs because semicolons are automatically
    /// inserted based on a fixed set of rules. This rule exists to detect those cases where a semicolon
    /// is NOT inserted automatically, and may be parsed differently than expected.
    ///

View on GitHub (pinned to e1e7af627c)

Solutions

  1. End the previous statement with `;`.
  2. Keep the operator at the end of the previous line instead of the start of the next (`a +`\n`b`, not `a`\n`+ b`).
  3. Use a formatter with semicolons enabled.

Example fix

// before
const ratio = total
/2

// after
const ratio = total / 2;
Defensive patterns

Strategy: validation

Validate before calling

# heuristic: lines starting with '/' after an expression line
rg -n -U '[\w)\]]\s*\n/' src/

Prevention

When it happens

Trigger: `const n = count\n/regex/.test(s)` or `const x = a\n/ 2 * b` — a statement ending in an expression, newline, then a line starting with `/`. The division parse either throws a syntax error or silently computes nonsense.

Common situations: Semicolon-less code where a regex test or a continuation of arithmetic starts a line; splitting long arithmetic expressions across lines right at the operator.

Related errors


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