Skip to content

Commit be16c46

Browse files
dvandersluismarcandre
authored andcommitted
Revert "Don't show a deprecation warning for EnsureNode#branch just yet"
This reverts commit 3a7c069.
1 parent dc102aa commit be16c46

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/rubocop/ast/node/ensure_node.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,24 @@ module AST
66
# node when the builder constructs the AST, making its methods available
77
# to all `ensure` nodes within RuboCop.
88
class EnsureNode < Node
9+
DEPRECATION_WARNING_LOCATION_CACHE = [] # rubocop:disable Style/MutableConstant
10+
private_constant :DEPRECATION_WARNING_LOCATION_CACHE
11+
912
# Returns the body of the `ensure` clause.
1013
#
1114
# @return [Node, nil] The body of the `ensure`.
1215
# @deprecated Use `EnsureNode#branch`
1316
def body
17+
first_caller = caller(1..1).first
18+
19+
unless DEPRECATION_WARNING_LOCATION_CACHE.include?(first_caller)
20+
warn '`EnsureNode#body` is deprecated and will be changed in the next major version of ' \
21+
'rubocop-ast. Use `EnsureNode#branch` instead to get the body of the `ensure` branch.'
22+
warn "Called from:\n#{caller.join("\n")}\n\n"
23+
24+
DEPRECATION_WARNING_LOCATION_CACHE << first_caller
25+
end
26+
1427
branch
1528
end
1629

0 commit comments

Comments
 (0)