Class: Rubocop::Cop::MethodAndVariableSnakeCase
- Defined in:
- lib/rubocop/cop/method_and_variable_snake_case.rb
Constant Summary collapse
- ERROR_MESSAGE =
'Use snake_case for methods and variables.'
- SNAKE_CASE =
/^@?[\da-z_]+[!?=]?$/
Instance Attribute Summary
Attributes inherited from Cop
Instance Method Summary collapse
Methods inherited from Cop
#add_offence, #has_report?, inherited, #initialize
Constructor Details
This class inherits a constructor from Rubocop::Cop::Cop
Instance Method Details
#check(sexp) ⇒ Object
24 25 26 27 28 |
# File 'lib/rubocop/cop/method_and_variable_snake_case.rb', line 24 def check(sexp) if [:@ivar, :@ident].include?(sexp[0]) && sexp[1] !~ SNAKE_CASE add_offence(:convention, sexp[2].lineno, ERROR_MESSAGE) end end |
#inspect(file, source, tokens, sexp) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rubocop/cop/method_and_variable_snake_case.rb', line 9 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 |