ESLint InterlaceESLint Interlace
Plugin: conventionsRules

no-console-spaces

ESLint rule documentation for no-console-spaces

📡 Live from GitHub — This documentation is fetched directly from no-console-spaces.md and cached for 6 hours.

Keywords: console, logging, spaces, formatting, ESLint rule, auto-fix, LLM-optimized

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 (removes extra spaces)
CategoryDevelopment
ESLint MCP✅ Optimized for ESLint MCP integration
Best ForClean console output, consistent logging

Rule Details

Console methods automatically add spaces between arguments, so leading/trailing spaces in strings are redundant.

Why This Matters

IssueImpactSolution
📝 Double spacesInconsistent outputRemove redundant spaces
🔍 Log parsingAffects log analysisClean formatting
📖 ReadabilityCluttered logsTrim strings

Examples

❌ Incorrect

// Leading/trailing spaces are redundant
console.log('Value: ', value);  // Double space in output
console.log(value, ' items');   // Double space in output
console.log(' Debug: ', data);  // Leading space unnecessary

✅ Correct

// Console adds spaces automatically
console.log('Value:', value);
console.log(value, 'items');
console.log('Debug:', data);

// Or use template literals for exact control
console.log(`Value: ${value}`);

Configuration Examples

Basic Usage

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

Further Reading

Known False Negatives

The following patterns are not detected due to static analysis limitations:

Dynamic Variable References

Why: Static analysis cannot trace values stored in variables or passed through function parameters.

// ❌ NOT DETECTED - Value from variable
const value = externalSource();
processValue(value); // Variable origin not tracked

Mitigation: Implement runtime validation and review code manually. Consider using TypeScript branded types for validated inputs.

Wrapped or Aliased Functions

Why: Custom wrapper functions or aliased methods are not recognized by the rule.

// ❌ NOT DETECTED - Custom wrapper
function myWrapper(data) {
  return internalApi(data); // Wrapper not analyzed
}
myWrapper(unsafeInput);

Mitigation: Apply this rule's principles to wrapper function implementations. Avoid aliasing security-sensitive functions.

Imported Values

Why: When values come from imports, the rule cannot analyze their origin or construction.

// ❌ NOT DETECTED - Value from import
import { getValue } from './helpers';
processValue(getValue()); // Cross-file not tracked

Mitigation: Ensure imported values follow the same constraints. Use TypeScript for type safety.

On this page

No Headings