Sha256: 5d8ca1fb71c8ad7604ac9f952e1d2616cec09f2a8c29fffd095f0fa81d3dc6ce

Contents?: true

Size: 1.41 KB

Versions: 4

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

require_relative 'utils'

class Danger::DangerWCC < Danger::Plugin
  class Reek
    include Utils

    def initialize(plugin, options = {})
      @plugin = plugin
      @options = options
    end

    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

    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

    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

    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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
danger-wcc-0.0.5 lib/wcc/reek.rb
danger-wcc-0.0.4 lib/wcc/reek.rb
danger-wcc-0.0.3 lib/wcc/reek.rb
danger-wcc-0.0.2 lib/wcc/reek.rb