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.
Files changed (188) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.rubocop.yml +15 -0
  5. data/.rubocop_todo.yml +69 -0
  6. data/.travis.yml +0 -1
  7. data/CONTRIBUTORS +1 -1
  8. data/Gemfile +23 -20
  9. data/Guardfile +9 -9
  10. data/HISTORY.md +10 -1
  11. data/checksum/metric_fu-4.11.3.gem.sha512 +1 -0
  12. data/config/rubocop.yml +269 -0
  13. data/gem_tasks/rubocop.rake +10 -0
  14. data/lib/metric_fu.rb +11 -9
  15. data/lib/metric_fu/calculate.rb +0 -1
  16. data/lib/metric_fu/cli/client.rb +6 -6
  17. data/lib/metric_fu/cli/helper.rb +22 -13
  18. data/lib/metric_fu/cli/parser.rb +14 -18
  19. data/lib/metric_fu/configuration.rb +7 -11
  20. data/lib/metric_fu/constantize.rb +4 -4
  21. data/lib/metric_fu/data_structures/line_numbers.rb +10 -11
  22. data/lib/metric_fu/data_structures/location.rb +12 -14
  23. data/lib/metric_fu/data_structures/sexp_node.rb +31 -13
  24. data/lib/metric_fu/environment.rb +29 -31
  25. data/lib/metric_fu/formatter.rb +4 -6
  26. data/lib/metric_fu/formatter/html.rb +13 -13
  27. data/lib/metric_fu/formatter/syntax.rb +5 -7
  28. data/lib/metric_fu/formatter/yaml.rb +1 -1
  29. data/lib/metric_fu/gem_run.rb +13 -15
  30. data/lib/metric_fu/gem_version.rb +9 -11
  31. data/lib/metric_fu/generator.rb +5 -8
  32. data/lib/metric_fu/io.rb +13 -15
  33. data/lib/metric_fu/loader.rb +17 -18
  34. data/lib/metric_fu/logger.rb +15 -18
  35. data/lib/metric_fu/logging/mf_debugger.rb +4 -4
  36. data/lib/metric_fu/metric.rb +11 -12
  37. data/lib/metric_fu/metrics/cane/generator.rb +10 -9
  38. data/lib/metric_fu/metrics/cane/grapher.rb +5 -7
  39. data/lib/metric_fu/metrics/cane/metric.rb +6 -8
  40. data/lib/metric_fu/metrics/cane/report.html.erb +3 -3
  41. data/lib/metric_fu/metrics/cane/violations.rb +6 -6
  42. data/lib/metric_fu/metrics/churn/generator.rb +2 -6
  43. data/lib/metric_fu/metrics/churn/hotspot.rb +1 -3
  44. data/lib/metric_fu/metrics/churn/metric.rb +5 -7
  45. data/lib/metric_fu/metrics/flay/generator.rb +7 -11
  46. data/lib/metric_fu/metrics/flay/grapher.rb +5 -6
  47. data/lib/metric_fu/metrics/flay/hotspot.rb +5 -7
  48. data/lib/metric_fu/metrics/flay/metric.rb +5 -7
  49. data/lib/metric_fu/metrics/flog/generator.rb +22 -23
  50. data/lib/metric_fu/metrics/flog/grapher.rb +11 -11
  51. data/lib/metric_fu/metrics/flog/hotspot.rb +3 -5
  52. data/lib/metric_fu/metrics/flog/metric.rb +3 -5
  53. data/lib/metric_fu/metrics/hotspots/analysis/analyzed_problems.rb +0 -1
  54. data/lib/metric_fu/metrics/hotspots/analysis/analyzer_tables.rb +19 -18
  55. data/lib/metric_fu/metrics/hotspots/analysis/grouping.rb +0 -2
  56. data/lib/metric_fu/metrics/hotspots/analysis/groupings.rb +1 -3
  57. data/lib/metric_fu/metrics/hotspots/analysis/problems.rb +4 -6
  58. data/lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb +14 -9
  59. data/lib/metric_fu/metrics/hotspots/analysis/ranking.rb +4 -5
  60. data/lib/metric_fu/metrics/hotspots/analysis/rankings.rb +1 -3
  61. data/lib/metric_fu/metrics/hotspots/analysis/record.rb +3 -5
  62. data/lib/metric_fu/metrics/hotspots/analysis/scoring_strategies.rb +0 -2
  63. data/lib/metric_fu/metrics/hotspots/analysis/table.rb +3 -4
  64. data/lib/metric_fu/metrics/hotspots/generator.rb +3 -6
  65. data/lib/metric_fu/metrics/hotspots/hotspot.rb +13 -13
  66. data/lib/metric_fu/metrics/hotspots/hotspot_analyzer.rb +5 -8
  67. data/lib/metric_fu/metrics/hotspots/metric.rb +1 -3
  68. data/lib/metric_fu/metrics/hotspots/report.html.erb +1 -1
  69. data/lib/metric_fu/metrics/rails_best_practices/generator.rb +10 -12
  70. data/lib/metric_fu/metrics/rails_best_practices/grapher.rb +5 -6
  71. data/lib/metric_fu/metrics/rails_best_practices/metric.rb +1 -3
  72. data/lib/metric_fu/metrics/rcov/external_client.rb +1 -3
  73. data/lib/metric_fu/metrics/rcov/generator.rb +13 -15
  74. data/lib/metric_fu/metrics/rcov/grapher.rb +6 -7
  75. data/lib/metric_fu/metrics/rcov/hotspot.rb +5 -7
  76. data/lib/metric_fu/metrics/rcov/metric.rb +5 -7
  77. data/lib/metric_fu/metrics/rcov/rcov_format_coverage.rb +16 -55
  78. data/lib/metric_fu/metrics/rcov/rcov_line.rb +48 -0
  79. data/lib/metric_fu/metrics/rcov/report.html.erb +2 -2
  80. data/lib/metric_fu/metrics/rcov/simplecov_formatter.rb +10 -11
  81. data/lib/metric_fu/metrics/reek/generator.rb +22 -23
  82. data/lib/metric_fu/metrics/reek/grapher.rb +5 -6
  83. data/lib/metric_fu/metrics/reek/hotspot.rb +5 -7
  84. data/lib/metric_fu/metrics/reek/metric.rb +2 -4
  85. data/lib/metric_fu/metrics/roodi/generator.rb +9 -10
  86. data/lib/metric_fu/metrics/roodi/grapher.rb +5 -6
  87. data/lib/metric_fu/metrics/roodi/hotspot.rb +1 -3
  88. data/lib/metric_fu/metrics/roodi/metric.rb +2 -4
  89. data/lib/metric_fu/metrics/saikuro/generator.rb +23 -27
  90. data/lib/metric_fu/metrics/saikuro/hotspot.rb +1 -3
  91. data/lib/metric_fu/metrics/saikuro/metric.rb +7 -8
  92. data/lib/metric_fu/metrics/saikuro/parsing_element.rb +6 -8
  93. data/lib/metric_fu/metrics/saikuro/report.html.erb +1 -1
  94. data/lib/metric_fu/metrics/saikuro/scratch_file.rb +24 -29
  95. data/lib/metric_fu/metrics/stats/generator.rb +9 -12
  96. data/lib/metric_fu/metrics/stats/grapher.rb +8 -9
  97. data/lib/metric_fu/metrics/stats/hotspot.rb +1 -3
  98. data/lib/metric_fu/metrics/stats/metric.rb +3 -5
  99. data/lib/metric_fu/reporter.rb +1 -1
  100. data/lib/metric_fu/reporting/graphs/graph.rb +8 -12
  101. data/lib/metric_fu/reporting/graphs/grapher.rb +7 -9
  102. data/lib/metric_fu/reporting/result.rb +0 -3
  103. data/lib/metric_fu/run.rb +12 -3
  104. data/lib/metric_fu/tasks/metric_fu.rake +8 -8
  105. data/lib/metric_fu/templates/configuration.rb +2 -5
  106. data/lib/metric_fu/templates/metrics_template.rb +19 -19
  107. data/lib/metric_fu/templates/report.rb +5 -8
  108. data/lib/metric_fu/templates/template.rb +20 -24
  109. data/lib/metric_fu/utility.rb +7 -8
  110. data/lib/metric_fu/version.rb +1 -1
  111. data/metric_fu.gemspec +31 -32
  112. data/spec/cli/helper_spec.rb +7 -14
  113. data/spec/dummy/lib/bad_encoding.rb +1 -1
  114. data/spec/fixtures/coverage-153.rb +2 -2
  115. data/spec/fixtures/coverage.rb +2 -2
  116. data/spec/metric_fu/calculate_spec.rb +3 -3
  117. data/spec/metric_fu/configuration_spec.rb +70 -82
  118. data/spec/metric_fu/data_structures/line_numbers_spec.rb +3 -5
  119. data/spec/metric_fu/data_structures/location_spec.rb +13 -31
  120. data/spec/metric_fu/formatter/configuration_spec.rb +11 -13
  121. data/spec/metric_fu/formatter/html_spec.rb +21 -28
  122. data/spec/metric_fu/formatter/yaml_spec.rb +9 -17
  123. data/spec/metric_fu/formatter_spec.rb +6 -6
  124. data/spec/metric_fu/gem_version_spec.rb +3 -5
  125. data/spec/metric_fu/generator_spec.rb +28 -38
  126. data/spec/metric_fu/loader_spec.rb +1 -3
  127. data/spec/metric_fu/metric_spec.rb +17 -21
  128. data/spec/metric_fu/metrics/cane/configuration_spec.rb +8 -8
  129. data/spec/metric_fu/metrics/cane/generator_spec.rb +26 -29
  130. data/spec/metric_fu/metrics/churn/configuration_spec.rb +6 -8
  131. data/spec/metric_fu/metrics/churn/generator_spec.rb +6 -11
  132. data/spec/metric_fu/metrics/flay/configuration_spec.rb +6 -8
  133. data/spec/metric_fu/metrics/flay/generator_spec.rb +36 -37
  134. data/spec/metric_fu/metrics/flay/grapher_spec.rb +2 -2
  135. data/spec/metric_fu/metrics/flog/configuration_spec.rb +11 -13
  136. data/spec/metric_fu/metrics/flog/generator_spec.rb +29 -31
  137. data/spec/metric_fu/metrics/flog/grapher_spec.rb +8 -10
  138. data/spec/metric_fu/metrics/hotspots/analysis/analyzed_problems_spec.rb +18 -24
  139. data/spec/metric_fu/metrics/hotspots/analysis/analyzer_tables_spec.rb +12 -17
  140. data/spec/metric_fu/metrics/hotspots/analysis/ranking_spec.rb +2 -6
  141. data/spec/metric_fu/metrics/hotspots/analysis/rankings_spec.rb +5 -14
  142. data/spec/metric_fu/metrics/hotspots/analysis/table_spec.rb +1 -3
  143. data/spec/metric_fu/metrics/hotspots/generator_spec.rb +6 -8
  144. data/spec/metric_fu/metrics/hotspots/hotspot_analyzer_spec.rb +1 -3
  145. data/spec/metric_fu/metrics/hotspots/hotspot_spec.rb +4 -5
  146. data/spec/metric_fu/metrics/rails_best_practices/configuration_spec.rb +6 -10
  147. data/spec/metric_fu/metrics/rails_best_practices/generator_spec.rb +2 -3
  148. data/spec/metric_fu/metrics/rails_best_practices/grapher_spec.rb +3 -3
  149. data/spec/metric_fu/metrics/rcov/configuration_spec.rb +20 -22
  150. data/spec/metric_fu/metrics/rcov/generator_spec.rb +6 -10
  151. data/spec/metric_fu/metrics/rcov/grapher_spec.rb +2 -2
  152. data/spec/metric_fu/metrics/rcov/hotspot_spec.rb +8 -8
  153. data/spec/metric_fu/metrics/rcov/rcov_line_spec.rb +89 -0
  154. data/spec/metric_fu/metrics/rcov/simplecov_formatter_spec.rb +31 -33
  155. data/spec/metric_fu/metrics/reek/configuration_spec.rb +6 -6
  156. data/spec/metric_fu/metrics/reek/generator_spec.rb +19 -20
  157. data/spec/metric_fu/metrics/reek/grapher_spec.rb +4 -4
  158. data/spec/metric_fu/metrics/roodi/configuration_spec.rb +7 -9
  159. data/spec/metric_fu/metrics/roodi/generator_spec.rb +3 -3
  160. data/spec/metric_fu/metrics/roodi/grapher_spec.rb +2 -2
  161. data/spec/metric_fu/metrics/saikuro/configuration_spec.rb +18 -19
  162. data/spec/metric_fu/metrics/saikuro/generator_spec.rb +7 -7
  163. data/spec/metric_fu/metrics/stats/generator_spec.rb +9 -9
  164. data/spec/metric_fu/metrics/stats/grapher_spec.rb +2 -2
  165. data/spec/metric_fu/reporter_spec.rb +3 -4
  166. data/spec/metric_fu/reporting/graphs/graph_spec.rb +1 -4
  167. data/spec/metric_fu/reporting/graphs/grapher_spec.rb +5 -5
  168. data/spec/metric_fu/reporting/result_spec.rb +9 -11
  169. data/spec/metric_fu/run_spec.rb +18 -32
  170. data/spec/metric_fu/templates/configuration_spec.rb +28 -34
  171. data/spec/metric_fu/templates/metrics_template_spec.rb +11 -0
  172. data/spec/metric_fu/templates/report_spec.rb +4 -4
  173. data/spec/metric_fu/templates/template_spec.rb +62 -48
  174. data/spec/metric_fu/utility_spec.rb +2 -2
  175. data/spec/metric_fu_spec.rb +5 -7
  176. data/spec/shared/configured.rb +9 -11
  177. data/spec/shared/test_coverage.rb +5 -9
  178. data/spec/spec_helper.rb +9 -9
  179. data/spec/support/deferred_garbaged_collection.rb +1 -2
  180. data/spec/support/matcher_create_file.rb +2 -4
  181. data/spec/support/matcher_create_files.rb +2 -4
  182. data/spec/support/suite.rb +3 -3
  183. data/spec/support/test_fixtures.rb +5 -7
  184. data/spec/support/timeout.rb +1 -1
  185. data/spec/support/usage_test.rb +23 -24
  186. data/spec/usage_test_spec.rb +18 -20
  187. metadata +12 -2
  188. metadata.gz.sig +0 -0
