flog 4.6.3 → 4.6.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71073335bad47948fc2c595a09ae883aeb2fbc119056c9ddd9922c374d278199
4
- data.tar.gz: 5c224d4e435702cd05363f78a5103139f43aed18a6e257c50f6917215bdd2ffa
3
+ metadata.gz: a6889c4ee131417e7461cd689e54af4a037d36ee3a854e037c9e453e7a19dee0
4
+ data.tar.gz: ee5fc40d4423a82b4b48db87b9bd02fac8006f4b5ac6e6f4701005a82412b451
5
5
  SHA512:
6
- metadata.gz: da67084a75b7bbff54bb536abaeaac2b63be971cd1d11b74cafd340175b70a2a0d149d840300cd920100c2e691d5e68ed95a72f8fe1c80602def3647f761c0d3
7
- data.tar.gz: 2b2b77800a343ae038ebe6499720bc7fcc18f3fff899c07c5d14c011f1456d4d2d8bceab33da9ce6ceff8d7c96d907942842696812081d0d1bd7293ff9357bd7
6
+ metadata.gz: a6b0a38246e5869182caf800b6e1bacb4bd442c06746d8aac8c4223528d58bf8c588909689f5424f05de6cfbe1ed97f12d89025fe2d3a2b195ea6508326d8691
7
+ data.tar.gz: 485e289aec33bf39a30b8361d42eaec662de13bbca5c72b3058a9f0e31375ce1b55cacb270b00551b671e59f031f9b861af50b03abeb155af4d079d0f325dbbf
checksums.yaml.gz.sig CHANGED
Binary file
data/History.rdoc CHANGED
@@ -1,3 +1,31 @@
1
+ === 4.6.6 / 2022-07-03
2
+
3
+ * 1 minor enhancement:
4
+
5
+ * Added support for to_proc w/ hash(?!?). (t-kinoshita)
6
+
7
+ * 2 bug fixes:
8
+
9
+ * Removed to_proc_normal (eg &:sym/call) as benchmarks are much better.
10
+ * ruby3: Fixed anonymous block pass. (prtngn)
11
+
12
+ === 4.6.5 / 2022-04-09
13
+
14
+ * 1 minor enhancement:
15
+
16
+ * Changed :iter scoring from branch to block_call (same score).
17
+
18
+ * 1 bug fix:
19
+
20
+ * Fixed support for ruby 3 (only affected block_pass / to_proc_normal).
21
+
22
+ === 4.6.4 / 2019-12-14
23
+
24
+ * 2 minor enhancements:
25
+
26
+ * Added basic support for safe_call (nic-potter).
27
+ * Added extra complexity penalty to safe_call processing.
28
+
1
29
  === 4.6.3 / 2019-09-14
2
30
 
3
31
  * 1 minor enhancement:
data/Rakefile CHANGED
@@ -7,12 +7,13 @@ Hoe.add_include_dirs("../../ruby_parser/dev/lib",
7
7
  "../../RubyInline/dev/lib",
8
8
  "../../sexp_processor/dev/lib",
9
9
  "../../ZenTest/dev/lib",
10
- "../../minitest/dev/lib",
11
10
  "../../path_expander/dev/lib",
12
11
  "lib")
13
12
 
14
13
  Hoe.plugin :seattlerb
14
+ Hoe.plugin :isolate
15
15
  Hoe.plugin :rdoc
16
+ Hoe.plugin :bundler
16
17
 
17
18
  Hoe.spec 'flog' do
18
19
  developer 'Ryan Davis', 'ryand-ruby@zenspider.com'
@@ -25,6 +26,8 @@ Hoe.spec 'flog' do
25
26
  dependency "sexp_processor", "~> 4.8"
26
27
  dependency "ruby_parser", ["~> 3.1", "> 3.1.0"]
27
28
  dependency "path_expander", "~> 1.0"
29
+
30
+ dependency "minitest", "~> 5.0", :dev
28
31
  end
29
32
 
30
33
  task :debug do
@@ -51,9 +54,12 @@ task :debug do
51
54
  exit 0
52
55
  end
53
56
  flog.flog file
54
- else
57
+ elsif ruby
55
58
  flog.flog_ruby ruby, "-"
56
59
  flog.calculate_total_scores
60
+ else
61
+ flog.flog
62
+ flog.calculate_total_scores
57
63
  end
58
64
 
59
65
  flog.report
