Sha256: 10762fcf18d6b5566acae506049e02ba89210982a7270a8c495e3d6c52c6ca2b

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

require 'pronto'
require 'reek'

module Pronto
  class Reek < Runner
    def run(patches, _)
      return [] unless patches

      patches_with_additions = patches.select { |patch| patch.additions > 0 }
        .select { |patch| ruby_file?(patch.new_file_full_path) }
      files = patches_with_additions.map(&:new_file_full_path)

      smells = files.flat_map do |file|
        ::Reek::Examiner.new(file).smells
      end
      messages_for(patches_with_additions, smells).compact
    end

    private

    def messages_for(patches, errors)
      errors.map do |error|
        patch = patch_for_error(patches, error)
        next if patch.nil?

        line = patch.added_lines.find do |added_line|
          error.lines.find { |error_line| error_line == added_line.new_lineno }
        end

        new_message(line, error) if line
      end
    end

    def new_message(line, error)
      Message.new(line.patch.delta.new_file[:path], line, :warning,
                  "#{error.message.capitalize} (#{error.smell_type})")
    end

    def patch_for_error(patches, error)
      patches.find do |patch|
        patch.new_file_full_path.to_s == error.source
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pronto-reek-0.5.1 lib/pronto/reek.rb