Sha256: 4a1e287e8c3e9dce35c6e2ad139df77259c2ad4ac74f78106f27d5b64dfe6236

Contents?: true

Size: 1.25 KB

Versions: 62

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # This auto-corrects unused arguments.
    class UnusedArgCorrector
      extend RangeHelp

      class << self
        attr_reader :processed_source

        def correct(processed_source, node)
          return if %i[kwarg kwoptarg].include?(node.type)

          @processed_source = processed_source

          if node.blockarg_type?
            correct_for_blockarg_type(node)
          else
            lambda do |corrector|
              variable_name = if node.optarg_type?
                                node.node_parts[0]
                              else
                                # Extract only a var name without splat (`*`)
                                node.source.gsub(/\A\*+/, '')
                              end
              corrector.replace(node.loc.name, "_#{variable_name}")
            end
          end
        end

        def correct_for_blockarg_type(node)
          lambda do |corrector|
            range = range_with_surrounding_space(range: node.source_range,
                                                 side: :left)
            range = range_with_surrounding_comma(range, :left)
            corrector.remove(range)
          end
        end
      end
    end
  end
end

Version data entries

62 entries across 43 versions & 5 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/correctors/unused_arg_corrector.rb
rubocop-0.88.0 lib/rubocop/cop/correctors/unused_arg_corrector.rb
rbhint-0.87.1.rc1 lib/rubocop/cop/correctors/unused_arg_corrector.rb
rubocop-0.87.1 lib/rubocop/cop/correctors/unused_arg_corrector.rb
rubocop-0.87.0 lib/rubocop/cop/correctors/unused_arg_corrector.rb
rubocop-0.86.0 lib/rubocop/cop/correctors/unused_arg_corrector.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/correctors/unused_arg_corrector.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/correctors/unused_arg_corrector.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/correctors/unused_arg_corrector.rb
rubocop-0.85.1 lib/rubocop/cop/correctors/unused_arg_corrector.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/correctors/unused_arg_corrector.rb
rubocop-0.85.0 lib/rubocop/cop/correctors/unused_arg_corrector.rb
rubocop-0.84.0 lib/rubocop/cop/correctors/unused_arg_corrector.rb
rubocop-0.83.0 lib/rubocop/cop/correctors/unused_arg_corrector.rb
rubocop-0.82.0 lib/rubocop/cop/correctors/unused_arg_corrector.rb
rubocop-0.81.0 lib/rubocop/cop/correctors/unused_arg_corrector.rb
rubocop-0.80.1 lib/rubocop/cop/correctors/unused_arg_corrector.rb
rubocop-0.80.0 lib/rubocop/cop/correctors/unused_arg_corrector.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/cop/correctors/unused_arg_corrector.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/correctors/unused_arg_corrector.rb