Sha256: 01b29d67e2df8f07c37bf48bcb110d9248c8a65ff5627bee5b65f317c1f3fd57

Contents?: true

Size: 781 Bytes

Versions: 11

Compression:

Stored size: 781 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    class MethodAndVariableSnakeCase < Cop
      ERROR_MESSAGE = 'Use snake_case for methods and variables.'
      SNAKE_CASE = /^@?[\da-z_]+[!?=]?$/

      def inspect(file, source, tokens, sexp)
        each(:def, sexp) { |s| check(s[1]) }

        each(:assign, sexp) do |s|
          case s[1][0]
          when :var_field
            check(s[1][1])
          when :field
            if s[1][1][0] == :var_ref && s[1][1][1][0..1] == [:@kw, 'self']
              check(s[1][3])
            end
          end
        end
      end

      def check(sexp)
        if [:@ivar, :@ident].include?(sexp[0]) && sexp[1] !~ SNAKE_CASE
          add_offence(:convention, sexp[2].lineno, ERROR_MESSAGE)
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rubocop-0.6.1 lib/rubocop/cop/method_and_variable_snake_case.rb
rubocop-0.6.0 lib/rubocop/cop/method_and_variable_snake_case.rb
rubocop-0.5.0 lib/rubocop/cop/method_and_variable_snake_case.rb
rubocop-0.4.6 lib/rubocop/cop/method_and_variable_snake_case.rb
rubocop-0.4.5 lib/rubocop/cop/method_and_variable_snake_case.rb
rubocop-0.4.4 lib/rubocop/cop/method_and_variable_snake_case.rb
rubocop-0.4.3 lib/rubocop/cop/method_and_variable_snake_case.rb
rubocop-0.4.2 lib/rubocop/cop/method_and_variable_snake_case.rb
rubocop-0.4.1 lib/rubocop/cop/method_and_variable_snake_case.rb
rubocop-0.4.0 lib/rubocop/cop/method_and_variable_snake_case.rb
rubocop-0.3.2 lib/rubocop/cop/method_and_variable_snake_case.rb