Skip to content

Migrate protocol_property_accessors_order examples to #example - #6910

Open
Akhrameev wants to merge 2 commits into
realm:mainfrom
Akhrameev:migrate-protocol-property-accessors-order-examples
Open

Akhrameev wants to merge 2 commits into
realm:mainfrom
Akhrameev:migrate-protocol-property-accessors-order-examples

Conversation

@Akhrameev

Copy link
Copy Markdown

Migrates the examples of protocol_property_accessors_order from #examples([...]) string literals to the #example { } macro added in #6893, so that they are compiled rather than merely stored as text. Progress toward #3348.

I picked this rule to go first because its examples were already self-contained, so no declarations had to be invented to make them compile.

Notes on the diff

  • The ↓ violation marker becomes /*>*/. without it the compiler tries to parse it and fails with "expected get or set in a protocol property". A comment is invisible to the compiler but survives in the closure's source text, which is what the macro reads, so the marker is restored on expansion by .replacing("/*>*/", with: "↓").
  • One non-triggering example stays a string. protocol Foo { var bar: String { set } } does not compile ("variable with a setter must also have a getter"), but it is what covers the accessorsList.count == 2 guard, so it now has a comment explaining why.
  • #corrections([...]) becomes a plain dictionary literal of two #example { } values, so both sides of the correction pair are compiled too.
  • The block is wrapped in swiftlint:disable all for consistency with unused_parameter. To be precise, it is not strictly required here: the rule's visitor sets skippableDeclarations to .allExcept(ProtocolDeclSyntax.self, VariableDeclSyntax.self), so it never descends into the enclosing struct, and the file lints clean without the directive.

Effect on the rendered documentation

No content changes, only indentation. The string literals hard-coded the line breaks, so the published examples carried a one-space indent and a dangling closing brace:

 protocol Foo {
- var bar: String { get set }
- }
+    var bar: String { get set }
 }

Four blocks on the rule's documentation page are affected. Comparing swiftlint generate-docs output before and after, protocol_property_accessors_order.md is the only file of 253 that changes.

I did not add a CHANGELOG.md entry, on the grounds that this changes only example indentation in the documentation and #6893 landed the same kind of migration without one. Happy to add an entry if you would prefer.

Checks

  • swift build clean
  • swift test green, 1112 tests in 377 suites
  • ProtocolPropertyAccessorsOrderRuleGeneratedTests green
  • swift run swiftlint reports 0 violations in 713 files
  • swift run swiftlint-dev rules register produces no diff

@SwiftLintBot

SwiftLintBot commented Sep 17, 2026 •

Copy link
Copy Markdown
1 Warning
⚠️ This PR may need tests.
20 Messages
📖 Building this branch resulted in the same binary size as when built on main.
📖 Linting Aerial with this PR took 0.1 s vs 0.1 s on main (0% slower).
📖 Linting Alamofire with this PR took 0.11 s vs 0.11 s on main (0% slower).
📖 Linting Brave with this PR took 0.34 s vs 0.33 s on main (3% slower).
📖 Linting Brigade with this PR took 18.71 s vs 18.68 s on main (0% slower).
📖 Linting DuckDuckGo with this PR took 1.95 s vs 1.93 s on main (1% slower).
📖 Linting Firefox with this PR took 0.67 s vs 0.68 s on main (1% faster).
📖 Linting Kickstarter with this PR took 0.41 s vs 0.41 s on main (0% slower).
📖 Linting Moya with this PR took 0.09 s vs 0.09 s on main (0% slower).
📖 Linting NetNewsWire with this PR took 0.17 s vs 0.17 s on main (0% slower).
📖 Linting Nimble with this PR took 0.09 s vs 0.09 s on main (0% slower).
📖 Linting PocketCasts with this PR took 0.46 s vs 0.46 s on main (0% slower).
📖 Linting Quick with this PR took 0.09 s vs 0.09 s on main (0% slower).
📖 Linting Realm with this PR took 0.19 s vs 0.18 s on main (5% slower).
📖 Linting Sourcery with this PR took 0.14 s vs 0.14 s on main (0% slower).
📖 Linting Swift with this PR took 0.19 s vs 0.19 s on main (0% slower).
📖 Linting SwiftLintPerformanceTests with this PR took 3.8 s vs 3.78 s on main (0% slower).
📖 Linting VLC with this PR took 0.17 s vs 0.17 s on main (0% slower).
📖 Linting Wire with this PR took 0.68 s vs 0.7 s on main (2% faster).
📖 Linting WordPress with this PR took 0.52 s vs 0.51 s on main (1% slower).

Generated by 🚫 Danger

The examples are now real code compiled by the macro, which is what
issue realm#3348 asks for. Nothing had to be invented to make them compile:
every example was already a self-contained protocol declaration.

One non-triggering example stays a string. `var bar: String { set }`
does not compile, because a setter requires a getter, but it is what
covers the rule's two-accessor guard, so it keeps a comment saying why.

Rendered documentation improves as a side effect. The old string
literals hard-coded the line breaks and indentation, so the docs showed
a one-space indent and a dangling closing brace.
@Akhrameev
Akhrameev force-pushed the migrate-protocol-property-accessors-order-examples branch from c98f11a to 7d1795a Compare October 6, 2026 11:44

This branch has not been deployed

No deployments
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