Class: PuppetLint::Report::CodeClimateReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet-lint/report/codeclimate.rb

Overview

Formats problems and writes them to a file as a code climate compatible report.

Class Method Summary collapse

Class Method Details

.write_report_file(problems, report_file) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/puppet-lint/report/codeclimate.rb', line 10

def self.write_report_file(problems, report_file)
  report = []
  problems.each do |messages|
    messages.each do |message|
      case message[:kind]
      when :warning
        severity = 'minor'
      when :error
        severity = 'major'
      else
        next
      end

      issue = {
        type: :issue,
        check_name: message[:check],
        description: message[:message],
        categories: [:Style],
        severity: severity,
        location: {
          path: message[:path],
          lines: {
            begin: message[:line],
            end: message[:line]
          }
        }
      }

      issue[:fingerprint] = Digest::MD5.hexdigest(Marshal.dump(issue))

      if message.key?(:description) && message.key?(:help_uri)
        issue[:content] = "#{message[:description].chomp('.')}. See [this page](#{message[:help_uri]}) for more information about the `#{message[:check]}` check."
      end
      report << issue
    end
  end
  File.write(report_file, "#{JSON.pretty_generate(report)}\n")
end