Skip to content

Commit

Permalink
Update swift lint and format + appy fixes (#2585)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
mat1th authored Feb 22, 2024
1 parent 58cb900 commit 97834bf
Show file tree
Hide file tree
Showing 174 changed files with 502 additions and 494 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ jobs:
- name: SwiftLint
run: |
docker run --rm -v `pwd`:`pwd` -w `pwd` \
ghcr.io/realm/swiftlint:0.49.1 \
ghcr.io/realm/swiftlint:0.54.0 \
swiftlint lint --strict --config .swiftlint.yml --reporter github-actions-logging
- name: SwiftFormat
run: |
docker run --rm -v `pwd`:`pwd` -w `pwd` \
ghcr.io/nicklockwood/swiftformat:0.50.3 \
ghcr.io/nicklockwood/swiftformat:0.53.1 \
--lint --config .swiftformat .
test:
Expand Down
2 changes: 1 addition & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--swiftversion 5.3
--swiftversion 5.8

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

Expand Down
2 changes: 1 addition & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ excluded:
- Tests
- Pods
- vendor
- "*/**/.build"
- "**/**/.build"
4 changes: 2 additions & 2 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ project 'HomeAssistant', 'Debug' => :debug, 'Release' => :release, 'Beta' => :re

def support_modules
pod 'SwiftGen', '~> 6.5.0'
pod 'SwiftLint', '0.49.1' # also update ci.yml GHA
pod 'SwiftFormat/CLI', '0.50.3' # also update ci.yml GHA
pod 'SwiftLint', '0.54.0' # also update ci.yml GHA
pod 'SwiftFormat/CLI', '0.53.1' # also update ci.yml GHA
end

if ENV['ONLY_SUPPORT_MODULES']
Expand Down
14 changes: 7 additions & 7 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ PODS:
- Realm (= 10.35.0)
- Sodium (0.9.1)
- Starscream (4.0.4)
- SwiftFormat/CLI (0.50.3)
- SwiftFormat/CLI (0.53.1)
- SwiftGen (6.5.1)
- SwiftLint (0.49.1)
- SwiftLint (0.54.0)
- SwiftMessages (9.0.6):
- SwiftMessages/App (= 9.0.6)
- SwiftMessages/App (9.0.6)
Expand Down Expand Up @@ -141,9 +141,9 @@ DEPENDENCIES:
- RealmSwift
- Sodium (from `https://github.com/zacwest/swift-sodium.git`, branch `xcode-14.0.1`)
- Starscream (from `https://github.com/zacwest/starscream`, branch `ha-swift-api`)
- SwiftFormat/CLI (= 0.50.3)
- SwiftFormat/CLI (= 0.53.1)
- SwiftGen (~> 6.5.0)
- SwiftLint (= 0.49.1)
- SwiftLint (= 0.54.0)
- SwiftMessages
- UIColor_Hex_Swift
- Version
Expand Down Expand Up @@ -274,16 +274,16 @@ SPEC CHECKSUMS:
RealmSwift: b358779c10ba6d2648d541f8a1bcd671f73485c1
Sodium: a7d42cb46e789d2630fa552d35870b416ed055ae
Starscream: 5178aed56b316f13fa3bc55694e583d35dd414d9
SwiftFormat: 61cda3819dc3a7d69795ce0430e1e1d53c4a4fb2
SwiftFormat: a8623113c7adcbeb4289a013cac68ec801e1ed24
SwiftGen: a6d22010845f08fe18fbdf3a07a8e380fd22e0ea
SwiftLint: 32ee33ded0636d0905ef6911b2b67bbaeeedafa5
SwiftLint: c1de071d9d08c8aba837545f6254315bc900e211
SwiftMessages: f0c7ef4705a570ad6c5e208b611f4333e660ed92
UIColor_Hex_Swift: 31cd3e47440f07a20d2503a36bb0437a445b3c29
Version: de5907f2c5d0f3cf21708db7801d1d5401139486
ViewRow: 8da541e9c019f3be63f4e28f311a62cac2045ecf
XCGLogger: 1943831ef907df55108b0b18657953f868de973b
ZIPFoundation: d170fa8e270b2a32bef9dcdcabff5b8f1a5deced

PODFILE CHECKSUM: 22fc24cfd665bd31532e7b68cf2aee22abb132b2
PODFILE CHECKSUM: a1fb8b74054208eb193f5366db79acab04a209b0

COCOAPODS: 1.15.2
12 changes: 6 additions & 6 deletions Sources/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension AppEnvironment {
}
}

@UIApplicationMain
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
@available(iOS, deprecated: 13.0)
var window: UIWindow? {
Expand Down Expand Up @@ -144,12 +144,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}

