You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Style/CombinableLoops cop assumes that any method that ends with _each is an iterator, and then applies the cop logic to the method body. This rule triggers on the rails validates_each method, described here, which is not actually an iterator.
The below code will trigger the cop:
classExample < ActiveRecord::Base# Has two attributes :array_values, :other_array_values, both of which are arrays of stringsvalidates_each:array_values,:other_array_valuesdo |record,attribute,array_value|
array_value.eachdo |array_value_item|
record.errors.add(attribute,"invalid")unlessis_valid_item?(array_value_item)endenddefis_valid_item?(item)returnitem !=="invalid"endend
Expected behavior
The Style/CombinableLoops should not necessarily trigger on methods with names that happen to end with _each, since that suffix doesn't necessarily imply that it's an iterator.
Actual behavior
The above code is not actually a combinable loop, because the validates_each is not really an iterator, but simply a method that can apply some validation logic to a value which may in turn be an enumerable. As such it should not trigger this cop.
Steps to reproduce the problem
See example above in the issue description above. There is no way to combine validates_each and the iteration over the array_value array.
The
Style/CombinableLoops
cop assumes that any method that ends with_each
is an iterator, and then applies the cop logic to the method body. This rule triggers on the railsvalidates_each
method, described here, which is not actually an iterator.The below code will trigger the cop:
Expected behavior
The
Style/CombinableLoops
should not necessarily trigger on methods with names that happen to end with_each
, since that suffix doesn't necessarily imply that it's an iterator.Actual behavior
The above code is not actually a combinable loop, because the
validates_each
is not really an iterator, but simply a method that can apply some validation logic to a value which may in turn be an enumerable. As such it should not trigger this cop.Steps to reproduce the problem
See example above in the issue description above. There is no way to combine
validates_each
and the iteration over thearray_value
array.RuboCop version
The text was updated successfully, but these errors were encountered: