Sha256: 7de713b72104d21833034fb912b66c76af12c3460289c5ace214fe2cdf31aa19

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cop makes sure that all variables use the configured style,
      # snake_case or camelCase, for their names.
      class VariableName < Cop
        include ConfigurableNaming

        def on_lvasgn(node)
          name, = *node
          check_name(node, name, node.loc.name)
        end

        def on_ivasgn(node)
          name, = *node
          check_name(node, name, node.loc.name)
        end

        # TODO: Why is this checking invocations of setter rather than
        #   definitions? Also, this is not variable.
        def on_send(node)
          return unless setter_call_on_self?(node)
          _receiver, method_name, = *node
          attribute_name = method_name.to_s.sub(/=$/, '').to_sym
          check_name(node, attribute_name, node.loc.selector)
        end

        private

        def message(style)
          format('Use %s for variables.', style)
        end

        def setter_call_on_self?(send_node)
          receiver, method_name, = *send_node
          return false unless receiver && receiver.type == :self
          method_name.to_s.end_with?('=')
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-0.25.0 lib/rubocop/cop/style/variable_name.rb