rubocop-ast 1.29.0 → 1.31.0

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: e155ad03b7e113e566024f6e7618bd143831a7bcf238aa5d263eccd66d511bf1
4
+ data.tar.gz: ab734ac50a5888e3623b87f79824c489fe2406ae60e885092a000ecdabd52438
5
5
  SHA512:
6
- metadata.gz: 20a8ea979cb2335691b7b39c9986962edc2fe61667e712187e3904e2a984fc3327b38034eca64028a362724964e982d053a093432d3f7994edae592cd8f6fb83
7
- data.tar.gz: 59ab4c65c59d3407224147391e8b253c930da8add826c50553b433039057865aa1211d13e90061bb4e3a40ebb97184ea8d5698f3b4f5d0ff7c3c343d14a566bd
6
+ metadata.gz: a939ed43023a1cd7b408331f54d33c2ce03e3adbb6f43ee4ef1916da3455a5372c2d1560a4d88f30e64d37255656d93cfaf6d6ba08617b247e6af4c8d9a9c0d8
7
+ data.tar.gz: 697372a43782fb445340e3738ae88fd68710e85fb8dd75d8a7045056073750842339397435beb0a84a006315df99bba002bee438bc5074450b1eecf368c91eee
@@ -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.2.
6
6
  # Source: lib/rubocop/ast/node_pattern/lexer.rex
7
7
  #++
8
8
 
@@ -70,7 +70,6 @@ class RuboCop::AST::NodePattern::LexerRex
70
70
  yield
71
71
  end
72
72
 
73
-
74
73
  ##
75
74
  # The current scanner class. Must be overridden in subclasses.
76
75
 
@@ -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,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.6.2
5
- # from Racc grammar file "".
4
+ # This file is automatically generated by Racc 1.7.3
5
+ # from Racc grammar file "parser.y".
6
6
  #
7
7
 
8
8
  require 'racc/parser.rb'
@@ -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,23 @@ 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
+ unless PARSER_ENGINES.include?(parser_engine)
31
+ raise ArgumentError, 'The keyword argument `parser_engine` accepts ' \
32
+ "`parser` or `parser_prism`, but `#{parser_engine}` was passed."
33
+ end
34
+
27
35
  # Defaults source encoding to UTF-8, regardless of the encoding it has
28
36
  # been read with, which could be non-utf8 depending on the default
29
37
  # external encoding.
@@ -33,9 +41,10 @@ module RuboCop
33
41
  @path = path
34
42
  @diagnostics = []
35
43
  @ruby_version = ruby_version
44
+ @parser_engine = parser_engine
36
45
  @parser_error = nil
37
46
 
38
- parse(source, ruby_version)
47
+ parse(source, ruby_version, parser_engine)
39
48
  end
40
49
 
41
50
  def ast_with_comments
@@ -193,7 +202,7 @@ module RuboCop
193
202
  end
194
203
  end
195
204
 
196
- def parse(source, ruby_version)
205
+ def parse(source, ruby_version, parser_engine)
197
206
  buffer_name = @path || STRING_SOURCE_NAME
198
207
  @buffer = Parser::Source::Buffer.new(buffer_name, 1)
199
208
 
@@ -207,7 +216,7 @@ module RuboCop
207
216
  return
208
217
  end
209
218
 
210
- @ast, @comments, @tokens = tokenize(create_parser(ruby_version))
219
+ @ast, @comments, @tokens = tokenize(create_parser(ruby_version, parser_engine))
211
220
  end
212
221
 
213
222
  def tokenize(parser)
@@ -227,58 +236,77 @@ module RuboCop
227
236
  end
228
237
 
229
238
  # 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}"
239
+ def parser_class(ruby_version, parser_engine)
240
+ case parser_engine
241
+ when :parser_whitequark
242
+ case ruby_version
243
+ when 1.9
244
+ require 'parser/ruby19'
245
+ Parser::Ruby19
246
+ when 2.0
247
+ require 'parser/ruby20'
248
+ Parser::Ruby20
249
+ when 2.1
250
+ require 'parser/ruby21'
251
+ Parser::Ruby21
252
+ when 2.2
253
+ require 'parser/ruby22'
254
+ Parser::Ruby22
255
+ when 2.3
256
+ require 'parser/ruby23'
257
+ Parser::Ruby23
258
+ when 2.4
259
+ require 'parser/ruby24'
260
+ Parser::Ruby24
261
+ when 2.5
262
+ require 'parser/ruby25'
263
+ Parser::Ruby25
264
+ when 2.6
265
+ require 'parser/ruby26'
266
+ Parser::Ruby26
267
+ when 2.7
268
+ require 'parser/ruby27'
269
+ Parser::Ruby27
270
+ when 2.8, 3.0
271
+ require 'parser/ruby30'
272
+ Parser::Ruby30
273
+ when 3.1
274
+ require 'parser/ruby31'
275
+ Parser::Ruby31
276
+ when 3.2
277
+ require 'parser/ruby32'
278
+ Parser::Ruby32
279
+ when 3.3
280
+ require 'parser/ruby33'
281
+ Parser::Ruby33
282
+ when 3.4
283
+ require 'parser/ruby34'
284
+ Parser::Ruby34
285
+ else
286
+ raise ArgumentError, "RuboCop found unknown Ruby version: #{ruby_version.inspect}"
287
+ end
288
+ when :parser_prism
289
+ require 'prism'
290
+
291
+ case ruby_version
292
+ when 3.3
293
+ require 'prism/translation/parser33'
294
+ Prism::Translation::Parser33
295
+ when 3.4
296
+ require 'prism/translation/parser34'
297
+ Prism::Translation::Parser34
298
+ else
299
+ raise ArgumentError, 'RuboCop supports target Ruby versions 3.3 and above with Prism. ' \
300
+ "Specified target Ruby version: #{ruby_version.inspect}"
301
+ end
274
302
  end
275
303
  end
276
304
  # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
277
305
 
278
- def create_parser(ruby_version)
306
+ def create_parser(ruby_version, parser_engine)
279
307
  builder = RuboCop::AST::Builder.new
280
308
 
281
- parser_class(ruby_version).new(builder).tap do |parser|
309
+ parser_class(ruby_version, parser_engine).new(builder).tap do |parser|
282
310
  # On JRuby there's a risk that we hang in tokenize() if we
283
311
  # don't set the all errors as fatal flag. The problem is caused by a bug
284
312
  # 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.29.0'
6
+ STRING = '1.31.0'
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.0
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-02-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: parser
@@ -18,14 +18,28 @@ 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
+ - !ruby/object:Gem::Dependency
30
+ name: prism
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 0.24.0
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 0.24.0
29
43
  description: " RuboCop's Node and NodePattern classes.\n"
30
44
  email: rubocop@googlegroups.com
31
45
  executables: []
@@ -149,14 +163,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
149
163
  requirements:
150
164
  - - ">="
151
165
  - !ruby/object:Gem::Version
152
- version: 2.6.0
166
+ version: 2.7.0
153
167
  required_rubygems_version: !ruby/object:Gem::Requirement
154
168
  requirements:
155
169
  - - ">="
156
170
  - !ruby/object:Gem::Version
157
171
  version: '0'
158
172
  requirements: []
159
- rubygems_version: 3.4.1
173
+ rubygems_version: 3.3.7
160
174
  signing_key:
161
175
  specification_version: 4
162
176
  summary: RuboCop tools to deal with Ruby code AST.