From c46166b45a05f751ff833f41f2aa66326aab4774 Mon Sep 17 00:00:00 2001 From: Caleb Jasik Date: Thu, 13 Feb 2025 16:23:37 -0600 Subject: [PATCH 1/5] Check swift formatting in CI --- .github/workflows/swiftfmt.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/workflows/swiftfmt.yml diff --git a/.github/workflows/swiftfmt.yml b/.github/workflows/swiftfmt.yml new file mode 100644 index 00000000..510ad976 --- /dev/null +++ b/.github/workflows/swiftfmt.yml @@ -0,0 +1,21 @@ +name: Swift format +on: + push: + branches: + - main + pull_request: + paths: + - '.github/workflows/swiftfmt.yml' + - '**.swift' +jobs: + swiftfmt: + name: Run swift format + runs-on: macos-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + with: + show-progress: false + + - name: Check formating + run: swiftformat --lint . --reporter github-actions-log From 9de1849e93c1ba1bf9e25f7a4905d205fad197a3 Mon Sep 17 00:00:00 2001 From: Caleb Jasik Date: Thu, 13 Feb 2025 16:24:48 -0600 Subject: [PATCH 2/5] Document dep on `swiftformat` and using it for swift formatting --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 901d4544..38a2b478 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ Install all of the following things: - [`xcode`](https://apps.apple.com/us/app/xcode/) +- [`swiftformat`](https://github.com/nicklockwood/SwiftFormat) - [`android-studio`](https://developer.android.com/studio) - [`flutter` 3.29.0](https://docs.flutter.dev/get-started/install) - [`gomobile`](https://pkg.go.dev/golang.org/x/mobile/cmd/gomobile) @@ -41,6 +42,10 @@ dart format lib/ test/ -l 120 In Android Studio, set the line length using Preferences -> Editor -> Code Style -> Dart -> Line length, set it to 120. Enable auto-format with Preferences -> Languages & Frameworks -> Flutter -> Format code on save. +`swiftformat .` can be used to format the `*.swift` code in the repo. + +There are several options for editor integrations listed in the source repo: + # Release From b1e28933883e0d03fccde6a78847caf31527d922 Mon Sep 17 00:00:00 2001 From: Caleb Jasik Date: Thu, 13 Feb 2025 16:32:20 -0600 Subject: [PATCH 3/5] Set Swift version to 5 --- ios/.swiftformat | 1 + ios/Runner.xcodeproj/project.pbxproj | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 ios/.swiftformat diff --git a/ios/.swiftformat b/ios/.swiftformat new file mode 100644 index 00000000..7bee4eda --- /dev/null +++ b/ios/.swiftformat @@ -0,0 +1 @@ +--swiftversion 5 diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index a455d67d..28d9bad9 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -563,6 +563,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -772,6 +773,7 @@ MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -825,6 +827,7 @@ SUPPORTED_PLATFORMS = iphoneos; SWIFT_COMPILATION_MODE = wholemodule; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; From 5d97e5352262bc720b3b304236d63fe1355ca586 Mon Sep 17 00:00:00 2001 From: Caleb Jasik Date: Thu, 13 Feb 2025 16:33:03 -0600 Subject: [PATCH 4/5] Ignore Pods and Generated folders when formatting --- ios/.swiftformat | 1 + 1 file changed, 1 insertion(+) diff --git a/ios/.swiftformat b/ios/.swiftformat index 7bee4eda..ca26317a 100644 --- a/ios/.swiftformat +++ b/ios/.swiftformat @@ -1 +1,2 @@ --swiftversion 5 +--exclude Pods,Generated \ No newline at end of file From 02e8c5bf357cad65a5fea3cfd35acbe15a452fa6 Mon Sep 17 00:00:00 2001 From: Caleb Jasik Date: Thu, 13 Feb 2025 16:48:35 -0600 Subject: [PATCH 5/5] Disable CI check for formatting --- .github/workflows/swiftfmt.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/swiftfmt.yml b/.github/workflows/swiftfmt.yml index 510ad976..f85ef184 100644 --- a/.github/workflows/swiftfmt.yml +++ b/.github/workflows/swiftfmt.yml @@ -17,5 +17,6 @@ jobs: with: show-progress: false - - name: Check formating - run: swiftformat --lint . --reporter github-actions-log + # Re-enable in follow-up PR that does the formatting. + # - name: Check formating + # run: swiftformat --lint . --reporter github-actions-log