Skip to content

Fix an incorrect autocorrect for Performance/MapCompact when used as an argument - #556

Merged
koic merged 1 commit into
rubocop:masterfrom
Starlexxx:fix-map-compact-as-argument
Nov 8, 2026
Merged

koic merged 1 commit into
rubocop:masterfrom
Starlexxx:fix-map-compact-as-argument

Conversation

@Starlexxx

Copy link
Copy Markdown
Contributor

The call wrapping a multiline map ... end.compact was taken for a method chained after compact, so the whole end.compact line was removed together with the block's end:

Set.new(
  members.map do |n, s|
    n if s.header?
  end.compact
)

# => Set.new(
#      members.filter_map do |n, s|
#        n if s.header?
#    )

Only a call whose receiver is the compact call is treated as chained now.

Found by rubocop-fuzz on aws-sdk-s3.

@Starlexxx
Starlexxx force-pushed the fix-map-compact-as-argument branch from 89e29e1 to 38552b3 Compare October 30, 2026 14:56
@koic
koic merged commit 22a6f21 into rubocop:master Nov 8, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants