rubocop 1.60.0 → 1.60.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8154c812a06c819d2014cca8c0967d9b9eb01ff0481b33318accfb61781b04ce
4
- data.tar.gz: d39b524c83cd84df683815b59ac1377fb9dc235dcce337507a56bf611eaa90af
3
+ metadata.gz: e1a3d23f54a884c339ea9572297b0c8327493b96f2285cdb0db4585d1b76f9e3
4
+ data.tar.gz: c0df01858756b5b0c18a786c576ce2a21b6f36ffa99947111b8a03d5296c24eb
5
5
  SHA512:
6
- metadata.gz: '0787d7ca9354c20ef1fbbee33dc551cd2e45e8c3ea4aac96a51f8348b3a03a3ae1cc5262e0e6d00f61591f48ce4ffbf9140d7f1ddd19b9716d0596df3bbaa55c'
7
- data.tar.gz: de7a48105e8126e9f2c323dc516d4c9862b8c239d881e8285496eb3e79cefdecf487a37e0cb3e0b98fc25264f33c3a2d104fb1e6a4e382d1619f21dace50cc99
6
+ metadata.gz: 22ae311355c3b238f17df4d3e078920e531d706630ee41e2bd58543f082714da1b19948a81a377c83a34b2a7845b2eb2024cc64f7df97f9df5b5111b6be39541
7
+ data.tar.gz: a60635fbaec51410dd057156d80f07e533c4ce18a7ff83cf1a10d448e80fecbb33fbf3f074ee8172bce997c46c0c0b3019d4d21e19aede283cf5ea7e1f21c95d
@@ -240,12 +240,12 @@ module RuboCop
240
240
  self
241
241
  end
242
242
 
243
- def select(...)
244
- cops.select(...)
243
+ def select(&block)
244
+ cops.select(&block)
245
245
  end
246
246
 
247
- def each(...)
248
- cops.each(...)
247
+ def each(&block)
248
+ cops.each(&block)
249
249
  end
250
250
 
251
251
  # @param [String] cop_name
@@ -126,6 +126,7 @@ module RuboCop
126
126
  FORWARDING_MSG = 'Use shorthand syntax `...` for arguments forwarding.'
127
127
  ARGS_MSG = 'Use anonymous positional arguments forwarding (`*`).'
128
128
  KWARGS_MSG = 'Use anonymous keyword arguments forwarding (`**`).'
129
+ BLOCK_MSG = 'Use anonymous block arguments forwarding (`&`).'
129
130
 
130
131
  def self.autocorrect_incompatible_with
131
132
  [Naming::BlockForwarding]
@@ -171,21 +172,36 @@ module RuboCop
171
172
  send_classifications.all? { |_, c, _, _| c == :all }
172
173
  end
173
174
 
175
+ # rubocop:disable Metrics/MethodLength
174
176
  def add_forward_all_offenses(node, send_classifications, forwardable_args)
175
- send_classifications.each do |send_node, _c, forward_rest, _forward_kwrest|
176
- register_forward_all_offense(send_node, send_node, forward_rest)
177
+ _rest_arg, _kwrest_arg, block_arg = *forwardable_args
178
+ registered_block_arg_offense = false
179
+
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 && outside_block?(forward_block_arg)
182
+ register_forward_block_arg_offense(!forward_rest, node.arguments, block_arg)
183
+ register_forward_block_arg_offense(!forward_rest, send_node, forward_block_arg)
184
+
185
+ registered_block_arg_offense = true
186
+ break
187
+ else
188
+ register_forward_all_offense(send_node, send_node, forward_rest)
189
+ end
177
190
  end
178
191
 
192
+ return if registered_block_arg_offense
193
+
179
194
  rest_arg, _kwrest_arg, _block_arg = *forwardable_args
180
195
  register_forward_all_offense(node, node.arguments, rest_arg)
181
196
  end
197
+ # rubocop:enable Metrics/MethodLength
182
198
 
183
199
  def add_post_ruby_32_offenses(def_node, send_classifications, forwardable_args)
184
200
  return unless use_anonymous_forwarding?
185
201
 
186
202
  rest_arg, kwrest_arg, _block_arg = *forwardable_args
187
203
 
188
- send_classifications.each do |send_node, _c, forward_rest, forward_kwrest|
204
+ send_classifications.each do |send_node, _c, forward_rest, forward_kwrest, _forward_block_arg| # rubocop:disable Layout/LineLength
189
205
  if outside_block?(forward_rest)
190
206
  register_forward_args_offense(def_node.arguments, rest_arg)
191
207
  register_forward_args_offense(send_node, forward_rest)
@@ -225,10 +241,7 @@ module RuboCop
225
241
 
226
242
  def classification_and_forwards(def_node, send_node, referenced_lvars, forwardable_args)
227
243
  classifier = SendNodeClassifier.new(
228
- def_node,
229
- send_node,
230
- referenced_lvars,
231
- forwardable_args,
244
+ def_node, send_node, referenced_lvars, forwardable_args,
232
245
  target_ruby_version: target_ruby_version,
233
246
  allow_only_rest_arguments: allow_only_rest_arguments?
234
247
  )
