Sha256: 61c1af17569bcfda6ce74843350b1d46d5818fb582343ff70dc049c2bcb0ba69

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

class DebuggerCheck
  attr_accessor :staged_files, :error_message, :grep_command

  def self.call(quiet=false)
    dirs = ['app/', 'lib/', 'script/', 'vendor/', 'test/'].reject {|d| !File.exists?(d)}
    check = new
    check.staged_files = Utils.staged_files(*dirs)

    result = check.run
    if !quiet && !result
      $stderr.puts check.error_message
      $stderr.puts
      check.print_dash_n_reminder
    end
    result
  end

  def run
    return true if staged_files.empty?

    if detected_bad_code?
      @error_message = "pre-commit: debugger statement(s) found:\n"
      @error_message += instances_of_debugger_violations
      false
    else
      true
    end
  end

  def detected_bad_code?
    !system("git diff --cached -S debugger --quiet --exit-code")
  end

  def instances_of_debugger_violations
    cmd = grep_command || "git grep"
    `#{cmd} -nH debugger #{staged_files}`
  end

  def print_dash_n_reminder
    $stderr.puts 'You can bypass this check using `git commit -n`'
    $stderr.puts
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pre-commit-0.1.3 lib/pre-commit/checks/debugger_check.rb