lib/pre-commit/checks/tabs.rb in pre-commit-0.6.1 vs lib/pre-commit/checks/tabs.rb in pre-commit-0.7.0

- old
+ new

@@ -1,49 +1,54 @@ -class Tabs +require 'pre-commit/utils' - attr_accessor :staged_files, :error_message +module PreCommit + class Tabs - # 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 - def self.call - check = new - check.staged_files = Utils.staged_files('*') - result = check.run + attr_accessor :staged_files, :error_message - if !result - $stderr.puts check.error_message - $stderr.puts - $stderr.puts 'pre-commit: You can bypass this check using `git commit -n`' - $stderr.puts - end + # 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 + def self.call + check = new + check.staged_files = Utils.staged_files('*') + result = check.run - result - end + if !result + $stderr.puts check.error_message + $stderr.puts + $stderr.puts 'pre-commit: You can bypass this check using `git commit -n`' + $stderr.puts + end - def run - # There is nothing to check - if staged_files.empty? - return true + result end - if detected_bad_code? - @error_message = "pre-commit: detected tab before initial space:\n" - @error_message += violations + def run + # There is nothing to check + if staged_files.empty? + return true + end - @passed = false - else - @passed = true + if detected_bad_code? + @error_message = "pre-commit: detected tab before initial space:\n" + @error_message += violations + + @passed = false + else + @passed = true + end end - end - LEADING_TAB_PATTERN = '^ *\t' + LEADING_TAB_PATTERN = '^ *\t' - def detected_bad_code? - system("#{Utils.grep} -q '#{LEADING_TAB_PATTERN}' #{staged_files}") - end + def detected_bad_code? + system("#{Utils.grep} -q '#{LEADING_TAB_PATTERN}' #{staged_files}") + end - def violations - `#{Utils.grep} '#{LEADING_TAB_PATTERN}' #{staged_files}` + def violations + `#{Utils.grep} '#{LEADING_TAB_PATTERN}' #{staged_files}` + end + end end