flog 4.1.2 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/History.txt CHANGED
@@ -1,3 +1,11 @@
1
+ === 4.2.0 / 2013-10-18
2
+
3
+ * 3 minor enhancements:
4
+
5
+ * Added --extended / -e to put file:line output on next line (for rubymine & friends)
6
+ * Extracted MethodBasedSexpProcessor and pushed up to sexp_processor gem.
7
+ * Updated dependency on sexp_processor to ~> 4.4.
8
+
1
9
  === 4.1.2 / 2013-09-05
2
10
 
3
11
  * 2 bug fixes:
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ Hoe.spec 'flog' do
20
20
  self.flog_method = :max_method
21
21
  self.flog_threshold = timebomb 150, 50, '2013-11-01', '2012-11-01'
22
22
 
23
- dependency "sexp_processor", "~> 4.0"
23
+ dependency "sexp_processor", "~> 4.4"
24
24
  dependency "ruby_parser", ["~> 3.1", "> 3.1.0"]
25
25
  end
26
26
 
data/lib/flog.rb CHANGED
@@ -10,8 +10,8 @@ class File
10
10
  end
11
11
  end
12
12
 
13
- class Flog < SexpProcessor
14
- VERSION = "4.1.2" # :nodoc:
13
+ class Flog < MethodBasedSexpProcessor
14
+ VERSION = "4.2.0" # :nodoc:
15
15
 
16
16
  ##
17
17
  # Cut off point where the report should stop unless --all given.
@@ -93,13 +93,10 @@ class Flog < SexpProcessor
93
93
 
94
94
  SCORES.merge!(:inject => 2)
95
95
 
96
- @@no_class = :main
97
- @@no_method = :none
98
-
99
96
  # :stopdoc:
100
97
  attr_accessor :multiplier
101
- attr_reader :calls, :option, :class_stack, :method_stack, :mass, :sclass
102
- attr_reader :method_locations, :method_scores, :scores
98
+ attr_reader :calls, :option, :mass
99
+ attr_reader :method_scores, :scores
103
100
  attr_reader :total_score, :totals
104
101
 
105
102
  # :startdoc:
@@ -227,49 +224,12 @@ class Flog < SexpProcessor
227
224
  process ast
228
225
  end
229
226
 
230
- ##
231
- # Adds name to the class stack, for the duration of the block
232
-
233
- def in_klass name
234
- if Sexp === name then
235
- name = case name.first
236
- when :colon2 then
237
- name = name.flatten
238
- name.delete :const
239
- name.delete :colon2
240
- name.join("::")
241
- when :colon3 then
242
- name.last.to_s
243
- else
244
- raise "unknown type #{name.inspect}"
245
- end
246
- end
247
-
248
- @class_stack.unshift name
249
- yield
250
- @class_stack.shift
251
- end
252
-
253
- ##
254
- # Adds name to the method stack, for the duration of the block
255
-
256
- def in_method(name, file, line)
257
- method_name = Regexp === name ? name.inspect : name.to_s
258
- @method_stack.unshift method_name
259
- @method_locations[signature] = "#{file}:#{line}"
260
- yield
261
- @method_stack.shift
262
- end
263
-
264
227
  ##
265
228
  # Creates a new Flog instance with +options+.
266
229
 
267
230
  def initialize option = {}
268
231
  super()
269
232
  @option = option
270
- @sclass = []
271
- @class_stack = []
272
- @method_stack = []
273
233
  @method_locations = {}
274
234
  @mass = {}
275
235
  @parser = nil
@@ -277,22 +237,6 @@ class Flog < SexpProcessor
277
237
  self.reset
278
238
  end
279
239
 
280
- ##
281
- # Returns the first class in the list, or @@no_class if there are
282
- # none.
283
-
284
- def klass_name
285
- name = @class_stack.first
286
-
287
- if Sexp === name then
288
- raise "you shouldn't see me"
289
- elsif @class_stack.any?
290
- @class_stack.reverse.join("::").sub(/\([^\)]+\)$/, '')
291
- else
292
- @@no_class
293
- end
294
- end
295
-
296
240
  ##
297
241
  # Returns the method/score pair of the maximum score.
