Class: Rubocop::Cop::AndOr

Inherits:
Cop
  • Object
show all
Defined in:
lib/rubocop/cop/and_or.rb

Constant Summary collapse

MSG =
'Use %s instead of %s.'
OPS =
{ 'and' => '&&', 'or' => '||' }

Instance Attribute Summary

Attributes inherited from Cop

#debug, #disabled_lines, #offences

Instance Method Summary collapse

Methods inherited from Cop

#add_offence, cop_name, #has_report?, inherited, #initialize, #inspect, #name, #on_comment

Constructor Details

This class inherits a constructor from Rubocop::Cop::Cop

Instance Method Details

#on_and(node) ⇒ Object Also known as: on_or



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rubocop/cop/and_or.rb', line 10

def on_and(node)
  op = node.loc.operator.source
  op_type = node.type.to_s

  if op == op_type
    add_offence(:convention,
                node.loc.operator.line,
                sprintf(MSG, OPS[op], op))
  end

  super
end