Skip to content

no-double-space

✅ Recommended 🔧 Fixable ⭐ CommonMark 🌟 GFM

🔗 Rule Source 🔗 Test Source

Disallow double or multiple consecutive spaces in text, except for leading and trailing spaces.

Rule Details

Markdown treats double or multiple consecutive spaces within a sentence as a single space.

Double spaces within a sentence are usually typos and can be hard to spot. This rule helps keep your code clean and consistent.

It only checks for double or multiple consecutive spaces within sentences. Since leading and trailing spaces have special meanings in Markdown, this rule does not check for them. Leading spaces are used for creating code blocks or indentation, while trailing spaces are used to create line breaks.

Examples

❌ Incorrect

Examples of incorrect code for this rule:

Default

md
foo  bar  baz
js
export default [
  // ...
  {
    rules: {
      'mark/no-double-space': 'error', 
    },
  },
  // ...
];

With multipleSpace: true Option

md
foo  bar  baz

foo   bar   baz

foo    bar    baz    qux
js
export default [
  // ...
  {
    rules: {
      'mark/no-double-space': ['error', { 
        multipleSpace: true, 
      }], 
    },
  },
  // ...
];

✅ Correct

Examples of correct code for this rule:

Default

md
foo bar baz qux

foo   bar    baz     qux

  foo bar

foo bar  

foo bar    
js
export default [
  // ...
  {
    rules: {
      'mark/no-double-space': 'error', 
    },
  },
  // ...
];

With multipleSpace: true Option

md
foo bar baz qux

  foo bar

foo bar  

foo bar    
js
export default [
  // ...
  {
    rules: {
      'mark/no-double-space': ['error', { 
        multipleSpace: true, 
      }], 
    },
  },
  // ...
];

Options

js
'mark/no-double-space': ['error', {
  multipleSpace: false,
}]

multipleSpace

Default: false

When multipleSpace is set to true, this rule will also check for multiple consecutive spaces (more than two) within a sentence.

Fix

This rule fixes the double or multiple consecutive spaces by replacing them with a single space.

AST

This rule applies only to the Text node.

Prior Art