rubocop-ast 1.38.0 → 1.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a3205a51f90d1dc493ef4c1ec96a4f40ed796dfc58bfc3661db72e67e134abc
4
- data.tar.gz: 6d55fec1f58d712845ecb936db794934ea264e64b0adeb2c097fae63a5e5cb3e
3
+ metadata.gz: 9e4a71ea1a0fa947b90afc9034eeb0c003b875f36ec8802a28228cba2325d094
4
+ data.tar.gz: 871addb4a4e3d427f5c549902f8c927ebe8796856fa5d8828db4e1235550b786
5
5
  SHA512:
6
- metadata.gz: 9468ab39ad7cd4ca56f0781605f07136dc89dfcbafc51482d5045799b468bf389d3c61671f49c7242f3dfbcc99090f3bd4b0c178d08b6038818b0158e3078658
7
- data.tar.gz: a5b2b0604abdd935bfba3213a908678b5697cee7345f5b9941bfdddbfc08ceb8e86cab35895490f2612fd71937baa2ff5b7d75bb2ee4dafb5efd656178dc00c1
6
+ metadata.gz: db53330f9e551fa8d09b60d743297c3c9cbf1ac3df66ced1ead0ecf252b8ddd8f02a0593effd9d0849314f9604b1d0560ff8f6f4b5fdea67fb306e86ba2c7aae
7
+ data.tar.gz: f635affad9b49b2179e8f176a714bb2f38fe49ade7254bfbf8dfcf2797c8939b33d8884a1ba28f77bf7343bb03a80be6f7ab62a79a4ee89b989a52d00434e136
data/README.md CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/rubocop-ast.svg)](https://badge.fury.io/rb/rubocop-ast)
4
4
  [![CI](https://github.com/rubocop/rubocop-ast/actions/workflows/rubocop.yml/badge.svg)](https://github.com/rubocop/rubocop-ast/actions/workflows/rubocop.yml)
5
- [![Test Coverage](https://api.codeclimate.com/v1/badges/a29666e6373bc41bc0a9/test_coverage)](https://codeclimate.com/github/rubocop/rubocop-ast/test_coverage)
6
- [![Maintainability](https://api.codeclimate.com/v1/badges/a29666e6373bc41bc0a9/maintainability)](https://codeclimate.com/github/rubocop/rubocop-ast/maintainability)
7
5
 
8
6
  Contains the classes needed by [RuboCop](https://github.com/rubocop/rubocop) to deal with Ruby's AST, in particular:
9
7
 
@@ -2,20 +2,13 @@
2
2
 
3
3
  module RuboCop
4
4
  module AST
5
- # `RuboCop::AST::Builder` is an AST builder that is utilized to let `Parser`
6
- # generate ASTs with {RuboCop::AST::Node}.
7
- #
8
- # @example
9
- # buffer = Parser::Source::Buffer.new('(string)')
10
- # buffer.source = 'puts :foo'
11
- #
12
- # builder = RuboCop::AST::Builder.new
13
- # require 'parser/ruby25'
14
- # parser = Parser::Ruby25.new(builder)
15
- # root_node = parser.parse(buffer)
16
- class Builder < Parser::Builders::Default
17
- self.emit_forward_arg = true if respond_to?(:emit_forward_arg=)
18
- self.emit_match_pattern = true if respond_to?(:emit_match_pattern=)
5
+ # Common functionality between the parser and prism builder
6
+ # @api private
7
+ module BuilderExtensions
8
+ def self.included(base)
9
+ base.emit_forward_arg = true
10
+ base.emit_match_pattern = true
11
+ end
19
12
 
20
13
  # @api private
21
14
  NODE_MAP = {
@@ -39,11 +32,13 @@ module RuboCop
39
32
  gvasgn: AsgnNode,
40
33
  block: BlockNode,
41
34
  numblock: BlockNode,
35
+ itblock: BlockNode,
42
36
  break: BreakNode,
43
37
  case_match: CaseMatchNode,
44
38
  casgn: CasgnNode,
45
39
  case: CaseNode,
46
40
  class: ClassNode,
41
+ complex: ComplexNode,
47
42
  const: ConstNode,
48
43
  def: DefNode,
49
44
  defined?: DefinedNode,
@@ -107,7 +102,7 @@ module RuboCop
107
102
  node_klass(type).new(type, children, location: source_map)
108
103
  end
109
104
 
110
- # TODO: Figure out what to do about literal encoding handling...
105
+ # Overwrite the base method to allow strings with invalid encoding
111
106
  # More details here https://github.com/whitequark/parser/issues/283
112
107
  def string_value(token)
113
108
  value(token)
@@ -119,5 +114,20 @@ module RuboCop
119
114
  NODE_MAP[type] || Node
120
115
  end
121
116
  end
117
+
118
+ # `RuboCop::AST::Builder` is an AST builder that is utilized to let `Parser`
119
+ # generate ASTs with {RuboCop::AST::Node}.
120
+ #
121
+ # @example
122
+ # buffer = Parser::Source::Buffer.new('(string)')
123
+ # buffer.source = 'puts :foo'
124
+ #
125
+ # builder = RuboCop::AST::Builder.new
126
+ # require 'parser/ruby25'
127
+ # parser = Parser::Ruby25.new(builder)
128
+ # root_node = parser.parse(buffer)
129
+ class Builder < Parser::Builders::Default
130
+ include BuilderExtensions
131
+ end
122
132
  end
123
133
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module AST
5
+ # A parser builder, based on the one provided by prism,
6
+ # which is capable of emitting AST for more recent Rubies.
7
+ class BuilderPrism < Prism::Translation::Parser::Builder
8
+ include BuilderExtensions
9
+ end
10
+ end
11
+ end
@@ -11,6 +11,8 @@ module RuboCop
11
11
  class BlockNode < Node
12
12
  include MethodIdentifierPredicates
13
13
 
14
+ IT_BLOCK_ARGUMENT = [ArgNode.new(:arg, [:it])].freeze
15
+ private_constant :IT_BLOCK_ARGUMENT
14
16
  VOID_CONTEXT_METHODS = %i[each tap].freeze
15
17
  private_constant :VOID_CONTEXT_METHODS
16
18
 
@@ -46,10 +48,10 @@ module RuboCop
46
48
  #
47
49
  # @return [Array<Node>]
48
50
  def arguments
49
- if numblock_type?
50
- [].freeze # Numbered parameters have no block arguments.
51
- else
51
+ if block_type?
52
52
  node_parts[1]
53
+ else
54
+ [].freeze # Numblocks and itblocks have no explicit block arguments.
53
55
  end
54
56
  end
55
57
 
@@ -60,6 +62,8 @@ module RuboCop
60
62
  def argument_list
61
63
  if numblock_type?
62
64
  numbered_arguments
65
+ elsif itblock_type?
66
+ IT_BLOCK_ARGUMENT
63
67
  else
64
68
  arguments.argument_list
65
69
  end
@@ -153,10 +157,7 @@ module RuboCop
153
157
 
154
158
  private
155
159
 
156
- # Numbered arguments of this `numblock`.
157
160
  def numbered_arguments
158
- return [].freeze unless numblock_type?
159
-
160
161
  max_param = children[1]
161
162
  1.upto(max_param).map do |i|
162
163
  ArgNode.new(:arg, [:"_#{i}"])
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module AST
5
+ # A node extension for `complex` nodes. This will be used in place of a plain
6
+ # node when the builder constructs the AST, making its methods available to
7
+ # all `complex` nodes within RuboCop.
8
+ class ComplexNode < Node
9
+ include BasicLiteralNode
10
+ include NumericNode
11
+ end
12
+ end
13
+ end
@@ -6,11 +6,24 @@ 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`.
12
15
  # @deprecated Use `EnsureNode#branch`
13
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
+
14
27
  branch
15
28
  end
16
29
 
@@ -20,7 +20,7 @@ module RuboCop
20
20
  # @return [Array<Symbol>] names of all the variables being assigned
21
21
  def names
22
22
  assignments.map do |assignment|
23
- if assignment.send_type? || assignment.indexasgn_type?
23
+ if assignment.type?(:send, :indexasgn)
24
24
  assignment.method_name
25
25
  else
26
26
  assignment.name
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module AST
5
5
  # Common functionality for primitive literal nodes: `sym`, `str`,
6
- # `int`, `float`, `rational`...
6
+ # `int`, `float`, `rational`, `complex`...
7
7
  module BasicLiteralNode
8
8
  # Returns the value of the literal.
9
9
  #
@@ -99,7 +99,9 @@ module RuboCop
99
99
 
100
100
  def valid_argument_types?
101
101
  [first, second].all? do |argument|
102
+ # rubocop:disable InternalAffairs/NodeTypeMultiplePredicates
102
103
  argument.pair_type? || argument.kwsplat_type?
104
+ # rubocop:enable InternalAffairs/NodeTypeMultiplePredicates
103
105
  end
104
106
  end
105
107
 
@@ -32,17 +32,17 @@ module RuboCop
32
32
  #
33
33
  # @return [Parser::Source::Range] the source range for the method name or keyword
34
34
  def selector
35
- if loc.respond_to? :keyword
35
+ if loc?(:keyword)
36
36
  loc.keyword
37
37
  else
38
38
  loc.selector
39
39
  end
40
40
  end
41
41
 
42
- # The `block` or `numblock` node associated with this method dispatch, if any.
42
+ # The `block`, `numblock`, or `itblock` node associated with this method dispatch, if any.
43
43
  #
44
- # @return [BlockNode, nil] the `block` or `numblock` node associated with this method
45
- # call or `nil`
44
+ # @return [BlockNode, nil] the `block`, `numblock`, or `itblock` node associated with this
45
+ # method call or `nil`
46
46
  def block_node
47
47
  parent if block_literal?
48
48
  end
@@ -200,8 +200,7 @@ module RuboCop
200
200
  arg = node.children[2]
201
201
 
202
202
  return unless node.send_type? && node.receiver.nil? && arg.is_a?(::AST::Node)
203
-
204
- return arg if arg.def_type? || arg.defs_type?
203
+ return arg if arg.any_def_type?
205
204
 
206
205
  def_modifier(arg)
207
206
  end
@@ -271,7 +270,7 @@ module RuboCop
271
270
 
272
271
  # @!method adjacent_def_modifier?(node = self)
273
272
  def_node_matcher :adjacent_def_modifier?, <<~PATTERN
274
- (send nil? _ ({def defs} ...))
273
+ (send nil? _ (any_def ...))
275
274
  PATTERN
276
275
 
277
276
  # @!method bare_access_modifier_declaration?(node = self)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module AST
5
- # Common functionality for primitive numeric nodes: `int`, `float`, `rational`...
5
+ # Common functionality for primitive numeric nodes: `int`, `float`, `rational`, `complex`...
6
6
  module NumericNode
7
7
  SIGN_REGEX = /\A[+-]/.freeze
8
8
  private_constant :SIGN_REGEX
@@ -15,7 +15,7 @@ module RuboCop
15
15
  #
16
16
  # @return [Boolean] whether this literal has a sign.
17
17
  def sign?
18
- source.match(SIGN_REGEX)
18
+ source.match?(SIGN_REGEX)
19
19
  end
20
20
  end
21
21
  end
@@ -57,7 +57,7 @@ module RuboCop
57
57
  # @return [Boolean] whether the last argument of the node is a block pass
58
58
  def block_argument?
59
59
  arguments? &&
60
- (last_argument.block_pass_type? || last_argument.blockarg_type?)
60
+ last_argument.type?(:block_pass, :blockarg)
61
61
  end
62
62
 
63
63
  # A specialized `ParameterizedNode` for node that have a single child
@@ -65,6 +65,7 @@ module RuboCop
65
65
  # arguments
66
66
  module WrappedArguments
67
67
  include ParameterizedNode
68
+
68
69
  # @return [Array] The arguments of the node.
69
70
  def arguments
70
71
  first = children.first
@@ -87,6 +87,9 @@ module RuboCop
87
87
 
88
88
  # @api private
89
89
  GROUP_FOR_TYPE = {
90
+ def: :any_def,
91
+ defs: :any_def,
92
+
90
93
  arg: :argument,
91
94
  optarg: :argument,
92
95
  restarg: :argument,
@@ -105,6 +108,13 @@ module RuboCop
105
108
  rational: :numeric,
106
109
  complex: :numeric,
107
110
 
111
+ str: :any_str,
112
+ dstr: :any_str,
113
+ xstr: :any_str,
114
+
115
+ sym: :any_sym,
116
+ dsym: :any_sym,
117
+
108
118
  irange: :range,
109
119
  erange: :range,
110
120
 
@@ -112,7 +122,11 @@ module RuboCop
112
122
  csend: :call,
113
123
 
114
124
  block: :any_block,
115
- numblock: :any_block
125
+ numblock: :any_block,
126
+ itblock: :any_block,
127
+
128
+ match_pattern: :any_match_pattern,
129
+ match_pattern_p: :any_match_pattern
116
130
  }.freeze
117
131
  private_constant :GROUP_FOR_TYPE
118
132
 
@@ -265,7 +279,7 @@ module RuboCop
265
279
  def right_siblings
266
280
  return [].freeze unless parent
267
281
 
268
- parent.children[sibling_index + 1..].freeze
282
+ parent.children[(sibling_index + 1)..].freeze
269
283
  end
270
284
 
271
285
  # Common destructuring method. This can be used to normalize
@@ -512,6 +526,10 @@ module RuboCop
512
526
  parent&.send_type? && parent.arguments.include?(self)
513
527
  end
514
528
 
529
+ def any_def_type?
530
+ GROUP_FOR_TYPE[type] == :any_def
531
+ end
532
+
515
533
  def argument_type?
516
534
  GROUP_FOR_TYPE[type] == :argument
517
535
  end
@@ -532,6 +550,18 @@ module RuboCop
532
550
  GROUP_FOR_TYPE[type] == :any_block
533
551
  end
534
552
 
553
+ def any_match_pattern_type?
554
+ GROUP_FOR_TYPE[type] == :any_match_pattern
555
+ end
556
+
557
+ def any_str_type?
558
+ GROUP_FOR_TYPE[type] == :any_str
559
+ end
560
+
561
+ def any_sym_type?
562
+ GROUP_FOR_TYPE[type] == :any_sym
563
+ end
564
+
535
565
  def guard_clause?
536
566
  node = operator_keyword? ? rhs : self
537
567
 
@@ -685,7 +715,7 @@ module RuboCop
685
715
  def case_if_value_used?
686
716
  # (case <condition> <when...>)
687
717
  # (if <condition> <truebranch> <falsebranch>)
688
- sibling_index.zero? ? true : parent.value_used?
718
+ sibling_index.zero? || parent.value_used?
689
719
  end
690
720
 
691
721
  def while_until_value_used?
@@ -15,10 +15,12 @@ module RuboCop
15
15
  @visit = {}
16
16
  end
17
17
 
18
+ # rubocop:disable Naming/PredicateMethod
18
19
  def enter(node_id)
19
20
  @visit[node_id] = false
20
21
  true
21
22
  end
23
+ # rubocop:enable Naming/PredicateMethod
22
24
 
23
25
  def success(node_id)
24
26
  @visit[node_id] = true
@@ -109,14 +111,7 @@ module RuboCop
109
111
  private
110
112
 
111
113
  def ruby_ast(ruby)
112
- buffer = ::Parser::Source::Buffer.new('(ruby)', source: ruby)
113
- ruby_parser.parse(buffer)
114
- end
115
-
116
- def ruby_parser
117
- require 'parser/current'
118
- builder = ::RuboCop::AST::Builder.new
119
- ::Parser::CurrentRuby.new(builder)
114
+ ProcessedSource.new(ruby, RUBY_VERSION.to_f, '(ruby)').ast
120
115
  end
121
116
  end
122
117
 
@@ -261,7 +261,7 @@ module RuboCop
261
261
  arities = children
262
262
  .reverse
263
263
  .map(&:arity_range)
264
- .map { |r| last = last.begin + r.begin..last.max + r.max }
264
+ .map { |r| last = (last.begin + r.begin)..(last.max + r.max) }
265
265
  .reverse!
266
266
  arities.push last_arity
267
267
  end
@@ -10,6 +10,7 @@ module RuboCop
10
10
  # /docs/modules/ROOT/pages/node_pattern.adoc
11
11
  class Compiler
12
12
  extend SimpleForwardable
13
+
13
14
  attr_reader :captures, :named_parameters, :positional_parameters, :binding
14
15
 
15
16
  def initialize
@@ -21,7 +21,7 @@ macros
21
21
  rules
22
22
  /\s+/
23
23
  /:(#{SYMBOL_NAME})/o { emit :tSYMBOL, &:to_sym }
24
- /"(.+?)"/ { emit :tSTRING }
24
+ /"(.*?)"/ { emit :tSTRING }
25
25
  /[-+]?\d+\.\d+/ { emit :tNUMBER, &:to_f }
26
26
  /[-+]?\d+/ { emit :tNUMBER, &:to_i }
27
27
  /#{Regexp.union(
@@ -122,7 +122,7 @@ class RuboCop::AST::NodePattern::LexerRex
122
122
  # do nothing
123
123
  when ss.skip(/:(#{SYMBOL_NAME})/o) then
124
124
  action { emit :tSYMBOL, &:to_sym }
125
- when ss.skip(/"(.+?)"/) then
125
+ when ss.skip(/"(.*?)"/) then
126
126
  action { emit :tSTRING }
127
127
  when ss.skip(/[-+]?\d+\.\d+/) then
128
128
  action { emit :tNUMBER, &:to_f }
@@ -179,7 +179,7 @@ module RuboCop
179
179
  class AnyOrder < Node
180
180
  include ForbidInSeqHead
181
181
 
182
- ARITIES = Hash.new { |h, k| h[k] = k - 1..Float::INFINITY }
182
+ ARITIES = Hash.new { |h, k| h[k] = (k - 1)..Float::INFINITY }
183
183
  private_constant :ARITIES
184
184
 
185
185
  def term_nodes
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  #
3
3
  # DO NOT MODIFY!!!!
4
- # This file is automatically generated by Racc 1.8.1
5
- # from Racc grammar file "parser.y".
4
+ # This file is automatically generated by Racc 1.5.0
5
+ # from Racc grammar file "".
6
6
  #
7
7
 
8
8
  require 'racc/parser.rb'
@@ -14,15 +14,15 @@ module RuboCop
14
14
 
15
15
  racc_action_table = [
16
16
  14, 15, 16, 21, 18, 17, 19, 10, 11, 12,
17
- 60, 22, 20, 4, 24, 5, 40, 6, 7, 8,
18
- 28, 23, 56, 50, 40, 61, 43, 66, 51, 51,
17
+ 60, 22, 20, 4, 40, 5, 43, 6, 7, 8,
18
+ 28, 23, 56, 50, 66, 61, 24, 51, 51, 40,
19
19
  58, 14, 15, 16, 21, 18, 17, 19, 10, 11,
20
20
  12, nil, 22, 20, 4, nil, 5, nil, 6, 7,
21
21
  8, 28, 23, nil, nil, -34, 14, 15, 16, 21,
22
22
  18, 17, 19, 10, 11, 12, nil, 22, 20, 4,
23
23
  nil, 5, nil, 6, 7, 8, 9, 23, 14, 15,
24
24
  16, 21, 18, 17, 19, 10, 11, 12, nil, 22,
25
- 20, 4, nil, 5, nil, 6, 7, 8, 28, 23,
25
+ 20, 4, nil, 5, nil, 6, 7, 8, 9, 23,
26
26
  14, 15, 16, 21, 18, 17, 19, 10, 11, 12,
27
27
  nil, 22, 20, 4, nil, 5, nil, 6, 7, 8,
28
28
  9, 23, 14, 15, 16, 21, 18, 17, 19, 10,
@@ -33,7 +33,7 @@ racc_action_table = [
33
33
  18, 17, 19, 10, 11, 12, nil, 22, 20, 4,
34
34
  nil, 5, nil, 6, 7, 8, 9, 23, 14, 15,
35
35
  16, 21, 18, 17, 19, 10, 11, 12, nil, 22,
36
- 20, 4, nil, 5, nil, 6, 7, 8, 9, 23,
36
+ 20, 4, nil, 5, nil, 6, 7, 8, 28, 23,
37
37
  14, 15, 16, 21, 18, 17, 19, 10, 11, 12,
38
38
  nil, 22, 20, 4, 44, 5, nil, 6, 7, 8,
39
39
  28, 23, 14, 15, 16, 21, 18, 17, 19, 10,
@@ -47,31 +47,31 @@ racc_action_table = [
47
47
  20, 4, nil, 5, nil, 6, 7, 8, 9, 23,
48
48
  14, 15, 16, 21, 18, 17, 19, 10, 11, 12,
49
49
  nil, 22, 20, 4, nil, 5, nil, 6, 7, 8,
50
- 9, 23, -1, -1, -1, -2, -2, -2, 47, 48,
51
- 49 ]
50
+ 9, 23, 47, 48, 49, -1, -1, -1, -2, -2,
51
+ -2 ]
52
52
 
53
53
  racc_action_check = [
54
54
  42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
55
- 54, 42, 42, 42, 1, 42, 10, 42, 42, 42,
56
- 42, 42, 42, 30, 11, 54, 24, 62, 30, 63,
55
+ 54, 42, 42, 42, 11, 42, 24, 42, 42, 42,
56
+ 42, 42, 42, 30, 62, 54, 1, 63, 30, 10,
57
57
  42, 59, 59, 59, 59, 59, 59, 59, 59, 59,
58
58
  59, nil, 59, 59, 59, nil, 59, nil, 59, 59,
59
- 59, 59, 59, nil, nil, 59, 0, 0, 0, 0,
59
+ 59, 59, 59, nil, nil, 59, 5, 5, 5, 5,
60
+ 5, 5, 5, 5, 5, 5, nil, 5, 5, 5,
61
+ nil, 5, nil, 5, 5, 5, 5, 5, 6, 6,
62
+ 6, 6, 6, 6, 6, 6, 6, 6, nil, 6,
63
+ 6, 6, nil, 6, nil, 6, 6, 6, 6, 6,
64
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
65
+ nil, 7, 7, 7, nil, 7, nil, 7, 7, 7,
66
+ 7, 7, 8, 8, 8, 8, 8, 8, 8, 8,
67
+ 8, 8, nil, 8, 8, 8, nil, 8, nil, 8,
68
+ 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
69
+ 9, 9, 9, 9, nil, 9, 9, 9, nil, 9,
70
+ nil, 9, 9, 9, 9, 9, 0, 0, 0, 0,
60
71
  0, 0, 0, 0, 0, 0, nil, 0, 0, 0,
61
72
  nil, 0, nil, 0, 0, 0, 0, 0, 4, 4,
62
73
  4, 4, 4, 4, 4, 4, 4, 4, nil, 4,
63
74
  4, 4, nil, 4, nil, 4, 4, 4, 4, 4,
64
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
65
- nil, 5, 5, 5, nil, 5, nil, 5, 5, 5,
66
- 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
67
- 6, 6, nil, 6, 6, 6, nil, 6, nil, 6,
68
- 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
69
- 7, 7, 7, 7, nil, 7, 7, 7, nil, 7,
70
- nil, 7, 7, 7, 7, 7, 8, 8, 8, 8,
71
- 8, 8, 8, 8, 8, 8, nil, 8, 8, 8,
72
- nil, 8, nil, 8, 8, 8, 8, 8, 9, 9,
73
- 9, 9, 9, 9, 9, 9, 9, 9, nil, 9,
74
- 9, 9, nil, 9, nil, 9, 9, 9, 9, 9,
75
75
  27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
76
76
  nil, 27, 27, 27, 27, 27, nil, 27, 27, 27,
77
77
  27, 27, 28, 28, 28, 28, 28, 28, 28, 28,
@@ -85,17 +85,17 @@ racc_action_check = [
85
85
  50, 50, nil, 50, nil, 50, 50, 50, 50, 50,
86
86
  61, 61, 61, 61, 61, 61, 61, 61, 61, 61,
87
87
  nil, 61, 61, 61, nil, 61, nil, 61, 61, 61,
88
- 61, 61, 25, 25, 25, 26, 26, 26, 29, 29,
89
- 29 ]
88
+ 61, 61, 29, 29, 29, 25, 25, 25, 26, 26,
89
+ 26 ]
90
90
 
91
91
  racc_action_pointer = [
92
- 54, 14, nil, nil, 76, 98, 120, 142, 164, 186,
93
- 4, 12, nil, nil, nil, nil, nil, nil, nil, nil,
94
- nil, nil, nil, nil, 26, 315, 318, 208, 230, 321,
92
+ 164, 26, nil, nil, 186, 54, 76, 98, 120, 142,
93
+ 17, 2, nil, nil, nil, nil, nil, nil, nil, nil,
94
+ nil, nil, nil, nil, 16, 318, 321, 208, 230, 315,
95
95
  -2, nil, nil, 252, nil, nil, nil, nil, nil, nil,
96
96
  274, nil, -2, nil, nil, nil, nil, nil, nil, nil,
97
97
  296, nil, nil, nil, -6, nil, nil, nil, nil, 29,
98
- nil, 318, 1, -1, nil, nil, nil ]
98
+ nil, 318, -2, -3, nil, nil, nil ]
99
99
 
100
100
  racc_action_default = [
101
101
  -47, -47, -1, -2, -31, -47, -47, -47, -47, -47,
@@ -107,26 +107,26 @@ racc_action_default = [
107
107
  -37, -47, -47, -47, -35, -39, -26 ]
108
108
 
109
109
  racc_goto_table = [
110
- 1, 33, 27, 25, 26, 34, 35, 36, 37, 38,
111
- 42, 32, 39, 41, 46, 63, 62, 64, 54, nil,
112
- nil, nil, nil, nil, nil, nil, 25, 26, 38, nil,
113
- nil, nil, nil, 53, 45, nil, nil, nil, nil, nil,
114
- 55, 25, 26, nil, nil, nil, 59, nil, nil, 57,
110
+ 1, 33, 64, 32, 25, 34, 35, 36, 37, 38,
111
+ 54, 26, 39, 41, 27, 42, 46, 63, 62, nil,
112
+ nil, nil, nil, nil, nil, nil, 45, 25, 38, nil,
113
+ nil, nil, nil, 53, 26, nil, nil, nil, nil, nil,
114
+ 55, 57, 25, nil, nil, nil, 59, nil, nil, 26,
115
115
  34, nil, nil, nil, nil, nil, nil, nil, nil, 53,
116
116
  nil, 65 ]
117
117
 
118
118
  racc_goto_check = [
119
- 1, 5, 4, 2, 3, 1, 1, 1, 1, 1,
120
- 8, 9, 6, 6, 10, 11, 12, 13, 14, nil,
121
- nil, nil, nil, nil, nil, nil, 2, 3, 1, nil,
122
- nil, nil, nil, 1, 9, nil, nil, nil, nil, nil,
123
- 1, 2, 3, nil, nil, nil, 5, nil, nil, 9,
119
+ 1, 5, 13, 9, 2, 1, 1, 1, 1, 1,
120
+ 14, 3, 6, 6, 4, 8, 10, 11, 12, nil,
121
+ nil, nil, nil, nil, nil, nil, 9, 2, 1, nil,
122
+ nil, nil, nil, 1, 3, nil, nil, nil, nil, nil,
123
+ 1, 9, 2, nil, nil, nil, 5, nil, nil, 3,
124
124
  1, nil, nil, nil, nil, nil, nil, nil, nil, 1,
125
125
  nil, 1 ]
126
126
 
127
127
  racc_goto_pointer = [
128
- nil, 0, -1, 0, -2, -4, 2, nil, -13, 7,
129
- -15, -44, -43, -42, -22 ]
128
+ nil, 0, 0, 7, 10, -4, 2, nil, -8, -1,
129
+ -13, -42, -41, -57, -30 ]
130
130
 
131
131
  racc_goto_default = [
132
132
  nil, 29, 2, 3, nil, nil, nil, 13, nil, nil,
@@ -239,7 +239,6 @@ Racc_arg = [
239
239
  racc_shift_n,
240
240
  racc_reduce_n,
241
241
  racc_use_result_var ]
242
- Ractor.make_shareable(Racc_arg) if defined?(Ractor)
243
242
 
244
243
  Racc_token_to_s_table = [
245
244
  "$end",
@@ -290,7 +289,6 @@ Racc_token_to_s_table = [
290
289
  "opt_rest",
291
290
  "rest",
292
291
  "arg_list" ]
293
- Ractor.make_shareable(Racc_token_to_s_table) if defined?(Ractor)
294
292
 
295
293
  Racc_debug_parser = false
296
294
 
@@ -50,6 +50,7 @@ module RuboCop
50
50
 
51
51
  extend SimpleForwardable
52
52
  include MethodDefiner
53
+
53
54
  Invalid = Class.new(StandardError)
54
55
 
55
56
  VAR = 'node'
@@ -4,6 +4,27 @@ require 'digest/sha1'
4
4
 
5
5
  module RuboCop
6
6
  module AST
7
+ # A `Prism` interface's class that provides a fixed `Prism::ParseLexResult` instead of parsing.
8
+ #
9
+ # This class implements the `parse_lex` method to return a preparsed `Prism::ParseLexResult`
10
+ # rather than parsing the source code. When the parse result is already available externally,
11
+ # such as in Ruby LSP, the Prism parsing process can be bypassed.
12
+ class PrismPreparsed
13
+ def initialize(prism_result)
14
+ unless prism_result.is_a?(Prism::ParseLexResult)
15
+ raise ArgumentError, <<~MESSAGE
16
+ Expected a `Prism::ParseLexResult` object, but received `#{prism_result.class}`.
17
+ MESSAGE
18
+ end
19
+
20
+ @prism_result = prism_result
21
+ end
22
+
23
+ def parse_lex(_source, **_prism_options)
24
+ @prism_result
25
+ end
26
+ end
27
+
7
28
  # ProcessedSource contains objects which are generated by Parser
8
29
  # and other information such as disabled lines for cops.
9
30
  # It also provides a convenient way to access source lines.
@@ -14,23 +35,21 @@ module RuboCop
14
35
  INVALID_LEVELS = %i[error fatal].freeze
15
36
  private_constant :INVALID_LEVELS
16
37
 
17
- PARSER_ENGINES = %i[parser_whitequark parser_prism].freeze
38
+ PARSER_ENGINES = %i[default parser_whitequark parser_prism].freeze
18
39
  private_constant :PARSER_ENGINES
19
40
 
20
41
  attr_reader :path, :buffer, :ast, :comments, :tokens, :diagnostics,
21
42
  :parser_error, :raw_source, :ruby_version, :parser_engine
22
43
 
23
- def self.from_file(path, ruby_version, parser_engine: :parser_whitequark)
44
+ def self.from_file(path, ruby_version, parser_engine: :default)
24
45
  file = File.read(path, mode: 'rb')
25
46
  new(file, ruby_version, path, parser_engine: parser_engine)
26
47
  end
27
48
 
28
- def initialize(source, ruby_version, path = nil, parser_engine: :parser_whitequark)
29
- parser_engine = parser_engine.to_sym
30
- unless PARSER_ENGINES.include?(parser_engine)
31
- raise ArgumentError, 'The keyword argument `parser_engine` accepts `parser_whitequark` ' \
32
- "or `parser_prism`, but `#{parser_engine}` was passed."
33
- end
49
+ def initialize(
50
+ source, ruby_version, path = nil, parser_engine: :default, prism_result: nil
51
+ )
52
+ parser_engine = normalize_parser_engine(parser_engine, ruby_version)
34
53
 
35
54
  # Defaults source encoding to UTF-8, regardless of the encoding it has
36
55
  # been read with, which could be non-utf8 depending on the default
@@ -44,7 +63,7 @@ module RuboCop
44
63
  @parser_engine = parser_engine
45
64
  @parser_error = nil
46
65
 
47
- parse(source, ruby_version, parser_engine)
66
+ parse(source, ruby_version, parser_engine, prism_result)
48
67
  end
49
68
 
50
69
  def ast_with_comments
@@ -202,7 +221,7 @@ module RuboCop
202
221
  end
203
222
  end
204
223
 
205
- def parse(source, ruby_version, parser_engine)
224
+ def parse(source, ruby_version, parser_engine, prism_result)
206
225
  buffer_name = @path || STRING_SOURCE_NAME
207
226
  @buffer = Parser::Source::Buffer.new(buffer_name, 1)
208
227
 
@@ -216,7 +235,9 @@ module RuboCop
216
235
  return
217
236
  end
218
237
 
219
- @ast, @comments, @tokens = tokenize(create_parser(ruby_version, parser_engine))
238
+ parser = create_parser(ruby_version, parser_engine, prism_result)
239
+
240
+ @ast, @comments, @tokens = tokenize(parser)
220
241
  end
221
242
 
222
243
  def tokenize(parser)
@@ -235,7 +256,8 @@ module RuboCop
235
256
  [ast, comments, tokens]
236
257
  end
237
258
 
238
- def parser_class(ruby_version, parser_engine) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
259
+ # rubocop:disable Lint/FloatComparison, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
260
+ def parser_class(ruby_version, parser_engine)
239
261
  case parser_engine
240
262
  when :parser_whitequark
241
263
  case ruby_version
@@ -282,54 +304,53 @@ module RuboCop
282
304
  require 'parser/ruby34'
283
305
  Parser::Ruby34
284
306
  else
285
- raise ArgumentError, "RuboCop found unknown Ruby version: #{ruby_version.inspect}"
307
+ raise ArgumentError, 'RuboCop supports target Ruby versions 3.4 and below with ' \
308
+ "`parser`. Specified target Ruby version: #{ruby_version.inspect}"
286
309
  end
287
310
  when :parser_prism
288
- require_prism
289
-
290
311
  case ruby_version
291
312
  when 3.3
292
- require_prism_translation_parser(ruby_version)
293
313
  Prism::Translation::Parser33
294
314
  when 3.4
295
- require_prism_translation_parser(ruby_version)
296
315
  Prism::Translation::Parser34
316
+ when 3.5, 4.0
317
+ Prism::Translation::Parser40
318
+ when 4.1
319
+ Prism::Translation::Parser41
297
320
  else
298
321
  raise ArgumentError, 'RuboCop supports target Ruby versions 3.3 and above with Prism. ' \
299
322
  "Specified target Ruby version: #{ruby_version.inspect}"
300
323
  end
301
324
  end
302
325
  end
326
+ # rubocop:enable Lint/FloatComparison, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
303
327
 
304
- # Prism is a native extension, a `LoadError` will be raised if linked to an incompatible
305
- # Ruby version. Only raise if it really was caused by Prism not being present.
306
- def require_prism
307
- require 'prism'
308
- rescue LoadError => e
309
- raise unless e.path == 'prism'
310
-
311
- warn "Error: Unable to load Prism. Add `gem 'prism'` to your Gemfile."
312
- exit!
328
+ def builder_class(parser_engine)
329
+ case parser_engine
330
+ when :parser_whitequark
331
+ RuboCop::AST::Builder
332
+ when :parser_prism
333
+ RuboCop::AST::BuilderPrism
334
+ end
313
335
  end
314
336
 
315
- # While Prism is not yet a dependency, users may run with outdated versions that
316
- # don't have all the parsers.
317
- def require_prism_translation_parser(version)
318
- require "prism/translation/parser#{version.to_s.delete('.')}"
319
- rescue LoadError
320
- warn <<~MESSAGE
321
- Error: Unable to load Prism parser for Ruby #{version}.
322
- * If you're using Bundler and don't yet have `gem 'prism'` as a dependency, add it now.
323
- * If you're using Bundler and already have `gem 'prism'` as a dependency, update it to the most recent version.
324
- * If you don't use Bundler, run `gem update prism`.
325
- MESSAGE
326
- exit!
327
- end
337
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
338
+ def create_parser(ruby_version, parser_engine, prism_result)
339
+ builder = builder_class(parser_engine).new
340
+
341
+ parser_class = parser_class(ruby_version, parser_engine)
328
342
 
329
- def create_parser(ruby_version, parser_engine)
330
- builder = RuboCop::AST::Builder.new
343
+ parser_instance = if parser_engine == :parser_prism && prism_result
344
+ # NOTE: Since it is intended for use with Ruby LSP, it targets only Prism.
345
+ # If there is no reuse of a pre-parsed result, such as in Ruby LSP,
346
+ # regular parsing with Prism occurs, and `else` branch will be executed.
347
+ prism_reparsed = PrismPreparsed.new(prism_result)
348
+ parser_class.new(builder, parser: prism_reparsed)
349
+ else
350
+ parser_class.new(builder)
351
+ end
331
352
 
332
- parser_class(ruby_version, parser_engine).new(builder).tap do |parser|
353
+ parser_instance.tap do |parser|
333
354
  # On JRuby there's a risk that we hang in tokenize() if we
334
355
  # don't set the all errors as fatal flag. The problem is caused by a bug
335
356
  # in Racc that is discussed in issue #93 of the whitequark/parser
@@ -341,6 +362,32 @@ module RuboCop
341
362
  end
342
363
  end
343
364
  end
365
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
366
+
367
+ def normalize_parser_engine(parser_engine, ruby_version)
368
+ parser_engine = parser_engine.to_sym
369
+ unless PARSER_ENGINES.include?(parser_engine)
370
+ raise ArgumentError, 'The keyword argument `parser_engine` accepts `default`, ' \
371
+ "`parser_whitequark`, or `parser_prism`, but `#{parser_engine}` " \
372
+ 'was passed.'
373
+ end
374
+ if parser_engine == :default
375
+ default_parser_engine(ruby_version)
376
+ else
377
+ parser_engine
378
+ end
379
+ end
380
+
381
+ # The Parser gem does not support Ruby 3.5 or later.
382
+ # It is also not fully compatible with Ruby 3.4 but for
383
+ # now respects using parser for backwards compatibility.
384
+ def default_parser_engine(ruby_version)
385
+ if ruby_version >= 3.4
386
+ :parser_prism
387
+ else
388
+ :parser_whitequark
389
+ end
390
+ end
344
391
 
345
392
  def first_token_index(range_or_node)
346
393
  begin_pos = source_range(range_or_node).begin_pos
@@ -26,16 +26,18 @@ module RuboCop
26
26
  SEND = 'send(TYPE_TO_METHOD[child.type], child)'
27
27
  assign_code = 'child = node.children[%<index>i]'
28
28
  code = "#{assign_code}\n#{SEND}"
29
+ # How a particular child node should be visited. For example, if a child node
30
+ # can be nil it should be guarded behind a nil check. Or, if a child node is a literal
31
+ # (like a symbol) then the literal itself should not be visited.
29
32
  TEMPLATE = {
30
33
  skip: '',
31
34
  always: code,
32
35
  nil?: "#{code} if child"
33
36
  }.freeze
34
37
 
35
- def def_callback(type, *signature,
36
- arity: signature.size..signature.size,
37
- arity_check: ENV.fetch('RUBOCOP_DEBUG', nil) && self.arity_check(arity),
38
- body: self.body(signature, arity_check))
38
+ def def_callback(type, *child_node_types,
39
+ expected_children_count: child_node_types.size..child_node_types.size,
40
+ body: self.body(child_node_types, expected_children_count))
39
41
  type, *aliases = type
40
42
  lineno = caller_locations(1, 1).first.lineno
41
43
  module_eval(<<~RUBY, __FILE__, lineno)
@@ -49,16 +51,23 @@ module RuboCop
49
51
  end
50
52
  end
51
53
 
52
- def body(signature, prelude)
53
- signature
54
- .map.with_index do |arg, i|
55
- TEMPLATE[arg].gsub('%<index>i', i.to_s)
54
+ def body(child_node_types, expected_children_count)
55
+ visit_children_code =
56
+ child_node_types
57
+ .map.with_index do |child_type, i|
58
+ TEMPLATE.fetch(child_type).gsub('%<index>i', i.to_s)
56
59
  end
57
- .unshift(prelude)
58
60
  .join("\n")
61
+
62
+ <<~BODY
63
+ #{children_count_check_code(expected_children_count)}
64
+ #{visit_children_code}
65
+ BODY
59
66
  end
60
67
 
61
- def arity_check(range)
68
+ def children_count_check_code(range)
69
+ return '' unless ENV.fetch('RUBOCOP_DEBUG', false)
70
+
62
71
  <<~RUBY
63
72
  n = node.children.size
64
73
  raise DebugError, [
@@ -70,20 +79,21 @@ module RuboCop
70
79
  end
71
80
  private_constant :CallbackCompiler
72
81
  extend CallbackCompiler
82
+
73
83
  send_code = CallbackCompiler::SEND
74
84
 
75
- ### arity == 0
85
+ ### children count == 0
76
86
  no_children = %i[true false nil self cbase zsuper redo retry
77
87
  forward_args forwarded_args match_nil_pattern
78
88
  forward_arg forwarded_restarg forwarded_kwrestarg
79
89
  lambda empty_else kwnilarg
80
90
  __FILE__ __LINE__ __ENCODING__]
81
91
 
82
- ### arity == 0..1
92
+ ### children count == 0..1
83
93
  opt_symbol_child = %i[restarg kwrestarg]
84
94
  opt_node_child = %i[splat kwsplat match_rest]
85
95
 
86
- ### arity == 1
96
+ ### children count == 1
87
97
  literal_child = %i[int float complex
88
98
  rational str sym lvar
89
99
  ivar cvar gvar nth_ref back_ref
@@ -100,16 +110,16 @@ module RuboCop
100
110
  NO_CHILD_NODES = (no_children + opt_symbol_child + literal_child).to_set.freeze
101
111
  private_constant :NO_CHILD_NODES # Used by Commissioner
102
112
 
103
- ### arity > 1
113
+ ### children count > 1
104
114
  symbol_then_opt_node = %i[lvasgn ivasgn cvasgn gvasgn]
105
115
  symbol_then_node_or_nil = %i[optarg kwoptarg]
106
116
  node_then_opt_node = %i[while until module sclass]
107
117
 
108
- ### variable arity
118
+ ### variable children count
109
119
  many_node_children = %i[dstr dsym xstr regexp array hash pair
110
120
  mlhs masgn or_asgn and_asgn rasgn mrasgn
111
121
  undef alias args super yield or and
112
- while_post until_post iflipflop eflipflop
122
+ while_post until_post
113
123
  match_with_lvasgn begin kwbegin return
114
124
  in_match match_alt break next
115
125
  match_as array_pattern array_pattern_with_tail
@@ -117,22 +127,22 @@ module RuboCop
117
127
  index indexasgn procarg0 kwargs]
118
128
  many_opt_node_children = %i[case rescue resbody ensure for when
119
129
  case_match in_pattern irange erange
120
- match_pattern match_pattern_p]
130
+ match_pattern match_pattern_p iflipflop eflipflop]
121
131
 
122
132
  ### Callbacks for above
123
133
  def_callback no_children
124
- def_callback opt_symbol_child, :skip, arity: 0..1
125
- def_callback opt_node_child, :nil?, arity: 0..1
134
+ def_callback opt_symbol_child, :skip, expected_children_count: 0..1
135
+ def_callback opt_node_child, :nil?, expected_children_count: 0..1
126
136
 
127
137
  def_callback literal_child, :skip
128
138
  def_callback node_child, :always
129
139
  def_callback node_or_nil_child, :nil?
130
140
 
131
- def_callback symbol_then_opt_node, :skip, :nil?, arity: 1..2
141
+ def_callback symbol_then_opt_node, :skip, :nil?, expected_children_count: 1..2
132
142
  def_callback symbol_then_node_or_nil, :skip, :nil?
133
143
  def_callback node_then_opt_node, :always, :nil?
134
144
 
135
- def_callback many_symbol_children, :skip, arity_check: nil
145
+ def_callback many_symbol_children, :skip, expected_children_count: (0..)
136
146
  def_callback many_node_children, body: <<~RUBY
137
147
  node.children.each { |child| #{send_code} }
138
148
  RUBY
@@ -143,13 +153,14 @@ module RuboCop
143
153
 
144
154
  ### Other particular cases
145
155
  def_callback :const, :nil?, :skip
146
- def_callback :casgn, :nil?, :skip, :nil?, arity: 2..3
156
+ def_callback :casgn, :nil?, :skip, :nil?, expected_children_count: 2..3
147
157
  def_callback :class, :always, :nil?, :nil?
148
158
  def_callback :def, :skip, :always, :nil?
149
159
  def_callback :op_asgn, :always, :skip, :always
150
160
  def_callback :if, :always, :nil?, :nil?
151
161
  def_callback :block, :always, :always, :nil?
152
162
  def_callback :numblock, :always, :skip, :nil?
163
+ def_callback :itblock, :always, :skip, :nil?
153
164
  def_callback :defs, :always, :skip, :always, :nil?
154
165
 
155
166
  def_callback %i[send csend], body: <<~RUBY
@@ -167,7 +178,7 @@ module RuboCop
167
178
 
168
179
  to_define = ::Parser::Meta::NODE_TYPES.to_a
169
180
  to_define -= defined
170
- to_define -= %i[numargs ident] # transient
181
+ to_define -= %i[numargs itarg ident] # transient
171
182
  to_define -= %i[blockarg_expr restarg_expr] # obsolete
172
183
  to_define -= %i[objc_kwarg objc_restarg objc_varargs] # mac_ruby
173
184
  def_callback to_define, body: <<~RUBY
@@ -5,11 +5,22 @@ module RuboCop
5
5
  module SimpleForwardable
6
6
  def def_delegators(accessor, *methods)
7
7
  methods.each do |method|
8
- class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
9
- def #{method}(...) # def example(...)
10
- #{accessor}.#{method}(...) # foo.example(...)
11
- end # end
12
- RUBY
8
+ if method.end_with?('=') && method.to_s != '[]='
9
+ # Defining a delegator for `foo=` can't use `foo=(...)` because it is a
10
+ # syntax error. Fall back to doing a slower `public_send` instead.
11
+ # TODO: Use foo(method, ...) when Ruby 3.1 is required.
12
+ class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
13
+ def #{method}(*args, **kwargs, &blk) # def example=(*args, **kwargs, &blk)
14
+ #{accessor}.public_send(:#{method}, *args, **kwargs, &blk) # foo.public_send(:example=, *args, **kwargs, &blk)
15
+ end # end
16
+ RUBY
17
+ else
18
+ class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
19
+ def #{method}(...) # def example(...)
20
+ #{accessor}.#{method}(...) # foo.example(...)
21
+ end # end
22
+ RUBY
23
+ end
13
24
  end
14
25
  end
15
26
  end
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module AST
5
5
  module Version
6
- STRING = '1.38.0'
6
+ STRING = '1.49.0'
7
7
  end
8
8
  end
9
9
  end
data/lib/rubocop/ast.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'parser'
4
+ require 'prism'
4
5
  require 'forwardable'
5
6
  require 'set'
6
7
 
@@ -47,6 +48,7 @@ require_relative 'ast/node/case_match_node'
47
48
  require_relative 'ast/node/case_node'
48
49
  require_relative 'ast/node/casgn_node'
49
50
  require_relative 'ast/node/class_node'
51
+ require_relative 'ast/node/complex_node'
50
52
  require_relative 'ast/node/const_node'
51
53
  require_relative 'ast/node/def_node'
52
54
  require_relative 'ast/node/defined_node'
@@ -92,6 +94,7 @@ require_relative 'ast/node/when_node'
92
94
  require_relative 'ast/node/while_node'
93
95
  require_relative 'ast/node/yield_node'
94
96
  require_relative 'ast/builder'
97
+ require_relative 'ast/builder_prism'
95
98
  require_relative 'ast/processed_source'
96
99
  require_relative 'ast/rubocop_compatibility'
97
100
  require_relative 'ast/token'
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.38.0
4
+ version: 1.49.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: 2025-01-27 00:00:00.000000000 Z
13
+ date: 2025-12-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: parser
@@ -18,14 +18,28 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: 3.3.1.0
21
+ version: 3.3.7.2
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: 3.3.1.0
28
+ version: 3.3.7.2
29
+ - !ruby/object:Gem::Dependency
30
+ name: prism
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '1.7'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.7'
29
43
  description: " RuboCop's Node and NodePattern classes.\n"
30
44
  email: rubocop@googlegroups.com
31
45
  executables: []
@@ -39,6 +53,7 @@ files:
39
53
  - lib/rubocop-ast.rb
40
54
  - lib/rubocop/ast.rb
41
55
  - lib/rubocop/ast/builder.rb
56
+ - lib/rubocop/ast/builder_prism.rb
42
57
  - lib/rubocop/ast/ext/range.rb
43
58
  - lib/rubocop/ast/node.rb
44
59
  - lib/rubocop/ast/node/alias_node.rb
@@ -54,6 +69,7 @@ files:
54
69
  - lib/rubocop/ast/node/case_node.rb
55
70
  - lib/rubocop/ast/node/casgn_node.rb
56
71
  - lib/rubocop/ast/node/class_node.rb
72
+ - lib/rubocop/ast/node/complex_node.rb
57
73
  - lib/rubocop/ast/node/const_node.rb
58
74
  - lib/rubocop/ast/node/csend_node.rb
59
75
  - lib/rubocop/ast/node/def_node.rb
@@ -162,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
178
  - !ruby/object:Gem::Version
163
179
  version: '0'
164
180
  requirements: []
165
- rubygems_version: 3.5.11
181
+ rubygems_version: 3.5.22
166
182
  signing_key:
167
183
  specification_version: 4
168
184
  summary: RuboCop tools to deal with Ruby code AST.