rubocop-ast 1.5.0 → 1.7.0
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.rb +1 -0
- data/lib/rubocop/ast/builder.rb +1 -0
- data/lib/rubocop/ast/node/case_match_node.rb +2 -2
- data/lib/rubocop/ast/node/in_pattern_node.rb +38 -0
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +23 -5
- data/lib/rubocop/ast/version.rb +1 -1
- 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: 25e84f96e233a9c966ad15efd834e109fea1c11d0998e2913ffd81310568d2b2
|
4
|
+
data.tar.gz: f6b8a033d2fd90518fb102f2cfaa27a5ef32bcfb892783ef79e2b9ad33ab4235
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 326d28041a4c30d64cac801ceec9677eea264c7a98754217ae27b026bf9779122803402cdddd8306881320e8ac185ce3ff708d4b6e2c869840622303b50b9ab1
|
7
|
+
data.tar.gz: 293b516ba03824c5c9fc56557943993688cf0796bd7ffe567434f7633ca71aa24aec8ebcac89284c3b7b9fb7d38302cf666b1e7b0bb844700d70bad8c65cc767
|
data/lib/rubocop/ast.rb
CHANGED
@@ -53,6 +53,7 @@ require_relative 'ast/node/forward_args_node'
|
|
53
53
|
require_relative 'ast/node/float_node'
|
54
54
|
require_relative 'ast/node/hash_node'
|
55
55
|
require_relative 'ast/node/if_node'
|
56
|
+
require_relative 'ast/node/in_pattern_node'
|
56
57
|
require_relative 'ast/node/index_node'
|
57
58
|
require_relative 'ast/node/indexasgn_node'
|
58
59
|
require_relative 'ast/node/int_node'
|
data/lib/rubocop/ast/builder.rb
CHANGED
@@ -24,9 +24,9 @@ module RuboCop
|
|
24
24
|
self
|
25
25
|
end
|
26
26
|
|
27
|
-
# Returns an array of all the
|
27
|
+
# Returns an array of all the `in` pattern branches in the `case` statement.
|
28
28
|
#
|
29
|
-
# @return [Array<
|
29
|
+
# @return [Array<InPatternNode>] an array of `in_pattern` nodes
|
30
30
|
def in_pattern_branches
|
31
31
|
node_parts[1...-1]
|
32
32
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module AST
|
5
|
+
# A node extension for `in` 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 `in` nodes within RuboCop.
|
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
|
+
|
16
|
+
# Returns the index of the `in` branch within the `case` statement.
|
17
|
+
#
|
18
|
+
# @return [Integer] the index of the `in` branch
|
19
|
+
def branch_index
|
20
|
+
parent.in_pattern_branches.index(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Checks whether the `in` node has a `then` keyword.
|
24
|
+
#
|
25
|
+
# @return [Boolean] whether the `in` node has a `then` keyword
|
26
|
+
def then?
|
27
|
+
loc.begin&.is?('then')
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns the body of the `in` node.
|
31
|
+
#
|
32
|
+
# @return [Node, nil] the body of the `in` node
|
33
|
+
def body
|
34
|
+
node_parts[-1]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -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
|
data/lib/rubocop/ast/version.rb
CHANGED
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.7.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: 2021-05-
|
13
|
+
date: 2021-05-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: parser
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- lib/rubocop/ast/node/forward_args_node.rb
|
83
83
|
- lib/rubocop/ast/node/hash_node.rb
|
84
84
|
- lib/rubocop/ast/node/if_node.rb
|
85
|
+
- lib/rubocop/ast/node/in_pattern_node.rb
|
85
86
|
- lib/rubocop/ast/node/index_node.rb
|
86
87
|
- lib/rubocop/ast/node/indexasgn_node.rb
|
87
88
|
- lib/rubocop/ast/node/int_node.rb
|