Skip to content
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

Fix a false positive for Style/RedundantFetchBlock when using with Rails.cache #8210

Merged

Conversation

fatkodima
Copy link
Contributor

Closes #8196

def should_not_check?(send, body)
(body&.const_type? && !check_for_constant?) ||
(body&.str_type? && !check_for_string?) ||
rails_cache?(send.receiver)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was late for the discussion of #8196.

I agree with the following @bbatsov's opinion.

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 Rails.cache. //cc @fatkodima

Ideally RuboCop core should be Rails unaware because RuboCop core focuses on Ruby. It is better to create IgnoredReceivers option and configure it with RuboCop Rails (or users).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we all agree as to what is the best. I see this PR as a temporary improvement, before a IgnoredReceivers option.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I get it! I'll merge this PR.

@koic koic merged commit 8e365cf into rubocop:master Jun 26, 2020
@koic
Copy link
Member

koic commented Jun 26, 2020

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positive for Style/RedundantFetchBlock cop with Rails.cache.fetch
3 participants