debride 1.0.0 → 1.1.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: 6abab211f7ada7517c61d2ed301cc1b9762d435d
4
- data.tar.gz: c2b904f36e9275028ad3966b74ce9fb53ca9d639
3
+ metadata.gz: d36c868e7a15b6746112225734bc0d747df00d6e
4
+ data.tar.gz: 84d0559594fe52021133115507afcea6974b3967
5
5
  SHA512:
6
- metadata.gz: ba06f6b5951e6094f242191706c9f1fbe6de90ae609bdd869ce0560eb3d7c855f1164cdfc62602feb55e2c87d8596181469eb81c2761350ad65a94c85f08850d
7
- data.tar.gz: df82696ec8ffcf55b1b2ad0985a31ab211909ec977ef983329d4cab824ce6164aa3f1b2834085c57f8ad8565868c53bfbdbcc6e5fa0cd83fe69f276a79531890
6
+ metadata.gz: 427ce5bf52dd04e4060da5c417fbe90cf918e2e39104b72da41ad3335aac76d359501aa33f4dbdb17b664f55391d2372aeafbb814beaf98d2b018593cae9b3e3
7
+ data.tar.gz: 19e156808348e4a005febc69774523634cbc2fb3798717a8cfe7bc6516544c1786b858867ef8bc83b7fb9dae30c189e86648c9585cfb73a9c358473219488787
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,13 @@
1
+ === 1.1.0 / 2015-03-18
2
+
3
+ * 1 minor enhancement:
4
+
5
+ * Added --whitelist option to exclude known false positives.
6
+
7
+ * 1 bug fix:
8
+
9
+ * Fixed sexp_processor dependency
10
+
1
11
  === 1.0.0 / 2015-03-09
2
12
 
3
13
  * 1 major enhancement
@@ -11,17 +11,33 @@ Analyze code for potentially uncalled / dead methods.
11
11
 
12
12
  * Static analysis of code. Can be easily hooked up to a CI.
13
13
  * As with all static analysis tools of dynamic languages, can't be 100%.
14
+ * Whitelisting known good methods by name or regexp.
14
15
 
15
16
  == SYNOPSIS:
16
17
 
17
- % debride lib test
18
+ % debride lib
18
19
 
19
20
  These methods MIGHT not be called:
20
21
 
21
22
  MyClass
22
- method! lib/some/file.rb:16
23
+ good_method lib/some/file.rb:16
24
+ bad_method lib/some/file.rb:20
23
25
  ...
24
26
 
27
+ But you know that good_method is called (perhaps because it is public
28
+ API), then you can whitelist it:
29
+
30
+ % echo good_method > whitelist.txt
31
+ % debride --whitelist whitelist.txt lib
32
+
33
+ These methods MIGHT not be called:
34
+
35
+ MyClass
36
+ bad_method lib/some/file.rb:20
37
+ ...
38
+
39
+ You can also use regexps in your whitelist by delimiting them with //'s.
40
+
25
41
  == REQUIREMENTS:
26
42
 
27
43
  * ruby 1.8+
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ Hoe.spec "debride" do
11
11
  developer "Ryan Davis", "ryand-ruby@zenspider.com"
12
12
  license "MIT"
13
13
 
14
- dependency "sexp_processor", "~> 4.4"
14
+ dependency "sexp_processor", "~> 4.5"
15
15
  dependency "ruby_parser", "~> 3.6"
16
16
  end
17
17
 
@@ -1,7 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
2
 
3
- $:.unshift "../../sexp_processor/dev/lib"
4
-
5
3
  require "ruby_parser"
6
4
  require "sexp_processor"
7
5
  require "optparse"
@@ -11,7 +9,7 @@ require "set"
11
9
  # A static code analyzer that points out possible dead methods.
12
10
 
13
11
  class Debride < MethodBasedSexpProcessor
14
- VERSION = "1.0.0" # :nodoc:
12
+ VERSION = "1.1.0" # :nodoc:
15
13
 
