Class: Pedant::CheckConditionalOrLoopIsEmpty
- Inherits:
-
Check
- Object
- Check
- Pedant::CheckConditionalOrLoopIsEmpty
show all
- Defined in:
- lib/pedant/checks/conditional_or_loop_is_empty.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, inherited, #initialize, initialize!, #name, #pass, provides, ready?, #report, #skip, #warn
Constructor Details
This class inherits a constructor from Pedant::Check
Class Method Details
.requires ⇒ Object
29
30
31
|
# File 'lib/pedant/checks/conditional_or_loop_is_empty.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
|
# File 'lib/pedant/checks/conditional_or_loop_is_empty.rb', line 33
def check(file, tree)
[:For, :Foreach, :Repeat, :While].each do |cls|
tree.all(cls).each do |node|
next unless node.body.is_a? Nasl::Empty
fail
report(:error, "#{cls} loop in #{file} has an empty statement as its body.")
end
end
tree.all(:If).each do |node|
[:true, :false].each do |name|
branch = node.send(name)
next if branch.nil?
next unless branch.is_a? Nasl::Empty
fail
report(:error, "If statement in #{file} has an empty statement as #{name} branch.")
end
end
end
|
#run ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/pedant/checks/conditional_or_loop_is_empty.rb', line 62
def run
pass
@kb[:trees].each { |file, tree| check(file, tree) }
end
|