Skip to content

Commit 00be06a

Browse files
committed
Render diff of messages
1 parent 2c9effa commit 00be06a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/pmdtester/builders/diff_report/violations.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: true
2+
require 'differ'
23

34
# Contains methods to write out html for the violations.
45
# This mixin is used by DiffReportBuilder.
@@ -59,7 +60,11 @@ def build_violation_table_row(doc, key, pmd_violation)
5960
end
6061

6162
# The violation message
62-
doc.td "\n" + pmd_violation.text + "\n"
63+
if pmd_violation.changed
64+
doc.td { diff_fragments(doc, pmd_violation) }
65+
else
66+
doc.td pmd_violation.text
67+
end
6368

6469
# The begin line of the violation
6570
line = violation['beginline']
@@ -72,6 +77,13 @@ def build_violation_table_row(doc, key, pmd_violation)
7277
end
7378
end
7479

80+
def diff_fragments(doc, violation)
81+
old_message = violation.attrs["oldMessage"]
82+
new_message = violation.text
83+
diff = Differ.diff_by_word(old_message, new_message)
84+
doc << diff.format_as(:html)
85+
end
86+
7587
def get_link_to_source(violation, key)
7688
l_str = @project.type == 'git' ? 'L' : 'l'
7789
line_str = "##{l_str}#{violation['beginline']}"

0 commit comments

Comments
 (0)