debride 1.10.1 → 1.11.0

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: 6967abff5ba6b28f0e9883d615830a93e7fcb2dbeb2eaafa665ececa1fed39ce
4
- data.tar.gz: b52412f613a2149775cd552e08f44f616ad1c5c89d0ae3fa1dca6f3ce0ffabeb
3
+ metadata.gz: a3d7a09de612d4aa5772fbc3db3e26f51a06331c360c62d359acb8465f3f242a
4
+ data.tar.gz: 95ce5aff93c1900456ad929a959d60f275feb036ecbb890edd590246d284c5eb
5
5
  SHA512:
6
- metadata.gz: fc77db06b93e7401cb6a723b1db1532e6c75fba1216301bb4037ae5c6516fcc577931186f1a9ebc9a4fb452403b92f984ab7dca1abcb312cfb0c921d400f32fd
7
- data.tar.gz: 48a62586d3131f682447f5855276ab43e9de334ea791c8d2afa6e9bd49e3ff77007b3be10c00c03f934648f97f62a71871db69169060be3b4a92d432d364495b
6
+ metadata.gz: b8c4f5575198e3d8de1c7486cf5b2a6e43e2f2d8ec61af07b3e6d8f5e101cd5343acb108a55468b1e19e8605c3c27acad32918084c4165a666f58e6d367fb72b
7
+ data.tar.gz: 17dbd73820e02cea048e1cdc61d4811e3d00702f0d2fcc58098e56982205b80e1932cf6358d3692a7647da0de67251c2cab22e274598b420eae48cedeff94726
checksums.yaml.gz.sig CHANGED
Binary file
data/History.rdoc CHANGED
@@ -1,3 +1,14 @@
1
+ === 1.11.0 / 2023-03-24
2
+
3
+ * 6 minor enhancements:
4
+
5
+ * Added X.const_get(:Y) support. (TSMMark)
6
+ * Added f(&block_pass) support. (TSMMark)
7
+ * Added obj&.safe_call support. (TSMMark)
8
+ * Added obj.method(:msg) support. (TSMMark)
9
+ * Added op_asgn2 (eg x &&= y) support. (TSMMark)
10
+ * Added try(:msg) support. (TSMMark)
11
+
1
12
  === 1.10.1 / 2022-12-03
2
13
 
3
14
  * 4 minor enhancements:
data/lib/debride.rb CHANGED
@@ -12,7 +12,7 @@ require "path_expander"
12
12
  # A static code analyzer that points out possible dead methods.
13
13
 
14
14
  class Debride < MethodBasedSexpProcessor
15
- VERSION = "1.10.1" # :nodoc:
15
+ VERSION = "1.11.0" # :nodoc:
16
16
  PROJECT = "debride"
17
17
 
18
18
  def self.load_plugins proj = PROJECT
@@ -220,6 +220,14 @@ class Debride < MethodBasedSexpProcessor
220
220
  sexp
221
221
  end
222
222
 
223
+ # handle &&=, ||=, etc
224
+ def process_op_asgn2(sexp)
225
+ _, _, method_name, * = sexp
226
+ called << method_name
227
+ process_until_empty sexp
228
+ sexp
229
+ end
230
+
223
231
  def record_method name, file, line
224
232
  signature = "#{klass_name}##{name}"
225
233
  method_locations[signature] = "#{file}:#{line}"
@@ -273,7 +281,7 @@ class Debride < MethodBasedSexpProcessor
273
281
  end
274
282
  record_method name, file, line
275
283
  end
276
- when :send, :public_send, :__send__ then
284
+ when :send, :public_send, :__send__, :try, :const_get then
277
285
  # s(:call, s(:const, :Seattle), :send, s(:lit, :raining?))
278
286
  _, _, _, msg_arg, * = sexp
279
287
  if Sexp === msg_arg && [:lit, :str].include?(msg_arg.sexp_type) then
@@ -291,6 +299,12 @@ class Debride < MethodBasedSexpProcessor
291
299
  called << val.last.to_sym if val.sexp_type == :str
292
300
  end
293
301
  end