@@ -237,7 +250,12 @@ module RuboCop
237
250
 
238
251
  return unless classification
239
252
 
240
- [classification, classifier.forwarded_rest_arg, classifier.forwarded_kwrest_arg]
253
+ [
254
+ classification,
255
+ classifier.forwarded_rest_arg,
256
+ classifier.forwarded_kwrest_arg,
257
+ classifier.forwarded_block_arg
258
+ ]
241
259
  end
242
260
 
243
261
  def redundant_named_arg(arg, config_name, keyword)
@@ -272,6 +290,16 @@ module RuboCop
272
290
  end
273
291
  end
274
292
 
293
+ def register_forward_block_arg_offense(add_parens, def_arguments_or_send, block_arg)
294
+ return if target_ruby_version <= 3.0
295
+
296
+ add_offense(block_arg, message: BLOCK_MSG) do |corrector|
297
+ add_parens_if_missing(def_arguments_or_send, corrector) if add_parens
298
+
299
+ corrector.replace(block_arg, '&')
300
+ end
301
+ end
302
+
275
303
  def register_forward_all_offense(def_or_send, send_or_arguments, rest_or_splat)
276
304
  arg_range = arguments_range(def_or_send, rest_or_splat)
277
305
 
@@ -23,6 +23,8 @@ module RuboCop
23
23
  # array.reject { |e| e.nil? }
24
24
  # array.delete_if { |e| e.nil? }
25
25
  # array.select { |e| !e.nil? }
26
+ # array.grep_v(nil)
27
+ # array.grep_v(NilClass)
26
28
  #
27
29
  # # good
28
30
  # array.compact
@@ -46,7 +48,7 @@ module RuboCop
46
48
  extend TargetRubyVersion
47
49
 
48
50
  MSG = 'Use `%<good>s` instead of `%<bad>s`.'
49
- RESTRICT_ON_SEND = %i[reject delete_if reject! select select!].freeze
51
+ RESTRICT_ON_SEND = %i[reject delete_if reject! select select! grep_v].freeze
50
52
  TO_ENUM_METHODS = %i[to_enum lazy].freeze
51
53
 
52
54
  minimum_target_ruby_version 2.4
@@ -79,6 +81,11 @@ module RuboCop
79
81
  $(lvar _) :nil?) :!))
80
82
  PATTERN
81
83
 
84
+ # @!method grep_v_with_nil?(node)
85
+ def_node_matcher :grep_v_with_nil?, <<~PATTERN
86
+ (send _ :grep_v {(nil) (const {nil? cbase} :NilClass)})
87
+ PATTERN
88
+
82
89
  def on_send(node)
83
90
  return unless (range = offense_range(node))
84
91
  return if allowed_receiver?(node.receiver)
@@ -95,8 +102,9 @@ module RuboCop
95
102
 
96
103
  private
97
104
 
105
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
98
106
  def offense_range(node)
99
- if reject_method_with_block_pass?(node)
107
+ if reject_method_with_block_pass?(node) || grep_v_with_nil?(node)
100
108
  range(node, node)
101
109
  else
102
110
  block_node = node.parent
@@ -110,6 +118,7 @@ module RuboCop
110
118
  range(node, block_node)
111
119
  end
112
120
  end
121
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
113
122
 
114
123
  def to_enum_method?(node)
115
124
  return false unless node.receiver.send_type?
@@ -54,7 +54,7 @@ module RuboCop
54
54
  return false unless (parent = node.parent)
55
55
 
56
56
  parent.while_post_type? || parent.until_post_type? || parent.match_with_lvasgn_type? ||
57
- like_method_argument_parentheses?(parent)
57
+ like_method_argument_parentheses?(parent) || multiline_control_flow_statements?(node)
58
58
  end
59
59
 
60
60
  def allowed_expression?(node)
@@ -104,6 +104,13 @@ module RuboCop
104
104
  !node.arithmetic_operation? && node.first_argument.begin_type?
105
105
  end
106
106
 
107
+ def multiline_control_flow_statements?(node)
108
+ return false unless (parent = node.parent)
109
+ return false if parent.single_line?
110
+
111
+ parent.return_type? || parent.next_type? || parent.break_type?
112
+ end
113
+
107
114
  def empty_parentheses?(node)
108
115
  # Don't flag `()`
109
116
  node.children.empty?
@@ -116,7 +116,7 @@ module RuboCop
116
116
 
117
117
  def pid_running?
118
118
  Process.kill(0, pid_path.read.to_i) == 1
119
- rescue Errno::ESRCH, Errno::ENOENT, Errno::EACCES
119
+ rescue Errno::ESRCH, Errno::ENOENT, Errno::EACCES, Errno::EROFS
120
120
  false
121
121
  end
122
122
 
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.60.0'
6
+ STRING = '1.60.1'
7
7
 
8
8
  MSG = '%<version>s (using Parser %<parser_version>s, ' \
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
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.0
4
+ version: 1.60.1
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-15 00:00:00.000000000 Z
13
+ date: 2024-01-17 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.0
1031
+ changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.60.1
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