+ Add associate_by_identity
as an alternate to associate
#798
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In #184, it was noticed that
associate
's result is unusable for separate nodes that might have identical content.The method
associate_by_locations
, which uses locations instead of nodes as indices, was added as a workaround.It was discussed at the time to change the definition of equality for
Node
(which was rejected) but it doesn't look like usingHash#compare_by_identity
was discussed which surprises me. For any user ofparser
that does not play around itsNode
s and only uses those returned from parsing, this seems like the perfect solution.This PR proposes to add
associate_by_identity
that does just that.This would be helpful for rubocop/rubocop#9756
If this is accepted, a release would be appreciated.