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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84c917625cddd9b79c0979e269fdd324f8119b9d2b3c6081fae0ef449669bea5
4
- data.tar.gz: 8d053cac9c670216326df54b5b7b6a8961bf89614defa16e93ad1c557a8b25a5
3
+ metadata.gz: 960041ab1bf7cf5ce2543826319f44b9f8fa8b5170f08ea3404baa4aafbf79a2
4
+ data.tar.gz: 0a337f60bc1029e338d1050248bcc649b921e3d540faf4b7125743e047415eed
5
5
  SHA512:
6
- metadata.gz: c95bd42a576592153d70f61367aafacd9677021515534a487706b736cc02cfcf717fc6db39e3df7212088301383cb7d60af9b929b4ca65b7baa5a66f5eca059e
7
- data.tar.gz: f0d99d3695e651ec10709dd729696a2b137c3b11603598164b433f61583218b16807c44ea1637ebe1922b496b8472795e4d54a4dc1312908f049e6f43b242ff8
6
+ metadata.gz: 27eacafc5f797c0d155c42c03ff70ba20f6a768236780a03269ed973c4bc43270c3aedbf59acb57d1b4e025e07c13289ec4bc164cbf208207a8c31e2cdeeef52
7
+ data.tar.gz: 1610166d40d0440c62a93722e4c80bf041df7771b094179c78b0f9ba941aeed061882571199e62f360312117e752dc0738f0e93c24b4110ade93fb66a733ec3d
@@ -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.map do |ancestor|
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.compact.reverse.join('::')
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 ruby_version
232
- when 1.9
233
- require 'parser/ruby19'
234
- Parser::Ruby19
235
- when 2.0
236
- require 'parser/ruby20'
237
- Parser::Ruby20
238
- when 2.1
239
- require 'parser/ruby21'
240
- Parser::Ruby21
241
- when 2.2
242
- require 'parser/ruby22'
243
- Parser::Ruby22
244
- when 2.3
245
- require 'parser/ruby23'
246
- Parser::Ruby23
247
- when 2.4
248
- require 'parser/ruby24'
249
- Parser::Ruby24
250
- when 2.5
251
- require 'parser/ruby25'
252
- Parser::Ruby25
253
- when 2.6
254
- require 'parser/ruby26'
255
- Parser::Ruby26
256
- when 2.7
257
- require 'parser/ruby27'
258
- Parser::Ruby27
259
- when 2.8, 3.0
260
- require 'parser/ruby30'
261
- Parser::Ruby30
262
- when 3.1
263
- require 'parser/ruby31'
264
- Parser::Ruby31
265
- when 3.2
266
- require 'parser/ruby32'
267
- Parser::Ruby32
268
- when 3.3
269
- require 'parser/ruby33'
270
- Parser::Ruby33
271
- else
272
- raise ArgumentError,
273
- "RuboCop found unknown Ruby version: #{ruby_version.inspect}"
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
@@ -83,7 +83,7 @@ module RuboCop
83
83
  end
84
84
 
85
85
  def left_curly_brace?
86
- type == :tLCURLY
86
+ type == :tLCURLY || type == :tLAMBEG
87
87
  end
88
88
 
89
89
  def right_curly_brace?
@@ -45,7 +45,7 @@ module RuboCop
45
45
  end # end
46
46
  RUBY
47
47
  aliases.each do |m|
48
- alias_method "on_#{m}", "on_#{type}"
48
+ alias_method :"on_#{m}", :"on_#{type}"
49
49
  end
50
50
  end
51
51
 
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module AST
5
5
  module Version
6
- STRING = '1.30.0'
6
+ STRING = '1.31.2'
7
7
  end
8
8
  end
9
9
  end
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.30.0
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: 2023-10-26 00:00:00.000000000 Z
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.2.1.0
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.2.1.0
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.6.0
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.4.10
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.