rubocop-ast 1.41.0 → 1.43.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 724e2118bf289e457d58db38594035fb1888100577cbc82ca6e7352b2d952d24
|
4
|
+
data.tar.gz: 0f957ba53af55775cfa988490b2ea07db0022d9b3dba3d28c48a95aff64552ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db7476e8bff5a7357b8722d6a48fd185ef296e10c9e69de6e8efd76e5f281e7ad8e4c18303df1415c8219359f17fe860742fd12ae3be726f8acdeacf9afed84f
|
7
|
+
data.tar.gz: c06cf9bed363772ee88102f93685993025c03886d0f68b01d139d20c128fe4d3bd66707321431d559b75801ce84613f6c0ccf3bb19fad674482a377418134e53
|
@@ -109,14 +109,7 @@ module RuboCop
|
|
109
109
|
private
|
110
110
|
|
111
111
|
def ruby_ast(ruby)
|
112
|
-
|
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)
|
112
|
+
ProcessedSource.new(ruby, RUBY_VERSION.to_f, '(ruby)').ast
|
120
113
|
end
|
121
114
|
end
|
122
115
|
|
@@ -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
|
|
@@ -35,25 +35,21 @@ module RuboCop
|
|
35
35
|
INVALID_LEVELS = %i[error fatal].freeze
|
36
36
|
private_constant :INVALID_LEVELS
|
37
37
|
|
38
|
-
PARSER_ENGINES = %i[parser_whitequark parser_prism].freeze
|
38
|
+
PARSER_ENGINES = %i[default parser_whitequark parser_prism].freeze
|
39
39
|
private_constant :PARSER_ENGINES
|
40
40
|
|
41
41
|
attr_reader :path, :buffer, :ast, :comments, :tokens, :diagnostics,
|
42
42
|
:parser_error, :raw_source, :ruby_version, :parser_engine
|
43
43
|
|
44
|
-
def self.from_file(path, ruby_version, parser_engine: :
|
44
|
+
def self.from_file(path, ruby_version, parser_engine: :default)
|
45
45
|
file = File.read(path, mode: 'rb')
|
46
46
|
new(file, ruby_version, path, parser_engine: parser_engine)
|
47
47
|
end
|
48
48
|
|
49
49
|
def initialize(
|
50
|
-
source, ruby_version, path = nil, parser_engine: :
|
50
|
+
source, ruby_version, path = nil, parser_engine: :default, prism_result: nil
|
51
51
|
)
|
52
|
-
parser_engine = parser_engine
|
53
|
-
unless PARSER_ENGINES.include?(parser_engine)
|
54
|
-
raise ArgumentError, 'The keyword argument `parser_engine` accepts `parser_whitequark` ' \
|
55
|
-
"or `parser_prism`, but `#{parser_engine}` was passed."
|
56
|
-
end
|
52
|
+
parser_engine = normalize_parser_engine(parser_engine, ruby_version)
|
57
53
|
|
58
54
|
# Defaults source encoding to UTF-8, regardless of the encoding it has
|
59
55
|
# been read with, which could be non-utf8 depending on the default
|
@@ -307,11 +303,10 @@ module RuboCop
|
|
307
303
|
require 'parser/ruby34'
|
308
304
|
Parser::Ruby34
|
309
305
|
else
|
310
|
-
raise ArgumentError,
|
306
|
+
raise ArgumentError, 'RuboCop supports target Ruby versions 3.4 and below with ' \
|
307
|
+
"`parser`. Specified target Ruby version: #{ruby_version.inspect}"
|
311
308
|
end
|
312
309
|
when :parser_prism
|
313
|
-
require_prism
|
314
|
-
|
315
310
|
case ruby_version
|
316
311
|
when 3.3
|
317
312
|
require 'prism/translation/parser33'
|
@@ -319,6 +314,9 @@ module RuboCop
|
|
319
314
|
when 3.4
|
320
315
|
require 'prism/translation/parser34'
|
321
316
|
Prism::Translation::Parser34
|
317
|
+
when 3.5
|
318
|
+
require 'prism/translation/parser35'
|
319
|
+
Prism::Translation::Parser35
|
322
320
|
else
|
323
321
|
raise ArgumentError, 'RuboCop supports target Ruby versions 3.3 and above with Prism. ' \
|
324
322
|
"Specified target Ruby version: #{ruby_version.inspect}"
|
@@ -331,49 +329,17 @@ module RuboCop
|
|
331
329
|
when :parser_whitequark
|
332
330
|
RuboCop::AST::Builder
|
333
331
|
when :parser_prism
|
334
|
-
require_prism
|
335
|
-
require_relative 'builder_prism'
|
336
332
|
RuboCop::AST::BuilderPrism
|
337
333
|
end
|
338
334
|
end
|
339
335
|
|
340
|
-
# Prism is a native extension, a `LoadError` will be raised if linked to an incompatible
|
341
|
-
# Ruby version. Only raise if it really was caused by Prism not being present.
|
342
|
-
# rubocop:disable Metrics/MethodLength
|
343
|
-
def require_prism
|
344
|
-
require 'prism'
|
345
|
-
required_prism_version = '1.4.0'
|
346
|
-
if required_prism_version > Prism::VERSION
|
347
|
-
# While Prism is not yet a dependency, users may run with outdated versions that
|
348
|
-
# don't have all the parsers.
|
349
|
-
warn <<~MESSAGE
|
350
|
-
Error: Prism version #{Prism::VERSION} was loaded, but rubocop-ast requires #{required_prism_version}.
|
351
|
-
* If you're using Bundler and don't yet have `gem 'prism'` as a dependency, add it now.
|
352
|
-
* If you're using Bundler and already have `gem 'prism'` as a dependency, update it to the most recent version.
|
353
|
-
* If you don't use Bundler, run `gem update prism`.
|
354
|
-
MESSAGE
|
355
|
-
exit!
|
356
|
-
end
|
357
|
-
rescue LoadError => e
|
358
|
-
raise unless e.path == 'prism'
|
359
|
-
|
360
|
-
warn "Error: Unable to load Prism. Add `gem 'prism'` to your Gemfile."
|
361
|
-
exit!
|
362
|
-
end
|
363
|
-
# rubocop:enable Metrics/MethodLength
|
364
|
-
|
365
336
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
366
337
|
def create_parser(ruby_version, parser_engine, prism_result)
|
367
338
|
builder = builder_class(parser_engine).new
|
368
339
|
|
369
340
|
parser_class = parser_class(ruby_version, parser_engine)
|
370
341
|
|
371
|
-
|
372
|
-
# The `:parser` keyword argument cannot be used to switch parsers because older versions of
|
373
|
-
# Prism do not support it.
|
374
|
-
parser_switch_available = parser_class.instance_method(:initialize).parameters.assoc(:key)
|
375
|
-
|
376
|
-
parser_instance = if prism_result && parser_switch_available
|
342
|
+
parser_instance = if prism_result
|
377
343
|
# NOTE: Since it is intended for use with Ruby LSP, it targets only Prism.
|
378
344
|
# If there is no reuse of a pre-parsed result, such as in Ruby LSP,
|
379
345
|
# regular parsing with Prism occurs, and `else` branch will be executed.
|
@@ -397,6 +363,31 @@ module RuboCop
|
|
397
363
|
end
|
398
364
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
399
365
|
|
366
|
+
def normalize_parser_engine(parser_engine, ruby_version)
|
367
|
+
parser_engine = parser_engine.to_sym
|
368
|
+
unless PARSER_ENGINES.include?(parser_engine)
|
369
|
+
raise ArgumentError, 'The keyword argument `parser_engine` accepts `default`, ' \
|
370
|
+
"`parser_whitequark`, or `parser_prism`, but `#{parser_engine}` " \
|
371
|
+
'was passed.'
|
372
|
+
end
|
373
|
+
if parser_engine == :default
|
374
|
+
default_parser_engine(ruby_version)
|
375
|
+
else
|
376
|
+
parser_engine
|
377
|
+
end
|
378
|
+
end
|
379
|
+
|
380
|
+
# The Parser gem does not support Ruby 3.5 or later.
|
381
|
+
# It is also not fully compatible with Ruby 3.4 but for
|
382
|
+
# now respects using parser for backwards compatibility.
|
383
|
+
def default_parser_engine(ruby_version)
|
384
|
+
if ruby_version >= 3.4
|
385
|
+
:parser_prism
|
386
|
+
else
|
387
|
+
:parser_whitequark
|
388
|
+
end
|
389
|
+
end
|
390
|
+
|
400
391
|
def first_token_index(range_or_node)
|
401
392
|
begin_pos = source_range(range_or_node).begin_pos
|
402
393
|
sorted_tokens.bsearch_index { |token| token.begin_pos >= begin_pos }
|
data/lib/rubocop/ast/version.rb
CHANGED
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
|
|
@@ -92,6 +93,7 @@ require_relative 'ast/node/when_node'
|
|
92
93
|
require_relative 'ast/node/while_node'
|
93
94
|
require_relative 'ast/node/yield_node'
|
94
95
|
require_relative 'ast/builder'
|
96
|
+
require_relative 'ast/builder_prism'
|
95
97
|
require_relative 'ast/processed_source'
|
96
98
|
require_relative 'ast/rubocop_compatibility'
|
97
99
|
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.
|
4
|
+
version: 1.43.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
- Yuji Nakayama
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2025-03-
|
12
|
+
date: 2025-03-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: parser
|
@@ -25,6 +25,20 @@ dependencies:
|
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 3.3.7.2
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: prism
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.4'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.4'
|
28
42
|
description: " RuboCop's Node and NodePattern classes.\n"
|
29
43
|
email: rubocop@googlegroups.com
|
30
44
|
executables: []
|