code_quality 0.1.0 → 0.1.1

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: 37c28c316373313c706968fba46f52a023f20584
4
- data.tar.gz: d6143f5b24da0776c272fa06b5a626976932b739
3
+ metadata.gz: 2aad6bae79b3c4e3ed57dcbd8441768630056e0e
4
+ data.tar.gz: f54a234cff30d6713b1d6614380796975b560ce9
5
5
  SHA512:
6
- metadata.gz: daed8fdb4a6ad0ce29c93c298f55735b7ec9a26a44c96e13c9f292371093739789dab4b4670c9edeffd599e25825f120c67fc3c2ca71b50da9f0c1c776cfde5c
7
- data.tar.gz: ac3117746cec3a4bcf35be15c927aa369550609008e60bf4665dfbe6457cb04f68889bdad12da915b2137c8d8dcbac2b01442723db2b4c44b2a663837d8f9af5
6
+ metadata.gz: c04a6210d08688e077c8c3a40462381040bd91c82f869aa7776b24001e44026e3a5adcd625f00328876df8e1a3b5e8854d30e90f98330a5fa5398c1146fa0c81
7
+ data.tar.gz: b1d39e7d4ac9350b48bcfedee9e982d9f56334646b9fd4cc7877c3dbe936a9f4d5502bd9693bc6f8d33ec93a03b13fe5659e55e4d39e5c67b9af68b815a74201
data/code_quality.gemspec CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_dependency "bundler-audit"
25
25
  spec.add_dependency "brakeman"
26
+ spec.add_dependency "rubycritic"
26
27
 
27
28
  spec.add_development_dependency "bundler", "~> 1.16"
28
29
  spec.add_development_dependency "rake", "~> 10.0"
@@ -1,3 +1,3 @@
1
1
  module CodeQuality
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -58,8 +58,35 @@ namespace :code_quality do
58
58
  task :quality_audit => [:"quality_audit:default"] do; end
59
59
  namespace :quality_audit do
60
60
  # default tasks
61
- task :default do
62
- puts "PENDING"
61
+ task :default => [:rubycritic] do; end
62
+
63
+ # desc "prepare dir"
64
+ task :prepare => :helpers do
65
+ @report_dir = "tmp/code_quality/quality_audit"
66
+ prepare_dir @report_dir
67
+
68
+ def report_dir
69
+ @report_dir
70
+ end
71
+ end
72
+
73
+ desc "rubycritic"
74
+ # e.g.: rake code_quality:quality_audit:rubycritic lowest_score=94.5
75
+ task :rubycritic => :prepare do
76
+ options = options_from_env(:lowest_score)
77
+ run_audit "Rubycritic - static analysis gems such as Reek, Flay and Flog to provide a quality report of your Ruby code." do
78
+ report = `rubycritic -p #{report_dir}/rubycritic app lib`
79
+ puts report
80
+
81
+ # if config lowest_score then audit it with report score
82
+ if options[:lowest_score]
83
+ if report.last(20) =~ /Score: (.+)/
84
+ report_score = $1.to_f
85
+ lowest_score = options[:lowest_score].to_f
86
+ audit_faild "Report score #{colorize(report_score, :yellow)} is lower then #{colorize(lowest_score, :yellow)}, must improve your code quality or set a higher #{colorize("lowest_score", :black, :white)}" if report_score < lowest_score
87
+ end
88
+ end
89
+ end
63
90
  end
64
91
  end
65
92
 
@@ -98,7 +125,27 @@ namespace :code_quality do
98
125
  end
99
126
 
100
127
  def audit_faild(msg)
101
- abort "[AUDIT FAILED] #{msg}"
128
+ flag = colorize("[AUDIT FAILED]", :red, :yellow)
129
+ abort "#{flag} #{msg}"
130
+ end
131
+
132
+ # e.g.: options_from_env(:a, :b) => {:a => ..., :b => ... }
133
+ def options_from_env(*keys)
134
+ ENV.to_h.slice(*keys.map(&:to_s)).symbolize_keys!
135
+ end
136
+
137
+ # set text color, background color using ANSI escape sequences, e.g.:
138
+ # colors = %w(black red green yellow blue pink cyan white default)
139
+ # colors.each { |color| puts colorize(color, color) }
140
+ # colors.each { |color| puts colorize(color, :green, color) }
141
+ def colorize(text, color = "default", bg = "default")
142
+ colors = %w(black red green yellow blue pink cyan white default)
143
+ fgcode = 30; bgcode = 40
144
+ tpl = "\e[%{code}m%{text}\e[0m"
145
+ cov = lambda { |txt, col, cod| tpl % {text: txt, code: (cod+colors.index(col.to_s))} }
146
+ ansi = cov.call(text, color, fgcode)
147
+ ansi = cov.call(ansi, bg, bgcode) if bg.to_s != "default"
148
+ ansi
102
149
  end
103
150
  end
104
151
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_quality
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - RainChen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-21 00:00:00.000000000 Z
11
+ date: 2017-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler-audit
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubycritic
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement