rubocop-rails 2.29.0 → 2.29.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: 210e46df0db68aeef5761f3afeeb86d62a52015be55190d3e6e1fd65368721be
4
- data.tar.gz: 7ff2ef268227cf39cb23b0479a8cf19c4ecc2acdf62c18f8e1766756e5965119
3
+ metadata.gz: f6fa236fdf79709d4d0baec3c3ed01bc254e807dbd5ec39229374187b1d3d30c
4
+ data.tar.gz: 99b29d27dd97c1adc12efb3d60a55370f6c4ad363bd6de51ca11ac33f3b1cd8a
5
5
  SHA512:
6
- metadata.gz: c84c5690318920b054525a7fc21ca4e0f067a2093757f7ff8182d429587c94898ba1ea1160893fe29e9a8ef9427f6cc076f613f283b5b857da0529fea7654a47
7
- data.tar.gz: ca501a5661bcebf2a6769a8cba620c637872e17023ac19fe8f6415b5ff4305d735ead0d24c7ffaee46f24c6cbeb466fcffeebdfb9cd96836211ab446643fc2a7
6
+ metadata.gz: 422221a038428edaf91477ef0ede6939023a686f3a62c14242efbfa1cb31be9d8f504eaf15ac103875696b5584b690cabcc86a4041b5c42cfd4480aa4ad27dbd
7
+ data.tar.gz: 8240dcae47150b3137a980e731d69133df5e54364b62014d296b51715b1e3f47077b828d4f256191c79d8a14121e0d5cce9b06857f54b632e398216290e31f29
@@ -63,11 +63,15 @@ module RuboCop
63
63
  private
64
64
 
65
65
  def register_offense(name, nodes, message_template)
66
- nodes.each do |node|
67
- add_offense(node, message: format(message_template, name: name)) do |corrector|
68
- next if same_line?(nodes.last, node)
66
+ last_node = nodes.last
69
67
 
70
- corrector.remove(range_by_whole_lines(node.source_range, include_final_newline: true))
68
+ nodes.each_with_index do |node, index|
69
+ add_offense(node, message: format(message_template, name: name)) do |corrector|
70
+ if index.zero?
71
+ corrector.replace(node, last_node.source)
72
+ else
73
+ corrector.remove(range_by_whole_lines(node.source_range, include_final_newline: true))
74
+ end
71
75
  end
72
76
  end
73
77
  end
@@ -173,7 +173,17 @@ module RuboCop
173
173
  end
174
174
 
175
175
  def autocorrect_file_join(corrector, node)
176
+ replace_receiver_with_rails_root(corrector, node)
177
+ remove_first_argument_with_comma(corrector, node)
178
+ process_arguments(corrector, node.arguments)
179
+ append_to_string_conversion(corrector, node)
180
+ end
181
+
182
+ def replace_receiver_with_rails_root(corrector, node)
176
183
  corrector.replace(node.receiver, 'Rails.root')
184
+ end
185
+
186
+ def remove_first_argument_with_comma(corrector, node)
177
187
  corrector.remove(
178
188
  range_with_surrounding_space(
179
189
  range_with_surrounding_comma(
@@ -183,9 +193,19 @@ module RuboCop
183
193
  side: :right
184
194
  )
185
195
  )
186
- node.arguments.filter(&:str_type?).each do |argument|
187
- corrector.replace(argument, argument.value.delete_prefix('/').inspect)
196
+ end
197
+
198
+ def process_arguments(corrector, arguments)
199
+ arguments.each do |argument|
200
+ if argument.str_type?
201
+ corrector.replace(argument, argument.value.delete_prefix('/').inspect)
202
+ elsif argument.array_type?
203
+ corrector.replace(argument, "*#{argument.source}")
204
+ end
188
205
  end
206
+ end
207
+
208
+ def append_to_string_conversion(corrector, node)
189
209
  corrector.insert_after(node, '.to_s')
190
210
  end
191
211
 
@@ -237,7 +237,12 @@ module RuboCop
237
237
  end
238
238
 
239
239
  replacement = "#{path_replacement}.#{method}"
240
- replacement += "(#{args.map(&:source).join(', ')})" unless args.empty?
240
+
241
+ if args.any?
242
+ formatted_args = args.map { |arg| arg.array_type? ? "*#{arg.source}" : arg.source }
243
+ replacement += "(#{formatted_args.join(', ')})"
244
+ end
245
+
241
246
  replacement
242
247
  end
243
248
 
@@ -328,8 +328,9 @@ module RuboCop
328
328
  end
329
329
 
330
330
  def return_value_assigned?(node)
331
- assignment = assignable_node(node).parent
332
- assignment&.lvasgn_type?
331
+ return false unless (assignment = assignable_node(node).parent)
332
+
333
+ assignment.assignment?
333
334
  end
334
335
 
335
336
  def persist_method?(node, methods = RESTRICT_ON_SEND)
@@ -32,7 +32,7 @@ module RuboCop
32
32
  def_node_matcher :params_require_permit, <<~PATTERN
33
33
  $(call
34
34
  $(call
35
- (send nil? :params) :require _) :permit ...)
35
+ (send nil? :params) :require _) :permit _+)
36
36
  PATTERN
37
37
 
38
38
  def_node_matcher :params_permit_require, <<~PATTERN
@@ -59,7 +59,7 @@ module RuboCop
59
59
  end
60
60
 
61
61
  add_offense(range, message: format(MSG, prefer: prefer)) do |corrector|
62
- corrector.remove(require_method.loc.dot.join(require_method.source_range.end))
62
+ corrector.remove(require_method.receiver.source_range.end.join(require_method.source_range.end))
63
63
  corrector.replace(permit_method.loc.selector, 'expect')
64
64
  if replace_argument
65
65
  corrector.insert_before(permit_method.first_argument, "#{require_key(require_method)}[")
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Rails
5
5
  # This module holds the RuboCop Rails version information.
6
6
  module Version
7
- STRING = '2.29.0'
7
+ STRING = '2.29.1'
8
8
 
9
9
  def self.document_version
10
10
  STRING.match('\d+\.\d+').to_s
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.29.0
4
+ version: 2.29.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -9,7 +9,7 @@ authors:
9
9
  - Yuji Nakayama
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2025-01-18 00:00:00.000000000 Z
12
+ date: 2025-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport