Class: RuboCop::Cop::Homebrew::SafeNavigationWithBlank Private

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
rubocops/safe_navigation_with_blank.rb,
sorbet/rbi/dsl/rubo_cop/cop/homebrew/safe_navigation_with_blank.rbi

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Note:

While the safe navigation operator is generally a good idea, when checking foo&.blank? in a conditional, foo being nil will actually do the opposite of what the author intends:

foo&.blank? #=> nil foo.blank? #=> true 

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

Example

# 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 =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

"Avoid calling `blank?` with the safe navigation operator in conditionals."

Instance Method Summary collapse

Instance Method Details

#on_if(node) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • node (RuboCop::AST::IfNode)
 40 41 42 43 44 45 46
# File 'rubocops/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

#safe_navigation_blank_in_conditional?(node, **kwargs, &block) ⇒ T.untyped

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:

  • (T.untyped)
 10
# File 'sorbet/rbi/dsl/rubo_cop/cop/homebrew/safe_navigation_with_blank.rbi', line 10 def safe_navigation_blank_in_conditional?(node, **kwargs, &block); end