Sha256: 14ca06013a7fbb7a90d445f193d9fe53c3ae3b5275538c9a24732b81ea1cb1f7

Contents?: true

Size: 849 Bytes

Versions: 14

Compression:

Stored size: 849 Bytes

Contents

module CC
  module Analyzer
    class EngineOutputFilter
      ISSUE_TYPE = "issue".freeze

      def initialize(config = {})
        @config = config
      end

      def filter?(output)
        return true unless output.present?

        if (json = parse_as_json(output))
          issue?(json) && ignore_issue?(json)
        else
          false
        end
      end

      private

      def parse_as_json(output)
        JSON.parse(output)
      rescue JSON::ParserError
        nil
      end

      def issue?(json)
        json["type"] && json["type"].downcase == ISSUE_TYPE
      end

      def ignore_issue?(json)
        !check_config(json["check_name"]).fetch("enabled", true)
      end

      def check_config(check_name)
        @checks ||= @config.fetch("checks", {})
        @checks.fetch(check_name, {})
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
codeclimate-0.14.2 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.14.1 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.14.0 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.13.0 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.11.0 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.10.1 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.10.0 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.9.7 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.9.6 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.9.5 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.9.4 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.9.3 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.9.2 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.9.1 lib/cc/analyzer/engine_output_filter.rb