mdsmith
Esc
    v0.52.0 GitHub
    MDS052 whitespace ready

    MDS052: no-space-in-code-spans

    Inline code spans with leading or trailing whitespace inside the backticks are almost always typos; flag them.

    CommonMark strips one space from each side of a code span when the content starts and ends with a space and is not entirely whitespace (` x `x, ` x `` x`). Whitespace that remains after this normalisation — a double space on one side, a tab, or a space on only one side — renders verbatim. Newlines inside code spans are normalised to spaces by CommonMark, so a leading or trailing newline renders as a leading or trailing space. This rule flags all of those cases.

    # Settings

    This rule has no tunable settings. Enable or disable it as a unit.

    # Config

    Enable:

    rules:
      no-space-in-code-spans: true

    Disable:

    rules:
      no-space-in-code-spans: false

    # Examples

    # Bad – leading space

    # Leading Space
    
    Use ` x` here.

    # Bad – trailing space

    # Trailing Space
    
    Use `x ` here.

    # Bad – double space on both sides

    # Double Space Both Sides
    
    Use `  x  ` here.

    # Good – no visible boundary whitespace

    # Clean Code Spans
    
    Use `x` for the value.
    
    Use ` x ` — CommonMark's single-space trim strips both outer spaces.
    
    Use `foo bar` for multi-word.

    # Diagnostics

    MessageMeaning
    code span has leading whitespaceWhitespace is visible at the start of the span after CommonMark’s single-space normalisation
    code span has trailing whitespaceWhitespace is visible at the end of the span after CommonMark’s single-space normalisation

    # Meta-Information

    • ID: MDS052
    • Name: no-space-in-code-spans
    • Status: ready
    • Default: disabled, opt-in
    • Fixable: yes (trims whitespace; spans that are empty after trimming or whose trimmed content starts/ends with a backtick adjacent to a delimiter are left unchanged or have a single protective space preserved)
    • Implementation: source
    • Category: whitespace
    • markdownlint: MD038 (no-space-in-code)
    • rumdl: MD038 (no-space-in-code)
    • mado: MD038 (no-space-in-code)