quality 0.2.12 → 1.0.0

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: 0edeca607b817ca04ce01dedc757dfea9b36879d
4
- data.tar.gz: f44e13d9324673f926c2189f24a8344c6c048c3c
3
+ metadata.gz: 3b529fe70947f211e50846ac7eeca8401e7af353
4
+ data.tar.gz: ae51331dff7e90e9c860631bde9a3001bbcb4be6
5
5
  SHA512:
6
- metadata.gz: e9ba54c54300f7c0bb4fbe38835ce94d23122269cd337e49c5e0a3c18d04fa79d8b1db8b444299956a336f840cf8b34fe44bc522d6bf2f58661d320898fde286
7
- data.tar.gz: 7fafb512806d0221fe10defa3f1cf166053a8cf1028bafcf8284f4edc5756b80ec0691910dd47c97d65e20f1ba92327b75349c29ab0b5cc366d30db07738d164
6
+ metadata.gz: 96c466f3f82770eb6b591d0f0ab348f616f2656a74ea1abe06ab844c1d44f90be5fc58d4542792dc24d03d255f64a6d0a9177b6061e72eced6b04ff04c300a41
7
+ data.tar.gz: c27d3c90ec6234412cfaa4583b057d11c19db6d0e7d25bdc9ed585241d445ebb827d6e732ead3fdfdea38c30c445c9aaa58a616f8bd125f63183847559602289
data/README.md CHANGED
@@ -24,6 +24,44 @@ Then run:
24
24
  $ rake quality
