Class: RuboCop::Formatter::DisabledConfigFormatter

Inherits:
BaseFormatter
  • Object
show all
Defined in:
lib/rubocop/formatter/disabled_config_formatter.rb

Overview

This formatter displays a YAML configuration file where all cops that detected any offenses are configured to not detect the offense.

Constant Summary collapse

HEADING =
['# This configuration was generated by',
 '# `%s`',
 "# on #{Time.now} using RuboCop version #{Version.version}.",
 '# The point is for the user to remove these configuration records',
 '# one by one as the offenses are removed from the code base.',
 '# Note that changes in the inspected code, or installation of new',
 '# versions of RuboCop, may require this file to be generated again.']
.join("\n")
COPS =
Cop::Cop.all.group_by(&:cop_name)

Class Attribute Summary collapse

Attributes inherited from BaseFormatter

#options, #output

Instance Method Summary collapse

Methods inherited from BaseFormatter

#started

Constructor Details

#initialize(output, options = {}) ⇒ DisabledConfigFormatter

Returns a new instance of DisabledConfigFormatter.



27
28
29
30
31
# File 'lib/rubocop/formatter/disabled_config_formatter.rb', line 27

def initialize(output, options = {})
  super
  @cops_with_offenses ||= Hash.new(0)
  @files_with_offenses ||= {}
end

Class Attribute Details

.config_to_allow_offensesObject

Returns the value of attribute config_to_allow_offenses.



24
25
26
# File 'lib/rubocop/formatter/disabled_config_formatter.rb', line 24

def config_to_allow_offenses
  @config_to_allow_offenses
end

.detected_stylesObject

Returns the value of attribute detected_styles.



24
25
26
# File 'lib/rubocop/formatter/disabled_config_formatter.rb', line 24

def detected_styles
  @detected_styles
end

Instance Method Details

#file_finished(file, offenses) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/rubocop/formatter/disabled_config_formatter.rb', line 41

def file_finished(file, offenses)
  offenses.each do |o|
    @cops_with_offenses[o.cop_name] += 1
    @files_with_offenses[o.cop_name] ||= []
    @files_with_offenses[o.cop_name] << file
  end
end

#file_started(_file, _file_info) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/rubocop/formatter/disabled_config_formatter.rb', line 33

def file_started(_file, _file_info)
  @exclude_limit_option = @options[:exclude_limit]
  @exclude_limit = (
    @exclude_limit_option ||
    RuboCop::Options::DEFAULT_MAXIMUM_EXCLUSION_ITEMS).to_i
  @show_offense_counts = !@options[:no_offense_counts]
end

#finished(_inspected_files) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rubocop/formatter/disabled_config_formatter.rb', line 49

def finished(_inspected_files)
  output.puts HEADING % command

  # Syntax isn't a real cop and it can't be disabled.
  @cops_with_offenses.delete('Syntax')

  output_offenses

  puts "Created #{output.path}."
  puts "Run `rubocop --config #{output.path}`, or add `inherit_from: " \
       "#{output.path}` in a .rubocop.yml file."
end