@@ -0,0 +1,10 @@
1
+ if ENV["FULL_BUILD"] != "true" # skip on Travis
2
+ require "rubocop/rake_task"
3
+ RuboCop::RakeTask.new(:rubocop) do |task|
4
+ task.patterns = ["lib", "spec"]
5
+ task.formatters = ["progress"]
6
+ task.options = ["--display-cop-names"]
7
+ task.fail_on_error = false
8
+ task.verbose = false
9
+ end
10
+ end
@@ -1,10 +1,10 @@
1
1
  # coding: utf-8
2
- require 'metric_fu/version'
3
- require 'forwardable'
4
- require 'pathname'
2
+ require "metric_fu/version"
3
+ require "forwardable"
4
+ require "pathname"
5
5
  module MetricFu
6
- APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__),'..'))
7
- LIB_ROOT = File.join(APP_ROOT,'lib/metric_fu')
6
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), ".."))
7
+ LIB_ROOT = File.join(APP_ROOT, "lib/metric_fu")
8
8
 
9
9
  module_function
10
10
 
@@ -13,11 +13,11 @@ module MetricFu
13
13
  end
14
14
 
15
15
  def metric_url
16
- 'https://github.com/metricfu/metric_fu'
16
+ "https://github.com/metricfu/metric_fu"
17
17
  end
