Skip to content

Commit

Permalink
Merge pull request #373 from tagliala/bugfix/fix-target-ruby-version-…
Browse files Browse the repository at this point in the history
…of-unfreeze-string

Set target version for `Performance/UnfreezeString`
  • Loading branch information
koic authored Sep 16, 2023
2 parents 0781feb + e6e20e3 commit 1b8df40
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/fix_target_version_for_unfreeze_string_cop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#373](https://github.com/rubocop/rubocop-performance/pull/373): Set target version for `Performance/UnfreezeString`. ([@tagliala][])
3 changes: 3 additions & 0 deletions lib/rubocop/cop/performance/unfreeze_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ module Performance
# +''
class UnfreezeString < Base
extend AutoCorrector
extend TargetRubyVersion

minimum_target_ruby_version 2.3

MSG = 'Use unary plus to get an unfrozen string literal.'
RESTRICT_ON_SEND = %i[dup new].freeze
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/performance/unfreeze_string_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,12 @@
String.new(capacity: 100)
RUBY
end

context 'when Ruby <= 2.2', :ruby22 do
it 'does not register an offense for an empty string with `.dup`' do
expect_no_offenses(<<~RUBY)
"".dup
RUBY
end
end
end

0 comments on commit 1b8df40

Please sign in to comment.