New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False positive of UnmodifiedReduceAccumulator for self
#9059
Comments
Interesting false positive; there are others too, which is why the cop is "Safe: false". I don't know if it's worth addressing it. FWIW, I think your implementation is not completely correct:
# Custom class with `#[]` method
def dig(key, *other_keys)
result = self[key]
result = result&.dig(*other_keys) unless other_keys.empty?
result
end |
No: for untranslated string (nonexistent keys) there are instances of
Yes, Your code seems more complex. |
You meant "Yes, but they are never
👍 @dvandersluis how do you feel about detecting this use case? |
So the idea as @marcandre mentioned was that we can't cover all cases, and it was decided in #8949 to flag index returns. However, I can add an exception if the method argument is |
I don't think the argument matters, only the form of the block. If the block is %i[a b c].inject({a: {b: {c: 42}}}) { |result, key| result[key] } # => 42 That corresponds to the non-block form too, @AlexWayfer you may want to simplify it: def dig(*keys)
keys.reduce(self, :[])
end |
Oh yeah, good call @marcandre I'll fix that up. |
Thank you, didn't know about this. |
* Remake `i18n` and `now` format arguments to keyword arguments. * Use simpler approach for `reduce`. rubocop/rubocop#9059 (comment)
* Remake `i18n` and `now` format arguments to keyword arguments. * Use simpler approach for `reduce`. rubocop/rubocop#9059 (comment)
I'm working on R18n gem and I've got a new offense from RuboCop.
Expected behavior
No offenses.
Actual behavior
The offense:
Steps to reproduce the problem
RuboCop version
The text was updated successfully, but these errors were encountered: