metric_fu 2.1.3.4 → 2.1.3.5

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.
@@ -1,5 +1,5 @@
1
- class RoodiAnalyzer
2
- include ScoringStrategies
1
+ class RoodiHotspot
2
+ include MetricFu::HotspotScoringStrategies
3
3
 
4
4
  COLUMNS = %w{problems}
5
5
 
@@ -12,15 +12,15 @@ class RoodiAnalyzer
12
12
  end
13
13
 
14
14
  def map(row)
15
- ScoringStrategies.present(row)
15
+ MetricFu::HotspotScoringStrategies.present(row)
16
16
  end
17
17
 
18
18
  def reduce(scores)
19
- ScoringStrategies.sum(scores)
19
+ MetricFu::HotspotScoringStrategies.sum(scores)
20
20
  end
21
21
 
22
22
  def score(metric_ranking, item)
23
- ScoringStrategies.percentile(metric_ranking, item)
23
+ MetricFu::HotspotScoringStrategies.percentile(metric_ranking, item)
24
24
  end
25
25
 
26
26
  def generate_records(data, table)
@@ -1,5 +1,5 @@
1
- class SaikuroAnalyzer
2
- include ScoringStrategies
1
+ class SaikuroHotspot
2
+ include MetricFu::HotspotScoringStrategies
3
3
 
4
4
  COLUMNS = %w{lines complexity}
5
5
 
@@ -16,11 +16,11 @@ class SaikuroAnalyzer
16
16
  end
17
17
 
18
18
  def reduce(scores)
19
- ScoringStrategies.average(scores)
19
+ MetricFu::HotspotScoringStrategies.average(scores)
20
20
  end
21
21
 
22
22
  def score(metric_ranking, item)
23
- ScoringStrategies.identity(metric_ranking, item)
23
+ MetricFu::HotspotScoringStrategies.identity(metric_ranking, item)
24
24
  end
25
25
 
26
26
  def generate_records(data, table)
@@ -1,4 +1,4 @@
1
- class StatsAnalyzer
1
+ class StatsHotspot
2
2
 
3
3
  COLUMNS = %w{stat_name stat_value}
4
4
 
@@ -1,29 +1,31 @@
1
- module ScoringStrategies
1
+ module MetricFu
2
+ module HotspotScoringStrategies
2
3
 
3
- def percentile(ranking, item)
4
- ranking.percentile(item) # per project score percentile
5
- end
4
+ def percentile(ranking, item)
5
+ ranking.percentile(item) # per project score percentile
6
+ end
6
7
 
7
- def identity(ranking, item)
8
- ranking[item] # Use the score you got (ex flog score of 20 is not bad even if it is the top one in project)
9
- end
8
+ def identity(ranking, item)
9
+ ranking[item] # Use the score you got (ex flog score of 20 is not bad even if it is the top one in project)
10
+ end
10
11
 
11
- def present(row)
12
- 1 # If present it's a one, not present it's a zero - For things like Reek that don't have a number
13
- end
12
+ def present(row)
13
+ 1 # If present it's a one, not present it's a zero - For things like Reek that don't have a number
14
+ end
14
15
 
15
- def sum(scores)
16
- scores.inject(0) {|s,x| s+x}
17
- end
16
+ def sum(scores)
17
+ scores.inject(0) {|s,x| s+x}
18
+ end
18
19
 
19
- def average(scores)
20
- # remove dependency on statarray
21
- # scores.to_statarray.mean
22
- score_length = scores.length
23
- sum = 0
24
- sum = scores.inject( nil ) { |sum,x| sum ? sum+x : x }
25
- (sum.to_f / score_length.to_f)
26
- end
20
+ def average(scores)
21
+ # remove dependency on statarray
22
+ # scores.to_statarray.mean
23
+ score_length = scores.length
24
+ sum = 0
25
+ sum = scores.inject( nil ) { |sum,x| sum ? sum+x : x }
26
+ (sum.to_f / score_length.to_f)
27
+ end
27
28
 
28
- extend self
29
+ extend self
30
+ end
29
31
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module MetricFu
2
- VERSION = "2.1.3.4"
2
+ VERSION = "2.1.3.5"
3
3
  end
data/metric_fu.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = MetricFu::VERSION
8
8
  s.summary = "A fistful of code metrics, with awesome templates and graphs"
9
9
  s.email = "github@benjaminfleischer.com"
