metric_fu 4.11.1 → 4.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (206) hide show
  1. checksums.yaml +5 -13
  2. data/.gitignore +6 -0
  3. data/.rubocop.yml +15 -0
  4. data/.rubocop_todo.yml +69 -0
  5. data/.simplecov +35 -3
  6. data/.travis.yml +6 -10
  7. data/CONTRIBUTORS +12 -11
  8. data/Gemfile +48 -29
  9. data/Guardfile +9 -9
  10. data/HISTORY.md +47 -1
  11. data/README.md +70 -57
  12. data/Rakefile +1 -15
  13. data/appveyor.yml +34 -0
  14. data/certs/bf4.pem +20 -20
  15. data/checksum/metric_fu-4.11.1.gem.sha512 +1 -0
  16. data/checksum/metric_fu-4.11.2.gem.sha512 +1 -0
  17. data/checksum/metric_fu-4.11.3.gem.sha512 +1 -0
  18. data/checksum/metric_fu-4.11.4.gem.sha512 +1 -0
  19. data/checksum/metric_fu-4.12.0.gem.sha512 +1 -0
  20. data/checksum/metric_fu-4.13.0.gem.sha512 +1 -0
  21. data/config/rubocop.yml +269 -0
  22. data/gem_tasks/build.rake +1 -0
  23. data/gem_tasks/rubocop.rake +10 -0
  24. data/gem_tasks/yard.rake +24 -0
  25. data/lib/metric_fu.rb +20 -9
  26. data/lib/metric_fu/calculate.rb +0 -1
  27. data/lib/metric_fu/cli/client.rb +6 -6
  28. data/lib/metric_fu/cli/helper.rb +22 -13
  29. data/lib/metric_fu/cli/parser.rb +14 -18
  30. data/lib/metric_fu/configuration.rb +7 -11
  31. data/lib/metric_fu/constantize.rb +4 -4
  32. data/lib/metric_fu/data_structures/line_numbers.rb +10 -11
  33. data/lib/metric_fu/data_structures/location.rb +12 -14
  34. data/lib/metric_fu/data_structures/sexp_node.rb +31 -13
  35. data/lib/metric_fu/environment.rb +29 -31
  36. data/lib/metric_fu/formatter.rb +4 -6
  37. data/lib/metric_fu/formatter/html.rb +13 -13
  38. data/lib/metric_fu/formatter/syntax.rb +5 -7
  39. data/lib/metric_fu/formatter/yaml.rb +1 -1
  40. data/lib/metric_fu/gem_run.rb +13 -15
  41. data/lib/metric_fu/gem_version.rb +10 -12
  42. data/lib/metric_fu/generator.rb +6 -9
  43. data/lib/metric_fu/io.rb +13 -15
  44. data/lib/metric_fu/loader.rb +17 -18
  45. data/lib/metric_fu/logger.rb +15 -18
  46. data/lib/metric_fu/logging/mf_debugger.rb +4 -4
  47. data/lib/metric_fu/metric.rb +11 -12
  48. data/lib/metric_fu/metrics/cane/generator.rb +10 -9
  49. data/lib/metric_fu/metrics/cane/grapher.rb +5 -7
  50. data/lib/metric_fu/metrics/cane/metric.rb +6 -8
  51. data/lib/metric_fu/metrics/cane/report.html.erb +3 -3
  52. data/lib/metric_fu/metrics/cane/violations.rb +6 -6
  53. data/lib/metric_fu/metrics/churn/generator.rb +2 -6
  54. data/lib/metric_fu/metrics/churn/hotspot.rb +1 -3
  55. data/lib/metric_fu/metrics/churn/metric.rb +5 -7
  56. data/lib/metric_fu/metrics/flay/generator.rb +7 -11
  57. data/lib/metric_fu/metrics/flay/grapher.rb +5 -6
  58. data/lib/metric_fu/metrics/flay/hotspot.rb +5 -7
  59. data/lib/metric_fu/metrics/flay/metric.rb +5 -7
  60. data/lib/metric_fu/metrics/flog/generator.rb +35 -24
  61. data/lib/metric_fu/metrics/flog/grapher.rb +11 -11
  62. data/lib/metric_fu/metrics/flog/hotspot.rb +3 -5
  63. data/lib/metric_fu/metrics/flog/metric.rb +3 -5
  64. data/lib/metric_fu/metrics/hotspots/analysis/analyzed_problems.rb +0 -1
  65. data/lib/metric_fu/metrics/hotspots/analysis/analyzer_tables.rb +19 -18
  66. data/lib/metric_fu/metrics/hotspots/analysis/grouping.rb +0 -2
  67. data/lib/metric_fu/metrics/hotspots/analysis/groupings.rb +1 -3
  68. data/lib/metric_fu/metrics/hotspots/analysis/problems.rb +4 -6
  69. data/lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb +14 -17
  70. data/lib/metric_fu/metrics/hotspots/analysis/ranking.rb +4 -5
  71. data/lib/metric_fu/metrics/hotspots/analysis/rankings.rb +1 -3
  72. data/lib/metric_fu/metrics/hotspots/analysis/record.rb +3 -5
  73. data/lib/metric_fu/metrics/hotspots/analysis/scoring_strategies.rb +0 -2
  74. data/lib/metric_fu/metrics/hotspots/analysis/table.rb +3 -4
  75. data/lib/metric_fu/metrics/hotspots/generator.rb +3 -6
  76. data/lib/metric_fu/metrics/hotspots/hotspot.rb +13 -13
  77. data/lib/metric_fu/metrics/hotspots/hotspot_analyzer.rb +5 -8
  78. data/lib/metric_fu/metrics/hotspots/metric.rb +1 -3
  79. data/lib/metric_fu/metrics/hotspots/report.html.erb +1 -1
  80. data/lib/metric_fu/metrics/rails_best_practices/generator.rb +14 -12
  81. data/lib/metric_fu/metrics/rails_best_practices/grapher.rb +5 -6
  82. data/lib/metric_fu/metrics/rails_best_practices/metric.rb +5 -4
  83. data/lib/metric_fu/metrics/rcov/external_client.rb +1 -3
  84. data/lib/metric_fu/metrics/rcov/generator.rb +13 -15
  85. data/lib/metric_fu/metrics/rcov/grapher.rb +6 -7
  86. data/lib/metric_fu/metrics/rcov/hotspot.rb +5 -7
  87. data/lib/metric_fu/metrics/rcov/metric.rb +5 -7
  88. data/lib/metric_fu/metrics/rcov/rcov_format_coverage.rb +16 -55
  89. data/lib/metric_fu/metrics/rcov/rcov_line.rb +48 -0
  90. data/lib/metric_fu/metrics/rcov/report.html.erb +2 -2
  91. data/lib/metric_fu/metrics/rcov/simplecov_formatter.rb +10 -11
  92. data/lib/metric_fu/metrics/reek/generator.rb +36 -82
  93. data/lib/metric_fu/metrics/reek/grapher.rb +5 -6
  94. data/lib/metric_fu/metrics/reek/hotspot.rb +5 -7
  95. data/lib/metric_fu/metrics/reek/metric.rb +2 -4
  96. data/lib/metric_fu/metrics/roodi/generator.rb +9 -10
  97. data/lib/metric_fu/metrics/roodi/grapher.rb +5 -6
  98. data/lib/metric_fu/metrics/roodi/hotspot.rb +1 -3
  99. data/lib/metric_fu/metrics/roodi/metric.rb +2 -4
  100. data/lib/metric_fu/metrics/saikuro/generator.rb +23 -27
  101. data/lib/metric_fu/metrics/saikuro/hotspot.rb +1 -3
  102. data/lib/metric_fu/metrics/saikuro/metric.rb +7 -8
  103. data/lib/metric_fu/metrics/saikuro/parsing_element.rb +6 -8
  104. data/lib/metric_fu/metrics/saikuro/report.html.erb +1 -1
  105. data/lib/metric_fu/metrics/saikuro/scratch_file.rb +24 -29
  106. data/lib/metric_fu/metrics/stats/generator.rb +9 -12
  107. data/lib/metric_fu/metrics/stats/grapher.rb +8 -9
  108. data/lib/metric_fu/metrics/stats/hotspot.rb +1 -3
  109. data/lib/metric_fu/metrics/stats/metric.rb +3 -5
  110. data/lib/metric_fu/reporter.rb +1 -1
  111. data/lib/metric_fu/reporting/graphs/graph.rb +8 -12
  112. data/lib/metric_fu/reporting/graphs/grapher.rb +7 -9
  113. data/lib/metric_fu/reporting/result.rb +0 -3
  114. data/lib/metric_fu/run.rb +12 -3
  115. data/lib/metric_fu/tasks/metric_fu.rake +8 -8
  116. data/lib/metric_fu/templates/configuration.rb +2 -5
  117. data/lib/metric_fu/templates/metrics_template.rb +45 -32
  118. data/lib/metric_fu/templates/report.rb +5 -8
  119. data/lib/metric_fu/templates/template.rb +20 -24
  120. data/lib/metric_fu/utility.rb +15 -8
  121. data/lib/metric_fu/version.rb +7 -1
  122. data/metric_fu.gemspec +29 -32
  123. data/spec/capture_warnings.rb +29 -22
  124. data/spec/cli/helper_spec.rb +9 -16
  125. data/spec/dummy/lib/bad_encoding.rb +1 -1
  126. data/spec/fixtures/coverage-153.rb +2 -2
  127. data/spec/fixtures/coverage.rb +2 -2
  128. data/spec/metric_fu/calculate_spec.rb +3 -3
  129. data/spec/metric_fu/configuration_spec.rb +71 -83
  130. data/spec/metric_fu/data_structures/line_numbers_spec.rb +3 -5
  131. data/spec/metric_fu/data_structures/location_spec.rb +13 -31
  132. data/spec/metric_fu/formatter/configuration_spec.rb +18 -20
  133. data/spec/metric_fu/formatter/html_spec.rb +21 -28
  134. data/spec/metric_fu/formatter/yaml_spec.rb +9 -17
  135. data/spec/metric_fu/formatter_spec.rb +16 -16
  136. data/spec/metric_fu/gem_version_spec.rb +4 -6
  137. data/spec/metric_fu/generator_spec.rb +33 -43
  138. data/spec/metric_fu/loader_spec.rb +5 -4
  139. data/spec/metric_fu/metric_spec.rb +21 -25
  140. data/spec/metric_fu/metrics/cane/configuration_spec.rb +14 -14
  141. data/spec/metric_fu/metrics/cane/generator_spec.rb +26 -29
  142. data/spec/metric_fu/metrics/churn/configuration_spec.rb +7 -9
  143. data/spec/metric_fu/metrics/churn/generator_spec.rb +6 -11
  144. data/spec/metric_fu/metrics/flay/configuration_spec.rb +7 -9
  145. data/spec/metric_fu/metrics/flay/generator_spec.rb +36 -37
  146. data/spec/metric_fu/metrics/flay/grapher_spec.rb +2 -2
  147. data/spec/metric_fu/metrics/flog/configuration_spec.rb +12 -14
  148. data/spec/metric_fu/metrics/flog/generator_spec.rb +31 -32
  149. data/spec/metric_fu/metrics/flog/grapher_spec.rb +8 -10
  150. data/spec/metric_fu/metrics/hotspots/analysis/analyzed_problems_spec.rb +18 -24
  151. data/spec/metric_fu/metrics/hotspots/analysis/analyzer_tables_spec.rb +12 -17
  152. data/spec/metric_fu/metrics/hotspots/analysis/ranking_spec.rb +2 -6
  153. data/spec/metric_fu/metrics/hotspots/analysis/rankings_spec.rb +5 -14
  154. data/spec/metric_fu/metrics/hotspots/analysis/table_spec.rb +1 -3
  155. data/spec/metric_fu/metrics/hotspots/generator_spec.rb +6 -8
  156. data/spec/metric_fu/metrics/hotspots/hotspot_analyzer_spec.rb +1 -3
  157. data/spec/metric_fu/metrics/hotspots/hotspot_spec.rb +4 -5
  158. data/spec/metric_fu/metrics/rails_best_practices/configuration_spec.rb +25 -17
  159. data/spec/metric_fu/metrics/rails_best_practices/generator_spec.rb +2 -3
  160. data/spec/metric_fu/metrics/rails_best_practices/grapher_spec.rb +3 -3
  161. data/spec/metric_fu/metrics/rcov/configuration_spec.rb +21 -23
  162. data/spec/metric_fu/metrics/rcov/generator_spec.rb +6 -10
  163. data/spec/metric_fu/metrics/rcov/grapher_spec.rb +2 -2
  164. data/spec/metric_fu/metrics/rcov/hotspot_spec.rb +8 -8
  165. data/spec/metric_fu/metrics/rcov/rcov_line_spec.rb +89 -0
  166. data/spec/metric_fu/metrics/rcov/simplecov_formatter_spec.rb +31 -33
  167. data/spec/metric_fu/metrics/reek/configuration_spec.rb +7 -7
  168. data/spec/metric_fu/metrics/reek/generator_spec.rb +131 -111
  169. data/spec/metric_fu/metrics/reek/grapher_spec.rb +4 -4
  170. data/spec/metric_fu/metrics/roodi/configuration_spec.rb +8 -10
  171. data/spec/metric_fu/metrics/roodi/generator_spec.rb +3 -3
  172. data/spec/metric_fu/metrics/roodi/grapher_spec.rb +2 -2
  173. data/spec/metric_fu/metrics/saikuro/configuration_spec.rb +22 -23
  174. data/spec/metric_fu/metrics/saikuro/generator_spec.rb +7 -7
  175. data/spec/metric_fu/metrics/stats/generator_spec.rb +10 -10
  176. data/spec/metric_fu/metrics/stats/grapher_spec.rb +2 -2
  177. data/spec/metric_fu/reporter_spec.rb +8 -9
  178. data/spec/metric_fu/reporting/graphs/graph_spec.rb +1 -4
  179. data/spec/metric_fu/reporting/graphs/grapher_spec.rb +5 -5
  180. data/spec/metric_fu/reporting/result_spec.rb +12 -14
  181. data/spec/metric_fu/run_spec.rb +19 -33
  182. data/spec/metric_fu/templates/configuration_spec.rb +34 -40
  183. data/spec/metric_fu/templates/metrics_template_spec.rb +11 -0
  184. data/spec/metric_fu/templates/report_spec.rb +4 -4
  185. data/spec/metric_fu/templates/template_spec.rb +78 -64
  186. data/spec/metric_fu/utility_spec.rb +3 -3
  187. data/spec/metric_fu_spec.rb +23 -6
  188. data/spec/quality_spec.rb +43 -15
  189. data/spec/shared/configured.rb +9 -11
  190. data/spec/shared/test_coverage.rb +5 -9
  191. data/spec/spec_helper.rb +13 -31
  192. data/spec/{dummy → support}/.metrics +0 -0
  193. data/spec/support/deferred_garbaged_collection.rb +1 -2
  194. data/spec/support/matcher_create_file.rb +6 -4
  195. data/spec/support/matcher_create_files.rb +6 -4
  196. data/spec/support/samples/reek/alfa.rb +1 -0
  197. data/spec/support/suite.rb +3 -3
  198. data/spec/support/test_fixtures.rb +5 -7
  199. data/spec/support/timeout.rb +1 -1
  200. data/spec/support/usage_test.rb +24 -25
  201. data/spec/usage_test_spec.rb +30 -32
  202. metadata +104 -103
  203. checksums.yaml.gz.sig +0 -0
  204. data.tar.gz.sig +0 -0
  205. data/gemfiles/Gemfile.travis +0 -10
  206. metadata.gz.sig +0 -0
