Sha256: 68529152c53d5acf338b59f1582d4eaa9b5b36fa05e2f764862f101d35706add

Contents?: true

Size: 1.38 KB

Versions: 6

Compression:

Stored size: 1.38 KB

Contents

module CC
  module Analyzer
    class Issue
      DEFAULT_SEVERITY = IssueValidations::SeverityValidation::MINOR
      DEPRECATED_SEVERITY = IssueValidations::SeverityValidation::NORMAL

      SPEC_ISSUE_ATTRIBUTES = %w[
        categories
        check_name
        content
        description
        location
        other_locations
        remediation_points
        severity
        type
      ]

      def initialize(output)
        @output = output
      end

      def as_json(*)
        parsed_output.reverse_merge!(
          "fingerprint" => fingerprint,
        ).merge!("severity" => severity)
      end

      def fingerprint
        parsed_output.fetch("fingerprint") { default_fingerprint }
      end

      # Allow access to hash keys as methods
      SPEC_ISSUE_ATTRIBUTES.each do |key|
        define_method(key) do
          parsed_output[key]
        end
      end

      def path
        parsed_output.fetch("location", {}).fetch("path", "")
      end

      private

      attr_reader :output

      def default_fingerprint
        SourceFingerprint.new(self).compute
      end

      def severity
        severity = parsed_output.fetch("severity", DEFAULT_SEVERITY)

        if severity == DEPRECATED_SEVERITY
          DEFAULT_SEVERITY
        else
          severity
        end
      end

      def parsed_output
        @parsed_output ||= JSON.parse(output)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
codeclimate-0.69.0 lib/cc/analyzer/issue.rb
codeclimate-0.68.0 lib/cc/analyzer/issue.rb
codeclimate-0.67.0 lib/cc/analyzer/issue.rb
codeclimate-0.66.0 lib/cc/analyzer/issue.rb
codeclimate-0.65.0 lib/cc/analyzer/issue.rb
codeclimate-0.64.0 lib/cc/analyzer/issue.rb