10
- s.homepage = "http://github.com/bf4/metric_fu"
10
+ s.homepage = "http://github.com/metricfu/metric_fu"
11
11
  s.description = "Code metrics from Flog, Flay, Simplecov-RCov, Saikuro, Churn, Reek, Roodi, Rails' stats task and Rails Best Practices"
12
12
  s.authors = ["Jake Scruggs", "Sean Soper", "Andre Arko", "Petrik de Heus", "Grant McInnes", "Nick Quaranto", "Édouard Brière", "Carl Youngblood", "Richard Huang", "Dan Mayer", "Benjamin Fleischer"]
13
13
  s.required_ruby_version = ">= 1.8.7"
@@ -1,31 +1,31 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
- describe MetricAnalyzer do
3
+ describe HotspotAnalyzer do
4
4
 
5
5
  context "with several types of data" do
6
-
6
+
7
7
  before do
8
8
  @yaml =<<-__
9
- ---
10
- :reek:
11
- :matches:
9
+ ---
10
+ :reek:
11
+ :matches:
12
12
  - :file_path: lib/client/client.rb
13
- :code_smells:
13
+ :code_smells:
14
14
  - :type: Large Class
15
15
  :message: has at least 27 methods
16
16
  :method: Devver::Client
17
17
  - :type: Long Method
18
18
  :message: has approx 6 statements
19
19
  :method: Devver::Client#client_requested_sync
20
- :flog:
21
- :method_containers:
20
+ :flog:
21
+ :method_containers:
22
22
  - :highest_score: 61.5870319141946
23
23
  :path: /lib/client/client.rb
24
- :methods:
25
- Client#client_requested_sync:
24
+ :methods:
25
+ Client#client_requested_sync:
26
26
  :path: /lib/client/client.rb
27
27
  :score: 37.9270319141946
28
- :operators:
28
+ :operators:
29
29
  :+: 1.70000000000001
30
30
  :/: 1.80000000000001
31
31
  :method_at_line: 1.90000000000001
@@ -47,8 +47,8 @@ describe MetricAnalyzer do
47
47
  :average_score: 11.1209009055421
48
48
  :total_score: 1817.6
49
49
  :name: Client#client_requested_sync
50
- :churn:
51
- :changes:
50
+ :churn:
51
+ :changes:
52
52
  - :file_path: lib/client/client.rb
53
53
  :times_changed: 54
54
54
  - :file_path: lib/client/foo.rb
@@ -56,8 +56,8 @@ describe MetricAnalyzer do
56
56
  __
57
57
  end
58
58
 
59
- it "gives all files, in order, from worst to best" do
60
- analyzer = MetricAnalyzer.new(@yaml)
59
+ it "gives all files, in order, from worst to best" do
60
+ analyzer = HotspotAnalyzer.new(@yaml)
61
61
  expected = [
62
62
  "lib/client/client.rb",
63
63
  "lib/client/foo.rb"]
@@ -65,7 +65,7 @@ __
65
65
  end
66
66
 
67
67
  it "gives all issues for a class" do
