checker 0.7.0 → 0.8.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +5 -6
- data/Gemfile +1 -1
- data/Gemfile.lock +89 -45
- data/Guardfile +16 -0
- data/Rakefile +2 -2
- data/bin/checker +2 -2
- data/checker.gemspec +13 -11
- data/lib/checker.rb +14 -16
- data/lib/checker/cli.rb +19 -22
- data/lib/checker/core_ext.rb +7 -9
- data/lib/checker/helper.rb +1 -1
- data/lib/checker/installator.rb +8 -8
- data/lib/checker/modules/base.rb +42 -44
- data/lib/checker/modules/coffeescript.rb +5 -3
- data/lib/checker/modules/conflict.rb +4 -4
- data/lib/checker/modules/console_log.rb +4 -3
- data/lib/checker/modules/haml.rb +4 -2
- data/lib/checker/modules/javascript.rb +5 -3
- data/lib/checker/modules/multifile.rb +16 -0
- data/lib/checker/modules/pry.rb +4 -4
- data/lib/checker/modules/rubocop.rb +12 -4
- data/lib/checker/modules/ruby.rb +6 -3
- data/lib/checker/modules/sass.rb +16 -14
- data/lib/checker/modules/slim.rb +4 -2
- data/lib/checker/modules/yaml.rb +5 -3
- data/lib/checker/options.rb +1 -1
- data/lib/checker/results/console_log.rb +1 -1
- data/lib/checker/rvm.rb +2 -2
- data/lib/checker/version.rb +1 -1
- data/spec/checker/cli_spec.rb +10 -8
- data/spec/checker/fixtures/conflict/without_conflict.rb +1 -2
- data/spec/checker/fixtures/pry/with_both.rb +1 -2
- data/spec/checker/fixtures/pry/with_pry.rb +1 -1
- data/spec/checker/fixtures/pry/with_pry_remote.rb +1 -1
- data/spec/checker/fixtures/pry/without_pry.rb +1 -2
- data/spec/checker/fixtures/ruby/good.rb +1 -1
- data/spec/checker/modules/base_spec.rb +15 -15
- data/spec/checker/modules/coffeescript_spec.rb +11 -11
- data/spec/checker/modules/conflict_spec.rb +8 -8
- data/spec/checker/modules/console_log_spec.rb +13 -13
- data/spec/checker/modules/haml_spec.rb +13 -13
- data/spec/checker/modules/javascript_spec.rb +22 -22
- data/spec/checker/modules/pry_spec.rb +10 -10
- data/spec/checker/modules/ruby_spec.rb +9 -10
- data/spec/checker/modules/sass_spec.rb +46 -46
- data/spec/checker/modules/slim_spec.rb +12 -12
- data/spec/checker/modules/yaml_spec.rb +12 -12
- data/spec/spec_helper.rb +6 -14
- metadata +39 -10
data/lib/checker/installator.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Checker
|
2
2
|
class Installator
|
3
3
|
def self.template
|
4
|
-
dir = File.expand_path(
|
4
|
+
dir = File.expand_path("../../..", __FILE__)
|
5
5
|
temp = File.read(File.join(dir, "/templates/checker-prepare-commit-msg"))
|
6
6
|
ERB.new(temp).result
|
7
7
|
end
|
@@ -21,7 +21,7 @@ module Checker
|
|
21
21
|
check_hook!
|
22
22
|
|
23
23
|
pre_commit = "#{hooks_dir}/prepare-commit-msg"
|
24
|
-
if File.
|
24
|
+
if File.exist?(pre_commit)
|
25
25
|
puts "Removing current git precommit hook..."
|
26
26
|
File.delete(pre_commit)
|
27
27
|
end
|
@@ -36,9 +36,9 @@ module Checker
|
|
36
36
|
if File.exist?(pre_commit)
|
37
37
|
puts "Appending checker script to existing prepare-commit-msg hook..."
|
38
38
|
begin
|
39
|
-
open(pre_commit,
|
40
|
-
f.puts(
|
41
|
-
f.chmod(
|
39
|
+
open(pre_commit, "a") do |f|
|
40
|
+
f.puts(template)
|
41
|
+
f.chmod(0o755)
|
42
42
|
end
|
43
43
|
rescue Exception => e
|
44
44
|
puts "Couldn't append checker script: #{e.message}"
|
@@ -46,12 +46,12 @@ module Checker
|
|
46
46
|
end
|
47
47
|
exit 0
|
48
48
|
else
|
49
|
-
tmp =
|
49
|
+
tmp = template
|
50
50
|
str = "#!/bin/bash \n #{tmp}"
|
51
51
|
begin
|
52
|
-
open(pre_commit, "w") do |f|
|
52
|
+
open(pre_commit, "w") do |f|
|
53
53
|
f.puts(str)
|
54
|
-
f.chmod(
|
54
|
+
f.chmod(0o755)
|
55
55
|
end
|
56
56
|
rescue Exception => e
|
57
57
|
puts "Couldn't write checker script: #{e.message}"
|
data/lib/checker/modules/base.rb
CHANGED
@@ -5,13 +5,13 @@ module Checker
|
|
5
5
|
|
6
6
|
def initialize(file_list = nil)
|
7
7
|
self.files = file_list
|
8
|
-
self.full_results = {:
|
8
|
+
self.full_results = { total: 0, ok: 0, warning: 0, fail: 0 }
|
9
9
|
end
|
10
10
|
|
11
11
|
def check
|
12
|
-
check_files_existing
|
12
|
+
check_files_existing || (return true)
|
13
13
|
print_module_header
|
14
|
-
check_executable
|
14
|
+
check_executable || (return true)
|
15
15
|
check_all_files
|
16
16
|
valid?
|
17
17
|
end
|
@@ -23,17 +23,17 @@ module Checker
|
|
23
23
|
def files_to_check
|
24
24
|
@files_to_check ||= begin
|
25
25
|
if self.class.extensions.any?
|
26
|
-
|
26
|
+
files.select do |f|
|
27
27
|
self.class.extensions.map { |ex| f.ends_with?(".#{ex}") }.any?
|
28
|
-
|
28
|
+
end
|
29
29
|
else
|
30
|
-
|
30
|
+
files
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
def classname
|
36
|
-
self.class.to_s.split(
|
36
|
+
self.class.to_s.split("::").last
|
37
37
|
end
|
38
38
|
|
39
39
|
private
|
@@ -63,33 +63,33 @@ module Checker
|
|
63
63
|
true
|
64
64
|
end
|
65
65
|
|
66
|
+
def after_check; end
|
67
|
+
|
66
68
|
def check_all_files
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
69
|
+
@results = files_to_check.map do |file_name|
|
70
|
+
gather_result :total
|
71
|
+
color " Checking #{file_name}...", :yellow
|
72
|
+
result = check_one_file(file_name)
|
73
|
+
show_status result.status
|
74
|
+
gather_result result.status
|
75
|
+
flush_and_forget_output result.status
|
76
|
+
after_check
|
77
|
+
result.success?
|
77
78
|
end
|
78
79
|
end
|
79
80
|
|
80
|
-
def check_one(
|
81
|
+
def check_one(_filename, _options = {})
|
81
82
|
puts "Called from #{self.class} - extend me in here!"
|
82
83
|
false
|
83
84
|
end
|
84
85
|
|
85
|
-
def check_one_file
|
86
|
+
def check_one_file(file_name)
|
86
87
|
checksum = ::Digest::MD5.hexdigest(file_name)
|
87
88
|
debug(file_name)
|
88
|
-
|
89
|
-
check_one(checkout_file_name(checksum), :extension => File.extname(file_name))
|
89
|
+
check_one(file_name, extension: File.extname(file_name))
|
90
90
|
end
|
91
91
|
|
92
|
-
def self.extensions
|
92
|
+
def self.extensions(*args)
|
93
93
|
@extensions ||= []
|
94
94
|
if args.empty?
|
95
95
|
@extensions
|
@@ -98,8 +98,8 @@ module Checker
|
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
-
def gather_result
|
102
|
-
|
101
|
+
def gather_result(result)
|
102
|
+
full_results[result] += 1
|
103
103
|
end
|
104
104
|
|
105
105
|
def plain_command(cmd, options = {})
|
@@ -108,13 +108,13 @@ module Checker
|
|
108
108
|
end
|
109
109
|
|
110
110
|
def silent_command(cmd, options = {})
|
111
|
-
options = { :
|
111
|
+
options = { output: false, return_boolean: true }.merge(options)
|
112
112
|
cmd = parse_command(cmd, options)
|
113
113
|
execute(cmd, options)
|
114
114
|
end
|
115
115
|
|
116
116
|
def flush_and_forget_output(status)
|
117
|
-
print @buffer.to_s if (status == :warning
|
117
|
+
print @buffer.to_s if (status == :warning) || (status == :fail)
|
118
118
|
@buffer = ""
|
119
119
|
end
|
120
120
|
|
@@ -150,15 +150,15 @@ module Checker
|
|
150
150
|
end
|
151
151
|
|
152
152
|
def exitstatus
|
153
|
-
|
153
|
+
$CHILD_STATUS && $CHILD_STATUS.exitstatus
|
154
154
|
end
|
155
155
|
|
156
156
|
def success?
|
157
|
-
|
157
|
+
$CHILD_STATUS && $CHILD_STATUS.success?
|
158
158
|
end
|
159
159
|
|
160
|
-
def parse_command
|
161
|
-
options = { :
|
160
|
+
def parse_command(command, options)
|
161
|
+
options = { bundler: true, output: true, rvm: true }.merge(options)
|
162
162
|
command = bundler_command(command) if use_bundler? && options[:bundler]
|
163
163
|
command = rvm_command(command) if use_rvm? && options[:rvm]
|
164
164
|
command << " > /dev/null" unless options[:output]
|
@@ -166,7 +166,7 @@ module Checker
|
|
166
166
|
end
|
167
167
|
|
168
168
|
def color(str, color)
|
169
|
-
print str.colorize(color)
|
169
|
+
print str.colorize(color) unless str.empty?
|
170
170
|
end
|
171
171
|
|
172
172
|
def name
|
@@ -174,7 +174,7 @@ module Checker
|
|
174
174
|
end
|
175
175
|
|
176
176
|
def use_bundler?
|
177
|
-
File.
|
177
|
+
File.exist?("Gemfile.lock")
|
178
178
|
end
|
179
179
|
|
180
180
|
def bundler_command(command)
|
@@ -182,7 +182,7 @@ module Checker
|
|
182
182
|
end
|
183
183
|
|
184
184
|
def use_rvm?
|
185
|
-
|
185
|
+
false
|
186
186
|
end
|
187
187
|
|
188
188
|
def rails_project?
|
@@ -190,7 +190,7 @@ module Checker
|
|
190
190
|
end
|
191
191
|
|
192
192
|
def rails_with_ap?
|
193
|
-
rails_project? && File.
|
193
|
+
rails_project? && File.exist?("app/assets")
|
194
194
|
end
|
195
195
|
|
196
196
|
def rvm_command(command)
|
@@ -202,21 +202,19 @@ module Checker
|
|
202
202
|
end
|
203
203
|
|
204
204
|
def with_checker_cache
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
`rm -rf app/assets/stylesheets/checker-cache*` if rails_with_ap?
|
212
|
-
end
|
205
|
+
`mkdir .checker-cache`
|
206
|
+
yield if block_given?
|
207
|
+
ensure
|
208
|
+
`rm -rf .checker-cache > /dev/null 2>&1`
|
209
|
+
## for sass check
|
210
|
+
`rm -rf app/assets/stylesheets/checker-cache*` if rails_with_ap?
|
213
211
|
end
|
214
212
|
|
215
|
-
def checkout_file
|
213
|
+
def checkout_file(file_name, target)
|
216
214
|
`git show :0:#{file_name} > #{checkout_file_name(target)} 2>/dev/null`
|
217
215
|
end
|
218
216
|
|
219
|
-
def checkout_file_name
|
217
|
+
def checkout_file_name(target)
|
220
218
|
".checker-cache/#{target}"
|
221
219
|
end
|
222
220
|
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
module Checker
|
2
2
|
module Modules
|
3
3
|
class Coffeescript < Base
|
4
|
-
extensions
|
4
|
+
extensions "coffee"
|
5
|
+
|
5
6
|
private
|
6
|
-
|
7
|
+
|
8
|
+
def check_one(file, _opts = {})
|
7
9
|
Checker::Result.result(self, plain_command("cat #{file} | egrep -v '^//=' | coffee -sc > /dev/null"))
|
8
10
|
end
|
9
11
|
|
10
12
|
def check_for_executable
|
11
|
-
silent_command(
|
13
|
+
silent_command("coffee -v", bundler: false)
|
12
14
|
end
|
13
15
|
|
14
16
|
def dependency_message
|
@@ -1,19 +1,19 @@
|
|
1
1
|
module Checker
|
2
2
|
module Modules
|
3
3
|
class Conflict < Base
|
4
|
-
|
5
4
|
private
|
6
|
-
|
5
|
+
|
6
|
+
def check_one(file, _opts = {})
|
7
7
|
status = [check_for_conflict_start(file), check_for_conflict_end(file)].all_true?
|
8
8
|
Checker::Result.result(self, status ? 0 : 1)
|
9
9
|
end
|
10
10
|
|
11
11
|
def check_for_conflict_start(file)
|
12
|
-
!plain_command("grep -n \"<<<<<<< \" #{file}", :
|
12
|
+
!plain_command("grep -n \"<<<<<<< \" #{file}", bundler: false, return_boolean: true, rvm: false)
|
13
13
|
end
|
14
14
|
|
15
15
|
def check_for_conflict_end(file)
|
16
|
-
!plain_command("grep -n \">>>>>>> \" #{file}", :
|
16
|
+
!plain_command("grep -n \">>>>>>> \" #{file}", bundler: false, return_boolean: true, rvm: false)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module Checker
|
2
2
|
module Modules
|
3
3
|
class ConsoleLog < Base
|
4
|
-
extensions
|
4
|
+
extensions "coffee", "js"
|
5
5
|
|
6
6
|
private
|
7
|
-
|
8
|
-
|
7
|
+
|
8
|
+
def check_one(file, _opts = {})
|
9
|
+
Checker::Result.result(self, plain_command("grep -n \"console\\.log\" #{file}", bundler: false, rvm: false))
|
9
10
|
end
|
10
11
|
|
11
12
|
def show_status(status)
|
data/lib/checker/modules/haml.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
module Checker
|
2
2
|
module Modules
|
3
3
|
class Haml < Base
|
4
|
-
extensions
|
4
|
+
extensions "haml"
|
5
|
+
|
5
6
|
private
|
6
|
-
|
7
|
+
|
8
|
+
def check_one(file, _opts = {})
|
7
9
|
Checker::Result.result(self, plain_command("haml --check #{file} >> /dev/null"))
|
8
10
|
end
|
9
11
|
|
@@ -1,14 +1,16 @@
|
|
1
1
|
module Checker
|
2
2
|
module Modules
|
3
3
|
class Javascript < Base
|
4
|
-
extensions
|
4
|
+
extensions "js"
|
5
|
+
|
5
6
|
private
|
6
|
-
|
7
|
+
|
8
|
+
def check_one(file, _opts = {})
|
7
9
|
Checker::Result.result(self, plain_command("jsl -process #{file}"))
|
8
10
|
end
|
9
11
|
|
10
12
|
def check_for_executable
|
11
|
-
silent_command(
|
13
|
+
silent_command("jsl -help:conf", bundler: false)
|
12
14
|
end
|
13
15
|
|
14
16
|
def dependency_message
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Checker
|
2
|
+
module Modules
|
3
|
+
class Multifile < Base
|
4
|
+
def check_all_files
|
5
|
+
gather_result :total
|
6
|
+
color " Checking #{files_to_check.join(', ')}...", :yellow
|
7
|
+
result = check_all(files_to_check)
|
8
|
+
show_status result.status
|
9
|
+
gather_result result.status
|
10
|
+
flush_and_forget_output result.status
|
11
|
+
@results = [result.success?]
|
12
|
+
after_check
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/checker/modules/pry.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
module Checker
|
2
2
|
module Modules
|
3
3
|
class Pry < Base
|
4
|
-
|
5
4
|
private
|
6
|
-
|
5
|
+
|
6
|
+
def check_one(file, _opts = {})
|
7
7
|
status = [check_for_binding_pry(file), check_for_binding_remote_pry(file)].all_true?
|
8
8
|
Checker::Result.result(self, status ? 0 : 1)
|
9
9
|
end
|
10
10
|
|
11
11
|
def check_for_binding_pry(file)
|
12
|
-
!plain_command("grep -n \"binding\\.pry\" #{file}", :
|
12
|
+
!plain_command("grep -n \"binding\\.pry\" #{file}", bundler: false, return_boolean: true, rvm: false)
|
13
13
|
end
|
14
14
|
|
15
15
|
def check_for_binding_remote_pry(file)
|
16
|
-
!plain_command("grep -n \"binding\\.remote_pry\" #{file}", :
|
16
|
+
!plain_command("grep -n \"binding\\.remote_pry\" #{file}", bundler: false, return_boolean: true, rvm: false)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module Checker
|
2
2
|
module Modules
|
3
|
-
class Rubocop <
|
4
|
-
extensions 'rb'
|
3
|
+
class Rubocop < Multifile
|
5
4
|
private
|
6
|
-
|
7
|
-
|
5
|
+
|
6
|
+
def check_all(files, _opts = {})
|
7
|
+
Checker::Result.result(self, plain_command("rubocop -f c #{files.join(' ')}", bundler: false))
|
8
8
|
end
|
9
9
|
|
10
10
|
def dependency_message
|
@@ -12,6 +12,14 @@ module Checker
|
|
12
12
|
str << "Install rubocop using rubygems: 'gem install rubocop'"
|
13
13
|
str
|
14
14
|
end
|
15
|
+
|
16
|
+
def fix_message(files)
|
17
|
+
"\nTo Autocorrect, execute: rubocop -a #{files.join(' ')}\n"
|
18
|
+
end
|
19
|
+
|
20
|
+
def after_check
|
21
|
+
puts fix_message(files_to_check).colorize(:green) if @results.first == false
|
22
|
+
end
|
15
23
|
end
|
16
24
|
end
|
17
25
|
end
|
data/lib/checker/modules/ruby.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
module Checker
|
2
2
|
module Modules
|
3
3
|
class Ruby < Base
|
4
|
-
extensions
|
4
|
+
extensions "rb"
|
5
|
+
|
5
6
|
private
|
6
|
-
|
7
|
-
|
7
|
+
|
8
|
+
def check_one(file, _opts = {})
|
9
|
+
puts " using version: #{`ruby -v`.chomp}"
|
10
|
+
Checker::Result.result(self, plain_command("ruby -c #{file}", bundler: false))
|
8
11
|
end
|
9
12
|
end
|
10
13
|
end
|
data/lib/checker/modules/sass.rb
CHANGED
@@ -1,23 +1,25 @@
|
|
1
1
|
module Checker
|
2
2
|
module Modules
|
3
3
|
class Sass < Base
|
4
|
-
extensions
|
4
|
+
extensions "scss", "sass"
|
5
|
+
|
5
6
|
private
|
7
|
+
|
6
8
|
def check_one(file, opts = {})
|
7
|
-
if preconditions_for_rails?(file)
|
9
|
+
if Checker::Options.use_rails_for_sass && preconditions_for_rails?(file)
|
8
10
|
rails_check(file, opts)
|
9
11
|
else
|
10
12
|
normal_check(file, opts)
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
14
|
-
def rails_check(file,
|
16
|
+
def rails_check(file, _opts)
|
15
17
|
debug("Rails project detected") if rails_project?
|
16
18
|
Checker::Result.result(self, plain_command(%(rails runner "Rails.application.assets.find_asset(\\"#{Dir.pwd}/#{file}\\").to_s")))
|
17
19
|
end
|
18
20
|
|
19
21
|
def normal_check(file, opts)
|
20
|
-
Checker::Result.result(self, plain_command("sass #{
|
22
|
+
Checker::Result.result(self, plain_command("sass #{'--scss' if opts[:extension] == '.scss'} -c #{file}"))
|
21
23
|
end
|
22
24
|
|
23
25
|
def check_for_executable
|
@@ -36,41 +38,41 @@ module Checker
|
|
36
38
|
end
|
37
39
|
|
38
40
|
## for rails project
|
39
|
-
def checkout_file
|
41
|
+
def checkout_file(file_name, target)
|
40
42
|
debug("git show :0:#{file_name} > #{checkout_file_name(target)} 2>/dev/null")
|
41
43
|
mkdir_if_necessary(checkout_file_name(target))
|
42
44
|
`git show :0:#{file_name} > #{checkout_file_name(target)} 2>/dev/null`
|
43
45
|
end
|
44
46
|
|
45
47
|
def mkdir_if_necessary(target)
|
46
|
-
dir = target.gsub(File.basename(target),
|
48
|
+
dir = target.gsub(File.basename(target), "")
|
47
49
|
create_dir(dir)
|
48
50
|
end
|
49
51
|
|
50
52
|
def create_dir(dir)
|
51
53
|
debug("Creating dir #{dir}")
|
52
|
-
Dir.mkdir(dir) unless File.
|
54
|
+
Dir.mkdir(dir) unless File.exist?(dir)
|
53
55
|
end
|
54
56
|
|
55
57
|
def stylesheets_dir
|
56
58
|
"app/assets/stylesheets/"
|
57
59
|
end
|
58
60
|
|
59
|
-
def checkout_file_name
|
60
|
-
|
61
|
+
def checkout_file_name(target)
|
62
|
+
Checker::Options.use_rails_for_sass && rails_with_ap? ? "#{stylesheets_dir}checker-cache#{target}" : super
|
61
63
|
end
|
62
64
|
|
63
|
-
def proper_path
|
64
|
-
file_name.gsub(/app\/assets\/stylesheets\//,
|
65
|
+
def proper_path(file_name)
|
66
|
+
file_name.gsub(/app\/assets\/stylesheets\//, "")
|
65
67
|
end
|
66
68
|
|
67
|
-
def check_one_file
|
68
|
-
if
|
69
|
+
def check_one_file(file_name)
|
70
|
+
if Checker::Options.use_rails_for_sass && rails_with_ap?
|
69
71
|
color " (using rails runner)... ", :blue
|
70
72
|
debug(file_name)
|
71
73
|
debug(proper_path(file_name))
|
72
74
|
checkout_file(file_name, proper_path(file_name))
|
73
|
-
check_one(checkout_file_name(proper_path(file_name)), :
|
75
|
+
check_one(checkout_file_name(proper_path(file_name)), extension: File.extname(file_name))
|
74
76
|
else
|
75
77
|
super
|
76
78
|
end
|