quality 1.3.0 → 1.3.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: 350f6c6730ee079bb5d55ac825ccbfd41e2fdfd2
4
- data.tar.gz: 4c6c2f025cde6d119766c48c945e9edbd18fe032
3
+ metadata.gz: 3fd46a1c5027604b62f85dbe5fe6a29f95242188
4
+ data.tar.gz: 3f3da1a73252e2c1b28164084dd3f5f3da8abf89
5
5
  SHA512:
6
- metadata.gz: c77587613d9841670e38b35623dd180326b3fc12c1a01b671a6ceec66eddc9c9b5fa4a7cabb9eef3b395a5fecc8801b6bba9277e07927ddcc571adccf49bfbf1
7
- data.tar.gz: 27690620eda4e95a5cd3f53590b06235ec28e8c7f4ca870f8dc3a2f447203d6a6cd898fff7e8ccd9b874e4b5daada3a318268ed5771c6b8e281138a872af7b43
6
+ metadata.gz: e1894369f734937ee0df1adabf61eb3def10bdd59c70e9bb522d16bff23d0c89e61ecb02f7f6456afc23ac6fb7f1743ac87b3a8e0e66aa3bc4f1359ee0b98da0
7
+ data.tar.gz: 8751ecd3fe496a94f9de979543b724fd171eab819dc404af2aa3f8382acad3628d96abf3f116a9a7d90085a24e15f8f83ad1158a4da42189e80215e451d65979
data/README.md CHANGED
@@ -1,10 +1,12 @@
1
+ [![Build Status](https://travis-ci.org/apiology/quality.png)](https://travis-ci.org/apiology/quality)
2
+
1
3
  # Quality -- code quality ratchet for Ruby
2
4
 
3
5
  ##Overview
4
6
 
5
7
  Quality is a tool that runs quality checks on Ruby code using cane,
6
- reek, flog and flay, and makes sure your numbers don't get any worse
7
- over time.
8
+ reek, flog, flay and rubocop and makes sure your numbers don't get any
9
+ worse over time.
8
10
 
9
11
  ```bash
10
12
  $ gem install quality
@@ -71,11 +73,11 @@ Quality::Rake::Task.new { |t|
71
73
 
72
74
  Quality makes use of the following other gems, which do the actual checking:
73
75
 
74
- * reek
75
- * cane
76
- * flog
77
- * flay
78
- * rubocop
76
+ * [reek](https://github.com/troessner/reek)
77
+ * [cane](https://github.com/square/cane)
78
+ * [flog](https://github.com/seattlerb/flog)
79
+ * [flay](https://github.com/seattlerb/flay)
80
+ * [rubocop](https://github.com/bbatsov/rubocop)
79
81
 
80
82
  ### Learn More
81
83
 
data/Rakefile CHANGED
@@ -1,15 +1,18 @@
1
1
  require 'rake/clean'
2
- require "bundler/gem_tasks"
2
+ require 'bundler/gem_tasks'
3
3
  require 'quality/rake/task'
4
4
 
5
- $:.unshift File.dirname(__FILE__) + '/lib'
5
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/lib'
6
6
 
7
7
  PROJECT_NAME = 'quality'
8
8
 
9
- BUILD_DIR = 'build'; directory BUILD_DIR
10
- PKG_DIR = "#{BUILD_DIR}/pkg"; directory PKG_DIR
9
+ BUILD_DIR = 'build'
10
+ directory BUILD_DIR
11
11
 
12
- GEM_MANIFEST = "Manifest.txt"
12
+ PKG_DIR = "#{BUILD_DIR}/pkg"
13
+ directory PKG_DIR
14
+
15
+ GEM_MANIFEST = 'Manifest.txt'
13
16
  VERSION_FILE = 'lib/quality.rb'
14
17
 
15
18
  CLOBBER.include("#{BUILD_DIR}/*")
@@ -20,15 +23,12 @@ Quality::Rake::Task.new do |t|
20
23
  t.skip_tools = ['reek']
21
24
  end
22
25
 
23
- task :clear_metrics do |t|
26
+ task :clear_metrics do |_t|
24
27
  puts Time.now
25
- ret =
26
- system("git checkout coverage/.last_run.json *_high_water_mark")
27
- if !ret
28
- fail
29
- end
28
+ ret = system('git checkout coverage/.last_run.json *_high_water_mark')
29
+ fail unless ret
30
30
  end
31
31
 
32
- task :localtest => [:clear_metrics, :test, :quality]
32
+ task localtest: [:clear_metrics, :test, :quality]
33
33
 
34
- task :default => [:localtest]
34
+ task default: [:localtest]
@@ -13,7 +13,7 @@ module Quality
13
13
  @violations = 0
14
14
  end
15
15
 
16
- def process!(&count_violations_on_line)
16
+ def process(&count_violations_on_line)
17
17
  process_file(file, &count_violations_on_line)
18
18
  end
19
19
 
@@ -42,9 +42,9 @@ module Quality
42
42
 
43
43
  def preprocess_line_for_emacs
44
44
  if @current_line =~ /^ *(\S*.rb:[0-9]*) *(.*)/
45
- $1 + ': ' + $2 + "\n"
45
+ Regexp.last_match[1] + ': ' + Regexp.last_match[2] + "\n"
46
46
  elsif @current_line =~ /^ *(.*) +(\S*.rb:[0-9]*) *(.*)/
47
- $2 + ': ' + $1 + "\n"
47
+ Regexp.last_match[2] + ': ' + Regexp.last_match[1] + "\n"
48
48
  else
49
49
  @current_line
50
50
  end
@@ -37,7 +37,7 @@ module Quality
37
37
  def run_command(processor, &count_violations_on_line)
38
38
  @popener.popen(full_cmd) do |file|
39
39
  processor.file = file
40
- @command_output = processor.process!(&count_violations_on_line)
40
+ @command_output = processor.process(&count_violations_on_line)
41
41
  end
42
42
  $CHILD_STATUS.exitstatus
43
43
  end
@@ -45,10 +45,9 @@ module Quality
45
45
  def check_exit_status(exit_status)
46
46
  return if @command_options[:gives_error_code_on_violations]
47
47
 
48
- if exit_status != 0
49
- fail("Error detected running #{full_cmd}. " \
50
- "Exit status is #{exit_status}, output is [#{out}]")
51
- end
48
+ fail("Error detected running #{full_cmd}. " \
49
+ "Exit status is #{exit_status}, " \
50
+ "output is [#{out}]") if exit_status != 0
52
51
  end
53
52
 
54
53
  def existing_violations
@@ -85,13 +84,13 @@ module Quality
85
84
 
86
85
  @found_output = false
87
86
  if args.size > 0
88
- "#{get_cmd_with_ruby_hack_prefix} #{args}"
87
+ "#{cmd_with_ruby_hack_prefix} #{args}"
89
88
  else
90
- "#{get_cmd_with_ruby_hack_prefix}"
89
+ "#{cmd_with_ruby_hack_prefix}"
91
90
  end
92
91
  end
93
92
 
94
- def get_cmd_with_ruby_hack_prefix
93
+ def cmd_with_ruby_hack_prefix
95
94
  if defined?(RUBY_ENGINE) && (RUBY_ENGINE == 'jruby')
96
95
  "jruby -S #{@cmd}"
97
96
  elsif RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
@@ -4,6 +4,11 @@ require 'rake'
4
4
  require 'rake/tasklib'
5
5
  require 'rbconfig'
6
6
  require_relative '../quality_checker'
7
+ require_relative '../tools/cane'
8
+ require_relative '../tools/flay'
9
+ require_relative '../tools/flog'
10
+ require_relative '../tools/reek'
11
+ require_relative '../tools/rubocop'
7
12
 
8
13
  module Quality
9
14
  #
@@ -24,6 +29,12 @@ module Quality
24
29
  #
25
30
  # rake quality
26
31
  class Task < ::Rake::TaskLib
32
+ include Tools::Cane
33
+ include Tools::Flay
34
+ include Tools::Flog
35
+ include Tools::Reek
36
+ include Tools::Rubocop
37
+
27
38
  # Name of quality task.
28
39
  # Defaults to :quality.
29
40
  attr_accessor :quality_name
@@ -51,10 +62,29 @@ module Quality
51
62
 
52
63
  # Defines a new task, using the name +name+.
53
64
  def initialize(args = {})
65
+ parse_args(args)
66
+
67
+ @skip_tools = []
68
+
69
+ @output_dir = '.'
70
+
71
+ yield self if block_given?
72
+
73
+ define
74
+ end
75
+
76
+ def parse_task_name_args(args)
54
77
  @quality_name = args[:quality_name] || 'quality'
55
78
 
56
79
  @ratchet_name = args[:ratchet_name] || 'ratchet'
80
+ end
81
+
82
+ def parse_args(args)
83
+ parse_task_name_args(args)
84
+ parse_unit_test_overrides(args)
85
+ end
57
86
 
87
+ def parse_unit_test_overrides(args)
58
88
  # allow unit tests to override the class that Rake DSL
59
89
  # messages are sent to.
60
90
  @dsl = args[:dsl] || ::Rake::Task
@@ -81,14 +111,6 @@ module Quality
81
111
  # Class which actually runs the quality check commands
82
112
  @quality_checker_class =
83
113
  args[:quality_checker_class] || Quality::QualityChecker
84
-
85
- @skip_tools = []
86
-
87
- @output_dir = '.'
88
-
89
- yield self if block_given?
90
-
91
- define
92
114
  end
93
115
 
94
116
  private
@@ -104,7 +126,11 @@ module Quality
104
126
  end
105
127
 
106
128
  def tools
107
- %w(cane flog flay reek rubocop)
129
+ self.class.ancestors.map do |ancestor|
130
+ ancestor_name = ancestor.to_s
131
+ next unless ancestor_name.start_with?('Quality::Tools::')
132
+ ancestor_name.split('::').last.downcase
133
+ end.compact
108
134
  end
109
135
 
110
136
  def run_quality
@@ -166,100 +192,18 @@ module Quality
166
192
  quality_checker.execute(&count_violations_on_line)
167
193
  end
168
194
 
169
- def quality_cane
170
- unless @configuration_writer.exist?('.cane')
171
- @configuration_writer.open('.cane', 'w') do |file|
172
- file.write('-f **/*.rb')
173
- end
174
- end
175
- ratchet_quality_cmd('cane',
176
- gives_error_code_on_violations: true,
177
- emacs_format: true) do |line|
178
- if line =~ /\(([0-9]*)\):$/
179
- $1.to_i
180
- else
181
- 0
182
- end
183
- end
184
- end
185
-
186
195
  def ruby_dirs
187
196
  @ruby_dirs ||= %w(lib test spec feature)
188
197
  end
189
198
 
190
- def ruby_files
191
- @globber.glob('*.rb')
192
- .concat(@globber.glob(File.join("{#{ruby_dirs.join(',')}}",
193
- '**', '*.rb'))).join(' ')
194
- end
195
-
196
- def quality_reek
197
- args = "--single-line #{ruby_files}"
198
- ratchet_quality_cmd('reek',
199
- args: args,
200
- emacs_format: true,
201
- gives_error_code_on_violations: true) do |line|
202
- self.class.count_reek_violations(line)
203
- end
204
- end
205
-
206
- def self.count_reek_violations(line)
207
- if line =~ /^ .* (.*)$/
208
- 1
209
- else
210
- 0
211
- end
212
- end
213
-
214
- def quality_flog
215
- ratchet_quality_cmd('flog',
216
- args: "--all --continue --methods-only #{ruby_files}",
217
- emacs_format: true) do |line|
218
- self.class.count_violations_in_flog_output(line)
219
- end
220
- end
221
-
222
- def self.count_violations_in_flog_output(line, threshold = 50)
223
- if line =~ /^ *([0-9.]*): flog total$/
224
- 0
225
- elsif line =~ /^ *([0-9.]*): (.*) .*.rb:[0-9]*$/
226
- score = $1.to_i
227
- if score > threshold
228
- 1
229
- else
230
- 0
231
- end
232
- else
233
- 0
234
- end
199
+ def ruby_files_glob
200
+ File.join("{#{ruby_dirs.join(',')}}",
201
+ '**', '*.rb')
235
202
  end
236
203
 
237
- def quality_flay
238
- ratchet_quality_cmd('flay',
239
- args: "-m 75 -t 99999 #{ruby_files}",
240
- emacs_format: true) do |line|
241
- if line =~ /^[0-9]*\).* \(mass = ([0-9]*)\)$/
242
- $1.to_i
243
- else
244
- 0
245
- end
246
- end
247
- end
248
-
249
- def quality_rubocop
250
- ratchet_quality_cmd('rubocop',
251
- gives_error_code_on_violations: true,
252
- args: "--format emacs #{ruby_files}") do |line|
253
- self.class.count_rubocop_violations(line)
254
- end
255
- end
256
-
257
- def self.count_rubocop_violations(line)
258
- if line =~ /^.* file[s|] inspected, (.*) offence[s|] detected$/
259
- 0
260
- else
261
- 1
262
- end
204
+ def ruby_files
205
+ @globber.glob('*.rb')
206
+ .concat(@globber.glob(ruby_files_glob)).join(' ')
263
207
  end
264
208
  end
265
209
  end
@@ -0,0 +1,28 @@
1
+ module Quality
2
+ module Tools
3
+ # Adds 'cane' tool support to quality gem
4
+ module Cane
5
+ private
6
+
7
+ def write_out_dot_cane
8
+ @configuration_writer.open('.cane', 'w') do |file|
9
+ file.write("-f #{ruby_files_glob}")
10
+ end
11
+ end
12
+
13
+ def quality_cane
14
+ write_out_dot_cane unless @configuration_writer.exist?('.cane')
15
+
16
+ ratchet_quality_cmd('cane',
17
+ gives_error_code_on_violations: true,
18
+ emacs_format: true) do |line|
19
+ if line =~ /\(([0-9]*)\):$/
20
+ Regexp.last_match[1].to_i
21
+ else
22
+ 0
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,20 @@
1
+ module Quality
2
+ module Tools
3
+ # Adds 'flay' tool support to quality gem
4
+ module Flay
5
+ private
6
+
7
+ def quality_flay
8
+ ratchet_quality_cmd('flay',
9
+ args: "--mass 75 --timeout 99999 #{ruby_files}",
10
+ emacs_format: true) do |line|
11
+ if line =~ /^[0-9]*\).* \(mass = ([0-9]*)\)$/
12
+ Regexp.last_match[1].to_i
13
+ else
14
+ 0
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,34 @@
1
+ module Quality
2
+ module Tools
3
+ # Adds 'flog' tool support to quality gem
4
+ module Flog
5
+ private
6
+
7
+ def quality_flog
8
+ args = "--all --continue --methods-only #{ruby_files}"
9
+ ratchet_quality_cmd('flog', args: args, emacs_format: true) do |line|
10
+ self.class.count_violations_in_flog_output(line)
11
+ end
12
+ end
13
+
14
+ def self.included(base)
15
+ base.extend ClassMethods
16
+ end
17
+
18
+ # See Flog.included
19
+ module ClassMethods
20
+ def count_violations_in_flog_output(line, threshold = 50)
21
+ return 0 if line =~ /^ *([0-9.]*): flog total$/
22
+
23
+ return 0 unless line =~ /^ *([0-9.]*): (.*) .*.rb:[0-9]*$/
24
+
25
+ score = Regexp.last_match[1].to_i
26
+
27
+ return 1 if score > threshold
28
+
29
+ 0
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,33 @@
1
+ module Quality
2
+ module Tools
3
+ # Adds 'reek' tool support to quality gem
4
+ module Reek
5
+ private
6
+
7
+ def quality_reek
8
+ args = "--single-line #{ruby_files}"
9
+ ratchet_quality_cmd('reek',
10
+ args: args,
11
+ emacs_format: true,
12
+ gives_error_code_on_violations: true) do |line|
13
+ self.class.count_reek_violations(line)
14
+ end
15
+ end
16
+
17
+ def self.included(base)
18
+ base.extend ClassMethods
19
+ end
20
+
21
+ # See Reek.included
22
+ module ClassMethods
23
+ def count_reek_violations(line)
24
+ if line =~ /^ .* (.*)$/
25
+ 1
26
+ else
27
+ 0
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,31 @@
1
+ module Quality
2
+ module Tools
3
+ # Adds 'rubocop' tool support to quality gem
4
+ module Rubocop
5
+ private
6
+
7
+ def quality_rubocop
8
+ ratchet_quality_cmd('rubocop',
9
+ gives_error_code_on_violations: true,
10
+ args: "--format emacs #{ruby_files}") do |line|
11
+ self.class.count_rubocop_violations(line)
12
+ end
13
+ end
14
+
15
+ def self.included(base)
16
+ base.extend ClassMethods
17
+ end
18
+
19
+ # See Rubocop.included
20
+ module ClassMethods
21
+ def count_rubocop_violations(line)
22
+ if line =~ /^.* file[s|] inspected, (.*) offence[s|] detected$/
23
+ 0
24
+ else
25
+ 1
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,6 @@
1
+ # Quality is a tool that runs quality checks on Ruby code using cane,
2
+ # reek, flog, flay and rubocop and makes sure your numbers don't get
3
+ # any worse over time.
1
4
  module Quality
2
- VERSION = '1.3.0'
5
+ VERSION = '1.3.1'
3
6
  end
@@ -1,49 +1,49 @@
1
1
  # ; -*-Ruby-*-
2
2
  # -*- encoding: utf-8 -*-
3
- $:.push File.join(File.dirname(__FILE__), "lib")
3
+ $LOAD_PATH.push File.join(File.dirname(__FILE__), 'lib')
4
4
  require 'quality/version'
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{quality}
7
+ s.name = %q(quality)
8
8
  s.version = Quality::VERSION
9
9
 
10
10
  s.authors = ['Vince Broz']
11
- #s.default_executable = %q{quality}
12
- s.description = %q{Quality is a tool that runs quality checks on Ruby
11
+ # s.default_executable = %q{quality}
12
+ s.description = %q(Quality is a tool that runs quality checks on Ruby
13
13
  code using rubocop, cane, reek, flog and flay, and makes sure
14
14
  your numbers don't get any worse over time.
15
- }
16
- s.email = ["vince@broz.cc"]
17
- #s.executables = ["quality"]
18
- #s.extra_rdoc_files = ["CHANGELOG", "License.txt"]
19
- s.files = Dir["License.txt", "README.md",
20
- "Rakefile",
21
- #"bin/quality",
22
- "{lib}/**/*",
23
- "quality.gemspec" ] & `git ls-files -z`.split("\0")
24
- #s.rdoc_options = ["--main", "README.md"]
25
- s.require_paths = ["lib"]
26
- s.homepage = %q{http://github.com/apiology/quality}
27
- #s.rubyforge_project = %q{quality}
28
- s.rubygems_version = %q{1.3.6}
29
- s.summary = %q{Code quality tools for Ruby}
30
15
 
31
- s.add_runtime_dependency(%q<cane>, [">= 2.6"])
32
- s.add_runtime_dependency(%q<reek>, [">= 1.3.4"])
33
- s.add_runtime_dependency(%q<flog>, [">= 4.1.1"])
34
- s.add_runtime_dependency(%q<flay>, [">= 2.4"])
35
- s.add_runtime_dependency(%q<rubocop>)
16
+ )
17
+ s.email = ['vince@broz.cc']
18
+ # s.executables = ["quality"]
19
+ # s.extra_rdoc_files = ["CHANGELOG", "License.txt"]
20
+ s.license = 'MIT'
21
+ s.files = Dir['License.txt', 'README.md',
22
+ 'Rakefile',
23
+ # "bin/quality",
24
+ '{lib}/**/*',
25
+ 'quality.gemspec'] & `git ls-files -z`.split("\0")
26
+ # s.rdoc_options = ["--main", "README.md"]
27
+ s.require_paths = ['lib']
28
+ s.homepage = %q(http://github.com/apiology/quality)
29
+ # s.rubyforge_project = %q{quality}
30
+ s.rubygems_version = %q(1.3.6)
31
+ s.summary = %q(Code quality tools for Ruby)
32
+
33
+ s.add_runtime_dependency(%q(cane), ['>= 2.6'])
34
+ s.add_runtime_dependency(%q(reek), ['>= 1.3.4'])
35
+ s.add_runtime_dependency(%q(flog), ['>= 4.1.1'])
36
+ s.add_runtime_dependency(%q(flay), ['>= 2.4'])
37
+ s.add_runtime_dependency(%q(rubocop))
36
38
 
37
39
  # need above this version to support Ruby 2.0 syntax
38
- s.add_runtime_dependency(%q<ruby_parser>, [">= 3.2.2"])
40
+ s.add_runtime_dependency(%q(ruby_parser), ['>= 3.2.2'])
39
41
 
40
42
  # cane has an unadvertised dependency on json
41
- s.add_runtime_dependency(%q<json>)
43
+ s.add_runtime_dependency(%q(json))
42
44
 
43
- s.add_development_dependency(%q<bundler>, [">= 1.1"])
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
+ s.add_development_dependency(%q(bundler), ['>= 1.1'])
46
+ s.add_development_dependency(%q(rake))
47
+ s.add_development_dependency(%q(simplecov))
48
+ s.add_development_dependency(%q(mocha))
49
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: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vince Broz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-03 00:00:00.000000000 Z
11
+ date: 2014-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cane
@@ -164,24 +164,11 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
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'
181
- description: |
167
+ description: |+
182
168
  Quality is a tool that runs quality checks on Ruby
183
169
  code using rubocop, cane, reek, flog and flay, and makes sure
184
170
  your numbers don't get any worse over time.
171
+
185
172
  email:
186
173
  - vince@broz.cc
187
174
  executables: []
@@ -194,10 +181,16 @@ files:
194
181
  - lib/quality/command_output_processor.rb
195
182
  - lib/quality/quality_checker.rb
196
183
  - lib/quality/rake/task.rb
184
+ - lib/quality/tools/cane.rb
185
+ - lib/quality/tools/flay.rb
186
+ - lib/quality/tools/flog.rb
187
+ - lib/quality/tools/reek.rb
188
+ - lib/quality/tools/rubocop.rb
197
189
  - lib/quality/version.rb
198
190
  - quality.gemspec
199
191
  homepage: http://github.com/apiology/quality
200
- licenses: []
192
+ licenses:
193
+ - MIT
201
194
  metadata: {}
202
195
  post_install_message:
203
196
  rdoc_options: []