68
- analyzer = MetricAnalyzer.new(@yaml)
68
+ analyzer = HotspotAnalyzer.new(@yaml)
69
69
  expected = {
70
70
  :reek => "found 2 code smells",
71
71
  :flog => "complexity is 37.9"
@@ -74,16 +74,16 @@ __
74
74
  end
75
75
 
76
76
  it "gives all issues for a method" do
77
- analyzer = MetricAnalyzer.new(@yaml)
78
- expected = {
79
- :reek => "found 1 code smells",
77
+ analyzer = HotspotAnalyzer.new(@yaml)
78
+ expected = {
79
+ :reek => "found 1 code smells",
80
80
  :flog => "complexity is 37.9"}
81
81
  analyzer.problems_with(:method, "Client#client_requested_sync").should == expected
82
82
  end
83
83
 
84
84
  it "gives all issues for a file" do
85
- analyzer = MetricAnalyzer.new(@yaml)
86
- expected = {
85
+ analyzer = HotspotAnalyzer.new(@yaml)
86
+ expected = {
87
87
  :reek => "found 2 code smells" ,
88
88
  :flog => "complexity is 37.9",
89
89
  :churn => "detected high level of churn (changed 54 times)"}
@@ -91,7 +91,7 @@ __
91
91
  end
92
92
 
93
93
  it "provide location for a method" do
94
- analyzer = MetricAnalyzer.new(@yaml)
94
+ analyzer = HotspotAnalyzer.new(@yaml)
95
95
  expected = Location.new("lib/client/client.rb",
96
96
  "Client",
97
97
  "Client#client_requested_sync")
@@ -99,7 +99,7 @@ __
99
99
  end
100
100
 
101
101
  it "provides location for a class" do
102
- analyzer = MetricAnalyzer.new(@yaml)
102
+ analyzer = HotspotAnalyzer.new(@yaml)
103
103
  expected = Location.new("lib/client/client.rb",
104
104
  "Client",
105
105
  nil)
@@ -107,7 +107,7 @@ __
107
107
  end
108
108
 
109
109
  it "provides location for a file" do
110
- analyzer = MetricAnalyzer.new(@yaml)
110
+ analyzer = HotspotAnalyzer.new(@yaml)
111
111
  expected = Location.new("lib/client/client.rb",
112
112
  nil,
113
113
  nil)
@@ -120,11 +120,11 @@ __
120
120
 
121
121
  before do
122
122
  @yaml =<<-__
123
- ---
124
- :reek:
125
- :matches:
123
+ ---
124
+ :reek:
125
+ :matches:
126
126
  - :file_path: lib/client/client.rb
127
- :code_smells:
127
+ :code_smells:
128
128
  - :type: Large Class
129
129
  :message: has at least 27 methods
130
130
  :method: Devver::Client
@@ -138,17 +138,17 @@ __
138
138
  end
139
139
 
140
140
  it "gives worst method" do
141
- analyzer = MetricAnalyzer.new(@yaml)
141
+ analyzer = HotspotAnalyzer.new(@yaml)
142
142
  analyzer.worst_methods(1).should == ["Client#client_requested_sync"]
143
143
  end
144
144
 
145
145
  it "gives worst class" do
146
- analyzer = MetricAnalyzer.new(@yaml)
146
+ analyzer = HotspotAnalyzer.new(@yaml)
147
147
  analyzer.worst_classes(1).should == ["Client"]
148
148
  end
149
149
 
150
150
  it "gives worst file" do
151
- analyzer = MetricAnalyzer.new(@yaml)
151
+ analyzer = HotspotAnalyzer.new(@yaml)
152
152
  analyzer.worst_files(1).should == ["lib/client/client.rb"]
153
153
  end
154
154
 
@@ -156,18 +156,18 @@ __
156
156
 
157
157
 
158
158
  context "with Saikuro data" do
159
-
159
+
160
160
  before do
161
161
  @yaml =<<-__
162
- :saikuro:
163
- :files:
164
- - :classes:
162
+ :saikuro:
163
+ :files:
164
+ - :classes:
165
165
  - :complexity: 0
166
166
  :methods: []
167
167
  :lines: 3
168
168
  :class_name: Shorty
169
169
  - :complexity: 19
170
- :methods:
170
+ :methods:
171
171
  - :complexity: 9
172
172
  :lines: 6
173
173
  :name: Shorty::Supr#self.handle_full_or_hash_option
@@ -177,9 +177,9 @@ __
177
177
  :lines: 92
178
178
  :class_name: Shorty::Supr
179
179
  :filename: supr.rb
180
- - :classes:
180
+ - :classes:
181
181
  - :complexity: 12
182
- :methods:
182
+ :methods:
183
183
  - :complexity: 8
184
184
  :lines: 10
185
185
  :name: Shorty::Bitly#info
@@ -188,27 +188,27 @@ __
188
188
  :filename: bitly.rb
189
189
  __
190
190
  end
191
-
191
+
192
192
  it "gives worst method" do
193
- analyzer = MetricAnalyzer.new(@yaml)
193
+ analyzer = HotspotAnalyzer.new(@yaml)
194
194
  analyzer.worst_methods(1).should == ["Supr#self.handle_full_or_hash_option"]
195
195
  end
196
196
 
197
197
  it "gives worst class" do
198
- analyzer = MetricAnalyzer.new(@yaml)
198
+ analyzer = HotspotAnalyzer.new(@yaml)
199
199
  analyzer.worst_classes(1).should == ["Bitly"]
200
200
  end
201
201
 
202
202
  it "gives complexity for method" do
203
- analyzer = MetricAnalyzer.new(@yaml)
203
+ analyzer = HotspotAnalyzer.new(@yaml)
204
204
  expected = {
205
205
  :saikuro => "complexity is 1.0"
206
206
  }
207
207
  analyzer.problems_with(:method, "Supr#initialize").should == expected
208
208
  end
209
-
209
+
210
210
  it "gives average complexity for class" do
211
- analyzer = MetricAnalyzer.new(@yaml)
211
+ analyzer = HotspotAnalyzer.new(@yaml)
212
212
  expected = {
213
213
  :saikuro => "average complexity is 5.0"
214
214
  }
@@ -218,19 +218,19 @@ __
218
218
  end
219
219
 
220
220
  context "with Flog data" do
221
-
221
+
222
222
  before do
223
223
  @yaml =<<-__
224
- ---
225
- :flog:
226
- :method_containers:
224
+ ---
225
+ :flog:
226
+ :method_containers:
227
227
  - :highest_score: 85.5481735632041
228
228
  :path: ""
229
- :methods:
230
- main#none:
231
- :path:
229
+ :methods:
230
+ main#none:
231
+ :path:
232
232
  :score: 85.5481735632041
233
- :operators:
233
+ :operators:
234
234
  :+: 9.10000000000001
235
235
  :assignment: 11.6000000000001
236
236
  :require: 38.5000000000002
@@ -245,11 +245,11 @@ __
245
245
  :name: main
246
246
  - :highest_score: 61.5870319141946
247
247
  :path: lib/generators/rcov.rb
248
- :methods:
249
- Rcov#add_method_data:
248
+ :methods:
249
+ Rcov#add_method_data:
250
250
  :path: lib/generators/rcov.rb:57
251
251
  :score: 61.5870319141946
252
- :operators:
252
+ :operators:
253
253
  :+: 1.70000000000001
254
254
  :/: 1.80000000000001
255
255
  :method_at_line: 1.90000000000001
@@ -268,10 +268,10 @@ __
268
268
  :each_with_index: 3.00000000000001
269
269
  :[]: 22.3000000000001
270
270
  :new: 1.60000000000001
271
- Rcov#analyze:
271
+ Rcov#analyze:
272
272
  :path: lib/generators/rcov.rb:34
273
273
  :score: 19.1504569136092
274
- :operators:
274
+ :operators:
275
275
  :+: 1.40000000000001
276
276
  :metric_directory: 1.6
277
277
  :assignment: 9.10000000000004
@@ -288,17 +288,17 @@ __
288
288
  :total_score: 195.23642381151
289
289
  - :highest_score: 60.0573892206447
290
290
  :path: lib/base/metric_analyzer.rb
291
- :methods:
292
- MetricAnalyzer#grouping_key:
291
+ :methods:
292
+ HotspotAnalyzer#grouping_key:
293
293
  :path: lib/base/metric_analyzer.rb:117
294
294
  :score: 2.6
295
- :operators:
295
+ :operators:
296
296
  :inspect: 1.3
297
297
  :object_id: 1.3
298
- MetricAnalyzer#fix_row_file_path!:
298
+ HotspotAnalyzer#fix_row_file_path!:
299
299
  :path: lib/base/metric_analyzer.rb:148
300
300
  :score: 20.2743680542699
301
- :operators:
301
+ :operators:
302
302
  :assignment: 10.0
303
303
  :include?: 3.1
304
304
  :branch: 7.20000000000001
@@ -309,32 +309,32 @@ __
309
309
  :[]: 5.40000000000001
310
310
  __
311
311
  end
312
-
312
+
313
313
  it "gives worst method" do
314
- analyzer = MetricAnalyzer.new(@yaml)
314
+ analyzer = HotspotAnalyzer.new(@yaml)
315
315
  analyzer.worst_methods(1).should == ["main#none"]
316
316
  end
317
317
 
318
318
  it "gives worst class" do
319
- analyzer = MetricAnalyzer.new(@yaml)
319
+ analyzer = HotspotAnalyzer.new(@yaml)
320
320
  analyzer.worst_classes(1).should == ["main"]
321
321
  end
322
322
 
323
323
  it "gives worst file" do
324
- analyzer = MetricAnalyzer.new(@yaml)
324
+ analyzer = HotspotAnalyzer.new(@yaml)
325
325
  analyzer.worst_files(1).should == ["lib/generators/rcov.rb:57"]
326
326
  end
327
327
 
328
328
  end
329
329
 
330
330
  context "with Roodi data" do
331
-
331
+
332
332
  before do
333
333
  @yaml =<<-__
334
- :roodi:
335
- :total:
334
+ :roodi:
335
+ :total:
336
336
  - Found 164 errors.
337
- :problems:
337
+ :problems:
338
338
  - :line: "158"
339
339
  :file: lib/client/client.rb
340
340
  :problem: Method name "process" cyclomatic complexity is 10. It should be 8 or less.
@@ -348,37 +348,37 @@ __
348
348
  end
349
349
 
350
350
  it "gives worst file" do
351
- analyzer = MetricAnalyzer.new(@yaml)
351
+ analyzer = HotspotAnalyzer.new(@yaml)
352
352
  analyzer.worst_files(1).should == ["lib/client/client.rb"]
353
353
  end
354
354
 
355
355
  end
356
356
 
357
357
  context "with Stats data" do
358
-
358
+
359
359
  before do
360
360
  @yaml =<<-__
361
- :stats:
361
+ :stats:
362
362
  :codeLOC: 4222
363
363
  :testLOC: 2111
364
364
  :code_to_test_ratio: 2
365
365
  __
366
366
  end
367
-
367
+
368
368
  it "should have codeLOC" do
369
- analyzer = MetricAnalyzer.new(@yaml)
369
+ analyzer = HotspotAnalyzer.new(@yaml)
370
370
  row = analyzer.table.rows_with('stat_name' => :codeLOC).first
371
371
  row['stat_value'].should == 4222
372
372
  end
373
373
 
374
374
  it "should have testLOC" do
375
- analyzer = MetricAnalyzer.new(@yaml)
375
+ analyzer = HotspotAnalyzer.new(@yaml)
376
376
  row = analyzer.table.rows_with('stat_name' => :testLOC).first
377
377
  row['stat_value'].should == 2111
378
378
  end
379
379
 
380
380
  it "should have code_to_test_ration" do
381
- analyzer = MetricAnalyzer.new(@yaml)
381
+ analyzer = HotspotAnalyzer.new(@yaml)
382
382
  row = analyzer.table.rows_with('stat_name' => :code_to_test_ratio).first
383
383
  row['stat_value'].should == 2
384
384
  end
@@ -389,11 +389,11 @@ end
389
389
 
390
390
  before do
391
391
  @yaml =<<-__
392
- :saikuro:
393
- :files:
394
- - :classes:
392
+ :saikuro:
393
+ :files:
394
+ - :classes:
395
395
  - :complexity: 19
396
- :methods:
396
+ :methods:
397
397
  - :complexity: 1
398
398
  :lines: 9
399
399
  :name: Client#client_requested_sync
@@ -403,24 +403,24 @@ end
403
403
  :lines: 92
404
404
  :class_name: Devver::Client
405
405
  :filename: client.rb
406
- :reek:
407
- :matches:
406
+ :reek:
407
+ :matches:
408
408
  - :file_path: lib/client/client.rb
409
- :code_smells:
409
+ :code_smells:
410
410
  - :type: Large Class
411
411
  :message: has at least 27 methods
412
412
  :method: Devver::Client
413
413
  - :type: Long Method
414
414
  :message: has approx 6 statements
415
415
  :method: Devver::Client#client_requested_sync
416
- :flog:
416
+ :flog:
417
417
  :total: 1817.6
418
- :pages:
418
+ :pages:
419
419
  - :path: /lib/client/client.rb
420
420
  :highest_score: 37.9
421
421
  :average_score: 13.6
422
- :scanned_methods:
423
- - :operators:
422
+ :scanned_methods:
423
+ - :operators:
424
424
  - :operator: "[]"
425
425
  :score: 11.1
426
426
  :score: 37.9
@@ -429,19 +429,19 @@ __
429
429
  end
430
430
 
431
431
  specify "all records should have full file_path" do
432
- analyzer = MetricAnalyzer.new(@yaml)
432
+ analyzer = HotspotAnalyzer.new(@yaml)
433
433
  analyzer.table.each do |row|
434
434
  row['file_path'].should == 'lib/client/client.rb'
435
435
  end
436
436
  end
437
-
437
+
438
438
  specify "all records should have class name" do
439
- analyzer = MetricAnalyzer.new(@yaml)
439
+ analyzer = HotspotAnalyzer.new(@yaml)
440
440
  analyzer.table.rows_with(:class_name => nil).should have(0).rows
441
441
  end
442
442
 
443
443
  specify "one record should not have method name" do
444
- analyzer = MetricAnalyzer.new(@yaml)
444
+ analyzer = HotspotAnalyzer.new(@yaml)
445
445
  analyzer.table.rows_with(:method_name => nil).should have(1).rows
446
446
  end
447
447