Class: RuboCop::Cop::Obsession::Rails::ValidateOneField

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/obsession/rails/validate_one_field.rb

Overview

This cop checks for ‘validates` callbacks with multiple fields.

One field per ‘validates` makes the validation extra clear.

Examples:


# bad
validates :name, :status, presence: true

# good
validates :name, presence: true
validates :status, presence: true

Constant Summary collapse

MSG =
'Validate only one field per line.'

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



26
27
28
# File 'lib/rubocop/cop/obsession/rails/validate_one_field.rb', line 26

def on_send(node)
  add_offense(node) if validates_with_more_than_one_field?(node)
end