Sha256: 4597aec8379a46d6b80e9a864b215393dc12889c66509766902b9806f6673f8b

Contents?: true

Size: 1.43 KB

Versions: 6

Compression:

Stored size: 1.43 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

6 entries across 6 versions & 1 rubygems

Version Path
danger-wcc-0.1.4 lib/wcc/reek.rb
danger-wcc-0.1.3 lib/wcc/reek.rb
danger-wcc-0.1.2 lib/wcc/reek.rb
danger-wcc-0.1.1 lib/wcc/reek.rb
danger-wcc-0.1.0 lib/wcc/reek.rb
danger-wcc-0.0.6 lib/wcc/reek.rb