@@ -1,16 +1,15 @@
1
1
  module MetricFu
2
2
  class MetricFlay < Metric
3
-
4
3
  def name
5
4
  :flay
6
5
  end
7
6
 
8
7
  def default_run_options
9
- { :dirs_to_flay => MetricFu::Io::FileSystem.directory('code_dirs'),
10
- # MetricFu has been setting the minimum score as 100 for
11
- # a long time. This is a really big number, considering
12
- # the default is 16. Setting it to nil to use the Flay default.
13
- :minimum_score => nil,
8
+ { dirs_to_flay: MetricFu::Io::FileSystem.directory("code_dirs"),
9
+ # MetricFu has been setting the minimum score as 100 for
10
+ # a long time. This is a really big number, considering
11
+ # the default is 16. Setting it to nil to use the Flay default.
12
+ minimum_score: nil,
14
13
  }
15
14
  end
16
15
 
@@ -25,6 +24,5 @@ module MetricFu
25
24
  def activate
26
25
  super
27
26
  end
28
-
29
27
  end
30
28
  end
@@ -1,9 +1,8 @@
1
- require 'pathname'
2
- require 'optparse'
1
+ require "pathname"
2
+ require "optparse"
3
3
 
4
4
  module MetricFu
5
5
  class FlogGenerator < Generator
6
-
7
6
  def self.metric
8
7
  :flog
9
8
  end
@@ -14,14 +13,14 @@ module MetricFu
14
13
  options[:continue] ? "--continue" : nil,
15
14
  ].compact
