Repository navigation
Conversation
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
force-pushed
the
migrate-protocol-property-accessors-order-examples
branch
from
October 6, 2026 11:44
c98f11a to
7d1795a
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Migrates the examples of
protocol_property_accessors_orderfrom#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
↓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: "↓").protocol Foo { var bar: String { set } }does not compile ("variable with a setter must also have a getter"), but it is what covers theaccessorsList.count == 2guard, 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.swiftlint:disable allfor consistency withunused_parameter. To be precise, it is not strictly required here: the rule's visitor setsskippableDeclarationsto.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-docsoutput before and after,protocol_property_accessors_order.mdis the only file of 253 that changes.I did not add a
CHANGELOG.mdentry, 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 buildcleanswift testgreen, 1112 tests in 377 suitesProtocolPropertyAccessorsOrderRuleGeneratedTestsgreenswift run swiftlintreports 0 violations in 713 filesswift run swiftlint-dev rules registerproduces no diff