data/lib/flog.rb CHANGED
@@ -11,7 +11,7 @@ class File
11
11
  end
12
12
 
13
13
  class Flog < MethodBasedSexpProcessor
14
- VERSION = "4.6.3" # :nodoc:
14
+ VERSION = "4.6.6" # :nodoc:
15
15
 
16
16
  ##
17
17
  # Cut off point where the report should stop unless --all given.
@@ -38,22 +38,13 @@ class Flog < MethodBasedSexpProcessor
38
38
  :assignment => 1,
39
39
  :block => 1,
40
40
  :block_pass => 1,
41
+ :block_call => 1,
41
42
  :branch => 1,
42
43
  :lit_fixnum => 0.25,
43
44
  :sclass => 5,
44
45
  :super => 1,
45
46
  :to_proc_icky! => 10,
46
47
  :to_proc_lasgn => 15,
47
- :to_proc_normal => case RUBY_VERSION
48
- when /^1\.8\.7/ then
49
- 2
50
- when /^1\.9/ then
51
- 1.5
52
- when /^2\./ then
53
- 1
54
- else
55
- 5
56
- end,
57
48
  :yield => 1,
58
49
  }
59
50
 
@@ -175,9 +166,9 @@ class Flog < MethodBasedSexpProcessor
175
166
 
176
167
  def flog(*files)
177
168
  files.each do |file|
178
- next unless file == '-' or File.readable? file
169
+ next unless file == "-" or File.readable? file
179
170
 
180
- ruby = file == '-' ? $stdin.read : File.binread(file)
171
+ ruby = file == "-" ? $stdin.read : File.binread(file)
181
172
 
182
173
  flog_ruby ruby, file
183
174
  end
@@ -198,7 +189,7 @@ class Flog < MethodBasedSexpProcessor
198
189
  q = option[:quiet]
199
190
  if e.inspect =~ /<\%|%\>/ or ruby =~ /<\%|%\>/ then
200
191
  return if q
201
- warn "#{e.inspect} at #{e.backtrace.first(5).join(', ')}"
192
+ warn "#{e.inspect} at #{e.backtrace.first(5).join(", ")}"
202
193
  warn "\n...stupid lemmings and their bad erb templates... skipping"
203
194
  else
204
195
  warn "ERROR: parsing ruby file #{file}" unless q
@@ -288,7 +279,7 @@ class Flog < MethodBasedSexpProcessor
288
279
  tally.each do |cat, score|
289
280
  case cat
290
281
  when :assignment then a += score
291
- when :branch then b += score
282
+ when :branch, :block_call then b += score
292
283
  else c += score
293
284
  end
294
285
  end
@@ -364,18 +355,23 @@ class Flog < MethodBasedSexpProcessor
364
355
 
365
356
  add_to_score :block_pass
366
357
 
358
+ return s() unless arg
359
+
367
360
  case arg.sexp_type
368
361
  when :lvar, :dvar, :ivar, :cvar, :self, :const, :colon2, :nil then # f(&b)
369
362
  # do nothing
370
- when :lit, :call then # f(&:b)
371
- add_to_score :to_proc_normal
363
+ when :lit then # f(&:b)
364
+ # do nothing -- this now costs about the same as a block
365
+ when :call then # f(&x.b)
366
+ # do nothing -- I don't like the indirection, but that's already scored
372
367
  when :lasgn then # f(&l=b)
373
368
  add_to_score :to_proc_lasgn
374
- when :iter, :dsym, :dstr, *BRANCHING then # below
369
+ when :iter, :dsym, :dstr, :hash, *BRANCHING then # below
375
370
  # f(&proc { ... })
376
371
  # f(&"#{...}")
377
372
  # f(&:"#{...}")
378
373
  # f(&if ... then ... end") and all other branching forms
374
+ # f(&{ a: 42 }) WHY?!?
379
375
  add_to_score :to_proc_icky!
380
376
  else
381
377
  raise({:block_pass_even_ickier! => arg}.inspect)
@@ -402,6 +398,22 @@ class Flog < MethodBasedSexpProcessor
402
398
  s()
403
399
  end
404
400
 
401
+ def process_safe_call(exp)
402
+ penalize_by 0.3 do
403
+ process exp.shift # recv
404
+ end
405
+
406
+ name = exp.shift
407
+
408
+ penalize_by 0.2 do
409
+ process_until_empty exp
410
+ end
411
+
412
+ add_to_score name, SCORES[name]
413
+
414
+ s()
415
+ end
416
+
405
417
  def process_case(exp)
