debride 1.7.0 → 1.8.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: a9e867eaaa0e3d510c124de19d4ea6ab0fa818e5
4
- data.tar.gz: 39740af34dbd97eb9e1286ab0a1ca51437aec120
3
+ metadata.gz: 9997dcf31c73430147cd74d4365cacc011a9ddf9
4
+ data.tar.gz: 0d52faa989d72642bfc90eb59efe69c1eb29bd85
5
5
  SHA512:
6
- metadata.gz: ee65c75009da3d4f6c8760c5fe0b493929008d42f81be3db3cb19e6cf3c8e30f89483eb30088c95d1174880e91b9895e72ecf5f31c5c6fa36d9930f374291d72
7
- data.tar.gz: ce1b919309e8790d5a320675721ed82116a1312440ff678fb002f00130247ca7369e71358ad3d379749ac2c6048b6e6a7e109b1405d478055daa30e5881f24ff
6
+ metadata.gz: '090808da18149228a64261245d549cb50fa78141b73428a913fe606b61f700bec4ada3de220c5b9ff01e48b1f15f94daa93a4296f570d8da65f6cea7bf53e124'
7
+ data.tar.gz: 73af8d47c93780a568590bc7bf34b4ff4df80dd6ce9e877d01347b232ca2907274b7d1cb4b090481a5aaab13e23f2e3575324a02e9f49c10bffb513c7817086b
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,13 @@
1
+ === 1.8.0 / 2017-05-09
2
+
3
+ * 1 minor enhancement:
4
+
5
+ * Updated rails support. (phiggins)
6
+
7
+ * 1 bug fix:
8
+
9
+ * Fixed regression reporting class methods caused by 1.7.0. (marcinruszkiewicz/etagwerker)
10
+
1
11
  === 1.7.0 / 2016-11-30
2
12
 
3
13
  * 1 minor enhancement:
@@ -52,6 +52,11 @@ debride-haml :: Plugin to allow debride to parse Haml files.
52
52
  debride-curly :: A plugin for the Curly templating language
53
53
  debride-slim :: Extends debride to analyze Slim files
54
54
 
