Sha256: eca7c70c606850110aeaacbe79884fd65bfaa6d641850ac88cbc1809e28c8ecb

Contents?: true

Size: 1.16 KB

Versions: 10

Compression:

Stored size: 1.16 KB

Contents

# encoding: utf-8
# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # Common functionality for cops handling unused arguments.
      module UnusedArgument
        def join_force?(force_class)
          force_class == VariableForce
        end

        def after_leaving_scope(scope, _variable_table)
          scope.variables.each_value do |variable|
            check_argument(variable)
          end
        end

        def check_argument(variable)
          return if variable.should_be_unused?
          return if variable.referenced?

          message = message(variable)
          add_offense(variable.declaration_node, :name, message)
        end

        def autocorrect(node)
          return if [:kwarg, :kwoptarg].include?(node.type)

          if node.blockarg_type?
            lambda do |corrector|
              range = range_with_surrounding_space(node.source_range, :left)
              range = range_with_surrounding_comma(range, :left)
              corrector.remove(range)
            end
          else
            ->(corrector) { corrector.insert_before(node.loc.name, '_') }
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/mixin/unused_argument.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/mixin/unused_argument.rb
rubocop-0.43.0 lib/rubocop/cop/mixin/unused_argument.rb
rubocop-0.42.0 lib/rubocop/cop/mixin/unused_argument.rb
rubocop-0.41.2 lib/rubocop/cop/mixin/unused_argument.rb
rubocop-0.41.1 lib/rubocop/cop/mixin/unused_argument.rb
rubocop-0.41.0 lib/rubocop/cop/mixin/unused_argument.rb
rubocop-0.40.0 lib/rubocop/cop/mixin/unused_argument.rb
rubocop-0.39.0 lib/rubocop/cop/mixin/unused_argument.rb
rubocop-0.38.0 lib/rubocop/cop/mixin/unused_argument.rb