File tree Expand file tree Collapse file tree 3 files changed +28
-4
lines changed Expand file tree Collapse file tree 3 files changed +28
-4
lines changed Original file line number Diff line number Diff line change
1
+ * [ #337 ] ( https://github.com/rubocop/rubocop-ast/pull/337 ) : Deprecate ` EnsureNode#body ` in favour of ` EnsureNode#branch ` . ` EnsureNode#body ` will be redefined in the next major version of rubocop-ast. ([ @dvandersluis ] [ ] )
Original file line number Diff line number Diff line change @@ -6,10 +6,31 @@ module AST
6
6
# node when the builder constructs the AST, making its methods available
7
7
# to all `ensure` nodes within RuboCop.
8
8
class EnsureNode < Node
9
+ DEPRECATION_WARNING_LOCATION_CACHE = [ ] # rubocop:disable Style/MutableConstant
10
+ private_constant :DEPRECATION_WARNING_LOCATION_CACHE
11
+
9
12
# Returns the body of the `ensure` clause.
10
13
#
11
14
# @return [Node, nil] The body of the `ensure`.
15
+ # @deprecated Use `EnsureNode#branch`
12
16
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
+
27
+ branch
28
+ end
29
+
30
+ # Returns an the ensure branch in the exception handling statement.
31
+ #
32
+ # @return [Node, nil] the body of the ensure branch.
33
+ def branch
13
34
node_parts [ 1 ]
14
35
end
15
36
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
RSpec . describe RuboCop ::AST ::EnsureNode do
4
- let ( :ensure_node ) { parse_source ( source ) . ast . children . first }
4
+ let ( :parsed_source ) { parse_source ( source ) }
5
+ let ( :ensure_node ) { parsed_source . ast . children . first }
6
+ let ( :node ) { parsed_source . node }
5
7
6
8
describe '.new' do
7
9
let ( :source ) { 'begin; beginbody; ensure; ensurebody; end' }
8
10
9
11
it { expect ( ensure_node ) . to be_a ( described_class ) }
10
12
end
11
13
12
- describe '#body ' do
13
- let ( :source ) { 'begin; beginbody; ensure; : ensurebody; end' }
14
+ describe '#branch ' do
15
+ let ( :source ) { 'begin; beginbody; ensure; >> ensurebody<< ; end' }
14
16
15
- it { expect ( ensure_node . body ) . to be_sym_type }
17
+ it { expect ( ensure_node . branch ) . to eq ( node ) }
16
18
end
17
19
18
20
describe '#rescue_node' do
You can’t perform that action at this time.
0 commit comments