Skip to content

Commit 580d863

Browse files
authored
Fix inline ignore comment not working on properties (#1025)
1 parent 644c9c3 commit 580d863

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
##### Bug Fixes
1515

16+
- Fix inline ignore comment not working on properties.
1617
- Fix false positive when a constrained protocol extension provides a default implementation that satisfies a requirement of the constraining protocol.
1718
- Fix indexing of xib/storyboard files in SPM projects.
1819
- Fix types conforming to App Intents protocols being reported as unused.

Sources/SyntaxAnalysis/DeclarationSyntaxVisitor.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ private extension SyntaxProtocol {
528528
/// Foo {} // periphery:ignore
529529
/// ```
530530
var commentCommandTrivia: Trivia {
531-
var commandTrivia = leadingTrivia
531+
var commandTrivia = leadingTrivia.merging(trailingTrivia)
532532

533533
if let hasMemberBlock = self as? HasMemberBlock {
534534
commandTrivia = commandTrivia
@@ -542,6 +542,12 @@ private extension SyntaxProtocol {
542542
.merging(body.rightBrace.trailingTrivia)
543543
}
544544

545+
if let hasAccessorBlock = self as? HasAccessorBlock, let accessorBlock = hasAccessorBlock.accessorBlock {
546+
commandTrivia = commandTrivia
547+
.merging(accessorBlock.leftBrace.trailingTrivia)
548+
.merging(accessorBlock.rightBrace.trailingTrivia)
549+
}
550+
545551
return commandTrivia
546552
}
547553
}
@@ -566,3 +572,14 @@ private protocol HasCodeBody {
566572
extension FunctionDeclSyntax: HasCodeBody {}
567573
extension InitializerDeclSyntax: HasCodeBody {}
568574
extension DeinitializerDeclSyntax: HasCodeBody {}
575+
576+
/// Identifies types with an AccessorBlockSyntax child
577+
private protocol HasAccessorBlock {
578+
var accessorBlock: AccessorBlockSyntax? { get }
579+
}
580+
581+
extension VariableDeclSyntax: HasAccessorBlock {
582+
var accessorBlock: AccessorBlockSyntax? {
583+
bindings.first?.accessorBlock
584+
}
585+
}

Tests/Fixtures/Sources/RetentionFixtures/testIgnoreComments.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,16 @@ public class Fixture308Class {
113113
public class Fixture309Class { // periphery:ignore
114114
public let reference = Fixture308Class()
115115
}
116+
117+
// Test inline ignore comments on properties
118+
public class Fixture310Class {
119+
var simplePropertyInlineIgnored: Int = 0 // periphery:ignore
120+
var computedPropertyInlineIgnored: Int { 0 } // periphery:ignore
121+
var computedPropertyWithOpenBraceIgnore: Int { // periphery:ignore
122+
0
123+
}
124+
}
125+
126+
public protocol Fixture311Protocol {
127+
var protocolPropertyInlineIgnored: String { get } // periphery:ignore
128+
}

Tests/PeripheryTests/RetentionTest.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,16 @@ final class RetentionTest: FixtureSourceGraphTestCase {
11131113
assertReferenced(.class("Fixture205"))
11141114
assertReferenced(.protocol("Fixture205Protocol"))
11151115
assertNotRedundantProtocol("Fixture205Protocol")
1116+
1117+
// Inline ignore comments on properties (issue #941)
1118+
assertReferenced(.class("Fixture310Class")) {
1119+
self.assertReferenced(.varInstance("simplePropertyInlineIgnored"))
1120+
self.assertReferenced(.varInstance("computedPropertyInlineIgnored"))
1121+
self.assertReferenced(.varInstance("computedPropertyWithOpenBraceIgnore"))
1122+
}
1123+
assertReferenced(.protocol("Fixture311Protocol")) {
1124+
self.assertReferenced(.varInstance("protocolPropertyInlineIgnored"))
1125+
}
11161126
}
11171127

11181128
// inline comment command tests

0 commit comments

Comments
 (0)