debride 1.6.0 → 1.7.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
  SHA1:
3
- metadata.gz: 82b0f1e06d3647db71770771357949a6b602f2eb
4
- data.tar.gz: b8dd7fb4af36fd5742baef9a041763aed58e5ccb
3
+ metadata.gz: a9e867eaaa0e3d510c124de19d4ea6ab0fa818e5
4
+ data.tar.gz: 39740af34dbd97eb9e1286ab0a1ca51437aec120
5
5
  SHA512:
6
- metadata.gz: 24628c05032af7f7f86dcd53ee0f67d73061b80d94c291d794edb3731e9cc2c9e697918d7ee5818358d26b5e13b0082e15e44cf2174bd3fc3c5def8b71aa42d3
7
- data.tar.gz: 38725e26ec1f5b696c9f02299e7625e40d009c813cde75a3c634ead60f85d0343310589d0478c618ea4aa038d9ce165605abb9551d0c397bc63965641b0b26a0
6
+ metadata.gz: ee65c75009da3d4f6c8760c5fe0b493929008d42f81be3db3cb19e6cf3c8e30f89483eb30088c95d1174880e91b9895e72ecf5f31c5c6fa36d9930f374291d72
7
+ data.tar.gz: ce1b919309e8790d5a320675721ed82116a1312440ff678fb002f00130247ca7369e71358ad3d379749ac2c6048b6e6a7e109b1405d478055daa30e5881f24ff
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,13 @@
1
+ === 1.7.0 / 2016-11-30
2
+
3
+ * 1 minor enhancement:
4
+
5
+ * Added bin/debride_rm to automatically remove all dead methods!
6
+
7
+ * 1 bug fix:
8
+
9
+ * Remove #map hash in favor of #method_locations (chrisarcand)
10
+
1
11
  === 1.6.0 / 2016-05-15
2
12
 
3
13
  * 1 minor enhancement:
@@ -5,5 +5,6 @@ README.rdoc
5
5
  Rakefile
6
6
  bin/debride
7
7
  bin/debride_rails_whitelist
8
+ bin/debride_rm
8
9
  lib/debride.rb
9
10
  test/test_debride.rb
@@ -5,7 +5,7 @@ rdoc :: http://docs.seattlerb.org/debride
5
5
 
6
6
  == DESCRIPTION:
7
7
 
8
- Analyze code for potentially uncalled / dead methods.
8
+ Analyze code for potentially uncalled / dead methods, now with auto-removal.
9
9
 
10
10
  == FEATURES/PROBLEMS:
11
11
 
@@ -13,6 +13,7 @@ Analyze code for potentially uncalled / dead methods.
13
13
  * As with all static analysis tools of dynamic languages, can't be 100%.
14
14
  * Whitelisting known good methods by name or regexp.
15
15
  * Use --rails for Rails-specific domain knowledge.
16
+ * Use debride_rm to brazenly remove all unused methods. BE CAREFUL.
16
17
  * Use `debride_rails_whitelist` to generate an emperical whitelist from logs.
17
18
  * Uses path_expander, so you can use:
18
19
  * dir_arg -- expand a directory automatically
@@ -49,6 +50,7 @@ You can also use regexps in your whitelist by delimiting them with //'s.
49
50
  debride-erb :: Extends debride to analyze erb files (via erubis ala rails).
50
51
  debride-haml :: Plugin to allow debride to parse Haml files.
51
52
  debride-curly :: A plugin for the Curly templating language
53
+ debride-slim :: Extends debride to analyze Slim files
52
54
 
53
55
  == REQUIREMENTS:
