rubocop 1.75.3 → 1.75.4
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/lint/boolean_symbol.rb +1 -1
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +2 -5
- data/lib/rubocop/cop/lint/literal_as_condition.rb +25 -11
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/style/arguments_forwarding.rb +1 -1
- data/lib/rubocop/cop/style/class_and_module_children.rb +12 -2
- data/lib/rubocop/cop/style/comparable_between.rb +2 -2
- data/lib/rubocop/cop/style/redundant_parentheses.rb +11 -3
- data/lib/rubocop/cop/style/safe_navigation.rb +1 -1
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +7 -1
- data/lib/rubocop/rspec/cop_helper.rb +2 -2
- data/lib/rubocop/rspec/shared_contexts.rb +1 -2
- 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: 4fc4cebf1565ee3ced4efc79eb1012c0750f797f0ba74f94620ff50ff1d7be8e
|
4
|
+
data.tar.gz: b1e53688b07611ebec3ebc028022f71314960573cc421cfdd1b6c6b831008abf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b124c47ddee3e947bbcda187086ae1a8bf45317702d6ab0bc43f7888b90c8d560c12f61ae6fc4890bf5fec29016d88678cbc08db84e9dad5ee3ec242c8e03884
|
7
|
+
data.tar.gz: fcc14e85af8aac9186971fa21371743f29221c8e694c7cf17b44762d628c7246d720b3e241f006286a43f3523e6ab9e587e0c2f0aecb5d34fe849375ca7ad183
|
@@ -48,7 +48,7 @@ module RuboCop
|
|
48
48
|
def autocorrect(corrector, node)
|
49
49
|
boolean_literal = node.source.delete(':')
|
50
50
|
parent = node.parent
|
51
|
-
if parent&.pair_type? && node.equal?(parent.children[0])
|
51
|
+
if parent&.pair_type? && parent.colon? && node.equal?(parent.children[0])
|
52
52
|
corrector.remove(parent.loc.operator)
|
53
53
|
boolean_literal = "#{node.source} =>"
|
54
54
|
end
|
@@ -6,9 +6,8 @@ module RuboCop
|
|
6
6
|
# Checks for circular argument references in optional keyword
|
7
7
|
# arguments and optional ordinal arguments.
|
8
8
|
#
|
9
|
-
# This
|
10
|
-
#
|
11
|
-
# NOTE: This syntax is no longer valid on Ruby 2.7 or higher.
|
9
|
+
# NOTE: This syntax was made invalid on Ruby 2.7 - Ruby 3.3 but is allowed
|
10
|
+
# again since Ruby 3.4.
|
12
11
|
#
|
13
12
|
# @example
|
14
13
|
#
|
@@ -41,8 +40,6 @@ module RuboCop
|
|
41
40
|
|
42
41
|
MSG = 'Circular argument reference - `%<arg_name>s`.'
|
43
42
|
|
44
|
-
maximum_target_ruby_version 2.6
|
45
|
-
|
46
43
|
def on_kwoptarg(node)
|
47
44
|
check_for_circular_argument_references(*node)
|
48
45
|
end
|
@@ -57,13 +57,9 @@ module RuboCop
|
|
57
57
|
def on_if(node)
|
58
58
|
cond = condition(node)
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
else
|
64
|
-
correct_if_node(node, cond, true) if cond.truthy_literal?
|
65
|
-
correct_if_node(node, cond, false) if cond.falsey_literal?
|
66
|
-
end
|
60
|
+
return unless cond.falsey_literal? || cond.truthy_literal?
|
61
|
+
|
62
|
+
correct_if_node(node, cond)
|
67
63
|
end
|
68
64
|
|
69
65
|
def on_while(node)
|
@@ -232,9 +228,27 @@ module RuboCop
|
|
232
228
|
)
|
233
229
|
end
|
234
230
|
|
235
|
-
|
236
|
-
|
237
|
-
|
231
|
+
def condition_evaluation(node, cond)
|
232
|
+
if node.unless?
|
233
|
+
cond.falsey_literal?
|
234
|
+
else
|
235
|
+
cond.truthy_literal?
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
240
|
+
def correct_if_node(node, cond)
|
241
|
+
result = condition_evaluation(node, cond)
|
242
|
+
|
243
|
+
if node.elsif? && result
|
244
|
+
add_offense(cond) do |corrector|
|
245
|
+
corrector.replace(node, "else\n #{node.if_branch.source}")
|
246
|
+
end
|
247
|
+
elsif node.elsif? && !result
|
248
|
+
add_offense(cond) do |corrector|
|
249
|
+
corrector.replace(node, "else\n #{node.else_branch.source}")
|
250
|
+
end
|
251
|
+
elsif result
|
238
252
|
add_offense(cond) do |corrector|
|
239
253
|
corrector.replace(node, node.if_branch.source)
|
240
254
|
end
|
@@ -252,7 +266,7 @@ module RuboCop
|
|
252
266
|
end
|
253
267
|
end
|
254
268
|
end
|
255
|
-
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
269
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
256
270
|
end
|
257
271
|
end
|
258
272
|
end
|
@@ -107,7 +107,7 @@ module RuboCop
|
|
107
107
|
# of the argument is not considered multiline, even if the argument
|
108
108
|
# itself might span multiple lines.
|
109
109
|
def allowed_multiline_argument?(node)
|
110
|
-
elements(node).one? && !Util.begins_its_line?(node.loc.end)
|
110
|
+
elements(node).one? && (!node.loc.end || !Util.begins_its_line?(node.loc.end))
|
111
111
|
end
|
112
112
|
|
113
113
|
def elements(node)
|
@@ -146,7 +146,7 @@ module RuboCop
|
|
146
146
|
minimum_target_ruby_version 2.7
|
147
147
|
|
148
148
|
FORWARDING_LVAR_TYPES = %i[splat kwsplat block_pass].freeze
|
149
|
-
ADDITIONAL_ARG_TYPES = %i[lvar arg].freeze
|
149
|
+
ADDITIONAL_ARG_TYPES = %i[lvar arg optarg].freeze
|
150
150
|
|
151
151
|
FORWARDING_MSG = 'Use shorthand syntax `...` for arguments forwarding.'
|
152
152
|
ARGS_MSG = 'Use anonymous positional arguments forwarding (`*`).'
|
@@ -149,9 +149,9 @@ module RuboCop
|
|
149
149
|
return unless node.body.children.last
|
150
150
|
|
151
151
|
last_child_leading_spaces = leading_spaces(node.body.children.last)
|
152
|
-
return if leading_spaces(node)
|
152
|
+
return if spaces_size(leading_spaces(node)) == spaces_size(last_child_leading_spaces)
|
153
153
|
|
154
|
-
column_delta = configured_indentation_width - last_child_leading_spaces
|
154
|
+
column_delta = configured_indentation_width - spaces_size(last_child_leading_spaces)
|
155
155
|
return if column_delta.zero?
|
156
156
|
|
157
157
|
AlignmentCorrector.correct(corrector, processed_source, node, column_delta)
|
@@ -161,6 +161,16 @@ module RuboCop
|
|
161
161
|
node.source_range.source_line[/\A\s*/]
|
162
162
|
end
|
163
163
|
|
164
|
+
def spaces_size(spaces_string)
|
165
|
+
mapping = { "\t" => tab_indentation_width }
|
166
|
+
spaces_string.chars.sum { |character| mapping.fetch(character, 1) }
|
167
|
+
end
|
168
|
+
|
169
|
+
def tab_indentation_width
|
170
|
+
config.for_cop('Layout/IndentationStyle')['IndentationWidth'] ||
|
171
|
+
configured_indentation_width
|
172
|
+
end
|
173
|
+
|
164
174
|
def check_style(node, body, style)
|
165
175
|
return if node.identifier.namespace&.cbase_type?
|
166
176
|
|
@@ -61,8 +61,8 @@ module RuboCop
|
|
61
61
|
|
62
62
|
def register_offense(node, min_and_value, max_and_value)
|
63
63
|
value = (min_and_value & max_and_value).first
|
64
|
-
min = min_and_value.find { _1 != value }
|
65
|
-
max = max_and_value.find { _1 != value }
|
64
|
+
min = min_and_value.find { _1 != value } || value
|
65
|
+
max = max_and_value.find { _1 != value } || value
|
66
66
|
|
67
67
|
prefer = "#{value.source}.between?(#{min.source}, #{max.source})"
|
68
68
|
add_offense(node, message: format(MSG, prefer: prefer)) do |corrector|
|
@@ -180,10 +180,18 @@ module RuboCop
|
|
180
180
|
# @!method interpolation?(node)
|
181
181
|
def_node_matcher :interpolation?, '[^begin ^^dstr]'
|
182
182
|
|
183
|
-
def argument_of_parenthesized_method_call?(
|
184
|
-
|
183
|
+
def argument_of_parenthesized_method_call?(begin_node)
|
184
|
+
node = begin_node.children.first
|
185
|
+
return false if node.basic_conditional? || method_call_parentheses_required?(node)
|
186
|
+
return false unless (parent = begin_node.parent)
|
187
|
+
|
188
|
+
parent.call_type? && parent.parenthesized? && parent.receiver != begin_node
|
189
|
+
end
|
190
|
+
|
191
|
+
def method_call_parentheses_required?(node)
|
192
|
+
return false unless node.call_type?
|
185
193
|
|
186
|
-
|
194
|
+
(node.receiver.nil? || node.loc.dot) && node.arguments.any?
|
187
195
|
end
|
188
196
|
|
189
197
|
def allow_in_multiline_conditions?
|
@@ -321,7 +321,7 @@ module RuboCop
|
|
321
321
|
end
|
322
322
|
|
323
323
|
def matching_call_nodes?(left, right)
|
324
|
-
return false unless left && right
|
324
|
+
return false unless left && right.respond_to?(:call_type?)
|
325
325
|
|
326
326
|
left.call_type? && right.call_type? && left.children == right.children
|
327
327
|
end
|
@@ -79,10 +79,16 @@ module RuboCop
|
|
79
79
|
# # bad
|
80
80
|
# method(1, 2,)
|
81
81
|
#
|
82
|
+
# # bad
|
83
|
+
# object[1, 2,]
|
84
|
+
#
|
82
85
|
# # good
|
83
86
|
# method(1, 2)
|
84
87
|
#
|
85
88
|
# # good
|
89
|
+
# object[1, 2]
|
90
|
+
#
|
91
|
+
# # good
|
86
92
|
# method(
|
87
93
|
# 1,
|
88
94
|
# 2
|
@@ -96,7 +102,7 @@ module RuboCop
|
|
96
102
|
end
|
97
103
|
|
98
104
|
def on_send(node)
|
99
|
-
return unless node.arguments? && node.parenthesized?
|
105
|
+
return unless node.arguments? && (node.parenthesized? || node.method?(:[]))
|
100
106
|
|
101
107
|
check(node, node.arguments, 'parameter of %<article>s method call',
|
102
108
|
node.last_argument.source_range.end_pos,
|
@@ -11,8 +11,8 @@ module CopHelper
|
|
11
11
|
ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : RuboCop::TargetRuby::DEFAULT_VERSION
|
12
12
|
end
|
13
13
|
let(:parser_engine) do
|
14
|
-
# The maximum version Parser can parse is 3.
|
15
|
-
ruby_version >= 3.
|
14
|
+
# The maximum version Parser can correctly parse is 3.3.
|
15
|
+
ruby_version >= 3.4 ? :parser_prism : ENV.fetch('PARSER_ENGINE', :parser_whitequark).to_sym
|
16
16
|
end
|
17
17
|
let(:rails_version) { false }
|
18
18
|
|
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.4
|
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-04-
|
12
|
+
date: 2025-04-28 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.4
|
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
|