class Danger::DangerWCC::Reek

Public Class Methods

new(plugin, options = {}) click to toggle source
# File lib/wcc/reek.rb, line 9
def initialize(plugin, options = {})
  @plugin = plugin
  @options = options
end

Public Instance Methods

perform() click to toggle source
# File lib/wcc/reek.rb, line 14
def perform
  # get the diff of new reek issues
  diff = run_reek_diff

  # run reek again to get line numbers
  reek_lines = run 'bundle exec reek --single-line --no-progress --no-color'
  reek_lines = reek_lines.lines

  each_addition_in_diff(diff) do |line|
    add_reek_warning(line, reek_lines[line.line_number.right - 1])
  end
end

Private Instance Methods

add_reek_warning(line, with_line_number) click to toggle source
# File lib/wcc/reek.rb, line 47
def add_reek_warning(line, with_line_number)
  return unless warning = line.content.match(/^\+?\s*([^\:]+\:\s+.+)$/i)

  line_info = with_line_number.match(/^\s*([^\:]+)\:(\d+)\:/i)
  plugin.warn(format_links_as_markdown(warning.captures[0]),
              file: line_info.captures[0],
              line: line_info.captures[1].to_i)
end
run_reek_diff() click to toggle source
# File lib/wcc/reek.rb, line 29
def run_reek_diff
  diff =
    run_and_diff do
      write_reek_config
      run('bundle exec reek --single-line --no-progress '\
      '--no-color --no-line-numbers')
    end
  GitDiff.from_string(diff)
end
write_reek_config() click to toggle source
# File lib/wcc/reek.rb, line 39
def write_reek_config
  return if File.exist?('.reek')
  return unless Dir.glob('*.reek').empty?

  default = File.join(File.dirname(__FILE__), 'defaults.reek')
  FileUtils.cp(default, './')
end