From 4dcd80e4e1c15da570e5473318e51618ba895aa8 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Wed, 13 Apr 2022 16:34:45 -0400 Subject: [PATCH] Swiftformat. --- Clocker/AppDelegate.swift | 2 +- .../ClockerUnitTests/ClockerUnitTests.swift | 2 +- Clocker/ClockerUnitTests/EventInfoTests.swift | 19 +++++---- .../StandardMenubarHandlerTests.swift | 39 ++++++++----------- .../OnboardingParentViewController.swift | 2 +- .../OnboardingSearchController.swift | 6 +-- Clocker/Overall App/AppKit + Additions.swift | 2 +- Clocker/Overall App/DataStore.swift | 4 +- Clocker/Panel/PanelController.swift | 2 +- Clocker/Panel/ParentPanelController.swift | 2 +- .../About/AboutViewController.swift | 2 +- .../AppFeedbackWindowController.swift | 4 +- 12 files changed, 40 insertions(+), 46 deletions(-) diff --git a/Clocker/AppDelegate.swift b/Clocker/AppDelegate.swift index 8bac137..52ecf02 100644 --- a/Clocker/AppDelegate.swift +++ b/Clocker/AppDelegate.swift @@ -110,7 +110,7 @@ open class AppDelegate: NSObject, NSApplicationDelegate { if controller != nil { controller = nil } - + // Check if another instance of the app is already running. If so, then stop this one. checkIfAppIsAlreadyOpen() diff --git a/Clocker/ClockerUnitTests/ClockerUnitTests.swift b/Clocker/ClockerUnitTests/ClockerUnitTests.swift index ab0b26d..2f7e12f 100644 --- a/Clocker/ClockerUnitTests/ClockerUnitTests.swift +++ b/Clocker/ClockerUnitTests/ClockerUnitTests.swift @@ -406,7 +406,7 @@ class ClockerUnitTests: XCTestCase { func testToasty() { let view = NSView(frame: CGRect.zero) view.makeToast("Hello, this is a toast") - XCTAssertEqual(view.subviews.first?.accessibilityIdentifier(), "ToastView") + XCTAssertEqual(view.subviews.first?.accessibilityIdentifier(), "ToastView") let toastExpectation = expectation(description: "Toast View should hide after 1 second") let result = XCTWaiter.wait(for: [toastExpectation], timeout: 1.5) // Set 1.5 seconds here for a little leeway if result == XCTWaiter.Result.timedOut { diff --git a/Clocker/ClockerUnitTests/EventInfoTests.swift b/Clocker/ClockerUnitTests/EventInfoTests.swift index 96e236d..cc116c0 100644 --- a/Clocker/ClockerUnitTests/EventInfoTests.swift +++ b/Clocker/ClockerUnitTests/EventInfoTests.swift @@ -1,8 +1,8 @@ // Copyright © 2015 Abhishek Banthia -import XCTest @testable import Clocker import EventKit +import XCTest class EventInfoTests: XCTestCase { private let eventStore = EKEventStore() @@ -12,7 +12,7 @@ class EventInfoTests: XCTestCase { let mockEvent = EKEvent(eventStore: eventStore) mockEvent.title = "Mock Title" mockEvent.startDate = Date().add(futureChunk) - + let mockEventInfo = EventInfo(event: mockEvent, isAllDay: false, meetingURL: nil, @@ -20,13 +20,13 @@ class EventInfoTests: XCTestCase { XCTAssert(mockEventInfo.metadataForMeeting() == "in 5m", "Metadata for meeting: \(mockEventInfo.metadataForMeeting()) doesn't match expectation") } - + func testMetadataForUpcomingEventHappeningInTenSeconds() throws { let futureChunk = TimeChunk(seconds: 10, minutes: 0, hours: 0, days: 0, weeks: 0, months: 0, years: 0) let mockEvent = EKEvent(eventStore: eventStore) mockEvent.title = "Mock Title" mockEvent.startDate = Date().add(futureChunk) - + let mockEventInfo = EventInfo(event: mockEvent, isAllDay: false, meetingURL: nil, @@ -40,7 +40,7 @@ class EventInfoTests: XCTestCase { let mockEvent = EKEvent(eventStore: eventStore) mockEvent.title = "Mock Title" mockEvent.startDate = Date().subtract(pastChunk) - + let mockEventInfo = EventInfo(event: mockEvent, isAllDay: false, meetingURL: nil, @@ -48,13 +48,13 @@ class EventInfoTests: XCTestCase { XCTAssert(mockEventInfo.metadataForMeeting() == "started +2m.", "Metadata for meeting: \(mockEventInfo.metadataForMeeting()) doesn't match expectation") } - + func testMetadataForEventPastTenMinutes() throws { let pastChunk = TimeChunk(seconds: 10, minutes: 10, hours: 0, days: 0, weeks: 0, months: 0, years: 0) let mockEvent = EKEvent(eventStore: eventStore) mockEvent.title = "Mock Title" mockEvent.startDate = Date().subtract(pastChunk) - + let mockEventInfo = EventInfo(event: mockEvent, isAllDay: false, meetingURL: nil, @@ -62,13 +62,13 @@ class EventInfoTests: XCTestCase { XCTAssert(mockEventInfo.metadataForMeeting() == "Error", "Metadata for meeting: \(mockEventInfo.metadataForMeeting()) doesn't match expectation") } - + func testMetadataForEventHappeningTomorrow() throws { let pastChunk = TimeChunk(seconds: 10, minutes: 0, hours: 25, days: 0, weeks: 0, months: 0, years: 0) let mockEvent = EKEvent(eventStore: eventStore) mockEvent.title = "Mock Title" mockEvent.startDate = Date().add(pastChunk) - + let mockEventInfo = EventInfo(event: mockEvent, isAllDay: false, meetingURL: nil, @@ -76,5 +76,4 @@ class EventInfoTests: XCTestCase { XCTAssert(mockEventInfo.metadataForMeeting() == "in 25h", "Metadata for meeting: \(mockEventInfo.metadataForMeeting()) doesn't match expectation") } - } diff --git a/Clocker/ClockerUnitTests/StandardMenubarHandlerTests.swift b/Clocker/ClockerUnitTests/StandardMenubarHandlerTests.swift index 4d18c8d..5cc24ee 100644 --- a/Clocker/ClockerUnitTests/StandardMenubarHandlerTests.swift +++ b/Clocker/ClockerUnitTests/StandardMenubarHandlerTests.swift @@ -1,14 +1,14 @@ // Copyright © 2015 Abhishek Banthia import CoreModelKit -import XCTest import EventKit +import XCTest @testable import Clocker class StandardMenubarHandlerTests: XCTestCase { private let eventStore = EKEventStore() - + private let mumbai = ["customLabel": "Ghar", "formattedAddress": "Mumbai", "place_id": "ChIJwe1EZjDG5zsRaYxkjY_tpF0", @@ -116,73 +116,68 @@ class StandardMenubarHandlerTests: XCTestCase { let menubarHandler = MenubarTitleProvider(with: store) XCTAssertNotNil(menubarHandler.titleForMenubar()) } - + func testFormattedUpcomingEvent() { let store = makeMockStore() - + let futureChunk = TimeChunk(seconds: 10, minutes: 10, hours: 0, days: 0, weeks: 0, months: 0, years: 0) let mockEvent = EKEvent(eventStore: eventStore) mockEvent.title = "Mock Title" mockEvent.startDate = Date().add(futureChunk) - + let menubarHandler = MenubarTitleProvider(with: store) XCTAssert(menubarHandler.format(event: mockEvent) == "Mock Title in 10m", "Suffix \(menubarHandler.format(event: mockEvent)) doesn't match expectation") - } - + func testUpcomingEventHappeningWithinOneMinute() { let store = makeMockStore() - + let futureChunk = TimeChunk(seconds: 10, minutes: 1, hours: 0, days: 0, weeks: 0, months: 0, years: 0) let mockEvent = EKEvent(eventStore: eventStore) mockEvent.title = "Mock Title" mockEvent.startDate = Date().add(futureChunk) - + let menubarHandler = MenubarTitleProvider(with: store) XCTAssert(menubarHandler.format(event: mockEvent) == "Mock Title in 1m", "Suffix \(menubarHandler.format(event: mockEvent)) doesn't match expectation") - } - + func testUpcomingEventHappeningWithinSeconds() { let store = makeMockStore() - + let futureChunk = TimeChunk(seconds: 10, minutes: 0, hours: 0, days: 0, weeks: 0, months: 0, years: 0) let mockEvent = EKEvent(eventStore: eventStore) mockEvent.title = "Mock Title" mockEvent.startDate = Date().add(futureChunk) - + let menubarHandler = MenubarTitleProvider(with: store) XCTAssert(menubarHandler.format(event: mockEvent) == "Mock Title starts now.", "Suffix \(menubarHandler.format(event: mockEvent)) doesn't match expectation") - } - + func testEmptyUpcomingEvent() { let store = makeMockStore() - + let futureChunk = TimeChunk(seconds: 10, minutes: 0, hours: 0, days: 0, weeks: 0, months: 0, years: 0) let mockEvent = EKEvent(eventStore: eventStore) mockEvent.startDate = Date().add(futureChunk) - + let menubarHandler = MenubarTitleProvider(with: store) XCTAssert(menubarHandler.format(event: mockEvent) == CLEmptyString, "Suffix \(menubarHandler.format(event: mockEvent)) doesn't match expectation") - } - + func testLongUpcomingEvent() { let store = makeMockStore() - + let futureChunk = TimeChunk(seconds: 10, minutes: 0, hours: 0, days: 0, weeks: 0, months: 0, years: 0) let mockEvent = EKEvent(eventStore: eventStore) mockEvent.title = "Really long calendar event title that longer than the longest name" mockEvent.startDate = Date().add(futureChunk) - + let menubarHandler = MenubarTitleProvider(with: store) XCTAssert(menubarHandler.format(event: mockEvent) == "Really long calendar event tit... starts now.", "Suffix \(menubarHandler.format(event: mockEvent)) doesn't match expectation") - } } diff --git a/Clocker/Onboarding/OnboardingParentViewController.swift b/Clocker/Onboarding/OnboardingParentViewController.swift index e88424d..1772011 100644 --- a/Clocker/Onboarding/OnboardingParentViewController.swift +++ b/Clocker/Onboarding/OnboardingParentViewController.swift @@ -223,7 +223,7 @@ class OnboardingParentViewController: NSViewController { if ProcessInfo.processInfo.arguments.contains(CLOnboaringTestsLaunchArgument) == false { UserDefaults.standard.set(true, forKey: CLShowOnboardingFlow) } - + // Install the menubar option! let appDelegate = NSApplication.shared.delegate as? AppDelegate appDelegate?.continueUsually() diff --git a/Clocker/Onboarding/OnboardingSearchController.swift b/Clocker/Onboarding/OnboardingSearchController.swift index be1eb12..b119d23 100644 --- a/Clocker/Onboarding/OnboardingSearchController.swift +++ b/Clocker/Onboarding/OnboardingSearchController.swift @@ -40,7 +40,7 @@ class OnboardingSearchController: NSViewController { super.viewDidLoad() view.wantsLayer = true - + resultsTableView.isHidden = true resultsTableView.delegate = self resultsTableView.setAccessibility("ResultsTableView") @@ -69,12 +69,12 @@ class OnboardingSearchController: NSViewController { setupUndoButton() } - + override func viewWillAppear() { super.viewWillAppear() searchResultsDataSource = SearchDataSource(with: searchBar, location: .onboarding) } - + override func viewWillDisappear() { super.viewWillDisappear() searchResultsDataSource = nil diff --git a/Clocker/Overall App/AppKit + Additions.swift b/Clocker/Overall App/AppKit + Additions.swift index ad78e09..d40c044 100644 --- a/Clocker/Overall App/AppKit + Additions.swift +++ b/Clocker/Overall App/AppKit + Additions.swift @@ -21,7 +21,7 @@ extension NSTextField { } extension NSFont { - func size(_ string: String, _ width: Double, attributes: [NSAttributedString.Key: AnyObject]) -> CGSize { + func size(for string: String, width: Double, attributes: [NSAttributedString.Key: AnyObject]) -> CGSize { let size = CGSize(width: width, height: Double.greatestFiniteMagnitude) diff --git a/Clocker/Overall App/DataStore.swift b/Clocker/Overall App/DataStore.swift index e837bff..2cdb2eb 100644 --- a/Clocker/Overall App/DataStore.swift +++ b/Clocker/Overall App/DataStore.swift @@ -71,11 +71,11 @@ class DataStore: NSObject { let cloudTimezones = ubiquitousStore?.object(forKey: CLDefaultPreferenceKey) as? [Data] let cloudLastUpdateDate = (ubiquitousStore?.object(forKey: CLUbiquitousStoreLastUpdateKey) as? Date) ?? Date() let defaultsLastUpdateDate = (ubiquitousStore?.object(forKey: CLUserDefaultsLastUpdateKey) as? Date) ?? Date() - + if cloudTimezones == currentTimezones { Logger.info("Ubiquitous Store timezones aren't equal to current timezones") } - + if defaultsLastUpdateDate.isLaterThanOrEqual(to: cloudLastUpdateDate) { Logger.info("Ubiquitous Store is stale as compared to User Defaults") } diff --git a/Clocker/Panel/PanelController.swift b/Clocker/Panel/PanelController.swift index 6e3fac3..89519f3 100644 --- a/Clocker/Panel/PanelController.swift +++ b/Clocker/Panel/PanelController.swift @@ -74,7 +74,7 @@ class PanelController: ParentPanelController { super.dismissRowActions() updateDefaultPreferences() - + setupUpcomingEventViewCollectionViewIfNeccesary() if DataStore.shared().timezones().isEmpty || DataStore.shared().shouldDisplay(.futureSlider) == false { diff --git a/Clocker/Panel/ParentPanelController.swift b/Clocker/Panel/ParentPanelController.swift index 535180c..c48700c 100644 --- a/Clocker/Panel/ParentPanelController.swift +++ b/Clocker/Panel/ParentPanelController.swift @@ -1151,7 +1151,7 @@ extension ParentPanelController: AppFeedbackWindowControllerDelegate { func appFeedbackWindowWillClose() { feedbackWindow = nil } - + func appFeedbackWindoEntryPoint() -> String { return "parent_panel_controller" } diff --git a/Clocker/Preferences/About/AboutViewController.swift b/Clocker/Preferences/About/AboutViewController.swift index afc91fb..b6ac392 100644 --- a/Clocker/Preferences/About/AboutViewController.swift +++ b/Clocker/Preferences/About/AboutViewController.swift @@ -157,7 +157,7 @@ extension AboutViewController: AppFeedbackWindowControllerDelegate { func appFeedbackWindowWillClose() { feedbackWindow = nil } - + func appFeedbackWindoEntryPoint() -> String { return "about_view_controller" } diff --git a/Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift b/Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift index 152c315..16f8781 100644 --- a/Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift +++ b/Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift @@ -210,7 +210,7 @@ class AppFeedbackWindowController: NSWindowController { AppFeedbackConstants.CLClockerVersion: versionInfo, AppFeedbackConstants.CLAppFeedbackDateProperty: todaysDate(), AppFeedbackConstants.CLAppFeedbackUserPreferences: generateUserPreferences(), - AppFeedbackConstants.CLFeedbackEntryPoint: appFeedbackWindowDelegate?.appFeedbackWindoEntryPoint() ?? "Error" + AppFeedbackConstants.CLFeedbackEntryPoint: appFeedbackWindowDelegate?.appFeedbackWindoEntryPoint() ?? "Error", ] } @@ -228,7 +228,7 @@ class AppFeedbackWindowController: NSWindowController { #if DEBUG Logger.info("Sending a feedback in Debug builds will lead to a no-op") #endif - + guard let identifier = serialNumber else { assertionFailure("Serial Identifier was unexpectedly nil") return