16
15
  @flogger = FlogCLI.new parse_options
17
- @flogger.flog *options[:dirs_to_flog]
16
+ @flogger.flog *files_to_flog
18
17
  end
19
18
 
20
19
  def analyze
21
20
  @method_containers = {}
22
21
  @flogger.calculate
23
22
  @flogger.each_by_score do |full_method_name, score, operators|
24
- container_name = full_method_name.split('#').first
23
+ container_name = full_method_name.split("#").first
25
24
  path = @flogger.method_locations[full_method_name]
26
25
  if @method_containers[container_name]
27
26
  @method_containers[container_name].add_method(full_method_name, operators, score, path)
@@ -35,23 +34,35 @@ module MetricFu
35
34
  end
36
35
 
37
36
  def to_h
38
- sorted_containers = @method_containers.values.sort_by {|c| c.highest_score}.reverse
39
- {:flog => { :total => @flogger.total_score,
40
- :average => @flogger.average,
41
- :method_containers => sorted_containers.map {|method_container| method_container.to_h}}}
37
+ sorted_containers = @method_containers.values.sort_by(&:highest_score).reverse
38
+ { flog: { total: @flogger.total_score,
39
+ average: @flogger.average,
40
+ method_containers: sorted_containers.map(&:to_h) } }
42
41
  end
