Class: Rubocop::Cop::ReduceArguments

Inherits:
Cop
  • Object
show all
Defined in:
lib/rubocop/cop/reduce_arguments.rb

Constant Summary collapse

ERROR_MESSAGE =
'Name reduce arguments |a, e| (accumulator, element)'

Instance Attribute Summary

Attributes inherited from Cop

#correlations, #debug, #disabled_lines, #offences

Instance Method Summary collapse

Methods inherited from Cop

#add_offence, cop_name, #has_report?, inherited, #initialize, #name

Constructor Details

This class inherits a constructor from Rubocop::Cop::Cop

Instance Method Details

#inspect(file, source, tokens, sexp) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/rubocop/cop/reduce_arguments.rb', line 8

def inspect(file, source, tokens, sexp)
  find_reduce_blocks(tokens).each do |reduce_block|
    l_ix, r_ix = reduce_block
    unless arguments_named_properly?(l_ix, r_ix, tokens)
      add_offence(:convention, tokens[l_ix].pos.lineno, ERROR_MESSAGE)
    end
  end
end