rubocop 1.60.1 → 1.60.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/internal_affairs/example_description.rb +4 -4
- data/lib/rubocop/cop/layout/redundant_line_break.rb +5 -1
- data/lib/rubocop/cop/style/arguments_forwarding.rb +10 -3
- data/lib/rubocop/cop/style/hash_each_methods.rb +26 -5
- data/lib/rubocop/server/client_command/exec.rb +0 -1
- data/lib/rubocop/server/server_command/exec.rb +0 -1
- 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: a5baa438e333ac7dbae0d7481f0a512e950f9ef11014f09d78f360d3bc64d528
|
4
|
+
data.tar.gz: bfba21f2555729c81554baad4910a35088fef9ba39538402e54841fdff1c8d8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 247eadb99d0c3d9f46067a707a0511433567fea2326ded958381c55cabe9a24ef6c2328e6d4ab901454a6af60cba185d5f87364fc9c1399684bbf3a657ef383b
|
7
|
+
data.tar.gz: 675be6aba0374927f8bf17df0d1dc51d4fc7a05431981d164ae62715fd9008b8ae6208b50f4b509afadb4622a0b19e0bf5d4c650aa203407ece15e9d88ebe031
|
@@ -63,10 +63,10 @@ module RuboCop
|
|
63
63
|
expect_correction: EXPECT_CORRECTION_DESCRIPTION_MAPPING
|
64
64
|
}.freeze
|
65
65
|
|
66
|
-
# @!method offense_example
|
67
|
-
def_node_matcher :offense_example
|
66
|
+
# @!method offense_example(node)
|
67
|
+
def_node_matcher :offense_example, <<~PATTERN
|
68
68
|
(block
|
69
|
-
(send _ {:it :specify}
|
69
|
+
(send _ {:it :specify} $...)
|
70
70
|
_args
|
71
71
|
`(send nil? %RESTRICT_ON_SEND ...)
|
72
72
|
)
|
@@ -74,7 +74,7 @@ module RuboCop
|
|
74
74
|
|
75
75
|
def on_send(node)
|
76
76
|
parent = node.each_ancestor(:block).first
|
77
|
-
return unless parent && (current_description = offense_example
|
77
|
+
return unless parent && (current_description = offense_example(parent)&.first)
|
78
78
|
|
79
79
|
method_name = node.method_name
|
80
80
|
message = format(MSG, method_name: method_name)
|
@@ -85,7 +85,11 @@ module RuboCop
|
|
85
85
|
|
86
86
|
def offense?(node)
|
87
87
|
node.multiline? && !too_long?(node) && suitable_as_single_line?(node) &&
|
88
|
-
!configured_to_not_be_inspected?(node)
|
88
|
+
!index_access_call_chained?(node) && !configured_to_not_be_inspected?(node)
|
89
|
+
end
|
90
|
+
|
91
|
+
def index_access_call_chained?(node)
|
92
|
+
node.send_type? && node.method?(:[]) && node.children.first.method?(:[])
|
89
93
|
end
|
90
94
|
|
91
95
|
def configured_to_not_be_inspected?(node)
|
@@ -104,7 +104,7 @@ module RuboCop
|
|
104
104
|
# end
|
105
105
|
#
|
106
106
|
# @example RedundantBlockArgumentNames: ['blk', 'block', 'proc'] (default)
|
107
|
-
# # bad
|
107
|
+
# # bad - But it is good with `EnforcedStyle: explicit` set for `Naming/BlockForwarding`.
|
108
108
|
# def foo(&block)
|
109
109
|
# bar(&block)
|
110
110
|
# end
|
@@ -178,7 +178,7 @@ module RuboCop
|
|
178
178
|
registered_block_arg_offense = false
|
179
179
|
|
180
180
|
send_classifications.each do |send_node, _c, forward_rest, forward_kwrest, forward_block_arg| # rubocop:disable Layout/LineLength
|
181
|
-
if !forward_rest && !forward_kwrest
|
181
|
+
if !forward_rest && !forward_kwrest
|
182
182
|
register_forward_block_arg_offense(!forward_rest, node.arguments, block_arg)
|
183
183
|
register_forward_block_arg_offense(!forward_rest, send_node, forward_block_arg)
|
184
184
|
|
@@ -291,7 +291,7 @@ module RuboCop
|
|
291
291
|
end
|
292
292
|
|
293
293
|
def register_forward_block_arg_offense(add_parens, def_arguments_or_send, block_arg)
|
294
|
-
return if target_ruby_version <= 3.0
|
294
|
+
return if target_ruby_version <= 3.0 || block_arg.source == '&' || explicit_block_name?
|
295
295
|
|
296
296
|
add_offense(block_arg, message: BLOCK_MSG) do |corrector|
|
297
297
|
add_parens_if_missing(def_arguments_or_send, corrector) if add_parens
|
@@ -469,6 +469,13 @@ module RuboCop
|
|
469
469
|
(@kwrest_arg_name && !forwarded_kwrest_arg)
|
470
470
|
end
|
471
471
|
end
|
472
|
+
|
473
|
+
def explicit_block_name?
|
474
|
+
block_forwarding_config = config.for_cop('Naming/BlockForwarding')
|
475
|
+
return false unless block_forwarding_config['Enabled']
|
476
|
+
|
477
|
+
block_forwarding_config['EnforcedStyle'] == 'explicit'
|
478
|
+
end
|
472
479
|
end
|
473
480
|
end
|
474
481
|
end
|
@@ -40,6 +40,7 @@ module RuboCop
|
|
40
40
|
|
41
41
|
MSG = 'Use `%<prefer>s` instead of `%<current>s`.'
|
42
42
|
UNUSED_BLOCK_ARG_MSG = "#{MSG.chop} and remove the unused `%<unused_code>s` block argument."
|
43
|
+
ARRAY_CONVERTER_METHODS = %i[assoc flatten rassoc sort sort_by to_a].freeze
|
43
44
|
|
44
45
|
# @!method kv_each(node)
|
45
46
|
def_node_matcher :kv_each, <<~PATTERN
|
@@ -56,7 +57,6 @@ module RuboCop
|
|
56
57
|
(call $(call _ ${:keys :values}) :each (block_pass (sym _)))
|
57
58
|
PATTERN
|
58
59
|
|
59
|
-
# rubocop:disable Metrics/AbcSize
|
60
60
|
def on_block(node)
|
61
61
|
return unless handleable?(node)
|
62
62
|
|
@@ -66,12 +66,24 @@ module RuboCop
|
|
66
66
|
|
67
67
|
return unless (key, value = each_arguments(node))
|
68
68
|
|
69
|
-
|
69
|
+
check_unused_block_args(node, key, value)
|
70
|
+
end
|
71
|
+
alias on_numblock on_block
|
72
|
+
|
73
|
+
# rubocop:disable Metrics/AbcSize
|
74
|
+
def check_unused_block_args(node, key, value)
|
75
|
+
return if node.body.nil?
|
76
|
+
|
77
|
+
value_unused = unused_block_arg_exist?(node, value)
|
78
|
+
key_unused = unused_block_arg_exist?(node, key)
|
79
|
+
return if value_unused && key_unused
|
80
|
+
|
81
|
+
if value_unused
|
70
82
|
message = message('each_key', node.method_name, value.source)
|
71
83
|
unused_range = key.source_range.end.join(value.source_range.end)
|
72
84
|
|
73
85
|
register_each_args_offense(node, message, 'each_key', unused_range)
|
74
|
-
elsif
|
86
|
+
elsif key_unused
|
75
87
|
message = message('each_value', node.method_name, key.source)
|
76
88
|
unused_range = key.source_range.begin.join(value.source_range.begin)
|
77
89
|
|
@@ -80,8 +92,6 @@ module RuboCop
|
|
80
92
|
end
|
81
93
|
# rubocop:enable Metrics/AbcSize
|
82
94
|
|
83
|
-
alias on_numblock on_block
|
84
|
-
|
85
95
|
def on_block_pass(node)
|
86
96
|
kv_each_with_block_pass(node.parent) do |target, method|
|
87
97
|
register_kv_with_block_pass_offense(node, target, method)
|
@@ -91,6 +101,7 @@ module RuboCop
|
|
91
101
|
private
|
92
102
|
|
93
103
|
def handleable?(node)
|
104
|
+
return false if use_array_converter_method_as_preceding?(node)
|
94
105
|
return false unless (root_receiver = root_receiver(node))
|
95
106
|
|
96
107
|
!root_receiver.literal? || root_receiver.hash_type?
|
@@ -143,6 +154,16 @@ module RuboCop
|
|
143
154
|
end
|
144
155
|
end
|
145
156
|
|
157
|
+
def use_array_converter_method_as_preceding?(node)
|
158
|
+
return false unless (preceding_method = node.children.first.children.first)
|
159
|
+
unless preceding_method.call_type? ||
|
160
|
+
preceding_method.block_type? || preceding_method.numblock_type?
|
161
|
+
return false
|
162
|
+
end
|
163
|
+
|
164
|
+
ARRAY_CONVERTER_METHODS.include?(preceding_method.method_name)
|
165
|
+
end
|
166
|
+
|
146
167
|
def root_receiver(node)
|
147
168
|
receiver = node.receiver
|
148
169
|
if receiver&.receiver
|
@@ -16,7 +16,6 @@ module RuboCop
|
|
16
16
|
# @api private
|
17
17
|
class Exec < Base
|
18
18
|
def run
|
19
|
-
Cache.status_path.delete if Cache.status_path.file?
|
20
19
|
# RuboCop output is colorized by default where there is a TTY.
|
21
20
|
# We must pass the --color option to preserve this behavior.
|
22
21
|
@args.unshift('--color') unless %w[--color --no-color].any? { |f| @args.include?(f) }
|
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.60.
|
4
|
+
version: 1.60.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2024-01-
|
13
|
+
date: 2024-01-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|
@@ -1028,7 +1028,7 @@ licenses:
|
|
1028
1028
|
- MIT
|
1029
1029
|
metadata:
|
1030
1030
|
homepage_uri: https://rubocop.org/
|
1031
|
-
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.60.
|
1031
|
+
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.60.2
|
1032
1032
|
source_code_uri: https://github.com/rubocop/rubocop/
|
1033
1033
|
documentation_uri: https://docs.rubocop.org/rubocop/1.60/
|
1034
1034
|
bug_tracker_uri: https://github.com/rubocop/rubocop/issues
|