pre-commit 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -36,6 +36,7 @@ These are the available checks:
36
36
  * merge_conflict (Will check if you are about to check in a merge conflict)
37
37
  * migrations (Will make sure you check in the proper files after creating a Rails migration)
38
38
  * ci (Will run the `pre_commit:ci` rake task and pass or fail accordingly)
39
+ * rubocop\_new and rubocop\_all (Check ruby code style using the rubocop gem. Rubocop must be installed)
39
40
 
40
41
  To configure which checks you would like to run, simply set the `pre-commit.checks` git configuration setting.
41
42
 
@@ -53,5 +54,10 @@ Note: If no checks are configured, a default set of checks is run:
53
54
 
54
55
  white_space, console_log, debugger, pry, tabs, jshint, migrations, merge_conflict, local
55
56
 
57
+ For the rubocop check, you can tell it what config file to use by setting a path relative to the repo:
58
+
59
+ # From your git repo
60
+ $ git config "pre-commit.rubocop.config" "config/rubocop.yml"
61
+
56
62
  [1]: https://rubygems.org/gems/pre-commit
57
63
  [2]: https://travis-ci.org/jish/pre-commit
@@ -1,7 +1,7 @@
1
1
  module PreCommit
2
2
 
3
3
  def self.root
4
- root = File.expand_path('../../..', __FILE__)
4
+ File.expand_path('../../..', __FILE__)
5
5
  end
6
6
 
7
7
  end
@@ -13,6 +13,10 @@ require 'pre-commit/checks/php_check'
13
13
  require 'pre-commit/checks/pry_check'
14
14
  require 'pre-commit/checks/rspec_focus_check'
15
15
  require 'pre-commit/checks/ruby_symbol_hashrockets'
16
+ begin
17
+ require 'pre-commit/checks/rubocop_check'
18
+ rescue LoadError # no rubocop
19
+ end
16
20
 
17
21
  module PreCommit
18
22
 
@@ -21,8 +25,6 @@ module PreCommit
21
25
  }
22
26
 
23
27
  ClosureSyntaxCheck = lambda {
24
- compiler = "test/javascript/lib/compiler.jar"
25
-
26
28
  if File.exists?('public/javascripts') && (args = Utils.staged_files('public/javascripts')).size > 0
27
29
  ClosureChecker.check(args.split(" "))
28
30
  else
@@ -49,6 +51,13 @@ module PreCommit
49
51
  :ruby_symbol_hashrockets => RubySymbolHashrockets
50
52
  }
51
53
 
54
+ if defined?(Rubocop)
55
+ Checks.merge!({
56
+ :rubocop_new => RubocopCheck.new(:new),
57
+ :rubocop_all => RubocopCheck.new(:all)
58
+ })
59
+ end
60
+
52
61
  # Can not delete this method with out a deprecation strategy.
53
62
  # It is refered to in the generated pre-commit hook in versions 0.0-0.1.1
54
63
  #
@@ -0,0 +1,55 @@
1
+ require 'pre-commit/base'
2
+ require 'pre-commit/utils'
3
+ require 'rubocop'
4
+
5
+ module PreCommit
6
+ class RubocopCheck
7
+
8
+ attr_accessor :type
9
+
10
+ def check_name
11
+ "Rubocop"
12
+ end
13
+
14
+ def initialize(type = :all)
15
+ @type = type
16
+ end
17
+
18
+ def files_to_check
19
+ case @type
20
+ when :new
21
+ Utils.new_files('.').split(" ")
22
+ else
23
+ Utils.staged_files('.').split(" ")
24
+ end
25
+ end
26
+
27
+ def reject_non_rb(staged_files)
28
+ staged_files.select { |f| f =~ /\.rb$/ }
29
+ end
30
+
31
+ def call
32
+ rb_files = reject_non_rb(files_to_check)
33
+ return true if rb_files.empty?
34
+ config_file = `git config pre-commit.rubocop.config`.chomp
35
+ args = rb_files
36
+ if !config_file.empty?
37
+ if !File.exist? config_file
38
+ $stderr.puts "Warning: rubocop config file '" + config_file + "' does not exist"
39
+ $stderr.puts "Set the path to the config file using:"
40
+ $stderr.puts "\tgit config pre-commit.rubocop.config 'path/relative/to/git/dir/rubocop.yml'"
41
+ $stderr.puts "rubocop will use its default configuration or look for a .rubocop.yml file\n\n"
42
+ else
43
+ args = ['-c', config_file] + args
44
+ end
45
+ end
46
+ run(args)
47
+ end
48
+
49
+ def run(rb_files)
50
+ rubocop = Rubocop::CLI.new
51
+ return rubocop.run(rb_files) == 0
52
+ end
53
+
54
+ end
55
+ end
@@ -1,17 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ OPTIONS = "-r rubygems"
4
+
3
5
  cmd = if system("which rvm > /dev/null")
