diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a79928a0593..b5ded316fca8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ * [#3157](https://github.com/bbatsov/rubocop/issues/3157): Don't let `LineEndConcatenation` and `UnneededInterpolation` make changes to the same string during auto-correct. ([@jonas054][]) * [#3187](https://github.com/bbatsov/rubocop/issues/3187): Let `Style/BlockDelimiters` ignore blocks in *all* method arguments. ([@jonas054][]) * Modify `Style/ParallelAssignment` to use implicit begins when parallel assignment uses a `rescue` modifier and is the only thing in the method. ([@rrosenblum][]) +* [#3217](https://github.com/bbatsov/rubocop/pull/3217): Fix output of ellipses for multi-line offense ranges in HTML formatter. ([@jonas054][]) ### Changes diff --git a/lib/rubocop/formatter/html_formatter.rb b/lib/rubocop/formatter/html_formatter.rb index d97781df1f25..cf345bd4d6a3 100644 --- a/lib/rubocop/formatter/html_formatter.rb +++ b/lib/rubocop/formatter/html_formatter.rb @@ -95,18 +95,14 @@ def decorated_message(offense) def highlighted_source_line(offense) location = offense.location - - source_line = if location.first_line == location.last_line - location.source_line - else - "#{location.source_line} #{ELLIPSES}" - end + source_line = location.source_line escape(source_line[0...offense.highlighted_area.begin_pos]) + "" + escape(offense.highlighted_area.source) + '' + - escape(source_line[offense.highlighted_area.end_pos..-1]) + escape(source_line[offense.highlighted_area.end_pos..-1]) + + (location.first_line == location.last_line ? '' : " #{ELLIPSES}") end def escape(s) diff --git a/spec/fixtures/html_formatter/expected.html b/spec/fixtures/html_formatter/expected.html index 7323b09c0615..5485b482368c 100644 --- a/spec/fixtures/html_formatter/expected.html +++ b/spec/fixtures/html_formatter/expected.html @@ -472,7 +472,7 @@
def set_book <span class="extra-code">...</span>
+ def set_book ...
@@ -494,7 +494,7 @@ def book_params <span class="extra-code">...</span>
+ def book_params ...