metric_fu 1.1.5 → 1.1.6
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.
- data/lib/base/configuration.rb +2 -0
- data/lib/base/generator.rb +7 -0
- data/lib/generators/flay.rb +2 -1
- data/lib/generators/flog.rb +32 -5
- data/lib/generators/reek.rb +28 -1
- data/lib/generators/roodi.rb +2 -1
- data/spec/base/generator_spec.rb +63 -0
- data/spec/generators/flog_spec.rb +19 -0
- data/spec/generators/reek_spec.rb +66 -0
- data/spec/spec_helper.rb +1 -0
- metadata +4 -4
data/lib/base/configuration.rb
CHANGED
data/lib/base/generator.rb
CHANGED
@@ -97,6 +97,13 @@ module MetricFu
|
|
97
97
|
self.class.metric_directory
|
98
98
|
end
|
99
99
|
|
100
|
+
def remove_excluded_files(paths, globs_to_remove = MetricFu.file_globs_to_ignore)
|
101
|
+
files_to_remove = []
|
102
|
+
globs_to_remove.each do |glob|
|
103
|
+
files_to_remove.concat(Dir[glob])
|
104
|
+
end
|
105
|
+
paths - files_to_remove
|
106
|
+
end
|
100
107
|
|
101
108
|
# Defines some hook methods for the concrete classes to hook into.
|
102
109
|
%w[emit analyze].each do |meth|
|
data/lib/generators/flay.rb
CHANGED
@@ -9,7 +9,8 @@ module MetricFu
|
|
9
9
|
|
10
10
|
def emit
|
11
11
|
files_to_flay = MetricFu.flay[:dirs_to_flay].map{|dir| Dir[File.join(dir, "**/*.rb")] }
|
12
|
-
|
12
|
+
files = remove_excluded_files(files_to_flay.flatten)
|
13
|
+
@output = `flay #{files.join(" ")}`
|
13
14
|
end
|
14
15
|
|
15
16
|
def analyze
|
data/lib/generators/flog.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
1
3
|
module MetricFu
|
2
4
|
|
3
5
|
class Flog < Generator
|
@@ -15,11 +17,17 @@ module MetricFu
|
|
15
17
|
def emit
|
16
18
|
metric_dir = MetricFu::Flog.metric_directory
|
17
19
|
MetricFu.flog[:dirs_to_flog].each do |directory|
|
18
|
-
|
20
|
+
directory = "." if directory=='./'
|
21
|
+
files = Dir.glob("#{directory}/**/*.rb")
|
22
|
+
files = remove_excluded_files(files)
|
23
|
+
files.each do |filename|
|
19
24
|
output_dir = "#{metric_dir}/#{filename.split("/")[0..-2].join("/")}"
|
20
25
|
mkdir_p(output_dir, :verbose => false) unless File.directory?(output_dir)
|
21
|
-
|
22
|
-
|
26
|
+
pathname = Pathname.new(filename)
|
27
|
+
if MetricFu::MD5Tracker.file_changed?(filename, metric_dir)
|
28
|
+
base_name = pathname.basename.to_s.gsub(/\..*$/,'.txt')
|
29
|
+
editted_filename = File.join(pathname.dirname.to_s, base_name)
|
30
|
+
`flog -ad #{filename} > #{metric_dir}/#{editted_filename}`
|
23
31
|
end
|
24
32
|
end
|
25
33
|
end
|
@@ -54,7 +62,10 @@ module MetricFu
|
|
54
62
|
page = parse(open(path, "r") { |f| f.read })
|
55
63
|
if page
|
56
64
|
page.path = path.sub(metric_directory, "").sub(".txt", ".rb")
|
57
|
-
|
65
|
+
#don't include old cached flog results for files that no longer exist.
|
66
|
+
if is_file_current?(page.path.to_s)
|
67
|
+
@pages << page
|
68
|
+
end
|
58
69
|
end
|
59
70
|
end
|
60
71
|
end
|
@@ -69,7 +80,23 @@ module MetricFu
|
|
69
80
|
end
|
70
81
|
|
71
82
|
private
|
72
|
-
|
83
|
+
|
84
|
+
def is_file_current?(pathname)
|
85
|
+
pathname = pathname.gsub(/^\//,'')
|
86
|
+
local_pathname = "./#{pathname}"
|
87
|
+
exists = false
|
88
|
+
|
89
|
+
MetricFu.flog[:dirs_to_flog].each do |directory|
|
90
|
+
directory = "." if directory=='./'
|
91
|
+
files = Dir.glob("#{directory}/**/*.rb")
|
92
|
+
if files.include?(pathname) || files.include?(local_pathname)
|
93
|
+
exists = true
|
94
|
+
break
|
95
|
+
end
|
96
|
+
end
|
97
|
+
exists
|
98
|
+
end
|
99
|
+
|
73
100
|
def average_score(total_flog_score, number_of_methods)
|
74
101
|
return 0 if total_flog_score == 0
|
75
102
|
round_to_tenths(total_flog_score/number_of_methods)
|
data/lib/generators/reek.rb
CHANGED
@@ -10,7 +10,34 @@ module MetricFu
|
|
10
10
|
|
11
11
|
def emit
|
12
12
|
files_to_reek = MetricFu.reek[:dirs_to_reek].map{|dir| Dir[File.join(dir, "**/*.rb")] }
|
13
|
-
|
13
|
+
files = remove_excluded_files(files_to_reek.flatten)
|
14
|
+
@output = `reek #{files.join(" ")}`
|
15
|
+
@output = massage_for_reek_12 if reek_12?
|
16
|
+
end
|
17
|
+
|
18
|
+
def reek_12?
|
19
|
+
return false if @output.length == 0
|
20
|
+
(@output =~ /^"/) != 0
|
21
|
+
end
|
22
|
+
|
23
|
+
def massage_for_reek_12
|
24
|
+
section_break = ''
|
25
|
+
@output.split("\n").map do |line|
|
26
|
+
case line
|
27
|
+
when /^ /
|
28
|
+
"#{line.gsub(/^ /, '')}\n"
|
29
|
+
else
|
30
|
+
parts = line.split(" -- ")
|
31
|
+
if parts[1].nil?
|
32
|
+
"#{line}\n"
|
33
|
+
else
|
34
|
+
warnings = parts[1].gsub(/ \(.*\):/, ':')
|
35
|
+
result = "#{section_break}\"#{parts[0]}\" -- #{warnings}\n"
|
36
|
+
section_break = "\n"
|
37
|
+
result
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end.join
|
14
41
|
end
|
15
42
|
|
16
43
|
def analyze
|
data/lib/generators/roodi.rb
CHANGED
@@ -9,7 +9,8 @@ module MetricFu
|
|
9
9
|
|
10
10
|
def emit
|
11
11
|
files_to_analyze = MetricFu.roodi[:dirs_to_roodi].map{|dir| Dir[File.join(dir, "**/*.rb")] }
|
12
|
-
|
12
|
+
files = remove_excluded_files(files_to_analyze.flatten)
|
13
|
+
@output = `roodi #{files.join(" ")}`
|
13
14
|
end
|
14
15
|
|
15
16
|
def analyze
|
data/spec/base/generator_spec.rb
CHANGED
@@ -2,6 +2,8 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
|
2
2
|
|
3
3
|
describe MetricFu::Generator do
|
4
4
|
|
5
|
+
include Construct::Helpers
|
6
|
+
|
5
7
|
MetricFu::Configuration.run do |config|
|
6
8
|
end
|
7
9
|
|
@@ -177,5 +179,66 @@ describe MetricFu::Generator do
|
|
177
179
|
ConcreteClass.new()
|
178
180
|
end
|
179
181
|
end
|
182
|
+
|
183
|
+
describe "path filter" do
|
184
|
+
|
185
|
+
context "given a list of paths" do
|
186
|
+
|
187
|
+
before do
|
188
|
+
@paths = %w(lib/fake/fake.rb
|
189
|
+
lib/this/dan_file.rb
|
190
|
+
lib/this/ben_file.rb
|
191
|
+
lib/this/avdi_file.rb
|
192
|
+
basic.rb
|
193
|
+
lib/bad/one.rb
|
194
|
+
lib/bad/two.rb
|
195
|
+
lib/bad/three.rb
|
196
|
+
lib/worse/four.rb)
|
197
|
+
@container = create_construct
|
198
|
+
@paths.each do |path|
|
199
|
+
@container.file(path)
|
200
|
+
end
|
201
|
+
@old_dir = Dir.pwd
|
202
|
+
Dir.chdir(@container)
|
203
|
+
end
|
204
|
+
|
205
|
+
after do
|
206
|
+
Dir.chdir(@old_dir)
|
207
|
+
@container.destroy!
|
208
|
+
end
|
209
|
+
|
210
|
+
it "should return entire pathlist given no exclude pattens" do
|
211
|
+
files = @concrete_class.remove_excluded_files(@paths)
|
212
|
+
files.should be == @paths
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should filter filename at root level" do
|
216
|
+
files = @concrete_class.remove_excluded_files(@paths, ['basic.rb'])
|
217
|
+
files.should_not include('basic.rb')
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should remove files that are two levels deep" do
|
221
|
+
files = @concrete_class.remove_excluded_files(@paths, ['**/fake.rb'])
|
222
|
+
files.should_not include('lib/fake/fake.rb')
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should remove files from an excluded directory" do
|
226
|
+
files = @concrete_class.remove_excluded_files(@paths, ['lib/bad/**'])
|
227
|
+
files.should_not include('lib/bad/one.rb')
|
228
|
+
files.should_not include('lib/bad/two.rb')
|
229
|
+
files.should_not include('lib/bad/three.rb')
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should support shell alternation globs" do
|
233
|
+
files = @concrete_class.remove_excluded_files(@paths, ['lib/this/{ben,dan}_file.rb'])
|
234
|
+
files.should_not include('lib/this/dan_file.rb')
|
235
|
+
files.should_not include('lib/this/ben_file.rb')
|
236
|
+
files.should include('lib/this/avdi_file.rb')
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
|
242
|
+
end
|
180
243
|
|
181
244
|
end
|
@@ -184,6 +184,7 @@ describe Flog do
|
|
184
184
|
File.stub!(:directory?).and_return(true)
|
185
185
|
flog = MetricFu::Flog.new('base_dir')
|
186
186
|
flog.should_receive(:open).and_return(@text)
|
187
|
+
flog.stub!(:is_file_current?).and_return(true)
|
187
188
|
Dir.should_receive(:glob).and_return(["tmp/metric_fu/scratch/flog/app/controllers/user_controller.txt"])
|
188
189
|
flog.analyze
|
189
190
|
@flog_hash = flog.to_h
|
@@ -206,6 +207,24 @@ describe Flog do
|
|
206
207
|
end
|
207
208
|
end
|
208
209
|
|
210
|
+
describe "to_h function ignore files not current" do
|
211
|
+
before :each do
|
212
|
+
MetricFu::Configuration.run {}
|
213
|
+
File.stub!(:directory?).and_return(true)
|
214
|
+
flog = MetricFu::Flog.new('base_dir')
|
215
|
+
flog.should_receive(:open).and_return(@text)
|
216
|
+
flog.stub!(:is_file_current?).and_return(false)
|
217
|
+
Dir.should_receive(:glob).and_return(["tmp/metric_fu/scratch/flog/app/controllers/user_controller.txt"])
|
218
|
+
flog.analyze
|
219
|
+
@flog_hash = flog.to_h
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should put the total in the hash" do
|
223
|
+
@flog_hash.should == {:flog=>{:total=>0, :pages=>[], :average=>0}}
|
224
|
+
end
|
225
|
+
|
226
|
+
end
|
227
|
+
|
209
228
|
describe "to_h function with zero total" do
|
210
229
|
it "should not blow up" do
|
211
230
|
MetricFu::Configuration.run {}
|
@@ -58,3 +58,69 @@ NewlineController#some_method calls current_user.<< "new line\n" multiple times
|
|
58
58
|
end
|
59
59
|
|
60
60
|
end
|
61
|
+
|
62
|
+
describe Reek do
|
63
|
+
before :each do
|
64
|
+
@reek = MetricFu::Reek.new
|
65
|
+
@lines11 = <<-HERE
|
66
|
+
"app/controllers/activity_reports_controller.rb" -- 4 warnings:
|
67
|
+
ActivityReportsController#authorize_user calls current_user.primary_site_ids multiple times (Duplication)
|
68
|
+
ActivityReportsController#authorize_user calls params[id] multiple times (Duplication)
|
69
|
+
ActivityReportsController#authorize_user calls params[primary_site_id] multiple times (Duplication)
|
70
|
+
ActivityReportsController#authorize_user has approx 6 statements (Long Method)
|
71
|
+
|
72
|
+
"app/controllers/application.rb" -- 1 warnings:
|
73
|
+
ApplicationController#start_background_task/block/block is nested (Nested Iterators)
|
74
|
+
|
75
|
+
"app/controllers/link_targets_controller.rb" -- 1 warnings:
|
76
|
+
LinkTargetsController#authorize_user calls current_user.role multiple times (Duplication)
|
77
|
+
|
78
|
+
"app/controllers/newline_controller.rb" -- 1 warnings:
|
79
|
+
NewlineController#some_method calls current_user.<< "new line\n" multiple times (Duplication)
|
80
|
+
HERE
|
81
|
+
@lines12 = <<-HERE
|
82
|
+
app/controllers/activity_reports_controller.rb -- 4 warnings (+3 masked):
|
83
|
+
ActivityReportsController#authorize_user calls current_user.primary_site_ids multiple times (Duplication)
|
84
|
+
ActivityReportsController#authorize_user calls params[id] multiple times (Duplication)
|
85
|
+
ActivityReportsController#authorize_user calls params[primary_site_id] multiple times (Duplication)
|
86
|
+
ActivityReportsController#authorize_user has approx 6 statements (Long Method)
|
87
|
+
app/controllers/application.rb -- 1 warnings:
|
88
|
+
ApplicationController#start_background_task/block/block is nested (Nested Iterators)
|
89
|
+
app/controllers/link_targets_controller.rb -- 1 warnings (+1 masked):
|
90
|
+
LinkTargetsController#authorize_user calls current_user.role multiple times (Duplication)
|
91
|
+
app/controllers/newline_controller.rb -- 1 warnings:
|
92
|
+
NewlineController#some_method calls current_user.<< "new line\n" multiple times (Duplication)
|
93
|
+
HERE
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'with Reek 1.1 output format' do
|
97
|
+
it 'reports 1.1 style when the output is empty' do
|
98
|
+
@reek.instance_variable_set(:@output, "")
|
99
|
+
@reek.should_not be_reek_12
|
100
|
+
end
|
101
|
+
it 'detects 1.1 format output' do
|
102
|
+
@reek.instance_variable_set(:@output, @lines11)
|
103
|
+
@reek.should_not be_reek_12
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'massages empty output to be unchanged' do
|
107
|
+
@reek.instance_variable_set(:@output, "")
|
108
|
+
@reek.massage_for_reek_12.should be_empty
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'with Reek 1.2 output format' do
|
113
|
+
before :each do
|
114
|
+
@reek = MetricFu::Reek.new
|
115
|
+
end
|
116
|
+
it 'detects 1.2 format output' do
|
117
|
+
@reek.instance_variable_set(:@output, @lines12)
|
118
|
+
@reek.should be_reek_12
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'correctly massages 1.2 output' do
|
122
|
+
@reek.instance_variable_set(:@output, @lines12)
|
123
|
+
@reek.massage_for_reek_12.should == @lines11
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metric_fu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jake Scruggs
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2009-12-
|
18
|
+
date: 2009-12-14 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -34,9 +34,9 @@ dependencies:
|
|
34
34
|
version_requirement:
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- - "
|
37
|
+
- - "="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 2.
|
39
|
+
version: 2.2.0
|
40
40
|
version:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: relevance-rcov
|