oxc-project/oxc · info · OxcDiagnostic

Do not use {leading_or_trailing} spaces with `console.{metho

Error message

Do not use {leading_or_trailing} spaces with `console.{method_name}` parameters

What it means

Diagnostic from the oxlint rule `unicorn/no-console-spaces`. `console.log/debug/info/warn/error` join their arguments with a single space, so a string argument that itself starts or ends with a space produces doubled spacing in the output. The rule flags leading spaces on non-first arguments and trailing spaces on non-last arguments (the positions the join actually affects), for both string literals and template literals, and is auto-fixable (the padding space is trimmed).

Source

Thrown at crates/oxc_linter/src/rules/unicorn/no_console_spaces.rs:18

use oxc_ast::{AstKind, ast::Expression};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};

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

fn no_console_spaces_diagnostic(
    leading_or_trailing: &str,
    method_name: &str,
    span: Span,
) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("Do not use {leading_or_trailing} spaces with `console.{method_name}` parameters"))
        .with_help("The `console.log()` method and similar methods join the parameters with a space so adding a leading/trailing space to a parameter, results in two spaces being added.")
        .with_label(span)
}

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

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallows leading/trailing space inside `console.log()` and similar methods.
    ///
    /// ### Why is this bad?
    ///
    /// The `console.log()` method and similar methods join the parameters
    /// with a space so adding a leading/trailing space to a parameter,
    /// results in two spaces being added.
    ///

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Remove the padding space from the argument — `oxlint --fix` does this automatically
  2. When alignment is wanted, be explicit: `console.log('task:'.padEnd(10), value)` or use a structured logger
  3. For deliberate padding, suppress with `// oxlint-disable-next-line unicorn/no-console-spaces`

Example fix

// before
console.log('Loading ', file, '... ');

// after
console.log('Loading', file, '...');
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: `console.log('abc ', 'def')`, `console.error('a', ' b ', 'c')`, `console.warn(`task ${id} `, status)` — a space-padded string/template literal argument in a joining position. Leading space on the first argument and trailing space on the last argument are allowed; only `console` as receiver with those five method names is checked.

Common situations: Hand-padded CLI or log output; copy-pasted log messages; replacing a formatting logger with raw console calls. Also migration notes: oxlint additionally flags `console['log'](...)` computed-key calls that eslint-plugin-unicorn passed.

Related errors


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