123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::Formatter::SimpleTextFormatter::Report

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: lib/rubocop/formatter/simple_text_formatter.rb

Overview

A helper class for building the report summary text.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(file_count, offense_count, correction_count, correctable_count, rainbow, safe_autocorrect: false) ⇒ Report

[ GitHub ]

  
# File 'lib/rubocop/formatter/simple_text_formatter.rb', line 110

def initialize(
  file_count, offense_count, correction_count, correctable_count, rainbow,
  safe_autocorrect: false
)
  @file_count = file_count
  @offense_count = offense_count
  @correction_count = correction_count
  @correctable_count = correctable_count
  @rainbow = rainbow
  @safe_autocorrect = safe_autocorrect
end

Instance Attribute Details

#rainbow (readonly, private)

[ GitHub ]

  
# File 'lib/rubocop/formatter/simple_text_formatter.rb', line 140

attr_reader :rainbow

Instance Method Details

#correctable (private)

[ GitHub ]

  
# File 'lib/rubocop/formatter/simple_text_formatter.rb', line 160

def correctable
  if @safe_autocorrect
    text = pluralize(@correctable_count, 'more offense')
    "#{colorize(text, :yellow)} can be corrected with `rubocop -A`"
  else
    text = pluralize(@correctable_count, 'offense')
    "#{colorize(text, :yellow)} autocorrectable"
  end
end

#corrections (private)

[ GitHub ]

  
# File 'lib/rubocop/formatter/simple_text_formatter.rb', line 153

def corrections
  text = pluralize(@correction_count, 'offense')
  color = @correction_count == @offense_count ? :green : :cyan

  colorize(text, color)
end

#files (private)

[ GitHub ]

  
# File 'lib/rubocop/formatter/simple_text_formatter.rb', line 142

def files
  pluralize(@file_count, 'file')
end

#offenses (private)

[ GitHub ]

  
# File 'lib/rubocop/formatter/simple_text_formatter.rb', line 146

def offenses
  text = pluralize(@offense_count, 'offense', no_for_zero: true)
  color = @offense_count.zero? ? :green : :red

  colorize(text, color)
end

#summary

[ GitHub ]

  
# File 'lib/rubocop/formatter/simple_text_formatter.rb', line 123

def summary
  if @correction_count.positive?
    if @correctable_count.positive?
      "#{files} inspected, #{offenses} detected, #{corrections} corrected, " \
        "#{correctable}"
    else
      "#{files} inspected, #{offenses} detected, #{corrections} corrected"
    end
  elsif @correctable_count.positive?
    "#{files} inspected, #{offenses} detected, #{correctable}"
  else
    "#{files} inspected, #{offenses} detected"
  end
end