25
25
  ```
26
26
 
27
+ If you want to ratchet up the quality and force yourself to improve
28
+ code, run:
29
+
30
+ ```bash
31
+ $ rake ratchet
32
+ ```
33
+
34
+ ## Configuration options
35
+
36
+ ```ruby
37
+ Quality::Rake::Task.new { |t|
38
+ # Name of quality task.
39
+ # Defaults to :quality.
40
+ t.quality_name = "quality"
41
+
42
+ # Name of ratchet task.
43
+ # Defaults to :ratchet.
44
+ t.ratchet_name = "ratchet"
45
+
46
+ # Array of strings describing tools to be skipped--e.g., ["cane"]
47
+ #
48
+ # Defaults to []
49
+ t.skip_tools = []
50
+
51
+ # Array of directory names which contain ruby files to analyze.
52
+ #
53
+ # Defaults to %w{lib test features}, which translates to *.rb in the base directory, as well as lib, test, and features.
54
+ t.ruby_dirs = %w{lib test features}
55
+
56
+ # Relative path to output directory where *_high_water_mark
57
+ # files will be read/written
58
+ #
59
+ # Defaults to .
60
+ t.output_dir = '.'
61
+ }
62
+ ```
63
+
64
+
27
65
  ## Optional tools
28
66
 
29
67
  The 'reek' gem is supported, but not by default. To support it, add the 'reek' gem to your Gemspec. Once reek supports Ruby 2.0, it will presumably support newer versions of the 'ruby_parser' gem. Currently it will disable Ruby 2.0 supports in other quality-check gems by forcing them to a lower version.
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rake/clean'
2
2
  require "bundler/gem_tasks"
3
+ require 'quality/rake/task'
3
4
 
4
5
  $:.unshift File.dirname(__FILE__) + '/lib'
5
6
 
@@ -17,3 +18,15 @@ Dir['tasks/**/*.rake'].each { |t| load t }
17
18
 
18
19
  task :default => [:test]
19
20
 
21
+ Quality::Rake::Task.new
22
+
23
+ task :clear_metrics do |t|
24
+ puts Time.now
25
+ ret =
26
+ system("git checkout coverage/.last_run.json *_high_water_mark")
27
+ if !ret
28
+ fail
29
+ end
30
+ end
31
+
32
+ task :localtest => [:clear_metrics, :test, :quality]
@@ -31,7 +31,11 @@ module Quality
31
31
 
32
32
  # Name of quality task.
33
33
  # Defaults to :quality.
34
- attr_accessor :name
34
+ attr_accessor :quality_name
35
+
36
+ # Name of ratchet task.
37
+ # Defaults to :ratchet.
38
+ attr_accessor :ratchet_name
35
39
 
36
40
  # Array of strings describing tools to be skipped--e.g., ["cane"]
37
41
  #
@@ -40,13 +44,45 @@ module Quality
40
44
 
41
45
  # Array of directory names which contain ruby files to analyze.
42
46
  #
43
- # Defaults to %w{lib test features}, which translates to *.rb in the base directory, as well as lib, test, and features.
47
+ # Defaults to %w{lib test features}, which translates to *.rb in
48
+ # the base directory, as well as lib, test, and features.
44
49
  attr_writer :ruby_dirs
45
50
 
51
+ # Relative path to output directory where *_high_water_mark
52
+ # files will be read/written
53
+ #
54
+ # Defaults to .
55
+ attr_writer :output_dir
56
+
46
57
  # Defines a new task, using the name +name+.
47
58
  def initialize(args = {})
48
- @name = args[:name]
49
- @name = 'quality' if @name.nil?
59
+ @quality_name = args[:quality_name] || 'quality'
60
+
61
+ @ratchet_name = args[:ratchet_name] || 'ratchet'
62
+
63
+ # allow unit tests to override the class that Rake DSL
64
+ # messages are sent to.
65
+ @dsl = args[:dsl]
66
+
67
+ # likewise, but for system()
68
+ @cmd_runner = args[:cmd_runner] || Kernel
69
+
70
+ # likewise, but for IO.popen()
71
+ @popener = args[:popener] || IO
72
+
73
+ # likewise, but for File.open() on the count files
74
+ @count_file = args[:count_file] || File
75
+
76
+ # likewise, but for IO.read()/IO.exist? on the count files
77
+ @count_io = args[:count_io] || IO
78
+
79
+ # likewise, but for Dir.glob() on target Ruby files
80
+ @globber = args[:globber] || Dir
81
+
82
+ # uses exist?() and open() to write out configuration files
83
+ # for tools if needed (e.g., .cane file)
84
+ @configuration_writer = args[:configuration_writer] || File
85
+
50
86
  @skip_tools = [] if @skip_tools.nil?
51
87
  @config_files = nil
52
88
  @source_files = nil
@@ -58,6 +94,7 @@ module Quality
58
94
  yield self if block_given?
59
95
  @config_files ||= 'config/**/*.reek'
60
96
  @source_files ||= 'lib/**/*.rb'
97
+ @output_dir ||= "."
61
98
  define
62
99
  end
63
100
 
@@ -66,11 +103,16 @@ module Quality
66
103
  def define # :nodoc:
67
104
  desc 'Verify quality has increased or stayed ' +
68
105
  'the same' unless ::Rake.application.last_comment
69
- task(name) { run_task }
70
- self
106
+ if @dsl.nil?
107
+ task(quality_name) { run_quality }
108
+ task(ratchet_name) { run_ratchet }
109
+ else
110
+ @dsl.task(quality_name) { run_quality }
111
+ @dsl.task(ratchet_name) { run_ratchet }
112
+ end
71
113
  end
72
114
 
73
- def run_task
115
+ def run_quality
74
116
  tools = ['cane', 'flog', 'flay', 'reek', 'rubocop']
75
117
  tools.each do |tool|
76
118
  installed = Gem::Specification.find_all_by_name(tool).any?
@@ -86,11 +128,27 @@ module Quality
86
128
  end
87
129
  end
88
130
 
131
+ def run_ratchet
132
+ @globber.glob("*_high_water_mark").each { |filename|
133
+ puts "Processing #{filename}"
134
+ existing_violations = @count_io.read(filename).to_i
135
+ if existing_violations < 0
136
+ raise "Problem with file #{filename}"
137
+ end
138
+ new_violations = [0, existing_violations - 1].max
139
+ @count_file.open(filename, 'w') {|f| f.write(new_violations.to_s) }
140
+ if new_violations != existing_violations
141
+ @cmd_runner.system("git commit -m 'tighten quality standard' #{filename}")
142
+ end
143
+ }
144
+ end
145
+
89
146
  def ratchet_quality_cmd(cmd,
90
147
  options,
91
148
  &process_output_line)
92
149
 
93
150
  gives_error_code_on_violations ||= options[:gives_error_code_on_violations]
151
+
94
152
  args ||= options[:args]
95
153
  emacs_format ||= options[:emacs_format]
96
154
 
@@ -109,7 +167,7 @@ module Quality
109
167
  full_cmd = "#{full_cmd} #{args}"
110
168
  end
111
169
 
112
- IO.popen(full_cmd) do |f|
170
+ @popener.popen(full_cmd) do |f|
113
171
  while line = f.gets
114
172
  if emacs_format
115
173
  if line =~ /^ *(\S*.rb:[0-9]*) *(.*)/
@@ -132,9 +190,9 @@ module Quality
132
190
  fail "Error detected running #{full_cmd}. Exit status is #{exit_status}, output is [#{out}]"
133
191
  end
134
192
  end
135
- filename = "#{cmd}_high_water_mark"
136
- if File.exist?(filename)
137
- existing_violations = IO.read(filename).to_i
193
+ filename = File.join(@output_dir, "#{cmd}_high_water_mark")
194
+ if @count_file.exist?(filename)
195
+ existing_violations = @count_io.read(filename).to_i
138
196
  else
139
197
  existing_violations = 9999999999
140
198
  end
@@ -145,13 +203,15 @@ module Quality
145
203
  "Reduce total number of #{cmd} violations to #{existing_violations} or below!"
146
204
  elsif violations < existing_violations
147
205
  puts "Ratcheting quality up..."
148
- File.open(filename, 'w') {|f| f.write(violations.to_s) }
206
+ @count_file.open(filename, 'w') do |f|
207
+ f.write(violations.to_s)
208
+ end
149
209
  end
150
210
  end
151
211
 
152
212
  def quality_cane
153
- if ! File.exist?(".cane")
154
- File.open(".cane", "w") {|f| f.write("-f **/*.rb")}
213
+ if ! @configuration_writer.exist?(".cane")
214
+ @configuration_writer.open(".cane", "w") {|f| f.write("-f **/*.rb")}
155
215
  end
156
216
  ratchet_quality_cmd("cane",
157
217
  gives_error_code_on_violations: true,
@@ -169,7 +229,7 @@ module Quality
169
229
  end
170
230
 
171
231
  def ruby_files
172
- Dir.glob('*.rb').concat(Dir.glob(File.join("{#{ruby_dirs.join(',')}}", '**', '*.rb'))).join(' ')
232
+ @globber.glob('*.rb').concat(@globber.glob(File.join("{#{ruby_dirs.join(',')}}", '**', '*.rb'))).join(' ')
173
233
  end
174
234
 
175
235
  def quality_reek
@@ -231,18 +291,6 @@ module Quality
231
291
  }
232
292
  end
233
293
 
234
- def quality
235
- Dir.glob("*_high_water_mark").each { |filename|
236
- puts "Processing #{filename}"
237
- existing_violations = IO.read(filename).to_i
238
- if existing_violations <= 0
239
- raise "Problem with file #{filename}"
240
- end
241
- new_violations = existing_violations - 1
242
- File.open(filename, 'w') {|f| f.write(new_violations.to_s) }
243
- system("git commit -m 'tighten quality standard' #{filename}")
244
- }
245
- end
246
294
  end
247
295
  end
248
296
  end
@@ -1,3 +1,3 @@
1
1
  module Quality
2
- VERSION = '0.2.12'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -42,4 +42,8 @@ your numbers don't get any worse over time.
42
42
 
43
43
  s.add_development_dependency(%q<bundler>, [">= 1.1"])
44
44
  s.add_development_dependency(%q<rake>)
45
+ s.add_development_dependency(%q<simplecov>)
46
+ s.add_development_dependency(%q<mocha>)
47
+ # depend on myself, so I can use my own features for development..
48
+ s.add_development_dependency(%q<quality>)
45
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quality
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vince Broz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-29 00:00:00.000000000 Z
11
+ date: 2013-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cane
@@ -136,6 +136,48 @@ dependencies:
136
136
  - - '>='
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: mocha
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: quality
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
139
181
  description: "Quality is a tool that runs quality checks on Ruby\ncode using rubocop,
140
182
  cane, reek, flog and flay, and makes sure \nyour numbers don't get any worse over
141
183
  time.\n"