rubocopter 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +7 -0
- data/bin/rubocopter +17 -0
- data/lib/rubocopter/cli.rb +97 -0
- data/lib/rubocopter/version.rb +3 -0
- data/lib/rubocopter.rb +4 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 15bb789590e6e7ba4b61bea04057362859c4fcfd
|
4
|
+
data.tar.gz: e7ef6833104019d9bfa712f3d811127d97ea7db5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f82afae1304b8671c27d3691d0e5347eddddaf3206980d32c1800bb182e18e0b0da7587ad1ecf3e5461114cc0f63154446fb56a02f2d8399c336fdcc9386d9f7
|
7
|
+
data.tar.gz: d63562899508e6f7b5f6c8b4c2031030a31fe8fc503d05816e391949302a60cecabd28c307ee965b36e883215a4b320ab81598f0ac394b21ca4d0c5f4c8b2323
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Matthew Basset
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/bin/rubocopter
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift(File.dirname(File.realpath(__FILE__)) + '/../lib')
|
5
|
+
|
6
|
+
require 'rubocopter'
|
7
|
+
require 'benchmark'
|
8
|
+
|
9
|
+
cli = RuboCopter::CLI.new
|
10
|
+
result = 0
|
11
|
+
|
12
|
+
time = Benchmark.realtime do
|
13
|
+
result = cli.run
|
14
|
+
end
|
15
|
+
|
16
|
+
puts "Finished in #{time} seconds" if cli.options[:debug]
|
17
|
+
exit result
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'shellwords'
|
3
|
+
require 'rubocop'
|
4
|
+
|
5
|
+
RuboCopter::Options = Struct.new(:hash, :debug)
|
6
|
+
|
7
|
+
class RuboCopter::CLI
|
8
|
+
|
9
|
+
attr_reader :options
|
10
|
+
|
11
|
+
def run(args = ARGV)
|
12
|
+
parse_options(args)
|
13
|
+
check_for_offences
|
14
|
+
|
15
|
+
return $?.exitstatus
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def ruby_file?(name)
|
21
|
+
File.extname(name).casecmp('.rb') == 0
|
22
|
+
end
|
23
|
+
|
24
|
+
def git_diff
|
25
|
+
puts "Checking files changes since #{@options.hash}"
|
26
|
+
git_command = Shellwords.join(%w(git diff --name-only) + [@options.hash])
|
27
|
+
git_output = `#{git_command}`
|
28
|
+
fail "git error: #{git_command}" unless $CHILD_STATUS.to_i
|
29
|
+
git_output.split("\n")
|
30
|
+
end
|
31
|
+
|
32
|
+
def changed_ruby_file_names
|
33
|
+
rubyfiles = []
|
34
|
+
git_diff.each do |file|
|
35
|
+
rubyfiles.push(file) if ruby_file?(file) && File.file?(file)
|
36
|
+
end
|
37
|
+
rubyfiles
|
38
|
+
end
|
39
|
+
|
40
|
+
def check_for_offences
|
41
|
+
if `which git` == ''
|
42
|
+
puts 'git not detected. Running normal rubocop.'
|
43
|
+
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
|
54
|
+
else
|
55
|
+
puts 'git directory not detected. Running normal rubocop.'
|
56
|
+
system(Shellwords.join(['rubocop', '-R'] + '--out rubocop_result.txt'.split))
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
if File.exists?('rubocop_result.txt')
|
61
|
+
text = File.open('rubocop_result.txt').read
|
62
|
+
puts text
|
63
|
+
offense = /(\d+) offense/.match(text.split("\n")[-1])
|
64
|
+
if offense
|
65
|
+
num_of_offense = offense[1].to_i
|
66
|
+
exit(-1) if num_of_offense > 0
|
67
|
+
end
|
68
|
+
else
|
69
|
+
puts 'Something went wrong. Rubocop was not run.'
|
70
|
+
exit(-1)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def parse_options(args)
|
75
|
+
@options = RuboCopter::Options.new('master', false)
|
76
|
+
|
77
|
+
opt_parser = OptionParser.new do |opts|
|
78
|
+
opts.banner = "Usage: rubocopter [options]"
|
79
|
+
|
80
|
+
opts.on('-c HASH', '--commit HASH', 'git hash to compare against') do |hash|
|
81
|
+
@options.hash = hash
|
82
|
+
end
|
83
|
+
|
84
|
+
opts.on("--debug", "Prints runtime") do
|
85
|
+
@options.debug = true
|
86
|
+
end
|
87
|
+
|
88
|
+
opts.on("-h", "--help", "Prints this help") do
|
89
|
+
puts opts
|
90
|
+
exit
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
opt_parser.parse!(args)
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
data/lib/rubocopter.rb
ADDED
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubocopter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Basset
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubocop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.29.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.29.1
|
27
|
+
description: Helps with speeding up rubocop checks in large git projects.
|
28
|
+
email:
|
29
|
+
- matthew@quandl.com
|
30
|
+
executables:
|
31
|
+
- rubocopter
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- MIT-LICENSE
|
36
|
+
- README.rdoc
|
37
|
+
- bin/rubocopter
|
38
|
+
- lib/rubocopter.rb
|
39
|
+
- lib/rubocopter/cli.rb
|
40
|
+
- lib/rubocopter/version.rb
|
41
|
+
homepage: https://github.com/quandl/rubocopter
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.9.3
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 2.4.5
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: Propel your RuboCop checking forward.
|
65
|
+
test_files: []
|