Class: RuboCop::Cop::Rails::NegateInclude
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Rails::NegateInclude
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/rails/negate_include.rb
Overview
Enforces the use of ‘collection.exclude?(obj)` over `!collection.include?(obj)`.
Constant Summary collapse
- MSG =
'Use `.exclude?` and remove the negation part.'
- RESTRICT_ON_SEND =
%i[!].freeze
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/rubocop/cop/rails/negate_include.rb', line 32 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 |