class Pronto::TerraformFormatRunner

Public Class Methods

new(patches, commit = nil) click to toggle source
Calls superclass method
# File lib/pronto/terraform_format_runner.rb, line 8
def initialize(patches, commit = nil)
  super
  @inspector = ::Pronto::TerraformFormat::Wrapper.new
  if ENV['PRONTO_TERRAFORM_FORMAT_FILE_EXTS'].nil?
    @tf_extensions = %w[.tf .tfvars]
  else
    comma_separated_exts = ENV['PRONTO_TERRAFORM_FORMAT_FILE_EXTS']
    @tf_extensions = comma_separated_exts.split(',').map(&:strip)
  end
end

Public Instance Methods

inspect(patch) click to toggle source
# File lib/pronto/terraform_format_runner.rb, line 28
def inspect(patch)
  messages = []

  file_path = patch.new_file_full_path.to_s
  offences = @inspector.run(file_path)
  if not offences[file_path].nil?
    offences[file_path].each do |offence|
      messages += patch
        .added_lines
        .select { |line| line.new_lineno == offence[:line] }
        .map { |line| new_message(offence, line) }
    end
  end

  messages.compact
end
new_message(offence, line) click to toggle source
# File lib/pronto/terraform_format_runner.rb, line 49
def new_message(offence, line)
  Message.new(
    offence[:file],
    line,
    :warning,
    offence[:message],
    nil,
    self.class
  )
end
run() click to toggle source
# File lib/pronto/terraform_format_runner.rb, line 19
def run
  return [] if !@patches || @patches.count.zero?
  @patches
    .select { |p| tf_file?(p.new_file_full_path) }
    .map { |p| inspect(p) }
    .flatten.compact
    .uniq(&:line) # generate only one message per line
end
tf_file?(file_path) click to toggle source
# File lib/pronto/terraform_format_runner.rb, line 45
def tf_file?(file_path)
  @tf_extensions.include? File.extname(file_path)
end