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