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.



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

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.



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

def config_to_allow_offenses
  @config_to_allow_offenses
end

.detected_stylesObject

Returns the value of attribute detected_styles.



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

def detected_styles
  @detected_styles
end

Instance Method Details

#file_finished(file, offenses) ⇒ Object



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

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



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

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



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

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