Class: Pedant::CheckContainsUnreachableCode
- Inherits:
-
Check
- Object
- Check
- Pedant::CheckContainsUnreachableCode
show all
- Defined in:
- lib/pedant/checks/contains_unreachable_code.rb
Instance Attribute Summary
Attributes inherited from Check
#result
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Check
all, depends, #fail, #fatal, friendly_name, inherited, #initialize, initialize!, list, #pass, provides, ready?, #report, run_checks_in_dependency_order, #skip, #warn
Constructor Details
This class inherits a constructor from Pedant::Check
Class Method Details
.requires ⇒ Object
29
30
31
|
# File 'lib/pedant/checks/contains_unreachable_code.rb', line 29
def self.requires
super + [:trees]
end
|
Instance Method Details
#check(file, tree) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/pedant/checks/contains_unreachable_code.rb', line 33
def check(file, tree)
def check_statements(file, list)
list.each do |node|
next if node.is_a?(Nasl::Call) and
node.name.ident.name == 'exit' and
node.args.length == 2 and
node.args[1].expr.is_a?(Nasl::String) and
node.args[1].expr.text =~ /plugin has been deprecated|patch has been replaced/i
if node.is_a?(Nasl::Break) || node.is_a?(Nasl::Continue) ||
node.is_a?(Nasl::Return) || (node.is_a?(Nasl::Call) &&
(node.name.ident.name == 'exit' ||
node.name.ident.name == 'audit') && node.name.indexes == [])
return node if node != list.last
end
end
return nil
end
tree.all(:Block).each do |blk|
node = check_statements(file, blk.body)
if not node.nil?
fail
report(:error, node.context(blk))
end
end
node = check_statements(file, tree)
if not node.nil?
fail
report(:error, node.context(node))
end
end
|
#check_statements(file, list) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/pedant/checks/contains_unreachable_code.rb', line 34
def check_statements(file, list)
list.each do |node|
next if node.is_a?(Nasl::Call) and
node.name.ident.name == 'exit' and
node.args.length == 2 and
node.args[1].expr.is_a?(Nasl::String) and
node.args[1].expr.text =~ /plugin has been deprecated|patch has been replaced/i
if node.is_a?(Nasl::Break) || node.is_a?(Nasl::Continue) ||
node.is_a?(Nasl::Return) || (node.is_a?(Nasl::Call) &&
(node.name.ident.name == 'exit' ||
node.name.ident.name == 'audit') && node.name.indexes == [])
return node if node != list.last
end
end
return nil
end
|
#run ⇒ Object
84
85
86
87
88
89
90
|
# File 'lib/pedant/checks/contains_unreachable_code.rb', line 84
def run
pass
@kb[:trees].each { |file, tree| check(file, tree) }
end
|