Class: Tailor::Rulers::AllowScreamingSnakeCaseClassesRuler

Inherits:
Tailor::Ruler
  • Object
show all
Defined in:
lib/tailor/rulers/allow_screaming_snake_case_classes_ruler.rb

Instance Attribute Summary

Attributes inherited from Tailor::Ruler

#lexer_observers

Instance Method Summary collapse

Methods inherited from Tailor::Ruler

#add_child_ruler, #problem_type, #problems

Methods included from Logger::Mixin

included

Constructor Details

#initialize(config, options) ⇒ AllowScreamingSnakeCaseClassesRuler

Returns a new instance of AllowScreamingSnakeCaseClassesRuler.



6
7
8
9
# File 'lib/tailor/rulers/allow_screaming_snake_case_classes_ruler.rb', line 6

def initialize(config, options)
  super(config, options)
  add_lexer_observers :const
end

Instance Method Details

#const_update(token, lexed_line, lineno, column) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/tailor/rulers/allow_screaming_snake_case_classes_ruler.rb', line 11

def const_update(token, lexed_line, lineno, column)
  ident_index = lexed_line.event_index(column)
  previous_event = lexed_line.event_at(ident_index - 2)
  log "previous event: #{previous_event}"

  return if previous_event.nil?

  if previous_event[1] == :on_kw &&
    (previous_event.last == 'class' || previous_event.last == 'module')
    measure(token, lineno, column)
  end
end

#measure(token, lineno, column) ⇒ Object

Checks to see if the class name matches /[A-Z].*_/.

Parameters:

  • token (Fixnum)

    The space(s).

  • lineno (Fixnum)

    Line the potential problem is on.

  • column (Fixnum)

    Column the potential problem is on.



29
30
31
32
33
34
35
36
# File 'lib/tailor/rulers/allow_screaming_snake_case_classes_ruler.rb', line 29

def measure(token, lineno, column)
  if token.screaming_snake_case?
    problem_message = 'Screaming-snake-case class/module found.'

    @problems << Problem.new(problem_type, lineno, column,
      problem_message, @options[:level])
  end
end