Skip to content

Commit

Permalink
chore: use official swift-format
Browse files Browse the repository at this point in the history
  • Loading branch information
bouassaba committed Nov 24, 2024
1 parent 83be484 commit 996580c
Show file tree
Hide file tree
Showing 87 changed files with 690 additions and 477 deletions.
13 changes: 4 additions & 9 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ on:
- main

jobs:
swiftlint:
lint:
runs-on: ubuntu-latest
container:
image: swift:5.10-noble
Expand All @@ -33,16 +33,11 @@ jobs:
- name: Lint Using swiftlint
run: swiftlint lint --strict .

swiftformat:
format:
runs-on: ubuntu-latest
container:
image: swift:5.10-noble
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: Lint Using swift-format
run: swift format lint -r .
6 changes: 6 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": 1,
"indentation": {
"spaces": 4
}
}
2 changes: 0 additions & 2 deletions .swiftformat

This file was deleted.

16 changes: 11 additions & 5 deletions Sources/Helpers/Color+Hex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ extension Color {
let hex = hex.trimmingCharacters(in: .alphanumerics.inverted)
var int = UInt64()
Scanner(string: hex).scanHexInt64(&int)
let red, green, blue: Double
let red: Double
let green: Double
let blue: Double
switch hex.count {
case 6: // RGB (24-bit)
(red, green, blue) = (Double((int >> 16) & 0xFF), Double((int >> 8) & 0xFF), Double(int & 0xFF))
case 8: // ARGB (32-bit)
(red, green, blue) = (Double((int >> 16) & 0xFF), Double((int >> 8) & 0xFF), Double(int & 0xFF))
case 6: // RGB (24-bit)
(red, green, blue) = (
Double((int >> 16) & 0xFF), Double((int >> 8) & 0xFF), Double(int & 0xFF)
)
case 8: // ARGB (32-bit)
(red, green, blue) = (
Double((int >> 16) & 0xFF), Double((int >> 8) & 0xFF), Double(int & 0xFF)
)
default:
(red, green, blue) = (0, 0, 0)
}
Expand Down
14 changes: 10 additions & 4 deletions Sources/Helpers/Fake.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,22 @@ enum Fake {
moreInfo: "http://voltaserve.com"
)

static func serverCall<T>(_ code: @escaping (CheckedContinuation<T, any Error>) -> Void) async throws -> T {
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<T, any Error>) in
static func serverCall<T>(_ code: @escaping (CheckedContinuation<T, any Error>) -> Void)
async throws -> T
{
try await withCheckedThrowingContinuation {
(continuation: CheckedContinuation<T, any Error>) in
DispatchQueue.main.asyncAfter(deadline: .now() + 2.5) {
code(continuation)
}
}
}

static func serverCall(_ code: @escaping (CheckedContinuation<Void, any Error>) -> Void) async throws {
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, any Error>) in
static func serverCall(_ code: @escaping (CheckedContinuation<Void, any Error>) -> Void)
async throws
{
try await withCheckedThrowingContinuation {
(continuation: CheckedContinuation<Void, any Error>) in
DispatchQueue.main.asyncAfter(deadline: .now() + 2.5) {
code(continuation)
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/Helpers/FileExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extension String {
func isImage() -> Bool {
let imageExtensions = [
".xpm", ".png", ".jpg", ".jpeg", ".jp2", ".gif", ".webp",
".tiff", ".tif", ".bmp", ".ico", ".heif", ".xcf", ".svg"
".tiff", ".tif", ".bmp", ".ico", ".heif", ".xcf", ".svg",
]
return imageExtensions.contains(self)
}
Expand Down Expand Up @@ -72,15 +72,15 @@ extension String {
func isVideo() -> Bool {
let videoExtensions = [
".ogv", ".ogg", ".mpeg", ".mov", ".mqv", ".mp4", ".webm",
".3gp", ".3g2", ".avi", ".flv", ".mkv", ".asf", ".m4v"
".3gp", ".3g2", ".avi", ".flv", ".mkv", ".asf", ".m4v",
]
return videoExtensions.contains(self)
}

func isAudio() -> Bool {
let audioExtensions = [
".oga", ".mp3", ".flac", ".midi", ".ape", ".mpc", ".amr",
".wav", ".aiff", ".au", ".aac", "voc", ".m4a", ".qcp"
".wav", ".aiff", ".au", ".aac", "voc", ".m4a", ".qcp",
]
return audioExtensions.contains(self)
}
Expand All @@ -98,7 +98,7 @@ extension String {
let codeExtensions = [
".html", ".js", "jsx", ".ts", ".tsx", ".css", ".sass",
".scss", ".go", ".py", ".rb", ".java", ".c", ".h", ".cpp",
".hpp", ".json", ".yml", ".yaml", ".toml", ".md"
".hpp", ".json", ".yml", ".yaml", ".toml", ".md",
]
return codeExtensions.contains(self)
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/Infrastructure/KeychainManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class KeychainManager {
let query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrAccount as String: key,
kSecValueData as String: data
kSecValueData as String: data,
]

SecItemAdd(query as CFDictionary, nil)
Expand All @@ -32,7 +32,7 @@ class KeychainManager {
kSecClass as String: kSecClassGenericPassword,
kSecAttrAccount as String: key,
kSecReturnData as String: true,
kSecMatchLimit as String: kSecMatchLimitOne
kSecMatchLimit as String: kSecMatchLimitOne,
]

var item: CFTypeRef?
Expand All @@ -45,7 +45,7 @@ class KeychainManager {
func delete(_ key: String) {
let query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrAccount as String: key
kSecAttrAccount as String: key,
]

SecItemDelete(query as CFDictionary)
Expand Down
3 changes: 2 additions & 1 deletion Sources/Infrastructure/TokenStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import VoltaserveCore
extension KeychainManager {
func saveToken(_ token: VOToken.Value, forKey key: String) {
if let data = try? JSONEncoder().encode(token),
let serialized = String(data: data, encoding: .utf8) {
let serialized = String(data: data, encoding: .utf8)
{
saveString(serialized, for: key)
}
}
Expand Down
24 changes: 15 additions & 9 deletions Sources/Library/Modifiers/Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,34 @@ extension View {
modifier(VOButton(color: .blue500, width: width, isDisabled: isDisabled))
}

func voSecondaryButton(colorScheme: ColorScheme, width: CGFloat? = nil, isDisabled: Bool = false) -> some View {
modifier(VOButton(
color: colorScheme == .dark ? .gray700 : .gray200,
width: width,
isDisabled: isDisabled
))
func voSecondaryButton(
colorScheme: ColorScheme, width: CGFloat? = nil, isDisabled: Bool = false
) -> some View {
modifier(
VOButton(
color: colorScheme == .dark ? .gray700 : .gray200,
width: width,
isDisabled: isDisabled
))
}
}

#Preview {
@Previewable @Environment(\.colorScheme) var colorScheme

VStack {
Button {} label: {
Button {
} label: {
VOButtonLabel("Lorem Ipsum")
}
.voPrimaryButton(width: 60)
Button {} label: {
Button {
} label: {
VOButtonLabel("Lorem Ipsum", isLoading: true)
}
.voSecondaryButton(colorScheme: colorScheme, width: 200)
Button {} label: {
Button {
} label: {
VOButtonLabel("Dolor Sit Amet")
}
.voButton(color: .red300)
Expand Down
4 changes: 3 additions & 1 deletion Sources/Library/Modifiers/ErrorAlert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ struct VOErrorAlert: ViewModifier {
}

extension View {
func voErrorAlert(isPresented: Binding<Bool>, title: String? = nil, message: String? = nil) -> some View {
func voErrorAlert(isPresented: Binding<Bool>, title: String? = nil, message: String? = nil)
-> some View
{
modifier(VOErrorAlert(isPresented: isPresented, title: title, message: message))
}
}
3 changes: 2 additions & 1 deletion Sources/Library/Modifiers/ErrorSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ extension View {
.voErrorSheet(
isPresented: $showLongError,
// swiftlint:disable:next line_length
message: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
message:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
)
}
3 changes: 2 additions & 1 deletion Sources/Library/Modifiers/FormHintLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ extension View {
}

#Preview {
Button {} label: {
Button {
} label: {
Text("Lorem ipsum")
.voFormHintLabel()
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/Library/Modifiers/WarningSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ extension View {
.voWarningSheet(
isPresented: $showLongWarning,
// swiftlint:disable:next line_length
message: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
message:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
)
}
2 changes: 1 addition & 1 deletion Sources/Library/Views/Avatar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct VOAvatar: View {
}

var color = ""
for index in 0 ..< 3 {
for index in 0..<3 {
let value = (hash >> (index * 8)) & 0xFF
color += String(format: "%02x", value)
}
Expand Down
5 changes: 4 additions & 1 deletion Sources/Library/Views/ButtonLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ struct VOButtonLabel: View {
private let isLoading: Bool
private let progressViewTint: Color

init(_ text: String, systemImage: String? = nil, isLoading: Bool = false, progressViewTint: Color = .primary) {
init(
_ text: String, systemImage: String? = nil, isLoading: Bool = false,
progressViewTint: Color = .primary
) {
self.text = text
self.systemImage = systemImage
self.isLoading = isLoading
Expand Down
3 changes: 2 additions & 1 deletion Sources/Library/Views/ColorBadge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ struct VOColorBadge: View {

var body: some View {
if style == .fill {
} else if style == .outline {}
} else if style == .outline {
}
Text(text)
.font(.footnote)
.padding(.horizontal)
Expand Down
4 changes: 3 additions & 1 deletion Sources/Library/Views/ErrorMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ struct VOErrorMessage: View {
VStack(spacing: VOMetrics.spacing2Xl) {
VOErrorMessage("Lorem ipsum dolor sit amet.")
// swiftlint:disable:next line_length
VOErrorMessage("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
VOErrorMessage(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
)
}
.padding()
}
3 changes: 2 additions & 1 deletion Sources/Library/Views/FormButtonLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ struct VOFormButtonLabel: View {

#Preview {
Form {
Button {} label: {
Button {
} label: {
VOFormButtonLabel("Lorem Ipsum", isLoading: true)
}
.disabled(true)
Expand Down
4 changes: 3 additions & 1 deletion Sources/Library/Views/WarningMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ struct VOWarningMessage: View {
VStack(spacing: VOMetrics.spacing2Xl) {
VOWarningMessage("Lorem ipsum dolor sit amet.")
// swiftlint:disable:next line_length
VOWarningMessage("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
VOWarningMessage(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
)
}
.padding()
}
3 changes: 2 additions & 1 deletion Sources/Screens/Account/AccountEditEmail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ struct AccountEditEmail: View, LoadStateProvider, FormValidatable, ErrorPresenta

func isValid() -> Bool {
if let identityUser = accountStore.identityUser {
return !normalizedValue.isEmpty && normalizedValue != (identityUser.pendingEmail ?? identityUser.email)
return !normalizedValue.isEmpty
&& normalizedValue != (identityUser.pendingEmail ?? identityUser.email)
}
return false
}
Expand Down
31 changes: 18 additions & 13 deletions Sources/Screens/Account/AccountOverview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import SwiftUI
import VoltaserveCore

struct AccountOverview: View, ViewDataProvider, LoadStateProvider, TimerLifecycle, TokenDistributing {
struct AccountOverview: View, ViewDataProvider, LoadStateProvider, TimerLifecycle, TokenDistributing
{
@EnvironmentObject private var tokenStore: TokenStore
@StateObject private var accountStore = AccountStore()
@StateObject private var invitationStore = InvitationStore()
Expand Down Expand Up @@ -42,23 +43,29 @@ struct AccountOverview: View, ViewDataProvider, LoadStateProvider, TimerLifecycl
VStack(alignment: .leading) {
if let storageUsage = accountStore.storageUsage {
// swiftlint:disable:next line_length
Text("\(storageUsage.bytes.prettyBytes()) of \(storageUsage.maxBytes.prettyBytes()) used")
Text(
"\(storageUsage.bytes.prettyBytes()) of \(storageUsage.maxBytes.prettyBytes()) used"
)
ProgressView(value: Double(storageUsage.percentage) / 100.0)
}
}
}
Section {
NavigationLink(destination: AccountSettings(accountStore: accountStore) {
dismiss()
performSignOut()
}) {
NavigationLink(
destination: AccountSettings(accountStore: accountStore) {
dismiss()
performSignOut()
}
) {
Label("Settings", systemImage: "gear")
}
NavigationLink(destination: InvitationIncomingList()) {
HStack {
Label("Invitations", systemImage: "paperplane")
Spacer()
if let incomingCount = invitationStore.incomingCount, incomingCount > 0 {
if let incomingCount = invitationStore.incomingCount,
incomingCount > 0
{
VONumberBadge(incomingCount)
}
}
Expand Down Expand Up @@ -110,15 +117,13 @@ struct AccountOverview: View, ViewDataProvider, LoadStateProvider, TimerLifecycl
// MARK: - LoadStateProvider

var isLoading: Bool {
accountStore.identityUserIsLoading ||
accountStore.storageUsageIsLoading ||
invitationStore.incomingCountIsLoading
accountStore.identityUserIsLoading || accountStore.storageUsageIsLoading
|| invitationStore.incomingCountIsLoading
}

var error: String? {
accountStore.identityUserError ??
accountStore.storageUsageError ??
invitationStore.incomingCountError
accountStore.identityUserError ?? accountStore.storageUsageError
?? invitationStore.incomingCountError
}

// MARK: - ViewDataProvider
Expand Down
Loading

0 comments on commit 996580c

Please sign in to comment.