Sha256: 9e9354429ffef4bf77cf43499345d360c4e1971f649c091357ed250330a572f2

Contents?: true

Size: 1.18 KB

Versions: 195

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # Checks for numbered parameters.
      #
      # It can either restrict the use of numbered parameters to
      # single-lined blocks, or disallow completely numbered parameters.
      #
      # @example EnforcedStyle: allow_single_line (default)
      #   # bad
      #   collection.each do
      #     puts _1
      #   end
      #
      #   # good
      #   collection.each { puts _1 }
      #
      # @example EnforcedStyle: disallow
      #   # bad
      #   collection.each { puts _1 }
      #
      #   # good
      #   collection.each { |item| puts item }
      #
      class NumberedParameters < Base
        include ConfigurableEnforcedStyle
        extend TargetRubyVersion

        MSG_DISALLOW = 'Avoid using numbered parameters.'
        MSG_MULTI_LINE = 'Avoid using numbered parameters for multi-line blocks.'

        minimum_target_ruby_version 2.7

        def on_numblock(node)
          if style == :disallow
            add_offense(node, message: MSG_DISALLOW)
          elsif node.multiline?
            add_offense(node, message: MSG_MULTI_LINE)
          end
        end
      end
    end
  end
end

Version data entries

195 entries across 188 versions & 19 rubygems

Version Path
study_line-0.2.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/style/numbered_parameters.rb
study_line-0.2.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/style/numbered_parameters.rb
rubocop-1.60.0 lib/rubocop/cop/style/numbered_parameters.rb
harbr-0.2.10 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/numbered_parameters.rb
harbr-0.2.9 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/numbered_parameters.rb
harbr-0.2.8 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/numbered_parameters.rb
harbr-0.2.7 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/numbered_parameters.rb
harbr-0.2.6 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/numbered_parameters.rb
harbr-0.2.5 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/numbered_parameters.rb
harbr-0.2.4 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/numbered_parameters.rb
harbr-0.2.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/numbered_parameters.rb
harbr-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/numbered_parameters.rb
harbr-0.2.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/numbered_parameters.rb
harbr-0.2.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/numbered_parameters.rb
harbr-0.1.99 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/numbered_parameters.rb
harbr-0.1.98 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/numbered_parameters.rb
harbr-0.1.97 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/numbered_parameters.rb
harbr-0.1.96 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/numbered_parameters.rb
harbr-0.1.95 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/numbered_parameters.rb
harbr-0.1.94 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/numbered_parameters.rb