Module: Overcommit::Hook::Shared::Pronto

Included in:
PreCommit::Pronto, PrePush::Pronto
Defined in:
lib/overcommit/hook/shared/pronto.rb

Overview

Constant Summary collapse

MESSAGE_TYPE_CATEGORIZER =
lambda do |type|
  type.include?('E') ? :error : :warning
end
MESSAGE_REGEX =
/^(?<file>(?:\w:)?[^:]+):(?<line>\d+) (?<type>[^ ]+)/.freeze

Instance Method Summary collapse

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/overcommit/hook/shared/pronto.rb', line 14

def run
  result = execute(command)
  return :pass if result.success?

  # e.g. runtime errors
  generic_errors = extract_messages(
    result.stderr.split("\n"),
    /^(?<type>[a-z]+)/i
  )

  pronto_infractions = extract_messages(
    result.stdout.split("\n").select { |line| line.match?(MESSAGE_REGEX) },
    MESSAGE_REGEX,
    MESSAGE_TYPE_CATEGORIZER,
  )

  generic_errors + pronto_infractions
end