🧹 Match swift-format to compiler version

Fixes #364.
This commit is contained in:
Chris Araman 2021-05-08 13:26:25 -07:00
parent 9dfa2f8b57
commit 4848f422d6
15 changed files with 91 additions and 76 deletions

View file

@ -5,13 +5,14 @@
# https://github.com/nicklockwood/SwiftFormat#config-file # https://github.com/nicklockwood/SwiftFormat#config-file
# #
--exclude Carthage/,docs/ --exclude docs/
# Disabled rules # Disabled rules
--disable blankLinesAroundMark --disable blankLinesAroundMark
--disable consecutiveSpaces --disable consecutiveSpaces
--disable hoistPatternLet --disable hoistPatternLet
--disable indent --disable indent
--disable trailingCommas
# Enabled rules (disabled by default) # Enabled rules (disabled by default)
--enable trailingClosures --enable trailingClosures

View file

@ -4,13 +4,12 @@
# #
# https://github.com/realm/SwiftLint#configuration # https://github.com/realm/SwiftLint#configuration
# #
---
disabled_rules:
- trailing_comma
excluded: excluded:
- Carthage
- docs - docs
opening_brace: opening_brace:
allow_multiline_func: true allow_multiline_func: true
trailing_comma:
mandatory_comma: true

View file

@ -1,6 +1,5 @@
brew "markdownlint-cli" brew "markdownlint-cli"
brew "shfmt" brew "shfmt"
brew "swift-format"
brew "swiftformat" brew "swiftformat"
# Already installed on GitHub Actions runner. # Already installed on GitHub Actions runner.

View file

