Sha256: c61fa82c0df46797d7c5c21af8f18a05119c6933143f9ad4b005dfa0b8368105

Contents?: true

Size: 1.2 KB

Versions: 32

Compression:

Stored size: 1.2 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.'

        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
        alias on_lvar      on_lvasgn

        private

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

Version data entries

32 entries across 25 versions & 5 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/naming/variable_name.rb
rubocop-0.86.0 lib/rubocop/cop/naming/variable_name.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/naming/variable_name.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/naming/variable_name.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/naming/variable_name.rb
rubocop-0.85.1 lib/rubocop/cop/naming/variable_name.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/naming/variable_name.rb
rubocop-0.85.0 lib/rubocop/cop/naming/variable_name.rb
rubocop-0.84.0 lib/rubocop/cop/naming/variable_name.rb
rubocop-0.83.0 lib/rubocop/cop/naming/variable_name.rb
rubocop-0.82.0 lib/rubocop/cop/naming/variable_name.rb
rubocop-0.81.0 lib/rubocop/cop/naming/variable_name.rb
rubocop-0.80.1 lib/rubocop/cop/naming/variable_name.rb
rubocop-0.80.0 lib/rubocop/cop/naming/variable_name.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/naming/variable_name.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/cop/naming/variable_name.rb
rubocop-0.79.0 lib/rubocop/cop/naming/variable_name.rb
rubocop-0.78.0 lib/rubocop/cop/naming/variable_name.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.1/lib/rubocop/cop/naming/variable_name.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/naming/variable_name.rb