298
242
 
@@ -307,16 +251,6 @@ class Flog < SexpProcessor
307
251
  max_method.last
308
252
  end
309
253
 
310
- ##
311
- # Returns the first method in the list, or "#none" if there are
312
- # none.
313
-
314
- def method_name
315
- m = @method_stack.first || @@no_method
316
- m = "##{m}" unless m =~ /::/
317
- m
318
- end
319
-
320
254
  ##
321
255
  # For the duration of the block the complexity factor is increased
322
256
  # by #bonus This allows the complexity of sub-expressions to be
@@ -329,13 +263,6 @@ class Flog < SexpProcessor
329
263
  @multiplier -= bonus
330
264
  end
331
265
 
332
- ##
333
- # Process each element of #exp in turn.
334
-
335
- def process_until_empty exp
336
- process exp.shift until exp.empty?
337
- end
338
-
339
266
  ##
340
267
  # Reset score data
341
268
 
@@ -345,7 +272,7 @@ class Flog < SexpProcessor
345
272
  @calls = Hash.new { |h,k| h[k] = Hash.new 0 }
346
273
  @method_scores = Hash.new { |h,k| h[k] = [] }
347
274
  @scores = Hash.new 0
348
- @method_locations = {}
275
+ method_locations.clear
349
276
  end
350
277
 
351
278
  ##
@@ -363,13 +290,6 @@ class Flog < SexpProcessor
363
290
  Math.sqrt(a*a + b*b + c*c)
364
291
  end
365
292
 
366
- ##
367
- # Returns the method signature for the current method.
368
-
369
- def signature
370
- "#{klass_name}#{method_name}"
371
- end
372
-
373
293
  ##
374
294
  # Final threshold that is used for report
375
295
 
@@ -487,13 +407,12 @@ class Flog < SexpProcessor
487
407
  end
488
408
 
489
409
  def process_class(exp)
490
- in_klass exp.shift do
410
+ super do
491
411
  penalize_by 1.0 do
492
412
  process exp.shift # superclass expression
493
413
  end
494
414
  process_until_empty exp
495
415
  end
496
- s()
497
416
  end
498
417
 
499
418
  def process_dasgn_curr(exp) # FIX: remove
@@ -505,22 +424,6 @@ class Flog < SexpProcessor
505
424
  alias :process_iasgn :process_dasgn_curr
506
425
  alias :process_lasgn :process_dasgn_curr
507
426
 
508
- def process_defn(exp)
509
- name = @sclass.empty? ? exp.shift : "::#{exp.shift}"
510
- in_method name, exp.file, exp.line do
511
- process_until_empty exp
512
- end
513
- s()
514
- end
515
-
516
- def process_defs(exp)
517
- process exp.shift # recv
518
- in_method "::#{exp.shift}", exp.file, exp.line do
519
- process_until_empty exp
520
- end
521
- s()
522
- end
523
-
524
427
  # TODO: it's not clear to me whether this can be generated at all.
525
428
  def process_else(exp)
526
429
  add_to_score :branch
@@ -605,20 +508,13 @@ class Flog < SexpProcessor
605
508
  s()
606
509
  end
607
510
 
608
- def process_module(exp)
609
- in_klass exp.shift do
610
- process_until_empty exp
611
- end
612
- s()
613
- end
614
-
615
511
  def process_sclass(exp)
616
- @sclass.push(true)
617
- penalize_by 0.5 do
618
- process exp.shift # recv
619
- process_until_empty exp
512
+ super do
513
+ penalize_by 0.5 do
514
+ process exp.shift # recv
515
+ process_until_empty exp
516
+ end
620
517
  end
621
- @sclass.pop
622
518
 
623
519
  add_to_score :sclass
624
520
  s()
data/lib/flog_cli.rb CHANGED
@@ -115,6 +115,10 @@ class FlogCLI
115
115
  option[:quiet] = true
116
116
  end
117
117
 
118
+ opts.on("-e", "--extended", "Put file:line on a separate line (for rubymine & friends).") do
119
+ option[:extended] = true
120
+ end
121
+
118
122
  opts.on("-s", "--score", "Display total score only.") do
119
123
  option[:score] = true
