rubocop-ast 1.31.3 → 1.32.0
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 +4 -4
- data/lib/rubocop/ast/builder.rb +1 -0
- data/lib/rubocop/ast/node/array_node.rb +5 -1
- data/lib/rubocop/ast/node/mixin/basic_literal_node.rb +1 -1
- data/lib/rubocop/ast/node/mixin/numeric_node.rb +1 -1
- data/lib/rubocop/ast/node/rational_node.rb +13 -0
- data/lib/rubocop/ast/node.rb +27 -19
- data/lib/rubocop/ast/node_pattern/compiler/binding.rb +3 -3
- data/lib/rubocop/ast/node_pattern/compiler/sequence_subcompiler.rb +2 -3
- data/lib/rubocop/ast/node_pattern/lexer.rex.rb +1 -2
- data/lib/rubocop/ast/node_pattern/node.rb +0 -1
- data/lib/rubocop/ast/node_pattern/parser.racc.rb +2 -2
- data/lib/rubocop/ast/processed_source.rb +2 -6
- data/lib/rubocop/ast/version.rb +1 -1
- data/lib/rubocop/ast.rb +1 -1
- metadata +4 -4
- data/lib/rubocop/ast/ext/range_min_max.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 173a6045b809d07aa80668e58d0967307e91573aea40a8674217b128450962cc
|
4
|
+
data.tar.gz: 6343ce59279962843711b4167e907193018a48333be31ae418ce10ffed450038
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35e6bbed1b028cb4cf9c2b775fdf676b607a913d2574059422c28f7ca4b7ccfe39c70d3ff72310af612ca678503b20d62a769d638037e956e800f1aaf28c45b8
|
7
|
+
data.tar.gz: 18144f00ba89f4879c95588236f3ffc5aaca1f6993dd2ba8152b34b18c0f96c3e8434ab8cc4c1392f4235af503068018608477b4772dcc6e041616357482440f
|
data/lib/rubocop/ast/builder.rb
CHANGED
@@ -17,7 +17,11 @@ module RuboCop
|
|
17
17
|
# @return [Array<Node>] an array of value nodes
|
18
18
|
alias values children
|
19
19
|
|
20
|
-
#
|
20
|
+
# Calls the given block for each `value` node in the `array` literal.
|
21
|
+
# If no block is given, an `Enumerator` is returned.
|
22
|
+
#
|
23
|
+
# @return [self] if a block is given
|
24
|
+
# @return [Enumerator] if no block is given
|
21
25
|
def each_value(&block)
|
22
26
|
return to_enum(__method__) unless block
|
23
27
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module RuboCop
|
4
4
|
module AST
|
5
|
-
# Common functionality for primitive numeric nodes: `int`, `float`,
|
5
|
+
# Common functionality for primitive numeric nodes: `int`, `float`, `rational`...
|
6
6
|
module NumericNode
|
7
7
|
SIGN_REGEX = /\A[+-]/.freeze
|
8
8
|
private_constant :SIGN_REGEX
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module AST
|
5
|
+
# A node extension for `rational` nodes. This will be used in place of a plain
|
6
|
+
# node when the builder constructs the AST, making its methods available to
|
7
|
+
# all `rational` nodes within RuboCop.
|
8
|
+
class RationalNode < Node
|
9
|
+
include BasicLiteralNode
|
10
|
+
include NumericNode
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/rubocop/ast/node.rb
CHANGED
@@ -88,6 +88,27 @@ module RuboCop
|
|
88
88
|
EMPTY_PROPERTIES = {}.freeze
|
89
89
|
private_constant :EMPTY_CHILDREN, :EMPTY_PROPERTIES
|
90
90
|
|
91
|
+
# Define a +recursive_?+ predicate method for the given node kind.
|
92
|
+
private_class_method def self.def_recursive_literal_predicate(kind) # rubocop:disable Metrics/MethodLength
|
93
|
+
recursive_kind = "recursive_#{kind}?"
|
94
|
+
kind_filter = "#{kind}?"
|
95
|
+
|
96
|
+
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
97
|
+
def #{recursive_kind} # def recursive_literal?
|
98
|
+
case type # case type
|
99
|
+
when :send # when :send
|
100
|
+
LITERAL_RECURSIVE_METHODS.include?(method_name) && # LITERAL_RECURSIVE_METHODS.include?(method_name) &&
|
101
|
+
receiver.send(:#{recursive_kind}) && # receiver.send(:recursive_literal?) &&
|
102
|
+
arguments.all?(&:#{recursive_kind}) # arguments.all?(&:recursive_literal?)
|
103
|
+
when LITERAL_RECURSIVE_TYPES # when LITERAL_RECURSIVE_TYPES
|
104
|
+
children.compact.all?(&:#{recursive_kind}) # children.compact.all?(&:recursive_literal?)
|
105
|
+
else # else
|
106
|
+
send(:#{kind_filter}) # send(:literal?)
|
107
|
+
end # end
|
108
|
+
end # end
|
109
|
+
RUBY
|
110
|
+
end
|
111
|
+
|
91
112
|
# @see https://www.rubydoc.info/gems/ast/AST/Node:initialize
|
92
113
|
def initialize(type, children = EMPTY_CHILDREN, properties = EMPTY_PROPERTIES)
|
93
114
|
@mutable_attributes = {}
|
@@ -380,22 +401,11 @@ module RuboCop
|
|
380
401
|
IMMUTABLE_LITERALS.include?(type)
|
381
402
|
end
|
382
403
|
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
when :send
|
389
|
-
LITERAL_RECURSIVE_METHODS.include?(method_name) &&
|
390
|
-
receiver.send(recursive_kind) &&
|
391
|
-
arguments.all?(&recursive_kind)
|
392
|
-
when LITERAL_RECURSIVE_TYPES
|
393
|
-
children.compact.all?(&recursive_kind)
|
394
|
-
else
|
395
|
-
send(kind_filter)
|
396
|
-
end
|
397
|
-
end
|
398
|
-
end
|
404
|
+
# @!macro [attach] def_recursive_literal_predicate
|
405
|
+
# @!method recursive_$1?
|
406
|
+
# @return [Boolean]
|
407
|
+
def_recursive_literal_predicate :literal
|
408
|
+
def_recursive_literal_predicate :basic_literal
|
399
409
|
|
400
410
|
def variable?
|
401
411
|
VARIABLES.include?(type)
|
@@ -547,8 +557,7 @@ module RuboCop
|
|
547
557
|
# So, does the return value of this node matter? If we changed it to
|
548
558
|
# `(...; nil)`, might that affect anything?
|
549
559
|
#
|
550
|
-
# rubocop:disable Metrics/MethodLength
|
551
|
-
def value_used?
|
560
|
+
def value_used? # rubocop:disable Metrics/MethodLength
|
552
561
|
# Be conservative and return true if we're not sure.
|
553
562
|
return false if parent.nil?
|
554
563
|
|
@@ -569,7 +578,6 @@ module RuboCop
|
|
569
578
|
true
|
570
579
|
end
|
571
580
|
end
|
572
|
-
# rubocop:enable Metrics/MethodLength
|
573
581
|
|
574
582
|
# Some expressions are evaluated for their value, some for their side
|
575
583
|
# effects, and some for both.
|
@@ -26,8 +26,9 @@ module RuboCop
|
|
26
26
|
var
|
27
27
|
end
|
28
28
|
|
29
|
-
#
|
30
|
-
|
29
|
+
# Yields for each branch of the given union, forbidding unification of
|
30
|
+
# bindings which only appear in a subset of the union.
|
31
|
+
def union_bind(enum) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
31
32
|
# We need to reset @bound before each branch is processed.
|
32
33
|
# Moreover we need to keep track of newly encountered wildcards.
|
33
34
|
# Var `newly_bound_intersection` will hold those that are encountered
|
@@ -62,7 +63,6 @@ module RuboCop
|
|
62
63
|
|
63
64
|
result
|
64
65
|
end
|
65
|
-
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
66
66
|
|
67
67
|
private
|
68
68
|
|
@@ -13,8 +13,8 @@ module RuboCop
|
|
13
13
|
# Doc on how this fits in the compiling process:
|
14
14
|
# /docs/modules/ROOT/pages/node_pattern.adoc
|
15
15
|
#
|
16
|
-
# rubocop:disable Metrics/ClassLength
|
17
|
-
|
16
|
+
class SequenceSubcompiler < Subcompiler # rubocop:disable Metrics/ClassLength
|
17
|
+
# Shift of 1 from standard Ruby indices
|
18
18
|
DELTA = 1
|
19
19
|
POSITIVE = :positive?.to_proc
|
20
20
|
private_constant :POSITIVE
|
@@ -413,7 +413,6 @@ module RuboCop
|
|
413
413
|
@in_sync = sub_compilers.all?(&:in_sync)
|
414
414
|
end
|
415
415
|
end
|
416
|
-
# rubocop:enable Metrics/ClassLength
|
417
416
|
end
|
418
417
|
end
|
419
418
|
end
|
@@ -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.
|
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
|
|
@@ -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.
|
5
|
-
# from Racc grammar file "".
|
4
|
+
# This file is automatically generated by Racc 1.8.1
|
5
|
+
# from Racc grammar file "parser.y".
|
6
6
|
#
|
7
7
|
|
8
8
|
require 'racc/parser.rb'
|
@@ -2,13 +2,12 @@
|
|
2
2
|
|
3
3
|
require 'digest/sha1'
|
4
4
|
|
5
|
-
# rubocop:disable Metrics/ClassLength
|
6
5
|
module RuboCop
|
7
6
|
module AST
|
8
7
|
# ProcessedSource contains objects which are generated by Parser
|
9
8
|
# and other information such as disabled lines for cops.
|
10
9
|
# It also provides a convenient way to access source lines.
|
11
|
-
class ProcessedSource
|
10
|
+
class ProcessedSource # rubocop:disable Metrics/ClassLength
|
12
11
|
# @api private
|
13
12
|
STRING_SOURCE_NAME = '(string)'
|
14
13
|
|
@@ -236,8 +235,7 @@ module RuboCop
|
|
236
235
|
[ast, comments, tokens]
|
237
236
|
end
|
238
237
|
|
239
|
-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
240
|
-
def parser_class(ruby_version, parser_engine)
|
238
|
+
def parser_class(ruby_version, parser_engine) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
241
239
|
case parser_engine
|
242
240
|
when :parser_whitequark
|
243
241
|
case ruby_version
|
@@ -307,7 +305,6 @@ module RuboCop
|
|
307
305
|
end
|
308
306
|
end
|
309
307
|
end
|
310
|
-
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
311
308
|
|
312
309
|
def create_parser(ruby_version, parser_engine)
|
313
310
|
builder = RuboCop::AST::Builder.new
|
@@ -345,4 +342,3 @@ module RuboCop
|
|
345
342
|
end
|
346
343
|
end
|
347
344
|
end
|
348
|
-
# rubocop:enable Metrics/ClassLength
|
data/lib/rubocop/ast/version.rb
CHANGED
data/lib/rubocop/ast.rb
CHANGED
@@ -5,7 +5,6 @@ require 'forwardable'
|
|
5
5
|
require 'set'
|
6
6
|
|
7
7
|
require_relative 'ast/ext/range'
|
8
|
-
require_relative 'ast/ext/range_min_max'
|
9
8
|
require_relative 'ast/node_pattern/method_definer'
|
10
9
|
require_relative 'ast/node_pattern'
|
11
10
|
require_relative 'ast/node/mixin/descendence'
|
@@ -70,6 +69,7 @@ require_relative 'ast/node/or_node'
|
|
70
69
|
require_relative 'ast/node/pair_node'
|
71
70
|
require_relative 'ast/node/procarg0_node'
|
72
71
|
require_relative 'ast/node/range_node'
|
72
|
+
require_relative 'ast/node/rational_node'
|
73
73
|
require_relative 'ast/node/regexp_node'
|
74
74
|
require_relative 'ast/node/rescue_node'
|
75
75
|
require_relative 'ast/node/resbody_node'
|
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.32.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: 2024-
|
13
|
+
date: 2024-08-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: parser
|
@@ -40,7 +40,6 @@ files:
|
|
40
40
|
- lib/rubocop/ast.rb
|
41
41
|
- lib/rubocop/ast/builder.rb
|
42
42
|
- lib/rubocop/ast/ext/range.rb
|
43
|
-
- lib/rubocop/ast/ext/range_min_max.rb
|
44
43
|
- lib/rubocop/ast/node.rb
|
45
44
|
- lib/rubocop/ast/node/alias_node.rb
|
46
45
|
- lib/rubocop/ast/node/and_asgn_node.rb
|
@@ -92,6 +91,7 @@ files:
|
|
92
91
|
- lib/rubocop/ast/node/pair_node.rb
|
93
92
|
- lib/rubocop/ast/node/procarg0_node.rb
|
94
93
|
- lib/rubocop/ast/node/range_node.rb
|
94
|
+
- lib/rubocop/ast/node/rational_node.rb
|
95
95
|
- lib/rubocop/ast/node/regexp_node.rb
|
96
96
|
- lib/rubocop/ast/node/resbody_node.rb
|
97
97
|
- lib/rubocop/ast/node/rescue_node.rb
|
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
156
|
- !ruby/object:Gem::Version
|
157
157
|
version: '0'
|
158
158
|
requirements: []
|
159
|
-
rubygems_version: 3.5.
|
159
|
+
rubygems_version: 3.5.11
|
160
160
|
signing_key:
|
161
161
|
specification_version: 4
|
162
162
|
summary: RuboCop tools to deal with Ruby code AST.
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module AST
|
5
|
-
module Ext
|
6
|
-
# Refinement to circumvent broken `Range#minmax` for infinity ranges in 2.6-
|
7
|
-
module RangeMinMax
|
8
|
-
if ::Range.instance_method(:minmax).owner != ::Range
|
9
|
-
refine ::Range do
|
10
|
-
def minmax
|
11
|
-
[min, max]
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|