Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to hide summary in plain/table reports #976

Merged
merged 1 commit into from Dec 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/brakeman.rb
Expand Up @@ -48,8 +48,7 @@ module Brakeman
# * :skip_libs - do not process lib/ directory (default: false)
# * :skip_checks - checks not to run (run all if not specified)
# * :absolute_paths - show absolute path of each file (default: false)
# * :summary_only - only output summary section of report
# (does not apply to tabs format)
# * :summary_only - only output summary section of report for plain/table (:summary_only, :no_summary, true)
#
#Alternatively, just supply a path as a string.
def self.run options
Expand Down
8 changes: 6 additions & 2 deletions lib/brakeman/options.rb
Expand Up @@ -229,8 +229,12 @@ def get_options args, destructive = false
options[:collapse_mass_assignment] = !separate
end

opts.on "--summary", "Only output summary of warnings" do
options[:summary_only] = true
opts.on "--[no-]summary", "Only output summary of warnings" do |summary_only|
if summary_only
options[:summary_only] = :summary_only
else
options[:summary_only] = :no_summary
end
end

opts.on "--absolute-paths", "Output absolute file paths in reports" do
Expand Down
17 changes: 12 additions & 5 deletions lib/brakeman/report/report_table.rb
Expand Up @@ -7,13 +7,20 @@ def initialize *args
end

def generate_report
out = text_header <<
"\n\n+SUMMARY+\n\n" <<
truncate_table(generate_overview.to_s) << "\n\n" <<
truncate_table(generate_warning_overview.to_s) << "\n"
summary_option = tracker.options[:summary_only]
out = ""

unless summary_option == :no_summary
out << text_header <<
"\n\n+SUMMARY+\n\n" <<
truncate_table(generate_overview.to_s) << "\n\n" <<
truncate_table(generate_warning_overview.to_s) << "\n"
end

#Return output early if only summarizing
return out if tracker.options[:summary_only]
if summary_option == :summary_only or summary_option == true
return out
end

if tracker.options[:report_routes] or tracker.options[:debug]
out << "\n+CONTROLLERS+\n" <<
Expand Down
14 changes: 10 additions & 4 deletions lib/brakeman/report/report_text.rb
Expand Up @@ -3,12 +3,18 @@
class Brakeman::Report::Text < Brakeman::Report::Base
def generate_report
HighLine.use_color = !!tracker.options[:output_color]
summary_option = tracker.options[:summary_only]
@output_string = "\n"

add_chunk generate_header
add_chunk generate_overview
add_chunk generate_warning_overview
return @output_string if tracker.options[:summary_only]
unless summary_option == :no_summary
add_chunk generate_header
add_chunk generate_overview
add_chunk generate_warning_overview
end

if summary_option == :summary_only or summary_option == true
return @output_string
end

add_chunk generate_controllers if tracker.options[:debug] or tracker.options[:report_routes]
add_chunk generate_templates if tracker.options[:debug]
Expand Down
10 changes: 9 additions & 1 deletion test/tests/options.rb
Expand Up @@ -15,7 +15,6 @@ class BrakemanOptionsTest < Minitest::Test
:debug => "-d",
:interactive_ignore => "-I",
:report_routes => "-m",
:summary_only => "--summary",
:absolute_paths => "--absolute-paths",
:list_checks => "-k",
:list_optional_checks => "--optional-checks",
Expand Down Expand Up @@ -320,6 +319,15 @@ def test_create_config_file_options
assert options[:create_config]
end

def test_summary_options
options = setup_options_from_input("--summary")

assert_equal :summary_only, options[:summary_only]

options = setup_options_from_input("--no-summary")
assert_equal :no_summary, options[:summary_only]
end

private

def setup_options_from_input(*args)
Expand Down