Class: RuboCop::Formatter::DisabledConfigFormatter

Inherits:
BaseFormatter
  • Object
show all
Includes:
PathUtil
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 =
<<~COMMENTS
  # This configuration was generated by
  # `%<command>s`
  # %<timestamp>susing 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.
COMMENTS

Constants included from PathUtil

PathUtil::HIDDEN_FILE_PATTERN

Class Attribute Summary collapse

Attributes inherited from BaseFormatter

#options, #output

Instance Method Summary collapse

Methods included from PathUtil

absolute?, glob?, hidden_dir?, hidden_file?, hidden_file_in_not_hidden_dir?, match_path?, maybe_hidden_file?, relative_path, smart_path

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



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

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

#file_started(_file, options) ⇒ Object



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

def file_started(_file, options)
  @config_for_pwd = options[:config_store].for_pwd
  @exclude_limit_option = @options[:exclude_limit]
  @exclude_limit = Integer(@exclude_limit_option ||
    RuboCop::Options::DEFAULT_MAXIMUM_EXCLUSION_ITEMS)
end

#finished(_inspected_files) ⇒ Object



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

def finished(_inspected_files)
  output.puts format(HEADING, command: command, timestamp: timestamp)

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

  output_offenses

  puts "Created #{output.path}."
end