Class: Rubocop::Cop::Lint::LiteralInCondition

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

Overview

This cop checks for literals used as operands in and/or expressions in the conditions of if/while/until.

Constant Summary collapse

MSG =
'Literal %s appeared in a condition.'
LITERALS =
[:str, :dstr, :int, :float, :array,
:hash, :regexp, :nil, :true, :false]

Instance Attribute Summary

Attributes inherited from Cop

#autocorrect, #debug, #disabled_lines, #offences

Instance Method Summary collapse

Methods inherited from Cop

#add_offence, #autocorrect_action, cop_name, #do_autocorrect, #ignore_node, inherited, #initialize, #inspect, #name, rails?

Constructor Details

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

Instance Method Details

#on_if(node) ⇒ Object



14
15
16
17
18
# File 'lib/rubocop/cop/lint/literal_in_condition.rb', line 14

def on_if(node)
  check_for_literal(node)

  super
end

#on_until(node) ⇒ Object



32
33
34
35
36
# File 'lib/rubocop/cop/lint/literal_in_condition.rb', line 32

def on_until(node)
  check_for_literal(node)

  super
end

#on_until_post(node) ⇒ Object



38
39
40
41
42
# File 'lib/rubocop/cop/lint/literal_in_condition.rb', line 38

def on_until_post(node)
  check_for_literal(node)

  super
end

#on_while(node) ⇒ Object



20
21
22
23
24
# File 'lib/rubocop/cop/lint/literal_in_condition.rb', line 20

def on_while(node)
  check_for_literal(node)

  super
end

#on_while_post(node) ⇒ Object



26
27
28
29
30
# File 'lib/rubocop/cop/lint/literal_in_condition.rb', line 26

def on_while_post(node)
  check_for_literal(node)

  super
end