Class: Overcommit::Hook::PreCommit::Scalastyle

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

Overview

Runs ‘scalastyle` against any modified Scala files.

Constant Summary collapse

MESSAGE_REGEX =
/
  ^(?<type>error|warning)\s
  file=(?<file>(?:\w:)?.+)\s
  message=.+\s
  line=(?<line>\d+)
/x

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#applicable_files, #command, #description, #enabled?, #execute, #execute_in_background, #flags, #in_path?, #initialize, #name, #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



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/overcommit/hook/pre_commit/scalastyle.rb', line 13

def run
  result = execute(command, args: applicable_files)
  output = result.stdout.chomp
  messages = output.split("\n").grep(MESSAGE_REGEX)
  return :pass if result.success? && messages.empty?

  # example message:
  #   error file=/path/to/file.scala message=Error message line=1 column=1
  extract_messages(
    messages,
    MESSAGE_REGEX,
    lambda { |type| type.to_sym }
  )
end