From b2bf16960012a0ee1fc50284e10b954a762e56b7 Mon Sep 17 00:00:00 2001 From: Ricardo Carvalho Date: Mon, 25 Mar 2024 18:00:42 +0100 Subject: [PATCH] Fix swiftlint --- .../activityparser/ActivityParser.swift | 35 +++++++++++-------- .../activityparser/IDEActivityModel.swift | 12 ++++--- Sources/XCLogParser/lexer/Lexer.swift | 2 +- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/Sources/XCLogParser/activityparser/ActivityParser.swift b/Sources/XCLogParser/activityparser/ActivityParser.swift index aefa435..73a53ea 100644 --- a/Sources/XCLogParser/activityparser/ActivityParser.swift +++ b/Sources/XCLogParser/activityparser/ActivityParser.swift @@ -164,6 +164,7 @@ public class ActivityParser { uniqueIdentifier: try parseAsString(token: iterator.next()), localizedResultString: try parseAsString(token: iterator.next()), xcbuildSignature: try parseAsString(token: iterator.next()), + // swiftlint:disable:next line_length attachments: try parseIDEActivityLogSectionAttachments(iterator: &iterator), // swiftlint:disable:next line_length unknown: isCommandLineLog ? Int(try parseAsInt(token: iterator.next())) : 0, @@ -363,20 +364,24 @@ public class ActivityParser { } throw XCLogParserError.parseError("Unexpected className found parsing IDEActivityLogMessage \(className)") } - - private func parseLogSectionAttachment(iterator: inout IndexingIterator<[Token]>) throws -> IDEActivityLogSectionAttachment { - let classRefToken = try getClassRefToken(iterator: &iterator) - guard case Token.classNameRef(let className) = classRefToken else { - throw XCLogParserError.parseError("Unexpected token found parsing IDEActivityLogSectionAttachment \(classRefToken)") - } - if className == "IDEFoundation.\(String(describing: IDEActivityLogSectionAttachment.self))" { - return try IDEActivityLogSectionAttachment(identifier: try parseAsString(token: iterator.next()), - majorVersion: try parseAsInt(token: iterator.next()), - minorVersion: try parseAsInt(token: iterator.next()), - metrics: try parseAsJson(token: iterator.next(), type: IDEActivityLogSectionAttachment.BuildOperationTaskMetrics.self)) - } - throw XCLogParserError.parseError("Unexpected className found parsing IDEConsoleItem \(className)") + private func parseLogSectionAttachment(iterator: inout IndexingIterator<[Token]>) + throws -> IDEActivityLogSectionAttachment { + let classRefToken = try getClassRefToken(iterator: &iterator) + guard case Token.classNameRef(let className) = classRefToken else { + throw XCLogParserError.parseError("Unexpected token found parsing " + + "IDEActivityLogSectionAttachment \(classRefToken)") + } + + if className == "IDEFoundation.\(String(describing: IDEActivityLogSectionAttachment.self))" { + let jsonType = IDEActivityLogSectionAttachment.BuildOperationTaskMetrics.self + return try IDEActivityLogSectionAttachment(identifier: try parseAsString(token: iterator.next()), + majorVersion: try parseAsInt(token: iterator.next()), + minorVersion: try parseAsInt(token: iterator.next()), + metrics: try parseAsJson(token: iterator.next(), + type: jsonType)) + } + throw XCLogParserError.parseError("Unexpected className found parsing IDEConsoleItem \(className)") } private func parseLogSection(iterator: inout IndexingIterator<[Token]>) @@ -450,7 +455,7 @@ public class ActivityParser { "IDEActivityLogSection: \(listToken)") } } - + private func parseIDEActivityLogSectionAttachments(iterator: inout IndexingIterator<[Token]>) throws -> [IDEActivityLogSectionAttachment] { guard let listToken = iterator.next() else { @@ -593,7 +598,7 @@ public class ActivityParser { throw XCLogParserError.parseError("Unexpected token parsing String: \(token)") } } - + private func parseAsJson(token: Token?, type: T.Type) throws -> T? { guard let token = token else { throw XCLogParserError.parseError("Unexpected EOF parsing JSON String") diff --git a/Sources/XCLogParser/activityparser/IDEActivityModel.swift b/Sources/XCLogParser/activityparser/IDEActivityModel.swift index 669c718..adeb83f 100644 --- a/Sources/XCLogParser/activityparser/IDEActivityModel.swift +++ b/Sources/XCLogParser/activityparser/IDEActivityModel.swift @@ -653,17 +653,21 @@ public class IDEActivityLogSectionAttachment: Encodable { public let wcStartTime: UInt64 public let wcDuration: UInt64 } - + public let identifier: String public let majorVersion: UInt64 public let minorVersion: UInt64 public let metrics: BuildOperationTaskMetrics? - - public init(identifier: String, majorVersion: UInt64, minorVersion: UInt64, metrics: BuildOperationTaskMetrics?) throws { + + public init( + identifier: String, + majorVersion: UInt64, + minorVersion: UInt64, + metrics: BuildOperationTaskMetrics? + ) throws { self.identifier = identifier self.majorVersion = majorVersion self.minorVersion = minorVersion self.metrics = metrics } } - diff --git a/Sources/XCLogParser/lexer/Lexer.swift b/Sources/XCLogParser/lexer/Lexer.swift index c1cb4df..03ad44b 100644 --- a/Sources/XCLogParser/lexer/Lexer.swift +++ b/Sources/XCLogParser/lexer/Lexer.swift @@ -217,7 +217,7 @@ public final class Lexer { } return .string(content) } - + private func handleJSONTokenTypeCase(scanner: Scanner, payload: String, redacted: Bool,