Class: PreCommit::Checks::GoBuild

Inherits:
Plugin
  • Object
show all
Defined in:
lib/plugins/pre_commit/checks/go_build.rb

Instance Attribute Summary

Attributes inherited from Plugin

#config, #pluginator

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Plugin

#initialize, #name

Constructor Details

This class inherits a constructor from PreCommit::Checks::Plugin

Class Method Details

.descriptionObject



22
23
24
# File 'lib/plugins/pre_commit/checks/go_build.rb', line 22

def self.description
  "Detects Go compiler errors"
end

Instance Method Details

#call(staged_files) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/plugins/pre_commit/checks/go_build.rb', line 7

def call(staged_files)
  staged_files = staged_files.grep(/\.go$/)
  return if staged_files.empty?

  errors = staged_files.map { |file| run_check(file) }.compact
  return if errors.empty?

  errors.join("\n")
end

#run_check(file) ⇒ Object



17
18
19
20
# File 'lib/plugins/pre_commit/checks/go_build.rb', line 17

def run_check(file)
  cmd = "go build -o /dev/null #{file} 2>&1"
  %x[ #{cmd} ]
end