debride 1.9.0 → 1.10.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c2b2a4fb03bd2f6f8a5406f0b413e3159b49ac6a9b0c3641bedc7a6e724a548
4
- data.tar.gz: cdeb2dc596fe5e496ed940a989fe84f482480c2a2cc7436228e1c4b07755ccbf
3
+ metadata.gz: 59c8a2f9b5b719c39af3b257881dbc7440f7f1c7000b4e55efdb411120f7cbde
4
+ data.tar.gz: 398c595e7080ecab2a3c2195f7a5176c4a4f19ecf517543a9fdc6d7b9dfe3eb4
5
5
  SHA512:
6
- metadata.gz: a11b67c7d6a82313be67dbb1680c54ab9f9db3e0f769ab2ce96980ebfb696cc5dd607d6107cb0cc00c9a5c966553439deea89fa0acd13be83707e6393b52070b
7
- data.tar.gz: f2f4eb04d9c348109b88fcca245233554bae0febe496ead9c08622653add4a2cdd10bb4405b7bff9cc308972d5cc46f46241aa56162976d2f89cf03c4ba9e2d4
6
+ metadata.gz: dce7e6ad57ab80693a10c2292192515ced017a6e944aa12c2fde55f766d818357bdc4e7b9c99ab14348a6039a299e3fecd3d105e3a02e544cabba0e5e03d54e5
7
+ data.tar.gz: bc1ec0cf4667aedfc5a85fbf076e3442f08d9acfc7ed2b4e480308f59a6301defcab4222f330f53832af693139aa324ab3cc83ad2d8bc80d1fa63c6e1edc0f18
checksums.yaml.gz.sig CHANGED
Binary file
data/Rakefile CHANGED
@@ -13,6 +13,7 @@ Hoe::add_include_dirs("../../sexp_processor/dev/lib",
13
13
  Hoe.plugin :isolate
14
14
  Hoe.plugin :seattlerb
15
15
  Hoe.plugin :rdoc
16
+ Hoe.plugin :cov
16
17
 
17
18
  Hoe.spec "debride" do
18
19
  developer "Ryan Davis", "ryand-ruby@zenspider.com"
@@ -32,10 +33,11 @@ def run dir, whitelist
32
33
  whitelist = whitelist && ["--whitelist", whitelist]
33
34
  verbose = ENV["V"] && "-v"
34
35
  exclude = ENV["E"] && ["--exclude", ENV["E"]]
36
+ minimum = ENV["M"] && ["--minimum", ENV["M"]]
35
37
 
36
38
  require "debride"
37
39
 
38
- args = ["--rails", verbose, whitelist, exclude, dir].flatten.compact
40
+ args = ["--rails", verbose, minimum, whitelist, exclude, dir].flatten.compact
39
41
 
40
42
  Debride.run(args).report
41
43
  end
data/lib/debride.rb CHANGED
@@ -150,6 +150,10 @@ class Debride < MethodBasedSexpProcessor
150
150
  options[:rails] = true
151
151
  end
152
152
 
153
+ opts.on("-m", "--minimum N", Integer, "Don't show hits less than N locs.") do |n|
154
+ options[:minimum] = n
155
+ end
156
+
153
157
  opts.on("-v", "--verbose", "Verbose. Show progress processing files.") do
154
158
  options[:verbose] = true
155
159
  end
@@ -240,6 +244,10 @@ class Debride < MethodBasedSexpProcessor
240
244
  _, _, _, *args = sexp
241
245
  file, line = sexp.file, sexp.line
242
246
  args.each do |(_, name)|
247
+ if Sexp === name then
248
+ process name
249
+ next
250
+ end
243
251
  record_method name, file, line
244
252
  record_method "#{name}=".to_sym, file, line
245
253
  end
@@ -248,6 +256,10 @@ class Debride < MethodBasedSexpProcessor
248
256
  _, _, _, *args = sexp
249
257
  file, line = sexp.file, sexp.line
250
258
  args.each do |(_, name)|
259
+ if Sexp === name then
260
+ process name
261
+ next
262
+ end
251
263
  record_method "#{name}=".to_sym, file, line
252
264
  end
253
265
  when :attr_reader then
@@ -255,6 +267,10 @@ class Debride < MethodBasedSexpProcessor
255
267
  _, _, _, *args = sexp
256
268
  file, line = sexp.file, sexp.line
257
269
  args.each do |(_, name)|
270
+ if Sexp === name then
271
+ process name
272
+ next
273
+ end
258
274
  record_method name, file, line
259
275
  end
260
276
  when :send, :public_send, :__send__ then
@@ -263,6 +279,18 @@ class Debride < MethodBasedSexpProcessor
263
279
  if Sexp === msg_arg && [:lit, :str].include?(msg_arg.sexp_type) then
264
280
  called << msg_arg.last.to_sym
265
281
  end
282
+ when :delegate then
283
+ # s(:call, nil, :delegate, ..., s(:hash, s(:lit, :to), s(:lit, :delegator)))
284
+ possible_hash = sexp.last
285
+ if Sexp === possible_hash && possible_hash.sexp_type == :hash
286
+ possible_hash.sexp_body.each_slice(2) do |key, val|
287
+ next unless key == s(:lit, :to)
288
+ next unless Sexp === val
289
+
290
+ called << val.last if val.sexp_type == :lit
291
+ called << val.last.to_sym if val.sexp_type == :str
292
+ end
293
+ end
266
294
  when *RAILS_DSL_METHODS, *RAILS_VALIDATION_METHODS then
267
295
  if option[:rails]
268
296
  # s(:call, nil, :before_save, s(:lit, :save_callback), s(:hash, ...))
@@ -282,10 +310,16 @@ class Debride < MethodBasedSexpProcessor
282
310
  when *RAILS_MACRO_METHODS
283
311
  # s(:call, nil, :has_one, s(:lit, :has_one_relation), ...)
284
312
  _, _, _, (_, name), * = sexp
285
- file, line = sexp.file, sexp.line
286
- record_method name, file, line
313
+
314
+ # try to detect route scope vs model scope
315
+ if context.include? :module or context.include? :class then
316
+ file, line = sexp.file, sexp.line
317
+ record_method name, file, line
318
+ end
287
319
  when /_path$/ then
288
- method_name = method_name.to_s[0..-6].to_sym if option[:rails]
320
+ method_name = method_name.to_s.delete_suffix("_path").to_sym if option[:rails]
321
+ when /^deliver_/ then
322
+ method_name = method_name.to_s.delete_prefix("deliver_").to_sym if option[:rails]
289
323
  end
290
324
 
291
325
  called << method_name
@@ -303,6 +337,7 @@ class Debride < MethodBasedSexpProcessor
303
337
  process val
304
338
 
305
339
  signature = "#{klass_name}::#{name}"
340
+
306
341
  known[name] << klass_name
307
342
 
308
343
  file, line = exp.file, exp.line
@@ -313,12 +348,16 @@ class Debride < MethodBasedSexpProcessor
313
348
 
314
349
  def name_to_string exp
315
350
  case exp.sexp_type
351
+ when :const then
352
+ exp.last.to_s
316
353
  when :colon2 then
317
- _, (_, lhs), rhs = exp
318
- "#{lhs}::#{rhs}"
354
+ _, lhs, rhs = exp
355
+ "#{name_to_string lhs}::#{rhs}"
319
356
  when :colon3 then
320
357
  _, rhs = exp
321
358
  "::#{rhs}"
359
+ when :self then # wtf?
360
+ "self"
322
361
  else
323
362
  raise "Not handled: #{exp.inspect}"
324
363
  end
@@ -440,13 +479,33 @@ class Debride < MethodBasedSexpProcessor
440
479
 
441
480
  io.puts "These methods MIGHT not be called:"
442
481
 
482
+ total = 0
483
+
443
484
  missing.each do |klass, meths|
444
- bad = meths.map { |(meth, location)| " %-35s %s" % [meth, location] }
485
+ bad = meths.map { |(meth, location)|
486
+ loc = if location then
487
+ l0, l1 = location.split(/:/).last.scan(/\d+/).flatten.map(&:to_i)
488
+ l1 ||= l0
489
+ l1 - l0 + 1
490
+ else
491
+ 1
492
+ end
493
+
494
+ next if option[:minimum] && loc < option[:minimum]
495
+
496
+ total += loc
497
+
498
+ " %-35s %s (%d)" % [meth, location, loc]
499
+ }.compact
500
+
501
+ next if bad.empty?
445
502
 
446
503
  io.puts
447
504
  io.puts klass
448
505
  io.puts bad.join "\n"
449
506
  end
507
+ io.puts
508
+ io.puts "Total suspect LOC: %d" % [total]
450
509
  end
451
510
 
452
511
  def report_json io, focus, missing
data.tar.gz.sig CHANGED
@@ -1,2 +1 @@
1
- ^$ ߦ��jhB>��!F"Bvum���f�*��:�\q�Ӫ�bjF�<����]2Iv��� �_��J<c�U�P�J<�lq��ФŮ�G�[�҄�&��tÆ��Q�z�̌c���6Ey�`Vșa�Ƅ��"
2
- :��܎6������C��{��[�ݿ}�IYš�|��Y���8��w.d���9�z�$��~u�l𝋀�E���s;)�Z��Q+��w($��<m�Qq���� PZ%�e$�\Nx�Nrn�Z
1
+ ��<����`�s�)}�:)�����a��~ޖ$���܍��DºZ��ջ�b#����K8%L
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.9.0
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -29,7 +29,7 @@ cert_chain:
29
29
  JFmxn4h9YO/pVdB962BdBNNDia0kgIjI3ENnkLq0dKpYU3+F3KhEuTksLO0L6X/V
30
30
  YsuyUzsMz6GQA4khyaMgKNSD
31
31
  -----END CERTIFICATE-----
32
- date: 2022-05-23 00:00:00.000000000 Z
32
+ date: 2022-12-03 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: sexp_processor
@@ -93,20 +93,34 @@ dependencies:
93
93
  - - "<"
94
94
  - !ruby/object:Gem::Version
95
95
  version: '7'
96
+ - !ruby/object:Gem::Dependency
97
+ name: simplecov
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '0.21'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '0.21'
96
110
  - !ruby/object:Gem::Dependency
97
111
  name: hoe
98
112
  requirement: !ruby/object:Gem::Requirement
99
113
  requirements:
100
114
  - - "~>"
101
115
  - !ruby/object:Gem::Version
102
- version: '3.23'
116
+ version: '3.25'
103
117
  type: :development
104
118
  prerelease: false
105
119
  version_requirements: !ruby/object:Gem::Requirement
106
120
  requirements:
107
121
  - - "~>"
108
122
  - !ruby/object:Gem::Version
109
- version: '3.23'
123
+ version: '3.25'
110
124
  description: Analyze code for potentially uncalled / dead methods, now with auto-removal.
111
125
  email:
112
126
  - ryand-ruby@zenspider.com
metadata.gz.sig CHANGED
Binary file