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 (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.log("hello", "world");

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.

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.