lib/vmdb/util.rb
Use =~
in places where the MatchData
returned by #match
will not be used. Open
Open
f.match(/.+-(\d+\.gz)/)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop identifies the use of Regexp#match
or String#match
, which
returns #<MatchData>
/nil
. The return value of =~
is an integral
index/nil
and is more performant.
Example:
# bad
do_something if str.match(/regex/)
while regex.match('str')
do_something
end
# good
method(str =~ /regex/)
return value unless regex =~ 'str'
Avoid rescuing the Exception
class. Perhaps you meant to rescue StandardError
? Open
Open
rescue Exception => e
_log.error(e.to_s)
return []
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for rescue blocks targeting the Exception class.
Example:
# bad
begin
do_something
rescue Exception
handle_exception
end
Example:
# good
begin
do_something
rescue ArgumentError
handle_exception
end