Skip to content

Commit 6d993c4

Browse files
authored
Merge pull request #15 from samzong/feat/swiftformat
feat(swiftformat): Add SwiftFormat configuration and improve code formatting
2 parents f9ff571 + 771c03f commit 6d993c4

31 files changed

Lines changed: 225 additions & 672 deletions

.swiftformat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--rules indent, linebreaks, redundantSelf
2+
--swiftversion 6.1
3+
--indent 4
4+
--exclude ConfigForge/Generated

CLI/Sources/ConfigForgeCLI/Commands/KubeCommand.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ class KubeConfigManager {
109109

110110
// Basic validation - check if required fields exist
111111
return yamlString.contains("apiVersion") &&
112-
yamlString.contains("clusters") &&
113-
yamlString.contains("contexts") &&
114-
yamlString.contains("users")
112+
yamlString.contains("clusters") &&
113+
yamlString.contains("contexts") &&
114+
yamlString.contains("users")
115115
} catch {
116116
return false
117117
}

CLI/Sources/ConfigForgeCLI/Models/SSHConfigEntry.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ struct SSHConfigEntry {
77

88
// Default initializer that generates a new UUID
99
init(host: String, directives: [(key: String, value: String)] = []) {
10-
self.id = UUID()
10+
id = UUID()
1111
self.host = host
1212
self.directives = directives
1313
}

CLI/Sources/ConfigForgeCLI/Services/CLISSHConfigFileManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class CLISSHConfigFileManager {
1616
func readConfigFile() throws -> String {
1717
if !fileManager.fileExists(atPath: sshConfigPath) {
1818
throw NSError(domain: "CLISSHConfigFileManager", code: 1,
19-
userInfo: [NSLocalizedDescriptionKey: "SSH config file does not exist at \(sshConfigPath)"])
19+
userInfo: [NSLocalizedDescriptionKey: "SSH config file does not exist at \(sshConfigPath)"])
2020
}
2121

2222
return try String(contentsOfFile: sshConfigPath, encoding: .utf8)

CLI/Sources/ConfigForgeCLI/Services/CLITerminalService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class CLITerminalService {
1818
exit(0)
1919
} catch {
2020
throw NSError(domain: "CLITerminalService", code: 1,
21-
userInfo: [NSLocalizedDescriptionKey: "Failed to connect to SSH host: \(error.localizedDescription)"])
21+
userInfo: [NSLocalizedDescriptionKey: "Failed to connect to SSH host: \(error.localizedDescription)"])
2222
}
2323
}
2424
}

CLI/Sources/ConfigForgeCLI/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ struct ConfigForgeCLI: ParsableCommand {
1616
],
1717
defaultSubcommand: SSHCommand.self
1818
)
19-
19+
2020
@Flag(name: .shortAndLong, help: "Enable verbose output")
2121
var verbose = false
22-
22+
2323
func run() throws {
2424
// 设置全局verbose标志
2525
GlobalOptions.verbose = verbose

ConfigForge/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import AppKit
1010
import SwiftUI
1111

1212
class AppDelegate: NSObject, NSApplicationDelegate {
13-
13+
1414
@MainActor
1515
func applicationDidFinishLaunching(_ notification: Notification) {
1616
let savedLanguage = UserDefaults.standard.string(forKey: "appLanguage")

ConfigForge/ConfigForgeApp.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import SwiftUI
1010
@main
1111
struct ConfigForgeApp: App {
1212
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
13-
13+
1414
var body: some Scene {
1515
WindowGroup(content: {
1616
ContentView()

ConfigForge/Models/ConfigDocument.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,21 @@ struct ConfigDocument: FileDocument, Sendable {
3939
let stringContent = String(data: data, encoding: .utf8) else {
4040
throw CocoaError(.fileReadCorruptFile)
4141
}
42-
self.content = stringContent
42+
content = stringContent
4343
if configuration.contentType == .yaml || stringContent.contains("apiVersion:") {
44-
self.contentType = .kubernetes
44+
contentType = .kubernetes
4545
} else if configuration.contentType == .text {
46-
self.contentType = .ssh
46+
contentType = .ssh
4747
}
4848
else {
49-
self.contentType = .unknown
50-
print("Warning: Could not determine config type during read.")
49+
contentType = .unknown
50+
print("Warning: Could not determine config type during read.")
5151
}
5252

5353
}
5454
init(content: String, type: ConfigContentType) {
5555
self.content = content
56-
self.contentType = type
56+
contentType = type
5757
}
5858
func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
5959
guard let data = content.data(using: .utf8) else {

ConfigForge/Models/KubeConfigFile.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ struct KubeConfigFile: Identifiable, Equatable {
5050
}
5151

5252
do {
53-
yamlContent = try String(contentsOf: url, encoding: .utf8)
53+
yamlContent = try String(contentsOf: url, encoding: .utf8)
5454
} catch {
5555
print("Warning: Could not read file content for \(url.path): \(error.localizedDescription)")
5656
}
57-
57+
5858
return KubeConfigFile(
5959
fileName: url.lastPathComponent,
6060
filePath: url,
@@ -67,17 +67,17 @@ struct KubeConfigFile: Identifiable, Equatable {
6767
}
6868

6969
mutating func updateYamlContent(_ newContent: String) {
70-
self.yamlContent = newContent
71-
self.status = .unknown
72-
self.modificationDate = Date()
70+
yamlContent = newContent
71+
status = .unknown
72+
modificationDate = Date()
7373
}
7474

7575
mutating func markAsInvalid(_ reason: String) {
76-
self.status = .invalid(reason)
76+
status = .invalid(reason)
7777
}
78-
78+
7979
static func == (lhs: KubeConfigFile, rhs: KubeConfigFile) -> Bool {
8080
return lhs.filePath == rhs.filePath &&
81-
lhs.fileType == rhs.fileType
81+
lhs.fileType == rhs.fileType
8282
}
8383
}

0 commit comments

Comments
 (0)