lib/pronto/brakeman.rb in pronto-brakeman-0.11.0 vs lib/pronto/brakeman.rb in pronto-brakeman-0.11.1

- old
+ new

@@ -2,27 +2,29 @@ require 'brakeman' module Pronto class Brakeman < Runner def run - files = ruby_patches.map do |patch| + patches = ruby_patches | erb_patches + files = patches.map do |patch| patch.new_file_full_path.relative_path_from(repo_path).to_s - end + end.sort return [] unless files.any? output = ::Brakeman.run(app_path: repo_path, output_formats: [:to_s], - only_files: files) - messages_for(ruby_patches, output).compact + only_files: files, + run_all_checks: run_all_checks?) + messages_for(patches, output).compact rescue ::Brakeman::NoApplication [] end - def messages_for(ruby_patches, output) + def messages_for(code_patches, output) output.filtered_warnings.map do |warning| - patch = patch_for_warning(ruby_patches, warning) + patch = patch_for_warning(code_patches, warning) next unless patch line = patch.added_lines.find do |added_line| added_line.new_lineno == warning.line end @@ -47,12 +49,29 @@ else # Brakeman Low confidence (and other possibilities) :info end end - def patch_for_warning(ruby_patches, warning) - ruby_patches.find do |patch| + def patch_for_warning(code_patches, warning) + code_patches.find do |patch| patch.new_file_full_path.to_s == warning.file.absolute end + end + + def run_all_checks? + pronto_brakeman_config['run_all_checks'] + end + + def pronto_brakeman_config + pronto_brakeman_config ||= Pronto::ConfigFile.new.to_h['brakeman'] || {} + end + + def erb_patches + @erb_patches ||= Array(@patches).select { |patch| patch.additions > 0 } + .select { |patch| erb_file?(patch.new_file_full_path) } + end + + def erb_file?(path) + File.extname(path) == '.erb' end end end