Skip to content

MD038 - no-space-in-code

Description

This rule is triggered when inline code spans have unnecessary spaces adjacent to the backticks. For example: ` some code ` instead of `some code`. Per the CommonMark specification, symmetric single-space padding (e.g., ` code `) is valid because the parser strips one space from each side, so it is not flagged by this rule.

Rationale

Spaces inside code spans are usually unintentional and can lead to inconsistent formatting. The extra whitespace adds no value and may cause confusion about where the code actually starts or ends.

Examples

Invalid

# Invalid Code Spans

This has ` leading space` in code.

This has `trailing space ` in code.

This has `  spaces on both sides  ` in code.

Valid

# Valid Code Spans

This document has `properly formatted` code spans.

Multiple code spans: `one` and `two` and `three`.

Code span with backticks inside: `` `backticks` ``.

Symmetric space padding: ` code ` is valid per CommonMark.