You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A bunch of minor bugs/problems with IndexWith. (Maybe it would’ve been better to make a ticket for each, but I assume they all can be fixed together.)
Mostly related to autocorrect (other than the first one).
The cop doesn’t detect problems with numbered block parameters collection.to_h { [_1, something(_1)] }. Probably affects IndexBy, too.
Autocorrection: Produces invalid code when there is a braceless hash in to_h:
a. code: collection.to_h { |x| [x, position: x, value: y] }.
b. correction: index_with { |x| position: x, value: y }
c. proper correction: index_with { |x| {position: x, value: y} }
Autocorrection: Ignores the simplification when value doesn’t depend on the key:
a. code: KEYS.to_h { |key| [key, true] } (frequently used in producing some initial/default value hashes)
b. correction: KEYS.index_with { |key| true }
c. better correction: KEYS.index_with(true)
Incorrect correction when keys are only the first element of the array (probably shouldn’t suggest correction at all):
A bunch of minor bugs/problems with IndexWith. (Maybe it would’ve been better to make a ticket for each, but I assume they all can be fixed together.)
Mostly related to autocorrect (other than the first one).
collection.to_h { [_1, something(_1)] }
. Probably affectsIndexBy
, too.to_h
:a. code:
collection.to_h { |x| [x, position: x, value: y] }
.b. correction:
index_with { |x| position: x, value: y }
c. proper correction:
index_with { |x| {position: x, value: y} }
a. code:
KEYS.to_h { |key| [key, true] }
(frequently used in producing some initial/default value hashes)b. correction:
KEYS.index_with { |key| true }
c. better correction:
KEYS.index_with(true)
RuboCop version
The text was updated successfully, but these errors were encountered: