code_analyzer 0.2.0 → 0.3.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.
- data/lib/code_analyzer/sexp.rb +45 -0
- data/lib/code_analyzer/version.rb +1 -1
- data/spec/code_analyzer/sexp_spec.rb +30 -0
- metadata +18 -7
data/lib/code_analyzer/sexp.rb
CHANGED
@@ -525,6 +525,51 @@ class Sexp
|
|
525
525
|
stmts
|
526
526
|
end
|
527
527
|
|
528
|
+
# Get expcetion class of rescue node.
|
529
|
+
#
|
530
|
+
# s(:rescue,
|
531
|
+
# s(
|
532
|
+
# s(:var_ref,
|
533
|
+
# s(:@const, "CustomException", s(1, 17))
|
534
|
+
# )
|
535
|
+
# ),
|
536
|
+
# nil,
|
537
|
+
# s(:stmts_add, s(:stmts_new), s(:void_stmt)),
|
538
|
+
# nil
|
539
|
+
# )
|
540
|
+
# => s(s(:var_ref, s(:@const, "CustomException", s(1, 17))))
|
541
|
+
def exception_classes
|
542
|
+
if :rescue == sexp_type
|
543
|
+
return [] unless self[1]
|
544
|
+
if :mrhs_add == self[1].sexp_type
|
545
|
+
exceptions = Array.new(self[1][2])
|
546
|
+
arg_nodes = self[1][1][1]
|
547
|
+
while :args_add == arg_nodes.sexp_type
|
548
|
+
exceptions.unshift arg_nodes[2]
|
549
|
+
arg_nodes = arg_nodes[1]
|
550
|
+
end
|
551
|
+
exceptions
|
552
|
+
else
|
553
|
+
self[1]
|
554
|
+
end
|
555
|
+
end
|
556
|
+
end
|
557
|
+
|
558
|
+
# Get exception variable of rescue node.
|
559
|
+
#
|
560
|
+
# s(:rescue,
|
561
|
+
# nil,
|
562
|
+
# s(:var_field, s(:@ident, "e", s(1, 20))),
|
563
|
+
# s(:stmts_add, s(:stmts_new), s(:void_stmt)),
|
564
|
+
# nil
|
565
|
+
# )
|
566
|
+
# => s(:var_field, s(:@ident, "e", s(1, 20)))
|
567
|
+
def exception_variable
|
568
|
+
if :rescue == sexp_type
|
569
|
+
self[2]
|
570
|
+
end
|
571
|
+
end
|
572
|
+
|
528
573
|
# Get hash value node.
|
529
574
|
#
|
530
575
|
# s(:hash,
|
@@ -420,6 +420,36 @@ describe Sexp do
|
|
420
420
|
end
|
421
421
|
end
|
422
422
|
|
423
|
+
describe "exception_classes" do
|
424
|
+
it "should get exception classes of rescue node" do
|
425
|
+
node = parse_content("def test; rescue CustomException; end").grep_node(sexp_type: :rescue)
|
426
|
+
node.exception_classes.first.to_s.should == "CustomException"
|
427
|
+
end
|
428
|
+
|
429
|
+
it "should get empty of empty rescue node" do
|
430
|
+
node = parse_content("def test; rescue; end").grep_node(sexp_type: :rescue)
|
431
|
+
node.exception_classes.first.to_s.should == ""
|
432
|
+
end
|
433
|
+
|
434
|
+
it "should get exception classes of rescue node for multiple exceptions" do
|
435
|
+
node = parse_content("def test; rescue StandardError, CustomException; end").grep_node(sexp_type: :rescue)
|
436
|
+
node.exception_classes.first.to_s.should == "StandardError"
|
437
|
+
node.exception_classes.last.to_s.should == "CustomException"
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
describe "exception_variable" do
|
442
|
+
it "should get exception varible of rescue node" do
|
443
|
+
node = parse_content("def test; rescue => e; end").grep_node(sexp_type: :rescue)
|
444
|
+
node.exception_variable.to_s.should == "e"
|
445
|
+
end
|
446
|
+
|
447
|
+
it "should get empty of empty rescue node" do
|
448
|
+
node = parse_content("def test; rescue; end").grep_node(sexp_type: :rescue)
|
449
|
+
node.exception_variable.to_s.should == ""
|
450
|
+
end
|
451
|
+
end
|
452
|
+
|
423
453
|
describe "hash_value" do
|
424
454
|
it "should get value for hash node" do
|
425
455
|
node = parse_content("{first_name: 'Richard', last_name: 'Huang'}").grep_node(sexp_type: :hash)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code_analyzer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sexp_processor
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: rspec
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,7 +37,12 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
description: a code analyzer tool which extracted from rails_best_practices, it helps
|
37
47
|
you easily build your own code analyzer tool.
|
38
48
|
email:
|
@@ -88,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
98
|
version: '0'
|
89
99
|
requirements: []
|
90
100
|
rubyforge_project:
|
91
|
-
rubygems_version: 1.8.
|
101
|
+
rubygems_version: 1.8.24
|
92
102
|
signing_key:
|
93
103
|
specification_version: 3
|
94
104
|
summary: a code analyzer helps you build your own code analyzer tool.
|
@@ -101,3 +111,4 @@ test_files:
|
|
101
111
|
- spec/code_analyzer/sexp_spec.rb
|
102
112
|
- spec/code_analyzer/warning_spec.rb
|
103
113
|
- spec/spec_helper.rb
|
114
|
+
has_rdoc:
|