Skip to main content
interlace
Plugin: conventionsRules

no-console-spaces

Disallow leading/trailing whitespace in console arguments. This rule is part of eslint-plugin-conventions.

Disallow leading/trailing whitespace in console arguments. This rule is part of eslint-plugin-conventions.

Quick Summary

AspectDetails
SeverityWarning (code quality)
Auto-Fix✅ Yes, for strings (removes the redundant spaces); templates are reported only
CategoryDevelopment
ESLint MCP✅ Optimized for ESLint MCP integration
Best ForClean console output, consistent logging

Rule Details

Console methods join their arguments with a space, so a space on the side of a string argument that touches another argument prints twice. The rule reports a leading space on an argument that has another argument before it, and a trailing space on an argument that has another after it, in quoted strings and template literals (only the outer edges of a template count; the spaces around an interpolation are its interior).

It reads the global console by binding — console.log, console['log'], globalThis.console.log, or the console / node:console module — on log, debug, info, warn, error, table, trace, group and groupCollapsed.

It does not report:

  • a leading space on the first argument or a trailing space on the last (or only) one: nothing is joined there, so the space is the message's own (an indented line, a prompt);
  • a string that is only whitespace (a deliberate spacer);
  • a console the code binds itself, such as an injected logger parameter.

Why This Matters

IssueImpactSolution
📝 Double spacesInconsistent outputRemove redundant spaces
🔍 Log parsingAffects log analysisClean formatting

Examples

❌ Incorrect

console.log('Value: ', value);  // Double space in output
console.log(value, ' items');   // Double space in output
console.log(' Debug: ', data);  // The trailing space doubles the separator

✅ Correct

console.log('hello', 'world');
console.log('Value:', value);
console.log('  indented line'); // only argument: the indent is the message's
console.log(count, 'items ');   // last argument: nothing follows it

Configuration Examples

Basic Usage

{
  rules: {
    'conventions/no-console-spaces': 'warn'
  }
}

Further Reading

Known False Negatives

  • A console reached through another object (deps.console.log(...)) or a wrapper function is not recognised as the global console.
  • A string assigned to a variable first (const label = 'a '; console.log(label, b)) is not read.

Use this rule

npm install -D oxlint-plugin-conventions
.oxlintrc.json
{  "jsPlugins": ["oxlint-plugin-conventions"],  "rules": {    "conventions/no-console-spaces": "error"  }}
vite.config.ts
import { defineConfig } from 'vite-plus';export default defineConfig({  lint: {    jsPlugins: ['oxlint-plugin-conventions'],    rules: {      'conventions/no-console-spaces': 'error',    },  },});

oxlint-plugin-conventions re-exports eslint-plugin-conventions/oxlint: the same rules under the same IDs, and no ESLint install. Why oxlint.

Did this rule catch something? Star the repo to get new CWE coverage as we ship it — or follow the AI-code-security benchmarks behind these rules.