Class: Danger::DangerStaticAnalyzerComments
- Inherits:
-
Plugin
- Object
- Plugin
- Danger::DangerStaticAnalyzerComments
- Defined in:
- lib/danger_plugin.rb
Constant Summary collapse
- LINT_SEVERITY_LEVELS =
["Warning", "Error", "Fatal"]
- CHECKSTYLE_SEVERITY_LEVELS =
["ignore", "info", "warning", "error"]
Instance Attribute Summary collapse
-
#android_lint_report_file ⇒ Object
Returns the value of attribute android_lint_report_file.
-
#checkstyle_report_file ⇒ Object
Returns the value of attribute checkstyle_report_file.
Instance Method Summary collapse
- #android_lint ⇒ Object
- #checkstyle ⇒ Object
- #current_dir ⇒ Object
- #run ⇒ Object
- #send_android_lint_inline_comment(issues) ⇒ Object
- #send_checkstyle_inline_comment(files) ⇒ Object
- #target_files ⇒ Object
Instance Attribute Details
#android_lint_report_file ⇒ Object
Returns the value of attribute android_lint_report_file.
9 10 11 |
# File 'lib/danger_plugin.rb', line 9 def android_lint_report_file @android_lint_report_file end |
#checkstyle_report_file ⇒ Object
Returns the value of attribute checkstyle_report_file.
10 11 12 |
# File 'lib/danger_plugin.rb', line 10 def checkstyle_report_file @checkstyle_report_file end |
Instance Method Details
#android_lint ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/danger_plugin.rb', line 17 def android_lint unless File.exists?(@android_lint_report_file) fail("Lint report not found at `#{@android_lint_report_file}`.") end file = File.open(@android_lint_report_file) report = Oga.parse_xml(file) issues = report.xpath('//issue') send_android_lint_inline_comment(issues) end |
#checkstyle ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/danger_plugin.rb', line 28 def checkstyle unless File.exists?(checkstyle_report_file) fail("Checkstyle report not found at `#{checkstyle_report_file}`.") end file = File.open(checkstyle_report_file) report = Oga.parse_xml(file) files = report.xpath('/checkstyle/file') send_checkstyle_inline_comment(files) end |
#current_dir ⇒ Object
69 70 71 |
# File 'lib/danger_plugin.rb', line 69 def current_dir "#{Dir.pwd}/" end |
#run ⇒ Object
12 13 14 15 |
# File 'lib/danger_plugin.rb', line 12 def run android_lint checkstyle end |
#send_android_lint_inline_comment(issues) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/danger_plugin.rb', line 51 def send_android_lint_inline_comment(issues) LINT_SEVERITY_LEVELS.reverse.each do |level| filtered = issues.select {|issue| issue.get("severity") == level} next if filtered.empty? filtered.each do |r| location = r.xpath('location').first filename = location.get('file').gsub(current_dir, "") next unless (target_files.include? filename) line = (location.get('line') || "0").to_i send(level === "Warning" ? "warn" : "fail", r.get('message'), file: filename, line: line) end end end |
#send_checkstyle_inline_comment(files) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/danger_plugin.rb', line 39 def send_checkstyle_inline_comment(files) files.each do |file| filename = file.get('name').gsub(current_dir, "") errors = file.xpath('error') errors.each do |error| next unless (target_files.include? filename) line = (error.get('line') || "0").to_i warn(error.get('message'), file: filename, line: line) end end end |
#target_files ⇒ Object
65 66 67 |
# File 'lib/danger_plugin.rb', line 65 def target_files (git.modified_files - git.deleted_files) + git.added_files end |