debride 1.2.0 → 1.3.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
  SHA1:
3
- metadata.gz: bb39a05e306cbbcd061e35997220368ac0cbd964
4
- data.tar.gz: 0704f659f6af475a29e97b424eeecb9ef66b1b8a
3
+ metadata.gz: 5a723b84c9a06468449e24ec4cf6f8911f1cfbc1
4
+ data.tar.gz: 7a135fd947b6cbd2905f4d4196aa526966f465e6
5
5
  SHA512:
6
- metadata.gz: a33032ea66b7b298f0a922978bb3f70b1fdd983bf1147e442fddaf8188be6695b81be4430b32135a4130d1893281d437683e58d8a90b02a533e3909b768edb27
7
- data.tar.gz: 0bcaa9a023b64733d5def8e8cec519328b21bb7a68fa8bf1da74aa7284e031ccc9fc2a4ec7692f037af5b0017400665772d88d9395bb3b5c08c28c16d953804e
6
+ metadata.gz: 6b43c1951aac3602c0ec3bbf1bb28e9aa14d976bb6cc4af7073000795dea551e78d58a20b924396cb2e09f5d422eb9af519d394b413964c541a17ddc46d23ac0
7
+ data.tar.gz: eae873a00409532767de144cea3d1f31249d4083a0823bb96ee38f89db7f4321bd4cbf54a977e4b494a55c4b66f531674a22f98bafdae7e51dbb1220207a7997
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,16 @@
1
+ === 1.3.0 / 2015-04-13
2
+
3
+ * 4 minor enhancements:
4
+
5
+ * Add explicit #send support. (phiggins)
6
+ * Added --exclude for files and dirs. (ianlotinsky)
7
+ * Added --rails flag and rails-specific call transformations.
8
+ * Added methods to called list found in rails DSL methods. (phiggins)
9
+
10
+ * 1 bug fix:
11
+
12
+ * Fixed bug with alias_method_chain. (phiggins)
13
+
1
14
  === 1.2.0 / 2015-03-26
2
15
 
3
16
  * 1 major enhancement:
@@ -46,6 +46,11 @@ You can also use regexps in your whitelist by delimiting them with //'s.
46
46
 
47
47
  * sudo gem install debride
48
48
 
49
+ == CONTRIBUTING:
50
+
51
+ * sudo gem install minitest
52
+ * ruby -Ilib:test test/test_debride.rb
53
+
49
54
  == LICENSE:
50
55
 
51
56
  (The MIT License)
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ end
18
18
  task :rails do
19
19
  ENV["GEM_HOME"] = "tmp/isolate/ruby-2.0.0"
20
20
  ENV["GEM_PATH"] = "../../debride-erb/dev/tmp/isolate/ruby-2.0.0"
21
- ruby "-Ilib:../../debride-erb/dev/lib bin/debride ~/Work/git/seattlerb.org/{app,lib} --whitelist ~/Work/git/seattlerb.org/whitelist.txt"
21
+ ruby "-Ilib:../../debride-erb/dev/lib bin/debride --rails ~/Work/git/seattlerb.org/{app,lib} --whitelist ~/Work/git/seattlerb.org/whitelist.txt"
22
22
  end
23
23
 
24
24
  # vim: syntax=ruby
@@ -9,7 +9,7 @@ require "set"
9
9
  # A static code analyzer that points out possible dead methods.
10
10
 
11
11
  class Debride < MethodBasedSexpProcessor
12
- VERSION = "1.2.0" # :nodoc:
12
+ VERSION = "1.3.0" # :nodoc:
13
13
  PROJECT = "debride"
14
14
 
15
15
  def self.expand_dirs_to_files *dirs # TODO: push back up to sexp_processor
@@ -59,7 +59,11 @@ class Debride < MethodBasedSexpProcessor
59
59
  opt = parse_options args
60
60
 
61
61
  debride = Debride.new opt
62
- debride.run expand_dirs_to_files(args)
62
+
63
+ files = expand_dirs_to_files(args)
64
+ files -= expand_dirs_to_files(debride.option[:exclude]) if debride.option[:exclude]
65
+
66
+ debride.run(files)
63
67
  debride
64
68
  end
65
69
 
@@ -111,10 +115,18 @@ class Debride < MethodBasedSexpProcessor
111
115
  exit
112
116
  end
113
117
 
118
+ opts.on("-e", "--exclude FILE1,FILE2,ETC", Array, "Exclude files or directories in comma-separated list.") do |list|
119
+ options[:exclude] = list
120
+ end
121
+
114
122
  opts.on("-w", "--whitelist FILE", String, "Whitelist these messages.") do |s|
