metric_fu 4.1.2 → 4.1.3

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.
Files changed (76) hide show
  1. data/.travis.yml +7 -4
  2. data/.yardopts +5 -0
  3. data/CONTRIBUTING.md +28 -13
  4. data/Gemfile +7 -3
  5. data/HISTORY.md +12 -0
  6. data/README.md +17 -0
  7. data/TODO.md +74 -79
  8. data/lib/metric_fu.rb +8 -0
  9. data/lib/metric_fu/configuration.rb +8 -3
  10. data/lib/metric_fu/core_ext.rb +2 -0
  11. data/lib/metric_fu/core_ext/inflector/inflections.rb +214 -0
  12. data/lib/metric_fu/core_ext/inflector/methods.rb +153 -0
  13. data/lib/metric_fu/core_ext/object.rb +3 -0
  14. data/lib/metric_fu/core_ext/object/blank.rb +106 -0
  15. data/lib/metric_fu/core_ext/object/to_json.rb +12 -0
  16. data/lib/metric_fu/core_ext/string.rb +2 -0
  17. data/lib/metric_fu/core_ext/string/inflections.rb +195 -0
  18. data/lib/metric_fu/initial_requires.rb +0 -8
  19. data/lib/metric_fu/metrics/base_template.rb +28 -1
  20. data/lib/metric_fu/metrics/churn/churn.rb +2 -2
  21. data/lib/metric_fu/metrics/churn/template_awesome/churn.html.erb +8 -6
  22. data/lib/metric_fu/metrics/hotspots/analysis/code_issue.rb +6 -0
  23. data/lib/metric_fu/metrics/hotspots/init.rb +1 -0
  24. data/lib/metric_fu/reporting/templates/awesome/awesome_template.rb +37 -20
  25. data/lib/metric_fu/reporting/templates/awesome/css/bluff.css +15 -0
  26. data/lib/metric_fu/reporting/templates/awesome/css/default.css +0 -48
  27. data/lib/metric_fu/reporting/templates/awesome/css/rcov.css +32 -0
  28. data/lib/metric_fu/reporting/templates/awesome/index.html.erb +4 -32
  29. data/lib/metric_fu/reporting/templates/awesome/layout.html.erb +2 -0
  30. data/lib/metric_fu/version.rb +1 -1
  31. data/metric_fu.gemspec +23 -11
  32. data/spec/cli/helper_spec.rb +38 -28
  33. data/spec/metric_fu/configuration_spec.rb +35 -22
  34. data/spec/metric_fu/metrics/base_template_spec.rb +7 -7
  35. data/spec/metric_fu/metrics/churn/churn_spec.rb +9 -2
  36. data/spec/metric_fu/metrics/flog/flog_spec.rb +57 -55
  37. data/spec/metric_fu/metrics/hotspots/hotspot_analyzer_spec.rb +0 -2
  38. data/spec/run_spec.rb +0 -8
  39. data/spec/support/suite.rb +3 -1
  40. metadata +74 -125
  41. data/home_page/back_all.jpg +0 -0
  42. data/home_page/cc.rb.gif +0 -0
  43. data/home_page/churn.gif +0 -0
  44. data/home_page/cruise_control_1.gif +0 -0
  45. data/home_page/cyclomatic.gif +0 -0
  46. data/home_page/flay.gif +0 -0
  47. data/home_page/flog.gif +0 -0
  48. data/home_page/flog2.gif +0 -0
  49. data/home_page/footer.gif +0 -0
  50. data/home_page/header.jpg +0 -0
  51. data/home_page/hotspot.gif +0 -0
  52. data/home_page/img09.gif +0 -0
  53. data/home_page/index.html +0 -138
  54. data/home_page/rcov.gif +0 -0
  55. data/home_page/reek.gif +0 -0
  56. data/home_page/robots.txt +0 -5
  57. data/home_page/roodi.gif +0 -0
  58. data/home_page/saikuro.gif +0 -0
  59. data/home_page/stats.gif +0 -0
  60. data/home_page/styles.css +0 -245
  61. data/home_page/title.gif +0 -0
  62. data/home_page/title_back.gif +0 -0
  63. data/lib/metric_fu/metrics/cane/template_standard/cane.html.erb +0 -95
  64. data/lib/metric_fu/metrics/churn/template_standard/churn.html.erb +0 -31
  65. data/lib/metric_fu/metrics/flay/template_standard/flay.html.erb +0 -34
  66. data/lib/metric_fu/metrics/flog/template_standard/flog.html.erb +0 -57
  67. data/lib/metric_fu/metrics/hotspots/template_standard/hotspots.html.erb +0 -54
  68. data/lib/metric_fu/metrics/rails_best_practices/template_standard/rails_best_practices.html.erb +0 -29
  69. data/lib/metric_fu/metrics/rcov/template_standard/rcov.html.erb +0 -43
  70. data/lib/metric_fu/metrics/reek/template_standard/reek.html.erb +0 -42
  71. data/lib/metric_fu/metrics/roodi/template_standard/roodi.html.erb +0 -29
  72. data/lib/metric_fu/metrics/saikuro/template_standard/saikuro.html.erb +0 -84
  73. data/lib/metric_fu/metrics/stats/template_standard/stats.html.erb +0 -55
  74. data/lib/metric_fu/reporting/templates/standard/default.css +0 -64
  75. data/lib/metric_fu/reporting/templates/standard/index.html.erb +0 -44
  76. data/lib/metric_fu/reporting/templates/standard/standard_template.rb +0 -26
