class Pedant::CheckConditionalOrLoopIsEmpty
Public Class Methods
requires()
click to toggle source
Calls superclass method
Pedant::Check::requires
# File lib/pedant/checks/conditional_or_loop_is_empty.rb, line 29 def self.requires super + [:trees] end
Public Instance Methods
check(file, tree)
click to toggle source
# File lib/pedant/checks/conditional_or_loop_is_empty.rb, line 33 def check(file, tree) # All of the loops have a body attribute, so they can be checked together. [: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 # An If statement may has two branches, each of which need to be checked. # This will not cause false positives on If statements without else # clauses, because those branches will be nil. 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()
click to toggle source
# File lib/pedant/checks/conditional_or_loop_is_empty.rb, line 64 def run # This check will pass by default. pass # Run this check on the tree from every file. @kb[:trees].each { |file, tree| check(file, tree) } end