Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
koic committed Sep 14, 2017
1 parent 9024c8b commit 44fa554
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/rubocop/cop/lint/unneeded_with_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def on_block(node)
def autocorrect(node)
lambda do |corrector|
unneeded_with_index?(node) do |send|
if each_with_index_method?(node)
if send.method_name == :each_with_index
corrector.replace(send.loc.selector, 'each')
else
corrector.remove(send.loc.selector)
Expand All @@ -61,16 +61,16 @@ def autocorrect(node)
private

def message(node)
each_with_index_method?(node) ? MSG_EACH_WITH_INDEX : MSG_WITH_INDEX
if node.method_name == :each_with_index
MSG_EACH_WITH_INDEX
else
MSG_WITH_INDEX
end
end

def with_index_range(send)
range_between(send.loc.selector.begin_pos, send.loc.selector.end_pos)
end

def each_with_index_method?(node)
node.children.first.children.last == :each_with_index
end
end
end
end
Expand Down

0 comments on commit 44fa554

Please sign in to comment.