18
18
 
19
19
  def metric_name
20
- 'MetricFu'
20
+ "MetricFu"
21
21
  end
22
22
 
23
23
  def run_dir
@@ -71,11 +71,12 @@ module MetricFu
71
71
  def root_dir
72
72
  APP_ROOT
73
73
  end
74
+
74
75
  def lib_dir
75
76
  LIB_ROOT
76
77
  end
77
78
 
78
- require 'metric_fu/loader'
79
+ require "metric_fu/loader"
79
80
  LOADER = MetricFu::Loader.new(LIB_ROOT)
80
81
  def loader
81
82
  LOADER
@@ -94,7 +95,7 @@ module MetricFu
94
95
 
95
96
  # @note artifact_dir is relative to where the task is being run,
96
97
  # not to the metric_fu library
97
- require 'metric_fu/io'
98
+ require "metric_fu/io"
98
99
  def artifact_dir
99
100
  MetricFu::Io::FileSystem.artifact_dir
100
101
  end
@@ -121,6 +122,7 @@ module MetricFu
121
122
  def run(options)
122
123
  MetricFu::Run.new.run(options)
123
124
  end
125
+
124
126
  def run_only(metrics_to_run_names, options)
125
127
  metrics_to_run_names = Array(metrics_to_run_names).map(&:to_s)
