Class: CC::Analyzer::Formatters::PlainTextFormatter

Inherits:
Formatter
  • Object
show all
Defined in:
lib/cc/analyzer/formatters/plain_text_formatter.rb

Constant Summary

Constants inherited from Formatter

Formatter::InvalidFormatterError

Instance Method Summary collapse

Methods inherited from Formatter

#initialize

Constructor Details

This class inherits a constructor from CC::Analyzer::Formatters::Formatter

Instance Method Details

#engine_running(engine) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/cc/analyzer/formatters/plain_text_formatter.rb', line 57

def engine_running(engine)
  @active_engine = engine
  with_spinner("Running #{engine.name}: ") do
    yield
  end
  @active_engine = nil
end

#failed(output) ⇒ Object



65
66
67
68
69
70
# File 'lib/cc/analyzer/formatters/plain_text_formatter.rb', line 65

def failed(output)
  spinner.stop("Failed")
  puts colorize("\nAnalysis failed with the following output:", :red)
  puts output
  exit 1
end

#finishedObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cc/analyzer/formatters/plain_text_formatter.rb', line 32

def finished
  puts

  issues_by_path.each do |path, file_issues|
    puts colorize("== #{path} (#{pluralize(file_issues.size, "issue")}) ==", :yellow)

    IssueSorter.new(file_issues).by_location.each do |issue|
      if location = issue["location"]
        print(colorize(LocationDescription.new(location, ": "), :cyan))
      end

      print(issue["description"])
      print(colorize(" [#{issue["engine_name"]}]", "#333333"))
      puts
    end
    puts
  end

  print(colorize("Analysis complete! Found #{pluralize(issues.size, "issue")}", :green))
  if warnings.size > 0
    print(colorize(" and #{pluralize(warnings.size, "warning")}", :green))
  end
  puts(colorize(".", :green))
end

#startedObject



10
11
12
# File 'lib/cc/analyzer/formatters/plain_text_formatter.rb', line 10

def started
  puts colorize("Starting analysis", :green)
end

#write(data) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cc/analyzer/formatters/plain_text_formatter.rb', line 14

def write(data)
  if data.present?
    json = JSON.parse(data)
    if @active_engine
      json["engine_name"] = @active_engine.name
    end

    case json["type"].downcase
    when "issue"
      issues << json
    when "warning"
      warnings << json
    else
      raise "Invalid type found: #{json["type"]}"
    end
  end
end