Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an error for Rails/Validation when passing no arguments #1337

Merged
merged 2 commits into from
Aug 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix an error for Rails/Validation when passing no arguments
  • Loading branch information
Earlopain committed Aug 22, 2024
commit 5e2237a83ecd3b0277ec9e1ef96ee257af6681d5
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
@@ -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')
6 changes: 6 additions & 0 deletions spec/rubocop/cop/rails/validation_spec.rb
Original file line number Diff line number Diff line change
@@ -171,4 +171,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