Sha256: e48a1fcc04c61e46f4d52fceeeac06dbb2287d7427e0d809c775b849635f03e7

Contents?: true

Size: 554 Bytes

Versions: 4

Compression:

Stored size: 554 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    class ConstantName < Cop
      MSG = 'Use SCREAMING_SNAKE_CASE for constants.'
      SNAKE_CASE = /^[\dA-Z_]+$/

      def on_casgn(node)
        _scope, const_name, value = *node

        # we cannot know the result of method calls line
        # NewClass = something_that_returns_a_class
        if value.type != :send && const_name !~ SNAKE_CASE
          add_offence(:convention,
                      node.loc.line,
                      MSG)
        end

        super
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.8.3 lib/rubocop/cop/constant_name.rb
rubocop-0.8.2 lib/rubocop/cop/constant_name.rb
rubocop-0.8.1 lib/rubocop/cop/constant_name.rb
rubocop-0.8.0 lib/rubocop/cop/constant_name.rb