Skip to content

Commit

Permalink
Fix an error for Rails/Validation when passing no arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Earlopain committed Aug 22, 2024
1 parent 2298948 commit 1efc402
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_error_rails_validation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1337](https://github.com/rubocop/rubocop-rails/pull/1337): Fix an error for `Rails/Validation` when passing no arguments. ([@earlopain][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ class Validation < Base

def on_send(node)
return if node.receiver
return unless (last_argument = node.last_argument)

range = node.loc.selector

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

corrector.replace(range, 'validates')
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/rails/validation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,10 @@
validates_numericality_of :a, b
RUBY
end

it 'registers no offense when no arguments are passed' do
expect_no_offenses(<<~RUBY)
validates_numericality_of
RUBY
end
end

0 comments on commit 1efc402

Please sign in to comment.