diff --git a/.github/workflows/periphery.yml b/.github/workflows/periphery.yml new file mode 100644 index 00000000..5b2910f9 --- /dev/null +++ b/.github/workflows/periphery.yml @@ -0,0 +1,18 @@ +name: Periphery +on: + push: + branches: [master] + pull_request: +jobs: + periphery: + name: Run Periphery + runs-on: macos-latest + steps: + - uses: actions/checkout@v6 + - uses: SwiftyLab/setup-swift@latest + with: + swift-version: "6.2" + - name: Install Periphery + run: brew install peripheryapp/periphery/periphery + - name: Run Periphery + run: periphery scan diff --git a/.periphery.yml b/.periphery.yml new file mode 100644 index 00000000..85b884af --- /dev/null +++ b/.periphery.yml @@ -0,0 +1 @@ +retain_public: true diff --git a/Sources/SwiftNASR/Distribution/Distribution.swift b/Sources/SwiftNASR/Distribution/Distribution.swift index 8a46bf7d..0899a627 100644 --- a/Sources/SwiftNASR/Distribution/Distribution.swift +++ b/Sources/SwiftNASR/Distribution/Distribution.swift @@ -1,29 +1,5 @@ import Foundation -private let metatypes = - [ - (RecordType.states, State.self), - (RecordType.airports, Airport.self), - (RecordType.ARTCCFacilities, ARTCC.self), - (RecordType.reportingPoints, Fix.self), - (RecordType.weatherReportingStations, WeatherStation.self), - (RecordType.airways, Airway.self), - (RecordType.ILSes, ILS.self), - (RecordType.terminalCommFacilities, TerminalCommFacility.self), - (RecordType.departureArrivalProceduresComplete, DepartureArrivalProcedure.self), - (RecordType.preferredRoutes, PreferredRoute.self), - (RecordType.holds, Hold.self), - (RecordType.weatherReportingLocations, WeatherReportingLocation.self), - (RecordType.parachuteJumpAreas, ParachuteJumpArea.self), - (RecordType.militaryTrainingRoutes, MilitaryTrainingRoute.self), - (RecordType.codedDepartureRoutes, CodedDepartureRoute.self), - (RecordType.miscActivityAreas, MiscActivityArea.self), - (RecordType.ARTCCBoundarySegments, ARTCCBoundarySegment.self), - (RecordType.FSSCommFacilities, FSSCommFacility.self), - (RecordType.ATSAirways, ATSAirway.self), - (RecordType.locationIdentifiers, LocationIdentifier.self) - ] as [(RecordType, any Record.Type)] - /// Record types available to load from a distribution. public enum RecordType: String, Codable, Sendable { case ARTCCFacilities = "AFF" @@ -51,20 +27,6 @@ public enum RecordType: String, Codable, Sendable { /// This is a pseudo-record-type intended to represent the `STATE.txt` file. /// `states` is not a loadable record type. case states = "_ST" - - var metatype: any Record.Type { - guard let type = metatypes.first(where: { $0.0 == self })?.1 else { - preconditionFailure("Unsupported type \(self)") - } - return type - } - - static func forType(_ type: any Record.Type) -> Self { - guard let value = metatypes.first(where: { $0.1 == type })?.0 else { - preconditionFailure("Unsupported type \(type)") - } - return value - } } /// Global actor that guarantees exclusive access to the distribution file. diff --git a/Sources/SwiftNASR/Loaders/ArchiveLoader.swift b/Sources/SwiftNASR/Loaders/ArchiveLoader.swift index daf076a7..7d7157a8 100644 --- a/Sources/SwiftNASR/Loaders/ArchiveLoader.swift +++ b/Sources/SwiftNASR/Loaders/ArchiveLoader.swift @@ -12,12 +12,6 @@ public final class ArchiveLoader: Loader { /// The data format for the archive (.txt or .csv). public let format: DataFormat - private let queue = DispatchQueue( - label: "codes.tim.SwiftNASR.ArchiveLoader", - qos: .utility, - attributes: .concurrent - ) - /** Creates a loader that loads from a given location on disk. diff --git a/Sources/SwiftNASR/Models/Records/Airport/Remark.swift b/Sources/SwiftNASR/Models/Records/Airport/Remark.swift index 0bd99a20..c27ea177 100644 --- a/Sources/SwiftNASR/Models/Records/Airport/Remark.swift +++ b/Sources/SwiftNASR/Models/Records/Airport/Remark.swift @@ -13,18 +13,6 @@ public struct Remarks: Record { /// All remarks added to the record. public var remarks = [Remark]() - /// Remarks applied to a record as a whole. - var general: [String] { - var remarks = [String]() - - for remark in self.remarks { - guard case .general(let content) = remark else { break } - remarks.append(content) - } - - return remarks - } - /** Gets the remarks for a specific field. diff --git a/Sources/SwiftNASR/Parsers/CSV/CSVHeaderMap.swift b/Sources/SwiftNASR/Parsers/CSV/CSVHeaderMap.swift index 2a839b81..55533eb5 100644 --- a/Sources/SwiftNASR/Parsers/CSV/CSVHeaderMap.swift +++ b/Sources/SwiftNASR/Parsers/CSV/CSVHeaderMap.swift @@ -28,13 +28,6 @@ struct CSVHeaderMap: Sendable { // MARK: - Methods - /// Check if a column exists in this CSV. - /// - Parameter columnName: The column name to check. - /// - Returns: True if the column exists. - func contains(_ columnName: String) -> Bool { - nameToIndex[columnName] != nil - } - /// Validate that all required columns exist. /// - Parameter requiredColumns: Array of column names that must be present. /// - Throws: `CSVParserError.missingRequiredColumns` if any are missing. @@ -45,16 +38,6 @@ struct CSVHeaderMap: Sendable { } } - /// Build an index array for transformer compatibility. - /// - /// Returns -1 for columns that don't exist, allowing transformers - /// to handle missing optional columns gracefully. - /// - Parameter columnNames: The column names to map. - /// - Returns: Array of indices (-1 for missing columns). - func indices(for columnNames: [String]) -> [Int] { - columnNames.map { nameToIndex[$0] ?? -1 } - } - // MARK: - Subscripts /// Look up column index by name. diff --git a/Sources/SwiftNASR/Parsers/CSV/CSVRow.swift b/Sources/SwiftNASR/Parsers/CSV/CSVRow.swift index 8d03c986..2344943d 100644 --- a/Sources/SwiftNASR/Parsers/CSV/CSVRow.swift +++ b/Sources/SwiftNASR/Parsers/CSV/CSVRow.swift @@ -11,9 +11,6 @@ struct CSVRow: Sendable { /// The raw field values for this row. let values: [String] - /// Number of fields in this row. - var count: Int { values.count } - // MARK: - Methods /// Access a field that should exist but may be empty. diff --git a/Sources/SwiftNASR/Parsers/Parser.swift b/Sources/SwiftNASR/Parsers/Parser.swift index 8d58233a..97d05fb8 100644 --- a/Sources/SwiftNASR/Parsers/Parser.swift +++ b/Sources/SwiftNASR/Parsers/Parser.swift @@ -45,15 +45,6 @@ final class OffsetParser: Sendable { } } -extension Parser { - static func raw(_ rawValue: T.RawValue, toEnum _: T.Type) throws -> T { - guard let val = T.for(rawValue) else { - throw ParserError.unknownRecordEnumValue(rawValue) - } - return val - } -} - enum ParserError: Swift.Error, CustomStringConvertible { case badData(_ reason: String) case unknownRecordIdentifier(_ recordIdentifier: String) diff --git a/Sources/SwiftNASR/Parsers/Record Parsers/FSSParser/FSSParser.swift b/Sources/SwiftNASR/Parsers/Record Parsers/FSSParser/FSSParser.swift index 36260d1f..067f081c 100644 --- a/Sources/SwiftNASR/Parsers/Record Parsers/FSSParser/FSSParser.swift +++ b/Sources/SwiftNASR/Parsers/Record Parsers/FSSParser/FSSParser.swift @@ -1,21 +1,5 @@ import Foundation -private var dateFormatter: DateFormatter { - let df = DateFormatter() - df.dateFormat = "dd MMM yyyy" - df.locale = Locale(identifier: "en_US_POSIX") - df.timeZone = zulu - return df -} - -private var lastUpdatedDateFormatter: DateFormatter { - let df = DateFormatter() - df.dateFormat = "dd MMM yyyy" - df.locale = Locale(identifier: "en_US_POSIX") - df.timeZone = zulu - return df -} - actor FixedWidthFSSParser: FixedWidthNoRecordIDParser { static let type: RecordType = .flightServiceStations var formats = [NASRTable]() diff --git a/Sources/SwiftNASR/Parsers/Record Parsers/NavaidParser.swift b/Sources/SwiftNASR/Parsers/Record Parsers/NavaidParser.swift index 9445431a..237c1d01 100644 --- a/Sources/SwiftNASR/Parsers/Record Parsers/NavaidParser.swift +++ b/Sources/SwiftNASR/Parsers/Record Parsers/NavaidParser.swift @@ -421,8 +421,6 @@ actor FixedWidthNavaidParser: FixedWidthParser { } } -private let classDesignatorDelimiters = CharacterSet(charactersIn: "-/") - private func parseLFRLegs(_ string: String, fieldIndex: Int) throws -> [(LFRLeg.Quadrant, UInt)] { let scanner = Scanner(string: string) var legs = [(LFRLeg.Quadrant, UInt)]() diff --git a/Sources/SwiftNASR/Support/JSONZipCoder.swift b/Sources/SwiftNASR/Support/JSONZipCoder.swift index 359657df..3b35b20f 100644 --- a/Sources/SwiftNASR/Support/JSONZipCoder.swift +++ b/Sources/SwiftNASR/Support/JSONZipCoder.swift @@ -42,7 +42,6 @@ public class JSONZipDecoder: JSONDecoder, @unchecked Sendable { } enum JSONZipError: Swift.Error { - case couldntCreateArchive case couldntReadArchive case emptyArchive case noDistributionFile diff --git a/Sources/SwiftNASR/Support/String+SwiftNASR.swift b/Sources/SwiftNASR/Support/String+SwiftNASR.swift index 8594ff7b..ac8b5f5d 100644 --- a/Sources/SwiftNASR/Support/String+SwiftNASR.swift +++ b/Sources/SwiftNASR/Support/String+SwiftNASR.swift @@ -1,8 +1,6 @@ import Foundation extension String { - var nsRange: NSRange { return NSRange(location: 0, length: count) } - func partitionSlices(by length: Int) -> [Substring] { var startIndex = self.startIndex var results = [Substring]() diff --git a/Tests/SwiftNASR_E2E/ErrorCollector.swift b/Tests/SwiftNASR_E2E/ErrorCollector.swift index d4c4ecff..8437b4e7 100644 --- a/Tests/SwiftNASR_E2E/ErrorCollector.swift +++ b/Tests/SwiftNASR_E2E/ErrorCollector.swift @@ -3,10 +3,6 @@ import Foundation actor ErrorCollector { private var errors: [RecordError] = [] - var errorCount: Int { - errors.count - } - func record(_ error: Swift.Error, recordType: String) { errors.append(RecordError(recordType: recordType, error: error)) } diff --git a/Tests/SwiftNASR_E2E/ProgressTracker.swift b/Tests/SwiftNASR_E2E/ProgressTracker.swift index 4b8df4ac..a0cc5ba6 100644 --- a/Tests/SwiftNASR_E2E/ProgressTracker.swift +++ b/Tests/SwiftNASR_E2E/ProgressTracker.swift @@ -41,7 +41,7 @@ func trackProgress(progress: ProgressTracker) -> Task { } @MainActor -func renderProgressBar(progress: ProgressTracker, barWidth: Int = 80) async { +func renderProgressBar(progress: ProgressTracker) async { let fractionCompleted = await progress.fractionCompleted let currentRecordType = await progress.currentRecordType let percent = Int((fractionCompleted * 100).rounded()) diff --git a/Tests/SwiftNASR_E2E/ProgressWeights.swift b/Tests/SwiftNASR_E2E/ProgressWeights.swift index 4a87d747..46904eb1 100644 --- a/Tests/SwiftNASR_E2E/ProgressWeights.swift +++ b/Tests/SwiftNASR_E2E/ProgressWeights.swift @@ -18,13 +18,6 @@ var CSVRecordTypes: Set { Set(recordTypeRegistry.values.filter(\.availableInCSV).map(\.recordType)) } -/// Calculates the total progress weight for a given format. -func totalWeight(isCSV: Bool) -> Int64 { - let recordTypes = isCSV ? CSVRecordTypes : txtRecordTypes - let recordTotal = recordTypes.reduce(0) { $0 + weight(for: $1, isCSV: isCSV) } - return loadingWeight + recordTotal -} - /// Calculates the total progress weight for selected record types. func totalWeight(isCSV: Bool, selectedRecordTypes: Set) -> Int64 { let recordTotal = selectedRecordTypes.reduce(0) { $0 + weight(for: $1, isCSV: isCSV) } diff --git a/Tests/SwiftNASR_E2E/SwiftNASR_E2E.swift b/Tests/SwiftNASR_E2E/SwiftNASR_E2E.swift index 1b303c48..6b65529b 100644 --- a/Tests/SwiftNASR_E2E/SwiftNASR_E2E.swift +++ b/Tests/SwiftNASR_E2E/SwiftNASR_E2E.swift @@ -41,7 +41,6 @@ struct SwiftNASR_E2E: AsyncParsableCommand { } private let progress = ProgressTracker() - private var progressTask: Task? init() {} @@ -157,7 +156,7 @@ struct SwiftNASR_E2E: AsyncParsableCommand { } print("Done loading \(formatName); parsing…") - progressTask = trackProgress(progress: progress) + _ = trackProgress(progress: progress) let errorCollector = ErrorCollector() try await parseValues( nasr: nasr,