Sha256: 432973068cf47e93abd36d1c141986965e3daa56130a62fc2ab283574619c8ed

Contents?: true

Size: 910 Bytes

Versions: 1

Compression:

Stored size: 910 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    module Style
      # This cop checks if the length a class exceeds some maximum value.
      # Comment lines can optionally be ignored.
      # The maximum allowed length is configurable.
      class ClassLength < Cop
        MSG = 'Class definition is too long. [%d/%d]'

        def on_class(node)
          check(node)
        end

        def max_length
          cop_config['Max']
        end

        def count_comments?
          cop_config['CountComments']
        end

        private

        def check(node)
          method_length = Util.source_length(node.loc.expression.source,
                                             count_comments?)

          if method_length > max_length
            message = sprintf(MSG, method_length, max_length)
            convention(node, :keyword, message)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-0.14.0 lib/rubocop/cop/style/class_length.rb