Class: RuboCop::Cop::Rails::NegateInclude
- Inherits:
-
RuboCop::Cop
- Object
- RuboCop::Cop
- RuboCop::Cop::Rails::NegateInclude
- Defined in:
- lib/rubocop/cop/rails/negate_include.rb
Overview
This cop enforces the use of ‘collection.exclude?(obj)` over `!collection.include?(obj)`.
Constant Summary collapse
- MSG =
'Use `.exclude?` and remove the negation part.'
Instance Method Summary collapse
Instance Method Details
#autocorrect(node) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/rubocop/cop/rails/negate_include.rb', line 29 def autocorrect(node) negate_include_call?(node) do |receiver, obj| lambda do |corrector| corrector.replace(node, "#{receiver.source}.exclude?(#{obj.source})") end end end |
#on_send(node) ⇒ Object
25 26 27 |
# File 'lib/rubocop/cop/rails/negate_include.rb', line 25 def on_send(node) add_offense(node) if negate_include_call?(node) end |