Skip to content

Commit

Permalink
Reduce complexity in DisabledConfigFormatter
Browse files Browse the repository at this point in the history
Split `finished` into smaller methods.
  • Loading branch information
lumeet authored and Neodelf committed Oct 15, 2016
1 parent 65cc169 commit 5d528d1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
10 changes: 5 additions & 5 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-05-14 15:43:21 +0300 using RuboCop version 0.40.0.
# on 2016-05-21 20:33:18 +0300 using RuboCop version 0.40.0.
# 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.

# Offense count: 203
# Offense count: 195
Metrics/AbcSize:
Max: 26
Max: 25

# Offense count: 22
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 160

# Offense count: 71
# Offense count: 72
Metrics/CyclomaticComplexity:
Max: 9

# Offense count: 237
# Offense count: 230
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 20
Expand Down
34 changes: 24 additions & 10 deletions lib/rubocop/formatter/disabled_config_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,41 @@ def file_finished(file, offenses)
end

def finished(_inspected_files)
command = 'rubocop --auto-gen-config'
if @exclude_limit_option
command += format(' --exclude-limit %d', @exclude_limit_option.to_i)
end
output.puts HEADING % command

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

@cops_with_offenses.sort.each do |cop_name, offense_count|
output.puts
cfg = self.class.config_to_allow_offenses[cop_name] || {}
output_offenses

output_cop_comments(output, cfg, cop_name, offense_count)
output_cop_config(output, cfg, cop_name)
end
puts "Created #{output.path}."
puts "Run `rubocop --config #{output.path}`, or add `inherit_from: " \
"#{output.path}` in a .rubocop.yml file."
end

def command
command = 'rubocop --auto-gen-config'
if @exclude_limit_option
command += format(' --exclude-limit %d', @exclude_limit_option.to_i)
end

command
end

def output_offenses
@cops_with_offenses.sort.each do |cop_name, offense_count|
output_cop(cop_name, offense_count)
end
end

def output_cop(cop_name, offense_count)
output.puts
cfg = self.class.config_to_allow_offenses[cop_name] || {}

output_cop_comments(output, cfg, cop_name, offense_count)
output_cop_config(output, cfg, cop_name)
end

def output_cop_comments(output, cfg, cop_name, offense_count)
output.puts "# Offense count: #{offense_count}" if @show_offense_counts
if COPS[cop_name] && COPS[cop_name].first.new.support_autocorrect?
Expand Down

0 comments on commit 5d528d1

Please sign in to comment.