rubocop / rubocop

A Ruby static code analyzer and formatter, based on the community Ruby style guide.
https://docs.rubocop.org
MIT License
12.63k stars 3.06k forks source link

Ruby 3.4.0preview1 - False positive for Style/FrozenStringLiteralComment cop #12922

Closed MatzFan closed 5 months ago

MatzFan commented 5 months ago

Ruby 3.4.0preview1 was released on May 16 and string literals are (finally) frozen by default. See release notes.

Expected behavior

With Ruby 3.4.0preview1 In a file without the string literal comment I would expect no offense. In a file with the string literal comment I would expect an offense stating that the string literal comment is unnecessary

Note: As deprecation warnings are not emitted by default the cop comment may want to suggest using Warning[:deprecated] = true or enabling the flag with -W:deprecated

Actual behavior

"Style/FrozenStringLiteralComment: Missing frozen string literal comment" cop is triggered

Steps to reproduce the problem

With Ruby 3.4.0preview1:

$ touch file.rb
$ echo "str = 'foo'" > file.rb
$ echo "puts str.frozen?" >> file.rb
$ ruby file.rb
> true
$ rubocop file.rb # triggers cop

RuboCop version

$ bundle exec rubocop -V
1.63.5 (using Parser 3.3.1.0, rubocop-ast 1.31.3, running on ruby 3.4.0) [x86_64-linux]
  - rubocop-capybara 2.20.0
  - rubocop-minitest 0.35.0
  - rubocop-performance 1.21.0
  - rubocop-rake 0.6.0
  - rubocop-sequel 0.3.4
Earlopain commented 5 months ago

I don't believe its time for this quite yet. While I'd love to finally get rid of these comments there are subtle differences during the migration time until Ruby 4.0:

It seems better for interested users to manually set EnforcedStyle: never until they are truly frozen.

koic commented 5 months ago

The behavior is still unstable with the introduction of the new concept of "chilled string". It might be better to wait until the specification stabilize.

MatzFan commented 5 months ago

I shall chill along with my strings :-)

koic commented 4 months ago

FYI, The following is an article worth reading to understand the current state of frozen string literal. https://gist.github.com/fxn/bf4eed2505c76f4fca03ab48c43adc72#can-i-delete-the-magic-comments-in-ruby-34