Class: RuboCop::Cop::Homebrew::NegateInclude Private

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

This cop is unsafe because false positives will occur for receiver objects that do not have an #exclude? method (e.g. IPAddr).

Enforces the use of collection.exclude?(obj) over !collection.include?(obj).

Example

# bad
!array.include?(2)
!hash.include?(:key)

# good
array.exclude?(2)
hash.exclude?(:key)

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 `.exclude?` and remove the negation part."
RESTRICT_ON_SEND =

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.

[:!].freeze

Instance Method Summary collapse

Instance Method Details

#negate_include_call?(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/negate_include.rbi', line 10

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

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



35
36
37
38
39
40
41
# File 'rubocops/negate_include.rb', line 35

def on_send(node)
  return unless (receiver, obj = negate_include_call?(node))

  add_offense(node) do |corrector|
    corrector.replace(node, "#{receiver.source}.exclude?(#{obj.source})")
  end
end