From 384839234d2374ac4e81aef8cf8e02dc675ec398 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune Date: Tue, 4 Aug 2020 13:27:26 -0400 Subject: [PATCH] Always freeze `#arguments` --- CHANGELOG.md | 1 + lib/rubocop/ast/node/block_node.rb | 2 +- lib/rubocop/ast/node/mixin/parameterized_node.rb | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8ad0a9aa..72ae002bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ ### Changes * [#94](https://github.com/rubocop-hq/rubocop-ast/pull/94): In Ruby 2.4, `Set#===` is harmonized with Ruby 2.5+ to call `include?`. ([@marcandre][]) +* [#91](https://github.com/rubocop-hq/rubocop-ast/pull/91): **(Potentially breaking)** `Node#arguments` always returns a frozen array ([@marcandre][]) ## 0.3.0 (2020-08-01) diff --git a/lib/rubocop/ast/node/block_node.rb b/lib/rubocop/ast/node/block_node.rb index 1af323acd..20b9c3f96 100644 --- a/lib/rubocop/ast/node/block_node.rb +++ b/lib/rubocop/ast/node/block_node.rb @@ -25,7 +25,7 @@ def send_node # @return [Array] def arguments if numblock_type? - [] # Numbered parameters have no block arguments. + [].freeze # Numbered parameters have no block arguments. else node_parts[1] end diff --git a/lib/rubocop/ast/node/mixin/parameterized_node.rb b/lib/rubocop/ast/node/mixin/parameterized_node.rb index 0a08cfa34..e1fe069cc 100644 --- a/lib/rubocop/ast/node/mixin/parameterized_node.rb +++ b/lib/rubocop/ast/node/mixin/parameterized_node.rb @@ -82,9 +82,9 @@ def arguments # and optimizes other calls module RestArguments include ParameterizedNode - # @return [Array] arguments, if any + # @return [Array] arguments, if any def arguments - children[first_argument_index..-1] + children[first_argument_index..-1].freeze end # A shorthand for getting the first argument of the node.