Sha256: 84c63a4235b43d18b312e63db38196fce9f31c4e7ec82e156bbb11576bbd7923

Contents?: true

Size: 998 Bytes

Versions: 4

Compression:

Stored size: 998 Bytes

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
        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)
        yield
      end

      def rule(rule)
        yield
      end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
goodcheck-1.5.1 lib/goodcheck/reporters/json.rb
goodcheck-1.5.0 lib/goodcheck/reporters/json.rb
goodcheck-1.4.1 lib/goodcheck/reporters/json.rb
goodcheck-1.4.0 lib/goodcheck/reporters/json.rb