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, 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/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
61
62
|
# 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.")
report(:error, node.body.context(node))
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.")
report(:error, branch.context(node))
end
end
end
|
#run ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/pedant/checks/conditional_or_loop_is_empty.rb', line 64
def run
pass
@kb[:trees].each { |file, tree| check(file, tree) }
end
|