Class: Tabs
- Inherits:
-
Object
- Object
- 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.
3 4 5 |
# File 'lib/pre-commit/checks/tabs.rb', line 3 def end |
#staged_files ⇒ Object
Returns the value of attribute staged_files.
3 4 5 |
# File 'lib/pre-commit/checks/tabs.rb', line 3 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
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/pre-commit/checks/tabs.rb', line 9 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
42 43 44 |
# File 'lib/pre-commit/checks/tabs.rb', line 42 def detected_bad_code? system("#{grep} -q '#{LEADING_TAB_PATTERN}' #{staged_files}") end |
#grep ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/pre-commit/checks/tabs.rb', line 50 def grep grep_version = `grep --version | head -n 1 | sed -e 's/^[^0-9.]*\([0-9.]*\)$/\1/'` if grep_version =~ /FreeBSD/ "grep -EnIH" else "grep -PnIH" end end |
#run ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/pre-commit/checks/tabs.rb', line 24 def run # There is nothing to check if staged_files.empty? return true end if detected_bad_code? = "pre-commit: detected tab before initial space:\n" += violations @passed = false else @passed = true end end |
#violations ⇒ Object
46 47 48 |
# File 'lib/pre-commit/checks/tabs.rb', line 46 def violations `#{grep} '#{LEADING_TAB_PATTERN}' #{staged_files}` end |