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 for Style/RedundantFetchBlock
cop with Rails.cache.fetch
#8196
Comments
Fixing this is going to be tricky, due to the dynamic nature of Ruby - we can never be sure about the type of a receiver. The best thing that comes to mind is to have some configuration about allowed receivers or whatever, as I don't want to hardcode some special handling of |
This cop is already marked as Something like |
Yeah, that's true. |
Adding a pair of disable/enable comments is what I ended up doing before submitting this issue. It was good enough in my case since I didn't have a lot of |
A very personal opinion, but custom objects defining This cop should be aware of
If we provide a setting, perfect, otherwise I'd hardcode |
From 3 suggested options, I would also prefer hardcoding I would implement any approach, just let me know. |
Maybe we can start with hardcoding |
I work in a Rails project in which we have a few instances of
The
Style/RedundantFetchBlock
cop shouldn't trigger in this case sinceisn't the same. It's documented here. Anything following the first parameter is considered to be an option. The value for a cache miss has to be passed as a block.
Expected behavior
I expect RuboCop to not register offenses for
Rails.cache.fetch
as explained above.Actual behavior
An offense for the
Style/RedundantFetchBlock
cop is registered. This is a false positive.Steps to reproduce the problem
With
Rails.cache.fetch('something') { "value_for_cache_miss" }
RuboCop version
The text was updated successfully, but these errors were encountered: