Skip to content

markdown-format re-emits whole-file lint output on every touch, unbounded #1589

Closed

Description

@kyle-sexton

Summary

markdown-format appends every line of markdownlint's whole-file output to additionalContext
on every Write/Edit of a Markdown file — no cap, no baseline, no dedup. A file edited repeatedly
in one session produces a full re-dump each time, and re-editing does not shrink the report because
the report is whole-file, not diff-scoped.

Measured in one consuming session:

  • 21 hook-context dumps, 377,996 bytes (~95K tokens) burned on lint output alone.
  • One file dumped eight times, ~145 KB, with byte-identical content across repeats.
  • On a real working file: 324 findings, 314 of them (97%) from a single rule the repository
    intentionally violates as house style.

The relevant code is plugins/markdown-format/hooks/markdown-format.sh: the residual-findings loop
hook::ctx_append " $line"s unconditionally over the whole of $FIX_OUTPUT.

Contributing factors

  1. No cap and no dedup. Nothing bounds the number of violation lines, and an unchanged finding
    set on a re-edited file is re-sent in full.
  2. Banner lines are included. markdownlint-cli2 always prints its version, the resolved
    Finding: <path> !**/node_modules/** … glob list, Linting: N files, and Summary: N issues.
    None of them says anything about the edited file; all of them cost context on every single edit.
  3. No signal about which rules dominate. A 324-finding report where 314 are one rule reads
    identically to 324 varied findings, so the one action that would actually fix it — configure that
    rule once in the repo's markdownlint config — is not visible from the report.

Config discovery itself is fine and is not the bug: a .markdownlint.jsonc disabling the dominant
rule drops that file from 324 findings to 10 (verified). The consuming repository simply had no
markdownlint config, which is the common case this hook has to behave well in.

Related, same file

On the clean-after-fix path (--fix succeeded, exit 0) the hook emits nothing at all, so
--fix rewriting the user's file is indistinguishable from the hook not having run. markdownlint-cli2
does report a count line (Attempted: N fixes in 1 file) that is currently discarded.

Expected

  1. Every run reports the total finding count and which rules dominate it.
  2. Individual violation lines are capped, with the omitted remainder reported as a count, and the cap
    is configurable.
  3. An unchanged finding set on a re-edited file reports its summary without repeating the detail —
    the summary must still go out. Suppressing the message entirely would reproduce the
    invisible-hook problem on the other side.
  4. Banner lines do not enter the report.
  5. A run that rewrote the file says so.
  6. Telemetry stays uncapped: a sink is a machine, and the cap exists to protect the model's context.

Environment

markdownlint-cli2 v0.23.1 (markdownlint v0.41.1), Windows 11 / Git Bash.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions