Class: PreCommit::Checks::GoFmt
- Inherits:
-
Plugin
- Object
- Plugin
- PreCommit::Checks::GoFmt
show all
- Defined in:
- lib/plugins/pre_commit/checks/go_fmt.rb
Instance Attribute Summary
Attributes inherited from Plugin
#config, #pluginator
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Plugin
#initialize, #name
Class Method Details
.description ⇒ Object
20
21
22
|
# File 'lib/plugins/pre_commit/checks/go_fmt.rb', line 20
def self.description
"Detects bad Go formatting"
end
|
Instance Method Details
#call(staged_files) ⇒ Object
5
6
7
8
9
10
11
12
13
|
# File 'lib/plugins/pre_commit/checks/go_fmt.rb', line 5
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
15
16
17
18
|
# File 'lib/plugins/pre_commit/checks/go_fmt.rb', line 15
def run_check(file)
cmd = "gofmt -l #{file} 2>&1"
%x[ #{cmd} ]
end
|