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 #17

Closed
wants to merge 9 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 @@ -14,35 +14,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 .
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
Loading
Loading