Class: Pedant::CheckFilesParseWithoutErrors
- Inherits:
-
Check
- Object
- Check
- Pedant::CheckFilesParseWithoutErrors
show all
- Defined in:
- lib/pedant/checks/files_parse_without_errors.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, ready?, #report, run_checks_in_dependency_order, #skip, #warn
Constructor Details
This class inherits a constructor from Pedant::Check
Class Method Details
.provides ⇒ Object
33
34
35
|
# File 'lib/pedant/checks/files_parse_without_errors.rb', line 33
def self.provides
super + [:codes, :trees]
end
|
.requires ⇒ Object
29
30
31
|
# File 'lib/pedant/checks/files_parse_without_errors.rb', line 29
def self.requires
super + [:file_mode, :base, :main]
end
|
Instance Method Details
#import(path) ⇒ Object
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
63
64
65
66
67
68
69
70
71
|
# File 'lib/pedant/checks/files_parse_without_errors.rb', line 38
def import(path)
path = @kb[:base] + path
file = path.basename
@kb[:codes][file] = :pending
@kb[:trees][file] = :pending
begin
contents = File.open(path, "rb").read
@kb[:codes][file] = contents
report(:info, "Read contents of #{path}.")
rescue
report(:error, "Failed to read contents of #{path}.")
return fatal
end
begin
tree = Nasl::Parser.new.parse(contents, path)
@kb[:trees][file] = tree
report(:info, "Parsed contents of #{path}.")
rescue Nasl::ParseException, Nasl::TokenException => e
report(:error, "Failed to parse #{path}.")
report(:error, e.message)
report(:error, e.backtrace)
return fatal
end
end
|
#run ⇒ Object
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/pedant/checks/files_parse_without_errors.rb', line 37
def run
def import(path)
path = @kb[:base] + path
file = path.basename
@kb[:codes][file] = :pending
@kb[:trees][file] = :pending
begin
contents = File.open(path, "rb").read
@kb[:codes][file] = contents
report(:info, "Read contents of #{path}.")
rescue
report(:error, "Failed to read contents of #{path}.")
return fatal
end
begin
tree = Nasl::Parser.new.parse(contents, path)
@kb[:trees][file] = tree
report(:info, "Parsed contents of #{path}.")
rescue Nasl::ParseException, Nasl::TokenException => e
report(:error, "Failed to parse #{path}.")
report(:error, e.message)
report(:error, e.backtrace)
return fatal
end
end
pass
@kb[:codes] = {}
@kb[:trees] = {}
import(@kb[:main])
return
while true
libs = Nasl::Include.all.map do |inc|
(@kb[:base] + inc.filename.text).basename
end
libs.delete_if { |lib| lib == @kb[:main] || @kb[:trees].has_key?(lib) }
break if libs.empty?
libs.each { |lib| import(lib) }
end
end
|