Skip to content

Commit 97834bf

Browse files
authored
Update swift lint and format + appy fixes (#2585)
## Summary Swift lint and swiftformat are outdated. This PR does update those + applies the new formatting form swiftformat. There is 1 swift file with a manual change: `Sources/Vehicle/Templates/Areas/CarPlayAreasViewModel.swift`. This is done because `swiftlint` did create the following swiftlint error: `error: Cyclomatic Complexity Violation: Function should have complexity 10 or less; currently complexity is 11 (cyclomatic_complexity)`. Because it does change a lot of files the question is if we want to finetune the `swiftformat` rules. ## Screenshots No user facing changes. ## Link to pull request in Documentation repository NA ## Any other notes NA
1 parent 58cb900 commit 97834bf

File tree

174 files changed

+502
-494
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

174 files changed

+502
-494
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ jobs:
3434
- name: SwiftLint
3535
run: |
3636
docker run --rm -v `pwd`:`pwd` -w `pwd` \
37-
ghcr.io/realm/swiftlint:0.49.1 \
37+
ghcr.io/realm/swiftlint:0.54.0 \
3838
swiftlint lint --strict --config .swiftlint.yml --reporter github-actions-logging
3939
- name: SwiftFormat
4040
run: |
4141
docker run --rm -v `pwd`:`pwd` -w `pwd` \
42-
ghcr.io/nicklockwood/swiftformat:0.50.3 \
42+
ghcr.io/nicklockwood/swiftformat:0.53.1 \
4343
--lint --config .swiftformat .
4444
4545
test:

.swiftformat

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
--swiftversion 5.3
1+
--swiftversion 5.8
22

33
--exclude vendor,Pods,**/Swiftgen/**,**/Resources/**,fastlane,**/Assets/**
44

.swiftlint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ excluded:
5353
- Tests
5454
- Pods
5555
- vendor
56-
- "*/**/.build"
56+
- "**/**/.build"

Podfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ project 'HomeAssistant', 'Debug' => :debug, 'Release' => :release, 'Beta' => :re
55

66
def support_modules
77
pod 'SwiftGen', '~> 6.5.0'
8-
pod 'SwiftLint', '0.49.1' # also update ci.yml GHA
9-
pod 'SwiftFormat/CLI', '0.50.3' # also update ci.yml GHA
8+
pod 'SwiftLint', '0.54.0' # also update ci.yml GHA
9+
pod 'SwiftFormat/CLI', '0.53.1' # also update ci.yml GHA
1010
end
1111

1212
if ENV['ONLY_SUPPORT_MODULES']

Podfile.lock

+7-7
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ PODS:
103103
- Realm (= 10.35.0)
104104
- Sodium (0.9.1)
105105
- Starscream (4.0.4)
106-
- SwiftFormat/CLI (0.50.3)
106+
- SwiftFormat/CLI (0.53.1)
107107
- SwiftGen (6.5.1)
108-
- SwiftLint (0.49.1)
108+
- SwiftLint (0.54.0)
109109
- SwiftMessages (9.0.6):
110110
- SwiftMessages/App (= 9.0.6)
111111
- SwiftMessages/App (9.0.6)
@@ -141,9 +141,9 @@ DEPENDENCIES:
141141
- RealmSwift
142142
- Sodium (from `https://github.com/zacwest/swift-sodium.git`, branch `xcode-14.0.1`)
143143
- Starscream (from `https://github.com/zacwest/starscream`, branch `ha-swift-api`)
144-
- SwiftFormat/CLI (= 0.50.3)
144+
- SwiftFormat/CLI (= 0.53.1)
145145
- SwiftGen (~> 6.5.0)
146-
- SwiftLint (= 0.49.1)
146+
- SwiftLint (= 0.54.0)
147147
- SwiftMessages
148148
- UIColor_Hex_Swift
149149
- Version
@@ -274,16 +274,16 @@ SPEC CHECKSUMS:
274274
RealmSwift: b358779c10ba6d2648d541f8a1bcd671f73485c1
275275
Sodium: a7d42cb46e789d2630fa552d35870b416ed055ae
276276
Starscream: 5178aed56b316f13fa3bc55694e583d35dd414d9
277-
SwiftFormat: 61cda3819dc3a7d69795ce0430e1e1d53c4a4fb2
277+
SwiftFormat: a8623113c7adcbeb4289a013cac68ec801e1ed24
278278
SwiftGen: a6d22010845f08fe18fbdf3a07a8e380fd22e0ea
279-
SwiftLint: 32ee33ded0636d0905ef6911b2b67bbaeeedafa5
279+
SwiftLint: c1de071d9d08c8aba837545f6254315bc900e211
280280
SwiftMessages: f0c7ef4705a570ad6c5e208b611f4333e660ed92
281281
UIColor_Hex_Swift: 31cd3e47440f07a20d2503a36bb0437a445b3c29
282282
Version: de5907f2c5d0f3cf21708db7801d1d5401139486
283283
ViewRow: 8da541e9c019f3be63f4e28f311a62cac2045ecf
284284
XCGLogger: 1943831ef907df55108b0b18657953f868de973b
285285
ZIPFoundation: d170fa8e270b2a32bef9dcdcabff5b8f1a5deced
286286

287-
PODFILE CHECKSUM: 22fc24cfd665bd31532e7b68cf2aee22abb132b2
287+
PODFILE CHECKSUM: a1fb8b74054208eb193f5366db79acab04a209b0
288288

289289
COCOAPODS: 1.15.2

Sources/App/AppDelegate.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extension AppEnvironment {
3535
}
3636
}
3737

