rubocop-rails 2.17.3 → 2.17.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1cd420a9b6ec0e14a26063533cf9db61a81a43e44bec26a8b98e577cf761e49
4
- data.tar.gz: 73918575c04e0f9ee8390d3efc0a4eb49b1cb4093695ecbafddbf995c406869d
3
+ metadata.gz: 8a9beeaefa16cbe4afb5d598878444a835536ccda5d9b46c3e44e111513f1d8e
4
+ data.tar.gz: 669a9681ce5ab1fca038229a831f7e5acae6bbdcc3a58ecfc88d65fd54ef7190
5
5
  SHA512:
6
- metadata.gz: 93fffc6d3f6cbb781692725c13eb6f049e3106f2fb7ccb43a48fdf7c0d85a189914740d2ef743b0642eaa94ae0fc584ec1a32be53095a12167b3c02db2b035d4
7
- data.tar.gz: 05ac2a5767f2c65437629fa623b3b4506547227c5b608a7ebc4e29a91b831e794ac6ee7c62a55b1573f3b228d40b6aaaedbda1fb7b81481c51f9c0df6884f389
6
+ metadata.gz: 72ca38ec9a9136bfa5bd635db9290314a4d1a4c8e3942f15aa62a823885ff1a1783f884598dce6f52765db75daccf8e4054d3faecdf973da6f2c53b10dc2c153
7
+ data.tar.gz: 536c7d8f5dfec22444d2d0fc4b297eac18f7b87cc6c871ce250bec58a2a6d380e814749534e5aedc47c0a66c7ae80ac8c61ffec330093c575cd1cc8dd76e4de9
@@ -69,15 +69,15 @@ module RuboCop
69
69
  def followed_by_render?(flash_node)
70
70
  flash_assigment_node = find_ancestor(flash_node, type: :send)
71
71
  context = flash_assigment_node
72
- if (if_node = context.each_ancestor(:if).first)
73
- context = if_node
72
+ if (node = context.each_ancestor(:if, :rescue).first)
73
+ context = node
74
74
  elsif context.right_siblings.empty?
75
75
  return true
76
76
  end
77
77
  context = context.right_siblings
78
78
 
79
- context.compact.any? do |node|
80
- render?(node)
79
+ context.compact.any? do |render_candidate|
80
+ render?(render_candidate)
81
81
  end
82
82
  end
83
83
 
@@ -69,7 +69,7 @@ module RuboCop
69
69
  class I18nLocaleTexts < Base
70
70
  MSG = 'Move locale texts to the locale files in the `config/locales` directory.'
71
71
 
72
- RESTRICT_ON_SEND = %i[validates redirect_to []= mail].freeze
72
+ RESTRICT_ON_SEND = %i[validates redirect_to redirect_back []= mail].freeze
73
73
 
74
74
  def_node_search :validation_message, <<~PATTERN
75
75
  (pair (sym :message) $str)
@@ -94,7 +94,7 @@ module RuboCop
94
94
  add_offense(text_node)
95
95
  end
96
96
  return
97
- when :redirect_to
97
+ when :redirect_to, :redirect_back
98
98
  text_node = redirect_to_flash(node).to_a.last
99
99
  when :[]=
100
100
  text_node = flash_assignment?(node)
@@ -186,11 +186,7 @@ module RuboCop
186
186
  def build_path_glob_replacement(path, method)
187
187
  receiver = range_between(path.loc.expression.begin_pos, path.children.first.loc.selector.end_pos).source
188
188
 
189
- argument = if path.arguments.one?
190
- path.first_argument.source
191
- else
192
- join_arguments(path.arguments)
193
- end
189
+ argument = path.arguments.one? ? path.first_argument.source : join_arguments(path.arguments)
194
190
 
195
191
  "#{receiver}.#{method}(#{argument})"
196
192
  end
@@ -214,11 +210,28 @@ module RuboCop
214
210
  end
215
211
 
216
212
  def join_arguments(arguments)
