class Warnings::BanditParser

Parser class for bandit generated json files.

Constants

ERROR_MISSING_KEY
NAME
RESULTS_KEY

Public Instance Methods

name() click to toggle source
# File lib/warnings/parser/bandit_parser.rb, line 19
def name
  NAME
end
parse(file) click to toggle source
# File lib/warnings/parser/bandit_parser.rb, line 11
def parse(file)
  json_hash = json(file)
  results_hash = json_hash[RESULTS_KEY]
  raise(ERROR_MISSING_KEY) if results_hash.nil?

  results_hash.each(&method(:store_issue))
end

Private Instance Methods

store_issue(hash) click to toggle source
# File lib/warnings/parser/bandit_parser.rb, line 25
def store_issue(hash)
  issue = Issue.new
  issue.file_name = hash['filename']
  issue.severity = to_severity(hash['issue_severity'])
  issue.message = hash['issue_text']
  issue.line = hash['line_number']
  issue.category = "#{hash['test_id']}-#{hash['test_name']}"
  @issues << issue
end
to_severity(severity) click to toggle source
# File lib/warnings/parser/bandit_parser.rb, line 35
def to_severity(severity)
  severity.downcase.to_sym
end