Class: RuboCop::Cop::UnusedArgCorrector
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
RangeHelp
|
|
Inherits: | Object |
Defined in: | lib/rubocop/cop/correctors/unused_arg_corrector.rb |
Overview
This autocorrects unused arguments.
Class Attribute Summary
- .processed_source readonly
Class Method Summary
RangeHelp
- Extended
add_range, column_offset_between, | |
contents_range | A range containing only the contents of a literal with delimiters (e.g. |
directions, | |
effective_column | Returns the column attribute of the range, except if the range is on the first line and there’s a byte order mark at the beginning of that line, in which case 1 is subtracted from the column value. |
final_pos, move_pos, move_pos_str, range_between, range_by_whole_lines, range_with_comments, range_with_comments_and_lines, range_with_surrounding_comma, range_with_surrounding_space, source_range |
Class Attribute Details
.processed_source (readonly)
[ GitHub ]# File 'lib/rubocop/cop/correctors/unused_arg_corrector.rb', line 10
attr_reader :processed_source
Class Method Details
.correct(corrector, processed_source, node)
[ GitHub ]# File 'lib/rubocop/cop/correctors/unused_arg_corrector.rb', line 12
def correct(corrector, processed_source, node) return if %i[kwarg kwoptarg].include?(node.type) @processed_source = processed_source if node.blockarg_type? correct_for_blockarg_type(corrector, node) else 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
.correct_for_blockarg_type(corrector, node)
[ GitHub ]# File 'lib/rubocop/cop/correctors/unused_arg_corrector.rb', line 31
def correct_for_blockarg_type(corrector, node) range = range_with_surrounding_space(node.source_range, side: :left) range = range_with_surrounding_comma(range, :left) corrector.remove(range) end