Class: Tabs

Inherits:
Object
  • Object
show all
Defined in:
lib/pre-commit/checks/tabs.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#error_messageObject

Returns the value of attribute error_message.



3
4
5
# File 'lib/pre-commit/checks/tabs.rb', line 3

def error_message
  @error_message
end

#staged_filesObject

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

.callObject

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
# File 'lib/pre-commit/checks/tabs.rb', line 9

def self.call
  check = new
  check.staged_files = Utils.staged_files('*')
  check.run
end

Instance Method Details

#detected_bad_code?Boolean

Returns:



34
35
36
# File 'lib/pre-commit/checks/tabs.rb', line 34

def detected_bad_code?
  system("grep -PnIH -q '^\t' #{staged_files}")
end

#runObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pre-commit/checks/tabs.rb', line 15

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

    $stderr.puts @error_message
    $stderr.puts

    @passed = false
  else
    @passed = true
  end
end

#violationsObject



38
39
40
# File 'lib/pre-commit/checks/tabs.rb', line 38

def violations
  `grep -PnIH '^\t' #{staged_files}`
end