Class: Maximus::Brakeman

Inherits:
Lint
  • Object
show all
Defined in:
lib/maximus/lints/brakeman.rb

Overview

Since:

  • 0.1.0

Instance Attribute Summary

Attributes inherited from Lint

#output

Instance Method Summary collapse

Methods inherited from Lint

#initialize, #refine

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

#resultObject

Brakeman (requires Rails)

See Also:

Since:

  • 0.1.0


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
47
48
49
50
51
52
# File 'lib/maximus/lints/brakeman.rb', line 8

def result

  return unless is_rails?

  @task = 'brakeman'

  return unless temp_config(@task)

  @path = @settings[:root_dir] if @path.blank?

  return unless 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