Module: Rubocop::Cop::FavorOtherKeywordOverNegation

Included in:
FavorUnlessOverNegatedIf, FavorUntilOverNegatedWhile
Defined in:
lib/rubocop/cop/favor_unless_over_negated_if.rb

Instance Method Summary collapse

Instance Method Details

#check(node) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rubocop/cop/favor_unless_over_negated_if.rb', line 6

def check(node)
  condition, _body, _rest = *node

  # Look at last expression of contents if there's a parenthesis
  # around condition.
  *_, condition = *condition while condition.type == :begin

  if condition.type == :send
    _object, method = *condition
    if method == :! && !(node.loc.respond_to?(:else) && node.loc.else)
      add_offence(:convention, node.loc.expression.line,
                  error_message)
    end
  end
end