Sha256: a8b34ed8ee056615e1246d4cf2bfc28a4e75b4d3170960cf384f23e6625714a4

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

module Goodcheck
  module Reporters
    class JSON
      attr_reader :stdout
      attr_reader :stderr
      attr_reader :issues

      def initialize(stdout:, stderr:)
        @stdout = stdout
        @stderr = stderr
        @issues = []
      end

      def analysis
        stderr.puts "Starting analysis..."
        yield

        json = issues.map do |issue|
          {
            rule_id: issue.rule.id,
            path: issue.path,
            location: {
              start_line: issue.location.start_line,
              start_column: issue.location.start_column,
              end_line: issue.location.end_line,
              end_column: issue.location.end_column
            },
            message: issue.rule.message,
            justifications: issue.rule.justifications
          }
        end
        stdout.puts ::JSON.dump(json)
        json
      end

      def file(path)
        stderr.puts "Checking #{path}..."
        yield
      end

      def rule(rule)
        stderr.puts "  Checking #{rule.id}..."
        yield
      end

      def issue(issue)
        issues << issue
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
goodcheck-1.3.1 lib/goodcheck/reporters/json.rb
goodcheck-1.2.0 lib/goodcheck/reporters/json.rb