quality 27.3.1 → 27.4.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: bfcd41bd56230180baf3c53dd928594ca894ecf3
4
- data.tar.gz: 0b265177f4aa7ad0b47c17f384744bc3908d327c
3
+ metadata.gz: 9e7d5c912404289b0414f2f8efa3f28374e1c698
4
+ data.tar.gz: e26e1eed73d85f7895ba3110e60474053dcd02df
5
5
  SHA512:
6
- metadata.gz: 0490189adadc58f5a161e829344967fc4145b5bc7b3f9c107f37663c704cafaa7755b96820659544b311a9546cc9fadbaecd71b0bd95700a0c5857a5829837f2
7
- data.tar.gz: 318f1dabb9fea7ae89963dd526f090bb8e5106380554464f701424d7a0625f560799f42e651819b5e9ba4dd6683c2e572876190926ca6b61dea0f3f3f0d5e51f
6
+ metadata.gz: 44634291db8c0f7b5803a204aef4839c1c495da354f01b3acc9118861d3a5de2f4f02995330e794fe078a7c1d2c9ded10e791e76bed747d88d8aaf7079584558
7
+ data.tar.gz: d76c732f3b3eddd05abccb43c28b726ed9d084fbbd2e6415adc7fa9c8bf8bce69b30248901c7b6466854ca695fd360b05bf7a505171609a77321af2f6b19fda5
data/README.md CHANGED
@@ -102,6 +102,13 @@ Quality::Rake::Task.new do |t|
102
102
  # Defaults to :ratchet.
103
103
  t.ratchet_name = 'ratchet'
104
104
 
105
+ #
106
+ # Set minimum values to ratchet to.
107
+ #
108
+ # Defaults to { bigfiles: 300 }
109
+ #
110
+ t.minimum_threshold = { bigfiles: 300 }
111
+
105
112
  # Array of strings describing tools to be skipped--e.g., ["cane"]
106
113
  #
107
114
  # Defaults to []
@@ -28,20 +28,22 @@ module Quality
28
28
  out
29
29
  end
30
30
 
31
+ def processed_output
32
+ if emacs_format
33
+ preprocess_line_for_emacs
34
+ else
35
+ @current_line
36
+ end
37
+ end
38
+
31
39
  def process_line(&block)
32
- output =
33
- if emacs_format
34
- preprocess_line_for_emacs
35
- else
36
- @current_line
37
- end
38
40
  @found_output = true
39
41
  @violations += if block
40
42
  yield @current_line
41
43
  else
42
44
  1
43
45
  end
44
- output
46
+ processed_output
45
47
  end
46
48
 
47
49
  def preprocess_line_for_emacs
@@ -12,7 +12,7 @@ module Quality
12
12
  :output_dir, :punchlist_regexp,
13
13
  :scalastyle_config, :scalastyle_exclude
14
14
 
15
- attr_writer :source_files_exclude_glob
15
+ attr_writer :source_files_exclude_glob, :minimum_threshold
16
16
 
17
17
  extend Forwardable
18
18
 
@@ -48,6 +48,10 @@ module Quality
48
48
  @dir.glob("#{output_dir}/*_high_water_mark")
49
49
  end
50
50
 
51
+ def minimum_threshold
52
+ @minimum_threshold ||= { bigfiles: 300 }
53
+ end
54
+
51
55
  def initialize(quality_name: 'quality',
52
56
  ratchet_name: 'ratchet',
53
57
  source_file_globber: Quality::LinguistSourceFileGlobber.new,
@@ -9,15 +9,19 @@ module Quality
9
9
  # if possible, or outputs data if the number of violations increased.
10
10
  class QualityChecker
11
11
  def initialize(cmd, command_options, output_dir, verbose,
12
+ minimum_threshold,
13
+ logger: STDOUT,
12
14
  count_file: File,
13
15
  count_io: IO,
14
16
  command_output_processor_class:
15
17
  Quality::CommandOutputProcessor,
16
18
  count_dir: Dir,
17
19
  process_class: Process)
20
+ @minimum_threshold = minimum_threshold
18
21
  @count_file = count_file
19
22
  @count_io = count_io
20
23
  @command_output_processor_class = command_output_processor_class
24
+ @logger = logger
21
25
  @count_dir = count_dir
22
26
  @cmd = cmd
23
27
  @command_options = command_options
@@ -60,30 +64,51 @@ module Quality
60
64
  "Exit status is #{exit_status}") if exit_status.nonzero?
