rubocop-ast 1.29.0 → 1.31.3

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: b08ce67ff41a6d40d8385735fe36ebe6fd90513f3cbafbd21afa4f9393a66f9a
4
- data.tar.gz: 24e6a84531e66531bcf5c358cfbed40815d1fd3f1d91e598a5b884a1971bb3c7
3
+ metadata.gz: 56067f459b491d4b3f10deb7f4d198b5ad9cffbc52739a53dec9d3b644c6b8a6
4
+ data.tar.gz: d45cf7be143799cea97c0af7c35e05d8ccdc7b5fc920ba05d2504bb1eacb745f
5
5
  SHA512:
6
- metadata.gz: 20a8ea979cb2335691b7b39c9986962edc2fe61667e712187e3904e2a984fc3327b38034eca64028a362724964e982d053a093432d3f7994edae592cd8f6fb83
7
- data.tar.gz: 59ab4c65c59d3407224147391e8b253c930da8add826c50553b433039057865aa1211d13e90061bb4e3a40ebb97184ea8d5698f3b4f5d0ff7c3c343d14a566bd
6
+ metadata.gz: c7f375ab38218879cf28118dd9b8144f2ce00832dc13aa6d23338adefaf531fbae4af141b9a9b1332a402b1d1c6e9105a1fe45ba1afe18c971aee0a713f2b695
7
+ data.tar.gz: 3d01a913bb5e333f8e605492574b2492238cf1208bac5b6a0fc0e880e76e0be391a6bf187c51ebdafbbef35f2702255b166cfe85e6a9ce7d0cedc4a868938c91
@@ -21,6 +21,24 @@ module RuboCop
21
21
  node_parts[0]
22
22
  end
23
23
 
24
+ # A shorthand for getting the first argument of this block.
25
+ # Equivalent to `arguments.first`.
26
+ #
27
+ # @return [Node, nil] the first argument of this block,
28
+ # or `nil` if there are no arguments
29
+ def first_argument
30
+ arguments[0]
31
+ end
32
+
33
+ # A shorthand for getting the last argument of this block.
34
+ # Equivalent to `arguments.last`.
35
+ #
36
+ # @return [Node, nil] the last argument of this block,
37
+ # or `nil` if there are no arguments
38
+ def last_argument
39
+ arguments[-1]
40
+ end
41
+
24
42
  # The arguments of this block.
25
43
  # Note that if the block has destructured arguments, `arguments` will
26
44
  # return a `mlhs` node, whereas `argument_list` will return only
@@ -81,7 +81,7 @@ module RuboCop
81
81
  (if? || unless?) && super
82
82
  end
83
83
 
84
- # Chacks whether the `if` node has nested `if` nodes in any of its
84
+ # Checks whether the `if` node has nested `if` nodes in any of its
85
85
  # branches.
86
86
  #
87
87
  # @note This performs a shallow search.
@@ -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
 
@@ -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.0.
5
+ # Generated by: oedipus_lex version 2.6.1.
6
6
  # Source: lib/rubocop/ast/node_pattern/lexer.rex
7
7
  #++
8
8
 
@@ -207,7 +207,7 @@ module RuboCop
207
207
  include ForbidInSeqHead
208
208
 
209
209
  def arity
210
- min, max = children.map(&:arity_range).map(&:minmax).transpose.map(&:sum)
210
+ min, max = children.map { |child| child.arity_range.minmax }.transpose.map(&:sum)
211
211
  min == max ? min || 0 : min..max # NOTE: || 0 for empty case, where min == max == nil.
212
212
  end
213
213
 
@@ -223,7 +223,7 @@ module RuboCop
223
223
  # Node class for `{ ... }`
224
224
  class Union < Node
225
225
  def arity
226
- minima, maxima = children.map(&:arity_range).map(&:minmax).transpose
226
+ minima, maxima = children.map { |child| child.arity_range.minmax }.transpose
227
227
  min = minima.min
228
228
  max = maxima.max
229
229
  min == max ? min : min..max
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  #
3
3
  # DO NOT MODIFY!!!!
4
- # This file is automatically generated by Racc 1.6.2
4
+ # This file is automatically generated by Racc 1.7.1
5
5
  # from Racc grammar file "".
6
6
  #
7
7
 
@@ -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
 
@@ -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,13 +203,13 @@ 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
 
200
210
  begin
201
211
  @buffer.source = source
202
- rescue EncodingError => e
212
+ rescue EncodingError, Parser::UnknownEncodingInMagicComment => e
203
213
  @parser_error = e
204
214
  @ast = nil
205
215
  @comments = []
@@ -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?
@@ -38,14 +38,14 @@ module RuboCop
38
38
  body: self.body(signature, arity_check))
39
39
  type, *aliases = type
40
40
  lineno = caller_locations(1, 1).first.lineno
41
- module_eval(<<~RUBY, __FILE__, lineno) # rubocop:disable Style/EvalWithLocation
41
+ module_eval(<<~RUBY, __FILE__, lineno)
42
42
  def on_#{type}(node) # def on_send(node)
43
43
  #{body} # # body ...
44
44
  nil # nil
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.29.0'
6
+ STRING = '1.31.3'
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.29.0
4
+ version: 1.31.3
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-06-01 00:00:00.000000000 Z
13
+ date: 2024-04-29 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.1.0
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.1.0
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.1
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.