Module: PreCommit

Defined in:
lib/pre-commit/cli.rb,
lib/pre-commit/utils.rb,
lib/pre-commit/checks.rb,
lib/pre-commit/runner.rb,
lib/pre-commit/checks/ci_check.rb,
lib/pre-commit/checks/js_check.rb,
lib/pre-commit/checks/php_check.rb,
lib/pre-commit/checks/pry_check.rb,
lib/pre-commit/checks/tabs_check.rb,
lib/pre-commit/checks/local_check.rb,
lib/pre-commit/checks/jshint_check.rb,
lib/pre-commit/checks/jslint_check.rb,
lib/pre-commit/checks/closure_check.rb,
lib/pre-commit/checks/rubocop_check.rb,
lib/pre-commit/checks/debugger_check.rb,
lib/pre-commit/checks/nb_space_check.rb,
lib/pre-commit/checks/migration_check.rb,
lib/pre-commit/checks/whitespace_check.rb,
lib/pre-commit/checks/console_log_check.rb,
lib/pre-commit/checks/rspec_focus_check.rb,
lib/pre-commit/checks/gemfile_path_check.rb,
lib/pre-commit/checks/merge_conflict_check.rb,
lib/pre-commit/checks/ruby_symbol_hashrockets.rb

Defined Under Namespace

Classes: CiCheck, Cli, ClosureCheck, ConsoleLogCheck, DebuggerCheck, GemfilePathCheck, JsCheck, JshintCheck, JslintCheck, LocalCheck, MergeConflictCheck, MigrationCheck, NbSpaceCheck, PhpCheck, PryCheck, RSpecFocusCheck, RubocopCheck, RubySymbolHashrockets, Runner, TabsCheck, Utils, WhiteSpaceCheck

Constant Summary collapse

CHECKS =
{
  :white_space             => WhiteSpaceCheck,
  :console_log             => ConsoleLogCheck,
  :js_lint                 => JslintCheck,
  :jshint                  => JshintCheck,
  :debugger                => DebuggerCheck,
  :pry                     => PryCheck,
  :local                   => LocalCheck,
  :nb_space                => NbSpaceCheck,
  :tabs                    => TabsCheck,
  :closure_syntax_check    => ClosureCheck,
  :merge_conflict          => MergeConflictCheck,
  :migrations              => MigrationCheck,
  :ci                      => CiCheck.new,
  :php                     => PhpCheck.new,
  :rspec_focus             => RSpecFocusCheck,
  :ruby_symbol_hashrockets => RubySymbolHashrockets,
  :gemfile_path            => GemfilePathCheck
}

Class Method Summary collapse

Class Method Details

.checks_to_runObject

Actually, on the deprecation note. This method isn’t really the problem. The problem is the default generated pre-commit hook. It shouldn’t have logic in it. The we have freedom to change the gem implementation however we want, and nobody is forced to update their pre-commit binary.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/pre-commit/checks.rb', line 58

def self.checks_to_run
  checks_to_run = `git config pre-commit.checks`.chomp.split(/,\s*/).map(&:to_sym)

  if checks_to_run.empty?
    CHECKS.values_at(:white_space, :console_log, :debugger, :pry, :tabs, :jshint,
      :migrations, :merge_conflict, :local, :nb_space)
  else
    [:js_lint, :rubocop].each do |check|
      if checks_to_run.delete("#{check}_all".to_sym) || checks_to_run.delete("#{check}_new".to_sym)
        $stderr.puts "please use just '#{check}' as check name"
        checks_to_run << check
      end
    end

    CHECKS.values_at(*checks_to_run)
  end.compact
end

.runObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/pre-commit/checks.rb', line 76

def self.run
  staged_files = Utils.staged_files
  errors = checks_to_run.map { |cmd| cmd.call(staged_files.dup) }.compact
  if errors.any?
    $stderr.puts "pre-commit: Stopping commit because of errors."
    $stderr.puts errors.join("\n")
    $stderr.puts
    $stderr.puts "pre-commit: You can bypass this check using `git commit -n`"
    $stderr.puts
    exit 1
  else
    exit 0
  end
end