Class: PreCommit::Checks::Whitespace
- Inherits:
-
Plugin
- Object
- Plugin
- PreCommit::Checks::Whitespace
show all
- Defined in:
- lib/plugins/pre_commit/checks/whitespace.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
.aliases ⇒ Object
7
8
9
|
# File 'lib/plugins/pre_commit/checks/whitespace.rb', line 7
def self.aliases
[:white_space]
end
|
.description ⇒ Object
40
41
42
|
# File 'lib/plugins/pre_commit/checks/whitespace.rb', line 40
def self.description
"Finds white space."
end
|
Instance Method Details
#call(staged_files) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/plugins/pre_commit/checks/whitespace.rb', line 25
def call(staged_files)
return if staged_files.empty?
errors = `git diff-index --check --cached HEAD -- #{files_string(staged_files)} 2>&1`
return if $?.success?
if errors =~ /fatal: bad revision 'HEAD'/
errors = `git diff-index --check --cached 4b825dc642cb6eb9a060e54bf8d69288fbee4904 -- 2>&1`
return if $?.success?
end
errors
end
|
#files_filter(staged_files) ⇒ Object
11
12
13
14
15
16
17
18
19
|
# File 'lib/plugins/pre_commit/checks/whitespace.rb', line 11
def files_filter(staged_files)
if
@list.map(&:name).include?("PreCommit::Checks::Rubocop")
then
staged_files.reject{|name| name =~ /\.rb$/ }
else
staged_files
end
end
|
#files_string(staged_files) ⇒ Object
21
22
23
|
# File 'lib/plugins/pre_commit/checks/whitespace.rb', line 21
def files_string(staged_files)
files_filter(staged_files).map{|file| "'#{file}'" }.join(" ")
end
|