@@ -7,14 +7,6 @@ require 'rake'
7
7
  require 'yaml'
8
8
  require 'redcard'
9
9
 
10
- begin
11
- require 'active_support'
12
- require 'active_support/core_ext/object/to_json'
13
- require 'active_support/core_ext/object/blank'
14
- require 'active_support/inflector'
15
- rescue LoadError
16
- require 'activesupport' unless defined?(ActiveSupport)
17
- end
18
10
  MetricFu.configure
19
11
  MetricFu.logging_require { 'mf_debugger' }
20
12
  include MfDebugger
@@ -149,7 +149,7 @@ module MetricFu
149
149
 
150
150
  def file_url(name, line) # :nodoc:
151
151
  return '' unless name
152
- filename = File.expand_path(name.gsub(/^\//, ''))
152
+ filename = complete_file_path(name)
153
153
  link_prefix = MetricFu.configuration.link_prefix
154
154
  if link_prefix
155
155
  "#{link_prefix}/#{name.gsub(/:.*$/, '')}"
@@ -162,6 +162,13 @@ module MetricFu
162
162
  end
163
163
  end
164
164
 
165
+ def complete_file_path(filename)
166
+ File.expand_path(remove_leading_slash(filename))
167
+ end
168
+
169
+ def remove_leading_slash(filename)
170
+ filename.gsub(/^\//, '')
171
+ end
165
172
  def render_as_txmt_protocol? # :nodoc:
166
173
  config = MetricFu.configuration
167
174
  return false unless config.platform.include?('darwin')
@@ -191,6 +198,26 @@ module MetricFu
191
198
  return first_value if iteration % 2 == 0
192
199
  return second_value
193
200
  end
201
+
202
+ # available in the erb template
203
+ # as it's processed in the context of
204
+ # the binding of this class
205
+ def metric_links
206
+ @metrics.keys.map {|metric| metric_link(metric.to_s) }
207
+ end
208
+
209
+ def metric_link(metric)
210
+ <<-LINK
211
+ <a href="#{metric}.html">
212
+ #{snake_case_to_title_case(metric)}
213
+ </a>
214
+ LINK
215
+ end
216
+
217
+ def snake_case_to_title_case(string)
218
+ string.split('_').collect{|word| word[0] = word[0..0].upcase; word}.join(" ")
219
+ end
220
+
194
221
  # belive me, I tried to meta program this with an inherited hook
195
222
  # I couldn't get it working
196
223
  def template_directory
@@ -7,8 +7,8 @@ module MetricFu
7
7
  end
8
8
 
9
9
  def analyze
10
- if @output.match(/Churning requires a subversion or git repo/)
11
- @churn = [:churn => {}]
10
+ if @output.nil? || @output.match(/Churning requires.*git/)
11
+ @churn = {:churn => {}}
12
12
  else
13
13
  @churn = YAML::load(@output)
14
14
  end
@@ -8,12 +8,14 @@
8
8
  <th>Times Changed</th>
9
9
  </tr>
10
10
  <% count = 0 %>
11
- <% @churn[:changes].each do |change| %>
12
- <tr>
13
- <td><%= link_to_filename(change[:file_path]) %></td>
14
- <td><%= change[:times_changed] %></td>
15
- </tr>
16
- <% count += 1 %>
11
+ <% if @churn[:changes] %>
12
+ <% @churn[:changes].each do |change| %>
13
+ <tr>
14
+ <td><%= link_to_filename(change[:file_path]) %></td>
15
+ <td><%= change[:times_changed] %></td>
16
+ </tr>
17
+ <% count += 1 %>
18
+ <% end %>
17
19
  <% end %>
18
20
  </table>
19
21
 
@@ -1,5 +1,8 @@
1
+ # TODO determine if this file should be deleted
2
+ # it doesn't appear to be used anywhere
1
3
  require 'delegate'
2
4
 
5
+ # TODO remove explicit metric analyzer loading
3
6
  [ 'hotspots/hotspot_analyzer',
4
7
  'flog/flog_hotspot',
5
8
  'saikuro/saikuro_hotspot',
@@ -8,6 +11,7 @@ require 'delegate'
8
11
  'flay/flay_hotspot'].each do |path|
9
12
  MetricFu.metrics_require { path }
10
13
  end
14
+ # TODO determine if the careful_array is needed
11
15
  %w(careful_array).each do |path|
12
16
  MetricFu.data_structures_require { path }
13
17
  end
@@ -18,6 +22,7 @@ module MetricFu
18
22
  include Comparable
19
23
 
20
24
  # TODO: Yuck! 'stat_value' is a column for StatHotspot
25
+ # TODO remove explicit metric references
21
26
  EXCLUDED_COLUMNS =
22
27
  FlogHotspot::COLUMNS +
23
28
  SaikuroHotspot::COLUMNS +
@@ -75,6 +80,7 @@ module MetricFu
75
80
  return nil
76
81
  end
77
82
 
83
+ # TODO remove explicit metric references
78
84
  def modifies?(other)
79
85
  case self.metric
80
86
  when :reek
@@ -1,3 +1,4 @@
1
+ # TODO remove explicit Churn dependency
1
2
  MetricFu::Configuration.run do |config|
2
3
  config.add_metric(:hotspots)
3
4
  config.configure_metric(:hotspots,
@@ -14,10 +14,13 @@ class AwesomeTemplate < MetricFu::Template
14
14
  FileUtils.copy(f, File.join(MetricFu.output_directory, File.basename(f)))
15
15
  end
16
16
 
17
+ @metrics = {}
17
18
  report.each_pair do |section, contents|
18
19
  if template_exists?(section)
19
20
  create_instance_var(section, contents)
21
+ @metrics[section] = contents
20
22
  create_instance_var(:per_file_data, per_file_data)
23
+ mf_debug "Generating html for section #{section} with #{template(section)} for report #{report.class}"
21
24
  @html = erbify(section)
22
25
  html = erbify('layout')
23
26
  fn = output_filename(section)
@@ -40,22 +43,25 @@ class AwesomeTemplate < MetricFu::Template
40
43
  write_file_data
41
44
  end
42
45
 
43
- def convert_ruby_to_html(ruby_text)
44
- # convertor = Syntax::Convertors::HTML.for_syntax('ruby')
45
- # convertor.convert(ruby_text)
46
+ def convert_ruby_to_html(ruby_text, line_number)
46
47
  tokens = CodeRay.scan(ruby_text, :ruby)
47
- tokens.div( :line_numbers => :table, :css => :class, :style => :alpha )
48
+ options = { :css => :class, :style => :alpha }
49
+ if line_number.to_i > 0
50
+ options = options.merge({:line_numbers => :inline, :line_number_start => line_number.to_i })
51
+ end
52
+ tokens.div(options)
53
+ # CodeRay options
54
+ # used to analyze source code, because object Tokens is a list of tokens with specified types.
48
55
  # :tab_width – tabulation width in spaces. Default: 8
49
- # :css – how to include the styles (:class и :style). Default: :class)
50
- #
51
- # :wrap – wrap result in html tag :page, :div, :span or not to wrap (nil)
52
- #
53
- # :line_numbers – how render line numbers (:table, :inline, :list or nil)
54
- #
55
- # :line_number_start – first line number
56
- #
57
- # :bold_every – make every n-th line number bold. Default: 10
58
- # CodeRay, as Syntax may be used to analyze source code, because object Tokens is a list of tokens with specified types.
56
+ # :css – how to include the styles (:class и :style). Default: :class)
57
+ #
58
+ # :wrap – wrap result in html tag :page, :div, :span or not to wrap (nil)
59
+ #
60
+ # :line_numbers – how render line numbers (:table, :inline, :list or nil)
61
+ #
62
+ # :line_number_start – first line number
63
+ #
64
+ # :bold_every – make every n-th line number bold. Default: 10
59
65
  end
60
66
  def write_file_data
61
67
 
@@ -63,14 +69,21 @@ class AwesomeTemplate < MetricFu::Template
63
69
  data = File.open(file, 'r').readlines
64
70
  fn = "#{file.gsub(%r{/}, '_')}.html"
65
71
 
66
- out = "<html><head><style>#{inline_css('css/syntax.css')}</style></head><body>"
72
+ out = <<-HTML
73
+ <html><head><style>
74
+ #{inline_css('css/syntax.css')}
75
+ #{inline_css('css/bluff.css') if MetricFu.configuration.graph_engine == :bluff}
76
+ #{inline_css('css/rcov.css') if @metrics.has_key?(:rcov)}
77
+ </style></head><body>
78
+ HTML
67
79
  out << "<table cellpadding='0' cellspacing='0' class='ruby'>"
68
80
  data.each_with_index do |line, idx|
69
- out << "<tr><td valign='top'><small>#{idx + 1}</small></td>"
81
+ line_number = (idx + 1).to_s
82
+ out << "<tr>"
70
83
  out << "<td valign='top'>"
71
- if lines.has_key?((idx + 1).to_s)
84
+ if lines.has_key?(line_number)
72
85
  out << "<ul>"
73
- lines[(idx + 1).to_s].each do |problem|
86
+ lines[line_number].each do |problem|
74
87
  out << "<li>#{problem[:description]} &raquo; #{problem[:type]}</li>"
75
88
  end
76
89
  out << "</ul>"
@@ -78,8 +91,12 @@ class AwesomeTemplate < MetricFu::Template
78
91
  out << "&nbsp;"
79
92
  end
80
93
  out << "</td>"
81
- line_for_display = MetricFu.configuration.syntax_highlighting ? convert_ruby_to_html(line) : line
82
- out << "<td valign='top'><a name='line#{idx + 1}'>#{line_for_display}</a></td>"
94
+ if MetricFu.configuration.syntax_highlighting
95
+ line_for_display = convert_ruby_to_html(line, line_number)
96
+ else
97
+ line_for_display = "<a name='n#{line_number}' href='n#{line_number}'>#{line_number}</a>#{line}"
98
+ end
99
+ out << "<td valign='top'>#{line_for_display}</td>"
83
100
  out << "</tr>"
84
101
  end
85
102
  out << "<table></body></html>"
@@ -0,0 +1,15 @@
1
+ .bluff-tooltip {
2
+ background: #fff;
3
+ border: 1px solid #d1edf5;
4
+ padding: 8px 8px 6px;
5
+ }
6
+ .bluff-tooltip .color {
7
+ display: block;
8
+ height: 4px;
9
+ width: 30px;
10
+ margin: 0 0 4px;
11
+ overflow: hidden;
12
+ }
13
+ .bluff-tooltip .data {
14
+ font-weight: bold;
15
+ }
@@ -41,51 +41,3 @@ table td.score {
41
41
  .warning {
42
42
  background: yellow;
43
43
  }
44
- .rcov_code td {
45
- border-bottom: 1px solid #ddd ;
46
- padding: 0;
47
- margin: 0;
48
- }
49
- .rcov_code tr {
50
- border: 0px;
51
- padding:0px;
52
- margin: 0px;
53
- }
54
- .rcov_code pre {
55
- border: 0px;
56
- padding: 0px;
57
- margin: 0px;
58
- }
59
- .rcov_run {}
60
- .rcov_not_run {
61
- background-color: #d88;
62
- }
63
- .rcov_run a, .rcov_not_run a {
64
- text-decoration: none;
65
- }
66
- .rcov_run a {
67
- color: #333;
68
- }
69
- .rcov_not_run a {
70
- color: #000;
71
- }
72
- .rcov_overflow {
73
- overflow: auto;
74
- font-size: 50%;
75
- }
76
-
77
- .bluff-tooltip {
78
- background: #fff;
79
- border: 1px solid #d1edf5;
80
- padding: 8px 8px 6px;
81
- }
82
- .bluff-tooltip .color {
83
- display: block;
84
- height: 4px;
85
- width: 30px;
86
- margin: 0 0 4px;
87
- overflow: hidden;
88
- }
89
- .bluff-tooltip .data {
90
- font-weight: bold;
91
- }
@@ -0,0 +1,32 @@
1
+ .rcov_code td {
2
+ border-bottom: 1px solid #ddd ;
3
+ padding: 0;
4
+ margin: 0;
5
+ }
6
+ .rcov_code tr {
7
+ border: 0px;
8
+ padding:0px;
9
+ margin: 0px;
10
+ }
11
+ .rcov_code pre {
12
+ border: 0px;
13
+ padding: 0px;
14
+ margin: 0px;
15
+ }
16
+ .rcov_run {}
17
+ .rcov_not_run {
18
+ background-color: #d88;
19
+ }
20
+ .rcov_run a, .rcov_not_run a {
21
+ text-decoration: none;
22
+ }
23
+ .rcov_run a {
24
+ color: #333;
25
+ }
26
+ .rcov_not_run a {
27
+ color: #000;
28
+ }
29
+ .rcov_overflow {
30
+ overflow: auto;
31
+ font-size: 50%;
32
+ }
@@ -1,37 +1,9 @@
1
1
  <h3>Metric Fu Results</h3>
2
2
  <ul id='projects'>
3
- <% if @churn %>
4
- <li class='even failure'><a href="churn.html">Churn</a></li>
5
- <% end %>
6
- <% if @flay %>
7
- <li class='even failure'><a href="flay.html">Flay</a></li>
8
- <% end %>
9
- <% if @flog %>
10
- <li class='even failure'><a href="flog.html">Flog</a></li>
11
- <% end %>
12
- <% if @rcov %>
13
- <li class='even failure'><a href="rcov.html">Rcov</a></li>
14
- <% end %>
15
- <% if @reek %>
16
- <li class='even failure'><a href="reek.html">Reek</a></li>
17
- <% end %>
18
- <% if @roodi %>
19
- <li class='even failure'><a href="roodi.html">Roodi</a></li>
20
- <% end %>
21
- <% if @saikuro %>
22
- <li class='even failure'><a href="saikuro.html">Saikuro</a></li>
23
- <% end %>
24
- <% if @cane %>
25
- <li class='even failure'><a href="cane.html">Cane</a></li>
26
- <% end %>
27
- <% if @stats %>
28
- <li class='even failure'><a href="stats.html">Stats</a></li>
29
- <% end %>
30
- <% if @rails_best_practices %>
31
- <li class='even failure'><a href="rails_best_practices.html">Rails Best Practices report</a></li>
32
- <% end %>
33
- <% if @hotspots %>
34
- <li class='even failure'><a href="hotspots.html">Hotspots</a></li>
3
+ <% metric_links.each do |link| %>
4
+ <li class='even failure'>
5
+ <%= link %>
6
+ </li>
35
7
  <% end %>
36
8
  </ul>
37
9
  <p>Generated on <%= Time.now.localtime %></p>
@@ -9,6 +9,8 @@
9
9
  <%= inline_css("css/buttons.css") %>
10
10
  <%= inline_css("css/integrity.css") %>
11
11
  <%= inline_css("css/default.css") %>
12
+ <%= inline_css('css/bluff.css') if MetricFu.configuration.graph_engine == :bluff %>
13
+ <%= inline_css('css/rcov.css') if @metrics.has_key?(:rcov) %>
12
14
  </style>
13
15
  <link REL="SHORTCUT ICON" HREF="/favicon.ico">
14
16
  <script language="javascript" src="js-class.js" type="text/javascript"></script>
@@ -1,3 +1,3 @@
1
1
  module MetricFu
2
- VERSION = "4.1.2"
2
+ VERSION = "4.1.3"
3
3
  end
data/metric_fu.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.version = MetricFu::VERSION
10
10
  s.summary = "A fistful of code metrics, with awesome templates and graphs"
11
11
  s.email = "github@benjaminfleischer.com"
12
- s.homepage = "http://github.com/metricfu/metric_fu"
12
+ s.homepage = "https://github.com/metricfu/metric_fu"
13
13
  s.description = "Code metrics from Flog, Flay, Saikuro, Churn, Reek, Roodi, Rails' stats task and Rails Best Practices, and optionally RCov"
14
14
  s.authors = ["Jake Scruggs", "Sean Soper", "Andre Arko", "Petrik de Heus", "Grant McInnes", "Nick Quaranto", "Édouard Brière", "Carl Youngblood", "Richard Huang", "Dan Mayer", "Benjamin Fleischer"]
15
15
  s.rubyforge_project = 'metric_fu'
@@ -17,32 +17,44 @@ Gem::Specification.new do |s|
17
17
  s.required_rubygems_version = ">= 1.3.6"
18
18
  s.files = `git ls-files`.split($\)
19
19
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
20
+ s.default_executable = %q{metric_fu}
20
21
  s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
21
22
  s.require_paths = ["lib"]
22
23
  s.license = 'MIT'
24
+ s.has_rdoc = true
25
+ s.extra_rdoc_files = ["HISTORY.md", "CONTRIBUTING.md", "TODO.md", "MIT-LICENSE"]
26
+ s.rdoc_options = ["--main", "README.md"]
23
27
 
24
28
  {
25
- "rails_best_practices" => MetricFu::MetricVersion.rails_best_practices,
26
- "japgolly-Saikuro" => MetricFu::MetricVersion.saikuro,
27
- "metric_fu-roodi" => MetricFu::MetricVersion.roodi,
29
+ # metric dependencies
28
30
  "flay" => MetricFu::MetricVersion.flay,
31
+ "churn" => MetricFu::MetricVersion.churn,
29
32
  "flog" => MetricFu::MetricVersion.flog,
30
33
  "reek" => MetricFu::MetricVersion.reek,
31
- "churn" => MetricFu::MetricVersion.churn,
32
34
  "cane" => MetricFu::MetricVersion.cane,
33
- # specifying dependencies for f, r, ch, f, and cane
35
+ # specifying gem dependencies for
36
+ # flay, churn, flog, reek, and cane
34
37
  "ruby_parser" => MetricFu::MetricVersion.ruby_parser,
35
38
  "sexp_processor" => MetricFu::MetricVersion.sexp_processor,
39
+ # reek
36
40
  "ruby2ruby" => MetricFu::MetricVersion.ruby2ruby,
41
+ # cane
37
42
  "parallel" => MetricFu::MetricVersion.parallel,
38
- "activesupport" => [">= 2.0.0"], # ok
43
+ # required by main, a churn dependency
44
+ "fattr" => ["= 2.2.1"],
45
+ "arrayfields" => ["= 4.7.4"],
46
+ "map" => ["= 6.2.0"],
47
+ "rails_best_practices" => MetricFu::MetricVersion.rails_best_practices,
48
+ "japgolly-Saikuro" => MetricFu::MetricVersion.saikuro,
49
+ "metric_fu-roodi" => MetricFu::MetricVersion.roodi,
50
+ #
51
+ # other dependencies
52
+ # ruby version identification
39
53
  'redcard' => [],
54
+ # syntax highlighting
40
55
  "coderay" => [],
41
- "fattr" => ["= 2.2.1"],
42
- "arrayfields" => ["= 4.7.4"],
43
- "map" => ["= 6.2.0"],
56
+ # default graphing libraries
44
57
  "bluff" => [],
45
- "googlecharts" => []
46
58
  }.each do |gem, version|
47
59
  if version == []
48
60
  s.add_runtime_dependency(gem)