Skip to content

Mark Performance/ChainArrayAllocation as unsafe and document ownership - #550

Open
thomasklemm wants to merge 1 commit into
rubocop:masterfrom
thomasklemm:thomasklemm/chain-array-ownership
Open

thomasklemm wants to merge 1 commit into
rubocop:masterfrom
thomasklemm:thomasklemm/chain-array-ownership

Conversation

@thomasklemm

@thomasklemm thomasklemm commented Oct 22, 2026 •

Copy link
Copy Markdown

Performance/ChainArrayAllocation recommends mutating an intermediate array, but cannot prove that the result is mutable and exclusively owned. An override can retain or freeze it. The new example shows uniq.map! changing an array retained by an Array subclass.

This documents that ownership boundary, keeps the first operation non-mutating in the ordinary Array example, and sets Safe: false. Detection is unchanged, the cop remains disabled by default, and it still has no autocorrection. When explicitly enabled, the cop is now skipped by --safe; normal runs are unchanged.

Related ownership discussion: #432. This does not implement or close that proposed reassignment cop.

The cop suggests mutating an intermediate array, but an overridden
method may return a shared or frozen array. Mark it Safe: false and
document the ownership hazard; detection is unchanged.
@thomasklemm
thomasklemm force-pushed the thomasklemm/chain-array-ownership branch from 5bf156f to 4a8d45f Compare November 18, 2026 11:59
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.

1 participant