Class: RuboCop::Cop::Rails::SafeNavigationWithBlank

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/rails/safe_navigation_with_blank.rb

Overview

Checks to make sure safe navigation isn’t used with ‘blank?` in a conditional.

Examples:

# bad
do_something if foo&.blank?
do_something unless foo&.blank?

# good
do_something if foo.blank?
do_something unless foo.blank?

Constant Summary collapse

MSG =
'Avoid calling `blank?` with the safe navigation operator in conditionals.'

Instance Method Summary collapse

Instance Method Details

#on_if(node) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/rubocop/cop/rails/safe_navigation_with_blank.rb', line 40

def on_if(node)
  return unless safe_navigation_blank_in_conditional?(node)

  add_offense(node) do |corrector|
    corrector.replace(safe_navigation_blank_in_conditional?(node).location.dot, '.')
  end
end