126
128
  MetricFu::Configuration.run do |config|
@@ -6,6 +6,5 @@ module MetricFu
6
6
  return 0 if total.zero?
7
7
  (Float(num) / Float(total) * 100).round
8
8
  end
9
-
10
9
  end
11
10
  end
@@ -1,17 +1,18 @@
1
- require 'metric_fu'
2
- require 'metric_fu/cli/helper'
3
- require 'metric_fu/cli/parser'
1
+ require "metric_fu"
2
+ require "metric_fu/cli/helper"
3
+ require "metric_fu/cli/parser"
4
4
  module MetricFu
5
5
  module Cli
6
6
  class Client
7
-
8
7
  def initialize
9
8
  @helper = MetricFu::Cli::Helper.new
10
9
  end
10
+
11
11
  def shutdown
12
12
  @helper.shutdown
13
13
  end
14
- def run(argv=ARGV.dup)
14
+
15
+ def run(argv = ARGV.dup)
15
16
  options = @helper.process_options(argv)
16
17
  mf_debug "Got options #{options.inspect}"
17
18
  if options[:run]
@@ -20,7 +21,6 @@ module MetricFu
20
21
  STDOUT.puts @helper.usage
21
22
  end
22
23
  end
23
-
24
24
  end
25
25
  end
26
26
  end