38-
@UIApplicationMain
38+
@main
3939
class AppDelegate: UIResponder, UIApplicationDelegate {
4040
@available(iOS, deprecated: 13.0)
4141
var window: UIWindow? {
@@ -144,12 +144,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
144144
}
145145
}
146146

147-
@objc internal func openAbout() {
147+
@objc func openAbout() {
148148
precondition(Current.sceneManager.supportsMultipleScenes)
149149
sceneManager.activateAnyScene(for: .about)
150150
}
151151

152-
@objc internal func openMenuUrl(_ command: AnyObject) {
152+
@objc func openMenuUrl(_ command: AnyObject) {
153153
guard let command = command as? UICommand, let url = MenuManager.url(from: command) else {
154154
return
155155
}
@@ -160,18 +160,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
160160
}
161161
}
162162

163-
@objc internal func openPreferences() {
163+
@objc func openPreferences() {
164164
precondition(Current.sceneManager.supportsMultipleScenes)
165165
sceneManager.activateAnyScene(for: .settings)
166166
}
167167

168-
@objc internal func openActionsPreferences() {
168+
@objc func openActionsPreferences() {
169169
precondition(Current.sceneManager.supportsMultipleScenes)
170170
let delegate: Guarantee<SettingsSceneDelegate> = sceneManager.scene(for: .init(activity: .settings))
171171
delegate.done { $0.pushActions(animated: true) }
172172
}
173173

174-
@objc internal func openHelp() {
174+
@objc func openHelp() {
175175
openURLInBrowser(
176176
URL(string: "https://companion.home-assistant.io")!,
177177
nil

Sources/App/ClientEvents/ClientEventTableViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public extension ClientEventTableViewController {
112112
}
113113

114114
extension UITableView {
115-
func applyChanges<T>(changes: RealmCollectionChange<T>) {
115+
func applyChanges(changes: RealmCollectionChange<some Any>) {
116116
switch changes {
117117
case .initial: reloadData()
118118
case let .update(_, deletions, insertions, updates):

Sources/App/ClientEvents/LocationHistoryListViewController.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ extension LocationHistoryListViewController: LocationHistoryDetailMoveDelegate {
8282
from row: RowOf<LocationHistoryDetailViewController>,
8383
in direction: LocationHistoryDetailViewController.MoveDirection
8484
) -> ButtonRowWithPresent<LocationHistoryDetailViewController>? {
85-
guard let indexPath = row.indexPath, let section = section else {
85+
guard let indexPath = row.indexPath, let section else {
8686
return nil
8787
}
8888

@@ -94,7 +94,7 @@ extension LocationHistoryListViewController: LocationHistoryDetailMoveDelegate {
9494
default: nextIndex = nil
9595
}
9696

97-
if let nextIndex = nextIndex {
97+
if let nextIndex {
9898
return section[nextIndex] as? ButtonRowWithPresent<LocationHistoryDetailViewController>
9999
} else {
100100
return nil
@@ -112,7 +112,7 @@ extension LocationHistoryListViewController: LocationHistoryDetailMoveDelegate {
112112
_ controller: LocationHistoryDetailViewController,
113113
move direction: LocationHistoryDetailViewController.MoveDirection
114114
) {
115-
guard let navigationController = navigationController,
115+
guard let navigationController,
116116
let nextRow = row(from: controller.row, in: direction),
117117
let nextController = nextRow.presentationMode?.makeController() else {
118118
return

Sources/App/Notifications/NotificationManagerLocalPushInterfaceExtension.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ final class NotificationManagerLocalPushInterfaceExtension: NSObject, Notificati
6262

6363
override init() {
6464
super.init()
65-
syncStates = PerServerContainer<LocalPushStateSync>(constructor: { server in
65+
self.syncStates = PerServerContainer<LocalPushStateSync>(constructor: { server in
6666
let sync = LocalPushStateSync(settingsKey: PushProviderConfiguration.defaultSettingsKey(for: server))
6767
let token = sync.observe { [weak self] _ in
6868
self?.notifyObservers(for: [server])
@@ -93,7 +93,7 @@ final class NotificationManagerLocalPushInterfaceExtension: NSObject, Notificati
9393
Current.Log.info("configuring push for \(ssid): \(servers)")
9494

9595
let existing = managers?.first(where: { $0.matchSSIDs == [ssid] })
96-
if let existing = existing {
96+
if let existing {
9797
usedManagers.insert(existing)
9898
}
9999
updatedManagers.append(updateManager(

Sources/App/Onboarding/API/OnboardingAuthError.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ struct OnboardingAuthError: LocalizedError {
9292
extraInfo = nil
9393
}
9494

95-
if let extraInfo = extraInfo {
95+
if let extraInfo {
9696
return extraInfo + "\n\n" + underlying.localizedDescription
9797
} else {
9898
return underlying.localizedDescription
@@ -101,7 +101,7 @@ struct OnboardingAuthError: LocalizedError {
101101
}
102102

103103
var responseString: String? {
104-
guard let data = data, let dataString = String(data: data, encoding: .utf8) else {
104+
guard let data, let dataString = String(data: data, encoding: .utf8) else {
105105
return nil
106106
}
107107

Sources/App/Onboarding/API/Steps/OnboardingAuthStepConnectivity.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class OnboardingAuthStepConnectivity: NSObject, OnboardingAuthPreStep, URLSessio
3737
let (requestPromise, requestResolver) = Promise<(data: Data, response: URLResponse)>.pending()
3838

3939
let task = session.dataTask(with: authDetails.url) { data, response, error in
40-
if let data = data, let response = response {
40+
if let data, let response {
4141
requestResolver.fulfill((data, response))
4242
} else {
4343
requestResolver.resolve(nil, error)

Sources/App/Onboarding/API/Steps/OnboardingAuthStepDuplicate.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ struct OnboardingAuthStepDuplicate: OnboardingAuthPostStep {
116116
handler: { [self] _ in
117117
let name = alert.textFields?.first?.text?.trimmingCharacters(in: .whitespaces)
118118

119-
guard let name = name, name.isEmpty == false,
119+
guard let name, name.isEmpty == false,
120120
!registeredDevices.contains(where: { $0.matches(name: name) }) else {
121121
promptForDeviceName(
122122
deviceName: deviceName,

Sources/App/Onboarding/Screens/OnboardingManualURLViewController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class OnboardingManualURLViewController: UIViewController, UITextFieldDelegate {
175175

176176
let alert = UIAlertController(
177177
title: L10n.Onboarding.ManualSetup.CouldntMakeUrl.title,
178-
message: L10n.Onboarding.ManualSetup.CouldntMakeUrl.message(self.urlField.text ?? ""),
178+
message: L10n.Onboarding.ManualSetup.CouldntMakeUrl.message(urlField.text ?? ""),
179179
preferredStyle: .alert
180180
)
181181
alert.addAction(UIAlertAction(title: L10n.okLabel, style: UIAlertAction.Style.default, handler: nil))
@@ -266,7 +266,7 @@ class OnboardingManualURLViewController: UIViewController, UITextFieldDelegate {
266266
}
267267

268268
@objc private func keyboardWillChangeFrame(_ note: Notification) {
269-
guard let scrollView = scrollView,
269+
guard let scrollView,
270270
let frameValue = note.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else {
271271
return
272272
}

Sources/App/QRCodeScanner/Camera/BarcodeScannerCamera.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class BarcodeScannerCamera: NSObject {
3333

3434
private var captureDevice: AVCaptureDevice? {
3535
didSet {
36-
guard let captureDevice = captureDevice else { return }
36+
guard let captureDevice else { return }
3737
Current.Log.info("Using capture device: \(captureDevice.localizedName)")
3838
sessionQueue.async {
3939
self.updateSessionForCaptureDevice(captureDevice)
@@ -79,7 +79,7 @@ class BarcodeScannerCamera: NSObject {
7979
}
8080

8181
guard
82-
let captureDevice = captureDevice,
82+
let captureDevice,
8383
let deviceInput = try? AVCaptureDeviceInput(device: captureDevice) else {
8484
Current.Log.error("Failed to obtain video input.")
8585
return
@@ -199,14 +199,14 @@ class BarcodeScannerCamera: NSObject {
199199
if isCaptureSessionConfigured {
200200
if !captureSession.isRunning {
201201
sessionQueue.async { [self] in
202-
self.captureSession.startRunning()
202+
captureSession.startRunning()
203203
}
204204
}
205205
return
206206
}
207207

208208
sessionQueue.async { [self] in
209-
self.configureCaptureSession { success in
209+
configureCaptureSession { success in
210210
guard success else { return }
211211
self.captureSession.startRunning()
212212
}

Sources/App/Scenes/SceneManager.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class SceneManager {
5757
}
5858
}
5959

60-
func resolve<T>(with possible: T) {
60+
func resolve(with possible: some Any) {
6161
handleBlock(possible)
6262
}
6363
}
@@ -77,13 +77,13 @@ class SceneManager {
7777

7878
init() {
7979
Current.realmFatalPresentation = { [weak self] viewController in
80-
guard let self = self else { return }
80+
guard let self else { return }
8181

8282
let under = UIViewController()
8383
under.view.backgroundColor = .black
8484
under.modalPresentationStyle = .fullScreen
8585

86-
self.webViewWindowControllerPromise.done { parent in
86+
webViewWindowControllerPromise.done { parent in
8787
parent.present(under, animated: false, completion: {
8888
under.present(viewController, animated: true, completion: nil)
8989
})

Sources/App/Scenes/SettingsSceneDelegate.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import UIKit
66
@objc class SettingsSceneDelegate: BasicSceneDelegate {
77
private var navigationController: UINavigationController? {
88
didSet {
9-
if let navigationController = navigationController {
9+
if let navigationController {
1010
navigationController.delegate = self
1111
update(navigationController: navigationController)
1212
}
@@ -155,7 +155,7 @@ extension SettingsSceneDelegate: NSToolbarDelegate {
155155
}
156156

157157
fileprivate func selectItemForIdentifier(_ identifier: NSToolbarItem.Identifier) {
158-
if let viewController = viewController(for: identifier), let navigationController = navigationController {
158+
if let viewController = viewController(for: identifier), let navigationController {
159159
scene?.title = SettingsRootDataSource.buttonRows.first(where: { $0.tag == identifier.rawValue })?.title
160160

161161
// before, so it can be reset by the controller

Sources/App/Scenes/WindowScenesManager.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ final class WindowScenesManager {
3737
}
3838

3939
// Create cascade effect so windows don't overlap
40-
internal func adjustedSystemFrame(
40+
func adjustedSystemFrame(
4141
_ systemFrame: CGRect,
4242
for screenSize: CGSize,
4343
numberOfConnectedScenes: Int

Sources/App/Servers/ServerSelectViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class ServerSelectViewController: HAFormViewController, ServerObserver, UIAdapti
7777
private func setupForm() {
7878
form.removeAll()
7979

80-
if let prompt = prompt, !prompt.isEmpty {
80+
if let prompt, !prompt.isEmpty {
8181
form +++ InfoLabelRow {
8282
$0.title = prompt
8383
}

Sources/App/Settings/ActionConfigurator.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ActionConfigurator: HAFormViewController, TypedRowControllerType {
2828

2929
self.isModalInPresentation = true
3030

31-
if let action = action {
31+
if let action {
3232
self.action = Action(value: action)
3333
self.newAction = false
3434
} else if let firstServer = Current.servers.all.first {
@@ -61,8 +61,8 @@ class ActionConfigurator: HAFormViewController, TypedRowControllerType {
6161
guard let self else { return }
6262
cell.backgroundColor = UIColor.clear
6363
cell.preservesSuperviewLayoutMargins = false
64-
self.updatePreviews()
65-
cell.view = self.preview
64+
updatePreviews()
65+
cell.view = preview
6666
}
6767

6868
let firstSection = Section()
@@ -369,7 +369,7 @@ class ActionPreview: UIView {
369369
}
370370

371371
@objc func handleGesture(gesture: UITapGestureRecognizer) {
372-
guard let action = action,
372+
guard let action,
373373
let server = Current.servers.server(forServerIdentifier: action.serverIdentifier) else {
374374
return
375375
}

Sources/App/Settings/AppleWatch/ComplicationFamilySelectViewController.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ class ComplicationFamilySelectViewController: HAFormViewController, RowControlle
7474

7575
return ComplicationEditViewController(config: complication)
7676
}, onDismiss: { [weak self] vc in
77-
guard let self = self, let vc = vc as? ComplicationEditViewController else { return }
77+
guard let self, let vc = vc as? ComplicationEditViewController else { return }
7878

7979
if vc.config.realm == nil {
8080
// not saved
81-
self.navigationController?.popViewController(animated: true)
81+
navigationController?.popViewController(animated: true)
8282
} else {
8383
// saved
84-
self.onDismissCallback?(self)
84+
onDismissCallback?(self)
8585
}
8686
})
8787
}

Sources/App/Settings/Connection/ConnectionSettingsViewController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class ConnectionSettingsViewController: HAFormViewController, RowControllerType
7474
let manager = Current.notificationManager.localPushManager
7575

7676
let updateValue = { [weak row, server] in
77-
guard let row = row else { return }
77+
guard let row else { return }
7878
switch manager.status(for: server) {
7979
case .disabled:
8080
row.value = L10n.SettingsDetails.Notifications.LocalPush.Status.disabled
@@ -124,7 +124,7 @@ class ConnectionSettingsViewController: HAFormViewController, RowControllerType
124124
var timer: Timer?
125125

126126
$0.onChange { [server] row in
127-
if let timer = timer, timer.isValid {
127+
if let timer, timer.isValid {
128128
timer.fireDate = Current.date().addingTimeInterval(1.0)
129129
} else {
130130
timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false, block: { _ in

0 commit comments

Comments
 (0)