quality 3.1.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dff4cb6cb0b90287a909c4bcaacb3ab65bfccee9
4
- data.tar.gz: c8e5409dfb6c3dbdbcac2e5ed0f9514db2b8e9fe
3
+ metadata.gz: 2f2ac78c5cf2ce1a7ffa14ae0620ee589e46ea5d
4
+ data.tar.gz: 77dbfa0aa0fcb5f7dc6e44bc59dc6b102942fb00
5
5
  SHA512:
6
- metadata.gz: 840c0c18e0266ed65a2ad45a69368e7ff436d7b9d02774e0a2a3dcd835272c54ccd1f02d72736e0b4faf3a635378a75e5d0d4b5bc917310d32864a6b572df228
7
- data.tar.gz: 9537a85f64c028a6adac27cc84525a5eeb1281232e323c8692ab48d31b1033dc46c99c8547c174921d78cc2d08ecbf6c837bbb5a467e17d51bd3b7a620a7ebd5
6
+ metadata.gz: b7a48e534105dfc33ac3f9eaad04ba799930d608c1e9850b469abf06f0d1f321f30f2594d21e318d09c40ca9970d989c50d6b65e58065831c0963b5f4f372a22
7
+ data.tar.gz: 95d993d5dc101127934b8aa407d765cdc8dcb133d2db0943a978f7e64ea18a651324efc94557ba546b5957c24e7fc156efe54cd60c9176b58c863b74ac5adc79
data/README.md CHANGED
@@ -72,8 +72,13 @@ Quality::Rake::Task.new { |t|
72
72
 
73
73
  # Array of directory names which contain ruby files to analyze.
74
74
  #
75
- # Defaults to %w{app lib test spec feature}, which translates to *.rb in the base directory, as well as those directories.
76
- t.ruby_dirs = %w{app lib test spec feature}
75
+ # Defaults to %w(app lib test spec feature), which translates to *.rb in the base directory, as well as those directories.
76
+ t.ruby_dirs = %w(app lib test spec feature)
77
+
78
+ # Array of directory names which contain any type of source files to analyze.
79
+ #
80
+ # Defaults to t.ruby_dirs
81
+ t.source_dirs.concat(%w(MyProject MyProjectTests))
77
82
 
78
83
  # Relative path to output directory where *_high_water_mark
79
84
  # files will be read/written
@@ -3,13 +3,8 @@
3
3
  require 'rake'
4
4
  require 'rake/tasklib'
5
5
  require 'rbconfig'
6
+ require_relative '../runner'
6
7
  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'
12
- require_relative '../tools/bigfiles'
13
8
 
14
9
  module Quality
15
10
  #
@@ -30,13 +25,6 @@ module Quality
30
25
  #
31
26
  # rake quality
32
27
  class Task < ::Rake::TaskLib
33
- include Tools::Cane
34
- include Tools::Flay
35
- include Tools::Flog
36
- include Tools::Reek
37
- include Tools::Rubocop
38
- include Tools::BigFiles
39
-
40
28
  # Name of quality task.
41
29
  # Defaults to :quality.
42
30
  attr_accessor :quality_name
@@ -61,11 +49,17 @@ module Quality
61
49
  # the base directory, as well as those directories.
62
50
  attr_writer :ruby_dirs
63
51
 
52
+ # Array of directory names which contain any type of source
53
+ # files to analyze.
54
+ #
55
+ # Defaults to the same as ruby_dirs
56
+ attr_writer :source_dirs
57
+
64
58
  # Relative path to output directory where *_high_water_mark
65
59
  # files will be read/written
66
60
  #
67
61
  # Defaults to .
68
- attr_writer :output_dir
62
+ attr_accessor :output_dir
69
63
 
70
64
  # Defines a new task, using the name +name+.
71
65
  def initialize(dsl: ::Rake::Task,
@@ -79,10 +73,8 @@ module Quality
79
73
  Quality::QualityChecker,
80
74
  quality_name: 'quality',
81
75
  ratchet_name: 'ratchet')
82
- @dsl, @cmd_runner, @count_file = dsl, cmd_runner, count_file
83
- @count_io, @globber, @gem_spec = count_io, globber, gem_spec
84
- @configuration_writer = configuration_writer
85
- @quality_checker_class = quality_checker_class
76
+ @dsl, @cmd_runner = dsl, cmd_runner
77
+ @globber = globber
86
78
  @quality_name, @ratchet_name = quality_name, ratchet_name
87
79
 
88
80
  @skip_tools = []
@@ -93,87 +85,29 @@ module Quality
93
85
 
94
86
  yield self if block_given?
95
87
 
88
+ @runner = Quality::Runner.new(self,
89
+ gem_spec: gem_spec,
90
+ quality_checker_class:
91
+ quality_checker_class,
92
+ count_io: count_io,
93
+ count_file: count_file,
94
+ configuration_writer:
95
+ configuration_writer)
96
96
  define
97
97
  end
98
98
 
99
- private
100
-
101
- def define # :nodoc:
102
- desc 'Verify quality has increased or stayed ' \
103
- 'the same' unless ::Rake.application.last_comment
104
- @dsl.define_task(quality_name) { run_quality }
105
- @dsl.define_task(ratchet_name) { run_ratchet }
106
- tools.each do |tool|
107
- @dsl.define_task(tool) { run_quality_with_tool(tool) }
108
- end
109
- end
110
-
111
- def tools
112
- self.class.ancestors.map do |ancestor|
113
- ancestor_name = ancestor.to_s
114
- next unless ancestor_name.start_with?('Quality::Tools::')
115
- ancestor_name.split('::').last.downcase
116
- end.compact
117
- end
118
-
119
- def run_quality
120
- tools.each do |tool|
121
- run_quality_with_tool(tool)
122
- end
123
- end
124
-
125
- def run_quality_with_tool(tool)
126
- installed = @gem_spec.find_all_by_name(tool).any?
127
- suppressed = @skip_tools.include? tool
128
-
129
- if installed && !suppressed
130
- method("quality_#{tool}".to_sym).call
131
- elsif !installed
132
- puts "#{tool} not installed"
133
- end
134
- end
135
-
136
- def run_ratchet
137
- @globber.glob("#{@output_dir}/*_high_water_mark").each do |filename|
138
- run_ratchet_on_file(filename)
139
- end
140
- end
141
-
142
- def run_ratchet_on_file(filename)
143
- puts "Processing #{filename}"
144
- existing_violations = count_existing_violations(filename)
145
- new_violations = [0, existing_violations - 1].max
146
- write_violations(filename, new_violations)
147
- end
148
-
149
- def write_violations(filename, new_violations)
150
- @count_file.open(filename, 'w') do |file|
151
- file.write(new_violations.to_s + "\n")
152
- end
153
- end
154
-
155
- def count_existing_violations(filename)
156
- existing_violations = @count_io.read(filename).to_i
157
- fail("Problem with file #{filename}") if existing_violations < 0
158
- existing_violations
159
- end
160
-
161
- def ratchet_quality_cmd(cmd,
162
- command_options,
163
- &count_violations_on_line)
164
- quality_checker = @quality_checker_class.new(cmd,
165
- command_options,
166
- @output_dir,
167
- verbose)
168
- quality_checker.execute(&count_violations_on_line)
169
- end
99
+ attr_reader :globber
170
100
 
171
101
  def ruby_dirs
172
102
  @ruby_dirs ||= %w(app lib test spec feature)
173
103
  end
174
104
 
105
+ def source_dirs
106
+ @source_dirs ||= ruby_dirs.clone
107
+ end
108
+
175
109
  def source_files_glob(extensions = 'rb,swift,cpp,c,java,py')
176
- File.join("{#{ruby_dirs.join(',')}}",
110
+ File.join("{#{source_dirs.join(',')}}",
177
111
  '**', "*.{#{extensions}}")
178
112
  end
179
113
 
@@ -182,9 +116,21 @@ module Quality
182
116
  end
183
117
 
184
118
  def ruby_files
185
- @globber.glob('*.rb')
119
+ @globber.glob('{*.rb,Rakefile}')
186
120
  .concat(@globber.glob(ruby_files_glob)).join(' ')
187
121
  end
122
+
123
+ private
124
+
125
+ def define # :nodoc:
126
+ desc 'Verify quality has increased or stayed ' \
127
+ 'the same' unless ::Rake.application.last_comment
128
+ @dsl.define_task(quality_name) { @runner.run_quality }
129
+ @dsl.define_task(ratchet_name) { @runner.run_ratchet }
130
+ @runner.tools.each do |tool|
131
+ @dsl.define_task(tool) { @runner.run_quality_with_tool(tool) }
132
+ end
133
+ end
188
134
  end
189
135
  end
190
136
  end
@@ -0,0 +1,105 @@
1
+ require_relative 'tools/cane'
2
+ require_relative 'tools/flay'
3
+ require_relative 'tools/flog'
4
+ require_relative 'tools/reek'
5
+ require_relative 'tools/rubocop'
6
+ require_relative 'tools/bigfiles'
7
+
8
+ module Quality
9
+ class Runner
10
+ include Tools::Cane
11
+ include Tools::Flay
12
+ include Tools::Flog
13
+ include Tools::Reek
14
+ include Tools::Rubocop
15
+ include Tools::BigFiles
16
+
17
+ def initialize(config,
18
+ gem_spec: Gem::Specification,
19
+ quality_checker_class: Quality::QualityChecker,
20
+ count_io: IO,
21
+ count_file: File,
22
+ configuration_writer: File)
23
+ @config = config
24
+ @gem_spec = gem_spec
25
+ @quality_checker_class = quality_checker_class
26
+ @count_io = count_io
27
+ @count_file = count_file
28
+ @configuration_writer = configuration_writer
29
+ end
30
+
31
+ def run_quality
32
+ tools.each { |tool| run_quality_with_tool(tool) }
33
+ end
34
+
35
+ def run_quality_with_tool(tool)
36
+ installed = @gem_spec.find_all_by_name(tool).any?
37
+ suppressed = @config.skip_tools.include? tool
38
+
39
+ if installed && !suppressed
40
+ method("quality_#{tool}".to_sym).call
41
+ elsif !installed
42
+ puts "#{tool} not installed"
43
+ end
44
+ end
45
+
46
+ def globber
47
+ @config.globber
48
+ end
49
+
50
+ def run_ratchet
51
+ globber.glob("#{@config.output_dir}/*_high_water_mark").each do |filename|
52
+ run_ratchet_on_file(filename)
53
+ end
54
+ end
55
+
56
+ def run_ratchet_on_file(filename)
57
+ puts "Processing #{filename}"
58
+ existing_violations = count_existing_violations(filename)
59
+ new_violations = [0, existing_violations - 1].max
60
+ write_violations(filename, new_violations)
61
+ end
62
+
63
+ def write_violations(filename, new_violations)
64
+ @count_file.open(filename, 'w') do |file|
65
+ file.write(new_violations.to_s + "\n")
66
+ end
67
+ end
68
+
69
+ def count_existing_violations(filename)
70
+ existing_violations = @count_io.read(filename).to_i
71
+ fail("Problem with file #{filename}") if existing_violations < 0
72
+ existing_violations
73
+ end
74
+
75
+ def tools
76
+ self.class.ancestors.map do |ancestor|
77
+ ancestor_name = ancestor.to_s
78
+ next unless ancestor_name.start_with?('Quality::Tools::')
79
+ ancestor_name.split('::').last.downcase
80
+ end.compact
81
+ end
82
+
83
+ def ratchet_quality_cmd(cmd,
84
+ command_options,
85
+ &count_violations_on_line)
86
+ quality_checker = @quality_checker_class.new(cmd,
87
+ command_options,
88
+ @config.output_dir,
89
+ @config.verbose)
90
+ quality_checker.execute(&count_violations_on_line)
91
+ end
92
+
93
+ def ruby_files
94
+ @config.ruby_files
95
+ end
96
+
97
+ def ruby_files_glob
98
+ @config.ruby_files_glob
99
+ end
100
+
101
+ def source_files_glob
102
+ @config.source_files_glob
103
+ end
104
+ end
105
+ end
@@ -2,5 +2,5 @@
2
2
  # reek, flog, flay and rubocop and makes sure your numbers don't get
3
3
  # any worse over time.
4
4
  module Quality
5
- VERSION = '3.1.0'
5
+ VERSION = '4.0.0'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quality
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vince Broz
@@ -202,6 +202,7 @@ files:
202
202
  - lib/quality/process_runner.rb
203
203
  - lib/quality/quality_checker.rb
204
204
  - lib/quality/rake/task.rb
205
+ - lib/quality/runner.rb
205
206
  - lib/quality/tools/bigfiles.rb
206
207
  - lib/quality/tools/cane.rb
207
208
  - lib/quality/tools/flay.rb