Skip to content

Commit

Permalink
chore: use official swift-format (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
bouassaba authored Nov 24, 2024
1 parent fb5452f commit ae4c53d
Show file tree
Hide file tree
Showing 40 changed files with 596 additions and 504 deletions.
45 changes: 19 additions & 26 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,28 @@ on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
swiftlint:
runs-on: ubuntu-latest
container:
image: swift:5.10-noble
lint:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Set Up swiftlint
run: |
sudo apt-get update && sudo apt-get install -y unzip curl
unzip ci/swiftlint.zip -d /usr/local/bin/
chmod +x /usr/local/bin/swiftlint
- name: Lint Using swiftlint
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set Up SwiftLint
run: brew install swiftlint

- name: Lint Using SwiftLint
run: swiftlint lint --strict .

swiftformat:
runs-on: ubuntu-latest
container:
image: swift:5.10-noble
format:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Set Up swiftformat
run: |
sudo apt-get update && sudo apt-get install -y unzip curl
unzip ci/swiftformat.zip -d /usr/local/bin/
chmod +x /usr/local/bin/swiftformat
- name: Lint Using swiftformat
run: swiftformat --lint .
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set Up swift-format
run: brew install swift-format

- name: Lint Using swift-format
run: swift format lint -r .
7 changes: 7 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"version": 1,
"lineLength": 120,
"indentation": {
"spaces": 4
}
}
2 changes: 0 additions & 2 deletions .swiftformat

This file was deleted.

1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ disabled_rules:
- function_body_length
- file_length
- non_optional_string_data_conversion
- trailing_comma
excluded:
- .build
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let package = Package(
name: "VoltaserveCore",
platforms: [
.iOS(.v13),
.macOS(.v12)
.macOS(.v12),
],
products: [
.library(
Expand All @@ -24,6 +24,6 @@ let package = Package(
dependencies: ["VoltaserveCore"],
path: "Tests",
resources: [.process("Resources")]
)
),
]
)
1 change: 1 addition & 0 deletions Sources/Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// included in the file LICENSE in the root of this repository.

import Foundation

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
Expand Down
8 changes: 4 additions & 4 deletions Sources/Common/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public struct VOErrorResponse: Decodable, Error {
}

