Class: Overcommit::Hook::PreCommit::Solargraph

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

Overview

Runs ‘solargraph typecheck` against any modified Ruby files.

Constant Summary collapse

MESSAGE_REGEX =
/^\s*(?<file>(?:\w:)?[^:]+):(?<line>\d+) - /.freeze

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



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

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

  stderr_lines = remove_harmless_glitches(result.stderr)
  violation_lines = result.stdout.split("\n").grep(MESSAGE_REGEX)
  if violation_lines.empty?
    if stderr_lines.empty?
      [:fail, 'Solargraph failed to run']
    else
      # let's feed it stderr so users see the errors
      extract_messages(stderr_lines, MESSAGE_REGEX)
    end
  else
    extract_messages(violation_lines, MESSAGE_REGEX)
  end
end