class RuboCop::Cop::Rails::DelegateAllowBlank

This cop looks for delegations that pass :allow_blank as an option instead of :allow_nil. :allow_blank is not a valid option to pass to ActiveSupport#delegate.

@example

# bad
delegate :foo, to: :bar, allow_blank: true

# good
delegate :foo, to: :bar, allow_nil: true

Constants

MSG
RESTRICT_ON_SEND

Public Instance Methods

on_send(node) click to toggle source
# File lib/rubocop/cop/rails/delegate_allow_blank.rb, line 26
def on_send(node)
  return unless (offending_node = allow_blank_option(node))

  add_offense(offending_node) do |corrector|
    corrector.replace(offending_node.key.source_range, 'allow_nil')
  end
end