61
65
  end
62
66
 
67
+ MAX_VIOLATIONS = 9_999_999_999
68
+
63
69
  def existing_violations
64
- if @count_file.exist?(@filename)
65
- @count_io.read(@filename).to_i
66
- else
67
- 9_999_999_999
70
+ @existing_violations ||=
71
+ begin
72
+ if @count_file.exist?(@filename)
73
+ @count_io.read(@filename).to_i
74
+ else
75
+ MAX_VIOLATIONS
76
+ end
77
+ end
78
+ end
79
+
80
+ def error_too_many_violations!
81
+ raise("Output from #{@cmd}\n\n#{@command_output}\n\n" \
82
+ "Reduce total number of #{@cmd} violations " \
83
+ "to #{existing_violations} or below!")
84
+ end
85
+
86
+ def violations_to_write
87
+ @violations_to_write ||= [@violations, @minimum_threshold].max
88
+ end
89
+
90
+ def report_ratchet
91
+ if @violations < existing_violations &&
92
+ existing_violations != MAX_VIOLATIONS
93
+ @logger.puts 'Ratcheting quality up...'
68
94
  end
69
95
  end
70
96
 
71
97
  def ratchet_violations
72
- existing = existing_violations
73
- report_violations(existing)
74
- if @violations > existing
75
- raise("Output from #{@cmd}\n\n#{@command_output}\n\n" \
76
- "Reduce total number of #{@cmd} violations " \
77
- "to #{existing} or below!")
78
- elsif @violations < existing
79
- puts 'Ratcheting quality up...'
80
- write_violations(@violations)
98
+ report_violations(existing_violations)
99
+ if @violations > [existing_violations, @minimum_threshold].max
100
+ error_too_many_violations!
101
+ elsif violations_to_write != existing_violations
102
+ report_ratchet
103
+ write_violations(violations_to_write)
81
104
  end
82
105
  end
83
106
 
84
107
  def report_violations(existing)
85
- puts "Existing violations: #{existing}"
86
- puts "Found #{@violations} #{@cmd} violations"
108
+ if existing != MAX_VIOLATIONS
109
+ @logger.puts "Existing violations: #{existing}"
110
+ end
111
+ @logger.puts "Found #{@violations} #{@cmd} violations"
87
112
  end
88
113
 
89
114
  def full_cmd
@@ -22,13 +22,10 @@ module Quality
22
22
 
23
23
  extend ::Forwardable
24
24
 
25
- def initialize(config,
26
- gem_spec: Gem::Specification,
25
+ def initialize(config, gem_spec: Gem::Specification,
27
26
  quality_checker_class: Quality::QualityChecker,
28
- count_io: IO,
29
- count_file: File,
30
- globber: Dir,
31
- which: Which.new)
27
+ count_io: IO, count_file: File,
28
+ globber: Dir, which: Which.new)
32
29
  @config = config
33
30
  @gem_spec = gem_spec
34
31
  @quality_checker_class = quality_checker_class
@@ -96,13 +93,18 @@ module Quality
96
93
  end.compact
97
94
  end
98
95
 
96
+ def minimum_threshold_for(cmd)
97
+ @config.minimum_threshold[cmd.to_sym] || 0
98
+ end
99
+
99
100
  def ratchet_quality_cmd(cmd,
100
101
  command_options,
101
102
  &count_violations_on_line)
102
103
  quality_checker = @quality_checker_class.new(cmd,
103
104
  command_options,
104
105
  @config.output_dir,
105
- @config.verbose)
106
+ @config.verbose,
107
+ minimum_threshold_for(cmd))
106
108
  quality_checker.execute(&count_violations_on_line)
107
109
  end
108
110
 
@@ -4,5 +4,5 @@
4
4
  # reek, flog, flay and rubocop and makes sure your numbers don't get
5
5
  # any worse over time.
6
6
  module Quality
7
- VERSION = '27.3.1'
7
+ VERSION = '27.4.0'.freeze
8
8
  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: 27.3.1
4
+ version: 27.4.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: 2017-02-05 00:00:00.000000000 Z
11
+ date: 2017-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -376,7 +376,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
376
376
  version: '0'
377
377
  requirements: []
378
378
  rubyforge_project:
379
- rubygems_version: 2.4.8
379
+ rubygems_version: 2.6.12
380
380
  signing_key:
381
381
  specification_version: 4
382
382
  summary: Code quality tools for Ruby