Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit 7df48b4

Browse files
committed
Update rubocop
Signed-off-by: Florian Wininger <[email protected]>
1 parent dbec1a2 commit 7df48b4

File tree

10 files changed

+66
-61
lines changed

10 files changed

+66
-61
lines changed

.rubocop_todo.yml

+25-31
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2017-12-21 10:52:38 +0100 using RuboCop version 0.52.0.
3+
# on 2019-07-03 09:07:58 +0200 using RuboCop version 0.72.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -13,26 +13,27 @@ Lint/DuplicateMethods:
1313

1414
# Offense count: 7
1515
Metrics/AbcSize:
16-
Max: 70
16+
Max: 67
1717

1818
# Offense count: 11
1919
# Configuration parameters: CountComments, ExcludedMethods.
20+
# ExcludedMethods: refine
2021
Metrics/BlockLength:
21-
Max: 79
22+
Max: 109
2223

2324
# Offense count: 5
2425
# Configuration parameters: CountComments.
2526
Metrics/ClassLength:
26-
Max: 187
27+
Max: 189
2728

2829
# Offense count: 2
2930
Metrics/CyclomaticComplexity:
3031
Max: 12
3132

3233
# Offense count: 10
33-
# Configuration parameters: CountComments.
34+
# Configuration parameters: CountComments, ExcludedMethods.
3435
Metrics/MethodLength:
35-
Max: 49
36+
Max: 47
3637

3738
# Offense count: 2
3839
Metrics/PerceivedComplexity:
@@ -51,11 +52,16 @@ Naming/FileName:
5152
- 'lib/ruby-nessus.rb'
5253
- 'lib/ruby-nessus/ruby-nessus.rb'
5354

54-
# Offense count: 5
55-
Style/DateTime:
55+
# Offense count: 13
56+
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
57+
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
58+
Naming/MemoizedInstanceVariableName:
5659
Exclude:
5760
- 'lib/ruby-nessus/version1/host.rb'
5861
- 'lib/ruby-nessus/version1/scan.rb'
62+
- 'lib/ruby-nessus/version2/event.rb'
63+
- 'lib/ruby-nessus/version2/host.rb'
64+
- 'lib/ruby-nessus/version2/scan.rb'
5965

6066
# Offense count: 12
6167
Style/Documentation:
@@ -75,11 +81,14 @@ Style/Documentation:
7581
- 'lib/ruby-nessus/version2/port.rb'
7682
- 'lib/ruby-nessus/version2/scan.rb'
7783

78-
# Offense count: 14
79-
# Configuration parameters: .
80-
# SupportedStyles: annotated, template, unannotated
81-
Style/FormatStringToken:
82-
EnforcedStyle: unannotated
84+
# Offense count: 3
85+
# Configuration parameters: EnforcedStyle.
86+
# SupportedStyles: left_coerce, right_coerce, single_coerce, fdiv
87+
Style/FloatDivision:
88+
Exclude:
89+
- 'lib/ruby-nessus/version1/scan.rb'
90+
- 'lib/ruby-nessus/version2/host.rb'
91+
- 'lib/ruby-nessus/version2/scan.rb'
8392

8493
# Offense count: 10
8594
# Configuration parameters: MinBodyLength.
@@ -92,7 +101,7 @@ Style/GuardClause:
92101

93102
# Offense count: 3
94103
# Cop supports --auto-correct.
95-
# Configuration parameters: AutoCorrect, EnforcedStyle.
104+
# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods.
96105
# SupportedStyles: predicate, comparison
97106
Style/NumericPredicate:
98107
Exclude:
@@ -101,24 +110,9 @@ Style/NumericPredicate:
101110
- 'lib/ruby-nessus/version2/host.rb'
102111
- 'lib/ruby-nessus/version2/scan.rb'
103112

104-
# Offense count: 1
113+
# Offense count: 83
105114
# Cop supports --auto-correct.
106-
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
107-
# SupportedStyles: slashes, percent_r, mixed
108-
Style/RegexpLiteral:
109-
Exclude:
110-
- 'lib/ruby-nessus/version1/port.rb'
111-
112-
# Offense count: 1
113-
# Cop supports --auto-correct.
114-
# Configuration parameters: EnforcedStyle.
115-
# SupportedStyles: implicit, explicit
116-
Style/RescueStandardError:
117-
Exclude:
118-
- 'lib/ruby-nessus/cli.rb'
119-
120-
# Offense count: 75
121-
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
115+
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
122116
# URISchemes: http, https
123117
Metrics/LineLength:
124118
Max: 185

lib/ruby-nessus/cli.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def optparse(*args)
115115
Log.it
116116
exit(-1)
117117
end
118-
rescue => e
118+
rescue StandardError => e
119119
Log.error e.message
120120
Log.it opts
121121
Log.it

lib/ruby-nessus/log.rb

+17-17
Original file line numberDiff line numberDiff line change
@@ -8,77 +8,77 @@ class Log
88
# Formatting
99
#
1010
def self.it(msg = nil)
11-
STDERR.puts msg.to_s
11+
warn msg.to_s
1212
end
1313

