Skip to content

Commit 94c917a

Browse files
committed
Fix nesting problem
1 parent 2796f2e commit 94c917a

File tree

2 files changed

+55
-56
lines changed

2 files changed

+55
-56
lines changed

lib/pmdtester/builders/project_hasher.rb

Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
require 'differ'
44

5-
# the same module as all the others? come on rubocop
65
module PmdTester
76
# Turn a project report into a hash that can be rendered somewhere else
87
module ProjectHasher
@@ -46,68 +45,68 @@ def violations_to_hash(project)
4645
'violations' => all_vs
4746
}
4847
end
49-
end
5048

51-
def link_template(project)
52-
l_str = project.type == 'git' ? 'L' : 'l'
53-
"#{project.webview_url}/{file}##{l_str}{line}"
54-
end
49+
def link_template(project)
50+
l_str = project.type == 'git' ? 'L' : 'l'
51+
"#{project.webview_url}/{file}##{l_str}{line}"
52+
end
5553

56-
def violation_type(violation)
57-
if violation.changed?
58-
'~'
59-
elsif violation.branch == 'patch'
60-
'+'
61-
else
62-
'-'
54+
def violation_type(violation)
55+
if violation.changed?
56+
'~'
57+
elsif violation.branch == 'patch'
58+
'+'
59+
else
60+
'-'
61+
end
6362
end
64-
end
6563

66-
def make_violation_hash(file_ref, violation)
67-
h = {
68-
't' => violation_type(violation),
69-
'l' => violation.line,
70-
'f' => file_ref,
71-
'r' => violation.rule_name,
72-
'm' => violation.changed? ? diff_fragments(violation) : violation.message
73-
}
74-
h['ol'] = violation.old_line if violation.changed? && violation.line != violation.old_line
75-
h
76-
end
64+
def make_violation_hash(file_ref, violation)
65+
h = {
66+
't' => violation_type(violation),
67+
'l' => violation.line,
68+
'f' => file_ref,
69+
'r' => violation.rule_name,
70+
'm' => violation.changed? ? diff_fragments(violation) : violation.message
71+
}
72+
h['ol'] = violation.old_line if violation.changed? && violation.line != violation.old_line
73+
h
74+
end
7775

78-
def diff_fragments(violation)
79-
diff = Differ.diff_by_word(violation.message, violation.old_message)
80-
diff.format_as(:html)
81-
end
76+
def diff_fragments(violation)
77+
diff = Differ.diff_by_word(violation.message, violation.old_message)
78+
diff.format_as(:html)
79+
end
8280

83-
def error_to_hash(error, project)
84-
escaped_stacktrace = sanitize_stacktrace(error)
85-
old_stacktrace = error.old_error.nil? ? nil : sanitize_stacktrace(error.old_error)
86-
87-
{
88-
'file_url' => project.get_webview_url(error.filename),
89-
'stack_trace_html' => escaped_stacktrace,
90-
'old_stack_trace_html' => old_stacktrace,
91-
'short_message' => error.short_message,
92-
'short_filename' => error.short_filename,
93-
'filename' => error.filename,
94-
'change_type' => change_type(error)
95-
}
96-
end
81+
def error_to_hash(error, project)
82+
escaped_stacktrace = sanitize_stacktrace(error)
83+
old_stacktrace = error.old_error.nil? ? nil : sanitize_stacktrace(error.old_error)
9784

98-
def sanitize_stacktrace(error)
99-
CGI.escapeHTML(error.stack_trace)
100-
.gsub(error.filename, '<span class="meta-var">$FILE</span>')
101-
.gsub(/\w++(?=\(\w++\.java:\d++\))/, '<span class="stack-trace-method">\\0</span>')
102-
end
85+
{
86+
'file_url' => project.get_webview_url(error.filename),
87+
'stack_trace_html' => escaped_stacktrace,
88+
'old_stack_trace_html' => old_stacktrace,
89+
'short_message' => error.short_message,
90+
'short_filename' => error.short_filename,
91+
'filename' => error.filename,
92+
'change_type' => change_type(error)
93+
}
94+
end
95+
96+
def sanitize_stacktrace(error)
97+
CGI.escapeHTML(error.stack_trace)
98+
.gsub(error.filename, '<span class="meta-var">$FILE</span>')
99+
.gsub(/\w++(?=\(\w++\.java:\d++\))/, '<span class="stack-trace-method">\\0</span>')
100+
end
103101

104-
def change_type(item)
105-
if item.branch == BASE
106-
'removed'
107-
elsif item.changed?
108-
'changed'
109-
else
110-
'added'
102+
def change_type(item)
103+
if item.branch == BASE
104+
'removed'
105+
elsif item.changed?
106+
'changed'
107+
else
108+
'added'
109+
end
111110
end
112111
end
113112
end

pmdtester.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
1111
s.metadata = { "bug_tracker_uri" => "https://github.com/pmd/pmd-regression-tester/issues", "homepage_uri" => "https://pmd.github.io", "source_code_uri" => "https://github.com/pmd/pmd-regression-tester" } if s.respond_to? :metadata=
1212
s.require_paths = ["lib".freeze]
1313
s.authors = ["Andreas Dangel".freeze, "Binguo Bao".freeze]
14-
s.date = "2020-11-23"
14+
s.date = "2020-11-25"
1515
s.description = "A regression testing tool ensure that new problems and unexpected behaviors will not be introduced to PMD project after fixing an issue , and new rules can work as expected.".freeze
1616
s.email = ["[email protected]".freeze, "[email protected]".freeze]
1717
s.executables = ["pmdtester".freeze]

0 commit comments

Comments
 (0)