From d03822410d2e75d7660773b07bccdd8f7d7d9986 Mon Sep 17 00:00:00 2001 From: Ian Maia Date: Fri, 23 Feb 2024 16:47:41 +0100 Subject: [PATCH 1/3] Use the SwiftLint version found in `.swiftlint.yml` in the SPM package definition --- Package.swift | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 5845297..5a2ae7d 100644 --- a/Package.swift +++ b/Package.swift @@ -1,5 +1,6 @@ // swift-tools-version:5.5 +import Foundation import PackageDescription let package = Package( @@ -14,7 +15,7 @@ let package = Package( // See https://github.com/erikdoe/ocmock/issues/500#issuecomment-1002700625 .package(url: "https://github.com/erikdoe/ocmock", revision: "afd2c6924e8a36cb872bc475248b978f743c6050"), .package(url: "https://github.com/Quick/Quick", from: "6.0.0"), - .package(url: "https://github.com/realm/SwiftLint", from: "0.54.0") + .package(url: "https://github.com/realm/SwiftLint", .exactItem(loadSwiftLintVersion())) ], targets: [ .target( @@ -60,3 +61,25 @@ let package = Package( ), ] ) + +func loadSwiftLintVersion() -> Version { + guard let yamlString = try? String(contentsOf: URL(fileURLWithPath: #file) + .deletingLastPathComponent() + .appendingPathComponent(".swiftlint.yml")) else { + fatalError("Failed to read YAML file.") + } + + guard let versionLine = yamlString.components(separatedBy: .newlines) + .first(where: { $0.contains("swiftlint_version") }) else { + fatalError("SwiftLint version not found in YAML file.") + } + + // assumes the format `swiftlint_version: ` + guard let version = Version(versionLine.components(separatedBy: ":") + .last? + .trimmingCharacters(in: .whitespaces) ?? "") else { + fatalError("Failed to extract SwiftLint version.") + } + + return version +} From 9d06f66318998c42c9a4505f9b4f161028e3ac93 Mon Sep 17 00:00:00 2001 From: Ian Maia Date: Fri, 23 Feb 2024 18:10:16 +0100 Subject: [PATCH 2/3] Fix Package.swift spacing --- Package.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Package.swift b/Package.swift index 5a2ae7d..4b43ade 100644 --- a/Package.swift +++ b/Package.swift @@ -68,18 +68,18 @@ func loadSwiftLintVersion() -> Version { .appendingPathComponent(".swiftlint.yml")) else { fatalError("Failed to read YAML file.") } - + guard let versionLine = yamlString.components(separatedBy: .newlines) .first(where: { $0.contains("swiftlint_version") }) else { fatalError("SwiftLint version not found in YAML file.") } - + // assumes the format `swiftlint_version: ` guard let version = Version(versionLine.components(separatedBy: ":") .last? .trimmingCharacters(in: .whitespaces) ?? "") else { fatalError("Failed to extract SwiftLint version.") } - + return version } From 8b77cd81dceb967d280ef9bf1ddebf06f5e5fc6c Mon Sep 17 00:00:00 2001 From: Ian Guedes Maia Date: Mon, 26 Feb 2024 11:17:54 +0100 Subject: [PATCH 3/3] Standardise indentation Co-authored-by: Gio Lodi --- Package.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Package.swift b/Package.swift index 4b43ade..263da84 100644 --- a/Package.swift +++ b/Package.swift @@ -64,20 +64,20 @@ let package = Package( func loadSwiftLintVersion() -> Version { guard let yamlString = try? String(contentsOf: URL(fileURLWithPath: #file) - .deletingLastPathComponent() - .appendingPathComponent(".swiftlint.yml")) else { + .deletingLastPathComponent() + .appendingPathComponent(".swiftlint.yml")) else { fatalError("Failed to read YAML file.") } guard let versionLine = yamlString.components(separatedBy: .newlines) - .first(where: { $0.contains("swiftlint_version") }) else { + .first(where: { $0.contains("swiftlint_version") }) else { fatalError("SwiftLint version not found in YAML file.") } - // assumes the format `swiftlint_version: ` + // Assumes the format `swiftlint_version: ` guard let version = Version(versionLine.components(separatedBy: ":") - .last? - .trimmingCharacters(in: .whitespaces) ?? "") else { + .last? + .trimmingCharacters(in: .whitespaces) ?? "") else { fatalError("Failed to extract SwiftLint version.") }