217
- quote = include_interpolation?(arguments) ? '"' : "'"
218
- joined_arguments = arguments.map(&:value).join('/')
213
+ use_interpolation = false
214
+
215
+ joined_arguments = arguments.map do |arg|
216
+ if arg.respond_to?(:value)
217
+ arg.value
218
+ else
219
+ use_interpolation = true
220
+ "\#{#{arg.source}}"
221
+ end
222
+ end.join('/')
223
+ quote = enforce_double_quotes? || include_interpolation?(arguments) || use_interpolation ? '"' : "'"
219
224
 
220
225
  "#{quote}#{joined_arguments}#{quote}"
221
226
  end
227
+
228
+ def enforce_double_quotes?
229
+ string_literals_config['EnforcedStyle'] == 'double_quotes'
230
+ end
231
+
232
+ def string_literals_config
233
+ config.for_cop('Style/StringLiterals')
234
+ end
222
235
  end
223
236
  end
224
237
  end
@@ -228,12 +228,25 @@ module RuboCop
228
228
  acceptable
229
229
  end
230
230
 
231
- # Time.new can be called with a time zone offset
231
+ # Time.new, Time.at, and Time.now can be called with a time zone offset
232
232
  # When it is, that should be considered safe
233
233
  # Example:
234
234
  # Time.new(1988, 3, 15, 3, 0, 0, "-05:00")
235
235
  def offset_provided?(node)
236
- node.arguments.size >= 7
236
+ case node.method_name
237
+ when :new
238
+ node.arguments.size == 7 || offset_option_provided?(node)
239
+ when :at, :now
240
+ offset_option_provided?(node)
241
+ end
242
+ end
243
+
244
+ def offset_option_provided?(node)
245
+ options = node.last_argument
246
+ options&.hash_type? &&
247
+ options.each_pair.any? do |pair|
248
+ pair.key.sym_type? && pair.key.value == :in && !pair.value.nil_type?
249
+ end
237
250
  end
238
251
  end
239
252
  end
@@ -139,11 +139,20 @@ module RuboCop
139
139
  pairs = node.arguments.last
140
140
  return unless pairs.hash_type?
141
141
 
142
+ return true if condition_hash_part?(pairs, keys: %i[if unless])
143
+
144
+ uniqueness_node = uniqueness_part(node)
145
+ return unless uniqueness_node&.hash_type?
146
+
147
+ condition_hash_part?(uniqueness_node, keys: %i[if unless conditions])
148
+ end
149
+
150
+ def condition_hash_part?(pairs, keys:)
142
151
  pairs.each_pair.any? do |pair|
143
152
  key = pair.key
144
153
  next unless key.sym_type?
145
154
 
146
- key.value == :if || key.value == :unless
155
+ keys.include?(key.value)
147
156
  end
148
157
  end
149
158
 
@@ -38,7 +38,9 @@ module RuboCop
38
38
  def on_send(node)
39
39
  return unless node.first_argument.sym_type?
40
40
 
41
- where_node_and_argument(root_receiver(node)) do |where_node, where_argument|
41
+ root_receiver = root_receiver(node)
42
+ where_node_and_argument(root_receiver) do |where_node, where_argument|
43
+ next unless root_receiver == root_receiver(where_node)
42
44
  next unless same_relationship?(where_argument, node.first_argument)
43
45
 
44
46
  range = range_between(node.loc.selector.begin_pos, node.loc.expression.end_pos)
@@ -50,7 +52,12 @@ module RuboCop
50
52
  private
51
53
 
52
54
  def root_receiver(node)
53
- node&.parent&.send_type? ? root_receiver(node.parent) : node
55
+ parent = node.parent
56
+ if !parent&.send_type? || parent.method?(:or) || parent.method?(:and)
57
+ node
58
+ else
59
+ root_receiver(parent)
60
+ end
54
61
  end
55
62
 
56
63
  def same_relationship?(where, left_joins)
@@ -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.17.3'
7
+ STRING = '2.17.4'
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.17.3
4
+ version: 2.17.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-11-20 00:00:00.000000000 Z
13
+ date: 2022-12-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -235,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
235
235
  - !ruby/object:Gem::Version
236
236
  version: '0'
237
237
  requirements: []
238
- rubygems_version: 3.2.22
238
+ rubygems_version: 3.3.26
239
239
  signing_key:
240
240
  specification_version: 4
241
241
  summary: Automatic Rails code style checking tool.