@@ -1,6 +1,6 @@
1
- require 'metric_fu'
2
- require 'metric_fu/cli/parser'
3
- MetricFu.lib_require { 'run' }
1
+ require "metric_fu"
2
+ require "metric_fu/cli/parser"
3
+ MetricFu.lib_require { "run" }
4
4
  # see https://github.com/grosser/pru/blob/master/bin/pru
5
5
  module MetricFu
6
6
  module Cli
@@ -14,54 +14,63 @@ module MetricFu
14
14
  def initialize
15
15
  @metric_fu = MetricFu::Run.new
16
16
  end
17
- def run(options={})
17
+
18
+ def run(options = {})
18
19
  @metric_fu.run(options)
19
20
  complete
20
21
  end
22
+
21
23
  def version
22
24
  MetricFu::VERSION
23
25
  end
26
+
24
27
  def shutdown
25
28
  out "\nShutting down. Bye"
26
29
  MetricFu::Cli.immediate_shutdown!
27
30
  end
31
+
28
32
  def banner
29
33
  "MetricFu: A Fistful of code metrics"
30
34
  end
35
+
31
36
  def usage
32
37
  <<-EOS
33
38
  #{banner}
34
39
  Use --help for help
35
40
  EOS
36
41
  end
42
+
37
43
  def executable_name
38
- 'metric_fu'
44
+ "metric_fu"
39
45
  end
40
46
 
41
47
  def metrics
42
48
  MetricFu::Metric.metrics.map(&:name).sort_by(&:to_s)
43
49
  end
44
50
 
45
- def process_options(argv=[])
51
+ def process_options(argv = [])
46
52
  options = MetricFu::Cli::MicroOptParse::Parser.new do |p|
47
- p.banner = self.banner
48
- p.version = self.version
49
- p.option :run, "Run all metrics with defaults", :default => true
50
- metrics.each do |metric|
51
- p.option metric.to_sym, "Enables or disables #{metric.to_s}", :default => true #, :value_in_set => [true, false]
52
- end
53
- p.option :open, "Open report in browser (if supported by formatter)", :default => true
53
+ p.banner = banner
54
+ p.version = version
55
+ p.option :run, "Run all metrics with defaults", default: true
56
+ metrics.each do |metric|
57
+ p.option metric.to_sym, "Enables or disables #{metric}", default: true # , :value_in_set => [true, false]
58
+ end
59
+ p.option :open, "Open report in browser (if supported by formatter)", default: true
54
60
  end.process!(argv)
55
61
  options
56
62
  end
57
63
 
58
64
  private
65
+
59
66
  def out(text)
60
67
  STDOUT.puts text
61
68
  end
69
+
62
70
  def error(text)
63
71
  STDERR.puts text
64
72
  end
73
+
65
74
  def complete
66
75
  out "all done"
67
76
  MetricFu::Cli.complete!
@@ -1,4 +1,4 @@
1
- require 'optparse'
1
+ require "optparse"
2
2
  module MetricFu
3
3
  module Cli
4
4
  # see https://github.com/florianpilz/CLI-Option-Parser-Examples
@@ -22,7 +22,6 @@ module MetricFu
22
22
  @options << [name, desc, settings]
23
23
  end
24
24
 
25
-
26
25
  private
27
26
 
28
27
  def build_option_parser
@@ -51,9 +50,9 @@ module MetricFu
51
50
  add_output_option(p)
52
51
 
53
52
  p.banner = @banner unless @banner.nil?
54
- p.on_tail("-h", "--help", "Show this message") {puts p ; success!}
53
+ p.on_tail("-h", "--help", "Show this message") { puts p; success! }
55
54
  short = @used_short.include?("v") ? "-V" : "-v"
