lib/newgistics/xml_marshaller.rb
Use each_value
instead of values.each
. Open
Open
root.attributes.values.each do |attribute|
- 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 }
Line is too long. [84/80] Open
Open
object[attribute] = build_list(attribute_set.member_type.primitive, element)
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression. Open
Open
if object.is_a?(Hash) || object.respond_to?(setter)
- Read upRead up
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression
Example:
# bad
def test
if something
work
end
end
# good
def test
return unless something
work
end
# also good
def test
work if something
end
# bad
if something
raise 'exception'
else
ok
end
# good
raise 'exception' if something
ok
Use the return of the conditional for variable assignment and comparison. Open
Open
if attribute_set.type.primitive == Array
object[attribute] = build_list(attribute_set.member_type.primitive, element)
else
object[attribute] = build_object(attribute_set.type.primitive, element)
end
- Exclude checks