Class: MetricFu::ReekGenerator
Instance Attribute Summary
Attributes inherited from Generator
#options, #result, #template
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Generator
#generate_result, generators, get_generator, #initialize, #metric, #metric_config, metric_directory, #metric_directory, not_implemented, #remove_excluded_files, #round_to_tenths, #silence_streams
Class Method Details
.metric ⇒ Object
3
4
5
|
# File 'lib/metric_fu/metrics/reek/generator.rb', line 3
def self.metric
:reek
end
|
Instance Method Details
#analyze ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/metric_fu/metrics/reek/generator.rb', line 26
def analyze
@matches = @output.group_by(&:source).collect do |file_path, smells|
{ file_path: file_path,
code_smells: analyze_smells(smells) }
end
@total = []
@total << "Detected #{@matches.size} files"
@total << "Found #{@matches.sum { |m| m[:code_smells].size }} code smells"
end
|
#emit ⇒ Object
7
8
9
10
11
12
13
14
15
|
# File 'lib/metric_fu/metrics/reek/generator.rb', line 7
def emit
files = files_to_analyze
if files.empty?
mf_log "Skipping Reek, no files found to analyze"
@output = run!([], config_files)
else
@output = run!(files, config_files)
end
end
|
#per_file_info(out) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/metric_fu/metrics/reek/generator.rb', line 40
def per_file_info(out)
@matches.each do |file_data|
file_path = file_data[:file_path]
next if File.extname(file_path) =~ /\.erb|\.html|\.haml/
begin
line_numbers = MetricFu::LineNumbers.new(File.read(file_path), file_path)
rescue StandardError => e
raise e unless e.message =~ /you shouldn't be able to get here/
mf_log "ruby_parser blew up while trying to parse #{file_path}. You won't have method level reek information for this file."
next
end
file_data[:code_smells].each do |smell_data|
line = line_numbers.start_line_for_method(smell_data[:method])
out[file_data[:file_path]][line.to_s] << { type: :reek,
description: "#{smell_data[:type]} - #{smell_data[:message]}" }
end
end
end
|
#run!(files, config_files) ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'lib/metric_fu/metrics/reek/generator.rb', line 17
def run!(files, config_files)
smells = []
files.each do |file|
e = examiner.new(File.new(file))
smells += e.smells
end
smells
end
|
#to_h ⇒ Object
36
37
38
|
# File 'lib/metric_fu/metrics/reek/generator.rb', line 36
def to_h
{ reek: { matches: @matches, total: @total } }
end
|