Skip to content

Commit

Permalink
Use stable sort when sorting tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima authored and marcandre committed Sep 18, 2020
1 parent 7e745be commit a1035a1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rubocop/ast/processed_source.rb
Expand Up @@ -269,7 +269,8 @@ def last_token_index(range_or_node)
# is passed as a method argument. In this case tokens are interleaved by
# heredoc contents' tokens.
def sorted_tokens
@sorted_tokens ||= tokens.sort_by(&:begin_pos)
# Use stable sort.
@sorted_tokens ||= tokens.sort_by.with_index { |token, i| [token.begin_pos, i] }
end

def source_range(range_or_node)
Expand Down

0 comments on commit a1035a1

Please sign in to comment.