diff --git a/.swiftformat b/.swiftformat index 69f1ff7..ce62d1c 100644 --- a/.swiftformat +++ b/.swiftformat @@ -5,13 +5,14 @@ # https://github.com/nicklockwood/SwiftFormat#config-file # ---exclude Carthage/,docs/ +--exclude docs/ # Disabled rules --disable blankLinesAroundMark --disable consecutiveSpaces --disable hoistPatternLet --disable indent +--disable trailingCommas # Enabled rules (disabled by default) --enable trailingClosures diff --git a/.swiftlint.yml b/.swiftlint.yml index 98d7c39..852c115 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -4,13 +4,12 @@ # # https://github.com/realm/SwiftLint#configuration # ---- + +disabled_rules: +- trailing_comma + excluded: -- Carthage - docs opening_brace: allow_multiline_func: true - -trailing_comma: - mandatory_comma: true diff --git a/Brewfile b/Brewfile index 4bea1f5..e8c9cec 100644 --- a/Brewfile +++ b/Brewfile @@ -1,6 +1,5 @@ brew "markdownlint-cli" brew "shfmt" -brew "swift-format" brew "swiftformat" # Already installed on GitHub Actions runner. diff --git a/Brewfile.lock.json b/Brewfile.lock.json index 95d1140..dc1f79c 100644 --- a/Brewfile.lock.json +++ b/Brewfile.lock.json @@ -59,55 +59,31 @@ } } }, - "swift-format": { - "version": "0.50300.0", - "bottle": { - "rebuild": 0, - "root_url": "https://ghcr.io/v2/homebrew/core", - "files": { - "arm64_big_sur": { - "cellar": ":any_skip_relocation", - "url": "https://ghcr.io/v2/homebrew/core/swift-format/blobs/sha256:75fa25fe584857edcac70f44e1bf5f2c1ab8cea794cab40955da080f0f2b1061", - "sha256": "75fa25fe584857edcac70f44e1bf5f2c1ab8cea794cab40955da080f0f2b1061" - }, - "big_sur": { - "cellar": ":any_skip_relocation", - "url": "https://ghcr.io/v2/homebrew/core/swift-format/blobs/sha256:7db963099096dac3d24d2d3095286791c55837506c12d8ebde3560c2c169890b", - "sha256": "7db963099096dac3d24d2d3095286791c55837506c12d8ebde3560c2c169890b" - }, - "catalina": { - "cellar": ":any_skip_relocation", - "url": "https://ghcr.io/v2/homebrew/core/swift-format/blobs/sha256:21776a6b8f2417f3d2171536f6788948f3c5e8e4f1681cd4cf088ebd828c307b", - "sha256": "21776a6b8f2417f3d2171536f6788948f3c5e8e4f1681cd4cf088ebd828c307b" - } - } - } - }, "swiftformat": { - "version": "0.48.0", + "version": "0.48.1", "bottle": { "rebuild": 0, "root_url": "https://ghcr.io/v2/homebrew/core", "files": { "arm64_big_sur": { "cellar": ":any_skip_relocation", - "url": "https://ghcr.io/v2/homebrew/core/swiftformat/blobs/sha256:bca1fc4ac0264ff950c14eb3c72c0fa321baa99fb60178266da19b680d67147b", - "sha256": "bca1fc4ac0264ff950c14eb3c72c0fa321baa99fb60178266da19b680d67147b" + "url": "https://ghcr.io/v2/homebrew/core/swiftformat/blobs/sha256:937b21c64f3aec2eaf9d0234f681013e1026f3110bafac9348a58e893305c266", + "sha256": "937b21c64f3aec2eaf9d0234f681013e1026f3110bafac9348a58e893305c266" }, "big_sur": { "cellar": ":any_skip_relocation", - "url": "https://ghcr.io/v2/homebrew/core/swiftformat/blobs/sha256:fa1af90b137298039eab4205a9a8733fbba4f9e5cf0322197674ce6f1582f0e0", - "sha256": "fa1af90b137298039eab4205a9a8733fbba4f9e5cf0322197674ce6f1582f0e0" + "url": "https://ghcr.io/v2/homebrew/core/swiftformat/blobs/sha256:e5217aee36051fd378912b4620786b5892ec4b69343e06f6b94747ab08e1c0ea", + "sha256": "e5217aee36051fd378912b4620786b5892ec4b69343e06f6b94747ab08e1c0ea" }, "catalina": { "cellar": ":any_skip_relocation", - "url": "https://ghcr.io/v2/homebrew/core/swiftformat/blobs/sha256:35bc84d95bcd8e5066669c6383f999507b1d1a8a08f3aae321f89e2944ea39e2", - "sha256": "35bc84d95bcd8e5066669c6383f999507b1d1a8a08f3aae321f89e2944ea39e2" + "url": "https://ghcr.io/v2/homebrew/core/swiftformat/blobs/sha256:203eaac0a2c2f18121937d3c065a867a748e7539f8a716d8e55358d626850ec3", + "sha256": "203eaac0a2c2f18121937d3c065a867a748e7539f8a716d8e55358d626850ec3" }, "mojave": { "cellar": ":any_skip_relocation", - "url": "https://ghcr.io/v2/homebrew/core/swiftformat/blobs/sha256:b5274f542e17907e806ca6e6d1ca630a538bc2e98330329bca5a1568d76a7267", - "sha256": "b5274f542e17907e806ca6e6d1ca630a538bc2e98330329bca5a1568d76a7267" + "url": "https://ghcr.io/v2/homebrew/core/swiftformat/blobs/sha256:cc3176e0ed768de2ab13ed28cb41c6efa010382fa2862896c474ff54ce385bfa", + "sha256": "cc3176e0ed768de2ab13ed28cb41c6efa010382fa2862896c474ff54ce385bfa" } } } @@ -126,10 +102,10 @@ "system": { "macos": { "big_sur": { - "HOMEBREW_VERSION": "3.1.5", + "HOMEBREW_VERSION": "3.1.5-146-g64b6846", "HOMEBREW_PREFIX": "/opt/homebrew", - "Homebrew/homebrew-core": "e6c5a215e70e758472a62b1ff0a1ecdf94facc61", - "CLT": "12.5.0.0.1.1617976050", + "Homebrew/homebrew-core": "625fbbcc0d7c16be8838dc2c309714dd553ccbd1", + "CLT": "12.5.0.22.9", "Xcode": "12.5", "macOS": "11.3.1" } diff --git a/Package.resolved b/Package.resolved index 391dbcc..34cfee5 100644 --- a/Package.resolved +++ b/Package.resolved @@ -46,6 +46,33 @@ "version": "4.0.0" } }, + { + "package": "swift-argument-parser", + "repositoryURL": "https://github.com/apple/swift-argument-parser.git", + "state": { + "branch": null, + "revision": "986d191f94cec88f6350056da59c2e59e83d1229", + "version": "0.4.3" + } + }, + { + "package": "swift-format", + "repositoryURL": "https://github.com/apple/swift-format", + "state": { + "branch": null, + "revision": "9c15831b798d767c9af0927a931de5d557004936", + "version": "0.50400.0" + } + }, + { + "package": "SwiftSyntax", + "repositoryURL": "https://github.com/apple/swift-syntax", + "state": { + "branch": null, + "revision": "2fff9fc25cdc059379b6bd309377cfab45d8520c", + "version": "0.50400.0" + } + }, { "package": "Version", "repositoryURL": "https://github.com/mxcl/Version.git", diff --git a/Package.swift b/Package.swift index 4066a86..a588682 100644 --- a/Package.swift +++ b/Package.swift @@ -6,7 +6,7 @@ import PackageDescription let package = Package( name: "mas", platforms: [ - .macOS(.v10_11), + .macOS(.v10_11) ], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. @@ -36,7 +36,7 @@ let package = Package( .unsafeFlags([ "-I", "Sources/PrivateFrameworks/CommerceKit", "-I", "Sources/PrivateFrameworks/StoreFoundation", - ]), + ]) ] ), .target( @@ -46,7 +46,7 @@ let package = Package( .unsafeFlags([ "-I", "Sources/PrivateFrameworks/CommerceKit", "-I", "Sources/PrivateFrameworks/StoreFoundation", - ]), + ]) ], linkerSettings: [ .linkedFramework("CommerceKit"), @@ -62,9 +62,19 @@ let package = Package( .unsafeFlags([ "-I", "Sources/PrivateFrameworks/CommerceKit", "-I", "Sources/PrivateFrameworks/StoreFoundation", - ]), + ]) ] ), ], swiftLanguageVersions: [.v5] ) + +#if swift(>=5.4) + package.dependencies += [ + .package(url: "https://github.com/apple/swift-format", from: "0.50400.0") + ] +#elseif swift(>=5.3) + package.dependencies += [ + .package(url: "https://github.com/apple/swift-format", from: "0.50300.0") + ] +#endif diff --git a/Sources/MasKit/Commands/Version.swift b/Sources/MasKit/Commands/Version.swift index 8feaf48..d166170 100644 --- a/Sources/MasKit/Commands/Version.swift +++ b/Sources/MasKit/Commands/Version.swift @@ -18,7 +18,7 @@ public struct VersionCommand: CommandProtocol { /// Runs the command. public func run(_: Options) -> Result { - print(Package.Version) + print(Package.version) return .success(()) } } diff --git a/Sources/MasKit/Formatters/Utilities.swift b/Sources/MasKit/Formatters/Utilities.swift index d4144a6..36729c0 100644 --- a/Sources/MasKit/Formatters/Utilities.swift +++ b/Sources/MasKit/Formatters/Utilities.swift @@ -15,29 +15,30 @@ let csi = "\u{001B}[" #if DEBUG -var printObserver: ((String) -> Void)? + var printObserver: ((String) -> Void)? -// Override global print for testability. -// See MasKitTests/OutputListener.swift. -func print(_ items: Any..., separator: String = " ", terminator: String = "\n") { - if let observer = printObserver { - let output = items - .map { "\($0)" } - .joined(separator: separator) - .appending(terminator) - observer(output) + // Override global print for testability. + // See MasKitTests/OutputListener.swift. + func print(_ items: Any..., separator: String = " ", terminator: String = "\n") { + if let observer = printObserver { + let output = + items + .map { "\($0)" } + .joined(separator: separator) + .appending(terminator) + observer(output) + } + + var prefix = "" + for item in items { + Swift.print(prefix, terminator: "") + Swift.print(item, terminator: "") + prefix = separator + } + + Swift.print(terminator, terminator: "") } - var prefix = "" - for item in items { - Swift.print(prefix, terminator: "") - Swift.print(item, terminator: "") - prefix = separator - } - - Swift.print(terminator, terminator: "") -} - #endif func printInfo(_ message: String) { diff --git a/Tests/MasKitTests/Controllers/MasStoreSearchSpec.swift b/Tests/MasKitTests/Controllers/MasStoreSearchSpec.swift index a1e5ccc..63983e0 100644 --- a/Tests/MasKitTests/Controllers/MasStoreSearchSpec.swift +++ b/Tests/MasKitTests/Controllers/MasStoreSearchSpec.swift @@ -25,7 +25,7 @@ class MasStoreSearchSpec: QuickSpec { expect(results.count) == 39 } catch { let maserror = error as! MASError - if case let .jsonParsing(nserror) = maserror { + if case .jsonParsing(let nserror) = maserror { fail("\(maserror) \(nserror!)") } } @@ -43,7 +43,7 @@ class MasStoreSearchSpec: QuickSpec { lookup = try storeSearch.lookup(app: appId) } catch { let maserror = error as! MASError - if case let .jsonParsing(nserror) = maserror { + if case .jsonParsing(let nserror) = maserror { fail("\(maserror) \(nserror!)") } } diff --git a/Tests/MasKitTests/ExternalCommands/OpenSystemCommandMock.swift b/Tests/MasKitTests/ExternalCommands/OpenSystemCommandMock.swift index 13352e0..96b56df 100644 --- a/Tests/MasKitTests/ExternalCommands/OpenSystemCommandMock.swift +++ b/Tests/MasKitTests/ExternalCommands/OpenSystemCommandMock.swift @@ -7,6 +7,7 @@ // import Foundation + @testable import MasKit class OpenSystemCommandMock: ExternalCommand { diff --git a/Tests/MasKitTests/Models/SoftwareProductMock.swift b/Tests/MasKitTests/Models/SoftwareProductMock.swift index ee8203e..c12bfa6 100644 --- a/Tests/MasKitTests/Models/SoftwareProductMock.swift +++ b/Tests/MasKitTests/Models/SoftwareProductMock.swift @@ -7,6 +7,7 @@ // import Foundation + @testable import MasKit struct SoftwareProductMock: SoftwareProduct { diff --git a/Tests/MasKitTests/Nimble/ResultPredicates.swift b/Tests/MasKitTests/Nimble/ResultPredicates.swift index c6c343c..4a9c1da 100644 --- a/Tests/MasKitTests/Nimble/ResultPredicates.swift +++ b/Tests/MasKitTests/Nimble/ResultPredicates.swift @@ -23,7 +23,7 @@ func beSuccess() -> Predicate> { /// Nimble predicate for result enum failure with associated error func beFailure(test: @escaping (MASError) -> Void = { _ in }) -> Predicate> { Predicate.define("be ") { expression, message in - if case let .failure(error) = try expression.evaluate() { + if case .failure(let error) = try expression.evaluate() { test(error) return PredicateResult(status: .matches, message: message) } diff --git a/script/format b/script/format index b888429..dc1287c 100755 --- a/script/format +++ b/script/format @@ -13,7 +13,7 @@ echo "==> 🚨 Formatting mas" -for LINTER in markdownlint shfmt swift-format swiftformat swiftlint; do +for LINTER in markdownlint shfmt swiftformat swiftlint; do if [[ ! -x "$(command -v ${LINTER})" ]]; then echo "error: ${LINTER} is not installed. Run 'script/bootstrap' or 'brew install ${LINTER}'." exit 1 @@ -28,7 +28,7 @@ echo echo "--> 🕊️ Swift" for SOURCE in Package.swift Sources Tests; do swiftformat ${SOURCE} - swift-format format --in-place --configuration .swift-format --recursive ${SOURCE} + swift run swift-format format --in-place --recursive ${SOURCE} swiftlint lint --fix --strict ${SOURCE} done diff --git a/script/lint b/script/lint index d4e5b0b..21adf4d 100755 --- a/script/lint +++ b/script/lint @@ -12,7 +12,7 @@ echo "==> 🚨 Linting mas" -for LINTER in git markdownlint shfmt swift-format swiftformat swiftlint; do +for LINTER in git markdownlint shfmt swiftformat swiftlint; do if [[ ! -x "$(command -v ${LINTER})" ]]; then echo "error: ${LINTER} is not installed. Run 'script/bootstrap' or 'brew install ${LINTER}'." exit 1 @@ -30,7 +30,7 @@ echo echo "--> 🕊️ Swift" for SOURCE in Package.swift Sources Tests; do swiftformat --lint ${SOURCE} - swift-format lint --configuration .swift-format --recursive ${SOURCE} + swift run swift-format lint --recursive ${SOURCE} swiftlint lint --strict ${SOURCE} done diff --git a/script/version b/script/version index b2372d9..f61a9f2 100755 --- a/script/version +++ b/script/version @@ -17,7 +17,7 @@ SCRIPT_PATH=$(dirname $(which $0)) cat <"${SCRIPT_PATH}/../Sources/MasKit/Package.swift" // Generated by: script/version enum Package { - static let Version = "${VERSION}" + static let version = "${VERSION}" } EOF