Class: RuboCop::Cop::UnusedArgCorrector

Inherits:
Object
  • Object
show all
Extended by:
Util
Defined in:
lib/rubocop/cop/correctors/unused_arg_corrector.rb

Overview

This auto-corrects unused arguments.

Constant Summary

Constants included from Util

RuboCop::Cop::Util::ASGN_NODES, RuboCop::Cop::Util::BYTE_ORDER_MARK, RuboCop::Cop::Util::CONDITIONAL_NODES, RuboCop::Cop::Util::EQUALS_ASGN_NODES, RuboCop::Cop::Util::LITERAL_REGEX, RuboCop::Cop::Util::LOGICAL_OPERATOR_NODES, RuboCop::Cop::Util::MODIFIER_NODES, RuboCop::Cop::Util::OPERATOR_METHODS, RuboCop::Cop::Util::SHORTHAND_ASGN_NODES

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Util

begins_its_line?, comment_line?, double_quotes_required?, effective_column, ends_its_line?, escape_string, first_part_of_call_chain, interpret_string_escapes, line_range, needs_escaping?, on_node, operator?, parentheses?, parenthesized_call?, precede?, range_between, range_by_whole_lines, range_with_surrounding_comma, range_with_surrounding_space, same_line?, source_range, strip_quotes, stripped_source_upto, symbol_without_quote?, to_string_literal, to_supported_styles, to_symbol_literal, within_node?

Methods included from AST::Sexp

#s

Methods included from PathUtil

absolute?, find_file_upwards, match_path?, pwd, relative_path, reset_pwd, smart_path

Class Attribute Details

.processed_sourceObject (readonly)

Returns the value of attribute processed_source.



10
11
12
# File 'lib/rubocop/cop/correctors/unused_arg_corrector.rb', line 10

def processed_source
  @processed_source
end

Class Method Details

.correct(processed_source, node) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rubocop/cop/correctors/unused_arg_corrector.rb', line 12

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

  @processed_source = processed_source

  if node.blockarg_type?
    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
  else
    ->(corrector) { corrector.insert_before(node.loc.name, '_') }
  end
end