rubocop-ast 1.34.0 → 1.35.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: 6aeec8c30cc0c6867ba22dcc54d1f6fbbf400465930563d3e777cadef39bd7a9
4
- data.tar.gz: 84512971edea6c49a505879088031a866d52dfd4450005a8864240523d8205af
3
+ metadata.gz: 561b04e1f93f2547b0aacb052524a3a3ef33374393da44b52c5252e9188a8617
4
+ data.tar.gz: 82061fc362d4ab8f9f8342ab5732cc6e435504467ed8f27f5b8b22a6443e23b9
5
5
  SHA512:
6
- metadata.gz: 7a0f34ce3cdcb2161ba584a24766f8d180b62643a41e9efd3711b248abe579860315950516013b5e579294776832b3e174299da5a0305eeb0baaeab234d61ef5
7
- data.tar.gz: 9c4664492b5fd8184633ff13f91b9ab8ffb2b90f31176a15c7455979e38484442243367074a3ada5393f59ff132652a57ffdefe91dc8dd0633c02c5e8dcb6c52
6
+ metadata.gz: 131019a04a091fc37a343a0c5f2481cba184b54883366e3362f98323dd7d2fe2f640ae7ee0bcad5c204fe17932d6116714df5e2a3123f8f1ee3f9b9890f866ba
7
+ data.tar.gz: c4c17c1178ee04b0e9ca05b442eadf121a2a1755be779e9ad508762ce7878c47249dca964028aebae71feda02e0fb8dd471e1fb3299b2f858506220ab14c418e
@@ -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,
@@ -13,6 +13,13 @@ module RuboCop
13
13
  node_parts[1]
14
14
  end
15
15
 
16
+ # Returns the `rescue` node of the `ensure`, if present.
17
+ #
18
+ # @return [Node, nil] The `rescue` node.
19
+ def rescue_node
20
+ node_parts[0] if node_parts[0].rescue_type?
21
+ end
22
+
16
23
  # Checks whether this node body is a void context.
17
24
  # Always `true` for `ensure`.
18
25
  #
@@ -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
@@ -16,7 +16,7 @@ module RuboCop
16
16
  #
17
17
  # @return [Symbol] the name of the variable being assigned
18
18
  def name
19
- assignment_node.name
19
+ assignment_node.call_type? ? assignment_node.method_name : assignment_node.name
20
20
  end
21
21
 
22
22
  # The operator being used for assignment as a symbol.
@@ -88,6 +88,34 @@ module RuboCop
88
88
  EMPTY_PROPERTIES = {}.freeze
89
89
  private_constant :EMPTY_CHILDREN, :EMPTY_PROPERTIES
90
90
 
91
+ # @api private
92
+ GROUP_FOR_TYPE = {
93
+ arg: :argument,
94
+ optarg: :argument,
95
+ restarg: :argument,
96
+ kwarg: :argument,
97
+ kwoptarg: :argument,
98
+ kwrestarg: :argument,
99
+ blockarg: :argument,
100
+ forward_arg: :argument,
101
+ shardowarg: :argument,
102
+
103
+ true: :boolean,
104
+ false: :boolean,
105
+
106
+ int: :numeric,
107
+ float: :numeric,
108
+ rational: :numeric,
109
+ complex: :numeric,
110
+
111
+ irange: :range,
112
+ erange: :range,
113
+
114
+ send: :call,
115
+ csend: :call
116
+ }.freeze
117
+ private_constant :GROUP_FOR_TYPE
118
+
91
119
  # Define a +recursive_?+ predicate method for the given node kind.
92
120
  private_class_method def self.def_recursive_literal_predicate(kind) # rubocop:disable Metrics/MethodLength
93
121
  recursive_kind = "recursive_#{kind}?"
@@ -126,6 +154,16 @@ module RuboCop
126
154
  end
127
155
  end
128
156
 
157
+ # Determine if the node is one of several node types in a single query
158
+ # Allows specific single node types, as well as "grouped" types
159
+ # (e.g. `:boolean` for `:true` or `:false`)
160
+ def type?(*types)
161
+ return true if types.include?(type)
162
+
163
+ group_type = GROUP_FOR_TYPE[type]
164
+ !group_type.nil? && types.include?(group_type)
165
+ end
166
+
129
167
  (Parser::Meta::NODE_TYPES - [:send]).each do |node_type|
130
168
  method_name = "#{node_type.to_s.gsub(/\W/, '')}_type?"
131
169
  class_eval <<~RUBY, __FILE__, __LINE__ + 1
@@ -312,13 +350,12 @@ module RuboCop
312
350
  def_node_matcher :str_content, '(str $_)'
313
351
 
314
352
  def const_name
315
- return unless const_type?
353
+ return unless const_type? || casgn_type?
316
354
 
317
- namespace, name = *self
318
355
  if namespace && !namespace.cbase_type?
319
- "#{namespace.const_name}::#{name}"
356
+ "#{namespace.const_name}::#{short_name}"
320
357
  else
321
- name.to_s
358
+ short_name.to_s
322
359
  end
323
360
  end
324
361
 
@@ -464,7 +501,7 @@ module RuboCop
464
501
  end
465
502
 
466
503
  def call_type?
467
- send_type? || csend_type?
504
+ GROUP_FOR_TYPE[type] == :call
468
505
  end
469
506
 
470
507
  def chained?
@@ -476,19 +513,19 @@ module RuboCop
476
513
  end
477
514
 
478
515
  def argument_type?
479
- ARGUMENT_TYPES.include?(type)
516
+ GROUP_FOR_TYPE[type] == :argument
480
517
  end
481
518
 
482
519
  def boolean_type?
483
- true_type? || false_type?
520
+ GROUP_FOR_TYPE[type] == :boolean
484
521
  end
485
522
 
486
523
  def numeric_type?
487
- int_type? || float_type? || rational_type? || complex_type?
524
+ GROUP_FOR_TYPE[type] == :numeric
488
525
  end
489
526
 
490
527
  def range_type?
491
- irange_type? || erange_type?
528
+ GROUP_FOR_TYPE[type] == :range
492
529
  end
493
530
 
494
531
  def guard_clause?
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module AST
5
5
  module Version
6
- STRING = '1.34.0'
6
+ STRING = '1.35.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.0
4
+ version: 1.35.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-04 00:00:00.000000000 Z
13
+ date: 2024-11-11 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