rubocop 1.80.0 → 1.80.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/lib/rubocop/cop/correctors/alignment_corrector.rb +6 -3
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -0
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -7
- data/lib/rubocop/cop/naming/predicate_method.rb +3 -2
- data/lib/rubocop/cop/style/redundant_begin.rb +2 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +12 -10
- data/lib/rubocop/cop/style/safe_navigation.rb +6 -0
- data/lib/rubocop/cop/style/string_concatenation.rb +17 -13
- data/lib/rubocop/result_cache.rb +1 -1
- data/lib/rubocop/runner.rb +6 -4
- 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: 427aedeb12fa3d9d84e7ccd8ea4c125b418a3170c0f91d02e66ef8717006fc0a
|
4
|
+
data.tar.gz: f5a5b09520f27ed77d9cc5e2077ce9a55fa77db97bdd1d593e399551abd45bb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddcf6fc4b8e900f900f5734c647b3d681d731d6d4bf37729c4960a751ace231d8835ca9800d4e499d1908f7e0474445bbf2490f5c8b9408d1301d6bff1196794
|
7
|
+
data.tar.gz: 94f856e78e6af3c0c78fd926268ae8349af663c2e7a1bc40a11842bb04db7a6baa1f239cb2c537ef8b442a4a76dfc09a8a7bfe10244abb2a78ed3b3b6600d38b
|
@@ -29,10 +29,13 @@ module RuboCop
|
|
29
29
|
def align_end(corrector, processed_source, node, align_to)
|
30
30
|
@processed_source = processed_source
|
31
31
|
whitespace = whitespace_range(node)
|
32
|
-
return false unless whitespace.source.strip.empty?
|
33
|
-
|
34
32
|
column = alignment_column(align_to)
|
35
|
-
|
33
|
+
|
34
|
+
if whitespace.source.strip.empty?
|
35
|
+
corrector.replace(whitespace, ' ' * column)
|
36
|
+
else
|
37
|
+
corrector.insert_after(whitespace, "\n#{' ' * column}")
|
38
|
+
end
|
36
39
|
end
|
37
40
|
|
38
41
|
private
|
@@ -17,6 +17,7 @@ module RuboCop
|
|
17
17
|
#
|
18
18
|
# # good
|
19
19
|
# CGI.escape('http://example.com')
|
20
|
+
# URI.encode_uri_component(uri) # Since Ruby 3.1
|
20
21
|
# URI.encode_www_form([['example', 'param'], ['lang', 'en']])
|
21
22
|
# URI.encode_www_form(page: 10, locale: 'en')
|
22
23
|
# URI.encode_www_form_component('http://example.com')
|
@@ -27,6 +28,7 @@ module RuboCop
|
|
27
28
|
#
|
28
29
|
# # good
|
29
30
|
# CGI.unescape(enc_uri)
|
31
|
+
# URI.decode_uri_component(uri) # Since Ruby 3.1
|
30
32
|
# URI.decode_www_form(enc_uri)
|
31
33
|
# URI.decode_www_form_component(enc_uri)
|
32
34
|
class UriEscapeUnescape < Base
|
@@ -19,8 +19,7 @@ module RuboCop
|
|
19
19
|
def check_end_kw_alignment(node, align_ranges)
|
20
20
|
return if ignored_node?(node)
|
21
21
|
|
22
|
-
end_loc = node.loc.end
|
23
|
-
return if accept_end_kw_alignment?(end_loc)
|
22
|
+
return unless (end_loc = node.loc.end)
|
24
23
|
|
25
24
|
matching = matching_ranges(end_loc, align_ranges)
|
26
25
|
|
@@ -57,11 +56,6 @@ module RuboCop
|
|
57
56
|
add_offense(end_loc, message: msg) { |corrector| autocorrect(corrector, node) }
|
58
57
|
end
|
59
58
|
|
60
|
-
def accept_end_kw_alignment?(end_loc)
|
61
|
-
end_loc.nil? || # Discard modifier forms of if/while/until.
|
62
|
-
!/\A[ \t]*end/.match?(processed_source.lines[end_loc.line - 1])
|
63
|
-
end
|
64
|
-
|
65
59
|
def style_parameter_name
|
66
60
|
'EnforcedStyleAlignWith'
|
67
61
|
end
|
@@ -14,7 +14,7 @@ module RuboCop
|
|
14
14
|
# method calls are assumed to return boolean values. The cop does not make an assessment
|
15
15
|
# if the return type is unknown (non-predicate method calls, variables, etc.).
|
16
16
|
#
|
17
|
-
# NOTE:
|
17
|
+
# NOTE: The `initialize` method and operator methods (`def ==`, etc.) are ignored.
|
18
18
|
#
|
19
19
|
# By default, the cop runs in `conservative` mode, which allows a method to be named
|
20
20
|
# with a question mark as long as at least one return value is boolean. In `aggressive`
|
@@ -149,7 +149,8 @@ module RuboCop
|
|
149
149
|
private
|
150
150
|
|
151
151
|
def allowed?(node)
|
152
|
-
|
152
|
+
node.method?(:initialize) ||
|
153
|
+
allowed_method?(node.method_name) ||
|
153
154
|
matches_allowed_pattern?(node.method_name) ||
|
154
155
|
allowed_bang_method?(node) ||
|
155
156
|
node.operator_method? ||
|
@@ -24,9 +24,6 @@ module RuboCop
|
|
24
24
|
(send `{(send _recv _msg) str array hash const #variable?} :[] ...)
|
25
25
|
PATTERN
|
26
26
|
|
27
|
-
# @!method method_node_and_args(node)
|
28
|
-
def_node_matcher :method_node_and_args, '$(call _recv _msg $...)'
|
29
|
-
|
30
27
|
# @!method rescue?(node)
|
31
28
|
def_node_matcher :rescue?, '{^resbody ^^resbody}'
|
32
29
|
|
@@ -228,7 +225,7 @@ module RuboCop
|
|
228
225
|
|
229
226
|
return check_unary(begin_node, node) if node.unary_operation?
|
230
227
|
|
231
|
-
return unless method_call_with_redundant_parentheses?(node)
|
228
|
+
return unless method_call_with_redundant_parentheses?(begin_node, node)
|
232
229
|
return if call_chain_starts_with_int?(begin_node, node) ||
|
233
230
|
do_end_block_in_method_chain?(begin_node, node)
|
234
231
|
|
@@ -239,8 +236,7 @@ module RuboCop
|
|
239
236
|
return if begin_node.chained?
|
240
237
|
|
241
238
|
node = node.children.first while suspect_unary?(node)
|
242
|
-
|
243
|
-
return if node.send_type? && !method_call_with_redundant_parentheses?(node)
|
239
|
+
return unless method_call_with_redundant_parentheses?(begin_node, node)
|
244
240
|
|
245
241
|
offense(begin_node, 'a unary operation')
|
246
242
|
end
|
@@ -302,13 +298,19 @@ module RuboCop
|
|
302
298
|
end
|
303
299
|
end
|
304
300
|
|
305
|
-
def method_call_with_redundant_parentheses?(node)
|
306
|
-
return false unless node.
|
301
|
+
def method_call_with_redundant_parentheses?(begin_node, node)
|
302
|
+
return false unless node.type?(:call, :super, :yield, :defined?)
|
307
303
|
return false if node.prefix_not?
|
304
|
+
return true if singular_parenthesized_parent?(begin_node)
|
305
|
+
|
306
|
+
node.arguments.empty? || parentheses?(node) || square_brackets?(node)
|
307
|
+
end
|
308
308
|
|
309
|
-
|
309
|
+
def singular_parenthesized_parent?(begin_node)
|
310
|
+
return true unless begin_node.parent
|
311
|
+
return false if begin_node.parent.type?(:splat, :kwsplat)
|
310
312
|
|
311
|
-
|
313
|
+
parentheses?(begin_node) && begin_node.parent.children.one?
|
312
314
|
end
|
313
315
|
|
314
316
|
def only_begin_arg?(args)
|
@@ -262,8 +262,14 @@ module RuboCop
|
|
262
262
|
end
|
263
263
|
|
264
264
|
def dotless_operator_call?(method_call)
|
265
|
+
return true if dotless_operator_method?(method_call)
|
266
|
+
|
265
267
|
method_call = method_call.parent while method_call.parent.send_type?
|
266
268
|
|
269
|
+
dotless_operator_method?(method_call)
|
270
|
+
end
|
271
|
+
|
272
|
+
def dotless_operator_method?(method_call)
|
267
273
|
return false if method_call.loc.dot
|
268
274
|
|
269
275
|
method_call.method?(:[]) || method_call.method?(:[]=) || method_call.operator_method?
|
@@ -100,7 +100,7 @@ module RuboCop
|
|
100
100
|
node.receiver.str_type? &&
|
101
101
|
node.first_argument.str_type? &&
|
102
102
|
node.multiline? &&
|
103
|
-
node.source
|
103
|
+
node.source.match?(/\+\s*\n/)
|
104
104
|
end
|
105
105
|
|
106
106
|
def find_topmost_plus_node(node)
|
@@ -141,22 +141,26 @@ module RuboCop
|
|
141
141
|
end
|
142
142
|
|
143
143
|
def replacement(parts)
|
144
|
-
interpolated_parts = parts.map
|
145
|
-
case part.type
|
146
|
-
when :str
|
147
|
-
adjust_str(part)
|
148
|
-
when :dstr
|
149
|
-
part.children.all?(&:str_type?) ? adjust_str(part) : part.value
|
150
|
-
else
|
151
|
-
"\#{#{part.source}}"
|
152
|
-
end
|
153
|
-
end
|
144
|
+
interpolated_parts = parts.map { |part| adjust_str(part) }
|
154
145
|
|
155
146
|
"\"#{handle_quotes(interpolated_parts).join}\""
|
156
147
|
end
|
157
148
|
|
158
|
-
def adjust_str(
|
159
|
-
|
149
|
+
def adjust_str(part)
|
150
|
+
case part.type
|
151
|
+
when :str
|
152
|
+
if single_quoted?(part)
|
153
|
+
part.value.gsub(/(\\|"|#\{|#@|#\$)/, '\\\\\&')
|
154
|
+
else
|
155
|
+
part.value.inspect[1..-2]
|
156
|
+
end
|
157
|
+
when :dstr, :begin
|
158
|
+
part.children.map do |child|
|
159
|
+
adjust_str(child)
|
160
|
+
end.join
|
161
|
+
else
|
162
|
+
"\#{#{part.source}}"
|
163
|
+
end
|
160
164
|
end
|
161
165
|
|
162
166
|
def handle_quotes(parts)
|
data/lib/rubocop/result_cache.rb
CHANGED
@@ -9,7 +9,7 @@ module RuboCop
|
|
9
9
|
# Provides functionality for caching RuboCop runs.
|
10
10
|
# @api private
|
11
11
|
class ResultCache
|
12
|
-
NON_CHANGING = %i[color format formatters out debug fail_level
|
12
|
+
NON_CHANGING = %i[color format formatters out debug display_time fail_level
|
13
13
|
fix_layout autocorrect safe_autocorrect autocorrect_all
|
14
14
|
cache fail_fast stdin parallel].freeze
|
15
15
|
|
data/lib/rubocop/runner.rb
CHANGED
@@ -273,7 +273,8 @@ module RuboCop
|
|
273
273
|
end
|
274
274
|
|
275
275
|
def do_inspection_loop(file)
|
276
|
-
|
276
|
+
# We can reuse the prism result since the source did not change yet.
|
277
|
+
processed_source = get_processed_source(file, @prism_result)
|
277
278
|
# This variable is 2d array used to track corrected offenses after each
|
278
279
|
# inspection iteration. This is used to output meaningful infinite loop
|
279
280
|
# error message.
|
@@ -295,7 +296,8 @@ module RuboCop
|
|
295
296
|
# loop if we find any.
|
296
297
|
break unless updated_source_file
|
297
298
|
|
298
|
-
|
299
|
+
# Autocorrect has happened, don't use the prism result since it is stale.
|
300
|
+
processed_source = get_processed_source(file, nil)
|
299
301
|
end
|
300
302
|
|
301
303
|
# Return summary of corrected offenses after all iterations
|
@@ -482,7 +484,7 @@ module RuboCop
|
|
482
484
|
end
|
483
485
|
|
484
486
|
# rubocop:disable Metrics/MethodLength
|
485
|
-
def get_processed_source(file)
|
487
|
+
def get_processed_source(file, prism_result)
|
486
488
|
config = @config_store.for_file(file)
|
487
489
|
ruby_version = config.target_ruby_version
|
488
490
|
parser_engine = config.parser_engine
|
@@ -493,7 +495,7 @@ module RuboCop
|
|
493
495
|
ruby_version,
|
494
496
|
file,
|
495
497
|
parser_engine: parser_engine,
|
496
|
-
prism_result:
|
498
|
+
prism_result: prism_result
|
497
499
|
)
|
498
500
|
else
|
499
501
|
begin
|
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.80.
|
4
|
+
version: 1.80.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-09-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -1090,7 +1090,7 @@ licenses:
|
|
1090
1090
|
- MIT
|
1091
1091
|
metadata:
|
1092
1092
|
homepage_uri: https://rubocop.org/
|
1093
|
-
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.80.
|
1093
|
+
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.80.2
|
1094
1094
|
source_code_uri: https://github.com/rubocop/rubocop/
|
1095
1095
|
documentation_uri: https://docs.rubocop.org/rubocop/1.80/
|
1096
1096
|
bug_tracker_uri: https://github.com/rubocop/rubocop/issues
|