120
124
  end
@@ -210,7 +214,9 @@ class FlogCLI
210
214
  def print_score io, name, score
211
215
  location = method_locations[name]
212
216
  if location then
213
- io.puts "%8.1f: %-32s %s" % [score, name, location]
217
+ sep = " "
218
+ sep = "%-11s" % "\n" if option[:extended]
219
+ io.puts "%8.1f: %-32s%s%s" % [score, name, sep, location]
214
220
  else
215
221
  io.puts "%8.1f: %s" % [score, name]
216
222
  end
data/test/test_flog.rb CHANGED
@@ -80,64 +80,6 @@ class TestFlog < FlogTest
80
80
  $stdin = old_stdin
81
81
  end
82
82
 
83
- def test_in_klass
84
- assert_empty @flog.class_stack
85
-
86
- @flog.in_klass "xxx::yyy" do
87
- assert_equal ["xxx::yyy"], @flog.class_stack
88
- end
89
-
90
- assert_empty @flog.class_stack
91
- end
92
-
93
- def test_in_method
94
- assert_empty @flog.method_stack
95
-
96
- @flog.in_method "xxx", "file.rb", 42 do
97
- assert_equal ["xxx"], @flog.method_stack
98
- end
99
-
100
- assert_empty @flog.method_stack
101
-
102
- expected = {"main#xxx" => "file.rb:42"}
103
- assert_equal expected, @flog.method_locations
104
- end
105
-
106
- def test_klass_name
107
- assert_equal :main, @flog.klass_name
108
-
109
- @flog.class_stack << "whatevs" << "flog"
110
- assert_equal "flog::whatevs", @flog.klass_name
111
- end
112
-
113
- def test_klass_name_sexp
114
- @flog.in_klass s(:colon2, s(:const, :X), :Y) do
115
- assert_equal "X::Y", @flog.klass_name
116
- end
117
-
118
- @flog.in_klass s(:colon3, :Y) do
119
- assert_equal "Y", @flog.klass_name
120
- end
121
- end
122
-
123
- def test_method_name
124
- assert_equal "#none", @flog.method_name
125
-
126
- @flog.method_stack << "whatevs"
127
- assert_equal "#whatevs", @flog.method_name
128
- end
129
-
130
- def test_method_name_cls
131
- assert_equal "#none", @flog.method_name
132
-
133
- @flog.method_stack << "::whatevs"
134
- assert_equal "::whatevs", @flog.method_name
135
- end
136
-
137
- # def test_process_until_empty
138
- # flunk "no"
139
- # end
140
-
141
83
  def test_penalize_by
142
84
  assert_equal 1, @flog.multiplier
143
85
  @flog.penalize_by 2 do
@@ -525,19 +467,6 @@ class TestFlog < FlogTest
525
467
  :branch => 4.0)
526
468
  end
527
469
 
528
- def test_signature
529
- assert_equal "main#none", @flog.signature
530
-
531
- @flog.class_stack << "X"
532
- assert_equal "X#none", @flog.signature
533
-
534
- @flog.method_stack << "y"
535
- assert_equal "X#y", @flog.signature
536
-
537
- @flog.class_stack.shift
538
- assert_equal "main#y", @flog.signature
539
- end
540
-
541
470
  def test_total_score
542
471
  @flog.add_to_score "blah", 2
543
472
  @flog.calculate_total_scores
@@ -40,6 +40,8 @@ class TestFlogCLI < FlogTest
40
40
  "--methods-only" => :methods,
41
41
  "-q" => :quiet,
42
42
  "--quiet" => :quiet,
43
+ "-e" => :extended,
44
+ "--extended" => :extended,
43
45
  "-s" => :score,
44
46
  "--score" => :score,
45
47
  "-v" => :verbose,
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flog
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 55
5
5
  prerelease:
6
6
  segments:
7
7
  - 4
8
- - 1
9
8
  - 2
10
- version: 4.1.2
9
+ - 0
10
+ version: 4.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Davis
@@ -16,9 +16,9 @@ bindir: bin
16
16
  cert_chain:
17
17
  - |
18
18
  -----BEGIN CERTIFICATE-----