115
123
  options[:whitelist] = File.read(s).split(/\n+/) rescue []
116
124
  end
117
125
 
126
+ opts.on("-r", "--rails", "Add some rails call conversions.") do
127
+ options[:rails] = true
128
+ end
129
+
118
130
  opts.on("-v", "--verbose", "Verbose. Show progress processing files.") do
119
131
  options[:verbose] = true
120
132
  end
@@ -182,8 +194,41 @@ class Debride < MethodBasedSexpProcessor
182
194
  case method_name
183
195
  when :new then
184
196
  method_name = :initialize
185
- when :alias_method_chain
186
- known[sexp[3]] << klass_name
197
+ when :alias_method_chain then
198
+ new_name = sexp[3]
199
+ new_name = new_name.last if Sexp === new_name # when is this NOT the case?
200
+ known[new_name] << klass_name if option[:rails]
201
+ when :send, :public_send, :__send__ then
202
+ sent_method = sexp[3]
203
+ if Sexp === sent_method && [:lit, :str].include?(sent_method.first)
204
+ called << sent_method.last.to_sym
205
+ end
206
+ when *RAILS_VALIDATION_METHODS then
207
+ if option[:rails]
208
+ possible_hash = sexp.last
209
+ if Sexp === possible_hash && possible_hash.first == :hash
210
+ possible_hash[1..-1].each_slice(2) do |key, val|
211
+ called << val.last if val.first == :lit
212
+ called << val.last.to_sym if val.first == :str
213
+ end
214
+ end
215
+ end
216
+ when *RAILS_DSL_METHODS then
217
+ if option[:rails]
218
+ new_name = sexp[3]
219
+ new_name = new_name.last if Sexp === new_name # when is this NOT the case?
220
+ called << new_name
221
+ possible_hash = sexp.last
222
+ if Sexp === possible_hash && possible_hash.first == :hash
223
+ possible_hash[1..-1].each_slice(2) do |key, val|
224
+ next unless Sexp === val
225
+ called << val.last if val.first == :lit
226
+ called << val.last.to_sym if val.first == :str
227
+ end
228
+ end
229
+ end
230
+ when /_path$/ then
231
+ method_name = method_name.to_s[0..-6].to_sym if option[:rails]
187
232
  end
188
233
 
189
234
  called << method_name
@@ -210,6 +255,7 @@ class Debride < MethodBasedSexpProcessor
210
255
  not_called = known.keys - called.to_a
211
256
 
212
257
  whitelist_regexp = Regexp.union whitelist_regexps
258
+
213
259
  not_called.reject! { |s| whitelist_regexp =~ s }
214
260
 
215
261
  by_class = Hash.new { |h,k| h[k] = [] }
@@ -241,4 +287,46 @@ class Debride < MethodBasedSexpProcessor
241
287
  end
242
288
  end
243
289
  end
290
+
291
+ RAILS_DSL_METHODS = [
292
+ :after_action,
293
+ :around_action,
294
+ :before_action,
295
+
296
+ # http://api.rubyonrails.org/v4.2.1/classes/ActiveRecord/Callbacks.html
297
+ :after_commit,
298
+ :after_create,
299
+ :after_destroy,
300
+ :after_find,
301
+ :after_initialize,
302
+ :after_rollback,
303
+ :after_save,
304
+ :after_touch,
305
+ :after_update,
306
+ :after_validation,
307
+ :around_create,
308
+ :around_destroy,
309
+ :around_save,
310
+ :around_update,
311
+ :before_create,
312
+ :before_destroy,
313
+ :before_save,
314
+ :before_update,
315
+ :before_validation,
316
+ ]
317
+
318
+ # http://api.rubyonrails.org/v4.2.1/classes/ActiveModel/Validations/HelperMethods.html
319
+ RAILS_VALIDATION_METHODS = [
320
+ :validates,
321
+ :validates_absence_of,
322
+ :validates_acceptance_of,
323
+ :validates_confirmation_of,
324
+ :validates_exclusion_of,
325
+ :validates_format_of,
326
+ :validates_inclusion_of,
327
+ :validates_length_of,
328
+ :validates_numericality_of,
329
+ :validates_presence_of,
330
+ :validates_size_of,
331
+ ]
244
332
  end
@@ -31,11 +31,26 @@ class TestDebride < Minitest::Test
31
31
  assert_option %w[-v woot.rb], %w[woot.rb], :verbose => true
32
32
  end
33
33
 
