-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Closed
Copy link
Labels
Description
Seems like an obvious issue that has been considered during implementation of this cop, but couldn't find any duplicates searching for "map to_h", so reporting just in case.
Steps to reproduce the problem
[1, 2, 3].map { it * 10 }.to_h do
[it, it * 100]
end.then { pp it }Actual behavior
Says Style/MapToHash: Pass a block to to_h instead of calling map.to_h.
Replacing map with to_h will obviously break the code, as to_h belongs to its following block
The message could implicitly hint at merging the code like so, but this requires some lenience on the reader's part.
[1, 2, 3].to_h do
it *= 10
[it, it * 100]
end.then { pp it }Expected behavior
A) Whitelist it (preferably)
B) Suggest something like "merge the blocks", but original code might be perfectly acceptable for clarity (so rather not)
RuboCop version
ruby : 3.4.5 (2025-07-16 revision 20cda200d3) +PRISM [arm64-darwin24]
rubocop: git 2025-08-04 12:08:56 eb470cef9
System : macOS 15.5 (24F74)
Model : MacBookAir10,1