54
56
 
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ def autoclave nuke
4
+ skips = 0
5
+
6
+ nuke.each do |path, ary|
7
+ # warn path
8
+
9
+ file = File.readlines path
10
+
11
+ ary.each do |(line, name)|
12
+ opener = file[line-1]
13
+
14
+ case opener
15
+ when /^\s*def/
16
+ # do nothing
17
+ else # attr_accessor, etc
18
+ # warn " unsupported: #{opener.strip}"
19
+ skips += 1
20
+ next
21
+ end
22
+
23
+ leader = opener[/^\s+/]
24
+ end_line = file[line..-1].find_index { |l| l =~ /^#{leader}end/ }
25
+
26
+ if end_line then
27
+ end_line += line + 1
28
+ end_line += 1 while file[end_line] =~ /^\s*$/
29
+ end_line += 1 while file[end_line] =~ /^\s*alias.*?\b#{name}$/
30
+ end_line += 1 while file[end_line] =~ /^\s*$/
31
+
32
+ end_line.downto line do |i|
33
+ file.delete_at(i-1)
34
+ end
35
+ else
36
+ warn "NOT FOUND: ending for #{name} #{path}:#{line}"
37
+ end
38
+ end
39
+
40
+ File.open path, "w" do |f|
41
+ f.write file.join
42
+ end
43
+ end
44
+
45
+ print " skips = %3d" % skips if skips > 0
46
+ end
47
+
48
+ def read_debride path
49
+ nuke = Hash.new { |h,k| h[k] = [] }
50
+
51
+ count = 0
52
+
53
+ File.foreach path do |line|
54
+ case line
55
+ when /^ (\S+)\s+(\S+):(\d+)$/ then
56
+ name, path, line = $1, $2, $3.to_i
57
+ nuke[path] << [line, name]
58
+ count += 1
59
+ when /^[\w:]+$/, "\n", /:$/ then
60
+ # ignore
61
+ else
62
+ warn "unparsed: #{line.chomp}"
63
+ end
64
+ end
65
+
66
+ nuke.each do |k, ary|
67
+ nuke[k] = ary.sort.reverse
68
+ end
69
+
70
+ [nuke, count]
71
+ end
72
+
73
+ iter = 0
74
+ old_count = nil
75
+
76
+ abort "usage: #{$0} [debride args]+" if ARGV.empty? or ARGV.include? "-h"
77
+
78
+ cmd = %w[debride] + ARGV + %w[> dummy_for_cmd_below]
79
+
80
+ loop do
81
+ iter += 1
82
+ dead = "dead%02d.txt" % iter
83
+ cmd[-1] = dead
84
+
85
+ Process.wait Process.spawn cmd.join " "
86
+ abort "debride failed: #{$?}" unless $?.success?
87
+
88
+ nuke, count = read_debride dead
89
+
90
+ break if old_count == count
91
+ old_count = count
92
+
93
+ print "iter = %2d count = %4d" % [iter, count]
94
+ autoclave nuke
95
+ puts
96
+ end
@@ -22,7 +22,7 @@ end
22
22
  # A static code analyzer that points out possible dead methods.
23
23
 
24
24
  class Debride < MethodBasedSexpProcessor
25
- VERSION = "1.6.0" # :nodoc:
25
+ VERSION = "1.7.0" # :nodoc:
26
26
  PROJECT = "debride"
27
27
 
28
28
  def self.load_plugins proj = PROJECT
@@ -188,7 +188,6 @@ class Debride < MethodBasedSexpProcessor
188
188
  # Command-line options.
189
189
 
190
190
  attr_accessor :option
191
- attr_accessor :map # :nodoc: # TODO: retire and use method_locations
192
191
 
193
192
  ##
194
193
  # Create a new Debride instance w/ +options+
@@ -197,7 +196,6 @@ class Debride < MethodBasedSexpProcessor
197
196
  self.option = { :whitelist => [] }.merge options
198
197
  self.known = Hash.new { |h,k| h[k] = Set.new }
199
198
  self.called = Set.new
200
- self.map = Hash.new { |h,k| h[k] = {} }
201
199
  super()
202
200
  end
203
201
 
@@ -220,7 +218,6 @@ class Debride < MethodBasedSexpProcessor
220
218
  def record_method name, file, line
221
219
  signature = "#{klass_name}##{name}"
222
220
  method_locations[signature] = "#{file}:#{line}"
223
- map[klass_name][name] = signature
224
221
  known[name] << klass_name
225
222
  end
226
223
 
@@ -304,7 +301,6 @@ class Debride < MethodBasedSexpProcessor
304
301
  process val
305
302
 
306
303
  signature = "#{klass_name}::#{name}"
307
- map[klass_name][name] = signature
308
304
  known[name] << klass_name
309
305
 
310
306
  file, line = exp.file, exp.line
@@ -340,7 +336,6 @@ class Debride < MethodBasedSexpProcessor
340
336
 
341
337
  def process_defn sexp # :nodoc:
342
338
  super do
343
- map[klass_name][plain_method_name] = signature
344
339
  known[plain_method_name] << klass_name
345
340
  process_until_empty sexp
346
341
  end
@@ -348,7 +343,6 @@ class Debride < MethodBasedSexpProcessor
348
343
 
349
344
  def process_defs sexp # :nodoc:
350
345
  super do
351
- map[klass_name][plain_method_name] = signature
352
346
  known[plain_method_name] << klass_name
353
347
  process_until_empty sexp
354
348
  end
@@ -404,7 +398,7 @@ class Debride < MethodBasedSexpProcessor
404
398
 
405
399
  missing.each do |klass, meths|
406
400
  bad = meths.map { |meth|
407
- location = method_locations[map[klass][meth]]
401
+ location = method_locations["#{klass}##{meth}"]
408
402
  path = location[/(.+):\d+$/, 1]
409
403
 
410
404
  next if focus and not File.fnmatch(focus, path)
@@ -269,24 +269,6 @@ class TestDebride < Minitest::Test
269
269
 
270
270
  d = assert_process [["AttributeAccessor", [:a1=, :a2, :a3, :r2, :w2=]]], ruby
271
271
 
272
- exp = {
273
- "AttributeAccessor" => {
274
- :a1 => "AttributeAccessor#a1",
275
- :a1= => "AttributeAccessor#a1=",
276
- :a2 => "AttributeAccessor#a2",
277
- :a2= => "AttributeAccessor#a2=",
278
- :a3 => "AttributeAccessor#a3",
279
- :a3= => "AttributeAccessor#a3=",
280
- :w1= => "AttributeAccessor#w1=",
281
- :w2= => "AttributeAccessor#w2=",
282
- :r1 => "AttributeAccessor#r1",
283
- :r2 => "AttributeAccessor#r2",
284
- :initialize => "AttributeAccessor#initialize"
285
- }
286
- }
287
-
288
- assert_equal exp, d.map
289
-
290
272
  exp = {
291
273
  "AttributeAccessor#a1" => "(io):2",
292
274
  "AttributeAccessor#a1=" => "(io):2",
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.6.0
4
+ version: 1.7.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
- MIIDPjCCAiagAwIBAgIBAzANBgkqhkiG9w0BAQUFADBFMRMwEQYDVQQDDApyeWFu
13
+ MIIDijCCAnKgAwIBAgIBATANBgkqhkiG9w0BAQUFADBFMRMwEQYDVQQDDApyeWFu
14
14
  ZC1ydWJ5MRkwFwYKCZImiZPyLGQBGRYJemVuc3BpZGVyMRMwEQYKCZImiZPyLGQB
15
- GRYDY29tMB4XDTE1MDkxOTIwNTEyMloXDTE2MDkxODIwNTEyMlowRTETMBEGA1UE
15
+ GRYDY29tMB4XDTE2MDkyNjAxNTczNVoXDTE3MDkyNjAxNTczNVowRTETMBEGA1UE
16
16
  AwwKcnlhbmQtcnVieTEZMBcGCgmSJomT8ixkARkWCXplbnNwaWRlcjETMBEGCgmS
17
17
  JomT8ixkARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALda
18
18
  b9DCgK+627gPJkB6XfjZ1itoOQvpqH1EXScSaba9/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KPZIh1OyhU4UO4zrkREcH8ML70v9cYHNvOd9oynRHnvC
28
+ l2tj/fD3YJ0AEkJxGrYwRWQmvMfC4bJ02bC1+rVOUIXXKp3+cUmiN4sTniof8VFo
29
+ bo/YYP4c7erpERa+9hrqygg6WQbJlk2YRlH3JXPFjmu869i2dcbR5ZLOAeEy+axH
30
+ E4oJcnPkJAr0rw504JGtlZtONZQblwmRJOIdXzolaE3NRGUzGVOUSptZppAKiavY
31
+ fO6tdKQc/5RfA8oQEkg8hrxA5PQSz4TOFJGLpFvIapEk6tMruQ0bHgkhr9auXg==
31
32
  -----END CERTIFICATE-----
32
- date: 2016-05-15 00:00:00.000000000 Z
33
+ date: 2016-12-01 00:00:00.000000000 Z
33
34
  dependencies:
34
35
  - !ruby/object:Gem::Dependency
35
36
  name: sexp_processor
@@ -101,12 +102,13 @@ dependencies:
101
102
  - - ~>
102
103
  - !ruby/object:Gem::Version
103
104
  version: '3.15'
104
- description: Analyze code for potentially uncalled / dead methods.
105
+ description: Analyze code for potentially uncalled / dead methods, now with auto-removal.
105
106
  email:
106
107
  - ryand-ruby@zenspider.com
107
108
  executables:
108
109
  - debride
109
110
  - debride_rails_whitelist
111
+ - debride_rm
110
112
  extensions: []
111
113
  extra_rdoc_files:
112
114
  - History.rdoc
@@ -120,6 +122,7 @@ files:
120
122
  - Rakefile
121
123
  - bin/debride
122
124
  - bin/debride_rails_whitelist
125
+ - bin/debride_rm
123
126
  - lib/debride.rb
124
127
  - test/test_debride.rb
125
128
  homepage: https://github.com/seattlerb/debride
@@ -147,5 +150,5 @@ rubyforge_project:
147
150
  rubygems_version: 2.4.5
148
151
  signing_key:
149
152
  specification_version: 4
150
- summary: Analyze code for potentially uncalled / dead methods.
153
+ summary: Analyze code for potentially uncalled / dead methods, now with auto-removal.
151
154
  test_files: []
metadata.gz.sig CHANGED
@@ -1 +1 @@
1
- *{��Y4�Dí� ��"諉HC���" ����a>�߯5�8����r���F1Ә�|g���'����}���O?�%�^�r�%���L��S��af! 7bnw7̌��[��ry�ex S�8��b������A�� od8���k�uw���|�(kK�܀8g���Qᠬ��^�I1���� Qk3G^w�𛂴 em�2��Ve.� }铡��n�$}Oze��<FxO7
1
+ �e�6������^�@&�e��zC��`W�j�Pqz�Ʌ +�4t��^��e;EU�� P�lKˮ~�-�'r��!z_AT��|���N�]N2_��OC�,�>2(�y'�𕙠�h��J��>n��)���C{��S��v�P�m���סA�E��;����L!�|p�*�P0��F��ϙ���nV���lT��.�v����ZZ8�^d0G��TS�ݴ�AI��=����:h�9껖����!�n�F(^�W