Class: RuboCop::Formatter::ClangStyleFormatter

Inherits:
SimpleTextFormatter show all
Defined in:
lib/rubocop/formatter/clang_style_formatter.rb

Overview

This formatter formats report data in clang style. The precise location of the problem is shown together with the relevant source code.

Direct Known Subclasses

FuubarStyleFormatter, ProgressFormatter

Constant Summary

Constants inherited from SimpleTextFormatter

SimpleTextFormatter::COLOR_FOR_SEVERITY

Instance Attribute Summary

Attributes inherited from BaseFormatter

#options, #output

Instance Method Summary collapse

Methods inherited from SimpleTextFormatter

#file_finished, #finished, #report_summary, #started

Methods included from Colorizable

#colorize, #rainbow

Methods included from PathUtil

absolute?, hidden?, issue_deprecation_warning, match_path?, relative_path

Methods inherited from BaseFormatter

#file_finished, #file_started, #finished, #initialize, #started

Constructor Details

This class inherits a constructor from RuboCop::Formatter::BaseFormatter

Instance Method Details

#highlight_line(location) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/rubocop/formatter/clang_style_formatter.rb', line 24

def highlight_line(location)
  column_length = if location.begin.line == location.end.line
                    location.column_range.count
                  else
                    location.source_line.length - location.column
                  end

  ' ' * location.column + '^' * column_length
end

#report_file(file, offenses) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rubocop/formatter/clang_style_formatter.rb', line 10

def report_file(file, offenses)
  offenses.each do |o|
    output.printf("%s:%d:%d: %s: %s\n",
                  cyan(smart_path(file)), o.line, o.real_column,
                  colored_severity_code(o), message(o))

    source_line = o.location.source_line
    next if source_line.blank?

    output.puts(source_line)
    output.puts(highlight_line(o.location))
  end
end