Sha256: 14da70687045b21f061979cdb13e7e1faf0c5233b349eed5153417b727d5699c

Contents?: true

Size: 1.2 KB

Versions: 10

Compression:

Stored size: 1.2 KB

Contents

require_relative '../ruler'

class Tailor
  module Rulers
    class AllowScreamingSnakeCaseClassesRuler < Tailor::Ruler
      def initialize(config, options)
        super(config, options)
        add_lexer_observers :const
      end

      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

      # Checks to see if the class name matches /[A-Z].*_/.
      #
      # @param [Fixnum] token The space(s).
      # @param [Fixnum] lineno Line the potential problem is on.
      # @param [Fixnum] column Column the potential problem is on.
      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
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
tailor-1.2.1 lib/tailor/rulers/allow_screaming_snake_case_classes_ruler.rb
tailor-1.2.0 lib/tailor/rulers/allow_screaming_snake_case_classes_ruler.rb
tailor-1.1.5 lib/tailor/rulers/allow_screaming_snake_case_classes_ruler.rb
tailor-1.1.4 lib/tailor/rulers/allow_screaming_snake_case_classes_ruler.rb
tailor-1.1.3 lib/tailor/rulers/allow_screaming_snake_case_classes_ruler.rb
tailor-1.1.2 lib/tailor/rulers/allow_screaming_snake_case_classes_ruler.rb
tailor-1.1.1 lib/tailor/rulers/allow_screaming_snake_case_classes_ruler.rb
tailor-1.1.0 lib/tailor/rulers/allow_screaming_snake_case_classes_ruler.rb
tailor-1.0.1 lib/tailor/rulers/allow_screaming_snake_case_classes_ruler.rb
tailor-1.0.0 lib/tailor/rulers/allow_screaming_snake_case_classes_ruler.rb