rubocop-ast 1.6.0 → 1.9.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 +4 -4
- data/lib/rubocop/ast/node.rb +5 -1
- data/lib/rubocop/ast/node/case_match_node.rb +14 -0
- data/lib/rubocop/ast/node/in_pattern_node.rb +7 -0
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +23 -5
- data/lib/rubocop/ast/node_pattern.rb +5 -5
- data/lib/rubocop/ast/node_pattern/compiler/sequence_subcompiler.rb +1 -1
- data/lib/rubocop/ast/node_pattern/node.rb +1 -1
- data/lib/rubocop/ast/node_pattern/parser.racc.rb +1 -1
- data/lib/rubocop/ast/node_pattern/parser.rb +1 -1
- data/lib/rubocop/ast/processed_source.rb +8 -8
- data/lib/rubocop/ast/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c74f293f4bc64d882c585948fa1cadb54c207f6f21b1d46986751433c9e8f8e6
|
4
|
+
data.tar.gz: c2d80c9d76eab9d8e9dfc1bb5d7ba3ea99ec55edda6c57e63acf894730f12e9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48c641709f25b739e2fca2784601c50b0344c6ee5f23011b58795e118ebceb38488944fc3b7929b3ed62e0e79dff6cd279a5aac71e817a2c2c9624a9d15cc0d2
|
7
|
+
data.tar.gz: ae3bdbcb7bc6664ecaf11ec72c98a598a88ea6d5b4b021607564fb361cf1663071bc9286a38af21b576c1f5cfc0d884895f845d825a331dff0cf7f106f9d6396
|
data/lib/rubocop/ast/node.rb
CHANGED
@@ -317,7 +317,11 @@ module RuboCop
|
|
317
317
|
# returns nil if answer cannot be determined
|
318
318
|
ancestors = each_ancestor(:class, :module, :sclass, :casgn, :block)
|
319
319
|
result = ancestors.map do |ancestor|
|
320
|
-
parent_module_name_part(ancestor)
|
320
|
+
parent_module_name_part(ancestor) do |full_name|
|
321
|
+
return nil unless full_name
|
322
|
+
|
323
|
+
full_name
|
324
|
+
end
|
321
325
|
end.compact.reverse.join('::')
|
322
326
|
result.empty? ? 'Object' : result
|
323
327
|
end
|
@@ -31,9 +31,23 @@ module RuboCop
|
|
31
31
|
node_parts[1...-1]
|
32
32
|
end
|
33
33
|
|
34
|
+
# Returns an array of all the when branches in the `case` statement.
|
35
|
+
#
|
36
|
+
# @return [Array<Node, nil>] an array of the bodies of the `in` branches
|
37
|
+
# and the `else` (if any). Note that these bodies could be nil.
|
38
|
+
def branches
|
39
|
+
bodies = in_pattern_branches.map(&:body)
|
40
|
+
if else?
|
41
|
+
# `empty-else` node sets nil because it has no body.
|
42
|
+
else_branch.empty_else_type? ? bodies.push(nil) : bodies.push(else_branch)
|
43
|
+
end
|
44
|
+
bodies
|
45
|
+
end
|
46
|
+
|
34
47
|
# Returns the else branch of the `case` statement, if any.
|
35
48
|
#
|
36
49
|
# @return [Node] the else branch node of the `case` statement
|
50
|
+
# @return [EmptyElse] the empty else branch node of the `case` statement
|
37
51
|
# @return [nil] if the case statement does not have an else branch.
|
38
52
|
def else_branch
|
39
53
|
node_parts[-1]
|
@@ -6,6 +6,13 @@ module RuboCop
|
|
6
6
|
# node when the builder constructs the AST, making its methods available
|
7
7
|
# to all `in` nodes within RuboCop.
|
8
8
|
class InPatternNode < Node
|
9
|
+
# Returns a node of the pattern in the `in` branch.
|
10
|
+
#
|
11
|
+
# @return [Node] a pattern node
|
12
|
+
def pattern
|
13
|
+
node_parts.first
|
14
|
+
end
|
15
|
+
|
9
16
|
# Returns the index of the `in` branch within the `case` statement.
|
10
17
|
#
|
11
18
|
# @return [Integer] the index of the `in` branch
|
@@ -165,16 +165,34 @@ module RuboCop
|
|
165
165
|
ARITHMETIC_OPERATORS.include?(method_name)
|
166
166
|
end
|
167
167
|
|
168
|
-
# Checks if this node is part of a chain of `def` modifiers.
|
168
|
+
# Checks if this node is part of a chain of `def` or `defs` modifiers.
|
169
169
|
#
|
170
170
|
# @example
|
171
171
|
#
|
172
172
|
# private def foo; end
|
173
173
|
#
|
174
|
-
# @return
|
175
|
-
|
176
|
-
|
177
|
-
|
174
|
+
# @return wether the `def|defs` node is a modifier or not.
|
175
|
+
# See also `def_modifier` that returns the node or `nil`
|
176
|
+
def def_modifier?(node = self)
|
177
|
+
!!def_modifier(node)
|
178
|
+
end
|
179
|
+
|
180
|
+
# Checks if this node is part of a chain of `def` or `defs` modifiers.
|
181
|
+
#
|
182
|
+
# @example
|
183
|
+
#
|
184
|
+
# private def foo; end
|
185
|
+
#
|
186
|
+
# @return [Node | nil] returns the `def|defs` node this is a modifier for,
|
187
|
+
# or `nil` if it isn't a def modifier
|
188
|
+
def def_modifier(node = self)
|
189
|
+
arg = node.children[2]
|
190
|
+
|
191
|
+
return unless node.send_type? && node.receiver.nil? && arg.is_a?(::AST::Node)
|
192
|
+
|
193
|
+
return arg if arg.def_type? || arg.defs_type?
|
194
|
+
|
195
|
+
def_modifier(arg)
|
178
196
|
end
|
179
197
|
|
180
198
|
# Checks whether this is a lambda. Some versions of parser parses
|
@@ -80,23 +80,23 @@ module RuboCop
|
|
80
80
|
"#<#{self.class} #{pattern}>"
|
81
81
|
end
|
82
82
|
|
83
|
-
def marshal_load(pattern)
|
83
|
+
def marshal_load(pattern) # :nodoc:
|
84
84
|
initialize pattern
|
85
85
|
end
|
86
86
|
|
87
|
-
def marshal_dump
|
87
|
+
def marshal_dump # :nodoc:
|
88
88
|
pattern
|
89
89
|
end
|
90
90
|
|
91
|
-
def as_json(_options = nil)
|
91
|
+
def as_json(_options = nil) # :nodoc:
|
92
92
|
pattern
|
93
93
|
end
|
94
94
|
|
95
|
-
def encode_with(coder)
|
95
|
+
def encode_with(coder) # :nodoc:
|
96
96
|
coder['pattern'] = pattern
|
97
97
|
end
|
98
98
|
|
99
|
-
def init_with(coder)
|
99
|
+
def init_with(coder) # :nodoc:
|
100
100
|
initialize(coder['pattern'])
|
101
101
|
end
|
102
102
|
|
@@ -347,7 +347,7 @@ module RuboCop
|
|
347
347
|
def compile_loop_advance(to = '+=1')
|
348
348
|
# The `#{@cur_child_var} ||` is just to avoid unused variable warning
|
349
349
|
"(#{@cur_child_var} = #{@seq_var}.children[#{@cur_index_var} #{to}]; " \
|
350
|
-
|
350
|
+
"#{@cur_child_var} || true)"
|
351
351
|
end
|
352
352
|
|
353
353
|
def compile_loop(term)
|
@@ -54,7 +54,7 @@ module RuboCop
|
|
54
54
|
children_nodes.sum(&:nb_captures)
|
55
55
|
end
|
56
56
|
|
57
|
-
# @return [Boolean] returns
|
57
|
+
# @return [Boolean] returns wether it matches a variable number of elements
|
58
58
|
def variadic?
|
59
59
|
arity.is_a?(Range)
|
60
60
|
end
|
@@ -52,7 +52,7 @@ module RuboCop
|
|
52
52
|
|
53
53
|
detail = node.loc&.expression&.source || node.to_s
|
54
54
|
raise NodePattern::Invalid, 'parse error, expected unary node pattern ' \
|
55
|
-
|
55
|
+
"but got expression matching multiple elements: #{detail}"
|
56
56
|
end
|
57
57
|
|
58
58
|
# Overrides Racc::Parser's method:
|
@@ -177,6 +177,14 @@ module RuboCop
|
|
177
177
|
sorted_tokens[last_token_index(range_or_node)]
|
178
178
|
end
|
179
179
|
|
180
|
+
# The tokens list is always sorted by token position, except for cases when heredoc
|
181
|
+
# is passed as a method argument. In this case tokens are interleaved by
|
182
|
+
# heredoc contents' tokens.
|
183
|
+
def sorted_tokens
|
184
|
+
# Use stable sort.
|
185
|
+
@sorted_tokens ||= tokens.sort_by.with_index { |token, i| [token.begin_pos, i] }
|
186
|
+
end
|
187
|
+
|
180
188
|
private
|
181
189
|
|
182
190
|
def comment_index
|
@@ -272,14 +280,6 @@ module RuboCop
|
|
272
280
|
sorted_tokens.bsearch_index { |token| token.end_pos >= end_pos }
|
273
281
|
end
|
274
282
|
|
275
|
-
# The tokens list is always sorted by token position, except for cases when heredoc
|
276
|
-
# is passed as a method argument. In this case tokens are interleaved by
|
277
|
-
# heredoc contents' tokens.
|
278
|
-
def sorted_tokens
|
279
|
-
# Use stable sort.
|
280
|
-
@sorted_tokens ||= tokens.sort_by.with_index { |token, i| [token.begin_pos, i] }
|
281
|
-
end
|
282
|
-
|
283
283
|
def source_range(range_or_node)
|
284
284
|
if range_or_node.respond_to?(:source_range)
|
285
285
|
range_or_node.source_range
|
data/lib/rubocop/ast/version.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-ast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
8
8
|
- Jonas Arvidsson
|
9
9
|
- Yuji Nakayama
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-
|
13
|
+
date: 2021-08-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: parser
|
@@ -154,7 +154,7 @@ metadata:
|
|
154
154
|
source_code_uri: https://github.com/rubocop-hq/rubocop-ast/
|
155
155
|
documentation_uri: https://docs.rubocop.org/rubocop-ast/
|
156
156
|
bug_tracker_uri: https://github.com/rubocop-hq/rubocop-ast/issues
|
157
|
-
post_install_message:
|
157
|
+
post_install_message:
|
158
158
|
rdoc_options: []
|
159
159
|
require_paths:
|
160
160
|
- lib
|
@@ -169,8 +169,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
169
|
- !ruby/object:Gem::Version
|
170
170
|
version: '0'
|
171
171
|
requirements: []
|
172
|
-
rubygems_version: 3.
|
173
|
-
signing_key:
|
172
|
+
rubygems_version: 3.2.3
|
173
|
+
signing_key:
|
174
174
|
specification_version: 4
|
175
175
|
summary: RuboCop tools to deal with Ruby code AST.
|
176
176
|
test_files: []
|