public enum Code: String, Codable, CaseIterable {
/* API */
// API
case groupNotFound = "group_not_found"
case fileNotFound = "file_not_found"
case invalidPath = "invalid_path"
Expand Down Expand Up @@ -71,7 +71,7 @@ public struct VOErrorResponse: Decodable, Error {
case invalidApiKey = "invalid_api_key"
case pathVariablesAndBodyParametersNotConsistent = "path_variables_and_body_parameters_not_consistent"

/* IdP */
// IdP
case usernameUnavailable = "username_unavailable"
case resourceNotFound = "resource_not_found"
case invalidUsernameOrPassword = "invalid_username_or_password"
Expand All @@ -84,11 +84,11 @@ public struct VOErrorResponse: Decodable, Error {
case unsupportedGrantType = "unsupported_grant_type"
case passwordValidationFailed = "password_validation_failed"

/* Common */
// Common
case internalServerError = "internal_server_error"
case requestValidationError = "request_validation_error"

/* Unexpected */
// Unexpected
case unknown

public init(rawValue: String) {
Expand Down
8 changes: 5 additions & 3 deletions Sources/Common/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// included in the file LICENSE in the root of this repository.

import Foundation

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
Expand All @@ -30,7 +31,7 @@ func handleJSONResponse<T: Decodable>(
return
}
let stringData = String(data: data, encoding: .utf8)
if (200 ... 299).contains(httpResponse.statusCode) {
if (200...299).contains(httpResponse.statusCode) {
do {
let result = try JSONDecoder().decode(T.self, from: data)
continuation.resume(returning: result)
Expand All @@ -44,6 +45,7 @@ func handleJSONResponse<T: Decodable>(
}
} else {
if let stringData {
// swift-format-ignore
// swiftlint:disable:next line_length
print("Request to URL: \(httpResponse.url!), failed with status code: \(httpResponse.statusCode), data: \(stringData)")
} else {
Expand Down Expand Up @@ -71,7 +73,7 @@ func handleDataResponse(
continuation.resume(throwing: VONoDataError())
return
}
if (200 ... 299).contains(httpResponse.statusCode) {
if (200...299).contains(httpResponse.statusCode) {
continuation.resume(returning: data)
} else {
handleErrorResponse(continuation: continuation, data: data)
Expand All @@ -96,7 +98,7 @@ func handleEmptyResponse(
continuation.resume(throwing: VONoDataError())
return
}
if (200 ... 299).contains(httpResponse.statusCode) {
if (200...299).contains(httpResponse.statusCode) {
continuation.resume()
} else {
handleErrorResponse(continuation: continuation, data: data)
Expand Down
1 change: 1 addition & 0 deletions Sources/Common/URLRequest+AuthHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// included in the file LICENSE in the root of this repository.

import Foundation

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
Expand Down
1 change: 1 addition & 0 deletions Sources/Common/URLRequest+JSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// included in the file LICENSE in the root of this repository.

import Foundation

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
Expand Down
4 changes: 2 additions & 2 deletions Sources/File+Wait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import Foundation

public extension VOFile {
func wait(_ id: String, sleepSeconds: UInt32 = 1) async throws -> Entity {
extension VOFile {
public func wait(_ id: String, sleepSeconds: UInt32 = 1) async throws -> Entity {
var file: Entity
repeat {
file = try await fetch(id)
Expand Down
31 changes: 14 additions & 17 deletions Sources/File.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// included in the file LICENSE in the root of this repository.

import Foundation

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
Expand Down Expand Up @@ -132,11 +133,12 @@ public struct VOFile {

public func fetchSegmentedThumbnail(_ id: String, page: Int, fileExtension: String) async throws -> Data {
try await withCheckedThrowingContinuation { continuation in
var request = URLRequest(url: urlForSegmentedThumbnail(
id,
page: page,
fileExtension: String(fileExtension.dropFirst())
))
var request = URLRequest(
url: urlForSegmentedThumbnail(
id,
page: page,
fileExtension: String(fileExtension.dropFirst())
))
request.httpMethod = "GET"
request.appendAuthorizationHeader(accessToken)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
Expand Down Expand Up @@ -526,7 +528,7 @@ public struct VOFile {
urlComponents.queryItems = [
.init(name: "type", value: FileType.file.rawValue),
.init(name: "workspace_id", value: options.workspaceID),
.init(name: "name", value: options.name)
.init(name: "name", value: options.name),
]
if let parentID = options.parentID {
urlComponents.queryItems?.append(.init(name: "parent_id", value: parentID))
Expand All @@ -540,7 +542,7 @@ public struct VOFile {
urlComponents.queryItems = [
.init(name: "type", value: FileType.folder.rawValue),
.init(name: "workspace_id", value: options.workspaceID),
.init(name: "name", value: options.name)
.init(name: "name", value: options.name),
]
if let parentID = options.parentID {
urlComponents.queryItems?.append(URLQueryItem(name: "parent_id", value: parentID))
Expand All @@ -550,28 +552,23 @@ public struct VOFile {
}

public func urlForOriginal(_ id: String, fileExtension: String) -> URL {
URL(string: "\(urlForID(id))/original.\(fileExtension)?" +
"access_token=\(accessToken)")!
URL(string: "\(urlForID(id))/original.\(fileExtension)?access_token=\(accessToken)")!
}

public func urlForPreview(_ id: String, fileExtension: String) -> URL {
URL(string: "\(urlForID(id))/preview.\(fileExtension)?" +
"access_token=\(accessToken)")!
URL(string: "\(urlForID(id))/preview.\(fileExtension)?access_token=\(accessToken)")!
}

public func urlForThumbnail(_ id: String, fileExtension: String) -> URL {
URL(string: "\(urlForID(id))/thumbnail.\(fileExtension)?" +
"access_token=\(accessToken)")!
URL(string: "\(urlForID(id))/thumbnail.\(fileExtension)?access_token=\(accessToken)")!
}

public func urlForSegmentedPage(_ id: String, page: Int, fileExtension: String) -> URL {
URL(string: "\(urlForID(id))/segmentation/pages/\(page).\(fileExtension)?" +
"access_token=\(accessToken)")!
URL(string: "\(urlForID(id))/segmentation/pages/\(page).\(fileExtension)?access_token=\(accessToken)")!
}

public func urlForSegmentedThumbnail(_ id: String, page: Int, fileExtension: String) -> URL {
URL(string: "\(urlForID(id))/segmentation/thumbnails/\(page).\(fileExtension)?" +
"access_token=\(accessToken)")!
URL(string: "\(urlForID(id))/segmentation/thumbnails/\(page).\(fileExtension)?access_token=\(accessToken)")!
}

public func urlForUserPermissions(_ id: String) -> URL {
Expand Down
1 change: 1 addition & 0 deletions Sources/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// included in the file LICENSE in the root of this repository.

import Foundation

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
Expand Down
1 change: 1 addition & 0 deletions Sources/Insights.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// included in the file LICENSE in the root of this repository.

import Foundation

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
Expand Down
1 change: 1 addition & 0 deletions Sources/Invitation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// included in the file LICENSE in the root of this repository.

import Foundation

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
Expand Down
22 changes: 12 additions & 10 deletions Sources/Mosaic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// included in the file LICENSE in the root of this repository.

import Foundation

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
Expand Down Expand Up @@ -44,13 +45,14 @@ public struct VOMosaic {
fileExtension: String
) async throws -> Data {
try await withCheckedThrowingContinuation { continuation in
var request = URLRequest(url: urlForTile(
id,
zoomLevel: zoomLevel,
row: row,
column: column,
fileExtension: fileExtension
))
var request = URLRequest(
url: urlForTile(
id,
zoomLevel: zoomLevel,
row: row,
column: column,
fileExtension: fileExtension
))
request.httpMethod = "GET"
request.appendAuthorizationHeader(accessToken)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
Expand Down Expand Up @@ -122,9 +124,9 @@ public struct VOMosaic {
column: Int,
fileExtension: String
) -> URL {
URL(string: "\(urlForFile(id))/zoom_level/\(zoomLevel.index)" +
"/row/\(row)/column/\(column)/extension/\(fileExtension)?" +
"access_token=\(accessToken)")!
// swift-format-ignore
// swiftlint:disable:next line_length
URL(string: "\(urlForFile(id))/zoom_level/\(zoomLevel.index)/row/\(row)/column/\(column)/extension/\(fileExtension)?access_token=\(accessToken)")!
}

// MARK: - Types
Expand Down
1 change: 1 addition & 0 deletions Sources/Organization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// included in the file LICENSE in the root of this repository.

import Foundation

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
Expand Down
1 change: 1 addition & 0 deletions Sources/Permission.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// included in the file LICENSE in the root of this repository.

import Foundation

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
Expand Down
1 change: 1 addition & 0 deletions Sources/Snapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// included in the file LICENSE in the root of this repository.

import Foundation

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
Expand Down
1 change: 1 addition & 0 deletions Sources/Storage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// included in the file LICENSE in the root of this repository.

import Foundation

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
Expand Down
6 changes: 3 additions & 3 deletions Sources/Task+Wait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import Foundation

public extension VOTask {
func wait(_ id: String, sleepSeconds: UInt32 = 1) async throws -> Entity? {
extension VOTask {
public func wait(_ id: String, sleepSeconds: UInt32 = 1) async throws -> Entity? {
var task: Entity?
repeat {
do {
Expand All @@ -30,7 +30,7 @@ public extension VOTask {
return task
}

enum RuntimeError: Error {
public enum RuntimeError: Error {
case message(String)
}
}
Loading

0 comments on commit ae4c53d

Please sign in to comment.