Class: RuboCop::Cop::Homebrew::Blank Private

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
rubocops/blank.rb,
sorbet/rbi/dsl/rubo_cop/cop/homebrew/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:

Auto-correction for this cop is unsafe because ' '.empty? returns false, but ' '.blank? returns true. Therefore, auto-correction is not compatible if the receiver is a non-empty blank string.

Checks for code that can be simplified using Object#blank?.

Example

# bad
foo.nil? || foo.empty?
foo == nil || foo.empty?

# good
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.

"Use `%<prefer>s` instead of `%<current>s`."

Instance Method Summary collapse

Instance Method Details

#nil_or_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.

Parameters:

Returns:

  • (T.untyped)


10
# File 'sorbet/rbi/dsl/rubo_cop/cop/homebrew/blank.rbi', line 10

def nil_or_empty?(node, **kwargs, &block); end

#on_or(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.



47
48
49
50
51
52
53
54
55
56
# File 'rubocops/blank.rb', line 47

def on_or(node)
  nil_or_empty?(node) do |var1, var2|
    return if var1 != var2

    message = format(MSG, prefer: replacement(var1), current: node.source)
    add_offense(node, message:) do |corrector|
      autocorrect(corrector, node)
    end
  end
end