rubocop 1.75.6 → 1.75.7
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/cop/gemspec/duplicated_assignment.rb +49 -5
- data/lib/rubocop/cop/layout/space_before_brackets.rb +6 -32
- data/lib/rubocop/cop/lint/duplicate_methods.rb +41 -1
- data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +32 -10
- data/lib/rubocop/cop/style/command_literal.rb +1 -1
- data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +4 -7
- data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
- data/lib/rubocop/cop/variable_force/assignment.rb +7 -3
- data/lib/rubocop/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef87f85272e845ecc9477a7c890be9f5d8daa78ef1c9625c3252ca8bee58ee40
|
4
|
+
data.tar.gz: aeb5a1576ba984944521e10cd92933cbf37080d492a25ed8e51bf46926dc0c4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f668097cd95658c24f521bed8e11b43c3b5ff01bdb49bc2e1cc5a71af630cb751a402bf8026f90cb95907fea56ff2cabe5ea0139329fa3e7fc31a46ca615fc4
|
7
|
+
data.tar.gz: cb542cf88e2de605a086e69009dcb8ae2afa4d0b7a713671e6c134cf8b77e5ccd4f6e408c6566be62d57809552e7ef0de30b849b619b0192c358a1441d4060a8
|
@@ -6,10 +6,11 @@ module RuboCop
|
|
6
6
|
# An attribute assignment method calls should be listed only once
|
7
7
|
# in a gemspec.
|
8
8
|
#
|
9
|
-
# Assigning to an attribute with the same name using `spec.foo =`
|
10
|
-
# an unintended usage. On the other hand,
|
11
|
-
# as `spec.requirements`,
|
12
|
-
# permitted because it is
|
9
|
+
# Assigning to an attribute with the same name using `spec.foo =` or
|
10
|
+
# `spec.attribute#[]=` will be an unintended usage. On the other hand,
|
11
|
+
# duplication of methods such # as `spec.requirements`,
|
12
|
+
# `spec.add_runtime_dependency`, and others are permitted because it is
|
13
|
+
# the intended use of appending values.
|
13
14
|
#
|
14
15
|
# @example
|
15
16
|
# # bad
|
@@ -34,6 +35,18 @@ module RuboCop
|
|
34
35
|
# spec.add_dependency('parallel', '~> 1.10')
|
35
36
|
# spec.add_dependency('parser', '>= 2.3.3.1', '< 3.0')
|
36
37
|
# end
|
38
|
+
#
|
39
|
+
# # bad
|
40
|
+
# Gem::Specification.new do |spec|
|
41
|
+
# spec.metadata["key"] = "value"
|
42
|
+
# spec.metadata["key"] = "value"
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# # good
|
46
|
+
# Gem::Specification.new do |spec|
|
47
|
+
# spec.metadata["key"] = "value"
|
48
|
+
# end
|
49
|
+
#
|
37
50
|
class DuplicatedAssignment < Base
|
38
51
|
include RangeHelp
|
39
52
|
include GemspecHelp
|
@@ -47,9 +60,26 @@ module RuboCop
|
|
47
60
|
(lvar #match_block_variable_name?) _ ...)
|
48
61
|
PATTERN
|
49
62
|
|
63
|
+
# @!method indexed_assignment_method_declarations(node)
|
64
|
+
def_node_search :indexed_assignment_method_declarations, <<~PATTERN
|
65
|
+
(send
|
66
|
+
(send (lvar #match_block_variable_name?) _)
|
67
|
+
:[]=
|
68
|
+
literal?
|
69
|
+
_
|
70
|
+
)
|
71
|
+
PATTERN
|
72
|
+
|
50
73
|
def on_new_investigation
|
51
74
|
return if processed_source.blank?
|
52
75
|
|
76
|
+
process_assignment_method_nodes
|
77
|
+
process_indexed_assignment_method_nodes
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def process_assignment_method_nodes
|
53
83
|
duplicated_assignment_method_nodes.each do |nodes|
|
54
84
|
nodes[1..].each do |node|
|
55
85
|
register_offense(node, node.method_name, nodes.first.first_line)
|
@@ -57,7 +87,14 @@ module RuboCop
|
|
57
87
|
end
|
58
88
|
end
|
59
89
|
|
60
|
-
|
90
|
+
def process_indexed_assignment_method_nodes
|
91
|
+
duplicated_indexed_assignment_method_nodes.each do |nodes|
|
92
|
+
nodes[1..].each do |node|
|
93
|
+
assignment = "#{node.children.first.method_name}[#{node.first_argument.source}]="
|
94
|
+
register_offense(node, assignment, nodes.first.first_line)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
61
98
|
|
62
99
|
def match_block_variable_name?(receiver_name)
|
63
100
|
gem_specification(processed_source.ast) do |block_variable_name|
|
@@ -73,6 +110,13 @@ module RuboCop
|
|
73
110
|
.select { |nodes| nodes.size > 1 }
|
74
111
|
end
|
75
112
|
|
113
|
+
def duplicated_indexed_assignment_method_nodes
|
114
|
+
indexed_assignment_method_declarations(processed_source.ast)
|
115
|
+
.group_by { |node| [node.children.first.method_name, node.first_argument] }
|
116
|
+
.values
|
117
|
+
.select { |nodes| nodes.size > 1 }
|
118
|
+
end
|
119
|
+
|
76
120
|
def register_offense(node, assignment, line_of_first_occurrence)
|
77
121
|
line_range = node.loc.column...node.loc.last_column
|
78
122
|
offense_location = source_range(processed_source.buffer, node.first_line, line_range)
|
@@ -22,51 +22,25 @@ module RuboCop
|
|
22
22
|
RESTRICT_ON_SEND = %i[[] []=].freeze
|
23
23
|
|
24
24
|
def on_send(node)
|
25
|
-
return unless (first_argument = node.first_argument)
|
26
|
-
|
27
|
-
begin_pos = first_argument.source_range.begin_pos
|
28
|
-
return unless (range = offense_range(node, begin_pos))
|
29
|
-
|
30
|
-
register_offense(range)
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def offense_range(node, begin_pos)
|
36
25
|
receiver_end_pos = node.receiver.source_range.end_pos
|
37
26
|
selector_begin_pos = node.loc.selector.begin_pos
|
38
27
|
return if receiver_end_pos >= selector_begin_pos
|
39
28
|
return if dot_before_brackets?(node, receiver_end_pos, selector_begin_pos)
|
40
29
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
30
|
+
range = range_between(receiver_end_pos, selector_begin_pos)
|
31
|
+
|
32
|
+
add_offense(range) do |corrector|
|
33
|
+
corrector.remove(range)
|
45
34
|
end
|
46
35
|
end
|
47
36
|
|
37
|
+
private
|
38
|
+
|
48
39
|
def dot_before_brackets?(node, receiver_end_pos, selector_begin_pos)
|
49
40
|
return false unless node.loc.respond_to?(:dot) && (dot = node.loc.dot)
|
50
41
|
|
51
42
|
dot.begin_pos == receiver_end_pos && dot.end_pos == selector_begin_pos
|
52
43
|
end
|
53
|
-
|
54
|
-
def offense_range_for_assignment(node, begin_pos)
|
55
|
-
end_pos = node.receiver.source_range.end_pos
|
56
|
-
|
57
|
-
return if begin_pos - end_pos == 1 ||
|
58
|
-
(range = range_between(end_pos, begin_pos - 1)).source.start_with?('[')
|
59
|
-
|
60
|
-
range
|
61
|
-
end
|
62
|
-
|
63
|
-
def register_offense(range)
|
64
|
-
add_offense(range) { |corrector| corrector.remove(range) }
|
65
|
-
end
|
66
|
-
|
67
|
-
def reference_variable_with_brackets?(node)
|
68
|
-
node.receiver&.variable? && node.method?(:[]) && node.arguments.size == 1
|
69
|
-
end
|
70
44
|
end
|
71
45
|
end
|
72
46
|
end
|
@@ -64,6 +64,23 @@ module RuboCop
|
|
64
64
|
# end
|
65
65
|
#
|
66
66
|
# delegate :baz, to: :bar
|
67
|
+
#
|
68
|
+
# # good - delegate with splat arguments is ignored
|
69
|
+
# def foo
|
70
|
+
# 1
|
71
|
+
# end
|
72
|
+
#
|
73
|
+
# delegate :foo, **options
|
74
|
+
#
|
75
|
+
# # good - delegate inside a condition is ignored
|
76
|
+
# def foo
|
77
|
+
# 1
|
78
|
+
# end
|
79
|
+
#
|
80
|
+
# if cond
|
81
|
+
# delegate :foo, to: :bar
|
82
|
+
# end
|
83
|
+
#
|
67
84
|
class DuplicateMethods < Base
|
68
85
|
MSG = 'Method `%<method>s` is defined at both %<defined>s and %<current>s.'
|
69
86
|
RESTRICT_ON_SEND = %i[alias_method attr_reader attr_writer attr_accessor attr
|
@@ -113,7 +130,10 @@ module RuboCop
|
|
113
130
|
|
114
131
|
# @!method delegate_method?(node)
|
115
132
|
def_node_matcher :delegate_method?, <<~PATTERN
|
116
|
-
(send nil? :delegate
|
133
|
+
(send nil? :delegate
|
134
|
+
({sym str} $_)+
|
135
|
+
(hash <(pair (sym :to) _) ...>)
|
136
|
+
)
|
117
137
|
PATTERN
|
118
138
|
|
119
139
|
# @!method sym_name(node)
|
@@ -155,11 +175,31 @@ module RuboCop
|
|
155
175
|
end
|
156
176
|
|
157
177
|
def on_delegate(node, method_names)
|
178
|
+
name_prefix = delegate_prefix(node)
|
179
|
+
|
158
180
|
method_names.each do |name|
|
181
|
+
name = "#{name_prefix}_#{name}" if name_prefix
|
182
|
+
|
159
183
|
found_instance_method(node, name)
|
160
184
|
end
|
161
185
|
end
|
162
186
|
|
187
|
+
def delegate_prefix(node)
|
188
|
+
kwargs_node = node.last_argument
|
189
|
+
|
190
|
+
return unless (prefix = hash_value(kwargs_node, :prefix))
|
191
|
+
|
192
|
+
if prefix.true_type?
|
193
|
+
hash_value(kwargs_node, :to).value
|
194
|
+
elsif prefix.type?(:sym, :str)
|
195
|
+
prefix.value
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def hash_value(node, key)
|
200
|
+
node.pairs.find { |pair| pair.key.value == key }&.value
|
201
|
+
end
|
202
|
+
|
163
203
|
def found_instance_method(node, name)
|
164
204
|
return found_sclass_method(node, name) unless (scope = node.parent_module_name)
|
165
205
|
|
@@ -39,7 +39,7 @@ module RuboCop
|
|
39
39
|
class AbcSize < Base
|
40
40
|
include MethodComplexity
|
41
41
|
|
42
|
-
MSG = 'Assignment Branch Condition size for
|
42
|
+
MSG = 'Assignment Branch Condition size for `%<method>s` is too high. ' \
|
43
43
|
'[%<abc_vector>s %<complexity>.4g/%<max>.4g]'
|
44
44
|
|
45
45
|
private
|
@@ -195,15 +195,27 @@ module RuboCop
|
|
195
195
|
def autocorrect(corrector, node)
|
196
196
|
case style
|
197
197
|
when :group
|
198
|
-
|
199
|
-
return unless def_nodes.any?
|
200
|
-
|
201
|
-
replace_defs(corrector, node, def_nodes)
|
198
|
+
autocorrect_group_style(corrector, node)
|
202
199
|
when :inline
|
200
|
+
autocorrect_inline_style(corrector, node)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def autocorrect_group_style(corrector, node)
|
205
|
+
def_nodes = find_corresponding_def_nodes(node)
|
206
|
+
return unless def_nodes.any?
|
207
|
+
|
208
|
+
replace_defs(corrector, node, def_nodes)
|
209
|
+
end
|
210
|
+
|
211
|
+
def autocorrect_inline_style(corrector, node)
|
212
|
+
if node.parent&.begin_type?
|
213
|
+
remove_modifier_node_within_begin(corrector, node, node.parent)
|
214
|
+
else
|
203
215
|
remove_nodes(corrector, node)
|
204
|
-
|
205
|
-
|
206
|
-
|
216
|
+
end
|
217
|
+
select_grouped_def_nodes(node).each do |grouped_def_node|
|
218
|
+
insert_inline_modifier(corrector, grouped_def_node, node.method_name)
|
207
219
|
end
|
208
220
|
end
|
209
221
|
|
@@ -224,9 +236,13 @@ module RuboCop
|
|
224
236
|
end
|
225
237
|
|
226
238
|
def offense?(node)
|
227
|
-
|
228
|
-
|
229
|
-
|
239
|
+
if group_style?
|
240
|
+
return false if node.parent ? node.parent.if_type? : access_modifier_with_symbol?(node)
|
241
|
+
|
242
|
+
access_modifier_is_inlined?(node) && !right_siblings_same_inline_method?(node)
|
243
|
+
else
|
244
|
+
access_modifier_is_not_inlined?(node) && select_grouped_def_nodes(node).any?
|
245
|
+
end
|
230
246
|
end
|
231
247
|
|
232
248
|
def correctable_group_offense?(node)
|
@@ -331,6 +347,12 @@ module RuboCop
|
|
331
347
|
end
|
332
348
|
end
|
333
349
|
|
350
|
+
def remove_modifier_node_within_begin(corrector, modifier_node, begin_node)
|
351
|
+
def_node = begin_node.children[1]
|
352
|
+
range = modifier_node.source_range.begin.join(def_node.source_range.begin)
|
353
|
+
corrector.remove(range)
|
354
|
+
end
|
355
|
+
|
334
356
|
def def_source(node, def_nodes)
|
335
357
|
[
|
336
358
|
*processed_source.ast_with_comments[node].map(&:text),
|
@@ -28,19 +28,16 @@ module RuboCop
|
|
28
28
|
|
29
29
|
MSG = 'Avoid modifier `%<keyword>s` after another conditional.'
|
30
30
|
|
31
|
+
# rubocop:disable Metrics/AbcSize
|
31
32
|
def on_if(node)
|
32
33
|
return unless node.modifier_form? && node.body.if_type?
|
33
34
|
|
34
35
|
add_offense(node.loc.keyword, message: format(MSG, keyword: node.keyword)) do |corrector|
|
35
|
-
keyword
|
36
|
-
|
37
|
-
corrector.replace(node, <<~RUBY.chop)
|
38
|
-
#{keyword} #{node.condition.source}
|
39
|
-
#{node.if_branch.source}
|
40
|
-
end
|
41
|
-
RUBY
|
36
|
+
corrector.wrap(node.if_branch, "#{node.keyword} #{node.condition.source}\n", "\nend")
|
37
|
+
corrector.remove(node.if_branch.source_range.end.join(node.condition.source_range.end))
|
42
38
|
end
|
43
39
|
end
|
40
|
+
# rubocop:enable Metrics/AbcSize
|
44
41
|
end
|
45
42
|
end
|
46
43
|
end
|
@@ -155,7 +155,7 @@ module RuboCop
|
|
155
155
|
end
|
156
156
|
|
157
157
|
def preferred_delimiters
|
158
|
-
config.for_cop('Style/PercentLiteralDelimiters')
|
158
|
+
config.for_cop('Style/PercentLiteralDelimiters')['PreferredDelimiters']['%r'].chars
|
159
159
|
end
|
160
160
|
|
161
161
|
def allowed_omit_parentheses_with_percent_r_literal?(node)
|
@@ -110,8 +110,13 @@ module RuboCop
|
|
110
110
|
end
|
111
111
|
|
112
112
|
def multiple_assignment_node
|
113
|
-
return nil unless node.parent
|
114
|
-
|
113
|
+
return nil unless (candidate_mlhs_node = node.parent)
|
114
|
+
|
115
|
+
# In `(foo, bar), *baz`, the splat node must be traversed as well.
|
116
|
+
candidate_mlhs_node = candidate_mlhs_node.parent if candidate_mlhs_node.splat_type?
|
117
|
+
|
118
|
+
return nil unless candidate_mlhs_node.mlhs_type?
|
119
|
+
return nil unless (grandparent_node = node.parent.parent)
|
115
120
|
if (node = find_multiple_assignment_node(grandparent_node))
|
116
121
|
return node
|
117
122
|
end
|
@@ -139,7 +144,6 @@ module RuboCop
|
|
139
144
|
|
140
145
|
def find_multiple_assignment_node(grandparent_node)
|
141
146
|
return unless grandparent_node.type == MULTIPLE_LEFT_HAND_SIDE_TYPE
|
142
|
-
return if grandparent_node.children.any?(&:splat_type?)
|
143
147
|
|
144
148
|
parent = grandparent_node.parent
|
145
149
|
return parent if parent.type == MULTIPLE_ASSIGNMENT_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.75.
|
4
|
+
version: 1.75.7
|
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-05-
|
12
|
+
date: 2025-05-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -1080,7 +1080,7 @@ licenses:
|
|
1080
1080
|
- MIT
|
1081
1081
|
metadata:
|
1082
1082
|
homepage_uri: https://rubocop.org/
|
1083
|
-
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.75.
|
1083
|
+
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.75.7
|
1084
1084
|
source_code_uri: https://github.com/rubocop/rubocop/
|
1085
1085
|
documentation_uri: https://docs.rubocop.org/rubocop/1.75/
|
1086
1086
|
bug_tracker_uri: https://github.com/rubocop/rubocop/issues
|