Showing 2,704 of 2,705 total issues
Use =~
in places where the MatchData
returned by #match
will not be used. Open
cidr = cidr + "/32" if cidr.match(/^\d+\.\d+\.\d+\.\d+$/)
- Read upRead up
- 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 more than 4 levels of block nesting. Open
if !@vpc
sibling = sib_by_name.values.sample
MU.log "Got multiple matching VPCs for #{self.class.cfg_name} #{@mu_name}, so I'm arbitrarily choosing #{sibling.mu_name}", MU::WARN, details: @config['vpc']
@vpc = sibling
end
- Read upRead up
- Exclude checks
This cop checks for excessive nesting of conditional and looping constructs.
You can configure if blocks are considered using the CountBlocks
option. When set to false
(the default) blocks are not counted
towards the nesting level. Set to true
to count blocks as well.
The maximum level of nesting allowed is configurable.
Do not suppress exceptions. Open
rescue StandardError => e
- Read upRead up
- Exclude checks
This cop checks for rescue blocks with no body.
Example:
# bad
def some_method
do_something
rescue
# do nothing
end
Example:
# bad
begin
do_something
rescue
# do nothing
end
Example:
# good
def some_method
do_something
rescue
handle_exception
end
Example:
# good
begin
do_something
rescue
handle_exception
end
The use of eval
is a serious security risk. Open
mu_yaml_schema = eval(%Q{
- Read upRead up
- Exclude checks
This cop checks for the use of Kernel#eval
and Binding#eval
.
Example:
# bad
eval(something)
binding.eval(something)
Use caller(5..5).first
instead of caller[4]
. Open
MU.log "Reference schema alias #{k} wants to alias #{v}, but no such attribute exists", MU::WARN, details: caller[4]
- Read upRead up
- Exclude checks
This cop identifies places where caller[n]
can be replaced by caller(n..n).first
.
Example:
# bad
caller[1]
caller.first
caller_locations[1]
caller_locations.first
# good
caller(2..2).first
caller(1..1).first
caller_locations(2..2).first
caller_locations(1..1).first
private
(on line 143) does not make singleton methods private. Use private_class_method
or private
inside a class << self
block instead. Open
def self.isGlobal?
- Read upRead up
- Exclude checks
This cop checks for private
or protected
access modifiers which are
applied to a singleton method. These access modifiers do not make
singleton methods private/protected. private_class_method
can be
used for that.
Example:
# bad
class C
private
def self.method
puts 'hi'
end
end
Example:
# good
class C
def self.method
puts 'hi'
end
private_class_method :method
end
Example:
# good
class C
class << self
private
def method
puts 'hi'
end
end
end
Unused method argument - args
. If it's necessary, use _
or _args
as an argument name to indicate that it won't be used. You can also write as cleanup(*)
if you want the method to accept any arguments but don't care about them. Open
def self.cleanup(*args)
- Read upRead up
- Exclude checks
This cop checks for unused method arguments.
Example:
# bad
def some_method(used, unused, _unused_but_allowed)
puts used
end
Example:
# good
def some_method(used, _unused, _unused_but_allowed)
puts used
end
Use =~
in places where the MatchData
returned by #match
will not be used. Open
if l.match(/\[(.+?)\]/)
- Read upRead up
- 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'
end
at 311, 16 is not aligned with if
at 309, 32. Open
end
- Read upRead up
- Exclude checks
This cop checks whether the end keywords are aligned properly.
Three modes are supported through the EnforcedStyleAlignWith
configuration parameter:
If it's set to keyword
(which is the default), the end
shall be aligned with the start of the keyword (if, class, etc.).
If it's set to variable
the end
shall be aligned with the
left-hand-side of the variable assignment, if there is one.
If it's set to start_of_line
, the end
shall be aligned with the
start of the line where the matching keyword appears.
Example: EnforcedStyleAlignWith: keyword (default)
# bad
variable = if true
end
# good
variable = if true
end
Example: EnforcedStyleAlignWith: variable
# bad
variable = if true
end
# good
variable = if true
end
Example: EnforcedStyleAlignWith: startofline
# bad
variable = if true
end
# good
puts(if true
end)
Redundant use of Object#to_s
in interpolation. Open
MU.log "saveDeployData invoked on #{@server.to_s} before Chef has been bootstrapped!", MU::WARN, details: caller
- Read upRead up
- Exclude checks
This cop checks for string conversion in string interpolation, which is redundant.
Example:
# bad
"result is #{something.to_s}"
Example:
# good
"result is #{something}"
Use =~
in places where the MatchData
returned by #match
will not be used. Open
raise MU::Cloud::BootstrapTempFail if data.match(/REBOOT_SCHEDULED| WARN: Reboot requested:|Rebooting server at a recipe's request|Chef::Exceptions::Reboot/)
- Read upRead up
- 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 more than 4 levels of block nesting. Open
if File.exist?(example_path)
example = "#\n# Examples:\n#\n"
# XXX these variables are all parameters from the BoKs in
# modules/tests. A really clever implementation would read
# and parse them to get default values, perhaps, instead of
- Read upRead up
- Exclude checks
This cop checks for excessive nesting of conditional and looping constructs.
You can configure if blocks are considered using the CountBlocks
option. When set to false
(the default) blocks are not counted
towards the nesting level. Set to true
to count blocks as well.
The maximum level of nesting allowed is configurable.
Use each_value
instead of values.each
. Open
MU::Cloud.resource_types.values.each { |attrs|
- Read upRead up
- Exclude checks
This cop checks for uses of each_key
and each_value
Hash methods.
Note: If you have an array of two-element arrays, you can put parentheses around the block arguments to indicate that you're not working with a hash, and suppress RuboCop offenses.
Example:
# bad
hash.keys.each { |k| p k }
hash.values.each { |v| p v }
hash.each { |k, _v| p k }
hash.each { |_k, v| p v }
# good
hash.each_key { |k| p k }
hash.each_value { |v| p v }
unexpected token tCOMMA
(Using Ruby 2.1 parser; configure using TargetRubyVersion
parameter, under AllCops
) Open
},
- Exclude checks
unexpected token tCOMMA
(Using Ruby 2.1 parser; configure using TargetRubyVersion
parameter, under AllCops
) Open
},
- Exclude checks
unexpected token tRCURLY
(Using Ruby 2.1 parser; configure using TargetRubyVersion
parameter, under AllCops
) Open
}
- Exclude checks
end
at 258, 8 is not aligned with if
at 242, 19. Open
end
- Read upRead up
- Exclude checks
This cop checks whether the end keywords are aligned properly.
Three modes are supported through the EnforcedStyleAlignWith
configuration parameter:
If it's set to keyword
(which is the default), the end
shall be aligned with the start of the keyword (if, class, etc.).
If it's set to variable
the end
shall be aligned with the
left-hand-side of the variable assignment, if there is one.
If it's set to start_of_line
, the end
shall be aligned with the
start of the line where the matching keyword appears.
Example: EnforcedStyleAlignWith: keyword (default)
# bad
variable = if true
end
# good
variable = if true
end
Example: EnforcedStyleAlignWith: variable
# bad
variable = if true
end
# good
variable = if true
end
Example: EnforcedStyleAlignWith: startofline
# bad
variable = if true
end
# good
puts(if true
end)
Use each_key
instead of keys.each
. Open
canon_links.keys.each { |longrole|
- Read upRead up
- Exclude checks
This cop checks for uses of each_key
and each_value
Hash methods.
Note: If you have an array of two-element arrays, you can put parentheses around the block arguments to indicate that you're not working with a hash, and suppress RuboCop offenses.
Example:
# bad
hash.keys.each { |k| p k }
hash.values.each { |v| p v }
hash.each { |k, _v| p k }
hash.each { |_k, v| p v }
# good
hash.each_key { |k| p k }
hash.each_value { |v| p v }
Do not suppress exceptions. Open
rescue Net::HTTPServerException
- Read upRead up
- Exclude checks
This cop checks for rescue blocks with no body.
Example:
# bad
def some_method
do_something
rescue
# do nothing
end
Example:
# bad
begin
do_something
rescue
# do nothing
end
Example:
# good
def some_method
do_something
rescue
handle_exception
end
Example:
# good
begin
do_something
rescue
handle_exception
end
Do not suppress exceptions. Open
rescue LoadError
- Read upRead up
- Exclude checks
This cop checks for rescue blocks with no body.
Example:
# bad
def some_method
do_something
rescue
# do nothing
end
Example:
# bad
begin
do_something
rescue
# do nothing
end
Example:
# good
def some_method
do_something
rescue
handle_exception
end
Example:
# good
begin
do_something
rescue
handle_exception
end