@objc internal func openAbout() {
@objc func openAbout() {
precondition(Current.sceneManager.supportsMultipleScenes)
sceneManager.activateAnyScene(for: .about)
}

@objc internal func openMenuUrl(_ command: AnyObject) {
@objc func openMenuUrl(_ command: AnyObject) {
guard let command = command as? UICommand, let url = MenuManager.url(from: command) else {
return
}
Expand All @@ -160,18 +160,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}

@objc internal func openPreferences() {
@objc func openPreferences() {
precondition(Current.sceneManager.supportsMultipleScenes)
sceneManager.activateAnyScene(for: .settings)
}

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

@objc internal func openHelp() {
@objc func openHelp() {
openURLInBrowser(
URL(string: "https://companion.home-assistant.io")!,
nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public extension ClientEventTableViewController {
}

extension UITableView {
func applyChanges<T>(changes: RealmCollectionChange<T>) {
func applyChanges(changes: RealmCollectionChange<some Any>) {
switch changes {
case .initial: reloadData()
case let .update(_, deletions, insertions, updates):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ extension LocationHistoryListViewController: LocationHistoryDetailMoveDelegate {
from row: RowOf<LocationHistoryDetailViewController>,
in direction: LocationHistoryDetailViewController.MoveDirection
) -> ButtonRowWithPresent<LocationHistoryDetailViewController>? {
guard let indexPath = row.indexPath, let section = section else {
guard let indexPath = row.indexPath, let section else {
return nil
}

Expand All @@ -94,7 +94,7 @@ extension LocationHistoryListViewController: LocationHistoryDetailMoveDelegate {
default: nextIndex = nil
}

if let nextIndex = nextIndex {
if let nextIndex {
return section[nextIndex] as? ButtonRowWithPresent<LocationHistoryDetailViewController>
} else {
return nil
Expand All @@ -112,7 +112,7 @@ extension LocationHistoryListViewController: LocationHistoryDetailMoveDelegate {
_ controller: LocationHistoryDetailViewController,
move direction: LocationHistoryDetailViewController.MoveDirection
) {
guard let navigationController = navigationController,
guard let navigationController,
let nextRow = row(from: controller.row, in: direction),
let nextController = nextRow.presentationMode?.makeController() else {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ final class NotificationManagerLocalPushInterfaceExtension: NSObject, Notificati

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

let existing = managers?.first(where: { $0.matchSSIDs == [ssid] })
if let existing = existing {
if let existing {
usedManagers.insert(existing)
}
updatedManagers.append(updateManager(
Expand Down
4 changes: 2 additions & 2 deletions Sources/App/Onboarding/API/OnboardingAuthError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct OnboardingAuthError: LocalizedError {
extraInfo = nil
}

if let extraInfo = extraInfo {
if let extraInfo {
return extraInfo + "\n\n" + underlying.localizedDescription
} else {
return underlying.localizedDescription
Expand All @@ -101,7 +101,7 @@ struct OnboardingAuthError: LocalizedError {
}

var responseString: String? {
guard let data = data, let dataString = String(data: data, encoding: .utf8) else {
guard let data, let dataString = String(data: data, encoding: .utf8) else {
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class OnboardingAuthStepConnectivity: NSObject, OnboardingAuthPreStep, URLSessio
let (requestPromise, requestResolver) = Promise<(data: Data, response: URLResponse)>.pending()

let task = session.dataTask(with: authDetails.url) { data, response, error in
if let data = data, let response = response {
if let data, let response {
requestResolver.fulfill((data, response))
} else {
requestResolver.resolve(nil, error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ struct OnboardingAuthStepDuplicate: OnboardingAuthPostStep {
handler: { [self] _ in
let name = alert.textFields?.first?.text?.trimmingCharacters(in: .whitespaces)

guard let name = name, name.isEmpty == false,
guard let name, name.isEmpty == false,
!registeredDevices.contains(where: { $0.matches(name: name) }) else {
promptForDeviceName(
deviceName: deviceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class OnboardingManualURLViewController: UIViewController, UITextFieldDelegate {

let alert = UIAlertController(
title: L10n.Onboarding.ManualSetup.CouldntMakeUrl.title,
message: L10n.Onboarding.ManualSetup.CouldntMakeUrl.message(self.urlField.text ?? ""),
message: L10n.Onboarding.ManualSetup.CouldntMakeUrl.message(urlField.text ?? ""),
preferredStyle: .alert
)
alert.addAction(UIAlertAction(title: L10n.okLabel, style: UIAlertAction.Style.default, handler: nil))
Expand Down Expand Up @@ -266,7 +266,7 @@ class OnboardingManualURLViewController: UIViewController, UITextFieldDelegate {
}

@objc private func keyboardWillChangeFrame(_ note: Notification) {
guard let scrollView = scrollView,
guard let scrollView,
let frameValue = note.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else {
return
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/App/QRCodeScanner/Camera/BarcodeScannerCamera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BarcodeScannerCamera: NSObject {

private var captureDevice: AVCaptureDevice? {
didSet {
guard let captureDevice = captureDevice else { return }
guard let captureDevice else { return }
Current.Log.info("Using capture device: \(captureDevice.localizedName)")
sessionQueue.async {
self.updateSessionForCaptureDevice(captureDevice)
Expand Down Expand Up @@ -79,7 +79,7 @@ class BarcodeScannerCamera: NSObject {
}

guard
let captureDevice = captureDevice,
let captureDevice,
let deviceInput = try? AVCaptureDeviceInput(device: captureDevice) else {
Current.Log.error("Failed to obtain video input.")
return
Expand Down Expand Up @@ -199,14 +199,14 @@ class BarcodeScannerCamera: NSObject {
if isCaptureSessionConfigured {
if !captureSession.isRunning {
sessionQueue.async { [self] in
self.captureSession.startRunning()
captureSession.startRunning()
}
}
return
}

sessionQueue.async { [self] in
self.configureCaptureSession { success in
configureCaptureSession { success in
guard success else { return }
self.captureSession.startRunning()
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/App/Scenes/SceneManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SceneManager {
}
}

func resolve<T>(with possible: T) {
func resolve(with possible: some Any) {
handleBlock(possible)
}
}
Expand All @@ -77,13 +77,13 @@ class SceneManager {

init() {
Current.realmFatalPresentation = { [weak self] viewController in
guard let self = self else { return }
guard let self else { return }

let under = UIViewController()
under.view.backgroundColor = .black
under.modalPresentationStyle = .fullScreen

self.webViewWindowControllerPromise.done { parent in
webViewWindowControllerPromise.done { parent in
parent.present(under, animated: false, completion: {
under.present(viewController, animated: true, completion: nil)
})
Expand Down
4 changes: 2 additions & 2 deletions Sources/App/Scenes/SettingsSceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import UIKit
@objc class SettingsSceneDelegate: BasicSceneDelegate {
private var navigationController: UINavigationController? {
didSet {
if let navigationController = navigationController {
if let navigationController {
navigationController.delegate = self
update(navigationController: navigationController)
}
Expand Down Expand Up @@ -155,7 +155,7 @@ extension SettingsSceneDelegate: NSToolbarDelegate {
}

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

// before, so it can be reset by the controller
Expand Down
2 changes: 1 addition & 1 deletion Sources/App/Scenes/WindowScenesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class WindowScenesManager {
}

// Create cascade effect so windows don't overlap
internal func adjustedSystemFrame(
func adjustedSystemFrame(
_ systemFrame: CGRect,
for screenSize: CGSize,
numberOfConnectedScenes: Int
Expand Down
2 changes: 1 addition & 1 deletion Sources/App/Servers/ServerSelectViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ServerSelectViewController: HAFormViewController, ServerObserver, UIAdapti
private func setupForm() {
form.removeAll()

if let prompt = prompt, !prompt.isEmpty {
if let prompt, !prompt.isEmpty {
form +++ InfoLabelRow {
$0.title = prompt
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/App/Settings/ActionConfigurator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ActionConfigurator: HAFormViewController, TypedRowControllerType {

self.isModalInPresentation = true

if let action = action {
if let action {
self.action = Action(value: action)
self.newAction = false
} else if let firstServer = Current.servers.all.first {
Expand Down Expand Up @@ -61,8 +61,8 @@ class ActionConfigurator: HAFormViewController, TypedRowControllerType {
guard let self else { return }
cell.backgroundColor = UIColor.clear
cell.preservesSuperviewLayoutMargins = false
self.updatePreviews()
cell.view = self.preview
updatePreviews()
cell.view = preview
}

let firstSection = Section()
Expand Down Expand Up @@ -369,7 +369,7 @@ class ActionPreview: UIView {
}

@objc func handleGesture(gesture: UITapGestureRecognizer) {
guard let action = action,
guard let action,
let server = Current.servers.server(forServerIdentifier: action.serverIdentifier) else {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ class ComplicationFamilySelectViewController: HAFormViewController, RowControlle

return ComplicationEditViewController(config: complication)
}, onDismiss: { [weak self] vc in
guard let self = self, let vc = vc as? ComplicationEditViewController else { return }
guard let self, let vc = vc as? ComplicationEditViewController else { return }

if vc.config.realm == nil {
// not saved
self.navigationController?.popViewController(animated: true)
navigationController?.popViewController(animated: true)
} else {
// saved
self.onDismissCallback?(self)
onDismissCallback?(self)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ConnectionSettingsViewController: HAFormViewController, RowControllerType
let manager = Current.notificationManager.localPushManager

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

$0.onChange { [server] row in
if let timer = timer, timer.isValid {
if let timer, timer.isValid {
timer.fireDate = Current.date().addingTimeInterval(1.0)
} else {
timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false, block: { _ in
Expand Down
Loading

0 comments on commit 97834bf

Please sign in to comment.