Sha256: 0450fea2461533890a618e91c6c2ddf144d01f71abcc9ac2af56210efa07e9ad

Contents?: true

Size: 1.67 KB

Versions: 140

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Naming
      # 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
      #
      # @example AllowedIdentifiers: ['fooBar']
      #   # good (with EnforcedStyle: snake_case)
      #   fooBar = 1
      #
      # @example AllowedPatterns: ['_v\d+\z']
      #   # good (with EnforcedStyle: camelCase)
      #   :release_v1
      #
      class VariableName < Base
        include AllowedIdentifiers
        include ConfigurableNaming
        include AllowedPattern

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

        def valid_name?(node, name, given_style = style)
          super || matches_allowed_pattern?(name)
        end

        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

140 entries across 139 versions & 13 rubygems

Version Path
harbr-0.1.38 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/naming/variable_name.rb
harbr-0.1.37 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/naming/variable_name.rb
getargv-0.3.3-universal-darwin vendor/bundle/ruby/3.3.0/gems/rubocop-1.59.0/lib/rubocop/cop/naming/variable_name.rb
rubocop-1.59.0 lib/rubocop/cop/naming/variable_name.rb
study_line-0.1.6 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/naming/variable_name.rb
study_line-0.1.5 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/naming/variable_name.rb
study_line-0.1.4 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/naming/variable_name.rb
study_line-0.1.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/naming/variable_name.rb
study_line-0.1.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/naming/variable_name.rb
study_line-0.1.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/naming/variable_name.rb
rubocop-1.58.0 lib/rubocop/cop/naming/variable_name.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.52.1/lib/rubocop/cop/naming/variable_name.rb
rubocop-1.57.2 lib/rubocop/cop/naming/variable_name.rb
rubocop-1.57.1 lib/rubocop/cop/naming/variable_name.rb
rubocop-1.57.0 lib/rubocop/cop/naming/variable_name.rb
rubocop-1.56.4 lib/rubocop/cop/naming/variable_name.rb
rubocop-1.56.3 lib/rubocop/cop/naming/variable_name.rb
rubocop-1.56.2 lib/rubocop/cop/naming/variable_name.rb
synctera_ruby_sdk-1.1.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/naming/variable_name.rb
synctera_ruby_sdk-1.1.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/naming/variable_name.rb