56
- p.on_tail(short, "--version", "Print version") {puts @version ; success!} unless @version.nil?
55
+ p.on_tail(short, "--version", "Print version") { puts @version; success! } unless @version.nil?
57
56
  p.on_tail("--debug-info", "Print debug info") { debug_info; success! }
58
57
  @default_values = @result.clone # save default values to reset @result in subsequent calls
59
58
  end
@@ -70,21 +69,21 @@ module MetricFu
70
69
  klass = o[2][:default].class == Fixnum ? Integer : o[2][:default].class
71
70
 
72
71
  if [TrueClass, FalseClass, NilClass].include?(klass) # boolean switch
73
- p.on("-" << short, "--[no-]" << o[0].to_s.gsub("_", "-"), o[1]) {|x| @result[o[0]] = x}
72
+ p.on("-" << short, "--[no-]" << o[0].to_s.gsub("_", "-"), o[1]) { |x| @result[o[0]] = x }
74
73
  else # argument with parameter
75
- p.on("-" << short, "--" << o[0].to_s.gsub("_", "-") << " " << o[2][:default].to_s, klass, o[1]) {|x| @result[o[0]] = x}
74
+ p.on("-" << short, "--" << o[0].to_s.gsub("_", "-") << " " << o[2][:default].to_s, klass, o[1]) { |x| @result[o[0]] = x }
76
75
  end
77
76
  end
78
77
 
79
78
  def add_output_option(p)
80
79
  p.on("--out FILE|DIR",
81
- "Specify the file or directory to use for output",
82
- "This option applies to the previously",
83
- "specified --format, or the default format",
84
- "if no format is specified. Paths are relative to",
85
- "#{MetricFu.run_path.join(MetricFu::Io::FileSystem.directory('base_directory'))}",
86
- "Check the specific formatter\'s docs to see",
87
- "whether to pass a file or a dir.") do |o|
80
+ "Specify the file or directory to use for output",
81
+ "This option applies to the previously",
82
+ "specified --format, or the default format",
83
+ "if no format is specified. Paths are relative to",
84
+ "#{MetricFu.run_path.join(MetricFu::Io::FileSystem.directory('base_directory'))}",
85
+ "Check the specific formatter\'s docs to see",
86
+ "whether to pass a file or a dir.") do |o|
88
87
  @result[:format] ||= MetricFu::Formatter::DEFAULT
89
88
  @result[:format].last << o
90
89
  end
@@ -111,7 +110,7 @@ module MetricFu
111
110
 
112
111
  def debug_info
113
112
  extend(MetricFu::Environment)
114
- require 'pp'
113
+ require "pp"
115
114
  pp debug_info
116
115
  end
117
116
 
@@ -124,7 +123,7 @@ module MetricFu
124
123
  # " <key> : <description>."
125
124
  def format_descriptions
126
125
  formats = MetricFu::Formatter::BUILTIN_FORMATS
127
- max = formats.keys.map{|s| s.length}.max
126
+ max = formats.keys.map(&:length).max
128
127
  formats.keys.sort.map do |key|
129
128
  " #{key}#{' ' * (max - key.length)} : #{formats[key][1]}"
130
129
  end
@@ -133,10 +132,7 @@ module MetricFu
133
132
  def success!
134
133
  MetricFu::Cli.complete!
135
134
  end
136
-
137
-
138
135
  end
139
136
  end
140
-
141
137
  end
142
138
  end
@@ -1,6 +1,5 @@
1
- MetricFu.lib_require { 'logger' }
1
+ MetricFu.lib_require { "logger" }
2
2
  module MetricFu
3
-
4
3
  # Even though the below class methods are defined on the MetricFu module
5
4
  # They are included here as they deal with configuration
6
5
 
@@ -12,9 +11,7 @@ module MetricFu
12
11
  end
13
12
 
14
13
  def self.configure
15
- configuration.tap do |config|
16
- config.configure_metrics
17
- end
14
+ configuration.tap(&:configure_metrics)
18
15
  end
19
16
 
20
17
  # = Configuration
@@ -51,10 +48,10 @@ module MetricFu
51
48
  # config.configure_formatter(MyCustomFormatter)
52
49
  #
53
50
  class Configuration
54
- require_relative 'environment'
55
- require_relative 'io'
56
- require_relative 'formatter'
57
- require_relative 'templates/configuration'
51
+ require_relative "environment"
52
+ require_relative "io"
53
+ require_relative "formatter"
54
+ require_relative "templates/configuration"
58
55
 
