Skip to content

Stop unused_parameter flagging $-prefixed closure parameters - #6763

Closed
systemblueio wants to merge 1 commit into
realm:mainfrom
systemblueio:fix/5740-unused-parameter-dollar
Closed

systemblueio wants to merge 1 commit into
realm:mainfrom
systemblueio:fix/5740-unused-parameter-dollar

Conversation

@systemblueio

Copy link
Copy Markdown
Contributor

Fixes #5740.

Problem

unused_parameter flagged $-prefixed closure parameters as unused:

list($items) { $item in
    row(item.title)   // uses the wrapped value `item`
}

A closure parameter written as a property-wrapper projection ($item) also
binds the wrapped value item, which is referenced here without the prefix.
The rule only tracked the $item spelling, so it reported the parameter as
unused, and its autocorrect rewrote the closure to invalid Swift:
list($items) { $item _ in ... }.

Fix

Skip $-prefixed parameters in the violation check, mirroring the existing
underscore handling. $-prefixed names only occur as closure projections, so
function, initializer, and subscript parameters are unaffected, and genuinely
unused regular closure parameters are still reported.

Tests

Added two non-triggering examples (wrapped value used, projected value used).
UnusedParameterRuleGeneratedTests passes, and the built binary no longer
reports the issue's example while still flagging a plain unused closure
parameter.

@SwiftLintBot

SwiftLintBot commented Jun 7, 2026 •

Copy link
Copy Markdown
19 Messages
📖 Building this branch resulted in the same binary size as when built on main.
📖 Linting Aerial with this PR took 0.12 s vs 0.1 s on main (19% slower).
📖 Linting Alamofire with this PR took 0.18 s vs 0.14 s on main (28% slower).
📖 Linting Brave with this PR took 0.49 s vs 0.48 s on main (2% slower).
📖 Linting DuckDuckGo with this PR took 2.04 s vs 2.07 s on main (1% faster).
📖 Linting Firefox with this PR took 0.88 s vs 0.93 s on main (5% faster).
📖 Linting Kickstarter with this PR took 0.57 s vs 0.55 s on main (3% slower).
📖 Linting Moya with this PR took 0.09 s vs 0.12 s on main (25% faster).
📖 Linting NetNewsWire with this PR took 0.23 s vs 0.24 s on main (4% faster).
📖 Linting Nimble with this PR took 0.1 s vs 0.12 s on main (16% faster).
📖 Linting PocketCasts with this PR took 0.58 s vs 0.64 s on main (9% faster).
📖 Linting Quick with this PR took 0.1 s vs 0.08 s on main (25% slower).
📖 Linting Realm with this PR took 0.23 s vs 0.25 s on main (7% faster).
📖 Linting Sourcery with this PR took 0.19 s vs 0.18 s on main (5% slower).
📖 Linting Swift with this PR took 0.3 s vs 0.31 s on main (3% faster).
📖 Linting SwiftLintPerformanceTests with this PR took 3.82 s vs 3.78 s on main (1% slower).
📖 Linting VLC with this PR took 0.18 s vs 0.19 s on main (5% faster).
📖 Linting Wire with this PR took 0.99 s vs 1.01 s on main (1% faster).
📖 Linting WordPress with this PR took 0.73 s vs 0.76 s on main (3% faster).

Generated by 🚫 Danger

A closure parameter written as a property-wrapper projection (e.g.
`list($items) { $item in ... }`) also binds the wrapped value `item`,
which can be referenced without the `$` prefix. The rule could not see
that implicit binding, so it reported the parameter as unused and its
autocorrect produced invalid Swift (`{ $item _ in }`).

Skip `$`-prefixed parameters in the violation check, mirroring the
existing underscore handling. `$`-prefixed names only occur as closure
projections, so regular parameters are unaffected.

Resolves #5740.

Co-Authored-By: Claude <noreply@anthropic.com>
@systemblueio systemblueio closed this by deleting the head repository Jun 9, 2026
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.

unused-parameter rule should not trigger on binding closure parameter

2 participants