-
Notifications
You must be signed in to change notification settings - Fork 1
/
metric_fu.rb
87 lines (73 loc) · 2.5 KB
/
metric_fu.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# encoding: utf-8
#
# This file is part of the metrics repository. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
#
module MetricFu
def self.custom_directories
rv = ENV["MF_SOURCES"]
if rv then
rv = rv.split(":") if rv.index(":")
rv = [rv] if !rv.is_a?(Array)
end
rv
end
def self.root_directory
Dir.pwd
end
class CaneGenerator
def emit
command = %Q{mf-cane#{abc_max_param}#{style_measure_param}#{no_doc_param}#{no_readme_param}#{directory_globs_params}}
mf_debug "** #{command}"
@output = `#{command}`
end
def directory_globs_params
if options[:dirs_to_cane]
globs = "{#{options[:dirs_to_cane].join(",")}}/**/*.rb"
" --abc-glob \"#{globs}\" --style-glob \"#{globs}\""
else
""
end
end
end
class RailsBestPracticesGenerator
def emit
mf_debug "** Rails Best Practices"
path = (MetricFu.custom_directories || ["."]).first
analyzer = ::RailsBestPractices::Analyzer.new(path, { 'silent' => true })
analyzer.analyze
@output = analyzer.errors
end
end
end
MetricFu::Configuration.run do |config|
config.configure_metrics.each do |metric|
enabled_metrics = [:cane, :flog, :flay, :reek, :roodi, :rails_best_practices, :saikuro]
metric.enabled = enabled_metrics.include?(metric.name)
end
config.configure_metric(:cane) do |metric|
metric.dirs_to_cane = MetricFu.custom_directories if MetricFu.custom_directories
metric.line_length = 160
metric.no_doc = "y"
metric.no_readme = "y"
end
config.configure_metric(:flog) do |metric|
metric.dirs_to_flog = MetricFu.custom_directories if MetricFu.custom_directories
end
config.configure_metric(:flay) do |metric|
metric.dirs_to_flay = MetricFu.custom_directories if MetricFu.custom_directories
end
config.configure_metric(:reek) do |metric|
metric.dirs_to_reek = MetricFu.custom_directories if MetricFu.custom_directories
metric.config_file_pattern = MetricFu.root_directory + "/metrics/reek.yml"
end
config.configure_metric(:roodi) do |metric|
metric.dirs_to_roodi = MetricFu.custom_directories if MetricFu.custom_directories
metric.roodi_config = MetricFu.root_directory + "/metrics/roodi.yml"
end
config.configure_metric(:saikuro) do |metric|
metric.input_directory = MetricFu.custom_directories
metric.warn_cyclo = 0
metric.error_cyclo = 6
end
end