302
+ when :method then
303
+ # s(:call, nil, :method, s(:lit, :foo))
304
+ _, _, _, msg_arg, * = sexp
305
+ if Sexp === msg_arg && [:lit, :str].include?(msg_arg.sexp_type) then
306
+ called << msg_arg.last.to_sym
307
+ end
294
308
  when *RAILS_DSL_METHODS, *RAILS_VALIDATION_METHODS then
295
309
  if option[:rails]
296
310
  # s(:call, nil, :before_save, s(:lit, :save_callback), s(:hash, ...))
@@ -329,6 +343,21 @@ class Debride < MethodBasedSexpProcessor
329
343
  sexp
330
344
  end
331
345
 
346
+ def process_block_pass exp # :nodoc:
347
+ _, name = exp
348
+
349
+ case name.sexp_type
350
+ when :lit then # eg &:to_sym
351
+ called << name.last
352
+ else # eg &lvar or &method(:x)
353
+ # do nothing, body will get processed below
354
+ end
355
+
356
+ process_until_empty exp
357
+
358
+ exp
359
+ end
360
+
332
361
  def process_cdecl exp # :nodoc:
333
362
  _, name, val = exp
334
363
 
@@ -348,7 +377,7 @@ class Debride < MethodBasedSexpProcessor
348
377
 
349
378
  def name_to_string exp
350
379
  case exp.sexp_type
351
- when :const then
380
+ when :const, :lit, :str then
352
381
  exp.last.to_s
353
382
  when :colon2 then
354
383
  _, lhs, rhs = exp
@@ -402,6 +431,8 @@ class Debride < MethodBasedSexpProcessor
402
431
  end
403
432
  end
404
433
 
434
+ alias process_safe_call process_call
435
+
405
436
  ##
406
437
  # Calculate the difference between known methods and called methods.
407
438
 
@@ -532,6 +563,10 @@ class Debride < MethodBasedSexpProcessor
532
563
  YAML.dump data, io
533
564
  end
534
565
 
566
+ def inspect
567
+ "Debride[current=%s]" % [signature]
568
+ end
569
+
535
570
  ##
536
571
  # Rails' macro-style methods that setup method calls to happen during a rails
537
572
  # app's execution.
@@ -541,7 +576,7 @@ class Debride < MethodBasedSexpProcessor
541
576
  :around_action,
542
577
  :before_action,
543
578
 
544
- # http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html
579
+ # https://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html
545
580
  :after_commit,
546
581
  :after_create,
547
582
  :after_destroy,
@@ -562,7 +597,7 @@ class Debride < MethodBasedSexpProcessor
562
597
  :before_update,
563
598
  :before_validation,
564
599
 
565
- # http://api.rubyonrails.org/classes/ActiveModel/Validations/ClassMethods.html#method-i-validate
600
+ # https://api.rubyonrails.org/classes/ActiveModel/Validations/ClassMethods.html#method-i-validate
566
601
  :validate,
567
602
  ]
568
603
 
data/test/test_debride.rb CHANGED
@@ -10,6 +10,7 @@ end
10
10
  class TestDebride < Minitest::Test
