Class: PreCommit::Tabs
- Inherits:
-
Object
- Object
- PreCommit::Tabs
- Defined in:
- lib/pre-commit/checks/tabs.rb
Constant Summary collapse
- LEADING_TAB_PATTERN =
'^ *\t'
Instance Attribute Summary collapse
-
#error_message ⇒ Object
Returns the value of attribute error_message.
-
#staged_files ⇒ Object
Returns the value of attribute staged_files.
Class Method Summary collapse
-
.call ⇒ Object
Maintaining the functionality of ‘call` for backwards compatibility Currently, the call method is expected to: * run a check * print any corresponding error messages if the check fails.
Instance Method Summary collapse
Instance Attribute Details
#error_message ⇒ Object
Returns the value of attribute error_message.
6 7 8 |
# File 'lib/pre-commit/checks/tabs.rb', line 6 def @error_message end |
#staged_files ⇒ Object
Returns the value of attribute staged_files.
6 7 8 |
# File 'lib/pre-commit/checks/tabs.rb', line 6 def staged_files @staged_files end |
Class Method Details
.call ⇒ Object
Maintaining the functionality of ‘call` for backwards compatibility Currently, the call method is expected to:
-
run a check
-
print any corresponding error messages if the check fails
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/pre-commit/checks/tabs.rb', line 12 def self.call check = new check.staged_files = Utils.staged_files('*') result = check.run if !result $stderr.puts check. $stderr.puts $stderr.puts 'pre-commit: You can bypass this check using `git commit -n`' $stderr.puts end result end |
Instance Method Details
#detected_bad_code? ⇒ Boolean
45 46 47 |
# File 'lib/pre-commit/checks/tabs.rb', line 45 def detected_bad_code? system("#{Utils.grep} -q '#{LEADING_TAB_PATTERN}' #{staged_files}") end |
#run ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pre-commit/checks/tabs.rb', line 27 def run # There is nothing to check if staged_files.empty? return true end if detected_bad_code? @error_message = "pre-commit: detected tab before initial space:\n" @error_message += violations @passed = false else @passed = true end end |
#violations ⇒ Object
49 50 51 |
# File 'lib/pre-commit/checks/tabs.rb', line 49 def violations `#{Utils.grep} '#{LEADING_TAB_PATTERN}' #{staged_files}` end |