Sha256: 7a96920f1ee08d5be7798dad4e5517d963b9c7e66da0dbef17399a37a48164b5

Contents?: true

Size: 1.17 KB

Versions: 13

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Naming
      # This cop makes sure that all variables use the configured style,
      # snake_case or camelCase, for their names.
      #
      # @example EnforcedStyle: snake_case (default)
      #   # bad
      #   fooBar = 1
      #
      #   # good
      #   foo_bar = 1
      #
      # @example EnforcedStyle: camelCase
      #   # bad
      #   foo_bar = 1
      #
      #   # good
      #   fooBar = 1
      class VariableName < Cop
        include ConfigurableNaming

        MSG = 'Use %<style>s for variable names.'.freeze

        def on_lvasgn(node)
          name, = *node
          return unless name
          check_name(node, name, node.loc.name)
        end
        alias on_ivasgn    on_lvasgn
        alias on_cvasgn    on_lvasgn
        alias on_arg       on_lvasgn
        alias on_optarg    on_lvasgn
        alias on_restarg   on_lvasgn
        alias on_kwoptarg  on_lvasgn
        alias on_kwarg     on_lvasgn
        alias on_kwrestarg on_lvasgn
        alias on_blockarg  on_lvasgn

        private

        def message(style)
          format(MSG, style: style)
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
rubocop-0.58.2 lib/rubocop/cop/naming/variable_name.rb
rubocop-0.58.1 lib/rubocop/cop/naming/variable_name.rb
rubocop-0.58.0 lib/rubocop/cop/naming/variable_name.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/rubocop-0.57.2/lib/rubocop/cop/naming/variable_name.rb
rubocop-0.57.2 lib/rubocop/cop/naming/variable_name.rb
rubocop-0.57.1 lib/rubocop/cop/naming/variable_name.rb
rubocop-0.57.0 lib/rubocop/cop/naming/variable_name.rb
rubocop-0.56.0 lib/rubocop/cop/naming/variable_name.rb
rubocop-0.55.0 lib/rubocop/cop/naming/variable_name.rb
rubocop-0.54.0 lib/rubocop/cop/naming/variable_name.rb
rubocop-0.53.0 lib/rubocop/cop/naming/variable_name.rb
rubocop-0.52.1 lib/rubocop/cop/naming/variable_name.rb
rubocop-0.52.0 lib/rubocop/cop/naming/variable_name.rb