class Pedant::CheckUsesOctalIntegers
Public Class Methods
requires()
click to toggle source
Calls superclass method
Pedant::Check::requires
# File lib/pedant/checks/uses_octal_integers.rb, line 29 def self.requires super + [:trees] end
Public Instance Methods
check(file, tree)
click to toggle source
# File lib/pedant/checks/uses_octal_integers.rb, line 33 def check(file, tree) tree.all(:Integer).select { |i| i.tokens.first.type == :INT_OCT }.each do |i| next if i.value == 0 # Lots of plugins use '00' or '0000', which is ok. warn report(:warn, "NASL integers beginning with '0' with all digits between 0-7 are octal.") report(:warn, "This integer will have decimal value '#{i.value}'.") report(:warn, i.context(i)) end tree.all(:Integer).select { |i| i.tokens.first.type == :INT_DEC }.each do |i| next if i.value == 0 # Lots of plugins use '00' or '0000', which is ok. next if not i.tokens.first.body =~ /^0[0-9]/ warn report(:warn, "This integer appears to be octal, but will be interpreted as decimal.") report(:warn, "NASL integers beginning with '0' with all digits between 0-7 are octal.") report(:warn, "Remove the leading '0' to make it clear this integer should be decimal.") report(:warn, i.context(i)) end end
run()
click to toggle source
# File lib/pedant/checks/uses_octal_integers.rb, line 53 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