diff --git a/CHANGELOG.md b/CHANGELOG.md index 05e1a23c9..b63631d2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,9 +10,23 @@ ##### Bug Fixes +- None. + +## 2.21.1 (2024-09-28) + +##### Breaking + +- None. + +##### Enhancements + +- None. + +##### Bug Fixes + - Enums with the `@main` attribute are now retained. -- Unused public/exported imports are excluded from the results even if unused in the declaring file as the exported symbols may be referenced in other files, and thus removing the import would result in a build failure. - Fixed issue in Swift 6 where declarations that override external type members are incorrectly identified as unused. +- Unused public/exported imports are excluded from the results even if unused in the declaring file as the exported symbols may be referenced in other files, and thus removing the import would result in a build failure. ## 2.21.0 (2024-06-15) diff --git a/Sources/Frontend/Version.swift b/Sources/Frontend/Version.swift index 5d8e52f77..e02d6a966 100644 --- a/Sources/Frontend/Version.swift +++ b/Sources/Frontend/Version.swift @@ -1 +1 @@ -let PeripheryVersion = "3.0.0.beta4" +let PeripheryVersion = "2.21.1" diff --git a/Sources/PeripheryKit/Syntax/ImportSyntaxVisitor.swift b/Sources/PeripheryKit/Syntax/ImportSyntaxVisitor.swift new file mode 100644 index 000000000..c576faf21 --- /dev/null +++ b/Sources/PeripheryKit/Syntax/ImportSyntaxVisitor.swift @@ -0,0 +1,39 @@ +import Foundation +import SwiftSyntax + +struct ImportStatement { + let module: String + let isTestable: Bool + let isExported: Bool + let location: SourceLocation +} + +final class ImportSyntaxVisitor: PeripherySyntaxVisitor { + var importStatements: [ImportStatement] = [] + + private let sourceLocationBuilder: SourceLocationBuilder + + init(sourceLocationBuilder: SourceLocationBuilder) { + self.sourceLocationBuilder = sourceLocationBuilder + } + + func visit(_ node: ImportDeclSyntax) { + let parts = node.path.map { $0.name.text } + let module = parts.first ?? "" + let attributes = node.attributes.compactMap { + if case let .attribute(attr) = $0 { + attr.attributeName.trimmedDescription + } else { + nil + } + } + let location = sourceLocationBuilder.location(at: node.positionAfterSkippingLeadingTrivia) + let statement = ImportStatement( + module: module, + isTestable: attributes.contains("testable"), + isExported: attributes.contains("_exported") || node.modifiers.contains { $0.name.text == "public" }, + location: location + ) + importStatements.append(statement) + } +} diff --git a/Sources/SourceGraph/Mutators/ExternalOverrideRetainer.swift b/Sources/SourceGraph/Mutators/ExternalOverrideRetainer.swift index a515244a6..f85bbb9df 100644 --- a/Sources/SourceGraph/Mutators/ExternalOverrideRetainer.swift +++ b/Sources/SourceGraph/Mutators/ExternalOverrideRetainer.swift @@ -1,4 +1,3 @@ -import Configuration import Foundation import Shared @@ -10,9 +9,9 @@ final class ExternalOverrideRetainer: SourceGraphMutator { private let graph: SourceGraph private let isSwift6FixEnabled: Bool - required init(graph: SourceGraph, configuration _: Configuration, swiftVersion: SwiftVersion) { + required init(graph: SourceGraph, configuration _: Configuration) { self.graph = graph - isSwift6FixEnabled = swiftVersion.version.isVersion(greaterThanOrEqualTo: "6.0") + isSwift6FixEnabled = SwiftVersion.current.version.isVersion(greaterThanOrEqualTo: "6.0") } func mutate() {