Sha256: 038d00cc049f91576e98ca960d404d3bc265529d0389ccfb899584ec2b4a5318

Contents?: true

Size: 759 Bytes

Versions: 4

Compression:

Stored size: 759 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    module Style
      # This cop checks whether symbol names are snake_case.
      # There's also an option to accept CamelCase symbol names as well.
      class SymbolName < Cop
        MSG = 'Use snake_case for symbols.'
        SNAKE_CASE = /^[\da-z_]+[!?=]?$/
        CAMEL_CASE = /^[A-Z][A-Za-z\d]*$/

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

        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.expression, MSG)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
rubocop-0.10.0 lib/rubocop/cop/style/symbol_name.rb
rubocop-0.9.1 lib/rubocop/cop/style/symbol_name.rb
sabat-rubocop-0.9.0 lib/rubocop/cop/style/symbol_name.rb
rubocop-0.9.0 lib/rubocop/cop/style/symbol_name.rb