rubocop-ast 1.34.1 → 1.36.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e18e1861fce6c7270825ae9878eb90e0e7fff0ade7e152dbb1930420ea443f6e
4
- data.tar.gz: d5c24a9c7ff60efed99bd0f30d0debdb828b6ab7833dfc267d9743a9fd110a38
3
+ metadata.gz: 9b32a3c0d2ed76918be1a82a02a7dec4d35d13aab699f3121a62223161746896
4
+ data.tar.gz: e55118604732fd8e5ff36c169b6a5d350597c364e964ca7f7fdb5aa1b10c1a64
5
5
  SHA512:
6
- metadata.gz: ee36477fed091f324d3259d528e0dbbec67267364cbd201e551d04f62d982058def295a487d27a549f02729327097bf0d6241d22642c20c8f199aa3ce3eb0541
7
- data.tar.gz: 2961fdad4fb442fc09eb7ec0ad234331ddff49e28851444d8befc18b2e7c4e8aa41f9c534461445aed856a6eebf16aa692d6f7d2c2d498fee27b48e1fbe9e121
6
+ metadata.gz: d4e174878308a303c32a4f73b0bffe77cfaae1940970bc6df204e9d2666b3559de38a19c038052185af66e1572aebaa2f751bb7dc01475de12e9c6545b673933
7
+ data.tar.gz: 328d37ec24c74ef4d302bb1b4a6963739053244b6eba88e4e5bd4979231b092d59a165e5cb3d38530e70b486dd3c894d0554e3a8baa2d393b6489964516c87f5
@@ -63,6 +63,7 @@ module RuboCop
63
63
  irange: RangeNode,
64
64
  erange: RangeNode,
65
65
  kwargs: HashNode,
66
+ kwbegin: KeywordBeginNode,
66
67
  kwsplat: KeywordSplatNode,
67
68
  lambda: LambdaNode,
68
69
  masgn: MasgnNode,
@@ -6,13 +6,41 @@ module RuboCop
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
 
37
+ # Returns the `rescue` node of the `ensure`, if present.
38
+ #
39
+ # @return [Node, nil] The `rescue` node.
40
+ def rescue_node
41
+ node_parts[0] if node_parts[0].rescue_type?
42
+ end
43
+
16
44
  # Checks whether this node body is a void context.
17
45
  # Always `true` for `ensure`.
18
46
  #
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module AST
5
+ # A node extension for `kwbegin` nodes. This will be used in place of a plain
6
+ # node when the builder constructs the AST, making its methods available
7
+ # to all `kwbegin` nodes within RuboCop.
8
+ class KeywordBeginNode < Node
9
+ # Returns the body of the `kwbegin` block. Returns `self` if the `kwbegin` contains
10
+ # multiple nodes.
11
+ #
12
+ # @return [Node, nil] The body of the `kwbegin`.
13
+ def body
14
+ return unless node_parts.any?
15
+
16
+ if rescue_node
17
+ rescue_node.body
18
+ elsif ensure_node
19
+ ensure_node.node_parts[0]
20
+ elsif node_parts.one?
21
+ node_parts[0]
22
+ else
23
+ self
24
+ end
25
+ end
26
+
27
+ # Returns the `rescue` node of the `kwbegin` block, if one is present.
28
+ #
29
+ # @return [Node, nil] The `rescue` node within `kwbegin`.
30
+ def ensure_node
31
+ node_parts[0] if node_parts[0]&.ensure_type?
32
+ end
33
+
34
+ # Returns the `rescue` node of the `kwbegin` block, if one is present.
35
+ #
36
+ # @return [Node, nil] The `rescue` node within `kwbegin`.
37
+ def rescue_node
38
+ return ensure_node&.rescue_node if ensure_node&.rescue_node
39
+
40
+ node_parts[0] if node_parts[0]&.rescue_type?
41
+ end
42
+ end
43
+ end
44
+ end
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module AST
5
5
  module Version
6
- STRING = '1.34.1'
6
+ STRING = '1.36.0'
7
7
  end
8
8
  end
9
9
  end
data/lib/rubocop/ast.rb CHANGED
@@ -60,6 +60,7 @@ require_relative 'ast/node/in_pattern_node'
60
60
  require_relative 'ast/node/index_node'
61
61
  require_relative 'ast/node/indexasgn_node'
62
62
  require_relative 'ast/node/int_node'
63
+ require_relative 'ast/node/keyword_begin_node'
63
64
  require_relative 'ast/node/keyword_splat_node'
64
65
  require_relative 'ast/node/lambda_node'
65
66
  require_relative 'ast/node/masgn_node'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-ast
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.34.1
4
+ version: 1.36.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-11-07 00:00:00.000000000 Z
13
+ date: 2024-11-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: parser
@@ -69,6 +69,7 @@ files:
69
69
  - lib/rubocop/ast/node/index_node.rb
70
70
  - lib/rubocop/ast/node/indexasgn_node.rb
71
71
  - lib/rubocop/ast/node/int_node.rb
72
+ - lib/rubocop/ast/node/keyword_begin_node.rb
72
73
  - lib/rubocop/ast/node/keyword_splat_node.rb
73
74
  - lib/rubocop/ast/node/lambda_node.rb
74
75
  - lib/rubocop/ast/node/masgn_node.rb