Class: Maximus::Brakeman
Overview
Instance Attribute Summary
Attributes inherited from Lint
Instance Method Summary collapse
-
#result ⇒ Object
Brakeman (requires Rails).
Methods inherited from Lint
Methods included from Helper
#check_default_config_path, #edit_yaml, #file_count, #file_list, #is_rails?, #lines_added_to_range, #node_module_exists, #path_exists?, #prompt, #reporter_path, #root_dir, #truthy?
Constructor Details
This class inherits a constructor from Maximus::Lint
Instance Method Details
#result ⇒ Object
Brakeman (requires Rails)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/maximus/lints/brakeman.rb', line 7 def result @task = 'brakeman' @path = @settings[:root_dir] if @path.blank? return unless is_rails? && temp_config(@task) && path_exists?(@path) tmp = Tempfile.new('brakeman') quietly { `brakeman #{@path} -f json -o #{tmp.path} -q` } brakeman = tmp.read tmp.close tmp.unlink unless brakeman.blank? bjson = JSON.parse(brakeman) @output[:ignored_warnings] = bjson['scan_info']['ignored_warnings'] @output[:checks_performed] = bjson['scan_info']['checks_performed'] @output[:number_of_controllers] = bjson['scan_info']['number_of_controllers'] @output[:number_of_models] = bjson['scan_info']['number_of_models'] @output[:number_of_templates] = bjson['scan_info']['number_of_templates'] @output[:ruby_version] = bjson['scan_info']['ruby_version'] @output[:rails_version] = bjson['scan_info']['rails_version'] brakeman = {} ['warnings', 'errors'].each do |type| new_brakeman = bjson[type].group_by { |s| s['file'] } new_brakeman.each do |file, errors| if file brakeman[file.to_sym] = errors.map { |e| hash_for_brakeman(e, type) } end end end # The output of brakeman is a mix of strings and symbols # but resetting the JSON like this standardizes everything. # @todo Better way to get around this? brakeman = JSON.parse(brakeman.to_json) end @output[:files_inspected] ||= files_inspected('rb', ' ') refine brakeman end |