Sha256: 4e28e8167290f0da59a09912edaeccf8ad83ced8b03b95f2ceebe0f3567b49ea

Contents?: true

Size: 745 Bytes

Versions: 10

Compression:

Stored size: 745 Bytes

Contents

require "digest/md5"

module CC
  module Analyzer
    class SourceFingerprint
      def initialize(issue)
        @issue = issue
      end

      def compute
        md5 = Digest::MD5.new
        md5 << issue.path
        md5 << issue.check_name.to_s
        md5 << relevant_source.gsub(/\s+/, "") if relevant_source
        md5.hexdigest
      end

      private

      attr_reader :issue

      def relevant_source
        source = SourceExtractor.new(raw_source).extract(issue.location)

        if source && !source.empty?
          source.encode(Encoding::UTF_8, "binary", invalid: :replace, undef: :replace, replace: "")
        end
      end

      def raw_source
        @raw_source ||= File.read(issue.path)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
codeclimate-0.32.0 lib/cc/analyzer/source_fingerprint.rb
codeclimate-0.32.0.rc1 lib/cc/analyzer/source_fingerprint.rb
codeclimate-0.31.1 lib/cc/analyzer/source_fingerprint.rb
codeclimate-0.31.0 lib/cc/analyzer/source_fingerprint.rb
codeclimate-0.30.1 lib/cc/analyzer/source_fingerprint.rb
codeclimate-0.30.0 lib/cc/analyzer/source_fingerprint.rb
codeclimate-0.29.0 lib/cc/analyzer/source_fingerprint.rb
codeclimate-0.28.0 lib/cc/analyzer/source_fingerprint.rb
codeclimate-0.27.2 lib/cc/analyzer/source_fingerprint.rb
codeclimate-0.27.1 lib/cc/analyzer/source_fingerprint.rb