34
+ def test_parse_options_exclude
35
+ assert_option %w[--exclude moot.rb], %w[], :exclude => %w[moot.rb]
36
+ assert_option %w[-e moot lib], %w[lib], :exclude => %w[moot]
37
+ assert_option %w[-e moot,moot.rb lib], %w[lib], :exclude => %w[moot moot.rb]
38
+ end
39
+
34
40
  def test_parse_options_whitelist
35
41
  exp = File.readlines("Manifest.txt").map(&:chomp) # omg dumb
36
42
  assert_option %w[--whitelist Manifest.txt], %w[], :whitelist => exp
37
43
  end
38
44
 
45
+ def test_exclude_files
46
+ debride = Debride.run %w[--exclude test lib]
47
+
48
+ exp = [["Debride",
49
+ [:process_call, :process_defn, :process_defs, :process_rb, :report]]]
50
+
51
+ assert_equal exp, debride.missing
52
+ end
53
+
39
54
  def test_whitelist
40
55
  debride = Debride.run %w[lib]
41
56
  debride.option[:whitelist] = %w[process_defn]
@@ -54,4 +69,81 @@ class TestDebride < Minitest::Test
54
69
 
55
70
  assert_equal exp, debride.missing
56
71
  end
72
+
73
+ def test_alias_method_chain
74
+ file = Tempfile.new ["debride_test", ".rb"]
75
+
76
+ file.write <<-RUBY.strip
77
+ class QuarterPounder
78
+ def royale_with_cheese
79
+ 1+1
80
+ end
81
+
82
+ alias_method_chain :royale, :cheese
83
+ end
84
+ RUBY
85
+
86
+ file.flush
87
+
88
+ debride = Debride.run [file.path, "--rails"]
89
+
90
+ exp = [["QuarterPounder", [:royale, :royale_with_cheese]]]
91
+
92
+ assert_equal exp, debride.missing
93
+ end
94
+
95
+ def test_method_send
96
+ file = Tempfile.new ["debride_test", ".rb"]
97
+
98
+ file.write <<-RUBY.strip
99
+ class Seattle
100
+ def self.raining?
101
+ true
102
+ end
103
+
104
+ def self.coffee
105
+ :good
106
+ end
107
+ end
108
+
109
+ Seattle.send :raining?
110
+ Seattle.__send__ "coffee"
111
+ Seattle.send "\#{foo}_bar"
112
+ RUBY
113
+
114
+ file.flush
115
+
116
+ debride = Debride.run [file.path]
117
+
118
+ exp = []
119
+
120
+ assert_equal exp, debride.missing
121
+ end
122
+
123
+ def test_rails_dsl_methods
124
+ file = Tempfile.new ["debride_test", ".rb"]
125
+
126
+ file.write <<-RUBY.strip
127
+ class RailsThing
128
+ def save_callback ; 1 ; end
129
+ def action_filter ; 1 ; end
130
+ def callback_condition ; 1 ; end
131
+ def action_condition ; 1 ; end
132
+ def string_condition ; 1 ; end
133
+ def validation_condition ; 1 ; end
134
+
135
+ before_save :save_callback, unless: :callback_condition
136
+ before_save :save_callback, if: 'string_condition'
137
+ before_action :action_filter, if: :action_condition, only: :new
138
+ after_save :save_callback, if: lambda {|r| true }
139
+ validates :database_column, if: :validation_condition
140
+ end
141
+ RUBY
142
+
143
+ file.flush
144
+
145
+ debride = Debride.run [file.path, "--rails"]
146
+
147
+ assert_equal [], debride.missing.sort
148
+ end
57
149
  end
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.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -29,7 +29,7 @@ cert_chain:
29
29
  xJcC6UN6NHMOVMyAXsr2HR0gRRx4ofN1LoP2KhXzSr8UMvQYlwPmE0N5GQv1b5AO
30
30
  VpzF30vNaJK6ZT7xlIsIlwmH
31
31
  -----END CERTIFICATE-----
32
- date: 2015-03-27 00:00:00.000000000 Z
32
+ date: 2015-04-13 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: sexp_processor
@@ -65,14 +65,14 @@ dependencies:
65
65
  requirements:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: '5.5'
68
+ version: '5.6'
69
69
  type: :development
70
70
  prerelease: false
71
71
  version_requirements: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ~>
74
74
  - !ruby/object:Gem::Version
75
- version: '5.5'
75
+ version: '5.6'
76
76
  - !ruby/object:Gem::Dependency
77
77
  name: rdoc
78
78
  requirement: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
Binary file