rubocop-ast 1.18.0 → 1.24.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubocop/ast/builder.rb +1 -1
- data/lib/rubocop/ast/ext/range.rb +1 -1
- data/lib/rubocop/ast/node/csend_node.rb +14 -0
- data/lib/rubocop/ast/node/mixin/descendence.rb +7 -2
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +3 -3
- data/lib/rubocop/ast/node/mixin/parameterized_node.rb +9 -1
- data/lib/rubocop/ast/node/regexp_node.rb +6 -0
- data/lib/rubocop/ast/node/send_node.rb +4 -0
- data/lib/rubocop/ast/node/str_node.rb +4 -0
- data/lib/rubocop/ast/node.rb +18 -8
- data/lib/rubocop/ast/node_pattern/compiler/binding.rb +2 -2
- data/lib/rubocop/ast/node_pattern.rb +16 -16
- data/lib/rubocop/ast/processed_source.rb +3 -3
- data/lib/rubocop/ast/sexp.rb +2 -1
- data/lib/rubocop/ast/token.rb +15 -1
- data/lib/rubocop/ast/traversal.rb +2 -1
- data/lib/rubocop/ast/version.rb +1 -1
- data/lib/rubocop/ast.rb +3 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f460fee9d6682f0942b107a76c8a24e59b3992e27cdb791a8d9d3e8902596bf0
|
4
|
+
data.tar.gz: 27b55278782ffad52905335f6ae6b1b1709e6156802d669158f903c4b04fecbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6302e8a65e1504fbe3a929f0e50d063ea07873c9650edc1f68f65525e57a2717f06fc87b64970cc98c06e63efa1058b16d6563aa2b2863a0a80a67b04c31e98
|
7
|
+
data.tar.gz: f8c7043155b9fb25ae1509c5bc8d3efe986ae9a74e302e886c3ad4947e5c06b79fd2ede7ba54aebdd3dc8bfe8b9f813ee5b6f2209140c7fee475dc31830f3d97
|
data/lib/rubocop/ast/builder.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module AST
|
5
|
+
# A node extension for `send` nodes. This will be used in place of a plain
|
6
|
+
# node when the builder constructs the AST, making its methods available
|
7
|
+
# to all `send` nodes within RuboCop.
|
8
|
+
class CsendNode < SendNode
|
9
|
+
def send_type?
|
10
|
+
false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -36,7 +36,10 @@ module RuboCop
|
|
36
36
|
#
|
37
37
|
# @return [Array<Node>] an array of child nodes
|
38
38
|
def child_nodes
|
39
|
-
|
39
|
+
# Iterate child nodes directly to avoid allocating an Enumerator.
|
40
|
+
nodes = []
|
41
|
+
each_child_node { |node| nodes << node }
|
42
|
+
nodes
|
40
43
|
end
|
41
44
|
|
42
45
|
# Calls the given block for each descendant node with depth first order.
|
@@ -102,7 +105,9 @@ module RuboCop
|
|
102
105
|
protected
|
103
106
|
|
104
107
|
def visit_descendants(types, &block)
|
105
|
-
|
108
|
+
children.each do |child|
|
109
|
+
next unless child.is_a?(::AST::Node)
|
110
|
+
|
106
111
|
yield child if types.empty? || types.include?(child.type)
|
107
112
|
child.visit_descendants(types, &block)
|
108
113
|
end
|
@@ -211,7 +211,7 @@ module RuboCop
|
|
211
211
|
#
|
212
212
|
# @return [Boolean] whether this method is a lambda literal
|
213
213
|
def lambda_literal?
|
214
|
-
|
214
|
+
loc.expression.source == '->' && block_literal?
|
215
215
|
end
|
216
216
|
|
217
217
|
# Checks whether this is a unary operation.
|
@@ -233,7 +233,7 @@ module RuboCop
|
|
233
233
|
#
|
234
234
|
# foo + bar
|
235
235
|
#
|
236
|
-
# @return [
|
236
|
+
# @return [Boolean] whether this method is a binary operation
|
237
237
|
def binary_operation?
|
238
238
|
return false unless loc.selector
|
239
239
|
|
@@ -249,7 +249,7 @@ module RuboCop
|
|
249
249
|
^{ # or the parent is...
|
250
250
|
sclass class module class_constructor? # a class-like node
|
251
251
|
[ { # or some "wrapper"
|
252
|
-
kwbegin begin block
|
252
|
+
kwbegin begin block numblock
|
253
253
|
(if _condition <%0 _>) # note: we're excluding the condition of `if` nodes
|
254
254
|
}
|
255
255
|
#in_macro_scope? # that is itself in a macro scope
|
@@ -82,9 +82,17 @@ module RuboCop
|
|
82
82
|
# and optimizes other calls
|
83
83
|
module RestArguments
|
84
84
|
include ParameterizedNode
|
85
|
+
|
86
|
+
EMPTY_ARGUMENTS = [].freeze
|
87
|
+
|
85
88
|
# @return [Array<Node>] arguments, if any
|
86
89
|
def arguments
|
87
|
-
|
90
|
+
if arguments?
|
91
|
+
children.drop(first_argument_index).freeze
|
92
|
+
else
|
93
|
+
# Skip unneeded Array allocation.
|
94
|
+
EMPTY_ARGUMENTS
|
95
|
+
end
|
88
96
|
end
|
89
97
|
|
90
98
|
# A shorthand for getting the first argument of the node.
|
@@ -11,6 +11,7 @@ module RuboCop
|
|
11
11
|
i: Regexp::IGNORECASE,
|
12
12
|
m: Regexp::MULTILINE,
|
13
13
|
n: Regexp::NOENCODING,
|
14
|
+
u: Regexp::FIXEDENCODING,
|
14
15
|
o: 0
|
15
16
|
}.freeze
|
16
17
|
private_constant :OPTIONS
|
@@ -87,6 +88,11 @@ module RuboCop
|
|
87
88
|
regopt_include?(:n)
|
88
89
|
end
|
89
90
|
|
91
|
+
# @return [Bool] if regexp uses the fixed-encoding regopt
|
92
|
+
def fixed_encoding?
|
93
|
+
regopt_include?(:u)
|
94
|
+
end
|
95
|
+
|
90
96
|
private
|
91
97
|
|
92
98
|
def regopt_include?(option)
|
data/lib/rubocop/ast/node.rb
CHANGED
@@ -84,8 +84,12 @@ module RuboCop
|
|
84
84
|
LITERAL_RECURSIVE_TYPES = (OPERATOR_KEYWORDS + COMPOSITE_LITERALS + %i[begin pair]).freeze
|
85
85
|
private_constant :LITERAL_RECURSIVE_METHODS, :LITERAL_RECURSIVE_TYPES
|
86
86
|
|
87
|
+
EMPTY_CHILDREN = [].freeze
|
88
|
+
EMPTY_PROPERTIES = {}.freeze
|
89
|
+
private_constant :EMPTY_CHILDREN, :EMPTY_PROPERTIES
|
90
|
+
|
87
91
|
# @see https://www.rubydoc.info/gems/ast/AST/Node:initialize
|
88
|
-
def initialize(type, children =
|
92
|
+
def initialize(type, children = EMPTY_CHILDREN, properties = EMPTY_PROPERTIES)
|
89
93
|
@mutable_attributes = {}
|
90
94
|
|
91
95
|
# ::AST::Node#initialize freezes itself.
|
@@ -101,11 +105,19 @@ module RuboCop
|
|
101
105
|
end
|
102
106
|
end
|
103
107
|
|
104
|
-
Parser::Meta::NODE_TYPES.each do |node_type|
|
108
|
+
(Parser::Meta::NODE_TYPES - [:send]).each do |node_type|
|
105
109
|
method_name = "#{node_type.to_s.gsub(/\W/, '')}_type?"
|
106
|
-
|
107
|
-
|
108
|
-
|
110
|
+
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
111
|
+
def #{method_name} # def block_type?
|
112
|
+
@type == :#{node_type} # @type == :block
|
113
|
+
end # end
|
114
|
+
RUBY
|
115
|
+
end
|
116
|
+
|
117
|
+
# Most nodes are of 'send' type, so this method is defined
|
118
|
+
# separately to make this check as fast as possible.
|
119
|
+
def send_type?
|
120
|
+
false
|
109
121
|
end
|
110
122
|
|
111
123
|
# Returns the parent node, or `nil` if the receiver is a root node.
|
@@ -203,9 +215,7 @@ module RuboCop
|
|
203
215
|
# destructuring method.
|
204
216
|
#
|
205
217
|
# @return [Array<Node>] the different parts of the ndde
|
206
|
-
|
207
|
-
to_a
|
208
|
-
end
|
218
|
+
alias node_parts to_a
|
209
219
|
|
210
220
|
# Calls the given block for each ancestor node from parent to root.
|
211
221
|
# If no block is given, an `Enumerator` is returned.
|
@@ -20,8 +20,8 @@ module RuboCop
|
|
20
20
|
end
|
21
21
|
|
22
22
|
if var == :forbidden_unification
|
23
|
-
raise Invalid, "Wildcard #{name} was first seen in a subset of a" \
|
24
|
-
"
|
23
|
+
raise Invalid, "Wildcard #{name} was first seen in a subset of a " \
|
24
|
+
"union and can't be used outside that union"
|
25
25
|
end
|
26
26
|
var
|
27
27
|
end
|
@@ -54,6 +54,22 @@ module RuboCop
|
|
54
54
|
|
55
55
|
VAR = 'node'
|
56
56
|
|
57
|
+
# Yields its argument and any descendants, depth-first.
|
58
|
+
#
|
59
|
+
def self.descend(element, &block)
|
60
|
+
return to_enum(__method__, element) unless block
|
61
|
+
|
62
|
+
yield element
|
63
|
+
|
64
|
+
if element.is_a?(::RuboCop::AST::Node)
|
65
|
+
element.children.each do |child|
|
66
|
+
descend(child, &block)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
nil
|
71
|
+
end
|
72
|
+
|
57
73
|
attr_reader :pattern, :ast, :match_code
|
58
74
|
|
59
75
|
def_delegators :@compiler, :captures, :named_parameters, :positional_parameters
|
@@ -100,22 +116,6 @@ module RuboCop
|
|
100
116
|
initialize(coder['pattern'])
|
101
117
|
end
|
102
118
|
|
103
|
-
# Yields its argument and any descendants, depth-first.
|
104
|
-
#
|
105
|
-
def self.descend(element, &block)
|
106
|
-
return to_enum(__method__, element) unless block
|
107
|
-
|
108
|
-
yield element
|
109
|
-
|
110
|
-
if element.is_a?(::RuboCop::AST::Node)
|
111
|
-
element.children.each do |child|
|
112
|
-
descend(child, &block)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
nil
|
117
|
-
end
|
118
|
-
|
119
119
|
def freeze
|
120
120
|
@match_code.freeze
|
121
121
|
@compiler.freeze
|
@@ -12,6 +12,9 @@ module RuboCop
|
|
12
12
|
# @api private
|
13
13
|
STRING_SOURCE_NAME = '(string)'
|
14
14
|
|
15
|
+
INVALID_LEVELS = %i[error fatal].freeze
|
16
|
+
private_constant :INVALID_LEVELS
|
17
|
+
|
15
18
|
attr_reader :path, :buffer, :ast, :comments, :tokens, :diagnostics,
|
16
19
|
:parser_error, :raw_source, :ruby_version
|
17
20
|
|
@@ -20,9 +23,6 @@ module RuboCop
|
|
20
23
|
new(file, ruby_version, path)
|
21
24
|
end
|
22
25
|
|
23
|
-
INVALID_LEVELS = %i[error fatal].freeze
|
24
|
-
private_constant :INVALID_LEVELS
|
25
|
-
|
26
26
|
def initialize(source, ruby_version, path = nil)
|
27
27
|
# Defaults source encoding to UTF-8, regardless of the encoding it has
|
28
28
|
# been read with, which could be non-utf8 depending on the default
|
data/lib/rubocop/ast/sexp.rb
CHANGED
data/lib/rubocop/ast/token.rb
CHANGED
@@ -4,6 +4,8 @@ module RuboCop
|
|
4
4
|
module AST
|
5
5
|
# A basic wrapper around Parser's tokens.
|
6
6
|
class Token
|
7
|
+
LEFT_PAREN_TYPES = %i[tLPAREN tLPAREN2].freeze
|
8
|
+
|
7
9
|
attr_reader :pos, :type, :text
|
8
10
|
|
9
11
|
def self.from_parser_token(parser_token)
|
@@ -89,7 +91,7 @@ module RuboCop
|
|
89
91
|
end
|
90
92
|
|
91
93
|
def left_parens?
|
92
|
-
|
94
|
+
LEFT_PAREN_TYPES.include?(type)
|
93
95
|
end
|
94
96
|
|
95
97
|
def right_parens?
|
@@ -100,6 +102,14 @@ module RuboCop
|
|
100
102
|
type == :tCOMMA
|
101
103
|
end
|
102
104
|
|
105
|
+
def dot?
|
106
|
+
type == :tDOT
|
107
|
+
end
|
108
|
+
|
109
|
+
def regexp_dots?
|
110
|
+
%i[tDOT2 tDOT3].include?(type)
|
111
|
+
end
|
112
|
+
|
103
113
|
def rescue_modifier?
|
104
114
|
type == :kRESCUE_MOD
|
105
115
|
end
|
@@ -111,6 +121,10 @@ module RuboCop
|
|
111
121
|
def equal_sign?
|
112
122
|
%i[tEQL tOP_ASGN].include?(type)
|
113
123
|
end
|
124
|
+
|
125
|
+
def new_line?
|
126
|
+
type == :tNL
|
127
|
+
end
|
114
128
|
end
|
115
129
|
end
|
116
130
|
end
|
@@ -75,7 +75,8 @@ module RuboCop
|
|
75
75
|
### arity == 0
|
76
76
|
no_children = %i[true false nil self cbase zsuper redo retry
|
77
77
|
forward_args forwarded_args match_nil_pattern
|
78
|
-
forward_arg
|
78
|
+
forward_arg forwarded_restarg forwarded_kwrestarg
|
79
|
+
lambda empty_else kwnilarg
|
79
80
|
__FILE__ __LINE__ __ENCODING__]
|
80
81
|
|
81
82
|
### arity == 0..1
|
data/lib/rubocop/ast/version.rb
CHANGED
data/lib/rubocop/ast.rb
CHANGED
@@ -76,6 +76,7 @@ require_relative 'ast/node/resbody_node'
|
|
76
76
|
require_relative 'ast/node/return_node'
|
77
77
|
require_relative 'ast/node/self_class_node'
|
78
78
|
require_relative 'ast/node/send_node'
|
79
|
+
require_relative 'ast/node/csend_node'
|
79
80
|
require_relative 'ast/node/str_node'
|
80
81
|
require_relative 'ast/node/dstr_node'
|
81
82
|
require_relative 'ast/node/super_node'
|
@@ -91,5 +92,5 @@ require_relative 'ast/token'
|
|
91
92
|
require_relative 'ast/traversal'
|
92
93
|
require_relative 'ast/version'
|
93
94
|
|
94
|
-
|
95
|
-
|
95
|
+
RuboCop::AST::NodePattern::Parser.autoload :WithMeta, "#{__dir__}/ast/node_pattern/with_meta"
|
96
|
+
RuboCop::AST::NodePattern::Compiler.autoload :Debug, "#{__dir__}/ast/node_pattern/compiler/debug"
|
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.24.1
|
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: 2022-
|
13
|
+
date: 2022-12-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: parser
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- lib/rubocop/ast/node/casgn_node.rb
|
77
77
|
- lib/rubocop/ast/node/class_node.rb
|
78
78
|
- lib/rubocop/ast/node/const_node.rb
|
79
|
+
- lib/rubocop/ast/node/csend_node.rb
|
79
80
|
- lib/rubocop/ast/node/def_node.rb
|
80
81
|
- lib/rubocop/ast/node/defined_node.rb
|
81
82
|
- lib/rubocop/ast/node/dstr_node.rb
|