43
42
 
44
43
  def per_file_info(out)
45
- @method_containers.each_pair do |klass, container|
46
- container.methods.each_pair do |method_name, data|
44
+ @method_containers.each_pair do |_klass, container|
45
+ container.methods.each_pair do |_method_name, data|
47
46
  next if data[:path].nil?
48
47
 
49
- file, line = data[:path].split(':')
48
+ file, line = data[:path].split(":")
50
49
 
51
- out[file][line] << {:type => :flog, :description => "Score of %.2f" % data[:score]}
50
+ out[file][line] << { type: :flog, description: "Score of %.2f" % data[:score] }
52
51
  end
53
52
  end
54
53
  end
54
+
55
+ private
56
+
57
+ def files_to_flog
58
+ options[:dirs_to_flog].flatten.map do |p|
59
+ if File.directory? p then
60
+ Dir[File.join(p, '**/*.{rb,rake}')]
61
+ else
62
+ p
63
+ end
64
+ end.flatten
65
+ end
55
66
  end
56
67
 
57
68
  class MethodContainer
@@ -63,22 +74,22 @@ module MetricFu
63
74
  @methods = {}
64
75
  end
65
76
 
66
- def add_path path
77
+ def add_path(path)
67
78
  return unless path
68
- @path ||= path.split(':').first
79
+ @path ||= path.split(":").first
69
80
  end
