rubocopter 0.0.10 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubocopter/cli.rb +34 -16
- data/lib/rubocopter/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d2ff96ab1f11fd023566f38011c8797caad35ee
|
4
|
+
data.tar.gz: fc144c71f5b107870eb0396f8a3b693d64d81a13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e5d81fcba6705107722d93ca419c202405f2c42b6c76cb271c1dc422674cdee39dc3804a56ec7e5dc0266505cdf03374a3271a93aaf95af015165a8536e8335
|
7
|
+
data.tar.gz: b74abcd2ab2fdf83137eae74bec90e8215c2dc4cdac95844a79d3e5fed4379e25688d0a5f54fe9fbb42f7e09e5af978a4c730b93d21a08830bfe1fdfb29bea99
|
data/lib/rubocopter/cli.rb
CHANGED
@@ -7,15 +7,14 @@ require_relative 'version'
|
|
7
7
|
RuboCopter::Options = Struct.new(:hash, :debug)
|
8
8
|
|
9
9
|
class RuboCopter::CLI
|
10
|
-
|
11
10
|
attr_reader :options
|
12
11
|
|
13
12
|
def run(args = ARGV)
|
14
|
-
parse_options(args)
|
15
|
-
check_for_offences
|
13
|
+
remaining_args = parse_options(args)
|
14
|
+
check_for_offences(remaining_args)
|
16
15
|
show_results
|
17
16
|
|
18
|
-
|
17
|
+
$CHILD_STATUS.exitstatus
|
19
18
|
end
|
20
19
|
|
21
20
|
private
|
@@ -40,34 +39,40 @@ class RuboCopter::CLI
|
|
40
39
|
rubyfiles
|
41
40
|
end
|
42
41
|
|
43
|
-
def check_for_offences
|
42
|
+
def check_for_offences(remaining_args = [])
|
43
|
+
rubocop_options = ['rubocop', '-R']
|
44
|
+
unless remaining_args.include?('--out')
|
45
|
+
rubocop_options += '--out rubocop_result.txt'.split
|
46
|
+
end
|
47
|
+
rubocop_options += remaining_args
|
48
|
+
|
44
49
|
# Check for git.
|
45
50
|
if `which git` == ''
|
46
51
|
puts 'git not detected. Running normal rubocop.'
|
47
|
-
system(Shellwords.join(
|
52
|
+
system(Shellwords.join(rubocop_options))
|
48
53
|
return
|
49
54
|
end
|
50
55
|
|
51
56
|
# Check for changes
|
52
57
|
`git rev-parse`
|
53
|
-
if
|
58
|
+
if $CHILD_STATUS.exitstatus == 0
|
54
59
|
files = changed_ruby_file_names
|
55
60
|
if files.length == 0
|
56
61
|
puts 'No changes detected, no reason to run rubocop'
|
57
62
|
exit(0)
|
58
63
|
else
|
59
|
-
system(Shellwords.join(
|
64
|
+
system(Shellwords.join(rubocop_options + files))
|
60
65
|
end
|
61
66
|
return
|
62
67
|
end
|
63
68
|
|
64
69
|
# No git directory
|
65
70
|
puts 'git directory not detected. Running normal rubocop.'
|
66
|
-
system(Shellwords.join(
|
71
|
+
system(Shellwords.join(rubocop_options))
|
67
72
|
end
|
68
73
|
|
69
74
|
def show_results
|
70
|
-
if File.
|
75
|
+
if File.exist?('rubocop_result.txt')
|
71
76
|
text = File.open('rubocop_result.txt').read
|
72
77
|
puts text
|
73
78
|
offense = /(\d+) offense/.match(text.split("\n")[-1])
|
@@ -85,9 +90,9 @@ class RuboCopter::CLI
|
|
85
90
|
@options = RuboCopter::Options.new('master', false)
|
86
91
|
|
87
92
|
opt_parser = OptionParser.new do |opts|
|
88
|
-
opts.banner = "Rubocopter v:#{RuboCopter::VERSION}\nUsage: rubocopter [options]"
|
93
|
+
opts.banner = "Rubocopter v:#{RuboCopter::VERSION}\nRubocop v:#{RuboCop::Version::STRING}\nUsage: rubocopter [options]\n *Any unknown options will be passed to rubocop directly."
|
89
94
|
|
90
|
-
opts.on('
|
95
|
+
opts.on('--commit HASH', 'git hash to compare against') do |hash|
|
91
96
|
@options.hash = hash
|
92
97
|
end
|
93
98
|
|
@@ -99,17 +104,31 @@ class RuboCopter::CLI
|
|
99
104
|
remove_git_hooks(hook)
|
100
105
|
end
|
101
106
|
|
102
|
-
opts.on(
|
107
|
+
opts.on('--debug', 'Prints runtime') do
|
103
108
|
@options.debug = true
|
104
109
|
end
|
105
110
|
|
106
|
-
opts.on(
|
111
|
+
opts.on('-h', '--help', 'Prints this help') do
|
107
112
|
puts opts
|
108
113
|
exit
|
109
114
|
end
|
110
115
|
end
|
111
116
|
|
112
|
-
|
117
|
+
remaining_args = {}
|
118
|
+
begin
|
119
|
+
opt_parser.parse(args)
|
120
|
+
rescue OptionParser::InvalidOption => e
|
121
|
+
remaining_args = e.args.map do |arg|
|
122
|
+
arg_index = args.index(arg)
|
123
|
+
if args[arg_index + 1].start_with?('-')
|
124
|
+
args[arg_index]
|
125
|
+
else
|
126
|
+
[args[arg_index], args[arg_index + 1]]
|
127
|
+
end
|
128
|
+
end.flatten
|
129
|
+
end
|
130
|
+
|
131
|
+
remaining_args
|
113
132
|
end
|
114
133
|
|
115
134
|
def install_git_hooks(hook)
|
@@ -138,5 +157,4 @@ class RuboCopter::CLI
|
|
138
157
|
end
|
139
158
|
exit(0)
|
140
159
|
end
|
141
|
-
|
142
160
|
end
|
data/lib/rubocopter/version.rb
CHANGED