Class: Rubocop::Cop::SymbolName

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

Constant Summary collapse

MSG =
'Use snake_case for symbols.'
SNAKE_CASE =
/^[\da-z_]+[!?=]?$/
CAMEL_CASE =
/^[A-Z][A-Za-z\d]*$/

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

#allow_camel_case?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/rubocop/cop/symbol_name.rb', line 10

def allow_camel_case?
  self.class.config['AllowCamelCase']
end

#on_sym(node) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/rubocop/cop/symbol_name.rb', line 14

def on_sym(node)
  sym_name = node.to_a[0]
  return unless sym_name =~ /^[a-zA-Z]/
  return if sym_name =~ SNAKE_CASE
  return if allow_camel_case? && sym_name =~ CAMEL_CASE
  add_offence(:convention, node.loc.line, MSG)
end