class Goodcheck::Reporters::JSON

Attributes

issues[R]
stderr[R]
stdout[R]

Public Class Methods

new(stdout:, stderr:) click to toggle source
# File lib/goodcheck/reporters/json.rb, line 8
def initialize(stdout:, stderr:)
  @stdout = stdout
  @stderr = stderr
  @issues = []
end

Public Instance Methods

analysis() { || ... } click to toggle source
# File lib/goodcheck/reporters/json.rb, line 14
def analysis
  yield

  json = issues.map do |issue|
    location = issue.location
    {
      rule_id: issue.rule.id,
      path: issue.path,
      location: location && {
        start_line: location.start_line,
        start_column: location.start_column,
        end_line: location.end_line,
        end_column: location.end_column
      },
      message: issue.rule.message,
      justifications: issue.rule.justifications,
      severity: issue.rule.severity
    }
  end
  stdout.puts ::JSON.dump(json)
  json
end
file(path) { || ... } click to toggle source
# File lib/goodcheck/reporters/json.rb, line 37
def file(path)
  yield
end
issue(issue) click to toggle source
# File lib/goodcheck/reporters/json.rb, line 45
def issue(issue)
  issues << issue
end
rule(rule) { || ... } click to toggle source
# File lib/goodcheck/reporters/json.rb, line 41
def rule(rule)
  yield
end
summary() click to toggle source
# File lib/goodcheck/reporters/json.rb, line 49
def summary
  # noop
end