Repository navigation
Highlighter: Implement syntax-highlighted diff rendering - #2035
Merged
Merged
Conversation
🌿 Interactive Playground and Documentation PreviewA preview deployment has been built for this pull request. Try out the changes live in the interactive playground: 🌱 Grown from commit ✅ Preview deployment has been cleaned up. |
commit: |
marcoroth
marked this pull request as ready for review
August 6, 2026 01:30
marcoroth
added a commit
that referenced
this pull request
Aug 6, 2026
…tput (#1572) This pull request adds a `--show-fix-diff` flag that previews what `--fix` would change, without changing anything, so a correctable offense can be inspected before it is applied. The `[Correctable]` tag already tells you a fix exists, but not what it does. Each correctable offense now gets a syntax highlighted diff underneath it, rendered by the diff view from #2035, with the characters that would actually change picked out: ``` [warning] Attribute `class` uses single quotes. Prefer double quotes for HTML attribute values: `class="card"`. (html-attribute-double-quotes) [Correctable] index.html.erb:2:14 1 │ <div id="gems"> → 2 │ <SPAN class='card'>Hello</SPAN> │ ~~~~~~ 3 │ </div> Running --fix would correct this to: index.html.erb 1 │ <div id="gems"> - 2 │ <SPAN class='card'>Hello</SPAN> + │ <SPAN class="card">Hello</SPAN> 3 │ </div> ``` The heading names the flag that would apply it, rather than reading as something that already happened. Previews are computed with unsafe fixes included, so an offense that needs `--fix-unsafely` says so instead of implying plain `--fix` would handle it. <img width="2454" height="1380" alt="CleanShot 2026-08-06 at 03 43 25@2x" src="https://github.com/user-attachments/assets/ae4e9859-b98d-4497-88fa-2d10fa54fdd3" /> <img width="3597" height="2024" alt="CleanShot 2026-08-06 at 03 43 02@2x" src="https://github.com/user-attachments/assets/869f4c98-11e6-4755-8536-f724af4fa05b" />
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds a diff view to the Highlighter, so a change between two versions of a template can be rendered with the same syntax highlighting, gutter and theming as the rest of the package. The motivating case is previewing what a Linter autocorrection would do, which currently has no way to be shown.
The renderer computes hunks itself rather than taking a pre-formatted diff, highlights both sides, and marks the characters that actually changed within each line:
Options
autocollapses a pair only where that reads better, and only when color is on. A pure insertion or deletion is the clearest case, because the composite is exactly the line as it exists in one of the two versions, with the inserted part tinted, nothing synthetic:A genuine replacement produces text that appears in neither version, so it collapses only while the change stays under 24 characters a side, stays a minority of the line, and still fits the available width. Collapsing a line only to have it truncated would trade a line of height for a loss of content.
With
NO_COLORset nothing collapses, including insertions. The composite above would still be a valid line, but without the tint it no longer shows which part was added, so the stacked pair carries strictly more information:The
splitlayout gives each column its own numbering, since there a column is one version of the file and the ambiguity that motivates the blank added numbers does not exist:It falls back to
unifiedwhen the terminal cannot give each column readable width.On the command line
herb-highlight difftakes two files:It also renders a diff that was produced elsewhere, read from an argument or from stdin, following the same rule as
herb-format: with no argument and something piped in, stdin is used.git diff -- app/views | herb-highlight diffThe input may be unified diff text as produced by
git diff, whichparseUnifiedDiff()turns into hunks, or JSON as{"original": "...", "modified": "..."}or{"hunks": [...]}.Follow up work: wiring this into the Linter CLI in #1572.