Sha256: 195e3008b906ad9ea390c44992bf2c26a1fe298878a72aa564cbd6383350583a

Contents?: true

Size: 864 Bytes

Versions: 8

Compression:

Stored size: 864 Bytes

Contents

class Tabs

  attr_accessor :staged_files, :error_message

  # 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('*')
    check.run
  end

  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

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

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

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
pre-commit-0.1.12 lib/pre-commit/checks/tabs.rb
pre-commit-0.1.11 lib/pre-commit/checks/tabs.rb
pre-commit-0.1.10 lib/pre-commit/checks/tabs.rb
pre-commit-0.1.9 lib/pre-commit/checks/tabs.rb
pre-commit-0.1.8 lib/pre-commit/checks/tabs.rb
pre-commit-0.1.7 lib/pre-commit/checks/tabs.rb
pre-commit-0.1.6 lib/pre-commit/checks/tabs.rb
pre-commit-0.1.5 lib/pre-commit/checks/tabs.rb