Skip to content

Commit 8abeb0b

Browse files
committed
Try to cleanup the logic to handle XML attrs
1 parent 6740a99 commit 8abeb0b

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

lib/pmdtester/parsers/pmd_report_document.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,27 @@ def start_element(name, attrs = [])
3535
@current_filename = remove_work_dir!(attrs['name'])
3636
@current_violations = []
3737
when 'violation'
38-
@current_violation = PmdViolation.new(attrs, @branch_name, @current_filename)
38+
@current_violation = PmdViolation.new(
39+
branch: @branch_name,
40+
fname: @current_filename,
41+
info_url: attrs['externalInfoUrl'],
42+
bline: attrs['beginline'].to_i,
43+
rule_name: attrs['rule'],
44+
ruleset_name: attrs['ruleset'].freeze
45+
)
3946
when 'error'
40-
remove_work_dir!(attrs['msg'])
4147
@current_filename = remove_work_dir!(attrs['filename'])
42-
@current_error = PmdError.new(attrs, @branch_name, @current_filename)
48+
49+
@current_error = PmdError.new(
50+
branch: @branch_name,
51+
filename: @current_filename,
52+
short_message: remove_work_dir!(attrs['msg'])
53+
)
4354
end
4455
end
4556

57+
# Modifies the string in place and returns it
58+
# (this is what sub! does, except it returns nil if no replacement occurred)
4659
def remove_work_dir!(str)
4760
str.sub!(/#{@working_dir}/, '')
4861
str

lib/pmdtester/pmd_error.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ class PmdError
2121
attr_accessor :old_error
2222
attr_reader :filename, :short_message
2323

24-
def initialize(attrs, branch, filename)
24+
def initialize(branch:, filename:, short_message:)
2525
@branch = branch
2626
@stack_trace = ''
2727
@changed = false
28-
@short_message = attrs['msg']
28+
@short_message = short_message
2929
@filename = filename
3030
end
3131

lib/pmdtester/pmd_violation.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,24 @@ class PmdViolation
3030
attr_reader :fname, :info_url, :line, :old_line, :old_message, :rule_name, :ruleset_name
3131
attr_accessor :message
3232

33-
def initialize(attrs, branch, fname)
33+
# rubocop:disable Metrics/ParameterLists
34+
# Disable it: how is replacing a long parameter list with a single hash helping?
35+
def initialize(branch:, fname:, info_url:, bline:, rule_name:, ruleset_name:)
3436
@branch = branch
3537
@fname = fname
3638
@message = ''
3739

38-
@info_url = attrs['externalInfoUrl']
39-
@line = attrs['beginline'].to_i
40-
@rule_name = attrs['rule']
40+
@info_url = info_url
41+
@line = bline
42+
@rule_name = rule_name
4143

42-
@ruleset_name = attrs['ruleset'].freeze
44+
@ruleset_name = ruleset_name
4345

4446
@changed = false
4547
@old_message = nil
4648
@old_line = nil
4749
end
50+
# rubocop:enable Metrics/ParameterLists
4851

4952
def line_move?(other)
5053
message.eql?(other.message) && (line - other.line).abs <= 5

0 commit comments

Comments
 (0)