Class: Pronto::TerraformFormat::OutputParser

Inherits:
Object
  • Object
show all
Defined in:
lib/pronto/terraform_format/output_parser.rb

Instance Method Summary collapse

Instance Method Details

#parse(file_path, output) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pronto/terraform_format/output_parser.rb', line 8

def parse(file_path, output)
  begin
    # skip first line
    diff = UnifiedDiff.parse(output.lines[3..output.lines.length].join(''))
  rescue StandardError => e
    puts "pronto-terraform_format ERROR: failed to parse output. #{e}"
    return {}
  end

  result = {}
  diff.chunks.each do |chunk|
    file = file_path
    result[file] ||= []
    result[file] << {
      file: file,
      line: chunk.modified_range.min,
      message: 'Needs to run terraform fmt'
    }
  end
  result
end