Sha256: 6f1e4f1b97f35b292a67a1b57a4060c455817b32339a465131859b523cfc991f

Contents?: true

Size: 805 Bytes

Versions: 13

Compression:

Stored size: 805 Bytes

Contents

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

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

      def filter?(output)
        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

13 entries across 13 versions & 1 rubygems

Version Path
codeclimate-0.9.0 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.8.1 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.8.0 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.7.2 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.7.0 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.6.4 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.6.3 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.6.2 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.6.1 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.6.0 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.5.0 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.4.4 lib/cc/analyzer/engine_output_filter.rb
codeclimate-0.4.3 lib/cc/analyzer/engine_output_filter.rb