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
# File 'lib/goodcheck/reporters/json.rb', line 14

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

#file(path) ⇒ Object



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

def file(path)
  stderr.puts "Checking #{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



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

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