diff --git a/changelog/fix_redundant_freeze_env_values.md b/changelog/fix_redundant_freeze_env_values.md new file mode 100644 index 00000000000..a95cb592736 --- /dev/null +++ b/changelog/fix_redundant_freeze_env_values.md @@ -0,0 +1 @@ +* [#10099](https://github.com/rubocop/rubocop/pull/10099): Update`Style/RedundantFreeze` to stop considering `ENV` values as immutable. ([@byroot][]) diff --git a/lib/rubocop/cop/style/redundant_freeze.rb b/lib/rubocop/cop/style/redundant_freeze.rb index a8df5517436..f1f21006f99 100644 --- a/lib/rubocop/cop/style/redundant_freeze.rb +++ b/lib/rubocop/cop/style/redundant_freeze.rb @@ -59,7 +59,6 @@ def strip_parenthesis(node) (begin (send {float int} {:+ :- :* :** :/ :% :<<} _)) (begin (send !{(str _) array} {:+ :- :* :** :/ :%} {float int})) (begin (send _ {:== :=== :!= :<= :>= :< :>} _)) - (send (const {nil? cbase} :ENV) :[] _) (send _ {:count :length :size} ...) (block (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 70821af3df2..2ffc476a07f 100644 --- a/spec/rubocop/cop/style/redundant_freeze_spec.rb +++ b/spec/rubocop/cop/style/redundant_freeze_spec.rb @@ -20,8 +20,6 @@ it_behaves_like 'immutable objects', '1.5' it_behaves_like 'immutable objects', ':sym' it_behaves_like 'immutable objects', ':""' - it_behaves_like 'immutable objects', "ENV['foo']" - it_behaves_like 'immutable objects', "::ENV['foo']" it_behaves_like 'immutable objects', "'foo'.count" it_behaves_like 'immutable objects', '(1 + 2)' it_behaves_like 'immutable objects', '(2 > 1)' @@ -44,6 +42,8 @@ it_behaves_like 'mutable objects', "('a' * 20)" it_behaves_like 'mutable objects', '(a + b)' it_behaves_like 'mutable objects', '([42] * 42)' + it_behaves_like 'mutable objects', "ENV['foo']" + it_behaves_like 'mutable objects', "::ENV['foo']" it 'allows .freeze on method call' do expect_no_offenses('TOP_TEST = Something.new.freeze')