70
81
 
71
82
  def add_method(full_method_name, operators, score, path)
72
- @methods[full_method_name] = {:operators => operators, :score => score, :path => path}
83
+ @methods[full_method_name] = { operators: operators, score: score, path: path }
73
84
  end
74
85
 
75
86
  def to_h
76
- { :name => @name,
77
- :path => @path || '',
78
- :total_score => total_score,
79
- :highest_score => highest_score,
80
- :average_score => average_score,
81
- :methods => @methods}
87
+ { name: @name,
88
+ path: @path || "",
89
+ total_score: total_score,
90
+ highest_score: highest_score,
91
+ average_score: average_score,
92
+ methods: @methods }
82
93
  end
83
94
 
84
95
  def highest_score
@@ -88,11 +99,11 @@ module MetricFu
88
99
  private
89
100
 
90
101
  def method_scores
91
- @method_scores ||= @methods.values.map {|v| v[:score] }
102
+ @method_scores ||= @methods.values.map { |v| v[:score] }
92
103
  end
93
104
 
94
105
  def total_score
95
- @total_score ||= method_scores.inject(0) {|sum, score| sum += score}
106
+ @total_score ||= method_scores.inject(0) { |sum, score| sum += score }
96
107
  end
97
108
 
98
109
  def average_score
@@ -1,4 +1,4 @@
1
- MetricFu.reporting_require { 'graphs/grapher' }
1
+ MetricFu.reporting_require { "graphs/grapher" }
2
2
  module MetricFu
3
3
  class FlogGrapher < Grapher
4
4
  attr_accessor :flog_average, :labels, :top_five_percent_average
@@ -11,30 +11,30 @@ module MetricFu
11
11
  super
12
12
  @flog_average = []
13
13
  @labels = {}
14
- @top_five_percent_average =[]
14
+ @top_five_percent_average = []
15
15
  end
16
16
 
17
17
  def get_metrics(metrics, date)
18
18
  if metrics && metrics[:flog]
