Class: Rubocop::Cop::NumericLiterals

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

Constant Summary collapse

MSG =
'Add underscores to large numeric literals to ' +
'improve their readability.'

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?, #ignore_node, inherited, #initialize, #inspect, #name, #on_comment

Constructor Details

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

Instance Method Details

#on_int(node) ⇒ Object Also known as: on_float



9
10
11
12
13
14
15
16
# File 'lib/rubocop/cop/numeric_literals.rb', line 9

def on_int(node)
  value, = *node

  if value > 10000 &&
      node.loc.expression.source.split('.').grep(/\d{6}/).any?
    add_offence(:convention, node.loc.expression.line, MSG)
  end
end