guard-brakeman 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +3 -0
  2. data/lib/guard/brakeman.rb +31 -25
  3. metadata +9 -11
data/README.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  Guard::Brakeman allows you to automatically run [Brakeman](http://brakemanscanner.org/) tests when files are modified.
4
4
 
5
+ Use guard-brakeman >= 0.4.0 for brakeman >= 1.5.3
6
+ --------------
7
+ And use < 0.4.0 for brakeman < 1.5.3
5
8
 
6
9
  ## Install
7
10
 
@@ -24,6 +24,9 @@ module Guard
24
24
 
25
25
  # TODO mixing the use of this attr, good to match? Bad to couple?
26
26
  @options = {
27
+ :notifications => true,
28
+ :run_on_start => false,
29
+ :chatty => false,
27
30
  :min_confidence => 1
28
31
  }.update(options)
29
32
  end
@@ -75,19 +78,19 @@ module Guard
75
78
  private
76
79
 
77
80
  def print_failed report
78
- all_warnings = report.all_warnings
81
+ UI.info "\n------ brakeman warnings --------\n"
79
82
 
80
- unless @options[:no_console_output]
81
- UI.info "\n------ brakeman warnings --------\n"
82
- puts all_warnings.sort_by { |w| w.confidence }
83
- end
83
+ icon = report.all_warnings.count > 0 ? :failed : :success
84
+
85
+ all_warnings = reject_below_threshold(report.all_warnings)
86
+
87
+ puts all_warnings.sort_by { |w| w.confidence }
84
88
 
85
- icon = all_warnings.count > 0 ? :failed : :success
86
89
  message = "#{all_warnings.count} brakeman findings"
87
90
 
88
- if @options[:output_file]
91
+ if @options[:output_files]
89
92
  write_report
90
- message += "\nResults written to #{@options[:output_file]}"
93
+ message += "\nResults written to #{@options[:output_files]}"
91
94
  end
92
95
 
93
96
  if @options[:chatty] && all_warnings.any?
@@ -101,8 +104,7 @@ module Guard
101
104
  message = ""
102
105
  should_alert = false
103
106
 
104
- fixed_warnings = report.fixed_warnings
105
-
107
+ fixed_warnings = reject_below_threshold(report.fixed_warnings)
106
108
  if fixed_warnings.any?
107
109
  icon = :success
108
110
  results_notification = "#{fixed_warnings.length} fixed warning(s)\n"
@@ -111,13 +113,11 @@ module Guard
111
113
  should_alert = true
112
114
  message += results_notification
113
115
 
114
- unless @options[:no_console_output]
115
- puts fixed_warnings.sort_by { |w| w.confidence }
116
- puts
117
- end
116
+ puts fixed_warnings.sort_by { |w| w.confidence }
117
+ puts
118
118
  end
119
119
 
120
- new_warnings = report.new_warnings
120
+ new_warnings = reject_below_threshold(report.new_warnings)
121
121
  if new_warnings.any?
122
122
  new_warning_message = "#{new_warnings.length} new warning(s)\n"
123
123
  UI.error new_warning_message
@@ -126,13 +126,11 @@ module Guard
126
126
  should_alert = true
127
127
  icon = :failed
128
128
 
129
- unless @options[:no_console_output]
130
- puts new_warnings.sort_by { |w| w.confidence }
131
- puts
132
- end
129
+ puts new_warnings.sort_by { |w| w.confidence }
130
+ puts
133
131
  end
134
132
 
135
- existing_warnings = report.existing_warnings
133
+ existing_warnings = reject_below_threshold(report.existing_warnings)
136
134
  if existing_warnings.any?
137
135
  should_alert = true if @options[:chatty]
138
136
  icon ||= :pending
@@ -141,12 +139,14 @@ module Guard
141
139
  UI.warning existing_warning_message
142
140
  message += existing_warning_message
143
141
 
144
- puts existing_warnings.sort_by { |w| w.confidence } unless @options[:no_console_output]
142
+ puts existing_warnings.sort_by { |w| w.confidence }
145
143
  end
146
144
 
147
- if @options[:output_file]
145
+
146
+
147
+ if @options[:output_files]
148
148
  write_report
149
- message += "\nResults written to #{@options[:output_file]}"
149
+ message += "\nResults written to #{@options[:output_files]}"
150
150
  end
151
151
 
152
152
  if @options[:notifications] && should_alert
@@ -154,9 +154,15 @@ module Guard
154
154
  end
155
155
  end
156
156
 
157
+ def reject_below_threshold(warnings)
158
+ warnings.reject {|w| w.confidence > (3 - @options[:min_confidence].to_i)}
159
+ end
160
+
157
161
  def write_report
158
- File.open @options[:output_file], "w" do |f|
159
- f.puts @tracker.report.send(@options[:output_format])
162
+ @options[:output_files].each_with_index do |output_file, i|
163
+ File.open output_file, "w" do |f|
164
+ f.puts @tracker.report.send(@options[:output_formats][i])
165
+ end
160
166
  end
161
167
  end
162
168
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-brakeman
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 2
10
- version: 0.3.2
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Neil Matatall
@@ -16,8 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-04-09 00:00:00 -07:00
20
- default_executable:
19
+ date: 2012-05-03 00:00:00 Z
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
22
  name: guard
@@ -43,12 +42,12 @@ dependencies:
43
42
  requirements:
44
43
  - - ">="
45
44
  - !ruby/object:Gem::Version
46
- hash: 7
45
+ hash: 5
47
46
  segments:
48
47
  - 1
49
48
  - 5
50
- - 2
51
- version: 1.5.2
49
+ - 3
50
+ version: 1.5.3
52
51
  type: :runtime
53
52
  version_requirements: *id002
54
53
  description: Guard::Brakeman automatically scans your Rails app for vulnerabilities
@@ -64,7 +63,6 @@ files:
64
63
  - lib/guard/brakeman.rb
65
64
  - LICENSE
66
65
  - README.md
67
- has_rdoc: true
68
66
  homepage: http://rubygems.org/gems/guard-brakeman
69
67
  licenses: []
70
68
 
@@ -96,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
94
  requirements: []
97
95
 
98
96
  rubyforge_project: guard-brakeman
99
- rubygems_version: 1.4.2
97
+ rubygems_version: 1.8.15
100
98
  signing_key:
101
99
  specification_version: 3
102
100
  summary: Guard gem for Brakeman