diff --git a/.github/workflows/swift_format.yml b/.github/workflows/swift_format.yml new file mode 100644 index 0000000..ee96707 --- /dev/null +++ b/.github/workflows/swift_format.yml @@ -0,0 +1,10 @@ +name: Lint +on: pull_request + +jobs: + Lint: + runs-on: macos-latest + steps: + - uses: actions/checkout@v3 + - name: SwiftFormat + run: swiftformat --lint . --reporter github-actions-log \ No newline at end of file diff --git a/.swift-version b/.swift-version index 3659ea2..f9ce5a9 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -5.8 +5.10 diff --git a/.swiftformat b/.swiftformat new file mode 100644 index 0000000..a2b586b --- /dev/null +++ b/.swiftformat @@ -0,0 +1,37 @@ +--allman false +--binarygrouping none +--closingparen balanced +--commas inline +--conflictmarkers reject +--decimalgrouping 3,4 +--elseposition same-line +--guardelse auto +--empty void +--exponentcase lowercase +--exponentgrouping disabled +--fractiongrouping disabled +--fragment false +--hexgrouping none +--hexliteralcase uppercase +--ifdef no-indent +--importgrouping alphabetized +--indent 4 +--indentcase false +--linebreaks lf +--octalgrouping none +--operatorfunc spaced +--patternlet hoist +--nospaceoperators +--self init-only +--selfrequired +--semicolons inline +--someAny true +--stripunusedargs closure-only +--trailingclosures +--trimwhitespace always +--wraparguments preserve +--wrapcollections preserve +--wrapparameters preserve +--modifierorder public,override +--xcodeindentation enabled +--disable redundantObjc,wrapMultilineStatementBraces,genericExtensions diff --git a/Package.swift b/Package.swift index 183ccbe..912c301 100644 --- a/Package.swift +++ b/Package.swift @@ -6,14 +6,14 @@ import PackageDescription let package = Package( name: "Cachi", platforms: [ - .macOS(.v13), + .macOS(.v13) ], dependencies: [ .package(url: "https://github.com/Subito-it/CachiKit", branch: "master"), .package(url: "https://github.com/Subito-it/Bariloche", branch: "master"), .package(url: "https://github.com/tcamin/Vaux", branch: "cachi"), .package(url: "https://github.com/michaeleisel/ZippyJSON", branch: "master"), - .package(url: "https://github.com/vapor/vapor.git", from: "4.77.1"), + .package(url: "https://github.com/vapor/vapor.git", from: "4.77.1") ], targets: [ .executableTarget( @@ -23,6 +23,6 @@ let package = Package( .testTarget( name: "CachiTests", dependencies: ["Cachi"] - ), + ) ] ) diff --git a/Sources/Cachi/Server/Routes/AttachmentRoute.swift b/Sources/Cachi/Server/Routes/AttachmentRoute.swift index c2c59bf..1919cab 100644 --- a/Sources/Cachi/Server/Routes/AttachmentRoute.swift +++ b/Sources/Cachi/Server/Routes/AttachmentRoute.swift @@ -45,14 +45,13 @@ struct AttachmentRoute: Routable { } var headers = [ - ("Content-Type", contentType), + ("Content-Type", contentType) ] if let filename = queryItems.first(where: { $0.name == "filename" })?.value?.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed), let fileAttributes = try? FileManager.default.attributesOfItem(atPath: destinationPath), let bytes = fileAttributes[.size] as? Int64, - bytes > 100 * 1024 - { + bytes > 100 * 1_024 { headers.append(("Content-Disposition", value: "attachment; filename=\(filename)")) } @@ -71,7 +70,7 @@ struct AttachmentRoute: Routable { .init(name: "id", value: identifier), .init(name: "test_id", value: testSummaryIdentifier), .init(name: "filename", value: filename), - .init(name: "content_type", value: contentType), + .init(name: "content_type", value: contentType) ] components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) } diff --git a/Sources/Cachi/Server/Routes/CSSRoute.swift b/Sources/Cachi/Server/Routes/CSSRoute.swift index b9d068a..3a14343 100644 --- a/Sources/Cachi/Server/Routes/CSSRoute.swift +++ b/Sources/Cachi/Server/Routes/CSSRoute.swift @@ -15,10 +15,9 @@ struct CSSRoute: Routable { return Response(status: .notFound, body: Response.Body(stringLiteral: "Not found...")) } - let cssContent: String? - switch imageIdentifier { - case "main": cssContent = mainCSS() - default: cssContent = nil + let cssContent: String? = switch imageIdentifier { + case "main": mainCSS() + default: nil } guard cssContent != nil else { diff --git a/Sources/Cachi/Server/Routes/CoverageFileRouteHTML.swift b/Sources/Cachi/Server/Routes/CoverageFileRouteHTML.swift index 3d457ca..daa531e 100644 --- a/Sources/Cachi/Server/Routes/CoverageFileRouteHTML.swift +++ b/Sources/Cachi/Server/Routes/CoverageFileRouteHTML.swift @@ -48,7 +48,7 @@ struct CoverageFileRouteHTML: Routable { var components = URLComponents(string: path)! components.queryItems = [ .init(name: "id", value: resultIdentifier), - .init(name: "path", value: path), + .init(name: "path", value: path) ] components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) } diff --git a/Sources/Cachi/Server/Routes/CoverageRouteHTML.swift b/Sources/Cachi/Server/Routes/CoverageRouteHTML.swift index 0b2e447..99f4989 100644 --- a/Sources/Cachi/Server/Routes/CoverageRouteHTML.swift +++ b/Sources/Cachi/Server/Routes/CoverageRouteHTML.swift @@ -55,7 +55,7 @@ struct CoverageRouteHTML: Routable { var components = URLComponents(string: path)! components.queryItems = [ .init(name: "id", value: resultIdentifier), - .init(name: "back_url", value: backUrl.hexadecimalRepresentation), + .init(name: "back_url", value: backUrl.hexadecimalRepresentation) ] components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) } @@ -115,7 +115,7 @@ struct CoverageRouteHTML: Routable { var components = URLComponents(string: Self.path)! components.queryItems = [ .init(name: "id", value: result.identifier), - .init(name: "back_url", value: backUrl.hexadecimalRepresentation), + .init(name: "back_url", value: backUrl.hexadecimalRepresentation) ] components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) } @@ -143,15 +143,14 @@ private extension CoverageRouteHTML { init(hexadecimalRepresentation: String?) { if let hexadecimalRepresentation, let data = Data(hexadecimalRepresentation: hexadecimalRepresentation), - let state = try? ZippyJSONDecoder().decode(RouteState.self, from: data) - { - showFilter = state.showFilter - filterQuery = state.filterQuery - hideFilters = state.hideFilters + let state = try? ZippyJSONDecoder().decode(RouteState.self, from: data) { + self.showFilter = state.showFilter + self.filterQuery = state.filterQuery + self.hideFilters = state.hideFilters } else { - showFilter = .files - filterQuery = "" - hideFilters = false + self.showFilter = .files + self.filterQuery = "" + self.hideFilters = false } } diff --git a/Sources/Cachi/Server/Routes/ImageRoute.swift b/Sources/Cachi/Server/Routes/ImageRoute.swift index e8de064..5faf74b 100644 --- a/Sources/Cachi/Server/Routes/ImageRoute.swift +++ b/Sources/Cachi/Server/Routes/ImageRoute.swift @@ -15,20 +15,19 @@ struct ImageRoute: Routable { return Response(status: .notFound, body: Response.Body(stringLiteral: "Not found...")) } - let imageContent: StaticString? - switch imageIdentifier { - case "imageTestPass": imageContent = imageTestPass() - case "imageTestFail": imageContent = imageTestFail() - case "imageTestRetried": imageContent = imageTestRetried() - case "imageTestGray": imageContent = imageTestGray() - case "imageArrowLeft": imageContent = imageArrowLeft() - case "imageArrowRight": imageContent = imageArrowRight() - case "imageArrowDown": imageContent = imageArrowDown() - case "imageLink": imageContent = imageLink() - case "imagePlaceholder": imageContent = imagePlaceholder() - case "imageAttachment": imageContent = imageAttachment() - case "imageEmpty": imageContent = imageEmpty() - default: imageContent = nil + let imageContent: StaticString? = switch imageIdentifier { + case "imageTestPass": imageTestPass() + case "imageTestFail": imageTestFail() + case "imageTestRetried": imageTestRetried() + case "imageTestGray": imageTestGray() + case "imageArrowLeft": imageArrowLeft() + case "imageArrowRight": imageArrowRight() + case "imageArrowDown": imageArrowDown() + case "imageLink": imageLink() + case "imagePlaceholder": imagePlaceholder() + case "imageAttachment": imageAttachment() + case "imageEmpty": imageEmpty() + default: nil } if let imageContent { diff --git a/Sources/Cachi/Server/Routes/ResultRouteHTML.swift b/Sources/Cachi/Server/Routes/ResultRouteHTML.swift index c31c5c9..6add797 100644 --- a/Sources/Cachi/Server/Routes/ResultRouteHTML.swift +++ b/Sources/Cachi/Server/Routes/ResultRouteHTML.swift @@ -66,7 +66,7 @@ struct ResultRouteHTML: Routable { var components = URLComponents(string: path)! components.queryItems = [ .init(name: "id", value: resultIdentifier), - .init(name: "back_url", value: backUrl.hexadecimalRepresentation), + .init(name: "back_url", value: backUrl.hexadecimalRepresentation) ] components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) } @@ -183,16 +183,15 @@ struct ResultRouteHTML: Routable { } private func resultsTableHTML(result: ResultBundle, state: RouteState, backUrl: String) -> HTML { - var tests: [ResultBundle.Test] - switch state.showFilter { + var tests: [ResultBundle.Test] = switch state.showFilter { case .failed: - tests = result.testsFailedExcludingRetries() + result.testsFailedExcludingRetries() case .passed: - tests = result.testsPassed + result.testsPassed case .retried: - tests = result.testsFailedRetring + result.testsFailedRetring default: - tests = result.tests + result.tests } if state.showSystemFailures, state.showFilter != .retried { @@ -269,7 +268,7 @@ struct ResultRouteHTML: Routable { var components = URLComponents(string: path)! components.queryItems = [ .init(name: "id", value: result.identifier), - .init(name: "back_url", value: backUrl.hexadecimalRepresentation), + .init(name: "back_url", value: backUrl.hexadecimalRepresentation) ] components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) } @@ -301,15 +300,14 @@ private extension ResultRouteHTML { init(hexadecimalRepresentation: String?) { if let hexadecimalRepresentation, let data = Data(hexadecimalRepresentation: hexadecimalRepresentation), - let state = try? ZippyJSONDecoder().decode(RouteState.self, from: data) - { - showFilter = state.showFilter - showFailureMessage = state.showFailureMessage - showSystemFailures = state.showSystemFailures + let state = try? ZippyJSONDecoder().decode(RouteState.self, from: data) { + self.showFilter = state.showFilter + self.showFailureMessage = state.showFailureMessage + self.showSystemFailures = state.showSystemFailures } else { - showFilter = .all - showFailureMessage = false - showSystemFailures = false + self.showFilter = .all + self.showFailureMessage = false + self.showSystemFailures = false } } diff --git a/Sources/Cachi/Server/Routes/ResultsRouteHTML.swift b/Sources/Cachi/Server/Routes/ResultsRouteHTML.swift index a0b8e60..f232519 100644 --- a/Sources/Cachi/Server/Routes/ResultsRouteHTML.swift +++ b/Sources/Cachi/Server/Routes/ResultsRouteHTML.swift @@ -163,11 +163,10 @@ private extension ResultsRouteHTML { init(hexadecimalRepresentation: String?) { if let hexadecimalRepresentation, let data = Data(hexadecimalRepresentation: hexadecimalRepresentation), - let state = try? ZippyJSONDecoder().decode(RouteState.self, from: data) - { - showSystemFailures = state.showSystemFailures + let state = try? ZippyJSONDecoder().decode(RouteState.self, from: data) { + self.showSystemFailures = state.showSystemFailures } else { - showSystemFailures = false + self.showSystemFailures = false } } diff --git a/Sources/Cachi/Server/Routes/ResultsStatRouteHTML.swift b/Sources/Cachi/Server/Routes/ResultsStatRouteHTML.swift index 48d8ccb..d1629f8 100644 --- a/Sources/Cachi/Server/Routes/ResultsStatRouteHTML.swift +++ b/Sources/Cachi/Server/Routes/ResultsStatRouteHTML.swift @@ -69,7 +69,7 @@ struct ResultsStatRouteHTML: Routable { static func urlString(backUrl: String) -> String { var components = URLComponents(string: path)! components.queryItems = [ - .init(name: "back_url", value: backUrl.hexadecimalRepresentation), + .init(name: "back_url", value: backUrl.hexadecimalRepresentation) ] components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) } @@ -172,7 +172,7 @@ struct ResultsStatRouteHTML: Routable { .init(name: "target", value: selectedTarget), .init(name: "device", value: selectedDevice), .init(name: "back_url", value: backUrl.hexadecimalRepresentation), - .init(name: type(of: statType).queryName, value: statType.rawValue), + .init(name: type(of: statType).queryName, value: statType.rawValue) ] components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) } diff --git a/Sources/Cachi/Server/Routes/ScriptRoute.swift b/Sources/Cachi/Server/Routes/ScriptRoute.swift index 8e2ce34..8bd2ff9 100644 --- a/Sources/Cachi/Server/Routes/ScriptRoute.swift +++ b/Sources/Cachi/Server/Routes/ScriptRoute.swift @@ -23,16 +23,14 @@ struct ScriptRoute: Routable { let resultBundles = State.shared.resultBundles if let resultIdentifier = queryItems.first(where: { $0.name == "id" })?.value, - let resultBundle = resultBundles.first(where: { $0.identifier == resultIdentifier }) - { + let resultBundle = resultBundles.first(where: { $0.identifier == resultIdentifier }) { scriptContent = scriptFilesCoverage(resultBundle: resultBundle) } case "coverage-folders": let resultBundles = State.shared.resultBundles if let resultIdentifier = queryItems.first(where: { $0.name == "id" })?.value, - let resultBundle = resultBundles.first(where: { $0.identifier == resultIdentifier }) - { + let resultBundle = resultBundles.first(where: { $0.identifier == resultIdentifier }) { scriptContent = scriptFoldersCoverage(resultBundle: resultBundle) } case "result-stat": @@ -68,7 +66,7 @@ struct ScriptRoute: Routable { var components = URLComponents(string: path)! components.queryItems = [ .init(name: "id", value: resultIdentifier), - .init(name: "type", value: type), + .init(name: "type", value: type) ] components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) } diff --git a/Sources/Cachi/Server/Routes/TestRoute.swift b/Sources/Cachi/Server/Routes/TestRoute.swift index 7e9a2a2..f86f475 100644 --- a/Sources/Cachi/Server/Routes/TestRoute.swift +++ b/Sources/Cachi/Server/Routes/TestRoute.swift @@ -19,8 +19,7 @@ struct TestRoute: Routable { defer { os_log("Result bundle with id '%@' fetched in %fms", log: .default, type: .info, testSummaryIdentifier, benchmarkStop(benchId)) } if let summaries = State.shared.testActionActivitySummaries(summaryIdentifier: testSummaryIdentifier), - let bodyData = try? JSONEncoder().encode(summaries) - { + let bodyData = try? JSONEncoder().encode(summaries) { return Response(body: Response.Body(data: bodyData)) } else { return Response(status: .internalServerError, body: Response.Body(stringLiteral: "Ouch...")) diff --git a/Sources/Cachi/Server/Routes/TestRouteHTML.swift b/Sources/Cachi/Server/Routes/TestRouteHTML.swift index 0145976..dafb066 100644 --- a/Sources/Cachi/Server/Routes/TestRouteHTML.swift +++ b/Sources/Cachi/Server/Routes/TestRouteHTML.swift @@ -72,7 +72,7 @@ struct TestRouteHTML: Routable { components.queryItems = [ .init(name: "id", value: testSummaryIdentifier), .init(name: "source", value: source), - .init(name: "back_url", value: backUrl.hexadecimalRepresentation), + .init(name: "back_url", value: backUrl.hexadecimalRepresentation) ] components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) } @@ -85,12 +85,11 @@ struct TestRouteHTML: Routable { let testSubtitle = test.groupName let testDuration = hoursMinutesSeconds(in: test.duration) - let testDetail: String - switch test.status { + let testDetail = switch test.status { case .success: - testDetail = "Passed in \(testDuration)" + "Passed in \(testDuration)" case .failure: - testDetail = "Failed in \(testDuration)" + "Failed in \(testDuration)" } let testDevice = "\(test.deviceModel) (\(test.deviceOs))" @@ -216,7 +215,7 @@ struct TestRouteHTML: Routable { .class(rowData.hasChildren ? "bold" : "") .style([ StyleAttribute(key: "white-space", value: "pre-line"), - StyleAttribute(key: "margin-bottom", value: "15px"), + StyleAttribute(key: "margin-bottom", value: "15px") ]) } else { div { rowData.title } @@ -258,20 +257,18 @@ struct TestRouteHTML: Routable { tableData { if let testSummaryIdentifier = test.summaryIdentifier { if let videoCaptureAttachment = videoCapture?.attachment { - return - video { - source(mediaURL: VideoCaptureRoute.urlString(identifier: videoCaptureAttachment.identifier, resultIdentifier: result.identifier, testSummaryIdentifier: testSummaryIdentifier, filename: videoCaptureAttachment.filename, contentType: videoCaptureAttachment.contentType)) - }.id("screen-capture") + video { + source(mediaURL: VideoCaptureRoute.urlString(identifier: videoCaptureAttachment.identifier, resultIdentifier: result.identifier, testSummaryIdentifier: testSummaryIdentifier, filename: videoCaptureAttachment.filename, contentType: videoCaptureAttachment.contentType)) + }.id("screen-capture") } else if let attachment = rowsData.compactMap(\.attachment).first(where: { $0.captureMedia.available }) { - return - div { - image(url: AttachmentRoute.urlString(identifier: attachment.identifier, resultIdentifier: result.identifier, testSummaryIdentifier: testSummaryIdentifier, filename: attachment.filename, contentType: attachment.contentType)).id("screen-capture") - } + div { + image(url: AttachmentRoute.urlString(identifier: attachment.identifier, resultIdentifier: result.identifier, testSummaryIdentifier: testSummaryIdentifier, filename: attachment.filename, contentType: attachment.contentType)).id("screen-capture") + } } else { - return image(url: ImageRoute.emptyImageUrl()) + image(url: ImageRoute.emptyImageUrl()) } } else { - return "" + "" } }.id("capture-column") } @@ -283,7 +280,7 @@ struct TestRouteHTML: Routable { components.queryItems = [ .init(name: "id", value: test.summaryIdentifier), .init(name: "source", value: source), - .init(name: "back_url", value: backUrl.hexadecimalRepresentation), + .init(name: "back_url", value: backUrl.hexadecimalRepresentation) ] components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) } diff --git a/Sources/Cachi/Server/Routes/TestSessionLogsRouteHTML.swift b/Sources/Cachi/Server/Routes/TestSessionLogsRouteHTML.swift index 7ef9a7a..6b0f290 100644 --- a/Sources/Cachi/Server/Routes/TestSessionLogsRouteHTML.swift +++ b/Sources/Cachi/Server/Routes/TestSessionLogsRouteHTML.swift @@ -82,7 +82,7 @@ struct TestSessionLogsRouteHTML: Routable { components.queryItems = [ .init(name: "id", value: testSummaryIdentifier), .init(name: "type", value: type), - .init(name: "back_url", value: backUrl.hexadecimalRepresentation), + .init(name: "back_url", value: backUrl.hexadecimalRepresentation) ] components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) } @@ -95,12 +95,11 @@ struct TestSessionLogsRouteHTML: Routable { let testSubtitle = test.groupName let testDuration = hoursMinutesSeconds(in: test.duration) - let testDetail: String - switch test.status { + let testDetail = switch test.status { case .success: - testDetail = "Passed in \(testDuration)" + "Passed in \(testDuration)" case .failure: - testDetail = "Failed in \(testDuration)" + "Failed in \(testDuration)" } let testDevice = "\(test.deviceModel) (\(test.deviceOs))" diff --git a/Sources/Cachi/Server/Routes/TestStatRouteHTML.swift b/Sources/Cachi/Server/Routes/TestStatRouteHTML.swift index b14be55..4ea2bef 100644 --- a/Sources/Cachi/Server/Routes/TestStatRouteHTML.swift +++ b/Sources/Cachi/Server/Routes/TestStatRouteHTML.swift @@ -125,7 +125,7 @@ struct TestStatRouteHTML: Routable { components.queryItems = [ .init(name: "id", value: testSummaryIdentifier), .init(name: "source", value: source), - .init(name: "back_url", value: backUrl.hexadecimalRepresentation), + .init(name: "back_url", value: backUrl.hexadecimalRepresentation) ] components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) } diff --git a/Sources/Cachi/Server/Routes/VideoCaptureRoute.swift b/Sources/Cachi/Server/Routes/VideoCaptureRoute.swift index 50f6131..7c085c2 100644 --- a/Sources/Cachi/Server/Routes/VideoCaptureRoute.swift +++ b/Sources/Cachi/Server/Routes/VideoCaptureRoute.swift @@ -59,7 +59,7 @@ struct VideoCaptureRoute: Routable { var headers = [ ("Content-Type", contentType), - ("Accept-Ranges", "bytes"), + ("Accept-Ranges", "bytes") ] if let filename = queryItems.first(where: { $0.name == "filename" })?.value?.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) { headers.append(("Content-Disposition", value: "attachment; filename=\(filename)")) @@ -80,7 +80,7 @@ struct VideoCaptureRoute: Routable { .init(name: "id", value: identifier), .init(name: "test_id", value: testSummaryIdentifier), .init(name: "filename", value: filename), - .init(name: "content_type", value: contentType), + .init(name: "content_type", value: contentType) ] components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) } @@ -139,9 +139,9 @@ private extension VideoCaptureRoute { step.title = aggregatedSteps.enumerated().map { index, step in switch index { case 0: - return step.title + step.title default: - return String(repeating: " ", count: index) + "· \(step.title)" + String(repeating: " ", count: index) + "· \(step.title)" } }.joined(separator: "\n") @@ -160,7 +160,7 @@ private extension VideoCaptureRoute { "::cue {", " font-size: 80%", "}", - "", + "" ] let addStep: (String, Double, Double) -> Void = { title, startTime, stopTime in diff --git a/Sources/Cachi/Server/Routes/XcResultDownloadRoute.swift b/Sources/Cachi/Server/Routes/XcResultDownloadRoute.swift index 6ba2458..4b4e880 100644 --- a/Sources/Cachi/Server/Routes/XcResultDownloadRoute.swift +++ b/Sources/Cachi/Server/Routes/XcResultDownloadRoute.swift @@ -40,7 +40,7 @@ struct XcResultDownloadRoute: Routable { let headers = [ ("Content-Type", "application/zip"), ("Accept-Ranges", "bytes"), - ("Content-Disposition", value: "attachment; filename=\(filename)"), + ("Content-Disposition", value: "attachment; filename=\(filename)") ] let response = req.fileio.streamFile(at: destinationUrl.path(percentEncoded: false)) @@ -54,7 +54,7 @@ struct XcResultDownloadRoute: Routable { static func urlString(testSummaryIdentifier: String?) -> String { var components = URLComponents(string: path)! components.queryItems = [ - .init(name: "id", value: testSummaryIdentifier), + .init(name: "id", value: testSummaryIdentifier) ] components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) } @@ -99,8 +99,7 @@ public extension URL { // for the duration of the block, so it needs to be copied out coord.coordinate(readingItemAt: srcDir, options: NSFileCoordinator.ReadingOptions.forUploading, - error: &readError) - { + error: &readError) { (zippedURL: URL) in readSucceeded = true // assert: read succeeded diff --git a/Sources/Cachi/Server/Server.swift b/Sources/Cachi/Server/Server.swift index 4dc025d..abe8f48 100644 --- a/Sources/Cachi/Server/Server.swift +++ b/Sources/Cachi/Server/Server.swift @@ -36,7 +36,7 @@ struct Server { TestStatRouteHTML(baseUrl: baseUrl, depth: parseDepth), VersionRoute(), VideoCaptureRoute(), - XcResultDownloadRoute(), + XcResultDownloadRoute() ] routes.append(HelpRoute(routes: routes)) diff --git a/Sources/Cachi/State.swift b/Sources/Cachi/State.swift index a225d47..14db690 100644 --- a/Sources/Cachi/State.swift +++ b/Sources/Cachi/State.swift @@ -50,8 +50,8 @@ class State { private let operationQueue = OperationQueue() init() { - _resultBundles = [] - _state = .ready + self._resultBundles = [] + self._state = .ready } func reset() { diff --git a/Sources/Cachi/StreamReader.swift b/Sources/Cachi/StreamReader.swift index ffed71f..02c699a 100644 --- a/Sources/Cachi/StreamReader.swift +++ b/Sources/Cachi/StreamReader.swift @@ -9,13 +9,13 @@ class StreamReader { private let delimPattern: Data private var isAtEOF: Bool = false - init?(url: URL, delimeter: String = "\n", encoding: String.Encoding = .utf8, chunkSize: Int = 4096) { + init?(url: URL, delimeter: String = "\n", encoding: String.Encoding = .utf8, chunkSize: Int = 4_096) { guard let fileHandle = try? FileHandle(forReadingFrom: url) else { return nil } self.fileHandle = fileHandle self.chunkSize = chunkSize self.encoding = encoding - buffer = Data(capacity: chunkSize) - delimPattern = delimeter.data(using: .utf8)! + self.buffer = Data(capacity: chunkSize) + self.delimPattern = delimeter.data(using: .utf8)! } deinit { diff --git a/Sources/Cachi/Utils/Benchmark.swift b/Sources/Cachi/Utils/Benchmark.swift index 9f2b3d3..5673868 100644 --- a/Sources/Cachi/Utils/Benchmark.swift +++ b/Sources/Cachi/Utils/Benchmark.swift @@ -15,5 +15,5 @@ func benchmarkStop(_ uuid: String) -> TimeInterval { benchmark[uuid] = nil return start } - return (CFAbsoluteTimeGetCurrent() - start) * 1000 + return (CFAbsoluteTimeGetCurrent() - start) * 1_000 } diff --git a/Sources/Cachi/Utils/ResultBundleTestStatus+Extension.swift b/Sources/Cachi/Utils/ResultBundleTestStatus+Extension.swift index 9c409e3..2b217da 100644 --- a/Sources/Cachi/Utils/ResultBundleTestStatus+Extension.swift +++ b/Sources/Cachi/Utils/ResultBundleTestStatus+Extension.swift @@ -1,9 +1,9 @@ extension ResultBundle { func htmlTitle() -> String { if let branchName = userInfo?.branchName, let commitHash = userInfo?.commitHash { - return "\(branchName) - \(commitHash)" + "\(branchName) - \(commitHash)" } else { - return identifier + identifier } } @@ -67,17 +67,17 @@ extension ResultBundle { func htmlStatusTitle() -> String { if testsUniquelyFailed.count > 0 { - return "Failed" + "Failed" } else { - return "Passed" + "Passed" } } func htmlTextColor() -> String { if testsUniquelyFailed.count > 0 { - return "color-error" + "color-error" } else { - return "color-text" + "color-text" } } } diff --git a/Tests/CachiTests/CachiBrowserTests.swift b/Tests/CachiTests/CachiBrowserTests.swift index 8471d15..68c05e1 100644 --- a/Tests/CachiTests/CachiBrowserTests.swift +++ b/Tests/CachiTests/CachiBrowserTests.swift @@ -32,16 +32,16 @@ final class CachiBrowserTests: XCTestCase { /// Returns path to the built products directory. var productsDirectory: URL { #if os(macOS) - for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") { - return bundle.bundleURL.deletingLastPathComponent() - } - fatalError("couldn't find the products directory") + for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") { + return bundle.bundleURL.deletingLastPathComponent() + } + fatalError("couldn't find the products directory") #else - return Bundle.main.bundleURL + return Bundle.main.bundleURL #endif } static var allTests = [ - ("testExample", testExample), + ("testExample", testExample) ] } diff --git a/Tests/CachiTests/XCTestManifests.swift b/Tests/CachiTests/XCTestManifests.swift index 2ea1696..7acce31 100644 --- a/Tests/CachiTests/XCTestManifests.swift +++ b/Tests/CachiTests/XCTestManifests.swift @@ -1,9 +1,9 @@ import XCTest #if !canImport(ObjectiveC) - public func allTests() -> [XCTestCaseEntry] { - [ - testCase(CachiBrowserTests.allTests), - ] - } +public func allTests() -> [XCTestCaseEntry] { + [ + testCase(CachiBrowserTests.allTests) + ] +} #endif