Skip to content

Commit

Permalink
Address complexity rubocop issues
Browse files Browse the repository at this point in the history
  • Loading branch information
maxjacobson authored and bbatsov committed Feb 3, 2022
1 parent 2ca25cd commit ab1e5b7
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/rubocop/formatter/disabled_config_formatter.rb
Expand Up @@ -122,12 +122,11 @@ def output_cop_comments(output_buffer, cfg, cop_name, offense_count)

cop_class = Cop::Registry.global.find_by_cop_name(cop_name)
default_cfg = default_config(cop_name)
if cop_class&.support_autocorrect?
if default_cfg.nil? || default_cfg['Safe'] || default_cfg['Safe'].nil?
output_buffer.puts '# Cop supports --auto-correct.'
else
output_buffer.puts '# Cop supports --auto-correct-all.'
end

if supports_safe_auto_correct?(cop_class, default_cfg)
output_buffer.puts '# Cop supports --auto-correct.'
elsif supports_unsafe_autocorrect?(cop_class, default_cfg)
output_buffer.puts '# Cop supports --auto-correct-all.'
end

return unless default_cfg
Expand All @@ -138,6 +137,15 @@ def output_cop_comments(output_buffer, cfg, cop_name, offense_count)
output_cop_param_comments(output_buffer, params, default_cfg)
end

def supports_safe_auto_correct?(cop_class, default_cfg)
cop_class&.support_autocorrect? &&
(default_cfg.nil? || default_cfg['Safe'] || default_cfg['Safe'].nil?)
end

def supports_unsafe_autocorrect?(cop_class, default_cfg)
cop_class&.support_autocorrect? && !default_cfg.nil? && default_cfg['Safe'] == false
end

def cop_config_params(default_cfg, cfg)
default_cfg.keys -
%w[Description StyleGuide Reference Enabled Exclude Safe
Expand Down

0 comments on commit ab1e5b7

Please sign in to comment.