rubocopter 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 15bb789590e6e7ba4b61bea04057362859c4fcfd
4
- data.tar.gz: e7ef6833104019d9bfa712f3d811127d97ea7db5
3
+ metadata.gz: 5244a6527323ba5bb4b6560925216c8a22200762
4
+ data.tar.gz: 3c904d1302984791c15420303d62216e9116dc99
5
5
  SHA512:
6
- metadata.gz: f82afae1304b8671c27d3691d0e5347eddddaf3206980d32c1800bb182e18e0b0da7587ad1ecf3e5461114cc0f63154446fb56a02f2d8399c336fdcc9386d9f7
7
- data.tar.gz: d63562899508e6f7b5f6c8b4c2031030a31fe8fc503d05816e391949302a60cecabd28c307ee965b36e883215a4b320ab81598f0ac394b21ca4d0c5f4c8b2323
6
+ metadata.gz: b4ebc8a3683d5d821293db9730b9c07baed73bd704d0135cab513c8068c8042b94285a8c6bbb2cf23ac4a54f2045696ae5e3780d1052c053b295a46eb190b72f
7
+ data.tar.gz: 02b50c2d3f4a3b90338609aa0fc8612395a604c554cb849b27f35b26daca47e875cdff34dd7039fb04fcbd6a107159d307c687b96d514a6b752e11475f917f41
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # Rubocopter
2
+
3
+ A simple wrapper gem around [RuboCop](https://github.com/bbatsov/rubocop). Rubocopter aids you in development by providing a convenient way to find ruby style and logic issues in your large .git projects by comparing only the changes from a given commit.
4
+
5
+ ## Installation
6
+
7
+ `gem install rubocopter`
8
+
9
+ ## Usage
10
+
11
+ `rubocopter`
12
+
13
+ Use the `-h` or `--help` flag to see options.
14
+
15
+ ## License
16
+
17
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,9 @@
1
+ #!/bin/sh
2
+ #
3
+ # Ensure your code is valid before commiting
4
+ rubocopter
5
+
6
+ if [ $? -ne 0 ]; then
7
+ echo 'Rubocop validation failed. Aborting commit.'
8
+ exit 1
9
+ fi
@@ -0,0 +1,9 @@
1
+ #!/bin/sh
2
+ #
3
+ # Ensure your code is valid before pushing
4
+ rubocopter
5
+
6
+ if [ $? -ne 0 ]; then
7
+ echo 'Rubocop validation failed. Aborting push.'
8
+ exit 1
9
+ fi
@@ -1,6 +1,7 @@
1
1
  require 'optparse'
2
2
  require 'shellwords'
3
3
  require 'rubocop'
4
+ require 'pathname'
4
5
 
5
6
  RuboCopter::Options = Struct.new(:hash, :debug)
6
7
 
@@ -11,6 +12,7 @@ class RuboCopter::CLI
11
12
  def run(args = ARGV)
12
13
  parse_options(args)
13
14
  check_for_offences
15
+ show_results
14
16
 
15
17
  return $?.exitstatus
16
18
  end
@@ -38,25 +40,32 @@ class RuboCopter::CLI
38
40
  end
39
41
 
40
42
  def check_for_offences
43
+ # Check for git.
41
44
  if `which git` == ''
42
45
  puts 'git not detected. Running normal rubocop.'
43
46
  system(Shellwords.join(['rubocop', '-R'] + '--out rubocop_result.txt'.split))
44
- else
45
- `git rev-parse`
46
- if $?.exitstatus == 0
47
- files = changed_ruby_file_names
48
- if files.length == 0
49
- puts 'No changes detected, no reason to run rubocop'
50
- exit(0)
51
- else
52
- system(Shellwords.join(['rubocop', '-R'] + files + '--out rubocop_result.txt'.split))
53
- end
47
+ return
48
+ end
49
+
50
+ # Check for changes
51
+ `git rev-parse`
52
+ if $?.exitstatus == 0
53
+ files = changed_ruby_file_names
54
+ if files.length == 0
55
+ puts 'No changes detected, no reason to run rubocop'
56
+ exit(0)
54
57
  else
55
- puts 'git directory not detected. Running normal rubocop.'
56
- system(Shellwords.join(['rubocop', '-R'] + '--out rubocop_result.txt'.split))
58
+ system(Shellwords.join(['rubocop', '-R'] + files + '--out rubocop_result.txt'.split))
57
59
  end
60
+ return
58
61
  end
59
62
 
63
+ # No git directory
64
+ puts 'git directory not detected. Running normal rubocop.'
65
+ system(Shellwords.join(['rubocop', '-R'] + '--out rubocop_result.txt'.split))
66
+ end
67
+
68
+ def show_results
60
69
  if File.exists?('rubocop_result.txt')
61
70
  text = File.open('rubocop_result.txt').read
62
71
  puts text
@@ -81,6 +90,14 @@ class RuboCopter::CLI
81
90
  @options.hash = hash
82
91
  end
83
92
 
93
+ opts.on('--install-git-hooks HOOK', 'write git hooks to rubocopter. options : all, commit, push') do |hook|
94
+ install_git_hooks(hook)
95
+ end
96
+
97
+ opts.on('--remove-git-hooks HOOK', 'remove git hooks. options : all, commit, push') do |hook|
98
+ remove_git_hooks(hook)
99
+ end
100
+
84
101
  opts.on("--debug", "Prints runtime") do
85
102
  @options.debug = true
86
103
  end
@@ -94,4 +111,31 @@ class RuboCopter::CLI
94
111
  opt_parser.parse!(args)
95
112
  end
96
113
 
114
+ def install_git_hooks(hook)
115
+ working_dir_git_hooks = Pathname.new(Dir.pwd).join('.git', 'hooks')
116
+ current_path = Pathname.new(File.dirname(__FILE__))
117
+ if hook == 'commit'
118
+ system(Shellwords.join(['cp', current_path.join('../../git_hooks', 'pre-commit'), working_dir_git_hooks]))
119
+ elsif hook == 'push'
120
+ system(Shellwords.join(['cp', current_path.join('../../git_hooks', 'pre-push'), working_dir_git_hooks]))
121
+ elsif hook == 'all'
122
+ system(Shellwords.join(['cp', current_path.join('../../git_hooks', 'pre-commit'), working_dir_git_hooks]))
123
+ system(Shellwords.join(['cp', current_path.join('../../git_hooks', 'pre-push'), working_dir_git_hooks]))
124
+ end
125
+ exit(0)
126
+ end
127
+
128
+ def remove_git_hooks(hook)
129
+ working_dir_git_hooks = Pathname.new(Dir.pwd).join('.git', 'hooks')
130
+ if hook == 'commit'
131
+ system(Shellwords.join(['rm', working_dir_git_hooks.join('pre-commit')]))
132
+ elsif hook == 'push'
133
+ system(Shellwords.join(['rm', working_dir_git_hooks.join('pre-push')]))
134
+ elsif hook == 'all'
135
+ system(Shellwords.join(['rm', working_dir_git_hooks.join('pre-commit')]))
136
+ system(Shellwords.join(['rm', working_dir_git_hooks.join('pre-push')]))
137
+ end
138
+ exit(0)
139
+ end
140
+
97
141
  end
@@ -1,3 +1,3 @@
1
1
  module RuboCopter
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocopter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Basset
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-19 00:00:00.000000000 Z
11
+ date: 2015-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -24,7 +24,7 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.29.1
27
- description: Helps with speeding up rubocop checks in large git projects.
27
+ description: Helps with speeding up RuboCop checks in large git projects.
28
28
  email:
29
29
  - matthew@quandl.com
30
30
  executables:
@@ -33,8 +33,10 @@ extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
35
  - MIT-LICENSE
36
- - README.rdoc
36
+ - README.md
37
37
  - bin/rubocopter
38
+ - git_hooks/pre-commit
39
+ - git_hooks/pre-push
38
40
  - lib/rubocopter.rb
39
41
  - lib/rubocopter/cli.rb
40
42
  - lib/rubocopter/version.rb
data/README.rdoc DELETED
@@ -1,7 +0,0 @@
1
- = Rubocopter
2
-
3
- A simple gem that you can run in your projects to aid in running RuboCop against only the changes in your .git projects.
4
-
5
- == License
6
-
7
- This project rocks and uses MIT-LICENSE.