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
Address frozen_string_literal
no longer applying to interpolated strings in Ruby 3.0 or higher
#10006
Address frozen_string_literal
no longer applying to interpolated strings in Ruby 3.0 or higher
#10006
Conversation
4a94653
to
0bf81bb
Compare
@sambostock As the original author of #8743 do you mind reviewing these changes? 🙏 |
The changes look good to me, but I think that this difference in behaviour should be mentioned in the docs for the two cops. I'm pretty sure most people don't know that there's a difference on Ruby 2.7 and 3.0. (I didn't know this myself) |
@bbatsov Good point about the docs, thanks 🙇 I'll add them and ping you again for another round of review 🙏 |
You'll also have to rebase on top of |
Use this helper method instead repeating the logic everywhere to ease future changes.
4287edd
to
3dd5ae9
Compare
@@ -21,6 +21,9 @@ module Style | |||
# | |||
# NOTE: Regexp and Range literals are frozen objects since Ruby 3.0. | |||
# | |||
# NOTE: From Ruby 3.0, this cop allows explicit freezing of interpolated |
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.
Initially, I wanted to link https://rubyreferences.github.io/rubychanges/3.0.html#interpolated-string-literals-are-no-longer-frozen-when--frozen-string-literal-true-is-used but it seems we are not linking to external resources in inline docs very often.
@bbatsov Thanks for the heads-up about the rebase. Done ✔️ I've added added a note to Do you mind reviewing this PR again? 🙏 |
Since Ruby 3.0 or higher interpolated strings are not frozen automatically anymore. Therefore, two changes must happen to how we treat interpolated literals * Style/MutableConstant should enforce freezing them * Style/RedundantFreeze should not consider it redundant to freeze them Strongly inspired by rubocop#8743
3dd5ae9
to
c537fc2
Compare
@@ -21,6 +21,9 @@ module Style | |||
# | |||
# NOTE: Regexp and Range literals are frozen objects since Ruby 3.0. |
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.
It seems we are using different style to highlight notes. I went with NOTE:
but would be happy to use "From Ruby 3.0, ..." pattern as seen above.
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.
NOTE:
is better.
Looks good. Thanks! |
Note, this PR is strongly inspired by #8743. Kudos to @sambostock ❤️
Since Ruby 3.0 or higher interpolated strings are not frozen automatically anymore.
Therefore, two changes must happen to how we treat interpolated literals
Style/MutableConstant
should enforce freezing themStyle/RedundantFreeze
should not consider it redundant to freeze themThe behaviour for Ruby 2.7 or lower is kept.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.