406
418
  add_to_score :branch
407
419
  process exp.shift # recv
@@ -477,7 +489,7 @@ class Flog < MethodBasedSexpProcessor
477
489
  end
478
490
  end
479
491
 
480
- add_to_score :branch
492
+ add_to_score :block_call
481
493
 
482
494
  process exp.shift # no penalty for LHS
483
495
 
data/test/test_flog.rb CHANGED
@@ -127,25 +127,24 @@ class TestFlog < FlogTest
127
127
  assert_process sexp, 1.1, :branch => 1.1 # 10% penalty over process_and
128
128
  end
129
129
 
130
- def test_process_block_pass
130
+ def test_process_block_pass__call
131
131
  sexp = s(:call, nil, :a,
132
132
  s(:block_pass,
133
133
  s(:call, nil, :b)))
134
134
 
135
- bonus = case RUBY_VERSION
136
- when /^1\.8\.7/ then 0.4
137
- when /^1\.9/ then 0.3
138
- when /^2\./ then 0.2
139
- else raise "Unhandled version #{RUBY_VERSION}"
140
- end
135
+ assert_process(sexp, 3.4,
136
+ :a => 1.0,
137
+ :block_pass => 1.2,
138
+ :b => 1.2)
139
+ end
141
140
 
142
- bonus += Flog::OTHER_SCORES[:to_proc_normal]
141
+ def test_process_block_pass__to_proc
142
+ sexp = s(:call, nil, :a,
143
+ s(:block_pass, s(:lit, :to_i)))
143
144
 
144
- assert_process(sexp, 3.4 + bonus,
145
+ assert_process(sexp, 2.2,
145
146
  :a => 1.0,
146
- :block_pass => 1.2,
147
- :b => 1.2,
148
- :to_proc_normal => 0.0 + bonus)
147
+ :block_pass => 1.2)
149
148
  end
150
149
 
151
150
  def test_process_block_pass_colon2
@@ -158,6 +157,17 @@ class TestFlog < FlogTest
158
157
  :block_pass => 1.2)
159
158
  end
160
159
 
160
+ def test_process_block_pass__hash_wtf
161
+ sexp = s(:call, nil, :a,
162
+ s(:block_pass,
163
+ s(:hash, s(:lit, :a), s(:lit, :b))))
164
+
165
+ assert_process(sexp, 14.2,
166
+ :a => 1.0,
167
+ :block_pass => 1.2,
168
+ :to_proc_icky! => 12.0)
169
+ end
170
+
161
171
  def test_process_block_pass_iter
162
172
  sexp = s(:block_pass,
163
173
  s(:iter, s(:call, nil, :lambda), nil, s(:lit, 1)))
@@ -166,7 +176,7 @@ class TestFlog < FlogTest
166
176
  :lit_fixnum => 0.275,
167
177
  :block_pass => 1.0,
168
178
  :lambda => 1.0,
169
- :branch => 1.0,
179
+ :block_call => 1.0,
170
180
  :to_proc_icky! => 10.0)
171
181
  end
172
182
 
@@ -181,15 +191,43 @@ class TestFlog < FlogTest
181
191
  :block_pass => 1.0,
182
192
  :lambda => 1.0,
183
193
  :assignment => 1.0,
184
- :branch => 1.0,
194
+ :block_call => 1.0,
185
195
  :to_proc_lasgn => 15.0)
186
196
  end
187
197
 
198
+ def test_process_block_pass__nil
199
+ sexp = s(:block_pass)
200
+
201
+ assert_process(sexp, 1.0,
202
+ :block_pass => 1.0)
203
+ end
204
+
188
205
  def test_process_call
189
- sexp = s(:call, nil, :a)
206
+ sexp = s(:call, nil, :a) # a
190
207
  assert_process sexp, 1.0, :a => 1.0
191
208
  end
192
209
 