11
11
  EXP_LIST = [["Debride",
12
12
  [:process_attrasgn,
13
+ :process_block_pass,
13
14
  :process_call,
14
15
  :process_cdecl,
15
16
  :process_colon2,
@@ -17,6 +18,7 @@ class TestDebride < Minitest::Test
17
18
  :process_const,
18
19
  :process_defn,
19
20
  :process_defs,
21
+ :process_op_asgn2,
20
22
  :process_rb,
21
23
  :report,
22
24
  :report_json,
@@ -287,6 +289,83 @@ class TestDebride < Minitest::Test
287
289
  assert_process [], ruby
288
290
  end
289
291
 
292
+ def test_method_try
293
+ ruby = <<-RUBY.strip
294
+ class Seattle
295
+ def self.raining?
296
+ true
297
+ end
298
+ end
299
+
300
+ Seattle.try :raining?
301
+ RUBY
302
+
303
+ assert_process [], ruby
304
+ end
305
+
306
+ def test_block_pass
307
+ ruby = <<-RUBY.strip
308
+ class Seattle
309
+ def self.raining?
310
+ true
311
+ end
312
+ end
313
+
314
+ [Seattle].each(&:raining?)
315
+ RUBY
316
+
317
+ assert_process [], ruby
318
+ end
319
+
320
+ def test_block_pass_other
321
+ ruby = <<-RUBY.strip
322
+ class Seattle
323
+ def self.raining?
324
+ -> { called }
325
+ end
326
+
327
+ def self.uncalled; end
328
+ def self.called; end
329
+ end
330
+
331
+ f(&Seattle.raining?)
332
+ RUBY
333
+
334
+ assert_process [["Seattle", [:uncalled]]], ruby
335
+ end
336
+
337
+ def test_safe_navigation_operator
338
+ ruby = <<-RUBY.strip
339
+ class Seattle
340
+ def self.raining?
341
+ true
342
+ end
343
+ end
344
+
345
+ Seattle&.raining?
346
+ RUBY
347
+
348
+ assert_process [], ruby
349
+ end
350
+
351
+ def test_call_method
352
+ ruby = <<-RUBY.strip
353
+ class Seattle
354
+ def self.raining?
355
+ true
356
+ end
357
+
358
+ def self.raining_still?
359
+ method(:raining?)
360
+ end
361
+ end
362
+
363
+ Seattle.raining_still?
364
+ RUBY
365
+
366
+ assert_process [], ruby
367
+ end
368
+
290
369
  def test_rails_dsl_methods
291
370
  ruby = <<-RUBY.strip
292
371
  class RailsThing
@@ -360,6 +439,8 @@ class TestDebride < Minitest::Test
360
439
  class Constants
361
440
  USED = 42
362
441
  ALSO = 314
442
+ AGAIN = 27
443
+ MORE = 72
363
444
  UNUSED = 24
364
445
 
365
446
  def something
@@ -370,6 +451,8 @@ class TestDebride < Minitest::Test
370
451
  something
371
452
  Constants::ALSO
372
453
  ::Constants::ALSO
454
+ Constants.const_get(:AGAIN)
455
+ ::Constants.const_get("MORE")
373
456
  RUBY
374
457
 
375
458
  assert_process [["Constants", [:UNUSED]]], ruby
@@ -379,11 +462,13 @@ class TestDebride < Minitest::Test
379
462
  ruby = <<-RUBY.strip
380
463
  class AttributeAccessor
381
464
  attr_accessor :a1, :a2, :a3
382
- attr_writer :w1, :w2
465
+ attr_writer :w1, :w2, :w3, :w4
383
466
  attr_reader :r1, :r2
384
467
  def initialize
385
468
  self.a2 = 'Bar'
386
469
  self.w1 = 'W'
470
+ self.w3 ||= 'W3'
471
+ self.w4 &&= 'W4'
387
472
  end
388
473
 
389
474
  def self.class_method
@@ -397,7 +482,10 @@ class TestDebride < Minitest::Test
397
482
  object.a3 = 'Baz'
398
483
  RUBY
399
484
 
400
- d = assert_process [["AttributeAccessor", [:a1=, :a2, :a3, :class_method, :r2, :w2=]]], ruby
485
+ exp = [["AttributeAccessor",
486
+ [:a1=, :a2, :a3, :class_method, :r2, :w2=]]]
487
+
488
+ d = assert_process exp, ruby
401
489
 
402
490
  exp = {
403
491
  "AttributeAccessor#a1" => "(io):2",
@@ -408,10 +496,12 @@ class TestDebride < Minitest::Test
408
496
  "AttributeAccessor#a3=" => "(io):2",
409
497
  "AttributeAccessor#w1=" => "(io):3",
410
498
  "AttributeAccessor#w2=" => "(io):3",
499
+ "AttributeAccessor#w3=" => "(io):3",
500
+ "AttributeAccessor#w4=" => "(io):3",
411
501
  "AttributeAccessor#r1" => "(io):4",
412
502
  "AttributeAccessor#r2" => "(io):4",
413
- "AttributeAccessor#initialize" => "(io):5-7",
414
- "AttributeAccessor::class_method" => "(io):10-11"
503
+ "AttributeAccessor#initialize" => "(io):5-9",
504
+ "AttributeAccessor::class_method" => "(io):12-13"
415
505
  }
416
506
 
417
507
  assert_equal exp, d.method_locations
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debride
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.1
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -10,9 +10,9 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDPjCCAiagAwIBAgIBBjANBgkqhkiG9w0BAQsFADBFMRMwEQYDVQQDDApyeWFu
13
+ MIIDPjCCAiagAwIBAgIBBzANBgkqhkiG9w0BAQsFADBFMRMwEQYDVQQDDApyeWFu
14
14
  ZC1ydWJ5MRkwFwYKCZImiZPyLGQBGRYJemVuc3BpZGVyMRMwEQYKCZImiZPyLGQB
15
- GRYDY29tMB4XDTIxMTIyMzIzMTkwNFoXDTIyMTIyMzIzMTkwNFowRTETMBEGA1UE
15
+ GRYDY29tMB4XDTIzMDEwMTA3NTExN1oXDTI0MDEwMTA3NTExN1owRTETMBEGA1UE
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
- AQCKB5jfsuSnKb+t/Wrh3UpdkmX7TrEsjVmERC0pPqzQ5GQJgmEXDD7oMgaKXaAq
26
- x2m+KSZDrqk7c8uho5OX6YMqg4KdxehfSLqqTZGoeV78qwf/jpPQZKTf+W9gUSJh
27
- zsWpo4K50MP+QtdSbKXZwjAafpQ8hK0MnnZ/aeCsW9ov5vdXpYbf3dpg6ADXRGE7
28
- lQY2y1tJ5/chqu6h7dQmnm2ABUqx9O+JcN9hbCYoA5i/EeubUEtFIh2w3SpO6YfB
29
- JFmxn4h9YO/pVdB962BdBNNDia0kgIjI3ENnkLq0dKpYU3+F3KhEuTksLO0L6X/V
30
- YsuyUzsMz6GQA4khyaMgKNSD
25
+ AQAkg3y+PBnBAPWdxxITm5sPHqdWQgSyCpRA20o4LTuWr8BWhSXBkfQNa7cY6fOn
26
+ xyM34VPzBFbExv6XOGDfOMFBVaYTHuN9peC/5/umL7kLl+nflXzL2QA7K6LYj5Bg
27
+ sM574Onr0dZDM6Vn69bzQ7rBIFDfK/OhlPzqKZad4nsdcsVH8ODCiT+ATMIZyz5K
28
+ WCnNtqlyiWXI8tdTpahDgcUwfcN/oN7v4K8iU5IbLJX6HQ5DKgmKjfb6XyMth16k
29
+ ROfWo9Uyp8ba/j9eVG14KkYRaLydAY1MNQk2yd3R5CGfeOpD1kttxjoypoUJ2dOG
30
+ nsNBRuQJ1UfiCG97a6DNm+Fr
31
31
  -----END CERTIFICATE-----
32
- date: 2022-12-03 00:00:00.000000000 Z
32
+ date: 2023-03-24 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: sexp_processor
@@ -113,14 +113,14 @@ dependencies:
113
113
  requirements:
114
114
  - - "~>"
115
115
  - !ruby/object:Gem::Version
116
- version: '3.25'
116
+ version: '4.0'
117
117
  type: :development
118
118
  prerelease: false
119
119
  version_requirements: !ruby/object:Gem::Requirement
120
120
  requirements:
121
121
  - - "~>"
122
122
  - !ruby/object:Gem::Version
123
- version: '3.25'
123
+ version: '4.0'
124
124
  description: Analyze code for potentially uncalled / dead methods, now with auto-removal.
125
125
  email:
126
126
  - ryand-ruby@zenspider.com
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
166
  - !ruby/object:Gem::Version
167
167
  version: '0'
168
168
  requirements: []
169
- rubygems_version: 3.3.12
169
+ rubygems_version: 3.4.6
170
170
  signing_key:
171
171
  specification_version: 4
172
172
  summary: Analyze code for potentially uncalled / dead methods, now with auto-removal.
metadata.gz.sig CHANGED
Binary file