pre-commit 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4d9c371797ba41d4ea7f982f02afb3ea83509b6c
4
+ data.tar.gz: 3db78877071110d7c8a6594144d6a581ff05f4b9
5
+ SHA512:
6
+ metadata.gz: ef060f68886d56abe7fb9ead2edfa62f287cb3a84fa76c83a26748fdde3f726a83124401274fbd7a2bb3a89c755ae5efc3a40158de8cd0e19d895deb59bd0e08
7
+ data.tar.gz: 5e182f1fd7511e7bddd86704c40220f6f2c83b69108213b3f1052bd123d984cfd2850bfb963828ba36765c9b3cfab665501d709f229f21a7656431f1c70fe62d
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  A better pre-commit hook for git.
2
2
 
3
+ [![Current version](https://badge.fury.io/rb/pre-commit.png)][1] 
4
+ [![Build status](https://secure.travis-ci.org/jish/pre-commit.png?branch=master)][2]
5
+
3
6
  ## Installation
4
7
 
5
8
  Install the gem
@@ -20,19 +23,21 @@ These are the available checks:
20
23
  * white_space
21
24
  * console_log
22
25
  * debugger
26
+ * pry
23
27
  * tabs
24
28
  * jshint
25
29
  * js\_lint\_all (Runs JSLint on all staged JS files)
26
30
  * js\_lint\_new (Runs JSLint on all new staged JS files)
27
31
  * closure\_syntax\_check
28
32
  * php (Runs php -l on all staged files)
33
+ * rspec_focus (Will check if you are about to check in a :focus in a spec file)
29
34
  * ruby_symbol_hashrockets (1.9 syntax. BAD :foo => "bar". GOOD foo: "bar")
30
35
  * local (executes `config/pre-commit.rb` with list of changed files)
31
- * merge conflict (Will check if you are about to check in a merge conflict)
36
+ * merge_conflict (Will check if you are about to check in a merge conflict)
32
37
  * migrations (Will make sure you check in the proper files after creating a Rails migration)
33
38
  * ci (Will run the `pre_commit:ci` rake task and pass or fail accordingly)
34
39
 
35
- To configure which checks you would like to run, simply set the `pre-commit.checks` git configuration setting.
40
+ To configure which checks you would like to run, simply set the `pre-commit.checks` git configuration setting.
36
41
 
37
42
  To enable `white_space` and `tab` checks:
38
43
 
@@ -46,4 +51,7 @@ To enable `white_space`, `console_log` and `debugger` checks:
46
51
 
47
52
  Note: If no checks are configured, a default set of checks is run:
48
53
 
49
- white_space, console_log, debugger, tabs, jshint, migrations, merge_conflict, local
54
+ white_space, console_log, debugger, pry, tabs, jshint, migrations, merge_conflict, local
55
+
56
+ [1]: https://rubygems.org/gems/pre-commit
57
+ [2]: https://travis-ci.org/jish/pre-commit
@@ -10,6 +10,8 @@ require 'pre-commit/checks/jshint_check'
10
10
  require 'pre-commit/checks/migration_check'
11
11
  require 'pre-commit/checks/ci_check'
12
12
  require 'pre-commit/checks/php_check'
13
+ require 'pre-commit/checks/pry_check'
14
+ require 'pre-commit/checks/rspec_focus_check'
13
15
  require 'pre-commit/checks/ruby_symbol_hashrockets'
14
16
 
15
17
  module PreCommit
@@ -35,6 +37,7 @@ module PreCommit
35
37
  :js_lint_new => JslintCheck.new(:new),
36
38
  :jshint => JshintCheck.new,
37
39
  :debugger => DebuggerCheck,
40
+ :pry => PryCheck,
38
41
  :local => LocalCheck,
39
42
  :tabs => Tabs,
40
43
  :closure_syntax_check => ClosureSyntaxCheck,
@@ -42,6 +45,7 @@ module PreCommit
42
45
  :migrations => MigrationCheck.new,
43
46
  :ci => CiCheck.new,
44
47
  :php => PhpCheck.new,
48
+ :rspec_focus => RSpecFocusCheck,
45
49
  :ruby_symbol_hashrockets => RubySymbolHashrockets
46
50
  }
47
51
 
@@ -60,7 +64,7 @@ module PreCommit
60
64
  checks_to_run = `git config pre-commit.checks`.chomp.split(/,\s*/).map(&:to_sym)
61
65
 
62
66
  if checks_to_run.empty?
63
- Checks.values_at(:white_space, :console_log, :debugger, :tabs, :jshint,
67
+ Checks.values_at(:white_space, :console_log, :debugger, :pry, :tabs, :jshint,
64
68
  :migrations, :merge_conflict, :local)
65
69
  else
66
70
  Checks.values_at(*checks_to_run)
@@ -0,0 +1,47 @@
1
+ module PreCommit
2
+ class PryCheck
3
+
4
+ attr_accessor :staged_files, :error_message, :grep_command
5
+
6
+ def self.call(quiet=false)
7
+ dirs = ['app/', 'lib/', 'script/', 'vendor/', 'test/'].reject {|d| !File.exists?(d)}
8
+ check = new
9
+ check.staged_files = Utils.staged_files(*dirs)
10
+
11
+ result = check.run
12
+ if !quiet && !result
13
+ $stderr.puts check.error_message
14
+ $stderr.puts
15
+ check.print_dash_n_reminder
16
+ end
17
+ result
18
+ end
19
+
20
+ def run
21
+ return true if staged_files.empty?
22
+
23
+ if detected_bad_code?
24
+ @error_message = "pre-commit: binding.pry statement(s) found:\n"
25
+ @error_message += instances_of_pry_violations
26
+ false
27
+ else
28
+ true
29
+ end
30
+ end
31
+
32
+ def detected_bad_code?
33
+ !system("git diff --cached -S binding.pry --quiet --exit-code")
34
+ end
35
+
36
+ def instances_of_pry_violations
37
+ cmd = grep_command || "git grep"
38
+ `#{cmd} -nH "binding\.pry" #{staged_files}`
39
+ end
40
+
41
+ def print_dash_n_reminder
42
+ $stderr.puts 'You can bypass this check using `git commit -n`'
43
+ $stderr.puts
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,54 @@
1
+ module PreCommit
2
+ class RSpecFocusCheck
3
+
4
+ attr_accessor :staged_files, :error_message, :grep_command, :spec_files
5
+
6
+ def self.call(quiet=false)
7
+ dirs = ['spec/'].reject {|d| !File.exists?(d)}
8
+ check = new
9
+ check.staged_files = Utils.staged_files(*dirs)
10
+
11
+ result = check.run
12
+ if !quiet && !result
13
+ $stderr.puts check.error_message
14
+ $stderr.puts
15
+ check.print_dash_n_reminder
16
+ end
17
+ result
18
+ end
19
+
20
+ def run
21
+ return true if staged_files.empty?
22
+
23
+ if detected_bad_code?
24
+ @error_message = "pre-commit: :focus in spec(s) found:\n"
25
+ @error_message += instances_of_rspec_focus_violations
26
+ false
27
+ else
28
+ true
29
+ end
30
+ end
31
+
32
+ def detected_bad_code?
33
+ spec_files = staged_files.split(' ').select do |file|
34
+ file =~ /_spec\.rb$/
35
+ end
36
+
37
+ return false if spec_files.empty?
38
+
39
+ diff = `git diff --cached -G:focus #{spec_files.join(" ")}`
40
+ !!(diff =~ /[\W\s]:focus[\W\s]/)
41
+ end
42
+
43
+ def instances_of_rspec_focus_violations
44
+ cmd = grep_command || "git grep"
45
+ `#{cmd} -nHw ':focus' #{staged_files}`
46
+ end
47
+
48
+ def print_dash_n_reminder
49
+ $stderr.puts 'You can bypass this check using `git commit -n`'
50
+ $stderr.puts
51
+ end
52
+
53
+ end
54
+ end
@@ -5,7 +5,7 @@ module PreCommit
5
5
 
6
6
  attr_accessor :staged_files, :error_message
7
7
 
8
- HASHROCKET_PATTERN = ':(?:\$|@|@@|[_A-Za-z])?\w*[=!?]?\s*=>\s*'
8
+ HASHROCKET_PATTERN = '[^:](:{1}(?:\$|@|@@|[_A-Za-z])?\w*[=!?]?\s*=>\s*)'
9
9
 
10
10
  def self.call
11
11
  check = new
@@ -9,7 +9,7 @@ else
9
9
  end
10
10
  cmd << " -r pre-commit"
11
11
 
12
- if !system("#{cmd} -e '' 2>&1")
12
+ if !system("#{cmd} -e ';' 2>&1")
13
13
  $stderr.puts "pre-commit: WARNING: Skipping checks because the pre-commit gem is not installed. (Did you change your Ruby version?)"
14
14
  exit(0)
15
15
  end
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pre-commit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
5
- prerelease:
4
+ version: 0.8.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Shajith Chacko, Josh Lubaway
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-14 00:00:00.000000000 Z
11
+ date: 2013-03-30 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: execjs
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  description: A git pre-commit hook written in ruby with a few more tricks up its sleeve
@@ -46,6 +43,8 @@ files:
46
43
  - lib/pre-commit/checks/merge_conflict.rb
47
44
  - lib/pre-commit/checks/migration_check.rb
48
45
  - lib/pre-commit/checks/php_check.rb
46
+ - lib/pre-commit/checks/pry_check.rb
47
+ - lib/pre-commit/checks/rspec_focus_check.rb
49
48
  - lib/pre-commit/checks/ruby_symbol_hashrockets.rb
50
49
  - lib/pre-commit/checks/tabs.rb
51
50
  - lib/pre-commit/checks.rb
@@ -65,6 +64,7 @@ files:
65
64
  - bin/pre-commit
66
65
  homepage: http://github.com/jish/pre-commit
67
66
  licenses: []
67
+ metadata: {}
68
68
  post_install_message:
69
69
  rdoc_options:
70
70
  - --main
@@ -72,20 +72,18 @@ rdoc_options:
72
72
  require_paths:
73
73
  - lib
74
74
  required_ruby_version: !ruby/object:Gem::Requirement
75
- none: false
76
75
  requirements:
77
- - - ! '>='
76
+ - - '>='
78
77
  - !ruby/object:Gem::Version
79
78
  version: '0'
80
79
  required_rubygems_version: !ruby/object:Gem::Requirement
81
- none: false
82
80
  requirements:
83
- - - ! '>='
81
+ - - '>='
84
82
  - !ruby/object:Gem::Version
85
83
  version: '0'
86
84
  requirements: []
87
85
  rubyforge_project:
88
- rubygems_version: 1.8.23
86
+ rubygems_version: 2.0.0
89
87
  signing_key:
90
88
  specification_version: 3
91
89
  summary: A slightly better git pre-commit hook