59
56
  # TODO: Remove need to include the module
60
57
  include MetricFu::Environment
@@ -122,7 +119,7 @@ module MetricFu
122
119
  # @return [Array<Symbol>] names of enabled metrics with graphs
123
120
  def graphed_metrics
124
121
  # TODO: This is a common enough need to be pushed into MetricFu::Metric as :enabled_metrics_with_graphs
125
- MetricFu::Metric.enabled_metrics.select{|metric|metric.has_graph?}.map(&:name)
122
+ MetricFu::Metric.enabled_metrics.select(&:has_graph?).map(&:name)
126
123
  end
127
124
 
128
125
  def configure_graph_engine(graph_engine)
@@ -149,6 +146,5 @@ module MetricFu
149
146
  def templates_option(option)
150
147
  @templates_configuration.option(option)
151
148
  end
152
-
153
149
  end
154
150
  end
@@ -4,7 +4,7 @@ module MetricFu
4
4
  # https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflector/methods.rb#L220
5
5
  def constantize(camel_cased_word)
6
6
  tries ||= 2
7
- names = camel_cased_word.split('::')
7
+ names = camel_cased_word.split("::")
8
8
  names.shift if names.empty? || names.first.empty?
9
9
 
10
10
  names.inject(Object) do |constant, name|
@@ -46,9 +46,9 @@ module MetricFu
46
46
  # https://github.com/rails/rails/blob/51cd6bb829c418c5fbf75de1dfbb177233b1b154/activesupport/lib/active_support/inflector/methods.rb#L88
47
47
  def underscore(camel_cased_word)
48
48
  word = camel_cased_word.to_s.dup
49
- word.gsub!(/::/, '/')
50
- word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
51
- word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
49
+ word.gsub!(/::/, "/")
50
+ word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
51
+ word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
52
52
  word.tr!("-", "_")
53
53
  word.downcase!
54
54
  word
@@ -1,4 +1,4 @@
1
- MetricFu.data_structures_require { 'sexp_node' }
1
+ MetricFu.data_structures_require { "sexp_node" }
2
2
  module MetricFu
3
3
  class LineNumbers
4
4
  attr_reader :file_path
@@ -7,7 +7,7 @@ module MetricFu
7
7
  # Used by metrics that don't provide line numbers for class, module, or methods problems
8
8
  # @param contents [String] a string of ruby code
9
9
  # @param file_path [String] the file path for the contents, defaults to empty string
10
- def initialize(contents,file_path='')
10
+ def initialize(contents, file_path = "")
11
11
  @file_path = file_path
12
12
  @locations = {}
13
13
  if contents.to_s.size.zero?
@@ -30,8 +30,8 @@ module MetricFu
30
30
  # If a location is found, return the method name (first element)
31
31
  # Else return :no_method_at_line
32
32
  def method_at_line(line_number)
33
- default_proc = ->{ [:no_method_at_line] }
34
- @locations.detect(default_proc) do |method_name, line_number_range|
33
+ default_proc = -> { [:no_method_at_line] }
34
+ @locations.detect(default_proc) do |_method_name, line_number_range|
35
35
  line_number_range.include?(line_number)
36
36
  end.first
37
37
  end
@@ -49,7 +49,7 @@ module MetricFu
49
49
  file_sexp = MetricFu::SexpNode.parse(contents)
50
50
  file_sexp && process_ast(file_sexp)
51
51
  rescue => e
52
- #catch errors for files ruby_parser fails on
52
+ # catch errors for files ruby_parser fails on
53
53
  mf_log "RUBY PARSE FAILURE: #{e.class}\t#{e.message}\tFILE:#{file_path}\tSEXP:#{file_sexp.inspect}\n\tCONTENT:#{contents.inspect}\n\t#{e.backtrace}"
54
54
  end
55
55
 
@@ -65,8 +65,8 @@ module MetricFu
65
65
  else
66
66
  mf_debug "SEXP: Parsing line numbers for classes in sexp type #{node.node_type.inspect}"
67
67
  mf_debug " in #{file_path}"
68
- node.each_module {|child_node| process_class(child_node) }
69
- node.each_class {|child_node| process_class(child_node) }
68
+ node.each_module { |child_node| process_class(child_node) }
69
+ node.each_class { |child_node| process_class(child_node) }
70
70
  end
71
71
  end
72
72
 
