Class: Pedant::CheckUsesOctalIntegers
- Inherits:
-
Check
- Object
- Check
- Pedant::CheckUsesOctalIntegers
show all
- Defined in:
- lib/pedant/checks/uses_octal_integers.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/uses_octal_integers.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
|
# 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 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 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 ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/pedant/checks/uses_octal_integers.rb', line 53
def run
pass
@kb[:trees].each { |file, tree| check(file, tree) }
end
|