Skip to content

Ignore unowned(unsafe) captures by default - #6824

Merged
SimplyDanny merged 2 commits into
realm:mainfrom
Yurii201811:fix/unowned-unsafe-captures
Jul 31, 2026
Merged

Ignore unowned(unsafe) captures by default#6824
SimplyDanny merged 2 commits into
realm:mainfrom
Yurii201811:fix/unowned-unsafe-captures

Conversation

@Yurii201811

Copy link
Copy Markdown
Contributor

Summary

Ignore unowned(unsafe) captures by default while preserving an opt-in include_unsafe setting.

Background

The explicit unsafe spelling communicates the intended lifetime tradeoff.

Closes #6817

Changes

  • add include_unsafe, defaulting to false
  • distinguish unsafe capture specifiers from unowned and unowned(safe)
  • cover default and configured behavior
  • update generated configuration metadata and changelog

Verification

  • generated rule tests
  • full Swift tests
  • SwiftLint self-lint
  • remaining platform gates or CI

@Yurii201811
Yurii201811 marked this pull request as ready for review July 13, 2026 08:45
@SwiftLintBot

SwiftLintBot commented Jul 13, 2026

Copy link
Copy Markdown
19 Messages
📖 Building this branch resulted in a binary size of 28379.07 KiB vs 28357.8 KiB when built on main (0% larger).
📖 Linting Aerial with this PR took 0.64 s vs 0.65 s on main (1% faster).
📖 Linting Alamofire with this PR took 0.93 s vs 0.92 s on main (1% slower).
📖 Linting Brave with this PR took 6.09 s vs 6.06 s on main (0% slower).
📖 Linting DuckDuckGo with this PR took 27.18 s vs 27.23 s on main (0% faster).
📖 Linting Firefox with this PR took 10.86 s vs 10.89 s on main (0% faster).
📖 Linting Kickstarter with this PR took 7.34 s vs 7.33 s on main (0% slower).
📖 Linting Moya with this PR took 0.37 s vs 0.36 s on main (2% slower).
📖 Linting NetNewsWire with this PR took 2.38 s vs 2.37 s on main (0% slower).
📖 Linting Nimble with this PR took 0.54 s vs 0.53 s on main (1% slower).
📖 Linting PocketCasts with this PR took 7.03 s vs 7.06 s on main (0% faster).
📖 Linting Quick with this PR took 0.35 s vs 0.35 s on main (0% slower).
📖 Linting Realm with this PR took 2.47 s vs 2.47 s on main (0% slower).
📖 Linting Sourcery with this PR took 1.46 s vs 1.48 s on main (1% faster).
📖 Linting Swift with this PR took 4.34 s vs 4.35 s on main (0% faster).
📖 Linting SwiftLintPerformanceTests with this PR took 0.17 s vs 0.17 s on main (0% slower).
📖 Linting VLC with this PR took 1.17 s vs 1.18 s on main (0% faster).
📖 Linting Wire with this PR took 15.57 s vs 15.65 s on main (0% faster).
📖 Linting WordPress with this PR took 9.85 s vs 9.92 s on main (0% faster).

Generated by 🚫 Danger

@SimplyDanny SimplyDanny left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @Yurii201811 for taking this!


private extension UnownedVariableCaptureRule {
final class Visitor: ViolationsSyntaxVisitor<ConfigurationType> {
override func visitPost(_ node: TokenSyntax) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's have a visitPost(_ node: ClosureCaptureSpecifierSyntax) instead which allows us to check for specifier and detail directly.

@ConfigurationElement(key: "severity")
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning)
@ConfigurationElement(key: "include_unsafe")
private(set) var includeUnsafe = false

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's call it allow_explicit_unsafe_unowned. It should be false by default to match the current behavior. It should be opt-in.

@SimplyDanny
SimplyDanny enabled auto-merge (squash) July 31, 2026 11:04
@SimplyDanny
SimplyDanny merged commit 50d40a9 into realm:main Jul 31, 2026
28 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.

unowned_variable_capture fires for unowned(unsafe) captures

3 participants