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
Style/MutableConstant false positive for heredoc with frozen_string_literal #10070
Comments
Fixes rubocop#10070. This PR fixes a false positive for `Style/MutableConstant` when using non-interpolated heredoc in Ruby 3.0.
Fixes #10070. This PR fixes a false positive for `Style/MutableConstant` when using non-interpolated heredoc in Ruby 3.0.
Hello, I was working on a related example and I was wondering, this should be frozen after all right? I ran the Rubocop auto correcter and it corrected to this: # frozen_string_literal: true
class MyClass
MY_CONSTANT = <<~LUA.freeze # calling .freeze does not raise Style/MutableConstant offense
lorem ipsum
lorem ipsum
LUA
end Feel free to correct me if I'm wrong as I don't work with frozen HEREDOCs too much. :) RuboCop version
|
Your heredoc would be frozen, and that test.rb:5:17: C: [Correctable] Style/RedundantFreeze: Do not freeze immutable objects, as freezing them has no effect.
MY_CONSTANT = <<~LUA.freeze # calling .freeze does not raise Style/MutableConstant offense
^^^^^^^^^^^^^ What was the original code that was autocorrected to your example? |
Original code was: class MyClass
MY_CONSTANT = <<~LUA
lorem ipsum
lorem ipsum
LUA
end Actually figured it out -- I think I had some cached version of Rubocop that was running (1.20.0). Sorry for the noise, and thanks for the explanation! |
Glad you figured it out @Zhao-Andy! |
Rubocop asks to freeze constant string(written with multiline heredoc style) when
# frozen_string_literal: true
Expected behavior
No error occures
Actual behavior
[Correctable] Style/MutableConstant: Freeze mutable objects assigned to constants
Steps to reproduce the problem
RuboCop version
The text was updated successfully, but these errors were encountered: