diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b4b2056622..43f072960c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Bug fixes * [#6995](https://github.com/rubocop-hq/rubocop/pull/6995): Fix an incorrect auto-correct for `Style/RedundantParentheses` when enclosed in parentheses at `while-post` or `until-post`. ([@koic][]) +* [#6996](https://github.com/rubocop-hq/rubocop/pull/6996): Fix a false positive for `Style/RedundantFreeze` when freezing the result of `String#*`. ([@bquorning][]) * [#6998](https://github.com/rubocop-hq/rubocop/pull/6998): Fix autocorrect of `Naming/RescuedExceptionsVariableName` to also rename all references to the variable. ([@Darhazer][]) ## 0.68.0 (2019-04-29) diff --git a/lib/rubocop/cop/style/redundant_freeze.rb b/lib/rubocop/cop/style/redundant_freeze.rb index ede6154825d..fb745c788bd 100644 --- a/lib/rubocop/cop/style/redundant_freeze.rb +++ b/lib/rubocop/cop/style/redundant_freeze.rb @@ -54,7 +54,7 @@ def strip_parenthesis(node) def_node_matcher :operation_produces_immutable_object?, <<-PATTERN { (begin (send {float int} {:+ :- :* :** :/ :% :<<} _)) - (begin (send _ {:+ :- :* :** :/ :%} {float int})) + (begin (send !(str _) {:+ :- :* :** :/ :%} {float int})) (begin (send _ {:== :=== :!= :<= :>= :< :>} _)) (send (const nil? :ENV) :[] _) (send _ {:count :length :size} ...) diff --git a/spec/rubocop/cop/style/redundant_freeze_spec.rb b/spec/rubocop/cop/style/redundant_freeze_spec.rb index ef55f1840e4..a8a6a3355f9 100644 --- a/spec/rubocop/cop/style/redundant_freeze_spec.rb +++ b/spec/rubocop/cop/style/redundant_freeze_spec.rb @@ -46,6 +46,7 @@ it_behaves_like 'mutable objects', '(1..5)' it_behaves_like 'mutable objects', '(1...5)' it_behaves_like 'mutable objects', "('a' + 'b')" + it_behaves_like 'mutable objects', "('a' * 20)" it_behaves_like 'mutable objects', '(a + b)' it 'allows .freeze on method call' do