19
19
  @top_five_percent_average.push(calc_top_five_percent_average(metrics))
20
20
  @flog_average.push(metrics[:flog][:average])
21
- @labels.update( { @labels.size => date })
21
+ @labels.update(@labels.size => date)
22
22
  end
23
23
  end
24
24
 
25
25
  def title
26
- 'Flog: code complexity'
26
+ "Flog: code complexity"
27
27
  end
28
28
 
29
29
  def data
30
30
  [
31
- ['average', @flog_average.join(',')],
32
- ['top 5% average', @top_five_percent_average.join(',')]
31
+ ["average", @flog_average.join(",")],
32
+ ["top 5% average", @top_five_percent_average.join(",")]
33
33
  ]
34
34
  end
35
35
 
36
36
  def output_filename
37
- 'flog.js'
37
+ "flog.js"
38
38
  end
39
39
 
40
40
  private
@@ -43,7 +43,7 @@ module MetricFu
43
43
  return calc_top_five_percent_average_legacy(metrics) if metrics[:flog][:pages]
44
44
 
45
45
  method_scores = metrics[:flog][:method_containers].inject([]) do |method_scores, container|
46
- method_scores += container[:methods].values.map {|v| v[:score]}
46
+ method_scores += container[:methods].values.map { |v| v[:score] }
47
47
  end
48
48
  method_scores.sort!.reverse!
49
49
 
@@ -59,14 +59,14 @@ module MetricFu
59
59
  end
60
60
 
61
61
  def calc_top_five_percent_average_legacy(metrics)
62
- methods = metrics[:flog][:pages].inject([]) {|methods, page| methods << page[:scanned_methods]}
62
+ methods = metrics[:flog][:pages].inject([]) { |methods, page| methods << page[:scanned_methods] }
63
63
  methods.flatten!
64
- methods = methods.sort_by {|method| method[:score]}.reverse
64
+ methods = methods.sort_by { |method| method[:score] }.reverse
65
65
 
66
66
  number_of_methods_that_is_five_percent = (methods.size * 0.05).ceil
67
67
 
68
68
  total_for_five_percent =
69
- methods[0...number_of_methods_that_is_five_percent].inject(0) {|total, method| total += method[:score] }
69
+ methods[0...number_of_methods_that_is_five_percent].inject(0) { |total, method| total += method[:score] }
70
70
  if number_of_methods_that_is_five_percent == 0
71
71
  0.0
72
72
  else
@@ -1,5 +1,4 @@
1
1
  class MetricFu::FlogHotspot < MetricFu::Hotspot
2
-
3
2
  COLUMNS = %w{score}
4
3
 
5
4
  def columns
@@ -23,10 +22,10 @@ class MetricFu::FlogHotspot < MetricFu::Hotspot
23
22
  end
24
23
 
25
24
  def generate_records(data, table)
26
- return if data==nil
25
+ return if data == nil
27
26
  Array(data[:method_containers]).each do |method_container|
28
27
  Array(method_container[:methods]).each do |entry|
29
- file_path = entry[1][:path].sub(%r{^/},'') if entry[1][:path]
28
+ file_path = entry[1][:path].sub(%r{^/}, "") if entry[1][:path]
30
29
  location = MetricFu::Location.for(entry.first)
31
30
  table << {
32
31
  "metric" => name,
@@ -42,7 +41,6 @@ class MetricFu::FlogHotspot < MetricFu::Hotspot
42
41
  def present_group(group)
43
42
  occurences = group.size
44
43
  complexity = get_mean(group.column("score"))
45
- "#{"average " if occurences > 1}complexity is %.1f" % complexity
44
+ "#{'average ' if occurences > 1}complexity is %.1f" % complexity
46
45
  end
47
-
48
46
  end
@@ -1,12 +1,11 @@
1
1
  module MetricFu
2
2
  class MetricFlog < Metric
3
-
4
3
  def name
5
4
  :flog
6
5
  end
7
6
 
8
7
  def default_run_options
9
- { :dirs_to_flog => MetricFu::Io::FileSystem.directory('code_dirs'), :continue => true, :all => true, :quiet => true }
8
+ { dirs_to_flog: MetricFu::Io::FileSystem.directory("code_dirs"), continue: true, all: true, quiet: true }
10
9
  end
11
10
 
12
11
  def has_graph?
@@ -22,10 +21,9 @@ module MetricFu
22
21
  end
23
22
 
24
23
  def activate
25
- activate_library 'flog'
26
- activate_library 'flog_cli'
24
+ activate_library "flog"
25
+ activate_library "flog_cli"
27
26
  super
28
27
  end
29
-
30
28
  end
31
29
  end
@@ -30,6 +30,5 @@ module MetricFu
30
30
  tables = @analyzer_tables.tables_for(granularity)
31
31
  tables[ranked_item_name]
32
32
  end
33
-
34
33
  end
35
34
  end
@@ -23,10 +23,10 @@ module MetricFu
23
23
 
24
24
  def tables_for(item)
25
25
  {
26
- :class => @class_tables,
27
- :method => @method_tables,
28
- :file => @file_tables,
29
- :tool => @tool_tables
26
+ class: @class_tables,
27
+ method: @method_tables,
28
+ file: @file_tables,
29
+ tool: @tool_tables
30
30
  }.fetch(item) do
31
31
  raise ArgumentError, "Item must be :class, :method, or :file, but was #{item}"
32
32
  end
@@ -35,7 +35,7 @@ module MetricFu
35
35
  private
36
36
 
37
37
  def make_table(columns)
38
- MetricFu::Table.new(:column_names => columns)
38
+ MetricFu::Table.new(column_names: columns)
39
39
  end
40
40
 
41
41
  def make_table_hash(columns)
@@ -52,9 +52,9 @@ module MetricFu
52
52
  table.each do |row|
53
53
  # We know that Saikuro provides the wrong data
54
54
  # TODO inject Saikuro reference
55
- next if row['metric'] == :saikuro
56
- key = [row['class_name'], row['method_name']]
57
- file_path = row['file_path']
55
+ next if row["metric"] == :saikuro
56
+ key = [row["class_name"], row["method_name"]]
57
+ file_path = row["file_path"]
58
58
  @class_and_method_to_file[key] ||= file_path
59
59
  end
60
60
  end
@@ -63,7 +63,7 @@ module MetricFu
63
63
  def process_rows!
64
64
  # Correct incorrect rows in the table
65
65
  table.each do |row|
66
- row_metric = row['metric'] #perf optimization
66
+ row_metric = row["metric"] # perf optimization
67
67
  # TODO inject Saikuro reference
68
68
  if row_metric == :saikuro
69
69
  fix_row_file_path!(row)
@@ -75,37 +75,38 @@ module MetricFu
75
75
  end
76
76
  end
77
77
 
78
-
79
78
  # COLLECT AND PROCESS RAW HOTSPOT METRICS
80
79
  def fix_row_file_path!(row)
81
80
  # We know that Saikuro rows are broken
82
81
  # next unless row['metric'] == :saikuro
83
- key = [row['class_name'], row['method_name']]
84
- current_file_path = row['file_path'].to_s
82
+ key = [row["class_name"], row["method_name"]]
83
+ current_file_path = row["file_path"].to_s
85
84
  correct_file_path = @class_and_method_to_file[key]
86
- if(correct_file_path!=nil && correct_file_path.include?(current_file_path))
87
- row['file_path'] = correct_file_path
85
+ if !correct_file_path.nil? && correct_file_path.include?(current_file_path)
86
+ row["file_path"] = correct_file_path
88
87
  else
89
88
  # There wasn't an exact match, so we can do a substring match
90
89
  matching_file_path = file_paths.detect {|file_path|
91
- file_path!=nil && file_path.include?(current_file_path)
90
+ !file_path.nil? && file_path.include?(current_file_path)
92
91
  }
93
- if(matching_file_path)
94
- row['file_path'] = matching_file_path
92
+ if matching_file_path
93
+ row["file_path"] = matching_file_path
95
94
  end
96
95
  end
97
96
  end
98
97
 
99
98
  def file_paths
100
- @file_paths ||= @table.column('file_path').uniq
99
+ @file_paths ||= @table.column("file_path").uniq
101
100
  end
102
101
 
103
102
  def file_tables
104
103
  @file_tables ||= make_table_hash(@columns)
105
104
  end
105
+
106
106
  def class_tables
107
107
  @class_tables ||= make_table_hash(@columns)
108
108
  end
109
+
109
110
  def method_tables
110
111
  @method_tables ||= make_table_hash(@columns)
111
112
  end
@@ -3,7 +3,6 @@
3
3
  end
4
4
  module MetricFu
5
5
  class Grouping
6
-
7
6
  def initialize(table, opts)
8
7
  column_name = opts.fetch(:by)
9
8
  hash = {}
@@ -20,6 +19,5 @@ module MetricFu
20
19
  yield value, rows
21
20
  end
22
21
  end
23
-
24
22
  end
25
23
  end
@@ -1,7 +1,6 @@
1
- MetricFu.metrics_require { 'hotspots/analysis/grouping' }
1
+ MetricFu.metrics_require { "hotspots/analysis/grouping" }
2
2
  module MetricFu
3
3
  class HotspotGroupings
4
-
5
4
  def initialize(table, opts)
6
5
  @table, @opts = table, opts
7
6
  end
@@ -9,6 +8,5 @@ module MetricFu
9
8
  def get_grouping
10
9
  MetricFu::Grouping.new(@table, @opts)
11
10
  end
12
-
13
11
  end
14
12
  end
@@ -1,9 +1,8 @@
1
- MetricFu.metrics_require { 'hotspots/analysis/groupings' }
1
+ MetricFu.metrics_require { "hotspots/analysis/groupings" }
2
2
  module MetricFu
3
3
  class HotspotProblems
4
-
5
4
  def initialize(sub_table)
6
- @grouping = group_by(sub_table, 'metric')
5
+ @grouping = group_by(sub_table, "metric")
7
6
  end
8
7
 
9
8
  def problems
@@ -14,9 +13,8 @@ module MetricFu
14
13
  problems
15
14
  end
16
15
 
17
- def group_by(sub_table, by = 'metric')
18
- MetricFu::HotspotGroupings.new(sub_table, :by => by).get_grouping
16
+ def group_by(sub_table, by = "metric")
17
+ MetricFu::HotspotGroupings.new(sub_table, by: by).get_grouping
19
18
  end
20
-
21
19
  end
22
20
  end
@@ -1,8 +1,8 @@
1
- MetricFu.lib_require { 'errors/analysis_error' }
2
- MetricFu.metrics_require { 'hotspots/analysis/problems' }
1
+ MetricFu.lib_require { "errors/analysis_error" }
2
+ MetricFu.metrics_require { "hotspots/analysis/problems" }
3
3
  module MetricFu
4
4
  class HotspotRankedProblemLocation
5
- MetricFu.data_structures_require { 'location' }
5
+ MetricFu.data_structures_require { "location" }
6
6
  attr_reader :sub_table, :granularity
7
7
  def initialize(sub_table, granularity)
8
8
  @sub_table = sub_table
@@ -11,20 +11,11 @@ module MetricFu
11
11
 
12
12
  def to_hash
13
13
  {
14
- 'location' => location.to_hash,
15
- 'details' => stringify_keys(problems),
14
+ "location" => location.to_hash,
15
+ "details" => MetricFu::Utility.stringify_keys(problems),
16
16
  }
17
17
  end
18
18
 
19
- def stringify_keys(hash)
20
- result = {}
21
- hash.each do |key, value|
22
- result[key.to_s] = value
23
- end
24
- result
25
- end
26
-
27
-
28
19
  # @todo redo as item,value, options = {}
29
20
  # Note that the other option for 'details' is :detailed (this isn't
30
21
  # at all clear from this method itself
@@ -44,30 +35,36 @@ module MetricFu
44
35
  def file_path
45
36
  first_row.file_path
46
37
  end
38
+
47
39
  def class_name
48
40
  first_row.class_name
49
41
  end
42
+
50
43
  def method_name
51
44
  first_row.method_name
52
45
  end
46
+
53
47
  def file_location
54
48
  MetricFu::Location.get(file_path, nil, nil)
55
49
  end
50
+
56
51
  def method_location
57
52
  MetricFu::Location.get(file_path, class_name, method_name)
58
53
  end
54
+
59
55
  def class_location
60
56
  MetricFu::Location.get(file_path, class_name, nil)
61
57
  end
58
+
62
59
  def first_row
63
60
  assert_sub_table_has_data
64
61
  @first_row ||= sub_table[0]
65
62
  end
63
+
66
64
  def assert_sub_table_has_data
67
- if (sub_table.length==0)
68
- raise MetricFu::AnalysisError, "The #{item.to_s} '#{value.to_s}' does not have any rows in the analysis table"
65
+ if (sub_table.length == 0)
66
+ raise MetricFu::AnalysisError, "The #{item} '#{value}' does not have any rows in the analysis table"
69
67
  end
70
68
  end
71
-
72
69
  end
73
70
  end