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
@@ -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
|
data/lib/metric_fu.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
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,
|
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
|
-
|
16
|
+
"https://github.com/metricfu/metric_fu"
|
17
17
|
end
|
18
18
|
|
19
19
|
def metric_name
|
20
|
-
|
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
|
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
|
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|
|
data/lib/metric_fu/calculate.rb
CHANGED
data/lib/metric_fu/cli/client.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
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
|
-
|
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
|
data/lib/metric_fu/cli/helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
MetricFu.lib_require {
|
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
|
-
|
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
|
-
|
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
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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!
|
data/lib/metric_fu/cli/parser.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
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
|
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
|
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
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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
|
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
|
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 {
|
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
|
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
|
55
|
-
require_relative
|
56
|
-
require_relative
|
57
|
-
require_relative
|
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
|
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 {
|
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 |
|
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(
|
86
|
-
process_class_methods(
|
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
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
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
|
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
|
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
|
-
|
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
|
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
|