rubocop-ast 1.32.3 → 1.38.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 +4 -4
- data/lib/rubocop/ast/builder.rb +7 -0
- data/lib/rubocop/ast/node/args_node.rb +1 -1
- data/lib/rubocop/ast/node/array_node.rb +4 -4
- data/lib/rubocop/ast/node/asgn_node.rb +2 -0
- data/lib/rubocop/ast/node/block_node.rb +2 -2
- data/lib/rubocop/ast/node/casgn_node.rb +4 -12
- data/lib/rubocop/ast/node/const_node.rb +1 -52
- data/lib/rubocop/ast/node/ensure_node.rb +15 -0
- data/lib/rubocop/ast/node/for_node.rb +1 -1
- data/lib/rubocop/ast/node/hash_node.rb +1 -1
- data/lib/rubocop/ast/node/if_node.rb +10 -3
- data/lib/rubocop/ast/node/in_pattern_node.rb +1 -1
- data/lib/rubocop/ast/node/keyword_begin_node.rb +44 -0
- data/lib/rubocop/ast/node/masgn_node.rb +63 -0
- data/lib/rubocop/ast/node/mixin/constant_node.rb +62 -0
- data/lib/rubocop/ast/node/mixin/descendence.rb +3 -3
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +7 -7
- data/lib/rubocop/ast/node/mixin/parameterized_node.rb +1 -1
- data/lib/rubocop/ast/node/mixin/predicate_operator_node.rb +7 -2
- data/lib/rubocop/ast/node/mlhs_node.rb +29 -0
- data/lib/rubocop/ast/node/op_asgn_node.rb +3 -1
- data/lib/rubocop/ast/node/str_node.rb +37 -1
- data/lib/rubocop/ast/node/until_node.rb +1 -1
- data/lib/rubocop/ast/node/var_node.rb +15 -0
- data/lib/rubocop/ast/node/when_node.rb +1 -1
- data/lib/rubocop/ast/node/while_node.rb +1 -1
- data/lib/rubocop/ast/node.rb +78 -22
- data/lib/rubocop/ast/node_pattern/lexer.rex.rb +1 -2
- data/lib/rubocop/ast/node_pattern/node.rb +7 -1
- data/lib/rubocop/ast/node_pattern/parser.racc.rb +42 -40
- data/lib/rubocop/ast/processed_source.rb +28 -8
- data/lib/rubocop/ast/token.rb +2 -1
- data/lib/rubocop/ast/version.rb +1 -1
- data/lib/rubocop/ast.rb +5 -0
- metadata +11 -3
@@ -8,13 +8,49 @@ module RuboCop
|
|
8
8
|
class StrNode < Node
|
9
9
|
include BasicLiteralNode
|
10
10
|
|
11
|
+
PERCENT_LITERAL_TYPES = {
|
12
|
+
:% => /\A%(?=[^a-zA-Z])/,
|
13
|
+
:q => /\A%q/,
|
14
|
+
:Q => /\A%Q/
|
15
|
+
}.freeze
|
16
|
+
private_constant :PERCENT_LITERAL_TYPES
|
17
|
+
|
18
|
+
def single_quoted?
|
19
|
+
loc_is?(:begin, "'")
|
20
|
+
end
|
21
|
+
|
22
|
+
def double_quoted?
|
23
|
+
loc_is?(:begin, '"')
|
24
|
+
end
|
25
|
+
|
11
26
|
def character_literal?
|
12
|
-
|
27
|
+
loc_is?(:begin, '?')
|
13
28
|
end
|
14
29
|
|
15
30
|
def heredoc?
|
16
31
|
loc.is_a?(Parser::Source::Map::Heredoc)
|
17
32
|
end
|
33
|
+
|
34
|
+
# Checks whether the string literal is delimited by percent brackets.
|
35
|
+
#
|
36
|
+
# @overload percent_literal?
|
37
|
+
# Check for any string percent literal.
|
38
|
+
#
|
39
|
+
# @overload percent_literal?(type)
|
40
|
+
# Check for a string percent literal of type `type`.
|
41
|
+
#
|
42
|
+
# @param type [Symbol] an optional percent literal type
|
43
|
+
#
|
44
|
+
# @return [Boolean] whether the string is enclosed in percent brackets
|
45
|
+
def percent_literal?(type = nil)
|
46
|
+
return false unless loc?(:begin)
|
47
|
+
|
48
|
+
if type
|
49
|
+
loc.begin.source.match?(PERCENT_LITERAL_TYPES.fetch(type))
|
50
|
+
else
|
51
|
+
loc.begin.source.start_with?('%')
|
52
|
+
end
|
53
|
+
end
|
18
54
|
end
|
19
55
|
end
|
20
56
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module AST
|
5
|
+
# A node extension for `lvar`, `ivar`, `cvar` and `gvar` nodes.
|
6
|
+
# This will be used in place of a plain node when the builder constructs
|
7
|
+
# the AST, making its methods available to all assignment nodes within RuboCop.
|
8
|
+
class VarNode < Node
|
9
|
+
# @return [Symbol] The name of the variable.
|
10
|
+
def name
|
11
|
+
node_parts[0]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/rubocop/ast/node.rb
CHANGED
@@ -76,9 +76,6 @@ module RuboCop
|
|
76
76
|
OPERATOR_KEYWORDS = %i[and or].to_set.freeze
|
77
77
|
# @api private
|
78
78
|
SPECIAL_KEYWORDS = %w[__FILE__ __LINE__ __ENCODING__].to_set.freeze
|
79
|
-
# @api private
|
80
|
-
ARGUMENT_TYPES = %i[arg optarg restarg kwarg kwoptarg kwrestarg
|
81
|
-
blockarg forward_arg shadowarg].to_set.freeze
|
82
79
|
|
83
80
|
LITERAL_RECURSIVE_METHODS = (COMPARISON_OPERATORS + %i[* ! <=>]).freeze
|
84
81
|
LITERAL_RECURSIVE_TYPES = (OPERATOR_KEYWORDS + COMPOSITE_LITERALS + %i[begin pair]).freeze
|
@@ -88,6 +85,37 @@ module RuboCop
|
|
88
85
|
EMPTY_PROPERTIES = {}.freeze
|
89
86
|
private_constant :EMPTY_CHILDREN, :EMPTY_PROPERTIES
|
90
87
|
|
88
|
+
# @api private
|
89
|
+
GROUP_FOR_TYPE = {
|
90
|
+
arg: :argument,
|
91
|
+
optarg: :argument,
|
92
|
+
restarg: :argument,
|
93
|
+
kwarg: :argument,
|
94
|
+
kwoptarg: :argument,
|
95
|
+
kwrestarg: :argument,
|
96
|
+
blockarg: :argument,
|
97
|
+
forward_arg: :argument,
|
98
|
+
shadowarg: :argument,
|
99
|
+
|
100
|
+
true: :boolean,
|
101
|
+
false: :boolean,
|
102
|
+
|
103
|
+
int: :numeric,
|
104
|
+
float: :numeric,
|
105
|
+
rational: :numeric,
|
106
|
+
complex: :numeric,
|
107
|
+
|
108
|
+
irange: :range,
|
109
|
+
erange: :range,
|
110
|
+
|
111
|
+
send: :call,
|
112
|
+
csend: :call,
|
113
|
+
|
114
|
+
block: :any_block,
|
115
|
+
numblock: :any_block
|
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
|
@@ -305,20 +343,19 @@ module RuboCop
|
|
305
343
|
|
306
344
|
# @!method receiver(node = self)
|
307
345
|
def_node_matcher :receiver, <<~PATTERN
|
308
|
-
{(send $_ ...) (
|
346
|
+
{(send $_ ...) (any_block (call $_ ...) ...)}
|
309
347
|
PATTERN
|
310
348
|
|
311
349
|
# @!method str_content(node = self)
|
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}::#{
|
356
|
+
"#{namespace.const_name}::#{short_name}"
|
320
357
|
else
|
321
|
-
|
358
|
+
short_name.to_s
|
322
359
|
end
|
323
360
|
end
|
324
361
|
|
@@ -460,11 +497,11 @@ module RuboCop
|
|
460
497
|
end
|
461
498
|
|
462
499
|
def parenthesized_call?
|
463
|
-
|
500
|
+
loc_is?(:begin, '(')
|
464
501
|
end
|
465
502
|
|
466
503
|
def call_type?
|
467
|
-
|
504
|
+
GROUP_FOR_TYPE[type] == :call
|
468
505
|
end
|
469
506
|
|
470
507
|
def chained?
|
@@ -476,27 +513,47 @@ module RuboCop
|
|
476
513
|
end
|
477
514
|
|
478
515
|
def argument_type?
|
479
|
-
|
516
|
+
GROUP_FOR_TYPE[type] == :argument
|
480
517
|
end
|
481
518
|
|
482
519
|
def boolean_type?
|
483
|
-
|
520
|
+
GROUP_FOR_TYPE[type] == :boolean
|
484
521
|
end
|
485
522
|
|
486
523
|
def numeric_type?
|
487
|
-
|
524
|
+
GROUP_FOR_TYPE[type] == :numeric
|
488
525
|
end
|
489
526
|
|
490
527
|
def range_type?
|
491
|
-
|
528
|
+
GROUP_FOR_TYPE[type] == :range
|
529
|
+
end
|
530
|
+
|
531
|
+
def any_block_type?
|
532
|
+
GROUP_FOR_TYPE[type] == :any_block
|
492
533
|
end
|
493
534
|
|
494
535
|
def guard_clause?
|
495
|
-
node =
|
536
|
+
node = operator_keyword? ? rhs : self
|
496
537
|
|
497
538
|
node.match_guard_clause?
|
498
539
|
end
|
499
540
|
|
541
|
+
# Shortcut to safely check if a location is present
|
542
|
+
# @return [Boolean]
|
543
|
+
def loc?(which_loc)
|
544
|
+
return false unless loc.respond_to?(which_loc)
|
545
|
+
|
546
|
+
!loc.public_send(which_loc).nil?
|
547
|
+
end
|
548
|
+
|
549
|
+
# Shortcut to safely test a particular location, even if
|
550
|
+
# this location does not exist or is `nil`
|
551
|
+
def loc_is?(which_loc, str)
|
552
|
+
return false unless loc?(which_loc)
|
553
|
+
|
554
|
+
loc.public_send(which_loc).is?(str)
|
555
|
+
end
|
556
|
+
|
500
557
|
# @!method match_guard_clause?(node = self)
|
501
558
|
def_node_matcher :match_guard_clause?, <<~PATTERN
|
502
559
|
[${(send nil? {:raise :fail} ...) return break next} single_line?]
|
@@ -510,7 +567,7 @@ module RuboCop
|
|
510
567
|
PATTERN
|
511
568
|
|
512
569
|
# @!method lambda?(node = self)
|
513
|
-
def_node_matcher :lambda?, '(
|
570
|
+
def_node_matcher :lambda?, '(any_block (send nil? :lambda) ...)'
|
514
571
|
|
515
572
|
# @!method lambda_or_proc?(node = self)
|
516
573
|
def_node_matcher :lambda_or_proc?, '{lambda? proc?}'
|
@@ -523,7 +580,7 @@ module RuboCop
|
|
523
580
|
{
|
524
581
|
(send #global_const?({:Class :Module :Struct}) :new ...)
|
525
582
|
(send #global_const?(:Data) :define ...)
|
526
|
-
(
|
583
|
+
(any_block {
|
527
584
|
(send #global_const?({:Class :Module :Struct}) :new ...)
|
528
585
|
(send #global_const?(:Data) :define ...)
|
529
586
|
} ...)
|
@@ -533,20 +590,20 @@ module RuboCop
|
|
533
590
|
# @deprecated Use `:class_constructor?`
|
534
591
|
# @!method struct_constructor?(node = self)
|
535
592
|
def_node_matcher :struct_constructor?, <<~PATTERN
|
536
|
-
(
|
593
|
+
(any_block (send #global_const?(:Struct) :new ...) _ $_)
|
537
594
|
PATTERN
|
538
595
|
|
539
596
|
# @!method class_definition?(node = self)
|
540
597
|
def_node_matcher :class_definition?, <<~PATTERN
|
541
598
|
{(class _ _ $_)
|
542
599
|
(sclass _ $_)
|
543
|
-
(
|
600
|
+
(any_block (send #global_const?({:Struct :Class}) :new ...) _ $_)}
|
544
601
|
PATTERN
|
545
602
|
|
546
603
|
# @!method module_definition?(node = self)
|
547
604
|
def_node_matcher :module_definition?, <<~PATTERN
|
548
605
|
{(module _ $_)
|
549
|
-
(
|
606
|
+
(any_block (send #global_const?(:Module) :new ...) _ $_)}
|
550
607
|
PATTERN
|
551
608
|
|
552
609
|
# Some expressions are evaluated for their value, some for their side
|
@@ -609,8 +666,7 @@ module RuboCop
|
|
609
666
|
last_node = self
|
610
667
|
|
611
668
|
while (current_node = last_node.parent)
|
612
|
-
yield current_node if types.empty? ||
|
613
|
-
types.include?(current_node.type)
|
669
|
+
yield current_node if types.empty? || current_node.type?(*types)
|
614
670
|
last_node = current_node
|
615
671
|
end
|
616
672
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# encoding: UTF-8
|
3
3
|
#--
|
4
4
|
# This file is automatically generated. Do not modify it.
|
5
|
-
# Generated by: oedipus_lex version 2.6.
|
5
|
+
# Generated by: oedipus_lex version 2.6.2.
|
6
6
|
# Source: lib/rubocop/ast/node_pattern/lexer.rex
|
7
7
|
#++
|
8
8
|
|
@@ -70,7 +70,6 @@ class RuboCop::AST::NodePattern::LexerRex
|
|
70
70
|
yield
|
71
71
|
end
|
72
72
|
|
73
|
-
|
74
73
|
##
|
75
74
|
# The current scanner class. Must be overridden in subclasses.
|
76
75
|
|
@@ -48,7 +48,7 @@ module RuboCop
|
|
48
48
|
children[0]
|
49
49
|
end
|
50
50
|
|
51
|
-
# @return [Integer] nb of captures
|
51
|
+
# @return [Integer] nb of captures that this node will emit
|
52
52
|
def nb_captures
|
53
53
|
children_nodes.sum(&:nb_captures)
|
54
54
|
end
|
@@ -243,6 +243,12 @@ module RuboCop
|
|
243
243
|
|
244
244
|
[with(children: new_children)]
|
245
245
|
end
|
246
|
+
|
247
|
+
# Each child in a union must contain the same number
|
248
|
+
# of captures. Only one branch ends up capturing.
|
249
|
+
def nb_captures
|
250
|
+
child.nb_captures
|
251
|
+
end
|
246
252
|
end
|
247
253
|
|
248
254
|
# Registry
|
@@ -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.
|
5
|
-
# from Racc grammar file "".
|
4
|
+
# This file is automatically generated by Racc 1.8.1
|
5
|
+
# from Racc grammar file "parser.y".
|
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,
|
18
|
-
28, 23, 56, 50,
|
17
|
+
60, 22, 20, 4, 24, 5, 40, 6, 7, 8,
|
18
|
+
28, 23, 56, 50, 40, 61, 43, 66, 51, 51,
|
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,
|
25
|
+
20, 4, nil, 5, nil, 6, 7, 8, 28, 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,
|
36
|
+
20, 4, nil, 5, nil, 6, 7, 8, 9, 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,
|
51
|
-
|
50
|
+
9, 23, -1, -1, -1, -2, -2, -2, 47, 48,
|
51
|
+
49 ]
|
52
52
|
|
53
53
|
racc_action_check = [
|
54
54
|
42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
|
55
|
-
54, 42, 42, 42,
|
56
|
-
42, 42, 42, 30,
|
55
|
+
54, 42, 42, 42, 1, 42, 10, 42, 42, 42,
|
56
|
+
42, 42, 42, 30, 11, 54, 24, 62, 30, 63,
|
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,
|
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,
|
59
|
+
59, 59, 59, nil, nil, 59, 0, 0, 0, 0,
|
71
60
|
0, 0, 0, 0, 0, 0, nil, 0, 0, 0,
|
72
61
|
nil, 0, nil, 0, 0, 0, 0, 0, 4, 4,
|
73
62
|
4, 4, 4, 4, 4, 4, 4, 4, nil, 4,
|
74
63
|
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,
|
89
|
-
|
88
|
+
61, 61, 25, 25, 25, 26, 26, 26, 29, 29,
|
89
|
+
29 ]
|
90
90
|
|
91
91
|
racc_action_pointer = [
|
92
|
-
|
93
|
-
|
94
|
-
nil, nil, nil, nil,
|
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,
|
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,
|
98
|
+
nil, 318, 1, -1, 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,
|
111
|
-
|
112
|
-
nil, nil, nil, nil, nil, nil,
|
113
|
-
nil, nil, nil, 53,
|
114
|
-
55,
|
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,
|
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,
|
120
|
-
|
121
|
-
nil, nil, nil, nil, nil, nil,
|
122
|
-
nil, nil, nil, 1,
|
123
|
-
1,
|
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,
|
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, 0,
|
129
|
-
-
|
128
|
+
nil, 0, -1, 0, -2, -4, 2, nil, -13, 7,
|
129
|
+
-15, -44, -43, -42, -22 ]
|
130
130
|
|
131
131
|
racc_goto_default = [
|
132
132
|
nil, 29, 2, 3, nil, nil, nil, 13, nil, nil,
|
@@ -239,6 +239,7 @@ 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)
|
242
243
|
|
243
244
|
Racc_token_to_s_table = [
|
244
245
|
"$end",
|
@@ -289,6 +290,7 @@ Racc_token_to_s_table = [
|
|
289
290
|
"opt_rest",
|
290
291
|
"rest",
|
291
292
|
"arg_list" ]
|
293
|
+
Ractor.make_shareable(Racc_token_to_s_table) if defined?(Ractor)
|
292
294
|
|
293
295
|
Racc_debug_parser = false
|
294
296
|
|
@@ -285,19 +285,14 @@ module RuboCop
|
|
285
285
|
raise ArgumentError, "RuboCop found unknown Ruby version: #{ruby_version.inspect}"
|
286
286
|
end
|
287
287
|
when :parser_prism
|
288
|
-
|
289
|
-
require 'prism'
|
290
|
-
rescue LoadError
|
291
|
-
warn "Error: Unable to load Prism. Add `gem 'prism'` to your Gemfile."
|
292
|
-
exit!
|
293
|
-
end
|
288
|
+
require_prism
|
294
289
|
|
295
290
|
case ruby_version
|
296
291
|
when 3.3
|
297
|
-
|
292
|
+
require_prism_translation_parser(ruby_version)
|
298
293
|
Prism::Translation::Parser33
|
299
294
|
when 3.4
|
300
|
-
|
295
|
+
require_prism_translation_parser(ruby_version)
|
301
296
|
Prism::Translation::Parser34
|
302
297
|
else
|
303
298
|
raise ArgumentError, 'RuboCop supports target Ruby versions 3.3 and above with Prism. ' \
|
@@ -306,6 +301,31 @@ module RuboCop
|
|
306
301
|
end
|
307
302
|
end
|
308
303
|
|
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!
|
313
|
+
end
|
314
|
+
|
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
|
328
|
+
|
309
329
|
def create_parser(ruby_version, parser_engine)
|
310
330
|
builder = RuboCop::AST::Builder.new
|
311
331
|
|
data/lib/rubocop/ast/token.rb
CHANGED
@@ -5,6 +5,7 @@ module RuboCop
|
|
5
5
|
# A basic wrapper around Parser's tokens.
|
6
6
|
class Token
|
7
7
|
LEFT_PAREN_TYPES = %i[tLPAREN tLPAREN2].freeze
|
8
|
+
LEFT_CURLY_TYPES = %i[tLCURLY tLAMBEG].freeze
|
8
9
|
|
9
10
|
attr_reader :pos, :type, :text
|
10
11
|
|
@@ -83,7 +84,7 @@ module RuboCop
|
|
83
84
|
end
|
84
85
|
|
85
86
|
def left_curly_brace?
|
86
|
-
type
|
87
|
+
LEFT_CURLY_TYPES.include?(type)
|
87
88
|
end
|
88
89
|
|
89
90
|
def right_curly_brace?
|
data/lib/rubocop/ast/version.rb
CHANGED
data/lib/rubocop/ast.rb
CHANGED
@@ -27,6 +27,7 @@ require_relative 'ast/node/mixin/method_identifier_predicates'
|
|
27
27
|
require_relative 'ast/node/mixin/binary_operator_node'
|
28
28
|
require_relative 'ast/node/mixin/collection_node'
|
29
29
|
require_relative 'ast/node/mixin/conditional_node'
|
30
|
+
require_relative 'ast/node/mixin/constant_node'
|
30
31
|
require_relative 'ast/node/mixin/hash_element_node'
|
31
32
|
require_relative 'ast/node/mixin/method_dispatch_node'
|
32
33
|
require_relative 'ast/node/mixin/modifier_node'
|
@@ -59,8 +60,11 @@ require_relative 'ast/node/in_pattern_node'
|
|
59
60
|
require_relative 'ast/node/index_node'
|
60
61
|
require_relative 'ast/node/indexasgn_node'
|
61
62
|
require_relative 'ast/node/int_node'
|
63
|
+
require_relative 'ast/node/keyword_begin_node'
|
62
64
|
require_relative 'ast/node/keyword_splat_node'
|
63
65
|
require_relative 'ast/node/lambda_node'
|
66
|
+
require_relative 'ast/node/masgn_node'
|
67
|
+
require_relative 'ast/node/mlhs_node'
|
64
68
|
require_relative 'ast/node/module_node'
|
65
69
|
require_relative 'ast/node/next_node'
|
66
70
|
require_relative 'ast/node/op_asgn_node'
|
@@ -83,6 +87,7 @@ require_relative 'ast/node/dstr_node'
|
|
83
87
|
require_relative 'ast/node/super_node'
|
84
88
|
require_relative 'ast/node/symbol_node'
|
85
89
|
require_relative 'ast/node/until_node'
|
90
|
+
require_relative 'ast/node/var_node'
|
86
91
|
require_relative 'ast/node/when_node'
|
87
92
|
require_relative 'ast/node/while_node'
|
88
93
|
require_relative 'ast/node/yield_node'
|