rubocop-ast 1.41.0 → 1.42.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: d19f7e10e7b8402e4cd47676b246f8ada988fe6039f45ce339f99e4aec065955
|
4
|
+
data.tar.gz: e877a86b9566a395e5e4d8b0656d688670c051090900cc1f753922f4f285882d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2eae7d51990b5b02aef754cb28ded1563712df934b1903439cb84f9d67d4c9507186112739a12aaaa7fb4bec33b9226f32c62ac128e21124f4d171a31ee263e3
|
7
|
+
data.tar.gz: d7ab2ea49e961d91b556a385e77e3bc70f67168af0af26c582bd141737c22a81f1f73d4838855baa92ddb39b2751f266d2df496d279f96c44cd66c1481d5e153
|
@@ -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
|
|
@@ -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,7 +303,8 @@ 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
310
|
require_prism
|
@@ -319,6 +316,9 @@ module RuboCop
|
|
319
316
|
when 3.4
|
320
317
|
require 'prism/translation/parser34'
|
321
318
|
Prism::Translation::Parser34
|
319
|
+
when 3.5
|
320
|
+
require 'prism/translation/parser35'
|
321
|
+
Prism::Translation::Parser35
|
322
322
|
else
|
323
323
|
raise ArgumentError, 'RuboCop supports target Ruby versions 3.3 and above with Prism. ' \
|
324
324
|
"Specified target Ruby version: #{ruby_version.inspect}"
|
@@ -397,6 +397,31 @@ module RuboCop
|
|
397
397
|
end
|
398
398
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
399
399
|
|
400
|
+
def normalize_parser_engine(parser_engine, ruby_version)
|
401
|
+
parser_engine = parser_engine.to_sym
|
402
|
+
unless PARSER_ENGINES.include?(parser_engine)
|
403
|
+
raise ArgumentError, 'The keyword argument `parser_engine` accepts `default`, ' \
|
404
|
+
"`parser_whitequark`, or `parser_prism`, but `#{parser_engine}` " \
|
405
|
+
'was passed.'
|
406
|
+
end
|
407
|
+
if parser_engine == :default
|
408
|
+
default_parser_engine(ruby_version)
|
409
|
+
else
|
410
|
+
parser_engine
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
# The Parser gem does not support Ruby 3.5 or later.
|
415
|
+
# It is also not fully compatible with Ruby 3.4 but for
|
416
|
+
# now respects using parser for backwards compatibility.
|
417
|
+
def default_parser_engine(ruby_version)
|
418
|
+
if ruby_version >= 3.5
|
419
|
+
:parser_prism
|
420
|
+
else
|
421
|
+
:parser_whitequark
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
400
425
|
def first_token_index(range_or_node)
|
401
426
|
begin_pos = source_range(range_or_node).begin_pos
|
402
427
|
sorted_tokens.bsearch_index { |token| token.begin_pos >= begin_pos }
|
data/lib/rubocop/ast/version.rb
CHANGED
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.42.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
|