1414
def self.it!(msg = nil)
15-
STDERR.puts "\t#{msg}"
15+
warn "\t#{msg}"
1616
end
1717

1818
def self.break
19-
STDERR.puts "\t"
20-
STDERR.puts ''
19+
warn "\t"
20+
warn ''
2121
end
2222

2323
def self.end
24-
STDERR.puts "\n\n"
24+
warn "\n\n"
2525
end
2626

2727
#
2828
# Headers
2929
#
3030
def self.h1(title, msg = nil)
31-
STDERR.puts Rainbow("-> #{title}: ").foreground(:green).bright + msg.to_s
31+
warn Rainbow("-> #{title}: ").foreground(:green).bright + msg.to_s
3232
end
3333

3434
def self.h2(title, msg = nil)
35-
STDERR.puts Rainbow("\t#{title}: ").foreground(:blue).bright + msg.to_s
35+
warn Rainbow("\t#{title}: ").foreground(:blue).bright + msg.to_s
3636
end
3737

3838
def self.h3(title, msg = nil)
39-
STDERR.puts "\t#{title}: " + Rainbow(msg.to_s).foreground(:blue).underline
39+
warn "\t#{title}: " + Rainbow(msg.to_s).foreground(:blue).underline
4040
end
4141

4242
def self.h4(msg = nil)
43-
STDERR.puts "\t\t- #{msg}"
43+
warn "\t\t- #{msg}"
4444
end
4545

4646
def self.h5(title, msg = nil)
47-
STDERR.puts "\t\t- #{title}: #{msg}"
47+
warn "\t\t- #{title}: #{msg}"
4848
end
4949

5050
#
5151
# Errors
5252
#
5353
def self.error(msg = nil)
54-
STDERR.puts Rainbow('ERROR: ').foreground(:red).bright + msg.to_s
54+
warn Rainbow('ERROR: ').foreground(:red).bright + msg.to_s
5555
end
5656

5757
def self.warn(msg = nil)
58-
STDERR.puts Rainbow('WARNING: ').foreground(:yellow).bright + msg.to_s
58+
warn Rainbow('WARNING: ').foreground(:yellow).bright + msg.to_s
5959
end
6060

6161
def self.info(msg = nil)
62-
STDERR.puts Rainbow('INFO: ').foreground(:green).bright + msg.to_s
62+
warn Rainbow('INFO: ').foreground(:green).bright + msg.to_s
6363
end
6464

6565
#
6666
# Event Severities
6767
#
6868
def self.informational(title, msg = nil)
69-
STDERR.puts Rainbow("\t#{title}: ").foreground(:magenta).bright + msg.to_s
69+
warn Rainbow("\t#{title}: ").foreground(:magenta).bright + msg.to_s
7070
end
7171

7272
def self.low(title, msg = nil)
73-
STDERR.puts Rainbow("\t#{title}: ").foreground(:green) + msg.to_s
73+
warn Rainbow("\t#{title}: ").foreground(:green) + msg.to_s
7474
end
7575

7676
def self.medium(title, msg = nil)
77-
STDERR.puts Rainbow("\t#{title}: ").foreground(:yellow).bright + msg.to_s
77+
warn Rainbow("\t#{title}: ").foreground(:yellow).bright + msg.to_s
7878
end
7979

8080
def self.high(title, msg = nil)
81-
STDERR.puts Rainbow("\t#{title}: ").foreground(:red).bright + msg.to_s
81+
warn Rainbow("\t#{title}: ").foreground(:red).bright + msg.to_s
8282
end
8383
end
8484
end

lib/ruby-nessus/version1/host.rb

+4
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def informational_events(&block)
128128

129129
@host.xpath('ReportItem').each do |event|
130130
next if event.at('severity').inner_text.to_i != 0
131+
131132
@informational_events << Event.new(event)
132133
@informational_event_count += 1
133134
end
@@ -156,6 +157,7 @@ def low_severity_events(&block)
156157

157158
@host.xpath('ReportItem').each do |event|
158159
next if event.at('severity').inner_text.to_i != 1
160+
159161
@low_severity_events << Event.new(event)
160162
end
161163

@@ -183,6 +185,7 @@ def medium_severity_events(&block)
183185

184186
@host.xpath('ReportItem').each do |event|
185187
next if event.at('severity').inner_text.to_i != 2
188+
186189
@medium_severity_events << Event.new(event)
187190
end
188191

@@ -210,6 +213,7 @@ def high_severity_events(&block)
210213

211214
@host.xpath('ReportItem').each do |event|
212215
next if event.at('severity').inner_text.to_i != 3
216+
213217
@high_severity_events << Event.new(event)
214218
end
215219

lib/ruby-nessus/version1/port.rb

+2-6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def initialize(service, number, protocol, raw_string)
3333
# Port.parse(port)
3434
def self.parse(str)
3535
@full_port = str
36-
components = str.match(/^([^\(]+)\((\d+)\/([^\)]+)\)/)
36+
components = str.match(%r{^([^\(]+)\((\d+)/([^\)]+)\)})
3737

