Skip to content

Commit 5e2237a

Browse files
committed
Fix an error for Rails/Validation when passing no arguments
1 parent a9db5f5 commit 5e2237a

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#1337](https://github.com/rubocop/rubocop-rails/pull/1337): Fix an error for `Rails/Validation` when passing no arguments. ([@earlopain][])

lib/rubocop/cop/rails/validation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ class Validation < Base
5959

6060
def on_send(node)
6161
return if node.receiver
62+
return unless (last_argument = node.last_argument)
6263

6364
range = node.loc.selector
6465

6566
add_offense(range, message: message(node)) do |corrector|
66-
last_argument = node.last_argument
6767
return if !last_argument.literal? && !last_argument.splat_type? && !frozen_array_argument?(last_argument)
6868

6969
corrector.replace(range, 'validates')

spec/rubocop/cop/rails/validation_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,10 @@
171171
validates_numericality_of :a, b
172172
RUBY
173173
end
174+
175+
it 'registers no offense when no arguments are passed' do
176+
expect_no_offenses(<<~RUBY)
177+
validates_numericality_of
178+
RUBY
179+
end
174180
end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy