Skip to content

Commit 1b8df40

Browse files
authored
Merge pull request #373 from tagliala/bugfix/fix-target-ruby-version-of-unfreeze-string
Set target version for `Performance/UnfreezeString`
2 parents 0781feb + e6e20e3 commit 1b8df40

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#373](https://github.com/rubocop/rubocop-performance/pull/373): Set target version for `Performance/UnfreezeString`. ([@tagliala][])

lib/rubocop/cop/performance/unfreeze_string.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ module Performance
2626
# +''
2727
class UnfreezeString < Base
2828
extend AutoCorrector
29+
extend TargetRubyVersion
30+
31+
minimum_target_ruby_version 2.3
2932

3033
MSG = 'Use unary plus to get an unfrozen string literal.'
3134
RESTRICT_ON_SEND = %i[dup new].freeze

spec/rubocop/cop/performance/unfreeze_string_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,12 @@
112112
String.new(capacity: 100)
113113
RUBY
114114
end
115+
116+
context 'when Ruby <= 2.2', :ruby22 do
117+
it 'does not register an offense for an empty string with `.dup`' do
118+
expect_no_offenses(<<~RUBY)
119+
"".dup
120+
RUBY
121+
end
122+
end
115123
end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy