diff --git a/CHANGELOG.md b/CHANGELOG.md index b1e0abb0e..27afd78e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Fix unused import false-positive for when a declaration's associated types are declared in different module than module that declares the declaration. - Fix unused import false-positive for modules that export unindexed modules. - Exclude conditionally imported modules from unused import detection, as they may provide symbols for code that was not compiled. +- Fix `--retain-assign-only-property-types` for properties with trailing comments. ## 3.2.0 (2025-06-27) diff --git a/Sources/SyntaxAnalysis/DeclarationSyntaxVisitor.swift b/Sources/SyntaxAnalysis/DeclarationSyntaxVisitor.swift index aed5dbc6e..b3778af52 100644 --- a/Sources/SyntaxAnalysis/DeclarationSyntaxVisitor.swift +++ b/Sources/SyntaxAnalysis/DeclarationSyntaxVisitor.swift @@ -303,7 +303,7 @@ public final class DeclarationSyntaxVisitor: PeripherySyntaxVisitor { let modifierNames = modifiers?.map(\.name.text) ?? [] let accessibility = modifierNames.mapFirst { Accessibility(rawValue: $0) } let attributeNames = attributes?.compactMap { - AttributeSyntax($0)?.attributeName.trimmedDescription ?? AttributeSyntax($0)?.attributeName.firstToken(viewMode: .sourceAccurate)?.text + AttributeSyntax($0)?.attributeName.trimmed.description ?? AttributeSyntax($0)?.attributeName.firstToken(viewMode: .sourceAccurate)?.text } ?? [] let location = sourceLocationBuilder.location(at: position) let returnClauseTypeLocations = typeNameLocations(for: returnClause) @@ -353,11 +353,11 @@ public final class DeclarationSyntaxVisitor: PeripherySyntaxVisitor { let genericParameterNames = genericParameterClause .parameters - .mapSet { $0.name.trimmedDescription } + .mapSet { $0.name.trimmed.description } return parameterClauseTypes .contains { - if let baseTypeName = $0.as(MetatypeTypeSyntax.self)?.baseType.trimmedDescription, + if let baseTypeName = $0.as(MetatypeTypeSyntax.self)?.baseType.trimmed.description, genericParameterNames.contains(baseTypeName), returnClauseTypeLocations.contains(where: { $0.name == baseTypeName }) { diff --git a/Sources/SyntaxAnalysis/ImportSyntaxVisitor.swift b/Sources/SyntaxAnalysis/ImportSyntaxVisitor.swift index fb36bc5c9..b549e00f1 100644 --- a/Sources/SyntaxAnalysis/ImportSyntaxVisitor.swift +++ b/Sources/SyntaxAnalysis/ImportSyntaxVisitor.swift @@ -16,7 +16,7 @@ public final class ImportSyntaxVisitor: PeripherySyntaxVisitor { let module = parts.first ?? "" let attributes = node.attributes.compactMap { if case let .attribute(attr) = $0 { - attr.attributeName.trimmedDescription + attr.attributeName.trimmed.description } else { nil } diff --git a/Sources/SyntaxAnalysis/TypeSyntaxInspector.swift b/Sources/SyntaxAnalysis/TypeSyntaxInspector.swift index b535c0a9c..7002fd61c 100644 --- a/Sources/SyntaxAnalysis/TypeSyntaxInspector.swift +++ b/Sources/SyntaxAnalysis/TypeSyntaxInspector.swift @@ -12,12 +12,12 @@ struct TypeSyntaxInspector { let sourceLocationBuilder: SourceLocationBuilder func type(for typeSyntax: TypeSyntax) -> String { - PropertyTypeSanitizer.sanitize(typeSyntax.description) + PropertyTypeSanitizer.sanitize(typeSyntax.trimmed.description) } func typeNameLocations(for typeSyntax: TypeSyntax) -> Set { types(for: typeSyntax).mapSet { - .init(name: $0.trimmedDescription, + .init(name: $0.trimmed.description, location: sourceLocationBuilder.location(at: $0.positionAfterSkippingLeadingTrivia)) } } diff --git a/Sources/SyntaxAnalysis/UnusedParameterParser.swift b/Sources/SyntaxAnalysis/UnusedParameterParser.swift index c3661359d..c012766aa 100644 --- a/Sources/SyntaxAnalysis/UnusedParameterParser.swift +++ b/Sources/SyntaxAnalysis/UnusedParameterParser.swift @@ -302,8 +302,8 @@ struct UnusedParameterParser { .compactMap { if case let .attribute(attr) = $0 { return Attribute( - name: attr.attributeName.trimmedDescription, - arguments: attr.arguments?.trimmedDescription + name: attr.attributeName.trimmed.description, + arguments: attr.arguments?.trimmed.description ) } diff --git a/Tests/Fixtures/Sources/DeclarationVisitorFixtures/PropertyFixture.swift b/Tests/Fixtures/Sources/DeclarationVisitorFixtures/PropertyFixture.swift index ab9e51181..1f2a5d829 100644 --- a/Tests/Fixtures/Sources/DeclarationVisitorFixtures/PropertyFixture.swift +++ b/Tests/Fixtures/Sources/DeclarationVisitorFixtures/PropertyFixture.swift @@ -19,4 +19,5 @@ class PropertyVisitorTestFixture { (CustomType.NestedType, CustomType.NestedType.NestedScalar, Swift.String) = (.init(), 1, "1") let (implicitDestructuringPropertyA, implicitDestructuringPropertyB) = (CustomType(), "1") let multipleBindingPropertyA: Int = 1, multipleBindingPropertyB: String = "" + var simpleTypeWithComment: Bool = true // comment } diff --git a/Tests/PeripheryTests/Syntax/PropertyVisitTest.swift b/Tests/PeripheryTests/Syntax/PropertyVisitTest.swift index 58aa49cbf..fc5729c29 100644 --- a/Tests/PeripheryTests/Syntax/PropertyVisitTest.swift +++ b/Tests/PeripheryTests/Syntax/PropertyVisitTest.swift @@ -116,6 +116,12 @@ final class PropertyVisitTest: XCTestCase { XCTAssertEqual(propertyB.variableTypeLocations, [fixtureLocation(line: 21, column: 70)]) } + func testSimpleTypeWithComment() { + let result = results[fixtureLocation(line: 22)]! + XCTAssertEqual(result.variableType, "Bool") + XCTAssertEqual(result.variableTypeLocations, [fixtureLocation(line: 22, column: 32)]) + } + // MARK: - Private private var fixturePath: SourceFile {