rubocop-ast 1.30.0 → 1.31.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubocop/ast/node.rb +2 -2
- data/lib/rubocop/ast/processed_source.rb +87 -53
- data/lib/rubocop/ast/token.rb +1 -1
- data/lib/rubocop/ast/traversal.rb +1 -1
- data/lib/rubocop/ast/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 960041ab1bf7cf5ce2543826319f44b9f8fa8b5170f08ea3404baa4aafbf79a2
|
4
|
+
data.tar.gz: 0a337f60bc1029e338d1050248bcc649b921e3d540faf4b7125743e047415eed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27eacafc5f797c0d155c42c03ff70ba20f6a768236780a03269ed973c4bc43270c3aedbf59acb57d1b4e025e07c13289ec4bc164cbf208207a8c31e2cdeeef52
|
7
|
+
data.tar.gz: 1610166d40d0440c62a93722e4c80bf041df7771b094179c78b0f9ba941aeed061882571199e62f360312117e752dc0738f0e93c24b4110ade93fb66a733ec3d
|
data/lib/rubocop/ast/node.rb
CHANGED
@@ -326,13 +326,13 @@ module RuboCop
|
|
326
326
|
# what class or module is this method/constant/etc definition in?
|
327
327
|
# returns nil if answer cannot be determined
|
328
328
|
ancestors = each_ancestor(:class, :module, :sclass, :casgn, :block)
|
329
|
-
result = ancestors.
|
329
|
+
result = ancestors.filter_map do |ancestor|
|
330
330
|
parent_module_name_part(ancestor) do |full_name|
|
331
331
|
return nil unless full_name
|
332
332
|
|
333
333
|
full_name
|
334
334
|
end
|
335
|
-
end.
|
335
|
+
end.reverse.join('::')
|
336
336
|
result.empty? ? 'Object' : result
|
337
337
|
end
|
338
338
|
|
@@ -15,15 +15,24 @@ module RuboCop
|
|
15
15
|
INVALID_LEVELS = %i[error fatal].freeze
|
16
16
|
private_constant :INVALID_LEVELS
|
17
17
|
|
18
|
+
PARSER_ENGINES = %i[parser_whitequark parser_prism].freeze
|
19
|
+
private_constant :PARSER_ENGINES
|
20
|
+
|
18
21
|
attr_reader :path, :buffer, :ast, :comments, :tokens, :diagnostics,
|
19
|
-
:parser_error, :raw_source, :ruby_version
|
22
|
+
:parser_error, :raw_source, :ruby_version, :parser_engine
|
20
23
|
|
21
|
-
def self.from_file(path, ruby_version)
|
24
|
+
def self.from_file(path, ruby_version, parser_engine: :parser_whitequark)
|
22
25
|
file = File.read(path, mode: 'rb')
|
23
|
-
new(file, ruby_version, path)
|
26
|
+
new(file, ruby_version, path, parser_engine: parser_engine)
|
24
27
|
end
|
25
28
|
|
26
|
-
def initialize(source, ruby_version, path = nil)
|
29
|
+
def initialize(source, ruby_version, path = nil, parser_engine: :parser_whitequark)
|
30
|
+
parser_engine = parser_engine.to_sym
|
31
|
+
unless PARSER_ENGINES.include?(parser_engine)
|
32
|
+
raise ArgumentError, 'The keyword argument `parser_engine` accepts `parser_whitequark` ' \
|
33
|
+
"or `parser_prism`, but `#{parser_engine}` was passed."
|
34
|
+
end
|
35
|
+
|
27
36
|
# Defaults source encoding to UTF-8, regardless of the encoding it has
|
28
37
|
# been read with, which could be non-utf8 depending on the default
|
29
38
|
# external encoding.
|
@@ -33,9 +42,10 @@ module RuboCop
|
|
33
42
|
@path = path
|
34
43
|
@diagnostics = []
|
35
44
|
@ruby_version = ruby_version
|
45
|
+
@parser_engine = parser_engine
|
36
46
|
@parser_error = nil
|
37
47
|
|
38
|
-
parse(source, ruby_version)
|
48
|
+
parse(source, ruby_version, parser_engine)
|
39
49
|
end
|
40
50
|
|
41
51
|
def ast_with_comments
|
@@ -193,7 +203,7 @@ module RuboCop
|
|
193
203
|
end
|
194
204
|
end
|
195
205
|
|
196
|
-
def parse(source, ruby_version)
|
206
|
+
def parse(source, ruby_version, parser_engine)
|
197
207
|
buffer_name = @path || STRING_SOURCE_NAME
|
198
208
|
@buffer = Parser::Source::Buffer.new(buffer_name, 1)
|
199
209
|
|
@@ -207,7 +217,7 @@ module RuboCop
|
|
207
217
|
return
|
208
218
|
end
|
209
219
|
|
210
|
-
@ast, @comments, @tokens = tokenize(create_parser(ruby_version))
|
220
|
+
@ast, @comments, @tokens = tokenize(create_parser(ruby_version, parser_engine))
|
211
221
|
end
|
212
222
|
|
213
223
|
def tokenize(parser)
|
@@ -227,58 +237,82 @@ module RuboCop
|
|
227
237
|
end
|
228
238
|
|
229
239
|
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
230
|
-
def parser_class(ruby_version)
|
231
|
-
case
|
232
|
-
when
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
240
|
+
def parser_class(ruby_version, parser_engine)
|
241
|
+
case parser_engine
|
242
|
+
when :parser_whitequark
|
243
|
+
case ruby_version
|
244
|
+
when 1.9
|
245
|
+
require 'parser/ruby19'
|
246
|
+
Parser::Ruby19
|
247
|
+
when 2.0
|
248
|
+
require 'parser/ruby20'
|
249
|
+
Parser::Ruby20
|
250
|
+
when 2.1
|
251
|
+
require 'parser/ruby21'
|
252
|
+
Parser::Ruby21
|
253
|
+
when 2.2
|
254
|
+
require 'parser/ruby22'
|
255
|
+
Parser::Ruby22
|
256
|
+
when 2.3
|
257
|
+
require 'parser/ruby23'
|
258
|
+
Parser::Ruby23
|
259
|
+
when 2.4
|
260
|
+
require 'parser/ruby24'
|
261
|
+
Parser::Ruby24
|
262
|
+
when 2.5
|
263
|
+
require 'parser/ruby25'
|
264
|
+
Parser::Ruby25
|
265
|
+
when 2.6
|
266
|
+
require 'parser/ruby26'
|
267
|
+
Parser::Ruby26
|
268
|
+
when 2.7
|
269
|
+
require 'parser/ruby27'
|
270
|
+
Parser::Ruby27
|
271
|
+
when 2.8, 3.0
|
272
|
+
require 'parser/ruby30'
|
273
|
+
Parser::Ruby30
|
274
|
+
when 3.1
|
275
|
+
require 'parser/ruby31'
|
276
|
+
Parser::Ruby31
|
277
|
+
when 3.2
|
278
|
+
require 'parser/ruby32'
|
279
|
+
Parser::Ruby32
|
280
|
+
when 3.3
|
281
|
+
require 'parser/ruby33'
|
282
|
+
Parser::Ruby33
|
283
|
+
when 3.4
|
284
|
+
require 'parser/ruby34'
|
285
|
+
Parser::Ruby34
|
286
|
+
else
|
287
|
+
raise ArgumentError, "RuboCop found unknown Ruby version: #{ruby_version.inspect}"
|
288
|
+
end
|
289
|
+
when :parser_prism
|
290
|
+
begin
|
291
|
+
require 'prism'
|
292
|
+
rescue LoadError
|
293
|
+
warn "Error: Unable to load Prism. Add `gem 'prism'` to your Gemfile."
|
294
|
+
exit!
|
295
|
+
end
|
296
|
+
|
297
|
+
case ruby_version
|
298
|
+
when 3.3
|
299
|
+
require 'prism/translation/parser33'
|
300
|
+
Prism::Translation::Parser33
|
301
|
+
when 3.4
|
302
|
+
require 'prism/translation/parser34'
|
303
|
+
Prism::Translation::Parser34
|
304
|
+
else
|
305
|
+
raise ArgumentError, 'RuboCop supports target Ruby versions 3.3 and above with Prism. ' \
|
306
|
+
"Specified target Ruby version: #{ruby_version.inspect}"
|
307
|
+
end
|
274
308
|
end
|
275
309
|
end
|
276
310
|
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
277
311
|
|
278
|
-
def create_parser(ruby_version)
|
312
|
+
def create_parser(ruby_version, parser_engine)
|
279
313
|
builder = RuboCop::AST::Builder.new
|
280
314
|
|
281
|
-
parser_class(ruby_version).new(builder).tap do |parser|
|
315
|
+
parser_class(ruby_version, parser_engine).new(builder).tap do |parser|
|
282
316
|
# On JRuby there's a risk that we hang in tokenize() if we
|
283
317
|
# don't set the all errors as fatal flag. The problem is caused by a bug
|
284
318
|
# in Racc that is discussed in issue #93 of the whitequark/parser
|
data/lib/rubocop/ast/token.rb
CHANGED
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.31.2
|
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:
|
13
|
+
date: 2024-03-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: parser
|
@@ -18,14 +18,14 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 3.
|
21
|
+
version: 3.3.0.4
|
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.
|
28
|
+
version: 3.3.0.4
|
29
29
|
description: " RuboCop's Node and NodePattern classes.\n"
|
30
30
|
email: rubocop@googlegroups.com
|
31
31
|
executables: []
|
@@ -149,14 +149,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
149
149
|
requirements:
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: 2.
|
152
|
+
version: 2.7.0
|
153
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
154
|
requirements:
|
155
155
|
- - ">="
|
156
156
|
- !ruby/object:Gem::Version
|
157
157
|
version: '0'
|
158
158
|
requirements: []
|
159
|
-
rubygems_version: 3.
|
159
|
+
rubygems_version: 3.5.3
|
160
160
|
signing_key:
|
161
161
|
specification_version: 4
|
162
162
|
summary: RuboCop tools to deal with Ruby code AST.
|