class Overcommit::Hook::PreCommit::CookStyle

Runs ‘cookstyle` against any modified Chef Ruby files.

@see docs.chef.io/cookstyle.html

Constants

COP_MESSAGE_TYPE_CATEGORIZER
GENERIC_MESSAGE_TYPE_CATEGORIZER

Public Instance Methods

run() click to toggle source
# File lib/overcommit/hook/pre_commit/cook_style.rb, line 16
def run
  result = execute(command, args: applicable_files)
  return :pass if result.success?

  generic_messages = extract_messages(
    result.stderr.split("\n"),
    /^(?<type>[a-z]+)/i,
    GENERIC_MESSAGE_TYPE_CATEGORIZER,
  )

  cop_messages = extract_messages(
    result.stdout.split("\n"),
    /^(?<file>(?:\w:)?[^:]+):(?<line>\d+):[^ ]+ (?<type>[^ ]+)/,
    COP_MESSAGE_TYPE_CATEGORIZER,
  )

  generic_messages + cop_messages
end