Skip to content

Commit 6d41cc4

Browse files
committed
Render line changes
1 parent 60342ba commit 6d41cc4

File tree

4 files changed

+31
-20
lines changed

4 files changed

+31
-20
lines changed

lib/pmdtester/builders/diff_report/violations.rb

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,45 +38,46 @@ def build_violation_table_body(doc, key, value)
3838
end
3939
end
4040

41-
def build_violation_table_row(doc, key, pmd_violation)
42-
doc.tr(class: get_css_class(pmd_violation)) do
41+
def build_violation_table_row(doc, key, violation)
42+
doc.tr(class: get_css_class(violation)) do
4343
build_table_anchor_column(doc, 'A', increment_violation_index)
4444

45-
violation = pmd_violation.attrs
46-
4745
# The rule that trigger the violation
4846
doc.td do
49-
doc.a(href: (violation['externalInfoUrl']).to_s) { doc.text violation['rule'] }
47+
doc.a(href: violation.info_url.to_s) { doc.text violation.rule_name }
5048
end
5149

5250
# The violation message
53-
if pmd_violation.changed
54-
doc.td { diff_fragments(doc, pmd_violation) }
51+
if violation.changed && violation.message != violation.old_message
52+
doc.td { diff_fragments(doc, violation) }
5553
else
56-
doc.td pmd_violation.text
54+
doc.td violation.text
5755
end
5856

59-
# The begin line of the violation
60-
line = violation['beginline']
61-
6257
# The link to the source file
6358
doc.td do
6459
link = get_link_to_source(violation, key)
65-
doc.a(href: link.to_s) { doc.text line }
60+
doc.a(href: link.to_s) { doc.text display_line(violation) }
6661
end
6762
end
6863
end
6964

7065
def diff_fragments(doc, violation)
71-
old_message = violation.attrs['oldMessage']
72-
new_message = violation.text
73-
diff = Differ.diff_by_word(old_message, new_message)
66+
diff = Differ.diff_by_word(violation.old_message, violation.message)
7467
doc << diff.format_as(:html)
7568
end
7669

70+
def display_line(violation)
71+
if violation.changed && violation.old_line != violation.line
72+
"#{violation.old_line} => #{violation.line}"
73+
else
74+
violation.line
75+
end
76+
end
77+
7778
def get_link_to_source(violation, key)
7879
l_str = @project.type == 'git' ? 'L' : 'l'
79-
line_str = "##{l_str}#{violation['beginline']}"
80+
line_str = "##{l_str}#{violation.line}"
8081
@project.get_webview_url(key) + line_str
8182
end
8283

@@ -85,8 +86,6 @@ def increment_violation_index
8586
@violation_index += 1
8687
end
8788

88-
private
89-
9089
def get_css_class(pmd_violation)
9190
if pmd_violation.changed
9291
'd'

lib/pmdtester/parsers/pmd_report_document.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def match_filter_set?(violation)
8181

8282
@filter_set.each do |filter_rule_ref|
8383
ruleset_attr = violation.attrs['ruleset'].delete(' ').downcase + '.xml'
84-
rule = violation.attrs['rule']
84+
rule = violation.rule_name
8585
rule_ref = "#{ruleset_attr}/#{rule}"
8686
return true if filter_rule_ref.eql?(ruleset_attr)
8787
return true if filter_rule_ref.eql?(rule_ref)

lib/pmdtester/pmd_violation.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ def try_merge?(other)
7878
end
7979
end
8080

81+
def old_message
82+
@attrs['oldMessage']
83+
end
84+
85+
def old_line
86+
@attrs['oldLine']
87+
end
88+
89+
def info_url
90+
@attrs['externalInfoUrl']
91+
end
92+
8193
def line
8294
@attrs['beginline']
8395
end

test/test_pmd_report_document.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_filter_set
2525
parser.parse(File.open('test/resources/pmd_report_document/test_document.xml'))
2626
assert_equal(1, doc.violations.violations_size)
2727
assert_equal('UncommentedEmptyConstructor',
28-
doc.violations.violations[FIRST_FILE][0].attrs['rule'])
28+
doc.violations.violations[FIRST_FILE][0].rule_name)
2929
# note: errors are not filtered - they don't refer to a rule/ruleset
3030
end
3131

0 commit comments

Comments
 (0)