Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use official swift-format #16

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

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")]
)
),
]
)
14 changes: 10 additions & 4 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 Expand Up @@ -53,7 +54,8 @@ public struct VOAccount {
}

public func sendResetPasswordEmail(_ options: SendResetPasswordEmailOptions) async throws {
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, any Error>) in
try await withCheckedThrowingContinuation {
(continuation: CheckedContinuation<Void, any Error>) in
var request = URLRequest(url: urlForSendPasswordEmail())
request.httpMethod = "POST"
request.setJSONBody(options, continuation: continuation)
Expand All @@ -70,7 +72,8 @@ public struct VOAccount {
}

public func resetPassword(_ options: ResetPasswordOptions) async throws {
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, any Error>) in
try await withCheckedThrowingContinuation {
(continuation: CheckedContinuation<Void, any Error>) in
var request = URLRequest(url: urlForResetPassword())
request.httpMethod = "POST"
request.setJSONBody(options, continuation: continuation)
Expand All @@ -87,7 +90,8 @@ public struct VOAccount {
}

public func confirmEmail(_ options: ConfirmEmailOptions) async throws {
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, any Error>) in
try await withCheckedThrowingContinuation {
(continuation: CheckedContinuation<Void, any Error>) in
var request = URLRequest(url: urlForConfirmEmail())
request.httpMethod = "POST"
request.setJSONBody(options, continuation: continuation)
Expand Down Expand Up @@ -174,7 +178,9 @@ public struct VOAccount {
public let minNumbers: Int
public let minSymbols: Int

public init(minLength: Int, minLowercase: Int, minUppercase: Int, minNumbers: Int, minSymbols: Int) {
public init(
minLength: Int, minLowercase: Int, minUppercase: Int, minNumbers: Int, minSymbols: Int
) {
self.minLength = minLength
self.minLowercase = minLowercase
self.minUppercase = minUppercase
Expand Down
3 changes: 2 additions & 1 deletion Sources/Common/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public struct VOErrorResponse: Decodable, Error {
case userNotAllowedToDeleteInvitation = "user_not_allowed_to_delete_invitation"
case userAlreadyMemberOfOrganization = "user_already_member_of_organization"
case invalidApiKey = "invalid_api_key"
case pathVariablesAndBodyParametersNotConsistent = "path_variables_and_body_parameters_not_consistent"
case pathVariablesAndBodyParametersNotConsistent =
"path_variables_and_body_parameters_not_consistent"

/* IdP */
case usernameUnavailable = "username_unavailable"
Expand Down
19 changes: 13 additions & 6 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,13 +31,15 @@ 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)
} catch {
if let stringData {
print("Failed to decode JSON: \(stringData), error: \(error.localizedDescription)")
print(
"Failed to decode JSON: \(stringData), error: \(error.localizedDescription)"
)
} else {
print("Failed to decode JSON with error: \(error.localizedDescription)")
}
Expand All @@ -45,9 +48,13 @@ func handleJSONResponse<T: Decodable>(
} else {
if let stringData {
// swiftlint:disable:next line_length
print("Request to URL: \(httpResponse.url!), failed with status code: \(httpResponse.statusCode), data: \(stringData)")
print(
"Request to URL: \(httpResponse.url!), failed with status code: \(httpResponse.statusCode), data: \(stringData)"
)
} else {
print("Request to URL: \(httpResponse.url!), failed with status code: \(httpResponse.statusCode)")
print(
"Request to URL: \(httpResponse.url!), failed with status code: \(httpResponse.statusCode)"
)
}
handleErrorResponse(continuation: continuation, data: data)
}
Expand All @@ -71,7 +78,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 +103,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
5 changes: 4 additions & 1 deletion Sources/Common/URLRequest+JSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
// included in the file LICENSE in the root of this repository.

import Foundation

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

extension URLRequest {
mutating func setJSONBody(_ body: Encodable, continuation: CheckedContinuation<some Any, any Error>) {
mutating func setJSONBody(
_ body: Encodable, continuation: CheckedContinuation<some Any, any Error>
) {
setValue("application/json", forHTTPHeaderField: "Content-Type")
do {
httpBody = try JSONEncoder().encode(body)
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
Loading
Loading