4
- "rvm default do ruby -rrubygems"
6
+ "rvm default do ruby"
5
7
  elsif system("which rbenv > /dev/null")
6
- "rbenv exec ruby -rrubygems"
8
+ "rbenv exec ruby"
7
9
  else
8
- "ruby -r rubygems"
10
+ "ruby"
9
11
  end
10
- cmd << " -r pre-commit"
11
12
 
12
- if !system("#{cmd} -e ';' 2>&1")
13
+ if !system(%Q{#{cmd} #{OPTIONS} -e "require 'pre-commit';" 2>&1})
13
14
  $stderr.puts "pre-commit: WARNING: Skipping checks because the pre-commit gem is not installed. (Did you change your Ruby version?)"
14
15
  exit(0)
15
16
  end
16
17
 
17
- exec("#{cmd} -e 'PreCommit.run'")
18
+ exec(%Q{#{cmd} #{OPTIONS} -e "require 'pre-commit'; PreCommit.run"})
metadata CHANGED
@@ -1,27 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pre-commit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Shajith Chacko, Josh Lubaway
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-03-30 00:00:00.000000000 Z
12
+ date: 2013-06-10 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: execjs
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: '0'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - '>='
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0'
27
30
  description: A git pre-commit hook written in ruby with a few more tricks up its sleeve
@@ -45,6 +48,7 @@ files:
45
48
  - lib/pre-commit/checks/php_check.rb
46
49
  - lib/pre-commit/checks/pry_check.rb
47
50
  - lib/pre-commit/checks/rspec_focus_check.rb
51
+ - lib/pre-commit/checks/rubocop_check.rb
48
52
  - lib/pre-commit/checks/ruby_symbol_hashrockets.rb
49
53
  - lib/pre-commit/checks/tabs.rb
50
54
  - lib/pre-commit/checks.rb
@@ -64,7 +68,6 @@ files:
64
68
  - bin/pre-commit
65
69
  homepage: http://github.com/jish/pre-commit
66
70
  licenses: []
67
- metadata: {}
68
71
  post_install_message:
69
72
  rdoc_options:
70
73
  - --main
@@ -72,18 +75,20 @@ rdoc_options:
72
75
  require_paths:
73
76
  - lib
74
77
  required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
75
79
  requirements:
76
- - - '>='
80
+ - - ! '>='
77
81
  - !ruby/object:Gem::Version
78
82
  version: '0'
79
83
  required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
80
85
  requirements:
81
- - - '>='
86
+ - - ! '>='
82
87
  - !ruby/object:Gem::Version
83
88
  version: '0'
84
89
  requirements: []
85
90
  rubyforge_project:
86
- rubygems_version: 2.0.0
91
+ rubygems_version: 1.8.23
87
92
  signing_key:
88
93
  specification_version: 3
89
94
  summary: A slightly better git pre-commit hook
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 4d9c371797ba41d4ea7f982f02afb3ea83509b6c
4
- data.tar.gz: 3db78877071110d7c8a6594144d6a581ff05f4b9
5
- SHA512:
6
- metadata.gz: ef060f68886d56abe7fb9ead2edfa62f287cb3a84fa76c83a26748fdde3f726a83124401274fbd7a2bb3a89c755ae5efc3a40158de8cd0e19d895deb59bd0e08
7
- data.tar.gz: 5e182f1fd7511e7bddd86704c40220f6f2c83b69108213b3f1052bd123d984cfd2850bfb963828ba36765c9b3cfab665501d709f229f21a7656431f1c70fe62d