@@ -79,11 +79,11 @@ module MetricFu
79
79
  process_class(module_node)
80
80
  end
81
81
 
82
- def process_class(class_node, module_name=nil)
82
+ def process_class(class_node, module_name = nil)
83
83
  class_name = class_node.name
84
84
  process_singleton_methods(class_node, class_name)
85
- process_instance_methods( class_node, class_name, module_name)
86
- process_class_methods( class_node, class_name, module_name)
85
+ process_instance_methods(class_node, class_name, module_name)
86
+ process_class_methods(class_node, class_name, module_name)
87
87
  end
88
88
 
89
89
  def process_singleton_methods(class_node, class_name)
@@ -108,6 +108,5 @@ module MetricFu
108
108
  @locations[class_method_name] = class_method_node.line_range
109
109
  end
110
110
  end
111
-
112
111
  end
113
112
  end
@@ -20,7 +20,7 @@ module MetricFu
20
20
  @file_name, @line_number = file_path.to_s.split(/:/)
21
21
  @class_name = class_name
22
22
  @method_name = method_name
23
- @simple_method_name = @method_name.to_s.sub(@class_name.to_s,'')
23
+ @simple_method_name = @method_name.to_s.sub(@class_name.to_s, "")
24
24
  @hash_key = to_key
25
25
  @hash = @hash_key.hash
26
26
  end
@@ -30,9 +30,9 @@ module MetricFu
30
30
  "class_name" => class_name,
31
31
  "method_name" => method_name,
32
32
  "file_path" => file_path,
33
- 'file_name' => file_name,
34
- 'line_number' => line_number,
35
- 'hash_key' => hash_key,
33
+ "file_name" => file_name,
34
+ "line_number" => line_number,
35
+ "hash_key" => hash_key,
36
36
  }
37
37
 
38
38
  if method_name.to_s.size > 0
@@ -48,7 +48,7 @@ module MetricFu
48
48
  end
49
49
 
50
50
  def <=>(other)
51
- self.hash <=> other.hash
51
+ hash <=> other.hash
52
52
  end
53
53
 
54
54
  # Generates the @hash key
@@ -58,12 +58,12 @@ module MetricFu
58
58
 
59
59
  def self.for(class_or_method_name)
60
60
  class_or_method_name = strip_modules(class_or_method_name)
61
- if(class_or_method_name)
61
+ if class_or_method_name
62
62
  begin
63
63
  match = class_or_method_name.match(/(.*)((\.|\#|\:\:[a-z])(.+))/)
64
64
  rescue => error
65
- #new error during port to metric_fu occasionally a unintialized
66
- #MatchData object shows up here. Not expected.
65
+ # new error during port to metric_fu occasionally a unintialized
66
+ # MatchData object shows up here. Not expected.
67
67
  mf_debug "ERROR on getting location for #{class_or_method_name} #{error.inspect}"
68
68
  match = nil
69
69
  end
@@ -71,9 +71,9 @@ module MetricFu
71
71
  # reek reports the method with :: not # on modules like
72
72
  # module ApplicationHelper \n def signed_in?, convert it so it records correctly
73
73
  # but classes have to start with a capital letter... HACK for REEK bug, reported underlying issue to REEK
74
- if(match)
74
+ if match
75
75
  class_name = strip_modules(match[1])
76
- method_name = class_or_method_name.gsub(/\:\:/,"#")
76
+ method_name = class_or_method_name.gsub(/\:\:/, "#")
77
77
  else
78
78
  class_name = strip_modules(class_or_method_name)
79
79
  method_name = nil
@@ -82,7 +82,7 @@ module MetricFu
82
82
  class_name = nil
83
83
  method_name = nil
84
84
  end
85
- self.get(nil, class_name, method_name)
85
+ get(nil, class_name, method_name)
86
86
  end
87
87
 
88
88
  def finalize
@@ -100,13 +100,11 @@ module MetricFu
100
100
  # reek reports the method with :: not # on modules like
101
101
  # module ApplicationHelper \n def signed_in?, convert it so it records correctly
102
102
  # but classes have to start with a capital letter... HACK for REEK bug, reported underlying issue to REEK
103
- if(class_or_method_name=~/\:\:[A-Z]/)
103
+ if class_or_method_name =~ /\:\:[A-Z]/
104
104
  class_or_method_name.split("::").last
105
105
  else
106
106
  class_or_method_name
107
107
  end
108
-
109
108
  end
110
-
111
109
  end
112
110
  end