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?, #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



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

def run
  result = execute(command, args: applicable_files)
  output = result.stdout.chomp + result.stderr.chomp
  messages = output.split("\n").grep(MESSAGE_REGEX)

  return [:fail, output] unless result.success? || messages.any?

  # 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