Sha256: a767c6e4dcb3419369d0d5377454b10be03695501b537912ea9bbeca6ed7613a

Contents?: true

Size: 837 Bytes

Versions: 157

Compression:

Stored size: 837 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 ||=
          if File.file?(issue.path)
            File.read(issue.path)
          else
            ""
          end
      end
    end
  end
end

Version data entries

157 entries across 157 versions & 2 rubygems

Version Path
codeclimate-fede-0.85.38 lib/cc/analyzer/source_fingerprint.rb
codeclimate-fede-0.85.37 lib/cc/analyzer/source_fingerprint.rb
codeclimate-fede-0.85.36 lib/cc/analyzer/source_fingerprint.rb
codeclimate-fede-0.85.35 lib/cc/analyzer/source_fingerprint.rb
codeclimate-fede-0.85.33 lib/cc/analyzer/source_fingerprint.rb
codeclimate-fede-0.85.32 lib/cc/analyzer/source_fingerprint.rb
codeclimate-fede-0.85.31 lib/cc/analyzer/source_fingerprint.rb
codeclimate-fede-0.85.30 lib/cc/analyzer/source_fingerprint.rb
codeclimate-fede-0.85.21 lib/cc/analyzer/source_fingerprint.rb
codeclimate-fede-0.85.24 lib/cc/analyzer/source_fingerprint.rb
codeclimate-fede-0.85.23 lib/cc/analyzer/source_fingerprint.rb
codeclimate-0.85.23 lib/cc/analyzer/source_fingerprint.rb
codeclimate-0.85.22 lib/cc/analyzer/source_fingerprint.rb
codeclimate-0.85.21 lib/cc/analyzer/source_fingerprint.rb
codeclimate-0.85.19 lib/cc/analyzer/source_fingerprint.rb
codeclimate-0.85.18 lib/cc/analyzer/source_fingerprint.rb
codeclimate-0.85.17 lib/cc/analyzer/source_fingerprint.rb
codeclimate-0.85.15 lib/cc/analyzer/source_fingerprint.rb
codeclimate-0.85.14 lib/cc/analyzer/source_fingerprint.rb
codeclimate-0.85.13 lib/cc/analyzer/source_fingerprint.rb