210
+ def test_process_call2
211
+ sexp = s(:call, s(:call, nil, :a), :b) # a.b
212
+ assert_process sexp, 2.2, :a => 1.2, :b => 1.0
213
+ end
214
+
215
+ def test_process_call3
216
+ sexp = s(:call, s(:call, s(:call, nil, :a), :b), :c) # a.b.c
217
+ assert_process sexp, 3.6, :a => 1.4, :b => 1.2, :c => 1.0
218
+ end
219
+
220
+ def test_process_safe_call2
221
+ sexp = s(:safe_call, s(:call, nil, :a), :b) # a&.b
222
+ assert_process sexp, 2.3, :a => 1.3, :b => 1.0
223
+ end
224
+
225
+ def test_process_safe_call3
226
+ sexp = s(:safe_call, s(:safe_call, s(:call, nil, :a), :b), :c) # a&.b&.c
227
+
228
+ assert_process sexp, 3.9, :a => 1.6, :b => 1.3, :c => 1.0
229
+ end
230
+
193
231
  def test_process_case
194
232
  case :a
195
233
  when :a
@@ -303,7 +341,7 @@ class TestFlog < FlogTest
303
341
  s(:call, nil, :loop), nil,
304
342
  s(:if, s(:true), s(:break), nil))
305
343
 
306
- assert_process sexp, 2.326, :loop => 1.0, :branch => 2.1
344
+ assert_process sexp, 2.326, :loop => 1.0, :branch => 1.1, :block_call => 1
307
345
  end
308
346
 
309
347
  def test_process_iter_dsl
@@ -351,6 +389,19 @@ class TestFlog < FlogTest
351
389
  assert_process sexp, 2.3, :something => 1.0, :task => 1.0, :lit_fixnum => 0.3
352
390
  end
353
391
 
392
+ def test_process_iter_dsl_hash_when_hash_empty
393
+ # task({}) do
394
+ # something
395
+ # end
396
+
397
+ sexp = s(:iter,
398
+ s(:call, nil, :task, s(:hash)),
399
+ nil,
400
+ s(:call, nil, :something))
401
+
402
+ assert_process sexp, 2.326, :something => 1.1, :task => 1.0, :block_call => 1
403
+ end
404
+
354
405
  def test_process_iter_dsl_namespaced
355
406
  # namespace :blah do
356
407
  # task :woot => 42 do
@@ -1,4 +1,4 @@
1
- require "test/test_flog"
1
+ require "test_flog"
2
2
  require "flog_cli"
3
3
 
4
4
  class FlogCLI
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flog
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.6.3
4
+ version: 4.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDPjCCAiagAwIBAgIBAzANBgkqhkiG9w0BAQsFADBFMRMwEQYDVQQDDApyeWFu
13
+ MIIDPjCCAiagAwIBAgIBBjANBgkqhkiG9w0BAQsFADBFMRMwEQYDVQQDDApyeWFu
14
14
  ZC1ydWJ5MRkwFwYKCZImiZPyLGQBGRYJemVuc3BpZGVyMRMwEQYKCZImiZPyLGQB
15
- GRYDY29tMB4XDTE4MTIwNDIxMzAxNFoXDTE5MTIwNDIxMzAxNFowRTETMBEGA1UE
15
+ GRYDY29tMB4XDTIxMTIyMzIzMTkwNFoXDTIyMTIyMzIzMTkwNFowRTETMBEGA1UE
16
16
  AwwKcnlhbmQtcnVieTEZMBcGCgmSJomT8ixkARkWCXplbnNwaWRlcjETMBEGCgmS
17
17
  JomT8ixkARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALda
18
18
  b9DCgK+627gPJkB6XfjZ1itoOQvpqH1EXScSaba9/S2VF22VYQbXU1xQXL/WzCkx
@@ -22,14 +22,14 @@ cert_chain:
22
22
  qhtV7HJxNKuPj/JFH0D2cswvzznE/a5FOYO68g+YCuFi5L8wZuuM8zzdwjrWHqSV
23
23
  gBEfoTEGr7Zii72cx+sCAwEAAaM5MDcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAw
24
24
  HQYDVR0OBBYEFEfFe9md/r/tj/Wmwpy+MI8d9k/hMA0GCSqGSIb3DQEBCwUAA4IB