55
+ == EDITOR INTEGRATION:
56
+
57
+ TextMate 2 :: * {Debride-Rails.tmbundle}[https://github.com/jjuliano/Debride-Rails.tmbundle] - Debride with Rails support
58
+ * {Debride.tmbundle}[https://github.com/jjuliano/Debride-Rails.tmbundle] - Debride for Ruby
59
+
55
60
  == REQUIREMENTS:
56
61
 
57
62
  * sexp_processor
@@ -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.7.0" # :nodoc:
25
+ VERSION = "1.8.0" # :nodoc:
26
26
  PROJECT = "debride"
27
27
 
28
28
  def self.load_plugins proj = PROJECT
@@ -262,29 +262,27 @@ class Debride < MethodBasedSexpProcessor
262
262
  if Sexp === msg_arg && [:lit, :str].include?(msg_arg.sexp_type) then
263
263
  called << msg_arg.last.to_sym
264
264
  end
265
- when *RAILS_VALIDATION_METHODS then
266
- if option[:rails]
267
- possible_hash = sexp.last
268
- if Sexp === possible_hash && possible_hash.sexp_type == :hash
269
- possible_hash.sexp_body.each_slice(2) do |key, val|
270
- called << val.last if val.first == :lit
271
- called << val.last.to_sym if val.first == :str
272
- end
273
- end
274
- end
275
- when *RAILS_DSL_METHODS then
276
- if option[:rails]
277
- # s(:call, nil, :before_save, s(:lit, :save_callback), s(:hash, ...))
278
- _, _, _, (_, new_name), possible_hash = sexp
279
- called << new_name
280
- if Sexp === possible_hash && possible_hash.sexp_type == :hash
281
- possible_hash.sexp_body.each_slice(2) do |key, val|
282
- next unless Sexp === val
283
- called << val.last if val.first == :lit
284
- called << val.last.to_sym if val.first == :str
285
- end
286
- end
287
- end
265
+ when *RAILS_DSL_METHODS, *RAILS_VALIDATION_METHODS then
266
+ if option[:rails]
267
+ # s(:call, nil, :before_save, s(:lit, :save_callback), s(:hash, ...))
268
+ if RAILS_DSL_METHODS.include?(method_name)
269
+ _, _, _, (_, new_name), * = sexp
270
+ called << new_name if new_name
271
+ end
272
+ possible_hash = sexp.last
273
+ if Sexp === possible_hash && possible_hash.sexp_type == :hash
274
+ possible_hash.sexp_body.each_slice(2) do |key, val|
275
+ next unless Sexp === val
276
+ called << val.last if val.first == :lit
277
+ called << val.last.to_sym if val.first == :str
278
+ end
279
+ end
280
+ end
281
+ when *RAILS_MACRO_METHODS
282
+ # s(:call, nil, :has_one, s(:lit, :has_one_relation), ...)
283
+ _, _, _, (_, name), * = sexp
284
+ file, line = sexp.file, sexp.line
285
+ record_method name, file, line
288
286
  when /_path$/ then
289
287
  method_name = method_name.to_s[0..-6].to_sym if option[:rails]
290
288
  end
@@ -398,7 +396,9 @@ class Debride < MethodBasedSexpProcessor
398
396
 
399
397
  missing.each do |klass, meths|
400
398
  bad = meths.map { |meth|
401
- location = method_locations["#{klass}##{meth}"]
399
+ location =
400
+ method_locations["#{klass}##{meth}"] ||
401
+ method_locations["#{klass}::#{meth}"]
402
402
  path = location[/(.+):\d+$/, 1]
403
403
 
404
404
  next if focus and not File.fnmatch(focus, path)
@@ -414,12 +414,16 @@ class Debride < MethodBasedSexpProcessor
414
414
  end
415
415
  end
416
416
 
417
+ ##
418
+ # Rails' macro-style methods that setup method calls to happen during a rails
419
+ # app's execution.
420
+
417
421
  RAILS_DSL_METHODS = [
418
422
  :after_action,
419
423
  :around_action,
420
424
  :before_action,
421
425
 
422
- # http://api.rubyonrails.org/v4.2.1/classes/ActiveRecord/Callbacks.html
426
+ # http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html
423
427
  :after_commit,
424
428
  :after_create,
425
429
  :after_destroy,
@@ -444,8 +448,12 @@ class Debride < MethodBasedSexpProcessor
444
448
  :validate,
445
449
  ]
446
450
 
447
- # http://api.rubyonrails.org/v4.2.1/classes/ActiveModel/Validations/HelperMethods.html
451
+ ##
452
+ # Rails' macro-style methods that count as method calls if their options
453
+ # include +:if+ or +:unless+.
454
+
448
455
  RAILS_VALIDATION_METHODS = [
456
+ # http://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html
449
457
  :validates,
450
458
  :validates_absence_of,
451
459
  :validates_acceptance_of,
@@ -458,4 +466,15 @@ class Debride < MethodBasedSexpProcessor
458
466
  :validates_presence_of,
459
467
  :validates_size_of,
460
468
  ]
469
+
470
+ ##
471
+ # Rails' macro-style methods that define methods dynamically.
472
+
473
+ RAILS_MACRO_METHODS = [
474
+ :belongs_to,
475
+ :has_and_belongs_to_many,
476
+ :has_many,
477
+ :has_one,
478
+ :scope,
479
+ ]
461
480
  end
@@ -223,12 +223,57 @@ class TestDebride < Minitest::Test
223
223
  after_save :save_callback, if: lambda {|r| true }
224
224
  validates :database_column, if: :validation_condition
225
225
  validate :some_validation_method
226
+
227
+ before_save do
228
+ foo.bar
229
+ end
226
230
  end
227
231
  RUBY
228
232
 
229
233
  assert_process [], ruby, :rails => true
230
234
  end
231
235
 
236
+ def test_rails_dsl_macro_definitions
237
+ ruby = <<-RUBY.strip
238
+ class RailsModel
239
+ has_one :has_one_relation
240
+ has_one :uncalled_has_one_relation
241
+ belongs_to :belongs_to_relation
242
+ belongs_to :uncalled_belongs_to_relation
243
+ has_many :has_many_relation
244
+ has_many :uncalled_has_many_relation
245
+ has_and_belongs_to_many :has_and_belongs_to_many_relation
246
+ has_and_belongs_to_many :uncalled_has_and_belongs_to_many_relation
247
+ scope :scope_method
248
+ scope :uncalled_scope_method
249
+
250
+ def instance_method_caller
251
+ has_one_relation
252
+ belongs_to_relation
253
+ has_many_relation
254
+ has_and_belongs_to_many_relation
255
+ end
256
+
257
+ def self.class_method_caller
258
+ scope_method
259
+ end
260
+
261
+ class_method_caller
262
+ new.instance_method_caller
263
+ end
264
+ RUBY
265
+
266
+ unused_methods = [
267
+ :uncalled_belongs_to_relation,
268
+ :uncalled_has_and_belongs_to_many_relation,
269
+ :uncalled_has_many_relation,
270
+ :uncalled_has_one_relation,
271
+ :uncalled_scope_method,
272
+ ]
273
+
274
+ assert_process [["RailsModel", unused_methods]], ruby, :rails => true
275
+ end
276
+
232
277
  def test_constants
233
278
  ruby = <<-RUBY.strip
234
279
  class Constants
@@ -259,6 +304,10 @@ class TestDebride < Minitest::Test
259
304
  self.a2 = 'Bar'
260
305
  self.w1 = 'W'
261
306
  end
307
+
308
+ def self.class_method
309
+ puts "bazinga"
310
+ end
262
311
  end
263
312
 
264
313
  object = AttributeAccessor.new
@@ -267,7 +316,7 @@ class TestDebride < Minitest::Test
267
316
  object.a3 = 'Baz'
268
317
  RUBY
269
318
 
270
- d = assert_process [["AttributeAccessor", [:a1=, :a2, :a3, :r2, :w2=]]], ruby
319
+ d = assert_process [["AttributeAccessor", [:a1=, :a2, :a3, :class_method, :r2, :w2=]]], ruby
271
320
 
272
321
  exp = {
273
322
  "AttributeAccessor#a1" => "(io):2",
@@ -280,7 +329,8 @@ class TestDebride < Minitest::Test
280
329
  "AttributeAccessor#w2=" => "(io):3",
281
330
  "AttributeAccessor#r1" => "(io):4",
282
331
  "AttributeAccessor#r2" => "(io):4",
283
- "AttributeAccessor#initialize" => "(io):5",
332
+ "AttributeAccessor#initialize" => "(io):5-7",
333
+ "AttributeAccessor::class_method" => "(io):10-11"
284
334
  }
285
335
 
286
336
  assert_equal exp, d.method_locations
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.7.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -30,78 +30,78 @@ cert_chain:
30
30
  E4oJcnPkJAr0rw504JGtlZtONZQblwmRJOIdXzolaE3NRGUzGVOUSptZppAKiavY
31
31
  fO6tdKQc/5RfA8oQEkg8hrxA5PQSz4TOFJGLpFvIapEk6tMruQ0bHgkhr9auXg==
32
32
  -----END CERTIFICATE-----
33
- date: 2016-12-01 00:00:00.000000000 Z
33
+ date: 2017-05-09 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: sexp_processor
37
37
  requirement: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ~>
39
+ - - "~>"
40
40
  - !ruby/object:Gem::Version
41
41
  version: '4.5'
42
42
  type: :runtime
43
43
  prerelease: false
44
44
  version_requirements: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ~>
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
48
  version: '4.5'
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: ruby_parser
51
51
  requirement: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ~>
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: '3.6'
56
56
  type: :runtime
57
57
  prerelease: false
58
58
  version_requirements: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ~>
60
+ - - "~>"
61
61
  - !ruby/object:Gem::Version
62
62
  version: '3.6'
63
63
  - !ruby/object:Gem::Dependency
64
64
  name: path_expander
65
65
  requirement: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ~>
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
69
  version: '1.0'
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - ~>
74
+ - - "~>"
75
75
  - !ruby/object:Gem::Version
76
76
  version: '1.0'
77
77
  - !ruby/object:Gem::Dependency
78
78
  name: rdoc
79
79
  requirement: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - ~>
81
+ - - "~>"
82
82
  - !ruby/object:Gem::Version
83
83
  version: '4.0'
84
84
  type: :development
85
85
  prerelease: false
86
86
  version_requirements: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - ~>
88
+ - - "~>"
89
89
  - !ruby/object:Gem::Version
90
90
  version: '4.0'
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: hoe
93
93
  requirement: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - ~>
95
+ - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '3.15'
97
+ version: '3.16'
98
98
  type: :development
99
99
  prerelease: false
100
100
  version_requirements: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - ~>
102
+ - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: '3.15'
104
+ version: '3.16'
105
105
  description: Analyze code for potentially uncalled / dead methods, now with auto-removal.
106
106
  email:
107
107
  - ryand-ruby@zenspider.com
@@ -115,7 +115,7 @@ extra_rdoc_files:
115
115
  - Manifest.txt
116
116
  - README.rdoc
117
117
  files:
118
- - .autotest
118
+ - ".autotest"
119
119
  - History.rdoc
120
120
  - Manifest.txt
121
121
  - README.rdoc
@@ -131,23 +131,23 @@ licenses:
131
131
  metadata: {}
132
132
  post_install_message:
133
133
  rdoc_options:
134
- - --main
134
+ - "--main"
135
135
  - README.rdoc
136
136
  require_paths:
137
137
  - lib
138
138
  required_ruby_version: !ruby/object:Gem::Requirement
139
139
  requirements:
140
- - - '>='
140
+ - - ">="
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0'
143
143
  required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  requirements:
145
- - - '>='
145
+ - - ">="
146
146
  - !ruby/object:Gem::Version
147
147
  version: '0'
148
148
  requirements: []
149
149
  rubyforge_project:
150
- rubygems_version: 2.4.5
150
+ rubygems_version: 2.6.8
151
151
  signing_key:
152
152
  specification_version: 4
153
153
  summary: Analyze code for potentially uncalled / dead methods, now with auto-removal.
metadata.gz.sig CHANGED
Binary file