Sha256: f8665bca69a7b108f492d5ae983a6c386297abff1cd41f806bab47ab947ee084

Contents?: true

Size: 681 Bytes

Versions: 4

Compression:

Stored size: 681 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    class SymbolSnakeCase < Cop
      ERROR_MESSAGE = 'Use snake_case for symbols.'
      SNAKE_CASE = /^@?[\da-z_]+[!?=]?$/
      OPERATORS = %w(! + - % * ** [])

      def inspect(file, source, tokens, sexp)
        each(:symbol_literal, sexp) do |s|
          symbol_ident = s[1][1][1]

          # handle a couple of special cases
          next if OPERATORS.include?(symbol_ident)

          unless symbol_ident =~ SNAKE_CASE
            line_no = s[1][1][2].lineno
            add_offence(:convention,
                        line_no,
                        ERROR_MESSAGE)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.5.0 lib/rubocop/cop/symbol_snake_case.rb
rubocop-0.4.6 lib/rubocop/cop/symbol_snake_case.rb
rubocop-0.4.5 lib/rubocop/cop/symbol_snake_case.rb
rubocop-0.4.4 lib/rubocop/cop/symbol_snake_case.rb