Class: Overcommit::Hook::PreCommit::Hlint

Inherits:
Base
  • Object
show all
Defined in:
lib/overcommit/hook/pre_commit/hlint.rb

Overview

Runs ‘hlint` against any modified Haskell files.

Constant Summary collapse

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

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#applicable_files, #command, #description, #enabled?, #excluded?, #execute, #execute_in_background, #flags, #in_path?, #included_files, #initialize, #name, #parallelize?, #processors, #quiet?, #required?, #required_executable, #required_libraries, #run?, #run_and_transform, #skip?

Constructor Details

This class inherits a constructor from Overcommit::Hook::Base

Instance Method Details

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/overcommit/hook/pre_commit/hlint.rb', line 19

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

  raw_messages = result.stdout.split("\n").grep(MESSAGE_REGEX)

  # example message:
  #   path/to/file.hs:1:0: Error: message
  extract_messages(
    raw_messages,
    MESSAGE_REGEX,
    MESSAGE_TYPE_CATEGORIZER
  )
end