lib/cc/config/checks_adapter.rb
Add empty line after guard clause. Open
Open
return unless checks.present?
- Read upRead up
- Exclude checks
Enforces empty line after guard clause
Example:
# bad
def foo
return if need_return?
bar
end
# good
def foo
return if need_return?
bar
end
# good
def foo
return if something?
return if something_different?
bar
end
# also good
def foo
if something?
do_something
return if need_return?
end
end
Convert if-elsif
to case-when
. Open
Open
if engine["config"].is_a?(String)
engine["config"] = {
"file" => engine["config"],
"checks" => checks,
}
- Read upRead up
- Exclude checks
Identifies places where if-elsif
constructions
can be replaced with case-when
.
Safety:
This cop is unsafe. case
statements use ===
for equality,
so if the original conditional used a different equality operator, the
behavior may be different.
Example:
# bad
if status == :active
perform_action
elsif status == :inactive || status == :hibernating
check_timeout
else
final_action
end
# good
case status
when :active
perform_action
when :inactive, :hibernating
check_timeout
else
final_action
end
Use each_key
instead of keys.each
. Open
Open
DefaultAdapter::ENGINES.keys.each do |name|
- Read upRead up
- Exclude checks
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.
Safety:
This cop is unsafe because it cannot be guaranteed that the receiver
is a Hash
. The AllowedReceivers
configuration can mitigate,
but not fully resolve, this safety issue.
Example:
# bad
hash.keys.each { |k| p k }
hash.values.each { |v| p v }
# good
hash.each_key { |k| p k }
hash.each_value { |v| p v }
Example: AllowedReceivers: ['execute']
# good
execute(sql).keys.each { |v| p v }
execute(sql).values.each { |v| p v }