Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions Sources/SyntaxAnalysis/DeclarationSyntaxVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 })
{
Expand Down
2 changes: 1 addition & 1 deletion Sources/SyntaxAnalysis/ImportSyntaxVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/SyntaxAnalysis/TypeSyntaxInspector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<TypeNameSourceLocation> {
types(for: typeSyntax).mapSet {
.init(name: $0.trimmedDescription,
.init(name: $0.trimmed.description,
location: sourceLocationBuilder.location(at: $0.positionAfterSkippingLeadingTrivia))
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/SyntaxAnalysis/UnusedParameterParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 6 additions & 0 deletions Tests/PeripheryTests/Syntax/PropertyVisitTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading