Class: RuboCop::Cop::Homebrew::SafeNavigationWithBlank Private
- 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.
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
- #on_if(node) ⇒ Object private
- #safe_navigation_blank_in_conditional?(node, **kwargs, &block) ⇒ T.untyped private
Instance Method Details
#on_if(node) ⇒ Object
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.
39 40 41 42 43 44 45 |
# File 'rubocops/safe_navigation_with_blank.rb', line 39 def on_if(node) return unless (node) add_offense(node) do |corrector| corrector.replace((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.
10 |
# File 'sorbet/rbi/dsl/rubo_cop/cop/homebrew/safe_navigation_with_blank.rbi', line 10 def (node, **kwargs, &block); end |