Sha256: c27455a450b572898c69c19d70d0060aaccdedbb1dd9c91d88e77f96167aff39

Contents?: true

Size: 1.28 KB

Versions: 44

Compression:

Stored size: 1.28 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 < Base
        include AllowedIdentifiers
        include ConfigurableNaming

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

        def on_lvasgn(node)
          name, = *node
          return unless name
          return if allowed_identifier?(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

44 entries across 44 versions & 6 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/naming/variable_name.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/naming/variable_name.rb
rubocop-1.28.2 lib/rubocop/cop/naming/variable_name.rb
rubocop-1.28.1 lib/rubocop/cop/naming/variable_name.rb
rubocop-1.28.0 lib/rubocop/cop/naming/variable_name.rb
rubocop-1.27.0 lib/rubocop/cop/naming/variable_name.rb
rubocop-1.26.1 lib/rubocop/cop/naming/variable_name.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/rubocop-1.26.0/lib/rubocop/cop/naming/variable_name.rb
rubocop-1.26.0 lib/rubocop/cop/naming/variable_name.rb
rubocop-1.25.1 lib/rubocop/cop/naming/variable_name.rb
rubocop-1.25.0 lib/rubocop/cop/naming/variable_name.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/rubocop-1.24.0/lib/rubocop/cop/naming/variable_name.rb
rubocop-1.24.1 lib/rubocop/cop/naming/variable_name.rb
rubocop-1.24.0 lib/rubocop/cop/naming/variable_name.rb
rubocop-1.23.0 lib/rubocop/cop/naming/variable_name.rb
rubocop-1.22.3 lib/rubocop/cop/naming/variable_name.rb
rubocop-1.22.2 lib/rubocop/cop/naming/variable_name.rb
rubocop-1.22.1 lib/rubocop/cop/naming/variable_name.rb
rubocop-1.22.0 lib/rubocop/cop/naming/variable_name.rb
rubocop-1.21.0 lib/rubocop/cop/naming/variable_name.rb