Skip to content

Allow prefer_key_paths to ignore identity closures ({ $0 }) #6068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

p4checo
Copy link
Contributor

@p4checo p4checo commented Apr 26, 2025

Add new ignore_identity_closures parameter to prefer_key_paths rule to skip conversion of identity closures ({ $0 }) to identity key paths (\self).

Add a small note to the rule description stating that identity key path conversion is Swift 6+ only.

@SwiftLintBot
Copy link

SwiftLintBot commented Apr 27, 2025

18 Messages
📖 Building this branch resulted in a binary size of 25521.05 KiB vs 25519.87 KiB when built on main (0% larger).
📖 Linting Aerial with this PR took 1.05 s vs 1.06 s on main (0% faster).
📖 Linting Alamofire with this PR took 1.41 s vs 1.41 s on main (0% slower).
📖 Linting Brave with this PR took 9.52 s vs 9.54 s on main (0% faster).
📖 Linting DuckDuckGo with this PR took 26.85 s vs 26.92 s on main (0% faster).
📖 Linting Firefox with this PR took 14.11 s vs 14.13 s on main (0% faster).
📖 Linting Kickstarter with this PR took 10.78 s vs 10.79 s on main (0% faster).
📖 Linting Moya with this PR took 0.56 s vs 0.56 s on main (0% slower).
📖 Linting NetNewsWire with this PR took 3.21 s vs 3.21 s on main (0% slower).
📖 Linting Nimble with this PR took 0.85 s vs 0.85 s on main (0% slower).
📖 Linting PocketCasts with this PR took 9.43 s vs 9.3 s on main (1% slower).
📖 Linting Quick with this PR took 0.49 s vs 0.5 s on main (2% faster).
📖 Linting Realm with this PR took 4.85 s vs 4.84 s on main (0% slower).
📖 Linting Sourcery with this PR took 2.48 s vs 2.48 s on main (0% slower).
📖 Linting Swift with this PR took 5.67 s vs 5.69 s on main (0% faster).
📖 Linting VLC with this PR took 1.5 s vs 1.51 s on main (0% faster).
📖 Linting Wire with this PR took 22.8 s vs 22.83 s on main (0% faster).
📖 Linting WordPress with this PR took 13.77 s vs 13.82 s on main (0% faster).

Generated by 🚫 Danger

Copy link
Collaborator

@SimplyDanny SimplyDanny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in general. Thanks!

Please see my comments and rebase your branch to make all tests run (there are relevant fixes on main).


static let description = RuleDescription(
identifier: "prefer_key_path",
name: "Prefer Key Path",
description: "Use a key path argument instead of a closure with property access",
description: """
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep the existing description as it's currently also used as the violation message and add a rational property instead to explain this detail.

@p4checo p4checo force-pushed the prefer-key-path-rule-ignore-identity-closure branch 4 times, most recently from 0b22e4f to cbf90c0 Compare August 6, 2025 11:23
@p4checo
Copy link
Contributor Author

p4checo commented Aug 6, 2025

Ready for re-review @SimplyDanny

Not sure what is causing the buildkite/swiftlint/bazel and buildkite/swiftlint/registration CI steps to fail, as I ran both command sequences locally and they succeed. They seem to be linker issues caused by some TSan symbols, so perhaps caused by some caching issue?

Thanks 🙏🏼

Copy link
Collaborator

@SimplyDanny SimplyDanny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a few more stylistic issue. Other than that, it looks good!

p4checo and others added 5 commits August 14, 2025 22:51
Add new `ignore_identity_closures` parameter to `prefer_key_paths` rule
to skip conversion of identity closures (`{ $0 }`) to identity key
paths (`\self`).

Add a small note to the rule description stating that identity key path
conversion is Swift 6+ only.
Co-authored-by: Danny Mösch <[email protected]>
@SimplyDanny SimplyDanny force-pushed the prefer-key-path-rule-ignore-identity-closure branch from ca999dc to 86890ba Compare August 14, 2025 20:53
@SimplyDanny SimplyDanny enabled auto-merge (squash) August 14, 2025 20:53
@SimplyDanny SimplyDanny merged commit fe09949 into realm:main Aug 14, 2025
20 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.

prefer_key_path in 0.58.0 warns if {$0} instead of (\.self) for SwiftPM using Swift 5
3 participants