diff --git a/.github/workflows/swift.yaml b/.github/workflows/swift.yaml index 386656644..ea3cc07ab 100644 --- a/.github/workflows/swift.yaml +++ b/.github/workflows/swift.yaml @@ -82,3 +82,13 @@ jobs: - name: Swiftdocs run: | .buildscript/build_swift_docs.sh ${{ runner.temp }}/swiftdocs + + swiftformat: + runs-on: macos-latest + + steps: + - uses: actions/checkout@v4 + - uses: jdx/mise-action@v2 + + - name: Run swiftformat + run: swiftformat --lint . diff --git a/.hooks/pre-commit b/.hooks/pre-commit index eaa6fa8ff..deed94894 100755 --- a/.hooks/pre-commit +++ b/.hooks/pre-commit @@ -1,7 +1,17 @@ #!/bin/bash -swift_files=$(git diff --diff-filter=d --staged --name-only -- '*.swift') +# Do not run on merge +if [[ $(git rev-parse -q --verify MERGE_HEAD) ]]; then + exit 0 +fi -echo $swift_files | xargs swift run swiftformat --quiet +ROOT="$(git rev-parse --show-toplevel)" +SWIFT_FORMAT="mise x -- swiftformat" +GIT_FORMAT_STAGED="$ROOT/Scripts/git-format-staged" +CONFIG="${ROOT}/.swiftformat" -echo $swift_files | xargs git add +$SWIFT_FORMAT --version 1>/dev/null 2>&1 +if [ $? -eq 0 ] +then + $GIT_FORMAT_STAGED --formatter "$SWIFT_FORMAT stdin --config "$CONFIG" --stdinpath '{}'" "*.swift" +fi diff --git a/Package.resolved b/Package.resolved index 8d4aa0788..e4806c58d 100644 --- a/Package.resolved +++ b/Package.resolved @@ -81,15 +81,6 @@ "version" : "600.0.1" } }, - { - "identity" : "swiftformat", - "kind" : "remoteSourceControl", - "location" : "https://github.com/nicklockwood/SwiftFormat", - "state" : { - "revision" : "dd989a46d0c6f15c016484bab8afe5e7a67a4022", - "version" : "0.54.0" - } - }, { "identity" : "xctest-dynamic-overlay", "kind" : "remoteSourceControl", diff --git a/Package.swift b/Package.swift index e6af4c440..3d9d18c3d 100644 --- a/Package.swift +++ b/Package.swift @@ -59,8 +59,7 @@ let package = Package( dependencies: [ .package(url: "https://github.com/ReactiveCocoa/ReactiveSwift.git", from: "7.1.1"), .package(url: "https://github.com/ReactiveX/RxSwift.git", from: "6.6.0"), - .package(url: "https://github.com/nicklockwood/SwiftFormat", exact: "0.54.0"), - .package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0"..<"601.0.0-prerelease"), + .package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0" ..< "601.0.0-prerelease"), .package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.1.0"), .package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.0.0"), .package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.4.0"), @@ -278,7 +277,7 @@ extension PackageDescription.Product { } for target in package.targets { - var settings = target.swiftSettings ?? [] - settings.append(.enableExperimentalFeature("StrictConcurrency=targeted")) - target.swiftSettings = settings + var settings = target.swiftSettings ?? [] + settings.append(.enableExperimentalFeature("StrictConcurrency=targeted")) + target.swiftSettings = settings } diff --git a/Samples/AlertContainer/Sources/AlertContainerScreen.swift b/Samples/AlertContainer/Sources/AlertContainerScreen.swift index dc84afe0d..3a095a6e9 100644 --- a/Samples/AlertContainer/Sources/AlertContainerScreen.swift +++ b/Samples/AlertContainer/Sources/AlertContainerScreen.swift @@ -30,7 +30,7 @@ public struct AlertContainerScreen: Screen { } public func viewControllerDescription(environment: ViewEnvironment) -> ViewControllerDescription { - return AlertContainerViewController.description(for: self, environment: environment) + AlertContainerViewController.description(for: self, environment: environment) } } diff --git a/Samples/AlertContainer/Sources/AlertContainerViewController.swift b/Samples/AlertContainer/Sources/AlertContainerViewController.swift index 1a6011787..a864f540f 100644 --- a/Samples/AlertContainer/Sources/AlertContainerViewController.swift +++ b/Samples/AlertContainer/Sources/AlertContainerViewController.swift @@ -18,13 +18,13 @@ import UIKit import Workflow import WorkflowUI -private struct AlertStyleConstants { +private enum AlertStyleConstants { static let viewWidth: CGFloat = 343.0 static let buttonTitleColor = UIColor(red: 41 / 255, green: 150 / 255, blue: 204 / 255, alpha: 1.0) static let titleFont = UIFont.systemFont(ofSize: 18, weight: .medium) } -internal final class AlertContainerViewController: ScreenViewController> { +final class AlertContainerViewController: ScreenViewController> { private var baseScreenViewController: DescribedViewController private let dimmingView = UIView() @@ -63,7 +63,7 @@ internal final class AlertContainerViewController: ScreenVi baseScreenViewController.update(screen: screen.baseScreen, environment: environment) if let alert = screen.alert { - if let alertView = alertView { + if let alertView { alertView.alert = alert } else { let inAlertView = AlertView(alert: alert) @@ -104,7 +104,7 @@ internal final class AlertContainerViewController: ScreenVi ) } } else { - if let alertView = alertView { + if let alertView { UIView.animate( withDuration: 0.1, delay: 0, @@ -126,23 +126,23 @@ internal final class AlertContainerViewController: ScreenVi } override var childForStatusBarStyle: UIViewController? { - return baseScreenViewController + baseScreenViewController } override var childForStatusBarHidden: UIViewController? { - return baseScreenViewController + baseScreenViewController } override var childForHomeIndicatorAutoHidden: UIViewController? { - return baseScreenViewController + baseScreenViewController } override var childForScreenEdgesDeferringSystemGestures: UIViewController? { - return baseScreenViewController + baseScreenViewController } override public var supportedInterfaceOrientations: UIInterfaceOrientationMask { - return baseScreenViewController.supportedInterfaceOrientations + baseScreenViewController.supportedInterfaceOrientations } } @@ -173,7 +173,7 @@ private final class AlertView: UIView { } private func commonInit() { - guard let alert = alert else { + guard let alert else { return } title.text = alert.title @@ -253,6 +253,7 @@ private final class AlertButton: UIButton { addTarget(self, action: #selector(triggerActionHandler), for: .touchUpInside) } + @available(*, unavailable) required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } diff --git a/Samples/AsyncWorker/Sources/AsyncWorkerWorkflow.swift b/Samples/AsyncWorker/Sources/AsyncWorkerWorkflow.swift index 9bb62d667..a90fcb726 100644 --- a/Samples/AsyncWorker/Sources/AsyncWorkerWorkflow.swift +++ b/Samples/AsyncWorker/Sources/AsyncWorkerWorkflow.swift @@ -22,7 +22,7 @@ extension AsyncWorkerWorkflow { } func makeInitialState() -> AsyncWorkerWorkflow.State { - return State(model: Model(message: "Initial State")) + State(model: Model(message: "Initial State")) } func workflowDidChange(from previousWorkflow: AsyncWorkerWorkflow, state: inout State) {} diff --git a/Samples/AsyncWorker/Sources/FakeNetwork/FakeNetworkManager.swift b/Samples/AsyncWorker/Sources/FakeNetwork/FakeNetworkManager.swift index 60669614b..b6a40b1c1 100644 --- a/Samples/AsyncWorker/Sources/FakeNetwork/FakeNetworkManager.swift +++ b/Samples/AsyncWorker/Sources/FakeNetwork/FakeNetworkManager.swift @@ -9,7 +9,7 @@ import Foundation class FakeNetworkManager { static func makeFakeNetworkRequest() -> FakeRequest { - return FakeRequest() + FakeRequest() } } diff --git a/Samples/AsyncWorker/Sources/FakeNetwork/Model.swift b/Samples/AsyncWorker/Sources/FakeNetwork/Model.swift index 833347a08..01bdb42f5 100644 --- a/Samples/AsyncWorker/Sources/FakeNetwork/Model.swift +++ b/Samples/AsyncWorker/Sources/FakeNetwork/Model.swift @@ -1,5 +1,5 @@ // -// FakeModel.swift +// Model.swift // AsyncWorker // // Created by Mark Johnson on 6/16/22. diff --git a/Samples/BackStackContainer/Sources/BackStackContainer.swift b/Samples/BackStackContainer/Sources/BackStackContainer.swift index 6293d0b72..89abfc48c 100644 --- a/Samples/BackStackContainer/Sources/BackStackContainer.swift +++ b/Samples/BackStackContainer/Sources/BackStackContainer.swift @@ -14,8 +14,8 @@ * limitations under the License. */ -import WorkflowUI import UIKit +import WorkflowUI public final class BackStackContainer: ScreenViewController>, UINavigationControllerDelegate { private let navController = UINavigationController() @@ -69,14 +69,12 @@ public final class BackStackContainer: ScreenViewController