debride 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/History.rdoc +10 -0
- data/README.rdoc +18 -2
- data/Rakefile +1 -1
- data/lib/debride.rb +18 -7
- data/test/test_debride.rb +22 -3
- metadata +4 -4
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d36c868e7a15b6746112225734bc0d747df00d6e
|
4
|
+
data.tar.gz: 84d0559594fe52021133115507afcea6974b3967
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 427ce5bf52dd04e4060da5c417fbe90cf918e2e39104b72da41ad3335aac76d359501aa33f4dbdb17b664f55391d2372aeafbb814beaf98d2b018593cae9b3e3
|
7
|
+
data.tar.gz: 19e156808348e4a005febc69774523634cbc2fb3798717a8cfe7bc6516544c1786b858867ef8bc83b7fb9dae30c189e86648c9585cfb73a9c358473219488787
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/History.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -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
|
18
|
+
% debride lib
|
18
19
|
|
19
20
|
These methods MIGHT not be called:
|
20
21
|
|
21
22
|
MyClass
|
22
|
-
|
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
data/lib/debride.rb
CHANGED
@@ -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.
|
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
|
-
|
53
|
-
|
54
|
-
|
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|
|
data/test/test_debride.rb
CHANGED
@@ -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
|
34
|
-
|
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
|
-
|
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.
|
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-
|
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.
|
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.
|
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
|