@ -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": { "swiftformat": {
"version": "0.48.0", "version": "0.48.1",
"bottle": { "bottle": {
"rebuild": 0, "rebuild": 0,
"root_url": "https://ghcr.io/v2/homebrew/core", "root_url": "https://ghcr.io/v2/homebrew/core",
"files": { "files": {
"arm64_big_sur": { "arm64_big_sur": {
"cellar": ":any_skip_relocation", "cellar": ":any_skip_relocation",
"url": "https://ghcr.io/v2/homebrew/core/swiftformat/blobs/sha256:bca1fc4ac0264ff950c14eb3c72c0fa321baa99fb60178266da19b680d67147b", "url": "https://ghcr.io/v2/homebrew/core/swiftformat/blobs/sha256:937b21c64f3aec2eaf9d0234f681013e1026f3110bafac9348a58e893305c266",
"sha256": "bca1fc4ac0264ff950c14eb3c72c0fa321baa99fb60178266da19b680d67147b" "sha256": "937b21c64f3aec2eaf9d0234f681013e1026f3110bafac9348a58e893305c266"
}, },
"big_sur": { "big_sur": {
"cellar": ":any_skip_relocation", "cellar": ":any_skip_relocation",
"url": "https://ghcr.io/v2/homebrew/core/swiftformat/blobs/sha256:fa1af90b137298039eab4205a9a8733fbba4f9e5cf0322197674ce6f1582f0e0", "url": "https://ghcr.io/v2/homebrew/core/swiftformat/blobs/sha256:e5217aee36051fd378912b4620786b5892ec4b69343e06f6b94747ab08e1c0ea",
"sha256": "fa1af90b137298039eab4205a9a8733fbba4f9e5cf0322197674ce6f1582f0e0" "sha256": "e5217aee36051fd378912b4620786b5892ec4b69343e06f6b94747ab08e1c0ea"
}, },
"catalina": { "catalina": {
"cellar": ":any_skip_relocation", "cellar": ":any_skip_relocation",
"url": "https://ghcr.io/v2/homebrew/core/swiftformat/blobs/sha256:35bc84d95bcd8e5066669c6383f999507b1d1a8a08f3aae321f89e2944ea39e2", "url": "https://ghcr.io/v2/homebrew/core/swiftformat/blobs/sha256:203eaac0a2c2f18121937d3c065a867a748e7539f8a716d8e55358d626850ec3",
"sha256": "35bc84d95bcd8e5066669c6383f999507b1d1a8a08f3aae321f89e2944ea39e2" "sha256": "203eaac0a2c2f18121937d3c065a867a748e7539f8a716d8e55358d626850ec3"
}, },
"mojave": { "mojave": {
"cellar": ":any_skip_relocation", "cellar": ":any_skip_relocation",
"url": "https://ghcr.io/v2/homebrew/core/swiftformat/blobs/sha256:b5274f542e17907e806ca6e6d1ca630a538bc2e98330329bca5a1568d76a7267", "url": "https://ghcr.io/v2/homebrew/core/swiftformat/blobs/sha256:cc3176e0ed768de2ab13ed28cb41c6efa010382fa2862896c474ff54ce385bfa",
"sha256": "b5274f542e17907e806ca6e6d1ca630a538bc2e98330329bca5a1568d76a7267" "sha256": "cc3176e0ed768de2ab13ed28cb41c6efa010382fa2862896c474ff54ce385bfa"
} }
} }
} }
@ -126,10 +102,10 @@
"system": { "system": {
"macos": { "macos": {
"big_sur": { "big_sur": {
"HOMEBREW_VERSION": "3.1.5", "HOMEBREW_VERSION": "3.1.5-146-g64b6846",
"HOMEBREW_PREFIX": "/opt/homebrew", "HOMEBREW_PREFIX": "/opt/homebrew",
"Homebrew/homebrew-core": "e6c5a215e70e758472a62b1ff0a1ecdf94facc61", "Homebrew/homebrew-core": "625fbbcc0d7c16be8838dc2c309714dd553ccbd1",
"CLT": "12.5.0.0.1.1617976050", "CLT": "12.5.0.22.9",
"Xcode": "12.5", "Xcode": "12.5",
"macOS": "11.3.1" "macOS": "11.3.1"
} }

View file

@ -46,6 +46,33 @@
"version": "4.0.0" "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", "package": "Version",
"repositoryURL": "https://github.com/mxcl/Version.git", "repositoryURL": "https://github.com/mxcl/Version.git",

View file

@ -6,7 +6,7 @@ import PackageDescription
let package = Package( let package = Package(
name: "mas", name: "mas",
platforms: [ platforms: [
.macOS(.v10_11), .macOS(.v10_11)
], ],
products: [ products: [
// Products define the executables and libraries a package produces, and make them visible to other packages. // Products define the executables and libraries a package produces, and make them visible to other packages.
@ -36,7 +36,7 @@ let package = Package(
.unsafeFlags([ .unsafeFlags([
"-I", "Sources/PrivateFrameworks/CommerceKit", "-I", "Sources/PrivateFrameworks/CommerceKit",
"-I", "Sources/PrivateFrameworks/StoreFoundation", "-I", "Sources/PrivateFrameworks/StoreFoundation",
]), ])
] ]
), ),
.target( .target(
@ -46,7 +46,7 @@ let package = Package(
.unsafeFlags([ .unsafeFlags([
"-I", "Sources/PrivateFrameworks/CommerceKit", "-I", "Sources/PrivateFrameworks/CommerceKit",
"-I", "Sources/PrivateFrameworks/StoreFoundation", "-I", "Sources/PrivateFrameworks/StoreFoundation",
]), ])
], ],
linkerSettings: [ linkerSettings: [
.linkedFramework("CommerceKit"), .linkedFramework("CommerceKit"),
@ -62,9 +62,19 @@ let package = Package(
.unsafeFlags([ .unsafeFlags([
"-I", "Sources/PrivateFrameworks/CommerceKit", "-I", "Sources/PrivateFrameworks/CommerceKit",
"-I", "Sources/PrivateFrameworks/StoreFoundation", "-I", "Sources/PrivateFrameworks/StoreFoundation",
]), ])
] ]
), ),
], ],
swiftLanguageVersions: [.v5] 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

View file

@ -18,7 +18,7 @@ public struct VersionCommand: CommandProtocol {
/// Runs the command. /// Runs the command.
public func run(_: Options) -> Result<Void, MASError> { public func run(_: Options) -> Result<Void, MASError> {
print(Package.Version) print(Package.version)
return .success(()) return .success(())
} }
} }

View file

@ -15,13 +15,14 @@ let csi = "\u{001B}["
#if DEBUG #if DEBUG
var printObserver: ((String) -> Void)? var printObserver: ((String) -> Void)?
// Override global print for testability. // Override global print for testability.
// See MasKitTests/OutputListener.swift. // See MasKitTests/OutputListener.swift.
func print(_ items: Any..., separator: String = " ", terminator: String = "\n") { func print(_ items: Any..., separator: String = " ", terminator: String = "\n") {
if let observer = printObserver { if let observer = printObserver {
let output = items let output =
items
.map { "\($0)" } .map { "\($0)" }
.joined(separator: separator) .joined(separator: separator)
.appending(terminator) .appending(terminator)
@ -36,7 +37,7 @@ func print(_ items: Any..., separator: String = " ", terminator: String = "\n")
} }
Swift.print(terminator, terminator: "") Swift.print(terminator, terminator: "")
} }
#endif #endif

View file

@ -25,7 +25,7 @@ class MasStoreSearchSpec: QuickSpec {
expect(results.count) == 39 expect(results.count) == 39
} catch { } catch {
let maserror = error as! MASError let maserror = error as! MASError
if case let .jsonParsing(nserror) = maserror { if case .jsonParsing(let nserror) = maserror {
fail("\(maserror) \(nserror!)") fail("\(maserror) \(nserror!)")
} }
} }
@ -43,7 +43,7 @@ class MasStoreSearchSpec: QuickSpec {
lookup = try storeSearch.lookup(app: appId) lookup = try storeSearch.lookup(app: appId)
} catch { } catch {
let maserror = error as! MASError let maserror = error as! MASError
if case let .jsonParsing(nserror) = maserror { if case .jsonParsing(let nserror) = maserror {
fail("\(maserror) \(nserror!)") fail("\(maserror) \(nserror!)")
} }
} }