25
- AQCbJwLmpJR2PomLU+Zzw3KRzH/hbyUWc/ftru71AopZ1fy4iY9J/BW5QYKVYwbP
26
- V0FSBWtvfI/RdwfKGtuGhPKECZgmLieGuZ3XCc09qPu1bdg7i/tu1p0t0c6163ku
27
- nDMDIC/t/DAFK0TY9I3HswuyZGbLW7rgF0DmiuZdN/RPhHq2pOLMLXJmFclCb/im
28
- 9yToml/06TJdUJ5p64mkBs0TzaK66DIB1Smd3PdtfZqoRV+EwaXMdx0Hb3zdR1JR
29
- Em82dBUFsipwMLCYj39kcyHWAxyl6Ae1Cn9r/ItVBCxoeFdrHjfavnrIEoXUt4bU
30
- UfBugfLD19bu3nvL+zTAGx/U
25
+ AQCKB5jfsuSnKb+t/Wrh3UpdkmX7TrEsjVmERC0pPqzQ5GQJgmEXDD7oMgaKXaAq
26
+ x2m+KSZDrqk7c8uho5OX6YMqg4KdxehfSLqqTZGoeV78qwf/jpPQZKTf+W9gUSJh
27
+ zsWpo4K50MP+QtdSbKXZwjAafpQ8hK0MnnZ/aeCsW9ov5vdXpYbf3dpg6ADXRGE7
28
+ lQY2y1tJ5/chqu6h7dQmnm2ABUqx9O+JcN9hbCYoA5i/EeubUEtFIh2w3SpO6YfB
29
+ JFmxn4h9YO/pVdB962BdBNNDia0kgIjI3ENnkLq0dKpYU3+F3KhEuTksLO0L6X/V
30
+ YsuyUzsMz6GQA4khyaMgKNSD
31
31
  -----END CERTIFICATE-----
32
- date: 2019-09-15 00:00:00.000000000 Z
32
+ date: 2022-07-04 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: sexp_processor
@@ -49,22 +49,22 @@ dependencies:
49
49
  name: ruby_parser
50
50
  requirement: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">"
53
- - !ruby/object:Gem::Version
54
- version: 3.1.0
55
52
  - - "~>"
56
53
  - !ruby/object:Gem::Version
57
54
  version: '3.1'
55
+ - - ">"
56
+ - !ruby/object:Gem::Version
57
+ version: 3.1.0
58
58
  type: :runtime
59
59
  prerelease: false
60
60
  version_requirements: !ruby/object:Gem::Requirement
61
61
  requirements:
62
- - - ">"
63
- - !ruby/object:Gem::Version
64
- version: 3.1.0
65
62
  - - "~>"
66
63
  - !ruby/object:Gem::Version
67
64
  version: '3.1'
65
+ - - ">"
66
+ - !ruby/object:Gem::Version
67
+ version: 3.1.0
68
68
  - !ruby/object:Gem::Dependency
69
69
  name: path_expander
70
70
  requirement: !ruby/object:Gem::Requirement
@@ -79,6 +79,20 @@ dependencies:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
81
  version: '1.0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: minitest
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '5.0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '5.0'
82
96
  - !ruby/object:Gem::Dependency
83
97
  name: rdoc
84
98
  requirement: !ruby/object:Gem::Requirement
@@ -105,14 +119,14 @@ dependencies:
105
119
  requirements:
106
120
  - - "~>"
107
121
  - !ruby/object:Gem::Version
108
- version: '3.18'
122
+ version: '3.24'
109
123
  type: :development
110
124
  prerelease: false
111
125
  version_requirements: !ruby/object:Gem::Requirement
112
126
  requirements:
113
127
  - - "~>"
114
128
  - !ruby/object:Gem::Version
115
- version: '3.18'
129
+ version: '3.24'
116
130
  description: |-
117
131
  Flog reports the most tortured code in an easy to read pain
118
132
  report. The higher the score, the more pain the code is in.
@@ -141,8 +155,10 @@ files:
141
155
  homepage: http://ruby.sadi.st/
142
156
  licenses:
143
157
  - MIT
144
- metadata: {}
145
- post_install_message:
158
+ metadata:
159
+ homepage_uri: http://ruby.sadi.st/
160
+ source_code_uri: https://github.com/seattlerb/flog
161
+ post_install_message:
146
162
  rdoc_options:
147
163
  - "--main"
148
164
  - README.rdoc
@@ -159,8 +175,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
175
  - !ruby/object:Gem::Version
160
176
  version: '0'
161
177
  requirements: []
162
- rubygems_version: 3.0.6
163
- signing_key:
178
+ rubygems_version: 3.3.12
179
+ signing_key:
164
180
  specification_version: 4
165
181
  summary: Flog reports the most tortured code in an easy to read pain report
166
182
  test_files: []
metadata.gz.sig CHANGED
Binary file