19
- MIIDPjCCAiagAwIBAgIBADANBgkqhkiG9w0BAQUFADBFMRMwEQYDVQQDDApyeWFu
19
+ MIIDPjCCAiagAwIBAgIBATANBgkqhkiG9w0BAQUFADBFMRMwEQYDVQQDDApyeWFu
20
20
  ZC1ydWJ5MRkwFwYKCZImiZPyLGQBGRYJemVuc3BpZGVyMRMwEQYKCZImiZPyLGQB
21
- GRYDY29tMB4XDTA5MDMwNjE4NTMxNVoXDTEwMDMwNjE4NTMxNVowRTETMBEGA1UE
21
+ GRYDY29tMB4XDTEzMDkxNjIzMDQxMloXDTE0MDkxNjIzMDQxMlowRTETMBEGA1UE
22
22
  AwwKcnlhbmQtcnVieTEZMBcGCgmSJomT8ixkARkWCXplbnNwaWRlcjETMBEGCgmS
23
23
  JomT8ixkARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALda
24
24
  b9DCgK+627gPJkB6XfjZ1itoOQvpqH1EXScSaba9/S2VF22VYQbXU1xQXL/WzCkx
@@ -28,15 +28,15 @@ cert_chain:
28
28
  qhtV7HJxNKuPj/JFH0D2cswvzznE/a5FOYO68g+YCuFi5L8wZuuM8zzdwjrWHqSV
29
29
  gBEfoTEGr7Zii72cx+sCAwEAAaM5MDcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAw
30
30
  HQYDVR0OBBYEFEfFe9md/r/tj/Wmwpy+MI8d9k/hMA0GCSqGSIb3DQEBBQUAA4IB
31
- AQAY59gYvDxqSqgC92nAP9P8dnGgfZgLxP237xS6XxFGJSghdz/nI6pusfCWKM8m
32
- vzjjH2wUMSSf3tNudQ3rCGLf2epkcU13/rguI88wO6MrE0wi4ZqLQX+eZQFskJb/
33
- w6x9W1ur8eR01s397LSMexySDBrJOh34cm2AlfKr/jokKCTwcM0OvVZnAutaovC0
34
- l1SVZ0ecg88bsWHA0Yhh7NFxK1utWoIhtB6AFC/+trM0FQEB/jZkIS8SaNzn96Rl
35
- n0sZEf77FLf5peR8TP/PtmIg7Cyqz23sLM4mCOoTGIy5OcZ8TdyiyINUHtb5ej/T
36
- FBHgymkyj/AOSqKRIpXPhjC6
31
+ AQCFZ7JTzoy1gcG4d8A6dmOJy7ygtO5MFpRIz8HuKCF5566nOvpy7aHhDDzFmQuu
32
+ FX3zDU6ghx5cQIueDhf2SGOncyBmmJRRYawm3wI0o1MeN6LZJ/3cRaOTjSFy6+S6
33
+ zqDmHBp8fVA2TGJtO0BLNkbGVrBJjh0UPmSoGzWlRhEVnYC33TpDAbNA+u39UrQI
34
+ ynwhNN7YbnmSR7+JU2cUjBFv2iPBO+TGuWC+9L2zn3NHjuc6tnmSYipA9y8Hv+As
35
+ Y4evBVezr3SjXz08vPqRO5YRdO3zfeMT8gBjRqZjWJGMZ2lD4XNfrs7eky74CyZw
36
+ xx3n58i0lQkBE1EpKE0lFu/y
37
37
  -----END CERTIFICATE-----
38
38
 
39
- date: 2013-09-05 00:00:00 Z
39
+ date: 2013-10-18 00:00:00 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sexp_processor
@@ -46,11 +46,11 @@ dependencies:
46
46
  requirements:
47
47
  - - ~>
48
48
  - !ruby/object:Gem::Version
49
- hash: 27
49
+ hash: 19
50
50
  segments:
51
51
  - 4
52
- - 0
53
- version: "4.0"
52
+ - 4
53
+ version: "4.4"
54
54
  type: :runtime
55
55
  version_requirements: *id001
56
56
  - !ruby/object:Gem::Dependency
metadata.gz.sig CHANGED
Binary file