16
14
  ##
17
15
  # Top level runner for bin/debride.
@@ -34,7 +32,7 @@ class Debride < MethodBasedSexpProcessor
34
32
  # Parse command line options and return a hash of parsed option values.
35
33
 
36
34
  def self.parse_options args
37
- options = {}
35
+ options = {:whitelist => []}
38
36
 
39
37
  OptionParser.new do |opts|
40
38
  opts.banner = "debride [options] files_or_dirs"
@@ -49,9 +47,9 @@ class Debride < MethodBasedSexpProcessor
49
47
  exit
50
48
  end
51
49
 
52
- # opts.on("-e", "--exclude FILE", String, "Exclude these messages.") do |s|
53
- # options[:exclude] = s
54
- # end
50
+ opts.on("-w", "--whitelist FILE", String, "Whitelist these messages.") do |s|
51
+ options[:whitelist] = File.read(s).split(/\n+/) rescue []
52
+ end
55
53
 
56
54
  opts.on("-v", "--verbose", "Verbose. Show progress processing files.") do
57
55
  options[:verbose] = true
@@ -133,8 +131,21 @@ class Debride < MethodBasedSexpProcessor
133
131
  # Calculate the difference between known methods and called methods.
134
132
 
135
133
  def missing
134
+ whitelist_regexps = []
135
+
136
+ option[:whitelist].each do |s|
137
+ if s =~ /^\/.+?\/$/ then
138
+ whitelist_regexps << Regexp.new(s[1..-2])
139
+ else
140
+ called << s.to_sym
141
+ end
142
+ end
143
+
136
144
  not_called = known.keys - called.to_a
137
145
 
146
+ whitelist_regexp = Regexp.union whitelist_regexps
147
+ not_called.reject! { |s| whitelist_regexp =~ s }
148
+
138
149
  by_class = Hash.new { |h,k| h[k] = [] }
139
150
 
140
151
  not_called.each do |meth|
@@ -18,6 +18,7 @@ class TestDebride < Minitest::Test
18
18
  def assert_option arg, rest, exp_opt
19
19
  opt = Debride.parse_options arg
20
20
 
21
+ exp_opt = {:whitelist => []}.merge exp_opt
21
22
  assert_equal exp_opt, opt
22
23
  assert_equal rest, arg
23
24
  end
@@ -30,9 +31,27 @@ class TestDebride < Minitest::Test
30
31
  assert_option %w[-v woot.rb], %w[woot.rb], :verbose => true
31
32
  end
32
33
 
33
- def test_parse_options_exclude
34
- skip "not yet"
34
+ def test_parse_options_whitelist
35
+ exp = File.readlines("Manifest.txt").map(&:chomp) # omg dumb
36
+ assert_option %w[--whitelist Manifest.txt], %w[], :whitelist => exp
37
+ end
38
+
39
+ def test_whitelist
40
+ debride = Debride.run %w[lib]
41
+ debride.option[:whitelist] = %w[process_defn]
42
+
43
+ exp = [["Debride",
44
+ [:process_call, :process_defs, :report, :run]]]
45
+
46
+ assert_equal exp, debride.missing
47
+ end
48
+
49
+ def test_whitelist_regexp
50
+ debride = Debride.run %w[lib]
51
+ debride.option[:whitelist] = %w[/^process_/ run]
35
52
 
36
- assert_option %w[--exclude path], %w[], :exclude => "path"
53
+ exp = [["Debride", [:report]]]
54
+
55
+ assert_equal exp, debride.missing
37
56
  end
38
57
  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.0.0
4
+ version: 1.1.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-09 00:00:00.000000000 Z
32
+ date: 2015-03-18 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: sexp_processor
@@ -37,14 +37,14 @@ dependencies:
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: '4.4'
40
+ version: '4.5'
41
41
  type: :runtime
42
42
  prerelease: false
43
43
  version_requirements: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '4.4'
47
+ version: '4.5'
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: ruby_parser
50
50
  requirement: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
Binary file