class RuboCop::Formatter::DisabledLinesFormatter

A basic formatter that displays the lines disabled inline comments.

Attributes

cop_disabled_line_ranges[R]

Public Instance Methods

file_started(file, options) click to toggle source
# File lib/rubocop/formatter/disabled_lines_formatter.rb, line 17
def file_started(file, options)
  return unless options[:cop_disabled_line_ranges]

  @cop_disabled_line_ranges[file] =
    options[:cop_disabled_line_ranges]
end
finished(_inspected_files) click to toggle source
# File lib/rubocop/formatter/disabled_lines_formatter.rb, line 24
def finished(_inspected_files)
  cops_disabled_in_comments_summary
end
started(_target_files) click to toggle source
# File lib/rubocop/formatter/disabled_lines_formatter.rb, line 13
def started(_target_files)
  @cop_disabled_line_ranges = {}
end

Private Instance Methods

cops_disabled_in_comments_summary() click to toggle source
# File lib/rubocop/formatter/disabled_lines_formatter.rb, line 30
def cops_disabled_in_comments_summary
  summary = "\nCops disabled line ranges:\n\n"

  @cop_disabled_line_ranges.each do |file, disabled_cops|
    disabled_cops.each do |cop, line_ranges|
      line_ranges.each do |line_range|
        file = cyan(smart_path(file))
        summary += "#{file}:#{line_range}: #{cop}\n"
      end
    end
  end

  output.puts summary
end
smart_path(path) click to toggle source
# File lib/rubocop/formatter/disabled_lines_formatter.rb, line 45
def smart_path(path)
  # Ideally, we calculate this relative to the project root.
  base_dir = Dir.pwd

  if path.start_with? base_dir
    relative_path(path, base_dir)
  else
    path
  end
end