code_analyzer 0.4.8 → 0.5.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 +5 -5
- data/.travis.yml +1 -2
- data/lib/code_analyzer.rb +8 -8
- data/lib/code_analyzer/checker.rb +10 -6
- data/lib/code_analyzer/checking_visitor.rb +3 -3
- data/lib/code_analyzer/checking_visitor/base.rb +1 -1
- data/lib/code_analyzer/checking_visitor/default.rb +13 -9
- data/lib/code_analyzer/sexp.rb +149 -102
- data/lib/code_analyzer/version.rb +1 -1
- data/lib/code_analyzer/warning.rb +1 -1
- data/spec/code_analyzer/checker_spec.rb +21 -17
- data/spec/code_analyzer/checking_visitor/default_spec.rb +12 -12
- data/spec/code_analyzer/checking_visitor/plain_spec.rb +4 -4
- data/spec/code_analyzer/nil_spec.rb +10 -10
- data/spec/code_analyzer/sexp_spec.rb +553 -339
- data/spec/code_analyzer/warning_spec.rb +9 -6
- data/spec/spec_helper.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6c252e6214745ff2bcf507702a49553d0ca90c75a12614ee3e5c197c1994656c
|
4
|
+
data.tar.gz: 85bb0e3b8ea846132ba4a159f4477749751cb54a94611a7402d241a2e296f1c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73fc0d1d771feafb646ff218837ae19e8de9556acd25b4fb3a3bad93b76899d950037145c603b1b5e48a38815b1be086102f65c3e77ad2bc2898931858988e6c
|
7
|
+
data.tar.gz: 3fd7c957fc9c2ceeb6714cf4a6a4f1db7b00f7ea6d4a9e73553b460c59f0bd42a4f5d4538e7bf00bc2f39d441f29bed8891a3d200a65b0653830d30c735b7dc0
|
data/.travis.yml
CHANGED
data/lib/code_analyzer.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
2
|
+
require 'ripper'
|
3
|
+
require 'code_analyzer/version'
|
4
|
+
require 'code_analyzer/nil'
|
5
|
+
require 'code_analyzer/sexp'
|
6
6
|
|
7
7
|
module CodeAnalyzer
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
autoload :AnalyzerException, 'code_analyzer/analyzer_exception'
|
9
|
+
autoload :Checker, 'code_analyzer/checker'
|
10
|
+
autoload :CheckingVisitor, 'code_analyzer/checking_visitor'
|
11
|
+
autoload :Warning, 'code_analyzer/warning'
|
12
12
|
end
|
@@ -28,9 +28,8 @@ module CodeAnalyzer
|
|
28
28
|
# @param [Sexp] node
|
29
29
|
def node_start(node)
|
30
30
|
@node = node
|
31
|
-
self.class.get_callbacks("start_#{node.sexp_type}".to_sym)
|
32
|
-
self.instance_exec(node, &block)
|
33
|
-
end
|
31
|
+
self.class.get_callbacks("start_#{node.sexp_type}".to_sym)
|
32
|
+
.each { |block| self.instance_exec(node, &block) }
|
34
33
|
end
|
35
34
|
|
36
35
|
# delegate to end_### according to the sexp_type, like
|
@@ -51,8 +50,13 @@ module CodeAnalyzer
|
|
51
50
|
# @param [String] message, is the warning message
|
52
51
|
# @param [String] filename, is the filename of source code
|
53
52
|
# @param [Integer] line_number, is the line number of the source code which is reviewing
|
54
|
-
def add_warning(
|
55
|
-
|
53
|
+
def add_warning(
|
54
|
+
message, filename = @node.file, line_number = @node.line_number
|
55
|
+
)
|
56
|
+
warnings <<
|
57
|
+
Warning.new(
|
58
|
+
filename: filename, line_number: line_number, message: message
|
59
|
+
)
|
56
60
|
end
|
57
61
|
|
58
62
|
# all warnings.
|
@@ -60,7 +64,7 @@ module CodeAnalyzer
|
|
60
64
|
@warnings ||= []
|
61
65
|
end
|
62
66
|
|
63
|
-
class <<self
|
67
|
+
class << self
|
64
68
|
def interesting_nodes(*nodes)
|
65
69
|
@interesting_nodes ||= []
|
66
70
|
@interesting_nodes += nodes
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module CodeAnalyzer
|
3
3
|
module CheckingVisitor
|
4
|
-
autoload :Base,
|
5
|
-
autoload :Plain,
|
6
|
-
autoload :Default,
|
4
|
+
autoload :Base, 'code_analyzer/checking_visitor/base'
|
5
|
+
autoload :Plain, 'code_analyzer/checking_visitor/plain'
|
6
|
+
autoload :Default, 'code_analyzer/checking_visitor/default'
|
7
7
|
end
|
8
8
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
module CodeAnalyzer::CheckingVisitor
|
3
3
|
# This is the default checking visitor to check ruby sexp nodes.
|
4
4
|
class Default < Base
|
5
|
-
def initialize(options={})
|
5
|
+
def initialize(options = {})
|
6
6
|
super
|
7
7
|
@checks = {}
|
8
8
|
@checkers.each do |checker|
|
@@ -28,9 +28,7 @@ module CodeAnalyzer::CheckingVisitor
|
|
28
28
|
def after_check
|
29
29
|
@checkers.each do |checker|
|
30
30
|
after_check_callbacks = checker.class.get_callbacks(:after_check)
|
31
|
-
after_check_callbacks.each
|
32
|
-
checker.instance_exec &block
|
33
|
-
end
|
31
|
+
after_check_callbacks.each { |block| checker.instance_exec &block }
|
34
32
|
end
|
35
33
|
end
|
36
34
|
|
@@ -41,7 +39,9 @@ module CodeAnalyzer::CheckingVisitor
|
|
41
39
|
def parse(filename, content)
|
42
40
|
Sexp.from_array(Ripper::SexpBuilder.new(content).parse)
|
43
41
|
rescue Exception
|
44
|
-
raise AnalyzerException.new(
|
42
|
+
raise AnalyzerException.new(
|
43
|
+
"#{filename} looks like it's not a valid Ruby file. Skipping..."
|
44
|
+
)
|
45
45
|
end
|
46
46
|
|
47
47
|
# recursively check ruby sexp node.
|
@@ -52,14 +52,18 @@ module CodeAnalyzer::CheckingVisitor
|
|
52
52
|
def check_node(node)
|
53
53
|
checkers = @checks[node.sexp_type]
|
54
54
|
if checkers
|
55
|
-
checkers.each
|
55
|
+
checkers.each do |checker|
|
56
|
+
checker.node_start(node) if checker.parse_file?(node.file)
|
57
|
+
end
|
56
58
|
end
|
57
|
-
node.children.each
|
59
|
+
node.children.each do |child_node|
|
58
60
|
child_node.file = node.file
|
59
61
|
check_node(child_node)
|
60
|
-
|
62
|
+
end
|
61
63
|
if checkers
|
62
|
-
checkers.each
|
64
|
+
checkers.each do |checker|
|
65
|
+
checker.node_end(node) if checker.parse_file?(node.file)
|
66
|
+
end
|
63
67
|
end
|
64
68
|
end
|
65
69
|
end
|
data/lib/code_analyzer/sexp.rb
CHANGED
@@ -16,10 +16,9 @@ class Sexp
|
|
16
16
|
def line_number
|
17
17
|
case sexp_type
|
18
18
|
when :def, :defs, :command, :command_call, :call, :fcall, :method_add_arg, :method_add_block,
|
19
|
-
:var_ref, :vcall, :const_ref, :const_path_ref, :class, :module,
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:massign
|
19
|
+
:var_ref, :vcall, :const_ref, :const_path_ref, :class, :module, :if, :unless,
|
20
|
+
:elsif, :ifop, :if_mod, :unless_mod, :binary, :alias, :symbol_literal, :symbol,
|
21
|
+
:aref, :hash, :assoc_new, :string_literal, :massign, :var_field
|
23
22
|
self[1].line_number
|
24
23
|
when :assoclist_from_args, :bare_assoc_hash
|
25
24
|
self[1][0].line_number
|
@@ -38,7 +37,7 @@ class Sexp
|
|
38
37
|
#
|
39
38
|
# @return [Array] child nodes.
|
40
39
|
def children
|
41
|
-
find_all { |
|
40
|
+
find_all { |sexp| Sexp === sexp }
|
42
41
|
end
|
43
42
|
|
44
43
|
# recursively find all child nodes, and yeild each child node.
|
@@ -68,10 +67,46 @@ class Sexp
|
|
68
67
|
message = options[:message]
|
69
68
|
to_s = options[:to_s]
|
70
69
|
self.recursive_children do |child|
|
71
|
-
if (
|
72
|
-
|
73
|
-
|
74
|
-
|
70
|
+
if (
|
71
|
+
!sexp_type ||
|
72
|
+
(
|
73
|
+
if sexp_type.is_a?(Array)
|
74
|
+
sexp_type.include?(child.sexp_type)
|
75
|
+
else
|
76
|
+
sexp_type == child.sexp_type
|
77
|
+
end
|
78
|
+
)
|
79
|
+
) &&
|
80
|
+
(
|
81
|
+
!receiver ||
|
82
|
+
(
|
83
|
+
if receiver.is_a?(Array)
|
84
|
+
receiver.include?(child.receiver.to_s)
|
85
|
+
else
|
86
|
+
receiver == child.receiver.to_s
|
87
|
+
end
|
88
|
+
)
|
89
|
+
) &&
|
90
|
+
(
|
91
|
+
!message ||
|
92
|
+
(
|
93
|
+
if message.is_a?(Array)
|
94
|
+
message.include?(child.message.to_s)
|
95
|
+
else
|
96
|
+
message == child.message.to_s
|
97
|
+
end
|
98
|
+
)
|
99
|
+
) &&
|
100
|
+
(
|
101
|
+
!to_s ||
|
102
|
+
(
|
103
|
+
if to_s.is_a?(Array)
|
104
|
+
to_s.include?(child.to_s)
|
105
|
+
else
|
106
|
+
to_s == child.to_s
|
107
|
+
end
|
108
|
+
)
|
109
|
+
)
|
75
110
|
yield child
|
76
111
|
end
|
77
112
|
end
|
@@ -91,7 +126,10 @@ class Sexp
|
|
91
126
|
# the condition value can be Symbol, Array or Sexp.
|
92
127
|
def grep_node(options)
|
93
128
|
result = CodeAnalyzer::Nil.new
|
94
|
-
grep_nodes(options)
|
129
|
+
grep_nodes(options) do |node|
|
130
|
+
result = node
|
131
|
+
break
|
132
|
+
end
|
95
133
|
result
|
96
134
|
end
|
97
135
|
|
@@ -138,9 +176,7 @@ class Sexp
|
|
138
176
|
#
|
139
177
|
# @return [Sexp] module name node
|
140
178
|
def module_name
|
141
|
-
if :module == sexp_type
|
142
|
-
self[1]
|
143
|
-
end
|
179
|
+
self[1] if :module == sexp_type
|
144
180
|
end
|
145
181
|
|
146
182
|
# Get the class name of the class node.
|
@@ -154,9 +190,7 @@ class Sexp
|
|
154
190
|
#
|
155
191
|
# @return [Sexp] class name node
|
156
192
|
def class_name
|
157
|
-
if :class == sexp_type
|
158
|
-
self[1]
|
159
|
-
end
|
193
|
+
self[1] if :class == sexp_type
|
160
194
|
end
|
161
195
|
|
162
196
|
# Get the base class of the class node.
|
@@ -170,9 +204,7 @@ class Sexp
|
|
170
204
|
#
|
171
205
|
# @return [Sexp] base class of class node
|
172
206
|
def base_class
|
173
|
-
if :class == sexp_type
|
174
|
-
self[2]
|
175
|
-
end
|
207
|
+
self[2] if :class == sexp_type
|
176
208
|
end
|
177
209
|
|
178
210
|
# Get the left value of the assign node.
|
@@ -185,9 +217,7 @@ class Sexp
|
|
185
217
|
#
|
186
218
|
# @return [Symbol] left value of lasgn or iasgn node
|
187
219
|
def left_value
|
188
|
-
if :assign == sexp_type
|
189
|
-
self[1]
|
190
|
-
end
|
220
|
+
self[1] if :assign == sexp_type
|
191
221
|
end
|
192
222
|
|
193
223
|
# Get the right value of assign node.
|
@@ -200,9 +230,7 @@ class Sexp
|
|
200
230
|
#
|
201
231
|
# @return [Sexp] right value of assign node
|
202
232
|
def right_value
|
203
|
-
if :assign == sexp_type
|
204
|
-
self[2]
|
205
|
-
end
|
233
|
+
self[2] if :assign == sexp_type
|
206
234
|
end
|
207
235
|
|
208
236
|
# Get the message node.
|
@@ -277,9 +305,7 @@ class Sexp
|
|
277
305
|
#
|
278
306
|
# @return [Sexp] argument node
|
279
307
|
def argument
|
280
|
-
if :binary == sexp_type
|
281
|
-
self[3]
|
282
|
-
end
|
308
|
+
self[3] if :binary == sexp_type
|
283
309
|
end
|
284
310
|
|
285
311
|
# Get all arguments.
|
@@ -305,7 +331,7 @@ class Sexp
|
|
305
331
|
else
|
306
332
|
node = self[1]
|
307
333
|
while true
|
308
|
-
if [
|
334
|
+
if %i[args_add args_add_star].include? node.sexp_type
|
309
335
|
nodes.unshift node[2]
|
310
336
|
node = node[1]
|
311
337
|
elsif :args_new == node.sexp_type
|
@@ -330,9 +356,7 @@ class Sexp
|
|
330
356
|
#
|
331
357
|
# @return [Sexp] conditional statement of if node
|
332
358
|
def conditional_statement
|
333
|
-
if [
|
334
|
-
self[1]
|
335
|
-
end
|
359
|
+
self[1] if %i[if unless elsif ifop if_mod unless_mod].include? sexp_type
|
336
360
|
end
|
337
361
|
|
338
362
|
# Get all condition nodes.
|
@@ -366,13 +390,15 @@ class Sexp
|
|
366
390
|
# @return [Array] all condition nodes
|
367
391
|
def all_conditions
|
368
392
|
nodes = []
|
369
|
-
if :binary == sexp_type && %w
|
370
|
-
if :binary == self[1].sexp_type &&
|
393
|
+
if :binary == sexp_type && %w[&& || and or].include?(self[2].to_s)
|
394
|
+
if :binary == self[1].sexp_type &&
|
395
|
+
%w[&& || and or].include?(self[1][2].to_s)
|
371
396
|
nodes += self[1].all_conditions
|
372
397
|
else
|
373
398
|
nodes << self[1]
|
374
399
|
end
|
375
|
-
if :binary == self[3].sexp_type &&
|
400
|
+
if :binary == self[3].sexp_type &&
|
401
|
+
%w[&& || and or].include?(self[3][2].to_s)
|
376
402
|
nodes += self[3].all_conditions
|
377
403
|
else
|
378
404
|
nodes << self[3]
|
@@ -399,6 +425,7 @@ class Sexp
|
|
399
425
|
when :defs
|
400
426
|
self[3]
|
401
427
|
else
|
428
|
+
|
402
429
|
end
|
403
430
|
end
|
404
431
|
|
@@ -506,13 +533,15 @@ class Sexp
|
|
506
533
|
# @return [Array] all statements
|
507
534
|
def statements
|
508
535
|
stmts = []
|
509
|
-
node =
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
536
|
+
node =
|
537
|
+
case sexp_type
|
538
|
+
when :do_block, :brace_block
|
539
|
+
self[2][1]
|
540
|
+
when :bodystmt
|
541
|
+
self[1]
|
542
|
+
else
|
543
|
+
|
544
|
+
end
|
516
545
|
if node
|
517
546
|
while true
|
518
547
|
if :stmts_add == node.sexp_type && s(:void_stmt) != node[2]
|
@@ -566,9 +595,7 @@ class Sexp
|
|
566
595
|
# )
|
567
596
|
# => s(:var_field, s(:@ident, "e", s(1, 20)))
|
568
597
|
def exception_variable
|
569
|
-
if :rescue == sexp_type
|
570
|
-
self[2]
|
571
|
-
end
|
598
|
+
self[2] if :rescue == sexp_type
|
572
599
|
end
|
573
600
|
|
574
601
|
# Get hash value node.
|
@@ -585,18 +612,18 @@ class Sexp
|
|
585
612
|
#
|
586
613
|
# @return [Sexp] hash value node
|
587
614
|
def hash_value(key)
|
588
|
-
pair_nodes =
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
615
|
+
pair_nodes =
|
616
|
+
case sexp_type
|
617
|
+
when :bare_assoc_hash
|
618
|
+
self[1]
|
619
|
+
when :hash
|
620
|
+
self[1][1]
|
621
|
+
else
|
622
|
+
|
623
|
+
end
|
595
624
|
if pair_nodes
|
596
625
|
pair_nodes.size.times do |i|
|
597
|
-
if key == pair_nodes[i][1].to_s
|
598
|
-
return pair_nodes[i][2]
|
599
|
-
end
|
626
|
+
return pair_nodes[i][2] if key == pair_nodes[i][1].to_s
|
600
627
|
end
|
601
628
|
end
|
602
629
|
CodeAnalyzer::Nil.new
|
@@ -640,18 +667,18 @@ class Sexp
|
|
640
667
|
#
|
641
668
|
# @return [Array] hash keys
|
642
669
|
def hash_keys
|
643
|
-
pair_nodes =
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
670
|
+
pair_nodes =
|
671
|
+
case sexp_type
|
672
|
+
when :bare_assoc_hash
|
673
|
+
self[1]
|
674
|
+
when :hash
|
675
|
+
self[1][1]
|
676
|
+
else
|
677
|
+
|
678
|
+
end
|
650
679
|
if pair_nodes
|
651
680
|
keys = []
|
652
|
-
pair_nodes.size.times
|
653
|
-
keys << pair_nodes[i][1].to_s
|
654
|
-
end
|
681
|
+
pair_nodes.size.times { |i| keys << pair_nodes[i][1].to_s }
|
655
682
|
keys
|
656
683
|
end
|
657
684
|
end
|
@@ -673,18 +700,18 @@ class Sexp
|
|
673
700
|
#
|
674
701
|
# @return [Array] hash values
|
675
702
|
def hash_values
|
676
|
-
pair_nodes =
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
703
|
+
pair_nodes =
|
704
|
+
case sexp_type
|
705
|
+
when :bare_assoc_hash
|
706
|
+
self[1]
|
707
|
+
when :hash
|
708
|
+
self[1][1]
|
709
|
+
else
|
710
|
+
|
711
|
+
end
|
683
712
|
if pair_nodes
|
684
713
|
values = []
|
685
|
-
pair_nodes.size.times
|
686
|
-
values << pair_nodes[i][2]
|
687
|
-
end
|
714
|
+
pair_nodes.size.times { |i| values << pair_nodes[i][2] }
|
688
715
|
values
|
689
716
|
end
|
690
717
|
end
|
@@ -707,7 +734,8 @@ class Sexp
|
|
707
734
|
if first_node
|
708
735
|
while true
|
709
736
|
array_size += 1
|
710
|
-
first_node =
|
737
|
+
first_node =
|
738
|
+
s(:args_new) == first_node[1] ? first_node[2] : first_node[1]
|
711
739
|
if :args_add != first_node.sexp_type
|
712
740
|
if :array == first_node.sexp_type
|
713
741
|
array_size += first_node.array_size
|
@@ -737,9 +765,13 @@ class Sexp
|
|
737
765
|
def array_values
|
738
766
|
case sexp_type
|
739
767
|
when :array
|
740
|
-
if nil == self[1] ||
|
768
|
+
if nil == self[1] ||
|
769
|
+
%i[words_new qwords_new symbols_new qsymbols_new].include?(
|
770
|
+
self[1].sexp_type
|
771
|
+
)
|
741
772
|
[]
|
742
|
-
elsif [
|
773
|
+
elsif %i[words_add qwords_add symbols_add qsymbols_add].include? self[1]
|
774
|
+
.sexp_type
|
743
775
|
self[1].array_values
|
744
776
|
else
|
745
777
|
arguments.all
|
@@ -748,10 +780,12 @@ class Sexp
|
|
748
780
|
values = []
|
749
781
|
node = self
|
750
782
|
while true
|
751
|
-
if [
|
783
|
+
if %i[words_add qwords_add symbols_add qsymbols_add].include? node
|
784
|
+
.sexp_type
|
752
785
|
values.unshift node[2]
|
753
786
|
node = node[1]
|
754
|
-
elsif [
|
787
|
+
elsif %i[words_new qwords_new symbols_new qsymbols_new].include? node
|
788
|
+
.sexp_type
|
755
789
|
break
|
756
790
|
end
|
757
791
|
end
|
@@ -808,22 +842,14 @@ class Sexp
|
|
808
842
|
# @return [String] to_s
|
809
843
|
def to_s
|
810
844
|
case sexp_type
|
811
|
-
when :string_literal, :xstring_literal, :string_content, :const_ref,
|
812
|
-
:args_add_block, :var_ref, :vcall, :var_field,
|
845
|
+
when :string_literal, :xstring_literal, :string_content, :const_ref,
|
846
|
+
:symbol_literal, :symbol, :args_add_block, :var_ref, :vcall, :var_field,
|
813
847
|
:@ident, :@tstring_content, :@const, :@ivar, :@kw, :@gvar, :@cvar
|
814
848
|
self[1].to_s
|
815
849
|
when :string_add
|
816
|
-
|
817
|
-
self[2].to_s
|
818
|
-
else
|
819
|
-
self[1].to_s
|
820
|
-
end
|
850
|
+
s(:string_content) == self[1] ? self[2].to_s : self[1].to_s
|
821
851
|
when :args_add
|
822
|
-
|
823
|
-
self[2].to_s
|
824
|
-
else
|
825
|
-
self[1].to_s
|
826
|
-
end
|
852
|
+
s(:args_new) == self[1] ? self[2].to_s : self[1].to_s
|
827
853
|
when :qwords_add
|
828
854
|
self[2].to_s
|
829
855
|
when :word_add
|
@@ -839,13 +865,17 @@ class Sexp
|
|
839
865
|
when :top_const_ref
|
840
866
|
"::#{self[1]}"
|
841
867
|
else
|
842
|
-
|
868
|
+
''
|
843
869
|
end
|
844
870
|
end
|
845
871
|
|
846
872
|
# check if the self node is a const.
|
847
873
|
def const?
|
848
|
-
:@const == self.sexp_type ||
|
874
|
+
:@const == self.sexp_type ||
|
875
|
+
(
|
876
|
+
%i[var_ref vcall].include?(self.sexp_type) &&
|
877
|
+
:@const == self[1].sexp_type
|
878
|
+
)
|
849
879
|
end
|
850
880
|
|
851
881
|
# true
|
@@ -862,25 +892,42 @@ class Sexp
|
|
862
892
|
def remove_line_and_column
|
863
893
|
node = self.clone
|
864
894
|
last_node = node.last
|
865
|
-
if Sexp === last_node && last_node.size == 2 &&
|
895
|
+
if Sexp === last_node && last_node.size == 2 &&
|
896
|
+
last_node.first.is_a?(Integer) &&
|
897
|
+
last_node.last.is_a?(Integer)
|
866
898
|
node.delete_at(-1)
|
867
899
|
end
|
868
900
|
node.sexp_body.each_with_index do |child, index|
|
869
|
-
if Sexp === child
|
870
|
-
node[index+1] = child.remove_line_and_column
|
871
|
-
end
|
901
|
+
node[index + 1] = child.remove_line_and_column if Sexp === child
|
872
902
|
end
|
873
903
|
node
|
874
904
|
end
|
875
905
|
|
876
906
|
# if the return value of these methods is nil, then return CodeAnalyzer::Nil.new instead
|
877
|
-
[
|
878
|
-
|
907
|
+
%i[
|
908
|
+
sexp_type
|
909
|
+
receiver
|
910
|
+
message
|
911
|
+
arguments
|
912
|
+
argument
|
913
|
+
class_name
|
914
|
+
base_class
|
915
|
+
method_name
|
916
|
+
body
|
917
|
+
block_node
|
918
|
+
conditional_statement
|
919
|
+
left_value
|
920
|
+
right_value
|
921
|
+
].each do |method|
|
879
922
|
class_eval <<-EOS
|
880
923
|
alias_method :origin_#{method}, :#{method}
|
881
924
|
|
882
|
-
def #{
|
883
|
-
|
925
|
+
def #{
|
926
|
+
method
|
927
|
+
}
|
928
|
+
ret = origin_#{
|
929
|
+
method
|
930
|
+
}
|
884
931
|
ret.nil? ? CodeAnalyzer::Nil.new : ret
|
885
932
|
end
|
886
933
|
EOS
|