View file

@ -7,6 +7,7 @@
// //
import Foundation import Foundation
@testable import MasKit @testable import MasKit
class OpenSystemCommandMock: ExternalCommand { class OpenSystemCommandMock: ExternalCommand {

View file

@ -7,6 +7,7 @@
// //
import Foundation import Foundation
@testable import MasKit @testable import MasKit
struct SoftwareProductMock: SoftwareProduct { struct SoftwareProductMock: SoftwareProduct {

View file

@ -23,7 +23,7 @@ func beSuccess() -> Predicate<Result<Void, MASError>> {
/// Nimble predicate for result enum failure with associated error /// Nimble predicate for result enum failure with associated error
func beFailure(test: @escaping (MASError) -> Void = { _ in }) -> Predicate<Result<Void, MASError>> { func beFailure(test: @escaping (MASError) -> Void = { _ in }) -> Predicate<Result<Void, MASError>> {
Predicate.define("be <failure>") { expression, message in Predicate.define("be <failure>") { expression, message in
if case let .failure(error) = try expression.evaluate() { if case .failure(let error) = try expression.evaluate() {
test(error) test(error)
return PredicateResult(status: .matches, message: message) return PredicateResult(status: .matches, message: message)
} }

View file

@ -13,7 +13,7 @@
echo "==> 🚨 Formatting mas" 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 if [[ ! -x "$(command -v ${LINTER})" ]]; then
echo "error: ${LINTER} is not installed. Run 'script/bootstrap' or 'brew install ${LINTER}'." echo "error: ${LINTER} is not installed. Run 'script/bootstrap' or 'brew install ${LINTER}'."
exit 1 exit 1
@ -28,7 +28,7 @@ echo
echo "--> 🕊️ Swift" echo "--> 🕊️ Swift"
for SOURCE in Package.swift Sources Tests; do for SOURCE in Package.swift Sources Tests; do
swiftformat ${SOURCE} 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} swiftlint lint --fix --strict ${SOURCE}
done done

View file

@ -12,7 +12,7 @@
echo "==> 🚨 Linting mas" 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 if [[ ! -x "$(command -v ${LINTER})" ]]; then
echo "error: ${LINTER} is not installed. Run 'script/bootstrap' or 'brew install ${LINTER}'." echo "error: ${LINTER} is not installed. Run 'script/bootstrap' or 'brew install ${LINTER}'."
exit 1 exit 1
@ -30,7 +30,7 @@ echo
echo "--> 🕊️ Swift" echo "--> 🕊️ Swift"
for SOURCE in Package.swift Sources Tests; do for SOURCE in Package.swift Sources Tests; do
swiftformat --lint ${SOURCE} swiftformat --lint ${SOURCE}
swift-format lint --configuration .swift-format --recursive ${SOURCE} swift run swift-format lint --recursive ${SOURCE}
swiftlint lint --strict ${SOURCE} swiftlint lint --strict ${SOURCE}
done done

View file

@ -17,7 +17,7 @@ SCRIPT_PATH=$(dirname $(which $0))
cat <<EOF >"${SCRIPT_PATH}/../Sources/MasKit/Package.swift" cat <<EOF >"${SCRIPT_PATH}/../Sources/MasKit/Package.swift"
// Generated by: script/version // Generated by: script/version
enum Package { enum Package {
static let Version = "${VERSION}" static let version = "${VERSION}"
} }
EOF EOF