{"record":{"id":"684b38bd89924262","repo":"oxc-project/oxc","slug":"do-not-use-leading-or-trailing-spaces-with-cons","errorCode":null,"errorMessage":"Do not use {leading_or_trailing} spaces with `console.{method_name}` parameters","messagePattern":"Do not use (.+?) spaces with `console\\.(.+?)` parameters","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"info","filePath":"crates/oxc_linter/src/rules/unicorn/no_console_spaces.rs","lineNumber":18,"sourceCode":"use oxc_ast::{AstKind, ast::Expression};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{\n    AstNode,\n    ast_util::{call_expr_method_callee_info, is_method_call},\n    context::LintContext,\n    rule::Rule,\n};\n\nfn no_console_spaces_diagnostic(\n    leading_or_trailing: &str,\n    method_name: &str,\n    span: Span,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Do not use {leading_or_trailing} spaces with `console.{method_name}` parameters\"))\n        .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.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoConsoleSpaces;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallows leading/trailing space inside `console.log()` and similar methods.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// The `console.log()` method and similar methods join the parameters\n    /// with a space so adding a leading/trailing space to a parameter,\n    /// results in two spaces being added.\n    ///","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/no_console_spaces.rs#L1-L36","documentation":"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).","triggerScenarios":"`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.","commonSituations":"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.","solutions":["Remove the padding space from the argument — `oxlint --fix` does this automatically","When alignment is wanted, be explicit: `console.log('task:'.padEnd(10), value)` or use a structured logger","For deliberate padding, suppress with `// oxlint-disable-next-line unicorn/no-console-spaces`"],"exampleFix":"// before\nconsole.log('Loading ', file, '... ');\n\n// after\nconsole.log('Loading', file, '...');","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pad log-message strings by hand; console methods join args with a single space","Use padEnd/padStart or a structured logger when alignment matters","Run `oxlint --fix` after touching log lines; this rule is auto-fixable"],"tags":["console","logging","style","whitespace","oxlint"],"backgroundTag":"console-output-formatting","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}