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
Enable Style/RedundantFetchBlock and autocorrect-all #47327
Conversation
@@ -280,7 +280,7 @@ def define_default_attribute(name, value, type, from_user:) | |||
name, | |||
value, | |||
type, | |||
_default_attributes.fetch(name.to_s) { nil }, | |||
_default_attributes.fetch(name.to_s, nil), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If nil
is the default, you can just use []
.
_default_attributes.fetch(name.to_s, nil), | |
_default_attributes[name.to_s], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@natematykiewicz Thank you, but I don't think we should change this yet unless there is a specific rule we can apply that supports it. I'd like to avoid making cosmetic changes without a "failing" case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you closed it because there's not a good way to differentiate Rails.cache
from Hash
. Makes sense. It's still possible this specific line using []
would be a performance change and not a cosmetic one. But you'd need a benchmark to see if it's actually faster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is solving a different problem. Feel free to open a PR with benchmarks 🙏
There's a bunch of related failures that should be fixed too:
Probably this change was too aggressive 🤔 |
Ok, TIL the reason for all of the Active Support failures is because it's calling After looking into this further it looks like this was already discussed on rubocop/rubocop#8196, and a previous attempt was made in #39765. I think because we're required to |
As @natematykiewicz pointed out in #47307 there is a rubocop rule for this.