Showing 14 of 1,009 total issues
Use tr
instead of gsub
. Open
definition = model.gsub(" ", "_").classify.constantize.
- Read upRead up
- Exclude checks
This cop identifies places where gsub
can be replaced by
tr
or delete
.
Example:
# bad
'abc'.gsub('b', 'd')
'abc'.gsub('a', '')
'abc'.gsub(/a/, 'd')
'abc'.gsub!('a', 'd')
# good
'abc'.gsub(/.*/, 'a')
'abc'.gsub(/a+/, 'd')
'abc'.tr('b', 'd')
'a b c'.delete(' ')
Use write_options[:storage_class] = storage_class
instead of write_options.merge!(:storage_class => storage_class)
. Open
write_options.merge!(:storage_class => storage_class) if storage_class
- Read upRead up
- Exclude checks
This cop identifies places where Hash#merge!
can be replaced by
Hash#[]=
.
Example:
hash.merge!(a: 1)
hash.merge!({'key' => 'value'})
hash.merge!(a: 1, b: 2)
Use =~
in places where the MatchData
returned by #match
will not be used. Open
delimiter_char = url.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'
Use =~
in places where the MatchData
returned by #match
will not be used. Open
unless @options[:url].to_s.match(/\A:fog.*url\z/)
- 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'
Use each_key
instead of keys.each
. Open
COLUMNS.keys.each do |column_name|
- 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 }
Use each_value
instead of each
. Open
@errors.each do |error, message|
- 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 }
HACK found Open
- HACK
- Exclude checks
TODO found Open
- TODO
- Exclude checks
TODO found Open
s.add_development_dependency('cucumber-expressions', '4.0.3') # TODO: investigate failures on 4.0.4
- Exclude checks
HACK found Open
Description: Checks formatting of special comments (TODO, FIXME, OPTIMIZE, HACK,
- Exclude checks
FIXME found Open
Description: Checks formatting of special comments (TODO, FIXME, OPTIMIZE, HACK,
- Exclude checks
TODO found Open
Description: Checks formatting of special comments (TODO, FIXME, OPTIMIZE, HACK,
- Exclude checks
FIXME found Open
- FIXME
- Exclude checks
TODO found Open
# TODO: is it even possible to take into account Procs?
- Exclude checks