rubocop 1.73.1 → 1.73.2
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/config/default.yml +1 -2
- data/config/internal_affairs.yml +4 -0
- data/lib/rubocop/config_loader.rb +0 -1
- data/lib/rubocop/cop/internal_affairs/example_description.rb +3 -1
- data/lib/rubocop/cop/internal_affairs/node_type_group.rb +91 -0
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +15 -70
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +0 -6
- data/lib/rubocop/cop/mixin/range_help.rb +12 -0
- data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -7
- data/lib/rubocop/cop/style/inverse_methods.rb +8 -5
- data/lib/rubocop/cop/style/keyword_parameters_order.rb +13 -7
- data/lib/rubocop/cop/style/multiline_block_chain.rb +1 -1
- data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -9
- data/lib/rubocop/cop/style/redundant_condition.rb +2 -3
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +0 -6
- data/lib/rubocop/cop/utils/format_string.rb +5 -2
- data/lib/rubocop/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 671bf05708f62eb3abe3b448168f7daa905cffe60e2652ad4ec21964594adf70
|
4
|
+
data.tar.gz: caef12b9b307560cda7125652fa0249fcc0908725e97cc963a10f4c1e0782faa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fea1053c5a5f72ffc9eea331b438f1fc1d876eed21c0f251569ab541cf3f9724193e1c3bf72a0154e84608ac4346cb7a122fcc4a5266fe7b520109c56c5dea1a
|
7
|
+
data.tar.gz: e2b4c854a638b119a3b28e39e77dd05d86fe85b890180bc9a70ac10727f9e74e1ed64e659fe397042610e4bc87b3153d5783d472a596de110628395708da6177
|
data/config/default.yml
CHANGED
@@ -1887,10 +1887,9 @@ Lint/EmptyConditionalBody:
|
|
1887
1887
|
Description: 'Checks for the presence of `if`, `elsif` and `unless` branches without a body.'
|
1888
1888
|
Enabled: true
|
1889
1889
|
AutoCorrect: contextual
|
1890
|
-
SafeAutoCorrect: false
|
1891
1890
|
AllowComments: true
|
1892
1891
|
VersionAdded: '0.89'
|
1893
|
-
VersionChanged: '1.
|
1892
|
+
VersionChanged: '1.73'
|
1894
1893
|
|
1895
1894
|
Lint/EmptyEnsure:
|
1896
1895
|
Description: 'Checks for empty ensure block.'
|
data/config/internal_affairs.yml
CHANGED
@@ -63,7 +63,6 @@ module RuboCop
|
|
63
63
|
loaded_features = resolver.resolve_requires(path, hash)
|
64
64
|
add_loaded_features(loaded_features)
|
65
65
|
|
66
|
-
resolver.override_department_setting_for_cops({}, hash)
|
67
66
|
resolver.resolve_inheritance_from_gems(hash)
|
68
67
|
resolver.resolve_inheritance(path, hash, file, debug?)
|
69
68
|
hash.delete('inherit_from')
|
@@ -50,10 +50,12 @@ module RuboCop
|
|
50
50
|
}.freeze
|
51
51
|
|
52
52
|
EXPECT_NO_CORRECTIONS_DESCRIPTION_MAPPING = {
|
53
|
-
/\A(auto[- ]?)?
|
53
|
+
/\A(auto[- ]?)?corrects?/ => 'does not correct',
|
54
|
+
/\band (auto[- ]?)?corrects/ => 'but does not correct'
|
54
55
|
}.freeze
|
55
56
|
|
56
57
|
EXPECT_CORRECTION_DESCRIPTION_MAPPING = {
|
58
|
+
/\bbut (does not|doesn't) (auto[- ]?)?correct/ => 'and autocorrects',
|
57
59
|
/\b(does not|doesn't) (auto[- ]?)?correct/ => 'autocorrects'
|
58
60
|
}.freeze
|
59
61
|
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InternalAffairs
|
6
|
+
# Checks that node types are checked against their group when all types of a
|
7
|
+
# group are checked.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# # bad
|
11
|
+
# node.type?(:irange, :erange)
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
# node.range_type?
|
15
|
+
#
|
16
|
+
# # bad
|
17
|
+
# node.type?(:irange, :erange, :send, :csend)
|
18
|
+
#
|
19
|
+
# # good
|
20
|
+
# node.type?(:range, :call)
|
21
|
+
#
|
22
|
+
class NodeTypeGroup < Base
|
23
|
+
extend AutoCorrector
|
24
|
+
include RangeHelp
|
25
|
+
|
26
|
+
MSG = 'Use `:%<group>s` instead of individually listing group types.'
|
27
|
+
|
28
|
+
RESTRICT_ON_SEND = %i[type? each_ancestor each_child_node each_descendant each_node].freeze
|
29
|
+
|
30
|
+
def on_send(node)
|
31
|
+
return unless node.receiver
|
32
|
+
|
33
|
+
symbol_args = node.arguments.select(&:sym_type?)
|
34
|
+
return if symbol_args.none?
|
35
|
+
|
36
|
+
NodePatternGroups::NODE_GROUPS.each do |group_name, group_types|
|
37
|
+
next unless group_satisfied?(group_types, symbol_args)
|
38
|
+
|
39
|
+
offense_range = arguments_range(node)
|
40
|
+
add_offense(offense_range, message: format(MSG, group: group_name)) do |corrector|
|
41
|
+
autocorrect(corrector, node, symbol_args, group_name, group_types)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
alias on_csend on_send
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def arguments_range(node)
|
50
|
+
range_between(
|
51
|
+
node.first_argument.source_range.begin_pos,
|
52
|
+
node.last_argument.source_range.end_pos
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
def group_satisfied?(group_types, symbol_args)
|
57
|
+
group_types.all? { |type| symbol_args.any? { |arg| arg.value == type } }
|
58
|
+
end
|
59
|
+
|
60
|
+
def autocorrect(corrector, node, symbol_args, group_name, group_types)
|
61
|
+
if node.method?(:type?) && node.arguments.count == group_types.count
|
62
|
+
autocorrect_to_explicit_predicate(corrector, node, group_name)
|
63
|
+
else
|
64
|
+
autocorrect_keep_method(corrector, symbol_args, group_name, group_types)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def autocorrect_to_explicit_predicate(corrector, node, group_name)
|
69
|
+
corrector.replace(node.selector, "#{group_name}_type?")
|
70
|
+
corrector.remove(arguments_range(node))
|
71
|
+
end
|
72
|
+
|
73
|
+
def autocorrect_keep_method(corrector, symbol_args, group_name, group_types)
|
74
|
+
first_replaced = false
|
75
|
+
symbol_args.each do |arg|
|
76
|
+
next unless group_types.include?(arg.value)
|
77
|
+
|
78
|
+
if first_replaced
|
79
|
+
range = range_with_surrounding_space(arg.source_range)
|
80
|
+
range = range_with_surrounding_comma(range, :left)
|
81
|
+
corrector.remove(range)
|
82
|
+
else
|
83
|
+
first_replaced = true
|
84
|
+
corrector.replace(arg, ":#{group_name}")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -17,6 +17,7 @@ require_relative 'internal_affairs/node_destructuring'
|
|
17
17
|
require_relative 'internal_affairs/node_first_or_last_argument'
|
18
18
|
require_relative 'internal_affairs/node_matcher_directive'
|
19
19
|
require_relative 'internal_affairs/node_pattern_groups'
|
20
|
+
require_relative 'internal_affairs/node_type_group'
|
20
21
|
require_relative 'internal_affairs/node_type_multiple_predicates'
|
21
22
|
require_relative 'internal_affairs/node_type_predicate'
|
22
23
|
require_relative 'internal_affairs/numblock_handler'
|
@@ -7,11 +7,6 @@ module RuboCop
|
|
7
7
|
#
|
8
8
|
# NOTE: empty `else` branches are handled by `Style/EmptyElse`.
|
9
9
|
#
|
10
|
-
# @safety
|
11
|
-
# Autocorrection for this cop is not safe. The conditions for empty branches that
|
12
|
-
# the autocorrection removes may have side effects, or the logic in subsequent
|
13
|
-
# branches may change due to the removal of a previous condition.
|
14
|
-
#
|
15
10
|
# @example
|
16
11
|
# # bad
|
17
12
|
# if condition
|
@@ -41,6 +36,13 @@ module RuboCop
|
|
41
36
|
# if condition
|
42
37
|
# do_something
|
43
38
|
# elsif other_condition
|
39
|
+
# nil
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# # good
|
43
|
+
# if condition
|
44
|
+
# do_something
|
45
|
+
# elsif other_condition
|
44
46
|
# do_something_else
|
45
47
|
# end
|
46
48
|
#
|
@@ -63,7 +65,6 @@ module RuboCop
|
|
63
65
|
class EmptyConditionalBody < Base
|
64
66
|
extend AutoCorrector
|
65
67
|
include CommentsHelp
|
66
|
-
include RangeHelp
|
67
68
|
|
68
69
|
MSG = 'Avoid `%<keyword>s` branches without a body.'
|
69
70
|
|
@@ -74,21 +75,14 @@ module RuboCop
|
|
74
75
|
range = offense_range(node)
|
75
76
|
|
76
77
|
add_offense(range, message: format(MSG, keyword: node.keyword)) do |corrector|
|
77
|
-
|
78
|
+
next unless can_simplify_conditional?(node)
|
79
|
+
|
80
|
+
flip_orphaned_else(corrector, node)
|
78
81
|
end
|
79
82
|
end
|
80
83
|
|
81
84
|
private
|
82
85
|
|
83
|
-
def do_autocorrect?(node)
|
84
|
-
# if condition; end.do_something
|
85
|
-
return false if (parent = node.parent)&.call_type?
|
86
|
-
# x = if condition; end
|
87
|
-
return false if (parent&.assignment? || parent&.operator_keyword?) && node.children.one?
|
88
|
-
|
89
|
-
true
|
90
|
-
end
|
91
|
-
|
92
86
|
def offense_range(node)
|
93
87
|
if node.loc.else
|
94
88
|
node.source_range.begin.join(node.loc.else.begin)
|
@@ -97,53 +91,23 @@ module RuboCop
|
|
97
91
|
end
|
98
92
|
end
|
99
93
|
|
100
|
-
def
|
101
|
-
|
102
|
-
remove_empty_branch(corrector, node)
|
103
|
-
correct_other_branches(corrector, node)
|
104
|
-
end
|
105
|
-
|
106
|
-
def remove_comments(corrector, node)
|
107
|
-
comments_in_range(node).each do |comment|
|
108
|
-
range = range_by_whole_lines(comment.source_range, include_final_newline: true)
|
109
|
-
corrector.remove(range)
|
110
|
-
end
|
94
|
+
def can_simplify_conditional?(node)
|
95
|
+
node.else_branch && node.loc.else.source == 'else'
|
111
96
|
end
|
112
97
|
|
113
|
-
# rubocop:disable Metrics/AbcSize
|
114
98
|
def remove_empty_branch(corrector, node)
|
115
99
|
range = if empty_if_branch?(node) && else_branch?(node)
|
116
100
|
branch_range(node)
|
117
|
-
elsif same_line?(node, else_kw_loc = node.loc.else)
|
118
|
-
node.source_range.begin.join(else_kw_loc.begin)
|
119
|
-
elsif node.parent&.loc.respond_to?(:end) &&
|
120
|
-
same_line?(node, end_loc = node.parent.loc.end)
|
121
|
-
node.source_range.begin.join(end_loc.begin)
|
122
101
|
else
|
123
102
|
deletion_range(branch_range(node))
|
124
103
|
end
|
125
104
|
|
126
105
|
corrector.remove(range)
|
127
106
|
end
|
128
|
-
# rubocop:enable Metrics/AbcSize
|
129
107
|
|
130
|
-
def
|
131
|
-
|
132
|
-
|
133
|
-
if node.else_branch&.if_type? && !node.else_branch.modifier_form?
|
134
|
-
# Replace an orphaned `elsif` with `if`
|
135
|
-
corrector.replace(node.else_branch.loc.keyword, 'if')
|
136
|
-
else
|
137
|
-
# Flip orphaned `else`
|
138
|
-
corrector.replace(node.loc.else, "#{node.inverse_keyword} #{node.condition.source}")
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def require_other_branches_correction?(node)
|
143
|
-
return false unless node.if_type? && node.else?
|
144
|
-
return false if !empty_if_branch?(node) && node.elsif?
|
145
|
-
|
146
|
-
!empty_elsif_branch?(node)
|
108
|
+
def flip_orphaned_else(corrector, node)
|
109
|
+
corrector.replace(node.loc.else, "#{node.inverse_keyword} #{node.condition.source}")
|
110
|
+
remove_empty_branch(corrector, node)
|
147
111
|
end
|
148
112
|
|
149
113
|
def empty_if_branch?(node)
|
@@ -154,36 +118,17 @@ module RuboCop
|
|
154
118
|
if_branch.if_type? && !if_branch.body
|
155
119
|
end
|
156
120
|
|
157
|
-
def empty_elsif_branch?(node)
|
158
|
-
return false unless (else_branch = node.else_branch)
|
159
|
-
|
160
|
-
else_branch.if_type? && !else_branch.body
|
161
|
-
end
|
162
|
-
|
163
121
|
def else_branch?(node)
|
164
122
|
node.else_branch && !node.else_branch.if_type?
|
165
123
|
end
|
166
124
|
|
167
|
-
# rubocop:disable Metrics/AbcSize
|
168
125
|
def branch_range(node)
|
169
126
|
if empty_if_branch?(node) && else_branch?(node)
|
170
127
|
node.source_range.with(end_pos: node.loc.else.begin_pos)
|
171
128
|
elsif node.loc.else
|
172
129
|
node.source_range.with(end_pos: node.condition.source_range.end_pos)
|
173
|
-
elsif all_branches_body_missing?(node)
|
174
|
-
if_node = node.ancestors.detect(&:if?)
|
175
|
-
node.source_range.join(if_node.loc.end.end)
|
176
|
-
else
|
177
|
-
node.source_range
|
178
130
|
end
|
179
131
|
end
|
180
|
-
# rubocop:enable Metrics/AbcSize
|
181
|
-
|
182
|
-
def all_branches_body_missing?(node)
|
183
|
-
return false unless node.parent&.if_type?
|
184
|
-
|
185
|
-
node.parent.branches.compact.empty?
|
186
|
-
end
|
187
132
|
|
188
133
|
def deletion_range(range)
|
189
134
|
# Collect a range between the start of the `if` node and the next relevant node,
|
@@ -156,12 +156,6 @@ module RuboCop
|
|
156
156
|
|
157
157
|
overridden_kwargs
|
158
158
|
end
|
159
|
-
|
160
|
-
def arguments_range(node)
|
161
|
-
arguments = node.arguments
|
162
|
-
|
163
|
-
range_between(arguments.first.source_range.begin_pos, arguments.last.source_range.end_pos)
|
164
|
-
end
|
165
159
|
end
|
166
160
|
end
|
167
161
|
end
|
@@ -34,6 +34,18 @@ module RuboCop
|
|
34
34
|
range_between(node.loc.begin.end_pos, node.loc.end.begin_pos)
|
35
35
|
end
|
36
36
|
|
37
|
+
# A range containing the first to the last argument
|
38
|
+
# of a method call or method definition.
|
39
|
+
# def foo(a, b:)
|
40
|
+
# ^^^^^
|
41
|
+
# bar(1, 2, 3, &blk)
|
42
|
+
# ^^^^^^^^^^^^^
|
43
|
+
# baz { |x, y:, z:| }
|
44
|
+
# ^^^^^^^^^
|
45
|
+
def arguments_range(node)
|
46
|
+
node.first_argument.source_range.join(node.last_argument.source_range)
|
47
|
+
end
|
48
|
+
|
37
49
|
def range_between(start_pos, end_pos)
|
38
50
|
Parser::Source::Range.new(processed_source.buffer, start_pos, end_pos)
|
39
51
|
end
|
@@ -137,11 +137,11 @@ module RuboCop
|
|
137
137
|
|
138
138
|
case depth(stripped_current_path)
|
139
139
|
when 0
|
140
|
-
range = arguments_range(current_path)
|
140
|
+
range = arguments_range(current_path.parent)
|
141
141
|
|
142
142
|
corrector.replace(range, '__FILE__')
|
143
143
|
when 1
|
144
|
-
range = arguments_range(current_path)
|
144
|
+
range = arguments_range(current_path.parent)
|
145
145
|
|
146
146
|
corrector.replace(range, '__dir__')
|
147
147
|
else
|
@@ -185,11 +185,6 @@ module RuboCop
|
|
185
185
|
corrector.remove(node.loc.dot)
|
186
186
|
corrector.remove(node.loc.selector)
|
187
187
|
end
|
188
|
-
|
189
|
-
def arguments_range(node)
|
190
|
-
range_between(node.parent.first_argument.source_range.begin_pos,
|
191
|
-
node.parent.last_argument.source_range.end_pos)
|
192
|
-
end
|
193
188
|
end
|
194
189
|
end
|
195
190
|
end
|
@@ -46,6 +46,7 @@ module RuboCop
|
|
46
46
|
|
47
47
|
MSG = 'Use `%<inverse>s` instead of inverting `%<method>s`.'
|
48
48
|
CLASS_COMPARISON_METHODS = %i[<= >= < >].freeze
|
49
|
+
SAFE_NAVIGATION_INCOMPATIBLE_METHODS = (CLASS_COMPARISON_METHODS + %i[any? none?]).freeze
|
49
50
|
EQUALITY_METHODS = %i[== != =~ !~ <= >= < >].freeze
|
50
51
|
NEGATED_EQUALITY_METHODS = %i[!= !~].freeze
|
51
52
|
CAMEL_CASE = /[A-Z]+[a-z]+/.freeze
|
@@ -77,7 +78,7 @@ module RuboCop
|
|
77
78
|
def on_send(node)
|
78
79
|
inverse_candidate?(node) do |method_call, lhs, method, rhs|
|
79
80
|
return unless inverse_methods.key?(method)
|
80
|
-
return if negated?(node) ||
|
81
|
+
return if negated?(node) || safe_navigation_incompatible?(method_call)
|
81
82
|
return if part_of_ignored_node?(node)
|
82
83
|
return if possible_class_hierarchy_check?(lhs, rhs, method)
|
83
84
|
|
@@ -154,10 +155,6 @@ module RuboCop
|
|
154
155
|
node.parent.respond_to?(:method?) && node.parent.method?(:!)
|
155
156
|
end
|
156
157
|
|
157
|
-
def relational_comparison_with_safe_navigation?(node)
|
158
|
-
node.csend_type? && CLASS_COMPARISON_METHODS.include?(node.method_name)
|
159
|
-
end
|
160
|
-
|
161
158
|
def not_to_receiver(node, method_call)
|
162
159
|
node.loc.selector.begin.join(method_call.source_range.begin)
|
163
160
|
end
|
@@ -166,6 +163,12 @@ module RuboCop
|
|
166
163
|
method_call.source_range.end.join(node.source_range.end)
|
167
164
|
end
|
168
165
|
|
166
|
+
def safe_navigation_incompatible?(node)
|
167
|
+
return false unless node.csend_type?
|
168
|
+
|
169
|
+
SAFE_NAVIGATION_INCOMPATIBLE_METHODS.include?(node.method_name)
|
170
|
+
end
|
171
|
+
|
169
172
|
# When comparing classes, `!(Integer < Numeric)` is not the same as
|
170
173
|
# `Integer > Numeric`.
|
171
174
|
def possible_class_hierarchy_check?(lhs, rhs, method)
|
@@ -42,19 +42,25 @@ module RuboCop
|
|
42
42
|
return if kwarg_nodes.empty?
|
43
43
|
|
44
44
|
add_offense(node) do |corrector|
|
45
|
-
|
46
|
-
|
45
|
+
defining_node = node.each_ancestor(:def, :defs, :block).first
|
46
|
+
next if processed_source.contains_comment?(arguments_range(defining_node))
|
47
|
+
next unless node.parent.find(&:kwoptarg_type?) == node
|
47
48
|
|
48
|
-
|
49
|
-
append_newline_to_last_kwoptarg(arguments, corrector) unless parentheses?(arguments)
|
50
|
-
|
51
|
-
remove_kwargs(kwarg_nodes, corrector)
|
52
|
-
end
|
49
|
+
autocorrect(corrector, node, defining_node, kwarg_nodes)
|
53
50
|
end
|
54
51
|
end
|
55
52
|
|
56
53
|
private
|
57
54
|
|
55
|
+
def autocorrect(corrector, node, defining_node, kwarg_nodes)
|
56
|
+
corrector.insert_before(node, "#{kwarg_nodes.map(&:source).join(', ')}, ")
|
57
|
+
|
58
|
+
arguments = defining_node.arguments
|
59
|
+
append_newline_to_last_kwoptarg(arguments, corrector) unless parentheses?(arguments)
|
60
|
+
|
61
|
+
remove_kwargs(kwarg_nodes, corrector)
|
62
|
+
end
|
63
|
+
|
58
64
|
def append_newline_to_last_kwoptarg(arguments, corrector)
|
59
65
|
last_argument = arguments.last
|
60
66
|
return if last_argument.type?(:kwrestarg, :blockarg)
|
@@ -28,7 +28,7 @@ module RuboCop
|
|
28
28
|
MSG = 'Avoid multi-line chains of blocks.'
|
29
29
|
|
30
30
|
def on_block(node)
|
31
|
-
node.send_node.each_node(:
|
31
|
+
node.send_node.each_node(:call) do |send_node|
|
32
32
|
receiver = send_node.receiver
|
33
33
|
|
34
34
|
next unless receiver&.any_block_type? && receiver.multiline?
|
@@ -50,7 +50,7 @@ module RuboCop
|
|
50
50
|
corrector.remove(range_by_whole_lines(arguments.loc.end, include_final_newline: true))
|
51
51
|
end
|
52
52
|
|
53
|
-
arguments_range = arguments_range(node)
|
53
|
+
arguments_range = range_with_surrounding_space(arguments_range(node), side: :left)
|
54
54
|
# If the method name isn't on the same line as def, move it directly after def
|
55
55
|
if arguments_range.first_line != opening_line(node)
|
56
56
|
corrector.remove(node.loc.name)
|
@@ -66,14 +66,6 @@ module RuboCop
|
|
66
66
|
processed_source[arguments.last_line - 1].strip
|
67
67
|
end
|
68
68
|
|
69
|
-
def arguments_range(node)
|
70
|
-
range = range_between(
|
71
|
-
node.first_argument.source_range.begin_pos, node.last_argument.source_range.end_pos
|
72
|
-
)
|
73
|
-
|
74
|
-
range_with_surrounding_space(range, side: :left)
|
75
|
-
end
|
76
|
-
|
77
69
|
def opening_line(node)
|
78
70
|
node.first_line
|
79
71
|
end
|
@@ -182,9 +182,8 @@ module RuboCop
|
|
182
182
|
return false unless node.ternary? || node.if?
|
183
183
|
|
184
184
|
cond = node.condition
|
185
|
-
|
186
|
-
|
187
|
-
end
|
185
|
+
return false unless cond.call_type?
|
186
|
+
return false if !cond.predicate_method? || allowed_method?(cond.method_name)
|
188
187
|
|
189
188
|
node.if_branch&.true_type? && node.else_branch && !node.else_branch.true_type?
|
190
189
|
end
|
@@ -60,7 +60,7 @@ module RuboCop
|
|
60
60
|
(begin (send !{(str _) array} {:+ :- :* :** :/ :%} {float int}))
|
61
61
|
(begin (send _ {:== :=== :!= :<= :>= :< :>} _))
|
62
62
|
(send _ {:count :length :size} ...)
|
63
|
-
(
|
63
|
+
(any_block (send _ {:count :length :size} ...) ...)
|
64
64
|
}
|
65
65
|
PATTERN
|
66
66
|
end
|
@@ -230,12 +230,6 @@ module RuboCop
|
|
230
230
|
!condition.comparison_method?
|
231
231
|
end
|
232
232
|
|
233
|
-
def arguments_range(node)
|
234
|
-
range_between(
|
235
|
-
node.first_argument.source_range.begin_pos, node.last_argument.source_range.end_pos
|
236
|
-
)
|
237
|
-
end
|
238
|
-
|
239
233
|
def wrap_condition?(node)
|
240
234
|
node.operator_keyword? || (node.call_type? && node.arguments.any? && !node.parenthesized?)
|
241
235
|
end
|
@@ -5,8 +5,11 @@ module RuboCop
|
|
5
5
|
module Utils
|
6
6
|
# Parses {Kernel#sprintf} format strings.
|
7
7
|
class FormatString
|
8
|
+
# Escaping the `#` in `INTERPOLATION` and `TEMPLATE_NAME` is necessary to
|
9
|
+
# avoid a bug in Ruby 3.2.0
|
10
|
+
# See: https://bugs.ruby-lang.org/issues/19379
|
8
11
|
DIGIT_DOLLAR = /(?<arg_number>\d+)\$/.freeze
|
9
|
-
INTERPOLATION =
|
12
|
+
INTERPOLATION = /\#\{.*?\}/.freeze
|
10
13
|
FLAG = /[ #0+-]|#{DIGIT_DOLLAR}/.freeze
|
11
14
|
NUMBER_ARG = /\*#{DIGIT_DOLLAR}?/.freeze
|
12
15
|
NUMBER = /\d+|#{NUMBER_ARG}|#{INTERPOLATION}/.freeze
|
@@ -14,7 +17,7 @@ module RuboCop
|
|
14
17
|
PRECISION = /\.(?<precision>#{NUMBER}?)/.freeze
|
15
18
|
TYPE = /(?<type>[bBdiouxXeEfgGaAcps])/.freeze
|
16
19
|
NAME = /<(?<name>\w+)>/.freeze
|
17
|
-
TEMPLATE_NAME = /(
|
20
|
+
TEMPLATE_NAME = /(?<!\#)\{(?<name>\w+)\}/.freeze
|
18
21
|
|
19
22
|
SEQUENCE = /
|
20
23
|
% (?<type>%)
|
data/lib/rubocop/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.73.
|
4
|
+
version: 1.73.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
- Yuji Nakayama
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2025-
|
12
|
+
date: 2025-03-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -297,6 +297,7 @@ files:
|
|
297
297
|
- lib/rubocop/cop/internal_affairs/node_pattern_groups.rb
|
298
298
|
- lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_processor.rb
|
299
299
|
- lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_walker.rb
|
300
|
+
- lib/rubocop/cop/internal_affairs/node_type_group.rb
|
300
301
|
- lib/rubocop/cop/internal_affairs/node_type_multiple_predicates.rb
|
301
302
|
- lib/rubocop/cop/internal_affairs/node_type_predicate.rb
|
302
303
|
- lib/rubocop/cop/internal_affairs/numblock_handler.rb
|
@@ -1074,7 +1075,7 @@ licenses:
|
|
1074
1075
|
- MIT
|
1075
1076
|
metadata:
|
1076
1077
|
homepage_uri: https://rubocop.org/
|
1077
|
-
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.73.
|
1078
|
+
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.73.2
|
1078
1079
|
source_code_uri: https://github.com/rubocop/rubocop/
|
1079
1080
|
documentation_uri: https://docs.rubocop.org/rubocop/1.73/
|
1080
1081
|
bug_tracker_uri: https://github.com/rubocop/rubocop/issues
|