From 4f05ea4574cb967ad846a31312a6b21a8d1353f4 Mon Sep 17 00:00:00 2001 From: Benjamin Quorning <22333+bquorning@users.noreply.github.com> Date: Tue, 30 Apr 2019 00:03:56 +0200 Subject: [PATCH] [Fix #6996] Allow freezing result of `String#*` (#6997) Fix a false positive for `Style/RedundantFreeze` when freezing the result of `String#*`. --- CHANGELOG.md | 1 + lib/rubocop/cop/style/redundant_freeze.rb | 2 +- spec/rubocop/cop/style/redundant_freeze_spec.rb | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) 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