Sha256: c17a7d08339cbcf9b90ddb04b8aa9f4a769748c730312a34e92ebcde71061d9b

Contents?: true

Size: 1.21 KB

Versions: 21

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Naming
      # This cop makes sure that all numbered variables use the
      # configured style, snake_case, normalcase, or non_integer,
      # for their numbering.
      #
      # @example EnforcedStyle: snake_case
      #   # bad
      #
      #   variable1 = 1
      #
      #   # good
      #
      #   variable_1 = 1
      #
      # @example EnforcedStyle: normalcase (default)
      #   # bad
      #
      #   variable_1 = 1
      #
      #   # good
      #
      #   variable1 = 1
      #
      # @example EnforcedStyle: non_integer
      #   # bad
      #
      #   variable1 = 1
      #
      #   variable_1 = 1
      #
      #   # good
      #
      #   variableone = 1
      #
      #   variable_one = 1
      class VariableNumber < Base
        include ConfigurableNumbering

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

        def on_arg(node)
          name, = *node
          check_name(node, name, node.loc.name)
        end
        alias on_lvasgn on_arg
        alias on_ivasgn on_arg
        alias on_cvasgn on_arg

        private

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

Version data entries

21 entries across 21 versions & 4 rubygems

Version Path
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/naming/variable_number.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/naming/variable_number.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/naming/variable_number.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/naming/variable_number.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/naming/variable_number.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/naming/variable_number.rb
rubocop-1.1.0 lib/rubocop/cop/naming/variable_number.rb
rubocop-1.0.0 lib/rubocop/cop/naming/variable_number.rb
rubocop-0.93.1 lib/rubocop/cop/naming/variable_number.rb
rubocop-0.93.0 lib/rubocop/cop/naming/variable_number.rb
rubocop-0.92.0 lib/rubocop/cop/naming/variable_number.rb
rubocop-0.91.1 lib/rubocop/cop/naming/variable_number.rb
rubocop-0.91.0 lib/rubocop/cop/naming/variable_number.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.90.0/lib/rubocop/cop/naming/variable_number.rb
rubocop-0.90.0 lib/rubocop/cop/naming/variable_number.rb
rubocop-0.89.1 lib/rubocop/cop/naming/variable_number.rb
rubocop-0.89.0 lib/rubocop/cop/naming/variable_number.rb
rubocop-0.88.0 lib/rubocop/cop/naming/variable_number.rb
rbhint-0.87.1.rc1 lib/rubocop/cop/naming/variable_number.rb
rubocop-0.87.1 lib/rubocop/cop/naming/variable_number.rb