metric_fu 4.11.3 → 4.11.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.rubocop.yml +15 -0
- data/.rubocop_todo.yml +69 -0
- data/.travis.yml +0 -1
- data/CONTRIBUTORS +1 -1
- data/Gemfile +23 -20
- data/Guardfile +9 -9
- data/HISTORY.md +10 -1
- data/checksum/metric_fu-4.11.3.gem.sha512 +1 -0
- data/config/rubocop.yml +269 -0
- data/gem_tasks/rubocop.rake +10 -0
- data/lib/metric_fu.rb +11 -9
- data/lib/metric_fu/calculate.rb +0 -1
- data/lib/metric_fu/cli/client.rb +6 -6
- data/lib/metric_fu/cli/helper.rb +22 -13
- data/lib/metric_fu/cli/parser.rb +14 -18
- data/lib/metric_fu/configuration.rb +7 -11
- data/lib/metric_fu/constantize.rb +4 -4
- data/lib/metric_fu/data_structures/line_numbers.rb +10 -11
- data/lib/metric_fu/data_structures/location.rb +12 -14
- data/lib/metric_fu/data_structures/sexp_node.rb +31 -13
- data/lib/metric_fu/environment.rb +29 -31
- data/lib/metric_fu/formatter.rb +4 -6
- data/lib/metric_fu/formatter/html.rb +13 -13
- data/lib/metric_fu/formatter/syntax.rb +5 -7
- data/lib/metric_fu/formatter/yaml.rb +1 -1
- data/lib/metric_fu/gem_run.rb +13 -15
- data/lib/metric_fu/gem_version.rb +9 -11
- data/lib/metric_fu/generator.rb +5 -8
- data/lib/metric_fu/io.rb +13 -15
- data/lib/metric_fu/loader.rb +17 -18
- data/lib/metric_fu/logger.rb +15 -18
- data/lib/metric_fu/logging/mf_debugger.rb +4 -4
- data/lib/metric_fu/metric.rb +11 -12
- data/lib/metric_fu/metrics/cane/generator.rb +10 -9
- data/lib/metric_fu/metrics/cane/grapher.rb +5 -7
- data/lib/metric_fu/metrics/cane/metric.rb +6 -8
- data/lib/metric_fu/metrics/cane/report.html.erb +3 -3
- data/lib/metric_fu/metrics/cane/violations.rb +6 -6
- data/lib/metric_fu/metrics/churn/generator.rb +2 -6
- data/lib/metric_fu/metrics/churn/hotspot.rb +1 -3
- data/lib/metric_fu/metrics/churn/metric.rb +5 -7
- data/lib/metric_fu/metrics/flay/generator.rb +7 -11
- data/lib/metric_fu/metrics/flay/grapher.rb +5 -6
- data/lib/metric_fu/metrics/flay/hotspot.rb +5 -7
- data/lib/metric_fu/metrics/flay/metric.rb +5 -7
- data/lib/metric_fu/metrics/flog/generator.rb +22 -23
- data/lib/metric_fu/metrics/flog/grapher.rb +11 -11
- data/lib/metric_fu/metrics/flog/hotspot.rb +3 -5
- data/lib/metric_fu/metrics/flog/metric.rb +3 -5
- data/lib/metric_fu/metrics/hotspots/analysis/analyzed_problems.rb +0 -1
- data/lib/metric_fu/metrics/hotspots/analysis/analyzer_tables.rb +19 -18
- data/lib/metric_fu/metrics/hotspots/analysis/grouping.rb +0 -2
- data/lib/metric_fu/metrics/hotspots/analysis/groupings.rb +1 -3
- data/lib/metric_fu/metrics/hotspots/analysis/problems.rb +4 -6
- data/lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb +14 -9
- data/lib/metric_fu/metrics/hotspots/analysis/ranking.rb +4 -5
- data/lib/metric_fu/metrics/hotspots/analysis/rankings.rb +1 -3
- data/lib/metric_fu/metrics/hotspots/analysis/record.rb +3 -5
- data/lib/metric_fu/metrics/hotspots/analysis/scoring_strategies.rb +0 -2
- data/lib/metric_fu/metrics/hotspots/analysis/table.rb +3 -4
- data/lib/metric_fu/metrics/hotspots/generator.rb +3 -6
- data/lib/metric_fu/metrics/hotspots/hotspot.rb +13 -13
- data/lib/metric_fu/metrics/hotspots/hotspot_analyzer.rb +5 -8
- data/lib/metric_fu/metrics/hotspots/metric.rb +1 -3
- data/lib/metric_fu/metrics/hotspots/report.html.erb +1 -1
- data/lib/metric_fu/metrics/rails_best_practices/generator.rb +10 -12
- data/lib/metric_fu/metrics/rails_best_practices/grapher.rb +5 -6
- data/lib/metric_fu/metrics/rails_best_practices/metric.rb +1 -3
- data/lib/metric_fu/metrics/rcov/external_client.rb +1 -3
- data/lib/metric_fu/metrics/rcov/generator.rb +13 -15
- data/lib/metric_fu/metrics/rcov/grapher.rb +6 -7
- data/lib/metric_fu/metrics/rcov/hotspot.rb +5 -7
- data/lib/metric_fu/metrics/rcov/metric.rb +5 -7
- data/lib/metric_fu/metrics/rcov/rcov_format_coverage.rb +16 -55
- data/lib/metric_fu/metrics/rcov/rcov_line.rb +48 -0
- data/lib/metric_fu/metrics/rcov/report.html.erb +2 -2
- data/lib/metric_fu/metrics/rcov/simplecov_formatter.rb +10 -11
- data/lib/metric_fu/metrics/reek/generator.rb +22 -23
- data/lib/metric_fu/metrics/reek/grapher.rb +5 -6
- data/lib/metric_fu/metrics/reek/hotspot.rb +5 -7
- data/lib/metric_fu/metrics/reek/metric.rb +2 -4
- data/lib/metric_fu/metrics/roodi/generator.rb +9 -10
- data/lib/metric_fu/metrics/roodi/grapher.rb +5 -6
- data/lib/metric_fu/metrics/roodi/hotspot.rb +1 -3
- data/lib/metric_fu/metrics/roodi/metric.rb +2 -4
- data/lib/metric_fu/metrics/saikuro/generator.rb +23 -27
- data/lib/metric_fu/metrics/saikuro/hotspot.rb +1 -3
- data/lib/metric_fu/metrics/saikuro/metric.rb +7 -8
- data/lib/metric_fu/metrics/saikuro/parsing_element.rb +6 -8
- data/lib/metric_fu/metrics/saikuro/report.html.erb +1 -1
- data/lib/metric_fu/metrics/saikuro/scratch_file.rb +24 -29
- data/lib/metric_fu/metrics/stats/generator.rb +9 -12
- data/lib/metric_fu/metrics/stats/grapher.rb +8 -9
- data/lib/metric_fu/metrics/stats/hotspot.rb +1 -3
- data/lib/metric_fu/metrics/stats/metric.rb +3 -5
- data/lib/metric_fu/reporter.rb +1 -1
- data/lib/metric_fu/reporting/graphs/graph.rb +8 -12
- data/lib/metric_fu/reporting/graphs/grapher.rb +7 -9
- data/lib/metric_fu/reporting/result.rb +0 -3
- data/lib/metric_fu/run.rb +12 -3
- data/lib/metric_fu/tasks/metric_fu.rake +8 -8
- data/lib/metric_fu/templates/configuration.rb +2 -5
- data/lib/metric_fu/templates/metrics_template.rb +19 -19
- data/lib/metric_fu/templates/report.rb +5 -8
- data/lib/metric_fu/templates/template.rb +20 -24
- data/lib/metric_fu/utility.rb +7 -8
- data/lib/metric_fu/version.rb +1 -1
- data/metric_fu.gemspec +31 -32
- data/spec/cli/helper_spec.rb +7 -14
- data/spec/dummy/lib/bad_encoding.rb +1 -1
- data/spec/fixtures/coverage-153.rb +2 -2
- data/spec/fixtures/coverage.rb +2 -2
- data/spec/metric_fu/calculate_spec.rb +3 -3
- data/spec/metric_fu/configuration_spec.rb +70 -82
- data/spec/metric_fu/data_structures/line_numbers_spec.rb +3 -5
- data/spec/metric_fu/data_structures/location_spec.rb +13 -31
- data/spec/metric_fu/formatter/configuration_spec.rb +11 -13
- data/spec/metric_fu/formatter/html_spec.rb +21 -28
- data/spec/metric_fu/formatter/yaml_spec.rb +9 -17
- data/spec/metric_fu/formatter_spec.rb +6 -6
- data/spec/metric_fu/gem_version_spec.rb +3 -5
- data/spec/metric_fu/generator_spec.rb +28 -38
- data/spec/metric_fu/loader_spec.rb +1 -3
- data/spec/metric_fu/metric_spec.rb +17 -21
- data/spec/metric_fu/metrics/cane/configuration_spec.rb +8 -8
- data/spec/metric_fu/metrics/cane/generator_spec.rb +26 -29
- data/spec/metric_fu/metrics/churn/configuration_spec.rb +6 -8
- data/spec/metric_fu/metrics/churn/generator_spec.rb +6 -11
- data/spec/metric_fu/metrics/flay/configuration_spec.rb +6 -8
- data/spec/metric_fu/metrics/flay/generator_spec.rb +36 -37
- data/spec/metric_fu/metrics/flay/grapher_spec.rb +2 -2
- data/spec/metric_fu/metrics/flog/configuration_spec.rb +11 -13
- data/spec/metric_fu/metrics/flog/generator_spec.rb +29 -31
- data/spec/metric_fu/metrics/flog/grapher_spec.rb +8 -10
- data/spec/metric_fu/metrics/hotspots/analysis/analyzed_problems_spec.rb +18 -24
- data/spec/metric_fu/metrics/hotspots/analysis/analyzer_tables_spec.rb +12 -17
- data/spec/metric_fu/metrics/hotspots/analysis/ranking_spec.rb +2 -6
- data/spec/metric_fu/metrics/hotspots/analysis/rankings_spec.rb +5 -14
- data/spec/metric_fu/metrics/hotspots/analysis/table_spec.rb +1 -3
- data/spec/metric_fu/metrics/hotspots/generator_spec.rb +6 -8
- data/spec/metric_fu/metrics/hotspots/hotspot_analyzer_spec.rb +1 -3
- data/spec/metric_fu/metrics/hotspots/hotspot_spec.rb +4 -5
- data/spec/metric_fu/metrics/rails_best_practices/configuration_spec.rb +6 -10
- data/spec/metric_fu/metrics/rails_best_practices/generator_spec.rb +2 -3
- data/spec/metric_fu/metrics/rails_best_practices/grapher_spec.rb +3 -3
- data/spec/metric_fu/metrics/rcov/configuration_spec.rb +20 -22
- data/spec/metric_fu/metrics/rcov/generator_spec.rb +6 -10
- data/spec/metric_fu/metrics/rcov/grapher_spec.rb +2 -2
- data/spec/metric_fu/metrics/rcov/hotspot_spec.rb +8 -8
- data/spec/metric_fu/metrics/rcov/rcov_line_spec.rb +89 -0
- data/spec/metric_fu/metrics/rcov/simplecov_formatter_spec.rb +31 -33
- data/spec/metric_fu/metrics/reek/configuration_spec.rb +6 -6
- data/spec/metric_fu/metrics/reek/generator_spec.rb +19 -20
- data/spec/metric_fu/metrics/reek/grapher_spec.rb +4 -4
- data/spec/metric_fu/metrics/roodi/configuration_spec.rb +7 -9
- data/spec/metric_fu/metrics/roodi/generator_spec.rb +3 -3
- data/spec/metric_fu/metrics/roodi/grapher_spec.rb +2 -2
- data/spec/metric_fu/metrics/saikuro/configuration_spec.rb +18 -19
- data/spec/metric_fu/metrics/saikuro/generator_spec.rb +7 -7
- data/spec/metric_fu/metrics/stats/generator_spec.rb +9 -9
- data/spec/metric_fu/metrics/stats/grapher_spec.rb +2 -2
- data/spec/metric_fu/reporter_spec.rb +3 -4
- data/spec/metric_fu/reporting/graphs/graph_spec.rb +1 -4
- data/spec/metric_fu/reporting/graphs/grapher_spec.rb +5 -5
- data/spec/metric_fu/reporting/result_spec.rb +9 -11
- data/spec/metric_fu/run_spec.rb +18 -32
- data/spec/metric_fu/templates/configuration_spec.rb +28 -34
- data/spec/metric_fu/templates/metrics_template_spec.rb +11 -0
- data/spec/metric_fu/templates/report_spec.rb +4 -4
- data/spec/metric_fu/templates/template_spec.rb +62 -48
- data/spec/metric_fu/utility_spec.rb +2 -2
- data/spec/metric_fu_spec.rb +5 -7
- data/spec/shared/configured.rb +9 -11
- data/spec/shared/test_coverage.rb +5 -9
- data/spec/spec_helper.rb +9 -9
- data/spec/support/deferred_garbaged_collection.rb +1 -2
- data/spec/support/matcher_create_file.rb +2 -4
- data/spec/support/matcher_create_files.rb +2 -4
- data/spec/support/suite.rb +3 -3
- data/spec/support/test_fixtures.rb +5 -7
- data/spec/support/timeout.rb +1 -1
- data/spec/support/usage_test.rb +23 -24
- data/spec/usage_test_spec.rb +18 -20
- metadata +12 -2
- metadata.gz.sig +0 -0
@@ -7,41 +7,6 @@ module MetricFu
|
|
7
7
|
@rcov_text = rcov_text
|
8
8
|
end
|
9
9
|
|
10
|
-
class Line
|
11
|
-
attr_accessor :content, :was_run
|
12
|
-
|
13
|
-
def initialize(content, was_run)
|
14
|
-
@content = content
|
15
|
-
@was_run = was_run
|
16
|
-
end
|
17
|
-
|
18
|
-
def to_h
|
19
|
-
{:content => @content, :was_run => @was_run}
|
20
|
-
end
|
21
|
-
|
22
|
-
def covered?
|
23
|
-
@was_run.one?
|
24
|
-
end
|
25
|
-
def missed?
|
26
|
-
@was_run.zero?
|
27
|
-
end
|
28
|
-
def ignored?
|
29
|
-
@was_run.nil?
|
30
|
-
end
|
31
|
-
def self.line_coverage(lines)
|
32
|
-
lines.map{|line| line[:was_run] }
|
33
|
-
end
|
34
|
-
def self.covered_lines(line_coverage)
|
35
|
-
line_coverage.count(1)
|
36
|
-
end
|
37
|
-
def self.missed_lines(line_coverage)
|
38
|
-
line_coverage.count(0)
|
39
|
-
end
|
40
|
-
def self.ignored_lines(line_coverage)
|
41
|
-
line_coverage.count(nil)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
10
|
def to_h
|
46
11
|
rcov_text = @rcov_text.split(NEW_FILE_MARKER)
|
47
12
|
|
@@ -49,7 +14,6 @@ module MetricFu
|
|
49
14
|
|
50
15
|
files = assemble_files(rcov_text)
|
51
16
|
|
52
|
-
|
53
17
|
TestCoverage.new(files).to_h
|
54
18
|
end
|
55
19
|
|
@@ -57,21 +21,21 @@ module MetricFu
|
|
57
21
|
|
58
22
|
def assemble_files(rcov_text)
|
59
23
|
files = {}
|
60
|
-
rcov_text.each_slice(2) {|out| files[out.first.strip] = out.last}
|
61
|
-
files.each_pair {|fname, content| files[fname] = content.split("\n") }
|
24
|
+
rcov_text.each_slice(2) { |out| files[out.first.strip] = out.last }
|
25
|
+
files.each_pair { |fname, content| files[fname] = content.split("\n") }
|
62
26
|
files.each_pair do |fname, content|
|
63
27
|
content.map! do |raw_line|
|
64
|
-
covered_line = if raw_line.start_with?(
|
28
|
+
covered_line = if raw_line.start_with?("--")
|
65
29
|
nil # simplecov ignores some lines
|
66
|
-
elsif raw_line.start_with?(
|
30
|
+
elsif raw_line.start_with?("!!")
|
67
31
|
0
|
68
32
|
else
|
69
33
|
1
|
70
34
|
end
|
71
|
-
|
35
|
+
RCovLine.new(raw_line[3..-1], covered_line).to_h
|
72
36
|
end
|
73
|
-
content.reject! {|line| line[:content].to_s ==
|
74
|
-
files[fname] = {:
|
37
|
+
content.reject! { |line| line[:content].to_s == "" }
|
38
|
+
files[fname] = { lines: content }
|
75
39
|
end
|
76
40
|
files
|
77
41
|
end
|
@@ -101,9 +65,9 @@ module MetricFu
|
|
101
65
|
end
|
102
66
|
|
103
67
|
def self.percent_run(lines)
|
104
|
-
line_coverage =
|
105
|
-
covered_lines =
|
106
|
-
ignored_lines =
|
68
|
+
line_coverage = RCovLine.line_coverage(lines)
|
69
|
+
covered_lines = RCovLine.covered_lines(line_coverage)
|
70
|
+
ignored_lines = RCovLine.ignored_lines(line_coverage)
|
107
71
|
relevant_lines = lines.count - ignored_lines
|
108
72
|
if block_given?
|
109
73
|
yield covered_lines, relevant_lines
|
@@ -113,6 +77,7 @@ module MetricFu
|
|
113
77
|
end
|
114
78
|
|
115
79
|
private
|
80
|
+
|
116
81
|
# TODO: remove multiple side effects
|
117
82
|
# sets global ivars and
|
118
83
|
# modifies the param passed in
|
@@ -131,9 +96,9 @@ module MetricFu
|
|
131
96
|
|
132
97
|
def add_global_percent_run(test_coverage, total_lines, total_lines_run)
|
133
98
|
percentage = self.class.floating_percent(total_lines_run, total_lines)
|
134
|
-
test_coverage.update(
|
135
|
-
:
|
136
|
-
|
99
|
+
test_coverage.update(
|
100
|
+
global_percent_run: round_to_tenths(percentage)
|
101
|
+
)
|
137
102
|
end
|
138
103
|
|
139
104
|
def add_method_data(test_coverage)
|
@@ -141,7 +106,7 @@ module MetricFu
|
|
141
106
|
file_contents = ""
|
142
107
|
coverage = []
|
143
108
|
|
144
|
-
info[:lines].each_with_index do |line,
|
109
|
+
info[:lines].each_with_index do |line, _index|
|
145
110
|
file_contents << "#{line[:content]}\n"
|
146
111
|
coverage << line[:was_run]
|
147
112
|
end
|
@@ -172,17 +137,13 @@ module MetricFu
|
|
172
137
|
method_coverage_map.each do |method_name, coverage_data|
|
173
138
|
test_coverage[file_path][:methods][method_name] = (coverage_data[:uncovered] / coverage_data[:total].to_f) * 100.0
|
174
139
|
end
|
175
|
-
|
176
140
|
end
|
177
141
|
end
|
178
142
|
|
179
143
|
def round_to_tenths(decimal)
|
180
|
-
decimal = 0.0 if decimal.to_s.eql?(
|
144
|
+
decimal = 0.0 if decimal.to_s.eql?("NaN")
|
181
145
|
(decimal * 10).round / 10.0
|
182
146
|
end
|
183
|
-
|
184
|
-
|
185
147
|
end
|
186
|
-
|
187
148
|
end
|
188
149
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module MetricFu
|
2
|
+
class RCovLine
|
3
|
+
attr_accessor :content, :was_run
|
4
|
+
|
5
|
+
def initialize(content, was_run)
|
6
|
+
@content = content
|
7
|
+
@was_run = was_run
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_h
|
11
|
+
{ content: @content, was_run: @was_run }
|
12
|
+
end
|
13
|
+
|
14
|
+
def covered?
|
15
|
+
@was_run == 1
|
16
|
+
end
|
17
|
+
|
18
|
+
def missed?
|
19
|
+
@was_run == 0
|
20
|
+
end
|
21
|
+
|
22
|
+
def ignored?
|
23
|
+
@was_run.nil?
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.line_coverage(lines)
|
27
|
+
lines.map { |line| line[:was_run] }
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.covered_lines(line_coverage)
|
31
|
+
line_coverage.count(1)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.missed_lines(line_coverage)
|
35
|
+
line_coverage.count(0)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.ignored_lines(line_coverage)
|
39
|
+
line_coverage.count(nil)
|
40
|
+
end
|
41
|
+
|
42
|
+
def css_class
|
43
|
+
return "" if ignored?
|
44
|
+
|
45
|
+
missed? ? "rcov_not_run" : "rcov_run"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -29,8 +29,8 @@
|
|
29
29
|
<table class="rcov_code">
|
30
30
|
<% file[:lines].each_with_index do |line, index| %>
|
31
31
|
<tr>
|
32
|
-
<%
|
33
|
-
<td class="<%= css_class %>"><%= link_to_filename(fname, index + 1, "<pre>#{line[:content]}</pre>") %></td>
|
32
|
+
<% rcov_line = RCovLine.new(line[:content], line[:was_run]) %>
|
33
|
+
<td class="<%= rcov_line.css_class %>"><%= link_to_filename(fname, index + 1, "<pre>#{line[:content]}</pre>") %></td>
|
34
34
|
</tr>
|
35
35
|
<% end %>
|
36
36
|
</table>
|
@@ -7,12 +7,12 @@ if defined?(JRUBY_VERSION)
|
|
7
7
|
# https://github.com/colszowka/simplecov/issues/86
|
8
8
|
end
|
9
9
|
end
|
10
|
-
require
|
11
|
-
|
12
|
-
require_relative
|
10
|
+
require "simplecov"
|
11
|
+
require "metric_fu/logger"
|
12
|
+
require_relative "external_client"
|
13
|
+
require_relative "rcov_format_coverage"
|
13
14
|
|
14
15
|
class SimpleCov::Formatter::MetricFu
|
15
|
-
|
16
16
|
def format(result)
|
17
17
|
rcov_text = FormatLikeRCov.new(result).format
|
18
18
|
client = MetricFu::RCovTestCoverageClient.new(coverage_file_path)
|
@@ -26,7 +26,7 @@ class SimpleCov::Formatter::MetricFu
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def default_coverage_file_path
|
29
|
-
File.join(SimpleCov.root,
|
29
|
+
File.join(SimpleCov.root, "coverage", "rcov", output_file_name)
|
30
30
|
end
|
31
31
|
|
32
32
|
# TODO: Read in from legacy coverage/rcov/rcov.txt path, when set
|
@@ -40,7 +40,7 @@ class SimpleCov::Formatter::MetricFu
|
|
40
40
|
# going forward, the file name will be in a date-stamped
|
41
41
|
# format like for all other reported metrics.
|
42
42
|
def output_file_name
|
43
|
-
|
43
|
+
"rcov.txt"
|
44
44
|
end
|
45
45
|
|
46
46
|
# report should reference file used to build it
|
@@ -57,9 +57,9 @@ class SimpleCov::Formatter::MetricFu
|
|
57
57
|
content << "=" * 80
|
58
58
|
content << "\n"
|
59
59
|
source_file.lines.each do |line|
|
60
|
-
content <<
|
61
|
-
content <<
|
62
|
-
content <<
|
60
|
+
content << "!!" if line.missed?
|
61
|
+
content << "--" if line.never? || line.skipped?
|
62
|
+
content << " " if line.covered?
|
63
63
|
content << " #{line.src.chomp}\n"
|
64
64
|
end
|
65
65
|
content << "\n"
|
@@ -68,8 +68,7 @@ class SimpleCov::Formatter::MetricFu
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def simple_file_name(source_file)
|
71
|
-
source_file.filename.gsub(SimpleCov.root,
|
71
|
+
source_file.filename.gsub(SimpleCov.root, ".")
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
75
74
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
module MetricFu
|
2
|
-
|
3
2
|
class ReekGenerator < Generator
|
4
3
|
REEK_REGEX = /^(\S+) (.*) \((.*)\)$/
|
5
4
|
|
@@ -20,7 +19,7 @@ module MetricFu
|
|
20
19
|
end
|
21
20
|
|
22
21
|
def run!(args)
|
23
|
-
require
|
22
|
+
require "reek/cli/application"
|
24
23
|
|
25
24
|
MetricFu::Utility.capture_output do
|
26
25
|
Reek::Cli::Application.new(args).execute
|
@@ -28,24 +27,24 @@ module MetricFu
|
|
28
27
|
end
|
29
28
|
|
30
29
|
def analyze
|
31
|
-
@matches = @output.chomp.split("\n\n").map{|m| m.split("\n") }
|
30
|
+
@matches = @output.chomp.split("\n\n").map { |m| m.split("\n") }
|
32
31
|
@matches = @matches.map do |match|
|
33
32
|
break {} if zero_warnings?(match)
|
34
|
-
file_path = match.shift.split(
|
35
|
-
file_path = file_path.gsub('"',
|
33
|
+
file_path = match.shift.split(" -- ").first
|
34
|
+
file_path = file_path.gsub('"', " ").strip
|
36
35
|
code_smells = match.map do |smell|
|
37
36
|
match_object = smell.match(REEK_REGEX)
|
38
37
|
next unless match_object
|
39
|
-
{:
|
40
|
-
|
41
|
-
|
38
|
+
{ method: match_object[1].strip,
|
39
|
+
message: match_object[2].strip,
|
40
|
+
type: match_object[3].strip }
|
42
41
|
end.compact
|
43
|
-
{:
|
42
|
+
{ file_path: file_path, code_smells: code_smells }
|
44
43
|
end
|
45
44
|
end
|
46
45
|
|
47
46
|
def to_h
|
48
|
-
{:
|
47
|
+
{ reek: { matches: @matches } }
|
49
48
|
end
|
50
49
|
|
51
50
|
def per_file_info(out)
|
@@ -53,7 +52,7 @@ module MetricFu
|
|
53
52
|
file_path = file_data[:file_path]
|
54
53
|
next if File.extname(file_path) =~ /\.erb|\.html|\.haml/
|
55
54
|
begin
|
56
|
-
line_numbers = MetricFu::LineNumbers.new(File.read(file_path),file_path)
|
55
|
+
line_numbers = MetricFu::LineNumbers.new(File.read(file_path), file_path)
|
57
56
|
rescue StandardError => e
|
58
57
|
raise e unless e.message =~ /you shouldn't be able to get here/
|
59
58
|
mf_log "ruby_parser blew up while trying to parse #{file_path}. You won't have method level reek information for this file."
|
@@ -62,8 +61,8 @@ module MetricFu
|
|
62
61
|
|
63
62
|
file_data[:code_smells].each do |smell_data|
|
64
63
|
line = line_numbers.start_line_for_method(smell_data[:method])
|
65
|
-
out[file_data[:file_path]][line.to_s] << {:
|
66
|
-
|
64
|
+
out[file_data[:file_path]][line.to_s] << { type: :reek,
|
65
|
+
description: "#{smell_data[:type]} - #{smell_data[:message]}" }
|
67
66
|
end
|
68
67
|
end
|
69
68
|
end
|
@@ -74,7 +73,7 @@ module MetricFu
|
|
74
73
|
end
|
75
74
|
|
76
75
|
def massage_for_reek_12
|
77
|
-
section_break =
|
76
|
+
section_break = ""
|
78
77
|
@output.split("\n").map do |line|
|
79
78
|
case line
|
80
79
|
when /^ /
|
@@ -84,7 +83,7 @@ module MetricFu
|
|
84
83
|
if parts[1].nil?
|
85
84
|
"#{line}\n"
|
86
85
|
else
|
87
|
-
warnings = parts[1].gsub(/ \(.*\):/,
|
86
|
+
warnings = parts[1].gsub(/ \(.*\):/, ":")
|
88
87
|
result = "#{section_break}\"#{parts[0]}\" -- #{warnings}\n"
|
89
88
|
section_break = "\n"
|
90
89
|
result
|
@@ -97,7 +96,7 @@ module MetricFu
|
|
97
96
|
|
98
97
|
def files_to_analyze
|
99
98
|
dirs_to_reek = options[:dirs_to_reek]
|
100
|
-
files_to_reek = dirs_to_reek.map{|dir| Dir[File.join(dir, "**","*.rb")] }.flatten
|
99
|
+
files_to_reek = dirs_to_reek.map { |dir| Dir[File.join(dir, "**", "*.rb")] }.flatten
|
101
100
|
remove_excluded_files(files_to_reek)
|
102
101
|
end
|
103
102
|
|
@@ -114,30 +113,30 @@ module MetricFu
|
|
114
113
|
def config_option
|
115
114
|
config_file_pattern = options[:config_file_pattern]
|
116
115
|
if config_file_pattern.to_s.empty?
|
117
|
-
[
|
116
|
+
[""]
|
118
117
|
else
|
119
|
-
[
|
118
|
+
["--config", config_file_pattern]
|
120
119
|
end
|
121
120
|
end
|
122
121
|
|
123
122
|
# Work around "Error: invalid option: --no-color" in reek < 1.3.7
|
124
123
|
def turn_off_color
|
125
|
-
if reek_version >=
|
126
|
-
|
124
|
+
if reek_version >= "1.3.7"
|
125
|
+
"--no-color"
|
127
126
|
else
|
128
|
-
|
127
|
+
""
|
129
128
|
end
|
130
129
|
end
|
131
130
|
|
132
131
|
def reek_version
|
133
|
-
@reek_version ||= `reek --version`.chomp.sub(/\s*reek\s*/,
|
132
|
+
@reek_version ||= `reek --version`.chomp.sub(/\s*reek\s*/, "")
|
134
133
|
# use the above, as the below may activate a version not available in
|
135
134
|
# a Bundler context
|
136
135
|
# MetricFu::GemVersion.activated_version('reek').to_s
|
137
136
|
end
|
138
137
|
|
139
138
|
def disable_line_number_option
|
140
|
-
|
139
|
+
"--no-line-numbers"
|
141
140
|
end
|
142
141
|
|
143
142
|
def zero_warnings?(match)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
MetricFu.reporting_require {
|
1
|
+
MetricFu.reporting_require { "graphs/grapher" }
|
2
2
|
module MetricFu
|
3
3
|
class ReekGrapher < Grapher
|
4
4
|
attr_accessor :reek_count, :labels
|
@@ -16,7 +16,7 @@ module MetricFu
|
|
16
16
|
def get_metrics(metrics, date)
|
17
17
|
if metrics && metrics[:reek]
|
18
18
|
counter = @labels.size
|
19
|
-
@labels.update(
|
19
|
+
@labels.update(@labels.size => date)
|
20
20
|
|
21
21
|
metrics[:reek][:matches].each do |reek_chunk|
|
22
22
|
reek_chunk[:code_smells].each do |code_smell|
|
@@ -33,17 +33,17 @@ module MetricFu
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def title
|
36
|
-
|
36
|
+
"Reek: code smells"
|
37
37
|
end
|
38
38
|
|
39
39
|
def data
|
40
40
|
@reek_count.map do |name, count|
|
41
|
-
[name, nil_counts_to_zero(count).join(
|
41
|
+
[name, nil_counts_to_zero(count).join(",")]
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
def output_filename
|
46
|
-
|
46
|
+
"reek.js"
|
47
47
|
end
|
48
48
|
|
49
49
|
private
|
@@ -51,6 +51,5 @@ module MetricFu
|
|
51
51
|
def nil_counts_to_zero(counts)
|
52
52
|
counts.map { |count| count || 0 }
|
53
53
|
end
|
54
|
-
|
55
54
|
end
|
56
55
|
end
|
@@ -1,13 +1,12 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
class MetricFu::ReekHotspot < MetricFu::Hotspot
|
3
|
-
|
4
3
|
# Note that in practice, the prefix reek__ is appended to each one
|
5
4
|
# This was a partially implemented idea to avoid column name collisions
|
6
5
|
# but it is only done in the ReekHotspot
|
7
6
|
COLUMNS = %w{type_name message value value_description comparable_message}
|
8
7
|
|
9
8
|
def columns
|
10
|
-
COLUMNS.map{|column| "#{name}__#{column}"}
|
9
|
+
COLUMNS.map { |column| "#{name}__#{column}" }
|
11
10
|
end
|
12
11
|
|
13
12
|
def name
|
@@ -27,7 +26,7 @@ class MetricFu::ReekHotspot < MetricFu::Hotspot
|
|
27
26
|
end
|
28
27
|
|
29
28
|
def generate_records(data, table)
|
30
|
-
return if data==nil
|
29
|
+
return if data == nil
|
31
30
|
data[:matches].each do |match|
|
32
31
|
file_path = match[:file_path]
|
33
32
|
match[:code_smells].each do |smell|
|
@@ -65,7 +64,7 @@ class MetricFu::ReekHotspot < MetricFu::Hotspot
|
|
65
64
|
def comparable_message(type_name, message)
|
66
65
|
if self.class.numeric_smell?(type_name)
|
67
66
|
match = message.match(/\d+/)
|
68
|
-
if
|
67
|
+
if match
|
69
68
|
match.pre_match + match.post_match
|
70
69
|
else
|
71
70
|
message
|
@@ -77,7 +76,7 @@ class MetricFu::ReekHotspot < MetricFu::Hotspot
|
|
77
76
|
|
78
77
|
def build_value_description(type_name, message)
|
79
78
|
item_type = message.match(/\d+ (.*)$/)
|
80
|
-
if
|
79
|
+
if item_type
|
81
80
|
"number of #{item_type[1]} in #{type_name.downcase}"
|
82
81
|
else
|
83
82
|
nil
|
@@ -87,11 +86,10 @@ class MetricFu::ReekHotspot < MetricFu::Hotspot
|
|
87
86
|
def parse_value(message)
|
88
87
|
# mf_debug "parsing #{message}"
|
89
88
|
match = message.match(/\d+/)
|
90
|
-
if
|
89
|
+
if match
|
91
90
|
match[0].to_i
|
92
91
|
else
|
93
92
|
nil
|
94
93
|
end
|
95
94
|
end
|
96
|
-
|
97
95
|
end
|