Class: Goodcheck::Reporters::JSON

Inherits:
Object
  • Object
show all
Defined in:
lib/goodcheck/reporters/json.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout:, stderr:) ⇒ JSON

Returns a new instance of JSON.



8
9
10
11
12
# File 'lib/goodcheck/reporters/json.rb', line 8

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

Instance Attribute Details

#issuesObject (readonly)

Returns the value of attribute issues.



6
7
8
# File 'lib/goodcheck/reporters/json.rb', line 6

def issues
  @issues
end

#stderrObject (readonly)

Returns the value of attribute stderr.



5
6
7
# File 'lib/goodcheck/reporters/json.rb', line 5

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



4
5
6
# File 'lib/goodcheck/reporters/json.rb', line 4

def stdout
  @stdout
end

Instance Method Details

#analysisObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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) ⇒ Object



37
38
39
# File 'lib/goodcheck/reporters/json.rb', line 37

def file(path)
  yield
end

#issue(issue) ⇒ Object



45
46
47
# File 'lib/goodcheck/reporters/json.rb', line 45

def issue(issue)
  issues << issue
end

#rule(rule) ⇒ Object



41
42
43
# File 'lib/goodcheck/reporters/json.rb', line 41

def rule(rule)
  yield
end

#summaryObject



49
50
51
# File 'lib/goodcheck/reporters/json.rb', line 49

def summary
  # noop
end