rubocop 1.76.0 → 1.76.1
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 +2 -2
- data/lib/rubocop/cop/lint/empty_interpolation.rb +1 -1
- data/lib/rubocop/cop/naming/predicate_method.rb +1 -1
- data/lib/rubocop/cop/style/redundant_array_flatten.rb +3 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +3 -2
- data/lib/rubocop/cop/style/safe_navigation.rb +14 -4
- data/lib/rubocop/rspec/expect_offense.rb +9 -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: b3a37fd910269f3c84074e6a29c94c43e0deb0ed967d6ce879fbfd6b45380db7
|
4
|
+
data.tar.gz: 65e707c85e20a9242af4bdc21b4bf0bf3d46e9646dc74a981dfe2a3691102d3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1255eac20671a11a1efd42d85696125d0394673b9343b99fc8205275b66445adb99b79da7e9ecc2c457c1e2bf86d57a207c4d7def8d17b6d13abbb6bd08aa574
|
7
|
+
data.tar.gz: bf23d4d52d27505fc7bcfdaf992fb3d942261bc9eaea475c8374ea991352b47b10938e5e7ac1d19d84a44e0fac0683eb6d01218a136be5b2eb39aa3504a376c6
|
data/config/default.yml
CHANGED
@@ -2689,7 +2689,7 @@ Metrics/AbcSize:
|
|
2689
2689
|
A calculated magnitude based on number of assignments,
|
2690
2690
|
branches, and conditions.
|
2691
2691
|
References:
|
2692
|
-
-
|
2692
|
+
- https://wiki.c2.com/?AbcMetric
|
2693
2693
|
- https://en.wikipedia.org/wiki/ABC_Software_Metric
|
2694
2694
|
Enabled: true
|
2695
2695
|
VersionAdded: '0.27'
|
@@ -5006,7 +5006,7 @@ Style/OpenStructUse:
|
|
5006
5006
|
Avoid using OpenStruct. As of Ruby 3.0, use is officially discouraged due to performance,
|
5007
5007
|
version compatibility, and potential security issues.
|
5008
5008
|
References:
|
5009
|
-
- https://docs.ruby-lang.org/en/3.0
|
5009
|
+
- https://docs.ruby-lang.org/en/3.0/OpenStruct.html#class-OpenStruct-label-Caveats
|
5010
5010
|
|
5011
5011
|
Enabled: pending
|
5012
5012
|
Safe: false
|
@@ -20,7 +20,7 @@ module RuboCop
|
|
20
20
|
|
21
21
|
def on_interpolation(begin_node)
|
22
22
|
node_children = begin_node.children.dup
|
23
|
-
node_children.delete_if { |e| e
|
23
|
+
node_children.delete_if { |e| e.nil_type? || (e.basic_literal? && e.value.to_s.empty?) }
|
24
24
|
return unless node_children.empty?
|
25
25
|
|
26
26
|
add_offense(begin_node) { |corrector| corrector.remove(begin_node) }
|
@@ -169,7 +169,7 @@ module RuboCop
|
|
169
169
|
|
170
170
|
def last_value(node)
|
171
171
|
value = node.begin_type? ? node.children.last : node
|
172
|
-
value
|
172
|
+
value&.return_type? ? extract_return_value(value) : value
|
173
173
|
end
|
174
174
|
|
175
175
|
def process_return_values(return_values)
|
@@ -12,6 +12,8 @@ module RuboCop
|
|
12
12
|
# Cop is unsafe because the receiver of `flatten` method might not
|
13
13
|
# be an `Array`, so it's possible it won't respond to `join` method,
|
14
14
|
# or the end result would be different.
|
15
|
+
# Also, if the global variable `$,` is set to a value other than the default `nil`,
|
16
|
+
# false positives may occur.
|
15
17
|
#
|
16
18
|
# @example
|
17
19
|
# # bad
|
@@ -30,7 +32,7 @@ module RuboCop
|
|
30
32
|
|
31
33
|
# @!method flatten_join?(node)
|
32
34
|
def_node_matcher :flatten_join?, <<~PATTERN
|
33
|
-
(call (call !nil? :flatten _?) :join
|
35
|
+
(call (call !nil? :flatten _?) :join (nil)?)
|
34
36
|
PATTERN
|
35
37
|
|
36
38
|
def on_send(node)
|
@@ -164,8 +164,9 @@ module RuboCop
|
|
164
164
|
if node.lambda_or_proc? && (node.braces? || node.send_node.lambda_literal?)
|
165
165
|
return 'an expression'
|
166
166
|
end
|
167
|
-
|
168
|
-
|
167
|
+
if node.any_match_pattern_type? && node.each_ancestor.none?(&:operator_keyword?)
|
168
|
+
return 'a one-line pattern matching'
|
169
|
+
end
|
169
170
|
return 'an interpolated expression' if interpolation?(begin_node)
|
170
171
|
return 'a method argument' if argument_of_parenthesized_method_call?(begin_node, node)
|
171
172
|
|
@@ -86,6 +86,10 @@ module RuboCop
|
|
86
86
|
# foo.baz = bar if foo
|
87
87
|
# foo.baz + bar if foo
|
88
88
|
# foo.bar > 2 if foo
|
89
|
+
#
|
90
|
+
# foo ? foo[index] : nil # Ignored `foo&.[](index)` due to unclear readability benefit.
|
91
|
+
# foo ? foo[idx] = v : nil # Ignored `foo&.[]=(idx, v)` due to unclear readability benefit.
|
92
|
+
# foo ? foo * 42 : nil # Ignored `foo&.*(42)` due to unclear readability benefit.
|
89
93
|
class SafeNavigation < Base # rubocop:disable Metrics/ClassLength
|
90
94
|
include NilMethods
|
91
95
|
include RangeHelp
|
@@ -146,6 +150,7 @@ module RuboCop
|
|
146
150
|
|
147
151
|
body = extract_if_body(node)
|
148
152
|
method_call = receiver.parent
|
153
|
+
return if dotless_operator_call?(method_call) || method_call.double_colon?
|
149
154
|
|
150
155
|
removal_ranges = [begin_range(node, body), end_range(node, body)]
|
151
156
|
|
@@ -181,6 +186,8 @@ module RuboCop
|
|
181
186
|
end
|
182
187
|
end
|
183
188
|
|
189
|
+
private
|
190
|
+
|
184
191
|
def report_offense(node, rhs, rhs_receiver, *removal_ranges, offense_range: node)
|
185
192
|
add_offense(offense_range) do |corrector|
|
186
193
|
next if ignored_node?(node)
|
@@ -198,8 +205,6 @@ module RuboCop
|
|
198
205
|
end
|
199
206
|
end
|
200
207
|
|
201
|
-
private
|
202
|
-
|
203
208
|
def find_method_chain(node)
|
204
209
|
return node unless node&.parent&.call_type?
|
205
210
|
|
@@ -253,6 +258,12 @@ module RuboCop
|
|
253
258
|
end
|
254
259
|
end
|
255
260
|
|
261
|
+
def dotless_operator_call?(method_call)
|
262
|
+
return false if method_call.loc.dot
|
263
|
+
|
264
|
+
method_call.method?(:[]) || method_call.method?(:[]=) || method_call.operator_method?
|
265
|
+
end
|
266
|
+
|
256
267
|
def handle_comments(corrector, node, method_call)
|
257
268
|
comments = comments(node)
|
258
269
|
return if comments.empty?
|
@@ -380,8 +391,7 @@ module RuboCop
|
|
380
391
|
method_chain)
|
381
392
|
start_method.each_ancestor do |ancestor|
|
382
393
|
break unless %i[send block].include?(ancestor.type)
|
383
|
-
next
|
384
|
-
next if ancestor.safe_navigation?
|
394
|
+
next if !ancestor.send_type? || ancestor.operator_method?
|
385
395
|
|
386
396
|
corrector.insert_before(ancestor.loc.dot, '&')
|
387
397
|
|
@@ -72,9 +72,15 @@ module RuboCop
|
|
72
72
|
#
|
73
73
|
# expect_no_corrections
|
74
74
|
#
|
75
|
-
# If your code has variables of different lengths, you can use
|
76
|
-
#
|
77
|
-
#
|
75
|
+
# If your code has variables of different lengths, you can use the
|
76
|
+
# following markers to format your template by passing the variables as a
|
77
|
+
# keyword arguments:
|
78
|
+
#
|
79
|
+
# - `%{foo}`: Interpolates `foo`
|
80
|
+
# - `^{foo}`: Inserts `'^' * foo.size` for dynamic offense range length
|
81
|
+
# - `_{foo}`: Inserts `' ' * foo.size` for dynamic offense range indentation
|
82
|
+
#
|
83
|
+
# You can also abbreviate offense messages with `[...]`.
|
78
84
|
#
|
79
85
|
# %w[raise fail].each do |keyword|
|
80
86
|
# expect_offense(<<~RUBY, keyword: keyword)
|
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.76.
|
4
|
+
version: 1.76.1
|
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-06-
|
12
|
+
date: 2025-06-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -1085,7 +1085,7 @@ licenses:
|
|
1085
1085
|
- MIT
|
1086
1086
|
metadata:
|
1087
1087
|
homepage_uri: https://rubocop.org/
|
1088
|
-
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.76.
|
1088
|
+
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.76.1
|
1089
1089
|
source_code_uri: https://github.com/rubocop/rubocop/
|
1090
1090
|
documentation_uri: https://docs.rubocop.org/rubocop/1.76/
|
1091
1091
|
bug_tracker_uri: https://github.com/rubocop/rubocop/issues
|