rubocop-ast 1.46.0 → 1.49.1

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: 2b94b9545a7aceaf8b52e8e6b8713df63fe1113c4040fd5f92563438c0307d21
4
- data.tar.gz: 6db23c373003f60f0faf0f48ff1a4cb7d086f36820e7f5e732a147eea0d22f98
3
+ metadata.gz: aad4bf15828f1db50f117c1a983e1f4c7f0cff233878a7f1a1686416ab21feff
4
+ data.tar.gz: 8ac8ad74b061c5fcd733e21420068edc69d0a9bfba532dc766e01dbb80be5c40
5
5
  SHA512:
6
- metadata.gz: 3a0fb03bcb60b82177efefcf2146d1512c50f9791f094769d64ae7c87899e9984ce41eebdb1fc8f6d8c40b287e42621f6d4bd9fdde23fe9884ebc0dd2202b5ae
7
- data.tar.gz: 8fd5e39ac28109336a207edfedf5fc6b782ede8da4594cfdd1faf41e8e9df4d59a17716e1ea55121c575514d17fce9e0b3071ab98ecc54b007f66af8f002f560
6
+ metadata.gz: 75f3882c819f2e10f7ef893481fbe9feddedfcdc91678c1c695d6ef36d94798dedf5667427cbfc6c022494e7e0c9581f54b4e1dcc9f05f2aea677668fe645b04
7
+ data.tar.gz: 94b37b0490cbf1ab81ab0c4c98a5bd8e6037b6ae5210af6ba2cbd23d4a263a3e4cfccad3f99fe621a6ab62d8356fc007fd066adb2d2379e02f5b07580ef2b2d4
data/README.md CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/rubocop-ast.svg)](https://badge.fury.io/rb/rubocop-ast)
4
4
  [![CI](https://github.com/rubocop/rubocop-ast/actions/workflows/rubocop.yml/badge.svg)](https://github.com/rubocop/rubocop-ast/actions/workflows/rubocop.yml)
5
- [![Test Coverage](https://api.codeclimate.com/v1/badges/a29666e6373bc41bc0a9/test_coverage)](https://codeclimate.com/github/rubocop/rubocop-ast/test_coverage)
6
- [![Maintainability](https://api.codeclimate.com/v1/badges/a29666e6373bc41bc0a9/maintainability)](https://codeclimate.com/github/rubocop/rubocop-ast/maintainability)
7
5
 
8
6
  Contains the classes needed by [RuboCop](https://github.com/rubocop/rubocop) to deal with Ruby's AST, in particular:
9
7
 
@@ -32,7 +32,7 @@ module RuboCop
32
32
  #
33
33
  # @return [Parser::Source::Range] the source range for the method name or keyword
34
34
  def selector
35
- if loc.respond_to? :keyword
35
+ if loc?(:keyword)
36
36
  loc.keyword
37
37
  else
38
38
  loc.selector
@@ -65,6 +65,7 @@ module RuboCop
65
65
  # arguments
66
66
  module WrappedArguments
67
67
  include ParameterizedNode
68
+
68
69
  # @return [Array] The arguments of the node.
69
70
  def arguments
70
71
  first = children.first
@@ -108,6 +108,13 @@ module RuboCop
108
108
  rational: :numeric,
109
109
  complex: :numeric,
110
110
 
111
+ str: :any_str,
112
+ dstr: :any_str,
113
+ xstr: :any_str,
114
+
115
+ sym: :any_sym,
116
+ dsym: :any_sym,
117
+
111
118
  irange: :range,
112
119
  erange: :range,
113
120
 
@@ -547,6 +554,14 @@ module RuboCop
547
554
  GROUP_FOR_TYPE[type] == :any_match_pattern
548
555
  end
549
556
 
557
+ def any_str_type?
558
+ GROUP_FOR_TYPE[type] == :any_str
559
+ end
560
+
561
+ def any_sym_type?
562
+ GROUP_FOR_TYPE[type] == :any_sym
563
+ end
564
+
550
565
  def guard_clause?
551
566
  node = operator_keyword? ? rhs : self
552
567
 
@@ -26,6 +26,12 @@ module RuboCop
26
26
  var
27
27
  end
28
28
 
29
+ # Returns currently bound variable names
30
+ # @return [Array<String>] variable names that are currently bound
31
+ def bound_variables
32
+ @bound.values
33
+ end
34
+
29
35
  # Yields for each branch of the given union, forbidding unification of
30
36
  # bindings which only appear in a subset of the union.
31
37
  def union_bind(enum) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
@@ -73,7 +73,7 @@ module RuboCop
73
73
  def visit_intersection
74
74
  multiple_access(:intersection) do
75
75
  node.children.map { |child| compile(child) }
76
- .join(' && ')
76
+ .join(' && ')
77
77
  end
78
78
  end
79
79
 
@@ -85,16 +85,21 @@ module RuboCop
85
85
  end
86
86
  end
87
87
 
88
- def visit_any_order
88
+ def visit_any_order # rubocop:disable Metrics/AbcSize
89
89
  within_loop do
90
90
  compiler.with_temp_variables do |matched|
91
+ bound_before = compiler.binding.bound_variables
91
92
  case_terms = compile_any_order_branches(matched)
92
93
  else_code, init = compile_any_order_else
93
94
  term = "#{compile_case(case_terms, else_code)} && #{compile_loop_advance}"
94
95
 
96
+ # Initialize unification variables before the loop to persist across iterations
97
+ newly_bound = compiler.binding.bound_variables - bound_before
98
+ unify_init = compile_unify_init(newly_bound)
99
+
95
100
  all_matched_check = "&&\n#{matched}.size == #{node.term_nodes.size}" if node.rest_node
96
101
  <<~RUBY
97
- (#{init}#{matched} = {}; true) &&
102
+ (#{init}#{unify_init}#{matched} = {}; true) &&
98
103
  #{compile_loop(term)} #{all_matched_check} \\
99
104
  RUBY
100
105
  end
@@ -412,6 +417,13 @@ module RuboCop
412
417
  end
413
418
  @in_sync = sub_compilers.all?(&:in_sync)
414
419
  end
420
+
421
+ # Generate initialization code for unification variables
422
+ # @param newly_bound [Array<String>] variable names that were newly bound
423
+ # @return [String] initialization code
424
+ def compile_unify_init(newly_bound)
425
+ newly_bound.map { |var| "#{var} = nil; " }.join
426
+ end
415
427
  end
416
428
  end
417
429
  end
@@ -10,6 +10,7 @@ module RuboCop
10
10
  # /docs/modules/ROOT/pages/node_pattern.adoc
11
11
  class Compiler
12
12
  extend SimpleForwardable
13
+
13
14
  attr_reader :captures, :named_parameters, :positional_parameters, :binding
14
15
 
15
16
  def initialize
@@ -21,7 +21,7 @@ macros
21
21
  rules
22
22
  /\s+/
23
23
  /:(#{SYMBOL_NAME})/o { emit :tSYMBOL, &:to_sym }
24
- /"(.+?)"/ { emit :tSTRING }
24
+ /"(.*?)"/ { emit :tSTRING }
25
25
  /[-+]?\d+\.\d+/ { emit :tNUMBER, &:to_f }
26
26
  /[-+]?\d+/ { emit :tNUMBER, &:to_i }
27
27
  /#{Regexp.union(
@@ -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.2.
5
+ # Generated by: oedipus_lex version 2.6.3.
6
6
  # Source: lib/rubocop/ast/node_pattern/lexer.rex
7
7
  #++
8
8
 
@@ -122,7 +122,7 @@ class RuboCop::AST::NodePattern::LexerRex
122
122
  # do nothing
123
123
  when ss.skip(/:(#{SYMBOL_NAME})/o) then
124
124
  action { emit :tSYMBOL, &:to_sym }
125
- when ss.skip(/"(.+?)"/) then
125
+ when ss.skip(/"(.*?)"/) then
126
126
  action { emit :tSTRING }
127
127
  when ss.skip(/[-+]?\d+\.\d+/) then
128
128
  action { emit :tNUMBER, &:to_f }
@@ -24,6 +24,8 @@ module RuboCop
24
24
  # - With no block and no captures: #match returns `true`.
25
25
  #
26
26
  class NodePattern
27
+ class Invalid < StandardError; end
28
+
27
29
  # Helpers for defining methods based on a pattern string
28
30
  module Macros
29
31
  # Define a method which applies a pattern to an AST node
@@ -50,7 +52,6 @@ module RuboCop
50
52
 
51
53
  extend SimpleForwardable
52
54
  include MethodDefiner
53
- Invalid = Class.new(StandardError)
54
55
 
55
56
  VAR = 'node'
56
57
 
@@ -310,14 +310,13 @@ module RuboCop
310
310
  when :parser_prism
311
311
  case ruby_version
312
312
  when 3.3
313
- require 'prism/translation/parser33'
314
313
  Prism::Translation::Parser33
315
314
  when 3.4
316
- require 'prism/translation/parser34'
317
315
  Prism::Translation::Parser34
318
- when 3.5
319
- require 'prism/translation/parser35'
320
- Prism::Translation::Parser35
316
+ when 3.5, 4.0
317
+ Prism::Translation::Parser40
318
+ when 4.1
319
+ Prism::Translation::Parser41
321
320
  else
322
321
  raise ArgumentError, 'RuboCop supports target Ruby versions 3.3 and above with Prism. ' \
323
322
  "Specified target Ruby version: #{ruby_version.inspect}"
@@ -79,13 +79,14 @@ module RuboCop
79
79
  end
80
80
  private_constant :CallbackCompiler
81
81
  extend CallbackCompiler
82
+
82
83
  send_code = CallbackCompiler::SEND
83
84
 
84
85
  ### children count == 0
85
86
  no_children = %i[true false nil self cbase zsuper redo retry
86
87
  forward_args forwarded_args match_nil_pattern
87
88
  forward_arg forwarded_restarg forwarded_kwrestarg
88
- lambda empty_else kwnilarg
89
+ lambda empty_else kwnilarg blocknilarg
89
90
  __FILE__ __LINE__ __ENCODING__]
90
91
 
91
92
  ### children count == 0..1
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module AST
5
5
  module Version
6
- STRING = '1.46.0'
6
+ STRING = '1.49.1'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-ast
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.46.0
4
+ version: 1.49.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
8
8
  - Jonas Arvidsson
9
9
  - Yuji Nakayama
10
- autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2025-07-16 00:00:00.000000000 Z
12
+ date: 1980-01-02 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: parser
@@ -32,14 +31,14 @@ dependencies:
32
31
  requirements:
33
32
  - - "~>"
34
33
  - !ruby/object:Gem::Version
35
- version: '1.4'
34
+ version: '1.7'
36
35
  type: :runtime
37
36
  prerelease: false
38
37
  version_requirements: !ruby/object:Gem::Requirement
39
38
  requirements:
40
39
  - - "~>"
41
40
  - !ruby/object:Gem::Version
42
- version: '1.4'
41
+ version: '1.7'
43
42
  description: " RuboCop's Node and NodePattern classes.\n"
44
43
  email: rubocop@googlegroups.com
45
44
  executables: []
@@ -163,7 +162,6 @@ metadata:
163
162
  documentation_uri: https://docs.rubocop.org/rubocop-ast/
164
163
  bug_tracker_uri: https://github.com/rubocop/rubocop-ast/issues
165
164
  rubygems_mfa_required: 'true'
166
- post_install_message:
167
165
  rdoc_options: []
168
166
  require_paths:
169
167
  - lib
@@ -178,8 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
176
  - !ruby/object:Gem::Version
179
177
  version: '0'
180
178
  requirements: []
181
- rubygems_version: 3.5.11
182
- signing_key:
179
+ rubygems_version: 4.0.3
183
180
  specification_version: 4
184
181
  summary: RuboCop tools to deal with Ruby code AST.
185
182
  test_files: []