lib/checkstyle_format/plugin.rb in danger-checkstyle_xml-0.0.4 vs lib/checkstyle_format/plugin.rb in danger-checkstyle_xml-0.0.5
- old
+ new
@@ -5,26 +5,26 @@
module Danger
# Danger plugin for checkstyle xml files.
#
# @example Parse the XML file, and let the plugin do your reporting
#
- # checkstyle_format.base_path = Dir.pwd
+ # checkstyle_format.base_regex = %r{^.*?\/src\/}
# checkstyle_format.report 'app/build/reports/checkstyle/checkstyle.xml'
#
# @example Parse the XML text, and let the plugin do your reporting
#
- # checkstyle_format.base_path = Dir.pwd
+ # checkstyle_format.base_regex = %r{^.*?\/src\/}
# checkstyle_format.report_by_text '<?xml ...'
#
# @see noboru-i/danger-checkstyle_format
# @tags lint, reporting
#
class DangerCheckstyleFormat < Plugin
- # Base path of `name` attributes in `file` tag.
+ # Base regex for converting the full paths into relative paths.
# Defaults to nil.
# @return [String]
- attr_accessor :base_path
+ attr_accessor :base_regex
# Report checkstyle warnings
#
# @return [void]
def report(file, inline_mode: true)
@@ -55,31 +55,29 @@
doc = Ox.parse(text)
present_elements = doc.nodes.first.nodes.reject do |test|
test.nodes.empty?
end
-
- # base_path_suffix = @base_path.end_with?("/") ? "" : "/"
- # base_path = @base_path + base_path_suffix
present_elements.flat_map do |parent|
parent.nodes.map do |child|
- CheckstyleError.generate(child, parent, @base_path)
+ CheckstyleError.generate(child, parent, @base_regex)
end
end
end
def send_comment(errors, inline_mode)
if inline_mode
send_inline_comment(errors)
else
- raise "not implemented." # TODO: not implemented.
+ # TODO: not implemented.
+ raise "Not implemented."
end
end
def send_inline_comment(errors)
errors.each do |error|
- puts "Sending inline comment to file #{error.file_name}, line #{error.line}"
+ # puts "Sending inline comment to file #{error.file_name}, line #{error.line}"
warn(error.message, file: error.file_name, line: error.line)
end
end
end
end