3838
if components
3939
return Port.new(components[1].strip, components[2].strip, components[3].strip, str)
@@ -73,11 +73,7 @@ def to_s
7373
# @return [Boolean]
7474
# Return false if the port object number is nil
7575
def number
76-
if @number
77-
@number
78-
else
79-
false
80-
end
76+
@number || false
8177
end
8278
end
8379
end

lib/ruby-nessus/version1/scan.rb

+2
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,10 @@ def event_percentage_for(type, round_percentage = false)
361361
#
362362
def find_by_hostname(hostname, &block)
363363
raise "Error: hostname can't be blank." if hostname.nil? || hostname.empty?
364+
364365
@xml.xpath('//ReportHost[HostName]').each do |host|
365366
next unless host.inner_text.match(hostname)
367+
366368
yield(Host.new(host)) if block
367369
end
368370
end

lib/ruby-nessus/version2/event.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def exploitability_ease
353353
# Return the event exploit available.
354354
#
355355
def exploit_available
356-
@exploit_available ||= @event.at('exploit_available')&.inner_text == "true"
356+
@exploit_available ||= @event.at('exploit_available')&.inner_text == 'true'
357357
end
358358

359359
#
@@ -363,7 +363,7 @@ def exploit_available
363363
# Return the event exploit framework canvas.
364364
#
365365
def exploit_framework_canvas
366-
@exploit_framework_canvas ||= @event.at('exploit_framework_canvas')&.inner_text == "true"
366+
@exploit_framework_canvas ||= @event.at('exploit_framework_canvas')&.inner_text == 'true'
367367
end
368368

369369
#
@@ -383,7 +383,7 @@ def canvas_package
383383
# Return the event exploit framework metasploit.
384384
#
385385
def exploit_framework_metasploit
386-
@exploit_framework_metasploit ||= @event.at('exploit_framework_metasploit')&.inner_text == "true"
386+
@exploit_framework_metasploit ||= @event.at('exploit_framework_metasploit')&.inner_text == 'true'
387387
end
388388

389389
#
@@ -403,7 +403,7 @@ def metasploit_name
403403
# Return the event exploit framework core.
404404
#
405405
def exploit_framework_core
406-
@exploit_framework_core ||= @event.at('exploit_framework_core')&.inner_text == "true"
406+
@exploit_framework_core ||= @event.at('exploit_framework_core')&.inner_text == 'true'
407407
end
408408
end
409409
end

lib/ruby-nessus/version2/host.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def to_s
2222
end
2323

2424
def name
25-
@host["name"]
25+
@host['name']
2626
end
2727

2828
#
@@ -94,6 +94,7 @@ def stop_time
9494
#
9595
def runtime
9696
return unless stop_time && start_time
97+
9798
Time.at(stop_time - start_time).utc.strftime('%H hours %M minutes and %S seconds')
9899
end
99100
alias scan_runtime runtime
@@ -169,6 +170,7 @@ def open_ports
169170
#
170171
def informational_severity_events
171172
return if @informational_events
173+
172174
@informational_events = @host.xpath('ReportItem').select { |event| event['severity'].to_i.zero? }.map do |event|
173175
Event.new(event)
174176
end
@@ -190,6 +192,7 @@ def informational_severity_events
190192
#
191193
def low_severity_events
192194
return if @low_severity_events
195+
193196
@low_severity_events = @host.xpath('ReportItem').select { |event| (event['severity'].to_i == 1) }.map do |event|
194197
Event.new(event)
195198
end
@@ -211,6 +214,7 @@ def low_severity_events
211214
#
212215
def medium_severity_events
213216
return if @medium_severity_events
217+
214218
@medium_severity_events = @host.xpath('ReportItem').select { |event| (event['severity'].to_i == 2) }.map do |event|
215219
Event.new(event)
216220
end
@@ -232,6 +236,7 @@ def medium_severity_events
232236
#
233237
def high_severity_events
234238
return if @high_severity_events
239+
235240
@high_severity_events = @host.xpath('ReportItem').select { |event| (event['severity'].to_i == 3) }.map do |event|
236241
Event.new(event)
237242
end
@@ -253,6 +258,7 @@ def high_severity_events
253258
#
254259
def critical_severity_events
255260
return if @critical_events
261+
256262
@critical_events = @host.xpath('ReportItem').select { |event| (event['severity'].to_i == 4) }.map do |event|
257263
Event.new(event)
258264
end
@@ -312,6 +318,7 @@ def events
312318
#
313319
def ports
314320
return if @ports
321+
315322
@ports = @host.xpath('ReportItem').map { |port| port['port'] }.uniq.sort
316323
end
317324

lib/ruby-nessus/version2/scan.rb

+2
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,10 @@ def event_percentage_for(type, round_percentage = nil)
324324
#
325325
def find_by_hostname(hostname, &block)
326326
raise "Error: hostname can't be blank." if hostname.nil? || hostname.empty?
327+
327328
@xml.xpath('//ReportHost').each do |host|
328329
next unless host['name'].match(hostname)
330+
329331
yield(Host.new(host)) if block
330332
end
331333
end

0 commit comments

Comments
 (0)