Skip to content

Highlighter: Mark every line of a multi-line offense output - #1999

Merged
marcoroth merged 1 commit into
mainfrom
highlighter-multi-line-offense-markers
Aug 4, 2026
Merged

marcoroth merged 1 commit into
mainfrom
highlighter-multi-line-offense-markers

Conversation

@marcoroth

Copy link
Copy Markdown
Owner

This pull request updates the Highlighter's diagnostic renderers so an offense that spans multiple lines is marked on every line it covers, instead of drawing a single marker on the start line using the end line's column.

Both renderers computed the marker as end.column - start.column anchored at start.column, and never looked at location.end.line at all. For an offense spanning (26:4) to (28:13) that produced a marker on line 26 running from column 4 to column 13, which is neither where the offense starts nor where it ends:

     24 │
     25 │   <div id="gems" class="grid min-w-full gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
  →  26 │     <% @gems.each do |topic_gem| %>
        │     ~~~~~~~~~
     27 │       <%= render partial: "gem_card", locals: {topic_gem: topic_gem} %>
     28 │     <% end %>

Now every spanned line gets an arrow and a marker: the first line from start.column, the last line up to end.column, and the lines in between across their non-whitespace content. The trailing context also runs off the end line rather than the start line, so the lines after the offense are actually visible:

     24 │
     25 │   <div id="gems" class="grid min-w-full gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
  →  26 │     <% @gems.each do |topic_gem| %>
        │     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  →  27 │       <%= render partial: "gem_card", locals: {topic_gem: topic_gem} %>
        │       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  →  28 │     <% end %>
        │     ~~~~~~~~~
     29 │   </div>
     30 │

The marker geometry moves into a new computeDiagnosticMarkers() helper in diagnostic-markers.ts, shared by both renderers so the split view (herb-lint detailed output) and the whole-file inline view stay consistent. It returns one marker per line and skips lines with nothing to mark, so a blank line inside a span stays unmarked rather than collecting a stray marker.

In the inline renderer the diagnostic message now renders under the last spanned line instead of the first, so it no longer sits wedged between the source lines of its own offense:

  →   2 │   <% @gems.each do |topic_gem| %>
        │   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  →   3 │     <%= render partial: "gem_card" %>
        │     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  →   4 │   <% end %>
        │   ~~~~~~~~~
        │   [warning] Multi-line offense (multi-line-rule)

Resolves #1982

@github-actions github-actions Bot added typescript TypeScript source across the javascript/ packages highlighter @herb-tools/highlighter syntax highlighting and diagnostic rendering labels Aug 4, 2026
@marcoroth
marcoroth marked this pull request as ready for review August 4, 2026 19:30
@github-actions

github-actions Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

🌿 Interactive Playground and Documentation Preview

A preview deployment has been built for this pull request. Try out the changes live in the interactive playground:


🌱 Grown from commit 6393212


✅ Preview deployment has been cleaned up.

@pkg-pr-new

pkg-pr-new Bot commented Aug 4, 2026

Copy link
Copy Markdown
npx https://pkg.pr.new/@herb-tools/formatter@1999
npx https://pkg.pr.new/@herb-tools/language-server@1999
npx https://pkg.pr.new/@herb-tools/linter@1999

commit: 6393212

@marcoroth
marcoroth merged commit e57236b into main Aug 4, 2026
22 checks passed
@marcoroth
marcoroth deleted the highlighter-multi-line-offense-markers branch August 4, 2026 19:38

This branch was successfully deployed

1 active deployment
herb-tools (Preview) — 63932124 Deployed Aug 4, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

highlighter @herb-tools/highlighter syntax highlighting and diagnostic rendering typescript TypeScript source across the javascript/ packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Highlighter: Multi-line offense uses start.column with end.column while not respecting end.line

1 participant