Class: RuboCop::Cop::Homebrew::Present Private
- Extended by:
- AutoCorrector
- Defined in:
- rubocops/present.rb,
sorbet/rbi/dsl/rubo_cop/cop/homebrew/present.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.
Checks for code that can be simplified using Object#present?
.
Example
# bad
!foo.nil? && !foo.empty?
# bad
foo != nil && !foo.empty?
# good
foo.present?
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.
"Use `%<prefer>s` instead of `%<current>s`."
Instance Method Summary collapse
- #autocorrect(corrector, node) ⇒ void private
- #exists_and_not_empty?(node, **kwargs, &block) ⇒ T.untyped private
- #on_and(node) ⇒ void private
- #on_or(node) ⇒ void private
Instance Method Details
#autocorrect(corrector, 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.
65 66 67 68 69 |
# File 'rubocops/present.rb', line 65 def autocorrect(corrector, node) variable1, _variable2 = exists_and_not_empty?(node) range = node.source_range corrector.replace(range, replacement(variable1)) end |
#exists_and_not_empty?(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/present.rbi', line 10 def exists_and_not_empty?(node, **kwargs, &block); end |
#on_and(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.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'rubocops/present.rb', line 41 def on_and(node) exists_and_not_empty?(node) do |var1, var2| return if var1 != var2 = format(MSG, prefer: replacement(var1), current: node.source) add_offense(node, message:) do |corrector| autocorrect(corrector, node) end end end |
#on_or(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.
54 55 56 57 58 59 60 61 62 |
# File 'rubocops/present.rb', line 54 def on_or(node) exists_and_not_empty?(node) do |var1, var2| return if var1 != var2 add_offense(node, message: MSG) do |corrector| autocorrect(corrector, node) end end end |