rubocop-ast 1.36.1 → 1.37.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/node/array_node.rb +1 -1
- data/lib/rubocop/ast/node/for_node.rb +1 -1
- data/lib/rubocop/ast/node/hash_node.rb +1 -1
- data/lib/rubocop/ast/node/if_node.rb +7 -0
- data/lib/rubocop/ast/node/in_pattern_node.rb +1 -1
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +3 -3
- data/lib/rubocop/ast/node/mixin/parameterized_node.rb +1 -1
- data/lib/rubocop/ast/node/mlhs_node.rb +4 -2
- data/lib/rubocop/ast/node/str_node.rb +37 -1
- data/lib/rubocop/ast/node/until_node.rb +1 -1
- data/lib/rubocop/ast/node/when_node.rb +1 -1
- data/lib/rubocop/ast/node/while_node.rb +1 -1
- data/lib/rubocop/ast/node.rb +13 -2
- data/lib/rubocop/ast/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71290c5f117f13043b681f7ce182d115284b84675bbfc0bf35448152ebfb42bd
|
4
|
+
data.tar.gz: 3c13a0e8e089409da5dd353bfea60c3981f56dac094f7a650690f3862bdf3e36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08c425d33229f9116b91905ef14ea762ad2d17603ae581795d3101526a51ee6a4c8e1ab2e508f2355b688e4143f668e71767f8283934ee3b27f045315add0a28'
|
7
|
+
data.tar.gz: 58173b8980810073f670c9087905923661d8a3fe0a43c17b354388ee07728611a6c5d1a690a2813184a6d4286c29c090d11d4f28de001ae395bfb774c53720bc
|
@@ -25,6 +25,13 @@ module RuboCop
|
|
25
25
|
keyword == 'unless'
|
26
26
|
end
|
27
27
|
|
28
|
+
# Checks whether the `if` node has an `then` clause.
|
29
|
+
#
|
30
|
+
# @return [Boolean] whether the node has an `then` clause
|
31
|
+
def then?
|
32
|
+
loc_is?(:begin, 'then')
|
33
|
+
end
|
34
|
+
|
28
35
|
# Checks whether the `if` is an `elsif`. Parser handles these by nesting
|
29
36
|
# `if` nodes in the `else` branch.
|
30
37
|
#
|
@@ -117,7 +117,7 @@ module RuboCop
|
|
117
117
|
#
|
118
118
|
# @return [Boolean] whether the method was called with a connecting dot
|
119
119
|
def dot?
|
120
|
-
|
120
|
+
loc_is?(:dot, '.')
|
121
121
|
end
|
122
122
|
|
123
123
|
# Checks whether the dispatched method uses a double colon to connect the
|
@@ -125,7 +125,7 @@ module RuboCop
|
|
125
125
|
#
|
126
126
|
# @return [Boolean] whether the method was called with a connecting dot
|
127
127
|
def double_colon?
|
128
|
-
|
128
|
+
loc_is?(:dot, '::')
|
129
129
|
end
|
130
130
|
|
131
131
|
# Checks whether the dispatched method uses a safe navigation operator to
|
@@ -133,7 +133,7 @@ module RuboCop
|
|
133
133
|
#
|
134
134
|
# @return [Boolean] whether the method was called with a connecting dot
|
135
135
|
def safe_navigation?
|
136
|
-
|
136
|
+
loc_is?(:dot, '&.')
|
137
137
|
end
|
138
138
|
|
139
139
|
# Checks whether the *explicit* receiver of this method dispatch is
|
@@ -8,13 +8,15 @@ module RuboCop
|
|
8
8
|
class MlhsNode < Node
|
9
9
|
# Returns all the assignment nodes on the left hand side (LHS) of a multiple assignment.
|
10
10
|
# These are generally assignment nodes (`lvasgn`, `ivasgn`, `cvasgn`, `gvasgn`, `casgn`)
|
11
|
-
# but can also be `send` nodes in case of `foo.bar, ... =` or `foo[:bar], ...
|
11
|
+
# but can also be `send` nodes in case of `foo.bar, ... =` or `foo[:bar], ... =`,
|
12
|
+
# or a `splat` node for `*, ... =`.
|
12
13
|
#
|
13
14
|
# @return [Array<Node>] the assignment nodes of the multiple assignment LHS
|
14
15
|
def assignments
|
15
16
|
child_nodes.flat_map do |node|
|
16
17
|
if node.splat_type?
|
17
|
-
|
18
|
+
# Anonymous splats have no children
|
19
|
+
node.child_nodes.first || node
|
18
20
|
elsif node.mlhs_type?
|
19
21
|
node.assignments
|
20
22
|
else
|
@@ -8,13 +8,49 @@ module RuboCop
|
|
8
8
|
class StrNode < Node
|
9
9
|
include BasicLiteralNode
|
10
10
|
|
11
|
+
PERCENT_LITERAL_TYPES = {
|
12
|
+
:% => /\A%(?=[^a-zA-Z])/,
|
13
|
+
:q => /\A%q/,
|
14
|
+
:Q => /\A%Q/
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
def single_quoted?
|
18
|
+
loc_is?(:begin, "'")
|
19
|
+
end
|
20
|
+
|
21
|
+
def double_quoted?
|
22
|
+
loc_is?(:begin, '"')
|
23
|
+
end
|
24
|
+
|
11
25
|
def character_literal?
|
12
|
-
|
26
|
+
loc_is?(:begin, '?')
|
13
27
|
end
|
14
28
|
|
15
29
|
def heredoc?
|
16
30
|
loc.is_a?(Parser::Source::Map::Heredoc)
|
17
31
|
end
|
32
|
+
|
33
|
+
# Checks whether the string literal is delimited by percent brackets.
|
34
|
+
#
|
35
|
+
# @overload percent_literal?
|
36
|
+
# Check for any string percent literal.
|
37
|
+
#
|
38
|
+
# @overload percent_literal?(type)
|
39
|
+
# Check for a string percent literal of type `type`.
|
40
|
+
#
|
41
|
+
# @param type [Symbol] an optional percent literal type
|
42
|
+
#
|
43
|
+
# @return [Boolean] whether the string is enclosed in percent brackets
|
44
|
+
def percent_literal?(type = nil)
|
45
|
+
opening_delimiter = loc.begin if loc.respond_to?(:begin)
|
46
|
+
return false unless opening_delimiter
|
47
|
+
|
48
|
+
if type
|
49
|
+
opening_delimiter.source.match?(PERCENT_LITERAL_TYPES.fetch(type))
|
50
|
+
else
|
51
|
+
opening_delimiter.source.start_with?('%')
|
52
|
+
end
|
53
|
+
end
|
18
54
|
end
|
19
55
|
end
|
20
56
|
end
|
data/lib/rubocop/ast/node.rb
CHANGED
@@ -497,7 +497,7 @@ module RuboCop
|
|
497
497
|
end
|
498
498
|
|
499
499
|
def parenthesized_call?
|
500
|
-
|
500
|
+
loc_is?(:begin, '(')
|
501
501
|
end
|
502
502
|
|
503
503
|
def call_type?
|
@@ -529,11 +529,22 @@ module RuboCop
|
|
529
529
|
end
|
530
530
|
|
531
531
|
def guard_clause?
|
532
|
-
node =
|
532
|
+
node = operator_keyword? ? rhs : self
|
533
533
|
|
534
534
|
node.match_guard_clause?
|
535
535
|
end
|
536
536
|
|
537
|
+
# Shortcut to safely test a particular location, even if
|
538
|
+
# this location does not exist or is `nil`
|
539
|
+
def loc_is?(which_loc, str)
|
540
|
+
return false unless loc.respond_to?(which_loc)
|
541
|
+
|
542
|
+
location = loc.public_send(which_loc)
|
543
|
+
return false unless location
|
544
|
+
|
545
|
+
location.is?(str)
|
546
|
+
end
|
547
|
+
|
537
548
|
# @!method match_guard_clause?(node = self)
|
538
549
|
def_node_matcher :match_guard_clause?, <<~PATTERN
|
539
550
|
[${(send nil? {:raise :fail} ...) return break next} single_line?]
|
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.37.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-12-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: parser
|